pi-roundtable-coding 0.40.0 → 0.43.0

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.
@@ -69,6 +69,45 @@ export function codingWorkerPrompt(dir: string): string {
69
69
  "Report changes and reasons, commits, checks and outcomes, held actions, and remaining work.",
70
70
  ].join("\n\n");
71
71
  }
72
+ /** The running session, for a stop to end its turn. */
73
+ let working: { abort(): Promise<void> } | undefined;
74
+ /** Set once the host's shutdown asked the worker to stop; the run's own report or failure then waits for it. */
75
+ let winding: Promise<never> | undefined;
76
+ /**
77
+ * The host's shutdown asked the worker to stop (SIGTERM; a cancel or a timeout kills instead): it
78
+ * ends its turn, keeps the tracked changes it made in a commit on its own branch, and exits, so
79
+ * the report can say where the work is. Untracked files are not committed; the report lists them.
80
+ */
81
+ async function windDown(dir: string): Promise<never> {
82
+ // A turn waiting for an approval never answers its abort, so the commit does not wait long for it.
83
+ await Promise.race([
84
+ working?.abort().catch(() => undefined),
85
+ Bun.sleep(1_000),
86
+ ]);
87
+ Bun.spawnSync(
88
+ [
89
+ "git",
90
+ "commit",
91
+ "--all",
92
+ "--no-verify",
93
+ "--message",
94
+ "wip: the host shut down while this task ran",
95
+ ],
96
+ {
97
+ cwd: dir,
98
+ stdin: "ignore",
99
+ stdout: "ignore",
100
+ stderr: "ignore",
101
+ timeout: 3_000,
102
+ },
103
+ );
104
+ process.send?.(
105
+ { type: "failure", message: "the worker was stopped", stopped: true },
106
+ () => process.exit(1),
107
+ );
108
+ // The parent kills the group if the message does not get out.
109
+ return new Promise<never>(() => {});
110
+ }
72
111
  const answers = new Map<
73
112
  number,
74
113
  (answer: HeldCallAnswer, reason?: string) => void
@@ -84,6 +123,9 @@ async function run({
84
123
  scratchDir,
85
124
  shellEnv,
86
125
  }: StartMessage): Promise<string> {
126
+ process.once("SIGTERM", () => {
127
+ winding ??= windDown(job.dir);
128
+ });
87
129
  const modelRuntime = await ModelRuntime.create({
88
130
  authPath: join(agentDir, "auth.json"),
89
131
  modelsPath: join(agentDir, "models.json"),
@@ -161,6 +203,7 @@ async function run({
161
203
  sessionManager: SessionManager.inMemory(job.dir),
162
204
  settingsManager: SettingsManager.inMemory({}),
163
205
  });
206
+ working = session;
164
207
  // Only what the host's progress posts read crosses: a message's text, never its thinking.
165
208
  if (progress)
166
209
  session.subscribe((event) => {
@@ -205,17 +248,20 @@ if (process.send) {
205
248
  } else if (message.type === "start" && !started) {
206
249
  started = true;
207
250
  void run(message as StartMessage).then(
208
- (report) => {
251
+ async (report) => {
252
+ await winding;
209
253
  process.send?.({ type: "report", report }, () => process.exit(0));
210
254
  },
211
- (error: unknown) =>
255
+ async (error: unknown) => {
256
+ await winding;
212
257
  process.send?.(
213
258
  {
214
259
  type: "failure",
215
260
  message: error instanceof Error ? error.message : String(error),
216
261
  },
217
262
  () => process.exit(1),
218
- ),
263
+ );
264
+ },
219
265
  );
220
266
  }
221
267
  });