@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
|
@@ -6,17 +6,16 @@ import { verificationDefinition } from "../body/decode.js";
|
|
|
6
6
|
import { contractId } from "../core/facts/types.js";
|
|
7
7
|
import { canonicalDebtId } from "../debt/identity.js";
|
|
8
8
|
import { gateRequirements, prepareVerificationDeclaration } from "../verification/declaration.js";
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/** Every amendment field is optional; naming none requests an unchanged, fact-free amendment. */
|
|
10
|
+
export const amendInputSchema = z.strictObject({
|
|
11
|
+
target: z
|
|
12
|
+
.string()
|
|
13
|
+
.refine((value) => value.trim() !== "", "target must be nonblank")
|
|
14
|
+
.exactOptional(),
|
|
15
|
+
edits: z.string().exactOptional(),
|
|
11
16
|
after: z.array(z.string()).readonly().exactOptional(),
|
|
12
17
|
gates: z.array(z.string()).readonly().exactOptional(),
|
|
13
18
|
});
|
|
14
|
-
export const amendInputSchemas = [
|
|
15
|
-
amendFields.required({ markdown: true }),
|
|
16
|
-
amendFields.required({ after: true }),
|
|
17
|
-
amendFields.required({ gates: true }),
|
|
18
|
-
];
|
|
19
|
-
export const amendInputSchema = z.union(amendInputSchemas);
|
|
20
19
|
export function requireMarkdown(value, label = "markdown") {
|
|
21
20
|
if (typeof value !== "string")
|
|
22
21
|
throw new KeiyakuError("invalid-input", `${label} must be a string`);
|
|
@@ -53,6 +52,12 @@ export function debtOption(value) {
|
|
|
53
52
|
throw new KeiyakuError("invalid-input", "debt must be a DebtId");
|
|
54
53
|
return canonicalDebtId(value);
|
|
55
54
|
}
|
|
55
|
+
export function nonblank(value, label) {
|
|
56
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
57
|
+
throw new KeiyakuError("invalid-input", `${label} must be a nonblank string`);
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
56
61
|
export function optionalNonblank(value, label) {
|
|
57
62
|
if (value === undefined)
|
|
58
63
|
return undefined;
|
|
@@ -104,9 +109,9 @@ export function documentDerivation(document) {
|
|
|
104
109
|
};
|
|
105
110
|
}
|
|
106
111
|
/** Early CLI acquisition uses the same Library caller boundary, never document-owner capabilities. */
|
|
107
|
-
export function validateContractMarkdown(
|
|
108
|
-
decodeContractDocument(requireMarkdown(
|
|
112
|
+
export function validateContractMarkdown(terms) {
|
|
113
|
+
decodeContractDocument(requireMarkdown(terms, "terms"), { requireTimeout: true });
|
|
109
114
|
}
|
|
110
|
-
export function validateArcMarkdown(
|
|
111
|
-
decodeArcDocument(requireMarkdown(
|
|
115
|
+
export function validateArcMarkdown(body) {
|
|
116
|
+
decodeArcDocument(requireMarkdown(body, "body"));
|
|
112
117
|
}
|
package/build/src/library/kei.js
CHANGED
|
@@ -5,14 +5,17 @@ import { parseToAST } from "../markdown/parse.js";
|
|
|
5
5
|
import { indexDocument, indexedHeadings, sectionContent, normalizeTitle } from "../markdown/query.js";
|
|
6
6
|
import { readDispatchesAt } from "../dispatch/index.js";
|
|
7
7
|
import { observeContractsForAdmissionInObservationAt } from "../git/observe.js";
|
|
8
|
-
import { withGitDecodeChannel, withGitReadObservation } from "../git/read-observation.js";
|
|
8
|
+
import { withGitDecodeChannel, withGitReadObservation, } from "../git/read-observation.js";
|
|
9
9
|
import { contractObservationOperation, deliveryOperation, stateOperation, withScopeAbortSignal, } from "../protocol/operations.js";
|
|
10
10
|
import { errorCategory, readContractValue, validated, KeiyakuError, project, } from "./outcome.js";
|
|
11
11
|
import { callerContractId, optionalBoolean, requireInput, amendInputSchema, contractTerms, documentDerivation, normalizedList, optionalNonblank, optionalSignal, requireMarkdown, } from "./input.js";
|
|
12
12
|
import { retainAdmission, } from "./contract-outcomes.js";
|
|
13
13
|
import { derivedContractPolicy, derivedFreshness, derivedGates, derivedHooks, gateNames, } from "./contract-settings.js";
|
|
14
|
+
import { contractHistoryInputSchema, } from "./contract-types.js";
|
|
15
|
+
import { selectHistoryPage } from "../history.js";
|
|
14
16
|
import { compactDelivery, admitDeliveryOperation } from "../protocol/deliver.js";
|
|
15
17
|
import { validateContractWaitHandle, waitContractLocal, } from "./contract-wait.js";
|
|
18
|
+
import { targetName } from "../core/facts/types.js";
|
|
16
19
|
import { prepareAmendDocument } from "../body/amend.js";
|
|
17
20
|
import { decodeArcDocument } from "../body/arc.js";
|
|
18
21
|
import { decodeContractDocument } from "../body/decode.js";
|
|
@@ -67,10 +70,7 @@ export class Kei {
|
|
|
67
70
|
return await waitContractLocal(validateContractWaitHandle(this.scope, this.id, input));
|
|
68
71
|
}
|
|
69
72
|
async history(input) {
|
|
70
|
-
const
|
|
71
|
-
const values = input === undefined ? {} : requireInput(input, "Contract history input", ["full"]);
|
|
72
|
-
return optionalBoolean(values.full, "full") === true;
|
|
73
|
-
});
|
|
73
|
+
const request = historyRequest(input);
|
|
74
74
|
return await readContractValue(() => withGitDecodeChannel(this.scope, (channel) => withGitReadObservation(this.scope, channel, async (observation) => {
|
|
75
75
|
const journals = await observeContractsForAdmissionInObservationAt(observation, [this.id]);
|
|
76
76
|
const record = journals.journals.get(this.id);
|
|
@@ -78,50 +78,17 @@ export class Kei {
|
|
|
78
78
|
throw new Error(`missing requested contract observation: ${this.id}`);
|
|
79
79
|
if (record.state === null)
|
|
80
80
|
return { kind: "contract-missing", contractId: this.id };
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (entry.kind === "bind")
|
|
85
|
-
terms = entry.data.terms;
|
|
86
|
-
else if (entry.kind === "amend")
|
|
87
|
-
terms = entry.data;
|
|
88
|
-
return event;
|
|
89
|
-
});
|
|
90
|
-
let unavailable;
|
|
91
|
-
let dispatches;
|
|
92
|
-
try {
|
|
93
|
-
dispatches = await readDispatchesAt(observation);
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
const category = errorCategory(error);
|
|
97
|
-
if (category === "aborted" || this.scope.signal?.aborted === true)
|
|
98
|
-
throw error;
|
|
99
|
-
unavailable = {
|
|
100
|
-
kind: "unavailable",
|
|
101
|
-
category: category === "authority-corruption" ? category : "internal",
|
|
102
|
-
diagnostic: error instanceof Error ? error.message : String(error),
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
events.push(...(dispatches ?? [])
|
|
106
|
-
.filter((dispatch) => dispatch.contractId === this.id)
|
|
107
|
-
.map((dispatch) => ({
|
|
108
|
-
kind: "dispatch",
|
|
109
|
-
at: dispatch.dispatchedAt,
|
|
110
|
-
akumaId: dispatch.akumaId,
|
|
111
|
-
})));
|
|
112
|
-
events.sort((left, right) => {
|
|
113
|
-
if (left.at !== right.at)
|
|
114
|
-
return left.at < right.at ? -1 : 1;
|
|
115
|
-
if ((left.kind === "dispatch") !== (right.kind === "dispatch"))
|
|
116
|
-
return left.kind === "dispatch" ? 1 : -1;
|
|
117
|
-
return 0;
|
|
118
|
-
});
|
|
119
|
-
return {
|
|
120
|
-
kind: "contract",
|
|
121
|
-
contractId: this.id,
|
|
122
|
-
events,
|
|
123
|
-
...(unavailable === undefined ? {} : { dispatches: unavailable }),
|
|
81
|
+
const journal = {
|
|
82
|
+
entries: record.entries,
|
|
83
|
+
addresses: new Map(record.entries.map((entry, index) => [entry.entry, String(index + 1)])),
|
|
124
84
|
};
|
|
85
|
+
if ("item" in request) {
|
|
86
|
+
const [event] = projectJournal(journal, new Set([Number(request.item)]), true);
|
|
87
|
+
return event === undefined
|
|
88
|
+
? { kind: "contract-unknown-history", contractId: this.id }
|
|
89
|
+
: { kind: "contract-exact", contractId: this.id, event };
|
|
90
|
+
}
|
|
91
|
+
return await journalPage(observation, this.scope, this.id, journal, request);
|
|
125
92
|
})));
|
|
126
93
|
}
|
|
127
94
|
async guidance() {
|
|
@@ -145,40 +112,53 @@ export class Kei {
|
|
|
145
112
|
const values = parsed.data;
|
|
146
113
|
const derived = values.gates === undefined ? undefined : derivedGates(this.composition, gateNames(values.gates));
|
|
147
114
|
return {
|
|
148
|
-
|
|
115
|
+
edits: values.edits,
|
|
116
|
+
target: values.target,
|
|
149
117
|
gates: derived,
|
|
150
118
|
prerequisites: values.after === undefined ? undefined : normalizedList(values.after, "after", callerContractId),
|
|
151
119
|
};
|
|
152
120
|
});
|
|
153
121
|
}
|
|
154
122
|
async amend(input) {
|
|
155
|
-
const {
|
|
123
|
+
const { edits, target, gates, prerequisites } = this.amendInput(input);
|
|
156
124
|
const hooks = derivedHooks(this.composition);
|
|
157
|
-
const
|
|
125
|
+
const requestsChange = edits !== undefined || target !== undefined || gates !== undefined || prerequisites !== undefined;
|
|
126
|
+
const amendmentPlan = edits === undefined ? undefined : validated(() => prepareAmendDocument(edits));
|
|
158
127
|
let changedSections;
|
|
159
|
-
|
|
128
|
+
const concluded = await this.local("amend", async (accumulator, channel, scope) => {
|
|
160
129
|
const admission = await amendOperation({
|
|
161
130
|
scope,
|
|
162
131
|
channel,
|
|
163
132
|
contractId: this.id,
|
|
164
133
|
progress: accumulator,
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
?
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
134
|
+
...(target === undefined ? {} : { target }),
|
|
135
|
+
...(requestsChange
|
|
136
|
+
? {
|
|
137
|
+
deriveAmendment: (source) => {
|
|
138
|
+
const current = persistedDocument(source.document.bytes);
|
|
139
|
+
const amendment = amendmentPlan === undefined ? undefined : validated(() => amendmentPlan(current));
|
|
140
|
+
const amended = amendment === undefined ? current : validated(() => decodeContractDocument(amendment.document));
|
|
141
|
+
changedSections =
|
|
142
|
+
amendment === undefined
|
|
143
|
+
? undefined
|
|
144
|
+
: new Set([...amendment.changedSections].filter((section) => sectionValue(current, section) !== sectionValue(amended, section)));
|
|
145
|
+
const terms = contractTerms(amended, gates ?? source.gates, prerequisites ?? source.after);
|
|
146
|
+
return { terms, verification: documentDerivation(amended).verification };
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
: {}),
|
|
176
150
|
});
|
|
151
|
+
// No requested change is the same answer as before: an accepted amendment that changed nothing.
|
|
152
|
+
if (admission.kind === "unchanged")
|
|
153
|
+
return { kind: "unchanged", contractId: this.id };
|
|
177
154
|
if (admission.kind !== "accepted")
|
|
178
155
|
return admission.kind === "refused"
|
|
179
156
|
? { kind: "refused", contractId: this.id, reason: compactReason(admission.refusal) }
|
|
180
157
|
: { contractId: this.id, ...compactRetry(admission.reason) };
|
|
181
|
-
const changes =
|
|
158
|
+
const changes = {
|
|
159
|
+
...changedAmendTerms(admission.value.source, admission.value.terms),
|
|
160
|
+
...(admission.value.target === undefined ? {} : { target: targetName(admission.value.target) }),
|
|
161
|
+
};
|
|
182
162
|
const sections = changedSections === undefined || changedSections.size === 0 ? {} : { changedSections: [...changedSections] };
|
|
183
163
|
accumulator.extendConclusions(this.id, { ...sections, ...changes });
|
|
184
164
|
const region = await observeChangedRegion(scope, this.id, changedSections, decodeContractDocument(admission.value.terms.document.bytes).region);
|
|
@@ -195,6 +175,7 @@ export class Kei {
|
|
|
195
175
|
});
|
|
196
176
|
return { kind: "accepted", contractId: this.id, ...value };
|
|
197
177
|
});
|
|
178
|
+
return concluded.kind === "unchanged" ? { kind: "accepted", contractId: this.id } : concluded;
|
|
198
179
|
}
|
|
199
180
|
/** One promise with an optional observation callback; observation never delays custody. */
|
|
200
181
|
async deliver(input, options) {
|
|
@@ -392,8 +373,8 @@ export class Kei {
|
|
|
392
373
|
}
|
|
393
374
|
async arc(input) {
|
|
394
375
|
const chapter = validated(() => {
|
|
395
|
-
const values = requireInput(input, "arc input", ["
|
|
396
|
-
return decodeArcDocument(requireMarkdown(values.
|
|
376
|
+
const values = requireInput(input, "arc input", ["body"]);
|
|
377
|
+
return decodeArcDocument(requireMarkdown(values.body, "body"));
|
|
397
378
|
});
|
|
398
379
|
const hooks = derivedHooks(this.composition);
|
|
399
380
|
return await this.local("arc", async (accumulator, channel, scope) => {
|
|
@@ -485,7 +466,7 @@ export class Kei {
|
|
|
485
466
|
return value;
|
|
486
467
|
}
|
|
487
468
|
}
|
|
488
|
-
function changedHistoryTerms(before, after) {
|
|
469
|
+
function changedHistoryTerms(before, after, complete) {
|
|
489
470
|
const sections = (terms) => {
|
|
490
471
|
const document = parseToAST(terms.document.bytes);
|
|
491
472
|
return new Map(indexedHeadings(indexDocument(document), { level: 2 })
|
|
@@ -498,8 +479,12 @@ function changedHistoryTerms(before, after) {
|
|
|
498
479
|
const equal = (left, right) => left !== undefined && left.length === right.length && left.every((value, index) => value === right[index]);
|
|
499
480
|
return {
|
|
500
481
|
...(changedSections.length === 0 ? {} : { changedSections }),
|
|
501
|
-
...(
|
|
502
|
-
|
|
482
|
+
...(complete
|
|
483
|
+
? { gates: after.gates, after: after.after }
|
|
484
|
+
: {
|
|
485
|
+
...(equal(before?.gates, after.gates) ? {} : { gates: after.gates }),
|
|
486
|
+
...(equal(before?.after, after.after) ? {} : { after: after.after }),
|
|
487
|
+
}),
|
|
503
488
|
};
|
|
504
489
|
}
|
|
505
490
|
function attestationHistory(entry) {
|
|
@@ -513,28 +498,52 @@ function attestationHistory(entry) {
|
|
|
513
498
|
...(summary === undefined ? {} : { summary }),
|
|
514
499
|
};
|
|
515
500
|
}
|
|
516
|
-
function
|
|
517
|
-
|
|
501
|
+
function historyTarget(target, complete) {
|
|
502
|
+
return target === undefined
|
|
503
|
+
? {}
|
|
504
|
+
: {
|
|
505
|
+
target: typeof target === "string" ? target : { kind: "contract", contractId: target.contractId },
|
|
506
|
+
...(complete && typeof target === "object" ? { targetIncarnation: target.worktree } : {}),
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
/** One exact address or one page window; the family's schema rejects contradictory intent. */
|
|
510
|
+
function historyRequest(input) {
|
|
511
|
+
const parsed = contractHistoryInputSchema.safeParse(input === undefined ? {} : requireInput(input, "Contract history input"));
|
|
512
|
+
if (!parsed.success)
|
|
513
|
+
throw new KeiyakuError("invalid-input", parsed.error.message, { cause: parsed.error });
|
|
514
|
+
return parsed.data;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Project selected one-based append positions from one complete observed journal,
|
|
518
|
+
* computing each amendment's summary against its real preceding terms. Sequence
|
|
519
|
+
* stays authoritative: rows keep append order even under equal or nonmonotonic clocks.
|
|
520
|
+
*/
|
|
521
|
+
function projectJournal(journal, selected, complete) {
|
|
522
|
+
const rows = [];
|
|
523
|
+
let terms;
|
|
524
|
+
journal.entries.forEach((entry, index) => {
|
|
525
|
+
const position = index + 1;
|
|
526
|
+
if (selected.has(position))
|
|
527
|
+
rows.push(journalRecord(journal, entry, position, terms, complete));
|
|
528
|
+
if (entry.kind === "bind")
|
|
529
|
+
terms = entry.data.terms;
|
|
530
|
+
else if (entry.kind === "amend")
|
|
531
|
+
terms = entry.data;
|
|
532
|
+
});
|
|
533
|
+
return rows;
|
|
534
|
+
}
|
|
535
|
+
function journalRecord(journal, entry, position, terms, complete) {
|
|
536
|
+
const common = { id: String(position), at: entry.at };
|
|
518
537
|
switch (entry.kind) {
|
|
519
538
|
case "bind": {
|
|
520
539
|
const { coordinates, terms: bound } = entry.data;
|
|
521
|
-
const target = coordinates.target;
|
|
522
540
|
return {
|
|
523
541
|
...common,
|
|
524
542
|
kind: "bind",
|
|
525
543
|
start: coordinates.start,
|
|
526
|
-
...(target
|
|
527
|
-
|
|
528
|
-
:
|
|
529
|
-
target: typeof target === "string" ? target : { kind: "contract", contractId: target.contractId },
|
|
530
|
-
}),
|
|
531
|
-
...(full
|
|
532
|
-
? {
|
|
533
|
-
document: bound.document.bytes,
|
|
534
|
-
gates: bound.gates,
|
|
535
|
-
after: bound.after,
|
|
536
|
-
...(typeof target === "object" ? { targetIncarnation: target.worktree } : {}),
|
|
537
|
-
}
|
|
544
|
+
...historyTarget(coordinates.target, complete),
|
|
545
|
+
...(complete
|
|
546
|
+
? { document: bound.document.bytes, gates: bound.gates, after: bound.after }
|
|
538
547
|
: {
|
|
539
548
|
...(bound.gates.length === 0 ? {} : { gates: bound.gates }),
|
|
540
549
|
...(bound.after.length === 0 ? {} : { after: bound.after }),
|
|
@@ -545,8 +554,9 @@ function historyEvent(entry, terms, full) {
|
|
|
545
554
|
return {
|
|
546
555
|
...common,
|
|
547
556
|
kind: "amend",
|
|
548
|
-
...
|
|
549
|
-
...(
|
|
557
|
+
...historyTarget(entry.data.target, complete),
|
|
558
|
+
...changedHistoryTerms(terms, entry.data, complete),
|
|
559
|
+
...(complete ? { document: entry.data.document.bytes } : {}),
|
|
550
560
|
};
|
|
551
561
|
case "deliver": {
|
|
552
562
|
const { tenderSnapshot, integration, note } = entry.data;
|
|
@@ -558,7 +568,7 @@ function historyEvent(entry, terms, full) {
|
|
|
558
568
|
contentId: integration.changeId,
|
|
559
569
|
predecessor: integration.predecessor,
|
|
560
570
|
...(note === undefined ? {} : { note }),
|
|
561
|
-
...(
|
|
571
|
+
...(complete ? { requireBranchesToBeUpToDate: entry.data.policy.requireBranchesToBeUpToDate } : {}),
|
|
562
572
|
};
|
|
563
573
|
}
|
|
564
574
|
case "reintegrated":
|
|
@@ -570,15 +580,19 @@ function historyEvent(entry, terms, full) {
|
|
|
570
580
|
};
|
|
571
581
|
case "attestation":
|
|
572
582
|
return { ...common, ...attestationHistory(entry) };
|
|
573
|
-
case "claimed":
|
|
574
|
-
|
|
583
|
+
case "claimed": {
|
|
584
|
+
const delivery = journal.addresses.get(entry.data.delivery);
|
|
585
|
+
if (delivery === undefined)
|
|
586
|
+
throw new KeiyakuError("authority-corruption", `claimed delivery is not a journal entry: ${entry.data.delivery}`);
|
|
587
|
+
return { ...common, kind: "claimed", deliveryId: delivery };
|
|
588
|
+
}
|
|
575
589
|
case "arc":
|
|
576
590
|
return {
|
|
577
591
|
...common,
|
|
578
592
|
kind: "arc",
|
|
579
593
|
chapter: entry.data.seq,
|
|
580
594
|
title: entry.data.title,
|
|
581
|
-
...(entry.data.body.length === 0 && !
|
|
595
|
+
...(entry.data.body.length === 0 && !complete ? {} : { body: entry.data.body }),
|
|
582
596
|
};
|
|
583
597
|
case "abandoned":
|
|
584
598
|
return {
|
|
@@ -588,6 +602,69 @@ function historyEvent(entry, terms, full) {
|
|
|
588
602
|
};
|
|
589
603
|
}
|
|
590
604
|
}
|
|
605
|
+
function compareText(left, right) {
|
|
606
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Anchor each available Dispatch to the journal row it follows in the existing
|
|
610
|
+
* chronological merge. Journal wins equal-time ties and sequence breaks its own;
|
|
611
|
+
* a Dispatch earlier than the first journal row belongs to that first row.
|
|
612
|
+
*/
|
|
613
|
+
function associateDispatches(entries, dispatches, contractId) {
|
|
614
|
+
const chronological = entries
|
|
615
|
+
.map((entry, index) => ({ position: index + 1, at: entry.at }))
|
|
616
|
+
.sort((left, right) => (left.at === right.at ? left.position - right.position : compareText(left.at, right.at)));
|
|
617
|
+
const own = dispatches
|
|
618
|
+
.filter((dispatch) => dispatch.contractId === contractId)
|
|
619
|
+
.sort((left, right) => left.dispatchedAt === right.dispatchedAt
|
|
620
|
+
? compareText(left.akumaId, right.akumaId)
|
|
621
|
+
: compareText(left.dispatchedAt, right.dispatchedAt));
|
|
622
|
+
const grouped = new Map();
|
|
623
|
+
let nextJournal = 0;
|
|
624
|
+
// Earlier than every journal timestamp belongs to the first appended row.
|
|
625
|
+
let position = 1;
|
|
626
|
+
for (const dispatch of own) {
|
|
627
|
+
while (chronological[nextJournal] !== undefined && chronological[nextJournal].at <= dispatch.dispatchedAt) {
|
|
628
|
+
position = chronological[nextJournal++].position;
|
|
629
|
+
}
|
|
630
|
+
const rows = grouped.get(position) ?? [];
|
|
631
|
+
rows.push({ kind: "dispatch", at: dispatch.dispatchedAt, akumaId: dispatch.akumaId });
|
|
632
|
+
grouped.set(position, rows);
|
|
633
|
+
}
|
|
634
|
+
return grouped;
|
|
635
|
+
}
|
|
636
|
+
/** One bounded journal page over the complete observation, with available enrichment. */
|
|
637
|
+
async function journalPage(observation, scope, contractId, journal, request) {
|
|
638
|
+
const page = selectHistoryPage(journal.entries.map((_entry, index) => index + 1), (position) => position, request);
|
|
639
|
+
let associations = new Map();
|
|
640
|
+
let unavailable;
|
|
641
|
+
try {
|
|
642
|
+
associations = associateDispatches(journal.entries, await readDispatchesAt(observation), contractId);
|
|
643
|
+
}
|
|
644
|
+
catch (error) {
|
|
645
|
+
const category = errorCategory(error);
|
|
646
|
+
if (category === "aborted" || scope.signal?.aborted === true)
|
|
647
|
+
throw error;
|
|
648
|
+
unavailable = {
|
|
649
|
+
kind: "unavailable",
|
|
650
|
+
category: category === "authority-corruption" ? category : "internal",
|
|
651
|
+
diagnostic: error instanceof Error ? error.message : String(error),
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
const events = [];
|
|
655
|
+
for (const row of projectJournal(journal, new Set(page.rows), false)) {
|
|
656
|
+
events.push(row, ...(associations.get(Number(row.id)) ?? []));
|
|
657
|
+
}
|
|
658
|
+
return {
|
|
659
|
+
kind: "contract",
|
|
660
|
+
contractId,
|
|
661
|
+
events,
|
|
662
|
+
...(page.omitted === 0 ? {} : { omitted: page.omitted }),
|
|
663
|
+
lowestRetainedSequence: 1,
|
|
664
|
+
highestSequence: journal.entries.length,
|
|
665
|
+
...(unavailable === undefined ? {} : { dispatches: unavailable }),
|
|
666
|
+
};
|
|
667
|
+
}
|
|
591
668
|
/** Internal constructor capability; callers select a Contract through Keis.of. */
|
|
592
669
|
export function createKeiHandle(id, scope, composition) {
|
|
593
670
|
return Reflect.construct(Kei, [KEIYAKU_HANDLE, id, scope, composition]);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type Owner } from "@astrosheep/square";
|
|
2
2
|
/** Select attribution at the submitting edge; no host or artifact lookup. */
|
|
3
|
-
export declare function deliveryOwner(environment: NodeJS.ProcessEnv): Owner | undefined;
|
|
3
|
+
export declare function deliveryOwner(environment: NodeJS.ProcessEnv, owner?: Owner): Owner | undefined;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { harnessOwner } from "@astrosheep/square";
|
|
2
2
|
/** Select attribution at the submitting edge; no host or artifact lookup. */
|
|
3
|
-
export function deliveryOwner(environment) {
|
|
3
|
+
export function deliveryOwner(environment, owner) {
|
|
4
4
|
const explicit = environment.KEIYAKU_INITIATOR?.trim();
|
|
5
5
|
if (explicit)
|
|
6
6
|
return explicit;
|
|
7
|
+
if (owner !== undefined)
|
|
8
|
+
return owner;
|
|
7
9
|
if (environment.CLAUDE_CODE_CHILD_SESSION === "1" && !environment.CLAUDE_CODE_SESSION_ID?.trim())
|
|
8
10
|
return undefined;
|
|
9
11
|
const coordinates = [
|
|
@@ -54,12 +54,16 @@ function classifyReconcile(result) {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
function classifyWait(result) {
|
|
57
|
-
if (result.kind === "
|
|
58
|
-
return
|
|
59
|
-
return result.
|
|
57
|
+
if (result.members.some((member) => member.kind === "akuma" && (member.observation.kind === "unobserved" || member.observation.kind === "missing")))
|
|
58
|
+
return "failed";
|
|
59
|
+
return result.reason === "missing" ? "refused" : "accepted";
|
|
60
60
|
}
|
|
61
61
|
function classifyHistory(value) {
|
|
62
|
-
return value.kind === "contract-missing" ||
|
|
62
|
+
return value.kind === "contract-missing" ||
|
|
63
|
+
value.kind === "contract-unknown-history" ||
|
|
64
|
+
value.kind === "akuma-unknown-history"
|
|
65
|
+
? "refused"
|
|
66
|
+
: "accepted";
|
|
63
67
|
}
|
|
64
68
|
function classifyNuke(result) {
|
|
65
69
|
if (result.kind === "refused")
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { type AddDebtInput, type AddDebtDocumentInput, type UpdateDebtInput, type DebtAbsent, type DebtShowResult } from "../debt/index.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { KeiyakuFor } from "./keiyaku.js";
|
|
3
|
+
import type { LifecycleSelection } from "../bounded-list.js";
|
|
3
4
|
type DebtListInvocation = Readonly<{
|
|
4
|
-
selection?:
|
|
5
|
+
selection?: LifecycleSelection;
|
|
5
6
|
limit?: number;
|
|
6
7
|
}>;
|
|
7
8
|
export type DebtUpdateInvocation = UpdateDebtInput & Readonly<{
|
|
8
9
|
id: string;
|
|
9
10
|
}>;
|
|
10
|
-
export declare function debtAdd(at:
|
|
11
|
+
export declare function debtAdd(at: KeiyakuFor, input: AddDebtInput | AddDebtDocumentInput, document: boolean): Promise<Readonly<{
|
|
11
12
|
kind: "refused";
|
|
12
13
|
reason: "invalid-graph";
|
|
13
14
|
diagnostic: string;
|
|
@@ -19,7 +20,7 @@ export declare function debtAdd(at: KeiyakuAt, input: AddDebtInput | AddDebtDocu
|
|
|
19
20
|
id: `debt/${string}`;
|
|
20
21
|
warning?: string;
|
|
21
22
|
}>>;
|
|
22
|
-
export declare function debtUpdate(at:
|
|
23
|
+
export declare function debtUpdate(at: KeiyakuFor, input: DebtUpdateInvocation): Promise<Readonly<{
|
|
23
24
|
kind: "refused";
|
|
24
25
|
reason: "debt-missing";
|
|
25
26
|
}> | Readonly<{
|
|
@@ -34,8 +35,8 @@ export declare function debtUpdate(at: KeiyakuAt, input: DebtUpdateInvocation):
|
|
|
34
35
|
changes?: readonly ("title" | "state" | "note" | "body" | "priority" | "needs")[];
|
|
35
36
|
warning?: string;
|
|
36
37
|
}>>;
|
|
37
|
-
export declare function debtShow(at:
|
|
38
|
-
export declare function debtLs(at:
|
|
38
|
+
export declare function debtShow(at: KeiyakuFor, id: string): Promise<DebtShowResult | DebtAbsent>;
|
|
39
|
+
export declare function debtLs(at: KeiyakuFor, input: DebtListInvocation): Promise<Readonly<{
|
|
39
40
|
kind: "debt-catalogue";
|
|
40
41
|
rows?: readonly Readonly<{
|
|
41
42
|
id: `debt/${string}`;
|
|
@@ -48,7 +49,7 @@ export declare function debtLs(at: KeiyakuAt, input: DebtListInvocation): Promis
|
|
|
48
49
|
readonly kind: "debt-catalogue";
|
|
49
50
|
readonly absent: true;
|
|
50
51
|
}>;
|
|
51
|
-
export declare function debtDoctor(at:
|
|
52
|
+
export declare function debtDoctor(at: KeiyakuFor): Promise<Readonly<{
|
|
52
53
|
kind: "absent";
|
|
53
54
|
}> | Readonly<{
|
|
54
55
|
kind: "present";
|
|
@@ -5,7 +5,6 @@ import { parseDebtCreationDocument } from "../debt/document.js";
|
|
|
5
5
|
import { invocationCoordinates } from "./keiyaku-coordinates.js";
|
|
6
6
|
const coordinates = (at) => invocationCoordinates({ ...at, use: "none" });
|
|
7
7
|
const absent = { kind: "absent" };
|
|
8
|
-
const missing = () => ({ kind: "refused", reason: "debt-missing" });
|
|
9
8
|
export async function debtAdd(at, input, document) {
|
|
10
9
|
const parsed = document ? addDocumentInput(input) : addInput(input);
|
|
11
10
|
if (document)
|
|
@@ -22,7 +21,7 @@ export async function debtUpdate(at, input) {
|
|
|
22
21
|
.debt({ id })
|
|
23
22
|
.update(rest);
|
|
24
23
|
updateInput(rest).signal?.throwIfAborted();
|
|
25
|
-
return missing
|
|
24
|
+
return { kind: "refused", reason: "debt-missing" };
|
|
26
25
|
}
|
|
27
26
|
export async function debtShow(at, id) {
|
|
28
27
|
const coord = await coordinates(at);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/** @architectureCompositionRoot */
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { type Owner } from "@astrosheep/square";
|
|
3
4
|
import { Repo } from "./repo.js";
|
|
4
5
|
import { type AkumaCaller } from "../akuma/caller.js";
|
|
5
6
|
import { type WorldRoot } from "../world.js";
|
|
6
|
-
/**
|
|
7
|
-
export declare function akumaCallerFromEnvironment(environment: NodeJS.ProcessEnv): Promise<AkumaCaller | undefined>;
|
|
7
|
+
/** Actor declarations win; a host Owner bypasses native environment decoding. */
|
|
8
|
+
export declare function akumaCallerFromEnvironment(environment: NodeJS.ProcessEnv, owner?: Owner): Promise<AkumaCaller | undefined>;
|
|
8
9
|
type WhoamiCoordinates = Readonly<{
|
|
9
10
|
cwd: string;
|
|
10
11
|
repo?: Repo;
|
|
@@ -54,5 +55,5 @@ export declare const whoamiFactsSchema: z.ZodReadonly<z.ZodObject<{
|
|
|
54
55
|
profileUnavailable: z.ZodExactOptional<z.ZodString>;
|
|
55
56
|
}, z.core.$strict>>;
|
|
56
57
|
export type WhoamiFacts = z.output<typeof whoamiFactsSchema>;
|
|
57
|
-
export declare function whoami(coordinates: WhoamiCoordinates, environment: NodeJS.ProcessEnv): Promise<WhoamiFacts>;
|
|
58
|
+
export declare function whoami(coordinates: WhoamiCoordinates, environment: NodeJS.ProcessEnv, owner?: Owner): Promise<WhoamiFacts>;
|
|
58
59
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** @architectureCompositionRoot */
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { decodeHarnessOwner, harnessOwner } from "@astrosheep/square";
|
|
3
4
|
import { contractIdSchema } from "../git/identity.js";
|
|
4
5
|
import { AkumaOwner } from "../akuma/akuma-owner.js";
|
|
5
6
|
import { KeiyakuError } from "../errors.js";
|
|
@@ -9,10 +10,32 @@ import { Keis } from "./contract-composition.js";
|
|
|
9
10
|
import { NoGitWorldError, Repo } from "./repo.js";
|
|
10
11
|
import { observeNamedAddress } from "./address.js";
|
|
11
12
|
import { dispatchAssociations } from "./selection.js";
|
|
12
|
-
import { decodeAkumaCaller } from "../akuma/caller.js";
|
|
13
|
+
import { akumaCallerSchema, decodeAkumaCaller } from "../akuma/caller.js";
|
|
13
14
|
import { World, worldRootSchema } from "../world.js";
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
function callerFromOwner(owner) {
|
|
16
|
+
const coordinate = decodeHarnessOwner(owner);
|
|
17
|
+
// Only session-only native coordinates have an existing lineage representation.
|
|
18
|
+
// Keep other Owners whole, especially agents sharing one harness session.
|
|
19
|
+
if (coordinate !== undefined &&
|
|
20
|
+
coordinate.agent === undefined &&
|
|
21
|
+
["pi", "codex", "claude-code", "opencode", "paseo"].includes(coordinate.channel)) {
|
|
22
|
+
const caller = akumaCallerSchema.safeParse({
|
|
23
|
+
kind: "external",
|
|
24
|
+
integration: coordinate.channel === "claude-code" ? "claude" : coordinate.channel,
|
|
25
|
+
id: coordinate.session,
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
if (caller.success && harnessOwner(coordinate) === owner)
|
|
29
|
+
return caller.data;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// A valid opaque Owner need not be representable as a harness coordinate.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { kind: "external", integration: "square", id: owner };
|
|
36
|
+
}
|
|
37
|
+
/** Actor declarations win; a host Owner bypasses native environment decoding. */
|
|
38
|
+
export async function akumaCallerFromEnvironment(environment, owner) {
|
|
16
39
|
const id = environment.KEIYAKU_ACTOR_ID;
|
|
17
40
|
const world = environment.KEIYAKU_ACTOR_WORLD;
|
|
18
41
|
if ((id === undefined) !== (world === undefined)) {
|
|
@@ -22,6 +45,8 @@ export async function akumaCallerFromEnvironment(environment) {
|
|
|
22
45
|
const resolved = await World.resolve({ cwd: world, repositoryRoot: world });
|
|
23
46
|
return decodeAkumaCaller({ kind: "akuma", akumaId: id, world: resolved.candidate });
|
|
24
47
|
}
|
|
48
|
+
if (owner !== undefined)
|
|
49
|
+
return callerFromOwner(owner);
|
|
25
50
|
const hosts = [
|
|
26
51
|
{ integration: "codex", variable: "CODEX_THREAD_ID", id: environment.CODEX_THREAD_ID },
|
|
27
52
|
{ integration: "pi", variable: "PI_SESSION_ID", id: environment.PI_SESSION_ID },
|
|
@@ -73,9 +98,9 @@ export const whoamiFactsSchema = z
|
|
|
73
98
|
function reason(error) {
|
|
74
99
|
return error instanceof Error ? error.message : String(error);
|
|
75
100
|
}
|
|
76
|
-
async function selfFrom(environment) {
|
|
101
|
+
async function selfFrom(environment, explicit) {
|
|
77
102
|
try {
|
|
78
|
-
const caller = await akumaCallerFromEnvironment(environment);
|
|
103
|
+
const caller = await akumaCallerFromEnvironment(environment, explicit);
|
|
79
104
|
return caller === undefined ? { kind: "none" } : callerFact(caller);
|
|
80
105
|
}
|
|
81
106
|
catch (error) {
|
|
@@ -163,9 +188,12 @@ async function callerProfile(caller, coordinates, environment) {
|
|
|
163
188
|
return { profileUnavailable: reason(error) };
|
|
164
189
|
}
|
|
165
190
|
}
|
|
166
|
-
export async function whoami(coordinates, environment) {
|
|
191
|
+
export async function whoami(coordinates, environment, owner) {
|
|
167
192
|
const world = coordinates.world !== null && (await World.established(coordinates.world)) ? coordinates.world : null;
|
|
168
|
-
const [self, contextContract] = await Promise.all([
|
|
193
|
+
const [self, contextContract] = await Promise.all([
|
|
194
|
+
selfFrom(environment, owner),
|
|
195
|
+
contextualContract(coordinates, world),
|
|
196
|
+
]);
|
|
169
197
|
const initiator = self.kind === "akuma" ? await currentTurn(self) : undefined;
|
|
170
198
|
return {
|
|
171
199
|
self,
|