@@ -1,5 +1,5 @@
11 import * as c from "yoctocolors";
2-import { G, writeln } from "./output.ts";
2+import { G, tildePath, writeln } from "./output.ts";
33 import { renderToolResultByName } from "./tool-result-renderers.ts";
44
55 function toolGlyph(name: string): string {
@@ -13,6 +13,76 @@ function toolGlyph(name: string): string {
1313 return G.info;
1414 }
1515
16+/** Resolve glyph for well-known shell commands (lazy to avoid init-order issues). */
17+function shellCmdGlyph(cmd: string): string {
18+ switch (cmd) {
19+ case "cat":
20+ case "head":
21+ case "tail":
22+ case "ls":
23+ case "wc":
24+ return G.read;
25+ case "grep":
26+ case "find":
27+ return G.search;
28+ case "mc-edit":
29+ case "sed":
30+ case "rm":
31+ case "mkdir":
32+ case "cp":
33+ case "mv":
34+ case "touch":
35+ return G.write;
36+ case "git":
37+ case "bun":
38+ case "echo":
39+ return G.run;
40+ default:
41+ return G.run;
42+ }
43+}
44+
45+/**
46+ * Strip a leading `cd <path> &&` prefix from a shell command string.
47+ * Returns the directory (tilde-abbreviated) and the remaining command.
48+ */
49+function parseShellCdPrefix(cmd: string): {
50+ cwd: string | null;
51+ rest: string;
52+} {
53+ const match = cmd.match(/^cd\s+(\S+)\s*&&\s*/);
54+ if (!match) return { cwd: null, rest: cmd };
55+ const rawPath = match[1] ?? "";
56+ const rest = cmd.slice(match[0].length).trim();
57+ return { cwd: tildePath(rawPath), rest: rest || cmd };
58+}
59+
60+/**
61+ * Extract the first command word from a shell string,
62+ * skipping inline env vars like `FOO=bar cmd ...`.
63+ */
64+function extractFirstCommand(cmd: string): string {
65+ const tokens = cmd.split(/\s+/);
66+ for (const token of tokens) {
67+ if (token.includes("=") && !token.startsWith("-")) continue;
68+ return token;
69+ }
70+ return tokens[0] ?? "";
71+}
72+
73+function truncate(s: string, max: number): string {
74+ return s.length > max ? `${s.slice(0, max - 1)}…` : s;
75+}
76+
77+function formatShellCallLine(cmd: string): string {
78+ const { cwd, rest } = parseShellCdPrefix(cmd);
79+ const firstCmd = extractFirstCommand(rest);
80+ const glyph = shellCmdGlyph(firstCmd);
81+ const cwdSuffix = cwd ? ` ${c.dim(`in ${cwd}`)}` : "";
82+ const display = truncate(rest, 80);
83+ return `${glyph} ${display}${cwdSuffix}`;
84+}
85+
1686 export function buildToolCallLine(name: string, args: unknown): string {
1787 const a =
1888 args && typeof args === "object" ? (args as Record<string, unknown>) : {};
@@ -29,8 +99,7 @@ export function buildToolCallLine(name: string, args: unknown): string {
2999 if (name === "shell") {
30100 const cmd = String(a.command ?? "").trim();
31101 if (!cmd) return `${G.run} ${c.dim("shell")}`;
32- const shortCmd = cmd.length > 72 ? `${cmd.slice(0, 69)}…` : cmd;
33- return `${G.run} ${shortCmd}`;
102+ return formatShellCallLine(cmd);
34103 }
35104
36105 if (name === "listSkills") {