@caupulican/pi-adaptative 0.81.41 → 0.81.42
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 +16 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/commands/text.py +5 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/context.py +3 -3
- package/dist/bundled-resources/runtimes/pi-shell-engine/errors.py +8 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/exec.py +26 -3
- package/dist/bundled-resources/runtimes/pi-shell-engine/expand.py +3 -0
- package/dist/bundled-resources/runtimes/pi-shell-engine/main.py +4 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/state.py +2 -1
- package/dist/bundled-resources/runtimes/pi-shell-engine/tokens.py +2 -0
- package/dist/core/agent-paths.d.ts +32 -0
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +65 -0
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/agent-session-contracts.d.ts +19 -1
- package/dist/core/agent-session-contracts.d.ts.map +1 -1
- package/dist/core/agent-session-contracts.js.map +1 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +4 -9
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +2 -0
- package/dist/core/autonomy/contracts.d.ts.map +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.js +4 -9
- package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts +3 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +17 -4
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/path-scope.d.ts +14 -0
- package/dist/core/autonomy/path-scope.d.ts.map +1 -1
- package/dist/core/autonomy/path-scope.js +37 -6
- package/dist/core/autonomy/path-scope.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +27 -1
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +32 -1
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/delegation/managed-lane-controller.d.ts +11 -1
- package/dist/core/delegation/managed-lane-controller.d.ts.map +1 -1
- package/dist/core/delegation/managed-lane-controller.js +84 -41
- package/dist/core/delegation/managed-lane-controller.js.map +1 -1
- package/dist/core/delegation/session-worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/session-worker-claim.js +4 -3
- package/dist/core/delegation/session-worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-action-journal.d.ts +73 -0
- package/dist/core/delegation/worker-action-journal.d.ts.map +1 -0
- package/dist/core/delegation/worker-action-journal.js +297 -0
- package/dist/core/delegation/worker-action-journal.js.map +1 -0
- package/dist/core/delegation/worker-actions.d.ts +36 -1
- package/dist/core/delegation/worker-actions.d.ts.map +1 -1
- package/dist/core/delegation/worker-actions.js +171 -46
- package/dist/core/delegation/worker-actions.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +75 -0
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-agent-control-coordinator.js +218 -0
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-agent-control.d.ts +66 -0
- package/dist/core/delegation/worker-agent-control.d.ts.map +1 -0
- package/dist/core/delegation/worker-agent-control.js +163 -0
- package/dist/core/delegation/worker-agent-control.js.map +1 -0
- package/dist/core/delegation/worker-attempt-executor.d.ts +80 -0
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -0
- package/dist/core/delegation/worker-attempt-executor.js +343 -0
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -0
- package/dist/core/delegation/worker-claim.d.ts +30 -0
- package/dist/core/delegation/worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/worker-claim.js +205 -53
- package/dist/core/delegation/worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-conversation-store.d.ts +116 -0
- package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -0
- package/dist/core/delegation/worker-conversation-store.js +442 -0
- package/dist/core/delegation/worker-conversation-store.js.map +1 -0
- package/dist/core/delegation/worker-delegation-controller.d.ts +21 -5
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +386 -251
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-delegation-request.d.ts +14 -0
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-request.js.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts +4 -2
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.js +16 -6
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
- package/dist/core/delegation/worker-execution-policy.d.ts +2 -1
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
- package/dist/core/delegation/worker-execution-policy.js +5 -7
- package/dist/core/delegation/worker-execution-policy.js.map +1 -1
- package/dist/core/delegation/worker-lifecycle.d.ts +44 -1
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js +120 -0
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-process-owner.d.ts +18 -0
- package/dist/core/delegation/worker-process-owner.d.ts.map +1 -0
- package/dist/core/delegation/worker-process-owner.js +54 -0
- package/dist/core/delegation/worker-process-owner.js.map +1 -0
- package/dist/core/delegation/worker-profile-resolver.d.ts +5 -1
- package/dist/core/delegation/worker-profile-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-profile-resolver.js +8 -0
- package/dist/core/delegation/worker-profile-resolver.js.map +1 -1
- package/dist/core/delegation/worker-recovery-coordinator.d.ts +54 -0
- package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-recovery-coordinator.js +181 -0
- package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-resource-catalog.d.ts +32 -0
- package/dist/core/delegation/worker-resource-catalog.d.ts.map +1 -0
- package/dist/core/delegation/worker-resource-catalog.js +116 -0
- package/dist/core/delegation/worker-resource-catalog.js.map +1 -0
- package/dist/core/delegation/worker-resource-materializer.d.ts +47 -0
- package/dist/core/delegation/worker-resource-materializer.d.ts.map +1 -0
- package/dist/core/delegation/worker-resource-materializer.js +137 -0
- package/dist/core/delegation/worker-resource-materializer.js.map +1 -0
- package/dist/core/delegation/worker-runner.d.ts +3 -1
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +189 -54
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-terminal-finalizer.d.ts +23 -0
- package/dist/core/delegation/worker-terminal-finalizer.d.ts.map +1 -0
- package/dist/core/delegation/worker-terminal-finalizer.js +12 -0
- package/dist/core/delegation/worker-terminal-finalizer.js.map +1 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +38 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.js +107 -0
- package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-write-reservation.d.ts +90 -0
- package/dist/core/delegation/worker-write-reservation.d.ts.map +1 -0
- package/dist/core/delegation/worker-write-reservation.js +348 -0
- package/dist/core/delegation/worker-write-reservation.js.map +1 -0
- package/dist/core/models/model-endpoint.d.ts +3 -0
- package/dist/core/models/model-endpoint.d.ts.map +1 -0
- package/dist/core/models/model-endpoint.js +11 -0
- package/dist/core/models/model-endpoint.js.map +1 -0
- package/dist/core/orchestration/agent-resume.d.ts +2 -0
- package/dist/core/orchestration/agent-resume.d.ts.map +1 -1
- package/dist/core/orchestration/agent-resume.js +7 -0
- package/dist/core/orchestration/agent-resume.js.map +1 -1
- package/dist/core/orchestration/attempt-usage.d.ts +28 -0
- package/dist/core/orchestration/attempt-usage.d.ts.map +1 -0
- package/dist/core/orchestration/attempt-usage.js +168 -0
- package/dist/core/orchestration/attempt-usage.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +19 -1
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +128 -28
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/contracts.d.ts +35 -0
- package/dist/core/orchestration/contracts.d.ts.map +1 -1
- package/dist/core/orchestration/contracts.js +17 -0
- package/dist/core/orchestration/contracts.js.map +1 -1
- package/dist/core/orchestration/delegation-ledger.d.ts +17 -2
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
- package/dist/core/orchestration/delegation-ledger.js +78 -3
- package/dist/core/orchestration/delegation-ledger.js.map +1 -1
- package/dist/core/orchestration/event-store.d.ts +1 -0
- package/dist/core/orchestration/event-store.d.ts.map +1 -1
- package/dist/core/orchestration/event-store.js +78 -38
- package/dist/core/orchestration/event-store.js.map +1 -1
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
- package/dist/core/orchestration/profile-registry.js +81 -41
- package/dist/core/orchestration/profile-registry.js.map +1 -1
- package/dist/core/orchestration/profile-store.d.ts.map +1 -1
- package/dist/core/orchestration/profile-store.js +18 -4
- package/dist/core/orchestration/profile-store.js.map +1 -1
- package/dist/core/orchestration/risk-budget.d.ts +2 -0
- package/dist/core/orchestration/risk-budget.d.ts.map +1 -1
- package/dist/core/orchestration/risk-budget.js +26 -0
- package/dist/core/orchestration/risk-budget.js.map +1 -1
- package/dist/core/orchestration/task-runtime.d.ts +13 -1
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
- package/dist/core/orchestration/task-runtime.js +127 -16
- package/dist/core/orchestration/task-runtime.js.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.d.ts +3 -1
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.js +75 -23
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
- package/dist/core/orchestration/worker-result-adapter.d.ts +9 -3
- package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
- package/dist/core/orchestration/worker-result-adapter.js +167 -14
- package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +1 -1
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +90 -54
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/research/evidence-bundle.d.ts +20 -0
- package/dist/core/research/evidence-bundle.d.ts.map +1 -1
- package/dist/core/research/evidence-bundle.js +173 -69
- package/dist/core/research/evidence-bundle.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +7 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +15 -1
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/session-artifact-bundle.d.ts +35 -0
- package/dist/core/session-artifact-bundle.d.ts.map +1 -0
- package/dist/core/session-artifact-bundle.js +61 -0
- package/dist/core/session-artifact-bundle.js.map +1 -0
- package/dist/core/tools/delegate-status.d.ts +6 -1
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +100 -18
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +9 -1
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +323 -61
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/run-process.d.ts +1 -1
- package/dist/core/tools/run-process.d.ts.map +1 -1
- package/dist/core/tools/run-process.js +69 -9
- package/dist/core/tools/run-process.js.map +1 -1
- package/dist/core/tools/shell-contract-router.d.ts.map +1 -1
- package/dist/core/tools/shell-contract-router.js +12 -5
- package/dist/core/tools/shell-contract-router.js.map +1 -1
- package/dist/core/util/bounded-file.d.ts +15 -0
- package/dist/core/util/bounded-file.d.ts.map +1 -0
- package/dist/core/util/bounded-file.js +120 -0
- package/dist/core/util/bounded-file.js.map +1 -0
- package/dist/core/util/bounded-jsonl.d.ts.map +1 -1
- package/dist/core/util/bounded-jsonl.js +119 -9
- package/dist/core/util/bounded-jsonl.js.map +1 -1
- package/dist/core/util/bounded-value.d.ts +3 -0
- package/dist/core/util/bounded-value.d.ts.map +1 -0
- package/dist/core/util/bounded-value.js +12 -0
- package/dist/core/util/bounded-value.js.map +1 -0
- package/dist/core/util/value-guards.d.ts +2 -0
- package/dist/core/util/value-guards.d.ts.map +1 -1
- package/dist/core/util/value-guards.js +5 -0
- package/dist/core/util/value-guards.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +27 -44
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/docs/tool-repair.md +3 -0
- package/docs/windows.md +4 -2
- 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 +12 -12
- package/package.json +4 -4
|
@@ -1,36 +1,184 @@
|
|
|
1
1
|
import { isPlainRecord } from "../util/value-guards.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
/** Bounds every durable evidence bundle, including worker-authored evidence. */
|
|
3
|
+
export const MAX_EVIDENCE_QUERY_CHARS = 4_096;
|
|
4
|
+
export const MAX_EVIDENCE_CREATED_AT_CHARS = 128;
|
|
5
|
+
export const MAX_EVIDENCE_SOURCES = 64;
|
|
6
|
+
export const MAX_EVIDENCE_FINDINGS = 64;
|
|
7
|
+
export const MAX_EVIDENCE_SOURCE_ID_CHARS = 256;
|
|
8
|
+
export const MAX_EVIDENCE_FINDING_ID_CHARS = 256;
|
|
9
|
+
export const MAX_EVIDENCE_TEXT_CHARS = 8_000;
|
|
10
|
+
export const MAX_EVIDENCE_EXCERPT_CHARS = 8_000;
|
|
11
|
+
export const MAX_EVIDENCE_IDS_PER_FINDING = 64;
|
|
12
|
+
export const MAX_EVIDENCE_METADATA_DEPTH = 8;
|
|
13
|
+
export const MAX_EVIDENCE_METADATA_ENTRIES = 64;
|
|
14
|
+
export const MAX_EVIDENCE_METADATA_ARRAY_ITEMS = 64;
|
|
15
|
+
export const MAX_EVIDENCE_METADATA_KEY_CHARS = 256;
|
|
16
|
+
export const MAX_EVIDENCE_METADATA_STRING_CHARS = 4_096;
|
|
17
|
+
function invalidEvidence(message) {
|
|
18
|
+
throw new Error(`Invalid evidence bundle: ${message}`);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Reads only own data properties. This is deliberately not Object.entries()/spread: snapshots
|
|
22
|
+
* and external lane reports are untrusted, and a getter must never execute while validating them.
|
|
23
|
+
*/
|
|
24
|
+
function ownDataRecord(value, label) {
|
|
25
|
+
if (!isPlainRecord(value))
|
|
26
|
+
invalidEvidence(`${label} must be a plain object.`);
|
|
27
|
+
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
28
|
+
const record = Object.create(null);
|
|
29
|
+
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
30
|
+
if (!("value" in descriptor))
|
|
31
|
+
invalidEvidence(`${label}.${key} must not be an accessor.`);
|
|
32
|
+
record[key] = descriptor.value;
|
|
8
33
|
}
|
|
34
|
+
return record;
|
|
35
|
+
}
|
|
36
|
+
function requiredBoundedString(value, label, maximumChars) {
|
|
37
|
+
if (typeof value !== "string" || value.length === 0)
|
|
38
|
+
invalidEvidence(`${label} must be a non-empty string.`);
|
|
39
|
+
if (value.length > maximumChars)
|
|
40
|
+
invalidEvidence(`${label} exceeds ${maximumChars} characters.`);
|
|
9
41
|
return value;
|
|
10
42
|
}
|
|
11
|
-
function
|
|
12
|
-
|
|
43
|
+
function optionalBoundedString(value, label, maximumChars) {
|
|
44
|
+
if (value === undefined)
|
|
45
|
+
return undefined;
|
|
46
|
+
return requiredBoundedString(value, label, maximumChars);
|
|
13
47
|
}
|
|
14
|
-
function
|
|
15
|
-
if (value
|
|
16
|
-
|
|
48
|
+
function boundedArray(value, label, maximumItems) {
|
|
49
|
+
if (!Array.isArray(value))
|
|
50
|
+
invalidEvidence(`${label} must be an array.`);
|
|
51
|
+
if (value.length > maximumItems)
|
|
52
|
+
invalidEvidence(`${label} exceeds ${maximumItems} entries.`);
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
function ownArrayValue(array, index, label) {
|
|
56
|
+
const descriptor = Object.getOwnPropertyDescriptor(array, String(index));
|
|
57
|
+
if (!descriptor || !("value" in descriptor))
|
|
58
|
+
invalidEvidence(`${label}[${index}] must be a data value.`);
|
|
59
|
+
return descriptor.value;
|
|
60
|
+
}
|
|
61
|
+
function normalizeJsonValue(value, label, depth) {
|
|
62
|
+
if (value === null || typeof value === "boolean")
|
|
63
|
+
return value;
|
|
64
|
+
if (typeof value === "string") {
|
|
65
|
+
if (value.length > MAX_EVIDENCE_METADATA_STRING_CHARS) {
|
|
66
|
+
invalidEvidence(`${label} exceeds ${MAX_EVIDENCE_METADATA_STRING_CHARS} characters.`);
|
|
67
|
+
}
|
|
68
|
+
return value;
|
|
17
69
|
}
|
|
18
70
|
if (typeof value === "number") {
|
|
19
|
-
|
|
71
|
+
if (!Number.isFinite(value))
|
|
72
|
+
invalidEvidence(`${label} must be finite.`);
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
if (depth >= MAX_EVIDENCE_METADATA_DEPTH) {
|
|
76
|
+
invalidEvidence(`${label} exceeds metadata depth ${MAX_EVIDENCE_METADATA_DEPTH}.`);
|
|
20
77
|
}
|
|
21
78
|
if (Array.isArray(value)) {
|
|
22
|
-
|
|
79
|
+
if (value.length > MAX_EVIDENCE_METADATA_ARRAY_ITEMS) {
|
|
80
|
+
invalidEvidence(`${label} exceeds ${MAX_EVIDENCE_METADATA_ARRAY_ITEMS} entries.`);
|
|
81
|
+
}
|
|
82
|
+
const copied = [];
|
|
83
|
+
for (let index = 0; index < value.length; index++) {
|
|
84
|
+
copied.push(normalizeJsonValue(ownArrayValue(value, index, label), `${label}[${index}]`, depth + 1));
|
|
85
|
+
}
|
|
86
|
+
return copied;
|
|
23
87
|
}
|
|
24
|
-
|
|
25
|
-
|
|
88
|
+
const record = ownDataRecord(value, label);
|
|
89
|
+
const entries = Object.entries(record);
|
|
90
|
+
if (entries.length > MAX_EVIDENCE_METADATA_ENTRIES) {
|
|
91
|
+
invalidEvidence(`${label} exceeds ${MAX_EVIDENCE_METADATA_ENTRIES} entries.`);
|
|
26
92
|
}
|
|
27
|
-
|
|
93
|
+
const copied = {};
|
|
94
|
+
for (const [key, nested] of entries) {
|
|
95
|
+
if (key.length > MAX_EVIDENCE_METADATA_KEY_CHARS) {
|
|
96
|
+
invalidEvidence(`${label} contains a key exceeding ${MAX_EVIDENCE_METADATA_KEY_CHARS} characters.`);
|
|
97
|
+
}
|
|
98
|
+
copied[key] = normalizeJsonValue(nested, `${label}.${key}`, depth + 1);
|
|
99
|
+
}
|
|
100
|
+
return copied;
|
|
28
101
|
}
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
102
|
+
function normalizeMetadata(value, label) {
|
|
103
|
+
const normalized = normalizeJsonValue(value, label, 0);
|
|
104
|
+
if (Array.isArray(normalized) || normalized === null || typeof normalized !== "object") {
|
|
105
|
+
invalidEvidence(`${label} must be an object.`);
|
|
32
106
|
}
|
|
33
|
-
return
|
|
107
|
+
return normalized;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Validates and copies an evidence bundle without invoking accessors or preserving unbounded
|
|
111
|
+
* foreign object graphs. This is the sole boundary used for durable worker-claim evidence.
|
|
112
|
+
*/
|
|
113
|
+
export function normalizeEvidenceBundleForStorage(value) {
|
|
114
|
+
const bundle = ownDataRecord(value, "bundle");
|
|
115
|
+
const query = requiredBoundedString(bundle.query, "bundle.query", MAX_EVIDENCE_QUERY_CHARS);
|
|
116
|
+
const createdAt = optionalBoundedString(bundle.createdAt, "bundle.createdAt", MAX_EVIDENCE_CREATED_AT_CHARS);
|
|
117
|
+
const sourceValues = boundedArray(bundle.sources, "bundle.sources", MAX_EVIDENCE_SOURCES);
|
|
118
|
+
const findingValues = boundedArray(bundle.findings, "bundle.findings", MAX_EVIDENCE_FINDINGS);
|
|
119
|
+
const sources = [];
|
|
120
|
+
for (let index = 0; index < sourceValues.length; index++) {
|
|
121
|
+
const source = ownDataRecord(ownArrayValue(sourceValues, index, "bundle.sources"), `bundle.sources[${index}]`);
|
|
122
|
+
const sourceKind = source.kind;
|
|
123
|
+
if (typeof sourceKind !== "string" ||
|
|
124
|
+
!["workspace", "transcript", "automata", "web", "user", "tool"].includes(sourceKind)) {
|
|
125
|
+
invalidEvidence(`bundle.sources[${index}].kind is invalid.`);
|
|
126
|
+
}
|
|
127
|
+
const kind = sourceKind;
|
|
128
|
+
if (typeof source.trusted !== "boolean")
|
|
129
|
+
invalidEvidence(`bundle.sources[${index}].trusted must be boolean.`);
|
|
130
|
+
sources.push({
|
|
131
|
+
id: requiredBoundedString(source.id, `bundle.sources[${index}].id`, MAX_EVIDENCE_SOURCE_ID_CHARS),
|
|
132
|
+
kind,
|
|
133
|
+
trusted: source.trusted,
|
|
134
|
+
...(source.title !== undefined
|
|
135
|
+
? { title: optionalBoundedString(source.title, `bundle.sources[${index}].title`, MAX_EVIDENCE_TEXT_CHARS) }
|
|
136
|
+
: {}),
|
|
137
|
+
...(source.uri !== undefined
|
|
138
|
+
? { uri: optionalBoundedString(source.uri, `bundle.sources[${index}].uri`, MAX_EVIDENCE_TEXT_CHARS) }
|
|
139
|
+
: {}),
|
|
140
|
+
...(source.excerpt !== undefined
|
|
141
|
+
? {
|
|
142
|
+
excerpt: optionalBoundedString(source.excerpt, `bundle.sources[${index}].excerpt`, MAX_EVIDENCE_EXCERPT_CHARS),
|
|
143
|
+
}
|
|
144
|
+
: {}),
|
|
145
|
+
...(source.metadata !== undefined
|
|
146
|
+
? { metadata: normalizeMetadata(source.metadata, `bundle.sources[${index}].metadata`) }
|
|
147
|
+
: {}),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const findings = [];
|
|
151
|
+
for (let index = 0; index < findingValues.length; index++) {
|
|
152
|
+
const finding = ownDataRecord(ownArrayValue(findingValues, index, "bundle.findings"), `bundle.findings[${index}]`);
|
|
153
|
+
const evidenceIdValues = boundedArray(finding.evidenceIds, `bundle.findings[${index}].evidenceIds`, MAX_EVIDENCE_IDS_PER_FINDING);
|
|
154
|
+
const evidenceIds = [];
|
|
155
|
+
for (let evidenceIndex = 0; evidenceIndex < evidenceIdValues.length; evidenceIndex++) {
|
|
156
|
+
evidenceIds.push(requiredBoundedString(ownArrayValue(evidenceIdValues, evidenceIndex, `bundle.findings[${index}].evidenceIds`), `bundle.findings[${index}].evidenceIds[${evidenceIndex}]`, MAX_EVIDENCE_SOURCE_ID_CHARS));
|
|
157
|
+
}
|
|
158
|
+
if (finding.confidence !== undefined &&
|
|
159
|
+
(typeof finding.confidence !== "number" || !Number.isFinite(finding.confidence))) {
|
|
160
|
+
invalidEvidence(`bundle.findings[${index}].confidence must be finite.`);
|
|
161
|
+
}
|
|
162
|
+
findings.push({
|
|
163
|
+
id: requiredBoundedString(finding.id, `bundle.findings[${index}].id`, MAX_EVIDENCE_FINDING_ID_CHARS),
|
|
164
|
+
summary: requiredBoundedString(finding.summary, `bundle.findings[${index}].summary`, MAX_EVIDENCE_TEXT_CHARS),
|
|
165
|
+
evidenceIds,
|
|
166
|
+
...(finding.confidence !== undefined ? { confidence: finding.confidence } : {}),
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return { query, sources, findings, ...(createdAt !== undefined ? { createdAt } : {}) };
|
|
170
|
+
}
|
|
171
|
+
function cloneJsonValue(value) {
|
|
172
|
+
if (Array.isArray(value)) {
|
|
173
|
+
return value.map(cloneJsonValue);
|
|
174
|
+
}
|
|
175
|
+
if (value !== null && typeof value === "object") {
|
|
176
|
+
return Object.fromEntries(Object.entries(value).map(([key, nested]) => [key, cloneJsonValue(nested)]));
|
|
177
|
+
}
|
|
178
|
+
return value;
|
|
179
|
+
}
|
|
180
|
+
function cloneJsonObject(value) {
|
|
181
|
+
return Object.fromEntries(Object.entries(value).map(([key, nested]) => [key, cloneJsonValue(nested)]));
|
|
34
182
|
}
|
|
35
183
|
function cloneEvidenceRef(source) {
|
|
36
184
|
return {
|
|
@@ -53,59 +201,15 @@ export function createEvidenceBundle(args) {
|
|
|
53
201
|
};
|
|
54
202
|
}
|
|
55
203
|
export function cloneEvidenceBundleForStorage(bundle) {
|
|
56
|
-
return
|
|
57
|
-
query: bundle.query,
|
|
58
|
-
sources: bundle.sources.map(cloneEvidenceRef),
|
|
59
|
-
findings: bundle.findings.map(cloneFinding),
|
|
60
|
-
createdAt: bundle.createdAt,
|
|
61
|
-
};
|
|
204
|
+
return normalizeEvidenceBundleForStorage(bundle);
|
|
62
205
|
}
|
|
63
206
|
export function isEvidenceBundle(value) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (typeof bundle.query !== "string")
|
|
68
|
-
return false;
|
|
69
|
-
if (bundle.createdAt !== undefined && typeof bundle.createdAt !== "string")
|
|
70
|
-
return false;
|
|
71
|
-
if (!Array.isArray(bundle.sources))
|
|
72
|
-
return false;
|
|
73
|
-
for (const source of bundle.sources) {
|
|
74
|
-
if (!isPlainRecord(source))
|
|
75
|
-
return false;
|
|
76
|
-
const ref = source;
|
|
77
|
-
if (typeof ref.id !== "string")
|
|
78
|
-
return false;
|
|
79
|
-
if (typeof ref.kind !== "string" ||
|
|
80
|
-
!["workspace", "transcript", "automata", "web", "user", "tool"].includes(ref.kind)) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
if (typeof ref.trusted !== "boolean")
|
|
84
|
-
return false;
|
|
85
|
-
if (ref.title !== undefined && typeof ref.title !== "string")
|
|
86
|
-
return false;
|
|
87
|
-
if (ref.uri !== undefined && typeof ref.uri !== "string")
|
|
88
|
-
return false;
|
|
89
|
-
if (ref.excerpt !== undefined && typeof ref.excerpt !== "string")
|
|
90
|
-
return false;
|
|
91
|
-
if (ref.metadata !== undefined && !isJsonObject(ref.metadata))
|
|
92
|
-
return false;
|
|
207
|
+
try {
|
|
208
|
+
normalizeEvidenceBundleForStorage(value);
|
|
209
|
+
return true;
|
|
93
210
|
}
|
|
94
|
-
|
|
211
|
+
catch {
|
|
95
212
|
return false;
|
|
96
|
-
for (const finding of bundle.findings) {
|
|
97
|
-
if (!isPlainRecord(finding))
|
|
98
|
-
return false;
|
|
99
|
-
const f = finding;
|
|
100
|
-
if (typeof f.id !== "string")
|
|
101
|
-
return false;
|
|
102
|
-
if (typeof f.summary !== "string")
|
|
103
|
-
return false;
|
|
104
|
-
if (f.confidence !== undefined && (typeof f.confidence !== "number" || !Number.isFinite(f.confidence)))
|
|
105
|
-
return false;
|
|
106
|
-
if (!Array.isArray(f.evidenceIds) || !f.evidenceIds.every((id) => typeof id === "string"))
|
|
107
|
-
return false;
|
|
108
213
|
}
|
|
109
|
-
return true;
|
|
110
214
|
}
|
|
111
215
|
//# sourceMappingURL=evidence-bundle.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evidence-bundle.js","sourceRoot":"","sources":["../../../src/core/research/evidence-bundle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,SAAS,cAAc,CAAC,KAAgB,EAAa;IACpD,IAAI,KAAK,CAAC,OAAO,C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IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC;YAAE,OAAO,KAAK,CAAC;IAC7E,CAAC;IAED,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC;QAAE,OAAO,KAAK,CAAC;IAClD,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QACvC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC;YAAE,OAAO,KAAK,CAAC;QAC1C,MAAM,CAAC,GAAG,OAAkC,CAAC;QAC7C,IAAI,OAAO,CAAC,CAAC,EAAE,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC3C,IAAI,OAAO,CAAC,CAAC,OAAO,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAChD,IAAI,CAAC,CAAC,UAAU,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,CAAC,UAAU,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;YACrG,OAAO,KAAK,CAAC;QACd,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,CAAC;YAAE,OAAO,KAAK,CAAC;IACzG,CAAC;IAED,OAAO,IAAI,CAAC;AAAA,CACZ","sourcesContent":["import type { EvidenceBundle, EvidenceRef, Finding, JsonObject, JsonValue } from \"../autonomy/contracts.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\nfunction cloneJsonValue(value: JsonValue): JsonValue {\n\tif (Array.isArray(value)) {\n\t\treturn value.map(cloneJsonValue);\n\t}\n\tif (value !== null && typeof value === \"object\") {\n\t\treturn Object.fromEntries(Object.entries(value).map(([key, nested]) => [key, cloneJsonValue(nested)]));\n\t}\n\treturn value;\n}\n\nfunction cloneJsonObject(value: JsonObject): JsonObject {\n\treturn Object.fromEntries(Object.entries(value).map(([key, nested]) => [key, cloneJsonValue(nested)]));\n}\n\nfunction isJsonValue(value: unknown): value is JsonValue {\n\tif (value === null || typeof value === \"string\" || typeof value === \"boolean\") {\n\t\treturn true;\n\t}\n\tif (typeof value === \"number\") {\n\t\treturn Number.isFinite(value);\n\t}\n\tif (Array.isArray(value)) {\n\t\treturn value.every(isJsonValue);\n\t}\n\tif (typeof value === \"object\") {\n\t\treturn isJsonObject(value);\n\t}\n\treturn false;\n}\n\nfunction isJsonObject(value: unknown): value is JsonObject {\n\tif (!isPlainRecord(value)) {\n\t\treturn false;\n\t}\n\treturn Object.values(value).every(isJsonValue);\n}\n\nfunction cloneEvidenceRef(source: EvidenceRef): EvidenceRef {\n\treturn {\n\t\t...source,\n\t\tmetadata: source.metadata ? cloneJsonObject(source.metadata) : undefined,\n\t};\n}\n\nfunction cloneFinding(finding: Finding): Finding {\n\treturn {\n\t\t...finding,\n\t\tevidenceIds: [...finding.evidenceIds],\n\t};\n}\n\nexport function createEvidenceBundle(args: {\n\tquery: string;\n\tsources: readonly EvidenceRef[];\n\tfindings: readonly Finding[];\n\tnow?: string;\n}): EvidenceBundle {\n\treturn {\n\t\tquery: args.query,\n\t\tsources: args.sources.map(cloneEvidenceRef),\n\t\tfindings: args.findings.map(cloneFinding),\n\t\tcreatedAt: args.now,\n\t};\n}\n\nexport function cloneEvidenceBundleForStorage(bundle: EvidenceBundle): EvidenceBundle {\n\treturn {\n\t\tquery: bundle.query,\n\t\tsources: bundle.sources.map(cloneEvidenceRef),\n\t\tfindings: bundle.findings.map(cloneFinding),\n\t\tcreatedAt: bundle.createdAt,\n\t};\n}\n\nexport function isEvidenceBundle(value: unknown): value is EvidenceBundle {\n\tif (!isPlainRecord(value)) return false;\n\tconst bundle = value as Record<string, unknown>;\n\n\tif (typeof bundle.query !== \"string\") return false;\n\tif (bundle.createdAt !== undefined && typeof bundle.createdAt !== \"string\") return false;\n\n\tif (!Array.isArray(bundle.sources)) return false;\n\tfor (const source of bundle.sources) {\n\t\tif (!isPlainRecord(source)) return false;\n\t\tconst ref = source as Record<string, unknown>;\n\t\tif (typeof ref.id !== \"string\") return false;\n\t\tif (\n\t\t\ttypeof ref.kind !== \"string\" ||\n\t\t\t![\"workspace\", \"transcript\", \"automata\", \"web\", \"user\", \"tool\"].includes(ref.kind)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\tif (typeof ref.trusted !== \"boolean\") return false;\n\t\tif (ref.title !== undefined && typeof ref.title !== \"string\") return false;\n\t\tif (ref.uri !== undefined && typeof ref.uri !== \"string\") return false;\n\t\tif (ref.excerpt !== undefined && typeof ref.excerpt !== \"string\") return false;\n\t\tif (ref.metadata !== undefined && !isJsonObject(ref.metadata)) return false;\n\t}\n\n\tif (!Array.isArray(bundle.findings)) return false;\n\tfor (const finding of bundle.findings) {\n\t\tif (!isPlainRecord(finding)) return false;\n\t\tconst f = finding as Record<string, unknown>;\n\t\tif (typeof f.id !== \"string\") return false;\n\t\tif (typeof f.summary !== \"string\") return false;\n\t\tif (f.confidence !== undefined && (typeof f.confidence !== \"number\" || !Number.isFinite(f.confidence)))\n\t\t\treturn false;\n\t\tif (!Array.isArray(f.evidenceIds) || !f.evidenceIds.every((id) => typeof id === \"string\")) return false;\n\t}\n\n\treturn true;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"evidence-bundle.js","sourceRoot":"","sources":["../../../src/core/research/evidence-bundle.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAExD,gFAAgF;AAChF,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC;AAC9C,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AACjD,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAA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CAAC,CAAC;AAAA,CACjD;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAA2B;IACzE,IAAI,CAAC;QACJ,iCAAiC,CAAC,KAAK,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC;IACb,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,KAAK,CAAC;IACd,CAAC;AAAA,CACD","sourcesContent":["import type {\n\tEvidenceBundle,\n\tEvidenceRef,\n\tEvidenceSourceKind,\n\tFinding,\n\tJsonObject,\n\tJsonValue,\n} from \"../autonomy/contracts.ts\";\nimport { isPlainRecord } from \"../util/value-guards.ts\";\n\n/** Bounds every durable evidence bundle, including worker-authored evidence. */\nexport const MAX_EVIDENCE_QUERY_CHARS = 4_096;\nexport const MAX_EVIDENCE_CREATED_AT_CHARS = 128;\nexport const MAX_EVIDENCE_SOURCES = 64;\nexport const MAX_EVIDENCE_FINDINGS = 64;\nexport const MAX_EVIDENCE_SOURCE_ID_CHARS = 256;\nexport const MAX_EVIDENCE_FINDING_ID_CHARS = 256;\nexport const MAX_EVIDENCE_TEXT_CHARS = 8_000;\nexport const MAX_EVIDENCE_EXCERPT_CHARS = 8_000;\nexport const MAX_EVIDENCE_IDS_PER_FINDING = 64;\nexport const MAX_EVIDENCE_METADATA_DEPTH = 8;\nexport const MAX_EVIDENCE_METADATA_ENTRIES = 64;\nexport const MAX_EVIDENCE_METADATA_ARRAY_ITEMS = 64;\nexport const MAX_EVIDENCE_METADATA_KEY_CHARS = 256;\nexport const MAX_EVIDENCE_METADATA_STRING_CHARS = 4_096;\n\nfunction invalidEvidence(message: string): never {\n\tthrow new Error(`Invalid evidence bundle: ${message}`);\n}\n\n/**\n * Reads only own data properties. This is deliberately not Object.entries()/spread: snapshots\n * and external lane reports are untrusted, and a getter must never execute while validating them.\n */\nfunction ownDataRecord(value: unknown, label: string): Record<string, unknown> {\n\tif (!isPlainRecord(value)) invalidEvidence(`${label} must be a plain object.`);\n\tconst descriptors = Object.getOwnPropertyDescriptors(value);\n\tconst record: Record<string, unknown> = Object.create(null) as Record<string, unknown>;\n\tfor (const [key, descriptor] of Object.entries(descriptors)) {\n\t\tif (!(\"value\" in descriptor)) invalidEvidence(`${label}.${key} must not be an accessor.`);\n\t\trecord[key] = descriptor.value;\n\t}\n\treturn record;\n}\n\nfunction requiredBoundedString(value: unknown, label: string, maximumChars: number): string {\n\tif (typeof value !== \"string\" || value.length === 0) invalidEvidence(`${label} must be a non-empty string.`);\n\tif (value.length > maximumChars) invalidEvidence(`${label} exceeds ${maximumChars} characters.`);\n\treturn value;\n}\n\nfunction optionalBoundedString(value: unknown, label: string, maximumChars: number): string | undefined {\n\tif (value === undefined) return undefined;\n\treturn requiredBoundedString(value, label, maximumChars);\n}\n\nfunction boundedArray(value: unknown, label: string, maximumItems: number): readonly unknown[] {\n\tif (!Array.isArray(value)) invalidEvidence(`${label} must be an array.`);\n\tif (value.length > maximumItems) invalidEvidence(`${label} exceeds ${maximumItems} entries.`);\n\treturn value;\n}\n\nfunction ownArrayValue(array: readonly unknown[], index: number, label: string): unknown {\n\tconst descriptor = Object.getOwnPropertyDescriptor(array, String(index));\n\tif (!descriptor || !(\"value\" in descriptor)) invalidEvidence(`${label}[${index}] must be a data value.`);\n\treturn descriptor.value;\n}\n\nfunction normalizeJsonValue(value: unknown, label: string, depth: number): JsonValue {\n\tif (value === null || typeof value === \"boolean\") return value;\n\tif (typeof value === \"string\") {\n\t\tif (value.length > MAX_EVIDENCE_METADATA_STRING_CHARS) {\n\t\t\tinvalidEvidence(`${label} exceeds ${MAX_EVIDENCE_METADATA_STRING_CHARS} characters.`);\n\t\t}\n\t\treturn value;\n\t}\n\tif (typeof value === \"number\") {\n\t\tif (!Number.isFinite(value)) invalidEvidence(`${label} must be finite.`);\n\t\treturn value;\n\t}\n\tif (depth >= MAX_EVIDENCE_METADATA_DEPTH) {\n\t\tinvalidEvidence(`${label} exceeds metadata depth ${MAX_EVIDENCE_METADATA_DEPTH}.`);\n\t}\n\tif (Array.isArray(value)) {\n\t\tif (value.length > MAX_EVIDENCE_METADATA_ARRAY_ITEMS) {\n\t\t\tinvalidEvidence(`${label} exceeds ${MAX_EVIDENCE_METADATA_ARRAY_ITEMS} entries.`);\n\t\t}\n\t\tconst copied: JsonValue[] = [];\n\t\tfor (let index = 0; index < value.length; index++) {\n\t\t\tcopied.push(normalizeJsonValue(ownArrayValue(value, index, label), `${label}[${index}]`, depth + 1));\n\t\t}\n\t\treturn copied;\n\t}\n\tconst record = ownDataRecord(value, label);\n\tconst entries = Object.entries(record);\n\tif (entries.length > MAX_EVIDENCE_METADATA_ENTRIES) {\n\t\tinvalidEvidence(`${label} exceeds ${MAX_EVIDENCE_METADATA_ENTRIES} entries.`);\n\t}\n\tconst copied: JsonObject = {};\n\tfor (const [key, nested] of entries) {\n\t\tif (key.length > MAX_EVIDENCE_METADATA_KEY_CHARS) {\n\t\t\tinvalidEvidence(`${label} contains a key exceeding ${MAX_EVIDENCE_METADATA_KEY_CHARS} characters.`);\n\t\t}\n\t\tcopied[key] = normalizeJsonValue(nested, `${label}.${key}`, depth + 1);\n\t}\n\treturn copied;\n}\n\nfunction normalizeMetadata(value: unknown, label: string): JsonObject {\n\tconst normalized = normalizeJsonValue(value, label, 0);\n\tif (Array.isArray(normalized) || normalized === null || typeof normalized !== \"object\") {\n\t\tinvalidEvidence(`${label} must be an object.`);\n\t}\n\treturn normalized;\n}\n\n/**\n * Validates and copies an evidence bundle without invoking accessors or preserving unbounded\n * foreign object graphs. This is the sole boundary used for durable worker-claim evidence.\n */\nexport function normalizeEvidenceBundleForStorage(value: unknown): EvidenceBundle {\n\tconst bundle = ownDataRecord(value, \"bundle\");\n\tconst query = requiredBoundedString(bundle.query, \"bundle.query\", MAX_EVIDENCE_QUERY_CHARS);\n\tconst createdAt = optionalBoundedString(bundle.createdAt, \"bundle.createdAt\", MAX_EVIDENCE_CREATED_AT_CHARS);\n\tconst sourceValues = boundedArray(bundle.sources, \"bundle.sources\", MAX_EVIDENCE_SOURCES);\n\tconst findingValues = boundedArray(bundle.findings, \"bundle.findings\", MAX_EVIDENCE_FINDINGS);\n\tconst sources: EvidenceRef[] = [];\n\tfor (let index = 0; index < sourceValues.length; index++) {\n\t\tconst source = ownDataRecord(ownArrayValue(sourceValues, index, \"bundle.sources\"), `bundle.sources[${index}]`);\n\t\tconst sourceKind = source.kind;\n\t\tif (\n\t\t\ttypeof sourceKind !== \"string\" ||\n\t\t\t![\"workspace\", \"transcript\", \"automata\", \"web\", \"user\", \"tool\"].includes(sourceKind)\n\t\t) {\n\t\t\tinvalidEvidence(`bundle.sources[${index}].kind is invalid.`);\n\t\t}\n\t\tconst kind = sourceKind as EvidenceSourceKind;\n\t\tif (typeof source.trusted !== \"boolean\") invalidEvidence(`bundle.sources[${index}].trusted must be boolean.`);\n\t\tsources.push({\n\t\t\tid: requiredBoundedString(source.id, `bundle.sources[${index}].id`, MAX_EVIDENCE_SOURCE_ID_CHARS),\n\t\t\tkind,\n\t\t\ttrusted: source.trusted,\n\t\t\t...(source.title !== undefined\n\t\t\t\t? { title: optionalBoundedString(source.title, `bundle.sources[${index}].title`, MAX_EVIDENCE_TEXT_CHARS) }\n\t\t\t\t: {}),\n\t\t\t...(source.uri !== undefined\n\t\t\t\t? { uri: optionalBoundedString(source.uri, `bundle.sources[${index}].uri`, MAX_EVIDENCE_TEXT_CHARS) }\n\t\t\t\t: {}),\n\t\t\t...(source.excerpt !== undefined\n\t\t\t\t? {\n\t\t\t\t\t\texcerpt: optionalBoundedString(\n\t\t\t\t\t\t\tsource.excerpt,\n\t\t\t\t\t\t\t`bundle.sources[${index}].excerpt`,\n\t\t\t\t\t\t\tMAX_EVIDENCE_EXCERPT_CHARS,\n\t\t\t\t\t\t),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t...(source.metadata !== undefined\n\t\t\t\t? { metadata: normalizeMetadata(source.metadata, `bundle.sources[${index}].metadata`) }\n\t\t\t\t: {}),\n\t\t});\n\t}\n\tconst findings: Finding[] = [];\n\tfor (let index = 0; index < findingValues.length; index++) {\n\t\tconst finding = ownDataRecord(\n\t\t\townArrayValue(findingValues, index, \"bundle.findings\"),\n\t\t\t`bundle.findings[${index}]`,\n\t\t);\n\t\tconst evidenceIdValues = boundedArray(\n\t\t\tfinding.evidenceIds,\n\t\t\t`bundle.findings[${index}].evidenceIds`,\n\t\t\tMAX_EVIDENCE_IDS_PER_FINDING,\n\t\t);\n\t\tconst evidenceIds: string[] = [];\n\t\tfor (let evidenceIndex = 0; evidenceIndex < evidenceIdValues.length; evidenceIndex++) {\n\t\t\tevidenceIds.push(\n\t\t\t\trequiredBoundedString(\n\t\t\t\t\townArrayValue(evidenceIdValues, evidenceIndex, `bundle.findings[${index}].evidenceIds`),\n\t\t\t\t\t`bundle.findings[${index}].evidenceIds[${evidenceIndex}]`,\n\t\t\t\t\tMAX_EVIDENCE_SOURCE_ID_CHARS,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tfinding.confidence !== undefined &&\n\t\t\t(typeof finding.confidence !== \"number\" || !Number.isFinite(finding.confidence))\n\t\t) {\n\t\t\tinvalidEvidence(`bundle.findings[${index}].confidence must be finite.`);\n\t\t}\n\t\tfindings.push({\n\t\t\tid: requiredBoundedString(finding.id, `bundle.findings[${index}].id`, MAX_EVIDENCE_FINDING_ID_CHARS),\n\t\t\tsummary: requiredBoundedString(finding.summary, `bundle.findings[${index}].summary`, MAX_EVIDENCE_TEXT_CHARS),\n\t\t\tevidenceIds,\n\t\t\t...(finding.confidence !== undefined ? { confidence: finding.confidence } : {}),\n\t\t});\n\t}\n\treturn { query, sources, findings, ...(createdAt !== undefined ? { createdAt } : {}) };\n}\n\nfunction cloneJsonValue(value: JsonValue): JsonValue {\n\tif (Array.isArray(value)) {\n\t\treturn value.map(cloneJsonValue);\n\t}\n\tif (value !== null && typeof value === \"object\") {\n\t\treturn Object.fromEntries(Object.entries(value).map(([key, nested]) => [key, cloneJsonValue(nested)]));\n\t}\n\treturn value;\n}\n\nfunction cloneJsonObject(value: JsonObject): JsonObject {\n\treturn Object.fromEntries(Object.entries(value).map(([key, nested]) => [key, cloneJsonValue(nested)]));\n}\n\nfunction cloneEvidenceRef(source: EvidenceRef): EvidenceRef {\n\treturn {\n\t\t...source,\n\t\tmetadata: source.metadata ? cloneJsonObject(source.metadata) : undefined,\n\t};\n}\n\nfunction cloneFinding(finding: Finding): Finding {\n\treturn {\n\t\t...finding,\n\t\tevidenceIds: [...finding.evidenceIds],\n\t};\n}\n\nexport function createEvidenceBundle(args: {\n\tquery: string;\n\tsources: readonly EvidenceRef[];\n\tfindings: readonly Finding[];\n\tnow?: string;\n}): EvidenceBundle {\n\treturn {\n\t\tquery: args.query,\n\t\tsources: args.sources.map(cloneEvidenceRef),\n\t\tfindings: args.findings.map(cloneFinding),\n\t\tcreatedAt: args.now,\n\t};\n}\n\nexport function cloneEvidenceBundleForStorage(bundle: EvidenceBundle): EvidenceBundle {\n\treturn normalizeEvidenceBundleForStorage(bundle);\n}\n\nexport function isEvidenceBundle(value: unknown): value is EvidenceBundle {\n\ttry {\n\t\tnormalizeEvidenceBundleForStorage(value);\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n"]}
|
|
@@ -41,6 +41,7 @@ import type { LaneRecord } from "./autonomy/lane-tracker.ts";
|
|
|
41
41
|
import type { ArtifactStore } from "./context/context-artifacts.ts";
|
|
42
42
|
import type { MemoryPromptInclusionReport, MemoryRetrievalDiagnostics } from "./context/memory-diagnostics.ts";
|
|
43
43
|
import type { ContextGcReport } from "./context-gc.ts";
|
|
44
|
+
import type { WorkerAgentControlPort } from "./delegation/worker-agent-control.ts";
|
|
44
45
|
import type { WorkerDelegationRequest } from "./delegation/worker-delegation-request.ts";
|
|
45
46
|
import type { ExtensionImportAuthority } from "./extension-import-authority.ts";
|
|
46
47
|
import { type ContextUsage, type Extension, type ExtensionCommandContextActions, type ExtensionErrorListener, ExtensionRunner, type ExtensionUIContext, type ShutdownHandler, type ToolDefinition, type ToolInfo } from "./extensions/index.ts";
|
|
@@ -72,6 +73,11 @@ export declare function hasAnsweredToolCallOnBranch(sessionManager: SessionManag
|
|
|
72
73
|
* production `getOpenTaskSteps` wiring below remains directly testable without another filter.
|
|
73
74
|
*/
|
|
74
75
|
export declare function deriveOpenTaskStepRefs(taskStepsState: TaskStepsState | undefined): OpenTaskStepRef[];
|
|
76
|
+
/** Bind goal-selected requirement identity as runtime metadata, outside the model-facing delegate schema. */
|
|
77
|
+
export declare function createGoalWorkerDelegationRequest(args: {
|
|
78
|
+
requirementId: string;
|
|
79
|
+
instructions: string;
|
|
80
|
+
}): WorkerDelegationRequest;
|
|
75
81
|
export interface RuntimeBuilderDeps {
|
|
76
82
|
/** Live agent — the snapshot/doctor read and restore its `state.tools` / `state.systemPrompt`. */
|
|
77
83
|
getAgent(): Agent;
|
|
@@ -175,6 +181,7 @@ export interface RuntimeBuilderDeps {
|
|
|
175
181
|
started: true;
|
|
176
182
|
record: LaneRecord;
|
|
177
183
|
};
|
|
184
|
+
workerAgentControl?: WorkerAgentControlPort;
|
|
178
185
|
getOrchestrationProfileCatalog(): Array<{
|
|
179
186
|
profileId: string;
|
|
180
187
|
role: string;
|