@srobroek/pi-worktrunk-merge-policy 0.7.2 → 0.7.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## worktrunk [0.7.3](https://github.com/srobroek/harness-plugins/compare/worktrunk--v0.7.2...worktrunk--v0.7.3) (2026-11-25)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **worktrunk:** refuse a merge after a leading cd the gate cannot read ([d3b36fe](https://github.com/srobroek/harness-plugins/commit/d3b36fe5e15a7dacfd7481074c10739adfddb6f2))
6
+
1
7
  ## worktrunk [0.7.2](https://github.com/srobroek/harness-plugins/compare/worktrunk--v0.7.1...worktrunk--v0.7.2) (2026-11-24)
2
8
 
3
9
  ## worktrunk [0.7.1](https://github.com/srobroek/harness-plugins/compare/worktrunk--v0.7.0...worktrunk--v0.7.1) (2026-11-23)
@@ -1383,14 +1383,16 @@ var HAS_WELLFORMED = !!"".isWellFormed;
1383
1383
  var compiled = new Map;
1384
1384
  // lib/src/shell-command.ts
1385
1385
  import { resolve } from "path";
1386
- function leadingCdCwd(command, cwd) {
1387
- const match = /^\s*cd\s+([^\s;&|]+)\s*&&/.exec(command);
1388
- if (!match)
1389
- return cwd;
1390
- const dir = match[1];
1391
- if (!dir || /^[-~$]/.test(dir) || /[\\`"'*?\x5b\x5d{}]/.test(dir))
1392
- return cwd;
1393
- return dir.startsWith("/") ? dir : resolve(cwd, dir);
1386
+ var LITERAL_CD = /^\s*cd[ \t]+([A-Za-z0-9_@%+=:,./-]+)[ \t]*(?:&&|$)/;
1387
+ var STARTS_WITH_CD = /^\s*(?:cd|pushd|popd)(?=\s|$|[;&|<>()])/;
1388
+ function leadingCd(command, cwd) {
1389
+ if (!STARTS_WITH_CD.test(command))
1390
+ return { kind: "none" };
1391
+ const match = LITERAL_CD.exec(command);
1392
+ const dir = match?.[1];
1393
+ if (match === null || dir === undefined || dir.startsWith("-") || dir.split("/").includes(".."))
1394
+ return { kind: "rejected" };
1395
+ return { kind: "dir", dir: resolve(cwd, dir), length: match[0].length };
1394
1396
  }
1395
1397
  function scanShell(source, options = {}) {
1396
1398
  const items = [];
@@ -2000,6 +2002,7 @@ var SOURCE_WORKTREE_RETRY = `${MERGE_RETRY} from the source worktree`;
2000
2002
  var MERGE_POLICY_REFUSAL = `worker-to-epic merges must preserve history; retry with ${MERGE_RETRY}`;
2001
2003
  var OPAQUE_DYNAMIC_MERGE_REFUSAL = "opaque dynamic shell body names a merge or land command; retry with a literal command";
2002
2004
  var UNPARSEABLE_MERGE_REFUSAL = "the command has an unterminated quote, substitution or here-document and names wt merge, so the merge cannot be checked; retry with a complete literal command";
2005
+ var UNKNOWN_DIRECTORY_MERGE_REFUSAL = "the command starts with a cd this gate cannot read (a quoted, expanded, `..` or redirected directory), so the repository the merge runs in is unknown; retry with `cd <literal path> && wt merge \u2026` or `wt -C <absolute path> merge \u2026`";
2003
2006
  var SHELLS = new Set(["bash", "sh", "zsh", "dash", "ksh"]);
2004
2007
  var GLOBAL_VALUE_OPTIONS = new Set(["-C", "--config", "--config-set"]);
2005
2008
  var MERGE_VALUE_OPTIONS = new Set(["--stage", "--format", "--config", "--config-set", "-C"]);
@@ -2169,13 +2172,16 @@ async function decideCommands(command, cwd, git, wt) {
2169
2172
  return { block: true, reason: UNPARSEABLE_MERGE_REFUSAL };
2170
2173
  if (collected.mergeVariables.size > 0 && collected.executed.some((word) => references(word, collected.mergeVariables)))
2171
2174
  return { block: true, reason: OPAQUE_DYNAMIC_MERGE_REFUSAL };
2172
- const shellCwd = leadingCdCwd(command, cwd);
2175
+ const lead = leadingCd(command, cwd);
2176
+ const shellCwd = lead.kind === "dir" ? lead.dir : lead.kind === "none" ? cwd : undefined;
2173
2177
  for (const argv of collected.commands) {
2174
2178
  const invocation = parseMergeInvocation(argv);
2175
2179
  if (!invocation || invocation.target === null)
2176
2180
  continue;
2177
2181
  const target = invocation.target;
2178
- const repoCwd = invocation.workdir ? invocation.workdir.startsWith("/") ? invocation.workdir : `${shellCwd}/${invocation.workdir}` : shellCwd;
2182
+ const repoCwd = invocation.workdir?.startsWith("/") ? invocation.workdir : shellCwd === undefined ? undefined : invocation.workdir ? `${shellCwd}/${invocation.workdir}` : shellCwd;
2183
+ if (repoCwd === undefined)
2184
+ return { block: true, reason: UNKNOWN_DIRECTORY_MERGE_REFUSAL };
2179
2185
  const configured = await wt(["config", "state", "default-branch"], repoCwd);
2180
2186
  const symbolic = configured || await git(["symbolic-ref", "--short", "refs/remotes/origin/HEAD"], repoCwd);
2181
2187
  const defaultBranch = symbolic?.replace(/^origin\//, "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@srobroek/pi-worktrunk-merge-policy",
3
- "version": "0.7.2",
3
+ "version": "0.7.3",
4
4
  "description": "Worktrunk (wt) skills: work in linked worktrees and run deterministic preflight checks before an agent run or merge.",
5
5
  "keywords": [
6
6
  "pi-package"