@srobroek/pi-worktrunk-merge-policy 0.7.1 → 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 +8 -0
- package/README.md +5 -0
- package/extensions/worktrunk.js +16 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
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
|
+
|
|
7
|
+
## worktrunk [0.7.2](https://github.com/srobroek/harness-plugins/compare/worktrunk--v0.7.1...worktrunk--v0.7.2) (2026-11-24)
|
|
8
|
+
|
|
1
9
|
## worktrunk [0.7.1](https://github.com/srobroek/harness-plugins/compare/worktrunk--v0.7.0...worktrunk--v0.7.1) (2026-11-23)
|
|
2
10
|
|
|
3
11
|
### Bug Fixes
|
package/README.md
CHANGED
|
@@ -11,6 +11,11 @@ It does three things:
|
|
|
11
11
|
- Ships two skills: `worktrunk-preflight` and `worktrunk-worktrees`.
|
|
12
12
|
|
|
13
13
|
## Install
|
|
14
|
+
Install the Pi package from npm:
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
pi install npm:@srobroek/pi-worktrunk-merge-policy
|
|
18
|
+
```
|
|
14
19
|
|
|
15
20
|
```sh
|
|
16
21
|
opencode plugin add 'github:srobroek/harness-plugins::path:plugins/worktrunk/opencode'
|
package/extensions/worktrunk.js
CHANGED
|
@@ -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
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
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
|
|
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
|
|
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