This commit is contained in:
Dax Raad
2025-08-07 15:01:44 -04:00
parent 6015a47dae
commit f82f29cd24
38 changed files with 324 additions and 362 deletions
+12 -14
View File
@@ -41,8 +41,8 @@ import { mergeDeep, pipe, splitWhen } from "remeda"
import { ToolRegistry } from "../tool/registry"
import { Plugin } from "../plugin"
import { Project } from "../project/project"
import { State } from "../project/state"
import { Paths } from "../project/path"
import { Instance } from "../project/instance"
export namespace Session {
const log = Log.create({ service: "session" })
@@ -65,7 +65,6 @@ export namespace Session {
id: Identifier.schema("session"),
projectID: z.string(),
directory: z.string(),
worktree: z.string(),
parentID: Identifier.schema("session").optional(),
share: z
.object({
@@ -130,8 +129,7 @@ export namespace Session {
),
}
const state = State.create(
() => Paths.directory,
const state = Instance.state(
() => {
const pending = new Map<string, AbortController>()
const autoCompacting = new Map<string, boolean>()
@@ -162,7 +160,7 @@ export namespace Session {
export async function create(parentID?: string) {
return createNext({
parentID,
directory: Paths.directory,
directory: Instance.directory,
})
}
@@ -172,7 +170,6 @@ export namespace Session {
id: Identifier.descending("session", input.id),
version: Installation.VERSION,
projectID: project.id,
worktree: project.worktree,
directory: input.directory,
parentID: input.parentID,
title: createDefaultTitle(!!input.parentID),
@@ -711,8 +708,8 @@ export namespace Session {
system,
mode: inputMode,
path: {
cwd: Paths.directory,
root: Paths.worktree,
cwd: Instance.directory,
root: Instance.worktree,
},
cost: 0,
tokens: {
@@ -838,6 +835,7 @@ export namespace Session {
},
params,
)
console.log(outputLimit)
const stream = streamText({
onError(e) {
log.error("streamText error", {
@@ -866,8 +864,8 @@ export namespace Session {
role: "assistant",
system,
path: {
cwd: Paths.directory,
root: Paths.worktree,
cwd: Instance.directory,
root: Instance.worktree,
},
cost: 0,
tokens: {
@@ -1276,8 +1274,8 @@ export namespace Session {
system,
mode: "build",
path: {
cwd: Paths.directory,
root: Paths.worktree,
cwd: Instance.directory,
root: Instance.worktree,
},
summary: true,
cost: 0,
@@ -1400,7 +1398,7 @@ export namespace Session {
{
id: Identifier.ascending("part"),
type: "text",
text: PROMPT_INITIALIZE.replace("${path}", Paths.worktree),
text: PROMPT_INITIALIZE.replace("${path}", Instance.worktree),
},
],
})
+40 -44
View File
@@ -1,8 +1,7 @@
import { Config } from "../config/config"
import z from "zod"
import { Provider } from "../provider/provider"
import { State } from "../project/state"
import { Paths } from "../project/path"
import { Instance } from "../project/instance"
export namespace Mode {
export const Info = z
@@ -23,50 +22,47 @@ export namespace Mode {
ref: "Mode",
})
export type Info = z.infer<typeof Info>
const state = State.create(
() => Paths.directory,
async () => {
const cfg = await Config.get()
const model = cfg.model ? Provider.parseModel(cfg.model) : undefined
const result: Record<string, Info> = {
build: {
model,
name: "build",
const state = Instance.state(async () => {
const cfg = await Config.get()
const model = cfg.model ? Provider.parseModel(cfg.model) : undefined
const result: Record<string, Info> = {
build: {
model,
name: "build",
tools: {},
},
plan: {
name: "plan",
model,
tools: {
write: false,
edit: false,
patch: false,
},
},
}
for (const [key, value] of Object.entries(cfg.mode ?? {})) {
if (value.disable) continue
let item = result[key]
if (!item)
item = result[key] = {
name: key,
tools: {},
},
plan: {
name: "plan",
model,
tools: {
write: false,
edit: false,
patch: false,
},
},
}
for (const [key, value] of Object.entries(cfg.mode ?? {})) {
if (value.disable) continue
let item = result[key]
if (!item)
item = result[key] = {
name: key,
tools: {},
}
item.name = key
if (value.model) item.model = Provider.parseModel(value.model)
if (value.prompt) item.prompt = value.prompt
if (value.temperature != undefined) item.temperature = value.temperature
if (value.top_p != undefined) item.topP = value.top_p
if (value.tools)
item.tools = {
...value.tools,
...item.tools,
}
}
}
item.name = key
if (value.model) item.model = Provider.parseModel(value.model)
if (value.prompt) item.prompt = value.prompt
if (value.temperature != undefined) item.temperature = value.temperature
if (value.top_p != undefined) item.topP = value.top_p
if (value.tools)
item.tools = {
...value.tools,
...item.tools,
}
}
return result
},
)
return result
})
export async function get(mode: string) {
return state().then((x) => x[mode])
+5 -5
View File
@@ -13,7 +13,7 @@ import PROMPT_ANTHROPIC_SPOOF from "./prompt/anthropic_spoof.txt"
import PROMPT_SUMMARIZE from "./prompt/summarize.txt"
import PROMPT_TITLE from "./prompt/title.txt"
import { Project } from "../project/project"
import { Paths } from "../project/path"
import { Instance } from "../project/instance"
export namespace SystemPrompt {
export function header(providerID: string) {
@@ -33,7 +33,7 @@ export namespace SystemPrompt {
[
`Here is some useful information about the environment you are running in:`,
`<env>`,
` Working directory: ${Paths.directory}`,
` Working directory: ${Instance.directory}`,
` Is directory a git repo: ${project.vcs === "git" ? "yes" : "no"}`,
` Platform: ${process.platform}`,
` Today's date: ${new Date().toDateString()}`,
@@ -42,7 +42,7 @@ export namespace SystemPrompt {
` ${
project.vcs === "git"
? await Ripgrep.tree({
cwd: Paths.directory,
cwd: Instance.directory,
limit: 200,
})
: ""
@@ -63,7 +63,7 @@ export namespace SystemPrompt {
const paths = new Set<string>()
for (const item of CUSTOM_FILES) {
const matches = await Filesystem.findUp(item, Paths.directory, Paths.worktree)
const matches = await Filesystem.findUp(item, Instance.directory, Instance.worktree)
matches.forEach((path) => paths.add(path))
}
@@ -72,7 +72,7 @@ export namespace SystemPrompt {
if (config.instructions) {
for (const instruction of config.instructions) {
const matches = await Filesystem.globUp(instruction, Paths.directory, Paths.worktree).catch(() => [])
const matches = await Filesystem.globUp(instruction, Instance.directory, Instance.worktree).catch(() => [])
matches.forEach((path) => paths.add(path))
}
}