poe-code 14.0.0 → 14.0.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/dist/index.js CHANGED
@@ -83357,8 +83357,14 @@ import { TextDecoder as TextDecoder2 } from "node:util";
83357
83357
  async function startManagedProcess(options) {
83358
83358
  assertOptionalFiniteDuration(options.startupTimeoutMs, "startup timeout");
83359
83359
  assertOptionalFiniteDuration(options.pollIntervalMs, "poll interval");
83360
- const fs31 = options.fs ?? defaultFs3();
83361
83360
  const spec10 = normalizeSpec(options.spec);
83361
+ return await withManagedProcessOperation(
83362
+ { ...options, id: spec10.id },
83363
+ async (fs31) => await startReservedProcess({ ...options, fs: fs31, spec: spec10 })
83364
+ );
83365
+ }
83366
+ async function startReservedProcess(options) {
83367
+ const { fs: fs31, spec: spec10 } = options;
83362
83368
  const existing = await readManagedProcess({
83363
83369
  baseDir: options.baseDir,
83364
83370
  fs: fs31,
@@ -83400,7 +83406,13 @@ async function startManagedProcess(options) {
83400
83406
  async function stopManagedProcess(options) {
83401
83407
  assertOptionalFiniteDuration(options.stopTimeoutMs, "stop timeout");
83402
83408
  assertOptionalFiniteDuration(options.pollIntervalMs, "poll interval");
83403
- const fs31 = options.fs ?? defaultFs3();
83409
+ return await withManagedProcessOperation(
83410
+ options,
83411
+ async (fs31) => await stopReservedProcess({ ...options, fs: fs31 })
83412
+ );
83413
+ }
83414
+ async function stopReservedProcess(options) {
83415
+ const { fs: fs31 } = options;
83404
83416
  const record2 = await readManagedProcess({
83405
83417
  baseDir: options.baseDir,
83406
83418
  fs: fs31,
@@ -83443,37 +83455,75 @@ async function stopManagedProcess(options) {
83443
83455
  return stopped;
83444
83456
  }
83445
83457
  async function restartManagedProcess(options) {
83446
- const fs31 = options.fs ?? defaultFs3();
83447
- const record2 = await readManagedProcess({
83448
- baseDir: options.baseDir,
83449
- fs: fs31,
83450
- id: options.id,
83451
- isPidRunning: options.isPidRunning
83458
+ assertOptionalFiniteDuration(options.startupTimeoutMs, "startup timeout");
83459
+ assertOptionalFiniteDuration(options.stopTimeoutMs, "stop timeout");
83460
+ assertOptionalFiniteDuration(options.pollIntervalMs, "poll interval");
83461
+ return await withManagedProcessOperation(options, async (fs31) => {
83462
+ const record2 = await readManagedProcess({
83463
+ baseDir: options.baseDir,
83464
+ fs: fs31,
83465
+ id: options.id,
83466
+ isPidRunning: options.isPidRunning
83467
+ });
83468
+ if (record2.spec === null) {
83469
+ throw await managedProcessNotFound(fs31, options.baseDir, options.id);
83470
+ }
83471
+ await stopReservedProcess({
83472
+ ...options,
83473
+ force: false,
83474
+ fs: fs31
83475
+ });
83476
+ return await startReservedProcess({
83477
+ ...options,
83478
+ fs: fs31,
83479
+ spec: normalizeSpec(record2.spec)
83480
+ });
83452
83481
  });
83453
- if (record2.spec === null) {
83454
- throw await managedProcessNotFound(fs31, options.baseDir, options.id);
83482
+ }
83483
+ async function withManagedProcessOperation(options, operation) {
83484
+ const fs31 = options.fs ?? defaultFs3();
83485
+ await assertProcessDirectorySafe(fs31, options.baseDir, options.id);
83486
+ await fs31.mkdir(options.baseDir, { recursive: true });
83487
+ const baseDir = path110.resolve(options.baseDir);
83488
+ const operationsDir = path110.join(path110.dirname(baseDir), ".process-operations", path110.basename(baseDir));
83489
+ await assertPathHasNoSymbolicLinks4(fs31, operationsDir);
83490
+ await fs31.mkdir(operationsDir, { recursive: true });
83491
+ const lockPath = path110.join(operationsDir, options.id);
83492
+ const owner = `${JSON.stringify({ token: randomUUID36(), pid: process.pid })}
83493
+ `;
83494
+ try {
83495
+ await fs31.writeFile(lockPath, owner, { encoding: "utf8", flag: "wx" });
83496
+ } catch (error3) {
83497
+ if (hasOwnErrorCode23(error3, "EEXIST")) {
83498
+ throw new UserError(
83499
+ `Managed process "${options.id}" has another operation in progress.
83500
+ Retry after it finishes.
83501
+ If the caller exited unexpectedly, confirm that all operations on this name have stopped,
83502
+ then remove this reservation file:
83503
+ ${lockPath}`
83504
+ );
83505
+ }
83506
+ throw error3;
83455
83507
  }
83456
- await stopManagedProcess({
83457
- baseDir: options.baseDir,
83458
- force: false,
83459
- fs: fs31,
83460
- id: options.id,
83461
- isPidRunning: options.isPidRunning,
83462
- pollIntervalMs: options.pollIntervalMs,
83463
- signalProcess: options.signalProcess,
83464
- stopRuntimeArtifacts: options.stopRuntimeArtifacts,
83465
- stopTimeoutMs: options.stopTimeoutMs
83466
- });
83467
- return await startManagedProcess({
83468
- baseDir: options.baseDir,
83469
- fs: fs31,
83470
- isPidRunning: options.isPidRunning,
83471
- pollIntervalMs: options.pollIntervalMs,
83472
- signalProcess: options.signalProcess,
83473
- spawnDaemon: options.spawnDaemon,
83474
- spec: record2.spec,
83475
- startupTimeoutMs: options.startupTimeoutMs
83476
- });
83508
+ let outcome;
83509
+ try {
83510
+ outcome = { result: await operation(fs31) };
83511
+ } catch (error3) {
83512
+ outcome = { error: error3 };
83513
+ }
83514
+ try {
83515
+ if (await fs31.readFile(lockPath, "utf8") !== owner) {
83516
+ throw new UserError(`Managed process operation ownership changed before release: ${lockPath}`);
83517
+ }
83518
+ await fs31.rm(lockPath);
83519
+ } catch (releaseError) {
83520
+ if ("error" in outcome) {
83521
+ throw new AggregateError([outcome.error, releaseError], "Managed process operation and ownership release failed");
83522
+ }
83523
+ throw releaseError;
83524
+ }
83525
+ if ("error" in outcome) throw outcome.error;
83526
+ return outcome.result;
83477
83527
  }
83478
83528
  async function describeStartFailure(fs31, baseDir, id, record2) {
83479
83529
  const state = record2.state;
@@ -83683,21 +83733,22 @@ function getFileId(stat35) {
83683
83733
  return typeof stat35.dev === "number" && typeof stat35.ino === "number" ? `${stat35.dev}:${stat35.ino}` : null;
83684
83734
  }
83685
83735
  async function removeManagedProcess(options) {
83686
- const fs31 = options.fs ?? defaultFs3();
83687
- const record2 = await readManagedProcess({
83688
- baseDir: options.baseDir,
83689
- fs: fs31,
83690
- id: options.id,
83691
- isPidRunning: options.isPidRunning
83736
+ await withManagedProcessOperation(options, async (fs31) => {
83737
+ const record2 = await readManagedProcess({
83738
+ baseDir: options.baseDir,
83739
+ fs: fs31,
83740
+ id: options.id,
83741
+ isPidRunning: options.isPidRunning
83742
+ });
83743
+ if (isActiveRecord(record2)) {
83744
+ throw new Error(`Managed process "${options.id}" must be stopped before removal.`);
83745
+ }
83746
+ const stateStore = createStateStore(options.baseDir, fs31);
83747
+ await stateStore.remove(options.id);
83748
+ if (record2.spec !== null && options.removeRuntimeArtifacts) {
83749
+ await options.removeRuntimeArtifacts({ record: record2 });
83750
+ }
83692
83751
  });
83693
- if (isActiveRecord(record2)) {
83694
- throw new Error(`Managed process "${options.id}" must be stopped before removal.`);
83695
- }
83696
- const stateStore = createStateStore(options.baseDir, fs31);
83697
- await stateStore.remove(options.id);
83698
- if (record2.spec !== null && options.removeRuntimeArtifacts) {
83699
- await options.removeRuntimeArtifacts({ record: record2 });
83700
- }
83701
83752
  }
83702
83753
  async function runManagedProcess(options) {
83703
83754
  if (options.signal?.aborted) {
@@ -157476,7 +157527,7 @@ var init_package2 = __esm({
157476
157527
  "package.json"() {
157477
157528
  package_default2 = {
157478
157529
  name: "poe-code",
157479
- version: "14.0.0",
157530
+ version: "14.0.1",
157480
157531
  description: "CLI tool to configure Poe API for developer workflows.",
157481
157532
  license: "MIT",
157482
157533
  type: "module",