@cortexkit/opencode-magic-context 0.25.0 → 0.27.0
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/README.md +14 -12
- package/dist/agents/dreamer.d.ts +19 -0
- package/dist/agents/dreamer.d.ts.map +1 -1
- package/dist/agents/hidden-agent-registrations.d.ts +67 -0
- package/dist/agents/hidden-agent-registrations.d.ts.map +1 -0
- package/dist/agents/historian.d.ts +1 -0
- package/dist/agents/historian.d.ts.map +1 -1
- package/dist/agents/permissions.d.ts +19 -42
- package/dist/agents/permissions.d.ts.map +1 -1
- package/dist/agents/smart-note-compiler.d.ts +2 -0
- package/dist/agents/smart-note-compiler.d.ts.map +1 -0
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/migrate-config-location.d.ts +89 -0
- package/dist/config/migrate-config-location.d.ts.map +1 -0
- package/dist/config/migrate-dreamer-v2.d.ts +37 -0
- package/dist/config/migrate-dreamer-v2.d.ts.map +1 -0
- package/dist/config/migrate-experimental.d.ts.map +1 -1
- package/dist/config/project-security.d.ts +3 -0
- package/dist/config/project-security.d.ts.map +1 -1
- package/dist/config/prune-config-leaf.d.ts.map +1 -1
- package/dist/config/schema/magic-context.d.ts +606 -60
- package/dist/config/schema/magic-context.d.ts.map +1 -1
- package/dist/features/magic-context/compaction-marker.d.ts +9 -3
- package/dist/features/magic-context/compaction-marker.d.ts.map +1 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts +18 -1
- package/dist/features/magic-context/compartment-chunk-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/compartment-embedding.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/classify-prompt.d.ts +50 -0
- package/dist/features/magic-context/dreamer/classify-prompt.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/classify.d.ts +22 -0
- package/dist/features/magic-context/dreamer/classify.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/cron.d.ts +72 -0
- package/dist/features/magic-context/dreamer/cron.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts +30 -0
- package/dist/features/magic-context/dreamer/evaluate-smart-notes.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/index.d.ts +1 -3
- package/dist/features/magic-context/dreamer/index.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/lease.d.ts +44 -6
- package/dist/features/magic-context/dreamer/lease.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/maintain-docs-protected-enforcement.d.ts +13 -0
- package/dist/features/magic-context/dreamer/maintain-docs-protected-enforcement.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts +36 -0
- package/dist/features/magic-context/dreamer/map-memories-prompt.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/map-memories.d.ts +22 -0
- package/dist/features/magic-context/dreamer/map-memories.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/open-opencode-db.d.ts +7 -0
- package/dist/features/magic-context/dreamer/open-opencode-db.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/primer-seed.d.ts +25 -0
- package/dist/features/magic-context/dreamer/primer-seed.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/promote-primers.d.ts +21 -0
- package/dist/features/magic-context/dreamer/promote-primers.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/protected-regions.d.ts +19 -0
- package/dist/features/magic-context/dreamer/protected-regions.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/refresh-primers.d.ts +30 -0
- package/dist/features/magic-context/dreamer/refresh-primers.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/retrospective-learnings.d.ts +47 -0
- package/dist/features/magic-context/dreamer/retrospective-learnings.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/retrospective-orphan-sweep.d.ts +48 -0
- package/dist/features/magic-context/dreamer/retrospective-orphan-sweep.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts +81 -0
- package/dist/features/magic-context/dreamer/retrospective-raw-provider.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts +8 -0
- package/dist/features/magic-context/dreamer/storage-dream-runs.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts +82 -0
- package/dist/features/magic-context/dreamer/storage-task-schedule.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/task-config.d.ts +28 -0
- package/dist/features/magic-context/dreamer/task-config.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/task-executor.d.ts +49 -0
- package/dist/features/magic-context/dreamer/task-executor.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/task-gates.d.ts +29 -0
- package/dist/features/magic-context/dreamer/task-gates.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/task-prompts.d.ts +37 -6
- package/dist/features/magic-context/dreamer/task-prompts.d.ts.map +1 -1
- package/dist/features/magic-context/dreamer/task-registry.d.ts +48 -0
- package/dist/features/magic-context/dreamer/task-registry.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts +88 -0
- package/dist/features/magic-context/dreamer/task-scheduler.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/verify-gate.d.ts +43 -0
- package/dist/features/magic-context/dreamer/verify-gate.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/verify-prompt.d.ts +41 -0
- package/dist/features/magic-context/dreamer/verify-prompt.d.ts.map +1 -0
- package/dist/features/magic-context/dreamer/verify.d.ts +43 -0
- package/dist/features/magic-context/dreamer/verify.d.ts.map +1 -0
- package/dist/features/magic-context/git-commits/search-git-commits.d.ts +2 -0
- package/dist/features/magic-context/git-commits/search-git-commits.d.ts.map +1 -1
- package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts +4 -4
- package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts.map +1 -1
- package/dist/features/magic-context/index.d.ts +1 -0
- package/dist/features/magic-context/index.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-cache.d.ts +2 -2
- package/dist/features/magic-context/memory/embedding-cache.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-identity.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-local.d.ts +3 -3
- package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-openai.d.ts +20 -9
- package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding-provider.d.ts +8 -4
- package/dist/features/magic-context/memory/embedding-provider.d.ts.map +1 -1
- package/dist/features/magic-context/memory/embedding.d.ts +2 -2
- package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
- package/dist/features/magic-context/memory/index.d.ts +4 -1
- package/dist/features/magic-context/memory/index.d.ts.map +1 -1
- package/dist/features/magic-context/memory/memory-migration.d.ts +1 -0
- package/dist/features/magic-context/memory/memory-migration.d.ts.map +1 -1
- package/dist/features/magic-context/memory/promotion.d.ts +16 -4
- package/dist/features/magic-context/memory/promotion.d.ts.map +1 -1
- package/dist/features/magic-context/memory/relocate-memory.d.ts +58 -0
- package/dist/features/magic-context/memory/relocate-memory.d.ts.map +1 -0
- package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts +2 -2
- package/dist/features/magic-context/memory/storage-memory-embeddings.d.ts.map +1 -1
- package/dist/features/magic-context/memory/storage-memory-verifications.d.ts +31 -0
- package/dist/features/magic-context/memory/storage-memory-verifications.d.ts.map +1 -0
- package/dist/features/magic-context/memory/storage-memory.d.ts +12 -1
- package/dist/features/magic-context/memory/storage-memory.d.ts.map +1 -1
- package/dist/features/magic-context/memory/types.d.ts +4 -0
- package/dist/features/magic-context/memory/types.d.ts.map +1 -1
- package/dist/features/magic-context/memory/verification-paths.d.ts +32 -0
- package/dist/features/magic-context/memory/verification-paths.d.ts.map +1 -0
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts.map +1 -1
- package/dist/features/magic-context/overflow-detection.d.ts.map +1 -1
- package/dist/features/magic-context/primer-clustering.d.ts +29 -0
- package/dist/features/magic-context/primer-clustering.d.ts.map +1 -0
- package/dist/features/magic-context/project-embedding-registry.d.ts +28 -4
- package/dist/features/magic-context/project-embedding-registry.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts +12 -2
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/sidekick/agent.d.ts.map +1 -1
- package/dist/features/magic-context/smart-notes/capabilities.d.ts +31 -0
- package/dist/features/magic-context/smart-notes/capabilities.d.ts.map +1 -0
- package/dist/features/magic-context/smart-notes/compiler-prompt.d.ts +2 -0
- package/dist/features/magic-context/smart-notes/compiler-prompt.d.ts.map +1 -0
- package/dist/features/magic-context/smart-notes/compiler.d.ts +52 -0
- package/dist/features/magic-context/smart-notes/compiler.d.ts.map +1 -0
- package/dist/features/magic-context/smart-notes/index.d.ts +10 -0
- package/dist/features/magic-context/smart-notes/index.d.ts.map +1 -0
- package/dist/features/magic-context/smart-notes/runner.d.ts +18 -0
- package/dist/features/magic-context/smart-notes/runner.d.ts.map +1 -0
- package/dist/features/magic-context/smart-notes/sandbox-runner.d.ts +22 -0
- package/dist/features/magic-context/smart-notes/sandbox-runner.d.ts.map +1 -0
- package/dist/features/magic-context/smart-notes/schedule.d.ts +9 -0
- package/dist/features/magic-context/smart-notes/schedule.d.ts.map +1 -0
- package/dist/features/magic-context/smart-notes/ssrf-guard.d.ts +49 -0
- package/dist/features/magic-context/smart-notes/ssrf-guard.d.ts.map +1 -0
- package/dist/features/magic-context/smart-notes/storage.d.ts +27 -0
- package/dist/features/magic-context/smart-notes/storage.d.ts.map +1 -0
- package/dist/features/magic-context/smart-notes/types.d.ts +63 -0
- package/dist/features/magic-context/smart-notes/types.d.ts.map +1 -0
- package/dist/features/magic-context/storage-db.d.ts +6 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +45 -4
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-session.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-shared.d.ts +5 -1
- package/dist/features/magic-context/storage-meta-shared.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta.d.ts +1 -1
- package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
- package/dist/features/magic-context/storage-notes.d.ts +15 -0
- package/dist/features/magic-context/storage-notes.d.ts.map +1 -1
- package/dist/features/magic-context/storage-primers.d.ts +85 -0
- package/dist/features/magic-context/storage-primers.d.ts.map +1 -0
- package/dist/features/magic-context/storage-tags.d.ts +68 -2
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +4 -3
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/features/magic-context/tagger.d.ts +7 -1
- package/dist/features/magic-context/tagger.d.ts.map +1 -1
- package/dist/features/magic-context/tool-owner-backfill.d.ts.map +1 -1
- package/dist/features/magic-context/transform-decision-log.d.ts +59 -0
- package/dist/features/magic-context/transform-decision-log.d.ts.map +1 -0
- package/dist/features/magic-context/types.d.ts +2 -0
- package/dist/features/magic-context/types.d.ts.map +1 -1
- package/dist/features/magic-context/user-memory/review-user-memories.d.ts +5 -0
- package/dist/features/magic-context/user-memory/review-user-memories.d.ts.map +1 -1
- package/dist/features/magic-context/user-memory/storage-user-memory.d.ts +18 -0
- package/dist/features/magic-context/user-memory/storage-user-memory.d.ts.map +1 -1
- package/dist/features/magic-context/v22-deferred-backfill.d.ts.map +1 -1
- package/dist/hooks/auto-update-checker/semver.d.ts +9 -0
- package/dist/hooks/auto-update-checker/semver.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-hint.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/command-handler.d.ts +8 -15
- package/dist/hooks/magic-context/command-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/compaction-marker-manager.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-parser.d.ts +9 -0
- package/dist/hooks/magic-context/compartment-parser.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-prompt.d.ts +4 -1
- package/dist/hooks/magic-context/compartment-prompt.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts +1 -0
- package/dist/hooks/magic-context/compartment-runner-historian.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-partial-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-recomp.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-types.d.ts +8 -0
- package/dist/hooks/magic-context/compartment-runner-types.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-validation.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts +1 -1
- package/dist/hooks/magic-context/compartment-trigger.d.ts.map +1 -1
- package/dist/hooks/magic-context/ctx-reduce-nudge.d.ts.map +1 -1
- package/dist/hooks/magic-context/derive-budgets.d.ts +5 -9
- package/dist/hooks/magic-context/derive-budgets.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-payloads.d.ts +1 -0
- package/dist/hooks/magic-context/event-payloads.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
- package/dist/hooks/magic-context/heuristic-cleanup.d.ts +1 -0
- package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-prompt.generated.d.ts +1 -1
- package/dist/hooks/magic-context/historian-prompt.generated.d.ts.map +1 -1
- package/dist/hooks/magic-context/historian-state-file.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts +2 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts +1 -0
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +0 -3
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts +10 -0
- package/dist/hooks/magic-context/protected-tail-boundary.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/send-session-notification.d.ts +2 -0
- package/dist/hooks/magic-context/send-session-notification.d.ts.map +1 -1
- package/dist/hooks/magic-context/system-prompt-hash.d.ts +17 -0
- package/dist/hooks/magic-context/system-prompt-hash.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-id-fallback.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts +10 -0
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts +32 -1
- package/dist/hooks/magic-context/transform-compartment-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +14 -5
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts +0 -2
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17664 -4236
- package/dist/plugin/dream-timer.d.ts +17 -9
- package/dist/plugin/dream-timer.d.ts.map +1 -1
- package/dist/plugin/embedding-bootstrap-helpers.d.ts +1 -1
- package/dist/plugin/embedding-bootstrap-helpers.d.ts.map +1 -1
- package/dist/plugin/embedding-bootstrap.d.ts.map +1 -1
- package/dist/plugin/hooks/create-session-hooks.d.ts +211 -0
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/instance-disposal.d.ts +2 -0
- package/dist/plugin/instance-disposal.d.ts.map +1 -0
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/shared/announcement.d.ts +1 -1
- package/dist/shared/announcement.d.ts.map +1 -1
- package/dist/shared/data-path.d.ts +26 -7
- package/dist/shared/data-path.d.ts.map +1 -1
- package/dist/shared/index.d.ts +0 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/model-suggestion-retry.d.ts +48 -2
- package/dist/shared/model-suggestion-retry.d.ts.map +1 -1
- package/dist/shared/redaction.d.ts +7 -0
- package/dist/shared/redaction.d.ts.map +1 -0
- package/dist/shared/resolve-fallbacks.d.ts +28 -16
- package/dist/shared/resolve-fallbacks.d.ts.map +1 -1
- package/dist/shared/rpc-server.d.ts.map +1 -1
- package/dist/shared/rpc-types.d.ts +2 -0
- package/dist/shared/rpc-types.d.ts.map +1 -1
- package/dist/shared/subagent-runner.d.ts +12 -3
- package/dist/shared/subagent-runner.d.ts.map +1 -1
- package/dist/shared/tui-config.d.ts.map +1 -1
- package/dist/tools/ctx-memory/tools.d.ts.map +1 -1
- package/dist/tools/ctx-memory/types.d.ts.map +1 -1
- package/dist/tools/ctx-memory/verification-recording.d.ts +8 -0
- package/dist/tools/ctx-memory/verification-recording.d.ts.map +1 -0
- package/dist/tools/ctx-search/tools.d.ts.map +1 -1
- package/dist/tools/ctx-search/types.d.ts +1 -1
- package/dist/tools/ctx-search/types.d.ts.map +1 -1
- package/dist/tui/data/context-db.d.ts +2 -0
- package/dist/tui/data/context-db.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/shared/announcement.test.ts +20 -0
- package/src/shared/announcement.ts +19 -7
- package/src/shared/data-path.test.ts +70 -6
- package/src/shared/data-path.ts +50 -8
- package/src/shared/index.ts +0 -1
- package/src/shared/model-suggestion-retry.test.ts +79 -2
- package/src/shared/model-suggestion-retry.ts +181 -3
- package/src/shared/redaction.test.ts +48 -0
- package/src/shared/redaction.ts +240 -0
- package/src/shared/resolve-fallbacks.test.ts +37 -71
- package/src/shared/resolve-fallbacks.ts +30 -26
- package/src/shared/rpc-server.ts +24 -0
- package/src/shared/rpc-types.ts +2 -0
- package/src/shared/subagent-runner.ts +12 -3
- package/src/shared/tui-config.test.ts +63 -0
- package/src/shared/tui-config.ts +67 -39
- package/src/tui/data/context-db.ts +12 -0
- package/src/tui/index.tsx +87 -17
- package/src/tui/slots/sidebar-content.tsx +15 -7
- package/dist/features/magic-context/dreamer/queue.d.ts +0 -55
- package/dist/features/magic-context/dreamer/queue.d.ts.map +0 -1
- package/dist/features/magic-context/dreamer/runner.d.ts +0 -92
- package/dist/features/magic-context/dreamer/runner.d.ts.map +0 -1
- package/dist/features/magic-context/dreamer/scheduler.d.ts +0 -29
- package/dist/features/magic-context/dreamer/scheduler.d.ts.map +0 -1
- package/dist/features/magic-context/key-files/aft-availability.d.ts +0 -11
- package/dist/features/magic-context/key-files/aft-availability.d.ts.map +0 -1
- package/dist/features/magic-context/key-files/identify-key-files.d.ts +0 -84
- package/dist/features/magic-context/key-files/identify-key-files.d.ts.map +0 -1
- package/dist/features/magic-context/key-files/project-key-files.d.ts +0 -42
- package/dist/features/magic-context/key-files/project-key-files.d.ts.map +0 -1
- package/dist/features/magic-context/key-files/read-history.d.ts +0 -26
- package/dist/features/magic-context/key-files/read-history.d.ts.map +0 -1
- package/dist/features/magic-context/key-files/read-stats.d.ts +0 -18
- package/dist/features/magic-context/key-files/read-stats.d.ts.map +0 -1
- package/dist/features/magic-context/key-files/storage-key-files.d.ts +0 -20
- package/dist/features/magic-context/key-files/storage-key-files.d.ts.map +0 -1
- package/dist/hooks/magic-context/key-files-block.d.ts +0 -27
- package/dist/hooks/magic-context/key-files-block.d.ts.map +0 -1
- package/dist/shared/model-requirements.d.ts +0 -26
- package/dist/shared/model-requirements.d.ts.map +0 -1
- package/src/shared/model-requirements.ts +0 -86
|
@@ -6,18 +6,36 @@ import { parseProviderModel } from "./resolve-fallbacks";
|
|
|
6
6
|
|
|
7
7
|
type Client = ReturnType<typeof createOpencodeClient>;
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
/** Max time to wait for the best-effort child-session abort HTTP call before
|
|
10
|
+
* giving up on its response (the abort still proceeds server-side). Keeps a
|
|
11
|
+
* wedged abort endpoint from masking the original timeout/abort error. */
|
|
12
|
+
const ABORT_CALL_TIMEOUT_MS = 3000;
|
|
13
|
+
|
|
14
|
+
export type PromptBody = {
|
|
10
15
|
model?: { providerID: string; modelID: string };
|
|
11
16
|
[key: string]: unknown;
|
|
12
17
|
};
|
|
13
18
|
|
|
14
|
-
type PromptArgs = {
|
|
19
|
+
export type PromptArgs = {
|
|
15
20
|
path: { id: string };
|
|
16
21
|
body: PromptBody;
|
|
17
22
|
signal?: AbortSignal;
|
|
18
23
|
[key: string]: unknown;
|
|
19
24
|
};
|
|
20
25
|
|
|
26
|
+
export interface PromptAttemptInfo {
|
|
27
|
+
/** Human-readable model label used in logs ("primary" or "provider/model"). */
|
|
28
|
+
label: string;
|
|
29
|
+
/** Zero-based attempt index: 0 is primary, 1+ are fallback models. */
|
|
30
|
+
attemptIndex: number;
|
|
31
|
+
/** True for configured fallback models, false for the primary attempt. */
|
|
32
|
+
isFallback: boolean;
|
|
33
|
+
/** Total attempted models including the primary and all configured fallbacks. */
|
|
34
|
+
totalAttempts: number;
|
|
35
|
+
/** Explicit model override for this attempt, when one was supplied. */
|
|
36
|
+
model?: { providerID: string; modelID: string };
|
|
37
|
+
}
|
|
38
|
+
|
|
21
39
|
export interface PromptRetryOptions {
|
|
22
40
|
timeoutMs?: number;
|
|
23
41
|
/** External abort signal — cancels the in-flight LLM prompt immediately when aborted */
|
|
@@ -47,6 +65,29 @@ export interface PromptRetryOptions {
|
|
|
47
65
|
callContext?: string;
|
|
48
66
|
}
|
|
49
67
|
|
|
68
|
+
export interface ValidatedPromptRetryOptions<TOutput, TValidated> extends PromptRetryOptions {
|
|
69
|
+
/**
|
|
70
|
+
* Fetch the output produced by the just-completed prompt attempt. This is
|
|
71
|
+
* intentionally caller-owned because OpenCode exposes results via session
|
|
72
|
+
* messages and each caller validates a different shape.
|
|
73
|
+
*/
|
|
74
|
+
fetchOutput: (args: PromptArgs, attempt: PromptAttemptInfo) => Promise<TOutput>;
|
|
75
|
+
/**
|
|
76
|
+
* Validate and optionally transform the fetched output. Throw to reject this
|
|
77
|
+
* model's output and advance to the next configured fallback model.
|
|
78
|
+
*/
|
|
79
|
+
validateOutput: (
|
|
80
|
+
output: TOutput,
|
|
81
|
+
attempt: PromptAttemptInfo,
|
|
82
|
+
) => TValidated | Promise<TValidated>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface ValidatedPromptRetryResult<TOutput, TValidated> {
|
|
86
|
+
output: TOutput;
|
|
87
|
+
validated: TValidated;
|
|
88
|
+
attempt: PromptAttemptInfo;
|
|
89
|
+
}
|
|
90
|
+
|
|
50
91
|
export interface ModelSuggestionInfo {
|
|
51
92
|
providerID: string;
|
|
52
93
|
modelID: string;
|
|
@@ -171,7 +212,15 @@ async function promptWithTimeout(
|
|
|
171
212
|
*/
|
|
172
213
|
async function abortChildRun(client: Client, sessionId: string): Promise<void> {
|
|
173
214
|
try {
|
|
174
|
-
|
|
215
|
+
// Bound the abort call: it's best-effort cleanup, and if the abort
|
|
216
|
+
// endpoint itself stalls (the runner is wedged) an unbounded await here
|
|
217
|
+
// would hang the caller and MASK the original timeout/abort error that we
|
|
218
|
+
// still need to surface. Race against a short timer; the abort keeps
|
|
219
|
+
// running server-side regardless of whether we wait for its response.
|
|
220
|
+
await Promise.race([
|
|
221
|
+
client.session.abort({ path: { id: sessionId } }),
|
|
222
|
+
new Promise<void>((resolve) => setTimeout(resolve, ABORT_CALL_TIMEOUT_MS)),
|
|
223
|
+
]);
|
|
175
224
|
} catch (error) {
|
|
176
225
|
log(`[model-retry] child session abort failed for ${sessionId}: ${String(error)}`);
|
|
177
226
|
}
|
|
@@ -368,3 +417,132 @@ export async function promptSyncWithModelSuggestionRetry(
|
|
|
368
417
|
);
|
|
369
418
|
throw lastError ?? new Error("All fallback models failed");
|
|
370
419
|
}
|
|
420
|
+
|
|
421
|
+
async function attemptAndValidate<TOutput, TValidated>(
|
|
422
|
+
client: Client,
|
|
423
|
+
args: PromptArgs,
|
|
424
|
+
timeoutMs: number,
|
|
425
|
+
signal: AbortSignal | undefined,
|
|
426
|
+
callContext: string,
|
|
427
|
+
attempt: PromptAttemptInfo,
|
|
428
|
+
options: ValidatedPromptRetryOptions<TOutput, TValidated>,
|
|
429
|
+
): Promise<ValidatedPromptRetryResult<TOutput, TValidated>> {
|
|
430
|
+
await attemptOnce(client, args, timeoutMs, signal, callContext, attempt.label);
|
|
431
|
+
const output = await options.fetchOutput(args, attempt);
|
|
432
|
+
const validated = await options.validateOutput(output, attempt);
|
|
433
|
+
return { output, validated, attempt };
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Run a prompt with model fallback support, but accept an attempt only after the
|
|
438
|
+
* caller validates the model's actual output. This covers "empty success" cases
|
|
439
|
+
* where the provider/OpenCode prompt call completes successfully but the subagent
|
|
440
|
+
* produced no usable assistant text / JSON.
|
|
441
|
+
*
|
|
442
|
+
* The happy path is still one prompt + one caller-owned output fetch: callers
|
|
443
|
+
* should use the returned output instead of fetching messages a second time.
|
|
444
|
+
* Validation failures are retryable across configured fallback models. If every
|
|
445
|
+
* attempt produces invalid output (or otherwise fails retryably), the first
|
|
446
|
+
* failure is re-thrown so callers surface the original failure semantics.
|
|
447
|
+
*/
|
|
448
|
+
export async function promptSyncWithValidatedOutputRetry<TOutput, TValidated = TOutput>(
|
|
449
|
+
client: Client,
|
|
450
|
+
args: PromptArgs,
|
|
451
|
+
options: ValidatedPromptRetryOptions<TOutput, TValidated>,
|
|
452
|
+
): Promise<ValidatedPromptRetryResult<TOutput, TValidated>> {
|
|
453
|
+
const timeoutMs = options.timeoutMs ?? 300_000;
|
|
454
|
+
const callContext = options.callContext ?? "subagent";
|
|
455
|
+
const fallbacks = options.fallbackModels ?? [];
|
|
456
|
+
|
|
457
|
+
const explicitPrimaryLabel =
|
|
458
|
+
args.body.model?.providerID && args.body.model.modelID
|
|
459
|
+
? `${args.body.model.providerID}/${args.body.model.modelID}`
|
|
460
|
+
: "primary";
|
|
461
|
+
const totalAttempts = fallbacks.length + 1;
|
|
462
|
+
|
|
463
|
+
let firstError: unknown = null;
|
|
464
|
+
let lastError: unknown = null;
|
|
465
|
+
|
|
466
|
+
try {
|
|
467
|
+
return await attemptAndValidate(
|
|
468
|
+
client,
|
|
469
|
+
args,
|
|
470
|
+
timeoutMs,
|
|
471
|
+
options.signal,
|
|
472
|
+
callContext,
|
|
473
|
+
{
|
|
474
|
+
label: explicitPrimaryLabel,
|
|
475
|
+
attemptIndex: 0,
|
|
476
|
+
isFallback: false,
|
|
477
|
+
totalAttempts,
|
|
478
|
+
model: args.body.model,
|
|
479
|
+
},
|
|
480
|
+
options,
|
|
481
|
+
);
|
|
482
|
+
} catch (error) {
|
|
483
|
+
firstError = error;
|
|
484
|
+
lastError = error;
|
|
485
|
+
if (isNonRetryable(error, options.signal)) throw error;
|
|
486
|
+
|
|
487
|
+
if (fallbacks.length === 0) {
|
|
488
|
+
throw error;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
log(
|
|
492
|
+
`[${callContext}] primary (${explicitPrimaryLabel}) failed validation/prompt: ${shortErr(error)}; trying ${fallbacks.length} fallback(s)`,
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
for (let i = 0; i < fallbacks.length; i += 1) {
|
|
497
|
+
const parsed = parseProviderModel(fallbacks[i]);
|
|
498
|
+
if (!parsed) {
|
|
499
|
+
log(`[${callContext}] skipping invalid fallback spec: ${fallbacks[i]}`);
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
const label = `${parsed.providerID}/${parsed.modelID}`;
|
|
504
|
+
const attemptArgs: PromptArgs = {
|
|
505
|
+
...args,
|
|
506
|
+
body: { ...args.body, model: parsed },
|
|
507
|
+
};
|
|
508
|
+
const attempt: PromptAttemptInfo = {
|
|
509
|
+
label,
|
|
510
|
+
attemptIndex: i + 1,
|
|
511
|
+
isFallback: true,
|
|
512
|
+
totalAttempts,
|
|
513
|
+
model: parsed,
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
try {
|
|
517
|
+
const result = await attemptAndValidate(
|
|
518
|
+
client,
|
|
519
|
+
attemptArgs,
|
|
520
|
+
timeoutMs,
|
|
521
|
+
options.signal,
|
|
522
|
+
callContext,
|
|
523
|
+
attempt,
|
|
524
|
+
options,
|
|
525
|
+
);
|
|
526
|
+
log(
|
|
527
|
+
`[${callContext}] fallback succeeded with ${label} (attempt ${i + 2}/${fallbacks.length + 1})`,
|
|
528
|
+
);
|
|
529
|
+
return result;
|
|
530
|
+
} catch (error) {
|
|
531
|
+
if (firstError === null) firstError = error;
|
|
532
|
+
lastError = error;
|
|
533
|
+
if (isNonRetryable(error, options.signal)) throw error;
|
|
534
|
+
|
|
535
|
+
const remaining = fallbacks.length - i - 1;
|
|
536
|
+
if (remaining > 0) {
|
|
537
|
+
log(
|
|
538
|
+
`[${callContext}] ${label} failed validation/prompt: ${shortErr(error)}; ${remaining} fallback(s) left`,
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
log(
|
|
545
|
+
`[${callContext}] all models exhausted; tried: ${[explicitPrimaryLabel, ...fallbacks].join(", ")}; original error: ${shortErr(firstError)}; last error: ${shortErr(lastError)}`,
|
|
546
|
+
);
|
|
547
|
+
throw firstError ?? lastError ?? new Error("All fallback models failed validation");
|
|
548
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/// <reference types="bun-types" />
|
|
2
|
+
|
|
3
|
+
import { describe, expect, test } from "bun:test";
|
|
4
|
+
|
|
5
|
+
import { hasShareabilitySensitiveText } from "./redaction";
|
|
6
|
+
|
|
7
|
+
describe("hasShareabilitySensitiveText", () => {
|
|
8
|
+
test("safe project facts are shareable", () => {
|
|
9
|
+
expect(
|
|
10
|
+
hasShareabilitySensitiveText(
|
|
11
|
+
"The historian runs as a hidden subagent and never busts the prompt cache.",
|
|
12
|
+
),
|
|
13
|
+
).toBe(false);
|
|
14
|
+
expect(
|
|
15
|
+
hasShareabilitySensitiveText("Migration v45 adds the retrospective watermark column."),
|
|
16
|
+
).toBe(false);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("flags inline key:value / key=value secrets the keyed redactor misses in prose", () => {
|
|
20
|
+
expect(hasShareabilitySensitiveText("Set api_key: sk-live-abc123 in the env.")).toBe(true);
|
|
21
|
+
expect(hasShareabilitySensitiveText("password=hunter2 for the staging box")).toBe(true);
|
|
22
|
+
expect(hasShareabilitySensitiveText("client_secret = abcdef in the OAuth app")).toBe(true);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("flags Windows forward-slash home (sanitizePathString only rewrites backslash form)", () => {
|
|
26
|
+
expect(hasShareabilitySensitiveText("logs are under C:/Users/ufuk/AppData/mc")).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("flags ~/ rooted personal paths", () => {
|
|
30
|
+
expect(hasShareabilitySensitiveText("config lives at ~/.config/opencode/x.jsonc")).toBe(
|
|
31
|
+
true,
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("flags local / private endpoints", () => {
|
|
36
|
+
expect(hasShareabilitySensitiveText("embed endpoint is http://localhost:1234/v1")).toBe(
|
|
37
|
+
true,
|
|
38
|
+
);
|
|
39
|
+
expect(hasShareabilitySensitiveText("the box answers on 127.0.0.1:8080")).toBe(true);
|
|
40
|
+
expect(hasShareabilitySensitiveText("LAN host 192.168.1.42 runs the model")).toBe(true);
|
|
41
|
+
expect(hasShareabilitySensitiveText("internal 10.0.0.5 endpoint")).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("a public IP / port alone is not flagged by the private-range rules", () => {
|
|
45
|
+
// 8.8.8.8 is public; no private-range or localhost pattern should match.
|
|
46
|
+
expect(hasShareabilitySensitiveText("DNS resolver at 8.8.8.8")).toBe(false);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { homedir, userInfo } from "node:os";
|
|
2
|
+
|
|
3
|
+
function escapeRegex(value: string): string {
|
|
4
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
// Whole-segment match: the key (or its components when split on common
|
|
8
|
+
// separators) must BE one of these words, not merely contain them as a
|
|
9
|
+
// substring. Bare substring matching wrongly redacts benign fields like
|
|
10
|
+
// `pin_key_files`, `token_budget`, and `injection_budget_tokens`.
|
|
11
|
+
const SECRET_WORDS = [
|
|
12
|
+
"key",
|
|
13
|
+
"token",
|
|
14
|
+
"secret",
|
|
15
|
+
"password",
|
|
16
|
+
"auth",
|
|
17
|
+
"authorization",
|
|
18
|
+
"bearer",
|
|
19
|
+
"credential",
|
|
20
|
+
];
|
|
21
|
+
const SECRET_SEGMENT_PATTERN = new RegExp(
|
|
22
|
+
`^(?:${SECRET_WORDS.map((w) => `${w}s?`).join("|")})$`,
|
|
23
|
+
"i",
|
|
24
|
+
);
|
|
25
|
+
const TRAILING_DESCRIPTORS = new Set(["id", "ids", "value", "values", "header", "headers"]);
|
|
26
|
+
|
|
27
|
+
function redactionTypeForKey(key: string): string {
|
|
28
|
+
const normalized = key
|
|
29
|
+
.trim()
|
|
30
|
+
.toLowerCase()
|
|
31
|
+
.replace(/[^a-z0-9_.-]+/g, "_");
|
|
32
|
+
const suffix = normalized.split(".").filter(Boolean).at(-1) ?? normalized;
|
|
33
|
+
return suffix || "secret";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const SECRET_QUALIFIERS = new Set([
|
|
37
|
+
"api",
|
|
38
|
+
"access",
|
|
39
|
+
"private",
|
|
40
|
+
"client",
|
|
41
|
+
"auth",
|
|
42
|
+
"authorization",
|
|
43
|
+
"secret",
|
|
44
|
+
"bearer",
|
|
45
|
+
"session",
|
|
46
|
+
"refresh",
|
|
47
|
+
"service",
|
|
48
|
+
"x",
|
|
49
|
+
"openai",
|
|
50
|
+
"anthropic",
|
|
51
|
+
"google",
|
|
52
|
+
"github",
|
|
53
|
+
"huggingface",
|
|
54
|
+
"aws",
|
|
55
|
+
"azure",
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
export function isSecretKey(key: string): boolean {
|
|
59
|
+
const segments = key
|
|
60
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1_$2")
|
|
61
|
+
.toLowerCase()
|
|
62
|
+
.split(/[._-]+/)
|
|
63
|
+
.filter(Boolean);
|
|
64
|
+
if (segments.length === 0) return false;
|
|
65
|
+
|
|
66
|
+
if (segments.length === 1) {
|
|
67
|
+
const first = segments[0];
|
|
68
|
+
return Boolean(first && SECRET_SEGMENT_PATTERN.test(first));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
for (let i = 0; i < segments.length; i++) {
|
|
72
|
+
const seg = segments[i];
|
|
73
|
+
if (!seg || !SECRET_SEGMENT_PATTERN.test(seg)) continue;
|
|
74
|
+
|
|
75
|
+
let trailingOk = true;
|
|
76
|
+
for (let j = i + 1; j < segments.length; j++) {
|
|
77
|
+
const tail = segments[j];
|
|
78
|
+
if (!tail) continue;
|
|
79
|
+
if (TRAILING_DESCRIPTORS.has(tail)) continue;
|
|
80
|
+
if (SECRET_SEGMENT_PATTERN.test(tail)) continue;
|
|
81
|
+
trailingOk = false;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
if (!trailingOk) continue;
|
|
85
|
+
|
|
86
|
+
for (let k = i - 1; k >= 0; k--) {
|
|
87
|
+
const lead = segments[k];
|
|
88
|
+
if (lead && SECRET_QUALIFIERS.has(lead)) return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function sanitizePathString(value: string): string {
|
|
95
|
+
const home = homedir();
|
|
96
|
+
const username = userInfo().username;
|
|
97
|
+
let sanitized = value;
|
|
98
|
+
if (home) {
|
|
99
|
+
sanitized = sanitized.replace(new RegExp(escapeRegex(home), "g"), "~");
|
|
100
|
+
}
|
|
101
|
+
sanitized = sanitized.replace(/\/Users\/[^/]+\//g, "/Users/<USER>/");
|
|
102
|
+
sanitized = sanitized.replace(/\/home\/[^/]+\//g, "/home/<USER>/");
|
|
103
|
+
sanitized = sanitized.replace(/C:\\Users\\[^\\]+\\/g, "C:\\Users\\<USER>\\");
|
|
104
|
+
if (username) {
|
|
105
|
+
sanitized = sanitized.replace(new RegExp(escapeRegex(username), "g"), "<USER>");
|
|
106
|
+
}
|
|
107
|
+
return sanitized;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const SECRET_TEXT_PATTERNS: Array<{
|
|
111
|
+
pattern: RegExp;
|
|
112
|
+
replacement: string | ((match: string, ...groups: string[]) => string);
|
|
113
|
+
}> = [
|
|
114
|
+
{
|
|
115
|
+
pattern: /\bsk-ant-(?:api03-)?[A-Za-z0-9_-]{32,}/g,
|
|
116
|
+
replacement: "<ANTHROPIC_API_KEY_REDACTED>",
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
pattern: /\bsk-(?:proj-)?[A-Za-z0-9_-]{32,}/g,
|
|
120
|
+
replacement: "<OPENAI_API_KEY_REDACTED>",
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
pattern: /\bgithub_pat_[A-Za-z0-9_]{20,}/g,
|
|
124
|
+
replacement: "<GITHUB_PAT_REDACTED>",
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
pattern: /\b(?:gh[opsu]|ghr)_[A-Za-z0-9]{30,}/g,
|
|
128
|
+
replacement: "<GITHUB_TOKEN_REDACTED>",
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
pattern: /\bhf_[A-Za-z0-9]{30,}/g,
|
|
132
|
+
replacement: "<HUGGINGFACE_TOKEN_REDACTED>",
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
pattern: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,
|
|
136
|
+
replacement: "<AWS_ACCESS_KEY_ID_REDACTED>",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
pattern: /\bxox[abprsuvc]-[A-Za-z0-9-]{10,}/g,
|
|
140
|
+
replacement: "<SLACK_TOKEN_REDACTED>",
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
pattern: /\bAIza[A-Za-z0-9_-]{35}\b/g,
|
|
144
|
+
replacement: "<GOOGLE_API_KEY_REDACTED>",
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
pattern: /\b(Authorization\s*:\s*Bearer\s+)([A-Za-z0-9._~+/=-]{8,})/gi,
|
|
148
|
+
replacement: (_full: string, prefix: string) => `${prefix}<REDACTED:bearer>`,
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
pattern: /\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,
|
|
152
|
+
replacement: "<JWT_REDACTED>",
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
pattern:
|
|
156
|
+
/(["'])([^"']*(?:key|token|secret|password|auth|bearer|credential)[^"']*)\1(\s*:\s*)(["'])([^"']*)\4/gi,
|
|
157
|
+
replacement: (
|
|
158
|
+
_full: string,
|
|
159
|
+
quote: string,
|
|
160
|
+
key: string,
|
|
161
|
+
separator: string,
|
|
162
|
+
valueQuote: string,
|
|
163
|
+
) =>
|
|
164
|
+
`${quote}${key}${quote}${separator}${valueQuote}<REDACTED:${redactionTypeForKey(key)}>${valueQuote}`,
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
pattern:
|
|
168
|
+
/\b([A-Za-z0-9_.-]*(?:key|token|secret|password|auth|bearer|credential)[A-Za-z0-9_.-]*)\s*=\s*([^\s'"`]+)/gi,
|
|
169
|
+
replacement: (_full: string, key: string) =>
|
|
170
|
+
`${key}=<REDACTED:${redactionTypeForKey(key)}>`,
|
|
171
|
+
},
|
|
172
|
+
];
|
|
173
|
+
|
|
174
|
+
export function redactSecretText(value: string): string {
|
|
175
|
+
let redacted = value;
|
|
176
|
+
for (const { pattern, replacement } of SECRET_TEXT_PATTERNS) {
|
|
177
|
+
if (typeof replacement === "string") {
|
|
178
|
+
redacted = redacted.replace(pattern, replacement);
|
|
179
|
+
} else {
|
|
180
|
+
redacted = redacted.replace(
|
|
181
|
+
pattern,
|
|
182
|
+
replacement as (match: string, ...groups: string[]) => string,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return redacted;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function sanitizeDiagnosticText(value: string): string {
|
|
190
|
+
return redactSecretText(sanitizePathString(value));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Extra shareability-only signals — patterns that mark text as unsafe to share
|
|
194
|
+
// with teammates but that the diagnostic sanitizer (tuned for secret/path
|
|
195
|
+
// REDACTION, not share-gating) does not rewrite. Kept here, NOT in
|
|
196
|
+
// sanitizeDiagnosticText, so diagnostic redaction output is unchanged.
|
|
197
|
+
const SHAREABILITY_SENSITIVE_PATTERNS: RegExp[] = [
|
|
198
|
+
// Windows user home, forward- OR back-slash (sanitizePathString only rewrites
|
|
199
|
+
// the backslash form).
|
|
200
|
+
/\bC:\/Users\/[^/\s]+/i,
|
|
201
|
+
// A `~`-rooted home path (personal/local).
|
|
202
|
+
/(?:^|\s)~\/[^\s]+/,
|
|
203
|
+
// Inline `key: value` / `key=value` secrets the keyed redactor misses in free
|
|
204
|
+
// text (it keys on config OBJECT keys, not prose).
|
|
205
|
+
/\b(?:api[_-]?key|secret|token|password|passwd|pwd|client[_-]?secret|access[_-]?key)\b\s*[:=]\s*\S+/i,
|
|
206
|
+
// Local / private endpoints — environment-specific, not a shared truth.
|
|
207
|
+
/\b(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(?::\d+)?\b/i,
|
|
208
|
+
/\b(?:10|127)\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/,
|
|
209
|
+
/\b192\.168\.\d{1,3}\.\d{1,3}\b/,
|
|
210
|
+
/\b172\.(?:1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3}\b/,
|
|
211
|
+
];
|
|
212
|
+
|
|
213
|
+
export function hasShareabilitySensitiveText(text: string): boolean {
|
|
214
|
+
try {
|
|
215
|
+
if (sanitizeDiagnosticText(text) !== text) return true;
|
|
216
|
+
return SHAREABILITY_SENSITIVE_PATTERNS.some((pattern) => pattern.test(text));
|
|
217
|
+
} catch {
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function sanitizeConfigValue(value: unknown, keyPath: string[] = []): unknown {
|
|
223
|
+
const key = keyPath.at(-1) ?? "";
|
|
224
|
+
if (key && isSecretKey(key)) {
|
|
225
|
+
return `<REDACTED:${redactionTypeForKey(key)}>`;
|
|
226
|
+
}
|
|
227
|
+
if (typeof value === "string") return sanitizeDiagnosticText(value);
|
|
228
|
+
if (Array.isArray(value)) {
|
|
229
|
+
return value.map((entry, index) => sanitizeConfigValue(entry, [...keyPath, String(index)]));
|
|
230
|
+
}
|
|
231
|
+
if (value && typeof value === "object") {
|
|
232
|
+
return Object.fromEntries(
|
|
233
|
+
Object.entries(value).map(([entryKey, entry]) => [
|
|
234
|
+
entryKey,
|
|
235
|
+
sanitizeConfigValue(entry, [...keyPath, entryKey]),
|
|
236
|
+
]),
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
return value;
|
|
240
|
+
}
|
|
@@ -1,98 +1,64 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
|
|
3
|
-
import { DREAMER_AGENT } from "../agents/dreamer";
|
|
4
|
-
import { HISTORIAN_AGENT } from "../agents/historian";
|
|
5
|
-
import { SIDEKICK_AGENT } from "../agents/sidekick";
|
|
6
3
|
import { parseProviderModel, resolveFallbackChain } from "./resolve-fallbacks";
|
|
7
4
|
|
|
8
5
|
describe("resolveFallbackChain", () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
6
|
+
// Policy: user-config-only. There is NO builtin provider-agnostic chain —
|
|
7
|
+
// when the user configures no fallback_models the result is EMPTY, and the
|
|
8
|
+
// runner's session-model last resort (a model the user actually has) is the
|
|
9
|
+
// only fallback. A hardcoded chain named providers the user may not have and
|
|
10
|
+
// produced `Model not found` retry storms.
|
|
11
|
+
test("returns empty when user provides nothing (no builtin chain)", () => {
|
|
12
|
+
expect(resolveFallbackChain(undefined)).toEqual([]);
|
|
17
13
|
});
|
|
18
14
|
|
|
19
|
-
test("returns
|
|
20
|
-
|
|
21
|
-
expect(chain.length).toBeGreaterThan(0);
|
|
15
|
+
test("returns empty for empty string", () => {
|
|
16
|
+
expect(resolveFallbackChain("")).toEqual([]);
|
|
22
17
|
});
|
|
23
18
|
|
|
24
|
-
test("returns
|
|
25
|
-
|
|
26
|
-
expect(chain.length).toBeGreaterThan(0);
|
|
19
|
+
test("returns empty for empty array", () => {
|
|
20
|
+
expect(resolveFallbackChain([])).toEqual([]);
|
|
27
21
|
});
|
|
28
22
|
|
|
29
23
|
test("user-only when user provides valid fallback_models string", () => {
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
expect(resolveFallbackChain("anthropic/claude-sonnet-4-6")).toEqual([
|
|
25
|
+
"anthropic/claude-sonnet-4-6",
|
|
26
|
+
]);
|
|
32
27
|
});
|
|
33
28
|
|
|
34
29
|
test("user-only when user provides valid fallback_models array", () => {
|
|
35
|
-
|
|
36
|
-
"anthropic/claude-sonnet-4-6",
|
|
37
|
-
|
|
38
|
-
]);
|
|
39
|
-
expect(chain).toEqual(["anthropic/claude-sonnet-4-6", "google/gemini-3-flash"]);
|
|
30
|
+
expect(
|
|
31
|
+
resolveFallbackChain(["anthropic/claude-sonnet-4-6", "google/gemini-3-flash"]),
|
|
32
|
+
).toEqual(["anthropic/claude-sonnet-4-6", "google/gemini-3-flash"]);
|
|
40
33
|
});
|
|
41
34
|
|
|
42
35
|
test("dedupes user-provided list", () => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
expect(
|
|
37
|
+
resolveFallbackChain([
|
|
38
|
+
"anthropic/claude-sonnet-4-6",
|
|
39
|
+
"anthropic/claude-sonnet-4-6",
|
|
40
|
+
"google/gemini-3-flash",
|
|
41
|
+
]),
|
|
42
|
+
).toEqual(["anthropic/claude-sonnet-4-6", "google/gemini-3-flash"]);
|
|
49
43
|
});
|
|
50
44
|
|
|
51
45
|
test("strips invalid 'provider/model' entries", () => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
expect(
|
|
47
|
+
resolveFallbackChain([
|
|
48
|
+
"anthropic/claude-sonnet-4-6",
|
|
49
|
+
"no-slash-here",
|
|
50
|
+
"/leading-slash",
|
|
51
|
+
"trailing-slash/",
|
|
52
|
+
"",
|
|
53
|
+
" ",
|
|
54
|
+
]),
|
|
55
|
+
).toEqual(["anthropic/claude-sonnet-4-6"]);
|
|
61
56
|
});
|
|
62
57
|
|
|
63
58
|
test("trims whitespace in user entries", () => {
|
|
64
|
-
|
|
65
|
-
" anthropic/claude-sonnet-4-6 ",
|
|
66
|
-
|
|
67
|
-
]);
|
|
68
|
-
expect(chain).toEqual(["anthropic/claude-sonnet-4-6", "google/gemini-3-flash"]);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("returns empty array for unknown agent with no user fallbacks", () => {
|
|
72
|
-
const chain = resolveFallbackChain("unknown-agent", undefined);
|
|
73
|
-
expect(chain).toEqual([]);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("returns user fallbacks for unknown agent when provided", () => {
|
|
77
|
-
const chain = resolveFallbackChain("unknown-agent", ["foo/bar"]);
|
|
78
|
-
expect(chain).toEqual(["foo/bar"]);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test("HISTORIAN_AGENT has builtin chain", () => {
|
|
82
|
-
const chain = resolveFallbackChain(HISTORIAN_AGENT, undefined);
|
|
83
|
-
expect(chain.length).toBeGreaterThan(0);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test("SIDEKICK_AGENT has builtin chain", () => {
|
|
87
|
-
const chain = resolveFallbackChain(SIDEKICK_AGENT, undefined);
|
|
88
|
-
expect(chain.length).toBeGreaterThan(0);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test("user-only policy: builtin not appended even if user set short list", () => {
|
|
92
|
-
const chain = resolveFallbackChain(DREAMER_AGENT, ["anthropic/claude-sonnet-4-6"]);
|
|
93
|
-
expect(chain).toEqual(["anthropic/claude-sonnet-4-6"]);
|
|
94
|
-
// Confirm length is exactly 1, not user+builtin
|
|
95
|
-
expect(chain.length).toBe(1);
|
|
59
|
+
expect(
|
|
60
|
+
resolveFallbackChain([" anthropic/claude-sonnet-4-6 ", "\tgoogle/gemini-3-flash\n"]),
|
|
61
|
+
).toEqual(["anthropic/claude-sonnet-4-6", "google/gemini-3-flash"]);
|
|
96
62
|
});
|
|
97
63
|
});
|
|
98
64
|
|