@piewf/cli 5.17.0 → 5.17.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.
@@ -3,7 +3,7 @@ import { lstat, readdir, readFile, stat } from "node:fs/promises";
3
3
  import { homedir } from "node:os";
4
4
  import { join, resolve } from "node:path";
5
5
  import { AGENT_STATES as CORE_AGENT_STATES, BUDGET_DIMENSIONS as CORE_BUDGET_DIMENSIONS, BUDGET_EVENT_TYPES as CORE_BUDGET_EVENT_TYPES, HARD_TERMINAL_RUN_STATES, RUN_STATES, errorText, isNodeError, isThinkingLevel, jsonValue, object, validateBudget, validateModelAliases, validateSchema } from "pi-extensible-workflows";
6
- import { acquireSessionLease, hasLiveSessionLease, projectSessionsDirectory, RunStore } from "pi-extensible-workflows/persistence";
6
+ import { acquireSessionLease, hasLiveSessionLease, json, projectSessionsDirectory, RunStore } from "pi-extensible-workflows/persistence";
7
7
  const DAY_MS = 24 * 60 * 60 * 1000;
8
8
  const REQUIRED_RUN_FILES = ["workflow.js", "state.json", "snapshot.json", "journal.json", "ownership.json", "worktrees.json", "borrowed-worktrees.json", "system-prompts.json"];
9
9
  const OPTIONAL_RUN_FILES = new Set(["result.json", "summary.json"]);
@@ -22,7 +22,6 @@ function positiveDays(value) { if (!Number.isSafeInteger(value) || value < 1 ||
22
22
  throw new Error("older-than-days must be a positive integer"); return value; }
23
23
  function runItem(entry, action, reason) { return { sessionId: entry.sessionId, runId: entry.runId, action, state: entry.run.state, stateMtimeMs: entry.stateMtimeMs, path: entry.store.directory, ...(reason ? { reason } : {}) }; }
24
24
  function sameNames(left, right) { return left.length === right.length && left.every((value, index) => value === right[index]); }
25
- async function jsonFile(path) { return JSON.parse(await readFile(path, "utf8")); }
26
25
  async function requiredFile(path) { const info = await lstat(path); if (!info.isFile())
27
26
  throw new Error(`Required artifact is not a regular file: ${path}`); }
28
27
  function stringList(value, label, nonEmpty = false) { if (!isList(value) || value.some((item) => typeof item !== "string" || (nonEmpty && !item)))
@@ -271,7 +270,7 @@ function validateJournal(value) { if (!object(value) || !object(value.completed)
271
270
  validateBudget(decision.proposed);
272
271
  } }
273
272
  async function validateSystemPrompts(store) {
274
- const value = await jsonFile(store.systemPromptPath());
273
+ const value = await json(store.systemPromptPath());
275
274
  if (object(value) && value.version === 2) {
276
275
  await store.systemPrompts();
277
276
  return;
@@ -312,14 +311,14 @@ async function validateRunArtifacts(store, workflowScript, state) {
312
311
  if (await readFile(join(store.directory, "workflow.js"), "utf8") !== workflowScript)
313
312
  throw new Error("Persisted workflow source does not match its launch snapshot");
314
313
  await validateSystemPrompts(store);
315
- const result = await jsonFile(join(store.directory, "result.json")).catch((error) => { if (isNodeError(error, "ENOENT"))
314
+ const result = await json(join(store.directory, "result.json")).catch((error) => { if (isNodeError(error, "ENOENT"))
316
315
  return undefined; throw error; });
317
316
  if (result === undefined && state === "completed")
318
317
  throw new Error("Completed run result is missing");
319
318
  if (result !== undefined && !jsonValue(result))
320
319
  throw new Error("Persisted workflow result is invalid");
321
- validateJournal(await jsonFile(join(store.directory, "journal.json")));
322
- const rawOwnership = await jsonFile(join(store.directory, "ownership.json"));
320
+ validateJournal(await json(join(store.directory, "journal.json")));
321
+ const rawOwnership = await json(join(store.directory, "ownership.json"));
323
322
  if (!isList(rawOwnership))
324
323
  throw new Error("Persisted ownership records are invalid");
325
324
  const ownershipIds = new Set();
@@ -362,7 +361,7 @@ async function scanSession(cwd, sessionId, home, expectedLease) {
362
361
  const ownerPath = join(runsPath, "owner.json");
363
362
  let liveLease = false;
364
363
  if (expectedLease && expectedLease.path === ownerPath) {
365
- const owned = await jsonFile(ownerPath);
364
+ const owned = await json(ownerPath);
366
365
  if (!object(owned) || owned.token !== expectedLease.token)
367
366
  throw new Error("Session ownership lease changed before deletion");
368
367
  }
@@ -113,7 +113,8 @@ function transcript(manager) {
113
113
  }
114
114
  function readTranscript(path) {
115
115
  try {
116
- if (!existsSync(path) || !statSync(path).isFile() || statSync(path).size === 0)
116
+ const info = existsSync(path) ? statSync(path) : undefined;
117
+ if (!info?.isFile() || info.size === 0)
117
118
  return undefined;
118
119
  const manager = SessionManager.open(path);
119
120
  if (!manager.getHeader())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@piewf/cli",
3
- "version": "5.17.0",
3
+ "version": "5.17.1",
4
4
  "description": "CLI for pi-extensible-workflows",
5
5
  "homepage": "https://vekexasia.github.io/pi-extensible-workflows/",
6
6
  "repository": {
@@ -45,7 +45,7 @@
45
45
  "@earendil-works/pi-coding-agent": "0.85.0",
46
46
  "@earendil-works/pi-server": "0.85.0",
47
47
  "@earendil-works/pi-tui": "0.85.0",
48
- "pi-extensible-workflows": "5.17.0",
48
+ "pi-extensible-workflows": "5.17.1",
49
49
  "typebox": "1.3.7"
50
50
  },
51
51
  "publishConfig": {