@adhdev/daemon-core 0.6.52 → 0.6.55

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 (164) hide show
  1. package/dist/index.d.ts +77 -35
  2. package/dist/index.js +717 -275
  3. package/dist/index.js.map +1 -1
  4. package/package.json +1 -1
  5. package/providers/_builtin/_helpers/index.js +26 -26
  6. package/providers/_builtin/cli/aider-cli/provider.json +37 -0
  7. package/providers/_builtin/cli/aider-cli/scripts/1.0/detect_status.js +20 -0
  8. package/providers/_builtin/cli/aider-cli/scripts/1.0/parse_approval.js +10 -0
  9. package/providers/_builtin/cli/aider-cli/scripts/1.0/parse_output.js +49 -0
  10. package/providers/_builtin/cli/aider-cli/scripts/1.0/scripts.js +7 -0
  11. package/providers/_builtin/cli/claude-cli/provider.json +9 -2
  12. package/providers/_builtin/cli/claude-cli/scripts/1.0/detect_status.js +31 -0
  13. package/providers/_builtin/cli/claude-cli/scripts/1.0/parse_approval.js +38 -0
  14. package/providers/_builtin/cli/claude-cli/scripts/1.0/parse_output.js +164 -0
  15. package/providers/_builtin/cli/claude-cli/scripts/1.0/scripts.js +42 -0
  16. package/providers/_builtin/cli/codex-cli/provider.json +9 -2
  17. package/providers/_builtin/cli/codex-cli/scripts/1.0/detect_status.js +20 -0
  18. package/providers/_builtin/cli/codex-cli/scripts/1.0/parse_approval.js +15 -0
  19. package/providers/_builtin/cli/codex-cli/scripts/1.0/parse_output.js +68 -0
  20. package/providers/_builtin/cli/codex-cli/scripts/1.0/scripts.js +11 -0
  21. package/providers/_builtin/cli/cursor-cli/provider.json +37 -0
  22. package/providers/_builtin/cli/cursor-cli/scripts/1.0/detect_status.js +19 -0
  23. package/providers/_builtin/cli/cursor-cli/scripts/1.0/parse_approval.js +10 -0
  24. package/providers/_builtin/cli/cursor-cli/scripts/1.0/parse_output.js +48 -0
  25. package/providers/_builtin/cli/cursor-cli/scripts/1.0/scripts.js +7 -0
  26. package/providers/_builtin/cli/gemini-cli/provider.json +9 -2
  27. package/providers/_builtin/cli/gemini-cli/scripts/1.0/detect_status.js +26 -0
  28. package/providers/_builtin/cli/gemini-cli/scripts/1.0/parse_approval.js +22 -0
  29. package/providers/_builtin/cli/gemini-cli/scripts/1.0/parse_output.js +71 -0
  30. package/providers/_builtin/cli/gemini-cli/scripts/1.0/scripts.js +12 -0
  31. package/providers/_builtin/cli/github-copilot-cli/provider.json +37 -0
  32. package/providers/_builtin/cli/github-copilot-cli/scripts/1.0/detect_status.js +19 -0
  33. package/providers/_builtin/cli/github-copilot-cli/scripts/1.0/parse_approval.js +9 -0
  34. package/providers/_builtin/cli/github-copilot-cli/scripts/1.0/parse_output.js +48 -0
  35. package/providers/_builtin/cli/github-copilot-cli/scripts/1.0/scripts.js +7 -0
  36. package/providers/_builtin/cli/goose-cli/provider.json +37 -0
  37. package/providers/_builtin/cli/goose-cli/scripts/1.0/detect_status.js +20 -0
  38. package/providers/_builtin/cli/goose-cli/scripts/1.0/parse_approval.js +10 -0
  39. package/providers/_builtin/cli/goose-cli/scripts/1.0/parse_output.js +48 -0
  40. package/providers/_builtin/cli/goose-cli/scripts/1.0/scripts.js +7 -0
  41. package/providers/_builtin/cli/opencode-cli/provider.json +37 -0
  42. package/providers/_builtin/cli/opencode-cli/scripts/1.0/detect_status.js +15 -0
  43. package/providers/_builtin/cli/opencode-cli/scripts/1.0/parse_approval.js +9 -0
  44. package/providers/_builtin/cli/opencode-cli/scripts/1.0/parse_output.js +48 -0
  45. package/providers/_builtin/cli/opencode-cli/scripts/1.0/scripts.js +7 -0
  46. package/providers/_builtin/extension/cline/scripts/1.0/focus_editor.js +5 -5
  47. package/providers/_builtin/extension/cline/scripts/1.0/list_chats.js +11 -11
  48. package/providers/_builtin/extension/cline/scripts/1.0/list_models.js +6 -6
  49. package/providers/_builtin/extension/cline/scripts/1.0/list_modes.js +5 -5
  50. package/providers/_builtin/extension/cline/scripts/1.0/new_session.js +12 -12
  51. package/providers/_builtin/extension/cline/scripts/1.0/open_panel.js +7 -7
  52. package/providers/_builtin/extension/cline/scripts/1.0/read_chat.js +29 -29
  53. package/providers/_builtin/extension/cline/scripts/1.0/resolve_action.js +19 -19
  54. package/providers/_builtin/extension/cline/scripts/1.0/send_message.js +15 -15
  55. package/providers/_builtin/extension/cline/scripts/1.0/set_mode.js +4 -4
  56. package/providers/_builtin/extension/cline/scripts/1.0/set_model.js +4 -4
  57. package/providers/_builtin/extension/cline/scripts/1.0/switch_session.js +21 -21
  58. package/providers/_builtin/extension/codex/scripts/1.0/explore_controls_webview.js +2 -2
  59. package/providers/_builtin/extension/codex/scripts/1.0/list_models.js +1 -1
  60. package/providers/_builtin/extension/codex/scripts/1.0/list_modes.js +1 -1
  61. package/providers/_builtin/extension/codex/scripts/1.0/new_session.js +2 -2
  62. package/providers/_builtin/extension/codex/scripts/1.0/read_chat.js +6 -6
  63. package/providers/_builtin/extension/codex/scripts/1.0/resolve_action.js +3 -3
  64. package/providers/_builtin/extension/codex/scripts/1.0/set_model.js +1 -1
  65. package/providers/_builtin/ide/antigravity/scripts/1.0/focus_editor.js +2 -2
  66. package/providers/_builtin/ide/antigravity/scripts/1.0/list_chats.js +19 -19
  67. package/providers/_builtin/ide/antigravity/scripts/1.0/list_models.js +1 -1
  68. package/providers/_builtin/ide/antigravity/scripts/1.0/list_modes.js +1 -1
  69. package/providers/_builtin/ide/antigravity/scripts/1.0/new_session.js +17 -17
  70. package/providers/_builtin/ide/antigravity/scripts/1.0/read_chat.js +41 -41
  71. package/providers/_builtin/ide/antigravity/scripts/1.0/resolve_action.js +6 -6
  72. package/providers/_builtin/ide/antigravity/scripts/1.0/send_message.js +13 -13
  73. package/providers/_builtin/ide/antigravity/scripts/1.0/set_model.js +1 -1
  74. package/providers/_builtin/ide/antigravity/scripts/1.0/switch_session.js +13 -13
  75. package/providers/_builtin/ide/cursor/scripts/1.0/dismiss_notification.js +3 -3
  76. package/providers/_builtin/ide/cursor/scripts/1.0/focus_editor.js +1 -1
  77. package/providers/_builtin/ide/cursor/scripts/1.0/list_models.js +12 -12
  78. package/providers/_builtin/ide/cursor/scripts/1.0/list_modes.js +5 -5
  79. package/providers/_builtin/ide/cursor/scripts/1.0/list_notifications.js +2 -2
  80. package/providers/_builtin/ide/cursor/scripts/1.0/list_sessions.js +5 -5
  81. package/providers/_builtin/ide/cursor/scripts/1.0/new_session.js +1 -1
  82. package/providers/_builtin/ide/cursor/scripts/1.0/open_panel.js +3 -3
  83. package/providers/_builtin/ide/cursor/scripts/1.0/read_chat.js +9 -9
  84. package/providers/_builtin/ide/cursor/scripts/1.0/resolve_action.js +4 -4
  85. package/providers/_builtin/ide/cursor/scripts/1.0/send_message.js +5 -5
  86. package/providers/_builtin/ide/cursor/scripts/1.0/set_mode.js +4 -4
  87. package/providers/_builtin/ide/cursor/scripts/1.0/set_model.js +12 -12
  88. package/providers/_builtin/ide/cursor/scripts/1.0/switch_session.js +2 -2
  89. package/providers/_builtin/ide/kiro/scripts/1.0/focus_editor.js +2 -2
  90. package/providers/_builtin/ide/kiro/scripts/1.0/open_panel.js +7 -7
  91. package/providers/_builtin/ide/kiro/scripts/1.0/resolve_action.js +3 -3
  92. package/providers/_builtin/ide/kiro/scripts/1.0/send_message.js +4 -4
  93. package/providers/_builtin/ide/kiro/scripts/1.0/webview_list_sessions.js +2 -2
  94. package/providers/_builtin/ide/kiro/scripts/1.0/webview_new_session.js +5 -5
  95. package/providers/_builtin/ide/kiro/scripts/1.0/webview_read_chat.js +13 -13
  96. package/providers/_builtin/ide/kiro/scripts/1.0/webview_resolve_action.js +1 -1
  97. package/providers/_builtin/ide/kiro/scripts/1.0/webview_send_message.js +8 -8
  98. package/providers/_builtin/ide/kiro/scripts/1.0/webview_set_mode.js +1 -1
  99. package/providers/_builtin/ide/kiro/scripts/1.0/webview_set_model.js +1 -1
  100. package/providers/_builtin/ide/kiro/scripts/1.0/webview_switch_session.js +3 -3
  101. package/providers/_builtin/ide/pearai/.tmp/after_rich.json +157 -0
  102. package/providers/_builtin/ide/pearai/.tmp/after_rich_raw.json +161 -0
  103. package/providers/_builtin/ide/pearai/.tmp/after_switch.json +592 -0
  104. package/providers/_builtin/ide/pearai/.tmp/after_switch_raw.json +596 -0
  105. package/providers/_builtin/ide/pearai/.tmp/home_dump_raw.json +176 -0
  106. package/providers/_builtin/ide/pearai/.tmp/items_raw.json +778 -0
  107. package/providers/_builtin/ide/pearai/.tmp/webview_dump.json +157 -0
  108. package/providers/_builtin/ide/pearai/.tmp/webview_dump_raw.json +161 -0
  109. package/providers/_builtin/ide/pearai/provider.json +1 -3
  110. package/providers/_builtin/ide/pearai/scripts/1.0/focus_editor.js +12 -16
  111. package/providers/_builtin/ide/pearai/scripts/1.0/list_models.js +45 -0
  112. package/providers/_builtin/ide/pearai/scripts/1.0/list_modes.js +44 -0
  113. package/providers/_builtin/ide/pearai/scripts/1.0/list_sessions.js +82 -27
  114. package/providers/_builtin/ide/pearai/scripts/1.0/new_session.js +26 -43
  115. package/providers/_builtin/ide/pearai/scripts/1.0/open_panel.js +10 -33
  116. package/providers/_builtin/ide/pearai/scripts/1.0/read_chat.js +169 -0
  117. package/providers/_builtin/ide/pearai/scripts/1.0/resolve_action.js +47 -41
  118. package/providers/_builtin/ide/pearai/scripts/1.0/scripts.js +36 -7
  119. package/providers/_builtin/ide/pearai/scripts/1.0/send_message.js +97 -22
  120. package/providers/_builtin/ide/pearai/scripts/1.0/set_mode.js +51 -0
  121. package/providers/_builtin/ide/pearai/scripts/1.0/set_model.js +54 -0
  122. package/providers/_builtin/ide/pearai/scripts/1.0/switch_session.js +81 -0
  123. package/providers/_builtin/ide/trae/scripts/1.0/focus_editor.js +2 -2
  124. package/providers/_builtin/ide/trae/scripts/1.0/list_chats.js +2 -2
  125. package/providers/_builtin/ide/trae/scripts/1.0/new_session.js +4 -4
  126. package/providers/_builtin/ide/trae/scripts/1.0/open_panel.js +6 -6
  127. package/providers/_builtin/ide/trae/scripts/1.0/read_chat.js +13 -13
  128. package/providers/_builtin/ide/trae/scripts/1.0/resolve_action.js +3 -3
  129. package/providers/_builtin/ide/trae/scripts/1.0/send_message.js +11 -11
  130. package/providers/_builtin/ide/trae/scripts/1.0/switch_session.js +2 -2
  131. package/providers/_builtin/ide/windsurf/scripts/1.0/focus_editor.js +6 -6
  132. package/providers/_builtin/ide/windsurf/scripts/1.0/list_chats.js +4 -4
  133. package/providers/_builtin/ide/windsurf/scripts/1.0/list_sessions.js +6 -6
  134. package/providers/_builtin/ide/windsurf/scripts/1.0/new_session.js +9 -9
  135. package/providers/_builtin/ide/windsurf/scripts/1.0/open_panel.js +6 -6
  136. package/providers/_builtin/ide/windsurf/scripts/1.0/resolve_action.js +8 -8
  137. package/providers/_builtin/ide/windsurf/scripts/1.0/switch_session.js +8 -8
  138. package/providers/_builtin/ide/windsurf/scripts/1.0.bak/focus_editor.js +6 -6
  139. package/providers/_builtin/ide/windsurf/scripts/1.0.bak/list_chats.js +12 -12
  140. package/providers/_builtin/ide/windsurf/scripts/1.0.bak/new_session.js +15 -15
  141. package/providers/_builtin/ide/windsurf/scripts/1.0.bak/open_panel.js +10 -10
  142. package/providers/_builtin/ide/windsurf/scripts/1.0.bak/read_chat.js +33 -33
  143. package/providers/_builtin/ide/windsurf/scripts/1.0.bak/resolve_action.js +6 -6
  144. package/providers/_builtin/ide/windsurf/scripts/1.0.bak/send_message.js +16 -16
  145. package/providers/_builtin/ide/windsurf/scripts/1.0.bak/switch_session.js +7 -7
  146. package/providers/_builtin/registry.json +76 -3
  147. package/src/cli-adapters/provider-cli-adapter.ts +267 -251
  148. package/src/cli-adapters/terminal-screen.ts +268 -0
  149. package/src/commands/chat-commands.ts +41 -15
  150. package/src/commands/cli-manager.ts +4 -2
  151. package/src/daemon/dev-server.ts +245 -35
  152. package/src/providers/acp-provider-instance.ts +1 -1
  153. package/src/providers/cli-provider-instance.ts +21 -8
  154. package/src/providers/provider-loader.ts +6 -6
  155. package/providers/_builtin/ide/pearai/scripts/1.0/webview_list_models.js +0 -43
  156. package/providers/_builtin/ide/pearai/scripts/1.0/webview_list_modes.js +0 -35
  157. package/providers/_builtin/ide/pearai/scripts/1.0/webview_list_sessions.js +0 -62
  158. package/providers/_builtin/ide/pearai/scripts/1.0/webview_new_session.js +0 -49
  159. package/providers/_builtin/ide/pearai/scripts/1.0/webview_read_chat.js +0 -92
  160. package/providers/_builtin/ide/pearai/scripts/1.0/webview_resolve_action.js +0 -59
  161. package/providers/_builtin/ide/pearai/scripts/1.0/webview_send_message.js +0 -72
  162. package/providers/_builtin/ide/pearai/scripts/1.0/webview_set_mode.js +0 -36
  163. package/providers/_builtin/ide/pearai/scripts/1.0/webview_set_model.js +0 -36
  164. package/providers/_builtin/ide/pearai/scripts/1.0/webview_switch_session.js +0 -34
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Minimal VT screen model for PTY parsing.
3
+ *
4
+ * This is not a full terminal emulator. It exists to turn raw PTY output into a
5
+ * stable "current screen" snapshot so provider parsers can inspect visible UI
6
+ * state instead of reparsing the full accumulated log stream.
7
+ */
8
+
9
+ function clamp(value: number, min: number, max: number): number {
10
+ return Math.max(min, Math.min(max, value));
11
+ }
12
+
13
+ export class TerminalScreen {
14
+ private rows: number;
15
+ private cols: number;
16
+ private cursorRow = 0;
17
+ private cursorCol = 0;
18
+ private savedRow = 0;
19
+ private savedCol = 0;
20
+ private lines: string[][];
21
+
22
+ constructor(rows = 40, cols = 120) {
23
+ this.rows = rows;
24
+ this.cols = cols;
25
+ this.lines = this.makeLines(rows, cols);
26
+ }
27
+
28
+ reset(rows = this.rows, cols = this.cols): void {
29
+ this.rows = rows;
30
+ this.cols = cols;
31
+ this.cursorRow = 0;
32
+ this.cursorCol = 0;
33
+ this.savedRow = 0;
34
+ this.savedCol = 0;
35
+ this.lines = this.makeLines(rows, cols);
36
+ }
37
+
38
+ resize(rows: number, cols: number): void {
39
+ const nextRows = Math.max(1, rows | 0);
40
+ const nextCols = Math.max(1, cols | 0);
41
+ const next = this.makeLines(nextRows, nextCols);
42
+ const copyRows = Math.min(this.rows, nextRows);
43
+ const copyCols = Math.min(this.cols, nextCols);
44
+ for (let r = 0; r < copyRows; r++) {
45
+ for (let c = 0; c < copyCols; c++) {
46
+ next[r][c] = this.lines[r][c];
47
+ }
48
+ }
49
+ this.rows = nextRows;
50
+ this.cols = nextCols;
51
+ this.lines = next;
52
+ this.cursorRow = clamp(this.cursorRow, 0, this.rows - 1);
53
+ this.cursorCol = clamp(this.cursorCol, 0, this.cols - 1);
54
+ this.savedRow = clamp(this.savedRow, 0, this.rows - 1);
55
+ this.savedCol = clamp(this.savedCol, 0, this.cols - 1);
56
+ }
57
+
58
+ write(data: string): void {
59
+ let i = 0;
60
+ while (i < data.length) {
61
+ const ch = data[i];
62
+
63
+ if (ch === '\x1b') {
64
+ const consumed = this.consumeEscape(data, i);
65
+ i = consumed > i ? consumed : i + 1;
66
+ continue;
67
+ }
68
+
69
+ if (ch === '\r') {
70
+ this.cursorCol = 0;
71
+ i++;
72
+ continue;
73
+ }
74
+
75
+ if (ch === '\n') {
76
+ this.newLine();
77
+ i++;
78
+ continue;
79
+ }
80
+
81
+ if (ch === '\b') {
82
+ this.cursorCol = Math.max(0, this.cursorCol - 1);
83
+ i++;
84
+ continue;
85
+ }
86
+
87
+ if (ch === '\t') {
88
+ const nextStop = Math.min(this.cols - 1, this.cursorCol + (8 - (this.cursorCol % 8 || 8)));
89
+ while (this.cursorCol < nextStop) this.putChar(' ');
90
+ i++;
91
+ continue;
92
+ }
93
+
94
+ if (ch >= ' ' && ch !== '\x7f') {
95
+ this.putChar(ch);
96
+ }
97
+
98
+ i++;
99
+ }
100
+ }
101
+
102
+ getText(): string {
103
+ const raw = this.lines.map(line => line.join('').replace(/\s+$/, ''));
104
+ let start = 0;
105
+ let end = raw.length;
106
+ while (start < end && raw[start] === '') start++;
107
+ while (end > start && raw[end - 1] === '') end--;
108
+ return raw.slice(start, end).join('\n');
109
+ }
110
+
111
+ private consumeEscape(data: string, start: number): number {
112
+ const next = data[start + 1];
113
+ if (!next) return start + 1;
114
+
115
+ if (next === '[') {
116
+ let end = start + 2;
117
+ while (end < data.length && !/[@-~]/.test(data[end])) end++;
118
+ if (end >= data.length) return data.length;
119
+ this.applyCsi(data.slice(start + 2, end), data[end]);
120
+ return end + 1;
121
+ }
122
+
123
+ if (next === ']') {
124
+ let end = start + 2;
125
+ while (end < data.length) {
126
+ if (data[end] === '\x07') return end + 1;
127
+ if (data[end] === '\x1b' && data[end + 1] === '\\') return end + 2;
128
+ end++;
129
+ }
130
+ return data.length;
131
+ }
132
+
133
+ if (next === '7') {
134
+ this.savedRow = this.cursorRow;
135
+ this.savedCol = this.cursorCol;
136
+ return start + 2;
137
+ }
138
+ if (next === '8') {
139
+ this.cursorRow = this.savedRow;
140
+ this.cursorCol = this.savedCol;
141
+ return start + 2;
142
+ }
143
+
144
+ return start + 2;
145
+ }
146
+
147
+ private applyCsi(paramText: string, finalChar: string): void {
148
+ const privateMode = paramText.startsWith('?');
149
+ const normalized = privateMode ? paramText.slice(1) : paramText;
150
+ const params = normalized.length > 0
151
+ ? normalized.split(';').map(p => parseInt(p || '0', 10) || 0)
152
+ : [0];
153
+
154
+ switch (finalChar) {
155
+ case 'A':
156
+ this.cursorRow = clamp(this.cursorRow - (params[0] || 1), 0, this.rows - 1);
157
+ return;
158
+ case 'B':
159
+ this.cursorRow = clamp(this.cursorRow + (params[0] || 1), 0, this.rows - 1);
160
+ return;
161
+ case 'C':
162
+ this.cursorCol = clamp(this.cursorCol + (params[0] || 1), 0, this.cols - 1);
163
+ return;
164
+ case 'D':
165
+ this.cursorCol = clamp(this.cursorCol - (params[0] || 1), 0, this.cols - 1);
166
+ return;
167
+ case 'E':
168
+ this.cursorRow = clamp(this.cursorRow + (params[0] || 1), 0, this.rows - 1);
169
+ this.cursorCol = 0;
170
+ return;
171
+ case 'F':
172
+ this.cursorRow = clamp(this.cursorRow - (params[0] || 1), 0, this.rows - 1);
173
+ this.cursorCol = 0;
174
+ return;
175
+ case 'G':
176
+ this.cursorCol = clamp((params[0] || 1) - 1, 0, this.cols - 1);
177
+ return;
178
+ case 'H':
179
+ case 'f': {
180
+ const row = (params[0] || 1) - 1;
181
+ const col = (params[1] || 1) - 1;
182
+ this.cursorRow = clamp(row, 0, this.rows - 1);
183
+ this.cursorCol = clamp(col, 0, this.cols - 1);
184
+ return;
185
+ }
186
+ case 'J': {
187
+ const mode = params[0] || 0;
188
+ if (mode === 2 || mode === 3) {
189
+ this.reset(this.rows, this.cols);
190
+ } else if (mode === 0) {
191
+ this.clearToEndOfScreen();
192
+ } else if (mode === 1) {
193
+ this.clearToStartOfScreen();
194
+ }
195
+ return;
196
+ }
197
+ case 'K': {
198
+ const mode = params[0] || 0;
199
+ if (mode === 2) this.clearLine(this.cursorRow, 0, this.cols - 1);
200
+ else if (mode === 1) this.clearLine(this.cursorRow, 0, this.cursorCol);
201
+ else this.clearLine(this.cursorRow, this.cursorCol, this.cols - 1);
202
+ return;
203
+ }
204
+ case 'm':
205
+ return;
206
+ case 's':
207
+ this.savedRow = this.cursorRow;
208
+ this.savedCol = this.cursorCol;
209
+ return;
210
+ case 'u':
211
+ this.cursorRow = this.savedRow;
212
+ this.cursorCol = this.savedCol;
213
+ return;
214
+ case 'h':
215
+ case 'l':
216
+ if (privateMode && (normalized === '1049' || normalized === '47')) {
217
+ this.reset(this.rows, this.cols);
218
+ }
219
+ return;
220
+ default:
221
+ return;
222
+ }
223
+ }
224
+
225
+ private putChar(ch: string): void {
226
+ if (this.cursorRow < 0 || this.cursorRow >= this.rows) return;
227
+ if (this.cursorCol < 0) this.cursorCol = 0;
228
+ if (this.cursorCol >= this.cols) this.newLine();
229
+ this.lines[this.cursorRow][this.cursorCol] = ch;
230
+ this.cursorCol++;
231
+ if (this.cursorCol >= this.cols) this.newLine();
232
+ }
233
+
234
+ private newLine(): void {
235
+ this.cursorCol = 0;
236
+ if (this.cursorRow >= this.rows - 1) {
237
+ this.lines.shift();
238
+ this.lines.push(Array.from({ length: this.cols }, () => ' '));
239
+ } else {
240
+ this.cursorRow++;
241
+ }
242
+ }
243
+
244
+ private clearLine(row: number, start: number, end: number): void {
245
+ if (row < 0 || row >= this.rows) return;
246
+ for (let c = clamp(start, 0, this.cols - 1); c <= clamp(end, 0, this.cols - 1); c++) {
247
+ this.lines[row][c] = ' ';
248
+ }
249
+ }
250
+
251
+ private clearToEndOfScreen(): void {
252
+ this.clearLine(this.cursorRow, this.cursorCol, this.cols - 1);
253
+ for (let r = this.cursorRow + 1; r < this.rows; r++) {
254
+ this.clearLine(r, 0, this.cols - 1);
255
+ }
256
+ }
257
+
258
+ private clearToStartOfScreen(): void {
259
+ for (let r = 0; r < this.cursorRow; r++) {
260
+ this.clearLine(r, 0, this.cols - 1);
261
+ }
262
+ this.clearLine(this.cursorRow, 0, this.cursorCol);
263
+ }
264
+
265
+ private makeLines(rows: number, cols: number): string[][] {
266
+ return Array.from({ length: rows }, () => Array.from({ length: cols }, () => ' '));
267
+ }
268
+ }
@@ -7,6 +7,10 @@ import type { CommandResult, CommandHelpers } from './handler.js';
7
7
  import { readChatHistory } from '../config/chat-history.js';
8
8
  import { LOG } from '../logging/logger.js';
9
9
 
10
+ function getTargetedCliAdapter(h: CommandHelpers, args: any, providerType?: string) {
11
+ return h.getCliAdapter(args?._targetInstance || h.currentIdeType || providerType);
12
+ }
13
+
10
14
  export async function handleChatHistory(h: CommandHelpers, args: any): Promise<CommandResult> {
11
15
  const { agentType, offset, limit, instanceId } = args;
12
16
  try {
@@ -20,13 +24,13 @@ export async function handleChatHistory(h: CommandHelpers, args: any): Promise<C
20
24
  }
21
25
 
22
26
  export async function handleReadChat(h: CommandHelpers, args: any): Promise<CommandResult> {
23
- const provider = h.getProvider();
27
+ const provider = h.getProvider(args?.agentType);
24
28
 
25
29
  const _log = (msg: string) => LOG.debug('Command', `[read_chat] ${msg}`);
26
30
 
27
31
  // CLI / ACP category: read from adapter
28
32
  if (provider?.category === 'cli' || provider?.category === 'acp') {
29
- const adapter = h.getCliAdapter(provider.type);
33
+ const adapter = getTargetedCliAdapter(h, args, provider.type);
30
34
  if (adapter) {
31
35
  _log(`${provider.category} adapter: ${(adapter as any).cliType}`);
32
36
  const status = (adapter as any).getStatus?.();
@@ -140,7 +144,7 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
140
144
  const text = args?.text || args?.message;
141
145
  if (!text) return { success: false, error: 'text required' };
142
146
  const _log = (msg: string) => LOG.debug('Command', `[send_chat] ${msg}`);
143
- const provider = h.getProvider();
147
+ const provider = h.getProvider(args?.agentType);
144
148
 
145
149
  const _logSendSuccess = (method: string, targetAgent?: string) => {
146
150
  h.historyWriter.appendNewMessages(
@@ -154,7 +158,7 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
154
158
 
155
159
  // CLI / ACP category: transmit via adapter
156
160
  if (provider?.category === 'cli' || provider?.category === 'acp') {
157
- const adapter = h.getCliAdapter(provider.type);
161
+ const adapter = getTargetedCliAdapter(h, args, provider.type);
158
162
  if (adapter) {
159
163
  _log(`${provider.category} adapter: ${(adapter as any).cliType}`);
160
164
  try {
@@ -305,7 +309,7 @@ export async function handleSendChat(h: CommandHelpers, args: any): Promise<Comm
305
309
  }
306
310
 
307
311
  export async function handleListChats(h: CommandHelpers, args: any): Promise<CommandResult> {
308
- const provider = h.getProvider();
312
+ const provider = h.getProvider(args?.agentType);
309
313
 
310
314
  // Extension: via AgentStreamManager
311
315
  if (provider?.category === 'extension' && h.agentStream && h.getCdp()) {
@@ -355,7 +359,17 @@ export async function handleListChats(h: CommandHelpers, args: any): Promise<Com
355
359
  }
356
360
 
357
361
  export async function handleNewChat(h: CommandHelpers, args: any): Promise<CommandResult> {
358
- const provider = h.getProvider();
362
+ const provider = h.getProvider(args?.agentType);
363
+
364
+ if (provider?.category === 'cli') {
365
+ const adapter = getTargetedCliAdapter(h, args, provider.type);
366
+ if (!adapter) return { success: false, error: 'CLI adapter not running' };
367
+ if (typeof (adapter as any).clearHistory === 'function') {
368
+ (adapter as any).clearHistory();
369
+ return { success: true, cleared: true };
370
+ }
371
+ return { success: false, error: 'new_chat not supported by this CLI provider' };
372
+ }
359
373
 
360
374
  if (provider?.category === 'extension' && h.agentStream && h.getCdp()) {
361
375
  const ok = await h.agentStream.newAgentSession(h.getCdp()!, provider.type, h.currentIdeType);
@@ -386,7 +400,7 @@ export async function handleNewChat(h: CommandHelpers, args: any): Promise<Comma
386
400
  }
387
401
 
388
402
  export async function handleSwitchChat(h: CommandHelpers, args: any): Promise<CommandResult> {
389
- const provider = h.getProvider();
403
+ const provider = h.getProvider(args?.agentType);
390
404
  const ideType = h.currentIdeType;
391
405
  const sessionId = args?.sessionId || args?.id || args?.chatId;
392
406
  if (!sessionId) return { success: false, error: 'sessionId required' };
@@ -473,12 +487,12 @@ export async function handleSwitchChat(h: CommandHelpers, args: any): Promise<Co
473
487
  }
474
488
 
475
489
  export async function handleSetMode(h: CommandHelpers, args: any): Promise<CommandResult> {
476
- const provider = h.getProvider();
490
+ const provider = h.getProvider(args?.agentType);
477
491
  const mode = args?.mode || 'agent';
478
492
 
479
493
  // ACP provider
480
494
  if (provider?.category === 'acp') {
481
- const adapter = h.getCliAdapter(provider.type);
495
+ const adapter = getTargetedCliAdapter(h, args, provider.type);
482
496
  if (adapter) {
483
497
  const acpInstance = (adapter as any)._acpInstance;
484
498
  if (acpInstance && typeof acpInstance.onEvent === 'function') {
@@ -526,14 +540,14 @@ export async function handleSetMode(h: CommandHelpers, args: any): Promise<Comma
526
540
  }
527
541
 
528
542
  export async function handleChangeModel(h: CommandHelpers, args: any): Promise<CommandResult> {
529
- const provider = h.getProvider();
543
+ const provider = h.getProvider(args?.agentType);
530
544
  const model = args?.model;
531
545
 
532
546
  LOG.info('Command', `[change_model] model=${model} provider=${provider?.type} category=${provider?.category} ideType=${h.currentIdeType} providerType=${h.currentProviderType}`);
533
547
 
534
548
  // ACP provider
535
549
  if (provider?.category === 'acp') {
536
- const adapter = h.getCliAdapter(provider.type);
550
+ const adapter = getTargetedCliAdapter(h, args, provider.type);
537
551
  LOG.info('Command', `[change_model] ACP adapter found: ${!!adapter}, type=${(adapter as any)?.cliType}, hasAcpInstance=${!!(adapter as any)?._acpInstance}`);
538
552
  if (adapter) {
539
553
  const acpInstance = (adapter as any)._acpInstance;
@@ -587,11 +601,11 @@ export async function handleSetThoughtLevel(h: CommandHelpers, args: any): Promi
587
601
  const value = args?.value;
588
602
  if (!configId || !value) return { success: false, error: 'configId and value required' };
589
603
 
590
- const provider = h.getProvider();
604
+ const provider = h.getProvider(args?.agentType);
591
605
  if (!provider || provider.category !== 'acp') {
592
606
  return { success: false, error: 'set_thought_level only for ACP providers' };
593
607
  }
594
- const adapter = h.getCliAdapter(provider.type);
608
+ const adapter = getTargetedCliAdapter(h, args, provider.type);
595
609
  const acpInstance = adapter?._acpInstance;
596
610
  if (!acpInstance) return { success: false, error: 'ACP instance not found' };
597
611
 
@@ -605,7 +619,7 @@ export async function handleSetThoughtLevel(h: CommandHelpers, args: any): Promi
605
619
  }
606
620
 
607
621
  export async function handleResolveAction(h: CommandHelpers, args: any): Promise<CommandResult> {
608
- const provider = h.getProvider();
622
+ const provider = h.getProvider(args?.agentType);
609
623
  const action = args?.action || 'approve';
610
624
  const button = args?.button || args?.buttonText
611
625
  || (action === 'approve' ? 'Accept' : action === 'reject' ? 'Reject' : 'Accept');
@@ -614,8 +628,20 @@ export async function handleResolveAction(h: CommandHelpers, args: any): Promise
614
628
 
615
629
  // 0. CLI / ACP category: navigate approval dialog via PTY arrow keys + Enter
616
630
  if (provider?.category === 'cli') {
617
- const adapter = h.getCliAdapter(provider.type);
631
+ const adapter = getTargetedCliAdapter(h, args, provider.type);
618
632
  if (!adapter) return { success: false, error: 'CLI adapter not running' };
633
+
634
+ // Handle data-driven resolve actions (like from the dashboard 'Fix' button)
635
+ if (args?.data && typeof (adapter as any).resolveAction === 'function') {
636
+ try {
637
+ await (adapter as any).resolveAction(args.data);
638
+ LOG.info('Command', `[resolveAction] CLI PTY → resolveAction triggered with data payload`);
639
+ return { success: true, method: 'cli-resolve-action' };
640
+ } catch (e: any) {
641
+ return { success: false, error: `CLI resolveAction failed: ${e.message}` };
642
+ }
643
+ }
644
+
619
645
  const status = (adapter as any).getStatus?.();
620
646
  if (status?.status !== 'waiting_approval') {
621
647
  return { success: false, error: 'Not in approval state' };
@@ -83,7 +83,8 @@ export class DaemonCliManager {
83
83
  const provider = this.providerLoader.getMeta(normalizedType);
84
84
  if (provider && provider.category === 'cli' && provider.patterns && provider.spawn) {
85
85
  console.log(chalk.cyan(` 📦 Using provider: ${provider.name} (${provider.type})`));
86
- return new ProviderCliAdapter(provider as any, workingDir, cliArgs);
86
+ const resolvedProvider = this.providerLoader.resolve(normalizedType) || provider;
87
+ return new ProviderCliAdapter(resolvedProvider as any, workingDir, cliArgs);
87
88
  }
88
89
 
89
90
  throw new Error(`No CLI provider found for '${cliType}'. Create a provider.js in providers/cli/${cliType}/`);
@@ -182,7 +183,8 @@ export class DaemonCliManager {
182
183
  // If InstanceManager exists, manage as CliProviderInstance unified
183
184
  const instanceManager = this.deps.getInstanceManager();
184
185
  if (provider && instanceManager) {
185
- const cliInstance = new CliProviderInstance(provider, resolvedDir, cliArgs, key);
186
+ const resolvedProvider = this.providerLoader.resolve(cliType, { version: cliInfo.version }) || provider;
187
+ const cliInstance = new CliProviderInstance(resolvedProvider, resolvedDir, cliArgs, key);
186
188
  try {
187
189
  await instanceManager.addInstance(key, cliInstance, {
188
190
  serverConn: this.deps.getServerConn(),