werkmeister 0.85.3 → 0.85.4

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/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __sandboxCreateRequire } from "node:module";
3
3
  const require = __sandboxCreateRequire(import.meta.url);
4
- var yee=Object.create;var eg=Object.defineProperty;var wee=Object.getOwnPropertyDescriptor;var xee=Object.getOwnPropertyNames;var kee=Object.getPrototypeOf,bee=Object.prototype.hasOwnProperty;var i=(e,t)=>eg(e,"name",{value:t,configurable:!0}),oe=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var A=(e,t)=>()=>(e&&(t=e(e=0)),t);var T=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ie=(e,t)=>{for(var r in t)eg(e,r,{get:t[r],enumerable:!0})},vee=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of xee(t))!bee.call(e,s)&&s!==r&&eg(e,s,{get:()=>t[s],enumerable:!(n=wee(t,s))||n.enumerable});return e};var Oe=(e,t,r)=>(r=e!=null?yee(kee(e)):{},vee(t||!e||!e.__esModule?eg(r,"default",{value:e,enumerable:!0}):r,e));var v,h=A(()=>{v={sha:"d0086c2196753a0724d1b68c79e81a45fffad46e",dirty:!1}});var Hd=T(mS=>{h();var tg=class extends Error{static{i(this,"CommanderError")}constructor(t,r,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=r,this.exitCode=t,this.nestedError=void 0}},hS=class extends tg{static{i(this,"InvalidArgumentError")}constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};mS.CommanderError=tg;mS.InvalidArgumentError=hS});var rg=T(yS=>{h();var{InvalidArgumentError:_ee}=Hd(),gS=class{static{i(this,"Argument")}constructor(t,r){switch(this.description=r||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case"<":this.required=!0,this._name=t.slice(1,-1);break;case"[":this.required=!1,this._name=t.slice(1,-1);break;default:this.required=!0,this._name=t;break}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(t,r){return r===this.defaultValue||!Array.isArray(r)?[t]:(r.push(t),r)}default(t,r){return this.defaultValue=t,this.defaultValueDescription=r,this}argParser(t){return this.parseArg=t,this}choices(t){return this.argChoices=t.slice(),this.parseArg=(r,n)=>{if(!this.argChoices.includes(r))throw new _ee(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(r,n):r},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function Eee(e){let t=e.name()+(e.variadic===!0?"...":"");return e.required?"<"+t+">":"["+t+"]"}i(Eee,"humanReadableArgName");yS.Argument=gS;yS.humanReadableArgName=Eee});var kS=T(xS=>{h();var{humanReadableArgName:$ee}=rg(),wS=class{static{i(this,"Help")}constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(t){this.helpWidth=this.helpWidth??t.helpWidth??80}visibleCommands(t){let r=t.commands.filter(s=>!s._hidden),n=t._getHelpCommand();return n&&!n._hidden&&r.push(n),this.sortSubcommands&&r.sort((s,o)=>s.name().localeCompare(o.name())),r}compareOptions(t,r){let n=i(s=>s.short?s.short.replace(/^-/,""):s.long.replace(/^--/,""),"getSortKey");return n(t).localeCompare(n(r))}visibleOptions(t){let r=t.options.filter(s=>!s.hidden),n=t._getHelpOption();if(n&&!n.hidden){let s=n.short&&t._findOption(n.short),o=n.long&&t._findOption(n.long);!s&&!o?r.push(n):n.long&&!o?r.push(t.createOption(n.long,n.description)):n.short&&!s&&r.push(t.createOption(n.short,n.description))}return this.sortOptions&&r.sort(this.compareOptions),r}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];let r=[];for(let n=t.parent;n;n=n.parent){let s=n.options.filter(o=>!o.hidden);r.push(...s)}return this.sortOptions&&r.sort(this.compareOptions),r}visibleArguments(t){return t._argsDescription&&t.registeredArguments.forEach(r=>{r.description=r.description||t._argsDescription[r.name()]||""}),t.registeredArguments.find(r=>r.description)?t.registeredArguments:[]}subcommandTerm(t){let r=t.registeredArguments.map(n=>$ee(n)).join(" ");return t._name+(t._aliases[0]?"|"+t._aliases[0]:"")+(t.options.length?" [options]":"")+(r?" "+r:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,r){return r.visibleCommands(t).reduce((n,s)=>Math.max(n,this.displayWidth(r.styleSubcommandTerm(r.subcommandTerm(s)))),0)}longestOptionTermLength(t,r){return r.visibleOptions(t).reduce((n,s)=>Math.max(n,this.displayWidth(r.styleOptionTerm(r.optionTerm(s)))),0)}longestGlobalOptionTermLength(t,r){return r.visibleGlobalOptions(t).reduce((n,s)=>Math.max(n,this.displayWidth(r.styleOptionTerm(r.optionTerm(s)))),0)}longestArgumentTermLength(t,r){return r.visibleArguments(t).reduce((n,s)=>Math.max(n,this.displayWidth(r.styleArgumentTerm(r.argumentTerm(s)))),0)}commandUsage(t){let r=t._name;t._aliases[0]&&(r=r+"|"+t._aliases[0]);let n="";for(let s=t.parent;s;s=s.parent)n=s.name()+" "+n;return n+r+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){let r=[];if(t.argChoices&&r.push(`choices: ${t.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),t.defaultValue!==void 0&&(t.required||t.optional||t.isBoolean()&&typeof t.defaultValue=="boolean")&&r.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),t.presetArg!==void 0&&t.optional&&r.push(`preset: ${JSON.stringify(t.presetArg)}`),t.envVar!==void 0&&r.push(`env: ${t.envVar}`),r.length>0){let n=`(${r.join(", ")})`;return t.description?`${t.description} ${n}`:n}return t.description}argumentDescription(t){let r=[];if(t.argChoices&&r.push(`choices: ${t.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),t.defaultValue!==void 0&&r.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),r.length>0){let n=`(${r.join(", ")})`;return t.description?`${t.description} ${n}`:n}return t.description}formatItemList(t,r,n){return r.length===0?[]:[n.styleTitle(t),...r,""]}groupItems(t,r,n){let s=new Map;return t.forEach(o=>{let a=n(o);s.has(a)||s.set(a,[])}),r.forEach(o=>{let a=n(o);s.has(a)||s.set(a,[]),s.get(a).push(o)}),s}formatHelp(t,r){let n=r.padWidth(t,r),s=r.helpWidth??80;function o(d,p){return r.formatItem(d,n,p,r)}i(o,"callFormatItem");let a=[`${r.styleTitle("Usage:")} ${r.styleUsage(r.commandUsage(t))}`,""],c=r.commandDescription(t);c.length>0&&(a=a.concat([r.boxWrap(r.styleCommandDescription(c),s),""]));let l=r.visibleArguments(t).map(d=>o(r.styleArgumentTerm(r.argumentTerm(d)),r.styleArgumentDescription(r.argumentDescription(d))));if(a=a.concat(this.formatItemList("Arguments:",l,r)),this.groupItems(t.options,r.visibleOptions(t),d=>d.helpGroupHeading??"Options:").forEach((d,p)=>{let m=d.map(w=>o(r.styleOptionTerm(r.optionTerm(w)),r.styleOptionDescription(r.optionDescription(w))));a=a.concat(this.formatItemList(p,m,r))}),r.showGlobalOptions){let d=r.visibleGlobalOptions(t).map(p=>o(r.styleOptionTerm(r.optionTerm(p)),r.styleOptionDescription(r.optionDescription(p))));a=a.concat(this.formatItemList("Global Options:",d,r))}return this.groupItems(t.commands,r.visibleCommands(t),d=>d.helpGroup()||"Commands:").forEach((d,p)=>{let m=d.map(w=>o(r.styleSubcommandTerm(r.subcommandTerm(w)),r.styleSubcommandDescription(r.subcommandDescription(w))));a=a.concat(this.formatItemList(p,m,r))}),a.join(`
4
+ var yee=Object.create;var eg=Object.defineProperty;var wee=Object.getOwnPropertyDescriptor;var xee=Object.getOwnPropertyNames;var kee=Object.getPrototypeOf,bee=Object.prototype.hasOwnProperty;var i=(e,t)=>eg(e,"name",{value:t,configurable:!0}),oe=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var A=(e,t)=>()=>(e&&(t=e(e=0)),t);var T=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ie=(e,t)=>{for(var r in t)eg(e,r,{get:t[r],enumerable:!0})},vee=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of xee(t))!bee.call(e,s)&&s!==r&&eg(e,s,{get:()=>t[s],enumerable:!(n=wee(t,s))||n.enumerable});return e};var Oe=(e,t,r)=>(r=e!=null?yee(kee(e)):{},vee(t||!e||!e.__esModule?eg(r,"default",{value:e,enumerable:!0}):r,e));var v,h=A(()=>{v={sha:"7feacbfe2e2f0ed13ce1c2dae4796494b6e92f9f",dirty:!1}});var Hd=T(mS=>{h();var tg=class extends Error{static{i(this,"CommanderError")}constructor(t,r,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=r,this.exitCode=t,this.nestedError=void 0}},hS=class extends tg{static{i(this,"InvalidArgumentError")}constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};mS.CommanderError=tg;mS.InvalidArgumentError=hS});var rg=T(yS=>{h();var{InvalidArgumentError:_ee}=Hd(),gS=class{static{i(this,"Argument")}constructor(t,r){switch(this.description=r||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case"<":this.required=!0,this._name=t.slice(1,-1);break;case"[":this.required=!1,this._name=t.slice(1,-1);break;default:this.required=!0,this._name=t;break}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(t,r){return r===this.defaultValue||!Array.isArray(r)?[t]:(r.push(t),r)}default(t,r){return this.defaultValue=t,this.defaultValueDescription=r,this}argParser(t){return this.parseArg=t,this}choices(t){return this.argChoices=t.slice(),this.parseArg=(r,n)=>{if(!this.argChoices.includes(r))throw new _ee(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(r,n):r},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function Eee(e){let t=e.name()+(e.variadic===!0?"...":"");return e.required?"<"+t+">":"["+t+"]"}i(Eee,"humanReadableArgName");yS.Argument=gS;yS.humanReadableArgName=Eee});var kS=T(xS=>{h();var{humanReadableArgName:$ee}=rg(),wS=class{static{i(this,"Help")}constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(t){this.helpWidth=this.helpWidth??t.helpWidth??80}visibleCommands(t){let r=t.commands.filter(s=>!s._hidden),n=t._getHelpCommand();return n&&!n._hidden&&r.push(n),this.sortSubcommands&&r.sort((s,o)=>s.name().localeCompare(o.name())),r}compareOptions(t,r){let n=i(s=>s.short?s.short.replace(/^-/,""):s.long.replace(/^--/,""),"getSortKey");return n(t).localeCompare(n(r))}visibleOptions(t){let r=t.options.filter(s=>!s.hidden),n=t._getHelpOption();if(n&&!n.hidden){let s=n.short&&t._findOption(n.short),o=n.long&&t._findOption(n.long);!s&&!o?r.push(n):n.long&&!o?r.push(t.createOption(n.long,n.description)):n.short&&!s&&r.push(t.createOption(n.short,n.description))}return this.sortOptions&&r.sort(this.compareOptions),r}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];let r=[];for(let n=t.parent;n;n=n.parent){let s=n.options.filter(o=>!o.hidden);r.push(...s)}return this.sortOptions&&r.sort(this.compareOptions),r}visibleArguments(t){return t._argsDescription&&t.registeredArguments.forEach(r=>{r.description=r.description||t._argsDescription[r.name()]||""}),t.registeredArguments.find(r=>r.description)?t.registeredArguments:[]}subcommandTerm(t){let r=t.registeredArguments.map(n=>$ee(n)).join(" ");return t._name+(t._aliases[0]?"|"+t._aliases[0]:"")+(t.options.length?" [options]":"")+(r?" "+r:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,r){return r.visibleCommands(t).reduce((n,s)=>Math.max(n,this.displayWidth(r.styleSubcommandTerm(r.subcommandTerm(s)))),0)}longestOptionTermLength(t,r){return r.visibleOptions(t).reduce((n,s)=>Math.max(n,this.displayWidth(r.styleOptionTerm(r.optionTerm(s)))),0)}longestGlobalOptionTermLength(t,r){return r.visibleGlobalOptions(t).reduce((n,s)=>Math.max(n,this.displayWidth(r.styleOptionTerm(r.optionTerm(s)))),0)}longestArgumentTermLength(t,r){return r.visibleArguments(t).reduce((n,s)=>Math.max(n,this.displayWidth(r.styleArgumentTerm(r.argumentTerm(s)))),0)}commandUsage(t){let r=t._name;t._aliases[0]&&(r=r+"|"+t._aliases[0]);let n="";for(let s=t.parent;s;s=s.parent)n=s.name()+" "+n;return n+r+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){let r=[];if(t.argChoices&&r.push(`choices: ${t.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),t.defaultValue!==void 0&&(t.required||t.optional||t.isBoolean()&&typeof t.defaultValue=="boolean")&&r.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),t.presetArg!==void 0&&t.optional&&r.push(`preset: ${JSON.stringify(t.presetArg)}`),t.envVar!==void 0&&r.push(`env: ${t.envVar}`),r.length>0){let n=`(${r.join(", ")})`;return t.description?`${t.description} ${n}`:n}return t.description}argumentDescription(t){let r=[];if(t.argChoices&&r.push(`choices: ${t.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),t.defaultValue!==void 0&&r.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),r.length>0){let n=`(${r.join(", ")})`;return t.description?`${t.description} ${n}`:n}return t.description}formatItemList(t,r,n){return r.length===0?[]:[n.styleTitle(t),...r,""]}groupItems(t,r,n){let s=new Map;return t.forEach(o=>{let a=n(o);s.has(a)||s.set(a,[])}),r.forEach(o=>{let a=n(o);s.has(a)||s.set(a,[]),s.get(a).push(o)}),s}formatHelp(t,r){let n=r.padWidth(t,r),s=r.helpWidth??80;function o(d,p){return r.formatItem(d,n,p,r)}i(o,"callFormatItem");let a=[`${r.styleTitle("Usage:")} ${r.styleUsage(r.commandUsage(t))}`,""],c=r.commandDescription(t);c.length>0&&(a=a.concat([r.boxWrap(r.styleCommandDescription(c),s),""]));let l=r.visibleArguments(t).map(d=>o(r.styleArgumentTerm(r.argumentTerm(d)),r.styleArgumentDescription(r.argumentDescription(d))));if(a=a.concat(this.formatItemList("Arguments:",l,r)),this.groupItems(t.options,r.visibleOptions(t),d=>d.helpGroupHeading??"Options:").forEach((d,p)=>{let m=d.map(w=>o(r.styleOptionTerm(r.optionTerm(w)),r.styleOptionDescription(r.optionDescription(w))));a=a.concat(this.formatItemList(p,m,r))}),r.showGlobalOptions){let d=r.visibleGlobalOptions(t).map(p=>o(r.styleOptionTerm(r.optionTerm(p)),r.styleOptionDescription(r.optionDescription(p))));a=a.concat(this.formatItemList("Global Options:",d,r))}return this.groupItems(t.commands,r.visibleCommands(t),d=>d.helpGroup()||"Commands:").forEach((d,p)=>{let m=d.map(w=>o(r.styleSubcommandTerm(r.subcommandTerm(w)),r.styleSubcommandDescription(r.subcommandDescription(w))));a=a.concat(this.formatItemList(p,m,r))}),a.join(`
5
5
  `)}displayWidth(t){return jI(t).length}styleTitle(t){return t}styleUsage(t){return t.split(" ").map(r=>r==="[options]"?this.styleOptionText(r):r==="[command]"?this.styleSubcommandText(r):r[0]==="["||r[0]==="<"?this.styleArgumentText(r):this.styleCommandText(r)).join(" ")}styleCommandDescription(t){return this.styleDescriptionText(t)}styleOptionDescription(t){return this.styleDescriptionText(t)}styleSubcommandDescription(t){return this.styleDescriptionText(t)}styleArgumentDescription(t){return this.styleDescriptionText(t)}styleDescriptionText(t){return t}styleOptionTerm(t){return this.styleOptionText(t)}styleSubcommandTerm(t){return t.split(" ").map(r=>r==="[options]"?this.styleOptionText(r):r[0]==="["||r[0]==="<"?this.styleArgumentText(r):this.styleSubcommandText(r)).join(" ")}styleArgumentTerm(t){return this.styleArgumentText(t)}styleOptionText(t){return t}styleArgumentText(t){return t}styleSubcommandText(t){return t}styleCommandText(t){return t}padWidth(t,r){return Math.max(r.longestOptionTermLength(t,r),r.longestGlobalOptionTermLength(t,r),r.longestSubcommandTermLength(t,r),r.longestArgumentTermLength(t,r))}preformatted(t){return/\n[^\S\r\n]/.test(t)}formatItem(t,r,n,s){let a=" ".repeat(2);if(!n)return a+t;let c=t.padEnd(r+t.length-s.displayWidth(t)),l=2,f=(this.helpWidth??80)-r-l-2,d;return f<this.minWidthToWrap||s.preformatted(n)?d=n:d=s.boxWrap(n,f).replace(/\n/g,`
6
6
  `+" ".repeat(r+l)),a+c+" ".repeat(l)+d.replace(/\n/g,`
7
7
  ${a}`)}boxWrap(t,r){if(r<this.minWidthToWrap)return t;let n=t.split(/\r\n|\n/),s=/[\s]*[^\s]+/g,o=[];return n.forEach(a=>{let c=a.match(s);if(c===null){o.push("");return}let l=[c.shift()],u=this.displayWidth(l[0]);c.forEach(f=>{let d=this.displayWidth(f);if(u+d<=r){l.push(f),u+=d;return}o.push(l.join(""));let p=f.trimStart();l=[p],u=this.displayWidth(p)}),o.push(l.join(""))}),o.join(`
@@ -619,7 +619,7 @@ ${J4}
619
619
  ${Y$}`}function z$(e){let t=[e.issueId,e.task].filter(Boolean).join(" ")||e.name,r=t.lastIndexOf(" ",58);return{title:t.length<60?t:`${t.slice(0,r>40?r:58).trimEnd()}\u2026`,...e.model?{model:e.model}:{},prompt:Q4(e.autonomous),background:`Workspace \`${e.name}\`${e.issueId?` for ${e.issueId}`:""}. Read \`CLAUDE.md\`, then \`.werkmeister/issue.md\`; its routing table picks the stage.`}}var J4,Y$,Pw,X4,Zae,ece,tce,Iw=A(()=>{"use strict";h();J4="This is an interactive run: check with me at each stage's human check.",Y$="Run `werkmeister feature up` only when the gate needs it, and `werkmeister feature stop` this workspace's containers right after `werkmeister pr open` succeeds.",Pw=["Tests never call the real Jira or GitHub APIs; the tracker is mocked. The only real issue updates are the status moves `werkmeister issue start` and `werkmeister pr open` make for this ticket and its `group:` members; run both.","Never read or write the real `~/.werkmeister`; tests use a temporary HOME. To see the machine config's shape run `werkmeister machine config`: it masks secrets such as `jira.api_token`.","No `npm link`, `npm`/`pnpm install -g`, `npm publish`, `werkmeister infra proxy-reload`, and no other workspaces.",'Where the ticket says "to confirm", use it as written unless the code shows a reason to change it, and record each choice in the stage output for PR review.',Y$].map(e=>`- ${e}`).join(`
620
620
  `),X4=[[/werkmeister registry sync/,"- Registry sync: the next `werkmeister registry sync` after merge picks up the change; the gate reads the branch's own `.werkmeister/services.yaml` fragment."],[/werkmeister infra proxy-reload/,"- Proxy reload: the next `werkmeister infra proxy-reload` after merge applies the change."],[/(?:npm|pnpm|yarn) link\b/,"- Linking the CLI: after merge, if at all; the run runs the built binary with `node`."],[/(?:(?:npm|pnpm|yarn) (?:install|i|add)\b[^`\n]*?(?: -g\b| --global\b)|yarn global add\b)/,"- Global installs: after merge, if at all; the run uses the workspace's own install."]],Zae=i(e=>new RegExp(`(?:^|(?<!["\u201C'])\\brun )\`?${e.source}`,"i"),"stepRe"),ece=X4.map(([e])=>Zae(e)),tce=/^(\s*(?:[-*]|\d+\.) +(?:\[[ x]\] +)?)?(.*)$/;i(gh,"deferMachineSteps");i(Q4,"startPrompt");i(z$,"buildStartArgs")});import*as xo from"node:fs";import*as gi from"node:path";function e5(e){return gi.join(W(e),"graduations.yml")}function Z4(e){try{let t=Nw.parse(xo.readFileSync(e5(e),"utf8"));return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{}}catch{return{}}}function oce(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"decision"}function ice(e){let t=gi.join(e,"stages"),r;try{r=xo.readdirSync(t).sort()}catch{return[]}return r.flatMap(n=>{let s=gi.join(t,n,"output");try{return xo.readdirSync(s).filter(o=>o.endsWith(".md")).sort().map(o=>gi.join(s,o))}catch{return[]}})}function ace(e,t){let r=e.split(`
621
621
  `),n=0;if(r[0]==="---"){let l=r.indexOf("---",1);l!==-1&&(n=l+1)}let s=[],o=new Set,a=!1;for(let l=n;l<r.length;l++){if(sce.test(r[l])){a=!a;continue}if(a)continue;let u=nce.exec(r[l]);u?s.push({at:l,level:u[1].length,title:u[2]}):rce.test(r[l].trim())&&o.add(s.length-1)}s.length&&o.delete(-1);let c=new Map;return[...o].map(l=>{let u=s[l],f=u?s.slice(l+1).find(w=>w.level<=u.level):s[0],d=oce(u?u.title:t),p=(c.get(d)??0)+1;c.set(d,p),p>1&&(d=`${d}-${p}`);let m=r.slice(u?u.at:n,f?f.at:r.length).join(`
622
- `);return{slug:d,body:m}})}function J$(e,t){return gi.relative(e,t.path)}var Nw,rce,nce,sce,t5,r5=A(()=>{"use strict";h();Nw=Oe(Ye(),1);Kr();rce=/^status:\s*decided\b/,nce=/^(#{1,6})\s+(.+?)\s*#*$/,sce=/^\s*(```|~~~)/;i(e5,"statePath");i(Z4,"readState");i(oce,"slugify");i(ice,"outputFiles");i(ace,"decidedSections");i(J$,"decisionId");t5={open(e){let t=Z4(e),r=[],n=0;for(let s of ice(e)){let o=ace(xo.readFileSync(s,"utf8"),gi.basename(s,".md"));for(let{slug:a,body:c}of o){n+=1;let l={path:`${s}#${a}`,number:n,type:"decision",slug:a,frontmatter:{},body:c},u=t[J$(e,l)]??{};l.frontmatter={type:"decision",status:"decided",refs:[],...u},!["graduated","superseded"].includes(l.frontmatter.status)&&r.push(l)}}return r},mark(e,t,r){let n=Z4(e),s=J$(e,t);n[s]={...n[s],...r},xo.mkdirSync(W(e),{recursive:!0}),xo.writeFileSync(e5(e),Nw.stringify(n))},cite:i((e,t)=>`decision ${String(t.number).padStart(3,"0")}, see ${J$(e,t)}`,"cite")}});function sf(e){let t=e.trim().toLowerCase();return Object.hasOwn(X$,t)?X$[t]:X$.feature}function js(e){return e.map((t,r)=>`${String(r+1).padStart(2,"0")}_${t.name}`)}function a1(e){let t=e.findIndex(r=>r.name==="propose");return t<0?null:js(e)[t]}function jw(e){return a1(e)??js(e)[e.length-1]}var Q$,Z$,e1,o5,i5,cce,a5,c5,l5,t1,r1,n1,yh,u5,s1,lce,f5,d5,p5,wh,xh,h5,m5,o1,n5,i1,uce,s5,fce,dce,X$,c1=A(()=>{"use strict";h();An();Cw();Q$="If the container is not running, run `werkmeister feature up` once first; `docker restart` only reloads one that is already running. Never run `werkmeister feature restart` or `werkmeister workspace init` to reload \u2014 they are slower, and init rewrites the stage contracts.",Z$="A library or CLI has no service to restart: build it, then exercise the built artifact exactly as its Validation text in `werkmeister-context.md` \xA7 How to validate says.",e1=["Confirm ponytail is active (see `_shared/standards.md`; invoke the skill only if it is not), then read the standards rows above. Restate the rule you are applying beside each edit."],o5="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 \u2014 never hand-roll `HOME=\u2026`. That run is on the host, without the container's env (`HOST`, `WERKMEISTER_SLOT`, `NODE_ENV`, `<SVC>_URL`, \u2026), and the PR gate runs the same commands in the workspace container. 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. ",i5='A subagent you brief to run tests or the CLI gets that wrapped command verbatim in its brief. 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). Redirect output to a file as one group, so every command in an `&&` chain lands there. For a background job (`run_in_background`) write background: `{ <test command>; } > <log> 2>&1` and read the exit code from the job\'s completion notice; for a foreground call write foreground: `{ <test command>; } > <log> 2>&1; echo "exit $?"`. Read back only the failing slice.',cce=o5+"Once it passes, run `werkmeister pr gate --tests` (from the workspace, detached when it may pass 10 minutes) and fix what it fails; record both exit codes. "+i5,a5=`${o5}Record its exit code. ${i5}`,c5="Once the review's fixes are in, run `werkmeister pr gate --tests` (from the workspace, detached when it may pass 10 minutes) and fix what it fails; record its exit code. A fix here reruns the host test step first.",l5="If the exercise below changes code, rerun the review on that delta: a fresh subagent with the same brief, over the commits and changes made since the first review. Fix its **Must fix** findings, rerun the host test step, and append the result as new rows to `output/review.md`; the gate's review row covers them.",t1=i(e=>`Before running tests, read \`git diff\` in each repo you touched and tick off each edit \`${e}\` settled against it: an edit reported as applied can be missing.`,"diffCheck"),r1="Before asking for approval, list the exercise rows only a person can run (a real VS Code window, a device, a browser). Ask the person for each one's result, one question per row (pass / fail / not run), and write the answer into `exercise.md`: PASS or FAIL in the table, and for a row not run a `MANUAL: not run (person's reason)` line under it (the table's result cell stays PASS or FAIL). An approval that skips this keeps those rows MANUAL, and the PR file says why.",n1="every skipped test by name with its skip reason and where it ran instead",yh=i(e=>e.map(t=>`\`${t}\``).join(", "),"keys"),u5="`git commit --fixup <sha>`, then `git rebase --autosquash $(git merge-base HEAD origin/main)`",s1=i(e=>e.group.length?[`This workspace is a grouped PR (\`group\` in \`workspace.yml\`): one commit per ticket, for the workspace's issue and each member, ${yh(e.group)}, so each can be reverted alone. Take the tickets one at a time: make that ticket's changes and tests, run the diff check below on them, then commit on the worktree's branch with a message that starts with its key (\`<KEY> <summary>\`) before starting the next. Each commit builds and passes the host tests on its own. A ticket that changes a released package carries its release entry (changeset) in its own commit. When a ticket's change alters a generated snapshot (e.g. \`strategy-jit.snapshot.json\`), regenerate it in that ticket's commit, so the commit passes the snapshot test alone; a brief that says to regenerate once for the whole PR does not override this. Commit order across tickets is free; a ticket whose change depends on another's evidence (a measurement) can come last. Never reorder commits to match the spec.`]:[],"groupStep"),lce="a `| criterion | result | evidence |` table whose result cell is exactly `PASS` or `FAIL` \u2014 nothing else in the cell \u2014 with the proof in the evidence column",f5=i((e,t)=>`Review the diff: for each code worktree you touched, start a fresh subagent and brief it with only the worktree path and "run the \`ponytail:ponytail-review\` skill over this worktree's ${t.length?"commits in `origin/main...HEAD` (the PR's base in place of `main` when it differs), plus any uncommitted changes and untracked files":"uncommitted changes, untracked files included"}" \u2014 not how you built it, so the review is not anchored on your reasoning. If the change adds or widens an allow rule or another pre-approved command, add to the brief: "this change pre-approves a command: list every file, env var, network address or process it can reach from its arguments, and treat each that leaves the workspace or its temp HOME as Must fix". Always add: "any finding where the change can restart or write the host daemon, the real \`~/.werkmeister\` or another workspace, whether through an allow rule, a script or a test, is Must fix". Fix every **Must fix** finding in place, and any **Should fix** finding that shows the change's own docs, comments, help text or changeset state something false (fix the code, or reword that text so it is true), ${t.length?`fold each fix into the commit of the ticket it belongs to (${u5}), `:""}then ${e}. Leave the other **Should fix** and **Nice to have** findings as they are. Write \`output/review.md\`: per worktree, the findings as the review grouped them, each marked \`fixed\` or \`left: <why>\`, then ${lce}, with one row per worktree (\`PASS\` means no Must fix left open). 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\`.`,"reviewStep"),d5=i(e=>f5("rerun the host test step above",e.group),"implementReview"),p5='For each decision that renames, keeps or removes a name, a fallback or an alias, record its definition site (file and line) and the commit that introduced it (`git log -S <name>`, in the repo that defines it). When that commit marks it as a transition or legacy alias, list "remove" as an option beside rename and keep.',wh=i((e,t)=>`${t} Then change \`status: proposed\` at the top of \`output/${e}\` to \`status: decided\`: that flip is the approval, and the next session starts without asking again. ${wo}`,"statusGate"),xh=", its first line `status: proposed`",h5=i(e=>e?`Ask this check through \`${e}\`: at most 4 questions per call (more than 4: batches of 4, one call after another), each standing on its own (what was checked, 2\u20133 concrete options with the exact wording or behaviour, the recommended one first; "Other" takes edits). Write each answer into the output file as its status, noted \`${mi.chat}\` (a PR file: \`${mi.chatPr}\`). A check left as a sentence at the end of a reply is not asked.`:`Ask this check as one numbered block at the end of your reply: each question stands on its own, options lettered with the recommended one first, then "reply with the letters, or your edits". Write each answer into the output file as its status, noted \`${mi.chat}\` (a PR file: \`${mi.chatPr}\`).`,"askLine"),m5="Review `output/` once against `../../BRIEF.md` and the live issue (`werkmeister issue view`). Flip every `status: proposed` to `status: decided` yourself, and record each decision \u2014 and anything you would have asked a person \u2014 under `## Recommendations for reviewer` in the PR body. Then start the next stage without asking.",o1=i(e=>`a \`| check | result | ${e} |\` table whose result cell is exactly \`PASS\` or \`FAIL\` \u2014 nothing else in the cell \u2014 with the captured output in the ${e} column. The rule holds for every table in \`exercise.md\`; describe a superseded run in prose, not as a \`FAIL\` row`,"exerciseFormat"),n5="the repo's lint command (the `&& <lint>` tail 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.",i1={name:"propose",job:"acceptance walk and PR files",writes:"the code commits (one per repo, or one per ticket in a grouped PR), `output/pr-<worktree>.md` per repo",check:"approve each PR file; `werkmeister pr open` opens it",standards:"none",contract:i(e=>({oneJob:`One job: prove each acceptance criterion, ${e.group.length?"check the per-ticket commits in":"commit in"} each code worktree, and write one PR file per repo touched. ${e.autonomous?"You approve it after the self-check":"Approving is the person's act"}; opening is \`werkmeister pr open\`.`,inputs:["Working (this run): `../../BRIEF.md` \xA7 Acceptance criteria","Working (this run): `../*/output/` \u2014 every prior stage's artifacts","Working (this run): `git status` and `git diff --stat` in each repo you touched","Reference (every run): `../../_shared/pr-rules.md` \u2014 the PR file format and the gate"],doNotLoad:"`_shared/standards.md` (no code is written here), source files, `.werkmeister/`.",process:["Walk every acceptance criterion in `BRIEF.md`. For each, write a row whose result cell is exactly PASS or FAIL (MANUAL for a criterion only the reviewer can check, e.g. it needs a real PR or the desktop app, with why in the evidence; never PASS for a check nobody ran), with the file and line in a prior `output/` that proves it in a separate evidence column. A FAIL routes back to the owning stage \u2014 do not fix it here.",e.group.length?`The commits are already made, one per ticket: keep them, never squash to one per repo. For a repo with \`ship: tag\` and a \`release_check\` in the registry, write the release entry it needs (e.g. a changeset). Run ${n5} Then fold everything uncommitted into its ticket's commit (${u5}), each ticket's release entry into that ticket's own commit, and check that \`git log --oneline origin/main..HEAD\` in each worktree shows one commit per ticket (the workspace's issue and ${yh(e.group)}), each message starting with its key.`:`In each code worktree you touched (\`git -C <repo>\`), commit on its branch with a message that names the change, not the stage. For a repo with \`ship: tag\` and a \`release_check\` in the registry, add the release entry it needs (e.g. a changeset) in the same commit. Before committing, run ${n5}`,"Before the PR file: for each follow-up a decided question in `decisions.md` promises, file it through `../../_shared/issues-report.md` and write its issue key beside that decision. The gate's follow-ups check stays as the backstop.","Write `output/pr-<worktree>.md` per repo touched, in the format of `_shared/pr-rules.md`, at `status: draft`, with `repo:` taken from `git -C <worktree> remote get-url origin` (as `owner/repo`; the gate rejects any other value). Title: `<type>(<scope>): <ISSUE-ID> <summary>`. Body: summary, the test and exercise results from prior outputs (every table with a `result` column \u2014 the gate reads them all \u2014 has a result cell of exactly `PASS` and the output in its own column: a FAIL cell anywhere in the PR file stops the PR, so describe a pre-fix reproduction in prose, not as a FAIL row), the acceptance table from step 1, and `Fixes <issue>` when the tracker is GitHub."+(e.group.length?" Start the body with `Rebase and merge, not squash: one commit per ticket, each revertable alone.` and list each member under the summary.":""),"Commit and push this folder's branch \u2014 the record. Never open a PR for it."],outputs:[e.group.length?"The per-ticket commits, kept, on each worktree's branch":"One commit per code repo touched, on that worktree's branch","`output/pr-<worktree>.md` per repo"],humanCheck:`Read each \`pr-*.md\`. Set \`status: approved\` on each one to open \u2014 that flip is the approval. Then \`werkmeister pr open\`, run detached as \`_shared/pr-rules.md\` rule 3 shows, runs the gate and opens it. Merging is yours. After the release, \`werkmeister pr status\`, then ${e.group.length?`check each member reads Done \u2014 \`werkmeister issue view <KEY>\` for ${yh(e.group)}; \`pr status\` moves them with the workspace's issue, so move one by hand only if it didn't \u2014 then `:""}the post-mortem (\`postmortem\` skill), then ask the person before \`werkmeister workspace close\`. Code written after a PR merged (e.g. found at release) is a follow-up: \`werkmeister pr new <worktree> --slug <slug>\`. ${wo}`,selfCheck:"Review each `pr-*.md` once against `../../BRIEF.md` and the live issue. Add `## Recommendations for reviewer` to its body \u2014 every decision and question collected on the way \u2014 then set `status: approved` yourself and run `werkmeister pr open` detached, as `_shared/pr-rules.md` rule 3 shows. Stop at the PR URL. Merging is the person's."+(e.group.length?` When the PR ships, check each member reads Done (\`werkmeister issue view <KEY>\` for ${yh(e.group)}) before the post-mortem; \`pr status\` moves them with the workspace's issue, so move one by hand only if it didn't.`:"")}),"contract")},uce=[{name:"research",job:"inventory the code, surface decisions",writes:"`output/inventory.md`, `output/decisions.md`",check:"answer every open question in `decisions.md`",standards:"none",contract:i(e=>({oneJob:"One job: establish what the code the brief touches does today, and turn the brief's open questions into an editable decision sheet. No code is written in this stage.",inputs:["Working (this run): `../../BRIEF.md`",`Working (this run): the files in ${e.repos} that \`BRIEF.md\` names \u2014 grep for call sites, don't read whole trees`],doNotLoad:`\`_shared/standards.md\` (nothing is written here), other stages' contracts, \`.werkmeister/*.yml\`, \`${be}\`.`,process:['List what exists that the brief touches: entry points, routes or exports, data shapes, and the tests that cover them. For each module the change adds an export to, grep the tests for whole-module mocks of it (e.g. `vi.mock("<module>"`, `mock.module`) and list every hit as a fixture the change must update. For each value the change alters (a string, a default, a command), grep tests and fixtures for that exact value and list the hits; never write that no test covers it without that grep.',"Find the test command in `../../.werkmeister/werkmeister-context.md` and copy it verbatim \u2014 do not restate it from memory.","Check what is already installed that could do the job before recommending anything new.","Write `output/inventory.md`: steps 1\u20133.",p5,"Write `output/decisions.md`: every open question in `BRIEF.md`, each as a heading with `status: proposed`, your recommended answer, and the evidence from steps 1\u20133 and 5. Leave the answer blank when only a person can give it (a ticket key, a preference)."],outputs:["`output/inventory.md`","`output/decisions.md`"],humanCheck:`Open \`output/decisions.md\`. Edit each answer as needed and change its \`status: proposed\` to \`status: decided\`. The next stage must not start while any question is still \`proposed\`. When every question reads \`decided\`, that is the approval \u2014 the next session starts the next stage without asking for confirmation. ${wo}`}),"contract")},{name:"spec",job:"write the spec for the change",gate:"spec.md",writes:"`output/spec.md`, any checkable artifact in the repo",check:"the spec covers every acceptance criterion",enter:"every question in `stages/01_research/output/decisions.md` reads `status: decided` \u2014 the flip *is* the approval, do not ask again",standards:"all",contract:i(e=>({oneJob:"One job: turn the settled decisions into a spec precise enough that the next stage needs no judgment calls, and prove any machine-checkable part of it.",inputs:[`Working (this run): \`${e.at("research")}/output/inventory.md\``,`Working (this run): \`${e.at("research")}/output/decisions.md\` \u2014 every entry must read \`status: decided\`; if not, stop and route back to that stage's human check`,"Reference (every run): `../../BRIEF.md` \xA7 Acceptance criteria"],doNotLoad:"source files already summarised in `inventory.md` (if it looks wrong, fix `inventory.md` and tell the person), `.werkmeister/*.yml`, other stages.",process:[`Write \`output/spec.md\`: what changes, file by file; the interfaces or schemas added; the tests that will prove it; what is explicitly out of scope.${e.group.length?" This is a grouped PR: list one commit per ticket (`<KEY> \u2026`) and what each holds, but do not fix their order.":""}`,"If the change has a machine-checkable artifact (a schema, an API document, a migration), write it in the repo and validate it with a command that needs no new dependency. Record the exact command in `spec.md`.","Map each acceptance criterion in `BRIEF.md` to the step or test in `spec.md` that satisfies it. A criterion with no mapping is a defect in this stage.","Load every `_shared/standards.md` row whose Applies-when matches a file `spec.md` changes, not only the universal ones. Under `## Conflicts` in `spec.md`, write one line per place the ticket's proposed shape breaks a loaded standard (the rule, and the shape that would satisfy it), or `none`.","In `spec.md`, answer: how does an existing user turn this on? Name the setup or config path (a setup command, a config key or file) and the doc that describes it, or say none is needed. Map the answer to a criterion as in step 3; a missing answer is a defect in this stage."],outputs:[`\`output/spec.md\`${xh}`,"Any artifact from step 2, in the repo"],humanCheck:wh("spec.md","Read `output/spec.md` against the brief. Edit it directly \u2014 the next stage builds whatever is on disk.")}),"contract")},{name:"implement",job:"build it and prove it",gate:"review.md",writes:"code diff, `output/exercise.md`, `output/review.md`",check:"read the diff and `review.md`; tests green",standards:"all",contract:i(e=>({oneJob:"One job: make the changes `spec.md` lists, add the tests it names, and prove them against the running service.",inputs:[`Working (this run): \`${e.at("spec")}/output/spec.md\` and the files it names`,`Working (this run): \`${e.at("research")}/output/decisions.md\``,"Reference (every run): `../../.werkmeister/werkmeister-context.md` \u2014 container names, published ports, test command"],doNotLoad:`\`BRIEF.md\` (\`decisions.md\` and \`spec.md\` carry the settled scope), \`inventory.md\`, \`.werkmeister/*.yml\`, \`${be}\`, other stages.`,process:[...e1,...s1(e),"Make the changes `spec.md` lists, and only those. No new runtime dependency unless `decisions.md` justified one in a line.","Add the tests `spec.md` names. Match the style of the nearest existing test; no new test framework.",t1("spec.md"),a5,d5(e),c5,l5,`Reload the running code: ${e.restart}. ${Q$} Then exercise the change as the How-to-validate section of \`werkmeister-context.md\` describes for each service touched, and capture the output. ${Z$}`,`Write \`output/exercise.md\`: \`git diff --stat\` for each repo you touched, the host and \`pr gate --tests\` exit codes and summary lines, ${n1}, any deviation from \`spec.md\` with its reason, and the exercise checks as ${o1("evidence")}.`,r1],outputs:[e.group.length?"Code changes, one commit per ticket (`<KEY> \u2026`), on the worktree's branch \u2014 the next stage keeps them":"Code changes, uncommitted \u2014 the next stage commits after the person reads the diff","`output/exercise.md`",`\`output/review.md\`: a \`| criterion | result | evidence |\` table, result exactly \`PASS\` or \`FAIL\`${xh}`],humanCheck:wh("review.md",e.group.length?"Read each ticket's commit (`git log -p origin/main..HEAD` in each worktree) and `review.md`. Run the tests yourself. Edit the code in place if something is off and fold it into that ticket's commit \u2014 the next stage keeps the commits as they are.":"Read the diff and `review.md`. Run the tests yourself. Edit the code in place if something is off \u2014 the next stage commits what is on disk.")}),"contract")},i1],s5=[{name:"reproduce",job:"reproduce and locate the root cause",writes:"`output/repro.md`",check:"agree the root cause",standards:"none",contract:i(e=>({oneJob:"One job: make the failure happen on demand and name its root cause. No fix is written in this stage.",inputs:["Working (this run): `../../BRIEF.md`",`Working (this run): the files in ${e.repos} on the failing path \u2014 follow the call chain, don't read whole trees`,"Reference (every run): `../../.werkmeister/werkmeister-context.md` \u2014 container names, published ports, logs, test command"],doNotLoad:"`_shared/standards.md` (nothing is written here), other stages' contracts, `.werkmeister/*.yml`.",process:["Reproduce the failure against the running service or with a test. Record the exact command and its output. Judge each run by its exit code, or by a check you have shown fails on a known-bad run \u2014 never by grepping the output for a line that may not be printed.","Write the smallest failing test that captures it, in the style of the nearest existing test. Do not commit it yet.","Trace to the root cause: the first place the code does something other than intended. A symptom site is not a root cause.","List every other caller of the function at the root cause and what each does with the result (an early return, a printed value, a stored state), so the fix's return shape is checked against every caller before the fix stage \u2014 a fix there reaches them too. When the fix belongs in shared code, list its call sites through every helper or entry point that reaches that code, not one argument shape, and record the search commands (greps) you used in `repro.md`.","When the proposed fix branches on a predicate, list each condition that makes it true and give each one a test.",p5,"When the root cause is a permission rule (allow, deny, ask), step 4 lists every source of a matching rule: each builder, each rule derived from a registered command (its `&&` segments included), rules recorded in existing workspaces and how a refresh or migrate removes them, and the list a headless wake passes (`--allowedTools` / `--disallowedTools`). The failing test probes each source.","Write `output/repro.md`: steps 1\u20137, and a proposed fix in one paragraph under a `status: proposed` line."],outputs:["`output/repro.md`","One failing test, uncommitted"],humanCheck:`Read \`output/repro.md\`. Correct the root cause or the proposed fix if needed, then change \`status: proposed\` to \`status: decided\`. That is the approval \u2014 the next session starts the fix without asking again. ${wo}`}),"contract")},{name:"fix",job:"fix it at the root cause",gate:"fix.md",writes:"code diff, `output/fix.md`",check:"read the diff; the failing test now passes",enter:"`stages/01_reproduce/output/repro.md` reads `status: decided` \u2014 the flip *is* the approval, do not ask again",standards:"all",contract:i(e=>({oneJob:"One job: make the failing test pass by changing the code at the root cause, and nothing else.",inputs:[`Working (this run): \`${e.at("reproduce")}/output/repro.md\` \u2014 must read \`status: decided\`; if not, stop and route back`,"Working (this run): the failing test and the files at the root cause","Reference (every run): `../../.werkmeister/werkmeister-context.md` \u2014 test command"],doNotLoad:"`BRIEF.md` (`repro.md` carries the settled scope), `.werkmeister/*.yml`, other stages.",process:[...e1,...s1(e),"Apply the fix `repro.md` settled, at the root cause. Every caller `repro.md` lists gets the fix through the shared function \u2014 do not patch callers one by one.",t1("repro.md"),cce,`Write \`output/fix.md\`: \`git diff --stat\` per repo, the failing test's name, the test exit code and summary line, and ${n1}.`],outputs:[e.group.length?"Code changes plus the test, one commit per ticket":"Code changes plus the test, uncommitted",`\`output/fix.md\`${xh}`],humanCheck:wh("fix.md",`${e.group.length?"Read each ticket's commit (`git log -p origin/main..HEAD`)":"Read the diff"}. Confirm the fix sits where \`repro.md\` put the root cause. Edit in place if not.`)}),"contract")},{name:"exercise",job:"prove it against the running service or the built CLI",gate:"review.md",writes:"`output/exercise.md`, `output/review.md`",check:"the original reproduction no longer fails",standards:"all",contract:i(e=>({oneJob:"One job: show the original failure is gone in the running service or the built binary, not just in the test. Then review the diff and fix what must be fixed.",inputs:[`Working (this run): \`${e.at("reproduce")}/output/repro.md\` \u2014 the reproduction steps`,`Working (this run): \`${e.at("fix")}/output/fix.md\``,"Reference (every run): `../../.werkmeister/werkmeister-context.md` \u2014 container names, published ports, test command"],doNotLoad:"`BRIEF.md` (`repro.md` carries the settled scope), `.werkmeister/*.yml`.",process:[`Reload the running code: ${e.restart}. ${Q$} ${Z$}`,"Rerun the reproduction steps from `repro.md` exactly. Capture the output.","Exercise one neighbouring path through each caller `repro.md` listed. Capture the output.",`Write \`output/exercise.md\`: steps 2\u20133 as ${o1("detail")}.`,f5("rerun the test command exactly as `../../.werkmeister/werkmeister-context.md` states it (through `.werkmeister/bin/with-temp-home`), rerun steps 2\u20133 and update `exercise.md`",e.group),r1],outputs:["`output/exercise.md`",`\`output/review.md\`: a \`| criterion | result | evidence |\` table, result exactly \`PASS\` or \`FAIL\`${xh}`,e.group.length?"Code changes from Must fix findings, folded into their tickets' commits":"Code changes from Must fix findings, uncommitted"],humanCheck:wh("review.md","Read `exercise.md` and `review.md`. A FAIL sends the run back to the fix stage.")}),"contract")},i1],fce=[{name:"scope",job:"fix the boundary and the invariants",writes:"`output/scope.md`",check:"agree what must not change",standards:"none",contract:i(e=>({oneJob:"One job: pin down what the refactor may touch and what behaviour must not change. No code is written in this stage.",inputs:["Working (this run): `../../BRIEF.md`",`Working (this run): the files in ${e.repos} that \`BRIEF.md\` names, and their callers`],doNotLoad:"`_shared/standards.md` (nothing is written here), other stages' contracts, `.werkmeister/*.yml`.",process:["List the files in scope and every caller outside it.","State the invariants: observable behaviour that must be identical after the refactor.","Name the existing tests that pin each invariant, and the gaps no test covers.",`Write \`output/scope.md\`: steps 1\u20133, the sequence of small steps you propose${e.group.length?` under one heading per ticket key (the workspace's issue, then ${yh(e.group)})`:""}, and a \`status: proposed\` line.`],outputs:["`output/scope.md`"],humanCheck:`Read \`output/scope.md\`. Correct the scope or invariants, then change \`status: proposed\` to \`status: decided\`. That is the approval \u2014 the next session starts without asking again. ${wo}`}),"contract")},{name:"implement",job:"refactor in green steps",gate:"review.md",writes:"code diff, `output/exercise.md`, `output/review.md`",check:"read the diff and `review.md`; tests green at every step",enter:"`stages/01_scope/output/scope.md` reads `status: decided` \u2014 the flip *is* the approval, do not ask again",standards:"all",contract:i(e=>({oneJob:"One job: carry out the steps `scope.md` settled, keeping every invariant true after each one.",inputs:[`Working (this run): \`${e.at("scope")}/output/scope.md\` \u2014 must read \`status: decided\``,"Working (this run): the files in scope","Reference (every run): `../../.werkmeister/werkmeister-context.md` \u2014 test command"],doNotLoad:"`BRIEF.md` (`scope.md` carries the settled scope), `.werkmeister/*.yml`, other stages.",process:[...e1,...s1(e),"First add a test for each invariant gap `scope.md` named. They must pass before any code moves.",`${e.group.length?"For each ticket, take its `scope.md` steps in order, then commit it before the next ticket; do not commit after every step. After each step":"Take the steps in order. After each one"}: ${t1("scope.md")} ${a5}`,d5(e),c5,l5,`After the last step, reload and exercise the service: ${e.restart}. ${Q$} ${Z$}`,`Write \`output/exercise.md\`: \`git diff --stat\` per repo, the test result after each step, the \`pr gate --tests\` exit code, ${n1}, and the final exercise checks as ${o1("evidence")}.`,r1],outputs:[e.group.length?"Code changes, one commit per ticket (`<KEY> \u2026`)":"Code changes, uncommitted","`output/exercise.md`",`\`output/review.md\`: a \`| criterion | result | evidence |\` table, result exactly \`PASS\` or \`FAIL\`${xh}`],humanCheck:wh("review.md",`Read the diff against \`scope.md\`. Anything outside scope goes back.${e.group.length?" Read it per commit: `git log -p origin/main..HEAD`.":""}`)}),"contract")},i1],dce=[{name:"questions",job:"frame what the spike must answer",writes:"`output/questions.md`",check:"agree the questions and what settles them",standards:"none",contract:i(()=>({oneJob:"One job: turn the brief into questions, each with the evidence that would settle it. No code is written in this stage.",inputs:["Working (this run): `../../BRIEF.md`"],doNotLoad:"source trees, `_shared/standards.md`, `.werkmeister/*.yml`.",process:["List the questions the brief asks or implies, most decision-relevant first.","For each: how it will be answered (read code, measure, prototype) and what result settles it.","Write `output/questions.md`: steps 1\u20132 and a `status: proposed` line."],outputs:["`output/questions.md`"],humanCheck:`Edit the questions, then change \`status: proposed\` to \`status: decided\`. That is the approval \u2014 the next session starts without asking again. ${wo}`}),"contract")},{name:"findings",job:"answer them with evidence",writes:"`output/findings.md`",check:"decide the next piece of work",enter:"`stages/01_questions/output/questions.md` reads `status: decided` \u2014 the flip *is* the approval, do not ask again",standards:"none",contract:i(e=>({oneJob:"One job: answer each settled question with evidence, and recommend what to build next.",inputs:[`Working (this run): \`${e.at("questions")}/output/questions.md\` \u2014 must read \`status: decided\``,`Working (this run): whatever each question's method names, in ${e.repos}`,"Reference (every run): `../../.werkmeister/werkmeister-context.md` \u2014 ports, containers","Reference (when the brief asks for a repo deliverable): `../../_shared/pr-rules.md` \u2014 the PR file format and the gate"],doNotLoad:"`_shared/standards.md` (prototype code is throwaway), `.werkmeister/*.yml`.",process:["Answer each question by its method. Prototype code lives in `output/` or on a scratch branch, never on the workspace branch.","Write `output/findings.md`: per question, the answer, the evidence (commands and output), and confidence.","End `findings.md` with a recommendation: the next work item and its work type.","If the brief asks for a deliverable in a code repo (e.g. a doc opened as a PR): commit it on that worktree's branch, and write `output/pr-<worktree>.md` in the format of `_shared/pr-rules.md` at `status: draft`, with `repo:` taken from `git -C <worktree> remote get-url origin` (as `owner/repo`; the gate rejects any other value), an acceptance table and `skip_exercise: <reason>` when there is nothing to exercise."],outputs:["`output/findings.md`","`output/pr-<worktree>.md` per repo \u2014 only when the brief asks for a repo deliverable"],humanCheck:"Read `findings.md`. The recommendation becomes the brief of the next workspace, or the spike ends here. If there is a `pr-*.md`, set `status: approved`; `werkmeister pr open` runs the gate and opens it, and close-out waits for it to ship. Otherwise, when the recommendation is recorded where it is needed, the post-mortem (`postmortem` skill), then `werkmeister workspace close`."}),"contract")}],X$={feature:uce,bugfix:s5,incident:s5,refactor:fce,spike:dce};i(sf,"templateFor");i(js,"stageDirs");i(a1,"proposeDir");i(jw,"prDir")});function Xc(e){let t=e.url?`[${e.ref}](${e.url})`:e.ref,r=e.title?`: ${e.title}`:"",n=e.fetchedAt?`Copy taken ${e.fetchedAt.slice(0,10)}: \`.werkmeister/issue.md\`.`:"No stored copy; run `werkmeister workspace init --refresh-issue`.";return["## Issue","",`${t}${r}. ${n}`,"Before each stage, re-read the live issue for newer direction: `werkmeister issue view`","Its status moves by itself (In Progress \u2192 In Review \u2192 Done): `docs/workspace-lifecycle.md` \xA7 Issue status in the werkmeister repo.",""].join(`
622
+ `);return{slug:d,body:m}})}function J$(e,t){return gi.relative(e,t.path)}var Nw,rce,nce,sce,t5,r5=A(()=>{"use strict";h();Nw=Oe(Ye(),1);Kr();rce=/^status:\s*decided\b/,nce=/^(#{1,6})\s+(.+?)\s*#*$/,sce=/^\s*(```|~~~)/;i(e5,"statePath");i(Z4,"readState");i(oce,"slugify");i(ice,"outputFiles");i(ace,"decidedSections");i(J$,"decisionId");t5={open(e){let t=Z4(e),r=[],n=0;for(let s of ice(e)){let o=ace(xo.readFileSync(s,"utf8"),gi.basename(s,".md"));for(let{slug:a,body:c}of o){n+=1;let l={path:`${s}#${a}`,number:n,type:"decision",slug:a,frontmatter:{},body:c},u=t[J$(e,l)]??{};l.frontmatter={type:"decision",status:"decided",refs:[],...u},!["graduated","superseded"].includes(l.frontmatter.status)&&r.push(l)}}return r},mark(e,t,r){let n=Z4(e),s=J$(e,t);n[s]={...n[s],...r},xo.mkdirSync(W(e),{recursive:!0}),xo.writeFileSync(e5(e),Nw.stringify(n))},cite:i((e,t)=>`decision ${String(t.number).padStart(3,"0")}, see ${J$(e,t)}`,"cite")}});function sf(e){let t=e.trim().toLowerCase();return Object.hasOwn(X$,t)?X$[t]:X$.feature}function js(e){return e.map((t,r)=>`${String(r+1).padStart(2,"0")}_${t.name}`)}function a1(e){let t=e.findIndex(r=>r.name==="propose");return t<0?null:js(e)[t]}function jw(e){return a1(e)??js(e)[e.length-1]}var Q$,Z$,e1,o5,i5,cce,a5,c5,l5,t1,r1,n1,yh,u5,s1,lce,f5,d5,p5,wh,xh,h5,m5,o1,n5,i1,uce,s5,fce,dce,X$,c1=A(()=>{"use strict";h();An();Cw();Q$="If the container is not running, run `werkmeister feature up` once first; `docker restart` only reloads one that is already running. Never run `werkmeister feature restart` or `werkmeister workspace init` to reload \u2014 they are slower, and init rewrites the stage contracts.",Z$="A library or CLI has no service to restart: build it, then exercise the built artifact exactly as its Validation text in `werkmeister-context.md` \xA7 How to validate says.",e1=["Confirm ponytail is active (see `_shared/standards.md`; invoke the skill only if it is not), then read the standards rows above. Restate the rule you are applying beside each edit."],o5="If the repo uses biome (`biome.json` or `biome.jsonc`), first run `pnpm exec biome check --write <the files you touched>` (never a folder), so formatting lands in the ticket's own commit. 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 \u2014 never hand-roll `HOME=\u2026`. That run is on the host, without the container's env (`HOST`, `WERKMEISTER_SLOT`, `NODE_ENV`, `<SVC>_URL`, \u2026), and the PR gate runs the same commands in the workspace container. 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. ",i5='A subagent you brief to run tests or the CLI gets that wrapped command verbatim in its brief. 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). Redirect output to a file as one group, so every command in an `&&` chain lands there. For a background job (`run_in_background`) write background: `{ <test command>; } > <log> 2>&1` and read the exit code from the job\'s completion notice; for a foreground call write foreground: `{ <test command>; } > <log> 2>&1; echo "exit $?"`. Read back only the failing slice.',cce=o5+"Once it passes, run `werkmeister pr gate --tests` (from the workspace, detached when it may pass 10 minutes) and fix what it fails; record both exit codes. "+i5,a5=`${o5}Record its exit code. ${i5}`,c5="Once the review's fixes are in, run `werkmeister pr gate --tests` (from the workspace, detached when it may pass 10 minutes) and fix what it fails; record its exit code. A fix here reruns the host test step first.",l5="If the exercise below changes code, rerun the review on that delta: a fresh subagent with the same brief, over the commits and changes made since the first review. Fix its **Must fix** findings, rerun the host test step, and append the result as new rows to `output/review.md`; the gate's review row covers them.",t1=i(e=>`Before running tests, read \`git diff\` in each repo you touched and tick off each edit \`${e}\` settled against it: an edit reported as applied can be missing.`,"diffCheck"),r1="Before asking for approval, list the exercise rows only a person can run (a real VS Code window, a device, a browser). Ask the person for each one's result, one question per row (pass / fail / not run), and write the answer into `exercise.md`: PASS or FAIL in the table, and for a row not run a `MANUAL: not run (person's reason)` line under it (the table's result cell stays PASS or FAIL). An approval that skips this keeps those rows MANUAL, and the PR file says why.",n1="every skipped test by name with its skip reason and where it ran instead",yh=i(e=>e.map(t=>`\`${t}\``).join(", "),"keys"),u5="`git commit --fixup <sha>`, then `git rebase --autosquash $(git merge-base HEAD origin/main)`",s1=i(e=>e.group.length?[`This workspace is a grouped PR (\`group\` in \`workspace.yml\`): one commit per ticket, for the workspace's issue and each member, ${yh(e.group)}, so each can be reverted alone. Take the tickets one at a time: make that ticket's changes and tests, run the diff check below on them, then commit on the worktree's branch with a message that starts with its key (\`<KEY> <summary>\`) before starting the next. Each commit builds and passes the host tests on its own. A ticket that changes a released package carries its release entry (changeset) in its own commit. When a ticket's change alters a generated snapshot (e.g. \`strategy-jit.snapshot.json\`), regenerate it in that ticket's commit, so the commit passes the snapshot test alone; a brief that says to regenerate once for the whole PR does not override this. Commit order across tickets is free; a ticket whose change depends on another's evidence (a measurement) can come last. Never reorder commits to match the spec.`]:[],"groupStep"),lce="a `| criterion | result | evidence |` table whose result cell is exactly `PASS` or `FAIL` \u2014 nothing else in the cell \u2014 with the proof in the evidence column",f5=i((e,t)=>`Review the diff: for each code worktree you touched, start a fresh subagent and brief it with only the worktree path and "run the \`ponytail:ponytail-review\` skill over this worktree's ${t.length?"commits in `origin/main...HEAD` (the PR's base in place of `main` when it differs), plus any uncommitted changes and untracked files":"uncommitted changes, untracked files included"}" \u2014 not how you built it, so the review is not anchored on your reasoning. If the change adds or widens an allow rule or another pre-approved command, add to the brief: "this change pre-approves a command: list every file, env var, network address or process it can reach from its arguments, and treat each that leaves the workspace or its temp HOME as Must fix". Always add: "any finding where the change can restart or write the host daemon, the real \`~/.werkmeister\` or another workspace, whether through an allow rule, a script or a test, is Must fix". Fix every **Must fix** finding in place, and any **Should fix** finding that shows the change's own docs, comments, help text or changeset state something false (fix the code, or reword that text so it is true), ${t.length?`fold each fix into the commit of the ticket it belongs to (${u5}), `:""}then ${e}. Leave the other **Should fix** and **Nice to have** findings as they are. Write \`output/review.md\`: per worktree, the findings as the review grouped them, each marked \`fixed\` or \`left: <why>\`, then ${lce}, with one row per worktree (\`PASS\` means no Must fix left open). 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\`.`,"reviewStep"),d5=i(e=>f5("rerun the host test step above",e.group),"implementReview"),p5='For each decision that renames, keeps or removes a name, a fallback or an alias, record its definition site (file and line) and the commit that introduced it (`git log -S <name>`, in the repo that defines it). When that commit marks it as a transition or legacy alias, list "remove" as an option beside rename and keep.',wh=i((e,t)=>`${t} Then change \`status: proposed\` at the top of \`output/${e}\` to \`status: decided\`: that flip is the approval, and the next session starts without asking again. ${wo}`,"statusGate"),xh=", its first line `status: proposed`",h5=i(e=>e?`Ask this check through \`${e}\`: at most 4 questions per call (more than 4: batches of 4, one call after another), each standing on its own (what was checked, 2\u20133 concrete options with the exact wording or behaviour, the recommended one first; "Other" takes edits). Write each answer into the output file as its status, noted \`${mi.chat}\` (a PR file: \`${mi.chatPr}\`). A check left as a sentence at the end of a reply is not asked.`:`Ask this check as one numbered block at the end of your reply: each question stands on its own, options lettered with the recommended one first, then "reply with the letters, or your edits". Write each answer into the output file as its status, noted \`${mi.chat}\` (a PR file: \`${mi.chatPr}\`).`,"askLine"),m5="Review `output/` once against `../../BRIEF.md` and the live issue (`werkmeister issue view`). Flip every `status: proposed` to `status: decided` yourself, and record each decision \u2014 and anything you would have asked a person \u2014 under `## Recommendations for reviewer` in the PR body. Then start the next stage without asking.",o1=i(e=>`a \`| check | result | ${e} |\` table whose result cell is exactly \`PASS\` or \`FAIL\` \u2014 nothing else in the cell \u2014 with the captured output in the ${e} column. The rule holds for every table in \`exercise.md\`; describe a superseded run in prose, not as a \`FAIL\` row`,"exerciseFormat"),n5="the repo's lint command (the `&& <lint>` tail 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.",i1={name:"propose",job:"acceptance walk and PR files",writes:"the code commits (one per repo, or one per ticket in a grouped PR), `output/pr-<worktree>.md` per repo",check:"approve each PR file; `werkmeister pr open` opens it",standards:"none",contract:i(e=>({oneJob:`One job: prove each acceptance criterion, ${e.group.length?"check the per-ticket commits in":"commit in"} each code worktree, and write one PR file per repo touched. ${e.autonomous?"You approve it after the self-check":"Approving is the person's act"}; opening is \`werkmeister pr open\`.`,inputs:["Working (this run): `../../BRIEF.md` \xA7 Acceptance criteria","Working (this run): `../*/output/` \u2014 every prior stage's artifacts","Working (this run): `git status` and `git diff --stat` in each repo you touched","Reference (every run): `../../_shared/pr-rules.md` \u2014 the PR file format and the gate"],doNotLoad:"`_shared/standards.md` (no code is written here), source files, `.werkmeister/`.",process:["Walk every acceptance criterion in `BRIEF.md`. For each, write a row whose result cell is exactly PASS or FAIL (MANUAL for a criterion only the reviewer can check, e.g. it needs a real PR or the desktop app, with why in the evidence; never PASS for a check nobody ran), with the file and line in a prior `output/` that proves it in a separate evidence column. A FAIL routes back to the owning stage \u2014 do not fix it here.",e.group.length?`The commits are already made, one per ticket: keep them, never squash to one per repo. For a repo with \`ship: tag\` and a \`release_check\` in the registry, write the release entry it needs (e.g. a changeset). Run ${n5} Then fold everything uncommitted into its ticket's commit (${u5}), each ticket's release entry into that ticket's own commit, and check that \`git log --oneline origin/main..HEAD\` in each worktree shows one commit per ticket (the workspace's issue and ${yh(e.group)}), each message starting with its key.`:`In each code worktree you touched (\`git -C <repo>\`), commit on its branch with a message that names the change, not the stage. For a repo with \`ship: tag\` and a \`release_check\` in the registry, add the release entry it needs (e.g. a changeset) in the same commit. Before committing, run ${n5}`,"Before the PR file: for each follow-up a decided question in `decisions.md` promises, file it through `../../_shared/issues-report.md` and write its issue key beside that decision. The gate's follow-ups check stays as the backstop.","Write `output/pr-<worktree>.md` per repo touched, in the format of `_shared/pr-rules.md`, at `status: draft`, with `repo:` taken from `git -C <worktree> remote get-url origin` (as `owner/repo`; the gate rejects any other value). Title: `<type>(<scope>): <ISSUE-ID> <summary>`. Body: summary, the test and exercise results from prior outputs (every table with a `result` column \u2014 the gate reads them all \u2014 has a result cell of exactly `PASS` and the output in its own column: a FAIL cell anywhere in the PR file stops the PR, so describe a pre-fix reproduction in prose, not as a FAIL row), the acceptance table from step 1, and `Fixes <issue>` when the tracker is GitHub."+(e.group.length?" Start the body with `Rebase and merge, not squash: one commit per ticket, each revertable alone.` and list each member under the summary.":""),"Commit and push this folder's branch \u2014 the record. Never open a PR for it."],outputs:[e.group.length?"The per-ticket commits, kept, on each worktree's branch":"One commit per code repo touched, on that worktree's branch","`output/pr-<worktree>.md` per repo"],humanCheck:`Read each \`pr-*.md\`. Set \`status: approved\` on each one to open \u2014 that flip is the approval. Then \`werkmeister pr open\`, run detached as \`_shared/pr-rules.md\` rule 3 shows, runs the gate and opens it. Merging is yours. After the release, \`werkmeister pr status\`, then ${e.group.length?`check each member reads Done \u2014 \`werkmeister issue view <KEY>\` for ${yh(e.group)}; \`pr status\` moves them with the workspace's issue, so move one by hand only if it didn't \u2014 then `:""}the post-mortem (\`postmortem\` skill), then ask the person before \`werkmeister workspace close\`. Code written after a PR merged (e.g. found at release) is a follow-up: \`werkmeister pr new <worktree> --slug <slug>\`. ${wo}`,selfCheck:"Review each `pr-*.md` once against `../../BRIEF.md` and the live issue. Add `## Recommendations for reviewer` to its body \u2014 every decision and question collected on the way \u2014 then set `status: approved` yourself and run `werkmeister pr open` detached, as `_shared/pr-rules.md` rule 3 shows. Stop at the PR URL. Merging is the person's."+(e.group.length?` When the PR ships, check each member reads Done (\`werkmeister issue view <KEY>\` for ${yh(e.group)}) before the post-mortem; \`pr status\` moves them with the workspace's issue, so move one by hand only if it didn't.`:"")}),"contract")},uce=[{name:"research",job:"inventory the code, surface decisions",writes:"`output/inventory.md`, `output/decisions.md`",check:"answer every open question in `decisions.md`",standards:"none",contract:i(e=>({oneJob:"One job: establish what the code the brief touches does today, and turn the brief's open questions into an editable decision sheet. No code is written in this stage.",inputs:["Working (this run): `../../BRIEF.md`",`Working (this run): the files in ${e.repos} that \`BRIEF.md\` names \u2014 grep for call sites, don't read whole trees`],doNotLoad:`\`_shared/standards.md\` (nothing is written here), other stages' contracts, \`.werkmeister/*.yml\`, \`${be}\`.`,process:['List what exists that the brief touches: entry points, routes or exports, data shapes, and the tests that cover them. For each module the change adds an export to, grep the tests for whole-module mocks of it (e.g. `vi.mock("<module>"`, `mock.module`) and list every hit as a fixture the change must update. For each value the change alters (a string, a default, a command), grep tests and fixtures for that exact value and list the hits; never write that no test covers it without that grep.',"Find the test command in `../../.werkmeister/werkmeister-context.md` and copy it verbatim \u2014 do not restate it from memory.","Check what is already installed that could do the job before recommending anything new.","Write `output/inventory.md`: steps 1\u20133.",p5,"Write `output/decisions.md`: every open question in `BRIEF.md`, each as a heading with `status: proposed`, your recommended answer, and the evidence from steps 1\u20133 and 5. Leave the answer blank when only a person can give it (a ticket key, a preference)."],outputs:["`output/inventory.md`","`output/decisions.md`"],humanCheck:`Open \`output/decisions.md\`. Edit each answer as needed and change its \`status: proposed\` to \`status: decided\`. The next stage must not start while any question is still \`proposed\`. When every question reads \`decided\`, that is the approval \u2014 the next session starts the next stage without asking for confirmation. ${wo}`}),"contract")},{name:"spec",job:"write the spec for the change",gate:"spec.md",writes:"`output/spec.md`, any checkable artifact in the repo",check:"the spec covers every acceptance criterion",enter:"every question in `stages/01_research/output/decisions.md` reads `status: decided` \u2014 the flip *is* the approval, do not ask again",standards:"all",contract:i(e=>({oneJob:"One job: turn the settled decisions into a spec precise enough that the next stage needs no judgment calls, and prove any machine-checkable part of it.",inputs:[`Working (this run): \`${e.at("research")}/output/inventory.md\``,`Working (this run): \`${e.at("research")}/output/decisions.md\` \u2014 every entry must read \`status: decided\`; if not, stop and route back to that stage's human check`,"Reference (every run): `../../BRIEF.md` \xA7 Acceptance criteria"],doNotLoad:"source files already summarised in `inventory.md` (if it looks wrong, fix `inventory.md` and tell the person), `.werkmeister/*.yml`, other stages.",process:[`Write \`output/spec.md\`: what changes, file by file; the interfaces or schemas added; the tests that will prove it; what is explicitly out of scope.${e.group.length?" This is a grouped PR: list one commit per ticket (`<KEY> \u2026`) and what each holds, but do not fix their order.":""}`,"If the change has a machine-checkable artifact (a schema, an API document, a migration), write it in the repo and validate it with a command that needs no new dependency. Record the exact command in `spec.md`.","Map each acceptance criterion in `BRIEF.md` to the step or test in `spec.md` that satisfies it. A criterion with no mapping is a defect in this stage.","Load every `_shared/standards.md` row whose Applies-when matches a file `spec.md` changes, not only the universal ones. Under `## Conflicts` in `spec.md`, write one line per place the ticket's proposed shape breaks a loaded standard (the rule, and the shape that would satisfy it), or `none`.","In `spec.md`, answer: how does an existing user turn this on? Name the setup or config path (a setup command, a config key or file) and the doc that describes it, or say none is needed. Map the answer to a criterion as in step 3; a missing answer is a defect in this stage."],outputs:[`\`output/spec.md\`${xh}`,"Any artifact from step 2, in the repo"],humanCheck:wh("spec.md","Read `output/spec.md` against the brief. Edit it directly \u2014 the next stage builds whatever is on disk.")}),"contract")},{name:"implement",job:"build it and prove it",gate:"review.md",writes:"code diff, `output/exercise.md`, `output/review.md`",check:"read the diff and `review.md`; tests green",standards:"all",contract:i(e=>({oneJob:"One job: make the changes `spec.md` lists, add the tests it names, and prove them against the running service.",inputs:[`Working (this run): \`${e.at("spec")}/output/spec.md\` and the files it names`,`Working (this run): \`${e.at("research")}/output/decisions.md\``,"Reference (every run): `../../.werkmeister/werkmeister-context.md` \u2014 container names, published ports, test command"],doNotLoad:`\`BRIEF.md\` (\`decisions.md\` and \`spec.md\` carry the settled scope), \`inventory.md\`, \`.werkmeister/*.yml\`, \`${be}\`, other stages.`,process:[...e1,...s1(e),"Make the changes `spec.md` lists, and only those. No new runtime dependency unless `decisions.md` justified one in a line.","Add the tests `spec.md` names. Match the style of the nearest existing test; no new test framework.",t1("spec.md"),a5,d5(e),c5,l5,`Reload the running code: ${e.restart}. ${Q$} Then exercise the change as the How-to-validate section of \`werkmeister-context.md\` describes for each service touched, and capture the output. ${Z$}`,`Write \`output/exercise.md\`: \`git diff --stat\` for each repo you touched, the host and \`pr gate --tests\` exit codes and summary lines, ${n1}, any deviation from \`spec.md\` with its reason, and the exercise checks as ${o1("evidence")}.`,r1],outputs:[e.group.length?"Code changes, one commit per ticket (`<KEY> \u2026`), on the worktree's branch \u2014 the next stage keeps them":"Code changes, uncommitted \u2014 the next stage commits after the person reads the diff","`output/exercise.md`",`\`output/review.md\`: a \`| criterion | result | evidence |\` table, result exactly \`PASS\` or \`FAIL\`${xh}`],humanCheck:wh("review.md",e.group.length?"Read each ticket's commit (`git log -p origin/main..HEAD` in each worktree) and `review.md`. Run the tests yourself. Edit the code in place if something is off and fold it into that ticket's commit \u2014 the next stage keeps the commits as they are.":"Read the diff and `review.md`. Run the tests yourself. Edit the code in place if something is off \u2014 the next stage commits what is on disk.")}),"contract")},i1],s5=[{name:"reproduce",job:"reproduce and locate the root cause",writes:"`output/repro.md`",check:"agree the root cause",standards:"none",contract:i(e=>({oneJob:"One job: make the failure happen on demand and name its root cause. No fix is written in this stage.",inputs:["Working (this run): `../../BRIEF.md`",`Working (this run): the files in ${e.repos} on the failing path \u2014 follow the call chain, don't read whole trees`,"Reference (every run): `../../.werkmeister/werkmeister-context.md` \u2014 container names, published ports, logs, test command"],doNotLoad:"`_shared/standards.md` (nothing is written here), other stages' contracts, `.werkmeister/*.yml`.",process:["Reproduce the failure against the running service or with a test. Record the exact command and its output. Judge each run by its exit code, or by a check you have shown fails on a known-bad run \u2014 never by grepping the output for a line that may not be printed.","Write the smallest failing test that captures it, in the style of the nearest existing test. Do not commit it yet.","Trace to the root cause: the first place the code does something other than intended. A symptom site is not a root cause.","List every other caller of the function at the root cause and what each does with the result (an early return, a printed value, a stored state), so the fix's return shape is checked against every caller before the fix stage \u2014 a fix there reaches them too. When the fix belongs in shared code, list its call sites through every helper or entry point that reaches that code, not one argument shape, and record the search commands (greps) you used in `repro.md`.","When the proposed fix branches on a predicate, list each condition that makes it true and give each one a test.",p5,"When the root cause is a permission rule (allow, deny, ask), step 4 lists every source of a matching rule: each builder, each rule derived from a registered command (its `&&` segments included), rules recorded in existing workspaces and how a refresh or migrate removes them, and the list a headless wake passes (`--allowedTools` / `--disallowedTools`). The failing test probes each source.","Write `output/repro.md`: steps 1\u20137, and a proposed fix in one paragraph under a `status: proposed` line."],outputs:["`output/repro.md`","One failing test, uncommitted"],humanCheck:`Read \`output/repro.md\`. Correct the root cause or the proposed fix if needed, then change \`status: proposed\` to \`status: decided\`. That is the approval \u2014 the next session starts the fix without asking again. ${wo}`}),"contract")},{name:"fix",job:"fix it at the root cause",gate:"fix.md",writes:"code diff, `output/fix.md`",check:"read the diff; the failing test now passes",enter:"`stages/01_reproduce/output/repro.md` reads `status: decided` \u2014 the flip *is* the approval, do not ask again",standards:"all",contract:i(e=>({oneJob:"One job: make the failing test pass by changing the code at the root cause, and nothing else.",inputs:[`Working (this run): \`${e.at("reproduce")}/output/repro.md\` \u2014 must read \`status: decided\`; if not, stop and route back`,"Working (this run): the failing test and the files at the root cause","Reference (every run): `../../.werkmeister/werkmeister-context.md` \u2014 test command"],doNotLoad:"`BRIEF.md` (`repro.md` carries the settled scope), `.werkmeister/*.yml`, other stages.",process:[...e1,...s1(e),"Apply the fix `repro.md` settled, at the root cause. Every caller `repro.md` lists gets the fix through the shared function \u2014 do not patch callers one by one.",t1("repro.md"),cce,`Write \`output/fix.md\`: \`git diff --stat\` per repo, the failing test's name, the test exit code and summary line, and ${n1}.`],outputs:[e.group.length?"Code changes plus the test, one commit per ticket":"Code changes plus the test, uncommitted",`\`output/fix.md\`${xh}`],humanCheck:wh("fix.md",`${e.group.length?"Read each ticket's commit (`git log -p origin/main..HEAD`)":"Read the diff"}. Confirm the fix sits where \`repro.md\` put the root cause. Edit in place if not.`)}),"contract")},{name:"exercise",job:"prove it against the running service or the built CLI",gate:"review.md",writes:"`output/exercise.md`, `output/review.md`",check:"the original reproduction no longer fails",standards:"all",contract:i(e=>({oneJob:"One job: show the original failure is gone in the running service or the built binary, not just in the test. Then review the diff and fix what must be fixed.",inputs:[`Working (this run): \`${e.at("reproduce")}/output/repro.md\` \u2014 the reproduction steps`,`Working (this run): \`${e.at("fix")}/output/fix.md\``,"Reference (every run): `../../.werkmeister/werkmeister-context.md` \u2014 container names, published ports, test command"],doNotLoad:"`BRIEF.md` (`repro.md` carries the settled scope), `.werkmeister/*.yml`.",process:[`Reload the running code: ${e.restart}. ${Q$} ${Z$}`,"Rerun the reproduction steps from `repro.md` exactly. Capture the output.","Exercise one neighbouring path through each caller `repro.md` listed. Capture the output.",`Write \`output/exercise.md\`: steps 2\u20133 as ${o1("detail")}.`,f5("rerun the test command exactly as `../../.werkmeister/werkmeister-context.md` states it (through `.werkmeister/bin/with-temp-home`), rerun steps 2\u20133 and update `exercise.md`",e.group),r1],outputs:["`output/exercise.md`",`\`output/review.md\`: a \`| criterion | result | evidence |\` table, result exactly \`PASS\` or \`FAIL\`${xh}`,e.group.length?"Code changes from Must fix findings, folded into their tickets' commits":"Code changes from Must fix findings, uncommitted"],humanCheck:wh("review.md","Read `exercise.md` and `review.md`. A FAIL sends the run back to the fix stage.")}),"contract")},i1],fce=[{name:"scope",job:"fix the boundary and the invariants",writes:"`output/scope.md`",check:"agree what must not change",standards:"none",contract:i(e=>({oneJob:"One job: pin down what the refactor may touch and what behaviour must not change. No code is written in this stage.",inputs:["Working (this run): `../../BRIEF.md`",`Working (this run): the files in ${e.repos} that \`BRIEF.md\` names, and their callers`],doNotLoad:"`_shared/standards.md` (nothing is written here), other stages' contracts, `.werkmeister/*.yml`.",process:["List the files in scope and every caller outside it.","State the invariants: observable behaviour that must be identical after the refactor.","Name the existing tests that pin each invariant, and the gaps no test covers.",`Write \`output/scope.md\`: steps 1\u20133, the sequence of small steps you propose${e.group.length?` under one heading per ticket key (the workspace's issue, then ${yh(e.group)})`:""}, and a \`status: proposed\` line.`],outputs:["`output/scope.md`"],humanCheck:`Read \`output/scope.md\`. Correct the scope or invariants, then change \`status: proposed\` to \`status: decided\`. That is the approval \u2014 the next session starts without asking again. ${wo}`}),"contract")},{name:"implement",job:"refactor in green steps",gate:"review.md",writes:"code diff, `output/exercise.md`, `output/review.md`",check:"read the diff and `review.md`; tests green at every step",enter:"`stages/01_scope/output/scope.md` reads `status: decided` \u2014 the flip *is* the approval, do not ask again",standards:"all",contract:i(e=>({oneJob:"One job: carry out the steps `scope.md` settled, keeping every invariant true after each one.",inputs:[`Working (this run): \`${e.at("scope")}/output/scope.md\` \u2014 must read \`status: decided\``,"Working (this run): the files in scope","Reference (every run): `../../.werkmeister/werkmeister-context.md` \u2014 test command"],doNotLoad:"`BRIEF.md` (`scope.md` carries the settled scope), `.werkmeister/*.yml`, other stages.",process:[...e1,...s1(e),"First add a test for each invariant gap `scope.md` named. They must pass before any code moves.",`${e.group.length?"For each ticket, take its `scope.md` steps in order, then commit it before the next ticket; do not commit after every step. After each step":"Take the steps in order. After each one"}: ${t1("scope.md")} ${a5}`,d5(e),c5,l5,`After the last step, reload and exercise the service: ${e.restart}. ${Q$} ${Z$}`,`Write \`output/exercise.md\`: \`git diff --stat\` per repo, the test result after each step, the \`pr gate --tests\` exit code, ${n1}, and the final exercise checks as ${o1("evidence")}.`,r1],outputs:[e.group.length?"Code changes, one commit per ticket (`<KEY> \u2026`)":"Code changes, uncommitted","`output/exercise.md`",`\`output/review.md\`: a \`| criterion | result | evidence |\` table, result exactly \`PASS\` or \`FAIL\`${xh}`],humanCheck:wh("review.md",`Read the diff against \`scope.md\`. Anything outside scope goes back.${e.group.length?" Read it per commit: `git log -p origin/main..HEAD`.":""}`)}),"contract")},i1],dce=[{name:"questions",job:"frame what the spike must answer",writes:"`output/questions.md`",check:"agree the questions and what settles them",standards:"none",contract:i(()=>({oneJob:"One job: turn the brief into questions, each with the evidence that would settle it. No code is written in this stage.",inputs:["Working (this run): `../../BRIEF.md`"],doNotLoad:"source trees, `_shared/standards.md`, `.werkmeister/*.yml`.",process:["List the questions the brief asks or implies, most decision-relevant first.","For each: how it will be answered (read code, measure, prototype) and what result settles it.","Write `output/questions.md`: steps 1\u20132 and a `status: proposed` line."],outputs:["`output/questions.md`"],humanCheck:`Edit the questions, then change \`status: proposed\` to \`status: decided\`. That is the approval \u2014 the next session starts without asking again. ${wo}`}),"contract")},{name:"findings",job:"answer them with evidence",writes:"`output/findings.md`",check:"decide the next piece of work",enter:"`stages/01_questions/output/questions.md` reads `status: decided` \u2014 the flip *is* the approval, do not ask again",standards:"none",contract:i(e=>({oneJob:"One job: answer each settled question with evidence, and recommend what to build next.",inputs:[`Working (this run): \`${e.at("questions")}/output/questions.md\` \u2014 must read \`status: decided\``,`Working (this run): whatever each question's method names, in ${e.repos}`,"Reference (every run): `../../.werkmeister/werkmeister-context.md` \u2014 ports, containers","Reference (when the brief asks for a repo deliverable): `../../_shared/pr-rules.md` \u2014 the PR file format and the gate"],doNotLoad:"`_shared/standards.md` (prototype code is throwaway), `.werkmeister/*.yml`.",process:["Answer each question by its method. Prototype code lives in `output/` or on a scratch branch, never on the workspace branch.","Write `output/findings.md`: per question, the answer, the evidence (commands and output), and confidence.","End `findings.md` with a recommendation: the next work item and its work type.","If the brief asks for a deliverable in a code repo (e.g. a doc opened as a PR): commit it on that worktree's branch, and write `output/pr-<worktree>.md` in the format of `_shared/pr-rules.md` at `status: draft`, with `repo:` taken from `git -C <worktree> remote get-url origin` (as `owner/repo`; the gate rejects any other value), an acceptance table and `skip_exercise: <reason>` when there is nothing to exercise."],outputs:["`output/findings.md`","`output/pr-<worktree>.md` per repo \u2014 only when the brief asks for a repo deliverable"],humanCheck:"Read `findings.md`. The recommendation becomes the brief of the next workspace, or the spike ends here. If there is a `pr-*.md`, set `status: approved`; `werkmeister pr open` runs the gate and opens it, and close-out waits for it to ship. Otherwise, when the recommendation is recorded where it is needed, the post-mortem (`postmortem` skill), then `werkmeister workspace close`."}),"contract")}],X$={feature:uce,bugfix:s5,incident:s5,refactor:fce,spike:dce};i(sf,"templateFor");i(js,"stageDirs");i(a1,"proposeDir");i(jw,"prDir")});function Xc(e){let t=e.url?`[${e.ref}](${e.url})`:e.ref,r=e.title?`: ${e.title}`:"",n=e.fetchedAt?`Copy taken ${e.fetchedAt.slice(0,10)}: \`.werkmeister/issue.md\`.`:"No stored copy; run `werkmeister workspace init --refresh-issue`.";return["## Issue","",`${t}${r}. ${n}`,"Before each stage, re-read the live issue for newer direction: `werkmeister issue view`","Its status moves by itself (In Progress \u2192 In Review \u2192 Done): `docs/workspace-lifecycle.md` \xA7 Issue status in the werkmeister repo.",""].join(`
623
623
  `)}var Lw=A(()=>{"use strict";h();i(Xc,"renderIssueRef")});import*as vr from"node:fs";import*as Yt from"node:path";function l1(e){return(e??"").split(",").map(t=>t.trim()).filter(t=>t)}function w5(e,t){let r=js(t),n;try{n=vr.readdirSync(Yt.join(e,"stages")).filter(s=>/^\d+_/.test(s))}catch{return[]}return n.filter(s=>!r.includes(s)).sort()}function hce(e,t){let[r]=Nn(),n=i(c=>vu.includes(r[c]?.type??""),"isIdle"),s=i(c=>c.map(l=>`\`${e}-${l}\``).join(", "),"names"),o=t.filter(c=>!n(c)),a=t.filter(n);return[o.length?o.map(c=>`\`docker restart ${e}-${c}\``).join(", "):"",a.length?`${s(a)} run no watcher, so a restart rebuilds nothing: build and test inside them with \`docker exec\` as \`.werkmeister/werkmeister-context.md\` \xA7 Test commands shows`:""].filter(Boolean).join("; ")}function x5(e,t){let r=js(t),n=(e.meta.FEATURE??"").trim(),s=l1(e.meta.SERVICES),o=e.repos.map(([a])=>a);return{at:i(a=>`../${r[t.findIndex(c=>c.name===a)]}`,"at"),repos:o.length?o.map(a=>`\`../../${a}/\``).join(", "):"the code worktrees in this workspace",restart:n&&s.length?hce(n,s):"restart whatever serves the change as `.werkmeister/werkmeister-context.md` describes",standards:"",autonomous:In(e.inputs.autonomous),group:l1(e.inputs.group),questionTool:us(e.workspaceRoot).questionTool}}function mce(e){let t=ur(null,Dt(e.workspaceRoot));if(!Object.keys(t).length)return C(Cc()||`no standard modules found in ${Tt()} \u2014 _shared/standards.md lists none`),{active:[],notActive:[],modules:t};let[r,n]=Nn(),[s,o]=Uu(e.repos.map(([a])=>a),r,n,Ft(e.workspaceRoot,e.configOverride),t,l1(e.meta.SERVICES));return{active:s,notActive:o,modules:t}}function gce(e){let t=Array.isArray(e.applies_to)?e.applies_to.map(String):[];return!t.length||t.includes("**/*")?"any code edit":"editing "+t.map(r=>`\`${r}\``).join(", ")}function yce(e){let t=i(r=>Yt.relative(r,e.path).split(Yt.sep).join("/"),"rel");return e.repo?`${e.repo}/${t(Yt.resolve(e.root,"..",".."))}`:`<standards_dir>/${t(Tt())}`}function wce(e){let t=["# Coding standards (factory)","","Read from their one home, not copied. Load only the rows a stage's contract names.","","| Standard | Read | Applies when |","|---|---|---|",...e.active.map(r=>`| ${r} | \`${yce(e.modules[r])}\` | ${gce(e.modules[r])} |`),pce,"","`<standards_dir>` is this machine's standards tree: `werkmeister standards check` prints its path (`overrides.standards_dir` in `werkmeister machine config`), and `werkmeister machine setup` grants Claude Code read access to it.",""];return e.notActive.length&&t.push(`Not applicable to this workspace (do not load): ${e.notActive.join(", ")}.`,""),t.push("Before writing code on a path a standard governs, restate the one rule you are applying in a line next to the edit \u2014 a rule read twenty tool calls ago no longer steers.",""),t.join(`
624
624
  `)}function xce(e,t){return e==="none"?"":`- Reference (every run): \`../../_shared/standards.md\` \u2014 rows ${[...t.active,"ponytail"].map(r=>`\`${r}\``).join(", ")}`}function Sce(e){let t=`${bce} ${vce}`;return e?`${kce} Then: ${t}`:t}function _ce(e,t,r,n=""){let s=t.contract(r);return[`# ${e} \u2014 ${t.job}`,"",s.oneJob,"","## Inputs",...s.inputs.map(o=>`- ${o}`),...r.standards?[r.standards]:[],"",`Do NOT load: ${s.doNotLoad}`,"","## Process",...n?[`0. ${n}`]:[],...s.process.map((o,a)=>`${a+1}. ${o}`),"","## Outputs",...s.outputs.map(o=>`- ${o}`),"",...r.autonomous?["## Self-check",s.selfCheck??m5]:["## Human check",s.humanCheck,"",h5(r.questionTool)],""].join(`
625
625
  `)}function Ece(e,t){let r=js(t),n=x5(e,t);return[`# Workspace: ${e.workspaceName}`,"",e.task,"",...e.issue?[Xc(e.issue)]:[],"Read this file, then `CONTEXT.md`, then only the one stage `CONTEXT.md` the routing table sends you to. Nothing else up front.","","## Where things live","","| Path | Holds |","|---|---|","| `BRIEF.md` | the run's input: goal, acceptance criteria, open questions |",...e.issue?.fetchedAt?["| `.werkmeister/issue.md` | the issue as fetched at creation; refresh with `werkmeister workspace init --refresh-issue` |"]:[],"| `CONTEXT.md` | the pipeline in one screen |","| `stages/NN_*/` | one stage each: `CONTEXT.md` (contract) + `output/` (this run's artifacts) |","| `_shared/` | factory: the coding standards and `issues-report.md` (fix a bug here or file an issue \u2014 bug, feature or task \u2014 and how), same every run |",...e.repos.map(([s,o])=>`| \`${s}/\` | code worktree${o?`, branch \`${o}\``:""} |`),"| this folder's git branch | the run's record (contracts + stage outputs): commit and push it; never open a PR from it or merge it |","| `.werkmeister/werkmeister-context.md` | generated infra facts: how to validate, test command, ports, container names |",`| \`.werkmeister/*.yml\`, \`${be}\`, \`.env\` | generated by \`werkmeister\`; do not hand-edit |`,"",`\`werkmeister feature up\` is safe here. Do not rerun \`werkmeister workspace init\` unless you mean to regenerate this file and the stage contracts. To reload code after an edit, ${n.restart}.`,"","## Route by what just happened","","| If | Go to | Stop when |","|---|---|---|",...t.map((s,o)=>`| ${o===0?"starting the run":s.enter??$ce(t[o-1],r[o-1],n.autonomous)} | \`stages/${r[o]}/CONTEXT.md\` | ${n.autonomous?"`output/` written and self-checked":"a person has read `output/`"} |`),"| asked to open or create a PR \u2014 including `/create-pr` or `finishing-a-development-branch` | `_shared/pr-rules.md`, then `werkmeister pr open` (rule 5: `pr watch` is the auto-fix) | PR URL is in the PR file |","| a PR merged or released, or asked to close out | `werkmeister pr status`, then the werkmeister `postmortem` skill (writes `postmortem.md`), then ask the person before `werkmeister workspace close` | `postmortem.md` written, then closed out after the person says yes |","| asked for status | `ls stages/*/output/` | report which stages hold artifacts |","| containers / ports / routing broken | `.werkmeister/werkmeister-context.md` | \u2014 |","| you hit a bug or need to log a feature/task \u2014 in the `werkmeister` tool or in a repo's code | `_shared/issues-report.md`: if this workspace's changes caused a bug, fix it here; otherwise file an issue where it belongs | fixed, or issue URL reported to the person |","",...n.autonomous?Tce(t):Oce,""].join(`