@caupulican/pi-adaptative 0.80.86 → 0.80.89
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 +178 -0
- package/dist/core/agent-session.d.ts +412 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +2053 -41
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/approval-gate.d.ts +4 -0
- package/dist/core/autonomy/approval-gate.d.ts.map +1 -0
- package/dist/core/autonomy/approval-gate.js +27 -0
- package/dist/core/autonomy/approval-gate.js.map +1 -0
- package/dist/core/autonomy/bounded-completion.d.ts +27 -0
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -0
- package/dist/core/autonomy/bounded-completion.js +44 -0
- package/dist/core/autonomy/bounded-completion.js.map +1 -0
- package/dist/core/autonomy/contracts.d.ts +129 -0
- package/dist/core/autonomy/contracts.d.ts.map +1 -0
- package/dist/core/autonomy/contracts.js +2 -0
- package/dist/core/autonomy/contracts.js.map +1 -0
- package/dist/core/autonomy/gates.d.ts +15 -0
- package/dist/core/autonomy/gates.d.ts.map +1 -0
- package/dist/core/autonomy/gates.js +205 -0
- package/dist/core/autonomy/gates.js.map +1 -0
- package/dist/core/autonomy/lane-tracker.d.ts +48 -0
- package/dist/core/autonomy/lane-tracker.d.ts.map +1 -0
- package/dist/core/autonomy/lane-tracker.js +125 -0
- package/dist/core/autonomy/lane-tracker.js.map +1 -0
- package/dist/core/autonomy/path-scope.d.ts +9 -0
- package/dist/core/autonomy/path-scope.d.ts.map +1 -0
- package/dist/core/autonomy/path-scope.js +122 -0
- package/dist/core/autonomy/path-scope.js.map +1 -0
- package/dist/core/autonomy/risk-assessment.d.ts +3 -0
- package/dist/core/autonomy/risk-assessment.d.ts.map +1 -0
- package/dist/core/autonomy/risk-assessment.js +122 -0
- package/dist/core/autonomy/risk-assessment.js.map +1 -0
- package/dist/core/autonomy/session-lane-record.d.ts +10 -0
- package/dist/core/autonomy/session-lane-record.d.ts.map +1 -0
- package/dist/core/autonomy/session-lane-record.js +36 -0
- package/dist/core/autonomy/session-lane-record.js.map +1 -0
- package/dist/core/autonomy/status.d.ts +40 -0
- package/dist/core/autonomy/status.d.ts.map +1 -0
- package/dist/core/autonomy/status.js +107 -0
- package/dist/core/autonomy/status.js.map +1 -0
- package/dist/core/autonomy/subagent-prompt.d.ts +21 -0
- package/dist/core/autonomy/subagent-prompt.d.ts.map +1 -0
- package/dist/core/autonomy/subagent-prompt.js +28 -0
- package/dist/core/autonomy/subagent-prompt.js.map +1 -0
- package/dist/core/autonomy/telemetry-events.d.ts +18 -0
- package/dist/core/autonomy/telemetry-events.d.ts.map +1 -0
- package/dist/core/autonomy/telemetry-events.js +60 -0
- package/dist/core/autonomy/telemetry-events.js.map +1 -0
- package/dist/core/context/artifact-retrieval.d.ts +49 -0
- package/dist/core/context/artifact-retrieval.d.ts.map +1 -0
- package/dist/core/context/artifact-retrieval.js +49 -0
- package/dist/core/context/artifact-retrieval.js.map +1 -0
- package/dist/core/context/brain-curator.d.ts +88 -0
- package/dist/core/context/brain-curator.d.ts.map +1 -0
- package/dist/core/context/brain-curator.js +192 -0
- package/dist/core/context/brain-curator.js.map +1 -0
- package/dist/core/context/context-artifacts.d.ts +94 -0
- package/dist/core/context/context-artifacts.d.ts.map +1 -0
- package/dist/core/context/context-artifacts.js +307 -0
- package/dist/core/context/context-artifacts.js.map +1 -0
- package/dist/core/context/context-audit.d.ts +66 -0
- package/dist/core/context/context-audit.d.ts.map +1 -0
- package/dist/core/context/context-audit.js +173 -0
- package/dist/core/context/context-audit.js.map +1 -0
- package/dist/core/context/context-composition.d.ts +122 -0
- package/dist/core/context/context-composition.d.ts.map +1 -0
- package/dist/core/context/context-composition.js +163 -0
- package/dist/core/context/context-composition.js.map +1 -0
- package/dist/core/context/context-item.d.ts +117 -0
- package/dist/core/context/context-item.d.ts.map +1 -0
- package/dist/core/context/context-item.js +36 -0
- package/dist/core/context/context-item.js.map +1 -0
- package/dist/core/context/context-prompt-enforcement.d.ts +86 -0
- package/dist/core/context/context-prompt-enforcement.d.ts.map +1 -0
- package/dist/core/context/context-prompt-enforcement.js +168 -0
- package/dist/core/context/context-prompt-enforcement.js.map +1 -0
- package/dist/core/context/context-prompt-policy.d.ts +90 -0
- package/dist/core/context/context-prompt-policy.d.ts.map +1 -0
- package/dist/core/context/context-prompt-policy.js +73 -0
- package/dist/core/context/context-prompt-policy.js.map +1 -0
- package/dist/core/context/context-retention.d.ts +36 -0
- package/dist/core/context/context-retention.d.ts.map +1 -0
- package/dist/core/context/context-retention.js +108 -0
- package/dist/core/context/context-retention.js.map +1 -0
- package/dist/core/context/context-store.d.ts +37 -0
- package/dist/core/context/context-store.d.ts.map +1 -0
- package/dist/core/context/context-store.js +45 -0
- package/dist/core/context/context-store.js.map +1 -0
- package/dist/core/context/memory-diagnostics.d.ts +50 -0
- package/dist/core/context/memory-diagnostics.d.ts.map +1 -0
- package/dist/core/context/memory-diagnostics.js +43 -0
- package/dist/core/context/memory-diagnostics.js.map +1 -0
- package/dist/core/context/memory-index-store.d.ts +28 -0
- package/dist/core/context/memory-index-store.d.ts.map +1 -0
- package/dist/core/context/memory-index-store.js +38 -0
- package/dist/core/context/memory-index-store.js.map +1 -0
- package/dist/core/context/memory-prompt-block.d.ts +34 -0
- package/dist/core/context/memory-prompt-block.d.ts.map +1 -0
- package/dist/core/context/memory-prompt-block.js +58 -0
- package/dist/core/context/memory-prompt-block.js.map +1 -0
- package/dist/core/context/memory-provider-contract.d.ts +114 -0
- package/dist/core/context/memory-provider-contract.d.ts.map +1 -0
- package/dist/core/context/memory-provider-contract.js +121 -0
- package/dist/core/context/memory-provider-contract.js.map +1 -0
- package/dist/core/context/memory-retrieval.d.ts +27 -0
- package/dist/core/context/memory-retrieval.d.ts.map +1 -0
- package/dist/core/context/memory-retrieval.js +91 -0
- package/dist/core/context/memory-retrieval.js.map +1 -0
- package/dist/core/context/okf-memory-provider.d.ts +26 -0
- package/dist/core/context/okf-memory-provider.d.ts.map +1 -0
- package/dist/core/context/okf-memory-provider.js +154 -0
- package/dist/core/context/okf-memory-provider.js.map +1 -0
- package/dist/core/context/okf-memory.d.ts +42 -0
- package/dist/core/context/okf-memory.d.ts.map +1 -0
- package/dist/core/context/okf-memory.js +175 -0
- package/dist/core/context/okf-memory.js.map +1 -0
- package/dist/core/context/policy-engine.d.ts +66 -0
- package/dist/core/context/policy-engine.d.ts.map +1 -0
- package/dist/core/context/policy-engine.js +171 -0
- package/dist/core/context/policy-engine.js.map +1 -0
- package/dist/core/context/policy-types.d.ts +102 -0
- package/dist/core/context/policy-types.d.ts.map +1 -0
- package/dist/core/context/policy-types.js +7 -0
- package/dist/core/context/policy-types.js.map +1 -0
- package/dist/core/context/sqlite-runtime-index.d.ts +19 -0
- package/dist/core/context/sqlite-runtime-index.d.ts.map +1 -0
- package/dist/core/context/sqlite-runtime-index.js +344 -0
- package/dist/core/context/sqlite-runtime-index.js.map +1 -0
- package/dist/core/context/storage-authority.d.ts +20 -0
- package/dist/core/context/storage-authority.d.ts.map +1 -0
- package/dist/core/context/storage-authority.js +51 -0
- package/dist/core/context/storage-authority.js.map +1 -0
- package/dist/core/context/tool-output-packer.d.ts +75 -0
- package/dist/core/context/tool-output-packer.d.ts.map +1 -0
- package/dist/core/context/tool-output-packer.js +77 -0
- package/dist/core/context/tool-output-packer.js.map +1 -0
- package/dist/core/context-gc.d.ts +13 -0
- package/dist/core/context-gc.d.ts.map +1 -1
- package/dist/core/context-gc.js +6 -0
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/cost/session-usage.d.ts +20 -0
- package/dist/core/cost/session-usage.d.ts.map +1 -0
- package/dist/core/cost/session-usage.js +164 -0
- package/dist/core/cost/session-usage.js.map +1 -0
- package/dist/core/delegation/session-worker-result.d.ts +10 -0
- package/dist/core/delegation/session-worker-result.d.ts.map +1 -0
- package/dist/core/delegation/session-worker-result.js +36 -0
- package/dist/core/delegation/session-worker-result.js.map +1 -0
- package/dist/core/delegation/worker-result.d.ts +9 -0
- package/dist/core/delegation/worker-result.d.ts.map +1 -0
- package/dist/core/delegation/worker-result.js +152 -0
- package/dist/core/delegation/worker-result.js.map +1 -0
- package/dist/core/delegation/worker-runner.d.ts +58 -0
- package/dist/core/delegation/worker-runner.d.ts.map +1 -0
- package/dist/core/delegation/worker-runner.js +188 -0
- package/dist/core/delegation/worker-runner.js.map +1 -0
- package/dist/core/extensions/builtin.d.ts +5 -1
- package/dist/core/extensions/builtin.d.ts.map +1 -1
- package/dist/core/extensions/builtin.js +23 -1
- package/dist/core/extensions/builtin.js.map +1 -1
- package/dist/core/footer-data-provider.d.ts +5 -1
- package/dist/core/footer-data-provider.d.ts.map +1 -1
- package/dist/core/footer-data-provider.js +13 -0
- package/dist/core/footer-data-provider.js.map +1 -1
- package/dist/core/goals/goal-continuation-controller.d.ts +22 -0
- package/dist/core/goals/goal-continuation-controller.d.ts.map +1 -0
- package/dist/core/goals/goal-continuation-controller.js +88 -0
- package/dist/core/goals/goal-continuation-controller.js.map +1 -0
- package/dist/core/goals/goal-continuation-defaults.d.ts +10 -0
- package/dist/core/goals/goal-continuation-defaults.d.ts.map +1 -0
- package/dist/core/goals/goal-continuation-defaults.js +10 -0
- package/dist/core/goals/goal-continuation-defaults.js.map +1 -0
- package/dist/core/goals/goal-continuation-prompt.d.ts +18 -0
- package/dist/core/goals/goal-continuation-prompt.d.ts.map +1 -0
- package/dist/core/goals/goal-continuation-prompt.js +141 -0
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -0
- package/dist/core/goals/goal-runtime-snapshot.d.ts +19 -0
- package/dist/core/goals/goal-runtime-snapshot.d.ts.map +1 -0
- package/dist/core/goals/goal-runtime-snapshot.js +23 -0
- package/dist/core/goals/goal-runtime-snapshot.js.map +1 -0
- package/dist/core/goals/goal-state.d.ts +87 -0
- package/dist/core/goals/goal-state.d.ts.map +1 -0
- package/dist/core/goals/goal-state.js +259 -0
- package/dist/core/goals/goal-state.js.map +1 -0
- package/dist/core/goals/goal-tool-core.d.ts +66 -0
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -0
- package/dist/core/goals/goal-tool-core.js +146 -0
- package/dist/core/goals/goal-tool-core.js.map +1 -0
- package/dist/core/goals/session-goal-state.d.ts +10 -0
- package/dist/core/goals/session-goal-state.d.ts.map +1 -0
- package/dist/core/goals/session-goal-state.js +35 -0
- package/dist/core/goals/session-goal-state.js.map +1 -0
- package/dist/core/learning/learning-audit.d.ts +45 -0
- package/dist/core/learning/learning-audit.d.ts.map +1 -0
- package/dist/core/learning/learning-audit.js +139 -0
- package/dist/core/learning/learning-audit.js.map +1 -0
- package/dist/core/learning/learning-gate.d.ts +29 -0
- package/dist/core/learning/learning-gate.d.ts.map +1 -0
- package/dist/core/learning/learning-gate.js +150 -0
- package/dist/core/learning/learning-gate.js.map +1 -0
- package/dist/core/learning/session-learning-decision.d.ts +10 -0
- package/dist/core/learning/session-learning-decision.d.ts.map +1 -0
- package/dist/core/learning/session-learning-decision.js +36 -0
- package/dist/core/learning/session-learning-decision.js.map +1 -0
- package/dist/core/model-capability.d.ts +41 -0
- package/dist/core/model-capability.d.ts.map +1 -0
- package/dist/core/model-capability.js +101 -0
- package/dist/core/model-capability.js.map +1 -0
- package/dist/core/model-router/config-diagnostics.d.ts.map +1 -1
- package/dist/core/model-router/config-diagnostics.js +1 -0
- package/dist/core/model-router/config-diagnostics.js.map +1 -1
- package/dist/core/model-router/intent-classifier.d.ts +2 -0
- package/dist/core/model-router/intent-classifier.d.ts.map +1 -1
- package/dist/core/model-router/intent-classifier.js +154 -9
- package/dist/core/model-router/intent-classifier.js.map +1 -1
- package/dist/core/model-router/route-judge.d.ts +54 -0
- package/dist/core/model-router/route-judge.d.ts.map +1 -0
- package/dist/core/model-router/route-judge.js +128 -0
- package/dist/core/model-router/route-judge.js.map +1 -0
- package/dist/core/model-router/status.d.ts +4 -1
- package/dist/core/model-router/status.d.ts.map +1 -1
- package/dist/core/model-router/status.js +30 -6
- package/dist/core/model-router/status.js.map +1 -1
- package/dist/core/model-router/tool-escalation.d.ts +4 -6
- package/dist/core/model-router/tool-escalation.d.ts.map +1 -1
- package/dist/core/model-router/tool-escalation.js +1 -1
- package/dist/core/model-router/tool-escalation.js.map +1 -1
- package/dist/core/models/fitness-store.d.ts +40 -0
- package/dist/core/models/fitness-store.d.ts.map +1 -0
- package/dist/core/models/fitness-store.js +61 -0
- package/dist/core/models/fitness-store.js.map +1 -0
- package/dist/core/profile-registry.d.ts.map +1 -1
- package/dist/core/profile-registry.js +1 -1
- package/dist/core/profile-registry.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +2 -0
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +12 -4
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/research/automata-provider.d.ts +5 -0
- package/dist/core/research/automata-provider.d.ts.map +1 -0
- package/dist/core/research/automata-provider.js +15 -0
- package/dist/core/research/automata-provider.js.map +1 -0
- package/dist/core/research/evidence-bundle.d.ts +10 -0
- package/dist/core/research/evidence-bundle.d.ts.map +1 -0
- package/dist/core/research/evidence-bundle.js +116 -0
- package/dist/core/research/evidence-bundle.js.map +1 -0
- package/dist/core/research/model-fitness.d.ts +82 -0
- package/dist/core/research/model-fitness.d.ts.map +1 -0
- package/dist/core/research/model-fitness.js +308 -0
- package/dist/core/research/model-fitness.js.map +1 -0
- package/dist/core/research/research-gate.d.ts +11 -0
- package/dist/core/research/research-gate.d.ts.map +1 -0
- package/dist/core/research/research-gate.js +82 -0
- package/dist/core/research/research-gate.js.map +1 -0
- package/dist/core/research/research-runner.d.ts +59 -0
- package/dist/core/research/research-runner.d.ts.map +1 -0
- package/dist/core/research/research-runner.js +155 -0
- package/dist/core/research/research-runner.js.map +1 -0
- package/dist/core/research/session-evidence-bundle.d.ts +11 -0
- package/dist/core/research/session-evidence-bundle.d.ts.map +1 -0
- package/dist/core/research/session-evidence-bundle.js +55 -0
- package/dist/core/research/session-evidence-bundle.js.map +1 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +4 -0
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/settings-manager.d.ts +160 -4
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +304 -9
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts +4 -0
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +18 -6
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +10 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/toolkit/script-registry.d.ts +34 -0
- package/dist/core/toolkit/script-registry.d.ts.map +1 -0
- package/dist/core/toolkit/script-registry.js +71 -0
- package/dist/core/toolkit/script-registry.js.map +1 -0
- package/dist/core/toolkit/script-runner.d.ts +28 -0
- package/dist/core/toolkit/script-runner.d.ts.map +1 -0
- package/dist/core/toolkit/script-runner.js +48 -0
- package/dist/core/toolkit/script-runner.js.map +1 -0
- package/dist/core/tools/artifact-retrieve.d.ts +23 -0
- package/dist/core/tools/artifact-retrieve.d.ts.map +1 -0
- package/dist/core/tools/artifact-retrieve.js +110 -0
- package/dist/core/tools/artifact-retrieve.js.map +1 -0
- package/dist/core/tools/delegate.d.ts +32 -0
- package/dist/core/tools/delegate.d.ts.map +1 -0
- package/dist/core/tools/delegate.js +60 -0
- package/dist/core/tools/delegate.js.map +1 -0
- package/dist/core/tools/fff-search-backend.d.ts +103 -0
- package/dist/core/tools/fff-search-backend.d.ts.map +1 -0
- package/dist/core/tools/fff-search-backend.js +151 -0
- package/dist/core/tools/fff-search-backend.js.map +1 -0
- package/dist/core/tools/find.d.ts +21 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +183 -10
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/goal.d.ts +35 -0
- package/dist/core/tools/goal.d.ts.map +1 -0
- package/dist/core/tools/goal.js +122 -0
- package/dist/core/tools/goal.js.map +1 -0
- package/dist/core/tools/grep.d.ts +21 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +272 -27
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +4 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +9 -0
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/model-fitness.d.ts +30 -0
- package/dist/core/tools/model-fitness.d.ts.map +1 -0
- package/dist/core/tools/model-fitness.js +38 -0
- package/dist/core/tools/model-fitness.js.map +1 -0
- package/dist/core/tools/run-toolkit-script.d.ts +24 -0
- package/dist/core/tools/run-toolkit-script.d.ts.map +1 -0
- package/dist/core/tools/run-toolkit-script.js +103 -0
- package/dist/core/tools/run-toolkit-script.js.map +1 -0
- package/dist/core/tools/search-router.d.ts +75 -0
- package/dist/core/tools/search-router.d.ts.map +1 -0
- package/dist/core/tools/search-router.js +85 -0
- package/dist/core/tools/search-router.js.map +1 -0
- package/dist/modes/interactive/components/fitness-role-selector.d.ts +13 -0
- package/dist/modes/interactive/components/fitness-role-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/fitness-role-selector.js +65 -0
- package/dist/modes/interactive/components/fitness-role-selector.js.map +1 -0
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +18 -16
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +16 -1
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +555 -11
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +9 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +308 -39
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/tools-manager.d.ts +2 -0
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +154 -2
- package/dist/utils/tools-manager.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +368 -12
- package/package.json +5 -4
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { CapabilityEnvelope, EvidenceBundle, GateOutcome } from "../autonomy/contracts.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Pure orchestration for one autonomous research pass: gate -> bounded isolated completion ->
|
|
4
|
+
* parse -> evidence bundle. The model executor is injected so this stays provider-free and
|
|
5
|
+
* session-free; production wires `AgentSession.runIsolatedCompletion` in.
|
|
6
|
+
*
|
|
7
|
+
* The lane is read-only by construction: the executor receives text prompts only, and the output
|
|
8
|
+
* is an `EvidenceBundle` whose model-synthesized findings are marked untrusted.
|
|
9
|
+
*/
|
|
10
|
+
/** Static across calls so callers can use `cacheRetention: "short"` and only pay for the variable tail. */
|
|
11
|
+
export declare const RESEARCH_LANE_SYSTEM_PROMPT: string;
|
|
12
|
+
export interface ResearchCompletion {
|
|
13
|
+
text: string;
|
|
14
|
+
costUsd: number;
|
|
15
|
+
stopReason: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ResearchRunnerOptions {
|
|
18
|
+
query: string;
|
|
19
|
+
/** Bounded, pre-redacted context handed to the research model (goal text, open requirements). */
|
|
20
|
+
context?: string;
|
|
21
|
+
/** Stripped research envelope - never the foreground/architect envelope. */
|
|
22
|
+
envelope: CapabilityEnvelope;
|
|
23
|
+
/** Budget for this pass; a post-hoc breach marks the run budget_exhausted (spend stays visible). */
|
|
24
|
+
maxUsd: number;
|
|
25
|
+
maxSources: number;
|
|
26
|
+
maxFindings: number;
|
|
27
|
+
/** Wall-clock budget in milliseconds; 0 disables. */
|
|
28
|
+
maxWallClockMs: number;
|
|
29
|
+
/** Executes one isolated completion. Production: AgentSession.runIsolatedCompletion. */
|
|
30
|
+
complete: (args: {
|
|
31
|
+
systemPrompt: string;
|
|
32
|
+
userPrompt: string;
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}) => Promise<ResearchCompletion>;
|
|
35
|
+
/** External cancellation (e.g. session disposal). */
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}
|
|
38
|
+
export type ResearchRunStatus = "succeeded" | "failed" | "canceled" | "timeout" | "budget_exhausted";
|
|
39
|
+
export interface ResearchRunResult {
|
|
40
|
+
status: ResearchRunStatus;
|
|
41
|
+
reasonCode: string;
|
|
42
|
+
gateOutcome: GateOutcome;
|
|
43
|
+
bundle?: EvidenceBundle;
|
|
44
|
+
costUsd: number;
|
|
45
|
+
}
|
|
46
|
+
export declare function buildResearchUserPrompt(args: {
|
|
47
|
+
query: string;
|
|
48
|
+
context?: string;
|
|
49
|
+
maxFindings: number;
|
|
50
|
+
}): string;
|
|
51
|
+
export interface ParsedResearchFindings {
|
|
52
|
+
findings: Array<{
|
|
53
|
+
summary: string;
|
|
54
|
+
confidence?: number;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
export declare function parseResearchFindings(text: string, maxFindings: number): ParsedResearchFindings | undefined;
|
|
58
|
+
export declare function runResearch(options: ResearchRunnerOptions): Promise<ResearchRunResult>;
|
|
59
|
+
//# sourceMappingURL=research-runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"research-runner.d.ts","sourceRoot":"","sources":["../../../src/core/research/research-runner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAwB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAItH;;;;;;;GAOG;AAEH,2GAA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AO,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC1D;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,sBAAsB,GAAG,SAAS,CAwC3G;AA+BD,wBAAsB,WAAW,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAwD5F","sourcesContent":["import { runBoundedCompletion } from \"../autonomy/bounded-completion.ts\";\nimport type { CapabilityEnvelope, EvidenceBundle, EvidenceRef, Finding, GateOutcome } from \"../autonomy/contracts.ts\";\nimport { createEvidenceBundle } from \"./evidence-bundle.ts\";\nimport { evaluateResearchRequest } from \"./research-gate.ts\";\n\n/**\n * Pure orchestration for one autonomous research pass: gate -> bounded isolated completion ->\n * parse -> evidence bundle. The model executor is injected so this stays provider-free and\n * session-free; production wires `AgentSession.runIsolatedCompletion` in.\n *\n * The lane is read-only by construction: the executor receives text prompts only, and the output\n * is an `EvidenceBundle` whose model-synthesized findings are marked untrusted.\n */\n\n/** Static across calls so callers can use `cacheRetention: \"short\"` and only pay for the variable tail. */\nexport const RESEARCH_LANE_SYSTEM_PROMPT = [\n\t\"You are a read-only research lane for a coding agent.\",\n\t\"You receive a research query plus bounded context and produce findings that help satisfy open goal requirements.\",\n\t\"Respond with STRICT JSON only - no prose, no markdown fences:\",\n\t'{\"findings\":[{\"summary\":\"<one concrete, actionable finding>\",\"confidence\":<0..1>}]}',\n\t\"Base findings only on the provided context. Never invent file paths, APIs, or facts.\",\n].join(\"\\n\");\n\nexport interface ResearchCompletion {\n\ttext: string;\n\tcostUsd: number;\n\tstopReason: string;\n}\n\nexport interface ResearchRunnerOptions {\n\tquery: string;\n\t/** Bounded, pre-redacted context handed to the research model (goal text, open requirements). */\n\tcontext?: string;\n\t/** Stripped research envelope - never the foreground/architect envelope. */\n\tenvelope: CapabilityEnvelope;\n\t/** Budget for this pass; a post-hoc breach marks the run budget_exhausted (spend stays visible). */\n\tmaxUsd: number;\n\tmaxSources: number;\n\tmaxFindings: number;\n\t/** Wall-clock budget in milliseconds; 0 disables. */\n\tmaxWallClockMs: number;\n\t/** Executes one isolated completion. Production: AgentSession.runIsolatedCompletion. */\n\tcomplete: (args: { systemPrompt: string; userPrompt: string; signal?: AbortSignal }) => Promise<ResearchCompletion>;\n\t/** External cancellation (e.g. session disposal). */\n\tsignal?: AbortSignal;\n}\n\nexport type ResearchRunStatus = \"succeeded\" | \"failed\" | \"canceled\" | \"timeout\" | \"budget_exhausted\";\n\nexport interface ResearchRunResult {\n\tstatus: ResearchRunStatus;\n\treasonCode: string;\n\tgateOutcome: GateOutcome;\n\tbundle?: EvidenceBundle;\n\tcostUsd: number;\n}\n\nexport function buildResearchUserPrompt(args: { query: string; context?: string; maxFindings: number }): string {\n\tconst parts = [`Research query: ${args.query}`];\n\tif (args.context && args.context.length > 0) {\n\t\tparts.push(\"\", \"Context:\", args.context);\n\t}\n\tparts.push(\"\", `Return at most ${args.maxFindings} findings.`);\n\treturn parts.join(\"\\n\");\n}\n\nexport interface ParsedResearchFindings {\n\tfindings: Array<{ summary: string; confidence?: number }>;\n}\n\nexport function parseResearchFindings(text: string, maxFindings: number): ParsedResearchFindings | undefined {\n\tconst trimmed = text.trim();\n\tconst candidates: string[] = [trimmed];\n\tconst fenced = /```(?:json)?\\s*([\\s\\S]*?)```/.exec(trimmed);\n\tif (fenced?.[1]) candidates.push(fenced[1].trim());\n\tconst start = trimmed.indexOf(\"{\");\n\tconst end = trimmed.lastIndexOf(\"}\");\n\tif (start >= 0 && end > start) candidates.push(trimmed.slice(start, end + 1));\n\n\tfor (const candidate of candidates) {\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(candidate);\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) continue;\n\t\tconst findingsRaw = (parsed as { findings?: unknown }).findings;\n\t\tif (!Array.isArray(findingsRaw)) continue;\n\n\t\tconst findings: Array<{ summary: string; confidence?: number }> = [];\n\t\tfor (const item of findingsRaw) {\n\t\t\tif (!item || typeof item !== \"object\" || Array.isArray(item)) continue;\n\t\t\tconst summary = (item as { summary?: unknown }).summary;\n\t\t\tif (typeof summary !== \"string\" || summary.trim().length === 0) continue;\n\t\t\tconst confidenceRaw = (item as { confidence?: unknown }).confidence;\n\t\t\tconst confidence =\n\t\t\t\ttypeof confidenceRaw === \"number\" && Number.isFinite(confidenceRaw)\n\t\t\t\t\t? Math.min(Math.max(confidenceRaw, 0), 1)\n\t\t\t\t\t: undefined;\n\t\t\tfindings.push({ summary: summary.trim(), confidence });\n\t\t\tif (findings.length >= maxFindings) break;\n\t\t}\n\t\t// A well-formed-but-empty findings array is a valid \"nothing found\"; a findings array whose\n\t\t// every item is malformed is not.\n\t\tif (findings.length > 0 || findingsRaw.length === 0) {\n\t\t\treturn { findings };\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction truncateExcerpt(text: string, maxChars: number): string {\n\tif (text.length <= maxChars) return text;\n\treturn `${text.slice(0, Math.max(0, maxChars - 1))}…`;\n}\n\nfunction buildBundle(options: ResearchRunnerOptions, parsed: ParsedResearchFindings): EvidenceBundle {\n\tconst contextRef: EvidenceRef = {\n\t\tid: \"src-context\",\n\t\tkind: \"user\",\n\t\ttitle: \"Goal/context provided to the research lane\",\n\t\ttrusted: true,\n\t\texcerpt: truncateExcerpt(options.context && options.context.length > 0 ? options.context : options.query, 2000),\n\t};\n\tconst synthesisRef: EvidenceRef = {\n\t\tid: \"src-synthesis\",\n\t\tkind: \"tool\",\n\t\ttitle: \"Research-model synthesis\",\n\t\ttrusted: false,\n\t};\n\tconst sources = [contextRef, synthesisRef].slice(0, Math.max(1, options.maxSources));\n\tconst findings: Finding[] = parsed.findings.slice(0, options.maxFindings).map((finding, index) => ({\n\t\tid: `finding-${index + 1}`,\n\t\tsummary: finding.summary,\n\t\tevidenceIds: [synthesisRef.id],\n\t\t...(finding.confidence !== undefined ? { confidence: finding.confidence } : {}),\n\t}));\n\treturn createEvidenceBundle({ query: options.query, sources, findings });\n}\n\nexport async function runResearch(options: ResearchRunnerOptions): Promise<ResearchRunResult> {\n\tconst gateOutcome = evaluateResearchRequest({\n\t\tenvelope: options.envelope,\n\t\tsourceKind: \"tool\",\n\t\testimatedUsd: options.maxUsd,\n\t});\n\tif (gateOutcome.outcome !== \"allow\") {\n\t\t// Skip-and-record, never prompt: gate denials inform diagnostics instead of blocking anything.\n\t\tconst status: ResearchRunStatus = gateOutcome.reasonCode === \"over_budget\" ? \"budget_exhausted\" : \"failed\";\n\t\treturn { status, reasonCode: gateOutcome.reasonCode, gateOutcome, costUsd: 0 };\n\t}\n\n\tconst bounded = await runBoundedCompletion({\n\t\tmaxWallClockMs: options.maxWallClockMs,\n\t\tsignal: options.signal,\n\t\texecute: (signal) =>\n\t\t\toptions.complete({\n\t\t\t\tsystemPrompt: RESEARCH_LANE_SYSTEM_PROMPT,\n\t\t\t\tuserPrompt: buildResearchUserPrompt(options),\n\t\t\t\tsignal,\n\t\t\t}),\n\t});\n\tif (bounded.failure) {\n\t\treturn {\n\t\t\tstatus: bounded.failure.status,\n\t\t\treasonCode: bounded.failure.reasonCode,\n\t\t\tgateOutcome,\n\t\t\tcostUsd: bounded.completion?.costUsd ?? 0,\n\t\t};\n\t}\n\tconst completion = bounded.completion;\n\tif (!completion) {\n\t\treturn { status: \"failed\", reasonCode: \"completion_error\", gateOutcome, costUsd: 0 };\n\t}\n\tif (completion.stopReason === \"error\" || completion.stopReason === \"aborted\") {\n\t\treturn { status: \"failed\", reasonCode: \"model_error\", gateOutcome, costUsd: completion.costUsd };\n\t}\n\n\tconst parsed = parseResearchFindings(completion.text, options.maxFindings);\n\tif (!parsed) {\n\t\treturn { status: \"failed\", reasonCode: \"unparseable_output\", gateOutcome, costUsd: completion.costUsd };\n\t}\n\n\tconst bundle = buildBundle(options, parsed);\n\tconst overBudget = options.maxUsd > 0 && completion.costUsd > options.maxUsd;\n\treturn {\n\t\tstatus: overBudget ? \"budget_exhausted\" : \"succeeded\",\n\t\treasonCode: overBudget\n\t\t\t? \"cost_budget_exceeded\"\n\t\t\t: parsed.findings.length === 0\n\t\t\t\t? \"no_findings\"\n\t\t\t\t: \"research_completed\",\n\t\tgateOutcome,\n\t\tbundle,\n\t\tcostUsd: completion.costUsd,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { runBoundedCompletion } from "../autonomy/bounded-completion.js";
|
|
2
|
+
import { createEvidenceBundle } from "./evidence-bundle.js";
|
|
3
|
+
import { evaluateResearchRequest } from "./research-gate.js";
|
|
4
|
+
/**
|
|
5
|
+
* Pure orchestration for one autonomous research pass: gate -> bounded isolated completion ->
|
|
6
|
+
* parse -> evidence bundle. The model executor is injected so this stays provider-free and
|
|
7
|
+
* session-free; production wires `AgentSession.runIsolatedCompletion` in.
|
|
8
|
+
*
|
|
9
|
+
* The lane is read-only by construction: the executor receives text prompts only, and the output
|
|
10
|
+
* is an `EvidenceBundle` whose model-synthesized findings are marked untrusted.
|
|
11
|
+
*/
|
|
12
|
+
/** Static across calls so callers can use `cacheRetention: "short"` and only pay for the variable tail. */
|
|
13
|
+
export const RESEARCH_LANE_SYSTEM_PROMPT = [
|
|
14
|
+
"You are a read-only research lane for a coding agent.",
|
|
15
|
+
"You receive a research query plus bounded context and produce findings that help satisfy open goal requirements.",
|
|
16
|
+
"Respond with STRICT JSON only - no prose, no markdown fences:",
|
|
17
|
+
'{"findings":[{"summary":"<one concrete, actionable finding>","confidence":<0..1>}]}',
|
|
18
|
+
"Base findings only on the provided context. Never invent file paths, APIs, or facts.",
|
|
19
|
+
].join("\n");
|
|
20
|
+
export function buildResearchUserPrompt(args) {
|
|
21
|
+
const parts = [`Research query: ${args.query}`];
|
|
22
|
+
if (args.context && args.context.length > 0) {
|
|
23
|
+
parts.push("", "Context:", args.context);
|
|
24
|
+
}
|
|
25
|
+
parts.push("", `Return at most ${args.maxFindings} findings.`);
|
|
26
|
+
return parts.join("\n");
|
|
27
|
+
}
|
|
28
|
+
export function parseResearchFindings(text, maxFindings) {
|
|
29
|
+
const trimmed = text.trim();
|
|
30
|
+
const candidates = [trimmed];
|
|
31
|
+
const fenced = /```(?:json)?\s*([\s\S]*?)```/.exec(trimmed);
|
|
32
|
+
if (fenced?.[1])
|
|
33
|
+
candidates.push(fenced[1].trim());
|
|
34
|
+
const start = trimmed.indexOf("{");
|
|
35
|
+
const end = trimmed.lastIndexOf("}");
|
|
36
|
+
if (start >= 0 && end > start)
|
|
37
|
+
candidates.push(trimmed.slice(start, end + 1));
|
|
38
|
+
for (const candidate of candidates) {
|
|
39
|
+
let parsed;
|
|
40
|
+
try {
|
|
41
|
+
parsed = JSON.parse(candidate);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
|
|
47
|
+
continue;
|
|
48
|
+
const findingsRaw = parsed.findings;
|
|
49
|
+
if (!Array.isArray(findingsRaw))
|
|
50
|
+
continue;
|
|
51
|
+
const findings = [];
|
|
52
|
+
for (const item of findingsRaw) {
|
|
53
|
+
if (!item || typeof item !== "object" || Array.isArray(item))
|
|
54
|
+
continue;
|
|
55
|
+
const summary = item.summary;
|
|
56
|
+
if (typeof summary !== "string" || summary.trim().length === 0)
|
|
57
|
+
continue;
|
|
58
|
+
const confidenceRaw = item.confidence;
|
|
59
|
+
const confidence = typeof confidenceRaw === "number" && Number.isFinite(confidenceRaw)
|
|
60
|
+
? Math.min(Math.max(confidenceRaw, 0), 1)
|
|
61
|
+
: undefined;
|
|
62
|
+
findings.push({ summary: summary.trim(), confidence });
|
|
63
|
+
if (findings.length >= maxFindings)
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
// A well-formed-but-empty findings array is a valid "nothing found"; a findings array whose
|
|
67
|
+
// every item is malformed is not.
|
|
68
|
+
if (findings.length > 0 || findingsRaw.length === 0) {
|
|
69
|
+
return { findings };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
function truncateExcerpt(text, maxChars) {
|
|
75
|
+
if (text.length <= maxChars)
|
|
76
|
+
return text;
|
|
77
|
+
return `${text.slice(0, Math.max(0, maxChars - 1))}…`;
|
|
78
|
+
}
|
|
79
|
+
function buildBundle(options, parsed) {
|
|
80
|
+
const contextRef = {
|
|
81
|
+
id: "src-context",
|
|
82
|
+
kind: "user",
|
|
83
|
+
title: "Goal/context provided to the research lane",
|
|
84
|
+
trusted: true,
|
|
85
|
+
excerpt: truncateExcerpt(options.context && options.context.length > 0 ? options.context : options.query, 2000),
|
|
86
|
+
};
|
|
87
|
+
const synthesisRef = {
|
|
88
|
+
id: "src-synthesis",
|
|
89
|
+
kind: "tool",
|
|
90
|
+
title: "Research-model synthesis",
|
|
91
|
+
trusted: false,
|
|
92
|
+
};
|
|
93
|
+
const sources = [contextRef, synthesisRef].slice(0, Math.max(1, options.maxSources));
|
|
94
|
+
const findings = parsed.findings.slice(0, options.maxFindings).map((finding, index) => ({
|
|
95
|
+
id: `finding-${index + 1}`,
|
|
96
|
+
summary: finding.summary,
|
|
97
|
+
evidenceIds: [synthesisRef.id],
|
|
98
|
+
...(finding.confidence !== undefined ? { confidence: finding.confidence } : {}),
|
|
99
|
+
}));
|
|
100
|
+
return createEvidenceBundle({ query: options.query, sources, findings });
|
|
101
|
+
}
|
|
102
|
+
export async function runResearch(options) {
|
|
103
|
+
const gateOutcome = evaluateResearchRequest({
|
|
104
|
+
envelope: options.envelope,
|
|
105
|
+
sourceKind: "tool",
|
|
106
|
+
estimatedUsd: options.maxUsd,
|
|
107
|
+
});
|
|
108
|
+
if (gateOutcome.outcome !== "allow") {
|
|
109
|
+
// Skip-and-record, never prompt: gate denials inform diagnostics instead of blocking anything.
|
|
110
|
+
const status = gateOutcome.reasonCode === "over_budget" ? "budget_exhausted" : "failed";
|
|
111
|
+
return { status, reasonCode: gateOutcome.reasonCode, gateOutcome, costUsd: 0 };
|
|
112
|
+
}
|
|
113
|
+
const bounded = await runBoundedCompletion({
|
|
114
|
+
maxWallClockMs: options.maxWallClockMs,
|
|
115
|
+
signal: options.signal,
|
|
116
|
+
execute: (signal) => options.complete({
|
|
117
|
+
systemPrompt: RESEARCH_LANE_SYSTEM_PROMPT,
|
|
118
|
+
userPrompt: buildResearchUserPrompt(options),
|
|
119
|
+
signal,
|
|
120
|
+
}),
|
|
121
|
+
});
|
|
122
|
+
if (bounded.failure) {
|
|
123
|
+
return {
|
|
124
|
+
status: bounded.failure.status,
|
|
125
|
+
reasonCode: bounded.failure.reasonCode,
|
|
126
|
+
gateOutcome,
|
|
127
|
+
costUsd: bounded.completion?.costUsd ?? 0,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
const completion = bounded.completion;
|
|
131
|
+
if (!completion) {
|
|
132
|
+
return { status: "failed", reasonCode: "completion_error", gateOutcome, costUsd: 0 };
|
|
133
|
+
}
|
|
134
|
+
if (completion.stopReason === "error" || completion.stopReason === "aborted") {
|
|
135
|
+
return { status: "failed", reasonCode: "model_error", gateOutcome, costUsd: completion.costUsd };
|
|
136
|
+
}
|
|
137
|
+
const parsed = parseResearchFindings(completion.text, options.maxFindings);
|
|
138
|
+
if (!parsed) {
|
|
139
|
+
return { status: "failed", reasonCode: "unparseable_output", gateOutcome, costUsd: completion.costUsd };
|
|
140
|
+
}
|
|
141
|
+
const bundle = buildBundle(options, parsed);
|
|
142
|
+
const overBudget = options.maxUsd > 0 && completion.costUsd > options.maxUsd;
|
|
143
|
+
return {
|
|
144
|
+
status: overBudget ? "budget_exhausted" : "succeeded",
|
|
145
|
+
reasonCode: overBudget
|
|
146
|
+
? "cost_budget_exceeded"
|
|
147
|
+
: parsed.findings.length === 0
|
|
148
|
+
? "no_findings"
|
|
149
|
+
: "research_completed",
|
|
150
|
+
gateOutcome,
|
|
151
|
+
bundle,
|
|
152
|
+
costUsd: completion.costUsd,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
//# sourceMappingURL=research-runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"research-runner.js","sourceRoot":"","sources":["../../../src/core/research/research-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAE7D;;;;;;;GAOG;AAEH,2GAA2G;AAC3G,MAAM,CAAC,MAAM,2BAA2B,GAAG;IAC1C,uDAAuD;IACvD,kHAAkH;IAClH,+DAA+D;IAC/D,qFAAqF;IACrF,sFAAsF;CACtF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAoCb,MAAM,UAAU,uBAAuB,CAAC,IAA8D,EAAU;IAC/G,MAAM,KAAK,GAAG,CAAC,mBAAmB,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IAChD,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7C,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1C,CAAC;IACD,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,kBAAkB,IAAI,CAAC,WAAW,YAAY,CAAC,CAAC;IAC/D,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAAA,CACxB;AAMD,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,WAAmB,EAAsC;IAC5G,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IAC5B,MAAM,UAAU,GAAa,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,MAAM,GAAG,8BAA8B,CAAC,IAAI,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UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC3E,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,oBAAoB,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC;IACzG,CAAC;IAED,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC5C,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAC7E,OAAO;QACN,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,WAAW;QACrD,UAAU,EAAE,UAAU;YACrB,CAAC,CAAC,sBAAsB;YACxB,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC;gBAC7B,CAAC,CAAC,aAAa;gBACf,CAAC,CAAC,oBAAoB;QACxB,WAAW;QACX,MAAM;QACN,OAAO,EAAE,UAAU,CAAC,OAAO;KAC3B,CAAC;AAAA,CACF","sourcesContent":["import { runBoundedCompletion } from \"../autonomy/bounded-completion.ts\";\nimport type { CapabilityEnvelope, EvidenceBundle, EvidenceRef, Finding, GateOutcome } from \"../autonomy/contracts.ts\";\nimport { createEvidenceBundle } from \"./evidence-bundle.ts\";\nimport { evaluateResearchRequest } from \"./research-gate.ts\";\n\n/**\n * Pure orchestration for one autonomous research pass: gate -> bounded isolated completion ->\n * parse -> evidence bundle. The model executor is injected so this stays provider-free and\n * session-free; production wires `AgentSession.runIsolatedCompletion` in.\n *\n * The lane is read-only by construction: the executor receives text prompts only, and the output\n * is an `EvidenceBundle` whose model-synthesized findings are marked untrusted.\n */\n\n/** Static across calls so callers can use `cacheRetention: \"short\"` and only pay for the variable tail. */\nexport const RESEARCH_LANE_SYSTEM_PROMPT = [\n\t\"You are a read-only research lane for a coding agent.\",\n\t\"You receive a research query plus bounded context and produce findings that help satisfy open goal requirements.\",\n\t\"Respond with STRICT JSON only - no prose, no markdown fences:\",\n\t'{\"findings\":[{\"summary\":\"<one concrete, actionable finding>\",\"confidence\":<0..1>}]}',\n\t\"Base findings only on the provided context. Never invent file paths, APIs, or facts.\",\n].join(\"\\n\");\n\nexport interface ResearchCompletion {\n\ttext: string;\n\tcostUsd: number;\n\tstopReason: string;\n}\n\nexport interface ResearchRunnerOptions {\n\tquery: string;\n\t/** Bounded, pre-redacted context handed to the research model (goal text, open requirements). */\n\tcontext?: string;\n\t/** Stripped research envelope - never the foreground/architect envelope. */\n\tenvelope: CapabilityEnvelope;\n\t/** Budget for this pass; a post-hoc breach marks the run budget_exhausted (spend stays visible). */\n\tmaxUsd: number;\n\tmaxSources: number;\n\tmaxFindings: number;\n\t/** Wall-clock budget in milliseconds; 0 disables. */\n\tmaxWallClockMs: number;\n\t/** Executes one isolated completion. Production: AgentSession.runIsolatedCompletion. */\n\tcomplete: (args: { systemPrompt: string; userPrompt: string; signal?: AbortSignal }) => Promise<ResearchCompletion>;\n\t/** External cancellation (e.g. session disposal). */\n\tsignal?: AbortSignal;\n}\n\nexport type ResearchRunStatus = \"succeeded\" | \"failed\" | \"canceled\" | \"timeout\" | \"budget_exhausted\";\n\nexport interface ResearchRunResult {\n\tstatus: ResearchRunStatus;\n\treasonCode: string;\n\tgateOutcome: GateOutcome;\n\tbundle?: EvidenceBundle;\n\tcostUsd: number;\n}\n\nexport function buildResearchUserPrompt(args: { query: string; context?: string; maxFindings: number }): string {\n\tconst parts = [`Research query: ${args.query}`];\n\tif (args.context && args.context.length > 0) {\n\t\tparts.push(\"\", \"Context:\", args.context);\n\t}\n\tparts.push(\"\", `Return at most ${args.maxFindings} findings.`);\n\treturn parts.join(\"\\n\");\n}\n\nexport interface ParsedResearchFindings {\n\tfindings: Array<{ summary: string; confidence?: number }>;\n}\n\nexport function parseResearchFindings(text: string, maxFindings: number): ParsedResearchFindings | undefined {\n\tconst trimmed = text.trim();\n\tconst candidates: string[] = [trimmed];\n\tconst fenced = /```(?:json)?\\s*([\\s\\S]*?)```/.exec(trimmed);\n\tif (fenced?.[1]) candidates.push(fenced[1].trim());\n\tconst start = trimmed.indexOf(\"{\");\n\tconst end = trimmed.lastIndexOf(\"}\");\n\tif (start >= 0 && end > start) candidates.push(trimmed.slice(start, end + 1));\n\n\tfor (const candidate of candidates) {\n\t\tlet parsed: unknown;\n\t\ttry {\n\t\t\tparsed = JSON.parse(candidate);\n\t\t} catch {\n\t\t\tcontinue;\n\t\t}\n\t\tif (!parsed || typeof parsed !== \"object\" || Array.isArray(parsed)) continue;\n\t\tconst findingsRaw = (parsed as { findings?: unknown }).findings;\n\t\tif (!Array.isArray(findingsRaw)) continue;\n\n\t\tconst findings: Array<{ summary: string; confidence?: number }> = [];\n\t\tfor (const item of findingsRaw) {\n\t\t\tif (!item || typeof item !== \"object\" || Array.isArray(item)) continue;\n\t\t\tconst summary = (item as { summary?: unknown }).summary;\n\t\t\tif (typeof summary !== \"string\" || summary.trim().length === 0) continue;\n\t\t\tconst confidenceRaw = (item as { confidence?: unknown }).confidence;\n\t\t\tconst confidence =\n\t\t\t\ttypeof confidenceRaw === \"number\" && Number.isFinite(confidenceRaw)\n\t\t\t\t\t? Math.min(Math.max(confidenceRaw, 0), 1)\n\t\t\t\t\t: undefined;\n\t\t\tfindings.push({ summary: summary.trim(), confidence });\n\t\t\tif (findings.length >= maxFindings) break;\n\t\t}\n\t\t// A well-formed-but-empty findings array is a valid \"nothing found\"; a findings array whose\n\t\t// every item is malformed is not.\n\t\tif (findings.length > 0 || findingsRaw.length === 0) {\n\t\t\treturn { findings };\n\t\t}\n\t}\n\treturn undefined;\n}\n\nfunction truncateExcerpt(text: string, maxChars: number): string {\n\tif (text.length <= maxChars) return text;\n\treturn `${text.slice(0, Math.max(0, maxChars - 1))}…`;\n}\n\nfunction buildBundle(options: ResearchRunnerOptions, parsed: ParsedResearchFindings): EvidenceBundle {\n\tconst contextRef: EvidenceRef = {\n\t\tid: \"src-context\",\n\t\tkind: \"user\",\n\t\ttitle: \"Goal/context provided to the research lane\",\n\t\ttrusted: true,\n\t\texcerpt: truncateExcerpt(options.context && options.context.length > 0 ? options.context : options.query, 2000),\n\t};\n\tconst synthesisRef: EvidenceRef = {\n\t\tid: \"src-synthesis\",\n\t\tkind: \"tool\",\n\t\ttitle: \"Research-model synthesis\",\n\t\ttrusted: false,\n\t};\n\tconst sources = [contextRef, synthesisRef].slice(0, Math.max(1, options.maxSources));\n\tconst findings: Finding[] = parsed.findings.slice(0, options.maxFindings).map((finding, index) => ({\n\t\tid: `finding-${index + 1}`,\n\t\tsummary: finding.summary,\n\t\tevidenceIds: [synthesisRef.id],\n\t\t...(finding.confidence !== undefined ? { confidence: finding.confidence } : {}),\n\t}));\n\treturn createEvidenceBundle({ query: options.query, sources, findings });\n}\n\nexport async function runResearch(options: ResearchRunnerOptions): Promise<ResearchRunResult> {\n\tconst gateOutcome = evaluateResearchRequest({\n\t\tenvelope: options.envelope,\n\t\tsourceKind: \"tool\",\n\t\testimatedUsd: options.maxUsd,\n\t});\n\tif (gateOutcome.outcome !== \"allow\") {\n\t\t// Skip-and-record, never prompt: gate denials inform diagnostics instead of blocking anything.\n\t\tconst status: ResearchRunStatus = gateOutcome.reasonCode === \"over_budget\" ? \"budget_exhausted\" : \"failed\";\n\t\treturn { status, reasonCode: gateOutcome.reasonCode, gateOutcome, costUsd: 0 };\n\t}\n\n\tconst bounded = await runBoundedCompletion({\n\t\tmaxWallClockMs: options.maxWallClockMs,\n\t\tsignal: options.signal,\n\t\texecute: (signal) =>\n\t\t\toptions.complete({\n\t\t\t\tsystemPrompt: RESEARCH_LANE_SYSTEM_PROMPT,\n\t\t\t\tuserPrompt: buildResearchUserPrompt(options),\n\t\t\t\tsignal,\n\t\t\t}),\n\t});\n\tif (bounded.failure) {\n\t\treturn {\n\t\t\tstatus: bounded.failure.status,\n\t\t\treasonCode: bounded.failure.reasonCode,\n\t\t\tgateOutcome,\n\t\t\tcostUsd: bounded.completion?.costUsd ?? 0,\n\t\t};\n\t}\n\tconst completion = bounded.completion;\n\tif (!completion) {\n\t\treturn { status: \"failed\", reasonCode: \"completion_error\", gateOutcome, costUsd: 0 };\n\t}\n\tif (completion.stopReason === \"error\" || completion.stopReason === \"aborted\") {\n\t\treturn { status: \"failed\", reasonCode: \"model_error\", gateOutcome, costUsd: completion.costUsd };\n\t}\n\n\tconst parsed = parseResearchFindings(completion.text, options.maxFindings);\n\tif (!parsed) {\n\t\treturn { status: \"failed\", reasonCode: \"unparseable_output\", gateOutcome, costUsd: completion.costUsd };\n\t}\n\n\tconst bundle = buildBundle(options, parsed);\n\tconst overBudget = options.maxUsd > 0 && completion.costUsd > options.maxUsd;\n\treturn {\n\t\tstatus: overBudget ? \"budget_exhausted\" : \"succeeded\",\n\t\treasonCode: overBudget\n\t\t\t? \"cost_budget_exceeded\"\n\t\t\t: parsed.findings.length === 0\n\t\t\t\t? \"no_findings\"\n\t\t\t\t: \"research_completed\",\n\t\tgateOutcome,\n\t\tbundle,\n\t\tcostUsd: completion.costUsd,\n\t};\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EvidenceBundle } from "../autonomy/contracts.ts";
|
|
2
|
+
import type { SessionEntry, SessionManager } from "../session-manager.ts";
|
|
3
|
+
export declare const EVIDENCE_BUNDLE_CUSTOM_TYPE = "evidence_bundle";
|
|
4
|
+
export interface EvidenceBundleSnapshotPayload {
|
|
5
|
+
version: 1;
|
|
6
|
+
bundle: EvidenceBundle;
|
|
7
|
+
}
|
|
8
|
+
export declare function appendEvidenceBundleSnapshot(sessionManager: Pick<SessionManager, "appendCustomEntry">, bundle: EvidenceBundle): string;
|
|
9
|
+
export declare function getEvidenceBundleSnapshots(entries: readonly SessionEntry[]): EvidenceBundle[];
|
|
10
|
+
export declare function getLatestEvidenceBundleSnapshot(entries: readonly SessionEntry[]): EvidenceBundle | undefined;
|
|
11
|
+
//# sourceMappingURL=session-evidence-bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-evidence-bundle.d.ts","sourceRoot":"","sources":["../../../src/core/research/session-evidence-bundle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG1E,eAAO,MAAM,2BAA2B,oBAAoB,CAAC;AAE7D,MAAM,WAAW,6BAA6B;IAC7C,OAAO,EAAE,CAAC,CAAC;IACX,MAAM,EAAE,cAAc,CAAC;CACvB;AAED,wBAAgB,4BAA4B,CAC3C,cAAc,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,CAAC,EACzD,MAAM,EAAE,cAAc,GACpB,MAAM,CAMR;AAQD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,cAAc,EAAE,CAmB7F;AAED,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,cAAc,GAAG,SAAS,CAe5G","sourcesContent":["import type { EvidenceBundle } from \"../autonomy/contracts.ts\";\nimport type { SessionEntry, SessionManager } from \"../session-manager.ts\";\nimport { cloneEvidenceBundleForStorage, isEvidenceBundle } from \"./evidence-bundle.ts\";\n\nexport const EVIDENCE_BUNDLE_CUSTOM_TYPE = \"evidence_bundle\";\n\nexport interface EvidenceBundleSnapshotPayload {\n\tversion: 1;\n\tbundle: EvidenceBundle;\n}\n\nexport function appendEvidenceBundleSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tbundle: EvidenceBundle,\n): string {\n\tconst payload: EvidenceBundleSnapshotPayload = {\n\t\tversion: 1,\n\t\tbundle: cloneEvidenceBundleForStorage(bundle),\n\t};\n\treturn sessionManager.appendCustomEntry(EVIDENCE_BUNDLE_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nexport function getEvidenceBundleSnapshots(entries: readonly SessionEntry[]): EvidenceBundle[] {\n\tconst bundles: EvidenceBundle[] = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== EVIDENCE_BUNDLE_CUSTOM_TYPE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst payload = entry.data;\n\t\tif (!isPlainRecord(payload)) continue;\n\t\tif (payload.version !== 1) continue;\n\t\tif (!(\"bundle\" in payload)) continue;\n\t\tconst bundle = payload.bundle;\n\t\tif (isEvidenceBundle(bundle)) {\n\t\t\tbundles.push(cloneEvidenceBundleForStorage(bundle));\n\t\t}\n\t}\n\n\treturn bundles;\n}\n\nexport function getLatestEvidenceBundleSnapshot(entries: readonly SessionEntry[]): EvidenceBundle | undefined {\n\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\tconst entry = entries[i];\n\t\tif (entry.type === \"custom\" && entry.customType === EVIDENCE_BUNDLE_CUSTOM_TYPE) {\n\t\t\tconst payload = entry.data;\n\t\t\tif (!isPlainRecord(payload)) continue;\n\t\t\tif (payload.version !== 1) continue;\n\t\t\tif (!(\"bundle\" in payload)) continue;\n\t\t\tconst bundle = payload.bundle;\n\t\t\tif (isEvidenceBundle(bundle)) {\n\t\t\t\treturn cloneEvidenceBundleForStorage(bundle);\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { cloneEvidenceBundleForStorage, isEvidenceBundle } from "./evidence-bundle.js";
|
|
2
|
+
export const EVIDENCE_BUNDLE_CUSTOM_TYPE = "evidence_bundle";
|
|
3
|
+
export function appendEvidenceBundleSnapshot(sessionManager, bundle) {
|
|
4
|
+
const payload = {
|
|
5
|
+
version: 1,
|
|
6
|
+
bundle: cloneEvidenceBundleForStorage(bundle),
|
|
7
|
+
};
|
|
8
|
+
return sessionManager.appendCustomEntry(EVIDENCE_BUNDLE_CUSTOM_TYPE, payload);
|
|
9
|
+
}
|
|
10
|
+
function isPlainRecord(value) {
|
|
11
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
12
|
+
return false;
|
|
13
|
+
const prototype = Object.getPrototypeOf(value);
|
|
14
|
+
return prototype === Object.prototype || prototype === null;
|
|
15
|
+
}
|
|
16
|
+
export function getEvidenceBundleSnapshots(entries) {
|
|
17
|
+
const bundles = [];
|
|
18
|
+
for (const entry of entries) {
|
|
19
|
+
if (entry.type !== "custom" || entry.customType !== EVIDENCE_BUNDLE_CUSTOM_TYPE) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
const payload = entry.data;
|
|
23
|
+
if (!isPlainRecord(payload))
|
|
24
|
+
continue;
|
|
25
|
+
if (payload.version !== 1)
|
|
26
|
+
continue;
|
|
27
|
+
if (!("bundle" in payload))
|
|
28
|
+
continue;
|
|
29
|
+
const bundle = payload.bundle;
|
|
30
|
+
if (isEvidenceBundle(bundle)) {
|
|
31
|
+
bundles.push(cloneEvidenceBundleForStorage(bundle));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return bundles;
|
|
35
|
+
}
|
|
36
|
+
export function getLatestEvidenceBundleSnapshot(entries) {
|
|
37
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
38
|
+
const entry = entries[i];
|
|
39
|
+
if (entry.type === "custom" && entry.customType === EVIDENCE_BUNDLE_CUSTOM_TYPE) {
|
|
40
|
+
const payload = entry.data;
|
|
41
|
+
if (!isPlainRecord(payload))
|
|
42
|
+
continue;
|
|
43
|
+
if (payload.version !== 1)
|
|
44
|
+
continue;
|
|
45
|
+
if (!("bundle" in payload))
|
|
46
|
+
continue;
|
|
47
|
+
const bundle = payload.bundle;
|
|
48
|
+
if (isEvidenceBundle(bundle)) {
|
|
49
|
+
return cloneEvidenceBundleForStorage(bundle);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=session-evidence-bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-evidence-bundle.js","sourceRoot":"","sources":["../../../src/core/research/session-evidence-bundle.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEvF,MAAM,CAAC,MAAM,2BAA2B,GAAG,iBAAiB,CAAC;AAO7D,MAAM,UAAU,4BAA4B,CAC3C,cAAyD,EACzD,MAAsB,EACb;IACT,MAAM,OAAO,GAAkC;QAC9C,OAAO,EAAE,CAAC;QACV,MAAM,EAAE,6BAA6B,CAAC,MAAM,CAAC;KAC7C,CAAC;IACF,OAAO,cAAc,CAAC,iBAAiB,CAAC,2BAA2B,EAAE,OAAO,CAAC,CAAC;AAAA,CAC9E;AAED,SAAS,aAAa,CAAC,KAAc,EAAoC;IACxE,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC9E,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC/C,OAAO,SAAS,KAAK,MAAM,CAAC,SAAS,IAAI,SAAS,KAAK,IAAI,CAAC;AAAA,CAC5D;AAED,MAAM,UAAU,0BAA0B,CAAC,OAAgC,EAAoB;IAC9F,MAAM,OAAO,GAAqB,EAAE,CAAC;IAErC,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,KAAK,2BAA2B,EAAE,CAAC;YACjF,SAAS;QACV,CAAC;QAED,MAAM,OAAO,GAAG,KA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Manager } from \"../session-manager.ts\";\nimport { cloneEvidenceBundleForStorage, isEvidenceBundle } from \"./evidence-bundle.ts\";\n\nexport const EVIDENCE_BUNDLE_CUSTOM_TYPE = \"evidence_bundle\";\n\nexport interface EvidenceBundleSnapshotPayload {\n\tversion: 1;\n\tbundle: EvidenceBundle;\n}\n\nexport function appendEvidenceBundleSnapshot(\n\tsessionManager: Pick<SessionManager, \"appendCustomEntry\">,\n\tbundle: EvidenceBundle,\n): string {\n\tconst payload: EvidenceBundleSnapshotPayload = {\n\t\tversion: 1,\n\t\tbundle: cloneEvidenceBundleForStorage(bundle),\n\t};\n\treturn sessionManager.appendCustomEntry(EVIDENCE_BUNDLE_CUSTOM_TYPE, payload);\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\tif (!value || typeof value !== \"object\" || Array.isArray(value)) return false;\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\nexport function getEvidenceBundleSnapshots(entries: readonly SessionEntry[]): EvidenceBundle[] {\n\tconst bundles: EvidenceBundle[] = [];\n\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"custom\" || entry.customType !== EVIDENCE_BUNDLE_CUSTOM_TYPE) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst payload = entry.data;\n\t\tif (!isPlainRecord(payload)) continue;\n\t\tif (payload.version !== 1) continue;\n\t\tif (!(\"bundle\" in payload)) continue;\n\t\tconst bundle = payload.bundle;\n\t\tif (isEvidenceBundle(bundle)) {\n\t\t\tbundles.push(cloneEvidenceBundleForStorage(bundle));\n\t\t}\n\t}\n\n\treturn bundles;\n}\n\nexport function getLatestEvidenceBundleSnapshot(entries: readonly SessionEntry[]): EvidenceBundle | undefined {\n\tfor (let i = entries.length - 1; i >= 0; i--) {\n\t\tconst entry = entries[i];\n\t\tif (entry.type === \"custom\" && entry.customType === EVIDENCE_BUNDLE_CUSTOM_TYPE) {\n\t\t\tconst payload = entry.data;\n\t\t\tif (!isPlainRecord(payload)) continue;\n\t\t\tif (payload.version !== 1) continue;\n\t\t\tif (!(\"bundle\" in payload)) continue;\n\t\t\tconst bundle = payload.bundle;\n\t\t\tif (isEvidenceBundle(bundle)) {\n\t\t\t\treturn cloneEvidenceBundleForStorage(bundle);\n\t\t\t}\n\t\t}\n\t}\n\treturn undefined;\n}\n"]}
|