werkmeister-core 0.94.4 → 0.95.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 +14 -0
- package/README.md +4 -0
- package/dist/fixture_workspace.d.ts +2 -0
- package/dist/fixture_workspace.js +4 -2
- 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/pr_lifecycle.d.ts +33 -1
- package/dist/pr_lifecycle.js +159 -9
- package/dist/pr_rules.js +3 -3
- package/dist/sandbox.d.ts +1 -1
- package/dist/sandbox.js +3 -2
- 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/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# sandbox-core
|
|
2
2
|
|
|
3
|
+
## 0.95.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f9c23df: werkmeister-core's test runner takes `COVERAGE=1` (and `pnpm run test:coverage`, which builds with source maps first): Node's built-in coverage, with lcov reports mapped back to `src/` in `$COVERAGE_DIR` (default `coverage/`). Off by default; the README's "Test coverage" section has the caveats (SW-756).
|
|
8
|
+
- 54c43fa: `with-fixture-workspace --gate` takes `--pr-line '<key>: <value>'` (repeatable), written into the seeded PR file as is, so a test can seed an unquoted value that `--pr-field` would quote, e.g. `--pr-line 'skip_release: no changeset: test-only'`, which the gate refuses with "Quote values that contain a colon". The keys are `--pr-field`'s but `status` (`--pr-field status=` already writes that line as is); one line, and it needs `--gate` (exit 2 otherwise). In-process fixtures take `prLines` (SW-851). Rerun `werkmeister workspace init` to regenerate the script's usage line.
|
|
9
|
+
|
|
10
|
+
## 0.95.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- 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`.
|
|
15
|
+
- 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.
|
|
16
|
+
|
|
3
17
|
## 0.94.4
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -31,6 +31,10 @@ for (const ws of workspaces) {
|
|
|
31
31
|
|
|
32
32
|
The daemon's operations are reached with `callTool`. The full API is at [werkmeister.io/sdk](https://werkmeister.io/sdk/).
|
|
33
33
|
|
|
34
|
+
## Test coverage (contributors)
|
|
35
|
+
|
|
36
|
+
In a werkmeister checkout, `pnpm --filter werkmeister-core run test:coverage` builds `dist/` with source maps and runs the suite with Node's built-in coverage (Node 22.5 or later). It prints a coverage table after the usual output and writes lcov reports, mapped back to `src/*.ts`, to `$COVERAGE_DIR` (default `coverage/`, git-ignored): `lcov-isolated.info` and `lcov-shared.info`, one per `node --test` run. Off by default: `pnpm test` is unchanged. A CI shard (`pnpm test N/M`) reports only its own files, and the `test/*.smoke.mjs` smokes run as plain `node`, so they are not counted. The run costs about 40% more wall time and 35% more CPU (77 s against 55 s in a 3-CPU container). Run `pnpm build` afterwards to rebuild `dist/` without source maps.
|
|
37
|
+
|
|
34
38
|
## Licence
|
|
35
39
|
|
|
36
40
|
Apache-2.0. See `LICENSE` and `NOTICE`.
|
|
@@ -40,6 +40,8 @@ export interface FixtureOptions {
|
|
|
40
40
|
issue?: string;
|
|
41
41
|
/** Extra front matter for each seeded PR file, e.g. `{ skip_release: "tests only" }` (SW-514); `status` replaces `approved`, verbatim (SW-549). */
|
|
42
42
|
prFields?: Record<string, string>;
|
|
43
|
+
/** Raw front matter lines added to each seeded PR file after `prFields`, unquoted, e.g. `skip_release: no changeset: test-only` (SW-851). */
|
|
44
|
+
prLines?: string[];
|
|
43
45
|
/** Every ports.yaml slot leased to `other-N`, each with its own folder so heldSlots keeps it, for no-slot paths (SW-634). */
|
|
44
46
|
slotsFull?: boolean;
|
|
45
47
|
/** 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). */
|
|
@@ -157,7 +157,9 @@ ${githubProject(repos.map((r) => r.name))}${opts.config ? YAML.stringify(opts.co
|
|
|
157
157
|
}
|
|
158
158
|
// status goes in verbatim, so a brief can try the forms people write, comments included (SW-549).
|
|
159
159
|
const { status = "approved", ...prFields } = opts.prFields ?? {};
|
|
160
|
-
|
|
160
|
+
// prLines go in as written, so a test can seed what YAML.stringify would quote (SW-851).
|
|
161
|
+
const extra = (Object.keys(prFields).length ? YAML.stringify(prFields) : "") +
|
|
162
|
+
(opts.prLines ?? []).map((l) => `${l}\n`).join("");
|
|
161
163
|
let applyFragmentChange;
|
|
162
164
|
for (const { name, change } of repos) {
|
|
163
165
|
// Ends in owner/repo.git so originSlug matches the PR file's repo: (SW-381).
|
|
@@ -328,7 +330,7 @@ const SCRIPT = `#!/bin/sh
|
|
|
328
330
|
# Generated by \`werkmeister workspace init\` (SW-292); rerun it to regenerate.
|
|
329
331
|
# Runs this workspace's own built werkmeister CLI against a seeded fixture workspace, removed on exit:
|
|
330
332
|
# temp HOME and registry, a local bare origin, logging fakes for gh and docker, dead Docker and daemon.
|
|
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>]...
|
|
333
|
+
# 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>]... [--pr-line '<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>]...
|
|
332
334
|
# It only ever runs that CLI, never another command, so one allow rule can cover it (SW-172, SW-231);
|
|
333
335
|
# --exec-runs, given first, also runs the registry's rows on the host, so the workspace asks before it (SW-473).
|
|
334
336
|
ws=$(cd "$(dirname "$0")/../.." && pwd -P) || exit 1
|
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/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";
|
|
@@ -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())
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "werkmeister-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.95.1",
|
|
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.",
|
|
@@ -137,6 +137,7 @@
|
|
|
137
137
|
"docs:sdk": "node ../../scripts/format-examples.mjs --check && typedoc --options typedoc.sdk.json",
|
|
138
138
|
"test": "sh ./run-tests.sh",
|
|
139
139
|
"test:changed": "node test-changed.mjs",
|
|
140
|
+
"test:coverage": "tsc --sourceMap && COVERAGE=1 sh ./run-tests.sh",
|
|
140
141
|
"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"
|
|
141
142
|
}
|
|
142
143
|
}
|