werkmeister-core 0.94.3 → 0.95.0
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 +21 -0
- package/dist/archetypes.d.ts +1 -1
- package/dist/archetypes.js +5 -3
- package/dist/fixture_workspace.d.ts +4 -0
- package/dist/fixture_workspace.js +18 -10
- package/dist/harness/claude/claude_md.js +3 -3
- package/dist/harness/claude/hooks_gen.js +9 -4
- package/dist/issue_status.js +2 -1
- package/dist/issue_trackers/jira.d.ts +7 -0
- package/dist/issue_trackers/jira.js +55 -2
- package/dist/issues_report.js +2 -1
- package/dist/migrate.js +9 -4
- package/dist/pr_lifecycle.d.ts +33 -1
- package/dist/pr_lifecycle.js +160 -10
- package/dist/pr_rules.js +3 -3
- package/dist/sandbox.d.ts +1 -1
- package/dist/sandbox.js +3 -2
- package/dist/scheduler_state.d.ts +9 -3
- package/dist/scheduler_state.js +13 -8
- package/dist/sdk.d.ts +1 -1
- package/dist/sdk.js +1 -1
- package/dist/strategies/icm.js +5 -1
- package/dist/strategies/icm_templates.js +2 -0
- package/dist/temp_home.d.ts +1 -1
- package/dist/temp_home.js +13 -4
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# sandbox-core
|
|
2
2
|
|
|
3
|
+
## 0.95.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 8ce9825: SW-717: `werkmeister pr push [repo]` force-pushes an open PR's rebased branch with `--force-with-lease` on `origin/<branch>`, so a session finishes rule 5's conflict fix without the person. It refuses anything but the workspace's own checked-out branch, a dirty tree, a merge from the base, or a lease origin no longer matches. ICM workspaces pre-approve it; rule 5 and the conflict wake message name it. SDK: `pushPrs`.
|
|
8
|
+
- 6b0433e: SW-795: `werkmeister workspace abandon "<reason>"` (and the `close-out` MCP tool with `abandon`) now moves a Jira issue to Done instead of leaving it In Progress, so an abandoned ticket leaves the queue. The comment reads `Abandoned, not shipped: <reason>` and names the branch that holds `postmortem.md`. `--keep-open` (MCP `keep_open`) puts the issue back as To Do instead, for work parked to retry later. Set `issue_statuses.abandoned: null` to keep the old comment-only behaviour.
|
|
9
|
+
|
|
10
|
+
## 0.94.4
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- e5bfa35: The fixture's config.yaml sits at its temp HOME's `~/.werkmeister/config.yaml`, and `machine migrate` runs when `*_CONFIG_FILE` names that default path, so `with-fixture-workspace machine migrate` works (SW-581).
|
|
15
|
+
- 2a8f495: `with-temp-home` takes `--cwd <dir>` (after `--no-wait`) and runs its command there, whatever the shell's cwd; in the werkmeister container the same worktree maps to `/app`. The test commands in `werkmeister-context.md` and their allow rules now pass `--cwd <ws>/<repo>`, so they work from the workspace root too, still with no `cd` (SW-652). Rerun `werkmeister workspace init` to regenerate the file; `werkmeister machine migrate` refreshes the rules and the wrapper.
|
|
16
|
+
- 2775cec: The core, CLI and MCP test entries refuse to start when HOME holds the real `~/.werkmeister` and is not `with-temp-home`'s temp HOME, which every version of the wrapper marks by setting TMPDIR to it (SW-662).
|
|
17
|
+
- 47cd1d8: Tests only: `up_exit.test.ts` drops an inherited `WERKMEISTER_ROOT`, and the `waitForSetupLoad` tests restore `WERKMEISTER_NO_WAIT` (SW-671).
|
|
18
|
+
- eb7da8b: `werkmeister internal wait-load` decides exit 75 from the wait's structured result (`spent`, `note`), not by parsing its note (SW-716).
|
|
19
|
+
- 46c84f0: `with-temp-home` pins the daemon at `http://127.0.0.1:65535`, which is refused like a stopped daemon unless a test listener was handed that port (port 1 was rejected by fetch as a bad port), with a 500 ms retry (SW-743).
|
|
20
|
+
- 1f15a0f: Tests only: `daemon-client.test.mjs` no longer fails under a no-match `--test-name-pattern`, and a `test:no-match` check runs in CI (SW-816).
|
|
21
|
+
- a0625a5: `with-fixture-workspace --stale-compose` (with `--fragment-change`) inits the workspace before the branch's fragment lands, so `pr gate` starts the service from `compose.gate.yml`; in-process fixtures get `staleCompose` and `applyFragmentChange()` (SW-817).
|
|
22
|
+
- e65468d: Tests only: a guard test fails when a file in `shared-process.list` is missing or touches shared process state (SW-826).
|
|
23
|
+
|
|
3
24
|
## 0.94.3
|
|
4
25
|
|
|
5
26
|
### Patch Changes
|
package/dist/archetypes.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export declare function isPlainChain(cmd: string): boolean;
|
|
|
59
59
|
* so every part runs under the temp HOME (`with-temp-home a && b` wraps only `a`) and a `{ …; }`
|
|
60
60
|
* group is not a syntax error (SW-660).
|
|
61
61
|
*/
|
|
62
|
-
export declare function wrappedTestCommand(tempHome: string, test: string, lint?: string): string;
|
|
62
|
+
export declare function wrappedTestCommand(tempHome: string, test: string, lint?: string, repo?: string): string;
|
|
63
63
|
/**
|
|
64
64
|
* How to exercise a change to one service when it has no URL to hit.
|
|
65
65
|
*
|
package/dist/archetypes.js
CHANGED
|
@@ -126,13 +126,15 @@ export function isPlainChain(cmd) {
|
|
|
126
126
|
* so every part runs under the temp HOME (`with-temp-home a && b` wraps only `a`) and a `{ …; }`
|
|
127
127
|
* group is not a syntax error (SW-660).
|
|
128
128
|
*/
|
|
129
|
-
export function wrappedTestCommand(tempHome, test, lint) {
|
|
129
|
+
export function wrappedTestCommand(tempHome, test, lint, repo) {
|
|
130
130
|
const full = lint ? `${lint} && ${test}` : test;
|
|
131
131
|
if (!tempHome)
|
|
132
132
|
return full;
|
|
133
|
+
// SW-652: from *repo*'s worktree (<ws>/<repo>; tempHome is <ws>/.werkmeister/bin/…), whatever the shell's cwd.
|
|
134
|
+
const wrapper = repo ? `${tempHome} --cwd ${path.resolve(tempHome, "../../..", repo)}` : tempHome;
|
|
133
135
|
if (isPlainChain(full) && !full.includes("&&"))
|
|
134
|
-
return `${
|
|
135
|
-
return `${
|
|
136
|
+
return `${wrapper} ${full}`;
|
|
137
|
+
return `${wrapper} sh -c '${full.split("'").join(`'\\''`)}'`;
|
|
136
138
|
}
|
|
137
139
|
/**
|
|
138
140
|
* How to exercise a change to one service when it has no URL to hit.
|
|
@@ -44,6 +44,8 @@ export interface FixtureOptions {
|
|
|
44
44
|
slotsFull?: boolean;
|
|
45
45
|
/** The first repo's `.werkmeister/services.yaml` on the branch, committed over a base fragment on main (`fragment`, else the default registry's), so the gate's fragment row compares the two (SW-664). */
|
|
46
46
|
fragmentChange?: string;
|
|
47
|
+
/** With `fragmentChange`: hold the branch's fragment back until `applyFragmentChange`, so a `workspace init` run first renders compose.yml from the base fragment and `pr gate` sees the branch settings as changed (SW-817). */
|
|
48
|
+
staleCompose?: boolean;
|
|
47
49
|
/** The texts `change` holds on main and on the branch, instead of `base` and `changed`, e.g. two pnpm-lock.yaml copies (SW-696). */
|
|
48
50
|
changeBase?: string;
|
|
49
51
|
changeBranch?: string;
|
|
@@ -85,6 +87,8 @@ export interface Fixture {
|
|
|
85
87
|
repo: string;
|
|
86
88
|
ghLog: string;
|
|
87
89
|
dockerLog: string;
|
|
90
|
+
/** With `staleCompose`: commit the branch's held-back fragment (SW-817). */
|
|
91
|
+
applyFragmentChange?: () => void;
|
|
88
92
|
/** What a process needs to run against the fixture, HOME (`<root>/home`, empty) included. */
|
|
89
93
|
env: Record<string, string>;
|
|
90
94
|
}
|
|
@@ -122,7 +122,9 @@ export function seedFixture(root, opts = {}) {
|
|
|
122
122
|
const repos = opts.repos ?? [{ name: "app" }];
|
|
123
123
|
write(path.join(root, "services.yaml"), opts.services ?? SERVICES);
|
|
124
124
|
write(path.join(root, "ports.yaml"), PORTS);
|
|
125
|
-
|
|
125
|
+
// At the temp HOME's default path, so `machine migrate` treats it as the home it is (SW-581).
|
|
126
|
+
const home = path.join(root, "home");
|
|
127
|
+
const configFile = path.join(dotDir(home), "config.yaml");
|
|
126
128
|
write(configFile, `version: 1
|
|
127
129
|
paths:
|
|
128
130
|
repos_root: ${root}/repos
|
|
@@ -156,6 +158,7 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
|
|
|
156
158
|
// status goes in verbatim, so a brief can try the forms people write, comments included (SW-549).
|
|
157
159
|
const { status = "approved", ...prFields } = opts.prFields ?? {};
|
|
158
160
|
const extra = Object.keys(prFields).length ? YAML.stringify(prFields) : "";
|
|
161
|
+
let applyFragmentChange;
|
|
159
162
|
for (const { name, change } of repos) {
|
|
160
163
|
// Ends in owner/repo.git so originSlug matches the PR file's repo: (SW-381).
|
|
161
164
|
const remote = path.join(root, "remotes", "o", `${name}.git`);
|
|
@@ -193,13 +196,18 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
|
|
|
193
196
|
git(source, "push", "-q", "origin", "HEAD:main");
|
|
194
197
|
}
|
|
195
198
|
git(source, "switch", "-q", "-c", "fixture-source");
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
199
|
+
const held = opts.staleCompose && frag !== undefined;
|
|
200
|
+
if (change)
|
|
201
|
+
write(path.join(repo, change), opts.changeBranch ?? "changed\n");
|
|
202
|
+
if (frag !== undefined && !held)
|
|
203
|
+
write(path.join(repo, FRAGMENT_FILE), frag);
|
|
204
|
+
if (change || (frag !== undefined && !held))
|
|
205
|
+
git(repo, "commit", "-q", "-am", `change ${changed.filter((f) => !held || f !== FRAGMENT_FILE).join(", ")}`);
|
|
206
|
+
if (held)
|
|
207
|
+
applyFragmentChange = () => {
|
|
200
208
|
write(path.join(repo, FRAGMENT_FILE), frag);
|
|
201
|
-
|
|
202
|
-
|
|
209
|
+
git(repo, "commit", "-q", "-am", `change ${FRAGMENT_FILE}`);
|
|
210
|
+
};
|
|
203
211
|
if (opts.prFile && changed.length)
|
|
204
212
|
write(path.join(notes, `pr-${name}.md`), `---\nrepo: o/${name}\nbranch: ${FIXTURE_BRANCH}\nbase: main\nstatus: ${status}\n${extra}---\n# feat: fixture change\n\n${PASS}`);
|
|
205
213
|
}
|
|
@@ -259,8 +267,7 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
|
|
|
259
267
|
fs.mkdirSync(ws, { recursive: true });
|
|
260
268
|
return [c.feature, ws, c.startedAt, c.memory, c.nanoCpus].join("\t");
|
|
261
269
|
});
|
|
262
|
-
|
|
263
|
-
fs.mkdirSync(home);
|
|
270
|
+
fs.mkdirSync(home, { recursive: true });
|
|
264
271
|
const fakes = writeFakes(path.join(root, "bin"), {
|
|
265
272
|
prUrl: `https://github.com/${FIXTURE_REPO_SLUG}/pull/1`,
|
|
266
273
|
running: opts.running ?? [],
|
|
@@ -272,6 +279,7 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
|
|
|
272
279
|
});
|
|
273
280
|
return {
|
|
274
281
|
root,
|
|
282
|
+
applyFragmentChange,
|
|
275
283
|
configFile,
|
|
276
284
|
workspace,
|
|
277
285
|
repo: path.join(workspace, repos[0].name),
|
|
@@ -320,7 +328,7 @@ const SCRIPT = `#!/bin/sh
|
|
|
320
328
|
# Generated by \`werkmeister workspace init\` (SW-292); rerun it to regenerate.
|
|
321
329
|
# Runs this workspace's own built werkmeister CLI against a seeded fixture workspace, removed on exit:
|
|
322
330
|
# temp HOME and registry, a local bare origin, logging fakes for gh and docker, dead Docker and daemon.
|
|
323
|
-
# usage: with-fixture-workspace [--no-wait] [--gate] [--bare] [--daemon] [--exec-runs] [--merged] [--behind] [--slots-full] [--running <file>] [--queue <feature>[,<feature>]... | --queue <feature>:<waitedMin>[:<service>,...]]... [--issue <ref>] [--pr-field <key>=<value>]... [--workspace <file>] [--config <file>] [--services <file>] [--fragment <file>] [--change <path>] [--change-base <file>] [--change-branch <file>] [--fragment-change <file>] [--print <file>]... <werkmeister args> [--then <werkmeister args>]...
|
|
331
|
+
# usage: with-fixture-workspace [--no-wait] [--gate] [--bare] [--daemon] [--exec-runs] [--merged] [--behind] [--slots-full] [--running <file>] [--queue <feature>[,<feature>]... | --queue <feature>:<waitedMin>[:<service>,...]]... [--issue <ref>] [--pr-field <key>=<value>]... [--workspace <file>] [--config <file>] [--services <file>] [--fragment <file>] [--change <path>] [--change-base <file>] [--change-branch <file>] [--fragment-change <file>] [--stale-compose] [--print <file>]... <werkmeister args> [--then <werkmeister args>]...
|
|
324
332
|
# It only ever runs that CLI, never another command, so one allow rule can cover it (SW-172, SW-231);
|
|
325
333
|
# --exec-runs, given first, also runs the registry's rows on the host, so the workspace asks before it (SW-473).
|
|
326
334
|
ws=$(cd "$(dirname "$0")/../.." && pwd -P) || exit 1
|
|
@@ -267,7 +267,7 @@ function testCommandLine(feature, svc, servicesConfig, archetypes, lint, tempHom
|
|
|
267
267
|
: `- \`${svc}\`: no test command registered (add \`test:\` to its registry entry)`;
|
|
268
268
|
}
|
|
269
269
|
/** SW-720: in sw-700 host `node`, a compound line and `docker exec … node <script>` were each denied before this form ran. */
|
|
270
|
-
const PROBE_FORM = (tempHome) => `A one-off probe is a \`node --test\` file, run as \`${tempHome} --no-wait node --test <file>\` (in the service's container, after its \`docker exec -w <dir> <container>\`, when the host has no node_modules); never host \`node <script>\`, a compound shell line or \`docker exec … node <script>\`. That form asks each time and is never pre-approved, since it runs any file (SW-510).`;
|
|
270
|
+
const PROBE_FORM = (tempHome) => `A one-off probe is a \`node --test\` file, run as \`${tempHome} --no-wait node --test <file>\` (in the service's container, after its \`docker exec -w <dir> <container>\`, when the host has no node_modules); never host \`node <script>\`, a compound shell line or \`docker exec … node <script>\`. That form, with no \`--cwd\` (pass the file's path instead), asks each time and is never pre-approved, since it runs any file (SW-510); with \`--cwd\` it matches no rule and auto mode denies it (SW-652).`;
|
|
271
271
|
// SW-765: sw-753's spec planned to delete turbo cache entries, not knowing the cache is one volume every workspace shares.
|
|
272
272
|
function sharedCachesLine(caches) {
|
|
273
273
|
const entries = Object.entries(caches);
|
|
@@ -342,7 +342,7 @@ export function buildSandboxContextMd(feature, slot, portStart, portEnd, localSe
|
|
|
342
342
|
const testCell = (r) => {
|
|
343
343
|
if (!r.test)
|
|
344
344
|
return "—";
|
|
345
|
-
return `\`${wrappedTestCommand(tempHome, r.test, lintOf(r.repo))}\``;
|
|
345
|
+
return `\`${wrappedTestCommand(tempHome, r.test, lintOf(r.repo), r.repo)}\``;
|
|
346
346
|
};
|
|
347
347
|
// SW-705: the gate tests every service a change reaches, so the table lists the candidates' whole repos.
|
|
348
348
|
// Each service's own `repo:`, not repos.<repo>.services: only registry sync fills that list.
|
|
@@ -532,7 +532,7 @@ How to exercise a change to each service in this workspace.${extraRows
|
|
|
532
532
|
: ""}${onDemand.length
|
|
533
533
|
? ` A plain \`werkmeister feature up\` skips the on-demand ones, ${onDemand.map((s) => `\`${s}\``).join(", ")}: start one with \`werkmeister feature up --service <name>\`.`
|
|
534
534
|
: ""}${tempHome
|
|
535
|
-
? ` Each test command runs through \`.werkmeister/bin/with-temp-home\`, which gives it a fresh temporary HOME and deletes it on exit: never hand-roll \`HOME=…\`. Start every exercise command with the script itself, never with env assignments or a \`cd\`, so one permission rule matches it: \`${tempHome} <test command>\`. A command that needs an env var takes it after the script (\`${tempHome} env WERKMEISTER_ROOT=… <cmd>\`); no rule pre-approves that form, so it asks. Put \`--no-wait\` first (\`${tempHome} --no-wait <cmd>\`) to skip its host-load and free-memory wait; the allow rules below cover that form too. That wait lasts up to 90 s; if load or memory is still over its limit then, the script exits 75 without running the command (retry later). It prints only on stderr, so a foreground call shows nothing until it ends and its only child is \`werkmeister internal wait-load\`: that is the wait, not a hang. The allow rule that covers them is \`Bash(${tempHome} <test command>:*)\` for each test command below: run those for a test without a prompt. A test command of more than one command (an \`&&\` chain, a \`{ …; }\` group, \`||\`, \`;\` or a pipe) is shown as \`${tempHome} sh -c '…'\`, so every part runs under the temp HOME, and its rule allows that exact line: run it as shown, with no extra arguments. ${PROBE_FORM(tempHome)} The script alone is never allowed either, since it runs any command. The temp HOME only keeps a run from writing to the real one by accident; it is not an isolation boundary. A pre-approved test command or built CLI still runs whatever the worktree holds, a test written in this run included, and that code can reach absolute paths, the caller's env, the network, docker and gh (SW-522).`
|
|
535
|
+
? ` Each test command runs through \`.werkmeister/bin/with-temp-home\`, which gives it a fresh temporary HOME and deletes it on exit: never hand-roll \`HOME=…\`. Start every exercise command with the script itself, never with env assignments or a \`cd\`, so one permission rule matches it: \`${tempHome} --cwd <worktree> <test command>\`. Its \`--cwd <worktree>\` runs the command from that service's worktree, whatever the shell's cwd, so it works from the workspace root too (SW-652). A command that needs an env var takes it after the script (\`${tempHome} env WERKMEISTER_ROOT=… <cmd>\`); no rule pre-approves that form, so it asks. Put \`--no-wait\` first (\`${tempHome} --no-wait <cmd>\`) to skip its host-load and free-memory wait; the allow rules below cover that form too. That wait lasts up to 90 s; if load or memory is still over its limit then, the script exits 75 without running the command (retry later). It prints only on stderr, so a foreground call shows nothing until it ends and its only child is \`werkmeister internal wait-load\`: that is the wait, not a hang. The allow rule that covers them is \`Bash(${tempHome} --cwd <worktree> <test command>:*)\` for each test command below: run those for a test without a prompt. A test command of more than one command (an \`&&\` chain, a \`{ …; }\` group, \`||\`, \`;\` or a pipe) is shown as \`${tempHome} --cwd <worktree> sh -c '…'\`, so every part runs under the temp HOME, and its rule allows that exact line: run it as shown, with no extra arguments. ${PROBE_FORM(tempHome)} The script alone is never allowed either, since it runs any command. The temp HOME only keeps a run from writing to the real one by accident; it is not an isolation boundary. A pre-approved test command or built CLI still runs whatever the worktree holds, a test written in this run included, and that code can reach absolute paths, the caller's env, the network, docker and gh (SW-522).`
|
|
536
536
|
: ""}${linted
|
|
537
537
|
? " A test command starting with `<lint> &&` first runs the repo's lint, the same command the PR gate's lint row runs, so a format error fails here, before the tests, and not first at `werkmeister pr open`."
|
|
538
538
|
: ""} ${HOST_SCRIPT_RULE}
|
|
@@ -443,10 +443,15 @@ hostServices = [], reposConfig = {}) {
|
|
|
443
443
|
}
|
|
444
444
|
if (!tempHome)
|
|
445
445
|
continue;
|
|
446
|
-
const
|
|
447
|
-
const
|
|
448
|
-
|
|
449
|
-
|
|
446
|
+
const repo = servicesConfig[svc]?.["repo"];
|
|
447
|
+
const lint = reposConfig[String(repo ?? "")]?.lint;
|
|
448
|
+
const wrapped = wrappedTestCommand(tempHome, cmd, lint, repo ? String(repo) : undefined);
|
|
449
|
+
// Exact for an `sh -c` line: a prefix would let `; <anything>` ride after the quote. Past any --cwd (SW-652).
|
|
450
|
+
const shC = wrapped
|
|
451
|
+
.slice(tempHome.length)
|
|
452
|
+
.replace(/^ --cwd \S+/, "")
|
|
453
|
+
.startsWith(" sh -c '");
|
|
454
|
+
rules.push(shC ? `Bash(${wrapped})` : `Bash(${wrapped}:*)`);
|
|
450
455
|
}
|
|
451
456
|
if (tempHome)
|
|
452
457
|
for (const cli of builtClis)
|
package/dist/issue_status.js
CHANGED
|
@@ -16,7 +16,8 @@ const DEFAULTS = {
|
|
|
16
16
|
in_review: "In Review",
|
|
17
17
|
merged: null,
|
|
18
18
|
done: "Done",
|
|
19
|
-
|
|
19
|
+
// No Won't Do in a default Jira workflow; the abandon comment says it wasn't shipped (SW-795).
|
|
20
|
+
abandoned: "Done",
|
|
20
21
|
},
|
|
21
22
|
github: {
|
|
22
23
|
in_progress: "status: in progress",
|
|
@@ -20,6 +20,13 @@ export declare function jiraSitePhrase(): string;
|
|
|
20
20
|
* spans, fenced blocks and links.
|
|
21
21
|
*/
|
|
22
22
|
export declare function markdownToWiki(md: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Jira wiki markup (REST v2's description and comment bodies) as Markdown, so
|
|
25
|
+
* `.werkmeister/issue.md` and `issue view` read cleanly (SW-878): headings,
|
|
26
|
+
* lists, bold, `{{monospace}}`, links and smart links, `{code}` / `{noformat}`
|
|
27
|
+
* blocks, and backslash escapes. The reverse of {@link markdownToWiki}.
|
|
28
|
+
*/
|
|
29
|
+
export declare function wikiToMarkdown(wiki: string): string;
|
|
23
30
|
/** Jira, narrowed to `scope.project`'s keys when set (SW-104). The site stays the machine's `jira:` block. */
|
|
24
31
|
export declare function jiraTracker(scope?: TrackerScope): IssueTrackerStrategy;
|
|
25
32
|
export declare const jira: IssueTrackerStrategy;
|
|
@@ -48,7 +48,15 @@ function fromRest(r) {
|
|
|
48
48
|
const f = r.fields ?? {};
|
|
49
49
|
const comments = (f.comment?.comments ?? []).flatMap((c) => {
|
|
50
50
|
const body = c.body?.trim();
|
|
51
|
-
return body
|
|
51
|
+
return body
|
|
52
|
+
? [
|
|
53
|
+
{
|
|
54
|
+
author: c.author?.displayName ?? "unknown",
|
|
55
|
+
created: c.created,
|
|
56
|
+
body: wikiToMarkdown(body),
|
|
57
|
+
},
|
|
58
|
+
]
|
|
59
|
+
: [];
|
|
52
60
|
});
|
|
53
61
|
return {
|
|
54
62
|
ref: r.key,
|
|
@@ -57,7 +65,7 @@ function fromRest(r) {
|
|
|
57
65
|
statusCategory: category(f.status?.statusCategory?.key),
|
|
58
66
|
type: str(f.issuetype?.name),
|
|
59
67
|
assignee: str(f.assignee?.displayName),
|
|
60
|
-
description: str(f.description),
|
|
68
|
+
description: f.description ? wikiToMarkdown(String(f.description)) : str(f.description),
|
|
61
69
|
url: jiraBrowseUrl(r.key) ?? undefined,
|
|
62
70
|
comments,
|
|
63
71
|
};
|
|
@@ -169,6 +177,51 @@ export function markdownToWiki(md) {
|
|
|
169
177
|
})
|
|
170
178
|
.join("\n");
|
|
171
179
|
}
|
|
180
|
+
/** A wiki escape (`\-`, `\{`) as its bare character. */
|
|
181
|
+
const unescapeWiki = (s) => s.replace(/\\([-{}!*_+^~[\]|#()\\])/g, "$1");
|
|
182
|
+
/**
|
|
183
|
+
* Jira wiki markup (REST v2's description and comment bodies) as Markdown, so
|
|
184
|
+
* `.werkmeister/issue.md` and `issue view` read cleanly (SW-878): headings,
|
|
185
|
+
* lists, bold, `{{monospace}}`, links and smart links, `{code}` / `{noformat}`
|
|
186
|
+
* blocks, and backslash escapes. The reverse of {@link markdownToWiki}.
|
|
187
|
+
*/
|
|
188
|
+
// shortcut: line-based like markdownToWiki; tables, colours, panels and quotes pass through as text.
|
|
189
|
+
export function wikiToMarkdown(wiki) {
|
|
190
|
+
let fence = false;
|
|
191
|
+
const inline = (s) => s
|
|
192
|
+
// An escape (`\}`) never closes a span, and `{{{{x}}}}` (braces shown in code) closes at the last `}}`.
|
|
193
|
+
.split(/(\{\{(?:\\.|[^\\\n])*?\}\}(?!\}))/)
|
|
194
|
+
.map((p) => p.startsWith("{{") && p.endsWith("}}") && p.length > 4
|
|
195
|
+
? `\`${unescapeWiki(p.slice(2, -2))}\``
|
|
196
|
+
: unescapeWiki(p
|
|
197
|
+
.replace(/\[([^|\]\n]+)\|([^|\]\s]+)(?:\|smart-link)?\]/g, (_m, text, url) => {
|
|
198
|
+
// A smart link's text is its URL; show the key the URL ends in.
|
|
199
|
+
const key = text === url ? /\/browse\/([A-Z][A-Z0-9]+-\d+)$/.exec(url)?.[1] : null;
|
|
200
|
+
return `[${key ?? text}](${url})`;
|
|
201
|
+
})
|
|
202
|
+
.replace(/(?<![\\\w*])\*(?=\S)([^*\n]*?\S)\*(?![\w*])/g, "**$1**")))
|
|
203
|
+
.join("");
|
|
204
|
+
return wiki
|
|
205
|
+
.split("\n")
|
|
206
|
+
.map((line) => {
|
|
207
|
+
if (/^\s*\{(code|noformat)(:[^}]*)?\}\s*$/.test(line)) {
|
|
208
|
+
fence = !fence;
|
|
209
|
+
return "```";
|
|
210
|
+
}
|
|
211
|
+
if (fence)
|
|
212
|
+
return line;
|
|
213
|
+
const h = /^h([1-6])\.\s+(.*)$/.exec(line);
|
|
214
|
+
if (h)
|
|
215
|
+
return `${"#".repeat(Number(h[1]))} ${inline(h[2])}`;
|
|
216
|
+
const li = /^([*#-]+)\s+(.*)$/.exec(line);
|
|
217
|
+
if (li) {
|
|
218
|
+
const indent = " ".repeat(li[1].length - 1);
|
|
219
|
+
return `${indent}${li[1].endsWith("#") ? "1." : "-"} ${inline(li[2])}`;
|
|
220
|
+
}
|
|
221
|
+
return inline(line);
|
|
222
|
+
})
|
|
223
|
+
.join("\n");
|
|
224
|
+
}
|
|
172
225
|
/** Werkmeister issues go to GitHub unless `overrides.werkmeister_issues_project` names a Jira project; issues_report.ts names it too. */
|
|
173
226
|
const WERKMEISTER_ISSUES_REPO = "jbbz-sandbox/werkmeister";
|
|
174
227
|
const NO_REST = "no Jira REST credentials: set jira.base_url, jira.email and jira.api_token (docs/issue-trackers.md), " +
|
package/dist/issues_report.js
CHANGED
|
@@ -64,7 +64,8 @@ ${appRow}
|
|
|
64
64
|
1. ${searchStep}
|
|
65
65
|
2. Title: one-line summary. Label or issue type: from the type table. Body: the template for its type, via \`--body-file\`.
|
|
66
66
|
3. Paste exact commands and error output — don't paraphrase.
|
|
67
|
-
4.
|
|
67
|
+
4. Cite this run's own files (\`stages/*/output/*\`, scripts it wrote) by this workspace's record branch on the workspace repo (\`git -C <workspace root> branch --show-current\`) plus the path, or a permalink at the pushed commit, never by the workspace folder: close-out removes the folder, and the issue is usually worked after that.
|
|
68
|
+
5. Tell the person the issue URL, then resume what you were doing.
|
|
68
69
|
|
|
69
70
|
## Body template: bug
|
|
70
71
|
|
package/dist/migrate.js
CHANGED
|
@@ -14,7 +14,7 @@ import * as os from "node:os";
|
|
|
14
14
|
import * as path from "node:path";
|
|
15
15
|
import { parse as parseYaml } from "yaml";
|
|
16
16
|
import { COMPOSE_FILE, LEGACY_COMPOSE_FILE } from "./compose_file.js";
|
|
17
|
-
import { configPath, envVar, expandUser, sandboxHome, servicesLocalYamlPath, servicesYamlPath, workspacesRoot, } from "./config.js";
|
|
17
|
+
import { configPath, envVar, expandUser, isFixture, sandboxHome, servicesLocalYamlPath, servicesYamlPath, workspacesRoot, } from "./config.js";
|
|
18
18
|
import { docker } from "./docker.js";
|
|
19
19
|
import { DOT_DIR, dotDir } from "./dot_dir.js";
|
|
20
20
|
import { writeFixtureWrapper } from "./fixture_workspace.js";
|
|
@@ -113,7 +113,8 @@ export async function migrate(opts = {}) {
|
|
|
113
113
|
const legacy = path.join(home, LEGACY_DOT_DIR);
|
|
114
114
|
const target = path.join(home, DOT_DIR);
|
|
115
115
|
const would = (did, will) => (checkOnly ? will : did);
|
|
116
|
-
|
|
116
|
+
// One that names the default path (the fixture's, SW-581) moves nothing elsewhere, so migrate runs.
|
|
117
|
+
if (envVar("CONFIG_FILE") && path.resolve(configPath()) !== path.join(target, "config.yaml")) {
|
|
117
118
|
return [
|
|
118
119
|
{
|
|
119
120
|
label: "tool home",
|
|
@@ -227,9 +228,13 @@ export async function migrate(opts = {}) {
|
|
|
227
228
|
steps.push(...syncRegistry());
|
|
228
229
|
}
|
|
229
230
|
// Its log path is the home; in --check before the move, `current` is judged against the old one.
|
|
230
|
-
const prWatch = prWatchScheduleState(opts.prWatch);
|
|
231
231
|
const prLabel = "pr-watch schedule";
|
|
232
|
-
|
|
232
|
+
// crontab isn't scoped by HOME: a fixture run must not rewrite the caller's real one (SW-581).
|
|
233
|
+
const prWatch = isFixture() ? undefined : prWatchScheduleState(opts.prWatch);
|
|
234
|
+
if (!prWatch) {
|
|
235
|
+
steps.push({ label: prLabel, ok: true, detail: "skipped in the fixture" });
|
|
236
|
+
}
|
|
237
|
+
else if (!prWatch.installed) {
|
|
233
238
|
steps.push({ label: prLabel, ok: true, detail: "not installed" });
|
|
234
239
|
}
|
|
235
240
|
else if (prWatch.current && !(checkOnly && moving)) {
|
package/dist/pr_lifecycle.d.ts
CHANGED
|
@@ -653,6 +653,35 @@ export declare function originBase(dir: string, run?: Run): Promise<string>;
|
|
|
653
653
|
/** Commits on *dir*'s HEAD that *base* (default: origin's default branch) lacks; null when git can't tell. */
|
|
654
654
|
export declare function commitsAhead(dir: string, base?: string, run?: Run): Promise<number | null>;
|
|
655
655
|
export declare function renderCloseout(prs: PrFile[], issue: string, note?: string): string;
|
|
656
|
+
/** Merge commits on HEAD since `origin/<base>`, or null when git can't count them; the gate (SW-733) and `pr push` (SW-717) refuse any. */
|
|
657
|
+
export declare function mergesFromBase(dir: string, base: string, run: Run): Promise<number | null>;
|
|
658
|
+
/**
|
|
659
|
+
* Force-pushes each open PR's rebased branch with a lease, so a session can finish rule 5's
|
|
660
|
+
* conflict fix without the person. The lease is `origin/<branch>` as last fetched, never
|
|
661
|
+
* typed by the agent. Refuses, and pushes nothing for that file, unless: the worktree is one of
|
|
662
|
+
* this workspace's own (checked without git); the branch is this workspace's own (the PR file's `branch:`, checked out, `<user>/<workspace>[-<slug>]`, not the
|
|
663
|
+
* base); the worktree is clean; it holds no merge commit from its base; and origin still has the
|
|
664
|
+
* leased head.
|
|
665
|
+
*
|
|
666
|
+
* @param ws - The workspace folder.
|
|
667
|
+
* @param only - A code worktree's directory name or a PR file's name, as for `pr gate`.
|
|
668
|
+
* @param deps - The services it uses; leave it at its default.
|
|
669
|
+
* @returns `ok`, false when any file was refused or its push failed; `lines`, one per PR file.
|
|
670
|
+
*
|
|
671
|
+
* @example
|
|
672
|
+
* ```ts
|
|
673
|
+
* import { pushPrs } from "werkmeister-core/sdk";
|
|
674
|
+
*
|
|
675
|
+
* const { ok, lines } = await pushPrs("/work/my-workspace");
|
|
676
|
+
* console.log(ok, lines.join("\n"));
|
|
677
|
+
* ```
|
|
678
|
+
*/
|
|
679
|
+
export declare function pushPrs(ws: string, only?: string, deps?: Deps): Promise<{
|
|
680
|
+
/** False when any PR file was refused or its push failed. */
|
|
681
|
+
ok: boolean;
|
|
682
|
+
/** One line per PR file: pushed, refused and why, or failed. */
|
|
683
|
+
lines: string[];
|
|
684
|
+
}>;
|
|
656
685
|
/** `--abandon`: record *why* on every unsettled PR file and in closeout.md. */
|
|
657
686
|
export declare function abandonWorkspace(ws: string, why: string): void;
|
|
658
687
|
/**
|
|
@@ -675,7 +704,9 @@ export declare function openTerminalSessions(ws: string, run?: Run, ownedDir?: s
|
|
|
675
704
|
*
|
|
676
705
|
* @param name - The workspace's folder name.
|
|
677
706
|
* @param opts - `abandon`: give up on unshipped work with this reason; the issue
|
|
678
|
-
*
|
|
707
|
+
* moves to its `abandoned` status (Jira: Done) with the reason and the post-mortem's
|
|
708
|
+
* branch as a comment, and every branch is pushed and kept.
|
|
709
|
+
* `keepOpen`: with `abandon`, put the issue back as To Do (GitHub: left open, comment only) instead.
|
|
679
710
|
* `noPr`: the work changed no repo, so close it as done with this reason instead of a PR.
|
|
680
711
|
* `skipPostmortem`: close without a `postmortem.md`, with this reason.
|
|
681
712
|
* Each needs a non-empty reason; `noPr` can't be combined with the other two.
|
|
@@ -705,6 +736,7 @@ export declare function closeOut(name: string, opts?: {
|
|
|
705
736
|
abandon?: string;
|
|
706
737
|
skipPostmortem?: string;
|
|
707
738
|
noPr?: string;
|
|
739
|
+
keepOpen?: boolean;
|
|
708
740
|
}, deps?: Deps): Promise<{
|
|
709
741
|
/** The equivalent CLI command, e.g. `werkmeister workspace close <name>`. */
|
|
710
742
|
command: string;
|
package/dist/pr_lifecycle.js
CHANGED
|
@@ -14,7 +14,7 @@ import YAML from "yaml";
|
|
|
14
14
|
import { clearNotice, raiseNotice, writeWakeNudge } from "./agent_state.js";
|
|
15
15
|
import { serviceNoTests, serviceTestCommand } from "./archetypes.js";
|
|
16
16
|
import { COMPOSE_FILE } from "./compose_file.js";
|
|
17
|
-
import { containerOf, dotDir, IDLE_SERVICE_TYPES, isFixture, loadArchetypes, loadReposConfig, loadServices, sandboxHome, servicesYamlPath, } from "./config.js";
|
|
17
|
+
import { containerOf, dotDir, getReposRoot, IDLE_SERVICE_TYPES, isFixture, loadArchetypes, loadReposConfig, loadServices, sandboxHome, servicesYamlPath, } from "./config.js";
|
|
18
18
|
import { GATE_COMPOSE_FILE, renderGateCompose } from "./generate.js";
|
|
19
19
|
import { updateNoteStatus } from "./graduate.js";
|
|
20
20
|
import { eachIssue, issueStatuses, moveIssue } from "./issue_status.js";
|
|
@@ -760,7 +760,7 @@ testsOnly = false) {
|
|
|
760
760
|
const why = res.code ? retryIf(res) : null;
|
|
761
761
|
if (why) {
|
|
762
762
|
// Only before this one retry: the gate itself never waits on load (SW-542).
|
|
763
|
-
const waited = await waitForHostLoadNow(deps, undefined, "the gate's retry");
|
|
763
|
+
const { note: waited } = await waitForHostLoadNow(deps, undefined, "the gate's retry");
|
|
764
764
|
res = await exec();
|
|
765
765
|
lines[0] = `${cmd} → exit ${res.code}, retried once after ${why}${waited ? `; ${waited}` : ""}`;
|
|
766
766
|
}
|
|
@@ -868,10 +868,19 @@ testsOnly = false) {
|
|
|
868
868
|
add("base", behind.code === 0 && (count === 0 || pushed), behind.code
|
|
869
869
|
? `cannot check against origin/${base}: ${(behind.stderr || behind.stdout).trim()}`
|
|
870
870
|
: pushed
|
|
871
|
-
? `${commits}; ${branch} is already pushed, so \`pr watch\` flags a conflict
|
|
871
|
+
? `${commits}; ${branch} is already pushed, so \`pr watch\` flags a conflict; after a rebase \`werkmeister pr push\` force-pushes it with a lease (rule 5)${also}`
|
|
872
872
|
: count
|
|
873
873
|
? `${commits} — \`git -C ${file.dir} rebase origin/${base}\` (keeps one commit per ticket), rerun the tests, then rerun${also}`
|
|
874
874
|
: `up to date with origin/${base}`);
|
|
875
|
+
if (behind.code === 0) {
|
|
876
|
+
const merges = await mergesFromBase(dir, base, deps.run);
|
|
877
|
+
add("merges", merges === 0, merges === null
|
|
878
|
+
? `cannot count merge commits in origin/${base}..HEAD`
|
|
879
|
+
: merges
|
|
880
|
+
? `${merges} merge commit${merges === 1 ? "" : "s"} in origin/${base}..HEAD — a rebase merge queue replays only non-merge commits, so a conflict a merge resolved comes back. ` +
|
|
881
|
+
`Rebase instead: \`git -C ${file.dir} rebase origin/${base}\` (rule 5), rerun the tests, then rerun`
|
|
882
|
+
: "no merge commits");
|
|
883
|
+
}
|
|
875
884
|
const status = await deps.run("git", ["-C", dir, "status", "--porcelain"]);
|
|
876
885
|
add("clean", status.code === 0 && status.stdout.trim() === "", status.code
|
|
877
886
|
? status.stderr.trim()
|
|
@@ -1976,8 +1985,10 @@ const conflictSteps = (e) => [
|
|
|
1976
1985
|
` Rebase, never merge ${e.base} in (GitHub can't rebase-merge a branch with a merge from its base):`,
|
|
1977
1986
|
` git -C ${e.dir} fetch origin ${e.base} && git -C ${e.dir} rebase origin/${e.base}`,
|
|
1978
1987
|
` A conflict in a generated file (a snapshot, a lockfile): take ${e.base}'s copy and regenerate it; never hand-merge it.`,
|
|
1979
|
-
|
|
1980
|
-
|
|
1988
|
+
// SW-717: the lease is origin/<branch> as last fetched, so the session pushes its own branch.
|
|
1989
|
+
" Then push it (a lease on origin's head; refuses anything but this workspace's own clean branch):",
|
|
1990
|
+
` werkmeister pr push ${path.basename(e.dir)}`,
|
|
1991
|
+
" and rerun the gate's tests.",
|
|
1981
1992
|
].join("\n");
|
|
1982
1993
|
/** One message for every new event on a PR; each block opens with SW-160's sentence. */
|
|
1983
1994
|
export function wakeMessage(url, events) {
|
|
@@ -2721,6 +2732,113 @@ export function renderCloseout(prs, issue, note) {
|
|
|
2721
2732
|
"",
|
|
2722
2733
|
].join("\n");
|
|
2723
2734
|
}
|
|
2735
|
+
/** Merge commits on HEAD since `origin/<base>`, or null when git can't count them; the gate (SW-733) and `pr push` (SW-717) refuse any. */
|
|
2736
|
+
export async function mergesFromBase(dir, base, run) {
|
|
2737
|
+
const r = await run("git", [
|
|
2738
|
+
"-C",
|
|
2739
|
+
dir,
|
|
2740
|
+
"rev-list",
|
|
2741
|
+
"--merges",
|
|
2742
|
+
"--count",
|
|
2743
|
+
`origin/${base}..HEAD`,
|
|
2744
|
+
]);
|
|
2745
|
+
return r.code ? null : Number(r.stdout.trim() || 0);
|
|
2746
|
+
}
|
|
2747
|
+
/**
|
|
2748
|
+
* Force-pushes each open PR's rebased branch with a lease, so a session can finish rule 5's
|
|
2749
|
+
* conflict fix without the person. The lease is `origin/<branch>` as last fetched, never
|
|
2750
|
+
* typed by the agent. Refuses, and pushes nothing for that file, unless: the worktree is one of
|
|
2751
|
+
* this workspace's own (checked without git); the branch is this workspace's own (the PR file's `branch:`, checked out, `<user>/<workspace>[-<slug>]`, not the
|
|
2752
|
+
* base); the worktree is clean; it holds no merge commit from its base; and origin still has the
|
|
2753
|
+
* leased head.
|
|
2754
|
+
*
|
|
2755
|
+
* @param ws - The workspace folder.
|
|
2756
|
+
* @param only - A code worktree's directory name or a PR file's name, as for `pr gate`.
|
|
2757
|
+
* @param deps - The services it uses; leave it at its default.
|
|
2758
|
+
* @returns `ok`, false when any file was refused or its push failed; `lines`, one per PR file.
|
|
2759
|
+
*
|
|
2760
|
+
* @example
|
|
2761
|
+
* ```ts
|
|
2762
|
+
* import { pushPrs } from "werkmeister-core/sdk";
|
|
2763
|
+
*
|
|
2764
|
+
* const { ok, lines } = await pushPrs("/work/my-workspace");
|
|
2765
|
+
* console.log(ok, lines.join("\n"));
|
|
2766
|
+
* ```
|
|
2767
|
+
*/
|
|
2768
|
+
export async function pushPrs(ws, only, deps = defaultDeps()) {
|
|
2769
|
+
const all = readPrFiles(ws);
|
|
2770
|
+
// Not selectFiles: it keeps a file named by *only* whatever its status, and its refusal says "set approved".
|
|
2771
|
+
const files = all.filter((f) => (!only || f.stem === only || f.dir === only) && statusOf(f) === "open");
|
|
2772
|
+
if (!files.length)
|
|
2773
|
+
return {
|
|
2774
|
+
ok: false,
|
|
2775
|
+
lines: [`No open PR to push${only ? ` for ${only}` : ""} (a PR file with status: open).`],
|
|
2776
|
+
};
|
|
2777
|
+
const lines = [];
|
|
2778
|
+
let ok = true;
|
|
2779
|
+
for (const f of files) {
|
|
2780
|
+
const line = await pushOne(ws, all, f, deps);
|
|
2781
|
+
if (line.startsWith("refused") || line.startsWith("failed"))
|
|
2782
|
+
ok = false;
|
|
2783
|
+
lines.push(`${f.stem}: ${line}`);
|
|
2784
|
+
}
|
|
2785
|
+
return { ok, lines };
|
|
2786
|
+
}
|
|
2787
|
+
/**
|
|
2788
|
+
* The PR file's worktree, when it is one of this workspace's own (a direct child whose `.git`
|
|
2789
|
+
* file points into a repo under the repos root), else null. Plain fs, so no git runs on a
|
|
2790
|
+
* folder or git config the agent chose: git can run commands from config (`core.fsmonitor`).
|
|
2791
|
+
*/
|
|
2792
|
+
function ownWorktree(ws, f) {
|
|
2793
|
+
if (!f.dir || f.dir !== path.basename(f.dir))
|
|
2794
|
+
return null;
|
|
2795
|
+
const dir = path.join(ws, f.dir);
|
|
2796
|
+
if (!repoDirs(ws).includes(dir))
|
|
2797
|
+
return null;
|
|
2798
|
+
let gitdir;
|
|
2799
|
+
try {
|
|
2800
|
+
gitdir = /^gitdir: (.+)$/m.exec(fs.readFileSync(path.join(dir, ".git"), "utf8"))?.[1] ?? "";
|
|
2801
|
+
}
|
|
2802
|
+
catch {
|
|
2803
|
+
return null; // a `.git` folder (a clone) or nothing: not a worktree of a registered repo
|
|
2804
|
+
}
|
|
2805
|
+
const rel = path.relative(getReposRoot(), path.resolve(dir, gitdir.trim()));
|
|
2806
|
+
return /^[^/\\]+[/\\]\.git[/\\]worktrees[/\\][^/\\]+$/.test(rel) ? dir : null;
|
|
2807
|
+
}
|
|
2808
|
+
async function pushOne(ws, all, f, deps) {
|
|
2809
|
+
const dir = ownWorktree(ws, f);
|
|
2810
|
+
if (!dir)
|
|
2811
|
+
return `refused: ${f.dir || "the PR file's worktree"} is not one of this workspace's worktrees of a repo under ${getReposRoot()} (a standalone clone keeps its git config in the workspace, so push it by hand)`;
|
|
2812
|
+
const branch = String(f.fm["branch"] ?? "");
|
|
2813
|
+
const base = String(f.fm["base"] ?? "main");
|
|
2814
|
+
const git = (...args) => deps.run("git", ["-C", dir, ...args]);
|
|
2815
|
+
// init names it <user>/<workspace>; a `pr new` follow-up adds -<slug> once a PR on it settled.
|
|
2816
|
+
const own = `${os.userInfo().username}/${path.basename(ws)}`;
|
|
2817
|
+
const followUp = branch.startsWith(`${own}-`) &&
|
|
2818
|
+
all.some((p) => p.fm["branch"] === own && PAST_MERGE.has(statusOf(p)));
|
|
2819
|
+
if (branch !== own && !followUp)
|
|
2820
|
+
return `refused: ${branch || "no branch:"} is not this workspace's own ${own} branch (or a \`pr new\` follow-up of it)`;
|
|
2821
|
+
const head = (await git("rev-parse", "--abbrev-ref", "HEAD")).stdout.trim();
|
|
2822
|
+
if (head !== branch)
|
|
2823
|
+
return `refused: ${f.dir} has ${head || "no branch"} checked out, not ${branch}`;
|
|
2824
|
+
const status = await git("status", "--porcelain");
|
|
2825
|
+
if (status.code || status.stdout.trim())
|
|
2826
|
+
return `refused: ${f.dir} is not clean — commit first:\n${status.stdout.trimEnd() || status.stderr.trim()}`;
|
|
2827
|
+
const merges = await mergesFromBase(dir, base, deps.run);
|
|
2828
|
+
if (merges !== 0)
|
|
2829
|
+
return `refused: ${merges === null ? "cannot count" : merges} merge commit(s) from origin/${base} — rebase instead: git -C ${f.dir} rebase origin/${base}`;
|
|
2830
|
+
const lease = (await git("rev-parse", "--verify", "-q", `refs/remotes/origin/${branch}`)).stdout.trim();
|
|
2831
|
+
if (!lease)
|
|
2832
|
+
return `refused: no origin/${branch} to lease against — \`werkmeister pr open\` pushes a new branch`;
|
|
2833
|
+
const remote = await git("ls-remote", "origin", `refs/heads/${branch}`);
|
|
2834
|
+
const live = remote.stdout.split(/\s/)[0] ?? "";
|
|
2835
|
+
if (remote.code || live !== lease)
|
|
2836
|
+
return `refused: origin's ${branch} is ${live || "unreadable"}, not the leased ${lease} — someone pushed since your fetch; \`git -C ${f.dir} fetch origin ${branch}\`, check what changed, rebase onto it, rerun`;
|
|
2837
|
+
const push = await git("push", "--no-verify", `--force-with-lease=${branch}:${lease}`, "origin", branch);
|
|
2838
|
+
return push.code
|
|
2839
|
+
? `failed: ${(push.stderr || push.stdout).trim()}`
|
|
2840
|
+
: `pushed ${branch} (lease ${lease.slice(0, 12)}); rerun the gate's tests (rule 5)`;
|
|
2841
|
+
}
|
|
2724
2842
|
/** `--abandon`: record *why* on every unsettled PR file and in closeout.md. */
|
|
2725
2843
|
export function abandonWorkspace(ws, why) {
|
|
2726
2844
|
const files = readPrFiles(ws);
|
|
@@ -2729,6 +2847,28 @@ export function abandonWorkspace(ws, why) {
|
|
|
2729
2847
|
writePrFields(f, { status: "abandoned", reason: why });
|
|
2730
2848
|
fs.writeFileSync(path.join(ws, "closeout.md"), renderCloseout(files, "not closed (abandoned)", `Abandoned: ${why}`));
|
|
2731
2849
|
}
|
|
2850
|
+
/** The abandon comment: the reason verbatim, and where the post-mortem survives the folder's removal (SW-795). */
|
|
2851
|
+
async function abandonComment(ws, why, deps) {
|
|
2852
|
+
const lines = [`Abandoned, not shipped: ${why}`];
|
|
2853
|
+
if (fs.existsSync(path.join(ws, "postmortem.md"))) {
|
|
2854
|
+
const r = await deps.run("git", ["-C", ws, "rev-parse", "--abbrev-ref", "HEAD"]);
|
|
2855
|
+
const branch = r.code === 0 ? r.stdout.trim() : "";
|
|
2856
|
+
lines.push(`Post-mortem: postmortem.md on ${branch && branch !== "HEAD" ? `branch ${branch}` : "the workspace's record branch"}, pushed at removal.`);
|
|
2857
|
+
}
|
|
2858
|
+
return lines.join("\n");
|
|
2859
|
+
}
|
|
2860
|
+
/** `--keep-open`: back in the queue instead of Done (SW-795). */
|
|
2861
|
+
// shortcut: To Do is Jira's default name; a GitHub issue is still open here, so it only gets the comment (its status label stays). Make it an issue_statuses point if a project names it otherwise.
|
|
2862
|
+
async function reopenIssue(tracker, ref, comment) {
|
|
2863
|
+
const status = tracker.id === "jira" ? "To Do" : undefined;
|
|
2864
|
+
try {
|
|
2865
|
+
await tracker.updateIssue(ref, { ...(status && { status }), comment });
|
|
2866
|
+
return status ? `${ref} → ${status}` : `${ref} commented, left open`;
|
|
2867
|
+
}
|
|
2868
|
+
catch (e) {
|
|
2869
|
+
return `${ref} not moved to "${status ?? "open"}": ${e.message}`;
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2732
2872
|
/** The VS Code extension's terminal.ts writes one file per session shell pid here, holding its cwd (SW-421). */
|
|
2733
2873
|
const vscodeTerminalsDir = () => path.join(sandboxHome(), "vscode-terminals");
|
|
2734
2874
|
const isIn = (ws, dir) => dir === ws || dir.startsWith(ws + path.sep);
|
|
@@ -2802,7 +2942,9 @@ export async function openTerminalSessions(ws, run = execRun, ownedDir = vscodeT
|
|
|
2802
2942
|
*
|
|
2803
2943
|
* @param name - The workspace's folder name.
|
|
2804
2944
|
* @param opts - `abandon`: give up on unshipped work with this reason; the issue
|
|
2805
|
-
*
|
|
2945
|
+
* moves to its `abandoned` status (Jira: Done) with the reason and the post-mortem's
|
|
2946
|
+
* branch as a comment, and every branch is pushed and kept.
|
|
2947
|
+
* `keepOpen`: with `abandon`, put the issue back as To Do (GitHub: left open, comment only) instead.
|
|
2806
2948
|
* `noPr`: the work changed no repo, so close it as done with this reason instead of a PR.
|
|
2807
2949
|
* `skipPostmortem`: close without a `postmortem.md`, with this reason.
|
|
2808
2950
|
* Each needs a non-empty reason; `noPr` can't be combined with the other two.
|
|
@@ -2837,6 +2979,9 @@ export async function closeOut(name, opts = {}, deps = defaultDeps()) {
|
|
|
2837
2979
|
if (opts.skipPostmortem !== undefined && !skip) {
|
|
2838
2980
|
throw new WorkspaceError(`Skipping the post-mortem needs a reason: werkmeister workspace close ${name} --skip-postmortem "<reason>"`);
|
|
2839
2981
|
}
|
|
2982
|
+
if (opts.keepOpen && !why) {
|
|
2983
|
+
throw new WorkspaceError(`--keep-open puts an abandoned issue back in the queue, so it needs abandon: werkmeister workspace abandon "<reason>" ${name} --keep-open`);
|
|
2984
|
+
}
|
|
2840
2985
|
const noPr = opts.noPr?.trim();
|
|
2841
2986
|
if (opts.noPr !== undefined && !noPr) {
|
|
2842
2987
|
throw new WorkspaceError(`--no-pr needs a reason: werkmeister workspace close ${name} --no-pr "<reason>"`);
|
|
@@ -2858,13 +3003,13 @@ export async function closeOut(name, opts = {}, deps = defaultDeps()) {
|
|
|
2858
3003
|
throw new WorkspaceError(`close-out of '${name}' is already running; that run reports the result. If none is, delete ${lock}.`);
|
|
2859
3004
|
}
|
|
2860
3005
|
try {
|
|
2861
|
-
return await closeOutLocked(name, ws, why, skip, noPr, deps);
|
|
3006
|
+
return await closeOutLocked(name, ws, why, skip, noPr, !!opts.keepOpen, deps);
|
|
2862
3007
|
}
|
|
2863
3008
|
finally {
|
|
2864
3009
|
fs.rmSync(lock, { force: true });
|
|
2865
3010
|
}
|
|
2866
3011
|
}
|
|
2867
|
-
async function closeOutLocked(name, ws, why, skip, noPr, deps) {
|
|
3012
|
+
async function closeOutLocked(name, ws, why, skip, noPr, keepOpen, deps) {
|
|
2868
3013
|
const command = `werkmeister workspace ${why ? "abandon <reason>" : "close"} ${name}`;
|
|
2869
3014
|
const cfg = loadConfigFile(ws, null);
|
|
2870
3015
|
// SW-108: a run's lessons go with the workspace unless someone asks for them on purpose.
|
|
@@ -2877,6 +3022,8 @@ async function closeOutLocked(name, ws, why, skip, noPr, deps) {
|
|
|
2877
3022
|
// Before abandonWorkspace, which rewrites the PR files: a refusal changes nothing.
|
|
2878
3023
|
if (why && postmortemRefusal)
|
|
2879
3024
|
throw new WorkspaceError(postmortemRefusal);
|
|
3025
|
+
// A retry after a failed removal: the issue already moved and has the comment, so it is not posted twice.
|
|
3026
|
+
const retry = fs.existsSync(path.join(ws, "closeout.md"));
|
|
2880
3027
|
if (why)
|
|
2881
3028
|
abandonWorkspace(ws, why);
|
|
2882
3029
|
const life = lifecycleOf(ws);
|
|
@@ -2927,12 +3074,15 @@ async function closeOutLocked(name, ws, why, skip, noPr, deps) {
|
|
|
2927
3074
|
const refs = issueRefsOf(cfg);
|
|
2928
3075
|
let issueLine = "none";
|
|
2929
3076
|
if (refs.length) {
|
|
3077
|
+
const comment = why && !retry && (await abandonComment(ws, why, deps));
|
|
2930
3078
|
// moveIssue never throws: a tracker refusal is a warning here, not a stopped close-out.
|
|
2931
3079
|
issueLine = await eachIssue(refs, async (ref) => {
|
|
2932
3080
|
const { tracker, statuses } = trackingOf(cfg, ref, deps);
|
|
2933
|
-
if (why)
|
|
3081
|
+
if (why && !retry && keepOpen)
|
|
3082
|
+
return reopenIssue(tracker, ref, comment || why);
|
|
3083
|
+
if (why && !retry)
|
|
2934
3084
|
return moveIssue(tracker, ref, "abandoned", statuses, {
|
|
2935
|
-
comment:
|
|
3085
|
+
comment: comment || why,
|
|
2936
3086
|
alwaysComment: true,
|
|
2937
3087
|
});
|
|
2938
3088
|
if (abandoned) {
|
package/dist/pr_rules.js
CHANGED
|
@@ -28,9 +28,9 @@ These hold for every PR this workspace produces, whatever skill or command was a
|
|
|
28
28
|
|
|
29
29
|
1. **This folder's git branch is a record only.** Commit and push it; never open a PR from it, never merge it.
|
|
30
30
|
2. **PRs come only from code worktrees** — one per repo touched at a time, from that repo's PR file (below).
|
|
31
|
-
3. **Gate.** Before a PR opens, all of these hold: every earlier stage/phase is done; every follow-up a decided question in \`decisions.md\` promises names its issue key; the PR file's acceptance table is all PASS (MANUAL rows pass and the gate lists them); the code worktree is clean; a branch not yet pushed is not behind \`origin/<base>\` (the gate fetches it first; a pushed one passes with a note, rule 5; when behind, rebase with \`git -C <repo> rebase origin/<base>\` and rerun the tests, before the first push so no force-push is needed); each touched service's registry test command passes (\`.werkmeister/werkmeister-context.md\`); the exercise evidence is all PASS (or \`skip_exercise\` gives the reason); the code review in \`review.md\` is all PASS (or \`skip_review\` gives the reason; only in a workspace whose build stage has the review step); the repo's release check passes; the PR file reads \`status: approved\`. The PR-file checks (stages, acceptance table, approved, exercise evidence, review) and the base check run first; if one fails, the gate stops before any test command. With the tests the gate can run past a 10-minute tool call. Run \`pr open\`, and \`pr gate\` or \`pr gate --tests\` too, alone as a background job your harness tracks (Claude Code: \`run_in_background\`), with only its log redirect and no \`cd\`, pipe or other command around it, so an allow rule for it matches (an autonomous run has one; an interactive one asks): \`werkmeister pr open > <absolute workspace path>/.werkmeister/pr-open.log 2>&1\`, or \`werkmeister pr gate --tests > <absolute workspace path>/.werkmeister/gate-run.log 2>&1\`. The log path is absolute because the shell's cwd can drift into a code worktree, which would write the log there as an untracked file. Wait for its completion notice, which carries the exit code, then read the log's end. A bare \`&\` dies when the tool call returns, and \`nohup … &\` sends no notice when it ends.
|
|
31
|
+
3. **Gate.** Before a PR opens, all of these hold: every earlier stage/phase is done; every follow-up a decided question in \`decisions.md\` promises names its issue key; the PR file's acceptance table is all PASS (MANUAL rows pass and the gate lists them); the code worktree is clean; a branch not yet pushed is not behind \`origin/<base>\` (the gate fetches it first; a pushed one passes with a note, rule 5; when behind, rebase with \`git -C <repo> rebase origin/<base>\` and rerun the tests, before the first push so no force-push is needed); the branch holds no merge commit from its base (rebase instead, rule 5); each touched service's registry test command passes (\`.werkmeister/werkmeister-context.md\`); the exercise evidence is all PASS (or \`skip_exercise\` gives the reason); the code review in \`review.md\` is all PASS (or \`skip_review\` gives the reason; only in a workspace whose build stage has the review step); the repo's release check passes; the PR file reads \`status: approved\`. The PR-file checks (stages, acceptance table, approved, exercise evidence, review) and the base check run first; if one fails, the gate stops before any test command. With the tests the gate can run past a 10-minute tool call. Run \`pr open\`, and \`pr gate\` or \`pr gate --tests\` too, alone as a background job your harness tracks (Claude Code: \`run_in_background\`), with only its log redirect and no \`cd\`, pipe or other command around it, so an allow rule for it matches (an autonomous run has one; an interactive one asks): \`werkmeister pr open > <absolute workspace path>/.werkmeister/pr-open.log 2>&1\`, or \`werkmeister pr gate --tests > <absolute workspace path>/.werkmeister/gate-run.log 2>&1\`. The log path is absolute because the shell's cwd can drift into a code worktree, which would write the log there as an untracked file. Wait for its completion notice, which carries the exit code, then read the log's end. A bare \`&\` dies when the tool call returns, and \`nohup … &\` sends no notice when it ends.
|
|
32
32
|
4. **Only \`werkmeister pr open\` opens PRs.** \`gh pr create\`, \`/create-pr\` and \`finishing-a-development-branch\` are blocked inside a workspace.
|
|
33
|
-
5. **Auto-fix is always on.** \`werkmeister pr watch\` wakes the session that opened the PR when a check fails, a review comes in or the PR conflicts with its base, with the cause in the message. On a conflict, rebase onto \`origin/<base>\`; never merge the base into the branch, or GitHub can't rebase-merge it. A conflict in a generated file (a snapshot, a lockfile): take the base's copy and regenerate it with the repo's generator (\`.werkmeister/werkmeister-context.md\` names it); never hand-merge it.
|
|
33
|
+
5. **Auto-fix is always on.** \`werkmeister pr watch\` wakes the session that opened the PR when a check fails, a review comes in or the PR conflicts with its base, with the cause in the message. On a conflict, rebase onto \`origin/<base>\`; never merge the base into the branch, or GitHub can't rebase-merge it. A conflict in a generated file (a snapshot, a lockfile): take the base's copy and regenerate it with the repo's generator (\`.werkmeister/werkmeister-context.md\` names it); never hand-merge it. Then push it with \`werkmeister pr push [repo]\`: it force-pushes with a lease on \`origin/<branch>\` as last fetched, and refuses anything but this workspace's own clean branch with no merge from its base. If it refuses because origin moved, fetch, look at what changed, rebase onto it and rerun. Rerun the gate's tests after the push. ${DESKTOP_AUTOFIX_RULE} Never turn on auto-merge.
|
|
34
34
|
6. **Merge is the person's act.** Tooling never merges. On a repo with a merge queue, the queue's method decides how every PR merges (\`gh api repos/<repo>/rules/branches/<base>\`, the \`merge_queue\` rule's \`merge_method\`); without one, squash is the default. A PR that needs another method says so at the top of its body, and the person merges it that way, bypassing the queue: a grouped PR (\`group\` in \`workspace.yml\`) says "Rebase and merge, not squash" and keeps its per-ticket commits (\`werkmeister pr gate\` warns when the base won't allow it); a PR whose commit SHAs must survive (e.g. a commit listed in \`.git-blame-ignore-revs\`) says "Merge with a merge commit", since squash and rebase both rewrite SHAs. A PR that must wait for a step outside the code (e.g. a ruleset applied after its CI goes green) sets \`hold: <reason>\` in its PR file: \`werkmeister pr open\` then opens it as a draft, which GitHub won't merge, with \`Don't merge until: <reason>\` at the top of the body. The session that does the step runs \`gh pr ready <url>\` and empties \`hold:\`. A PR the repo's own automation queues (a release bot's version PR) is the exception: leave it to that automation, and don't tell the person it's theirs to merge.
|
|
35
35
|
7. **Close out only when every PR file is \`shipped\`, \`closed\` or \`abandoned\`, and after the post-mortem:** the werkmeister \`postmortem\` skill writes \`postmortem.md\` at the workspace root. \`werkmeister workspace close\` refuses without it unless \`--skip-postmortem "<reason>"\`.
|
|
36
36
|
|
|
@@ -97,7 +97,7 @@ Lifecycle: \`working → ready → pr-open → merged → shipped → closed-out
|
|
|
97
97
|
| \`werkmeister pr adopt <pr-number\\|url> [repo]\` | the fix landed outside this workspace: write the PR file from that PR, then record its status |
|
|
98
98
|
| \`werkmeister pr adopt --no-pr "<reason>" [repo]\` | the fix is already on base with no PR: write a \`closed\` PR file with the reason |
|
|
99
99
|
| \`werkmeister workspace close\` | after ship: move the issue to done if shipping didn't, write \`closeout.md\`, remove the workspace, delete merged branches |
|
|
100
|
-
| \`werkmeister workspace abandon "<reason>"\` | give up: record the reason,
|
|
100
|
+
| \`werkmeister workspace abandon "<reason>"\` | give up: record the reason, move the issue to Done with the reason (\`--keep-open\`: To Do), push and keep every branch with commits of its own, remove the workspace |
|
|
101
101
|
| \`werkmeister workspace close --no-pr "<reason>"\` | close out as done when the work changed no repo (no PR files, clean worktrees, no commits ahead); needs \`postmortem.md\` |
|
|
102
102
|
| \`werkmeister workspace close --skip-postmortem "<reason>"\` | close out without a post-mortem, only when the person says to; the reason goes in \`closeout.md\` |
|
|
103
103
|
`;
|
package/dist/sandbox.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ import { type ResumeResult } from "./lifecycle.js";
|
|
|
26
26
|
import { type Deps, type Lifecycle } from "./pr_lifecycle.js";
|
|
27
27
|
import { type NeedItem, type WorkspaceState } from "./workspace_state.js";
|
|
28
28
|
import { listRepoWorktrees } from "./worktrees.js";
|
|
29
|
-
export { adoptPr, callbackMessage, closeOut, gatePrs, gateTests, type Lifecycle, lifecycleOf, newPr, openPrs, type PrStatus, readPrFiles, refreshPrStatus, runGate, waitForHostLoadNow, watchPrs, } from "./pr_lifecycle.js";
|
|
29
|
+
export { adoptPr, callbackMessage, closeOut, gatePrs, gateTests, type Lifecycle, lifecycleOf, newPr, openPrs, type PrStatus, pushPrs, readPrFiles, refreshPrStatus, runGate, waitForHostLoadNow, watchPrs, } from "./pr_lifecycle.js";
|
|
30
30
|
export type { Activity, ActivityId, NeedItem, NeedKind, NeedSource, Phase, PhaseId, WorkspaceState, } from "./workspace_state.js";
|
|
31
31
|
export { listRepoWorktrees };
|
|
32
32
|
/**
|
package/dist/sandbox.js
CHANGED
|
@@ -70,7 +70,7 @@ import { computePromptSpec, isTrue, loadConfigFile, readAutonomous, resolveInput
|
|
|
70
70
|
import { legacyAgent, prNeeds, workspaceState, } from "./workspace_state.js";
|
|
71
71
|
import { revokeWorkspaceToken } from "./workspace_token.js";
|
|
72
72
|
import { hasGit, listRepoWorktrees } from "./worktrees.js";
|
|
73
|
-
export { adoptPr, callbackMessage, closeOut, gatePrs, gateTests, lifecycleOf, newPr, openPrs, readPrFiles, refreshPrStatus, runGate, waitForHostLoadNow, watchPrs,
|
|
73
|
+
export { adoptPr, callbackMessage, closeOut, gatePrs, gateTests, lifecycleOf, newPr, openPrs, pushPrs, readPrFiles, refreshPrStatus, runGate, waitForHostLoadNow, watchPrs,
|
|
74
74
|
// biome-ignore lint/suspicious/noImportCycles: pr_lifecycle↔sandbox.ts↔usage_snapshot; SW-411
|
|
75
75
|
} from "./pr_lifecycle.js";
|
|
76
76
|
export { listRepoWorktrees };
|
|
@@ -974,7 +974,8 @@ function servicesNamedIn(text, repos) {
|
|
|
974
974
|
.replace(/\\/g, "") // Jira wiki markup escapes hyphens (`smart\-app`).
|
|
975
975
|
.replace(/\{(code|noformat)[^}]*\}[\s\S]*?\{\1\}/g, "")
|
|
976
976
|
.replace(/```[\s\S]*?```/g, "")
|
|
977
|
-
|
|
977
|
+
// An indented line is a quoted log, unless it is a nested list item (SW-886).
|
|
978
|
+
.replace(/^(?: {4}|\t)(?!\s*(?:[-*+]|\d+\.)\s).*$/gm, "")
|
|
978
979
|
// One span at a time: a pattern spanning two spans would eat the prose between them.
|
|
979
980
|
.replace(/\{\{[^}]*\}\}|`[^`\n]*`/g, (m) => (/\s/.test(m) ? "" : m));
|
|
980
981
|
return Object.entries(loadServices())
|
|
@@ -71,16 +71,22 @@ export declare const readHostLoad: () => {
|
|
|
71
71
|
load: number[];
|
|
72
72
|
cores: number;
|
|
73
73
|
};
|
|
74
|
+
/** What with-temp-home's wait did: *spent* means a limit was still over when it gave up (SW-716). */
|
|
75
|
+
export interface HostLoadWait {
|
|
76
|
+
spent: boolean;
|
|
77
|
+
note: string;
|
|
78
|
+
}
|
|
74
79
|
/**
|
|
75
80
|
* The wait of `werkmeister internal wait-load`, which the generated with-temp-home runs first (SW-224):
|
|
76
81
|
* up to 90 s for the 1-minute load to fall under the limit and free memory to rise over its own (SW-620),
|
|
77
|
-
* saying so up front and printing progress each minute (SW-262)
|
|
78
|
-
*
|
|
82
|
+
* saying so up front and printing progress each minute (SW-262). Returns the note for the wrapper's stderr ("" when
|
|
83
|
+
* it did not wait) and whether the wait is *spent* with a limit still over (SW-716).
|
|
84
|
+
* The gate stopped waiting in SW-542.
|
|
79
85
|
* Load not on macOS: its loadavg counts idle daemons in R state (450-550 on a quiet host) and never the
|
|
80
86
|
* Linux VM that runs the tests, so it is no signal to wait on (SW-556). Its memory is: Claude Code
|
|
81
87
|
* stops an idle background shell when the Mac runs low (SW-620).
|
|
82
88
|
*/
|
|
83
|
-
export declare function waitForHostLoadNow(deps?: HostLoadDeps, platform?: NodeJS.Platform, before?: string): Promise<
|
|
89
|
+
export declare function waitForHostLoadNow(deps?: HostLoadDeps, platform?: NodeJS.Platform, before?: string): Promise<HostLoadWait>;
|
|
84
90
|
/**
|
|
85
91
|
* Before compose starts a setup one-shot among *services* (undefined: what a whole `up` starts),
|
|
86
92
|
* wait on host load and free memory as with-temp-home does, and fail once the wait is spent (SW-630,
|
package/dist/scheduler_state.js
CHANGED
|
@@ -177,16 +177,18 @@ const minutes = (ms) => Number((ms / 60_000).toFixed(1));
|
|
|
177
177
|
/**
|
|
178
178
|
* The wait of `werkmeister internal wait-load`, which the generated with-temp-home runs first (SW-224):
|
|
179
179
|
* up to 90 s for the 1-minute load to fall under the limit and free memory to rise over its own (SW-620),
|
|
180
|
-
* saying so up front and printing progress each minute (SW-262)
|
|
181
|
-
*
|
|
180
|
+
* saying so up front and printing progress each minute (SW-262). Returns the note for the wrapper's stderr ("" when
|
|
181
|
+
* it did not wait) and whether the wait is *spent* with a limit still over (SW-716).
|
|
182
|
+
* The gate stopped waiting in SW-542.
|
|
182
183
|
* Load not on macOS: its loadavg counts idle daemons in R state (450-550 on a quiet host) and never the
|
|
183
184
|
* Linux VM that runs the tests, so it is no signal to wait on (SW-556). Its memory is: Claude Code
|
|
184
185
|
* stops an idle background shell when the Mac runs low (SW-620).
|
|
185
186
|
*/
|
|
186
187
|
export async function waitForHostLoadNow(deps = realHostLoad, platform = process.platform, before = "with-temp-home; --no-wait skips") {
|
|
187
188
|
// WERKMEISTER_NO_WAIT skips it inside the command too, not only in with-temp-home's shell (SW-425).
|
|
189
|
+
const none = { spent: false, note: "" };
|
|
188
190
|
if (envVar("NO_WAIT"))
|
|
189
|
-
return
|
|
191
|
+
return none;
|
|
190
192
|
const read = () => {
|
|
191
193
|
const { load, cores } = deps.hostLoad();
|
|
192
194
|
const limit = platform === "darwin" ? 0 : hostLoadLimit(cores);
|
|
@@ -199,7 +201,7 @@ export async function waitForHostLoadNow(deps = realHostLoad, platform = process
|
|
|
199
201
|
};
|
|
200
202
|
let now = read();
|
|
201
203
|
if (!now.loadOver && !now.memory)
|
|
202
|
-
return
|
|
204
|
+
return none;
|
|
203
205
|
const waitedFor = [now.loadOver && "host load", now.memory && "free memory"]
|
|
204
206
|
.filter(Boolean)
|
|
205
207
|
.join(" and ");
|
|
@@ -219,11 +221,14 @@ export async function waitForHostLoadNow(deps = realHostLoad, platform = process
|
|
|
219
221
|
await deps.sleep(LOAD_POLL_MS);
|
|
220
222
|
now = read();
|
|
221
223
|
if (!now.loadOver && !now.memory)
|
|
222
|
-
return `waited ${waited / 1000} s for ${waitedFor}
|
|
224
|
+
return { spent: false, note: `waited ${waited / 1000} s for ${waitedFor}` };
|
|
223
225
|
if (waited % LOAD_PROGRESS_MS === 0 && waited < WRAPPER_LOAD_WAIT_MS)
|
|
224
226
|
info(`still waiting: ${state()}, ${waited / 1000} s so far, up to ${minutes(WRAPPER_LOAD_WAIT_MS - waited)} min left`);
|
|
225
227
|
}
|
|
226
|
-
return
|
|
228
|
+
return {
|
|
229
|
+
spent: true,
|
|
230
|
+
note: `ran with ${state()}; the ${minutes(WRAPPER_LOAD_WAIT_MS)} min host-load wait is spent`,
|
|
231
|
+
};
|
|
227
232
|
}
|
|
228
233
|
/**
|
|
229
234
|
* Before compose starts a setup one-shot among *services* (undefined: what a whole `up` starts),
|
|
@@ -240,8 +245,8 @@ export async function waitForSetupLoad(workspace, services, deps = realHostLoad,
|
|
|
240
245
|
if (!setups.length)
|
|
241
246
|
return;
|
|
242
247
|
const what = setups.join(", ");
|
|
243
|
-
const note = await waitForHostLoadNow(deps, platform, `starting ${what}; WERKMEISTER_NO_WAIT=1 skips`);
|
|
244
|
-
if (!
|
|
248
|
+
const { spent, note } = await waitForHostLoadNow(deps, platform, `starting ${what}; WERKMEISTER_NO_WAIT=1 skips`);
|
|
249
|
+
if (!spent)
|
|
245
250
|
return;
|
|
246
251
|
const { load, cores } = deps.hostLoad();
|
|
247
252
|
const limit = hostLoadLimit(cores);
|
package/dist/sdk.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export { type CleanPlan, type CleanResult, type ProxyOps, type ProxyReloadResult
|
|
|
26
26
|
export type { Step } from "./machine_setup.js";
|
|
27
27
|
export { type MigrateOptions, migrate } from "./migrate.js";
|
|
28
28
|
export { listNotes, type Note, parseNote } from "./notes.js";
|
|
29
|
-
export { adoptPr, gatePrs, type Lifecycle, newPr, openPrs, type PrCallback, type PrView, } from "./pr_lifecycle.js";
|
|
29
|
+
export { adoptPr, gatePrs, type Lifecycle, newPr, openPrs, type PrCallback, type PrView, pushPrs, } from "./pr_lifecycle.js";
|
|
30
30
|
export { type SyncRegistryOptions, syncRegistry } from "./registry_sync.js";
|
|
31
31
|
export type { WorkspaceResources } from "./resources.js";
|
|
32
32
|
export type { StartArgs } from "./run_start.js";
|
package/dist/sdk.js
CHANGED
|
@@ -20,7 +20,7 @@ export { issueTracker } from "./issue_tracker.js";
|
|
|
20
20
|
export { planClean, readServicesFromWorkspace, reloadProxy, removeService, runClean, } from "./lifecycle.js";
|
|
21
21
|
export { migrate } from "./migrate.js";
|
|
22
22
|
export { listNotes, parseNote } from "./notes.js";
|
|
23
|
-
export { adoptPr, gatePrs, newPr, openPrs, } from "./pr_lifecycle.js";
|
|
23
|
+
export { adoptPr, gatePrs, newPr, openPrs, pushPrs, } from "./pr_lifecycle.js";
|
|
24
24
|
export { syncRegistry } from "./registry_sync.js";
|
|
25
25
|
// Workspaces: list, read state, create, close.
|
|
26
26
|
export { applyIssueFormAnswer, approvePr, buildIssueFormRequest, buildRefinePrompt, checkInTriage, claimResumeNudge, closeOut, createWorkspace, fetchIssueCard, fetchIssueFormData, followLogsInTerminal, getClaudeTranscript, getClaudeTurnStatus, getDockerUi, getFormSchema, getIssueStatuses, getK8sForwardsHealth, getKubeContext, getOpenPrs, getWorkspacePRs, getWorkspaceResources, getWorkspaceStatuses, getWorkspaceUsage, icmStage, launchPrReconcile, lifecycleOf, listSessions, listWorkspaces, mergeFormData, openFeatureBrowser, openWorkspace, postSlackReviewRequest, refinePrompt, refreshPrStatus, resolveWorkspaceDir, resumeAndNudge, resumeClaudeInTerminal, runWorkspaceAction, sendToClaudeSession, startArgs, switchKubeContext, validateFormData, WORKSPACE_ACTIONS, watchPrs, } from "./sandbox.js";
|
package/dist/strategies/icm.js
CHANGED
|
@@ -22,7 +22,7 @@ import { deferMachineSteps, RUN_LIMITS } from "../run_start.js";
|
|
|
22
22
|
import { loadStandardsModules, repoDirs, resolveActiveStandards } from "../standards.js";
|
|
23
23
|
import { _INPUT_FIELDS, isTrue, loadConfigFile, loadSandboxServiceConfigs, } from "../workspace_prompts.js";
|
|
24
24
|
import { stageDecisions } from "./icm_decisions.js";
|
|
25
|
-
import { askLine, prDir, proposeDir, SELF_CHECK, stageDirs, templateFor, } from "./icm_templates.js";
|
|
25
|
+
import { askLine, ICM_TEMPLATES, prDir, proposeDir, SELF_CHECK, stageDirs, templateFor, } from "./icm_templates.js";
|
|
26
26
|
import { renderIssueRef } from "./issue_section.js";
|
|
27
27
|
const PONYTAIL_ROW = "| ponytail | optional plugin (SW-643): when installed, its SessionStart hook prints `PONYTAIL MODE ACTIVE` " +
|
|
28
28
|
"in every session. Invoke the `ponytail` skill only if that line is missing and the skill is listed; " +
|
|
@@ -390,6 +390,10 @@ function drifted(root) {
|
|
|
390
390
|
function init(ctx) {
|
|
391
391
|
const root = ctx.workspaceRoot;
|
|
392
392
|
const stages = templateFor(ctx.inputs["work_type"] ?? "");
|
|
393
|
+
// templateFor falls back to feature silently; a typo (`bug`) would get the wrong stages unnoticed (SW-874).
|
|
394
|
+
const wt = (ctx.inputs["work_type"] ?? "").trim().toLowerCase();
|
|
395
|
+
if (wt && !Object.hasOwn(ICM_TEMPLATES, wt))
|
|
396
|
+
warn(`work_type "${ctx.inputs["work_type"]}" is not a template; using feature. Valid: ${Object.keys(ICM_TEMPLATES).join(", ")}.`);
|
|
393
397
|
const foreign = foreignStageDirs(root, stages);
|
|
394
398
|
if (foreign.length) {
|
|
395
399
|
warn(`stages/ holds ${foreign.join(", ")}, which the current ${ctx.inputs["work_type"] || "feature"} template does not render — ` +
|
|
@@ -153,6 +153,8 @@ const followUpGroup = (tool) => `Before filing 3 or more follow-up tickets, ask
|
|
|
153
153
|
const START_GRANTS = ["issue start", "issue view"];
|
|
154
154
|
const propose = {
|
|
155
155
|
name: "propose",
|
|
156
|
+
// SW-717: rule 5's conflict fix pushes its own rebased branch; pr push refuses any other.
|
|
157
|
+
grants: ["pr push:*"],
|
|
156
158
|
job: "acceptance walk and PR files",
|
|
157
159
|
writes: "the code commits (one per repo, or one per ticket in a grouped PR), `output/pr-<worktree>.md` per repo",
|
|
158
160
|
check: "approve each PR file; `werkmeister pr open` opens it",
|
package/dist/temp_home.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* hand-roll `HOME=$(mktemp -d) …` and none can forget it.
|
|
5
5
|
*/
|
|
6
6
|
/** Also run inline in a container by the pr gate (SW-329). */
|
|
7
|
-
export declare const TEMP_HOME_SCRIPT = "#!/bin/sh\n# Generated by `werkmeister workspace init` (SW-124); rerun it to regenerate.\n# Runs <cmd...> with HOME set to a fresh temporary directory, removed on exit,\n# so no test or CLI exercise reads or writes the real ~/.werkmeister.\n# --no-wait first does what WERKMEISTER_NO_WAIT=1 does, without an env assignment (SW-367),\n# and exports it, so a with-temp-home nested under it skips its wait too (SW-425).\n[ \"${1:-}\" != --no-wait ] || { export WERKMEISTER_NO_WAIT=1; shift; }\nno_wait=${WERKMEISTER_NO_WAIT:-}\n[ \"$#\" -gt 0 ] || { echo \"usage: with-temp-home [--no-wait] <cmd> [args...]\" >&2; exit 2; }\n# Wait like the pr gate while host load is over budget.host_load (SW-224), before HOME\n# changes so the real config's budget applies; no werkmeister on PATH, no wait.\n# In the background with a trap, so killing the wrapper ends the wait too (SW-456).\n[ -n \"$no_wait\" ] || ! command -v werkmeister >/dev/null 2>&1 || {\n # Trap before the fork: $! is empty until the job exists, so no signal can land between them.\n trap 'kill $! 2>/dev/null; exit 130' HUP INT TERM\n werkmeister internal wait-load >&2 &\n wait $!\n# 75: the wait is spent and load is still over, so running would pile on (SW-540); any other failure runs.\n} || { s=$?; [ \"$s\" -ne 75 ] || exit 75; }\ntmp=$(mktemp -d) || exit 1\n# os.tmpdir() scratch from the wrapped command goes with the temp HOME (SW-799).\nexport TMPDIR=\"$tmp\"\ntrap 'rm -rf \"$tmp\"' EXIT\ntrap 'exit 130' HUP INT TERM\n# Corepack keeps pnpm under HOME; without this a fresh HOME re-downloads it every run.\nexport COREPACK_HOME=\"${COREPACK_HOME:-$HOME/.cache/node/corepack}\"\n# OrbStack and Docker Desktop keep the compose plugin and context here (SW-285).\nexport DOCKER_CONFIG=\"${DOCKER_CONFIG:-$HOME/.docker}\"\n# A temp HOME isolates files, not the daemon: unreachable unless the caller sets it (SW-264).\nexport WERKMEISTER_HOST=\"${WERKMEISTER_HOST:-http://127.0.0.1:
|
|
7
|
+
export declare const TEMP_HOME_SCRIPT = "#!/bin/sh\n# Generated by `werkmeister workspace init` (SW-124); rerun it to regenerate.\n# Runs <cmd...> with HOME set to a fresh temporary directory, removed on exit,\n# so no test or CLI exercise reads or writes the real ~/.werkmeister.\n# --no-wait first does what WERKMEISTER_NO_WAIT=1 does, without an env assignment (SW-367),\n# and exports it, so a with-temp-home nested under it skips its wait too (SW-425).\n[ \"${1:-}\" != --no-wait ] || { export WERKMEISTER_NO_WAIT=1; shift; }\nno_wait=${WERKMEISTER_NO_WAIT:-}\n# --cwd <dir> next runs the command there, whatever the shell's cwd, with no `cd` to break the allow rule (SW-652).\n# In the werkmeister container the worktree is also at /app, the only place its node_modules volume is mounted (SW-548).\nif [ \"${1:-}\" = --cwd ] && [ \"$#\" -ge 2 ]; then\n if [ /app -ef \"$2\" ]; then cd /app; else cd \"$2\"; fi || exit 1\n shift 2\nfi\n[ \"$#\" -gt 0 ] || { echo \"usage: with-temp-home [--no-wait] [--cwd <dir>] <cmd> [args...]\" >&2; exit 2; }\n# Wait like the pr gate while host load is over budget.host_load (SW-224), before HOME\n# changes so the real config's budget applies; no werkmeister on PATH, no wait.\n# In the background with a trap, so killing the wrapper ends the wait too (SW-456).\n[ -n \"$no_wait\" ] || ! command -v werkmeister >/dev/null 2>&1 || {\n # Trap before the fork: $! is empty until the job exists, so no signal can land between them.\n trap 'kill $! 2>/dev/null; exit 130' HUP INT TERM\n werkmeister internal wait-load >&2 &\n wait $!\n# 75: the wait is spent and load is still over, so running would pile on (SW-540); any other failure runs.\n} || { s=$?; [ \"$s\" -ne 75 ] || exit 75; }\ntmp=$(mktemp -d) || exit 1\n# os.tmpdir() scratch from the wrapped command goes with the temp HOME (SW-799); HOME = TMPDIR is also how a test entry knows the HOME is this temp one (SW-662).\nexport TMPDIR=\"$tmp\"\ntrap 'rm -rf \"$tmp\"' EXIT\ntrap 'exit 130' HUP INT TERM\n# Corepack keeps pnpm under HOME; without this a fresh HOME re-downloads it every run.\nexport COREPACK_HOME=\"${COREPACK_HOME:-$HOME/.cache/node/corepack}\"\n# OrbStack and Docker Desktop keep the compose plugin and context here (SW-285).\nexport DOCKER_CONFIG=\"${DOCKER_CONFIG:-$HOME/.docker}\"\n# A temp HOME isolates files, not the daemon: unreachable unless the caller sets it (SW-264). Refused, as a\n# stopped daemon is: fetch rejects :1 as a \"bad port\" before connecting (SW-743). A short retry, not the 15 s restart gap.\n# shortcut: 65535 is in macOS's ephemeral range, so a port-0 listener (another test's fake daemon) can hold it; bind-and-close a port (SW-708) if that flakes.\nexport WERKMEISTER_HOST=\"${WERKMEISTER_HOST:-http://127.0.0.1:65535}\"\nexport WERKMEISTER_DAEMON_RETRY_MS=\"${WERKMEISTER_DAEMON_RETRY_MS:-500}\"\n# An agent's shell inherits its Claude Code session's variables; CI has none (SW-332). CLAUDE_BIN stays.\nunset CLAUDECODE\nfor v in $(env | sed -n '/^CLAUDE_CODE_[A-Za-z0-9_]*=/s/=.*//p'); do unset \"$v\"; done\nHOME=$tmp \"$@\"\nstatus=$?\n# A failure under load reads as load (SW-209).\n[ \"$status\" -eq 0 ] || echo \"with-temp-home: exit $status; host load $(uptime | sed 's/.*load averages*: //; s/,//g') on $(getconf _NPROCESSORS_ONLN) cores\" >&2\nexit \"$status\"\n";
|
|
8
8
|
export declare function tempHomeWrapper(workspaceRoot: string): string;
|
|
9
9
|
/** Write the wrapper, executable, over any earlier copy; returns its path. */
|
|
10
10
|
export declare function writeTempHomeWrapper(workspaceRoot: string): string;
|
package/dist/temp_home.js
CHANGED
|
@@ -15,7 +15,13 @@ export const TEMP_HOME_SCRIPT = `#!/bin/sh
|
|
|
15
15
|
# and exports it, so a with-temp-home nested under it skips its wait too (SW-425).
|
|
16
16
|
[ "\${1:-}" != --no-wait ] || { export WERKMEISTER_NO_WAIT=1; shift; }
|
|
17
17
|
no_wait=\${WERKMEISTER_NO_WAIT:-}
|
|
18
|
-
|
|
18
|
+
# --cwd <dir> next runs the command there, whatever the shell's cwd, with no \`cd\` to break the allow rule (SW-652).
|
|
19
|
+
# In the werkmeister container the worktree is also at /app, the only place its node_modules volume is mounted (SW-548).
|
|
20
|
+
if [ "\${1:-}" = --cwd ] && [ "$#" -ge 2 ]; then
|
|
21
|
+
if [ /app -ef "$2" ]; then cd /app; else cd "$2"; fi || exit 1
|
|
22
|
+
shift 2
|
|
23
|
+
fi
|
|
24
|
+
[ "$#" -gt 0 ] || { echo "usage: with-temp-home [--no-wait] [--cwd <dir>] <cmd> [args...]" >&2; exit 2; }
|
|
19
25
|
# Wait like the pr gate while host load is over budget.host_load (SW-224), before HOME
|
|
20
26
|
# changes so the real config's budget applies; no werkmeister on PATH, no wait.
|
|
21
27
|
# In the background with a trap, so killing the wrapper ends the wait too (SW-456).
|
|
@@ -27,7 +33,7 @@ no_wait=\${WERKMEISTER_NO_WAIT:-}
|
|
|
27
33
|
# 75: the wait is spent and load is still over, so running would pile on (SW-540); any other failure runs.
|
|
28
34
|
} || { s=$?; [ "$s" -ne 75 ] || exit 75; }
|
|
29
35
|
tmp=$(mktemp -d) || exit 1
|
|
30
|
-
# os.tmpdir() scratch from the wrapped command goes with the temp HOME (SW-799).
|
|
36
|
+
# os.tmpdir() scratch from the wrapped command goes with the temp HOME (SW-799); HOME = TMPDIR is also how a test entry knows the HOME is this temp one (SW-662).
|
|
31
37
|
export TMPDIR="$tmp"
|
|
32
38
|
trap 'rm -rf "$tmp"' EXIT
|
|
33
39
|
trap 'exit 130' HUP INT TERM
|
|
@@ -35,8 +41,11 @@ trap 'exit 130' HUP INT TERM
|
|
|
35
41
|
export COREPACK_HOME="\${COREPACK_HOME:-$HOME/.cache/node/corepack}"
|
|
36
42
|
# OrbStack and Docker Desktop keep the compose plugin and context here (SW-285).
|
|
37
43
|
export DOCKER_CONFIG="\${DOCKER_CONFIG:-$HOME/.docker}"
|
|
38
|
-
# A temp HOME isolates files, not the daemon: unreachable unless the caller sets it (SW-264).
|
|
39
|
-
|
|
44
|
+
# A temp HOME isolates files, not the daemon: unreachable unless the caller sets it (SW-264). Refused, as a
|
|
45
|
+
# stopped daemon is: fetch rejects :1 as a "bad port" before connecting (SW-743). A short retry, not the 15 s restart gap.
|
|
46
|
+
# shortcut: 65535 is in macOS's ephemeral range, so a port-0 listener (another test's fake daemon) can hold it; bind-and-close a port (SW-708) if that flakes.
|
|
47
|
+
export WERKMEISTER_HOST="\${WERKMEISTER_HOST:-http://127.0.0.1:65535}"
|
|
48
|
+
export WERKMEISTER_DAEMON_RETRY_MS="\${WERKMEISTER_DAEMON_RETRY_MS:-500}"
|
|
40
49
|
# An agent's shell inherits its Claude Code session's variables; CI has none (SW-332). CLAUDE_BIN stays.
|
|
41
50
|
unset CLAUDECODE
|
|
42
51
|
for v in $(env | sed -n '/^CLAUDE_CODE_[A-Za-z0-9_]*=/s/=.*//p'); do unset "$v"; done
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "werkmeister-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.95.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "werkmeister's shared library. Its public API is werkmeister-core/sdk; every other entry point is internal.",
|
|
@@ -136,6 +136,7 @@
|
|
|
136
136
|
"docs:links": "typedoc",
|
|
137
137
|
"docs:sdk": "node ../../scripts/format-examples.mjs --check && typedoc --options typedoc.sdk.json",
|
|
138
138
|
"test": "sh ./run-tests.sh",
|
|
139
|
-
"test:changed": "node test-changed.mjs"
|
|
139
|
+
"test:changed": "node test-changed.mjs",
|
|
140
|
+
"test:no-match": "sh ../../scripts/require-temp-home.sh && unset GIT_DIR GIT_WORK_TREE GIT_COMMON_DIR && WERKMEISTER_GH_BIN=$PWD/test/no-gh.sh node --test --test-concurrency=3 --test-name-pattern=__nomatch__ test/*.test.mjs"
|
|
140
141
|
}
|
|
141
142
|
}
|