@astrosheep/keiyaku 4.6.33 → 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 +10 -1
- package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +5 -2
- package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +5 -2
- package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +5 -2
- package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/pi/keiyaku.ts +1 -135
- package/build/skills/keiyaku-akuma/SKILL.md +5 -2
- package/build/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/src/akuma/akuma-observe.d.ts +8 -0
- package/build/src/akuma/akuma-observe.js +8 -0
- package/build/src/akuma/akuma-owner.d.ts +1 -0
- package/build/src/akuma/akuma-owner.js +3 -5
- package/build/src/akuma/akuma-wait.d.ts +117 -2
- package/build/src/akuma/akuma-wait.js +53 -22
- package/build/src/akuma/akuma.d.ts +6 -1
- package/build/src/akuma/akuma.js +37 -18
- 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 +6 -0
- package/build/src/akuma/heart/index.js +27 -9
- package/build/src/akuma/heart/rows.d.ts +1 -0
- package/build/src/akuma/heart/rows.js +4 -0
- 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.js +4 -9
- package/build/src/akuma/selection-observation.d.ts +622 -0
- package/build/src/akuma/selection-observation.js +7 -3
- 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 +2 -3
- package/build/src/cli/commands/akuma-grammar.js +32 -39
- package/build/src/cli/commands/akuma.js +6 -3
- package/build/src/cli/commands/contract-grammar.js +32 -31
- package/build/src/cli/commands/contract-help.d.ts +3 -3
- package/build/src/cli/commands/contract-help.js +10 -8
- package/build/src/cli/commands/contract.d.ts +3 -3
- package/build/src/cli/commands/contract.js +11 -10
- package/build/src/cli/parse.d.ts +4 -10
- package/build/src/cli/parse.js +1 -1
- package/build/src/cli/render/akuma-activity.d.ts +9 -19
- package/build/src/cli/render/akuma-activity.js +83 -110
- package/build/src/cli/render/catalog.js +3 -2
- package/build/src/cli/render/contract-history.d.ts +1 -3
- package/build/src/cli/render/contract-history.js +68 -49
- package/build/src/cli/render/contract-wait.js +9 -1
- package/build/src/cli/render/kanshi-akuma.d.ts +4 -3
- package/build/src/cli/render/kanshi-akuma.js +26 -21
- package/build/src/cli/render/kanshi.js +34 -43
- package/build/src/cli/render/verbs.js +20 -17
- package/build/src/cli/runtime.js +9 -23
- 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 -1
- package/build/src/debt/index.js +3 -3
- package/build/src/debt/operations.d.ts +2 -1
- package/build/src/git/observe.d.ts +4 -3
- package/build/src/git/observe.js +8 -7
- package/build/src/history.d.ts +26 -0
- package/build/src/history.js +43 -0
- package/build/src/index.d.ts +4 -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 -3
- package/build/src/kanshi/index.js +2 -2
- package/build/src/kanshi/read.js +5 -2
- package/build/src/library/akumas.d.ts +5 -1
- package/build/src/library/akumas.js +11 -5
- package/build/src/library/contract-composition.js +10 -10
- package/build/src/library/contract-creation.js +2 -2
- package/build/src/library/contract-types.d.ts +215 -25
- package/build/src/library/contract-types.js +31 -13
- package/build/src/library/contract-wait.d.ts +205 -0
- package/build/src/library/contract-wait.js +15 -3
- package/build/src/library/input.d.ts +3 -3
- package/build/src/library/input.js +5 -5
- package/build/src/library/kei.js +134 -76
- 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 +5 -1
- package/build/src/library/keiyaku-debt.d.ts +8 -7
- package/build/src/library/keiyaku-identity.d.ts +4 -3
- package/build/src/library/keiyaku-identity.js +30 -7
- package/build/src/library/keiyaku-verbs.d.ts +515 -44
- package/build/src/library/keiyaku-verbs.js +84 -79
- package/build/src/library/keiyaku-wait.d.ts +570 -0
- package/build/src/library/keiyaku-wait.js +25 -8
- package/build/src/library/keiyaku.d.ts +3110 -31
- package/build/src/library/keiyaku.js +335 -407
- package/build/src/library/model-tools.d.ts +268 -70
- package/build/src/library/model-tools.js +110 -95
- package/build/src/library/selection.d.ts +6 -5
- package/build/src/library/selection.js +10 -3
- package/build/src/mcp/adapter.js +1 -1
- package/build/src/mcp/help.d.ts +1 -1
- package/build/src/mcp/help.js +4 -3
- package/build/src/pi/index.d.ts +2 -0
- package/build/src/pi/index.js +23 -7
- package/build/src/pi/status.d.ts +12 -0
- package/build/src/pi/status.js +140 -0
- package/build/src/protocol/operations.d.ts +2 -0
- package/build/src/protocol/operations.js +1 -1
- package/build/src/protocol/read/status.d.ts +12 -4
- package/build/src/protocol/read/status.js +19 -12
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/package.json +1 -1
- 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/keiyaku.ts +1 -135
- package/skills/keiyaku-akuma/SKILL.md +5 -2
- package/skills/keiyaku-debt/SKILL.md +2 -1
package/build/src/library/kei.js
CHANGED
|
@@ -5,12 +5,14 @@ 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";
|
|
16
18
|
import { targetName } from "../core/facts/types.js";
|
|
@@ -68,10 +70,7 @@ export class Kei {
|
|
|
68
70
|
return await waitContractLocal(validateContractWaitHandle(this.scope, this.id, input));
|
|
69
71
|
}
|
|
70
72
|
async history(input) {
|
|
71
|
-
const
|
|
72
|
-
const values = input === undefined ? {} : requireInput(input, "Contract history input", ["full"]);
|
|
73
|
-
return optionalBoolean(values.full, "full") === true;
|
|
74
|
-
});
|
|
73
|
+
const request = historyRequest(input);
|
|
75
74
|
return await readContractValue(() => withGitDecodeChannel(this.scope, (channel) => withGitReadObservation(this.scope, channel, async (observation) => {
|
|
76
75
|
const journals = await observeContractsForAdmissionInObservationAt(observation, [this.id]);
|
|
77
76
|
const record = journals.journals.get(this.id);
|
|
@@ -79,50 +78,17 @@ export class Kei {
|
|
|
79
78
|
throw new Error(`missing requested contract observation: ${this.id}`);
|
|
80
79
|
if (record.state === null)
|
|
81
80
|
return { kind: "contract-missing", contractId: this.id };
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (entry.kind === "bind")
|
|
86
|
-
terms = entry.data.terms;
|
|
87
|
-
else if (entry.kind === "amend")
|
|
88
|
-
terms = entry.data;
|
|
89
|
-
return event;
|
|
90
|
-
});
|
|
91
|
-
let unavailable;
|
|
92
|
-
let dispatches;
|
|
93
|
-
try {
|
|
94
|
-
dispatches = await readDispatchesAt(observation);
|
|
95
|
-
}
|
|
96
|
-
catch (error) {
|
|
97
|
-
const category = errorCategory(error);
|
|
98
|
-
if (category === "aborted" || this.scope.signal?.aborted === true)
|
|
99
|
-
throw error;
|
|
100
|
-
unavailable = {
|
|
101
|
-
kind: "unavailable",
|
|
102
|
-
category: category === "authority-corruption" ? category : "internal",
|
|
103
|
-
diagnostic: error instanceof Error ? error.message : String(error),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
events.push(...(dispatches ?? [])
|
|
107
|
-
.filter((dispatch) => dispatch.contractId === this.id)
|
|
108
|
-
.map((dispatch) => ({
|
|
109
|
-
kind: "dispatch",
|
|
110
|
-
at: dispatch.dispatchedAt,
|
|
111
|
-
akumaId: dispatch.akumaId,
|
|
112
|
-
})));
|
|
113
|
-
events.sort((left, right) => {
|
|
114
|
-
if (left.at !== right.at)
|
|
115
|
-
return left.at < right.at ? -1 : 1;
|
|
116
|
-
if ((left.kind === "dispatch") !== (right.kind === "dispatch"))
|
|
117
|
-
return left.kind === "dispatch" ? 1 : -1;
|
|
118
|
-
return 0;
|
|
119
|
-
});
|
|
120
|
-
return {
|
|
121
|
-
kind: "contract",
|
|
122
|
-
contractId: this.id,
|
|
123
|
-
events,
|
|
124
|
-
...(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)])),
|
|
125
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);
|
|
126
92
|
})));
|
|
127
93
|
}
|
|
128
94
|
async guidance() {
|
|
@@ -146,7 +112,7 @@ export class Kei {
|
|
|
146
112
|
const values = parsed.data;
|
|
147
113
|
const derived = values.gates === undefined ? undefined : derivedGates(this.composition, gateNames(values.gates));
|
|
148
114
|
return {
|
|
149
|
-
|
|
115
|
+
edits: values.edits,
|
|
150
116
|
target: values.target,
|
|
151
117
|
gates: derived,
|
|
152
118
|
prerequisites: values.after === undefined ? undefined : normalizedList(values.after, "after", callerContractId),
|
|
@@ -154,10 +120,10 @@ export class Kei {
|
|
|
154
120
|
});
|
|
155
121
|
}
|
|
156
122
|
async amend(input) {
|
|
157
|
-
const {
|
|
123
|
+
const { edits, target, gates, prerequisites } = this.amendInput(input);
|
|
158
124
|
const hooks = derivedHooks(this.composition);
|
|
159
|
-
const requestsChange =
|
|
160
|
-
const amendmentPlan =
|
|
125
|
+
const requestsChange = edits !== undefined || target !== undefined || gates !== undefined || prerequisites !== undefined;
|
|
126
|
+
const amendmentPlan = edits === undefined ? undefined : validated(() => prepareAmendDocument(edits));
|
|
161
127
|
let changedSections;
|
|
162
128
|
const concluded = await this.local("amend", async (accumulator, channel, scope) => {
|
|
163
129
|
const admission = await amendOperation({
|
|
@@ -407,8 +373,8 @@ export class Kei {
|
|
|
407
373
|
}
|
|
408
374
|
async arc(input) {
|
|
409
375
|
const chapter = validated(() => {
|
|
410
|
-
const values = requireInput(input, "arc input", ["
|
|
411
|
-
return decodeArcDocument(requireMarkdown(values.
|
|
376
|
+
const values = requireInput(input, "arc input", ["body"]);
|
|
377
|
+
return decodeArcDocument(requireMarkdown(values.body, "body"));
|
|
412
378
|
});
|
|
413
379
|
const hooks = derivedHooks(this.composition);
|
|
414
380
|
return await this.local("arc", async (accumulator, channel, scope) => {
|
|
@@ -500,7 +466,7 @@ export class Kei {
|
|
|
500
466
|
return value;
|
|
501
467
|
}
|
|
502
468
|
}
|
|
503
|
-
function changedHistoryTerms(before, after) {
|
|
469
|
+
function changedHistoryTerms(before, after, complete) {
|
|
504
470
|
const sections = (terms) => {
|
|
505
471
|
const document = parseToAST(terms.document.bytes);
|
|
506
472
|
return new Map(indexedHeadings(indexDocument(document), { level: 2 })
|
|
@@ -513,8 +479,12 @@ function changedHistoryTerms(before, after) {
|
|
|
513
479
|
const equal = (left, right) => left !== undefined && left.length === right.length && left.every((value, index) => value === right[index]);
|
|
514
480
|
return {
|
|
515
481
|
...(changedSections.length === 0 ? {} : { changedSections }),
|
|
516
|
-
...(
|
|
517
|
-
|
|
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
|
+
}),
|
|
518
488
|
};
|
|
519
489
|
}
|
|
520
490
|
function attestationHistory(entry) {
|
|
@@ -528,31 +498,52 @@ function attestationHistory(entry) {
|
|
|
528
498
|
...(summary === undefined ? {} : { summary }),
|
|
529
499
|
};
|
|
530
500
|
}
|
|
531
|
-
function historyTarget(target,
|
|
501
|
+
function historyTarget(target, complete) {
|
|
532
502
|
return target === undefined
|
|
533
503
|
? {}
|
|
534
504
|
: {
|
|
535
505
|
target: typeof target === "string" ? target : { kind: "contract", contractId: target.contractId },
|
|
536
|
-
...(
|
|
506
|
+
...(complete && typeof target === "object" ? { targetIncarnation: target.worktree } : {}),
|
|
537
507
|
};
|
|
538
508
|
}
|
|
539
|
-
|
|
540
|
-
|
|
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 };
|
|
541
537
|
switch (entry.kind) {
|
|
542
538
|
case "bind": {
|
|
543
539
|
const { coordinates, terms: bound } = entry.data;
|
|
544
|
-
const target = coordinates.target;
|
|
545
540
|
return {
|
|
546
541
|
...common,
|
|
547
542
|
kind: "bind",
|
|
548
543
|
start: coordinates.start,
|
|
549
|
-
...historyTarget(target,
|
|
550
|
-
...(
|
|
551
|
-
? {
|
|
552
|
-
document: bound.document.bytes,
|
|
553
|
-
gates: bound.gates,
|
|
554
|
-
after: bound.after,
|
|
555
|
-
}
|
|
544
|
+
...historyTarget(coordinates.target, complete),
|
|
545
|
+
...(complete
|
|
546
|
+
? { document: bound.document.bytes, gates: bound.gates, after: bound.after }
|
|
556
547
|
: {
|
|
557
548
|
...(bound.gates.length === 0 ? {} : { gates: bound.gates }),
|
|
558
549
|
...(bound.after.length === 0 ? {} : { after: bound.after }),
|
|
@@ -563,9 +554,9 @@ function historyEvent(entry, terms, full) {
|
|
|
563
554
|
return {
|
|
564
555
|
...common,
|
|
565
556
|
kind: "amend",
|
|
566
|
-
...historyTarget(entry.data.target,
|
|
567
|
-
...changedHistoryTerms(terms, entry.data),
|
|
568
|
-
...(
|
|
557
|
+
...historyTarget(entry.data.target, complete),
|
|
558
|
+
...changedHistoryTerms(terms, entry.data, complete),
|
|
559
|
+
...(complete ? { document: entry.data.document.bytes } : {}),
|
|
569
560
|
};
|
|
570
561
|
case "deliver": {
|
|
571
562
|
const { tenderSnapshot, integration, note } = entry.data;
|
|
@@ -577,7 +568,7 @@ function historyEvent(entry, terms, full) {
|
|
|
577
568
|
contentId: integration.changeId,
|
|
578
569
|
predecessor: integration.predecessor,
|
|
579
570
|
...(note === undefined ? {} : { note }),
|
|
580
|
-
...(
|
|
571
|
+
...(complete ? { requireBranchesToBeUpToDate: entry.data.policy.requireBranchesToBeUpToDate } : {}),
|
|
581
572
|
};
|
|
582
573
|
}
|
|
583
574
|
case "reintegrated":
|
|
@@ -589,15 +580,19 @@ function historyEvent(entry, terms, full) {
|
|
|
589
580
|
};
|
|
590
581
|
case "attestation":
|
|
591
582
|
return { ...common, ...attestationHistory(entry) };
|
|
592
|
-
case "claimed":
|
|
593
|
-
|
|
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
|
+
}
|
|
594
589
|
case "arc":
|
|
595
590
|
return {
|
|
596
591
|
...common,
|
|
597
592
|
kind: "arc",
|
|
598
593
|
chapter: entry.data.seq,
|
|
599
594
|
title: entry.data.title,
|
|
600
|
-
...(entry.data.body.length === 0 && !
|
|
595
|
+
...(entry.data.body.length === 0 && !complete ? {} : { body: entry.data.body }),
|
|
601
596
|
};
|
|
602
597
|
case "abandoned":
|
|
603
598
|
return {
|
|
@@ -607,6 +602,69 @@ function historyEvent(entry, terms, full) {
|
|
|
607
602
|
};
|
|
608
603
|
}
|
|
609
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
|
+
}
|
|
610
668
|
/** Internal constructor capability; callers select a Contract through Keis.of. */
|
|
611
669
|
export function createKeiHandle(id, scope, composition) {
|
|
612
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 = [
|
|
@@ -59,7 +59,11 @@ function classifyWait(result) {
|
|
|
59
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";
|
|
@@ -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
|
-
/** Actor declarations win;
|
|
7
|
-
export declare function akumaCallerFromEnvironment(environment: NodeJS.ProcessEnv,
|
|
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,
|
|
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,8 +45,8 @@ export async function akumaCallerFromEnvironment(environment, caller) {
|
|
|
22
45
|
const resolved = await World.resolve({ cwd: world, repositoryRoot: world });
|
|
23
46
|
return decodeAkumaCaller({ kind: "akuma", akumaId: id, world: resolved.candidate });
|
|
24
47
|
}
|
|
25
|
-
if (
|
|
26
|
-
return
|
|
48
|
+
if (owner !== undefined)
|
|
49
|
+
return callerFromOwner(owner);
|
|
27
50
|
const hosts = [
|
|
28
51
|
{ integration: "codex", variable: "CODEX_THREAD_ID", id: environment.CODEX_THREAD_ID },
|
|
29
52
|
{ integration: "pi", variable: "PI_SESSION_ID", id: environment.PI_SESSION_ID },
|
|
@@ -165,10 +188,10 @@ async function callerProfile(caller, coordinates, environment) {
|
|
|
165
188
|
return { profileUnavailable: reason(error) };
|
|
166
189
|
}
|
|
167
190
|
}
|
|
168
|
-
export async function whoami(coordinates, environment,
|
|
191
|
+
export async function whoami(coordinates, environment, owner) {
|
|
169
192
|
const world = coordinates.world !== null && (await World.established(coordinates.world)) ? coordinates.world : null;
|
|
170
193
|
const [self, contextContract] = await Promise.all([
|
|
171
|
-
selfFrom(environment,
|
|
194
|
+
selfFrom(environment, owner),
|
|
172
195
|
contextualContract(coordinates, world),
|
|
173
196
|
]);
|
|
174
197
|
const initiator = self.kind === "akuma" ? await currentTurn(self) : undefined;
|