@aisac/cli 0.4.0-beta.12 → 0.4.0-beta.14

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.
@@ -499,15 +499,22 @@ async function request(child, id, method, params) {
499
499
  return message.result;
500
500
  }
501
501
 
502
- /** @param {string} executable @param {string} cwd @param {string|undefined} profile @param {NodeJS.ProcessEnv} environment */
503
- export async function readEffectiveWritableRoots(executable, cwd, profile, environment) {
504
- validateProfile(profile);
502
+ /**
503
+ * Run one short-lived, initialized app-server for a preflight read, then stop it
504
+ * and its process group. `body` gets the child and whether a signal cancelled it.
505
+ * @template T
506
+ * @param {{ executable: string, cwd: string, profile: string|undefined, environment: NodeJS.ProcessEnv, configArgs?: string[] }} options
507
+ * @param {(child: OwnedChild, cancelled: () => boolean) => Promise<T>} body
508
+ * @returns {Promise<T>}
509
+ */
510
+ async function withPreflightServer(options, body) {
511
+ validateProfile(options.profile);
505
512
  const args = [];
506
- if (profile !== undefined) args.push('--profile', profile);
507
- args.push('app-server', '--listen', 'stdio://');
508
- const child = spawn(executable, args, {
509
- cwd,
510
- env: childEnvironment(environment),
513
+ if (options.profile !== undefined) args.push('--profile', options.profile);
514
+ args.push(...(options.configArgs ?? []), 'app-server', '--listen', 'stdio://');
515
+ const child = spawn(options.executable, args, {
516
+ cwd: options.cwd,
517
+ env: childEnvironment(options.environment),
511
518
  stdio: ['pipe', 'pipe', 'ignore'],
512
519
  detached: process.platform !== 'win32',
513
520
  });
@@ -531,32 +538,7 @@ export async function readEffectiveWritableRoots(executable, cwd, profile, envir
531
538
  } catch {
532
539
  fail('preflight_failed');
533
540
  }
534
- const result = await request(child, 1, 'config/read', { cwd, includeLayers: true });
535
- const rawConfig = result.config;
536
- if (
537
- rawConfig === undefined ||
538
- rawConfig === null ||
539
- typeof rawConfig !== 'object' ||
540
- Array.isArray(rawConfig)
541
- )
542
- fail('preflight_roots_unavailable');
543
- const config = /** @type {JsonObject} */ (rawConfig);
544
- const rawSandbox = config.sandbox_workspace_write;
545
- if (cancelled) fail('preflight_cancelled');
546
- if (rawSandbox === undefined || rawSandbox === null) return [];
547
- if (typeof rawSandbox !== 'object' || Array.isArray(rawSandbox))
548
- fail('preflight_roots_unavailable');
549
- const sandbox = /** @type {JsonObject} */ (rawSandbox);
550
- const roots = sandbox.writable_roots;
551
- if (cancelled) fail('preflight_cancelled');
552
- if (roots === undefined || roots === null) return [];
553
- if (
554
- !Array.isArray(roots) ||
555
- roots.some((path) => typeof path !== 'string' || !isAbsolute(path))
556
- )
557
- fail('preflight_roots_unavailable');
558
- if (cancelled) fail('preflight_cancelled');
559
- return deduplicate(roots);
541
+ return await body(child, () => cancelled);
560
542
  } finally {
561
543
  process.removeListener('SIGINT', cancel);
562
544
  process.removeListener('SIGTERM', cancel);
@@ -565,6 +547,57 @@ export async function readEffectiveWritableRoots(executable, cwd, profile, envir
565
547
  }
566
548
  }
567
549
 
550
+ /** @param {string} executable @param {string} cwd @param {string|undefined} profile @param {NodeJS.ProcessEnv} environment */
551
+ export async function readEffectiveWritableRoots(executable, cwd, profile, environment) {
552
+ return withPreflightServer(
553
+ { executable, cwd, profile, environment },
554
+ async (child, cancelled) => {
555
+ const result = await request(child, 1, 'config/read', { cwd, includeLayers: true });
556
+ const rawConfig = result.config;
557
+ if (
558
+ rawConfig === undefined ||
559
+ rawConfig === null ||
560
+ typeof rawConfig !== 'object' ||
561
+ Array.isArray(rawConfig)
562
+ )
563
+ fail('preflight_roots_unavailable');
564
+ const config = /** @type {JsonObject} */ (rawConfig);
565
+ const rawSandbox = config.sandbox_workspace_write;
566
+ if (cancelled()) fail('preflight_cancelled');
567
+ if (rawSandbox === undefined || rawSandbox === null) return [];
568
+ if (typeof rawSandbox !== 'object' || Array.isArray(rawSandbox))
569
+ fail('preflight_roots_unavailable');
570
+ const sandbox = /** @type {JsonObject} */ (rawSandbox);
571
+ const roots = sandbox.writable_roots;
572
+ if (cancelled()) fail('preflight_cancelled');
573
+ if (roots === undefined || roots === null) return [];
574
+ if (
575
+ !Array.isArray(roots) ||
576
+ roots.some((path) => typeof path !== 'string' || !isAbsolute(path))
577
+ )
578
+ fail('preflight_roots_unavailable');
579
+ if (cancelled()) fail('preflight_cancelled');
580
+ return deduplicate(roots);
581
+ },
582
+ );
583
+ }
584
+
585
+ /**
586
+ * What Codex reports for a set of session-flag hooks (`hooks/list` for one
587
+ * folder), read from a short-lived app-server started with those flags and the
588
+ * user's own CODEX_HOME, where the trust records live. It writes no config and
589
+ * no trust record (spec aisac-engineering-extensions FR6, part 1 Q4).
590
+ * @param {{ executable: string, cwd: string, profile: string|undefined, environment: NodeJS.ProcessEnv, configArgs: string[] }} options
591
+ * @returns {Promise<JsonObject>}
592
+ */
593
+ export async function readCodexHookList(options) {
594
+ return withPreflightServer(options, async (child, cancelled) => {
595
+ const result = await request(child, 1, 'hooks/list', { cwds: [options.cwd] });
596
+ if (cancelled()) fail('preflight_cancelled');
597
+ return result;
598
+ });
599
+ }
600
+
568
601
  /** @param {LaunchPlan} plan @param {string[]} configuredRoots */
569
602
  export function makeCodexLaunchEnvelope(plan, configuredRoots) {
570
603
  const roots = deduplicate([...configuredRoots, ...plan.additionalRoots]);