@adhdev/daemon-core 0.6.49 → 0.6.51

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.d.ts CHANGED
@@ -179,9 +179,13 @@ interface ADHDevConfig {
179
179
  disableUpstream?: boolean;
180
180
  }
181
181
  interface CliHistoryEntry {
182
+ category?: 'ide' | 'cli' | 'acp';
182
183
  cliType: string;
183
184
  dir: string;
184
185
  cliArgs?: string[];
186
+ workspace?: string;
187
+ newWindow?: boolean;
188
+ model?: string;
185
189
  timestamp: number;
186
190
  label?: string;
187
191
  }
@@ -210,7 +214,7 @@ declare function isSetupComplete(): boolean;
210
214
  */
211
215
  declare function resetConfig(): void;
212
216
  /**
213
- * Add CLI launch to history (max 20, dedup by cliType+dir+args)
217
+ * Add launch to history (max 20, dedup by category+type+dir+args+workspace+model)
214
218
  */
215
219
  declare function addCliHistory(entry: Omit<CliHistoryEntry, 'timestamp'>): void;
216
220
 
@@ -2496,7 +2500,7 @@ declare const DAEMON_WS_PATH = "/ipc";
2496
2500
  * category: 'cli'
2497
2501
  * binary: string — binary name
2498
2502
  * spawn: { command, args, shell, env }
2499
- * patterns: { prompt, generating, approval, ready }
2503
+ * patterns: { prompt, generating, approval, ready } — prompt helps end startup splash-gate early; sendMessage does not wait for it
2500
2504
  * timeouts?: { idleFinish, generatingIdle, maxResponse, approvalCooldown, outputSettle, ... }
2501
2505
  * cleanOutput(raw, lastUserInput): string
2502
2506
  */
@@ -2570,6 +2574,9 @@ declare class ProviderCliAdapter implements CliAdapter {
2570
2574
  private idleTimeout;
2571
2575
  private ready;
2572
2576
  private startupBuffer;
2577
+ /** After spawn: briefly skip generating/settle so splash/redraw does not flip status; not used to gate sendMessage */
2578
+ private startupParseGate;
2579
+ private spawnAt;
2573
2580
  private onPtyDataCallback;
2574
2581
  private ptyOutputBuffer;
2575
2582
  private ptyOutputFlushTimer;
package/dist/index.js CHANGED
@@ -320,14 +320,26 @@ function addCliHistory(entry) {
320
320
  const config = loadConfig();
321
321
  const history = config.cliHistory || [];
322
322
  const argsKey = (entry.cliArgs || []).join(" ");
323
+ const category = entry.category || "cli";
324
+ const workspaceKey = entry.workspace || "";
325
+ const modelKey = entry.model || "";
323
326
  const filtered = history.filter((h) => {
324
327
  const hArgsKey = (h.cliArgs || []).join(" ");
325
- return !(h.cliType === entry.cliType && h.dir === entry.dir && hArgsKey === argsKey);
328
+ return !((h.category || "cli") === category && h.cliType === entry.cliType && h.dir === entry.dir && hArgsKey === argsKey && (h.workspace || "") === workspaceKey && (h.model || "") === modelKey);
326
329
  });
327
330
  filtered.unshift({
328
331
  ...entry,
332
+ category,
329
333
  timestamp: Date.now(),
330
- label: entry.label || `${entry.cliType} \xB7 ${entry.dir.split("/").filter(Boolean).pop() || "root"}${argsKey ? ` (${argsKey})` : ""}`
334
+ label: entry.label || (() => {
335
+ const base = `${entry.cliType} \xB7 ${entry.dir.split("/").filter(Boolean).pop() || "root"}`;
336
+ const suffix = [];
337
+ if (entry.workspace && entry.workspace !== entry.dir) suffix.push(entry.workspace.split("/").filter(Boolean).pop() || entry.workspace);
338
+ if (entry.model) suffix.push(`model=${entry.model}`);
339
+ if (argsKey) suffix.push(argsKey);
340
+ if (entry.newWindow) suffix.push("new window");
341
+ return suffix.length > 0 ? `${base} (${suffix.join(" \xB7 ")})` : base;
342
+ })()
331
343
  });
332
344
  config.cliHistory = filtered.slice(0, 20);
333
345
  saveConfig(config);
@@ -768,6 +780,9 @@ var init_provider_cli_adapter = __esm({
768
780
  idleTimeout = null;
769
781
  ready = false;
770
782
  startupBuffer = "";
783
+ /** After spawn: briefly skip generating/settle so splash/redraw does not flip status; not used to gate sendMessage */
784
+ startupParseGate = false;
785
+ spawnAt = 0;
771
786
  // PTY I/O
772
787
  onPtyDataCallback = null;
773
788
  ptyOutputBuffer = "";
@@ -881,9 +896,15 @@ var init_provider_cli_adapter = __esm({
881
896
  this.ptyProcess = null;
882
897
  this.setStatus("stopped", "pty_exit");
883
898
  this.ready = false;
899
+ this.startupParseGate = false;
900
+ this.spawnAt = 0;
884
901
  this.onStatusChange?.();
885
902
  });
886
- this.setStatus("starting", "spawn");
903
+ this.spawnAt = Date.now();
904
+ this.startupParseGate = true;
905
+ this.startupBuffer = "";
906
+ this.ready = true;
907
+ this.setStatus("idle", "pty_ready");
887
908
  this.onStatusChange?.();
888
909
  }
889
910
  // ─── Output state machine ────────────────────────────
@@ -899,7 +920,7 @@ var init_provider_cli_adapter = __esm({
899
920
  }
900
921
  }
901
922
  this.recentOutputBuffer = (this.recentOutputBuffer + cleanData).slice(-1e3);
902
- if (!this.ready) {
923
+ if (this.startupParseGate) {
903
924
  this.startupBuffer += cleanData;
904
925
  LOG.info("CLI", `[${this.cliType}] startup chunk (${cleanData.length} chars): ${cleanData.slice(0, 200).replace(/\n/g, "\\n")}`);
905
926
  const dialogPatterns = [
@@ -914,13 +935,19 @@ var init_provider_cli_adapter = __esm({
914
935
  this.startupBuffer = "";
915
936
  return;
916
937
  }
917
- if (patterns.prompt.some((p) => p.test(this.startupBuffer))) {
918
- this.ready = true;
919
- this.setStatus("idle", "prompt_matched");
920
- LOG.info("CLI", `[${this.cliType}] \u2713 Ready`);
921
- this.onStatusChange?.();
938
+ const elapsed = Date.now() - this.spawnAt;
939
+ const bufCap = this.startupBuffer.length > 12e3;
940
+ const promptMatched = patterns.prompt.some((p) => p.test(this.startupBuffer));
941
+ if (promptMatched || elapsed > 8e3 || bufCap) {
942
+ this.startupParseGate = false;
943
+ if (promptMatched) {
944
+ LOG.info("CLI", `[${this.cliType}] \u2713 Startup gate end (prompt matched)`);
945
+ } else {
946
+ LOG.info("CLI", `[${this.cliType}] startup gate end (${elapsed}ms, cap=${bufCap}, prompt=${promptMatched})`);
947
+ }
948
+ } else {
949
+ return;
922
950
  }
923
- return;
924
951
  }
925
952
  if (cleanData.trim().length > 5) {
926
953
  LOG.debug("CLI", `[${this.cliType}] output chunk (${cleanData.length}): ${cleanData.slice(0, 300).replace(/\n/g, "\\n")}`);
@@ -1128,6 +1155,8 @@ var init_provider_cli_adapter = __esm({
1128
1155
  this.ptyProcess = null;
1129
1156
  this.setStatus("stopped", "stop_cmd");
1130
1157
  this.ready = false;
1158
+ this.startupParseGate = false;
1159
+ this.spawnAt = 0;
1131
1160
  this.onStatusChange?.();
1132
1161
  }, this.timeouts.shutdownGrace);
1133
1162
  }
@@ -1174,16 +1203,29 @@ var init_provider_cli_adapter = __esm({
1174
1203
  * Used by DevServer /api/cli/debug endpoint.
1175
1204
  */
1176
1205
  getDebugState() {
1206
+ const sb = this.startupBuffer;
1207
+ const testOnStartup = (p) => {
1208
+ const flags = p.flags.includes("g") ? p.flags.replace(/g/g, "") : p.flags;
1209
+ return new RegExp(p.source, flags).test(sb);
1210
+ };
1211
+ const promptDiagnostics = this.provider.patterns.prompt.map((p) => ({
1212
+ pattern: p.toString(),
1213
+ matchedAgainstStartupBuffer: testOnStartup(p)
1214
+ }));
1177
1215
  return {
1178
1216
  type: this.cliType,
1179
1217
  name: this.cliName,
1180
1218
  status: this.currentStatus,
1181
1219
  ready: this.ready,
1220
+ startupParseGate: this.startupParseGate,
1221
+ spawnAt: this.spawnAt,
1182
1222
  workingDir: this.workingDir,
1183
1223
  messages: this.messages.slice(-20),
1184
1224
  messageCount: this.messages.length,
1185
- // Buffers
1186
- startupBuffer: this.startupBuffer.slice(-500),
1225
+ // Buffers (longer tails here than in periodic logs — for matching provider.json patterns)
1226
+ startupBuffer: sb.slice(-4e3),
1227
+ startupBufferLength: sb.length,
1228
+ promptDiagnostics,
1187
1229
  recentOutputBuffer: this.recentOutputBuffer.slice(-500),
1188
1230
  settledBuffer: this.settledBuffer.slice(-500),
1189
1231
  responseBuffer: this.responseBuffer.slice(-500),
@@ -7041,6 +7083,7 @@ function getAvailableIdeIds() {
7041
7083
  // src/commands/router.ts
7042
7084
  init_config();
7043
7085
  init_workspaces();
7086
+ init_config();
7044
7087
  init_logger();
7045
7088
 
7046
7089
  // src/logging/command-log.ts
@@ -7307,6 +7350,18 @@ var DaemonCommandRouter = class {
7307
7350
  };
7308
7351
  LOG.info("LaunchIDE", `target=${ideKey || "auto"}`);
7309
7352
  const result = await launchWithCdp(launchArgs);
7353
+ if (result.success && (result.ideId || ideKey)) {
7354
+ try {
7355
+ addCliHistory({
7356
+ category: "ide",
7357
+ cliType: result.ideId || ideKey,
7358
+ dir: resolvedWorkspace || "",
7359
+ workspace: resolvedWorkspace || "",
7360
+ newWindow: args?.newWindow === true
7361
+ });
7362
+ } catch {
7363
+ }
7364
+ }
7310
7365
  if (result.success && result.port && result.ideId && !this.deps.cdpManagers.has(result.ideId)) {
7311
7366
  const logFn = this.deps.getCdpLogFn ? this.deps.getCdpLogFn(result.ideId) : LOG.forComponent(`CDP:${result.ideId}`).asLogFn();
7312
7367
  const provider = this.deps.providerLoader.getMeta(result.ideId);
@@ -8924,7 +8979,7 @@ ${installInfo}`
8924
8979
  }
8925
8980
  }
8926
8981
  try {
8927
- addCliHistory({ cliType: normalizedType, dir: resolvedDir, cliArgs });
8982
+ addCliHistory({ category: "acp", cliType: normalizedType, dir: resolvedDir, workspace: resolvedDir, cliArgs, model: initialModel });
8928
8983
  } catch (e) {
8929
8984
  LOG.warn("CLI", `ACP history save failed: ${e?.message}`);
8930
8985
  }
@@ -9013,7 +9068,7 @@ ${installInfo}`
9013
9068
  console.log(import_chalk.default.green(` \u2713 CLI started: ${cliInfo.displayName} v${cliInfo.version || "unknown"} in ${resolvedDir}`));
9014
9069
  }
9015
9070
  try {
9016
- addCliHistory({ cliType, dir: resolvedDir, cliArgs });
9071
+ addCliHistory({ category: "cli", cliType, dir: resolvedDir, workspace: resolvedDir, cliArgs, model: initialModel });
9017
9072
  } catch (e) {
9018
9073
  LOG.warn("CLI", `CLI history save failed: ${e?.message}`);
9019
9074
  }