@astrosheep/keiyaku 4.6.31 → 4.6.32
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 +34 -17
- package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +16 -11
- package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +5 -3
- package/build/plugins/claude/skills/keiyaku-bind/SKILL.md +4 -3
- package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +17 -17
- package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +16 -11
- package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +5 -3
- package/build/plugins/codex/skills/keiyaku-bind/SKILL.md +4 -3
- package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +17 -17
- package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +16 -11
- package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +5 -3
- package/build/plugins/opencode/skills/keiyaku-bind/SKILL.md +4 -3
- package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +17 -17
- package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/plugins/pi/README.md +16 -18
- package/build/plugins/pi/akuma-tools.ts +31 -38
- package/build/plugins/pi/keiyaku.ts +15 -4
- package/build/skills/keiyaku-akuma/SKILL.md +16 -11
- package/build/skills/keiyaku-babysit/SKILL.md +5 -3
- package/build/skills/keiyaku-bind/SKILL.md +4 -3
- package/build/skills/keiyaku-debt/SKILL.md +17 -17
- package/build/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/src/akuma/akuma-call.d.ts +3 -5
- package/build/src/akuma/akuma-call.js +7 -10
- package/build/src/akuma/akuma-errors.d.ts +7 -4
- package/build/src/akuma/akuma-errors.js +16 -12
- package/build/src/akuma/akuma-instance.d.ts +39 -303
- package/build/src/akuma/akuma-instance.js +48 -48
- package/build/src/akuma/akuma-observe.d.ts +5 -4
- package/build/src/akuma/akuma-observe.js +1 -7
- package/build/src/akuma/akuma-owner.d.ts +14 -6
- package/build/src/akuma/akuma-owner.js +33 -27
- package/build/src/akuma/akuma-selection-execution.d.ts +22 -19
- package/build/src/akuma/akuma-selection-execution.js +71 -124
- package/build/src/akuma/akuma-wait.d.ts +3 -3
- package/build/src/akuma/akuma.d.ts +47 -384
- package/build/src/akuma/akuma.js +8 -58
- package/build/src/akuma/archetype.d.ts +16 -19
- package/build/src/akuma/archetype.js +48 -49
- package/build/src/akuma/body.js +31 -26
- package/build/src/akuma/call-initial-tell.d.ts +4 -1
- package/build/src/akuma/call-initial-tell.js +9 -1
- package/build/src/akuma/call-input.d.ts +8 -1
- package/build/src/akuma/call-input.js +27 -18
- package/build/src/akuma/caller.js +2 -1
- package/build/src/akuma/detached-body.js +1 -1
- package/build/src/akuma/heart/facts.d.ts +5 -4
- package/build/src/akuma/heart/facts.js +5 -5
- package/build/src/akuma/heart/soul.js +20 -4
- package/build/src/akuma/identity.d.ts +1 -1
- package/build/src/akuma/identity.js +9 -4
- package/build/src/akuma/index.d.ts +6 -7
- package/build/src/akuma/index.js +2 -3
- package/build/src/akuma/projection.d.ts +3 -0
- package/build/src/akuma/provider-recipe.js +3 -2
- package/build/src/akuma/providers/acp/config.js +11 -10
- package/build/src/akuma/providers/acp/index.js +2 -1
- package/build/src/akuma/providers/codex-app-server/index.js +7 -1
- package/build/src/akuma/providers/grok-build/index.js +2 -1
- package/build/src/akuma/providers/index.d.ts +0 -1
- package/build/src/akuma/providers/index.js +0 -8
- package/build/src/akuma/providers/paseo/index.js +7 -4
- package/build/src/akuma/providers/pi/index.js +4 -3
- package/build/src/akuma/publication.d.ts +1 -2
- package/build/src/akuma/publication.js +16 -14
- package/build/src/akuma/schema.d.ts +3 -49
- package/build/src/akuma/schema.js +6 -147
- package/build/src/akuma/selection-observation.d.ts +281 -240
- package/build/src/akuma/selection-observation.js +122 -68
- package/build/src/akuma/status-projection.d.ts +49 -285
- package/build/src/akuma/status-projection.js +178 -138
- package/build/src/body/amend.js +2 -1
- package/build/src/body/arc.js +3 -2
- package/build/src/body/criteria.js +4 -3
- package/build/src/body/decode.js +2 -1
- package/build/src/body/envelope.js +2 -1
- package/build/src/body/region.d.ts +1 -3
- package/build/src/body/region.js +3 -8
- package/build/src/body-host.d.ts +4 -11
- package/build/src/body-host.js +5 -4
- package/build/src/bounded-list.js +2 -1
- package/build/src/cli/commands/akuma-grammar.d.ts +109 -66
- package/build/src/cli/commands/akuma-grammar.js +75 -95
- package/build/src/cli/commands/akuma.d.ts +8 -3
- package/build/src/cli/commands/akuma.js +63 -122
- package/build/src/cli/commands/contract-grammar.d.ts +3 -135
- package/build/src/cli/commands/contract-grammar.js +125 -218
- package/build/src/cli/commands/contract-help.d.ts +24 -21
- package/build/src/cli/commands/contract-help.js +43 -35
- package/build/src/cli/commands/contract.d.ts +6 -18
- package/build/src/cli/commands/contract.js +65 -272
- package/build/src/cli/commands/debt-grammar.d.ts +2 -4
- package/build/src/cli/commands/debt-grammar.js +22 -190
- package/build/src/cli/commands/debt.js +10 -87
- package/build/src/cli/commands/report.d.ts +2 -4
- package/build/src/cli/coordinates.d.ts +1 -1
- package/build/src/cli/coordinates.js +1 -1
- package/build/src/cli/main.js +9 -3
- package/build/src/cli/parse.d.ts +80 -3
- package/build/src/cli/parse.js +76 -16
- package/build/src/cli/render/akuma-activity.d.ts +19 -24
- package/build/src/cli/render/akuma-activity.js +164 -259
- package/build/src/cli/render/akuma.d.ts +3 -3
- package/build/src/cli/render/akuma.js +36 -43
- package/build/src/cli/render/catalog.d.ts +2 -5
- package/build/src/cli/render/catalog.js +2 -33
- package/build/src/cli/render/contract-history.js +1 -2
- package/build/src/cli/render/contract-observation.d.ts +0 -7
- package/build/src/cli/render/contract-observation.js +0 -3
- package/build/src/cli/render/contract.d.ts +7 -9
- package/build/src/cli/render/contract.js +35 -64
- package/build/src/cli/render/debt.d.ts +3 -11
- package/build/src/cli/render/debt.js +17 -88
- package/build/src/cli/render/delivery-preview.js +4 -4
- package/build/src/cli/render/kanshi-akuma.d.ts +5 -3
- package/build/src/cli/render/kanshi-akuma.js +22 -18
- package/build/src/cli/render/kanshi.d.ts +1 -3
- package/build/src/cli/render/kanshi.js +16 -39
- package/build/src/cli/render/receipt.d.ts +21 -12
- package/build/src/cli/render/receipt.js +49 -44
- package/build/src/cli/render/refusal.d.ts +4 -3
- package/build/src/cli/render/refusal.js +15 -17
- package/build/src/cli/render/settings.d.ts +1 -1
- package/build/src/cli/render/terminal.d.ts +9 -8
- package/build/src/cli/render/terminal.js +48 -32
- package/build/src/cli/render/verbs.d.ts +3 -1
- package/build/src/cli/render/verbs.js +74 -116
- package/build/src/cli/runtime.js +66 -65
- package/build/src/cli/streams.d.ts +2 -9
- package/build/src/cli/streams.js +8 -1
- package/build/src/cli/usage.d.ts +2 -1
- package/build/src/cli/usage.js +3 -2
- package/build/src/contract-worktree.js +2 -10
- package/build/src/core/facts/codec.js +9 -23
- package/build/src/core/facts/errors.d.ts +2 -1
- package/build/src/core/facts/errors.js +3 -3
- package/build/src/core/facts/types.d.ts +2 -13
- package/build/src/core/facts/types.js +1 -6
- package/build/src/core/verbs/abandon.d.ts +1 -2
- package/build/src/core/verbs/amend.d.ts +1 -2
- package/build/src/core/verbs/arc.d.ts +1 -2
- package/build/src/core/verbs/attestation.d.ts +1 -2
- package/build/src/core/verbs/bind.d.ts +1 -2
- package/build/src/core/verbs/deliver.d.ts +1 -2
- package/build/src/core/verbs/placement.d.ts +1 -2
- package/build/src/core/verbs/reintegrate.d.ts +1 -2
- package/build/src/debt/board.d.ts +14 -94
- package/build/src/debt/board.js +25 -160
- package/build/src/debt/catalog.d.ts +0 -2
- package/build/src/debt/catalog.js +1 -22
- package/build/src/debt/document.d.ts +8 -11
- package/build/src/debt/document.js +19 -62
- package/build/src/debt/identity.d.ts +2 -14
- package/build/src/debt/identity.js +19 -49
- package/build/src/debt/index.d.ts +81 -219
- package/build/src/debt/index.js +61 -110
- package/build/src/debt/input.d.ts +19 -5
- package/build/src/debt/input.js +51 -177
- package/build/src/debt/lifecycle-operations.d.ts +1 -3
- package/build/src/debt/lifecycle-operations.js +1 -73
- package/build/src/debt/operation-types.d.ts +24 -128
- package/build/src/debt/operation-types.js +6 -62
- package/build/src/debt/operations.d.ts +8 -17
- package/build/src/debt/operations.js +58 -154
- package/build/src/debt/store.d.ts +0 -2
- package/build/src/debt/store.js +32 -87
- package/build/src/errors.d.ts +28 -0
- package/build/src/errors.js +26 -0
- package/build/src/git/hooks.d.ts +1 -1
- package/build/src/git/observe.d.ts +3 -0
- package/build/src/git/observe.js +19 -5
- package/build/src/git/reconcile.d.ts +3 -16
- package/build/src/git/reconcile.js +0 -18
- package/build/src/git/repository.d.ts +2 -1
- package/build/src/git/repository.js +3 -3
- package/build/src/git/target-placement.d.ts +4 -4
- package/build/src/git/target.d.ts +2 -2
- package/build/src/git/tender.d.ts +1 -2
- package/build/src/git/tender.js +5 -12
- package/build/src/identity/coordinates.d.ts +1 -1
- package/build/src/identity/coordinates.js +3 -2
- package/build/src/identity/normalize.js +2 -1
- package/build/src/identity/selector.js +4 -3
- package/build/src/index.d.ts +34 -57
- package/build/src/index.js +11 -36
- package/build/src/kanshi/counts.d.ts +3 -8
- package/build/src/kanshi/counts.js +6 -14
- package/build/src/kanshi/index.d.ts +22 -7
- package/build/src/kanshi/index.js +30 -4
- package/build/src/kanshi/read.d.ts +81 -270
- package/build/src/kanshi/read.js +39 -199
- package/build/src/kanshi/report.d.ts +340 -1619
- package/build/src/kanshi/report.js +19 -31
- package/build/src/library/address.d.ts +11 -11
- package/build/src/library/address.js +34 -27
- package/build/src/library/akuma-creation.d.ts +210 -79
- package/build/src/library/akuma-creation.js +201 -242
- package/build/src/library/akumas.d.ts +24 -5
- package/build/src/library/akumas.js +96 -29
- package/build/src/library/bind.d.ts +7 -10
- package/build/src/library/bind.js +2 -8
- package/build/src/library/continuation.d.ts +141 -231
- package/build/src/library/continuation.js +22 -31
- package/build/src/library/contract-address.d.ts +6 -9
- package/build/src/library/contract-address.js +11 -16
- package/build/src/library/contract-composition.d.ts +2 -3
- package/build/src/library/contract-composition.js +12 -19
- package/build/src/library/contract-creation.js +33 -34
- package/build/src/library/contract-outcomes.d.ts +1278 -806
- package/build/src/library/contract-outcomes.js +11 -37
- package/build/src/library/contract-settings.d.ts +1 -2
- package/build/src/library/contract-settings.js +5 -7
- package/build/src/library/contract-types.d.ts +42 -67
- package/build/src/library/contract-types.js +15 -56
- package/build/src/library/contract-wait.d.ts +40 -3
- package/build/src/library/contract-wait.js +28 -21
- package/build/src/library/delivery.d.ts +366 -389
- package/build/src/library/delivery.js +5 -25
- package/build/src/library/input.d.ts +31 -5
- package/build/src/library/input.js +40 -40
- package/build/src/library/invocation.d.ts +13 -11
- package/build/src/library/invocation.js +69 -58
- package/build/src/library/kei.d.ts +16 -8
- package/build/src/library/kei.js +459 -19
- package/build/src/library/keiyaku-attribution.d.ts +0 -8
- package/build/src/library/keiyaku-attribution.js +0 -11
- package/build/src/library/keiyaku-classify.d.ts +2 -2
- package/build/src/library/keiyaku-classify.js +40 -59
- package/build/src/library/keiyaku-coordinates.d.ts +3 -8
- package/build/src/library/keiyaku-coordinates.js +6 -26
- package/build/src/library/keiyaku-debt.d.ts +21 -93
- package/build/src/library/keiyaku-debt.js +8 -157
- package/build/src/library/keiyaku-identity.js +5 -4
- package/build/src/library/keiyaku-verbs.d.ts +4004 -3885
- package/build/src/library/keiyaku-verbs.js +309 -271
- package/build/src/library/keiyaku.d.ts +30 -860
- package/build/src/library/keiyaku.js +169 -256
- package/build/src/library/nuke.d.ts +4 -2
- package/build/src/library/nuke.js +5 -1
- package/build/src/library/outcome.d.ts +424 -307
- package/build/src/library/outcome.js +167 -362
- package/build/src/library/reconcile.d.ts +331 -143
- package/build/src/library/reconcile.js +38 -72
- package/build/src/library/refusal.d.ts +20 -28
- package/build/src/library/refusal.js +1 -11
- package/build/src/library/repo.js +4 -3
- package/build/src/library/selection.d.ts +32 -21
- package/build/src/library/selection.js +63 -87
- package/build/src/mcp/adapter.d.ts +6 -0
- package/build/src/mcp/adapter.js +177 -42
- package/build/src/mcp/help.d.ts +1 -1
- package/build/src/mcp/help.js +12 -7
- package/build/src/mcp/output.d.ts +385 -0
- package/build/src/mcp/output.js +193 -0
- package/build/src/plugin/public.d.ts +4 -0
- package/build/src/plugin/runtime.d.ts +1 -1
- package/build/src/plugin/runtime.js +2 -2
- package/build/src/protocol/amend.d.ts +1 -1
- package/build/src/protocol/amend.js +2 -2
- package/build/src/protocol/bind.d.ts +5 -7
- package/build/src/protocol/bind.js +3 -3
- package/build/src/protocol/completion.d.ts +158 -195
- package/build/src/protocol/completion.js +55 -19
- package/build/src/protocol/deliver.d.ts +11 -6
- package/build/src/protocol/deliver.js +30 -30
- package/build/src/protocol/delivery-preview.d.ts +13 -11
- package/build/src/protocol/delivery-preview.js +2 -2
- package/build/src/protocol/execution-observation.d.ts +5 -13
- package/build/src/protocol/intent.d.ts +6 -9
- package/build/src/protocol/intent.js +18 -31
- package/build/src/protocol/operations.d.ts +48 -53
- package/build/src/protocol/operations.js +16 -25
- package/build/src/protocol/outcome.d.ts +3 -1
- package/build/src/protocol/placement.d.ts +1 -2
- package/build/src/protocol/placement.js +1 -1
- package/build/src/protocol/progress.d.ts +1 -0
- package/build/src/protocol/read/status.d.ts +29 -112
- package/build/src/protocol/read/status.js +52 -78
- package/build/src/protocol/reintegrate.d.ts +1 -2
- package/build/src/protocol/reintegrate.js +0 -1
- package/build/src/protocol/result-leaves.d.ts +11 -32
- package/build/src/protocol/result-leaves.js +18 -57
- package/build/src/protocol/result-reasons.d.ts +6 -6
- package/build/src/protocol/review.js +0 -1
- package/build/src/protocol/verify.d.ts +192 -146
- package/build/src/protocol/verify.js +60 -47
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/build/src/settings.d.ts +8 -9
- package/build/src/settings.js +16 -13
- package/build/src/settlement/holder.js +2 -2
- package/build/src/settlement/settle.d.ts +0 -6
- package/build/src/settlement/settle.js +0 -4
- package/build/src/verification/declaration.d.ts +3 -6
- package/build/src/verification/declaration.js +3 -5
- package/build/src/verification/observation.d.ts +2 -2
- package/build/src/world.d.ts +3 -2
- package/build/src/world.js +5 -6
- package/package.json +1 -1
- package/plugins/paseo/plugin/index.server.ts +1 -1
- package/plugins/paseo/plugin/server/attach.ts +74 -67
- package/plugins/paseo/plugin/server/keiyaku.ts +80 -14
- package/plugins/paseo/plugin/server/message.ts +2 -1
- package/plugins/paseo/plugin/server/mirror-identity.ts +6 -4
- package/plugins/paseo/plugin/server/sdk.ts +9 -11
- package/plugins/paseo/plugin/server/transport.ts +24 -1
- package/plugins/pi/README.md +16 -18
- package/plugins/pi/akuma-tools.ts +31 -38
- package/plugins/pi/keiyaku.ts +15 -4
- package/skills/keiyaku-akuma/SKILL.md +16 -11
- package/skills/keiyaku-babysit/SKILL.md +5 -3
- package/skills/keiyaku-bind/SKILL.md +4 -3
- package/skills/keiyaku-debt/SKILL.md +17 -17
- package/skills/keiyaku-workflow/SKILL.md +4 -3
- package/build/src/akuma/providers/codex-app-server/configuration.d.ts +0 -5
- package/build/src/akuma/providers/codex-app-server/configuration.js +0 -72
- package/build/src/cli/commands/debt-query.d.ts +0 -5
- package/build/src/cli/commands/debt-query.js +0 -194
- package/build/src/cli/render/akuma-tool-command.d.ts +0 -6
- package/build/src/cli/render/akuma-tool-command.js +0 -143
- package/build/src/cli/render/akuma-tool.d.ts +0 -29
- package/build/src/cli/render/akuma-tool.js +0 -225
- package/build/src/debt/context.d.ts +0 -28
- package/build/src/debt/context.js +0 -102
- package/build/src/debt/created-observation.d.ts +0 -26
- package/build/src/debt/created-observation.js +0 -38
- package/build/src/debt/query.d.ts +0 -80
- package/build/src/debt/query.js +0 -283
- package/build/src/library/contract-execution.d.ts +0 -28
- package/build/src/library/contract-execution.js +0 -506
- package/build/src/library/keiyaku-policy.d.ts +0 -27
- package/build/src/library/keiyaku-policy.js +0 -44
- package/build/src/library/keiyaku-status.d.ts +0 -1487
- package/build/src/library/keiyaku-status.js +0 -92
|
@@ -7,14 +7,14 @@ import { prepareDelivery, deliveryIntegrationSnapshots } from "./deliver.js";
|
|
|
7
7
|
import { verifyRequirement } from "./intent.js";
|
|
8
8
|
import { timestamp, unpackVerificationOutcome } from "./operations.js";
|
|
9
9
|
import { executionStop } from "./progress.js";
|
|
10
|
-
import {
|
|
10
|
+
import { placementSchema, normalPlacementSchema } from "./completion.js";
|
|
11
11
|
import { activeReasonSchema, retrySchema, compactRetry, compactReason } from "./result-reasons.js";
|
|
12
12
|
const checkCoordinate = {
|
|
13
13
|
index: z.number().int().positive(),
|
|
14
14
|
requirement: z.string().min(1),
|
|
15
15
|
retainedPath: z.string().exactOptional(),
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
const runtimeStopSchema = z.union([
|
|
18
18
|
z
|
|
19
19
|
.strictObject({ kind: z.enum(["unknown-exit", "cancelled"]), diagnostic: z.string().min(1).exactOptional() })
|
|
20
20
|
.readonly(),
|
|
@@ -32,36 +32,58 @@ export const runtimeStopSchema = z.union([
|
|
|
32
32
|
})
|
|
33
33
|
.readonly(),
|
|
34
34
|
]);
|
|
35
|
-
|
|
35
|
+
const checkAdmissionStopSchema = z
|
|
36
|
+
.union([
|
|
36
37
|
z.strictObject({ kind: z.literal("refused"), reason: activeReasonSchema }).readonly(),
|
|
37
38
|
...retrySchema.options,
|
|
38
39
|
z.strictObject({ kind: z.literal("cancelled") }).readonly(),
|
|
40
|
+
])
|
|
41
|
+
.meta({ id: "verificationAdmissionStop" });
|
|
42
|
+
const normalAdmissionSchema = z.enum(["admitted", "reused", "unrecorded"]);
|
|
43
|
+
export function verificationAdmissionOutcome(admission) {
|
|
44
|
+
switch (admission) {
|
|
45
|
+
case "admitted":
|
|
46
|
+
case "reused":
|
|
47
|
+
case "unrecorded":
|
|
48
|
+
return "benign";
|
|
49
|
+
default:
|
|
50
|
+
switch (admission.kind) {
|
|
51
|
+
case "retry":
|
|
52
|
+
return "retry";
|
|
53
|
+
case "refused":
|
|
54
|
+
case "cancelled":
|
|
55
|
+
return "failed";
|
|
56
|
+
default: {
|
|
57
|
+
const exhaustive = admission;
|
|
58
|
+
return exhaustive;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function terminalCheckSchemas(admission) {
|
|
64
|
+
const terminal = { ...checkCoordinate, kind: z.literal("terminal"), admission };
|
|
65
|
+
return [
|
|
66
|
+
z.strictObject({ ...terminal, verdict: z.literal("satisfied") }).readonly(),
|
|
67
|
+
z.strictObject({ ...terminal, verdict: z.literal("unsatisfied"), summary: z.string() }).readonly(),
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
const normalVerificationCheckSchema = z.union(terminalCheckSchemas(normalAdmissionSchema));
|
|
71
|
+
const verificationCheckSchema = z.union([
|
|
72
|
+
...terminalCheckSchemas(z.union([normalAdmissionSchema, checkAdmissionStopSchema])),
|
|
73
|
+
z.strictObject({ ...checkCoordinate, kind: z.literal("stopped"), stop: runtimeStopSchema }).readonly(),
|
|
39
74
|
]);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export const verificationCheckSchema = z.union([
|
|
43
|
-
z
|
|
44
|
-
.strictObject({ ...checkCoordinate, kind: z.literal("terminal"), verdict: z.literal("satisfied"), admission })
|
|
45
|
-
.readonly(),
|
|
46
|
-
z
|
|
75
|
+
function verifyValue(check, placement) {
|
|
76
|
+
return z
|
|
47
77
|
.strictObject({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
summary: z.string(),
|
|
52
|
-
admission,
|
|
78
|
+
snapshot: snapshotIdSchema,
|
|
79
|
+
checks: z.array(check).readonly(),
|
|
80
|
+
placement: placement.exactOptional(),
|
|
53
81
|
})
|
|
54
|
-
.readonly()
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
export const verifyValueSchema =
|
|
58
|
-
|
|
59
|
-
snapshot: snapshotIdSchema,
|
|
60
|
-
checks: z.array(verificationCheckSchema).readonly(),
|
|
61
|
-
placement: placementSchema.exactOptional(),
|
|
62
|
-
})
|
|
63
|
-
.readonly();
|
|
64
|
-
export function compactVerificationStop(stop) {
|
|
82
|
+
.readonly();
|
|
83
|
+
}
|
|
84
|
+
export const verifyNormalValueSchema = verifyValue(normalVerificationCheckSchema, normalPlacementSchema);
|
|
85
|
+
export const verifyValueSchema = verifyValue(verificationCheckSchema, placementSchema);
|
|
86
|
+
function compactVerificationStop(stop) {
|
|
65
87
|
if ("refusal" in stop)
|
|
66
88
|
return { kind: "refused", reason: compactReason(stop.refusal) };
|
|
67
89
|
if ("retry" in stop)
|
|
@@ -81,14 +103,6 @@ export function compactVerificationStop(stop) {
|
|
|
81
103
|
return { kind: stop.failure, diagnostic: stop.diagnostic };
|
|
82
104
|
}
|
|
83
105
|
}
|
|
84
|
-
export function compactVerify(value) {
|
|
85
|
-
const placement = compactPlacement(value);
|
|
86
|
-
return {
|
|
87
|
-
snapshot: value.snapshot,
|
|
88
|
-
checks: value.checks,
|
|
89
|
-
...(placement === undefined ? {} : { placement }),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
106
|
async function prepareVerification(input) {
|
|
93
107
|
input.signal?.throwIfAborted();
|
|
94
108
|
const observed = await observeGitForAdmissionAt(input.scope, input.channel, [input.contractId]);
|
|
@@ -102,8 +116,6 @@ async function prepareVerification(input) {
|
|
|
102
116
|
if (derivation.verification.kind === "refused")
|
|
103
117
|
return { kind: "refused", refusal: derivation.verification.refusal };
|
|
104
118
|
const definition = derivation.verification.data;
|
|
105
|
-
if (definition === null)
|
|
106
|
-
return { kind: "refused", refusal: { kind: "verification-not-selected" } };
|
|
107
119
|
if (input.index !== undefined && input.index > definition.declarations.length)
|
|
108
120
|
return {
|
|
109
121
|
kind: "refused",
|
|
@@ -124,7 +136,6 @@ async function prepareVerification(input) {
|
|
|
124
136
|
document: derivation.bytes,
|
|
125
137
|
includeDirty: input.includeDirty,
|
|
126
138
|
requireBranchesToBeUpToDate: input.requireBranchesToBeUpToDate,
|
|
127
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
128
139
|
});
|
|
129
140
|
if (prepared.kind === "refused")
|
|
130
141
|
return prepared;
|
|
@@ -139,15 +150,13 @@ function checkReport(coordinate, checked) {
|
|
|
139
150
|
const stop = compactVerificationStop(checked.stop);
|
|
140
151
|
if (stop.kind === "refused" || stop.kind === "retry")
|
|
141
152
|
throw new Error("nonterminal check requires a runtime stop");
|
|
142
|
-
return { ...fields,
|
|
153
|
+
return { ...fields, kind: "stopped", stop };
|
|
143
154
|
}
|
|
144
|
-
// A terminal verdict only proves admission when custody holds the matching attestation, reuse, or stop.
|
|
145
|
-
const attested = checked.admission?.facts.some((fact) => fact.kind === "attestation" && fact.data.gate === VERIFIED && fact.data.requirement === requirement);
|
|
146
155
|
let admission;
|
|
147
156
|
if (checked.reuse !== undefined)
|
|
148
157
|
admission = "reused";
|
|
149
|
-
else if (
|
|
150
|
-
admission =
|
|
158
|
+
else if (checked.admission !== undefined)
|
|
159
|
+
admission = "admitted";
|
|
151
160
|
else if (checked.stop !== undefined) {
|
|
152
161
|
const stop = compactVerificationStop(checked.stop);
|
|
153
162
|
if (stop.kind === "refused" || stop.kind === "retry")
|
|
@@ -158,15 +167,15 @@ function checkReport(coordinate, checked) {
|
|
|
158
167
|
throw new Error("terminal check admission can only refuse, retry or cancel");
|
|
159
168
|
}
|
|
160
169
|
else
|
|
161
|
-
|
|
162
|
-
const terminal = { ...fields, kind: "terminal",
|
|
170
|
+
admission = "unrecorded";
|
|
171
|
+
const terminal = { ...fields, kind: "terminal", admission };
|
|
163
172
|
if (checked.counts.verdict === "satisfied")
|
|
164
173
|
return { ...terminal, verdict: "satisfied" };
|
|
165
174
|
if (checked.counts.summary === undefined)
|
|
166
175
|
throw new Error("unsatisfied terminal check requires its diagnosis");
|
|
167
176
|
return { ...terminal, verdict: "unsatisfied", summary: checked.counts.summary };
|
|
168
177
|
}
|
|
169
|
-
/** Capture a prospective delivery
|
|
178
|
+
/** Capture a prospective delivery, then independently execute each selected declaration. */
|
|
170
179
|
export async function verifyOperation(input) {
|
|
171
180
|
const prepared = await prepareVerification(input);
|
|
172
181
|
if (prepared.kind === "refused")
|
|
@@ -190,13 +199,13 @@ export async function verifyOperation(input) {
|
|
|
190
199
|
channel: input.channel,
|
|
191
200
|
repository: input.scope,
|
|
192
201
|
contractId: state.id,
|
|
202
|
+
gates: state.terms.gates,
|
|
193
203
|
at: timestamp(),
|
|
194
204
|
snapshot,
|
|
195
205
|
declaration,
|
|
196
206
|
requirement,
|
|
197
207
|
index,
|
|
198
208
|
total: definition.declarations.length,
|
|
199
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
200
209
|
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
201
210
|
...(input.progress === undefined ? {} : { progress: input.progress }),
|
|
202
211
|
});
|
|
@@ -214,5 +223,9 @@ export async function verifyOperation(input) {
|
|
|
214
223
|
if (checked.stop !== undefined)
|
|
215
224
|
break;
|
|
216
225
|
}
|
|
217
|
-
return {
|
|
226
|
+
return {
|
|
227
|
+
kind: "accepted",
|
|
228
|
+
...(state.terms.gates.includes(VERIFIED) ? { checkpoint } : {}),
|
|
229
|
+
value: { snapshot, checks },
|
|
230
|
+
};
|
|
218
231
|
}
|
|
Binary file
|
package/build/src/settings.d.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
+
import { KeiyakuError } from "./errors.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
export type SettingsScope = "project" | "user";
|
|
3
4
|
export type SettingsScopeState = z.output<typeof settingsScopeStateSchema>;
|
|
4
5
|
export type SettingsEntry = z.output<typeof settingsEntrySchema>;
|
|
5
6
|
export type SettingsNamespaceFailure = z.output<typeof settingsNamespaceFailureSchema>;
|
|
6
7
|
export type SettingsNamespaceView = z.output<typeof settingsNamespaceViewSchema>;
|
|
7
|
-
export type Settings = Readonly<{
|
|
8
|
-
scopes: Readonly<{
|
|
9
|
-
project: SettingsScopeState;
|
|
10
|
-
user: SettingsScopeState;
|
|
11
|
-
}>;
|
|
12
|
-
namespaces?: Readonly<Record<string, SettingsNamespaceView>>;
|
|
8
|
+
export type Settings = z.output<typeof settingsSchema> & Readonly<{
|
|
13
9
|
namespace(name: string): SettingsNamespaceView;
|
|
14
10
|
}>;
|
|
15
11
|
export declare const settingsScopeStateSchema: z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
@@ -132,14 +128,17 @@ export declare const settingsSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
132
128
|
}>>>>>;
|
|
133
129
|
}, z.core.$strict>>;
|
|
134
130
|
export type SettingsInput = Readonly<{
|
|
135
|
-
|
|
131
|
+
cwd?: string;
|
|
136
132
|
home?: string;
|
|
137
133
|
}>;
|
|
138
|
-
export declare class SettingsError extends
|
|
134
|
+
export declare class SettingsError extends KeiyakuError {
|
|
139
135
|
readonly kind = "settings";
|
|
140
136
|
constructor(message: string);
|
|
141
137
|
}
|
|
142
|
-
|
|
138
|
+
declare function loadSettings(input?: SettingsInput): Promise<Settings>;
|
|
139
|
+
export declare const Settings: Readonly<{
|
|
140
|
+
load: typeof loadSettings;
|
|
141
|
+
}>;
|
|
143
142
|
/** Read only the project scope owned by a materialized candidate snapshot. */
|
|
144
143
|
export declare function projectSettings(root: string): Promise<Settings>;
|
|
145
144
|
export {};
|
package/build/src/settings.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KeiyakuError } from "./errors.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { readFile, realpath } from "node:fs/promises";
|
|
3
4
|
import { homedir } from "node:os";
|
|
@@ -60,11 +61,10 @@ export const settingsSchema = z
|
|
|
60
61
|
namespaces: keyedValues(settingsNamespaceViewSchema).exactOptional(),
|
|
61
62
|
})
|
|
62
63
|
.readonly();
|
|
63
|
-
export class SettingsError extends
|
|
64
|
+
export class SettingsError extends KeiyakuError {
|
|
64
65
|
kind = "settings";
|
|
65
66
|
constructor(message) {
|
|
66
|
-
super(message);
|
|
67
|
-
this.name = "SettingsError";
|
|
67
|
+
super("invalid-input", message);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
function object(value) {
|
|
@@ -155,7 +155,7 @@ function settingsFromScopes(project, user) {
|
|
|
155
155
|
}
|
|
156
156
|
function namespace(name) {
|
|
157
157
|
if (typeof name !== "string" || name.trim().length === 0)
|
|
158
|
-
throw new
|
|
158
|
+
throw new KeiyakuError("invalid-input", "settings namespace must be nonblank");
|
|
159
159
|
return resolveNamespace(name);
|
|
160
160
|
}
|
|
161
161
|
const names = [...new Set([user, project].flatMap((scope) => Object.keys(scope.root ?? {})))].sort();
|
|
@@ -176,16 +176,18 @@ async function canonicalCoordinate(path) {
|
|
|
176
176
|
return resolvedPath;
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
|
-
|
|
179
|
+
async function loadSettings(input = {}) {
|
|
180
180
|
if (!object(input))
|
|
181
|
-
throw new
|
|
182
|
-
|
|
183
|
-
|
|
181
|
+
throw new KeiyakuError("invalid-input", "settings input must be an object");
|
|
182
|
+
for (const key of Object.keys(input))
|
|
183
|
+
if (key !== "cwd" && key !== "home")
|
|
184
|
+
throw new KeiyakuError("invalid-input", `settings input has unknown field: ${key}`);
|
|
185
|
+
for (const field of ["cwd", "home"]) {
|
|
186
|
+
const value = input[field];
|
|
187
|
+
if (value !== undefined && (typeof value !== "string" || value.trim().length === 0))
|
|
188
|
+
throw new KeiyakuError("invalid-input", `settings ${field} must be a nonblank string`);
|
|
184
189
|
}
|
|
185
|
-
|
|
186
|
-
throw new TypeError("settings home must be a nonblank string");
|
|
187
|
-
}
|
|
188
|
-
const projectDirectory = input.root === undefined ? undefined : await canonicalCoordinate(join(input.root, ".keiyaku"));
|
|
190
|
+
const projectDirectory = input.cwd === undefined ? undefined : await canonicalCoordinate(join(input.cwd, ".keiyaku"));
|
|
189
191
|
const userDirectory = await canonicalCoordinate(input.home ?? join(homedir(), ".keiyaku"));
|
|
190
192
|
const project = projectDirectory === undefined || projectDirectory === userDirectory
|
|
191
193
|
? { state: { kind: "absent" } }
|
|
@@ -193,10 +195,11 @@ export async function settings(input = {}) {
|
|
|
193
195
|
const user = await readScope(join(userDirectory, "settings.json"));
|
|
194
196
|
return settingsFromScopes(project, user);
|
|
195
197
|
}
|
|
198
|
+
export const Settings = Object.freeze({ load: loadSettings });
|
|
196
199
|
/** Read only the project scope owned by a materialized candidate snapshot. */
|
|
197
200
|
export async function projectSettings(root) {
|
|
198
201
|
if (typeof root !== "string" || root.trim().length === 0)
|
|
199
|
-
throw new
|
|
202
|
+
throw new KeiyakuError("invalid-input", "settings root must be a nonblank string");
|
|
200
203
|
return settingsFromScopes(await readScope(join(resolve(root), ".keiyaku", "settings.json")), {
|
|
201
204
|
state: { kind: "absent" },
|
|
202
205
|
});
|
|
@@ -4,7 +4,7 @@ import { contractId } from "../core/facts/types.js";
|
|
|
4
4
|
import { GIT_REF, updateGitTree, updateRefsAtomically, writeBlob, writeStateCommit } from "../git/repository.js";
|
|
5
5
|
import { confirmPrivateStatePublication } from "../git/private-state-seat.js";
|
|
6
6
|
import { withGitTargetedReadObservation, } from "../git/read-observation.js";
|
|
7
|
-
import {
|
|
7
|
+
import { canonicalDebtId } from "../debt/identity.js";
|
|
8
8
|
import { acquireDebtSettlementFence } from "./fence.js";
|
|
9
9
|
// The private persisted spelling predates the product rename. Keep its bytes
|
|
10
10
|
// and path stable so an existing held association still settles after upgrade.
|
|
@@ -58,7 +58,7 @@ function decodeHolder(path, bytes) {
|
|
|
58
58
|
let owner;
|
|
59
59
|
try {
|
|
60
60
|
debtId = `debt/${record.taskId.slice("task/".length)}`;
|
|
61
|
-
|
|
61
|
+
canonicalDebtId(debtId);
|
|
62
62
|
owner = contractId(record.contractId);
|
|
63
63
|
}
|
|
64
64
|
catch (error) {
|
|
@@ -54,11 +54,5 @@ export type SettlementInput = Readonly<{
|
|
|
54
54
|
effects: readonly Effect[];
|
|
55
55
|
progress?: SettlementProgress;
|
|
56
56
|
}>;
|
|
57
|
-
export type SettlementBatchInput = Readonly<{
|
|
58
|
-
repository: GitRepository;
|
|
59
|
-
channel: GitDecodeChannel;
|
|
60
|
-
contracts: readonly Readonly<Pick<SettlementInput, "state" | "effects">>[];
|
|
61
|
-
}>;
|
|
62
57
|
export declare function settle(input: SettlementInput): Promise<SettlementReport>;
|
|
63
|
-
export declare function settleAll(input: SettlementBatchInput): Promise<readonly SettlementReport[]>;
|
|
64
58
|
export {};
|
|
@@ -295,7 +295,3 @@ export async function settle(input) {
|
|
|
295
295
|
const repository = onPrimaryWorktree(input.repository);
|
|
296
296
|
return await settleObserved({ ...input, repository });
|
|
297
297
|
}
|
|
298
|
-
export async function settleAll(input) {
|
|
299
|
-
const repository = onPrimaryWorktree(input.repository);
|
|
300
|
-
return await Promise.all(input.contracts.map((contract) => settleObserved({ repository, channel: input.channel, ...contract })));
|
|
301
|
-
}
|
|
@@ -13,13 +13,10 @@ export type VerificationDefinition = Readonly<{
|
|
|
13
13
|
export type VerificationDeclarationRefusal = Readonly<{
|
|
14
14
|
kind: "verification-declaration-invalid";
|
|
15
15
|
}>;
|
|
16
|
-
export type VerificationDeclarationPreparation = Preparation<VerificationDefinition
|
|
17
|
-
export declare const VERIFIED:
|
|
16
|
+
export type VerificationDeclarationPreparation = Preparation<VerificationDefinition, VerificationDeclarationRefusal>;
|
|
17
|
+
export declare const VERIFIED: string;
|
|
18
18
|
/** The display index and surrounding document never participate in execution identity. */
|
|
19
19
|
export declare function verificationRequirement(declaration: VerificationDeclaration): RequirementId;
|
|
20
20
|
export declare function singletonRequirement(declaredGate: Gate): RequirementId;
|
|
21
21
|
export declare function gateRequirements(gates: readonly Gate[], definition: VerificationDefinition | null): Readonly<Record<string, readonly RequirementId[]>>;
|
|
22
|
-
export declare function prepareVerificationDeclaration(
|
|
23
|
-
gates: readonly Gate[];
|
|
24
|
-
definition: VerificationDefinition | null;
|
|
25
|
-
}>): VerificationDeclarationPreparation;
|
|
22
|
+
export declare function prepareVerificationDeclaration(definition: VerificationDefinition | null): VerificationDeclarationPreparation;
|
|
@@ -17,11 +17,9 @@ export function gateRequirements(gates, definition) {
|
|
|
17
17
|
: [singletonRequirement(declaredGate)],
|
|
18
18
|
]));
|
|
19
19
|
}
|
|
20
|
-
export function prepareVerificationDeclaration(
|
|
21
|
-
if (
|
|
22
|
-
return { kind: "prepared", data:
|
|
23
|
-
if (input.definition !== null && input.definition.declarations.length > 0)
|
|
24
|
-
return { kind: "prepared", data: input.definition };
|
|
20
|
+
export function prepareVerificationDeclaration(definition) {
|
|
21
|
+
if (definition !== null && definition.declarations.length > 0)
|
|
22
|
+
return { kind: "prepared", data: definition };
|
|
25
23
|
return {
|
|
26
24
|
kind: "refused",
|
|
27
25
|
refusal: { kind: "verification-declaration-invalid" },
|
|
@@ -7,8 +7,8 @@ export declare const verificationObservationSchema: z.ZodDiscriminatedUnion<[z.Z
|
|
|
7
7
|
outcome: z.ZodExactOptional<z.ZodString>;
|
|
8
8
|
elapsedMs: z.ZodExactOptional<z.ZodNumber>;
|
|
9
9
|
phase: z.ZodEnum<{
|
|
10
|
-
cleanup: "cleanup";
|
|
11
10
|
materialize: "materialize";
|
|
11
|
+
cleanup: "cleanup";
|
|
12
12
|
setup: "setup";
|
|
13
13
|
declaration: "declaration";
|
|
14
14
|
}>;
|
|
@@ -27,8 +27,8 @@ export declare const verificationObservationSchema: z.ZodDiscriminatedUnion<[z.Z
|
|
|
27
27
|
}>;
|
|
28
28
|
text: z.ZodString;
|
|
29
29
|
phase: z.ZodEnum<{
|
|
30
|
-
cleanup: "cleanup";
|
|
31
30
|
materialize: "materialize";
|
|
31
|
+
cleanup: "cleanup";
|
|
32
32
|
setup: "setup";
|
|
33
33
|
declaration: "declaration";
|
|
34
34
|
}>;
|
package/build/src/world.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KeiyakuError } from "./errors.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
declare const WORLD_BRAND: unique symbol;
|
|
3
4
|
export type WorldRoot = string & {
|
|
@@ -19,11 +20,11 @@ export type WorldResolution = Readonly<{
|
|
|
19
20
|
candidate: WorldRoot | null;
|
|
20
21
|
establish: () => Promise<WorldRoot>;
|
|
21
22
|
}>;
|
|
22
|
-
export declare class WorldError extends
|
|
23
|
+
export declare class WorldError extends KeiyakuError {
|
|
23
24
|
readonly kind: "invalid-world";
|
|
24
25
|
constructor(message: string);
|
|
25
26
|
}
|
|
26
|
-
type WorldInput = string | WorldResolutionInput;
|
|
27
|
+
export type WorldInput = string | WorldResolutionInput;
|
|
27
28
|
export declare const World: Readonly<{
|
|
28
29
|
resolve(input: WorldInput): Promise<WorldResolution>;
|
|
29
30
|
locate(input: WorldInput): Promise<WorldRoot | null>;
|
package/build/src/world.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KeiyakuError } from "./errors.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { lstat, mkdir, realpath, stat } from "node:fs/promises";
|
|
3
4
|
import { dirname, join, parse, resolve } from "node:path";
|
|
@@ -8,17 +9,15 @@ export const worldResolutionSchema = z
|
|
|
8
9
|
.readonly();
|
|
9
10
|
export const worldLocationSchema = worldRootSchema.nullable();
|
|
10
11
|
export const worldEstablishedSchema = z.boolean();
|
|
11
|
-
export class WorldError extends
|
|
12
|
+
export class WorldError extends KeiyakuError {
|
|
12
13
|
kind = "invalid-world";
|
|
13
14
|
constructor(message) {
|
|
14
|
-
super(message);
|
|
15
|
-
this.name = "WorldError";
|
|
16
|
-
this.kind = "invalid-world";
|
|
15
|
+
super("internal", message);
|
|
17
16
|
}
|
|
18
17
|
}
|
|
19
18
|
async function directory(input, label) {
|
|
20
19
|
if (typeof input !== "string" || input.trim().length === 0) {
|
|
21
|
-
throw new
|
|
20
|
+
throw new KeiyakuError("invalid-input", `${label} must be a nonblank path`);
|
|
22
21
|
}
|
|
23
22
|
const path = resolve(input);
|
|
24
23
|
let real;
|
|
@@ -61,7 +60,7 @@ async function inputValues(input, label) {
|
|
|
61
60
|
if (typeof input === "string")
|
|
62
61
|
return { cwd: await directory(input, label) };
|
|
63
62
|
if (input === null || typeof input !== "object")
|
|
64
|
-
throw new
|
|
63
|
+
throw new KeiyakuError("invalid-input", `${label} must be a path or resolution input`);
|
|
65
64
|
const cwd = await directory(input.cwd, `${label} cwd`);
|
|
66
65
|
if (input.repositoryRoot === undefined)
|
|
67
66
|
return { cwd };
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@ export default function contribute(server: PluginServerContext) {
|
|
|
14
14
|
const mirror = createProvider(transport, handoff);
|
|
15
15
|
server.registerProvider(mirror.provider);
|
|
16
16
|
server.handle(refreshRpc, (input, context) => refreshOrReopen(context.paseo, input, mirror.refresh));
|
|
17
|
-
server.handle(attachRpc, (input, context) => attach(input, context));
|
|
17
|
+
server.handle(attachRpc, (input, context) => attach(input, context, transport.status));
|
|
18
18
|
const removeModelCorrection = registerModelCorrection(server, transport.status);
|
|
19
19
|
const removeHooks = registerRegistrationHooks(server, handoff);
|
|
20
20
|
return async () => {
|
|
@@ -3,87 +3,94 @@ import type { PaseoAgent } from "@getpaseo/client";
|
|
|
3
3
|
import type { PluginHandlerContext } from "@getpaseo/plugin/server";
|
|
4
4
|
import type { z } from "zod";
|
|
5
5
|
import type { attachRpc } from "../shared/attach-rpc.js";
|
|
6
|
+
import { raceAbort, type StatusReader } from "./transport.js";
|
|
6
7
|
import { listMirrorCandidates, matchesCanonicalMirror } from "./mirror-identity.js";
|
|
7
8
|
|
|
9
|
+
type Input = z.output<typeof attachRpc.input>;
|
|
10
|
+
const MAX_ANCESTRY = 32;
|
|
11
|
+
|
|
8
12
|
function skip(reason: string) {
|
|
9
13
|
console.warn(`Keiyaku mirror not attached: ${reason}`);
|
|
10
14
|
return { attached: false };
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
|
|
17
|
+
/** Each attempt owns its ancestry; daemon creation owns concurrency/idempotency. */
|
|
18
|
+
export async function attach(input: Input, { paseo }: PluginHandlerContext, readStatus?: StatusReader) {
|
|
19
|
+
const seen = new Set<string>();
|
|
20
|
+
// The installed RPC context has no cancellation signal. Fence local custody
|
|
21
|
+
// with a deadline; list supports cancellation, refresh/create do not.
|
|
22
|
+
const signal = AbortSignal.timeout(4000);
|
|
23
|
+
async function ensure(target: Input): Promise<{ attached: boolean }> {
|
|
24
|
+
signal.throwIfAborted();
|
|
25
|
+
const world = await realpath(target.world);
|
|
26
|
+
const key = `keiyaku:${world}:${target.akuId}`;
|
|
27
|
+
if (seen.has(key) || seen.size >= MAX_ANCESTRY) return skip("cyclic or excessively deep Akuma caller ancestry");
|
|
28
|
+
seen.add(key);
|
|
29
|
+
// Include archived/detached children: host intent forbids a replacement or reparent.
|
|
30
|
+
const existing = await listMirrorCandidates(paseo, world, target.akuId, true, signal);
|
|
31
|
+
if (existing.length > 1) return skip(`ambiguous mirror for ${target.akuId}`);
|
|
32
|
+
if (existing.length === 1) return { attached: true };
|
|
33
|
+
|
|
34
|
+
let caller = target.caller;
|
|
35
|
+
if (caller === undefined && readStatus !== undefined) {
|
|
36
|
+
const retained = (await readStatus(world, target.akuId, signal)).caller;
|
|
37
|
+
caller = retained?.kind === "akuma"
|
|
38
|
+
? { kind: "akuma", world: retained.world, akuId: retained.akumaId } : retained;
|
|
39
|
+
}
|
|
40
|
+
if (caller?.kind === "akuma") {
|
|
41
|
+
const parentWorld = await realpath(caller.world);
|
|
42
|
+
let candidates = await listMirrorCandidates(paseo, parentWorld, caller.akuId, true, signal);
|
|
43
|
+
if (candidates.length === 0 && readStatus !== undefined) {
|
|
44
|
+
if (!(await ensure({ world: parentWorld, akuId: caller.akuId })).attached) return { attached: false };
|
|
45
|
+
candidates = await listMirrorCandidates(paseo, parentWorld, caller.akuId, true, signal);
|
|
46
|
+
}
|
|
47
|
+
if (candidates.length !== 1) return skip(candidates.length
|
|
48
|
+
? `ambiguous Akuma parent ${caller.akuId}: multiple mirrors`
|
|
49
|
+
: `no mirror for Akuma parent ${caller.akuId}`);
|
|
50
|
+
const parent = await raceAbort(signal, () => paseo.agents.ref(candidates[0]!.id).refresh());
|
|
51
|
+
if (!parent) return skip(`Akuma parent mirror ${candidates[0]!.id} does not exist`);
|
|
52
|
+
if (parent.agent.archivedAt) return skip(`Akuma parent mirror ${parent.agent.id} is archived`);
|
|
53
|
+
if (parent.agent.id !== candidates[0]!.id || !(await matchesCanonicalMirror(parent.agent, parentWorld, caller.akuId)))
|
|
54
|
+
return skip(`Akuma parent mirror ${parent.agent.id} changed identity`);
|
|
55
|
+
return create(world, target.akuId, parent.agent);
|
|
56
|
+
}
|
|
57
|
+
if (caller?.kind !== "external") return skip("caller is not an external host");
|
|
58
|
+
if (!["codex", "pi", "claude"].includes(caller.integration))
|
|
59
|
+
return skip(`unsupported caller integration ${caller.integration}`);
|
|
60
|
+
const matches = (agent: Pick<PaseoAgent, "persistence">) =>
|
|
61
|
+
agent.persistence?.sessionId === caller.id &&
|
|
62
|
+
(agent.persistence.metadata?.provider ?? agent.persistence.provider) === caller.integration;
|
|
21
63
|
const candidates: string[] = [];
|
|
64
|
+
const cursors = new Set<string>();
|
|
22
65
|
let cursor: string | undefined;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const page = await paseo.agents.list({ filter
|
|
66
|
+
for (;;) {
|
|
67
|
+
signal.throwIfAborted();
|
|
68
|
+
const page = await raceAbort(signal, () => paseo.agents.list({ filter: { includeArchived: true, includeBackground: true }, signal,
|
|
69
|
+
page: { limit: 200, ...(cursor ? { cursor } : {}) } }));
|
|
26
70
|
for (const { agent } of page.entries) if (matches(agent)) candidates.push(agent.id);
|
|
27
71
|
if (candidates.length > 1) return skip(`ambiguous ${caller.integration} session ${caller.id}: multiple parents`);
|
|
28
72
|
if (!page.pageInfo.hasMore) break;
|
|
29
73
|
const next = page.pageInfo.nextCursor;
|
|
30
|
-
if (!next || next
|
|
74
|
+
if (!next || cursors.has(next)) return skip("incomplete parent directory pagination");
|
|
75
|
+
cursors.add(next);
|
|
31
76
|
cursor = next;
|
|
32
|
-
}
|
|
77
|
+
}
|
|
33
78
|
if (!candidates[0]) return skip(`no parent for ${caller.integration} session ${caller.id}`);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return skip(`
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (!parent) return skip(`parent ${parentId} does not exist`);
|
|
40
|
-
if (parent.agent.archivedAt) return skip(`parent ${parentId} is archived`);
|
|
41
|
-
if (native && !matches(parent.agent)) return skip(`parent ${parentId} changed native identity`);
|
|
42
|
-
const world = await realpath(input.world);
|
|
43
|
-
// Keep the creation fingerprint immutable: aliases belong to the forwarder's
|
|
44
|
-
// rename path, not this idempotent request (including retries after rename).
|
|
45
|
-
await paseo.agents.create({ parent: parentId, cwd: parent.agent.cwd, title: input.akuId,
|
|
46
|
-
config: { provider: "keiyaku/mirror", options: { world, akuId: input.akuId } },
|
|
47
|
-
idempotencyKey: `keiyaku:${world}:${input.akuId}`,
|
|
48
|
-
});
|
|
49
|
-
return { attached: true };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async function attachToAkuma(input: z.output<typeof attachRpc.input>,
|
|
53
|
-
caller: Extract<NonNullable<z.output<typeof attachRpc.input>["caller"]>, { kind: "akuma" }>,
|
|
54
|
-
paseo: PluginHandlerContext["paseo"]): Promise<{ attached: boolean }> {
|
|
55
|
-
let parentWorld: string;
|
|
56
|
-
let childWorld: string;
|
|
57
|
-
try {
|
|
58
|
-
[parentWorld, childWorld] = await Promise.all([realpath(caller.world), realpath(input.world)]);
|
|
59
|
-
} catch {
|
|
60
|
-
return skip("Akuma parent or child World is unavailable");
|
|
61
|
-
}
|
|
62
|
-
let candidates: PaseoAgent[];
|
|
63
|
-
try {
|
|
64
|
-
candidates = await listMirrorCandidates(paseo, parentWorld, caller.akuId, true);
|
|
65
|
-
} catch (error) {
|
|
66
|
-
return skip(error instanceof Error ? error.message : String(error));
|
|
67
|
-
}
|
|
68
|
-
if (candidates.length !== 1) return skip(candidates.length
|
|
69
|
-
? `ambiguous Akuma parent ${caller.akuId}: multiple mirrors`
|
|
70
|
-
: `no mirror for Akuma parent ${caller.akuId}`);
|
|
71
|
-
const candidate = candidates[0]!;
|
|
72
|
-
let current: { agent: PaseoAgent } | null;
|
|
73
|
-
try {
|
|
74
|
-
current = await paseo.agents.ref(candidate.id).refresh();
|
|
75
|
-
} catch (error) {
|
|
76
|
-
return skip(`Akuma parent mirror ${candidate.id} could not be read: ${error instanceof Error ? error.message : String(error)}`);
|
|
79
|
+
const parent = await raceAbort(signal, () => paseo.agents.ref(candidates[0]!).refresh());
|
|
80
|
+
if (!parent) return skip(`parent ${candidates[0]} does not exist`);
|
|
81
|
+
if (parent.agent.archivedAt) return skip(`parent ${parent.agent.id} is archived`);
|
|
82
|
+
if (parent.agent.id !== candidates[0] || !matches(parent.agent)) return skip(`parent ${parent.agent.id} changed native identity`);
|
|
83
|
+
return create(world, target.akuId, parent.agent);
|
|
77
84
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
async function create(world: string, akuId: string, parent: PaseoAgent) {
|
|
86
|
+
signal.throwIfAborted();
|
|
87
|
+
// Aliases never change this creation fingerprint, including after a rename.
|
|
88
|
+
await paseo.agents.create({ parent: parent.id, cwd: parent.cwd, title: akuId,
|
|
89
|
+
config: { provider: "keiyaku/mirror", options: { world, akuId } },
|
|
90
|
+
idempotencyKey: `keiyaku:${world}:${akuId}`,
|
|
91
|
+
});
|
|
92
|
+
return { attached: true };
|
|
82
93
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
config: { provider: "keiyaku/mirror", options: { world: childWorld, akuId: input.akuId } },
|
|
86
|
-
idempotencyKey: `keiyaku:${childWorld}:${input.akuId}`,
|
|
87
|
-
});
|
|
88
|
-
return { attached: true };
|
|
94
|
+
try { return await raceAbort(signal, () => ensure(input)); }
|
|
95
|
+
catch (error) { return skip(error instanceof Error ? error.message : String(error)); }
|
|
89
96
|
}
|