@akagilnc/pi-workflow-roles 0.1.4992 → 0.1.4996

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.
@@ -312,9 +312,7 @@ function parseCurrentCourtState(raw: unknown): CurrentCourtState | undefined {
312
312
  };
313
313
  }
314
314
 
315
- async function readRoleRunStateDisk(
316
- runDirectory: string,
317
- ): Promise<RoleRunStateDisk | undefined> {
315
+ async function readRoleRunStateRaw(runDirectory: string): Promise<unknown | undefined> {
318
316
  let raw: unknown;
319
317
  try {
320
318
  raw = JSON.parse(await readFile(join(runDirectory, RUN_STATE_FILE), "utf8"));
@@ -328,16 +326,26 @@ async function readRoleRunStateDisk(
328
326
  if (errorCodeOf(error) === "ENOENT") return undefined;
329
327
  throw error;
330
328
  }
329
+ return raw;
330
+ }
331
+
332
+ function parseRoleRunIdentity(raw: unknown, runDirectory: string): {
333
+ readonly runId: string;
334
+ readonly role: RoleRunRecord["role"];
335
+ readonly bookKey: string;
336
+ readonly runDirectory: string;
337
+ readonly state: RoleRunState;
338
+ } {
331
339
  if (raw === null || typeof raw !== "object" || Array.isArray(raw)) {
332
- return undefined;
340
+ throw new TypeError("Invalid run-state.json");
333
341
  }
334
342
  const record = raw as Record<string, unknown>;
335
343
  if (typeof record.runId !== "string" || record.runId.trim() === "") {
336
- return undefined;
344
+ throw new TypeError("Invalid run-state.json");
337
345
  }
338
346
  const role = typeof record.role === "string" ? packagedRoleMetadata(record.role)?.role : undefined;
339
347
  if (role === undefined) {
340
- return undefined;
348
+ throw new TypeError("Invalid run-state.json");
341
349
  }
342
350
  if (
343
351
  record.state !== "admitted" &&
@@ -345,12 +353,28 @@ async function readRoleRunStateDisk(
345
353
  record.state !== "resumable" &&
346
354
  record.state !== "terminal"
347
355
  ) {
348
- return undefined;
356
+ throw new TypeError("Invalid run-state.json");
349
357
  }
350
- if (typeof record.bookKey !== "string") return undefined;
351
- if (typeof record.projectRoot !== "string") return undefined;
352
- if (typeof record.sessionDirectory !== "string") return undefined;
353
- if (typeof record.admittedRequestPath !== "string") return undefined;
358
+ if (typeof record.bookKey !== "string") throw new TypeError("Invalid run-state.json");
359
+ return {
360
+ runId: record.runId,
361
+ role,
362
+ state: record.state,
363
+ bookKey: record.bookKey,
364
+ runDirectory,
365
+ };
366
+ }
367
+
368
+ async function readRoleRunStateDisk(
369
+ runDirectory: string,
370
+ ): Promise<RoleRunStateDisk | undefined> {
371
+ const raw = await readRoleRunStateRaw(runDirectory);
372
+ if (raw === undefined) return undefined;
373
+ const identity = parseRoleRunIdentity(raw, runDirectory);
374
+ const record = raw as Record<string, unknown>;
375
+ if (typeof record.projectRoot !== "string") throw new TypeError("Invalid run-state.json");
376
+ if (typeof record.sessionDirectory !== "string") throw new TypeError("Invalid run-state.json");
377
+ if (typeof record.admittedRequestPath !== "string") throw new TypeError("Invalid run-state.json");
354
378
  const storedRunDirectory =
355
379
  typeof record.runDirectory === "string" && record.runDirectory.trim() !== ""
356
380
  ? record.runDirectory
@@ -389,10 +413,10 @@ async function readRoleRunStateDisk(
389
413
  : undefined;
390
414
  const currentCourt = parseCurrentCourtState(record.currentCourt);
391
415
  return {
392
- runId: record.runId,
393
- role,
394
- state: record.state,
395
- bookKey: record.bookKey,
416
+ runId: identity.runId,
417
+ role: identity.role,
418
+ state: identity.state,
419
+ bookKey: identity.bookKey,
396
420
  projectRoot: record.projectRoot,
397
421
  runDirectory: runDir,
398
422
  admittedRequestPath: rewriteRunDirectoryPathValue(
@@ -491,15 +515,8 @@ export async function readRoleRunIdentity(
491
515
  }
492
516
  | undefined
493
517
  > {
494
- const disk = await readRoleRunStateDisk(runDirectory);
495
- if (disk === undefined) return undefined;
496
- return {
497
- runId: disk.runId,
498
- role: disk.role,
499
- bookKey: disk.bookKey,
500
- runDirectory: disk.runDirectory,
501
- state: disk.state,
502
- };
518
+ const raw = await readRoleRunStateRaw(runDirectory);
519
+ return raw === undefined ? undefined : parseRoleRunIdentity(raw, runDirectory);
503
520
  }
504
521
 
505
522
  export async function markRunAdmitted(
@@ -352,10 +352,12 @@ export async function summonPublicRole(
352
352
  loadCredentialProviders,
353
353
  loadPublicCliConfig,
354
354
  resolveEffectiveSeat,
355
+ validatePublicCliConfigAxes,
355
356
  } = await import("./public-cli/config.ts");
356
357
  const credentials =
357
358
  options.credentials ?? (await loadCredentialProviders(agentDir));
358
359
  const config = await loadPublicCliConfig(home);
360
+ validatePublicCliConfigAxes(config, packageRoot);
359
361
  // Nested summons: officer seat only (flag>seat>default pi). #178 order below.
360
362
  const resolvedSeat = resolveEffectiveSeat(config, options.role, credentials);
361
363
  const inheritedSelection = options.model === undefined