werkmeister-core 0.92.2 → 0.93.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # sandbox-core
2
2
 
3
+ ## 0.93.1
4
+
5
+ ### Patch Changes
6
+
7
+ - cde5d85: SW-799: `with-temp-home` exports `TMPDIR` as its temp dir, so scratch a wrapped command makes in `os.tmpdir()` (the scripts tests' `mkdtemp` dirs) is removed on exit instead of piling up in the host's temp folder.
8
+
9
+ ## 0.93.0
10
+
3
11
  ## 0.92.2
4
12
 
5
13
  ## 0.92.1
@@ -50,7 +50,7 @@ import { info } from "../../reporter.js";
50
50
  import { repoDirs } from "../../standards.js";
51
51
  import { tempHomeWrapper } from "../../temp_home.js";
52
52
  // biome-ignore lint/suspicious/noImportCycles: jira→harness→…→issue_tracker (SW-188); SW-411
53
- import { readAutonomous, readAutoStop, readModel } from "../../workspace_prompts.js";
53
+ import { readAutonomous, readAutoStop, readGrants, readModel } from "../../workspace_prompts.js";
54
54
  import { AUTONOMOUS_DENY, cli, pluginTool } from "../autonomous_deny.js";
55
55
  import { CODEX_HOOKS_FILE, CODEX_LAUNCH, writeCodexConfig } from "../codex/index.js";
56
56
  // biome-ignore lint/suspicious/noImportCycles: jira→harness→…→issue_tracker (SW-188); SW-411
@@ -505,6 +505,7 @@ export function workspaceAllowRules(workspaceRoot, autonomous = readAutonomous(w
505
505
  const extra = hostServices.filter((s) => !services.includes(s));
506
506
  const any = services.length > 0 || extra.length > 0;
507
507
  const rules = buildAllowRules(any ? feature : "", services, any ? loadServices() : {}, any ? loadArchetypes() : {}, wrapper, builtClis, extra, reposConfig);
508
+ rules.push(...readGrants(workspaceRoot).flatMap(cli));
508
509
  if (!autonomous)
509
510
  return rules;
510
511
  // Exact: `--prefix`, `--dir`/`-C` reach another workspace, `--script-shell` runs any file.
@@ -527,8 +528,8 @@ function builtCliWrappers(workspaceRoot) {
527
528
  export function workspaceAskRules(workspaceRoot) {
528
529
  const tempHome = tempHomeWrapper(workspaceRoot);
529
530
  const nodeTest = [
530
- `Bash(${tempHome} env WERKMEISTER_ROOT=* node --test:*)`,
531
- `Bash(${tempHome} --no-wait env WERKMEISTER_ROOT=* node --test:*)`,
531
+ `Bash(${tempHome} env WERKMEISTER_ROOT=* node --test*)`,
532
+ `Bash(${tempHome} --no-wait env WERKMEISTER_ROOT=* node --test*)`,
532
533
  // SW-720: the probe form werkmeister-context.md names; an ask, so auto mode prompts instead of denying it.
533
534
  `Bash(${tempHome} node --test*)`,
534
535
  `Bash(${tempHome} --no-wait node --test*)`,
@@ -177,6 +177,10 @@ function renderContract(dir, stage, v, step0 = "") {
177
177
  "## Outputs",
178
178
  ...c.outputs.map((o) => `- ${o}`),
179
179
  "",
180
+ "## Pre-approved",
181
+ ...(stage.grants ?? []).map((g) => g.endsWith(":*") ? `- \`werkmeister ${g.slice(0, -2)} …\`` : `- \`werkmeister ${g}\``),
182
+ "- Every other command asks. Read and edit files with Read, Edit and Write, never a `python3` heredoc or `python3 -c`, which no run pre-approves (SW-807).",
183
+ "",
180
184
  ...(v.autonomous
181
185
  ? ["## Self-check", c.selfCheck ?? SELF_CHECK]
182
186
  : ["## Human check", c.humanCheck, "", askLine(v.questionTool)]),
@@ -46,6 +46,8 @@ export interface Stage {
46
46
  gate?: string;
47
47
  /** Which _shared/standards.md rows the contract names. */
48
48
  standards: "none" | "all";
49
+ /** SW-807: `werkmeister` subcommands this stage runs, pre-approved for the whole run; init reads them from here, never from the rendered CONTEXT.md, which the agent can edit. */
50
+ grants?: string[];
49
51
  contract(v: IcmVars): Contract;
50
52
  }
51
53
  export declare const askLine: (tool?: string) => string;
@@ -58,3 +60,5 @@ export declare function stageDirs(stages: Stage[]): string[];
58
60
  export declare function proposeDir(stages: Stage[]): string | null;
59
61
  /** The stage dir whose output holds PR files: propose, else the last stage (spike, SW-83). */
60
62
  export declare function prDir(stages: Stage[]): string;
63
+ /** Every stage's grants for *workType*, once each: granted for the whole run (SW-807). */
64
+ export declare function stageGrants(workType: string): string[];
@@ -128,6 +128,9 @@ const exerciseFormat = (col) => `a \`| check | result | ${col} |\` table whose r
128
128
  // SW-736: `changeset status --since` reads git history, so before the commit it failed on an entry just written (sw-699, sw-755).
129
129
  const RELEASE_AFTER_COMMIT = "Run the repo's release check (the `Release check:` command in `werkmeister-context.md`) after the commit, not before: a check that compares the branch with its base in git history does not see an uncommitted release entry.";
130
130
  const LINT = "the repo's lint command (the `<lint> &&` head of the test command in `werkmeister-context.md`, when it has one, which the PR gate's lint row runs) and fix what it fails, release entry included.";
131
+ // SW-807: exact, this workspace's own issue only. The feature, gate and status commands keep asking:
132
+ // each can reach shared infra, another workspace or the real ~/.werkmeister from agent-editable input.
133
+ const START_GRANTS = ["issue start", "issue view"];
131
134
  const propose = {
132
135
  name: "propose",
133
136
  job: "acceptance walk and PR files",
@@ -180,6 +183,7 @@ const noCommitPlan = (group) => group.length
180
183
  const feature = [
181
184
  {
182
185
  name: "research",
186
+ grants: START_GRANTS,
183
187
  job: "inventory the code, surface decisions",
184
188
  writes: "`output/inventory.md`, `output/decisions.md`",
185
189
  check: "answer every open question in `decisions.md`",
@@ -293,6 +297,7 @@ const feature = [
293
297
  const bugfix = [
294
298
  {
295
299
  name: "reproduce",
300
+ grants: START_GRANTS,
296
301
  job: "reproduce and locate the root cause",
297
302
  writes: "`output/repro.md`",
298
303
  check: "agree the root cause",
@@ -398,6 +403,7 @@ const bugfix = [
398
403
  const refactor = [
399
404
  {
400
405
  name: "scope",
406
+ grants: START_GRANTS,
401
407
  job: "fix the boundary and the invariants",
402
408
  writes: "`output/scope.md`",
403
409
  check: "agree what must not change",
@@ -465,6 +471,7 @@ const refactor = [
465
471
  const spike = [
466
472
  {
467
473
  name: "questions",
474
+ grants: START_GRANTS,
468
475
  job: "frame what the spike must answer",
469
476
  writes: "`output/questions.md`",
470
477
  check: "agree the questions and what settles them",
@@ -536,3 +543,7 @@ export function proposeDir(stages) {
536
543
  export function prDir(stages) {
537
544
  return proposeDir(stages) ?? stageDirs(stages)[stages.length - 1];
538
545
  }
546
+ /** Every stage's grants for *workType*, once each: granted for the whole run (SW-807). */
547
+ export function stageGrants(workType) {
548
+ return [...new Set(templateFor(workType).flatMap((s) => s.grants ?? []))];
549
+ }
@@ -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\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:1}\"\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";
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:1}\"\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
@@ -27,6 +27,8 @@ no_wait=\${WERKMEISTER_NO_WAIT:-}
27
27
  # 75: the wait is spent and load is still over, so running would pile on (SW-540); any other failure runs.
28
28
  } || { s=$?; [ "$s" -ne 75 ] || exit 75; }
29
29
  tmp=$(mktemp -d) || exit 1
30
+ # os.tmpdir() scratch from the wrapped command goes with the temp HOME (SW-799).
31
+ export TMPDIR="$tmp"
30
32
  trap 'rm -rf "$tmp"' EXIT
31
33
  trap 'exit 130' HUP INT TERM
32
34
  # Corepack keeps pnpm under HOME; without this a fresh HOME re-downloads it every run.
@@ -28,6 +28,8 @@ export declare function isTrue(value: unknown): boolean;
28
28
  * through `loadConfigFile`, which logs — the same reason as `readContextStrategy`.
29
29
  */
30
30
  export declare function readAutonomous(workspaceRoot: string): boolean;
31
+ /** SW-807: an ICM workspace's stage grants, for the whole run and either mode; none for another strategy. */
32
+ export declare function readGrants(workspaceRoot: string): string[];
31
33
  /** The workspace's `auto_stop` input (#231); unset follows `autonomous` (SW-39). */
32
34
  export declare function readAutoStop(workspaceRoot: string): boolean;
33
35
  /**
@@ -25,6 +25,7 @@ import { resolveModel } from "./model_tiers.js";
25
25
  import { ProcError, run as procRun } from "./proc.js";
26
26
  import { loadProjects } from "./projects.js";
27
27
  import { info, warn } from "./reporter.js";
28
+ import { stageGrants } from "./strategies/icm_templates.js";
28
29
  import { STRATEGY_IDS } from "./strategies/types.js";
29
30
  function isDir(p) {
30
31
  try {
@@ -136,6 +137,12 @@ export function isTrue(value) {
136
137
  export function readAutonomous(workspaceRoot) {
137
138
  return isTrue(readWorkspaceField(workspaceRoot, "autonomous"));
138
139
  }
140
+ /** SW-807: an ICM workspace's stage grants, for the whole run and either mode; none for another strategy. */
141
+ export function readGrants(workspaceRoot) {
142
+ if (String(readWorkspaceField(workspaceRoot, "context_strategy") ?? "").trim() !== "icm")
143
+ return [];
144
+ return stageGrants(String(readWorkspaceField(workspaceRoot, "work_type") ?? ""));
145
+ }
139
146
  /** The workspace's `auto_stop` input (#231); unset follows `autonomous` (SW-39). */
140
147
  export function readAutoStop(workspaceRoot) {
141
148
  const value = readWorkspaceField(workspaceRoot, "auto_stop");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "werkmeister-core",
3
- "version": "0.92.2",
3
+ "version": "0.93.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.",