From 3a688edee373cbbc291a149e50e1d2802e2e29a4 Mon Sep 17 00:00:00 2001 From: Adam Malczewski Date: Wed, 24 Jun 2026 01:23:55 +0900 Subject: feat(system-prompt): add prompt:workspace_id variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lets the AI know which workspace it's in — especially useful when summoning agents. Wired through the construct context in both the regular turn flow and the compaction flow. --- packages/session-orchestrator/src/orchestrator.ts | 3 +++ packages/system-prompt/src/catalog.ts | 1 + packages/system-prompt/src/resolver.ts | 2 ++ packages/system-prompt/src/service.ts | 9 +++++---- packages/system-prompt/src/types.ts | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/session-orchestrator/src/orchestrator.ts b/packages/session-orchestrator/src/orchestrator.ts index 5398867..7599a0c 100644 --- a/packages/session-orchestrator/src/orchestrator.ts +++ b/packages/session-orchestrator/src/orchestrator.ts @@ -489,6 +489,7 @@ export function createSessionOrchestrator( effectiveCwd ?? process.cwd(), { ...(modelName !== undefined ? { model: modelName } : {}), + ...(workspaceId !== undefined ? { workspaceId } : {}), }, ); } else { @@ -952,8 +953,10 @@ export function createCompactionService( let compactionSystemPrompt: string; if (systemPromptService !== undefined) { const cwd = (await deps.conversationStore.getEffectiveCwd(conversationId)) ?? process.cwd(); + const workspaceId = await deps.conversationStore.getWorkspaceId(conversationId); const constructed = await systemPromptService.construct(conversationId, cwd, { ...(opts?.modelName !== undefined ? { model: opts.modelName } : {}), + workspaceId, }); compactionSystemPrompt = `${constructed}\n\n${COMPACTION_SYSTEM_PROMPT}`; } else { diff --git a/packages/system-prompt/src/catalog.ts b/packages/system-prompt/src/catalog.ts index cfa3bb1..1c825ab 100644 --- a/packages/system-prompt/src/catalog.ts +++ b/packages/system-prompt/src/catalog.ts @@ -16,6 +16,7 @@ export function getVariableCatalog(): SystemPromptVariable[] { { type: "prompt", name: "cwd", description: "Conversation working directory" }, { type: "prompt", name: "model", description: "Current model name" }, { type: "prompt", name: "conversation_id", description: "Conversation identifier" }, + { type: "prompt", name: "workspace_id", description: "Workspace identifier" }, { type: "git", name: "branch", description: "Current git branch" }, { type: "git", name: "status", description: "Short git status" }, { diff --git a/packages/system-prompt/src/resolver.ts b/packages/system-prompt/src/resolver.ts index eed7bcb..1ef9028 100644 --- a/packages/system-prompt/src/resolver.ts +++ b/packages/system-prompt/src/resolver.ts @@ -55,6 +55,7 @@ export interface ResolverAdapters { export interface ResolverContext { readonly model?: string; readonly conversationId?: string; + readonly workspaceId?: string; } export interface ResolveOptions { @@ -116,6 +117,7 @@ export async function resolveVariables( vars.set("prompt:cwd", cwd); vars.set("prompt:model", ctx?.model ?? null); vars.set("prompt:conversation_id", ctx?.conversationId ?? null); + vars.set("prompt:workspace_id", ctx?.workspaceId ?? null); // ── git:* ──────────────────────────────────────────────────────────────── // branch is a single value — trim fully; status keeps its leading status diff --git a/packages/system-prompt/src/service.ts b/packages/system-prompt/src/service.ts index 4b4436f..6fdae51 100644 --- a/packages/system-prompt/src/service.ts +++ b/packages/system-prompt/src/service.ts @@ -46,10 +46,11 @@ export function createSystemPromptService(deps: SystemPromptServiceDeps): System if (template === null) template = DEFAULT_TEMPLATE; const referencedKeys = extractVariables(template); - const resolverContext: ResolverContext = - context?.model !== undefined - ? { model: context.model, conversationId } - : { conversationId }; + const resolverContext: ResolverContext = { + conversationId, + ...(context?.model !== undefined ? { model: context.model } : {}), + ...(context?.workspaceId !== undefined ? { workspaceId: context.workspaceId } : {}), + }; const vars = await resolveVariables(cwd, deps.adapters, { context: resolverContext, referencedKeys, diff --git a/packages/system-prompt/src/types.ts b/packages/system-prompt/src/types.ts index dd6aa69..2690355 100644 --- a/packages/system-prompt/src/types.ts +++ b/packages/system-prompt/src/types.ts @@ -24,7 +24,7 @@ export interface SystemPromptService { construct( conversationId: string, cwd: string, - context?: { readonly model?: string }, + context?: { readonly model?: string; readonly workspaceId?: string }, ): Promise; /** Read the persisted resolved system prompt, or `null` if never constructed. */ -- cgit v1.2.3