@stigmer/client 0.1.3 → 0.2.0

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 (61) hide show
  1. package/app-handover.d.ts +119 -0
  2. package/app-handover.d.ts.map +1 -0
  3. package/app-handover.js +523 -0
  4. package/app-handover.js.map +1 -0
  5. package/gen/organization.d.ts +2 -0
  6. package/gen/organization.d.ts.map +1 -1
  7. package/gen/organization.js +8 -0
  8. package/gen/organization.js.map +1 -1
  9. package/iam-principal.d.ts +11 -0
  10. package/iam-principal.d.ts.map +1 -1
  11. package/iam-principal.js +16 -0
  12. package/iam-principal.js.map +1 -1
  13. package/index.d.ts +11 -5
  14. package/index.d.ts.map +1 -1
  15. package/index.js +10 -3
  16. package/index.js.map +1 -1
  17. package/package.json +3 -3
  18. package/platform.d.ts +41 -3
  19. package/platform.d.ts.map +1 -1
  20. package/platform.js +56 -3
  21. package/platform.js.map +1 -1
  22. package/run/format-elapsed.d.ts +10 -0
  23. package/run/format-elapsed.d.ts.map +1 -0
  24. package/run/format-elapsed.js +25 -0
  25. package/run/format-elapsed.js.map +1 -0
  26. package/run/step-words.d.ts +78 -0
  27. package/run/step-words.d.ts.map +1 -0
  28. package/run/step-words.js +316 -0
  29. package/run/step-words.js.map +1 -0
  30. package/run/tool-view.d.ts +26 -2
  31. package/run/tool-view.d.ts.map +1 -1
  32. package/run/tool-view.js +83 -17
  33. package/run/tool-view.js.map +1 -1
  34. package/run/turn-activity.d.ts +9 -7
  35. package/run/turn-activity.d.ts.map +1 -1
  36. package/run/turn-activity.js +24 -144
  37. package/run/turn-activity.js.map +1 -1
  38. package/run/turn-ending.d.ts +59 -0
  39. package/run/turn-ending.d.ts.map +1 -0
  40. package/run/turn-ending.js +394 -0
  41. package/run/turn-ending.js.map +1 -0
  42. package/run/turn-steps.d.ts +16 -0
  43. package/run/turn-steps.d.ts.map +1 -0
  44. package/run/turn-steps.js +65 -0
  45. package/run/turn-steps.js.map +1 -0
  46. package/session-events.d.ts +3 -1
  47. package/session-events.d.ts.map +1 -1
  48. package/session-events.js +1 -0
  49. package/session-events.js.map +1 -1
  50. package/src/app-handover.ts +613 -0
  51. package/src/gen/organization.ts +7 -0
  52. package/src/iam-principal.ts +21 -0
  53. package/src/index.ts +49 -1
  54. package/src/platform.ts +80 -3
  55. package/src/run/format-elapsed.ts +22 -0
  56. package/src/run/step-words.ts +360 -0
  57. package/src/run/tool-view.ts +102 -19
  58. package/src/run/turn-activity.ts +27 -146
  59. package/src/run/turn-ending.ts +475 -0
  60. package/src/run/turn-steps.ts +81 -0
  61. package/src/session-events.ts +4 -1
@@ -72,6 +72,13 @@ export interface ToolContentBlock {
72
72
  * any unrecognized or truncated payload lands there, so this is never worse than
73
73
  * showing the raw result.
74
74
  */
75
+ /** The lines a read returned: 1-based, inclusive, and the file's length when the engine says it. */
76
+ export interface FileLineRange {
77
+ readonly start: number;
78
+ readonly end: number;
79
+ readonly total?: number;
80
+ }
81
+
75
82
  export type ToolResultView =
76
83
  // File edit. oldText/newText are the two sides of the change: the
77
84
  // old_string/new_string fragments from the tool's input. The
@@ -91,6 +98,12 @@ export type ToolResultView =
91
98
  readonly content: string;
92
99
  readonly language?: string;
93
100
  readonly truncated: boolean;
101
+ /**
102
+ * The lines a read returned, when its answer says (the Stigmer
103
+ * harness's `@@ lines A-B of T @@` frame; the Claude engine's
104
+ * numbered lines, which give no total): 1-based and inclusive.
105
+ */
106
+ readonly range?: FileLineRange;
94
107
  }
95
108
  // A rendered terminal session. `command` is the command that produced this
96
109
  // output (the prompt line) — it belongs here, not as a stray arg, because a
@@ -387,14 +400,30 @@ export function withoutOffloadTail(text: string): string {
387
400
  /**
388
401
  * Normalizes a tool use into a typed ToolResultView for rendering.
389
402
  *
390
- * A result that is an error always yields an `error` view. Otherwise the kind
391
- * drives interpretation, and anything unrecognized degrades to `json`/`text`.
403
+ * A result that is an error yields an `error` view, except a foreground
404
+ * command's: a command that failed is still a command, so it reads as its
405
+ * terminal (the command, what it printed, and the exit code when the output
406
+ * names one). Otherwise the kind drives interpretation, and anything
407
+ * unrecognized degrades to `json`/`text`.
392
408
  */
409
+ /**
410
+ * What an edit tried to change, as the diff of its own input (the text it
411
+ * meant to replace and its replacement), whatever its answer: a failed edit
412
+ * opens to what it tried rather than to its error. `undefined` for a call
413
+ * that is not a file edit.
414
+ */
415
+ export function editAttemptOf(tool: ToolViewInput): Extract<ToolResultView, { type: "diff" }> | undefined {
416
+ if (resolveToolKind(tool) !== "file_edit") return undefined;
417
+ const view = normalizeEdit(tool.input as Args);
418
+ return view.type === "diff" ? view : undefined;
419
+ }
420
+
393
421
  export function normalizeToolResult(tool: ToolViewInput): ToolResultView {
394
422
  const result = tool.result?.text ?? "";
395
423
  const args = tool.input as Args;
396
424
 
397
425
  if (tool.result?.isError === true && result !== "") {
426
+ if (tool.background === undefined && resolveToolKind(tool) === "shell") return failedShell(result, args);
398
427
  return { type: "error", message: result };
399
428
  }
400
429
 
@@ -454,7 +483,7 @@ export function normalizeToolResult(tool: ToolViewInput): ToolResultView {
454
483
  function normalizeEdit(args: Args): ToolResultView {
455
484
  // The inline transcript diff for a file edit is reconstructed from the tool
456
485
  // args (there is no captured `file_changes` mirror — apply-then-review renders
457
- // captured diffs via FileReviewCard/FileChangeDiff, not here). The Stigmer
486
+ // captured diffs via FileChangeDiff, not here). The Stigmer
458
487
  // and Claude engines return prose with no diff, so the presentation layer
459
488
  // computes the visual diff from the args fragments.
460
489
  const path = firstString(args, PATH_FIELDS) ?? "";
@@ -465,7 +494,7 @@ function normalizeEdit(args: Args): ToolResultView {
465
494
 
466
495
  function normalizeWrite(args: Args): ToolResultView {
467
496
  // The inline transcript view for a file write is the proposed content from the
468
- // tool args (captured diffs render via FileReviewCard, not here).
497
+ // tool args (captured diffs render via FileChangeDiff, not here).
469
498
  const path = firstString(args, PATH_FIELDS) ?? "";
470
499
  const content = firstString(args, WRITE_CONTENT_FIELDS) ?? "";
471
500
  return { type: "file", path, content, language: languageFromPath(path), truncated: false };
@@ -480,6 +509,7 @@ function normalizeRead(args: Args, result: string): ToolResultView {
480
509
  content: framed?.body ?? result,
481
510
  language: languageFromPath(path),
482
511
  truncated: framed?.truncated || isTruncated(result),
512
+ ...(framed?.range !== undefined ? { range: framed.range } : {}),
483
513
  };
484
514
  }
485
515
 
@@ -499,13 +529,30 @@ function stigmerReadHeaderFields(line: string): string | undefined {
499
529
  return STIGMER_READ_FIELDS.test(fields) ? fields : undefined;
500
530
  }
501
531
 
502
- function splitStigmerReadFrame(result: string): { body: string; truncated: boolean } | undefined {
532
+ /** A read's answer without its frame, whether the engine cut it, and the lines it returned when the frame says. */
533
+ interface ReadFrame {
534
+ readonly body: string;
535
+ readonly truncated: boolean;
536
+ readonly range?: FileLineRange;
537
+ }
538
+
539
+ // The header's range, read by position ("lines 14-17 of 88", "lines 1-40").
540
+ const STIGMER_READ_RANGE = /^lines (\d+)-(\d+)(?: of (\d+))?/;
541
+
542
+ function splitStigmerReadFrame(result: string): ReadFrame | undefined {
503
543
  const lines = result.split("\n");
504
544
  let at = 0;
505
545
  while (STIGMER_READ_NOTICE.test(lines[at] ?? "")) at += 1;
506
546
  const fields = stigmerReadHeaderFields(lines[at] ?? "");
507
547
  if (fields === undefined) return undefined;
508
- return { body: lines.slice(at + 1).join("\n"), truncated: fields.includes("truncated") };
548
+ const range = STIGMER_READ_RANGE.exec(fields);
549
+ return {
550
+ body: lines.slice(at + 1).join("\n"),
551
+ truncated: fields.includes("truncated"),
552
+ ...(range !== null
553
+ ? { range: { start: Number(range[1]), end: Number(range[2]), ...(range[3] !== undefined ? { total: Number(range[3]) } : {}) } }
554
+ : {}),
555
+ };
509
556
  }
510
557
 
511
558
  // The Claude engine answers a text read as the file's lines, each after its
@@ -515,7 +562,7 @@ function splitStigmerReadFrame(result: string): { body: string; truncated: boole
515
562
  // number and a tab, read by another engine, is never stripped.
516
563
  const NUMBERED_READ_LINE = /^ *(\d+)\t/;
517
564
 
518
- function splitNumberedReadFrame(result: string): { body: string; truncated: boolean } | undefined {
565
+ function splitNumberedReadFrame(result: string): ReadFrame | undefined {
519
566
  const lines = result.split("\n");
520
567
  const first = NUMBERED_READ_LINE.exec(lines[0] ?? "");
521
568
  if (first === null) return undefined;
@@ -526,7 +573,7 @@ function splitNumberedReadFrame(result: string): { body: string; truncated: bool
526
573
  if (numbered === null || Number(numbered[1]) !== start + index) return undefined;
527
574
  body.push(line.slice(numbered[0].length));
528
575
  }
529
- return { body: body.join("\n"), truncated: false };
576
+ return { body: body.join("\n"), truncated: false, range: { start, end: start + body.length - 1 } };
530
577
  }
531
578
 
532
579
  // Matches the deepagents shell marker, e.g. "[Command failed with exit code 2]"
@@ -554,6 +601,19 @@ function normalizeBackground(background: BackgroundCommandView, args: Args): Too
554
601
  }
555
602
  }
556
603
 
604
+ /**
605
+ * A foreground command whose result is an error, as its terminal: an exit
606
+ * code only where the output names one (an error result with no exit line
607
+ * did not exit 0).
608
+ */
609
+ function failedShell(result: string, args: Args): ToolResultView {
610
+ const view = normalizeShell(result, args);
611
+ if (view.type !== "terminal" || view.exitCode !== 0) return view;
612
+ return view.command === undefined
613
+ ? { type: "terminal", stdout: view.stdout, stderr: view.stderr }
614
+ : { type: "terminal", command: view.command, stdout: view.stdout, stderr: view.stderr };
615
+ }
616
+
557
617
  function normalizeShell(result: string, args: Args): ToolResultView {
558
618
  // The command is the session's prompt line. "command" matches the shell
559
619
  // primaryField shared with the runner/Go classifier and both Stigmer and
@@ -562,9 +622,8 @@ function normalizeShell(result: string, args: Args): ToolResultView {
562
622
 
563
623
  // Stigmer-harness subagent steps emit structured shell output, a
564
624
  // {stdout,stderr,exitCode} record; read it so the real output surfaces
565
- // instead of the raw JSON string. A failed shell never reaches here —
566
- // normalizeToolResult routes TOOL_CALL_FAILED to the error view first — so
567
- // only success is handled.
625
+ // instead of the raw JSON string. A failed shell reaches here through
626
+ // failedShell, which keeps a named exit code and drops an unnamed one.
568
627
  const shell = tryParseJson(result);
569
628
  if (hasShellFields(shell)) {
570
629
  return {
@@ -590,8 +649,25 @@ function normalizeShell(result: string, args: Args): ToolResultView {
590
649
  return { type: "terminal", command, stdout: result.replace(SHELL_EXIT_LINE, ""), stderr: "", exitCode: exitLine !== null ? Number(exitLine[1]) : 0 };
591
650
  }
592
651
 
593
- // A grep-style match line, e.g. " 12: // TODO: fix".
594
- const GREP_MATCH_LINE = /^\s*\d+[:\t]/;
652
+ // A match line in either form a search tool writes: the Stigmer harness's
653
+ // " 12: // TODO: fix" (the line, then the text), and the "path:12:text" of
654
+ // ripgrep and the search tools of other engines (the file, the line, then
655
+ // the text).
656
+ const GREP_MATCH_LINE = /^\s*(\d+)[:\t]\s?(.*)$/;
657
+ const PATH_MATCH_LINE = /^(\S[^:]*):(\d+):(.*)$/;
658
+ /** Whether `line` is the harness's file header above its matches, e.g. "/workspace/a.go:" (checked without a pattern, in linear time). */
659
+ function isFileHeader(line: string): boolean {
660
+ return line !== "" && line.trimStart() === line && line.trimEnd().endsWith(":");
661
+ }
662
+
663
+ /** A match line as its parts, or undefined when the line is neither form. */
664
+ function matchOf(line: string): ToolSearchMatch | undefined {
665
+ const pathForm = PATH_MATCH_LINE.exec(line);
666
+ if (pathForm !== null) return { file: pathForm[1]!, line: Number(pathForm[2]), text: pathForm[3]!.trim() };
667
+ const lineForm = GREP_MATCH_LINE.exec(line);
668
+ if (lineForm !== null) return { line: Number(lineForm[1]), text: lineForm[2]!.trim() };
669
+ return undefined;
670
+ }
595
671
 
596
672
  // A search answers in plain text (see searchFromPlainText). A JSON answer is
597
673
  // not a shape any engine is known to give, so it degrades to the json view
@@ -605,15 +681,22 @@ function normalizeSearch(result: string): ToolResultView {
605
681
  return searchFromPlainText(result);
606
682
  }
607
683
 
608
- // The plain-text path for the Stigmer harness: grep emits " 12: match" lines;
609
- // glob/semantic search emit one path per line.
684
+ // The plain-text path: a content search emits match lines (either form,
685
+ // see matchOf); glob/semantic search emit one path per line.
610
686
  function searchFromPlainText(result: string): ToolResultView {
611
687
  const lines = nonEmptyLines(result);
612
- const matchLines = lines.filter((l) => GREP_MATCH_LINE.test(l));
688
+ // The harness's form names each file once, on a "path:" line above its
689
+ // matches; each match carries the file it sits under.
690
+ const found: ToolSearchMatch[] = [];
691
+ let file: string | undefined;
692
+ for (const line of lines) {
693
+ const match = matchOf(line);
694
+ if (match !== undefined) found.push(match.file === undefined && file !== undefined ? { ...match, file } : match);
695
+ else if (isFileHeader(line)) file = line.trim().slice(0, -1);
696
+ }
613
697
 
614
- if (matchLines.length > 0) {
615
- const matches = matchLines.map((l) => ({ text: l.trim() }));
616
- return { type: "search", matches, count: matches.length, kind: "content" };
698
+ if (found.length > 0) {
699
+ return { type: "search", matches: found, count: found.length, kind: "content" };
617
700
  }
618
701
 
619
702
  // Path/name results (glob, semantic search): each meaningful line is a match.
@@ -9,7 +9,9 @@
9
9
  // harness's `Bash` read alike), the asks waiting on a person, a message or
10
10
  // thinking still streaming, and the to-do list.
11
11
  // It returns structure, never prose; `activityPhrase` beside it gives the
12
- // present-tense words, so a surface may lay the parts out as it likes.
12
+ // present-tense words, so a surface may lay the parts out as it likes. The
13
+ // words come from one table of every kind's tenses (step-words.ts), which
14
+ // each step's own line reads too.
13
15
  //
14
16
  // Trade-offs:
15
17
  // - "How far" is a fraction only when the agent keeps a to-do list. Without
@@ -17,6 +19,11 @@
17
19
  // - The newest open call on the primary thread is "now": it is the one the
18
20
  // agent started last, and a subagent's own calls belong to its card. A
19
21
  // turn with nothing open and nothing streaming is waiting on its model.
22
+ // - A turn that has not started and whose liveness carries the server's
23
+ // wait for a sandbox (`TurnLiveness.awaitingSandboxMs`) is waiting for a
24
+ // sandbox with room. The wait is the server's, measured when it sent the
25
+ // liveness: a surface that shows it ticking counts on from the liveness's
26
+ // arrival, never from its own clock against the server's.
20
27
  // - Time is the caller's clock (`nowMs`) against the turn's own start, the
21
28
  // person's message as the log stamped it, so a page that reloads mid-turn
22
29
  // reads the same elapsed time.
@@ -25,6 +32,7 @@
25
32
  // summary and `stigmer status` all say "1h 3m", never "63m 0s".
26
33
 
27
34
  import type { ToolUse, Turn } from "@stigmer/session-log";
35
+ import { KIND_WORDS, phraseOf, targetOf } from "./step-words.js";
28
36
  import { resolveToolKind, type ToolKind } from "./tool-view.js";
29
37
 
30
38
  /** What a working turn is doing now. */
@@ -38,7 +46,12 @@ export type TurnActivity =
38
46
  /** The agent is thinking (its thinking is streaming). */
39
47
  | { readonly kind: "thinking" }
40
48
  /** Nothing is open: the turn waits on its model's next step. */
41
- | { readonly kind: "waiting_on_model" };
49
+ | { readonly kind: "waiting_on_model" }
50
+ /** The turn has not started: every sandbox is busy. `waitedMs` is the server's measure when it last said so (module header). */
51
+ | { readonly kind: "waiting_for_sandbox"; readonly waitedMs: number };
52
+
53
+ /** The words for a turn waiting for a sandbox with room. */
54
+ export const SANDBOX_WAIT_PHRASE = "Waiting for a sandbox";
42
55
 
43
56
  /** How far a turn's to-do list has got. */
44
57
  export interface TodoProgress {
@@ -64,23 +77,9 @@ export interface TurnProgress {
64
77
  readonly todos: TodoProgress | undefined;
65
78
  }
66
79
 
67
- /** The longest target a phrase carries before it is cut. */
68
- const TARGET_MAX = 48;
69
-
70
- /**
71
- * A span of time in at most two units, the larger first: "42s", "1m 12s",
72
- * "1h 3m", "2d 5h". Seconds are floored, so a span never reads longer than it
73
- * was; a negative span reads "0s".
74
- */
75
- export function formatElapsed(ms: number): string {
76
- const seconds = Math.max(0, Math.floor(ms / 1000));
77
- if (seconds < 60) return `${seconds}s`;
78
- const minutes = Math.floor(seconds / 60);
79
- if (minutes < 60) return `${minutes}m ${seconds % 60}s`;
80
- const hours = Math.floor(minutes / 60);
81
- if (hours < 24) return `${hours}h ${minutes % 60}m`;
82
- return `${Math.floor(hours / 24)}d ${hours % 24}h`;
83
- }
80
+ // formatElapsed lives in its own module (./format-elapsed.ts), so a surface
81
+ // that only says a duration does not load this module's step words.
82
+ export { formatElapsed } from "./format-elapsed.js";
84
83
 
85
84
  /** The activity, time and progress of `turn` at `nowMs` (module header). */
86
85
  export function describeTurnActivity(turn: Turn, nowMs: number): TurnProgress {
@@ -101,6 +100,8 @@ export function describeTurnActivity(turn: Turn, nowMs: number): TurnProgress {
101
100
  }
102
101
 
103
102
  function activityOf(turn: Turn, open: readonly ToolUse[]): TurnActivity {
103
+ const sandboxWait = turn.liveness?.awaitingSandboxMs;
104
+ if (sandboxWait !== undefined && !turn.ended) return { kind: "waiting_for_sandbox", waitedMs: sandboxWait };
104
105
  if (turn.asks.length > 0) return { kind: "waiting_for_you", count: turn.asks.length };
105
106
  const last = turn.items.at(-1);
106
107
  if (last?.kind === "message" && last.live) return { kind: "writing" };
@@ -125,75 +126,9 @@ function todoProgress(turn: Turn): TodoProgress | undefined {
125
126
  };
126
127
  }
127
128
 
128
- /** What a call acts on, in a few characters: a file's name, a search's pattern, a page's host, a subagent's task. */
129
- function targetOf(tool: ToolUse): string {
130
- const input = tool.input;
131
- const text = (key: string): string => {
132
- const value = input[key];
133
- return typeof value === "string" ? value : "";
134
- };
135
- const kind = resolveToolKind(tool);
136
- switch (kind) {
137
- case "file_read":
138
- case "file_write":
139
- case "file_edit":
140
- case "file_delete":
141
- return short(baseName(text("path") || text("file_path") || text("notebook_path")));
142
- case "search":
143
- return short(text("pattern") || text("query"));
144
- case "fetch":
145
- return short(hostOf(text("url")));
146
- case "web_search":
147
- return short(text("query"));
148
- case "subagent":
149
- return short(text("description"));
150
- case "mcp":
151
- return short(tool.name);
152
- case "skill":
153
- return short(text("skill") || text("name"));
154
- case "list":
155
- return short(baseName(text("path")));
156
- case "shell":
157
- case "think":
158
- case "todo":
159
- case "memory":
160
- case "background_stop":
161
- case "unknown":
162
- return "";
163
- /* v8 ignore next -- @preserve: the exhaustiveness guard over ToolKind; resolveToolKind answers only the arms above */
164
- default: {
165
- const never: never = kind;
166
- return never;
167
- }
168
- }
169
- }
170
-
171
- // The path is the model's, so the trailing separators are trimmed by a loop:
172
- // a regular expression like /[\\/]+$/ backtracks quadratically on a long run
173
- // of them, and the activity line reads this every second.
174
- function baseName(path: string): string {
175
- let end = path.length;
176
- while (end > 0 && (path[end - 1] === "/" || path[end - 1] === "\\")) end -= 1;
177
- const trimmed = path.slice(0, end);
178
- return trimmed.slice(Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\")) + 1);
179
- }
180
-
181
- function hostOf(url: string): string {
182
- try {
183
- return new URL(url).host;
184
- } catch {
185
- return "";
186
- }
187
- }
188
-
189
- function short(value: string): string {
190
- const flat = value.replace(/\s+/g, " ").trim();
191
- return flat.length <= TARGET_MAX ? flat : `${flat.slice(0, TARGET_MAX - 1)}…`;
192
- }
193
-
194
129
  /**
195
130
  * The activity in present-tense words: "Editing invoice.ts", "Running a
196
- * command", "Waiting for you". A kind's words name the work, whichever
131
+ * command", "Waiting for you", "Waiting for a sandbox". A kind's words name the work, whichever
197
132
  * harness ran it; a target the input did not name leaves the generic words.
198
133
  */
199
134
  export function activityPhrase(activity: TurnActivity): string {
@@ -206,6 +141,8 @@ export function activityPhrase(activity: TurnActivity): string {
206
141
  return "Thinking";
207
142
  case "waiting_on_model":
208
143
  return "Working";
144
+ case "waiting_for_sandbox":
145
+ return SANDBOX_WAIT_PHRASE;
209
146
  case "tool":
210
147
  return toolPhrase(activity.toolKind, activity.target);
211
148
  /* v8 ignore next -- @preserve: the exhaustiveness guard over TurnActivity; describeTurnActivity answers only the arms above */
@@ -216,67 +153,11 @@ export function activityPhrase(activity: TurnActivity): string {
216
153
  }
217
154
  }
218
155
 
156
+ /** A kind's present-tense words, on its target when it names one (step-words.ts). */
219
157
  function toolPhrase(kind: ToolKind, target: string): string {
220
- const on = (verb: string, fallback: string): string => (target === "" ? fallback : `${verb} ${target}`);
221
- switch (kind) {
222
- case "file_read":
223
- return on("Reading", "Reading a file");
224
- case "file_write":
225
- return on("Writing", "Writing a file");
226
- case "file_edit":
227
- return on("Editing", "Editing a file");
228
- case "file_delete":
229
- return on("Deleting", "Deleting a file");
230
- case "shell":
231
- return "Running a command";
232
- case "search":
233
- return on("Searching for", "Searching");
234
- case "list":
235
- return on("Looking in", "Looking through files");
236
- case "fetch":
237
- return on("Reading", "Reading a page");
238
- case "web_search":
239
- return on("Searching the web for", "Searching the web");
240
- case "think":
241
- return "Thinking";
242
- case "todo":
243
- return "Planning";
244
- case "subagent":
245
- return target === "" ? "A helper is working" : `A helper is working on ${target}`;
246
- case "mcp":
247
- return on("Using", "Using a tool");
248
- case "memory":
249
- return "Remembering";
250
- case "background_stop":
251
- return "Stopping a command";
252
- case "skill":
253
- return on("Using the skill", "Using a skill");
254
- case "unknown":
255
- return "Working";
256
- /* v8 ignore next -- @preserve: the exhaustiveness guard over ToolKind; resolveToolKind answers only the arms above */
257
- default: {
258
- const never: never = kind;
259
- return never;
260
- }
261
- }
158
+ return phraseOf(KIND_WORDS[kind].present, target);
262
159
  }
263
160
 
264
- /** The past-tense verb and the counted noun a settled call of each kind reads as. */
265
- const SETTLED_WORDS: Readonly<Partial<Record<ToolKind, readonly [verb: string, noun: string]>>> = {
266
- file_read: ["read", "file"],
267
- file_write: ["wrote", "file"],
268
- file_edit: ["edited", "file"],
269
- file_delete: ["deleted", "file"],
270
- shell: ["ran", "command"],
271
- search: ["searched", "pattern"],
272
- list: ["looked through", "folder"],
273
- fetch: ["read", "page"],
274
- web_search: ["searched the web", "time"],
275
- mcp: ["used", "tool"],
276
- skill: ["used", "skill"],
277
- unknown: ["used", "tool"],
278
- };
279
-
280
161
  /**
281
162
  * A stretch of settled calls in a few words, kinds in the order the agent
282
163
  * first used them: "Searched 1 pattern, read 1 file, edited invoice.ts,
@@ -288,11 +169,11 @@ export function settledStepsPhrase(tools: readonly ToolUse[]): string {
288
169
  const byKind = new Map<ToolKind, ToolUse[]>();
289
170
  for (const tool of tools) {
290
171
  const kind = resolveToolKind(tool);
291
- if (SETTLED_WORDS[kind] === undefined) continue;
172
+ if (KIND_WORDS[kind].counted === undefined) continue;
292
173
  byKind.set(kind, [...(byKind.get(kind) ?? []), tool]);
293
174
  }
294
175
  const parts = [...byKind].map(([kind, uses]) => {
295
- const [verb, noun] = SETTLED_WORDS[kind]!;
176
+ const [verb, noun] = KIND_WORDS[kind].counted!;
296
177
  const only = uses.length === 1 ? targetOf(uses[0]!) : "";
297
178
  if (kind === "file_edit" && only !== "") return `${verb} ${only}`;
298
179
  return `${verb} ${uses.length} ${noun}${uses.length === 1 ? "" : "s"}`;