@astrosheep/keiyaku 4.6.4 → 4.6.7
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 +7 -0
- package/build/{integrations/marketplace → plugins}/.agents/plugins/marketplace.json +1 -1
- package/build/plugins/.claude-plugin/marketplace.json +5 -0
- package/build/{integrations/marketplace/plugins/keiyaku → plugins/claude}/.claude-plugin/plugin.json +1 -1
- package/build/{integrations/marketplace/plugins/keiyaku → plugins/claude}/skills/keiyaku-akuma/SKILL.md +43 -8
- package/build/{integrations/marketplace/plugins/keiyaku → plugins/claude}/skills/keiyaku-bind/SKILL.md +7 -8
- package/build/{integrations/marketplace/plugins/keiyaku → plugins/claude}/skills/keiyaku-workflow/SKILL.md +3 -3
- package/build/{integrations/marketplace/plugins/keiyaku → plugins/codex}/.codex-plugin/plugin.json +1 -1
- package/build/plugins/codex/skills/keiyaku/SKILL.md +44 -0
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +130 -0
- package/build/plugins/codex/skills/keiyaku-akuma/references/automation.md +269 -0
- package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +65 -0
- package/build/plugins/codex/skills/keiyaku-bind/SKILL.md +216 -0
- package/build/plugins/codex/skills/keiyaku-bind/agents/openai.yaml +4 -0
- package/build/plugins/codex/skills/keiyaku-task/SKILL.md +104 -0
- package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +129 -0
- package/build/plugins/opencode/package.json +6 -0
- package/build/plugins/opencode/skills/keiyaku/SKILL.md +44 -0
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +130 -0
- package/build/plugins/opencode/skills/keiyaku-akuma/references/automation.md +269 -0
- package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +65 -0
- package/build/plugins/opencode/skills/keiyaku-bind/SKILL.md +216 -0
- package/build/plugins/opencode/skills/keiyaku-bind/agents/openai.yaml +4 -0
- package/build/plugins/opencode/skills/keiyaku-task/SKILL.md +104 -0
- package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +129 -0
- package/build/skills/keiyaku/SKILL.md +44 -0
- package/build/skills/keiyaku-akuma/SKILL.md +130 -0
- package/build/skills/keiyaku-akuma/references/automation.md +269 -0
- package/build/skills/keiyaku-babysit/SKILL.md +65 -0
- package/build/skills/keiyaku-bind/SKILL.md +216 -0
- package/build/skills/keiyaku-bind/agents/openai.yaml +4 -0
- package/build/skills/keiyaku-task/SKILL.md +104 -0
- package/build/skills/keiyaku-workflow/SKILL.md +129 -0
- package/build/src/akuma/akuma-instance.js +7 -5
- package/build/src/akuma/akuma-observe.d.ts +22 -15
- package/build/src/akuma/akuma-observe.js +87 -16
- package/build/src/akuma/akuma-owner.d.ts +3 -2
- package/build/src/akuma/akuma-owner.js +28 -10
- package/build/src/akuma/akuma-selection-execution.d.ts +3 -1
- package/build/src/akuma/akuma-selection-execution.js +2 -1
- package/build/src/akuma/akuma-wait.d.ts +6 -4
- package/build/src/akuma/akuma-wait.js +78 -53
- package/build/src/akuma/akuma.d.ts +6 -4
- package/build/src/akuma/akuma.js +4 -0
- package/build/src/akuma/body.d.ts +1 -0
- package/build/src/akuma/body.js +12 -23
- package/build/src/akuma/call-initial-tell.d.ts +2 -2
- package/build/src/akuma/call-initial-tell.js +1 -1
- package/build/src/akuma/call-request.d.ts +2 -2
- package/build/src/akuma/heart/index.d.ts +7 -2
- package/build/src/akuma/heart/index.js +50 -5
- package/build/src/akuma/heart/tells.d.ts +33 -2
- package/build/src/akuma/heart/tells.js +24 -18
- package/build/src/akuma/heart/timeline.d.ts +23 -1
- package/build/src/akuma/heart/timeline.js +28 -21
- package/build/src/akuma/projection.d.ts +10 -10
- package/build/src/akuma/providers/pi/index.js +72 -39
- package/build/src/akuma/selection-observation.d.ts +20 -20
- package/build/src/akuma/selection-owner-port.d.ts +1 -1
- package/build/src/akuma/selection-owner-port.js +16 -5
- package/build/src/akuma/selection-request.d.ts +2 -0
- package/build/src/akuma/selection-request.js +2 -1
- package/build/src/akuma-body.js +5 -2
- package/build/src/alias/index.d.ts +0 -1
- package/build/src/alias/index.js +0 -4
- package/build/src/body/amend.d.ts +0 -4
- package/build/src/body/amend.js +0 -3
- package/build/src/body/region.d.ts +0 -1
- package/build/src/body/region.js +0 -3
- package/build/src/body/verification.d.ts +0 -1
- package/build/src/cli/commands/akuma-grammar.js +23 -66
- package/build/src/cli/commands/akuma.js +23 -42
- package/build/src/cli/commands/contract-grammar.d.ts +14 -1
- package/build/src/cli/commands/contract-grammar.js +54 -21
- package/build/src/cli/commands/contract-help.d.ts +9 -8
- package/build/src/cli/commands/contract-help.js +14 -7
- package/build/src/cli/commands/contract.js +57 -117
- package/build/src/cli/commands/install.d.ts +5 -5
- package/build/src/cli/commands/install.js +4 -7
- package/build/src/cli/commands/task-grammar.js +10 -66
- package/build/src/cli/commands/task.d.ts +0 -1
- package/build/src/cli/commands/task.js +34 -53
- package/build/src/cli/coordinates.d.ts +1 -2
- package/build/src/cli/coordinates.js +1 -4
- package/build/src/cli/parse.d.ts +2 -3
- package/build/src/cli/parse.js +24 -66
- package/build/src/cli/render/akuma.d.ts +3 -16
- package/build/src/cli/render/akuma.js +1 -13
- package/build/src/cli/render/audit.js +1 -1
- package/build/src/cli/render/contract.js +34 -32
- package/build/src/cli/render/kanshi-akuma.d.ts +8 -2
- package/build/src/cli/render/kanshi-akuma.js +14 -7
- package/build/src/cli/render/kanshi.d.ts +3 -1
- package/build/src/cli/render/kanshi.js +44 -32
- package/build/src/cli/render/receipt.js +6 -1
- package/build/src/cli/render/task.d.ts +1 -1
- package/build/src/cli/render/task.js +3 -27
- package/build/src/cli/render/terminal.d.ts +6 -2
- package/build/src/cli/render/terminal.js +8 -2
- package/build/src/cli/runtime.js +3 -16
- package/build/src/cli/scan.d.ts +26 -0
- package/build/src/cli/scan.js +82 -0
- package/build/src/cli/streams.d.ts +5 -0
- package/build/src/cli/streams.js +11 -0
- package/build/src/contract-worktree.js +38 -21
- package/build/src/core/facts/codec.d.ts +1 -2
- package/build/src/core/facts/codec.js +5 -11
- package/build/src/core/facts/types.d.ts +16 -2
- package/build/src/core/facts/types.js +15 -0
- package/build/src/core/verbs/abandon.js +3 -9
- package/build/src/core/verbs/amend.js +2 -9
- package/build/src/core/verbs/arc.js +6 -13
- package/build/src/core/verbs/attestation.js +2 -9
- package/build/src/core/verbs/bind.js +2 -9
- package/build/src/core/verbs/deliver.js +2 -9
- package/build/src/core/verbs/placement.d.ts +1 -1
- package/build/src/core/verbs/placement.js +2 -9
- package/build/src/core/verbs/reintegrate.d.ts +1 -1
- package/build/src/core/verbs/reintegrate.js +2 -9
- package/build/src/dispatch/index.d.ts +2 -2
- package/build/src/dispatch/index.js +33 -11
- package/build/src/git/hooks.d.ts +2 -4
- package/build/src/git/hooks.js +0 -12
- package/build/src/git/integration.d.ts +5 -3
- package/build/src/git/integration.js +36 -25
- package/build/src/git/nuke.js +4 -4
- package/build/src/git/observe.d.ts +4 -4
- package/build/src/git/observe.js +5 -5
- package/build/src/git/process.d.ts +1 -4
- package/build/src/git/process.js +1 -11
- package/build/src/git/read-observation.js +1 -1
- package/build/src/git/reconcile.d.ts +1 -1
- package/build/src/git/reconcile.js +15 -13
- package/build/src/git/repository.d.ts +2 -6
- package/build/src/git/repository.js +18 -31
- package/build/src/git/scratch.d.ts +6 -6
- package/build/src/git/scratch.js +110 -46
- package/build/src/git/target-placement.d.ts +5 -5
- package/build/src/git/target-placement.js +18 -33
- package/build/src/git/tender.d.ts +6 -2
- package/build/src/git/tender.js +19 -12
- package/build/src/git/terminal-reconcile.js +24 -13
- package/build/src/git/terminal-seal.d.ts +2 -5
- package/build/src/git/terminal-seal.js +5 -3
- package/build/src/git/workspace.d.ts +17 -13
- package/build/src/git/workspace.js +58 -41
- package/build/src/kanshi/index.d.ts +2 -2
- package/build/src/kanshi/index.js +1 -1
- package/build/src/kanshi/read.d.ts +8 -1
- package/build/src/kanshi/read.js +72 -7
- package/build/src/kanshi/report.d.ts +12 -0
- package/build/src/library/akuma-creation.d.ts +4 -4
- package/build/src/library/akuma-creation.js +21 -19
- package/build/src/library/bind.d.ts +1 -63
- package/build/src/library/bind.js +3 -9
- package/build/src/library/contract-creation.js +2 -30
- package/build/src/library/contract-execution.d.ts +0 -1
- package/build/src/library/contract-execution.js +9 -34
- package/build/src/library/contract-operations.d.ts +5 -1
- package/build/src/library/contract-operations.js +7 -3
- package/build/src/library/contract-types.d.ts +1 -1
- package/build/src/library/delivery.d.ts +91 -93
- package/build/src/library/delivery.js +2 -1
- package/build/src/library/input.d.ts +0 -2
- package/build/src/library/input.js +0 -4
- package/build/src/library/invocation.d.ts +0 -1
- package/build/src/library/invocation.js +3 -25
- package/build/src/library/outcome.d.ts +651 -602
- package/build/src/library/outcome.js +4 -4
- package/build/src/library/reconcile.d.ts +6 -0
- package/build/src/library/reconcile.js +31 -1
- package/build/src/library/repo.d.ts +0 -1
- package/build/src/library/selection.d.ts +1 -10
- package/build/src/library/selection.js +19 -17
- package/build/src/plugin/akuma-signals.d.ts +10 -11
- package/build/src/plugin/akuma-signals.js +36 -20
- package/build/src/plugin/public.d.ts +5 -0
- package/build/src/plugin/runtime.d.ts +1 -0
- package/build/src/plugin/runtime.js +34 -23
- package/build/src/protocol/abandon.d.ts +1 -1
- package/build/src/protocol/abandon.js +3 -10
- package/build/src/protocol/amend.js +2 -5
- package/build/src/protocol/arc.d.ts +1 -1
- package/build/src/protocol/arc.js +2 -9
- package/build/src/protocol/attempt.d.ts +3 -20
- package/build/src/protocol/attempt.js +6 -5
- package/build/src/protocol/audit.d.ts +1 -0
- package/build/src/protocol/audit.js +10 -11
- package/build/src/protocol/completion.d.ts +129 -55
- package/build/src/protocol/completion.js +62 -73
- package/build/src/protocol/deliver.d.ts +7 -5
- package/build/src/protocol/deliver.js +74 -44
- package/build/src/protocol/execution-observation.d.ts +2 -4
- package/build/src/protocol/execution-observation.js +3 -7
- package/build/src/protocol/intent.d.ts +1 -1
- package/build/src/protocol/intent.js +1 -0
- package/build/src/protocol/operations.d.ts +24 -12
- package/build/src/protocol/operations.js +36 -15
- package/build/src/protocol/placement.d.ts +2 -1
- package/build/src/protocol/placement.js +21 -5
- package/build/src/protocol/progress.d.ts +1 -1
- package/build/src/protocol/read/status.js +58 -41
- package/build/src/protocol/reintegrate.d.ts +1 -1
- package/build/src/protocol/reintegrate.js +10 -19
- package/build/src/protocol/review.d.ts +3 -28
- package/build/src/protocol/review.js +10 -37
- package/build/src/protocol/run.d.ts +19 -7
- package/build/src/protocol/run.js +19 -9
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/build/src/settlement/holder.d.ts +2 -4
- package/build/src/settlement/holder.js +3 -6
- package/build/src/task/board.d.ts +6 -0
- package/build/src/task/board.js +30 -1
- package/build/src/task/catalog.js +1 -4
- package/build/src/task/compose.d.ts +0 -1
- package/build/src/task/compose.js +0 -1
- package/build/src/task/context.d.ts +0 -1
- package/build/src/task/context.js +0 -3
- package/build/src/task/created-observation.d.ts +5 -1
- package/build/src/task/created-observation.js +12 -5
- package/build/src/task/index.d.ts +1 -1
- package/build/src/task/index.js +7 -6
- package/build/src/task/input.d.ts +0 -6
- package/build/src/task/input.js +2 -14
- package/build/src/task/mutation.d.ts +3 -4
- package/build/src/task/mutation.js +11 -39
- package/build/src/task/operations.d.ts +2 -7
- package/build/src/task/operations.js +37 -49
- package/build/src/task/query.d.ts +0 -1
- package/build/src/task/query.js +1 -4
- package/build/src/task/store.d.ts +0 -2
- package/build/src/task/store.js +27 -11
- package/build/src/verification/declaration.js +3 -2
- package/build/src/verification/execution.d.ts +3 -2
- package/build/src/verification/execution.js +10 -6
- package/build/src/workspace-place.d.ts +0 -1
- package/build/src/workspace-place.js +0 -11
- package/package.json +13 -9
- package/build/integrations/marketplace/.claude-plugin/marketplace.json +0 -5
- package/build/integrations/marketplace/plugins/keiyaku/package.json +0 -17
- /package/build/{integrations/marketplace/plugins/keiyaku → plugins/claude}/skills/keiyaku/SKILL.md +0 -0
- /package/build/{integrations/marketplace/plugins/keiyaku → plugins/claude}/skills/keiyaku-akuma/references/automation.md +0 -0
- /package/build/{integrations/marketplace/plugins/keiyaku → plugins/claude}/skills/keiyaku-babysit/SKILL.md +0 -0
- /package/build/{integrations/marketplace/plugins/keiyaku → plugins/claude}/skills/keiyaku-bind/agents/openai.yaml +0 -0
- /package/build/{integrations/marketplace/plugins/keiyaku → plugins/claude}/skills/keiyaku-task/SKILL.md +0 -0
- /package/build/{integrations/marketplace/plugins/keiyaku/opencode.js → plugins/opencode/index.js} +0 -0
- /package/build/{integrations → plugins}/pi/keiyaku.ts +0 -0
package/build/src/akuma/body.js
CHANGED
|
@@ -10,7 +10,7 @@ import { HeldAkumaLeash, breakBody, decidePendingTellDisposition, drainPendingTe
|
|
|
10
10
|
import { akumaPathsSchema, pathsForAkuId, worldRootForAkumaPaths } from "./identity.js";
|
|
11
11
|
import { admitCallInitialTell, } from "./call-initial-tell.js";
|
|
12
12
|
import { akumaExecutionEnvironment } from "./providers/execution-environment.js";
|
|
13
|
-
import {
|
|
13
|
+
import { emitPluginSignal } from "../plugin/akuma-signals.js";
|
|
14
14
|
import { World } from "../world.js";
|
|
15
15
|
import { resolveProviderExecution } from "./providers/index.js";
|
|
16
16
|
import { clearBodyRequestTransport, settleBodyRequests } from "./request-serve.js";
|
|
@@ -156,7 +156,7 @@ function boundedDiagnostic(error) {
|
|
|
156
156
|
const text = diagnostic(error);
|
|
157
157
|
return text.length <= 500 ? text : `${text.slice(0, 500)}...`;
|
|
158
158
|
}
|
|
159
|
-
async function recordPluginDiagnostic(paths, occurrence, error) {
|
|
159
|
+
export async function recordPluginDiagnostic(paths, occurrence, error) {
|
|
160
160
|
try {
|
|
161
161
|
await appendFile(paths.log, `plugin ${occurrence} failed: ${boundedDiagnostic(error)}\n`);
|
|
162
162
|
}
|
|
@@ -306,8 +306,7 @@ async function recoverBodyRequests(input) {
|
|
|
306
306
|
}
|
|
307
307
|
return false;
|
|
308
308
|
}
|
|
309
|
-
function turnOutcomeEmitter(launch, soul) {
|
|
310
|
-
let plugins;
|
|
309
|
+
function turnOutcomeEmitter(launch, soul, world) {
|
|
311
310
|
const reportDiagnostic = (message) => {
|
|
312
311
|
void recordPluginDiagnostic(launch.paths, "turn outcome", message);
|
|
313
312
|
};
|
|
@@ -318,11 +317,7 @@ function turnOutcomeEmitter(launch, soul) {
|
|
|
318
317
|
if (turn === null)
|
|
319
318
|
throw new Error(`Committed Turn ${turnSequence} is missing from Heart`);
|
|
320
319
|
const participants = await readTurnParticipants(launch.paths, turnSequence);
|
|
321
|
-
|
|
322
|
-
world: await World.at(worldRootForAkumaPaths(launch.paths)),
|
|
323
|
-
reportDiagnostic,
|
|
324
|
-
});
|
|
325
|
-
await (await plugins).emit({
|
|
320
|
+
await emitPluginSignal({ world, reportDiagnostic }, {
|
|
326
321
|
kind: "akuma.turn-outcome",
|
|
327
322
|
akumaId: soul.id,
|
|
328
323
|
bodySequence: turn.bodySequence,
|
|
@@ -333,7 +328,7 @@ function turnOutcomeEmitter(launch, soul) {
|
|
|
333
328
|
? { kind: "answered", text: outcome.answer }
|
|
334
329
|
: { kind: "failed", reason: outcome.diagnostic },
|
|
335
330
|
...(launch.completion?.contractId === undefined ? {} : { contractId: launch.completion.contractId }),
|
|
336
|
-
}
|
|
331
|
+
});
|
|
337
332
|
}
|
|
338
333
|
catch (error) {
|
|
339
334
|
await recordPluginDiagnostic(launch.paths, "turn outcome", error);
|
|
@@ -341,22 +336,16 @@ function turnOutcomeEmitter(launch, soul) {
|
|
|
341
336
|
},
|
|
342
337
|
};
|
|
343
338
|
}
|
|
344
|
-
function bodyEndEmitter(launch, soul) {
|
|
345
|
-
let plugins;
|
|
339
|
+
function bodyEndEmitter(launch, soul, world) {
|
|
346
340
|
const reportDiagnostic = (message) => {
|
|
347
341
|
void recordPluginDiagnostic(launch.paths, "body end", message);
|
|
348
342
|
};
|
|
349
|
-
return (bodySequence, end, diagnostic) =>
|
|
343
|
+
return async (bodySequence, end, diagnostic) => {
|
|
350
344
|
try {
|
|
351
345
|
const latestTurn = await readLatestTurnForBody(launch.paths, bodySequence);
|
|
352
346
|
const initiator = latestTurn?.initiator;
|
|
353
347
|
const participants = latestTurn === null ? [] : await readTurnParticipants(launch.paths, latestTurn.sequence);
|
|
354
|
-
|
|
355
|
-
world: await World.at(worldRootForAkumaPaths(launch.paths)),
|
|
356
|
-
reportDiagnostic,
|
|
357
|
-
});
|
|
358
|
-
const runtime = await plugins;
|
|
359
|
-
await runtime.emit({
|
|
348
|
+
await emitPluginSignal({ world, reportDiagnostic }, {
|
|
360
349
|
kind: "akuma.body-ended",
|
|
361
350
|
akumaId: soul.id,
|
|
362
351
|
bodySequence,
|
|
@@ -365,12 +354,12 @@ function bodyEndEmitter(launch, soul) {
|
|
|
365
354
|
...(participants.length === 0 ? {} : { participants }),
|
|
366
355
|
...(diagnostic === undefined ? {} : { diagnostic }),
|
|
367
356
|
...(launch.completion?.contractId === undefined ? {} : { contractId: launch.completion.contractId }),
|
|
368
|
-
}
|
|
357
|
+
});
|
|
369
358
|
}
|
|
370
359
|
catch (error) {
|
|
371
360
|
await recordPluginDiagnostic(launch.paths, "body end", error);
|
|
372
361
|
}
|
|
373
|
-
}
|
|
362
|
+
};
|
|
374
363
|
}
|
|
375
364
|
async function admitInitialCallTell(runtime, input) {
|
|
376
365
|
const paths = pathsForAkuId(runtime.world, input.id);
|
|
@@ -575,8 +564,8 @@ export async function driveAkumaBody(launch, adapter, runtimeInput = {}) {
|
|
|
575
564
|
const prepared = await prepareBodyExecution(launch, leash, runtime, adapter);
|
|
576
565
|
if (prepared === null)
|
|
577
566
|
return;
|
|
578
|
-
emitBodyEnd = bodyEndEmitter(launch, prepared.soul);
|
|
579
|
-
emitTurnOutcome = turnOutcomeEmitter(launch, prepared.soul);
|
|
567
|
+
emitBodyEnd = bodyEndEmitter(launch, prepared.soul, world);
|
|
568
|
+
emitTurnOutcome = turnOutcomeEmitter(launch, prepared.soul, world);
|
|
580
569
|
const body = await leash.recordBody(launch.paths, { leashTakenAt: runtime.now() });
|
|
581
570
|
bodySequence = body.sequence;
|
|
582
571
|
const supervisor = await BodySupervisor.open(launch.paths, body.sequence, leash);
|
|
@@ -78,8 +78,8 @@ export declare const tellResultSchema: z.ZodObject<{
|
|
|
78
78
|
}>;
|
|
79
79
|
turnSequence: z.ZodNumber;
|
|
80
80
|
receipt: z.ZodOptional<z.ZodEnum<{
|
|
81
|
-
required: "required";
|
|
82
81
|
unavailable: "unavailable";
|
|
82
|
+
required: "required";
|
|
83
83
|
}>>;
|
|
84
84
|
}, z.core.$strict>, z.ZodTransform<Readonly<{
|
|
85
85
|
turnSequence: number;
|
|
@@ -90,7 +90,7 @@ export declare const tellResultSchema: z.ZodObject<{
|
|
|
90
90
|
deliveredAt: string;
|
|
91
91
|
route: "live" | "launch";
|
|
92
92
|
turnSequence: number;
|
|
93
|
-
receipt?: "
|
|
93
|
+
receipt?: "unavailable" | "required" | undefined;
|
|
94
94
|
}>>>>;
|
|
95
95
|
}, z.core.$strict>;
|
|
96
96
|
wake: z.ZodUnion<readonly [z.ZodObject<{
|
|
@@ -37,7 +37,7 @@ export async function admitCallInitialTell(input) {
|
|
|
37
37
|
const birth = await waitForObservation({
|
|
38
38
|
timeoutMs: BIRTH_TIMEOUT_MS,
|
|
39
39
|
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
40
|
-
probe: async () => await readWaitComplete(input.world, input.id),
|
|
40
|
+
probe: async () => await readWaitComplete(input.world, [input.id], "all", input.signal),
|
|
41
41
|
observe: async () => (await bornStatus(paths, input.id, { aperture: "receipt" })).status,
|
|
42
42
|
complete: defaultWaitComplete,
|
|
43
43
|
});
|
|
@@ -206,8 +206,8 @@ declare const liveResultSchema: z.ZodObject<{
|
|
|
206
206
|
}>;
|
|
207
207
|
turnSequence: z.ZodNumber;
|
|
208
208
|
receipt: z.ZodOptional<z.ZodEnum<{
|
|
209
|
-
required: "required";
|
|
210
209
|
unavailable: "unavailable";
|
|
210
|
+
required: "required";
|
|
211
211
|
}>>;
|
|
212
212
|
}, z.core.$strict>, z.ZodTransform<Readonly<{
|
|
213
213
|
turnSequence: number;
|
|
@@ -218,7 +218,7 @@ declare const liveResultSchema: z.ZodObject<{
|
|
|
218
218
|
deliveredAt: string;
|
|
219
219
|
route: "live" | "launch";
|
|
220
220
|
turnSequence: number;
|
|
221
|
-
receipt?: "
|
|
221
|
+
receipt?: "unavailable" | "required" | undefined;
|
|
222
222
|
}>>>>;
|
|
223
223
|
}, z.core.$strict>;
|
|
224
224
|
wake: z.ZodUnion<readonly [z.ZodObject<{
|
|
@@ -23,12 +23,17 @@ export type ActivitySlice = ActivityFactSlice;
|
|
|
23
23
|
export type { ActivityFact };
|
|
24
24
|
export type { TimelineFact } from "./timeline.js";
|
|
25
25
|
export declare function activitySlice(paths: AkumaPaths): Promise<ActivitySlice>;
|
|
26
|
-
export declare function readStatusFacts(paths: AkumaPaths, input: StatusFactInput): Promise<ActivitySlice["rows"]>;
|
|
26
|
+
export declare function readStatusFacts(paths: AkumaPaths, input: StatusFactInput, signal?: AbortSignal): Promise<ActivitySlice["rows"]>;
|
|
27
|
+
/** One live observation's successful raw input and decoded frontier, never a connection. */
|
|
28
|
+
export declare function createStatusFactReader(paths: AkumaPaths): {
|
|
29
|
+
clear(): void;
|
|
30
|
+
read(input: StatusFactInput, signal?: AbortSignal): Promise<ActivitySlice["rows"]>;
|
|
31
|
+
};
|
|
27
32
|
type LifeSnapshot = Pick<HeartSnapshot, "soul" | "latestBody" | "latestSession" | "latestKill"> & Readonly<{
|
|
28
33
|
hasPendingTell: boolean;
|
|
29
34
|
}>;
|
|
30
35
|
/** Lifecycle probes do not load narration, Tell bodies, or delivery histories. */
|
|
31
|
-
export declare function readLifeSnapshot(paths: AkumaPaths): Promise<LifeSnapshot>;
|
|
36
|
+
export declare function readLifeSnapshot(paths: AkumaPaths, signal?: AbortSignal): Promise<LifeSnapshot>;
|
|
32
37
|
export declare function recordTell(paths: AkumaPaths, tell: Omit<TellFact, "sequence" | "state" | "deliveries" | "binding">, options?: Readonly<{
|
|
33
38
|
interrupt?: boolean;
|
|
34
39
|
}>): Promise<Readonly<{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parsePublicHistoryId } from "../identity.js";
|
|
2
2
|
import { answeredTurnFact, endBodyFact, finishBodyFact, deleteStopControl, insertActivityFact, insertTurnEndFact, insertTurnStartFact, insertPauseControl, insertKillFact, insertSessionFact, insertStopControl, killFactForBody, latestBodyFact, latestKillFact, latestSessionFact, latestTurnFactForBody, lastAnsweredTurnFact, pauseFact, sessionFactForCoordinate, stopFact, turnFact, } from "./rows.js";
|
|
3
3
|
import { insertTellDeliveryFact, dispositionSnapshotProven, insertTellBindingFact, insertTellDispositionSnapshot, insertTellFact, insertTellReceiptFact, insertUndeliveredTellReceipts, latestOpenTellDisposition, openBoundTurns, openTellDispositionIds, pendingTellFacts, hasPendingTell, resolveTellDispositionSnapshot, tellDispositionResolved, tellFact, tellIdsForFence, turnParticipants, } from "./tells.js";
|
|
4
|
-
import { activityFactSlice, statusFacts, lastActivityAt as readLastActivityAt, pruneActivityFacts, } from "./timeline.js";
|
|
4
|
+
import { activityFactSlice, statusFacts, readStatusBatch, decodeTimelineBatch, lastActivityAt as readLastActivityAt, pruneActivityFacts, } from "./timeline.js";
|
|
5
5
|
import { isHeartAbsent, readSealFromLeash, withHeartTransaction, withReadOnlyHeart } from "./storage.js";
|
|
6
6
|
import { soulFact } from "./soul.js";
|
|
7
7
|
import { AkumaBusyError, HeartAuthorityCorruptionError } from "./facts.js";
|
|
@@ -53,11 +53,56 @@ export async function appendActivity(paths, input) {
|
|
|
53
53
|
export async function activitySlice(paths) {
|
|
54
54
|
return await withReadOnlyHeart(paths, (heart) => activityFactSlice(heart));
|
|
55
55
|
}
|
|
56
|
-
export async function readStatusFacts(paths, input) {
|
|
57
|
-
return await withReadOnlyHeart(paths, (heart) => statusFacts(heart, input));
|
|
56
|
+
export async function readStatusFacts(paths, input, signal) {
|
|
57
|
+
return await withReadOnlyHeart(paths, (heart) => statusFacts(heart, input), signal);
|
|
58
|
+
}
|
|
59
|
+
// Each query returns a fixed set of scalar columns; compare JSON columns as text.
|
|
60
|
+
function sameRawRows(left, right) {
|
|
61
|
+
if (left.length !== right.length)
|
|
62
|
+
return false;
|
|
63
|
+
if (left.length === 0)
|
|
64
|
+
return true;
|
|
65
|
+
const columns = Object.keys(left[0]);
|
|
66
|
+
return left.every((row, index) => columns.every((column) => row[column] === right[index][column]));
|
|
67
|
+
}
|
|
68
|
+
function sameStatusBatch(left, right) {
|
|
69
|
+
return (left.frontier === right.frontier &&
|
|
70
|
+
sameRawRows(left.rows, right.rows) &&
|
|
71
|
+
sameRawRows(left.turns, right.turns) &&
|
|
72
|
+
sameRawRows(left.calls, right.calls) &&
|
|
73
|
+
sameRawRows(left.activity, right.activity) &&
|
|
74
|
+
sameRawRows(left.tells.rows, right.tells.rows) &&
|
|
75
|
+
sameRawRows(left.tells.deliveries, right.tells.deliveries) &&
|
|
76
|
+
sameRawRows(left.tells.bindings, right.tells.bindings));
|
|
77
|
+
}
|
|
78
|
+
/** One live observation's successful raw input and decoded frontier, never a connection. */
|
|
79
|
+
export function createStatusFactReader(paths) {
|
|
80
|
+
let memo;
|
|
81
|
+
return {
|
|
82
|
+
clear() {
|
|
83
|
+
memo = undefined;
|
|
84
|
+
},
|
|
85
|
+
async read(input, signal) {
|
|
86
|
+
try {
|
|
87
|
+
const next = await withReadOnlyHeart(paths, (heart) => {
|
|
88
|
+
const batch = readStatusBatch(heart, input);
|
|
89
|
+
if (memo !== undefined && sameStatusBatch(batch, memo.batch))
|
|
90
|
+
return memo;
|
|
91
|
+
return { batch, facts: decodeTimelineBatch(batch) };
|
|
92
|
+
}, signal);
|
|
93
|
+
// Publication follows COMMIT, so failed reads can never supply a fallback.
|
|
94
|
+
memo = next;
|
|
95
|
+
return next.facts;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
memo = undefined;
|
|
99
|
+
throw error;
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
};
|
|
58
103
|
}
|
|
59
104
|
/** Lifecycle probes do not load narration, Tell bodies, or delivery histories. */
|
|
60
|
-
export async function readLifeSnapshot(paths) {
|
|
105
|
+
export async function readLifeSnapshot(paths, signal) {
|
|
61
106
|
try {
|
|
62
107
|
return await withReadOnlyHeart(paths, (heart) => ({
|
|
63
108
|
soul: soulFact(heart),
|
|
@@ -65,7 +110,7 @@ export async function readLifeSnapshot(paths) {
|
|
|
65
110
|
latestSession: latestSessionFact(heart),
|
|
66
111
|
latestKill: latestKillFact(heart),
|
|
67
112
|
hasPendingTell: hasPendingTell(heart),
|
|
68
|
-
}));
|
|
113
|
+
}), signal);
|
|
69
114
|
}
|
|
70
115
|
catch (error) {
|
|
71
116
|
if (isHeartAbsent(error))
|
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
import type { DatabaseSync } from "node:sqlite";
|
|
2
|
-
import { type TellDeliveryInput, type TellFact, type TellReceiptInput } from "./facts.js";
|
|
2
|
+
import { type TellDelivery, type TellDeliveryInput, type TellFact, type TellReceiptInput } from "./facts.js";
|
|
3
|
+
type TellRow = Readonly<{
|
|
4
|
+
sequence: number;
|
|
5
|
+
id: string;
|
|
6
|
+
body: string;
|
|
7
|
+
schema_json: string | null;
|
|
8
|
+
initiator: string | null;
|
|
9
|
+
recorded_at: string;
|
|
10
|
+
state: TellFact["state"];
|
|
11
|
+
}>;
|
|
12
|
+
type TellDeliveryRow = Readonly<{
|
|
13
|
+
turn_sequence: number;
|
|
14
|
+
route: TellDelivery["route"];
|
|
15
|
+
receipt: TellDelivery["receipt"] | null;
|
|
16
|
+
delivered_at: string;
|
|
17
|
+
}>;
|
|
3
18
|
export declare const tellStateSql = "CASE\n WHEN EXISTS (\n SELECT 1 FROM tell_deliveries d\n WHERE d.tell_id = tells.id AND (d.route = 'launch' OR d.receipt = 'unavailable')\n ) THEN 'told'\n WHEN EXISTS (SELECT 1 FROM tell_receipts r WHERE r.evidence = 'exact' AND r.tell_id = tells.id) THEN 'told'\n WHEN EXISTS (\n SELECT 1 FROM tell_receipts r\n JOIN tell_deliveries d ON d.turn_sequence = r.turn_sequence AND d.fence = r.fence\n WHERE r.evidence = 'fence' AND d.tell_id = tells.id\n ) THEN 'told'\n ELSE 'pending'\nEND";
|
|
4
19
|
export declare const pendingTellSequencesSql = "SELECT tells.sequence FROM tells WHERE CASE\n WHEN EXISTS (\n SELECT 1 FROM tell_deliveries d\n WHERE d.tell_id = tells.id AND (d.route = 'launch' OR d.receipt = 'unavailable')\n ) THEN 'told'\n WHEN EXISTS (SELECT 1 FROM tell_receipts r WHERE r.evidence = 'exact' AND r.tell_id = tells.id) THEN 'told'\n WHEN EXISTS (\n SELECT 1 FROM tell_receipts r\n JOIN tell_deliveries d ON d.turn_sequence = r.turn_sequence AND d.fence = r.fence\n WHERE r.evidence = 'fence' AND d.tell_id = tells.id\n ) THEN 'told'\n ELSE 'pending'\nEND = 'pending'\n UNION SELECT tells.sequence FROM tells JOIN tell_disposition_members m ON m.tell_id = tells.id";
|
|
5
20
|
export declare const pendingTellProtectionSql = "SELECT d.turn_sequence FROM tell_deliveries d\n JOIN tells ON tells.id = d.tell_id WHERE CASE\n WHEN EXISTS (\n SELECT 1 FROM tell_deliveries d\n WHERE d.tell_id = tells.id AND (d.route = 'launch' OR d.receipt = 'unavailable')\n ) THEN 'told'\n WHEN EXISTS (SELECT 1 FROM tell_receipts r WHERE r.evidence = 'exact' AND r.tell_id = tells.id) THEN 'told'\n WHEN EXISTS (\n SELECT 1 FROM tell_receipts r\n JOIN tell_deliveries d ON d.turn_sequence = r.turn_sequence AND d.fence = r.fence\n WHERE r.evidence = 'fence' AND d.tell_id = tells.id\n ) THEN 'told'\n ELSE 'pending'\nEND = 'pending'\n UNION SELECT d.turn_sequence FROM tell_deliveries d JOIN tell_disposition_members m ON m.tell_id = d.tell_id";
|
|
6
|
-
|
|
21
|
+
type TellBatch = Readonly<{
|
|
22
|
+
rows: readonly TellRow[];
|
|
23
|
+
deliveries: readonly (TellDeliveryRow & {
|
|
24
|
+
sequence: number;
|
|
25
|
+
tell_id: string;
|
|
26
|
+
fence: string;
|
|
27
|
+
})[];
|
|
28
|
+
bindings: readonly {
|
|
29
|
+
sequence: number;
|
|
30
|
+
tell_id: string;
|
|
31
|
+
turn_sequence: number;
|
|
32
|
+
bound_at: string;
|
|
33
|
+
}[];
|
|
34
|
+
}>;
|
|
35
|
+
export declare function decodeTellBatch(batch: TellBatch): readonly TellFact[];
|
|
36
|
+
export declare function tellBatchAtSequences(database: DatabaseSync, sequences: readonly number[]): TellBatch;
|
|
7
37
|
export declare function hasPendingTell(database: DatabaseSync): boolean;
|
|
8
38
|
export declare function insertTellFact(database: DatabaseSync, tell: Omit<TellFact, "sequence" | "state" | "deliveries">): number;
|
|
9
39
|
export declare function tellFact(database: DatabaseSync, id: string): TellFact | null;
|
|
@@ -30,3 +60,4 @@ export declare function insertTellBindingFact(database: DatabaseSync, input: Rea
|
|
|
30
60
|
export declare function turnParticipants(database: DatabaseSync, turnSequence: number): readonly string[];
|
|
31
61
|
export declare function drainPendingTells(pending: readonly TellFact[], activeTurnSequences?: readonly number[]): readonly TellFact[];
|
|
32
62
|
export declare function openBoundTurns(database: DatabaseSync, bodySequence: number): readonly number[];
|
|
63
|
+
export {};
|
|
@@ -18,16 +18,26 @@ export const pendingTellSequencesSql = `SELECT tells.sequence FROM tells WHERE $
|
|
|
18
18
|
export const pendingTellProtectionSql = `SELECT d.turn_sequence FROM tell_deliveries d
|
|
19
19
|
JOIN tells ON tells.id = d.tell_id WHERE ${tellStateSql} = 'pending'
|
|
20
20
|
UNION SELECT d.turn_sequence FROM tell_deliveries d JOIN tell_disposition_members m ON m.tell_id = d.tell_id`;
|
|
21
|
-
function
|
|
21
|
+
function readTellBatch(database, rows) {
|
|
22
22
|
if (rows.length === 0)
|
|
23
|
-
return [];
|
|
23
|
+
return { rows, deliveries: [], bindings: [] };
|
|
24
24
|
const ids = JSON.stringify(rows.map((row) => row.id));
|
|
25
|
-
const deliveries =
|
|
26
|
-
|
|
27
|
-
.prepare(`SELECT tell_id, turn_sequence, route, receipt, delivered_at
|
|
25
|
+
const deliveries = database
|
|
26
|
+
.prepare(`SELECT sequence, tell_id, turn_sequence, fence, route, receipt, delivered_at
|
|
28
27
|
FROM tell_deliveries WHERE tell_id IN (SELECT value FROM json_each(?)) ORDER BY sequence`)
|
|
29
28
|
.all(ids);
|
|
30
|
-
|
|
29
|
+
const bindings = database
|
|
30
|
+
.prepare(`SELECT sequence, tell_id, turn_sequence, bound_at FROM tell_bindings
|
|
31
|
+
WHERE sequence IN (
|
|
32
|
+
SELECT MAX(sequence) FROM tell_bindings
|
|
33
|
+
WHERE tell_id IN (SELECT value FROM json_each(?)) GROUP BY tell_id
|
|
34
|
+
) ORDER BY sequence`)
|
|
35
|
+
.all(ids);
|
|
36
|
+
return { rows, deliveries, bindings };
|
|
37
|
+
}
|
|
38
|
+
export function decodeTellBatch(batch) {
|
|
39
|
+
const deliveries = new Map();
|
|
40
|
+
for (const row of batch.deliveries) {
|
|
31
41
|
const group = deliveries.get(row.tell_id) ?? [];
|
|
32
42
|
group.push({
|
|
33
43
|
turnSequence: row.turn_sequence,
|
|
@@ -38,16 +48,9 @@ function decodeTellRows(database, rows) {
|
|
|
38
48
|
deliveries.set(row.tell_id, group);
|
|
39
49
|
}
|
|
40
50
|
const bindings = new Map();
|
|
41
|
-
const
|
|
42
|
-
.prepare(`SELECT tell_id, turn_sequence, bound_at FROM tell_bindings
|
|
43
|
-
WHERE sequence IN (
|
|
44
|
-
SELECT MAX(sequence) FROM tell_bindings
|
|
45
|
-
WHERE tell_id IN (SELECT value FROM json_each(?)) GROUP BY tell_id
|
|
46
|
-
)`)
|
|
47
|
-
.all(ids);
|
|
48
|
-
for (const row of bindingRows)
|
|
51
|
+
for (const row of batch.bindings)
|
|
49
52
|
bindings.set(row.tell_id, { turnSequence: row.turn_sequence, boundAt: row.bound_at });
|
|
50
|
-
return rows.map((row) => ({
|
|
53
|
+
return batch.rows.map((row) => ({
|
|
51
54
|
kind: "tell",
|
|
52
55
|
sequence: row.sequence,
|
|
53
56
|
id: row.id,
|
|
@@ -60,14 +63,17 @@ function decodeTellRows(database, rows) {
|
|
|
60
63
|
...(bindings.has(row.id) ? { binding: bindings.get(row.id) } : {}),
|
|
61
64
|
}));
|
|
62
65
|
}
|
|
63
|
-
|
|
66
|
+
function decodeTellRows(database, rows) {
|
|
67
|
+
return decodeTellBatch(readTellBatch(database, rows));
|
|
68
|
+
}
|
|
69
|
+
export function tellBatchAtSequences(database, sequences) {
|
|
64
70
|
if (sequences.length === 0)
|
|
65
|
-
return [];
|
|
71
|
+
return { rows: [], deliveries: [], bindings: [] };
|
|
66
72
|
const rows = database
|
|
67
73
|
.prepare(`SELECT sequence, id, body, initiator, schema_json, recorded_at, ${tellStateSql} AS state
|
|
68
74
|
FROM tells WHERE sequence IN (SELECT value FROM json_each(?)) ORDER BY sequence`)
|
|
69
75
|
.all(JSON.stringify(sequences));
|
|
70
|
-
return
|
|
76
|
+
return readTellBatch(database, rows);
|
|
71
77
|
}
|
|
72
78
|
export function hasPendingTell(database) {
|
|
73
79
|
return database.prepare(`SELECT 1 FROM tells WHERE ${tellStateSql} = 'pending' LIMIT 1`).get() !== undefined;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DatabaseSync } from "node:sqlite";
|
|
2
2
|
import type { CallFact, TellFact, TurnEndFact, TurnStartFact } from "./facts.js";
|
|
3
|
-
import { type ActivityFact } from "./rows.js";
|
|
3
|
+
import { type ActivityFact, type ActivityRow, type CallRow, type TurnRow } from "./rows.js";
|
|
4
|
+
import { tellBatchAtSequences } from "./tells.js";
|
|
4
5
|
export type TimelineFact = TurnStartFact | CallFact | ActivityFact | TellFact | TurnEndFact;
|
|
5
6
|
export type ActivityFactSlice = Readonly<{
|
|
6
7
|
rows: readonly TimelineFact[];
|
|
@@ -9,10 +10,31 @@ export type ActivityFactSlice = Readonly<{
|
|
|
9
10
|
}>;
|
|
10
11
|
export declare function lastActivityAt(database: DatabaseSync): string | null;
|
|
11
12
|
export declare function pruneActivityFacts(database: DatabaseSync, limit: number, protectionReleased?: boolean): void;
|
|
13
|
+
type TimelineRow = Readonly<{
|
|
14
|
+
sequence: number;
|
|
15
|
+
kind: "turn-start" | "call" | "activity" | "tell" | "turn-end";
|
|
16
|
+
}>;
|
|
17
|
+
type TimelineBatch = Readonly<{
|
|
18
|
+
rows: readonly TimelineRow[];
|
|
19
|
+
turns: readonly TurnRow[];
|
|
20
|
+
calls: readonly CallRow[];
|
|
21
|
+
activity: readonly ActivityRow[];
|
|
22
|
+
tells: ReturnType<typeof tellBatchAtSequences>;
|
|
23
|
+
}>;
|
|
24
|
+
export declare function decodeTimelineBatch(batch: TimelineBatch): readonly TimelineFact[];
|
|
12
25
|
export type StatusFactInput = Readonly<{
|
|
13
26
|
aperture: "monitoring" | "receipt";
|
|
14
27
|
admittedTellId?: string;
|
|
15
28
|
}>;
|
|
16
29
|
/** Select the frontier and its delivered Tells, plus aperture-required Tell pins. */
|
|
30
|
+
export declare function readStatusBatch(database: DatabaseSync, input: StatusFactInput): {
|
|
31
|
+
rows: readonly TimelineRow[];
|
|
32
|
+
turns: readonly TurnRow[];
|
|
33
|
+
calls: readonly CallRow[];
|
|
34
|
+
activity: readonly ActivityRow[];
|
|
35
|
+
tells: ReturnType<typeof tellBatchAtSequences>;
|
|
36
|
+
frontier: number | null;
|
|
37
|
+
};
|
|
17
38
|
export declare function statusFacts(database: DatabaseSync, input: StatusFactInput): readonly TimelineFact[];
|
|
18
39
|
export declare function activityFactSlice(database: DatabaseSync): ActivityFactSlice;
|
|
40
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { decodeActivityRow, decodeCallRow, decodeTurnRow, } from "./rows.js";
|
|
2
|
-
import {
|
|
2
|
+
import { decodeTellBatch, tellBatchAtSequences, tellStateSql, pendingTellProtectionSql, pendingTellSequencesSql, } from "./tells.js";
|
|
3
3
|
export function lastActivityAt(database) {
|
|
4
4
|
const row = database
|
|
5
5
|
.prepare(`SELECT CASE timeline.kind
|
|
@@ -52,36 +52,40 @@ export function pruneActivityFacts(database, limit, protectionReleased = false)
|
|
|
52
52
|
DELETE FROM timeline WHERE sequence < ? AND sequence NOT IN protected`)
|
|
53
53
|
.run(cutoff.sequence, cutoff.sequence, cutoff.sequence, cutoff.sequence);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function readTimelineBatch(database, rows) {
|
|
56
56
|
const sequences = (kind) => JSON.stringify(rows.filter((row) => row.kind === kind).map((row) => row.sequence));
|
|
57
|
-
const facts = new Map();
|
|
58
57
|
const turns = database
|
|
59
58
|
.prepare(`SELECT sequence, body_sequence, started_at, end_sequence, outcome,
|
|
60
59
|
history_id, session_json, answer, answer_json, schema_json, initiator, diagnostic, completed_at FROM turns
|
|
61
|
-
WHERE sequence IN (SELECT value FROM json_each(?)) OR end_sequence IN (SELECT value FROM json_each(?))
|
|
60
|
+
WHERE sequence IN (SELECT value FROM json_each(?)) OR end_sequence IN (SELECT value FROM json_each(?))
|
|
61
|
+
ORDER BY sequence`)
|
|
62
62
|
.all(sequences("turn-start"), sequences("turn-end"));
|
|
63
|
-
for (const row of turns) {
|
|
64
|
-
const { end, ...start } = decodeTurnRow(row);
|
|
65
|
-
facts.set(start.sequence, start);
|
|
66
|
-
if (end !== undefined)
|
|
67
|
-
facts.set(end.sequence, end);
|
|
68
|
-
}
|
|
69
63
|
const calls = database
|
|
70
64
|
.prepare(`SELECT sequence, turn_sequence, body, at FROM calls
|
|
71
|
-
WHERE sequence IN (SELECT value FROM json_each(?))`)
|
|
65
|
+
WHERE sequence IN (SELECT value FROM json_each(?)) ORDER BY sequence`)
|
|
72
66
|
.all(sequences("call"));
|
|
73
|
-
for (const row of calls)
|
|
74
|
-
facts.set(row.sequence, decodeCallRow(row));
|
|
75
67
|
const activity = database
|
|
76
68
|
.prepare(`SELECT sequence, turn_sequence, event_json, at FROM activity
|
|
77
|
-
WHERE sequence IN (SELECT value FROM json_each(?))`)
|
|
69
|
+
WHERE sequence IN (SELECT value FROM json_each(?)) ORDER BY sequence`)
|
|
78
70
|
.all(sequences("activity"));
|
|
79
|
-
|
|
71
|
+
const tells = tellBatchAtSequences(database, rows.filter((row) => row.kind === "tell").map((row) => row.sequence));
|
|
72
|
+
return { rows, turns, calls, activity, tells };
|
|
73
|
+
}
|
|
74
|
+
export function decodeTimelineBatch(batch) {
|
|
75
|
+
const facts = new Map();
|
|
76
|
+
for (const row of batch.turns) {
|
|
77
|
+
const { end, ...start } = decodeTurnRow(row);
|
|
78
|
+
facts.set(start.sequence, start);
|
|
79
|
+
if (end !== undefined)
|
|
80
|
+
facts.set(end.sequence, end);
|
|
81
|
+
}
|
|
82
|
+
for (const row of batch.calls)
|
|
83
|
+
facts.set(row.sequence, decodeCallRow(row));
|
|
84
|
+
for (const row of batch.activity)
|
|
80
85
|
facts.set(row.sequence, decodeActivityRow(row));
|
|
81
|
-
|
|
82
|
-
for (const fact of tells)
|
|
86
|
+
for (const fact of decodeTellBatch(batch.tells))
|
|
83
87
|
facts.set(fact.sequence, fact);
|
|
84
|
-
return rows.map((row) => {
|
|
88
|
+
return batch.rows.map((row) => {
|
|
85
89
|
const fact = facts.get(row.sequence);
|
|
86
90
|
if (fact === undefined || fact.kind !== row.kind)
|
|
87
91
|
throw new Error(`Akuma timeline references missing ${row.kind} ${row.sequence}`);
|
|
@@ -89,7 +93,7 @@ function decodeTimelineRows(database, rows) {
|
|
|
89
93
|
});
|
|
90
94
|
}
|
|
91
95
|
/** Select the frontier and its delivered Tells, plus aperture-required Tell pins. */
|
|
92
|
-
export function
|
|
96
|
+
export function readStatusBatch(database, input) {
|
|
93
97
|
const frontier = database.prepare("SELECT sequence FROM turns ORDER BY sequence DESC LIMIT 1").get();
|
|
94
98
|
const rows = database
|
|
95
99
|
.prepare(`WITH selected(sequence) AS (
|
|
@@ -104,7 +108,10 @@ export function statusFacts(database, input) {
|
|
|
104
108
|
UNION SELECT sequence FROM tells WHERE ? AND ${tellStateSql} = 'pending'
|
|
105
109
|
) SELECT timeline.sequence, timeline.kind FROM timeline JOIN selected USING(sequence) ORDER BY sequence`)
|
|
106
110
|
.all(frontier?.sequence ?? null, frontier?.sequence ?? null, frontier?.sequence ?? null, frontier?.sequence ?? null, frontier?.sequence ?? null, input.admittedTellId ?? null, input.aperture === "monitoring" || input.admittedTellId === undefined ? 1 : 0);
|
|
107
|
-
return
|
|
111
|
+
return { frontier: frontier?.sequence ?? null, ...readTimelineBatch(database, rows) };
|
|
112
|
+
}
|
|
113
|
+
export function statusFacts(database, input) {
|
|
114
|
+
return decodeTimelineBatch(readStatusBatch(database, input));
|
|
108
115
|
}
|
|
109
116
|
export function activityFactSlice(database) {
|
|
110
117
|
const bounds = database.prepare("SELECT MIN(sequence) AS lowest, MAX(sequence) AS highest FROM timeline").get();
|
|
@@ -112,7 +119,7 @@ export function activityFactSlice(database) {
|
|
|
112
119
|
.prepare("SELECT sequence, kind FROM timeline ORDER BY sequence")
|
|
113
120
|
.all();
|
|
114
121
|
return {
|
|
115
|
-
rows:
|
|
122
|
+
rows: decodeTimelineBatch(readTimelineBatch(database, rows)),
|
|
116
123
|
lowestRetained: bounds.lowest,
|
|
117
124
|
highest: bounds.highest,
|
|
118
125
|
};
|
|
@@ -41,8 +41,8 @@ export declare const tellRowSchema: z.ZodObject<{
|
|
|
41
41
|
}>;
|
|
42
42
|
turnSequence: z.ZodNumber;
|
|
43
43
|
receipt: z.ZodOptional<z.ZodEnum<{
|
|
44
|
-
required: "required";
|
|
45
44
|
unavailable: "unavailable";
|
|
45
|
+
required: "required";
|
|
46
46
|
}>>;
|
|
47
47
|
}, z.core.$strict>, z.ZodTransform<Readonly<{
|
|
48
48
|
turnSequence: number;
|
|
@@ -53,7 +53,7 @@ export declare const tellRowSchema: z.ZodObject<{
|
|
|
53
53
|
deliveredAt: string;
|
|
54
54
|
route: "live" | "launch";
|
|
55
55
|
turnSequence: number;
|
|
56
|
-
receipt?: "
|
|
56
|
+
receipt?: "unavailable" | "required" | undefined;
|
|
57
57
|
}>>>>;
|
|
58
58
|
}, z.core.$strict>;
|
|
59
59
|
declare const outcomeSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
@@ -283,8 +283,8 @@ declare const openSnapshotRowSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z
|
|
|
283
283
|
}>;
|
|
284
284
|
turnSequence: z.ZodNumber;
|
|
285
285
|
receipt: z.ZodOptional<z.ZodEnum<{
|
|
286
|
-
required: "required";
|
|
287
286
|
unavailable: "unavailable";
|
|
287
|
+
required: "required";
|
|
288
288
|
}>>;
|
|
289
289
|
}, z.core.$strict>, z.ZodTransform<Readonly<{
|
|
290
290
|
turnSequence: number;
|
|
@@ -295,7 +295,7 @@ declare const openSnapshotRowSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z
|
|
|
295
295
|
deliveredAt: string;
|
|
296
296
|
route: "live" | "launch";
|
|
297
297
|
turnSequence: number;
|
|
298
|
-
receipt?: "
|
|
298
|
+
receipt?: "unavailable" | "required" | undefined;
|
|
299
299
|
}>>>>;
|
|
300
300
|
}, z.core.$strict>]>, z.ZodObject<{
|
|
301
301
|
kind: z.ZodLiteral<"tool">;
|
|
@@ -449,8 +449,8 @@ declare const idleSnapshotRowSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z
|
|
|
449
449
|
}>;
|
|
450
450
|
turnSequence: z.ZodNumber;
|
|
451
451
|
receipt: z.ZodOptional<z.ZodEnum<{
|
|
452
|
-
required: "required";
|
|
453
452
|
unavailable: "unavailable";
|
|
453
|
+
required: "required";
|
|
454
454
|
}>>;
|
|
455
455
|
}, z.core.$strict>, z.ZodTransform<Readonly<{
|
|
456
456
|
turnSequence: number;
|
|
@@ -461,7 +461,7 @@ declare const idleSnapshotRowSchema: z.ZodUnion<readonly [z.ZodUnion<readonly [z
|
|
|
461
461
|
deliveredAt: string;
|
|
462
462
|
route: "live" | "launch";
|
|
463
463
|
turnSequence: number;
|
|
464
|
-
receipt?: "
|
|
464
|
+
receipt?: "unavailable" | "required" | undefined;
|
|
465
465
|
}>>>>;
|
|
466
466
|
}, z.core.$strict>]>, z.ZodObject<{
|
|
467
467
|
kind: z.ZodLiteral<"tool">;
|
|
@@ -638,8 +638,8 @@ export declare const activitySnapshotSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
638
638
|
}>;
|
|
639
639
|
turnSequence: z.ZodNumber;
|
|
640
640
|
receipt: z.ZodOptional<z.ZodEnum<{
|
|
641
|
-
required: "required";
|
|
642
641
|
unavailable: "unavailable";
|
|
642
|
+
required: "required";
|
|
643
643
|
}>>;
|
|
644
644
|
}, z.core.$strict>, z.ZodTransform<Readonly<{
|
|
645
645
|
turnSequence: number;
|
|
@@ -650,7 +650,7 @@ export declare const activitySnapshotSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
650
650
|
deliveredAt: string;
|
|
651
651
|
route: "live" | "launch";
|
|
652
652
|
turnSequence: number;
|
|
653
|
-
receipt?: "
|
|
653
|
+
receipt?: "unavailable" | "required" | undefined;
|
|
654
654
|
}>>>>;
|
|
655
655
|
}, z.core.$strict>]>, z.ZodObject<{
|
|
656
656
|
kind: z.ZodLiteral<"tool">;
|
|
@@ -845,8 +845,8 @@ export declare const activitySnapshotSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
845
845
|
}>;
|
|
846
846
|
turnSequence: z.ZodNumber;
|
|
847
847
|
receipt: z.ZodOptional<z.ZodEnum<{
|
|
848
|
-
required: "required";
|
|
849
848
|
unavailable: "unavailable";
|
|
849
|
+
required: "required";
|
|
850
850
|
}>>;
|
|
851
851
|
}, z.core.$strict>, z.ZodTransform<Readonly<{
|
|
852
852
|
turnSequence: number;
|
|
@@ -857,7 +857,7 @@ export declare const activitySnapshotSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
857
857
|
deliveredAt: string;
|
|
858
858
|
route: "live" | "launch";
|
|
859
859
|
turnSequence: number;
|
|
860
|
-
receipt?: "
|
|
860
|
+
receipt?: "unavailable" | "required" | undefined;
|
|
861
861
|
}>>>>;
|
|
862
862
|
}, z.core.$strict>]>, z.ZodObject<{
|
|
863
863
|
kind: z.ZodLiteral<"tool">;
|