make /init a default slash command on server side (#3677)

This commit is contained in:
Aiden Cline
2025-11-01 01:14:09 -05:00
committed by GitHub
parent c72f8b17c6
commit 041353f4ff
6 changed files with 92 additions and 49 deletions

View File

@@ -2,8 +2,6 @@ import { Decimal } from "decimal.js"
import z from "zod"
import { type LanguageModelUsage, type ProviderMetadata } from "ai"
import PROMPT_INITIALIZE from "../session/prompt/initialize.txt"
import { Bus } from "../bus"
import { Config } from "../config/config"
import { Flag } from "../flag/flag"
@@ -14,11 +12,11 @@ import { Share } from "../share/share"
import { Storage } from "../storage/storage"
import { Log } from "../util/log"
import { MessageV2 } from "./message-v2"
import { Project } from "../project/project"
import { Instance } from "../project/instance"
import { SessionPrompt } from "./prompt"
import { fn } from "@/util/fn"
import { Snapshot } from "@/snapshot"
import { Command } from "../command"
export namespace Session {
const log = Log.create({ service: "session" })
@@ -164,7 +162,12 @@ export namespace Session {
})
})
export async function createNext(input: { id?: string; title?: string; parentID?: string; directory: string }) {
export async function createNext(input: {
id?: string
title?: string
parentID?: string
directory: string
}) {
const result: Info = {
id: Identifier.descending("session", input.id),
version: Installation.VERSION,
@@ -402,7 +405,9 @@ export namespace Session {
.add(new Decimal(tokens.input).mul(input.model.cost?.input ?? 0).div(1_000_000))
.add(new Decimal(tokens.output).mul(input.model.cost?.output ?? 0).div(1_000_000))
.add(new Decimal(tokens.cache.read).mul(input.model.cost?.cache_read ?? 0).div(1_000_000))
.add(new Decimal(tokens.cache.write).mul(input.model.cost?.cache_write ?? 0).div(1_000_000))
.add(
new Decimal(tokens.cache.write).mul(input.model.cost?.cache_write ?? 0).div(1_000_000),
)
.toNumber(),
tokens,
}
@@ -423,22 +428,13 @@ export namespace Session {
messageID: Identifier.schema("message"),
}),
async (input) => {
await SessionPrompt.prompt({
await SessionPrompt.command({
sessionID: input.sessionID,
messageID: input.messageID,
model: {
providerID: input.providerID,
modelID: input.modelID,
},
parts: [
{
id: Identifier.ascending("part"),
type: "text",
text: PROMPT_INITIALIZE.replace("${path}", Instance.worktree),
},
],
model: input.providerID + "/" + input.modelID,
command: Command.Default.INIT,
arguments: "",
})
await Project.setInitialized(Instance.project.id)
},
)
}

View File

@@ -1593,6 +1593,7 @@ export namespace SessionPrompt {
let index = 0
template = template.replace(bashRegex, () => results[index++])
}
template = template.trim()
const parts = [
{
@@ -1657,6 +1658,8 @@ export namespace SessionPrompt {
})()
const agent = await Agent.get(agentName)
let result: MessageV2.WithParts
if ((agent.mode === "subagent" && command.subtask !== false) || command.subtask === true) {
using abort = lock(input.sessionID)
@@ -1732,7 +1735,7 @@ export namespace SessionPrompt {
}
await Session.updatePart(toolPart)
const result = await TaskTool.init().then((t) =>
const taskResult = await TaskTool.init().then((t) =>
t.execute(args, {
sessionID: input.sessionID,
abort: abort.signal,
@@ -1760,22 +1763,31 @@ export namespace SessionPrompt {
},
input: toolPart.state.input,
title: "",
metadata: result.metadata,
output: result.output,
metadata: taskResult.metadata,
output: taskResult.output,
}
await Session.updatePart(toolPart)
}
return { info: assistantMsg, parts: [toolPart] }
result = { info: assistantMsg, parts: [toolPart] }
} else {
result = await prompt({
sessionID: input.sessionID,
messageID: input.messageID,
model,
agent: agentName,
parts,
})
}
return prompt({
Bus.publish(Command.Event.Executed, {
name: input.command,
sessionID: input.sessionID,
messageID: input.messageID,
model,
agent: agentName,
parts,
arguments: input.arguments,
messageID: result.info.id,
})
return result
}
async function ensureTitle(input: {

View File

@@ -1,8 +0,0 @@
Please analyze this codebase and create an AGENTS.md file containing:
1. Build/lint/test commands - especially for running a single test
2. Code style guidelines including imports, formatting, types, naming conventions, error handling, etc.
The file you create will be given to agentic coding agents (such as yourself) that operate in this repository. Make it about 20 lines long.
If there are Cursor rules (in .cursor/rules/ or .cursorrules) or Copilot rules (in .github/copilot-instructions.md), make sure to include them.
If there's already an AGENTS.md, improve it if it's located in ${path}