@astrosheep/keiyaku 4.0.0 → 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 +133 -8
- package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +2 -2
- package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +4 -4
- package/build/integrations/marketplace/plugins/keiyaku/opencode.js +2 -2
- package/build/integrations/marketplace/plugins/keiyaku/package.json +2 -2
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +13 -5
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +91 -32
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +134 -0
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/agents/openai.yaml +4 -0
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +41 -6
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +262 -46
- package/build/src/akuma/abort.d.ts +2 -0
- package/build/src/akuma/abort.js +50 -0
- package/build/src/akuma/akuma.d.ts +50 -33
- package/build/src/akuma/akuma.js +175 -127
- package/build/src/akuma/archetype.d.ts +14 -5
- package/build/src/akuma/archetype.js +85 -39
- package/build/src/akuma/body.d.ts +3 -5
- package/build/src/akuma/body.js +490 -183
- package/build/src/akuma/coordinate.d.ts +9 -0
- package/build/src/akuma/coordinate.js +22 -0
- package/build/src/akuma/heart/facts.d.ts +88 -45
- package/build/src/akuma/heart/facts.js +19 -8
- package/build/src/akuma/heart/index.d.ts +64 -55
- package/build/src/akuma/heart/index.js +172 -252
- package/build/src/akuma/heart/rows.d.ts +38 -83
- package/build/src/akuma/heart/rows.js +117 -155
- package/build/src/akuma/heart/schema.d.ts +1 -1
- package/build/src/akuma/heart/schema.js +61 -22
- 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 +47 -0
- package/build/src/akuma/heart/storage.js +224 -0
- package/build/src/akuma/heart/tells.d.ts +12 -0
- package/build/src/akuma/heart/tells.js +79 -0
- package/build/src/akuma/heart/timeline.d.ts +15 -0
- package/build/src/akuma/heart/timeline.js +86 -0
- package/build/src/akuma/identity.d.ts +2 -2
- package/build/src/akuma/identity.js +9 -9
- package/build/src/akuma/index.d.ts +10 -3
- package/build/src/akuma/index.js +7 -1
- package/build/src/akuma/projection.d.ts +176 -0
- package/build/src/akuma/projection.js +256 -0
- 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 +67 -13
- package/build/src/akuma/provider.js +172 -105
- 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.d.ts → claude/events.d.ts} +9 -41
- package/build/src/akuma/providers/claude/events.js +238 -0
- package/build/src/akuma/providers/claude/index.d.ts +47 -0
- package/build/src/akuma/providers/claude/index.js +279 -0
- package/build/src/akuma/providers/claude/input.d.ts +13 -0
- package/build/src/akuma/providers/claude/input.js +109 -0
- package/build/src/akuma/providers/codex-app-server/events.d.ts +1 -1
- package/build/src/akuma/providers/codex-app-server/events.js +15 -12
- package/build/src/akuma/providers/codex-app-server/index.d.ts +15 -13
- package/build/src/akuma/providers/codex-app-server/index.js +77 -33
- 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 +35 -56
- package/build/src/akuma/providers/opencode-sdk/events.d.ts +54 -0
- package/build/src/akuma/providers/opencode-sdk/events.js +235 -0
- package/build/src/akuma/providers/opencode-sdk/index.d.ts +33 -0
- package/build/src/akuma/providers/opencode-sdk/index.js +308 -0
- package/build/src/akuma/providers/opencode-sdk/session.d.ts +26 -0
- package/build/src/akuma/providers/opencode-sdk/session.js +63 -0
- package/build/src/akuma/providers/pi/events.d.ts +33 -0
- package/build/src/akuma/providers/pi/events.js +166 -0
- package/build/src/akuma/providers/pi/index.d.ts +11 -0
- package/build/src/akuma/providers/pi/index.js +191 -0
- 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 -6
- package/build/src/akuma/requests.js +95 -65
- package/build/src/alias/index.d.ts +4 -3
- package/build/src/alias/index.js +12 -13
- 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/body/render.js +2 -1
- package/build/src/body/shape.js +7 -1
- package/build/src/body/verification.js +19 -4
- package/build/src/cli/accepted.d.ts +18 -12
- package/build/src/cli/accepted.js +73 -34
- package/build/src/cli/actor.js +3 -3
- package/build/src/cli/commands/akuma-invoke.d.ts +44 -19
- package/build/src/cli/commands/akuma-invoke.js +101 -52
- package/build/src/cli/commands/akuma.d.ts +27 -9
- package/build/src/cli/commands/akuma.js +151 -80
- package/build/src/cli/commands/contract.d.ts +155 -0
- package/build/src/cli/commands/contract.js +20 -0
- package/build/src/cli/commands/install.js +2 -0
- package/build/src/cli/commands/task-invoke.d.ts +19 -4
- package/build/src/cli/commands/task-invoke.js +65 -17
- 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 +52 -14
- 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 +9 -3
- package/build/src/cli/invoke.js +287 -108
- package/build/src/cli/main.js +54 -7
- package/build/src/cli/parse.d.ts +21 -117
- package/build/src/cli/parse.js +79 -84
- 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 +4 -2
- package/build/src/cli/render/akuma-tool.js +35 -5
- package/build/src/cli/render/akuma.d.ts +3 -1
- package/build/src/cli/render/akuma.js +247 -212
- package/build/src/cli/render/audit.d.ts +3 -0
- package/build/src/cli/render/audit.js +104 -0
- package/build/src/cli/render/catalog.d.ts +2 -0
- package/build/src/cli/render/catalog.js +16 -0
- package/build/src/cli/render/contract.d.ts +3 -3
- package/build/src/cli/render/contract.js +200 -54
- package/build/src/cli/render/kanshi.js +272 -129
- 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 -3
- 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 +20 -0
- package/build/src/cli/render/terminal.js +121 -0
- package/build/src/cli/render/text.js +11 -3
- package/build/src/cli/result.d.ts +126 -19
- package/build/src/cli/usage.d.ts +1 -0
- package/build/src/cli/usage.js +3 -0
- package/build/src/contract-worktree.d.ts +44 -0
- package/build/src/contract-worktree.js +251 -0
- package/build/src/coordination/durable-file.d.ts +5 -1
- package/build/src/coordination/durable-file.js +57 -10
- 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/codec.js +23 -4
- package/build/src/core/facts/eligibility.d.ts +1 -10
- package/build/src/core/facts/eligibility.js +0 -49
- 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/facts/observation.d.ts +3 -0
- package/build/src/core/facts/observation.js +12 -0
- package/build/src/core/facts/types.d.ts +10 -3
- package/build/src/core/subject.js +2 -2
- package/build/src/core/verbs/amend.d.ts +1 -1
- package/build/src/core/verbs/amend.js +3 -18
- package/build/src/core/verbs/bind.js +2 -16
- package/build/src/core/verbs/deliver.d.ts +1 -1
- package/build/src/core/verbs/deliver.js +14 -4
- package/build/src/core/verbs/placement.d.ts +1 -1
- package/build/src/core/verbs/placement.js +7 -9
- package/build/src/dispatch/index.d.ts +5 -3
- package/build/src/dispatch/index.js +30 -21
- package/build/src/duration.d.ts +10 -0
- package/build/src/duration.js +22 -0
- package/build/src/git/admission.d.ts +2 -2
- package/build/src/git/admission.js +33 -23
- package/build/src/git/hooks.d.ts +15 -0
- package/build/src/git/hooks.js +70 -18
- package/build/src/git/identity.d.ts +5 -1
- package/build/src/git/identity.js +23 -4
- package/build/src/git/integration.d.ts +48 -0
- package/build/src/git/integration.js +250 -0
- package/build/src/git/observe.d.ts +29 -15
- package/build/src/git/observe.js +185 -76
- package/build/src/git/read-observation.d.ts +41 -0
- package/build/src/git/read-observation.js +361 -0
- package/build/src/git/reconcile.d.ts +17 -5
- package/build/src/git/reconcile.js +305 -109
- package/build/src/git/repository.d.ts +41 -18
- package/build/src/git/repository.js +220 -114
- package/build/src/git/scratch.d.ts +17 -0
- package/build/src/git/scratch.js +73 -0
- package/build/src/git/target-placement.d.ts +92 -0
- package/build/src/git/target-placement.js +375 -0
- package/build/src/git/tender.d.ts +49 -0
- package/build/src/git/tender.js +63 -0
- package/build/src/git/terminal-seal.d.ts +24 -0
- package/build/src/git/terminal-seal.js +89 -0
- package/build/src/git/tree.d.ts +2 -2
- package/build/src/git/tree.js +4 -0
- package/build/src/git/workspace.d.ts +53 -0
- package/build/src/git/workspace.js +139 -0
- package/build/src/identity/selector.d.ts +6 -0
- package/build/src/identity/selector.js +19 -0
- package/build/src/index.d.ts +4 -2
- package/build/src/index.js +2 -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 +7 -3
- package/build/src/kanshi/read.js +245 -45
- package/build/src/kanshi/report.d.ts +81 -6
- package/build/src/kanshi/select.d.ts +5 -0
- package/build/src/kanshi/select.js +33 -1
- package/build/src/library/address.d.ts +57 -0
- package/build/src/library/address.js +165 -0
- package/build/src/library/akuma-creation.d.ts +16 -7
- package/build/src/library/akuma-creation.js +96 -22
- package/build/src/library/audit.d.ts +18 -0
- package/build/src/library/audit.js +44 -0
- package/build/src/library/bind.d.ts +21 -0
- package/build/src/library/bind.js +56 -0
- package/build/src/library/catalog.d.ts +58 -0
- package/build/src/library/catalog.js +69 -0
- package/build/src/library/configuration.d.ts +6 -15
- package/build/src/library/configuration.js +14 -17
- package/build/src/library/contract.d.ts +23 -49
- package/build/src/library/contract.js +171 -185
- package/build/src/library/delivery.d.ts +24 -0
- package/build/src/library/delivery.js +21 -0
- package/build/src/library/fleet.d.ts +65 -0
- package/build/src/library/fleet.js +153 -0
- package/build/src/library/input.d.ts +3 -0
- package/build/src/library/input.js +19 -0
- package/build/src/library/keiyaku.d.ts +18 -3
- package/build/src/library/keiyaku.js +12 -1
- package/build/src/library/mutation.d.ts +39 -0
- package/build/src/library/mutation.js +37 -0
- package/build/src/library/reconcile.d.ts +29 -0
- package/build/src/library/reconcile.js +179 -0
- package/build/src/library/refusal.d.ts +21 -0
- package/build/src/library/refusal.js +29 -0
- package/build/src/library/region.d.ts +14 -1
- package/build/src/library/region.js +18 -4
- package/build/src/library/repo.d.ts +4 -13
- package/build/src/library/repo.js +14 -24
- package/build/src/protocol/attempt.d.ts +16 -3
- package/build/src/protocol/attempt.js +41 -10
- package/build/src/protocol/bind.d.ts +9 -2
- package/build/src/protocol/bind.js +48 -40
- package/build/src/protocol/intent.d.ts +57 -20
- package/build/src/protocol/intent.js +55 -79
- package/build/src/protocol/operations.d.ts +152 -43
- package/build/src/protocol/operations.js +482 -166
- package/build/src/protocol/outcome.d.ts +14 -3
- package/build/src/protocol/outcome.js +11 -3
- package/build/src/protocol/placement.d.ts +41 -0
- package/build/src/protocol/placement.js +147 -0
- package/build/src/protocol/read/documents.d.ts +2 -2
- package/build/src/protocol/read/documents.js +4 -4
- package/build/src/protocol/read/status.d.ts +18 -5
- package/build/src/protocol/read/status.js +73 -13
- package/build/src/protocol/run.d.ts +49 -7
- package/build/src/protocol/run.js +53 -25
- package/build/src/runtime/proc/line-rpc.d.ts +4 -8
- package/build/src/runtime/proc/line-rpc.js +22 -28
- package/build/src/runtime/proc/run.d.ts +23 -21
- package/build/src/runtime/proc/run.js +123 -89
- 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 +7 -1
- package/build/src/settings.js +32 -17
- package/build/src/settlement/fence.d.ts +5 -0
- package/build/src/settlement/fence.js +14 -0
- package/build/src/settlement/holder.d.ts +35 -4
- package/build/src/settlement/holder.js +127 -28
- package/build/src/settlement/settle.d.ts +9 -1
- package/build/src/settlement/settle.js +74 -37
- package/build/src/task/board.d.ts +23 -5
- package/build/src/task/board.js +17 -10
- package/build/src/task/compose.d.ts +2 -2
- package/build/src/task/compose.js +18 -10
- package/build/src/task/context.d.ts +3 -3
- package/build/src/task/context.js +15 -20
- package/build/src/task/document.d.ts +2 -1
- package/build/src/task/document.js +15 -5
- package/build/src/task/index.d.ts +27 -15
- package/build/src/task/index.js +57 -35
- package/build/src/task/operations.d.ts +38 -13
- package/build/src/task/operations.js +80 -46
- package/build/src/task/query.d.ts +67 -0
- package/build/src/task/query.js +279 -0
- package/build/src/task/store.d.ts +5 -7
- package/build/src/task/store.js +43 -28
- package/build/src/verification/declaration.d.ts +1 -0
- package/build/src/verification/execution.d.ts +51 -0
- package/build/src/verification/execution.js +108 -0
- package/build/src/workspace-place.d.ts +41 -0
- package/build/src/workspace-place.js +386 -0
- package/build/src/world.d.ts +24 -0
- package/build/src/world.js +136 -0
- package/package.json +8 -4
- package/build/src/akuma/activity.d.ts +0 -66
- package/build/src/akuma/activity.js +0 -139
- package/build/src/akuma/providers/claude.js +0 -305
- package/build/src/context-root.d.ts +0 -4
- package/build/src/context-root.js +0 -15
- package/build/src/git/delivery.d.ts +0 -20
- package/build/src/git/delivery.js +0 -109
- package/build/src/git/verification.d.ts +0 -14
- package/build/src/git/verification.js +0 -56
- package/build/src/protocol/read/audit.d.ts +0 -25
- package/build/src/protocol/read/audit.js +0 -39
- package/build/src/verification/producer.d.ts +0 -23
- package/build/src/verification/producer.js +0 -54
|
@@ -1,185 +1,85 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import { answeredTurnFact, endBodyFact, finishBodyFact, insertActivityFact, insertTurnEndFact, insertTurnStartFact, insertPauseControl, insertRequestFact, insertSessionFact, insertStopControl, killFactForBody, latestBodyFact, latestKillFact, latestSessionFact, lastAnsweredTurnFact, nonterminalRequestFacts, pauseFact, requestFact, sessionFactForCoordinate, stopFact, updateRequestRefused, updateRequestReserved, updateRequestServed, updateRequestVoided, } from "./rows.js";
|
|
2
|
+
import { insertTellDeliveryFact, insertTellFact, insertTellReceiptFact, pendingTellFacts, tellFact, tellIdsForFence, } from "./tells.js";
|
|
3
|
+
import { activityFactSlice, pruneActivityFacts, } from "./timeline.js";
|
|
4
|
+
import { isHeartAbsent, readSealFromLeash, transaction, withHeart } from "./storage.js";
|
|
5
|
+
import { soulFact } from "./soul.js";
|
|
6
|
+
export { HeartAbsentError, HeldAkumaLeash, initializeHeart, isHeartAbsent, probeLeash } from "./storage.js";
|
|
7
|
+
export { life, lifeAt } from "./facts.js";
|
|
6
8
|
const ACTIVITY_LIMIT = 5_000;
|
|
7
|
-
function
|
|
8
|
-
const value = error;
|
|
9
|
-
const message = String(value?.message ?? "").toLowerCase();
|
|
10
|
-
return value?.code === "ERR_SQLITE_BUSY" || value?.code === "ERR_SQLITE_LOCKED"
|
|
11
|
-
|| value?.errcode === 5 || message.includes("database is locked") || message.includes("database is busy");
|
|
12
|
-
}
|
|
13
|
-
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;
|
|
19
|
-
}
|
|
20
|
-
function withHeart(paths, body) {
|
|
21
|
-
const database = openHeart(paths.heart);
|
|
9
|
+
export async function readSoul(paths) {
|
|
22
10
|
try {
|
|
23
|
-
return
|
|
24
|
-
}
|
|
25
|
-
finally {
|
|
26
|
-
database.close();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
function transaction(database, body) {
|
|
30
|
-
database.exec("BEGIN IMMEDIATE");
|
|
31
|
-
try {
|
|
32
|
-
const result = body();
|
|
33
|
-
database.exec("COMMIT");
|
|
34
|
-
return result;
|
|
11
|
+
return await withHeart(paths, soulFact);
|
|
35
12
|
}
|
|
36
13
|
catch (error) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
catch { /* preserve the adjudication failure */ }
|
|
14
|
+
if (isHeartAbsent(error))
|
|
15
|
+
return null;
|
|
41
16
|
throw error;
|
|
42
17
|
}
|
|
43
18
|
}
|
|
44
|
-
export function
|
|
45
|
-
const heart = openHeart(paths.heart, false);
|
|
46
|
-
try {
|
|
47
|
-
heart.exec(HEART_SCHEMA);
|
|
48
|
-
assertHeartSchemaVersion(heart);
|
|
49
|
-
}
|
|
50
|
-
finally {
|
|
51
|
-
heart.close();
|
|
52
|
-
}
|
|
53
|
-
const leash = new DatabaseSync(paths.leash);
|
|
19
|
+
export async function heartExists(paths) {
|
|
54
20
|
try {
|
|
55
|
-
|
|
56
|
-
assertLeashSchemaVersion(leash);
|
|
57
|
-
}
|
|
58
|
-
finally {
|
|
59
|
-
leash.close();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
export class HeldAkumaLeash {
|
|
63
|
-
database;
|
|
64
|
-
closed = false;
|
|
65
|
-
constructor(database) {
|
|
66
|
-
this.database = database;
|
|
67
|
-
}
|
|
68
|
-
static try(paths) {
|
|
69
|
-
const database = new DatabaseSync(paths.leash, { timeout: 0 });
|
|
70
|
-
try {
|
|
71
|
-
assertLeashSchemaVersion(database);
|
|
72
|
-
database.exec("PRAGMA busy_timeout=0; BEGIN EXCLUSIVE");
|
|
73
|
-
return new HeldAkumaLeash(database);
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
database.close();
|
|
77
|
-
if (isBusy(error))
|
|
78
|
-
return null;
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
21
|
+
return await withHeart(paths, () => true);
|
|
81
22
|
}
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
if (soulFact(heart) !== null)
|
|
87
|
-
return "already-born";
|
|
88
|
-
insertSoulFact(heart, soul);
|
|
89
|
-
if (session !== undefined)
|
|
90
|
-
insertSessionFact(heart, session);
|
|
91
|
-
return "born";
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
sealIfUnborn(paths, input) {
|
|
95
|
-
if (withHeart(paths, (heart) => soulFact(heart)) !== null)
|
|
96
|
-
return "born";
|
|
97
|
-
insertSealFact(this.database, input);
|
|
98
|
-
this.database.exec("COMMIT");
|
|
99
|
-
this.closed = true;
|
|
100
|
-
this.database.close();
|
|
101
|
-
return "sealed";
|
|
102
|
-
}
|
|
103
|
-
clearPause(paths) { withHeart(paths, deletePauseControl); }
|
|
104
|
-
release() {
|
|
105
|
-
if (this.closed)
|
|
106
|
-
return;
|
|
107
|
-
this.closed = true;
|
|
108
|
-
try {
|
|
109
|
-
this.database.exec("ROLLBACK");
|
|
110
|
-
}
|
|
111
|
-
finally {
|
|
112
|
-
this.database.close();
|
|
113
|
-
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (isHeartAbsent(error))
|
|
25
|
+
return false;
|
|
26
|
+
throw error;
|
|
114
27
|
}
|
|
115
28
|
}
|
|
116
|
-
export function
|
|
117
|
-
const claim = HeldAkumaLeash.try(paths);
|
|
118
|
-
if (claim === null)
|
|
119
|
-
return "held";
|
|
120
|
-
claim.release();
|
|
121
|
-
return "free";
|
|
122
|
-
}
|
|
123
|
-
export function readSoul(paths) {
|
|
124
|
-
if (!existsSync(paths.heart))
|
|
125
|
-
return null;
|
|
126
|
-
return withHeart(paths, soulFact);
|
|
127
|
-
}
|
|
128
|
-
export function heartExists(paths) { return existsSync(paths.heart); }
|
|
129
|
-
export function readSeal(paths) {
|
|
130
|
-
if (!existsSync(paths.leash))
|
|
131
|
-
return null;
|
|
132
|
-
const leash = new DatabaseSync(paths.leash);
|
|
29
|
+
export async function readSeal(paths) {
|
|
133
30
|
try {
|
|
134
|
-
|
|
135
|
-
return sealFact(leash);
|
|
31
|
+
return await readSealFromLeash(paths);
|
|
136
32
|
}
|
|
137
|
-
|
|
138
|
-
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (isHeartAbsent(error))
|
|
35
|
+
return null;
|
|
36
|
+
throw error;
|
|
139
37
|
}
|
|
140
38
|
}
|
|
141
|
-
export function
|
|
142
|
-
return withHeart(paths, (heart) => {
|
|
143
|
-
return { sequence: insertBodyFact(heart, input), collar: input.collar, leashTakenAt: input.leashTakenAt };
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
export function recordSession(paths, input) {
|
|
147
|
-
return withHeart(paths, (heart) => ({ sequence: insertSessionFact(heart, input), ...input }));
|
|
39
|
+
export async function recordSession(paths, input) {
|
|
40
|
+
return await withHeart(paths, (heart) => ({ sequence: insertSessionFact(heart, input), ...input }));
|
|
148
41
|
}
|
|
149
|
-
export function appendActivity(paths, input) {
|
|
150
|
-
return withHeart(paths, (heart) => transaction(heart, () => {
|
|
42
|
+
export async function appendActivity(paths, input) {
|
|
43
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
151
44
|
const sequence = insertActivityFact(heart, input);
|
|
152
45
|
pruneActivityFacts(heart, ACTIVITY_LIMIT);
|
|
153
46
|
return sequence;
|
|
154
47
|
}));
|
|
155
48
|
}
|
|
156
|
-
export function activitySlice(paths, input = {}) {
|
|
49
|
+
export async function activitySlice(paths, input = {}) {
|
|
157
50
|
const limit = input.limit ?? ACTIVITY_LIMIT;
|
|
158
|
-
return withHeart(paths, (heart) => activityFactSlice(heart, { ...input, limit }));
|
|
51
|
+
return await withHeart(paths, (heart) => activityFactSlice(heart, { ...input, limit }));
|
|
159
52
|
}
|
|
160
|
-
export function recordTell(paths, tell) {
|
|
161
|
-
return withHeart(paths, (heart) => transaction(heart, () => {
|
|
162
|
-
if (
|
|
163
|
-
return "
|
|
164
|
-
insertTellFact(heart, tell);
|
|
165
|
-
|
|
53
|
+
export async function recordTell(paths, tell) {
|
|
54
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
55
|
+
if (soulFact(heart) === null)
|
|
56
|
+
return { kind: "not-born" };
|
|
57
|
+
const sequence = insertTellFact(heart, tell);
|
|
58
|
+
pruneActivityFacts(heart, ACTIVITY_LIMIT);
|
|
59
|
+
return { kind: "recorded", tell: { sequence, ...tell, state: "pending", deliveries: [] } };
|
|
166
60
|
}));
|
|
167
61
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
62
|
+
export async function recordTellDeliveries(paths, inputs) {
|
|
63
|
+
await withHeart(paths, (heart) => transaction(heart, () => {
|
|
64
|
+
for (const input of inputs) {
|
|
65
|
+
const current = tellFact(heart, input.tellId);
|
|
66
|
+
if (current === null)
|
|
67
|
+
throw new Error(`unknown tell ${input.tellId}`);
|
|
68
|
+
}
|
|
69
|
+
for (const input of inputs)
|
|
70
|
+
insertTellDeliveryFact(heart, input);
|
|
71
|
+
pruneActivityFacts(heart, ACTIVITY_LIMIT);
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
export async function recordTellReceipt(paths, input) {
|
|
75
|
+
await withHeart(paths, (heart) => transaction(heart, () => {
|
|
76
|
+
const tellIds = input.evidence === "exact"
|
|
77
|
+
? [input.tellId]
|
|
78
|
+
: tellIdsForFence(heart, input.turnSequence, input.fence);
|
|
79
|
+
if (tellIds.length === 0)
|
|
80
|
+
throw new Error("tell receipt has no delivery mapping");
|
|
81
|
+
insertTellReceiptFact(heart, input);
|
|
82
|
+
pruneActivityFacts(heart, ACTIVITY_LIMIT);
|
|
183
83
|
}));
|
|
184
84
|
}
|
|
185
85
|
function sameRequestInput(fact, input) {
|
|
@@ -190,8 +90,8 @@ function sameRequestInput(fact, input) {
|
|
|
190
90
|
&& fact.world === input.world
|
|
191
91
|
&& JSON.stringify(fact.recipe) === JSON.stringify(input.recipe);
|
|
192
92
|
}
|
|
193
|
-
export function admitRequest(paths, input) {
|
|
194
|
-
return withHeart(paths, (heart) => transaction(heart, () => {
|
|
93
|
+
export async function admitRequest(paths, input) {
|
|
94
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
195
95
|
insertRequestFact(heart, input);
|
|
196
96
|
const fact = requestFact(heart, input.id);
|
|
197
97
|
if (fact === null)
|
|
@@ -201,8 +101,8 @@ export function admitRequest(paths, input) {
|
|
|
201
101
|
return fact;
|
|
202
102
|
}));
|
|
203
103
|
}
|
|
204
|
-
export function reserveRequest(paths, id, child) {
|
|
205
|
-
return withHeart(paths, (heart) => transaction(heart, () => {
|
|
104
|
+
export async function reserveRequest(paths, id, child) {
|
|
105
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
206
106
|
const before = requestFact(heart, id);
|
|
207
107
|
if (before === null)
|
|
208
108
|
throw new Error(`unknown Akuma request ${id}`);
|
|
@@ -214,8 +114,8 @@ export function reserveRequest(paths, id, child) {
|
|
|
214
114
|
return requestFact(heart, id);
|
|
215
115
|
}));
|
|
216
116
|
}
|
|
217
|
-
export function serveRequest(paths, id, child) {
|
|
218
|
-
return withHeart(paths, (heart) => transaction(heart, () => {
|
|
117
|
+
export async function serveRequest(paths, id, child) {
|
|
118
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
219
119
|
const before = requestFact(heart, id);
|
|
220
120
|
if (before === null)
|
|
221
121
|
throw new Error(`unknown Akuma request ${id}`);
|
|
@@ -227,8 +127,8 @@ export function serveRequest(paths, id, child) {
|
|
|
227
127
|
return requestFact(heart, id);
|
|
228
128
|
}));
|
|
229
129
|
}
|
|
230
|
-
export function refuseRequest(paths, id, diagnostic) {
|
|
231
|
-
return withHeart(paths, (heart) => transaction(heart, () => {
|
|
130
|
+
export async function refuseRequest(paths, id, diagnostic) {
|
|
131
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
232
132
|
const before = requestFact(heart, id);
|
|
233
133
|
if (before === null)
|
|
234
134
|
throw new Error(`unknown Akuma request ${id}`);
|
|
@@ -240,8 +140,8 @@ export function refuseRequest(paths, id, diagnostic) {
|
|
|
240
140
|
return requestFact(heart, id);
|
|
241
141
|
}));
|
|
242
142
|
}
|
|
243
|
-
export function voidRequest(paths, id, evidence) {
|
|
244
|
-
return withHeart(paths, (heart) => transaction(heart, () => {
|
|
143
|
+
export async function voidRequest(paths, id, evidence) {
|
|
144
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
245
145
|
const before = requestFact(heart, id);
|
|
246
146
|
if (before === null)
|
|
247
147
|
throw new Error(`unknown Akuma request ${id}`);
|
|
@@ -253,65 +153,78 @@ export function voidRequest(paths, id, evidence) {
|
|
|
253
153
|
return requestFact(heart, id);
|
|
254
154
|
}));
|
|
255
155
|
}
|
|
256
|
-
export function readRequest(paths, id) {
|
|
257
|
-
return withHeart(paths, (heart) => requestFact(heart, id));
|
|
258
|
-
}
|
|
259
|
-
export function readNonterminalRequests(paths) {
|
|
260
|
-
return withHeart(paths, nonterminalRequestFacts);
|
|
261
|
-
}
|
|
262
|
-
export function
|
|
263
|
-
return withHeart(paths, (heart) =>
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
156
|
+
export async function readRequest(paths, id) {
|
|
157
|
+
return await withHeart(paths, (heart) => requestFact(heart, id));
|
|
158
|
+
}
|
|
159
|
+
export async function readNonterminalRequests(paths) {
|
|
160
|
+
return await withHeart(paths, nonterminalRequestFacts);
|
|
161
|
+
}
|
|
162
|
+
export async function readKill(paths, bodySequence) {
|
|
163
|
+
return await withHeart(paths, (heart) => killFactForBody(heart, bodySequence));
|
|
164
|
+
}
|
|
165
|
+
export async function requestStop(paths, at) {
|
|
166
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
167
|
+
const body = latestBodyFact(heart);
|
|
168
|
+
if (body === null)
|
|
169
|
+
throw new Error("Akuma has no Body to kill");
|
|
170
|
+
if (latestKillFact(heart)?.bodySequence === body.sequence)
|
|
171
|
+
return { kind: "already-killed", body };
|
|
172
|
+
if (body.end !== undefined)
|
|
173
|
+
return { kind: "already-stopped", body };
|
|
174
|
+
const existing = stopFact(heart);
|
|
175
|
+
if (existing !== null && existing.bodySequence !== body.sequence) {
|
|
176
|
+
throw new Error("Akuma stop target is not the latest Body");
|
|
177
|
+
}
|
|
178
|
+
insertStopControl(heart, body.sequence, at);
|
|
179
|
+
return { kind: "requested", body };
|
|
268
180
|
}));
|
|
269
181
|
}
|
|
270
|
-
export function requestPause(paths, at) {
|
|
271
|
-
return withHeart(paths, (heart) => transaction(heart, () => {
|
|
272
|
-
if (
|
|
273
|
-
return "
|
|
182
|
+
export async function requestPause(paths, at) {
|
|
183
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
184
|
+
if (soulFact(heart) === null)
|
|
185
|
+
return { kind: "not-born" };
|
|
186
|
+
const body = latestBodyFact(heart);
|
|
187
|
+
if (body === null)
|
|
188
|
+
throw new Error("Akuma has no Body to interrupt");
|
|
274
189
|
insertPauseControl(heart, at);
|
|
275
|
-
return "requested";
|
|
190
|
+
return { kind: "requested", body };
|
|
276
191
|
}));
|
|
277
192
|
}
|
|
278
|
-
export function stopRequested(paths
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
193
|
+
export async function stopRequested(paths, bodySequence) {
|
|
194
|
+
return await withHeart(paths, (heart) => {
|
|
195
|
+
const target = stopFact(heart);
|
|
196
|
+
return target !== null && (bodySequence === undefined || target.bodySequence === bodySequence);
|
|
197
|
+
});
|
|
283
198
|
}
|
|
284
|
-
export function
|
|
285
|
-
return withHeart(paths, (heart) =>
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
voidTellsByDeath(heart);
|
|
290
|
-
voidRequestsByDeath(heart, `death:${death.evidence}`);
|
|
291
|
-
return "recorded";
|
|
292
|
-
}));
|
|
199
|
+
export async function pauseRequested(paths, bodySequence) {
|
|
200
|
+
return await withHeart(paths, (heart) => {
|
|
201
|
+
const target = pauseFact(heart);
|
|
202
|
+
return target !== null && (bodySequence === undefined || target.bodySequence === bodySequence);
|
|
203
|
+
});
|
|
293
204
|
}
|
|
294
|
-
export function breakBody(paths, input) {
|
|
295
|
-
withHeart(paths, (heart) => endBodyFact(heart, input));
|
|
205
|
+
export async function breakBody(paths, input) {
|
|
206
|
+
await withHeart(paths, (heart) => endBodyFact(heart, input));
|
|
296
207
|
}
|
|
297
|
-
export function
|
|
298
|
-
return withHeart(paths, (heart) => {
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
return { sequence, ...input };
|
|
311
|
-
});
|
|
208
|
+
export async function beginTurn(paths, input) {
|
|
209
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
210
|
+
const fact = insertTurnStartFact(heart, input);
|
|
211
|
+
pruneActivityFacts(heart, ACTIVITY_LIMIT);
|
|
212
|
+
return fact;
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
export async function endTurn(paths, input) {
|
|
216
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
217
|
+
const fact = insertTurnEndFact(heart, { kind: "turn-end", ...input });
|
|
218
|
+
pruneActivityFacts(heart, ACTIVITY_LIMIT);
|
|
219
|
+
return fact;
|
|
220
|
+
}));
|
|
312
221
|
}
|
|
313
|
-
export function finishBodyIfIdle(paths, input) {
|
|
314
|
-
return withHeart(paths, (heart) => transaction(heart, () => {
|
|
222
|
+
export async function finishBodyIfIdle(paths, input) {
|
|
223
|
+
return await withHeart(paths, (heart) => transaction(heart, () => {
|
|
224
|
+
if (stopFact(heart)?.bodySequence === input.sequence || pauseFact(heart)?.bodySequence === input.sequence) {
|
|
225
|
+
endBodyFact(heart, { ...input, end: "put-down" });
|
|
226
|
+
return { kind: "controlled" };
|
|
227
|
+
}
|
|
315
228
|
const pending = pendingTellFacts(heart);
|
|
316
229
|
if (pending.length > 0)
|
|
317
230
|
return { kind: "pending", tells: pending.map((tell) => tell.id) };
|
|
@@ -319,43 +232,50 @@ export function finishBodyIfIdle(paths, input) {
|
|
|
319
232
|
return { kind: "finished" };
|
|
320
233
|
}));
|
|
321
234
|
}
|
|
322
|
-
export function readHeart(paths) {
|
|
323
|
-
|
|
324
|
-
return
|
|
235
|
+
export async function readHeart(paths) {
|
|
236
|
+
try {
|
|
237
|
+
return await withHeart(paths, (heart) => ({
|
|
238
|
+
soul: soulFact(heart),
|
|
239
|
+
latestBody: latestBodyFact(heart),
|
|
240
|
+
latestSession: latestSessionFact(heart),
|
|
241
|
+
pending: pendingTellFacts(heart),
|
|
242
|
+
latestKill: latestKillFact(heart),
|
|
243
|
+
stop: stopFact(heart),
|
|
244
|
+
pause: pauseFact(heart),
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
if (isHeartAbsent(error)) {
|
|
249
|
+
return { soul: null, latestBody: null, latestSession: null, pending: [], latestKill: null, stop: null, pause: null };
|
|
250
|
+
}
|
|
251
|
+
throw error;
|
|
325
252
|
}
|
|
326
|
-
return withHeart(paths, (heart) => ({
|
|
327
|
-
soul: soulFact(heart),
|
|
328
|
-
latestBody: latestBodyFact(heart),
|
|
329
|
-
latestSession: latestSessionFact(heart),
|
|
330
|
-
pending: pendingTellFacts(heart),
|
|
331
|
-
death: deathFact(heart),
|
|
332
|
-
}));
|
|
333
|
-
}
|
|
334
|
-
export function readTurns(paths) {
|
|
335
|
-
return withHeart(paths, historyFacts);
|
|
336
|
-
}
|
|
337
|
-
export function readLastAnsweredTurn(paths) {
|
|
338
|
-
return withHeart(paths, lastAnsweredTurnFact);
|
|
339
253
|
}
|
|
340
|
-
export function
|
|
341
|
-
return withHeart(paths,
|
|
254
|
+
export async function readLastAnsweredTurn(paths) {
|
|
255
|
+
return await withHeart(paths, lastAnsweredTurnFact);
|
|
342
256
|
}
|
|
343
|
-
export function readForkPoint(paths, historyId) {
|
|
344
|
-
|
|
345
|
-
return
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
257
|
+
export async function readForkPoint(paths, historyId) {
|
|
258
|
+
try {
|
|
259
|
+
return await withHeart(paths, (heart) => {
|
|
260
|
+
const turn = answeredTurnFact(heart, historyId);
|
|
261
|
+
const outcome = turn?.end?.outcome;
|
|
262
|
+
if (outcome?.kind !== "answered" || outcome.historyId === undefined)
|
|
263
|
+
return null;
|
|
264
|
+
const recipe = sessionFactForCoordinate(heart, outcome.session);
|
|
265
|
+
if (recipe === null)
|
|
266
|
+
throw new Error(`Akuma fork point ${historyId} has no session recipe`);
|
|
267
|
+
return {
|
|
268
|
+
historyId: outcome.historyId,
|
|
269
|
+
session: outcome.session,
|
|
270
|
+
provider: recipe.provider,
|
|
271
|
+
cwd: recipe.cwd,
|
|
272
|
+
options: recipe.options,
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
if (isHeartAbsent(error))
|
|
349
278
|
return null;
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
throw new Error(`Akuma fork point ${historyId} has no session recipe`);
|
|
353
|
-
return {
|
|
354
|
-
historyId: turn.outcome.historyId,
|
|
355
|
-
session: turn.outcome.session,
|
|
356
|
-
provider: recipe.provider,
|
|
357
|
-
cwd: recipe.cwd,
|
|
358
|
-
options: recipe.options,
|
|
359
|
-
};
|
|
360
|
-
});
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
361
281
|
}
|