@astrosheep/keiyaku 4.6.32 → 4.6.33

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 (199) hide show
  1. package/README.md +8 -6
  2. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +13 -9
  3. package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +8 -6
  4. package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -1
  5. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +13 -9
  6. package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +8 -6
  7. package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -1
  8. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +13 -9
  9. package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +8 -6
  10. package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +2 -1
  11. package/build/plugins/pi/README.md +55 -97
  12. package/build/plugins/pi/keiyaku.ts +2 -9
  13. package/build/skills/keiyaku-akuma/SKILL.md +13 -9
  14. package/build/skills/keiyaku-babysit/SKILL.md +8 -6
  15. package/build/skills/keiyaku-workflow/SKILL.md +2 -1
  16. package/build/src/akuma/akuma-instance.d.ts +11 -0
  17. package/build/src/akuma/akuma-instance.js +1 -2
  18. package/build/src/akuma/akuma-observe.js +73 -14
  19. package/build/src/akuma/akuma-selection-execution.d.ts +82 -7
  20. package/build/src/akuma/akuma-selection-execution.js +26 -27
  21. package/build/src/akuma/akuma-wait.d.ts +40 -1
  22. package/build/src/akuma/akuma-wait.js +58 -29
  23. package/build/src/akuma/akuma.d.ts +11 -0
  24. package/build/src/akuma/body.js +13 -18
  25. package/build/src/akuma/call-initial-tell.d.ts +0 -1
  26. package/build/src/akuma/call-initial-tell.js +0 -1
  27. package/build/src/akuma/heart/activity-schema.d.ts +16 -0
  28. package/build/src/akuma/heart/activity-schema.js +7 -0
  29. package/build/src/akuma/heart/index.d.ts +1 -1
  30. package/build/src/akuma/heart/index.js +9 -1
  31. package/build/src/akuma/heart/timeline.js +4 -4
  32. package/build/src/akuma/projection-read.d.ts +4 -2
  33. package/build/src/akuma/projection-read.js +21 -14
  34. package/build/src/akuma/projection.d.ts +94 -2
  35. package/build/src/akuma/projection.js +47 -47
  36. package/build/src/akuma/provider.d.ts +2 -2
  37. package/build/src/akuma/provider.js +27 -20
  38. package/build/src/akuma/providers/acp/core.js +2 -5
  39. package/build/src/akuma/providers/opencode-sdk/events.d.ts +2 -1
  40. package/build/src/akuma/providers/opencode-sdk/events.js +31 -1
  41. package/build/src/akuma/publication.js +3 -2
  42. package/build/src/akuma/selection-observation.d.ts +23 -0
  43. package/build/src/akuma/selection-observation.js +15 -4
  44. package/build/src/akuma/status-projection.d.ts +14 -1
  45. package/build/src/akuma/status-projection.js +40 -2
  46. package/build/src/akuma/turn-drive.js +21 -15
  47. package/build/src/body/amend.js +5 -17
  48. package/build/src/body/decode.js +11 -1
  49. package/build/src/body/envelope.d.ts +5 -1
  50. package/build/src/body/envelope.js +4 -2
  51. package/build/src/body/render.js +4 -6
  52. package/build/src/cli/commands/akuma-grammar.d.ts +3 -5
  53. package/build/src/cli/commands/akuma-grammar.js +22 -40
  54. package/build/src/cli/commands/akuma.d.ts +1 -2
  55. package/build/src/cli/commands/akuma.js +6 -58
  56. package/build/src/cli/commands/contract-grammar.d.ts +1 -0
  57. package/build/src/cli/commands/contract-grammar.js +7 -11
  58. package/build/src/cli/commands/contract-help.d.ts +3 -2
  59. package/build/src/cli/commands/contract-help.js +11 -5
  60. package/build/src/cli/commands/contract.js +3 -0
  61. package/build/src/cli/commands/debt-grammar.js +2 -4
  62. package/build/src/cli/parse.js +1 -4
  63. package/build/src/cli/render/akuma-activity.d.ts +3 -15
  64. package/build/src/cli/render/akuma-activity.js +19 -73
  65. package/build/src/cli/render/akuma.d.ts +5 -11
  66. package/build/src/cli/render/akuma.js +22 -30
  67. package/build/src/cli/render/catalog.js +1 -4
  68. package/build/src/cli/render/contract-history.js +2 -0
  69. package/build/src/cli/render/contract-observation.d.ts +2 -1
  70. package/build/src/cli/render/contract-observation.js +25 -1
  71. package/build/src/cli/render/contract-wait.d.ts +2 -2
  72. package/build/src/cli/render/contract-wait.js +13 -17
  73. package/build/src/cli/render/contract.js +12 -9
  74. package/build/src/cli/render/debt.js +1 -2
  75. package/build/src/cli/render/execution-progress.js +1 -3
  76. package/build/src/cli/render/kanshi-akuma.js +1 -2
  77. package/build/src/cli/render/kanshi.js +11 -17
  78. package/build/src/cli/render/receipt.d.ts +1 -1
  79. package/build/src/cli/render/receipt.js +33 -28
  80. package/build/src/cli/render/reconcile.js +2 -5
  81. package/build/src/cli/render/refusal.js +3 -6
  82. package/build/src/cli/render/terminal.d.ts +2 -4
  83. package/build/src/cli/render/terminal.js +10 -17
  84. package/build/src/cli/render/verbs.d.ts +1 -0
  85. package/build/src/cli/render/verbs.js +19 -17
  86. package/build/src/cli/runtime.js +3 -9
  87. package/build/src/core/facts/codec.js +7 -2
  88. package/build/src/core/facts/eligibility.d.ts +4 -4
  89. package/build/src/core/facts/eligibility.js +11 -0
  90. package/build/src/core/facts/fold.js +9 -5
  91. package/build/src/core/facts/gate.d.ts +5 -1
  92. package/build/src/core/facts/gate.js +14 -10
  93. package/build/src/core/facts/types.d.ts +5 -1
  94. package/build/src/core/facts/types.js +7 -0
  95. package/build/src/core/subject.d.ts +4 -1
  96. package/build/src/core/subject.js +10 -2
  97. package/build/src/core/verbs/amend.d.ts +15 -4
  98. package/build/src/core/verbs/amend.js +19 -9
  99. package/build/src/debt/index.d.ts +0 -1
  100. package/build/src/debt/index.js +6 -11
  101. package/build/src/debt/input.d.ts +2 -1
  102. package/build/src/debt/input.js +6 -4
  103. package/build/src/dispatch/index.d.ts +0 -17
  104. package/build/src/dispatch/index.js +1 -10
  105. package/build/src/git/identity.js +16 -45
  106. package/build/src/git/nuke.js +13 -23
  107. package/build/src/git/observe.d.ts +3 -0
  108. package/build/src/git/observe.js +25 -23
  109. package/build/src/git/process.js +11 -18
  110. package/build/src/git/read-observation.d.ts +5 -4
  111. package/build/src/git/repository.d.ts +2 -0
  112. package/build/src/git/repository.js +13 -1
  113. package/build/src/git/scratch.js +2 -14
  114. package/build/src/git/terminal-reconcile.js +1 -13
  115. package/build/src/index.d.ts +2 -0
  116. package/build/src/kanshi/index.d.ts +0 -1
  117. package/build/src/kanshi/index.js +0 -1
  118. package/build/src/kanshi/read.d.ts +21 -0
  119. package/build/src/kanshi/read.js +2 -1
  120. package/build/src/kanshi/report.d.ts +94 -0
  121. package/build/src/library/address.d.ts +12 -5
  122. package/build/src/library/address.js +18 -32
  123. package/build/src/library/akuma-creation.d.ts +39 -0
  124. package/build/src/library/akuma-creation.js +3 -9
  125. package/build/src/library/continuation.d.ts +10 -0
  126. package/build/src/library/contract-creation.js +10 -11
  127. package/build/src/library/contract-outcomes.d.ts +72 -1
  128. package/build/src/library/contract-outcomes.js +1 -0
  129. package/build/src/library/contract-types.d.ts +18 -0
  130. package/build/src/library/contract-types.js +2 -0
  131. package/build/src/library/contract-wait.d.ts +7 -0
  132. package/build/src/library/contract-wait.js +53 -49
  133. package/build/src/library/delivery.d.ts +25 -0
  134. package/build/src/library/input.d.ts +5 -23
  135. package/build/src/library/input.js +12 -7
  136. package/build/src/library/kei.js +39 -20
  137. package/build/src/library/keiyaku-classify.js +3 -3
  138. package/build/src/library/keiyaku-debt.js +1 -2
  139. package/build/src/library/keiyaku-identity.d.ts +3 -3
  140. package/build/src/library/keiyaku-identity.js +11 -6
  141. package/build/src/library/keiyaku-verbs.d.ts +456 -1362
  142. package/build/src/library/keiyaku-verbs.js +80 -92
  143. package/build/src/library/keiyaku-wait.d.ts +183 -0
  144. package/build/src/library/keiyaku-wait.js +213 -0
  145. package/build/src/library/keiyaku.d.ts +3 -1
  146. package/build/src/library/keiyaku.js +49 -73
  147. package/build/src/{mcp/output.d.ts → library/model-tools.d.ts} +227 -56
  148. package/build/src/library/model-tools.js +347 -0
  149. package/build/src/library/outcome.js +5 -6
  150. package/build/src/library/refusal.d.ts +25 -1
  151. package/build/src/library/refusal.js +4 -5
  152. package/build/src/library/selection.d.ts +12 -0
  153. package/build/src/library/selection.js +1 -2
  154. package/build/src/mcp/adapter.d.ts +0 -6
  155. package/build/src/mcp/adapter.js +10 -159
  156. package/build/src/mcp/description.d.ts +2 -0
  157. package/build/src/mcp/description.js +2 -0
  158. package/build/src/mcp/help.d.ts +1 -1
  159. package/build/src/mcp/help.js +6 -4
  160. package/build/src/pi/index.d.ts +3 -0
  161. package/build/src/pi/index.js +83 -0
  162. package/build/src/protocol/amend.d.ts +14 -3
  163. package/build/src/protocol/amend.js +113 -46
  164. package/build/src/protocol/bind.d.ts +1 -1
  165. package/build/src/protocol/bind.js +5 -16
  166. package/build/src/protocol/completion.d.ts +30 -0
  167. package/build/src/protocol/completion.js +8 -5
  168. package/build/src/protocol/deliver.js +7 -20
  169. package/build/src/protocol/delivery-preview.d.ts +5 -0
  170. package/build/src/protocol/execution-observation.d.ts +8 -0
  171. package/build/src/protocol/intent.d.ts +1 -0
  172. package/build/src/protocol/intent.js +4 -1
  173. package/build/src/protocol/operations.d.ts +54 -16
  174. package/build/src/protocol/operations.js +17 -31
  175. package/build/src/protocol/placement.js +7 -1
  176. package/build/src/protocol/progress.js +0 -6
  177. package/build/src/protocol/read/status.d.ts +40 -0
  178. package/build/src/protocol/read/status.js +7 -10
  179. package/build/src/protocol/reintegrate.js +2 -2
  180. package/build/src/protocol/result-leaves.d.ts +56 -8
  181. package/build/src/protocol/result-leaves.js +11 -2
  182. package/build/src/protocol/run.js +1 -4
  183. package/build/src/protocol/verify.d.ts +10 -0
  184. package/build/src/protocol/verify.js +1 -0
  185. package/build/src/runtime/proc/windows-launch.exe +0 -0
  186. package/build/src/settlement/settle.js +19 -68
  187. package/package.json +7 -3
  188. package/plugins/pi/README.md +55 -97
  189. package/plugins/pi/keiyaku.ts +2 -9
  190. package/skills/keiyaku-akuma/SKILL.md +13 -9
  191. package/skills/keiyaku-babysit/SKILL.md +8 -6
  192. package/skills/keiyaku-workflow/SKILL.md +2 -1
  193. package/build/plugins/pi/akuma-tools.ts +0 -283
  194. package/build/src/body/keys.d.ts +0 -4
  195. package/build/src/body/keys.js +0 -11
  196. package/build/src/kanshi/roster.d.ts +0 -2
  197. package/build/src/kanshi/roster.js +0 -2
  198. package/build/src/mcp/output.js +0 -193
  199. package/plugins/pi/akuma-tools.ts +0 -283
@@ -8,11 +8,14 @@ export function record(value, label) {
8
8
  }
9
9
  return value;
10
10
  }
11
- export function closed(value, allowed, label) {
12
- for (const key of Object.keys(value)) {
11
+ /** One closed caller object: an object with only the fields its surface names. */
12
+ export function fields(value, allowed, label) {
13
+ const recordValue = record(value, label);
14
+ for (const key of Object.keys(recordValue)) {
13
15
  if (!allowed.includes(key))
14
16
  throw new KeiyakuError("invalid-input", `${label} has unknown field: ${key}`);
15
17
  }
18
+ return recordValue;
16
19
  }
17
20
  export function debtId(value) {
18
21
  if (typeof value !== "string")
@@ -74,8 +77,7 @@ export function addInput(input) {
74
77
  return parseDebtInput(addDebtInputSchema.extend({ signal: signalSchema }), input);
75
78
  }
76
79
  export function addDocumentInput(input) {
77
- const v = record(input, "addDocument input");
78
- closed(v, ["markdown", "signal"], "addDocument input");
80
+ const v = fields(input, ["markdown", "signal"], "addDocument input");
79
81
  const markdown = text(v.markdown, "markdown");
80
82
  if (markdown === undefined)
81
83
  throw new KeiyakuError("invalid-input", "markdown is required");
@@ -1,26 +1,9 @@
1
- import { z } from "zod";
2
1
  import { type ContractId } from "../core/facts/types.js";
3
2
  import { type AkumaId } from "../akuma/identity.js";
4
3
  import { type PrivateStateSeatCloseLag } from "../git/private-state-seat.js";
5
4
  import type { GitRepository } from "../git/process.js";
6
5
  import { type GitReadObservation } from "../git/read-observation.js";
7
6
  import { type DispatchAssociation } from "../akuma/dispatch-association.js";
8
- export declare const dispatchSchema: z.ZodReadonly<z.ZodObject<{
9
- akumaId: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
10
- contractId: z.ZodPipe<z.ZodString, z.ZodTransform<ContractId, string>>;
11
- dispatchedAt: z.ZodString;
12
- }, z.core.$strict>>;
13
- export declare const dispatchFailureSchema: z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
14
- kind: z.ZodLiteral<"conflict">;
15
- current: z.ZodReadonly<z.ZodObject<{
16
- akumaId: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
17
- contractId: z.ZodPipe<z.ZodString, z.ZodTransform<ContractId, string>>;
18
- dispatchedAt: z.ZodString;
19
- }, z.core.$strict>>;
20
- }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
21
- kind: z.ZodLiteral<"publication-failed">;
22
- diagnostic: z.ZodString;
23
- }, z.core.$strict>>]>;
24
7
  export type Dispatch = Readonly<{
25
8
  akumaId: AkumaId;
26
9
  contractId: ContractId;
@@ -1,9 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
- import { z } from "zod";
3
- import { contractIdSchema } from "../git/identity.js";
4
2
  import { AuthorityCorruptionError } from "../core/facts/errors.js";
5
3
  import { contractId } from "../core/facts/types.js";
6
- import { akumaIdSchema, parseAkumaId } from "../akuma/identity.js";
4
+ import { parseAkumaId } from "../akuma/identity.js";
7
5
  import { appendPrivateStateSeatClose, confirmPrivateStatePublication, mergePrivateStateSeatClose, withPrivateStatePublicationSeat, } from "../git/private-state-seat.js";
8
6
  import { GIT_FORMAT_BYTES, GIT_FORMAT_PATH, GIT_REF, readBlob, readGitPaths, updateGitTree, updateRefsAtomically, writeBlob, writeStateCommit, } from "../git/repository.js";
9
7
  import { withGitDecodeChannel, withGitReadObservation, withGitTargetedReadObservation, } from "../git/read-observation.js";
@@ -11,13 +9,6 @@ import { NO_DISPATCH_ASSOCIATION } from "../akuma/dispatch-association.js";
11
9
  const DISPATCH_ROOT = "dispatch";
12
10
  const DISPATCH_PREFIX = `${DISPATCH_ROOT}/`;
13
11
  const DISPATCH_SUFFIX = ".json";
14
- export const dispatchSchema = z
15
- .strictObject({ akumaId: akumaIdSchema, contractId: contractIdSchema, dispatchedAt: z.string() })
16
- .readonly();
17
- export const dispatchFailureSchema = z.union([
18
- z.strictObject({ kind: z.literal("conflict"), current: dispatchSchema }).readonly(),
19
- z.strictObject({ kind: z.literal("publication-failed"), diagnostic: z.string() }).readonly(),
20
- ]);
21
12
  function pathFor(akumaId) {
22
13
  return `${DISPATCH_PREFIX}${createHash("sha256").update(akumaId).digest("hex")}${DISPATCH_SUFFIX}`;
23
14
  }
@@ -1,52 +1,23 @@
1
1
  import { z } from "zod";
2
2
  import { createHash } from "node:crypto";
3
3
  import { changeId, contractHead, contractId, snapshotId, } from "../core/facts/types.js";
4
+ function validatedString(validate, message) {
5
+ return z.string().transform((value, context) => {
6
+ try {
7
+ return validate(value);
8
+ }
9
+ catch {
10
+ context.addIssue({ code: "custom", message });
11
+ return z.NEVER;
12
+ }
13
+ });
14
+ }
4
15
  // Structural admission reuses the pure identity constructors; physical minting remains distinct.
5
- export const contractIdSchema = z.string().transform((value, context) => {
6
- try {
7
- return contractId(value);
8
- }
9
- catch {
10
- context.addIssue({ code: "custom", message: "invalid contractId" });
11
- return z.NEVER;
12
- }
13
- });
14
- export const snapshotIdSchema = z.string().transform((value, context) => {
15
- try {
16
- return snapshotId(value);
17
- }
18
- catch {
19
- context.addIssue({ code: "custom", message: "invalid snapshotId" });
20
- return z.NEVER;
21
- }
22
- });
23
- export const contractHeadSchema = z.string().transform((value, context) => {
24
- try {
25
- return contractHead(value);
26
- }
27
- catch {
28
- context.addIssue({ code: "custom", message: "invalid ContractHead" });
29
- return z.NEVER;
30
- }
31
- });
32
- export const changeIdSchema = z.string().transform((value, context) => {
33
- try {
34
- return changeId(value);
35
- }
36
- catch {
37
- context.addIssue({ code: "custom", message: "invalid changeId" });
38
- return z.NEVER;
39
- }
40
- });
41
- export const mintedSnapshotInputSchema = z.string().transform((value, context) => {
42
- try {
43
- return mintSnapshotId(value);
44
- }
45
- catch {
46
- context.addIssue({ code: "custom", message: "invalid mintSnapshotId" });
47
- return z.NEVER;
48
- }
49
- });
16
+ export const contractIdSchema = validatedString(contractId, "invalid contractId");
17
+ export const snapshotIdSchema = validatedString(snapshotId, "invalid snapshotId");
18
+ export const contractHeadSchema = validatedString(contractHead, "invalid ContractHead");
19
+ export const changeIdSchema = validatedString(changeId, "invalid changeId");
20
+ export const mintedSnapshotInputSchema = validatedString(mintSnapshotId, "invalid mintSnapshotId");
50
21
  const GIT_OBJECT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
51
22
  function locator(value) {
52
23
  return createHash("sha256").update(value, "utf8").digest("hex");
@@ -56,31 +56,27 @@ async function unregisteredResidueBelongsToRepository(repository, path) {
56
56
  throw error;
57
57
  }
58
58
  }
59
- async function removeUnregisteredResidue(repository, entry) {
60
- let present = true;
59
+ /** Residue presence follows access: a path whose target is gone is already removed. */
60
+ async function residuePresent(path) {
61
61
  try {
62
- await access(entry.path);
62
+ await access(path);
63
+ return true;
63
64
  }
64
65
  catch (error) {
65
66
  if (error.code === "ENOENT")
66
- present = false;
67
- else
68
- throw error;
67
+ return false;
68
+ throw error;
69
69
  }
70
- if (!present)
70
+ }
71
+ async function removeUnregisteredResidue(repository, entry) {
72
+ if (!(await residuePresent(entry.path)))
71
73
  return true;
72
74
  if (!(await unregisteredResidueBelongsToRepository(repository, entry.path))) {
73
75
  throw new GitResetStopError(`managed Place path has foreign custody: ${entry.path}`);
74
76
  }
75
77
  await rm(entry.path, { recursive: true, force: true });
76
- try {
77
- await access(entry.path);
78
- }
79
- catch (error) {
80
- if (error.code === "ENOENT")
81
- return true;
82
- throw error;
83
- }
78
+ if (!(await residuePresent(entry.path)))
79
+ return true;
84
80
  throw new GitResetStopError(`managed Place worktree remains present: ${entry.path}`);
85
81
  }
86
82
  async function removeManagedWorktree(repository, entry) {
@@ -93,14 +89,8 @@ async function removeManagedWorktree(repository, entry) {
93
89
  if ((await registeredWorktrees(repository)).some((candidate) => candidate.path === entry.path)) {
94
90
  throw new GitResetStopError(`managed Place worktree remains registered: ${entry.path}`);
95
91
  }
96
- try {
97
- await access(entry.path);
98
- }
99
- catch (error) {
100
- if (error.code === "ENOENT")
101
- return true;
102
- throw error;
103
- }
92
+ if (!(await residuePresent(entry.path)))
93
+ return true;
104
94
  throw new GitResetStopError(`managed Place worktree remains present: ${entry.path}`);
105
95
  }
106
96
  async function deleteRefAt(repository, ref, expectedOid) {
@@ -51,6 +51,9 @@ export type BindTargetSelection = Readonly<{
51
51
  }> | Readonly<{
52
52
  kind: "targetless";
53
53
  }>;
54
+ export declare function selectExplicitTarget(repository: GitRepository, input: string): Promise<Extract<BindTargetSelection, {
55
+ kind: "explicit" | "contract";
56
+ }> | null>;
54
57
  export declare function normalizeTargetBranch(repository: GitRepository, input: string): Promise<string | null>;
55
58
  /**
56
59
  * Observe bind's tender start and optional reward target without creating persistent state.
@@ -1,6 +1,7 @@
1
1
  import { decodeJournal } from "../core/facts/codec.js";
2
2
  import { AuthorityCorruptionError } from "../core/facts/errors.js";
3
3
  import { foldJournal } from "../core/facts/fold.js";
4
+ import { contractId, } from "../core/facts/types.js";
4
5
  import { resolveContractTarget } from "./target.js";
5
6
  import { contractJournalPath, contractJournalPaths, mintContractHead, mintSnapshotId, } from "./identity.js";
6
7
  import { currentBranch, isKeiyakuOwnedRef } from "./repository.js";
@@ -34,6 +35,18 @@ export function deliveryTargetObserver(observation) {
34
35
  return { head, drift: unavailable || (integration !== null && head !== expected) };
35
36
  };
36
37
  }
38
+ export async function selectExplicitTarget(repository, input) {
39
+ if (input.startsWith("kei/")) {
40
+ try {
41
+ return { kind: "contract", contractId: contractId(input) };
42
+ }
43
+ catch {
44
+ return null;
45
+ }
46
+ }
47
+ const target = await normalizeTargetBranch(repository, input);
48
+ return target === null ? null : { kind: "explicit", target };
49
+ }
37
50
  const TARGET_COORDINATES_FORMAT = "%(refname)%00%(objectname)%00";
38
51
  export async function normalizeTargetBranch(repository, input) {
39
52
  if (input.includes("\0"))
@@ -201,19 +214,22 @@ export function activeContractJournalPaths(observation) {
201
214
  return [path];
202
215
  });
203
216
  }
204
- /** Observe active journals without following their prerequisite edges. */
205
- export async function observeActiveContractJournals(observation) {
206
- const git = observation.snapshot;
207
- const journals = activeContractJournalPaths(observation).map((path) => [path, git.paths.get(path)]);
208
- const results = await observation.readBlobs(journals.map(([, entry]) => entry.oid));
217
+ async function readJournalBlobs(entries, readBlobsAt) {
218
+ const results = await readBlobsAt(entries.map(([, entry]) => entry.oid));
209
219
  const blobs = new Map();
210
- for (const [path, entry] of journals) {
220
+ for (const [path, entry] of entries) {
211
221
  const result = results.get(entry.oid);
212
222
  if (result?.kind !== "present")
213
223
  throw new AuthorityCorruptionError(`missing Git journal object: ${path}`);
214
224
  blobs.set(entry.oid, result.bytes);
215
225
  }
216
- return enumerateContractObservations(git, blobs, "active");
226
+ return blobs;
227
+ }
228
+ /** Observe active journals without following their prerequisite edges. */
229
+ export async function observeActiveContractJournals(observation) {
230
+ const git = observation.snapshot;
231
+ const journals = activeContractJournalPaths(observation).map((path) => [path, git.paths.get(path)]);
232
+ return enumerateContractObservations(git, await readJournalBlobs(journals, observation.readBlobs), "active");
217
233
  }
218
234
  export async function observeActiveContractWorld(observation) {
219
235
  const contracts = await observeActiveContractJournals(observation);
@@ -230,14 +246,7 @@ export async function observeActiveContractWorld(observation) {
230
246
  export async function observeContractWorld(observation, requested = []) {
231
247
  const git = observation.snapshot;
232
248
  const journals = [...git.paths].filter(([path, entry]) => /^contracts\/(?:active|terminal)\//u.test(path) && path.endsWith(".jsonl") && entry.type === "blob");
233
- const results = await observation.readBlobs(journals.map(([, entry]) => entry.oid));
234
- const blobs = new Map();
235
- for (const [path, entry] of journals) {
236
- const result = results.get(entry.oid);
237
- if (result?.kind !== "present")
238
- throw new AuthorityCorruptionError(`missing Git journal object: ${path}`);
239
- blobs.set(entry.oid, result.bytes);
240
- }
249
+ const blobs = await readJournalBlobs(journals, observation.readBlobs);
241
250
  const contracts = new Map(enumerateContractObservations(git, blobs));
242
251
  for (const id of requested) {
243
252
  if (!contracts.has(id))
@@ -257,14 +266,7 @@ async function observeTargetedContractsFromSnapshotAt(snapshot, readBlobsAt, ids
257
266
  const journal = snapshot.paths.get(path);
258
267
  return journal?.type === "blob" ? [[path, journal]] : [];
259
268
  });
260
- const results = await readBlobsAt(entries.map(([, entry]) => entry.oid));
261
- const blobs = new Map();
262
- for (const [path, entry] of entries) {
263
- const result = results.get(entry.oid);
264
- if (result?.kind !== "present")
265
- throw new AuthorityCorruptionError(`missing Git journal object: ${path}`);
266
- blobs.set(entry.oid, result.bytes);
267
- }
269
+ const blobs = await readJournalBlobs(entries, readBlobsAt);
268
270
  const contracts = new Map();
269
271
  for (const id of ids)
270
272
  contracts.set(id, observeFromGit(snapshot, id, blobs));
@@ -30,6 +30,14 @@ export function gitChildEnvironment(environment) {
30
30
  }
31
31
  return { ...inherited, ...environment };
32
32
  }
33
+ function gitProcessOptions(repository, args, environment) {
34
+ return {
35
+ argv: [repository.gitPath, ...args],
36
+ cwd: repository.effectiveCwd,
37
+ env: gitChildEnvironment(environment),
38
+ ...(repository.signal === undefined ? {} : { signal: repository.signal }),
39
+ };
40
+ }
33
41
  function commandError(command, error) {
34
42
  const candidate = error;
35
43
  const stderr = candidate.stderr === undefined ? Buffer.alloc(0) : Buffer.from(candidate.stderr);
@@ -51,12 +59,7 @@ export async function executeGit(repository, args, input, environment) {
51
59
  const stderr = [];
52
60
  let stderrBytes = 0;
53
61
  let inputError;
54
- const owned = spawnCancellableProcess({
55
- argv: [repository.gitPath, ...args],
56
- cwd: repository.effectiveCwd,
57
- env: gitChildEnvironment(environment),
58
- ...(repository.signal === undefined ? {} : { signal: repository.signal }),
59
- });
62
+ const owned = spawnCancellableProcess(gitProcessOptions(repository, args, environment));
60
63
  const child = owned.child;
61
64
  child.stdout.on("data", (chunk) => stdout.push(chunk));
62
65
  child.stderr.on("data", (chunk) => {
@@ -127,12 +130,7 @@ export async function runGitPipe(repository, sourceArgs, sinkArgs) {
127
130
  const processes = [];
128
131
  const pending = [];
129
132
  const start = (args) => {
130
- const owned = spawnCancellableProcess({
131
- argv: [repository.gitPath, ...args],
132
- cwd: repository.effectiveCwd,
133
- env: gitChildEnvironment(),
134
- ...(repository.signal === undefined ? {} : { signal: repository.signal }),
135
- });
133
+ const owned = spawnCancellableProcess(gitProcessOptions(repository, args));
136
134
  processes.push(owned);
137
135
  const { child } = owned;
138
136
  const stderr = [];
@@ -199,12 +197,7 @@ export async function runGitPipe(repository, sourceArgs, sinkArgs) {
199
197
  }
200
198
  }
201
199
  export async function consumeGitStdout(repository, args, consume) {
202
- const result = await consumeProcessStdout({
203
- argv: [repository.gitPath, ...args],
204
- cwd: repository.effectiveCwd,
205
- env: gitChildEnvironment(),
206
- ...(repository.signal === undefined ? {} : { signal: repository.signal }),
207
- }, consume);
200
+ const result = await consumeProcessStdout(gitProcessOptions(repository, args), consume);
208
201
  const { outcome } = result;
209
202
  if (outcome.kind === "terminal" && outcome.code === 0)
210
203
  return;
@@ -28,14 +28,15 @@ export type GitDecodeChannel = Readonly<{
28
28
  readonly [gitDecodeChannelBrand]: true;
29
29
  readObjects(oids: readonly GitOid[]): Promise<ReadonlyMap<GitOid, GitObjectResult>>;
30
30
  }>;
31
+ type TreeObservation = Readonly<{
32
+ paths: ReadonlyMap<string, TreeEntry>;
33
+ directories: ReadonlyMap<string, ReadonlyMap<string, TreeEntry>>;
34
+ }>;
31
35
  export type GitTreeSelection = Readonly<{
32
36
  paths?: readonly string[];
33
37
  subtrees?: readonly string[];
34
38
  }>;
35
- export declare function readGitTreeSelection(channel: GitDecodeChannel, root: GitOid, selection: GitTreeSelection): Promise<Readonly<{
36
- paths: ReadonlyMap<string, TreeEntry>;
37
- directories: ReadonlyMap<string, ReadonlyMap<string, TreeEntry>>;
38
- }>>;
39
+ export declare function readGitTreeSelection(channel: GitDecodeChannel, root: GitOid, selection: GitTreeSelection): Promise<TreeObservation>;
39
40
  export declare function withGitDecodeChannel<Value>(repository: GitRepository, consume: (channel: GitDecodeChannel) => Value | PromiseLike<Value>, onRetirementFailure?: (error: unknown) => void): Promise<Value>;
40
41
  /**
41
42
  * Blob-only reads over a decode channel: a missing object stays missing, and a present
@@ -37,6 +37,8 @@ type RegisteredWorktree = Readonly<{
37
37
  }>;
38
38
  export declare function registeredWorktrees(repository: GitRepository): Promise<readonly RegisteredWorktree[]>;
39
39
  export declare function registeredWorktreePaths(repository: GitRepository): Promise<readonly string[]>;
40
+ /** Absence is ENOENT on the path entry itself: a dangling symlink is present residue, not a missing path. */
41
+ export declare function pathExists(path: string): Promise<boolean>;
40
42
  export declare function repositoryAt(cwd: string, gitPath?: string): Promise<GitRepository>;
41
43
  export declare function commonGitDirectory(repository: GitRepository): string;
42
44
  /** Read one worktree's attached branch, or null for detached HEAD. */
@@ -1,6 +1,6 @@
1
1
  import { KeiyakuError } from "../errors.js";
2
2
  import { isAbsolute, resolve } from "node:path";
3
- import { realpath } from "node:fs/promises";
3
+ import { lstat, realpath } from "node:fs/promises";
4
4
  import { AuthorityCorruptionError } from "../core/facts/errors.js";
5
5
  import { gitObjectId } from "./identity.js";
6
6
  import { executeGit, GitPlumbingError } from "./process.js";
@@ -82,6 +82,18 @@ export async function registeredWorktrees(repository) {
82
82
  export async function registeredWorktreePaths(repository) {
83
83
  return (await registeredWorktrees(repository)).map((worktree) => worktree.path);
84
84
  }
85
+ /** Absence is ENOENT on the path entry itself: a dangling symlink is present residue, not a missing path. */
86
+ export async function pathExists(path) {
87
+ try {
88
+ await lstat(path);
89
+ return true;
90
+ }
91
+ catch (error) {
92
+ if (error.code === "ENOENT")
93
+ return false;
94
+ throw error;
95
+ }
96
+ }
85
97
  export async function repositoryAt(cwd, gitPath = "git") {
86
98
  if (typeof cwd !== "string" || cwd.length === 0) {
87
99
  throw new Error("repository path must be a nonempty string");
@@ -1,12 +1,12 @@
1
1
  import { z } from "zod";
2
2
  import { createHash, randomBytes } from "node:crypto";
3
- import { lstat, realpath, unlink } from "node:fs/promises";
3
+ import { realpath, unlink } from "node:fs/promises";
4
4
  import { tmpdir } from "node:os";
5
5
  import { basename, dirname, join } from "node:path";
6
6
  import { acquireSqliteTransactionLock, tryAcquireSqliteTransactionLock, } from "../coordination/sqlite-transaction-lock.js";
7
7
  import { contractLocator, gitRefLocator, gitObjectIdForSnapshot } from "./identity.js";
8
8
  import { executeGit } from "./process.js";
9
- import { registeredWorktreePaths } from "./repository.js";
9
+ import { pathExists, registeredWorktreePaths } from "./repository.js";
10
10
  const SCRATCH_PREFIX = "keiyaku-v4-verify-";
11
11
  const SCRATCH_ROOT = await realpath(tmpdir());
12
12
  const SCRATCH_PATTERN = /^keiyaku-v4-verify-([0-9a-f]{24}|[0-9a-f]{64}-[0-9a-f]{64}-[0-9a-f]{64})$/;
@@ -59,18 +59,6 @@ async function* collectableScratchWorktrees(paths, terminalPrefix) {
59
59
  yield { path, lockPath, release: () => lock.close() };
60
60
  }
61
61
  }
62
- /** Absence is ENOENT on the path entry itself: a dangling symlink is present residue, not a missing path. */
63
- async function pathExists(path) {
64
- try {
65
- await lstat(path);
66
- return true;
67
- }
68
- catch (error) {
69
- if (error.code === "ENOENT")
70
- return false;
71
- throw error;
72
- }
73
- }
74
62
  async function removeScratch(repository, path) {
75
63
  const removal = AbortSignal.timeout(SCRATCH_REMOVAL_TIMEOUT_MS);
76
64
  const retirementRepository = { ...repository, signal: removal };
@@ -1,5 +1,4 @@
1
- import { lstat } from "node:fs/promises";
2
- import { CANDIDATE_PIN_REF_NAMESPACE, isKeiyakuOwnedRef, readRef, writeCommit } from "./repository.js";
1
+ import { CANDIDATE_PIN_REF_NAMESPACE, isKeiyakuOwnedRef, pathExists, readRef, writeCommit, } from "./repository.js";
3
2
  import { contractPhysicalName, gitObjectIdForSnapshot, mintSnapshotId } from "./identity.js";
4
3
  import { withGitReadObservation } from "./read-observation.js";
5
4
  import { observeContractWorld } from "./observe.js";
@@ -8,17 +7,6 @@ import { runDestroyHooks } from "./hooks.js";
8
7
  import { terminalSealExpectations as decodeTerminalSealExpectations, terminalSealSnapshots, observeTerminalWorkspace, } from "./terminal-seal.js";
9
8
  import { GitPlumbingError, executeGit } from "./process.js";
10
9
  import { worktreePath } from "./workspace.js";
11
- async function pathExists(path) {
12
- try {
13
- await lstat(path);
14
- return true;
15
- }
16
- catch (error) {
17
- if (error.code === "ENOENT")
18
- return false;
19
- throw error;
20
- }
21
- }
22
10
  /** Attempt removal once. Retention is a lag carrying its reason; no effect claims the worktree state after it. */
23
11
  async function removeTerminalWorktree(repository, topology, path) {
24
12
  const registered = topology.paths.has(path);
@@ -10,6 +10,7 @@ export type { Guidance } from "./library/kei.js";
10
10
  export type { Delivery } from "./library/delivery.js";
11
11
  export { Keiyaku, KeiyakuArcDocumentError, KeiyakuUsageError } from "./library/keiyaku.js";
12
12
  export type { KeiyakuAt } from "./library/keiyaku.js";
13
+ export type { InvocationWaitMember, InvocationWaitResult } from "./library/keiyaku-wait.js";
13
14
  export type { KeiyakuRunOptions, VerbEntry, VerbName, VerbInput, VerbOutput, VerbProgress, VerbRun, VerbRunFor, VerbDisposition, VerbCompletion, } from "./library/keiyaku-verbs.js";
14
15
  export { Keis } from "./library/contract-composition.js";
15
16
  export type { KeisReconcile, ReconcileInput } from "./library/contract-composition.js";
@@ -26,6 +27,7 @@ export type { AkumaAddressRefusal, AkumaSetAddressInput } from "./library/addres
26
27
  export type { SpawnProgress, SpawnWaitObserver } from "./library/akuma-creation.js";
27
28
  export type { WhoamiFacts } from "./library/keiyaku-identity.js";
28
29
  export type { ChangeId, ContractHead, ContractId, ContractState, ContractTarget, JournalEntry as Fact, FactKind, SnapshotId, } from "./core/facts/types.js";
30
+ export type { GateStaleReason } from "./core/facts/gate.js";
29
31
  export { Kanshi } from "./kanshi/index.js";
30
32
  export type { KanshiScopeInput, KanshiBoardOptions, KanshiCountsReport, AkumaKanshiRow, AkumaKanshiWorld, ContractEndpointObservation, ContractHolderObservation, ContractKanshiBoard, ContractKanshiDetail, KanshiContractReport, KanshiResult, KanshiRegionSelection, KanshiReport, RegionDeclaration, RegionRead, Section, DebtKanshiRow, DebtKanshiWorld, } from "./kanshi/index.js";
31
33
  export { AkumaAddressError, AkumaWorldScopeError, Akumas } from "./library/akumas.js";
@@ -15,7 +15,6 @@ export declare const Kanshi: Readonly<{
15
15
  of(scope: KanshiScopeInput): Kanshi;
16
16
  }>;
17
17
  export { kanshiObservationSchema } from "./read.js";
18
- export { kanshiCountsReportSchema } from "./counts.js";
19
18
  export type { KanshiCountsReport } from "./counts.js";
20
19
  export { regionReadSchema, kanshiReportSchema, kanshiContractReportSchema, kanshiResultSchema } from "./report.js";
21
20
  export type { KanshiBoardOptions, KanshiScopeInput } from "./read.js";
@@ -26,5 +26,4 @@ export const Kanshi = Object.freeze({
26
26
  },
27
27
  });
28
28
  export { kanshiObservationSchema } from "./read.js";
29
- export { kanshiCountsReportSchema } from "./counts.js";
30
29
  export { regionReadSchema, kanshiReportSchema, kanshiContractReportSchema, kanshiResultSchema } from "./report.js";
@@ -159,6 +159,17 @@ export declare const kanshiObservationSchema: z.ZodReadonly<z.ZodObject<{
159
159
  toolId: z.ZodString;
160
160
  }, z.core.$strict>>>>>;
161
161
  latestActivity: z.ZodExactOptional<z.ZodNumber>;
162
+ awaiting: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
163
+ kind: z.ZodLiteral<"permission">;
164
+ id: z.ZodNumber;
165
+ requests: z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
166
+ id: z.ZodString;
167
+ action: z.ZodString;
168
+ resources: z.ZodReadonly<z.ZodArray<z.ZodString>>;
169
+ tool: z.ZodExactOptional<z.ZodString>;
170
+ }, z.core.$strict>>>>;
171
+ clipped: z.ZodExactOptional<z.ZodLiteral<true>>;
172
+ }, z.core.$strict>>>;
162
173
  pending: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodReadonly<z.ZodObject<{
163
174
  id: z.ZodNumber;
164
175
  tellId: z.ZodString;
@@ -239,6 +250,16 @@ export declare const kanshiObservationSchema: z.ZodReadonly<z.ZodObject<{
239
250
  kind: z.ZodLiteral<"missing">;
240
251
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
241
252
  kind: z.ZodLiteral<"stale">;
253
+ reason: z.ZodExactOptional<z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
254
+ kind: z.ZodLiteral<"candidate-content-changed">;
255
+ target: z.ZodExactOptional<z.ZodString>;
256
+ previousChange: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").ChangeId, string>>;
257
+ currentChange: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").ChangeId, string>>;
258
+ }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
259
+ kind: z.ZodLiteral<"snapshot-changed">;
260
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
261
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").SnapshotId, string>>;
262
+ }, z.core.$strict>>]>>;
242
263
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
243
264
  kind: z.ZodLiteral<"attested">;
244
265
  verdict: z.ZodEnum<{
@@ -13,8 +13,9 @@ import { readContractCatalogue, readContractObservation, readContractPhase, } fr
13
13
  import { readDebtHolderProjectionAt } from "../settlement/holder.js";
14
14
  import { observeRecentDebtStatus, DebtAuthorityCorruptionError } from "../debt/index.js";
15
15
  import { kanshiReportSchema, kanshiContractReportSchema, sectionSchema } from "./report.js";
16
- import { ROSTER_SNAPSHOT_ROWS, ROSTER_VISIBLE_ROWS } from "./roster.js";
17
16
  import { selectRegion } from "./select.js";
17
+ const ROSTER_VISIBLE_ROWS = 10;
18
+ const ROSTER_SNAPSHOT_ROWS = 3;
18
19
  export const kanshiObservationSchema = z
19
20
  .strictObject({
20
21
  report: z.union([kanshiReportSchema, kanshiContractReportSchema]),