werkmeister-core 0.93.8 → 0.93.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # sandbox-core
2
2
 
3
+ ## 0.93.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 5db8d8a: Autonomous workspaces no longer pre-approve `werkmeister feature up --service:*` or `feature up <feature> --service:*`, which let an agent start another workspace's service (`feature up --service x <other>`, or `-w <path>`). Both forms are now allowed exactly, once for each of the workspace's own services (SW-843).
8
+ - 2e91d10: A service whose volumes mount the docker socket or the werkmeister home (or a parent of either) no longer gets a pre-approved `docker exec <feature>-<svc> sh -c '<test>'` rule: its test code would run with the host's docker and the real `~/.werkmeister`. Those runs ask; `werkmeister pr gate` still runs them (SW-845).
9
+
10
+ ## 0.93.9
11
+
3
12
  ## 0.93.8
4
13
 
5
14
  ### Patch Changes
@@ -0,0 +1,2 @@
1
+ /** The three checks a run makes before filing a bug about a generated file; a leaf module so the issues guide and the ICM review step can share it without an import cycle. */
2
+ export declare const generatedFileCheck: (tool?: string) => string;
@@ -0,0 +1,7 @@
1
+ /** The three checks a run makes before filing a bug about a generated file; a leaf module so the issues guide and the ICM review step can share it without an import cycle. */
2
+ import { COMPOSE_FILE } from "./compose_file.js";
3
+ // SW-844: sw-773 filed SW-835 against werkmeister for a settings.json edit the person had made by hand.
4
+ export const generatedFileCheck = (tool) => `Before filing a bug about a generated file (\`.claude/settings.json\`, \`.werkmeister/*\`, \`${COMPOSE_FILE}\`, \`.env\`) that changed outside this run's own edits, check three things and file only if they still point at werkmeister: ` +
5
+ "(1) compare it with its record where one exists (`.werkmeister/claude-permissions.json` for the permission rules and model werkmeister merges in; hook entries are not recorded) and say whether the record changed too — werkmeister rewrites the record whenever it changes what it merges in, so a recorded rule or model missing from the file while the record is unchanged was not removed by werkmeister; " +
6
+ "(2) compare the file's mtime with this session's own activity: was any of its commands running then? " +
7
+ `(3) Ask the person${tool ? ` through \`${tool}\`` : ""} whether they edited it, before naming a werkmeister writer.`;
@@ -90,8 +90,11 @@ export declare function removeWorkspaceHooks(workspaceRoot: string): string[];
90
90
  export declare function writeAutoStopHook(workspaceRoot: string, on: boolean): string;
91
91
  export declare const READ_ONLY_GIT_RULES: string[];
92
92
  export declare const AUTONOMOUS_RULES: string[];
93
- /** AUTONOMOUS_RULES plus the `werkmeister` and `docker` commands that name this feature or its containers. */
94
- export declare function autonomousRules(feature: string, services: string[]): string[];
93
+ /**
94
+ * AUTONOMOUS_RULES plus the `werkmeister` and `docker` commands that name this feature or its containers.
95
+ * *repoServices*: the workspace's repos' other services (on-demand ones), which only `feature up --service` starts.
96
+ */
97
+ export declare function autonomousRules(feature: string, services: string[], repoServices?: string[]): string[];
95
98
  /**
96
99
  * Allow rules for each local service's registered test command, then read-only
97
100
  * git. Each command gets the container form the agent is told to run, plus the
@@ -43,9 +43,11 @@
43
43
  */
44
44
  import * as fs from "node:fs";
45
45
  import * as path from "node:path";
46
+ import { parse as parseYaml } from "yaml";
46
47
  import { candidateServiceNames, containerTestCommand, isPlainChain, serviceTestCommand, wrappedTestCommand, } from "../../archetypes.js";
47
- import { dotDir, getReposRoot, loadArchetypes, loadReposConfig, loadServices, } from "../../config.js";
48
+ import { dotDir, expandUser, getReposRoot, loadArchetypes, loadReposConfig, loadServices, sandboxHome, sandboxRoot, } from "../../config.js";
48
49
  import { frozenInstalls } from "../../fragment_detect/workspace.js";
50
+ import { workspaceServices } from "../../registry_sync.js";
49
51
  import { info } from "../../reporter.js";
50
52
  import { repoDirs } from "../../standards.js";
51
53
  import { tempHomeWrapper } from "../../temp_home.js";
@@ -349,8 +351,6 @@ export const AUTONOMOUS_RULES = [
349
351
  // No-arg forms act on the cwd's FEATURE; `autonomousRules` adds the named ones.
350
352
  // Each pre-SW-186 spelling keeps its rule until the CLI drops it, beside its new one.
351
353
  ...["up", "restart", "feature up", "feature restart"].flatMap(cli),
352
- // SW-132: one of its own services, on-demand ones included, the way the PR gate starts them.
353
- ...cli("feature up --service:*"),
354
354
  ...[
355
355
  "status",
356
356
  "feature status",
@@ -386,15 +386,20 @@ export const AUTONOMOUS_RULES = [
386
386
  "k8s-forwards-status",
387
387
  ].flatMap(pluginTool),
388
388
  ];
389
- /** AUTONOMOUS_RULES plus the `werkmeister` and `docker` commands that name this feature or its containers. */
390
- export function autonomousRules(feature, services) {
389
+ /**
390
+ * AUTONOMOUS_RULES plus the `werkmeister` and `docker` commands that name this feature or its containers.
391
+ * *repoServices*: the workspace's repos' other services (on-demand ones), which only `feature up --service` starts.
392
+ */
393
+ export function autonomousRules(feature, services, repoServices = []) {
391
394
  if (!feature)
392
395
  return AUTONOMOUS_RULES;
393
396
  return [
394
397
  ...AUTONOMOUS_RULES,
395
398
  // Exact: `werkmeister feature restart <f> infra` and `docker restart <f>-a <other>` stay out.
396
399
  ...["up", "restart", "feature up", "feature restart"].flatMap((cmd) => cli(`${cmd} ${feature}`)),
397
- ...cli(`feature up ${feature} --service:*`),
400
+ // SW-132: one of its own services, the way the PR gate starts them. SW-843: exact, since a
401
+ // trailing `<other>` or `-w <path>` would start another workspace's container.
402
+ ...[...services, ...repoServices].flatMap((svc) => [`feature up --service ${svc}`, `feature up ${feature} --service ${svc}`].flatMap(cli)),
398
403
  ...["logs", "test", "services", "feature logs", "feature test", "feature services"].flatMap((cmd) => cli(`${cmd} ${feature}:*`)),
399
404
  // SW-560: no `docker exec <f>-<svc>:*`: any container reaches the host daemon over
400
405
  // host.docker.internal, and some mount the docker socket; its exact registered test still runs.
@@ -428,7 +433,8 @@ hostServices = [], reposConfig = {}) {
428
433
  const cmd = serviceTestCommand(svc, servicesConfig[svc], archetypes);
429
434
  if (!cmd)
430
435
  continue;
431
- if (services.includes(svc)) {
436
+ // SW-845: a container holding the docker socket or the real werkmeister home asks each run.
437
+ if (services.includes(svc) && !hostAccess(servicesConfig[svc])) {
432
438
  rules.push(`Bash(${containerTestCommand(feature, svc, cmd)})`);
433
439
  // Splitting a `{ …; }` group or `||` on `&&` gives rules no shell command matches.
434
440
  if (isPlainChain(cmd))
@@ -457,6 +463,61 @@ hostServices = [], reposConfig = {}) {
457
463
  .map((r) => `${wrapped}--no-wait ${r.slice(wrapped.length)}`));
458
464
  return [...new Set([...rules, ...READ_ONLY_GIT_RULES])];
459
465
  }
466
+ /**
467
+ * True when one of *entry*'s host binds is a docker socket (any path ending `docker.sock`, e.g. OrbStack's)
468
+ * or the werkmeister home, or a parent of either; symlinks resolved (`/var` → `/private/var` on macOS).
469
+ */
470
+ function hostAccess(entry) {
471
+ const real = (p) => {
472
+ try {
473
+ return fs.realpathSync(p);
474
+ }
475
+ catch {
476
+ return path.resolve(p);
477
+ }
478
+ };
479
+ const targets = ["/var/run/docker.sock", sandboxHome()].map(real);
480
+ return (entry?.extra_volumes ?? []).some((spec) => {
481
+ const src = spec.split(":")[0];
482
+ if (!src.includes("/"))
483
+ return false; // a named volume
484
+ const host = real(expandUser(src));
485
+ if (path.basename(host) === "docker.sock")
486
+ return true;
487
+ return targets.some((t) => t === host || t.startsWith(`${host}${path.sep}`) || host === "/");
488
+ });
489
+ }
490
+ /**
491
+ * SW-845: *registry* with each entry's `extra_volumes` widened to every bind compose mounts: the
492
+ * branch's own fragment and the workspace's `dev_links` too (both agent-editable), variables
493
+ * substituted as generate.ts does. Only the mounts: test commands stay the registry's.
494
+ */
495
+ function withComposeMounts(registry, workspaceRoot) {
496
+ const branch = workspaceServices(registry, workspaceRoot);
497
+ // generate.ts's loadDevLinks reads the same field; importing it closes a cycle (generate → claude_md → jira → here).
498
+ let devLinks = {};
499
+ try {
500
+ const yml = parseYaml(fs.readFileSync(path.join(dotDir(workspaceRoot), "workspace.yml"), "utf8"));
501
+ devLinks = yml?.["dev_links"] ?? {};
502
+ }
503
+ catch {
504
+ // No workspace.yml (or unreadable): no dev_links, as generate.ts reads it.
505
+ }
506
+ return Object.fromEntries(Object.entries(registry).map(([id, entry]) => {
507
+ const repo = path.join(workspaceRoot, String(branch[id]?.["repo"] ?? entry["repo"] ?? ""));
508
+ const specs = [
509
+ ...(entry.extra_volumes ?? []),
510
+ ...(branch[id]?.extra_volumes ?? []),
511
+ ...(devLinks[id] ?? []),
512
+ ].map((s) => {
513
+ const out = s.split("${WORKSPACE}").join(workspaceRoot).split("${REPO}").join(repo);
514
+ return out.includes("${WERKMEISTER_ROOT}")
515
+ ? out.split("${WERKMEISTER_ROOT}").join(sandboxRoot())
516
+ : out;
517
+ });
518
+ return [id, { ...entry, extra_volumes: specs }];
519
+ }));
520
+ }
460
521
  function _readEnv(workspaceRoot) {
461
522
  let text;
462
523
  try {
@@ -504,7 +565,7 @@ export function workspaceAllowRules(workspaceRoot, autonomous = readAutonomous(w
504
565
  }
505
566
  const extra = hostServices.filter((s) => !services.includes(s));
506
567
  const any = services.length > 0 || extra.length > 0;
507
- const rules = buildAllowRules(any ? feature : "", services, any ? loadServices() : {}, any ? loadArchetypes() : {}, wrapper, builtClis, extra, reposConfig);
568
+ const rules = buildAllowRules(any ? feature : "", services, any ? withComposeMounts(loadServices(), workspaceRoot) : {}, any ? loadArchetypes() : {}, wrapper, builtClis, extra, reposConfig);
508
569
  rules.push(...readGrants(workspaceRoot).flatMap(cli));
509
570
  if (!autonomous)
510
571
  return rules;
@@ -513,7 +574,7 @@ export function workspaceAllowRules(workspaceRoot, autonomous = readAutonomous(w
513
574
  // `yarnPath` would otherwise grant itself an install that runs its own file.
514
575
  const reposRoot = getReposRoot();
515
576
  const installs = repoNames.flatMap((name) => frozenInstalls((f) => fs.existsSync(path.join(reposRoot, name, f))).map((c) => `Bash(${c})`));
516
- return [...new Set([...rules, ...autonomousRules(feature, services), ...installs])];
577
+ return [...new Set([...rules, ...autonomousRules(feature, services, extra), ...installs])];
517
578
  }
518
579
  function builtCliWrappers(workspaceRoot) {
519
580
  return repoDirs(workspaceRoot)
@@ -10,4 +10,4 @@
10
10
  */
11
11
  import { type IssueTrackerStrategy } from "./issue_tracker.js";
12
12
  export declare const WERKMEISTER_ISSUES_REPO = "jbbz-sandbox/werkmeister";
13
- export declare function buildIssuesReportMd(workspaceName: string, issueId?: string, tracker?: IssueTrackerStrategy): string;
13
+ export declare function buildIssuesReportMd(workspaceName: string, issueId?: string, tracker?: IssueTrackerStrategy, questionTool?: string): string;
@@ -9,9 +9,10 @@
9
9
  * `.werkmeister/issues-report.md`; each strategy's CLAUDE.md points at its copy.
10
10
  */
11
11
  import { COMPOSE_FILE } from "./compose_file.js";
12
+ import { generatedFileCheck } from "./generated_file_check.js";
12
13
  import { issueTracker } from "./issue_tracker.js";
13
14
  export const WERKMEISTER_ISSUES_REPO = "jbbz-sandbox/werkmeister";
14
- export function buildIssuesReportMd(workspaceName, issueId = "", tracker = issueTracker()) {
15
+ export function buildIssuesReportMd(workspaceName, issueId = "", tracker = issueTracker(), questionTool) {
15
16
  const { row: appRow, search: searchStep, werkmeister, } = tracker.filingGuide(issueId.trim(), workspaceName);
16
17
  const sandboxWhere = werkmeister ?? {
17
18
  where: `https://github.com/${WERKMEISTER_ISSUES_REPO}/issues`,
@@ -45,6 +46,8 @@ Decide this first.
45
46
 
46
47
  Not sure? Check whether it happens on the base branch. If you still can't tell, ask the person — don't guess.
47
48
 
49
+ ${generatedFileCheck(questionTool)}
50
+
48
51
  ## Features and tasks
49
52
 
50
53
  File one when the person asks for it, or when you find work outside this workspace's task. Work inside the task is done here, not filed.
@@ -340,7 +340,7 @@ function render(ctx) {
340
340
  const base = vars(ctx, stages);
341
341
  const files = {
342
342
  "_shared/standards.md": renderStandards(r),
343
- "_shared/issues-report.md": buildIssuesReportMd(ctx.workspaceName, issueIdOfMeta(ctx.meta), issueTracker({ project: ctx.inputs["project"], text: issueIdOfMeta(ctx.meta) })),
343
+ "_shared/issues-report.md": buildIssuesReportMd(ctx.workspaceName, issueIdOfMeta(ctx.meta), issueTracker({ project: ctx.inputs["project"], text: issueIdOfMeta(ctx.meta) }), base.questionTool),
344
344
  };
345
345
  files["_shared/pr-rules.md"] = buildPrRulesMd(`stages/${prDir(stages)}/output/`, base.autonomous);
346
346
  stages.forEach((stage, i) => {
@@ -7,6 +7,7 @@
7
7
  * restated.
8
8
  */
9
9
  import { COMPOSE_FILE } from "../compose_file.js";
10
+ import { generatedFileCheck } from "../generated_file_check.js";
10
11
  import { APPROVAL_NOTE, CHAT_APPROVAL, HOST_SCRIPT_RULE } from "../pr_rules.js";
11
12
  // SW-135: a container that never started has no `pnpm` in /opt/werkmeister-tools until `werkmeister feature up`
12
13
  // bootstraps it, so `docker restart` on it loops on "pnpm: not found".
@@ -33,11 +34,13 @@ const baseCheck = (doc) => `Before writing code, fetch the base and list \`git l
33
34
  // SW-547: sw-526's over-width test lines surfaced only at the lint chain, after 7 commits.
34
35
  const HOST_TESTS =
35
36
  // SW-646: the command is the repo's `format:` (registry `repo:`), so no toolchain is named here.
36
- "If `../../.werkmeister/werkmeister-context.md` gives the repo a format command (`Format:` under its repo commands), first run it on the files you touched (never a folder), so formatting lands in the ticket's own commit. " +
37
+ "If `../../.werkmeister/werkmeister-context.md` gives the repo a format command (`Format:` under its repo commands), first run it on the files you touched (never a folder), where the service's tests run (its container when its How-to-validate text says so), so formatting lands in the ticket's own commit. " +
37
38
  "Run the test command exactly as `../../.werkmeister/werkmeister-context.md` states it: through `.werkmeister/bin/with-temp-home`, which gives it a fresh temporary HOME — never hand-roll `HOME=…`. " +
38
39
  "That run is on the host, without the container's env (`HOST`, `WERKMEISTER_SLOT`, `NODE_ENV`, `<SVC>_URL`, …), and the PR gate runs the same commands in the workspace container. " +
39
40
  // SW-506: werkmeister's host checkout has no node_modules; the recipe is its services.yaml text (SW-190), not this generic step.
40
- "When a service's How-to-validate text in `werkmeister-context.md` says to run in its container (`docker exec`), follow that text instead: starting this workspace's own container with `werkmeister feature up --service <name>` is expected for it and allowed. ";
41
+ "When a service's How-to-validate text in `werkmeister-context.md` says to run in its container (`docker exec`), follow that text instead: starting this workspace's own container with `werkmeister feature up --service <name>` is expected for it and allowed. " +
42
+ // SW-846: sw-829 ran only a one-file fast route in the container; the gate's lint row then failed on formatting.
43
+ "Before `werkmeister pr gate --tests`, run the repo's whole lint chain there too (every command the test command in `werkmeister-context.md` runs ahead of the service's own tests, when it has any; one `&&` segment alone is not it) and fix what it fails: a fast route that runs one test file skips it, and the gate's lint row then fails on it. ";
41
44
  const TEST_TAIL = "A subagent you brief to run tests or the CLI gets that wrapped command verbatim in its brief. " +
42
45
  // SW-125: a host-skipped test still asserted removed behaviour; only the gate's container run found it.
43
46
  "A skipped test is not a pass: name each one with its skip reason, and run it where it can run (the workspace container) or say where it will (the gate, CI). " +
@@ -86,7 +89,7 @@ const groupStep = (v) => v.group.length
86
89
  // SW-388: in sw-386 a must-fix passed the tests, the exercise and the gate; only a separate review caught it.
87
90
  // SW-505: sw-469 wrote review.md as prose and lost a gate pass; the gate reads the `result` column of every table.
88
91
  const REVIEW_FORMAT = "a `| criterion | result | evidence |` table whose result cell is exactly `PASS` or `FAIL` — nothing else in the cell — with the proof in the evidence column";
89
- const reviewStep = (rerun, group) => "Review the diff: for each code worktree you touched, start a fresh subagent and brief it with only the worktree path and " +
92
+ const reviewStep = (rerun, { group, questionTool }) => "Review the diff: for each code worktree you touched, start a fresh subagent and brief it with only the worktree path and " +
90
93
  `"run the \`ponytail:ponytail-review\` skill over this worktree's ${group.length
91
94
  ? "commits in `origin/main...HEAD` (the PR's base in place of `main` when it differs), plus any uncommitted changes and untracked files"
92
95
  : "uncommitted changes, untracked files included"}" — not how you built it, so the review is not anchored on your reasoning. ` +
@@ -99,10 +102,11 @@ const reviewStep = (rerun, group) => "Review the diff: for each code worktree yo
99
102
  // SW-449: a left Should fix shipped a false "every key is checked" in a changeset (sw-412).
100
103
  "Fix every **Must fix** finding in place, and any **Should fix** finding that shows the change's own docs, comments, help text or release entry state something false (fix the code, or reword that text so it is true), " +
101
104
  `${group.length ? `fold each fix into the commit of the ticket it belongs to (${FOLD}), ` : ""}then ${rerun}. Leave the other **Should fix** and **Nice to have** findings as they are. ` +
105
+ `${generatedFileCheck(questionTool)} ` +
102
106
  "Write `output/review.md`: per worktree, the findings as the review grouped them, each marked `fixed` or `left: <why>`, then " +
103
107
  `${REVIEW_FORMAT}, with one row per worktree (\`PASS\` means no Must fix left open). ` +
104
108
  "The PR gate refuses to open a PR while `review.md` is missing or has a row that is not `PASS`; a file of prose alone fails with `has no PASS row`.";
105
- const implementReview = (v) => reviewStep("rerun the host test step above", v.group);
109
+ const implementReview = (v) => reviewStep("rerun the host test step above", v);
106
110
  // SW-687: sw-634 decided a blocklist for a pre-approved wrapper's input; one key it let through sent auth to any host.
107
111
  const PREAPPROVED_INPUT = "When the change adds or widens an input to a pre-approved command (an allow rule, or a wrapper an allow rule covers), the decision defaults to an allowlist of accepted values and lists what each accepted value can reach: files, env vars, network addresses, processes. A blocklist needs a stated reason.";
108
112
  // SW-789: sw-751 named the build chain as the critical path from task start/end times; the row held all 3 CPUs for ~170 s, so only a CPU cut shortens it.
@@ -404,7 +408,7 @@ const bugfix = [
404
408
  // SW-579: the review step rewrites exercise.md, so recorded MANUAL results come first.
405
409
  MANUAL_STEP,
406
410
  // SW-678: these edits come after the fix stage's gate; one service's test command missed docs-site's (sw-631, sw-669).
407
- reviewStep("rerun `werkmeister pr gate --tests` (from the workspace, as a background job with its log, as rule 3 of `_shared/pr-rules.md` shows), not one service's test command: it retests every service the diff touches, and these edits come after the fix stage's gate. Then rerun steps 2–3 and update `exercise.md`", v.group),
411
+ reviewStep("rerun `werkmeister pr gate --tests` (from the workspace, as a background job with its log, as rule 3 of `_shared/pr-rules.md` shows), not one service's test command: it retests every service the diff touches, and these edits come after the fix stage's gate. Then rerun steps 2–3 and update `exercise.md`", v),
408
412
  ],
409
413
  outputs: [
410
414
  "`output/exercise.md`",
@@ -176,7 +176,7 @@ function init(ctx) {
176
176
  // CLAUDE.md's "## Issues" section points here.
177
177
  const issuesReportPath = path.join(dotDir(workspaceRoot), "issues-report.md");
178
178
  fs.mkdirSync(path.dirname(issuesReportPath), { recursive: true });
179
- fs.writeFileSync(issuesReportPath, buildIssuesReportMd(workspaceName, issueIdOfMeta(meta), issueTracker({ project: inputs["project"], text: issueIdOfMeta(meta) })));
179
+ fs.writeFileSync(issuesReportPath, buildIssuesReportMd(workspaceName, issueIdOfMeta(meta), issueTracker({ project: inputs["project"], text: issueIdOfMeta(meta) }), layout.questionTool));
180
180
  success(`Wrote ${issuesReportPath}`);
181
181
  const prRulesPath = path.join(dotDir(workspaceRoot), "pr-rules.md");
182
182
  fs.writeFileSync(prRulesPath, buildPrRulesMd(".werkmeister/notes/"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "werkmeister-core",
3
- "version": "0.93.8",
3
+ "version": "0.93.10",
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.",