@astrosheep/keiyaku 4.5.1 → 4.5.2

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.
@@ -42,11 +42,17 @@ export declare class Akuma {
42
42
  listArchetypes(): Promise<readonly string[]>;
43
43
  call(input: AkumaCallLaunchInput): Promise<AkumaHandle>;
44
44
  beginCall(input: AkumaCallLaunchInput, context: AkumaCallContext): Promise<AkumaBornCall>;
45
- finishCall(born: AkumaBornCall): Promise<AkumaHandle>;
45
+ finishCall(born: AkumaBornCall, completion?: Readonly<{
46
+ participantName?: string;
47
+ contractId?: string;
48
+ }>): Promise<AkumaHandle>;
46
49
  [CALL_WITH_CONTEXT](input: AkumaCallLaunchInput, context: AkumaCallContext): Promise<AkumaHandle>;
47
50
  list(input?: AkumaListInput): Promise<AkumaList>;
48
51
  }
49
52
  export declare function callAkumaWithContext(akuma: Akuma, input: AkumaCallLaunchInput, context: AkumaCallContext): Promise<AkumaHandle>;
50
53
  export declare function beginAkumaCall(akuma: Akuma, input: AkumaCallLaunchInput, context: AkumaCallContext): Promise<AkumaBornCall>;
51
- export declare function finishAkumaCall(akuma: Akuma, born: AkumaBornCall): Promise<AkumaHandle>;
54
+ export declare function finishAkumaCall(akuma: Akuma, born: AkumaBornCall, completion?: Readonly<{
55
+ participantName?: string;
56
+ contractId?: string;
57
+ }>): Promise<AkumaHandle>;
52
58
  export {};
@@ -112,13 +112,18 @@ export class Akuma {
112
112
  },
113
113
  };
114
114
  }
115
- async finishCall(born) {
115
+ async finishCall(born, completion = {}) {
116
116
  if (born.kind === "requested") {
117
117
  return new AkumaHandle(born.id, this.path, { cwd: born.cwd, source: born.execution.source });
118
118
  }
119
119
  const published = await launchAkuma({
120
120
  allocated: born.allocated,
121
- launch: async (allocated) => await spawnAkumaBody({ paths: allocated.paths, seed: born.seed, initialBody: born.initialBody }),
121
+ launch: async (allocated) => await spawnAkumaBody({
122
+ paths: allocated.paths,
123
+ seed: born.seed,
124
+ initialBody: born.initialBody,
125
+ ...(Object.keys(completion).length === 0 ? {} : { completion }),
126
+ }),
122
127
  });
123
128
  return new AkumaHandle(published.id, this.path, {
124
129
  cwd: born.execution.cwd,
@@ -174,6 +179,6 @@ export async function callAkumaWithContext(akuma, input, context) {
174
179
  export async function beginAkumaCall(akuma, input, context) {
175
180
  return await akuma.beginCall(input, context);
176
181
  }
177
- export async function finishAkumaCall(akuma, born) {
178
- return await akuma.finishCall(born);
182
+ export async function finishAkumaCall(akuma, born, completion = {}) {
183
+ return await akuma.finishCall(born, completion);
179
184
  }
@@ -11,6 +11,10 @@ export type BodyLaunch = Readonly<{
11
11
  birthSession?: Omit<SessionFact, "sequence">;
12
12
  initialBody?: string;
13
13
  refuseIfHeld?: boolean;
14
+ completion?: Readonly<{
15
+ participantName?: string;
16
+ contractId?: string;
17
+ }>;
14
18
  }>;
15
19
  export type TellWake = Readonly<{
16
20
  kind: "told";
@@ -78,18 +78,19 @@ async function persistTurn(paths, turnSequence, result, completedAt) {
78
78
  await endTurn(paths, { turnSequence, outcome: { kind: "failed", diagnostic }, completedAt });
79
79
  return { outcome: "failed", diagnostic };
80
80
  }
81
- const OUTCOME_PREVIEW_LIMIT = 1_000;
82
- function outcomePreview(identity, outcome) {
83
- const text = outcome.outcome === "answered" ? outcome.answer : outcome.diagnostic;
84
- if (text.length <= OUTCOME_PREVIEW_LIMIT)
85
- return text;
86
- return `${text.slice(0, OUTCOME_PREVIEW_LIMIT)}\n\nkeiyaku history ${identity} --last`;
81
+ function completionMessage(identity, completion) {
82
+ const participant = completion?.participantName;
83
+ const contract = completion?.contractId;
84
+ const header = [identity, participant === undefined ? undefined : `(@${participant})`, contract]
85
+ .filter((value) => value !== undefined)
86
+ .join(" ");
87
+ return `${header}\n✓ came back`;
87
88
  }
88
89
  function boundedDiagnostic(error) {
89
90
  const text = diagnostic(error);
90
91
  return text.length <= 500 ? text : `${text.slice(0, 500)}...`;
91
92
  }
92
- async function expressInitialOutcome(launch, outcome) {
93
+ async function expressInitialOutcome(launch) {
93
94
  try {
94
95
  const { Square } = await import("@astrosheep/square");
95
96
  const identity = launch.seed?.id ?? (await readHeart(launch.paths)).soul?.id;
@@ -100,7 +101,7 @@ async function expressInitialOutcome(launch, outcome) {
100
101
  const joined = await square.implicitJoin(identity);
101
102
  if (joined.state === "done" || joined.participant === undefined)
102
103
  return;
103
- await joined.participant.express(outcomePreview(identity, outcome));
104
+ await joined.participant.express(completionMessage(identity, launch.completion));
104
105
  }
105
106
  finally {
106
107
  await square.close();
@@ -217,7 +218,7 @@ async function runBodyTurns(input) {
217
218
  }
218
219
  const outcome = await persistTurn(launch.paths, result.turnSequence, result, runtime.now());
219
220
  if (initial !== undefined)
220
- await expressInitialOutcome(launch, outcome);
221
+ await expressInitialOutcome(launch);
221
222
  if (outcome.outcome === "failed") {
222
223
  await breakBody(launch.paths, { sequence: bodySequence, end: "broke-off", at: runtime.now() });
223
224
  return;
@@ -124,7 +124,7 @@ export async function invokeAkuma(command, input) {
124
124
  : undefined;
125
125
  let result;
126
126
  try {
127
- result = await (input.finishCall ?? finishCall)(born);
127
+ result = await (input.finishCall ?? finishCall)(born, listener?.participantName);
128
128
  }
129
129
  catch (error) {
130
130
  if (listener?.committed === true) {
@@ -2,5 +2,6 @@ import type { AllocatedAkuma } from "../akuma/identity.js";
2
2
  import { type WorldRoot } from "../world.js";
3
3
  export declare function recognizeAndListen(worldRoot: WorldRoot, environment: NodeJS.ProcessEnv, allocated: AllocatedAkuma): Promise<{
4
4
  committed: boolean;
5
+ participantName: string;
5
6
  rollback(): Promise<void>;
6
7
  } | void>;
@@ -56,6 +56,7 @@ export async function recognizeAndListen(worldRoot, environment, allocated) {
56
56
  listening = change.activity !== null;
57
57
  return {
58
58
  committed: true,
59
+ participantName: name,
59
60
  rollback,
60
61
  };
61
62
  }
@@ -99,6 +99,6 @@ export type ForkResult = Readonly<{
99
99
  parent: AkuId;
100
100
  }>);
101
101
  export declare function beginCall(input: CallInput): Promise<BornCall>;
102
- export declare function finishCall(born: BornCall): Promise<CallResult>;
102
+ export declare function finishCall(born: BornCall, participantName?: string): Promise<CallResult>;
103
103
  export declare function callKeiyaku(input: CallInput): Promise<CallResult>;
104
104
  export declare function forkKeiyaku(input: ForkInput): Promise<ForkResult>;
@@ -236,9 +236,13 @@ export async function beginCall(input) {
236
236
  alias: aliasStage,
237
237
  };
238
238
  }
239
- export async function finishCall(born) {
239
+ export async function finishCall(born, participantName) {
240
240
  const world = akumaWorld(born.path);
241
- const handle = await finishAkumaCall(world, born.born);
241
+ const contractId = born.dispatch.kind === "dispatched" ? born.dispatch.dispatch.contractId : undefined;
242
+ const handle = await finishAkumaCall(world, born.born, {
243
+ ...(participantName === undefined ? {} : { participantName }),
244
+ ...(contractId === undefined ? {} : { contractId }),
245
+ });
242
246
  const readonly = (await handle.status()).readonly;
243
247
  const observation = await observeCall(handle, born.mode, born.timeoutMs);
244
248
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrosheep/keiyaku",
3
- "version": "4.5.1",
3
+ "version": "4.5.2",
4
4
  "files": [
5
5
  "build"
6
6
  ],
@@ -64,7 +64,7 @@
64
64
  "dependencies": {
65
65
  "@agentclientprotocol/sdk": "^1.3.0",
66
66
  "@anthropic-ai/claude-agent-sdk": "^0.3.226",
67
- "@astrosheep/square": "0.3.23",
67
+ "@astrosheep/square": "0.3.24",
68
68
  "@earendil-works/pi-coding-agent": "0.80.10",
69
69
  "@opencode-ai/sdk": "1.18.3",
70
70
  "cross-spawn": "^7.0.6",