@code-yeongyu/senpi 2026.8.26 → 2026.8.27
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 +55 -0
- package/README.md +3 -3
- package/dist/cli/args.d.ts +3 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +14 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +10 -1
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/bash-executor.d.ts.map +1 -1
- package/dist/core/bash-executor.js +67 -29
- package/dist/core/bash-executor.js.map +1 -1
- package/dist/core/credential-pool/classify.d.ts +42 -0
- package/dist/core/credential-pool/classify.d.ts.map +1 -0
- package/dist/core/credential-pool/classify.js +75 -0
- package/dist/core/credential-pool/classify.js.map +1 -0
- package/dist/core/credential-pool/env-slots.d.ts +22 -0
- package/dist/core/credential-pool/env-slots.d.ts.map +1 -0
- package/dist/core/credential-pool/env-slots.js +37 -0
- package/dist/core/credential-pool/env-slots.js.map +1 -0
- package/dist/core/credential-pool/failover.d.ts +54 -0
- package/dist/core/credential-pool/failover.d.ts.map +1 -0
- package/dist/core/credential-pool/failover.js +106 -0
- package/dist/core/credential-pool/failover.js.map +1 -0
- package/dist/core/credential-pool/rotation-stream.d.ts +43 -0
- package/dist/core/credential-pool/rotation-stream.d.ts.map +1 -0
- package/dist/core/credential-pool/rotation-stream.js +96 -0
- package/dist/core/credential-pool/rotation-stream.js.map +1 -0
- package/dist/core/credential-pool/state-store.d.ts +89 -0
- package/dist/core/credential-pool/state-store.d.ts.map +1 -0
- package/dist/core/credential-pool/state-store.js +166 -0
- package/dist/core/credential-pool/state-store.js.map +1 -0
- package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/index.js +67 -0
- package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
- package/dist/core/extensions/builtin/compaction/log.d.ts +1 -1
- package/dist/core/extensions/builtin/compaction/log.d.ts.map +1 -1
- package/dist/core/extensions/builtin/compaction/log.js +1 -0
- package/dist/core/extensions/builtin/compaction/log.js.map +1 -1
- package/dist/core/extensions/builtin/config-reload/index.js +14 -22
- package/dist/core/extensions/builtin/config-reload/index.js.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation-recovery.d.ts +1 -0
- package/dist/core/extensions/builtin/goal/continuation-recovery.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation-recovery.js +2 -0
- package/dist/core/extensions/builtin/goal/continuation-recovery.js.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation.d.ts +8 -1
- package/dist/core/extensions/builtin/goal/continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/continuation.js +15 -0
- package/dist/core/extensions/builtin/goal/continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/direct-input-lifecycle.js +2 -2
- package/dist/core/extensions/builtin/goal/direct-input-lifecycle.js.map +1 -1
- package/dist/core/extensions/builtin/goal/format.d.ts +6 -1
- package/dist/core/extensions/builtin/goal/format.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/format.js +6 -0
- package/dist/core/extensions/builtin/goal/format.js.map +1 -1
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.js +5 -2
- package/dist/core/extensions/builtin/goal/lifecycle-helpers.js.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/monitor-continuation.js +31 -7
- package/dist/core/extensions/builtin/goal/monitor-continuation.js.map +1 -1
- package/dist/core/extensions/builtin/goal/persistence.js +2 -0
- package/dist/core/extensions/builtin/goal/persistence.js.map +1 -1
- package/dist/core/extensions/builtin/goal/renderers.d.ts +14 -0
- package/dist/core/extensions/builtin/goal/renderers.d.ts.map +1 -0
- package/dist/core/extensions/builtin/goal/renderers.js +153 -0
- package/dist/core/extensions/builtin/goal/renderers.js.map +1 -0
- package/dist/core/extensions/builtin/goal/store.d.ts +6 -2
- package/dist/core/extensions/builtin/goal/store.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/store.js +8 -2
- package/dist/core/extensions/builtin/goal/store.js.map +1 -1
- package/dist/core/extensions/builtin/goal/tool-registration.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/tool-registration.js +16 -6
- package/dist/core/extensions/builtin/goal/tool-registration.js.map +1 -1
- package/dist/core/extensions/builtin/goal/types.d.ts +1 -0
- package/dist/core/extensions/builtin/goal/types.d.ts.map +1 -1
- package/dist/core/extensions/builtin/goal/types.js.map +1 -1
- package/dist/core/extensions/builtin/todotools/index.js +1 -1
- package/dist/core/extensions/builtin/todotools/index.js.map +1 -1
- package/dist/core/extensions/builtin/todotools/native-todo-mirror.d.ts +1 -1
- package/dist/core/extensions/builtin/todotools/native-todo-mirror.d.ts.map +1 -1
- package/dist/core/extensions/builtin/todotools/native-todo-mirror.js +1 -1
- package/dist/core/extensions/builtin/todotools/native-todo-mirror.js.map +1 -1
- package/dist/core/hidden-stdout-log.d.ts +10 -0
- package/dist/core/hidden-stdout-log.d.ts.map +1 -1
- package/dist/core/hidden-stdout-log.js +36 -5
- package/dist/core/hidden-stdout-log.js.map +1 -1
- package/dist/core/model-config-schema.d.ts +85 -12
- package/dist/core/model-config-schema.d.ts.map +1 -1
- package/dist/core/model-config-schema.js +25 -0
- package/dist/core/model-config-schema.js.map +1 -1
- package/dist/core/model-runtime.d.ts +34 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +98 -5
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts +2 -0
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +32 -7
- package/dist/core/tools/output-accumulator.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/main.d.ts.map +1 -1
- package/dist/main.js +26 -2
- package/dist/main.js.map +1 -1
- package/dist/modes/index.d.ts +1 -0
- package/dist/modes/index.d.ts.map +1 -1
- package/dist/modes/index.js +1 -0
- package/dist/modes/index.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution-fallback.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution-fallback.js +82 -1
- package/dist/modes/interactive/components/tool-execution-fallback.js.map +1 -1
- package/dist/modes/interactive/interactive-host-runtime.d.ts +29 -0
- package/dist/modes/interactive/interactive-host-runtime.d.ts.map +1 -0
- package/dist/modes/interactive/interactive-host-runtime.js +244 -0
- package/dist/modes/interactive/interactive-host-runtime.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +46 -8
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/connection-handler.d.ts.map +1 -1
- package/dist/modes/rpc/connection-handler.js +7 -1
- package/dist/modes/rpc/connection-handler.js.map +1 -1
- package/dist/modes/rpc/host-ensure.d.ts +41 -0
- package/dist/modes/rpc/host-ensure.d.ts.map +1 -0
- package/dist/modes/rpc/host-ensure.js +245 -0
- package/dist/modes/rpc/host-ensure.js.map +1 -0
- package/dist/modes/rpc/host-lifecycle.d.ts +57 -0
- package/dist/modes/rpc/host-lifecycle.d.ts.map +1 -0
- package/dist/modes/rpc/host-lifecycle.js +491 -0
- package/dist/modes/rpc/host-lifecycle.js.map +1 -0
- package/dist/modes/rpc/host-watchdog.d.ts +33 -0
- package/dist/modes/rpc/host-watchdog.d.ts.map +1 -0
- package/dist/modes/rpc/host-watchdog.js +142 -0
- package/dist/modes/rpc/host-watchdog.js.map +1 -0
- package/dist/modes/rpc/multi-session-host.d.ts +7 -1
- package/dist/modes/rpc/multi-session-host.d.ts.map +1 -1
- package/dist/modes/rpc/multi-session-host.js +206 -32
- package/dist/modes/rpc/multi-session-host.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +25 -0
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +83 -10
- 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/rpc-types.d.ts +2 -1
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/dist/modes/rpc/session-command-router.d.ts.map +1 -1
- package/dist/modes/rpc/session-command-router.js +12 -2
- package/dist/modes/rpc/session-command-router.js.map +1 -1
- package/dist/modes/rpc/session-event-writer.d.ts +13 -2
- package/dist/modes/rpc/session-event-writer.d.ts.map +1 -1
- package/dist/modes/rpc/session-event-writer.js +65 -25
- package/dist/modes/rpc/session-event-writer.js.map +1 -1
- package/docs/rpc.md +53 -1
- package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +30 -0
- package/node_modules/@code-yeongyu/senpi-codemode/package.json +4 -4
- package/node_modules/@code-yeongyu/senpi-codemode/src/kernels/js/worker-indirect-eval.js +711 -1
- package/node_modules/@code-yeongyu/senpi-codemode/src/prompt/eval-prompt.ts +10 -10
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/detached-eval-result.ts +9 -3
- package/node_modules/@code-yeongyu/senpi-codemode/src/tool/eval-tool.ts +6 -1
- package/node_modules/@earendil-works/pi-agent-core/package.json +3 -3
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.d.ts +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.js +46 -14
- package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-tool-pairs.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.d.ts +11 -0
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.js +30 -16
- package/node_modules/@earendil-works/pi-ai/dist/api/cursor-agent.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/classify.d.ts +16 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/classify.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/classify.js +75 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/classify.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.d.ts +45 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.js +81 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/failover.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/select.d.ts +31 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/select.d.ts.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/select.js +65 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/select.js.map +1 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts +12 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js +37 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/pool/slots.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js +32 -6
- package/node_modules/@earendil-works/pi-ai/dist/auth/resolve.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts +6 -0
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +6 -1
- package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts +75 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js +75 -0
- package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.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/amazon-bedrock.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/cloudflare-workers-ai.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/minimax-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/minimax.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/mistral.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/nvidia.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/providers/data/zai-coding-cn.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/providers/data/zai.json +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +4 -0
- package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
- package/node_modules/@earendil-works/pi-ai/package.json +5 -5
- 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/dist/terminal.d.ts +5 -0
- package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js +90 -1
- package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui.js +1 -1
- package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
- package/node_modules/@earendil-works/pi-tui/package.json +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/config-reload/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAiB,eAAe,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE/G,OAAO,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AACrG,OAAO,EAAE,8BAA8B,EAAE,MAAM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AC7D,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IACnC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED,SAAS,WAAW,CAAC,KAAwB;IAC5C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import { existsSync, lstatSync, readFileSync } from \"node:fs\";\nimport { basename, dirname, relative, resolve, sep } from \"node:path\";\nimport { bindToProviderScope } from \"@earendil-works/pi-ai/node/provider-scope\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../../../../config.ts\";\nimport { resolvePath } from \"../../../../utils/paths.ts\";\nimport { ModelConfig } from \"../../../model-config.ts\";\nimport { parseSettingsJson, type Settings, SettingsManager, wasSelfWrite } from \"../../../settings-manager.ts\";\nimport type { ExtensionAPI, ExtensionContext, SessionStartEvent } from \"../../types.ts\";\nimport { isLoadableExtensionEntry, isScannableExtensionDirectory } from \"./extension-watch-scope.ts\";\nimport { excludeGeneratedExtensionShims } from \"./generated-shim-filter.ts\";\nimport { type ConfigReloadLogger, createConfigReloadLogger } from \"./log.ts\";\nimport {\n\tCONFIG_WATCH_CHANGED,\n\tCONFIG_WATCH_READY,\n\tCONFIG_WATCH_REGISTER,\n\tCONFIG_WATCH_REJECTED,\n\tCONFIG_WATCH_RELOADED,\n\tCONFIG_WATCH_UNREGISTER,\n\ttype ConfigWatchRegistration,\n\ttype ConfigWatchTarget,\n\tisConfigWatchRegistration,\n\tisConfigWatchUnregistration,\n\tisConfigWatchValidation,\n\tmatchesConfigWatchFilter,\n} from \"./protocol.ts\";\nimport { ReloadVetoDeferral } from \"./reload-deferral.ts\";\nimport {\n\texcludeRoutineOnlySettingsChanges,\n\tisSettingsPath,\n\tjoinConfigDir,\n\trefreshSettingsContentSnapshots,\n\tupdateSettingsContentSnapshot,\n} from \"./routine-settings.ts\";\nimport {\n\tConfigReloadWatchEngine,\n\tcreateFsWatchEventSource,\n\ttype RealChange,\n\ttype WatchClock,\n\ttype WatchEventSource,\n\ttype WatchTarget,\n} from \"./watch-engine.ts\";\n\nconst BUILTIN_REGISTRATION_ID = \"builtin\";\nconst DEFAULT_DEBOUNCE_MS = 200;\nconst COMPACTION_RECHECK_MS = 250;\nconst VETO_RECHECK_MS = 1000;\nconst CONFIG_FILE_NAMES = [\"settings.jsonc\", \"settings.json\", \"models.json\", \"keybindings.json\"] as const;\n\n/**\n * The engine applies one predicate to both file gating and directory descent, so\n * this must admit scannable directories in order to reach their entry files.\n */\nconst extensionWatchFilter =\n\t(extensionsDir: string) =>\n\t(relPath: string): boolean =>\n\t\tisLoadableExtensionEntry(extensionsDir, relPath) || isScannableExtensionDirectory(extensionsDir, relPath);\n\ntype ConfigReloadWatchSettings = {\n\treadonly settings?: boolean;\n\treadonly models?: boolean;\n\treadonly keybindings?: boolean;\n\treadonly prompts?: boolean;\n\treadonly skills?: boolean;\n\treadonly extensions?: boolean;\n};\n\ntype ConfigReloadSettingsPatch = {\n\treadonly enabled?: boolean;\n\treadonly debounceMs?: number;\n\treadonly watch?: ConfigReloadWatchSettings;\n};\n\n/** Keep config-reload's settings schema owned by the builtin while exposing it on Settings. */\ndeclare module \"../../../settings-manager.ts\" {\n\tinterface Settings {\n\t\tconfigReload?: ConfigReloadSettingsPatch;\n\t}\n}\n\ntype ResolvedConfigReloadSettings = {\n\treadonly enabled: boolean;\n\treadonly debounceMs: number;\n\treadonly watch: Required<ConfigReloadWatchSettings>;\n};\n\ntype WatchTargetInput = Omit<WatchTarget, \"id\">;\n\ntype ActiveTarget = {\n\treadonly registrationId: string;\n\treadonly target: WatchTarget;\n\t/** Presence targets rebuild the watcher set once this missing path appears. */\n\treadonly rearmOnCreation?: string;\n};\n\ntype PendingChange = {\n\treadonly registrationId: string;\n\treadonly paths: Set<string>;\n};\n\ntype ReloadHandoff = {\n\treadonly hashesAtRequest: ReadonlyMap<string, string>;\n\treadonly settingsContentsAtRequest: ReadonlyMap<string, string>;\n\treadonly requestedAt: number;\n\treadonly changes: readonly { readonly registrationId: string; readonly paths: readonly string[] }[];\n};\n\n/** Session-keyed handoffs survive replacement extension factories during reload. */\nexport class ConfigReloadHandoffRegistry<T> {\n\treadonly #handoffs = new Map<string, T>();\n\n\tset(sessionHandle: string, handoff: T): void {\n\t\tthis.#handoffs.set(sessionHandle, handoff);\n\t}\n\n\ttake(sessionHandle: string): T | undefined {\n\t\tconst handoff = this.#handoffs.get(sessionHandle);\n\t\tthis.#handoffs.delete(sessionHandle);\n\t\treturn handoff;\n\t}\n\n\tdelete(sessionHandle: string): void {\n\t\tthis.#handoffs.delete(sessionHandle);\n\t}\n}\n\nconst reloadHandoffs = new ConfigReloadHandoffRegistry<ReloadHandoff>();\n\nfunction bindExternalCallback<TArgs extends unknown[], TResult>(\n\tcallback: (...args: TArgs) => TResult,\n): (...args: TArgs) => TResult {\n\ttry {\n\t\treturn bindToProviderScope(callback);\n\t} catch {\n\t\treturn callback;\n\t}\n}\n\nexport interface ConfigReloadExtensionOptions {\n\treadonly agentDir?: string;\n\treadonly subscribe?: WatchEventSource;\n\treadonly clock?: WatchClock;\n\treadonly logger?: ConfigReloadLogger;\n\t/** Test seam. Production uses the watch engine's SHA-256 implementation. */\n\treadonly hashFile?: (path: string) => string;\n}\n\n/**\n * Watch config resources and request the host's existing full reload flow.\n *\n * The optional options are test seams. Production registration uses the default\n * filesystem event source and agent directory.\n */\nexport function configReloadExtension(pi: ExtensionAPI, options: ConfigReloadExtensionOptions = {}): void {\n\tconst sessionOwned = (() => {\n\t\ttry {\n\t\t\tbindToProviderScope(() => undefined);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t})();\n\tconst handoffKey = (ctx: ExtensionContext): string => (sessionOwned ? ctx.sessionManager.getSessionId() : \"classic\");\n\tconst agentDir = resolve(options.agentDir ?? getAgentDir());\n\tconst subscribe = options.subscribe ?? createFsWatchEventSource();\n\tconst logger = options.logger ?? createConfigReloadLogger(agentDir);\n\tconst registrations = new Map<string, ConfigWatchRegistration>();\n\tconst rejectedRegistrations = new Map<string, string>();\n\t/** Last-seen settings.json contents per path; the diff base for routine-key classification. */\n\tconst settingsContents = new Map<string, string>();\n\tconst eventUnsubscribes: Array<() => void> = [];\n\tconst pending = new Map<string, PendingChange>();\n\tlet engine: ConfigReloadWatchEngine | undefined;\n\tlet activeTargets: ActiveTarget[] = [];\n\tlet currentContext: ExtensionContext | undefined;\n\tlet started = false;\n\tlet reloadInFlight = false;\n\tlet deferredNoticeShown = false;\n\tlet unavailableReloadLogged = false;\n\tlet compactionRecheck: ReturnType<typeof setTimeout> | undefined;\n\tlet vetoRecheck: ReturnType<typeof setTimeout> | undefined;\n\tconst vetoDeferral = new ReloadVetoDeferral();\n\tlet changeChain: Promise<void> = Promise.resolve();\n\n\t// The engine goes inert the moment close() is called; its unsubscribe loop can\n\t// take seconds per watcher, and session_shutdown is awaited by the reload flow.\n\tconst closeWatchers = (): void => {\n\t\tengine?.close().catch((error: unknown) => {\n\t\t\tlogger.error(\"watcher_error\", { path: \"watcher teardown\", message: errorMessage(error) });\n\t\t});\n\t\tengine = undefined;\n\t\tactiveTargets = [];\n\t};\n\n\tconst clearCompactionRecheck = (): void => {\n\t\tif (compactionRecheck === undefined) return;\n\t\t(options.clock ?? defaultClock).clearTimeout(compactionRecheck);\n\t\tcompactionRecheck = undefined;\n\t};\n\n\tconst clearVetoRecheck = (): void => {\n\t\tif (vetoRecheck === undefined) return;\n\t\t(options.clock ?? defaultClock).clearTimeout(vetoRecheck);\n\t\tvetoRecheck = undefined;\n\t};\n\n\tconst cleanupEventListeners = (): void => {\n\t\tfor (const unsubscribe of eventUnsubscribes.splice(0)) {\n\t\t\tunsubscribe();\n\t\t}\n\t};\n\n\tconst rejectRegistration = (registrationId: string, errors: readonly string[]): void => {\n\t\tpi.events.emit(CONFIG_WATCH_REJECTED, {\n\t\t\tregistrationId,\n\t\t\tpaths: [],\n\t\t\terrors: [...errors],\n\t\t});\n\t\tlogger.warn(\"registration_rejected\", { registrationId, errorCount: errors.length });\n\t};\n\n\tconst handleRegistration = (payload: unknown): void => {\n\t\tif (!isConfigWatchRegistration(payload)) return;\n\t\tconst fingerprint = registrationFingerprint(payload);\n\t\t// A component may synchronously re-register from a CONFIG_WATCH_REJECTED\n\t\t// listener (e.g. sticky-rejection recovery). Rejected registrations are\n\t\t// never stored, so the identity guard below cannot break that recursion;\n\t\t// ignoring an identical payload after one rejection does.\n\t\tif (rejectedRegistrations.get(payload.id) === fingerprint) {\n\t\t\tlogger.debug(\"registration_rejection_suppressed\", { registrationId: payload.id });\n\t\t\treturn;\n\t\t}\n\t\tconst cwd = currentContext?.cwd ?? process.cwd();\n\t\tif (registrationHasRestrictedTarget(payload, cwd, agentDir)) {\n\t\t\trejectedRegistrations.set(payload.id, fingerprint);\n\t\t\trejectRegistration(payload.id, [\"Configuration watch target is restricted\"]);\n\t\t\treturn;\n\t\t}\n\t\trejectedRegistrations.delete(payload.id);\n\n\t\t// A component may re-emit its unchanged registration when it receives the\n\t\t// ready event from rebuildWatchers. Rebuilding for that same payload emits\n\t\t// ready again and creates an unbounded synchronous rebuild loop.\n\t\tif (registrations.get(payload.id) === payload) return;\n\t\tregistrations.set(payload.id, payload);\n\t\tpending.delete(payload.id);\n\t\tlogger.info(\"registration_added\", { id: payload.id });\n\t\tif (started && currentContext) {\n\t\t\trebuildWatchers(currentContext);\n\t\t}\n\t};\n\n\tconst handleUnregistration = (payload: unknown): void => {\n\t\tif (!isConfigWatchUnregistration(payload)) return;\n\t\trejectedRegistrations.delete(payload.id);\n\t\tif (!registrations.delete(payload.id)) return;\n\t\tpending.delete(payload.id);\n\t\tlogger.info(\"registration_removed\", { id: payload.id });\n\t\tif (started && currentContext) {\n\t\t\trebuildWatchers(currentContext);\n\t\t}\n\t};\n\n\tconst processChange = async (change: RealChange): Promise<void> => {\n\t\tif (reloadInFlight || !currentContext) return;\n\t\t// Suppression state (self-write consumption, routine-diff base) is per path,\n\t\t// so it must be resolved before grouping: a path watched by several\n\t\t// registrations would otherwise be classified once per group and reach the\n\t\t// reload flow through the later group.\n\t\tconst watchedPaths = excludeSelfWrites(\n\t\t\tchange.changedPaths,\n\t\t\tengine,\n\t\t\tagentDir,\n\t\t\tcurrentContext.cwd,\n\t\t\tlogger,\n\t\t\tsettingsContents,\n\t\t);\n\t\tconst significantPaths = excludeRoutineOnlySettingsChanges(\n\t\t\twatchedPaths,\n\t\t\tsettingsContents,\n\t\t\tagentDir,\n\t\t\tcurrentContext.cwd,\n\t\t\tlogger,\n\t\t);\n\t\tconst configPaths = excludeGeneratedExtensionShims(significantPaths, agentDir);\n\t\tfor (const path of significantPaths) {\n\t\t\tif (!configPaths.includes(path)) logger.debug(\"generated_shim_change_suppressed\", { path });\n\t\t}\n\t\tconst groups = groupChangedPaths(configPaths, activeTargets);\n\t\tconst rearmDirectoryWatch = change.created.some((path) =>\n\t\t\tactiveTargets.some((target) => target.rearmOnCreation === resolve(path)),\n\t\t);\n\t\tfor (const [registrationId, paths] of groups) {\n\t\t\tconst errors = await validateChangedPaths(registrationId, paths, registrations, agentDir, currentContext.cwd);\n\t\t\tif (errors.length > 0) {\n\t\t\t\trejectChange(currentContext, registrationId, paths, errors, logger, pi);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\taddPending(pending, registrationId, paths);\n\t\t\tconst deferred = !canRequestReload(currentContext);\n\t\t\tpi.events.emit(CONFIG_WATCH_CHANGED, {\n\t\t\t\tregistrationId,\n\t\t\t\tpaths: [...paths],\n\t\t\t\tdeferred,\n\t\t\t});\n\t\t\tlogger.info(\"change_detected\", { registrationId, paths, deferred });\n\t\t}\n\t\tif (rearmDirectoryWatch) rebuildWatchers(currentContext);\n\t\tawait flushPending();\n\t};\n\n\tconst enqueueChange = (change: RealChange): void => {\n\t\tif (reloadInFlight) return;\n\t\tchangeChain = changeChain\n\t\t\t.then(() => processChange(change))\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tlogger.error(\"watcher_error\", { path: \"config reload\", message: errorMessage(error) });\n\t\t\t});\n\t};\n\n\tconst rebuildWatchers = (ctx: ExtensionContext): void => {\n\t\tcloseWatchers();\n\t\tclearCompactionRecheck();\n\t\tconst settingsManager = SettingsManager.create(ctx.cwd, agentDir, { projectTrusted: ctx.isProjectTrusted() });\n\t\tconst settings = resolveConfigReloadSettings(settingsManager);\n\t\tif (!settings.enabled || ctx.mode === \"print\" || ctx.mode === \"json\") {\n\t\t\tpi.events.emit(CONFIG_WATCH_READY, { enabled: false });\n\t\t\treturn;\n\t\t}\n\n\t\tactiveTargets = buildWatchTargets({\n\t\t\tcwd: ctx.cwd,\n\t\t\tagentDir,\n\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\tsettings,\n\t\t\tskillPaths: settings.watch.skills ? settingsManager.getSkillPaths() : [],\n\t\t\tregistrations,\n\t\t});\n\t\tengine = new ConfigReloadWatchEngine({\n\t\t\ttargets: activeTargets.map((entry) => entry.target),\n\t\t\tsubscribe,\n\t\t\tdebounceMs: settings.debounceMs,\n\t\t\tclock: options.clock,\n\t\t\thashFile: options.hashFile,\n\t\t\tonRealChange: bindExternalCallback(enqueueChange),\n\t\t\tonError: bindExternalCallback((error, path) => {\n\t\t\t\tlogger.error(\"watcher_error\", { path, message: errorMessage(error) });\n\t\t\t}),\n\t\t});\n\t\trefreshSettingsContentSnapshots(settingsContents, agentDir, ctx.cwd);\n\t\tlogger.info(\"watcher_started\", { targetCount: activeTargets.length });\n\t\tpi.events.emit(CONFIG_WATCH_READY, { enabled: true });\n\t};\n\n\tconst flushPending = async (): Promise<void> => {\n\t\tconst ctx = currentContext;\n\t\tif (!ctx || pending.size === 0 || reloadInFlight) return;\n\t\tif (!ctx.isIdle() || ctx.hasPendingMessages()) return;\n\t\tif (ctx.isCompacting?.() ?? false) {\n\t\t\tarmCompactionRecheck();\n\t\t\treturn;\n\t\t}\n\t\tclearCompactionRecheck();\n\t\tif (!ctx.requestReload) {\n\t\t\tif (!unavailableReloadLogged) {\n\t\t\t\tunavailableReloadLogged = true;\n\t\t\t\tlogger.info(\"reload_requested\", { reason: \"requestReload unavailable\", paths: [] });\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Probe the extension veto (session_before_reload) BEFORE announcing the\n\t\t// reload: a vetoed hot-reload defers quietly (one notice per distinct\n\t\t// reason) and retries on later idle edges or the veto recheck clock,\n\t\t// instead of re-notifying \"Hot-reloading:\" plus the veto warning forever.\n\t\tif (ctx.checkReloadVeto) {\n\t\t\tconst veto = await ctx.checkReloadVeto();\n\t\t\tif (currentContext !== ctx || reloadInFlight || pending.size === 0) return;\n\t\t\tif (veto.cancelled) {\n\t\t\t\tconst notice = vetoDeferral.defer(veto.reason);\n\t\t\t\tif (notice) ctx.ui.notify(notice, \"info\");\n\t\t\t\tlogger.info(\"reload_deferred\", { reason: veto.reason ?? \"extension veto\" });\n\t\t\t\tarmVetoRecheck();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tclearVetoRecheck();\n\t\tvetoDeferral.reset();\n\n\t\tconst changes = pendingChanges(pending);\n\t\tconst paths = uniquePaths(changes.flatMap((change) => change.paths));\n\t\treloadInFlight = true;\n\t\treloadHandoffs.set(handoffKey(ctx), {\n\t\t\thashesAtRequest: engine?.getBaselineSnapshot() ?? new Map<string, string>(),\n\t\t\tsettingsContentsAtRequest: new Map(settingsContents),\n\t\t\trequestedAt: Date.now(),\n\t\t\tchanges,\n\t\t});\n\t\tctx.ui.notify(`Hot-reloading: ${formatPaths(paths)}`, \"info\");\n\t\tlogger.info(\"reload_requested\", { reason: \"config changed\", paths });\n\n\t\tconst handoffKeyForReload = handoffKey(ctx);\n\t\ttry {\n\t\t\tawait ctx.requestReload();\n\t\t\treloadInFlight = false;\n\t\t\treloadHandoffs.delete(handoffKeyForReload);\n\t\t} catch (error) {\n\t\t\treloadInFlight = false;\n\t\t\treloadHandoffs.delete(handoffKeyForReload);\n\t\t\tlogger.error(\"watcher_error\", { path: \"reload\", message: errorMessage(error) });\n\t\t}\n\t};\n\n\tconst armCompactionRecheck = (): void => {\n\t\tif (compactionRecheck !== undefined) return;\n\t\tconst clock = options.clock ?? defaultClock;\n\t\tcompactionRecheck = clock.setTimeout(() => {\n\t\t\tcompactionRecheck = undefined;\n\t\t\tvoid flushPending();\n\t\t}, COMPACTION_RECHECK_MS);\n\t};\n\n\tconst armVetoRecheck = (): void => {\n\t\tif (vetoRecheck !== undefined) return;\n\t\tconst clock = options.clock ?? defaultClock;\n\t\tvetoRecheck = clock.setTimeout(() => {\n\t\t\tvetoRecheck = undefined;\n\t\t\tvoid flushPending();\n\t\t}, VETO_RECHECK_MS);\n\t};\n\n\tconst processReloadHandoff = async (event: SessionStartEvent, ctx: ExtensionContext): Promise<void> => {\n\t\tif (event.reason !== \"reload\") return;\n\t\tconst handoff = reloadHandoffs.take(handoffKey(ctx));\n\t\tif (!handoff) return;\n\t\tconst paths = uniquePaths(handoff.changes.flatMap((change) => change.paths));\n\t\tfor (const change of handoff.changes) {\n\t\t\tpi.events.emit(CONFIG_WATCH_RELOADED, {\n\t\t\t\tregistrationId: change.registrationId,\n\t\t\t\tpaths: [...change.paths],\n\t\t\t});\n\t\t}\n\t\tctx.ui.notify(`Hot-reloaded: ${formatPaths(paths)}`, \"info\");\n\t\tlogger.info(\"reload_completed\", { durationMs: Math.max(0, Date.now() - handoff.requestedAt) });\n\n\t\tconst changedPaths = compareSnapshots(handoff.hashesAtRequest, engine?.getBaselineSnapshot() ?? new Map());\n\t\tif (changedPaths.length > 0) {\n\t\t\tsettingsContents.clear();\n\t\t\tfor (const [path, content] of handoff.settingsContentsAtRequest) settingsContents.set(path, content);\n\t\t\tenqueueChange({ changedPaths, created: [], deleted: [] });\n\t\t\tawait changeChain;\n\t\t}\n\t};\n\n\teventUnsubscribes.push(pi.events.on(CONFIG_WATCH_REGISTER, handleRegistration));\n\teventUnsubscribes.push(pi.events.on(CONFIG_WATCH_UNREGISTER, handleUnregistration));\n\n\tpi.on(\"session_start\", async (event, ctx) => {\n\t\tstarted = true;\n\t\tcurrentContext = ctx;\n\t\trebuildWatchers(ctx);\n\t\tawait processReloadHandoff(event, ctx);\n\t});\n\n\tpi.on(\"agent_end\", async (_event, ctx) => {\n\t\tcurrentContext = ctx;\n\t\tawait flushPending();\n\t});\n\tpi.on(\"agent_settled\", async (_event, ctx) => {\n\t\tcurrentContext = ctx;\n\t\tawait flushPending();\n\t});\n\tpi.on(\"project_trust\", () => {\n\t\tif (currentContext) rebuildWatchers(currentContext);\n\t\treturn { trusted: \"undecided\" };\n\t});\n\tpi.on(\"session_shutdown\", (event) => {\n\t\tconst closingContext = currentContext;\n\t\tstarted = false;\n\t\tcurrentContext = undefined;\n\t\tcloseWatchers();\n\t\tclearCompactionRecheck();\n\t\tclearVetoRecheck();\n\t\tvetoDeferral.reset();\n\t\tcleanupEventListeners();\n\t\tpending.clear();\n\t\tif (event.reason !== \"reload\" && closingContext) reloadHandoffs.delete(handoffKey(closingContext));\n\t});\n\n\tfunction canRequestReload(ctx: ExtensionContext): boolean {\n\t\treturn (\n\t\t\tctx.isIdle() &&\n\t\t\t!ctx.hasPendingMessages() &&\n\t\t\t!(ctx.isCompacting?.() ?? false) &&\n\t\t\tctx.requestReload !== undefined\n\t\t);\n\t}\n\n\tfunction armDeferredNotice(ctx: ExtensionContext): void {\n\t\tif (deferredNoticeShown || pending.size === 0 || !ctx.requestReload) return;\n\t\tdeferredNoticeShown = true;\n\t\tctx.ui.notify(\"Config changed; reloading when idle\", \"info\");\n\t}\n\n\tfunction rejectChange(\n\t\tctx: ExtensionContext,\n\t\tregistrationId: string,\n\t\tpaths: readonly string[],\n\t\terrors: readonly string[],\n\t\tactiveLogger: ConfigReloadLogger,\n\t\tapi: ExtensionAPI,\n\t): void {\n\t\tctx.ui.notify(`Config change rejected: ${errors.join(\"; \")}`, \"error\");\n\t\tapi.events.emit(CONFIG_WATCH_REJECTED, { registrationId, paths: [...paths], errors: [...errors] });\n\t\tactiveLogger.warn(\"validation_rejected\", { registrationId, errorCount: errors.length });\n\t}\n\n\tfunction addPending(changes: Map<string, PendingChange>, registrationId: string, paths: readonly string[]): void {\n\t\tconst pendingChange = changes.get(registrationId) ?? { registrationId, paths: new Set<string>() };\n\t\tfor (const path of paths) pendingChange.paths.add(path);\n\t\tchanges.set(registrationId, pendingChange);\n\t\tif (!canRequestReload(currentContext!)) armDeferredNotice(currentContext!);\n\t}\n}\n\nexport default configReloadExtension;\n\nconst defaultClock: WatchClock = {\n\tsetTimeout: (callback, delayMs) => setTimeout(callback, delayMs),\n\tclearTimeout: (timer) => clearTimeout(timer),\n};\n\nfunction resolveConfigReloadSettings(settingsManager: SettingsManager): ResolvedConfigReloadSettings {\n\tconst global = readConfigReloadPatch(settingsManager.getGlobalSettings());\n\tconst project = readConfigReloadPatch(settingsManager.getProjectSettings());\n\treturn {\n\t\tenabled: project.enabled ?? global.enabled ?? true,\n\t\tdebounceMs: project.debounceMs ?? global.debounceMs ?? DEFAULT_DEBOUNCE_MS,\n\t\twatch: {\n\t\t\tsettings: project.watch?.settings ?? global.watch?.settings ?? true,\n\t\t\tmodels: project.watch?.models ?? global.watch?.models ?? true,\n\t\t\tkeybindings: project.watch?.keybindings ?? global.watch?.keybindings ?? true,\n\t\t\tprompts: project.watch?.prompts ?? global.watch?.prompts ?? true,\n\t\t\tskills: project.watch?.skills ?? global.watch?.skills ?? true,\n\t\t\textensions: project.watch?.extensions ?? global.watch?.extensions ?? true,\n\t\t},\n\t};\n}\n\nfunction readConfigReloadPatch(settings: Settings): ConfigReloadSettingsPatch {\n\tconst candidate: unknown = settings.configReload;\n\tif (!isPlainObject(candidate)) return {};\n\tconst watch = isPlainObject(candidate.watch) ? candidate.watch : undefined;\n\treturn {\n\t\tenabled: typeof candidate.enabled === \"boolean\" ? candidate.enabled : undefined,\n\t\tdebounceMs: validDebounce(candidate.debounceMs),\n\t\twatch: watch\n\t\t\t? {\n\t\t\t\t\tsettings: booleanOrUndefined(watch.settings),\n\t\t\t\t\tmodels: booleanOrUndefined(watch.models),\n\t\t\t\t\tkeybindings: booleanOrUndefined(watch.keybindings),\n\t\t\t\t\tprompts: booleanOrUndefined(watch.prompts),\n\t\t\t\t\tskills: booleanOrUndefined(watch.skills),\n\t\t\t\t\textensions: booleanOrUndefined(watch.extensions),\n\t\t\t\t}\n\t\t\t: undefined,\n\t};\n}\n\nfunction validDebounce(value: unknown): number | undefined {\n\tif (typeof value !== \"number\" || !Number.isFinite(value) || value < 0) return undefined;\n\treturn Math.floor(value);\n}\n\nfunction booleanOrUndefined(value: unknown): boolean | undefined {\n\treturn typeof value === \"boolean\" ? value : undefined;\n}\n\nfunction buildWatchTargets(options: {\n\treadonly cwd: string;\n\treadonly agentDir: string;\n\treadonly projectTrusted: boolean;\n\treadonly settings: ResolvedConfigReloadSettings;\n\treadonly skillPaths: readonly string[];\n\treadonly registrations: ReadonlyMap<string, ConfigWatchRegistration>;\n}): ActiveTarget[] {\n\tconst targets: ActiveTarget[] = [];\n\tconst addBuiltin = (id: string, target: WatchTargetInput, rearmOnCreation?: string): void => {\n\t\ttargets.push({ registrationId: BUILTIN_REGISTRATION_ID, target: { ...target, id }, rearmOnCreation });\n\t};\n\tconst addBuiltinDirectory = (id: string, path: string, filter?: (relPath: string) => boolean): void => {\n\t\tconst resourcePath = resolve(path);\n\t\tif (isExistingDirectory(resourcePath)) {\n\t\t\taddBuiltin(\n\t\t\t\tid,\n\t\t\t\tfilter\n\t\t\t\t\t? { kind: \"dir-recursive\", path: resourcePath, filter }\n\t\t\t\t\t: { kind: \"dir-recursive\", path: resourcePath },\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst watchPath = nearestExistingDirectory(dirname(resourcePath));\n\t\tconst firstMissingSegment = relative(watchPath, resourcePath).split(sep)[0] || basename(resourcePath);\n\t\tconst createdPath = resolve(watchPath, firstMissingSegment);\n\t\taddBuiltin(\n\t\t\t`${id}-presence`,\n\t\t\t{\n\t\t\t\tkind: \"dir\",\n\t\t\t\tpath: watchPath,\n\t\t\t\tallowList: [firstMissingSegment],\n\t\t\t},\n\t\t\tcreatedPath,\n\t\t);\n\t};\n\tconst { cwd, agentDir, projectTrusted, settings } = options;\n\tconst projectDir = joinConfigDir(cwd);\n\n\tconst jsonAllowList = CONFIG_FILE_NAMES.filter((name) => {\n\t\tif (name === \"settings.json\" || name === \"settings.jsonc\") return settings.watch.settings;\n\t\tif (name === \"models.json\") return settings.watch.models;\n\t\treturn settings.watch.keybindings;\n\t});\n\tif (jsonAllowList.length > 0) {\n\t\taddBuiltin(\"builtin-global-json\", { kind: \"dir\", path: agentDir, allowList: jsonAllowList });\n\t}\n\tif (settings.watch.prompts) {\n\t\taddBuiltinDirectory(\"builtin-global-prompts\", resolve(agentDir, \"prompts\"));\n\t}\n\tif (settings.watch.extensions) {\n\t\tconst globalExtensionsDir = resolve(agentDir, \"extensions\");\n\t\taddBuiltinDirectory(\"builtin-global-extensions\", globalExtensionsDir, extensionWatchFilter(globalExtensionsDir));\n\t}\n\tif (settings.watch.skills) {\n\t\tfor (const [index, skillPath] of options.skillPaths.entries()) {\n\t\t\tconst target = targetForSkillPath(resolvePath(skillPath, cwd, { trim: true }));\n\t\t\tif (target.kind === \"dir-recursive\") {\n\t\t\t\taddBuiltinDirectory(`builtin-skill-${index}`, target.path);\n\t\t\t} else {\n\t\t\t\taddBuiltin(`builtin-skill-${index}`, target);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (projectTrusted) {\n\t\tconst projectDirExists = isExistingDirectory(projectDir);\n\t\tconst projectWatchEnabled = Object.values(settings.watch).some(Boolean);\n\t\tif (projectWatchEnabled) {\n\t\t\taddBuiltin(\n\t\t\t\t\"builtin-project-presence\",\n\t\t\t\t{ kind: \"dir\", path: cwd, allowList: [CONFIG_DIR_NAME] },\n\t\t\t\tprojectDirExists ? undefined : projectDir,\n\t\t\t);\n\t\t}\n\t\tif (projectDirExists) {\n\t\t\tif (settings.watch.settings) {\n\t\t\t\taddBuiltin(\"builtin-project-settings\", {\n\t\t\t\t\tkind: \"dir\",\n\t\t\t\t\tpath: projectDir,\n\t\t\t\t\tallowList: [\"settings.jsonc\", \"settings.json\"],\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (settings.watch.prompts) {\n\t\t\t\taddBuiltinDirectory(\"builtin-project-prompts\", resolve(projectDir, \"prompts\"));\n\t\t\t}\n\t\t\tif (settings.watch.skills) {\n\t\t\t\taddBuiltinDirectory(\"builtin-project-skills\", resolve(projectDir, \"skills\"));\n\t\t\t}\n\t\t\tif (settings.watch.extensions) {\n\t\t\t\tconst projectExtensionsDir = resolve(projectDir, \"extensions\");\n\t\t\t\taddBuiltinDirectory(\n\t\t\t\t\t\"builtin-project-extensions\",\n\t\t\t\t\tprojectExtensionsDir,\n\t\t\t\t\textensionWatchFilter(projectExtensionsDir),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (const registration of options.registrations.values()) {\n\t\tfor (const [index, target] of registration.targets.entries()) {\n\t\t\tconst path = resolvePath(target.path, cwd, { trim: true });\n\t\t\tconst watchTarget = externalTargetToWatchTarget(path, target.kind, target.filterGlobs);\n\t\t\ttargets.push({\n\t\t\t\tregistrationId: registration.id,\n\t\t\t\ttarget: { ...watchTarget, id: `external-${registration.id}-${index}` },\n\t\t\t});\n\t\t}\n\t}\n\treturn targets;\n}\n\nfunction isExistingDirectory(path: string): boolean {\n\ttry {\n\t\treturn lstatSync(path).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction nearestExistingDirectory(path: string): string {\n\tlet candidate = resolve(path);\n\twhile (!isExistingDirectory(candidate)) {\n\t\tconst parent = dirname(candidate);\n\t\tif (parent === candidate) return candidate;\n\t\tcandidate = parent;\n\t}\n\treturn candidate;\n}\n\nfunction targetForSkillPath(path: string): WatchTargetInput {\n\ttry {\n\t\tif (lstatSync(path).isFile()) {\n\t\t\treturn { kind: \"dir\", path: dirname(path), allowList: [basename(path)] };\n\t\t}\n\t} catch {\n\t\t// A missing configured skill path is treated as a directory so it becomes watchable when present.\n\t}\n\treturn { kind: \"dir-recursive\", path };\n}\n\nfunction externalTargetToWatchTarget(\n\tpath: string,\n\tkind: \"file\" | \"dir\",\n\tfilterGlobs: readonly string[] | undefined,\n): WatchTargetInput {\n\tif (kind === \"file\") {\n\t\tconst name = basename(path);\n\t\treturn {\n\t\t\tkind: \"dir\",\n\t\t\tpath: dirname(path),\n\t\t\tallowList: [name],\n\t\t\tfilter: (relativePath) => relativePath === name && matchesConfigWatchFilter(relativePath, filterGlobs),\n\t\t};\n\t}\n\treturn {\n\t\tkind: \"dir-recursive\",\n\t\tpath,\n\t\t// Literal filters also declare explicitly watched dot-directories. Without\n\t\t// this, an external ancestor target filtered to \".omo\" drops its creation\n\t\t// event before the validator can inspect the new config beneath it.\n\t\tallowList: literalFilterNames(filterGlobs),\n\t\tfilter: (relativePath) => matchesConfigWatchFilter(relativePath, filterGlobs),\n\t};\n}\n\nfunction literalFilterNames(filterGlobs: readonly string[] | undefined): string[] | undefined {\n\tif (!filterGlobs) return undefined;\n\t// A root-anchored glob names a literal path relative to the watch root, so\n\t// strip the anchor before the separator check rejects it.\n\tconst literalNames = filterGlobs\n\t\t.map((filterGlob) => (filterGlob.startsWith(\"/\") ? filterGlob.slice(1) : filterGlob))\n\t\t.filter((filterGlob) => !filterGlob.includes(\"*\") && !filterGlob.includes(\"/\") && !filterGlob.includes(\"\\\\\\\\\"));\n\treturn literalNames.length > 0 ? literalNames : undefined;\n}\n\nfunction groupChangedPaths(paths: readonly string[], targets: readonly ActiveTarget[]): Map<string, string[]> {\n\tconst groups = new Map<string, string[]>();\n\tfor (const path of paths) {\n\t\tlet matched = false;\n\t\tfor (const activeTarget of targets) {\n\t\t\tif (!targetMatchesPath(activeTarget.target, path)) continue;\n\t\t\tconst group = groups.get(activeTarget.registrationId) ?? [];\n\t\t\tif (!group.includes(path)) group.push(path);\n\t\t\tgroups.set(activeTarget.registrationId, group);\n\t\t\tmatched = true;\n\t\t}\n\t\tif (!matched) {\n\t\t\tconst group = groups.get(BUILTIN_REGISTRATION_ID) ?? [];\n\t\t\tgroup.push(path);\n\t\t\tgroups.set(BUILTIN_REGISTRATION_ID, group);\n\t\t}\n\t}\n\treturn groups;\n}\n\nfunction targetMatchesPath(target: WatchTarget, path: string): boolean {\n\tconst relativePath = relative(resolve(target.path), resolve(path));\n\tif (relativePath === \"..\" || relativePath.startsWith(`..${sep}`)) return false;\n\tif (target.kind === \"dir\" && relativePath.includes(sep)) return false;\n\tif (\n\t\ttarget.allowList &&\n\t\t!target.allowList.some((allowed) => relativePath === allowed || relativePath.startsWith(`${allowed}${sep}`))\n\t) {\n\t\treturn false;\n\t}\n\treturn target.filter?.(relativePath) ?? true;\n}\n\nfunction excludeSelfWrites(\n\tpaths: readonly string[],\n\tengine: ConfigReloadWatchEngine | undefined,\n\tagentDir: string,\n\tcwd: string,\n\tlogger: ConfigReloadLogger,\n\tsettingsContents: Map<string, string>,\n): string[] {\n\tconst snapshot = engine?.getBaselineSnapshot();\n\treturn paths.filter((path) => {\n\t\tif (!isSettingsPath(path, agentDir, cwd)) return true;\n\t\tconst hash = snapshot?.get(path);\n\t\tif (hash === undefined || !wasSelfWrite(path, hash)) return true;\n\t\tlogger.debug(\"self_write_suppressed\", { path });\n\t\t// Advance the routine-diff base so a later external change is not\n\t\t// polluted by this session's own just-applied write.\n\t\tupdateSettingsContentSnapshot(settingsContents, path);\n\t\treturn false;\n\t});\n}\n\nasync function validateChangedPaths(\n\tregistrationId: string,\n\tpaths: readonly string[],\n\tregistrations: ReadonlyMap<string, ConfigWatchRegistration>,\n\tagentDir: string,\n\tcwd: string,\n): Promise<string[]> {\n\tif (registrationId === BUILTIN_REGISTRATION_ID) {\n\t\treturn validateBuiltinPaths(paths, agentDir, cwd);\n\t}\n\tconst registration = registrations.get(registrationId);\n\tif (!registration?.validate) return [];\n\ttry {\n\t\tconst result = await registration.validate(paths);\n\t\tif (!isConfigWatchValidation(result)) return [\"Configuration validator returned an invalid result\"];\n\t\treturn result.ok ? [] : result.errors;\n\t} catch (error) {\n\t\treturn [errorMessage(error)];\n\t}\n}\n\nfunction validateBuiltinPaths(paths: readonly string[], agentDir: string, cwd: string): string[] {\n\tconst errors: string[] = [];\n\tfor (const path of paths) {\n\t\tif (isSettingsPath(path, agentDir, cwd)) {\n\t\t\tconst error = validateSettingsFile(path);\n\t\t\tif (error) errors.push(error);\n\t\t\tcontinue;\n\t\t}\n\t\tif (resolve(path) === resolve(agentDir, \"models.json\")) {\n\t\t\tconst error = ModelConfig.loadSync(path).getError();\n\t\t\tif (error) errors.push(error);\n\t\t\tcontinue;\n\t\t}\n\t\tif (resolve(path) === resolve(agentDir, \"keybindings.json\")) {\n\t\t\tconst error = validateKeybindingsFile(path);\n\t\t\tif (error) errors.push(error);\n\t\t}\n\t}\n\treturn errors;\n}\n\nfunction validateSettingsFile(path: string): string | undefined {\n\tif (!existsSync(path)) return undefined;\n\ttry {\n\t\tconst parsed = parseSettingsJson(readFileSync(path, \"utf-8\"));\n\t\t// Keep validation aligned with SettingsManager's loader and migrations without duplicating migration rules.\n\t\tSettingsManager.inMemory(parsed as Partial<Settings>);\n\t\treturn undefined;\n\t} catch (error) {\n\t\treturn `Invalid ${basename(path)}: ${errorMessage(error)}`;\n\t}\n}\n\nfunction validateKeybindingsFile(path: string): string | undefined {\n\tif (!existsSync(path)) return undefined;\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(readFileSync(path, \"utf-8\"));\n\t\tif (!isPlainObject(parsed)) return \"keybindings.json must contain an object\";\n\t\tfor (const value of Object.values(parsed)) {\n\t\t\tif (typeof value === \"string\") continue;\n\t\t\tif (Array.isArray(value) && value.every((entry) => typeof entry === \"string\")) continue;\n\t\t\treturn \"keybindings.json bindings must be strings or string arrays\";\n\t\t}\n\t\treturn undefined;\n\t} catch (error) {\n\t\treturn `Invalid keybindings.json: ${errorMessage(error)}`;\n\t}\n}\n\nfunction registrationFingerprint(registration: ConfigWatchRegistration): string {\n\treturn JSON.stringify({\n\t\tid: registration.id,\n\t\tdisplayName: registration.displayName,\n\t\ttargets: registration.targets.map((target) => ({\n\t\t\tpath: target.path,\n\t\t\tkind: target.kind,\n\t\t\tfilterGlobs: target.filterGlobs ?? null,\n\t\t})),\n\t\thasValidate: registration.validate !== undefined,\n\t});\n}\n\nfunction isProtectedAgentPath(candidate: string, agentDir: string): boolean {\n\tconst authPath = resolve(agentDir, \"auth.json\");\n\tconst sessionsPath = resolve(agentDir, \"sessions\");\n\tconst logsPath = resolve(agentDir, \"logs\");\n\treturn isWithin(candidate, authPath) || isWithin(candidate, sessionsPath) || isWithin(candidate, logsPath);\n}\n\n// A watch rooted exactly at the agent directory is safe when every filter is\n// root-anchored (a leading `/` matches only an immediate child of the watch root,\n// never a nested path) and none of those anchored names resolves into a protected\n// path. Unfiltered targets, unanchored filters, and any protected filter stay\n// fail-closed.\nfunction isSafeFilteredAgentDirTarget(target: ConfigWatchTarget, resolvedPath: string, agentDir: string): boolean {\n\tif (target.kind !== \"dir\" || resolvedPath !== resolve(agentDir)) return false;\n\tconst filterGlobs = target.filterGlobs;\n\tif (!filterGlobs || filterGlobs.length === 0) return false;\n\treturn filterGlobs.every((glob) => {\n\t\tif (!glob.startsWith(\"/\")) return false;\n\t\treturn !isProtectedAgentPath(resolve(resolvedPath, glob.slice(1)), agentDir);\n\t});\n}\n\nfunction registrationHasRestrictedTarget(\n\tregistration: ConfigWatchRegistration,\n\tcwd: string,\n\tagentDir: string,\n): boolean {\n\tconst authPath = resolve(agentDir, \"auth.json\");\n\tconst sessionsPath = resolve(agentDir, \"sessions\");\n\tconst logsPath = resolve(agentDir, \"logs\");\n\treturn registration.targets.some((target) => {\n\t\tconst path = resolvePath(target.path, cwd, { trim: true });\n\t\tif (isSafeFilteredAgentDirTarget(target, path, agentDir)) return false;\n\t\treturn (\n\t\t\tisWithin(path, authPath) ||\n\t\t\tisWithin(authPath, path) ||\n\t\t\tisWithin(path, sessionsPath) ||\n\t\t\tisWithin(path, logsPath)\n\t\t);\n\t});\n}\n\nfunction pendingChanges(pending: ReadonlyMap<string, PendingChange>): Array<{\n\treadonly registrationId: string;\n\treadonly paths: readonly string[];\n}> {\n\treturn [...pending.values()].map((change) => ({\n\t\tregistrationId: change.registrationId,\n\t\tpaths: [...change.paths].sort(),\n\t}));\n}\n\nfunction compareSnapshots(previous: ReadonlyMap<string, string>, next: ReadonlyMap<string, string>): string[] {\n\tconst changed = new Set<string>();\n\tfor (const [path, hash] of next) {\n\t\tif (previous.get(path) !== hash) changed.add(path);\n\t}\n\tfor (const path of previous.keys()) {\n\t\tif (!next.has(path)) changed.add(path);\n\t}\n\treturn [...changed].sort();\n}\n\nfunction uniquePaths(paths: readonly string[]): string[] {\n\treturn [...new Set(paths)].sort();\n}\n\nfunction isWithin(path: string, root: string): boolean {\n\treturn path === root || path.startsWith(`${root}${sep}`);\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction formatPaths(paths: readonly string[]): string {\n\treturn paths.length === 0 ? \"configuration\" : paths.join(\", \");\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/config-reload/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AA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AAC,KAAK,CAAC,CAAC;IAC/C,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAC;AAC7D,CAAC;AAED,SAAS,YAAY,CAAC,KAAc;IACnC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED,SAAS,WAAW,CAAC,KAAwB;IAC5C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChE,CAAC","sourcesContent":["import { existsSync, lstatSync, readFileSync } from \"node:fs\";\nimport { basename, dirname, relative, resolve, sep } from \"node:path\";\nimport { bindToProviderScope } from \"@earendil-works/pi-ai/node/provider-scope\";\nimport { CONFIG_DIR_NAME, getAgentDir } from \"../../../../config.ts\";\nimport { resolvePath } from \"../../../../utils/paths.ts\";\nimport { ModelConfig } from \"../../../model-config.ts\";\nimport { parseSettingsJson, type Settings, SettingsManager, wasSelfWrite } from \"../../../settings-manager.ts\";\nimport type { ExtensionAPI, ExtensionContext, SessionStartEvent } from \"../../types.ts\";\nimport { isLoadableExtensionEntry, isScannableExtensionDirectory } from \"./extension-watch-scope.ts\";\nimport { excludeGeneratedExtensionShims } from \"./generated-shim-filter.ts\";\nimport { type ConfigReloadLogger, createConfigReloadLogger } from \"./log.ts\";\nimport {\n\tCONFIG_WATCH_CHANGED,\n\tCONFIG_WATCH_READY,\n\tCONFIG_WATCH_REGISTER,\n\tCONFIG_WATCH_REJECTED,\n\tCONFIG_WATCH_RELOADED,\n\tCONFIG_WATCH_UNREGISTER,\n\ttype ConfigWatchRegistration,\n\ttype ConfigWatchTarget,\n\tisConfigWatchRegistration,\n\tisConfigWatchUnregistration,\n\tisConfigWatchValidation,\n\tmatchesConfigWatchFilter,\n} from \"./protocol.ts\";\nimport { ReloadVetoDeferral } from \"./reload-deferral.ts\";\nimport {\n\texcludeRoutineOnlySettingsChanges,\n\tisSettingsPath,\n\tjoinConfigDir,\n\trefreshSettingsContentSnapshots,\n\tupdateSettingsContentSnapshot,\n} from \"./routine-settings.ts\";\nimport {\n\tConfigReloadWatchEngine,\n\tcreateFsWatchEventSource,\n\ttype RealChange,\n\ttype WatchClock,\n\ttype WatchEventSource,\n\ttype WatchTarget,\n} from \"./watch-engine.ts\";\n\nconst BUILTIN_REGISTRATION_ID = \"builtin\";\nconst DEFAULT_DEBOUNCE_MS = 200;\nconst COMPACTION_RECHECK_MS = 250;\nconst VETO_RECHECK_MS = 1000;\nconst CONFIG_FILE_NAMES = [\"settings.jsonc\", \"settings.json\", \"models.json\", \"keybindings.json\"] as const;\n\n/**\n * The engine applies one predicate to both file gating and directory descent, so\n * this must admit scannable directories in order to reach their entry files.\n */\nconst extensionWatchFilter =\n\t(extensionsDir: string) =>\n\t(relPath: string): boolean =>\n\t\tisLoadableExtensionEntry(extensionsDir, relPath) || isScannableExtensionDirectory(extensionsDir, relPath);\n\ntype ConfigReloadWatchSettings = {\n\treadonly settings?: boolean;\n\treadonly models?: boolean;\n\treadonly keybindings?: boolean;\n\treadonly prompts?: boolean;\n\treadonly skills?: boolean;\n\treadonly extensions?: boolean;\n};\n\ntype ConfigReloadSettingsPatch = {\n\treadonly enabled?: boolean;\n\treadonly debounceMs?: number;\n\treadonly watch?: ConfigReloadWatchSettings;\n};\n\n/** Keep config-reload's settings schema owned by the builtin while exposing it on Settings. */\ndeclare module \"../../../settings-manager.ts\" {\n\tinterface Settings {\n\t\tconfigReload?: ConfigReloadSettingsPatch;\n\t}\n}\n\ntype ResolvedConfigReloadSettings = {\n\treadonly enabled: boolean;\n\treadonly debounceMs: number;\n\treadonly watch: Required<ConfigReloadWatchSettings>;\n};\n\ntype WatchTargetInput = Omit<WatchTarget, \"id\">;\n\ntype ActiveTarget = {\n\treadonly registrationId: string;\n\treadonly target: WatchTarget;\n\t/** Presence targets rebuild the watcher set once this missing path appears. */\n\treadonly rearmOnCreation?: string;\n};\n\ntype PendingChange = {\n\treadonly registrationId: string;\n\treadonly paths: Set<string>;\n};\n\ntype ReloadHandoff = {\n\treadonly hashesAtRequest: ReadonlyMap<string, string>;\n\treadonly settingsContentsAtRequest: ReadonlyMap<string, string>;\n\treadonly requestedAt: number;\n\treadonly changes: readonly { readonly registrationId: string; readonly paths: readonly string[] }[];\n};\n\n/** Session-keyed handoffs survive replacement extension factories during reload. */\nexport class ConfigReloadHandoffRegistry<T> {\n\treadonly #handoffs = new Map<string, T>();\n\n\tset(sessionHandle: string, handoff: T): void {\n\t\tthis.#handoffs.set(sessionHandle, handoff);\n\t}\n\n\ttake(sessionHandle: string): T | undefined {\n\t\tconst handoff = this.#handoffs.get(sessionHandle);\n\t\tthis.#handoffs.delete(sessionHandle);\n\t\treturn handoff;\n\t}\n\n\tdelete(sessionHandle: string): void {\n\t\tthis.#handoffs.delete(sessionHandle);\n\t}\n}\n\nconst reloadHandoffs = new ConfigReloadHandoffRegistry<ReloadHandoff>();\n\nfunction bindExternalCallback<TArgs extends unknown[], TResult>(\n\tcallback: (...args: TArgs) => TResult,\n): (...args: TArgs) => TResult {\n\ttry {\n\t\treturn bindToProviderScope(callback);\n\t} catch {\n\t\treturn callback;\n\t}\n}\n\nexport interface ConfigReloadExtensionOptions {\n\treadonly agentDir?: string;\n\treadonly subscribe?: WatchEventSource;\n\treadonly clock?: WatchClock;\n\treadonly logger?: ConfigReloadLogger;\n\t/** Test seam. Production uses the watch engine's SHA-256 implementation. */\n\treadonly hashFile?: (path: string) => string;\n}\n\n/**\n * Watch config resources and request the host's existing full reload flow.\n *\n * The optional options are test seams. Production registration uses the default\n * filesystem event source and agent directory.\n */\nexport function configReloadExtension(pi: ExtensionAPI, options: ConfigReloadExtensionOptions = {}): void {\n\tconst sessionOwned = (() => {\n\t\ttry {\n\t\t\tbindToProviderScope(() => undefined);\n\t\t\treturn true;\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t})();\n\tconst handoffKey = (ctx: ExtensionContext): string => (sessionOwned ? ctx.sessionManager.getSessionId() : \"classic\");\n\tconst agentDir = resolve(options.agentDir ?? getAgentDir());\n\tconst subscribe = options.subscribe ?? createFsWatchEventSource();\n\tconst logger = options.logger ?? createConfigReloadLogger(agentDir);\n\tconst registrations = new Map<string, ConfigWatchRegistration>();\n\tconst rejectedRegistrations = new Map<string, string>();\n\t/** Last-seen settings.json contents per path; the diff base for routine-key classification. */\n\tconst settingsContents = new Map<string, string>();\n\tconst eventUnsubscribes: Array<() => void> = [];\n\tconst pending = new Map<string, PendingChange>();\n\tlet engine: ConfigReloadWatchEngine | undefined;\n\tlet activeTargets: ActiveTarget[] = [];\n\tlet currentContext: ExtensionContext | undefined;\n\tlet started = false;\n\tlet reloadInFlight = false;\n\tlet deferredNoticeShown = false;\n\tlet unavailableReloadLogged = false;\n\tlet compactionRecheck: ReturnType<typeof setTimeout> | undefined;\n\tlet vetoRecheck: ReturnType<typeof setTimeout> | undefined;\n\tconst vetoDeferral = new ReloadVetoDeferral();\n\tlet changeChain: Promise<void> = Promise.resolve();\n\n\t// The engine goes inert the moment close() is called; its unsubscribe loop can\n\t// take seconds per watcher, and session_shutdown is awaited by the reload flow.\n\tconst closeWatchers = (): void => {\n\t\tengine?.close().catch((error: unknown) => {\n\t\t\tlogger.error(\"watcher_error\", { path: \"watcher teardown\", message: errorMessage(error) });\n\t\t});\n\t\tengine = undefined;\n\t\tactiveTargets = [];\n\t};\n\n\tconst clearCompactionRecheck = (): void => {\n\t\tif (compactionRecheck === undefined) return;\n\t\t(options.clock ?? defaultClock).clearTimeout(compactionRecheck);\n\t\tcompactionRecheck = undefined;\n\t};\n\n\tconst clearVetoRecheck = (): void => {\n\t\tif (vetoRecheck === undefined) return;\n\t\t(options.clock ?? defaultClock).clearTimeout(vetoRecheck);\n\t\tvetoRecheck = undefined;\n\t};\n\n\tconst cleanupEventListeners = (): void => {\n\t\tfor (const unsubscribe of eventUnsubscribes.splice(0)) {\n\t\t\tunsubscribe();\n\t\t}\n\t};\n\n\tconst rejectRegistration = (registrationId: string, errors: readonly string[]): void => {\n\t\tpi.events.emit(CONFIG_WATCH_REJECTED, {\n\t\t\tregistrationId,\n\t\t\tpaths: [],\n\t\t\terrors: [...errors],\n\t\t});\n\t\tlogger.warn(\"registration_rejected\", { registrationId, errorCount: errors.length });\n\t};\n\n\tconst handleRegistration = (payload: unknown): void => {\n\t\tif (!isConfigWatchRegistration(payload)) return;\n\t\tconst fingerprint = registrationFingerprint(payload);\n\t\t// A component may synchronously re-register from a CONFIG_WATCH_REJECTED\n\t\t// listener (e.g. sticky-rejection recovery). Rejected registrations are\n\t\t// never stored, so the identity guard below cannot break that recursion;\n\t\t// ignoring an identical payload after one rejection does.\n\t\tif (rejectedRegistrations.get(payload.id) === fingerprint) {\n\t\t\tlogger.debug(\"registration_rejection_suppressed\", { registrationId: payload.id });\n\t\t\treturn;\n\t\t}\n\t\tconst cwd = currentContext?.cwd ?? process.cwd();\n\t\tif (registrationHasRestrictedTarget(payload, cwd, agentDir)) {\n\t\t\trejectedRegistrations.set(payload.id, fingerprint);\n\t\t\trejectRegistration(payload.id, [\"Configuration watch target is restricted\"]);\n\t\t\treturn;\n\t\t}\n\t\trejectedRegistrations.delete(payload.id);\n\n\t\t// A component may re-emit its unchanged registration when it receives the\n\t\t// ready event from rebuildWatchers. Rebuilding for that same payload emits\n\t\t// ready again and creates an unbounded synchronous rebuild loop.\n\t\tif (registrations.get(payload.id) === payload) return;\n\t\tregistrations.set(payload.id, payload);\n\t\tpending.delete(payload.id);\n\t\tlogger.info(\"registration_added\", { id: payload.id });\n\t\tif (started && currentContext) {\n\t\t\trebuildWatchers(currentContext);\n\t\t}\n\t};\n\n\tconst handleUnregistration = (payload: unknown): void => {\n\t\tif (!isConfigWatchUnregistration(payload)) return;\n\t\trejectedRegistrations.delete(payload.id);\n\t\tif (!registrations.delete(payload.id)) return;\n\t\tpending.delete(payload.id);\n\t\tlogger.info(\"registration_removed\", { id: payload.id });\n\t\tif (started && currentContext) {\n\t\t\trebuildWatchers(currentContext);\n\t\t}\n\t};\n\n\tconst processChange = async (change: RealChange): Promise<void> => {\n\t\tif (reloadInFlight || !currentContext) return;\n\t\t// Suppression state (self-write consumption, routine-diff base) is per path,\n\t\t// so it must be resolved before grouping: a path watched by several\n\t\t// registrations would otherwise be classified once per group and reach the\n\t\t// reload flow through the later group.\n\t\tconst watchedPaths = excludeSelfWrites(\n\t\t\tchange.changedPaths,\n\t\t\tengine,\n\t\t\tagentDir,\n\t\t\tcurrentContext.cwd,\n\t\t\tlogger,\n\t\t\tsettingsContents,\n\t\t);\n\t\tconst significantPaths = excludeRoutineOnlySettingsChanges(\n\t\t\twatchedPaths,\n\t\t\tsettingsContents,\n\t\t\tagentDir,\n\t\t\tcurrentContext.cwd,\n\t\t\tlogger,\n\t\t);\n\t\tconst configPaths = excludeGeneratedExtensionShims(significantPaths, agentDir);\n\t\tfor (const path of significantPaths) {\n\t\t\tif (!configPaths.includes(path)) logger.debug(\"generated_shim_change_suppressed\", { path });\n\t\t}\n\t\tconst groups = groupChangedPaths(configPaths, activeTargets);\n\t\tconst rearmDirectoryWatch = change.created.some((path) =>\n\t\t\tactiveTargets.some((target) => target.rearmOnCreation === resolve(path)),\n\t\t);\n\t\tfor (const [registrationId, paths] of groups) {\n\t\t\tconst errors = await validateChangedPaths(registrationId, paths, registrations, agentDir, currentContext.cwd);\n\t\t\tif (errors.length > 0) {\n\t\t\t\trejectChange(currentContext, registrationId, paths, errors, logger, pi);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\taddPending(pending, registrationId, paths);\n\t\t\tconst deferred = !canRequestReload(currentContext);\n\t\t\tpi.events.emit(CONFIG_WATCH_CHANGED, {\n\t\t\t\tregistrationId,\n\t\t\t\tpaths: [...paths],\n\t\t\t\tdeferred,\n\t\t\t});\n\t\t\tlogger.info(\"change_detected\", { registrationId, paths, deferred });\n\t\t}\n\t\tif (rearmDirectoryWatch) rebuildWatchers(currentContext);\n\t\tawait flushPending();\n\t};\n\n\tconst enqueueChange = (change: RealChange): void => {\n\t\tif (reloadInFlight) return;\n\t\tchangeChain = changeChain\n\t\t\t.then(() => processChange(change))\n\t\t\t.catch((error: unknown) => {\n\t\t\t\tlogger.error(\"watcher_error\", { path: \"config reload\", message: errorMessage(error) });\n\t\t\t});\n\t};\n\n\tconst rebuildWatchers = (ctx: ExtensionContext): void => {\n\t\tcloseWatchers();\n\t\tclearCompactionRecheck();\n\t\tconst settingsManager = SettingsManager.create(ctx.cwd, agentDir, { projectTrusted: ctx.isProjectTrusted() });\n\t\tconst settings = resolveConfigReloadSettings(settingsManager);\n\t\tif (!settings.enabled || ctx.mode === \"print\" || ctx.mode === \"json\") {\n\t\t\tpi.events.emit(CONFIG_WATCH_READY, { enabled: false });\n\t\t\treturn;\n\t\t}\n\n\t\tactiveTargets = buildWatchTargets({\n\t\t\tcwd: ctx.cwd,\n\t\t\tagentDir,\n\t\t\tprojectTrusted: ctx.isProjectTrusted(),\n\t\t\tsettings,\n\t\t\tskillPaths: settings.watch.skills ? settingsManager.getSkillPaths() : [],\n\t\t\tregistrations,\n\t\t});\n\t\tengine = new ConfigReloadWatchEngine({\n\t\t\ttargets: activeTargets.map((entry) => entry.target),\n\t\t\tsubscribe,\n\t\t\tdebounceMs: settings.debounceMs,\n\t\t\tclock: options.clock,\n\t\t\thashFile: options.hashFile,\n\t\t\tonRealChange: bindExternalCallback(enqueueChange),\n\t\t\tonError: bindExternalCallback((error, path) => {\n\t\t\t\tlogger.error(\"watcher_error\", { path, message: errorMessage(error) });\n\t\t\t}),\n\t\t});\n\t\trefreshSettingsContentSnapshots(settingsContents, agentDir, ctx.cwd);\n\t\tlogger.info(\"watcher_started\", { targetCount: activeTargets.length });\n\t\tpi.events.emit(CONFIG_WATCH_READY, { enabled: true });\n\t};\n\n\tconst flushPending = async (): Promise<void> => {\n\t\tconst ctx = currentContext;\n\t\tif (!ctx || pending.size === 0 || reloadInFlight) return;\n\t\tif (!ctx.isIdle() || ctx.hasPendingMessages()) return;\n\t\tif (ctx.isCompacting?.() ?? false) {\n\t\t\tarmCompactionRecheck();\n\t\t\treturn;\n\t\t}\n\t\tclearCompactionRecheck();\n\t\tif (!ctx.requestReload) {\n\t\t\tif (!unavailableReloadLogged) {\n\t\t\t\tunavailableReloadLogged = true;\n\t\t\t\tlogger.info(\"reload_requested\", { reason: \"requestReload unavailable\", paths: [] });\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Probe the extension veto (session_before_reload) BEFORE announcing the\n\t\t// reload: a vetoed hot-reload defers quietly (one notice per distinct\n\t\t// reason) and retries on later idle edges or the veto recheck clock,\n\t\t// instead of re-notifying \"Hot-reloading:\" plus the veto warning forever.\n\t\tif (ctx.checkReloadVeto) {\n\t\t\tconst veto = await ctx.checkReloadVeto();\n\t\t\tif (currentContext !== ctx || reloadInFlight || pending.size === 0) return;\n\t\t\tif (veto.cancelled) {\n\t\t\t\tconst notice = vetoDeferral.defer(veto.reason);\n\t\t\t\tif (notice) ctx.ui.notify(notice, \"info\");\n\t\t\t\tlogger.info(\"reload_deferred\", { reason: veto.reason ?? \"extension veto\" });\n\t\t\t\tarmVetoRecheck();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t\tclearVetoRecheck();\n\t\tvetoDeferral.reset();\n\n\t\tconst changes = pendingChanges(pending);\n\t\tconst paths = uniquePaths(changes.flatMap((change) => change.paths));\n\t\treloadInFlight = true;\n\t\treloadHandoffs.set(handoffKey(ctx), {\n\t\t\thashesAtRequest: engine?.getBaselineSnapshot() ?? new Map<string, string>(),\n\t\t\tsettingsContentsAtRequest: new Map(settingsContents),\n\t\t\trequestedAt: Date.now(),\n\t\t\tchanges,\n\t\t});\n\t\tctx.ui.notify(`Hot-reloading: ${formatPaths(paths)}`, \"info\");\n\t\tlogger.info(\"reload_requested\", { reason: \"config changed\", paths });\n\n\t\tconst handoffKeyForReload = handoffKey(ctx);\n\t\ttry {\n\t\t\tawait ctx.requestReload();\n\t\t\treloadInFlight = false;\n\t\t\treloadHandoffs.delete(handoffKeyForReload);\n\t\t} catch (error) {\n\t\t\treloadInFlight = false;\n\t\t\treloadHandoffs.delete(handoffKeyForReload);\n\t\t\tlogger.error(\"watcher_error\", { path: \"reload\", message: errorMessage(error) });\n\t\t}\n\t};\n\n\tconst armCompactionRecheck = (): void => {\n\t\tif (compactionRecheck !== undefined) return;\n\t\tconst clock = options.clock ?? defaultClock;\n\t\tcompactionRecheck = clock.setTimeout(() => {\n\t\t\tcompactionRecheck = undefined;\n\t\t\tvoid flushPending();\n\t\t}, COMPACTION_RECHECK_MS);\n\t};\n\n\tconst armVetoRecheck = (): void => {\n\t\tif (vetoRecheck !== undefined) return;\n\t\tconst clock = options.clock ?? defaultClock;\n\t\tvetoRecheck = clock.setTimeout(() => {\n\t\t\tvetoRecheck = undefined;\n\t\t\tvoid flushPending();\n\t\t}, VETO_RECHECK_MS);\n\t};\n\n\tconst processReloadHandoff = async (event: SessionStartEvent, ctx: ExtensionContext): Promise<void> => {\n\t\tif (event.reason !== \"reload\") return;\n\t\tconst handoff = reloadHandoffs.take(handoffKey(ctx));\n\t\tif (!handoff) return;\n\t\tconst paths = uniquePaths(handoff.changes.flatMap((change) => change.paths));\n\t\tfor (const change of handoff.changes) {\n\t\t\tpi.events.emit(CONFIG_WATCH_RELOADED, {\n\t\t\t\tregistrationId: change.registrationId,\n\t\t\t\tpaths: [...change.paths],\n\t\t\t});\n\t\t}\n\t\tctx.ui.notify(`Hot-reloaded: ${formatPaths(paths)}`, \"info\");\n\t\tlogger.info(\"reload_completed\", { durationMs: Math.max(0, Date.now() - handoff.requestedAt) });\n\n\t\tconst changedPaths = compareSnapshots(handoff.hashesAtRequest, engine?.getBaselineSnapshot() ?? new Map());\n\t\tif (changedPaths.length > 0) {\n\t\t\tsettingsContents.clear();\n\t\t\tfor (const [path, content] of handoff.settingsContentsAtRequest) settingsContents.set(path, content);\n\t\t\tenqueueChange({ changedPaths, created: [], deleted: [] });\n\t\t\tawait changeChain;\n\t\t}\n\t};\n\n\teventUnsubscribes.push(pi.events.on(CONFIG_WATCH_REGISTER, handleRegistration));\n\teventUnsubscribes.push(pi.events.on(CONFIG_WATCH_UNREGISTER, handleUnregistration));\n\n\tpi.on(\"session_start\", async (event, ctx) => {\n\t\tstarted = true;\n\t\tcurrentContext = ctx;\n\t\trebuildWatchers(ctx);\n\t\tawait processReloadHandoff(event, ctx);\n\t});\n\n\tpi.on(\"agent_end\", async (_event, ctx) => {\n\t\tcurrentContext = ctx;\n\t\tawait flushPending();\n\t});\n\tpi.on(\"agent_settled\", async (_event, ctx) => {\n\t\tcurrentContext = ctx;\n\t\tawait flushPending();\n\t});\n\tpi.on(\"project_trust\", () => {\n\t\tif (currentContext) rebuildWatchers(currentContext);\n\t\treturn { trusted: \"undecided\" };\n\t});\n\tpi.on(\"session_shutdown\", (event) => {\n\t\tconst closingContext = currentContext;\n\t\tstarted = false;\n\t\tcurrentContext = undefined;\n\t\tcloseWatchers();\n\t\tclearCompactionRecheck();\n\t\tclearVetoRecheck();\n\t\tvetoDeferral.reset();\n\t\tcleanupEventListeners();\n\t\tpending.clear();\n\t\tif (event.reason !== \"reload\" && closingContext) reloadHandoffs.delete(handoffKey(closingContext));\n\t});\n\n\tfunction canRequestReload(ctx: ExtensionContext): boolean {\n\t\treturn (\n\t\t\tctx.isIdle() &&\n\t\t\t!ctx.hasPendingMessages() &&\n\t\t\t!(ctx.isCompacting?.() ?? false) &&\n\t\t\tctx.requestReload !== undefined\n\t\t);\n\t}\n\n\tfunction armDeferredNotice(ctx: ExtensionContext): void {\n\t\tif (deferredNoticeShown || pending.size === 0 || !ctx.requestReload) return;\n\t\tdeferredNoticeShown = true;\n\t\tctx.ui.notify(\"Config changed; reloading when idle\", \"info\");\n\t}\n\n\tfunction rejectChange(\n\t\tctx: ExtensionContext,\n\t\tregistrationId: string,\n\t\tpaths: readonly string[],\n\t\terrors: readonly string[],\n\t\tactiveLogger: ConfigReloadLogger,\n\t\tapi: ExtensionAPI,\n\t): void {\n\t\tctx.ui.notify(`Config change rejected: ${errors.join(\"; \")}`, \"error\");\n\t\tapi.events.emit(CONFIG_WATCH_REJECTED, { registrationId, paths: [...paths], errors: [...errors] });\n\t\tactiveLogger.warn(\"validation_rejected\", { registrationId, errorCount: errors.length });\n\t}\n\n\tfunction addPending(changes: Map<string, PendingChange>, registrationId: string, paths: readonly string[]): void {\n\t\tconst pendingChange = changes.get(registrationId) ?? { registrationId, paths: new Set<string>() };\n\t\tfor (const path of paths) pendingChange.paths.add(path);\n\t\tchanges.set(registrationId, pendingChange);\n\t\tif (!canRequestReload(currentContext!)) armDeferredNotice(currentContext!);\n\t}\n}\n\nexport default configReloadExtension;\n\nconst defaultClock: WatchClock = {\n\tsetTimeout: (callback, delayMs) => setTimeout(callback, delayMs),\n\tclearTimeout: (timer) => clearTimeout(timer),\n};\n\nfunction resolveConfigReloadSettings(settingsManager: SettingsManager): ResolvedConfigReloadSettings {\n\tconst global = readConfigReloadPatch(settingsManager.getGlobalSettings());\n\tconst project = readConfigReloadPatch(settingsManager.getProjectSettings());\n\treturn {\n\t\tenabled: project.enabled ?? global.enabled ?? true,\n\t\tdebounceMs: project.debounceMs ?? global.debounceMs ?? DEFAULT_DEBOUNCE_MS,\n\t\twatch: {\n\t\t\tsettings: project.watch?.settings ?? global.watch?.settings ?? true,\n\t\t\tmodels: project.watch?.models ?? global.watch?.models ?? true,\n\t\t\tkeybindings: project.watch?.keybindings ?? global.watch?.keybindings ?? true,\n\t\t\tprompts: project.watch?.prompts ?? global.watch?.prompts ?? true,\n\t\t\tskills: project.watch?.skills ?? global.watch?.skills ?? true,\n\t\t\textensions: project.watch?.extensions ?? global.watch?.extensions ?? true,\n\t\t},\n\t};\n}\n\nfunction readConfigReloadPatch(settings: Settings): ConfigReloadSettingsPatch {\n\tconst candidate: unknown = settings.configReload;\n\tif (!isPlainObject(candidate)) return {};\n\tconst watch = isPlainObject(candidate.watch) ? candidate.watch : undefined;\n\treturn {\n\t\tenabled: typeof candidate.enabled === \"boolean\" ? candidate.enabled : undefined,\n\t\tdebounceMs: validDebounce(candidate.debounceMs),\n\t\twatch: watch\n\t\t\t? {\n\t\t\t\t\tsettings: booleanOrUndefined(watch.settings),\n\t\t\t\t\tmodels: booleanOrUndefined(watch.models),\n\t\t\t\t\tkeybindings: booleanOrUndefined(watch.keybindings),\n\t\t\t\t\tprompts: booleanOrUndefined(watch.prompts),\n\t\t\t\t\tskills: booleanOrUndefined(watch.skills),\n\t\t\t\t\textensions: booleanOrUndefined(watch.extensions),\n\t\t\t\t}\n\t\t\t: undefined,\n\t};\n}\n\nfunction validDebounce(value: unknown): number | undefined {\n\tif (typeof value !== \"number\" || !Number.isFinite(value) || value < 0) return undefined;\n\treturn Math.floor(value);\n}\n\nfunction booleanOrUndefined(value: unknown): boolean | undefined {\n\treturn typeof value === \"boolean\" ? value : undefined;\n}\n\nfunction buildWatchTargets(options: {\n\treadonly cwd: string;\n\treadonly agentDir: string;\n\treadonly projectTrusted: boolean;\n\treadonly settings: ResolvedConfigReloadSettings;\n\treadonly skillPaths: readonly string[];\n\treadonly registrations: ReadonlyMap<string, ConfigWatchRegistration>;\n}): ActiveTarget[] {\n\tconst targets: ActiveTarget[] = [];\n\tconst addBuiltin = (id: string, target: WatchTargetInput, rearmOnCreation?: string): void => {\n\t\ttargets.push({ registrationId: BUILTIN_REGISTRATION_ID, target: { ...target, id }, rearmOnCreation });\n\t};\n\tconst addBuiltinDirectory = (id: string, path: string, filter?: (relPath: string) => boolean): void => {\n\t\tconst resourcePath = resolve(path);\n\t\tif (isExistingDirectory(resourcePath)) {\n\t\t\taddBuiltin(\n\t\t\t\tid,\n\t\t\t\tfilter\n\t\t\t\t\t? { kind: \"dir-recursive\", path: resourcePath, filter }\n\t\t\t\t\t: { kind: \"dir-recursive\", path: resourcePath },\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\t\tconst watchPath = nearestExistingDirectory(dirname(resourcePath));\n\t\tconst firstMissingSegment = relative(watchPath, resourcePath).split(sep)[0] || basename(resourcePath);\n\t\tconst createdPath = resolve(watchPath, firstMissingSegment);\n\t\taddBuiltin(\n\t\t\t`${id}-presence`,\n\t\t\t{\n\t\t\t\tkind: \"dir\",\n\t\t\t\tpath: watchPath,\n\t\t\t\tallowList: [firstMissingSegment],\n\t\t\t},\n\t\t\tcreatedPath,\n\t\t);\n\t};\n\tconst { cwd, agentDir, projectTrusted, settings } = options;\n\tconst projectDir = joinConfigDir(cwd);\n\n\tconst jsonAllowList = CONFIG_FILE_NAMES.filter((name) => {\n\t\tif (name === \"settings.json\" || name === \"settings.jsonc\") return settings.watch.settings;\n\t\tif (name === \"models.json\") return settings.watch.models;\n\t\treturn settings.watch.keybindings;\n\t});\n\tif (jsonAllowList.length > 0) {\n\t\taddBuiltin(\"builtin-global-json\", { kind: \"dir\", path: agentDir, allowList: jsonAllowList });\n\t}\n\tif (settings.watch.prompts) {\n\t\taddBuiltinDirectory(\"builtin-global-prompts\", resolve(agentDir, \"prompts\"));\n\t}\n\tif (settings.watch.extensions) {\n\t\tconst globalExtensionsDir = resolve(agentDir, \"extensions\");\n\t\taddBuiltinDirectory(\"builtin-global-extensions\", globalExtensionsDir, extensionWatchFilter(globalExtensionsDir));\n\t}\n\tif (settings.watch.skills) {\n\t\tfor (const [index, skillPath] of options.skillPaths.entries()) {\n\t\t\tconst target = targetForSkillPath(resolvePath(skillPath, cwd, { trim: true }));\n\t\t\tif (target.kind === \"dir-recursive\") {\n\t\t\t\taddBuiltinDirectory(`builtin-skill-${index}`, target.path);\n\t\t\t} else {\n\t\t\t\taddBuiltin(`builtin-skill-${index}`, target);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (projectTrusted) {\n\t\tconst projectDirExists = isExistingDirectory(projectDir);\n\t\tconst projectWatchEnabled = Object.values(settings.watch).some(Boolean);\n\t\tif (projectWatchEnabled) {\n\t\t\taddBuiltin(\n\t\t\t\t\"builtin-project-presence\",\n\t\t\t\t{ kind: \"dir\", path: cwd, allowList: [CONFIG_DIR_NAME] },\n\t\t\t\tprojectDirExists ? undefined : projectDir,\n\t\t\t);\n\t\t}\n\t\tif (projectDirExists) {\n\t\t\tif (settings.watch.settings) {\n\t\t\t\taddBuiltin(\"builtin-project-settings\", {\n\t\t\t\t\tkind: \"dir\",\n\t\t\t\t\tpath: projectDir,\n\t\t\t\t\tallowList: [\"settings.jsonc\", \"settings.json\"],\n\t\t\t\t});\n\t\t\t}\n\t\t\tif (settings.watch.prompts) {\n\t\t\t\taddBuiltinDirectory(\"builtin-project-prompts\", resolve(projectDir, \"prompts\"));\n\t\t\t}\n\t\t\tif (settings.watch.skills) {\n\t\t\t\taddBuiltinDirectory(\"builtin-project-skills\", resolve(projectDir, \"skills\"));\n\t\t\t}\n\t\t\tif (settings.watch.extensions) {\n\t\t\t\tconst projectExtensionsDir = resolve(projectDir, \"extensions\");\n\t\t\t\taddBuiltinDirectory(\n\t\t\t\t\t\"builtin-project-extensions\",\n\t\t\t\t\tprojectExtensionsDir,\n\t\t\t\t\textensionWatchFilter(projectExtensionsDir),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (const registration of options.registrations.values()) {\n\t\tfor (const [index, target] of registration.targets.entries()) {\n\t\t\tconst path = resolvePath(target.path, cwd, { trim: true });\n\t\t\tconst watchTarget = externalTargetToWatchTarget(path, target.kind, target.filterGlobs);\n\t\t\ttargets.push({\n\t\t\t\tregistrationId: registration.id,\n\t\t\t\ttarget: { ...watchTarget, id: `external-${registration.id}-${index}` },\n\t\t\t});\n\t\t}\n\t}\n\treturn targets;\n}\n\nfunction isExistingDirectory(path: string): boolean {\n\ttry {\n\t\treturn lstatSync(path).isDirectory();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction nearestExistingDirectory(path: string): string {\n\tlet candidate = resolve(path);\n\twhile (!isExistingDirectory(candidate)) {\n\t\tconst parent = dirname(candidate);\n\t\tif (parent === candidate) return candidate;\n\t\tcandidate = parent;\n\t}\n\treturn candidate;\n}\n\nfunction targetForSkillPath(path: string): WatchTargetInput {\n\ttry {\n\t\tif (lstatSync(path).isFile()) {\n\t\t\treturn { kind: \"dir\", path: dirname(path), allowList: [basename(path)] };\n\t\t}\n\t} catch {\n\t\t// A missing configured skill path is treated as a directory so it becomes watchable when present.\n\t}\n\treturn { kind: \"dir-recursive\", path };\n}\n\nfunction externalTargetToWatchTarget(\n\tpath: string,\n\tkind: \"file\" | \"dir\",\n\tfilterGlobs: readonly string[] | undefined,\n): WatchTargetInput {\n\tif (kind === \"file\") {\n\t\tconst name = basename(path);\n\t\treturn {\n\t\t\tkind: \"dir\",\n\t\t\tpath: dirname(path),\n\t\t\tallowList: [name],\n\t\t\tfilter: (relativePath) => relativePath === name && matchesConfigWatchFilter(relativePath, filterGlobs),\n\t\t};\n\t}\n\treturn {\n\t\tkind: \"dir-recursive\",\n\t\tpath,\n\t\t// Literal filters also declare explicitly watched dot-directories. Without\n\t\t// this, an external ancestor target filtered to \".omo\" drops its creation\n\t\t// event before the validator can inspect the new config beneath it.\n\t\tallowList: literalFilterNames(filterGlobs),\n\t\tfilter: (relativePath) => matchesConfigWatchFilter(relativePath, filterGlobs),\n\t};\n}\n\nfunction literalFilterNames(filterGlobs: readonly string[] | undefined): string[] | undefined {\n\tif (!filterGlobs) return undefined;\n\t// A root-anchored glob names a literal path relative to the watch root, so\n\t// strip the anchor before the separator check rejects it.\n\tconst literalNames = filterGlobs\n\t\t.map((filterGlob) => (filterGlob.startsWith(\"/\") ? filterGlob.slice(1) : filterGlob))\n\t\t.filter((filterGlob) => !filterGlob.includes(\"*\") && !filterGlob.includes(\"/\") && !filterGlob.includes(\"\\\\\\\\\"));\n\treturn literalNames.length > 0 ? literalNames : undefined;\n}\n\nfunction groupChangedPaths(paths: readonly string[], targets: readonly ActiveTarget[]): Map<string, string[]> {\n\tconst groups = new Map<string, string[]>();\n\tfor (const path of paths) {\n\t\tlet matched = false;\n\t\tfor (const activeTarget of targets) {\n\t\t\tif (!targetMatchesPath(activeTarget.target, path)) continue;\n\t\t\tconst group = groups.get(activeTarget.registrationId) ?? [];\n\t\t\tif (!group.includes(path)) group.push(path);\n\t\t\tgroups.set(activeTarget.registrationId, group);\n\t\t\tmatched = true;\n\t\t}\n\t\tif (!matched) {\n\t\t\tconst group = groups.get(BUILTIN_REGISTRATION_ID) ?? [];\n\t\t\tgroup.push(path);\n\t\t\tgroups.set(BUILTIN_REGISTRATION_ID, group);\n\t\t}\n\t}\n\treturn groups;\n}\n\nfunction targetMatchesPath(target: WatchTarget, path: string): boolean {\n\tconst relativePath = relative(resolve(target.path), resolve(path));\n\tif (relativePath === \"..\" || relativePath.startsWith(`..${sep}`)) return false;\n\tif (target.kind === \"dir\" && relativePath.includes(sep)) return false;\n\tif (\n\t\ttarget.allowList &&\n\t\t!target.allowList.some((allowed) => relativePath === allowed || relativePath.startsWith(`${allowed}${sep}`))\n\t) {\n\t\treturn false;\n\t}\n\treturn target.filter?.(relativePath) ?? true;\n}\n\nfunction excludeSelfWrites(\n\tpaths: readonly string[],\n\tengine: ConfigReloadWatchEngine | undefined,\n\tagentDir: string,\n\tcwd: string,\n\tlogger: ConfigReloadLogger,\n\tsettingsContents: Map<string, string>,\n): string[] {\n\tconst snapshot = engine?.getBaselineSnapshot();\n\treturn paths.filter((path) => {\n\t\tif (!isSettingsPath(path, agentDir, cwd)) return true;\n\t\tconst hash = snapshot?.get(path);\n\t\tif (hash === undefined || !wasSelfWrite(path, hash)) return true;\n\t\tlogger.debug(\"self_write_suppressed\", { path });\n\t\t// Advance the routine-diff base so a later external change is not\n\t\t// polluted by this session's own just-applied write.\n\t\tupdateSettingsContentSnapshot(settingsContents, path);\n\t\treturn false;\n\t});\n}\n\nasync function validateChangedPaths(\n\tregistrationId: string,\n\tpaths: readonly string[],\n\tregistrations: ReadonlyMap<string, ConfigWatchRegistration>,\n\tagentDir: string,\n\tcwd: string,\n): Promise<string[]> {\n\tif (registrationId === BUILTIN_REGISTRATION_ID) {\n\t\treturn validateBuiltinPaths(paths, agentDir, cwd);\n\t}\n\tconst registration = registrations.get(registrationId);\n\tif (!registration?.validate) return [];\n\ttry {\n\t\tconst result = await registration.validate(paths);\n\t\tif (!isConfigWatchValidation(result)) return [\"Configuration validator returned an invalid result\"];\n\t\treturn result.ok ? [] : result.errors;\n\t} catch (error) {\n\t\treturn [errorMessage(error)];\n\t}\n}\n\nfunction validateBuiltinPaths(paths: readonly string[], agentDir: string, cwd: string): string[] {\n\tconst errors: string[] = [];\n\tfor (const path of paths) {\n\t\tif (isSettingsPath(path, agentDir, cwd)) {\n\t\t\tconst error = validateSettingsFile(path);\n\t\t\tif (error) errors.push(error);\n\t\t\tcontinue;\n\t\t}\n\t\tif (resolve(path) === resolve(agentDir, \"models.json\")) {\n\t\t\tconst error = ModelConfig.loadSync(path).getError();\n\t\t\tif (error) errors.push(error);\n\t\t\tcontinue;\n\t\t}\n\t\tif (resolve(path) === resolve(agentDir, \"keybindings.json\")) {\n\t\t\tconst error = validateKeybindingsFile(path);\n\t\t\tif (error) errors.push(error);\n\t\t}\n\t}\n\treturn errors;\n}\n\nfunction validateSettingsFile(path: string): string | undefined {\n\tif (!existsSync(path)) return undefined;\n\ttry {\n\t\tconst parsed = parseSettingsJson(readFileSync(path, \"utf-8\"));\n\t\t// Keep validation aligned with SettingsManager's loader and migrations without duplicating migration rules.\n\t\tSettingsManager.inMemory(parsed as Partial<Settings>);\n\t\treturn undefined;\n\t} catch (error) {\n\t\treturn `Invalid ${basename(path)}: ${errorMessage(error)}`;\n\t}\n}\n\nfunction validateKeybindingsFile(path: string): string | undefined {\n\tif (!existsSync(path)) return undefined;\n\ttry {\n\t\tconst parsed: unknown = JSON.parse(readFileSync(path, \"utf-8\"));\n\t\tif (!isPlainObject(parsed)) return \"keybindings.json must contain an object\";\n\t\tfor (const value of Object.values(parsed)) {\n\t\t\tif (typeof value === \"string\") continue;\n\t\t\tif (Array.isArray(value) && value.every((entry) => typeof entry === \"string\")) continue;\n\t\t\treturn \"keybindings.json bindings must be strings or string arrays\";\n\t\t}\n\t\treturn undefined;\n\t} catch (error) {\n\t\treturn `Invalid keybindings.json: ${errorMessage(error)}`;\n\t}\n}\n\nfunction registrationFingerprint(registration: ConfigWatchRegistration): string {\n\treturn JSON.stringify({\n\t\tid: registration.id,\n\t\tdisplayName: registration.displayName,\n\t\ttargets: registration.targets.map((target) => ({\n\t\t\tpath: target.path,\n\t\t\tkind: target.kind,\n\t\t\tfilterGlobs: target.filterGlobs ?? null,\n\t\t})),\n\t\thasValidate: registration.validate !== undefined,\n\t});\n}\n\n// A directory target that covers a protected path is safe when every filter is\n// root-anchored (a leading `/` matches only a path relative to the watch root,\n// never a suffix at any depth) and none of those anchored paths intersects a\n// protected path in either direction. Unfiltered targets, unanchored filters,\n// and any protected filter stay fail-closed.\nfunction isSafeFilteredProtectedTarget(\n\ttarget: ConfigWatchTarget,\n\tresolvedPath: string,\n\tprotectedPaths: readonly string[],\n): boolean {\n\tif (target.kind !== \"dir\") return false;\n\tif (protectedPaths.some((protectedPath) => isWithin(resolvedPath, protectedPath))) return false;\n\tconst filterGlobs = target.filterGlobs;\n\tif (!filterGlobs || filterGlobs.length === 0) return false;\n\treturn filterGlobs.every((glob) => {\n\t\tif (!glob.startsWith(\"/\")) return false;\n\t\tconst filteredPath = resolve(resolvedPath, glob.slice(1));\n\t\treturn protectedPaths.every(\n\t\t\t(protectedPath) => !isWithin(filteredPath, protectedPath) && !isWithin(protectedPath, filteredPath),\n\t\t);\n\t});\n}\n\nfunction registrationHasRestrictedTarget(\n\tregistration: ConfigWatchRegistration,\n\tcwd: string,\n\tagentDir: string,\n): boolean {\n\tconst protectedPaths = [resolve(agentDir, \"auth.json\"), resolve(agentDir, \"sessions\"), resolve(agentDir, \"logs\")];\n\treturn registration.targets.some((target) => {\n\t\tconst path = resolvePath(target.path, cwd, { trim: true });\n\t\tif (isSafeFilteredProtectedTarget(target, path, protectedPaths)) return false;\n\t\treturn protectedPaths.some((protectedPath) => isWithin(path, protectedPath) || isWithin(protectedPath, path));\n\t});\n}\n\nfunction pendingChanges(pending: ReadonlyMap<string, PendingChange>): Array<{\n\treadonly registrationId: string;\n\treadonly paths: readonly string[];\n}> {\n\treturn [...pending.values()].map((change) => ({\n\t\tregistrationId: change.registrationId,\n\t\tpaths: [...change.paths].sort(),\n\t}));\n}\n\nfunction compareSnapshots(previous: ReadonlyMap<string, string>, next: ReadonlyMap<string, string>): string[] {\n\tconst changed = new Set<string>();\n\tfor (const [path, hash] of next) {\n\t\tif (previous.get(path) !== hash) changed.add(path);\n\t}\n\tfor (const path of previous.keys()) {\n\t\tif (!next.has(path)) changed.add(path);\n\t}\n\treturn [...changed].sort();\n}\n\nfunction uniquePaths(paths: readonly string[]): string[] {\n\treturn [...new Set(paths)].sort();\n}\n\nfunction isWithin(path: string, root: string): boolean {\n\treturn path === root || path.startsWith(`${root}${sep}`);\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nfunction errorMessage(error: unknown): string {\n\treturn error instanceof Error ? error.message : String(error);\n}\n\nfunction formatPaths(paths: readonly string[]): string {\n\treturn paths.length === 0 ? \"configuration\" : paths.join(\", \");\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const CONTINUATION_CAP_BLOCKED_REASON = "continuation cap reached";
|
|
2
2
|
export declare const REPETITION_BLOCKED_REASON = "repeated assistant output";
|
|
3
3
|
export declare const LENGTH_EXHAUSTED_BLOCKED_REASON = "output truncation repeated";
|
|
4
|
+
export declare const UNATTENDED_CONTINUATION_BLOCKED_REASON = "unattended continuation limit reached";
|
|
4
5
|
export declare const PROVIDER_ERROR_BLOCKED_REASON = "provider error ended the turn (retries exhausted)";
|
|
5
6
|
export declare function isMechanicalContinuationBlock(blockedReason: string | undefined): boolean;
|
|
6
7
|
export declare function continuationCapRecoveryHint(blockedReason: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"continuation-recovery.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/continuation-recovery.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B,6BAA6B,CAAC;AAC1E,eAAO,MAAM,yBAAyB,8BAA8B,CAAC;AACrE,eAAO,MAAM,+BAA+B,+BAA+B,CAAC;AAC5E,eAAO,MAAM,6BAA6B,sDAAsD,CAAC;
|
|
1
|
+
{"version":3,"file":"continuation-recovery.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/continuation-recovery.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,+BAA+B,6BAA6B,CAAC;AAC1E,eAAO,MAAM,yBAAyB,8BAA8B,CAAC;AACrE,eAAO,MAAM,+BAA+B,+BAA+B,CAAC;AAC5E,eAAO,MAAM,sCAAsC,0CAA0C,CAAC;AAC9F,eAAO,MAAM,6BAA6B,sDAAsD,CAAC;AAiBjG,wBAAgB,6BAA6B,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAGxF;AAED,wBAAgB,2BAA2B,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CAGzE"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export const CONTINUATION_CAP_BLOCKED_REASON = "continuation cap reached";
|
|
2
2
|
export const REPETITION_BLOCKED_REASON = "repeated assistant output";
|
|
3
3
|
export const LENGTH_EXHAUSTED_BLOCKED_REASON = "output truncation repeated";
|
|
4
|
+
export const UNATTENDED_CONTINUATION_BLOCKED_REASON = "unattended continuation limit reached";
|
|
4
5
|
export const PROVIDER_ERROR_BLOCKED_REASON = "provider error ended the turn (retries exhausted)";
|
|
5
6
|
// Mechanical blocks are stops the runtime imposed on itself, not decisions the
|
|
6
7
|
// user or the model made. A terminal provider error belongs here: the provider
|
|
@@ -11,6 +12,7 @@ const MECHANICAL_CONTINUATION_BLOCKS = [
|
|
|
11
12
|
CONTINUATION_CAP_BLOCKED_REASON,
|
|
12
13
|
REPETITION_BLOCKED_REASON,
|
|
13
14
|
LENGTH_EXHAUSTED_BLOCKED_REASON,
|
|
15
|
+
UNATTENDED_CONTINUATION_BLOCKED_REASON,
|
|
14
16
|
PROVIDER_ERROR_BLOCKED_REASON,
|
|
15
17
|
];
|
|
16
18
|
const RESUME_GUIDANCE = "Send any message to resume.";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"continuation-recovery.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/continuation-recovery.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,+BAA+B,GAAG,0BAA0B,CAAC;AAC1E,MAAM,CAAC,MAAM,yBAAyB,GAAG,2BAA2B,CAAC;AACrE,MAAM,CAAC,MAAM,+BAA+B,GAAG,4BAA4B,CAAC;AAC5E,MAAM,CAAC,MAAM,6BAA6B,GAAG,mDAAmD,CAAC;AAEjG,+EAA+E;AAC/E,+EAA+E;AAC/E,8EAA8E;AAC9E,4EAA4E;AAC5E,8BAA8B;AAC9B,MAAM,8BAA8B,GAAsB;IACzD,+BAA+B;IAC/B,yBAAyB;IACzB,+BAA+B;IAC/B,6BAA6B;CAC7B,CAAC;AAEF,MAAM,eAAe,GAAG,6BAA6B,CAAC;AAEtD,MAAM,UAAU,6BAA6B,CAAC,aAAiC;IAC9E,IAAI,aAAa,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC9C,OAAO,8BAA8B,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,aAAqB;IAChE,IAAI,CAAC,6BAA6B,CAAC,aAAa,CAAC;QAAE,OAAO,8BAA8B,aAAa,EAAE,CAAC;IACxG,OAAO,8BAA8B,aAAa,KAAK,eAAe,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["export const CONTINUATION_CAP_BLOCKED_REASON = \"continuation cap reached\";\nexport const REPETITION_BLOCKED_REASON = \"repeated assistant output\";\nexport const LENGTH_EXHAUSTED_BLOCKED_REASON = \"output truncation repeated\";\nexport const PROVIDER_ERROR_BLOCKED_REASON = \"provider error ended the turn (retries exhausted)\";\n\n// Mechanical blocks are stops the runtime imposed on itself, not decisions the\n// user or the model made. A terminal provider error belongs here: the provider\n// failing is infrastructure, and the user's next message is exactly the retry\n// signal, so the goal resumes instead of stranding behind a block that only\n// `/goal resume` could clear.\nconst MECHANICAL_CONTINUATION_BLOCKS: readonly string[] = [\n\tCONTINUATION_CAP_BLOCKED_REASON,\n\tREPETITION_BLOCKED_REASON,\n\tLENGTH_EXHAUSTED_BLOCKED_REASON,\n\tPROVIDER_ERROR_BLOCKED_REASON,\n];\n\nconst RESUME_GUIDANCE = \"Send any message to resume.\";\n\nexport function isMechanicalContinuationBlock(blockedReason: string | undefined): boolean {\n\tif (blockedReason === undefined) return false;\n\treturn MECHANICAL_CONTINUATION_BLOCKS.includes(blockedReason);\n}\n\nexport function continuationCapRecoveryHint(blockedReason: string): string {\n\tif (!isMechanicalContinuationBlock(blockedReason)) return `Goal continuation blocked: ${blockedReason}`;\n\treturn `Goal continuation blocked: ${blockedReason}. ${RESUME_GUIDANCE}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"continuation-recovery.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/continuation-recovery.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,+BAA+B,GAAG,0BAA0B,CAAC;AAC1E,MAAM,CAAC,MAAM,yBAAyB,GAAG,2BAA2B,CAAC;AACrE,MAAM,CAAC,MAAM,+BAA+B,GAAG,4BAA4B,CAAC;AAC5E,MAAM,CAAC,MAAM,sCAAsC,GAAG,uCAAuC,CAAC;AAC9F,MAAM,CAAC,MAAM,6BAA6B,GAAG,mDAAmD,CAAC;AAEjG,+EAA+E;AAC/E,+EAA+E;AAC/E,8EAA8E;AAC9E,4EAA4E;AAC5E,8BAA8B;AAC9B,MAAM,8BAA8B,GAAsB;IACzD,+BAA+B;IAC/B,yBAAyB;IACzB,+BAA+B;IAC/B,sCAAsC;IACtC,6BAA6B;CAC7B,CAAC;AAEF,MAAM,eAAe,GAAG,6BAA6B,CAAC;AAEtD,MAAM,UAAU,6BAA6B,CAAC,aAAiC;IAC9E,IAAI,aAAa,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC9C,OAAO,8BAA8B,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,aAAqB;IAChE,IAAI,CAAC,6BAA6B,CAAC,aAAa,CAAC;QAAE,OAAO,8BAA8B,aAAa,EAAE,CAAC;IACxG,OAAO,8BAA8B,aAAa,KAAK,eAAe,EAAE,CAAC;AAC1E,CAAC","sourcesContent":["export const CONTINUATION_CAP_BLOCKED_REASON = \"continuation cap reached\";\nexport const REPETITION_BLOCKED_REASON = \"repeated assistant output\";\nexport const LENGTH_EXHAUSTED_BLOCKED_REASON = \"output truncation repeated\";\nexport const UNATTENDED_CONTINUATION_BLOCKED_REASON = \"unattended continuation limit reached\";\nexport const PROVIDER_ERROR_BLOCKED_REASON = \"provider error ended the turn (retries exhausted)\";\n\n// Mechanical blocks are stops the runtime imposed on itself, not decisions the\n// user or the model made. A terminal provider error belongs here: the provider\n// failing is infrastructure, and the user's next message is exactly the retry\n// signal, so the goal resumes instead of stranding behind a block that only\n// `/goal resume` could clear.\nconst MECHANICAL_CONTINUATION_BLOCKS: readonly string[] = [\n\tCONTINUATION_CAP_BLOCKED_REASON,\n\tREPETITION_BLOCKED_REASON,\n\tLENGTH_EXHAUSTED_BLOCKED_REASON,\n\tUNATTENDED_CONTINUATION_BLOCKED_REASON,\n\tPROVIDER_ERROR_BLOCKED_REASON,\n];\n\nconst RESUME_GUIDANCE = \"Send any message to resume.\";\n\nexport function isMechanicalContinuationBlock(blockedReason: string | undefined): boolean {\n\tif (blockedReason === undefined) return false;\n\treturn MECHANICAL_CONTINUATION_BLOCKS.includes(blockedReason);\n}\n\nexport function continuationCapRecoveryHint(blockedReason: string): string {\n\tif (!isMechanicalContinuationBlock(blockedReason)) return `Goal continuation blocked: ${blockedReason}`;\n\treturn `Goal continuation blocked: ${blockedReason}. ${RESUME_GUIDANCE}`;\n}\n"]}
|
|
@@ -7,6 +7,13 @@ export declare const GOAL_CONTINUATION_CAP = 8;
|
|
|
7
7
|
export declare const GOAL_STALL_TOOLLESS_THRESHOLD = 3;
|
|
8
8
|
export declare const GOAL_REPETITION_HASH_STREAK = 3;
|
|
9
9
|
export declare const GOAL_LENGTH_RECOVERY_LIMIT = 1;
|
|
10
|
+
/**
|
|
11
|
+
* Hard budget of automatic continuations without accepted direct user input (#1139).
|
|
12
|
+
* Progress and tool use never refill it: only direct input does. Stays above the
|
|
13
|
+
* #447 distinct-progress pin (50) and an 8-hour monitor-backstop cadence
|
|
14
|
+
* (~120 deliveries at 240s), below the observed 289-continuation incident run.
|
|
15
|
+
*/
|
|
16
|
+
export declare const GOAL_UNATTENDED_CONTINUATION_LIMIT = 150;
|
|
10
17
|
export declare const GOAL_USER_GRACE_DELAY_MS = 10000;
|
|
11
18
|
export type GoalContinuationPath = "immediate" | "monitorDelayed" | "userGrace" | "sessionStart" | "systemRecovery" | "providerRecovery";
|
|
12
19
|
export type GoalContinuationInput = {
|
|
@@ -29,7 +36,7 @@ export type GoalContinuationVerdict = {
|
|
|
29
36
|
stallNotice: boolean;
|
|
30
37
|
} | {
|
|
31
38
|
kind: "deny";
|
|
32
|
-
reason: "not-eligible" | "single-flight" | "cap" | "stale" | "repetition" | "length-exhausted";
|
|
39
|
+
reason: "not-eligible" | "single-flight" | "cap" | "stale" | "repetition" | "length-exhausted" | "unattended";
|
|
33
40
|
};
|
|
34
41
|
export declare function shouldQueueGoalContinuationWhenIdle(goal: Goal | null, isIdle: boolean, hasPendingMessages: boolean): goal is Goal;
|
|
35
42
|
export declare function shouldQueueGoalContinuationAfterAgentEnd(goal: Goal | null, hasPendingMessages: boolean, messages: readonly AgentMessage[]): goal is Goal;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"continuation.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/continuation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,KAAK,qBAAqB,GAAG,OAAO,CAAC,YAAY,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC,CAAC;AAG1E,eAAO,MAAM,qBAAqB,IAAI,CAAC;AACvC,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAC/C,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAC7C,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAC5C,eAAO,MAAM,wBAAwB,QAAS,CAAC;AAE/C,MAAM,MAAM,oBAAoB,GAC7B,WAAW,GACX,gBAAgB,GAChB,WAAW,GACX,cAAc,GACd,gBAAgB,GAChB,kBAAkB,CAAC;AAEtB,MAAM,MAAM,qBAAqB,GAAG;IACnC,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;IACrC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,cAAc,EAAE,qBAAqB,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;IACzE,QAAQ,CAAC,wBAAwB,EAAE,MAAM,CAAC;IAC1C,QAAQ,CAAC,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IACvD,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,QAAQ,CAAC,2BAA2B,EAAE,MAAM,CAAC;IA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sB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,uFAAuF;AACvF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQtD;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAC7C,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,EACtB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,qBAAqB,EAAE,MAAM,GAC3B,MAAM,CAER;AAED,wBAAgB,2BAA2B,CAC1C,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,2BAA2B,GAAG,kBAAkB,CAAC,GAClF,OAAO,CAMT;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG,OAAO,CAKpF"}
|
|
@@ -2,6 +2,13 @@ export const GOAL_CONTINUATION_CAP = 8;
|
|
|
2
2
|
export const GOAL_STALL_TOOLLESS_THRESHOLD = 3;
|
|
3
3
|
export const GOAL_REPETITION_HASH_STREAK = 3;
|
|
4
4
|
export const GOAL_LENGTH_RECOVERY_LIMIT = 1;
|
|
5
|
+
/**
|
|
6
|
+
* Hard budget of automatic continuations without accepted direct user input (#1139).
|
|
7
|
+
* Progress and tool use never refill it: only direct input does. Stays above the
|
|
8
|
+
* #447 distinct-progress pin (50) and an 8-hour monitor-backstop cadence
|
|
9
|
+
* (~120 deliveries at 240s), below the observed 289-continuation incident run.
|
|
10
|
+
*/
|
|
11
|
+
export const GOAL_UNATTENDED_CONTINUATION_LIMIT = 150;
|
|
5
12
|
export const GOAL_USER_GRACE_DELAY_MS = 10_000;
|
|
6
13
|
export function shouldQueueGoalContinuationWhenIdle(goal, isIdle, hasPendingMessages) {
|
|
7
14
|
return goal?.status === "active" && isIdle && !hasPendingMessages;
|
|
@@ -47,6 +54,8 @@ export function evaluateGoalContinuation(input) {
|
|
|
47
54
|
return { kind: "deny", reason: "single-flight" };
|
|
48
55
|
if (hasRepeatedNormalizedOutputHash(input.recentNormalizedOutputHashes))
|
|
49
56
|
return { kind: "deny", reason: "repetition" };
|
|
57
|
+
if (isUnattendedBudgetExhausted(input))
|
|
58
|
+
return { kind: "deny", reason: "unattended" };
|
|
50
59
|
if (input.consecutiveContinuations >= GOAL_CONTINUATION_CAP) {
|
|
51
60
|
return { kind: "deny", reason: "cap" };
|
|
52
61
|
}
|
|
@@ -106,6 +115,12 @@ function isEligibleForGoalContinuation(input) {
|
|
|
106
115
|
}
|
|
107
116
|
return input.isIdle;
|
|
108
117
|
}
|
|
118
|
+
/** Monitor-delayed deliveries are exempt: armed-wake waiting is by-design and rate-limited by the cache-aware timer. */
|
|
119
|
+
function isUnattendedBudgetExhausted(input) {
|
|
120
|
+
if (input.path === "monitorDelayed")
|
|
121
|
+
return false;
|
|
122
|
+
return (input.goal?.unattendedContinuations ?? 0) >= GOAL_UNATTENDED_CONTINUATION_LIMIT;
|
|
123
|
+
}
|
|
109
124
|
function hasRepeatedNormalizedOutputHash(hashes) {
|
|
110
125
|
const latestHash = hashes.at(-1);
|
|
111
126
|
if (latestHash === undefined)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"continuation.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/continuation.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AACvC,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAC7C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAC5C,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAgC/C,MAAM,UAAU,mCAAmC,CAClD,IAAiB,EACjB,MAAe,EACf,kBAA2B;IAE3B,OAAO,IAAI,EAAE,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,CAAC,kBAAkB,CAAC;AACnE,CAAC;AAED,MAAM,UAAU,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KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC;QACzF,MAAM,IAAI,CAAC,CAAC;IACb,CAAC;IACD,OAAO,MAAM,IAAI,2BAA2B,CAAC;AAC9C,CAAC;AAED,SAAS,qBAAqB,CAAC,KAA4B;IAC1D,OAAO,KAAK,CAAC,0BAA0B,IAAI,6BAA6B,CAAC;AAC1E,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { Goal } from \"./types.ts\";\n\ntype AssistantAgentMessage = Extract<AgentMessage, { role: \"assistant\" }>;\ntype ToolResultAgentMessage = Extract<AgentMessage, { role: \"toolResult\" }>;\n\nexport const GOAL_CONTINUATION_CAP = 8;\nexport const GOAL_STALL_TOOLLESS_THRESHOLD = 3;\nexport const GOAL_REPETITION_HASH_STREAK = 3;\nexport const GOAL_LENGTH_RECOVERY_LIMIT = 1;\nexport const GOAL_USER_GRACE_DELAY_MS = 10_000;\n\nexport type GoalContinuationPath =\n\t| \"immediate\"\n\t| \"monitorDelayed\"\n\t| \"userGrace\"\n\t| \"sessionStart\"\n\t| \"systemRecovery\"\n\t| \"providerRecovery\";\n\nexport type GoalContinuationInput = {\n\treadonly goal: Goal | null;\n\treadonly isIdle: boolean;\n\treadonly hasPendingMessages: boolean;\n\treadonly path: GoalContinuationPath;\n\treadonly lastStopReason: AssistantAgentMessage[\"stopReason\"] | undefined;\n\treadonly consecutiveContinuations: number;\n\treadonly lastContinuationSignature: string | undefined;\n\treadonly currentSignature: string | undefined;\n\treadonly consecutiveLengthRecoveries: number;\n\treadonly recentNormalizedOutputHashes: readonly string[];\n\treadonly toollessContinuationStreak: number;\n\treadonly continuationPending: boolean;\n};\n\nexport type GoalContinuationVerdict =\n\t| { kind: \"continue\"; prompt: \"full\" | \"minimal\"; stallNotice: boolean }\n\t| {\n\t\t\tkind: \"deny\";\n\t\t\treason: \"not-eligible\" | \"single-flight\" | \"cap\" | \"stale\" | \"repetition\" | \"length-exhausted\";\n\t };\n\nexport function shouldQueueGoalContinuationWhenIdle(\n\tgoal: Goal | null,\n\tisIdle: boolean,\n\thasPendingMessages: boolean,\n): goal is Goal {\n\treturn goal?.status === \"active\" && isIdle && !hasPendingMessages;\n}\n\nexport function shouldQueueGoalContinuationAfterAgentEnd(\n\tgoal: Goal | null,\n\thasPendingMessages: boolean,\n\tmessages: readonly AgentMessage[],\n): goal is Goal {\n\treturn goal?.status === \"active\" && !hasPendingMessages && didAgentEndCleanly(messages);\n}\n\nfunction didAgentEndCleanly(messages: readonly AgentMessage[]): boolean {\n\tconst lastAssistantIndex = findLastAssistantMessageIndex(messages);\n\tif (lastAssistantIndex === undefined) return false;\n\n\tconst lastAssistant = messages[lastAssistantIndex];\n\tif (lastAssistant?.role !== \"assistant\" || !isContinuableStopReason(lastAssistant.stopReason)) return false;\n\n\tfor (let index = lastAssistantIndex + 1; index < messages.length; index++) {\n\t\tconst message = messages[index];\n\t\tif (message?.role === \"toolResult\" && isAbortedToolResult(message)) return false;\n\t}\n\treturn true;\n}\n\nfunction findLastAssistantMessageIndex(messages: readonly AgentMessage[]): number | undefined {\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst message = messages[index];\n\t\tif (message?.role === \"assistant\") {\n\t\t\treturn index;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction isContinuableStopReason(stopReason: AssistantAgentMessage[\"stopReason\"]): boolean {\n\treturn stopReason === \"stop\" || stopReason === \"length\";\n}\n\nfunction isAbortedToolResult(message: ToolResultAgentMessage): boolean {\n\tif (!message.isError) return false;\n\treturn message.content.some((content) => content.type === \"text\" && /\\babort(?:ed)?\\b/i.test(content.text));\n}\n\nexport function evaluateGoalContinuation(input: GoalContinuationInput): GoalContinuationVerdict {\n\tif (!isEligibleForGoalContinuation(input)) return { kind: \"deny\", reason: \"not-eligible\" };\n\tif (input.continuationPending) return { kind: \"deny\", reason: \"single-flight\" };\n\tif (hasRepeatedNormalizedOutputHash(input.recentNormalizedOutputHashes))\n\t\treturn { kind: \"deny\", reason: \"repetition\" };\n\tif (input.consecutiveContinuations >= GOAL_CONTINUATION_CAP) {\n\t\treturn { kind: \"deny\", reason: \"cap\" };\n\t}\n\tif (\n\t\t(input.path === \"immediate\" || input.path === \"userGrace\") &&\n\t\tinput.lastContinuationSignature !== undefined &&\n\t\tinput.lastContinuationSignature === input.currentSignature\n\t) {\n\t\treturn { kind: \"deny\", reason: \"stale\" };\n\t}\n\tif (input.lastStopReason === \"length\") {\n\t\tif (input.consecutiveLengthRecoveries >= GOAL_LENGTH_RECOVERY_LIMIT) {\n\t\t\treturn { kind: \"deny\", reason: \"length-exhausted\" };\n\t\t}\n\t\treturn { kind: \"continue\", prompt: \"minimal\", stallNotice: shouldShowStallNotice(input) };\n\t}\n\treturn { kind: \"continue\", prompt: \"full\", stallNotice: shouldShowStallNotice(input) };\n}\n\n/** Produces a stable, whitespace-insensitive representation for repetition detection. */\nexport function normalizeAssistantText(text: string): string {\n\treturn text.toLowerCase().replace(/\\s+/g, \" \").trim();\n}\n\n/** Hashes normalized assistant text with the deterministic 32-bit FNV-1a algorithm. */\nexport function hashAssistantText(text: string): string {\n\tconst normalized = normalizeAssistantText(text);\n\tlet hash = 0x811c9dc5;\n\tfor (let index = 0; index < normalized.length; index++) {\n\t\thash ^= normalized.charCodeAt(index);\n\t\thash = Math.imul(hash, 0x01000193);\n\t}\n\treturn (hash >>> 0).toString(16).padStart(8, \"0\");\n}\n\n/**\n * Identifies the observable goal progress for stale-continuation admission.\n * Deliberately excludes goal.updatedAt because usage accounting updates it after every agent turn.\n */\nexport function buildGoalContinuationSignature(\n\tgoal: Pick<Goal, \"id\">,\n\topenTodos: number,\n\ttotalTodos: number,\n\tlastAssistantTextHash: string,\n): string {\n\treturn `${goal.id}:${openTodos}/${totalTodos}:${lastAssistantTextHash}`;\n}\n\nexport function hasGoalContinuationProgress(\n\tinput: Pick<GoalContinuationInput, \"lastContinuationSignature\" | \"currentSignature\">,\n): boolean {\n\treturn (\n\t\tinput.lastContinuationSignature !== undefined &&\n\t\tinput.currentSignature !== undefined &&\n\t\tinput.lastContinuationSignature !== input.currentSignature\n\t);\n}\n\nexport function continuationTurnUsedTools(messages: readonly AgentMessage[]): boolean {\n\treturn messages.some((message) => {\n\t\tif (message?.role === \"toolResult\") return true;\n\t\treturn message?.role === \"assistant\" && message.content.some((content) => content.type === \"toolCall\");\n\t});\n}\n\nfunction isEligibleForGoalContinuation(input: GoalContinuationInput): boolean {\n\tif (input.goal?.status !== \"active\" || input.hasPendingMessages) return false;\n\tif (input.path === \"systemRecovery\" || input.path === \"providerRecovery\") return true;\n\tif (input.path === \"immediate\") {\n\t\treturn input.lastStopReason !== undefined && isContinuableStopReason(input.lastStopReason);\n\t}\n\treturn input.isIdle;\n}\n\nfunction hasRepeatedNormalizedOutputHash(hashes: readonly string[]): boolean {\n\tconst latestHash = hashes.at(-1);\n\tif (latestHash === undefined) return false;\n\n\tlet streak = 0;\n\tfor (let index = hashes.length - 1; index >= 0 && hashes[index] === latestHash; index--) {\n\t\tstreak += 1;\n\t}\n\treturn streak >= GOAL_REPETITION_HASH_STREAK;\n}\n\nfunction shouldShowStallNotice(input: GoalContinuationInput): boolean {\n\treturn input.toollessContinuationStreak >= GOAL_STALL_TOOLLESS_THRESHOLD;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"continuation.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/continuation.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AACvC,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAC7C,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAC5C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kCAAkC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OAAO,KAAK,CAAC,cAAc,KAAK,SAAS,IAAI,uBAAuB,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC5F,CAAC;IACD,OAAO,KAAK,CAAC,MAAM,CAAC;AACrB,CAAC;AAED,wHAAwH;AACxH,SAAS,2BAA2B,CAAC,KAA4B;IAChE,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAgB;QAAE,OAAO,KAAK,CAAC;IAClD,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,uBAAuB,IAAI,CAAC,CAAC,IAAI,kCAAkC,CAAC;AACzF,CAAC;AAED,SAAS,+BAA+B,CAAC,MAAyB;IACjE,MAAM,UAAU,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,IAAI,UAAU,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAE3C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,IAAI,KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,UAAU,EAAE,KAAK,EAAE,EAAE,CAAC;QACzF,MAAM,IAAI,CAAC,CAAC;IACb,CAAC;IACD,OAAO,MAAM,IAAI,2BAA2B,CAAC;AAC9C,CAAC;AAED,SAAS,qBAAqB,CAAC,KAA4B;IAC1D,OAAO,KAAK,CAAC,0BAA0B,IAAI,6BAA6B,CAAC;AAC1E,CAAC","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { Goal } from \"./types.ts\";\n\ntype AssistantAgentMessage = Extract<AgentMessage, { role: \"assistant\" }>;\ntype ToolResultAgentMessage = Extract<AgentMessage, { role: \"toolResult\" }>;\n\nexport const GOAL_CONTINUATION_CAP = 8;\nexport const GOAL_STALL_TOOLLESS_THRESHOLD = 3;\nexport const GOAL_REPETITION_HASH_STREAK = 3;\nexport const GOAL_LENGTH_RECOVERY_LIMIT = 1;\n/**\n * Hard budget of automatic continuations without accepted direct user input (#1139).\n * Progress and tool use never refill it: only direct input does. Stays above the\n * #447 distinct-progress pin (50) and an 8-hour monitor-backstop cadence\n * (~120 deliveries at 240s), below the observed 289-continuation incident run.\n */\nexport const GOAL_UNATTENDED_CONTINUATION_LIMIT = 150;\nexport const GOAL_USER_GRACE_DELAY_MS = 10_000;\n\nexport type GoalContinuationPath =\n\t| \"immediate\"\n\t| \"monitorDelayed\"\n\t| \"userGrace\"\n\t| \"sessionStart\"\n\t| \"systemRecovery\"\n\t| \"providerRecovery\";\n\nexport type GoalContinuationInput = {\n\treadonly goal: Goal | null;\n\treadonly isIdle: boolean;\n\treadonly hasPendingMessages: boolean;\n\treadonly path: GoalContinuationPath;\n\treadonly lastStopReason: AssistantAgentMessage[\"stopReason\"] | undefined;\n\treadonly consecutiveContinuations: number;\n\treadonly lastContinuationSignature: string | undefined;\n\treadonly currentSignature: string | undefined;\n\treadonly consecutiveLengthRecoveries: number;\n\treadonly recentNormalizedOutputHashes: readonly string[];\n\treadonly toollessContinuationStreak: number;\n\treadonly continuationPending: boolean;\n};\n\nexport type GoalContinuationVerdict =\n\t| { kind: \"continue\"; prompt: \"full\" | \"minimal\"; stallNotice: boolean }\n\t| {\n\t\t\tkind: \"deny\";\n\t\t\treason: \"not-eligible\" | \"single-flight\" | \"cap\" | \"stale\" | \"repetition\" | \"length-exhausted\" | \"unattended\";\n\t };\n\nexport function shouldQueueGoalContinuationWhenIdle(\n\tgoal: Goal | null,\n\tisIdle: boolean,\n\thasPendingMessages: boolean,\n): goal is Goal {\n\treturn goal?.status === \"active\" && isIdle && !hasPendingMessages;\n}\n\nexport function shouldQueueGoalContinuationAfterAgentEnd(\n\tgoal: Goal | null,\n\thasPendingMessages: boolean,\n\tmessages: readonly AgentMessage[],\n): goal is Goal {\n\treturn goal?.status === \"active\" && !hasPendingMessages && didAgentEndCleanly(messages);\n}\n\nfunction didAgentEndCleanly(messages: readonly AgentMessage[]): boolean {\n\tconst lastAssistantIndex = findLastAssistantMessageIndex(messages);\n\tif (lastAssistantIndex === undefined) return false;\n\n\tconst lastAssistant = messages[lastAssistantIndex];\n\tif (lastAssistant?.role !== \"assistant\" || !isContinuableStopReason(lastAssistant.stopReason)) return false;\n\n\tfor (let index = lastAssistantIndex + 1; index < messages.length; index++) {\n\t\tconst message = messages[index];\n\t\tif (message?.role === \"toolResult\" && isAbortedToolResult(message)) return false;\n\t}\n\treturn true;\n}\n\nfunction findLastAssistantMessageIndex(messages: readonly AgentMessage[]): number | undefined {\n\tfor (let index = messages.length - 1; index >= 0; index--) {\n\t\tconst message = messages[index];\n\t\tif (message?.role === \"assistant\") {\n\t\t\treturn index;\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction isContinuableStopReason(stopReason: AssistantAgentMessage[\"stopReason\"]): boolean {\n\treturn stopReason === \"stop\" || stopReason === \"length\";\n}\n\nfunction isAbortedToolResult(message: ToolResultAgentMessage): boolean {\n\tif (!message.isError) return false;\n\treturn message.content.some((content) => content.type === \"text\" && /\\babort(?:ed)?\\b/i.test(content.text));\n}\n\nexport function evaluateGoalContinuation(input: GoalContinuationInput): GoalContinuationVerdict {\n\tif (!isEligibleForGoalContinuation(input)) return { kind: \"deny\", reason: \"not-eligible\" };\n\tif (input.continuationPending) return { kind: \"deny\", reason: \"single-flight\" };\n\tif (hasRepeatedNormalizedOutputHash(input.recentNormalizedOutputHashes))\n\t\treturn { kind: \"deny\", reason: \"repetition\" };\n\tif (isUnattendedBudgetExhausted(input)) return { kind: \"deny\", reason: \"unattended\" };\n\tif (input.consecutiveContinuations >= GOAL_CONTINUATION_CAP) {\n\t\treturn { kind: \"deny\", reason: \"cap\" };\n\t}\n\tif (\n\t\t(input.path === \"immediate\" || input.path === \"userGrace\") &&\n\t\tinput.lastContinuationSignature !== undefined &&\n\t\tinput.lastContinuationSignature === input.currentSignature\n\t) {\n\t\treturn { kind: \"deny\", reason: \"stale\" };\n\t}\n\tif (input.lastStopReason === \"length\") {\n\t\tif (input.consecutiveLengthRecoveries >= GOAL_LENGTH_RECOVERY_LIMIT) {\n\t\t\treturn { kind: \"deny\", reason: \"length-exhausted\" };\n\t\t}\n\t\treturn { kind: \"continue\", prompt: \"minimal\", stallNotice: shouldShowStallNotice(input) };\n\t}\n\treturn { kind: \"continue\", prompt: \"full\", stallNotice: shouldShowStallNotice(input) };\n}\n\n/** Produces a stable, whitespace-insensitive representation for repetition detection. */\nexport function normalizeAssistantText(text: string): string {\n\treturn text.toLowerCase().replace(/\\s+/g, \" \").trim();\n}\n\n/** Hashes normalized assistant text with the deterministic 32-bit FNV-1a algorithm. */\nexport function hashAssistantText(text: string): string {\n\tconst normalized = normalizeAssistantText(text);\n\tlet hash = 0x811c9dc5;\n\tfor (let index = 0; index < normalized.length; index++) {\n\t\thash ^= normalized.charCodeAt(index);\n\t\thash = Math.imul(hash, 0x01000193);\n\t}\n\treturn (hash >>> 0).toString(16).padStart(8, \"0\");\n}\n\n/**\n * Identifies the observable goal progress for stale-continuation admission.\n * Deliberately excludes goal.updatedAt because usage accounting updates it after every agent turn.\n */\nexport function buildGoalContinuationSignature(\n\tgoal: Pick<Goal, \"id\">,\n\topenTodos: number,\n\ttotalTodos: number,\n\tlastAssistantTextHash: string,\n): string {\n\treturn `${goal.id}:${openTodos}/${totalTodos}:${lastAssistantTextHash}`;\n}\n\nexport function hasGoalContinuationProgress(\n\tinput: Pick<GoalContinuationInput, \"lastContinuationSignature\" | \"currentSignature\">,\n): boolean {\n\treturn (\n\t\tinput.lastContinuationSignature !== undefined &&\n\t\tinput.currentSignature !== undefined &&\n\t\tinput.lastContinuationSignature !== input.currentSignature\n\t);\n}\n\nexport function continuationTurnUsedTools(messages: readonly AgentMessage[]): boolean {\n\treturn messages.some((message) => {\n\t\tif (message?.role === \"toolResult\") return true;\n\t\treturn message?.role === \"assistant\" && message.content.some((content) => content.type === \"toolCall\");\n\t});\n}\n\nfunction isEligibleForGoalContinuation(input: GoalContinuationInput): boolean {\n\tif (input.goal?.status !== \"active\" || input.hasPendingMessages) return false;\n\tif (input.path === \"systemRecovery\" || input.path === \"providerRecovery\") return true;\n\tif (input.path === \"immediate\") {\n\t\treturn input.lastStopReason !== undefined && isContinuableStopReason(input.lastStopReason);\n\t}\n\treturn input.isIdle;\n}\n\n/** Monitor-delayed deliveries are exempt: armed-wake waiting is by-design and rate-limited by the cache-aware timer. */\nfunction isUnattendedBudgetExhausted(input: GoalContinuationInput): boolean {\n\tif (input.path === \"monitorDelayed\") return false;\n\treturn (input.goal?.unattendedContinuations ?? 0) >= GOAL_UNATTENDED_CONTINUATION_LIMIT;\n}\n\nfunction hasRepeatedNormalizedOutputHash(hashes: readonly string[]): boolean {\n\tconst latestHash = hashes.at(-1);\n\tif (latestHash === undefined) return false;\n\n\tlet streak = 0;\n\tfor (let index = hashes.length - 1; index >= 0 && hashes[index] === latestHash; index--) {\n\t\tstreak += 1;\n\t}\n\treturn streak >= GOAL_REPETITION_HASH_STREAK;\n}\n\nfunction shouldShowStallNotice(input: GoalContinuationInput): boolean {\n\treturn input.toollessContinuationStreak >= GOAL_STALL_TOOLLESS_THRESHOLD;\n}\n"]}
|
|
@@ -38,7 +38,7 @@ export class GoalDirectInputLifecycle {
|
|
|
38
38
|
if (currentGoal?.id !== candidate.goalId)
|
|
39
39
|
return;
|
|
40
40
|
if (currentGoal.status === "blocked" && isMechanicalContinuationBlock(currentGoal.blockedReason)) {
|
|
41
|
-
await resetContinuationStreak(ref);
|
|
41
|
+
await resetContinuationStreak(ref, { unattended: true });
|
|
42
42
|
const reactivated = await updateGoal(ref, { status: "active" }, "user");
|
|
43
43
|
this.#dependencies.beginAgentGoalAccounting(reactivated);
|
|
44
44
|
this.#dependencies.refreshGoalUi(ctx, reactivated);
|
|
@@ -46,7 +46,7 @@ export class GoalDirectInputLifecycle {
|
|
|
46
46
|
}
|
|
47
47
|
if (currentGoal.status !== "active")
|
|
48
48
|
return;
|
|
49
|
-
const reset = await resetContinuationStreak(ref);
|
|
49
|
+
const reset = await resetContinuationStreak(ref, { unattended: true });
|
|
50
50
|
if (reset !== null)
|
|
51
51
|
this.#dependencies.refreshGoalUi(ctx, reset);
|
|
52
52
|
if (this.#suppressedLoadResumeArmed) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"direct-input-lifecycle.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/direct-input-lifecycle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAE3E,OAAO,EAAE,QAAQ,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAoB3E,gFAAgF;AAChF,MAAM,OAAO,wBAAwB;IAC3B,aAAa,CAAmC;IAChD,WAAW,GAAG,IAAI,GAAG,EAAgC,CAAC;IAC/D,0BAA0B,GAAG,KAAK,CAAC;IAEnC,YAAY,YAA8C;QACzD,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,KAAK;QACJ,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,0BAA0B,GAAG,KAAK,CAAC;IACzC,CAAC;IAED,iFAAiF;IACjF,uBAAuB;QACtB,IAAI,CAAC,0BAA0B,GAAG,IAAI,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAAiB,EAAE,GAAqB;QACrD,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW;YAAE,OAAO;QAEzC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1D,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;QAClE,IAAI,CAAC,WAAW,CAAC,GAAG,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AAG,KAAK,CAAC;YACxC,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,EAAE,CAAC,GAAG,EAAE,KAAK,IAAI,WAAW,CAAC,CAAC;QACjF,CAAC;IACF,CAAC;CACD","sourcesContent":["import type { ExtensionContext, InputDispositionEvent, InputEvent } from \"../../types.ts\";\nimport { isMechanicalContinuationBlock } from \"./continuation-recovery.ts\";\nimport type { MonitorAwareGoalContinuation } from \"./monitor-continuation.ts\";\nimport { readGoal, resetContinuationStreak, updateGoal } from \"./store.ts\";\nimport type { Goal, GoalStoreRef } from \"./types.ts\";\n\ntype DirectInputCandidate = {\n\treadonly goalId: string | null;\n};\n\ntype DirectInputLifecycleDependencies = {\n\treadonly monitor: MonitorAwareGoalContinuation;\n\treadonly goalStoreRef: (ctx: ExtensionContext) => GoalStoreRef;\n\treadonly beginAgentGoalAccounting: (goal: Goal) => void;\n\treadonly refreshGoalUi: (ctx: ExtensionContext, goal: Goal) => void;\n\t/**\n\t * One-shot resume fired when the first user message after a suppressed\n\t * flooded load is accepted. The load-time suppression notice tells the user\n\t * to \"send a message to resume\"; this callback is what keeps that promise.\n\t */\n\treadonly resumeAfterSuppressedLoad?: (ctx: ExtensionContext, goal: Goal) => Promise<void>;\n};\n\n/** Correlates raw input with admission before changing persisted Goal state. */\nexport class GoalDirectInputLifecycle {\n\treadonly #dependencies: DirectInputLifecycleDependencies;\n\treadonly #candidates = new Map<string, DirectInputCandidate>();\n\t#suppressedLoadResumeArmed = false;\n\n\tconstructor(dependencies: DirectInputLifecycleDependencies) {\n\t\tthis.#dependencies = dependencies;\n\t}\n\n\treset(): void {\n\t\tthis.#candidates.clear();\n\t\tthis.#suppressedLoadResumeArmed = false;\n\t}\n\n\t/** Arms the one-shot resume for a goal parked by load-time flood suppression. */\n\tarmSuppressedLoadResume(): void {\n\t\tthis.#suppressedLoadResumeArmed = true;\n\t}\n\n\tasync onInput(event: InputEvent, ctx: ExtensionContext): Promise<void> {\n\t\tif (event.source === \"extension\") return;\n\n\t\tthis.#dependencies.monitor.holdDirectInput(event.inputId);\n\t\tthis.#candidates.set(event.inputId, { goalId: null });\n\t\tconst goal = await readGoal(this.#dependencies.goalStoreRef(ctx));\n\t\tthis.#candidates.set(event.inputId, { goalId: goal?.id ?? null });\n\t}\n\n\tasync onDisposition(event: InputDispositionEvent, ctx: ExtensionContext): Promise<void> {\n\t\tconst candidate = this.#candidates.get(event.inputId);\n\t\tif (candidate === undefined) return;\n\t\tthis.#candidates.delete(event.inputId);\n\t\tconst accepted = event.disposition === \"started\" || event.disposition === \"queued\";\n\t\tthis.#dependencies.monitor.resolveDirectInput(event.inputId, accepted);\n\t\tif (!accepted || candidate.goalId === null) return;\n\n\t\tconst ref = this.#dependencies.goalStoreRef(ctx);\n\t\tconst currentGoal = await readGoal(ref);\n\t\tif (currentGoal?.id !== candidate.goalId) return;\n\n\t\tif (currentGoal.status === \"blocked\" && isMechanicalContinuationBlock(currentGoal.blockedReason)) {\n\t\t\tawait resetContinuationStreak(ref, { unattended: true });\n\t\t\tconst reactivated = await updateGoal(ref, { status: \"active\" }, \"user\");\n\t\t\tthis.#dependencies.beginAgentGoalAccounting(reactivated);\n\t\t\tthis.#dependencies.refreshGoalUi(ctx, reactivated);\n\t\t\treturn;\n\t\t}\n\n\t\tif (currentGoal.status !== \"active\") return;\n\t\tconst reset = await resetContinuationStreak(ref, { unattended: true });\n\t\tif (reset !== null) this.#dependencies.refreshGoalUi(ctx, reset);\n\t\tif (this.#suppressedLoadResumeArmed) {\n\t\t\tthis.#suppressedLoadResumeArmed = false;\n\t\t\tawait this.#dependencies.resumeAfterSuppressedLoad?.(ctx, reset ?? currentGoal);\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import type { Goal, GoalStatus, GoalToolResponse } from "./types.ts";
|
|
1
|
+
import type { Goal, GoalStatus, GoalToolResponse, GoalToolSnapshot } from "./types.ts";
|
|
2
2
|
export declare function formatGoalElapsedSeconds(value: number): string;
|
|
3
3
|
export declare function formatTokensCompact(value: number): string;
|
|
4
4
|
export declare function goalStatusLabel(status: GoalStatus): string;
|
|
5
5
|
export declare function formatGoalForTool(goal: Goal | null): string;
|
|
6
|
+
export type GoalToolRenderDetails = {
|
|
7
|
+
goal: GoalToolSnapshot | null;
|
|
8
|
+
notice?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function goalToolRenderDetails(goal: Goal | null, notice?: string): GoalToolRenderDetails;
|
|
6
11
|
export declare function goalToolResponse(goal: Goal | null): GoalToolResponse;
|
|
7
12
|
export declare function formatGoalToolResponse(goal: Goal | null, notice?: string): string;
|
|
8
13
|
//# sourceMappingURL=format.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/goal/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEvF,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiB9D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKzD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAW1D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,CAW3D;AAED,MAAM,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,qBAAqB,CAK/F;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,gBAAgB,CAEpE;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAGjF"}
|