@mariozechner/pi-coding-agent 0.7.28 → 0.8.1
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 +12 -0
- package/README.md +74 -4
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +18 -9
- package/dist/main.js.map +1 -1
- package/dist/session-manager.d.ts.map +1 -1
- package/dist/session-manager.js +1 -1
- package/dist/session-manager.js.map +1 -1
- package/dist/settings-manager.d.ts +3 -0
- package/dist/settings-manager.d.ts.map +1 -1
- package/dist/settings-manager.js +7 -0
- package/dist/settings-manager.js.map +1 -1
- package/dist/theme/dark.json +70 -0
- package/dist/theme/light.json +69 -0
- package/dist/theme/theme-schema.json +246 -0
- package/dist/theme/theme.d.ts +33 -0
- package/dist/theme/theme.d.ts.map +1 -0
- package/dist/theme/theme.js +470 -0
- package/dist/theme/theme.js.map +1 -0
- package/dist/tui/assistant-message.d.ts.map +1 -1
- package/dist/tui/assistant-message.js +7 -7
- package/dist/tui/assistant-message.js.map +1 -1
- package/dist/tui/dynamic-border.d.ts +1 -0
- package/dist/tui/dynamic-border.d.ts.map +1 -1
- package/dist/tui/dynamic-border.js +5 -2
- package/dist/tui/dynamic-border.js.map +1 -1
- package/dist/tui/footer.d.ts +3 -1
- package/dist/tui/footer.d.ts.map +1 -1
- package/dist/tui/footer.js +20 -5
- package/dist/tui/footer.js.map +1 -1
- package/dist/tui/model-selector.d.ts.map +1 -1
- package/dist/tui/model-selector.js +14 -13
- package/dist/tui/model-selector.js.map +1 -1
- package/dist/tui/oauth-selector.d.ts.map +1 -1
- package/dist/tui/oauth-selector.js +9 -8
- package/dist/tui/oauth-selector.js.map +1 -1
- package/dist/tui/queue-mode-selector.d.ts.map +1 -1
- package/dist/tui/queue-mode-selector.js +3 -10
- package/dist/tui/queue-mode-selector.js.map +1 -1
- package/dist/tui/session-selector.d.ts +1 -0
- package/dist/tui/session-selector.d.ts.map +1 -1
- package/dist/tui/session-selector.js +11 -15
- package/dist/tui/session-selector.js.map +1 -1
- package/dist/tui/theme-selector.d.ts +11 -0
- package/dist/tui/theme-selector.d.ts.map +1 -0
- package/dist/tui/theme-selector.js +46 -0
- package/dist/tui/theme-selector.js.map +1 -0
- package/dist/tui/thinking-selector.d.ts.map +1 -1
- package/dist/tui/thinking-selector.js +3 -10
- package/dist/tui/thinking-selector.js.map +1 -1
- package/dist/tui/tool-execution.d.ts.map +1 -1
- package/dist/tui/tool-execution.js +36 -109
- package/dist/tui/tool-execution.js.map +1 -1
- package/dist/tui/tui-renderer.d.ts +3 -1
- package/dist/tui/tui-renderer.d.ts.map +1 -1
- package/dist/tui/tui-renderer.js +146 -94
- package/dist/tui/tui-renderer.js.map +1 -1
- package/dist/tui/user-message-selector.d.ts +1 -0
- package/dist/tui/user-message-selector.d.ts.map +1 -1
- package/dist/tui/user-message-selector.js +12 -20
- package/dist/tui/user-message-selector.js.map +1 -1
- package/dist/tui/user-message.d.ts +0 -1
- package/dist/tui/user-message.d.ts.map +1 -1
- package/dist/tui/user-message.js +5 -4
- package/dist/tui/user-message.js.map +1 -1
- package/package.json +6 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-selector.d.ts","sourceRoot":"","sources":["../../src/tui/session-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,SAAS,EAAuB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"session-selector.d.ts","sourceRoot":"","sources":["../../src/tui/session-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,SAAS,EAAuB,MAAM,sBAAsB,CAAC;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAI5D,UAAU,WAAW;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,IAAI,CAAC;IACd,QAAQ,EAAE,IAAI,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,cAAM,WAAY,YAAW,SAAS;IACrC,OAAO,CAAC,WAAW,CAAqB;IACxC,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,WAAW,CAAQ;IACpB,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IAC7B,OAAO,CAAC,UAAU,CAAa;IAE/B,YAAY,QAAQ,EAAE,WAAW,EAAE,EAclC;IAED,OAAO,CAAC,cAAc;IAkBtB,UAAU,IAAI,IAAI,CAEjB;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAoE9B;IAED,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CA+BjC;CACD;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,SAAS;IACtD,OAAO,CAAC,WAAW,CAAc;IAEjC,YAAY,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,EAAE,QAAQ,EAAE,MAAM,IAAI,EA4BxG;IAED,cAAc,IAAI,WAAW,CAE5B;CACD","sourcesContent":["import { type Component, Container, Input, Spacer, Text } from \"@mariozechner/pi-tui\";\nimport type { SessionManager } from \"../session-manager.js\";\nimport { theme } from \"../theme/theme.js\";\nimport { DynamicBorder } from \"./dynamic-border.js\";\n\ninterface SessionItem {\n\tpath: string;\n\tid: string;\n\tcreated: Date;\n\tmodified: Date;\n\tmessageCount: number;\n\tfirstMessage: string;\n\tallMessagesText: string;\n}\n\n/**\n * Custom session list component with multi-line items and search\n */\nclass SessionList implements Component {\n\tprivate allSessions: SessionItem[] = [];\n\tprivate filteredSessions: SessionItem[] = [];\n\tprivate selectedIndex: number = 0;\n\tprivate searchInput: Input;\n\tpublic onSelect?: (sessionPath: string) => void;\n\tpublic onCancel?: () => void;\n\tprivate maxVisible: number = 5; // Max sessions visible (each session is 3 lines: msg + metadata + blank)\n\n\tconstructor(sessions: SessionItem[]) {\n\t\tthis.allSessions = sessions;\n\t\tthis.filteredSessions = sessions;\n\t\tthis.searchInput = new Input();\n\n\t\t// Handle Enter in search input - select current item\n\t\tthis.searchInput.onSubmit = () => {\n\t\t\tif (this.filteredSessions[this.selectedIndex]) {\n\t\t\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t\t\tif (this.onSelect) {\n\t\t\t\t\tthis.onSelect(selected.path);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n\tprivate filterSessions(query: string): void {\n\t\tif (!query.trim()) {\n\t\t\tthis.filteredSessions = this.allSessions;\n\t\t} else {\n\t\t\tconst searchTokens = query\n\t\t\t\t.toLowerCase()\n\t\t\t\t.split(/\\s+/)\n\t\t\t\t.filter((t) => t);\n\t\t\tthis.filteredSessions = this.allSessions.filter((session) => {\n\t\t\t\t// Search through all messages in the session\n\t\t\t\tconst searchText = session.allMessagesText.toLowerCase();\n\t\t\t\treturn searchTokens.every((token) => searchText.includes(token));\n\t\t\t});\n\t\t}\n\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredSessions.length - 1));\n\t}\n\n\tinvalidate(): void {\n\t\t// No cached state to invalidate currently\n\t}\n\n\trender(width: number): string[] {\n\t\tconst lines: string[] = [];\n\n\t\t// Render search input\n\t\tlines.push(...this.searchInput.render(width));\n\t\tlines.push(\"\"); // Blank line after search\n\n\t\tif (this.filteredSessions.length === 0) {\n\t\t\tlines.push(theme.fg(\"muted\", \" No sessions found\"));\n\t\t\treturn lines;\n\t\t}\n\n\t\t// Format dates\n\t\tconst formatDate = (date: Date): string => {\n\t\t\tconst now = new Date();\n\t\t\tconst diffMs = now.getTime() - date.getTime();\n\t\t\tconst diffMins = Math.floor(diffMs / 60000);\n\t\t\tconst diffHours = Math.floor(diffMs / 3600000);\n\t\t\tconst diffDays = Math.floor(diffMs / 86400000);\n\n\t\t\tif (diffMins < 1) return \"just now\";\n\t\t\tif (diffMins < 60) return `${diffMins} minute${diffMins !== 1 ? \"s\" : \"\"} ago`;\n\t\t\tif (diffHours < 24) return `${diffHours} hour${diffHours !== 1 ? \"s\" : \"\"} ago`;\n\t\t\tif (diffDays === 1) return \"1 day ago\";\n\t\t\tif (diffDays < 7) return `${diffDays} days ago`;\n\n\t\t\treturn date.toLocaleDateString();\n\t\t};\n\n\t\t// Calculate visible range with scrolling\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredSessions.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredSessions.length);\n\n\t\t// Render visible sessions (2 lines per session + blank line)\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst session = this.filteredSessions[i];\n\t\t\tconst isSelected = i === this.selectedIndex;\n\n\t\t\t// Normalize first message to single line\n\t\t\tconst normalizedMessage = session.firstMessage.replace(/\\n/g, \" \").trim();\n\n\t\t\t// First line: cursor + message\n\t\t\tconst cursor = isSelected ? theme.fg(\"accent\", \"› \") : \" \";\n\t\t\tconst maxMsgWidth = width - 2; // Account for cursor\n\t\t\tconst truncatedMsg = normalizedMessage.substring(0, maxMsgWidth);\n\t\t\tconst messageLine = cursor + (isSelected ? theme.bold(truncatedMsg) : truncatedMsg);\n\n\t\t\t// Second line: metadata (dimmed)\n\t\t\tconst modified = formatDate(session.modified);\n\t\t\tconst msgCount = `${session.messageCount} message${session.messageCount !== 1 ? \"s\" : \"\"}`;\n\t\t\tconst metadata = ` ${modified} · ${msgCount}`;\n\t\t\tconst metadataLine = theme.fg(\"dim\", metadata);\n\n\t\t\tlines.push(messageLine);\n\t\t\tlines.push(metadataLine);\n\t\t\tlines.push(\"\"); // Blank line between sessions\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredSessions.length) {\n\t\t\tconst scrollInfo = theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredSessions.length})`);\n\t\t\tlines.push(scrollInfo);\n\t\t}\n\n\t\treturn lines;\n\t}\n\n\thandleInput(keyData: string): void {\n\t\t// Up arrow\n\t\tif (keyData === \"\\x1b[A\") {\n\t\t\tthis.selectedIndex = Math.max(0, this.selectedIndex - 1);\n\t\t}\n\t\t// Down arrow\n\t\telse if (keyData === \"\\x1b[B\") {\n\t\t\tthis.selectedIndex = Math.min(this.filteredSessions.length - 1, this.selectedIndex + 1);\n\t\t}\n\t\t// Enter\n\t\telse if (keyData === \"\\r\") {\n\t\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t\tif (selected && this.onSelect) {\n\t\t\t\tthis.onSelect(selected.path);\n\t\t\t}\n\t\t}\n\t\t// Escape - cancel\n\t\telse if (keyData === \"\\x1b\") {\n\t\t\tif (this.onCancel) {\n\t\t\t\tthis.onCancel();\n\t\t\t}\n\t\t}\n\t\t// Ctrl+C - exit process\n\t\telse if (keyData === \"\\x03\") {\n\t\t\tprocess.exit(0);\n\t\t}\n\t\t// Pass everything else to search input\n\t\telse {\n\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\tthis.filterSessions(this.searchInput.getValue());\n\t\t}\n\t}\n}\n\n/**\n * Component that renders a session selector\n */\nexport class SessionSelectorComponent extends Container {\n\tprivate sessionList: SessionList;\n\n\tconstructor(sessionManager: SessionManager, onSelect: (sessionPath: string) => void, onCancel: () => void) {\n\t\tsuper();\n\n\t\t// Load all sessions\n\t\tconst sessions = sessionManager.loadAllSessions();\n\n\t\t// Add header\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.bold(\"Resume Session\"), 1, 0));\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Create session list\n\t\tthis.sessionList = new SessionList(sessions);\n\t\tthis.sessionList.onSelect = onSelect;\n\t\tthis.sessionList.onCancel = onCancel;\n\n\t\tthis.addChild(this.sessionList);\n\n\t\t// Add bottom border\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\n\t\t// Auto-cancel if no sessions\n\t\tif (sessions.length === 0) {\n\t\t\tsetTimeout(() => onCancel(), 100);\n\t\t}\n\t}\n\n\tgetSessionList(): SessionList {\n\t\treturn this.sessionList;\n\t}\n}\n"]}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { Container, Input, Spacer, Text } from "@mariozechner/pi-tui";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
* Dynamic border component that adjusts to viewport width
|
|
5
|
-
*/
|
|
6
|
-
class DynamicBorder {
|
|
7
|
-
render(width) {
|
|
8
|
-
return [chalk.blue("─".repeat(Math.max(1, width)))];
|
|
9
|
-
}
|
|
10
|
-
}
|
|
2
|
+
import { theme } from "../theme/theme.js";
|
|
3
|
+
import { DynamicBorder } from "./dynamic-border.js";
|
|
11
4
|
/**
|
|
12
5
|
* Custom session list component with multi-line items and search
|
|
13
6
|
*/
|
|
@@ -50,13 +43,16 @@ class SessionList {
|
|
|
50
43
|
}
|
|
51
44
|
this.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredSessions.length - 1));
|
|
52
45
|
}
|
|
46
|
+
invalidate() {
|
|
47
|
+
// No cached state to invalidate currently
|
|
48
|
+
}
|
|
53
49
|
render(width) {
|
|
54
50
|
const lines = [];
|
|
55
51
|
// Render search input
|
|
56
52
|
lines.push(...this.searchInput.render(width));
|
|
57
53
|
lines.push(""); // Blank line after search
|
|
58
54
|
if (this.filteredSessions.length === 0) {
|
|
59
|
-
lines.push(
|
|
55
|
+
lines.push(theme.fg("muted", " No sessions found"));
|
|
60
56
|
return lines;
|
|
61
57
|
}
|
|
62
58
|
// Format dates
|
|
@@ -88,22 +84,22 @@ class SessionList {
|
|
|
88
84
|
// Normalize first message to single line
|
|
89
85
|
const normalizedMessage = session.firstMessage.replace(/\n/g, " ").trim();
|
|
90
86
|
// First line: cursor + message
|
|
91
|
-
const cursor = isSelected ?
|
|
87
|
+
const cursor = isSelected ? theme.fg("accent", "› ") : " ";
|
|
92
88
|
const maxMsgWidth = width - 2; // Account for cursor
|
|
93
89
|
const truncatedMsg = normalizedMessage.substring(0, maxMsgWidth);
|
|
94
|
-
const messageLine = cursor + (isSelected ?
|
|
90
|
+
const messageLine = cursor + (isSelected ? theme.bold(truncatedMsg) : truncatedMsg);
|
|
95
91
|
// Second line: metadata (dimmed)
|
|
96
92
|
const modified = formatDate(session.modified);
|
|
97
93
|
const msgCount = `${session.messageCount} message${session.messageCount !== 1 ? "s" : ""}`;
|
|
98
94
|
const metadata = ` ${modified} · ${msgCount}`;
|
|
99
|
-
const metadataLine =
|
|
95
|
+
const metadataLine = theme.fg("dim", metadata);
|
|
100
96
|
lines.push(messageLine);
|
|
101
97
|
lines.push(metadataLine);
|
|
102
98
|
lines.push(""); // Blank line between sessions
|
|
103
99
|
}
|
|
104
100
|
// Add scroll indicator if needed
|
|
105
101
|
if (startIndex > 0 || endIndex < this.filteredSessions.length) {
|
|
106
|
-
const scrollInfo =
|
|
102
|
+
const scrollInfo = theme.fg("muted", ` (${this.selectedIndex + 1}/${this.filteredSessions.length})`);
|
|
107
103
|
lines.push(scrollInfo);
|
|
108
104
|
}
|
|
109
105
|
return lines;
|
|
@@ -152,7 +148,7 @@ export class SessionSelectorComponent extends Container {
|
|
|
152
148
|
const sessions = sessionManager.loadAllSessions();
|
|
153
149
|
// Add header
|
|
154
150
|
this.addChild(new Spacer(1));
|
|
155
|
-
this.addChild(new Text(
|
|
151
|
+
this.addChild(new Text(theme.bold("Resume Session"), 1, 0));
|
|
156
152
|
this.addChild(new Spacer(1));
|
|
157
153
|
this.addChild(new DynamicBorder());
|
|
158
154
|
this.addChild(new Spacer(1));
|
|
@@ -1 +1 @@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QAAQ,CAAC,CAAC;QAC7C,IAAI,CAAC,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACrC,IAAI,CAAC,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAErC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAEhC,oBAAoB;QACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,CAAC,QAAQ,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;QAEnC,6BAA6B;QAC7B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,CAAC;QACnC,CAAC;IAAA,CACD;IAED,cAAc,GAAgB;QAC7B,OAAO,IAAI,CAAC,WAAW,CAAC;IAAA,CACxB;CACD","sourcesContent":["import { type Component, Container, Input, Spacer, Text } from \"@mariozechner/pi-tui\";\nimport chalk from \"chalk\";\nimport type { SessionManager } from \"../session-manager.js\";\n\n/**\n * Dynamic border component that adjusts to viewport width\n */\nclass DynamicBorder implements Component {\n\trender(width: number): string[] {\n\t\treturn [chalk.blue(\"─\".repeat(Math.max(1, width)))];\n\t}\n}\n\ninterface SessionItem {\n\tpath: string;\n\tid: string;\n\tcreated: Date;\n\tmodified: Date;\n\tmessageCount: number;\n\tfirstMessage: string;\n\tallMessagesText: string;\n}\n\n/**\n * Custom session list component with multi-line items and search\n */\nclass SessionList implements Component {\n\tprivate allSessions: SessionItem[] = [];\n\tprivate filteredSessions: SessionItem[] = [];\n\tprivate selectedIndex: number = 0;\n\tprivate searchInput: Input;\n\tpublic onSelect?: (sessionPath: string) => void;\n\tpublic onCancel?: () => void;\n\tprivate maxVisible: number = 5; // Max sessions visible (each session is 3 lines: msg + metadata + blank)\n\n\tconstructor(sessions: SessionItem[]) {\n\t\tthis.allSessions = sessions;\n\t\tthis.filteredSessions = sessions;\n\t\tthis.searchInput = new Input();\n\n\t\t// Handle Enter in search input - select current item\n\t\tthis.searchInput.onSubmit = () => {\n\t\t\tif (this.filteredSessions[this.selectedIndex]) {\n\t\t\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t\t\tif (this.onSelect) {\n\t\t\t\t\tthis.onSelect(selected.path);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n\tprivate filterSessions(query: string): void {\n\t\tif (!query.trim()) {\n\t\t\tthis.filteredSessions = this.allSessions;\n\t\t} else {\n\t\t\tconst searchTokens = query\n\t\t\t\t.toLowerCase()\n\t\t\t\t.split(/\\s+/)\n\t\t\t\t.filter((t) => t);\n\t\t\tthis.filteredSessions = this.allSessions.filter((session) => {\n\t\t\t\t// Search through all messages in the session\n\t\t\t\tconst searchText = session.allMessagesText.toLowerCase();\n\t\t\t\treturn searchTokens.every((token) => searchText.includes(token));\n\t\t\t});\n\t\t}\n\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredSessions.length - 1));\n\t}\n\n\trender(width: number): string[] {\n\t\tconst lines: string[] = [];\n\n\t\t// Render search input\n\t\tlines.push(...this.searchInput.render(width));\n\t\tlines.push(\"\"); // Blank line after search\n\n\t\tif (this.filteredSessions.length === 0) {\n\t\t\tlines.push(chalk.gray(\" No sessions found\"));\n\t\t\treturn lines;\n\t\t}\n\n\t\t// Format dates\n\t\tconst formatDate = (date: Date): string => {\n\t\t\tconst now = new Date();\n\t\t\tconst diffMs = now.getTime() - date.getTime();\n\t\t\tconst diffMins = Math.floor(diffMs / 60000);\n\t\t\tconst diffHours = Math.floor(diffMs / 3600000);\n\t\t\tconst diffDays = Math.floor(diffMs / 86400000);\n\n\t\t\tif (diffMins < 1) return \"just now\";\n\t\t\tif (diffMins < 60) return `${diffMins} minute${diffMins !== 1 ? \"s\" : \"\"} ago`;\n\t\t\tif (diffHours < 24) return `${diffHours} hour${diffHours !== 1 ? \"s\" : \"\"} ago`;\n\t\t\tif (diffDays === 1) return \"1 day ago\";\n\t\t\tif (diffDays < 7) return `${diffDays} days ago`;\n\n\t\t\treturn date.toLocaleDateString();\n\t\t};\n\n\t\t// Calculate visible range with scrolling\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredSessions.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredSessions.length);\n\n\t\t// Render visible sessions (2 lines per session + blank line)\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst session = this.filteredSessions[i];\n\t\t\tconst isSelected = i === this.selectedIndex;\n\n\t\t\t// Normalize first message to single line\n\t\t\tconst normalizedMessage = session.firstMessage.replace(/\\n/g, \" \").trim();\n\n\t\t\t// First line: cursor + message\n\t\t\tconst cursor = isSelected ? chalk.blue(\"› \") : \" \";\n\t\t\tconst maxMsgWidth = width - 2; // Account for cursor\n\t\t\tconst truncatedMsg = normalizedMessage.substring(0, maxMsgWidth);\n\t\t\tconst messageLine = cursor + (isSelected ? chalk.bold(truncatedMsg) : truncatedMsg);\n\n\t\t\t// Second line: metadata (dimmed)\n\t\t\tconst modified = formatDate(session.modified);\n\t\t\tconst msgCount = `${session.messageCount} message${session.messageCount !== 1 ? \"s\" : \"\"}`;\n\t\t\tconst metadata = ` ${modified} · ${msgCount}`;\n\t\t\tconst metadataLine = chalk.dim(metadata);\n\n\t\t\tlines.push(messageLine);\n\t\t\tlines.push(metadataLine);\n\t\t\tlines.push(\"\"); // Blank line between sessions\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredSessions.length) {\n\t\t\tconst scrollInfo = chalk.gray(` (${this.selectedIndex + 1}/${this.filteredSessions.length})`);\n\t\t\tlines.push(scrollInfo);\n\t\t}\n\n\t\treturn lines;\n\t}\n\n\thandleInput(keyData: string): void {\n\t\t// Up arrow\n\t\tif (keyData === \"\\x1b[A\") {\n\t\t\tthis.selectedIndex = Math.max(0, this.selectedIndex - 1);\n\t\t}\n\t\t// Down arrow\n\t\telse if (keyData === \"\\x1b[B\") {\n\t\t\tthis.selectedIndex = Math.min(this.filteredSessions.length - 1, this.selectedIndex + 1);\n\t\t}\n\t\t// Enter\n\t\telse if (keyData === \"\\r\") {\n\t\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t\tif (selected && this.onSelect) {\n\t\t\t\tthis.onSelect(selected.path);\n\t\t\t}\n\t\t}\n\t\t// Escape - cancel\n\t\telse if (keyData === \"\\x1b\") {\n\t\t\tif (this.onCancel) {\n\t\t\t\tthis.onCancel();\n\t\t\t}\n\t\t}\n\t\t// Ctrl+C - exit process\n\t\telse if (keyData === \"\\x03\") {\n\t\t\tprocess.exit(0);\n\t\t}\n\t\t// Pass everything else to search input\n\t\telse {\n\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\tthis.filterSessions(this.searchInput.getValue());\n\t\t}\n\t}\n}\n\n/**\n * Component that renders a session selector\n */\nexport class SessionSelectorComponent extends Container {\n\tprivate sessionList: SessionList;\n\n\tconstructor(sessionManager: SessionManager, onSelect: (sessionPath: string) => void, onCancel: () => void) {\n\t\tsuper();\n\n\t\t// Load all sessions\n\t\tconst sessions = sessionManager.loadAllSessions();\n\n\t\t// Add header\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(chalk.bold(\"Resume Session\"), 1, 0));\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Create session list\n\t\tthis.sessionList = new SessionList(sessions);\n\t\tthis.sessionList.onSelect = onSelect;\n\t\tthis.sessionList.onCancel = onCancel;\n\n\t\tthis.addChild(this.sessionList);\n\n\t\t// Add bottom border\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\n\t\t// Auto-cancel if no sessions\n\t\tif (sessions.length === 0) {\n\t\t\tsetTimeout(() => onCancel(), 100);\n\t\t}\n\t}\n\n\tgetSessionList(): SessionList {\n\t\treturn this.sessionList;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session-selector.js","sourceRoot":"","sources":["../../src/tui/session-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEtF,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAYpD;;GAEG;AACH,MAAM,WAAW;IACR,WAAW,GAAkB,EAAE,CAAC;IAChC,gBAAgB,GAAkB,EAAE,CAAC;IACrC,aAAa,GAAW,CAAC,CAAC;IAC1B,WAAW,CAAQ;IACpB,QAAQ,CAAiC;IACzC,QAAQ,CAAc;IACrB,UAAU,GAAW,CAAC,CAAC,CAAC,yEAAyE;IAEzG,YAAY,QAAuB,EAAE;QACpC,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC;QAC5B,IAAI,CAAC,gBAAgB,GAAG,QAAQ,CAAC;QACjC,IAAI,CAAC,WAAW,GAAG,IAAI,KAAK,EAAE,CAAC;QAE/B,qDAAqD;QACrD,IAAI,CAAC,WAAW,CAAC,QAAQ,GAAG,GAAG,EAAE,CAAC;YACjC,IAAI,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC;gBAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;gBAC3D,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;oBACnB,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;gBAC9B,CAAC;YACF,CAAC;QAAA,CACD,CAAC;IAAA,CACF;IAEO,cAAc,CAAC,KAAa,EAAQ;QAC3C,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE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AW,GAAG,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC7C,IAAI,CAAC,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACrC,IAAI,CAAC,WAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAErC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAEhC,oBAAoB;QACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7B,IAAI,CAAC,QAAQ,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;QAEnC,6BAA6B;QAC7B,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,CAAC;QACnC,CAAC;IAAA,CACD;IAED,cAAc,GAAgB;QAC7B,OAAO,IAAI,CAAC,WAAW,CAAC;IAAA,CACxB;CACD","sourcesContent":["import { type Component, Container, Input, Spacer, Text } from \"@mariozechner/pi-tui\";\nimport type { SessionManager } from \"../session-manager.js\";\nimport { theme } from \"../theme/theme.js\";\nimport { DynamicBorder } from \"./dynamic-border.js\";\n\ninterface SessionItem {\n\tpath: string;\n\tid: string;\n\tcreated: Date;\n\tmodified: Date;\n\tmessageCount: number;\n\tfirstMessage: string;\n\tallMessagesText: string;\n}\n\n/**\n * Custom session list component with multi-line items and search\n */\nclass SessionList implements Component {\n\tprivate allSessions: SessionItem[] = [];\n\tprivate filteredSessions: SessionItem[] = [];\n\tprivate selectedIndex: number = 0;\n\tprivate searchInput: Input;\n\tpublic onSelect?: (sessionPath: string) => void;\n\tpublic onCancel?: () => void;\n\tprivate maxVisible: number = 5; // Max sessions visible (each session is 3 lines: msg + metadata + blank)\n\n\tconstructor(sessions: SessionItem[]) {\n\t\tthis.allSessions = sessions;\n\t\tthis.filteredSessions = sessions;\n\t\tthis.searchInput = new Input();\n\n\t\t// Handle Enter in search input - select current item\n\t\tthis.searchInput.onSubmit = () => {\n\t\t\tif (this.filteredSessions[this.selectedIndex]) {\n\t\t\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t\t\tif (this.onSelect) {\n\t\t\t\t\tthis.onSelect(selected.path);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n\tprivate filterSessions(query: string): void {\n\t\tif (!query.trim()) {\n\t\t\tthis.filteredSessions = this.allSessions;\n\t\t} else {\n\t\t\tconst searchTokens = query\n\t\t\t\t.toLowerCase()\n\t\t\t\t.split(/\\s+/)\n\t\t\t\t.filter((t) => t);\n\t\t\tthis.filteredSessions = this.allSessions.filter((session) => {\n\t\t\t\t// Search through all messages in the session\n\t\t\t\tconst searchText = session.allMessagesText.toLowerCase();\n\t\t\t\treturn searchTokens.every((token) => searchText.includes(token));\n\t\t\t});\n\t\t}\n\n\t\tthis.selectedIndex = Math.min(this.selectedIndex, Math.max(0, this.filteredSessions.length - 1));\n\t}\n\n\tinvalidate(): void {\n\t\t// No cached state to invalidate currently\n\t}\n\n\trender(width: number): string[] {\n\t\tconst lines: string[] = [];\n\n\t\t// Render search input\n\t\tlines.push(...this.searchInput.render(width));\n\t\tlines.push(\"\"); // Blank line after search\n\n\t\tif (this.filteredSessions.length === 0) {\n\t\t\tlines.push(theme.fg(\"muted\", \" No sessions found\"));\n\t\t\treturn lines;\n\t\t}\n\n\t\t// Format dates\n\t\tconst formatDate = (date: Date): string => {\n\t\t\tconst now = new Date();\n\t\t\tconst diffMs = now.getTime() - date.getTime();\n\t\t\tconst diffMins = Math.floor(diffMs / 60000);\n\t\t\tconst diffHours = Math.floor(diffMs / 3600000);\n\t\t\tconst diffDays = Math.floor(diffMs / 86400000);\n\n\t\t\tif (diffMins < 1) return \"just now\";\n\t\t\tif (diffMins < 60) return `${diffMins} minute${diffMins !== 1 ? \"s\" : \"\"} ago`;\n\t\t\tif (diffHours < 24) return `${diffHours} hour${diffHours !== 1 ? \"s\" : \"\"} ago`;\n\t\t\tif (diffDays === 1) return \"1 day ago\";\n\t\t\tif (diffDays < 7) return `${diffDays} days ago`;\n\n\t\t\treturn date.toLocaleDateString();\n\t\t};\n\n\t\t// Calculate visible range with scrolling\n\t\tconst startIndex = Math.max(\n\t\t\t0,\n\t\t\tMath.min(this.selectedIndex - Math.floor(this.maxVisible / 2), this.filteredSessions.length - this.maxVisible),\n\t\t);\n\t\tconst endIndex = Math.min(startIndex + this.maxVisible, this.filteredSessions.length);\n\n\t\t// Render visible sessions (2 lines per session + blank line)\n\t\tfor (let i = startIndex; i < endIndex; i++) {\n\t\t\tconst session = this.filteredSessions[i];\n\t\t\tconst isSelected = i === this.selectedIndex;\n\n\t\t\t// Normalize first message to single line\n\t\t\tconst normalizedMessage = session.firstMessage.replace(/\\n/g, \" \").trim();\n\n\t\t\t// First line: cursor + message\n\t\t\tconst cursor = isSelected ? theme.fg(\"accent\", \"› \") : \" \";\n\t\t\tconst maxMsgWidth = width - 2; // Account for cursor\n\t\t\tconst truncatedMsg = normalizedMessage.substring(0, maxMsgWidth);\n\t\t\tconst messageLine = cursor + (isSelected ? theme.bold(truncatedMsg) : truncatedMsg);\n\n\t\t\t// Second line: metadata (dimmed)\n\t\t\tconst modified = formatDate(session.modified);\n\t\t\tconst msgCount = `${session.messageCount} message${session.messageCount !== 1 ? \"s\" : \"\"}`;\n\t\t\tconst metadata = ` ${modified} · ${msgCount}`;\n\t\t\tconst metadataLine = theme.fg(\"dim\", metadata);\n\n\t\t\tlines.push(messageLine);\n\t\t\tlines.push(metadataLine);\n\t\t\tlines.push(\"\"); // Blank line between sessions\n\t\t}\n\n\t\t// Add scroll indicator if needed\n\t\tif (startIndex > 0 || endIndex < this.filteredSessions.length) {\n\t\t\tconst scrollInfo = theme.fg(\"muted\", ` (${this.selectedIndex + 1}/${this.filteredSessions.length})`);\n\t\t\tlines.push(scrollInfo);\n\t\t}\n\n\t\treturn lines;\n\t}\n\n\thandleInput(keyData: string): void {\n\t\t// Up arrow\n\t\tif (keyData === \"\\x1b[A\") {\n\t\t\tthis.selectedIndex = Math.max(0, this.selectedIndex - 1);\n\t\t}\n\t\t// Down arrow\n\t\telse if (keyData === \"\\x1b[B\") {\n\t\t\tthis.selectedIndex = Math.min(this.filteredSessions.length - 1, this.selectedIndex + 1);\n\t\t}\n\t\t// Enter\n\t\telse if (keyData === \"\\r\") {\n\t\t\tconst selected = this.filteredSessions[this.selectedIndex];\n\t\t\tif (selected && this.onSelect) {\n\t\t\t\tthis.onSelect(selected.path);\n\t\t\t}\n\t\t}\n\t\t// Escape - cancel\n\t\telse if (keyData === \"\\x1b\") {\n\t\t\tif (this.onCancel) {\n\t\t\t\tthis.onCancel();\n\t\t\t}\n\t\t}\n\t\t// Ctrl+C - exit process\n\t\telse if (keyData === \"\\x03\") {\n\t\t\tprocess.exit(0);\n\t\t}\n\t\t// Pass everything else to search input\n\t\telse {\n\t\t\tthis.searchInput.handleInput(keyData);\n\t\t\tthis.filterSessions(this.searchInput.getValue());\n\t\t}\n\t}\n}\n\n/**\n * Component that renders a session selector\n */\nexport class SessionSelectorComponent extends Container {\n\tprivate sessionList: SessionList;\n\n\tconstructor(sessionManager: SessionManager, onSelect: (sessionPath: string) => void, onCancel: () => void) {\n\t\tsuper();\n\n\t\t// Load all sessions\n\t\tconst sessions = sessionManager.loadAllSessions();\n\n\t\t// Add header\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new Text(theme.bold(\"Resume Session\"), 1, 0));\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\t\tthis.addChild(new Spacer(1));\n\n\t\t// Create session list\n\t\tthis.sessionList = new SessionList(sessions);\n\t\tthis.sessionList.onSelect = onSelect;\n\t\tthis.sessionList.onCancel = onCancel;\n\n\t\tthis.addChild(this.sessionList);\n\n\t\t// Add bottom border\n\t\tthis.addChild(new Spacer(1));\n\t\tthis.addChild(new DynamicBorder());\n\n\t\t// Auto-cancel if no sessions\n\t\tif (sessions.length === 0) {\n\t\t\tsetTimeout(() => onCancel(), 100);\n\t\t}\n\t}\n\n\tgetSessionList(): SessionList {\n\t\treturn this.sessionList;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Container, SelectList } from "@mariozechner/pi-tui";
|
|
2
|
+
/**
|
|
3
|
+
* Component that renders a theme selector
|
|
4
|
+
*/
|
|
5
|
+
export declare class ThemeSelectorComponent extends Container {
|
|
6
|
+
private selectList;
|
|
7
|
+
private onPreview;
|
|
8
|
+
constructor(currentTheme: string, onSelect: (themeName: string) => void, onCancel: () => void, onPreview: (themeName: string) => void);
|
|
9
|
+
getSelectList(): SelectList;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=theme-selector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-selector.d.ts","sourceRoot":"","sources":["../../src/tui/theme-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmB,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAI9E;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,SAAS;IACpD,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,SAAS,CAA8B;IAE/C,YACC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,EACrC,QAAQ,EAAE,MAAM,IAAI,EACpB,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,EAyCtC;IAED,aAAa,IAAI,UAAU,CAE1B;CACD","sourcesContent":["import { Container, type SelectItem, SelectList } from \"@mariozechner/pi-tui\";\nimport { getAvailableThemes, getSelectListTheme } from \"../theme/theme.js\";\nimport { DynamicBorder } from \"./dynamic-border.js\";\n\n/**\n * Component that renders a theme selector\n */\nexport class ThemeSelectorComponent extends Container {\n\tprivate selectList: SelectList;\n\tprivate onPreview: (themeName: string) => void;\n\n\tconstructor(\n\t\tcurrentTheme: string,\n\t\tonSelect: (themeName: string) => void,\n\t\tonCancel: () => void,\n\t\tonPreview: (themeName: string) => void,\n\t) {\n\t\tsuper();\n\t\tthis.onPreview = onPreview;\n\n\t\t// Get available themes and create select items\n\t\tconst themes = getAvailableThemes();\n\t\tconst themeItems: SelectItem[] = themes.map((name) => ({\n\t\t\tvalue: name,\n\t\t\tlabel: name,\n\t\t\tdescription: name === currentTheme ? \"(current)\" : undefined,\n\t\t}));\n\n\t\t// Add top border\n\t\tthis.addChild(new DynamicBorder());\n\n\t\t// Create selector\n\t\tthis.selectList = new SelectList(themeItems, 10, getSelectListTheme());\n\n\t\t// Preselect current theme\n\t\tconst currentIndex = themes.indexOf(currentTheme);\n\t\tif (currentIndex !== -1) {\n\t\t\tthis.selectList.setSelectedIndex(currentIndex);\n\t\t}\n\n\t\tthis.selectList.onSelect = (item) => {\n\t\t\tonSelect(item.value);\n\t\t};\n\n\t\tthis.selectList.onCancel = () => {\n\t\t\tonCancel();\n\t\t};\n\n\t\tthis.selectList.onSelectionChange = (item) => {\n\t\t\tthis.onPreview(item.value);\n\t\t};\n\n\t\tthis.addChild(this.selectList);\n\n\t\t// Add bottom border\n\t\tthis.addChild(new DynamicBorder());\n\t}\n\n\tgetSelectList(): SelectList {\n\t\treturn this.selectList;\n\t}\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Container, SelectList } from "@mariozechner/pi-tui";
|
|
2
|
+
import { getAvailableThemes, getSelectListTheme } from "../theme/theme.js";
|
|
3
|
+
import { DynamicBorder } from "./dynamic-border.js";
|
|
4
|
+
/**
|
|
5
|
+
* Component that renders a theme selector
|
|
6
|
+
*/
|
|
7
|
+
export class ThemeSelectorComponent extends Container {
|
|
8
|
+
selectList;
|
|
9
|
+
onPreview;
|
|
10
|
+
constructor(currentTheme, onSelect, onCancel, onPreview) {
|
|
11
|
+
super();
|
|
12
|
+
this.onPreview = onPreview;
|
|
13
|
+
// Get available themes and create select items
|
|
14
|
+
const themes = getAvailableThemes();
|
|
15
|
+
const themeItems = themes.map((name) => ({
|
|
16
|
+
value: name,
|
|
17
|
+
label: name,
|
|
18
|
+
description: name === currentTheme ? "(current)" : undefined,
|
|
19
|
+
}));
|
|
20
|
+
// Add top border
|
|
21
|
+
this.addChild(new DynamicBorder());
|
|
22
|
+
// Create selector
|
|
23
|
+
this.selectList = new SelectList(themeItems, 10, getSelectListTheme());
|
|
24
|
+
// Preselect current theme
|
|
25
|
+
const currentIndex = themes.indexOf(currentTheme);
|
|
26
|
+
if (currentIndex !== -1) {
|
|
27
|
+
this.selectList.setSelectedIndex(currentIndex);
|
|
28
|
+
}
|
|
29
|
+
this.selectList.onSelect = (item) => {
|
|
30
|
+
onSelect(item.value);
|
|
31
|
+
};
|
|
32
|
+
this.selectList.onCancel = () => {
|
|
33
|
+
onCancel();
|
|
34
|
+
};
|
|
35
|
+
this.selectList.onSelectionChange = (item) => {
|
|
36
|
+
this.onPreview(item.value);
|
|
37
|
+
};
|
|
38
|
+
this.addChild(this.selectList);
|
|
39
|
+
// Add bottom border
|
|
40
|
+
this.addChild(new DynamicBorder());
|
|
41
|
+
}
|
|
42
|
+
getSelectList() {
|
|
43
|
+
return this.selectList;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=theme-selector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-selector.js","sourceRoot":"","sources":["../../src/tui/theme-selector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmB,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,sBAAuB,SAAQ,SAAS;IAC5C,UAAU,CAAa;IACvB,SAAS,CAA8B;IAE/C,YACC,YAAoB,EACpB,QAAqC,EACrC,QAAoB,EACpB,SAAs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AE/B,oBAAoB;QACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;IAAA,CACnC;IAED,aAAa,GAAe;QAC3B,OAAO,IAAI,CAAC,UAAU,CAAC;IAAA,CACvB;CACD","sourcesContent":["import { Container, type SelectItem, SelectList } from \"@mariozechner/pi-tui\";\nimport { getAvailableThemes, getSelectListTheme } from \"../theme/theme.js\";\nimport { DynamicBorder } from \"./dynamic-border.js\";\n\n/**\n * Component that renders a theme selector\n */\nexport class ThemeSelectorComponent extends Container {\n\tprivate selectList: SelectList;\n\tprivate onPreview: (themeName: string) => void;\n\n\tconstructor(\n\t\tcurrentTheme: string,\n\t\tonSelect: (themeName: string) => void,\n\t\tonCancel: () => void,\n\t\tonPreview: (themeName: string) => void,\n\t) {\n\t\tsuper();\n\t\tthis.onPreview = onPreview;\n\n\t\t// Get available themes and create select items\n\t\tconst themes = getAvailableThemes();\n\t\tconst themeItems: SelectItem[] = themes.map((name) => ({\n\t\t\tvalue: name,\n\t\t\tlabel: name,\n\t\t\tdescription: name === currentTheme ? \"(current)\" : undefined,\n\t\t}));\n\n\t\t// Add top border\n\t\tthis.addChild(new DynamicBorder());\n\n\t\t// Create selector\n\t\tthis.selectList = new SelectList(themeItems, 10, getSelectListTheme());\n\n\t\t// Preselect current theme\n\t\tconst currentIndex = themes.indexOf(currentTheme);\n\t\tif (currentIndex !== -1) {\n\t\t\tthis.selectList.setSelectedIndex(currentIndex);\n\t\t}\n\n\t\tthis.selectList.onSelect = (item) => {\n\t\t\tonSelect(item.value);\n\t\t};\n\n\t\tthis.selectList.onCancel = () => {\n\t\t\tonCancel();\n\t\t};\n\n\t\tthis.selectList.onSelectionChange = (item) => {\n\t\t\tthis.onPreview(item.value);\n\t\t};\n\n\t\tthis.addChild(this.selectList);\n\n\t\t// Add bottom border\n\t\tthis.addChild(new DynamicBorder());\n\t}\n\n\tgetSelectList(): SelectList {\n\t\treturn this.selectList;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thinking-selector.d.ts","sourceRoot":"","sources":["../../src/tui/thinking-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"thinking-selector.d.ts","sourceRoot":"","sources":["../../src/tui/thinking-selector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAmB,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAI9E;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,OAAO,CAAC,UAAU,CAAa;IAE/B,YAAY,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EAAE,QAAQ,EAAE,MAAM,IAAI,EAmCtG;IAED,aAAa,IAAI,UAAU,CAE1B;CACD","sourcesContent":["import type { ThinkingLevel } from \"@mariozechner/pi-agent\";\nimport { Container, type SelectItem, SelectList } from \"@mariozechner/pi-tui\";\nimport { getSelectListTheme } from \"../theme/theme.js\";\nimport { DynamicBorder } from \"./dynamic-border.js\";\n\n/**\n * Component that renders a thinking level selector with borders\n */\nexport class ThinkingSelectorComponent extends Container {\n\tprivate selectList: SelectList;\n\n\tconstructor(currentLevel: ThinkingLevel, onSelect: (level: ThinkingLevel) => void, onCancel: () => void) {\n\t\tsuper();\n\n\t\tconst thinkingLevels: SelectItem[] = [\n\t\t\t{ value: \"off\", label: \"off\", description: \"No reasoning\" },\n\t\t\t{ value: \"minimal\", label: \"minimal\", description: \"Very brief reasoning (~1k tokens)\" },\n\t\t\t{ value: \"low\", label: \"low\", description: \"Light reasoning (~2k tokens)\" },\n\t\t\t{ value: \"medium\", label: \"medium\", description: \"Moderate reasoning (~8k tokens)\" },\n\t\t\t{ value: \"high\", label: \"high\", description: \"Deep reasoning (~16k tokens)\" },\n\t\t];\n\n\t\t// Add top border\n\t\tthis.addChild(new DynamicBorder());\n\n\t\t// Create selector\n\t\tthis.selectList = new SelectList(thinkingLevels, 5, getSelectListTheme());\n\n\t\t// Preselect current level\n\t\tconst currentIndex = thinkingLevels.findIndex((item) => item.value === currentLevel);\n\t\tif (currentIndex !== -1) {\n\t\t\tthis.selectList.setSelectedIndex(currentIndex);\n\t\t}\n\n\t\tthis.selectList.onSelect = (item) => {\n\t\t\tonSelect(item.value as ThinkingLevel);\n\t\t};\n\n\t\tthis.selectList.onCancel = () => {\n\t\t\tonCancel();\n\t\t};\n\n\t\tthis.addChild(this.selectList);\n\n\t\t// Add bottom border\n\t\tthis.addChild(new DynamicBorder());\n\t}\n\n\tgetSelectList(): SelectList {\n\t\treturn this.selectList;\n\t}\n}\n"]}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { Container, SelectList } from "@mariozechner/pi-tui";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
* Dynamic border component that adjusts to viewport width
|
|
5
|
-
*/
|
|
6
|
-
class DynamicBorder {
|
|
7
|
-
render(width) {
|
|
8
|
-
return [chalk.blue("─".repeat(Math.max(1, width)))];
|
|
9
|
-
}
|
|
10
|
-
}
|
|
2
|
+
import { getSelectListTheme } from "../theme/theme.js";
|
|
3
|
+
import { DynamicBorder } from "./dynamic-border.js";
|
|
11
4
|
/**
|
|
12
5
|
* Component that renders a thinking level selector with borders
|
|
13
6
|
*/
|
|
@@ -25,7 +18,7 @@ export class ThinkingSelectorComponent extends Container {
|
|
|
25
18
|
// Add top border
|
|
26
19
|
this.addChild(new DynamicBorder());
|
|
27
20
|
// Create selector
|
|
28
|
-
this.selectList = new SelectList(thinkingLevels, 5);
|
|
21
|
+
this.selectList = new SelectList(thinkingLevels, 5, getSelectListTheme());
|
|
29
22
|
// Preselect current level
|
|
30
23
|
const currentIndex = thinkingLevels.findIndex((item) => item.value === currentLevel);
|
|
31
24
|
if (currentIndex !== -1) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thinking-selector.js","sourceRoot":"","sources":["../../src/tui/thinking-selector.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"thinking-selector.js","sourceRoot":"","sources":["../../src/tui/thinking-selector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAmB,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,SAAS;IAC/C,UAAU,CAAa;IAE/B,YAAY,YAA2B,EAAE,QAAwC,EAAE,QAAoB,EAAE;QACxG,KAAK,EAAE,CAAC;QAER,MAAM,cAAc,GAAiB;YACpC,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE;YAC3D,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,mCAAmC,EAAE;YACxF,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,8BAA8B,EAAE;YAC3E,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,iCAAiC,EAAE;YACpF,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,8BAA8B,EAAE;SAC7E,CAAC;QAEF,iBAAiB;QACjB,IAAI,CAAC,QAAQ,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;QAEnC,kBAAkB;QAClB,IAAI,CAAC,UAAU,GAAG,IAAI,UAAU,CAAC,cAAc,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC,CAAC;QAE1E,0BAA0B;QAC1B,MAAM,YAAY,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,KAAK,YAAY,CAAC,CAAC;QACrF,IAAI,YAAY,KAAK,CAAC,CAAC,EAAE,CAAC;YACzB,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;QAChD,CAAC;QAED,IAAI,CAAC,UAAU,CAAC,QAAQ,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;YACpC,QAAQ,CAAC,IAAI,CAAC,KAAsB,CAAC,CAAC;QAAA,CACtC,CAAC;QAEF,IAAI,CAAC,UAAU,CAAC,QAAQ,GAAG,GAAG,EAAE,CAAC;YAChC,QAAQ,EAAE,CAAC;QAAA,CACX,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE/B,oBAAoB;QACpB,IAAI,CAAC,QAAQ,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;IAAA,CACnC;IAED,aAAa,GAAe;QAC3B,OAAO,IAAI,CAAC,UAAU,CAAC;IAAA,CACvB;CACD","sourcesContent":["import type { ThinkingLevel } from \"@mariozechner/pi-agent\";\nimport { Container, type SelectItem, SelectList } from \"@mariozechner/pi-tui\";\nimport { getSelectListTheme } from \"../theme/theme.js\";\nimport { DynamicBorder } from \"./dynamic-border.js\";\n\n/**\n * Component that renders a thinking level selector with borders\n */\nexport class ThinkingSelectorComponent extends Container {\n\tprivate selectList: SelectList;\n\n\tconstructor(currentLevel: ThinkingLevel, onSelect: (level: ThinkingLevel) => void, onCancel: () => void) {\n\t\tsuper();\n\n\t\tconst thinkingLevels: SelectItem[] = [\n\t\t\t{ value: \"off\", label: \"off\", description: \"No reasoning\" },\n\t\t\t{ value: \"minimal\", label: \"minimal\", description: \"Very brief reasoning (~1k tokens)\" },\n\t\t\t{ value: \"low\", label: \"low\", description: \"Light reasoning (~2k tokens)\" },\n\t\t\t{ value: \"medium\", label: \"medium\", description: \"Moderate reasoning (~8k tokens)\" },\n\t\t\t{ value: \"high\", label: \"high\", description: \"Deep reasoning (~16k tokens)\" },\n\t\t];\n\n\t\t// Add top border\n\t\tthis.addChild(new DynamicBorder());\n\n\t\t// Create selector\n\t\tthis.selectList = new SelectList(thinkingLevels, 5, getSelectListTheme());\n\n\t\t// Preselect current level\n\t\tconst currentIndex = thinkingLevels.findIndex((item) => item.value === currentLevel);\n\t\tif (currentIndex !== -1) {\n\t\t\tthis.selectList.setSelectedIndex(currentIndex);\n\t\t}\n\n\t\tthis.selectList.onSelect = (item) => {\n\t\t\tonSelect(item.value as ThinkingLevel);\n\t\t};\n\n\t\tthis.selectList.onCancel = () => {\n\t\t\tonCancel();\n\t\t};\n\n\t\tthis.addChild(this.selectList);\n\n\t\t// Add bottom border\n\t\tthis.addChild(new DynamicBorder());\n\t}\n\n\tgetSelectList(): SelectList {\n\t\treturn this.selectList;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-execution.d.ts","sourceRoot":"","sources":["../../src/tui/tool-execution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAgB,MAAM,sBAAsB,CAAC;AAyH/D;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,SAAS;IACpD,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAC,CAIb;IAEF,YAAY,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAStC;IAED,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,CAG1B;IAED,YAAY,CAAC,MAAM,EAAE;QACpB,OAAO,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAClF,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,OAAO,EAAE,OAAO,CAAC;KACjB,GAAG,IAAI,CAGP;IAED,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAGnC;IAED,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,mBAAmB;CAqG3B","sourcesContent":["import * as os from \"node:os\";\nimport { Container, Spacer, Text } from \"@mariozechner/pi-tui\";\nimport chalk from \"chalk\";\nimport * as Diff from \"diff\";\nimport stripAnsi from \"strip-ansi\";\n\n/**\n * Convert absolute path to tilde notation if it's in home directory\n */\nfunction shortenPath(path: string): string {\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn \"~\" + path.slice(home.length);\n\t}\n\treturn path;\n}\n\n/**\n * Replace tabs with spaces for consistent rendering\n */\nfunction replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\n/**\n * Generate a unified diff with line numbers and context\n */\nfunction generateDiff(oldStr: string, newStr: string): string {\n\tconst parts = Diff.diffLines(oldStr, newStr);\n\tconst output: string[] = [];\n\n\t// Calculate max line number for padding\n\tconst oldLines = oldStr.split(\"\\n\");\n\tconst newLines = newStr.split(\"\\n\");\n\tconst maxLineNum = Math.max(oldLines.length, newLines.length);\n\tconst lineNumWidth = String(maxLineNum).length;\n\n\tconst CONTEXT_LINES = 2; // Show 2 lines of context around changes\n\n\tlet oldLineNum = 1;\n\tlet newLineNum = 1;\n\tlet lastWasChange = false;\n\n\tfor (let i = 0; i < parts.length; i++) {\n\t\tconst part = parts[i];\n\t\tconst raw = part.value.split(\"\\n\");\n\t\tif (raw[raw.length - 1] === \"\") {\n\t\t\traw.pop();\n\t\t}\n\n\t\tif (part.added || part.removed) {\n\t\t\t// Show the change\n\t\t\tfor (const line of raw) {\n\t\t\t\tif (part.added) {\n\t\t\t\t\tconst lineNum = String(newLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(chalk.green(`${lineNum} ${line}`));\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t} else {\n\t\t\t\t\t// removed\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(chalk.red(`${lineNum} ${line}`));\n\t\t\t\t\toldLineNum++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlastWasChange = true;\n\t\t} else {\n\t\t\t// Context lines - only show a few before/after changes\n\t\t\tconst isFirstPart = i === 0;\n\t\t\tconst isLastPart = i === parts.length - 1;\n\t\t\tconst nextPartIsChange = i < parts.length - 1 && (parts[i + 1].added || parts[i + 1].removed);\n\n\t\t\tif (lastWasChange || nextPartIsChange || isFirstPart || isLastPart) {\n\t\t\t\t// Show context\n\t\t\t\tlet linesToShow = raw;\n\t\t\t\tlet skipStart = 0;\n\t\t\t\tlet skipEnd = 0;\n\n\t\t\t\tif (!isFirstPart && !lastWasChange) {\n\t\t\t\t\t// Show only last N lines as leading context\n\t\t\t\t\tskipStart = Math.max(0, raw.length - CONTEXT_LINES);\n\t\t\t\t\tlinesToShow = raw.slice(skipStart);\n\t\t\t\t}\n\n\t\t\t\tif (!isLastPart && !nextPartIsChange && linesToShow.length > CONTEXT_LINES) {\n\t\t\t\t\t// Show only first N lines as trailing context\n\t\t\t\t\tskipEnd = linesToShow.length - CONTEXT_LINES;\n\t\t\t\t\tlinesToShow = linesToShow.slice(0, CONTEXT_LINES);\n\t\t\t\t}\n\n\t\t\t\t// Add ellipsis if we skipped lines at start\n\t\t\t\tif (skipStart > 0) {\n\t\t\t\t\toutput.push(chalk.dim(`${\"\".padStart(lineNumWidth, \" \")} ...`));\n\t\t\t\t}\n\n\t\t\t\tfor (const line of linesToShow) {\n\t\t\t\t\tconst lineNum = String(oldLineNum).padStart(lineNumWidth, \" \");\n\t\t\t\t\toutput.push(chalk.dim(`${lineNum} ${line}`));\n\t\t\t\t\toldLineNum++;\n\t\t\t\t\tnewLineNum++;\n\t\t\t\t}\n\n\t\t\t\t// Add ellipsis if we skipped lines at end\n\t\t\t\tif (skipEnd > 0) {\n\t\t\t\t\toutput.push(chalk.dim(`${\"\".padStart(lineNumWidth, \" \")} ...`));\n\t\t\t\t}\n\n\t\t\t\t// Update line numbers for skipped lines\n\t\t\t\toldLineNum += skipStart + skipEnd;\n\t\t\t\tnewLineNum += skipStart + skipEnd;\n\t\t\t} else {\n\t\t\t\t// Skip these context lines entirely\n\t\t\t\toldLineNum += raw.length;\n\t\t\t\tnewLineNum += raw.length;\n\t\t\t}\n\n\t\t\tlastWasChange = false;\n\t\t}\n\t}\n\n\treturn output.join(\"\\n\");\n}\n\n/**\n * Component that renders a tool call with its result (updateable)\n */\nexport class ToolExecutionComponent extends Container {\n\tprivate contentText: Text;\n\tprivate toolName: string;\n\tprivate args: any;\n\tprivate expanded = false;\n\tprivate result?: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tisError: boolean;\n\t\tdetails?: any;\n\t};\n\n\tconstructor(toolName: string, args: any) {\n\t\tsuper();\n\t\tthis.toolName = toolName;\n\t\tthis.args = args;\n\t\tthis.addChild(new Spacer(1));\n\t\t// Content with colored background and padding\n\t\tthis.contentText = new Text(\"\", 1, 1, { r: 40, g: 40, b: 50 });\n\t\tthis.addChild(this.contentText);\n\t\tthis.updateDisplay();\n\t}\n\n\tupdateArgs(args: any): void {\n\t\tthis.args = args;\n\t\tthis.updateDisplay();\n\t}\n\n\tupdateResult(result: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: any;\n\t\tisError: boolean;\n\t}): void {\n\t\tthis.result = result;\n\t\tthis.updateDisplay();\n\t}\n\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tthis.updateDisplay();\n\t}\n\n\tprivate updateDisplay(): void {\n\t\tconst bgColor = this.result\n\t\t\t? this.result.isError\n\t\t\t\t? { r: 60, g: 40, b: 40 }\n\t\t\t\t: { r: 40, g: 50, b: 40 }\n\t\t\t: { r: 40, g: 40, b: 50 };\n\n\t\tthis.contentText.setCustomBgRgb(bgColor);\n\t\tthis.contentText.setText(this.formatToolExecution());\n\t}\n\n\tprivate getTextOutput(): string {\n\t\tif (!this.result) return \"\";\n\n\t\t// Extract text from content blocks\n\t\tconst textBlocks = this.result.content?.filter((c: any) => c.type === \"text\") || [];\n\t\tconst imageBlocks = this.result.content?.filter((c: any) => c.type === \"image\") || [];\n\n\t\t// Strip ANSI codes from raw output (bash may emit colors/formatting)\n\t\tlet output = textBlocks.map((c: any) => stripAnsi(c.text || \"\")).join(\"\\n\");\n\n\t\t// Add indicator for images\n\t\tif (imageBlocks.length > 0) {\n\t\t\tconst imageIndicators = imageBlocks.map((img: any) => `[Image: ${img.mimeType}]`).join(\"\\n\");\n\t\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t\t}\n\n\t\treturn output;\n\t}\n\n\tprivate formatToolExecution(): string {\n\t\tlet text = \"\";\n\n\t\t// Format based on tool type\n\t\tif (this.toolName === \"bash\") {\n\t\t\tconst command = this.args?.command || \"\";\n\t\t\ttext = chalk.bold(`$ ${command || chalk.dim(\"...\")}`);\n\n\t\t\tif (this.result) {\n\t\t\t\t// Show output without code fences - more minimal\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 5;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += \"\\n\\n\" + displayLines.map((line: string) => chalk.dim(line)).join(\"\\n\");\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += chalk.dim(`\\n... (${remaining} more lines)`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"read\") {\n\t\t\tconst path = shortenPath(this.args?.file_path || this.args?.path || \"\");\n\t\t\ttext = chalk.bold(\"read\") + \" \" + (path ? chalk.cyan(path) : chalk.dim(\"...\"));\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\tconst maxLines = this.expanded ? lines.length : 10;\n\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\ttext += \"\\n\\n\" + displayLines.map((line: string) => chalk.dim(replaceTabs(line))).join(\"\\n\");\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\ttext += chalk.dim(`\\n... (${remaining} more lines)`);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"write\") {\n\t\t\tconst path = shortenPath(this.args?.file_path || this.args?.path || \"\");\n\t\t\tconst fileContent = this.args?.content || \"\";\n\t\t\tconst lines = fileContent ? fileContent.split(\"\\n\") : [];\n\t\t\tconst totalLines = lines.length;\n\n\t\t\ttext = chalk.bold(\"write\") + \" \" + (path ? chalk.cyan(path) : chalk.dim(\"...\"));\n\t\t\tif (totalLines > 10) {\n\t\t\t\ttext += ` (${totalLines} lines)`;\n\t\t\t}\n\n\t\t\t// Show first 10 lines of content if available\n\t\t\tif (fileContent) {\n\t\t\t\tconst maxLines = this.expanded ? lines.length : 10;\n\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\ttext += \"\\n\\n\" + displayLines.map((line: string) => chalk.dim(replaceTabs(line))).join(\"\\n\");\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\ttext += chalk.dim(`\\n... (${remaining} more lines)`);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"edit\") {\n\t\t\tconst path = shortenPath(this.args?.file_path || this.args?.path || \"\");\n\t\t\ttext = chalk.bold(\"edit\") + \" \" + (path ? chalk.cyan(path) : chalk.dim(\"...\"));\n\n\t\t\tif (this.result) {\n\t\t\t\t// Show error message if it's an error\n\t\t\t\tif (this.result.isError) {\n\t\t\t\t\tconst errorText = this.getTextOutput();\n\t\t\t\t\tif (errorText) {\n\t\t\t\t\t\ttext += \"\\n\\n\" + chalk.red(errorText);\n\t\t\t\t\t}\n\t\t\t\t} else if (this.result.details?.diff) {\n\t\t\t\t\t// Show diff if available\n\t\t\t\t\tconst diffLines = this.result.details.diff.split(\"\\n\");\n\t\t\t\t\tconst coloredLines = diffLines.map((line: string) => {\n\t\t\t\t\t\tif (line.startsWith(\"+\")) {\n\t\t\t\t\t\t\treturn chalk.green(line);\n\t\t\t\t\t\t} else if (line.startsWith(\"-\")) {\n\t\t\t\t\t\t\treturn chalk.red(line);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn chalk.dim(line);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\ttext += \"\\n\\n\" + coloredLines.join(\"\\n\");\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Generic tool\n\t\t\ttext = chalk.bold(this.toolName);\n\n\t\t\tconst content = JSON.stringify(this.args, null, 2);\n\t\t\ttext += \"\\n\\n\" + content;\n\t\t\tconst output = this.getTextOutput();\n\t\t\tif (output) {\n\t\t\t\ttext += \"\\n\" + output;\n\t\t\t}\n\t\t}\n\n\t\treturn text;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"tool-execution.d.ts","sourceRoot":"","sources":["../../src/tui/tool-execution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAgB,MAAM,sBAAsB,CAAC;AAsB/D;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,SAAS;IACpD,OAAO,CAAC,WAAW,CAAO;IAC1B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,IAAI,CAAM;IAClB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,MAAM,CAAC,CAIb;IAEF,YAAY,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAStC;IAED,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,CAG1B;IAED,YAAY,CAAC,MAAM,EAAE;QACpB,OAAO,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QAClF,OAAO,CAAC,EAAE,GAAG,CAAC;QACd,OAAO,EAAE,OAAO,CAAC;KACjB,GAAG,IAAI,CAGP;IAED,WAAW,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAGnC;IAED,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,mBAAmB;CAqH3B","sourcesContent":["import * as os from \"node:os\";\nimport { Container, Spacer, Text } from \"@mariozechner/pi-tui\";\nimport stripAnsi from \"strip-ansi\";\nimport { theme } from \"../theme/theme.js\";\n\n/**\n * Convert absolute path to tilde notation if it's in home directory\n */\nfunction shortenPath(path: string): string {\n\tconst home = os.homedir();\n\tif (path.startsWith(home)) {\n\t\treturn \"~\" + path.slice(home.length);\n\t}\n\treturn path;\n}\n\n/**\n * Replace tabs with spaces for consistent rendering\n */\nfunction replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\n/**\n * Component that renders a tool call with its result (updateable)\n */\nexport class ToolExecutionComponent extends Container {\n\tprivate contentText: Text;\n\tprivate toolName: string;\n\tprivate args: any;\n\tprivate expanded = false;\n\tprivate result?: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tisError: boolean;\n\t\tdetails?: any;\n\t};\n\n\tconstructor(toolName: string, args: any) {\n\t\tsuper();\n\t\tthis.toolName = toolName;\n\t\tthis.args = args;\n\t\tthis.addChild(new Spacer(1));\n\t\t// Content with colored background and padding\n\t\tthis.contentText = new Text(\"\", 1, 1, (text: string) => theme.bg(\"toolPendingBg\", text));\n\t\tthis.addChild(this.contentText);\n\t\tthis.updateDisplay();\n\t}\n\n\tupdateArgs(args: any): void {\n\t\tthis.args = args;\n\t\tthis.updateDisplay();\n\t}\n\n\tupdateResult(result: {\n\t\tcontent: Array<{ type: string; text?: string; data?: string; mimeType?: string }>;\n\t\tdetails?: any;\n\t\tisError: boolean;\n\t}): void {\n\t\tthis.result = result;\n\t\tthis.updateDisplay();\n\t}\n\n\tsetExpanded(expanded: boolean): void {\n\t\tthis.expanded = expanded;\n\t\tthis.updateDisplay();\n\t}\n\n\tprivate updateDisplay(): void {\n\t\tconst bgFn = this.result\n\t\t\t? this.result.isError\n\t\t\t\t? (text: string) => theme.bg(\"toolErrorBg\", text)\n\t\t\t\t: (text: string) => theme.bg(\"toolSuccessBg\", text)\n\t\t\t: (text: string) => theme.bg(\"toolPendingBg\", text);\n\n\t\tthis.contentText.setCustomBgFn(bgFn);\n\t\tthis.contentText.setText(this.formatToolExecution());\n\t}\n\n\tprivate getTextOutput(): string {\n\t\tif (!this.result) return \"\";\n\n\t\t// Extract text from content blocks\n\t\tconst textBlocks = this.result.content?.filter((c: any) => c.type === \"text\") || [];\n\t\tconst imageBlocks = this.result.content?.filter((c: any) => c.type === \"image\") || [];\n\n\t\t// Strip ANSI codes from raw output (bash may emit colors/formatting)\n\t\tlet output = textBlocks.map((c: any) => stripAnsi(c.text || \"\")).join(\"\\n\");\n\n\t\t// Add indicator for images\n\t\tif (imageBlocks.length > 0) {\n\t\t\tconst imageIndicators = imageBlocks.map((img: any) => `[Image: ${img.mimeType}]`).join(\"\\n\");\n\t\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t\t}\n\n\t\treturn output;\n\t}\n\n\tprivate formatToolExecution(): string {\n\t\tlet text = \"\";\n\n\t\t// Format based on tool type\n\t\tif (this.toolName === \"bash\") {\n\t\t\tconst command = this.args?.command || \"\";\n\t\t\ttext = theme.fg(\"toolTitle\", theme.bold(`$ ${command || theme.fg(\"toolOutput\", \"...\")}`));\n\n\t\t\tif (this.result) {\n\t\t\t\t// Show output without code fences - more minimal\n\t\t\t\tconst output = this.getTextOutput().trim();\n\t\t\t\tif (output) {\n\t\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\t\tconst maxLines = this.expanded ? lines.length : 5;\n\t\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\t\ttext += \"\\n\\n\" + displayLines.map((line: string) => theme.fg(\"toolOutput\", line)).join(\"\\n\");\n\t\t\t\t\tif (remaining > 0) {\n\t\t\t\t\t\ttext += theme.fg(\"toolOutput\", `\\n... (${remaining} more lines)`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"read\") {\n\t\t\tconst path = shortenPath(this.args?.file_path || this.args?.path || \"\");\n\t\t\tconst offset = this.args?.offset;\n\t\t\tconst limit = this.args?.limit;\n\n\t\t\t// Build path display with offset/limit suffix\n\t\t\tlet pathDisplay = path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\");\n\t\t\tif (offset !== undefined) {\n\t\t\t\tconst endLine = limit !== undefined ? offset + limit : \"\";\n\t\t\t\tpathDisplay += theme.fg(\"toolOutput\", `:${offset}${endLine ? `-${endLine}` : \"\"}`);\n\t\t\t}\n\n\t\t\ttext = theme.fg(\"toolTitle\", theme.bold(\"read\")) + \" \" + pathDisplay;\n\n\t\t\tif (this.result) {\n\t\t\t\tconst output = this.getTextOutput();\n\t\t\t\tconst lines = output.split(\"\\n\");\n\t\t\t\tconst maxLines = this.expanded ? lines.length : 10;\n\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\ttext += \"\\n\\n\" + displayLines.map((line: string) => theme.fg(\"toolOutput\", replaceTabs(line))).join(\"\\n\");\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\ttext += theme.fg(\"toolOutput\", `\\n... (${remaining} more lines)`);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"write\") {\n\t\t\tconst path = shortenPath(this.args?.file_path || this.args?.path || \"\");\n\t\t\tconst fileContent = this.args?.content || \"\";\n\t\t\tconst lines = fileContent ? fileContent.split(\"\\n\") : [];\n\t\t\tconst totalLines = lines.length;\n\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"write\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\"));\n\t\t\tif (totalLines > 10) {\n\t\t\t\ttext += ` (${totalLines} lines)`;\n\t\t\t}\n\n\t\t\t// Show first 10 lines of content if available\n\t\t\tif (fileContent) {\n\t\t\t\tconst maxLines = this.expanded ? lines.length : 10;\n\t\t\t\tconst displayLines = lines.slice(0, maxLines);\n\t\t\t\tconst remaining = lines.length - maxLines;\n\n\t\t\t\ttext += \"\\n\\n\" + displayLines.map((line: string) => theme.fg(\"toolOutput\", replaceTabs(line))).join(\"\\n\");\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\ttext += theme.fg(\"toolOutput\", `\\n... (${remaining} more lines)`);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (this.toolName === \"edit\") {\n\t\t\tconst path = shortenPath(this.args?.file_path || this.args?.path || \"\");\n\t\t\ttext =\n\t\t\t\ttheme.fg(\"toolTitle\", theme.bold(\"edit\")) +\n\t\t\t\t\" \" +\n\t\t\t\t(path ? theme.fg(\"accent\", path) : theme.fg(\"toolOutput\", \"...\"));\n\n\t\t\tif (this.result) {\n\t\t\t\t// Show error message if it's an error\n\t\t\t\tif (this.result.isError) {\n\t\t\t\t\tconst errorText = this.getTextOutput();\n\t\t\t\t\tif (errorText) {\n\t\t\t\t\t\ttext += \"\\n\\n\" + theme.fg(\"error\", errorText);\n\t\t\t\t\t}\n\t\t\t\t} else if (this.result.details?.diff) {\n\t\t\t\t\t// Show diff if available\n\t\t\t\t\tconst diffLines = this.result.details.diff.split(\"\\n\");\n\t\t\t\t\tconst coloredLines = diffLines.map((line: string) => {\n\t\t\t\t\t\tif (line.startsWith(\"+\")) {\n\t\t\t\t\t\t\treturn theme.fg(\"toolDiffAdded\", line);\n\t\t\t\t\t\t} else if (line.startsWith(\"-\")) {\n\t\t\t\t\t\t\treturn theme.fg(\"toolDiffRemoved\", line);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn theme.fg(\"toolDiffContext\", line);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\ttext += \"\\n\\n\" + coloredLines.join(\"\\n\");\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// Generic tool\n\t\t\ttext = theme.fg(\"toolTitle\", theme.bold(this.toolName));\n\n\t\t\tconst content = JSON.stringify(this.args, null, 2);\n\t\t\ttext += \"\\n\\n\" + content;\n\t\t\tconst output = this.getTextOutput();\n\t\t\tif (output) {\n\t\t\t\ttext += \"\\n\" + output;\n\t\t\t}\n\t\t}\n\n\t\treturn text;\n\t}\n}\n"]}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as os from "node:os";
|
|
2
2
|
import { Container, Spacer, Text } from "@mariozechner/pi-tui";
|
|
3
|
-
import chalk from "chalk";
|
|
4
|
-
import * as Diff from "diff";
|
|
5
3
|
import stripAnsi from "strip-ansi";
|
|
4
|
+
import { theme } from "../theme/theme.js";
|
|
6
5
|
/**
|
|
7
6
|
* Convert absolute path to tilde notation if it's in home directory
|
|
8
7
|
*/
|
|
@@ -19,92 +18,6 @@ function shortenPath(path) {
|
|
|
19
18
|
function replaceTabs(text) {
|
|
20
19
|
return text.replace(/\t/g, " ");
|
|
21
20
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Generate a unified diff with line numbers and context
|
|
24
|
-
*/
|
|
25
|
-
function generateDiff(oldStr, newStr) {
|
|
26
|
-
const parts = Diff.diffLines(oldStr, newStr);
|
|
27
|
-
const output = [];
|
|
28
|
-
// Calculate max line number for padding
|
|
29
|
-
const oldLines = oldStr.split("\n");
|
|
30
|
-
const newLines = newStr.split("\n");
|
|
31
|
-
const maxLineNum = Math.max(oldLines.length, newLines.length);
|
|
32
|
-
const lineNumWidth = String(maxLineNum).length;
|
|
33
|
-
const CONTEXT_LINES = 2; // Show 2 lines of context around changes
|
|
34
|
-
let oldLineNum = 1;
|
|
35
|
-
let newLineNum = 1;
|
|
36
|
-
let lastWasChange = false;
|
|
37
|
-
for (let i = 0; i < parts.length; i++) {
|
|
38
|
-
const part = parts[i];
|
|
39
|
-
const raw = part.value.split("\n");
|
|
40
|
-
if (raw[raw.length - 1] === "") {
|
|
41
|
-
raw.pop();
|
|
42
|
-
}
|
|
43
|
-
if (part.added || part.removed) {
|
|
44
|
-
// Show the change
|
|
45
|
-
for (const line of raw) {
|
|
46
|
-
if (part.added) {
|
|
47
|
-
const lineNum = String(newLineNum).padStart(lineNumWidth, " ");
|
|
48
|
-
output.push(chalk.green(`${lineNum} ${line}`));
|
|
49
|
-
newLineNum++;
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
// removed
|
|
53
|
-
const lineNum = String(oldLineNum).padStart(lineNumWidth, " ");
|
|
54
|
-
output.push(chalk.red(`${lineNum} ${line}`));
|
|
55
|
-
oldLineNum++;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
lastWasChange = true;
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
// Context lines - only show a few before/after changes
|
|
62
|
-
const isFirstPart = i === 0;
|
|
63
|
-
const isLastPart = i === parts.length - 1;
|
|
64
|
-
const nextPartIsChange = i < parts.length - 1 && (parts[i + 1].added || parts[i + 1].removed);
|
|
65
|
-
if (lastWasChange || nextPartIsChange || isFirstPart || isLastPart) {
|
|
66
|
-
// Show context
|
|
67
|
-
let linesToShow = raw;
|
|
68
|
-
let skipStart = 0;
|
|
69
|
-
let skipEnd = 0;
|
|
70
|
-
if (!isFirstPart && !lastWasChange) {
|
|
71
|
-
// Show only last N lines as leading context
|
|
72
|
-
skipStart = Math.max(0, raw.length - CONTEXT_LINES);
|
|
73
|
-
linesToShow = raw.slice(skipStart);
|
|
74
|
-
}
|
|
75
|
-
if (!isLastPart && !nextPartIsChange && linesToShow.length > CONTEXT_LINES) {
|
|
76
|
-
// Show only first N lines as trailing context
|
|
77
|
-
skipEnd = linesToShow.length - CONTEXT_LINES;
|
|
78
|
-
linesToShow = linesToShow.slice(0, CONTEXT_LINES);
|
|
79
|
-
}
|
|
80
|
-
// Add ellipsis if we skipped lines at start
|
|
81
|
-
if (skipStart > 0) {
|
|
82
|
-
output.push(chalk.dim(`${"".padStart(lineNumWidth, " ")} ...`));
|
|
83
|
-
}
|
|
84
|
-
for (const line of linesToShow) {
|
|
85
|
-
const lineNum = String(oldLineNum).padStart(lineNumWidth, " ");
|
|
86
|
-
output.push(chalk.dim(`${lineNum} ${line}`));
|
|
87
|
-
oldLineNum++;
|
|
88
|
-
newLineNum++;
|
|
89
|
-
}
|
|
90
|
-
// Add ellipsis if we skipped lines at end
|
|
91
|
-
if (skipEnd > 0) {
|
|
92
|
-
output.push(chalk.dim(`${"".padStart(lineNumWidth, " ")} ...`));
|
|
93
|
-
}
|
|
94
|
-
// Update line numbers for skipped lines
|
|
95
|
-
oldLineNum += skipStart + skipEnd;
|
|
96
|
-
newLineNum += skipStart + skipEnd;
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
// Skip these context lines entirely
|
|
100
|
-
oldLineNum += raw.length;
|
|
101
|
-
newLineNum += raw.length;
|
|
102
|
-
}
|
|
103
|
-
lastWasChange = false;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return output.join("\n");
|
|
107
|
-
}
|
|
108
21
|
/**
|
|
109
22
|
* Component that renders a tool call with its result (updateable)
|
|
110
23
|
*/
|
|
@@ -120,7 +33,7 @@ export class ToolExecutionComponent extends Container {
|
|
|
120
33
|
this.args = args;
|
|
121
34
|
this.addChild(new Spacer(1));
|
|
122
35
|
// Content with colored background and padding
|
|
123
|
-
this.contentText = new Text("", 1, 1,
|
|
36
|
+
this.contentText = new Text("", 1, 1, (text) => theme.bg("toolPendingBg", text));
|
|
124
37
|
this.addChild(this.contentText);
|
|
125
38
|
this.updateDisplay();
|
|
126
39
|
}
|
|
@@ -137,12 +50,12 @@ export class ToolExecutionComponent extends Container {
|
|
|
137
50
|
this.updateDisplay();
|
|
138
51
|
}
|
|
139
52
|
updateDisplay() {
|
|
140
|
-
const
|
|
53
|
+
const bgFn = this.result
|
|
141
54
|
? this.result.isError
|
|
142
|
-
?
|
|
143
|
-
:
|
|
144
|
-
:
|
|
145
|
-
this.contentText.
|
|
55
|
+
? (text) => theme.bg("toolErrorBg", text)
|
|
56
|
+
: (text) => theme.bg("toolSuccessBg", text)
|
|
57
|
+
: (text) => theme.bg("toolPendingBg", text);
|
|
58
|
+
this.contentText.setCustomBgFn(bgFn);
|
|
146
59
|
this.contentText.setText(this.formatToolExecution());
|
|
147
60
|
}
|
|
148
61
|
getTextOutput() {
|
|
@@ -165,7 +78,7 @@ export class ToolExecutionComponent extends Container {
|
|
|
165
78
|
// Format based on tool type
|
|
166
79
|
if (this.toolName === "bash") {
|
|
167
80
|
const command = this.args?.command || "";
|
|
168
|
-
text =
|
|
81
|
+
text = theme.fg("toolTitle", theme.bold(`$ ${command || theme.fg("toolOutput", "...")}`));
|
|
169
82
|
if (this.result) {
|
|
170
83
|
// Show output without code fences - more minimal
|
|
171
84
|
const output = this.getTextOutput().trim();
|
|
@@ -174,25 +87,33 @@ export class ToolExecutionComponent extends Container {
|
|
|
174
87
|
const maxLines = this.expanded ? lines.length : 5;
|
|
175
88
|
const displayLines = lines.slice(0, maxLines);
|
|
176
89
|
const remaining = lines.length - maxLines;
|
|
177
|
-
text += "\n\n" + displayLines.map((line) =>
|
|
90
|
+
text += "\n\n" + displayLines.map((line) => theme.fg("toolOutput", line)).join("\n");
|
|
178
91
|
if (remaining > 0) {
|
|
179
|
-
text +=
|
|
92
|
+
text += theme.fg("toolOutput", `\n... (${remaining} more lines)`);
|
|
180
93
|
}
|
|
181
94
|
}
|
|
182
95
|
}
|
|
183
96
|
}
|
|
184
97
|
else if (this.toolName === "read") {
|
|
185
98
|
const path = shortenPath(this.args?.file_path || this.args?.path || "");
|
|
186
|
-
|
|
99
|
+
const offset = this.args?.offset;
|
|
100
|
+
const limit = this.args?.limit;
|
|
101
|
+
// Build path display with offset/limit suffix
|
|
102
|
+
let pathDisplay = path ? theme.fg("accent", path) : theme.fg("toolOutput", "...");
|
|
103
|
+
if (offset !== undefined) {
|
|
104
|
+
const endLine = limit !== undefined ? offset + limit : "";
|
|
105
|
+
pathDisplay += theme.fg("toolOutput", `:${offset}${endLine ? `-${endLine}` : ""}`);
|
|
106
|
+
}
|
|
107
|
+
text = theme.fg("toolTitle", theme.bold("read")) + " " + pathDisplay;
|
|
187
108
|
if (this.result) {
|
|
188
109
|
const output = this.getTextOutput();
|
|
189
110
|
const lines = output.split("\n");
|
|
190
111
|
const maxLines = this.expanded ? lines.length : 10;
|
|
191
112
|
const displayLines = lines.slice(0, maxLines);
|
|
192
113
|
const remaining = lines.length - maxLines;
|
|
193
|
-
text += "\n\n" + displayLines.map((line) =>
|
|
114
|
+
text += "\n\n" + displayLines.map((line) => theme.fg("toolOutput", replaceTabs(line))).join("\n");
|
|
194
115
|
if (remaining > 0) {
|
|
195
|
-
text +=
|
|
116
|
+
text += theme.fg("toolOutput", `\n... (${remaining} more lines)`);
|
|
196
117
|
}
|
|
197
118
|
}
|
|
198
119
|
}
|
|
@@ -201,7 +122,10 @@ export class ToolExecutionComponent extends Container {
|
|
|
201
122
|
const fileContent = this.args?.content || "";
|
|
202
123
|
const lines = fileContent ? fileContent.split("\n") : [];
|
|
203
124
|
const totalLines = lines.length;
|
|
204
|
-
text =
|
|
125
|
+
text =
|
|
126
|
+
theme.fg("toolTitle", theme.bold("write")) +
|
|
127
|
+
" " +
|
|
128
|
+
(path ? theme.fg("accent", path) : theme.fg("toolOutput", "..."));
|
|
205
129
|
if (totalLines > 10) {
|
|
206
130
|
text += ` (${totalLines} lines)`;
|
|
207
131
|
}
|
|
@@ -210,21 +134,24 @@ export class ToolExecutionComponent extends Container {
|
|
|
210
134
|
const maxLines = this.expanded ? lines.length : 10;
|
|
211
135
|
const displayLines = lines.slice(0, maxLines);
|
|
212
136
|
const remaining = lines.length - maxLines;
|
|
213
|
-
text += "\n\n" + displayLines.map((line) =>
|
|
137
|
+
text += "\n\n" + displayLines.map((line) => theme.fg("toolOutput", replaceTabs(line))).join("\n");
|
|
214
138
|
if (remaining > 0) {
|
|
215
|
-
text +=
|
|
139
|
+
text += theme.fg("toolOutput", `\n... (${remaining} more lines)`);
|
|
216
140
|
}
|
|
217
141
|
}
|
|
218
142
|
}
|
|
219
143
|
else if (this.toolName === "edit") {
|
|
220
144
|
const path = shortenPath(this.args?.file_path || this.args?.path || "");
|
|
221
|
-
text =
|
|
145
|
+
text =
|
|
146
|
+
theme.fg("toolTitle", theme.bold("edit")) +
|
|
147
|
+
" " +
|
|
148
|
+
(path ? theme.fg("accent", path) : theme.fg("toolOutput", "..."));
|
|
222
149
|
if (this.result) {
|
|
223
150
|
// Show error message if it's an error
|
|
224
151
|
if (this.result.isError) {
|
|
225
152
|
const errorText = this.getTextOutput();
|
|
226
153
|
if (errorText) {
|
|
227
|
-
text += "\n\n" +
|
|
154
|
+
text += "\n\n" + theme.fg("error", errorText);
|
|
228
155
|
}
|
|
229
156
|
}
|
|
230
157
|
else if (this.result.details?.diff) {
|
|
@@ -232,13 +159,13 @@ export class ToolExecutionComponent extends Container {
|
|
|
232
159
|
const diffLines = this.result.details.diff.split("\n");
|
|
233
160
|
const coloredLines = diffLines.map((line) => {
|
|
234
161
|
if (line.startsWith("+")) {
|
|
235
|
-
return
|
|
162
|
+
return theme.fg("toolDiffAdded", line);
|
|
236
163
|
}
|
|
237
164
|
else if (line.startsWith("-")) {
|
|
238
|
-
return
|
|
165
|
+
return theme.fg("toolDiffRemoved", line);
|
|
239
166
|
}
|
|
240
167
|
else {
|
|
241
|
-
return
|
|
168
|
+
return theme.fg("toolDiffContext", line);
|
|
242
169
|
}
|
|
243
170
|
});
|
|
244
171
|
text += "\n\n" + coloredLines.join("\n");
|
|
@@ -247,7 +174,7 @@ export class ToolExecutionComponent extends Container {
|
|
|
247
174
|
}
|
|
248
175
|
else {
|
|
249
176
|
// Generic tool
|
|
250
|
-
text =
|
|
177
|
+
text = theme.fg("toolTitle", theme.bold(this.toolName));
|
|
251
178
|
const content = JSON.stringify(this.args, null, 2);
|
|
252
179
|
text += "\n\n" + content;
|
|
253
180
|
const output = this.getTextOutput();
|