@code-yeongyu/senpi-agent-core 2026.11.3-3 → 2026.11.4-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.
Files changed (92) hide show
  1. package/dist/agent-loop.js +7 -47
  2. package/dist/conformance/index.d.ts +23 -0
  3. package/dist/conformance/index.js +17 -0
  4. package/dist/conformance/loop-core-manifest.d.ts +1 -1
  5. package/dist/conformance/loop-core-manifest.js +1 -0
  6. package/dist/conformance/registry.js +9 -1
  7. package/dist/execution/canonical-json.d.ts +3 -0
  8. package/dist/execution/canonical-json.js +12 -0
  9. package/dist/execution/coordinator-codec.js +13 -2
  10. package/dist/execution/coordinator-consent.d.ts +29 -0
  11. package/dist/execution/coordinator-consent.js +63 -0
  12. package/dist/execution/coordinator-sequential.d.ts +15 -0
  13. package/dist/execution/coordinator-sequential.js +34 -0
  14. package/dist/execution/coordinator-types.d.ts +45 -0
  15. package/dist/execution/coordinator.d.ts +3 -1
  16. package/dist/execution/coordinator.js +35 -3
  17. package/dist/execution/device-files-node.d.ts +8 -0
  18. package/dist/execution/device-files-node.js +112 -0
  19. package/dist/execution/device-files.d.ts +80 -0
  20. package/dist/execution/device-files.js +87 -0
  21. package/dist/execution/nested-codec.d.ts +5 -0
  22. package/dist/execution/nested-codec.js +41 -0
  23. package/dist/execution/nested-types.d.ts +92 -0
  24. package/dist/execution/nested-types.js +3 -0
  25. package/dist/execution/nested.d.ts +48 -0
  26. package/dist/execution/nested.js +206 -0
  27. package/dist/execution/plane-model.d.ts +33 -0
  28. package/dist/execution/plane-model.js +80 -0
  29. package/dist/execution/plane.d.ts +72 -0
  30. package/dist/execution/plane.js +172 -0
  31. package/dist/execution/remote-device-files.d.ts +12 -0
  32. package/dist/execution/remote-device-files.js +84 -0
  33. package/dist/execution/remote-executor.d.ts +10 -0
  34. package/dist/execution/remote-executor.js +49 -15
  35. package/dist/execution/remote-file-call.d.ts +14 -0
  36. package/dist/execution/remote-file-call.js +30 -0
  37. package/dist/execution/remote-link.d.ts +36 -0
  38. package/dist/execution/remote-link.js +117 -0
  39. package/dist/execution/remote-protocol.d.ts +21 -4
  40. package/dist/execution/remote-protocol.js +18 -2
  41. package/dist/execution/remote-tool-host.d.ts +11 -3
  42. package/dist/execution/remote-tool-host.js +23 -64
  43. package/dist/execution/scope-lifecycle.d.ts +81 -0
  44. package/dist/execution/scope-lifecycle.js +173 -0
  45. package/dist/execution/testing/batch-executor.js +32 -3
  46. package/dist/execution/testing/batch-harness.d.ts +25 -3
  47. package/dist/execution/testing/batch-harness.js +83 -5
  48. package/dist/execution/testing/cancel-cases.d.ts +8 -0
  49. package/dist/execution/testing/cancel-cases.js +64 -0
  50. package/dist/execution/testing/consent-cases.d.ts +14 -0
  51. package/dist/execution/testing/consent-cases.js +66 -0
  52. package/dist/execution/testing/kill-nest.d.ts +6 -0
  53. package/dist/execution/testing/kill-nest.js +55 -0
  54. package/dist/execution/testing/kill-wakex.d.ts +6 -0
  55. package/dist/execution/testing/kill-wakex.js +81 -0
  56. package/dist/execution/testing/lifecycle-cases.d.ts +9 -0
  57. package/dist/execution/testing/lifecycle-cases.js +60 -0
  58. package/dist/execution/testing/lifecycle-registry.d.ts +3 -0
  59. package/dist/execution/testing/lifecycle-registry.js +19 -0
  60. package/dist/execution/testing/multi-lifecycle-cases.d.ts +4 -0
  61. package/dist/execution/testing/multi-lifecycle-cases.js +34 -0
  62. package/dist/execution/testing/multi-seq-cases.d.ts +4 -0
  63. package/dist/execution/testing/multi-seq-cases.js +46 -0
  64. package/dist/execution/testing/nest-cases.d.ts +39 -0
  65. package/dist/execution/testing/nest-cases.js +181 -0
  66. package/dist/execution/testing/nest-registry.d.ts +3 -0
  67. package/dist/execution/testing/nest-registry.js +27 -0
  68. package/dist/execution/testing/scope-cases.d.ts +6 -0
  69. package/dist/execution/testing/scope-cases.js +49 -0
  70. package/dist/execution/testing/seq-cases.d.ts +6 -0
  71. package/dist/execution/testing/seq-cases.js +71 -0
  72. package/dist/execution/testing/seq-registry.d.ts +3 -0
  73. package/dist/execution/testing/seq-registry.js +32 -0
  74. package/dist/execution/testing/wake-exec-cases.d.ts +20 -0
  75. package/dist/execution/testing/wake-exec-cases.js +147 -0
  76. package/dist/execution/testing/wake-registry.d.ts +3 -0
  77. package/dist/execution/testing/wake-registry.js +26 -0
  78. package/dist/execution/tool-host.d.ts +10 -2
  79. package/dist/execution/tool-outcome-events.d.ts +11 -0
  80. package/dist/execution/tool-outcome-events.js +47 -0
  81. package/dist/execution/wake-inbox.d.ts +25 -0
  82. package/dist/execution/wake-inbox.js +85 -0
  83. package/dist/execution/wake-outbox.d.ts +30 -0
  84. package/dist/execution/wake-outbox.js +87 -0
  85. package/dist/execution/wake-types.d.ts +45 -0
  86. package/dist/execution/wake-types.js +3 -0
  87. package/dist/index.d.ts +13 -2
  88. package/dist/index.js +11 -1
  89. package/dist/node.d.ts +1 -0
  90. package/dist/node.js +1 -0
  91. package/dist/transport/testing/multi-cases.js +8 -8
  92. package/package.json +3 -3
@@ -0,0 +1,112 @@
1
+ import { constants } from "node:fs";
2
+ import { lstat, mkdir, open, readdir, rename, rm } from "node:fs/promises";
3
+ import { dirname } from "node:path";
4
+ import { DeviceFileError, FILE_CHANNEL_MAX_BYTES } from "./device-files.js";
5
+ function deviceError(error, path) {
6
+ if (error instanceof DeviceFileError)
7
+ return error;
8
+ const code = error.code;
9
+ const message = error instanceof Error ? error.message : String(error);
10
+ if (code === "ENOENT")
11
+ return new DeviceFileError("not_found", path);
12
+ if (code === "EEXIST")
13
+ return new DeviceFileError("exists", path);
14
+ if (code === "EISDIR" || code === "ENOTDIR" || code === "ENXIO")
15
+ return new DeviceFileError("not_a_file", path);
16
+ if (code === "ABORT_ERR")
17
+ return new DeviceFileError("aborted", path);
18
+ return new DeviceFileError("io", message);
19
+ }
20
+ async function guarded(path, signal, run) {
21
+ if (signal?.aborted)
22
+ throw new DeviceFileError("aborted", path);
23
+ try {
24
+ return await run();
25
+ }
26
+ catch (error) {
27
+ throw deviceError(error, path);
28
+ }
29
+ }
30
+ /**
31
+ * Opens a regular file only. The open never blocks (a named pipe with no peer would hold it, and a worker thread,
32
+ * forever), and the type is checked on the opened descriptor, so nothing can swap the path in between.
33
+ */
34
+ async function openRegular(path, flags) {
35
+ const handle = await open(path, flags | constants.O_NONBLOCK, 0o666);
36
+ try {
37
+ if (!(await handle.stat()).isFile())
38
+ throw new DeviceFileError("not_a_file", path);
39
+ return handle;
40
+ }
41
+ catch (error) {
42
+ await handle.close();
43
+ throw error;
44
+ }
45
+ }
46
+ /** Reads at most the channel limit: a file that grows past it while being read is refused, never shipped in full. */
47
+ async function readBounded(path, signal) {
48
+ const handle = await openRegular(path, constants.O_RDONLY);
49
+ try {
50
+ const chunks = [];
51
+ let total = 0;
52
+ for (;;) {
53
+ if (signal?.aborted)
54
+ throw new DeviceFileError("aborted", path);
55
+ const chunk = new Uint8Array(64 * 1024);
56
+ const { bytesRead } = await handle.read(chunk, 0, chunk.length, null);
57
+ if (bytesRead === 0)
58
+ break;
59
+ total += bytesRead;
60
+ if (total > FILE_CHANNEL_MAX_BYTES)
61
+ throw new DeviceFileError("too_large", path);
62
+ chunks.push(chunk.subarray(0, bytesRead));
63
+ }
64
+ const bytes = new Uint8Array(total);
65
+ let offset = 0;
66
+ for (const chunk of chunks) {
67
+ bytes.set(chunk, offset);
68
+ offset += chunk.length;
69
+ }
70
+ return bytes;
71
+ }
72
+ finally {
73
+ await handle.close();
74
+ }
75
+ }
76
+ function statOf(entry) {
77
+ const kind = entry.isFile() ? "file" : entry.isDirectory() ? "directory" : "other";
78
+ return { kind, size: entry.size, mtimeMs: entry.mtimeMs };
79
+ }
80
+ /**
81
+ * The local filesystem as {@link DeviceFiles}: what a fused session's extension code uses, called directly, and what a
82
+ * hand runs a channel operation on once its grant, handlers and policy have allowed it. Reads and writes are bounded
83
+ * by {@link FILE_CHANNEL_MAX_BYTES} before any data is in memory, so both sides of a split session agree on the limit.
84
+ */
85
+ export function localDeviceFiles() {
86
+ return {
87
+ read: (path, options) => guarded(path, options?.signal, () => readBounded(path, options?.signal)),
88
+ write: (path, data, options) => guarded(path, options?.signal, async () => {
89
+ if (data.byteLength > FILE_CHANNEL_MAX_BYTES)
90
+ throw new DeviceFileError("too_large", path);
91
+ await mkdir(dirname(path), { recursive: true });
92
+ const handle = await openRegular(path, constants.O_WRONLY | constants.O_CREAT | constants.O_TRUNC | (options?.exclusive ? constants.O_EXCL : 0));
93
+ try {
94
+ await handle.writeFile(data);
95
+ }
96
+ finally {
97
+ await handle.close();
98
+ }
99
+ }),
100
+ list: (path, options) => guarded(path, options?.signal, () => readdir(path)),
101
+ stat: (path, options) => guarded(path, options?.signal, async () => statOf(await lstat(path))),
102
+ rename: (from, to, options) => guarded(from, options?.signal, () => rename(from, to)),
103
+ remove: (path, options) => guarded(path, options?.signal, async () => {
104
+ await lstat(path);
105
+ await rm(path, { recursive: true });
106
+ }),
107
+ mkdir: (path, options) => guarded(path, options?.signal, async () => {
108
+ await mkdir(path, { recursive: true });
109
+ }),
110
+ };
111
+ }
112
+ //# sourceMappingURL=device-files-node.js.map
@@ -0,0 +1,80 @@
1
+ import type { JsonValue } from "@earendil-works/pi-ai";
2
+ /**
3
+ * The device's files, as extension code reaches them (brain/hand split, S40, senpi#5645). On a fused session this is
4
+ * the local filesystem, called directly. On a split session every operation is one message to the hand, which checks
5
+ * the session's grant, runs its own `tool_call` handlers and filesystem policy, and touches its own disk: the files
6
+ * stay on the device wherever the loop runs. There is no fallback to a direct open.
7
+ */
8
+ export interface DeviceFiles {
9
+ read(path: string, options?: DeviceFileOptions): Promise<Uint8Array>;
10
+ /** Creates parent directories. `exclusive`: fail `exists` when the file is already there (lock files). */
11
+ write(path: string, data: Uint8Array, options?: DeviceFileOptions & {
12
+ readonly exclusive?: boolean;
13
+ }): Promise<void>;
14
+ list(path: string, options?: DeviceFileOptions): Promise<readonly string[]>;
15
+ stat(path: string, options?: DeviceFileOptions): Promise<DeviceFileStat>;
16
+ rename(from: string, to: string, options?: DeviceFileOptions): Promise<void>;
17
+ /** Removes a file, or a directory with everything in it. */
18
+ remove(path: string, options?: DeviceFileOptions): Promise<void>;
19
+ /** Creates a directory and its parents; an existing directory is not an error. */
20
+ mkdir(path: string, options?: DeviceFileOptions): Promise<void>;
21
+ }
22
+ export interface DeviceFileOptions {
23
+ readonly signal?: AbortSignal;
24
+ }
25
+ export interface DeviceFileStat {
26
+ readonly kind: "file" | "directory" | "other";
27
+ readonly size: number;
28
+ readonly mtimeMs: number;
29
+ }
30
+ /** The channel's name in a hand's `hello`. */
31
+ export declare const FILE_CHANNEL = "file/1";
32
+ /** The most data one operation reads or writes, in raw bytes, in both directions. */
33
+ export declare const FILE_CHANNEL_MAX_BYTES: number;
34
+ export type DeviceFileOp = "read" | "write" | "list" | "stat" | "rename" | "remove" | "mkdir";
35
+ export declare const DEVICE_FILE_OPS: readonly DeviceFileOp[];
36
+ export type DeviceFileErrorCode = "not_found" | "not_a_file" | "exists" | "too_large" | "io" | "aborted" | "refused_by_grant" | "refused_by_policy" | "hand_unreachable" | "unsupported" | "interrupted" | "protocol";
37
+ /**
38
+ * A device file operation that did not complete. `interrupted` carries the hand's terminal reason; `uncertain` says the
39
+ * operation may have taken effect (a write may or may not have landed). Nothing is ever retried.
40
+ */
41
+ export declare class DeviceFileError extends Error {
42
+ readonly code: DeviceFileErrorCode;
43
+ readonly reason: string | undefined;
44
+ readonly uncertain: boolean;
45
+ constructor(code: DeviceFileErrorCode, message: string, detail?: {
46
+ reason?: string;
47
+ uncertain?: boolean;
48
+ });
49
+ }
50
+ /** One operation's arguments, as the hand receives them: paths are strings, written data is base64. */
51
+ export type DeviceFileArgs = {
52
+ readonly op: "read" | "list" | "stat" | "remove" | "mkdir";
53
+ readonly path: string;
54
+ } | {
55
+ readonly op: "write";
56
+ readonly path: string;
57
+ readonly data: string;
58
+ readonly exclusive: boolean;
59
+ } | {
60
+ readonly op: "rename";
61
+ readonly path: string;
62
+ readonly to: string;
63
+ };
64
+ /** One operation's outcome, carried in a settled result's `details.file`. */
65
+ export type DeviceFileOutcome = {
66
+ readonly ok: true;
67
+ readonly value: JsonValue;
68
+ } | {
69
+ readonly ok: false;
70
+ readonly code: DeviceFileErrorCode;
71
+ readonly message: string;
72
+ };
73
+ /** Parses an operation's arguments; `undefined` for anything malformed. */
74
+ export declare function decodeDeviceFileArgs(op: unknown, args: unknown): DeviceFileArgs | undefined;
75
+ export declare function encodeBase64(bytes: Uint8Array): string;
76
+ export declare function decodeBase64(text: string): Uint8Array;
77
+ /** The raw byte length a base64 string decodes to, without decoding it. */
78
+ export declare function base64Length(text: string): number;
79
+ export declare function fileOutcomeOf(details: unknown): DeviceFileOutcome | undefined;
80
+ //# sourceMappingURL=device-files.d.ts.map
@@ -0,0 +1,87 @@
1
+ /** The channel's name in a hand's `hello`. */
2
+ export const FILE_CHANNEL = "file/1";
3
+ /** The most data one operation reads or writes, in raw bytes, in both directions. */
4
+ export const FILE_CHANNEL_MAX_BYTES = 8 * 1024 * 1024;
5
+ export const DEVICE_FILE_OPS = ["read", "write", "list", "stat", "rename", "remove", "mkdir"];
6
+ /**
7
+ * A device file operation that did not complete. `interrupted` carries the hand's terminal reason; `uncertain` says the
8
+ * operation may have taken effect (a write may or may not have landed). Nothing is ever retried.
9
+ */
10
+ export class DeviceFileError extends Error {
11
+ constructor(code, message, detail = {}) {
12
+ super(`${code}: ${message}`);
13
+ this.name = "DeviceFileError";
14
+ this.code = code;
15
+ this.reason = detail.reason;
16
+ this.uncertain = detail.uncertain ?? false;
17
+ }
18
+ }
19
+ const CODES = [
20
+ "not_found",
21
+ "not_a_file",
22
+ "exists",
23
+ "too_large",
24
+ "io",
25
+ "aborted",
26
+ "refused_by_grant",
27
+ "refused_by_policy",
28
+ "hand_unreachable",
29
+ "unsupported",
30
+ "interrupted",
31
+ "protocol",
32
+ ];
33
+ function isDeviceFileErrorCode(value) {
34
+ return typeof value === "string" && CODES.includes(value);
35
+ }
36
+ const isRecord = (value) => typeof value === "object" && value !== null;
37
+ /** Parses an operation's arguments; `undefined` for anything malformed. */
38
+ export function decodeDeviceFileArgs(op, args) {
39
+ if (!isRecord(args) || typeof args.path !== "string" || args.path.length === 0)
40
+ return undefined;
41
+ const path = args.path;
42
+ switch (op) {
43
+ case "read":
44
+ case "list":
45
+ case "stat":
46
+ case "remove":
47
+ case "mkdir":
48
+ return { op, path };
49
+ case "write":
50
+ return typeof args.data === "string"
51
+ ? { op, path, data: args.data, exclusive: args.exclusive === true }
52
+ : undefined;
53
+ case "rename":
54
+ return typeof args.to === "string" && args.to.length > 0 ? { op, path, to: args.to } : undefined;
55
+ default:
56
+ return undefined;
57
+ }
58
+ }
59
+ export function encodeBase64(bytes) {
60
+ let binary = "";
61
+ for (let start = 0; start < bytes.length; start += 0x8000)
62
+ binary += String.fromCharCode(...bytes.subarray(start, start + 0x8000));
63
+ return btoa(binary);
64
+ }
65
+ export function decodeBase64(text) {
66
+ const binary = atob(text);
67
+ const bytes = new Uint8Array(binary.length);
68
+ for (let index = 0; index < binary.length; index++)
69
+ bytes[index] = binary.charCodeAt(index);
70
+ return bytes;
71
+ }
72
+ /** The raw byte length a base64 string decodes to, without decoding it. */
73
+ export function base64Length(text) {
74
+ const padding = text.endsWith("==") ? 2 : text.endsWith("=") ? 1 : 0;
75
+ return Math.floor((text.length * 3) / 4) - padding;
76
+ }
77
+ export function fileOutcomeOf(details) {
78
+ if (!isRecord(details) || !isRecord(details.file))
79
+ return undefined;
80
+ const file = details.file;
81
+ if (file.ok === true && "value" in file)
82
+ return { ok: true, value: file.value };
83
+ if (file.ok === false && isDeviceFileErrorCode(file.code) && typeof file.message === "string")
84
+ return { ok: false, code: file.code, message: file.message };
85
+ return undefined;
86
+ }
87
+ //# sourceMappingURL=device-files.js.map
@@ -0,0 +1,5 @@
1
+ import type { StoreValue } from "../durable/store.ts";
2
+ import type { NestedRecord } from "./nested-types.ts";
3
+ /** Decodes the brain's nested record; anything else is a corrupt store, never a guess. */
4
+ export declare function decodeNestedRecord(value: StoreValue): NestedRecord;
5
+ //# sourceMappingURL=nested-codec.d.ts.map
@@ -0,0 +1,41 @@
1
+ const object = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
2
+ const strings = (value, keys) => keys.every((key) => typeof value[key] === "string");
3
+ const numbers = (value, keys) => keys.every((key) => typeof value[key] === "number" && Number.isFinite(value[key]));
4
+ const stringList = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
5
+ function parent(value) {
6
+ return (object(value) &&
7
+ strings(value, ["executionId", "executor", "scope"]) &&
8
+ numbers(value, ["generation", "admittedAt", "leaseUntil", "budget"]) &&
9
+ object(value.capabilities) &&
10
+ stringList(value.capabilities.preparation) &&
11
+ stringList(value.capabilities.body));
12
+ }
13
+ function child(value) {
14
+ return (object(value) &&
15
+ strings(value, ["executionId", "target"]) &&
16
+ numbers(value, ["cost"]) &&
17
+ value.origin === "tool" &&
18
+ (value.activityId === null || typeof value.activityId === "string"));
19
+ }
20
+ function activity(value) {
21
+ return (object(value) &&
22
+ strings(value, ["activityId", "parent", "executor", "scope"]) &&
23
+ numbers(value, ["budget", "expiresAt", "debited"]) &&
24
+ stringList(value.targets) &&
25
+ typeof value.ended === "boolean");
26
+ }
27
+ const each = (value, check) => object(value) && Object.values(value).every(check);
28
+ /** Decodes the brain's nested record; anything else is a corrupt store, never a guess. */
29
+ export function decodeNestedRecord(value) {
30
+ if (object(value) &&
31
+ parent(value.parent) &&
32
+ (value.phase === "preparation" || value.phase === "body" || value.phase === "settled") &&
33
+ typeof value.cancelled === "boolean" &&
34
+ numbers(value, ["expiresAt", "debited"]) &&
35
+ each(value.children, child) &&
36
+ each(value.activities, activity) &&
37
+ each(value.cancels, (entry) => entry === "queued" || entry === "delivered"))
38
+ return value;
39
+ throw new Error("corrupt nested admission record");
40
+ }
41
+ //# sourceMappingURL=nested-codec.js.map
@@ -0,0 +1,92 @@
1
+ import type { ExecutionRef } from "./coordinator-types.ts";
2
+ /** 0010's lifetime of an execution: a nested set never outlives its parent's admission by more than this. */
3
+ export declare const NESTED_LIFETIME_MS: number;
4
+ /** The parent execution a nested set belongs to, as the brain recorded it when it sent the parent's prepare. */
5
+ export type NestedParent = {
6
+ readonly executionId: string;
7
+ readonly generation: number;
8
+ /** The executor the parent was sent to: the only sender whose nested requests name this parent. */
9
+ readonly executor: string;
10
+ readonly scope: string;
11
+ readonly admittedAt: number;
12
+ readonly leaseUntil: number;
13
+ /** The aggregate reservation every child (and every activity's child) is debited from. */
14
+ readonly budget: number;
15
+ /** Targets a nested request may name: `preparation` from the prepare on, `body` added at release. */
16
+ readonly capabilities: {
17
+ readonly preparation: readonly string[];
18
+ readonly body: readonly string[];
19
+ };
20
+ };
21
+ /** A coordinator-owned background activity of a detached cell (design 5.6.3), registered before the detached result. */
22
+ export type NestedActivity = {
23
+ readonly activityId: string;
24
+ readonly parent: string;
25
+ readonly executor: string;
26
+ readonly scope: string;
27
+ /** A subset of the parent's targets: the activity never holds authority the parent did not. */
28
+ readonly targets: readonly string[];
29
+ readonly budget: number;
30
+ readonly expiresAt: number;
31
+ };
32
+ /** A nested request as the brain's endpoint hands it over; `sender` is the authenticated hand, never a claim. */
33
+ export type NestedRequest = {
34
+ readonly sender: string;
35
+ readonly parent: string;
36
+ readonly parentGeneration: number;
37
+ readonly scope: string;
38
+ readonly childRequestId: string;
39
+ /** The executor the child runs on. */
40
+ readonly target: string;
41
+ readonly cost: number;
42
+ /** Set by a detached cell: admitted against the live activity, never by reviving the terminal invocation. */
43
+ readonly activityId?: string;
44
+ };
45
+ export type NestedRefusal = "unknown_parent" | "not_parent_executor" | "stale_generation" | "scope_mismatch" | "parent_terminal" | "expired" | "not_in_nested_set" | "budget_exhausted" | "invalid_cost" | "unknown_activity" | "activity_ended" | "conflicting_request";
46
+ /** A child is tool-originated work, never human intent. */
47
+ export type NestedChild = {
48
+ readonly executionId: string;
49
+ readonly target: string;
50
+ readonly cost: number;
51
+ readonly origin: "tool";
52
+ readonly activityId: string | null;
53
+ };
54
+ export type NestedAdmission = {
55
+ readonly kind: "admitted";
56
+ readonly child: ExecutionRef;
57
+ readonly target: string;
58
+ readonly replayed: boolean;
59
+ } | {
60
+ readonly kind: "refused";
61
+ readonly reason: NestedRefusal;
62
+ };
63
+ export type ActivityRefusal = "parent_terminal" | "unknown_parent" | "exceeds_parent" | "conflicting_activity";
64
+ export type ActivityRecord = NestedActivity & {
65
+ readonly debited: number;
66
+ readonly ended: boolean;
67
+ };
68
+ /** The brain's durable record of one parent's nested work. */
69
+ export type NestedRecord = {
70
+ readonly parent: NestedParent;
71
+ readonly phase: "preparation" | "body" | "settled";
72
+ readonly cancelled: boolean;
73
+ /** The nested set's expiry: follows the parent's renewals, never past its lease or its lifetime. */
74
+ readonly expiresAt: number;
75
+ readonly debited: number;
76
+ readonly children: {
77
+ readonly [childRequestId: string]: NestedChild;
78
+ };
79
+ readonly activities: {
80
+ readonly [activityId: string]: ActivityRecord;
81
+ };
82
+ /** The parent cancel's cascade, per child execution id: queued until its executor took it. */
83
+ readonly cancels: {
84
+ readonly [childExecutionId: string]: "queued" | "delivered";
85
+ };
86
+ };
87
+ /** Where a parent cancel is delivered: the child's executor, with 0010 cancel semantics. */
88
+ export type NestedCancelTarget = {
89
+ readonly ref: ExecutionRef;
90
+ readonly executor: string;
91
+ };
92
+ //# sourceMappingURL=nested-types.d.ts.map
@@ -0,0 +1,3 @@
1
+ /** 0010's lifetime of an execution: a nested set never outlives its parent's admission by more than this. */
2
+ export const NESTED_LIFETIME_MS = 24 * 60 * 60 * 1000;
3
+ //# sourceMappingURL=nested-types.js.map
@@ -0,0 +1,48 @@
1
+ import type { DurableStore } from "../durable/store.ts";
2
+ import type { AdmissionLine } from "../durable/store-admission.ts";
3
+ import { type ActivityRefusal, type NestedActivity, type NestedAdmission, type NestedCancelTarget, type NestedParent, type NestedRecord, type NestedRequest } from "./nested-types.ts";
4
+ export interface NestedAdmissionOptions {
5
+ /** The brain's issuer: every parent and child here is one of its executions. */
6
+ readonly issuer: string;
7
+ readonly store: DurableStore;
8
+ readonly epoch: number;
9
+ /** The single admission line of the store's writable epoch: the brain is the single writer, so a cancel and a child
10
+ * admission are linearized here. */
11
+ readonly admission: AdmissionLine;
12
+ readonly clock: () => number;
13
+ }
14
+ /**
15
+ * Nested requests admitted on the brain that owns the parent execution (design 5.6.3). Every step is durable before
16
+ * the reply it causes; a replay of the same `(parent, childRequestId)` returns the same child and is never debited twice.
17
+ */
18
+ export interface NestedAdmissionControl {
19
+ /** Writes the parent's nested set, scoped to preparation, before its prepare is sent. Idempotent. */
20
+ open(parent: NestedParent): Promise<{
21
+ readonly kind: "opened";
22
+ } | {
23
+ readonly kind: "refused";
24
+ readonly reason: "conflicting_parent";
25
+ }>;
26
+ release(parent: string): Promise<void>;
27
+ /** The parent's invocation is terminal: only its live activities still admit. */
28
+ settle(parent: string): Promise<void>;
29
+ /** Follows a parent renewal: the set's expiry moves forward, never past the lease or the parent's lifetime. */
30
+ renew(parent: string, leaseUntil: number): Promise<number>;
31
+ registerActivity(activity: NestedActivity): Promise<{
32
+ readonly kind: "registered";
33
+ } | {
34
+ readonly kind: "refused";
35
+ readonly reason: ActivityRefusal;
36
+ }>;
37
+ endActivity(parent: string, activityId: string): Promise<void>;
38
+ admit(request: NestedRequest): Promise<NestedAdmission>;
39
+ /** Cancels the parent and every child: the cascade is durably queued, then delivered by `deliverCancels`. */
40
+ cancel(parent: string): Promise<readonly NestedCancelTarget[]>;
41
+ /** Sends every queued cascade to its child's executor and marks it delivered; re-sent after a restart until then. */
42
+ deliverCancels(parent: string, send: (target: NestedCancelTarget) => Promise<void>): Promise<number>;
43
+ read(parent: string): Promise<NestedRecord | undefined>;
44
+ }
45
+ /** A child's execution id: encoded like the record keys, so no two (parent, childRequestId) pairs can collide. */
46
+ export declare const nestedChildId: (parent: string, childRequestId: string) => string;
47
+ export declare function createNestedAdmission(options: NestedAdmissionOptions): NestedAdmissionControl;
48
+ //# sourceMappingURL=nested.d.ts.map