@code-yeongyu/senpi-agent-core 2026.11.2-3 → 2026.11.3-2

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.
@@ -9,6 +9,7 @@ function outcome(value) {
9
9
  return false;
10
10
  switch (value.reason) {
11
11
  case "result":
12
+ case "blocked":
12
13
  return value.value !== undefined && value.uncertain === false;
13
14
  case "cancelled":
14
15
  case "lease_expired":
@@ -17,6 +17,7 @@ function authorized(entry, { actor, event }) {
17
17
  case "prepare":
18
18
  case "effect":
19
19
  case "freeze":
20
+ case "block":
20
21
  case "dispatch":
21
22
  case "result":
22
23
  case "expire":
@@ -94,6 +95,13 @@ export function transitionExecution(entry, command) {
94
95
  return "call" in progress && progress.call.digest === event.call.digest
95
96
  ? replayed(entry)
96
97
  : refused("invalid_transition");
98
+ case "block":
99
+ return progress.state === "preparing"
100
+ ? advance(entry, {
101
+ state: "settled",
102
+ outcome: { reason: "blocked", value: event.value, hooksRan: entry.effectPossible, uncertain: false },
103
+ })
104
+ : refused("invalid_transition");
97
105
  case "consent":
98
106
  return progress.state === "prepared_awaiting_consent"
99
107
  ? advance(entry, { state: "prepared", call: progress.call })
@@ -23,6 +23,13 @@ export type ExecutionOutcome = {
23
23
  readonly value: StoreValue;
24
24
  readonly hooksRan: boolean;
25
25
  readonly uncertain: false;
26
+ }
27
+ /** Preparation ended without a frozen call (a blocking handler, a failed validation, a preflight abort); no body ran. */
28
+ | {
29
+ readonly reason: "blocked";
30
+ readonly value: StoreValue;
31
+ readonly hooksRan: boolean;
32
+ readonly uncertain: false;
26
33
  } | {
27
34
  readonly reason: "cancelled" | "lease_expired" | "hand_restarted" | "uncertain";
28
35
  readonly hooksRan: boolean;
@@ -59,6 +66,9 @@ export type ExecutionEvent = {
59
66
  } | {
60
67
  readonly kind: "result";
61
68
  readonly value: StoreValue;
69
+ } | {
70
+ readonly kind: "block";
71
+ readonly value: StoreValue;
62
72
  } | {
63
73
  readonly kind: "renew";
64
74
  readonly seq: number;
@@ -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,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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/senpi-agent-core",
3
- "version": "2026.11.2-3",
3
+ "version": "2026.11.3-2",
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.2-3",
76
- "@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.11.2-3",
75
+ "@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.3-2",
76
+ "@earendil-works/pi-telemetry": "npm:@code-yeongyu/senpi-telemetry@2026.11.3-2",
77
77
  "diff": "9.0.0",
78
78
  "ignore": "7.0.9",
79
79
  "typebox": "1.3.34",