@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.
Files changed (118) hide show
  1. package/README.md +10 -1
  2. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +5 -2
  3. package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +2 -1
  4. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +5 -2
  5. package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +2 -1
  6. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +5 -2
  7. package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +2 -1
  8. package/build/plugins/pi/keiyaku.ts +1 -135
  9. package/build/skills/keiyaku-akuma/SKILL.md +5 -2
  10. package/build/skills/keiyaku-debt/SKILL.md +2 -1
  11. package/build/src/akuma/akuma-observe.d.ts +8 -0
  12. package/build/src/akuma/akuma-observe.js +8 -0
  13. package/build/src/akuma/akuma-owner.d.ts +1 -0
  14. package/build/src/akuma/akuma-owner.js +3 -5
  15. package/build/src/akuma/akuma-wait.d.ts +117 -2
  16. package/build/src/akuma/akuma-wait.js +53 -22
  17. package/build/src/akuma/akuma.d.ts +6 -1
  18. package/build/src/akuma/akuma.js +37 -18
  19. package/build/src/akuma/heart/facts.d.ts +1 -0
  20. package/build/src/akuma/heart/facts.js +14 -0
  21. package/build/src/akuma/heart/index.d.ts +6 -0
  22. package/build/src/akuma/heart/index.js +27 -9
  23. package/build/src/akuma/heart/rows.d.ts +1 -0
  24. package/build/src/akuma/heart/rows.js +4 -0
  25. package/build/src/akuma/lineage-cache.d.ts +7 -2
  26. package/build/src/akuma/lineage-cache.js +48 -24
  27. package/build/src/akuma/projection-read.js +4 -9
  28. package/build/src/akuma/selection-observation.d.ts +622 -0
  29. package/build/src/akuma/selection-observation.js +7 -3
  30. package/build/src/bounded-list.d.ts +8 -0
  31. package/build/src/bounded-list.js +10 -0
  32. package/build/src/cli/commands/akuma-grammar.d.ts +2 -3
  33. package/build/src/cli/commands/akuma-grammar.js +32 -39
  34. package/build/src/cli/commands/akuma.js +6 -3
  35. package/build/src/cli/commands/contract-grammar.js +32 -31
  36. package/build/src/cli/commands/contract-help.d.ts +3 -3
  37. package/build/src/cli/commands/contract-help.js +10 -8
  38. package/build/src/cli/commands/contract.d.ts +3 -3
  39. package/build/src/cli/commands/contract.js +11 -10
  40. package/build/src/cli/parse.d.ts +4 -10
  41. package/build/src/cli/parse.js +1 -1
  42. package/build/src/cli/render/akuma-activity.d.ts +9 -19
  43. package/build/src/cli/render/akuma-activity.js +83 -110
  44. package/build/src/cli/render/catalog.js +3 -2
  45. package/build/src/cli/render/contract-history.d.ts +1 -3
  46. package/build/src/cli/render/contract-history.js +68 -49
  47. package/build/src/cli/render/contract-wait.js +9 -1
  48. package/build/src/cli/render/kanshi-akuma.d.ts +4 -3
  49. package/build/src/cli/render/kanshi-akuma.js +26 -21
  50. package/build/src/cli/render/kanshi.js +34 -43
  51. package/build/src/cli/render/verbs.js +20 -17
  52. package/build/src/cli/runtime.js +9 -23
  53. package/build/src/debt/board.d.ts +2 -1
  54. package/build/src/debt/board.js +3 -3
  55. package/build/src/debt/catalog.js +2 -1
  56. package/build/src/debt/document.d.ts +1 -0
  57. package/build/src/debt/document.js +3 -0
  58. package/build/src/debt/index.d.ts +2 -1
  59. package/build/src/debt/index.js +3 -3
  60. package/build/src/debt/operations.d.ts +2 -1
  61. package/build/src/git/observe.d.ts +4 -3
  62. package/build/src/git/observe.js +8 -7
  63. package/build/src/history.d.ts +26 -0
  64. package/build/src/history.js +43 -0
  65. package/build/src/index.d.ts +4 -3
  66. package/build/src/kanshi/counts.d.ts +15 -1
  67. package/build/src/kanshi/counts.js +14 -3
  68. package/build/src/kanshi/index.d.ts +3 -3
  69. package/build/src/kanshi/index.js +2 -2
  70. package/build/src/kanshi/read.js +5 -2
  71. package/build/src/library/akumas.d.ts +5 -1
  72. package/build/src/library/akumas.js +11 -5
  73. package/build/src/library/contract-composition.js +10 -10
  74. package/build/src/library/contract-creation.js +2 -2
  75. package/build/src/library/contract-types.d.ts +215 -25
  76. package/build/src/library/contract-types.js +31 -13
  77. package/build/src/library/contract-wait.d.ts +205 -0
  78. package/build/src/library/contract-wait.js +15 -3
  79. package/build/src/library/input.d.ts +3 -3
  80. package/build/src/library/input.js +5 -5
  81. package/build/src/library/kei.js +134 -76
  82. package/build/src/library/keiyaku-attribution.d.ts +1 -1
  83. package/build/src/library/keiyaku-attribution.js +3 -1
  84. package/build/src/library/keiyaku-classify.js +5 -1
  85. package/build/src/library/keiyaku-debt.d.ts +8 -7
  86. package/build/src/library/keiyaku-identity.d.ts +4 -3
  87. package/build/src/library/keiyaku-identity.js +30 -7
  88. package/build/src/library/keiyaku-verbs.d.ts +515 -44
  89. package/build/src/library/keiyaku-verbs.js +84 -79
  90. package/build/src/library/keiyaku-wait.d.ts +570 -0
  91. package/build/src/library/keiyaku-wait.js +25 -8
  92. package/build/src/library/keiyaku.d.ts +3110 -31
  93. package/build/src/library/keiyaku.js +335 -407
  94. package/build/src/library/model-tools.d.ts +268 -70
  95. package/build/src/library/model-tools.js +110 -95
  96. package/build/src/library/selection.d.ts +6 -5
  97. package/build/src/library/selection.js +10 -3
  98. package/build/src/mcp/adapter.js +1 -1
  99. package/build/src/mcp/help.d.ts +1 -1
  100. package/build/src/mcp/help.js +4 -3
  101. package/build/src/pi/index.d.ts +2 -0
  102. package/build/src/pi/index.js +23 -7
  103. package/build/src/pi/status.d.ts +12 -0
  104. package/build/src/pi/status.js +140 -0
  105. package/build/src/protocol/operations.d.ts +2 -0
  106. package/build/src/protocol/operations.js +1 -1
  107. package/build/src/protocol/read/status.d.ts +12 -4
  108. package/build/src/protocol/read/status.js +19 -12
  109. package/build/src/runtime/proc/windows-launch.exe +0 -0
  110. package/package.json +1 -1
  111. package/plugins/paseo/plugin/index.server.ts +6 -2
  112. package/plugins/paseo/plugin/server/attach.ts +68 -48
  113. package/plugins/paseo/plugin/server/directory.ts +259 -0
  114. package/plugins/paseo/plugin/server/mirror-identity.ts +3 -32
  115. package/plugins/paseo/plugin/server/reopen.ts +52 -38
  116. package/plugins/pi/keiyaku.ts +1 -135
  117. package/skills/keiyaku-akuma/SKILL.md +5 -2
  118. package/skills/keiyaku-debt/SKILL.md +2 -1
@@ -30,9 +30,6 @@ const TOOL_BUDGET = 3;
30
30
  function identity(id, alias) {
31
31
  return `${id}${alias === undefined ? "" : ` (${alias})`}`;
32
32
  }
33
- function associatedContractId(contract) {
34
- return contract.kind === "associated" ? contract.contractId : undefined;
35
- }
36
33
  /** The one human-fact separator of this family. */
37
34
  const FACT_SEPARATOR = " · ";
38
35
  /** A supporting fact of an action receipt or an observation panel is one indent deep. */
@@ -44,17 +41,13 @@ export function subordinateLines(lines) {
44
41
  /**
45
42
  * The one observation identity line: complete Akuma identity, optional alias as a parenthetical
46
43
  * supplement, and a known associated Contract inline behind the shared separator.
47
- */
48
- function panelIdentity(id, alias, contract) {
49
- const contractId = contract === undefined ? undefined : associatedContractId(contract);
50
- return `${identity(id, alias)}${contractId === undefined ? "" : `${FACT_SEPARATOR}${contractId}`}`;
51
- }
52
- /**
53
- * Identity and its static coordinates. The execution directory and any already-exposed effective
54
- * actions belong above the content boundary; an absent coordinate is an absent line.
44
+ * The execution directory and any already-exposed effective actions belong above the content
45
+ * boundary; an absent coordinate is an absent line.
55
46
  */
56
47
  export function panelHead(id, alias, contract, context = []) {
57
- return [panelIdentity(id, alias, contract), ...subordinateLines(context)];
48
+ const contractId = contract?.kind === "associated" ? contract.contractId : undefined;
49
+ const line = `${identity(id, alias)}${contractId === undefined ? "" : `${FACT_SEPARATOR}${contractId}`}`;
50
+ return [line, ...subordinateLines(context)];
58
51
  }
59
52
  /**
60
53
  * One action receipt: the verdict and the complete subject on the first line, every supporting fact
@@ -413,17 +406,6 @@ function lifeConclusion(life, pending) {
413
406
  return { mark: "?", verb: "hung" };
414
407
  return { mark: "!", verb: life };
415
408
  }
416
- function conclusionMarkVerb(status, outcome) {
417
- if (outcome === "failed" || (status !== undefined && failedOutcomeDiagnostic(status) !== undefined))
418
- return { mark: "!", verb: "failed" };
419
- if (outcome === "answered")
420
- return { mark: "✓", verb: "answered" };
421
- if (outcome === "unanswered")
422
- return { mark: "○", verb: "unanswered" };
423
- if (status === undefined)
424
- return { mark: "⧗", verb: "pending tell" };
425
- return lifeConclusion(status.life, !defaultWaitComplete(status));
426
- }
427
409
  function durationText(durationMs) {
428
410
  const seconds = Math.max(0, Math.round(durationMs / 1000));
429
411
  if (seconds < 60)
@@ -434,37 +416,33 @@ function durationText(durationMs) {
434
416
  * One wait-style conclusion for every observer of an input-bound Tell. A target
435
417
  * that settled at or after this wait began keeps its duration, a target already
436
418
  * settled names no duration, and an unfinished target carries the elapsed wait.
419
+ * An ended wait is the deadline itself, so it never reads a pinned completion.
437
420
  */
438
- function waitConclusionRow(input) {
439
- const duration = input.complete
440
- ? input.at !== undefined && input.at >= input.startedAt
441
- ? ` — ${durationText(Math.max(0, input.at - input.startedAt))}`
442
- : ""
443
- : input.end === undefined || !Number.isFinite(input.startedAt)
444
- ? ""
445
- : ` — waited ${durationText(Math.max(0, input.end - input.startedAt))}`;
446
- return `${input.mark} ${input.verb}${duration}`;
447
- }
448
- export function inputWaitConclusion(observation, input) {
449
- const end = input.now;
450
- const complete = observation.kind !== "deadline";
421
+ function waitConclusion(observation, input) {
422
+ const ended = observation.kind === "deadline";
451
423
  const pinned = input.completedAt == null ? Number.NaN : Date.parse(input.completedAt);
452
- const at = complete ? (Number.isFinite(pinned) ? pinned : undefined) : end;
453
- const conclusion = conclusionMarkVerb(input.status, observation.kind === "answered"
454
- ? "answered"
455
- : observation.kind === "failed" || observation.kind === "invalid-output"
456
- ? "failed"
424
+ const at = ended ? input.now : Number.isFinite(pinned) ? pinned : undefined;
425
+ const failed = observation.kind === "failed" ||
426
+ observation.kind === "invalid-output" ||
427
+ (input.status !== undefined && failedOutcomeDiagnostic(input.status) !== undefined);
428
+ const state = failed
429
+ ? { mark: "!", verb: "failed" }
430
+ : observation.kind === "answered"
431
+ ? { mark: "✓", verb: "answered" }
457
432
  : observation.kind === "unanswered"
458
- ? "unanswered"
459
- : "life");
433
+ ? { mark: "○", verb: "unanswered" }
434
+ : input.status === undefined
435
+ ? { mark: "⧗", verb: "pending tell" }
436
+ : lifeConclusion(input.status.life, !defaultWaitComplete(input.status));
437
+ const elapsed = ended
438
+ ? at === undefined || !Number.isFinite(input.startedAt)
439
+ ? ""
440
+ : ` — waited ${durationText(Math.max(0, at - input.startedAt))}`
441
+ : at !== undefined && at >= input.startedAt
442
+ ? ` — ${durationText(Math.max(0, at - input.startedAt))}`
443
+ : "";
460
444
  return [
461
- waitConclusionRow({
462
- ...(at === undefined ? {} : { at }),
463
- startedAt: input.startedAt,
464
- complete,
465
- ...(end === undefined ? {} : { end }),
466
- ...conclusion,
467
- }),
445
+ `${state.mark} ${state.verb}${elapsed}`,
468
446
  ...(observation.kind === "failed" || observation.kind === "invalid-output"
469
447
  ? [`! ${safeText(observation.diagnostic)}`]
470
448
  : []),
@@ -539,7 +517,7 @@ export function inputWaitStream(context, head, options) {
539
517
  }
540
518
  else {
541
519
  const currentTime = now();
542
- lines.push(...inputWaitConclusion(result.observation, {
520
+ lines.push(...waitConclusion(result.observation, {
543
521
  startedAt,
544
522
  ...(result.completedAt === undefined ? {} : { completedAt: result.completedAt }),
545
523
  ...(currentTime === undefined ? {} : { now: currentTime }),
@@ -583,41 +561,31 @@ export function currentWorkLines(work, context) {
583
561
  : [`${work.outcome.verdict} ${work.outcome.historyId} · activity ${work.outcome.activityId}`]),
584
562
  ];
585
563
  }
586
- function snapshotCore(view, context, options) {
587
- const activity = currentWorkLines(view.work, context);
564
+ function snapshotConclusion(status) {
565
+ const conclusion = lifeConclusion(status.life, status.work.pending !== undefined);
566
+ return `${conclusion.mark} ${conclusion.verb}${status.strandedReason === undefined ? "" : ` · ${status.strandedReason}`}`;
567
+ }
568
+ export function snapshotText(view, context, options = {}) {
588
569
  // A source later than the observation reads as the whole word `now`, so the surface only appends
589
570
  // a unit suffix when the age actually names a unit.
590
571
  const activityAge = view.lastActivityAt === undefined
591
572
  ? undefined
592
573
  : ageText(view.lastActivityAt, new Date(context.now ?? Date.now()).toISOString());
593
- const contextFacts = [
574
+ const head = panelHead(view.id, options.alias, view.contract, [
594
575
  safeText(view.cwd),
595
576
  ...(activityAge === undefined
596
577
  ? []
597
578
  : [`${view.life} · last activity ${activityAge === "now" ? activityAge : `${activityAge} ago`}`]),
598
- ];
599
- const facts = [
600
- ...contractFacts(view.contract ?? { kind: "none" }, context.columns - SUBORDINATE_INDENT.length),
601
- ...(options.facts ?? []),
602
- ];
603
- return {
604
- activity,
605
- head: panelHead(view.id, options.alias, view.contract, contextFacts),
606
- facts,
607
- };
608
- }
609
- function snapshotConclusion(status) {
610
- const conclusion = lifeConclusion(status.life, status.work.pending !== undefined);
611
- return `${conclusion.mark} ${conclusion.verb}${status.strandedReason === undefined ? "" : ` · ${status.strandedReason}`}`;
612
- }
613
- export function snapshotText(view, context, options = {}) {
614
- const core = snapshotCore(view, context, options);
579
+ ]);
615
580
  const conclusion = snapshotConclusion(view);
616
- const content = [...core.activity, ...(conclusion.length === 0 ? [] : [conclusion])];
581
+ const content = [...currentWorkLines(view.work, context), ...(conclusion.length === 0 ? [] : [conclusion])];
617
582
  return [
618
- ...core.head,
619
- ...(content.length === 0 ? [] : [frameRule(core.head, context.columns), ...content]),
620
- ...subordinateLines([...renderReportedChangeLines(view), ...core.facts]),
583
+ ...head,
584
+ ...(content.length === 0 ? [] : [frameRule(head, context.columns), ...content]),
585
+ ...subordinateLines([
586
+ ...renderReportedChangeLines(view),
587
+ ...contractFacts(view.contract ?? { kind: "none" }, context.columns - SUBORDINATE_INDENT.length),
588
+ ]),
621
589
  ].join("\n");
622
590
  }
623
591
  function killResultLabel(evidence) {
@@ -679,19 +647,9 @@ export function historyRawAnswer(result, historyId) {
679
647
  }
680
648
  /** One compact wait result line: an observed life mark, the complete identity, a bounded summary. */
681
649
  const WAIT_SUMMARY_SEPARATOR = " — ";
682
- const WAIT_LIFE = {
683
- running: { mark: "●", state: "running" },
684
- killed: { mark: "×", state: "killed" },
685
- hung: { mark: "?", state: "hung" },
686
- untidy: { mark: "!", state: "untidy" },
687
- stranded: { mark: "!", state: "stranded" },
688
- };
689
650
  function foldedSummary(value) {
690
651
  return safeText(value).replace(/\s+/gu, " ").trim();
691
652
  }
692
- function preview(value, fallback) {
693
- return foldedSummary(value) || fallback;
694
- }
695
653
  function waitLine(mark, subject, summary, columns) {
696
654
  const head = `${mark} ${subject}`;
697
655
  const room = columns - displayColumns(head) - displayColumns(WAIT_SUMMARY_SEPARATOR);
@@ -703,38 +661,31 @@ function waitLine(mark, subject, summary, columns) {
703
661
  /**
704
662
  * The final public snapshot as one wait summary. A stopped life stays explicit over any older
705
663
  * outcome; pending input stays visible beside the life it belongs to; a sleeping member without
706
- * pending input shows its current answered preview or failed diagnostic, else completion. The
707
- * mark reports the observed life, never continuing liveness.
664
+ * pending input shows its settled outcome, else completion. The mark reports the observed life,
665
+ * never continuing liveness.
708
666
  */
709
667
  function waitSummary(member) {
710
668
  const pending = member.pending !== undefined;
711
669
  const outcome = member.outcome;
712
- const life = WAIT_LIFE[member.life];
713
- const observed = life ??
714
- (pending
715
- ? { mark: "⧗", state: "pending tell" }
716
- : outcome === undefined
717
- ? { mark: "✓", state: "completed" }
718
- : outcome.kind === "answered"
719
- ? { mark: "✓", state: preview(outcome.answer, "answered") }
720
- : outcome.kind === "canceled"
721
- ? { mark: "○", state: "canceled" }
722
- : { mark: "!", state: preview(outcome.diagnostic, "failed") });
670
+ const observed = member.life === "asleep" && !pending && outcome !== undefined
671
+ ? outcome.kind === "answered"
672
+ ? { mark: "✓", verb: "answered" }
673
+ : outcome.kind === "canceled"
674
+ ? { mark: "○", verb: "canceled" }
675
+ : { mark: "!", verb: "failed" }
676
+ : lifeConclusion(member.life, pending);
677
+ const stopped = member.life !== "asleep";
723
678
  return {
724
- ...observed,
679
+ mark: observed.mark,
725
680
  summary: [
726
- observed.state,
727
- ...(pending && life !== undefined ? ["pending tell"] : []),
728
- ...(outcome?.kind === "failed" && (life !== undefined || pending) ? [preview(outcome.diagnostic, "failed")] : []),
681
+ observed.verb,
682
+ ...(pending && stopped ? ["pending tell"] : []),
683
+ ...(outcome?.kind === "failed" && (stopped || pending) ? ["failed"] : []),
729
684
  ...(member.strandedReason === undefined ? [] : [member.strandedReason]),
730
685
  ].join(FACT_SEPARATOR),
731
686
  };
732
687
  }
733
- /**
734
- * One wait's final text: one compact line per observed member, then one failure line per member
735
- * the wait could not read. A wait opens no frame and extracts no separate answer, so an answer is
736
- * visible only as the snapshot's own bounded summary.
737
- */
688
+ /** Compact final facts, actual recent events, and an exact-turn full outcome; never a live frame. */
738
689
  export function waitText(result, presentation, context) {
739
690
  const alias = result.results.length === 1 ? presentation.alias : undefined;
740
691
  return result.results
@@ -744,7 +695,29 @@ export function waitText(result, presentation, context) {
744
695
  if (member.kind === "unobserved")
745
696
  return waitLine("!", identity(member.id, alias), `observation failed${FACT_SEPARATOR}${member.diagnostic}`, context.columns);
746
697
  const { mark, summary } = waitSummary(member);
747
- return waitLine(mark, identity(member.id, alias), summary, context.columns);
698
+ const outcome = member.outcome;
699
+ const payload = outcome?.kind === "answered" ? outcome.answer : outcome?.kind === "failed" ? outcome.diagnostic : undefined;
700
+ return [
701
+ waitLine(mark, identity(member.id, alias), summary, context.columns),
702
+ ...(member.lastActivityAt === undefined ? [] : [` activity ${safeText(member.lastActivityAt)}`]),
703
+ ...groupedRows(member.events ?? [], context),
704
+ ...(member.eventsUnavailable === undefined
705
+ ? []
706
+ : diagnosticLines("recent activity", member.eventsUnavailable, context.columns, { state: "unavailable" })),
707
+ ...(outcome === undefined ? [] : [` ${outcome.historyId} · ${outcome.kind}`]),
708
+ ...(payload === undefined
709
+ ? []
710
+ : renderBoundedPayload({
711
+ text: payload,
712
+ first: " ",
713
+ continuation: " ",
714
+ columns: context.columns,
715
+ maxLines: Number.MAX_SAFE_INTEGER,
716
+ quote: "",
717
+ preserveLines: true,
718
+ truncated: false,
719
+ })),
720
+ ].join("\n");
748
721
  })
749
722
  .join("\n");
750
723
  }
@@ -752,8 +725,8 @@ export function historyText(result, presentation, context) {
752
725
  if (presentation.id !== undefined) {
753
726
  return historyRawAnswer(result, presentation.id) ?? `${presentation.id} has no matching retained history`;
754
727
  }
755
- if (presentation.last === true)
756
- return result.kind === "akuma-last" ? result.answer : "no answer retained";
728
+ if (presentation.answer === true)
729
+ return result.kind === "akuma-answer" ? result.answer : "no answer retained";
757
730
  if (result.kind !== "akuma")
758
731
  throw new Error("history result lacks page");
759
732
  const rows = groupedRows(result.events, context, { history: true });
@@ -1,10 +1,11 @@
1
- import { contractAttentionFacts, progressStrip } from "./contract-observation.js";
1
+ import { contractAttentionFacts, lifecycleWord, progressStrip } from "./contract-observation.js";
2
2
  import { ageText, emptyCatalogue, safeText } from "./terminal.js";
3
3
  import { contractMark } from "./marks.js";
4
4
  /** One summary row names identity, age, title, and a terminal outcome or the current candidate strip. */
5
5
  function contractCatalogueBlock(row, observedAt) {
6
6
  const head = `${contractMark(row)} ${safeText(row.id)} · ${ageText(row.phaseAt, observedAt, "future")} · ${safeText(row.title ?? "title unavailable")}`;
7
- return [head, ` ${progressStrip(row)}`, ...contractAttentionFacts(row).map((fact) => ` ${safeText(fact)}`)].join("\n");
7
+ const state = row.phase === "bound" ? progressStrip(row) : lifecycleWord(row.phase);
8
+ return [head, ` ${state}`, ...contractAttentionFacts(row).map((fact) => ` ${safeText(fact)}`)].join("\n");
8
9
  }
9
10
  export function renderContractCatalogue(list) {
10
11
  const rows = list.rows ?? [];
@@ -1,6 +1,4 @@
1
1
  import type { ContractHistory } from "../../index.js";
2
2
  export declare function renderContractHistory(history: Extract<ContractHistory, {
3
- kind: "contract";
4
- }>, options?: Readonly<{
5
- full?: boolean;
3
+ kind: "contract" | "contract-exact";
6
4
  }>): string;
@@ -1,8 +1,47 @@
1
1
  import { gateDisplayName, lifecycleWord, shortGitId } from "./contract-observation.js";
2
- import { receiptPayload } from "./receipt.js";
3
2
  import { DEFAULT_CLI_COLUMNS, renderOpaqueBlock, safeText } from "./terminal.js";
4
3
  function listFact(label, values) {
5
- return values === undefined || values.length === 0 ? [] : [` ${label} ${values.map(safeText).join(" · ")}`];
4
+ return values === undefined ? [] : [` ${label} ${values.length === 0 ? "none" : values.map(safeText).join(" · ")}`];
5
+ }
6
+ function historicalPayload(label, payload) {
7
+ return [` ${label}`, ...payload.split("\n").map((line) => (line.length === 0 ? "" : ` ${safeText(line)}`))];
8
+ }
9
+ /** Lay out a recorded dependency-key set as its labeled facts; unknown representations stay literal. */
10
+ function subjectFact(subject) {
11
+ let parsed;
12
+ try {
13
+ parsed = JSON.parse(subject);
14
+ }
15
+ catch {
16
+ return safeText(subject);
17
+ }
18
+ if (!Array.isArray(parsed) || parsed.length === 0)
19
+ return safeText(subject);
20
+ const parts = [];
21
+ for (const key of parsed) {
22
+ if (!Array.isArray(key) || key.length !== 2)
23
+ return safeText(subject);
24
+ const [kind, identity] = key;
25
+ if (typeof kind !== "string" || typeof identity !== "string")
26
+ return safeText(subject);
27
+ const value = safeText(identity);
28
+ switch (kind) {
29
+ case "change":
30
+ case "document":
31
+ case "segment":
32
+ parts.push(`${kind} ${value}`);
33
+ break;
34
+ case "snapshot":
35
+ parts.push(`snapshot ${shortGitId(value)}`);
36
+ break;
37
+ case "target":
38
+ parts.push(`target revision ${value}`);
39
+ break;
40
+ default:
41
+ return safeText(subject);
42
+ }
43
+ }
44
+ return parts.join(" · ");
6
45
  }
7
46
  function targetName(target) {
8
47
  if (target === undefined)
@@ -19,15 +58,14 @@ function payloadSuffix(payload) {
19
58
  const count = renderOpaqueBlock(payload, " ", DEFAULT_CLI_COLUMNS).length;
20
59
  return ` · ${count} line${count === 1 ? "" : "s"}`;
21
60
  }
22
- function eventLine(event, dispatches = []) {
61
+ function eventLine(event) {
23
62
  switch (event.kind) {
24
63
  case "dispatch":
25
64
  return `dispatch · ${event.akumaId}`;
26
65
  case "bind": {
27
66
  const gates = event.gates?.map(gateDisplayName) ?? [];
28
67
  const gateFact = gates.length === 0 ? "" : ` · ${gates.length === 1 ? "gate" : "gates"} ${gates.join(" · ")}`;
29
- const callers = dispatches.flatMap((item) => (item.kind === "dispatch" ? [` · ${item.akumaId}`] : [])).join("");
30
- return `bound to ${targetName(event.target)} @ ${shortGitId(event.start)}${gateFact}${callers}`;
68
+ return `bound to ${targetName(event.target)} @ ${shortGitId(event.start)}${gateFact}`;
31
69
  }
32
70
  case "amend": {
33
71
  const changed = [
@@ -44,7 +82,7 @@ function eventLine(event, dispatches = []) {
44
82
  return `integrated ${shortGitId(event.predecessor)}..${shortGitId(event.integration)}`;
45
83
  case "attestation": {
46
84
  const requirement = event.gate === "verified" || event.requirement !== `gate:${event.gate}` ? ` ${event.requirement}` : "";
47
- return `${event.verdict === "satisfied" ? "✓" : "×"} ${gateDisplayName(event.gate)}${requirement} · subject ${safeText(event.subject)}${payloadSuffix(event.summary)}`;
85
+ return `${event.verdict === "satisfied" ? "✓" : "×"} ${gateDisplayName(event.gate)}${requirement} · subject ${subjectFact(event.subject)}${payloadSuffix(event.summary)}`;
48
86
  }
49
87
  case "claimed":
50
88
  return lifecycleWord("claimed");
@@ -80,7 +118,7 @@ function semanticBody(event) {
80
118
  ` content identity ${event.contentId}`,
81
119
  ];
82
120
  if (event.note !== undefined)
83
- receiptPayload(lines, "note", event.note);
121
+ lines.push(...historicalPayload("note", event.note));
84
122
  return lines;
85
123
  }
86
124
  case "reintegrated":
@@ -93,10 +131,10 @@ function semanticBody(event) {
93
131
  ` gate ${event.gate}`,
94
132
  ` requirement ${event.requirement}`,
95
133
  ` verdict ${event.verdict}`,
96
- ` subject ${safeText(event.subject)}`,
134
+ ` subject ${subjectFact(event.subject)}`,
97
135
  ];
98
136
  if (event.summary !== undefined)
99
- receiptPayload(lines, "summary", event.summary);
137
+ lines.push(...historicalPayload("summary", event.summary));
100
138
  return lines;
101
139
  }
102
140
  case "claimed":
@@ -105,28 +143,25 @@ function semanticBody(event) {
105
143
  return [
106
144
  ` sequence ${event.chapter}`,
107
145
  ` title ${safeText(event.title)}`,
108
- ...(event.body === undefined ? [] : [" body", ...renderOpaqueBlock(event.body, " ", DEFAULT_CLI_COLUMNS)]),
146
+ ...(event.body === undefined ? [] : historicalPayload("body", event.body)),
109
147
  ];
110
148
  case "abandoned": {
111
149
  const lines = [];
112
150
  if (event.note !== undefined)
113
- receiptPayload(lines, "note", event.note);
151
+ lines.push(...historicalPayload("note", event.note));
114
152
  return lines;
115
153
  }
116
154
  }
117
155
  }
118
- /** Full mode exposes supplied historical facts, never a current-state reread. */
119
- function fullEventLines(event) {
120
- const identity = event.kind === "dispatch" ? event.akumaId : event.id;
121
- const header = `${event.at} ${event.kind} · ${identity}`;
122
- const detail = [
156
+ /** One complete retained record, without substituting a current-state read. */
157
+ function exactEventLines(event) {
158
+ return [
159
+ `${event.at} ${event.kind} · ${event.id}`,
123
160
  ...semanticBody(event),
124
161
  ...(event.kind === "bind" || event.kind === "amend"
125
162
  ? [
126
- ...(event.document === undefined
127
- ? []
128
- : [" document", ...renderOpaqueBlock(event.document, " ", DEFAULT_CLI_COLUMNS)]),
129
- ...(event.kind !== "bind" || event.targetIncarnation === undefined
163
+ ...(event.document === undefined ? [] : historicalPayload("document", event.document)),
164
+ ...(event.targetIncarnation === undefined
130
165
  ? []
131
166
  : [
132
167
  ` target incarnation ${safeText(event.targetIncarnation.id)} · ${safeText(event.targetIncarnation.identity)}`,
@@ -137,35 +172,22 @@ function fullEventLines(event) {
137
172
  ? []
138
173
  : [` require branches up to date ${event.requireBranchesToBeUpToDate}`]),
139
174
  ];
140
- return [header, ...detail];
141
175
  }
142
- export function renderContractHistory(history, options = {}) {
176
+ export function renderContractHistory(history) {
177
+ const header = `history ${history.contractId}`;
178
+ if (history.kind === "contract-exact")
179
+ return [header, "", ...exactEventLines(history.event)].join("\n");
143
180
  const journals = history.events.filter((event) => event.kind !== "dispatch").length;
144
181
  const dispatches = history.events.length - journals;
145
182
  const counts = [
146
- ...(journals === 0
147
- ? []
148
- : [`${journals} ${options.full === true ? "journal " : ""}${journals === 1 ? "entry" : "entries"}`]),
183
+ ...(journals === 0 ? [] : [`${journals} ${journals === 1 ? "entry" : "entries"}`]),
149
184
  ...(dispatches === 0 ? [] : [`${dispatches} ${dispatches === 1 ? "dispatch" : "dispatches"}`]),
150
185
  ];
151
- const state = history.events.some((event) => event.kind === "claimed")
152
- ? lifecycleWord("claimed")
153
- : history.events.some((event) => event.kind === "abandoned")
154
- ? "abandoned"
155
- : "bound";
156
- const header = `history ${history.contractId}${options.full === true ? "" : ` · ${state}`}${counts.length === 0 ? "" : ` · ${counts.join(" · ")}`}`;
157
- const failure = history.dispatches === undefined
158
- ? []
159
- : [
160
- "",
161
- `! Dispatch history unavailable · ${history.dispatches.category} · ${safeText(history.dispatches.diagnostic)}`,
162
- ];
163
- if (options.full === true)
164
- return [header, "", ...history.events.flatMap(fullEventLines), ...failure].join("\n");
165
- const lines = [header, ""];
186
+ const lines = [header + (counts.length === 0 ? "" : ` · ${counts.join(" · ")}`), ""];
187
+ if (history.omitted !== undefined)
188
+ lines.push(`… ${history.omitted} journal entries omitted`, "");
166
189
  let day;
167
- for (let index = 0; index < history.events.length; index += 1) {
168
- const event = history.events[index];
190
+ for (const event of history.events) {
169
191
  const nextDay = event.at.slice(0, 10);
170
192
  if (nextDay !== day) {
171
193
  if (day !== undefined)
@@ -173,12 +195,9 @@ export function renderContractHistory(history, options = {}) {
173
195
  lines.push(nextDay, "");
174
196
  day = nextDay;
175
197
  }
176
- const adjacent = [];
177
- if (event.kind === "bind") {
178
- while (history.events[index + 1]?.kind === "dispatch")
179
- adjacent.push(history.events[++index]);
180
- }
181
- lines.push(`${clock(event)} ${eventLine(event, adjacent)}`);
198
+ lines.push(`${clock(event)} ${event.kind === "dispatch" ? "" : `${event.id} `}${eventLine(event)}`);
182
199
  }
183
- return [...lines, ...failure].join("\n");
200
+ if (history.dispatches !== undefined)
201
+ lines.push("", `! Dispatch history unavailable · ${history.dispatches.category} · ${safeText(history.dispatches.diagnostic)}`);
202
+ return lines.join("\n");
184
203
  }
@@ -1,3 +1,5 @@
1
+ import { progressStrip } from "./contract-observation.js";
2
+ import { safeText } from "./terminal.js";
1
3
  export function contractWaitMemberText(member) {
2
4
  const facts = [];
3
5
  if (member.presence === "unknown")
@@ -10,5 +12,11 @@ export function contractWaitMemberText(member) {
10
12
  if (member.terminal !== undefined)
11
13
  facts.push(member.terminal === "claimed" ? "accepted" : "abandoned");
12
14
  }
13
- return `${member.id}${facts.length === 0 ? "" : ` (${facts.join(", ")})`}`;
15
+ const head = `${member.id}${facts.length === 0 ? "" : ` (${facts.join(", ")})`}`;
16
+ return member.summary === undefined
17
+ ? head
18
+ : [
19
+ `${head}${member.summary.title === undefined ? "" : ` · ${safeText(member.summary.title)}`}`,
20
+ ` ${progressStrip(member.summary)}`,
21
+ ].join("\n");
14
22
  }
@@ -3,16 +3,17 @@ import { type TextRenderContext } from "./terminal.js";
3
3
  declare const NARROW_COLUMNS = 72;
4
4
  declare function akumaLabel(row: Pick<AkumaKanshiRow, "aliases">, aliasesUnavailable: boolean): string;
5
5
  declare function associationFact(contract: NonNullable<AkumaKanshiRow["contract"]>): string;
6
+ declare function akumaRowLines(row: AkumaKanshiRow, aliasesUnavailable: boolean, observedAt: string, context: TextRenderContext, caller?: string): readonly string[];
6
7
  /**
7
8
  * One Akuma board section. The World board omits an empty section because its other
8
9
  * sections already say what the World holds; a standalone catalogue states its
9
10
  * own emptiness. A failed Alias observation belongs to the
10
11
  * section, so an empty roster still states its emptiness rather than dropping that
11
- * evidence.
12
+ * evidence. `rows` narrows a present section to one already-partitioned subset.
12
13
  */
13
14
  declare function renderAkumaBoard(section: BoardSection<AkumaKanshiWorld>, observedAt: string, context: TextRenderContext & Readonly<{
14
15
  caller?: string;
15
- }>, emptyRows?: readonly string[]): readonly string[];
16
+ }>, emptyRows?: readonly string[], rows?: readonly AkumaKanshiRow[] | undefined): readonly string[];
16
17
  declare function renderAkuma(report: KanshiReport, context: TextRenderContext): readonly string[];
17
18
  declare function formatAge(source: string | null | undefined, observedAt: string): string;
18
- export { akumaLabel, associationFact, formatAge, NARROW_COLUMNS, renderAkuma, renderAkumaBoard };
19
+ export { akumaLabel, akumaRowLines, associationFact, formatAge, NARROW_COLUMNS, renderAkuma, renderAkumaBoard };
@@ -1,6 +1,6 @@
1
1
  import { currentWorkLines } from "./akuma-activity.js";
2
2
  import { akumaMark } from "./marks.js";
3
- import { ageText, elapsedMilliseconds, emptyCatalogue, entityLines, identityLine, RECENT_TONE_MS, renderSectionBlock, safeText, tone, } from "./terminal.js";
3
+ import { ageText, elapsedMilliseconds, emptyCatalogue, entityLines, identityLine, RECENT_TONE_MS, safeText, tone, } from "./terminal.js";
4
4
  const NARROW_COLUMNS = 72;
5
5
  const ACTIVITY_INDENT = " ";
6
6
  function mostRecentTimestamp(...values) {
@@ -83,40 +83,45 @@ function akumaRowLines(row, aliasesUnavailable, observedAt, context, caller) {
83
83
  ...previewLines,
84
84
  ];
85
85
  }
86
- function akumaBoardRows(board, rows, observedAt, context, caller) {
87
- const aliasesUnavailable = board.aliasesError !== undefined;
88
- const rendered = renderSectionBlock({
89
- name: "AKUMA",
90
- rows: rows.map((row) => akumaRowLines(row, aliasesUnavailable, observedAt, context, caller)),
91
- hasMore: board.more === true,
92
- });
93
- return [`AKUMA // ${rows.length} recent`, ...rendered.slice(1)];
94
- }
95
86
  /**
96
87
  * One Akuma board section. The World board omits an empty section because its other
97
88
  * sections already say what the World holds; a standalone catalogue states its
98
89
  * own emptiness. A failed Alias observation belongs to the
99
90
  * section, so an empty roster still states its emptiness rather than dropping that
100
- * evidence.
91
+ * evidence. `rows` narrows a present section to one already-partitioned subset.
101
92
  */
102
- function renderAkumaBoard(section, observedAt, context, emptyRows = [emptyCatalogue("akuma")]) {
93
+ function renderAkumaBoard(section, observedAt, context, emptyRows = [emptyCatalogue("akuma")], rows = section.kind === "present" ? (section.rows ?? []) : []) {
103
94
  if (section.kind === "absent")
104
95
  return ["AKUMA // absent"];
105
96
  if (section.kind === "failed") {
106
97
  return ["AKUMA // unavailable", "", tone(`! ${safeText(section.diagnostic)}`, "alert", context.color)];
107
98
  }
108
- const board = section;
109
- const rows = board.rows ?? [];
110
- const aliasFailure = board.aliasesError;
99
+ const aliasesUnavailable = section.aliasesError !== undefined;
111
100
  if (rows.length === 0) {
112
- if (aliasFailure === undefined)
113
- return emptyRows;
101
+ // A non-empty complete page narrowed to no rows has all its evidence nested elsewhere.
102
+ if ((section.rows ?? []).length > 0) {
103
+ const evidence = [
104
+ ...(section.aliasesError === undefined
105
+ ? []
106
+ : [tone(`! aliases unavailable · ${safeText(section.aliasesError)}`, "alert", context.color)]),
107
+ ...(section.more === true ? ["…"] : []),
108
+ ];
109
+ return evidence.length === 0 ? [] : ["AKUMA", "", ...evidence];
110
+ }
111
+ const empty = emptyRows.length === 0 && section.aliasesError !== undefined ? [emptyCatalogue("akuma")] : emptyRows;
114
112
  return [
115
- ...(emptyRows.length === 0 ? [emptyCatalogue("akuma")] : emptyRows),
116
- tone(`! aliases unavailable · ${aliasFailure}`, "alert", context.color),
113
+ ...empty,
114
+ ...(section.aliasesError === undefined
115
+ ? []
116
+ : [tone(`! aliases unavailable · ${section.aliasesError}`, "alert", context.color)]),
117
117
  ];
118
118
  }
119
- return akumaBoardRows(board, rows, observedAt, context, context.caller);
119
+ return [
120
+ `AKUMA // ${rows.length} recent`,
121
+ "",
122
+ ...rows.flatMap((row) => akumaRowLines(row, aliasesUnavailable, observedAt, context, context.caller)),
123
+ ...(section.more === true ? ["…"] : []),
124
+ ];
120
125
  }
121
126
  function renderAkuma(report, context) {
122
127
  return renderAkumaBoard(report.akumas, report.observedAt, context, []);
@@ -126,4 +131,4 @@ function formatAge(source, observedAt) {
126
131
  return "—";
127
132
  return ageText(source, observedAt);
128
133
  }
129
- export { akumaLabel, associationFact, formatAge, NARROW_COLUMNS, renderAkuma, renderAkumaBoard };
134
+ export { akumaLabel, akumaRowLines, associationFact, formatAge, NARROW_COLUMNS, renderAkuma, renderAkumaBoard };