@mrrlin-dev/mcp 0.4.208 → 0.4.210

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.
Files changed (2) hide show
  1. package/dist/bin.cjs +107 -39
  2. package/package.json +1 -1
package/dist/bin.cjs CHANGED
@@ -89731,6 +89731,11 @@ async function runDraftSpec(ctx, input, deps) {
89731
89731
  }
89732
89732
  if (hasActiveBlocker) return skipped("blocked_by_active");
89733
89733
  }
89734
+ const draftLinkFlag = ctx.boundDraftCommit ? void 0 : process.env.MRRLIN_MCP_DRAFT_LINK_V1?.trim().toLowerCase();
89735
+ if (draftLinkFlag && draftLinkFlag !== "1" && draftLinkFlag !== "0" && draftLinkFlag !== "false") {
89736
+ return { kind: "retry", failureReason: "provider_unavailable", error: "Invalid MRRLIN_MCP_DRAFT_LINK_V1" };
89737
+ }
89738
+ const useDraftLinkV1 = draftLinkFlag === "1";
89734
89739
  const autoDeploy = task.autoDeploy ?? "off";
89735
89740
  let topology = null;
89736
89741
  let deploySkippedReason = null;
@@ -89928,27 +89933,44 @@ async function runDraftSpec(ctx, input, deps) {
89928
89933
  })
89929
89934
  };
89930
89935
  }
89931
- let fresh;
89932
- try {
89933
- fresh = await client.getTask(projectSlug, taskId);
89934
- } catch (error51) {
89935
- if (error51 instanceof MrrlinApiError && error51.status === 404) {
89936
- return { kind: "failed", failureReason: "zero_output", error: `task ${taskId} disappeared before linking` };
89936
+ let linkedPageId;
89937
+ if (useDraftLinkV1) {
89938
+ try {
89939
+ const fresh = await client.getDraftLinkV1(projectSlug, taskId, { signal: ctx.signal });
89940
+ if (fresh.kind === "missing") {
89941
+ return { kind: "failed", failureReason: "zero_output", error: `task ${taskId} disappeared before linking` };
89942
+ }
89943
+ linkedPageId = fresh.specWikiPageId;
89944
+ } catch (error51) {
89945
+ return {
89946
+ kind: "retry",
89947
+ failureReason: "provider_unavailable",
89948
+ error: `pre-link draft lookup failed for ${taskId}: ${errMessage3(error51)}`
89949
+ };
89950
+ }
89951
+ } else {
89952
+ try {
89953
+ linkedPageId = (await client.getTask(projectSlug, taskId)).specWikiPageId;
89954
+ } catch (error51) {
89955
+ if (error51 instanceof MrrlinApiError && error51.status === 404) {
89956
+ return { kind: "failed", failureReason: "zero_output", error: `task ${taskId} disappeared before linking` };
89957
+ }
89958
+ return {
89959
+ kind: "retry",
89960
+ failureReason: "provider_unavailable",
89961
+ error: `pre-link task re-fetch failed for ${taskId}: ${errMessage3(error51)}`
89962
+ };
89937
89963
  }
89938
- return {
89939
- kind: "retry",
89940
- failureReason: "provider_unavailable",
89941
- error: `pre-link task re-fetch failed for ${taskId}: ${errMessage3(error51)}`
89942
- };
89943
89964
  }
89944
- if (fresh.specWikiPageId) {
89945
- return skipped("lost_link_race", { pageId, linkedPageId: fresh.specWikiPageId });
89965
+ if (linkedPageId) {
89966
+ return skipped("lost_link_race", { pageId, linkedPageId });
89946
89967
  }
89947
89968
  const linkPatch = { specWikiPageId: pageId };
89948
89969
  if (deployTargets !== void 0 && deployTargets.length > 0) {
89949
89970
  linkPatch.deployTargets = deployTargets;
89950
89971
  }
89951
89972
  try {
89973
+ if (useDraftLinkV1) ctx.signal?.throwIfAborted();
89952
89974
  await client.updateTask(projectSlug, taskId, linkPatch);
89953
89975
  } catch (error51) {
89954
89976
  return {
@@ -92408,7 +92430,7 @@ function git2(checkout, args, hooksDir, baseEnv = process.env) {
92408
92430
  async function createRunWorktree(opts) {
92409
92431
  const signal = opts.signal;
92410
92432
  signal?.throwIfAborted();
92411
- const worktreePath = (0, import_node_path23.join)(opts.worktreeRoot, opts.slug, opts.runId);
92433
+ const worktreePath = (0, import_node_path23.resolve)(opts.worktreeRoot, opts.slug, opts.runId);
92412
92434
  const hooksDir = prepareDisabledGitHooksDir(opts.locksDir, opts.runId);
92413
92435
  const runGit2 = async (args) => {
92414
92436
  if (!signal) return git2(opts.checkout, args, hooksDir);
@@ -92426,7 +92448,7 @@ async function createRunWorktree(opts) {
92426
92448
  (0, import_node_fs17.mkdirSync)(opts.worktreeRoot, { recursive: true });
92427
92449
  const base = opts.local ? `refs/heads/${opts.defaultBranch}` : `origin/${opts.defaultBranch}`;
92428
92450
  try {
92429
- if (!opts.local) await runGit2(["fetch", "origin", opts.defaultBranch]);
92451
+ if (!opts.local) await runGit2(["fetch", "--no-auto-gc", "origin", opts.defaultBranch]);
92430
92452
  if (!(0, import_node_fs17.existsSync)(worktreePath)) {
92431
92453
  await runGit2([
92432
92454
  "worktree",
@@ -92448,14 +92470,14 @@ async function createRunWorktree(opts) {
92448
92470
  return worktreePath;
92449
92471
  }
92450
92472
  async function openRunWorktree(opts) {
92451
- const worktreePath = (0, import_node_path23.join)(opts.worktreeRoot, opts.slug, opts.runId);
92473
+ const worktreePath = (0, import_node_path23.resolve)(opts.worktreeRoot, opts.slug, opts.runId);
92452
92474
  const hooksDir = prepareDisabledGitHooksDir(opts.locksDir, opts.runId);
92453
92475
  const branch = worktreeBranch(opts.runId);
92454
92476
  const env = buildLocalStepEnv();
92455
92477
  await withCheckoutLock(opts.locksDir, opts.slug, async () => {
92456
92478
  if ((0, import_node_fs17.existsSync)(worktreePath)) {
92457
92479
  const real = (0, import_node_fs17.realpathSync)(worktreePath);
92458
- const listed = git2(opts.checkout, ["worktree", "list", "--porcelain"], hooksDir, env).split(/\n\s*\n/).map((block) => block.split("\n")).find((lines2) => {
92480
+ const listed = git2(opts.checkout, ["-c", "core.quotePath=false", "worktree", "list", "--porcelain"], hooksDir, env).split(/\n\s*\n/).map((block) => block.split("\n")).find((lines2) => {
92459
92481
  const listedPath = lines2.find((line) => line.startsWith("worktree "))?.slice("worktree ".length);
92460
92482
  return listedPath !== void 0 && (0, import_node_fs17.existsSync)(listedPath) && (0, import_node_fs17.realpathSync)(listedPath) === real;
92461
92483
  });
@@ -92473,19 +92495,48 @@ async function openRunWorktree(opts) {
92473
92495
  throw new Error(`run_branch_missing: ${opts.checkout} has no branch ${branch}`);
92474
92496
  }
92475
92497
  (0, import_node_fs17.mkdirSync)(opts.worktreeRoot, { recursive: true });
92476
- git2(opts.checkout, ["worktree", "prune"], hooksDir, env);
92477
- git2(opts.checkout, ["worktree", "add", worktreePath, branch], hooksDir, env);
92498
+ git2(opts.checkout, ["worktree", "add", "--", worktreePath, branch], hooksDir, env);
92478
92499
  });
92479
92500
  return worktreePath;
92480
92501
  }
92481
92502
  async function removeRunWorktree(opts) {
92503
+ if (!(0, import_node_path23.isAbsolute)(opts.worktreePath) || (0, import_node_path23.normalize)(opts.worktreePath) !== opts.worktreePath) {
92504
+ throw new Error("run_worktree_invalid: removal requires a normalized absolute path");
92505
+ }
92482
92506
  const hooksDir = prepareDisabledGitHooksDir(opts.locksDir, (0, import_node_path23.basename)(opts.worktreePath));
92483
92507
  await withCheckoutLock(opts.locksDir, opts.slug, async () => {
92508
+ let target;
92484
92509
  try {
92485
- git2(opts.checkout, ["worktree", "remove", "--force", opts.worktreePath], hooksDir);
92486
- } catch {
92510
+ if ((0, import_node_fs17.lstatSync)(opts.worktreePath).isSymbolicLink()) {
92511
+ throw new Error("run_worktree_invalid: removal target is a symbolic link");
92512
+ }
92513
+ target = (0, import_node_path23.normalize)(import_node_fs17.realpathSync.native(opts.worktreePath));
92514
+ } catch (error51) {
92515
+ if (error51.code !== "ENOENT") throw error51;
92516
+ }
92517
+ if (target) {
92518
+ const listing = git2(opts.checkout, ["-c", "core.quotePath=false", "worktree", "list", "--porcelain"], hooksDir);
92519
+ const pathKey = (path40) => process.platform === "win32" ? (0, import_node_path23.normalize)(path40).toLowerCase() : (0, import_node_path23.normalize)(path40);
92520
+ const records = listing.split(/\r?\n\r?\n/).filter(Boolean).map((record2) => {
92521
+ const [line, ...fields] = record2.split(/\r?\n/);
92522
+ const registered = line?.startsWith("worktree ") ? line.slice("worktree ".length) : "";
92523
+ if (/^"(?:[^"\\]|\\.)*"$/.test(registered)) return null;
92524
+ if (/[\x00-\x1f\x7f]/.test(registered)) return null;
92525
+ if (!(0, import_node_path23.isAbsolute)(registered)) throw new Error("run_worktree_invalid: ambiguous Git worktree registration");
92526
+ return { registered, locked: fields.some((field) => /^locked(?: |$)/.test(field)) };
92527
+ });
92528
+ const requestedKey = pathKey(opts.worktreePath);
92529
+ const targetKey = pathKey(target);
92530
+ if (requestedKey !== targetKey && records.some((record2) => record2 !== null && pathKey(record2.registered) === requestedKey)) {
92531
+ throw new Error("run_worktree_invalid: registered path resolves to another location");
92532
+ }
92533
+ const matches = records.filter((record2) => record2 !== null && pathKey(record2.registered) === targetKey);
92534
+ if (matches.length !== 1) {
92535
+ throw new Error("run_worktree_invalid: expected one exact Git worktree registration");
92536
+ }
92537
+ const match = matches[0];
92538
+ if (!match.locked) git2(opts.checkout, ["worktree", "remove", "--force", "--", match.registered], hooksDir);
92487
92539
  }
92488
- git2(opts.checkout, ["worktree", "prune"], hooksDir);
92489
92540
  removeDisabledGitHooksDir(opts.locksDir, (0, import_node_path23.basename)(opts.worktreePath));
92490
92541
  });
92491
92542
  }
@@ -92617,7 +92668,7 @@ async function doPushRunBranch(opts, execGit) {
92617
92668
  }
92618
92669
  return { pushedSha: localSha };
92619
92670
  }
92620
- async function sweepOrphanWorktrees(opts) {
92671
+ async function sweepOrphanWorktrees(opts, runGit2 = git2) {
92621
92672
  const reaped = [];
92622
92673
  const hooksDir = prepareDisabledGitHooksDir(opts.locksDir, `sweep:${opts.slug}`);
92623
92674
  const ownedPrefix = (() => {
@@ -92631,32 +92682,49 @@ async function sweepOrphanWorktrees(opts) {
92631
92682
  await withCheckoutLock(opts.locksDir, opts.slug, async () => {
92632
92683
  await withCheckoutLock(opts.worktreeRoot, worktreeRootSweepLock, async () => {
92633
92684
  if (!canSweepColdWorkRoot(opts.worktreeRoot)) return;
92634
- const listing = git2(opts.checkout, ["worktree", "list", "--porcelain"], hooksDir);
92635
- for (const block of listing.split("\n\n")) {
92685
+ const listing = runGit2(opts.checkout, ["-c", "core.quotePath=false", "worktree", "list", "--porcelain"], hooksDir);
92686
+ const blocks = listing.split(/\r?\n\r?\n/).filter(Boolean);
92687
+ const paths = blocks.map((block) => {
92688
+ const [path40, head, branch, ...flags] = block.split(/\r?\n/);
92689
+ if (!path40?.startsWith("worktree ")) return void 0;
92690
+ if (!/^HEAD (?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(head ?? "")) return void 0;
92691
+ if (!/^(?:branch refs\/heads\/[^\x00-\x20\x7f]+|detached)$/.test(branch ?? "")) return void 0;
92692
+ if (flags.some((flag) => !/^(?:locked|prunable)(?: [^\x00-\x1f\x7f]*)?$/.test(flag))) return void 0;
92693
+ return path40.slice("worktree ".length);
92694
+ });
92695
+ const counts = /* @__PURE__ */ new Map();
92696
+ for (const path40 of paths) {
92697
+ if (!path40 || !(0, import_node_path23.isAbsolute)(path40) || /[\x00-\x1f\x7f]/.test(path40)) continue;
92698
+ const key = process.platform === "win32" ? (0, import_node_path23.normalize)(path40).toLowerCase() : (0, import_node_path23.normalize)(path40);
92699
+ counts.set(key, (counts.get(key) ?? 0) + 1);
92700
+ }
92701
+ for (const [index, block] of blocks.entries()) {
92636
92702
  if (/^locked(?: |$)/m.test(block)) continue;
92637
- const m = /^worktree (.+)$/m.exec(block);
92638
- const wt = m?.[1]?.trim();
92639
- if (!wt) continue;
92640
- const canonicalWt = (() => {
92641
- try {
92642
- return (import_node_fs17.realpathSync.native ?? import_node_fs17.realpathSync)(wt);
92643
- } catch {
92644
- return wt;
92645
- }
92646
- })();
92703
+ const wt = paths[index];
92704
+ if (!wt || !(0, import_node_path23.isAbsolute)(wt) || /[\x00-\x1f\x7f]/.test(wt)) continue;
92705
+ const key = process.platform === "win32" ? (0, import_node_path23.normalize)(wt).toLowerCase() : (0, import_node_path23.normalize)(wt);
92706
+ if (counts.get(key) !== 1) continue;
92707
+ let canonicalWt;
92708
+ try {
92709
+ if ((0, import_node_fs17.lstatSync)(wt).isSymbolicLink()) continue;
92710
+ canonicalWt = import_node_fs17.realpathSync.native(wt);
92711
+ } catch {
92712
+ continue;
92713
+ }
92647
92714
  const normWt = (0, import_node_path23.normalize)(canonicalWt);
92715
+ const canonicalKey = process.platform === "win32" ? normWt.toLowerCase() : normWt;
92716
+ if (canonicalKey !== key) continue;
92648
92717
  const normPrefix = (0, import_node_path23.normalize)(ownedPrefix);
92649
92718
  const isMatch = process.platform === "win32" ? normWt.toLowerCase().startsWith(normPrefix.toLowerCase()) : normWt.startsWith(normPrefix);
92650
- if (isMatch && opts.isReapable(wt)) {
92719
+ if (isMatch && (0, import_node_path23.isAbsolute)(wt) && opts.isReapable(wt)) {
92651
92720
  try {
92652
- git2(opts.checkout, ["worktree", "remove", "--force", wt], hooksDir);
92721
+ runGit2(opts.checkout, ["worktree", "remove", "--force", "--", wt], hooksDir);
92653
92722
  removeDisabledGitHooksDir(opts.locksDir, (0, import_node_path23.basename)(wt));
92654
92723
  reaped.push(wt);
92655
92724
  } catch {
92656
92725
  }
92657
92726
  }
92658
92727
  }
92659
- git2(opts.checkout, ["worktree", "prune"], hooksDir);
92660
92728
  });
92661
92729
  });
92662
92730
  } finally {
@@ -99432,7 +99500,7 @@ Do NOT derail the current task - if the operator has an in-flight question, answ
99432
99500
  }
99433
99501
 
99434
99502
  // src/_generated/version.ts
99435
- var PKG_VERSION = "0.4.208";
99503
+ var PKG_VERSION = "0.4.210";
99436
99504
 
99437
99505
  // src/bridge-allowed-origins.ts
99438
99506
  var DEFAULT_DIRECTOR_BRIDGE_ALLOWED_ORIGINS = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrrlin-dev/mcp",
3
- "version": "0.4.208",
3
+ "version": "0.4.210",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "mrrlin-mcp": "dist/bin.cjs"