@code-yeongyu/senpi-agent-core 2026.11.3-1 → 2026.11.3-3
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/dist/conformance/index.d.ts +14 -0
- package/dist/conformance/index.js +8 -0
- package/dist/conformance/registry.js +22 -0
- package/dist/execution/coordinator-codec.d.ts +5 -0
- package/dist/execution/coordinator-codec.js +93 -0
- package/dist/execution/coordinator-plan.d.ts +33 -0
- package/dist/execution/coordinator-plan.js +106 -0
- package/dist/execution/coordinator-types.d.ts +116 -0
- package/dist/execution/coordinator-types.js +2 -0
- package/dist/execution/coordinator.d.ts +25 -0
- package/dist/execution/coordinator.js +132 -0
- package/dist/execution/grant-verify.d.ts +70 -0
- package/dist/execution/grant-verify.js +87 -0
- package/dist/execution/ledger-codec.js +1 -0
- package/dist/execution/ledger-transition.js +8 -0
- package/dist/execution/ledger-types.d.ts +10 -0
- package/dist/execution/ledger.d.ts +2 -0
- package/dist/execution/ledger.js +1 -0
- package/dist/execution/remote-executor.d.ts +64 -0
- package/dist/execution/remote-executor.js +159 -0
- package/dist/execution/remote-hand-ledger.d.ts +40 -0
- package/dist/execution/remote-hand-ledger.js +137 -0
- package/dist/execution/remote-protocol.d.ts +87 -0
- package/dist/execution/remote-protocol.js +88 -0
- package/dist/execution/remote-tool-host.d.ts +29 -0
- package/dist/execution/remote-tool-host.js +155 -0
- package/dist/execution/testing/batch-cases.d.ts +6 -0
- package/dist/execution/testing/batch-cases.js +210 -0
- package/dist/execution/testing/batch-executor.d.ts +34 -0
- package/dist/execution/testing/batch-executor.js +141 -0
- package/dist/execution/testing/batch-harness.d.ts +36 -0
- package/dist/execution/testing/batch-harness.js +208 -0
- package/dist/execution/testing/batch-registry.d.ts +3 -0
- package/dist/execution/testing/batch-registry.js +30 -0
- package/dist/execution/testing/fault-hand-cases.d.ts +6 -0
- package/dist/execution/testing/fault-hand-cases.js +70 -0
- package/dist/execution/testing/hand-harness.d.ts +48 -0
- package/dist/execution/testing/hand-harness.js +136 -0
- package/dist/execution/testing/kill-batch.d.ts +12 -0
- package/dist/execution/testing/kill-batch.js +70 -0
- package/dist/execution/testing/kill-hand.d.ts +16 -0
- package/dist/execution/testing/kill-hand.js +75 -0
- package/dist/execution/testing/ledger-cases.js +9 -0
- package/dist/execution/testing/multi-hand-cases.d.ts +6 -0
- package/dist/execution/testing/multi-hand-cases.js +44 -0
- package/dist/execution/testing/prep-cases.d.ts +57 -0
- package/dist/execution/testing/prep-cases.js +89 -0
- package/dist/harness/env/nodejs.js +4 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +8 -0
- package/package.json +3 -3
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createAdmissionLine } from "../../durable/store-admission.js";
|
|
2
|
+
import { createManualTimers } from "../../durable/testing/manual-timers.js";
|
|
3
|
+
import { claimedStore } from "../../durable/testing/store-cases.js";
|
|
4
|
+
import { createInProcessNetwork } from "../../transport/in-process-carrier.js";
|
|
5
|
+
import { localEndpoint } from "../../transport/local-endpoint.js";
|
|
6
|
+
import { createExecutionLedger } from "../ledger.js";
|
|
7
|
+
import { createRemoteExecutor } from "../remote-executor.js";
|
|
8
|
+
import { createHandLedger } from "../remote-hand-ledger.js";
|
|
9
|
+
import { createRemoteToolHost } from "../remote-tool-host.js";
|
|
10
|
+
const TICK_MS = 5;
|
|
11
|
+
const LEASE_MS = 3_600_000;
|
|
12
|
+
const drain = async () => {
|
|
13
|
+
for (let turn = 0; turn < 32; turn++)
|
|
14
|
+
await Promise.resolve();
|
|
15
|
+
};
|
|
16
|
+
export function call(id) {
|
|
17
|
+
return { type: "toolCall", id, name: "probe", arguments: { id } };
|
|
18
|
+
}
|
|
19
|
+
export async function openHandRig(adapters, options) {
|
|
20
|
+
const timers = createManualTimers(1_000);
|
|
21
|
+
const network = createInProcessNetwork({ schedule: (deliver) => void timers.setTimer(deliver, 0) });
|
|
22
|
+
const sessionSide = adapters.transport.createSide(timers);
|
|
23
|
+
const handSide = adapters.transport.createSide(timers);
|
|
24
|
+
const installed = options.fault?.(timers);
|
|
25
|
+
const outer = (side) => (installed === undefined ? side : installed.wrap(side));
|
|
26
|
+
const endpoint = localEndpoint(adapters.platform, "hand-conformance", "/run/senpi-conformance");
|
|
27
|
+
network.listen(endpoint, outer(handSide));
|
|
28
|
+
const link = network.dial(endpoint, outer(sessionSide));
|
|
29
|
+
link.connect();
|
|
30
|
+
installed?.start(link);
|
|
31
|
+
const { medium } = await claimedStore(adapters.store);
|
|
32
|
+
const bodies = [];
|
|
33
|
+
const faults = [];
|
|
34
|
+
const gates = new Map();
|
|
35
|
+
let gated = false;
|
|
36
|
+
const killed = Promise.withResolvers();
|
|
37
|
+
const scopeRunner = (scopeId) => ({
|
|
38
|
+
run: async (handCall) => {
|
|
39
|
+
bodies.push(`${scopeId}:${handCall.toolCallId}`);
|
|
40
|
+
if (gated) {
|
|
41
|
+
const gate = gates.get(handCall.toolCallId) ?? Promise.withResolvers();
|
|
42
|
+
gates.set(handCall.toolCallId, gate);
|
|
43
|
+
await gate.promise;
|
|
44
|
+
}
|
|
45
|
+
return { content: [{ type: "text", text: `ran:${handCall.toolCallId}` }], details: {} };
|
|
46
|
+
},
|
|
47
|
+
isSequential: () => false,
|
|
48
|
+
dispose: async () => { },
|
|
49
|
+
});
|
|
50
|
+
const startHand = (store) => {
|
|
51
|
+
const ledger = createExecutionLedger({ store, epoch: 1, admission: createAdmissionLine() });
|
|
52
|
+
return createRemoteExecutor({
|
|
53
|
+
authority: { kind: "self" },
|
|
54
|
+
transport: handSide,
|
|
55
|
+
openScope: async (scope) => scopeRunner(scope.id),
|
|
56
|
+
ledger: createHandLedger({
|
|
57
|
+
ledger,
|
|
58
|
+
executor: "hand",
|
|
59
|
+
issuer: "session",
|
|
60
|
+
workspace: "workspace",
|
|
61
|
+
now: timers.now,
|
|
62
|
+
leaseMs: LEASE_MS,
|
|
63
|
+
}),
|
|
64
|
+
onFault: (error) => faults.push(error),
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
let commit = -1;
|
|
68
|
+
let dead = false;
|
|
69
|
+
const killing = (point) => {
|
|
70
|
+
if (dead)
|
|
71
|
+
throw new Error("the hand was killed");
|
|
72
|
+
if (point.op !== "commit")
|
|
73
|
+
return;
|
|
74
|
+
if (point.at === "before")
|
|
75
|
+
commit += 1;
|
|
76
|
+
const kill = options.killAt;
|
|
77
|
+
if (kill !== undefined && kill.commit === commit && kill.at === point.at) {
|
|
78
|
+
dead = true;
|
|
79
|
+
killed.resolve();
|
|
80
|
+
throw new Error(`hand killed ${point.at} commit ${commit}`);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
let current = await adapters.store.open(medium, { onWritePoint: killing });
|
|
84
|
+
await startHand(current).ready;
|
|
85
|
+
const host = createRemoteToolHost({ transport: sessionSide, placement: options.placement });
|
|
86
|
+
const pump = async (stop, ms) => {
|
|
87
|
+
const end = timers.now() + ms;
|
|
88
|
+
await drain();
|
|
89
|
+
while (!stop() && timers.now() < end) {
|
|
90
|
+
await timers.advanceTo(Math.min(end, timers.now() + TICK_MS));
|
|
91
|
+
await drain();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const runUntil = async (done, what, budgetMs = 600_000) => {
|
|
95
|
+
await pump(done, budgetMs);
|
|
96
|
+
if (!done())
|
|
97
|
+
throw new Error(`${what}: not reached within ${budgetMs} ms of transport time`);
|
|
98
|
+
};
|
|
99
|
+
const settle = async (promise, what, budgetMs = 600_000) => {
|
|
100
|
+
let outcome;
|
|
101
|
+
promise.then((value) => void (outcome = { value }), (error) => void (outcome = { error }));
|
|
102
|
+
await runUntil(() => outcome !== undefined, what, budgetMs);
|
|
103
|
+
if (outcome === undefined || "error" in outcome)
|
|
104
|
+
throw outcome?.error;
|
|
105
|
+
return outcome.value;
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
advance: (ms) => pump(() => false, ms),
|
|
109
|
+
bodies,
|
|
110
|
+
faults,
|
|
111
|
+
killed: killed.promise,
|
|
112
|
+
execute: (scope, calls, mode = "parallel") => host.execute({ scope: { id: scope, root: `/work/${scope}` }, calls, mode }, { emit: () => { } }),
|
|
113
|
+
async restart() {
|
|
114
|
+
current = await adapters.store.open(medium);
|
|
115
|
+
await settle(startHand(current).ready, "the restarted hand recovered");
|
|
116
|
+
},
|
|
117
|
+
gateBodies: () => {
|
|
118
|
+
gated = true;
|
|
119
|
+
},
|
|
120
|
+
release(toolCallId) {
|
|
121
|
+
const gate = gates.get(toolCallId) ?? Promise.withResolvers();
|
|
122
|
+
gates.set(toolCallId, gate);
|
|
123
|
+
gate.resolve();
|
|
124
|
+
},
|
|
125
|
+
settle,
|
|
126
|
+
runUntil,
|
|
127
|
+
disconnect: () => link.drop(),
|
|
128
|
+
reconnect: () => link.connect(),
|
|
129
|
+
rows: async () => createExecutionLedger({
|
|
130
|
+
store: await adapters.store.open(medium),
|
|
131
|
+
epoch: 1,
|
|
132
|
+
admission: createAdmissionLine(),
|
|
133
|
+
}).scan(),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=hand-harness.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CaseImplementation } from "../../conformance/runner.ts";
|
|
2
|
+
import type { BatchCaseAdapters } from "./batch-executor.ts";
|
|
3
|
+
import { type BrainKill } from "./batch-harness.ts";
|
|
4
|
+
export interface KillBatchDeclaration {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly scenario: string;
|
|
7
|
+
readonly kill: BrainKill;
|
|
8
|
+
readonly placement: "everywhere";
|
|
9
|
+
}
|
|
10
|
+
export declare const KILL_BATCH_DECLARATIONS: readonly KillBatchDeclaration[];
|
|
11
|
+
export declare const KILL_BATCH_CASES: ReadonlyMap<string, CaseImplementation<BatchCaseAdapters>>;
|
|
12
|
+
//# sourceMappingURL=kill-batch.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { expectEqual } from "../../durable/testing/store-harness.js";
|
|
2
|
+
import { BrainKilledError, batchHarness, batchPlan, expectRejects, resultOf, } from "./batch-harness.js";
|
|
3
|
+
const notRun = { kind: "not_run", cause: "batch_abort" };
|
|
4
|
+
const SCENARIOS = [
|
|
5
|
+
{
|
|
6
|
+
name: "a released wave then a sequential call",
|
|
7
|
+
calls: [
|
|
8
|
+
["a", "e1"],
|
|
9
|
+
["b", "e2"],
|
|
10
|
+
["c", "e1", "read", "sequential"],
|
|
11
|
+
],
|
|
12
|
+
writes: ["manifest", "prepare:a", "prepare:b", "prepare:c", "decision", "release:a", "release:b"].concat([
|
|
13
|
+
"outcome:a",
|
|
14
|
+
"outcome:b",
|
|
15
|
+
"release:c",
|
|
16
|
+
"outcome:c",
|
|
17
|
+
]),
|
|
18
|
+
expected: { decision: "RELEASE", outcomes: [resultOf("a"), resultOf("b"), resultOf("c")] },
|
|
19
|
+
prepared: ["a", "b", "c"],
|
|
20
|
+
ran: ["a", "b", "c"],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "a batch_abort reply",
|
|
24
|
+
calls: [
|
|
25
|
+
["a", "e1"],
|
|
26
|
+
["b", "e2", "stop"],
|
|
27
|
+
["c", "e1"],
|
|
28
|
+
],
|
|
29
|
+
writes: ["manifest", "prepare:a", "prepare:b", "decision", "outcome:a", "outcome:b", "outcome:c"],
|
|
30
|
+
expected: { decision: "ABORT", outcomes: [notRun, notRun, notRun] },
|
|
31
|
+
prepared: ["a", "b"],
|
|
32
|
+
ran: [],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "a blocked call beside a released call (the executor's blocked reply must be durable)",
|
|
36
|
+
calls: [
|
|
37
|
+
["a", "e1", "deny"],
|
|
38
|
+
["b", "e2"],
|
|
39
|
+
],
|
|
40
|
+
writes: ["manifest", "prepare:a", "prepare:b", "decision", "outcome:a", "release:b", "outcome:b"],
|
|
41
|
+
expected: { decision: "RELEASE", outcomes: [{ kind: "blocked", result: "blocked: deny" }, resultOf("b")] },
|
|
42
|
+
prepared: ["a", "b"],
|
|
43
|
+
ran: ["b"],
|
|
44
|
+
},
|
|
45
|
+
];
|
|
46
|
+
const AT = ["before", "after"];
|
|
47
|
+
const cases = SCENARIOS.flatMap((scenario, scenarioIndex) => scenario.writes.flatMap((label, writeIndex) => AT.map((at, atIndex) => {
|
|
48
|
+
const number = SCENARIOS.slice(0, scenarioIndex).reduce((sum, s) => sum + s.writes.length, 0) + writeIndex + 1;
|
|
49
|
+
const id = `KILL-BATCH-${String(number).padStart(2, "0")}-${atIndex + 1}`;
|
|
50
|
+
const kill = { label, at };
|
|
51
|
+
const run = async (adapters) => {
|
|
52
|
+
const h = await batchHarness(adapters);
|
|
53
|
+
const plan = batchPlan(id.toLowerCase(), scenario.calls);
|
|
54
|
+
await expectRejects((await h.brain(kill)).run(plan), BrainKilledError, `${at} ${label}`);
|
|
55
|
+
expectEqual(await (await h.brain()).run(plan), scenario.expected, "recovery reaches the uncrashed outcomes");
|
|
56
|
+
for (const [executionId, executor] of scenario.calls) {
|
|
57
|
+
const preparedOnce = scenario.prepared.includes(executionId) ? 1 : 0;
|
|
58
|
+
for (const step of ["shim", "hook"])
|
|
59
|
+
expectEqual(h.count(`${step}:${executionId}`), preparedOnce, `${step}:${executionId} once at most`);
|
|
60
|
+
const ranOnce = scenario.ran.includes(executionId) ? 1 : 0;
|
|
61
|
+
expectEqual(h.count(`body:${executionId}`), ranOnce, `body:${executionId}`);
|
|
62
|
+
if (preparedOnce === 1)
|
|
63
|
+
expectEqual(await h.ledgerState(executor, executionId), "settled", "stable ids");
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
return { id, scenario: scenario.name, kill, placement: "everywhere", run };
|
|
67
|
+
})));
|
|
68
|
+
export const KILL_BATCH_DECLARATIONS = cases.map(({ run: _run, ...entry }) => entry);
|
|
69
|
+
export const KILL_BATCH_CASES = new Map(cases.map(({ id, run }) => [id, run]));
|
|
70
|
+
//# sourceMappingURL=kill-batch.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CaseImplementation } from "../../conformance/runner.ts";
|
|
2
|
+
import type { HandPlacement } from "../remote-tool-host.ts";
|
|
3
|
+
import { type HandCaseAdapters, type KillPoint } from "./hand-harness.ts";
|
|
4
|
+
/** The ledger commits one call makes on a hand, in order. */
|
|
5
|
+
declare const COMMITS: readonly ["admit", "prepare", "effect", "freeze", "release", "dispatch", "settle", "ack"];
|
|
6
|
+
export interface KillHandDeclaration {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly operation: (typeof COMMITS)[number];
|
|
9
|
+
readonly at: KillPoint["at"];
|
|
10
|
+
readonly placement: HandPlacement;
|
|
11
|
+
readonly expected: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const KILL_HAND_DECLARATIONS: readonly KillHandDeclaration[];
|
|
14
|
+
export declare const KILL_HAND_CASES: ReadonlyMap<string, CaseImplementation<HandCaseAdapters>>;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=kill-hand.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { TOOL_RESULT_PLACEHOLDER } from "@earendil-works/pi-ai";
|
|
2
|
+
import { expectEqual } from "../../durable/testing/store-harness.js";
|
|
3
|
+
import { call, openHandRig } from "./hand-harness.js";
|
|
4
|
+
/** The ledger commits one call makes on a hand, in order. */
|
|
5
|
+
const COMMITS = ["admit", "prepare", "effect", "freeze", "release", "dispatch", "settle", "ack"];
|
|
6
|
+
const PLACEMENTS = ["split-local", "cross-machine"];
|
|
7
|
+
function expectedAfter(lastDurable) {
|
|
8
|
+
if (lastDurable < 0)
|
|
9
|
+
return { outcome: "result" };
|
|
10
|
+
if (lastDurable <= 2)
|
|
11
|
+
return { outcome: "restarted", uncertain: lastDurable >= 2 };
|
|
12
|
+
if (lastDurable <= 4)
|
|
13
|
+
return { outcome: "result" };
|
|
14
|
+
if (lastDurable === 5)
|
|
15
|
+
return { outcome: "restarted", uncertain: true };
|
|
16
|
+
return { outcome: "result" };
|
|
17
|
+
}
|
|
18
|
+
/** How many times the body ran in total: once, or never when the kill came before it ran. */
|
|
19
|
+
function bodyRuns(kill, lastDurable) {
|
|
20
|
+
if (lastDurable >= 0 && lastDurable <= 2)
|
|
21
|
+
return 0;
|
|
22
|
+
if (lastDurable === 5)
|
|
23
|
+
return kill.commit === 6 ? 1 : 0;
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
function describeExpected(placement, expected, runs) {
|
|
27
|
+
const body = runs === 0 ? "the tool never runs" : "the tool runs exactly once";
|
|
28
|
+
if (expected.outcome === "result")
|
|
29
|
+
return `the session gets the tool's result; ${body}`;
|
|
30
|
+
return placement === "split-local"
|
|
31
|
+
? `the session gets today's placeholder result, no uncertain outcome; ${body}`
|
|
32
|
+
: `the session gets hand_restarted, ${expected.uncertain ? "uncertain" : "not uncertain"}, never rerun; ${body}`;
|
|
33
|
+
}
|
|
34
|
+
const cases = COMMITS.flatMap((operation, commit) => ["before", "durable"].flatMap((at) => PLACEMENTS.map((placement) => {
|
|
35
|
+
const kill = { commit, at };
|
|
36
|
+
const lastDurable = at === "durable" ? commit : commit - 1;
|
|
37
|
+
const expected = expectedAfter(lastDurable);
|
|
38
|
+
const runs = bodyRuns(kill, lastDurable);
|
|
39
|
+
const id = `KILL-HAND-${String(commit + 1).padStart(2, "0")}-${at === "before" ? "B" : "D"}-${placement === "split-local" ? "SL" : "XM"}`;
|
|
40
|
+
const what = `${id} (${operation} ${at}, ${placement})`;
|
|
41
|
+
const run = async (adapters) => {
|
|
42
|
+
const rig = await openHandRig(adapters, { placement, killAt: kill });
|
|
43
|
+
const outcome = rig.execute("scope", [call("c1")]);
|
|
44
|
+
await rig.settle(rig.killed, `${what}: the kill point fired`);
|
|
45
|
+
await rig.restart();
|
|
46
|
+
const { messages } = await rig.settle(outcome, `${what}: the session got the call's outcome`);
|
|
47
|
+
await rig.advance(200);
|
|
48
|
+
const [message] = messages;
|
|
49
|
+
const text = message?.content.map((part) => (part.type === "text" ? part.text : "")).join("");
|
|
50
|
+
if (expected.outcome === "result") {
|
|
51
|
+
expectEqual([text, message?.isError], ["ran:c1", false], `${what}: the tool's result`);
|
|
52
|
+
}
|
|
53
|
+
else if (placement === "split-local") {
|
|
54
|
+
expectEqual([text, message?.isError], [TOOL_RESULT_PLACEHOLDER, false], `${what}: today's placeholder`);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
expectEqual(message?.details, { outcome: "hand_restarted", uncertain: expected.uncertain, hooksRan: expected.uncertain }, `${what}: the endpoint outcome`);
|
|
58
|
+
expectEqual(message?.isError, true, `${what}: reported as an error`);
|
|
59
|
+
}
|
|
60
|
+
expectEqual(rig.bodies.length, runs, `${what}: tool body runs`);
|
|
61
|
+
const rows = await rig.rows();
|
|
62
|
+
expectEqual(rows.map((row) => row.progress.state), ["acked"], `${what}: one durable record, acknowledged`);
|
|
63
|
+
};
|
|
64
|
+
const declaration = {
|
|
65
|
+
id,
|
|
66
|
+
operation,
|
|
67
|
+
at,
|
|
68
|
+
placement,
|
|
69
|
+
expected: `${placement}: kill ${at} the ${operation} commit; ${describeExpected(placement, expected, runs)}; one durable record`,
|
|
70
|
+
};
|
|
71
|
+
return { declaration, run };
|
|
72
|
+
})));
|
|
73
|
+
export const KILL_HAND_DECLARATIONS = cases.map(({ declaration }) => declaration);
|
|
74
|
+
export const KILL_HAND_CASES = new Map(cases.map(({ declaration, run }) => [declaration.id, run]));
|
|
75
|
+
//# sourceMappingURL=kill-hand.js.map
|
|
@@ -20,6 +20,15 @@ const preparation = async ({ store }) => {
|
|
|
20
20
|
expectEqual((await ledger.apply(command({ kind: "effect" }))).status, "replayed", "effects never granted twice");
|
|
21
21
|
await ledger.apply(command({ kind: "freeze", call: FROZEN, awaitingConsent: false }));
|
|
22
22
|
expectEqual((await row(await reopen())).progress, { state: "prepared", call: FROZEN }, "frozen bytes survive reopen");
|
|
23
|
+
expectEqual(await ledger.apply(command({ kind: "block", value: "late" })), { status: "refused", reason: "invalid_transition" }, "a frozen call cannot be blocked");
|
|
24
|
+
const blocked = await fixture(store);
|
|
25
|
+
await runEvents(blocked.ledger, [...PREPARE.slice(0, 2), { kind: "block", value: { reply: "blocked" } }]);
|
|
26
|
+
expectEqual((await row(await blocked.reopen())).progress, {
|
|
27
|
+
state: "settled",
|
|
28
|
+
outcome: { reason: "blocked", value: { reply: "blocked" }, hooksRan: true, uncertain: false },
|
|
29
|
+
}, "a blocked preparation is a durable terminal outcome");
|
|
30
|
+
await (await blocked.reopen()).recover(102);
|
|
31
|
+
expectEqual((await row(await blocked.reopen())).progress.state, "settled", "restart recovery keeps a blocked call");
|
|
23
32
|
};
|
|
24
33
|
const consent = async ({ store }) => {
|
|
25
34
|
const { ledger } = await fixture(store);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CaseImplementation } from "../../conformance/runner.ts";
|
|
2
|
+
import { type HandCaseAdapters } from "./hand-harness.ts";
|
|
3
|
+
type HandCase = CaseImplementation<HandCaseAdapters>;
|
|
4
|
+
export declare const MULTI_HAND_CASES: ReadonlyMap<string, HandCase>;
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=multi-hand-cases.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { expectEqual } from "../../durable/testing/store-harness.js";
|
|
2
|
+
import { call, openHandRig } from "./hand-harness.js";
|
|
3
|
+
const SCOPES = ["a", "b", "c"];
|
|
4
|
+
const CALLS_PER_SCOPE = 3;
|
|
5
|
+
const callIds = (scope) => Array.from({ length: CALLS_PER_SCOPE }, (_, index) => `${scope}${index + 1}`);
|
|
6
|
+
const texts = (messages) => messages.map((message) => message.content.map((part) => (part.type === "text" ? part.text : "")).join(""));
|
|
7
|
+
/** Several sessions' scopes run batches at once on one hand: each scope's calls start in its lane order. */
|
|
8
|
+
const manyScopesOnOneHand = async (adapters) => {
|
|
9
|
+
const rig = await openHandRig(adapters, { placement: "split-local" });
|
|
10
|
+
rig.gateBodies();
|
|
11
|
+
const batches = SCOPES.map((scope) => rig.execute(scope, callIds(scope).map(call)));
|
|
12
|
+
await rig.runUntil(() => rig.bodies.length === SCOPES.length * CALLS_PER_SCOPE, "MULTI-HAND-01: every body started");
|
|
13
|
+
for (const scope of SCOPES)
|
|
14
|
+
expectEqual(rig.bodies.filter((body) => body.startsWith(`${scope}:`)), callIds(scope).map((id) => `${scope}:${id}`), `MULTI-HAND-01: scope ${scope} kept its lane order`);
|
|
15
|
+
for (const scope of [...SCOPES].reverse())
|
|
16
|
+
for (const id of [...callIds(scope)].reverse())
|
|
17
|
+
rig.release(id);
|
|
18
|
+
const results = await rig.settle(Promise.all(batches), "MULTI-HAND-01: every batch settled");
|
|
19
|
+
expectEqual(results.map(({ messages }) => texts(messages)), SCOPES.map((scope) => callIds(scope).map((id) => `ran:${id}`)), "MULTI-HAND-01: each scope's results in its source order");
|
|
20
|
+
};
|
|
21
|
+
/** A hand killed with several scopes' calls in flight: each scope recovers on its own, nothing runs twice. */
|
|
22
|
+
const killWithScopesInFlight = async (adapters) => {
|
|
23
|
+
const dispatchCommits = SCOPES.length * 6;
|
|
24
|
+
const rig = await openHandRig(adapters, {
|
|
25
|
+
placement: "cross-machine",
|
|
26
|
+
killAt: { commit: dispatchCommits, at: "before" },
|
|
27
|
+
});
|
|
28
|
+
rig.gateBodies();
|
|
29
|
+
const batches = SCOPES.map((scope) => rig.execute(scope, [call(`${scope}1`)]));
|
|
30
|
+
await rig.runUntil(() => rig.bodies.length === SCOPES.length, "MULTI-KILL-01: every scope's call is running");
|
|
31
|
+
rig.release("a1");
|
|
32
|
+
await rig.settle(rig.killed, "MULTI-KILL-01: the hand died while the scopes were in flight");
|
|
33
|
+
await rig.restart();
|
|
34
|
+
const results = await rig.settle(Promise.all(batches), "MULTI-KILL-01: every scope got its outcome");
|
|
35
|
+
expectEqual(results.map(({ messages }) => messages.map((message) => message.details)), SCOPES.map(() => [{ outcome: "hand_restarted", uncertain: true, hooksRan: true }]), "MULTI-KILL-01: each scope's call ended hand_restarted, uncertain");
|
|
36
|
+
expectEqual(rig.bodies, SCOPES.map((scope) => `${scope}:${scope}1`), "MULTI-KILL-01: no call ran twice");
|
|
37
|
+
await rig.advance(200);
|
|
38
|
+
expectEqual((await rig.rows()).map((row) => row.progress.state), SCOPES.map(() => "acked"), "MULTI-KILL-01: one durable record per call, acknowledged");
|
|
39
|
+
};
|
|
40
|
+
export const MULTI_HAND_CASES = new Map([
|
|
41
|
+
["MULTI-HAND-01", manyScopesOnOneHand],
|
|
42
|
+
["MULTI-KILL-01", killWithScopesInFlight],
|
|
43
|
+
]);
|
|
44
|
+
//# sourceMappingURL=multi-hand-cases.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { JsonObject } from "@earendil-works/pi-ai";
|
|
2
|
+
import type { CaseImplementation } from "../../conformance/runner.ts";
|
|
3
|
+
import type { ExecutionEntry, FrozenCall } from "../ledger-types.ts";
|
|
4
|
+
/**
|
|
5
|
+
* PREP-01..04: the prepared executor runs today's preparation once, in today's order, under the execution ledger.
|
|
6
|
+
* The cases drive an executor adapter around one fixture tool, `qa`: inactive until the executor activates it, with a
|
|
7
|
+
* shim that maps `{legacy:"42"}` to `{value:42}`, a schema that requires a number, and an ordered `tool_call` chain.
|
|
8
|
+
* No conformance host provides the executor adapter yet, so these cases are run by the executor's own tests and are
|
|
9
|
+
* not in `CONFORMANCE_REGISTRY`.
|
|
10
|
+
*/
|
|
11
|
+
export interface PrepFixtureOptions {
|
|
12
|
+
/** A last `tool_call` handler replaces the call's arguments with these values. */
|
|
13
|
+
readonly rewrite?: JsonObject;
|
|
14
|
+
/** A last `tool_call` handler blocks the call with this reason. */
|
|
15
|
+
readonly block?: string;
|
|
16
|
+
}
|
|
17
|
+
export type PrepOutcome = {
|
|
18
|
+
readonly kind: "prepared";
|
|
19
|
+
readonly call: FrozenCall;
|
|
20
|
+
} | {
|
|
21
|
+
readonly kind: "blocked";
|
|
22
|
+
readonly reason: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly kind: "refused";
|
|
25
|
+
readonly reason: string;
|
|
26
|
+
};
|
|
27
|
+
export type ReleaseOutcome = {
|
|
28
|
+
readonly kind: "settled";
|
|
29
|
+
readonly text: string;
|
|
30
|
+
readonly isError: boolean;
|
|
31
|
+
} | {
|
|
32
|
+
readonly kind: "replayed";
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: "refused";
|
|
35
|
+
readonly reason: string;
|
|
36
|
+
};
|
|
37
|
+
export interface PrepFixture {
|
|
38
|
+
/** The `tool_call` chain's own trace steps, in registration order (for example a PreToolUse shell hook). */
|
|
39
|
+
readonly handlerSteps: readonly string[];
|
|
40
|
+
prepare(id: string, args: JsonObject): Promise<PrepOutcome>;
|
|
41
|
+
release(id: string): Promise<ReleaseOutcome>;
|
|
42
|
+
/** `effect` when effect_possible became durable, then `activate`, `shim`, each handler step and `body(<value>)`. */
|
|
43
|
+
trace(): readonly string[];
|
|
44
|
+
/** Replace the executor with a fresh instance over the same store, after the ledger's restart recovery. */
|
|
45
|
+
restart(): Promise<void>;
|
|
46
|
+
/** The execution row read through a ledger reopened on the same store. */
|
|
47
|
+
row(id: string): Promise<ExecutionEntry | undefined>;
|
|
48
|
+
}
|
|
49
|
+
export interface PrepCaseAdapters {
|
|
50
|
+
readonly executor: {
|
|
51
|
+
open(options?: PrepFixtureOptions): Promise<PrepFixture>;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
type PrepCase = CaseImplementation<PrepCaseAdapters>;
|
|
55
|
+
export declare const PREP_CASES: ReadonlyMap<string, PrepCase>;
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=prep-cases.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { expectEqual } from "../../durable/testing/store-harness.js";
|
|
2
|
+
const LEGACY = { legacy: "42" };
|
|
3
|
+
function preparedCall(outcome) {
|
|
4
|
+
if (outcome.kind !== "prepared")
|
|
5
|
+
throw new Error(`expected a prepared call, got ${JSON.stringify(outcome)}`);
|
|
6
|
+
return outcome.call;
|
|
7
|
+
}
|
|
8
|
+
function count(trace, step) {
|
|
9
|
+
return trace.filter((entry) => entry === step).length;
|
|
10
|
+
}
|
|
11
|
+
const shim = async ({ executor }) => {
|
|
12
|
+
const fixture = await executor.open();
|
|
13
|
+
const call = preparedCall(await fixture.prepare("prep-01", LEGACY));
|
|
14
|
+
expectEqual({ name: call.name, args: call.args }, { name: "qa", args: { value: 42 } }, "shim output is frozen");
|
|
15
|
+
const trace = fixture.trace();
|
|
16
|
+
expectEqual(count(trace, "shim"), 1, "the shim runs once");
|
|
17
|
+
expectEqual(trace.indexOf("effect") < trace.indexOf("shim"), true, "the shim runs after effect_possible");
|
|
18
|
+
const invalid = await executor.open();
|
|
19
|
+
expectEqual((await invalid.prepare("prep-01-invalid", { value: "bad" })).kind, "blocked", "validation blocks");
|
|
20
|
+
expectEqual(invalid.trace(), ["effect", "activate", "shim"], "no handler runs after a failed validation");
|
|
21
|
+
const row = await invalid.row("prep-01-invalid");
|
|
22
|
+
const outcome = row?.progress.state === "settled" ? row.progress.outcome.reason : row?.progress.state;
|
|
23
|
+
expectEqual({ outcome, effectPossible: row?.effectPossible }, { outcome: "blocked", effectPossible: true }, "an invalid call settles blocked, with nothing frozen");
|
|
24
|
+
};
|
|
25
|
+
const activationOrder = async ({ executor }) => {
|
|
26
|
+
const fixture = await executor.open();
|
|
27
|
+
preparedCall(await fixture.prepare("prep-02", LEGACY));
|
|
28
|
+
const prepared = ["effect", "activate", "shim", ...fixture.handlerSteps];
|
|
29
|
+
expectEqual(fixture.trace(), prepared, "preparation runs in today's order after effect_possible");
|
|
30
|
+
expectEqual((await fixture.release("prep-02")).kind, "settled", "release runs the body");
|
|
31
|
+
expectEqual(fixture.trace(), [...prepared, "body(42)"], "the body follows the frozen preparation");
|
|
32
|
+
};
|
|
33
|
+
const handlersOnce = async ({ executor }) => {
|
|
34
|
+
const fixture = await executor.open();
|
|
35
|
+
const [first, concurrent] = await Promise.all([
|
|
36
|
+
fixture.prepare("prep-03", LEGACY),
|
|
37
|
+
fixture.prepare("prep-03", LEGACY),
|
|
38
|
+
]);
|
|
39
|
+
const resent = await fixture.prepare("prep-03", LEGACY);
|
|
40
|
+
expectEqual([concurrent, resent], [first, first], "a re-sent prepare returns the stored reply");
|
|
41
|
+
const released = await fixture.release("prep-03");
|
|
42
|
+
expectEqual(released.kind, "settled", "first release settles");
|
|
43
|
+
expectEqual((await fixture.release("prep-03")).kind === "settled", false, "a re-sent release never reruns the body");
|
|
44
|
+
expectEqual((await fixture.prepare("prep-03", LEGACY)).kind === "blocked", false, "a prepare after release never reruns preparation");
|
|
45
|
+
const trace = fixture.trace();
|
|
46
|
+
for (const step of ["effect", "activate", "shim", ...fixture.handlerSteps, "body(42)"]) {
|
|
47
|
+
expectEqual(count(trace, step), 1, `${step} runs exactly once`);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const frozenCall = async ({ executor }) => {
|
|
51
|
+
const plain = preparedCall(await (await executor.open()).prepare("prep-04", LEGACY));
|
|
52
|
+
const fixture = await executor.open({ rewrite: { value: 43 } });
|
|
53
|
+
const raw = { legacy: "42" };
|
|
54
|
+
const call = preparedCall(await fixture.prepare("prep-04", raw));
|
|
55
|
+
expectEqual(call.args, { value: 43 }, "the frozen call is what the tool_call chain left");
|
|
56
|
+
expectEqual(call.digest === plain.digest, false, "the digest binds the frozen arguments");
|
|
57
|
+
expectEqual((await fixture.row("prep-04"))?.progress, { state: "prepared", call }, "the frozen call is durable");
|
|
58
|
+
raw.legacy = "7";
|
|
59
|
+
expectEqual(await fixture.release("prep-04"), { kind: "settled", text: "qa:43", isError: false }, "body result");
|
|
60
|
+
expectEqual(fixture.trace().at(-1), "body(43)", "release runs the body with the frozen arguments");
|
|
61
|
+
const blocked = await executor.open({ block: "held by policy" });
|
|
62
|
+
expectEqual(await blocked.prepare("prep-04-blocked", LEGACY), { kind: "blocked", reason: "held by policy" }, "block");
|
|
63
|
+
expectEqual((await blocked.release("prep-04-blocked")).kind, "refused", "a blocked call cannot be released");
|
|
64
|
+
expectEqual(blocked.trace().some((step) => step.startsWith("body(")), false, "a blocked call never reaches the body");
|
|
65
|
+
};
|
|
66
|
+
const storedReplies = async ({ executor }) => {
|
|
67
|
+
for (const [options, args] of [
|
|
68
|
+
[{}, LEGACY],
|
|
69
|
+
[{ block: "held by policy" }, LEGACY],
|
|
70
|
+
[{}, { value: "bad" }],
|
|
71
|
+
]) {
|
|
72
|
+
const fixture = await executor.open(options);
|
|
73
|
+
const first = await fixture.prepare("prep-05", args);
|
|
74
|
+
const steps = fixture.trace();
|
|
75
|
+
await fixture.restart();
|
|
76
|
+
expectEqual(await fixture.prepare("prep-05", args), first, `re-sent ${first.kind} reply after restart`);
|
|
77
|
+
expectEqual(fixture.trace(), steps, "a re-sent prepare after restart reruns no preparation step");
|
|
78
|
+
const row = await fixture.row("prep-05");
|
|
79
|
+
expectEqual(row?.progress.state === "preparing", false, `a ${first.kind} preparation leaves no row in preparing for restart recovery`);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
export const PREP_CASES = new Map([
|
|
83
|
+
["PREP-01", shim],
|
|
84
|
+
["PREP-02", activationOrder],
|
|
85
|
+
["PREP-03", handlersOnce],
|
|
86
|
+
["PREP-04", frozenCall],
|
|
87
|
+
["PREP-05", storedReplies],
|
|
88
|
+
]);
|
|
89
|
+
//# sourceMappingURL=prep-cases.js.map
|
|
@@ -888,6 +888,10 @@ export class NodeExecutionEnv {
|
|
|
888
888
|
infos.push(info.value);
|
|
889
889
|
}
|
|
890
890
|
catch (error) {
|
|
891
|
+
// Another process can remove an entry after readdir listed it (a released lock
|
|
892
|
+
// directory, a renamed staging file); the listing omits it as if readdir had run later.
|
|
893
|
+
if (isNodeError(error) && error.code === "ENOENT")
|
|
894
|
+
continue;
|
|
891
895
|
return err(toFileError(error, entryPath));
|
|
892
896
|
}
|
|
893
897
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,15 @@ export * from "./agent.ts";
|
|
|
5
5
|
export * from "./agent-loop.ts";
|
|
6
6
|
export { createInternalAgentChannel, type InternalAgentChannel, type OrderedAgentRecord } from "./internal-events.ts";
|
|
7
7
|
export { EMPTY_TOOL_USE_DEMOTION_DIAGNOSTIC, ProviderRetryWatchdogAbortError } from "./assistant-terminal-state.ts";
|
|
8
|
+
export { createRemoteExecutor, type HandCall, type HandScope, type OpenHandScope, type RemoteExecutor, type RemoteExecutorOptions, } from "./execution/remote-executor.ts";
|
|
9
|
+
export { createHandLedger, type HandAdmission, type HandLedger, type HandLedgerOptions, } from "./execution/remote-hand-ledger.ts";
|
|
10
|
+
export { decodeRemoteMessage, encodeRemoteMessage, HAND_CONTROL_LANE, type RemoteAbort, type RemoteAck, type RemoteHandMessage, type RemoteHello, type RemoteInvoke, type RemoteRefused, type RemoteSettled, RemoteProtocolError, type RemoteTerminal, type RemoteTerminalReason, type RemoteToolResult, } from "./execution/remote-protocol.ts";
|
|
11
|
+
export { authorize, createGrantVerifier, DEFAULT_WORKSPACE, type GrantRefusal, type GrantRow, type GrantSnapshot, type GrantVerdict, type GrantVerifier, type GrantVerifierOptions, HAND_CAPABILITY, type HandAuthority, type WorkspaceRoot, } from "./execution/grant-verify.ts";
|
|
12
|
+
export { createRemoteToolHost, type HandPlacement, type RemoteToolHostOptions } from "./execution/remote-tool-host.ts";
|
|
13
|
+
export { type CarrierLink, createInProcessNetwork, type InProcessNetwork } from "./transport/in-process-carrier.ts";
|
|
14
|
+
export { type LocalEndpoint, localEndpoint } from "./transport/local-endpoint.ts";
|
|
15
|
+
export { createReliableTransport, type ReliableTransportOptions } from "./transport/reliable-transport.ts";
|
|
16
|
+
export type { Transport, TransportClock, TransportFrame, TransportSide } from "./transport/transport.ts";
|
|
8
17
|
export * from "./harness/agent-harness.ts";
|
|
9
18
|
export { type BranchPreparation, type BranchSummaryDetails, type BranchSummaryResult, type CollectEntriesResult, collectEntriesForBranchSummary, type FileOperations, type GenerateBranchSummaryOptions, generateBranchSummary, prepareBranchEntries, } from "./harness/compaction/branch-summarization.ts";
|
|
10
19
|
export { type CompactionPreparation, type CompactionSettings, type CompactResult, calculateContextTokens, compact, DEFAULT_COMPACTION_SETTINGS, estimateContextTokens, estimateTokens, findCutPoint, findTurnStartIndex, generateSummary, generateSummaryWithUsage, getLastAssistantUsage, prepareCompaction, serializeConversation, shouldCompact, } from "./harness/compaction/compaction.ts";
|
package/dist/index.js
CHANGED
|
@@ -4,6 +4,14 @@ export * from "./agent.js";
|
|
|
4
4
|
export * from "./agent-loop.js";
|
|
5
5
|
export { createInternalAgentChannel } from "./internal-events.js";
|
|
6
6
|
export { EMPTY_TOOL_USE_DEMOTION_DIAGNOSTIC, ProviderRetryWatchdogAbortError } from "./assistant-terminal-state.js";
|
|
7
|
+
export { createRemoteExecutor, } from "./execution/remote-executor.js";
|
|
8
|
+
export { createHandLedger, } from "./execution/remote-hand-ledger.js";
|
|
9
|
+
export { decodeRemoteMessage, encodeRemoteMessage, HAND_CONTROL_LANE, RemoteProtocolError, } from "./execution/remote-protocol.js";
|
|
10
|
+
export { authorize, createGrantVerifier, DEFAULT_WORKSPACE, HAND_CAPABILITY, } from "./execution/grant-verify.js";
|
|
11
|
+
export { createRemoteToolHost } from "./execution/remote-tool-host.js";
|
|
12
|
+
export { createInProcessNetwork } from "./transport/in-process-carrier.js";
|
|
13
|
+
export { localEndpoint } from "./transport/local-endpoint.js";
|
|
14
|
+
export { createReliableTransport } from "./transport/reliable-transport.js";
|
|
7
15
|
export * from "./harness/agent-harness.js";
|
|
8
16
|
export { collectEntriesForBranchSummary, generateBranchSummary, prepareBranchEntries, } from "./harness/compaction/branch-summarization.js";
|
|
9
17
|
export { calculateContextTokens, compact, DEFAULT_COMPACTION_SETTINGS, estimateContextTokens, estimateTokens, findCutPoint, findTurnStartIndex, generateSummary, generateSummaryWithUsage, getLastAssistantUsage, prepareCompaction, serializeConversation, shouldCompact, } from "./harness/compaction/compaction.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-yeongyu/senpi-agent-core",
|
|
3
|
-
"version": "2026.11.3-
|
|
3
|
+
"version": "2026.11.3-3",
|
|
4
4
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@earendil-works/chord": "0.99.1",
|
|
75
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.3-
|
|
76
|
-
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.11.3-
|
|
75
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.3-3",
|
|
76
|
+
"@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.11.3-3",
|
|
77
77
|
"diff": "9.0.0",
|
|
78
78
|
"ignore": "7.0.9",
|
|
79
79
|
"typebox": "1.3.34",
|