werkmeister 0.29.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CONVENTIONS.md CHANGED
@@ -16,7 +16,7 @@ by other tooling, so they are not free to drift.
16
16
  Runtime data dirs live alongside the source: `infra/`, `bin/`.
17
17
  Path resolution: package root = `WERKMEISTER_ROOT` / `SANDBOX_ROOT` env, else the first
18
18
  ancestor holding `apps/cli` (`sandboxRoot()` / `infraRoot()` in
19
- `packages/sandbox-core/src/config.ts`, re-exported by `src/lib/config.ts` as
19
+ `packages/werkmeister-core/src/config.ts`, re-exported by `src/lib/config.ts` as
20
20
  `getSandboxRoot()` / `getInfraRoot()`).
21
21
 
22
22
  ## Language
@@ -34,13 +34,13 @@ ancestor holding `apps/cli` (`sandboxRoot()` / `infraRoot()` in
34
34
  verbatim with other consumers, so the environment options in `generate.ts`
35
35
  (autoescape, trim/lstrip) are load-bearing — see the notes there before
36
36
  touching them.
37
- - Subprocesses go through `packages/sandbox-core/src/proc.ts` (spawnSync-based, synchronous):
37
+ - Subprocesses go through `packages/werkmeister-core/src/proc.ts` (spawnSync-based, synchronous):
38
38
  - `run(cmd: string[], opts)` → `{ status, stdout, stderr }`; `check: true` throws `ProcError`.
39
39
  - `capture(cmd)` → trimmed stdout, throws on failure.
40
40
  - Streaming/inherit-stdio cases: pass `stdio: "inherit"`.
41
41
  - `timeout` is in **seconds**, not milliseconds.
42
42
  - Filesystem work uses the sync `node:fs` API (`readFileSync` etc.) plus `node:path`.
43
- - ANSI colors come from `packages/sandbox-core/src/colors.ts` — the single definition site.
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
46
  `Error: <msg>` in red and exits 1; `SANDBOX_DEBUG` re-raises with a stack.
package/README.md CHANGED
@@ -51,8 +51,8 @@ feature name (`infra` plus the workspaces under the workspaces root).
51
51
  nunjucks with a small compat layer (`{% do %}`, dict truthiness,
52
52
  `map(attribute=…)`) so they stay shared verbatim with other consumers
53
53
  - `sandbox mcp` runs the one MCP server over stdio. Its source is
54
- `apps/mcp`, bundled into `dist/mcp.js` by `esbuild.mjs` so it ships in the npm
54
+ `apps/werkmeister-mcp`, bundled into `dist/mcp.js` by `esbuild.mjs` so it ships in the npm
55
55
  package. `sandbox dashboard` runs the localhost workspaces dashboard from
56
- `apps/sandbox-dashboard`, which is checkout-only
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,7 +1,7 @@
1
1
  import { createRequire as __sandboxCreateRequire } from "node:module";
2
2
  const require = __sandboxCreateRequire(import.meta.url);
3
- var b=Object.defineProperty;var i=(e,t)=>b(e,"name",{value:t,configurable:!0});import*as r from"node:fs";import*as x from"node:path";import*as g from"node:fs";import*as l from"node:path";var y=[".werkmeister",".sandbox"];function d(e){let t=y.find(n=>g.existsSync(l.join(e,n)));return l.join(e,t??y[0])}i(d,"dotDir");import*as m from"node:fs";import*as p from"node:path";function S(e){let t=p.resolve(e);for(;;){if(m.existsSync(p.join(d(t),"workspace.yml")))return t;let n=p.dirname(t);if(n===t)return null;t=n}}i(S,"findRecordRoot");var q=new Set(["working","needs-you","done","idle"]),R=new Set(["AskUserQuestion","ExitPlanMode"]),_="mcp__ccd_turn__wrap_up",v=new Set(["permission_prompt","elicitation_dialog"]),w=i(e=>x.join(d(e),"agent-state.json"),"stateFile");function A(e){try{let t=JSON.parse(r.readFileSync(w(e),"utf8"));if(!q.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(A,"readAgentState");function T(e){return/\?[\s*_`'")\]]*$/.test(e)}i(T,"asksQuestion");function P(e){let t=e.trim().split(/\n\s*\n/);return t[t.length-1].trim().slice(0,200)}i(P,"questionOf");function $(e){let t=r.openSync(e,"r"),n;try{let s=r.fstatSync(t).size,a=Math.min(s,65536),c=Buffer.alloc(a);r.readSync(t,c,0,a,s-a),n=c.toString("utf8")}finally{r.closeSync(t)}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 u=c.filter(f=>f?.type==="text"&&typeof f.text=="string");if(u.length)return u.map(f=>f.text).join(`
5
- `)}return null}i($,"lastAssistantText");function O(e,t){switch(e.hook_event_name){case"UserPromptSubmit":return{state:"working"};case"PostToolUse":return e.tool_name===_&&t?.via==="wrap_up"?null:{state:"working"};case"PreToolUse":{let n=String(e.tool_name??""),o=e.tool_input?.ask;if(n===_&&typeof o=="string"&&o.trim())return{state:"needs-you",question:o.trim(),via:"wrap_up"};if(!R.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,o=String(e.message??"");return!(typeof n=="string"?v.has(n):!/waiting for your input/i.test(o))||t?.state==="needs-you"&&t.question?null:{state:"needs-you",question:o||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=$(e.transcript_path)),n&&T(n)?{state:"needs-you",question:P(n)}:t?.via==="wrap_up"?null:{state:"done"}}case"SessionEnd":return t?.state==="working"?{state:"idle"}:null;default:return null}}i(O,"nextState");function D(e,t=new Date){let n=S(String(e.cwd||process.cwd()));if(!n)return null;let o=A(n),s=O(e,o);if(!s||o&&o.state===s.state&&o.question===s.question&&o.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=w(n),u=`${c}.${process.pid}.tmp`;return r.writeFileSync(u,`${JSON.stringify(a)}
6
- `),r.renameSync(u,c),c}i(D,"record");function k(){try{let e=process.stdin.isTTY?"":r.readFileSync(0,"utf8"),t=e.trim()?JSON.parse(e):{};typeof t=="object"&&t!==null&&!Array.isArray(t)&&D(t)}catch{}}i(k,"main");k();
3
+ var b=Object.defineProperty;var i=(e,t)=>b(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 g(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(g,"findRecordRoot");var R=new Set(["working","needs-you","done","idle"]),A=new Set(["AskUserQuestion","ExitPlanMode"]),w="mcp__ccd_turn__wrap_up",N=new Set(["permission_prompt","elicitation_dialog"]),k=i(e=>m.join(p(e),"agent-state.json"),"stateFile");function O(e){try{let t=JSON.parse(o.readFileSync(k(e),"utf8"));if(!R.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(O,"readAgentState");function v(e){return/\?[\s*_`'")\]]*$/.test(e)}i(v,"asksQuestion");function T(e){let t=e.trim().split(/\n\s*\n/);return t[t.length-1].trim().slice(0,200)}i(T,"questionOf");function D(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 S=c.filter(f=>f?.type==="text"&&typeof f.text=="string");if(S.length)return S.map(f=>f.text).join(`
5
+ `)}return null}i(D,"lastAssistantText");function q(e,t){switch(e.hook_event_name){case"UserPromptSubmit":return{state:"working"};case"PostToolUse":return e.tool_name===w&&t?.via==="wrap_up"?null:{state:"working"};case"PreToolUse":{let n=String(e.tool_name??""),r=e.tool_input?.ask;if(n===w&&typeof r=="string"&&r.trim())return{state:"needs-you",question:r.trim(),via:"wrap_up"};if(!A.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"?N.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=D(e.transcript_path)),n&&v(n)?{state:"needs-you",question:T(n)}:t?.via==="wrap_up"?null:{state:"done"}}case"SessionEnd":return t?.state==="working"?{state:"idle"}:null;default:return null}}i(q,"nextState");var x="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"),$=i(e=>m.join(p(e),"resume-nudge.json"),"nudgePath");function j(e,t){let n=`${e}.${process.pid}.tmp`;o.writeFileSync(n,`${JSON.stringify(t)}
6
+ `),o.renameSync(n,e)}i(j,"writeAtomic");function U(e,t){if(!o.existsSync(E(t)))return null;switch(e.hook_event_name){case"PreToolUse":return{continue:!1,stopReason:x,hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:x}};case"UserPromptSubmit":return{decision:"block",reason:"This workspace is paused. Press \u25B6 Resume on its card first."};default:return null}}i(U,"pauseGate");function F(e,t=new Date){let n=g(String(e.cwd||process.cwd()));if(!n)return null;let r=O(n),s=q(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 j(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=g(String(t.cwd||process.cwd())),r=n?U(t,n):null;if(r){console.log(JSON.stringify(r));return}n&&t.hook_event_name==="UserPromptSubmit"&&o.rmSync($(n),{force:!0}),F(t)}catch{}}i(P,"main");P();
7
7
  //# sourceMappingURL=agent_state.js.map