@adhdev/daemon-core 0.9.82-rc.323 → 0.9.82-rc.324

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -308,10 +308,10 @@ function readInjected(value) {
308
308
  }
309
309
  function getDaemonBuildInfo() {
310
310
  if (cached) return cached;
311
- const commit = readInjected(true ? "c19690a16292dbcb1ed5ff5458b94596fce46e38" : void 0) ?? "unknown";
312
- const commitShort = readInjected(true ? "c19690a1" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
313
- const version = readInjected(true ? "0.9.82-rc.323" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
314
- const builtAt = readInjected(true ? "2026-06-19T06:24:49.522Z" : void 0);
311
+ const commit = readInjected(true ? "a0aeebdac30d9abea5b46e3f2618f864bbff19d0" : void 0) ?? "unknown";
312
+ const commitShort = readInjected(true ? "a0aeebda" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
313
+ const version = readInjected(true ? "0.9.82-rc.324" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
314
+ const builtAt = readInjected(true ? "2026-06-19T07:37:54.347Z" : void 0);
315
315
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
316
316
  return cached;
317
317
  }
@@ -2943,26 +2943,113 @@ __export(mesh_work_queue_exports, {
2943
2943
  validateMeshTaskModeRequest: () => validateMeshTaskModeRequest
2944
2944
  });
2945
2945
  import { randomUUID as randomUUID5 } from "crypto";
2946
+ function hasNegationBefore(text, matchIndex) {
2947
+ const before = text.slice(0, matchIndex);
2948
+ const clauseStart = Math.max(
2949
+ before.lastIndexOf("\n"),
2950
+ before.lastIndexOf(". "),
2951
+ before.lastIndexOf("! "),
2952
+ before.lastIndexOf("? "),
2953
+ before.lastIndexOf(";")
2954
+ );
2955
+ const clause = before.slice(clauseStart + 1);
2956
+ const lower = clause.toLowerCase();
2957
+ const tokens = clause.split(/\s+/).filter(Boolean);
2958
+ const windowTokens = tokens.slice(Math.max(0, tokens.length - NEGATION_WINDOW_TOKENS));
2959
+ const windowText = windowTokens.join(" ").toLowerCase();
2960
+ for (const cue of NEGATION_CUES) {
2961
+ const c = cue.toLowerCase();
2962
+ if (/[^\x00-\x7f]/.test(c)) {
2963
+ if (lower.includes(c)) return true;
2964
+ } else if (windowText.includes(c)) {
2965
+ return true;
2966
+ }
2967
+ }
2968
+ return false;
2969
+ }
2970
+ function hasTrailingNegation(text, matchEnd) {
2971
+ const after = text.slice(matchEnd);
2972
+ const clauseEnd = (() => {
2973
+ const stops = [after.indexOf("\n"), after.indexOf(". "), after.indexOf("; ")].filter((i) => i >= 0);
2974
+ return stops.length ? Math.min(...stops) : after.length;
2975
+ })();
2976
+ const clause = after.slice(0, clauseEnd).toLowerCase();
2977
+ for (const cue of NEGATION_CUES) {
2978
+ const c = cue.toLowerCase();
2979
+ if (/[^\x00-\x7f]/.test(c) && clause.includes(c)) return true;
2980
+ }
2981
+ return false;
2982
+ }
2983
+ function isMutationKeywordInCommandContext(text, matchStart, matchEnd) {
2984
+ if (isInsideBackticksOrFence(text, matchStart, matchEnd)) return true;
2985
+ const lineStart = text.lastIndexOf("\n", matchStart - 1) + 1;
2986
+ const linePrefix = text.slice(lineStart, matchStart);
2987
+ if (/^\s*[$>]\s/.test(text.slice(lineStart))) return true;
2988
+ if (/^\s*$/.test(linePrefix)) return true;
2989
+ if (/(?:&&|\|\||\||;)\s*$/.test(linePrefix)) return true;
2990
+ if (/(?:^|[\s,])(?:then|run|first)\s+$/i.test(linePrefix)) return true;
2991
+ if (/,\s*$/.test(linePrefix)) return true;
2992
+ return false;
2993
+ }
2994
+ function isInsideBackticksOrFence(text, matchStart, matchEnd) {
2995
+ const fenceRe = /```/g;
2996
+ let fenceCount = 0;
2997
+ let m;
2998
+ while ((m = fenceRe.exec(text)) !== null) {
2999
+ if (m.index >= matchStart) break;
3000
+ fenceCount++;
3001
+ }
3002
+ if (fenceCount % 2 === 1) return true;
3003
+ let inlineCount = 0;
3004
+ for (let i = 0; i < matchStart; i++) {
3005
+ if (text[i] === "`") {
3006
+ if (text[i + 1] === "`" && text[i + 2] === "`") {
3007
+ i += 2;
3008
+ continue;
3009
+ }
3010
+ inlineCount++;
3011
+ }
3012
+ }
3013
+ return inlineCount % 2 === 1;
3014
+ }
3015
+ function isRealMutationMatch(text, matchStart, matchEnd) {
3016
+ if (hasNegationBefore(text, matchStart)) return false;
3017
+ if (hasTrailingNegation(text, matchEnd)) return false;
3018
+ return isMutationKeywordInCommandContext(text, matchStart, matchEnd);
3019
+ }
3020
+ function patternHasRealMutation(pattern, text) {
3021
+ const re = new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : pattern.flags + "g");
3022
+ let match;
3023
+ while ((match = re.exec(text)) !== null) {
3024
+ if (isRealMutationMatch(text, match.index, match.index + match[0].length)) return true;
3025
+ if (match.index === re.lastIndex) re.lastIndex++;
3026
+ }
3027
+ return false;
3028
+ }
2946
3029
  function detectGitMutation(message) {
2947
3030
  const re = /\bgit\s+([a-z][a-z0-9-]*)/gi;
2948
3031
  let match;
2949
3032
  while ((match = re.exec(message)) !== null) {
2950
3033
  const sub = match[1].toLowerCase();
2951
- if (GIT_MUTATION_SUBCOMMANDS.has(sub)) return true;
3034
+ const isReal = () => isRealMutationMatch(message, match.index, match.index + match[0].length);
3035
+ if (GIT_MUTATION_SUBCOMMANDS.has(sub)) {
3036
+ if (isReal()) return true;
3037
+ continue;
3038
+ }
2952
3039
  if (sub === "stash") {
2953
3040
  const after = message.slice(re.lastIndex).match(/^\s+([a-z][a-z0-9-]*)/i);
2954
3041
  const next = after ? after[1].toLowerCase() : "";
2955
- if (!GIT_STASH_READONLY_SUBCOMMANDS.has(next)) return true;
3042
+ if (!GIT_STASH_READONLY_SUBCOMMANDS.has(next) && isReal()) return true;
2956
3043
  } else if (sub === "checkout") {
2957
- return true;
3044
+ if (isReal()) return true;
2958
3045
  } else if (sub === "submodule") {
2959
3046
  const after = message.slice(re.lastIndex).match(/^\s+([a-z][a-z0-9-]*)/i);
2960
3047
  const next = after ? after[1].toLowerCase() : "";
2961
- if (next === "update" || next === "add" || next === "sync" || next === "deinit") return true;
3048
+ if ((next === "update" || next === "add" || next === "sync" || next === "deinit") && isReal()) return true;
2962
3049
  } else if (sub === "worktree") {
2963
3050
  const after = message.slice(re.lastIndex).match(/^\s+([a-z][a-z0-9-]*)/i);
2964
3051
  const next = after ? after[1].toLowerCase() : "";
2965
- if (next === "add" || next === "remove" || next === "move" || next === "prune") return true;
3052
+ if ((next === "add" || next === "remove" || next === "move" || next === "prune") && isReal()) return true;
2966
3053
  }
2967
3054
  }
2968
3055
  return false;
@@ -2981,7 +3068,7 @@ function validateMeshTaskModeRequest(mode, message) {
2981
3068
  return { valid: true, taskMode, violations: [] };
2982
3069
  }
2983
3070
  const text = message || "";
2984
- const violations = LIVE_DEBUG_READONLY_FORBIDDEN.filter((rule) => rule.pattern.test(text)).map((rule) => rule.label);
3071
+ const violations = LIVE_DEBUG_READONLY_FORBIDDEN.filter((rule) => patternHasRealMutation(rule.pattern, text)).map((rule) => rule.label);
2985
3072
  if (detectGitMutation(text)) {
2986
3073
  violations.push("git_mutation");
2987
3074
  }
@@ -3011,13 +3098,21 @@ function firstProviderPriority(policy) {
3011
3098
  if (!Array.isArray(raw)) return void 0;
3012
3099
  return raw.find((type) => typeof type === "string" && type.trim())?.trim();
3013
3100
  }
3101
+ function readNodeOverride(node, key) {
3102
+ const overrides = node?.userOverrides;
3103
+ if (!overrides || typeof overrides !== "object" || Array.isArray(overrides)) return null;
3104
+ const value = overrides[key];
3105
+ return typeof value === "string" && value.trim() ? value.trim() : null;
3106
+ }
3014
3107
  function buildMeshNodeCapabilityTags(node, providerType) {
3015
3108
  const provider = typeof providerType === "string" && providerType.trim() ? providerType.trim() : firstProviderPriority(node?.policy);
3016
3109
  const worktreeBranch = typeof node?.worktreeBranch === "string" && node.worktreeBranch.trim() ? node.worktreeBranch.trim() : null;
3110
+ const os30 = readNodeOverride(node, "platform") ?? process.platform;
3111
+ const arch2 = readNodeOverride(node, "arch") ?? process.arch;
3017
3112
  return normalizeMeshCapabilityTags([
3018
3113
  ...Array.isArray(node?.capabilities) ? node.capabilities : [],
3019
- `os=${process.platform}`,
3020
- `arch=${process.arch}`,
3114
+ `os=${os30}`,
3115
+ `arch=${arch2}`,
3021
3116
  ...provider ? [`provider=${provider}`] : [],
3022
3117
  // Worktree nodes automatically expose a "worktree=<branch>" tag so that
3023
3118
  // mesh_enqueue_task with required_tags: ["worktree=<branch>"] routes
@@ -3374,7 +3469,7 @@ function recordMeshToolCall(opts) {
3374
3469
  return { rateLimitExceeded: false, callsInWindow: 0, advisory: null };
3375
3470
  }
3376
3471
  }
3377
- var ACTIVE_MESH_QUEUE_STATUSES, HISTORICAL_MESH_QUEUE_STATUSES, MESH_TASK_MODES, LIVE_DEBUG_READONLY_FORBIDDEN, GIT_MUTATION_SUBCOMMANDS, GIT_STASH_READONLY_SUBCOMMANDS, DEPENDENCY_FAILURE_TERMINALS;
3472
+ var ACTIVE_MESH_QUEUE_STATUSES, HISTORICAL_MESH_QUEUE_STATUSES, MESH_TASK_MODES, LIVE_DEBUG_READONLY_FORBIDDEN, NEGATION_CUES, NEGATION_WINDOW_TOKENS, GIT_MUTATION_SUBCOMMANDS, GIT_STASH_READONLY_SUBCOMMANDS, DEPENDENCY_FAILURE_TERMINALS;
3378
3473
  var init_mesh_work_queue = __esm({
3379
3474
  "src/mesh/mesh-work-queue.ts"() {
3380
3475
  "use strict";
@@ -3393,6 +3488,23 @@ var init_mesh_work_queue = __esm({
3393
3488
  { label: "package_install", pattern: /\b(npm\s+(?:install|i|add|link|uninstall|remove)|yarn\s+(?:add|remove|link)|pnpm\s+(?:add|remove|link)|pip\s+install|brew\s+install|apt\s+install|cargo\s+install)\b/i },
3394
3489
  { label: "container_mutation", pattern: /\b(docker\s+(?:build|run|exec|push|tag|rmi|rm|create|start|stop|kill)|kubectl\s+(?:apply|delete|patch|replace|create|scale))\b/i }
3395
3490
  ];
3491
+ NEGATION_CUES = [
3492
+ "don't",
3493
+ "do not",
3494
+ "never",
3495
+ "avoid",
3496
+ "without",
3497
+ "no longer",
3498
+ "not",
3499
+ "forbidden",
3500
+ "\uD558\uC9C0 \uB9C8",
3501
+ "\uD558\uC9C0 \uB9C8\uC138\uC694",
3502
+ "\uB9D0 \uAC83",
3503
+ "\uAE08\uC9C0",
3504
+ "\uC5C6\uC74C",
3505
+ "\uC54A"
3506
+ ];
3507
+ NEGATION_WINDOW_TOKENS = 6;
3396
3508
  GIT_MUTATION_SUBCOMMANDS = /* @__PURE__ */ new Set([
3397
3509
  "add",
3398
3510
  "commit",
@@ -43521,6 +43633,70 @@ ${e?.stderr || ""}`
43521
43633
  };
43522
43634
  }
43523
43635
  }
43636
+ async function checkWorktreeChangesPatchEquivalentInRef(repoRoot, ref, worktreeHead) {
43637
+ const startedAt = Date.now();
43638
+ try {
43639
+ const { execFileSync: execFileSync7 } = await import("child_process");
43640
+ const git = (gitArgs) => execFileSync7("git", gitArgs, {
43641
+ cwd: repoRoot,
43642
+ encoding: "utf8",
43643
+ maxBuffer: REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES
43644
+ });
43645
+ const mergeBase = git(["merge-base", ref, worktreeHead]).trim();
43646
+ let mergedTree = "";
43647
+ try {
43648
+ mergedTree = git(["merge-tree", "--write-tree", ref, worktreeHead]).trim().split(/\s+/)[0] || "";
43649
+ } catch (mergeTreeErr) {
43650
+ const output = `${mergeTreeErr?.message || ""}
43651
+ ${mergeTreeErr?.stdout || ""}
43652
+ ${mergeTreeErr?.stderr || ""}`;
43653
+ const isSubmoduleConflict = /(submodule|160000)/i.test(output) || /Recursive merging with submodules/i.test(output);
43654
+ if (!isSubmoduleConflict) throw mergeTreeErr;
43655
+ const evaluation = evaluateGitlinkTrivialFastForward(repoRoot, ref, worktreeHead);
43656
+ if (!evaluation.trivial) {
43657
+ return {
43658
+ contained: false,
43659
+ ref,
43660
+ worktreeHead,
43661
+ mergeBase: mergeBase || void 0,
43662
+ durationMs: Date.now() - startedAt,
43663
+ error: `merge-tree submodule conflict is not a trivial fast-forward: ${evaluation.reason || "unknown"}`
43664
+ };
43665
+ }
43666
+ mergedTree = synthesizeTrivialFastForwardMergeTree(repoRoot, ref, worktreeHead, evaluation.gitlinks) || "";
43667
+ }
43668
+ if (!mergedTree) {
43669
+ return {
43670
+ contained: false,
43671
+ ref,
43672
+ worktreeHead,
43673
+ mergeBase: mergeBase || void 0,
43674
+ durationMs: Date.now() - startedAt,
43675
+ error: "could not resolve synthetic merge tree for containment check"
43676
+ };
43677
+ }
43678
+ const ffGitlinkExcludePaths = collectFastForwardGitlinkPaths(repoRoot, ref, worktreeHead);
43679
+ const residualPatchId = await computeGitPatchId(repoRoot, ref, mergedTree, ffGitlinkExcludePaths);
43680
+ const contained = residualPatchId === "";
43681
+ return {
43682
+ contained,
43683
+ ref,
43684
+ worktreeHead,
43685
+ mergeBase: mergeBase || void 0,
43686
+ mergedTree,
43687
+ residualPatchId,
43688
+ durationMs: Date.now() - startedAt
43689
+ };
43690
+ } catch (e) {
43691
+ return {
43692
+ contained: false,
43693
+ ref,
43694
+ worktreeHead,
43695
+ durationMs: Date.now() - startedAt,
43696
+ error: e?.message || String(e)
43697
+ };
43698
+ }
43699
+ }
43524
43700
  async function runMeshRefineEffectiveDiffGate(repoRoot, baseHead, branchHead) {
43525
43701
  const startedAt = Date.now();
43526
43702
  try {
@@ -44492,13 +44668,19 @@ function buildMemberJoinNode(mesh, args, fallbackDaemonId) {
44492
44668
  const workspace = typeof source?.workspace === "string" && source.workspace.trim() ? source.workspace.trim() : typeof args?.workspace === "string" && args.workspace.trim() ? args.workspace.trim() : process.cwd();
44493
44669
  if (!workspace) return null;
44494
44670
  const nodeId = typeof source?.id === "string" && source.id.trim() ? source.id.trim() : typeof source?.nodeId === "string" && source.nodeId.trim() ? source.nodeId.trim() : void 0;
44671
+ const baseOverrides = source?.userOverrides && typeof source.userOverrides === "object" && !Array.isArray(source.userOverrides) ? source.userOverrides : {};
44672
+ const userOverrides = {
44673
+ ...baseOverrides,
44674
+ ...typeof baseOverrides.platform === "string" && baseOverrides.platform.trim() ? {} : { platform: process.platform },
44675
+ ...typeof baseOverrides.arch === "string" && baseOverrides.arch.trim() ? {} : { arch: process.arch }
44676
+ };
44495
44677
  return {
44496
44678
  ...nodeId ? { id: nodeId } : {},
44497
44679
  workspace,
44498
44680
  ...typeof source?.repoRoot === "string" && source.repoRoot.trim() ? { repoRoot: source.repoRoot.trim() } : {},
44499
44681
  ...typeof source?.daemonId === "string" && source.daemonId.trim() ? { daemonId: source.daemonId.trim() } : fallbackDaemonId ? { daemonId: fallbackDaemonId } : {},
44500
44682
  ...typeof source?.machineId === "string" && source.machineId.trim() ? { machineId: source.machineId.trim() } : {},
44501
- userOverrides: source?.userOverrides && typeof source.userOverrides === "object" && !Array.isArray(source.userOverrides) ? source.userOverrides : {},
44683
+ userOverrides,
44502
44684
  policy: source?.policy && typeof source.policy === "object" && !Array.isArray(source.policy) ? source.policy : {},
44503
44685
  role: "member"
44504
44686
  };
@@ -45008,6 +45190,7 @@ var DaemonCommandRouter = class {
45008
45190
  candidateRefs.push("origin/main", "origin/master", "main", "master");
45009
45191
  const seen = /* @__PURE__ */ new Set();
45010
45192
  const checkedRefs = [];
45193
+ const resolvedRefCommits = [];
45011
45194
  for (const ref of candidateRefs) {
45012
45195
  if (!ref || seen.has(ref)) continue;
45013
45196
  seen.add(ref);
@@ -45018,12 +45201,24 @@ var DaemonCommandRouter = class {
45018
45201
  continue;
45019
45202
  }
45020
45203
  checkedRefs.push(ref);
45204
+ resolvedRefCommits.push({ ref, commit });
45021
45205
  try {
45022
45206
  await runGit3(["merge-base", "--is-ancestor", head, commit], args.repoRoot);
45023
45207
  return { allow: true, status: "merged_to_default_ref", source: "git_merge_base", ref };
45024
45208
  } catch {
45025
45209
  }
45026
45210
  }
45211
+ for (const { ref, commit } of resolvedRefCommits) {
45212
+ let containment;
45213
+ try {
45214
+ containment = await checkWorktreeChangesPatchEquivalentInRef(args.repoRoot, commit, head);
45215
+ } catch {
45216
+ continue;
45217
+ }
45218
+ if (containment.contained) {
45219
+ return { allow: true, status: "patch_equivalent_to_default_ref", source: "git_patch_equivalence", ref };
45220
+ }
45221
+ }
45027
45222
  return {
45028
45223
  allow: false,
45029
45224
  status: metadataStatus || void 0,