@astrosheep/keiyaku 4.0.4 → 4.0.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.
Files changed (173) hide show
  1. package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +1 -1
  2. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
  3. package/build/integrations/marketplace/plugins/keiyaku/package.json +1 -1
  4. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +3 -3
  5. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +14 -0
  6. package/build/src/akuma/akuma.d.ts +0 -1
  7. package/build/src/akuma/akuma.js +1 -6
  8. package/build/src/akuma/allowed.d.ts +1 -1
  9. package/build/src/akuma/allowed.js +3 -10
  10. package/build/src/akuma/body.d.ts +5 -2
  11. package/build/src/akuma/body.js +29 -23
  12. package/build/src/akuma/heart/facts.d.ts +35 -9
  13. package/build/src/akuma/heart/index.d.ts +4 -13
  14. package/build/src/akuma/heart/index.js +2 -133
  15. package/build/src/akuma/heart/request-authority.d.ts +12 -0
  16. package/build/src/akuma/heart/request-authority.js +119 -0
  17. package/build/src/akuma/heart/request-rows.d.ts +16 -0
  18. package/build/src/akuma/heart/request-rows.js +88 -0
  19. package/build/src/akuma/heart/rows.d.ts +1 -28
  20. package/build/src/akuma/heart/rows.js +0 -137
  21. package/build/src/akuma/heart/schema.d.ts +1 -1
  22. package/build/src/akuma/heart/schema.js +9 -2
  23. package/build/src/akuma/heart/soul.js +0 -36
  24. package/build/src/akuma/index.d.ts +1 -1
  25. package/build/src/akuma/provider-recipe.js +1 -11
  26. package/build/src/akuma/provider.d.ts +1 -6
  27. package/build/src/akuma/providers/acp/core.js +6 -2
  28. package/build/src/akuma/providers/acp/index.js +0 -1
  29. package/build/src/akuma/providers/claude/index.d.ts +0 -4
  30. package/build/src/akuma/providers/claude/index.js +7 -3
  31. package/build/src/akuma/providers/codex-app-server/index.d.ts +2 -27
  32. package/build/src/akuma/providers/codex-app-server/index.js +0 -2
  33. package/build/src/akuma/providers/grok-build/index.js +0 -1
  34. package/build/src/akuma/providers/opencode-sdk/index.d.ts +2 -28
  35. package/build/src/akuma/providers/opencode-sdk/index.js +8 -4
  36. package/build/src/akuma/providers/opencode-sdk/session.d.ts +1 -1
  37. package/build/src/akuma/providers/opencode-sdk/session.js +1 -1
  38. package/build/src/akuma/providers/pi/index.js +11 -4
  39. package/build/src/akuma/request-serve.d.ts +87 -0
  40. package/build/src/akuma/request-serve.js +484 -0
  41. package/build/src/akuma/request-wire.d.ts +124 -0
  42. package/build/src/akuma/request-wire.js +380 -0
  43. package/build/src/akuma/requests.d.ts +28 -94
  44. package/build/src/akuma/requests.js +52 -562
  45. package/build/src/akuma-body.d.ts +7 -0
  46. package/build/src/akuma-body.js +54 -1
  47. package/build/src/body/arc.js +4 -29
  48. package/build/src/body/decode.js +5 -39
  49. package/build/src/body/envelope.d.ts +7 -0
  50. package/build/src/body/envelope.js +37 -0
  51. package/build/src/cli/accepted.js +17 -9
  52. package/build/src/cli/commands/akuma.js +2 -2
  53. package/build/src/cli/commands/contract.d.ts +6 -6
  54. package/build/src/cli/commands/contract.js +3 -3
  55. package/build/src/cli/commands/task-invoke.js +98 -9
  56. package/build/src/cli/coordinates.d.ts +1 -0
  57. package/build/src/cli/coordinates.js +7 -4
  58. package/build/src/cli/invoke.js +28 -4
  59. package/build/src/cli/parse.d.ts +2 -2
  60. package/build/src/cli/parse.js +21 -8
  61. package/build/src/cli/render/akuma.js +56 -13
  62. package/build/src/cli/render/audit.js +2 -6
  63. package/build/src/cli/render/contract.js +40 -0
  64. package/build/src/cli/render/receipt.js +28 -1
  65. package/build/src/cli/render/terminal.d.ts +0 -2
  66. package/build/src/cli/render/terminal.js +0 -29
  67. package/build/src/cli/result.d.ts +15 -7
  68. package/build/src/contract-worktree.d.ts +1 -2
  69. package/build/src/contract-worktree.js +4 -9
  70. package/build/src/core/facts/codec.js +9 -0
  71. package/build/src/core/facts/fold.js +13 -1
  72. package/build/src/core/facts/types.d.ts +8 -1
  73. package/build/src/core/subject.js +4 -3
  74. package/build/src/core/verbs/placement.d.ts +9 -1
  75. package/build/src/core/verbs/placement.js +24 -6
  76. package/build/src/core/verbs/reintegrate.d.ts +13 -0
  77. package/build/src/core/verbs/reintegrate.js +24 -0
  78. package/build/src/dispatch/index.d.ts +1 -1
  79. package/build/src/git/admission.d.ts +2 -1
  80. package/build/src/git/integration.d.ts +5 -2
  81. package/build/src/git/integration.js +54 -1
  82. package/build/src/git/observe.d.ts +2 -1
  83. package/build/src/git/observe.js +6 -5
  84. package/build/src/git/process.d.ts +26 -0
  85. package/build/src/git/process.js +94 -0
  86. package/build/src/git/read-observation.d.ts +2 -1
  87. package/build/src/git/read-observation.js +3 -2
  88. package/build/src/git/reconcile.d.ts +2 -1
  89. package/build/src/git/reconcile.js +9 -6
  90. package/build/src/git/repository.d.ts +2 -29
  91. package/build/src/git/repository.js +4 -118
  92. package/build/src/git/scratch.d.ts +1 -1
  93. package/build/src/git/scratch.js +1 -1
  94. package/build/src/git/target-placement.d.ts +1 -1
  95. package/build/src/git/target-placement.js +9 -7
  96. package/build/src/git/tender.d.ts +1 -1
  97. package/build/src/git/tender.js +2 -1
  98. package/build/src/git/terminal-seal.d.ts +2 -2
  99. package/build/src/git/terminal-seal.js +3 -6
  100. package/build/src/git/workspace.d.ts +1 -1
  101. package/build/src/git/workspace.js +1 -1
  102. package/build/src/index.d.ts +1 -2
  103. package/build/src/index.js +1 -1
  104. package/build/src/library/address.js +7 -1
  105. package/build/src/library/audit.d.ts +2 -1
  106. package/build/src/library/audit.js +1 -1
  107. package/build/src/library/bind.d.ts +2 -1
  108. package/build/src/library/bind.js +1 -1
  109. package/build/src/library/configuration.d.ts +1 -1
  110. package/build/src/library/configuration.js +52 -18
  111. package/build/src/library/contract.d.ts +55 -2
  112. package/build/src/library/contract.js +162 -23
  113. package/build/src/library/delivery.d.ts +1 -1
  114. package/build/src/library/fleet.d.ts +27 -7
  115. package/build/src/library/fleet.js +79 -39
  116. package/build/src/library/input.d.ts +0 -1
  117. package/build/src/library/input.js +0 -5
  118. package/build/src/library/keiyaku.d.ts +1 -1
  119. package/build/src/library/mutation.d.ts +2 -1
  120. package/build/src/library/reconcile.d.ts +2 -1
  121. package/build/src/library/reconcile.js +3 -1
  122. package/build/src/library/region.d.ts +1 -1
  123. package/build/src/library/repo.d.ts +3 -1
  124. package/build/src/library/repo.js +8 -4
  125. package/build/src/protocol/abandon.d.ts +9 -0
  126. package/build/src/protocol/abandon.js +15 -0
  127. package/build/src/protocol/amend.d.ts +16 -0
  128. package/build/src/protocol/amend.js +77 -0
  129. package/build/src/protocol/arc.d.ts +6 -0
  130. package/build/src/protocol/arc.js +12 -0
  131. package/build/src/protocol/attempt.d.ts +2 -1
  132. package/build/src/protocol/audit.d.ts +53 -0
  133. package/build/src/protocol/audit.js +140 -0
  134. package/build/src/protocol/bind.d.ts +1 -1
  135. package/build/src/protocol/completion.d.ts +32 -0
  136. package/build/src/protocol/completion.js +130 -0
  137. package/build/src/protocol/deliver.d.ts +37 -0
  138. package/build/src/protocol/deliver.js +160 -0
  139. package/build/src/protocol/intent.d.ts +1 -1
  140. package/build/src/protocol/intent.js +1 -1
  141. package/build/src/protocol/operations.d.ts +64 -200
  142. package/build/src/protocol/operations.js +21 -640
  143. package/build/src/protocol/placement.d.ts +4 -13
  144. package/build/src/protocol/placement.js +3 -15
  145. package/build/src/protocol/read/status.d.ts +1 -1
  146. package/build/src/protocol/read/status.js +3 -1
  147. package/build/src/protocol/reconcile.d.ts +35 -0
  148. package/build/src/protocol/reconcile.js +41 -0
  149. package/build/src/protocol/reintegrate.d.ts +31 -0
  150. package/build/src/protocol/reintegrate.js +74 -0
  151. package/build/src/protocol/review.d.ts +33 -0
  152. package/build/src/protocol/review.js +148 -0
  153. package/build/src/protocol/run.d.ts +1 -1
  154. package/build/src/settlement/fence.d.ts +1 -1
  155. package/build/src/settlement/holder.d.ts +1 -1
  156. package/build/src/settlement/settle.d.ts +1 -1
  157. package/build/src/task/board.d.ts +0 -1
  158. package/build/src/task/board.js +0 -3
  159. package/build/src/task/compose.d.ts +1 -1
  160. package/build/src/task/compose.js +11 -4
  161. package/build/src/task/index.d.ts +1 -1
  162. package/build/src/task/index.js +2 -127
  163. package/build/src/task/input.d.ts +18 -0
  164. package/build/src/task/input.js +189 -0
  165. package/build/src/task/mutation.d.ts +39 -0
  166. package/build/src/task/mutation.js +85 -0
  167. package/build/src/task/operations.d.ts +2 -0
  168. package/build/src/task/operations.js +35 -11
  169. package/build/src/task/store.js +0 -2
  170. package/build/src/verification/execution.d.ts +1 -1
  171. package/build/src/workspace-place.d.ts +1 -4
  172. package/build/src/workspace-place.js +0 -15
  173. package/package.json +3 -3
@@ -0,0 +1,119 @@
1
+ import { insertRequestFact, nonterminalRequestFacts, requestFact, updateRequestRefused, updateRequestReserved, updateRequestServed, updateRequestVoided, updateUpstreamRequestServed, } from "./request-rows.js";
2
+ import { transaction, withHeart } from "./storage.js";
3
+ import { soulFact } from "./soul.js";
4
+ import { clipAllowedActions } from "../allowed.js";
5
+ import { requestPayloadJson } from "./request-rows.js";
6
+ export async function admitRequest(paths, input) {
7
+ return await withHeart(paths, (heart) => transaction(heart, () => {
8
+ const soul = soulFact(heart);
9
+ if (soul === null)
10
+ throw new Error("Akuma request admission requires a born Soul");
11
+ const action = input.action;
12
+ const parentAllowed = soul.allowed;
13
+ const permitted = action === "akuma.wait" || parentAllowed.includes(action);
14
+ const normalized = input.action === "akuma.call"
15
+ ? {
16
+ ...input,
17
+ recipe: {
18
+ ...input.recipe,
19
+ allowed: permitted ? clipAllowedActions(input.recipe.allowed, parentAllowed) : input.recipe.allowed,
20
+ },
21
+ }
22
+ : input;
23
+ insertRequestFact(heart, {
24
+ ...normalized,
25
+ requester: soul.id,
26
+ admittedAt: input.admittedAt,
27
+ ...(permitted ? {} : { refusal: `not-allowed: ${action}` }),
28
+ });
29
+ const fact = requestFact(heart, input.id);
30
+ if (fact === null)
31
+ throw new Error(`Akuma request ${input.id} was not admitted`);
32
+ if (fact.requester !== soul.id
33
+ || fact.id !== normalized.id
34
+ || fact.action !== normalized.action
35
+ || requestPayloadJson(fact) !== requestPayloadJson(normalized)) {
36
+ throw new Error(`Akuma request ${input.id} reused different input`);
37
+ }
38
+ return fact;
39
+ }));
40
+ }
41
+ export async function reserveRequest(paths, id, child) {
42
+ return await withHeart(paths, (heart) => transaction(heart, () => {
43
+ const before = requestFact(heart, id);
44
+ if (before === null)
45
+ throw new Error(`unknown Akuma request ${id}`);
46
+ if (before.action !== "akuma.call")
47
+ throw new Error(`Akuma request ${id} cannot reserve a child`);
48
+ if (before.state === "admitted")
49
+ updateRequestReserved(heart, id, child);
50
+ else if ((before.state !== "reserved" && before.state !== "served") || before.child !== child) {
51
+ throw new Error(`Akuma request ${id} cannot reserve ${child}`);
52
+ }
53
+ return requestFact(heart, id);
54
+ }));
55
+ }
56
+ export async function serveRequest(paths, id, child) {
57
+ return await withHeart(paths, (heart) => transaction(heart, () => {
58
+ const before = requestFact(heart, id);
59
+ if (before === null)
60
+ throw new Error(`unknown Akuma request ${id}`);
61
+ if (before.action !== "akuma.call")
62
+ throw new Error(`Akuma request ${id} cannot serve a child`);
63
+ if (before.state === "reserved" && before.child === child)
64
+ updateRequestServed(heart, id, child);
65
+ else if (before.state !== "served" || before.child !== child) {
66
+ throw new Error(`Akuma request ${id} cannot serve ${child}`);
67
+ }
68
+ return requestFact(heart, id);
69
+ }));
70
+ }
71
+ export async function serveUpstreamRequest(paths, id, service) {
72
+ return await withHeart(paths, (heart) => transaction(heart, () => {
73
+ const before = requestFact(heart, id);
74
+ if (before === null)
75
+ throw new Error(`unknown Akuma request ${id}`);
76
+ if (before.action === "akuma.call" || service.action !== before.action) {
77
+ throw new Error(`Akuma request ${id} has a mismatched service reference`);
78
+ }
79
+ if (before.state === "admitted")
80
+ updateUpstreamRequestServed(heart, id, service);
81
+ else if (before.state !== "served") {
82
+ throw new Error(`Akuma request ${id} cannot be served as ${service.action}`);
83
+ }
84
+ return requestFact(heart, id);
85
+ }));
86
+ }
87
+ export async function refuseRequest(paths, id, diagnostic) {
88
+ return await withHeart(paths, (heart) => transaction(heart, () => {
89
+ const before = requestFact(heart, id);
90
+ if (before === null)
91
+ throw new Error(`unknown Akuma request ${id}`);
92
+ if (before.state === "admitted")
93
+ updateRequestRefused(heart, id, diagnostic);
94
+ else if (before.state !== "refused" || before.diagnostic !== diagnostic) {
95
+ throw new Error(`Akuma request ${id} cannot be refused`);
96
+ }
97
+ return requestFact(heart, id);
98
+ }));
99
+ }
100
+ export async function voidRequest(paths, id, evidence) {
101
+ return await withHeart(paths, (heart) => transaction(heart, () => {
102
+ const before = requestFact(heart, id);
103
+ if (before === null)
104
+ throw new Error(`unknown Akuma request ${id}`);
105
+ if (before.state === "admitted" || before.state === "reserved") {
106
+ updateRequestVoided(heart, id, evidence);
107
+ }
108
+ else if (before.state !== "voided" || before.evidence !== evidence) {
109
+ throw new Error(`Akuma request ${id} cannot be voided`);
110
+ }
111
+ return requestFact(heart, id);
112
+ }));
113
+ }
114
+ export async function readRequest(paths, id) {
115
+ return await withHeart(paths, (heart) => requestFact(heart, id));
116
+ }
117
+ export async function readNonterminalRequests(paths) {
118
+ return await withHeart(paths, nonterminalRequestFacts);
119
+ }
@@ -0,0 +1,16 @@
1
+ import type { DatabaseSync } from "node:sqlite";
2
+ import type { AkuId } from "../identity.js";
3
+ import type { RequestFact, RequestInput } from "./facts.js";
4
+ export declare function requestPayloadJson(input: RequestInput): string;
5
+ export declare function insertRequestFact(database: DatabaseSync, input: RequestInput & Readonly<{
6
+ requester: AkuId;
7
+ admittedAt: string;
8
+ refusal?: string;
9
+ }>): void;
10
+ export declare function requestFact(database: DatabaseSync, id: string): RequestFact | null;
11
+ export declare function nonterminalRequestFacts(database: DatabaseSync): readonly RequestFact[];
12
+ export declare function updateRequestReserved(database: DatabaseSync, id: string, child: AkuId): void;
13
+ export declare function updateRequestServed(database: DatabaseSync, id: string, child: AkuId): void;
14
+ export declare function updateUpstreamRequestServed(database: DatabaseSync, id: string, service: unknown): void;
15
+ export declare function updateRequestRefused(database: DatabaseSync, id: string, diagnostic: string): void;
16
+ export declare function updateRequestVoided(database: DatabaseSync, id: string, evidence: string): void;
@@ -0,0 +1,88 @@
1
+ import { isTaskMutationAction } from "../../task/mutation.js";
2
+ function json(value) {
3
+ return JSON.stringify(value);
4
+ }
5
+ function parsed(value) {
6
+ if (typeof value !== "string")
7
+ throw new Error("Akuma authority contains non-text JSON");
8
+ return JSON.parse(value);
9
+ }
10
+ export function requestPayloadJson(input) {
11
+ const { id: _id, action: _action, requester: _requester, admittedAt: _admittedAt, state: _state, child: _child, service: _service, diagnostic: _diagnostic, evidence: _evidence, refusal: _refusal, ...payload } = input;
12
+ return json(payload);
13
+ }
14
+ function decodeRequestRow(row) {
15
+ const knownAction = [
16
+ "akuma.call", "akuma.wait", "akuma.tell", "akuma.kill", "contract.deliver", "contract.review",
17
+ ].includes(row.action) || isTaskMutationAction(row.action);
18
+ if (!knownAction)
19
+ throw new Error(`Akuma authority contains an unknown request action: ${row.action}`);
20
+ const payload = parsed(row.payload_json);
21
+ const input = {
22
+ id: row.id,
23
+ requester: row.requester,
24
+ action: row.action,
25
+ ...payload,
26
+ admittedAt: row.admitted_at,
27
+ };
28
+ if (row.state === "reserved") {
29
+ if (input.action !== "akuma.call" || row.child === null) {
30
+ throw new Error("Akuma authority contains an invalid reserved request");
31
+ }
32
+ return { ...input, state: row.state, child: row.child };
33
+ }
34
+ if (row.state === "served") {
35
+ if (input.action === "akuma.call") {
36
+ if (row.child === null)
37
+ throw new Error("Akuma authority contains a served call without a child");
38
+ return { ...input, state: row.state, child: row.child };
39
+ }
40
+ if (row.service_json === null) {
41
+ throw new Error("Akuma authority contains a served request without a service reference");
42
+ }
43
+ const service = parsed(row.service_json);
44
+ return { ...input, state: row.state, service };
45
+ }
46
+ if (row.state === "refused")
47
+ return { ...input, state: row.state, diagnostic: row.diagnostic };
48
+ if (row.state === "voided")
49
+ return { ...input, state: row.state, evidence: row.evidence };
50
+ return { ...input, state: "admitted" };
51
+ }
52
+ const REQUEST_COLUMNS = `sequence, id, requester, action, payload_json, admitted_at,
53
+ state, child, service_json, diagnostic, evidence`;
54
+ export function insertRequestFact(database, input) {
55
+ const { id, action, requester, admittedAt, refusal } = input;
56
+ database.prepare(`INSERT OR IGNORE INTO requests(
57
+ id, requester, action, payload_json, admitted_at, state, diagnostic
58
+ ) VALUES (?, ?, ?, ?, ?, ?, ?)`).run(id, requester, action, requestPayloadJson(input), admittedAt, refusal === undefined ? "admitted" : "refused", refusal ?? null);
59
+ }
60
+ export function requestFact(database, id) {
61
+ const row = database.prepare(`SELECT ${REQUEST_COLUMNS} FROM requests WHERE id = ?`).get(id);
62
+ return row === undefined ? null : decodeRequestRow(row);
63
+ }
64
+ export function nonterminalRequestFacts(database) {
65
+ const rows = database.prepare(`SELECT ${REQUEST_COLUMNS} FROM requests
66
+ WHERE state IN ('admitted', 'reserved') ORDER BY sequence`).all();
67
+ return rows.map(decodeRequestRow);
68
+ }
69
+ export function updateRequestReserved(database, id, child) {
70
+ database.prepare("UPDATE requests SET state = 'reserved', child = ? WHERE id = ? AND state = 'admitted'")
71
+ .run(child, id);
72
+ }
73
+ export function updateRequestServed(database, id, child) {
74
+ database.prepare(`UPDATE requests SET state = 'served', child = ?
75
+ WHERE id = ? AND state = 'reserved'`).run(child, id);
76
+ }
77
+ export function updateUpstreamRequestServed(database, id, service) {
78
+ database.prepare(`UPDATE requests SET state = 'served', service_json = ?
79
+ WHERE id = ? AND state = 'admitted' AND action != 'akuma.call'`).run(json(service), id);
80
+ }
81
+ export function updateRequestRefused(database, id, diagnostic) {
82
+ database.prepare(`UPDATE requests SET state = 'refused', diagnostic = ?
83
+ WHERE id = ? AND state = 'admitted'`).run(diagnostic, id);
84
+ }
85
+ export function updateRequestVoided(database, id, evidence) {
86
+ database.prepare(`UPDATE requests SET state = 'voided', child = NULL, service_json = NULL, evidence = ?
87
+ WHERE id = ? AND state IN ('admitted', 'reserved')`).run(evidence, id);
88
+ }
@@ -1,6 +1,5 @@
1
1
  import type { DatabaseSync } from "node:sqlite";
2
- import type { AkuId } from "../identity.js";
3
- import type { BodyEnd, BodyFact, CallFact, KillFact, PauseFact, RequestFact, RequestInput, ResumeCoordinate, SessionFact, StopFact, TurnFact, TurnStartFact, TurnEndFact } from "./facts.js";
2
+ import type { BodyEnd, BodyFact, CallFact, KillFact, PauseFact, ResumeCoordinate, SessionFact, StopFact, TurnFact, TurnStartFact, TurnEndFact } from "./facts.js";
4
3
  export type SealRow = Readonly<{
5
4
  evidence: string;
6
5
  at: string;
@@ -39,19 +38,6 @@ export type CallRow = Readonly<{
39
38
  body: string;
40
39
  at: string;
41
40
  }>;
42
- export type RequestRow = Readonly<{
43
- sequence: number;
44
- id: string;
45
- requester: string;
46
- action: string;
47
- payload_json: string;
48
- admitted_at: string;
49
- state: RequestFact["state"];
50
- child: string | null;
51
- service_json: string | null;
52
- diagnostic: string | null;
53
- evidence: string | null;
54
- }>;
55
41
  export type ActivityRow = Readonly<{
56
42
  sequence: number;
57
43
  turn_sequence: number;
@@ -77,7 +63,6 @@ export declare function decodeSessionRow(row: SessionRow): SessionFact;
77
63
  export declare function decodeBodyRow(row: BodyRow): BodyFact;
78
64
  export declare function decodeTurnRow(row: TurnRow): TurnFact;
79
65
  export declare function decodeCallRow(row: CallRow): CallFact;
80
- export declare function decodeRequestRow(row: RequestRow): RequestFact;
81
66
  export declare function encodeActivityEvent(event: unknown): string;
82
67
  export declare function decodeActivityRow(row: ActivityRow): ActivityFact;
83
68
  export declare function sealExists(database: DatabaseSync): boolean;
@@ -100,18 +85,6 @@ export declare function insertActivityFact(database: DatabaseSync, input: Readon
100
85
  event: unknown;
101
86
  at: string;
102
87
  }>): number;
103
- export declare function insertRequestFact(database: DatabaseSync, input: RequestInput & Readonly<{
104
- requester: AkuId;
105
- admittedAt: string;
106
- refusal?: string;
107
- }>): void;
108
- export declare function requestFact(database: DatabaseSync, id: string): RequestFact | null;
109
- export declare function nonterminalRequestFacts(database: DatabaseSync): readonly RequestFact[];
110
- export declare function updateRequestReserved(database: DatabaseSync, id: string, child: AkuId): void;
111
- export declare function updateRequestServed(database: DatabaseSync, id: string, child: AkuId): void;
112
- export declare function updateUpstreamRequestServed(database: DatabaseSync, id: string, service: unknown): void;
113
- export declare function updateRequestRefused(database: DatabaseSync, id: string, diagnostic: string): void;
114
- export declare function updateRequestVoided(database: DatabaseSync, id: string, evidence: string): void;
115
88
  export declare function insertStopControl(database: DatabaseSync, bodySequence: number, at: string): void;
116
89
  export declare function insertPauseControl(database: DatabaseSync, at: string): void;
117
90
  export declare function stopFact(database: DatabaseSync): StopFact | null;
@@ -7,66 +7,6 @@ function parsed(value) {
7
7
  throw new Error("Akuma authority contains non-text JSON");
8
8
  return JSON.parse(value);
9
9
  }
10
- function object(value) {
11
- return value !== null && typeof value === "object" && !Array.isArray(value)
12
- ? value
13
- : null;
14
- }
15
- function exactKeys(value, expected) {
16
- const actual = Object.keys(value).sort();
17
- return actual.length === expected.length && actual.every((key, index) => key === expected[index]);
18
- }
19
- const KILL_EVIDENCE = [
20
- "already-killed",
21
- "already-stopped",
22
- "hung",
23
- "killed",
24
- "untidy",
25
- "unavailable",
26
- ];
27
- function decodeRequestService(value, input) {
28
- const service = object(value);
29
- if (service === null || service.action !== input.action) {
30
- throw new Error("Akuma authority contains a mismatched request service reference");
31
- }
32
- if (input.action === "akuma.wait") {
33
- if (!exactKeys(service, ["action"])) {
34
- throw new Error("Akuma authority contains an invalid wait service reference");
35
- }
36
- return { action: input.action };
37
- }
38
- if (input.action === "akuma.tell") {
39
- if (!exactKeys(service, ["action", "target", "tellId"])
40
- || service.target !== input.target
41
- || service.tellId !== input.id) {
42
- throw new Error("Akuma authority contains an invalid tell service reference");
43
- }
44
- return { action: input.action, target: input.target, tellId: input.id };
45
- }
46
- if (!exactKeys(service, ["action", "results"]) || !Array.isArray(service.results)) {
47
- throw new Error("Akuma authority contains an invalid kill service reference");
48
- }
49
- let targetIndex = -1;
50
- const results = service.results.map((value) => {
51
- const result = object(value);
52
- if (result === null
53
- || !exactKeys(result, ["evidence", "id"])
54
- || typeof result.id !== "string"
55
- || !KILL_EVIDENCE.includes(result.evidence)) {
56
- throw new Error("Akuma authority contains an invalid kill service reference");
57
- }
58
- const index = input.targets.indexOf(result.id);
59
- if (index <= targetIndex) {
60
- throw new Error("Akuma authority contains an invalid kill service reference");
61
- }
62
- targetIndex = index;
63
- return {
64
- id: result.id,
65
- evidence: result.evidence,
66
- };
67
- });
68
- return { action: input.action, results };
69
- }
70
10
  function resumeCoordinate(value) {
71
11
  const coordinate = decodeResumeCoordinate(value);
72
12
  if (coordinate === null)
@@ -126,46 +66,6 @@ export function decodeTurnRow(row) {
126
66
  export function decodeCallRow(row) {
127
67
  return { kind: "call", sequence: row.sequence, turnSequence: row.turn_sequence, body: row.body, at: row.at };
128
68
  }
129
- export function decodeRequestRow(row) {
130
- if (!["akuma.call", "akuma.wait", "akuma.tell", "akuma.kill"].includes(row.action)) {
131
- throw new Error(`Akuma authority contains an unknown request action: ${row.action}`);
132
- }
133
- const payload = parsed(row.payload_json);
134
- const input = {
135
- id: row.id,
136
- requester: row.requester,
137
- action: row.action,
138
- ...payload,
139
- admittedAt: row.admitted_at,
140
- };
141
- if (row.state === "reserved") {
142
- if (input.action !== "akuma.call" || row.child === null) {
143
- throw new Error("Akuma authority contains an invalid reserved request");
144
- }
145
- return { ...input, state: row.state, child: row.child };
146
- }
147
- if (row.state === "served") {
148
- if (input.action === "akuma.call") {
149
- if (row.child === null)
150
- throw new Error("Akuma authority contains a served call without a child");
151
- return { ...input, state: row.state, child: row.child };
152
- }
153
- if (row.service_json === null) {
154
- throw new Error("Akuma authority contains a served request without a service reference");
155
- }
156
- const service = decodeRequestService(parsed(row.service_json), input);
157
- return {
158
- ...input,
159
- state: row.state,
160
- service,
161
- };
162
- }
163
- if (row.state === "refused")
164
- return { ...input, state: row.state, diagnostic: row.diagnostic };
165
- if (row.state === "voided")
166
- return { ...input, state: row.state, evidence: row.evidence };
167
- return { ...input, state: "admitted" };
168
- }
169
69
  export function encodeActivityEvent(event) {
170
70
  return json(event);
171
71
  }
@@ -210,43 +110,6 @@ export function insertActivityFact(database, input) {
210
110
  .run(sequence, input.turnSequence, encodeActivityEvent(input.event), input.at);
211
111
  return sequence;
212
112
  }
213
- const REQUEST_COLUMNS = `sequence, id, requester, action, payload_json, admitted_at,
214
- state, child, service_json, diagnostic, evidence`;
215
- export function insertRequestFact(database, input) {
216
- const { id, action, requester, admittedAt, refusal, ...payload } = input;
217
- database.prepare(`INSERT OR IGNORE INTO requests(
218
- id, requester, action, payload_json, admitted_at, state, diagnostic
219
- ) VALUES (?, ?, ?, ?, ?, ?, ?)`).run(id, requester, action, json(payload), admittedAt, refusal === undefined ? "admitted" : "refused", refusal ?? null);
220
- }
221
- export function requestFact(database, id) {
222
- const row = database.prepare(`SELECT ${REQUEST_COLUMNS} FROM requests WHERE id = ?`).get(id);
223
- return row === undefined ? null : decodeRequestRow(row);
224
- }
225
- export function nonterminalRequestFacts(database) {
226
- const rows = database.prepare(`SELECT ${REQUEST_COLUMNS} FROM requests
227
- WHERE state IN ('admitted', 'reserved') ORDER BY sequence`).all();
228
- return rows.map(decodeRequestRow);
229
- }
230
- export function updateRequestReserved(database, id, child) {
231
- database.prepare("UPDATE requests SET state = 'reserved', child = ? WHERE id = ? AND state = 'admitted'")
232
- .run(child, id);
233
- }
234
- export function updateRequestServed(database, id, child) {
235
- database.prepare(`UPDATE requests SET state = 'served', child = ?
236
- WHERE id = ? AND state = 'reserved'`).run(child, id);
237
- }
238
- export function updateUpstreamRequestServed(database, id, service) {
239
- database.prepare(`UPDATE requests SET state = 'served', service_json = ?
240
- WHERE id = ? AND state = 'admitted' AND action != 'akuma.call'`).run(json(service), id);
241
- }
242
- export function updateRequestRefused(database, id, diagnostic) {
243
- database.prepare(`UPDATE requests SET state = 'refused', diagnostic = ?
244
- WHERE id = ? AND state = 'admitted'`).run(diagnostic, id);
245
- }
246
- export function updateRequestVoided(database, id, evidence) {
247
- database.prepare(`UPDATE requests SET state = 'voided', child = NULL, service_json = NULL, evidence = ?
248
- WHERE id = ? AND state IN ('admitted', 'reserved')`).run(evidence, id);
249
- }
250
113
  export function insertStopControl(database, bodySequence, at) {
251
114
  database.prepare("INSERT OR IGNORE INTO control(kind, value_json, at) VALUES ('stop', ?, ?)")
252
115
  .run(json({ bodySequence }), at);
@@ -1,5 +1,5 @@
1
1
  import type { DatabaseSync } from "node:sqlite";
2
2
  export declare function assertHeartSchemaVersion(database: DatabaseSync): void;
3
3
  export declare function assertLeashSchemaVersion(database: DatabaseSync): void;
4
- export declare const HEART_SCHEMA = "\n CREATE TABLE IF NOT EXISTS akuma_schema (\n singleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n version INTEGER NOT NULL CHECK (version = 16)\n ) STRICT;\n INSERT OR IGNORE INTO akuma_schema(singleton, version) VALUES (1, 16);\n CREATE TABLE IF NOT EXISTS soul (\n singleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n soul_json TEXT NOT NULL CHECK (json_valid(soul_json))\n ) STRICT;\n CREATE TABLE IF NOT EXISTS bodies (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n leash_taken_at TEXT NOT NULL,\n hung_diagnostic TEXT,\n hung_at TEXT,\n end TEXT CHECK (end IN ('exited', 'broke-off', 'put-down')),\n ended_at TEXT,\n CHECK ((hung_diagnostic IS NULL AND hung_at IS NULL) OR (hung_diagnostic IS NOT NULL AND hung_at IS NOT NULL AND end IS NULL))\n ) STRICT;\n CREATE TABLE IF NOT EXISTS sessions (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n provider TEXT NOT NULL,\n coordinate_json TEXT NOT NULL CHECK (json_valid(coordinate_json)),\n cwd TEXT NOT NULL,\n options_json TEXT NOT NULL CHECK (json_valid(options_json)),\n admitted_at TEXT NOT NULL\n ) STRICT;\n CREATE TABLE IF NOT EXISTS turns (\n sequence INTEGER PRIMARY KEY REFERENCES timeline(sequence) ON DELETE CASCADE,\n body_sequence INTEGER NOT NULL REFERENCES bodies(sequence),\n started_at TEXT NOT NULL,\n end_sequence INTEGER UNIQUE REFERENCES timeline(sequence) ON DELETE SET NULL,\n outcome TEXT CHECK (outcome IN ('answered', 'failed')),\n history_id TEXT UNIQUE,\n session_json TEXT CHECK (session_json IS NULL OR json_valid(session_json)),\n answer TEXT,\n diagnostic TEXT,\n completed_at TEXT,\n CHECK (\n (outcome = 'answered' AND session_json IS NOT NULL AND answer IS NOT NULL AND diagnostic IS NULL)\n OR (outcome = 'failed' AND history_id IS NULL AND session_json IS NULL AND answer IS NULL AND diagnostic IS NOT NULL)\n OR (outcome IS NULL AND end_sequence IS NULL AND history_id IS NULL AND session_json IS NULL AND answer IS NULL AND diagnostic IS NULL AND completed_at IS NULL)\n )\n ) STRICT;\n CREATE TABLE IF NOT EXISTS timeline (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n kind TEXT NOT NULL CHECK (kind IN ('turn-start', 'call', 'activity', 'tell', 'turn-end'))\n ) STRICT;\n CREATE TABLE IF NOT EXISTS calls (\n sequence INTEGER PRIMARY KEY REFERENCES timeline(sequence) ON DELETE CASCADE,\n turn_sequence INTEGER NOT NULL REFERENCES turns(sequence) ON DELETE CASCADE,\n body TEXT NOT NULL,\n at TEXT NOT NULL\n ) STRICT;\n CREATE TABLE IF NOT EXISTS activity (\n sequence INTEGER PRIMARY KEY REFERENCES timeline(sequence) ON DELETE CASCADE,\n turn_sequence INTEGER NOT NULL REFERENCES turns(sequence) ON DELETE CASCADE,\n event_json TEXT NOT NULL CHECK (json_valid(event_json)),\n at TEXT NOT NULL\n ) STRICT;\n CREATE TABLE IF NOT EXISTS tells (\n id TEXT PRIMARY KEY,\n sequence INTEGER NOT NULL UNIQUE REFERENCES timeline(sequence) ON DELETE CASCADE,\n body TEXT NOT NULL,\n recorded_at TEXT NOT NULL\n ) STRICT;\n CREATE TABLE IF NOT EXISTS tell_deliveries (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n tell_id TEXT NOT NULL REFERENCES tells(id) ON DELETE CASCADE,\n route TEXT NOT NULL CHECK (route IN ('launch', 'live')),\n turn_sequence INTEGER NOT NULL REFERENCES turns(sequence) ON DELETE CASCADE,\n fence TEXT NOT NULL,\n receipt TEXT CHECK (receipt IN ('unavailable', 'required')),\n delivered_at TEXT NOT NULL,\n CHECK ((route = 'launch' AND receipt IS NULL) OR (route = 'live' AND receipt IS NOT NULL)),\n UNIQUE (tell_id, turn_sequence, fence)\n ) STRICT;\n CREATE TABLE IF NOT EXISTS tell_receipts (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n evidence TEXT NOT NULL CHECK (evidence IN ('exact', 'fence')),\n tell_id TEXT REFERENCES tells(id) ON DELETE CASCADE,\n turn_sequence INTEGER REFERENCES turns(sequence) ON DELETE CASCADE,\n fence TEXT,\n kind TEXT NOT NULL,\n received_at TEXT NOT NULL,\n CHECK (\n (evidence = 'exact' AND tell_id IS NOT NULL AND turn_sequence IS NULL AND fence IS NULL)\n OR (evidence = 'fence' AND tell_id IS NULL AND turn_sequence IS NOT NULL AND fence IS NOT NULL)\n )\n ) STRICT;\n CREATE UNIQUE INDEX IF NOT EXISTS tell_receipts_exact\n ON tell_receipts(tell_id, kind) WHERE evidence = 'exact';\n CREATE UNIQUE INDEX IF NOT EXISTS tell_receipts_fence\n ON tell_receipts(turn_sequence, fence, kind) WHERE evidence = 'fence';\n CREATE TABLE IF NOT EXISTS requests (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n id TEXT NOT NULL UNIQUE,\n requester TEXT NOT NULL,\n action TEXT NOT NULL CHECK (action IN ('akuma.call', 'akuma.wait', 'akuma.tell', 'akuma.kill')),\n payload_json TEXT NOT NULL CHECK (json_valid(payload_json)),\n admitted_at TEXT NOT NULL,\n state TEXT NOT NULL CHECK (state IN ('admitted', 'reserved', 'served', 'refused', 'voided')),\n child TEXT,\n service_json TEXT CHECK (service_json IS NULL OR json_valid(service_json)),\n diagnostic TEXT,\n evidence TEXT,\n CHECK (\n (state = 'admitted' AND child IS NULL AND service_json IS NULL AND diagnostic IS NULL AND evidence IS NULL)\n OR (state = 'reserved' AND action = 'akuma.call'\n AND child IS NOT NULL AND service_json IS NULL\n AND diagnostic IS NULL AND evidence IS NULL)\n OR (state = 'served'\n AND ((action = 'akuma.call' AND child IS NOT NULL AND service_json IS NULL)\n OR (action != 'akuma.call' AND child IS NULL AND service_json IS NOT NULL))\n AND diagnostic IS NULL AND evidence IS NULL)\n OR (state = 'refused' AND child IS NULL AND service_json IS NULL AND diagnostic IS NOT NULL AND evidence IS NULL)\n OR (state = 'voided' AND child IS NULL AND service_json IS NULL AND diagnostic IS NULL AND evidence IS NOT NULL)\n )\n ) STRICT;\n CREATE TABLE IF NOT EXISTS control (\n kind TEXT PRIMARY KEY CHECK (kind IN ('stop', 'pause')),\n value_json TEXT NOT NULL CHECK (json_valid(value_json)),\n at TEXT NOT NULL\n ) STRICT;\n CREATE TABLE IF NOT EXISTS kills (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n body_sequence INTEGER NOT NULL UNIQUE REFERENCES bodies(sequence),\n evidence TEXT NOT NULL CHECK (evidence = 'killed'),\n at TEXT NOT NULL\n ) STRICT;\n";
4
+ export declare const HEART_SCHEMA = "\n CREATE TABLE IF NOT EXISTS akuma_schema (\n singleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n version INTEGER NOT NULL CHECK (version = 19)\n ) STRICT;\n INSERT OR IGNORE INTO akuma_schema(singleton, version) VALUES (1, 19);\n CREATE TABLE IF NOT EXISTS soul (\n singleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n soul_json TEXT NOT NULL CHECK (json_valid(soul_json))\n ) STRICT;\n CREATE TABLE IF NOT EXISTS bodies (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n leash_taken_at TEXT NOT NULL,\n hung_diagnostic TEXT,\n hung_at TEXT,\n end TEXT CHECK (end IN ('exited', 'broke-off', 'put-down')),\n ended_at TEXT,\n CHECK ((hung_diagnostic IS NULL AND hung_at IS NULL) OR (hung_diagnostic IS NOT NULL AND hung_at IS NOT NULL AND end IS NULL))\n ) STRICT;\n CREATE TABLE IF NOT EXISTS sessions (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n provider TEXT NOT NULL,\n coordinate_json TEXT NOT NULL CHECK (json_valid(coordinate_json)),\n cwd TEXT NOT NULL,\n options_json TEXT NOT NULL CHECK (json_valid(options_json)),\n admitted_at TEXT NOT NULL\n ) STRICT;\n CREATE TABLE IF NOT EXISTS turns (\n sequence INTEGER PRIMARY KEY REFERENCES timeline(sequence) ON DELETE CASCADE,\n body_sequence INTEGER NOT NULL REFERENCES bodies(sequence),\n started_at TEXT NOT NULL,\n end_sequence INTEGER UNIQUE REFERENCES timeline(sequence) ON DELETE SET NULL,\n outcome TEXT CHECK (outcome IN ('answered', 'failed')),\n history_id TEXT UNIQUE,\n session_json TEXT CHECK (session_json IS NULL OR json_valid(session_json)),\n answer TEXT,\n diagnostic TEXT,\n completed_at TEXT,\n CHECK (\n (outcome = 'answered' AND session_json IS NOT NULL AND answer IS NOT NULL AND diagnostic IS NULL)\n OR (outcome = 'failed' AND history_id IS NULL AND session_json IS NULL AND answer IS NULL AND diagnostic IS NOT NULL)\n OR (outcome IS NULL AND end_sequence IS NULL AND history_id IS NULL AND session_json IS NULL AND answer IS NULL AND diagnostic IS NULL AND completed_at IS NULL)\n )\n ) STRICT;\n CREATE TABLE IF NOT EXISTS timeline (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n kind TEXT NOT NULL CHECK (kind IN ('turn-start', 'call', 'activity', 'tell', 'turn-end'))\n ) STRICT;\n CREATE TABLE IF NOT EXISTS calls (\n sequence INTEGER PRIMARY KEY REFERENCES timeline(sequence) ON DELETE CASCADE,\n turn_sequence INTEGER NOT NULL REFERENCES turns(sequence) ON DELETE CASCADE,\n body TEXT NOT NULL,\n at TEXT NOT NULL\n ) STRICT;\n CREATE TABLE IF NOT EXISTS activity (\n sequence INTEGER PRIMARY KEY REFERENCES timeline(sequence) ON DELETE CASCADE,\n turn_sequence INTEGER NOT NULL REFERENCES turns(sequence) ON DELETE CASCADE,\n event_json TEXT NOT NULL CHECK (json_valid(event_json)),\n at TEXT NOT NULL\n ) STRICT;\n CREATE TABLE IF NOT EXISTS tells (\n id TEXT PRIMARY KEY,\n sequence INTEGER NOT NULL UNIQUE REFERENCES timeline(sequence) ON DELETE CASCADE,\n body TEXT NOT NULL,\n recorded_at TEXT NOT NULL\n ) STRICT;\n CREATE TABLE IF NOT EXISTS tell_deliveries (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n tell_id TEXT NOT NULL REFERENCES tells(id) ON DELETE CASCADE,\n route TEXT NOT NULL CHECK (route IN ('launch', 'live')),\n turn_sequence INTEGER NOT NULL REFERENCES turns(sequence) ON DELETE CASCADE,\n fence TEXT NOT NULL,\n receipt TEXT CHECK (receipt IN ('unavailable', 'required')),\n delivered_at TEXT NOT NULL,\n CHECK ((route = 'launch' AND receipt IS NULL) OR (route = 'live' AND receipt IS NOT NULL)),\n UNIQUE (tell_id, turn_sequence, fence)\n ) STRICT;\n CREATE TABLE IF NOT EXISTS tell_receipts (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n evidence TEXT NOT NULL CHECK (evidence IN ('exact', 'fence')),\n tell_id TEXT REFERENCES tells(id) ON DELETE CASCADE,\n turn_sequence INTEGER REFERENCES turns(sequence) ON DELETE CASCADE,\n fence TEXT,\n kind TEXT NOT NULL,\n received_at TEXT NOT NULL,\n CHECK (\n (evidence = 'exact' AND tell_id IS NOT NULL AND turn_sequence IS NULL AND fence IS NULL)\n OR (evidence = 'fence' AND tell_id IS NULL AND turn_sequence IS NOT NULL AND fence IS NOT NULL)\n )\n ) STRICT;\n CREATE UNIQUE INDEX IF NOT EXISTS tell_receipts_exact\n ON tell_receipts(tell_id, kind) WHERE evidence = 'exact';\n CREATE UNIQUE INDEX IF NOT EXISTS tell_receipts_fence\n ON tell_receipts(turn_sequence, fence, kind) WHERE evidence = 'fence';\n CREATE TABLE IF NOT EXISTS requests (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n id TEXT NOT NULL UNIQUE,\n requester TEXT NOT NULL,\n action TEXT NOT NULL CHECK (\n action IN (\n 'akuma.call', 'akuma.wait', 'akuma.tell', 'akuma.kill',\n 'contract.deliver', 'contract.review',\n 'task.add', 'task.addDocument', 'task.compose', 'task.update', 'task.start',\n 'task.stop', 'task.hold', 'task.resume', 'task.done', 'task.drop'\n )\n ),\n payload_json TEXT NOT NULL CHECK (json_valid(payload_json)),\n admitted_at TEXT NOT NULL,\n state TEXT NOT NULL CHECK (state IN ('admitted', 'reserved', 'served', 'refused', 'voided')),\n child TEXT,\n service_json TEXT CHECK (service_json IS NULL OR json_valid(service_json)),\n diagnostic TEXT,\n evidence TEXT,\n CHECK (\n (state = 'admitted' AND child IS NULL AND service_json IS NULL AND diagnostic IS NULL AND evidence IS NULL)\n OR (state = 'reserved' AND action = 'akuma.call'\n AND child IS NOT NULL AND service_json IS NULL\n AND diagnostic IS NULL AND evidence IS NULL)\n OR (state = 'served'\n AND ((action = 'akuma.call' AND child IS NOT NULL AND service_json IS NULL)\n OR (action != 'akuma.call' AND child IS NULL AND service_json IS NOT NULL))\n AND diagnostic IS NULL AND evidence IS NULL)\n OR (state = 'refused' AND child IS NULL AND service_json IS NULL AND diagnostic IS NOT NULL AND evidence IS NULL)\n OR (state = 'voided' AND child IS NULL AND service_json IS NULL AND diagnostic IS NULL AND evidence IS NOT NULL)\n )\n ) STRICT;\n CREATE TABLE IF NOT EXISTS control (\n kind TEXT PRIMARY KEY CHECK (kind IN ('stop', 'pause')),\n value_json TEXT NOT NULL CHECK (json_valid(value_json)),\n at TEXT NOT NULL\n ) STRICT;\n CREATE TABLE IF NOT EXISTS kills (\n sequence INTEGER PRIMARY KEY AUTOINCREMENT,\n body_sequence INTEGER NOT NULL UNIQUE REFERENCES bodies(sequence),\n evidence TEXT NOT NULL CHECK (evidence = 'killed'),\n at TEXT NOT NULL\n ) STRICT;\n";
5
5
  export declare const LEASH_SCHEMA = "\n PRAGMA journal_mode=DELETE;\n CREATE TABLE IF NOT EXISTS leash_schema (\n singleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n version INTEGER NOT NULL CHECK (version = 4)\n ) STRICT;\n INSERT OR IGNORE INTO leash_schema(singleton, version) VALUES (1, 4);\n CREATE TABLE IF NOT EXISTS seal (\n singleton INTEGER PRIMARY KEY CHECK (singleton = 1),\n evidence TEXT NOT NULL,\n at TEXT NOT NULL\n ) STRICT;\n";
@@ -1,4 +1,4 @@
1
- const HEART_SCHEMA_VERSION = 16;
1
+ const HEART_SCHEMA_VERSION = 19;
2
2
  const LEASH_SCHEMA_VERSION = 4;
3
3
  function assertSchemaVersion(database, table, expected) {
4
4
  const row = database.prepare(`SELECT version FROM ${table} WHERE singleton = 1`).get();
@@ -109,7 +109,14 @@ export const HEART_SCHEMA = `
109
109
  sequence INTEGER PRIMARY KEY AUTOINCREMENT,
110
110
  id TEXT NOT NULL UNIQUE,
111
111
  requester TEXT NOT NULL,
112
- action TEXT NOT NULL CHECK (action IN ('akuma.call', 'akuma.wait', 'akuma.tell', 'akuma.kill')),
112
+ action TEXT NOT NULL CHECK (
113
+ action IN (
114
+ 'akuma.call', 'akuma.wait', 'akuma.tell', 'akuma.kill',
115
+ 'contract.deliver', 'contract.review',
116
+ 'task.add', 'task.addDocument', 'task.compose', 'task.update', 'task.start',
117
+ 'task.stop', 'task.hold', 'task.resume', 'task.done', 'task.drop'
118
+ )
119
+ ),
113
120
  payload_json TEXT NOT NULL CHECK (json_valid(payload_json)),
114
121
  admitted_at TEXT NOT NULL,
115
122
  state TEXT NOT NULL CHECK (state IN ('admitted', 'reserved', 'served', 'refused', 'voided')),
@@ -6,9 +6,6 @@ function record(value) {
6
6
  ? value
7
7
  : null;
8
8
  }
9
- function unknownKey(value, allowed) {
10
- return Object.keys(value).find((key) => !allowed.includes(key));
11
- }
12
9
  function nonblank(value, what) {
13
10
  if (typeof value !== "string" || value.trim().length === 0) {
14
11
  throw new Error(`Akuma soul ${what} must be a nonblank string`);
@@ -28,14 +25,9 @@ function decodeOrigin(value) {
28
25
  if (origin === null)
29
26
  throw new Error("Akuma soul origin must be an object");
30
27
  if (origin.kind === "direct") {
31
- if (unknownKey(origin, ["kind"]) !== undefined)
32
- throw new Error("Akuma soul direct origin must have only kind");
33
28
  return { kind: "direct" };
34
29
  }
35
30
  if (origin.kind === "request") {
36
- if (unknownKey(origin, ["kind", "parent", "requestId"]) !== undefined) {
37
- throw new Error("Akuma soul request origin must have only kind, parent, and requestId");
38
- }
39
31
  return {
40
32
  kind: "request",
41
33
  parent: soulAkuIdentity(origin.parent, "request parent").id,
@@ -43,9 +35,6 @@ function decodeOrigin(value) {
43
35
  };
44
36
  }
45
37
  if (origin.kind === "fork") {
46
- if (unknownKey(origin, ["at", "kind", "parent"]) !== undefined) {
47
- throw new Error("Akuma soul fork origin must have only kind, parent, and at");
48
- }
49
38
  return {
50
39
  kind: "fork",
51
40
  parent: soulAkuIdentity(origin.parent, "fork parent").id,
@@ -54,34 +43,10 @@ function decodeOrigin(value) {
54
43
  }
55
44
  throw new Error("Akuma soul origin must be direct, request, or fork");
56
45
  }
57
- function decodeConfinement(value) {
58
- const confinement = record(value);
59
- if (confinement === null)
60
- throw new Error("Akuma soul confinement must be an object");
61
- if (confinement.kind === "unconfined") {
62
- if (unknownKey(confinement, ["kind"]) !== undefined)
63
- throw new Error("Akuma soul unconfined confinement must have only kind");
64
- return { kind: "unconfined" };
65
- }
66
- if (confinement.kind === "declared") {
67
- if (unknownKey(confinement, ["kind", "writableRoots"]) !== undefined) {
68
- throw new Error("Akuma soul declared confinement must have only kind and writableRoots");
69
- }
70
- if (!Array.isArray(confinement.writableRoots)
71
- || confinement.writableRoots.some((root) => typeof root !== "string" || root.trim().length === 0)) {
72
- throw new Error("Akuma soul declared confinement writableRoots must be nonblank strings");
73
- }
74
- return { kind: "declared", writableRoots: [...confinement.writableRoots] };
75
- }
76
- throw new Error("Akuma soul confinement must be unconfined or declared");
77
- }
78
46
  function validateSoul(value) {
79
47
  const soul = record(value);
80
48
  if (soul === null)
81
49
  throw new Error("Akuma soul must be an object");
82
- if (unknownKey(soul, ["allowed", "archetype", "confinement", "createdAt", "cwd", "description", "id", "options", "origin", "provider", "readonly"]) !== undefined) {
83
- throw new Error("Akuma soul has an unknown field");
84
- }
85
50
  const identity = soulAkuIdentity(soul.id, "id");
86
51
  const id = identity.id;
87
52
  const archetype = nonblank(soul.archetype, "name");
@@ -103,7 +68,6 @@ function validateSoul(value) {
103
68
  ...(restraint === undefined ? {} : { readonly: restraint }),
104
69
  cwd: nonblank(soul.cwd, "cwd"),
105
70
  origin: decodeOrigin(soul.origin),
106
- confinement: decodeConfinement(soul.confinement),
107
71
  allowed: effectiveAllowedActions(soul.allowed),
108
72
  createdAt: nonblank(soul.createdAt, "createdAt"),
109
73
  };
@@ -13,5 +13,5 @@ export type { AkumaList, AkumaListInput, AkumaListRow, AkumaStatus, ActivityHist
13
13
  export type { ActiveToolRow, ClosedTurn, ClosedTurnRow, CompletedToolRow, HistoryCursor, HistoryPage, IdleSnapshotRow, OpenSnapshotRow, OpenTurn, OpenTurnRow, OutcomeRow, ReportedFileChange, RetainedWindow, Snapshot, SnapshotRow, TellRow, TurnLedger, TurnOutcome, TurnStartRow, UnsettledToolRow, } from "./akuma.js";
14
14
  export type { AgentEvent, ToolCall, ToolEvent, ToolResult } from "./provider.js";
15
15
  export type { AkuId } from "./identity.js";
16
- export type { Confinement, KillEvidence, ResumeCoordinate, TurnFact, } from "./heart/index.js";
16
+ export type { KillEvidence, ResumeCoordinate, TurnFact, } from "./heart/index.js";
17
17
  export type { ProviderOptions, ReadonlyRestraint } from "./provider-recipe.js";
@@ -24,10 +24,6 @@ export function decodeProviderOptions(value) {
24
24
  const options = record(value);
25
25
  if (options === null)
26
26
  throw new TypeError("provider options must be an object");
27
- const allowed = ["effort", "model", "network", "readonly", "systemPrompt"];
28
- const unknown = Object.keys(options).find((key) => !allowed.includes(key));
29
- if (unknown !== undefined)
30
- throw new TypeError(`provider options have unknown field ${unknown}`);
31
27
  const model = optionText(options, "model", "refuse");
32
28
  const effort = optionText(options, "effort", "refuse");
33
29
  if (options.readonly !== undefined && options.readonly !== true) {
@@ -50,12 +46,10 @@ export function decodeReadonlyRestraint(value) {
50
46
  const restraint = record(value);
51
47
  if (restraint === null)
52
48
  throw new TypeError("readonly restraint must be an object");
53
- const keys = Object.keys(restraint).sort();
54
- if (restraint.enforcement === "native" && keys.length === 1 && keys[0] === "enforcement") {
49
+ if (restraint.enforcement === "native") {
55
50
  return Object.freeze({ enforcement: "native" });
56
51
  }
57
52
  if (restraint.enforcement === "none"
58
- && keys.length === 2 && keys[0] === "diagnostic" && keys[1] === "enforcement"
59
53
  && typeof restraint.diagnostic === "string" && restraint.diagnostic.trim().length > 0) {
60
54
  return Object.freeze({ enforcement: "none", diagnostic: restraint.diagnostic });
61
55
  }
@@ -69,10 +63,6 @@ export function decodeProviderRecipe(input) {
69
63
  const value = record(input);
70
64
  if (value === null)
71
65
  throw new TypeError("provider execution must be an object");
72
- const allowed = ["config", "env", "executable", "kind", "name"];
73
- const unknown = Object.keys(value).find((key) => !allowed.includes(key));
74
- if (unknown !== undefined)
75
- throw new TypeError(`provider execution has unknown field ${unknown}`);
76
66
  if (typeof value.name !== "string" || value.name.trim().length === 0) {
77
67
  throw new TypeError("provider execution name must be a nonblank string");
78
68
  }
@@ -1,4 +1,3 @@
1
- import type { Confinement } from "./heart/index.js";
2
1
  import { decodeResumeCoordinate, encodeResumeCoordinate, type ResumeCoordinate } from "./coordinate.js";
3
2
  import type { ProviderOptions, ReadonlyRestraint } from "./provider-recipe.js";
4
3
  export type { ResumeCoordinate } from "./coordinate.js";
@@ -138,7 +137,7 @@ export type DriveInput = Readonly<{
138
137
  cwd: string;
139
138
  options: ProviderOptions;
140
139
  signal: AbortSignal;
141
- requests?: Readonly<{
140
+ requests: Readonly<{
142
141
  dir: string;
143
142
  }>;
144
143
  }>;
@@ -151,10 +150,6 @@ export type ProviderOptionAdmission = Readonly<{
151
150
  diagnostic: string;
152
151
  }>;
153
152
  export type ProviderAdapter = Readonly<{
154
- confinement(input: Readonly<{
155
- cwd: string;
156
- options: ProviderOptions;
157
- }>): Confinement;
158
153
  admitOptions(options: ProviderOptions): ProviderOptionAdmission;
159
154
  fork?(input: Readonly<{
160
155
  session: ResumeCoordinate;