pi-better-goal 0.16.0 → 0.16.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-better-goal",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Pi extension for goal tracking with background-aware continuation.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -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
 
@@ -1,5 +1,6 @@
1
1
  import { execFile } from "node:child_process";
2
- import { cpSync, existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from "node:fs";
2
+ import { readFileSync, readdirSync, statSync } from "node:fs";
3
+ import { mkdir, mkdtemp, readdir, readFile, rm, stat, utimes, writeFile } from "node:fs/promises";
3
4
  import { tmpdir } from "node:os";
4
5
  import { dirname, join } from "node:path";
5
6
 
@@ -139,18 +140,54 @@ async function settlementScheduler(script: string, runDir: string, timeoutMs?: n
139
140
 
140
141
  // --peek suppresses seen bookkeeping, not syncRun's issue-tree write. Give the live
141
142
  // probe private inputs; keep cwd so relative workspace paths retain their meaning.
143
+ const budget = timeoutMs ?? SCHEDULER_SYNC_TIMEOUT_MS;
144
+ const startedAt = performance.now();
145
+ const signal = AbortSignal.timeout(budget);
142
146
  let snapshot: string | undefined;
143
147
  try {
144
- snapshot = mkdtempSync(join(tmpdir(), "pi-goal-scheduler-"));
145
- for (const name of ["task-plan.json", "issue-tree.json", "next-actions-seen.json", "reviews", "results"]) {
148
+ snapshot = await mkdtemp(join(tmpdir(), "pi-goal-scheduler-"));
149
+ for (const name of ["task-plan.json", "issue-tree.json", "next-actions-seen.json"]) {
150
+ await copySchedulerRecord(join(runDir, name), join(snapshot, name), signal);
151
+ }
152
+ // next-actions reads top-level JSON records. Review checkout trees and worker
153
+ // artifacts can be much larger and aren't inputs to the settlement decision.
154
+ for (const name of ["reviews", "results"]) {
155
+ signal.throwIfAborted();
146
156
  const source = join(runDir, name);
147
- if (existsSync(source)) cpSync(source, join(snapshot, name), { recursive: true, dereference: true });
157
+ const names = await readdir(source).catch((error: NodeJS.ErrnoException) => {
158
+ if (error.code === "ENOENT") return [];
159
+ throw error;
160
+ });
161
+ if (!names.length) continue;
162
+ const target = join(snapshot, name);
163
+ await mkdir(target);
164
+ for (const file of names) {
165
+ if (file.endsWith(".json")) {
166
+ await copySchedulerRecord(join(source, file), join(target, file), signal);
167
+ }
168
+ }
148
169
  }
149
- return await executeScheduler(script, snapshot, timeoutMs ?? SCHEDULER_SYNC_TIMEOUT_MS, true, runDir);
170
+ const remaining = budget - Math.ceil(performance.now() - startedAt);
171
+ if (signal.aborted || remaining <= 0) return { ok: false, reason: `the live scheduler check timed out after ${budget} ms` };
172
+ return await executeScheduler(script, snapshot, remaining, true, runDir);
150
173
  } catch (error) {
174
+ if (signal.aborted) return { ok: false, reason: `the live scheduler check timed out after ${budget} ms` };
151
175
  return { ok: false, reason: `could not prepare the live scheduler check (${String(error).slice(0, DETAIL_LIMIT)})` };
152
176
  } finally {
153
- if (snapshot) rmSync(snapshot, { recursive: true, force: true });
177
+ if (snapshot) await rm(snapshot, { recursive: true, force: true });
178
+ }
179
+ }
180
+
181
+ async function copySchedulerRecord(source: string, target: string, signal: AbortSignal): Promise<void> {
182
+ signal.throwIfAborted();
183
+ try {
184
+ const info = await stat(source);
185
+ if (!info.isFile()) return;
186
+ await writeFile(target, await readFile(source, { signal }), { signal });
187
+ // Review mtimes tell the scheduler when the last round was written.
188
+ await utimes(target, info.atime, info.mtime);
189
+ } catch (error) {
190
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
154
191
  }
155
192
  }
156
193