diff options
| author | Adam Malczewski <[email protected]> | 2026-06-05 21:19:45 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-06-05 21:19:45 +0900 |
| commit | 4283d1f8a0bc3953e65962a2364c903d0015f047 (patch) | |
| tree | 4de5d2d2c1114301f03236b6dfc98a638a7c61c0 /packages/kernel/src/runtime | |
| parent | 368be032ef57638b558db659d70bfac00cb95cdd (diff) | |
| download | dispatch-4283d1f8a0bc3953e65962a2364c903d0015f047.tar.gz dispatch-4283d1f8a0bc3953e65962a2364c903d0015f047.zip | |
feat(kernel): listModels/ModelInfo + per-turn cwd contracts; add transport-contract wire package
Diffstat (limited to 'packages/kernel/src/runtime')
| -rw-r--r-- | packages/kernel/src/runtime/dispatch.ts | 4 | ||||
| -rw-r--r-- | packages/kernel/src/runtime/run-turn.test.ts | 65 | ||||
| -rw-r--r-- | packages/kernel/src/runtime/run-turn.ts | 3 |
3 files changed, 72 insertions, 0 deletions
diff --git a/packages/kernel/src/runtime/dispatch.ts b/packages/kernel/src/runtime/dispatch.ts index 1ba0849..d168319 100644 --- a/packages/kernel/src/runtime/dispatch.ts +++ b/packages/kernel/src/runtime/dispatch.ts @@ -17,6 +17,7 @@ export async function executeToolCall( conversationId: string, turnId: string, toolSpan?: Span, + cwd?: string, ): Promise<ToolResult> { if (tool === undefined) { return { content: `Unknown tool: ${call.name}`, isError: true }; @@ -31,6 +32,7 @@ export async function executeToolCall( emit(toolOutputEvent(conversationId, turnId, call.id, data, stream)); }, log: toolSpan?.log ?? createNoopLogger(), + ...(cwd !== undefined ? { cwd } : {}), }; try { return await tool.execute(call.input, ctx); @@ -54,6 +56,7 @@ export function createStepDispatcher( conversationId: string, turnId: string, toolSpans: Map<string, Span>, + cwd?: string, ): StepDispatcher { let activeCount = 0; let unsafeRunning = false; @@ -91,6 +94,7 @@ export function createStepDispatcher( conversationId, turnId, tcSpan, + cwd, ); activeCount--; if (entry.tool?.concurrencySafe === false) unsafeRunning = false; diff --git a/packages/kernel/src/runtime/run-turn.test.ts b/packages/kernel/src/runtime/run-turn.test.ts index 2dd5d2e..48a6fbc 100644 --- a/packages/kernel/src/runtime/run-turn.test.ts +++ b/packages/kernel/src/runtime/run-turn.test.ts @@ -740,6 +740,71 @@ describe("runTurn", () => { } }); + it("forwards cwd from RunTurnInput to ToolExecuteContext", async () => { + let capturedCwd: string | undefined = "SENTINEL_NOT_SET"; + + const tool = createFakeTool("cwdcheck", async (_input, ctx) => { + capturedCwd = ctx.cwd; + return { content: "ok" }; + }); + + const provider = createFakeProvider([ + [ + { type: "tool-call", toolCallId: "tc1", toolName: "cwdcheck", input: {} }, + { type: "finish", reason: "tool-calls" }, + ], + [ + { type: "text-delta", delta: "done" }, + { type: "finish", reason: "stop" }, + ], + ]); + + await runTurn({ + provider, + messages: [userMessage], + tools: [tool], + dispatch: { maxConcurrent: 1, eager: false }, + conversationId: "tab-test", + turnId: "turn-test", + emit: () => {}, + cwd: "/some/dir", + }); + + expect(capturedCwd).toBe("/some/dir"); + }); + + it("forwards undefined cwd when RunTurnInput has no cwd", async () => { + let capturedCwd: string | undefined = "SENTINEL_NOT_SET"; + + const tool = createFakeTool("cwdcheck", async (_input, ctx) => { + capturedCwd = ctx.cwd; + return { content: "ok" }; + }); + + const provider = createFakeProvider([ + [ + { type: "tool-call", toolCallId: "tc1", toolName: "cwdcheck", input: {} }, + { type: "finish", reason: "tool-calls" }, + ], + [ + { type: "text-delta", delta: "done" }, + { type: "finish", reason: "stop" }, + ], + ]); + + await runTurn({ + provider, + messages: [userMessage], + tools: [tool], + dispatch: { maxConcurrent: 1, eager: false }, + conversationId: "tab-test", + turnId: "turn-test", + emit: () => {}, + }); + + expect(capturedCwd).toBeUndefined(); + }); + it("aggregates usage across multiple steps", async () => { const provider = createFakeProvider([ [ diff --git a/packages/kernel/src/runtime/run-turn.ts b/packages/kernel/src/runtime/run-turn.ts index 01b280b..6b07e24 100644 --- a/packages/kernel/src/runtime/run-turn.ts +++ b/packages/kernel/src/runtime/run-turn.ts @@ -80,6 +80,7 @@ interface StepContext { readonly logger: Logger; readonly turnSpan: Span | undefined; readonly toolSpans: Map<string, Span>; + readonly cwd: string | undefined; } interface StepResult { @@ -202,6 +203,7 @@ async function executeStep(ctx: StepContext): Promise<StepResult> { ctx.conversationId, ctx.turnId, ctx.toolSpans, + ctx.cwd, ); try { @@ -364,6 +366,7 @@ export async function runTurn(input: RunTurnInput): Promise<RunTurnResult> { logger: turnSpan?.log ?? logger ?? createNoopLogger(), turnSpan, toolSpans, + cwd: input.cwd, }); totalUsage = addUsage(totalUsage, stepResult.usage); |
