acpx 0.12.0 → 0.12.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.
Files changed (32) hide show
  1. package/README.md +3 -2
  2. package/dist/{cli-CxsS1XQp.js → cli-pKoIEH5O.js} +4 -4
  3. package/dist/{cli-CxsS1XQp.js.map → cli-pKoIEH5O.js.map} +1 -1
  4. package/dist/cli.d.ts +1 -2
  5. package/dist/cli.d.ts.map +1 -1
  6. package/dist/cli.js +18 -12
  7. package/dist/cli.js.map +1 -1
  8. package/dist/{client-DwNyFauq.d.ts → client-CFo_9MIo.d.ts} +2 -3
  9. package/dist/client-CFo_9MIo.d.ts.map +1 -0
  10. package/dist/{flags-Bjq_XQ4-.js → flags-CjeFX5ki.js} +3 -3
  11. package/dist/{flags-Bjq_XQ4-.js.map → flags-CjeFX5ki.js.map} +1 -1
  12. package/dist/{flows-Db_LZKu9.js → flows-Cym6H3vg.js} +3 -3
  13. package/dist/{flows-Db_LZKu9.js.map → flows-Cym6H3vg.js.map} +1 -1
  14. package/dist/flows.d.ts +2 -2
  15. package/dist/flows.d.ts.map +1 -1
  16. package/dist/flows.js +1 -1
  17. package/dist/{live-checkpoint-ClPCSdrW.js → live-checkpoint-DQp4JSHD.js} +7 -6
  18. package/dist/live-checkpoint-DQp4JSHD.js.map +1 -0
  19. package/dist/{output-CjdF5rHk.js → output-fNqTAsFQ.js} +126 -18
  20. package/dist/output-fNqTAsFQ.js.map +1 -0
  21. package/dist/runtime.d.ts +16 -12
  22. package/dist/runtime.d.ts.map +1 -1
  23. package/dist/runtime.js +3 -2
  24. package/dist/runtime.js.map +1 -1
  25. package/dist/{session-options-jkYbBxGE.d.ts → session-options-C4uYkKDy.d.ts} +1 -2
  26. package/dist/session-options-C4uYkKDy.d.ts.map +1 -0
  27. package/package.json +16 -16
  28. package/skills/acpx/SKILL.md +5 -5
  29. package/dist/client-DwNyFauq.d.ts.map +0 -1
  30. package/dist/live-checkpoint-ClPCSdrW.js.map +0 -1
  31. package/dist/output-CjdF5rHk.js.map +0 -1
  32. package/dist/session-options-jkYbBxGE.d.ts.map +0 -1
@@ -1,4 +1,4 @@
1
- import { $ as getPerfMetricsSnapshot, B as absolutePath, C as mergeSessionOptions, Ct as promptToDisplayText, D as applyLifecycleSnapshotToRecord, Dt as withInterrupt, E as applyConversation, Et as TimeoutError, F as modelStateFromConfigOptions, Ft as isRetryablePromptError, G as listSessions, H as findSession, I as splitCommandLine, It as normalizeOutputError, J as pruneSessions, K as listSessionsForAgent, Lt as extractAcpError, N as assertRequestedModelSupported, Ot as withTimeout, Pt as formatErrorMessage, Q as formatPerfMetric, Qt as QueueProtocolError, S as advertisedModelState, T as sessionOptionsFromRecord, Tt as InterruptedError, U as findSessionByDirectoryWalk, Ut as OUTPUT_ERROR_CODES, V as findGitRepositoryRoot, W as isoNow, Wt as OUTPUT_ERROR_ORIGINS, X as writeSessionRecord, Y as resolveSessionRecord, Zt as QueueConnectionError, _ as createSessionConversation, _t as parseJsonRpcErrorMessage, a as applyRequestedModelIfAdvertised, at as startPerfTimer, b as recordSessionUpdate, bt as isPromptInput, c as setCurrentModelId, ct as normalizeRuntimeSessionId, d as setDesiredModelId, dt as sessionBaseDir, et as incrementPerfCounter, f as syncAdvertisedModelState, ft as sessionEventActivePath, g as cloneSessionConversation, gt as isAcpJsonRpcMessage, h as cloneSessionAcpxState, ht as extractSessionUpdateNotification, i as connectAndLoadSession, it as setPerfGauge, k as AcpClient, l as setDesiredConfigOption, m as applyConfigOptionsToState, mt as sessionEventSegmentPath, n as runPromptTurn, nt as recordPerfDuration, o as currentModelIdFromSetModelResponse, p as applyConfigOptionsToRecord, pt as sessionEventLockPath, q as normalizeName, r as withConnectedSession, rt as resetPerfMetrics, s as clearDesiredConfigOption, t as LiveSessionCheckpoint, tt as measurePerf, u as setDesiredModeId, ut as defaultSessionEventLog, v as recordClientOperation, vt as parsePromptStopReason, w as persistSessionOptions, wt as textPrompt, x as trimConversationForRuntime, y as recordPromptSubmission, zt as toAcpErrorPayload } from "./live-checkpoint-ClPCSdrW.js";
1
+ import { $ as getPerfMetricsSnapshot, B as absolutePath, C as mergeSessionOptions, Ct as promptToDisplayText, D as applyLifecycleSnapshotToRecord, Dt as withInterrupt, E as applyConversation, Et as TimeoutError, F as modelStateFromConfigOptions, Ft as isRetryablePromptError, G as listSessions, H as findSession, I as splitCommandLine, It as normalizeOutputError, J as pruneSessions, K as listSessionsForAgent, Lt as extractAcpError, N as assertRequestedModelSupported, Ot as withTimeout, Pt as formatErrorMessage, Q as formatPerfMetric, Qt as QueueProtocolError, S as advertisedModelState, T as sessionOptionsFromRecord, Tt as InterruptedError, U as findSessionByDirectoryWalk, Ut as OUTPUT_ERROR_CODES, V as findGitRepositoryRoot, W as isoNow, Wt as OUTPUT_ERROR_ORIGINS, X as writeSessionRecord, Y as resolveSessionRecord, Zt as QueueConnectionError, _ as createSessionConversation, _t as parseJsonRpcErrorMessage, a as applyRequestedModelIfAdvertised, at as startPerfTimer, b as recordSessionUpdate, bt as isPromptInput, c as setCurrentModelId, ct as normalizeRuntimeSessionId, d as setDesiredModelId, dt as sessionBaseDir, et as incrementPerfCounter, f as syncAdvertisedModelState, ft as sessionEventActivePath, g as cloneSessionConversation, gt as isAcpJsonRpcMessage, h as cloneSessionAcpxState, ht as extractSessionUpdateNotification, i as connectAndLoadSession, it as setPerfGauge, k as AcpClient, l as setDesiredConfigOption, m as applyConfigOptionsToState, mt as sessionEventSegmentPath, n as runPromptTurn, nt as recordPerfDuration, o as currentModelIdFromSetModelResponse, p as applyConfigOptionsToRecord, pt as sessionEventLockPath, q as normalizeName, r as withConnectedSession, rt as resetPerfMetrics, s as clearDesiredConfigOption, t as LiveSessionCheckpoint, tt as measurePerf, u as setDesiredModeId, ut as defaultSessionEventLog, v as recordClientOperation, vt as parsePromptStopReason, w as persistSessionOptions, wt as textPrompt, x as trimConversationForRuntime, y as recordPromptSubmission, zt as toAcpErrorPayload } from "./live-checkpoint-DQp4JSHD.js";
2
2
  import fs, { mkdtempSync, realpathSync, writeFileSync } from "node:fs";
3
3
  import path from "node:path";
4
4
  import fs$1 from "node:fs/promises";
@@ -104,18 +104,26 @@ function isQueueOwnerHeartbeatStale(owner) {
104
104
  }
105
105
  async function ensureQueueDir() {
106
106
  const baseDir = queueBaseDir();
107
- await fs$1.mkdir(baseDir, {
108
- recursive: true,
109
- mode: 448
110
- });
111
- await fs$1.chmod(baseDir, 448);
107
+ try {
108
+ await fs$1.mkdir(baseDir, {
109
+ recursive: true,
110
+ mode: 448
111
+ });
112
+ await fs$1.chmod(baseDir, 448);
113
+ } catch (error) {
114
+ const message = error instanceof Error ? error.message : String(error);
115
+ throw new Error(`Failed to prepare queue directory ${baseDir}: ${message}`, { cause: error });
116
+ }
112
117
  const socketDir = queueSocketBaseDir();
113
- if (socketDir) {
118
+ if (socketDir) try {
114
119
  await fs$1.mkdir(socketDir, {
115
120
  recursive: true,
116
121
  mode: 448
117
122
  });
118
123
  await fs$1.chmod(socketDir, 448);
124
+ } catch (error) {
125
+ const message = error instanceof Error ? error.message : String(error);
126
+ throw new Error(`Failed to prepare queue socket directory ${socketDir}: ${message}`, { cause: error });
119
127
  }
120
128
  }
121
129
  async function removeSocketFile(socketPath) {
@@ -1310,6 +1318,7 @@ async function submitToQueueOwner(owner, options) {
1310
1318
  owner,
1311
1319
  request,
1312
1320
  onAccepted: ({ resolve }) => {
1321
+ options.onQueueAccepted?.();
1313
1322
  options.outputFormatter.setContext({ sessionId: options.sessionId });
1314
1323
  if (!options.waitForCompletion) resolve({
1315
1324
  queued: true,
@@ -2311,7 +2320,9 @@ function writeQueueOwnerPayloadFile(payload) {
2311
2320
  });
2312
2321
  return payloadPath;
2313
2322
  }
2314
- function buildQueueOwnerSpawnOptions(payloadFilePath) {
2323
+ /** Max stderr bytes retained for cold-start diagnostics. */
2324
+ const QUEUE_OWNER_STARTUP_STDERR_MAX_BYTES = 4e3;
2325
+ function buildQueueOwnerSpawnOptions(payloadFilePath, opts) {
2315
2326
  const env = {
2316
2327
  ...process.env,
2317
2328
  [QUEUE_OWNER_PAYLOAD_FILE_ENV]: payloadFilePath
@@ -2319,14 +2330,77 @@ function buildQueueOwnerSpawnOptions(payloadFilePath) {
2319
2330
  delete env[QUEUE_OWNER_PAYLOAD_ENV];
2320
2331
  return {
2321
2332
  detached: true,
2322
- stdio: "ignore",
2333
+ stdio: opts?.captureStderr === true ? [
2334
+ "ignore",
2335
+ "ignore",
2336
+ "pipe"
2337
+ ] : "ignore",
2323
2338
  env,
2324
2339
  windowsHide: true
2325
2340
  };
2326
2341
  }
2342
+ function formatQueueOwnerStartupFailure(params) {
2343
+ const parts = [`Session queue owner failed to start for session ${params.sessionId}`];
2344
+ if (params.exit.spawnError) parts.push(`spawn error: ${params.exit.spawnError.message}`);
2345
+ else if (params.exit.exited) {
2346
+ const codePart = params.exit.code === null ? "null" : String(params.exit.code);
2347
+ const signalPart = params.exit.signal ? `, signal ${params.exit.signal}` : "";
2348
+ parts.push(`exited with code ${codePart}${signalPart} before binding its socket`);
2349
+ }
2350
+ const tail = params.logTail.trim();
2351
+ if (tail.length > 0) parts.push(`stderr:\n${tail}`);
2352
+ return parts.join(": ");
2353
+ }
2327
2354
  function spawnQueueOwnerProcess(options) {
2328
2355
  const payloadPath = writeQueueOwnerPayloadFile(JSON.stringify(options));
2329
- spawn(process.execPath, resolveQueueOwnerSpawnArgs(), buildQueueOwnerSpawnOptions(payloadPath)).unref();
2356
+ let exited = false;
2357
+ let code = null;
2358
+ let signal = null;
2359
+ let spawnError;
2360
+ let capturing = true;
2361
+ let stderrTail = Buffer.alloc(0);
2362
+ const child = spawn(process.execPath, resolveQueueOwnerSpawnArgs(), buildQueueOwnerSpawnOptions(payloadPath, { captureStderr: true }));
2363
+ const stopStartupCapture = () => {
2364
+ if (!capturing) return;
2365
+ capturing = false;
2366
+ const stderr = child.stderr;
2367
+ if (!stderr) return;
2368
+ stderr.removeAllListeners("data");
2369
+ stderr.on("data", () => {});
2370
+ stderr.resume();
2371
+ stderr.unref();
2372
+ };
2373
+ child.stderr?.on("data", (chunk) => {
2374
+ if (!capturing) return;
2375
+ const buf = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
2376
+ const combined = Buffer.concat([stderrTail, buf]);
2377
+ stderrTail = combined.length > 4e3 ? combined.subarray(combined.length - QUEUE_OWNER_STARTUP_STDERR_MAX_BYTES) : combined;
2378
+ });
2379
+ child.stderr?.on("error", () => {});
2380
+ child.on("error", (error) => {
2381
+ spawnError = error;
2382
+ });
2383
+ child.on("close", (exitCode, exitSignal) => {
2384
+ exited = true;
2385
+ code = exitCode;
2386
+ signal = exitSignal;
2387
+ stopStartupCapture();
2388
+ });
2389
+ child.unref();
2390
+ return {
2391
+ pid: child.pid,
2392
+ getExitState: () => ({
2393
+ exited,
2394
+ code,
2395
+ signal,
2396
+ ...spawnError ? { spawnError } : {}
2397
+ }),
2398
+ readLogTail: (maxBytes = QUEUE_OWNER_STARTUP_STDERR_MAX_BYTES) => {
2399
+ const start = Math.max(0, stderrTail.length - maxBytes);
2400
+ return stderrTail.subarray(start).toString("utf8");
2401
+ },
2402
+ stopStartupCapture
2403
+ };
2330
2404
  }
2331
2405
  //#endregion
2332
2406
  //#region src/session/events.ts
@@ -3093,7 +3167,8 @@ async function runSessionPrompt(options) {
3093
3167
  const savePromptSuccess = async (response) => {
3094
3168
  await flushPendingMessages(false);
3095
3169
  output.flush();
3096
- record.lastUsedAt = isoNow();
3170
+ const now = isoNow();
3171
+ record.lastUsedAt = now;
3097
3172
  record.closed = false;
3098
3173
  record.closedAt = void 0;
3099
3174
  record.protocolVersion = client.initializeResult?.protocolVersion;
@@ -3282,7 +3357,7 @@ async function sendSessionDirect(options) {
3282
3357
  const QUEUE_OWNER_STARTUP_MAX_ATTEMPTS = 120;
3283
3358
  const QUEUE_OWNER_HEARTBEAT_INTERVAL_MS = 5e3;
3284
3359
  const QUEUE_OWNER_ACTIVE_TURN_CANCEL_GRACE_MS = 750;
3285
- async function submitToRunningOwner(options, waitForCompletion) {
3360
+ async function submitToRunningOwner(options, waitForCompletion, extras) {
3286
3361
  return await trySubmitToRunningOwner({
3287
3362
  sessionId: options.sessionId,
3288
3363
  message: promptToDisplayText(options.prompt),
@@ -3299,7 +3374,8 @@ async function submitToRunningOwner(options, waitForCompletion) {
3299
3374
  promptRetries: options.promptRetries,
3300
3375
  waitForCompletion,
3301
3376
  verbose: options.verbose,
3302
- sessionOptions: options.sessionOptions
3377
+ sessionOptions: options.sessionOptions,
3378
+ onQueueAccepted: extras?.onQueueAccepted
3303
3379
  });
3304
3380
  }
3305
3381
  function createQueueOwnerSharedClient(options, sessionRecord) {
@@ -3366,6 +3442,9 @@ function logDeferredCancelFailure(error, verbose) {
3366
3442
  if (!verbose) return;
3367
3443
  process.stderr.write(`[acpx] failed to apply deferred cancel: ${formatErrorMessage(error)}\n`);
3368
3444
  }
3445
+ function queueOwnerExitIsFatal(exit) {
3446
+ return exit.exited && (exit.spawnError !== void 0 || exit.code !== 0 || exit.signal !== null);
3447
+ }
3369
3448
  function logQueueOwnerReady(params) {
3370
3449
  if (!params.verbose) return;
3371
3450
  process.stderr.write(`[acpx] queue owner ready for session ${params.sessionId} (ttlMs=${params.ttlMs}, maxQueueDepth=${params.maxQueueDepth})\n`);
@@ -3602,14 +3681,42 @@ async function sendSession(options) {
3602
3681
  const waitForCompletion = options.waitForCompletion !== false;
3603
3682
  const queuedToOwner = await submitToRunningOwner(options, waitForCompletion);
3604
3683
  if (queuedToOwner) return queuedToOwner;
3605
- spawnQueueOwnerProcess(queueOwnerRuntimeOptionsFromSend(options));
3684
+ const owner = spawnQueueOwnerProcess(queueOwnerRuntimeOptionsFromSend(options));
3685
+ const onQueueAccepted = () => {
3686
+ owner.stopStartupCapture();
3687
+ };
3606
3688
  for (let attempt = 0; attempt < QUEUE_OWNER_STARTUP_MAX_ATTEMPTS; attempt += 1) {
3607
- const queued = await submitToRunningOwner(options, waitForCompletion);
3608
- if (queued) return queued;
3689
+ const queued = await submitToRunningOwner(options, waitForCompletion, { onQueueAccepted });
3690
+ if (queued) {
3691
+ owner.stopStartupCapture();
3692
+ return queued;
3693
+ }
3694
+ const exit = owner.getExitState();
3695
+ if (queueOwnerExitIsFatal(exit)) {
3696
+ const message = formatQueueOwnerStartupFailure({
3697
+ sessionId: options.sessionId,
3698
+ exit,
3699
+ logTail: owner.readLogTail()
3700
+ });
3701
+ owner.stopStartupCapture();
3702
+ throw new Error(message);
3703
+ }
3609
3704
  await waitMs(50);
3610
3705
  }
3611
- throw new Error(`Session queue owner failed to start for session ${options.sessionId}`);
3706
+ const finalExit = owner.getExitState();
3707
+ const message = formatQueueOwnerStartupFailure({
3708
+ sessionId: options.sessionId,
3709
+ exit: finalExit.exited ? finalExit : {
3710
+ exited: false,
3711
+ code: null,
3712
+ signal: null
3713
+ },
3714
+ logTail: owner.readLogTail()
3715
+ });
3716
+ owner.stopStartupCapture();
3717
+ throw new Error(message);
3612
3718
  }
3719
+ const queueOwnerRuntimeTestInternals = { queueOwnerExitIsFatal };
3613
3720
  //#endregion
3614
3721
  //#region src/session/session.ts
3615
3722
  var session_exports = /* @__PURE__ */ __exportAll({
@@ -3632,6 +3739,7 @@ var session_exports = /* @__PURE__ */ __exportAll({
3632
3739
  mergeConnectedModelState: () => mergeConnectedModelState,
3633
3740
  normalizeQueueOwnerTtlMs: () => normalizeQueueOwnerTtlMs,
3634
3741
  pruneSessions: () => pruneSessions,
3742
+ queueOwnerRuntimeTestInternals: () => queueOwnerRuntimeTestInternals,
3635
3743
  runOnce: () => runOnce,
3636
3744
  runQueuedTask: () => runQueuedTask,
3637
3745
  runSessionQueueOwner: () => runSessionQueueOwner,
@@ -4590,4 +4698,4 @@ function createOutputFormatter(format, options = {}) {
4590
4698
  //#endregion
4591
4699
  export { runSessionQueueOwner as a, buildQueueOwnerArgOverride as c, createSessionWithClient as d, cancelSessionPrompt as f, __exportAll as g, isProcessAlive as h, session_exports as i, flushPerfMetricsCapture as l, DEFAULT_QUEUE_OWNER_TTL_MS as m, getTextErrorRemediationHints as n, runOnce as o, probeQueueOwnerHealth as p, output_exports as r, sendSessionDirect as s, createOutputFormatter as t, installPerfMetricsCapture as u };
4592
4700
 
4593
- //# sourceMappingURL=output-CjdF5rHk.js.map
4701
+ //# sourceMappingURL=output-fNqTAsFQ.js.map