werkmeister 0.41.0 → 0.44.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.
Files changed (34) hide show
  1. package/CONVENTIONS.md +2 -2
  2. package/README.md +8 -8
  3. package/bin/generate-certs.sh +12 -12
  4. package/dist/NOTICE +1 -1
  5. package/dist/lib/agent_state.js +4 -4
  6. package/dist/lib/gate.js +2 -2
  7. package/dist/lib/pr_guard.js +1 -1
  8. package/dist/main.js +558 -551
  9. package/dist/mcp.js +406 -404
  10. package/dist/werkmeister-workspaces.vsix +0 -0
  11. package/infra/compose/k8s-port-forward/Dockerfile +1 -1
  12. package/infra/compose/k8s-port-forward/entrypoint.sh +2 -2
  13. package/infra/compose/redisinsight/databases.json +1 -1
  14. package/infra/compose/scripts/werkmeister-install-startup.sh +9 -9
  15. package/infra/compose/shared-infra.yml +17 -28
  16. package/infra/proxy/ui/index.html +4 -4
  17. package/infra/schemas/services-fragment.schema.json +5 -5
  18. package/infra/schemas/workspace.schema.json +9 -9
  19. package/infra/skills/{sb-author → w9r-author}/SKILL.md +6 -6
  20. package/infra/skills/{sb-handoff → w9r-handoff}/SKILL.md +8 -8
  21. package/infra/skills/{sb-implement → w9r-implement}/SKILL.md +12 -12
  22. package/infra/skills/{sb-pr → w9r-pr}/SKILL.md +12 -12
  23. package/infra/skills/{sb-research → w9r-research}/SKILL.md +10 -10
  24. package/infra/skills/{sb-review → w9r-review}/SKILL.md +12 -12
  25. package/infra/skills/{sb-test → w9r-test}/SKILL.md +9 -9
  26. package/infra/templates/Caddyfile.njk +5 -6
  27. package/infra/templates/docker-compose.feature.yml.njk +8 -9
  28. package/infra/templates/env.njk +7 -6
  29. package/infra/templates/supergraph-config.yml.njk +4 -4
  30. package/package.json +4 -6
  31. package/w9r +1 -1
  32. package/werkmeister +21 -29
  33. package/dist/sandbox-workspaces.vsix +0 -0
  34. package/sandbox +0 -4
package/CONVENTIONS.md CHANGED
@@ -14,7 +14,7 @@ by other tooling, so they are not free to drift.
14
14
  | `src/lib/<name>.ts` | shared library modules |
15
15
 
16
16
  Runtime data dirs live alongside the source: `infra/`, `bin/`.
17
- Path resolution: package root = `WERKMEISTER_ROOT` / `SANDBOX_ROOT` env, else the first
17
+ Path resolution: package root = `WERKMEISTER_ROOT` / `WERKMEISTER_ROOT` env, else the first
18
18
  ancestor holding `apps/cli` (`sandboxRoot()` / `infraRoot()` in
19
19
  `packages/werkmeister-core/src/config.ts`, re-exported by `src/lib/config.ts` as
20
20
  `getSandboxRoot()` / `getInfraRoot()`).
@@ -43,7 +43,7 @@ ancestor holding `apps/cli` (`sandboxRoot()` / `infraRoot()` in
43
43
  - ANSI colors come from `packages/werkmeister-core/src/colors.ts` — the single definition site.
44
44
  - `console.error` for stderr, `console.log` for stdout.
45
45
  - `process.exit(n)` for exit codes. Thrown errors reach `main`, which prints
46
- `Error: <msg>` in red and exits 1; `SANDBOX_DEBUG` re-raises with a stack.
46
+ `Error: <msg>` in red and exits 1; `WERKMEISTER_DEBUG` re-raises with a stack.
47
47
  - Interactive prompts use `node:readline/promises`, which makes the enclosing
48
48
  function `async` — command `run()` signatures are `async (args) => Promise<void>`.
49
49
  - No new npm dependencies beyond: commander, nunjucks, yaml.
package/README.md CHANGED
@@ -12,26 +12,26 @@ pnpm run build
12
12
  ./werkmeister --help
13
13
  ```
14
14
 
15
- `./werkmeister` (alias `./w9r`; `./sandbox` is deprecated) resolves a node runtime
16
- (WERKMEISTER_NODE → SANDBOX_NODE → PATH → newest nvm) and execs
17
- `dist/main.js`. `sandbox hooks gate` bypasses the CLI import chain via
15
+ `./werkmeister` (alias `./w9r`) resolves a node runtime
16
+ (WERKMEISTER_NODE → PATH → newest nvm) and execs
17
+ `dist/main.js`. `werkmeister hooks gate` bypasses the CLI import chain via
18
18
  `dist/lib/gate.js` for a fast PreToolUse cold start.
19
19
 
20
20
  ## Tab completion
21
21
 
22
- `sandbox __complete` answers bash's `complete -C` protocol (COMP_LINE/COMP_POINT
22
+ `werkmeister __complete` answers bash's `complete -C` protocol (COMP_LINE/COMP_POINT
23
23
  in, candidates on stdout), so both shells share one code path and there is no
24
24
  generated completion script to keep in sync — candidates come off the commander
25
25
  program itself.
26
26
 
27
- `sandbox setup` installs it into `~/.zshrc` as a managed block (idempotent;
27
+ `werkmeister setup` installs it into `~/.zshrc` as a managed block (idempotent;
28
28
  re-running replaces its own block and nothing else). To wire it up by hand, or
29
29
  in bash, which setup does not touch:
30
30
 
31
31
  ```sh
32
32
  autoload -Uz compinit && compinit # zsh only; skip if your rc runs it
33
33
  autoload -Uz +X bashcompinit && bashcompinit
34
- complete -C 'sandbox __complete' sandbox
34
+ complete -C 'werkmeister __complete' werkmeister
35
35
  ```
36
36
 
37
37
  Completes subcommand names, a command's long flags, and any positional as a
@@ -50,9 +50,9 @@ feature name (`infra` plus the workspaces under the workspaces root).
50
50
  - CLI parsing is commander; templates in `infra/templates/*.njk` render through
51
51
  nunjucks with a small compat layer (`{% do %}`, dict truthiness,
52
52
  `map(attribute=…)`) so they stay shared verbatim with other consumers
53
- - `sandbox mcp` runs the one MCP server over stdio. Its source is
53
+ - `werkmeister mcp` runs the one MCP server over stdio. Its source is
54
54
  `apps/werkmeister-mcp`, bundled into `dist/mcp.js` by `esbuild.mjs` so it ships in the npm
55
- package. `sandbox dashboard` runs the localhost workspaces dashboard from
55
+ package. `werkmeister dashboard` runs the localhost workspaces dashboard from
56
56
  `apps/werkmeister-dashboard`, which is checkout-only
57
57
  - interactive prompts and process-spawn edges are async (`run()` is
58
58
  `async` throughout); core logic stays synchronous
@@ -1,23 +1,23 @@
1
1
  #!/bin/bash
2
- # Generate the self-signed TLS certificate the sandbox ingress terminates.
2
+ # Generate the self-signed TLS certificate the werkmeister ingress terminates.
3
3
  #
4
- # The hostnames are NOT hardcoded here. They come from the sandbox ingress
4
+ # The hostnames are NOT hardcoded here. They come from the werkmeister ingress
5
5
  # config (`ingress.local_domain` / `ingress.remote_domain` in
6
6
  # ~/.werkmeister/config.yaml, crossed with the routed services in
7
- # ~/.werkmeister/services.yaml) and are passed in by `sandbox setup` via --domain.
7
+ # ~/.werkmeister/services.yaml) and are passed in by `werkmeister setup` via --domain.
8
8
  # That way the certificate SANs, the /etc/hosts entries and the Caddy site
9
9
  # blocks all derive from one list instead of three hand-synced copies.
10
10
  #
11
11
  # Standalone use (no CLI): pass --domain yourself, or set WERKMEISTER_INGRESS_HOSTS
12
- # to a comma/space-separated list. `sandbox setup` is the normal entry point.
13
- # WERKMEISTER_HOSTS_FILE overrides /etc/hosts (tests). Each WERKMEISTER_* falls back to SANDBOX_*.
12
+ # to a comma/space-separated list. `werkmeister setup` is the normal entry point.
13
+ # WERKMEISTER_HOSTS_FILE overrides /etc/hosts (tests).
14
14
  #
15
15
  # Usage:
16
16
  # generate-certs.sh [--domain HOST]... [--certs-dir DIR]
17
17
  # [--no-trust] [--no-hosts] [--force] [--check]
18
18
  #
19
19
  # --domain HOST Hostname to cover (repeatable). Also seeds /etc/hosts.
20
- # --certs-dir DIR Output directory [$SANDBOX_CERTS_DIR, else ~/.docker/certs]
20
+ # --certs-dir DIR Output directory [$WERKMEISTER_CERTS_DIR, else ~/.docker/certs]
21
21
  # --no-trust Skip adding the cert to the macOS System keychain (no sudo)
22
22
  # --no-hosts Skip the /etc/hosts update (no sudo)
23
23
  # --force Regenerate even if a certificate already exists
@@ -27,10 +27,10 @@
27
27
 
28
28
  set -euo pipefail
29
29
 
30
- CERTS_DIR="${WERKMEISTER_CERTS_DIR:-${SANDBOX_CERTS_DIR:-$HOME/.docker/certs}}"
31
- HOSTS_FILE="${WERKMEISTER_HOSTS_FILE:-${SANDBOX_HOSTS_FILE:-/etc/hosts}}"
32
- HOSTS_BEGIN="# BEGIN sandbox ingress"
33
- HOSTS_END="# END sandbox ingress"
30
+ CERTS_DIR="${WERKMEISTER_CERTS_DIR:-$HOME/.docker/certs}"
31
+ HOSTS_FILE="${WERKMEISTER_HOSTS_FILE:-/etc/hosts}"
32
+ HOSTS_BEGIN="# BEGIN sandbox ingress" # name-check: ignore
33
+ HOSTS_END="# END sandbox ingress" # name-check: ignore
34
34
  DO_TRUST=true
35
35
  DO_HOSTS=true
36
36
  FORCE=false
@@ -39,7 +39,7 @@ DOMAINS=()
39
39
 
40
40
  # Seed from the env fallback (comma or whitespace separated) before parsing
41
41
  # flags, so an explicit --domain adds to it rather than being overridden.
42
- INGRESS_HOSTS="${WERKMEISTER_INGRESS_HOSTS:-${SANDBOX_INGRESS_HOSTS:-}}"
42
+ INGRESS_HOSTS="${WERKMEISTER_INGRESS_HOSTS:-}"
43
43
  if [ -n "$INGRESS_HOSTS" ]; then
44
44
  IFS=', ' read -r -a DOMAINS <<< "$INGRESS_HOSTS"
45
45
  fi
@@ -207,7 +207,7 @@ if [ "$FORCE" != "skip_generate" ]; then
207
207
  echo " Certificate: $CRT"
208
208
  echo " Private Key: $KEY"
209
209
  echo ""
210
- echo "Note: Docker Compose mounts these into Caddy via \$SANDBOX_CERTS_DIR."
210
+ echo "Note: Docker Compose mounts these into Caddy via \$WERKMEISTER_CERTS_DIR."
211
211
 
212
212
  # Trust the certificate on macOS.
213
213
  if [ "$DO_TRUST" = true ] && [[ "$OSTYPE" == "darwin"* ]]; then
package/dist/NOTICE CHANGED
@@ -5,7 +5,7 @@ This product includes software developed by Jay Boyer.
5
5
  The werkmeister npm package bundles third-party packages into dist/*.js under
6
6
  the MIT, ISC, BSD-2-Clause and BSD-3-Clause licences. Their names, versions and
7
7
  licence texts are in dist/THIRD-PARTY-LICENSES.txt. The bundled VS Code
8
- extension (dist/sandbox-workspaces.vsix) carries its own LICENSE, NOTICE and
8
+ extension (dist/werkmeister-workspaces.vsix) carries its own LICENSE, NOTICE and
9
9
  THIRD-PARTY-LICENSES.txt. It also contains Apache-2.0, BSD-3-Clause, ISC, MIT
10
10
  and Unlicense code. None of these packages carries an Apache NOTICE file.
11
11
 
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __sandboxCreateRequire } from "node:module";
2
2
  const require = __sandboxCreateRequire(import.meta.url);
3
- var R=Object.defineProperty;var i=(e,t)=>R(e,"name",{value:t,configurable:!0});import*as o from"node:fs";import*as m from"node:path";import*as _ from"node:fs";import*as l from"node:path";var y=[".werkmeister",".sandbox"];function p(e){let t=y.find(n=>_.existsSync(l.join(e,n)));return l.join(e,t??y[0])}i(p,"dotDir");import*as d from"node:fs";import*as u from"node:path";function S(e){let t=u.resolve(e);for(;;){if(d.existsSync(u.join(p(t),"workspace.yml")))return t;let n=u.dirname(t);if(n===t)return null;t=n}}i(S,"findRecordRoot");var b=new Set(["working","needs-you","done","idle"]),O=new Set(["AskUserQuestion","ExitPlanMode"]),x="mcp__ccd_turn__wrap_up",A=new Set(["permission_prompt","elicitation_dialog"]),k=i(e=>m.join(p(e),"agent-state.json"),"stateFile");function N(e){try{let t=JSON.parse(o.readFileSync(k(e),"utf8"));if(!b.has(t?.state)||typeof t.at!="string")return null;let n={state:t.state,at:t.at};return typeof t.question=="string"&&(n.question=t.question),t.via==="wrap_up"&&(n.via="wrap_up"),n}catch{return null}}i(N,"readAgentState");function v(e){return/\?[\s*_`'")\]]*$/.test(e)}i(v,"asksQuestion");function D(e){let t=e.trim().split(/\n\s*\n/);return t[t.length-1].trim().slice(0,200)}i(D,"questionOf");function T(e){let t=o.openSync(e,"r"),n;try{let s=o.fstatSync(t).size,a=Math.min(s,65536),c=Buffer.alloc(a);o.readSync(t,c,0,a,s-a),n=c.toString("utf8")}finally{o.closeSync(t)}let r=n.split(`
4
- `);for(let s=r.length-1;s>=0;s--){let a;try{a=JSON.parse(r[s])}catch{continue}if(a.type!=="assistant")continue;let c=a.message?.content;if(typeof c=="string")return c;if(!Array.isArray(c))continue;let g=c.filter(f=>f?.type==="text"&&typeof f.text=="string");if(g.length)return g.map(f=>f.text).join(`
5
- `)}return null}i(T,"lastAssistantText");function $(e,t){switch(e.hook_event_name){case"UserPromptSubmit":return{state:"working"};case"PostToolUse":return e.tool_name===x&&t?.via==="wrap_up"?null:{state:"working"};case"PreToolUse":{let n=String(e.tool_name??""),r=e.tool_input?.ask;if(n===x&&typeof r=="string"&&r.trim())return{state:"needs-you",question:r.trim(),via:"wrap_up"};if(!O.has(n))return{state:"working"};let s=e.tool_input?.questions?.[0]?.question;return{state:"needs-you",question:typeof s=="string"?s:"Approve the plan?"}}case"Notification":{let n=e.notification_type,r=String(e.message??"");return!(typeof n=="string"?A.has(n):!/waiting for your input/i.test(r))||t?.state==="needs-you"&&t.question?null:{state:"needs-you",question:r||void 0}}case"Stop":{let n=null;return typeof e.last_assistant_message=="string"?n=e.last_assistant_message:typeof e.transcript_path=="string"&&(n=T(e.transcript_path)),n&&v(n)?{state:"needs-you",question:D(n)}:t?.via==="wrap_up"?null:{state:"done"}}case"SessionEnd":return t?.state==="working"?{state:"idle"}:null;default:return null}}i($,"nextState");var w="Workspace paused by the person from its card. End your turn now; it continues when they press Resume.";var E=i(e=>m.join(p(e),"paused.json"),"pausedPath"),q=i(e=>m.join(p(e),"resume-nudge.json"),"nudgePath");function U(e,t){let n=`${e}.${process.pid}.tmp`;o.writeFileSync(n,`${JSON.stringify(t)}
6
- `),o.renameSync(n,e)}i(U,"writeAtomic");function j(e,t){if(!o.existsSync(E(t)))return null;switch(e.hook_event_name){case"PreToolUse":return{continue:!1,stopReason:w,hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:w}};case"UserPromptSubmit":return{decision:"block",reason:"This workspace is paused. Press \u25B6 Resume on its card first."};default:return null}}i(j,"pauseGate");function F(e,t=new Date){let n=S(String(e.cwd||process.cwd()));if(!n)return null;let r=N(n),s=$(e,r);if(!s||r&&r.state===s.state&&r.question===s.question&&r.via===s.via)return null;let a={state:s.state,at:t.toISOString()};s.question&&(a.question=s.question),s.via&&(a.via=s.via);let c=k(n);return U(c,a),c}i(F,"record");function P(){try{let e=process.stdin.isTTY?"":o.readFileSync(0,"utf8"),t=e.trim()?JSON.parse(e):{};if(typeof t!="object"||t===null||Array.isArray(t))return;let n=S(String(t.cwd||process.cwd())),r=n?j(t,n):null;if(r){console.log(JSON.stringify(r));return}n&&t.hook_event_name==="UserPromptSubmit"&&o.rmSync(q(n),{force:!0}),F(t)}catch{}}i(P,"main");P();
3
+ var P=Object.defineProperty;var i=(t,e)=>P(t,"name",{value:e,configurable:!0});import*as r from"node:fs";import*as d from"node:path";import*as g from"node:path";var S=".werkmeister";function p(t){return g.join(t,S)}i(p,"dotDir");import*as l from"node:fs";import*as u from"node:path";function y(t){let e=u.resolve(t);for(;;){if(l.existsSync(u.join(p(e),"workspace.yml")))return e;let n=u.dirname(e);if(n===e)return null;e=n}}i(y,"findRecordRoot");var R=new Set(["working","needs-you","done","idle"]),O=new Set(["AskUserQuestion","ExitPlanMode"]),_="mcp__ccd_turn__wrap_up",A=new Set(["permission_prompt","elicitation_dialog"]),x=i(t=>d.join(p(t),"agent-state.json"),"stateFile");function N(t){try{let e=JSON.parse(r.readFileSync(x(t),"utf8"));if(!R.has(e?.state)||typeof e.at!="string")return null;let n={state:e.state,at:e.at};return typeof e.question=="string"&&(n.question=e.question),e.via==="wrap_up"&&(n.via="wrap_up"),n}catch{return null}}i(N,"readAgentState");function v(t){return/\?[\s*_`'")\]]*$/.test(t)}i(v,"asksQuestion");function T(t){let e=t.trim().split(/\n\s*\n/);return e[e.length-1].trim().slice(0,200)}i(T,"questionOf");function D(t){let e=r.openSync(t,"r"),n;try{let s=r.fstatSync(e).size,a=Math.min(s,65536),c=Buffer.alloc(a);r.readSync(e,c,0,a,s-a),n=c.toString("utf8")}finally{r.closeSync(e)}let o=n.split(`
4
+ `);for(let s=o.length-1;s>=0;s--){let a;try{a=JSON.parse(o[s])}catch{continue}if(a.type!=="assistant")continue;let c=a.message?.content;if(typeof c=="string")return c;if(!Array.isArray(c))continue;let h=c.filter(f=>f?.type==="text"&&typeof f.text=="string");if(h.length)return h.map(f=>f.text).join(`
5
+ `)}return null}i(D,"lastAssistantText");function E(t,e){switch(t.hook_event_name){case"UserPromptSubmit":return{state:"working"};case"PostToolUse":return t.tool_name===_&&e?.via==="wrap_up"?null:{state:"working"};case"PreToolUse":{let n=String(t.tool_name??""),o=t.tool_input?.ask;if(n===_&&typeof o=="string"&&o.trim())return{state:"needs-you",question:o.trim(),via:"wrap_up"};if(!O.has(n))return{state:"working"};let s=t.tool_input?.questions?.[0]?.question;return{state:"needs-you",question:typeof s=="string"?s:"Approve the plan?"}}case"Notification":{let n=t.notification_type,o=String(t.message??"");return!(typeof n=="string"?A.has(n):!/waiting for your input/i.test(o))||e?.state==="needs-you"&&e.question?null:{state:"needs-you",question:o||void 0}}case"Stop":{let n=null;return typeof t.last_assistant_message=="string"?n=t.last_assistant_message:typeof t.transcript_path=="string"&&(n=D(t.transcript_path)),n&&v(n)?{state:"needs-you",question:T(n)}:e?.via==="wrap_up"?null:{state:"done"}}case"SessionEnd":return e?.state==="working"?{state:"idle"}:null;default:return null}}i(E,"nextState");var w="Workspace paused by the person from its card. End your turn now; it continues when they press Resume.";var $=i(t=>d.join(p(t),"paused.json"),"pausedPath"),q=i(t=>d.join(p(t),"resume-nudge.json"),"nudgePath");function U(t,e){let n=`${t}.${process.pid}.tmp`;r.writeFileSync(n,`${JSON.stringify(e)}
6
+ `),r.renameSync(n,t)}i(U,"writeAtomic");function b(t,e){if(!r.existsSync($(e)))return null;switch(t.hook_event_name){case"PreToolUse":return{continue:!1,stopReason:w,hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:w}};case"UserPromptSubmit":return{decision:"block",reason:"This workspace is paused. Press \u25B6 Resume on its card first."};default:return null}}i(b,"pauseGate");function j(t,e=new Date){let n=y(String(t.cwd||process.cwd()));if(!n)return null;let o=N(n),s=E(t,o);if(!s||o&&o.state===s.state&&o.question===s.question&&o.via===s.via)return null;let a={state:s.state,at:e.toISOString()};s.question&&(a.question=s.question),s.via&&(a.via=s.via);let c=x(n);return U(c,a),c}i(j,"record");function k(){try{let t=process.stdin.isTTY?"":r.readFileSync(0,"utf8"),e=t.trim()?JSON.parse(t):{};if(typeof e!="object"||e===null||Array.isArray(e))return;let n=y(String(e.cwd||process.cwd())),o=n?b(e,n):null;if(o){console.log(JSON.stringify(o));return}n&&e.hook_event_name==="UserPromptSubmit"&&r.rmSync(q(n),{force:!0}),j(e)}catch{}}i(k,"main");k();
7
7
  //# sourceMappingURL=agent_state.js.map
package/dist/lib/gate.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __sandboxCreateRequire } from "node:module";
2
2
  const require = __sandboxCreateRequire(import.meta.url);
3
- var P=Object.defineProperty;var o=(t,e)=>P(t,"name",{value:e,configurable:!0});import*as c from"node:fs";import*as a from"node:path";import*as $ from"node:fs";import*as w from"node:path";var _=[".werkmeister",".sandbox"];function S(t){let e=_.find(n=>$.existsSync(w.join(t,n)));return w.join(t,e??_[0])}o(S,"dotDir");var O="Precedence: these standards' rules win over conflicting task framing \u2014 if a rule and the task clash, follow the rule and say so (invariant: apply it and write a `decision` note; rule: surface the conflict in one line, then apply). This gate fires once; your retry will proceed.",A="Standards gate: invoke `sb-implement` before coding \u2014 it loads the universal base (ponytail + comments + engineering) and the workspace notes. Then retry this edit.";function R(t){let e="",n=0,s=t.length;for(;n<s;){let u=t[n];if(n+=1,u==="*")e+=".*";else if(u==="?")e+=".";else if(u==="["){let r=n;for(r<s&&t[r]==="!"&&(r+=1),r<s&&t[r]==="]"&&(r+=1);r<s&&t[r]!=="]";)r+=1;if(r>=s)e+="\\[";else{let i=t.slice(n,r).replace(/\\/g,"\\\\");n=r+1,i.startsWith("!")?i="^"+i.slice(1):i.startsWith("^")&&(i="\\"+i),e+=`[${i}]`}}else e+=u.replace(/[.+^${}()|[\]\\]/g,"\\$&")}return`^(?:${e})$`}o(R,"_translate");function F(t,e){return new RegExp(R(e),"s").test(t)}o(F,"fnmatch");function J(t){let e=a.resolve(t);for(;;){if(W(S(e)))return e;let n=a.dirname(e);if(n===e)return null;e=n}}o(J,"findWorkspaceRoot");function W(t){try{return c.statSync(t).isDirectory()}catch{return!1}}o(W,"_isDir");function T(t){try{return c.statSync(t).isFile()}catch{return!1}}o(T,"_isFile");function h(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}o(h,"_isDict");function C(t){let e=a.join(S(t),"standards.json");if(!T(e))return null;let n;try{n=JSON.parse(c.readFileSync(e,"utf8"))}catch{return null}return h(n)?n:null}o(C,"loadManifest");function E(t,e){return a.join(S(t),".gate",`${e}.json`)}o(E,"_statePath");function G(t,e){let n=E(t,e);if(!T(n))return{};let s;try{s=JSON.parse(c.readFileSync(n,"utf8"))}catch{return null}return h(s)?s:null}o(G,"_loadState");function L(t,e,n){try{let s=E(t,e);return c.mkdirSync(a.dirname(s),{recursive:!0}),c.writeFileSync(s,JSON.stringify(n)),!0}catch{return!1}}o(L,"_saveState");function k(t){return[...t].sort()}o(k,"_sorted");function X(t){let e=/^---\r?\n([\s\S]*?)\r?\n---/.exec(t);if(!e)return;let n=/^status:\s*["']?([^\s"'#]+)/m.exec(e[1]);return n?n[1].toLowerCase():null}o(X,"_noteStatus");function Y(t,e){let n=String(e.note??"");if(!/^[a-z]+$/.test(n))return!0;let s=e.status?String(e.status).toLowerCase():null,u=a.join(S(t),"notes"),r;try{r=c.readdirSync(u)}catch(l){return l.code!=="ENOENT"}let i=new RegExp(`^\\d{3}-${n}-.+\\.md$`);for(let l of r){if(!i.test(l))continue;let m;try{m=c.readFileSync(a.join(u,l),"utf8")}catch{return!0}let p=X(m);if(p===void 0)return!0;if(!(p==="superseded"||p==="graduated")&&(s===null||p===s))return!0}return!1}o(Y,"_phaseGateSatisfied");function z(t){let e=String(t.note);if(t.status){let n=String(t.status);return`Phase gate: no \`${e}\` note in \`.sandbox/notes/\` has \`status: ${n}\`, so source edits wait for an approved design. Invoke \`sb-research\`, present the design to the user, and when they approve write \`NNN-${e}-<slug>.md\` with \`status: ${n}\` recording what was approved. Then retry this edit. Edits under \`.sandbox/\` are not gated.`}return`Phase gate: no \`${e}\` note in \`.sandbox/notes/\` names the root cause yet. Invoke \`sb-research\`, reproduce the problem, and write \`NNN-${e}-<slug>.md\` stating the root cause. Then retry this edit. Edits under \`.sandbox/\` are not gated.`}o(z,"_phaseGateText");function H(t,e,n){if(!e||e.includes("/")||e.includes(".."))return null;let s=J(t);if(s===null)return null;let u=C(s);if(u===null)return null;let r=G(s,e);if(r===null)return null;let i=n?a.relative(s,n):"",l=u.phase_gate;if(h(l)&&i&&i!==".."&&!i.startsWith(".."+a.sep)&&!a.isAbsolute(i)&&!_.some(f=>i.startsWith(f+a.sep))&&!Y(s,l))return z(l);let m=new Set(Array.isArray(r.delivered)?r.delivered:[]),p=!r.phase_entry_delivered,d=null,b=h(u.domains)?u.domains:{};for(let f of k(Object.keys(b))){let y=b[f];if(m.has(f)||!h(y))continue;if((Array.isArray(y.applies_to)?y.applies_to:[]).some(j=>F(i,String(j)))){d=f;break}}if(!p&&d===null)return null;let g=[];if(p&&g.push(A),d!==null){let f=b[d],y=String(h(f)&&f.summary||"").trim(),x=`Standards gate: you are editing a path governed by the \`${d}\` standard, which has not been loaded this session. Invoke the \`sb-${d}-standard\` skill, then retry this edit.`;y&&(x+=` Summary: ${y}.`),g.push(x)}g.push(O);let D={phase_entry_delivered:!0,delivered:k(d?new Set([...m,d]):m)};return L(s,e,D)?g.join(`
4
- `):null}o(H,"decide");function N(){let t;try{let i=process.stdin.isTTY?"":c.readFileSync(0,"utf8"),l=i.trim()?JSON.parse(i):{};t=h(l)?l:{}}catch{t={}}let e=String(t.session_id||""),n=t.tool_input,s=String(h(n)&&n.file_path||""),u=String(t.cwd||process.cwd()),r;try{r=H(u,e,s)}catch{r=null}r&&console.log(JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:r}}))}o(N,"main");N();
3
+ var P=Object.defineProperty;var a=(t,e)=>P(t,"name",{value:e,configurable:!0});import*as c from"node:fs";import*as o from"node:path";import*as $ from"node:path";var k=".werkmeister";function S(t){return $.join(t,k)}a(S,"dotDir");var j="Precedence: these standards' rules win over conflicting task framing \u2014 if a rule and the task clash, follow the rule and say so (invariant: apply it and write a `decision` note; rule: surface the conflict in one line, then apply). This gate fires once; your retry will proceed.",O="Standards gate: invoke `w9r-implement` before coding \u2014 it loads the universal base (ponytail + comments + engineering) and the workspace notes. Then retry this edit.";function A(t){let e="",n=0,s=t.length;for(;n<s;){let u=t[n];if(n+=1,u==="*")e+=".*";else if(u==="?")e+=".";else if(u==="["){let r=n;for(r<s&&t[r]==="!"&&(r+=1),r<s&&t[r]==="]"&&(r+=1);r<s&&t[r]!=="]";)r+=1;if(r>=s)e+="\\[";else{let i=t.slice(n,r).replace(/\\/g,"\\\\");n=r+1,i.startsWith("!")?i="^"+i.slice(1):i.startsWith("^")&&(i="\\"+i),e+=`[${i}]`}}else e+=u.replace(/[.+^${}()|[\]\\]/g,"\\$&")}return`^(?:${e})$`}a(A,"_translate");function R(t,e){return new RegExp(A(e),"s").test(t)}a(R,"fnmatch");function F(t){let e=o.resolve(t);for(;;){if(J(S(e)))return e;let n=o.dirname(e);if(n===e)return null;e=n}}a(F,"findWorkspaceRoot");function J(t){try{return c.statSync(t).isDirectory()}catch{return!1}}a(J,"_isDir");function E(t){try{return c.statSync(t).isFile()}catch{return!1}}a(E,"_isFile");function d(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}a(d,"_isDict");function W(t){let e=o.join(S(t),"standards.json");if(!E(e))return null;let n;try{n=JSON.parse(c.readFileSync(e,"utf8"))}catch{return null}return d(n)?n:null}a(W,"loadManifest");function N(t,e){return o.join(S(t),".gate",`${e}.json`)}a(N,"_statePath");function C(t,e){let n=N(t,e);if(!E(n))return{};let s;try{s=JSON.parse(c.readFileSync(n,"utf8"))}catch{return null}return d(s)?s:null}a(C,"_loadState");function G(t,e,n){try{let s=N(t,e);return c.mkdirSync(o.dirname(s),{recursive:!0}),c.writeFileSync(s,JSON.stringify(n)),!0}catch{return!1}}a(G,"_saveState");function T(t){return[...t].sort()}a(T,"_sorted");function L(t){let e=/^---\r?\n([\s\S]*?)\r?\n---/.exec(t);if(!e)return;let n=/^status:\s*["']?([^\s"'#]+)/m.exec(e[1]);return n?n[1].toLowerCase():null}a(L,"_noteStatus");function X(t,e){let n=String(e.note??"");if(!/^[a-z]+$/.test(n))return!0;let s=e.status?String(e.status).toLowerCase():null,u=o.join(S(t),"notes"),r;try{r=c.readdirSync(u)}catch(l){return l.code!=="ENOENT"}let i=new RegExp(`^\\d{3}-${n}-.+\\.md$`);for(let l of r){if(!i.test(l))continue;let p;try{p=c.readFileSync(o.join(u,l),"utf8")}catch{return!0}let h=L(p);if(h===void 0)return!0;if(!(h==="superseded"||h==="graduated")&&(s===null||h===s))return!0}return!1}a(X,"_phaseGateSatisfied");function Y(t){let e=String(t.note);if(t.status){let n=String(t.status);return`Phase gate: no \`${e}\` note in \`.werkmeister/notes/\` has \`status: ${n}\`, so source edits wait for an approved design. Invoke \`w9r-research\`, present the design to the user, and when they approve write \`NNN-${e}-<slug>.md\` with \`status: ${n}\` recording what was approved. Then retry this edit. Edits under \`.werkmeister/\` are not gated.`}return`Phase gate: no \`${e}\` note in \`.werkmeister/notes/\` names the root cause yet. Invoke \`w9r-research\`, reproduce the problem, and write \`NNN-${e}-<slug>.md\` stating the root cause. Then retry this edit. Edits under \`.werkmeister/\` are not gated.`}a(Y,"_phaseGateText");function z(t,e,n){if(!e||e.includes("/")||e.includes(".."))return null;let s=F(t);if(s===null)return null;let u=W(s);if(u===null)return null;let r=C(s,e);if(r===null)return null;let i=n?o.relative(s,n):"",l=u.phase_gate;if(d(l)&&i&&i!==".."&&!i.startsWith(".."+o.sep)&&!o.isAbsolute(i)&&!i.startsWith(k+o.sep)&&!X(s,l))return Y(l);let p=new Set(Array.isArray(r.delivered)?r.delivered:[]),h=!r.phase_entry_delivered,f=null,w=d(u.domains)?u.domains:{};for(let m of T(Object.keys(w))){let y=w[m];if(p.has(m)||!d(y))continue;if((Array.isArray(y.applies_to)?y.applies_to:[]).some(D=>R(i,String(D)))){f=m;break}}if(!h&&f===null)return null;let g=[];if(h&&g.push(O),f!==null){let m=w[f],y=String(d(m)&&m.summary||"").trim(),_=`Standards gate: you are editing a path governed by the \`${f}\` standard, which has not been loaded this session. Invoke the \`w9r-${f}-standard\` skill, then retry this edit.`;y&&(_+=` Summary: ${y}.`),g.push(_)}g.push(j);let b={phase_entry_delivered:!0,delivered:T(f?new Set([...p,f]):p)};return G(s,e,b)?g.join(`
4
+ `):null}a(z,"decide");function x(){let t;try{let i=process.stdin.isTTY?"":c.readFileSync(0,"utf8"),l=i.trim()?JSON.parse(i):{};t=d(l)?l:{}}catch{t={}}let e=String(t.session_id||""),n=t.tool_input,s=String(d(n)&&n.file_path||""),u=String(t.cwd||process.cwd()),r;try{r=z(u,e,s)}catch{r=null}r&&console.log(JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:r}}))}a(x,"main");x();
5
5
  //# sourceMappingURL=gate.js.map
@@ -1,4 +1,4 @@
1
1
  import { createRequire as __sandboxCreateRequire } from "node:module";
2
2
  const require = __sandboxCreateRequire(import.meta.url);
3
- var m=Object.defineProperty;var r=(e,t)=>m(e,"name",{value:t,configurable:!0});import*as i from"node:fs";import*as o from"node:path";import*as u from"node:fs";import*as a from"node:path";var p=[".werkmeister",".sandbox"];function c(e){let t=p.find(n=>u.existsSync(a.join(e,n)));return a.join(e,t??p[0])}r(c,"dotDir");function h(e){let t=o.resolve(e);for(;;){if(i.existsSync(o.join(c(t),"workspace.yml")))return t;let n=o.dirname(t);if(n===t)return null;t=n}}r(h,"findRecordRoot");function x(e){try{let t=i.readdirSync(o.join(e,"stages")).filter(s=>/^\d+_/.test(s)).sort(),n=t.find(s=>/^\d+_propose$/.test(s))??t.find(s=>/^\d+_ship$/.test(s))??t.at(-1);return n?`stages/${n}/output/`:"the last stage's output/"}catch{return`${o.basename(c(e))}/notes/`}}r(x,"prFileDirName");var S=/(?<!<)<<(?!<)-?\s*(['"]?)(\w+)\1([^\n]*)(?:\n(?:[\s\S]*?\n)?\t*\2(?=\n|$)|[\s\S]*$)/g,R=/'[^']*(?:'|$)|"(?:[^"\\]|\\[\s\S])*(?:"|$)/g,$=/(?:^|[;&|({\n`])\s*(?:(?:\w+=\S*|command|exec|env|then|do|else)\s+)*gh\s+pr\s+create\b/,y=/create_pull_request$/;function _(e){return $.test(e.replace(S,"$3").replace(R,"_"))}r(_,"opensPr");function g(e){return["_shared/pr-rules.md",...p.map(t=>`${t}/pr-rules.md`)].find(t=>i.existsSync(o.join(e,t)))??"docs/workspace-lifecycle.md in the sandbox repo"}r(g,"prRulesPath");function D(e){let t=h(String(e.cwd||process.cwd()));if(!t)return null;let n=String(e.tool_name||""),s=String(e.tool_input?.command||"");if(!(n==="Bash"&&_(s)||y.test(n)))return null;let l=g(t);return`Inside sandbox workspace \`${o.basename(t)}\`, PRs open only through \`sandbox pr open\`: it runs the pre-PR gate and records the URL. Write the PR file in \`${x(t)}\`, have the person set \`status: approved\`, then run \`sandbox pr open\`. Rules: \`${l}\`.`}r(D,"decide");function f(){let e=null;try{let t=process.stdin.isTTY?"":i.readFileSync(0,"utf8"),n=t.trim()?JSON.parse(t):{};typeof n=="object"&&n!==null&&!Array.isArray(n)&&(e=D(n))}catch{e=null}e&&console.log(JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:e}}))}r(f,"main");f();
3
+ var m=Object.defineProperty;var s=(e,t)=>m(e,"name",{value:t,configurable:!0});import*as i from"node:fs";import*as n from"node:path";import*as l from"node:path";var a=".werkmeister";function p(e){return l.join(e,a)}s(p,"dotDir");function f(e){let t=n.resolve(e);for(;;){if(i.existsSync(n.join(p(t),"workspace.yml")))return t;let r=n.dirname(t);if(r===t)return null;t=r}}s(f,"findRecordRoot");function h(e){try{let t=i.readdirSync(n.join(e,"stages")).filter(o=>/^\d+_/.test(o)).sort(),r=t.find(o=>/^\d+_propose$/.test(o))??t.find(o=>/^\d+_ship$/.test(o))??t.at(-1);return r?`stages/${r}/output/`:"the last stage's output/"}catch{return`${n.basename(p(e))}/notes/`}}s(h,"prFileDirName");var R=/(?<!<)<<(?!<)-?\s*(['"]?)(\w+)\1([^\n]*)(?:\n(?:[\s\S]*?\n)?\t*\2(?=\n|$)|[\s\S]*$)/g,_=/'[^']*(?:'|$)|"(?:[^"\\]|\\[\s\S])*(?:"|$)/g,y=/(?:^|[;&|({\n`])\s*(?:(?:\w+=\S*|command|exec|env|then|do|else)\s+)*gh\s+pr\s+create\b/,S=/create_pull_request$/;function $(e){return y.test(e.replace(R,"$3").replace(_,"_"))}s($,"opensPr");function g(e){return["_shared/pr-rules.md",`${a}/pr-rules.md`].find(t=>i.existsSync(n.join(e,t)))??"docs/workspace-lifecycle.md in the werkmeister repo"}s(g,"prRulesPath");function w(e){let t=f(String(e.cwd||process.cwd()));if(!t)return null;let r=String(e.tool_name||""),o=String(e.tool_input?.command||"");if(!(r==="Bash"&&$(o)||S.test(r)))return null;let d=g(t);return`Inside workspace \`${n.basename(t)}\`, PRs open only through \`werkmeister pr open\`: it runs the pre-PR gate and records the URL. Write the PR file in \`${h(t)}\`, have the person set \`status: approved\`, then run \`werkmeister pr open\`. Rules: \`${d}\`.`}s(w,"decide");function u(){let e=null;try{let t=process.stdin.isTTY?"":i.readFileSync(0,"utf8"),r=t.trim()?JSON.parse(t):{};typeof r=="object"&&r!==null&&!Array.isArray(r)&&(e=w(r))}catch{e=null}e&&console.log(JSON.stringify({hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:e}}))}s(u,"main");u();
4
4
  //# sourceMappingURL=pr_guard.js.map