@astrosheep/keiyaku 4.0.1 → 4.0.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.
Files changed (246) hide show
  1. package/README.md +137 -5
  2. package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +1 -1
  3. package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
  4. package/build/integrations/marketplace/plugins/keiyaku/package.json +1 -1
  5. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +3 -3
  6. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +91 -35
  7. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +89 -58
  8. package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +146 -53
  9. package/build/src/akuma/abort.d.ts +2 -0
  10. package/build/src/akuma/abort.js +50 -0
  11. package/build/src/akuma/akuma.d.ts +23 -14
  12. package/build/src/akuma/akuma.js +120 -104
  13. package/build/src/akuma/archetype.d.ts +7 -6
  14. package/build/src/akuma/archetype.js +68 -41
  15. package/build/src/akuma/body.d.ts +3 -5
  16. package/build/src/akuma/body.js +417 -214
  17. package/build/src/akuma/heart/facts.d.ts +25 -34
  18. package/build/src/akuma/heart/facts.js +18 -7
  19. package/build/src/akuma/heart/index.d.ts +39 -42
  20. package/build/src/akuma/heart/index.js +134 -93
  21. package/build/src/akuma/heart/rows.d.ts +9 -31
  22. package/build/src/akuma/heart/rows.js +26 -44
  23. package/build/src/akuma/heart/schema.d.ts +1 -1
  24. package/build/src/akuma/heart/schema.js +7 -15
  25. package/build/src/akuma/heart/soul.d.ts +8 -0
  26. package/build/src/akuma/heart/soul.js +136 -0
  27. package/build/src/akuma/heart/storage.d.ts +29 -14
  28. package/build/src/akuma/heart/storage.js +91 -26
  29. package/build/src/akuma/identity.d.ts +2 -2
  30. package/build/src/akuma/identity.js +9 -9
  31. package/build/src/akuma/index.d.ts +6 -1
  32. package/build/src/akuma/index.js +6 -0
  33. package/build/src/akuma/projection.d.ts +117 -38
  34. package/build/src/akuma/projection.js +208 -97
  35. package/build/src/akuma/provider-recipe.d.ts +24 -0
  36. package/build/src/akuma/provider-recipe.js +100 -0
  37. package/build/src/akuma/provider.d.ts +12 -4
  38. package/build/src/akuma/provider.js +117 -70
  39. package/build/src/akuma/providers/acp/core.d.ts +19 -0
  40. package/build/src/akuma/providers/acp/core.js +159 -0
  41. package/build/src/akuma/providers/acp/events.d.ts +20 -0
  42. package/build/src/akuma/providers/acp/events.js +73 -0
  43. package/build/src/akuma/providers/acp/index.d.ts +12 -0
  44. package/build/src/akuma/providers/acp/index.js +94 -0
  45. package/build/src/akuma/providers/claude/events.js +66 -13
  46. package/build/src/akuma/providers/claude/index.d.ts +2 -1
  47. package/build/src/akuma/providers/claude/index.js +35 -21
  48. package/build/src/akuma/providers/codex-app-server/events.js +4 -1
  49. package/build/src/akuma/providers/codex-app-server/index.d.ts +3 -3
  50. package/build/src/akuma/providers/codex-app-server/index.js +24 -31
  51. package/build/src/akuma/providers/grok-build/index.d.ts +4 -0
  52. package/build/src/akuma/providers/grok-build/index.js +70 -0
  53. package/build/src/akuma/providers/index.d.ts +5 -3
  54. package/build/src/akuma/providers/index.js +24 -59
  55. package/build/src/akuma/providers/opencode-sdk/events.d.ts +40 -34
  56. package/build/src/akuma/providers/opencode-sdk/events.js +220 -101
  57. package/build/src/akuma/providers/opencode-sdk/index.d.ts +3 -2
  58. package/build/src/akuma/providers/opencode-sdk/index.js +233 -128
  59. package/build/src/akuma/providers/opencode-sdk/session.d.ts +11 -26
  60. package/build/src/akuma/providers/opencode-sdk/session.js +10 -9
  61. package/build/src/akuma/providers/pi/events.js +49 -11
  62. package/build/src/akuma/providers/pi/index.d.ts +1 -1
  63. package/build/src/akuma/providers/pi/index.js +50 -21
  64. package/build/src/akuma/publication.d.ts +3 -3
  65. package/build/src/akuma/publication.js +61 -44
  66. package/build/src/akuma/requests.d.ts +9 -7
  67. package/build/src/akuma/requests.js +92 -65
  68. package/build/src/alias/index.d.ts +2 -2
  69. package/build/src/alias/index.js +10 -10
  70. package/build/src/body/decode.js +7 -1
  71. package/build/src/body/region.d.ts +2 -0
  72. package/build/src/body/region.js +77 -7
  73. package/build/src/cli/accepted.d.ts +17 -13
  74. package/build/src/cli/accepted.js +72 -34
  75. package/build/src/cli/actor.js +3 -3
  76. package/build/src/cli/commands/akuma-invoke.d.ts +4 -3
  77. package/build/src/cli/commands/akuma-invoke.js +14 -9
  78. package/build/src/cli/commands/akuma.d.ts +13 -3
  79. package/build/src/cli/commands/akuma.js +67 -34
  80. package/build/src/cli/commands/contract.d.ts +18 -5
  81. package/build/src/cli/commands/contract.js +9 -3
  82. package/build/src/cli/commands/install.js +2 -2
  83. package/build/src/cli/commands/task-invoke.d.ts +17 -4
  84. package/build/src/cli/commands/task-invoke.js +43 -20
  85. package/build/src/cli/commands/task-query.d.ts +5 -0
  86. package/build/src/cli/commands/task-query.js +247 -0
  87. package/build/src/cli/commands/task.d.ts +3 -1
  88. package/build/src/cli/commands/task.js +54 -16
  89. package/build/src/cli/coordinates.d.ts +18 -0
  90. package/build/src/cli/coordinates.js +120 -0
  91. package/build/src/cli/draft.d.ts +8 -0
  92. package/build/src/cli/draft.js +96 -0
  93. package/build/src/cli/invoke.d.ts +4 -3
  94. package/build/src/cli/invoke.js +160 -179
  95. package/build/src/cli/main.js +34 -6
  96. package/build/src/cli/parse.d.ts +9 -2
  97. package/build/src/cli/parse.js +31 -9
  98. package/build/src/cli/render/akuma-tool-command.d.ts +6 -0
  99. package/build/src/cli/render/akuma-tool-command.js +144 -0
  100. package/build/src/cli/render/akuma-tool.d.ts +2 -2
  101. package/build/src/cli/render/akuma-tool.js +30 -4
  102. package/build/src/cli/render/akuma.d.ts +1 -0
  103. package/build/src/cli/render/akuma.js +211 -116
  104. package/build/src/cli/render/audit.d.ts +3 -0
  105. package/build/src/cli/render/audit.js +104 -0
  106. package/build/src/cli/render/contract.d.ts +3 -3
  107. package/build/src/cli/render/contract.js +192 -79
  108. package/build/src/cli/render/kanshi.js +263 -168
  109. package/build/src/cli/render/receipt.d.ts +19 -0
  110. package/build/src/cli/render/receipt.js +106 -0
  111. package/build/src/cli/render/refusal.d.ts +16 -2
  112. package/build/src/cli/render/refusal.js +88 -20
  113. package/build/src/cli/render/region.d.ts +2 -0
  114. package/build/src/cli/render/region.js +17 -0
  115. package/build/src/cli/render/task.d.ts +2 -1
  116. package/build/src/cli/render/task.js +223 -60
  117. package/build/src/cli/render/terminal.d.ts +7 -0
  118. package/build/src/cli/render/terminal.js +46 -0
  119. package/build/src/cli/render/text.js +6 -3
  120. package/build/src/cli/result.d.ts +115 -20
  121. package/build/src/cli/usage.d.ts +3 -0
  122. package/build/src/cli/usage.js +7 -0
  123. package/build/src/contract-worktree.d.ts +6 -5
  124. package/build/src/contract-worktree.js +95 -57
  125. package/build/src/coordination/durable-file.d.ts +4 -3
  126. package/build/src/coordination/durable-file.js +29 -25
  127. package/build/src/coordination/sqlite-transaction-lock.d.ts +4 -0
  128. package/build/src/coordination/sqlite-transaction-lock.js +22 -5
  129. package/build/src/core/facts/fold.js +1 -6
  130. package/build/src/core/facts/gate.d.ts +1 -0
  131. package/build/src/core/facts/gate.js +1 -0
  132. package/build/src/core/verbs/amend.d.ts +1 -1
  133. package/build/src/core/verbs/amend.js +0 -11
  134. package/build/src/core/verbs/deliver.d.ts +1 -1
  135. package/build/src/core/verbs/deliver.js +1 -7
  136. package/build/src/core/verbs/placement.d.ts +1 -1
  137. package/build/src/core/verbs/placement.js +4 -1
  138. package/build/src/dispatch/index.d.ts +2 -2
  139. package/build/src/dispatch/index.js +17 -17
  140. package/build/src/git/admission.d.ts +1 -1
  141. package/build/src/git/admission.js +11 -11
  142. package/build/src/git/hooks.js +13 -13
  143. package/build/src/git/integration.d.ts +14 -15
  144. package/build/src/git/integration.js +80 -44
  145. package/build/src/git/observe.d.ts +5 -3
  146. package/build/src/git/observe.js +18 -12
  147. package/build/src/git/read-observation.js +10 -9
  148. package/build/src/git/reconcile.d.ts +2 -0
  149. package/build/src/git/reconcile.js +138 -95
  150. package/build/src/git/repository.d.ts +27 -19
  151. package/build/src/git/repository.js +155 -83
  152. package/build/src/git/scratch.d.ts +7 -3
  153. package/build/src/git/scratch.js +44 -37
  154. package/build/src/git/target-placement.d.ts +40 -4
  155. package/build/src/git/target-placement.js +221 -101
  156. package/build/src/git/tender.d.ts +6 -5
  157. package/build/src/git/tender.js +24 -43
  158. package/build/src/git/terminal-seal.d.ts +1 -1
  159. package/build/src/git/terminal-seal.js +7 -5
  160. package/build/src/git/workspace.d.ts +36 -4
  161. package/build/src/git/workspace.js +53 -18
  162. package/build/src/identity/selector.js +1 -1
  163. package/build/src/index.d.ts +3 -3
  164. package/build/src/index.js +1 -1
  165. package/build/src/kanshi/index.d.ts +2 -2
  166. package/build/src/kanshi/index.js +1 -1
  167. package/build/src/kanshi/read.d.ts +2 -1
  168. package/build/src/kanshi/read.js +118 -27
  169. package/build/src/kanshi/report.d.ts +50 -0
  170. package/build/src/kanshi/select.d.ts +5 -0
  171. package/build/src/kanshi/select.js +32 -0
  172. package/build/src/library/address.d.ts +12 -3
  173. package/build/src/library/address.js +77 -46
  174. package/build/src/library/akuma-creation.d.ts +6 -1
  175. package/build/src/library/akuma-creation.js +86 -13
  176. package/build/src/library/audit.d.ts +18 -0
  177. package/build/src/library/audit.js +44 -0
  178. package/build/src/library/bind.js +4 -4
  179. package/build/src/library/catalog.d.ts +1 -1
  180. package/build/src/library/catalog.js +5 -8
  181. package/build/src/library/contract.d.ts +5 -6
  182. package/build/src/library/contract.js +11 -35
  183. package/build/src/library/delivery.d.ts +2 -1
  184. package/build/src/library/fleet.d.ts +2 -2
  185. package/build/src/library/fleet.js +35 -71
  186. package/build/src/library/keiyaku.d.ts +3 -2
  187. package/build/src/library/keiyaku.js +1 -0
  188. package/build/src/library/mutation.d.ts +7 -6
  189. package/build/src/library/mutation.js +23 -25
  190. package/build/src/library/reconcile.d.ts +29 -0
  191. package/build/src/library/reconcile.js +179 -0
  192. package/build/src/library/region.d.ts +12 -0
  193. package/build/src/library/region.js +15 -1
  194. package/build/src/library/repo.d.ts +4 -16
  195. package/build/src/library/repo.js +13 -38
  196. package/build/src/protocol/attempt.js +6 -6
  197. package/build/src/protocol/bind.js +4 -4
  198. package/build/src/protocol/intent.d.ts +15 -2
  199. package/build/src/protocol/intent.js +21 -6
  200. package/build/src/protocol/operations.d.ts +73 -22
  201. package/build/src/protocol/operations.js +292 -88
  202. package/build/src/protocol/outcome.d.ts +9 -3
  203. package/build/src/protocol/outcome.js +3 -1
  204. package/build/src/protocol/placement.d.ts +15 -4
  205. package/build/src/protocol/placement.js +58 -25
  206. package/build/src/protocol/read/status.d.ts +8 -1
  207. package/build/src/protocol/read/status.js +61 -14
  208. package/build/src/runtime/proc/line-rpc.d.ts +3 -8
  209. package/build/src/runtime/proc/line-rpc.js +16 -43
  210. package/build/src/runtime/proc/run.d.ts +15 -29
  211. package/build/src/runtime/proc/run.js +113 -105
  212. package/build/src/runtime/proc/stdio.d.ts +18 -0
  213. package/build/src/runtime/proc/stdio.js +58 -0
  214. package/build/src/settings.d.ts +2 -2
  215. package/build/src/settings.js +8 -8
  216. package/build/src/settlement/fence.d.ts +0 -4
  217. package/build/src/settlement/fence.js +0 -9
  218. package/build/src/settlement/holder.d.ts +11 -1
  219. package/build/src/settlement/holder.js +25 -0
  220. package/build/src/settlement/settle.d.ts +1 -1
  221. package/build/src/settlement/settle.js +52 -89
  222. package/build/src/task/board.d.ts +3 -3
  223. package/build/src/task/board.js +6 -9
  224. package/build/src/task/compose.d.ts +1 -1
  225. package/build/src/task/compose.js +18 -10
  226. package/build/src/task/context.d.ts +3 -3
  227. package/build/src/task/context.js +14 -14
  228. package/build/src/task/document.d.ts +2 -1
  229. package/build/src/task/document.js +15 -5
  230. package/build/src/task/index.d.ts +19 -7
  231. package/build/src/task/index.js +42 -23
  232. package/build/src/task/operations.d.ts +15 -9
  233. package/build/src/task/operations.js +78 -48
  234. package/build/src/task/query.d.ts +67 -0
  235. package/build/src/task/query.js +279 -0
  236. package/build/src/task/store.d.ts +2 -2
  237. package/build/src/task/store.js +40 -25
  238. package/build/src/verification/execution.d.ts +4 -2
  239. package/build/src/verification/execution.js +9 -5
  240. package/build/src/workspace-place.d.ts +41 -0
  241. package/build/src/workspace-place.js +386 -0
  242. package/build/src/world.d.ts +13 -2
  243. package/build/src/world.js +81 -48
  244. package/package.json +3 -2
  245. package/build/src/protocol/read/audit.d.ts +0 -31
  246. package/build/src/protocol/read/audit.js +0 -55
@@ -1,24 +1,67 @@
1
1
  import { DatabaseSync } from "node:sqlite";
2
+ import { lstat } from "node:fs/promises";
3
+ import { pathToFileURL } from "node:url";
2
4
  import { HEART_SCHEMA, LEASH_SCHEMA, assertHeartSchemaVersion, assertLeashSchemaVersion } from "./schema.js";
3
- import { deletePauseControl, deleteStopControl, insertKillFact, insertSealFact, insertSessionFact, insertSoulFact, killFactForBody, latestBodyFact, latestKillFact, sealExists, sealFact, soulFact, stopFact, } from "./rows.js";
5
+ import { deletePauseControl, deleteStopControl, insertBodyFact, insertKillFact, insertSealFact, insertSessionFact, killFactForBody, latestBodyFact, latestKillFact, markBodyHung, sealExists, sealFact, stopFact, } from "./rows.js";
4
6
  import { insertTellFact } from "./tells.js";
5
7
  import { pruneActivityFacts } from "./timeline.js";
8
+ import { insertSoulFact, soulFact } from "./soul.js";
6
9
  const ACTIVITY_LIMIT = 5_000;
10
+ const SQLITE_CANTOPEN = 14;
11
+ export class HeartAbsentError extends Error {
12
+ path;
13
+ constructor(path, options) {
14
+ super(`Akuma Heart database is absent: ${path}`, options);
15
+ this.path = path;
16
+ this.name = "HeartAbsentError";
17
+ }
18
+ }
19
+ export function isHeartAbsent(error) {
20
+ return error instanceof HeartAbsentError;
21
+ }
7
22
  function isBusy(error) {
8
23
  const value = error;
9
24
  const message = String(value?.message ?? "").toLowerCase();
10
25
  return value?.code === "ERR_SQLITE_BUSY" || value?.code === "ERR_SQLITE_LOCKED"
11
26
  || value?.errcode === 5 || message.includes("database is locked") || message.includes("database is busy");
12
27
  }
13
- export function openHeart(path, verify = true) {
14
- const database = new DatabaseSync(path);
15
- database.exec("PRAGMA foreign_keys=ON; PRAGMA busy_timeout=5000; PRAGMA journal_mode=WAL");
16
- if (verify)
17
- assertHeartSchemaVersion(database);
18
- return database;
28
+ async function openExistingDatabase(path, timeout) {
29
+ const uri = pathToFileURL(path);
30
+ uri.searchParams.set("mode", "rw");
31
+ try {
32
+ return timeout === undefined
33
+ ? new DatabaseSync(uri.href)
34
+ : new DatabaseSync(uri.href, { timeout });
35
+ }
36
+ catch (error) {
37
+ if (error.errcode === SQLITE_CANTOPEN) {
38
+ try {
39
+ await lstat(path);
40
+ }
41
+ catch (metadataError) {
42
+ if (metadataError.code === "ENOENT") {
43
+ throw new HeartAbsentError(path, { cause: error });
44
+ }
45
+ }
46
+ }
47
+ throw error;
48
+ }
49
+ }
50
+ async function openHeart(path, verify = true) {
51
+ const database = await openExistingDatabase(path);
52
+ try {
53
+ database.exec("PRAGMA foreign_keys=ON; PRAGMA busy_timeout=5000; PRAGMA journal_mode=WAL");
54
+ if (verify)
55
+ assertHeartSchemaVersion(database);
56
+ return database;
57
+ }
58
+ catch (error) {
59
+ database.close();
60
+ throw error;
61
+ }
19
62
  }
20
- export function withHeart(paths, body) {
21
- const database = openHeart(paths.heart);
63
+ export async function withHeart(paths, body) {
64
+ const database = await openHeart(paths.heart);
22
65
  try {
23
66
  return body(database);
24
67
  }
@@ -41,8 +84,8 @@ export function transaction(database, body) {
41
84
  throw error;
42
85
  }
43
86
  }
44
- export function initializeHeart(paths) {
45
- const heart = openHeart(paths.heart, false);
87
+ export async function initializeHeart(paths) {
88
+ const heart = new DatabaseSync(paths.heart);
46
89
  try {
47
90
  heart.exec(HEART_SCHEMA);
48
91
  assertHeartSchemaVersion(heart);
@@ -62,11 +105,12 @@ export function initializeHeart(paths) {
62
105
  export class HeldAkumaLeash {
63
106
  database;
64
107
  closed = false;
108
+ bodySequence;
65
109
  constructor(database) {
66
110
  this.database = database;
67
111
  }
68
- static try(paths) {
69
- const database = new DatabaseSync(paths.leash, { timeout: 0 });
112
+ static async try(paths) {
113
+ const database = await openExistingDatabase(paths.leash, 0);
70
114
  try {
71
115
  assertLeashSchemaVersion(database);
72
116
  database.exec("PRAGMA busy_timeout=0; BEGIN EXCLUSIVE");
@@ -79,10 +123,10 @@ export class HeldAkumaLeash {
79
123
  throw error;
80
124
  }
81
125
  }
82
- birth(paths, soul, session) {
126
+ async birth(paths, soul, session) {
83
127
  if (sealExists(this.database))
84
128
  return "sealed";
85
- return withHeart(paths, (heart) => transaction(heart, () => {
129
+ return await withHeart(paths, (heart) => transaction(heart, () => {
86
130
  if (soulFact(heart) !== null)
87
131
  return "already-born";
88
132
  insertSoulFact(heart, soul);
@@ -91,8 +135,10 @@ export class HeldAkumaLeash {
91
135
  return "born";
92
136
  }));
93
137
  }
94
- sealIfUnborn(paths, input) {
95
- if (withHeart(paths, (heart) => soulFact(heart)) !== null)
138
+ async sealIfUnborn(paths, input) {
139
+ if (sealExists(this.database))
140
+ return "sealed";
141
+ if (await withHeart(paths, (heart) => soulFact(heart)) !== null)
96
142
  return "born";
97
143
  insertSealFact(this.database, input);
98
144
  this.database.exec("COMMIT");
@@ -100,9 +146,26 @@ export class HeldAkumaLeash {
100
146
  this.database.close();
101
147
  return "sealed";
102
148
  }
103
- clearPause(paths) { withHeart(paths, deletePauseControl); }
104
- settleStop(paths, expectedBodySequence) {
105
- return withHeart(paths, (heart) => transaction(heart, () => {
149
+ readSeal() {
150
+ return sealFact(this.database);
151
+ }
152
+ async clearPause(paths) { await withHeart(paths, deletePauseControl); }
153
+ async clearStop(paths) { await withHeart(paths, deleteStopControl); }
154
+ async recordBody(paths, input) {
155
+ if (this.closed || this.bodySequence !== undefined)
156
+ throw new Error("Akuma leash cannot start another Body");
157
+ const sequence = await withHeart(paths, (heart) => insertBodyFact(heart, input));
158
+ this.bodySequence = sequence;
159
+ return { sequence, leashTakenAt: input.leashTakenAt };
160
+ }
161
+ async recordBodyHung(paths, input) {
162
+ if (this.closed || this.bodySequence !== input.sequence) {
163
+ throw new Error(`Akuma Body ${input.sequence} is not owned by this leash`);
164
+ }
165
+ await withHeart(paths, (heart) => markBodyHung(heart, input));
166
+ }
167
+ async settleStop(paths, expectedBodySequence) {
168
+ return await withHeart(paths, (heart) => transaction(heart, () => {
106
169
  const target = stopFact(heart);
107
170
  if (target === null) {
108
171
  if (expectedBodySequence === undefined)
@@ -116,6 +179,8 @@ export class HeldAkumaLeash {
116
179
  const latest = latestBodyFact(heart);
117
180
  if (latest?.sequence !== target.bodySequence)
118
181
  throw new Error("Akuma stop target is not the latest Body");
182
+ if (latest.end !== "put-down")
183
+ return null;
119
184
  const result = latestKillFact(heart)?.bodySequence === target.bodySequence
120
185
  ? "already-killed"
121
186
  : (insertKillFact(heart, target.bodySequence, target.requestedAt), "recorded");
@@ -123,8 +188,8 @@ export class HeldAkumaLeash {
123
188
  return { target, result };
124
189
  }));
125
190
  }
126
- recordInterruptTell(paths, tell) {
127
- return withHeart(paths, (heart) => transaction(heart, () => {
191
+ async recordInterruptTell(paths, tell) {
192
+ return await withHeart(paths, (heart) => transaction(heart, () => {
128
193
  deletePauseControl(heart);
129
194
  if (soulFact(heart) === null)
130
195
  return { kind: "not-born" };
@@ -145,15 +210,15 @@ export class HeldAkumaLeash {
145
210
  }
146
211
  }
147
212
  }
148
- export function probeLeash(paths) {
149
- const claim = HeldAkumaLeash.try(paths);
213
+ export async function probeLeash(paths) {
214
+ const claim = await HeldAkumaLeash.try(paths);
150
215
  if (claim === null)
151
216
  return "held";
152
217
  claim.release();
153
218
  return "free";
154
219
  }
155
- export function readSealFromLeash(paths) {
156
- const leash = new DatabaseSync(paths.leash);
220
+ export async function readSealFromLeash(paths) {
221
+ const leash = await openExistingDatabase(paths.leash);
157
222
  try {
158
223
  assertLeashSchemaVersion(leash);
159
224
  return sealFact(leash);
@@ -35,12 +35,12 @@ export declare function akuIdFromDirectoryName(name: string): Readonly<{
35
35
  archetype: string;
36
36
  suffix: string;
37
37
  }>;
38
- export declare function ensureAkumaRunRoot(worldRoot: string): string;
38
+ export declare function ensureAkumaRunRoot(worldRoot: string): Promise<string>;
39
39
  export declare function allocateAkumaDirectory(input: Readonly<{
40
40
  worldRoot: string;
41
41
  archetype: string;
42
42
  draw?: () => string;
43
- }>): AllocatedAkuma;
43
+ }>): Promise<AllocatedAkuma>;
44
44
  export declare function pathsForAkuId(worldRoot: string, id: AkuId): AkumaPaths;
45
45
  export declare function worldRootForAkumaPaths(paths: AkumaPaths): string;
46
46
  export {};
@@ -1,12 +1,12 @@
1
1
  import { randomBytes } from "node:crypto";
2
- import { mkdirSync, writeFileSync } from "node:fs";
2
+ import { mkdir, writeFile } from "node:fs/promises";
3
3
  import { dirname, join } from "node:path";
4
4
  import { identityCoordinate, identitySegments } from "../identity/coordinates.js";
5
5
  import { normalizeIdentityStem } from "../identity/normalize.js";
6
6
  const HEX8 = /^[0-9a-f]{8}$/u;
7
7
  export function archetypeName(value) {
8
8
  if (value.length === 0 || normalizeIdentityStem({ source: value }) !== value) {
9
- throw new TypeError("Akuma archetype must be one normalized human identity segment");
9
+ throw new TypeError("Akuma name must be one normalized human identity segment");
10
10
  }
11
11
  return value;
12
12
  }
@@ -24,7 +24,7 @@ export function akuId(input) {
24
24
  export function parseAkuId(value) {
25
25
  const segments = identitySegments({ family: "aku", value });
26
26
  if (segments.length !== 2)
27
- throw new TypeError("Akuma identity must be aku/<archetype>/<hex8>");
27
+ throw new TypeError("Akuma identity must be aku/<akuma>/<hex8>");
28
28
  const archetype = archetypeName(segments[0]);
29
29
  const suffix = suffixSegment(segments[1]);
30
30
  return { id: akuId({ archetype, suffix }), archetype, suffix };
@@ -48,11 +48,11 @@ export function akuIdFromDirectoryName(name) {
48
48
  const suffix = name.slice(-8);
49
49
  return { id: akuId({ archetype, suffix }), archetype, suffix };
50
50
  }
51
- export function ensureAkumaRunRoot(worldRoot) {
51
+ export async function ensureAkumaRunRoot(worldRoot) {
52
52
  const runRoot = akumaRunRoot(worldRoot);
53
- mkdirSync(runRoot, { recursive: true });
53
+ await mkdir(runRoot, { recursive: true });
54
54
  try {
55
- writeFileSync(join(runRoot, ".gitignore"), "*\n", { flag: "wx" });
55
+ await writeFile(join(runRoot, ".gitignore"), "*\n", { flag: "wx" });
56
56
  }
57
57
  catch (error) {
58
58
  if (error.code !== "EEXIST")
@@ -60,14 +60,14 @@ export function ensureAkumaRunRoot(worldRoot) {
60
60
  }
61
61
  return runRoot;
62
62
  }
63
- export function allocateAkumaDirectory(input) {
63
+ export async function allocateAkumaDirectory(input) {
64
64
  const archetype = archetypeName(input.archetype);
65
- const runRoot = ensureAkumaRunRoot(input.worldRoot);
65
+ const runRoot = await ensureAkumaRunRoot(input.worldRoot);
66
66
  for (;;) {
67
67
  const suffix = suffixSegment(input.draw?.() ?? randomBytes(4).toString("hex"));
68
68
  const paths = akumaPaths({ runRoot, archetype, suffix });
69
69
  try {
70
- mkdirSync(paths.directory);
70
+ await mkdir(paths.directory);
71
71
  return { id: akuId({ archetype, suffix }), archetype, suffix, paths };
72
72
  }
73
73
  catch (error) {
@@ -1,9 +1,14 @@
1
+ import { type AkuId } from "./identity.js";
2
+ import type { WorldRoot } from "../world.js";
1
3
  export { Akuma, AkumaHandle, AkumaNotBornError } from "./akuma.js";
2
4
  export type { WorldRoot } from "../world.js";
5
+ export declare function probeBornAkuma(worldPath: WorldRoot, id: AkuId): Promise<boolean>;
3
6
  export { AkumaArchetypeError, listArchetypeDefinitions, listArchetypes } from "./archetype.js";
4
7
  export type { ArchetypeCatalogRow } from "./archetype.js";
5
8
  export { AkumaBodyRequestError } from "./requests.js";
6
9
  export type { AkumaList, AkumaListInput, AkumaListRow, AkumaStatus, ActivityHistory, ActivityRow, ActivitySnapshot, ActivitySnapshotEntry, ForkReceipt, InterruptReceipt, TellResult, UnbornAkumaListRow, } from "./akuma.js";
10
+ export type { ActiveToolRow, ClosedTurn, ClosedTurnRow, CompletedToolRow, HistoryCursor, HistoryPage, IdleSnapshotRow, OpenSnapshotRow, OpenTurn, OpenTurnRow, OutcomeRow, RetainedWindow, Snapshot, SnapshotRow, TellRow, TurnLedger, TurnOutcome, TurnStartRow, UnsettledToolRow, } from "./akuma.js";
7
11
  export type { AgentEvent, ToolCall, ToolEvent, ToolResult } from "./provider.js";
8
12
  export type { AkuId } from "./identity.js";
9
- export type { Confinement, KillEvidence, ProviderOptions, ResumeCoordinate, TurnFact, } from "./heart/index.js";
13
+ export type { Confinement, KillEvidence, ResumeCoordinate, TurnFact, } from "./heart/index.js";
14
+ export type { ProviderOptions, ReadonlyRestraint } from "./provider-recipe.js";
@@ -1,3 +1,9 @@
1
+ import { readSoul } from "./heart/index.js";
2
+ import { pathsForAkuId } from "./identity.js";
1
3
  export { Akuma, AkumaHandle, AkumaNotBornError } from "./akuma.js";
4
+ export async function probeBornAkuma(worldPath, id) {
5
+ const soul = await readSoul(pathsForAkuId(worldPath, id));
6
+ return soul !== null;
7
+ }
2
8
  export { AkumaArchetypeError, listArchetypeDefinitions, listArchetypes } from "./archetype.js";
3
9
  export { AkumaBodyRequestError } from "./requests.js";
@@ -1,50 +1,46 @@
1
1
  import { type ToolCall, type ToolResult } from "./provider.js";
2
- import type { ActivitySlice, TellDelivery, TellFact, TimelineFact, TurnEndFact } from "./heart/index.js";
3
- export type ActivityRow = Readonly<{
2
+ import type { TellDelivery, TellFact, TimelineFact, TurnEndFact } from "./heart/index.js";
3
+ export type TurnOutcome = TurnEndFact["outcome"];
4
+ export type TurnStartRow = Readonly<{
4
5
  kind: "turn";
5
6
  sequence: number;
6
7
  turnSequence: number;
7
8
  bodySequence: number;
8
9
  at: string;
9
- }> | Readonly<{
10
+ }>;
11
+ type CallRow = Readonly<{
10
12
  kind: "call";
11
13
  sequence: number;
12
14
  turnSequence: number;
13
15
  at: string;
14
16
  text: string;
15
- }> | Readonly<{
17
+ }>;
18
+ type SaidRow = Readonly<{
16
19
  kind: "said";
17
20
  sequence: number;
18
21
  turnSequence: number;
19
22
  at: string;
20
23
  text: string;
21
24
  truncated?: true;
22
- }> | Readonly<{
25
+ }>;
26
+ type ThoughtRow = Readonly<{
23
27
  kind: "thought";
24
28
  sequence: number;
25
29
  turnSequence: number;
26
30
  at: string;
27
31
  text: string;
28
32
  truncated?: true;
29
- }> | Readonly<{
30
- kind: "tool";
31
- sequence: number;
32
- turnSequence: number;
33
- at: string;
34
- completedAt?: string;
35
- durationMs?: number;
36
- name: string;
37
- call: ToolCall;
38
- state: "running" | ToolResult;
39
- truncated?: true;
40
- }> | Readonly<{
33
+ }>;
34
+ type NoteRow = Readonly<{
41
35
  kind: "note";
42
36
  sequence: number;
43
37
  turnSequence: number;
44
38
  at: string;
45
39
  text: string;
46
40
  truncated?: true;
47
- }> | Readonly<{
41
+ }>;
42
+ type TurnNarrationRow = CallRow | SaidRow | ThoughtRow | NoteRow;
43
+ export type TellRow = Readonly<{
48
44
  kind: "tell";
49
45
  sequence: number;
50
46
  at: string;
@@ -52,26 +48,88 @@ export type ActivityRow = Readonly<{
52
48
  text: string;
53
49
  state: TellFact["state"];
54
50
  deliveries: readonly TellDelivery[];
55
- }> | Readonly<{
51
+ }>;
52
+ export type OutcomeRow = Readonly<{
56
53
  kind: "outcome";
57
54
  sequence: number;
58
55
  turnSequence: number;
59
56
  at: string;
60
- outcome: TurnEndFact["outcome"];
57
+ outcome: TurnOutcome;
61
58
  }>;
62
- export type ActivitySnapshot = Readonly<{
63
- entries: readonly ActivitySnapshotEntry[];
64
- lowestRetained: number | null;
65
- highest: number | null;
59
+ export type ActiveToolRow = Readonly<{
60
+ kind: "tool";
61
+ sequence: number;
62
+ turnSequence: number;
63
+ at: string;
64
+ name: string;
65
+ call: ToolCall;
66
+ state: "active";
67
+ truncated?: true;
66
68
  }>;
67
- export type ActivitySnapshotEntry = Readonly<{
69
+ export type CompletedToolRow = Readonly<{
70
+ kind: "tool";
71
+ sequence: number;
72
+ turnSequence: number;
73
+ at: string;
74
+ completedAt?: string;
75
+ durationMs?: number;
76
+ name: string;
77
+ call: ToolCall;
78
+ state: ToolResult;
79
+ truncated?: true;
80
+ }>;
81
+ export type UnsettledToolRow = Readonly<{
82
+ kind: "tool";
83
+ sequence: number;
84
+ turnSequence: number;
85
+ at: string;
86
+ name: string;
87
+ call: ToolCall;
88
+ state: "unsettled";
89
+ truncated?: true;
90
+ }>;
91
+ export type OpenTurnRow = TurnNarrationRow | ActiveToolRow | CompletedToolRow;
92
+ export type ClosedTurnRow = TurnNarrationRow | UnsettledToolRow | CompletedToolRow;
93
+ export type OpenTurn = Readonly<{
94
+ kind: "open";
95
+ turn: TurnStartRow;
96
+ rows: readonly OpenTurnRow[];
97
+ }>;
98
+ export type ClosedTurn = Readonly<{
99
+ kind: "closed";
100
+ turn: TurnStartRow;
101
+ rows: readonly ClosedTurnRow[];
102
+ outcome: OutcomeRow;
103
+ }>;
104
+ export type ProjectedTurn = OpenTurn | ClosedTurn;
105
+ export type ActivityRow = TurnStartRow | OpenTurnRow | ClosedTurnRow | TellRow | OutcomeRow;
106
+ type SnapshotFactRow = TurnNarrationRow | TellRow;
107
+ export type OpenSnapshotRow = SnapshotFactRow | ActiveToolRow | CompletedToolRow;
108
+ export type IdleSnapshotRow = SnapshotFactRow | CompletedToolRow;
109
+ export type SnapshotRow = OpenSnapshotRow | IdleSnapshotRow;
110
+ export type ActivitySnapshotEntry<Row extends SnapshotRow = SnapshotRow> = Readonly<{
68
111
  kind: "row";
69
- row: ActivityRow;
112
+ row: Row;
70
113
  }> | Readonly<{
71
114
  kind: "gap";
72
115
  count: number;
73
116
  }>;
74
- export type ActivitySnapshotProfile = "status" | "feedback";
117
+ export type Snapshot = Readonly<{
118
+ kind: "unborn";
119
+ entries: readonly [];
120
+ omitted: 0;
121
+ }> | Readonly<{
122
+ kind: "open";
123
+ turn: TurnStartRow;
124
+ entries: readonly ActivitySnapshotEntry<OpenSnapshotRow>[];
125
+ omitted: number;
126
+ }> | Readonly<{
127
+ kind: "idle";
128
+ outcome?: OutcomeRow;
129
+ entries: readonly ActivitySnapshotEntry<IdleSnapshotRow>[];
130
+ omitted: number;
131
+ }>;
132
+ export type ActivitySnapshot = Snapshot;
75
133
  export type ActivityHistory = Readonly<{
76
134
  rows: readonly ActivityRow[];
77
135
  omitted: number;
@@ -81,17 +139,38 @@ export type ActivityHistory = Readonly<{
81
139
  lowestRetained: number | null;
82
140
  highest: number | null;
83
141
  }>;
84
- /** Project the complete retained fact window in persisted timeline order. */
85
- export declare function projectTimeline(facts: readonly TimelineFact[]): readonly ActivityRow[];
86
- /** Apply the bounded snapshot policy after semantic projection. */
87
- export declare function selectActivitySnapshot(facts: readonly TimelineFact[], input?: Readonly<{
88
- lowestRetained?: number | null;
89
- highest?: number | null;
90
- profile?: ActivitySnapshotProfile;
91
- }>): ActivitySnapshot;
92
- /** Apply cursor and limit to the one semantic timeline projection. */
93
- export declare function projectActivityHistory(slice: ActivitySlice, input: Readonly<{
142
+ export type HistoryPage = ActivityHistory;
143
+ export type HistoryCursor = Readonly<{
94
144
  before?: number;
95
145
  since?: number;
96
146
  limit: number;
97
- }>): ActivityHistory;
147
+ }>;
148
+ export type RetainedWindow = Readonly<{
149
+ lowestRetained: number | null;
150
+ highest: number | null;
151
+ }>;
152
+ export type TurnLedger = Readonly<{
153
+ rows: readonly ActivityRow[];
154
+ turns: readonly ProjectedTurn[];
155
+ retained: RetainedWindow;
156
+ openTurn?: OpenTurn;
157
+ latestOutcome?: OutcomeRow;
158
+ }>;
159
+ /** Fold the retained fact timeline into Turn-owned rows without inventing provider facts. */
160
+ export declare function projectTurns(facts: readonly TimelineFact[], retained?: RetainedWindow): TurnLedger;
161
+ /** Split one nonnegative ordinary allowance into newest tail first, then pre-tail voice. */
162
+ export declare function ordinarySnapshotBudget(ordinaryBudget: number): Readonly<{
163
+ tail: number;
164
+ voice: number;
165
+ }>;
166
+ /** Count selected ordinary rows; active tools and pending tells stay outside this total. */
167
+ export declare function ordinarySelectedCount(snapshot: ActivitySnapshot): number;
168
+ /** Select one current Turn, one latest outcome, or no focus; pending tells stay actionable. */
169
+ export declare function selectSnapshot(ledger: TurnLedger, budget?: Readonly<{
170
+ tail: number;
171
+ voice?: number;
172
+ }>): ActivitySnapshot;
173
+ /** Apply the one snapshot policy used by every public observation consumer. */
174
+ export declare function selectActivitySnapshot(facts: readonly TimelineFact[]): ActivitySnapshot;
175
+ export declare function selectHistory(ledger: TurnLedger, cursor: HistoryCursor): HistoryPage;
176
+ export {};