@sayknow-cli/coding-agent 0.7.19 → 0.7.20

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,7 +2,7 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
- ## [0.7.19] - 2026-11-09
5
+ ## [0.7.20] - 2026-11-10
6
6
 
7
7
  ## [0.7.18] - 2026-11-09
8
8
 
@@ -1,4 +1,9 @@
1
1
  import type { InteractiveModeContext } from "../types";
2
+ /**
3
+ * One terminal row for an untrusted `/ssh list` field.
4
+ * Ordinary names, hosts, usernames, and ports are unchanged.
5
+ */
6
+ export declare function sshListTerminalLabel(value: string): string;
2
7
  export declare class SSHCommandController {
3
8
  #private;
4
9
  private ctx;
@@ -23,6 +23,8 @@ export interface ControlSurface {
23
23
  setThinking(level: ControlValue): Promise<ControlValue> | ControlValue;
24
24
  cycleThinking(): Promise<ControlValue> | ControlValue;
25
25
  setPermissionMode(mode: ControlValue): Promise<ControlValue> | ControlValue;
26
+ configurePermissionChannel?(input: ControlInput): Promise<ControlValue> | ControlValue;
27
+ respondPermission?(input: ControlInput): ControlValue;
26
28
  setQueueMode(kind: string, mode: ControlValue): Promise<ControlValue> | ControlValue;
27
29
  runCompaction(): Promise<ControlValue> | ControlValue;
28
30
  setAutoCompaction(on: boolean): Promise<ControlValue> | ControlValue;
@@ -0,0 +1,47 @@
1
+ import type { ClientBridge, ClientBridgePermissionOption, ClientBridgePermissionOutcome, ClientBridgePermissionToolCall } from "../../session/client-bridge";
2
+ import type { ControlSurface } from "./control/operations";
3
+ type PermissionOutcome = ClientBridgePermissionOutcome;
4
+ export interface ExternalPermissionChannelInput {
5
+ enabled: boolean;
6
+ }
7
+ export interface ExternalPermissionResponseInput {
8
+ sessionId: string;
9
+ id: string;
10
+ optionId: string;
11
+ comment?: string;
12
+ }
13
+ export interface ExternalPermissionRequest {
14
+ id: string;
15
+ sessionId: string;
16
+ toolCall: ClientBridgePermissionToolCall;
17
+ options: ClientBridgePermissionOption[];
18
+ expiresAt: string;
19
+ }
20
+ export declare class ExternalPermissionError extends Error {
21
+ readonly code: "invalid_input" | "resource_gone" | "too_many_outstanding" | "payload_too_large";
22
+ constructor(code: "invalid_input" | "resource_gone" | "too_many_outstanding" | "payload_too_large", message: string);
23
+ }
24
+ export declare class ExternalPermissionRuntime {
25
+ #private;
26
+ constructor(sessionId: string, options?: {
27
+ timeoutMs?: number;
28
+ maxPending?: number;
29
+ });
30
+ get enabled(): boolean;
31
+ installControls(surface: Pick<ControlSurface, "setPermissionMode" | "configurePermissionChannel" | "respondPermission">, setProvider: (provider: ClientBridge["requestPermission"]) => void, hasReverseProvider: () => boolean): void;
32
+ configure(input: unknown): {
33
+ enabled: boolean;
34
+ };
35
+ request(toolCall: ClientBridgePermissionToolCall, options: ClientBridgePermissionOption[], signal?: AbortSignal): Promise<PermissionOutcome>;
36
+ list(input?: unknown): {
37
+ sessionId: string;
38
+ enabled: boolean;
39
+ requests: ExternalPermissionRequest[];
40
+ };
41
+ respond(input: unknown): {
42
+ accepted: true;
43
+ };
44
+ dispose(): void;
45
+ cancelPending(): void;
46
+ }
47
+ export {};
@@ -43,6 +43,7 @@ export type ClientBridgePermissionOutcome = {
43
43
  outcome: "selected";
44
44
  optionId: string;
45
45
  kind?: ClientBridgePermissionOptionKind;
46
+ comment?: string;
46
47
  };
47
48
  export interface ClientBridgeTerminalExitStatus {
48
49
  exitCode?: number | null;
@@ -1,6 +1,3 @@
1
- /**
2
- * Render file listings with optional icons and metadata.
3
- */
4
1
  import type { Theme } from "../modes/theme/theme";
5
2
  export interface FileEntry {
6
3
  path: string;
@@ -15,4 +15,13 @@ export interface StatusLineOptions {
15
15
  };
16
16
  meta?: string[];
17
17
  }
18
+ /**
19
+ * Sanitize untrusted text embedded in status lines while preserving caller-provided
20
+ * SGR color/style sequences (e.g. `theme.fg`) and intentional OSC 8 file hyperlinks.
21
+ *
22
+ * Uses a linear-time 1-pass scanner to avoid quadratic backtracking on repeated
23
+ * unterminated control introducers, stripping arbitrary OSC, DCS, non-SGR CSI,
24
+ * C0/C1 controls, and directional overrides, while flattening newlines and tabs to single spaces.
25
+ */
26
+ export declare function sanitizeStatusLineText(text: string): string;
18
27
  export declare function renderStatusLine(options: StatusLineOptions, theme: Theme): 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.19",
4
+ "version": "0.7.20",
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.19",
58
- "@sayknow-cli/agent-core": "0.7.19",
59
- "@sayknow-cli/ai": "0.7.19",
60
- "@sayknow-cli/natives": "0.7.19",
61
- "@sayknow-cli/tui": "0.7.19",
62
- "@sayknow-cli/utils": "0.7.19",
57
+ "@sayknow-cli/stats": "0.7.20",
58
+ "@sayknow-cli/agent-core": "0.7.20",
59
+ "@sayknow-cli/ai": "0.7.20",
60
+ "@sayknow-cli/natives": "0.7.20",
61
+ "@sayknow-cli/tui": "0.7.20",
62
+ "@sayknow-cli/utils": "0.7.20",
63
63
  "@puppeteer/browsers": "^2.13.0",
64
64
  "@types/turndown": "5.0.6",
65
65
  "@xterm/headless": "^6.0.0",
@@ -77,7 +77,8 @@
77
77
  },
78
78
  "devDependencies": {
79
79
  "@types/bun": "^1.3.14",
80
- "@types/ws": "^8.5.13"
80
+ "@types/ws": "^8.5.13",
81
+ "fast-check": "4.10.2"
81
82
  },
82
83
  "engines": {
83
84
  "bun": ">=1.3.14"
@@ -6,6 +6,7 @@ import type {
6
6
  ToolCallLocation,
7
7
  ToolKind,
8
8
  } from "@agentclientprotocol/sdk";
9
+ import { sanitizeText } from "@sayknow-cli/utils";
9
10
  import type { AgentSessionEvent } from "../../session/agent-session";
10
11
  import { resolveToCwd } from "../../tools/path-utils";
11
12
  import type { TodoStatus } from "../../tools/todo-write";
@@ -550,6 +551,139 @@ function extractTodoEntries(phases: unknown[]): Array<{ content: string; status:
550
551
  function isTodoStatus(status: unknown): status is TodoStatus {
551
552
  return status === "pending" || status === "in_progress" || status === "completed" || status === "abandoned";
552
553
  }
554
+
555
+ /** Shallow copies stay recursive. Deeper rawInput values use one iterative pass. */
556
+ const CLIENT_VALUE_MAX_DEPTH = 64;
557
+
558
+ function isClientContainer(value: object): boolean {
559
+ if (Array.isArray(value)) return true;
560
+ const prototype = Object.getPrototypeOf(value);
561
+ return prototype === Object.prototype || prototype === null;
562
+ }
563
+
564
+ /** Strip terminal controls from tool-argument text copied into a session update. */
565
+ function sanitizeClientValue(value: unknown): unknown {
566
+ return sanitizeClientValueWalk(value, new WeakMap(), 0);
567
+ }
568
+
569
+ function sanitizeClientValueWalk(value: unknown, seen: WeakMap<object, unknown>, depth: number): unknown {
570
+ if (typeof value === "string") {
571
+ const clean = sanitizeText(value);
572
+ return clean === value ? value : clean;
573
+ }
574
+ if (typeof value !== "object" || value === null) return value;
575
+ if (depth >= CLIENT_VALUE_MAX_DEPTH) return sanitizeClientTail(value, seen);
576
+ const existing = seen.get(value);
577
+ if (existing !== undefined) return existing;
578
+ if (Array.isArray(value)) {
579
+ const next: unknown[] = [];
580
+ seen.set(value, next);
581
+ let changed = false;
582
+ for (const item of value) {
583
+ const clean = sanitizeClientValueWalk(item, seen, depth + 1);
584
+ if (clean !== item) changed = true;
585
+ next.push(clean);
586
+ }
587
+ if (!changed) seen.set(value, value);
588
+ return changed ? next : value;
589
+ }
590
+ if (!isClientContainer(value)) return value;
591
+ const next = Object.create(Object.getPrototypeOf(value)) as Record<string, unknown>;
592
+ seen.set(value, next);
593
+ let changed = false;
594
+ for (const key of Object.keys(value)) {
595
+ const current = (value as Record<string, unknown>)[key];
596
+ const clean = sanitizeClientValueWalk(current, seen, depth + 1);
597
+ if (clean !== current) changed = true;
598
+ Object.defineProperty(next, key, { value: clean, enumerable: true, writable: true, configurable: true });
599
+ }
600
+ if (!changed) seen.set(value, value);
601
+ return changed ? next : value;
602
+ }
603
+
604
+ type ClientTailFrame = {
605
+ source: object;
606
+ keys: readonly string[] | null;
607
+ index: number;
608
+ box: object;
609
+ changed: boolean;
610
+ holdKey?: string | number;
611
+ };
612
+
613
+ /** Iterative copy of one nested rawInput value. Each container is entered once. Keys are copied as-is. */
614
+ function sanitizeClientTail(root: object, seen: WeakMap<object, unknown>): unknown {
615
+ const cached = seen.get(root);
616
+ if (cached !== undefined) return cached;
617
+ if (!isClientContainer(root)) return root;
618
+
619
+ const open = (node: object): ClientTailFrame => {
620
+ const box = Array.isArray(node) ? [] : Object.create(Object.getPrototypeOf(node));
621
+ seen.set(node, box);
622
+ return {
623
+ source: node,
624
+ keys: Array.isArray(node) ? null : Object.keys(node),
625
+ index: 0,
626
+ box,
627
+ changed: false,
628
+ };
629
+ };
630
+ const put = (frame: ClientTailFrame, key: string | number, child: unknown, dirty: boolean): void => {
631
+ if (Array.isArray(frame.box)) (frame.box as unknown[]).push(child);
632
+ else {
633
+ Object.defineProperty(frame.box, String(key), {
634
+ value: child,
635
+ enumerable: true,
636
+ writable: true,
637
+ configurable: true,
638
+ });
639
+ }
640
+ if (dirty) frame.changed = true;
641
+ };
642
+
643
+ const stack = [open(root)];
644
+ let finished: unknown = stack[0]!.box;
645
+ while (stack.length > 0) {
646
+ const frame = stack[stack.length - 1]!;
647
+ const length = frame.keys === null ? (frame.source as unknown[]).length : frame.keys.length;
648
+ if (frame.index >= length) {
649
+ finished = frame.changed ? frame.box : frame.source;
650
+ if (!frame.changed) seen.set(frame.source, frame.source);
651
+ stack.pop();
652
+ const parent = stack[stack.length - 1];
653
+ if (parent && parent.holdKey !== undefined) {
654
+ put(parent, parent.holdKey, finished, finished !== frame.source);
655
+ parent.holdKey = undefined;
656
+ }
657
+ continue;
658
+ }
659
+ const key = frame.keys === null ? frame.index : frame.keys[frame.index]!;
660
+ const child =
661
+ frame.keys === null
662
+ ? (frame.source as unknown[])[frame.index]
663
+ : (frame.source as Record<string, unknown>)[key];
664
+ frame.index += 1;
665
+ if (typeof child === "string") {
666
+ const clean = sanitizeText(child);
667
+ put(frame, key, clean, clean !== child);
668
+ continue;
669
+ }
670
+ if (typeof child === "object" && child !== null) {
671
+ const found = seen.get(child);
672
+ if (found !== undefined) {
673
+ put(frame, key, found, found !== child);
674
+ continue;
675
+ }
676
+ if (isClientContainer(child)) {
677
+ frame.holdKey = key;
678
+ stack.push(open(child));
679
+ continue;
680
+ }
681
+ }
682
+ put(frame, key, child, false);
683
+ }
684
+ return finished;
685
+ }
686
+
553
687
  export function buildToolCallStartUpdate(input: {
554
688
  toolCallId: string;
555
689
  toolName: string;
@@ -564,7 +698,7 @@ export function buildToolCallStartUpdate(input: {
564
698
  title: buildToolTitle(input.toolName, input.args, input.intent),
565
699
  kind: mapToolKind(input.toolName),
566
700
  status: input.status ?? "pending",
567
- rawInput: input.args,
701
+ rawInput: sanitizeClientValue(input.args),
568
702
  };
569
703
  const content = buildToolStartContent(input.toolName, input.args);
570
704
  if (content.length > 0) {
@@ -604,7 +738,9 @@ function buildToolStartContent(toolName: string, args: unknown): ToolCallContent
604
738
  return [];
605
739
  }
606
740
  const command = extractStringProperty<CommandContainer>(args, "command");
607
- return command ? [textToolCallContent(`$ ${command}`)] : [];
741
+ if (!command) return [];
742
+ const safeCommand = sanitizeText(command);
743
+ return safeCommand.length > 0 ? [textToolCallContent(`$ ${safeCommand}`)] : [];
608
744
  }
609
745
 
610
746
  function mergeToolUpdateContent(startContent: ToolCallContent[], resultContent: ToolCallContent[]): ToolCallContent[] {
@@ -645,7 +781,8 @@ function isCommandToolName(toolName: string): boolean {
645
781
  function buildToolTitle(toolName: string, args: unknown, intent: string | undefined): string {
646
782
  const trimmedIntent = intent?.trim();
647
783
  if (trimmedIntent) {
648
- return trimmedIntent;
784
+ const safeIntent = sanitizeText(trimmedIntent).trim();
785
+ if (safeIntent.length > 0) return safeIntent;
649
786
  }
650
787
 
651
788
  const subject =
@@ -654,10 +791,11 @@ function buildToolTitle(toolName: string, args: unknown, intent: string | undefi
654
791
  extractStringProperty<PatternContainer>(args, "pattern") ??
655
792
  extractStringProperty<QueryContainer>(args, "query");
656
793
  if (subject) {
657
- return `${toolName}: ${subject}`;
794
+ const safeSubject = sanitizeText(subject);
795
+ if (safeSubject.length > 0) return sanitizeText(`${toolName}: ${safeSubject}`);
658
796
  }
659
797
 
660
- return toolName;
798
+ return sanitizeText(toolName);
661
799
  }
662
800
 
663
801
  /**
@@ -1,4 +1,5 @@
1
1
  import { Box, Container, Spacer, Text } from "@sayknow-cli/tui";
2
+ import { sanitizeText } from "@sayknow-cli/utils";
2
3
  import type { Rule } from "../../capability/rule";
3
4
  import { theme } from "../../modes/theme/theme";
4
5
 
@@ -36,8 +37,10 @@ export class TtsrNotificationComponent extends Container {
36
37
  #rebuild(): void {
37
38
  this.#box.clear();
38
39
 
39
- // Build header: warning symbol + rule name + rewind icon
40
- const ruleNames = this.rules.map(r => theme.bold(r.name)).join(", ");
40
+ // Build header: warning symbol + rule name + rewind icon.
41
+ // Sanitize before theme styling and the two-line cut so a control
42
+ // sequence cannot reach the terminal, including one split by truncation.
43
+ const ruleNames = this.rules.map(r => theme.bold(sanitizeText(r.name))).join(", ");
41
44
  const label = this.rules.length === 1 ? "rule" : "rules";
42
45
  const header = `${theme.icon.warning} Injecting ${label}: ${ruleNames}`;
43
46
 
@@ -52,7 +55,7 @@ export class TtsrNotificationComponent extends Container {
52
55
  if (desc) {
53
56
  this.#box.addChild(new Spacer(1));
54
57
 
55
- let displayText = desc.trim();
58
+ let displayText = sanitizeText(desc).trim();
56
59
  if (!this.#expanded) {
57
60
  // Truncate to first 2 lines
58
61
  const lines = displayText.split("\n");
@@ -70,7 +73,7 @@ export class TtsrNotificationComponent extends Container {
70
73
  if (!this.#expanded) {
71
74
  const hasMoreContent = this.rules.some(r => {
72
75
  const desc = r.description || r.content;
73
- return desc && desc.split("\n").length > 2;
76
+ return !!desc && sanitizeText(desc).trim().split("\n").length > 2;
74
77
  });
75
78
  if (hasMoreContent) {
76
79
  this.#box.addChild(new Text(theme.italic(" (ctrl+o to expand)"), 0, 0));
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Handles /ssh subcommands for managing SSH host configurations.
5
5
  */
6
- import { getProjectDir, getSSHConfigPath } from "@sayknow-cli/utils";
6
+ import { getProjectDir, getSSHConfigPath, sanitizeDisplayLine } from "@sayknow-cli/utils";
7
7
  import { type SSHHost, sshCapability } from "../../capability/ssh";
8
8
  import { loadCapability } from "../../discovery";
9
9
  import { addSSHHost, readSSHConfigFile, removeSSHHost, type SSHHostConfig } from "../../ssh/config-writer";
@@ -18,6 +18,14 @@ import {
18
18
  showCommandMessage,
19
19
  } from "./command-controller-shared";
20
20
 
21
+ /**
22
+ * One terminal row for an untrusted `/ssh list` field.
23
+ * Ordinary names, hosts, usernames, and ports are unchanged.
24
+ */
25
+ export function sshListTerminalLabel(value: string): string {
26
+ return sanitizeDisplayLine(value);
27
+ }
28
+
21
29
  export class SSHCommandController {
22
30
  constructor(private ctx: InteractiveModeContext) {}
23
31
 
@@ -287,7 +295,7 @@ export class SSHCommandController {
287
295
  for (const name of userHosts) {
288
296
  const config = userConfig.hosts![name];
289
297
  const details = this.#formatHostDetails(config);
290
- lines.push(` ${theme.fg("accent", name)} ${details}`);
298
+ lines.push(` ${theme.fg("accent", sshListTerminalLabel(name))} ${details}`);
291
299
  }
292
300
  lines.push("");
293
301
  }
@@ -298,7 +306,7 @@ export class SSHCommandController {
298
306
  for (const name of projectHosts) {
299
307
  const config = projectConfig.hosts![name];
300
308
  const details = this.#formatHostDetails(config);
301
- lines.push(` ${theme.fg("accent", name)} ${details}`);
309
+ lines.push(` ${theme.fg("accent", sshListTerminalLabel(name))} ${details}`);
302
310
  }
303
311
  lines.push("");
304
312
  }
@@ -308,7 +316,10 @@ export class SSHCommandController {
308
316
  for (const { providerName, shortPath, items: hosts } of groupBySource(discoveredHosts, h => h._source)) {
309
317
  lines.push(
310
318
  theme.fg("accent", "Discovered") +
311
- theme.fg("muted", ` (${providerName}: ${shortPath}):`) +
319
+ theme.fg(
320
+ "muted",
321
+ ` (${sshListTerminalLabel(providerName)}: ${sshListTerminalLabel(shortPath)}):`,
322
+ ) +
312
323
  theme.fg("dim", " read-only"),
313
324
  );
314
325
  for (const host of hosts) {
@@ -317,7 +328,7 @@ export class SSHCommandController {
317
328
  username: host.username,
318
329
  port: host.port,
319
330
  });
320
- lines.push(` ${theme.fg("accent", host.name)} ${details}`);
331
+ lines.push(` ${theme.fg("accent", sshListTerminalLabel(host.name))} ${details}`);
321
332
  }
322
333
  lines.push("");
323
334
  }
@@ -332,11 +343,11 @@ export class SSHCommandController {
332
343
  /**
333
344
  * Format host details (host, user, port) for display
334
345
  */
335
- #formatHostDetails(config: { host?: string; username?: string; port?: number }): string {
346
+ #formatHostDetails(config: { host?: string; username?: string; port?: number | string }): string {
336
347
  const parts: string[] = [];
337
- if (config.host) parts.push(config.host);
338
- if (config.username) parts.push(`user=${config.username}`);
339
- if (config.port && config.port !== 22) parts.push(`port=${config.port}`);
348
+ if (config.host) parts.push(sshListTerminalLabel(config.host));
349
+ if (config.username) parts.push(`user=${sshListTerminalLabel(config.username)}`);
350
+ if (config.port && config.port !== 22) parts.push(`port=${sshListTerminalLabel(String(config.port))}`);
340
351
  return theme.fg("dim", parts.length > 0 ? `[${parts.join(", ")}]` : "");
341
352
  }
342
353
 
@@ -1,4 +1,5 @@
1
1
  import * as fs from "node:fs/promises";
2
+ import { sanitizeText } from "@sayknow-cli/utils";
2
3
  import { resolveToCwd } from "../../tools/path-utils";
3
4
  import {
4
5
  applyOpsToPhases,
@@ -27,6 +28,11 @@ const USAGE = [
27
28
  " /todo rm [<task|phase>] Remove task/phase/all",
28
29
  ].join("\n");
29
30
 
31
+ // Session todo text is drawn with showStatus, which does not strip terminal controls.
32
+ function todoStatusText(text: string): string {
33
+ return sanitizeText(text);
34
+ }
35
+
30
36
  // =============================================================================
31
37
  // Argument tokenizer (respects double-quoted strings)
32
38
  // =============================================================================
@@ -196,7 +202,7 @@ export class TodoCommandController {
196
202
  this.ctx.showStatus("No todos. Use /todo append <task> to start one.");
197
203
  return;
198
204
  }
199
- this.ctx.showStatus(phasesToMarkdown(phases).trimEnd());
205
+ this.ctx.showStatus(todoStatusText(phasesToMarkdown(phases).trimEnd()));
200
206
  }
201
207
 
202
208
  #copyMarkdown(): void {
@@ -296,7 +302,7 @@ export class TodoCommandController {
296
302
  });
297
303
 
298
304
  this.#commit(next, `/todo append → ${targetPhase.name}`);
299
- this.ctx.showStatus(`Appended to ${targetPhase.name}: ${finalContent}`);
305
+ this.ctx.showStatus(todoStatusText(`Appended to ${targetPhase.name}: ${finalContent}`));
300
306
  }
301
307
 
302
308
  // ------------------------------------------------------------- start / done / drop / rm
@@ -318,7 +324,7 @@ export class TodoCommandController {
318
324
  return;
319
325
  }
320
326
  this.#commit(phases, `/todo start ${hit.task.content}`);
321
- this.ctx.showStatus(`Started: ${hit.task.content}`);
327
+ this.ctx.showStatus(todoStatusText(`Started: ${hit.task.content}`));
322
328
  }
323
329
 
324
330
  #mutateStatus(rest: string, target: "completed" | "abandoned"): void {
@@ -345,7 +351,7 @@ export class TodoCommandController {
345
351
  return;
346
352
  }
347
353
  this.#commit(phases, `/todo ${op} ${taskHit.task.content}`);
348
- this.ctx.showStatus(`Marked ${target}: ${taskHit.task.content}`);
354
+ this.ctx.showStatus(todoStatusText(`Marked ${target}: ${taskHit.task.content}`));
349
355
  return;
350
356
  }
351
357
 
@@ -357,7 +363,7 @@ export class TodoCommandController {
357
363
  return;
358
364
  }
359
365
  this.#commit(phases, `/todo ${op} ${phaseHit.name}`);
360
- this.ctx.showStatus(`Marked phase ${phaseHit.name} ${target}.`);
366
+ this.ctx.showStatus(todoStatusText(`Marked phase ${phaseHit.name} ${target}.`));
361
367
  return;
362
368
  }
363
369
 
@@ -380,7 +386,7 @@ export class TodoCommandController {
380
386
  return;
381
387
  }
382
388
  this.#commit(phases, `/todo rm ${taskHit.task.content}`);
383
- this.ctx.showStatus(`Removed: ${taskHit.task.content}`);
389
+ this.ctx.showStatus(todoStatusText(`Removed: ${taskHit.task.content}`));
384
390
  return;
385
391
  }
386
392
  const phaseHit = findPhaseFuzzy(current, trimmed);
@@ -391,7 +397,7 @@ export class TodoCommandController {
391
397
  return;
392
398
  }
393
399
  this.#commit(phases, `/todo rm ${phaseHit.name}`);
394
- this.ctx.showStatus(`Removed phase: ${phaseHit.name}`);
400
+ this.ctx.showStatus(todoStatusText(`Removed phase: ${phaseHit.name}`));
395
401
  return;
396
402
  }
397
403
  this.ctx.showError(`No task or phase matched "${trimmed}".`);
@@ -1,14 +1,20 @@
1
+ import { sanitizeText } from "@sayknow-cli/utils";
1
2
  import type { Tool } from "../../tools";
2
3
 
3
4
  export interface ToolsMarkdownBindings {
4
5
  tools: ReadonlyArray<Pick<Tool, "description" | "name">>;
5
6
  }
6
7
 
8
+ /**
9
+ * Flatten breaks before stripping controls so a carriage return cannot stay in
10
+ * the cell, then escape pipes. `sanitizeText` removes the sequence, not only ESC.
11
+ */
12
+ function neutralizeCellText(value: string): string {
13
+ return sanitizeText(value.replace(/\r?\n+/g, " ").replace(/\r/g, " "));
14
+ }
15
+
7
16
  function escapeTableCell(value: string): string {
8
- return value
9
- .replace(/\|/g, "\\|")
10
- .replace(/\r?\n+/g, " ")
11
- .trim();
17
+ return neutralizeCellText(value).replace(/\|/g, "\\|").trim();
12
18
  }
13
19
 
14
20
  export function buildToolsMarkdown(bindings: ToolsMarkdownBindings): string {
@@ -20,8 +26,9 @@ export function buildToolsMarkdown(bindings: ToolsMarkdownBindings): string {
20
26
  "| Tool | Description |",
21
27
  "|------|-------------|",
22
28
  ...bindings.tools.map(tool => {
29
+ const name = neutralizeCellText(tool.name);
23
30
  const description = escapeTableCell(tool.description) || "No description provided.";
24
- return `| \`${tool.name}\` | ${description} |`;
31
+ return `| \`${name}\` | ${description} |`;
25
32
  }),
26
33
  ].join("\n");
27
34
  }
@@ -40,6 +40,7 @@ Use `irc` to DM `0-Main` on unexpected state instead of guessing; coordinate bef
40
40
 
41
41
  [COMPLETION]
42
42
  No TODO tracking, no progress updates. Execute, call `yield`, done.
43
+ The one exception: when you measure comparable numbers (sizes, timings, counts per variant), you MAY show them with `report_metric`. It is display-only, so the same numbers still belong in `yield`.
43
44
 
44
45
  While work remains, always continue with another tool call — investigate, edit, run, verify. Save narrative for the final `yield` payload.
45
46
 
@@ -36,6 +36,7 @@ Optimize for correctness first, maintainability second, and brevity third. Prefe
36
36
  <communication>
37
37
  - Be concise and information-dense.
38
38
  - Do not narrate progress, ceremony, timing, scope inflation, or session limits.
39
+ - Conciseness never means a silent `ask`: before opening a selector, state in visible text what you found, why the decision is the user's, and what each option changes.
39
40
  - If the user's intent is clear, act without asking. Ask only when the next step is destructive or requires a missing choice that materially changes the outcome.
40
41
  - Treat an informational question as a request for an answer, not implicit permission to take action; answer read-only unless the user explicitly asks for a concrete change or command execution.
41
42
  - When the user proposes something wrong, say what breaks and what to do instead once; then defer to their call.
@@ -217,11 +218,16 @@ For image understanding, call `{{toolRefs.read}}` on the image path; the image i
217
218
  - Do not yield non-trivial work without proof: focused tests, e2e, browsing, QA, or an explicit reason verification cannot be run.
218
219
  - Test observable behavior, edge values, branch conditions, invariants, and error handling.
219
220
  - Do not test defaults or tautologies.
221
+ - When a second fix built on the same assumption fails the same check, test the assumption directly before writing a third fix.
222
+ - Before attributing a measured result (speedup, regression, latency, eval score) to a change, identify the bottleneck or confounder that bounds it and rule out that it measured something else; label attribution you could not verify.
223
+ - When a change alters a shared data contract (key, identifier, serialized format, schema, default), also check the consumers symbol search misses: persisted data, other languages, config and flags, and pinned dependency source.
220
224
  </verification>
221
225
  </workflow>
222
226
 
223
227
  {{#unless subagent}}
224
228
  <soul>
229
+ - **Routing comes first** - The action bias below never overrides `<routing>`: informational questions ("why is X failing?") and judgment asks ("what do you think of X?") stay answer-only and read-only unless the user explicitly asks for a change.
230
+
225
231
  You carry the soul of a senior staff engineer who has shipped and owned load-bearing systems for years. This is your character, not a checklist:
226
232
 
227
233
  - **Craft.** You care about correct, boring, maintainable code and a clean diff in the right place. You have no patience for cargo-culting, busywork, ceremony, or decoration.
@@ -13,19 +13,20 @@ Asks user when you need clarification or input during task execution.
13
13
  </instruction>
14
14
 
15
15
  <caution>
16
- - Provide 2-5 concise, distinct options
16
+ - Provide 2-5 distinct options. Keep labels short; put premise and trade-offs in the question body, not the labels.
17
17
  </caution>
18
18
 
19
19
  <critical>
20
+ - **Explain before you ask.** Before calling `ask`, explain the decision in your visible reply: what you found, why you cannot resolve it yourself, what each option changes (consequences, risk, reversibility), and your recommendation with its reason. The `ask` call must never be the first thing the user sees about this decision; conciseness rules do not waive this explanation. Also keep each question body self-contained (one or two sentences of premise and trade-offs) so it can be answered even if the preceding text scrolled away.
20
21
  - **Default to action.** Resolve ambiguity yourself using repo conventions, existing patterns, and reasonable defaults. Exhaust existing sources (code, configs, docs, history) before asking. Only ask when options have materially different tradeoffs the user must decide.
21
22
  - **If multiple choices are acceptable**, pick the most conservative/standard option and proceed; state the choice.
22
- - **Do NOT include "Other" option** — UI automatically adds "Other (type your own)" to every question.
23
+ - **Do NOT include the automatic custom-input control or labels that imitate it** such as "Other (type your own)", "Other (specify)", "type your own", "custom input", or "직접 입력" — UI automatically adds "Other (type your own)" to every question. A plain domain value such as "Other" is allowed when it is a genuine answer, not a request for free text. To collect free text, ask for it in the question body and rely on the automatic Other/custom-input control instead of adding a fake option.
23
24
  </critical>
24
25
 
25
26
  <examples>
26
27
  # Single question
27
- questions: [{"id": "auth_method", "question": "Which authentication method should this API use?", "options": [{"label": "JWT"}, {"label": "OAuth2"}, {"label": "Session cookies"}], "recommended": 0}]
28
+ questions: [{"id": "auth_method", "question": "The API has no auth yet and both web and CLI clients call it. JWT stays stateless and suits the CLI; session cookies are simpler for the web app but need a shared store to scale. Which authentication method should it use?", "options": [{"label": "JWT"}, {"label": "OAuth2"}, {"label": "Session cookies"}], "recommended": 0}]
28
29
 
29
30
  # Multiple questions
30
- questions: [{"id": "storage_type", "question": "Which storage backend?", "options": [{"label": "SQLite"}, {"label": "PostgreSQL"}]}, {"id": "auth_method", "question": "Which auth method?", "options": [{"label": "JWT"}, {"label": "Session cookies"}]}]
31
+ questions: [{"id": "storage_type", "question": "The service runs as a single process today. SQLite needs no extra infrastructure but serializes writes; PostgreSQL handles concurrent writers but must be provisioned. Which storage backend?", "options": [{"label": "SQLite"}, {"label": "PostgreSQL"}]}, {"id": "auth_method", "question": "Sessions must be revocable immediately after a permission change. Session cookies support that directly; JWTs need a denylist to do the same. Which auth method?", "options": [{"label": "JWT"}, {"label": "Session cookies"}]}]
31
32
  </examples>
@@ -29,6 +29,8 @@ export interface ControlSurface {
29
29
  setThinking(level: ControlValue): Promise<ControlValue> | ControlValue;
30
30
  cycleThinking(): Promise<ControlValue> | ControlValue;
31
31
  setPermissionMode(mode: ControlValue): Promise<ControlValue> | ControlValue;
32
+ configurePermissionChannel?(input: ControlInput): Promise<ControlValue> | ControlValue;
33
+ respondPermission?(input: ControlInput): ControlValue;
32
34
  setQueueMode(kind: string, mode: ControlValue): Promise<ControlValue> | ControlValue;
33
35
  runCompaction(): Promise<ControlValue> | ControlValue;
34
36
  setAutoCompaction(on: boolean): Promise<ControlValue> | ControlValue;