@adhdev/daemon-core 0.9.82-rc.213 → 0.9.82-rc.214

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.mjs CHANGED
@@ -10397,7 +10397,25 @@ var init_cli_state_engine = __esm({
10397
10397
  "CLI",
10398
10398
  `[${this.provider.type}] settled diagnostics prompt=${JSON.stringify(this.currentTurnScope?.prompt || "").slice(0, 140)} status=${String(status || "")} parsedStatus=${String(parsedStatus || "")} parsedMsgCount=${parsedMessages.length} lastParsedAssistant=${JSON.stringify((lastParsedAssistant?.content || "").slice(0, 120)).slice(0, 160)} responseBuffer=${JSON.stringify((snap.responseBuffer || "").slice(0, 160)).slice(0, 220)} recentActivity=${recentInteractiveActivity}`
10399
10399
  );
10400
- const shouldHoldGenerating = status === "idle" && this.isWaitingForResponse && !!this.currentTurnScope && !modal && !(parsedStatus === "idle" && !!lastParsedAssistant);
10400
+ const hasFinalCurrentTurnAssistant = (() => {
10401
+ if (parsedStatus !== "idle") return false;
10402
+ const msgs = Array.isArray(parsedMessages) ? parsedMessages : [];
10403
+ let lastUserIdx = -1;
10404
+ for (let i = msgs.length - 1; i >= 0; i--) {
10405
+ if (msgs[i]?.role === "user") {
10406
+ lastUserIdx = i;
10407
+ break;
10408
+ }
10409
+ }
10410
+ const searchSlice = lastUserIdx >= 0 ? msgs.slice(lastUserIdx + 1) : msgs;
10411
+ return searchSlice.some((m) => {
10412
+ if (!m || m.role !== "assistant") return false;
10413
+ if (typeof m.content !== "string" || !m.content.trim()) return false;
10414
+ const kind = typeof m.kind === "string" && m.kind.trim() ? m.kind.trim() : "standard";
10415
+ return kind === "standard" && m.meta?.streaming !== true;
10416
+ });
10417
+ })();
10418
+ const shouldHoldGenerating = status === "idle" && this.isWaitingForResponse && !!this.currentTurnScope && !modal && !hasFinalCurrentTurnAssistant;
10401
10419
  if (shouldHoldGenerating) {
10402
10420
  this.applyHoldGenerating(ctx);
10403
10421
  return;
@@ -35464,6 +35482,35 @@ function extractToolOutputContent(payload) {
35464
35482
  }
35465
35483
  return "";
35466
35484
  }
35485
+ function hasAssistantStandardMessageSinceLastUser(records, content) {
35486
+ const normalized = content.trim();
35487
+ if (!normalized) return false;
35488
+ for (let i = records.length - 1; i >= 0; i--) {
35489
+ const record = records[i];
35490
+ if (record.kind === "session_start") continue;
35491
+ if (record.role === "user") return false;
35492
+ if (record.role === "assistant" && record.kind === "standard" && record.content.trim() === normalized) {
35493
+ return true;
35494
+ }
35495
+ }
35496
+ return false;
35497
+ }
35498
+ function pushAssistantStandardMessage(records, sessionId, receivedAt, content, workspace) {
35499
+ const text = content.trim();
35500
+ if (!text) return;
35501
+ if (hasAssistantStandardMessageSinceLastUser(records, text)) return;
35502
+ const msg = {
35503
+ ts: new Date(receivedAt).toISOString(),
35504
+ receivedAt,
35505
+ role: "assistant",
35506
+ content: text,
35507
+ kind: "standard",
35508
+ agent: "codex-cli",
35509
+ historySessionId: sessionId
35510
+ };
35511
+ if (workspace) msg.workspace = workspace;
35512
+ records.push(msg);
35513
+ }
35467
35514
  function readSessionMeta(filePath) {
35468
35515
  try {
35469
35516
  const firstLine = fs15.readFileSync(filePath, "utf-8").split("\n").find(Boolean);
@@ -35519,13 +35566,34 @@ function parseSessionFile(filePath, sessionId, workspaceFallback) {
35519
35566
  }
35520
35567
  continue;
35521
35568
  }
35522
- if (type !== "response_item") continue;
35523
35569
  const payloadType = String(payload.type ?? "").trim();
35570
+ if (type === "event_msg") {
35571
+ if (payloadType === "task_complete") {
35572
+ pushAssistantStandardMessage(
35573
+ records,
35574
+ sessionId,
35575
+ receivedAt,
35576
+ flattenCodexContent(payload.last_agent_message),
35577
+ detectedWorkspace
35578
+ );
35579
+ } else if (payloadType === "agent_message" && String(payload.phase ?? "").trim() === "final_answer") {
35580
+ pushAssistantStandardMessage(
35581
+ records,
35582
+ sessionId,
35583
+ receivedAt,
35584
+ flattenCodexContent(payload.message),
35585
+ detectedWorkspace
35586
+ );
35587
+ }
35588
+ continue;
35589
+ }
35590
+ if (type !== "response_item") continue;
35524
35591
  if (payloadType === "message") {
35525
35592
  const role = String(payload.role ?? "").trim();
35526
35593
  if (role !== "user" && role !== "assistant") continue;
35527
35594
  const content = flattenCodexContent(payload.content);
35528
35595
  if (!content) continue;
35596
+ if (role === "assistant" && hasAssistantStandardMessageSinceLastUser(records, content)) continue;
35529
35597
  const msg = {
35530
35598
  ts: new Date(receivedAt).toISOString(),
35531
35599
  receivedAt,
@@ -39458,6 +39526,7 @@ async function maybeRunDaemonUpgradeHelperFromEnv() {
39458
39526
 
39459
39527
  // src/commands/router.ts
39460
39528
  init_mesh_work_queue();
39529
+ init_repo_mesh_types();
39461
39530
  import { homedir as homedir25, hostname as osHostname } from "os";
39462
39531
  import { basename as pathBasename, join as pathJoin, resolve as pathResolve2 } from "path";
39463
39532
  import * as fs22 from "fs";
@@ -42017,7 +42086,8 @@ var DaemonCommandRouter = class {
42017
42086
  ...result ? {
42018
42087
  success: result.success === true,
42019
42088
  result,
42020
- finalBranchConvergenceState: result.finalBranchConvergenceState
42089
+ finalBranchConvergenceState: result.finalBranchConvergenceState,
42090
+ ...result.blockerContext ? { blockerContext: result.blockerContext } : {}
42021
42091
  } : {}
42022
42092
  }
42023
42093
  });
@@ -42547,6 +42617,27 @@ var DaemonCommandRouter = class {
42547
42617
  finalBranchConvergenceState
42548
42618
  };
42549
42619
  }
42620
+ const requireApprovalForPush = mesh?.policy?.requireApprovalForPush ?? DEFAULT_MESH_POLICY.requireApprovalForPush;
42621
+ let pushResult;
42622
+ if (!requireApprovalForPush) {
42623
+ const pushStarted = Date.now();
42624
+ try {
42625
+ await execFileAsync3("git", ["push", "origin", baseBranch], { cwd: repoRoot, encoding: "utf8" });
42626
+ pushResult = { pushed: true, remote: "origin", branch: baseBranch, durationMs: Date.now() - pushStarted };
42627
+ recordMeshRefineStage(refineStages, "push", "passed", pushStarted, pushResult);
42628
+ finalBranchConvergenceState.status = "merged_pushed";
42629
+ } catch (e) {
42630
+ pushResult = {
42631
+ pushed: false,
42632
+ remote: "origin",
42633
+ branch: baseBranch,
42634
+ error: e?.message || String(e),
42635
+ stderr: e?.stderr,
42636
+ durationMs: Date.now() - pushStarted
42637
+ };
42638
+ recordMeshRefineStage(refineStages, "push", "failed", pushStarted, pushResult);
42639
+ }
42640
+ }
42550
42641
  return {
42551
42642
  success: true,
42552
42643
  merged: true,
@@ -42560,7 +42651,13 @@ var DaemonCommandRouter = class {
42560
42651
  mergeResult,
42561
42652
  refineStages,
42562
42653
  ...ledgerError ? { ledgerError } : {},
42563
- finalBranchConvergenceState
42654
+ finalBranchConvergenceState,
42655
+ // Push outcome or readiness info for coordinator.
42656
+ ...pushResult ? { pushResult } : {
42657
+ pushReady: true,
42658
+ pushCommand: `git push origin ${baseBranch}`,
42659
+ pushNote: "requireApprovalForPush is enabled \u2014 run the push command or obtain user approval before pushing."
42660
+ }
42564
42661
  };
42565
42662
  } catch (e) {
42566
42663
  return { success: false, error: e.message, refineStages };
@@ -42578,9 +42675,46 @@ var DaemonCommandRouter = class {
42578
42675
  const refineCode = typeof result.code === "string" ? result.code : "";
42579
42676
  const refineTerminalKind = result.success === true ? "completed" : refineCode === "blocked_review" ? "blocked_review" : refineCode === "validation_failed" || refineCode === "validation_dependencies_missing" ? "validation_failed" : refineCode === "submodule_reachability_failed" ? "submodule_reachability_failed" : refineCode === "merge_failed" || refineCode === "patch_equivalence_failed" || refineCode === "needs_rebase" || refineCode === "needs_rebase_with_conflicts" ? "merge_failed" : refineCode === "cleanup_failed" ? "cleanup_failed" : "merge_failed";
42580
42677
  const isTerminalSuccess = refineTerminalKind === "completed";
42678
+ const blockerContext = isTerminalSuccess ? void 0 : (() => {
42679
+ const code = typeof result.code === "string" ? result.code : refineTerminalKind;
42680
+ const stage = refineTerminalKind === "validation_failed" ? "validation" : refineTerminalKind === "submodule_reachability_failed" ? "submodule_reachability" : refineCode === "patch_equivalence_failed" ? "patch_equivalence" : refineCode === "needs_rebase" || refineCode === "needs_rebase_with_conflicts" ? "patch_equivalence" : refineTerminalKind === "merge_failed" ? "merge" : refineTerminalKind === "cleanup_failed" ? "cleanup" : "unknown";
42681
+ const ctx = {
42682
+ stage,
42683
+ reason: code,
42684
+ terminalKind: refineTerminalKind
42685
+ };
42686
+ if (typeof result.error === "string") ctx.error = result.error;
42687
+ if (typeof result.blockedReason === "string") ctx.blockedReason = result.blockedReason;
42688
+ if (stage === "patch_equivalence" && result.patchEquivalence) {
42689
+ const pe = result.patchEquivalence;
42690
+ ctx.details = {
42691
+ expectedPatchId: pe.expectedPatchId,
42692
+ actualPatchId: pe.actualPatchId,
42693
+ status: pe.status,
42694
+ actionableHint: pe.actionableHint,
42695
+ error: pe.error
42696
+ };
42697
+ }
42698
+ if (stage === "submodule_reachability" && Array.isArray(result.unreachableSubmoduleCommits)) {
42699
+ ctx.details = {
42700
+ unreachableCount: result.unreachableSubmoduleCommits.length,
42701
+ paths: result.unreachableSubmoduleCommits.map((e) => e.path),
42702
+ autoPublishAllowed: result.unreachableSubmoduleCommits[0]?.autoPublishAllowed
42703
+ };
42704
+ }
42705
+ if (stage === "validation" && result.validationSummary) {
42706
+ const vs = result.validationSummary;
42707
+ ctx.details = {
42708
+ failureCode: vs.failureCode,
42709
+ commandsRun: Array.isArray(vs.commandsRun) ? vs.commandsRun.length : void 0
42710
+ };
42711
+ }
42712
+ return ctx;
42713
+ })();
42581
42714
  const normalizedResult = {
42582
42715
  ...result,
42583
42716
  terminalKind: refineTerminalKind,
42717
+ ...blockerContext ? { blockerContext } : {},
42584
42718
  ...result.nextStep === void 0 && !isTerminalSuccess ? {
42585
42719
  nextStep: refineTerminalKind === "blocked_review" ? "Request user review/approval before attempting to merge again." : refineTerminalKind === "validation_failed" ? "Fix failing tests or configure validation.bootstrapCommands and retry mesh_refine_node." : refineTerminalKind === "submodule_reachability_failed" ? "Push unreachable submodule commits to origin/main, then retry mesh_refine_node." : refineTerminalKind === "merge_failed" ? "Resolve merge conflicts or patch equivalence issues, then retry mesh_refine_node." : refineTerminalKind === "cleanup_failed" ? "Manually remove the worktree and retry or use mesh_remove_node." : "Inspect refineStages for the failing stage and retry."
42586
42720
  } : {}