@astrosheep/keiyaku 4.6.32 → 4.6.34
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 +18 -7
- package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +18 -11
- package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +18 -11
- package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +18 -11
- package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/pi/README.md +55 -97
- package/build/plugins/pi/keiyaku.ts +1 -142
- package/build/skills/keiyaku-akuma/SKILL.md +18 -11
- package/build/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/src/akuma/akuma-instance.d.ts +11 -0
- package/build/src/akuma/akuma-instance.js +1 -2
- package/build/src/akuma/akuma-observe.d.ts +8 -0
- package/build/src/akuma/akuma-observe.js +81 -14
- package/build/src/akuma/akuma-owner.d.ts +1 -0
- package/build/src/akuma/akuma-owner.js +3 -5
- package/build/src/akuma/akuma-selection-execution.d.ts +82 -7
- package/build/src/akuma/akuma-selection-execution.js +26 -27
- package/build/src/akuma/akuma-wait.d.ts +155 -1
- package/build/src/akuma/akuma-wait.js +94 -34
- package/build/src/akuma/akuma.d.ts +17 -1
- package/build/src/akuma/akuma.js +37 -18
- package/build/src/akuma/body.js +13 -18
- package/build/src/akuma/call-initial-tell.d.ts +0 -1
- package/build/src/akuma/call-initial-tell.js +0 -1
- package/build/src/akuma/heart/activity-schema.d.ts +16 -0
- package/build/src/akuma/heart/activity-schema.js +7 -0
- package/build/src/akuma/heart/facts.d.ts +1 -0
- package/build/src/akuma/heart/facts.js +14 -0
- package/build/src/akuma/heart/index.d.ts +7 -1
- package/build/src/akuma/heart/index.js +35 -9
- package/build/src/akuma/heart/rows.d.ts +1 -0
- package/build/src/akuma/heart/rows.js +4 -0
- package/build/src/akuma/heart/timeline.js +4 -4
- package/build/src/akuma/lineage-cache.d.ts +7 -2
- package/build/src/akuma/lineage-cache.js +48 -24
- package/build/src/akuma/projection-read.d.ts +4 -2
- package/build/src/akuma/projection-read.js +25 -23
- package/build/src/akuma/projection.d.ts +94 -2
- package/build/src/akuma/projection.js +47 -47
- package/build/src/akuma/provider.d.ts +2 -2
- package/build/src/akuma/provider.js +27 -20
- package/build/src/akuma/providers/acp/core.js +2 -5
- package/build/src/akuma/providers/opencode-sdk/events.d.ts +2 -1
- package/build/src/akuma/providers/opencode-sdk/events.js +31 -1
- package/build/src/akuma/publication.js +3 -2
- package/build/src/akuma/selection-observation.d.ts +645 -0
- package/build/src/akuma/selection-observation.js +22 -7
- package/build/src/akuma/status-projection.d.ts +14 -1
- package/build/src/akuma/status-projection.js +40 -2
- package/build/src/akuma/turn-drive.js +21 -15
- package/build/src/body/amend.js +5 -17
- package/build/src/body/decode.js +11 -1
- package/build/src/body/envelope.d.ts +5 -1
- package/build/src/body/envelope.js +4 -2
- package/build/src/body/render.js +4 -6
- package/build/src/bounded-list.d.ts +8 -0
- package/build/src/bounded-list.js +10 -0
- package/build/src/cli/commands/akuma-grammar.d.ts +5 -8
- package/build/src/cli/commands/akuma-grammar.js +52 -77
- package/build/src/cli/commands/akuma.d.ts +1 -2
- package/build/src/cli/commands/akuma.js +12 -61
- package/build/src/cli/commands/contract-grammar.d.ts +1 -0
- package/build/src/cli/commands/contract-grammar.js +39 -42
- package/build/src/cli/commands/contract-help.d.ts +6 -5
- package/build/src/cli/commands/contract-help.js +21 -13
- package/build/src/cli/commands/contract.d.ts +3 -3
- package/build/src/cli/commands/contract.js +13 -9
- package/build/src/cli/commands/debt-grammar.js +2 -4
- package/build/src/cli/parse.d.ts +4 -10
- package/build/src/cli/parse.js +2 -5
- package/build/src/cli/render/akuma-activity.d.ts +12 -34
- package/build/src/cli/render/akuma-activity.js +99 -180
- package/build/src/cli/render/akuma.d.ts +5 -11
- package/build/src/cli/render/akuma.js +22 -30
- package/build/src/cli/render/catalog.js +4 -6
- package/build/src/cli/render/contract-history.d.ts +1 -3
- package/build/src/cli/render/contract-history.js +70 -49
- package/build/src/cli/render/contract-observation.d.ts +2 -1
- package/build/src/cli/render/contract-observation.js +25 -1
- package/build/src/cli/render/contract-wait.d.ts +2 -2
- package/build/src/cli/render/contract-wait.js +21 -17
- package/build/src/cli/render/contract.js +12 -9
- package/build/src/cli/render/debt.js +1 -2
- package/build/src/cli/render/execution-progress.js +1 -3
- package/build/src/cli/render/kanshi-akuma.d.ts +4 -3
- package/build/src/cli/render/kanshi-akuma.js +27 -23
- package/build/src/cli/render/kanshi.js +45 -60
- package/build/src/cli/render/receipt.d.ts +1 -1
- package/build/src/cli/render/receipt.js +33 -28
- package/build/src/cli/render/reconcile.js +2 -5
- package/build/src/cli/render/refusal.js +3 -6
- package/build/src/cli/render/terminal.d.ts +2 -4
- package/build/src/cli/render/terminal.js +10 -17
- package/build/src/cli/render/verbs.d.ts +1 -0
- package/build/src/cli/render/verbs.js +39 -34
- package/build/src/cli/runtime.js +12 -32
- package/build/src/core/facts/codec.js +7 -2
- package/build/src/core/facts/eligibility.d.ts +4 -4
- package/build/src/core/facts/eligibility.js +11 -0
- package/build/src/core/facts/fold.js +9 -5
- package/build/src/core/facts/gate.d.ts +5 -1
- package/build/src/core/facts/gate.js +14 -10
- package/build/src/core/facts/types.d.ts +5 -1
- package/build/src/core/facts/types.js +7 -0
- package/build/src/core/subject.d.ts +4 -1
- package/build/src/core/subject.js +10 -2
- package/build/src/core/verbs/amend.d.ts +15 -4
- package/build/src/core/verbs/amend.js +19 -9
- package/build/src/debt/board.d.ts +2 -1
- package/build/src/debt/board.js +3 -3
- package/build/src/debt/catalog.js +2 -1
- package/build/src/debt/document.d.ts +1 -0
- package/build/src/debt/document.js +3 -0
- package/build/src/debt/index.d.ts +2 -2
- package/build/src/debt/index.js +9 -14
- package/build/src/debt/input.d.ts +2 -1
- package/build/src/debt/input.js +6 -4
- package/build/src/debt/operations.d.ts +2 -1
- package/build/src/dispatch/index.d.ts +0 -17
- package/build/src/dispatch/index.js +1 -10
- package/build/src/git/identity.js +16 -45
- package/build/src/git/nuke.js +13 -23
- package/build/src/git/observe.d.ts +7 -3
- package/build/src/git/observe.js +29 -26
- package/build/src/git/process.js +11 -18
- package/build/src/git/read-observation.d.ts +5 -4
- package/build/src/git/repository.d.ts +2 -0
- package/build/src/git/repository.js +13 -1
- package/build/src/git/scratch.js +2 -14
- package/build/src/git/terminal-reconcile.js +1 -13
- package/build/src/history.d.ts +26 -0
- package/build/src/history.js +43 -0
- package/build/src/index.d.ts +6 -3
- package/build/src/kanshi/counts.d.ts +15 -1
- package/build/src/kanshi/counts.js +14 -3
- package/build/src/kanshi/index.d.ts +3 -4
- package/build/src/kanshi/index.js +2 -3
- package/build/src/kanshi/read.d.ts +21 -0
- package/build/src/kanshi/read.js +7 -3
- package/build/src/kanshi/report.d.ts +94 -0
- package/build/src/library/address.d.ts +12 -5
- package/build/src/library/address.js +18 -32
- package/build/src/library/akuma-creation.d.ts +39 -0
- package/build/src/library/akuma-creation.js +3 -9
- package/build/src/library/akumas.d.ts +5 -1
- package/build/src/library/akumas.js +11 -5
- package/build/src/library/continuation.d.ts +10 -0
- package/build/src/library/contract-composition.js +10 -10
- package/build/src/library/contract-creation.js +12 -13
- package/build/src/library/contract-outcomes.d.ts +72 -1
- package/build/src/library/contract-outcomes.js +1 -0
- package/build/src/library/contract-types.d.ts +233 -25
- package/build/src/library/contract-types.js +32 -12
- package/build/src/library/contract-wait.d.ts +212 -0
- package/build/src/library/contract-wait.js +65 -49
- package/build/src/library/delivery.d.ts +25 -0
- package/build/src/library/input.d.ts +8 -26
- package/build/src/library/input.js +17 -12
- package/build/src/library/kei.js +167 -90
- package/build/src/library/keiyaku-attribution.d.ts +1 -1
- package/build/src/library/keiyaku-attribution.js +3 -1
- package/build/src/library/keiyaku-classify.js +8 -4
- package/build/src/library/keiyaku-debt.d.ts +8 -7
- package/build/src/library/keiyaku-debt.js +1 -2
- package/build/src/library/keiyaku-identity.d.ts +4 -3
- package/build/src/library/keiyaku-identity.js +35 -7
- package/build/src/library/keiyaku-verbs.d.ts +974 -1409
- package/build/src/library/keiyaku-verbs.js +154 -161
- package/build/src/library/keiyaku-wait.d.ts +753 -0
- package/build/src/library/keiyaku-wait.js +230 -0
- package/build/src/library/keiyaku.d.ts +3110 -29
- package/build/src/library/keiyaku.js +342 -438
- package/build/src/library/model-tools.d.ts +754 -0
- package/build/src/library/model-tools.js +362 -0
- package/build/src/library/outcome.js +5 -6
- package/build/src/library/refusal.d.ts +25 -1
- package/build/src/library/refusal.js +4 -5
- package/build/src/library/selection.d.ts +18 -5
- package/build/src/library/selection.js +11 -5
- package/build/src/mcp/adapter.d.ts +0 -6
- package/build/src/mcp/adapter.js +11 -160
- package/build/src/mcp/description.d.ts +2 -0
- package/build/src/mcp/description.js +2 -0
- package/build/src/mcp/help.d.ts +1 -1
- package/build/src/mcp/help.js +10 -7
- package/build/src/pi/index.d.ts +5 -0
- package/build/src/pi/index.js +99 -0
- package/build/src/pi/status.d.ts +12 -0
- package/build/src/pi/status.js +140 -0
- package/build/src/protocol/amend.d.ts +14 -3
- package/build/src/protocol/amend.js +113 -46
- package/build/src/protocol/bind.d.ts +1 -1
- package/build/src/protocol/bind.js +5 -16
- package/build/src/protocol/completion.d.ts +30 -0
- package/build/src/protocol/completion.js +8 -5
- package/build/src/protocol/deliver.js +7 -20
- package/build/src/protocol/delivery-preview.d.ts +5 -0
- package/build/src/protocol/execution-observation.d.ts +8 -0
- package/build/src/protocol/intent.d.ts +1 -0
- package/build/src/protocol/intent.js +4 -1
- package/build/src/protocol/operations.d.ts +56 -16
- package/build/src/protocol/operations.js +18 -32
- package/build/src/protocol/placement.js +7 -1
- package/build/src/protocol/progress.js +0 -6
- package/build/src/protocol/read/status.d.ts +52 -4
- package/build/src/protocol/read/status.js +26 -22
- package/build/src/protocol/reintegrate.js +2 -2
- package/build/src/protocol/result-leaves.d.ts +56 -8
- package/build/src/protocol/result-leaves.js +11 -2
- package/build/src/protocol/run.js +1 -4
- package/build/src/protocol/verify.d.ts +10 -0
- package/build/src/protocol/verify.js +1 -0
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/build/src/settlement/settle.js +19 -68
- package/package.json +7 -3
- package/plugins/paseo/plugin/index.server.ts +6 -2
- package/plugins/paseo/plugin/server/attach.ts +68 -48
- package/plugins/paseo/plugin/server/directory.ts +259 -0
- package/plugins/paseo/plugin/server/mirror-identity.ts +3 -32
- package/plugins/paseo/plugin/server/reopen.ts +52 -38
- package/plugins/pi/README.md +55 -97
- package/plugins/pi/keiyaku.ts +1 -142
- package/skills/keiyaku-akuma/SKILL.md +18 -11
- package/skills/keiyaku-babysit/SKILL.md +8 -6
- package/skills/keiyaku-debt/SKILL.md +2 -1
- package/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/pi/akuma-tools.ts +0 -283
- package/build/src/body/keys.d.ts +0 -4
- package/build/src/body/keys.js +0 -11
- package/build/src/kanshi/roster.d.ts +0 -2
- package/build/src/kanshi/roster.js +0 -2
- package/build/src/mcp/output.d.ts +0 -385
- package/build/src/mcp/output.js +0 -193
- package/plugins/pi/akuma-tools.ts +0 -283
package/build/src/akuma/body.js
CHANGED
|
@@ -128,6 +128,15 @@ export async function recordPluginDiagnostic(paths, occurrence, error) {
|
|
|
128
128
|
/* plugin diagnostic loss never changes Heart truth */
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
|
+
/** The plugin host bag for one Body occurrence; diagnostics are appended to its log. */
|
|
132
|
+
function pluginHost(launch, world, occurrence) {
|
|
133
|
+
return {
|
|
134
|
+
world,
|
|
135
|
+
reportDiagnostic: (message) => {
|
|
136
|
+
void recordPluginDiagnostic(launch.paths, occurrence, message);
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
131
140
|
async function prepareBodyExecution(launch, leash, runtime, adapter) {
|
|
132
141
|
runtime.signal?.throwIfAborted();
|
|
133
142
|
const birth = await bornSoul(launch, leash, runtime.now());
|
|
@@ -178,12 +187,7 @@ async function prepareBodyStart(paths, leash) {
|
|
|
178
187
|
return true;
|
|
179
188
|
}
|
|
180
189
|
async function emitBodyBirth(launch, soul, world, bodySequence) {
|
|
181
|
-
await emitPluginSignal({
|
|
182
|
-
world,
|
|
183
|
-
reportDiagnostic: (message) => {
|
|
184
|
-
void recordPluginDiagnostic(launch.paths, "birth", message);
|
|
185
|
-
},
|
|
186
|
-
}, {
|
|
190
|
+
await emitPluginSignal(pluginHost(launch, world, "birth"), {
|
|
187
191
|
kind: "akuma.born",
|
|
188
192
|
akumaId: soul.id,
|
|
189
193
|
bodySequence,
|
|
@@ -193,16 +197,13 @@ async function emitBodyBirth(launch, soul, world, bodySequence) {
|
|
|
193
197
|
});
|
|
194
198
|
}
|
|
195
199
|
function turnStartedEmitter(launch, soul, world) {
|
|
196
|
-
const reportDiagnostic = (message) => {
|
|
197
|
-
void recordPluginDiagnostic(launch.paths, "turn started", message);
|
|
198
|
-
};
|
|
199
200
|
return {
|
|
200
201
|
async emit(turnSequence) {
|
|
201
202
|
try {
|
|
202
203
|
const turn = await readTurn(launch.paths, turnSequence);
|
|
203
204
|
if (turn === null)
|
|
204
205
|
throw new Error(`Committed Turn ${turnSequence} is missing from Heart`);
|
|
205
|
-
await emitPluginSignal(
|
|
206
|
+
await emitPluginSignal(pluginHost(launch, world, "turn started"), {
|
|
206
207
|
kind: "akuma.turn-started",
|
|
207
208
|
akumaId: soul.id,
|
|
208
209
|
turnSequence,
|
|
@@ -216,9 +217,6 @@ function turnStartedEmitter(launch, soul, world) {
|
|
|
216
217
|
};
|
|
217
218
|
}
|
|
218
219
|
function turnOutcomeEmitter(launch, soul, world) {
|
|
219
|
-
const reportDiagnostic = (message) => {
|
|
220
|
-
void recordPluginDiagnostic(launch.paths, "turn outcome", message);
|
|
221
|
-
};
|
|
222
220
|
return {
|
|
223
221
|
async emit(turnSequence) {
|
|
224
222
|
try {
|
|
@@ -227,7 +225,7 @@ function turnOutcomeEmitter(launch, soul, world) {
|
|
|
227
225
|
throw new Error(`Committed Turn ${turnSequence} outcome is missing from Heart`);
|
|
228
226
|
const outcome = turn.end.outcome;
|
|
229
227
|
const participants = await readTurnParticipants(launch.paths, turnSequence);
|
|
230
|
-
await emitPluginSignal(
|
|
228
|
+
await emitPluginSignal(pluginHost(launch, world, "turn outcome"), {
|
|
231
229
|
kind: "akuma.turn-outcome",
|
|
232
230
|
akumaId: soul.id,
|
|
233
231
|
bodySequence: turn.bodySequence,
|
|
@@ -250,9 +248,6 @@ function turnOutcomeEmitter(launch, soul, world) {
|
|
|
250
248
|
};
|
|
251
249
|
}
|
|
252
250
|
function bodyEndEmitter(launch, soul, world) {
|
|
253
|
-
const reportDiagnostic = (message) => {
|
|
254
|
-
void recordPluginDiagnostic(launch.paths, "body end", message);
|
|
255
|
-
};
|
|
256
251
|
return async (bodySequence, end, diagnostic) => {
|
|
257
252
|
try {
|
|
258
253
|
const latestTurn = await readLatestTurnForBody(launch.paths, bodySequence);
|
|
@@ -260,7 +255,7 @@ function bodyEndEmitter(launch, soul, world) {
|
|
|
260
255
|
const at = latestBody?.sequence === bodySequence ? (latestBody.hung?.at ?? latestBody.endedAt) : undefined;
|
|
261
256
|
const initiator = latestTurn?.initiator;
|
|
262
257
|
const participants = latestTurn === null ? [] : await readTurnParticipants(launch.paths, latestTurn.sequence);
|
|
263
|
-
await emitPluginSignal(
|
|
258
|
+
await emitPluginSignal(pluginHost(launch, world, "body end"), {
|
|
264
259
|
kind: "akuma.body-ended",
|
|
265
260
|
akumaId: soul.id,
|
|
266
261
|
bodySequence,
|
|
@@ -70,7 +70,6 @@ export async function admitCallInitialTell(input) {
|
|
|
70
70
|
id: input.initialTell.tellId,
|
|
71
71
|
body: input.initialTell.body,
|
|
72
72
|
recordedAt: input.now?.() ?? new Date().toISOString(),
|
|
73
|
-
...(input.initialTell.schemaJson === undefined ? {} : { schemaJson: input.initialTell.schemaJson }),
|
|
74
73
|
...(input.initialTell.initiator === undefined ? {} : { initiator: input.initialTell.initiator }),
|
|
75
74
|
});
|
|
76
75
|
if (recorded.kind === "not-born")
|
|
@@ -184,6 +184,12 @@ declare const toolEventSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
184
184
|
}, z.core.$strip>]>;
|
|
185
185
|
truncated: z.ZodOptional<z.ZodLiteral<true>>;
|
|
186
186
|
}, z.core.$strip>]>;
|
|
187
|
+
export declare const permissionRequestSchema: z.ZodObject<{
|
|
188
|
+
id: z.ZodString;
|
|
189
|
+
action: z.ZodString;
|
|
190
|
+
resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
|
|
191
|
+
tool: z.ZodOptional<z.ZodString>;
|
|
192
|
+
}, z.core.$strip>;
|
|
187
193
|
export declare const agentEventSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
188
194
|
type: z.ZodLiteral<"session">;
|
|
189
195
|
coordinate: z.ZodUnion<readonly [z.ZodPipe<z.ZodObject<{
|
|
@@ -204,6 +210,15 @@ export declare const agentEventSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
204
210
|
}, z.core.$strip>, z.ZodObject<{
|
|
205
211
|
type: z.ZodLiteral<"model">;
|
|
206
212
|
model: z.ZodOptional<z.ZodString>;
|
|
213
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
214
|
+
type: z.ZodLiteral<"permission">;
|
|
215
|
+
requests: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
216
|
+
id: z.ZodString;
|
|
217
|
+
action: z.ZodString;
|
|
218
|
+
resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
|
|
219
|
+
tool: z.ZodOptional<z.ZodString>;
|
|
220
|
+
}, z.core.$strip>>>;
|
|
221
|
+
truncated: z.ZodOptional<z.ZodLiteral<true>>;
|
|
207
222
|
}, z.core.$strip>, z.ZodObject<{
|
|
208
223
|
type: z.ZodLiteral<"assistant">;
|
|
209
224
|
text: z.ZodString;
|
|
@@ -327,6 +342,7 @@ export declare const agentEventSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
327
342
|
kind: z.ZodString;
|
|
328
343
|
truncated: z.ZodOptional<z.ZodLiteral<true>>;
|
|
329
344
|
}, z.core.$strip>]>;
|
|
345
|
+
export type PermissionRequest = z.infer<typeof permissionRequestSchema>;
|
|
330
346
|
export type SearchScope = z.infer<typeof searchScopeSchema>;
|
|
331
347
|
export type ToolInput = z.infer<typeof toolInputSchema>;
|
|
332
348
|
export type ToolCall = z.infer<typeof toolCallSchema>;
|
|
@@ -42,12 +42,19 @@ const toolEventSchema = z.union([
|
|
|
42
42
|
z.object({ ...toolFields, phase: z.literal("started"), result: z.never().optional() }),
|
|
43
43
|
z.object({ ...toolFields, phase: z.literal("completed"), result: toolResultSchema }),
|
|
44
44
|
]);
|
|
45
|
+
export const permissionRequestSchema = z.object({
|
|
46
|
+
id: text,
|
|
47
|
+
action: text,
|
|
48
|
+
resources: z.array(text).readonly(),
|
|
49
|
+
tool: text.optional(),
|
|
50
|
+
});
|
|
45
51
|
export const agentEventSchema = z.union([
|
|
46
52
|
z.object({ type: z.literal("session"), coordinate: resumeCoordinateSchema }),
|
|
47
53
|
// One provider-neutral runtime-model observation in the shared agent-event
|
|
48
54
|
// vocabulary. Body admits it into the Soul's single current model; it is
|
|
49
55
|
// never appended to activity, so compaction cannot lose or resurrect it.
|
|
50
56
|
z.object({ type: z.literal("model"), model: text.optional() }),
|
|
57
|
+
z.object({ type: z.literal("permission"), requests: z.array(permissionRequestSchema).readonly(), truncated }),
|
|
51
58
|
z.object({ type: z.literal("assistant"), text, truncated }),
|
|
52
59
|
z.object({ type: z.literal("thought"), text, truncated }),
|
|
53
60
|
toolEventSchema,
|
|
@@ -223,6 +223,7 @@ export type SealFact = Readonly<{
|
|
|
223
223
|
}>;
|
|
224
224
|
export type LeashProbe = "held" | "free";
|
|
225
225
|
export type AkumaLife = "running" | "asleep" | "stranded" | "hung" | "untidy" | "killed";
|
|
226
|
+
export declare function akumaLifecycle(life: AkumaLife | "unborn" | "stillborn"): "active" | "settled";
|
|
226
227
|
export type HeartSnapshot = Readonly<{
|
|
227
228
|
soul: Soul | null;
|
|
228
229
|
latestBody: BodyFact | null;
|
|
@@ -58,6 +58,20 @@ export class BodyControlledError extends Error {
|
|
|
58
58
|
this.name = "BodyControlledError";
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
+
export function akumaLifecycle(life) {
|
|
62
|
+
switch (life) {
|
|
63
|
+
case "running":
|
|
64
|
+
case "unborn":
|
|
65
|
+
case "stranded":
|
|
66
|
+
case "hung":
|
|
67
|
+
case "untidy":
|
|
68
|
+
return "active";
|
|
69
|
+
case "asleep":
|
|
70
|
+
case "killed":
|
|
71
|
+
case "stillborn":
|
|
72
|
+
return "settled";
|
|
73
|
+
}
|
|
74
|
+
}
|
|
61
75
|
export function life(input) {
|
|
62
76
|
if (input.body?.hung !== undefined)
|
|
63
77
|
return "hung";
|
|
@@ -56,6 +56,7 @@ export declare function createTimelineReader(paths: AkumaPaths): Readonly<{
|
|
|
56
56
|
/** One observer owns its connection and successful decoded frontier. */
|
|
57
57
|
export declare function createStatusFactReader(paths: AkumaPaths): {
|
|
58
58
|
life: (signal?: AbortSignal) => Promise<LifeSnapshot>;
|
|
59
|
+
wait: (recent: boolean, signal?: AbortSignal) => Promise<WaitFacts>;
|
|
59
60
|
tellOutcome: (id: string, signal?: AbortSignal) => Promise<{
|
|
60
61
|
tell: Readonly<{
|
|
61
62
|
kind: "tell";
|
|
@@ -80,9 +81,14 @@ export declare function createStatusFactReader(paths: AkumaPaths): {
|
|
|
80
81
|
clear(): void;
|
|
81
82
|
read(input: StatusFactInput, signal?: AbortSignal): Promise<ActivitySlice["rows"]>;
|
|
82
83
|
};
|
|
83
|
-
type LifeSnapshot = Pick<HeartSnapshot, "soul" | "latestBody" | "latestSession" | "latestKill"> & Readonly<{
|
|
84
|
+
type LifeSnapshot = Pick<HeartSnapshot, "soul" | "latestBody" | "latestSession" | "latestKill" | "lastActivityAt"> & Readonly<{
|
|
84
85
|
hasPendingTell: boolean;
|
|
85
86
|
}>;
|
|
87
|
+
export type WaitFacts = LifeSnapshot & Readonly<{
|
|
88
|
+
turn: TurnFact | null;
|
|
89
|
+
activity: ActivityFactSlice | undefined;
|
|
90
|
+
activityDiagnostic: string | undefined;
|
|
91
|
+
}>;
|
|
86
92
|
/** Lifecycle probes do not load narration, Tell bodies, or delivery histories. */
|
|
87
93
|
export declare function readLifeSnapshot(paths: AkumaPaths, signal?: AbortSignal, read?: HeartRead): Promise<LifeSnapshot>;
|
|
88
94
|
export type InterruptTellAdmission = Readonly<{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parsePublicHistoryId } from "../identity.js";
|
|
2
2
|
import { decodeRuntimeModel, withoutModel } from "../provider-recipe.js";
|
|
3
3
|
import { BodyControlledError } from "./facts.js";
|
|
4
|
-
import { answeredTurnFact, completeInterruptBarrier as judgeInterruptBarrier, endBodyFact, finishBodyFact, deleteStopControl, insertReportFact, insertActivityFact, insertTurnEndFact, insertTurnStartFact, insertKillFact, insertSessionFact, insertStopControl, killFactForBody, hasBodyHandoffControl, latestBodyFact, insertInterruptBarrier, isTellProtectedByPause, latestKillFact, latestSessionFact, latestTurnFactForBody, lastAnsweredTurnFact, pauseFact, sessionFactForCoordinate, stopFact, turnFact, openTurnsForBody, terminalTurnForTell, } from "./rows.js";
|
|
4
|
+
import { answeredTurnFact, completeInterruptBarrier as judgeInterruptBarrier, endBodyFact, finishBodyFact, deleteStopControl, insertReportFact, insertActivityFact, insertTurnEndFact, insertTurnStartFact, insertKillFact, insertSessionFact, insertStopControl, killFactForBody, hasBodyHandoffControl, latestBodyFact, insertInterruptBarrier, isTellProtectedByPause, latestKillFact, latestSessionFact, latestTurnFactForBody, latestTurnFact, lastAnsweredTurnFact, pauseFact, sessionFactForCoordinate, stopFact, turnFact, openTurnsForBody, terminalTurnForTell, } from "./rows.js";
|
|
5
5
|
import { insertTellDeliveryFact, dispositionSnapshotProven, insertTellBindingFact, insertTellDispositionSnapshot, insertTellReceiptFact, insertUndeliveredTellReceipts, latestOpenTellDisposition, openBoundTurns, openTellDispositionIds, pendingTellFacts, hasPendingTell, resolveTellDispositionSnapshot, sameTellInput, tellDispositionResolved, tellFact, tellIdsForFence, turnParticipants, } from "./tells.js";
|
|
6
6
|
import { activityFactSlice, statusFacts, readStatusBatch, decodeTimelineBatch, timelineDataVersion, lastActivityAt as readLastActivityAt, pruneActivityFacts, } from "./timeline.js";
|
|
7
7
|
import { createHeartReader, isHeartAbsent, readSealFromLeash, recordPendingTell, withHeartTransaction, withReadOnlyHeart, } from "./storage.js";
|
|
@@ -132,6 +132,21 @@ export function createStatusFactReader(paths) {
|
|
|
132
132
|
let memo;
|
|
133
133
|
return {
|
|
134
134
|
life: (signal) => readLifeSnapshot(paths, signal, reader.read),
|
|
135
|
+
wait: (recent, signal) => reader.read((heart) => {
|
|
136
|
+
const snapshot = lifeSnapshot(heart);
|
|
137
|
+
const turn = latestTurnFact(heart);
|
|
138
|
+
let activity;
|
|
139
|
+
let activityDiagnostic;
|
|
140
|
+
if (recent) {
|
|
141
|
+
try {
|
|
142
|
+
activity = activityFactSlice(heart);
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
activityDiagnostic = error instanceof Error ? error.message : String(error);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { ...snapshot, turn, activity, activityDiagnostic };
|
|
149
|
+
}, signal),
|
|
135
150
|
tellOutcome: (id, signal) => reader.read((heart) => {
|
|
136
151
|
const tell = tellFact(heart, id);
|
|
137
152
|
// A pending Tell may be retried by a successor after cancellation. Its
|
|
@@ -163,20 +178,31 @@ export function createStatusFactReader(paths) {
|
|
|
163
178
|
},
|
|
164
179
|
};
|
|
165
180
|
}
|
|
181
|
+
function lifeSnapshot(heart) {
|
|
182
|
+
return {
|
|
183
|
+
soul: soulFact(heart),
|
|
184
|
+
latestBody: latestBodyFact(heart),
|
|
185
|
+
latestSession: latestSessionFact(heart),
|
|
186
|
+
latestKill: latestKillFact(heart),
|
|
187
|
+
hasPendingTell: hasPendingTell(heart),
|
|
188
|
+
lastActivityAt: readLastActivityAt(heart),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
166
191
|
/** Lifecycle probes do not load narration, Tell bodies, or delivery histories. */
|
|
167
192
|
export async function readLifeSnapshot(paths, signal, read = (body, signal) => withReadOnlyHeart(paths, body, signal)) {
|
|
168
193
|
try {
|
|
169
|
-
return await read(
|
|
170
|
-
soul: soulFact(heart),
|
|
171
|
-
latestBody: latestBodyFact(heart),
|
|
172
|
-
latestSession: latestSessionFact(heart),
|
|
173
|
-
latestKill: latestKillFact(heart),
|
|
174
|
-
hasPendingTell: hasPendingTell(heart),
|
|
175
|
-
}), signal);
|
|
194
|
+
return await read(lifeSnapshot, signal);
|
|
176
195
|
}
|
|
177
196
|
catch (error) {
|
|
178
197
|
if (isHeartAbsent(error))
|
|
179
|
-
return {
|
|
198
|
+
return {
|
|
199
|
+
soul: null,
|
|
200
|
+
latestBody: null,
|
|
201
|
+
latestSession: null,
|
|
202
|
+
latestKill: null,
|
|
203
|
+
hasPendingTell: false,
|
|
204
|
+
lastActivityAt: null,
|
|
205
|
+
};
|
|
180
206
|
throw error;
|
|
181
207
|
}
|
|
182
208
|
}
|
|
@@ -189,4 +189,5 @@ export declare function killFactForBody(database: DatabaseSync, bodySequence: nu
|
|
|
189
189
|
export declare function lastAnsweredTurnFact(database: DatabaseSync): TurnFact | null;
|
|
190
190
|
export declare function answeredTurnFact(database: DatabaseSync, turnSequence: number): TurnFact | null;
|
|
191
191
|
export declare function latestTurnFactForBody(database: DatabaseSync, bodySequence: number): TurnFact | null;
|
|
192
|
+
export declare function latestTurnFact(database: DatabaseSync): TurnFact | null;
|
|
192
193
|
export declare function turnFact(database: DatabaseSync, turnSequence: number): TurnFact | null;
|
|
@@ -428,6 +428,10 @@ export function latestTurnFactForBody(database, bodySequence) {
|
|
|
428
428
|
.get(bodySequence);
|
|
429
429
|
return row === undefined ? null : decodeTurnRow(row);
|
|
430
430
|
}
|
|
431
|
+
export function latestTurnFact(database) {
|
|
432
|
+
const latest = database.prepare("SELECT sequence FROM turns ORDER BY sequence DESC LIMIT 1").get();
|
|
433
|
+
return latest === undefined ? null : turnFact(database, latest.sequence);
|
|
434
|
+
}
|
|
431
435
|
export function turnFact(database, turnSequence) {
|
|
432
436
|
const row = database
|
|
433
437
|
.prepare(`SELECT sequence, body_sequence, started_at, end_sequence, outcome, history_id,
|
|
@@ -3,20 +3,17 @@ import { decodeTellBatch, tellBatchAtSequences, tellStateSql, pendingTellProtect
|
|
|
3
3
|
export function lastActivityAt(database) {
|
|
4
4
|
const row = database
|
|
5
5
|
.prepare(`SELECT CASE timeline.kind
|
|
6
|
-
WHEN 'turn-start' THEN started_turn.started_at
|
|
7
6
|
WHEN 'call' THEN calls.at
|
|
8
7
|
WHEN 'activity' THEN activity.at
|
|
9
8
|
WHEN 'report' THEN reports.at
|
|
10
9
|
WHEN 'tell' THEN tells.recorded_at
|
|
11
|
-
WHEN 'turn-end' THEN ended_turn.completed_at
|
|
12
10
|
END AS at
|
|
13
11
|
FROM timeline
|
|
14
|
-
LEFT JOIN turns AS started_turn ON timeline.kind = 'turn-start' AND started_turn.sequence = timeline.sequence
|
|
15
12
|
LEFT JOIN calls ON timeline.kind = 'call' AND calls.sequence = timeline.sequence
|
|
16
13
|
LEFT JOIN activity ON timeline.kind = 'activity' AND activity.sequence = timeline.sequence
|
|
17
14
|
LEFT JOIN reports ON timeline.kind = 'report' AND reports.sequence = timeline.sequence
|
|
18
15
|
LEFT JOIN tells ON timeline.kind = 'tell' AND tells.sequence = timeline.sequence
|
|
19
|
-
|
|
16
|
+
WHERE timeline.kind IN ('call', 'activity', 'report', 'tell')
|
|
20
17
|
ORDER BY timeline.sequence DESC LIMIT 1`)
|
|
21
18
|
.get();
|
|
22
19
|
if (row === undefined || row.at === null)
|
|
@@ -48,6 +45,9 @@ export function pruneActivityFacts(database, limit, protectionReleased = false)
|
|
|
48
45
|
UNION ${pendingTellProtectionSql}
|
|
49
46
|
), protected(sequence) AS (
|
|
50
47
|
SELECT sequence FROM protected_turns
|
|
48
|
+
UNION SELECT MAX(sequence) FROM activity
|
|
49
|
+
WHERE turn_sequence IN (SELECT sequence FROM turns WHERE end_sequence IS NULL)
|
|
50
|
+
AND json_extract(event_json, '$.type') = 'permission' GROUP BY turn_sequence
|
|
51
51
|
UNION SELECT sequence FROM calls WHERE turn_sequence IN (SELECT sequence FROM protected_turns)
|
|
52
52
|
UNION SELECT end_sequence FROM turns WHERE sequence IN (SELECT sequence FROM protected_turns) AND end_sequence IS NOT NULL
|
|
53
53
|
UNION ${pendingTellSequencesSql}
|
|
@@ -7,13 +7,17 @@ import type { WorldRoot } from "../world.js";
|
|
|
7
7
|
* rebuilt from Hearts, and an unavailable cache falls back to direct Soul reads.
|
|
8
8
|
*/
|
|
9
9
|
export type AkumaLineage = ReadonlyMap<AkumaId, AkumaCaller | null>;
|
|
10
|
+
type LineageObservation = Readonly<{
|
|
11
|
+
edges: AkumaLineage;
|
|
12
|
+
skipped: number;
|
|
13
|
+
}>;
|
|
10
14
|
export type LineageMember = Readonly<{
|
|
11
15
|
id: AkumaId;
|
|
12
16
|
paths: AkumaPaths;
|
|
13
17
|
}>;
|
|
14
18
|
export declare function akumaLineageCachePath(world: WorldRoot): string;
|
|
15
19
|
/** Authoritative lineage read: every known born Soul, with no cache consultation. */
|
|
16
|
-
export declare function readDirectAkumaLineage(members: readonly LineageMember[]): Promise<
|
|
20
|
+
export declare function readDirectAkumaLineage(members: readonly LineageMember[]): Promise<LineageObservation>;
|
|
17
21
|
/**
|
|
18
22
|
* Discard the disposable record when an offered edge disagrees with a born
|
|
19
23
|
* Soul. The next caller-scoped answer comes from direct Soul evidence and
|
|
@@ -36,4 +40,5 @@ export declare function recordAkumaLineage(world: WorldRoot, soul: Readonly<{
|
|
|
36
40
|
* Rows whose Akuma directory no longer exists never join this view, and fresh
|
|
37
41
|
* edges plus that pruning are written back best-effort.
|
|
38
42
|
*/
|
|
39
|
-
export declare function readAkumaLineage(world: WorldRoot, members: readonly LineageMember[]): Promise<
|
|
43
|
+
export declare function readAkumaLineage(world: WorldRoot, members: readonly LineageMember[]): Promise<LineageObservation>;
|
|
44
|
+
export {};
|
|
@@ -31,14 +31,14 @@ function readCachedEdge(row) {
|
|
|
31
31
|
throw new Error("Akuma lineage cache row has an empty caller");
|
|
32
32
|
return [akumaId, caller];
|
|
33
33
|
}
|
|
34
|
-
/**
|
|
35
|
-
async function readLineageCache(path) {
|
|
34
|
+
/** Decode only current members; obsolete and invalid rows are disposable misses. */
|
|
35
|
+
async function readLineageCache(path, known) {
|
|
36
36
|
try {
|
|
37
37
|
await lstat(path);
|
|
38
38
|
}
|
|
39
39
|
catch (error) {
|
|
40
40
|
if (error.code === "ENOENT")
|
|
41
|
-
return new Map();
|
|
41
|
+
return { edges: new Map(), stale: [] };
|
|
42
42
|
return null;
|
|
43
43
|
}
|
|
44
44
|
let database;
|
|
@@ -53,7 +53,24 @@ async function readLineageCache(path) {
|
|
|
53
53
|
try {
|
|
54
54
|
database.exec("PRAGMA busy_timeout=0");
|
|
55
55
|
const rows = database.prepare("SELECT aku_id, caller_json FROM lineage").all();
|
|
56
|
-
|
|
56
|
+
const edges = new Map();
|
|
57
|
+
const stale = [];
|
|
58
|
+
for (const row of rows) {
|
|
59
|
+
if (typeof row.aku_id !== "string")
|
|
60
|
+
continue;
|
|
61
|
+
if (known.has(row.aku_id)) {
|
|
62
|
+
try {
|
|
63
|
+
const [id, caller] = readCachedEdge(row);
|
|
64
|
+
edges.set(id, caller);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// A malformed current edge is a miss, not a reason to discard peers.
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
stale.push(row.aku_id);
|
|
72
|
+
}
|
|
73
|
+
return { edges, stale };
|
|
57
74
|
}
|
|
58
75
|
catch {
|
|
59
76
|
return null;
|
|
@@ -76,10 +93,10 @@ async function writeLineageCache(path, fresh, stale, replace = false) {
|
|
|
76
93
|
try {
|
|
77
94
|
if (replace)
|
|
78
95
|
database.exec("DELETE FROM lineage");
|
|
79
|
-
for (const [akumaId, caller] of fresh)
|
|
80
|
-
insert.run(akumaId, caller === null ? null : JSON.stringify(caller));
|
|
81
96
|
for (const akumaId of stale)
|
|
82
97
|
remove.run(akumaId);
|
|
98
|
+
for (const [akumaId, caller] of fresh)
|
|
99
|
+
insert.run(akumaId, caller === null ? null : JSON.stringify(caller));
|
|
83
100
|
database.exec("COMMIT");
|
|
84
101
|
}
|
|
85
102
|
catch (error) {
|
|
@@ -98,16 +115,22 @@ async function writeLineageCache(path, fresh, stale, replace = false) {
|
|
|
98
115
|
async function directEdge(member) {
|
|
99
116
|
try {
|
|
100
117
|
const soul = await readSoul(member.paths);
|
|
118
|
+
if (soul !== null && soul.id !== member.id)
|
|
119
|
+
throw new Error("Akuma soul does not match its coordinate");
|
|
101
120
|
return soul === null ? null : [member.id, soul.caller ?? null];
|
|
102
121
|
}
|
|
103
122
|
catch {
|
|
104
|
-
//
|
|
105
|
-
return
|
|
123
|
+
// Unreadability is not authoritative absence and cannot justify a rebuild.
|
|
124
|
+
return undefined;
|
|
106
125
|
}
|
|
107
126
|
}
|
|
108
127
|
/** Authoritative lineage read: every known born Soul, with no cache consultation. */
|
|
109
128
|
export async function readDirectAkumaLineage(members) {
|
|
110
|
-
|
|
129
|
+
const observed = await boundedMap(members, directEdge);
|
|
130
|
+
return {
|
|
131
|
+
edges: new Map(observed.filter((edge) => edge !== null && edge !== undefined)),
|
|
132
|
+
skipped: observed.filter((edge) => edge === undefined).length,
|
|
133
|
+
};
|
|
111
134
|
}
|
|
112
135
|
/**
|
|
113
136
|
* Discard the disposable record when an offered edge disagrees with a born
|
|
@@ -144,19 +167,20 @@ export async function recordAkumaLineage(world, soul) {
|
|
|
144
167
|
*/
|
|
145
168
|
export async function readAkumaLineage(world, members) {
|
|
146
169
|
const path = akumaLineageCachePath(world);
|
|
147
|
-
const cached = await readLineageCache(path);
|
|
148
|
-
if (cached === null)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
170
|
+
const cached = await readLineageCache(path, new Set(members.map((member) => member.id)));
|
|
171
|
+
if (cached === null) {
|
|
172
|
+
const direct = await readDirectAkumaLineage(members);
|
|
173
|
+
if (direct.skipped === 0) {
|
|
174
|
+
await invalidateAkumaLineage(world);
|
|
175
|
+
await rebuildAkumaLineage(world, direct.edges);
|
|
176
|
+
}
|
|
177
|
+
return direct;
|
|
178
|
+
}
|
|
179
|
+
const missing = members.filter((member) => !cached.edges.has(member.id));
|
|
180
|
+
const fresh = await readDirectAkumaLineage(missing);
|
|
181
|
+
for (const [akumaId, caller] of fresh.edges)
|
|
182
|
+
cached.edges.set(akumaId, caller);
|
|
183
|
+
if (fresh.edges.size > 0 || cached.stale.length > 0)
|
|
184
|
+
await writeLineageCache(path, [...fresh.edges], cached.stale);
|
|
185
|
+
return { edges: cached.edges, skipped: fresh.skipped };
|
|
162
186
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { ActivitySnapshot, TurnLedger } from "./projection.js";
|
|
1
|
+
import type { ActivitySnapshot, HistoryCursor, HistoryPage, TurnLedger } from "./projection.js";
|
|
2
2
|
export declare const DEFAULT_TAIL = 3;
|
|
3
3
|
/** Present the same snapshot without its reported-change summary. */
|
|
4
4
|
export declare function withoutReportedChanges(snapshot: ActivitySnapshot): ActivitySnapshot;
|
|
5
|
-
|
|
5
|
+
/** Raw reported spellings on the current frontier, before containment partitioning. */
|
|
6
|
+
export declare function reportedChangePaths(ledger: TurnLedger): readonly string[];
|
|
6
7
|
export declare function selectSnapshot(ledger: TurnLedger, input: Readonly<{
|
|
7
8
|
aperture: "monitoring" | "receipt";
|
|
8
9
|
budget?: Readonly<{
|
|
@@ -10,6 +11,7 @@ export declare function selectSnapshot(ledger: TurnLedger, input: Readonly<{
|
|
|
10
11
|
}>;
|
|
11
12
|
executionDir?: string;
|
|
12
13
|
admittedTellId?: string;
|
|
14
|
+
canonicalize?: (absolutePath: string) => string;
|
|
13
15
|
}>): Readonly<{
|
|
14
16
|
snapshot: ActivitySnapshot;
|
|
15
17
|
ordinaryCount: number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { selectHistoryPage } from "../history.js";
|
|
1
2
|
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
2
3
|
export const DEFAULT_TAIL = 3;
|
|
3
4
|
const REPORTED_CHANGE_LIMIT = 5;
|
|
@@ -74,12 +75,13 @@ function aggregateReportedChanges(changes) {
|
|
|
74
75
|
? { path: group.path, diffstat: { added: group.added, removed: group.removed } }
|
|
75
76
|
: { path: group.path });
|
|
76
77
|
}
|
|
77
|
-
function summarizeReportedChanges(rows, executionDir) {
|
|
78
|
+
function summarizeReportedChanges(rows, executionDir, canonicalize) {
|
|
78
79
|
const files = aggregateReportedChanges(flattenReportedChanges(rows));
|
|
79
80
|
const inside = files.filter((change) => {
|
|
80
81
|
if (executionDir === undefined)
|
|
81
82
|
return true;
|
|
82
|
-
const
|
|
83
|
+
const absolute = resolve(executionDir, change.path);
|
|
84
|
+
const path = relative(executionDir, canonicalize === undefined ? absolute : canonicalize(absolute));
|
|
83
85
|
return path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
|
|
84
86
|
});
|
|
85
87
|
const outside = files.length - inside.length;
|
|
@@ -89,11 +91,18 @@ function summarizeReportedChanges(rows, executionDir) {
|
|
|
89
91
|
...(outside === 0 ? {} : { reportedChangesOutside: outside }),
|
|
90
92
|
};
|
|
91
93
|
}
|
|
92
|
-
function
|
|
94
|
+
function frontierRows(ledger) {
|
|
93
95
|
if (ledger.openTurn !== undefined)
|
|
94
|
-
return
|
|
96
|
+
return ledger.openTurn.rows;
|
|
95
97
|
const closed = ledger.turns.findLast((turn) => turn.kind === "closed");
|
|
96
|
-
return closed
|
|
98
|
+
return closed?.rows ?? [];
|
|
99
|
+
}
|
|
100
|
+
function frontierReportedChanges(ledger, executionDir, canonicalize) {
|
|
101
|
+
return summarizeReportedChanges(frontierRows(ledger), executionDir, canonicalize);
|
|
102
|
+
}
|
|
103
|
+
/** Raw reported spellings on the current frontier, before containment partitioning. */
|
|
104
|
+
export function reportedChangePaths(ledger) {
|
|
105
|
+
return flattenReportedChanges(frontierRows(ledger)).map((change) => change.path);
|
|
97
106
|
}
|
|
98
107
|
function isPendingTell(row) {
|
|
99
108
|
return row.kind === "tell" && row.state === "pending";
|
|
@@ -128,22 +137,21 @@ export function selectSnapshot(ledger, input) {
|
|
|
128
137
|
const tailCount = Math.min(DEFAULT_TAIL, Math.max(0, input.budget?.tail ?? DEFAULT_TAIL));
|
|
129
138
|
if (ledger.turns.length === 0 && !ledger.rows.some((row) => row.kind === "tell"))
|
|
130
139
|
return { snapshot: { kind: "unborn", entries: [], ...EMPTY_REPORTED }, ordinaryCount: 0 };
|
|
140
|
+
const receiptTellId = input.aperture === "receipt" ? input.admittedTellId : undefined;
|
|
131
141
|
const pending = ledger.rows.filter(isPendingTell);
|
|
132
|
-
const admittedTell =
|
|
133
|
-
?
|
|
134
|
-
:
|
|
135
|
-
const pins =
|
|
136
|
-
|
|
137
|
-
? []
|
|
138
|
-
: [admittedTell]
|
|
139
|
-
: pending;
|
|
140
|
-
const reported = frontierReportedChanges(ledger, input.executionDir);
|
|
142
|
+
const admittedTell = receiptTellId === undefined
|
|
143
|
+
? undefined
|
|
144
|
+
: ledger.rows.find((row) => row.kind === "tell" && row.tellId === receiptTellId);
|
|
145
|
+
const pins = receiptTellId === undefined ? pending : admittedTell === undefined ? [] : [admittedTell];
|
|
146
|
+
const reported = frontierReportedChanges(ledger, input.executionDir, input.canonicalize);
|
|
141
147
|
if (ledger.openTurn !== undefined) {
|
|
142
148
|
const window = currentTurnWindow(ledger);
|
|
143
149
|
const opening = openingInput(ledger);
|
|
144
150
|
const latestSaid = window.findLast((row) => row.kind === "said");
|
|
151
|
+
const permission = window.findLast((row) => row.kind === "permission");
|
|
145
152
|
const pinSet = new Set([
|
|
146
153
|
...window.filter(isProtectedTool),
|
|
154
|
+
...(permission === undefined ? [] : [permission]),
|
|
147
155
|
...(latestSaid === undefined ? [] : [latestSaid]),
|
|
148
156
|
...pins,
|
|
149
157
|
...(opening === undefined ? [] : [opening]),
|
|
@@ -173,21 +181,15 @@ export function selectSnapshot(ledger, input) {
|
|
|
173
181
|
};
|
|
174
182
|
}
|
|
175
183
|
export function selectHistory(ledger, cursor) {
|
|
176
|
-
const
|
|
177
|
-
? row.sequence < cursor.before
|
|
178
|
-
: cursor.since !== undefined
|
|
179
|
-
? row.sequence > cursor.since
|
|
180
|
-
: true);
|
|
181
|
-
const rows = cursor.since !== undefined ? eligible.slice(0, cursor.limit) : eligible.slice(-cursor.limit);
|
|
182
|
-
const omitted = Math.max(0, eligible.length - rows.length);
|
|
184
|
+
const { rows, omitted } = selectHistoryPage(ledger.rows, (row) => row.sequence, cursor);
|
|
183
185
|
const historyLost = cursor.since !== undefined
|
|
184
186
|
? ledger.rows[0] !== undefined && ledger.rows[0].sequence > cursor.since + 1
|
|
185
187
|
: ledger.retained.lowestRetained !== null && ledger.retained.lowestRetained > 1 && omitted === 0;
|
|
186
188
|
return {
|
|
187
189
|
rows,
|
|
188
190
|
omitted,
|
|
189
|
-
hasEarlier: cursor.since === undefined &&
|
|
190
|
-
hasLater: cursor.since !== undefined &&
|
|
191
|
+
hasEarlier: cursor.since === undefined && omitted > 0,
|
|
192
|
+
hasLater: cursor.since !== undefined && omitted > 0,
|
|
191
193
|
historyLost,
|
|
192
194
|
lowestRetained: ledger.retained.lowestRetained,
|
|
193
195
|
highest: ledger.retained.highest,
|