@adhdev/daemon-core 0.5.31 → 0.5.33

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
@@ -2607,6 +2607,7 @@ declare class CliProviderInstance implements ProviderInstance {
2607
2607
  private monitor;
2608
2608
  private generatingDebounceTimer;
2609
2609
  private generatingDebouncePending;
2610
+ private lastApprovalEventAt;
2610
2611
  private historyWriter;
2611
2612
  readonly instanceId: string;
2612
2613
  constructor(provider: ProviderModule, workingDir: string, cliArgs?: string[], instanceId?: string);
@@ -2615,6 +2616,8 @@ declare class CliProviderInstance implements ProviderInstance {
2615
2616
  getState(): ProviderState;
2616
2617
  onEvent(event: string, data?: any): void;
2617
2618
  dispose(): void;
2619
+ private completedDebounceTimer;
2620
+ private completedDebouncePending;
2618
2621
  private detectStatusTransition;
2619
2622
  private pushEvent;
2620
2623
  private flushEvents;
package/dist/index.js CHANGED
@@ -6745,7 +6745,7 @@ try {
6745
6745
  LOG.error("CLI", "[ProviderCliAdapter] node-pty not found. Terminal features disabled.");
6746
6746
  }
6747
6747
  function stripAnsi(str) {
6748
- return str.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "").replace(/\x1B\][^\x07]*\x07/g, "").replace(/\x1B\][^\x1B]*\x1B\\/g, "");
6748
+ return str.replace(/\x1B\[\d*[A-HJKSTfG]/g, " ").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "").replace(/\x1B\][^\x07]*\x07/g, "").replace(/\x1B\][^\x1B]*\x1B\\/g, "").replace(/ +/g, " ");
6749
6749
  }
6750
6750
  function findBinary(name) {
6751
6751
  const isWin = os11.platform() === "win32";
@@ -7053,6 +7053,9 @@ var ProviderCliAdapter = class {
7053
7053
  }
7054
7054
  return;
7055
7055
  }
7056
+ if (cleanData.trim().length > 5) {
7057
+ LOG.debug("CLI", `[${this.cliType}] output chunk (${cleanData.length}): ${cleanData.slice(0, 300).replace(/\n/g, "\\n")}`);
7058
+ }
7056
7059
  const hasApproval = patterns.approval.some((p) => p.test(this.recentOutputBuffer));
7057
7060
  if (hasApproval && this.currentStatus !== "waiting_approval") {
7058
7061
  const inCooldown = this.lastApprovalResolvedAt && Date.now() - this.lastApprovalResolvedAt < this.timeouts.approvalCooldown;
@@ -7333,6 +7336,7 @@ var CliProviderInstance = class {
7333
7336
  monitor;
7334
7337
  generatingDebounceTimer = null;
7335
7338
  generatingDebouncePending = null;
7339
+ lastApprovalEventAt = 0;
7336
7340
  historyWriter;
7337
7341
  instanceId;
7338
7342
  // ─── Lifecycle ─────────────────────────────────
@@ -7417,7 +7421,8 @@ var CliProviderInstance = class {
7417
7421
  this.adapter.shutdown();
7418
7422
  this.monitor.reset();
7419
7423
  }
7420
- // ─── Status transition detection (moved from daemon-status.ts) ──────
7424
+ completedDebounceTimer = null;
7425
+ completedDebouncePending = null;
7421
7426
  detectStatusTransition() {
7422
7427
  const now = Date.now();
7423
7428
  const adapterStatus = this.adapter.getStatus();
@@ -7427,7 +7432,15 @@ var CliProviderInstance = class {
7427
7432
  if (newStatus !== this.lastStatus) {
7428
7433
  LOG.info("CLI", `[${this.type}] status: ${this.lastStatus} \u2192 ${newStatus}`);
7429
7434
  if (this.lastStatus === "idle" && newStatus === "generating") {
7430
- this.generatingStartedAt = now;
7435
+ if (this.completedDebouncePending) {
7436
+ LOG.info("CLI", `[${this.type}] cancelled pending completed (resumed generating)`);
7437
+ if (this.completedDebounceTimer) {
7438
+ clearTimeout(this.completedDebounceTimer);
7439
+ this.completedDebounceTimer = null;
7440
+ }
7441
+ this.completedDebouncePending = null;
7442
+ }
7443
+ if (!this.generatingStartedAt) this.generatingStartedAt = now;
7431
7444
  if (this.generatingDebounceTimer) clearTimeout(this.generatingDebounceTimer);
7432
7445
  this.generatingDebouncePending = { chatTitle, timestamp: now };
7433
7446
  this.generatingDebounceTimer = setTimeout(() => {
@@ -7446,16 +7459,25 @@ var CliProviderInstance = class {
7446
7459
  this.pushEvent({ event: "agent:generating_started", ...this.generatingDebouncePending });
7447
7460
  this.generatingDebouncePending = null;
7448
7461
  }
7462
+ if (this.completedDebounceTimer) {
7463
+ clearTimeout(this.completedDebounceTimer);
7464
+ this.completedDebounceTimer = null;
7465
+ }
7466
+ this.completedDebouncePending = null;
7449
7467
  if (!this.generatingStartedAt) this.generatingStartedAt = now;
7450
7468
  const modal = adapterStatus.activeModal;
7451
7469
  LOG.info("CLI", `[${this.type}] approval modal: "${modal?.message?.slice(0, 80) ?? "none"}"`);
7452
- this.pushEvent({
7453
- event: "agent:waiting_approval",
7454
- chatTitle,
7455
- timestamp: now,
7456
- modalMessage: modal?.message,
7457
- modalButtons: modal?.buttons
7458
- });
7470
+ const approvalCooldown = 5e3;
7471
+ if (this.lastStatus !== "waiting_approval" && (!this.lastApprovalEventAt || now - this.lastApprovalEventAt > approvalCooldown)) {
7472
+ this.lastApprovalEventAt = now;
7473
+ this.pushEvent({
7474
+ event: "agent:waiting_approval",
7475
+ chatTitle,
7476
+ timestamp: now,
7477
+ modalMessage: modal?.message,
7478
+ modalButtons: modal?.buttons
7479
+ });
7480
+ }
7459
7481
  } else if (newStatus === "idle" && (this.lastStatus === "generating" || this.lastStatus === "waiting_approval")) {
7460
7482
  const duration = this.generatingStartedAt ? Math.round((now - this.generatingStartedAt) / 1e3) : 0;
7461
7483
  if (this.generatingDebouncePending) {
@@ -7465,17 +7487,31 @@ var CliProviderInstance = class {
7465
7487
  this.generatingDebounceTimer = null;
7466
7488
  }
7467
7489
  this.generatingDebouncePending = null;
7490
+ this.generatingStartedAt = 0;
7468
7491
  } else {
7469
- LOG.info("CLI", `[${this.type}] completed in ${duration}s`);
7470
- this.pushEvent({ event: "agent:generating_completed", chatTitle, duration, timestamp: now });
7492
+ if (this.completedDebounceTimer) clearTimeout(this.completedDebounceTimer);
7493
+ this.completedDebouncePending = { chatTitle, duration, timestamp: now };
7494
+ this.completedDebounceTimer = setTimeout(() => {
7495
+ if (this.completedDebouncePending) {
7496
+ LOG.info("CLI", `[${this.type}] completed in ${this.completedDebouncePending.duration}s`);
7497
+ this.pushEvent({ event: "agent:generating_completed", ...this.completedDebouncePending });
7498
+ this.completedDebouncePending = null;
7499
+ this.generatingStartedAt = 0;
7500
+ }
7501
+ this.completedDebounceTimer = null;
7502
+ }, 2e3);
7471
7503
  }
7472
- this.generatingStartedAt = 0;
7473
7504
  } else if (newStatus === "stopped") {
7474
7505
  if (this.generatingDebounceTimer) {
7475
7506
  clearTimeout(this.generatingDebounceTimer);
7476
7507
  this.generatingDebounceTimer = null;
7477
7508
  }
7478
7509
  this.generatingDebouncePending = null;
7510
+ if (this.completedDebounceTimer) {
7511
+ clearTimeout(this.completedDebounceTimer);
7512
+ this.completedDebounceTimer = null;
7513
+ }
7514
+ this.completedDebouncePending = null;
7479
7515
  this.pushEvent({ event: "agent:stopped", chatTitle, timestamp: now });
7480
7516
  }
7481
7517
  this.lastStatus = newStatus;
@@ -8874,7 +8910,8 @@ var ProviderStreamAdapter = class {
8874
8910
  extensionId: this.extensionId,
8875
8911
  status: "error",
8876
8912
  messages: [],
8877
- inputContent: ""
8913
+ inputContent: "",
8914
+ _error: message
8878
8915
  };
8879
8916
  }
8880
8917
  };
@@ -8893,9 +8930,11 @@ var DaemonAgentStreamManager = class {
8893
8930
  if (providerLoader) {
8894
8931
  const allExtProviders = providerLoader.getByCategory("extension");
8895
8932
  for (const p of allExtProviders) {
8896
- const adapter = new ProviderStreamAdapter(p);
8933
+ const resolved = providerLoader.resolve(p.type);
8934
+ if (!resolved) continue;
8935
+ const adapter = new ProviderStreamAdapter(resolved);
8897
8936
  this.allAdapters.push(adapter);
8898
- this.logFn(`[AgentStream] Adapter created: ${p.type} (${p.name})`);
8937
+ this.logFn(`[AgentStream] Adapter created: ${p.type} (${p.name}) scripts=${Object.keys(resolved.scripts || {}).join(",") || "none"}`);
8899
8938
  }
8900
8939
  }
8901
8940
  }
@@ -8982,6 +9021,7 @@ var DaemonAgentStreamManager = class {
8982
9021
  try {
8983
9022
  const evaluate = (expr, timeout) => cdp.evaluateInSessionFrame(agent.sessionId, expr, timeout);
8984
9023
  const state = await agent.adapter.readChat(evaluate);
9024
+ this.logFn(`[AgentStream] readChat(${type}) result: status=${state.status} msgs=${state.messages?.length || 0} model=${state.model || ""}${state.status === "error" ? " error=" + JSON.stringify(state.error || state._error || "unknown") : ""}`);
8985
9025
  agent.lastState = state;
8986
9026
  agent.lastError = null;
8987
9027
  if (state.status === "panel_hidden") {