@adhdev/daemon-core 0.7.15 → 0.7.17
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/dist/index.js +19 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -76
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +9 -74
- package/src/commands/cli-manager.ts +21 -12
package/package.json
CHANGED
|
@@ -702,40 +702,23 @@ export class ProviderCliAdapter implements CliAdapter {
|
|
|
702
702
|
this.accumulatedBuffer = (this.accumulatedBuffer + cleanData).slice(-ProviderCliAdapter.MAX_ACCUMULATED_BUFFER);
|
|
703
703
|
this.accumulatedRawBuffer = (this.accumulatedRawBuffer + rawData).slice(-ProviderCliAdapter.MAX_ACCUMULATED_BUFFER);
|
|
704
704
|
|
|
705
|
-
// ─── Startup
|
|
705
|
+
// ─── Startup: detect CLI readiness (no auto-proceed)
|
|
706
706
|
if (this.startupParseGate) {
|
|
707
707
|
this.startupBuffer += cleanData;
|
|
708
|
-
|
|
709
|
-
const dialogPatterns = [
|
|
710
|
-
/Do you want to connect/i,
|
|
711
|
-
/Do you trust the files/i,
|
|
712
|
-
/Quick safety check/i,
|
|
713
|
-
/Is this a project/i,
|
|
714
|
-
/Enter to confirm/i,
|
|
715
|
-
/be able to read, edit, and execute/i,
|
|
716
|
-
/Security guide/i,
|
|
717
|
-
];
|
|
718
|
-
if (dialogPatterns.some(p => p.test(this.startupBuffer))) {
|
|
719
|
-
setTimeout(() => this.ptyProcess?.write('\r'), this.timeouts.dialogAccept);
|
|
720
|
-
this.startupBuffer = '';
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
708
|
const elapsed = Date.now() - this.spawnAt;
|
|
725
|
-
const bufCap = this.startupBuffer.length > 12000;
|
|
726
|
-
|
|
727
|
-
// Use detectStatus script to check if CLI is ready (shows a prompt)
|
|
728
709
|
const scriptStatus = this.runDetectStatus(this.startupBuffer);
|
|
729
|
-
const isReady = scriptStatus === 'idle'
|
|
710
|
+
const isReady = scriptStatus === 'idle'
|
|
711
|
+
|| scriptStatus === 'waiting_approval'
|
|
712
|
+
|| elapsed > 8000
|
|
713
|
+
|| this.startupBuffer.length > 12000;
|
|
730
714
|
|
|
731
715
|
if (isReady) {
|
|
732
716
|
this.startupParseGate = false;
|
|
733
717
|
this.ready = true;
|
|
734
|
-
LOG.info('CLI', `[${this.cliType}] Startup
|
|
718
|
+
LOG.info('CLI', `[${this.cliType}] Startup ready (${elapsed}ms, scriptStatus=${scriptStatus})`);
|
|
735
719
|
this.onStatusChange?.();
|
|
736
|
-
} else {
|
|
737
|
-
return;
|
|
738
720
|
}
|
|
721
|
+
// No early return — status detection runs from the start
|
|
739
722
|
}
|
|
740
723
|
|
|
741
724
|
// ─── Script-based status detection
|
|
@@ -957,56 +940,8 @@ export class ProviderCliAdapter implements CliAdapter {
|
|
|
957
940
|
}
|
|
958
941
|
|
|
959
942
|
private commitCurrentTranscript(): void {
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
if (parsed && Array.isArray(parsed.messages) && parsed.messages.length > 0) {
|
|
963
|
-
const parsedMessages = parsed.messages
|
|
964
|
-
.filter((m: any) => m && (m.role === 'user' || m.role === 'assistant'))
|
|
965
|
-
.map((m: any) => ({
|
|
966
|
-
role: m.role,
|
|
967
|
-
content: typeof m.content === 'string' ? m.content : String(m.content || ''),
|
|
968
|
-
timestamp: m.timestamp,
|
|
969
|
-
}));
|
|
970
|
-
const latestAssistant = [...parsedMessages]
|
|
971
|
-
.reverse()
|
|
972
|
-
.find((m: CliChatMessage) => m.role === 'assistant' && m.content.trim());
|
|
973
|
-
if (latestAssistant) {
|
|
974
|
-
LOG.info('CLI', `[${this.cliType}] commitCurrentTranscript parsed assistant len=${latestAssistant.content.length} scopePrompt=${JSON.stringify(this.currentTurnScope?.prompt || '').slice(0, 120)}`);
|
|
975
|
-
const nextMessages = [...baseMessages];
|
|
976
|
-
const last = nextMessages[nextMessages.length - 1];
|
|
977
|
-
if (last?.role === 'assistant') {
|
|
978
|
-
last.content = latestAssistant.content;
|
|
979
|
-
last.timestamp = latestAssistant.timestamp || last.timestamp;
|
|
980
|
-
} else if (last?.role === 'user') {
|
|
981
|
-
nextMessages.push({
|
|
982
|
-
role: 'assistant',
|
|
983
|
-
content: latestAssistant.content,
|
|
984
|
-
timestamp: latestAssistant.timestamp || Date.now(),
|
|
985
|
-
});
|
|
986
|
-
} else {
|
|
987
|
-
nextMessages.push({
|
|
988
|
-
role: 'assistant',
|
|
989
|
-
content: latestAssistant.content,
|
|
990
|
-
timestamp: latestAssistant.timestamp || Date.now(),
|
|
991
|
-
});
|
|
992
|
-
}
|
|
993
|
-
this.committedMessages = nextMessages;
|
|
994
|
-
this.syncMessageViews();
|
|
995
|
-
return;
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
const fallback = String(this.responseBuffer || '').trim();
|
|
1000
|
-
LOG.info('CLI', `[${this.cliType}] commitCurrentTranscript fallback len=${fallback.length} scopePrompt=${JSON.stringify(this.currentTurnScope?.prompt || '').slice(0, 120)}`);
|
|
1001
|
-
if (!fallback) return;
|
|
1002
|
-
const last = baseMessages[baseMessages.length - 1];
|
|
1003
|
-
if (last?.role === 'assistant') {
|
|
1004
|
-
last.content = fallback;
|
|
1005
|
-
} else {
|
|
1006
|
-
baseMessages.push({ role: 'assistant', content: fallback, timestamp: Date.now() });
|
|
1007
|
-
}
|
|
1008
|
-
this.committedMessages = baseMessages;
|
|
1009
|
-
this.syncMessageViews();
|
|
943
|
+
// No-op: terminal output is the canonical display for CLI providers.
|
|
944
|
+
// Assistant text extraction from PTY output has been removed.
|
|
1010
945
|
}
|
|
1011
946
|
|
|
1012
947
|
// ─── Script Execution ──────────────────────────
|
|
@@ -62,6 +62,15 @@ export interface HostedCliRuntimeDescriptor {
|
|
|
62
62
|
cliArgs?: string[];
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
const chalkApi: any = (chalk as any)?.yellow
|
|
66
|
+
? (chalk as any)
|
|
67
|
+
: (chalk as any)?.default || null;
|
|
68
|
+
|
|
69
|
+
function colorize(color: 'red' | 'green' | 'yellow' | 'cyan', text: string): string {
|
|
70
|
+
const fn = chalkApi?.[color];
|
|
71
|
+
return typeof fn === 'function' ? fn(text) : text;
|
|
72
|
+
}
|
|
73
|
+
|
|
65
74
|
// ─── DaemonCliManager ────────────────────────────
|
|
66
75
|
|
|
67
76
|
export class DaemonCliManager {
|
|
@@ -87,16 +96,16 @@ export class DaemonCliManager {
|
|
|
87
96
|
const provider = this.providerLoader.getByAlias(cliType);
|
|
88
97
|
const actKind = provider?.category === 'acp' ? 'acp' : 'cli';
|
|
89
98
|
let next = loadConfig();
|
|
90
|
-
console.log(
|
|
99
|
+
console.log(colorize('cyan', ` 📂 Saving recent workspace: ${dir}`));
|
|
91
100
|
const recent = next.recentCliWorkspaces || [];
|
|
92
101
|
if (!recent.includes(dir)) {
|
|
93
102
|
next = { ...next, recentCliWorkspaces: [dir, ...recent].slice(0, 10) };
|
|
94
103
|
}
|
|
95
104
|
next = appendWorkspaceActivity(next, dir, { kind: actKind, agentType: normalizedType });
|
|
96
105
|
saveConfig(next);
|
|
97
|
-
console.log(
|
|
106
|
+
console.log(colorize('green', ` ✓ Recent workspace saved: ${dir}`));
|
|
98
107
|
} catch (e) {
|
|
99
|
-
console.error(
|
|
108
|
+
console.error(colorize('red', ` ✗ Failed to save recent workspace: ${e}`));
|
|
100
109
|
}
|
|
101
110
|
}
|
|
102
111
|
|
|
@@ -129,7 +138,7 @@ export class DaemonCliManager {
|
|
|
129
138
|
// Load CLI config from provider.js
|
|
130
139
|
const provider = this.providerLoader.getMeta(normalizedType);
|
|
131
140
|
if (provider && provider.category === 'cli' && provider.patterns && provider.spawn) {
|
|
132
|
-
console.log(
|
|
141
|
+
console.log(colorize('cyan', ` 📦 Using provider: ${provider.name} (${provider.type})`));
|
|
133
142
|
const resolvedProvider = this.providerLoader.resolve(normalizedType) || provider;
|
|
134
143
|
const transportFactory = this.getTransportFactory(runtimeId, normalizedType, workingDir, cliArgs, attachExisting);
|
|
135
144
|
return new ProviderCliAdapter(resolvedProvider as any, workingDir, cliArgs, transportFactory);
|
|
@@ -243,7 +252,7 @@ export class DaemonCliManager {
|
|
|
243
252
|
}
|
|
244
253
|
}
|
|
245
254
|
|
|
246
|
-
console.log(
|
|
255
|
+
console.log(colorize('cyan', ` 🔌 Starting ACP agent: ${provider.name} (${provider.type}) in ${resolvedDir}`));
|
|
247
256
|
|
|
248
257
|
const acpInstance = new AcpProviderInstance(provider, resolvedDir, cliArgs);
|
|
249
258
|
await instanceManager.addInstance(key, acpInstance, {
|
|
@@ -280,13 +289,13 @@ export class DaemonCliManager {
|
|
|
280
289
|
setOnPtyData: () => {},
|
|
281
290
|
} as any);
|
|
282
291
|
|
|
283
|
-
console.log(
|
|
292
|
+
console.log(colorize('green', ` ✓ ACP agent started: ${provider.name} in ${resolvedDir}`));
|
|
284
293
|
|
|
285
294
|
// If initialModel exists, change model after session start
|
|
286
295
|
if (initialModel) {
|
|
287
296
|
try {
|
|
288
297
|
await acpInstance.setConfigOption('model', initialModel);
|
|
289
|
-
console.log(
|
|
298
|
+
console.log(colorize('green', ` 🤖 Initial model set: ${initialModel}`));
|
|
290
299
|
} catch (e: any) {
|
|
291
300
|
LOG.warn('CLI', `[ACP] Initial model set failed: ${e?.message}`);
|
|
292
301
|
}
|
|
@@ -301,9 +310,9 @@ export class DaemonCliManager {
|
|
|
301
310
|
const cliInfo = await detectCLI(cliType, this.providerLoader);
|
|
302
311
|
if (!cliInfo) throw new Error(`${cliType} not found`);
|
|
303
312
|
|
|
304
|
-
console.log(
|
|
313
|
+
console.log(colorize('yellow', ` ⚡ Starting CLI ${cliType} in ${resolvedDir}...`));
|
|
305
314
|
if (provider) {
|
|
306
|
-
console.log(
|
|
315
|
+
console.log(colorize('cyan', ` 📦 Using provider: ${provider.name} (${provider.type})`));
|
|
307
316
|
}
|
|
308
317
|
|
|
309
318
|
// If InstanceManager exists, manage as CliProviderInstance unified
|
|
@@ -320,7 +329,7 @@ export class DaemonCliManager {
|
|
|
320
329
|
{},
|
|
321
330
|
false,
|
|
322
331
|
);
|
|
323
|
-
console.log(
|
|
332
|
+
console.log(colorize('green', ` ✓ CLI started: ${cliInfo.displayName} v${cliInfo.version || 'unknown'} in ${resolvedDir}`));
|
|
324
333
|
} else {
|
|
325
334
|
// Fallback: InstanceManager without directly adapter manage
|
|
326
335
|
const adapter = this.createAdapter(cliType, resolvedDir, cliArgs, key, false);
|
|
@@ -357,7 +366,7 @@ export class DaemonCliManager {
|
|
|
357
366
|
}
|
|
358
367
|
|
|
359
368
|
this.adapters.set(key, adapter);
|
|
360
|
-
console.log(
|
|
369
|
+
console.log(colorize('green', ` ✓ CLI started: ${cliInfo.displayName} v${cliInfo.version || 'unknown'} in ${resolvedDir}`));
|
|
361
370
|
}
|
|
362
371
|
|
|
363
372
|
try { addCliHistory({ category: 'cli', cliType, dir: resolvedDir, workspace: resolvedDir, cliArgs, model: initialModel }); } catch (e) { LOG.warn('CLI', `CLI history save failed: ${(e as Error)?.message}`); }
|
|
@@ -541,7 +550,7 @@ export class DaemonCliManager {
|
|
|
541
550
|
if (found) {
|
|
542
551
|
await this.stopSessionWithMode(found.key, mode);
|
|
543
552
|
} else {
|
|
544
|
-
console.log(
|
|
553
|
+
console.log(colorize('yellow', ` ⚠ No adapter found for ${cliType}`));
|
|
545
554
|
}
|
|
546
555
|
return { success: true, cliType, dir, stopped: true, mode };
|
|
547
556
|
}
|