@adhdev/daemon-standalone 0.9.76-rc.10 → 0.9.76-rc.11

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 CHANGED
@@ -28412,6 +28412,140 @@ var require_dist2 = __commonJS({
28412
28412
  };
28413
28413
  }
28414
28414
  });
28415
+ var git_worktree_exports = {};
28416
+ __export2(git_worktree_exports, {
28417
+ createWorktree: () => createWorktree,
28418
+ listWorktrees: () => listWorktrees,
28419
+ parseWorktreeListOutput: () => parseWorktreeListOutput,
28420
+ removeWorktree: () => removeWorktree,
28421
+ resolveWorktreePath: () => resolveWorktreePath
28422
+ });
28423
+ function resolveWorktreePath(repoRoot, meshName, branch) {
28424
+ const safeBranch = branch.replace(/[/\\:*?"<>|]/g, "-").replace(/^\.+|\.+$/g, "");
28425
+ const safeMeshName = meshName.replace(/[/\\:*?"<>|]/g, "-").replace(/^\.+|\.+$/g, "");
28426
+ const parentDir = path42.dirname(repoRoot);
28427
+ return path42.join(parentDir, WORKTREE_DIR_NAME, safeMeshName, safeBranch);
28428
+ }
28429
+ async function createWorktree(opts) {
28430
+ const { repoRoot, branch, baseBranch, meshName } = opts;
28431
+ const targetDir = opts.targetDir || resolveWorktreePath(repoRoot, meshName, branch);
28432
+ if ((0, import_node_fs2.existsSync)(targetDir)) {
28433
+ throw new Error(`Worktree target directory already exists: ${targetDir}`);
28434
+ }
28435
+ await (0, import_promises3.mkdir)(path42.dirname(targetDir), { recursive: true });
28436
+ const args = ["worktree", "add", targetDir, "-b", branch];
28437
+ if (baseBranch) {
28438
+ args.push(baseBranch);
28439
+ }
28440
+ try {
28441
+ await execFileAsync2("git", args, {
28442
+ cwd: repoRoot,
28443
+ encoding: "utf8",
28444
+ timeout: GIT_TIMEOUT_MS,
28445
+ maxBuffer: GIT_MAX_BUFFER,
28446
+ windowsHide: true
28447
+ });
28448
+ } catch (error48) {
28449
+ const stderr = typeof error48.stderr === "string" ? error48.stderr : "";
28450
+ if (/already exists/i.test(stderr)) {
28451
+ throw new Error(`Branch '${branch}' already exists or is checked out in another worktree`);
28452
+ }
28453
+ throw new Error(`git worktree add failed: ${stderr.trim() || error48.message}`);
28454
+ }
28455
+ return {
28456
+ success: true,
28457
+ worktreePath: targetDir,
28458
+ branch
28459
+ };
28460
+ }
28461
+ async function removeWorktree(repoRoot, worktreePath) {
28462
+ if (!(0, import_node_fs2.existsSync)(worktreePath)) {
28463
+ await pruneWorktrees(repoRoot);
28464
+ return { success: true, removedPath: worktreePath };
28465
+ }
28466
+ try {
28467
+ await execFileAsync2("git", ["worktree", "remove", worktreePath, "--force"], {
28468
+ cwd: repoRoot,
28469
+ encoding: "utf8",
28470
+ timeout: GIT_TIMEOUT_MS,
28471
+ maxBuffer: GIT_MAX_BUFFER,
28472
+ windowsHide: true
28473
+ });
28474
+ } catch (error48) {
28475
+ const stderr = typeof error48.stderr === "string" ? error48.stderr : "";
28476
+ throw new Error(`git worktree remove failed: ${stderr.trim() || error48.message}`);
28477
+ }
28478
+ return { success: true, removedPath: worktreePath };
28479
+ }
28480
+ async function listWorktrees(repoRoot) {
28481
+ const { stdout } = await execFileAsync2("git", ["worktree", "list", "--porcelain"], {
28482
+ cwd: repoRoot,
28483
+ encoding: "utf8",
28484
+ timeout: GIT_TIMEOUT_MS,
28485
+ maxBuffer: GIT_MAX_BUFFER,
28486
+ windowsHide: true
28487
+ });
28488
+ return parseWorktreeListOutput(stdout);
28489
+ }
28490
+ function parseWorktreeListOutput(output) {
28491
+ const entries = [];
28492
+ const blocks = output.trim().split(/\n\n+/);
28493
+ for (const block of blocks) {
28494
+ if (!block.trim()) continue;
28495
+ const lines = block.trim().split("\n");
28496
+ const entry = { path: "", head: "", branch: null, bare: false };
28497
+ for (const line of lines) {
28498
+ if (line.startsWith("worktree ")) {
28499
+ entry.path = line.slice("worktree ".length).trim();
28500
+ } else if (line.startsWith("HEAD ")) {
28501
+ entry.head = line.slice("HEAD ".length).trim();
28502
+ } else if (line.startsWith("branch ")) {
28503
+ const ref = line.slice("branch ".length).trim();
28504
+ entry.branch = ref.replace(/^refs\/heads\//, "");
28505
+ } else if (line === "bare") {
28506
+ entry.bare = true;
28507
+ }
28508
+ }
28509
+ if (entry.path) {
28510
+ entries.push(entry);
28511
+ }
28512
+ }
28513
+ return entries;
28514
+ }
28515
+ async function pruneWorktrees(repoRoot) {
28516
+ try {
28517
+ await execFileAsync2("git", ["worktree", "prune"], {
28518
+ cwd: repoRoot,
28519
+ encoding: "utf8",
28520
+ timeout: GIT_TIMEOUT_MS,
28521
+ windowsHide: true
28522
+ });
28523
+ } catch {
28524
+ }
28525
+ }
28526
+ var path42;
28527
+ var import_promises3;
28528
+ var import_node_fs2;
28529
+ var import_node_child_process2;
28530
+ var import_node_util2;
28531
+ var execFileAsync2;
28532
+ var WORKTREE_DIR_NAME;
28533
+ var GIT_TIMEOUT_MS;
28534
+ var GIT_MAX_BUFFER;
28535
+ var init_git_worktree = __esm2({
28536
+ "src/git/git-worktree.ts"() {
28537
+ "use strict";
28538
+ path42 = __toESM2(require("path"));
28539
+ import_promises3 = require("fs/promises");
28540
+ import_node_fs2 = require("fs");
28541
+ import_node_child_process2 = require("child_process");
28542
+ import_node_util2 = require("util");
28543
+ execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process2.execFile);
28544
+ WORKTREE_DIR_NAME = ".adhdev-worktrees";
28545
+ GIT_TIMEOUT_MS = 3e4;
28546
+ GIT_MAX_BUFFER = 4 * 1024 * 1024;
28547
+ }
28548
+ });
28415
28549
  var config_exports = {};
28416
28550
  __export2(config_exports, {
28417
28551
  generateMachineId: () => generateMachineId,
@@ -28672,10 +28806,10 @@ var require_dist2 = __commonJS({
28672
28806
  return (0, import_path22.join)(getConfigDir(), "meshes.json");
28673
28807
  }
28674
28808
  function loadMeshConfig() {
28675
- const path26 = getMeshConfigPath();
28676
- if (!(0, import_fs2.existsSync)(path26)) return { meshes: [] };
28809
+ const path27 = getMeshConfigPath();
28810
+ if (!(0, import_fs2.existsSync)(path27)) return { meshes: [] };
28677
28811
  try {
28678
- const raw = JSON.parse((0, import_fs2.readFileSync)(path26, "utf-8"));
28812
+ const raw = JSON.parse((0, import_fs2.readFileSync)(path27, "utf-8"));
28679
28813
  if (!raw || !Array.isArray(raw.meshes)) return { meshes: [] };
28680
28814
  return raw;
28681
28815
  } catch {
@@ -28683,16 +28817,16 @@ var require_dist2 = __commonJS({
28683
28817
  }
28684
28818
  }
28685
28819
  function saveMeshConfig(config2) {
28686
- const path26 = getMeshConfigPath();
28687
- (0, import_fs2.writeFileSync)(path26, JSON.stringify(config2, null, 2), { encoding: "utf-8", mode: 384 });
28820
+ const path27 = getMeshConfigPath();
28821
+ (0, import_fs2.writeFileSync)(path27, JSON.stringify(config2, null, 2), { encoding: "utf-8", mode: 384 });
28688
28822
  }
28689
28823
  function normalizeRepoIdentity(remoteUrl) {
28690
28824
  let identity = remoteUrl.trim();
28691
28825
  if (identity.startsWith("http://") || identity.startsWith("https://")) {
28692
28826
  try {
28693
28827
  const url2 = new URL(identity);
28694
- const path26 = url2.pathname.replace(/^\//, "").replace(/\.git$/, "");
28695
- return `${url2.hostname}/${path26}`;
28828
+ const path27 = url2.pathname.replace(/^\//, "").replace(/\.git$/, "");
28829
+ return `${url2.hostname}/${path27}`;
28696
28830
  } catch {
28697
28831
  }
28698
28832
  }
@@ -28767,9 +28901,12 @@ var require_dist2 = __commonJS({
28767
28901
  id: `node_${(0, import_crypto32.randomUUID)().replace(/-/g, "")}`,
28768
28902
  workspace: opts.workspace.trim(),
28769
28903
  repoRoot: opts.repoRoot,
28904
+ daemonId: opts.daemonId,
28770
28905
  userOverrides: opts.userOverrides || {},
28771
28906
  policy: opts.policy || {},
28772
- isLocalWorktree: opts.isLocalWorktree
28907
+ isLocalWorktree: opts.isLocalWorktree,
28908
+ worktreeBranch: opts.worktreeBranch,
28909
+ clonedFromNodeId: opts.clonedFromNodeId
28773
28910
  };
28774
28911
  mesh.nodes.push(node);
28775
28912
  mesh.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
@@ -28817,7 +28954,7 @@ var require_dist2 = __commonJS({
28817
28954
  buildCoordinatorSystemPrompt: () => buildCoordinatorSystemPrompt
28818
28955
  });
28819
28956
  function buildCoordinatorSystemPrompt(ctx) {
28820
- const { mesh, status, userInstruction } = ctx;
28957
+ const { mesh, status, userInstruction, coordinatorCliType } = ctx;
28821
28958
  const sections = [];
28822
28959
  sections.push(`You are a **Repo Mesh Coordinator** \u2014 a technical team lead who orchestrates work across multiple agent sessions on a shared Git repository.
28823
28960
 
@@ -28831,15 +28968,15 @@ Default branch: \`${mesh.defaultBranch}\`` : ""}`);
28831
28968
  } else {
28832
28969
  sections.push("## Nodes\nNo nodes configured yet. Ask the user to add nodes with `adhdev mesh add-node`.");
28833
28970
  }
28834
- sections.push(buildPolicySection(mesh.policy));
28971
+ sections.push(buildPolicySection({ ...DEFAULT_MESH_POLICY, ...mesh.policy || {} }));
28835
28972
  sections.push(TOOLS_SECTION);
28836
28973
  sections.push(WORKFLOW_SECTION);
28837
- sections.push(RULES_SECTION);
28974
+ sections.push(buildRulesSection(coordinatorCliType));
28838
28975
  if (userInstruction) {
28839
28976
  sections.push(`## Additional Context
28840
28977
  ${userInstruction}`);
28841
28978
  }
28842
- if (mesh.coordinator.systemPromptSuffix) {
28979
+ if (mesh.coordinator?.systemPromptSuffix) {
28843
28980
  sections.push(mesh.coordinator.systemPromptSuffix);
28844
28981
  }
28845
28982
  return sections.join("\n\n");
@@ -28883,13 +29020,31 @@ ${userInstruction}`);
28883
29020
  rules.push(`- Maximum **${policy.maxParallelTasks}** tasks running in parallel`);
28884
29021
  return `## Policy
28885
29022
  ${rules.join("\n")}`;
29023
+ }
29024
+ function buildRulesSection(coordinatorCliType) {
29025
+ const coordinatorNote = coordinatorCliType ? `
29026
+ - **Coordinator runtime is not a delegation default.** This coordinator is running as \`${coordinatorCliType}\`, but delegated node sessions must follow the user's requested provider, not the coordinator's own runtime.` : "";
29027
+ return `## Rules
29028
+
29029
+ - **Minimize coordinator context.** The coordinator's job is routing, not implementing. Do not read source files, run commands, or analyze code directly \u2014 delegate all of that to node agents. Your context should stay lean.
29030
+ - **Delegate analysis too.** If you need to understand a bug or explore the codebase, send that investigation as a task to a node. Do not do it yourself.
29031
+ - **Respect explicit provider requests.** If the user names an agent/provider, pass the matching provider type to \`mesh_launch_session\`: Hermes \u2192 \`hermes-cli\`, Claude Code/Claude \u2192 \`claude-cli\`, Codex \u2192 \`codex-cli\`, Gemini \u2192 \`gemini-cli\`. Never substitute \`claude-cli\` just because the coordinator itself is Claude Code.
29032
+ - **Front-load the task message.** When calling \`mesh_send_task\`, include everything the agent needs: what files to touch, what the problem is, what the fix should look like. The agent won't ask follow-up questions.
29033
+ - **Don't inspect code.** Trust the agent's output. Verify via \`mesh_git_status\`, not by reading source files.
29034
+ - **Don't over-parallelize.** Start with 1-2 concurrent tasks. Scale up if they succeed.
29035
+ - **Handle failures gracefully.** If a task fails, read the chat to understand why, then retry or reassign.
29036
+ - **Keep the user informed.** Report progress after each delegation round \u2014 one or two sentences, not a narration.
29037
+ - **Respect node capabilities.** Don't send build tasks to read-only nodes. Don't push from nodes that aren't allowed to.
29038
+ - **Never fabricate tool results.** Always call the actual tool; never pretend you did.
29039
+ - **Clean up worktree nodes.** After a worktree task completes and its changes are merged or checkpointed, call \`mesh_remove_node\` to free resources.
29040
+ - **Name worktree branches meaningfully.** Use descriptive names like \`feat/auth-refactor\` or \`fix/build-123\`.${coordinatorNote}`;
28886
29041
  }
28887
29042
  var TOOLS_SECTION;
28888
29043
  var WORKFLOW_SECTION;
28889
- var RULES_SECTION;
28890
29044
  var init_coordinator_prompt = __esm2({
28891
29045
  "src/mesh/coordinator-prompt.ts"() {
28892
29046
  "use strict";
29047
+ init_repo_mesh_types();
28893
29048
  TOOLS_SECTION = `## Available Tools
28894
29049
 
28895
29050
  | Tool | Purpose |
@@ -28901,30 +29056,23 @@ ${rules.join("\n")}`;
28901
29056
  | \`mesh_read_chat\` | Read an agent's recent messages to check progress |
28902
29057
  | \`mesh_git_status\` | Check git status on a specific node |
28903
29058
  | \`mesh_checkpoint\` | Create a git checkpoint on a node |
28904
- | \`mesh_approve\` | Approve/reject a pending agent action |`;
29059
+ | \`mesh_approve\` | Approve/reject a pending agent action |
29060
+ | \`mesh_clone_node\` | Create a worktree node for isolated parallel branch work |
29061
+ | \`mesh_remove_node\` | Remove a node (cleans up worktree if applicable) |`;
28905
29062
  WORKFLOW_SECTION = `## Orchestration Workflow
28906
29063
 
28907
29064
  1. **Assess** \u2014 Call \`mesh_status\` to see which nodes are healthy and available.
28908
29065
  2. **Plan** \u2014 Decompose the user's request into independent tasks for parallel execution, or sequential tasks when dependencies exist.
28909
29066
  3. **Delegate** \u2014 For each task:
28910
29067
  a. Pick the best node (consider: health, dirty state, current workload).
28911
- b. If no session exists, call \`mesh_launch_session\` to start one.
28912
- c. Call \`mesh_send_task\` with a **complete, self-contained** instruction that includes all context the agent needs (file paths, line numbers, what to change, why). Do not send partial instructions expecting future follow-up.
29068
+ b. If you need branch isolation for parallel work, call \`mesh_clone_node\` to create a worktree node first.
29069
+ c. If no session exists, call \`mesh_launch_session\` to start one.
29070
+ d. Call \`mesh_send_task\` with a **complete, self-contained** instruction that includes all context the agent needs (file paths, line numbers, what to change, why). Do not send partial instructions expecting future follow-up.
28913
29071
  4. **Monitor** \u2014 Periodically call \`mesh_read_chat\` to check progress. Handle approvals via \`mesh_approve\`.
28914
29072
  5. **Verify** \u2014 When a task reports completion, call \`mesh_git_status\` to verify changes were made.
28915
29073
  6. **Checkpoint** \u2014 Call \`mesh_checkpoint\` to save the work.
28916
- 7. **Report** \u2014 Summarize what was done, what changed, and any issues.`;
28917
- RULES_SECTION = `## Rules
28918
-
28919
- - **Minimize coordinator context.** The coordinator's job is routing, not implementing. Do not read source files, run commands, or analyze code directly \u2014 delegate all of that to node agents. Your context should stay lean.
28920
- - **Delegate analysis too.** If you need to understand a bug or explore the codebase, send that investigation as a task to a node. Do not do it yourself.
28921
- - **Front-load the task message.** When calling \`mesh_send_task\`, include everything the agent needs: what files to touch, what the problem is, what the fix should look like. The agent won't ask follow-up questions.
28922
- - **Don't inspect code.** Trust the agent's output. Verify via \`mesh_git_status\`, not by reading source files.
28923
- - **Don't over-parallelize.** Start with 1-2 concurrent tasks. Scale up if they succeed.
28924
- - **Handle failures gracefully.** If a task fails, read the chat to understand why, then retry or reassign.
28925
- - **Keep the user informed.** Report progress after each delegation round \u2014 one or two sentences, not a narration.
28926
- - **Respect node capabilities.** Don't send build tasks to read-only nodes. Don't push from nodes that aren't allowed to.
28927
- - **Never fabricate tool results.** Always call the actual tool; never pretend you did.`;
29074
+ 7. **Clean up** \u2014 Remove worktree nodes via \`mesh_remove_node\` after their work is merged or no longer needed.
29075
+ 8. **Report** \u2014 Summarize what was done, what changed, and any issues.`;
28928
29076
  }
28929
29077
  });
28930
29078
  function setLogLevel(level) {
@@ -28941,13 +29089,13 @@ ${rules.join("\n")}`;
28941
29089
  return LOG_DIR;
28942
29090
  }
28943
29091
  function getCurrentDaemonLogPath(date5 = /* @__PURE__ */ new Date()) {
28944
- return path9.join(LOG_DIR, `daemon-${date5.toISOString().slice(0, 10)}.log`);
29092
+ return path10.join(LOG_DIR, `daemon-${date5.toISOString().slice(0, 10)}.log`);
28945
29093
  }
28946
29094
  function checkDateRotation() {
28947
29095
  const today = getDateStr();
28948
29096
  if (today !== currentDate) {
28949
29097
  currentDate = today;
28950
- currentLogFile = path9.join(LOG_DIR, `daemon-${currentDate}.log`);
29098
+ currentLogFile = path10.join(LOG_DIR, `daemon-${currentDate}.log`);
28951
29099
  cleanOldLogs();
28952
29100
  }
28953
29101
  }
@@ -28961,7 +29109,7 @@ ${rules.join("\n")}`;
28961
29109
  const dateMatch = file2.match(/daemon-(\d{4}-\d{2}-\d{2})/);
28962
29110
  if (dateMatch && dateMatch[1] < cutoffStr) {
28963
29111
  try {
28964
- fs22.unlinkSync(path9.join(LOG_DIR, file2));
29112
+ fs22.unlinkSync(path10.join(LOG_DIR, file2));
28965
29113
  } catch {
28966
29114
  }
28967
29115
  }
@@ -29078,7 +29226,7 @@ ${rules.join("\n")}`;
29078
29226
  writeToFile(`Log level: ${currentLevel}`);
29079
29227
  }
29080
29228
  var fs22;
29081
- var path9;
29229
+ var path10;
29082
29230
  var os42;
29083
29231
  var LEVEL_NUM;
29084
29232
  var LEVEL_LABEL;
@@ -29101,12 +29249,12 @@ ${rules.join("\n")}`;
29101
29249
  "src/logging/logger.ts"() {
29102
29250
  "use strict";
29103
29251
  fs22 = __toESM2(require("fs"));
29104
- path9 = __toESM2(require("path"));
29252
+ path10 = __toESM2(require("path"));
29105
29253
  os42 = __toESM2(require("os"));
29106
29254
  LEVEL_NUM = { debug: 0, info: 1, warn: 2, error: 3 };
29107
29255
  LEVEL_LABEL = { debug: "DBG", info: "INF", warn: "WRN", error: "ERR" };
29108
29256
  currentLevel = "info";
29109
- LOG_DIR = process.platform === "win32" ? path9.join(process.env.LOCALAPPDATA || process.env.APPDATA || path9.join(os42.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path9.join(os42.homedir(), "Library", "Logs", "adhdev") : path9.join(os42.homedir(), ".local", "share", "adhdev", "logs");
29257
+ LOG_DIR = process.platform === "win32" ? path10.join(process.env.LOCALAPPDATA || process.env.APPDATA || path10.join(os42.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path10.join(os42.homedir(), "Library", "Logs", "adhdev") : path10.join(os42.homedir(), ".local", "share", "adhdev", "logs");
29110
29258
  MAX_LOG_SIZE = 5 * 1024 * 1024;
29111
29259
  MAX_LOG_DAYS = 7;
29112
29260
  try {
@@ -29114,16 +29262,16 @@ ${rules.join("\n")}`;
29114
29262
  } catch {
29115
29263
  }
29116
29264
  currentDate = getDateStr();
29117
- currentLogFile = path9.join(LOG_DIR, `daemon-${currentDate}.log`);
29265
+ currentLogFile = path10.join(LOG_DIR, `daemon-${currentDate}.log`);
29118
29266
  cleanOldLogs();
29119
29267
  try {
29120
- const oldLog = path9.join(LOG_DIR, "daemon.log");
29268
+ const oldLog = path10.join(LOG_DIR, "daemon.log");
29121
29269
  if (fs22.existsSync(oldLog)) {
29122
29270
  const stat2 = fs22.statSync(oldLog);
29123
29271
  const oldDate = stat2.mtime.toISOString().slice(0, 10);
29124
- fs22.renameSync(oldLog, path9.join(LOG_DIR, `daemon-${oldDate}.log`));
29272
+ fs22.renameSync(oldLog, path10.join(LOG_DIR, `daemon-${oldDate}.log`));
29125
29273
  }
29126
- const oldLogBackup = path9.join(LOG_DIR, "daemon.log.old");
29274
+ const oldLogBackup = path10.join(LOG_DIR, "daemon.log.old");
29127
29275
  if (fs22.existsSync(oldLogBackup)) {
29128
29276
  fs22.unlinkSync(oldLogBackup);
29129
29277
  }
@@ -29155,7 +29303,7 @@ ${rules.join("\n")}`;
29155
29303
  }
29156
29304
  };
29157
29305
  interceptorInstalled = false;
29158
- LOG_PATH = path9.join(LOG_DIR, `daemon-${getDateStr()}.log`);
29306
+ LOG_PATH = path10.join(LOG_DIR, `daemon-${getDateStr()}.log`);
29159
29307
  }
29160
29308
  });
29161
29309
  function normalizeCategories(categories) {
@@ -29621,9 +29769,9 @@ ${rules.join("\n")}`;
29621
29769
  function findBinary(name) {
29622
29770
  const trimmed = String(name || "").trim();
29623
29771
  if (!trimmed) return trimmed;
29624
- const expanded = trimmed.startsWith("~") ? path13.join(os9.homedir(), trimmed.slice(1)) : trimmed;
29625
- if (path13.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
29626
- return path13.isAbsolute(expanded) ? expanded : path13.resolve(expanded);
29772
+ const expanded = trimmed.startsWith("~") ? path14.join(os9.homedir(), trimmed.slice(1)) : trimmed;
29773
+ if (path14.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
29774
+ return path14.isAbsolute(expanded) ? expanded : path14.resolve(expanded);
29627
29775
  }
29628
29776
  const isWin = os9.platform() === "win32";
29629
29777
  try {
@@ -29639,7 +29787,7 @@ ${rules.join("\n")}`;
29639
29787
  }
29640
29788
  }
29641
29789
  function isScriptBinary(binaryPath) {
29642
- if (!path13.isAbsolute(binaryPath)) return false;
29790
+ if (!path14.isAbsolute(binaryPath)) return false;
29643
29791
  try {
29644
29792
  const fs16 = require("fs");
29645
29793
  const resolved = fs16.realpathSync(binaryPath);
@@ -29655,7 +29803,7 @@ ${rules.join("\n")}`;
29655
29803
  }
29656
29804
  }
29657
29805
  function looksLikeMachOOrElf(filePath) {
29658
- if (!path13.isAbsolute(filePath)) return false;
29806
+ if (!path14.isAbsolute(filePath)) return false;
29659
29807
  try {
29660
29808
  const fs16 = require("fs");
29661
29809
  const resolved = fs16.realpathSync(filePath);
@@ -29745,14 +29893,14 @@ ${rules.join("\n")}`;
29745
29893
  };
29746
29894
  }
29747
29895
  var os9;
29748
- var path13;
29896
+ var path14;
29749
29897
  var import_child_process4;
29750
29898
  var buildCliSpawnEnv;
29751
29899
  var init_provider_cli_shared = __esm2({
29752
29900
  "src/cli-adapters/provider-cli-shared.ts"() {
29753
29901
  "use strict";
29754
29902
  os9 = __toESM2(require("os"));
29755
- path13 = __toESM2(require("path"));
29903
+ path14 = __toESM2(require("path"));
29756
29904
  import_child_process4 = require("child_process");
29757
29905
  init_spawn_env();
29758
29906
  buildCliSpawnEnv = import_session_host_core3.sanitizeSpawnEnv;
@@ -29877,9 +30025,9 @@ ${rules.join("\n")}`;
29877
30025
  const allArgs = [...spawnConfig.args, ...extraArgs];
29878
30026
  let shellCmd;
29879
30027
  let shellArgs;
29880
- const useShellUnix = !isWin && (!!spawnConfig.shell || !path14.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
30028
+ const useShellUnix = !isWin && (!!spawnConfig.shell || !path15.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
29881
30029
  const isCmdShim = isWin && /\.(cmd|bat)$/i.test(binaryPath);
29882
- const useShellWin = !!spawnConfig.shell || isCmdShim || !path14.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
30030
+ const useShellWin = !!spawnConfig.shell || isCmdShim || !path15.isAbsolute(binaryPath) || isScriptBinary(binaryPath);
29883
30031
  const useShell = isWin ? useShellWin : useShellUnix;
29884
30032
  if (useShell) {
29885
30033
  shellCmd = isWin ? "cmd.exe" : process.env.SHELL || "/bin/zsh";
@@ -29956,13 +30104,13 @@ ${rules.join("\n")}`;
29956
30104
  return "";
29957
30105
  }
29958
30106
  var os10;
29959
- var path14;
30107
+ var path15;
29960
30108
  var import_session_host_core22;
29961
30109
  var init_provider_cli_runtime = __esm2({
29962
30110
  "src/cli-adapters/provider-cli-runtime.ts"() {
29963
30111
  "use strict";
29964
30112
  os10 = __toESM2(require("os"));
29965
- path14 = __toESM2(require("path"));
30113
+ path15 = __toESM2(require("path"));
29966
30114
  import_session_host_core22 = require_dist();
29967
30115
  init_provider_cli_shared();
29968
30116
  }
@@ -32109,6 +32257,7 @@ ${lastSnapshot}`;
32109
32257
  createGitWorkspaceMonitor: () => createGitWorkspaceMonitor2,
32110
32258
  createInteractionId: () => createInteractionId,
32111
32259
  createMesh: () => createMesh,
32260
+ createWorktree: () => createWorktree,
32112
32261
  deleteMesh: () => deleteMesh,
32113
32262
  detectAllVersions: () => detectAllVersions,
32114
32263
  detectCLIs: () => detectCLIs,
@@ -32161,6 +32310,7 @@ ${lastSnapshot}`;
32161
32310
  launchWithCdp: () => launchWithCdp,
32162
32311
  listHostedCliRuntimes: () => listHostedCliRuntimes2,
32163
32312
  listMeshes: () => listMeshes,
32313
+ listWorktrees: () => listWorktrees,
32164
32314
  loadConfig: () => loadConfig2,
32165
32315
  loadState: () => loadState,
32166
32316
  logCommand: () => logCommand,
@@ -32180,6 +32330,7 @@ ${lastSnapshot}`;
32180
32330
  normalizeSessionModalFields: () => normalizeSessionModalFields,
32181
32331
  parsePorcelainV2Status: () => parsePorcelainV2Status,
32182
32332
  parseProviderSourceConfigUpdate: () => parseProviderSourceConfigUpdate,
32333
+ parseWorktreeListOutput: () => parseWorktreeListOutput,
32183
32334
  partitionSessionHostDiagnosticsSessions: () => partitionSessionHostDiagnosticsSessions,
32184
32335
  partitionSessionHostRecords: () => partitionSessionHostRecords,
32185
32336
  prepareSessionChatTailUpdate: () => prepareSessionChatTailUpdate2,
@@ -32189,6 +32340,7 @@ ${lastSnapshot}`;
32189
32340
  recordDebugTrace: () => recordDebugTrace,
32190
32341
  registerExtensionProviders: () => registerExtensionProviders,
32191
32342
  removeNode: () => removeNode,
32343
+ removeWorktree: () => removeWorktree,
32192
32344
  resetConfig: () => resetConfig,
32193
32345
  resetDebugRuntimeConfig: () => resetDebugRuntimeConfig,
32194
32346
  resetState: () => resetState,
@@ -32198,6 +32350,7 @@ ${lastSnapshot}`;
32198
32350
  resolveGitRepository: () => resolveGitRepository,
32199
32351
  resolveSessionHostAppName: () => resolveSessionHostAppName,
32200
32352
  resolveSessionHostAppNameResolution: () => resolveSessionHostAppNameResolution2,
32353
+ resolveWorktreePath: () => resolveWorktreePath,
32201
32354
  runAsyncBatch: () => runAsyncBatch2,
32202
32355
  runGit: () => runGit,
32203
32356
  saveConfig: () => saveConfig,
@@ -33540,17 +33693,18 @@ ${lastSnapshot}`;
33540
33693
  this.lastStatus.delete(sessionId);
33541
33694
  }
33542
33695
  };
33696
+ init_git_worktree();
33543
33697
  init_config();
33544
33698
  var fs5 = __toESM2(require("fs"));
33545
33699
  var os7 = __toESM2(require("os"));
33546
- var path42 = __toESM2(require("path"));
33700
+ var path52 = __toESM2(require("path"));
33547
33701
  var import_crypto22 = require("crypto");
33548
33702
  var MAX_WORKSPACES = 50;
33549
33703
  function expandPath(p) {
33550
33704
  const t = (p || "").trim();
33551
33705
  if (!t) return "";
33552
- if (t.startsWith("~")) return path42.join(os7.homedir(), t.slice(1).replace(/^\//, ""));
33553
- return path42.resolve(t);
33706
+ if (t.startsWith("~")) return path52.join(os7.homedir(), t.slice(1).replace(/^\//, ""));
33707
+ return path52.resolve(t);
33554
33708
  }
33555
33709
  function validateWorkspacePath(absPath) {
33556
33710
  try {
@@ -33564,7 +33718,7 @@ ${lastSnapshot}`;
33564
33718
  }
33565
33719
  }
33566
33720
  function defaultWorkspaceLabel(absPath) {
33567
- const base = path42.basename(absPath) || absPath;
33721
+ const base = path52.basename(absPath) || absPath;
33568
33722
  return base;
33569
33723
  }
33570
33724
  function getDefaultWorkspacePath(config2) {
@@ -33655,9 +33809,9 @@ ${lastSnapshot}`;
33655
33809
  return getDefaultWorkspacePath(config2) || void 0;
33656
33810
  }
33657
33811
  function findWorkspaceByPath(config2, rawPath) {
33658
- const abs = path42.resolve(expandPath(rawPath));
33812
+ const abs = path52.resolve(expandPath(rawPath));
33659
33813
  if (!abs) return void 0;
33660
- return (config2.workspaces || []).find((w) => path42.resolve(expandPath(w.path)) === abs);
33814
+ return (config2.workspaces || []).find((w) => path52.resolve(expandPath(w.path)) === abs);
33661
33815
  }
33662
33816
  function addWorkspaceEntry(config2, rawPath, label, options) {
33663
33817
  const abs = expandPath(rawPath);
@@ -33673,7 +33827,7 @@ ${lastSnapshot}`;
33673
33827
  const v2 = validateWorkspacePath(abs);
33674
33828
  if (!v2.ok) return { error: v2.error };
33675
33829
  const list = [...config2.workspaces || []];
33676
- if (list.some((w) => path42.resolve(w.path) === abs)) {
33830
+ if (list.some((w) => path52.resolve(w.path) === abs)) {
33677
33831
  return { error: "Workspace already in list" };
33678
33832
  }
33679
33833
  if (list.length >= MAX_WORKSPACES) {
@@ -33705,7 +33859,7 @@ ${lastSnapshot}`;
33705
33859
  if (validateWorkspacePath(abs).ok !== true) return { error: "Workspace path is no longer valid" };
33706
33860
  return { config: { ...config2, defaultWorkspaceId: id } };
33707
33861
  }
33708
- var path52 = __toESM2(require("path"));
33862
+ var path6 = __toESM2(require("path"));
33709
33863
  function normalizeSummaryItem(item) {
33710
33864
  if (!item || typeof item !== "object") return null;
33711
33865
  const id = String(item.id || "").trim();
@@ -33770,9 +33924,9 @@ ${lastSnapshot}`;
33770
33924
  function normalizeWorkspace(workspace) {
33771
33925
  if (!workspace) return "";
33772
33926
  try {
33773
- return path52.resolve(expandPath(workspace));
33927
+ return path6.resolve(expandPath(workspace));
33774
33928
  } catch {
33775
- return path52.resolve(workspace);
33929
+ return path6.resolve(workspace);
33776
33930
  }
33777
33931
  }
33778
33932
  function buildRecentActivityKey(entry) {
@@ -33938,14 +34092,14 @@ ${lastSnapshot}`;
33938
34092
  sessionNotificationUnreadOverrides: nextSessionNotificationUnreadOverrides
33939
34093
  };
33940
34094
  }
33941
- var path6 = __toESM2(require("path"));
34095
+ var path7 = __toESM2(require("path"));
33942
34096
  var MAX_SAVED_SESSIONS = 500;
33943
34097
  function normalizeWorkspace2(workspace) {
33944
34098
  if (!workspace) return "";
33945
34099
  try {
33946
- return path6.resolve(expandPath(workspace));
34100
+ return path7.resolve(expandPath(workspace));
33947
34101
  } catch {
33948
- return path6.resolve(workspace);
34102
+ return path7.resolve(workspace);
33949
34103
  }
33950
34104
  }
33951
34105
  function buildSavedProviderSessionKey(providerSessionId) {
@@ -34116,7 +34270,7 @@ ${lastSnapshot}`;
34116
34270
  var import_child_process = require("child_process");
34117
34271
  var import_fs4 = require("fs");
34118
34272
  var import_os22 = require("os");
34119
- var path7 = __toESM2(require("path"));
34273
+ var path8 = __toESM2(require("path"));
34120
34274
  var BUILTIN_IDE_DEFINITIONS = [];
34121
34275
  var registeredIDEs = /* @__PURE__ */ new Map();
34122
34276
  function registerIDEDefinition(def) {
@@ -34135,9 +34289,9 @@ ${lastSnapshot}`;
34135
34289
  function findCliCommand(command) {
34136
34290
  const trimmed = String(command || "").trim();
34137
34291
  if (!trimmed) return null;
34138
- if (path7.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~")) {
34139
- const candidate = trimmed.startsWith("~") ? path7.join((0, import_os22.homedir)(), trimmed.slice(1)) : trimmed;
34140
- const resolved = path7.isAbsolute(candidate) ? candidate : path7.resolve(candidate);
34292
+ if (path8.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~")) {
34293
+ const candidate = trimmed.startsWith("~") ? path8.join((0, import_os22.homedir)(), trimmed.slice(1)) : trimmed;
34294
+ const resolved = path8.isAbsolute(candidate) ? candidate : path8.resolve(candidate);
34141
34295
  return (0, import_fs4.existsSync)(resolved) ? resolved : null;
34142
34296
  }
34143
34297
  try {
@@ -34165,7 +34319,7 @@ ${lastSnapshot}`;
34165
34319
  function checkPathExists(paths) {
34166
34320
  const home = (0, import_os22.homedir)();
34167
34321
  for (const p of paths) {
34168
- const normalized = p.startsWith("~") ? path7.join(home, p.slice(1)) : p;
34322
+ const normalized = p.startsWith("~") ? path8.join(home, p.slice(1)) : p;
34169
34323
  if (normalized.includes("*")) {
34170
34324
  const username = home.split(/[\\/]/).pop() || "";
34171
34325
  const resolved = normalized.replace("*", username);
@@ -34188,8 +34342,8 @@ ${lastSnapshot}`;
34188
34342
  if ((0, import_fs4.existsSync)(bundledCli)) resolvedCli = bundledCli;
34189
34343
  }
34190
34344
  if (!resolvedCli && appPath && os21 === "win32") {
34191
- const { dirname: dirname8 } = await import("path");
34192
- const appDir = dirname8(appPath);
34345
+ const { dirname: dirname9 } = await import("path");
34346
+ const appDir = dirname9(appPath);
34193
34347
  const candidates = [
34194
34348
  `${appDir}\\\\bin\\\\${def.cli}.cmd`,
34195
34349
  `${appDir}\\\\bin\\\\${def.cli}`,
@@ -34221,7 +34375,7 @@ ${lastSnapshot}`;
34221
34375
  }
34222
34376
  var import_child_process2 = require("child_process");
34223
34377
  var os22 = __toESM2(require("os"));
34224
- var path8 = __toESM2(require("path"));
34378
+ var path9 = __toESM2(require("path"));
34225
34379
  var import_fs5 = require("fs");
34226
34380
  function parseVersion(raw) {
34227
34381
  const match = raw.match(/v?(\d+\.\d+(?:\.\d+)?(?:-[a-zA-Z0-9.]+)?)/);
@@ -34234,18 +34388,18 @@ ${lastSnapshot}`;
34234
34388
  function expandHome(value) {
34235
34389
  const trimmed = value.trim();
34236
34390
  if (!trimmed.startsWith("~")) return trimmed;
34237
- return path8.join(os22.homedir(), trimmed.slice(1));
34391
+ return path9.join(os22.homedir(), trimmed.slice(1));
34238
34392
  }
34239
34393
  function isExplicitCommandPath(command) {
34240
34394
  const trimmed = command.trim();
34241
- return path8.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
34395
+ return path9.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
34242
34396
  }
34243
34397
  function resolveCommandPath(command) {
34244
34398
  const trimmed = command.trim();
34245
34399
  if (!trimmed) return null;
34246
34400
  if (isExplicitCommandPath(trimmed)) {
34247
34401
  const expanded = expandHome(trimmed);
34248
- const candidate = path8.isAbsolute(expanded) ? expanded : path8.resolve(expanded);
34402
+ const candidate = path9.isAbsolute(expanded) ? expanded : path9.resolve(expanded);
34249
34403
  return (0, import_fs5.existsSync)(candidate) ? candidate : null;
34250
34404
  }
34251
34405
  return null;
@@ -36490,9 +36644,9 @@ ${cleanBody}`;
36490
36644
  return cleanTitle || cleanBody;
36491
36645
  }
36492
36646
  var fs32 = __toESM2(require("fs"));
36493
- var path10 = __toESM2(require("path"));
36647
+ var path11 = __toESM2(require("path"));
36494
36648
  var os52 = __toESM2(require("os"));
36495
- var HISTORY_DIR = path10.join(os52.homedir(), ".adhdev", "history");
36649
+ var HISTORY_DIR = path11.join(os52.homedir(), ".adhdev", "history");
36496
36650
  var RETAIN_DAYS = 30;
36497
36651
  var SAVED_HISTORY_INDEX_VERSION = 1;
36498
36652
  var SAVED_HISTORY_INDEX_FILE = ".saved-history-index.json";
@@ -36655,7 +36809,7 @@ ${cleanBody}`;
36655
36809
  function buildSavedHistoryFileSignatureMap(dir, files) {
36656
36810
  return new Map(files.map((file2) => {
36657
36811
  try {
36658
- const stat2 = fs32.statSync(path10.join(dir, file2));
36812
+ const stat2 = fs32.statSync(path11.join(dir, file2));
36659
36813
  return [file2, `${file2}:${stat2.size}:${Math.trunc(stat2.mtimeMs)}`];
36660
36814
  } catch {
36661
36815
  return [file2, `${file2}:missing`];
@@ -36666,7 +36820,7 @@ ${cleanBody}`;
36666
36820
  return files.map((file2) => fileSignatures.get(file2) || `${file2}:missing`).join("|");
36667
36821
  }
36668
36822
  function getSavedHistoryIndexFilePath(dir) {
36669
- return path10.join(dir, SAVED_HISTORY_INDEX_FILE);
36823
+ return path11.join(dir, SAVED_HISTORY_INDEX_FILE);
36670
36824
  }
36671
36825
  function getSavedHistoryIndexLockPath(dir) {
36672
36826
  return `${getSavedHistoryIndexFilePath(dir)}${SAVED_HISTORY_INDEX_LOCK_SUFFIX}`;
@@ -36768,7 +36922,7 @@ ${cleanBody}`;
36768
36922
  }
36769
36923
  for (const file2 of Array.from(currentEntries.keys())) {
36770
36924
  if (incomingFiles.has(file2)) continue;
36771
- if (!fs32.existsSync(path10.join(dir, file2))) {
36925
+ if (!fs32.existsSync(path11.join(dir, file2))) {
36772
36926
  currentEntries.delete(file2);
36773
36927
  }
36774
36928
  }
@@ -36794,7 +36948,7 @@ ${cleanBody}`;
36794
36948
  const indexStat = fs32.statSync(getSavedHistoryIndexFilePath(dir));
36795
36949
  const files = listHistoryFiles(dir);
36796
36950
  for (const file2 of files) {
36797
- const stat2 = fs32.statSync(path10.join(dir, file2));
36951
+ const stat2 = fs32.statSync(path11.join(dir, file2));
36798
36952
  if (stat2.mtimeMs > indexStat.mtimeMs) return true;
36799
36953
  }
36800
36954
  return false;
@@ -36804,14 +36958,14 @@ ${cleanBody}`;
36804
36958
  }
36805
36959
  function buildSavedHistoryFileSignature(dir, file2) {
36806
36960
  try {
36807
- const stat2 = fs32.statSync(path10.join(dir, file2));
36961
+ const stat2 = fs32.statSync(path11.join(dir, file2));
36808
36962
  return `${file2}:${stat2.size}:${Math.trunc(stat2.mtimeMs)}`;
36809
36963
  } catch {
36810
36964
  return `${file2}:missing`;
36811
36965
  }
36812
36966
  }
36813
36967
  function persistSavedHistoryFileSummaryEntry(agentType, dir, file2, updater) {
36814
- const filePath = path10.join(dir, file2);
36968
+ const filePath = path11.join(dir, file2);
36815
36969
  const result = withLockedPersistedSavedHistoryIndex(dir, (entries) => {
36816
36970
  const currentEntry = entries.get(file2) || null;
36817
36971
  const nextSummary = updater(currentEntry?.summary || null);
@@ -36884,7 +37038,7 @@ ${cleanBody}`;
36884
37038
  function computeSavedHistoryFileSummary(dir, file2) {
36885
37039
  const historySessionId = extractSavedHistorySessionIdFromFile(file2);
36886
37040
  if (!historySessionId) return null;
36887
- const filePath = path10.join(dir, file2);
37041
+ const filePath = path11.join(dir, file2);
36888
37042
  const content = fs32.readFileSync(filePath, "utf-8");
36889
37043
  const lines = content.split("\n").filter(Boolean);
36890
37044
  let messageCount = 0;
@@ -36971,7 +37125,7 @@ ${cleanBody}`;
36971
37125
  const summaryBySessionId = /* @__PURE__ */ new Map();
36972
37126
  const nextPersistedEntries = /* @__PURE__ */ new Map();
36973
37127
  for (const file2 of files.slice().sort()) {
36974
- const filePath = path10.join(dir, file2);
37128
+ const filePath = path11.join(dir, file2);
36975
37129
  const signature = fileSignatures.get(file2) || `${file2}:missing`;
36976
37130
  const cached2 = savedHistoryFileSummaryCache.get(filePath);
36977
37131
  const persisted = persistedEntries.get(file2);
@@ -37091,12 +37245,12 @@ ${cleanBody}`;
37091
37245
  });
37092
37246
  }
37093
37247
  if (newMessages.length === 0) return;
37094
- const dir = path10.join(HISTORY_DIR, this.sanitize(agentType));
37248
+ const dir = path11.join(HISTORY_DIR, this.sanitize(agentType));
37095
37249
  fs32.mkdirSync(dir, { recursive: true });
37096
37250
  const date5 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
37097
37251
  const filePrefix = effectiveHistoryKey ? `${this.sanitize(effectiveHistoryKey)}_` : "";
37098
37252
  const fileName = `${filePrefix}${date5}.jsonl`;
37099
- const filePath = path10.join(dir, fileName);
37253
+ const filePath = path11.join(dir, fileName);
37100
37254
  const lines = newMessages.map((m) => JSON.stringify(m)).join("\n") + "\n";
37101
37255
  fs32.appendFileSync(filePath, lines, "utf-8");
37102
37256
  updateSavedHistoryIndexForAppendedMessages(agentType, dir, fileName, effectiveHistoryKey, newMessages);
@@ -37187,11 +37341,11 @@ ${cleanBody}`;
37187
37341
  const ws2 = String(workspace || "").trim();
37188
37342
  if (!id || !ws2) return;
37189
37343
  try {
37190
- const dir = path10.join(HISTORY_DIR, this.sanitize(agentType));
37344
+ const dir = path11.join(HISTORY_DIR, this.sanitize(agentType));
37191
37345
  fs32.mkdirSync(dir, { recursive: true });
37192
37346
  const date5 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
37193
37347
  const fileName = `${this.sanitize(id)}_${date5}.jsonl`;
37194
- const filePath = path10.join(dir, fileName);
37348
+ const filePath = path11.join(dir, fileName);
37195
37349
  const record2 = {
37196
37350
  ts: (/* @__PURE__ */ new Date()).toISOString(),
37197
37351
  receivedAt: Date.now(),
@@ -37237,14 +37391,14 @@ ${cleanBody}`;
37237
37391
  this.lastSeenCounts.set(toDedupKey, Math.max(fromCount, this.lastSeenCounts.get(toDedupKey) || 0));
37238
37392
  this.lastSeenCounts.delete(fromDedupKey);
37239
37393
  }
37240
- const dir = path10.join(HISTORY_DIR, this.sanitize(agentType));
37394
+ const dir = path11.join(HISTORY_DIR, this.sanitize(agentType));
37241
37395
  if (!fs32.existsSync(dir)) return;
37242
37396
  const fromPrefix = `${this.sanitize(fromId)}_`;
37243
37397
  const toPrefix = `${this.sanitize(toId)}_`;
37244
37398
  const files = fs32.readdirSync(dir).filter((file2) => file2.startsWith(fromPrefix) && file2.endsWith(".jsonl"));
37245
37399
  for (const file2 of files) {
37246
- const sourcePath = path10.join(dir, file2);
37247
- const targetPath = path10.join(dir, `${toPrefix}${file2.slice(fromPrefix.length)}`);
37400
+ const sourcePath = path11.join(dir, file2);
37401
+ const targetPath = path11.join(dir, `${toPrefix}${file2.slice(fromPrefix.length)}`);
37248
37402
  const sourceLines = fs32.readFileSync(sourcePath, "utf-8").split("\n").filter(Boolean);
37249
37403
  const rewritten = sourceLines.map((line) => {
37250
37404
  try {
@@ -37278,13 +37432,13 @@ ${cleanBody}`;
37278
37432
  const sessionId = String(historySessionId || "").trim();
37279
37433
  if (!sessionId) return;
37280
37434
  try {
37281
- const dir = path10.join(HISTORY_DIR, this.sanitize(agentType));
37435
+ const dir = path11.join(HISTORY_DIR, this.sanitize(agentType));
37282
37436
  if (!fs32.existsSync(dir)) return;
37283
37437
  const prefix = `${this.sanitize(sessionId)}_`;
37284
37438
  const files = fs32.readdirSync(dir).filter((file2) => file2.startsWith(prefix) && file2.endsWith(".jsonl")).sort();
37285
37439
  const seen = /* @__PURE__ */ new Set();
37286
37440
  for (const file2 of files) {
37287
- const filePath = path10.join(dir, file2);
37441
+ const filePath = path11.join(dir, file2);
37288
37442
  const lines = fs32.readFileSync(filePath, "utf-8").split("\n").filter(Boolean);
37289
37443
  const next = [];
37290
37444
  for (const line of lines) {
@@ -37338,11 +37492,11 @@ ${cleanBody}`;
37338
37492
  const cutoff = Date.now() - RETAIN_DAYS * 24 * 60 * 60 * 1e3;
37339
37493
  const agentDirs = fs32.readdirSync(HISTORY_DIR, { withFileTypes: true }).filter((d) => d.isDirectory());
37340
37494
  for (const dir of agentDirs) {
37341
- const dirPath = path10.join(HISTORY_DIR, dir.name);
37495
+ const dirPath = path11.join(HISTORY_DIR, dir.name);
37342
37496
  const files = fs32.readdirSync(dirPath).filter((f) => f.endsWith(".jsonl") || f.endsWith(".terminal.log"));
37343
37497
  let removedAny = false;
37344
37498
  for (const file2 of files) {
37345
- const filePath = path10.join(dirPath, file2);
37499
+ const filePath = path11.join(dirPath, file2);
37346
37500
  const stat2 = fs32.statSync(filePath);
37347
37501
  if (stat2.mtimeMs < cutoff) {
37348
37502
  fs32.unlinkSync(filePath);
@@ -37392,13 +37546,13 @@ ${cleanBody}`;
37392
37546
  function readChatHistory(agentType, offset = 0, limit = 30, historySessionId, excludeRecentCount = 0, historyBehavior) {
37393
37547
  try {
37394
37548
  const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
37395
- const dir = path10.join(HISTORY_DIR, sanitized);
37549
+ const dir = path11.join(HISTORY_DIR, sanitized);
37396
37550
  if (!fs32.existsSync(dir)) return { messages: [], hasMore: false };
37397
37551
  const files = listHistoryFiles(dir, historySessionId);
37398
37552
  const allMessages = [];
37399
37553
  const seen = /* @__PURE__ */ new Set();
37400
37554
  for (const file2 of files) {
37401
- const filePath = path10.join(dir, file2);
37555
+ const filePath = path11.join(dir, file2);
37402
37556
  const content = fs32.readFileSync(filePath, "utf-8");
37403
37557
  const lines = content.trim().split("\n").filter(Boolean);
37404
37558
  for (let i = 0; i < lines.length; i++) {
@@ -37422,7 +37576,7 @@ ${cleanBody}`;
37422
37576
  function listSavedHistorySessions(agentType, options = {}, historyBehavior) {
37423
37577
  try {
37424
37578
  const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
37425
- const dir = path10.join(HISTORY_DIR, sanitized);
37579
+ const dir = path11.join(HISTORY_DIR, sanitized);
37426
37580
  if (!fs32.existsSync(dir)) {
37427
37581
  savedHistorySessionCache.delete(sanitized);
37428
37582
  return { sessions: [], hasMore: false };
@@ -37483,11 +37637,11 @@ ${cleanBody}`;
37483
37637
  }
37484
37638
  function readExistingSessionStartRecord(agentType, historySessionId) {
37485
37639
  try {
37486
- const dir = path10.join(HISTORY_DIR, agentType);
37640
+ const dir = path11.join(HISTORY_DIR, agentType);
37487
37641
  if (!fs32.existsSync(dir)) return null;
37488
37642
  const files = listHistoryFiles(dir, historySessionId).sort();
37489
37643
  for (const file2 of files) {
37490
- const lines = fs32.readFileSync(path10.join(dir, file2), "utf-8").split("\n").filter(Boolean);
37644
+ const lines = fs32.readFileSync(path11.join(dir, file2), "utf-8").split("\n").filter(Boolean);
37491
37645
  for (const line of lines) {
37492
37646
  try {
37493
37647
  const parsed = JSON.parse(line);
@@ -37507,16 +37661,16 @@ ${cleanBody}`;
37507
37661
  function rewriteCanonicalSavedHistory(agentType, historySessionId, records) {
37508
37662
  if (records.length === 0) return false;
37509
37663
  try {
37510
- const dir = path10.join(HISTORY_DIR, agentType);
37664
+ const dir = path11.join(HISTORY_DIR, agentType);
37511
37665
  fs32.mkdirSync(dir, { recursive: true });
37512
37666
  const prefix = `${historySessionId.replace(/[^a-zA-Z0-9_-]/g, "_")}_`;
37513
37667
  for (const file2 of fs32.readdirSync(dir)) {
37514
37668
  if (file2.startsWith(prefix) && file2.endsWith(".jsonl")) {
37515
- fs32.unlinkSync(path10.join(dir, file2));
37669
+ fs32.unlinkSync(path11.join(dir, file2));
37516
37670
  }
37517
37671
  }
37518
37672
  const targetDate = new Date(records[records.length - 1].receivedAt || Date.now()).toISOString().slice(0, 10);
37519
- const filePath = path10.join(dir, `${prefix}${targetDate}.jsonl`);
37673
+ const filePath = path11.join(dir, `${prefix}${targetDate}.jsonl`);
37520
37674
  fs32.writeFileSync(filePath, `${records.map((record2) => JSON.stringify(record2)).join("\n")}
37521
37675
  `, "utf-8");
37522
37676
  invalidatePersistedSavedHistoryIndex(agentType, dir);
@@ -39817,7 +39971,7 @@ ${effect.notification.body || ""}`.trim();
39817
39971
  }
39818
39972
  var fs42 = __toESM2(require("fs"));
39819
39973
  var os62 = __toESM2(require("os"));
39820
- var path11 = __toESM2(require("path"));
39974
+ var path12 = __toESM2(require("path"));
39821
39975
  var import_node_crypto = require("crypto");
39822
39976
  var VALID_INPUT_MEDIA_TYPES = /* @__PURE__ */ new Set(["text", "image", "audio", "video", "resource"]);
39823
39977
  function getProviderLabel(provider) {
@@ -40318,7 +40472,7 @@ ${effect.notification.body || ""}`.trim();
40318
40472
  }
40319
40473
  function getChatDebugBundleDir() {
40320
40474
  const override = typeof process.env.ADHDEV_DEBUG_BUNDLE_DIR === "string" ? process.env.ADHDEV_DEBUG_BUNDLE_DIR.trim() : "";
40321
- return override || path11.join(os62.homedir(), ".adhdev", "debug-bundles", "chat");
40475
+ return override || path12.join(os62.homedir(), ".adhdev", "debug-bundles", "chat");
40322
40476
  }
40323
40477
  function safeBundleIdSegment(value, fallback) {
40324
40478
  const normalized = String(value || fallback).trim().replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
@@ -40351,7 +40505,7 @@ ${effect.notification.body || ""}`.trim();
40351
40505
  const bundleId = createChatDebugBundleId(targetSessionId);
40352
40506
  const dir = getChatDebugBundleDir();
40353
40507
  fs42.mkdirSync(dir, { recursive: true });
40354
- const savedPath = path11.join(dir, `${bundleId}.json`);
40508
+ const savedPath = path12.join(dir, `${bundleId}.json`);
40355
40509
  const json2 = `${JSON.stringify(bundle, null, 2)}
40356
40510
  `;
40357
40511
  fs42.writeFileSync(savedPath, json2, { encoding: "utf8", mode: 384 });
@@ -41493,7 +41647,7 @@ ${effect.notification.body || ""}`.trim();
41493
41647
  return { success: false, error: "resolveAction script not available for this provider" };
41494
41648
  }
41495
41649
  var fs52 = __toESM2(require("fs"));
41496
- var path12 = __toESM2(require("path"));
41650
+ var path13 = __toESM2(require("path"));
41497
41651
  var os72 = __toESM2(require("os"));
41498
41652
  var KEY_TO_VK = {
41499
41653
  Backspace: 8,
@@ -41750,25 +41904,25 @@ ${effect.notification.body || ""}`.trim();
41750
41904
  const inputPath = rawPath || ".";
41751
41905
  const home = os72.homedir();
41752
41906
  if (inputPath.startsWith("~")) {
41753
- return path12.resolve(path12.join(home, inputPath.slice(1)));
41907
+ return path13.resolve(path13.join(home, inputPath.slice(1)));
41754
41908
  }
41755
41909
  if (process.platform === "win32") {
41756
41910
  const normalized = normalizeWindowsRequestedPath(inputPath);
41757
- if (path12.win32.isAbsolute(normalized)) {
41758
- return path12.win32.normalize(normalized);
41911
+ if (path13.win32.isAbsolute(normalized)) {
41912
+ return path13.win32.normalize(normalized);
41759
41913
  }
41760
- return path12.win32.resolve(normalized);
41914
+ return path13.win32.resolve(normalized);
41761
41915
  }
41762
- if (path12.isAbsolute(inputPath)) {
41763
- return path12.normalize(inputPath);
41916
+ if (path13.isAbsolute(inputPath)) {
41917
+ return path13.normalize(inputPath);
41764
41918
  }
41765
- return path12.resolve(inputPath);
41919
+ return path13.resolve(inputPath);
41766
41920
  }
41767
41921
  function listDirectoryEntriesSafe(dirPath) {
41768
41922
  const entries = fs52.readdirSync(dirPath, { withFileTypes: true });
41769
41923
  const files = [];
41770
41924
  for (const entry of entries) {
41771
- const entryPath = path12.join(dirPath, entry.name);
41925
+ const entryPath = path13.join(dirPath, entry.name);
41772
41926
  try {
41773
41927
  if (entry.isDirectory()) {
41774
41928
  files.push({ name: entry.name, type: "directory" });
@@ -41822,7 +41976,7 @@ ${effect.notification.body || ""}`.trim();
41822
41976
  async function handleFileWrite(h, args) {
41823
41977
  try {
41824
41978
  const filePath = resolveSafePath(args?.path);
41825
- fs52.mkdirSync(path12.dirname(filePath), { recursive: true });
41979
+ fs52.mkdirSync(path13.dirname(filePath), { recursive: true });
41826
41980
  fs52.writeFileSync(filePath, args?.content || "", "utf-8");
41827
41981
  return { success: true, path: filePath };
41828
41982
  } catch (e) {
@@ -42927,7 +43081,7 @@ ${effect.notification.body || ""}`.trim();
42927
43081
  }
42928
43082
  };
42929
43083
  var os13 = __toESM2(require("os"));
42930
- var path16 = __toESM2(require("path"));
43084
+ var path17 = __toESM2(require("path"));
42931
43085
  var crypto4 = __toESM2(require("crypto"));
42932
43086
  var import_fs6 = require("fs");
42933
43087
  var import_child_process6 = require("child_process");
@@ -42935,7 +43089,7 @@ ${effect.notification.body || ""}`.trim();
42935
43089
  init_provider_cli_adapter();
42936
43090
  init_config();
42937
43091
  var os12 = __toESM2(require("os"));
42938
- var path15 = __toESM2(require("path"));
43092
+ var path16 = __toESM2(require("path"));
42939
43093
  var crypto3 = __toESM2(require("crypto"));
42940
43094
  var fs6 = __toESM2(require("fs"));
42941
43095
  var import_node_module = require("module");
@@ -42990,7 +43144,7 @@ ${effect.notification.body || ""}`.trim();
42990
43144
  var CachedDatabaseSync = null;
42991
43145
  function getDatabaseSync() {
42992
43146
  if (CachedDatabaseSync) return CachedDatabaseSync;
42993
- const requireFn = typeof require === "function" ? require : (0, import_node_module.createRequire)(path15.join(process.cwd(), "__adhdev_sqlite_loader__.js"));
43147
+ const requireFn = typeof require === "function" ? require : (0, import_node_module.createRequire)(path16.join(process.cwd(), "__adhdev_sqlite_loader__.js"));
42994
43148
  const sqliteModule = requireFn(`node:${"sqlite"}`);
42995
43149
  CachedDatabaseSync = sqliteModule.DatabaseSync;
42996
43150
  if (!CachedDatabaseSync) {
@@ -45048,11 +45202,11 @@ ${rawInput}` : rawInput;
45048
45202
  }
45049
45203
  function isExplicitCommand(command) {
45050
45204
  const trimmed = command.trim();
45051
- return path16.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
45205
+ return path17.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
45052
45206
  }
45053
45207
  function expandExecutable(command) {
45054
45208
  const trimmed = command.trim();
45055
- return trimmed.startsWith("~") ? path16.join(os13.homedir(), trimmed.slice(1)) : trimmed;
45209
+ return trimmed.startsWith("~") ? path17.join(os13.homedir(), trimmed.slice(1)) : trimmed;
45056
45210
  }
45057
45211
  function commandExists(command) {
45058
45212
  const trimmed = command.trim();
@@ -45333,7 +45487,7 @@ ${rawInput}` : rawInput;
45333
45487
  async startSession(cliType, workingDir, cliArgs, initialModel, options) {
45334
45488
  const trimmed = (workingDir || "").trim();
45335
45489
  if (!trimmed) throw new Error("working directory required");
45336
- const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) : path16.resolve(trimmed);
45490
+ const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) : path17.resolve(trimmed);
45337
45491
  const normalizedType = this.providerLoader.resolveAlias(cliType);
45338
45492
  const rawProvider = this.providerLoader.getByAlias(cliType);
45339
45493
  const provider = rawProvider ? this.providerLoader.resolve(normalizedType) || rawProvider : void 0;
@@ -45832,9 +45986,9 @@ Run 'adhdev doctor' for detailed diagnostics.`
45832
45986
  var import_child_process7 = require("child_process");
45833
45987
  var net3 = __toESM2(require("net"));
45834
45988
  var os15 = __toESM2(require("os"));
45835
- var path18 = __toESM2(require("path"));
45989
+ var path19 = __toESM2(require("path"));
45836
45990
  var fs7 = __toESM2(require("fs"));
45837
- var path17 = __toESM2(require("path"));
45991
+ var path18 = __toESM2(require("path"));
45838
45992
  var os14 = __toESM2(require("os"));
45839
45993
  var chokidar = __toESM2(require_chokidar());
45840
45994
  init_logger();
@@ -46154,7 +46308,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
46154
46308
  try {
46155
46309
  if (!fs7.existsSync(candidate) || !fs7.statSync(candidate).isDirectory()) return false;
46156
46310
  return ["ide", "extension", "cli", "acp"].some(
46157
- (category) => fs7.existsSync(path17.join(candidate, category))
46311
+ (category) => fs7.existsSync(path18.join(candidate, category))
46158
46312
  );
46159
46313
  } catch {
46160
46314
  return false;
@@ -46162,20 +46316,20 @@ Run 'adhdev doctor' for detailed diagnostics.`
46162
46316
  }
46163
46317
  static hasProviderRootMarker(candidate) {
46164
46318
  try {
46165
- return fs7.existsSync(path17.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
46319
+ return fs7.existsSync(path18.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
46166
46320
  } catch {
46167
46321
  return false;
46168
46322
  }
46169
46323
  }
46170
46324
  detectDefaultUserDir() {
46171
- const fallback = path17.join(os14.homedir(), ".adhdev", "providers");
46325
+ const fallback = path18.join(os14.homedir(), ".adhdev", "providers");
46172
46326
  const envOptIn = process.env[_ProviderLoader.SIBLING_ENV_VAR] === "1";
46173
46327
  const visited = /* @__PURE__ */ new Set();
46174
46328
  for (const start of this.probeStarts) {
46175
- let current = path17.resolve(start);
46329
+ let current = path18.resolve(start);
46176
46330
  while (!visited.has(current)) {
46177
46331
  visited.add(current);
46178
- const siblingCandidate = path17.join(path17.dirname(current), _ProviderLoader.REPO_PROVIDER_DIRNAME);
46332
+ const siblingCandidate = path18.join(path18.dirname(current), _ProviderLoader.REPO_PROVIDER_DIRNAME);
46179
46333
  if (_ProviderLoader.looksLikeProviderRoot(siblingCandidate)) {
46180
46334
  const hasMarker = _ProviderLoader.hasProviderRootMarker(siblingCandidate);
46181
46335
  if (envOptIn || hasMarker) {
@@ -46197,7 +46351,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
46197
46351
  return { path: siblingCandidate, source };
46198
46352
  }
46199
46353
  }
46200
- const parent = path17.dirname(current);
46354
+ const parent = path18.dirname(current);
46201
46355
  if (parent === current) break;
46202
46356
  current = parent;
46203
46357
  }
@@ -46207,11 +46361,11 @@ Run 'adhdev doctor' for detailed diagnostics.`
46207
46361
  constructor(options) {
46208
46362
  this.logFn = options?.logFn || LOG2.forComponent("Provider").asLogFn();
46209
46363
  this.probeStarts = options?.probeStarts ?? [process.cwd(), __dirname];
46210
- this.defaultProvidersDir = path17.join(os14.homedir(), ".adhdev", "providers");
46364
+ this.defaultProvidersDir = path18.join(os14.homedir(), ".adhdev", "providers");
46211
46365
  const detected = this.detectDefaultUserDir();
46212
46366
  this.userDir = detected.path;
46213
46367
  this.userDirSource = detected.source;
46214
- this.upstreamDir = path17.join(this.defaultProvidersDir, ".upstream");
46368
+ this.upstreamDir = path18.join(this.defaultProvidersDir, ".upstream");
46215
46369
  this.disableUpstream = false;
46216
46370
  this.applySourceConfig({
46217
46371
  userDir: options?.userDir,
@@ -46270,7 +46424,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
46270
46424
  this.userDir = detected.path;
46271
46425
  this.userDirSource = detected.source;
46272
46426
  }
46273
- this.upstreamDir = path17.join(this.defaultProvidersDir, ".upstream");
46427
+ this.upstreamDir = path18.join(this.defaultProvidersDir, ".upstream");
46274
46428
  this.disableUpstream = this.sourceMode === "no-upstream";
46275
46429
  if (this.explicitProviderDir) {
46276
46430
  this.log(`Config 'providerDir' applied: ${this.userDir}`);
@@ -46284,7 +46438,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
46284
46438
  * Canonical provider directory shape for a given root.
46285
46439
  */
46286
46440
  getProviderDir(root, category, type) {
46287
- return path17.join(root, category, type);
46441
+ return path18.join(root, category, type);
46288
46442
  }
46289
46443
  /**
46290
46444
  * Canonical user override directory for a provider.
@@ -46311,7 +46465,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
46311
46465
  resolveProviderFile(type, ...segments) {
46312
46466
  const dir = this.findProviderDirInternal(type);
46313
46467
  if (!dir) return null;
46314
- return path17.join(dir, ...segments);
46468
+ return path18.join(dir, ...segments);
46315
46469
  }
46316
46470
  /**
46317
46471
  * Load all providers (3-tier priority)
@@ -46350,7 +46504,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
46350
46504
  if (!fs7.existsSync(this.upstreamDir)) return false;
46351
46505
  try {
46352
46506
  return fs7.readdirSync(this.upstreamDir).some(
46353
- (d) => fs7.statSync(path17.join(this.upstreamDir, d)).isDirectory()
46507
+ (d) => fs7.statSync(path18.join(this.upstreamDir, d)).isDirectory()
46354
46508
  );
46355
46509
  } catch {
46356
46510
  return false;
@@ -46847,8 +47001,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
46847
47001
  resolved._resolvedScriptDir = entry.scriptDir;
46848
47002
  resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
46849
47003
  if (providerDir) {
46850
- const fullDir = path17.join(providerDir, entry.scriptDir);
46851
- resolved._resolvedScriptsPath = fs7.existsSync(path17.join(fullDir, "scripts.js")) ? path17.join(fullDir, "scripts.js") : fullDir;
47004
+ const fullDir = path18.join(providerDir, entry.scriptDir);
47005
+ resolved._resolvedScriptsPath = fs7.existsSync(path18.join(fullDir, "scripts.js")) ? path18.join(fullDir, "scripts.js") : fullDir;
46852
47006
  }
46853
47007
  matched = true;
46854
47008
  }
@@ -46863,8 +47017,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
46863
47017
  resolved._resolvedScriptDir = base.defaultScriptDir;
46864
47018
  resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
46865
47019
  if (providerDir) {
46866
- const fullDir = path17.join(providerDir, base.defaultScriptDir);
46867
- resolved._resolvedScriptsPath = fs7.existsSync(path17.join(fullDir, "scripts.js")) ? path17.join(fullDir, "scripts.js") : fullDir;
47020
+ const fullDir = path18.join(providerDir, base.defaultScriptDir);
47021
+ resolved._resolvedScriptsPath = fs7.existsSync(path18.join(fullDir, "scripts.js")) ? path18.join(fullDir, "scripts.js") : fullDir;
46868
47022
  }
46869
47023
  }
46870
47024
  resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
@@ -46881,8 +47035,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
46881
47035
  resolved._resolvedScriptDir = dirOverride;
46882
47036
  resolved._resolvedScriptsSource = `versions:${range}`;
46883
47037
  if (providerDir) {
46884
- const fullDir = path17.join(providerDir, dirOverride);
46885
- resolved._resolvedScriptsPath = fs7.existsSync(path17.join(fullDir, "scripts.js")) ? path17.join(fullDir, "scripts.js") : fullDir;
47038
+ const fullDir = path18.join(providerDir, dirOverride);
47039
+ resolved._resolvedScriptsPath = fs7.existsSync(path18.join(fullDir, "scripts.js")) ? path18.join(fullDir, "scripts.js") : fullDir;
46886
47040
  }
46887
47041
  }
46888
47042
  } else if (override.scripts) {
@@ -46898,8 +47052,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
46898
47052
  resolved._resolvedScriptDir = base.defaultScriptDir;
46899
47053
  resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
46900
47054
  if (providerDir) {
46901
- const fullDir = path17.join(providerDir, base.defaultScriptDir);
46902
- resolved._resolvedScriptsPath = fs7.existsSync(path17.join(fullDir, "scripts.js")) ? path17.join(fullDir, "scripts.js") : fullDir;
47055
+ const fullDir = path18.join(providerDir, base.defaultScriptDir);
47056
+ resolved._resolvedScriptsPath = fs7.existsSync(path18.join(fullDir, "scripts.js")) ? path18.join(fullDir, "scripts.js") : fullDir;
46903
47057
  }
46904
47058
  }
46905
47059
  }
@@ -46931,14 +47085,14 @@ Run 'adhdev doctor' for detailed diagnostics.`
46931
47085
  this.log(` [loadScriptsFromDir] ${type}: providerDir not found`);
46932
47086
  return null;
46933
47087
  }
46934
- const dir = path17.join(providerDir, scriptDir);
47088
+ const dir = path18.join(providerDir, scriptDir);
46935
47089
  if (!fs7.existsSync(dir)) {
46936
47090
  this.log(` [loadScriptsFromDir] ${type}: dir not found: ${dir}`);
46937
47091
  return null;
46938
47092
  }
46939
47093
  const cached2 = this.scriptsCache.get(dir);
46940
47094
  if (cached2) return cached2;
46941
- const scriptsJs = path17.join(dir, "scripts.js");
47095
+ const scriptsJs = path18.join(dir, "scripts.js");
46942
47096
  if (fs7.existsSync(scriptsJs)) {
46943
47097
  try {
46944
47098
  delete require.cache[require.resolve(scriptsJs)];
@@ -46980,7 +47134,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
46980
47134
  return;
46981
47135
  }
46982
47136
  if (filePath.endsWith(".js") || filePath.endsWith(".json")) {
46983
- this.log(`File changed: ${path17.basename(filePath)}, reloading...`);
47137
+ this.log(`File changed: ${path18.basename(filePath)}, reloading...`);
46984
47138
  this.reload();
46985
47139
  }
46986
47140
  };
@@ -47035,7 +47189,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
47035
47189
  }
47036
47190
  const https = require("https");
47037
47191
  const { execSync: execSync7 } = require("child_process");
47038
- const metaPath = path17.join(this.upstreamDir, _ProviderLoader.META_FILE);
47192
+ const metaPath = path18.join(this.upstreamDir, _ProviderLoader.META_FILE);
47039
47193
  let prevEtag = "";
47040
47194
  let prevTimestamp = 0;
47041
47195
  try {
@@ -47095,17 +47249,17 @@ Run 'adhdev doctor' for detailed diagnostics.`
47095
47249
  return { updated: false };
47096
47250
  }
47097
47251
  this.log("Downloading latest providers from GitHub...");
47098
- const tmpTar = path17.join(os14.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
47099
- const tmpExtract = path17.join(os14.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
47252
+ const tmpTar = path18.join(os14.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
47253
+ const tmpExtract = path18.join(os14.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
47100
47254
  await this.downloadFile(_ProviderLoader.GITHUB_TARBALL_URL, tmpTar);
47101
47255
  fs7.mkdirSync(tmpExtract, { recursive: true });
47102
47256
  execSync7(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
47103
47257
  const extracted = fs7.readdirSync(tmpExtract);
47104
47258
  const rootDir = extracted.find(
47105
- (d) => fs7.statSync(path17.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
47259
+ (d) => fs7.statSync(path18.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
47106
47260
  );
47107
47261
  if (!rootDir) throw new Error("Unexpected tarball structure");
47108
- const sourceDir = path17.join(tmpExtract, rootDir);
47262
+ const sourceDir = path18.join(tmpExtract, rootDir);
47109
47263
  const backupDir = this.upstreamDir + ".bak";
47110
47264
  if (fs7.existsSync(this.upstreamDir)) {
47111
47265
  if (fs7.existsSync(backupDir)) fs7.rmSync(backupDir, { recursive: true, force: true });
@@ -47180,8 +47334,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
47180
47334
  copyDirRecursive(src, dest) {
47181
47335
  fs7.mkdirSync(dest, { recursive: true });
47182
47336
  for (const entry of fs7.readdirSync(src, { withFileTypes: true })) {
47183
- const srcPath = path17.join(src, entry.name);
47184
- const destPath = path17.join(dest, entry.name);
47337
+ const srcPath = path18.join(src, entry.name);
47338
+ const destPath = path18.join(dest, entry.name);
47185
47339
  if (entry.isDirectory()) {
47186
47340
  this.copyDirRecursive(srcPath, destPath);
47187
47341
  } else {
@@ -47192,7 +47346,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
47192
47346
  /** .meta.json save */
47193
47347
  writeMeta(metaPath, etag, timestamp) {
47194
47348
  try {
47195
- fs7.mkdirSync(path17.dirname(metaPath), { recursive: true });
47349
+ fs7.mkdirSync(path18.dirname(metaPath), { recursive: true });
47196
47350
  fs7.writeFileSync(metaPath, JSON.stringify({
47197
47351
  etag,
47198
47352
  timestamp,
@@ -47209,7 +47363,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
47209
47363
  const scan = (d) => {
47210
47364
  try {
47211
47365
  for (const entry of fs7.readdirSync(d, { withFileTypes: true })) {
47212
- if (entry.isDirectory()) scan(path17.join(d, entry.name));
47366
+ if (entry.isDirectory()) scan(path18.join(d, entry.name));
47213
47367
  else if (entry.name === "provider.json") count++;
47214
47368
  }
47215
47369
  } catch {
@@ -47437,17 +47591,17 @@ Run 'adhdev doctor' for detailed diagnostics.`
47437
47591
  for (const root of searchRoots) {
47438
47592
  if (!fs7.existsSync(root)) continue;
47439
47593
  const candidate = this.getProviderDir(root, cat, type);
47440
- if (fs7.existsSync(path17.join(candidate, "provider.json"))) return candidate;
47441
- const catDir = path17.join(root, cat);
47594
+ if (fs7.existsSync(path18.join(candidate, "provider.json"))) return candidate;
47595
+ const catDir = path18.join(root, cat);
47442
47596
  if (fs7.existsSync(catDir)) {
47443
47597
  try {
47444
47598
  for (const entry of fs7.readdirSync(catDir, { withFileTypes: true })) {
47445
47599
  if (!entry.isDirectory()) continue;
47446
- const jsonPath = path17.join(catDir, entry.name, "provider.json");
47600
+ const jsonPath = path18.join(catDir, entry.name, "provider.json");
47447
47601
  if (fs7.existsSync(jsonPath)) {
47448
47602
  try {
47449
47603
  const data = JSON.parse(fs7.readFileSync(jsonPath, "utf-8"));
47450
- if (data.type === type) return path17.join(catDir, entry.name);
47604
+ if (data.type === type) return path18.join(catDir, entry.name);
47451
47605
  } catch {
47452
47606
  }
47453
47607
  }
@@ -47464,7 +47618,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
47464
47618
  * (template substitution is NOT applied here — scripts.js handles that)
47465
47619
  */
47466
47620
  buildScriptWrappersFromDir(dir) {
47467
- const scriptsJs = path17.join(dir, "scripts.js");
47621
+ const scriptsJs = path18.join(dir, "scripts.js");
47468
47622
  if (fs7.existsSync(scriptsJs)) {
47469
47623
  try {
47470
47624
  delete require.cache[require.resolve(scriptsJs)];
@@ -47478,7 +47632,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
47478
47632
  for (const file2 of fs7.readdirSync(dir)) {
47479
47633
  if (!file2.endsWith(".js")) continue;
47480
47634
  const scriptName = toCamel(file2.replace(".js", ""));
47481
- const filePath = path17.join(dir, file2);
47635
+ const filePath = path18.join(dir, file2);
47482
47636
  result[scriptName] = (...args) => {
47483
47637
  try {
47484
47638
  let content = fs7.readFileSync(filePath, "utf-8");
@@ -47538,7 +47692,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
47538
47692
  }
47539
47693
  const hasJson = entries.some((e) => e.name === "provider.json");
47540
47694
  if (hasJson) {
47541
- const jsonPath = path17.join(d, "provider.json");
47695
+ const jsonPath = path18.join(d, "provider.json");
47542
47696
  try {
47543
47697
  const raw = fs7.readFileSync(jsonPath, "utf-8");
47544
47698
  const mod = JSON.parse(raw);
@@ -47559,7 +47713,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
47559
47713
  this.log(`\u26A0 Invalid provider at ${jsonPath}: ${validation.errors.join("; ")}`);
47560
47714
  } else {
47561
47715
  const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
47562
- const scriptsPath = path17.join(d, "scripts.js");
47716
+ const scriptsPath = path18.join(d, "scripts.js");
47563
47717
  if (!hasCompatibility && fs7.existsSync(scriptsPath)) {
47564
47718
  try {
47565
47719
  delete require.cache[require.resolve(scriptsPath)];
@@ -47585,7 +47739,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
47585
47739
  if (!entry.isDirectory()) continue;
47586
47740
  if (entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
47587
47741
  if (excludeDirs && d === dir && excludeDirs.includes(entry.name)) continue;
47588
- scan(path17.join(d, entry.name));
47742
+ scan(path18.join(d, entry.name));
47589
47743
  }
47590
47744
  }
47591
47745
  };
@@ -47906,8 +48060,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
47906
48060
  const appNameMap = getMacAppIdentifiers();
47907
48061
  const appName = appNameMap[ideId];
47908
48062
  if (appName) {
47909
- const storagePath = path18.join(
47910
- process.env.APPDATA || path18.join(os15.homedir(), "AppData", "Roaming"),
48063
+ const storagePath = path19.join(
48064
+ process.env.APPDATA || path19.join(os15.homedir(), "AppData", "Roaming"),
47911
48065
  appName,
47912
48066
  "storage.json"
47913
48067
  );
@@ -48092,9 +48246,9 @@ Run 'adhdev doctor' for detailed diagnostics.`
48092
48246
  init_config();
48093
48247
  init_logger();
48094
48248
  var fs8 = __toESM2(require("fs"));
48095
- var path19 = __toESM2(require("path"));
48249
+ var path20 = __toESM2(require("path"));
48096
48250
  var os16 = __toESM2(require("os"));
48097
- var LOG_DIR2 = process.platform === "win32" ? path19.join(process.env.LOCALAPPDATA || process.env.APPDATA || path19.join(os16.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path19.join(os16.homedir(), "Library", "Logs", "adhdev") : path19.join(os16.homedir(), ".local", "share", "adhdev", "logs");
48251
+ var LOG_DIR2 = process.platform === "win32" ? path20.join(process.env.LOCALAPPDATA || process.env.APPDATA || path20.join(os16.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path20.join(os16.homedir(), "Library", "Logs", "adhdev") : path20.join(os16.homedir(), ".local", "share", "adhdev", "logs");
48098
48252
  var MAX_FILE_SIZE = 5 * 1024 * 1024;
48099
48253
  var MAX_DAYS = 7;
48100
48254
  try {
@@ -48132,13 +48286,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
48132
48286
  return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
48133
48287
  }
48134
48288
  var currentDate2 = getDateStr2();
48135
- var currentFile = path19.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
48289
+ var currentFile = path20.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
48136
48290
  var writeCount2 = 0;
48137
48291
  function checkRotation() {
48138
48292
  const today = getDateStr2();
48139
48293
  if (today !== currentDate2) {
48140
48294
  currentDate2 = today;
48141
- currentFile = path19.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
48295
+ currentFile = path20.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
48142
48296
  cleanOldFiles();
48143
48297
  }
48144
48298
  }
@@ -48152,7 +48306,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
48152
48306
  const dateMatch = file2.match(/commands-(\d{4}-\d{2}-\d{2})/);
48153
48307
  if (dateMatch && dateMatch[1] < cutoffStr) {
48154
48308
  try {
48155
- fs8.unlinkSync(path19.join(LOG_DIR2, file2));
48309
+ fs8.unlinkSync(path20.join(LOG_DIR2, file2));
48156
48310
  } catch {
48157
48311
  }
48158
48312
  }
@@ -48234,7 +48388,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
48234
48388
  }
48235
48389
  cleanOldFiles();
48236
48390
  init_logger();
48237
- var import_node_fs2 = require("fs");
48391
+ var import_node_fs3 = require("fs");
48238
48392
  var import_node_module2 = require("module");
48239
48393
  var import_node_path = require("path");
48240
48394
  var DEFAULT_SERVER_NAME = "adhdev-mesh";
@@ -48257,8 +48411,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
48257
48411
  }
48258
48412
  const serverName = mcpConfig.serverName?.trim() || DEFAULT_SERVER_NAME;
48259
48413
  if (mcpConfig.mode === "auto_import") {
48260
- const path26 = mcpConfig.path?.trim();
48261
- if (!path26) {
48414
+ const path27 = mcpConfig.path?.trim();
48415
+ if (!path27) {
48262
48416
  return { kind: "unsupported", reason: "Provider auto-import MCP config is missing a config path" };
48263
48417
  }
48264
48418
  const mcpServer = resolveAdhdevMcpServerLaunch({
@@ -48275,7 +48429,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
48275
48429
  return {
48276
48430
  kind: "auto_import",
48277
48431
  serverName,
48278
- configPath: (0, import_node_path.join)(workspace, path26),
48432
+ configPath: (0, import_node_path.join)(workspace, path27),
48279
48433
  configFormat: mcpConfig.format,
48280
48434
  mcpServer
48281
48435
  };
@@ -48352,8 +48506,8 @@ Run 'adhdev doctor' for detailed diagnostics.`
48352
48506
  }
48353
48507
  function normalizeExistingPath(filePath) {
48354
48508
  try {
48355
- if (!(0, import_node_fs2.existsSync)(filePath)) return null;
48356
- return import_node_fs2.realpathSync.native(filePath);
48509
+ if (!(0, import_node_fs3.existsSync)(filePath)) return null;
48510
+ return import_node_fs3.realpathSync.native(filePath);
48357
48511
  } catch {
48358
48512
  return null;
48359
48513
  }
@@ -48673,13 +48827,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
48673
48827
  var import_child_process9 = require("child_process");
48674
48828
  var fs9 = __toESM2(require("fs"));
48675
48829
  var os18 = __toESM2(require("os"));
48676
- var path20 = __toESM2(require("path"));
48830
+ var path21 = __toESM2(require("path"));
48677
48831
  var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
48678
48832
  function getUpgradeLogPath() {
48679
48833
  const home = os18.homedir();
48680
- const dir = path20.join(home, ".adhdev");
48834
+ const dir = path21.join(home, ".adhdev");
48681
48835
  fs9.mkdirSync(dir, { recursive: true });
48682
- return path20.join(dir, "daemon-upgrade.log");
48836
+ return path21.join(dir, "daemon-upgrade.log");
48683
48837
  }
48684
48838
  function appendUpgradeLog(message) {
48685
48839
  const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
@@ -48690,14 +48844,14 @@ Run 'adhdev doctor' for detailed diagnostics.`
48690
48844
  }
48691
48845
  }
48692
48846
  function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platform) {
48693
- const binDir = path20.dirname(nodeExecutable);
48847
+ const binDir = path21.dirname(nodeExecutable);
48694
48848
  if (platform10 === "win32") {
48695
- const npmCliPath = path20.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
48849
+ const npmCliPath = path21.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
48696
48850
  if (fs9.existsSync(npmCliPath)) {
48697
48851
  return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
48698
48852
  }
48699
48853
  for (const candidate of ["npm.exe", "npm"]) {
48700
- const candidatePath = path20.join(binDir, candidate);
48854
+ const candidatePath = path21.join(binDir, candidate);
48701
48855
  if (fs9.existsSync(candidatePath)) {
48702
48856
  return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
48703
48857
  }
@@ -48705,7 +48859,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
48705
48859
  return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
48706
48860
  }
48707
48861
  for (const candidate of ["npm"]) {
48708
- const candidatePath = path20.join(binDir, candidate);
48862
+ const candidatePath = path21.join(binDir, candidate);
48709
48863
  if (fs9.existsSync(candidatePath)) {
48710
48864
  return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
48711
48865
  }
@@ -48722,13 +48876,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
48722
48876
  let currentDir = resolvedPath;
48723
48877
  try {
48724
48878
  if (fs9.statSync(resolvedPath).isFile()) {
48725
- currentDir = path20.dirname(resolvedPath);
48879
+ currentDir = path21.dirname(resolvedPath);
48726
48880
  }
48727
48881
  } catch {
48728
- currentDir = path20.dirname(resolvedPath);
48882
+ currentDir = path21.dirname(resolvedPath);
48729
48883
  }
48730
48884
  while (true) {
48731
- const packageJsonPath = path20.join(currentDir, "package.json");
48885
+ const packageJsonPath = path21.join(currentDir, "package.json");
48732
48886
  try {
48733
48887
  if (fs9.existsSync(packageJsonPath)) {
48734
48888
  const parsed = JSON.parse(fs9.readFileSync(packageJsonPath, "utf8"));
@@ -48739,7 +48893,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
48739
48893
  }
48740
48894
  } catch {
48741
48895
  }
48742
- const parentDir = path20.dirname(currentDir);
48896
+ const parentDir = path21.dirname(currentDir);
48743
48897
  if (parentDir === currentDir) {
48744
48898
  return null;
48745
48899
  }
@@ -48747,13 +48901,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
48747
48901
  }
48748
48902
  }
48749
48903
  function resolveInstallPrefixFromPackageRoot(packageRoot, packageName) {
48750
- const nodeModulesDir = packageName.startsWith("@") ? path20.dirname(path20.dirname(packageRoot)) : path20.dirname(packageRoot);
48751
- if (path20.basename(nodeModulesDir) !== "node_modules") {
48904
+ const nodeModulesDir = packageName.startsWith("@") ? path21.dirname(path21.dirname(packageRoot)) : path21.dirname(packageRoot);
48905
+ if (path21.basename(nodeModulesDir) !== "node_modules") {
48752
48906
  return null;
48753
48907
  }
48754
- const maybeLibDir = path20.dirname(nodeModulesDir);
48755
- if (path20.basename(maybeLibDir) === "lib") {
48756
- return path20.dirname(maybeLibDir);
48908
+ const maybeLibDir = path21.dirname(nodeModulesDir);
48909
+ if (path21.basename(maybeLibDir) === "lib") {
48910
+ return path21.dirname(maybeLibDir);
48757
48911
  }
48758
48912
  return maybeLibDir;
48759
48913
  }
@@ -48868,7 +49022,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
48868
49022
  }
48869
49023
  }
48870
49024
  function stopSessionHostProcesses(appName) {
48871
- const pidFile = path20.join(os18.homedir(), ".adhdev", `${appName}-session-host.pid`);
49025
+ const pidFile = path21.join(os18.homedir(), ".adhdev", `${appName}-session-host.pid`);
48872
49026
  try {
48873
49027
  if (fs9.existsSync(pidFile)) {
48874
49028
  const pid = Number.parseInt(fs9.readFileSync(pidFile, "utf8").trim(), 10);
@@ -48885,7 +49039,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
48885
49039
  }
48886
49040
  }
48887
49041
  function removeDaemonPidFile() {
48888
- const pidFile = path20.join(os18.homedir(), ".adhdev", "daemon.pid");
49042
+ const pidFile = path21.join(os18.homedir(), ".adhdev", "daemon.pid");
48889
49043
  try {
48890
49044
  fs9.unlinkSync(pidFile);
48891
49045
  } catch {
@@ -48896,7 +49050,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
48896
49050
  const npmRoot = String(execNpmCommandSync(["root", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
48897
49051
  if (!npmRoot) return;
48898
49052
  const npmPrefix = surface.installPrefix || String(execNpmCommandSync(["prefix", "-g", ...prefixArgs], { encoding: "utf8" }, surface)).trim();
48899
- const binDir = process.platform === "win32" ? npmPrefix : path20.join(npmPrefix, "bin");
49053
+ const binDir = process.platform === "win32" ? npmPrefix : path21.join(npmPrefix, "bin");
48900
49054
  const packageBaseName = pkgName.startsWith("@") ? pkgName.split("/")[1] : pkgName;
48901
49055
  const binNames = /* @__PURE__ */ new Set([packageBaseName]);
48902
49056
  if (pkgName === "@adhdev/daemon-standalone") {
@@ -48904,25 +49058,25 @@ Run 'adhdev doctor' for detailed diagnostics.`
48904
49058
  }
48905
49059
  if (pkgName.startsWith("@")) {
48906
49060
  const [scope, name] = pkgName.split("/");
48907
- const scopeDir = path20.join(npmRoot, scope);
49061
+ const scopeDir = path21.join(npmRoot, scope);
48908
49062
  if (!fs9.existsSync(scopeDir)) return;
48909
49063
  for (const entry of fs9.readdirSync(scopeDir)) {
48910
49064
  if (!entry.startsWith(`.${name}-`)) continue;
48911
- fs9.rmSync(path20.join(scopeDir, entry), { recursive: true, force: true });
48912
- appendUpgradeLog(`Removed stale scoped staging dir: ${path20.join(scopeDir, entry)}`);
49065
+ fs9.rmSync(path21.join(scopeDir, entry), { recursive: true, force: true });
49066
+ appendUpgradeLog(`Removed stale scoped staging dir: ${path21.join(scopeDir, entry)}`);
48913
49067
  }
48914
49068
  } else {
48915
49069
  for (const entry of fs9.readdirSync(npmRoot)) {
48916
49070
  if (!entry.startsWith(`.${pkgName}-`)) continue;
48917
- fs9.rmSync(path20.join(npmRoot, entry), { recursive: true, force: true });
48918
- appendUpgradeLog(`Removed stale staging dir: ${path20.join(npmRoot, entry)}`);
49071
+ fs9.rmSync(path21.join(npmRoot, entry), { recursive: true, force: true });
49072
+ appendUpgradeLog(`Removed stale staging dir: ${path21.join(npmRoot, entry)}`);
48919
49073
  }
48920
49074
  }
48921
49075
  if (fs9.existsSync(binDir)) {
48922
49076
  for (const entry of fs9.readdirSync(binDir)) {
48923
49077
  if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
48924
- fs9.rmSync(path20.join(binDir, entry), { recursive: true, force: true });
48925
- appendUpgradeLog(`Removed stale bin staging entry: ${path20.join(binDir, entry)}`);
49078
+ fs9.rmSync(path21.join(binDir, entry), { recursive: true, force: true });
49079
+ appendUpgradeLog(`Removed stale bin staging entry: ${path21.join(binDir, entry)}`);
48926
49080
  }
48927
49081
  }
48928
49082
  }
@@ -49119,6 +49273,40 @@ Run 'adhdev doctor' for detailed diagnostics.`
49119
49273
  constructor(deps) {
49120
49274
  this.deps = deps;
49121
49275
  }
49276
+ getCachedInlineMesh(meshId, inlineMesh) {
49277
+ if (inlineMesh && typeof inlineMesh === "object") {
49278
+ this.inlineMeshCache.set(meshId, inlineMesh);
49279
+ return inlineMesh;
49280
+ }
49281
+ return this.inlineMeshCache.get(meshId);
49282
+ }
49283
+ async getMeshForCommand(meshId, inlineMesh) {
49284
+ try {
49285
+ const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
49286
+ const mesh = getMesh3(meshId);
49287
+ if (mesh) return { mesh, inline: false };
49288
+ } catch {
49289
+ }
49290
+ const cached2 = this.getCachedInlineMesh(meshId, inlineMesh);
49291
+ return cached2 ? { mesh: cached2, inline: true } : null;
49292
+ }
49293
+ updateInlineMeshNode(meshId, mesh, node) {
49294
+ if (!mesh || !Array.isArray(mesh.nodes) || !node?.id) return;
49295
+ const idx = mesh.nodes.findIndex((entry) => entry?.id === node.id || entry?.nodeId === node.id);
49296
+ if (idx >= 0) mesh.nodes[idx] = node;
49297
+ else mesh.nodes.push(node);
49298
+ mesh.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
49299
+ this.inlineMeshCache.set(meshId, mesh);
49300
+ }
49301
+ removeInlineMeshNode(meshId, mesh, nodeId) {
49302
+ if (!mesh || !Array.isArray(mesh.nodes)) return false;
49303
+ const idx = mesh.nodes.findIndex((entry) => entry?.id === nodeId || entry?.nodeId === nodeId);
49304
+ if (idx === -1) return false;
49305
+ mesh.nodes.splice(idx, 1);
49306
+ mesh.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
49307
+ this.inlineMeshCache.set(meshId, mesh);
49308
+ return true;
49309
+ }
49122
49310
  async traceSessionHostAction(action, args, run, summarizeResult) {
49123
49311
  const interactionId = typeof args?._interactionId === "string" ? args._interactionId : void 0;
49124
49312
  const sessionId = typeof args?.sessionId === "string" ? args.sessionId : void 0;
@@ -49818,13 +50006,94 @@ Run 'adhdev doctor' for detailed diagnostics.`
49818
50006
  const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
49819
50007
  if (!meshId || !nodeId) return { success: false, error: "meshId and nodeId required" };
49820
50008
  try {
49821
- const { removeNode: removeNode3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
49822
- const removed = removeNode3(meshId, nodeId);
50009
+ const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh);
50010
+ const mesh = meshRecord?.mesh;
50011
+ const node = mesh?.nodes?.find((n) => n.id === nodeId || n.nodeId === nodeId);
50012
+ if (node?.isLocalWorktree && node.workspace) {
50013
+ try {
50014
+ const sourceNode = node.clonedFromNodeId ? mesh?.nodes.find((n) => n.id === node.clonedFromNodeId || n.nodeId === node.clonedFromNodeId) : mesh?.nodes.find((n) => !n.isLocalWorktree);
50015
+ const repoRoot = sourceNode?.repoRoot || sourceNode?.workspace;
50016
+ if (repoRoot) {
50017
+ const { removeWorktree: removeWorktree2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
50018
+ await removeWorktree2(repoRoot, node.workspace);
50019
+ }
50020
+ } catch (e) {
50021
+ LOG2.warn("MeshNode", `Worktree cleanup failed for ${nodeId}: ${e.message}`);
50022
+ }
50023
+ }
50024
+ let removed = false;
50025
+ if (meshRecord?.inline) {
50026
+ removed = this.removeInlineMeshNode(meshId, mesh, nodeId);
50027
+ } else {
50028
+ const { removeNode: removeNode3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
50029
+ removed = removeNode3(meshId, nodeId);
50030
+ }
49823
50031
  return { success: true, removed };
49824
50032
  } catch (e) {
49825
50033
  return { success: false, error: e.message };
49826
50034
  }
49827
50035
  }
50036
+ case "clone_mesh_node": {
50037
+ const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
50038
+ const sourceNodeId = typeof args?.sourceNodeId === "string" ? args.sourceNodeId.trim() : "";
50039
+ const branch = typeof args?.branch === "string" ? args.branch.trim() : "";
50040
+ const baseBranch = typeof args?.baseBranch === "string" ? args.baseBranch.trim() : void 0;
50041
+ if (!meshId) return { success: false, error: "meshId required" };
50042
+ if (!sourceNodeId) return { success: false, error: "sourceNodeId required" };
50043
+ if (!branch) return { success: false, error: "branch required" };
50044
+ try {
50045
+ const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh);
50046
+ const mesh = meshRecord?.mesh;
50047
+ if (!mesh) return { success: false, error: "Mesh not found" };
50048
+ const sourceNode = mesh.nodes?.find((n) => n.id === sourceNodeId || n.nodeId === sourceNodeId);
50049
+ if (!sourceNode) return { success: false, error: `Source node '${sourceNodeId}' not found in mesh` };
50050
+ const repoRoot = sourceNode.repoRoot || sourceNode.workspace;
50051
+ const { createWorktree: createWorktree2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
50052
+ const result = await createWorktree2({
50053
+ repoRoot,
50054
+ branch,
50055
+ baseBranch,
50056
+ meshName: mesh.name
50057
+ });
50058
+ let node;
50059
+ if (meshRecord.inline) {
50060
+ const { randomUUID: randomUUID8 } = await import("crypto");
50061
+ node = {
50062
+ id: `node_${randomUUID8().replace(/-/g, "")}`,
50063
+ workspace: result.worktreePath,
50064
+ repoRoot: result.worktreePath,
50065
+ daemonId: sourceNode.daemonId,
50066
+ userOverrides: { ...sourceNode.userOverrides || {} },
50067
+ policy: { ...sourceNode.policy || {} },
50068
+ isLocalWorktree: true,
50069
+ worktreeBranch: result.branch,
50070
+ clonedFromNodeId: sourceNodeId
50071
+ };
50072
+ this.updateInlineMeshNode(meshId, mesh, node);
50073
+ } else {
50074
+ const { addNode: addNode3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
50075
+ node = addNode3(meshId, {
50076
+ workspace: result.worktreePath,
50077
+ repoRoot: result.worktreePath,
50078
+ daemonId: sourceNode.daemonId,
50079
+ userOverrides: { ...sourceNode.userOverrides || {} },
50080
+ isLocalWorktree: true,
50081
+ worktreeBranch: result.branch,
50082
+ clonedFromNodeId: sourceNodeId,
50083
+ policy: { ...sourceNode.policy || {} }
50084
+ });
50085
+ if (!node) return { success: false, error: "Failed to register worktree node" };
50086
+ }
50087
+ return {
50088
+ success: true,
50089
+ node,
50090
+ worktreePath: result.worktreePath,
50091
+ branch: result.branch
50092
+ };
50093
+ } catch (e) {
50094
+ return { success: false, error: e.message };
50095
+ }
50096
+ }
49828
50097
  // ─── Mesh Coordinator Launch ───
49829
50098
  case "launch_mesh_coordinator": {
49830
50099
  const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
@@ -49893,9 +50162,24 @@ Run 'adhdev doctor' for detailed diagnostics.`
49893
50162
  workspace
49894
50163
  };
49895
50164
  }
49896
- const { existsSync: existsSync22, readFileSync: readFileSync15, writeFileSync: writeFileSync12, copyFileSync: copyFileSync3 } = await import("fs");
50165
+ let systemPrompt = "";
50166
+ try {
50167
+ systemPrompt = buildCoordinatorSystemPrompt2({ mesh, coordinatorCliType: cliType });
50168
+ } catch (error48) {
50169
+ const message = error48?.message || String(error48);
50170
+ LOG2.error("MeshCoordinator", `Failed to build coordinator prompt: ${message}`);
50171
+ return {
50172
+ success: false,
50173
+ code: "mesh_coordinator_prompt_failed",
50174
+ error: `Failed to build Repo Mesh coordinator prompt: ${message}`,
50175
+ meshId,
50176
+ cliType,
50177
+ workspace
50178
+ };
50179
+ }
50180
+ const { existsSync: existsSync23, readFileSync: readFileSync15, writeFileSync: writeFileSync12, copyFileSync: copyFileSync3 } = await import("fs");
49897
50181
  const mcpConfigPath = coordinatorSetup.configPath;
49898
- const hadExistingMcpConfig = existsSync22(mcpConfigPath);
50182
+ const hadExistingMcpConfig = existsSync23(mcpConfigPath);
49899
50183
  let existingMcpConfig = {};
49900
50184
  if (hadExistingMcpConfig) {
49901
50185
  try {
@@ -49923,12 +50207,6 @@ Run 'adhdev doctor' for detailed diagnostics.`
49923
50207
  };
49924
50208
  writeFileSync12(mcpConfigPath, JSON.stringify(mcpConfig, null, 2), "utf-8");
49925
50209
  LOG2.info("MeshCoordinator", `Wrote ${mcpConfigPath} with ${coordinatorSetup.serverName} server`);
49926
- let systemPrompt = "";
49927
- try {
49928
- systemPrompt = buildCoordinatorSystemPrompt2({ mesh });
49929
- } catch {
49930
- systemPrompt = `You are a Repo Mesh Coordinator for "${mesh.name}". Use the adhdev-mesh MCP tools (mesh_status, mesh_list_nodes, mesh_send_task, mesh_read_chat, mesh_launch_session, etc.) to orchestrate work across ${mesh.nodes.length} node(s).`;
49931
- }
49932
50210
  const cliArgs = [];
49933
50211
  if (systemPrompt) {
49934
50212
  cliArgs.push("--append-system-prompt", systemPrompt);
@@ -51578,11 +51856,11 @@ Run 'adhdev doctor' for detailed diagnostics.`
51578
51856
  }
51579
51857
  };
51580
51858
  var fs11 = __toESM2(require("fs"));
51581
- var path21 = __toESM2(require("path"));
51859
+ var path222 = __toESM2(require("path"));
51582
51860
  var os19 = __toESM2(require("os"));
51583
51861
  var import_child_process10 = require("child_process");
51584
51862
  var import_os3 = require("os");
51585
- var ARCHIVE_PATH = path21.join(os19.homedir(), ".adhdev", "version-history.json");
51863
+ var ARCHIVE_PATH = path222.join(os19.homedir(), ".adhdev", "version-history.json");
51586
51864
  var MAX_ENTRIES_PER_PROVIDER = 20;
51587
51865
  var VersionArchive = class {
51588
51866
  history = {};
@@ -51629,7 +51907,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
51629
51907
  }
51630
51908
  save() {
51631
51909
  try {
51632
- fs11.mkdirSync(path21.dirname(ARCHIVE_PATH), { recursive: true });
51910
+ fs11.mkdirSync(path222.dirname(ARCHIVE_PATH), { recursive: true });
51633
51911
  fs11.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
51634
51912
  } catch {
51635
51913
  }
@@ -51686,7 +51964,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
51686
51964
  for (const p of paths) {
51687
51965
  if (p.includes("*")) {
51688
51966
  const home = os19.homedir();
51689
- const resolved = p.replace(/\*/g, home.split(path21.sep).pop() || "");
51967
+ const resolved = p.replace(/\*/g, home.split(path222.sep).pop() || "");
51690
51968
  if (fs11.existsSync(resolved)) return resolved;
51691
51969
  } else {
51692
51970
  if (fs11.existsSync(p)) return p;
@@ -51696,7 +51974,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
51696
51974
  }
51697
51975
  function getMacAppVersion(appPath) {
51698
51976
  if ((0, import_os3.platform)() !== "darwin" || !appPath.endsWith(".app")) return null;
51699
- const plistPath = path21.join(appPath, "Contents", "Info.plist");
51977
+ const plistPath = path222.join(appPath, "Contents", "Info.plist");
51700
51978
  if (!fs11.existsSync(plistPath)) return null;
51701
51979
  const raw = runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
51702
51980
  return raw || null;
@@ -51722,7 +52000,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
51722
52000
  const cliBin = provider.cli ? findBinary2(provider.cli) : null;
51723
52001
  let resolvedBin = cliBin;
51724
52002
  if (!resolvedBin && appPath && currentOs === "darwin") {
51725
- const bundled = path21.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
52003
+ const bundled = path222.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
51726
52004
  if (provider.cli && fs11.existsSync(bundled)) resolvedBin = bundled;
51727
52005
  }
51728
52006
  info.installed = !!(appPath || resolvedBin);
@@ -51761,7 +52039,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
51761
52039
  }
51762
52040
  var http2 = __toESM2(require("http"));
51763
52041
  var fs15 = __toESM2(require("fs"));
51764
- var path25 = __toESM2(require("path"));
52042
+ var path26 = __toESM2(require("path"));
51765
52043
  init_config();
51766
52044
  function generateFiles(type, name, category, opts = {}) {
51767
52045
  const { cdpPorts, cli, processName, installPath, binary, extensionId, version: version2 = "0.1" } = opts;
@@ -52106,7 +52384,7 @@ async (params) => {
52106
52384
  }
52107
52385
  init_logger();
52108
52386
  var fs12 = __toESM2(require("fs"));
52109
- var path222 = __toESM2(require("path"));
52387
+ var path232 = __toESM2(require("path"));
52110
52388
  init_logger();
52111
52389
  async function handleCdpEvaluate(ctx, req, res) {
52112
52390
  const body = await ctx.readBody(req);
@@ -52285,17 +52563,17 @@ async (params) => {
52285
52563
  return;
52286
52564
  }
52287
52565
  let scriptsPath = "";
52288
- const directScripts = path222.join(dir, "scripts.js");
52566
+ const directScripts = path232.join(dir, "scripts.js");
52289
52567
  if (fs12.existsSync(directScripts)) {
52290
52568
  scriptsPath = directScripts;
52291
52569
  } else {
52292
- const scriptsDir = path222.join(dir, "scripts");
52570
+ const scriptsDir = path232.join(dir, "scripts");
52293
52571
  if (fs12.existsSync(scriptsDir)) {
52294
52572
  const versions = fs12.readdirSync(scriptsDir).filter((d) => {
52295
- return fs12.statSync(path222.join(scriptsDir, d)).isDirectory();
52573
+ return fs12.statSync(path232.join(scriptsDir, d)).isDirectory();
52296
52574
  }).sort().reverse();
52297
52575
  for (const ver of versions) {
52298
- const p = path222.join(scriptsDir, ver, "scripts.js");
52576
+ const p = path232.join(scriptsDir, ver, "scripts.js");
52299
52577
  if (fs12.existsSync(p)) {
52300
52578
  scriptsPath = p;
52301
52579
  break;
@@ -53122,7 +53400,7 @@ async (params) => {
53122
53400
  }
53123
53401
  }
53124
53402
  var fs13 = __toESM2(require("fs"));
53125
- var path232 = __toESM2(require("path"));
53403
+ var path24 = __toESM2(require("path"));
53126
53404
  function slugifyFixtureName(value) {
53127
53405
  const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
53128
53406
  return normalized || `fixture-${Date.now()}`;
@@ -53132,11 +53410,11 @@ async (params) => {
53132
53410
  if (!providerDir) {
53133
53411
  throw new Error(`Provider directory not found for '${type}'`);
53134
53412
  }
53135
- return path232.join(providerDir, "fixtures");
53413
+ return path24.join(providerDir, "fixtures");
53136
53414
  }
53137
53415
  function readCliFixture(ctx, type, name) {
53138
53416
  const fixtureDir = getCliFixtureDir(ctx, type);
53139
- const filePath = path232.join(fixtureDir, `${name}.json`);
53417
+ const filePath = path24.join(fixtureDir, `${name}.json`);
53140
53418
  if (!fs13.existsSync(filePath)) {
53141
53419
  throw new Error(`Fixture not found: ${filePath}`);
53142
53420
  }
@@ -53903,7 +54181,7 @@ async (params) => {
53903
54181
  },
53904
54182
  notes: typeof body?.notes === "string" ? body.notes : void 0
53905
54183
  };
53906
- const filePath = path232.join(fixtureDir, `${name}.json`);
54184
+ const filePath = path24.join(fixtureDir, `${name}.json`);
53907
54185
  fs13.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
53908
54186
  ctx.json(res, 200, {
53909
54187
  saved: true,
@@ -53927,7 +54205,7 @@ async (params) => {
53927
54205
  return;
53928
54206
  }
53929
54207
  const fixtures = fs13.readdirSync(fixtureDir).filter((file2) => file2.endsWith(".json")).sort((a, b2) => b2.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file2) => {
53930
- const fullPath = path232.join(fixtureDir, file2);
54208
+ const fullPath = path24.join(fixtureDir, file2);
53931
54209
  try {
53932
54210
  const raw = JSON.parse(fs13.readFileSync(fullPath, "utf-8"));
53933
54211
  return {
@@ -54061,7 +54339,7 @@ async (params) => {
54061
54339
  }
54062
54340
  }
54063
54341
  var fs14 = __toESM2(require("fs"));
54064
- var path24 = __toESM2(require("path"));
54342
+ var path25 = __toESM2(require("path"));
54065
54343
  var os20 = __toESM2(require("os"));
54066
54344
  function getAutoImplPid(ctx) {
54067
54345
  const pid = ctx.autoImplProcess?.pid;
@@ -54111,22 +54389,22 @@ async (params) => {
54111
54389
  if (!fs14.existsSync(scriptsDir)) return null;
54112
54390
  const versions = fs14.readdirSync(scriptsDir).filter((d) => {
54113
54391
  try {
54114
- return fs14.statSync(path24.join(scriptsDir, d)).isDirectory();
54392
+ return fs14.statSync(path25.join(scriptsDir, d)).isDirectory();
54115
54393
  } catch {
54116
54394
  return false;
54117
54395
  }
54118
54396
  }).sort((a, b2) => b2.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
54119
54397
  if (versions.length === 0) return null;
54120
- return path24.join(scriptsDir, versions[0]);
54398
+ return path25.join(scriptsDir, versions[0]);
54121
54399
  }
54122
54400
  function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
54123
- const canonicalUserDir = path24.resolve(ctx.providerLoader.getUserProviderDir(category, type));
54124
- const desiredDir = requestedDir ? path24.resolve(requestedDir) : canonicalUserDir;
54125
- const upstreamRoot = path24.resolve(ctx.providerLoader.getUpstreamDir());
54126
- if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path24.sep}`)) {
54401
+ const canonicalUserDir = path25.resolve(ctx.providerLoader.getUserProviderDir(category, type));
54402
+ const desiredDir = requestedDir ? path25.resolve(requestedDir) : canonicalUserDir;
54403
+ const upstreamRoot = path25.resolve(ctx.providerLoader.getUpstreamDir());
54404
+ if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path25.sep}`)) {
54127
54405
  return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
54128
54406
  }
54129
- if (path24.basename(desiredDir) !== type) {
54407
+ if (path25.basename(desiredDir) !== type) {
54130
54408
  return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
54131
54409
  }
54132
54410
  const sourceDir = ctx.findProviderDir(type);
@@ -54134,11 +54412,11 @@ async (params) => {
54134
54412
  return { dir: null, reason: `Provider source directory not found for '${type}'` };
54135
54413
  }
54136
54414
  if (!fs14.existsSync(desiredDir)) {
54137
- fs14.mkdirSync(path24.dirname(desiredDir), { recursive: true });
54415
+ fs14.mkdirSync(path25.dirname(desiredDir), { recursive: true });
54138
54416
  fs14.cpSync(sourceDir, desiredDir, { recursive: true });
54139
54417
  ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
54140
54418
  }
54141
- const providerJson = path24.join(desiredDir, "provider.json");
54419
+ const providerJson = path25.join(desiredDir, "provider.json");
54142
54420
  if (!fs14.existsSync(providerJson)) {
54143
54421
  return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
54144
54422
  }
@@ -54149,13 +54427,13 @@ async (params) => {
54149
54427
  const refDir = ctx.findProviderDir(referenceType);
54150
54428
  if (!refDir || !fs14.existsSync(refDir)) return {};
54151
54429
  const referenceScripts = {};
54152
- const scriptsDir = path24.join(refDir, "scripts");
54430
+ const scriptsDir = path25.join(refDir, "scripts");
54153
54431
  const latestDir = getLatestScriptVersionDir(scriptsDir);
54154
54432
  if (!latestDir) return referenceScripts;
54155
54433
  for (const file2 of fs14.readdirSync(latestDir)) {
54156
54434
  if (!file2.endsWith(".js")) continue;
54157
54435
  try {
54158
- referenceScripts[file2] = fs14.readFileSync(path24.join(latestDir, file2), "utf-8");
54436
+ referenceScripts[file2] = fs14.readFileSync(path25.join(latestDir, file2), "utf-8");
54159
54437
  } catch {
54160
54438
  }
54161
54439
  }
@@ -54263,9 +54541,9 @@ async (params) => {
54263
54541
  });
54264
54542
  const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
54265
54543
  const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
54266
- const tmpDir = path24.join(os20.tmpdir(), "adhdev-autoimpl");
54544
+ const tmpDir = path25.join(os20.tmpdir(), "adhdev-autoimpl");
54267
54545
  if (!fs14.existsSync(tmpDir)) fs14.mkdirSync(tmpDir, { recursive: true });
54268
- const promptFile = path24.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
54546
+ const promptFile = path25.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
54269
54547
  fs14.writeFileSync(promptFile, prompt, "utf-8");
54270
54548
  ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
54271
54549
  const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
@@ -54697,7 +54975,7 @@ async (params) => {
54697
54975
  setMode: "set_mode.js"
54698
54976
  };
54699
54977
  const targetFileNames = new Set(functions.map((fn2) => funcToFile[fn2]).filter(Boolean));
54700
- const scriptsDir = path24.join(providerDir, "scripts");
54978
+ const scriptsDir = path25.join(providerDir, "scripts");
54701
54979
  const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
54702
54980
  if (latestScriptsDir) {
54703
54981
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -54708,7 +54986,7 @@ async (params) => {
54708
54986
  for (const file2 of fs14.readdirSync(latestScriptsDir)) {
54709
54987
  if (file2.endsWith(".js") && targetFileNames.has(file2)) {
54710
54988
  try {
54711
- const content = fs14.readFileSync(path24.join(latestScriptsDir, file2), "utf-8");
54989
+ const content = fs14.readFileSync(path25.join(latestScriptsDir, file2), "utf-8");
54712
54990
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
54713
54991
  lines.push("```javascript");
54714
54992
  lines.push(content);
@@ -54725,7 +55003,7 @@ async (params) => {
54725
55003
  lines.push("");
54726
55004
  for (const file2 of refFiles) {
54727
55005
  try {
54728
- const content = fs14.readFileSync(path24.join(latestScriptsDir, file2), "utf-8");
55006
+ const content = fs14.readFileSync(path25.join(latestScriptsDir, file2), "utf-8");
54729
55007
  lines.push(`### \`${file2}\` \u{1F512}`);
54730
55008
  lines.push("```javascript");
54731
55009
  lines.push(content);
@@ -54766,10 +55044,10 @@ async (params) => {
54766
55044
  lines.push("");
54767
55045
  }
54768
55046
  }
54769
- const docsDir = path24.join(providerDir, "../../docs");
55047
+ const docsDir = path25.join(providerDir, "../../docs");
54770
55048
  const loadGuide = (name) => {
54771
55049
  try {
54772
- const p = path24.join(docsDir, name);
55050
+ const p = path25.join(docsDir, name);
54773
55051
  if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
54774
55052
  } catch {
54775
55053
  }
@@ -55006,7 +55284,7 @@ async (params) => {
55006
55284
  parseApproval: "parse_approval.js"
55007
55285
  };
55008
55286
  const targetFileNames = new Set(functions.map((fn2) => funcToFile[fn2]).filter(Boolean));
55009
- const scriptsDir = path24.join(providerDir, "scripts");
55287
+ const scriptsDir = path25.join(providerDir, "scripts");
55010
55288
  const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
55011
55289
  if (latestScriptsDir) {
55012
55290
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -55018,7 +55296,7 @@ async (params) => {
55018
55296
  if (!file2.endsWith(".js")) continue;
55019
55297
  if (!targetFileNames.has(file2)) continue;
55020
55298
  try {
55021
- const content = fs14.readFileSync(path24.join(latestScriptsDir, file2), "utf-8");
55299
+ const content = fs14.readFileSync(path25.join(latestScriptsDir, file2), "utf-8");
55022
55300
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
55023
55301
  lines.push("```javascript");
55024
55302
  lines.push(content);
@@ -55034,7 +55312,7 @@ async (params) => {
55034
55312
  lines.push("");
55035
55313
  for (const file2 of refFiles) {
55036
55314
  try {
55037
- const content = fs14.readFileSync(path24.join(latestScriptsDir, file2), "utf-8");
55315
+ const content = fs14.readFileSync(path25.join(latestScriptsDir, file2), "utf-8");
55038
55316
  lines.push(`### \`${file2}\` \u{1F512}`);
55039
55317
  lines.push("```javascript");
55040
55318
  lines.push(content);
@@ -55067,10 +55345,10 @@ async (params) => {
55067
55345
  lines.push("");
55068
55346
  }
55069
55347
  }
55070
- const docsDir = path24.join(providerDir, "../../docs");
55348
+ const docsDir = path25.join(providerDir, "../../docs");
55071
55349
  const loadGuide = (name) => {
55072
55350
  try {
55073
- const p = path24.join(docsDir, name);
55351
+ const p = path25.join(docsDir, name);
55074
55352
  if (fs14.existsSync(p)) return fs14.readFileSync(p, "utf-8");
55075
55353
  } catch {
55076
55354
  }
@@ -55515,8 +55793,8 @@ data: ${JSON.stringify(msg.data)}
55515
55793
  }
55516
55794
  getEndpointList() {
55517
55795
  return this.routes.map((r) => {
55518
- const path26 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
55519
- return `${r.method.padEnd(5)} ${path26}`;
55796
+ const path27 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
55797
+ return `${r.method.padEnd(5)} ${path27}`;
55520
55798
  });
55521
55799
  }
55522
55800
  async start(port = DEV_SERVER_PORT) {
@@ -55804,12 +56082,12 @@ data: ${JSON.stringify(msg.data)}
55804
56082
  // ─── DevConsole SPA ───
55805
56083
  getConsoleDistDir() {
55806
56084
  const candidates = [
55807
- path25.resolve(__dirname, "../../web-devconsole/dist"),
55808
- path25.resolve(__dirname, "../../../web-devconsole/dist"),
55809
- path25.join(process.cwd(), "packages/web-devconsole/dist")
56085
+ path26.resolve(__dirname, "../../web-devconsole/dist"),
56086
+ path26.resolve(__dirname, "../../../web-devconsole/dist"),
56087
+ path26.join(process.cwd(), "packages/web-devconsole/dist")
55810
56088
  ];
55811
56089
  for (const dir of candidates) {
55812
- if (fs15.existsSync(path25.join(dir, "index.html"))) return dir;
56090
+ if (fs15.existsSync(path26.join(dir, "index.html"))) return dir;
55813
56091
  }
55814
56092
  return null;
55815
56093
  }
@@ -55819,7 +56097,7 @@ data: ${JSON.stringify(msg.data)}
55819
56097
  this.json(res, 500, { error: "DevConsole not found. Run: npm run build -w packages/web-devconsole" });
55820
56098
  return;
55821
56099
  }
55822
- const htmlPath = path25.join(distDir, "index.html");
56100
+ const htmlPath = path26.join(distDir, "index.html");
55823
56101
  try {
55824
56102
  const html = fs15.readFileSync(htmlPath, "utf-8");
55825
56103
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
@@ -55844,15 +56122,15 @@ data: ${JSON.stringify(msg.data)}
55844
56122
  this.json(res, 404, { error: "Not found" });
55845
56123
  return;
55846
56124
  }
55847
- const safePath = path25.normalize(pathname).replace(/^\.\.\//, "");
55848
- const filePath = path25.join(distDir, safePath);
56125
+ const safePath = path26.normalize(pathname).replace(/^\.\.\//, "");
56126
+ const filePath = path26.join(distDir, safePath);
55849
56127
  if (!filePath.startsWith(distDir)) {
55850
56128
  this.json(res, 403, { error: "Forbidden" });
55851
56129
  return;
55852
56130
  }
55853
56131
  try {
55854
56132
  const content = fs15.readFileSync(filePath);
55855
- const ext = path25.extname(filePath);
56133
+ const ext = path26.extname(filePath);
55856
56134
  const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
55857
56135
  res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
55858
56136
  res.end(content);
@@ -55965,9 +56243,9 @@ data: ${JSON.stringify(msg.data)}
55965
56243
  const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
55966
56244
  if (entry.isDirectory()) {
55967
56245
  files.push({ path: rel, size: 0, type: "dir" });
55968
- scan(path25.join(d, entry.name), rel);
56246
+ scan(path26.join(d, entry.name), rel);
55969
56247
  } else {
55970
- const stat2 = fs15.statSync(path25.join(d, entry.name));
56248
+ const stat2 = fs15.statSync(path26.join(d, entry.name));
55971
56249
  files.push({ path: rel, size: stat2.size, type: "file" });
55972
56250
  }
55973
56251
  }
@@ -55990,7 +56268,7 @@ data: ${JSON.stringify(msg.data)}
55990
56268
  this.json(res, 404, { error: `Provider directory not found: ${type}` });
55991
56269
  return;
55992
56270
  }
55993
- const fullPath = path25.resolve(dir, path25.normalize(filePath));
56271
+ const fullPath = path26.resolve(dir, path26.normalize(filePath));
55994
56272
  if (!fullPath.startsWith(dir)) {
55995
56273
  this.json(res, 403, { error: "Forbidden" });
55996
56274
  return;
@@ -56015,14 +56293,14 @@ data: ${JSON.stringify(msg.data)}
56015
56293
  this.json(res, 404, { error: `Provider directory not found: ${type}` });
56016
56294
  return;
56017
56295
  }
56018
- const fullPath = path25.resolve(dir, path25.normalize(filePath));
56296
+ const fullPath = path26.resolve(dir, path26.normalize(filePath));
56019
56297
  if (!fullPath.startsWith(dir)) {
56020
56298
  this.json(res, 403, { error: "Forbidden" });
56021
56299
  return;
56022
56300
  }
56023
56301
  try {
56024
56302
  if (fs15.existsSync(fullPath)) fs15.copyFileSync(fullPath, fullPath + ".bak");
56025
- fs15.mkdirSync(path25.dirname(fullPath), { recursive: true });
56303
+ fs15.mkdirSync(path26.dirname(fullPath), { recursive: true });
56026
56304
  fs15.writeFileSync(fullPath, content, "utf-8");
56027
56305
  this.log(`File saved: ${fullPath} (${content.length} chars)`);
56028
56306
  this.providerLoader.reload();
@@ -56039,7 +56317,7 @@ data: ${JSON.stringify(msg.data)}
56039
56317
  return;
56040
56318
  }
56041
56319
  for (const name of ["scripts.js", "provider.json"]) {
56042
- const p = path25.join(dir, name);
56320
+ const p = path26.join(dir, name);
56043
56321
  if (fs15.existsSync(p)) {
56044
56322
  const source = fs15.readFileSync(p, "utf-8");
56045
56323
  this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
@@ -56060,8 +56338,8 @@ data: ${JSON.stringify(msg.data)}
56060
56338
  this.json(res, 404, { error: `Provider not found: ${type}` });
56061
56339
  return;
56062
56340
  }
56063
- const target = fs15.existsSync(path25.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
56064
- const targetPath = path25.join(dir, target);
56341
+ const target = fs15.existsSync(path26.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
56342
+ const targetPath = path26.join(dir, target);
56065
56343
  try {
56066
56344
  if (fs15.existsSync(targetPath)) fs15.copyFileSync(targetPath, targetPath + ".bak");
56067
56345
  fs15.writeFileSync(targetPath, source, "utf-8");
@@ -56208,7 +56486,7 @@ data: ${JSON.stringify(msg.data)}
56208
56486
  }
56209
56487
  let targetDir;
56210
56488
  targetDir = this.providerLoader.getUserProviderDir(category, type);
56211
- const jsonPath = path25.join(targetDir, "provider.json");
56489
+ const jsonPath = path26.join(targetDir, "provider.json");
56212
56490
  if (fs15.existsSync(jsonPath)) {
56213
56491
  this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
56214
56492
  return;
@@ -56220,8 +56498,8 @@ data: ${JSON.stringify(msg.data)}
56220
56498
  const createdFiles = ["provider.json"];
56221
56499
  if (result.files) {
56222
56500
  for (const [relPath, content] of Object.entries(result.files)) {
56223
- const fullPath = path25.join(targetDir, relPath);
56224
- fs15.mkdirSync(path25.dirname(fullPath), { recursive: true });
56501
+ const fullPath = path26.join(targetDir, relPath);
56502
+ fs15.mkdirSync(path26.dirname(fullPath), { recursive: true });
56225
56503
  fs15.writeFileSync(fullPath, content, "utf-8");
56226
56504
  createdFiles.push(relPath);
56227
56505
  }
@@ -56274,22 +56552,22 @@ data: ${JSON.stringify(msg.data)}
56274
56552
  if (!fs15.existsSync(scriptsDir)) return null;
56275
56553
  const versions = fs15.readdirSync(scriptsDir).filter((d) => {
56276
56554
  try {
56277
- return fs15.statSync(path25.join(scriptsDir, d)).isDirectory();
56555
+ return fs15.statSync(path26.join(scriptsDir, d)).isDirectory();
56278
56556
  } catch {
56279
56557
  return false;
56280
56558
  }
56281
56559
  }).sort((a, b2) => b2.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
56282
56560
  if (versions.length === 0) return null;
56283
- return path25.join(scriptsDir, versions[0]);
56561
+ return path26.join(scriptsDir, versions[0]);
56284
56562
  }
56285
56563
  resolveAutoImplWritableProviderDir(category, type, requestedDir) {
56286
- const canonicalUserDir = path25.resolve(this.providerLoader.getUserProviderDir(category, type));
56287
- const desiredDir = requestedDir ? path25.resolve(requestedDir) : canonicalUserDir;
56288
- const upstreamRoot = path25.resolve(this.providerLoader.getUpstreamDir());
56289
- if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path25.sep}`)) {
56564
+ const canonicalUserDir = path26.resolve(this.providerLoader.getUserProviderDir(category, type));
56565
+ const desiredDir = requestedDir ? path26.resolve(requestedDir) : canonicalUserDir;
56566
+ const upstreamRoot = path26.resolve(this.providerLoader.getUpstreamDir());
56567
+ if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path26.sep}`)) {
56290
56568
  return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
56291
56569
  }
56292
- if (path25.basename(desiredDir) !== type) {
56570
+ if (path26.basename(desiredDir) !== type) {
56293
56571
  return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
56294
56572
  }
56295
56573
  const sourceDir = this.findProviderDir(type);
@@ -56297,11 +56575,11 @@ data: ${JSON.stringify(msg.data)}
56297
56575
  return { dir: null, reason: `Provider source directory not found for '${type}'` };
56298
56576
  }
56299
56577
  if (!fs15.existsSync(desiredDir)) {
56300
- fs15.mkdirSync(path25.dirname(desiredDir), { recursive: true });
56578
+ fs15.mkdirSync(path26.dirname(desiredDir), { recursive: true });
56301
56579
  fs15.cpSync(sourceDir, desiredDir, { recursive: true });
56302
56580
  this.log(`Auto-implement writable copy created: ${desiredDir}`);
56303
56581
  }
56304
- const providerJson = path25.join(desiredDir, "provider.json");
56582
+ const providerJson = path26.join(desiredDir, "provider.json");
56305
56583
  if (!fs15.existsSync(providerJson)) {
56306
56584
  return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
56307
56585
  }
@@ -56337,7 +56615,7 @@ data: ${JSON.stringify(msg.data)}
56337
56615
  setMode: "set_mode.js"
56338
56616
  };
56339
56617
  const targetFileNames = new Set(functions.map((fn2) => funcToFile[fn2]).filter(Boolean));
56340
- const scriptsDir = path25.join(providerDir, "scripts");
56618
+ const scriptsDir = path26.join(providerDir, "scripts");
56341
56619
  const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
56342
56620
  if (latestScriptsDir) {
56343
56621
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -56348,7 +56626,7 @@ data: ${JSON.stringify(msg.data)}
56348
56626
  for (const file2 of fs15.readdirSync(latestScriptsDir)) {
56349
56627
  if (file2.endsWith(".js") && targetFileNames.has(file2)) {
56350
56628
  try {
56351
- const content = fs15.readFileSync(path25.join(latestScriptsDir, file2), "utf-8");
56629
+ const content = fs15.readFileSync(path26.join(latestScriptsDir, file2), "utf-8");
56352
56630
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
56353
56631
  lines.push("```javascript");
56354
56632
  lines.push(content);
@@ -56365,7 +56643,7 @@ data: ${JSON.stringify(msg.data)}
56365
56643
  lines.push("");
56366
56644
  for (const file2 of refFiles) {
56367
56645
  try {
56368
- const content = fs15.readFileSync(path25.join(latestScriptsDir, file2), "utf-8");
56646
+ const content = fs15.readFileSync(path26.join(latestScriptsDir, file2), "utf-8");
56369
56647
  lines.push(`### \`${file2}\` \u{1F512}`);
56370
56648
  lines.push("```javascript");
56371
56649
  lines.push(content);
@@ -56406,10 +56684,10 @@ data: ${JSON.stringify(msg.data)}
56406
56684
  lines.push("");
56407
56685
  }
56408
56686
  }
56409
- const docsDir = path25.join(providerDir, "../../docs");
56687
+ const docsDir = path26.join(providerDir, "../../docs");
56410
56688
  const loadGuide = (name) => {
56411
56689
  try {
56412
- const p = path25.join(docsDir, name);
56690
+ const p = path26.join(docsDir, name);
56413
56691
  if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
56414
56692
  } catch {
56415
56693
  }
@@ -56583,7 +56861,7 @@ data: ${JSON.stringify(msg.data)}
56583
56861
  parseApproval: "parse_approval.js"
56584
56862
  };
56585
56863
  const targetFileNames = new Set(functions.map((fn2) => funcToFile[fn2]).filter(Boolean));
56586
- const scriptsDir = path25.join(providerDir, "scripts");
56864
+ const scriptsDir = path26.join(providerDir, "scripts");
56587
56865
  const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
56588
56866
  if (latestScriptsDir) {
56589
56867
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -56595,7 +56873,7 @@ data: ${JSON.stringify(msg.data)}
56595
56873
  if (!file2.endsWith(".js")) continue;
56596
56874
  if (!targetFileNames.has(file2)) continue;
56597
56875
  try {
56598
- const content = fs15.readFileSync(path25.join(latestScriptsDir, file2), "utf-8");
56876
+ const content = fs15.readFileSync(path26.join(latestScriptsDir, file2), "utf-8");
56599
56877
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
56600
56878
  lines.push("```javascript");
56601
56879
  lines.push(content);
@@ -56611,7 +56889,7 @@ data: ${JSON.stringify(msg.data)}
56611
56889
  lines.push("");
56612
56890
  for (const file2 of refFiles) {
56613
56891
  try {
56614
- const content = fs15.readFileSync(path25.join(latestScriptsDir, file2), "utf-8");
56892
+ const content = fs15.readFileSync(path26.join(latestScriptsDir, file2), "utf-8");
56615
56893
  lines.push(`### \`${file2}\` \u{1F512}`);
56616
56894
  lines.push("```javascript");
56617
56895
  lines.push(content);
@@ -56644,10 +56922,10 @@ data: ${JSON.stringify(msg.data)}
56644
56922
  lines.push("");
56645
56923
  }
56646
56924
  }
56647
- const docsDir = path25.join(providerDir, "../../docs");
56925
+ const docsDir = path26.join(providerDir, "../../docs");
56648
56926
  const loadGuide = (name) => {
56649
56927
  try {
56650
- const p = path25.join(docsDir, name);
56928
+ const p = path26.join(docsDir, name);
56651
56929
  if (fs15.existsSync(p)) return fs15.readFileSync(p, "utf-8");
56652
56930
  } catch {
56653
56931
  }