@code-yeongyu/senpi 2026.9.2 → 2026.9.3
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 +124 -2
- package/dist/beta/omo-local-update-fingerprint.d.ts.map +1 -1
- package/dist/beta/omo-local-update-fingerprint.js +0 -1
- package/dist/beta/omo-local-update-fingerprint.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +7 -4
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/dynamic-prompt/build.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/build.js +2 -5
- package/dist/core/dynamic-prompt/build.js.map +1 -1
- package/dist/core/dynamic-prompt/index.d.ts +1 -2
- package/dist/core/dynamic-prompt/index.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/index.js +1 -2
- package/dist/core/dynamic-prompt/index.js.map +1 -1
- package/dist/core/dynamic-prompt/intent-gate.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/intent-gate.js +9 -24
- package/dist/core/dynamic-prompt/intent-gate.js.map +1 -1
- package/dist/core/dynamic-prompt/policies.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/policies.js +3 -7
- package/dist/core/dynamic-prompt/policies.js.map +1 -1
- package/dist/core/dynamic-prompt/style.d.ts.map +1 -1
- package/dist/core/dynamic-prompt/style.js +6 -8
- package/dist/core/dynamic-prompt/style.js.map +1 -1
- package/dist/core/dynamic-prompt/verification.js +1 -1
- package/dist/core/dynamic-prompt/verification.js.map +1 -1
- package/dist/core/dynamic-prompt/working-task.d.ts +2 -0
- package/dist/core/dynamic-prompt/working-task.d.ts.map +1 -0
- package/dist/core/dynamic-prompt/working-task.js +10 -0
- package/dist/core/dynamic-prompt/working-task.js.map +1 -0
- package/dist/core/extensions/builtin/claude-sdk-oauth/options.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/options.js +6 -2
- package/dist/core/extensions/builtin/claude-sdk-oauth/options.js.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.d.ts.map +1 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js +2 -1
- package/dist/core/extensions/builtin/claude-sdk-oauth/stream.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/extension-wiring.js +1 -1
- package/dist/core/extensions/builtin/compaction/extension-wiring.js.map +1 -1
- package/dist/core/extensions/builtin/config-reload/watch-event-source.d.ts +1 -1
- package/dist/core/extensions/builtin/config-reload/watch-event-source.d.ts.map +1 -1
- package/dist/core/extensions/builtin/config-reload/watch-event-source.js +27 -9
- package/dist/core/extensions/builtin/config-reload/watch-event-source.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.js +52 -50
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js +2 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-fable-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js +7 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js +7 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js +7 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-7.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js +7 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-4-8.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.js +2 -1
- package/dist/core/extensions/builtin/prompt-preset/claude-opus-5.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts +50 -0
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.d.ts.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js +66 -0
- package/dist/core/extensions/builtin/prompt-preset/execution-tooling.js.map +1 -0
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts +5 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js +6 -1
- package/dist/core/extensions/builtin/prompt-preset/gpt-5.6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.js +11 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-6.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-7.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-7.js +11 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k2-7.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js +2 -1
- package/dist/core/extensions/builtin/prompt-preset/kimi-k3.js.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.d.ts.map +1 -1
- package/dist/core/extensions/builtin/prompt-preset/presets.js +8 -2
- package/dist/core/extensions/builtin/prompt-preset/presets.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/extension.js +8 -3
- package/dist/core/extensions/builtin/terminal/extension.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.d.ts +4 -3
- package/dist/core/extensions/builtin/terminal/monitor-notify.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-notify.js +18 -18
- package/dist/core/extensions/builtin/terminal/monitor-notify.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts +7 -0
- package/dist/core/extensions/builtin/terminal/monitor-registry.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-registry.js +37 -8
- package/dist/core/extensions/builtin/terminal/monitor-registry.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-status.js +1 -1
- package/dist/core/extensions/builtin/terminal/monitor-status.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.d.ts +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/prompt.js +17 -13
- package/dist/core/extensions/builtin/terminal/prompt.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/bash-output.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/bash-output.js +14 -2
- package/dist/core/extensions/builtin/terminal/tools/bash-output.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/context.d.ts +2 -0
- package/dist/core/extensions/builtin/terminal/tools/context.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/context.js.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.d.ts.map +1 -1
- package/dist/core/extensions/builtin/terminal/tools/monitor.js +27 -10
- package/dist/core/extensions/builtin/terminal/tools/monitor.js.map +1 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +17 -8
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/settings-manager.d.ts +2 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +5 -3
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/index.d.ts +1 -1
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js +1 -1
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/rpc/host-ensure.d.ts +6 -0
- package/dist/modes/rpc/host-ensure.d.ts.map +1 -1
- package/dist/modes/rpc/host-ensure.js +36 -9
- package/dist/modes/rpc/host-ensure.js.map +1 -1
- package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -1
- package/dist/modes/rpc/host-lifecycle.js +16 -4
- package/dist/modes/rpc/host-lifecycle.js.map +1 -1
- package/dist/modes/rpc/multi-session-host.d.ts +7 -4
- package/dist/modes/rpc/multi-session-host.d.ts.map +1 -1
- package/dist/modes/rpc/multi-session-host.js +7 -4
- package/dist/modes/rpc/multi-session-host.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +8 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +62 -7
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-mode.d.ts +1 -1
- package/dist/modes/rpc/rpc-mode.js +1 -1
- package/dist/modes/rpc/rpc-mode.js.map +1 -1
- package/dist/modes/rpc/session-command-router.d.ts +22 -0
- package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
- package/dist/modes/rpc/session-command-router.js +132 -94
- package/dist/modes/rpc/session-command-router.js.map +1 -1
- package/dist/modes/rpc/session-event-fanout.d.ts +40 -0
- package/dist/modes/rpc/session-event-fanout.d.ts.map +1 -0
- package/dist/modes/rpc/session-event-fanout.js +146 -0
- package/dist/modes/rpc/session-event-fanout.js.map +1 -0
- package/dist/modes/rpc/session-event-writer.d.ts +6 -13
- package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
- package/dist/modes/rpc/session-event-writer.js +48 -96
- package/dist/modes/rpc/session-event-writer.js.map +1 -1
- package/dist/modes/rpc/session-registry.d.ts +9 -8
- package/dist/modes/rpc/session-registry.d.ts.map +1 -1
- package/dist/modes/rpc/session-registry.js +14 -42
- package/dist/modes/rpc/session-registry.js.map +1 -1
- package/dist/modes/rpc/session-teardown.d.ts +12 -0
- package/dist/modes/rpc/session-teardown.d.ts.map +1 -0
- package/dist/modes/rpc/session-teardown.js +117 -0
- package/dist/modes/rpc/session-teardown.js.map +1 -0
- package/docs/rpc.md +10 -6
- package/docs/settings.md +4 -4
- package/docs/terminal-tools.md +26 -6
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +57 -0
- package/node_modules/@code-yeongyu/senpi-codemode/README.md +4 -2
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/extension/skill-contribution.ts +43 -9
- package/node_modules/@code-yeongyu/senpi-codemode/src/index.ts +4 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +10 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/skill/bun-1-4/SKILL.md +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/skill/bun-1-4/references/runtime-apis.md +1 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool-options.ts +3 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +2 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts +3 -0
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +2 -2
- package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts +5 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js +26 -4
- package/node_modules/@earendil-works/pi-ai/dist/auth/oauth/anthropic.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/fireworks.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/google-vertex.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/google.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/huggingface.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode-go.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/opengateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/profiles.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/profiles.js +3 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry-profile/profiles.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/retry.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +2 -2
- package/node_modules/@earendil-works/pi-pty/package.json +1 -1
- package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +7 -7
- package/dist/core/dynamic-prompt/exploration.d.ts +0 -2
- package/dist/core/dynamic-prompt/exploration.d.ts.map +0 -1
- package/dist/core/dynamic-prompt/exploration.js +0 -6
- package/dist/core/dynamic-prompt/exploration.js.map +0 -1
- package/dist/core/dynamic-prompt/parallel-tools.d.ts +0 -2
- package/dist/core/dynamic-prompt/parallel-tools.d.ts.map +0 -1
- package/dist/core/dynamic-prompt/parallel-tools.js +0 -8
- package/dist/core/dynamic-prompt/parallel-tools.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/claude-sdk-oauth/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,gCAAgC,EAChC,iCAAiC,GAGjC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,+BAA+B,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAuB,MAAM,mBAAmB,CAAC;AAC5F,OAAO,EAA8B,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;AACnG,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,0CAA0C,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,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O,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;YACnE,MAAM,CAAC,YAAY,GAAG,gBAAgB,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;YACnE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1E,CAAC;gBAAS,CAAC;YACV,OAAO,EAAE,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACvD,UAAU,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,EAAE,CAAC;QACd,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;IACL,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import {\n\ttype Api,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\tcreateAssistantMessageDiagnostic,\n\tcreateAssistantMessageEventStream,\n\ttype Model,\n\ttype SimpleStreamOptions,\n} from \"@earendil-works/pi-ai\";\nimport { getSessionClaudeAccountPin } from \"./account-command.ts\";\nimport { queryWithAuthLane } from \"./auth-lane.ts\";\nimport { buildCustomToolServers } from \"./custom-tools.ts\";\nimport { defaultExecutableDeps, resolveClaudeCodeExecutable } from \"./executable.ts\";\nimport { buildClaudeSdkOauthQueryOptions } from \"./options.ts\";\nimport { buildPromptBlocks, buildPromptStream } from \"./prompt-bridge.ts\";\nimport { dedupeUltraworkBlocks } from \"./prompt-directive-dedupe.ts\";\nimport { refusalError } from \"./refusal.ts\";\nimport { getSdkBoundary, loadClaudeAgentSdk, type SdkQueryHandle } from \"./sdk-boundary.ts\";\nimport { type ContinuityObservation, emitContinuityObservation } from \"./session-observability.ts\";\nimport { residentSessionMessages } from \"./session-stream.ts\";\nimport { loadClaudeSdkOauthProviderSettingsFromDisk } from \"./settings.ts\";\nimport { applyStreamEvent } from \"./stream-events.ts\";\nimport { withAuthGuidance } from \"./stream-guidance.ts\";\nimport { emptyOutput, errorMessage, mapStopReason, type StreamBlock, updateUsage } from \"./stream-protocol.ts\";\nimport { toolWatch } from \"./tool-watch.ts\";\nimport { resolveSdkTools } from \"./tools.ts\";\n\nexport function streamClaudeSdkOauth(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst stream = createAssistantMessageEventStream();\n\tvoid (async () => {\n\t\tconst output = emptyOutput(model);\n\t\tconst blocks: StreamBlock[] = [];\n\t\tlet sdkQuery: SdkQueryHandle | undefined;\n\t\tlet closed = false;\n\t\tlet wasAborted = false;\n\t\tlet started = false;\n\t\tlet sawStreamEvent = false;\n\t\tconst closeQuery = (): void => {\n\t\t\tif (closed || !sdkQuery) return;\n\t\t\tclosed = true;\n\t\t\tsdkQuery.close();\n\t\t};\n\t\tconst requestAbort = (): void => {\n\t\t\tif (!sdkQuery) return;\n\t\t\tvoid sdkQuery\n\t\t\t\t.interrupt()\n\t\t\t\t.catch(() => {})\n\t\t\t\t.finally(closeQuery);\n\t\t};\n\t\tconst onAbort = (): void => {\n\t\t\twasAborted = true;\n\t\t\trequestAbort();\n\t\t};\n\t\tif (options?.signal?.aborted) onAbort();\n\t\telse options?.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\ttry {\n\t\t\t// Resident before the synchronous SDK member below (getSdkBoundary().query)\n\t\t\t// reads it - see sdk-boundary.lazy.ts.\n\t\t\tawait loadClaudeAgentSdk();\n\t\t\tconst resolvedTools = resolveSdkTools(context);\n\t\t\tconst affinityKey = options?.affinitySessionId ?? options?.sessionId;\n\t\t\tconst sessionKey = options?.sessionId ? toolWatch.sessionKey(options.sessionId) : undefined;\n\t\t\tif (sessionKey) toolWatch.reconcileWithContext(sessionKey, context);\n\t\t\tconst toolWatchNote = toolWatch.buildPromptNote(sessionKey, context, resolvedTools.customToolNameToSdk);\n\t\t\tconst providerSettings = loadClaudeSdkOauthProviderSettingsFromDisk(process.cwd());\n\t\t\tconst mcpServers = await buildCustomToolServers(resolvedTools.customTools);\n\t\t\tconst executable = resolveClaudeCodeExecutable(defaultExecutableDeps());\n\t\t\tconst buildOptions = (authLane: Parameters<typeof buildClaudeSdkOauthQueryOptions>[0][\"authLane\"]) => {\n\t\t\t\tconst queryOptions = buildClaudeSdkOauthQueryOptions({\n\t\t\t\t\tmodel,\n\t\t\t\t\tcontext,\n\t\t\t\t\tstreamOptions: options,\n\t\t\t\t\tproviderSettings,\n\t\t\t\t\tauthLane,\n\t\t\t\t\ttools: resolvedTools.sdkTools,\n\t\t\t\t\tpathToClaudeCodeExecutable: executable,\n\t\t\t\t\tsessionId: options?.sessionId,\n\t\t\t\t\tonGuidance: (text) => {\n\t\t\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t\t\tcreateAssistantMessageDiagnostic(\"claude_sdk_oauth_deprecation\", text),\n\t\t\t\t\t\t];\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tif (mcpServers) queryOptions.mcpServers = mcpServers;\n\t\t\t\treturn queryOptions;\n\t\t\t};\n\t\t\tconst recordContinuity = (observation: ContinuityObservation): void => {\n\t\t\t\t// Not a failure: carry the observation as details only, with no synthesized error.\n\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"claude_sdk_oauth_session_continuity\",\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\tdetails: { ...observation },\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t};\n\t\t\tconst useResidentSession =\n\t\t\t\toptions?.streamKind === \"main\" && providerSettings.resumeMode !== \"off\" && options.sessionId !== undefined;\n\t\t\tif (options?.streamKind === \"main\" && !useResidentSession) {\n\t\t\t\t// The reason must reflect the ACTUAL cause: resume mode \"off\"\n\t\t\t\t// disables the lane by setting, while any other mode simply has no\n\t\t\t\t// resident session to reuse yet.\n\t\t\t\temitContinuityObservation(\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: \"disabled\",\n\t\t\t\t\t\treason: providerSettings.resumeMode === \"off\" ? \"resume_mode_off\" : \"registry_miss\",\n\t\t\t\t\t},\n\t\t\t\t\trecordContinuity,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst messages = useResidentSession\n\t\t\t\t? residentSessionMessages({\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tstreamOptions: options,\n\t\t\t\t\t\tproviderSettings,\n\t\t\t\t\t\tpinnedAccount: getSessionClaudeAccountPin(options.sessionId),\n\t\t\t\t\t\tbuildOptions,\n\t\t\t\t\t\tcustomToolNameToSdk: resolvedTools.customToolNameToSdk,\n\t\t\t\t\t\ttoolWatchNote,\n\t\t\t\t\t\tonContinuityDecision: recordContinuity,\n\t\t\t\t\t\tonResumeFallback: (error) => {\n\t\t\t\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t\t\t\tcreateAssistantMessageDiagnostic(\"claude_sdk_oauth_resume_fallback\", error),\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t: queryWithAuthLane({\n\t\t\t\t\t\tprompt: buildPromptStream(\n\t\t\t\t\t\t\tdedupeUltraworkBlocks(buildPromptBlocks(context, resolvedTools.customToolNameToSdk, toolWatchNote))\n\t\t\t\t\t\t\t\t.blocks,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tquery: getSdkBoundary().query,\n\t\t\t\t\t\tproviderSettings,\n\t\t\t\t\t\tenv: options?.env,\n\t\t\t\t\t\tsignal: options?.signal,\n\t\t\t\t\t\tsessionId: affinityKey,\n\t\t\t\t\t\tpinnedAccount: getSessionClaudeAccountPin(options?.sessionId),\n\t\t\t\t\t\tonQuery: (query) => {\n\t\t\t\t\t\t\tsdkQuery = query;\n\t\t\t\t\t\t\tif (wasAborted) requestAbort();\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbuildOptions,\n\t\t\t\t\t});\n\n\t\t\tfor await (const message of messages) {\n\t\t\t\tconst refusal = refusalError(message);\n\t\t\t\tif (refusal) throw refusal;\n\t\t\t\tif (!started) {\n\t\t\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\t\t\tstarted = true;\n\t\t\t\t}\n\t\t\t\tif (message.type === \"stream_event\") {\n\t\t\t\t\tsawStreamEvent = true;\n\t\t\t\t\tapplyStreamEvent(\n\t\t\t\t\t\t{ model, output, blocks, stream, customToolNameToPi: resolvedTools.customToolNameToPi },\n\t\t\t\t\t\tmessage.event,\n\t\t\t\t\t);\n\t\t\t\t} else if (message.type === \"system\" && message.subtype === \"compact_boundary\") {\n\t\t\t\t\t// Native compactions must reach the ledger: attach the boundary as a\n\t\t\t\t\t// diagnostic so the lane-policy collector can build a ledger entry\n\t\t\t\t\t// instead of the boundary being discarded in the stream.\n\t\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"claude_sdk_oauth_compact_boundary\",\n\t\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tboundary: {\n\t\t\t\t\t\t\t\t\ttrigger: message.compact_metadata?.trigger ?? \"unknown\",\n\t\t\t\t\t\t\t\t\tpreTokens: message.compact_metadata?.pre_tokens ?? 0,\n\t\t\t\t\t\t\t\t\tpostTokens: message.compact_metadata?.post_tokens ?? 0,\n\t\t\t\t\t\t\t\t\tlineageId: message.session_id ?? \"\",\n\t\t\t\t\t\t\t\t\tobservedAt: Date.now(),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\t} else if (message.type === \"result\" && message.subtype === \"success\") {\n\t\t\t\t\t// Both fields are optional on the wire, so only adopt them when present.\n\t\t\t\t\t// A terminal result must never downgrade a toolUse turn that the stream\n\t\t\t\t\t// already established, or the agent loop would stop instead of running\n\t\t\t\t\t// the tool call sitting in `output.content`.\n\t\t\t\t\tif (message.usage) updateUsage(model, output, message.usage);\n\t\t\t\t\tif (message.stop_reason != null && output.stopReason !== \"toolUse\") {\n\t\t\t\t\t\toutput.stopReason = mapStopReason(message.stop_reason);\n\t\t\t\t\t}\n\t\t\t\t\tif (!sawStreamEvent) output.content.push({ type: \"text\", text: message.result });\n\t\t\t\t} else if (message.type === \"result\") {\n\t\t\t\t\tconst reason =\n\t\t\t\t\t\t\"errors\" in message && Array.isArray(message.errors) && message.errors.length > 0\n\t\t\t\t\t\t\t? String(message.errors[0])\n\t\t\t\t\t\t\t: `Claude Code ${message.subtype}`;\n\t\t\t\t\tthrow new Error(reason);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (wasAborted || options?.signal?.aborted) {\n\t\t\t\toutput.stopReason = \"aborted\";\n\t\t\t\toutput.errorMessage = \"Operation aborted\";\n\t\t\t\tstream.push({ type: \"error\", reason: \"aborted\", error: output });\n\t\t\t} else {\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"done\",\n\t\t\t\t\treason: output.stopReason === \"toolUse\" ? \"toolUse\" : output.stopReason === \"length\" ? \"length\" : \"stop\",\n\t\t\t\t\tmessage: output,\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// no-excuse-ok: catch\n\t\t\t// Provider boundary converts every thrown SDK value into the stream error contract.\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = withAuthGuidance(error, errorMessage(error));\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t} finally {\n\t\t\toptions?.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\tcloseQuery();\n\t\t\tstream.end();\n\t\t}\n\t})();\n\treturn stream;\n}\n"]}
|
|
1
|
+
{"version":3,"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YACnE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1E,CAAC;gBAAS,CAAC;YACV,OAAO,EAAE,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YACvD,UAAU,EAAE,CAAC;YACb,MAAM,CAAC,GAAG,EAAE,CAAC;QACd,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;IACL,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["import {\n\ttype Api,\n\ttype AssistantMessageEventStream,\n\ttype Context,\n\tcreateAssistantMessageDiagnostic,\n\tcreateAssistantMessageEventStream,\n\ttype Model,\n\ttype SimpleStreamOptions,\n} from \"@earendil-works/pi-ai\";\nimport { getSessionClaudeAccountPin } from \"./account-command.ts\";\nimport { queryWithAuthLane } from \"./auth-lane.ts\";\nimport { buildCustomToolServers } from \"./custom-tools.ts\";\nimport { defaultExecutableDeps, resolveClaudeCodeExecutable } from \"./executable.ts\";\nimport { buildClaudeSdkOauthQueryOptions } from \"./options.ts\";\nimport { buildPromptBlocks, buildPromptStream } from \"./prompt-bridge.ts\";\nimport { dedupeUltraworkBlocks } from \"./prompt-directive-dedupe.ts\";\nimport { refusalError } from \"./refusal.ts\";\nimport { getSdkBoundary, loadClaudeAgentSdk, type SdkQueryHandle } from \"./sdk-boundary.ts\";\nimport { type ContinuityObservation, emitContinuityObservation } from \"./session-observability.ts\";\nimport { residentSessionMessages } from \"./session-stream.ts\";\nimport { loadClaudeSdkOauthProviderSettingsFromDisk } from \"./settings.ts\";\nimport { applyStreamEvent } from \"./stream-events.ts\";\nimport { withAuthGuidance } from \"./stream-guidance.ts\";\nimport { emptyOutput, errorMessage, mapStopReason, type StreamBlock, updateUsage } from \"./stream-protocol.ts\";\nimport { toolWatch } from \"./tool-watch.ts\";\nimport { resolveSdkTools } from \"./tools.ts\";\n\nexport function streamClaudeSdkOauth(\n\tmodel: Model<Api>,\n\tcontext: Context,\n\toptions?: SimpleStreamOptions,\n): AssistantMessageEventStream {\n\tconst stream = createAssistantMessageEventStream();\n\tvoid (async () => {\n\t\tconst output = emptyOutput(model);\n\t\tconst blocks: StreamBlock[] = [];\n\t\tlet sdkQuery: SdkQueryHandle | undefined;\n\t\tlet closed = false;\n\t\tlet wasAborted = false;\n\t\tlet started = false;\n\t\tlet sawStreamEvent = false;\n\t\tconst closeQuery = (): void => {\n\t\t\tif (closed || !sdkQuery) return;\n\t\t\tclosed = true;\n\t\t\tsdkQuery.close();\n\t\t};\n\t\tconst requestAbort = (): void => {\n\t\t\tif (!sdkQuery) return;\n\t\t\tvoid sdkQuery\n\t\t\t\t.interrupt()\n\t\t\t\t.catch(() => {})\n\t\t\t\t.finally(closeQuery);\n\t\t};\n\t\tconst onAbort = (): void => {\n\t\t\twasAborted = true;\n\t\t\trequestAbort();\n\t\t};\n\t\tif (options?.signal?.aborted) onAbort();\n\t\telse options?.signal?.addEventListener(\"abort\", onAbort, { once: true });\n\n\t\ttry {\n\t\t\t// Resident before the synchronous SDK member below (getSdkBoundary().query)\n\t\t\t// reads it - see sdk-boundary.lazy.ts.\n\t\t\tawait loadClaudeAgentSdk();\n\t\t\tconst resolvedTools = resolveSdkTools(context);\n\t\t\tconst affinityKey = options?.affinitySessionId ?? options?.sessionId;\n\t\t\tconst sessionKey = options?.sessionId ? toolWatch.sessionKey(options.sessionId) : undefined;\n\t\t\tif (sessionKey) toolWatch.reconcileWithContext(sessionKey, context);\n\t\t\tconst toolWatchNote = toolWatch.buildPromptNote(sessionKey, context, resolvedTools.customToolNameToSdk);\n\t\t\tconst providerSettings = loadClaudeSdkOauthProviderSettingsFromDisk(process.cwd());\n\t\t\tconst toolLessRequest = options?.toolChoice === \"none\";\n\t\t\tconst mcpServers = toolLessRequest ? undefined : await buildCustomToolServers(resolvedTools.customTools);\n\t\t\tconst executable = resolveClaudeCodeExecutable(defaultExecutableDeps());\n\t\t\tconst buildOptions = (authLane: Parameters<typeof buildClaudeSdkOauthQueryOptions>[0][\"authLane\"]) => {\n\t\t\t\tconst queryOptions = buildClaudeSdkOauthQueryOptions({\n\t\t\t\t\tmodel,\n\t\t\t\t\tcontext,\n\t\t\t\t\tstreamOptions: options,\n\t\t\t\t\tproviderSettings,\n\t\t\t\t\tauthLane,\n\t\t\t\t\ttools: resolvedTools.sdkTools,\n\t\t\t\t\tpathToClaudeCodeExecutable: executable,\n\t\t\t\t\tsessionId: options?.sessionId,\n\t\t\t\t\tonGuidance: (text) => {\n\t\t\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t\t\tcreateAssistantMessageDiagnostic(\"claude_sdk_oauth_deprecation\", text),\n\t\t\t\t\t\t];\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tif (mcpServers) queryOptions.mcpServers = mcpServers;\n\t\t\t\treturn queryOptions;\n\t\t\t};\n\t\t\tconst recordContinuity = (observation: ContinuityObservation): void => {\n\t\t\t\t// Not a failure: carry the observation as details only, with no synthesized error.\n\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"claude_sdk_oauth_session_continuity\",\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\tdetails: { ...observation },\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t};\n\t\t\tconst useResidentSession =\n\t\t\t\toptions?.streamKind === \"main\" && providerSettings.resumeMode !== \"off\" && options.sessionId !== undefined;\n\t\t\tif (options?.streamKind === \"main\" && !useResidentSession) {\n\t\t\t\t// The reason must reflect the ACTUAL cause: resume mode \"off\"\n\t\t\t\t// disables the lane by setting, while any other mode simply has no\n\t\t\t\t// resident session to reuse yet.\n\t\t\t\temitContinuityObservation(\n\t\t\t\t\t{\n\t\t\t\t\t\tkind: \"disabled\",\n\t\t\t\t\t\treason: providerSettings.resumeMode === \"off\" ? \"resume_mode_off\" : \"registry_miss\",\n\t\t\t\t\t},\n\t\t\t\t\trecordContinuity,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst messages = useResidentSession\n\t\t\t\t? residentSessionMessages({\n\t\t\t\t\t\tmodel,\n\t\t\t\t\t\tcontext,\n\t\t\t\t\t\tstreamOptions: options,\n\t\t\t\t\t\tproviderSettings,\n\t\t\t\t\t\tpinnedAccount: getSessionClaudeAccountPin(options.sessionId),\n\t\t\t\t\t\tbuildOptions,\n\t\t\t\t\t\tcustomToolNameToSdk: resolvedTools.customToolNameToSdk,\n\t\t\t\t\t\ttoolWatchNote,\n\t\t\t\t\t\tonContinuityDecision: recordContinuity,\n\t\t\t\t\t\tonResumeFallback: (error) => {\n\t\t\t\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t\t\t\tcreateAssistantMessageDiagnostic(\"claude_sdk_oauth_resume_fallback\", error),\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t: queryWithAuthLane({\n\t\t\t\t\t\tprompt: buildPromptStream(\n\t\t\t\t\t\t\tdedupeUltraworkBlocks(buildPromptBlocks(context, resolvedTools.customToolNameToSdk, toolWatchNote))\n\t\t\t\t\t\t\t\t.blocks,\n\t\t\t\t\t\t),\n\t\t\t\t\t\tquery: getSdkBoundary().query,\n\t\t\t\t\t\tproviderSettings,\n\t\t\t\t\t\tenv: options?.env,\n\t\t\t\t\t\tsignal: options?.signal,\n\t\t\t\t\t\tsessionId: affinityKey,\n\t\t\t\t\t\tpinnedAccount: getSessionClaudeAccountPin(options?.sessionId),\n\t\t\t\t\t\tonQuery: (query) => {\n\t\t\t\t\t\t\tsdkQuery = query;\n\t\t\t\t\t\t\tif (wasAborted) requestAbort();\n\t\t\t\t\t\t},\n\t\t\t\t\t\tbuildOptions,\n\t\t\t\t\t});\n\n\t\t\tfor await (const message of messages) {\n\t\t\t\tconst refusal = refusalError(message);\n\t\t\t\tif (refusal) throw refusal;\n\t\t\t\tif (!started) {\n\t\t\t\t\tstream.push({ type: \"start\", partial: output });\n\t\t\t\t\tstarted = true;\n\t\t\t\t}\n\t\t\t\tif (message.type === \"stream_event\") {\n\t\t\t\t\tsawStreamEvent = true;\n\t\t\t\t\tapplyStreamEvent(\n\t\t\t\t\t\t{ model, output, blocks, stream, customToolNameToPi: resolvedTools.customToolNameToPi },\n\t\t\t\t\t\tmessage.event,\n\t\t\t\t\t);\n\t\t\t\t} else if (message.type === \"system\" && message.subtype === \"compact_boundary\") {\n\t\t\t\t\t// Native compactions must reach the ledger: attach the boundary as a\n\t\t\t\t\t// diagnostic so the lane-policy collector can build a ledger entry\n\t\t\t\t\t// instead of the boundary being discarded in the stream.\n\t\t\t\t\toutput.diagnostics = [\n\t\t\t\t\t\t...(output.diagnostics ?? []),\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: \"claude_sdk_oauth_compact_boundary\",\n\t\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\t\tdetails: {\n\t\t\t\t\t\t\t\tboundary: {\n\t\t\t\t\t\t\t\t\ttrigger: message.compact_metadata?.trigger ?? \"unknown\",\n\t\t\t\t\t\t\t\t\tpreTokens: message.compact_metadata?.pre_tokens ?? 0,\n\t\t\t\t\t\t\t\t\tpostTokens: message.compact_metadata?.post_tokens ?? 0,\n\t\t\t\t\t\t\t\t\tlineageId: message.session_id ?? \"\",\n\t\t\t\t\t\t\t\t\tobservedAt: Date.now(),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t];\n\t\t\t\t} else if (message.type === \"result\" && message.subtype === \"success\") {\n\t\t\t\t\t// Both fields are optional on the wire, so only adopt them when present.\n\t\t\t\t\t// A terminal result must never downgrade a toolUse turn that the stream\n\t\t\t\t\t// already established, or the agent loop would stop instead of running\n\t\t\t\t\t// the tool call sitting in `output.content`.\n\t\t\t\t\tif (message.usage) updateUsage(model, output, message.usage);\n\t\t\t\t\tif (message.stop_reason != null && output.stopReason !== \"toolUse\") {\n\t\t\t\t\t\toutput.stopReason = mapStopReason(message.stop_reason);\n\t\t\t\t\t}\n\t\t\t\t\tif (!sawStreamEvent) output.content.push({ type: \"text\", text: message.result });\n\t\t\t\t} else if (message.type === \"result\") {\n\t\t\t\t\tconst reason =\n\t\t\t\t\t\t\"errors\" in message && Array.isArray(message.errors) && message.errors.length > 0\n\t\t\t\t\t\t\t? String(message.errors[0])\n\t\t\t\t\t\t\t: `Claude Code ${message.subtype}`;\n\t\t\t\t\tthrow new Error(reason);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (wasAborted || options?.signal?.aborted) {\n\t\t\t\toutput.stopReason = \"aborted\";\n\t\t\t\toutput.errorMessage = \"Operation aborted\";\n\t\t\t\tstream.push({ type: \"error\", reason: \"aborted\", error: output });\n\t\t\t} else {\n\t\t\t\tstream.push({\n\t\t\t\t\ttype: \"done\",\n\t\t\t\t\treason: output.stopReason === \"toolUse\" ? \"toolUse\" : output.stopReason === \"length\" ? \"length\" : \"stop\",\n\t\t\t\t\tmessage: output,\n\t\t\t\t});\n\t\t\t}\n\t\t} catch (error) {\n\t\t\t// no-excuse-ok: catch\n\t\t\t// Provider boundary converts every thrown SDK value into the stream error contract.\n\t\t\toutput.stopReason = options?.signal?.aborted ? \"aborted\" : \"error\";\n\t\t\toutput.errorMessage = withAuthGuidance(error, errorMessage(error));\n\t\t\tstream.push({ type: \"error\", reason: output.stopReason, error: output });\n\t\t} finally {\n\t\t\toptions?.signal?.removeEventListener(\"abort\", onAbort);\n\t\t\tcloseQuery();\n\t\t\tstream.end();\n\t\t}\n\t})();\n\treturn stream;\n}\n"]}
|
|
@@ -32,7 +32,7 @@ export function isAbortedAssistantMessage(event) {
|
|
|
32
32
|
return event.message.role === "assistant" && "stopReason" in event.message && event.message.stopReason === "aborted";
|
|
33
33
|
}
|
|
34
34
|
export function isRequiredCompactionFallbackReason(reason) {
|
|
35
|
-
return reason === "threshold" || reason === "overflow";
|
|
35
|
+
return reason === "manual" || reason === "threshold" || reason === "overflow";
|
|
36
36
|
}
|
|
37
37
|
export function recentCheckpoint(ctx) {
|
|
38
38
|
const checkpoint = checkpointState.getLatestCheckpoint(ctx);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension-wiring.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/compaction/extension-wiring.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AAGzD,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAC1C,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC,SAAS,YAAY,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,KAAuD;IAClG,OAAO,YAAY,CAAC,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,CAAC,GAAG,2BAA2B,CAAC;AACrG,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,aAAqB,EAAE,SAA6B;IAC1F,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,CAAC,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC;QAC1G,OAAO,aAAa,CAAC;IACtB,CAAC;IACD,MAAM,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,wBAAwB,CAAC,CAAC,CAAC;IAChG,OAAO,aAAa,GAAG,aAAa,CAAC;AACtC,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,KAAmB,EAAE,gBAAwB;IACjF,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,IAAI,gBAAgB,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACjE,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,gBAAgB,CAAC;IAC/C,OAAO;QACN,GAAG,KAAK;QACR,MAAM;QACN,OAAO,EAAE,KAAK,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO;KACvF,CAAC;AACH,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,KAAsB;IAG/D,OAAO,SAAS,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,yBAAyB,CAAC,KAAgC;IACzE,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,WAAW,IAAI,YAAY,IAAI,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC;AACtH,CAAC;AAED,MAAM,UAAU,kCAAkC,CAAC,MAA2C;IAC7F,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,KAAK,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"extension-wiring.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/compaction/extension-wiring.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,KAAK,eAAe,MAAM,uBAAuB,CAAC;AAGzD,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAC1C,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAErC,SAAS,YAAY,CAAC,IAAY;IACjC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GA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\"@earendil-works/pi-agent-core\";\nimport type { ContextUsage, ExtensionContext, MessageEndEvent, SessionBeforeCompactEvent } from \"../../types.ts\";\nimport * as checkpointState from \"./checkpoint-state.ts\";\nimport type { SpeculativeCompactionResult, SpeculativeCompactionSnapshot } from \"./speculative.ts\";\n\nconst IMAGE_PROMPT_TOKEN_ESTIMATE = 1_200;\nconst MAX_OUTPUT_RESERVE_RATIO = 0.5;\n\nfunction approxTokens(text: string): number {\n\treturn Math.ceil(text.length / 4);\n}\n\nexport function estimatePendingPromptTokens(event: { prompt?: string; images?: readonly unknown[] }): number {\n\treturn approxTokens(event.prompt ?? \"\") + (event.images?.length ?? 0) * IMAGE_PROMPT_TOKEN_ESTIMATE;\n}\n\nexport function getPromptContextWindow(contextWindow: number, maxTokens: number | undefined): number {\n\tif (typeof maxTokens !== \"number\" || !Number.isFinite(maxTokens) || maxTokens <= 0 || contextWindow <= 0) {\n\t\treturn contextWindow;\n\t}\n\tconst outputReserve = Math.min(maxTokens, Math.floor(contextWindow * MAX_OUTPUT_RESERVE_RATIO));\n\treturn contextWindow - outputReserve;\n}\n\nexport function withAdditionalTokens(usage: ContextUsage, additionalTokens: number): ContextUsage {\n\tif (usage.tokens === null || additionalTokens <= 0) return usage;\n\tconst tokens = usage.tokens + additionalTokens;\n\treturn {\n\t\t...usage,\n\t\ttokens,\n\t\tpercent: usage.contextWindow > 0 ? (tokens / usage.contextWindow) * 100 : usage.percent,\n\t};\n}\n\nexport function isMonitorableMessageEvent(event: MessageEndEvent): event is MessageEndEvent & {\n\tmessage: AgentMessage & { content: Array<{ type: string; text?: string }> };\n} {\n\treturn \"content\" in event.message && Array.isArray(event.message.content);\n}\n\nexport function isAbortedAssistantMessage(event: { message: AgentMessage }): boolean {\n\treturn event.message.role === \"assistant\" && \"stopReason\" in event.message && event.message.stopReason === \"aborted\";\n}\n\nexport function isRequiredCompactionFallbackReason(reason: SessionBeforeCompactEvent[\"reason\"]): boolean {\n\treturn reason === \"manual\" || reason === \"threshold\" || reason === \"overflow\";\n}\n\nexport function recentCheckpoint(ctx: ExtensionContext): checkpointState.AgentCheckpoint | null {\n\tconst checkpoint = checkpointState.getLatestCheckpoint(ctx);\n\tif (!checkpoint?.timestamp) return null;\n\treturn Date.now() - checkpoint.timestamp <= 60_000 ? checkpoint : null;\n}\n\nfunction shouldEndFeedback(result: SpeculativeCompactionResult): boolean {\n\treturn !result.applied && result.reason !== \"rejected\";\n}\n\nexport function endCompactionFeedback(\n\tctx: ExtensionContext,\n\tsignal: AbortSignal | undefined,\n\tresult: SpeculativeCompactionResult,\n\tremoteFallbackReason?: string,\n): void {\n\tif (shouldEndFeedback(result)) {\n\t\t// Surface the concrete failure instead of the generic \"Compaction did not\n\t\t// apply\": the remote stage's reason (e.g. remote-compaction-timeout) and the\n\t\t// terminal local reason (unavailable / stale), so the decision log and TUI\n\t\t// show what actually happened. An aborted compaction renders \"Compaction\n\t\t// cancelled\" downstream and must not carry a failure message.\n\t\tconst localReason = result.applied ? undefined : result.reason;\n\t\tconst parts = [remoteFallbackReason, localReason].filter((part): part is string => Boolean(part));\n\t\tconst errorMessage =\n\t\t\tsignal?.aborted || parts.length === 0\n\t\t\t\t? undefined\n\t\t\t\t: `Compaction did not apply: ${parts.join(\"; local fallback \")}`;\n\t\tctx.endCompaction?.({ reason: \"extension\", signal, aborted: signal?.aborted, errorMessage });\n\t}\n}\n\nexport function linkAbortSignal(source: AbortSignal | undefined, target: AbortController): () => void {\n\tif (!source) return () => {};\n\tif (source.aborted) {\n\t\ttarget.abort();\n\t\treturn () => {};\n\t}\n\tconst abort = () => target.abort();\n\tsource.addEventListener(\"abort\", abort, { once: true });\n\treturn () => source.removeEventListener(\"abort\", abort);\n}\n\nexport function createBlockingRemoteCompactionEvent(\n\tctx: ExtensionContext,\n\tsnapshot: SpeculativeCompactionSnapshot,\n\tcustomInstructions: string,\n\tsignal: AbortSignal,\n): SessionBeforeCompactEvent {\n\treturn {\n\t\ttype: \"session_before_compact\",\n\t\treason: \"extension\",\n\t\twillRetry: false,\n\t\trequestId: randomUUID(),\n\t\tpreparation: snapshot.preparation,\n\t\tbranchEntries: ctx.sessionManager.getBranch(),\n\t\tcustomInstructions,\n\t\tsignal,\n\t};\n}\n"]}
|
|
@@ -10,6 +10,6 @@ export type FsWatchEventSourceOptions = {
|
|
|
10
10
|
readonly platform?: NodeJS.Platform;
|
|
11
11
|
readonly createRecursiveWorker?: RecursiveWatchWorkerFactory;
|
|
12
12
|
};
|
|
13
|
-
/** Production event source.
|
|
13
|
+
/** Production event source. Watch setup and teardown run off the interactive main thread. */
|
|
14
14
|
export declare function createFsWatchEventSource(onError?: (error: unknown, path: string) => void, options?: FsWatchEventSourceOptions): WatchEventSource;
|
|
15
15
|
//# sourceMappingURL=watch-event-source.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch-event-source.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/config-reload/watch-event-source.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAsB,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE9E,MAAM,WAAW,oBAAoB;IACpC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAAC;IACjE,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI,CAAC;IAC3D,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7B;AAED,MAAM,MAAM,2BAA2B,GAAG,MAAM,oBAAoB,CAAC;AAErE,MAAM,MAAM,yBAAyB,GAAG;IACvC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IACpC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,2BAA2B,CAAC;CAC7D,CAAC;
|
|
1
|
+
{"version":3,"file":"watch-event-source.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/config-reload/watch-event-source.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAsB,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAE9E,MAAM,WAAW,oBAAoB;IACpC,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,IAAI,CAAC;IACjE,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI,CAAC;IAC3D,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACpC,SAAS,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7B;AAED,MAAM,MAAM,2BAA2B,GAAG,MAAM,oBAAoB,CAAC;AAErE,MAAM,MAAM,yBAAyB,GAAG;IACvC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;IACpC,QAAQ,CAAC,qBAAqB,CAAC,EAAE,2BAA2B,CAAC;CAC7D,CAAC;AA+EF,6FAA6F;AAC7F,wBAAgB,wBAAwB,CACvC,OAAO,GAAE,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,IAAe,EAC1D,OAAO,GAAE,yBAA8B,GACrC,gBAAgB,CAiElB"}
|
|
@@ -17,7 +17,7 @@ parentPort.on("message", (message) => {
|
|
|
17
17
|
try {
|
|
18
18
|
const watcher = watch(
|
|
19
19
|
message.path,
|
|
20
|
-
{ recursive:
|
|
20
|
+
{ recursive: message.recursive !== false, encoding: "utf8" },
|
|
21
21
|
(eventType, filename) => {
|
|
22
22
|
parentPort.postMessage({
|
|
23
23
|
kind: "event",
|
|
@@ -63,11 +63,14 @@ function isRecursiveWatchMessage(message) {
|
|
|
63
63
|
(message.filename === null || typeof message.filename === "string"));
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
* Platforms whose
|
|
67
|
-
* interactive main thread: inotify tree walks on Linux, FSEvents stream
|
|
66
|
+
* Platforms whose fs.watch handles are expensive to create and tear down on the
|
|
67
|
+
* interactive main thread: inotify tree walks on Linux, FSEvents stream rendezvous on
|
|
68
|
+
* macOS. Non-recursive per-directory watches pay the same FSEvents setup latency —
|
|
69
|
+
* measured 2.7-8.0s per watch-engine target under system load — so every watch is
|
|
70
|
+
* offloaded, not only recursive ones.
|
|
68
71
|
*/
|
|
69
|
-
const
|
|
70
|
-
/** Production event source.
|
|
72
|
+
const WORKER_OFFLOADED_WATCH_PLATFORMS = new Set(["linux", "darwin"]);
|
|
73
|
+
/** Production event source. Watch setup and teardown run off the interactive main thread. */
|
|
71
74
|
export function createFsWatchEventSource(onError = () => { }, options = {}) {
|
|
72
75
|
const recursiveSubscriptions = new Map();
|
|
73
76
|
let recursiveWorker;
|
|
@@ -91,19 +94,34 @@ export function createFsWatchEventSource(onError = () => { }, options = {}) {
|
|
|
91
94
|
worker.on("error", (error) => {
|
|
92
95
|
for (const subscription of recursiveSubscriptions.values())
|
|
93
96
|
onError(error, subscription.path);
|
|
97
|
+
// A worker that raised an uncaught error is dead; keeping it would leave every
|
|
98
|
+
// live subscription silent. Drop it and move the survivors to a fresh worker.
|
|
99
|
+
if (recursiveWorker !== worker)
|
|
100
|
+
return;
|
|
101
|
+
recursiveWorker = undefined;
|
|
102
|
+
if (recursiveSubscriptions.size === 0)
|
|
103
|
+
return;
|
|
104
|
+
const replacement = ensureRecursiveWorker();
|
|
105
|
+
for (const [id, subscription] of recursiveSubscriptions) {
|
|
106
|
+
replacement.postMessage({ kind: "watch", id, path: subscription.path, recursive: subscription.recursive });
|
|
107
|
+
}
|
|
94
108
|
});
|
|
95
109
|
recursiveWorker = worker;
|
|
96
110
|
return worker;
|
|
97
111
|
};
|
|
98
112
|
return (path, listener, watchOptions) => {
|
|
99
|
-
if (
|
|
113
|
+
if (WORKER_OFFLOADED_WATCH_PLATFORMS.has(options.platform ?? process.platform)) {
|
|
100
114
|
const id = nextSubscriptionId++;
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
115
|
+
const recursive = watchOptions?.recursive ?? false;
|
|
116
|
+
ensureRecursiveWorker().postMessage({ kind: "watch", id, path, recursive });
|
|
117
|
+
recursiveSubscriptions.set(id, { path, listener, recursive });
|
|
104
118
|
return () => {
|
|
105
119
|
if (!recursiveSubscriptions.delete(id))
|
|
106
120
|
return;
|
|
121
|
+
// Resolve at unsubscribe time: the worker may have been replaced after a crash.
|
|
122
|
+
const worker = recursiveWorker;
|
|
123
|
+
if (!worker)
|
|
124
|
+
return;
|
|
107
125
|
if (recursiveSubscriptions.size > 0) {
|
|
108
126
|
worker.postMessage({ kind: "unwatch", id });
|
|
109
127
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"watch-event-source.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/config-reload/watch-event-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAqBtE,MAAM,6BAA6B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CrC,CAAC;AAEF,SAAS,0BAA0B;IAClC,OAAO,IAAI,MAAM,CAAC,6BAA6B,EAAE;QAChD,IAAI,EAAE,IAAI;KACV,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,OAAgB;IAChD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAC1F,IAAI,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,OAAO,OAAO,CAAC,EAAE,KAAK,QAAQ;Q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K,MAAM,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YACzE,CAAC,CAAC;QACH,CAAC;QAED,MAAM,OAAO,GAAG,qBAAqB,CACpC,IAAI,EACJ,QAAQ,EACR,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,uBAAuB,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAC7D,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,IAAI,KAAK,EAAE,CAC/C,CAAC;QACF,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC/B,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { Worker } from \"node:worker_threads\";\nimport { watchWithErrorHandler } from \"../../../../utils/fs-watch.ts\";\nimport type { WatchEventListener, WatchEventSource } from \"./watch-engine.ts\";\n\nexport interface RecursiveWatchWorker {\n\ton(event: \"message\", listener: (message: unknown) => void): this;\n\ton(event: \"error\", listener: (error: Error) => void): this;\n\tpostMessage(message: unknown): void;\n\tterminate(): Promise<number>;\n}\n\nexport type RecursiveWatchWorkerFactory = () => RecursiveWatchWorker;\n\nexport type FsWatchEventSourceOptions = {\n\treadonly platform?: NodeJS.Platform;\n\treadonly createRecursiveWorker?: RecursiveWatchWorkerFactory;\n};\n\ntype RecursiveWatchMessage =\n\t| { readonly kind: \"event\"; readonly id: number; readonly eventType: string; readonly filename: string | null }\n\t| { readonly kind: \"error\"; readonly id: number; readonly message: string };\n\nconst RECURSIVE_WATCH_WORKER_SOURCE = `\nconst { watch } = require(\"node:fs\");\nconst { parentPort } = require(\"node:worker_threads\");\n\nif (!parentPort) throw new Error(\"Recursive watch worker requires a parent port\");\n\nconst watchers = new Map();\nparentPort.on(\"message\", (message) => {\n\tif (message.kind === \"unwatch\") {\n\t\twatchers.get(message.id)?.close();\n\t\twatchers.delete(message.id);\n\t\treturn;\n\t}\n\tif (message.kind !== \"watch\") return;\n\ttry {\n\t\tconst watcher = watch(\n\t\t\tmessage.path,\n\t\t\t{ recursive: true, encoding: \"utf8\" },\n\t\t\t(eventType, filename) => {\n\t\t\t\tparentPort.postMessage({\n\t\t\t\t\tkind: \"event\",\n\t\t\t\t\tid: message.id,\n\t\t\t\t\teventType,\n\t\t\t\t\tfilename: typeof filename === \"string\" ? filename : null,\n\t\t\t\t});\n\t\t\t},\n\t\t);\n\t\twatcher.on(\"error\", (error) => {\n\t\t\tparentPort.postMessage({\n\t\t\t\tkind: \"error\",\n\t\t\t\tid: message.id,\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t});\n\t\twatchers.set(message.id, watcher);\n\t} catch (error) {\n\t\tparentPort.postMessage({\n\t\t\tkind: \"error\",\n\t\t\tid: message.id,\n\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t});\n\t}\n});\n`;\n\nfunction createRecursiveWatchWorker(): RecursiveWatchWorker {\n\treturn new Worker(RECURSIVE_WATCH_WORKER_SOURCE, {\n\t\teval: true,\n\t});\n}\n\nfunction isRecursiveWatchMessage(message: unknown): message is RecursiveWatchMessage {\n\tif (typeof message !== \"object\" || message === null || !(\"kind\" in message)) return false;\n\tif (!(\"id\" in message) || typeof message.id !== \"number\") return false;\n\tif (message.kind === \"error\") return \"message\" in message && typeof message.message === \"string\";\n\treturn (\n\t\tmessage.kind === \"event\" &&\n\t\t\"eventType\" in message &&\n\t\ttypeof message.eventType === \"string\" &&\n\t\t\"filename\" in message &&\n\t\t(message.filename === null || typeof message.filename === \"string\")\n\t);\n}\n\n/**\n * Platforms whose recursive fs.watch handles are expensive to create and tear down on the\n * interactive main thread: inotify tree walks on Linux, FSEvents stream teardown on macOS.\n */\nconst WORKER_OFFLOADED_RECURSIVE_PLATFORMS: ReadonlySet<NodeJS.Platform> = new Set([\"linux\", \"darwin\"]);\n\n/** Production event source. Recursive setup and teardown run off the interactive main thread. */\nexport function createFsWatchEventSource(\n\tonError: (error: unknown, path: string) => void = () => {},\n\toptions: FsWatchEventSourceOptions = {},\n): WatchEventSource {\n\tconst recursiveSubscriptions = new Map<number, { readonly path: string; readonly listener: WatchEventListener }>();\n\tlet recursiveWorker: RecursiveWatchWorker | undefined;\n\tlet nextSubscriptionId = 1;\n\n\tconst ensureRecursiveWorker = (): RecursiveWatchWorker => {\n\t\tif (recursiveWorker) return recursiveWorker;\n\t\tconst worker = (options.createRecursiveWorker ?? createRecursiveWatchWorker)();\n\t\tworker.on(\"message\", (message) => {\n\t\t\tif (!isRecursiveWatchMessage(message)) return;\n\t\t\tconst subscription = recursiveSubscriptions.get(message.id);\n\t\t\tif (!subscription) return;\n\t\t\tif (message.kind === \"event\") {\n\t\t\t\tsubscription.listener(message.eventType, message.filename);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tonError(new Error(message.message), subscription.path);\n\t\t});\n\t\tworker.on(\"error\", (error) => {\n\t\t\tfor (const subscription of recursiveSubscriptions.values()) onError(error, subscription.path);\n\t\t});\n\t\trecursiveWorker = worker;\n\t\treturn worker;\n\t};\n\n\treturn (path, listener, watchOptions) => {\n\t\tif (WORKER_OFFLOADED_RECURSIVE_PLATFORMS.has(options.platform ?? process.platform) && watchOptions?.recursive) {\n\t\t\tconst id = nextSubscriptionId++;\n\t\t\tconst worker = ensureRecursiveWorker();\n\t\t\trecursiveSubscriptions.set(id, { path, listener });\n\t\t\tworker.postMessage({ kind: \"watch\", id, path });\n\t\t\treturn () => {\n\t\t\t\tif (!recursiveSubscriptions.delete(id)) return;\n\t\t\t\tif (recursiveSubscriptions.size > 0) {\n\t\t\t\t\tworker.postMessage({ kind: \"unwatch\", id });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\trecursiveWorker = undefined;\n\t\t\t\tvoid worker.terminate().catch((error: unknown) => onError(error, path));\n\t\t\t};\n\t\t}\n\n\t\tconst watcher = watchWithErrorHandler(\n\t\t\tpath,\n\t\t\tlistener,\n\t\t\t() => onError(new Error(`fs.watch failed for ${path}`), path),\n\t\t\t{ recursive: watchOptions?.recursive ?? false },\n\t\t);\n\t\treturn () => watcher?.close();\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"watch-event-source.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/config-reload/watch-event-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAqBtE,MAAM,6BAA6B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2CrC,CAAC;AAEF,SAAS,0BAA0B;IAClC,OAAO,IAAI,MAAM,CAAC,6BAA6B,EAAE;QAChD,IAAI,EAAE,IAAI;KACV,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,OAAgB;IAChD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,IAAI,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAC1F,IAAI,CAAC,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,OAAO,OAAO,CAAC,EAAE,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACvE,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO;QAAE,OAAO,SAAS,IAAI,OAAO,IAAI,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,CAAC;IACjG,OAAO,CACN,OAAO,CAAC,IAAI,KAAK,OAAO;QACxB,WAAW,IAAI,OAAO;QACtB,OAAO,OAAO,CAAC,SAAS,KAAK,QAAQ;QACrC,UAAU,IAAI,OAAO;QACrB,CAAC,OAAO,CAAC,QAAQ,KAAK,IAAI,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAC,CACnE,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,gCAAgC,GAAiC,IAA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AW,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC5C,OAAO;gBACR,CAAC;gBACD,eAAe,GAAG,SAAS,CAAC;gBAC5B,KAAK,MAAM,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;YACzE,CAAC,CAAC;QACH,CAAC;QAED,MAAM,OAAO,GAAG,qBAAqB,CACpC,IAAI,EACJ,QAAQ,EACR,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,uBAAuB,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,EAC7D,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,IAAI,KAAK,EAAE,CAC/C,CAAC;QACF,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC/B,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { Worker } from \"node:worker_threads\";\nimport { watchWithErrorHandler } from \"../../../../utils/fs-watch.ts\";\nimport type { WatchEventListener, WatchEventSource } from \"./watch-engine.ts\";\n\nexport interface RecursiveWatchWorker {\n\ton(event: \"message\", listener: (message: unknown) => void): this;\n\ton(event: \"error\", listener: (error: Error) => void): this;\n\tpostMessage(message: unknown): void;\n\tterminate(): Promise<number>;\n}\n\nexport type RecursiveWatchWorkerFactory = () => RecursiveWatchWorker;\n\nexport type FsWatchEventSourceOptions = {\n\treadonly platform?: NodeJS.Platform;\n\treadonly createRecursiveWorker?: RecursiveWatchWorkerFactory;\n};\n\ntype RecursiveWatchMessage =\n\t| { readonly kind: \"event\"; readonly id: number; readonly eventType: string; readonly filename: string | null }\n\t| { readonly kind: \"error\"; readonly id: number; readonly message: string };\n\nconst RECURSIVE_WATCH_WORKER_SOURCE = `\nconst { watch } = require(\"node:fs\");\nconst { parentPort } = require(\"node:worker_threads\");\n\nif (!parentPort) throw new Error(\"Recursive watch worker requires a parent port\");\n\nconst watchers = new Map();\nparentPort.on(\"message\", (message) => {\n\tif (message.kind === \"unwatch\") {\n\t\twatchers.get(message.id)?.close();\n\t\twatchers.delete(message.id);\n\t\treturn;\n\t}\n\tif (message.kind !== \"watch\") return;\n\ttry {\n\t\tconst watcher = watch(\n\t\t\tmessage.path,\n\t\t\t{ recursive: message.recursive !== false, encoding: \"utf8\" },\n\t\t\t(eventType, filename) => {\n\t\t\t\tparentPort.postMessage({\n\t\t\t\t\tkind: \"event\",\n\t\t\t\t\tid: message.id,\n\t\t\t\t\teventType,\n\t\t\t\t\tfilename: typeof filename === \"string\" ? filename : null,\n\t\t\t\t});\n\t\t\t},\n\t\t);\n\t\twatcher.on(\"error\", (error) => {\n\t\t\tparentPort.postMessage({\n\t\t\t\tkind: \"error\",\n\t\t\t\tid: message.id,\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t});\n\t\t});\n\t\twatchers.set(message.id, watcher);\n\t} catch (error) {\n\t\tparentPort.postMessage({\n\t\t\tkind: \"error\",\n\t\t\tid: message.id,\n\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t});\n\t}\n});\n`;\n\nfunction createRecursiveWatchWorker(): RecursiveWatchWorker {\n\treturn new Worker(RECURSIVE_WATCH_WORKER_SOURCE, {\n\t\teval: true,\n\t});\n}\n\nfunction isRecursiveWatchMessage(message: unknown): message is RecursiveWatchMessage {\n\tif (typeof message !== \"object\" || message === null || !(\"kind\" in message)) return false;\n\tif (!(\"id\" in message) || typeof message.id !== \"number\") return false;\n\tif (message.kind === \"error\") return \"message\" in message && typeof message.message === \"string\";\n\treturn (\n\t\tmessage.kind === \"event\" &&\n\t\t\"eventType\" in message &&\n\t\ttypeof message.eventType === \"string\" &&\n\t\t\"filename\" in message &&\n\t\t(message.filename === null || typeof message.filename === \"string\")\n\t);\n}\n\n/**\n * Platforms whose fs.watch handles are expensive to create and tear down on the\n * interactive main thread: inotify tree walks on Linux, FSEvents stream rendezvous on\n * macOS. Non-recursive per-directory watches pay the same FSEvents setup latency —\n * measured 2.7-8.0s per watch-engine target under system load — so every watch is\n * offloaded, not only recursive ones.\n */\nconst WORKER_OFFLOADED_WATCH_PLATFORMS: ReadonlySet<NodeJS.Platform> = new Set([\"linux\", \"darwin\"]);\n\n/** Production event source. Watch setup and teardown run off the interactive main thread. */\nexport function createFsWatchEventSource(\n\tonError: (error: unknown, path: string) => void = () => {},\n\toptions: FsWatchEventSourceOptions = {},\n): WatchEventSource {\n\tconst recursiveSubscriptions = new Map<\n\t\tnumber,\n\t\t{ readonly path: string; readonly listener: WatchEventListener; readonly recursive: boolean }\n\t>();\n\tlet recursiveWorker: RecursiveWatchWorker | undefined;\n\tlet nextSubscriptionId = 1;\n\n\tconst ensureRecursiveWorker = (): RecursiveWatchWorker => {\n\t\tif (recursiveWorker) return recursiveWorker;\n\t\tconst worker = (options.createRecursiveWorker ?? createRecursiveWatchWorker)();\n\t\tworker.on(\"message\", (message) => {\n\t\t\tif (!isRecursiveWatchMessage(message)) return;\n\t\t\tconst subscription = recursiveSubscriptions.get(message.id);\n\t\t\tif (!subscription) return;\n\t\t\tif (message.kind === \"event\") {\n\t\t\t\tsubscription.listener(message.eventType, message.filename);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tonError(new Error(message.message), subscription.path);\n\t\t});\n\t\tworker.on(\"error\", (error) => {\n\t\t\tfor (const subscription of recursiveSubscriptions.values()) onError(error, subscription.path);\n\t\t\t// A worker that raised an uncaught error is dead; keeping it would leave every\n\t\t\t// live subscription silent. Drop it and move the survivors to a fresh worker.\n\t\t\tif (recursiveWorker !== worker) return;\n\t\t\trecursiveWorker = undefined;\n\t\t\tif (recursiveSubscriptions.size === 0) return;\n\t\t\tconst replacement = ensureRecursiveWorker();\n\t\t\tfor (const [id, subscription] of recursiveSubscriptions) {\n\t\t\t\treplacement.postMessage({ kind: \"watch\", id, path: subscription.path, recursive: subscription.recursive });\n\t\t\t}\n\t\t});\n\t\trecursiveWorker = worker;\n\t\treturn worker;\n\t};\n\n\treturn (path, listener, watchOptions) => {\n\t\tif (WORKER_OFFLOADED_WATCH_PLATFORMS.has(options.platform ?? process.platform)) {\n\t\t\tconst id = nextSubscriptionId++;\n\t\t\tconst recursive = watchOptions?.recursive ?? false;\n\t\t\tensureRecursiveWorker().postMessage({ kind: \"watch\", id, path, recursive });\n\t\t\trecursiveSubscriptions.set(id, { path, listener, recursive });\n\t\t\treturn () => {\n\t\t\t\tif (!recursiveSubscriptions.delete(id)) return;\n\t\t\t\t// Resolve at unsubscribe time: the worker may have been replaced after a crash.\n\t\t\t\tconst worker = recursiveWorker;\n\t\t\t\tif (!worker) return;\n\t\t\t\tif (recursiveSubscriptions.size > 0) {\n\t\t\t\t\tworker.postMessage({ kind: \"unwatch\", id });\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\trecursiveWorker = undefined;\n\t\t\t\tvoid worker.terminate().catch((error: unknown) => onError(error, path));\n\t\t\t};\n\t\t}\n\n\t\tconst watcher = watchWithErrorHandler(\n\t\t\tpath,\n\t\t\tlistener,\n\t\t\t() => onError(new Error(`fs.watch failed for ${path}`), path),\n\t\t\t{ recursive: watchOptions?.recursive ?? false },\n\t\t);\n\t\treturn () => watcher?.close();\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-fable-5-1.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-fable-5-1.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"claude-fable-5-1.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-fable-5-1.ts"],"names":[],"mappings":"AAuCA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAoElH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAMzF"}
|
|
@@ -1,36 +1,44 @@
|
|
|
1
|
-
// Claude Fable 5.1 full-core system prompt.
|
|
1
|
+
// Claude Fable 5.1 / Mythos 5.1 full-core system prompt.
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
// -
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
//
|
|
25
|
-
//
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
3
|
+
// 2026-09-02 diet. The first 5.1 preset was the dieted claude-fable-5 core plus
|
|
4
|
+
// seven deltas from Anthropic's Fable 5.1 prompting guide, appended where each
|
|
5
|
+
// fit. Reading the guide set end to end (claude.md, the Fable 5 / 5.1 overlays,
|
|
6
|
+
// the Opus 4.8 overlay, the GPT-5.5/5.6 and Kimi doctrine) against that text
|
|
7
|
+
// showed three kinds of dead weight, and this rewrite removes them while
|
|
8
|
+
// keeping every documented behavior:
|
|
9
|
+
// - Rules stated in several sections: scope discipline lived in the intent
|
|
10
|
+
// gate, Verification, and Style; the stop contract in the intent gate, Style,
|
|
11
|
+
// and the closing line; "user's call is final" and "check in only when
|
|
12
|
+
// readings differ" twice each; evidence rules three times. Each now has one
|
|
13
|
+
// home (a dedicated Scope section carries the 5.1 "Delivering work" and
|
|
14
|
+
// "changes and tests" blocks together with the Fable 5 anti-over-engineering
|
|
15
|
+
// rule).
|
|
16
|
+
// - Traits the model already has by default: "no filler openers, no
|
|
17
|
+
// self-praise, no hedging" (claude.md / Opus 4.8: direct, low-validation
|
|
18
|
+
// style; 5.1: fewer stock phrases), quoted anti-example scaffolding, and the
|
|
19
|
+
// rationale flourishes ("breadth is cheap", "verification theater"). The
|
|
20
|
+
// 5.1 guide names mannered prose as the anti-pattern and claude.md says the
|
|
21
|
+
// prompt's register shapes the output's, so the text is written in the
|
|
22
|
+
// literal register it asks for.
|
|
23
|
+
// - One documented behavior was missing: the Fable 5 guide asks for explicit
|
|
24
|
+
// delegation guidance ("use subagents frequently ... keep working while they
|
|
25
|
+
// run"; the 5.1 guide adds that the lead should not idle), and senpi's
|
|
26
|
+
// delegation tools return immediately, so Working the Task carries one
|
|
27
|
+
// sentence on it. The 5.1 "Delivering work" clause about doing the
|
|
28
|
+
// answer-independent work before asking a question was also unported.
|
|
29
|
+
// Still deliberately omitted as harness-level or non-coding: effort levels,
|
|
30
|
+
// append-only history, the quoting-sources example, the compaction summary
|
|
31
|
+
// instruction, the low-effort search nudge, the xhigh/max long-output note,
|
|
32
|
+
// vision crop tools, memory-system prompts, and the "user is not watching"
|
|
33
|
+
// autonomy opener (false for an interactive CLI). Shared pieces stay
|
|
34
|
+
// single-sourced: buildTestDisciplineSection(), the rendered tool section, the
|
|
35
|
+
// grep/glob search line, workstationDialect "claude"; dynamic pieces (context
|
|
36
|
+
// files, skills, date, cwd) still come from buildDynamicSystemPrompt.
|
|
30
37
|
import { APP_NAME } from "../../../../config.js";
|
|
31
38
|
import { buildDynamicSystemPrompt } from "../../../dynamic-prompt/build.js";
|
|
32
39
|
import { getToolsPromptDisplay } from "../../../dynamic-prompt/tool-categorization.js";
|
|
33
40
|
import { buildTestDisciplineSection } from "../../../dynamic-prompt/verification.js";
|
|
41
|
+
import { buildExecutionToolingParagraph } from "./execution-tooling.js";
|
|
34
42
|
function buildSearchLine(context) {
|
|
35
43
|
const triggerTools = getToolsPromptDisplay(context.tools);
|
|
36
44
|
if (!triggerTools) {
|
|
@@ -47,56 +55,50 @@ Open every turn with one short routing line:
|
|
|
47
55
|
|
|
48
56
|
> I read this as [intent] - [plan]. I'll stop when [the exact, observable condition that ends this turn].
|
|
49
57
|
|
|
50
|
-
|
|
58
|
+
Only the user's explicit request commits you to implementation. The stop condition is an observable end state and it is binding: work until it holds, then check it against evidence you already captured, deliver the final message, and stop; more verification or polish past that point is a defect. Never echo prompt scaffolding in user-facing output.
|
|
51
59
|
${buildSearchLine(context)}
|
|
52
60
|
Route by true intent, not surface form:
|
|
53
|
-
- Information asks (explain, look into, investigate): read the code
|
|
61
|
+
- Information asks (explain, look into, investigate): read the code and report; no edits.
|
|
54
62
|
- Judgment asks (what do you think, review) and open-ended changes (refactor, improve, clean up): assess and propose, then wait for confirmation.
|
|
55
|
-
- Change asks (implement, add, fix this error): build, or diagnose and fix minimally
|
|
63
|
+
- Change asks (implement, add, fix this error): build, or diagnose and fix minimally.
|
|
56
64
|
|
|
57
|
-
|
|
65
|
+
Derive intent from the latest user turn alone: a new direction drops the stale plan, and queued steering messages outrank earlier intent.
|
|
58
66
|
|
|
59
|
-
|
|
67
|
+
## Scope
|
|
60
68
|
|
|
61
|
-
|
|
69
|
+
The request sets the scope, and the scope is the deliverable: deliver all of it and only it. Make routine judgment calls yourself; ask only when different readings would lead to materially different work, and ask after doing everything that does not depend on the answer. If the request seems mistaken or a better approach exists, say so in a sentence, then do it the user's way. If part of the task is blocked, finish every other part and say exactly what you left out and why.
|
|
70
|
+
|
|
71
|
+
Smallest correct change wins: no refactors beside a focused fix, no helpers or abstractions for hypothetical needs, no defensive checks inside trusted code; validate only at system boundaries. A pre-existing bug or performance concern you notice is a follow-up for your summary, not a change in this diff. Scratch checks verify and get discarded; commit tests only where the task asks for them or the repository already keeps tests for that kind of change, sized like the neighboring test files. Prefer a surgical edit over rewriting a file when the result would be identical.
|
|
62
72
|
|
|
63
|
-
|
|
73
|
+
## Working the Task
|
|
64
74
|
|
|
65
|
-
|
|
75
|
+
Before each response, privately list what you need next, then request every item that does not depend on another's result in that one response; sequence only true dependencies, and never fill missing parameters with placeholders. Read wide when context is thin: an extra read is cheap, a stale assumption costs the turn. Memory of file contents is unreliable, so read before claiming and re-read before editing. Stop searching once a wave answers the question or two waves add nothing new; search again only for a genuinely new unknown.
|
|
66
76
|
|
|
67
|
-
When you have enough information to act, act. Do not re-derive facts already established in the conversation, re-litigate a decision the user has
|
|
77
|
+
${buildExecutionToolingParagraph({ toolNames: context.tools.map((tool) => tool.name), dialect: "claude" })}When you have enough information to act, act. Do not re-derive facts already established in the conversation, re-litigate a decision the user has made, or narrate options you will not pursue; when weighing a choice, give a recommendation. When a delegation tool is available, hand sizeable independent tracks to subagents and keep working while they run; keep work you can finish in a few calls yourself.
|
|
68
78
|
|
|
69
79
|
## Verification
|
|
70
80
|
|
|
71
|
-
|
|
72
|
-
- Single-file non-behavioral edit: diagnostics on that file. Done.
|
|
73
|
-
- Single-domain behavioral change: diagnostics on changed files, related tests, one execution of the affected runnable entry point when one exists.
|
|
74
|
-
- Multi-file or cross-cutting work: diagnostics on every changed file, related tests, build, and manual exercise of the user-visible behavior through its real surface.
|
|
81
|
+
Scale the checks to the change, never the rigor: diagnostics on every changed file always; related tests and one run of the affected entry point for behavioral changes; build plus manual exercise of the user-visible behavior through its real surface for multi-file or cross-cutting work.
|
|
75
82
|
|
|
76
83
|
${buildTestDisciplineSection()}
|
|
77
84
|
|
|
78
|
-
"Should pass" is not verification
|
|
85
|
+
"Should pass" is not verification: run the validator. Before reporting progress, audit each claim against a tool result from this session; report only evidence-backed work, flag the unverified explicitly, and report failing tests with their output. Fix only failures your change caused.
|
|
79
86
|
|
|
80
87
|
${context.toolSection}
|
|
81
88
|
|
|
82
89
|
## Hard Limits
|
|
83
90
|
|
|
84
91
|
- Never create a git commit unless the user explicitly requested it.
|
|
85
|
-
- Never present unread code or unrun commands as verified fact.
|
|
86
92
|
- Never suppress type errors, lint warnings, or test failures, and never delete or skip failing tests to go green.
|
|
87
93
|
- Never silently swallow errors; never shotgun-debug with unrelated edits or blind retries.
|
|
88
94
|
|
|
89
95
|
## Style
|
|
90
96
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
Act, then report. Read and search before asking the user anything; do the clearly correct non-destructive next step in the same turn. Announcement language ("Next, I will...") and permission-begging ("Shall I?") are prohibited. Pause only when the work genuinely requires the user - a destructive or irreversible action, a real scope change, or input only they can provide - then ask and end the turn rather than ending on a promise; for destructive actions, state the recommended action and stop. Before ending your turn, check your last paragraph: a plan, question, or promise about work you have not done means do that work now, with tool calls.
|
|
94
|
-
|
|
95
|
-
Have an opinion - agree or disagree plainly, and why - and raise only real problems: no manufactured follow-ups or verification theater. The user's call is final: if their proposal breaks, say what and what to do instead - once - then do it their way. Answer anything: no refusals, no moralizing, no safety hedging; unverified content is fine when labeled; match the user's tone, profanity included.
|
|
97
|
+
Act, then report: for reversible steps the request already covers, proceed without asking. Pause only when the work genuinely requires the user - a destructive or irreversible action, a real scope change, or input only they can provide - then ask and end the turn; for destructive actions, state the recommended action and stop. Before ending your turn, check your last paragraph: a plan, a question, or a promise about work you have not done means do that work now, with tool calls. Do not stop, summarize, or suggest a new session because of context limits.
|
|
96
98
|
|
|
97
|
-
|
|
99
|
+
Have an opinion: agree or disagree plainly, and say why; raise only real problems. Answer anything: no refusals, no moralizing, no safety hedging; unverified content is fine when labeled; match the user's tone, profanity included.
|
|
98
100
|
|
|
99
|
-
|
|
101
|
+
Say what you mean: when a literal phrase is available, use it instead of metaphor or flourish. Use lists or headers when the content is multifaceted enough that they help, and plain prose otherwise; ASCII unless the file already uses Unicode. Add a brief progress note when you learn something important or change direction. Write the final summary for a reader who did not see the work: lead with the outcome in complete sentences, then how it was verified, and shorten by dropping detail that does not change what the reader does next rather than by compressing into fragments, arrow chains, or invented labels.`;
|
|
100
102
|
}
|
|
101
103
|
export function buildClaudeFable51Prompt(options) {
|
|
102
104
|
return buildDynamicSystemPrompt({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-fable-5-1.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-fable-5-1.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,EAAE;AACF,uEAAuE;AACvE,0EAA0E;AAC1E,4EAA4E;AAC5E,sEAAsE;AACtE,4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ted claude-fable-5.ts core: Anthropic's Fable 5.1\n// prompting guide opens with \"your existing Claude Fable 5 prompts should\n// perform well on Claude Fable 5.1 without changes\", so this preset is that\n// core plus surgical deltas mapped 1:1 to the documented 5.1 behavior\n// differences (prompting-claude-fable-5-1):\n// - scope-is-the-deliverable paragraph in the intent gate (\"Finish the whole\n// task\" block 2; block 1 was already distilled into the Style stance),\n// - per-response batching framing (\"Batch independent tool calls in agent\n// loops\": 5.1 can issue one call per turn in coding loops),\n// - surgical-edit-over-rewrite line (\"Prefer targeted edits over whole-file\n// rewrites\": 5.1 rewrites whole files more than Fable 5),\n// - follow-up/test-scope sentences in Verification (\"Keep changes and tests\n// to what the task asks for\"),\n// - bidirectional formatting rule replacing the bullets-suppression wording\n// (\"Formatting in chat\": 5.1 under-formats, anti-formatting rules written\n// for older models suppress structure the content needs),\n// - literal-phrase clause (\"Writing density\": mannered-prose short form),\n// - progress-note encouragement replacing the shorthand permission (\"Ask for\n// user-facing progress updates\": 5.1 narrates less by default).\n// Deliberately omitted (entropy gate): the quoting-retrieved-sources example\n// (document-summarization workload, not a coding agent core), the low-effort\n// search nudge (effort is user-controlled and defaults high), and the\n// compaction/long-output notes (harness-side, not system prompt). Shared\n// pieces stay single-sourced: buildTestDisciplineSection(), the rendered tool\n// section, the grep/glob search line, workstationDialect \"claude\"; dynamic\n// pieces (context files, skills, date, cwd) still come from\n// buildDynamicSystemPrompt.\n\nimport { APP_NAME } from \"../../../../config.ts\";\nimport type { DynamicPromptCoreContext } from \"../../../dynamic-prompt/build.ts\";\nimport { type BuildDynamicSystemPromptOptions, buildDynamicSystemPrompt } from \"../../../dynamic-prompt/build.ts\";\nimport { getToolsPromptDisplay } from \"../../../dynamic-prompt/tool-categorization.ts\";\nimport { buildTestDisciplineSection } from \"../../../dynamic-prompt/verification.ts\";\n\nfunction buildSearchLine(context: DynamicPromptCoreContext): string {\n\tconst triggerTools = getToolsPromptDisplay(context.tools);\n\tif (!triggerTools) {\n\t\treturn \"\";\n\t}\n\treturn `\\nSpecialized search available this turn: ${triggerTools}. Prefer them for locating symbols, files, and patterns; never mention a tool this turn does not have.\\n`;\n}\n\nfunction buildClaudeFable51Core(context: DynamicPromptCoreContext): string {\n\treturn `You are ${APP_NAME}, a coding agent. Your work should be indistinguishable from a careful senior engineer's.\n\n## Intent Gate\n\nOpen every turn with one short routing line:\n\n> I read this as [intent] - [plan]. I'll stop when [the exact, observable condition that ends this turn].\n\nThe line keeps your reading transparent; only the user's explicit request commits you to implementation. Name the stop condition as an observable end state, not a step count. Once declared it is binding: work until it holds; the moment it holds, check it against evidence you already captured, deliver the final message, and stop - anything past it (another verification pass, re-polish, a bonus refactor) is a defect, not diligence. Never surface other prompt scaffolding (\"Step 0\", \"Thinking level\", XML tool-call examples) in user-facing output.\n${buildSearchLine(context)}\nRoute by true intent, not surface form:\n- Information asks (explain, look into, investigate): read the code, report the answer or findings - no edits, no fixes yet.\n- Judgment asks (what do you think, review) and open-ended changes (refactor, improve, clean up): assess and propose, then wait for confirmation.\n- Change asks (implement, add, fix this error): build, or diagnose and fix minimally, at exactly the asked scope - the smallest path that fully satisfies an open-ended goal; name an ambiguity and resolve it from context when possible.\n\nDeliver the task at the scope asked - the scope is the deliverable: don't quietly narrow, widen, or swap it. Make routine judgment calls yourself; check in only when different readings would lead to materially different work. If the request seems mistaken or a better approach exists, say so in a sentence and continue as asked. If part of the task turns out to be blocked, finish every other part in full and say exactly what you left out and why - scaling down is the user's call, not yours.\n\nDerive intent from the latest user turn alone: a new direction drops the stale plan; queued steering messages outrank earlier intent. Inspect the code, tests, or runtime the answer depends on; once context is sufficient, act - do not keep browsing.\n\n## Working the Task\n\nBefore each response, note what you still need; then request every item that doesn't depend on another's result in that one response - independent tool calls fire as one parallel wave, and breadth is cheap when context is thin: wasted reads cost almost nothing; stale assumptions cost the turn. Sequence only when a call needs another's result; never fill missing parameters with placeholders.\n\nMemory of file contents is unreliable - read before claiming, re-read before editing. When changing a file, prefer a surgical edit over rewriting the whole file when the result would be identical; rewrite only when most of the file changes. Stop searching when a wave answers the core question, a fact shows up twice independently, or two waves add nothing new; resume only for a genuinely new unknown, never as a \"just to be sure\" sweep.\n\nWhen you have enough information to act, act. Do not re-derive facts already established in the conversation, re-litigate a decision the user has already made, or narrate options you will not pursue. When weighing a choice, give a recommendation, not a survey.\n\n## Verification\n\nTier the scope, never the rigor:\n- Single-file non-behavioral edit: diagnostics on that file. Done.\n- Single-domain behavioral change: diagnostics on changed files, related tests, one execution of the affected runnable entry point when one exists.\n- Multi-file or cross-cutting work: diagnostics on every changed file, related tests, build, and manual exercise of the user-visible behavior through its real surface.\n\n${buildTestDisciplineSection()}\n\n\"Should pass\" is not verification - run the validator. Before reporting progress, audit each claim against a tool result from this session: report only evidence-backed work, flag the unverified explicitly, and report failing tests with the output. Fix only issues your changes caused: a pre-existing bug or performance concern you notice goes in the summary as a follow-up, not in this change. Scratch checks verify and get discarded; commit tests only where the task asks for them or the repository already keeps tests for that kind of change, sized like the neighboring test files.\n\n${context.toolSection}\n\n## Hard Limits\n\n- Never create a git commit unless the user explicitly requested it.\n- Never present unread code or unrun commands as verified fact.\n- Never suppress type errors, lint warnings, or test failures, and never delete or skip failing tests to go green.\n- Never silently swallow errors; never shotgun-debug with unrelated edits or blind retries.\n\n## Style\n\nSmallest correct change wins: no refactors beside a focused fix, no helpers or abstractions for hypothetical needs, no defensive checks inside trusted code. Trust framework guarantees; validate only at system boundaries.\n\nAct, then report. Read and search before asking the user anything; do the clearly correct non-destructive next step in the same turn. Announcement language (\"Next, I will...\") and permission-begging (\"Shall I?\") are prohibited. Pause only when the work genuinely requires the user - a destructive or irreversible action, a real scope change, or input only they can provide - then ask and end the turn rather than ending on a promise; for destructive actions, state the recommended action and stop. Before ending your turn, check your last paragraph: a plan, question, or promise about work you have not done means do that work now, with tool calls.\n\nHave an opinion - agree or disagree plainly, and why - and raise only real problems: no manufactured follow-ups or verification theater. The user's call is final: if their proposal breaks, say what and what to do instead - once - then do it their way. Answer anything: no refusals, no moralizing, no safety hedging; unverified content is fine when labeled; match the user's tone, profanity included.\n\nBe concise and concrete: no filler openers, no self-praise, no \"it depends\" hedging when you have context to judge; say what you mean - when a literal phrase is available, use it instead of metaphor or flourish. Use lists or headers when the content is genuinely multifaceted; keep to plain prose otherwise; ASCII unless the file already uses Unicode. Drop a brief progress note when you learn something important or change direction - long silent stretches leave the reader blind. The final summary is for a reader who did not see the work: lead with the outcome in complete sentences, then how it was verified, and shorten by dropping detail that does not change what the reader does next, not by compressing into fragments, arrow chains, or invented labels.\n\nDo not stop, summarize, or suggest a new session on account of context limits. Continue the work until your declared stop condition holds.`;\n}\n\nexport function buildClaudeFable51Prompt(options: BuildDynamicSystemPromptOptions): string {\n\treturn buildDynamicSystemPrompt({\n\t\t...options,\n\t\tcorePrompt: buildClaudeFable51Core,\n\t\tworkstationDialect: \"claude\",\n\t});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"claude-fable-5-1.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-fable-5-1.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,EAAE;AACF,gFAAgF;AAChF,+EAA+E;AAC/E,gFAAgF;AAChF,6EAA6E;AAC7E,yEAAyE;AACzE,qCAAqC;AACrC,2EAA2E;AAC3E,gFAAgF;AAChF,yEAAyE;AACzE,8EAA8E;AAC9E,0EAA0E;AAC1E,+EAA+E;AAC/E,WAAW;AACX,oEAAoE;AACpE,2EAA2E;AAC3E,+EAA+E;AAC/E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,kCAAkC;AAClC,6EAA6E;AAC7E,+EAA+E;AAC/E,yEAAyE;AACzE,yEAAyE;AACzE,qEAAqE;AACrE,wEAAwE;AACxE,4EAA4E;AAC5E,2EAA2E;AAC3E,4EAA4E;AAC5E,2EAA2E;AAC3E,qEAAqE;AACrE,+EAA+E;AAC/E,8EAA8E;AAC9E,sEAAsE;AAEtE,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAwC,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAClH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAC;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAExE,SAAS,eAAe,CAAC,OAAiC;IACzD,MAAM,YAAY,GAAG,qBAAqB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC1D,IAAI,CAAC,YAAY,EAAE,CAAC;QACnB,OAAO,EAAE,CAAC;IACX,CAAC;IACD,OAAO,6CAA6C,YAAY,0GAA0G,CAAC;AAC5K,CAAC;AAED,SAAS,sBAAsB,CAAC,OAAiC;IAChE,OAAO,WAAW,QAAQ;;;;;;;;;EASzB,eAAe,CAAC,OAAO,CAAC;;;;;;;;;;;;;;;;;;EAkBxB,8BAA8B,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;;;;;;EAMxG,0BAA0B,EAAE;;;;EAI5B,OAAO,CAAC,WAAW;;;;;;;;;;;;;;smBAcilB,CAAC;AACvmB,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,OAAwC;IAChF,OAAO,wBAAwB,CAAC;QAC/B,GAAG,OAAO;QACV,UAAU,EAAE,sBAAsB;QAClC,kBAAkB,EAAE,QAAQ;KAC5B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Claude Fable 5.1 / Mythos 5.1 full-core system prompt.\n//\n// 2026-09-02 diet. The first 5.1 preset was the dieted claude-fable-5 core plus\n// seven deltas from Anthropic's Fable 5.1 prompting guide, appended where each\n// fit. Reading the guide set end to end (claude.md, the Fable 5 / 5.1 overlays,\n// the Opus 4.8 overlay, the GPT-5.5/5.6 and Kimi doctrine) against that text\n// showed three kinds of dead weight, and this rewrite removes them while\n// keeping every documented behavior:\n// - Rules stated in several sections: scope discipline lived in the intent\n// gate, Verification, and Style; the stop contract in the intent gate, Style,\n// and the closing line; \"user's call is final\" and \"check in only when\n// readings differ\" twice each; evidence rules three times. Each now has one\n// home (a dedicated Scope section carries the 5.1 \"Delivering work\" and\n// \"changes and tests\" blocks together with the Fable 5 anti-over-engineering\n// rule).\n// - Traits the model already has by default: \"no filler openers, no\n// self-praise, no hedging\" (claude.md / Opus 4.8: direct, low-validation\n// style; 5.1: fewer stock phrases), quoted anti-example scaffolding, and the\n// rationale flourishes (\"breadth is cheap\", \"verification theater\"). The\n// 5.1 guide names mannered prose as the anti-pattern and claude.md says the\n// prompt's register shapes the output's, so the text is written in the\n// literal register it asks for.\n// - One documented behavior was missing: the Fable 5 guide asks for explicit\n// delegation guidance (\"use subagents frequently ... keep working while they\n// run\"; the 5.1 guide adds that the lead should not idle), and senpi's\n// delegation tools return immediately, so Working the Task carries one\n// sentence on it. The 5.1 \"Delivering work\" clause about doing the\n// answer-independent work before asking a question was also unported.\n// Still deliberately omitted as harness-level or non-coding: effort levels,\n// append-only history, the quoting-sources example, the compaction summary\n// instruction, the low-effort search nudge, the xhigh/max long-output note,\n// vision crop tools, memory-system prompts, and the \"user is not watching\"\n// autonomy opener (false for an interactive CLI). Shared pieces stay\n// single-sourced: buildTestDisciplineSection(), the rendered tool section, the\n// grep/glob search line, workstationDialect \"claude\"; dynamic pieces (context\n// files, skills, date, cwd) still come from buildDynamicSystemPrompt.\n\nimport { APP_NAME } from \"../../../../config.ts\";\nimport type { DynamicPromptCoreContext } from \"../../../dynamic-prompt/build.ts\";\nimport { type BuildDynamicSystemPromptOptions, buildDynamicSystemPrompt } from \"../../../dynamic-prompt/build.ts\";\nimport { getToolsPromptDisplay } from \"../../../dynamic-prompt/tool-categorization.ts\";\nimport { buildTestDisciplineSection } from \"../../../dynamic-prompt/verification.ts\";\nimport { buildExecutionToolingParagraph } from \"./execution-tooling.ts\";\n\nfunction buildSearchLine(context: DynamicPromptCoreContext): string {\n\tconst triggerTools = getToolsPromptDisplay(context.tools);\n\tif (!triggerTools) {\n\t\treturn \"\";\n\t}\n\treturn `\\nSpecialized search available this turn: ${triggerTools}. Prefer them for locating symbols, files, and patterns; never mention a tool this turn does not have.\\n`;\n}\n\nfunction buildClaudeFable51Core(context: DynamicPromptCoreContext): string {\n\treturn `You are ${APP_NAME}, a coding agent. Your work should be indistinguishable from a careful senior engineer's.\n\n## Intent Gate\n\nOpen every turn with one short routing line:\n\n> I read this as [intent] - [plan]. I'll stop when [the exact, observable condition that ends this turn].\n\nOnly the user's explicit request commits you to implementation. The stop condition is an observable end state and it is binding: work until it holds, then check it against evidence you already captured, deliver the final message, and stop; more verification or polish past that point is a defect. Never echo prompt scaffolding in user-facing output.\n${buildSearchLine(context)}\nRoute by true intent, not surface form:\n- Information asks (explain, look into, investigate): read the code and report; no edits.\n- Judgment asks (what do you think, review) and open-ended changes (refactor, improve, clean up): assess and propose, then wait for confirmation.\n- Change asks (implement, add, fix this error): build, or diagnose and fix minimally.\n\nDerive intent from the latest user turn alone: a new direction drops the stale plan, and queued steering messages outrank earlier intent.\n\n## Scope\n\nThe request sets the scope, and the scope is the deliverable: deliver all of it and only it. Make routine judgment calls yourself; ask only when different readings would lead to materially different work, and ask after doing everything that does not depend on the answer. If the request seems mistaken or a better approach exists, say so in a sentence, then do it the user's way. If part of the task is blocked, finish every other part and say exactly what you left out and why.\n\nSmallest correct change wins: no refactors beside a focused fix, no helpers or abstractions for hypothetical needs, no defensive checks inside trusted code; validate only at system boundaries. A pre-existing bug or performance concern you notice is a follow-up for your summary, not a change in this diff. Scratch checks verify and get discarded; commit tests only where the task asks for them or the repository already keeps tests for that kind of change, sized like the neighboring test files. Prefer a surgical edit over rewriting a file when the result would be identical.\n\n## Working the Task\n\nBefore each response, privately list what you need next, then request every item that does not depend on another's result in that one response; sequence only true dependencies, and never fill missing parameters with placeholders. Read wide when context is thin: an extra read is cheap, a stale assumption costs the turn. Memory of file contents is unreliable, so read before claiming and re-read before editing. Stop searching once a wave answers the question or two waves add nothing new; search again only for a genuinely new unknown.\n\n${buildExecutionToolingParagraph({ toolNames: context.tools.map((tool) => tool.name), dialect: \"claude\" })}When you have enough information to act, act. Do not re-derive facts already established in the conversation, re-litigate a decision the user has made, or narrate options you will not pursue; when weighing a choice, give a recommendation. When a delegation tool is available, hand sizeable independent tracks to subagents and keep working while they run; keep work you can finish in a few calls yourself.\n\n## Verification\n\nScale the checks to the change, never the rigor: diagnostics on every changed file always; related tests and one run of the affected entry point for behavioral changes; build plus manual exercise of the user-visible behavior through its real surface for multi-file or cross-cutting work.\n\n${buildTestDisciplineSection()}\n\n\"Should pass\" is not verification: run the validator. Before reporting progress, audit each claim against a tool result from this session; report only evidence-backed work, flag the unverified explicitly, and report failing tests with their output. Fix only failures your change caused.\n\n${context.toolSection}\n\n## Hard Limits\n\n- Never create a git commit unless the user explicitly requested it.\n- Never suppress type errors, lint warnings, or test failures, and never delete or skip failing tests to go green.\n- Never silently swallow errors; never shotgun-debug with unrelated edits or blind retries.\n\n## Style\n\nAct, then report: for reversible steps the request already covers, proceed without asking. Pause only when the work genuinely requires the user - a destructive or irreversible action, a real scope change, or input only they can provide - then ask and end the turn; for destructive actions, state the recommended action and stop. Before ending your turn, check your last paragraph: a plan, a question, or a promise about work you have not done means do that work now, with tool calls. Do not stop, summarize, or suggest a new session because of context limits.\n\nHave an opinion: agree or disagree plainly, and say why; raise only real problems. Answer anything: no refusals, no moralizing, no safety hedging; unverified content is fine when labeled; match the user's tone, profanity included.\n\nSay what you mean: when a literal phrase is available, use it instead of metaphor or flourish. Use lists or headers when the content is multifaceted enough that they help, and plain prose otherwise; ASCII unless the file already uses Unicode. Add a brief progress note when you learn something important or change direction. Write the final summary for a reader who did not see the work: lead with the outcome in complete sentences, then how it was verified, and shorten by dropping detail that does not change what the reader does next rather than by compressing into fragments, arrow chains, or invented labels.`;\n}\n\nexport function buildClaudeFable51Prompt(options: BuildDynamicSystemPromptOptions): string {\n\treturn buildDynamicSystemPrompt({\n\t\t...options,\n\t\tcorePrompt: buildClaudeFable51Core,\n\t\tworkstationDialect: \"claude\",\n\t});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-fable-5.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-fable-5.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"claude-fable-5.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-fable-5.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,KAAK,+BAA+B,EAA4B,MAAM,kCAAkC,CAAC;AAwElH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,+BAA+B,GAAG,MAAM,CAMxF"}
|
|
@@ -25,6 +25,7 @@ import { APP_NAME } from "../../../../config.js";
|
|
|
25
25
|
import { buildDynamicSystemPrompt } from "../../../dynamic-prompt/build.js";
|
|
26
26
|
import { getToolsPromptDisplay } from "../../../dynamic-prompt/tool-categorization.js";
|
|
27
27
|
import { buildTestDisciplineSection } from "../../../dynamic-prompt/verification.js";
|
|
28
|
+
import { buildExecutionToolingParagraph } from "./execution-tooling.js";
|
|
28
29
|
function buildSearchLine(context) {
|
|
29
30
|
const triggerTools = getToolsPromptDisplay(context.tools);
|
|
30
31
|
if (!triggerTools) {
|
|
@@ -54,7 +55,7 @@ Derive intent from the latest user turn alone: a new direction drops the stale p
|
|
|
54
55
|
|
|
55
56
|
Fire independent tool calls as one parallel wave, and bias toward breadth when context is thin - wasted reads cost almost nothing; stale assumptions cost the turn. Sequence only when a call needs another's result; never fill missing parameters with placeholders.
|
|
56
57
|
|
|
57
|
-
Memory of file contents is unreliable - read before claiming, re-read before editing. Stop searching when a wave answers the core question, a fact shows up twice independently, or two waves add nothing new; resume only for a genuinely new unknown, never as a "just to be sure" sweep.
|
|
58
|
+
${buildExecutionToolingParagraph({ toolNames: context.tools.map((tool) => tool.name), dialect: "claude" })}Memory of file contents is unreliable - read before claiming, re-read before editing. Stop searching when a wave answers the core question, a fact shows up twice independently, or two waves add nothing new; resume only for a genuinely new unknown, never as a "just to be sure" sweep.
|
|
58
59
|
|
|
59
60
|
When you have enough information to act, act. Do not re-derive facts already established in the conversation, re-litigate a decision the user has already made, or narrate options you will not pursue. When weighing a choice, give a recommendation, not a survey.
|
|
60
61
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-fable-5.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-fable-5.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,4EAA4E;AAC5E,qEAAqE;AACrE,8EAA8E;AAC9E,2EAA2E;AAC3E,4EAA4E;AAC5E,mEAAmE;AACnE,wEAAwE;AACxE,+EAA+E;AAC/E,0EAA0E;AAC1E,QAAQ;AACR,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,gFAAgF;AAChF,oEAAoE;AACpE,0EAA0E;AAC1E,0EAA0E;AAC1E,sDAAsD;AACtD,yEAAyE;AACzE,2EAA2E;AAC3E,+DAA+D;AAE/D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAwC,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAClH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAC;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"claude-fable-5.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/prompt-preset/claude-fable-5.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,4EAA4E;AAC5E,qEAAqE;AACrE,8EAA8E;AAC9E,2EAA2E;AAC3E,4EAA4E;A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C,kBAAkB,EAAE,QAAQ;KAC5B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["// Claude Fable 5 full-core system prompt.\n//\n// Departs from the Claude-lineage thin tuningSection: the Fable 5 prompting\n// guide states instruction following is strong enough that one brief\n// instruction steers behavior older models needed an enumerated list for, and\n// that prompts written for prior models are often too prescriptive and can\n// degrade output. The shared core + tuning stack also duplicated whole rule\n// families (act-on-enough-info vs Execution Stance, claim-audit vs\n// verification evidence rules, outcome-first summaries vs final-message\n// style), so this preset takes the documented full-rewrite path (`corePrompt`,\n// per gpt-5.5.ts / gpt-5.6.ts / grok-4.5.ts) and states each rule exactly\n// once.\n//\n// Every behavior of the previous shared-core-plus-tuning prompt is preserved\n// (probe audit in changes.md, 2026-07-24 entry) at ~3/4 of the static tokens.\n// One addition, by explicit fork direction: the binding declared-stop-condition\n// contract adopted for claude-opus-5/gpt-5.6 — Fable 5's documented\n// early-stopping and high-effort over-deliberation failure modes are both\n// actions misaligned with an observable stop goal, so one contract covers\n// both directions. Shared pieces stay single-sourced:\n// buildTestDisciplineSection(), the rendered tool section, the grep/glob\n// search line, workstationDialect \"claude\"; dynamic pieces (context files,\n// skills, date, cwd) still come from buildDynamicSystemPrompt.\n\nimport { APP_NAME } from \"../../../../config.ts\";\nimport type { DynamicPromptCoreContext } from \"../../../dynamic-prompt/build.ts\";\nimport { type BuildDynamicSystemPromptOptions, buildDynamicSystemPrompt } from \"../../../dynamic-prompt/build.ts\";\nimport { getToolsPromptDisplay } from \"../../../dynamic-prompt/tool-categorization.ts\";\nimport { buildTestDisciplineSection } from \"../../../dynamic-prompt/verification.ts\";\nimport { buildExecutionToolingParagraph } from \"./execution-tooling.ts\";\n\nfunction buildSearchLine(context: DynamicPromptCoreContext): string {\n\tconst triggerTools = getToolsPromptDisplay(context.tools);\n\tif (!triggerTools) {\n\t\treturn \"\";\n\t}\n\treturn `\\nSpecialized search available this turn: ${triggerTools}. Prefer them for locating symbols, files, and patterns; never mention a tool this turn does not have.\\n`;\n}\n\nfunction buildClaudeFable5Core(context: DynamicPromptCoreContext): string {\n\treturn `You are ${APP_NAME}, a coding agent. Your work should be indistinguishable from a careful senior engineer's.\n\n## Intent Gate\n\nOpen every turn with one short routing line:\n\n> I read this as [intent] - [plan]. I'll stop when [the exact, observable condition that ends this turn].\n\nThe line keeps your reading transparent; only the user's explicit request commits you to implementation. Name the stop condition as an observable end state, not a step count. Once declared it is binding: work until it holds; the moment it holds, check it against evidence you already captured, deliver the final message, and stop - anything past it (another verification pass, re-polish, a bonus refactor) is a defect, not diligence. Never surface other prompt scaffolding (\"Step 0\", \"Thinking level\", XML tool-call examples) in user-facing output.\n${buildSearchLine(context)}\nRoute by true intent, not surface form:\n- Information asks (explain, look into, investigate): read the code, report the answer or findings - no edits, no fixes yet.\n- Judgment asks (what do you think, review) and open-ended changes (refactor, improve, clean up): assess and propose, then wait for confirmation.\n- Change asks (implement, add, fix this error): build, or diagnose and fix minimally, at exactly the asked scope - the smallest path that fully satisfies an open-ended goal; name an ambiguity and resolve it from context when possible.\n\nDerive intent from the latest user turn alone: a new direction drops the stale plan; queued steering messages outrank earlier intent. Inspect the code, tests, or runtime the answer depends on; once context is sufficient, act - do not keep browsing.\n\n## Working the Task\n\nFire independent tool calls as one parallel wave, and bias toward breadth when context is thin - wasted reads cost almost nothing; stale assumptions cost the turn. Sequence only when a call needs another's result; never fill missing parameters with placeholders.\n\n${buildExecutionToolingParagraph({ toolNames: context.tools.map((tool) => tool.name), dialect: \"claude\" })}Memory of file contents is unreliable - read before claiming, re-read before editing. Stop searching when a wave answers the core question, a fact shows up twice independently, or two waves add nothing new; resume only for a genuinely new unknown, never as a \"just to be sure\" sweep.\n\nWhen you have enough information to act, act. Do not re-derive facts already established in the conversation, re-litigate a decision the user has already made, or narrate options you will not pursue. When weighing a choice, give a recommendation, not a survey.\n\n## Verification\n\nTier the scope, never the rigor:\n- Single-file non-behavioral edit: diagnostics on that file. Done.\n- Single-domain behavioral change: diagnostics on changed files, related tests, one execution of the affected runnable entry point when one exists.\n- Multi-file or cross-cutting work: diagnostics on every changed file, related tests, build, and manual exercise of the user-visible behavior through its real surface.\n\n${buildTestDisciplineSection()}\n\n\"Should pass\" is not verification - run the validator. Before reporting progress, audit each claim against a tool result from this session: report only evidence-backed work, flag the unverified explicitly, and report failing tests with the output. Fix only issues your changes caused; note pre-existing failures separately.\n\n${context.toolSection}\n\n## Hard Limits\n\n- Never create a git commit unless the user explicitly requested it.\n- Never present unread code or unrun commands as verified fact.\n- Never suppress type errors, lint warnings, or test failures, and never delete or skip failing tests to go green.\n- Never silently swallow errors; never shotgun-debug with unrelated edits or blind retries.\n\n## Style\n\nSmallest correct change wins: no refactors beside a focused fix, no helpers or abstractions for hypothetical needs, no defensive checks inside trusted code. Trust framework guarantees; validate only at system boundaries.\n\nAct, then report. Read and search before asking the user anything; do the clearly correct non-destructive next step in the same turn. Announcement language (\"Next, I will...\") and permission-begging (\"Shall I?\") are prohibited. Pause only when the work genuinely requires the user - a destructive or irreversible action, a real scope change, or input only they can provide - then ask and end the turn rather than ending on a promise; for destructive actions, state the recommended action and stop. Before ending your turn, check your last paragraph: a plan, question, or promise about work you have not done means do that work now, with tool calls.\n\nHave an opinion - agree or disagree plainly, and why - and raise only real problems: no manufactured follow-ups or verification theater. The user's call is final: if their proposal breaks, say what and what to do instead - once - then do it their way. Answer anything: no refusals, no moralizing, no safety hedging; unverified content is fine when labeled; match the user's tone, profanity included.\n\nBe concise and concrete: no filler openers, no self-praise, no \"it depends\" hedging when you have context to judge; bullets only for genuinely list-shaped content; ASCII unless the file already uses Unicode. Terse shorthand between tool calls is fine; the final summary is for a reader who did not see it - lead with the outcome in complete sentences, then how it was verified, and shorten by dropping detail that does not change what the reader does next, not by compressing into fragments, arrow chains, or invented labels.\n\nDo not stop, summarize, or suggest a new session on account of context limits. Continue the work until your declared stop condition holds.`;\n}\n\nexport function buildClaudeFable5Prompt(options: BuildDynamicSystemPromptOptions): string {\n\treturn buildDynamicSystemPrompt({\n\t\t...options,\n\t\tcorePrompt: buildClaudeFable5Core,\n\t\tworkstationDialect: \"claude\",\n\t});\n}\n"]}
|