@astrosheep/keiyaku 4.6.28 → 4.6.29

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 (33) hide show
  1. package/build/plugins/claude/.claude-plugin/plugin.json +1 -1
  2. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +2 -0
  3. package/build/plugins/codex/.codex-plugin/plugin.json +1 -1
  4. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +2 -0
  5. package/build/plugins/opencode/package.json +1 -1
  6. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +2 -0
  7. package/build/plugins/pi/README.md +10 -0
  8. package/build/plugins/pi/akuma-tools.ts +2 -2
  9. package/build/plugins/pi/keiyaku.ts +73 -1
  10. package/build/skills/keiyaku-akuma/SKILL.md +2 -0
  11. package/build/src/akuma/akuma-owner.js +5 -4
  12. package/build/src/akuma/akuma.d.ts +2 -0
  13. package/build/src/akuma/akuma.js +17 -5
  14. package/build/src/akuma/identity.d.ts +4 -0
  15. package/build/src/akuma/identity.js +7 -0
  16. package/build/src/akuma/projection.d.ts +7 -1
  17. package/build/src/akuma/projection.js +6 -1
  18. package/build/src/cli/commands/akuma-grammar.js +4 -4
  19. package/build/src/cli/render/akuma-activity.js +7 -8
  20. package/build/src/cli/render/akuma.js +1 -1
  21. package/build/src/index.d.ts +2 -1
  22. package/build/src/index.js +1 -1
  23. package/build/src/kanshi/counts.d.ts +15 -0
  24. package/build/src/kanshi/counts.js +66 -0
  25. package/build/src/kanshi/index.d.ts +2 -0
  26. package/build/src/kanshi/index.js +1 -0
  27. package/build/src/library/selection.d.ts +6 -1
  28. package/build/src/library/selection.js +5 -3
  29. package/package.json +2 -2
  30. package/plugins/pi/README.md +10 -0
  31. package/plugins/pi/akuma-tools.ts +2 -2
  32. package/plugins/pi/keiyaku.ts +73 -1
  33. package/skills/keiyaku-akuma/SKILL.md +2 -0
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keiyaku",
3
- "version": "4.6.28",
3
+ "version": "4.6.29",
4
4
  "description": "Use the Keiyaku contract, debt, and Akuma CLI.",
5
5
  "author": {
6
6
  "name": "Keiyaku"
@@ -124,6 +124,7 @@ keiyaku ls "aku/*/*"
124
124
  keiyaku ls --mine
125
125
  keiyaku history @reviewer --last
126
126
  keiyaku history @reviewer --id turn/3
127
+ keiyaku history @reviewer --id report/5
127
128
  ```
128
129
 
129
130
  - `whoami`: who you are; for an Akuma, also who started its current turn.
@@ -131,6 +132,7 @@ keiyaku history @reviewer --id turn/3
131
132
  - `ls aku/`: callable names. `ls "aku/*/*"`: recent instances.
132
133
  `ls --mine`: Akumas you called, plus their descendants in this World.
133
134
  `--caller` selects another caller; see `ls --help`.
135
+ - `history <aku> --id report/N`: the exact retained report text, including during an open Turn.
134
136
  - `history <aku> --last`: latest answer. `--id turn/N`: one exact turn's
135
137
  answer or failure diagnostic (ids are in `history <aku> --json`).
136
138
  Keep the complete AkuId if an alias may move.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keiyaku",
3
- "version": "4.6.28+codex.20260905023250",
3
+ "version": "4.6.29+codex.20260905023250",
4
4
  "description": "Use the Keiyaku contract, debt, and Akuma CLI.",
5
5
  "author": {
6
6
  "name": "Keiyaku"
@@ -124,6 +124,7 @@ keiyaku ls "aku/*/*"
124
124
  keiyaku ls --mine
125
125
  keiyaku history @reviewer --last
126
126
  keiyaku history @reviewer --id turn/3
127
+ keiyaku history @reviewer --id report/5
127
128
  ```
128
129
 
129
130
  - `whoami`: who you are; for an Akuma, also who started its current turn.
@@ -131,6 +132,7 @@ keiyaku history @reviewer --id turn/3
131
132
  - `ls aku/`: callable names. `ls "aku/*/*"`: recent instances.
132
133
  `ls --mine`: Akumas you called, plus their descendants in this World.
133
134
  `--caller` selects another caller; see `ls --help`.
135
+ - `history <aku> --id report/N`: the exact retained report text, including during an open Turn.
134
136
  - `history <aku> --last`: latest answer. `--id turn/N`: one exact turn's
135
137
  answer or failure diagnostic (ids are in `history <aku> --json`).
136
138
  Keep the complete AkuId if an alias may move.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keiyaku-harness",
3
- "version": "4.6.28",
3
+ "version": "4.6.29",
4
4
  "type": "module",
5
5
  "main": "./index.js"
6
6
  }
@@ -124,6 +124,7 @@ keiyaku ls "aku/*/*"
124
124
  keiyaku ls --mine
125
125
  keiyaku history @reviewer --last
126
126
  keiyaku history @reviewer --id turn/3
127
+ keiyaku history @reviewer --id report/5
127
128
  ```
128
129
 
129
130
  - `whoami`: who you are; for an Akuma, also who started its current turn.
@@ -131,6 +132,7 @@ keiyaku history @reviewer --id turn/3
131
132
  - `ls aku/`: callable names. `ls "aku/*/*"`: recent instances.
132
133
  `ls --mine`: Akumas you called, plus their descendants in this World.
133
134
  `--caller` selects another caller; see `ls --help`.
135
+ - `history <aku> --id report/N`: the exact retained report text, including during an open Turn.
134
136
  - `history <aku> --last`: latest answer. `--id turn/N`: one exact turn's
135
137
  answer or failure diagnostic (ids are in `history <aku> --json`).
136
138
  Keep the complete AkuId if an alias may move.
@@ -16,6 +16,16 @@ keiyaku install pi
16
16
  pi --extension ./plugins/pi/keiyaku.ts
17
17
  ```
18
18
 
19
+ ## Native status
20
+
21
+ Interactive Pi sessions show a compact status entry with the current World's
22
+ running Akuma, active Contracts, and open Debts across all namespaces. A zero
23
+ is an observed empty count; `-` means absent and `?` means unknown or failed.
24
+ The entry refreshes after each completed read (five seconds later) and when the
25
+ agent settles. It starts with the session and is removed on shutdown or reload;
26
+ non-terminal modes do not run the sampler. The `/keiyaku` overlay and native
27
+ tools are unchanged.
28
+
19
29
  ## Native tools
20
30
 
21
31
  All tools return the SDK result in `details`, `structuredContent`, and JSON
@@ -261,10 +261,10 @@ export function registerAkumaTools(pi: ExtensionAPI, exposure: "hidden" | "direc
261
261
  );
262
262
  register<ToolAddress<AkumaHistoryInput>>(
263
263
  "akuma_history",
264
- "Read retained execution history, the last answer, or one exact turn/n outcome. id cannot combine with paging or last. before/since are durable sequence cursors, not timestamps.",
264
+ "Read retained execution history, the last answer, one exact turn/n outcome, or one exact report/n. id cannot combine with paging or last. before/since are durable sequence cursors, not timestamps.",
265
265
  {
266
266
  akuma: selector,
267
- id: { type: "string", pattern: "^turn/[1-9][0-9]*$" },
267
+ id: { type: "string", pattern: "^(turn|report)/[1-9][0-9]*$" },
268
268
  before: { type: "integer", minimum: 1 },
269
269
  since: { type: "integer", minimum: 1 },
270
270
  limit,
@@ -1,4 +1,5 @@
1
1
  import type { ExtensionAPI, Theme } from "@earendil-works/pi-coding-agent";
2
+ import { kanshiCounts, NoGitWorldError, Repo, World } from "@astrosheep/keiyaku";
2
3
  import { registerAkumaTools } from "./akuma-tools.ts";
3
4
 
4
5
  type ExecResult = Readonly<{ stdout: string; stderr: string; code: number }>;
@@ -37,8 +38,79 @@ function overlay(lines: readonly string[], theme: Theme, done: () => void) {
37
38
  };
38
39
  }
39
40
 
40
- export default function keiyakuExtension(pi: ExtensionAPI): void {
41
+ type StatusReaders = { repo: typeof Repo.at; world: typeof World.resolve; counts: typeof kanshiCounts };
42
+
43
+ export default function keiyakuExtension(
44
+ pi: ExtensionAPI,
45
+ readers: StatusReaders = { repo: Repo.at, world: World.resolve, counts: kanshiCounts },
46
+ ): void {
41
47
  registerAkumaTools(pi);
48
+ let close: (() => void) | undefined;
49
+ let refresh: (() => void) | undefined;
50
+ pi.on("session_start", (_event, ctx) => {
51
+ close?.();
52
+ close = undefined;
53
+ refresh = undefined;
54
+ if (ctx.mode !== "tui") return;
55
+ const cwd = ctx.cwd;
56
+ const ui = ctx.ui;
57
+ let live = true;
58
+ let reading = false;
59
+ let pending = false;
60
+ let timer: ReturnType<typeof setTimeout> | undefined;
61
+ const unknown = "aku ? · kei ? · debt ?";
62
+ const show = (text: string | undefined): void => ui.setStatus("keiyaku", text);
63
+ const value = (section: { kind: "present"; value: number } | { kind: "absent" | "failed" }): string =>
64
+ section.kind === "present" ? String(section.value) : section.kind === "absent" ? "-" : "?";
65
+ const sample = async (): Promise<string> => {
66
+ let repo: Repo | undefined;
67
+ try {
68
+ repo = await readers.repo({ path: cwd });
69
+ } catch (error) {
70
+ if (!(error instanceof NoGitWorldError)) throw error;
71
+ }
72
+ const world = await readers.world(repo === undefined ? { cwd } : { cwd, repositoryRoot: repo.root });
73
+ const report = await readers.counts({ world: world.root, ...(repo === undefined ? {} : { repo }) });
74
+ return `aku ${value(report.akuma)} · kei ${value(report.contracts)} · debt ${value(report.debts)}`;
75
+ };
76
+ const request = (): void => {
77
+ if (!live) return;
78
+ if (timer !== undefined) clearTimeout(timer);
79
+ timer = undefined;
80
+ if (reading) {
81
+ pending = true;
82
+ return;
83
+ }
84
+ reading = true;
85
+ void sample().catch(() => unknown).then((text) => {
86
+ if (!live) return;
87
+ show(text);
88
+ reading = false;
89
+ if (pending) {
90
+ pending = false;
91
+ request();
92
+ } else {
93
+ timer = setTimeout(request, 5_000);
94
+ timer.unref();
95
+ }
96
+ });
97
+ };
98
+ close = () => {
99
+ if (!live) return;
100
+ live = false;
101
+ if (timer !== undefined) clearTimeout(timer);
102
+ show(undefined);
103
+ };
104
+ refresh = request;
105
+ show(unknown);
106
+ request();
107
+ });
108
+ pi.on("agent_settled", () => { refresh?.(); });
109
+ pi.on("session_shutdown", () => {
110
+ close?.();
111
+ close = undefined;
112
+ refresh = undefined;
113
+ });
42
114
  pi.registerCommand("keiyaku", {
43
115
  description: "Open the Kanshi world status",
44
116
  handler: async (_args, ctx) => {
@@ -124,6 +124,7 @@ keiyaku ls "aku/*/*"
124
124
  keiyaku ls --mine
125
125
  keiyaku history @reviewer --last
126
126
  keiyaku history @reviewer --id turn/3
127
+ keiyaku history @reviewer --id report/5
127
128
  ```
128
129
 
129
130
  - `whoami`: who you are; for an Akuma, also who started its current turn.
@@ -131,6 +132,7 @@ keiyaku history @reviewer --id turn/3
131
132
  - `ls aku/`: callable names. `ls "aku/*/*"`: recent instances.
132
133
  `ls --mine`: Akumas you called, plus their descendants in this World.
133
134
  `--caller` selects another caller; see `ls --help`.
135
+ - `history <aku> --id report/N`: the exact retained report text, including during an open Turn.
134
136
  - `history <aku> --last`: latest answer. `--id turn/N`: one exact turn's
135
137
  answer or failure diagnostic (ids are in `history <aku> --json`).
136
138
  Keep the complete AkuId if an alias may move.
@@ -9,7 +9,7 @@ import { handoffPendingTells, wakeRecordedTell } from "./body.js";
9
9
  import { admitCallInitialTell } from "./call-initial-tell.js";
10
10
  import { acquireLeash } from "./control.js";
11
11
  import { activitySlice, projectTell, readForkPoint, readHeart, readInterruptCompletion, readKill, readLastAnsweredTurn, readSoul, readTell, recordReport, recordTell, requestStop, } from "./heart/index.js";
12
- import { parsePublicHistoryId, pathsForAkuId } from "./identity.js";
12
+ import { parseExactHistorySelector, pathsForAkuId } from "./identity.js";
13
13
  import { projectTurns, selectExactHistory, selectHistory } from "./projection.js";
14
14
  import { resolveProviderExecution } from "./providers/index.js";
15
15
  import { publishAkuma } from "./publication.js";
@@ -131,9 +131,10 @@ export class AkumaOwner {
131
131
  throw new TypeError("Akuma history id must be a nonblank string");
132
132
  if (input.before !== undefined || input.since !== undefined || input.limit !== undefined)
133
133
  throw new TypeError("Akuma history id cannot be combined with before, since, or limit");
134
- if (parsePublicHistoryId(input.id) === null)
135
- throw new TypeError("Akuma history id must match turn/<positive safe integer>");
136
- return selectExactHistory((await this.projectHistoryTurns()).rows, input.id);
134
+ const selector = parseExactHistorySelector(input.id);
135
+ if (selector === null)
136
+ throw new TypeError("Akuma history id must match turn/<positive safe integer> or report/<positive safe integer>");
137
+ return selectExactHistory((await this.projectHistoryTurns()).rows, selector);
137
138
  }
138
139
  async report(input, signal) {
139
140
  return await recordReport(this.paths, input, signal);
@@ -484,6 +484,8 @@ export declare function knownAkuma(path: WorldRoot, selected?: string): Promise<
484
484
  runRoot: string;
485
485
  rows: readonly KnownAkuma[];
486
486
  }>>;
487
+ /** Exact running count requires every recognized coordinate to be readable. */
488
+ export declare function countRunningAkuma(path: WorldRoot): Promise<number>;
487
489
  /** The bounded recent-activity roster input: native membership and observed extent. */
488
490
  export declare function readAkumaRoster(path: WorldRoot, input?: AkumaListInput): Promise<AkumaList>;
489
491
  /**
@@ -99,14 +99,26 @@ async function freshnessOrdered(rows) {
99
99
  async function readableRows(rows) {
100
100
  const loaded = await boundedMap(rows, async ({ id, paths }) => {
101
101
  try {
102
- return await rosterListRow(paths, id);
102
+ return { row: await rosterListRow(paths, id) };
103
103
  }
104
- catch {
105
- return null;
104
+ catch (error) {
105
+ return { error };
106
106
  }
107
107
  });
108
- const values = [...loaded].filter((row) => row !== null);
109
- return { rows: values, skipped: loaded.length - values.length };
108
+ const values = loaded.flatMap((item) => (item.row === undefined ? [] : [item.row]));
109
+ const failed = loaded.find((item) => item.row === undefined);
110
+ return {
111
+ rows: values,
112
+ skipped: loaded.length - values.length,
113
+ ...(failed === undefined ? {} : { failure: failed.error }),
114
+ };
115
+ }
116
+ /** Exact running count requires every recognized coordinate to be readable. */
117
+ export async function countRunningAkuma(path) {
118
+ const observed = await readableRows((await knownAkuma(path)).rows);
119
+ if (observed.skipped > 0)
120
+ throw new Error("Cannot classify every recognized Akuma", { cause: observed.failure });
121
+ return observed.rows.filter((row) => row.life === "running").length;
110
122
  }
111
123
  function rosterInput(input, allowLimit) {
112
124
  if (typeof input !== "object" || input === null || Array.isArray(input))
@@ -4,6 +4,10 @@ export type AkuId = string & {
4
4
  readonly [AKU_ID]: true;
5
5
  };
6
6
  export declare function parsePublicHistoryId(value: string): number | null;
7
+ export declare function parseExactHistorySelector(value: string): Readonly<{
8
+ kind: "turn" | "report";
9
+ sequence: number;
10
+ }> | null;
7
11
  export declare const akumaPathsSchema: z.ZodObject<{
8
12
  directory: z.ZodString;
9
13
  heart: z.ZodString;
@@ -12,6 +12,13 @@ export function parsePublicHistoryId(value) {
12
12
  const sequence = Number(match[1]);
13
13
  return Number.isSafeInteger(sequence) ? sequence : null;
14
14
  }
15
+ export function parseExactHistorySelector(value) {
16
+ const match = /^(turn|report)\/([1-9][0-9]*)$/u.exec(value);
17
+ if (match === null)
18
+ return null;
19
+ const sequence = Number(match[2]);
20
+ return Number.isSafeInteger(sequence) ? { kind: match[1], sequence } : null;
21
+ }
15
22
  const pathText = z.string().refine((value) => value.trim() !== "");
16
23
  export const akumaPathsSchema = z
17
24
  .object({
@@ -1023,12 +1023,18 @@ export type ActivityHistory = Readonly<{
1023
1023
  export type ExactHistory = Readonly<{
1024
1024
  kind: "exact";
1025
1025
  outcome: OutcomeRow;
1026
+ }> | Readonly<{
1027
+ kind: "exact-report";
1028
+ report: ReportRow;
1026
1029
  }> | Readonly<{
1027
1030
  kind: "unknown-history";
1028
1031
  id: string;
1029
1032
  }>;
1030
1033
  export type HistoryPage = ActivityHistory;
1031
- export declare function selectExactHistory(rows: readonly ActivityRow[], id: string): ExactHistory;
1034
+ export declare function selectExactHistory(rows: readonly ActivityRow[], selector: Readonly<{
1035
+ kind: "turn" | "report";
1036
+ sequence: number;
1037
+ }>): ExactHistory;
1032
1038
  export type HistoryCursor = Readonly<{
1033
1039
  before?: number;
1034
1040
  since?: number;
@@ -207,7 +207,12 @@ function publicOutcome(turnSequence, outcome) {
207
207
  return { kind: "canceled", historyId };
208
208
  return { kind: "failed", historyId, diagnostic: outcome.diagnostic };
209
209
  }
210
- export function selectExactHistory(rows, id) {
210
+ export function selectExactHistory(rows, selector) {
211
+ const id = `${selector.kind}/${selector.sequence}`;
212
+ if (selector.kind === "report") {
213
+ const report = rows.find((row) => row.kind === "report" && row.sequence === selector.sequence);
214
+ return report === undefined ? { kind: "unknown-history", id } : { kind: "exact-report", report };
215
+ }
211
216
  const outcome = rows.find((row) => row.kind === "outcome" && row.outcome.historyId === id);
212
217
  return outcome === undefined ? { kind: "unknown-history", id } : { kind: "exact", outcome };
213
218
  }
@@ -2,7 +2,7 @@ import { CliUsageError, commandGuide, usageLine } from "../usage.js";
2
2
  import { scanArgs } from "../scan.js";
3
3
  import { parseDuration as decodeDuration } from "../../duration.js";
4
4
  import { parseAkumaAlias, parseAkumaGlob } from "../../identity/selector.js";
5
- import { parsePublicHistoryId } from "../../akuma/identity.js";
5
+ import { parseExactHistorySelector } from "../../akuma/identity.js";
6
6
  const SET_SELECTORS = '(<aku/...> | @alias | <kei/...> | "aku/<name-pattern>/<hex-pattern>")...';
7
7
  const SET_DETAILS = "Globs contain * and use lowercase hex digits or * in the suffix. --repo requires at least one Contract (kei/...) selector.";
8
8
  const SCHEMA_DETAILS = "--schema supplies a JSON Schema answer contract to the provider; on observation the CLI parses JSON but does not independently validate schema conformance.";
@@ -99,7 +99,7 @@ const AKUMA_COMMAND_SPECS = {
99
99
  usage: "history <aku/...|@alias> [--before <index> | --since <index>] [--limit <count>]\nhistory <aku/...|@alias> --id <historyId>\nhistory <aku/...|@alias> --last\nhistory <kei/...> [--full] [--repo <path>]",
100
100
  purpose: "Read an Akuma's answers and activity, or a Contract's history of changes and assigned work.",
101
101
  details: [
102
- "--id reads an exact retained terminal turn (turn/<number>): its answer or failure diagnostic.",
102
+ "--id reads an exact retained terminal turn (turn/<number>) or report (report/<number>).",
103
103
  "--before <index> pages older rows before that sequence; --since <index> pages newer rows after it.",
104
104
  "--limit bounds page size (default 12); without --since, the latest rows are shown.",
105
105
  "With --since, paging starts at the earliest newer rows.",
@@ -240,8 +240,8 @@ function parseAkumaHistory(selector, flags, output, fail) {
240
240
  if (limit !== undefined && limit > 5_000)
241
241
  fail("--limit must be no greater than 5000");
242
242
  const id = flags.id === undefined ? undefined : stringFlag(flags.id, "history --id requires a nonblank historyId", fail);
243
- if (id !== undefined && parsePublicHistoryId(id) === null)
244
- fail("history --id requires turn/<positive safe integer>");
243
+ if (id !== undefined && parseExactHistorySelector(id) === null)
244
+ fail("history --id requires turn/<positive safe integer> or report/<positive safe integer>");
245
245
  return {
246
246
  command: "history",
247
247
  akuma: selector,
@@ -806,7 +806,11 @@ export function callRawAnswer(result, streamed) {
806
806
  return answerBytes(observation.observation.answer, result.structured === true);
807
807
  }
808
808
  export function historyRawAnswer(result, historyId) {
809
- if (historyId === undefined || result.kind !== "exact")
809
+ if (historyId === undefined)
810
+ return undefined;
811
+ if (result.kind === "exact-report")
812
+ return result.report.text;
813
+ if (result.kind !== "exact")
810
814
  return undefined;
811
815
  const outcome = result.outcome.outcome;
812
816
  return outcome.kind === "answered" ? outcome.answer : outcome.kind === "canceled" ? "canceled" : outcome.diagnostic;
@@ -879,13 +883,8 @@ export function waitText(result, presentation, context) {
879
883
  }
880
884
  export function historyText(result, presentation, context) {
881
885
  if (presentation.id !== undefined) {
882
- if (result.kind !== "exact")
883
- return `${result.kind === "unknown-history" ? result.historyId : "unknown"} has no matching retained outcome`;
884
- return result.outcome.outcome.kind === "answered"
885
- ? result.outcome.outcome.answer
886
- : result.outcome.outcome.kind === "canceled"
887
- ? "canceled"
888
- : result.outcome.outcome.diagnostic;
886
+ return (historyRawAnswer(result, presentation.id) ??
887
+ `${result.kind === "unknown-history" ? result.historyId : "unknown"} has no matching retained history`);
889
888
  }
890
889
  if (presentation.last === true)
891
890
  return result.kind === "last" ? result.answer : "no answer retained";
@@ -183,5 +183,5 @@ export function forkOutcome(receipt) {
183
183
  export function historyOutcome(result, id) {
184
184
  if (id === undefined)
185
185
  return "accepted";
186
- return result.kind === "exact" ? "accepted" : "refused";
186
+ return result.kind === "exact" || result.kind === "exact-report" ? "accepted" : "refused";
187
187
  }
@@ -50,7 +50,8 @@ export { z } from "zod";
50
50
  export { Akuma, AkumaArchetypeError, AkumaBusyError, AkumaDecodeError, AkumaNotBornError, AkumaProviderError, Schema, listArchetypeDefinitions, } from "./akuma/index.js";
51
51
  export type { AkumaCaller, AkumaOrigin, ActivityHistory, ActivityRow, AkuId, AkumaAskObservation, AkumaAskOptions, AkumaAskResult, AkumaBirthInput, AkumaHistoryOptions, AkumaHostOptions, AkumaIdleOptions, AkumaIdleResult, AkumaReportOptions, AkumaReportResult, AkumaSignalOptions, AkumaStatus, AkumaStreamSnapshot, AkumaTellOptions, AkumaTellResult, ArchetypeCatalog, ArchetypeCatalogInput, ArchetypeCatalogRow, InterruptReceipt, JsonSchema, JsonSchemaDocument, KillEvidence, SchemaLike, StandardSchemaV1, } from "./akuma/index.js";
52
52
  export type { ActorId, ChangeId, ContractHead, ContractId, ContractState, ContractTarget, JournalEntry as Fact, FactKind, SnapshotId, } from "./core/facts/types.js";
53
- export { kanshi, kanshiCategory, observeKanshi, selectKanshi, selectRegion } from "./kanshi/index.js";
53
+ export { kanshi, kanshiCategory, kanshiCounts, observeKanshi, selectKanshi, selectRegion } from "./kanshi/index.js";
54
+ export type { KanshiCountsInput, KanshiCountsReport } from "./kanshi/index.js";
54
55
  export type { AkumaKanshiRow, AkumaKanshiWorld, ContractEndpointObservation, ContractHolderObservation, ContractKanshiBoard, ContractKanshiRow, KanshiCategoryInput, KanshiCategoryReport, KanshiInput, KanshiRegionSelection, KanshiReport, KanshiSelection, RegionDeclaration, RegionRead, Section, DebtKanshiRow, DebtKanshiWorld, } from "./kanshi/index.js";
55
56
  export { AkumaAddressError, AkumaWorldScopeError, Akumas } from "./library/akumas.js";
56
57
  export type { AkumaAddressInput, AkumaAskInput, AkumaHistoryInput, AkumaHistoryResult, AkumaKillInput, AkumaKillResult, AkumaList, AkumaListInput, AkumaObservation, AkumaObservationStage, AkumaTellInput, AkumaWaitInput, AkumaWaitResult, AkumaWorldScopeRefusal, CallInput, CallResult, CallWaitHead, CreatedDebtObservation, DispatchAssociation, DispatchStage, ForkInput, ForkResult, TellResult, TellWake, } from "./library/akumas.js";
@@ -47,7 +47,7 @@ export { actorId } from "./core/facts/types.js";
47
47
  */
48
48
  export { z } from "zod";
49
49
  export { Akuma, AkumaArchetypeError, AkumaBusyError, AkumaDecodeError, AkumaNotBornError, AkumaProviderError, Schema, listArchetypeDefinitions, } from "./akuma/index.js";
50
- export { kanshi, kanshiCategory, observeKanshi, selectKanshi, selectRegion } from "./kanshi/index.js";
50
+ export { kanshi, kanshiCategory, kanshiCounts, observeKanshi, selectKanshi, selectRegion } from "./kanshi/index.js";
51
51
  export { AkumaAddressError, AkumaWorldScopeError, Akumas } from "./library/akumas.js";
52
52
  export { nukeKeiyaku as nuke } from "./library/nuke.js";
53
53
  export { SettingsError, settings } from "./settings.js";
@@ -0,0 +1,15 @@
1
+ import { Repo } from "../library/repo.js";
2
+ import { type WorldRoot } from "../world.js";
3
+ import type { Section } from "./report.js";
4
+ export type KanshiCountsInput = Readonly<{
5
+ world: WorldRoot | null;
6
+ repo?: Repo;
7
+ }>;
8
+ export type KanshiCountsReport = Readonly<{
9
+ root: WorldRoot | null;
10
+ observedAt: string;
11
+ akuma: Section<number>;
12
+ contracts: Section<number>;
13
+ debts: Section<number>;
14
+ }>;
15
+ export declare function kanshiCounts(input: KanshiCountsInput): Promise<KanshiCountsReport>;
@@ -0,0 +1,66 @@
1
+ import { countRunningAkuma } from "../akuma/akuma.js";
2
+ import { DebtAuthorityCorruptionError } from "../debt/index.js";
3
+ import { observeDebtBoard } from "../debt/operations.js";
4
+ import { withGitDecodeChannel, withGitReadObservation } from "../git/read-observation.js";
5
+ import { Repo, scopeForRepo } from "../library/repo.js";
6
+ import { readContractBoard } from "../protocol/read/status.js";
7
+ import { World } from "../world.js";
8
+ async function section(read) {
9
+ try {
10
+ return { kind: "present", value: await read() };
11
+ }
12
+ catch (error) {
13
+ const text = (error instanceof Error ? error.message : String(error)).replaceAll(/\s+/gu, " ").trim();
14
+ return {
15
+ kind: "failed",
16
+ failure: {
17
+ message: text.length <= 240 ? text : `${text.slice(0, 239)}…`,
18
+ ...(error instanceof DebtAuthorityCorruptionError && error.coordinate !== undefined
19
+ ? { coordinate: error.coordinate }
20
+ : {}),
21
+ },
22
+ };
23
+ }
24
+ }
25
+ export async function kanshiCounts(input) {
26
+ if (typeof input !== "object" || input === null || Array.isArray(input))
27
+ throw new TypeError("kanshi counts input must be an object");
28
+ for (const key of Object.keys(input))
29
+ if (key !== "world" && key !== "repo")
30
+ throw new TypeError(`kanshi counts input has unknown field: ${key}`);
31
+ if (input.world !== null && (typeof input.world !== "string" || input.world.trim().length === 0))
32
+ throw new TypeError("kanshi world must be a WorldRoot or null");
33
+ if (input.repo !== undefined && !(input.repo instanceof Repo))
34
+ throw new TypeError("kanshi repo must be a Repo");
35
+ const world = input.world === null ? null : await World.prove(input.world);
36
+ const observedAt = new Date().toISOString();
37
+ const absent = { kind: "absent" };
38
+ const contracts = input.repo === undefined
39
+ ? Promise.resolve(absent)
40
+ : section(async () => {
41
+ const repo = scopeForRepo(input.repo);
42
+ return withGitDecodeChannel(repo, (channel) => withGitReadObservation(repo, channel, async (observation) => (await readContractBoard(observation)).rows.length));
43
+ });
44
+ const worldSections = async () => {
45
+ if (world === null)
46
+ return [absent, absent];
47
+ let established;
48
+ try {
49
+ established = await World.established(world);
50
+ }
51
+ catch (error) {
52
+ const failed = await section(async () => {
53
+ throw error;
54
+ });
55
+ return [failed, failed];
56
+ }
57
+ if (!established)
58
+ return [absent, absent];
59
+ return Promise.all([
60
+ section(() => countRunningAkuma(world)),
61
+ section(async () => (await observeDebtBoard(world)).statusRows.filter((row) => row.state === "open").length),
62
+ ]);
63
+ };
64
+ const [contractSection, [akuma, debts]] = await Promise.all([contracts, worldSections()]);
65
+ return { root: world, observedAt, akuma, contracts: contractSection, debts };
66
+ }
@@ -1,4 +1,6 @@
1
1
  export { kanshi, kanshiCategory, observeKanshi } from "./read.js";
2
+ export { kanshiCounts } from "./counts.js";
3
+ export type { KanshiCountsInput, KanshiCountsReport } from "./counts.js";
2
4
  export { selectKanshi, selectRegion } from "./select.js";
3
5
  export type { KanshiCategoryInput, KanshiInput } from "./read.js";
4
6
  export type { AkumaKanshiRow, AkumaKanshiWorld, ContractEndpointObservation, ContractHolderObservation, ContractKanshiBoard, ContractKanshiRow, KanshiCategoryReport, KanshiReport, Section, DebtKanshiRow, DebtKanshiWorld, KanshiRegionSelection, RegionDeclaration, RegionOverlap, RegionRead, } from "./report.js";
@@ -1,2 +1,3 @@
1
1
  export { kanshi, kanshiCategory, observeKanshi } from "./read.js";
2
+ export { kanshiCounts } from "./counts.js";
2
3
  export { selectKanshi, selectRegion } from "./select.js";
@@ -1,7 +1,7 @@
1
1
  import type { BodyLauncher } from "../akuma/body-launch.js";
2
2
  import { type AskObserver } from "../akuma/akuma-selection-execution.js";
3
3
  import { type AkumaStatus } from "../akuma/akuma.js";
4
- import { type ActivityHistory, type OutcomeRow } from "../akuma/projection.js";
4
+ import { type ActivityHistory, type OutcomeRow, type ReportRow } from "../akuma/projection.js";
5
5
  import { type Schema } from "../akuma/schema.js";
6
6
  import type { AkumaAskResult, AkumaKillResult, AkumaObservation, AkumaTellResult, AkumaWaitResult } from "../akuma/selection-observation.js";
7
7
  import type { DispatchAssociation } from "../akuma/dispatch-association.js";
@@ -49,6 +49,11 @@ export type AkumaHistoryResult = Readonly<{
49
49
  id: AkumaStatus["id"];
50
50
  outcome: OutcomeRow;
51
51
  contract: DispatchAssociation;
52
+ }> | Readonly<{
53
+ kind: "exact-report";
54
+ id: AkumaStatus["id"];
55
+ report: ReportRow;
56
+ contract: DispatchAssociation;
52
57
  }> | Readonly<{
53
58
  kind: "unknown-history";
54
59
  id: AkumaStatus["id"];
@@ -5,7 +5,7 @@ import { AkumaNotBornError, AkumaObservationError } from "../akuma/akuma-errors.
5
5
  import { AkumaOwner } from "../akuma/akuma-owner.js";
6
6
  import { decodeAskObservation, executeAskAkuma, executeKillAkuma, executeTellAkuma, } from "../akuma/akuma-selection-execution.js";
7
7
  import { executeWaitAkuma } from "../akuma/akuma-wait.js";
8
- import { parsePublicHistoryId } from "../akuma/identity.js";
8
+ import { parseExactHistorySelector } from "../akuma/identity.js";
9
9
  import { schemaJsonText } from "../akuma/schema.js";
10
10
  import { observeDispatchAssociations } from "../dispatch/index.js";
11
11
  import { observeContractAt } from "../git/observe.js";
@@ -277,8 +277,8 @@ function validateHistoryInput(values) {
277
277
  throw new TypeError("last must be a boolean");
278
278
  if (values.id !== undefined && (typeof values.id !== "string" || values.id.trim() === ""))
279
279
  throw new TypeError("id must be a nonblank string");
280
- if (values.id !== undefined && parsePublicHistoryId(values.id) === null)
281
- throw new TypeError("id must match turn/<positive safe integer>");
280
+ if (values.id !== undefined && parseExactHistorySelector(values.id) === null)
281
+ throw new TypeError("id must match turn/<positive safe integer> or report/<positive safe integer>");
282
282
  if (values.id !== undefined &&
283
283
  (values.last === true || values.before !== undefined || values.since !== undefined || values.limit !== undefined))
284
284
  throw new TypeError("id cannot be combined with last, before, since, or limit");
@@ -305,6 +305,8 @@ export async function historyAkuma(input, reportDiagnostic = stderrPluginDiagnos
305
305
  if (values.id !== undefined) {
306
306
  if ("kind" in history && history.kind === "exact")
307
307
  return { kind: "exact", id: addressed.id, outcome: history.outcome, contract };
308
+ if ("kind" in history && history.kind === "exact-report")
309
+ return { kind: "exact-report", id: addressed.id, report: history.report, contract };
308
310
  return { kind: "unknown-history", id: addressed.id, historyId: values.id, contract };
309
311
  }
310
312
  return { kind: "history", id: addressed.id, history: history, contract };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrosheep/keiyaku",
3
- "version": "4.6.28",
3
+ "version": "4.6.29",
4
4
  "workspaces": [
5
5
  "plugins/square",
6
6
  "plugins/paseo/forwarder"
@@ -81,7 +81,7 @@
81
81
  "dependencies": {
82
82
  "@agentclientprotocol/sdk": "^1.3.0",
83
83
  "@anthropic-ai/claude-agent-sdk": "^0.3.226",
84
- "@astrosheep/keiyaku-plugin-square": "0.1.21",
84
+ "@astrosheep/keiyaku-plugin-square": "0.1.22",
85
85
  "@astrosheep/square": "^0.4.1",
86
86
  "@getpaseo/client": "0.14.0",
87
87
  "@getpaseo/protocol": "0.14.0",
@@ -16,6 +16,16 @@ keiyaku install pi
16
16
  pi --extension ./plugins/pi/keiyaku.ts
17
17
  ```
18
18
 
19
+ ## Native status
20
+
21
+ Interactive Pi sessions show a compact status entry with the current World's
22
+ running Akuma, active Contracts, and open Debts across all namespaces. A zero
23
+ is an observed empty count; `-` means absent and `?` means unknown or failed.
24
+ The entry refreshes after each completed read (five seconds later) and when the
25
+ agent settles. It starts with the session and is removed on shutdown or reload;
26
+ non-terminal modes do not run the sampler. The `/keiyaku` overlay and native
27
+ tools are unchanged.
28
+
19
29
  ## Native tools
20
30
 
21
31
  All tools return the SDK result in `details`, `structuredContent`, and JSON
@@ -261,10 +261,10 @@ export function registerAkumaTools(pi: ExtensionAPI, exposure: "hidden" | "direc
261
261
  );
262
262
  register<ToolAddress<AkumaHistoryInput>>(
263
263
  "akuma_history",
264
- "Read retained execution history, the last answer, or one exact turn/n outcome. id cannot combine with paging or last. before/since are durable sequence cursors, not timestamps.",
264
+ "Read retained execution history, the last answer, one exact turn/n outcome, or one exact report/n. id cannot combine with paging or last. before/since are durable sequence cursors, not timestamps.",
265
265
  {
266
266
  akuma: selector,
267
- id: { type: "string", pattern: "^turn/[1-9][0-9]*$" },
267
+ id: { type: "string", pattern: "^(turn|report)/[1-9][0-9]*$" },
268
268
  before: { type: "integer", minimum: 1 },
269
269
  since: { type: "integer", minimum: 1 },
270
270
  limit,
@@ -1,4 +1,5 @@
1
1
  import type { ExtensionAPI, Theme } from "@earendil-works/pi-coding-agent";
2
+ import { kanshiCounts, NoGitWorldError, Repo, World } from "@astrosheep/keiyaku";
2
3
  import { registerAkumaTools } from "./akuma-tools.ts";
3
4
 
4
5
  type ExecResult = Readonly<{ stdout: string; stderr: string; code: number }>;
@@ -37,8 +38,79 @@ function overlay(lines: readonly string[], theme: Theme, done: () => void) {
37
38
  };
38
39
  }
39
40
 
40
- export default function keiyakuExtension(pi: ExtensionAPI): void {
41
+ type StatusReaders = { repo: typeof Repo.at; world: typeof World.resolve; counts: typeof kanshiCounts };
42
+
43
+ export default function keiyakuExtension(
44
+ pi: ExtensionAPI,
45
+ readers: StatusReaders = { repo: Repo.at, world: World.resolve, counts: kanshiCounts },
46
+ ): void {
41
47
  registerAkumaTools(pi);
48
+ let close: (() => void) | undefined;
49
+ let refresh: (() => void) | undefined;
50
+ pi.on("session_start", (_event, ctx) => {
51
+ close?.();
52
+ close = undefined;
53
+ refresh = undefined;
54
+ if (ctx.mode !== "tui") return;
55
+ const cwd = ctx.cwd;
56
+ const ui = ctx.ui;
57
+ let live = true;
58
+ let reading = false;
59
+ let pending = false;
60
+ let timer: ReturnType<typeof setTimeout> | undefined;
61
+ const unknown = "aku ? · kei ? · debt ?";
62
+ const show = (text: string | undefined): void => ui.setStatus("keiyaku", text);
63
+ const value = (section: { kind: "present"; value: number } | { kind: "absent" | "failed" }): string =>
64
+ section.kind === "present" ? String(section.value) : section.kind === "absent" ? "-" : "?";
65
+ const sample = async (): Promise<string> => {
66
+ let repo: Repo | undefined;
67
+ try {
68
+ repo = await readers.repo({ path: cwd });
69
+ } catch (error) {
70
+ if (!(error instanceof NoGitWorldError)) throw error;
71
+ }
72
+ const world = await readers.world(repo === undefined ? { cwd } : { cwd, repositoryRoot: repo.root });
73
+ const report = await readers.counts({ world: world.root, ...(repo === undefined ? {} : { repo }) });
74
+ return `aku ${value(report.akuma)} · kei ${value(report.contracts)} · debt ${value(report.debts)}`;
75
+ };
76
+ const request = (): void => {
77
+ if (!live) return;
78
+ if (timer !== undefined) clearTimeout(timer);
79
+ timer = undefined;
80
+ if (reading) {
81
+ pending = true;
82
+ return;
83
+ }
84
+ reading = true;
85
+ void sample().catch(() => unknown).then((text) => {
86
+ if (!live) return;
87
+ show(text);
88
+ reading = false;
89
+ if (pending) {
90
+ pending = false;
91
+ request();
92
+ } else {
93
+ timer = setTimeout(request, 5_000);
94
+ timer.unref();
95
+ }
96
+ });
97
+ };
98
+ close = () => {
99
+ if (!live) return;
100
+ live = false;
101
+ if (timer !== undefined) clearTimeout(timer);
102
+ show(undefined);
103
+ };
104
+ refresh = request;
105
+ show(unknown);
106
+ request();
107
+ });
108
+ pi.on("agent_settled", () => { refresh?.(); });
109
+ pi.on("session_shutdown", () => {
110
+ close?.();
111
+ close = undefined;
112
+ refresh = undefined;
113
+ });
42
114
  pi.registerCommand("keiyaku", {
43
115
  description: "Open the Kanshi world status",
44
116
  handler: async (_args, ctx) => {
@@ -124,6 +124,7 @@ keiyaku ls "aku/*/*"
124
124
  keiyaku ls --mine
125
125
  keiyaku history @reviewer --last
126
126
  keiyaku history @reviewer --id turn/3
127
+ keiyaku history @reviewer --id report/5
127
128
  ```
128
129
 
129
130
  - `whoami`: who you are; for an Akuma, also who started its current turn.
@@ -131,6 +132,7 @@ keiyaku history @reviewer --id turn/3
131
132
  - `ls aku/`: callable names. `ls "aku/*/*"`: recent instances.
132
133
  `ls --mine`: Akumas you called, plus their descendants in this World.
133
134
  `--caller` selects another caller; see `ls --help`.
135
+ - `history <aku> --id report/N`: the exact retained report text, including during an open Turn.
134
136
  - `history <aku> --last`: latest answer. `--id turn/N`: one exact turn's
135
137
  answer or failure diagnostic (ids are in `history <aku> --json`).
136
138
  Keep the complete AkuId if an alias may move.