@astrosheep/keiyaku 4.0.1 → 4.0.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.
- package/README.md +137 -5
- package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/package.json +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +3 -3
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +91 -35
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +98 -58
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +152 -53
- package/build/src/akuma/abort.d.ts +2 -0
- package/build/src/akuma/abort.js +50 -0
- package/build/src/akuma/akuma.d.ts +23 -14
- package/build/src/akuma/akuma.js +120 -104
- package/build/src/akuma/archetype.d.ts +7 -6
- package/build/src/akuma/archetype.js +68 -41
- package/build/src/akuma/body.d.ts +3 -5
- package/build/src/akuma/body.js +408 -213
- package/build/src/akuma/heart/facts.d.ts +25 -34
- package/build/src/akuma/heart/facts.js +18 -7
- package/build/src/akuma/heart/index.d.ts +39 -42
- package/build/src/akuma/heart/index.js +134 -93
- package/build/src/akuma/heart/rows.d.ts +9 -31
- package/build/src/akuma/heart/rows.js +26 -44
- package/build/src/akuma/heart/schema.d.ts +1 -1
- package/build/src/akuma/heart/schema.js +7 -15
- package/build/src/akuma/heart/soul.d.ts +8 -0
- package/build/src/akuma/heart/soul.js +136 -0
- package/build/src/akuma/heart/storage.d.ts +28 -14
- package/build/src/akuma/heart/storage.js +86 -26
- package/build/src/akuma/identity.d.ts +2 -2
- package/build/src/akuma/identity.js +9 -9
- package/build/src/akuma/index.d.ts +6 -1
- package/build/src/akuma/index.js +6 -0
- package/build/src/akuma/projection.d.ts +117 -38
- package/build/src/akuma/projection.js +208 -97
- package/build/src/akuma/provider-recipe.d.ts +24 -0
- package/build/src/akuma/provider-recipe.js +100 -0
- package/build/src/akuma/provider.d.ts +12 -4
- package/build/src/akuma/provider.js +117 -70
- package/build/src/akuma/providers/acp/core.d.ts +19 -0
- package/build/src/akuma/providers/acp/core.js +159 -0
- package/build/src/akuma/providers/acp/events.d.ts +20 -0
- package/build/src/akuma/providers/acp/events.js +73 -0
- package/build/src/akuma/providers/acp/index.d.ts +12 -0
- package/build/src/akuma/providers/acp/index.js +94 -0
- package/build/src/akuma/providers/claude/events.js +66 -13
- package/build/src/akuma/providers/claude/index.d.ts +2 -1
- package/build/src/akuma/providers/claude/index.js +35 -21
- package/build/src/akuma/providers/codex-app-server/events.js +4 -1
- package/build/src/akuma/providers/codex-app-server/index.d.ts +3 -3
- package/build/src/akuma/providers/codex-app-server/index.js +24 -31
- package/build/src/akuma/providers/grok-build/index.d.ts +4 -0
- package/build/src/akuma/providers/grok-build/index.js +70 -0
- package/build/src/akuma/providers/index.d.ts +5 -3
- package/build/src/akuma/providers/index.js +24 -59
- package/build/src/akuma/providers/opencode-sdk/events.d.ts +40 -34
- package/build/src/akuma/providers/opencode-sdk/events.js +220 -101
- package/build/src/akuma/providers/opencode-sdk/index.d.ts +3 -2
- package/build/src/akuma/providers/opencode-sdk/index.js +233 -128
- package/build/src/akuma/providers/opencode-sdk/session.d.ts +11 -26
- package/build/src/akuma/providers/opencode-sdk/session.js +10 -9
- package/build/src/akuma/providers/pi/events.js +49 -11
- package/build/src/akuma/providers/pi/index.d.ts +1 -1
- package/build/src/akuma/providers/pi/index.js +50 -21
- package/build/src/akuma/publication.d.ts +3 -3
- package/build/src/akuma/publication.js +28 -40
- package/build/src/akuma/requests.d.ts +9 -7
- package/build/src/akuma/requests.js +92 -65
- package/build/src/alias/index.d.ts +2 -2
- package/build/src/alias/index.js +10 -10
- package/build/src/body/decode.js +7 -1
- package/build/src/body/region.d.ts +2 -0
- package/build/src/body/region.js +77 -7
- package/build/src/cli/accepted.d.ts +17 -13
- package/build/src/cli/accepted.js +72 -34
- package/build/src/cli/actor.js +3 -3
- package/build/src/cli/commands/akuma-invoke.d.ts +4 -3
- package/build/src/cli/commands/akuma-invoke.js +14 -9
- package/build/src/cli/commands/akuma.d.ts +13 -3
- package/build/src/cli/commands/akuma.js +67 -34
- package/build/src/cli/commands/contract.d.ts +18 -5
- package/build/src/cli/commands/contract.js +9 -3
- package/build/src/cli/commands/task-invoke.d.ts +17 -4
- package/build/src/cli/commands/task-invoke.js +43 -20
- package/build/src/cli/commands/task-query.d.ts +5 -0
- package/build/src/cli/commands/task-query.js +247 -0
- package/build/src/cli/commands/task.d.ts +3 -1
- package/build/src/cli/commands/task.js +51 -13
- package/build/src/cli/coordinates.d.ts +18 -0
- package/build/src/cli/coordinates.js +120 -0
- package/build/src/cli/draft.d.ts +8 -0
- package/build/src/cli/draft.js +96 -0
- package/build/src/cli/invoke.d.ts +4 -3
- package/build/src/cli/invoke.js +160 -179
- package/build/src/cli/main.js +34 -6
- package/build/src/cli/parse.d.ts +9 -2
- package/build/src/cli/parse.js +29 -7
- package/build/src/cli/render/akuma-tool-command.d.ts +6 -0
- package/build/src/cli/render/akuma-tool-command.js +144 -0
- package/build/src/cli/render/akuma-tool.d.ts +2 -2
- package/build/src/cli/render/akuma-tool.js +30 -4
- package/build/src/cli/render/akuma.d.ts +1 -0
- package/build/src/cli/render/akuma.js +211 -116
- package/build/src/cli/render/audit.d.ts +3 -0
- package/build/src/cli/render/audit.js +104 -0
- package/build/src/cli/render/contract.d.ts +3 -3
- package/build/src/cli/render/contract.js +192 -79
- package/build/src/cli/render/kanshi.js +263 -168
- package/build/src/cli/render/receipt.d.ts +19 -0
- package/build/src/cli/render/receipt.js +106 -0
- package/build/src/cli/render/refusal.d.ts +16 -2
- package/build/src/cli/render/refusal.js +88 -20
- package/build/src/cli/render/region.d.ts +2 -0
- package/build/src/cli/render/region.js +17 -0
- package/build/src/cli/render/task.d.ts +2 -1
- package/build/src/cli/render/task.js +223 -60
- package/build/src/cli/render/terminal.d.ts +7 -0
- package/build/src/cli/render/terminal.js +46 -0
- package/build/src/cli/render/text.js +6 -3
- package/build/src/cli/result.d.ts +115 -20
- package/build/src/cli/usage.d.ts +1 -0
- package/build/src/cli/usage.js +3 -0
- package/build/src/contract-worktree.d.ts +6 -5
- package/build/src/contract-worktree.js +95 -57
- package/build/src/coordination/durable-file.d.ts +4 -3
- package/build/src/coordination/durable-file.js +29 -25
- package/build/src/coordination/sqlite-transaction-lock.d.ts +4 -0
- package/build/src/coordination/sqlite-transaction-lock.js +22 -5
- package/build/src/core/facts/fold.js +1 -6
- package/build/src/core/facts/gate.d.ts +1 -0
- package/build/src/core/facts/gate.js +1 -0
- package/build/src/core/verbs/amend.d.ts +1 -1
- package/build/src/core/verbs/amend.js +0 -11
- package/build/src/core/verbs/deliver.d.ts +1 -1
- package/build/src/core/verbs/deliver.js +1 -7
- package/build/src/core/verbs/placement.d.ts +1 -1
- package/build/src/core/verbs/placement.js +4 -1
- package/build/src/dispatch/index.d.ts +2 -2
- package/build/src/dispatch/index.js +17 -17
- package/build/src/git/admission.d.ts +1 -1
- package/build/src/git/admission.js +11 -11
- package/build/src/git/hooks.js +13 -13
- package/build/src/git/integration.d.ts +14 -15
- package/build/src/git/integration.js +80 -44
- package/build/src/git/observe.d.ts +5 -3
- package/build/src/git/observe.js +18 -12
- package/build/src/git/read-observation.js +9 -9
- package/build/src/git/reconcile.d.ts +2 -0
- package/build/src/git/reconcile.js +138 -95
- package/build/src/git/repository.d.ts +27 -19
- package/build/src/git/repository.js +155 -83
- package/build/src/git/scratch.d.ts +7 -3
- package/build/src/git/scratch.js +44 -37
- package/build/src/git/target-placement.d.ts +40 -4
- package/build/src/git/target-placement.js +221 -101
- package/build/src/git/tender.d.ts +6 -5
- package/build/src/git/tender.js +24 -43
- package/build/src/git/terminal-seal.d.ts +1 -1
- package/build/src/git/terminal-seal.js +7 -5
- package/build/src/git/workspace.d.ts +36 -4
- package/build/src/git/workspace.js +53 -18
- package/build/src/identity/selector.js +1 -1
- package/build/src/index.d.ts +3 -3
- package/build/src/index.js +1 -1
- package/build/src/kanshi/index.d.ts +2 -2
- package/build/src/kanshi/index.js +1 -1
- package/build/src/kanshi/read.d.ts +2 -1
- package/build/src/kanshi/read.js +118 -27
- package/build/src/kanshi/report.d.ts +50 -0
- package/build/src/kanshi/select.d.ts +5 -0
- package/build/src/kanshi/select.js +32 -0
- package/build/src/library/address.d.ts +12 -3
- package/build/src/library/address.js +77 -46
- package/build/src/library/akuma-creation.d.ts +6 -1
- package/build/src/library/akuma-creation.js +86 -13
- package/build/src/library/audit.d.ts +18 -0
- package/build/src/library/audit.js +44 -0
- package/build/src/library/bind.js +4 -4
- package/build/src/library/catalog.d.ts +1 -1
- package/build/src/library/catalog.js +5 -8
- package/build/src/library/contract.d.ts +5 -6
- package/build/src/library/contract.js +11 -35
- package/build/src/library/delivery.d.ts +2 -1
- package/build/src/library/fleet.d.ts +2 -2
- package/build/src/library/fleet.js +35 -71
- package/build/src/library/keiyaku.d.ts +3 -2
- package/build/src/library/keiyaku.js +1 -0
- package/build/src/library/mutation.d.ts +7 -6
- package/build/src/library/mutation.js +23 -25
- package/build/src/library/reconcile.d.ts +29 -0
- package/build/src/library/reconcile.js +179 -0
- package/build/src/library/region.d.ts +12 -0
- package/build/src/library/region.js +15 -1
- package/build/src/library/repo.d.ts +4 -16
- package/build/src/library/repo.js +13 -38
- package/build/src/protocol/attempt.js +6 -6
- package/build/src/protocol/bind.js +4 -4
- package/build/src/protocol/intent.d.ts +15 -2
- package/build/src/protocol/intent.js +21 -6
- package/build/src/protocol/operations.d.ts +73 -22
- package/build/src/protocol/operations.js +292 -88
- package/build/src/protocol/outcome.d.ts +9 -3
- package/build/src/protocol/outcome.js +3 -1
- package/build/src/protocol/placement.d.ts +15 -4
- package/build/src/protocol/placement.js +58 -25
- package/build/src/protocol/read/status.d.ts +8 -1
- package/build/src/protocol/read/status.js +61 -14
- package/build/src/runtime/proc/line-rpc.d.ts +3 -8
- package/build/src/runtime/proc/line-rpc.js +16 -43
- package/build/src/runtime/proc/run.d.ts +15 -29
- package/build/src/runtime/proc/run.js +113 -105
- package/build/src/runtime/proc/stdio.d.ts +18 -0
- package/build/src/runtime/proc/stdio.js +58 -0
- package/build/src/settings.d.ts +2 -2
- package/build/src/settings.js +8 -8
- package/build/src/settlement/fence.d.ts +0 -4
- package/build/src/settlement/fence.js +0 -9
- package/build/src/settlement/holder.d.ts +11 -1
- package/build/src/settlement/holder.js +25 -0
- package/build/src/settlement/settle.d.ts +1 -1
- package/build/src/settlement/settle.js +52 -89
- package/build/src/task/board.d.ts +3 -3
- package/build/src/task/board.js +6 -9
- package/build/src/task/compose.d.ts +1 -1
- package/build/src/task/compose.js +18 -10
- package/build/src/task/context.d.ts +3 -3
- package/build/src/task/context.js +14 -14
- package/build/src/task/document.d.ts +2 -1
- package/build/src/task/document.js +15 -5
- package/build/src/task/index.d.ts +19 -7
- package/build/src/task/index.js +42 -23
- package/build/src/task/operations.d.ts +15 -9
- package/build/src/task/operations.js +78 -48
- package/build/src/task/query.d.ts +67 -0
- package/build/src/task/query.js +279 -0
- package/build/src/task/store.d.ts +2 -2
- package/build/src/task/store.js +40 -25
- package/build/src/verification/execution.d.ts +4 -2
- package/build/src/verification/execution.js +9 -5
- package/build/src/workspace-place.d.ts +41 -0
- package/build/src/workspace-place.js +386 -0
- package/build/src/world.d.ts +13 -2
- package/build/src/world.js +81 -48
- package/package.json +3 -2
- package/build/src/protocol/read/audit.d.ts +0 -31
- 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,
|
|
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
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 =
|
|
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 =
|
|
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,8 @@ 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 (await withHeart(paths, (heart) => soulFact(heart)) !== null)
|
|
96
140
|
return "born";
|
|
97
141
|
insertSealFact(this.database, input);
|
|
98
142
|
this.database.exec("COMMIT");
|
|
@@ -100,9 +144,23 @@ export class HeldAkumaLeash {
|
|
|
100
144
|
this.database.close();
|
|
101
145
|
return "sealed";
|
|
102
146
|
}
|
|
103
|
-
clearPause(paths) { withHeart(paths, deletePauseControl); }
|
|
104
|
-
|
|
105
|
-
|
|
147
|
+
async clearPause(paths) { await withHeart(paths, deletePauseControl); }
|
|
148
|
+
async clearStop(paths) { await withHeart(paths, deleteStopControl); }
|
|
149
|
+
async recordBody(paths, input) {
|
|
150
|
+
if (this.closed || this.bodySequence !== undefined)
|
|
151
|
+
throw new Error("Akuma leash cannot start another Body");
|
|
152
|
+
const sequence = await withHeart(paths, (heart) => insertBodyFact(heart, input));
|
|
153
|
+
this.bodySequence = sequence;
|
|
154
|
+
return { sequence, leashTakenAt: input.leashTakenAt };
|
|
155
|
+
}
|
|
156
|
+
async recordBodyHung(paths, input) {
|
|
157
|
+
if (this.closed || this.bodySequence !== input.sequence) {
|
|
158
|
+
throw new Error(`Akuma Body ${input.sequence} is not owned by this leash`);
|
|
159
|
+
}
|
|
160
|
+
await withHeart(paths, (heart) => markBodyHung(heart, input));
|
|
161
|
+
}
|
|
162
|
+
async settleStop(paths, expectedBodySequence) {
|
|
163
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
106
164
|
const target = stopFact(heart);
|
|
107
165
|
if (target === null) {
|
|
108
166
|
if (expectedBodySequence === undefined)
|
|
@@ -116,6 +174,8 @@ export class HeldAkumaLeash {
|
|
|
116
174
|
const latest = latestBodyFact(heart);
|
|
117
175
|
if (latest?.sequence !== target.bodySequence)
|
|
118
176
|
throw new Error("Akuma stop target is not the latest Body");
|
|
177
|
+
if (latest.end !== "put-down")
|
|
178
|
+
return null;
|
|
119
179
|
const result = latestKillFact(heart)?.bodySequence === target.bodySequence
|
|
120
180
|
? "already-killed"
|
|
121
181
|
: (insertKillFact(heart, target.bodySequence, target.requestedAt), "recorded");
|
|
@@ -123,8 +183,8 @@ export class HeldAkumaLeash {
|
|
|
123
183
|
return { target, result };
|
|
124
184
|
}));
|
|
125
185
|
}
|
|
126
|
-
recordInterruptTell(paths, tell) {
|
|
127
|
-
return withHeart(paths, (heart) => transaction(heart, () => {
|
|
186
|
+
async recordInterruptTell(paths, tell) {
|
|
187
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
128
188
|
deletePauseControl(heart);
|
|
129
189
|
if (soulFact(heart) === null)
|
|
130
190
|
return { kind: "not-born" };
|
|
@@ -145,15 +205,15 @@ export class HeldAkumaLeash {
|
|
|
145
205
|
}
|
|
146
206
|
}
|
|
147
207
|
}
|
|
148
|
-
export function probeLeash(paths) {
|
|
149
|
-
const claim = HeldAkumaLeash.try(paths);
|
|
208
|
+
export async function probeLeash(paths) {
|
|
209
|
+
const claim = await HeldAkumaLeash.try(paths);
|
|
150
210
|
if (claim === null)
|
|
151
211
|
return "held";
|
|
152
212
|
claim.release();
|
|
153
213
|
return "free";
|
|
154
214
|
}
|
|
155
|
-
export function readSealFromLeash(paths) {
|
|
156
|
-
const leash =
|
|
215
|
+
export async function readSealFromLeash(paths) {
|
|
216
|
+
const leash = await openExistingDatabase(paths.leash);
|
|
157
217
|
try {
|
|
158
218
|
assertLeashSchemaVersion(leash);
|
|
159
219
|
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 {
|
|
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
|
|
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/<
|
|
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
|
-
|
|
53
|
+
await mkdir(runRoot, { recursive: true });
|
|
54
54
|
try {
|
|
55
|
-
|
|
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
|
-
|
|
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,
|
|
13
|
+
export type { Confinement, KillEvidence, ResumeCoordinate, TurnFact, } from "./heart/index.js";
|
|
14
|
+
export type { ProviderOptions, ReadonlyRestraint } from "./provider-recipe.js";
|
package/build/src/akuma/index.js
CHANGED
|
@@ -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 {
|
|
3
|
-
export type
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
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
|
-
}
|
|
30
|
-
|
|
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
|
-
}
|
|
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
|
-
}
|
|
51
|
+
}>;
|
|
52
|
+
export type OutcomeRow = Readonly<{
|
|
56
53
|
kind: "outcome";
|
|
57
54
|
sequence: number;
|
|
58
55
|
turnSequence: number;
|
|
59
56
|
at: string;
|
|
60
|
-
outcome:
|
|
57
|
+
outcome: TurnOutcome;
|
|
61
58
|
}>;
|
|
62
|
-
export type
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
|
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:
|
|
112
|
+
row: Row;
|
|
70
113
|
}> | Readonly<{
|
|
71
114
|
kind: "gap";
|
|
72
115
|
count: number;
|
|
73
116
|
}>;
|
|
74
|
-
export type
|
|
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
|
-
|
|
85
|
-
export
|
|
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
|
-
}
|
|
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 {};
|