@caupulican/pi-adaptative 0.86.2 → 0.86.5
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 +40 -0
- package/dist/core/agent-paths.d.ts +13 -0
- package/dist/core/agent-paths.d.ts.map +1 -1
- package/dist/core/agent-paths.js +23 -0
- package/dist/core/agent-paths.js.map +1 -1
- package/dist/core/autonomy/bounded-completion.d.ts +7 -0
- package/dist/core/autonomy/bounded-completion.d.ts.map +1 -1
- package/dist/core/autonomy/bounded-completion.js +12 -4
- package/dist/core/autonomy/bounded-completion.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts +2 -0
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +6 -3
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/subagent-prompt.js +1 -1
- package/dist/core/autonomy/subagent-prompt.js.map +1 -1
- package/dist/core/background-lane-controller.d.ts +25 -2
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +67 -0
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/delegation/replay-safe-mailbox-bounds.d.ts +4 -0
- package/dist/core/delegation/replay-safe-mailbox-bounds.d.ts.map +1 -0
- package/dist/core/delegation/replay-safe-mailbox-bounds.js +20 -0
- package/dist/core/delegation/replay-safe-mailbox-bounds.js.map +1 -0
- package/dist/core/delegation/sanitized-context-fork.d.ts +25 -0
- package/dist/core/delegation/sanitized-context-fork.d.ts.map +1 -0
- package/dist/core/delegation/sanitized-context-fork.js +299 -0
- package/dist/core/delegation/sanitized-context-fork.js.map +1 -0
- package/dist/core/delegation/session-root-mailbox.d.ts +75 -0
- package/dist/core/delegation/session-root-mailbox.d.ts.map +1 -0
- package/dist/core/delegation/session-root-mailbox.js +627 -0
- package/dist/core/delegation/session-root-mailbox.js.map +1 -0
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts +102 -9
- package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +1307 -125
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-agent-control.d.ts +183 -8
- package/dist/core/delegation/worker-agent-control.d.ts.map +1 -1
- package/dist/core/delegation/worker-agent-control.js +778 -48
- package/dist/core/delegation/worker-agent-control.js.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts +9 -0
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.js +479 -214
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.d.ts +9 -0
- package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.js +22 -14
- package/dist/core/delegation/worker-authority-resolver.js.map +1 -1
- package/dist/core/delegation/worker-context-fork-store.d.ts +71 -0
- package/dist/core/delegation/worker-context-fork-store.d.ts.map +1 -0
- package/dist/core/delegation/worker-context-fork-store.js +437 -0
- package/dist/core/delegation/worker-context-fork-store.js.map +1 -0
- package/dist/core/delegation/worker-context-inheritance-policy.d.ts +18 -0
- package/dist/core/delegation/worker-context-inheritance-policy.d.ts.map +1 -0
- package/dist/core/delegation/worker-context-inheritance-policy.js +28 -0
- package/dist/core/delegation/worker-context-inheritance-policy.js.map +1 -0
- package/dist/core/delegation/worker-conversation-revision.d.ts +31 -0
- package/dist/core/delegation/worker-conversation-revision.d.ts.map +1 -0
- package/dist/core/delegation/worker-conversation-revision.js +203 -0
- package/dist/core/delegation/worker-conversation-revision.js.map +1 -0
- package/dist/core/delegation/worker-conversation-store.d.ts +130 -18
- package/dist/core/delegation/worker-conversation-store.d.ts.map +1 -1
- package/dist/core/delegation/worker-conversation-store.js +1263 -79
- package/dist/core/delegation/worker-conversation-store.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +29 -2
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +625 -111
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-delegation-request.d.ts +2 -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 +20 -1
- package/dist/core/delegation/worker-dispatch-scheduler.d.ts.map +1 -1
- package/dist/core/delegation/worker-dispatch-scheduler.js +210 -37
- package/dist/core/delegation/worker-dispatch-scheduler.js.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.d.ts +38 -0
- package/dist/core/delegation/worker-fleet-limits.d.ts.map +1 -0
- package/dist/core/delegation/worker-fleet-limits.js +113 -0
- package/dist/core/delegation/worker-fleet-limits.js.map +1 -0
- package/dist/core/delegation/worker-lane-projection.d.ts +1 -0
- package/dist/core/delegation/worker-lane-projection.d.ts.map +1 -1
- package/dist/core/delegation/worker-lane-projection.js +6 -2
- package/dist/core/delegation/worker-lane-projection.js.map +1 -1
- package/dist/core/delegation/worker-lifecycle.d.ts +20 -3
- package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
- package/dist/core/delegation/worker-lifecycle.js +42 -18
- package/dist/core/delegation/worker-lifecycle.js.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.d.ts +4 -0
- package/dist/core/delegation/worker-notification-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-notification-coordinator.js +45 -4
- package/dist/core/delegation/worker-notification-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-provider-turn-protocol.d.ts +50 -0
- package/dist/core/delegation/worker-provider-turn-protocol.d.ts.map +1 -0
- package/dist/core/delegation/worker-provider-turn-protocol.js +185 -0
- package/dist/core/delegation/worker-provider-turn-protocol.js.map +1 -0
- package/dist/core/delegation/worker-recovery-coordinator.d.ts +45 -4
- package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-recovery-coordinator.js +223 -17
- package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-retry-policy.d.ts +36 -0
- package/dist/core/delegation/worker-retry-policy.d.ts.map +1 -0
- package/dist/core/delegation/worker-retry-policy.js +41 -0
- package/dist/core/delegation/worker-retry-policy.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 +4 -2
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-task-view.d.ts +43 -0
- package/dist/core/delegation/worker-task-view.d.ts.map +1 -0
- package/dist/core/delegation/worker-task-view.js +194 -0
- package/dist/core/delegation/worker-task-view.js.map +1 -0
- package/dist/core/delegation/worker-terminal-handoff-coordinator.d.ts +55 -0
- package/dist/core/delegation/worker-terminal-handoff-coordinator.d.ts.map +1 -0
- package/dist/core/delegation/worker-terminal-handoff-coordinator.js +179 -0
- package/dist/core/delegation/worker-terminal-handoff-coordinator.js.map +1 -0
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts +2 -2
- package/dist/core/delegation/worker-tree-budget-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-tree-budget-coordinator.js +12 -46
- package/dist/core/delegation/worker-tree-budget-coordinator.js.map +1 -1
- package/dist/core/keybindings.d.ts +10 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +2 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/orchestration/attempt-ordering.d.ts +9 -0
- package/dist/core/orchestration/attempt-ordering.d.ts.map +1 -0
- package/dist/core/orchestration/attempt-ordering.js +29 -0
- package/dist/core/orchestration/attempt-ordering.js.map +1 -0
- package/dist/core/orchestration/capability-gateway.d.ts +19 -0
- package/dist/core/orchestration/capability-gateway.d.ts.map +1 -1
- package/dist/core/orchestration/capability-gateway.js +19 -2
- package/dist/core/orchestration/capability-gateway.js.map +1 -1
- package/dist/core/orchestration/contracts.d.ts +43 -3
- package/dist/core/orchestration/contracts.d.ts.map +1 -1
- package/dist/core/orchestration/contracts.js +24 -0
- package/dist/core/orchestration/contracts.js.map +1 -1
- package/dist/core/orchestration/delegation-ledger.d.ts +8 -3
- package/dist/core/orchestration/delegation-ledger.d.ts.map +1 -1
- package/dist/core/orchestration/delegation-ledger.js +148 -55
- package/dist/core/orchestration/delegation-ledger.js.map +1 -1
- package/dist/core/orchestration/event-store.d.ts +6 -3
- package/dist/core/orchestration/event-store.d.ts.map +1 -1
- package/dist/core/orchestration/event-store.js +228 -30
- package/dist/core/orchestration/event-store.js.map +1 -1
- package/dist/core/orchestration/task-runtime-codecs.d.ts +31 -0
- package/dist/core/orchestration/task-runtime-codecs.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime-codecs.js +1471 -0
- package/dist/core/orchestration/task-runtime-codecs.js.map +1 -0
- package/dist/core/orchestration/task-runtime-projection.d.ts +30 -0
- package/dist/core/orchestration/task-runtime-projection.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime-projection.js +340 -0
- package/dist/core/orchestration/task-runtime-projection.js.map +1 -0
- package/dist/core/orchestration/task-runtime-reducer.d.ts +38 -0
- package/dist/core/orchestration/task-runtime-reducer.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime-reducer.js +1270 -0
- package/dist/core/orchestration/task-runtime-reducer.js.map +1 -0
- package/dist/core/orchestration/task-runtime-state.d.ts +142 -0
- package/dist/core/orchestration/task-runtime-state.d.ts.map +1 -0
- package/dist/core/orchestration/task-runtime-state.js +14 -0
- package/dist/core/orchestration/task-runtime-state.js.map +1 -0
- package/dist/core/orchestration/task-runtime.d.ts +44 -98
- package/dist/core/orchestration/task-runtime.d.ts.map +1 -1
- package/dist/core/orchestration/task-runtime.js +357 -1113
- package/dist/core/orchestration/task-runtime.js.map +1 -1
- package/dist/core/orchestration/worker-context-fork-reference.d.ts +20 -0
- package/dist/core/orchestration/worker-context-fork-reference.d.ts.map +1 -0
- package/dist/core/orchestration/worker-context-fork-reference.js +53 -0
- package/dist/core/orchestration/worker-context-fork-reference.js.map +1 -0
- package/dist/core/research/research-runner.d.ts +2 -0
- package/dist/core/research/research-runner.d.ts.map +1 -1
- package/dist/core/research/research-runner.js +1 -0
- package/dist/core/research/research-runner.js.map +1 -1
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +8 -0
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/secrets/credential-project.d.ts.map +1 -1
- package/dist/core/secrets/credential-project.js +24 -2
- package/dist/core/secrets/credential-project.js.map +1 -1
- package/dist/core/security/secret-text.d.ts +3 -0
- package/dist/core/security/secret-text.d.ts.map +1 -1
- package/dist/core/security/secret-text.js +15 -0
- package/dist/core/security/secret-text.js.map +1 -1
- package/dist/core/settings-manager.d.ts +3 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +160 -8
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +31 -4
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +751 -98
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/activity-lane.d.ts +5 -0
- package/dist/modes/interactive/components/activity-lane.d.ts.map +1 -1
- package/dist/modes/interactive/components/activity-lane.js +133 -49
- package/dist/modes/interactive/components/activity-lane.js.map +1 -1
- package/dist/modes/interactive/components/agents-overlay.d.ts +40 -0
- package/dist/modes/interactive/components/agents-overlay.d.ts.map +1 -0
- package/dist/modes/interactive/components/agents-overlay.js +153 -0
- package/dist/modes/interactive/components/agents-overlay.js.map +1 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +18 -13
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.d.ts +1 -1
- package/dist/modes/interactive/interactive-event-controller.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.js +6 -3
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +5 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +51 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/key-handlers.d.ts +1 -0
- package/dist/modes/interactive/key-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/key-handlers.js +1 -0
- package/dist/modes/interactive/key-handlers.js.map +1 -1
- package/docs/harness-architecture.md +61 -17
- package/docs/settings.md +17 -9
- package/docs/worker-profiles.md +6 -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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-conversation-revision.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-conversation-revision.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,8BAA8B;IAC9C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,qBAAqB;IACrC,QAAQ,CAAC,QAAQ,EAAE,8BAA8B,CAAC;IAClD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED,qBAAa,gCAAiC,SAAQ,KAAK;IAC1D,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAkBD,wBAAgB,kCAAkC,CAAC,IAAI,EAAE,MAAM,GAAG,8BAA8B,CAE/F;AAED,wBAAgB,kCAAkC,CACjD,IAAI,EAAE,8BAA8B,EACpC,KAAK,EAAE,8BAA8B,GACnC,OAAO,CAQT;AAmED;;;;;;;;GAQG;AACH,wBAAgB,wCAAwC,CACvD,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,qBAAqB,EACnC,eAAe,EAAE,MAAM,GACrB,qBAAqB,CAQvB;AAED,wBAAgB,qBAAqB,CACpC,WAAW,EAAE,MAAM,EACnB,iBAAiB,EAAE,MAAM,EACzB,WAAW,EAAE,MAAM,EACnB,gBAAgB,CAAC,EAAE,MAAM,GACvB,qBAAqB,CAOvB"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { closeSync, fstatSync, openSync, readSync, statSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { CURRENT_SESSION_VERSION } from "@caupulican/pi-agent-core/session";
|
|
5
|
+
const MAX_WORKER_SESSION_HEADER_BYTES = 64 * 1024;
|
|
6
|
+
const WORKER_SESSION_ENTRY_DIGEST_SEED = createHash("sha256").update("pi-worker-session-entry-chain-v1").digest("hex");
|
|
7
|
+
export class WorkerConversationOwnershipError extends Error {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "WorkerConversationOwnershipError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function revisionFromStats(stats) {
|
|
14
|
+
return {
|
|
15
|
+
dev: stats.dev,
|
|
16
|
+
ino: stats.ino,
|
|
17
|
+
size: stats.size,
|
|
18
|
+
mtimeNs: stats.mtimeNs,
|
|
19
|
+
ctimeNs: stats.ctimeNs,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function readWorkerConversationFileRevision(file) {
|
|
23
|
+
return revisionFromStats(statSync(file, { bigint: true }));
|
|
24
|
+
}
|
|
25
|
+
export function sameWorkerConversationFileRevision(left, right) {
|
|
26
|
+
return (left.dev === right.dev &&
|
|
27
|
+
left.ino === right.ino &&
|
|
28
|
+
left.size === right.size &&
|
|
29
|
+
left.mtimeNs === right.mtimeNs &&
|
|
30
|
+
left.ctimeNs === right.ctimeNs);
|
|
31
|
+
}
|
|
32
|
+
function lineDigest(content) {
|
|
33
|
+
return createHash("sha256").update("pi-worker-session-line-v1").update("\0").update(content).digest("hex");
|
|
34
|
+
}
|
|
35
|
+
function nextEntryDigest(previous, byteLength, digest) {
|
|
36
|
+
return createHash("sha256")
|
|
37
|
+
.update("pi-worker-session-entry-chain-v1")
|
|
38
|
+
.update("\0")
|
|
39
|
+
.update(previous)
|
|
40
|
+
.update("\0")
|
|
41
|
+
.update(String(byteLength))
|
|
42
|
+
.update("\0")
|
|
43
|
+
.update(digest)
|
|
44
|
+
.digest("hex");
|
|
45
|
+
}
|
|
46
|
+
function verifyOwnedAppend(sessionFile, previousRevision, serialized) {
|
|
47
|
+
const expected = Buffer.from(`${serialized}\n`, "utf8");
|
|
48
|
+
const position = Number(previousRevision.size);
|
|
49
|
+
if (!Number.isSafeInteger(position)) {
|
|
50
|
+
throw new WorkerConversationOwnershipError("Worker conversation changed during its owned append.");
|
|
51
|
+
}
|
|
52
|
+
const fd = openSync(sessionFile, "r");
|
|
53
|
+
try {
|
|
54
|
+
const startRevision = revisionFromStats(fstatSync(fd, { bigint: true }));
|
|
55
|
+
if (startRevision.dev !== previousRevision.dev ||
|
|
56
|
+
startRevision.ino !== previousRevision.ino ||
|
|
57
|
+
startRevision.size !== previousRevision.size + BigInt(expected.length)) {
|
|
58
|
+
throw new WorkerConversationOwnershipError("Worker conversation changed during its owned append.");
|
|
59
|
+
}
|
|
60
|
+
const actual = Buffer.allocUnsafe(expected.length);
|
|
61
|
+
let bytesRead = 0;
|
|
62
|
+
while (bytesRead < actual.length) {
|
|
63
|
+
const count = readSync(fd, actual, bytesRead, actual.length - bytesRead, position + bytesRead);
|
|
64
|
+
if (count === 0) {
|
|
65
|
+
throw new WorkerConversationOwnershipError("Worker conversation changed during its owned append.");
|
|
66
|
+
}
|
|
67
|
+
bytesRead += count;
|
|
68
|
+
}
|
|
69
|
+
const endRevision = revisionFromStats(fstatSync(fd, { bigint: true }));
|
|
70
|
+
const pathRevision = readWorkerConversationFileRevision(sessionFile);
|
|
71
|
+
if (!sameWorkerConversationFileRevision(startRevision, endRevision) ||
|
|
72
|
+
!sameWorkerConversationFileRevision(endRevision, pathRevision) ||
|
|
73
|
+
!actual.equals(expected)) {
|
|
74
|
+
throw new WorkerConversationOwnershipError("Worker conversation changed during its owned append.");
|
|
75
|
+
}
|
|
76
|
+
const serializedBytes = actual.length - 1;
|
|
77
|
+
return {
|
|
78
|
+
revision: pathRevision,
|
|
79
|
+
serializedBytes,
|
|
80
|
+
digest: lineDigest(actual.subarray(0, serializedBytes)),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
closeSync(fd);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Verify the exact bytes appended by SessionManager and advance the trusted raw-file head once.
|
|
89
|
+
*
|
|
90
|
+
* The caller must hold the canonical conversation lock. That advisory lock excludes every
|
|
91
|
+
* supported writer, while revision/digest scans detect changes made between owned critical
|
|
92
|
+
* sections and during cold opens. This bounded append check intentionally reads only the new
|
|
93
|
+
* suffix: it cannot detect a noncooperating process rewriting an equal-length prefix inside the
|
|
94
|
+
* locked append window without reintroducing an O(n) prefix scan or a second durable authority.
|
|
95
|
+
*/
|
|
96
|
+
export function advanceWorkerSessionHeadAfterOwnedAppend(sessionFile, previousHead, serializedEntry) {
|
|
97
|
+
const append = verifyOwnedAppend(sessionFile, previousHead.revision, serializedEntry);
|
|
98
|
+
return {
|
|
99
|
+
revision: append.revision,
|
|
100
|
+
headerDigest: previousHead.headerDigest,
|
|
101
|
+
entryDigest: nextEntryDigest(previousHead.entryDigest, append.serializedBytes, append.digest),
|
|
102
|
+
entryCount: previousHead.entryCount + 1,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
export function scanWorkerSessionFile(sessionFile, expectedSessionId, expectedCwd, prefixEntryCount) {
|
|
106
|
+
const fd = openSync(sessionFile, "r");
|
|
107
|
+
try {
|
|
108
|
+
return scanOpenWorkerSessionFile(fd, sessionFile, expectedSessionId, expectedCwd, prefixEntryCount);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
closeSync(fd);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function scanOpenWorkerSessionFile(fd, sessionFile, expectedSessionId, expectedCwd, prefixEntryCount) {
|
|
115
|
+
const startRevision = revisionFromStats(fstatSync(fd, { bigint: true }));
|
|
116
|
+
const buffer = Buffer.allocUnsafe(64 * 1024);
|
|
117
|
+
let position = 0;
|
|
118
|
+
let lineBytes = 0;
|
|
119
|
+
let lineHash = createHash("sha256").update("pi-worker-session-line-v1").update("\0");
|
|
120
|
+
let lineIndex = 0;
|
|
121
|
+
let entryDigest = WORKER_SESSION_ENTRY_DIGEST_SEED;
|
|
122
|
+
let prefixDigest = prefixEntryCount === 0 ? entryDigest : undefined;
|
|
123
|
+
let headerDigest = "";
|
|
124
|
+
const headerParts = [];
|
|
125
|
+
let headerBytes = 0;
|
|
126
|
+
const finishLine = () => {
|
|
127
|
+
const digest = lineHash.digest("hex");
|
|
128
|
+
if (lineIndex === 0) {
|
|
129
|
+
headerDigest = digest;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
entryDigest = nextEntryDigest(entryDigest, lineBytes, digest);
|
|
133
|
+
if (lineIndex === prefixEntryCount)
|
|
134
|
+
prefixDigest = entryDigest;
|
|
135
|
+
}
|
|
136
|
+
lineIndex += 1;
|
|
137
|
+
lineBytes = 0;
|
|
138
|
+
lineHash = createHash("sha256").update("pi-worker-session-line-v1").update("\0");
|
|
139
|
+
};
|
|
140
|
+
while (true) {
|
|
141
|
+
const bytesRead = readSync(fd, buffer, 0, buffer.length, position);
|
|
142
|
+
if (bytesRead === 0)
|
|
143
|
+
break;
|
|
144
|
+
position += bytesRead;
|
|
145
|
+
let segmentStart = 0;
|
|
146
|
+
while (segmentStart < bytesRead) {
|
|
147
|
+
const newlineIndex = buffer.indexOf(0x0a, segmentStart);
|
|
148
|
+
const segmentEnd = newlineIndex < 0 || newlineIndex >= bytesRead ? bytesRead : newlineIndex;
|
|
149
|
+
const segment = buffer.subarray(segmentStart, segmentEnd);
|
|
150
|
+
lineHash.update(segment);
|
|
151
|
+
lineBytes += segment.length;
|
|
152
|
+
if (lineIndex === 0 && segment.length > 0) {
|
|
153
|
+
headerBytes += segment.length;
|
|
154
|
+
if (headerBytes > MAX_WORKER_SESSION_HEADER_BYTES) {
|
|
155
|
+
throw new WorkerConversationOwnershipError("Worker conversation session header exceeds its bound.");
|
|
156
|
+
}
|
|
157
|
+
headerParts.push(Buffer.from(segment));
|
|
158
|
+
}
|
|
159
|
+
if (newlineIndex < 0 || newlineIndex >= bytesRead)
|
|
160
|
+
break;
|
|
161
|
+
finishLine();
|
|
162
|
+
segmentStart = newlineIndex + 1;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const endRevision = revisionFromStats(fstatSync(fd, { bigint: true }));
|
|
166
|
+
if (!sameWorkerConversationFileRevision(startRevision, endRevision)) {
|
|
167
|
+
throw new WorkerConversationOwnershipError("Worker conversation session file changed while it was verified.");
|
|
168
|
+
}
|
|
169
|
+
if (lineBytes !== 0) {
|
|
170
|
+
throw new WorkerConversationOwnershipError("Worker conversation session file ends with a partial entry.");
|
|
171
|
+
}
|
|
172
|
+
if (lineIndex === 0)
|
|
173
|
+
throw new WorkerConversationOwnershipError("Worker conversation session header is missing.");
|
|
174
|
+
let header;
|
|
175
|
+
try {
|
|
176
|
+
header = JSON.parse(Buffer.concat(headerParts, headerBytes).toString("utf8"));
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
throw new WorkerConversationOwnershipError("Worker conversation session header is invalid.");
|
|
180
|
+
}
|
|
181
|
+
if (!header ||
|
|
182
|
+
typeof header !== "object" ||
|
|
183
|
+
Array.isArray(header) ||
|
|
184
|
+
header.type !== "session" ||
|
|
185
|
+
header.version !== CURRENT_SESSION_VERSION ||
|
|
186
|
+
header.id !== expectedSessionId ||
|
|
187
|
+
typeof header.cwd !== "string" ||
|
|
188
|
+
resolve(header.cwd) !== resolve(expectedCwd)) {
|
|
189
|
+
throw new WorkerConversationOwnershipError("Worker conversation session header changed identity.");
|
|
190
|
+
}
|
|
191
|
+
const revision = readWorkerConversationFileRevision(sessionFile);
|
|
192
|
+
if (!sameWorkerConversationFileRevision(revision, endRevision) || revision.size !== BigInt(position)) {
|
|
193
|
+
throw new WorkerConversationOwnershipError("Worker conversation session file changed while it was verified.");
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
revision,
|
|
197
|
+
headerDigest,
|
|
198
|
+
entryDigest,
|
|
199
|
+
entryCount: lineIndex - 1,
|
|
200
|
+
...(prefixDigest ? { prefixDigest } : {}),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=worker-conversation-revision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-conversation-revision.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-conversation-revision.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ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CAAC;IAClH,IAAI,MAAe,CAAC;IACpB,IAAI,CAAC;QACJ,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/E,CAAC;IAAC,MAAM,CAAC;QACR,MAAM,IAAI,gCAAgC,CAAC,gDAAgD,CAAC,CAAC;IAC9F,CAAC;IACD,IACC,CAAC,MAAM;QACP,OAAO,MAAM,KAAK,QAAQ;QAC1B,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACpB,MAA6B,CAAC,IAAI,KAAK,SAAS;QAChD,MAAgC,CAAC,OAAO,KAAK,uBAAuB;QACpE,MAA2B,CAAC,EAAE,KAAK,iBAAiB;QACrD,OAAQ,MAA4B,CAAC,GAAG,KAAK,QAAQ;QACrD,OAAO,CAAE,MAA0B,CAAC,GAAG,CAAC,KAAK,OAAO,CAAC,WAAW,CAAC,EAChE,CAAC;QACF,MAAM,IAAI,gCAAgC,CAAC,sDAAsD,CAAC,CAAC;IACpG,CAAC;IACD,MAAM,QAAQ,GAAG,kCAAkC,CAAC,WAAW,CAAC,CAAC;IACjE,IAAI,CAAC,kCAAkC,CAAC,QAAQ,EAAE,WAAW,CAAC,IAAI,QAAQ,CAAC,IAAI,KAAK,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtG,MAAM,IAAI,gCAAgC,CAAC,iEAAiE,CAAC,CAAC;IAC/G,CAAC;IACD,OAAO;QACN,QAAQ;QACR,YAAY;QACZ,WAAW;QACX,UAAU,EAAE,SAAS,GAAG,CAAC;QACzB,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzC,CAAC;AACH,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { closeSync, fstatSync, openSync, readSync, statSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { CURRENT_SESSION_VERSION } from \"@caupulican/pi-agent-core/session\";\n\nconst MAX_WORKER_SESSION_HEADER_BYTES = 64 * 1024;\nconst WORKER_SESSION_ENTRY_DIGEST_SEED = createHash(\"sha256\").update(\"pi-worker-session-entry-chain-v1\").digest(\"hex\");\n\nexport interface WorkerConversationFileRevision {\n\treadonly dev: bigint;\n\treadonly ino: bigint;\n\treadonly size: bigint;\n\treadonly mtimeNs: bigint;\n\treadonly ctimeNs: bigint;\n}\n\nexport interface WorkerSessionFileHead {\n\treadonly revision: WorkerConversationFileRevision;\n\treadonly headerDigest: string;\n\treadonly entryDigest: string;\n\treadonly entryCount: number;\n\treadonly prefixDigest?: string;\n}\n\nexport class WorkerConversationOwnershipError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"WorkerConversationOwnershipError\";\n\t}\n}\n\nfunction revisionFromStats(stats: {\n\tdev: bigint;\n\tino: bigint;\n\tsize: bigint;\n\tmtimeNs: bigint;\n\tctimeNs: bigint;\n}): WorkerConversationFileRevision {\n\treturn {\n\t\tdev: stats.dev,\n\t\tino: stats.ino,\n\t\tsize: stats.size,\n\t\tmtimeNs: stats.mtimeNs,\n\t\tctimeNs: stats.ctimeNs,\n\t};\n}\n\nexport function readWorkerConversationFileRevision(file: string): WorkerConversationFileRevision {\n\treturn revisionFromStats(statSync(file, { bigint: true }));\n}\n\nexport function sameWorkerConversationFileRevision(\n\tleft: WorkerConversationFileRevision,\n\tright: WorkerConversationFileRevision,\n): boolean {\n\treturn (\n\t\tleft.dev === right.dev &&\n\t\tleft.ino === right.ino &&\n\t\tleft.size === right.size &&\n\t\tleft.mtimeNs === right.mtimeNs &&\n\t\tleft.ctimeNs === right.ctimeNs\n\t);\n}\n\nfunction lineDigest(content: string | Buffer): string {\n\treturn createHash(\"sha256\").update(\"pi-worker-session-line-v1\").update(\"\\0\").update(content).digest(\"hex\");\n}\n\nfunction nextEntryDigest(previous: string, byteLength: number, digest: string): string {\n\treturn createHash(\"sha256\")\n\t\t.update(\"pi-worker-session-entry-chain-v1\")\n\t\t.update(\"\\0\")\n\t\t.update(previous)\n\t\t.update(\"\\0\")\n\t\t.update(String(byteLength))\n\t\t.update(\"\\0\")\n\t\t.update(digest)\n\t\t.digest(\"hex\");\n}\n\nfunction verifyOwnedAppend(\n\tsessionFile: string,\n\tpreviousRevision: WorkerConversationFileRevision,\n\tserialized: string,\n): { revision: WorkerConversationFileRevision; serializedBytes: number; digest: string } {\n\tconst expected = Buffer.from(`${serialized}\\n`, \"utf8\");\n\tconst position = Number(previousRevision.size);\n\tif (!Number.isSafeInteger(position)) {\n\t\tthrow new WorkerConversationOwnershipError(\"Worker conversation changed during its owned append.\");\n\t}\n\tconst fd = openSync(sessionFile, \"r\");\n\ttry {\n\t\tconst startRevision = revisionFromStats(fstatSync(fd, { bigint: true }));\n\t\tif (\n\t\t\tstartRevision.dev !== previousRevision.dev ||\n\t\t\tstartRevision.ino !== previousRevision.ino ||\n\t\t\tstartRevision.size !== previousRevision.size + BigInt(expected.length)\n\t\t) {\n\t\t\tthrow new WorkerConversationOwnershipError(\"Worker conversation changed during its owned append.\");\n\t\t}\n\t\tconst actual = Buffer.allocUnsafe(expected.length);\n\t\tlet bytesRead = 0;\n\t\twhile (bytesRead < actual.length) {\n\t\t\tconst count = readSync(fd, actual, bytesRead, actual.length - bytesRead, position + bytesRead);\n\t\t\tif (count === 0) {\n\t\t\t\tthrow new WorkerConversationOwnershipError(\"Worker conversation changed during its owned append.\");\n\t\t\t}\n\t\t\tbytesRead += count;\n\t\t}\n\t\tconst endRevision = revisionFromStats(fstatSync(fd, { bigint: true }));\n\t\tconst pathRevision = readWorkerConversationFileRevision(sessionFile);\n\t\tif (\n\t\t\t!sameWorkerConversationFileRevision(startRevision, endRevision) ||\n\t\t\t!sameWorkerConversationFileRevision(endRevision, pathRevision) ||\n\t\t\t!actual.equals(expected)\n\t\t) {\n\t\t\tthrow new WorkerConversationOwnershipError(\"Worker conversation changed during its owned append.\");\n\t\t}\n\t\tconst serializedBytes = actual.length - 1;\n\t\treturn {\n\t\t\trevision: pathRevision,\n\t\t\tserializedBytes,\n\t\t\tdigest: lineDigest(actual.subarray(0, serializedBytes)),\n\t\t};\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\n/**\n * Verify the exact bytes appended by SessionManager and advance the trusted raw-file head once.\n *\n * The caller must hold the canonical conversation lock. That advisory lock excludes every\n * supported writer, while revision/digest scans detect changes made between owned critical\n * sections and during cold opens. This bounded append check intentionally reads only the new\n * suffix: it cannot detect a noncooperating process rewriting an equal-length prefix inside the\n * locked append window without reintroducing an O(n) prefix scan or a second durable authority.\n */\nexport function advanceWorkerSessionHeadAfterOwnedAppend(\n\tsessionFile: string,\n\tpreviousHead: WorkerSessionFileHead,\n\tserializedEntry: string,\n): WorkerSessionFileHead {\n\tconst append = verifyOwnedAppend(sessionFile, previousHead.revision, serializedEntry);\n\treturn {\n\t\trevision: append.revision,\n\t\theaderDigest: previousHead.headerDigest,\n\t\tentryDigest: nextEntryDigest(previousHead.entryDigest, append.serializedBytes, append.digest),\n\t\tentryCount: previousHead.entryCount + 1,\n\t};\n}\n\nexport function scanWorkerSessionFile(\n\tsessionFile: string,\n\texpectedSessionId: string,\n\texpectedCwd: string,\n\tprefixEntryCount?: number,\n): WorkerSessionFileHead {\n\tconst fd = openSync(sessionFile, \"r\");\n\ttry {\n\t\treturn scanOpenWorkerSessionFile(fd, sessionFile, expectedSessionId, expectedCwd, prefixEntryCount);\n\t} finally {\n\t\tcloseSync(fd);\n\t}\n}\n\nfunction scanOpenWorkerSessionFile(\n\tfd: number,\n\tsessionFile: string,\n\texpectedSessionId: string,\n\texpectedCwd: string,\n\tprefixEntryCount?: number,\n): WorkerSessionFileHead {\n\tconst startRevision = revisionFromStats(fstatSync(fd, { bigint: true }));\n\tconst buffer = Buffer.allocUnsafe(64 * 1024);\n\tlet position = 0;\n\tlet lineBytes = 0;\n\tlet lineHash = createHash(\"sha256\").update(\"pi-worker-session-line-v1\").update(\"\\0\");\n\tlet lineIndex = 0;\n\tlet entryDigest = WORKER_SESSION_ENTRY_DIGEST_SEED;\n\tlet prefixDigest = prefixEntryCount === 0 ? entryDigest : undefined;\n\tlet headerDigest = \"\";\n\tconst headerParts: Buffer[] = [];\n\tlet headerBytes = 0;\n\n\tconst finishLine = (): void => {\n\t\tconst digest = lineHash.digest(\"hex\");\n\t\tif (lineIndex === 0) {\n\t\t\theaderDigest = digest;\n\t\t} else {\n\t\t\tentryDigest = nextEntryDigest(entryDigest, lineBytes, digest);\n\t\t\tif (lineIndex === prefixEntryCount) prefixDigest = entryDigest;\n\t\t}\n\t\tlineIndex += 1;\n\t\tlineBytes = 0;\n\t\tlineHash = createHash(\"sha256\").update(\"pi-worker-session-line-v1\").update(\"\\0\");\n\t};\n\n\twhile (true) {\n\t\tconst bytesRead = readSync(fd, buffer, 0, buffer.length, position);\n\t\tif (bytesRead === 0) break;\n\t\tposition += bytesRead;\n\t\tlet segmentStart = 0;\n\t\twhile (segmentStart < bytesRead) {\n\t\t\tconst newlineIndex = buffer.indexOf(0x0a, segmentStart);\n\t\t\tconst segmentEnd = newlineIndex < 0 || newlineIndex >= bytesRead ? bytesRead : newlineIndex;\n\t\t\tconst segment = buffer.subarray(segmentStart, segmentEnd);\n\t\t\tlineHash.update(segment);\n\t\t\tlineBytes += segment.length;\n\t\t\tif (lineIndex === 0 && segment.length > 0) {\n\t\t\t\theaderBytes += segment.length;\n\t\t\t\tif (headerBytes > MAX_WORKER_SESSION_HEADER_BYTES) {\n\t\t\t\t\tthrow new WorkerConversationOwnershipError(\"Worker conversation session header exceeds its bound.\");\n\t\t\t\t}\n\t\t\t\theaderParts.push(Buffer.from(segment));\n\t\t\t}\n\t\t\tif (newlineIndex < 0 || newlineIndex >= bytesRead) break;\n\t\t\tfinishLine();\n\t\t\tsegmentStart = newlineIndex + 1;\n\t\t}\n\t}\n\tconst endRevision = revisionFromStats(fstatSync(fd, { bigint: true }));\n\tif (!sameWorkerConversationFileRevision(startRevision, endRevision)) {\n\t\tthrow new WorkerConversationOwnershipError(\"Worker conversation session file changed while it was verified.\");\n\t}\n\tif (lineBytes !== 0) {\n\t\tthrow new WorkerConversationOwnershipError(\"Worker conversation session file ends with a partial entry.\");\n\t}\n\tif (lineIndex === 0) throw new WorkerConversationOwnershipError(\"Worker conversation session header is missing.\");\n\tlet header: unknown;\n\ttry {\n\t\theader = JSON.parse(Buffer.concat(headerParts, headerBytes).toString(\"utf8\"));\n\t} catch {\n\t\tthrow new WorkerConversationOwnershipError(\"Worker conversation session header is invalid.\");\n\t}\n\tif (\n\t\t!header ||\n\t\ttypeof header !== \"object\" ||\n\t\tArray.isArray(header) ||\n\t\t(header as { type?: unknown }).type !== \"session\" ||\n\t\t(header as { version?: unknown }).version !== CURRENT_SESSION_VERSION ||\n\t\t(header as { id?: unknown }).id !== expectedSessionId ||\n\t\ttypeof (header as { cwd?: unknown }).cwd !== \"string\" ||\n\t\tresolve((header as { cwd: string }).cwd) !== resolve(expectedCwd)\n\t) {\n\t\tthrow new WorkerConversationOwnershipError(\"Worker conversation session header changed identity.\");\n\t}\n\tconst revision = readWorkerConversationFileRevision(sessionFile);\n\tif (!sameWorkerConversationFileRevision(revision, endRevision) || revision.size !== BigInt(position)) {\n\t\tthrow new WorkerConversationOwnershipError(\"Worker conversation session file changed while it was verified.\");\n\t}\n\treturn {\n\t\trevision,\n\t\theaderDigest,\n\t\tentryDigest,\n\t\tentryCount: lineIndex - 1,\n\t\t...(prefixDigest ? { prefixDigest } : {}),\n\t};\n}\n"]}
|
|
@@ -2,6 +2,34 @@ import { type CompactionPreparation, type CompactionResult, estimateContextToken
|
|
|
2
2
|
import { type SessionContext, SessionManager } from "@caupulican/pi-agent-core/session";
|
|
3
3
|
import type { Message, Usage } from "@caupulican/pi-ai";
|
|
4
4
|
import type { AgentResumeContext, AttemptUsageSnapshot, ResourcePointer } from "../orchestration/contracts.ts";
|
|
5
|
+
import { type WorkerContextForkReference } from "../orchestration/worker-context-fork-reference.ts";
|
|
6
|
+
import { type WorkerConversationFileRevision, type WorkerSessionFileHead } from "./worker-conversation-revision.ts";
|
|
7
|
+
export declare const MAX_WORKER_TRANSCRIPT_PAGE_MESSAGES = 64;
|
|
8
|
+
export declare const MAX_WORKER_TRANSCRIPT_PAGE_BYTES: number;
|
|
9
|
+
interface WorkerConversationTranscriptPageOptions {
|
|
10
|
+
/** Opaque raw-entry offset returned by the previous page. */
|
|
11
|
+
cursor?: number;
|
|
12
|
+
maxMessages?: number;
|
|
13
|
+
maxBytes?: number;
|
|
14
|
+
}
|
|
15
|
+
interface WorkerConversationTranscriptPage {
|
|
16
|
+
/** Opaque raw-entry offset used for this page; it is not a message count. */
|
|
17
|
+
cursor: number;
|
|
18
|
+
messages: Message[];
|
|
19
|
+
nextCursor?: number;
|
|
20
|
+
/** Messages consumed but not cloned because one message exceeded the complete page byte ceiling. */
|
|
21
|
+
omittedMessages: number;
|
|
22
|
+
/** Exact UTF-8 JSON byte length of `messages`, including array framing. */
|
|
23
|
+
serializedBytes: number;
|
|
24
|
+
}
|
|
25
|
+
interface WorkerControlTranscriptExpectation {
|
|
26
|
+
messageId: string;
|
|
27
|
+
content: string;
|
|
28
|
+
}
|
|
29
|
+
interface WorkerControlTranscriptReconciliation {
|
|
30
|
+
delivered: boolean;
|
|
31
|
+
appended: boolean;
|
|
32
|
+
}
|
|
5
33
|
export interface CreateWorkerConversationOptions {
|
|
6
34
|
agentDir: string;
|
|
7
35
|
parentSessionId: string;
|
|
@@ -12,8 +40,10 @@ export interface CreateWorkerConversationOptions {
|
|
|
12
40
|
modelRef?: string;
|
|
13
41
|
resourceProfileNames: readonly string[];
|
|
14
42
|
contextPointers: readonly ResourcePointer[];
|
|
43
|
+
/** Immutable sanitized parent context captured before this logical agent is admitted. */
|
|
44
|
+
birthContextForkReference?: WorkerContextForkReference;
|
|
15
45
|
}
|
|
16
|
-
|
|
46
|
+
interface OpenWorkerConversationOptions {
|
|
17
47
|
agentDir: string;
|
|
18
48
|
resumeContext: AgentResumeContext;
|
|
19
49
|
expectedLogicalAgentId?: string;
|
|
@@ -45,23 +75,52 @@ export interface WorkerConversationRetentionPolicy {
|
|
|
45
75
|
*/
|
|
46
76
|
getFailedCompactionUsage?: () => Usage | undefined;
|
|
47
77
|
}
|
|
48
|
-
|
|
78
|
+
interface WorkerConversationRetentionOutcome {
|
|
49
79
|
status: "within_limit" | "compacted_verified" | "compacted_deterministic" | "cannot_compact";
|
|
50
80
|
context: SessionContext;
|
|
51
81
|
contextUsage: ReturnType<typeof estimateContextTokens>;
|
|
52
82
|
}
|
|
83
|
+
interface WorkerConversationMetadataState {
|
|
84
|
+
logicalAgentId: string;
|
|
85
|
+
parentSessionId?: string;
|
|
86
|
+
birthContextForkReference?: WorkerContextForkReference;
|
|
87
|
+
usageAccountingVersion?: 1;
|
|
88
|
+
}
|
|
89
|
+
interface WorkerConversationMetadataBinding extends WorkerConversationMetadataState {
|
|
90
|
+
file: string;
|
|
91
|
+
agentDir: string;
|
|
92
|
+
}
|
|
93
|
+
interface WorkerConversationCore {
|
|
94
|
+
sessionManager: SessionManager;
|
|
95
|
+
head?: WorkerSessionFileHead;
|
|
96
|
+
metadataRevision?: WorkerConversationFileRevision;
|
|
97
|
+
metadataState?: WorkerConversationMetadataState;
|
|
98
|
+
invalid: boolean;
|
|
99
|
+
generation: number;
|
|
100
|
+
activeTranscriptCursors: number;
|
|
101
|
+
}
|
|
102
|
+
export interface WorkerTranscriptCommitCursor {
|
|
103
|
+
readonly kind: "worker-transcript-suffix-v1";
|
|
104
|
+
}
|
|
53
105
|
/**
|
|
54
106
|
* Durable SessionManager-backed transcript for exactly one logical worker lane.
|
|
55
107
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* is its exact prefix.
|
|
108
|
+
* The canonical session-file lock plus a raw-byte revision head fences competing processes. One
|
|
109
|
+
* store shares the parsed core across lightweight resume-context views; unexpected durable changes
|
|
110
|
+
* fail closed for active owners and only strict append-only recovery may replace the core.
|
|
60
111
|
*/
|
|
61
112
|
export declare class WorkerConversation {
|
|
62
|
-
private readonly
|
|
113
|
+
private readonly core;
|
|
63
114
|
private readonly resumeContext;
|
|
64
|
-
|
|
115
|
+
private readonly agentDir?;
|
|
116
|
+
private readonly metadataFile?;
|
|
117
|
+
constructor(sessionManager: SessionManager, resumeContext: AgentResumeContext, metadata?: WorkerConversationMetadataBinding, sharedCore?: WorkerConversationCore);
|
|
118
|
+
private get sessionManager();
|
|
119
|
+
private set sessionManager(value);
|
|
120
|
+
/** Persisted conversations share one adopted metadata state; direct in-memory instances are current. */
|
|
121
|
+
private get usageAccountingVersion();
|
|
122
|
+
/** Immutable parent-context identity installed before this logical worker's first attempt. */
|
|
123
|
+
getBirthContextForkReference(): WorkerContextForkReference | undefined;
|
|
65
124
|
/** Resolve current provider-visible messages lazily through SessionManager. */
|
|
66
125
|
getProviderContext(): SessionContext;
|
|
67
126
|
/** Convert the current compacted projection at its transcript owner, never at each consumer. */
|
|
@@ -73,21 +132,58 @@ export declare class WorkerConversation {
|
|
|
73
132
|
* context. This is recovery/audit data; it is never loaded into a provider request implicitly.
|
|
74
133
|
*/
|
|
75
134
|
getRawTranscript(): Message[];
|
|
135
|
+
/**
|
|
136
|
+
* Read one bounded raw-transcript page without materializing the complete session entry list.
|
|
137
|
+
* A message larger than the complete page ceiling is consumed as an omission so every valid
|
|
138
|
+
* non-terminal cursor advances. The opaque cursor is a raw-entry offset, so each entry is visited
|
|
139
|
+
* at most once across a complete pagination pass and a page may contain no transcript messages.
|
|
140
|
+
* `serializedBytes` measures the returned `messages` JSON array.
|
|
141
|
+
*/
|
|
142
|
+
getRawTranscriptPage(options?: WorkerConversationTranscriptPageOptions): WorkerConversationTranscriptPage;
|
|
143
|
+
/** Last durable provider message owned by one attempt, never an earlier persistent-worker turn. */
|
|
144
|
+
getLastAttemptMessage(attemptId: string): Message | undefined;
|
|
76
145
|
/** Durable host-observed mutation progress. Custom entries never enter provider context. */
|
|
77
146
|
recordChangedFile(attemptId: string, filePath: string): void;
|
|
78
147
|
/** Rehydrate the bounded mutation set across owner-session disposal and worker resume. */
|
|
79
148
|
getChangedFiles(attemptId: string): string[];
|
|
149
|
+
/**
|
|
150
|
+
* Mark the first transcript entry owned by one durable attempt. Persistent logical workers share
|
|
151
|
+
* a conversation across tasks, so recovery accounting must not replay an earlier task's spend as
|
|
152
|
+
* the new attempt's baseline. The marker is idempotent and never enters provider context.
|
|
153
|
+
*/
|
|
154
|
+
beginAttemptUsage(attemptId: string): void;
|
|
155
|
+
/**
|
|
156
|
+
* Persist the authoritative task prompt once inside its durable attempt boundary. The boundary,
|
|
157
|
+
* rather than provider-history length, is the idempotency owner: inherited birth messages and
|
|
158
|
+
* queued mailbox controls may already exist, while a crash after append must not duplicate the
|
|
159
|
+
* prompt on resume.
|
|
160
|
+
*/
|
|
161
|
+
ensureAttemptUserPrompt(attemptId: string, prompt: string): void;
|
|
162
|
+
/** Whether missing attempt markers have versioned, fail-closed accounting semantics. */
|
|
163
|
+
usesAttemptUsageBoundaries(): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Upgrade a legacy idle conversation before its next durable task is prepared. Persisting this
|
|
166
|
+
* evidence first closes the crash window where the task exists but its transcript marker does not.
|
|
167
|
+
*/
|
|
168
|
+
enableAttemptUsageBoundaries(): void;
|
|
80
169
|
/**
|
|
81
170
|
* Recover cumulative accounting from raw entry metadata without cloning or resolving message
|
|
82
|
-
* payloads that compaction deliberately moved out of the provider-visible working set.
|
|
171
|
+
* payloads that compaction deliberately moved out of the provider-visible working set. Attempts
|
|
172
|
+
* created before usage boundaries existed conservatively fall back to the complete transcript.
|
|
83
173
|
*/
|
|
84
|
-
getRawTranscriptUsage(): AttemptUsageSnapshot;
|
|
174
|
+
getRawTranscriptUsage(attemptId?: string): AttemptUsageSnapshot;
|
|
85
175
|
/**
|
|
86
176
|
* Locate a bounded set of durable mailbox delivery commits without materializing or cloning the
|
|
87
177
|
* complete raw transcript. Recovery uses this only to close the narrow crash window after a
|
|
88
178
|
* control message was appended but before its mailbox acknowledgement was persisted.
|
|
89
179
|
*/
|
|
90
|
-
findDeliveredWorkerControlMessageIds(
|
|
180
|
+
findDeliveredWorkerControlMessageIds(expectations: readonly WorkerControlTranscriptExpectation[]): Set<string>;
|
|
181
|
+
/**
|
|
182
|
+
* Atomically prove one exact worker-control identity and optionally append it. Reopening inside
|
|
183
|
+
* the canonical session-file lock makes two stale recovery owners serialize on the latest durable
|
|
184
|
+
* transcript instead of both observing absence and appending a duplicate.
|
|
185
|
+
*/
|
|
186
|
+
reconcileWorkerControlMessage(expectation: WorkerControlTranscriptExpectation, message: Message, appendIfMissing: boolean): WorkerControlTranscriptReconciliation;
|
|
91
187
|
/**
|
|
92
188
|
* Append one shared-compaction checkpoint when the current provider-visible context exceeds the
|
|
93
189
|
* explicit worker policy. The source transcript remains append-only; only the projection sent to
|
|
@@ -96,22 +192,38 @@ export declare class WorkerConversation {
|
|
|
96
192
|
compactProviderContext(policy: WorkerConversationRetentionPolicy, signal?: AbortSignal): Promise<WorkerConversationRetentionOutcome>;
|
|
97
193
|
/** Append one already-authorized worker message to the canonical transcript. */
|
|
98
194
|
appendMessage(message: Message): string;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
195
|
+
private appendSessionEntry;
|
|
196
|
+
private appendSessionEntryLocked;
|
|
197
|
+
private reopenVerifiedSessionManagerLocked;
|
|
198
|
+
private synchronizeCoreLocked;
|
|
199
|
+
/** Store-only refresh while the canonical session-file lock is already held. */
|
|
200
|
+
refreshCachedCoreLocked(): void;
|
|
201
|
+
private captureTranscriptCommitCursorLocked;
|
|
202
|
+
/** Atomically capture the provider projection and the raw-entry cursor that immediately follows it. */
|
|
203
|
+
beginTranscriptCommit(): {
|
|
204
|
+
history: Message[];
|
|
205
|
+
cursor: WorkerTranscriptCommitCursor;
|
|
206
|
+
};
|
|
207
|
+
private withCanonicalSessionLock;
|
|
208
|
+
/** Commit only the bounded child-loop suffix captured by an opaque raw-entry cursor. */
|
|
209
|
+
captureTranscriptCommitCursor(): WorkerTranscriptCommitCursor;
|
|
210
|
+
abortTranscriptCommit(cursor: WorkerTranscriptCommitCursor): void;
|
|
211
|
+
commitTranscript(cursor: WorkerTranscriptCommitCursor, suffix: readonly Message[], options?: {
|
|
212
|
+
appendMissing?: boolean;
|
|
213
|
+
}): number;
|
|
106
214
|
/** Return an isolated copy suitable for durable orchestration/process-resume state. */
|
|
107
215
|
getResumeContext(): AgentResumeContext;
|
|
108
216
|
}
|
|
109
217
|
/** Creates and reopens canonical SessionManager transcripts for logical Pi worker lanes. */
|
|
110
218
|
export declare class WorkerConversationStore {
|
|
219
|
+
private readonly cachedCores;
|
|
220
|
+
clearCache(): void;
|
|
111
221
|
create(options: CreateWorkerConversationOptions): WorkerConversation;
|
|
112
222
|
private createLocked;
|
|
113
223
|
/** Open the one canonical transcript or atomically create it with the exact same durable identity. */
|
|
114
224
|
ensure(options: CreateWorkerConversationOptions): WorkerConversation;
|
|
115
225
|
open(options: OpenWorkerConversationOptions): WorkerConversation;
|
|
226
|
+
private openExisting;
|
|
116
227
|
}
|
|
228
|
+
export {};
|
|
117
229
|
//# sourceMappingURL=worker-conversation-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-conversation-store.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-conversation-store.ts"],"names":[],"mappings":"AAIA,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EAErB,qBAAqB,EAErB,MAAM,iDAAiD,CAAC;
|
|
1
|
+
{"version":3,"file":"worker-conversation-store.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-conversation-store.ts"],"names":[],"mappings":"AAIA,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EAErB,qBAAqB,EAErB,MAAM,iDAAiD,CAAC;AAGzD,OAAO,EAG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