@srobroek/pi-worktrunk-merge-policy 0.8.0 → 1.0.1
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 +19 -0
- package/README.md +11 -23
- package/extensions/worktrunk.js +29 -317
- package/package.json +1 -1
- package/skills/worktrunk-worktrees/SKILL.md +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
## worktrunk [1.0.1](https://github.com/srobroek/harness-plugins/compare/worktrunk--v1.0.0...worktrunk--v1.0.1) (2026-12-04)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
* retire beads, worktrunk, trunk-dev and chezmoi gates (guidance only) ([#294](https://github.com/srobroek/harness-plugins/issues/294)) ([19eab97](https://github.com/srobroek/harness-plugins/commit/19eab97fee1e3eb8719838e4ba2a9a8d87c3ea9e))
|
|
6
|
+
|
|
7
|
+
## worktrunk [1.0.0](https://github.com/srobroek/harness-plugins/compare/worktrunk--v0.8.0...worktrunk--v1.0.0) (2026-12-04)
|
|
8
|
+
|
|
9
|
+
### ⚠ BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* **beads:** @srobroek/pi-safety no longer ships child-gates or
|
|
12
|
+
child-gates-plan.js. Install @srobroek/pi-child-gates for them.
|
|
13
|
+
|
|
14
|
+
* chore: update bun.lock for the child-gates workspace
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **beads:** escaped quotes and cd prefix in gates; child-gates as its own package ([21cb2eb](https://github.com/srobroek/harness-plugins/commit/21cb2eb1917d4473e5c250155962e6b9a7441c13))
|
|
19
|
+
|
|
1
20
|
## worktrunk [0.8.0](https://github.com/srobroek/harness-plugins/compare/worktrunk--v0.7.4...worktrunk--v0.8.0) (2026-12-02)
|
|
2
21
|
|
|
3
22
|
### Features
|
package/README.md
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
omp-plugins `worktrunk` package. The omp isolation precheck is not ported: OpenCode has no native
|
|
5
5
|
checkout-cloning isolation to refuse.
|
|
6
6
|
|
|
7
|
-
It does three things:
|
|
7
|
+
It does three things, and refuses no shell call:
|
|
8
8
|
|
|
9
9
|
- Registers `wt` as OpenCode's worktree strategy.
|
|
10
|
-
-
|
|
10
|
+
- Raises the timeout of a short `wt switch` call so foreground hooks finish.
|
|
11
11
|
- Ships two skills: `worktrunk-preflight` and `worktrunk-worktrees`.
|
|
12
12
|
|
|
13
13
|
## Install
|
|
@@ -29,7 +29,7 @@ claude plugin install worktrunk@harness-plugins
|
|
|
29
29
|
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
Claude Code get the two skills only; the worktree strategy and
|
|
32
|
+
Claude Code get the two skills only; the worktree strategy and the `wt switch` timeout are OpenCode code.
|
|
33
33
|
|
|
34
34
|
Needs `wt` and `git` on `PATH`. The preflight skill also needs `python3` (3.11 or later).
|
|
35
35
|
|
|
@@ -37,7 +37,7 @@ Needs `wt` and `git` on `PATH`. The preflight skill also needs `python3` (3.11 o
|
|
|
37
37
|
|
|
38
38
|
| Option | Default | Effect |
|
|
39
39
|
| --- | --- | --- |
|
|
40
|
-
| `strategy` | `true` | `false` keeps OpenCode's bundled Git strategy. The
|
|
40
|
+
| `strategy` | `true` | `false` keeps OpenCode's bundled Git strategy. The `wt switch` timeout and the skills stay on. |
|
|
41
41
|
|
|
42
42
|
```jsonc
|
|
43
43
|
{ "plugins": [{ "package": "...", "options": { "strategy": false } }] }
|
|
@@ -66,22 +66,11 @@ restores the previous one. Worktrees created before the plugin loaded keep their
|
|
|
66
66
|
Removing a directory that no longer exists does nothing.
|
|
67
67
|
- `list` reports the main worktree as `root` and every linked worktree as `worktree`.
|
|
68
68
|
|
|
69
|
-
## Merge
|
|
69
|
+
## Merge guidance
|
|
70
70
|
|
|
71
|
-
`
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
`--no-ff`;
|
|
75
|
-
- such a merge run from the target worktree, or from a detached `HEAD`, because `wt merge`
|
|
76
|
-
merges the current branch;
|
|
77
|
-
- a merge it cannot check: the default branch cannot be resolved, a probe times out, or the
|
|
78
|
-
command is unterminated or runs a merge stored in a variable (`cmd="wt merge x"; eval "$cmd"`).
|
|
79
|
-
|
|
80
|
-
`wt merge` with no target and merges to the default branch pass. The gate reads the default branch
|
|
81
|
-
from `wt config state default-branch`, then `origin/HEAD`, in the call's directory: the shell
|
|
82
|
-
`workdir` (resolved against the session directory), a leading `cd DIR &&`, or `wt -C DIR`. It
|
|
83
|
-
finds merges behind wrappers (`env`, `sudo`, `timeout`, ...), in `$(...)`, backticks, process
|
|
84
|
-
substitutions, `eval` and `sh -c`. `git merge` and `gh pr merge` are not gated.
|
|
71
|
+
The plugin no longer checks `wt merge` calls. The `worktrunk-worktrees` skill carries the rule as
|
|
72
|
+
guidance: a worker-to-epic merge passes `--no-squash --no-ff` to keep per-commit history, and
|
|
73
|
+
`wt merge` runs from the source worktree.
|
|
85
74
|
|
|
86
75
|
## Skills
|
|
87
76
|
|
|
@@ -99,19 +88,18 @@ resolve it as `../skills`. A skill with the same id that the host already has wi
|
|
|
99
88
|
|
|
100
89
|
## pi
|
|
101
90
|
|
|
102
|
-
One extension, `pi/extensions/worktrunk.js` (source `pi-src/worktrunk.ts`). The
|
|
103
|
-
`wt switch` timeout
|
|
91
|
+
One extension, `pi/extensions/worktrunk.js` (source `pi-src/worktrunk.ts`). The
|
|
92
|
+
`wt switch` timeout shares `shared/switch-timeout.ts` with OpenCode.
|
|
104
93
|
|
|
105
94
|
| Feature | pi hook | Behavior |
|
|
106
95
|
| --- | --- | --- |
|
|
107
|
-
| Merge policy gate | `tool_call` on `bash` | Returns `{ block: true, reason }` for every merge the OpenCode gate refuses, checked in `ctx.cwd`. A handler error blocks the call, as pi treats a throwing `tool_call` handler. |
|
|
108
96
|
| `wt switch` timeout | `tool_call` on `bash` | Raises a `timeout` shorter than 600 s to 600 s on a `wt switch` call, so foreground hooks are not killed mid-provisioning. pi's bash tool has no default timeout, so a call without one is left alone. |
|
|
109
97
|
| `worktrunk_preflight` tool | `registerTool` | The checks of `preflight.py`, ported to TypeScript in `shared/preflight.ts` with the same ids, statuses and `{ ok, summary, checks }` JSON. Parameters: `path` (default: the session directory), `only` (check ids), `apply`. `apply` writes `.config/wt.toml` under pi's file-mutation queue. |
|
|
110
98
|
|
|
111
99
|
The worktree strategy has no pi counterpart: pi has no worktree-strategy hook. pi-subagents allocates
|
|
112
100
|
its child worktrees itself, running `wt -C <root> switch --create <branch> --base <commit> --no-cd
|
|
113
101
|
--no-hooks --format json` with `spawnSync` from its extension process, not through the bash tool.
|
|
114
|
-
pi fires `tool_call` only for tool calls, so
|
|
102
|
+
pi fires `tool_call` only for tool calls, so the timeout hook does not see that allocation.
|
|
115
103
|
|
|
116
104
|
pi-subagents' foreground children do not load the parent's extensions ([required host extensions](https://github.com/nicobailon/pi-subagents/blob/main/docs/agents.md#required-host-extensions)). List this extension for every child in `~/.pi/agent/settings.json`, with the path where pi installed this repository:
|
|
117
105
|
|
package/extensions/worktrunk.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// Generated by scripts/build.ts. Do not edit.
|
|
3
3
|
// plugins/worktrunk/pi-src/worktrunk.ts
|
|
4
|
-
import { isAbsolute as isAbsolute2, resolve as
|
|
4
|
+
import { isAbsolute as isAbsolute2, resolve as resolve2 } from "path";
|
|
5
5
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
6
6
|
import {
|
|
7
7
|
isToolCallEventType,
|
|
@@ -9,6 +9,11 @@ import {
|
|
|
9
9
|
} from "@earendil-works/pi-coding-agent";
|
|
10
10
|
import { Type } from "typebox";
|
|
11
11
|
|
|
12
|
+
// plugins/worktrunk/shared/preflight.ts
|
|
13
|
+
import { accessSync, constants as constants2, existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "fs";
|
|
14
|
+
import { homedir } from "os";
|
|
15
|
+
import { dirname, isAbsolute, join, resolve } from "path";
|
|
16
|
+
|
|
12
17
|
// lib/src/agent-tools.ts
|
|
13
18
|
var MCP_TOOL_AGENTS = new Set([
|
|
14
19
|
"adversarial-challenger",
|
|
@@ -51,6 +56,8 @@ var MCP_EXCLUDED_AGENTS = new Set([
|
|
|
51
56
|
// lib/src/shell-tokenizer.ts
|
|
52
57
|
var SEPARATORS = new Set([";", "&", "|", "(", ")", `
|
|
53
58
|
`]);
|
|
59
|
+
var DOUBLE_QUOTE_ESCAPES = new Set(["$", "`", '"', "\\", `
|
|
60
|
+
`]);
|
|
54
61
|
function token(value, startsQuoted = false, sawQuote = false) {
|
|
55
62
|
return { value, startsQuoted, sawQuote };
|
|
56
63
|
}
|
|
@@ -80,6 +87,17 @@ function tokenizeShell(command, options = {}) {
|
|
|
80
87
|
quote = null;
|
|
81
88
|
continue;
|
|
82
89
|
}
|
|
90
|
+
if (quote === '"' && ch === "\\" && DOUBLE_QUOTE_ESCAPES.has(command[i + 1])) {
|
|
91
|
+
const next = command[++i];
|
|
92
|
+
if (next !== `
|
|
93
|
+
`) {
|
|
94
|
+
if (options.preserveBackslashes)
|
|
95
|
+
current += ch;
|
|
96
|
+
current += next;
|
|
97
|
+
}
|
|
98
|
+
started = true;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
83
101
|
current += ch;
|
|
84
102
|
started = true;
|
|
85
103
|
continue;
|
|
@@ -166,6 +184,8 @@ function shellQuoteBalanced(command) {
|
|
|
166
184
|
if (quote !== null) {
|
|
167
185
|
if (ch === quote)
|
|
168
186
|
quote = null;
|
|
187
|
+
else if (quote === '"' && ch === "\\" && DOUBLE_QUOTE_ESCAPES.has(command[i + 1]))
|
|
188
|
+
i++;
|
|
169
189
|
continue;
|
|
170
190
|
}
|
|
171
191
|
if (ch === '"' || ch === "'")
|
|
@@ -1385,18 +1405,6 @@ var HAS_WELLFORMED = !!"".isWellFormed;
|
|
|
1385
1405
|
// lib/src/patterns.ts
|
|
1386
1406
|
var compiled = new Map;
|
|
1387
1407
|
// lib/src/shell-command.ts
|
|
1388
|
-
import { resolve } from "path";
|
|
1389
|
-
var LITERAL_CD = /^\s*cd[ \t]+([A-Za-z0-9_@%+=:,./-]+)[ \t]*(?:&&|$)/;
|
|
1390
|
-
var STARTS_WITH_CD = /^\s*(?:cd|pushd|popd)(?=\s|$|[;&|<>()])/;
|
|
1391
|
-
function leadingCd(command, cwd) {
|
|
1392
|
-
if (!STARTS_WITH_CD.test(command))
|
|
1393
|
-
return { kind: "none" };
|
|
1394
|
-
const match = LITERAL_CD.exec(command);
|
|
1395
|
-
const dir = match?.[1];
|
|
1396
|
-
if (match === null || dir === undefined || dir.startsWith("-") || dir.split("/").includes(".."))
|
|
1397
|
-
return { kind: "rejected" };
|
|
1398
|
-
return { kind: "dir", dir: resolve(cwd, dir), length: match[0].length };
|
|
1399
|
-
}
|
|
1400
1408
|
function scanShell(source, options = {}) {
|
|
1401
1409
|
const items = [];
|
|
1402
1410
|
const substitutions = [];
|
|
@@ -1925,296 +1933,7 @@ var WRITE_TOOLS = new Set(["edit", "write", "patch"]);
|
|
|
1925
1933
|
var READ_TOOLS = new Set(["read"]);
|
|
1926
1934
|
var SHELL_ALIASES = new Set(["bash", "Bash"]);
|
|
1927
1935
|
var SHELL_EXECUTABLES = new Set(["bash", "sh", "zsh", "dash", "ksh"]);
|
|
1928
|
-
// lib/src/safe-git.ts
|
|
1929
|
-
import { devNull } from "os";
|
|
1930
|
-
var SAFE_GIT_CONFIG = [
|
|
1931
|
-
["core.fsmonitor", "false"],
|
|
1932
|
-
["core.hooksPath", devNull]
|
|
1933
|
-
];
|
|
1934
|
-
var SAFE_GIT_ARGS = [...SAFE_GIT_CONFIG.flatMap(([key, value]) => ["-c", `${key}=${value}`]), "--no-optional-locks"];
|
|
1935
|
-
var HARDENED_GIT_CONFIG = [
|
|
1936
|
-
...SAFE_GIT_CONFIG,
|
|
1937
|
-
["core.attributesFile", devNull],
|
|
1938
|
-
["log.showSignature", "false"],
|
|
1939
|
-
["gpg.program", devNull],
|
|
1940
|
-
["gpg.ssh.program", devNull],
|
|
1941
|
-
["gpg.x509.program", devNull],
|
|
1942
|
-
["commit.gpgSign", "false"],
|
|
1943
|
-
["tag.gpgSign", "false"],
|
|
1944
|
-
["gpg.ssh.defaultKeyCommand", ""],
|
|
1945
|
-
["core.sshCommand", ""],
|
|
1946
|
-
["credential.helper", ""],
|
|
1947
|
-
["diff.external", ""]
|
|
1948
|
-
];
|
|
1949
|
-
var EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
|
1950
|
-
var INHERITED_GIT_VARIABLES = [
|
|
1951
|
-
"GIT_DIR",
|
|
1952
|
-
"GIT_WORK_TREE",
|
|
1953
|
-
"GIT_COMMON_DIR",
|
|
1954
|
-
"GIT_INDEX_FILE",
|
|
1955
|
-
"GIT_OBJECT_DIRECTORY",
|
|
1956
|
-
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
|
|
1957
|
-
"GIT_PREFIX",
|
|
1958
|
-
"GIT_NAMESPACE",
|
|
1959
|
-
"GIT_REPLACE_REF_BASE",
|
|
1960
|
-
"GIT_GRAFT_FILE",
|
|
1961
|
-
"GIT_SHALLOW_FILE",
|
|
1962
|
-
"GIT_CONFIG",
|
|
1963
|
-
"GIT_EXEC_PATH",
|
|
1964
|
-
"GIT_EXTERNAL_DIFF",
|
|
1965
|
-
"GIT_PAGER",
|
|
1966
|
-
"GIT_EDITOR",
|
|
1967
|
-
"GIT_SEQUENCE_EDITOR",
|
|
1968
|
-
"GIT_SSH",
|
|
1969
|
-
"GIT_SSH_COMMAND",
|
|
1970
|
-
"GIT_ASKPASS",
|
|
1971
|
-
"GIT_PROXY_COMMAND",
|
|
1972
|
-
"GIT_LITERAL_PATHSPECS",
|
|
1973
|
-
"GIT_GLOB_PATHSPECS",
|
|
1974
|
-
"GIT_NOGLOB_PATHSPECS",
|
|
1975
|
-
"GIT_ICASE_PATHSPECS"
|
|
1976
|
-
];
|
|
1977
|
-
var PROGRAM_VARIABLES = ["PAGER", "EDITOR", "VISUAL", "SSH_ASKPASS"];
|
|
1978
|
-
function hardenedGitEnv(base) {
|
|
1979
|
-
const env = {};
|
|
1980
|
-
const dropped = new Set([...INHERITED_GIT_VARIABLES, ...PROGRAM_VARIABLES]);
|
|
1981
|
-
for (const [key, value] of Object.entries(base)) {
|
|
1982
|
-
if (value === undefined || dropped.has(key) || key.startsWith("GIT_TRACE"))
|
|
1983
|
-
continue;
|
|
1984
|
-
if (key === "GIT_CONFIG_PARAMETERS" || key === "GIT_CONFIG_COUNT" || /^GIT_CONFIG_(KEY|VALUE)_\d+$/.test(key))
|
|
1985
|
-
continue;
|
|
1986
|
-
env[key] = value;
|
|
1987
|
-
}
|
|
1988
|
-
let count = 0;
|
|
1989
|
-
for (const [key, value] of HARDENED_GIT_CONFIG) {
|
|
1990
|
-
env[`GIT_CONFIG_KEY_${count}`] = key;
|
|
1991
|
-
env[`GIT_CONFIG_VALUE_${count}`] = value;
|
|
1992
|
-
count += 1;
|
|
1993
|
-
}
|
|
1994
|
-
env.GIT_CONFIG_COUNT = String(count);
|
|
1995
|
-
env.GIT_ATTR_SOURCE = EMPTY_TREE;
|
|
1996
|
-
env.GIT_OPTIONAL_LOCKS = "0";
|
|
1997
|
-
env.GIT_NO_LAZY_FETCH = "1";
|
|
1998
|
-
env.GIT_ALLOW_PROTOCOL = "";
|
|
1999
|
-
return env;
|
|
2000
|
-
}
|
|
2001
|
-
|
|
2002
|
-
// plugins/worktrunk/shared/merge-gate.ts
|
|
2003
|
-
var MERGE_RETRY = "wt merge <target> --no-squash --no-ff";
|
|
2004
|
-
var SOURCE_WORKTREE_RETRY = `${MERGE_RETRY} from the source worktree`;
|
|
2005
|
-
var MERGE_POLICY_REFUSAL = `worker-to-epic merges must preserve history; retry with ${MERGE_RETRY}`;
|
|
2006
|
-
var OPAQUE_DYNAMIC_MERGE_REFUSAL = "opaque dynamic shell body names a merge or land command; retry with a literal command";
|
|
2007
|
-
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";
|
|
2008
|
-
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`";
|
|
2009
|
-
var SHELLS = new Set(["bash", "sh", "zsh", "dash", "ksh"]);
|
|
2010
|
-
var GLOBAL_VALUE_OPTIONS = new Set(["-C", "--config", "--config-set"]);
|
|
2011
|
-
var MERGE_VALUE_OPTIONS = new Set(["--stage", "--format", "--config", "--config-set", "-C"]);
|
|
2012
|
-
var ASSIGNMENT2 = /^([A-Za-z_]\w*)=([\s\S]*)$/;
|
|
2013
|
-
var MAX_DEPTH = 8;
|
|
2014
|
-
function base(word) {
|
|
2015
|
-
return word?.split("/").pop() ?? "";
|
|
2016
|
-
}
|
|
2017
|
-
function parseMergeInvocation(argv) {
|
|
2018
|
-
const wtIndex = argv.findIndex((word) => base(word) === "wt");
|
|
2019
|
-
if (wtIndex < 0)
|
|
2020
|
-
return null;
|
|
2021
|
-
let subIndex = wtIndex + 1;
|
|
2022
|
-
let workdir = null;
|
|
2023
|
-
while (subIndex < argv.length && argv[subIndex]?.startsWith("-")) {
|
|
2024
|
-
const option = argv[subIndex] ?? "";
|
|
2025
|
-
if (option === "-C")
|
|
2026
|
-
workdir = argv[subIndex + 1] ?? null;
|
|
2027
|
-
subIndex += GLOBAL_VALUE_OPTIONS.has(option) ? 2 : 1;
|
|
2028
|
-
}
|
|
2029
|
-
if (argv[subIndex] !== "merge")
|
|
2030
|
-
return null;
|
|
2031
|
-
if (argv.includes("--help") || argv.includes("-h"))
|
|
2032
|
-
return null;
|
|
2033
|
-
let target = null;
|
|
2034
|
-
let noSquash = false;
|
|
2035
|
-
let noFf = false;
|
|
2036
|
-
for (let i = subIndex + 1;i < argv.length; i++) {
|
|
2037
|
-
const arg = argv[i];
|
|
2038
|
-
if (arg === "--no-squash") {
|
|
2039
|
-
noSquash = true;
|
|
2040
|
-
continue;
|
|
2041
|
-
}
|
|
2042
|
-
if (arg === "--no-ff") {
|
|
2043
|
-
noFf = true;
|
|
2044
|
-
continue;
|
|
2045
|
-
}
|
|
2046
|
-
if (arg === "--") {
|
|
2047
|
-
target = argv[i + 1] ?? null;
|
|
2048
|
-
break;
|
|
2049
|
-
}
|
|
2050
|
-
if (!arg)
|
|
2051
|
-
continue;
|
|
2052
|
-
if (arg.startsWith("-") || MERGE_VALUE_OPTIONS.has(argv[i - 1] ?? ""))
|
|
2053
|
-
continue;
|
|
2054
|
-
if (target === null)
|
|
2055
|
-
target = arg;
|
|
2056
|
-
}
|
|
2057
|
-
return { target, noSquash, noFf, workdir };
|
|
2058
|
-
}
|
|
2059
|
-
function namesMergeCommand(source) {
|
|
2060
|
-
for (const item of scanShell(source).items) {
|
|
2061
|
-
if (item.kind !== "command")
|
|
2062
|
-
continue;
|
|
2063
|
-
const argv = commandWords(item.words.map((word) => word.value)).argv;
|
|
2064
|
-
const executable = base(argv[0]);
|
|
2065
|
-
if (executable === "wt" && parseMergeInvocation(argv) !== null)
|
|
2066
|
-
return true;
|
|
2067
|
-
if (executable === "git" && argv[1] === "merge")
|
|
2068
|
-
return true;
|
|
2069
|
-
if (executable === "gh" && argv[1] === "pr" && argv[2] === "merge")
|
|
2070
|
-
return true;
|
|
2071
|
-
}
|
|
2072
|
-
return false;
|
|
2073
|
-
}
|
|
2074
|
-
function references(text, names) {
|
|
2075
|
-
for (const match of text.matchAll(/\$(?:\{([A-Za-z_]\w*)[^}]*\}|([A-Za-z_]\w*))/g)) {
|
|
2076
|
-
if (names.has(match[1] ?? match[2] ?? ""))
|
|
2077
|
-
return true;
|
|
2078
|
-
}
|
|
2079
|
-
return false;
|
|
2080
|
-
}
|
|
2081
|
-
function collectCommands(source) {
|
|
2082
|
-
const collected = { commands: [], executed: [], mergeVariables: new Set, complete: true };
|
|
2083
|
-
const visit = (text, evaluated, depth) => {
|
|
2084
|
-
if (depth > MAX_DEPTH) {
|
|
2085
|
-
collected.complete = false;
|
|
2086
|
-
return;
|
|
2087
|
-
}
|
|
2088
|
-
const scan = scanShell(text);
|
|
2089
|
-
if (!scan.complete)
|
|
2090
|
-
collected.complete = false;
|
|
2091
|
-
for (const item of scan.items) {
|
|
2092
|
-
if (item.kind !== "command")
|
|
2093
|
-
continue;
|
|
2094
|
-
const values = item.words.map((word) => word.value);
|
|
2095
|
-
for (const value of values) {
|
|
2096
|
-
const assignment = ASSIGNMENT2.exec(value);
|
|
2097
|
-
if (!assignment)
|
|
2098
|
-
break;
|
|
2099
|
-
if (namesMergeCommand(assignment[2] ?? ""))
|
|
2100
|
-
collected.mergeVariables.add(assignment[1] ?? "");
|
|
2101
|
-
}
|
|
2102
|
-
const argv = commandWords(values).argv;
|
|
2103
|
-
if (argv.length === 0)
|
|
2104
|
-
continue;
|
|
2105
|
-
collected.commands.push(argv);
|
|
2106
|
-
if (evaluated)
|
|
2107
|
-
collected.executed.push(...argv);
|
|
2108
|
-
else if (argv[0] !== undefined)
|
|
2109
|
-
collected.executed.push(argv[0]);
|
|
2110
|
-
const executable = base(argv[0]);
|
|
2111
|
-
if (SHELLS.has(executable) && argv[1] === "-c" && argv[2])
|
|
2112
|
-
visit(argv[2], true, depth + 1);
|
|
2113
|
-
if (executable === "eval" && argv.length > 1)
|
|
2114
|
-
visit(argv.slice(1).join(" "), true, depth + 1);
|
|
2115
|
-
}
|
|
2116
|
-
for (const substitution of scan.substitutions)
|
|
2117
|
-
visit(substitution, evaluated, depth + 1);
|
|
2118
|
-
};
|
|
2119
|
-
visit(source, false, 0);
|
|
2120
|
-
return collected;
|
|
2121
|
-
}
|
|
2122
|
-
|
|
2123
|
-
class ProbeTimeout extends Error {
|
|
2124
|
-
}
|
|
2125
|
-
var PROBE_BOUNDS = { timeoutMs: 8000, budgetMs: 25000 };
|
|
2126
|
-
async function spawnProbe(binary, args, cwd, signal) {
|
|
2127
|
-
let child;
|
|
2128
|
-
try {
|
|
2129
|
-
child = Bun.spawn([binary, ...args], {
|
|
2130
|
-
cwd,
|
|
2131
|
-
stdin: "ignore",
|
|
2132
|
-
stdout: "pipe",
|
|
2133
|
-
stderr: "ignore",
|
|
2134
|
-
signal,
|
|
2135
|
-
env: hardenedGitEnv(Bun.env)
|
|
2136
|
-
});
|
|
2137
|
-
} catch {
|
|
2138
|
-
return null;
|
|
2139
|
-
}
|
|
2140
|
-
const run = await supervise(child, { signal });
|
|
2141
|
-
if (signal.aborted || run.kind !== "exited")
|
|
2142
|
-
throw new ProbeTimeout(`${binary} ${args.join(" ")}`);
|
|
2143
|
-
return run.exitCode === 0 ? run.stdout.trim() : null;
|
|
2144
|
-
}
|
|
2145
|
-
var defaultProbes = {
|
|
2146
|
-
git: (args, cwd, signal) => spawnProbe("git", args, cwd, signal),
|
|
2147
|
-
wt: (args, cwd, signal) => spawnProbe("wt", args, cwd, signal)
|
|
2148
|
-
};
|
|
2149
|
-
async function decideMergePolicy(command, cwd, probes = defaultProbes, bounds = PROBE_BOUNDS) {
|
|
2150
|
-
const budget = AbortSignal.timeout(bounds.budgetMs);
|
|
2151
|
-
const probe = async (binary, args, dir) => {
|
|
2152
|
-
const label = `${binary} ${args.join(" ")}`;
|
|
2153
|
-
if (budget.aborted)
|
|
2154
|
-
throw new ProbeTimeout(label);
|
|
2155
|
-
const signal = AbortSignal.any([budget, AbortSignal.timeout(bounds.timeoutMs)]);
|
|
2156
|
-
const aborted = new Promise((_, reject) => {
|
|
2157
|
-
signal.addEventListener("abort", () => reject(new ProbeTimeout(label)), { once: true });
|
|
2158
|
-
});
|
|
2159
|
-
return Promise.race([probes[binary](args, dir, signal), aborted]);
|
|
2160
|
-
};
|
|
2161
|
-
try {
|
|
2162
|
-
return await decideCommands(command, cwd, (args, dir) => probe("git", args, dir), (args, dir) => probe("wt", args, dir));
|
|
2163
|
-
} catch (error) {
|
|
2164
|
-
if (!(error instanceof ProbeTimeout))
|
|
2165
|
-
throw error;
|
|
2166
|
-
return {
|
|
2167
|
-
block: true,
|
|
2168
|
-
reason: `merge policy probe \`${error.message}\` timed out, so the merge cannot be checked; retry once git and wt answer promptly`
|
|
2169
|
-
};
|
|
2170
|
-
}
|
|
2171
|
-
}
|
|
2172
|
-
async function decideCommands(command, cwd, git, wt) {
|
|
2173
|
-
const collected = collectCommands(command);
|
|
2174
|
-
if (!collected.complete && /\bwt\b[\s\S]*\bmerge\b/.test(command))
|
|
2175
|
-
return { block: true, reason: UNPARSEABLE_MERGE_REFUSAL };
|
|
2176
|
-
if (collected.mergeVariables.size > 0 && collected.executed.some((word) => references(word, collected.mergeVariables)))
|
|
2177
|
-
return { block: true, reason: OPAQUE_DYNAMIC_MERGE_REFUSAL };
|
|
2178
|
-
const lead = leadingCd(command, cwd);
|
|
2179
|
-
const shellCwd = lead.kind === "dir" ? lead.dir : lead.kind === "none" ? cwd : undefined;
|
|
2180
|
-
for (const argv of collected.commands) {
|
|
2181
|
-
const invocation = parseMergeInvocation(argv);
|
|
2182
|
-
if (!invocation || invocation.target === null)
|
|
2183
|
-
continue;
|
|
2184
|
-
const target = invocation.target;
|
|
2185
|
-
const repoCwd = invocation.workdir?.startsWith("/") ? invocation.workdir : shellCwd === undefined ? undefined : invocation.workdir ? `${shellCwd}/${invocation.workdir}` : shellCwd;
|
|
2186
|
-
if (repoCwd === undefined)
|
|
2187
|
-
return { block: true, reason: UNKNOWN_DIRECTORY_MERGE_REFUSAL };
|
|
2188
|
-
const configured = await wt(["config", "state", "default-branch"], repoCwd);
|
|
2189
|
-
const symbolic = configured || await git(["symbolic-ref", "--short", "refs/remotes/origin/HEAD"], repoCwd);
|
|
2190
|
-
const defaultBranch = symbolic?.replace(/^origin\//, "");
|
|
2191
|
-
if (!defaultBranch)
|
|
2192
|
-
return { block: true, reason: `cannot determine the repository default branch; ${MERGE_RETRY}` };
|
|
2193
|
-
if (target === defaultBranch)
|
|
2194
|
-
continue;
|
|
2195
|
-
if (!invocation.noSquash || !invocation.noFf)
|
|
2196
|
-
return { block: true, reason: MERGE_POLICY_REFUSAL.replace("<target>", target) };
|
|
2197
|
-
const currentBranch = await git(["branch", "--show-current"], repoCwd);
|
|
2198
|
-
if (currentBranch === null) {
|
|
2199
|
-
return {
|
|
2200
|
-
block: true,
|
|
2201
|
-
reason: `\`git branch --show-current\` failed in ${repoCwd}, so the source branch cannot be checked; ${SOURCE_WORKTREE_RETRY.replace("<target>", target)}`
|
|
2202
|
-
};
|
|
2203
|
-
}
|
|
2204
|
-
if (!currentBranch || currentBranch === target) {
|
|
2205
|
-
return {
|
|
2206
|
-
block: true,
|
|
2207
|
-
reason: `worker-to-epic merges must run from the source worktree; retry with ${SOURCE_WORKTREE_RETRY.replace("<target>", target)}`
|
|
2208
|
-
};
|
|
2209
|
-
}
|
|
2210
|
-
}
|
|
2211
|
-
return;
|
|
2212
|
-
}
|
|
2213
|
-
|
|
2214
1936
|
// plugins/worktrunk/shared/preflight.ts
|
|
2215
|
-
import { accessSync, constants as constants2, existsSync, mkdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "fs";
|
|
2216
|
-
import { homedir } from "os";
|
|
2217
|
-
import { dirname, isAbsolute, join, resolve as resolve2 } from "path";
|
|
2218
1937
|
var APPROVALS_FIX = "wt config approvals add --yes";
|
|
2219
1938
|
var MERGE_FIX = "wt merge --no-squash --no-ff";
|
|
2220
1939
|
var WORKTREE_FIX = "wt switch -y --create --no-cd --base <base-commit> --format json <branch>";
|
|
@@ -2288,7 +2007,7 @@ function unavailable(command) {
|
|
|
2288
2007
|
return command.returncode === null;
|
|
2289
2008
|
}
|
|
2290
2009
|
function resolvePath(path) {
|
|
2291
|
-
const absolute =
|
|
2010
|
+
const absolute = resolve(path);
|
|
2292
2011
|
try {
|
|
2293
2012
|
return realpathSync(absolute);
|
|
2294
2013
|
} catch {
|
|
@@ -2393,7 +2112,7 @@ function parseJsonObject(text) {
|
|
|
2393
2112
|
}
|
|
2394
2113
|
return;
|
|
2395
2114
|
}
|
|
2396
|
-
var
|
|
2115
|
+
var ASSIGNMENT2 = /^[A-Za-z_][A-Za-z0-9_]*=/;
|
|
2397
2116
|
function isPathToken(token) {
|
|
2398
2117
|
return /^(?:\/|\.\/|\.\.\/|~\/)/.test(token) || token.includes("/") && !token.startsWith("-");
|
|
2399
2118
|
}
|
|
@@ -2414,7 +2133,7 @@ function commandWords2(command) {
|
|
|
2414
2133
|
if (tokens === undefined || tokens.length === 0)
|
|
2415
2134
|
return;
|
|
2416
2135
|
let index = 0;
|
|
2417
|
-
while (index < tokens.length &&
|
|
2136
|
+
while (index < tokens.length && ASSIGNMENT2.test(tokens[index]))
|
|
2418
2137
|
index++;
|
|
2419
2138
|
return index < tokens.length ? tokens.slice(index) : undefined;
|
|
2420
2139
|
}
|
|
@@ -3037,13 +2756,13 @@ async function runPreflight(options, ctx, checks = CHECKS) {
|
|
|
3037
2756
|
|
|
3038
2757
|
// plugins/worktrunk/shared/switch-timeout.ts
|
|
3039
2758
|
var SWITCH_TIMEOUT_MS = 600000;
|
|
3040
|
-
var
|
|
2759
|
+
var GLOBAL_VALUE_OPTIONS = new Set(["-C", "--config", "--config-set"]);
|
|
3041
2760
|
function isSwitch(argv) {
|
|
3042
2761
|
if (argv[0]?.split("/").pop() !== "wt")
|
|
3043
2762
|
return false;
|
|
3044
2763
|
let index = 1;
|
|
3045
2764
|
while (argv[index]?.startsWith("-"))
|
|
3046
|
-
index +=
|
|
2765
|
+
index += GLOBAL_VALUE_OPTIONS.has(argv[index] ?? "") ? 2 : 1;
|
|
3047
2766
|
return argv[index] === "switch" && !argv.includes("--help") && !argv.includes("-h");
|
|
3048
2767
|
}
|
|
3049
2768
|
function namesSwitchCommand(source) {
|
|
@@ -3059,17 +2778,11 @@ function switchTimeout(input) {
|
|
|
3059
2778
|
return;
|
|
3060
2779
|
return namesSwitchCommand(input.command) ? SWITCH_TIMEOUT_SECONDS : undefined;
|
|
3061
2780
|
}
|
|
3062
|
-
async function mergeGateBlock(event, cwd, probes) {
|
|
3063
|
-
if (!isToolCallEventType("bash", event) || !/merge/.test(event.input.command))
|
|
3064
|
-
return;
|
|
3065
|
-
const decision = await decideMergePolicy(event.input.command, cwd, probes);
|
|
3066
|
-
return decision === undefined ? undefined : { block: true, reason: decision.reason };
|
|
3067
|
-
}
|
|
3068
2781
|
function preflightDirectory(sessionDirectory, path) {
|
|
3069
2782
|
const raw = path?.replace(/^@/, "");
|
|
3070
2783
|
if (!raw)
|
|
3071
2784
|
return sessionDirectory;
|
|
3072
|
-
return isAbsolute2(raw) ? raw :
|
|
2785
|
+
return isAbsolute2(raw) ? raw : resolve2(sessionDirectory, raw);
|
|
3073
2786
|
}
|
|
3074
2787
|
var preflightParameters = Type.Object({
|
|
3075
2788
|
path: Type.Optional(Type.String({ description: "Repository directory; defaults to the session directory" })),
|
|
@@ -3082,13 +2795,13 @@ var preflightParameters = Type.Object({
|
|
|
3082
2795
|
});
|
|
3083
2796
|
function createExtension(overrides = {}) {
|
|
3084
2797
|
return (pi) => {
|
|
3085
|
-
pi.on("tool_call", async (event
|
|
2798
|
+
pi.on("tool_call", async (event) => {
|
|
3086
2799
|
if (!isToolCallEventType("bash", event))
|
|
3087
2800
|
return;
|
|
3088
2801
|
const longer = switchTimeout(event.input);
|
|
3089
2802
|
if (longer !== undefined)
|
|
3090
2803
|
event.input.timeout = longer;
|
|
3091
|
-
return
|
|
2804
|
+
return;
|
|
3092
2805
|
});
|
|
3093
2806
|
pi.registerTool({
|
|
3094
2807
|
name: "worktrunk_preflight",
|
|
@@ -3116,7 +2829,6 @@ export {
|
|
|
3116
2829
|
SWITCH_TIMEOUT_SECONDS,
|
|
3117
2830
|
createExtension,
|
|
3118
2831
|
worktrunk_default as default,
|
|
3119
|
-
mergeGateBlock,
|
|
3120
2832
|
preflightDirectory,
|
|
3121
2833
|
switchTimeout
|
|
3122
2834
|
};
|
package/package.json
CHANGED
|
@@ -38,8 +38,8 @@ Python). If an immediate test, typecheck, or dev server fails with missing-modul
|
|
|
38
38
|
## Merging
|
|
39
39
|
|
|
40
40
|
`wt merge <target>` merges the current branch, so run it from the source worktree. A worker-to-epic merge MUST pass
|
|
41
|
-
`--no-squash --no-ff` to keep per-commit history; an epic-to-default merge may be plain or squashing. This
|
|
42
|
-
|
|
41
|
+
`--no-squash --no-ff` to keep per-commit history; an epic-to-default merge may be plain or squashing. This is guidance: nothing
|
|
42
|
+
refuses a merge that breaks either rule, so check the target and flags before you run it.
|
|
43
43
|
|
|
44
44
|
## Ledger and the canonical checkout
|
|
45
45
|
|