@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
@@ -20,6 +20,7 @@ const bindFields = {
20
20
  ...regionFields,
21
21
  };
22
22
  const amendFields = {
23
+ target: z.string().exactOptional(),
23
24
  changedSections: z.array(z.string()).min(1).readonly().exactOptional(),
24
25
  gatesChanged: z.literal(true).exactOptional(),
25
26
  afterChanged: z.literal(true).exactOptional(),
@@ -26,6 +26,14 @@ export declare const contractHistoryEventSchema: z.ZodUnion<readonly [z.ZodReado
26
26
  kind: z.ZodLiteral<"amend">;
27
27
  id: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").EntryUlid, string>>;
28
28
  at: z.ZodString;
29
+ target: z.ZodExactOptional<z.ZodUnion<readonly [z.ZodString, z.ZodReadonly<z.ZodObject<{
30
+ kind: z.ZodLiteral<"contract">;
31
+ contractId: z.ZodPipe<z.ZodString, z.ZodTransform<ContractId, string>>;
32
+ }, z.core.$strict>>]>>;
33
+ targetIncarnation: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
34
+ id: z.ZodString;
35
+ identity: z.ZodString;
36
+ }, z.core.$strict>>>;
29
37
  changedSections: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
30
38
  gates: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>>;
31
39
  after: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<ContractId, string>>>>>;
@@ -103,6 +111,14 @@ export declare const contractHistorySchema: z.ZodUnion<readonly [z.ZodReadonly<z
103
111
  kind: z.ZodLiteral<"amend">;
104
112
  id: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").EntryUlid, string>>;
105
113
  at: z.ZodString;
114
+ target: z.ZodExactOptional<z.ZodUnion<readonly [z.ZodString, z.ZodReadonly<z.ZodObject<{
115
+ kind: z.ZodLiteral<"contract">;
116
+ contractId: z.ZodPipe<z.ZodString, z.ZodTransform<ContractId, string>>;
117
+ }, z.core.$strict>>]>>;
118
+ targetIncarnation: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
119
+ id: z.ZodString;
120
+ identity: z.ZodString;
121
+ }, z.core.$strict>>>;
106
122
  changedSections: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
107
123
  gates: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>>>>;
108
124
  after: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodPipe<z.ZodString, z.ZodTransform<ContractId, string>>>>>;
@@ -193,6 +209,8 @@ export type KeisOptions = Readonly<{
193
209
  settings?: Settings;
194
210
  }>;
195
211
  export type AmendInput = Readonly<{
212
+ /** Explicit existing branch or active Contract; omission retains the target. */
213
+ target?: string;
196
214
  markdown?: string;
197
215
  after?: readonly ContractId[];
198
216
  gates?: readonly string[];
@@ -26,6 +26,8 @@ export const contractHistoryEventSchema = z.union([
26
26
  targetIncarnation: z.strictObject({ id: z.string(), identity: z.string() }).readonly().exactOptional(),
27
27
  }),
28
28
  historyEvent("amend", {
29
+ target: historyTarget.exactOptional(),
30
+ targetIncarnation: z.strictObject({ id: z.string(), identity: z.string() }).readonly().exactOptional(),
29
31
  changedSections: z.array(z.string()).readonly().exactOptional(),
30
32
  gates: historyGates,
31
33
  after: historyAfter,
@@ -90,4 +90,11 @@ export type ValidatedWait = Readonly<{
90
90
  }>;
91
91
  export declare function validateContractWait(scope: RepositoryScope, input: unknown): ValidatedWait;
92
92
  export declare function validateContractWaitHandle(scope: RepositoryScope, id: ContractId, input?: ContractWaitOptions): ValidatedWait;
93
+ /** One invocation's journal baselines and witnessed progress, shared with mixed observation. */
94
+ export declare function createContractWaitObserver(scope: RepositoryScope, ids: readonly ContractId[]): {
95
+ members: () => readonly ContractWaitMember[];
96
+ reason: (completion: "any" | "all") => "deadline" | "missing" | "terminal" | "changed" | undefined;
97
+ satisfied: () => ContractId[];
98
+ observe(signal?: AbortSignal): Promise<void>;
99
+ };
93
100
  export declare function waitContractLocal(input: ValidatedWait): Promise<ContractWaitResult>;
@@ -67,10 +67,12 @@ function validateContractWaitValues(values, scope) {
67
67
  ...(signal === undefined ? {} : { signal }),
68
68
  };
69
69
  }
70
+ function satisfied(member) {
71
+ return member.present === true && (member.changed || member.terminal !== null);
72
+ }
70
73
  function readiness(members, completion) {
71
74
  if (members.some((member) => member.present === false))
72
75
  return "missing";
73
- const satisfied = (member) => member.present === true && (member.changed || member.terminal !== null);
74
76
  if (completion === "any" ? members.some(satisfied) : members.every(satisfied))
75
77
  return members.some((member) => member.changed) ? "changed" : "terminal";
76
78
  return undefined;
@@ -91,6 +93,46 @@ function waitResult(members, reason) {
91
93
  })),
92
94
  };
93
95
  }
96
+ /** One invocation's journal baselines and witnessed progress, shared with mixed observation. */
97
+ export function createContractWaitObserver(scope, ids) {
98
+ let initialized = false;
99
+ let members = ids.map((id) => ({
100
+ id,
101
+ baseline: null,
102
+ changed: false,
103
+ present: null,
104
+ terminal: null,
105
+ }));
106
+ return {
107
+ members: () => waitResult(members, "deadline").contracts,
108
+ reason: (completion) => readiness(members, completion),
109
+ satisfied: () => members.filter(satisfied).map((member) => member.id),
110
+ async observe(signal) {
111
+ const reading = { ...scope, ...(signal === undefined ? {} : { signal }) };
112
+ const states = await readContractValue(() => withGitDecodeChannel(reading, async (channel) => {
113
+ const observed = await observeContractsForAdmissionAt(reading, channel, ids);
114
+ return ids.map((id) => {
115
+ const record = observed.journals.get(id);
116
+ if (record === undefined)
117
+ throw new Error(`missing requested contract observation: ${id}`);
118
+ return record.state;
119
+ });
120
+ }));
121
+ signal?.throwIfAborted();
122
+ members = members.map((member, index) => {
123
+ const state = states[index] ?? null;
124
+ return {
125
+ ...member,
126
+ baseline: initialized ? member.baseline : (state?.head ?? null),
127
+ changed: member.changed || (initialized && state !== null && state.head !== member.baseline),
128
+ present: state !== null,
129
+ terminal: state?.terminal?.kind ?? null,
130
+ };
131
+ });
132
+ initialized = true;
133
+ },
134
+ };
135
+ }
94
136
  export async function waitContractLocal(input) {
95
137
  const { ids, completion, timeoutMs, signal } = input;
96
138
  signal?.throwIfAborted();
@@ -108,57 +150,19 @@ export async function waitContractLocal(input) {
108
150
  if (timeoutMs !== undefined && timeoutMs > 0)
109
151
  scheduleDeadline();
110
152
  const readSignal = signal === undefined ? deadlineController.signal : AbortSignal.any([signal, deadlineController.signal]);
111
- const scope = { ...input.scope, signal: readSignal };
112
- const read = async () => await readContractValue(() => withGitDecodeChannel(scope, async (channel) => {
113
- const observed = await observeContractsForAdmissionAt(scope, channel, ids);
114
- return ids.map((id) => {
115
- const record = observed.journals.get(id);
116
- if (record === undefined)
117
- throw new Error(`missing requested contract observation: ${id}`);
118
- return record.state;
119
- });
120
- }));
121
- let members = ids.map((id) => ({
122
- id,
123
- baseline: null,
124
- changed: false,
125
- present: null,
126
- terminal: null,
127
- }));
128
- const result = (reason) => waitResult(members, reason);
153
+ const observer = createContractWaitObserver(input.scope, ids);
154
+ const result = (reason) => ({
155
+ kind: "contract",
156
+ reason,
157
+ contracts: observer.members(),
158
+ });
129
159
  try {
130
- const initial = await read();
131
- signal?.throwIfAborted();
132
- members = members.map((member, index) => {
133
- const state = initial[index] ?? null;
134
- return {
135
- ...member,
136
- baseline: state?.head ?? null,
137
- present: state !== null,
138
- terminal: state?.terminal?.kind ?? null,
139
- };
140
- });
141
- const initialResult = readiness(members, completion);
142
- if (initialResult !== undefined)
143
- return result(initialResult);
144
- if (performance.now() >= deadline)
145
- return result("deadline");
146
160
  for (;;) {
147
- const states = await read();
161
+ await observer.observe(readSignal);
148
162
  signal?.throwIfAborted();
149
- members = members.map((member, index) => {
150
- const state = states[index] ?? null;
151
- const head = state?.head ?? null;
152
- return {
153
- ...member,
154
- present: state !== null,
155
- terminal: state?.terminal?.kind ?? null,
156
- changed: member.changed || (state !== null && head !== member.baseline),
157
- };
158
- });
159
- const observedResult = readiness(members, completion);
160
- if (observedResult !== undefined)
161
- return result(observedResult);
163
+ const reason = observer.reason(completion);
164
+ if (reason !== undefined)
165
+ return result(reason);
162
166
  const remaining = deadline - performance.now();
163
167
  if (remaining <= 0)
164
168
  return result("deadline");
@@ -28,6 +28,11 @@ export declare const deliverPlacementSchema: z.ZodUnion<readonly [z.ZodReadonly<
28
28
  requirement: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>;
29
29
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
30
30
  state: z.ZodLiteral<"stale">;
31
+ reason: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
32
+ kind: z.ZodLiteral<"snapshot-changed">;
33
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").SnapshotId, string>>;
34
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").SnapshotId, string>>;
35
+ }, z.core.$strict>>>;
31
36
  previousContentId: z.ZodExactOptional<z.ZodString>;
32
37
  currentContentId: z.ZodExactOptional<z.ZodString>;
33
38
  gate: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -143,6 +148,11 @@ export declare const deliveredValueSchema: z.ZodReadonly<z.ZodObject<{
143
148
  requirement: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>;
144
149
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
145
150
  state: z.ZodLiteral<"stale">;
151
+ reason: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
152
+ kind: z.ZodLiteral<"snapshot-changed">;
153
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").SnapshotId, string>>;
154
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").SnapshotId, string>>;
155
+ }, z.core.$strict>>>;
146
156
  previousContentId: z.ZodExactOptional<z.ZodString>;
147
157
  currentContentId: z.ZodExactOptional<z.ZodString>;
148
158
  gate: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -252,6 +262,11 @@ export declare const deliveredValueSchema: z.ZodReadonly<z.ZodObject<{
252
262
  requirement: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>;
253
263
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
254
264
  state: z.ZodLiteral<"stale">;
265
+ reason: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
266
+ kind: z.ZodLiteral<"snapshot-changed">;
267
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").SnapshotId, string>>;
268
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").SnapshotId, string>>;
269
+ }, z.core.$strict>>>;
255
270
  previousContentId: z.ZodExactOptional<z.ZodString>;
256
271
  currentContentId: z.ZodExactOptional<z.ZodString>;
257
272
  gate: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -370,6 +385,11 @@ export declare const deliverySchema: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
370
385
  requirement: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>;
371
386
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
372
387
  state: z.ZodLiteral<"stale">;
388
+ reason: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
389
+ kind: z.ZodLiteral<"snapshot-changed">;
390
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").SnapshotId, string>>;
391
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").SnapshotId, string>>;
392
+ }, z.core.$strict>>>;
373
393
  previousContentId: z.ZodExactOptional<z.ZodString>;
374
394
  currentContentId: z.ZodExactOptional<z.ZodString>;
375
395
  gate: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -479,6 +499,11 @@ export declare const deliverySchema: z.ZodNullable<z.ZodReadonly<z.ZodObject<{
479
499
  requirement: z.ZodPipe<z.ZodString, z.ZodTransform<import("../core/facts/types.js").RequirementId, string>>;
480
500
  }, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
481
501
  state: z.ZodLiteral<"stale">;
502
+ reason: z.ZodExactOptional<z.ZodReadonly<z.ZodObject<{
503
+ kind: z.ZodLiteral<"snapshot-changed">;
504
+ previousSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").SnapshotId, string>>;
505
+ currentSnapshot: z.ZodPipe<z.ZodString, z.ZodTransform<import("../index.js").SnapshotId, string>>;
506
+ }, z.core.$strict>>>;
482
507
  previousContentId: z.ZodExactOptional<z.ZodString>;
483
508
  currentContentId: z.ZodExactOptional<z.ZodString>;
484
509
  gate: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
@@ -3,37 +3,19 @@ import type { DecodedContractDocument } from "../body/types.js";
3
3
  import { type ContractId, type ContractTerms, type Gate } from "../core/facts/types.js";
4
4
  import { type DebtId } from "../debt/identity.js";
5
5
  import type { DocumentDerivation } from "../protocol/operations.js";
6
- export declare const amendInputSchemas: readonly [z.ZodObject<{
7
- markdown: z.ZodNonOptional<z.ZodExactOptional<z.ZodString>>;
8
- after: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
9
- gates: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
10
- }, z.core.$strict>, z.ZodObject<{
6
+ /** Every amendment field is optional; naming none requests an unchanged, fact-free amendment. */
7
+ export declare const amendInputSchema: z.ZodObject<{
8
+ target: z.ZodExactOptional<z.ZodString>;
11
9
  markdown: z.ZodExactOptional<z.ZodString>;
12
- after: z.ZodNonOptional<z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>>;
13
- gates: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
14
- }, z.core.$strict>, z.ZodObject<{
15
- markdown: z.ZodExactOptional<z.ZodString>;
16
- after: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
17
- gates: z.ZodNonOptional<z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>>;
18
- }, z.core.$strict>];
19
- export declare const amendInputSchema: z.ZodUnion<readonly [z.ZodObject<{
20
- markdown: z.ZodNonOptional<z.ZodExactOptional<z.ZodString>>;
21
10
  after: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
22
11
  gates: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
23
- }, z.core.$strict>, z.ZodObject<{
24
- markdown: z.ZodExactOptional<z.ZodString>;
25
- after: z.ZodNonOptional<z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>>;
26
- gates: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
27
- }, z.core.$strict>, z.ZodObject<{
28
- markdown: z.ZodExactOptional<z.ZodString>;
29
- after: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>;
30
- gates: z.ZodNonOptional<z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodString>>>>;
31
- }, z.core.$strict>]>;
12
+ }, z.core.$strict>;
32
13
  export declare function requireMarkdown(value: unknown, label?: string): string;
33
14
  /** Core contract parsing stays foundational; the caller boundary declares the category once. */
34
15
  export declare function callerContractId(value: string): ContractId;
35
16
  export declare function requireInput(value: unknown, label: string, allowed?: readonly string[]): Record<string, unknown>;
36
17
  export declare function debtOption(value: unknown): DebtId | undefined;
18
+ export declare function nonblank(value: unknown, label: string): string;
37
19
  export declare function optionalNonblank(value: unknown, label: string): string | undefined;
38
20
  export declare function optionalBoolean(value: unknown, label: string): boolean | undefined;
39
21
  export declare function optionalSignal(value: unknown): AbortSignal | undefined;
@@ -6,17 +6,16 @@ import { verificationDefinition } from "../body/decode.js";
6
6
  import { contractId } from "../core/facts/types.js";
7
7
  import { canonicalDebtId } from "../debt/identity.js";
8
8
  import { gateRequirements, prepareVerificationDeclaration } from "../verification/declaration.js";
9
- const amendFields = z.strictObject({
9
+ /** Every amendment field is optional; naming none requests an unchanged, fact-free amendment. */
10
+ export const amendInputSchema = z.strictObject({
11
+ target: z
12
+ .string()
13
+ .refine((value) => value.trim() !== "", "target must be nonblank")
14
+ .exactOptional(),
10
15
  markdown: z.string().exactOptional(),
11
16
  after: z.array(z.string()).readonly().exactOptional(),
12
17
  gates: z.array(z.string()).readonly().exactOptional(),
13
18
  });
14
- export const amendInputSchemas = [
15
- amendFields.required({ markdown: true }),
16
- amendFields.required({ after: true }),
17
- amendFields.required({ gates: true }),
18
- ];
19
- export const amendInputSchema = z.union(amendInputSchemas);
20
19
  export function requireMarkdown(value, label = "markdown") {
21
20
  if (typeof value !== "string")
22
21
  throw new KeiyakuError("invalid-input", `${label} must be a string`);
@@ -53,6 +52,12 @@ export function debtOption(value) {
53
52
  throw new KeiyakuError("invalid-input", "debt must be a DebtId");
54
53
  return canonicalDebtId(value);
55
54
  }
55
+ export function nonblank(value, label) {
56
+ if (typeof value !== "string" || value.trim().length === 0) {
57
+ throw new KeiyakuError("invalid-input", `${label} must be a nonblank string`);
58
+ }
59
+ return value;
60
+ }
56
61
  export function optionalNonblank(value, label) {
57
62
  if (value === undefined)
58
63
  return undefined;
@@ -13,6 +13,7 @@ import { retainAdmission, } from "./contract-outcomes.js";
13
13
  import { derivedContractPolicy, derivedFreshness, derivedGates, derivedHooks, gateNames, } from "./contract-settings.js";
14
14
  import { compactDelivery, admitDeliveryOperation } from "../protocol/deliver.js";
15
15
  import { validateContractWaitHandle, waitContractLocal, } from "./contract-wait.js";
16
+ import { targetName } from "../core/facts/types.js";
16
17
  import { prepareAmendDocument } from "../body/amend.js";
17
18
  import { decodeArcDocument } from "../body/arc.js";
18
19
  import { decodeContractDocument } from "../body/decode.js";
@@ -146,39 +147,52 @@ export class Kei {
146
147
  const derived = values.gates === undefined ? undefined : derivedGates(this.composition, gateNames(values.gates));
147
148
  return {
148
149
  markdown: values.markdown,
150
+ target: values.target,
149
151
  gates: derived,
150
152
  prerequisites: values.after === undefined ? undefined : normalizedList(values.after, "after", callerContractId),
151
153
  };
152
154
  });
153
155
  }
154
156
  async amend(input) {
155
- const { markdown, gates, prerequisites } = this.amendInput(input);
157
+ const { markdown, target, gates, prerequisites } = this.amendInput(input);
156
158
  const hooks = derivedHooks(this.composition);
159
+ const requestsChange = markdown !== undefined || target !== undefined || gates !== undefined || prerequisites !== undefined;
157
160
  const amendmentPlan = markdown === undefined ? undefined : validated(() => prepareAmendDocument(markdown));
158
161
  let changedSections;
159
- return await this.local("amend", async (accumulator, channel, scope) => {
162
+ const concluded = await this.local("amend", async (accumulator, channel, scope) => {
160
163
  const admission = await amendOperation({
161
164
  scope,
162
165
  channel,
163
166
  contractId: this.id,
164
167
  progress: accumulator,
165
- deriveAmendment: (source) => {
166
- const current = persistedDocument(source.document.bytes);
167
- const amendment = amendmentPlan === undefined ? undefined : validated(() => amendmentPlan(current));
168
- const amended = amendment === undefined ? current : validated(() => decodeContractDocument(amendment.document));
169
- changedSections =
170
- amendment === undefined
171
- ? undefined
172
- : new Set([...amendment.changedSections].filter((section) => sectionValue(current, section) !== sectionValue(amended, section)));
173
- const terms = contractTerms(amended, gates ?? source.gates, prerequisites ?? source.after);
174
- return { terms, verification: documentDerivation(amended).verification };
175
- },
168
+ ...(target === undefined ? {} : { target }),
169
+ ...(requestsChange
170
+ ? {
171
+ deriveAmendment: (source) => {
172
+ const current = persistedDocument(source.document.bytes);
173
+ const amendment = amendmentPlan === undefined ? undefined : validated(() => amendmentPlan(current));
174
+ const amended = amendment === undefined ? current : validated(() => decodeContractDocument(amendment.document));
175
+ changedSections =
176
+ amendment === undefined
177
+ ? undefined
178
+ : new Set([...amendment.changedSections].filter((section) => sectionValue(current, section) !== sectionValue(amended, section)));
179
+ const terms = contractTerms(amended, gates ?? source.gates, prerequisites ?? source.after);
180
+ return { terms, verification: documentDerivation(amended).verification };
181
+ },
182
+ }
183
+ : {}),
176
184
  });
185
+ // No requested change is the same answer as before: an accepted amendment that changed nothing.
186
+ if (admission.kind === "unchanged")
187
+ return { kind: "unchanged", contractId: this.id };
177
188
  if (admission.kind !== "accepted")
178
189
  return admission.kind === "refused"
179
190
  ? { kind: "refused", contractId: this.id, reason: compactReason(admission.refusal) }
180
191
  : { contractId: this.id, ...compactRetry(admission.reason) };
181
- const changes = changedAmendTerms(admission.value.source, admission.value.terms);
192
+ const changes = {
193
+ ...changedAmendTerms(admission.value.source, admission.value.terms),
194
+ ...(admission.value.target === undefined ? {} : { target: targetName(admission.value.target) }),
195
+ };
182
196
  const sections = changedSections === undefined || changedSections.size === 0 ? {} : { changedSections: [...changedSections] };
183
197
  accumulator.extendConclusions(this.id, { ...sections, ...changes });
184
198
  const region = await observeChangedRegion(scope, this.id, changedSections, decodeContractDocument(admission.value.terms.document.bytes).region);
@@ -195,6 +209,7 @@ export class Kei {
195
209
  });
196
210
  return { kind: "accepted", contractId: this.id, ...value };
197
211
  });
212
+ return concluded.kind === "unchanged" ? { kind: "accepted", contractId: this.id } : concluded;
198
213
  }
199
214
  /** One promise with an optional observation callback; observation never delays custody. */
200
215
  async deliver(input, options) {
@@ -513,6 +528,14 @@ function attestationHistory(entry) {
513
528
  ...(summary === undefined ? {} : { summary }),
514
529
  };
515
530
  }
531
+ function historyTarget(target, full) {
532
+ return target === undefined
533
+ ? {}
534
+ : {
535
+ target: typeof target === "string" ? target : { kind: "contract", contractId: target.contractId },
536
+ ...(full && typeof target === "object" ? { targetIncarnation: target.worktree } : {}),
537
+ };
538
+ }
516
539
  function historyEvent(entry, terms, full) {
517
540
  const common = { id: entry.entry, at: entry.at };
518
541
  switch (entry.kind) {
@@ -523,17 +546,12 @@ function historyEvent(entry, terms, full) {
523
546
  ...common,
524
547
  kind: "bind",
525
548
  start: coordinates.start,
526
- ...(target === undefined
527
- ? {}
528
- : {
529
- target: typeof target === "string" ? target : { kind: "contract", contractId: target.contractId },
530
- }),
549
+ ...historyTarget(target, full),
531
550
  ...(full
532
551
  ? {
533
552
  document: bound.document.bytes,
534
553
  gates: bound.gates,
535
554
  after: bound.after,
536
- ...(typeof target === "object" ? { targetIncarnation: target.worktree } : {}),
537
555
  }
538
556
  : {
539
557
  ...(bound.gates.length === 0 ? {} : { gates: bound.gates }),
@@ -545,6 +563,7 @@ function historyEvent(entry, terms, full) {
545
563
  return {
546
564
  ...common,
547
565
  kind: "amend",
566
+ ...historyTarget(entry.data.target, full),
548
567
  ...changedHistoryTerms(terms, entry.data),
549
568
  ...(full ? { document: entry.data.document.bytes, gates: entry.data.gates, after: entry.data.after } : {}),
550
569
  };
@@ -54,9 +54,9 @@ function classifyReconcile(result) {
54
54
  }
55
55
  }
56
56
  function classifyWait(result) {
57
- if (result.kind === "contract")
58
- return result.reason === "missing" ? "refused" : "accepted";
59
- return result.results.some((item) => item.kind !== "observed") ? "failed" : "accepted";
57
+ if (result.members.some((member) => member.kind === "akuma" && (member.observation.kind === "unobserved" || member.observation.kind === "missing")))
58
+ return "failed";
59
+ return result.reason === "missing" ? "refused" : "accepted";
60
60
  }
61
61
  function classifyHistory(value) {
62
62
  return value.kind === "contract-missing" || value.kind === "akuma-unknown-history" ? "refused" : "accepted";
@@ -5,7 +5,6 @@ import { parseDebtCreationDocument } from "../debt/document.js";
5
5
  import { invocationCoordinates } from "./keiyaku-coordinates.js";
6
6
  const coordinates = (at) => invocationCoordinates({ ...at, use: "none" });
7
7
  const absent = { kind: "absent" };
8
- const missing = () => ({ kind: "refused", reason: "debt-missing" });
9
8
  export async function debtAdd(at, input, document) {
10
9
  const parsed = document ? addDocumentInput(input) : addInput(input);
11
10
  if (document)
@@ -22,7 +21,7 @@ export async function debtUpdate(at, input) {
22
21
  .debt({ id })
23
22
  .update(rest);
24
23
  updateInput(rest).signal?.throwIfAborted();
25
- return missing();
24
+ return { kind: "refused", reason: "debt-missing" };
26
25
  }
27
26
  export async function debtShow(at, id) {
28
27
  const coord = await coordinates(at);
@@ -3,8 +3,8 @@ import { z } from "zod";
3
3
  import { Repo } from "./repo.js";
4
4
  import { type AkumaCaller } from "../akuma/caller.js";
5
5
  import { type WorldRoot } from "../world.js";
6
- /** Environment attribution is explicit invocation input, never SDK admission. */
7
- export declare function akumaCallerFromEnvironment(environment: NodeJS.ProcessEnv): Promise<AkumaCaller | undefined>;
6
+ /** Actor declarations win; an explicit caller bypasses native host decoding. */
7
+ export declare function akumaCallerFromEnvironment(environment: NodeJS.ProcessEnv, caller?: AkumaCaller): Promise<AkumaCaller | undefined>;
8
8
  type WhoamiCoordinates = Readonly<{
9
9
  cwd: string;
10
10
  repo?: Repo;
@@ -54,5 +54,5 @@ export declare const whoamiFactsSchema: z.ZodReadonly<z.ZodObject<{
54
54
  profileUnavailable: z.ZodExactOptional<z.ZodString>;
55
55
  }, z.core.$strict>>;
56
56
  export type WhoamiFacts = z.output<typeof whoamiFactsSchema>;
57
- export declare function whoami(coordinates: WhoamiCoordinates, environment: NodeJS.ProcessEnv): Promise<WhoamiFacts>;
57
+ export declare function whoami(coordinates: WhoamiCoordinates, environment: NodeJS.ProcessEnv, caller?: AkumaCaller): Promise<WhoamiFacts>;
58
58
  export {};
@@ -11,8 +11,8 @@ import { observeNamedAddress } from "./address.js";
11
11
  import { dispatchAssociations } from "./selection.js";
12
12
  import { decodeAkumaCaller } from "../akuma/caller.js";
13
13
  import { World, worldRootSchema } from "../world.js";
14
- /** Environment attribution is explicit invocation input, never SDK admission. */
15
- export async function akumaCallerFromEnvironment(environment) {
14
+ /** Actor declarations win; an explicit caller bypasses native host decoding. */
15
+ export async function akumaCallerFromEnvironment(environment, caller) {
16
16
  const id = environment.KEIYAKU_ACTOR_ID;
17
17
  const world = environment.KEIYAKU_ACTOR_WORLD;
18
18
  if ((id === undefined) !== (world === undefined)) {
@@ -22,6 +22,8 @@ export async function akumaCallerFromEnvironment(environment) {
22
22
  const resolved = await World.resolve({ cwd: world, repositoryRoot: world });
23
23
  return decodeAkumaCaller({ kind: "akuma", akumaId: id, world: resolved.candidate });
24
24
  }
25
+ if (caller !== undefined)
26
+ return caller;
25
27
  const hosts = [
26
28
  { integration: "codex", variable: "CODEX_THREAD_ID", id: environment.CODEX_THREAD_ID },
27
29
  { integration: "pi", variable: "PI_SESSION_ID", id: environment.PI_SESSION_ID },
@@ -73,9 +75,9 @@ export const whoamiFactsSchema = z
73
75
  function reason(error) {
74
76
  return error instanceof Error ? error.message : String(error);
75
77
  }
76
- async function selfFrom(environment) {
78
+ async function selfFrom(environment, explicit) {
77
79
  try {
78
- const caller = await akumaCallerFromEnvironment(environment);
80
+ const caller = await akumaCallerFromEnvironment(environment, explicit);
79
81
  return caller === undefined ? { kind: "none" } : callerFact(caller);
80
82
  }
81
83
  catch (error) {
@@ -163,9 +165,12 @@ async function callerProfile(caller, coordinates, environment) {
163
165
  return { profileUnavailable: reason(error) };
164
166
  }
165
167
  }
166
- export async function whoami(coordinates, environment) {
168
+ export async function whoami(coordinates, environment, caller) {
167
169
  const world = coordinates.world !== null && (await World.established(coordinates.world)) ? coordinates.world : null;
168
- const [self, contextContract] = await Promise.all([selfFrom(environment), contextualContract(coordinates, world)]);
170
+ const [self, contextContract] = await Promise.all([
171
+ selfFrom(environment, caller),
172
+ contextualContract(coordinates, world),
173
+ ]);
169
174
  const initiator = self.kind === "akuma" ? await currentTurn(self) : undefined;
170
175
  return {
171
176
  self,