werkmeister 0.78.0 → 0.79.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/dist/lib/agent_state.js +4 -4
- package/dist/main.js +589 -566
- package/dist/mcp.js +442 -437
- package/dist/werkmeister-workspaces.vsix +0 -0
- package/infra/schemas/services-fragment.schema.json +5 -0
- package/infra/skills/w9r-pr/SKILL.md +6 -4
- package/man/werkmeister-machine-tokens.1 +30 -0
- package/man/werkmeister.1 +4 -0
- package/package.json +4 -3
package/dist/lib/agent_state.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __sandboxCreateRequire } from "node:module";
|
|
2
2
|
const require = __sandboxCreateRequire(import.meta.url);
|
|
3
|
-
var
|
|
4
|
-
`);for(let
|
|
5
|
-
`)}return null}i(
|
|
6
|
-
`),a.renameSync(n,t)}i(L,"writeAtomic");function Q(t){try{let e=JSON.parse(a.readFileSync(H(t),"utf8"));return Number.isInteger(e?.position)?{position:e.position,reason:String(e.reason??"")}:null}catch{return null}}i(Q,"readWaiting");var T=i((t,e)=>d.join(
|
|
3
|
+
var v=Object.defineProperty;var i=(t,e)=>v(t,"name",{value:e,configurable:!0});import*as a from"node:fs";import*as d from"node:path";import*as N from"node:path";var E=".werkmeister";function l(t){return N.join(t,E)}i(l,"dotDir");var _="mcp__ccd_turn__wrap_up";import*as g from"node:fs";import*as p from"node:path";function w(t){let e=p.resolve(t);for(;;){if(g.existsSync(p.join(l(e),"workspace.yml")))return e;let n=p.dirname(e);if(n===e)return null;e=n}}i(w,"findRecordRoot");var D=new Set(["working","needs-you","done","idle"]),b=new Set(["AskUserQuestion","ExitPlanMode"]),U=new Set(["permission_prompt","elicitation_dialog"]),R=i(t=>d.join(l(t),"agent-state.json"),"stateFile");function j(t){try{let e=JSON.parse(a.readFileSync(R(t),"utf8"));return e&&typeof e=="object"&&!Array.isArray(e)?e:null}catch{return null}}i(j,"readRaw");function q(t){if(!D.has(t?.state)||typeof t?.at!="string")return null;let e={state:t.state,at:t.at};return typeof t.question=="string"&&(e.question=t.question),t.via==="wrap_up"&&(e.via="wrap_up"),e}i(q,"stateOf");function I(t){let e={};for(let[n,s]of Object.entries(t?.sessions??{}))(s?.status==="busy"||s?.status==="idle")&&typeof s.at=="string"&&(e[n]={status:s.status,at:s.at,...s.headless===!0&&{headless:!0}});return e}i(I,"sessionsOf");var W=new Set(["UserPromptSubmit","PreToolUse","PostToolUse"]);function C(t){return t==="SessionEnd"?null:t==="SessionStart"||t==="Stop"?"idle":W.has(t)?"busy":void 0}i(C,"nextSessionStatus");function F(t){return/\?[\s*_`'")\]]*$/.test(t)}i(F,"asksQuestion");function J(t){let e=t.trim().split(/\n\s*\n/);return e[e.length-1].trim().slice(0,200)}i(J,"questionOf");function M(t){let e=a.openSync(t,"r"),n;try{let r=a.fstatSync(e).size,o=Math.min(r,65536),f=Buffer.alloc(o);a.readSync(e,f,0,o,r-o),n=f.toString("utf8")}finally{a.closeSync(e)}let s=n.split(`
|
|
4
|
+
`);for(let r=s.length-1;r>=0;r--){let o;try{o=JSON.parse(s[r])}catch{continue}if(o.type!=="assistant")continue;let f=o.message?.content;if(typeof f=="string")return f;if(!Array.isArray(f))continue;let u=f.filter(c=>c?.type==="text"&&typeof c.text=="string");if(u.length)return u.map(c=>c.text).join(`
|
|
5
|
+
`)}return null}i(M,"lastAssistantText");function K(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??""),s=t.tool_input?.ask;if(n===_&&typeof s=="string"&&s.trim())return{state:"needs-you",question:s.trim(),via:"wrap_up"};if(!b.has(n))return{state:"working"};let r=t.tool_input?.questions?.[0]?.question;return{state:"needs-you",question:typeof r=="string"?r:"Approve the plan?"}}case"Notification":{let n=t.notification_type,s=String(t.message??"");return!(typeof n=="string"?U.has(n):!/waiting for your input/i.test(s))||e?.state==="needs-you"&&e.question?null:{state:"needs-you",question:s||void 0}}case"PermissionRequest":{let n=t.tool_input?.description;return{state:"needs-you",question:typeof n=="string"&&n.trim()?n.trim():`Approve ${String(t.tool_name??"the tool call")}?`}}case"Stop":{let n=null;return typeof t.last_assistant_message=="string"?n=t.last_assistant_message:typeof t.transcript_path=="string"&&(n=M(t.transcript_path)),n&&F(n)?{state:"needs-you",question:J(n)}:e?.via==="wrap_up"?null:{state:"done"}}case"SessionEnd":return e?.state==="working"?{state:"idle"}:null;default:return null}}i(K,"nextState");var Y="Workspace paused by the person from its card. End your turn now; it continues when they press Resume.";var B=i(t=>d.join(l(t),"paused.json"),"pausedPath"),G=i(t=>d.join(l(t),"resume-nudge.json"),"nudgePath"),H=i(t=>d.join(l(t),"waiting.json"),"waitingPath");function L(t,e){let n=`${t}.${process.pid}.tmp`;a.writeFileSync(n,`${JSON.stringify(e)}
|
|
6
|
+
`),a.renameSync(n,t)}i(L,"writeAtomic");function Q(t){try{let e=JSON.parse(a.readFileSync(H(t),"utf8"));return Number.isInteger(e?.position)?{position:e.position,reason:String(e.reason??"")}:null}catch{return null}}i(Q,"readWaiting");var T=i((t,e)=>d.join(l(t),`wake-nudge-${e}.json`),"wakeNudgePath"),z=/^[\w-]+$/;function V(t){try{let e=JSON.parse(a.readFileSync(t,"utf8"))?.message;return typeof e=="string"?e:null}catch{return null}}i(V,"readWakeNudge");var A=i((t,e)=>typeof e=="string"&&z.test(e)&&a.existsSync(T(t,e)),"pendingWake");function X(t,e){let n=t.hook_event_name;if(n!=="UserPromptSubmit"&&n!=="PostToolUse"&&n!=="Stop"||t.agent_id||!A(e,t.session_id))return null;let s=T(e,t.session_id),r=`${s}.${process.pid}-${Date.now()}.claimed`;try{a.renameSync(s,r)}catch{return null}let o=V(r);return a.rmSync(r,{force:!0}),o===null?null:n==="Stop"?{decision:"block",reason:o}:{hookSpecificOutput:{hookEventName:n,additionalContext:o}}}i(X,"deliverWake");function Z(t,e){let n=a.existsSync(B(e)),s=n?null:Q(e);if(!n&&!s)return null;let r=s?`Waiting for capacity (position ${s.position}). End your turn now; it starts when another feature stops.`:Y;switch(t.hook_event_name){case"PreToolUse":{let o={hookSpecificOutput:{hookEventName:"PreToolUse",permissionDecision:"deny",permissionDecisionReason:r}};return process.env.WERKMEISTER_HOOK_HARNESS==="codex"?o:{continue:!1,stopReason:r,...o}}case"UserPromptSubmit":return{decision:"block",reason:s?"This workspace is waiting for capacity; it starts on its own.":"This workspace is paused. Press \u25B6 Resume on its card first."};default:return null}}i(Z,"pauseGate");function tt(t,e=new Date){let n=w(String(t.cwd||process.cwd()));if(!n)return null;let s=j(n),r=q(s),o=K(t,r);o?.state==="working"&&r?.state==="needs-you"&&A(n,t.session_id)&&(o=null);let f=o!==null&&!(r&&r.state===o.state&&r.question===o.question&&r.via===o.via),u=I(s),c=t.session_id,x=process.env.CLAUDE_CODE_ENTRYPOINT?.startsWith("sdk")??!1,k=x&&u[c]&&!u[c].headless,O=x&&!k,S=typeof c=="string"&&c?C(t.hook_event_name):void 0,h=!1;if(S===null&&c in u&&!k?(delete u[c],h=!0):S&&(u[c]?.status!==S||!!u[c]?.headless!==O)&&(u[c]={status:S,at:e.toISOString(),...O&&{headless:!0}},h=!0),!f&&!h)return null;let m={...r};f&&o&&(m={state:o.state,at:e.toISOString()},o.question&&(m.question=o.question),o.via&&(m.via=o.via)),Object.keys(u).length&&(m.sessions=u);let P=R(n);return L(P,m),P}i(tt,"record");function $(){try{let t=process.stdin.isTTY?"":a.readFileSync(0,"utf8"),e=t.trim()?JSON.parse(t):{};if(typeof e!="object"||e===null||Array.isArray(e))return;let n=w(String(e.cwd||process.cwd())),s=n?Z(e,n):null;if(s){console.log(JSON.stringify(s));return}n&&e.hook_event_name==="UserPromptSubmit"&&a.rmSync(G(n),{force:!0});let r=n?X(e,n):null;if(r&&console.log(JSON.stringify(r)),r&&e.hook_event_name==="Stop")return;tt(e)}catch{}}i($,"main");$();
|
|
7
7
|
//# sourceMappingURL=agent_state.js.map
|