chainlesschain 0.166.161 → 0.166.163

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 (48) hide show
  1. package/README.md +15 -3
  2. package/package.json +1 -1
  3. package/src/assets/linux-subreaper/linux-arm64/manifest.json +1 -1
  4. package/src/assets/linux-subreaper/linux-x64/manifest.json +1 -1
  5. package/src/command-help-index.json +1 -1
  6. package/src/commands/agenda.js +23 -2
  7. package/src/commands/agent.js +56 -21
  8. package/src/commands/ccron.js +1 -0
  9. package/src/commands/loop.js +34 -1
  10. package/src/commands/mcp.js +13 -3
  11. package/src/commands/plugin.js +10 -31
  12. package/src/commands/skill.js +31 -6
  13. package/src/commands/tasks.js +20 -2
  14. package/src/data/changelog.json +26 -0
  15. package/src/harness/background-task-command-runner.js +23 -25
  16. package/src/harness/prompt-compressor.js +10 -1
  17. package/src/lib/__tests__/provider-stream.test.js +16 -0
  18. package/src/lib/background-agent-supervisor.js +3 -0
  19. package/src/lib/chat-core.js +10 -3
  20. package/src/lib/coding-task-guidance.js +1 -0
  21. package/src/lib/context-memory-kernel/live-compaction.js +100 -19
  22. package/src/lib/cowork-cron.js +115 -31
  23. package/src/lib/install-command-policy.js +23 -0
  24. package/src/lib/json-schema-output.js +12 -31
  25. package/src/lib/loop.js +30 -11
  26. package/src/lib/lsp/__tests__/code-intelligence.integration.test.js +17 -15
  27. package/src/lib/plan-mode.js +16 -0
  28. package/src/lib/plugin-runtime/install.js +111 -67
  29. package/src/lib/process-execution-broker/index.js +19 -9
  30. package/src/lib/provider-stream.js +7 -3
  31. package/src/lib/public-ide-capability-manifest.js +88 -0
  32. package/src/lib/public-ide-capability-validation.js +24 -0
  33. package/src/lib/read-file-loop-guard.js +9 -1
  34. package/src/lib/repl-denials.js +11 -0
  35. package/src/lib/search-command.js +13 -2
  36. package/src/lib/secret-store.js +30 -5
  37. package/src/lib/session-plan-approval.js +11 -2
  38. package/src/lib/status-line.cjs +3 -2
  39. package/src/lib/stream-retry.js +20 -0
  40. package/src/lib/task-record.js +12 -1
  41. package/src/lib/text-file-search.js +7 -2
  42. package/src/repl/agent-repl.js +195 -33
  43. package/src/runtime/agent-core.js +44 -18
  44. package/src/runtime/coding-agent-contract-shared.cjs +4 -2
  45. package/src/runtime/headless-runner.js +61 -4
  46. package/src/runtime/headless-stream.js +86 -17
  47. package/src/runtime/provider-stream-state.js +3 -1
  48. package/src/workers/background-agent-worker.js +11 -10
@@ -286,12 +286,7 @@ const SINGLE_SUBSCHEMA_KEYWORDS = [
286
286
  "unevaluatedProperties",
287
287
  ];
288
288
 
289
- const ARRAY_SUBSCHEMA_KEYWORDS = [
290
- "allOf",
291
- "anyOf",
292
- "oneOf",
293
- "prefixItems",
294
- ];
289
+ const ARRAY_SUBSCHEMA_KEYWORDS = ["allOf", "anyOf", "oneOf", "prefixItems"];
295
290
 
296
291
  const MAP_SUBSCHEMA_KEYWORDS = [
297
292
  "$defs",
@@ -322,11 +317,7 @@ function resolveSchemaUri(reference, baseUri) {
322
317
  }
323
318
  }
324
319
 
325
- function scanSchemaDocument(
326
- schema,
327
- retrievalUri,
328
- { references, resources },
329
- ) {
320
+ function scanSchemaDocument(schema, retrievalUri, { references, resources }) {
330
321
  const seen = new Set();
331
322
 
332
323
  function visit(node, inheritedBase) {
@@ -547,8 +538,8 @@ async function fetchExternalSchema(
547
538
  const schema = parseExternalSchema(raw, uri);
548
539
  const bytes =
549
540
  Number.isFinite(response?.bytes) && response.bytes >= 0
550
- ? response.bytes
551
- : Buffer.byteLength(JSON.stringify(schema), "utf8");
541
+ ? response.bytes
542
+ : Buffer.byteLength(JSON.stringify(schema), "utf8");
552
543
  if (bytes > maxDocumentBytes) {
553
544
  throw new Error(
554
545
  `External JSON Schema "${uri}" exceeds ${maxDocumentBytes} bytes`,
@@ -556,9 +547,7 @@ async function fetchExternalSchema(
556
547
  }
557
548
  let retrievalUri = uri;
558
549
  if (responseEnvelope && response?.url) {
559
- retrievalUri = withoutFragment(
560
- resolveSchemaUri(String(response.url), uri),
561
- );
550
+ retrievalUri = withoutFragment(resolveSchemaUri(String(response.url), uri));
562
551
  const redirected = new URL(retrievalUri);
563
552
  const redirectPolicy = checkAllowed(retrievalUri, {
564
553
  allowedDomains,
@@ -584,11 +573,7 @@ async function fetchExternalSchema(
584
573
  * Remote references are HTTPS-only and use the shared DNS-rebinding/SSRF-safe
585
574
  * fetch path with bounded document count, bytes, redirects and timeout.
586
575
  */
587
- export async function loadSchemaFileWithRefs(
588
- fs,
589
- schemaFile,
590
- options = {},
591
- ) {
576
+ export async function loadSchemaFileWithRefs(fs, schemaFile, options = {}) {
592
577
  const schema = loadSchemaFile(fs, schemaFile);
593
578
  if (!schema || typeof schema !== "object") return schema;
594
579
 
@@ -605,16 +590,13 @@ export async function loadSchemaFileWithRefs(
605
590
  const allowedDomains = Array.isArray(options.allowedDomains)
606
591
  ? options.allowedDomains
607
592
  : ["*"];
608
- const maxDocuments =
609
- options.maxDocuments ?? DEFAULT_MAX_EXTERNAL_DOCUMENTS;
593
+ const maxDocuments = options.maxDocuments ?? DEFAULT_MAX_EXTERNAL_DOCUMENTS;
610
594
  const maxDocumentBytes =
611
595
  options.maxDocumentBytes ?? DEFAULT_MAX_EXTERNAL_DOCUMENT_BYTES;
612
596
  const maxTotalBytes =
613
597
  options.maxTotalBytes ?? DEFAULT_MAX_EXTERNAL_TOTAL_BYTES;
614
- const timeoutMs =
615
- options.timeoutMs ?? DEFAULT_EXTERNAL_TIMEOUT_MS;
616
- const fetchSchema =
617
- options.fetchSchema || _deps.webFetch;
598
+ const timeoutMs = options.timeoutMs ?? DEFAULT_EXTERNAL_TIMEOUT_MS;
599
+ const fetchSchema = options.fetchSchema || _deps.webFetch;
618
600
 
619
601
  const references = new Map();
620
602
  const resources = new Set();
@@ -626,8 +608,7 @@ export async function loadSchemaFileWithRefs(
626
608
 
627
609
  while (true) {
628
610
  const uri = [...references.keys()].find(
629
- (candidate) =>
630
- !resources.has(candidate) && !fetched.has(candidate),
611
+ (candidate) => !resources.has(candidate) && !fetched.has(candidate),
631
612
  );
632
613
  if (!uri) break;
633
614
  if (fetched.size >= maxDocuments) {
@@ -655,8 +636,7 @@ export async function loadSchemaFileWithRefs(
655
636
  );
656
637
  }
657
638
  assertExternalSchemaIsValid(loaded.schema, uri);
658
- const redirected =
659
- loaded.retrievalUri && loaded.retrievalUri !== uri;
639
+ const redirected = loaded.retrievalUri && loaded.retrievalUri !== uri;
660
640
  if (redirected) {
661
641
  registry[loaded.retrievalUri] = loaded.schema;
662
642
  registry[uri] = { $ref: loaded.retrievalUri };
@@ -726,6 +706,7 @@ export async function runJsonSchemaConstrained(cfg = {}) {
726
706
  writeErr,
727
707
  },
728
708
  );
709
+ if (outcome?.exitCode) return outcome.exitCode;
729
710
  const raw =
730
711
  String(outcome?.result ?? captured ?? "").trim() || captured.trim();
731
712
  lastRaw = raw;
package/src/lib/loop.js CHANGED
@@ -13,6 +13,7 @@
13
13
 
14
14
  /** Multipliers for the duration suffixes we accept. */
15
15
  const DURATION_UNITS = { ms: 1, s: 1000, m: 60000, h: 3600000 };
16
+ const MAX_TIMER_DELAY_MS = 2_147_483_647;
16
17
 
17
18
  /**
18
19
  * Parse a human interval ("30s", "5m", "1.5h", "500ms") into milliseconds.
@@ -169,17 +170,22 @@ export function makeSleep(signal) {
169
170
  clearTimeout(t);
170
171
  resolve();
171
172
  };
172
- t = setTimeout(() => {
173
- // Normal completion: drop the abort listener so it can't accumulate on
174
- // a shared signal across rounds. A long `cc loop` reuses one
175
- // AbortController for the whole run, and `{once:true}` only removes the
176
- // listener if it FIRES — a sleep that completes normally never aborts,
177
- // so without this each round would leak a dangling listener (N rounds →
178
- // N retained closures + a MaxListenersExceededWarning past 10).
179
- signal?.removeEventListener("abort", onAbort);
180
- resolve();
181
- }, ms);
173
+ let remaining = ms;
174
+ const wait = () => {
175
+ const chunk = Math.min(remaining, MAX_TIMER_DELAY_MS);
176
+ t = setTimeout(() => {
177
+ remaining -= chunk;
178
+ if (remaining > 0) {
179
+ wait();
180
+ return;
181
+ }
182
+ // A normally completed round must release its abort listener.
183
+ signal?.removeEventListener("abort", onAbort);
184
+ resolve();
185
+ }, chunk);
186
+ };
182
187
  signal?.addEventListener("abort", onAbort, { once: true });
188
+ wait();
183
189
  });
184
190
  }
185
191
 
@@ -192,11 +198,14 @@ export function makeSleep(signal) {
192
198
  * @param {(n:number)=>Promise<{exitCode?:number, output?:string}>} opts.runIteration
193
199
  * @param {number} opts.intervalMs default delay between iterations (>= 0)
194
200
  * @param {number} [opts.maxIterations] stop after N rounds (>= 1)
201
+ * @param {number|null} [opts.endsAt] epoch-ms deadline for dispatching rounds
195
202
  * @param {boolean} [opts.untilExitZero] stop once a round exits with code 0
196
203
  * @param {RegExp} [opts.untilRegex] stop once a round's output matches
197
204
  * @param {(ms:number)=>Promise<void>} [opts.sleep] injectable delay
198
205
  * @param {()=>boolean} [opts.shouldStop] external stop probe (e.g. SIGINT)
199
206
  * @param {(n:number, res:object)=>void} [opts.onIteration] per-round hook
207
+ * @param {(nextRunAt:number|null)=>void} [opts.onWait] next eligible dispatch
208
+ * @param {()=>number} [opts.now] injectable clock
200
209
  * @param {number} [opts.startIndex] iterations already done (resume)
201
210
  * @returns {Promise<{iterations:number, stoppedBy:string, results:object[]}>}
202
211
  * `iterations` is cumulative (startIndex + rounds run this call);
@@ -206,11 +215,14 @@ export async function runLoop({
206
215
  runIteration,
207
216
  intervalMs,
208
217
  maxIterations,
218
+ endsAt = null,
209
219
  untilExitZero = false,
210
220
  untilRegex = null,
211
221
  sleep,
212
222
  shouldStop,
213
223
  onIteration,
224
+ onWait,
225
+ now = Date.now,
214
226
  startIndex = 0,
215
227
  }) {
216
228
  if (typeof runIteration !== "function") {
@@ -227,6 +239,9 @@ export async function runLoop({
227
239
  if (shouldStop && shouldStop()) {
228
240
  return { iterations: i, stoppedBy: "signal", results };
229
241
  }
242
+ if (endsAt != null && now() >= endsAt) {
243
+ return { iterations: i, stoppedBy: "expired", results };
244
+ }
230
245
 
231
246
  i += 1;
232
247
  const res = (await runIteration(i)) || {};
@@ -261,6 +276,10 @@ export async function runLoop({
261
276
  const nextMs = Number.isFinite(res.nextDelayMs)
262
277
  ? res.nextDelayMs
263
278
  : intervalMs;
264
- await delay(nextMs);
279
+ const waitingSince = now();
280
+ const nextRunAt = waitingSince + nextMs;
281
+ const wakeAt = endsAt == null ? nextRunAt : Math.min(nextRunAt, endsAt);
282
+ onWait?.(endsAt == null || nextRunAt < endsAt ? nextRunAt : null);
283
+ await delay(Math.max(0, wakeAt - waitingSince));
265
284
  }
266
285
  }
@@ -20,7 +20,7 @@ const suite = serverAvailable ? describe : describe.skip;
20
20
 
21
21
  if (!serverAvailable) {
22
22
  // Make the skip reason obvious in test output.
23
- // eslint-disable-next-line no-console
23
+
24
24
  console.warn(
25
25
  "[lsp.integration] SKIP — no `typescript-language-server` on PATH. " +
26
26
  "Install it to run real LSP integration coverage.",
@@ -74,21 +74,23 @@ suite("CodeIntelligence against a real typescript-language-server", () => {
74
74
  }
75
75
  });
76
76
 
77
- it("resolves a cross-file definition", async () => {
78
- // `add` usage in main.ts (line 3, col 15) → declaration in math.ts
79
- const res = await ci.definition(path.join(tmp, "src", "main.ts"), 3, 15);
80
- expect(res.available).toBe(true);
81
- expect(res.locations.length).toBeGreaterThan(0);
82
- expect(res.locations.some((l) => l.file.endsWith("math.ts"))).toBe(true);
83
- }, 30000);
77
+ it("serves simultaneous definition and references queries on cold start", async () => {
78
+ const main = path.join(tmp, "src", "main.ts");
79
+ const math = path.join(tmp, "src", "math.ts");
80
+ const [definition, references] = await Promise.all([
81
+ ci.definition(main, 3, 15),
82
+ ci.references(math, 1, 17),
83
+ ]);
84
84
 
85
- it("finds all references to a symbol across files", async () => {
86
- // `add` declaration in math.ts (line 1, col 17)
87
- const res = await ci.references(path.join(tmp, "src", "math.ts"), 1, 17);
88
- expect(res.available).toBe(true);
89
- // declaration + import + call site
90
- expect(res.locations.length).toBeGreaterThanOrEqual(2);
91
- expect(res.locations.some((l) => l.file.endsWith("main.ts"))).toBe(true);
85
+ expect(definition.available).toBe(true);
86
+ expect(
87
+ definition.locations.map((item) => path.basename(item.file)),
88
+ ).toContain("math.ts");
89
+ expect(references.available).toBe(true);
90
+ expect(references.locations.length).toBeGreaterThanOrEqual(2);
91
+ expect(
92
+ references.locations.map((item) => path.basename(item.file)),
93
+ ).toContain("main.ts");
92
94
  }, 30000);
93
95
 
94
96
  it("reports diagnostics for an undefined name", async () => {
@@ -8,6 +8,7 @@
8
8
  */
9
9
 
10
10
  import { EventEmitter } from "events";
11
+ import { isDeepStrictEqual } from "node:util";
11
12
  import {
12
13
  createPlanSessionEvent,
13
14
  PLAN_PERSISTENCE_ERROR_CODES,
@@ -1234,6 +1235,21 @@ export class PlanModeManager extends EventEmitter {
1234
1235
  };
1235
1236
  }
1236
1237
 
1238
+ /** Enforce the parameters covered by a durable session approval. */
1239
+ allowsApprovedToolArgs(toolName, args) {
1240
+ if (!this.sessionId || !this.executionLock || READ_TOOLS.has(toolName))
1241
+ return true;
1242
+
1243
+ const item = this.currentPlan?.items.find(
1244
+ (candidate) =>
1245
+ candidate.tool === toolName &&
1246
+ this.executionLock.approvedItemIds.includes(candidate.id) &&
1247
+ (candidate.status === PlanStatus.APPROVED ||
1248
+ candidate.status === PlanStatus.EXECUTING),
1249
+ );
1250
+ return Boolean(item && isDeepStrictEqual(item.params, args));
1251
+ }
1252
+
1237
1253
  /**
1238
1254
  * Attribute a live tool call to the next approved item for that tool.
1239
1255
  * Read-only/helper calls that were not part of the approved plan remain
@@ -51,6 +51,7 @@ import {
51
51
  redactPluginSourceForDisplay,
52
52
  } from "../plugin-source-identity.js";
53
53
  import { assertRegistryResolutionAuthority } from "./remote-source.js";
54
+ import { normalizeInstallCommandResult } from "../install-command-policy.js";
54
55
  import {
55
56
  writePluginLock,
56
57
  buildPluginSbom,
@@ -794,10 +795,18 @@ function _withMaterializedSource(source, fn, opts = {}) {
794
795
  }
795
796
  return result;
796
797
  }
797
- const cloned = fetchGitRepo(git.url, git.ref, { cwd: opts.cwd });
798
+ let cloned;
799
+ let installCommand;
798
800
  try {
801
+ cloned = fetchGitRepo(git.url, git.ref, {
802
+ cwd: opts.cwd,
803
+ onInstallCommand(receipt) {
804
+ installCommand = receipt;
805
+ },
806
+ });
799
807
  const result = fn(cloned, git);
800
808
  if (result && typeof result === "object") {
809
+ if (installCommand) result.installCommand = installCommand;
801
810
  try {
802
811
  const cached = publishMarketplaceSourceCache(
803
812
  cloned,
@@ -816,9 +825,13 @@ function _withMaterializedSource(source, fn, opts = {}) {
816
825
  }
817
826
  }
818
827
  return result;
828
+ } catch (error) {
829
+ if (installCommand) error.installCommand = installCommand;
830
+ throw error;
819
831
  } finally {
820
832
  try {
821
- _deps.rmSync(path.dirname(cloned), { recursive: true, force: true });
833
+ if (cloned)
834
+ _deps.rmSync(path.dirname(cloned), { recursive: true, force: true });
822
835
  } catch {
823
836
  /* temp cleanup is best-effort */
824
837
  }
@@ -1987,13 +2000,17 @@ export function fetchGitRepo(url, ref, options = {}) {
1987
2000
  const executable = resolveTrustedGitExecutable(cwd);
1988
2001
  const base = _deps.mkdtempSync(path.join(os.tmpdir(), "cc-plugin-git-"));
1989
2002
  const dir = path.join(base, "repo");
2003
+ const stderrHash = crypto.createHash("sha256");
2004
+ let printedToStderr = false;
2005
+ let ran = false;
2006
+ let lastProcess;
1990
2007
  const run = (args) => {
1991
2008
  const hardenedArgs = hardenedPluginGitArgs(args, { url, cwd });
1992
2009
  const auditRedactArgIndexes = hardenedArgs.flatMap((argument, index) =>
1993
2010
  argument === url || (ref != null && argument === ref) ? [index] : [],
1994
2011
  );
1995
2012
  try {
1996
- return _deps.spawnSync(executable, hardenedArgs, {
2013
+ lastProcess = _deps.spawnSync(executable, hardenedArgs, {
1997
2014
  cwd: base,
1998
2015
  encoding: "utf8",
1999
2016
  env: hardenedPluginGitEnvironment(),
@@ -2006,8 +2023,16 @@ export function fetchGitRepo(url, ref, options = {}) {
2006
2023
  auditRedactArgIndexes,
2007
2024
  });
2008
2025
  } catch (error) {
2009
- return { error, status: null, stdout: "", stderr: "" };
2026
+ lastProcess = { error, status: null, stdout: "", stderr: "" };
2010
2027
  }
2028
+ if (lastProcess.stderr?.length) {
2029
+ printedToStderr = true;
2030
+ stderrHash.update(lastProcess.stderr);
2031
+ }
2032
+ ran ||= Boolean(
2033
+ lastProcess.pid || lastProcess.signal || lastProcess.status != null,
2034
+ );
2035
+ return lastProcess;
2011
2036
  };
2012
2037
 
2013
2038
  // Reduce host-specific checkout differences before the v2 inventory hashes
@@ -2027,35 +2052,56 @@ export function fetchGitRepo(url, ref, options = {}) {
2027
2052
  const cloneArgs = [...canonicalCheckoutArgs, "clone", "--depth", "1"];
2028
2053
  if (ref) cloneArgs.push("--branch", ref);
2029
2054
  cloneArgs.push(url, dir);
2030
- let res = run(cloneArgs);
2031
- if (res.error && res.error.code === "ENOENT") {
2032
- throw new Error("git is not installed (needed to fetch a remote plugin)");
2033
- }
2034
- if (res.error) {
2035
- throw new Error(
2036
- `git process failed for ${redactPluginSourceForDisplay(url)}`,
2037
- );
2038
- }
2039
- if (res.status !== 0) {
2040
- // A commit SHA can't be used with --branch/--depth; retry with a full clone
2041
- // then checkout the ref explicitly.
2042
- if (ref) {
2043
- try {
2044
- _deps.rmSync(dir, { recursive: true, force: true });
2045
- } catch {
2046
- /* ignore */
2047
- }
2048
- const full = run([...canonicalCheckoutArgs, "clone", url, dir]);
2049
- if (!full.error && full.status === 0) {
2050
- const co = run([...canonicalCheckoutArgs, "-C", dir, "checkout", ref]);
2051
- if (co.status === 0) return dir;
2055
+ try {
2056
+ const res = run(cloneArgs);
2057
+ if (res.error?.code === "ENOENT") {
2058
+ throw new Error("git is not installed (needed to fetch a remote plugin)");
2059
+ }
2060
+ if (res.error) {
2061
+ throw new Error(
2062
+ `git process failed for ${redactPluginSourceForDisplay(url)}`,
2063
+ );
2064
+ }
2065
+ if (res.status !== 0) {
2066
+ // A commit SHA can't be used with --branch/--depth; retry with a full clone
2067
+ // then checkout the ref explicitly.
2068
+ if (ref) {
2069
+ try {
2070
+ _deps.rmSync(dir, { recursive: true, force: true });
2071
+ } catch {
2072
+ /* ignore */
2073
+ }
2074
+ const full = run([...canonicalCheckoutArgs, "clone", url, dir]);
2075
+ if (!full.error && full.status === 0) {
2076
+ const co = run([
2077
+ ...canonicalCheckoutArgs,
2078
+ "-C",
2079
+ dir,
2080
+ "checkout",
2081
+ ref,
2082
+ ]);
2083
+ if (!co.error && co.status === 0) return dir;
2084
+ }
2052
2085
  }
2086
+ throw new Error(
2087
+ `git clone failed for ${redactPluginSourceForDisplay(url)} (git exited ${lastProcess.status})`,
2088
+ );
2089
+ }
2090
+ return dir;
2091
+ } finally {
2092
+ if (lastProcess) {
2093
+ options.onInstallCommand?.(
2094
+ normalizeInstallCommandResult({
2095
+ ran,
2096
+ exitCode: lastProcess.status,
2097
+ timedOut: lastProcess.error?.code === "ETIMEDOUT",
2098
+ signal: lastProcess.signal,
2099
+ printedToStderr,
2100
+ stderrDigest: stderrHash.digest("hex"),
2101
+ }),
2102
+ );
2053
2103
  }
2054
- throw new Error(
2055
- `git clone failed for ${redactPluginSourceForDisplay(url)} (git exited ${res.status})`,
2056
- );
2057
2104
  }
2058
- return dir;
2059
2105
  }
2060
2106
 
2061
2107
  /**
@@ -3390,17 +3436,17 @@ function sameSourceAuthority(current, candidate) {
3390
3436
  if (current.type === "registry") {
3391
3437
  return Boolean(
3392
3438
  current.sourceDigest &&
3393
- candidate.sourceDigest &&
3394
- current.sourceDigest === candidate.sourceDigest &&
3395
- current.resolvedSourceDigest &&
3396
- candidate.resolvedSourceDigest &&
3397
- current.resolvedSourceDigest === candidate.resolvedSourceDigest,
3439
+ candidate.sourceDigest &&
3440
+ current.sourceDigest === candidate.sourceDigest &&
3441
+ current.resolvedSourceDigest &&
3442
+ candidate.resolvedSourceDigest &&
3443
+ current.resolvedSourceDigest === candidate.resolvedSourceDigest,
3398
3444
  );
3399
3445
  }
3400
3446
  return Boolean(
3401
3447
  current.sourceDigest &&
3402
- candidate.sourceDigest &&
3403
- current.sourceDigest === candidate.sourceDigest,
3448
+ candidate.sourceDigest &&
3449
+ current.sourceDigest === candidate.sourceDigest,
3404
3450
  );
3405
3451
  }
3406
3452
 
@@ -3996,8 +4042,8 @@ function assertCatalogRemoteArtifactBindings(metadata) {
3996
4042
  const expectedSignature = expectations.signature || {};
3997
4043
  const expectsRemoteSignature = Boolean(
3998
4044
  expectedSignature.url &&
3999
- expectedSignature.publicKeyUrl &&
4000
- expectedSignature.publicKeySha256,
4045
+ expectedSignature.publicKeyUrl &&
4046
+ expectedSignature.publicKeySha256,
4001
4047
  );
4002
4048
  if (expectsRemoteSignature !== Boolean(evidence.signature)) {
4003
4049
  throw new Error(
@@ -5626,9 +5672,9 @@ function samePointerState(left, right) {
5626
5672
  if (!left.present) return true;
5627
5673
  return Boolean(
5628
5674
  Buffer.isBuffer(left.bytes) &&
5629
- Buffer.isBuffer(right.bytes) &&
5630
- left.bytes.equals(right.bytes) &&
5631
- sameFileGeneration(left.generation, right.generation),
5675
+ Buffer.isBuffer(right.bytes) &&
5676
+ left.bytes.equals(right.bytes) &&
5677
+ sameFileGeneration(left.generation, right.generation),
5632
5678
  );
5633
5679
  }
5634
5680
 
@@ -5666,9 +5712,9 @@ function sameLifecycleFileState(left, right) {
5666
5712
  if (!left.present) return true;
5667
5713
  return Boolean(
5668
5714
  Buffer.isBuffer(left.bytes) &&
5669
- Buffer.isBuffer(right.bytes) &&
5670
- left.bytes.equals(right.bytes) &&
5671
- sameFileGeneration(left.generation, right.generation),
5715
+ Buffer.isBuffer(right.bytes) &&
5716
+ left.bytes.equals(right.bytes) &&
5717
+ sameFileGeneration(left.generation, right.generation),
5672
5718
  );
5673
5719
  }
5674
5720
 
@@ -5716,11 +5762,11 @@ function serializePluginNameState(state) {
5716
5762
  function samePluginNameState(left, right) {
5717
5763
  return Boolean(
5718
5764
  left &&
5719
- right &&
5720
- sameFileGeneration(left.generation, right.generation) &&
5721
- left.payloadDigest === right.payloadDigest &&
5722
- left.fileCount === right.fileCount &&
5723
- left.totalBytes === right.totalBytes,
5765
+ right &&
5766
+ sameFileGeneration(left.generation, right.generation) &&
5767
+ left.payloadDigest === right.payloadDigest &&
5768
+ left.fileCount === right.fileCount &&
5769
+ left.totalBytes === right.totalBytes,
5724
5770
  );
5725
5771
  }
5726
5772
 
@@ -5743,8 +5789,8 @@ function lifecycleFileContentMatches(left, right) {
5743
5789
  if (!left.present) return true;
5744
5790
  return Boolean(
5745
5791
  Buffer.isBuffer(left.bytes) &&
5746
- Buffer.isBuffer(right.bytes) &&
5747
- left.bytes.equals(right.bytes),
5792
+ Buffer.isBuffer(right.bytes) &&
5793
+ left.bytes.equals(right.bytes),
5748
5794
  );
5749
5795
  }
5750
5796
 
@@ -5810,9 +5856,7 @@ function hasRetainedLifecycleRecovery(nameDir) {
5810
5856
  function authoritativeTransactionCleanupPending(cleanup) {
5811
5857
  return Boolean(
5812
5858
  cleanup?.cleanupPending === true &&
5813
- /^\.(?:install|uninstall)-/u.test(
5814
- path.basename(cleanup.cleanupPath || ""),
5815
- ),
5859
+ /^\.(?:install|uninstall)-/u.test(path.basename(cleanup.cleanupPath || "")),
5816
5860
  );
5817
5861
  }
5818
5862
 
@@ -5902,22 +5946,22 @@ function fileGeneration(stat) {
5902
5946
  function sameFileGeneration(left, right) {
5903
5947
  return Boolean(
5904
5948
  left &&
5905
- right &&
5906
- left.dev === right.dev &&
5907
- left.ino === right.ino &&
5908
- left.birthtimeMs === right.birthtimeMs &&
5909
- left.mtimeMs === right.mtimeMs &&
5910
- left.size === right.size,
5949
+ right &&
5950
+ left.dev === right.dev &&
5951
+ left.ino === right.ino &&
5952
+ left.birthtimeMs === right.birthtimeMs &&
5953
+ left.mtimeMs === right.mtimeMs &&
5954
+ left.size === right.size,
5911
5955
  );
5912
5956
  }
5913
5957
 
5914
5958
  function sameInstalledVersionState(left, right) {
5915
5959
  return Boolean(
5916
5960
  left &&
5917
- right &&
5918
- sameFileGeneration(left.generation, right.generation) &&
5919
- left.payloadDigest === right.payloadDigest &&
5920
- left.sourceDigest === right.sourceDigest,
5961
+ right &&
5962
+ sameFileGeneration(left.generation, right.generation) &&
5963
+ left.payloadDigest === right.payloadDigest &&
5964
+ left.sourceDigest === right.sourceDigest,
5921
5965
  );
5922
5966
  }
5923
5967
 
@@ -5999,8 +6043,8 @@ function activePointerMatchesSnapshot(transaction) {
5999
6043
  if (!snapshot.present) return true;
6000
6044
  return Boolean(
6001
6045
  Buffer.isBuffer(current.bytes) &&
6002
- Buffer.isBuffer(snapshot.bytes) &&
6003
- current.bytes.equals(snapshot.bytes),
6046
+ Buffer.isBuffer(snapshot.bytes) &&
6047
+ current.bytes.equals(snapshot.bytes),
6004
6048
  );
6005
6049
  }
6006
6050
 
@@ -5753,17 +5753,27 @@ class ProcessExecutionBroker extends EventEmitter {
5753
5753
  const cb = typeof options === "function" ? options : callback;
5754
5754
  if (this._requiresExplicitLinuxWorkspaceShell(opts.cwd || process.cwd())) {
5755
5755
  const invocation = this._explicitLinuxShellInvocation(command, opts);
5756
- return this.spawn(invocation.command, invocation.args, {
5756
+ return this.execFile(
5757
+ invocation.command,
5758
+ invocation.args,
5759
+ {
5760
+ ...opts,
5761
+ shell: false,
5762
+ origin: opts.origin || "shell:exec",
5763
+ },
5764
+ cb,
5765
+ );
5766
+ }
5767
+ return this.execFile(
5768
+ command,
5769
+ [],
5770
+ {
5757
5771
  ...opts,
5758
- shell: false,
5772
+ shell: true,
5759
5773
  origin: opts.origin || "shell:exec",
5760
- });
5761
- }
5762
- return this.spawn(command, [], {
5763
- ...opts,
5764
- shell: true,
5765
- origin: opts.origin || "shell:exec",
5766
- });
5774
+ },
5775
+ cb,
5776
+ );
5767
5777
  }
5768
5778
 
5769
5779
  execSync(command, options = {}) {
@@ -11,6 +11,10 @@ import {
11
11
  import { resolveProviderDefinition } from "./llm-providers.js";
12
12
  import { normalizeOllamaBaseUrl } from "./ollama-base-url.js";
13
13
  import { ollamaProviderFetch } from "./ollama-provider-fetch.js";
14
+ import {
15
+ CHAT_COMPLETIONS_STREAM_FAILED,
16
+ createChatCompletionsStreamError,
17
+ } from "./stream-retry.js";
14
18
  import {
15
19
  assertCustomProviderConnection,
16
20
  geminiGenerateContentUrl,
@@ -139,12 +143,12 @@ export async function* openAIStream({
139
143
  }
140
144
  try {
141
145
  const obj = JSON.parse(payload);
142
- if (requireCompletion && obj.error)
143
- throw new Error("OpenAI stream returned an error");
146
+ if (obj?.error) throw createChatCompletionsStreamError();
144
147
  const delta = obj?.choices?.[0]?.delta?.content;
145
148
  if (delta) yield delta;
146
149
  } catch (error) {
147
- if (requireCompletion) throw error;
150
+ if (requireCompletion || error?.code === CHAT_COMPLETIONS_STREAM_FAILED)
151
+ throw error;
148
152
  /* skip */
149
153
  }
150
154
  }