pi-better-server 0.7.0 → 0.7.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.
Files changed (105) hide show
  1. package/package.json +1 -1
  2. package/src/codex/return.ts +3 -2
  3. package/src/detach/extension.ts +20 -3
  4. package/src/event-log.ts +40 -12
  5. package/src/hosted-session.ts +11 -5
  6. package/src/remote-client/packages.ts +1 -4
  7. package/src/runtime/background-tools.ts +2 -1
  8. package/src/runtime/domain/background/registry.mjs +3 -0
  9. package/src/runtime/domain/background/shared-operation-coordinator/src/task-lifetime.mjs +6 -0
  10. package/src/runtime/domain/background/terminal-publication.mjs +5 -2
  11. package/src/runtime/domain/background-service/managed-authority.domain.mjs +13 -0
  12. package/src/runtime/domain/background-service/managed-authority.ts +16 -0
  13. package/src/runtime/domain/background-service/managed-client.domain.mjs +2 -2
  14. package/src/runtime/domain/background-service/managed-client.ts +2 -2
  15. package/src/runtime/domain/background-service/observed-waits.domain.mjs +8 -4
  16. package/src/runtime/domain/background-service/observed-waits.ts +8 -4
  17. package/src/runtime/domain/background-service/registry.domain.mjs +3 -0
  18. package/src/runtime/domain/background-service/registry.ts +2 -0
  19. package/src/runtime/domain/background-service/runtime.domain.mjs +3 -2
  20. package/src/runtime/domain/background-service/runtime.ts +3 -2
  21. package/src/runtime/domain/background-service/shared-harness-settings.domain.mjs +2 -3
  22. package/src/runtime/domain/background-service/shared-harness-settings.ts +2 -5
  23. package/src/runtime/domain/background-service/shared-operation-coordinator/src/expiry.domain.mjs +44 -0
  24. package/src/runtime/domain/background-service/shared-operation-coordinator/src/expiry.ts +44 -0
  25. package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +8 -1
  26. package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +8 -1
  27. package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +3 -0
  28. package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +5 -0
  29. package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-lifetime.domain.mjs +7 -0
  30. package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-lifetime.ts +7 -0
  31. package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.domain.mjs +22 -13
  32. package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.ts +40 -32
  33. package/src/runtime/domain/background-service/shared-sandbox-diagnostics.domain.mjs +12 -19
  34. package/src/runtime/domain/background-service/shared-sandbox-diagnostics.ts +12 -16
  35. package/src/runtime/domain/background-service/shared-ssh-core/index.domain.mjs +1 -1
  36. package/src/runtime/domain/background-service/shared-ssh-core/index.ts +1 -1
  37. package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +1 -0
  38. package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +12 -7
  39. package/src/runtime/domain/background-service/supervisor/generated/task-lifetime.mjs +9 -0
  40. package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +12 -7
  41. package/src/runtime/domain/background-service/supervisor/runner.ts +12 -7
  42. package/src/runtime/domain/background-service/supervisor/types.ts +1 -1
  43. package/src/runtime/domain/background-service/tools.domain.mjs +3 -2
  44. package/src/runtime/domain/background-service/tools.ts +3 -2
  45. package/src/runtime/domain/catalog/catalog-preferences.mjs +1 -3
  46. package/src/runtime/domain/coordinator/src/expiry.mjs +43 -0
  47. package/src/runtime/domain/coordinator/src/schema.mjs +8 -1
  48. package/src/runtime/domain/coordinator/src/store.mjs +3 -0
  49. package/src/runtime/domain/coordinator/src/task-lifetime.mjs +6 -0
  50. package/src/runtime/domain/coordinator/src/waits.mjs +22 -13
  51. package/src/runtime/domain/sandbox-policy/package.json +1 -1
  52. package/src/runtime/domain/sandbox-policy/shared-harness-settings.domain.mjs +2 -3
  53. package/src/runtime/domain/sandbox-policy/shared-harness-settings.ts +2 -5
  54. package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.domain.mjs +12 -19
  55. package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.ts +12 -16
  56. package/src/runtime/domain/shared-harness-settings.mjs +2 -3
  57. package/src/runtime/domain/subagents/README.md +2 -2
  58. package/src/runtime/domain/subagents/catalog-preferences.domain.mjs +1 -3
  59. package/src/runtime/domain/subagents/catalog-preferences.ts +1 -5
  60. package/src/runtime/domain/subagents/cleanup.domain.mjs +5 -2
  61. package/src/runtime/domain/subagents/cleanup.ts +4 -1
  62. package/src/runtime/domain/subagents/config.ts +1 -1
  63. package/src/runtime/domain/subagents/extensions.mjs +1 -0
  64. package/src/runtime/domain/subagents/finalization.domain.mjs +34 -30
  65. package/src/runtime/domain/subagents/finalization.ts +30 -28
  66. package/src/runtime/domain/subagents/git-workspace.domain.mjs +51 -6
  67. package/src/runtime/domain/subagents/git-workspace.ts +48 -6
  68. package/src/runtime/domain/subagents/index.domain.mjs +99 -54
  69. package/src/runtime/domain/subagents/index.ts +100 -51
  70. package/src/runtime/domain/subagents/isolated-workspace.domain.mjs +7 -14
  71. package/src/runtime/domain/subagents/isolated-workspace.ts +6 -12
  72. package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +28 -2
  73. package/src/runtime/domain/subagents/managed-launch-host.ts +26 -2
  74. package/src/runtime/domain/subagents/managed-launch-port.ts +2 -0
  75. package/src/runtime/domain/subagents/package.json +1 -1
  76. package/src/runtime/domain/subagents/registry-cleanup-worker.mjs +24 -0
  77. package/src/runtime/domain/subagents/registry.domain.mjs +40 -14
  78. package/src/runtime/domain/subagents/registry.ts +26 -12
  79. package/src/runtime/domain/subagents/settings-page.domain.mjs +10 -10
  80. package/src/runtime/domain/subagents/settings-page.ts +10 -10
  81. package/src/runtime/domain/subagents/shared-harness-settings.domain.mjs +2 -3
  82. package/src/runtime/domain/subagents/shared-harness-settings.ts +2 -5
  83. package/src/runtime/domain/subagents/shared-operation-coordinator/src/expiry.domain.mjs +44 -0
  84. package/src/runtime/domain/subagents/shared-operation-coordinator/src/expiry.ts +44 -0
  85. package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +8 -1
  86. package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +8 -1
  87. package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +3 -0
  88. package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +5 -0
  89. package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-lifetime.domain.mjs +7 -0
  90. package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-lifetime.ts +7 -0
  91. package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.domain.mjs +22 -13
  92. package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.ts +40 -32
  93. package/src/runtime/domain/subagents/shared-sandbox-diagnostics.domain.mjs +12 -19
  94. package/src/runtime/domain/subagents/shared-sandbox-diagnostics.ts +12 -16
  95. package/src/runtime/domain/subagents/stop.domain.mjs +7 -5
  96. package/src/runtime/domain/subagents/stop.ts +7 -5
  97. package/src/runtime/domain/subagents/timing.domain.mjs +7 -3
  98. package/src/runtime/domain/subagents/timing.ts +11 -4
  99. package/src/runtime/domain/subagents/workspace-files.domain.mjs +6 -6
  100. package/src/runtime/domain/subagents/workspace-files.ts +6 -6
  101. package/src/runtime/domain/subagents/workspace-prepare-worker.mjs +12 -0
  102. package/src/runtime/task-expiry.ts +52 -0
  103. package/src/server.ts +4 -0
  104. package/src/shared-ssh-core/index.ts +1 -1
  105. package/src/version.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-server",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Daemon that hosts Pi agent sessions behind a local Unix socket with session-addressed Pi RPC.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -11,6 +11,7 @@ import { DaemonClient } from "../client.ts";
11
11
  import { moveSession, type MoveResult } from "../move/orchestrate.ts";
12
12
  import { defaultServerDir, socketPathFor } from "../paths.ts";
13
13
  import { resolveSession } from "../remote/sessions.ts";
14
+ import { shellQuote } from "../startup/runtime.ts";
14
15
  import { preflightCodexProvider } from "./preflight.ts";
15
16
  import { readRolloutMeta } from "./rollout.ts";
16
17
  import { startCodexDaemon, type CodexDaemon } from "./daemon.ts";
@@ -74,8 +75,8 @@ async function localDaemon(serverDir: string, codex: CodexRuntimeOptions | undef
74
75
  * plain `codex resume` works.
75
76
  */
76
77
  export function resumeHint(cwd: string, sessionId: string, managed: boolean, serverDir: string): string {
77
- if (!managed) return `cd ${cwd} && codex resume ${sessionId}`;
78
- const env = serverDir === defaultServerDir() ? "" : `PI_SERVER_DIR=${serverDir} `;
78
+ if (!managed) return `cd ${shellQuote(cwd)} && codex resume ${sessionId}`;
79
+ const env = serverDir === defaultServerDir() ? "" : `PI_SERVER_DIR=${shellQuote(serverDir)} `;
79
80
  return `${env}pi-remote attach ${sessionId} --agent codex (or: ${env}pi-remote steer ${sessionId} --agent codex "<message>")`;
80
81
  }
81
82
 
@@ -60,6 +60,7 @@ export function assertLocalSessionTransferSafe(sessionManager: unknown): void {
60
60
  interface ManagerOwnershipGuard {
61
61
  departed: Set<string>;
62
62
  wrapped: boolean;
63
+ flushDropped?: () => boolean;
63
64
  }
64
65
 
65
66
  // Native replacement and separately loaded extension modules must share both gates and latches.
@@ -107,9 +108,15 @@ function createLocalOwnershipGuard() {
107
108
  if (state.wrapped) return;
108
109
  state.wrapped = true;
109
110
  const rewrite = typeof manager._rewriteFile === "function" ? manager._rewriteFile : undefined;
110
- // Dropped entries remain in memory. After a failed move unfences the source, rewrite them
111
- // before appending again so every on-disk parentId still points to an on-disk entry.
111
+ // Entries withheld by the fence remain in memory. Rewriting restores parent links
112
+ // on rollback, or on the next append if the fence was lifted outside this handler.
112
113
  let dropped = false;
114
+ state.flushDropped = () => {
115
+ if (!dropped || !rewrite || manager.flushed === false) return false;
116
+ rewrite.call(manager);
117
+ dropped = false;
118
+ return true;
119
+ };
113
120
  for (const method of GATED_METHODS) {
114
121
  const original = manager[method];
115
122
  if (typeof original !== "function") continue;
@@ -119,8 +126,8 @@ function createLocalOwnershipGuard() {
119
126
  return undefined;
120
127
  }
121
128
  if (dropped) {
129
+ if (state.flushDropped?.()) return undefined;
122
130
  dropped = false;
123
- if (rewrite && manager.flushed !== false) return rewrite.call(this);
124
131
  }
125
132
  return (original as (...a: unknown[]) => unknown).apply(this, args);
126
133
  };
@@ -180,6 +187,7 @@ export function markLocalSessionDeparted(pi: ExtensionAPI, sessionId: string, ma
180
187
 
181
188
  export interface DetachDeps {
182
189
  resolveTarget: typeof resolveTarget;
190
+ waitMs?: number;
183
191
  }
184
192
 
185
193
  export function registerDetach(pi: ExtensionAPI, deps: DetachDeps = { resolveTarget }): void {
@@ -223,6 +231,7 @@ export function registerDetach(pi: ExtensionAPI, deps: DetachDeps = { resolveTar
223
231
  return DaemonClient.connect(target.socketPath);
224
232
  },
225
233
  isBusy: () => !ctx.isIdle(),
234
+ ...(deps.waitMs === undefined ? {} : { waitMs: deps.waitMs }),
226
235
  ...(parsed.toCwd ? { toCwd: parsed.toCwd } : {}),
227
236
  onProgress: (message) => ctx.ui.notify(message, "info"),
228
237
  });
@@ -231,6 +240,14 @@ export function registerDetach(pi: ExtensionAPI, deps: DetachDeps = { resolveTar
231
240
  } catch (error) {
232
241
  const message = error instanceof Error ? error.message : String(error);
233
242
  const untouched = error instanceof PreflightError || (error instanceof MoveError && error.sourceUnfenced);
243
+ if (error instanceof MoveError && error.sourceUnfenced && manager.getSessionId() === sessionId) {
244
+ try {
245
+ if (!localOwnershipGuard(pi).blockedFor(manager)) managerOwnershipGuard(manager).flushDropped?.();
246
+ } catch (flushError) {
247
+ ctx.ui.notify(`${message}\nCould not persist entries buffered during the move: ${String(flushError)}`, "error");
248
+ return;
249
+ }
250
+ }
234
251
  ctx.ui.notify(untouched ? `${message}\nThis session is unchanged.` : message, "error");
235
252
  } finally {
236
253
  await target?.close();
package/src/event-log.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
2
- import { dirname } from "node:path";
1
+ import { appendFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, truncateSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
3
 
4
4
  export interface LoggedEvent {
5
5
  seq: number;
@@ -56,13 +56,14 @@ export class EventLog {
56
56
  private pending: string[] = [];
57
57
  private pendingBytes = 0;
58
58
  private timer: ReturnType<typeof setTimeout> | undefined;
59
+ private committed: ((entry: LoggedEvent) => void) | undefined;
59
60
 
60
61
  constructor(path: string, options: EventLogOptions = {}) {
61
62
  this.path = path;
62
63
  this.ringSize = options.ringSize ?? DEFAULT_RING;
63
64
  this.maxEvents = options.maxEvents ?? DEFAULT_MAX_EVENTS;
64
65
  mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
65
- const existing = this.readFile();
66
+ const existing = this.readFile(true);
66
67
  this.fileEvents = existing.length;
67
68
  this.lastSeq = existing.at(-1)?.seq ?? 0;
68
69
  this.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
@@ -77,17 +78,21 @@ export class EventLog {
77
78
  return this.lastSeq;
78
79
  }
79
80
 
80
- append(event: unknown): LoggedEvent {
81
- const logged: LoggedEvent = { seq: ++this.lastSeq, event };
81
+ onCommitted(listener: (entry: LoggedEvent) => void): void {
82
+ this.committed = listener;
83
+ }
84
+
85
+ append(event: unknown, flushImmediately = false): LoggedEvent {
86
+ const logged: LoggedEvent = { seq: this.lastSeq + 1, event };
82
87
  const line = `${JSON.stringify(logged)}\n`;
88
+ this.lastSeq = logged.seq;
83
89
  const size = Buffer.byteLength(line);
84
- this.pushRing(logged, size);
85
90
  this.pending.push(line);
86
91
  this.pendingBytes += size;
87
92
  this.fileEvents++;
88
93
  this.fileBytes += size;
89
94
  // Small batches are written after a short delay; a big one (or a quiet gap in the stream) does not wait.
90
- if (this.pendingBytes >= 256 * 1024) this.flush();
95
+ if (flushImmediately || this.pendingBytes >= 256 * 1024) this.flush();
91
96
  else if (!this.timer) {
92
97
  this.timer = setTimeout(() => this.flush(), this.flushMs);
93
98
  this.timer.unref();
@@ -103,10 +108,18 @@ export class EventLog {
103
108
  this.timer = undefined;
104
109
  }
105
110
  if (this.pending.length === 0) return;
106
- const text = this.pending.join("");
111
+ const pending = this.pending;
112
+ appendFileSync(this.path, pending.join(""), { mode: 0o600 });
107
113
  this.pending = [];
108
114
  this.pendingBytes = 0;
109
- appendFileSync(this.path, text, { mode: 0o600 });
115
+ // Deliver the recorded values. Pi may mutate a streaming message between
116
+ // append and flush, and a replay must agree with the original delivery.
117
+ const committed = pending.map(line => {
118
+ const entry = JSON.parse(line) as LoggedEvent;
119
+ this.pushRing(entry, Buffer.byteLength(line));
120
+ return entry;
121
+ });
122
+ for (const entry of committed) this.committed?.(entry);
110
123
  }
111
124
 
112
125
  private pushRing(entry: LoggedEvent, size: number): void {
@@ -122,6 +135,7 @@ export class EventLog {
122
135
 
123
136
  /** Every retained event with `seq > sinceSeq`, in order. */
124
137
  since(sinceSeq: number): Replay {
138
+ this.flush();
125
139
  const ringFirst = this.ring[0]?.seq;
126
140
  const source = ringFirst !== undefined && sinceSeq + 1 >= ringFirst ? this.ring : this.readFile();
127
141
  const firstSeq = source[0]?.seq ?? 0;
@@ -141,16 +155,30 @@ export class EventLog {
141
155
  // Drop the oldest until the file is at half its byte bound (the newest event always stays).
142
156
  while (start < lines.length - 1 && bytes > this.maxBytes / 2) bytes -= Buffer.byteLength(lines[start++]!);
143
157
  keep = keep.slice(start);
144
- writeFileSync(this.path, lines.slice(start).join(""), { mode: 0o600 });
158
+ const staging = mkdtempSync(join(dirname(this.path), ".compact-events-"));
159
+ try {
160
+ const next = join(staging, "events.jsonl");
161
+ writeFileSync(next, lines.slice(start).join(""), { mode: 0o600 });
162
+ renameSync(next, this.path);
163
+ } finally {
164
+ rmSync(staging, { recursive: true, force: true });
165
+ }
145
166
  this.fileEvents = keep.length;
146
167
  this.fileBytes = bytes;
147
168
  }
148
169
 
149
- private readFile(): LoggedEvent[] {
170
+ private readFile(repairTail = false): LoggedEvent[] {
150
171
  this.flush();
151
172
  if (!existsSync(this.path)) return [];
152
173
  const entries: LoggedEvent[] = [];
153
- for (const line of readFileSync(this.path, "utf8").split("\n")) {
174
+ let text = readFileSync(this.path, "utf8");
175
+ if (repairTail && text && !text.endsWith("\n")) {
176
+ // A crash can leave a partial final line. Remove it before any new
177
+ // append, so a later committed event cannot land on the broken line.
178
+ text = text.slice(0, text.lastIndexOf("\n") + 1);
179
+ truncateSync(this.path, Buffer.byteLength(text));
180
+ }
181
+ for (const line of text.split("\n")) {
154
182
  if (!line) continue;
155
183
  try {
156
184
  entries.push(JSON.parse(line) as LoggedEvent);
@@ -104,6 +104,9 @@ export class HostedSession {
104
104
  constructor(session: AgentSession, log: EventLog, onActivity: (kind?: "work" | "metadata") => void, activity?: SessionActivity) {
105
105
  this.session = session;
106
106
  this.log = log;
107
+ this.log.onCommitted(entry => {
108
+ for (const listener of this.listeners) listener(entry);
109
+ });
107
110
  this.onActivity = onActivity;
108
111
  this.activity = activity;
109
112
  this.ui = new UiBridge((event) => {
@@ -125,7 +128,9 @@ export class HostedSession {
125
128
  if (event.type === "message_end") this.activeMessage = undefined;
126
129
  if (event.type === "tool_execution_start" || event.type === "tool_execution_update") this.activeTools.set(event.toolCallId, event);
127
130
  if (event.type === "tool_execution_end") this.activeTools.delete(event.toolCallId);
128
- this.publish(event);
131
+ // Clients use lifecycle events to decide when a turn is idle. Flush those
132
+ // boundaries together with any preceding token or tool updates.
133
+ this.publish(event, event.type !== "message_update" && event.type !== "tool_execution_update");
129
134
  if (event.type === "agent_start") this.runIdle = session.waitForIdle().catch(() => undefined);
130
135
  if (event.type === "agent_end") for (const release of [...this.releaseOnAgentEnd]) release();
131
136
  this.onActivity("work");
@@ -228,6 +233,7 @@ export class HostedSession {
228
233
  fence(): void { this.disposed = true; fenceHostedSession(this.session); this.activity?.revokeRuntime(); }
229
234
 
230
235
  get lastSeq(): number {
236
+ this.log.flush();
231
237
  return this.log.last;
232
238
  }
233
239
 
@@ -243,11 +249,10 @@ export class HostedSession {
243
249
  /** Activation notices share the normal sequence and replay log, including after commitStop. */
244
250
  publishRuntimeEvent(event: unknown): void { this.publish(event); }
245
251
 
246
- private publish(event: unknown): void {
252
+ private publish(event: unknown, flushImmediately = true): void {
247
253
  this.progressAt = Date.now();
248
254
  if (this.runtimeReleased) return;
249
- const logged = this.log.append(event);
250
- for (const listener of this.listeners) listener(logged);
255
+ this.log.append(event, flushImmediately);
251
256
  }
252
257
 
253
258
  /**
@@ -255,6 +260,7 @@ export class HostedSession {
255
260
  * The replay and the live registration happen in one synchronous step, so no event is lost or repeated.
256
261
  */
257
262
  subscribe(sinceSeq: number | undefined, listener: Listener): { replay: Replay; unsubscribe: () => void } {
263
+ this.log.flush();
258
264
  const replay = sinceSeq === undefined ? { events: [], firstSeq: 0, truncated: false } : this.log.since(sinceSeq);
259
265
  return { replay, unsubscribe: this.addListener(listener) };
260
266
  }
@@ -305,9 +311,9 @@ export class HostedSession {
305
311
  this.ui.cancelAll();
306
312
  await aborted;
307
313
  this.unsubscribe();
314
+ this.log.flush();
308
315
  this.listeners.clear();
309
316
  this.runtimeReleased = true;
310
- this.log.flush();
311
317
  this.session.dispose();
312
318
  }
313
319
 
@@ -6,6 +6,7 @@ import { delimiter, dirname, isAbsolute, join, resolve } from "node:path";
6
6
  import { promisify } from "node:util";
7
7
  import { fileURLToPath } from "node:url";
8
8
  import { getAgentDir, ProjectTrustStore, SettingsManager } from "@earendil-works/pi-coding-agent";
9
+ import lockfile from "proper-lockfile";
9
10
 
10
11
  export interface PackageSpec {
11
12
  source: string;
@@ -34,10 +35,6 @@ const semver = piRequire("semver") as {
34
35
  valid(value: string): string | null;
35
36
  validRange(value: string): string | null;
36
37
  };
37
- const lockfile = piRequire("proper-lockfile") as {
38
- lockSync(path: string, options: { realpath: boolean }): () => void;
39
- lock(path: string, options: { realpath: boolean; retries: { retries: number; minTimeout: number; maxTimeout: number } }): Promise<() => Promise<void>>;
40
- };
41
38
  const run = promisify(execFile);
42
39
  const resources = ["extensions", "skills", "prompts", "themes"] as const;
43
40
  const commitPattern = /^[a-f0-9]{40}$/;
@@ -363,7 +363,8 @@ export async function createBackgroundTools(root: string, instance: string, drai
363
363
  if (record.tool === '__background_dismiss')
364
364
  return service.dismissDurableTask(origin, record.params.id);
365
365
  const tool = session.extensionRunner.getToolDefinition(record.tool);
366
- if (!tool || record.parametersDigest !== authority.backgroundDigest(tool.parameters))
366
+ if (!tool || (record.parametersDigest !== authority.backgroundParametersDigest(tool.parameters)
367
+ && record.parametersDigest !== authority.backgroundDigest(tool.parameters)))
367
368
  throw new Error('capability-mismatch: Background tool schema');
368
369
  if (!Check(tool.parameters, record.params))
369
370
  throw new Error('Invalid Background tool parameters');
@@ -1,3 +1,4 @@
1
+ import { taskDeadline } from "./shared-operation-coordinator/src/task-lifetime.mjs";
1
2
  import { createHash } from "node:crypto";
2
3
  import { mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
3
4
  import { tmpdir } from "node:os";
@@ -112,6 +113,8 @@ export function inspectMeta(id) {
112
113
  metaCache.delete(id);
113
114
  return { id, found: true, readable: false, error: `invalid metadata: ${invalid}` };
114
115
  }
116
+ if (meta.status === "running")
117
+ meta.deadlineAt = taskDeadline(meta.startedAt, meta.deadlineAt);
115
118
  metaCache.set(id, meta);
116
119
  return { id, meta, found: true, readable: true };
117
120
  }
@@ -0,0 +1,6 @@
1
+ // Generated from packages/operation-coordinator/src/task-lifetime.ts. Do not edit directly.
2
+ /** Absolute wall-clock limit, including time spent waiting for a runner. */
3
+ export const MAX_TASK_LIFETIME_MS = 24 * 60 * 60 * 1000;
4
+ export function taskDeadline(startedAt, requestedDeadline) {
5
+ return Math.min(startedAt + MAX_TASK_LIFETIME_MS, requestedDeadline ?? Infinity);
6
+ }
@@ -1,5 +1,6 @@
1
1
  // Generated canonical terminal publication. Do not edit directly.
2
2
  import { existsSync, statSync } from "node:fs";
3
+ import { taskDeadline } from "./shared-operation-coordinator/src/task-lifetime.mjs";
3
4
  function terminalOutcome(status) {
4
5
  switch (status) {
5
6
  case "succeeded": return "succeeded";
@@ -46,13 +47,15 @@ function evidenceFor(inspection) {
46
47
  /** Shared terminal publication contract for the host and fixed server cancel adapter. */
47
48
  export function supervisorTerminalPublication(operation, inspection, refs = evidenceFor(inspection)) {
48
49
  const status = inspection.status;
49
- const outcome = terminalOutcome(status);
50
+ const endedAt = inspection.result?.endedAt ?? inspection.lost?.recordedAt;
51
+ const expired = endedAt !== undefined && endedAt >= taskDeadline(Math.min(operation.createdAt, inspection.launch.createdAt));
52
+ const outcome = expired ? "failed" : terminalOutcome(status);
50
53
  return {
51
54
  operationId: operation.operationId,
52
55
  eventId: `${operation.taskId}:${inspection.result?.endedAt ?? inspection.lost?.recordedAt ?? inspection.observedAt}:${status}`,
53
56
  outcome, owner: operation.owner,
54
57
  evidence: refs.map(ref => ({ kind: ref.kind, ref: ref.ref, ...(ref.summary ? { summary: ref.summary } : {}), detailLost: ref.detailLost })),
55
58
  ...(outcome === "lost" ? { detailLost: true } : {}),
56
- reason: inspection.result ? `supervisor ${status} exit=${inspection.result.exitCode ?? "null"}` : "supervisor lost: no terminal evidence",
59
+ reason: expired ? "24-hour task lifetime exceeded" : inspection.result ? `supervisor ${status} exit=${inspection.result.exitCode ?? "null"}` : "supervisor lost: no terminal evidence",
57
60
  };
58
61
  }
@@ -5,6 +5,19 @@ import { join } from 'node:path';
5
5
  import { readAdmissionStartToken, readProcessStartTokenFresh } from "./process-identity.domain.mjs";
6
6
  const ordered = (value) => value === null || typeof value !== 'object' ? value : Array.isArray(value) ? value.map(ordered) : Object.fromEntries(Object.keys(value).sort().map(key => [key, ordered(value[key])]));
7
7
  export const backgroundDigest = (value) => createHash('sha256').update(JSON.stringify(ordered(value))).digest('hex');
8
+ export const TASK_TIMEOUT_HELP = "Optional whole-task timeout in seconds. Command watchers default to 900 seconds when omitted; pass 0 to use the 24-hour maximum. Spawned processes also have a 24-hour maximum. When the Background tasks sandbox profile sets a command time limit, that cap applies to each actual command (and each watch check) independently: a smaller timeout_seconds still wins, and 0 does not disable the policy cap.";
9
+ // Admission v1/v2 hashes the full schema. Preserve the 0.20.1 wire text
10
+ // for this annotation; all property names, validation rules and defaults remain in the digest.
11
+ const PUBLISHED_TIMEOUT_HELP = "Optional whole-task timeout in seconds. Command watchers default to 900 seconds when omitted; pass 0 to disable. Spawned processes have no default timeout. When the Background tasks sandbox profile sets a command time limit, that cap applies to each actual command (and each watch check) independently: a smaller timeout_seconds still wins, and 0 does not disable the policy cap.";
12
+ export function backgroundParametersDigest(parameters) {
13
+ const wire = JSON.stringify(ordered(parameters), (key, value) => {
14
+ if (key === 'timeout_seconds' && value?.description === TASK_TIMEOUT_HELP) {
15
+ return { ...value, description: PUBLISHED_TIMEOUT_HELP };
16
+ }
17
+ return value;
18
+ });
19
+ return createHash('sha256').update(wire).digest('hex');
20
+ }
8
21
  export function readBackgroundAuthority(root, instance, authority, requireLive = true) {
9
22
  if (!authority || !/^[a-f0-9-]{36}$/.test(authority.id) || !/^[a-f0-9]{64}$/.test(authority.secret))
10
23
  throw new Error('background-authority-refused');
@@ -4,6 +4,22 @@ import { join } from 'node:path';
4
4
  import { readAdmissionStartToken, readProcessStartTokenFresh } from './process-identity.js';
5
5
  const ordered = (value: any): any => value === null || typeof value !== 'object' ? value : Array.isArray(value) ? value.map(ordered) : Object.fromEntries(Object.keys(value).sort().map(key => [key, ordered(value[key])]));
6
6
  export const backgroundDigest = (value: unknown) => createHash('sha256').update(JSON.stringify(ordered(value))).digest('hex');
7
+
8
+ export const TASK_TIMEOUT_HELP = "Optional whole-task timeout in seconds. Command watchers default to 900 seconds when omitted; pass 0 to use the 24-hour maximum. Spawned processes also have a 24-hour maximum. When the Background tasks sandbox profile sets a command time limit, that cap applies to each actual command (and each watch check) independently: a smaller timeout_seconds still wins, and 0 does not disable the policy cap.";
9
+ // Admission v1/v2 hashes the full schema. Preserve the 0.20.1 wire text
10
+ // for this annotation; all property names, validation rules and defaults remain in the digest.
11
+ const PUBLISHED_TIMEOUT_HELP = "Optional whole-task timeout in seconds. Command watchers default to 900 seconds when omitted; pass 0 to disable. Spawned processes have no default timeout. When the Background tasks sandbox profile sets a command time limit, that cap applies to each actual command (and each watch check) independently: a smaller timeout_seconds still wins, and 0 does not disable the policy cap.";
12
+
13
+ export function backgroundParametersDigest(parameters: unknown): string {
14
+ const wire = JSON.stringify(ordered(parameters), (key, value) => {
15
+ if (key === 'timeout_seconds' && value?.description === TASK_TIMEOUT_HELP) {
16
+ return { ...value, description: PUBLISHED_TIMEOUT_HELP };
17
+ }
18
+ return value;
19
+ });
20
+ return createHash('sha256').update(wire).digest('hex');
21
+ }
22
+
7
23
  export function readBackgroundAuthority(root: string, instance: string, authority: any, requireLive = true): any {
8
24
  if (!authority || !/^[a-f0-9-]{36}$/.test(authority.id) || !/^[a-f0-9]{64}$/.test(authority.secret))
9
25
  throw new Error('background-authority-refused');
@@ -3,7 +3,7 @@ import { createHash, randomBytes, randomUUID } from 'node:crypto';
3
3
  import { lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
4
4
  import { join } from 'node:path';
5
5
  import { getAgentDir } from '@earendil-works/pi-coding-agent';
6
- import { backgroundDigest } from "./managed-authority.domain.mjs";
6
+ import { backgroundDigest, backgroundParametersDigest } from "./managed-authority.domain.mjs";
7
7
  import { readAdmissionStartToken, readProcessStartTokenFresh } from "./process-identity.domain.mjs";
8
8
  import { currentForegroundSandboxPolicy, FOREGROUND_SANDBOX_POLICY_CHANNEL } from "./sandbox.domain.mjs";
9
9
  import { backgroundListNeedsHistory, backgroundObservation } from "./work-observation.domain.mjs";
@@ -50,7 +50,7 @@ export async function requestBackgroundTool(pi, ctx, key, tool, params, paramete
50
50
  const start = version === 2 ? readAdmissionStartToken(process.pid) : readProcessStartTokenFresh(process.pid);
51
51
  const record = { version, id, secretHash: createHash('sha256').update(secret).digest('hex'), instanceId: hello.instanceId,
52
52
  owner: { kind: 'parent-session', sessionId, workspace: realpathSync(ctx.cwd) }, branchIds, projectTrusted: ctx.isProjectTrusted(),
53
- pid: process.pid, start, key, tool, params, parametersDigest: parameters === undefined ? undefined : backgroundDigest(parameters), policy };
53
+ pid: process.pid, start, key, tool, params, parametersDigest: parameters === undefined ? undefined : backgroundParametersDigest(parameters), policy };
54
54
  const staged = `${path}.tmp`;
55
55
  writeFileSync(staged, JSON.stringify(record), { flag: 'wx', mode: 0o600 });
56
56
  renameSync(staged, path);
@@ -2,7 +2,7 @@ import { createHash, randomBytes, randomUUID } from 'node:crypto';
2
2
  import { lstatSync, mkdirSync, readFileSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
3
3
  import { join } from 'node:path';
4
4
  import { getAgentDir, type ExtensionAPI, type ExtensionContext } from '@earendil-works/pi-coding-agent';
5
- import { backgroundDigest } from './managed-authority.js';
5
+ import { backgroundDigest, backgroundParametersDigest } from './managed-authority.js';
6
6
  import { readAdmissionStartToken, readProcessStartTokenFresh } from './process-identity.js';
7
7
  import { currentForegroundSandboxPolicy, FOREGROUND_SANDBOX_POLICY_CHANNEL } from './sandbox.js';
8
8
  import { backgroundListNeedsHistory, backgroundObservation } from './work-observation.js';
@@ -48,7 +48,7 @@ export async function requestBackgroundTool(pi: ExtensionAPI, ctx: ExtensionCont
48
48
  const start = version === 2 ? readAdmissionStartToken(process.pid) : readProcessStartTokenFresh(process.pid);
49
49
  const record = { version, id, secretHash: createHash('sha256').update(secret).digest('hex'), instanceId: hello.instanceId,
50
50
  owner: { kind: 'parent-session', sessionId, workspace: realpathSync(ctx.cwd) }, branchIds, projectTrusted: ctx.isProjectTrusted(),
51
- pid: process.pid, start, key, tool, params, parametersDigest: parameters === undefined ? undefined : backgroundDigest(parameters), policy };
51
+ pid: process.pid, start, key, tool, params, parametersDigest: parameters === undefined ? undefined : backgroundParametersDigest(parameters), policy };
52
52
  const staged = `${path}.tmp`;
53
53
  writeFileSync(staged, JSON.stringify(record), { flag: 'wx', mode: 0o600 });
54
54
  renameSync(staged, path);
@@ -1,4 +1,5 @@
1
1
  // Generated fixed launch domain from packages/pi-better-background-tasks/src/observed-waits.ts. Do not edit directly.
2
+ import { taskDeadline } from "./shared-operation-coordinator/src/task-lifetime.domain.mjs";
2
3
  import { getObservedWaitHost, registerObservedWaitClient } from "./observed-wait-client.domain.mjs";
3
4
  export { getObservedWaitHost, registerObservedWaitClient } from "./observed-wait-client.domain.mjs";
4
5
  /**
@@ -341,14 +342,16 @@ function mapEvidence(operationId, taskId, records, revision) {
341
342
  /** Shared terminal publication contract for the host and fixed server cancel adapter. */
342
343
  export function supervisorTerminalPublication(operation, inspection, refs = evidenceFor(inspection)) {
343
344
  const status = inspection.status;
344
- const outcome = terminalOutcome(status);
345
+ const endedAt = inspection.result?.endedAt ?? inspection.lost?.recordedAt;
346
+ const expired = endedAt !== undefined && endedAt >= taskDeadline(Math.min(operation.createdAt, inspection.launch.createdAt));
347
+ const outcome = expired ? "failed" : terminalOutcome(status);
345
348
  return {
346
349
  operationId: operation.operationId,
347
350
  eventId: `${operation.taskId}:${inspection.result?.endedAt ?? inspection.lost?.recordedAt ?? inspection.observedAt}:${status}`,
348
351
  outcome, owner: operation.owner,
349
352
  evidence: refs.map(ref => ({ kind: ref.kind, ref: ref.ref, ...(ref.summary ? { summary: ref.summary } : {}), detailLost: ref.detailLost })),
350
353
  ...(outcome === "lost" ? { detailLost: true } : {}),
351
- reason: inspection.result ? `supervisor ${status} exit=${inspection.result.exitCode ?? "null"}` : "supervisor lost: no terminal evidence",
354
+ reason: expired ? "24-hour task lifetime exceeded" : inspection.result ? `supervisor ${status} exit=${inspection.result.exitCode ?? "null"}` : "supervisor lost: no terminal evidence",
352
355
  };
353
356
  }
354
357
  export class ObservedWaitHost {
@@ -3079,11 +3082,12 @@ export class ObservedWaitHost {
3079
3082
  return;
3080
3083
  const store = this.requireStore();
3081
3084
  const status = inspection.status;
3082
- const outcome = terminalOutcome(status);
3083
3085
  const refs = evidenceFor(inspection);
3086
+ const publication = supervisorTerminalPublication(operation, inspection, refs);
3087
+ const outcome = publication.outcome;
3084
3088
  let recorded;
3085
3089
  try {
3086
- recorded = store.recordTerminalOutcome(supervisorTerminalPublication(operation, inspection, refs));
3090
+ recorded = store.recordTerminalOutcome(publication);
3087
3091
  }
3088
3092
  catch (error) {
3089
3093
  // A timer and a tool call can observe the same terminal record. The store
@@ -1,3 +1,4 @@
1
+ import { taskDeadline } from "./shared-operation-coordinator/src/task-lifetime.ts";
1
2
  import { getObservedWaitHost, registerObservedWaitClient } from "./observed-wait-client.js";
2
3
  export { getObservedWaitHost, registerObservedWaitClient } from "./observed-wait-client.js";
3
4
  /**
@@ -865,14 +866,16 @@ function mapEvidence(
865
866
  /** Shared terminal publication contract for the host and fixed server cancel adapter. */
866
867
  export function supervisorTerminalPublication(operation: OperationRecord, inspection: SupervisorInspection, refs = evidenceFor(inspection)) {
867
868
  const status = inspection.status;
868
- const outcome = terminalOutcome(status);
869
+ const endedAt = inspection.result?.endedAt ?? inspection.lost?.recordedAt;
870
+ const expired = endedAt !== undefined && endedAt >= taskDeadline(Math.min(operation.createdAt, inspection.launch.createdAt));
871
+ const outcome = expired ? "failed" : terminalOutcome(status);
869
872
  return {
870
873
  operationId: operation.operationId,
871
874
  eventId: `${operation.taskId}:${inspection.result?.endedAt ?? inspection.lost?.recordedAt ?? inspection.observedAt}:${status}`,
872
875
  outcome, owner: operation.owner,
873
876
  evidence: refs.map(ref => ({ kind: ref.kind, ref: ref.ref, ...(ref.summary ? { summary: ref.summary } : {}), detailLost: ref.detailLost })),
874
877
  ...(outcome === "lost" ? { detailLost: true } : {}),
875
- reason: inspection.result ? `supervisor ${status} exit=${inspection.result.exitCode ?? "null"}` : "supervisor lost: no terminal evidence",
878
+ reason: expired ? "24-hour task lifetime exceeded" : inspection.result ? `supervisor ${status} exit=${inspection.result.exitCode ?? "null"}` : "supervisor lost: no terminal evidence",
876
879
  };
877
880
  }
878
881
 
@@ -3544,11 +3547,12 @@ export class ObservedWaitHost {
3544
3547
  if (this.resultHandoffs.has(operation.operationId) || this.store?.resultSupervision(operation.operationId)) return;
3545
3548
  const store = this.requireStore();
3546
3549
  const status = inspection.status;
3547
- const outcome = terminalOutcome(status);
3548
3550
  const refs = evidenceFor(inspection);
3551
+ const publication = supervisorTerminalPublication(operation, inspection, refs);
3552
+ const outcome = publication.outcome;
3549
3553
  let recorded;
3550
3554
  try {
3551
- recorded = store.recordTerminalOutcome(supervisorTerminalPublication(operation, inspection, refs));
3555
+ recorded = store.recordTerminalOutcome(publication);
3552
3556
  } catch (error) {
3553
3557
  // A timer and a tool call can observe the same terminal record. The store
3554
3558
  // keeps the first revision; a replay is never a second execution.
@@ -1,4 +1,5 @@
1
1
  // Generated fixed launch domain from packages/pi-better-background-tasks/src/registry.ts. Do not edit directly.
2
+ import { taskDeadline } from "./shared-operation-coordinator/src/task-lifetime.domain.mjs";
2
3
  import { createHash } from "node:crypto";
3
4
  import { mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
4
5
  import { tmpdir } from "node:os";
@@ -113,6 +114,8 @@ export function inspectMeta(id) {
113
114
  metaCache.delete(id);
114
115
  return { id, found: true, readable: false, error: `invalid metadata: ${invalid}` };
115
116
  }
117
+ if (meta.status === "running")
118
+ meta.deadlineAt = taskDeadline(meta.startedAt, meta.deadlineAt);
116
119
  metaCache.set(id, meta);
117
120
  return { id, meta, found: true, readable: true };
118
121
  }
@@ -1,3 +1,4 @@
1
+ import { taskDeadline } from "./shared-operation-coordinator/src/task-lifetime.ts";
1
2
  import { createHash } from "node:crypto";
2
3
  import { mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
3
4
  import { tmpdir } from "node:os";
@@ -137,6 +138,7 @@ export function inspectMeta(id: string): MetaInspection {
137
138
  metaCache.delete(id);
138
139
  return { id, found: true, readable: false, error: `invalid metadata: ${invalid}` };
139
140
  }
141
+ if (meta.status === "running") meta.deadlineAt = taskDeadline(meta.startedAt, meta.deadlineAt);
140
142
  metaCache.set(id, meta);
141
143
  return { id, meta, found: true, readable: true };
142
144
  } catch (error) {
@@ -1,4 +1,5 @@
1
1
  // Generated fixed launch domain from packages/pi-better-background-tasks/src/runtime.ts. Do not edit directly.
2
+ import { taskDeadline } from "./shared-operation-coordinator/src/task-lifetime.domain.mjs";
2
3
  import { WATCH_FINGERPRINT_VERSION, watchOutcomeFingerprint } from "./watch-fingerprint.domain.mjs";
3
4
  import { readFileSync, statSync } from "node:fs";
4
5
  import { appendLine, appendTaskOutput, appendWatchResult, retainLogTail, resolveMaxLogBytes } from "./logs.domain.mjs";
@@ -281,7 +282,7 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
281
282
  status: "running",
282
283
  startedAt: now,
283
284
  lastProgressAt: now,
284
- deadlineAt: params.timeout_seconds ? now + params.timeout_seconds * 1000 : undefined,
285
+ deadlineAt: taskDeadline(now, params.timeout_seconds ? now + params.timeout_seconds * 1000 : undefined),
285
286
  logPath,
286
287
  callback: params.callback,
287
288
  callbackOrigin,
@@ -565,7 +566,7 @@ export function createBackgroundTaskRuntime(attention = createFailureAttention()
565
566
  status: "running",
566
567
  startedAt: now,
567
568
  lastProgressAt: now,
568
- deadlineAt: timeoutSeconds ? now + timeoutSeconds * 1000 : undefined,
569
+ deadlineAt: taskDeadline(now, timeoutSeconds ? now + timeoutSeconds * 1000 : undefined),
569
570
  intervalMs: Math.max(1, params.interval_seconds ?? 30) * 1000,
570
571
  logPath: logPathFor(id),
571
572
  callback: params.callback,
@@ -1,3 +1,4 @@
1
+ import { taskDeadline } from "./shared-operation-coordinator/src/task-lifetime.ts";
1
2
  import { WATCH_FINGERPRINT_VERSION, watchOutcomeFingerprint } from "./watch-fingerprint.js";
2
3
  import { readFileSync, statSync } from "node:fs";
3
4
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
@@ -366,7 +367,7 @@ function spawnTask(
366
367
  status: "running",
367
368
  startedAt: now,
368
369
  lastProgressAt: now,
369
- deadlineAt: params.timeout_seconds ? now + params.timeout_seconds * 1000 : undefined,
370
+ deadlineAt: taskDeadline(now, params.timeout_seconds ? now + params.timeout_seconds * 1000 : undefined),
370
371
  logPath,
371
372
  callback: params.callback,
372
373
  callbackOrigin,
@@ -658,7 +659,7 @@ function startWatchTask(
658
659
  status: "running",
659
660
  startedAt: now,
660
661
  lastProgressAt: now,
661
- deadlineAt: timeoutSeconds ? now + timeoutSeconds * 1000 : undefined,
662
+ deadlineAt: taskDeadline(now, timeoutSeconds ? now + timeoutSeconds * 1000 : undefined),
662
663
  intervalMs: Math.max(1, params.interval_seconds ?? 30) * 1000,
663
664
  logPath: logPathFor(id),
664
665
  callback: params.callback,
@@ -2,11 +2,10 @@
2
2
  // Generated from packages/harness-settings/index.ts. Do not edit directly.
3
3
  import { existsSync, lstatSync, realpathSync, readFileSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
4
4
  import { randomUUID } from "node:crypto";
5
- import { createRequire } from "node:module";
6
5
  import { join } from "node:path";
7
6
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
8
- // Match Pi's settings lock without depending on a private SDK import.
9
- const lockfile = createRequire(import.meta.url)("proper-lockfile");
7
+ // A static import lets the compiled Pi loader resolve dependencies of the settings lock.
8
+ import lockfile from "proper-lockfile";
10
9
  const NAMESPACE = "piBetterHarness";
11
10
  export function harnessSettingsPath(seams = {}) {
12
11
  return join((seams.agentDir ?? getAgentDir)(), "settings.json");
@@ -1,14 +1,11 @@
1
1
  // Generated from packages/harness-settings/index.ts. Do not edit directly.
2
2
  import { existsSync, lstatSync, realpathSync, readFileSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
3
3
  import { randomUUID } from "node:crypto";
4
- import { createRequire } from "node:module";
5
4
  import { join } from "node:path";
6
5
  import { getAgentDir } from "@earendil-works/pi-coding-agent";
6
+ // A static import lets the compiled Pi loader resolve dependencies of the settings lock.
7
+ import lockfile from "proper-lockfile";
7
8
 
8
- // Match Pi's settings lock without depending on a private SDK import.
9
- const lockfile = createRequire(import.meta.url)("proper-lockfile") as {
10
- lockSync(path: string, options: { realpath: boolean }): () => void;
11
- };
12
9
  const NAMESPACE = "piBetterHarness";
13
10
  export interface HarnessSettingsSeams { agentDir?: () => string }
14
11