@sayknow-cli/coding-agent 0.7.8 → 0.7.9

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/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.7.9] - 2026-10-17
6
+
7
+ ### Fixed
8
+
9
+ - The stream-stall hint now suggests an idle timeout longer than the one that fired (twice the larger of the configured override and the longest built-in window). It previously suggested `PI_STREAM_IDLE_TIMEOUT_MS=300000`, which equals Anthropic's built-in window and changed nothing.
10
+ - Managed fallback now treats Z.AI error `1113` (insufficient balance or no resource package) as exhausted quota and advances after one upstream request instead of retrying the same model until the step budget is spent.
11
+ - After compaction or another Codex history rewrite, the first WebSocket request now starts from a fresh provider-visible baseline instead of inheriting stale connection context and eventually failing with `context_length_exceeded`.
12
+ - Session storage on macOS accepts paths named through OS-owned links such as `/var` → `/private/var` and `/tmp` → `/private/tmp`. Managed roots are canonical, so a session or agent directory under the system temp dir was rejected as `Managed path escapes configured root` or `Unsafe reparse storage path`. Only root-owned links in root-owned, non-world-writable directories are exempt; user-created links anywhere in the path are still refused.
13
+
5
14
  ## [0.7.8] - 2026-10-09
6
15
 
7
16
  ### Fixed
@@ -1,3 +1,4 @@
1
+ import * as fs from "node:fs";
1
2
  import { type NativeDirectoryTreeSnapshot, type NativeOwnerOnlySecurityResult, type RecoveryFsRoot } from "@sayknow-cli/natives";
2
3
  import { type NativePublishOutcome } from "./native-publish-outcome";
3
4
  export declare const MANAGED_ARTIFACT_MAX_DEPTH = 32;
@@ -51,6 +52,13 @@ export declare function retainManagedDirectoryAuthority(root: ManagedDirectoryRo
51
52
  ino: bigint;
52
53
  }): RecoveryFsRoot | undefined;
53
54
  export declare function assertManagedDirectoryRoot(root: ManagedDirectoryRoot): void;
55
+ /**
56
+ * A root-owned link inside a root-owned directory that nobody else can write (macOS `/var`
57
+ * and `/tmp`, merged-usr `/bin`) is OS layout: replacing it already requires root. Windows
58
+ * reports uid 0 for every file, so the exemption is POSIX-only.
59
+ * @internal
60
+ */
61
+ export declare function isTrustedSystemLink(linkPath: string, linkStat: fs.Stats): boolean;
54
62
  /** Internal retained-root capability for one managed descendant subtree. */
55
63
  export declare class ManagedSessionDescendantStore {
56
64
  #private;
@@ -269,6 +269,10 @@ export type NativeDirectoryTreeSnapshot = {
269
269
  rootIno: string;
270
270
  entries: NativeDirectoryTreeEntry[];
271
271
  };
272
+ /** Reject a symlink/junction/reparse component before a storage path is created or opened. */
273
+ declare function assertNoReparsePath(pathname: string): void;
274
+ /** @internal Exported for tests. */
275
+ export { assertNoReparsePath as assertNoReparseStoragePath };
272
276
  export declare class FileSessionStorage implements SessionStorage {
273
277
  #private;
274
278
  ensureDirSync(dir: string): void;
@@ -342,4 +346,3 @@ export declare class MemorySessionStorage implements SessionStorage {
342
346
  deleteSessionVerified(target: VerifiedSessionDeleteTarget): Promise<VerifiedSessionDeleteResult>;
343
347
  openWriter(path: string, options?: SessionStorageWriterOpenOptions): SessionStorageWriter;
344
348
  }
345
- export {};
@@ -28,7 +28,7 @@ export interface TmuxLaunchContext {
28
28
  }
29
29
  export interface TmuxSpawnResult {
30
30
  exitCode: number | null;
31
- signalCode?: string | null;
31
+ signalCode?: NodeJS.Signals | number | null;
32
32
  stderr?: string;
33
33
  /** Populated only when the caller asked for `stdout: "pipe"`. */
34
34
  stdout?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@sayknow-cli/coding-agent",
4
- "version": "0.7.8",
4
+ "version": "0.7.9",
5
5
  "description": "Sayknow-CLI CLI with read, bash, edit, write tools and session management",
6
6
  "homepage": "https://sayknow-cli.com",
7
7
  "author": "jaybeyond",
@@ -54,12 +54,12 @@
54
54
  "@agentclientprotocol/sdk": "1.3.0",
55
55
  "@babel/parser": "^7.29.3",
56
56
  "@mozilla/readability": "^0.6.0",
57
- "@sayknow-cli/stats": "0.7.8",
58
- "@sayknow-cli/agent-core": "0.7.8",
59
- "@sayknow-cli/ai": "0.7.8",
60
- "@sayknow-cli/natives": "0.7.8",
61
- "@sayknow-cli/tui": "0.7.8",
62
- "@sayknow-cli/utils": "0.7.8",
57
+ "@sayknow-cli/stats": "0.7.9",
58
+ "@sayknow-cli/agent-core": "0.7.9",
59
+ "@sayknow-cli/ai": "0.7.9",
60
+ "@sayknow-cli/natives": "0.7.9",
61
+ "@sayknow-cli/tui": "0.7.9",
62
+ "@sayknow-cli/utils": "0.7.9",
63
63
  "@puppeteer/browsers": "^2.13.0",
64
64
  "@types/turndown": "5.0.6",
65
65
  "@xterm/headless": "^6.0.0",
@@ -1,3 +1,5 @@
1
+ import { getStreamIdleTimeoutRemediationMs } from "@sayknow-cli/ai/utils/idle-iterator";
2
+
1
3
  const STREAM_IDLE_TIMEOUT_PATTERN = /\bstream stalled while waiting for the next event\b/i;
2
4
  const GENERIC_ABORT_PATTERN = /^Request was aborted\.?$/i;
3
5
  const ABORT_DISPLAY_LABEL_PATTERN = /^(?:Operation aborted|Aborted after \d+ retry attempts?)(?::|$)/;
@@ -37,5 +39,5 @@ function normalizeAbortCause(errorMessage: string | undefined): string {
37
39
  function streamIdleTimeoutHint(cause: string): string {
38
40
  if (!STREAM_IDLE_TIMEOUT_PATTERN.test(cause)) return "";
39
41
  const separator = /[.!?]$/.test(cause) ? " " : ". ";
40
- return `${separator}Hint: set PI_STREAM_IDLE_TIMEOUT_MS=300000 for slow reasoning/proxy streams, or PI_STREAM_IDLE_TIMEOUT_MS=0 to disable the watchdog.`;
42
+ return `${separator}Hint: set PI_STREAM_IDLE_TIMEOUT_MS=${getStreamIdleTimeoutRemediationMs()} for slow reasoning/proxy streams, or PI_STREAM_IDLE_TIMEOUT_MS=0 to disable the watchdog.`;
41
43
  }
@@ -12781,9 +12781,23 @@ export class AgentSession {
12781
12781
  }
12782
12782
 
12783
12783
  #closeCodexProviderSessionsForHistoryRewrite(): void {
12784
- const currentModel = this.model;
12785
- if (currentModel?.api !== "openai-codex-responses") return;
12786
- this.#closeProviderSessionsForModelSwitch(currentModel, currentModel);
12784
+ const providerKey = "openai-codex-responses";
12785
+ const maps = new Set<Map<string, ProviderSessionState>>([this.#providerSessionState]);
12786
+ if (this.agent.providerSessionState) maps.add(this.agent.providerSessionState);
12787
+ for (const scope of this.#temporaryProviderSessionScopes) maps.add(scope.providerSessionState);
12788
+ for (const providerSessionState of maps) {
12789
+ const state = providerSessionState.get(providerKey);
12790
+ if (!state) continue;
12791
+ try {
12792
+ state.close();
12793
+ } catch (error) {
12794
+ logger.warn("Failed to close Codex provider session state after history rewrite", {
12795
+ providerKey,
12796
+ error: String(error),
12797
+ });
12798
+ }
12799
+ providerSessionState.delete(providerKey);
12800
+ }
12787
12801
  }
12788
12802
 
12789
12803
  /**
@@ -319,7 +319,7 @@ export function retainManagedDirectoryAuthority(
319
319
  expected?: { dev: bigint; ino: bigint },
320
320
  ): RecoveryFsRoot | undefined {
321
321
  assertManagedDirectoryRoot(root);
322
- managedRelativePath(root, directory);
322
+ const components = managedRelativePath(root, directory);
323
323
  const resolved = path.resolve(directory);
324
324
  if (process.platform !== "linux") return undefined;
325
325
  const named = fs.lstatSync(resolved, { bigint: true });
@@ -336,7 +336,7 @@ export function retainManagedDirectoryAuthority(
336
336
  retainedRoot.identity.ino !== root.ino.toString()
337
337
  )
338
338
  throw new Error("Managed root authority changed");
339
- const relative = path.relative(root.canonicalPath, resolved).split(path.sep).join("/");
339
+ const relative = components.join("/");
340
340
  return rootAuthority.retainManagedDirectory(relative, named.dev.toString(), named.ino.toString());
341
341
  } finally {
342
342
  rootAuthority.close();
@@ -368,13 +368,70 @@ function ensureManagedRoot(root: ManagedDirectoryRoot): void {
368
368
  }
369
369
 
370
370
  function managedRelativePath(root: ManagedDirectoryRoot, pathname: string): readonly string[] {
371
- const relative = path.relative(root.canonicalPath, path.resolve(pathname));
371
+ const resolved = path.resolve(pathname);
372
+ const components = textualRelativePath(root.canonicalPath, resolved) ?? aliasedRelativePath(root, resolved);
373
+ if (components === undefined) throw new Error(`Managed path escapes configured root: ${pathname}`);
374
+ return components;
375
+ }
376
+
377
+ function textualRelativePath(rootPath: string, resolved: string): string[] | undefined {
378
+ const relative = path.relative(rootPath, resolved);
372
379
  if (relative === "") return [];
373
- if (path.isAbsolute(relative) || relative.split(path.sep).includes(".."))
374
- throw new Error(`Managed path escapes configured root: ${pathname}`);
380
+ if (path.isAbsolute(relative) || relative.split(path.sep).includes("..")) return undefined;
375
381
  return relative.split(path.sep);
376
382
  }
377
383
 
384
+ /**
385
+ * The root is canonical, but a caller may name it through an OS alias such as macOS
386
+ * `/var` -> `/private/var`. Find the textual ancestor that is the root directory itself
387
+ * (same device and inode, not a link) and accept it only when every link above it is OS
388
+ * layout. Components below it stay textual, so the per-component checks still reject any
389
+ * link inside the root.
390
+ */
391
+ function aliasedRelativePath(root: ManagedDirectoryRoot, resolved: string): string[] | undefined {
392
+ const below: string[] = [];
393
+ let current = resolved;
394
+ for (;;) {
395
+ try {
396
+ const stat = fs.lstatSync(current, { bigint: true });
397
+ if (stat.isDirectory() && stat.dev === root.dev && stat.ino === root.ino) {
398
+ return onlyTrustedSystemLinks(path.dirname(current)) ? below.reverse() : undefined;
399
+ }
400
+ } catch (error) {
401
+ const code = (error as NodeJS.ErrnoException).code;
402
+ if (code !== "ENOENT" && code !== "ENOTDIR") throw error;
403
+ }
404
+ const parent = path.dirname(current);
405
+ if (parent === current) return undefined;
406
+ below.push(path.basename(current));
407
+ current = parent;
408
+ }
409
+ }
410
+
411
+ function onlyTrustedSystemLinks(pathname: string): boolean {
412
+ const parsed = path.parse(pathname);
413
+ let current = parsed.root;
414
+ for (const part of pathname.slice(parsed.root.length).split(path.sep)) {
415
+ if (!part) continue;
416
+ current = path.join(current, part);
417
+ const stat = fs.lstatSync(current);
418
+ if (stat.isSymbolicLink() && !isTrustedSystemLink(current, stat)) return false;
419
+ }
420
+ return true;
421
+ }
422
+
423
+ /**
424
+ * A root-owned link inside a root-owned directory that nobody else can write (macOS `/var`
425
+ * and `/tmp`, merged-usr `/bin`) is OS layout: replacing it already requires root. Windows
426
+ * reports uid 0 for every file, so the exemption is POSIX-only.
427
+ * @internal
428
+ */
429
+ export function isTrustedSystemLink(linkPath: string, linkStat: fs.Stats): boolean {
430
+ if (process.platform === "win32" || linkStat.uid !== 0) return false;
431
+ const parent = fs.statSync(path.dirname(linkPath));
432
+ return parent.uid === 0 && (parent.mode & 0o022) === 0;
433
+ }
434
+
378
435
  const PROCESS_START_ID = randomUUID();
379
436
 
380
437
  function securityError(pathname: string, result: NativeSecurity): Error {
@@ -7,6 +7,7 @@ import * as native from "@sayknow-cli/natives";
7
7
  import { isEnoent, pathIsWithin, peekFile, toError } from "@sayknow-cli/utils";
8
8
  import {
9
9
  assertManagedDirectoryRoot,
10
+ isTrustedSystemLink,
10
11
  type ManagedDirectoryRoot,
11
12
  validateNativeSecurityResult,
12
13
  } from "./internal/managed-session-storage";
@@ -487,14 +488,22 @@ function assertNoReparsePath(pathname: string): void {
487
488
  for (const part of resolved.slice(parsed.root.length).split(path.sep)) {
488
489
  if (!part) continue;
489
490
  current = path.join(current, part);
491
+ let stat: fs.Stats;
490
492
  try {
491
- if (fs.lstatSync(current).isSymbolicLink()) throw new Error(`Unsafe reparse storage path: ${current}`);
493
+ stat = fs.lstatSync(current);
492
494
  } catch (error) {
493
495
  if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
496
+ continue;
497
+ }
498
+ if (stat.isSymbolicLink() && !isTrustedSystemLink(current, stat)) {
499
+ throw new Error(`Unsafe reparse storage path: ${current}`);
494
500
  }
495
501
  }
496
502
  }
497
503
 
504
+ /** @internal Exported for tests. */
505
+ export { assertNoReparsePath as assertNoReparseStoragePath };
506
+
498
507
  // FinalizationRegistry to clean up leaked file descriptors
499
508
  const writerRegistry = new FinalizationRegistry<number>(fd => {
500
509
  try {
@@ -70,7 +70,7 @@ export interface TmuxLaunchContext {
70
70
 
71
71
  export interface TmuxSpawnResult {
72
72
  exitCode: number | null;
73
- signalCode?: string | null;
73
+ signalCode?: NodeJS.Signals | number | null;
74
74
  stderr?: string;
75
75
  /** Populated only when the caller asked for `stdout: "pipe"`. */
76
76
  stdout?: string;