@astralyn/pi 0.84.6 → 0.84.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/dist/core/compaction/compaction.d.ts +2 -0
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +7 -7
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/extensions/background/index.d.ts.map +1 -1
- package/dist/extensions/background/index.js +48 -72
- package/dist/extensions/background/index.js.map +1 -1
- package/dist/extensions/background/manager.d.ts.map +1 -1
- package/dist/extensions/background/manager.js +5 -3
- package/dist/extensions/background/manager.js.map +1 -1
- package/dist/extensions/background/registry.d.ts +11 -13
- package/dist/extensions/background/registry.d.ts.map +1 -1
- package/dist/extensions/background/registry.js +71 -80
- package/dist/extensions/background/registry.js.map +1 -1
- package/dist/extensions/background/render.d.ts.map +1 -1
- package/dist/extensions/background/render.js +17 -4
- package/dist/extensions/background/render.js.map +1 -1
- package/dist/extensions/deepwiki/constants.d.ts +2 -2
- package/dist/extensions/deepwiki/constants.d.ts.map +1 -1
- package/dist/extensions/deepwiki/constants.js +5 -5
- package/dist/extensions/deepwiki/constants.js.map +1 -1
- package/dist/extensions/deepwiki/schema.js +1 -1
- package/dist/extensions/deepwiki/schema.js.map +1 -1
- package/dist/extensions/question/constants.d.ts +2 -2
- package/dist/extensions/question/constants.d.ts.map +1 -1
- package/dist/extensions/question/constants.js +5 -2
- package/dist/extensions/question/constants.js.map +1 -1
- package/dist/extensions/router/dialog-host.d.ts +60 -0
- package/dist/extensions/router/dialog-host.d.ts.map +1 -0
- package/dist/extensions/router/dialog-host.js +196 -0
- package/dist/extensions/router/dialog-host.js.map +1 -0
- package/dist/extensions/router/probe.d.ts.map +1 -1
- package/dist/extensions/router/probe.js +2 -0
- package/dist/extensions/router/probe.js.map +1 -1
- package/dist/extensions/router/ui.d.ts.map +1 -1
- package/dist/extensions/router/ui.js +117 -67
- package/dist/extensions/router/ui.js.map +1 -1
- package/dist/extensions/subagent/activity.d.ts +9 -0
- package/dist/extensions/subagent/activity.d.ts.map +1 -1
- package/dist/extensions/subagent/activity.js +21 -0
- package/dist/extensions/subagent/activity.js.map +1 -1
- package/dist/extensions/subagent/agents-command.d.ts.map +1 -1
- package/dist/extensions/subagent/agents-command.js +355 -71
- package/dist/extensions/subagent/agents-command.js.map +1 -1
- package/dist/extensions/subagent/agents.d.ts.map +1 -1
- package/dist/extensions/subagent/agents.js +7 -3
- package/dist/extensions/subagent/agents.js.map +1 -1
- package/dist/extensions/subagent/constants.d.ts +1 -0
- package/dist/extensions/subagent/constants.d.ts.map +1 -1
- package/dist/extensions/subagent/constants.js +4 -0
- package/dist/extensions/subagent/constants.js.map +1 -1
- package/dist/extensions/subagent/index.js +2 -2
- package/dist/extensions/subagent/index.js.map +1 -1
- package/dist/extensions/subagent/render.d.ts.map +1 -1
- package/dist/extensions/subagent/render.js +1 -7
- package/dist/extensions/subagent/render.js.map +1 -1
- package/dist/extensions/subagent/sdk-runner.d.ts.map +1 -1
- package/dist/extensions/subagent/sdk-runner.js +19 -0
- package/dist/extensions/subagent/sdk-runner.js.map +1 -1
- package/dist/extensions/subagent/settings.d.ts.map +1 -1
- package/dist/extensions/subagent/settings.js +11 -4
- package/dist/extensions/subagent/settings.js.map +1 -1
- package/dist/extensions/subagent/state.d.ts +9 -0
- package/dist/extensions/subagent/state.d.ts.map +1 -1
- package/dist/extensions/subagent/state.js +33 -2
- package/dist/extensions/subagent/state.js.map +1 -1
- package/dist/extensions/subagent/ui/model-list.d.ts +1 -0
- package/dist/extensions/subagent/ui/model-list.d.ts.map +1 -1
- package/dist/extensions/subagent/ui/model-list.js +5 -0
- package/dist/extensions/subagent/ui/model-list.js.map +1 -1
- package/dist/extensions/todo/constants.d.ts +1 -1
- package/dist/extensions/todo/constants.d.ts.map +1 -1
- package/dist/extensions/todo/constants.js +10 -27
- package/dist/extensions/todo/constants.js.map +1 -1
- package/dist/extensions/todo/state.d.ts.map +1 -1
- package/dist/extensions/todo/state.js +27 -16
- package/dist/extensions/todo/state.js.map +1 -1
- package/dist/extensions/todo/view.d.ts.map +1 -1
- package/dist/extensions/todo/view.js +16 -5
- package/dist/extensions/todo/view.js.map +1 -1
- package/docs/bundled/extensions/background.md +3 -3
- package/docs/bundled/extensions/todo.md +2 -2
- package/docs/compaction.md +2 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-runner.js","sourceRoot":"","sources":["../../../src/extensions/subagent/sdk-runner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAiBnD,SAAS,kBAAkB,CAAC,IAAwB,EAAE,IAA0B;IAC/E,OAAO;QACN,IAAI;QACJ,wBAAwB,IAAI,CAAC,KAAK,CAAC,IAAI,iDAAiD;QACxF,wIAAwI;QACxI,6GAA6G;QAC7G,8EAA8E;QAC9E,iEAAiE;QACjE,oGAAoG;QACpG,0EAA0E;QAC1E,6IAA6I;QAC7I,wJAAwJ;QACxJ,uLAAuL;QACvL,IAAI,CAAC,KAAK,CAAC,YAAY;KACvB;SACC,MAAM,CAAC,CAAC,IAAI,EAAkB,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;SACvD,IAAI,CAAC,MAAM,CAAC,CAAC;AAChB,CAAC;AAED,SAAS,oBAAoB,CAAC,OAA8C;IAC3E,KAAK,IAAI,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CA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,uBAAuB;gBAC9B,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;aACnB,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACP,QAAQ,CAAC;gBACR,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,QAAQ;gBACjB,MAAM;gBACN,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC7D,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;aACnB,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;YAAS,CAAC;QACV,SAAS,CAAC,MAAM,EAAE,CAAC;QACnB,eAAe,EAAE,EAAE,CAAC;QACpB,WAAW,EAAE,EAAE,CAAC;QAChB,OAAO,EAAE,OAAO,EAAE,CAAC;QACnB,aAAa,EAAE,CAAC;IACjB,CAAC;AACF,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { AgentSessionEvent } from \"../../core/agent-session.ts\";\nimport type { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { DefaultResourceLoader } from \"../../core/resource-loader.ts\";\nimport { createAgentSession } from \"../../core/sdk.ts\";\nimport { SessionManager } from \"../../core/session-manager.ts\";\nimport { SettingsManager } from \"../../core/settings-manager.ts\";\nimport { finalAssistantText } from \"./activity.ts\";\nimport type { RunCancellation } from \"./cancellation.ts\";\nimport type { SubagentRunEvent } from \"./state.ts\";\nimport type { ResolvedSubagentTask } from \"./types.ts\";\n\nexport interface SdkRunnerOptions {\n\ttask: ResolvedSubagentTask;\n\t/** Cancellation scope covering this attempt (queued through session end). */\n\tscope: RunCancellation;\n\t/** Reducer input; the adapter never touches run state directly. */\n\tdispatch: (event: SubagentRunEvent) => void;\n\tmodelRuntime: ModelRuntime;\n\tagentDir: string;\n\tprojectTrusted: boolean;\n\tonProgress?: () => void;\n}\n\nfunction workerSystemPrompt(base: string | undefined, task: ResolvedSubagentTask): string {\n\treturn [\n\t\tbase,\n\t\t`You are Pi subagent \"${task.agent.name}\", working independently on one delegated task.`,\n\t\t\"You cannot see the parent conversation; rely entirely on the task briefing and repository context available in your working directory.\",\n\t\t\"Only your final message is returned to the caller; nothing you write in earlier turns is visible to anyone.\",\n\t\t\"Complete the task fully—do not gold-plate it, but do not leave it half-done.\",\n\t\t\"Stay inside the assigned working directory and delegated scope.\",\n\t\t\"Do not ask the end user questions. If blocked, report the exact blocker and what would resolve it.\",\n\t\t\"Do not spawn subagents or invoke tools outside the configured tool list.\",\n\t\t\"When referencing files in the final report, use paths relative to the task's working directory so the caller can locate them unambiguously.\",\n\t\t\"Include code snippets only when the exact text is load-bearing (a bug you found, a signature the caller asked for); do not recap code you merely read.\",\n\t\t\"End with a concise report covering findings or changes, verification performed, blockers, and unresolved risks. The caller will relay it to the user, so include only the essentials.\",\n\t\ttask.agent.systemPrompt,\n\t]\n\t\t.filter((part): part is string => Boolean(part?.trim()))\n\t\t.join(\"\\n\\n\");\n}\n\nfunction lastAssistantMessage(session: { messages: readonly AgentMessage[] }) {\n\tfor (let index = session.messages.length - 1; index >= 0; index--) {\n\t\tconst message = session.messages[index];\n\t\tif (message?.role === \"assistant\") return message;\n\t}\n\treturn undefined;\n}\n\nfunction assistantError(message: ReturnType<typeof lastAssistantMessage>): string | undefined {\n\tif (!message || message.role !== \"assistant\") return undefined;\n\treturn message.errorMessage;\n}\n\ninterface ThrottledEmitter {\n\temit: () => void;\n\t/** Drops any pending timer so nothing fires after the run has settled. */\n\tcancel: () => void;\n}\n\nfunction createThrottledEmitter(onProgress: (() => void) | undefined): ThrottledEmitter {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\treturn {\n\t\temit: () => {\n\t\t\tif (!onProgress || timer) return;\n\t\t\ttimer = setTimeout(() => {\n\t\t\t\ttimer = undefined;\n\t\t\t\tonProgress();\n\t\t\t}, 80);\n\t\t},\n\t\tcancel: () => {\n\t\t\tif (timer) clearTimeout(timer);\n\t\t\ttimer = undefined;\n\t\t},\n\t};\n}\n\ntype InitializationOutcome =\n\t| { kind: \"created\"; session: Awaited<ReturnType<typeof createAgentSession>>[\"session\"] }\n\t| { kind: \"aborted\" }\n\t| { kind: \"error\"; error: unknown };\n\n// Neither resource loading nor session creation takes an abort signal, and\n// both can hang on network work; race both against the scope. The losing\n// chain keeps running, so its eventual result or rejection is always\n// consumed by a no-op handler.\nasync function raceInitialization(\n\tchain: Promise<InitializationOutcome>,\n\tscope: RunCancellation,\n): Promise<InitializationOutcome> {\n\treturn new Promise<InitializationOutcome>((resolve) => {\n\t\tlet settled = false;\n\t\tconst finish = (outcome: InitializationOutcome): void => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tscope.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tresolve(outcome);\n\t\t};\n\t\tconst onAbort = (): void => {\n\t\t\tfinish({ kind: \"aborted\" });\n\t\t};\n\t\tif (scope.signal.aborted) {\n\t\t\tonAbort();\n\t\t\tvoid chain.then(\n\t\t\t\t() => undefined,\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tscope.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tvoid chain.then(\n\t\t\t(outcome) => finish(outcome),\n\t\t\t(error) => finish({ kind: \"error\", error }),\n\t\t);\n\t});\n}\n\n/**\n * Runs one worker attempt as a pure adapter: it owns the worker session's\n * lifecycle and translates AgentSessionEvents into SubagentRunEvents; every\n * state transition happens in the reducer on the other side of dispatch.\n */\nexport async function runSdkTask(options: SdkRunnerOptions): Promise<void> {\n\tconst { task, scope, dispatch, modelRuntime, agentDir, projectTrusted, onProgress } = options;\n\tconst throttled = createThrottledEmitter(onProgress);\n\tlet unsubscribe: (() => void) | undefined;\n\tlet unregisterAbort: (() => void) | undefined;\n\tlet session: Awaited<ReturnType<typeof createAgentSession>>[\"session\"] | undefined;\n\t// Streaming updates carry no semantic weight; the settled messages are\n\t// where usage is accounted, and worker sessions can replay them.\n\tconst seenAssistantMessages = new Set<unknown>();\n\tconst emitImmediate = (): void => onProgress?.();\n\tconst emitThrottled = throttled.emit;\n\n\tunregisterAbort = scope.onAbort(async () => {\n\t\tif (session) await session.abort();\n\t});\n\n\ttry {\n\t\tif (scope.aborted) {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport: \"\",\n\t\t\t\terror: \"Subagent was aborted before it started.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst settingsManager = SettingsManager.create(task.cwd, agentDir, { projectTrusted });\n\t\tconst resourceLoader = new DefaultResourceLoader({\n\t\t\tcwd: task.cwd,\n\t\t\tagentDir,\n\t\t\tsettingsManager,\n\t\t\tnoExtensions: true,\n\t\t\tnoSkills: true,\n\t\t\tnoPromptTemplates: true,\n\t\t\tnoThemes: true,\n\t\t\t// Read-only explorers skip AGENTS.md/CLAUDE.md: they don't need\n\t\t\t// commit/PR/style rules, and the parent interprets their results.\n\t\t\tnoContextFiles: task.agent.omitContextFiles ?? false,\n\t\t\tsystemPromptOverride: (base) => workerSystemPrompt(base, task),\n\t\t});\n\t\tconst initialization = (async (): Promise<InitializationOutcome> => {\n\t\t\tawait resourceLoader.reload();\n\t\t\tif (scope.signal.aborted) return { kind: \"aborted\" };\n\t\t\tconst created = await createAgentSession({\n\t\t\t\tcwd: task.cwd,\n\t\t\t\tagentDir,\n\t\t\t\tmodelRuntime,\n\t\t\t\tmodel: task.model,\n\t\t\t\tthinkingLevel: task.thinking,\n\t\t\t\ttools: task.agent.tools,\n\t\t\t\tresourceLoader,\n\t\t\t\tsessionManager: SessionManager.inMemory(task.cwd),\n\t\t\t\tsettingsManager,\n\t\t\t});\n\t\t\treturn { kind: \"created\", session: created.session };\n\t\t})();\n\t\tconst outcome = await raceInitialization(initialization, scope);\n\t\tif (outcome.kind === \"error\") throw outcome.error;\n\t\tif (outcome.kind === \"aborted\") {\n\t\t\t// The initialization chain cannot be cancelled. Dispose the\n\t\t\t// session if it eventually resolves, and swallow a late rejection\n\t\t\t// after this run has already settled.\n\t\t\tvoid initialization.then(\n\t\t\t\t(late) => {\n\t\t\t\t\tif (late.kind === \"created\") {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tlate.session.dispose();\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// The aborted run has no remaining channel for cleanup errors.\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t);\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport: \"\",\n\t\t\t\terror: \"Subagent was aborted during initialization.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tsession = outcome.session;\n\t\tif (scope.aborted) {\n\t\t\tawait session.abort();\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport: \"\",\n\t\t\t\terror: \"Subagent was aborted during initialization.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tunsubscribe = session.subscribe((event: AgentSessionEvent) => {\n\t\t\tif (event.type === \"auto_retry_start\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"auto_retry_start\",\n\t\t\t\t\tattempt: event.attempt,\n\t\t\t\t\tmaxAttempts: event.maxAttempts,\n\t\t\t\t\tdeadline: Date.now() + event.delayMs,\n\t\t\t\t\terror: event.errorMessage,\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"auto_retry_end\") {\n\t\t\t\tdispatch({ type: \"auto_retry_end\" });\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"turn_end\") {\n\t\t\t\tdispatch({ type: \"turn_end\" });\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"message_end\" && event.message.role === \"assistant\") {\n\t\t\t\tif (!seenAssistantMessages.has(event.message)) {\n\t\t\t\t\tseenAssistantMessages.add(event.message);\n\t\t\t\t\tdispatch({ type: \"assistant_message_settled\", usage: event.message.usage });\n\t\t\t\t} else {\n\t\t\t\t\tdispatch({ type: \"assistant_message_settled\", usage: undefined });\n\t\t\t\t}\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"tool_execution_start\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"tool_started\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\targs: event.args,\n\t\t\t\t\tstartedAt: Date.now(),\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"tool_execution_update\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"tool_updated\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\targs: event.args,\n\t\t\t\t});\n\t\t\t\temitThrottled();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"tool_execution_end\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"tool_ended\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\tresult: event.result,\n\t\t\t\t\tisError: event.isError,\n\t\t\t\t\tendedAt: Date.now(),\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t}\n\t\t});\n\t\tawait session.prompt(task.prompt);\n\t\tconst finalMessage = lastAssistantMessage(session);\n\t\tconst report = finalAssistantText(session.messages);\n\t\tconst error = assistantError(finalMessage);\n\t\tif (scope.signal.aborted || finalMessage?.stopReason === \"aborted\") {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport,\n\t\t\t\terror: error ?? \"Subagent was aborted.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t} else if (finalMessage?.stopReason === \"error\" || error) {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"failed\",\n\t\t\t\treport,\n\t\t\t\terror: error ?? \"Subagent failed.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t} else {\n\t\t\tdispatch({ type: \"settle\", verdict: \"completed\", report, error: undefined, endedAt: Date.now() });\n\t\t}\n\t} catch (error) {\n\t\tconst report = session ? finalAssistantText(session.messages) : \"\";\n\t\tif (scope.signal.aborted) {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport,\n\t\t\t\terror: \"Subagent was aborted.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t} else {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"failed\",\n\t\t\t\treport,\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t}\n\t} finally {\n\t\tthrottled.cancel();\n\t\tunregisterAbort?.();\n\t\tunsubscribe?.();\n\t\tsession?.dispose();\n\t\temitImmediate();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sdk-runner.js","sourceRoot":"","sources":["../../../src/extensions/subagent/sdk-runner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAiBnD,SAA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aACnB,CAAC,CAAC;QACJ,CAAC;aAAM,CAAC;YACP,QAAQ,CAAC;gBACR,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,QAAQ;gBACjB,MAAM;gBACN,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC7D,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE;aACnB,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;YAAS,CAAC;QACV,SAAS,CAAC,MAAM,EAAE,CAAC;QACnB,eAAe,EAAE,EAAE,CAAC;QACpB,WAAW,EAAE,EAAE,CAAC;QAChB,OAAO,EAAE,OAAO,EAAE,CAAC;QACnB,aAAa,EAAE,CAAC;IACjB,CAAC;AACF,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { AgentSessionEvent } from \"../../core/agent-session.ts\";\nimport type { ModelRuntime } from \"../../core/model-runtime.ts\";\nimport { DefaultResourceLoader } from \"../../core/resource-loader.ts\";\nimport { createAgentSession } from \"../../core/sdk.ts\";\nimport { SessionManager } from \"../../core/session-manager.ts\";\nimport { SettingsManager } from \"../../core/settings-manager.ts\";\nimport { finalAssistantText } from \"./activity.ts\";\nimport type { RunCancellation } from \"./cancellation.ts\";\nimport type { SubagentRunEvent } from \"./state.ts\";\nimport type { ResolvedSubagentTask } from \"./types.ts\";\n\nexport interface SdkRunnerOptions {\n\ttask: ResolvedSubagentTask;\n\t/** Cancellation scope covering this attempt (queued through session end). */\n\tscope: RunCancellation;\n\t/** Reducer input; the adapter never touches run state directly. */\n\tdispatch: (event: SubagentRunEvent) => void;\n\tmodelRuntime: ModelRuntime;\n\tagentDir: string;\n\tprojectTrusted: boolean;\n\tonProgress?: () => void;\n}\n\nfunction workerSystemPrompt(base: string | undefined, task: ResolvedSubagentTask): string {\n\treturn [\n\t\tbase,\n\t\t`You are Pi subagent \"${task.agent.name}\", working independently on one delegated task.`,\n\t\t\"You cannot see the parent conversation; rely entirely on the task briefing and repository context available in your working directory.\",\n\t\t\"Only your final message is returned to the caller; nothing you write in earlier turns is visible to anyone.\",\n\t\t\"Complete the task fully—do not gold-plate it, but do not leave it half-done.\",\n\t\t\"Stay inside the assigned working directory and delegated scope.\",\n\t\t\"Do not ask the end user questions. If blocked, report the exact blocker and what would resolve it.\",\n\t\t\"Do not spawn subagents or invoke tools outside the configured tool list.\",\n\t\t\"When referencing files in the final report, use paths relative to the task's working directory so the caller can locate them unambiguously.\",\n\t\t\"Include code snippets only when the exact text is load-bearing (a bug you found, a signature the caller asked for); do not recap code you merely read.\",\n\t\t\"End with a concise report covering findings or changes, verification performed, blockers, and unresolved risks. The caller will relay it to the user, so include only the essentials.\",\n\t\ttask.agent.systemPrompt,\n\t]\n\t\t.filter((part): part is string => Boolean(part?.trim()))\n\t\t.join(\"\\n\\n\");\n}\n\nfunction lastAssistantMessage(session: { messages: readonly AgentMessage[] }) {\n\tfor (let index = session.messages.length - 1; index >= 0; index--) {\n\t\tconst message = session.messages[index];\n\t\tif (message?.role === \"assistant\") return message;\n\t}\n\treturn undefined;\n}\n\nfunction assistantError(message: ReturnType<typeof lastAssistantMessage>): string | undefined {\n\tif (!message || message.role !== \"assistant\") return undefined;\n\treturn message.errorMessage;\n}\n\ninterface ThrottledEmitter {\n\temit: () => void;\n\t/** Drops any pending timer so nothing fires after the run has settled. */\n\tcancel: () => void;\n}\n\nfunction createThrottledEmitter(onProgress: (() => void) | undefined): ThrottledEmitter {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\treturn {\n\t\temit: () => {\n\t\t\tif (!onProgress || timer) return;\n\t\t\ttimer = setTimeout(() => {\n\t\t\t\ttimer = undefined;\n\t\t\t\tonProgress();\n\t\t\t}, 80);\n\t\t},\n\t\tcancel: () => {\n\t\t\tif (timer) clearTimeout(timer);\n\t\t\ttimer = undefined;\n\t\t},\n\t};\n}\n\ntype InitializationOutcome =\n\t| { kind: \"created\"; session: Awaited<ReturnType<typeof createAgentSession>>[\"session\"] }\n\t| { kind: \"aborted\" }\n\t| { kind: \"error\"; error: unknown };\n\n// Neither resource loading nor session creation takes an abort signal, and\n// both can hang on network work; race both against the scope. The losing\n// chain keeps running, so its eventual result or rejection is always\n// consumed by a no-op handler.\nasync function raceInitialization(\n\tchain: Promise<InitializationOutcome>,\n\tscope: RunCancellation,\n): Promise<InitializationOutcome> {\n\treturn new Promise<InitializationOutcome>((resolve) => {\n\t\tlet settled = false;\n\t\tconst finish = (outcome: InitializationOutcome): void => {\n\t\t\tif (settled) return;\n\t\t\tsettled = true;\n\t\t\tscope.signal.removeEventListener(\"abort\", onAbort);\n\t\t\tresolve(outcome);\n\t\t};\n\t\tconst onAbort = (): void => {\n\t\t\tfinish({ kind: \"aborted\" });\n\t\t};\n\t\tif (scope.signal.aborted) {\n\t\t\tonAbort();\n\t\t\tvoid chain.then(\n\t\t\t\t() => undefined,\n\t\t\t\t() => undefined,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tscope.signal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tvoid chain.then(\n\t\t\t(outcome) => finish(outcome),\n\t\t\t(error) => finish({ kind: \"error\", error }),\n\t\t);\n\t});\n}\n\n/**\n * Runs one worker attempt as a pure adapter: it owns the worker session's\n * lifecycle and translates AgentSessionEvents into SubagentRunEvents; every\n * state transition happens in the reducer on the other side of dispatch.\n */\nexport async function runSdkTask(options: SdkRunnerOptions): Promise<void> {\n\tconst { task, scope, dispatch, modelRuntime, agentDir, projectTrusted, onProgress } = options;\n\tconst throttled = createThrottledEmitter(onProgress);\n\tlet unsubscribe: (() => void) | undefined;\n\tlet unregisterAbort: (() => void) | undefined;\n\tlet session: Awaited<ReturnType<typeof createAgentSession>>[\"session\"] | undefined;\n\t// Streaming updates carry no semantic weight; the settled messages are\n\t// where usage is accounted, and worker sessions can replay them.\n\tconst seenAssistantMessages = new Set<unknown>();\n\tconst emitImmediate = (): void => onProgress?.();\n\tconst emitThrottled = throttled.emit;\n\n\tunregisterAbort = scope.onAbort(async () => {\n\t\tif (session) await session.abort();\n\t});\n\n\ttry {\n\t\tif (scope.aborted) {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport: \"\",\n\t\t\t\terror: \"Subagent was aborted before it started.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst settingsManager = SettingsManager.create(task.cwd, agentDir, { projectTrusted });\n\t\tconst resourceLoader = new DefaultResourceLoader({\n\t\t\tcwd: task.cwd,\n\t\t\tagentDir,\n\t\t\tsettingsManager,\n\t\t\tnoExtensions: true,\n\t\t\tnoSkills: true,\n\t\t\tnoPromptTemplates: true,\n\t\t\tnoThemes: true,\n\t\t\t// Read-only explorers skip AGENTS.md/CLAUDE.md: they don't need\n\t\t\t// commit/PR/style rules, and the parent interprets their results.\n\t\t\tnoContextFiles: task.agent.omitContextFiles ?? false,\n\t\t\tsystemPromptOverride: (base) => workerSystemPrompt(base, task),\n\t\t});\n\t\tconst initialization = (async (): Promise<InitializationOutcome> => {\n\t\t\tawait resourceLoader.reload();\n\t\t\tif (scope.signal.aborted) return { kind: \"aborted\" };\n\t\t\tconst created = await createAgentSession({\n\t\t\t\tcwd: task.cwd,\n\t\t\t\tagentDir,\n\t\t\t\tmodelRuntime,\n\t\t\t\tmodel: task.model,\n\t\t\t\tthinkingLevel: task.thinking,\n\t\t\t\ttools: task.agent.tools,\n\t\t\t\tresourceLoader,\n\t\t\t\tsessionManager: SessionManager.inMemory(task.cwd),\n\t\t\t\tsettingsManager,\n\t\t\t});\n\t\t\treturn { kind: \"created\", session: created.session };\n\t\t})();\n\t\tconst outcome = await raceInitialization(initialization, scope);\n\t\tif (outcome.kind === \"error\") throw outcome.error;\n\t\tif (outcome.kind === \"aborted\") {\n\t\t\t// The initialization chain cannot be cancelled. Dispose the\n\t\t\t// session if it eventually resolves, and swallow a late rejection\n\t\t\t// after this run has already settled.\n\t\t\tvoid initialization.then(\n\t\t\t\t(late) => {\n\t\t\t\t\tif (late.kind === \"created\") {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tlate.session.dispose();\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t// The aborted run has no remaining channel for cleanup errors.\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t);\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport: \"\",\n\t\t\t\terror: \"Subagent was aborted during initialization.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\t\tsession = outcome.session;\n\t\tif (scope.aborted) {\n\t\t\tawait session.abort();\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport: \"\",\n\t\t\t\terror: \"Subagent was aborted during initialization.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tunsubscribe = session.subscribe((event: AgentSessionEvent) => {\n\t\t\tif (event.type === \"auto_retry_start\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"auto_retry_start\",\n\t\t\t\t\tattempt: event.attempt,\n\t\t\t\t\tmaxAttempts: event.maxAttempts,\n\t\t\t\t\tdeadline: Date.now() + event.delayMs,\n\t\t\t\t\terror: event.errorMessage,\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"auto_retry_end\") {\n\t\t\t\tdispatch({ type: \"auto_retry_end\" });\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"turn_end\") {\n\t\t\t\tdispatch({ type: \"turn_end\" });\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"compaction_start\") {\n\t\t\t\tdispatch({ type: \"compaction_started\", startedAt: Date.now() });\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"compaction_end\") {\n\t\t\t\t// A worker has no status line of its own, so the compaction's outcome —\n\t\t\t\t// especially the reason a failed one blocks the next request — only\n\t\t\t\t// reaches the caller through the activity log.\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"compaction_ended\",\n\t\t\t\t\ttokensBefore: event.result?.tokensBefore,\n\t\t\t\t\ttokensAfter: event.result?.estimatedTokensAfter,\n\t\t\t\t\terror: event.errorMessage,\n\t\t\t\t\tendedAt: Date.now(),\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"message_end\" && event.message.role === \"assistant\") {\n\t\t\t\tif (!seenAssistantMessages.has(event.message)) {\n\t\t\t\t\tseenAssistantMessages.add(event.message);\n\t\t\t\t\tdispatch({ type: \"assistant_message_settled\", usage: event.message.usage });\n\t\t\t\t} else {\n\t\t\t\t\tdispatch({ type: \"assistant_message_settled\", usage: undefined });\n\t\t\t\t}\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"tool_execution_start\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"tool_started\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\targs: event.args,\n\t\t\t\t\tstartedAt: Date.now(),\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"tool_execution_update\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"tool_updated\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\targs: event.args,\n\t\t\t\t});\n\t\t\t\temitThrottled();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (event.type === \"tool_execution_end\") {\n\t\t\t\tdispatch({\n\t\t\t\t\ttype: \"tool_ended\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\tresult: event.result,\n\t\t\t\t\tisError: event.isError,\n\t\t\t\t\tendedAt: Date.now(),\n\t\t\t\t});\n\t\t\t\temitImmediate();\n\t\t\t}\n\t\t});\n\t\tawait session.prompt(task.prompt);\n\t\tconst finalMessage = lastAssistantMessage(session);\n\t\tconst report = finalAssistantText(session.messages);\n\t\tconst error = assistantError(finalMessage);\n\t\tif (scope.signal.aborted || finalMessage?.stopReason === \"aborted\") {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport,\n\t\t\t\terror: error ?? \"Subagent was aborted.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t} else if (finalMessage?.stopReason === \"error\" || error) {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"failed\",\n\t\t\t\treport,\n\t\t\t\terror: error ?? \"Subagent failed.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t} else {\n\t\t\tdispatch({ type: \"settle\", verdict: \"completed\", report, error: undefined, endedAt: Date.now() });\n\t\t}\n\t} catch (error) {\n\t\tconst report = session ? finalAssistantText(session.messages) : \"\";\n\t\tif (scope.signal.aborted) {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"aborted\",\n\t\t\t\treport,\n\t\t\t\terror: \"Subagent was aborted.\",\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t} else {\n\t\t\tdispatch({\n\t\t\t\ttype: \"settle\",\n\t\t\t\tverdict: \"failed\",\n\t\t\t\treport,\n\t\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t\t\tendedAt: Date.now(),\n\t\t\t});\n\t\t}\n\t} finally {\n\t\tthrottled.cancel();\n\t\tunregisterAbort?.();\n\t\tunsubscribe?.();\n\t\tsession?.dispose();\n\t\temitImmediate();\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/settings.ts"],"names":[],"mappings":"AAIA,OAAO,EAIN,KAAK,iBAAiB,EAEtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAiC9E,wBAAgB,qBAAqB,CAAC,QAAQ,SAAgB,GAAG,MAAM,CAEtE;AAED,wBAAgB,mBAAmB,IAAI,kBAAkB,CAExD;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAiCnE;AAeD,wBAAsB,kBAAkB,CAAC,QAAQ,SAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAS9F;AAwBD,wBAAsB,qBAAqB,CAC1C,OAAO,EAAE,iBAAiB,EAC1B,KAAK,EAAE,OAAO,CAAC,uBAAuB,CAAC,EACvC,QAAQ,SAAgB,GACtB,OAAO,CAAC,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/settings.ts"],"names":[],"mappings":"AAIA,OAAO,EAIN,KAAK,iBAAiB,EAEtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAiC9E,wBAAgB,qBAAqB,CAAC,QAAQ,SAAgB,GAAG,MAAM,CAEtE;AAED,wBAAgB,mBAAmB,IAAI,kBAAkB,CAExD;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,kBAAkB,CAiCnE;AAeD,wBAAsB,kBAAkB,CAAC,QAAQ,SAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAS9F;AAwBD,wBAAsB,qBAAqB,CAC1C,OAAO,EAAE,iBAAiB,EAC1B,KAAK,EAAE,OAAO,CAAC,uBAAuB,CAAC,EACvC,QAAQ,SAAgB,GACtB,OAAO,CAAC,kBAAkB,CAAC,CA4B7B"}
|
|
@@ -125,7 +125,8 @@ export async function updateProfileOverride(profile, patch, agentDir = getAgentD
|
|
|
125
125
|
// different profiles cannot overwrite each other.
|
|
126
126
|
return withFileMutationQueue(filePath, async () => {
|
|
127
127
|
const config = await loadSubagentConfig(agentDir);
|
|
128
|
-
const
|
|
128
|
+
const currentOverride = config.profiles[profile];
|
|
129
|
+
const current = currentOverride ?? {};
|
|
129
130
|
const next = { ...current };
|
|
130
131
|
if ("model" in patch) {
|
|
131
132
|
if (patch.model === undefined)
|
|
@@ -139,10 +140,16 @@ export async function updateProfileOverride(profile, patch, agentDir = getAgentD
|
|
|
139
140
|
else
|
|
140
141
|
next.thinking = patch.thinking;
|
|
141
142
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
const hasNext = Object.keys(next).length > 0;
|
|
144
|
+
const changed = (currentOverride !== undefined) !== hasNext ||
|
|
145
|
+
current.model !== next.model ||
|
|
146
|
+
current.thinking !== next.thinking;
|
|
147
|
+
if (!changed)
|
|
148
|
+
return config;
|
|
149
|
+
if (hasNext)
|
|
145
150
|
config.profiles[profile] = next;
|
|
151
|
+
else
|
|
152
|
+
delete config.profiles[profile];
|
|
146
153
|
await writeSubagentConfigFile(filePath, config);
|
|
147
154
|
return config;
|
|
148
155
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../src/extensions/subagent/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,iBA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,QAAQ,CAAC,OAAO,CAAC,CAAC;;YAC/D,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;QACrC,MAAM,uBAAuB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAChD,OAAO,MAAM,CAAC;IACf,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { mkdir, readFile, rename, unlink, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { withFileMutationQueue } from \"../../core/tools/file-mutation-queue.ts\";\nimport {\n\tSUBAGENT_AGENT_NAMES,\n\tSUBAGENT_CONFIG_FILE,\n\tSUBAGENT_CONFIG_VERSION,\n\ttype SubagentAgentName,\n\tTHINKING_LEVELS,\n} from \"./constants.ts\";\nimport type { SubagentConfigFile, SubagentProfileOverride } from \"./types.ts\";\n\nfunction isThinkingLevel(value: unknown): boolean {\n\treturn typeof value === \"string\" && (THINKING_LEVELS as readonly string[]).includes(value);\n}\n\n// Overrides hold concrete values only; absence means \"inherit the parent\n// session\". The file format has no compatibility aliases.\nfunction normalizeOverride(value: unknown, profile: string): SubagentProfileOverride {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new Error(`Profile override for \"${profile}\" must be an object.`);\n\t}\n\tconst input = value as Record<string, unknown>;\n\tconst output: SubagentProfileOverride = {};\n\tif (input.model !== undefined) {\n\t\tif (typeof input.model !== \"string\" || input.model.trim().length === 0 || input.model === \"inherit\") {\n\t\t\tthrow new Error(`Profile \"${profile}\" model override must be a concrete model id.`);\n\t\t}\n\t\toutput.model = input.model.trim();\n\t}\n\tif (input.thinking !== undefined) {\n\t\tif (!isThinkingLevel(input.thinking)) {\n\t\t\tthrow new Error(`Profile \"${profile}\" thinking override is invalid.`);\n\t\t}\n\t\toutput.thinking = input.thinking as SubagentProfileOverride[\"thinking\"];\n\t}\n\tconst unknownKeys = Object.keys(input).filter((key) => key !== \"model\" && key !== \"thinking\");\n\tif (unknownKeys.length > 0) {\n\t\tthrow new Error(`Profile \"${profile}\" has unsupported setting(s): ${unknownKeys.join(\", \")}.`);\n\t}\n\treturn output;\n}\n\nexport function getSubagentConfigPath(agentDir = getAgentDir()): string {\n\treturn join(agentDir, SUBAGENT_CONFIG_FILE);\n}\n\nexport function emptySubagentConfig(): SubagentConfigFile {\n\treturn { version: SUBAGENT_CONFIG_VERSION, profiles: {} };\n}\n\nexport function parseSubagentConfig(raw: string): SubagentConfigFile {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch {\n\t\tthrow new Error(`${SUBAGENT_CONFIG_FILE} is not valid JSON.`);\n\t}\n\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\tthrow new Error(`${SUBAGENT_CONFIG_FILE} must be a JSON object.`);\n\t}\n\tconst root = parsed as Record<string, unknown>;\n\tif (root.version !== SUBAGENT_CONFIG_VERSION) {\n\t\tthrow new Error(`${SUBAGENT_CONFIG_FILE} has unsupported version ${String(root.version)}.`);\n\t}\n\tif (\n\t\troot.profiles !== undefined &&\n\t\t(!root.profiles || typeof root.profiles !== \"object\" || Array.isArray(root.profiles))\n\t) {\n\t\tthrow new Error(`${SUBAGENT_CONFIG_FILE} profiles must be an object.`);\n\t}\n\tconst profiles: Record<string, SubagentProfileOverride> = {};\n\tfor (const [name, value] of Object.entries((root.profiles as Record<string, unknown> | undefined) ?? {})) {\n\t\t// The only profiles are the two built-in ones; unknown keys are rejected\n\t\t// outright (no legacy aliases or compatibility mapping).\n\t\tif (!(SUBAGENT_AGENT_NAMES as readonly string[]).includes(name)) {\n\t\t\tthrow new Error(`${SUBAGENT_CONFIG_FILE} contains unknown profile \"${name}\".`);\n\t\t}\n\t\tprofiles[name] = normalizeOverride(value, name);\n\t}\n\tconst unknownKeys = Object.keys(root).filter((key) => key !== \"version\" && key !== \"profiles\");\n\tif (unknownKeys.length > 0)\n\t\tthrow new Error(`${SUBAGENT_CONFIG_FILE} has unsupported field(s): ${unknownKeys.join(\", \")}.`);\n\treturn { version: SUBAGENT_CONFIG_VERSION, profiles };\n}\n\n// A stale or invalid config (older formats, unknown profiles, malformed\n// JSON) must not block every subagent call: reset it to an empty, fully\n// inheriting config. The reset is best-effort — when the write fails the\n// caller still gets the empty config and the next load retries the reset.\nasync function resetSubagentConfigFile(filePath: string): Promise<void> {\n\ttry {\n\t\tawait writeSubagentConfigFile(filePath, emptySubagentConfig());\n\t} catch {\n\t\t// Keep the original failure invisible to callers; an unwritable config\n\t\t// file is a setup problem, not a reason to fail the subagent call.\n\t}\n}\n\nexport async function loadSubagentConfig(agentDir = getAgentDir()): Promise<SubagentConfigFile> {\n\tconst filePath = getSubagentConfigPath(agentDir);\n\ttry {\n\t\treturn parseSubagentConfig(await readFile(filePath, \"utf8\"));\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return emptySubagentConfig();\n\t\tawait resetSubagentConfigFile(filePath);\n\t\treturn emptySubagentConfig();\n\t}\n}\n\n// Queue-free write body: read-modify-write callers run their whole\n// transaction inside the queue, so saveSubagentConfig must not queue the\n// same path again — that would deadlock.\nasync function writeSubagentConfigFile(filePath: string, config: SubagentConfigFile): Promise<void> {\n\tconst payload = `${JSON.stringify({ version: SUBAGENT_CONFIG_VERSION, profiles: config.profiles }, null, 2)}\\n`;\n\tawait mkdir(dirname(filePath), { recursive: true });\n\tconst tempPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;\n\ttry {\n\t\tawait writeFile(tempPath, payload, { encoding: \"utf8\", mode: 0o600 });\n\t\tawait rename(tempPath, filePath);\n\t} catch (error) {\n\t\ttry {\n\t\t\tawait unlink(tempPath);\n\t\t} catch {\n\t\t\t// Ignore cleanup errors and preserve the original failure.\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n// Only keys present in the patch change; a key set to undefined clears\n// that override (back to inheriting the parent session).\nexport async function updateProfileOverride(\n\tprofile: SubagentAgentName,\n\tpatch: Partial<SubagentProfileOverride>,\n\tagentDir = getAgentDir(),\n): Promise<SubagentConfigFile> {\n\tconst filePath = getSubagentConfigPath(agentDir);\n\t// Load and write run inside one queue slot so concurrent updates to\n\t// different profiles cannot overwrite each other.\n\treturn withFileMutationQueue(filePath, async () => {\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst current = config.profiles[profile] ?? {};\n\t\tconst next: SubagentProfileOverride = { ...current };\n\t\tif (\"model\" in patch) {\n\t\t\tif (patch.model === undefined) delete next.model;\n\t\t\telse next.model = patch.model;\n\t\t}\n\t\tif (\"thinking\" in patch) {\n\t\t\tif (patch.thinking === undefined) delete next.thinking;\n\t\t\telse next.thinking = patch.thinking;\n\t\t}\n\t\tif (Object.keys(next).length === 0) delete config.profiles[profile];\n\t\telse config.profiles[profile] = next;\n\t\tawait writeSubagentConfigFile(filePath, config);\n\t\treturn config;\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../../src/extensions/subagent/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yCAAyC,CAAC;AAChF,OAAO,EACN,oBAAoB,EACpB,oBAAoB,EACpB,uBAAuB,EAEvB,eAAe,GACf,MAAM,gBAAgB,CAAC;AAGxB,SAAS,eAAe,CAAC,KAAc;IACtC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAK,eAAqC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC5F,CAAC;AAED,yEAAyE;AACzE,0DAA0D;AAC1D,SAAS,iBAAiB,CAAC,KAAc,EAAE,OAAe;IACzD,IAAI,CAAC,KAA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AAC;QACrC,MAAM,uBAAuB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAChD,OAAO,MAAM,CAAC;IACf,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { mkdir, readFile, rename, unlink, writeFile } from \"node:fs/promises\";\nimport { dirname, join } from \"node:path\";\nimport { getAgentDir } from \"../../config.ts\";\nimport { withFileMutationQueue } from \"../../core/tools/file-mutation-queue.ts\";\nimport {\n\tSUBAGENT_AGENT_NAMES,\n\tSUBAGENT_CONFIG_FILE,\n\tSUBAGENT_CONFIG_VERSION,\n\ttype SubagentAgentName,\n\tTHINKING_LEVELS,\n} from \"./constants.ts\";\nimport type { SubagentConfigFile, SubagentProfileOverride } from \"./types.ts\";\n\nfunction isThinkingLevel(value: unknown): boolean {\n\treturn typeof value === \"string\" && (THINKING_LEVELS as readonly string[]).includes(value);\n}\n\n// Overrides hold concrete values only; absence means \"inherit the parent\n// session\". The file format has no compatibility aliases.\nfunction normalizeOverride(value: unknown, profile: string): SubagentProfileOverride {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new Error(`Profile override for \"${profile}\" must be an object.`);\n\t}\n\tconst input = value as Record<string, unknown>;\n\tconst output: SubagentProfileOverride = {};\n\tif (input.model !== undefined) {\n\t\tif (typeof input.model !== \"string\" || input.model.trim().length === 0 || input.model === \"inherit\") {\n\t\t\tthrow new Error(`Profile \"${profile}\" model override must be a concrete model id.`);\n\t\t}\n\t\toutput.model = input.model.trim();\n\t}\n\tif (input.thinking !== undefined) {\n\t\tif (!isThinkingLevel(input.thinking)) {\n\t\t\tthrow new Error(`Profile \"${profile}\" thinking override is invalid.`);\n\t\t}\n\t\toutput.thinking = input.thinking as SubagentProfileOverride[\"thinking\"];\n\t}\n\tconst unknownKeys = Object.keys(input).filter((key) => key !== \"model\" && key !== \"thinking\");\n\tif (unknownKeys.length > 0) {\n\t\tthrow new Error(`Profile \"${profile}\" has unsupported setting(s): ${unknownKeys.join(\", \")}.`);\n\t}\n\treturn output;\n}\n\nexport function getSubagentConfigPath(agentDir = getAgentDir()): string {\n\treturn join(agentDir, SUBAGENT_CONFIG_FILE);\n}\n\nexport function emptySubagentConfig(): SubagentConfigFile {\n\treturn { version: SUBAGENT_CONFIG_VERSION, profiles: {} };\n}\n\nexport function parseSubagentConfig(raw: string): SubagentConfigFile {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(raw);\n\t} catch {\n\t\tthrow new Error(`${SUBAGENT_CONFIG_FILE} is not valid JSON.`);\n\t}\n\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) {\n\t\tthrow new Error(`${SUBAGENT_CONFIG_FILE} must be a JSON object.`);\n\t}\n\tconst root = parsed as Record<string, unknown>;\n\tif (root.version !== SUBAGENT_CONFIG_VERSION) {\n\t\tthrow new Error(`${SUBAGENT_CONFIG_FILE} has unsupported version ${String(root.version)}.`);\n\t}\n\tif (\n\t\troot.profiles !== undefined &&\n\t\t(!root.profiles || typeof root.profiles !== \"object\" || Array.isArray(root.profiles))\n\t) {\n\t\tthrow new Error(`${SUBAGENT_CONFIG_FILE} profiles must be an object.`);\n\t}\n\tconst profiles: Record<string, SubagentProfileOverride> = {};\n\tfor (const [name, value] of Object.entries((root.profiles as Record<string, unknown> | undefined) ?? {})) {\n\t\t// The only profiles are the two built-in ones; unknown keys are rejected\n\t\t// outright (no legacy aliases or compatibility mapping).\n\t\tif (!(SUBAGENT_AGENT_NAMES as readonly string[]).includes(name)) {\n\t\t\tthrow new Error(`${SUBAGENT_CONFIG_FILE} contains unknown profile \"${name}\".`);\n\t\t}\n\t\tprofiles[name] = normalizeOverride(value, name);\n\t}\n\tconst unknownKeys = Object.keys(root).filter((key) => key !== \"version\" && key !== \"profiles\");\n\tif (unknownKeys.length > 0)\n\t\tthrow new Error(`${SUBAGENT_CONFIG_FILE} has unsupported field(s): ${unknownKeys.join(\", \")}.`);\n\treturn { version: SUBAGENT_CONFIG_VERSION, profiles };\n}\n\n// A stale or invalid config (older formats, unknown profiles, malformed\n// JSON) must not block every subagent call: reset it to an empty, fully\n// inheriting config. The reset is best-effort — when the write fails the\n// caller still gets the empty config and the next load retries the reset.\nasync function resetSubagentConfigFile(filePath: string): Promise<void> {\n\ttry {\n\t\tawait writeSubagentConfigFile(filePath, emptySubagentConfig());\n\t} catch {\n\t\t// Keep the original failure invisible to callers; an unwritable config\n\t\t// file is a setup problem, not a reason to fail the subagent call.\n\t}\n}\n\nexport async function loadSubagentConfig(agentDir = getAgentDir()): Promise<SubagentConfigFile> {\n\tconst filePath = getSubagentConfigPath(agentDir);\n\ttry {\n\t\treturn parseSubagentConfig(await readFile(filePath, \"utf8\"));\n\t} catch (error) {\n\t\tif ((error as NodeJS.ErrnoException).code === \"ENOENT\") return emptySubagentConfig();\n\t\tawait resetSubagentConfigFile(filePath);\n\t\treturn emptySubagentConfig();\n\t}\n}\n\n// Queue-free write body: read-modify-write callers run their whole\n// transaction inside the queue, so saveSubagentConfig must not queue the\n// same path again — that would deadlock.\nasync function writeSubagentConfigFile(filePath: string, config: SubagentConfigFile): Promise<void> {\n\tconst payload = `${JSON.stringify({ version: SUBAGENT_CONFIG_VERSION, profiles: config.profiles }, null, 2)}\\n`;\n\tawait mkdir(dirname(filePath), { recursive: true });\n\tconst tempPath = `${filePath}.${process.pid}.${Date.now()}.tmp`;\n\ttry {\n\t\tawait writeFile(tempPath, payload, { encoding: \"utf8\", mode: 0o600 });\n\t\tawait rename(tempPath, filePath);\n\t} catch (error) {\n\t\ttry {\n\t\t\tawait unlink(tempPath);\n\t\t} catch {\n\t\t\t// Ignore cleanup errors and preserve the original failure.\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n// Only keys present in the patch change; a key set to undefined clears\n// that override (back to inheriting the parent session).\nexport async function updateProfileOverride(\n\tprofile: SubagentAgentName,\n\tpatch: Partial<SubagentProfileOverride>,\n\tagentDir = getAgentDir(),\n): Promise<SubagentConfigFile> {\n\tconst filePath = getSubagentConfigPath(agentDir);\n\t// Load and write run inside one queue slot so concurrent updates to\n\t// different profiles cannot overwrite each other.\n\treturn withFileMutationQueue(filePath, async () => {\n\t\tconst config = await loadSubagentConfig(agentDir);\n\t\tconst currentOverride = config.profiles[profile];\n\t\tconst current = currentOverride ?? {};\n\t\tconst next: SubagentProfileOverride = { ...current };\n\t\tif (\"model\" in patch) {\n\t\t\tif (patch.model === undefined) delete next.model;\n\t\t\telse next.model = patch.model;\n\t\t}\n\t\tif (\"thinking\" in patch) {\n\t\t\tif (patch.thinking === undefined) delete next.thinking;\n\t\t\telse next.thinking = patch.thinking;\n\t\t}\n\t\tconst hasNext = Object.keys(next).length > 0;\n\t\tconst changed =\n\t\t\t(currentOverride !== undefined) !== hasNext ||\n\t\t\tcurrent.model !== next.model ||\n\t\t\tcurrent.thinking !== next.thinking;\n\t\tif (!changed) return config;\n\t\tif (hasNext) config.profiles[profile] = next;\n\t\telse delete config.profiles[profile];\n\t\tawait writeSubagentConfigFile(filePath, config);\n\t\treturn config;\n\t});\n}\n"]}
|
|
@@ -51,6 +51,15 @@ export type SubagentRunEvent = {
|
|
|
51
51
|
result: unknown;
|
|
52
52
|
isError: boolean;
|
|
53
53
|
endedAt: number;
|
|
54
|
+
} | {
|
|
55
|
+
type: "compaction_started";
|
|
56
|
+
startedAt: number;
|
|
57
|
+
} | {
|
|
58
|
+
type: "compaction_ended";
|
|
59
|
+
tokensBefore: number | undefined;
|
|
60
|
+
tokensAfter: number | undefined;
|
|
61
|
+
error: string | undefined;
|
|
62
|
+
endedAt: number;
|
|
54
63
|
} | {
|
|
55
64
|
type: "settle";
|
|
56
65
|
verdict: "completed" | "failed" | "aborted";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/extensions/subagent/state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["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IAAI,CAUvF;AAqBD;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,CAmJ5F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,SAAS,gBAAgB,EAAE,GAAG,MAAM,CAIpE;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,SAAS,kBAAkB,EAAE,GAAG,eAAe,CAAC,QAAQ,CAAC,CASvF;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,MAAM,CAAC,GAAG,OAAO,CAK1F;AAiBD,wBAAgB,aAAa,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAE9D;AAED,MAAM,WAAW,iBAAiB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,kBAAkB,EAAE,GAAG,SAAa,GAAG,iBAAiB,GAAG,SAAS,CAY7G"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { relative } from "node:path";
|
|
2
|
-
import { activitySummary, addUsage, emptyUsage, resultSummary } from "./activity.js";
|
|
3
|
-
import { ACTIVITY_LIMIT, ACTIVITY_TEXT_LIMIT, ERROR_TEXT_LIMIT, RETRY_ERROR_TEXT_LIMIT, TASK_OUTPUT_LIMIT, } from "./constants.js";
|
|
2
|
+
import { activitySummary, addUsage, compactionError, compactionSummary, emptyUsage, resultSummary, } from "./activity.js";
|
|
3
|
+
import { ACTIVITY_LIMIT, ACTIVITY_TEXT_LIMIT, COMPACTION_ACTIVITY_ID, ERROR_TEXT_LIMIT, RETRY_ERROR_TEXT_LIMIT, TASK_OUTPUT_LIMIT, } from "./constants.js";
|
|
4
4
|
import { modelId } from "./model-selection.js";
|
|
5
5
|
import { boundText } from "./text.js";
|
|
6
6
|
function runId(batchId, index) {
|
|
@@ -200,6 +200,37 @@ export function reduceRun(state, event) {
|
|
|
200
200
|
}
|
|
201
201
|
draft.currentActivity = deriveCurrentActivity(draft);
|
|
202
202
|
});
|
|
203
|
+
case "compaction_started":
|
|
204
|
+
// Auto-compaction is a synthetic activity: it has a start, an end and a
|
|
205
|
+
// failure mode just like a tool call, so it reuses the activity log and its
|
|
206
|
+
// budgets. It is not a tool call, so it never counts toward toolUses.
|
|
207
|
+
return withRevision(state, (draft) => {
|
|
208
|
+
clearRetry(draft);
|
|
209
|
+
appendActivity(draft.activities, {
|
|
210
|
+
id: COMPACTION_ACTIVITY_ID,
|
|
211
|
+
toolName: COMPACTION_ACTIVITY_ID,
|
|
212
|
+
summary: "Compacting context…",
|
|
213
|
+
status: "running",
|
|
214
|
+
startedAt: event.startedAt,
|
|
215
|
+
});
|
|
216
|
+
draft.currentActivity = deriveCurrentActivity(draft);
|
|
217
|
+
});
|
|
218
|
+
case "compaction_ended":
|
|
219
|
+
return withRevision(state, (draft) => {
|
|
220
|
+
clearRetry(draft);
|
|
221
|
+
// Only one compaction runs at a time, so the newest running entry with
|
|
222
|
+
// this id is always the one that just ended.
|
|
223
|
+
const activity = [...draft.activities]
|
|
224
|
+
.reverse()
|
|
225
|
+
.find((candidate) => candidate.id === COMPACTION_ACTIVITY_ID && candidate.status === "running");
|
|
226
|
+
if (activity) {
|
|
227
|
+
activity.status = event.error ? "failed" : "succeeded";
|
|
228
|
+
activity.endedAt = event.endedAt;
|
|
229
|
+
activity.summary = compactionSummary(event.tokensBefore, event.tokensAfter);
|
|
230
|
+
activity.resultSummary = event.error ? compactionError(event.error) : undefined;
|
|
231
|
+
}
|
|
232
|
+
draft.currentActivity = deriveCurrentActivity(draft);
|
|
233
|
+
});
|
|
203
234
|
case "settle":
|
|
204
235
|
return withRevision(state, (draft) => {
|
|
205
236
|
draft.status = event.verdict;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{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,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC;QAAE,OAAO,SAAS,CAAC;IACjE,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAClD,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,eAAe,CAAC,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;IACnF,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;IAChE,OAAO;QACN,OAAO;QACP,WAAW;QACX,gBAAgB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;QAC/E,KAAK,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;KACrE,CAAC;AACH,CAAC","sourcesContent":["import { relative } from \"node:path\";\nimport type { Usage } from \"@earendil-works/pi-ai\";\nimport { activitySummary, addUsage, emptyUsage, resultSummary } from \"./activity.ts\";\nimport {\n\tACTIVITY_LIMIT,\n\tACTIVITY_TEXT_LIMIT,\n\tERROR_TEXT_LIMIT,\n\tRETRY_ERROR_TEXT_LIMIT,\n\tTASK_OUTPUT_LIMIT,\n} from \"./constants.ts\";\nimport { modelId } from \"./model-selection.ts\";\nimport { boundText } from \"./text.ts\";\nimport type { ResolvedSubagentTask, SubagentDetails, SubagentRunDetails, ToolActivity } from \"./types.ts\";\n\n/**\n * Mutable-run state plus an internal revision counter. All transitions go\n * through {@link reduceRun}; the batch runner compares version sums instead\n * of diffing rendered fields.\n */\nexport interface SubagentRunState extends SubagentRunDetails {\n\t/** Monotonic per-run revision; bumped by every applied event. */\n\tversion: number;\n}\n\n/** The adapter layer's only output and the reducer's only input. */\nexport type SubagentRunEvent =\n\t| { type: \"slot_acquired\"; startedAt: number }\n\t| {\n\t\t\ttype: \"retry_scheduled\";\n\t\t\tattempt: number;\n\t\t\tmaxAttempts: number;\n\t\t\tdeadline: number;\n\t\t\terror: string | undefined;\n\t }\n\t| { type: \"retry_started\" }\n\t| { type: \"auto_retry_start\"; attempt: number; maxAttempts: number; deadline: number; error: string }\n\t| { type: \"auto_retry_end\" }\n\t| { type: \"turn_end\" }\n\t| { type: \"assistant_message_settled\"; usage: Usage | undefined }\n\t| { type: \"tool_started\"; toolCallId: string; toolName: string; args: unknown; startedAt: number }\n\t| { type: \"tool_updated\"; toolCallId: string; toolName: string; args: unknown }\n\t| { type: \"tool_ended\"; toolCallId: string; result: unknown; isError: boolean; endedAt: number }\n\t| {\n\t\t\ttype: \"settle\";\n\t\t\tverdict: \"completed\" | \"failed\" | \"aborted\";\n\t\t\treport: string;\n\t\t\terror: string | undefined;\n\t\t\tendedAt: number;\n\t }\n\t| { type: \"abort_while_queued\"; endedAt: number }\n\t| { type: \"abort_while_retrying\"; endedAt: number };\n\nfunction runId(batchId: string | undefined, index: number): string {\n\tif (!batchId) return `subagent-${index + 1}`;\n\t// toolCallIds are provider-shaped (\"call_ABC...\"); keep the readable\n\t// prefix, then disambiguate truncated collisions with a deterministic\n\t// hash of the full id.\n\tconst sanitized = batchId.replace(/[^A-Za-z0-9-]+/gu, \"-\").replace(/^-+|-+$/gu, \"\");\n\tconst hash = hashRunId(batchId);\n\tconst prefix = sanitized.length > 24 ? `${sanitized.slice(0, 24)}-${hash}` : sanitized || `run-${hash}`;\n\treturn `${prefix}-${index + 1}`;\n}\n\nfunction hashRunId(value: string): string {\n\tlet hash = 0x811c9dc5;\n\tfor (let index = 0; index < value.length; index++) {\n\t\thash ^= value.charCodeAt(index);\n\t\thash = Math.imul(hash, 0x01000193);\n\t}\n\treturn (hash >>> 0).toString(36).padStart(6, \"0\").slice(0, 6);\n}\n\nexport function createRunState(\n\ttask: ResolvedSubagentTask,\n\tindex: number,\n\tbatchId: string | undefined,\n\tparentCwd: string,\n): SubagentRunState {\n\treturn {\n\t\tid: runId(batchId, index),\n\t\tagent: task.agent.name,\n\t\tdescription: task.description,\n\t\t// Display-only relative path; the worker session itself uses the\n\t\t// resolved absolute task.cwd. Empty means \"same as the parent\".\n\t\tcwd: relative(parentCwd, task.cwd),\n\t\tmodel: modelId(task.model),\n\t\tthinking: task.thinking,\n\t\tstatus: \"queued\",\n\t\tactivities: [],\n\t\treport: \"\",\n\t\tusage: emptyUsage(),\n\t\tversion: 0,\n\t};\n}\n\n/** Strips internal fields for projection into the public details shape. */\nexport function toRunDetails(state: SubagentRunState): SubagentRunDetails {\n\tconst { version: _version, ...details } = state;\n\treturn details;\n}\n\n// The live \"current activity\" line is derived, never imperative: a pending\n// retry wins, then the most recent still-running tool. This is what keeps a\n// parallel batch's line correct when tools end out of order.\nexport function deriveCurrentActivity(state: SubagentRunState): string | undefined {\n\tif (state.status === \"completed\" || state.status === \"failed\" || state.status === \"aborted\") return undefined;\n\tif (state.retry) return `Retrying (${state.retry.attempt}/${state.retry.maxAttempts})…`;\n\tfor (let index = state.activities.length - 1; index >= 0; index--) {\n\t\tconst activity = state.activities[index];\n\t\tif (activity?.status === \"running\") return activity.summary;\n\t}\n\treturn undefined;\n}\n\nfunction positiveInteger(value: number, fallback: number): number {\n\treturn Number.isFinite(value) ? Math.max(1, Math.floor(value)) : fallback;\n}\n\nfunction retryError(error: string): string {\n\tconst normalized = error.replace(/\\s+/gu, \" \").trim();\n\treturn boundText(normalized, RETRY_ERROR_TEXT_LIMIT).replace(/\\s+/gu, \" \").trim();\n}\n\nfunction makeRetry(attempt: number, maxAttempts: number, deadline: number, error: string): SubagentRunState[\"retry\"] {\n\tconst normalizedAttempt = positiveInteger(attempt, 1);\n\treturn {\n\t\tattempt: normalizedAttempt,\n\t\tmaxAttempts: Math.max(normalizedAttempt, positiveInteger(maxAttempts, normalizedAttempt)),\n\t\tdeadline,\n\t\terror: retryError(error),\n\t};\n}\n\n// The in-memory activity log keeps the newest entries within both the count\n// and text budgets; a bounded O(ACTIVITY_LIMIT) rescan per event replaces\n// incremental byte bookkeeping. Exported for direct budget tests: real\n// events bound every summary, so the text-budget eviction is otherwise\n// purely defensive.\nexport function appendActivity(activities: ToolActivity[], activity: ToolActivity): void {\n\tactivities.push(activity);\n\twhile (activities.length > ACTIVITY_LIMIT) activities.shift();\n\twhile (\n\t\tactivities.reduce((total, item) => total + item.summary.length + (item.resultSummary?.length ?? 0), 0) >\n\t\tACTIVITY_TEXT_LIMIT\n\t) {\n\t\tif (activities.length <= 1) break;\n\t\tactivities.shift();\n\t}\n}\n\nfunction isTerminal(state: SubagentRunState): boolean {\n\treturn state.status === \"completed\" || state.status === \"failed\" || state.status === \"aborted\";\n}\n\nfunction withRevision(state: SubagentRunState, mutate: (draft: SubagentRunState) => void): SubagentRunState {\n\tconst draft: SubagentRunState = {\n\t\t...state,\n\t\tactivities: state.activities.map((activity) => ({ ...activity })),\n\t\tusage: { ...state.usage },\n\t};\n\tmutate(draft);\n\tdraft.version = state.version + 1;\n\treturn draft;\n}\n\nfunction clearRetry(draft: SubagentRunState): void {\n\tdraft.retry = undefined;\n}\n\n/**\n * Pure transition function; timestamps and deadlines arrive in the event.\n * Events applied after a terminal verdict are ignored (settle is idempotent)\n * — except retry_scheduled, the one sanctioned reopening transition.\n */\nexport function reduceRun(state: SubagentRunState, event: SubagentRunEvent): SubagentRunState {\n\tif (isTerminal(state) && event.type !== \"retry_scheduled\") return state;\n\n\tswitch (event.type) {\n\t\tcase \"slot_acquired\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.status = \"running\";\n\t\t\t\tdraft.startedAt = event.startedAt;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"retry_scheduled\":\n\t\t\t// The full reset matrix from the historical resetRunForRetry: only\n\t\t\t// runs that produced nothing are retried, so nothing of value is\n\t\t\t// discarded. The retry view stays visible through the backoff.\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tconst error = draft.error ?? \"Subagent failed before retry.\";\n\t\t\t\tdraft.status = \"queued\";\n\t\t\t\tdraft.error = undefined;\n\t\t\t\tdraft.startedAt = undefined;\n\t\t\t\tdraft.endedAt = undefined;\n\t\t\t\tdraft.report = \"\";\n\t\t\t\tdraft.activities = [];\n\t\t\t\tdraft.usage = emptyUsage();\n\t\t\t\tdraft.retry = makeRetry(event.attempt, event.maxAttempts, event.deadline, error);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"retry_started\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"auto_retry_start\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.retry = makeRetry(event.attempt, event.maxAttempts, event.deadline, event.error);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"auto_retry_end\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"turn_end\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.usage.turns++;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"assistant_message_settled\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\taddUsage(draft.usage, event.usage);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"tool_started\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.usage.toolUses++;\n\t\t\t\tappendActivity(draft.activities, {\n\t\t\t\t\tid: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\tsummary: activitySummary(event.toolName, event.args),\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\t});\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"tool_updated\": {\n\t\t\tconst summary = activitySummary(event.toolName, event.args);\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tconst activity =\n\t\t\t\t\tdraft.activities.find(\n\t\t\t\t\t\t(candidate) => candidate.id === event.toolCallId && candidate.status === \"running\",\n\t\t\t\t\t) ?? [...draft.activities].reverse().find((candidate) => candidate.status === \"running\");\n\t\t\t\tif (activity) activity.summary = summary;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\t}\n\t\tcase \"tool_ended\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tconst activity = draft.activities.find((candidate) => candidate.id === event.toolCallId);\n\t\t\t\tif (activity && activity.status === \"running\") {\n\t\t\t\t\tactivity.status = event.isError ? \"failed\" : \"succeeded\";\n\t\t\t\t\tactivity.endedAt = event.endedAt;\n\t\t\t\t\tactivity.resultSummary = resultSummary(event.result) || undefined;\n\t\t\t\t}\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"settle\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.status = event.verdict;\n\t\t\t\tdraft.report = boundText(event.report, TASK_OUTPUT_LIMIT);\n\t\t\t\tdraft.error = event.error ? boundText(event.error, ERROR_TEXT_LIMIT) : undefined;\n\t\t\t\tdraft.endedAt = event.endedAt;\n\t\t\t\tdraft.retry = undefined;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity({ ...draft, status: event.verdict });\n\t\t\t});\n\t\tcase \"abort_while_queued\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.status = \"aborted\";\n\t\t\t\tdraft.error = \"Subagent was aborted while queued.\";\n\t\t\t\tdraft.endedAt = event.endedAt;\n\t\t\t\tdraft.retry = undefined;\n\t\t\t\tdraft.currentActivity = undefined;\n\t\t\t});\n\t\tcase \"abort_while_retrying\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.status = \"aborted\";\n\t\t\t\tdraft.error = \"Subagent was aborted while waiting to retry.\";\n\t\t\t\tdraft.endedAt = event.endedAt;\n\t\t\t\tdraft.retry = undefined;\n\t\t\t\tdraft.currentActivity = undefined;\n\t\t\t});\n\t}\n}\n\nexport function versionSum(runs: readonly SubagentRunState[]): number {\n\tlet total = 0;\n\tfor (const run of runs) total += run.version;\n\treturn total;\n}\n\nexport function statusOf(runs: readonly SubagentRunDetails[]): SubagentDetails[\"status\"] {\n\tif (runs.length === 0) return \"running\";\n\t// Active beats terminal: any queued or running run keeps the batch\n\t// \"running\" regardless of what the others have settled to.\n\tif (runs.some((run) => run.status === \"queued\" || run.status === \"running\")) return \"running\";\n\tif (runs.every((run) => run.status === \"completed\")) return \"completed\";\n\tif (runs.some((run) => run.status === \"completed\")) return \"partial\";\n\tif (runs.every((run) => run.status === \"aborted\")) return \"aborted\";\n\treturn \"failed\";\n}\n\nexport function isSubagentError(details: Pick<SubagentDetails, \"status\" | \"runs\">): boolean {\n\tif (details.status !== \"failed\" && details.status !== \"aborted\") return false;\n\t// A batch with any successful run is a partial result, not an error:\n\t// per-run status is already reported in the content sections.\n\treturn !details.runs.some((run) => run.status === \"completed\");\n}\n\nfunction statusText(details: SubagentDetails): string {\n\tif (details.runs.length === 0) return \"Initializing…\";\n\tconst running = details.runs.filter((run) => run.status === \"running\").length;\n\tconst queued = details.runs.filter((run) => run.status === \"queued\").length;\n\tconst completed = details.runs.filter((run) => run.status === \"completed\").length;\n\tconst failed = details.runs.filter((run) => run.status === \"failed\").length;\n\tconst aborted = details.runs.filter((run) => run.status === \"aborted\").length;\n\tconst parts = [`${completed}/${details.runs.length} complete`];\n\tif (running) parts.push(`${running} running`);\n\tif (queued) parts.push(`${queued} queued`);\n\tif (failed) parts.push(`${failed} failed`);\n\tif (aborted) parts.push(`${aborted} aborted`);\n\treturn parts.join(\" · \");\n}\n\nexport function statusSummary(details: SubagentDetails): string {\n\treturn statusText(details);\n}\n\nexport interface SubagentRetryView {\n\tattempt: number;\n\tmaxAttempts: number;\n\tremainingSeconds: number;\n\terror: string;\n}\n\nexport function getSubagentRetryView(run: SubagentRunDetails, now = Date.now()): SubagentRetryView | undefined {\n\tconst retry = run.retry;\n\tif (!retry || !Number.isFinite(retry.deadline)) return undefined;\n\tconst attempt = positiveInteger(retry.attempt, 1);\n\tconst maxAttempts = Math.max(attempt, positiveInteger(retry.maxAttempts, attempt));\n\tconst currentTime = Number.isFinite(now) ? now : retry.deadline;\n\treturn {\n\t\tattempt,\n\t\tmaxAttempts,\n\t\tremainingSeconds: Math.max(0, Math.ceil((retry.deadline - currentTime) / 1000)),\n\t\terror: retryError(typeof retry.error === \"string\" ? retry.error : \"\"),\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/extensions/subagent/state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EACN,eAAe,EACf,QAAQ,EACR,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,aAAa,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EACN,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAiDtC,SAAS,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AQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC;IAChE,OAAO;QACN,OAAO;QACP,WAAW;QACX,gBAAgB,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,IAAI,CAAC,CAAC;QAC/E,KAAK,EAAE,UAAU,CAAC,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;KACrE,CAAC;AACH,CAAC","sourcesContent":["import { relative } from \"node:path\";\nimport type { Usage } from \"@earendil-works/pi-ai\";\nimport {\n\tactivitySummary,\n\taddUsage,\n\tcompactionError,\n\tcompactionSummary,\n\temptyUsage,\n\tresultSummary,\n} from \"./activity.ts\";\nimport {\n\tACTIVITY_LIMIT,\n\tACTIVITY_TEXT_LIMIT,\n\tCOMPACTION_ACTIVITY_ID,\n\tERROR_TEXT_LIMIT,\n\tRETRY_ERROR_TEXT_LIMIT,\n\tTASK_OUTPUT_LIMIT,\n} from \"./constants.ts\";\nimport { modelId } from \"./model-selection.ts\";\nimport { boundText } from \"./text.ts\";\nimport type { ResolvedSubagentTask, SubagentDetails, SubagentRunDetails, ToolActivity } from \"./types.ts\";\n\n/**\n * Mutable-run state plus an internal revision counter. All transitions go\n * through {@link reduceRun}; the batch runner compares version sums instead\n * of diffing rendered fields.\n */\nexport interface SubagentRunState extends SubagentRunDetails {\n\t/** Monotonic per-run revision; bumped by every applied event. */\n\tversion: number;\n}\n\n/** The adapter layer's only output and the reducer's only input. */\nexport type SubagentRunEvent =\n\t| { type: \"slot_acquired\"; startedAt: number }\n\t| {\n\t\t\ttype: \"retry_scheduled\";\n\t\t\tattempt: number;\n\t\t\tmaxAttempts: number;\n\t\t\tdeadline: number;\n\t\t\terror: string | undefined;\n\t }\n\t| { type: \"retry_started\" }\n\t| { type: \"auto_retry_start\"; attempt: number; maxAttempts: number; deadline: number; error: string }\n\t| { type: \"auto_retry_end\" }\n\t| { type: \"turn_end\" }\n\t| { type: \"assistant_message_settled\"; usage: Usage | undefined }\n\t| { type: \"tool_started\"; toolCallId: string; toolName: string; args: unknown; startedAt: number }\n\t| { type: \"tool_updated\"; toolCallId: string; toolName: string; args: unknown }\n\t| { type: \"tool_ended\"; toolCallId: string; result: unknown; isError: boolean; endedAt: number }\n\t| { type: \"compaction_started\"; startedAt: number }\n\t| {\n\t\t\ttype: \"compaction_ended\";\n\t\t\ttokensBefore: number | undefined;\n\t\t\ttokensAfter: number | undefined;\n\t\t\terror: string | undefined;\n\t\t\tendedAt: number;\n\t }\n\t| {\n\t\t\ttype: \"settle\";\n\t\t\tverdict: \"completed\" | \"failed\" | \"aborted\";\n\t\t\treport: string;\n\t\t\terror: string | undefined;\n\t\t\tendedAt: number;\n\t }\n\t| { type: \"abort_while_queued\"; endedAt: number }\n\t| { type: \"abort_while_retrying\"; endedAt: number };\n\nfunction runId(batchId: string | undefined, index: number): string {\n\tif (!batchId) return `subagent-${index + 1}`;\n\t// toolCallIds are provider-shaped (\"call_ABC...\"); keep the readable\n\t// prefix, then disambiguate truncated collisions with a deterministic\n\t// hash of the full id.\n\tconst sanitized = batchId.replace(/[^A-Za-z0-9-]+/gu, \"-\").replace(/^-+|-+$/gu, \"\");\n\tconst hash = hashRunId(batchId);\n\tconst prefix = sanitized.length > 24 ? `${sanitized.slice(0, 24)}-${hash}` : sanitized || `run-${hash}`;\n\treturn `${prefix}-${index + 1}`;\n}\n\nfunction hashRunId(value: string): string {\n\tlet hash = 0x811c9dc5;\n\tfor (let index = 0; index < value.length; index++) {\n\t\thash ^= value.charCodeAt(index);\n\t\thash = Math.imul(hash, 0x01000193);\n\t}\n\treturn (hash >>> 0).toString(36).padStart(6, \"0\").slice(0, 6);\n}\n\nexport function createRunState(\n\ttask: ResolvedSubagentTask,\n\tindex: number,\n\tbatchId: string | undefined,\n\tparentCwd: string,\n): SubagentRunState {\n\treturn {\n\t\tid: runId(batchId, index),\n\t\tagent: task.agent.name,\n\t\tdescription: task.description,\n\t\t// Display-only relative path; the worker session itself uses the\n\t\t// resolved absolute task.cwd. Empty means \"same as the parent\".\n\t\tcwd: relative(parentCwd, task.cwd),\n\t\tmodel: modelId(task.model),\n\t\tthinking: task.thinking,\n\t\tstatus: \"queued\",\n\t\tactivities: [],\n\t\treport: \"\",\n\t\tusage: emptyUsage(),\n\t\tversion: 0,\n\t};\n}\n\n/** Strips internal fields for projection into the public details shape. */\nexport function toRunDetails(state: SubagentRunState): SubagentRunDetails {\n\tconst { version: _version, ...details } = state;\n\treturn details;\n}\n\n// The live \"current activity\" line is derived, never imperative: a pending\n// retry wins, then the most recent still-running tool. This is what keeps a\n// parallel batch's line correct when tools end out of order.\nexport function deriveCurrentActivity(state: SubagentRunState): string | undefined {\n\tif (state.status === \"completed\" || state.status === \"failed\" || state.status === \"aborted\") return undefined;\n\tif (state.retry) return `Retrying (${state.retry.attempt}/${state.retry.maxAttempts})…`;\n\tfor (let index = state.activities.length - 1; index >= 0; index--) {\n\t\tconst activity = state.activities[index];\n\t\tif (activity?.status === \"running\") return activity.summary;\n\t}\n\treturn undefined;\n}\n\nfunction positiveInteger(value: number, fallback: number): number {\n\treturn Number.isFinite(value) ? Math.max(1, Math.floor(value)) : fallback;\n}\n\nfunction retryError(error: string): string {\n\tconst normalized = error.replace(/\\s+/gu, \" \").trim();\n\treturn boundText(normalized, RETRY_ERROR_TEXT_LIMIT).replace(/\\s+/gu, \" \").trim();\n}\n\nfunction makeRetry(attempt: number, maxAttempts: number, deadline: number, error: string): SubagentRunState[\"retry\"] {\n\tconst normalizedAttempt = positiveInteger(attempt, 1);\n\treturn {\n\t\tattempt: normalizedAttempt,\n\t\tmaxAttempts: Math.max(normalizedAttempt, positiveInteger(maxAttempts, normalizedAttempt)),\n\t\tdeadline,\n\t\terror: retryError(error),\n\t};\n}\n\n// The in-memory activity log keeps the newest entries within both the count\n// and text budgets; a bounded O(ACTIVITY_LIMIT) rescan per event replaces\n// incremental byte bookkeeping. Exported for direct budget tests: real\n// events bound every summary, so the text-budget eviction is otherwise\n// purely defensive.\nexport function appendActivity(activities: ToolActivity[], activity: ToolActivity): void {\n\tactivities.push(activity);\n\twhile (activities.length > ACTIVITY_LIMIT) activities.shift();\n\twhile (\n\t\tactivities.reduce((total, item) => total + item.summary.length + (item.resultSummary?.length ?? 0), 0) >\n\t\tACTIVITY_TEXT_LIMIT\n\t) {\n\t\tif (activities.length <= 1) break;\n\t\tactivities.shift();\n\t}\n}\n\nfunction isTerminal(state: SubagentRunState): boolean {\n\treturn state.status === \"completed\" || state.status === \"failed\" || state.status === \"aborted\";\n}\n\nfunction withRevision(state: SubagentRunState, mutate: (draft: SubagentRunState) => void): SubagentRunState {\n\tconst draft: SubagentRunState = {\n\t\t...state,\n\t\tactivities: state.activities.map((activity) => ({ ...activity })),\n\t\tusage: { ...state.usage },\n\t};\n\tmutate(draft);\n\tdraft.version = state.version + 1;\n\treturn draft;\n}\n\nfunction clearRetry(draft: SubagentRunState): void {\n\tdraft.retry = undefined;\n}\n\n/**\n * Pure transition function; timestamps and deadlines arrive in the event.\n * Events applied after a terminal verdict are ignored (settle is idempotent)\n * — except retry_scheduled, the one sanctioned reopening transition.\n */\nexport function reduceRun(state: SubagentRunState, event: SubagentRunEvent): SubagentRunState {\n\tif (isTerminal(state) && event.type !== \"retry_scheduled\") return state;\n\n\tswitch (event.type) {\n\t\tcase \"slot_acquired\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.status = \"running\";\n\t\t\t\tdraft.startedAt = event.startedAt;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"retry_scheduled\":\n\t\t\t// The full reset matrix from the historical resetRunForRetry: only\n\t\t\t// runs that produced nothing are retried, so nothing of value is\n\t\t\t// discarded. The retry view stays visible through the backoff.\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tconst error = draft.error ?? \"Subagent failed before retry.\";\n\t\t\t\tdraft.status = \"queued\";\n\t\t\t\tdraft.error = undefined;\n\t\t\t\tdraft.startedAt = undefined;\n\t\t\t\tdraft.endedAt = undefined;\n\t\t\t\tdraft.report = \"\";\n\t\t\t\tdraft.activities = [];\n\t\t\t\tdraft.usage = emptyUsage();\n\t\t\t\tdraft.retry = makeRetry(event.attempt, event.maxAttempts, event.deadline, error);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"retry_started\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"auto_retry_start\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.retry = makeRetry(event.attempt, event.maxAttempts, event.deadline, event.error);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"auto_retry_end\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"turn_end\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.usage.turns++;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"assistant_message_settled\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\taddUsage(draft.usage, event.usage);\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"tool_started\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tdraft.usage.toolUses++;\n\t\t\t\tappendActivity(draft.activities, {\n\t\t\t\t\tid: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\tsummary: activitySummary(event.toolName, event.args),\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\t});\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"tool_updated\": {\n\t\t\tconst summary = activitySummary(event.toolName, event.args);\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tconst activity =\n\t\t\t\t\tdraft.activities.find(\n\t\t\t\t\t\t(candidate) => candidate.id === event.toolCallId && candidate.status === \"running\",\n\t\t\t\t\t) ?? [...draft.activities].reverse().find((candidate) => candidate.status === \"running\");\n\t\t\t\tif (activity) activity.summary = summary;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\t}\n\t\tcase \"tool_ended\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tconst activity = draft.activities.find((candidate) => candidate.id === event.toolCallId);\n\t\t\t\tif (activity && activity.status === \"running\") {\n\t\t\t\t\tactivity.status = event.isError ? \"failed\" : \"succeeded\";\n\t\t\t\t\tactivity.endedAt = event.endedAt;\n\t\t\t\t\tactivity.resultSummary = resultSummary(event.result) || undefined;\n\t\t\t\t}\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"compaction_started\":\n\t\t\t// Auto-compaction is a synthetic activity: it has a start, an end and a\n\t\t\t// failure mode just like a tool call, so it reuses the activity log and its\n\t\t\t// budgets. It is not a tool call, so it never counts toward toolUses.\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\tappendActivity(draft.activities, {\n\t\t\t\t\tid: COMPACTION_ACTIVITY_ID,\n\t\t\t\t\ttoolName: COMPACTION_ACTIVITY_ID,\n\t\t\t\t\tsummary: \"Compacting context…\",\n\t\t\t\t\tstatus: \"running\",\n\t\t\t\t\tstartedAt: event.startedAt,\n\t\t\t\t});\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"compaction_ended\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tclearRetry(draft);\n\t\t\t\t// Only one compaction runs at a time, so the newest running entry with\n\t\t\t\t// this id is always the one that just ended.\n\t\t\t\tconst activity = [...draft.activities]\n\t\t\t\t\t.reverse()\n\t\t\t\t\t.find((candidate) => candidate.id === COMPACTION_ACTIVITY_ID && candidate.status === \"running\");\n\t\t\t\tif (activity) {\n\t\t\t\t\tactivity.status = event.error ? \"failed\" : \"succeeded\";\n\t\t\t\t\tactivity.endedAt = event.endedAt;\n\t\t\t\t\tactivity.summary = compactionSummary(event.tokensBefore, event.tokensAfter);\n\t\t\t\t\tactivity.resultSummary = event.error ? compactionError(event.error) : undefined;\n\t\t\t\t}\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity(draft);\n\t\t\t});\n\t\tcase \"settle\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.status = event.verdict;\n\t\t\t\tdraft.report = boundText(event.report, TASK_OUTPUT_LIMIT);\n\t\t\t\tdraft.error = event.error ? boundText(event.error, ERROR_TEXT_LIMIT) : undefined;\n\t\t\t\tdraft.endedAt = event.endedAt;\n\t\t\t\tdraft.retry = undefined;\n\t\t\t\tdraft.currentActivity = deriveCurrentActivity({ ...draft, status: event.verdict });\n\t\t\t});\n\t\tcase \"abort_while_queued\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.status = \"aborted\";\n\t\t\t\tdraft.error = \"Subagent was aborted while queued.\";\n\t\t\t\tdraft.endedAt = event.endedAt;\n\t\t\t\tdraft.retry = undefined;\n\t\t\t\tdraft.currentActivity = undefined;\n\t\t\t});\n\t\tcase \"abort_while_retrying\":\n\t\t\treturn withRevision(state, (draft) => {\n\t\t\t\tdraft.status = \"aborted\";\n\t\t\t\tdraft.error = \"Subagent was aborted while waiting to retry.\";\n\t\t\t\tdraft.endedAt = event.endedAt;\n\t\t\t\tdraft.retry = undefined;\n\t\t\t\tdraft.currentActivity = undefined;\n\t\t\t});\n\t}\n}\n\nexport function versionSum(runs: readonly SubagentRunState[]): number {\n\tlet total = 0;\n\tfor (const run of runs) total += run.version;\n\treturn total;\n}\n\nexport function statusOf(runs: readonly SubagentRunDetails[]): SubagentDetails[\"status\"] {\n\tif (runs.length === 0) return \"running\";\n\t// Active beats terminal: any queued or running run keeps the batch\n\t// \"running\" regardless of what the others have settled to.\n\tif (runs.some((run) => run.status === \"queued\" || run.status === \"running\")) return \"running\";\n\tif (runs.every((run) => run.status === \"completed\")) return \"completed\";\n\tif (runs.some((run) => run.status === \"completed\")) return \"partial\";\n\tif (runs.every((run) => run.status === \"aborted\")) return \"aborted\";\n\treturn \"failed\";\n}\n\nexport function isSubagentError(details: Pick<SubagentDetails, \"status\" | \"runs\">): boolean {\n\tif (details.status !== \"failed\" && details.status !== \"aborted\") return false;\n\t// A batch with any successful run is a partial result, not an error:\n\t// per-run status is already reported in the content sections.\n\treturn !details.runs.some((run) => run.status === \"completed\");\n}\n\nfunction statusText(details: SubagentDetails): string {\n\tif (details.runs.length === 0) return \"Initializing…\";\n\tconst running = details.runs.filter((run) => run.status === \"running\").length;\n\tconst queued = details.runs.filter((run) => run.status === \"queued\").length;\n\tconst completed = details.runs.filter((run) => run.status === \"completed\").length;\n\tconst failed = details.runs.filter((run) => run.status === \"failed\").length;\n\tconst aborted = details.runs.filter((run) => run.status === \"aborted\").length;\n\tconst parts = [`${completed}/${details.runs.length} complete`];\n\tif (running) parts.push(`${running} running`);\n\tif (queued) parts.push(`${queued} queued`);\n\tif (failed) parts.push(`${failed} failed`);\n\tif (aborted) parts.push(`${aborted} aborted`);\n\treturn parts.join(\" · \");\n}\n\nexport function statusSummary(details: SubagentDetails): string {\n\treturn statusText(details);\n}\n\nexport interface SubagentRetryView {\n\tattempt: number;\n\tmaxAttempts: number;\n\tremainingSeconds: number;\n\terror: string;\n}\n\nexport function getSubagentRetryView(run: SubagentRunDetails, now = Date.now()): SubagentRetryView | undefined {\n\tconst retry = run.retry;\n\tif (!retry || !Number.isFinite(retry.deadline)) return undefined;\n\tconst attempt = positiveInteger(retry.attempt, 1);\n\tconst maxAttempts = Math.max(attempt, positiveInteger(retry.maxAttempts, attempt));\n\tconst currentTime = Number.isFinite(now) ? now : retry.deadline;\n\treturn {\n\t\tattempt,\n\t\tmaxAttempts,\n\t\tremainingSeconds: Math.max(0, Math.ceil((retry.deadline - currentTime) / 1000)),\n\t\terror: retryError(typeof retry.error === \"string\" ? retry.error : \"\"),\n\t};\n}\n"]}
|
|
@@ -62,6 +62,7 @@ export declare class ProfileModelListComponent extends Container implements Focu
|
|
|
62
62
|
getSearchValue(): string;
|
|
63
63
|
updateModels(models: readonly Model<Api>[]): void;
|
|
64
64
|
setStatus(message: string | undefined, tone?: StatusTone): void;
|
|
65
|
+
invalidate(): void;
|
|
65
66
|
handleInput(data: string): void;
|
|
66
67
|
}
|
|
67
68
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-list.d.ts","sourceRoot":"","sources":["../../../../src/extensions/subagent/ui/model-list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACN,SAAS,EACT,KAAK,SAAS,EAGd,KAAK,kBAAkB,EAIvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAKvE,KAAK,UAAU,GAAG,KAAK,GAAG,QAAQ,CAAC;AACnC,KAAK,UAAU,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC;AAEhD,MAAM,WAAW,kBAAkB;IAClC,iEAAiE;IACjE,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,oFAAoF;IACpF,KAAK,EAAE,KAA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C,KAAK,CAAa;IAC1B,OAAO,CAAC,aAAa,CAAqB;IAC1C,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,QAAQ,CAAS;IAEzB,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,IAAI,OAAO,CAAC,KAAK,EAAE,OAAO,EAGzB;gBAEW,OAAO,EAAE,uBAAuB;IAsB5C,OAAO,CAAC,iBAAiB;IAYzB,OAAO,CAAC,eAAe;IAYvB,OAAO,CAAC,qBAAqB;IAa7B,OAAO,CAAC,YAAY;IAcpB,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,eAAe;IAqBvB,OAAO,CAAC,WAAW;IAYnB,OAAO,CAAC,UAAU;IA8ClB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,WAAW;IASnB,iBAAiB,IAAI,kBAAkB,GAAG,SAAS;IAMnD,QAAQ,IAAI,UAAU;IAItB,cAAc,IAAI,MAAM;IAIxB,YAAY,CAAC,MAAM,EAAE,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI;IAMjD,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,GAAE,UAAoB,GAAG,IAAI;IAM/D,UAAU,IAAI,IAAI;IAM3B,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;CAiB/B"}
|
|
@@ -213,6 +213,11 @@ export class ProfileModelListComponent extends Container {
|
|
|
213
213
|
this.statusTone = tone;
|
|
214
214
|
this.updateList();
|
|
215
215
|
}
|
|
216
|
+
invalidate() {
|
|
217
|
+
this.updateScopeView();
|
|
218
|
+
this.updateList();
|
|
219
|
+
super.invalidate();
|
|
220
|
+
}
|
|
216
221
|
handleInput(data) {
|
|
217
222
|
if (this.keybindings.matches(data, "tui.input.tab")) {
|
|
218
223
|
this.toggleScope();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-list.js","sourceRoot":"","sources":["../../../../src/extensions/sub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CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YACnC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/C,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { Api, Model } from \"@earendil-works/pi-ai\";\nimport {\n\tContainer,\n\ttype Focusable,\n\tfuzzyFilter,\n\tInput,\n\ttype KeybindingsManager,\n\tSpacer,\n\tText,\n\tTruncatedText,\n} from \"@earendil-works/pi-tui\";\nimport type { Theme } from \"../../../modes/interactive/theme/theme.ts\";\nimport { modelId, parseModelSpec } from \"../model-selection.ts\";\n\nconst MAX_VISIBLE_MODELS = 10;\n\ntype ModelScope = \"all\" | \"scoped\";\ntype StatusTone = \"muted\" | \"success\" | \"error\";\n\nexport interface ProfileModelChoice {\n\t/** Undefined represents inheriting the current session model. */\n\tmodelId: string | undefined;\n\t/** Effective model for capability checks; unavailable saved overrides have none. */\n\tmodel: Model<Api> | undefined;\n\tunavailable: boolean;\n}\n\nexport interface ProfileModelListOptions {\n\ttheme: Theme;\n\tkeybindings: KeybindingsManager;\n\tmodels: readonly Model<Api>[];\n\tscopedModels: readonly { model: Model<Api> }[];\n\tcurrentSessionModel: Model<Api> | undefined;\n\tsavedModelId: string | undefined;\n\t/** Reports the confirmed choice; undefined means the picker was dismissed. */\n\tonDone: (choice: ProfileModelChoice | undefined) => void;\n}\n\ninterface ModelChoiceItem extends ProfileModelChoice {\n\tkey: string;\n\tprovider: string;\n\tid: string;\n\tname: string | undefined;\n}\n\nfunction compareModels(left: Model<Api>, right: Model<Api>): number {\n\tconst provider = left.provider.localeCompare(right.provider);\n\treturn provider !== 0 ? provider : left.id.localeCompare(right.id);\n}\n\nfunction modelSearchText(item: ModelChoiceItem): string {\n\tif (item.modelId === undefined) {\n\t\tconst inherited = item.model ? ` ${modelId(item.model)} ${item.model.name}` : \"\";\n\t\treturn `inherit${inherited}`;\n\t}\n\tconst name = item.name ? ` ${item.name}` : \"\";\n\treturn `${item.provider} ${item.provider}/${item.id} ${item.provider} ${item.id}${name}`;\n}\n\n/** Searchable /model-style model picker used by /agents; confirm reports the selected choice. */\nexport class ProfileModelListComponent extends Container implements Focusable {\n\tprivate readonly theme: Theme;\n\tprivate readonly keybindings: KeybindingsManager;\n\tprivate readonly currentSessionModel: Model<Api> | undefined;\n\tprivate readonly savedModelId: string | undefined;\n\tprivate readonly scopedModelKeys: Set<string>;\n\tprivate readonly onDone: (choice: ProfileModelChoice | undefined) => void;\n\tprivate readonly searchInput: Input;\n\tprivate readonly scopeContainer: Container;\n\tprivate readonly listContainer: Container;\n\tprivate models: Model<Api>[];\n\tprivate allChoices: ModelChoiceItem[] = [];\n\tprivate scopedChoices: ModelChoiceItem[] = [];\n\tprivate activeChoices: ModelChoiceItem[] = [];\n\tprivate filteredChoices: ModelChoiceItem[] = [];\n\tprivate selectedIndex = 0;\n\tprivate scope: ModelScope;\n\tprivate statusMessage: string | undefined;\n\tprivate statusTone: StatusTone = \"muted\";\n\tprivate _focused = false;\n\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\n\tconstructor(options: ProfileModelListOptions) {\n\t\tsuper();\n\t\tthis.theme = options.theme;\n\t\tthis.keybindings = options.keybindings;\n\t\tthis.models = [...options.models];\n\t\tthis.currentSessionModel = options.currentSessionModel;\n\t\tthis.savedModelId = options.savedModelId;\n\t\tthis.scopedModelKeys = new Set(options.scopedModels.map(({ model }) => modelId(model)));\n\t\tthis.scope = this.scopedModelKeys.size > 0 ? \"scoped\" : \"all\";\n\t\tthis.onDone = options.onDone;\n\n\t\tthis.scopeContainer = new Container();\n\t\tthis.addChild(this.scopeContainer);\n\t\tthis.searchInput = new Input();\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\tthis.rebuildChoices(this.savedModelId ?? \"\");\n\t}\n\n\tprivate makeInheritChoice(): ModelChoiceItem {\n\t\treturn {\n\t\t\tkey: \"\",\n\t\t\tmodelId: undefined,\n\t\t\tmodel: this.currentSessionModel,\n\t\t\tunavailable: false,\n\t\t\tprovider: this.currentSessionModel?.provider ?? \"\",\n\t\t\tid: \"inherit\",\n\t\t\tname: this.currentSessionModel?.name,\n\t\t};\n\t}\n\n\tprivate makeModelChoice(model: Model<Api>): ModelChoiceItem {\n\t\treturn {\n\t\t\tkey: modelId(model),\n\t\t\tmodelId: modelId(model),\n\t\t\tmodel,\n\t\t\tunavailable: false,\n\t\t\tprovider: model.provider,\n\t\t\tid: model.id,\n\t\t\tname: model.name,\n\t\t};\n\t}\n\n\tprivate makeUnavailableChoice(modelId: string): ModelChoiceItem {\n\t\tconst parsed = parseModelSpec(modelId);\n\t\treturn {\n\t\t\tkey: modelId,\n\t\t\tmodelId,\n\t\t\tmodel: undefined,\n\t\t\tunavailable: true,\n\t\t\tprovider: parsed.provider,\n\t\t\tid: parsed.id,\n\t\t\tname: undefined,\n\t\t};\n\t}\n\n\tprivate buildChoices(models: readonly Model<Api>[]): ModelChoiceItem[] {\n\t\tconst sorted = [...models].sort(compareModels);\n\t\tconst availableById = new Map(this.models.map((model) => [modelId(model), model]));\n\t\tconst choices: ModelChoiceItem[] = [this.makeInheritChoice()];\n\t\tif (this.savedModelId) {\n\t\t\tconst saved = availableById.get(this.savedModelId);\n\t\t\tchoices.push(saved ? this.makeModelChoice(saved) : this.makeUnavailableChoice(this.savedModelId));\n\t\t}\n\t\tfor (const model of sorted) {\n\t\t\tif (modelId(model) !== this.savedModelId) choices.push(this.makeModelChoice(model));\n\t\t}\n\t\treturn choices;\n\t}\n\n\tprivate rebuildChoices(preferredKey?: string): void {\n\t\tconst currentKey = preferredKey ?? this.filteredChoices[this.selectedIndex]?.key ?? this.savedModelId ?? \"\";\n\t\tthis.allChoices = this.buildChoices(this.models);\n\t\tconst scopedModels = this.models.filter((model) => this.scopedModelKeys.has(modelId(model)));\n\t\tthis.scopedChoices = this.buildChoices(scopedModels);\n\t\tthis.activeChoices = this.scope === \"scoped\" ? this.scopedChoices : this.allChoices;\n\t\tthis.applyFilter(this.searchInput.getValue(), currentKey, false);\n\t\tthis.updateScopeView();\n\t}\n\n\tprivate applyFilter(query: string, preferredKey?: string, resetSelection = true): void {\n\t\tthis.filteredChoices = query ? fuzzyFilter(this.activeChoices, query, modelSearchText) : this.activeChoices;\n\t\tif (preferredKey !== undefined) {\n\t\t\tconst preferredIndex = this.filteredChoices.findIndex((choice) => choice.key === preferredKey);\n\t\t\tthis.selectedIndex = preferredIndex >= 0 ? preferredIndex : 0;\n\t\t} else if (query && resetSelection) {\n\t\t\tthis.selectedIndex = 0;\n\t\t} else {\n\t\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredChoices.length - 1));\n\t\t}\n\t\tthis.updateList();\n\t}\n\n\tprivate updateScopeView(): void {\n\t\tthis.scopeContainer.clear();\n\t\tif (this.scopedModelKeys.size === 0) {\n\t\t\tthis.scopeContainer.addChild(\n\t\t\t\tnew Text(\n\t\t\t\t\tthis.theme.fg(\"warning\", \"Only showing models from configured providers. Use /login to add providers.\"),\n\t\t\t\t\t0,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t);\n\t\t\tthis.scopeContainer.addChild(new Spacer(1));\n\t\t\treturn;\n\t\t}\n\t\tconst all = this.scope === \"all\" ? this.theme.fg(\"accent\", \"all\") : this.theme.fg(\"muted\", \"all\");\n\t\tconst scoped = this.scope === \"scoped\" ? this.theme.fg(\"accent\", \"scoped\") : this.theme.fg(\"muted\", \"scoped\");\n\t\tthis.scopeContainer.addChild(\n\t\t\tnew Text(`${this.theme.fg(\"muted\", \"Scope: \")}${all}${this.theme.fg(\"muted\", \" | \")}${scoped}`, 0, 0),\n\t\t);\n\t\tthis.scopeContainer.addChild(new Spacer(1));\n\t}\n\n\tprivate choiceLabel(choice: ModelChoiceItem): string {\n\t\tif (choice.modelId === undefined) {\n\t\t\tconst inherited = choice.model ? modelId(choice.model) : \"none\";\n\t\t\treturn `inherit ${this.theme.fg(\"muted\", `(${inherited})`)}`;\n\t\t}\n\t\tif (choice.unavailable) {\n\t\t\tconst badge = choice.provider ? `${choice.provider} · unavailable` : \"unavailable\";\n\t\t\treturn `${choice.id} ${this.theme.fg(\"warning\", `[${badge}]`)}`;\n\t\t}\n\t\treturn `${choice.id} ${this.theme.fg(\"muted\", `[${choice.provider}]`)}`;\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(\n\t\t\t\tthis.selectedIndex - Math.floor(MAX_VISIBLE_MODELS / 2),\n\t\t\t\tthis.filteredChoices.length - MAX_VISIBLE_MODELS,\n\t\t\t),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + MAX_VISIBLE_MODELS, this.filteredChoices.length);\n\t\tfor (let index = startIndex; index < endIndex; index++) {\n\t\t\tconst choice = this.filteredChoices[index];\n\t\t\tif (!choice) continue;\n\t\t\tconst selected = index === this.selectedIndex;\n\t\t\tconst saved = choice.modelId === this.savedModelId;\n\t\t\tconst prefix = selected ? this.theme.fg(\"accent\", \"→ \") : \" \";\n\t\t\tconst label = this.choiceLabel(choice);\n\t\t\tconst styledLabel = selected ? this.theme.fg(\"accent\", label) : label;\n\t\t\tconst checkmark = saved ? this.theme.fg(\"success\", \" ✓\") : \"\";\n\t\t\tthis.listContainer.addChild(new TruncatedText(`${prefix}${styledLabel}${checkmark}`, 0, 0));\n\t\t}\n\n\t\tif (startIndex > 0 || endIndex < this.filteredChoices.length) {\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew TruncatedText(\n\t\t\t\t\tthis.theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredChoices.length})`),\n\t\t\t\t\t0,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tif (this.filteredChoices.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(this.theme.fg(\"muted\", \" No matching models\"), 0, 0));\n\t\t} else {\n\t\t\tconst selected = this.filteredChoices[this.selectedIndex];\n\t\t\tif (selected?.model?.name) {\n\t\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\t\tthis.listContainer.addChild(new Text(this.theme.fg(\"muted\", ` Model Name: ${selected.model.name}`), 0, 0));\n\t\t\t}\n\t\t}\n\t\tif (this.statusMessage) {\n\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\tthis.listContainer.addChild(new Text(this.theme.fg(this.statusTone, ` ${this.statusMessage}`), 0, 0));\n\t\t}\n\t}\n\n\tprivate moveSelection(offset: -1 | 1): void {\n\t\tif (this.filteredChoices.length === 0) return;\n\t\tthis.selectedIndex = (this.selectedIndex + offset + this.filteredChoices.length) % this.filteredChoices.length;\n\t\tthis.updateList();\n\t}\n\n\tprivate toggleScope(): void {\n\t\tif (this.scopedModelKeys.size === 0) return;\n\t\tconst currentKey = this.filteredChoices[this.selectedIndex]?.key;\n\t\tthis.scope = this.scope === \"all\" ? \"scoped\" : \"all\";\n\t\tthis.activeChoices = this.scope === \"scoped\" ? this.scopedChoices : this.allChoices;\n\t\tthis.applyFilter(this.searchInput.getValue(), currentKey, false);\n\t\tthis.updateScopeView();\n\t}\n\n\tgetSelectedChoice(): ProfileModelChoice | undefined {\n\t\tconst selected = this.filteredChoices[this.selectedIndex];\n\t\tif (!selected) return undefined;\n\t\treturn { modelId: selected.modelId, model: selected.model, unavailable: selected.unavailable };\n\t}\n\n\tgetScope(): ModelScope {\n\t\treturn this.scope;\n\t}\n\n\tgetSearchValue(): string {\n\t\treturn this.searchInput.getValue();\n\t}\n\n\tupdateModels(models: readonly Model<Api>[]): void {\n\t\tconst selectedKey = this.filteredChoices[this.selectedIndex]?.key;\n\t\tthis.models = [...models];\n\t\tthis.rebuildChoices(selectedKey);\n\t}\n\n\tsetStatus(message: string | undefined, tone: StatusTone = \"muted\"): void {\n\t\tthis.statusMessage = message;\n\t\tthis.statusTone = tone;\n\t\tthis.updateList();\n\t}\n\n\thandleInput(data: string): void {\n\t\tif (this.keybindings.matches(data, \"tui.input.tab\")) {\n\t\t\tthis.toggleScope();\n\t\t} else if (this.keybindings.matches(data, \"tui.select.up\")) {\n\t\t\tthis.moveSelection(-1);\n\t\t} else if (this.keybindings.matches(data, \"tui.select.down\")) {\n\t\t\tthis.moveSelection(1);\n\t\t} else if (this.keybindings.matches(data, \"tui.select.confirm\")) {\n\t\t\tconst selected = this.getSelectedChoice();\n\t\t\tif (selected) this.onDone(selected);\n\t\t} else if (this.keybindings.matches(data, \"tui.select.cancel\")) {\n\t\t\tthis.onDone(undefined);\n\t\t} else {\n\t\t\tthis.searchInput.handleInput(data);\n\t\t\tthis.applyFilter(this.searchInput.getValue());\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model-list.js","sourceRoot":"","sources":["../../../../src/extensions/subagent/ui/model-list.ts"],"names":[],"mappings":"AACA,OAAO,EACN,SAAS,EAET,WAAW,EACX,KAAK,EAEL,MAAM,EACN,IAAI,EACJ,aAAa,GACb,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,kBAAkB,GAAG,EAAE,CAAC;AA+B9B,SAAS,aAAa,CAAC,IAAgB,EAAE,KAAiB;IACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7D,OAAO,QAAQ,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AACpE,CAAC;AAED,SAAS,eAAe,CAAC,IAAqB;IAC7C,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAChC,MAAM,SAAS,GA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,CAAC;QACpB,CAAC;aAAM,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,eAAe,CAAC,EAAE,CAAC;YAC5D,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;aAAM,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,iBAAiB,CAAC,EAAE,CAAC;YAC9D,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;aAAM,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,oBAAoB,CAAC,EAAE,CAAC;YACjE,MAAM,QAAQ,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC1C,IAAI,QAAQ;gBAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC;aAAM,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,mBAAmB,CAAC,EAAE,CAAC;YAChE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;YACnC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/C,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { Api, Model } from \"@earendil-works/pi-ai\";\nimport {\n\tContainer,\n\ttype Focusable,\n\tfuzzyFilter,\n\tInput,\n\ttype KeybindingsManager,\n\tSpacer,\n\tText,\n\tTruncatedText,\n} from \"@earendil-works/pi-tui\";\nimport type { Theme } from \"../../../modes/interactive/theme/theme.ts\";\nimport { modelId, parseModelSpec } from \"../model-selection.ts\";\n\nconst MAX_VISIBLE_MODELS = 10;\n\ntype ModelScope = \"all\" | \"scoped\";\ntype StatusTone = \"muted\" | \"success\" | \"error\";\n\nexport interface ProfileModelChoice {\n\t/** Undefined represents inheriting the current session model. */\n\tmodelId: string | undefined;\n\t/** Effective model for capability checks; unavailable saved overrides have none. */\n\tmodel: Model<Api> | undefined;\n\tunavailable: boolean;\n}\n\nexport interface ProfileModelListOptions {\n\ttheme: Theme;\n\tkeybindings: KeybindingsManager;\n\tmodels: readonly Model<Api>[];\n\tscopedModels: readonly { model: Model<Api> }[];\n\tcurrentSessionModel: Model<Api> | undefined;\n\tsavedModelId: string | undefined;\n\t/** Reports the confirmed choice; undefined means the picker was dismissed. */\n\tonDone: (choice: ProfileModelChoice | undefined) => void;\n}\n\ninterface ModelChoiceItem extends ProfileModelChoice {\n\tkey: string;\n\tprovider: string;\n\tid: string;\n\tname: string | undefined;\n}\n\nfunction compareModels(left: Model<Api>, right: Model<Api>): number {\n\tconst provider = left.provider.localeCompare(right.provider);\n\treturn provider !== 0 ? provider : left.id.localeCompare(right.id);\n}\n\nfunction modelSearchText(item: ModelChoiceItem): string {\n\tif (item.modelId === undefined) {\n\t\tconst inherited = item.model ? ` ${modelId(item.model)} ${item.model.name}` : \"\";\n\t\treturn `inherit${inherited}`;\n\t}\n\tconst name = item.name ? ` ${item.name}` : \"\";\n\treturn `${item.provider} ${item.provider}/${item.id} ${item.provider} ${item.id}${name}`;\n}\n\n/** Searchable /model-style model picker used by /agents; confirm reports the selected choice. */\nexport class ProfileModelListComponent extends Container implements Focusable {\n\tprivate readonly theme: Theme;\n\tprivate readonly keybindings: KeybindingsManager;\n\tprivate readonly currentSessionModel: Model<Api> | undefined;\n\tprivate readonly savedModelId: string | undefined;\n\tprivate readonly scopedModelKeys: Set<string>;\n\tprivate readonly onDone: (choice: ProfileModelChoice | undefined) => void;\n\tprivate readonly searchInput: Input;\n\tprivate readonly scopeContainer: Container;\n\tprivate readonly listContainer: Container;\n\tprivate models: Model<Api>[];\n\tprivate allChoices: ModelChoiceItem[] = [];\n\tprivate scopedChoices: ModelChoiceItem[] = [];\n\tprivate activeChoices: ModelChoiceItem[] = [];\n\tprivate filteredChoices: ModelChoiceItem[] = [];\n\tprivate selectedIndex = 0;\n\tprivate scope: ModelScope;\n\tprivate statusMessage: string | undefined;\n\tprivate statusTone: StatusTone = \"muted\";\n\tprivate _focused = false;\n\n\tget focused(): boolean {\n\t\treturn this._focused;\n\t}\n\n\tset focused(value: boolean) {\n\t\tthis._focused = value;\n\t\tthis.searchInput.focused = value;\n\t}\n\n\tconstructor(options: ProfileModelListOptions) {\n\t\tsuper();\n\t\tthis.theme = options.theme;\n\t\tthis.keybindings = options.keybindings;\n\t\tthis.models = [...options.models];\n\t\tthis.currentSessionModel = options.currentSessionModel;\n\t\tthis.savedModelId = options.savedModelId;\n\t\tthis.scopedModelKeys = new Set(options.scopedModels.map(({ model }) => modelId(model)));\n\t\tthis.scope = this.scopedModelKeys.size > 0 ? \"scoped\" : \"all\";\n\t\tthis.onDone = options.onDone;\n\n\t\tthis.scopeContainer = new Container();\n\t\tthis.addChild(this.scopeContainer);\n\t\tthis.searchInput = new Input();\n\t\tthis.addChild(this.searchInput);\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.listContainer = new Container();\n\t\tthis.addChild(this.listContainer);\n\n\t\tthis.rebuildChoices(this.savedModelId ?? \"\");\n\t}\n\n\tprivate makeInheritChoice(): ModelChoiceItem {\n\t\treturn {\n\t\t\tkey: \"\",\n\t\t\tmodelId: undefined,\n\t\t\tmodel: this.currentSessionModel,\n\t\t\tunavailable: false,\n\t\t\tprovider: this.currentSessionModel?.provider ?? \"\",\n\t\t\tid: \"inherit\",\n\t\t\tname: this.currentSessionModel?.name,\n\t\t};\n\t}\n\n\tprivate makeModelChoice(model: Model<Api>): ModelChoiceItem {\n\t\treturn {\n\t\t\tkey: modelId(model),\n\t\t\tmodelId: modelId(model),\n\t\t\tmodel,\n\t\t\tunavailable: false,\n\t\t\tprovider: model.provider,\n\t\t\tid: model.id,\n\t\t\tname: model.name,\n\t\t};\n\t}\n\n\tprivate makeUnavailableChoice(modelId: string): ModelChoiceItem {\n\t\tconst parsed = parseModelSpec(modelId);\n\t\treturn {\n\t\t\tkey: modelId,\n\t\t\tmodelId,\n\t\t\tmodel: undefined,\n\t\t\tunavailable: true,\n\t\t\tprovider: parsed.provider,\n\t\t\tid: parsed.id,\n\t\t\tname: undefined,\n\t\t};\n\t}\n\n\tprivate buildChoices(models: readonly Model<Api>[]): ModelChoiceItem[] {\n\t\tconst sorted = [...models].sort(compareModels);\n\t\tconst availableById = new Map(this.models.map((model) => [modelId(model), model]));\n\t\tconst choices: ModelChoiceItem[] = [this.makeInheritChoice()];\n\t\tif (this.savedModelId) {\n\t\t\tconst saved = availableById.get(this.savedModelId);\n\t\t\tchoices.push(saved ? this.makeModelChoice(saved) : this.makeUnavailableChoice(this.savedModelId));\n\t\t}\n\t\tfor (const model of sorted) {\n\t\t\tif (modelId(model) !== this.savedModelId) choices.push(this.makeModelChoice(model));\n\t\t}\n\t\treturn choices;\n\t}\n\n\tprivate rebuildChoices(preferredKey?: string): void {\n\t\tconst currentKey = preferredKey ?? this.filteredChoices[this.selectedIndex]?.key ?? this.savedModelId ?? \"\";\n\t\tthis.allChoices = this.buildChoices(this.models);\n\t\tconst scopedModels = this.models.filter((model) => this.scopedModelKeys.has(modelId(model)));\n\t\tthis.scopedChoices = this.buildChoices(scopedModels);\n\t\tthis.activeChoices = this.scope === \"scoped\" ? this.scopedChoices : this.allChoices;\n\t\tthis.applyFilter(this.searchInput.getValue(), currentKey, false);\n\t\tthis.updateScopeView();\n\t}\n\n\tprivate applyFilter(query: string, preferredKey?: string, resetSelection = true): void {\n\t\tthis.filteredChoices = query ? fuzzyFilter(this.activeChoices, query, modelSearchText) : this.activeChoices;\n\t\tif (preferredKey !== undefined) {\n\t\t\tconst preferredIndex = this.filteredChoices.findIndex((choice) => choice.key === preferredKey);\n\t\t\tthis.selectedIndex = preferredIndex >= 0 ? preferredIndex : 0;\n\t\t} else if (query && resetSelection) {\n\t\t\tthis.selectedIndex = 0;\n\t\t} else {\n\t\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredChoices.length - 1));\n\t\t}\n\t\tthis.updateList();\n\t}\n\n\tprivate updateScopeView(): void {\n\t\tthis.scopeContainer.clear();\n\t\tif (this.scopedModelKeys.size === 0) {\n\t\t\tthis.scopeContainer.addChild(\n\t\t\t\tnew Text(\n\t\t\t\t\tthis.theme.fg(\"warning\", \"Only showing models from configured providers. Use /login to add providers.\"),\n\t\t\t\t\t0,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t);\n\t\t\tthis.scopeContainer.addChild(new Spacer(1));\n\t\t\treturn;\n\t\t}\n\t\tconst all = this.scope === \"all\" ? this.theme.fg(\"accent\", \"all\") : this.theme.fg(\"muted\", \"all\");\n\t\tconst scoped = this.scope === \"scoped\" ? this.theme.fg(\"accent\", \"scoped\") : this.theme.fg(\"muted\", \"scoped\");\n\t\tthis.scopeContainer.addChild(\n\t\t\tnew Text(`${this.theme.fg(\"muted\", \"Scope: \")}${all}${this.theme.fg(\"muted\", \" | \")}${scoped}`, 0, 0),\n\t\t);\n\t\tthis.scopeContainer.addChild(new Spacer(1));\n\t}\n\n\tprivate choiceLabel(choice: ModelChoiceItem): string {\n\t\tif (choice.modelId === undefined) {\n\t\t\tconst inherited = choice.model ? modelId(choice.model) : \"none\";\n\t\t\treturn `inherit ${this.theme.fg(\"muted\", `(${inherited})`)}`;\n\t\t}\n\t\tif (choice.unavailable) {\n\t\t\tconst badge = choice.provider ? `${choice.provider} · unavailable` : \"unavailable\";\n\t\t\treturn `${choice.id} ${this.theme.fg(\"warning\", `[${badge}]`)}`;\n\t\t}\n\t\treturn `${choice.id} ${this.theme.fg(\"muted\", `[${choice.provider}]`)}`;\n\t}\n\n\tprivate updateList(): void {\n\t\tthis.listContainer.clear();\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(\n\t\t\t\tthis.selectedIndex - Math.floor(MAX_VISIBLE_MODELS / 2),\n\t\t\t\tthis.filteredChoices.length - MAX_VISIBLE_MODELS,\n\t\t\t),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + MAX_VISIBLE_MODELS, this.filteredChoices.length);\n\t\tfor (let index = startIndex; index < endIndex; index++) {\n\t\t\tconst choice = this.filteredChoices[index];\n\t\t\tif (!choice) continue;\n\t\t\tconst selected = index === this.selectedIndex;\n\t\t\tconst saved = choice.modelId === this.savedModelId;\n\t\t\tconst prefix = selected ? this.theme.fg(\"accent\", \"→ \") : \" \";\n\t\t\tconst label = this.choiceLabel(choice);\n\t\t\tconst styledLabel = selected ? this.theme.fg(\"accent\", label) : label;\n\t\t\tconst checkmark = saved ? this.theme.fg(\"success\", \" ✓\") : \"\";\n\t\t\tthis.listContainer.addChild(new TruncatedText(`${prefix}${styledLabel}${checkmark}`, 0, 0));\n\t\t}\n\n\t\tif (startIndex > 0 || endIndex < this.filteredChoices.length) {\n\t\t\tthis.listContainer.addChild(\n\t\t\t\tnew TruncatedText(\n\t\t\t\t\tthis.theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredChoices.length})`),\n\t\t\t\t\t0,\n\t\t\t\t\t0,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tif (this.filteredChoices.length === 0) {\n\t\t\tthis.listContainer.addChild(new Text(this.theme.fg(\"muted\", \" No matching models\"), 0, 0));\n\t\t} else {\n\t\t\tconst selected = this.filteredChoices[this.selectedIndex];\n\t\t\tif (selected?.model?.name) {\n\t\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\t\tthis.listContainer.addChild(new Text(this.theme.fg(\"muted\", ` Model Name: ${selected.model.name}`), 0, 0));\n\t\t\t}\n\t\t}\n\t\tif (this.statusMessage) {\n\t\t\tthis.listContainer.addChild(new Spacer(1));\n\t\t\tthis.listContainer.addChild(new Text(this.theme.fg(this.statusTone, ` ${this.statusMessage}`), 0, 0));\n\t\t}\n\t}\n\n\tprivate moveSelection(offset: -1 | 1): void {\n\t\tif (this.filteredChoices.length === 0) return;\n\t\tthis.selectedIndex = (this.selectedIndex + offset + this.filteredChoices.length) % this.filteredChoices.length;\n\t\tthis.updateList();\n\t}\n\n\tprivate toggleScope(): void {\n\t\tif (this.scopedModelKeys.size === 0) return;\n\t\tconst currentKey = this.filteredChoices[this.selectedIndex]?.key;\n\t\tthis.scope = this.scope === \"all\" ? \"scoped\" : \"all\";\n\t\tthis.activeChoices = this.scope === \"scoped\" ? this.scopedChoices : this.allChoices;\n\t\tthis.applyFilter(this.searchInput.getValue(), currentKey, false);\n\t\tthis.updateScopeView();\n\t}\n\n\tgetSelectedChoice(): ProfileModelChoice | undefined {\n\t\tconst selected = this.filteredChoices[this.selectedIndex];\n\t\tif (!selected) return undefined;\n\t\treturn { modelId: selected.modelId, model: selected.model, unavailable: selected.unavailable };\n\t}\n\n\tgetScope(): ModelScope {\n\t\treturn this.scope;\n\t}\n\n\tgetSearchValue(): string {\n\t\treturn this.searchInput.getValue();\n\t}\n\n\tupdateModels(models: readonly Model<Api>[]): void {\n\t\tconst selectedKey = this.filteredChoices[this.selectedIndex]?.key;\n\t\tthis.models = [...models];\n\t\tthis.rebuildChoices(selectedKey);\n\t}\n\n\tsetStatus(message: string | undefined, tone: StatusTone = \"muted\"): void {\n\t\tthis.statusMessage = message;\n\t\tthis.statusTone = tone;\n\t\tthis.updateList();\n\t}\n\n\toverride invalidate(): void {\n\t\tthis.updateScopeView();\n\t\tthis.updateList();\n\t\tsuper.invalidate();\n\t}\n\n\thandleInput(data: string): void {\n\t\tif (this.keybindings.matches(data, \"tui.input.tab\")) {\n\t\t\tthis.toggleScope();\n\t\t} else if (this.keybindings.matches(data, \"tui.select.up\")) {\n\t\t\tthis.moveSelection(-1);\n\t\t} else if (this.keybindings.matches(data, \"tui.select.down\")) {\n\t\t\tthis.moveSelection(1);\n\t\t} else if (this.keybindings.matches(data, \"tui.select.confirm\")) {\n\t\t\tconst selected = this.getSelectedChoice();\n\t\t\tif (selected) this.onDone(selected);\n\t\t} else if (this.keybindings.matches(data, \"tui.select.cancel\")) {\n\t\t\tthis.onDone(undefined);\n\t\t} else {\n\t\t\tthis.searchInput.handleInput(data);\n\t\t\tthis.applyFilter(this.searchInput.getValue());\n\t\t}\n\t}\n}\n"]}
|