claude-code-session-manager 0.96.0 → 0.98.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/assets/{DataModel-T0D00BpK.js → DataModel-DCEgMTjH.js} +1 -1
  2. package/dist/assets/{History-DuAovTr7.js → History-Bfdoywlh.js} +1 -1
  3. package/dist/assets/{Hooks-CgP9jsAN.js → Hooks-CKDJjTJV.js} +1 -1
  4. package/dist/assets/{HostBilko-DHfz3Mxa.js → HostBilko-CDVHE0hT.js} +1 -1
  5. package/dist/assets/{Library--poVP-d1.js → Library-7akfgy67.js} +1 -1
  6. package/dist/assets/{MarkdownEditor-C56-Pc4c.js → MarkdownEditor-DDesiqet.js} +1 -1
  7. package/dist/assets/{McpServers-D-ykP4Vi.js → McpServers-D4lZtXof.js} +1 -1
  8. package/dist/assets/{Memory-BrkJjRL8.js → Memory-CeI8G1w5.js} +1 -1
  9. package/dist/assets/{Permissions-BMpAaxJu.js → Permissions-BGleLja4.js} +1 -1
  10. package/dist/assets/{Plugins-OuEe5S_T.js → Plugins-P4eCXy_S.js} +2 -2
  11. package/dist/assets/{ProvenanceBadge-4eNbDYe8.js → ProvenanceBadge-BFczzI1B.js} +1 -1
  12. package/dist/assets/{SaveBar-BQ8y9Lkv.js → SaveBar-l9jnEMES.js} +1 -1
  13. package/dist/assets/{Scheduler-DcMT5sT_.js → Scheduler-C_phpeUS.js} +1 -1
  14. package/dist/assets/{ScopeSwitcher-XdxtVKP-.js → ScopeSwitcher-CjJi8ST5.js} +1 -1
  15. package/dist/assets/{Settings-FdaPUq2t.js → Settings-BIwZ3FGQ.js} +1 -1
  16. package/dist/assets/{SkillReferenceGraph-CJzvvc0_.js → SkillReferenceGraph-CjbO01Sg.js} +1 -1
  17. package/dist/assets/{Skills-Wvm9OE1e.js → Skills-BxZ9_fCR.js} +1 -1
  18. package/dist/assets/{SystemPrompt--LYw_69j.js → SystemPrompt-D8vfFb8b.js} +1 -1
  19. package/dist/assets/{TagLibrary-Be6HbMMx.js → TagLibrary-2vzUo7YL.js} +1 -1
  20. package/dist/assets/{TiptapBody-DzFlWMgO.js → TiptapBody-B8ZfbK90.js} +1 -1
  21. package/dist/assets/{Toggle-BxtAFE1i.js → Toggle-BbW4nGGf.js} +1 -1
  22. package/dist/assets/{index-XkrLB67D.js → index-Cd98Q1lD.js} +3 -3
  23. package/dist/assets/{settingsSchema-BIvDZ1Cj.js → settingsSchema-IhUfucCF.js} +1 -1
  24. package/dist/index.html +1 -1
  25. package/package.json +2 -1
  26. package/plugins/session-manager-dev/skills/builder/4-manual/SKILL.md +2 -0
  27. package/plugins/session-manager-dev/skills/develop/SKILL.md +12 -5
  28. package/src/main/__tests__/ipcSchemas-dependsOn.test.cjs +39 -0
  29. package/src/main/__tests__/planValidator.test.cjs +54 -0
  30. package/src/main/__tests__/prdCreateAdoption.test.cjs +205 -0
  31. package/src/main/__tests__/queueOpsAutoArchive.test.cjs +63 -6
  32. package/src/main/__tests__/scheduler-mutate-reentrancy.test.cjs +117 -0
  33. package/src/main/build-info.json +4 -4
  34. package/src/main/ipcSchemas.cjs +10 -6
  35. package/src/main/lib/__tests__/watchdog-helpers.test.cjs +66 -0
  36. package/src/main/lib/planValidator.cjs +59 -7
  37. package/src/main/lib/prdCreate.cjs +32 -7
  38. package/src/main/lib/watchdogHelpers.cjs +21 -5
  39. package/src/main/queueOps.cjs +17 -6
  40. package/src/main/scheduler.cjs +65 -5
@@ -1 +1 @@
1
- import{az as b,ak as n,S as N,aR as k,ax as K}from"./index-XkrLB67D.js";function T({node:e,targetScope:r,onOverride:s,schema:a,rootLabel:m}){const[f,x]=b.useState(""),[u,o]=b.useState(!0),g=[],d=e.kind==="object"&&Object.keys(e.children).length===0,y=((a==null?void 0:a.rootKeys())??[]).length>0;return n.jsxs("div",{className:"h-full flex flex-col",children:[n.jsxs("div",{className:"shrink-0 border-b border-line bg-bg-elev px-3 py-1.5 flex items-center gap-2 text-xs",children:[n.jsxs("span",{className:"text-fg-faint",children:["merged · overrides → ",n.jsx("span",{className:"text-fg-dim",children:N[r].label})]}),y&&n.jsxs("label",{className:"flex items-center gap-1 text-fg-faint cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:u,onChange:t=>o(t.target.checked),className:"accent-accent"}),"show unset keys"]}),n.jsx("div",{className:"flex-1"}),n.jsx("input",{value:f,onChange:t=>x(t.target.value),placeholder:"filter keys or descriptions…",className:"bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg w-56"})]}),n.jsx("div",{className:"flex-1 overflow-auto px-3 py-2 font-mono text-xs",children:d&&!u?n.jsx("div",{className:"text-fg-faint italic px-2 py-4",children:"no settings resolved — all scope files empty or missing"}):n.jsx(E,{node:e,path:g,label:m??"(root)",targetScope:r,onOverride:s,filter:f,depth:0,schema:a,showGhosts:u,defaultOpen:!0})})]})}function E(e){return e.node.kind==="object"?n.jsx(P,{...e,node:e.node}):e.node.kind==="array"?n.jsx(R,{...e,node:e.node}):n.jsx(J,{...e,node:e.node})}function A(e,r){return r.trim()?e.toLowerCase().includes(r.toLowerCase()):!0}function w(e,r,s){return!!(!s.trim()||e.some(a=>A(a,s))||r!=null&&r.description&&A(r.description,s))}function P({node:e,path:r,label:s,targetScope:a,onOverride:m,filter:f,depth:x,schema:u,showGhosts:o,defaultOpen:g}){const[d,h]=b.useState(g??x<2),y=(u==null?void 0:u.at(r))??null,t=new Set(Object.keys(e.children)),i=o?(y==null?void 0:y.knownChildren)??[]:[],c=Array.from(new Set([...t,...i])).sort(),l=b.useMemo(()=>f.trim()?c.filter(p=>{const v=(u==null?void 0:u.at([...r,p]))??null;return w([...r,p],v,f)?!0:t.has(p)?L(e.children[p],[...r,p],f,u):!1}):c,[c.join(","),f,e,r.join("."),u]);if(f.trim()&&l.length===0&&!w(r,y,f))return null;if(r.length===0)return n.jsx("div",{children:l.map(p=>j(p))});return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-1 py-0.5 hover:bg-bg-elev/50 rounded cursor-pointer",style:{paddingLeft:x*14},onClick:()=>h(!d),children:[n.jsx("span",{className:"text-fg-faint w-3 shrink-0",children:d?"▾":"▸"}),n.jsx("span",{className:"text-fg",children:s}),n.jsxs("span",{className:"text-fg-faint",children:[" {",t.size,i.length>t.size?`/${new Set([...t,...i]).size}`:"","}"]}),(y==null?void 0:y.description)&&n.jsxs("span",{className:"text-fg-faint truncate max-w-md",title:y.description,children:["— ",y.description]})]}),d&&l.map(p=>j(p))]});function j(p){if(t.has(p))return n.jsx(E,{node:e.children[p],path:[...r,p],label:p,targetScope:a,onOverride:m,filter:f,depth:x+1,schema:u,showGhosts:o},p);const v=(u==null?void 0:u.at([...r,p]))??null;return v?n.jsx(I,{path:[...r,p],label:p,info:v,targetScope:a,onSet:m,depth:x+1,filter:f},p):null}}function L(e,r,s,a){const m=(a==null?void 0:a.at(r))??null;if(w(r,m,s))return!0;if(e.kind!=="object")return!1;for(const f of Object.keys(e.children))if(L(e.children[f],[...r,f],s,a))return!0;return!1}function R({node:e,path:r,label:s,filter:a,depth:m,schema:f}){const[x,u]=b.useState(!0),o=(f==null?void 0:f.at(r))??null;return w(r,o,a)?n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-1 py-0.5 hover:bg-bg-elev/50 rounded cursor-pointer",style:{paddingLeft:m*14},onClick:()=>u(!x),children:[n.jsx("span",{className:"text-fg-faint w-3 shrink-0",children:x?"▾":"▸"}),n.jsx("span",{className:"text-fg",children:s}),n.jsxs("span",{className:"text-fg-faint",children:[" [",e.items.length,"]"]}),n.jsx(S,{tone:"warn",children:"accumulated"}),(o==null?void 0:o.description)&&n.jsxs("span",{className:"text-fg-faint truncate max-w-md",title:o.description,children:["— ",o.description]})]}),x&&e.items.map((g,d)=>n.jsxs("div",{className:"flex items-start gap-2 py-0.5",style:{paddingLeft:(m+1)*14},children:[n.jsx("span",{className:"text-fg-faint w-3 shrink-0"}),n.jsxs("span",{className:"text-fg-faint",children:[d,":"]}),n.jsx("span",{className:"text-fg-dim truncate max-w-xl",children:O(g.value)}),n.jsx(C,{scope:g.fromScope})]},d))]}):null}function J({node:e,path:r,label:s,targetScope:a,onOverride:m,filter:f,depth:x,schema:u}){const[o,g]=b.useState(!1),d=(u==null?void 0:u.at(r))??null;if(!w(r,d,f))return null;const h=e.winner!==a,y=e.shadowed.length>0;return n.jsxs("div",{children:[n.jsxs("div",{className:"group flex items-center gap-2 py-0.5 hover:bg-bg-elev/50 rounded",style:{paddingLeft:x*14},children:[n.jsx("span",{className:`w-3 shrink-0 ${y?"text-fg-faint cursor-pointer":""}`,onClick:()=>y&&g(!o),children:y?o?"▾":"▸":""}),n.jsxs("span",{className:"text-fg",children:[s,":"]}),n.jsx("span",{className:"text-fg-dim truncate max-w-md",children:O(e.value)}),n.jsx(C,{scope:e.winner}),(d==null?void 0:d.deprecated)&&n.jsx(S,{tone:"warn",children:"deprecated"}),(d==null?void 0:d.default)!==void 0&&_(e.value,d.default)&&n.jsx(S,{tone:"dim",children:"= default"}),e.typeMismatch&&n.jsx("span",{className:"text-yellow-500/80",title:"shadowed scopes have a different value type",children:"⚠"}),(d==null?void 0:d.description)&&n.jsxs("span",{className:"text-fg-faint truncate max-w-md",title:d.description,children:["— ",d.description]}),n.jsx("div",{className:"flex-1"}),(d==null?void 0:d.enum)&&n.jsx(F,{values:d.enum}),n.jsx("button",{disabled:!h,onClick:()=>m(r,e.value),className:`opacity-0 group-hover:opacity-100 px-1.5 py-0 text-[10px] border rounded transition-opacity ${h?"border-accent/50 text-accent hover:bg-accent hover:text-bg":"border-line text-fg-faint cursor-not-allowed"}`,title:h?`copy into ${N[a].label} draft`:`already winning in ${N[a].label}`,children:"override"})]}),o&&e.shadowed.map((t,i)=>n.jsxs("div",{className:"flex items-center gap-2 py-0.5 text-fg-faint line-through",style:{paddingLeft:(x+1)*14+12},children:[n.jsx("span",{children:"shadowed:"}),n.jsx("span",{className:"truncate max-w-xl",children:O(t.value)}),n.jsx(C,{scope:t.scope,dim:!0})]},i))]})}function I({path:e,label:r,info:s,targetScope:a,onSet:m,depth:f,filter:x}){if(!w(e,s,x))return null;const u=s.default!==void 0?s.default:M(s.type),o=Array.isArray(s.type)?s.type.join("|"):s.type??"?";return n.jsxs("div",{className:"group flex items-center gap-2 py-0.5 hover:bg-bg-elev/50 rounded opacity-60",style:{paddingLeft:f*14},children:[n.jsx("span",{className:"w-3 shrink-0"}),n.jsx("span",{className:"text-fg-dim",children:r}),n.jsx(S,{tone:"dim",children:o}),s.required&&n.jsx(S,{tone:"warn",children:"required"}),s.default!==void 0&&n.jsxs("span",{className:"text-fg-faint",children:["default: ",O(s.default)]}),s.description&&n.jsxs("span",{className:"text-fg-faint truncate max-w-md",title:s.description,children:["— ",s.description]}),n.jsx("div",{className:"flex-1"}),s.enum&&n.jsx(F,{values:s.enum}),n.jsx("button",{onClick:()=>m(e,u),className:"opacity-0 group-hover:opacity-100 px-1.5 py-0 text-[10px] border border-accent/50 rounded text-accent hover:bg-accent hover:text-bg transition-opacity",title:`write to ${N[a].label} draft`,children:"set"})]})}function _(e,r){return e===r?!0:typeof e!=typeof r?!1:e&&r&&typeof e=="object"?JSON.stringify(e)===JSON.stringify(r):!1}function M(e){switch(Array.isArray(e)?e[0]:e){case"boolean":return!1;case"integer":case"number":return 0;case"string":return"";case"array":return[];case"object":return{};case"null":return null;default:return null}}function O(e){if(typeof e=="string")return JSON.stringify(e);if(e===null)return"null";if(typeof e=="object"){const r=JSON.stringify(e);return r.length>100?r.slice(0,100)+"…":r}return String(e)}function C({scope:e,dim:r}){const s=e==="user"?"bg-bg-hi text-fg-dim border-line":e==="project"?"bg-blue-950/30 text-blue-400/80 border-blue-900/40":"bg-purple-950/30 text-purple-400/80 border-purple-900/40";return n.jsx("span",{className:`text-[10px] px-1 py-0 rounded border uppercase tracking-wide shrink-0 ${s} ${r?"opacity-60":""}`,children:N[e].label})}function S({children:e,tone:r="default"}){const s={default:"bg-bg-hi text-fg-dim border-line",warn:"bg-yellow-950/30 text-yellow-500/80 border-yellow-900/40",dim:"bg-bg-elev text-fg-faint border-line"}[r];return n.jsx("span",{className:`text-[10px] px-1 py-0 rounded border uppercase tracking-wide shrink-0 ${s}`,children:e})}function F({values:e}){const r=e.map(s=>String(s)).join(" | ");return n.jsxs("span",{className:"text-[10px] text-fg-faint truncate max-w-xs",title:`allowed: ${r}`,children:["∈ ",r.length>30?r.slice(0,30)+"…":r]})}function G(e,r,s){const a=k(o=>o.files),m=k(o=>o.loadJson),f=k(o=>o.watchFile),x=k(o=>o.unwatchFile),u=b.useMemo(()=>{const o={};for(const g of e.scopes){const d=e.resolve(g,r??"",s);d&&(o[g]=d)}return o},[e,r,s]);return b.useEffect(()=>{const o=Object.values(u).filter(Boolean);return o.forEach(g=>{a[g]||m(g),f(g)}),()=>{o.forEach(g=>x(g))}},[JSON.stringify(u)]),u}function z(e){const r=e??{},s={...r.$defs??{},...r.definitions??{}},a=t=>{if(!t)return{};if(!t.$ref)return x(t);const i=/^#\/(\$defs|definitions)\/(.+)$/.exec(t.$ref);if(!i)return x(t);const c=s[i[2]];return c?a({...c,...u(t)}):x(t)},m=new Set(["__proto__","constructor","prototype"]),f=t=>{if(!t)return{};const i={};for(const[c,l]of Object.entries(t))m.has(c)||(i[c]=l);return i},x=t=>{if(!t.allOf||t.allOf.length===0)return t;const i={...t};delete i.allOf;for(const c of t.allOf){const l=a(c);Object.assign(i,{properties:{...f(i.properties),...f(l.properties)},required:B([...i.required??[],...l.required??[]])}),!i.description&&l.description&&(i.description=l.description),i.default===void 0&&l.default!==void 0&&(i.default=l.default),!i.type&&l.type&&(i.type=l.type)}return i},u=t=>{const{$ref:i,...c}=t;return c},o=(t,i)=>{let c=a(t);for(const l of i){if(!c)return null;if(/^\d+$/.test(l)){const v=Array.isArray(c.items)?c.items[Number(l)]:c.items;c=v?a(v):null;continue}const j=c.properties;if(j&&!m.has(l)&&l in j){c=a(j[l]);continue}const p=c.additionalProperties;if(p&&typeof p=="object"){c=a(p);continue}return null}return c},g=(t,i,c)=>{if(!t)return null;const l={};if(t.description&&(l.description=t.description),t.type&&(l.type=t.type),t.default!==void 0&&(l.default=t.default),t.enum&&(l.enum=t.enum),t.const!==void 0&&(l.const=t.const),t.deprecated&&(l.deprecated=!0),t.examples&&(l.examples=t.examples),t.properties&&(l.knownChildren=Object.keys(t.properties)),c&&(i!=null&&i.includes(c))&&(l.required=!0),t.items&&!Array.isArray(t.items)){const j=a(t.items),p=g(j,void 0,null);p&&(l.itemsInfo=p)}return(t.additionalProperties===!0||typeof t.additionalProperties=="object")&&(l.open=!0),l},d=t=>i=>{if(i.length===0)return g(a(t),void 0,null);const c=o(t,i.slice(0,-1));if(!c)return null;const l=i[i.length-1],j=o(c,[l]);return g(j,c.required,l)},h=t=>{const i=a(t);return Object.keys(i.properties??{})},y=t=>({at:d(t),rootKeys:()=>h(t),rootedAt:i=>{const c=o(t,i);return y(c??{})}});return y(r)}function B(e){return Array.from(new Set(e))}let $=null;function V(){return $||($=z(K)),$}export{T as E,V as s,G as u};
1
+ import{az as b,ak as n,S as N,aR as k,ax as K}from"./index-Cd98Q1lD.js";function T({node:e,targetScope:r,onOverride:s,schema:a,rootLabel:m}){const[f,x]=b.useState(""),[u,o]=b.useState(!0),g=[],d=e.kind==="object"&&Object.keys(e.children).length===0,y=((a==null?void 0:a.rootKeys())??[]).length>0;return n.jsxs("div",{className:"h-full flex flex-col",children:[n.jsxs("div",{className:"shrink-0 border-b border-line bg-bg-elev px-3 py-1.5 flex items-center gap-2 text-xs",children:[n.jsxs("span",{className:"text-fg-faint",children:["merged · overrides → ",n.jsx("span",{className:"text-fg-dim",children:N[r].label})]}),y&&n.jsxs("label",{className:"flex items-center gap-1 text-fg-faint cursor-pointer",children:[n.jsx("input",{type:"checkbox",checked:u,onChange:t=>o(t.target.checked),className:"accent-accent"}),"show unset keys"]}),n.jsx("div",{className:"flex-1"}),n.jsx("input",{value:f,onChange:t=>x(t.target.value),placeholder:"filter keys or descriptions…",className:"bg-bg border border-line rounded px-2 py-0.5 text-xs text-fg w-56"})]}),n.jsx("div",{className:"flex-1 overflow-auto px-3 py-2 font-mono text-xs",children:d&&!u?n.jsx("div",{className:"text-fg-faint italic px-2 py-4",children:"no settings resolved — all scope files empty or missing"}):n.jsx(E,{node:e,path:g,label:m??"(root)",targetScope:r,onOverride:s,filter:f,depth:0,schema:a,showGhosts:u,defaultOpen:!0})})]})}function E(e){return e.node.kind==="object"?n.jsx(P,{...e,node:e.node}):e.node.kind==="array"?n.jsx(R,{...e,node:e.node}):n.jsx(J,{...e,node:e.node})}function A(e,r){return r.trim()?e.toLowerCase().includes(r.toLowerCase()):!0}function w(e,r,s){return!!(!s.trim()||e.some(a=>A(a,s))||r!=null&&r.description&&A(r.description,s))}function P({node:e,path:r,label:s,targetScope:a,onOverride:m,filter:f,depth:x,schema:u,showGhosts:o,defaultOpen:g}){const[d,h]=b.useState(g??x<2),y=(u==null?void 0:u.at(r))??null,t=new Set(Object.keys(e.children)),i=o?(y==null?void 0:y.knownChildren)??[]:[],c=Array.from(new Set([...t,...i])).sort(),l=b.useMemo(()=>f.trim()?c.filter(p=>{const v=(u==null?void 0:u.at([...r,p]))??null;return w([...r,p],v,f)?!0:t.has(p)?L(e.children[p],[...r,p],f,u):!1}):c,[c.join(","),f,e,r.join("."),u]);if(f.trim()&&l.length===0&&!w(r,y,f))return null;if(r.length===0)return n.jsx("div",{children:l.map(p=>j(p))});return n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-1 py-0.5 hover:bg-bg-elev/50 rounded cursor-pointer",style:{paddingLeft:x*14},onClick:()=>h(!d),children:[n.jsx("span",{className:"text-fg-faint w-3 shrink-0",children:d?"▾":"▸"}),n.jsx("span",{className:"text-fg",children:s}),n.jsxs("span",{className:"text-fg-faint",children:[" {",t.size,i.length>t.size?`/${new Set([...t,...i]).size}`:"","}"]}),(y==null?void 0:y.description)&&n.jsxs("span",{className:"text-fg-faint truncate max-w-md",title:y.description,children:["— ",y.description]})]}),d&&l.map(p=>j(p))]});function j(p){if(t.has(p))return n.jsx(E,{node:e.children[p],path:[...r,p],label:p,targetScope:a,onOverride:m,filter:f,depth:x+1,schema:u,showGhosts:o},p);const v=(u==null?void 0:u.at([...r,p]))??null;return v?n.jsx(I,{path:[...r,p],label:p,info:v,targetScope:a,onSet:m,depth:x+1,filter:f},p):null}}function L(e,r,s,a){const m=(a==null?void 0:a.at(r))??null;if(w(r,m,s))return!0;if(e.kind!=="object")return!1;for(const f of Object.keys(e.children))if(L(e.children[f],[...r,f],s,a))return!0;return!1}function R({node:e,path:r,label:s,filter:a,depth:m,schema:f}){const[x,u]=b.useState(!0),o=(f==null?void 0:f.at(r))??null;return w(r,o,a)?n.jsxs("div",{children:[n.jsxs("div",{className:"flex items-center gap-1 py-0.5 hover:bg-bg-elev/50 rounded cursor-pointer",style:{paddingLeft:m*14},onClick:()=>u(!x),children:[n.jsx("span",{className:"text-fg-faint w-3 shrink-0",children:x?"▾":"▸"}),n.jsx("span",{className:"text-fg",children:s}),n.jsxs("span",{className:"text-fg-faint",children:[" [",e.items.length,"]"]}),n.jsx(S,{tone:"warn",children:"accumulated"}),(o==null?void 0:o.description)&&n.jsxs("span",{className:"text-fg-faint truncate max-w-md",title:o.description,children:["— ",o.description]})]}),x&&e.items.map((g,d)=>n.jsxs("div",{className:"flex items-start gap-2 py-0.5",style:{paddingLeft:(m+1)*14},children:[n.jsx("span",{className:"text-fg-faint w-3 shrink-0"}),n.jsxs("span",{className:"text-fg-faint",children:[d,":"]}),n.jsx("span",{className:"text-fg-dim truncate max-w-xl",children:O(g.value)}),n.jsx(C,{scope:g.fromScope})]},d))]}):null}function J({node:e,path:r,label:s,targetScope:a,onOverride:m,filter:f,depth:x,schema:u}){const[o,g]=b.useState(!1),d=(u==null?void 0:u.at(r))??null;if(!w(r,d,f))return null;const h=e.winner!==a,y=e.shadowed.length>0;return n.jsxs("div",{children:[n.jsxs("div",{className:"group flex items-center gap-2 py-0.5 hover:bg-bg-elev/50 rounded",style:{paddingLeft:x*14},children:[n.jsx("span",{className:`w-3 shrink-0 ${y?"text-fg-faint cursor-pointer":""}`,onClick:()=>y&&g(!o),children:y?o?"▾":"▸":""}),n.jsxs("span",{className:"text-fg",children:[s,":"]}),n.jsx("span",{className:"text-fg-dim truncate max-w-md",children:O(e.value)}),n.jsx(C,{scope:e.winner}),(d==null?void 0:d.deprecated)&&n.jsx(S,{tone:"warn",children:"deprecated"}),(d==null?void 0:d.default)!==void 0&&_(e.value,d.default)&&n.jsx(S,{tone:"dim",children:"= default"}),e.typeMismatch&&n.jsx("span",{className:"text-yellow-500/80",title:"shadowed scopes have a different value type",children:"⚠"}),(d==null?void 0:d.description)&&n.jsxs("span",{className:"text-fg-faint truncate max-w-md",title:d.description,children:["— ",d.description]}),n.jsx("div",{className:"flex-1"}),(d==null?void 0:d.enum)&&n.jsx(F,{values:d.enum}),n.jsx("button",{disabled:!h,onClick:()=>m(r,e.value),className:`opacity-0 group-hover:opacity-100 px-1.5 py-0 text-[10px] border rounded transition-opacity ${h?"border-accent/50 text-accent hover:bg-accent hover:text-bg":"border-line text-fg-faint cursor-not-allowed"}`,title:h?`copy into ${N[a].label} draft`:`already winning in ${N[a].label}`,children:"override"})]}),o&&e.shadowed.map((t,i)=>n.jsxs("div",{className:"flex items-center gap-2 py-0.5 text-fg-faint line-through",style:{paddingLeft:(x+1)*14+12},children:[n.jsx("span",{children:"shadowed:"}),n.jsx("span",{className:"truncate max-w-xl",children:O(t.value)}),n.jsx(C,{scope:t.scope,dim:!0})]},i))]})}function I({path:e,label:r,info:s,targetScope:a,onSet:m,depth:f,filter:x}){if(!w(e,s,x))return null;const u=s.default!==void 0?s.default:M(s.type),o=Array.isArray(s.type)?s.type.join("|"):s.type??"?";return n.jsxs("div",{className:"group flex items-center gap-2 py-0.5 hover:bg-bg-elev/50 rounded opacity-60",style:{paddingLeft:f*14},children:[n.jsx("span",{className:"w-3 shrink-0"}),n.jsx("span",{className:"text-fg-dim",children:r}),n.jsx(S,{tone:"dim",children:o}),s.required&&n.jsx(S,{tone:"warn",children:"required"}),s.default!==void 0&&n.jsxs("span",{className:"text-fg-faint",children:["default: ",O(s.default)]}),s.description&&n.jsxs("span",{className:"text-fg-faint truncate max-w-md",title:s.description,children:["— ",s.description]}),n.jsx("div",{className:"flex-1"}),s.enum&&n.jsx(F,{values:s.enum}),n.jsx("button",{onClick:()=>m(e,u),className:"opacity-0 group-hover:opacity-100 px-1.5 py-0 text-[10px] border border-accent/50 rounded text-accent hover:bg-accent hover:text-bg transition-opacity",title:`write to ${N[a].label} draft`,children:"set"})]})}function _(e,r){return e===r?!0:typeof e!=typeof r?!1:e&&r&&typeof e=="object"?JSON.stringify(e)===JSON.stringify(r):!1}function M(e){switch(Array.isArray(e)?e[0]:e){case"boolean":return!1;case"integer":case"number":return 0;case"string":return"";case"array":return[];case"object":return{};case"null":return null;default:return null}}function O(e){if(typeof e=="string")return JSON.stringify(e);if(e===null)return"null";if(typeof e=="object"){const r=JSON.stringify(e);return r.length>100?r.slice(0,100)+"…":r}return String(e)}function C({scope:e,dim:r}){const s=e==="user"?"bg-bg-hi text-fg-dim border-line":e==="project"?"bg-blue-950/30 text-blue-400/80 border-blue-900/40":"bg-purple-950/30 text-purple-400/80 border-purple-900/40";return n.jsx("span",{className:`text-[10px] px-1 py-0 rounded border uppercase tracking-wide shrink-0 ${s} ${r?"opacity-60":""}`,children:N[e].label})}function S({children:e,tone:r="default"}){const s={default:"bg-bg-hi text-fg-dim border-line",warn:"bg-yellow-950/30 text-yellow-500/80 border-yellow-900/40",dim:"bg-bg-elev text-fg-faint border-line"}[r];return n.jsx("span",{className:`text-[10px] px-1 py-0 rounded border uppercase tracking-wide shrink-0 ${s}`,children:e})}function F({values:e}){const r=e.map(s=>String(s)).join(" | ");return n.jsxs("span",{className:"text-[10px] text-fg-faint truncate max-w-xs",title:`allowed: ${r}`,children:["∈ ",r.length>30?r.slice(0,30)+"…":r]})}function G(e,r,s){const a=k(o=>o.files),m=k(o=>o.loadJson),f=k(o=>o.watchFile),x=k(o=>o.unwatchFile),u=b.useMemo(()=>{const o={};for(const g of e.scopes){const d=e.resolve(g,r??"",s);d&&(o[g]=d)}return o},[e,r,s]);return b.useEffect(()=>{const o=Object.values(u).filter(Boolean);return o.forEach(g=>{a[g]||m(g),f(g)}),()=>{o.forEach(g=>x(g))}},[JSON.stringify(u)]),u}function z(e){const r=e??{},s={...r.$defs??{},...r.definitions??{}},a=t=>{if(!t)return{};if(!t.$ref)return x(t);const i=/^#\/(\$defs|definitions)\/(.+)$/.exec(t.$ref);if(!i)return x(t);const c=s[i[2]];return c?a({...c,...u(t)}):x(t)},m=new Set(["__proto__","constructor","prototype"]),f=t=>{if(!t)return{};const i={};for(const[c,l]of Object.entries(t))m.has(c)||(i[c]=l);return i},x=t=>{if(!t.allOf||t.allOf.length===0)return t;const i={...t};delete i.allOf;for(const c of t.allOf){const l=a(c);Object.assign(i,{properties:{...f(i.properties),...f(l.properties)},required:B([...i.required??[],...l.required??[]])}),!i.description&&l.description&&(i.description=l.description),i.default===void 0&&l.default!==void 0&&(i.default=l.default),!i.type&&l.type&&(i.type=l.type)}return i},u=t=>{const{$ref:i,...c}=t;return c},o=(t,i)=>{let c=a(t);for(const l of i){if(!c)return null;if(/^\d+$/.test(l)){const v=Array.isArray(c.items)?c.items[Number(l)]:c.items;c=v?a(v):null;continue}const j=c.properties;if(j&&!m.has(l)&&l in j){c=a(j[l]);continue}const p=c.additionalProperties;if(p&&typeof p=="object"){c=a(p);continue}return null}return c},g=(t,i,c)=>{if(!t)return null;const l={};if(t.description&&(l.description=t.description),t.type&&(l.type=t.type),t.default!==void 0&&(l.default=t.default),t.enum&&(l.enum=t.enum),t.const!==void 0&&(l.const=t.const),t.deprecated&&(l.deprecated=!0),t.examples&&(l.examples=t.examples),t.properties&&(l.knownChildren=Object.keys(t.properties)),c&&(i!=null&&i.includes(c))&&(l.required=!0),t.items&&!Array.isArray(t.items)){const j=a(t.items),p=g(j,void 0,null);p&&(l.itemsInfo=p)}return(t.additionalProperties===!0||typeof t.additionalProperties=="object")&&(l.open=!0),l},d=t=>i=>{if(i.length===0)return g(a(t),void 0,null);const c=o(t,i.slice(0,-1));if(!c)return null;const l=i[i.length-1],j=o(c,[l]);return g(j,c.required,l)},h=t=>{const i=a(t);return Object.keys(i.properties??{})},y=t=>({at:d(t),rootKeys:()=>h(t),rootedAt:i=>{const c=o(t,i);return y(c??{})}});return y(r)}function B(e){return Array.from(new Set(e))}let $=null;function V(){return $||($=z(K)),$}export{T as E,V as s,G as u};
package/dist/index.html CHANGED
@@ -7,7 +7,7 @@
7
7
  <link rel="preconnect" href="https://fonts.googleapis.com">
8
8
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
9
  <link href="https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;0,6..72,700;1,6..72,400&family=Geist:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap" rel="stylesheet">
10
- <script type="module" crossorigin src="./assets/index-XkrLB67D.js"></script>
10
+ <script type="module" crossorigin src="./assets/index-Cd98Q1lD.js"></script>
11
11
  <link rel="modulepreload" crossorigin href="./assets/monaco-editor-BW5C4Iv1.js">
12
12
  <link rel="stylesheet" crossorigin href="./assets/monaco-editor-BTnBOi8r.css">
13
13
  <link rel="stylesheet" crossorigin href="./assets/index-CKH5Uxik.css">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-code-session-manager",
3
- "version": "0.96.0",
3
+ "version": "0.98.0",
4
4
  "description": "Local cockpit for the Claude Code CLI — multi-tab terminal, full config surface, scheduler, voice dictation, and live observability.",
5
5
  "type": "module",
6
6
  "main": "src/main/index.cjs",
@@ -53,6 +53,7 @@
53
53
  "refresh:vad-assets": "node scripts/refresh-vad-assets.mjs",
54
54
  "health": "node src/main/health.cjs",
55
55
  "manual:check": "node web/manual/build.mjs --check",
56
+ "manual:readability": "node web/manual/readability.mjs",
56
57
  "manual:build": "node web/manual/build.mjs",
57
58
  "manual:figures": "xvfb-run -a node web/manual/capture-figures.mjs",
58
59
  "lint:selectors": "node scripts/check-unstable-selectors.cjs",
@@ -45,6 +45,8 @@ Edit the chapter HTML in `session-manager-operations/manual/chapters/`.
45
45
 
46
46
  Hard rules — these are the ones that protect a paying customer:
47
47
 
48
+ - **Follow `manual/STYLE.md`** (voice, reading level, component vocabulary) — it is the single
49
+ writing contract for every chapter, revisions included.
48
50
  - **Every claim must be checkable against real code right now.** Read the file, run the
49
51
  command, confirm the constant. A wrong instruction in a paid product is a refund.
50
52
  - **Never invent a screenshot.** A figure slot that has no captured image stays a
@@ -204,7 +204,10 @@ can't load skills.
204
204
 
205
205
  **Every plan ends with one `validate` PRD.** After the work-item PRDs are written, author
206
206
  exactly one more through `scheduler_create_prd`: `agentType: "validator"`, `tag: "build"`,
207
- `estimateMinutes: 10`, `dependsOn` = every other slug in this plan, slug
207
+ `estimateMinutes: 10`, `dependsOn` = every other slug in this plan (`dependsOn` is capped at
208
+ 100 entries; for a plan bigger than that, list only the plan's sink PRDs — those nothing else
209
+ in the plan depends on — since `hasDownstreamValidator` walks `dependsOn` transitively, so a
210
+ validator anchored on the sinks alone still covers every upstream PRD), slug
208
211
  `validate-<short-plan-name>`. Its Goal lists the plan's PRD slugs and titles; its Acceptance
209
212
  criteria give, per PRD, where its file lives
210
213
  (`<cwd>/session-manager-operations/scheduler/epics/<epic-id>/prds/<NN>-<slug>.md` while queued,
@@ -215,8 +218,10 @@ can't load skills.
215
218
  While a plan has a pending validator, the scheduler suppresses both the per-PRD validation
216
219
  prompt into this session and the in-run `/code-review` steps for its work-items — one review,
217
220
  once, at the end. If `scheduler_create_prd` rejects `agentType: "validator"` (persona not
218
- installed on this machine yet), say so and fall back to today's per-PRD validation; do not
219
- hand-write the file.
221
+ installed on this machine yet — the usual cause is a running app older than 0.96.0, since the
222
+ validator persona is only seeded to `~/.claude/agents` on app boot), say so and fall back to
223
+ today's per-PRD validation; do not hand-write the file. Note the stale-app cause in your report
224
+ so the human knows to restart onto >=0.96.0.
220
225
 
221
226
  - **Sub-tasked Acceptance Criteria** (either shape, when a single PRD legitimately spans more
222
227
  than one concern dimension from step 3 — e.g. it has both core-functionality and
@@ -452,8 +457,10 @@ can't load skills.
452
457
  ## Phase 2 — Validation runs as its own job; this session only decides
453
458
 
454
459
  Every plan queued in Phase 1 ends with a `validate` PRD (agentType `validator`) whose
455
- `dependsOn` lists every other slug in the plan, so the scheduler runs it exactly once, after the
456
- last work-item lands. That job — not this session — re-runs each PRD's gate, checks every
460
+ `dependsOn` lists every other slug in the plan — or, for a plan over the 100-entry cap, just the
461
+ plan's sink PRDs, since `hasDownstreamValidator` walks `dependsOn` transitively and still credits
462
+ every upstream PRD — so the scheduler runs it exactly once, after the last work-item lands.
463
+ That job — not this session — re-runs each PRD's gate, checks every
457
464
  acceptance criterion against the tree, reviews the plan's combined diff (`/code-review`,
458
465
  `/security-review`), commits a review record, and ends with `VALIDATION: <slug>
459
466
  VERIFIED|REFUTED` per PRD. The scheduler appends one verdict event per PRD to this Epic (the
@@ -0,0 +1,39 @@
1
+ /**
2
+ * ipcSchemas-dependsOn.test.cjs — dependsOn array cap for schedulerCreatePrd
3
+ * (PRD: raise-dependson-cap-to-100). A /develop plan's validate PRD depends
4
+ * on every other slug in the plan, so the cap must clear a 36-PRD plan while
5
+ * still bounding an unbounded payload.
6
+ *
7
+ * Run: timeout 300 npx vitest run src/main/__tests__/ipcSchemas-dependsOn.test.cjs
8
+ */
9
+
10
+ 'use strict';
11
+
12
+ import { test, expect } from 'vitest';
13
+ const { schemas } = require('../ipcSchemas.cjs');
14
+
15
+ const basePrd = {
16
+ title: 'validate the plan',
17
+ estimateMinutes: 5,
18
+ goal: 'Validate the plan',
19
+ acceptanceCriteria: ['it validates'],
20
+ implementationNotes: 'n/a',
21
+ };
22
+
23
+ test('schedulerCreatePrd accepts 36 dependsOn entries', () => {
24
+ const dependsOn = Array.from({ length: 36 }, (_, i) => `prd-${i}`);
25
+ const result = schemas.schedulerCreatePrd.safeParse({ ...basePrd, dependsOn });
26
+ expect(result.success).toBe(true);
27
+ });
28
+
29
+ test('schedulerCreatePrd rejects 101 dependsOn entries', () => {
30
+ const dependsOn = Array.from({ length: 101 }, (_, i) => `prd-${i}`);
31
+ const result = schemas.schedulerCreatePrd.safeParse({ ...basePrd, dependsOn });
32
+ expect(result.success).toBe(false);
33
+ });
34
+
35
+ test('schedulerCreatePrd accepts exactly 100 dependsOn entries', () => {
36
+ const dependsOn = Array.from({ length: 100 }, (_, i) => `prd-${i}`);
37
+ const result = schemas.schedulerCreatePrd.safeParse({ ...basePrd, dependsOn });
38
+ expect(result.success).toBe(true);
39
+ });
@@ -69,3 +69,57 @@ test('false when the depending row is not agentType validator', () => {
69
69
  ];
70
70
  expect(hasDownstreamValidator(job, jobs)).toBe(false);
71
71
  });
72
+
73
+ test('true when a pending validator reaches the job transitively via one sink (2-hop)', () => {
74
+ const job = { slug: '111-alpha' };
75
+ const jobs = [
76
+ job,
77
+ { slug: '150-sink', agentType: 'dev-lead', status: 'pending', dependsOn: ['111-alpha'] },
78
+ { slug: '999-validate', agentType: 'validator', status: 'pending', dependsOn: ['150-sink'] },
79
+ ];
80
+ expect(hasDownstreamValidator(job, jobs)).toBe(true);
81
+ });
82
+
83
+ test('true when a pending validator reaches the job transitively via two intermediate sinks (3-hop)', () => {
84
+ const job = { slug: '111-alpha' };
85
+ const jobs = [
86
+ job,
87
+ { slug: '140-mid', agentType: 'dev-lead', status: 'pending', dependsOn: ['111-alpha'] },
88
+ { slug: '150-sink', agentType: 'dev-lead', status: 'pending', dependsOn: ['140-mid'] },
89
+ { slug: '999-validate', agentType: 'validator', status: 'pending', dependsOn: ['150-sink'] },
90
+ ];
91
+ expect(hasDownstreamValidator(job, jobs)).toBe(true);
92
+ });
93
+
94
+ test('false when the validator only reaches an unrelated branch', () => {
95
+ const job = { slug: '111-alpha' };
96
+ const jobs = [
97
+ job,
98
+ { slug: '222-beta', agentType: 'dev-lead', status: 'pending', dependsOn: [] },
99
+ { slug: '150-sink', agentType: 'dev-lead', status: 'pending', dependsOn: ['222-beta'] },
100
+ { slug: '999-validate', agentType: 'validator', status: 'pending', dependsOn: ['150-sink'] },
101
+ ];
102
+ expect(hasDownstreamValidator(job, jobs)).toBe(false);
103
+ });
104
+
105
+ test('cycle in dependsOn terminates and returns false when the job is not reachable', () => {
106
+ const job = { slug: '111-alpha' };
107
+ const jobs = [
108
+ job,
109
+ { slug: '200-a', agentType: 'dev-lead', status: 'pending', dependsOn: ['201-b'] },
110
+ { slug: '201-b', agentType: 'dev-lead', status: 'pending', dependsOn: ['200-a'] },
111
+ { slug: '999-validate', agentType: 'validator', status: 'pending', dependsOn: ['200-a'] },
112
+ ];
113
+ expect(hasDownstreamValidator(job, jobs)).toBe(false);
114
+ });
115
+
116
+ test('false when a same-named validator/sink pair belongs to a different project (cwd)', () => {
117
+ const job = { slug: '011-alpha', cwd: '/projectA' };
118
+ const jobs = [
119
+ job,
120
+ { slug: '012-sink', cwd: '/projectA', agentType: 'dev-lead', status: 'pending', dependsOn: [] },
121
+ { slug: '512-sink', cwd: '/projectB', agentType: 'dev-lead', status: 'pending', dependsOn: ['011-alpha'] },
122
+ { slug: '999-validate', cwd: '/projectB', agentType: 'validator', status: 'pending', dependsOn: ['sink'] },
123
+ ];
124
+ expect(hasDownstreamValidator(job, jobs)).toBe(false);
125
+ });
@@ -0,0 +1,205 @@
1
+ /**
2
+ * prdCreateAdoption.test.cjs — PRD 1446: scheduler_create_prd wrote a PRD
3
+ * file and promised its queue row "on the next reconcile pass (~1 minute)",
4
+ * but nothing reliably ran that pass. The 60s pollLoop only reaches
5
+ * reconcile() via maybeLaunchWhenAvailable, which returns early while zero
6
+ * rows are pending; the 10-minute rescheduleTimer awaits refreshNextReset()
7
+ * -> billing.fetchUsage() BEFORE reconciling, and stalled indefinitely while
8
+ * the usage meter was rate-limited (PRDs 1420-1441 sat unadopted 17+
9
+ * minutes, 2026-09-25).
10
+ *
11
+ * Two fixes, exercised here:
12
+ * 1. scheduler.remote gained `requestReconcile()` — the SAME broadcast
13
+ * coalescer / reconcile() seam `remote.resetJob` already used (no
14
+ * second reconcile implementation) — and prdCreate.cjs's createPrd()
15
+ * calls it right after a successful write.
16
+ * 2. rescheduleTimer's refreshNextReset() await is now bounded by a
17
+ * RESCHEDULE_TIMER_BILLING_RACE_MS Promise.race against the cached
18
+ * reset value, so its own mutate(reconcile) still runs even when
19
+ * billing.fetchUsage() never resolves.
20
+ *
21
+ * HOME-isolated + fixture-project pattern mirrors reconcileTiming.test.cjs.
22
+ *
23
+ * Run: timeout 300 npx vitest run src/main/__tests__/prdCreateAdoption.test.cjs
24
+ */
25
+
26
+ 'use strict';
27
+
28
+ import {
29
+ test, expect, beforeAll, afterAll, afterEach, vi,
30
+ } from 'vitest';
31
+ const fs = require('node:fs');
32
+ const os = require('node:os');
33
+ const path = require('node:path');
34
+
35
+ let tmpHome;
36
+ let originalHome;
37
+ let scheduler;
38
+ let usage;
39
+ let config;
40
+ let createPrd;
41
+
42
+ /** A bare cwd for the fake-remote createPrd() tests below — these don't go
43
+ * through a real Epic/queue, so all they need is a directory config.cjs's
44
+ * validatePath will accept. Not os.homedir(): this file's beforeAll swaps
45
+ * process.env.HOME for scheduler.cjs's isolation, so os.homedir() called
46
+ * from inside a test would resolve to tmpHome instead of the real home
47
+ * config.cjs's allowedRoots snapshot was seeded with at import time. */
48
+ function makeAllowedCwd(prefix) {
49
+ const cwd = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
50
+ config.addAllowedRoot(cwd);
51
+ return cwd;
52
+ }
53
+
54
+ beforeAll(() => {
55
+ originalHome = process.env.HOME;
56
+ tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'sm-prd-adoption-home-'));
57
+ process.env.HOME = tmpHome;
58
+
59
+ // Required AFTER HOME is swapped, never at module top level: activeSessions.cjs
60
+ // (pulled in transitively by prdCreate.cjs/scheduler.cjs) snapshots
61
+ // `os.homedir()` into a module-scope constant at first require — loading it
62
+ // before this reassignment would permanently bake in the vitest sandbox's
63
+ // own HOME (tests/setup/schedulerSandbox.globalSetup.cjs) instead of this
64
+ // file's tmpHome, silently breaking every ~/.claude/projects-scan-dependent
65
+ // assertion below (allProjectCwds/reconcile would always come back empty).
66
+ scheduler = require('../scheduler.cjs');
67
+ usage = require('../usage.cjs');
68
+ config = require('../config.cjs');
69
+ ({ createPrd } = require('../lib/prdCreate.cjs'));
70
+
71
+ if (!scheduler.PRDS_DIR.startsWith(tmpHome)) {
72
+ throw new Error(`refusing to run: PRDS_DIR (${scheduler.PRDS_DIR}) is not under the temp HOME (${tmpHome})`);
73
+ }
74
+ });
75
+
76
+ afterAll(() => {
77
+ process.env.HOME = originalHome;
78
+ fs.rmSync(tmpHome, { recursive: true, force: true });
79
+ });
80
+
81
+ afterEach(() => {
82
+ vi.restoreAllMocks();
83
+ vi.useRealTimers();
84
+ });
85
+
86
+ function registerActiveProject(cwd) {
87
+ const projectsDir = path.join(tmpHome, '.claude', 'projects');
88
+ const slugDir = path.join(projectsDir, `fake-project-slug-${path.basename(cwd)}`);
89
+ fs.mkdirSync(slugDir, { recursive: true });
90
+ fs.writeFileSync(path.join(slugDir, 'transcript.jsonl'), `${JSON.stringify({ cwd })}\n`);
91
+ }
92
+
93
+ function makeFixtureProject(prefix) {
94
+ const cwd = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
95
+ registerActiveProject(cwd);
96
+ return cwd;
97
+ }
98
+
99
+ function writeCanonicalPrd(cwd, epicId, slug) {
100
+ const epicPrdsDir = path.join(cwd, 'session-manager-operations', 'scheduler', 'epics', epicId, 'prds');
101
+ fs.mkdirSync(epicPrdsDir, { recursive: true });
102
+ fs.writeFileSync(
103
+ path.join(epicPrdsDir, `${slug}.md`),
104
+ `---\ntitle: Adoption fixture\ncwd: ${cwd}\nestimateMinutes: 10\nsourcePromptId: ${epicId}\ncreatedVia: scheduler-api\nissuedAt: 2026-09-25T00:00:00.000Z\n---\n\n# Goal\n\nSomething.\n`,
105
+ 'utf8',
106
+ );
107
+ }
108
+
109
+ test('remote.requestReconcile() adopts a freshly-created PRD into a pending row with no tickQueue call', async () => {
110
+ const cwd = makeFixtureProject('sm-prd-adoption-fresh-');
111
+ writeCanonicalPrd(cwd, 'epic-fresh', '9001-fresh');
112
+
113
+ const tickQueueSpy = vi.spyOn(scheduler, 'tickQueue');
114
+
115
+ await scheduler.remote.requestReconcile();
116
+
117
+ expect(tickQueueSpy).not.toHaveBeenCalled();
118
+ const job = await scheduler.remote.getJob('9001-fresh');
119
+ expect(job).not.toBeNull();
120
+ expect(job.status).toBe('pending');
121
+ });
122
+
123
+ test('createPrd() calls remote.requestReconcile() once after a successful write and reports enqueued:true once the row exists', async () => {
124
+ const writes = new Map();
125
+ const requestReconcile = vi.fn(async () => {});
126
+ const remote = {
127
+ async allocateParallelGroup() { return '9002'; },
128
+ async readPrd(slug) {
129
+ return writes.has(slug) ? { ok: true, text: writes.get(slug) } : { ok: false, error: 'missing' };
130
+ },
131
+ async writePrd(slug, body) {
132
+ writes.set(slug, body);
133
+ return { ok: true, path: `/fake/${slug}.md` };
134
+ },
135
+ async listPrds() { return { prds: [], total: 0, limit: 0, offset: 0, hasMore: false }; },
136
+ requestReconcile,
137
+ // Simulates the reconcile pass having already produced the queue row by
138
+ // the time createPrd() checks for it.
139
+ async getJob(slug) { return writes.has(slug) ? { slug, status: 'pending' } : null; },
140
+ };
141
+
142
+ const result = await createPrd({
143
+ title: 'Adoption wiring check',
144
+ cwd: makeAllowedCwd('sm-prd-adoption-hit-'),
145
+ estimateMinutes: 10,
146
+ goal: 'g',
147
+ acceptanceCriteria: ['a'],
148
+ implementationNotes: 'n',
149
+ }, remote);
150
+
151
+ expect(result.ok).toBe(true);
152
+ expect(requestReconcile).toHaveBeenCalledTimes(1);
153
+ expect(result.enqueued).toBe(true);
154
+ expect(result.note).not.toMatch(/derived by the next scheduler reconcile pass/);
155
+ });
156
+
157
+ test('createPrd() reports enqueued:false with the deferred-pass note when the row is not visible right after reconcile', async () => {
158
+ const writes = new Map();
159
+ const requestReconcile = vi.fn(async () => {});
160
+ const remote = {
161
+ async allocateParallelGroup() { return '9003'; },
162
+ async readPrd(slug) {
163
+ return writes.has(slug) ? { ok: true, text: writes.get(slug) } : { ok: false, error: 'missing' };
164
+ },
165
+ async writePrd(slug, body) {
166
+ writes.set(slug, body);
167
+ return { ok: true, path: `/fake/${slug}.md` };
168
+ },
169
+ async listPrds() { return { prds: [], total: 0, limit: 0, offset: 0, hasMore: false }; },
170
+ requestReconcile,
171
+ async getJob() { return null; },
172
+ };
173
+
174
+ const result = await createPrd({
175
+ title: 'Adoption wiring miss',
176
+ cwd: makeAllowedCwd('sm-prd-adoption-miss-'),
177
+ estimateMinutes: 10,
178
+ goal: 'g',
179
+ acceptanceCriteria: ['a'],
180
+ implementationNotes: 'n',
181
+ }, remote);
182
+
183
+ expect(result.ok).toBe(true);
184
+ expect(requestReconcile).toHaveBeenCalledTimes(1);
185
+ expect(result.enqueued).toBe(false);
186
+ expect(result.note).toMatch(/derived by the next scheduler reconcile pass/);
187
+ });
188
+
189
+ test('rescheduleTimer still reconciles when billing.fetchUsage() never resolves', async () => {
190
+ const cwd = makeFixtureProject('sm-prd-adoption-stall-');
191
+ writeCanonicalPrd(cwd, 'epic-stall', '9004-stall');
192
+
193
+ vi.spyOn(usage, 'fetchUsage').mockImplementation(() => new Promise(() => {}));
194
+ vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] });
195
+
196
+ const pending = scheduler.rescheduleTimer();
197
+ await vi.advanceTimersByTimeAsync(scheduler.RESCHEDULE_TIMER_BILLING_RACE_MS);
198
+ await pending;
199
+
200
+ vi.useRealTimers();
201
+
202
+ const job = await scheduler.remote.getJob('9004-stall');
203
+ expect(job).not.toBeNull();
204
+ expect(job.status).toBe('pending');
205
+ }, 15_000);
@@ -5,22 +5,39 @@
5
5
  *
6
6
  * selectAutoArchivable is pure (no fs) so it's fully covered here without
7
7
  * touching disk. autoArchiveCompleted's disk-mutating path (archiveMany) is
8
- * exercised only via its kill-switch / no-op branches, since archiveMany
9
- * targets the real ~/.claude/session-manager/scheduled-plans/prds-archived
10
- * directory (not test-injectable) — mutating that from a test run would be
11
- * an unwanted side effect on the developer's real filesystem.
8
+ * mostly exercised only via its kill-switch / no-op branches, since
9
+ * archiveMany's default destination is not test-injectable — except for the
10
+ * two retire-flag tests below, which write into PRDS_DIR (a lazy getter
11
+ * resolved under this run's SM_SCHEDULER_HOME sandbox — see
12
+ * tests/setup/schedulerSandbox.cjs — so they never touch a real
13
+ * ~/.claude/session-manager tree) and stub 'electron' via require.cache so
14
+ * registerQueueOpsHandlers' ipcMain.handle calls are no-ops outside a real
15
+ * Electron process. 'electron' is an externalized node_modules dependency
16
+ * under vitest, so vi.mock('electron', ...) never intercepts queueOps.cjs's
17
+ * own require('electron') — pre-seeding require.cache for its resolved path
18
+ * is the one hook that reaches it.
12
19
  *
13
20
  * Run: timeout 300 npx vitest run src/main/__tests__/queueOpsAutoArchive.test.cjs
14
21
  */
15
22
 
16
23
  'use strict';
17
24
 
18
- import { test, expect, afterEach } from 'vitest';
25
+ import { test, expect, afterEach, vi } from 'vitest';
26
+ const fs = require('node:fs');
27
+ const path = require('node:path');
28
+
29
+ const electronPath = require.resolve('electron');
30
+ require.cache[electronPath] = {
31
+ id: electronPath,
32
+ filename: electronPath,
33
+ loaded: true,
34
+ exports: { ipcMain: { handle: () => {} } },
35
+ };
19
36
 
20
37
  const RETENTION_MS = 7 * 24 * 60 * 60_000;
21
38
  const NOW = Date.parse('2026-07-24T12:00:00.000Z');
22
39
 
23
- const { selectAutoArchivable, autoArchiveCompleted } = require('../queueOps.cjs');
40
+ const { selectAutoArchivable, autoArchiveCompleted, archiveMany, registerQueueOpsHandlers, PRDS_DIR } = require('../queueOps.cjs');
24
41
 
25
42
  function fresh(overrides = {}) {
26
43
  return {
@@ -152,3 +169,43 @@ test('selectAutoArchivable never selects a slug whose job is still pending or ru
152
169
  const slugs = selectAutoArchivable([pending, running, completed], { nowMs: NOW });
153
170
  expect(slugs).toEqual(['15-done']);
154
171
  });
172
+
173
+ // ---------- retire-flag deadlock guard (PRD 1442: reconcile() -> mutate()
174
+ // body -> autoArchiveCompleted -> archiveMany -> retireCompletedSlugsFn ->
175
+ // mutate() re-entered every tick, so mutateTail never settled) ----------
176
+
177
+ test('autoArchiveCompleted never invokes retireCompletedSlugs', async () => {
178
+ const slug = 'test-auto-archive-no-retire';
179
+ fs.mkdirSync(PRDS_DIR, { recursive: true });
180
+ const src = path.join(PRDS_DIR, `${slug}.md`);
181
+ fs.writeFileSync(src, '# Goal\n\ntest\n', 'utf8');
182
+
183
+ const spy = vi.fn(async () => {});
184
+ registerQueueOpsHandlers({ retireCompletedSlugs: spy });
185
+
186
+ const job = old({ slug, status: 'completed' });
187
+ const result = await autoArchiveCompleted({ jobs: [job] }, { nowMs: NOW });
188
+
189
+ expect(result.archived).toBe(1);
190
+ expect(fs.existsSync(src)).toBe(false);
191
+ expect(result.results[0].ok).toBe(true);
192
+ expect(fs.existsSync(result.results[0].archivedTo)).toBe(true);
193
+ expect(spy).not.toHaveBeenCalled();
194
+ });
195
+
196
+ test('manual archiveMany still retires', async () => {
197
+ const slug = 'test-manual-archive-still-retires';
198
+ fs.mkdirSync(PRDS_DIR, { recursive: true });
199
+ const src = path.join(PRDS_DIR, `${slug}.md`);
200
+ fs.writeFileSync(src, '# Goal\n\ntest\n', 'utf8');
201
+
202
+ const spy = vi.fn(async () => {});
203
+ registerQueueOpsHandlers({ retireCompletedSlugs: spy });
204
+
205
+ const result = await archiveMany([slug]);
206
+
207
+ expect(result.archived).toBe(1);
208
+ expect(fs.existsSync(src)).toBe(false);
209
+ expect(spy).toHaveBeenCalledTimes(1);
210
+ expect(spy).toHaveBeenCalledWith([slug]);
211
+ });
@@ -0,0 +1,117 @@
1
+ /**
2
+ * scheduler-mutate-reentrancy.test.cjs — regression cover for PRD 1443.
3
+ *
4
+ * mutate()'s chain (`mutateTail = mutateTail.then(...)`) is the single-writer
5
+ * lock over queue.json. Calling mutate() again from INSIDE a still-running
6
+ * mutate body (and awaiting it) used to queue the inner call behind
7
+ * mutateTail — which the outer call itself is holding — so the inner
8
+ * `await` never resolved and the whole scheduler froze (PRD 1442 was the one
9
+ * known path: reconcile -> autoArchiveCompleted -> retireCompletedSlugs ->
10
+ * mutate). The fix tracks "am I inside a live mutate body" via
11
+ * AsyncLocalStorage and rejects immediately on re-entry instead of
12
+ * deadlocking.
13
+ *
14
+ * HOME-isolated (mirrors scheduler-broadcast-reconcile.test.cjs): stub HOME to
15
+ * a mkdtemp dir and mock queueStore's read/write so this never touches real
16
+ * queue.json.
17
+ *
18
+ * Run: timeout 120 npx vitest run src/main/__tests__/scheduler-mutate-reentrancy.test.cjs
19
+ */
20
+ 'use strict';
21
+
22
+ import { test, expect, beforeAll, afterAll, afterEach, vi } from 'vitest';
23
+ const fs = require('node:fs');
24
+ const os = require('node:os');
25
+ const path = require('node:path');
26
+
27
+ let tmpHome;
28
+ let originalHome;
29
+ let scheduler;
30
+ let queueStore;
31
+
32
+ beforeAll(() => {
33
+ originalHome = process.env.HOME;
34
+ tmpHome = fs.mkdtempSync(path.join(os.tmpdir(), 'sm-mutate-reentrancy-home-'));
35
+ process.env.HOME = tmpHome;
36
+
37
+ scheduler = require('../scheduler.cjs');
38
+ queueStore = require('../lib/queueStore.cjs');
39
+
40
+ if (!scheduler.PRDS_DIR.startsWith(tmpHome)) {
41
+ throw new Error(`refusing to run: PRDS_DIR (${scheduler.PRDS_DIR}) is not under the temp HOME (${tmpHome})`);
42
+ }
43
+ });
44
+
45
+ afterAll(() => {
46
+ process.env.HOME = originalHome;
47
+ fs.rmSync(tmpHome, { recursive: true, force: true });
48
+ });
49
+
50
+ function freshState() {
51
+ return { config: {}, jobs: [], scheduledFor: null, lastRunAt: null, paused: null };
52
+ }
53
+
54
+ function wait(ms) {
55
+ return new Promise((resolve) => setTimeout(resolve, ms));
56
+ }
57
+
58
+ afterEach(() => {
59
+ vi.restoreAllMocks();
60
+ });
61
+
62
+ test('nested awaited mutate rejects instead of hanging', async () => {
63
+ vi.spyOn(queueStore, 'readMerged').mockImplementation(async () => freshState());
64
+ vi.spyOn(queueStore, 'writeSplit').mockResolvedValue(undefined);
65
+
66
+ let innerRejection = null;
67
+ const outerPromise = scheduler._mutateForTests(async () => {
68
+ try {
69
+ await scheduler._mutateForTests(async () => 'inner-should-never-resolve');
70
+ } catch (err) {
71
+ innerRejection = err;
72
+ }
73
+ return 'outer-done';
74
+ });
75
+
76
+ const result = await Promise.race([
77
+ outerPromise,
78
+ wait(2000).then(() => { throw new Error('outer mutate did not settle within 2s'); }),
79
+ ]);
80
+
81
+ expect(result).toBe('outer-done');
82
+ expect(innerRejection).toBeInstanceOf(Error);
83
+ expect(innerRejection.message).toMatch(/re-entered/i);
84
+ });
85
+
86
+ test('mutate scheduled via setTimeout from a finished body runs normally', async () => {
87
+ vi.spyOn(queueStore, 'readMerged').mockImplementation(async () => freshState());
88
+ vi.spyOn(queueStore, 'writeSplit').mockResolvedValue(undefined);
89
+
90
+ let deferredResult = null;
91
+ let deferredError = null;
92
+
93
+ await scheduler._mutateForTests(async () => {
94
+ setTimeout(() => {
95
+ scheduler._mutateForTests(async () => 'deferred-ok')
96
+ .then((r) => { deferredResult = r; })
97
+ .catch((err) => { deferredError = err; });
98
+ }, 10);
99
+ return 'immediate';
100
+ });
101
+
102
+ await wait(300);
103
+
104
+ expect(deferredError).toBeNull();
105
+ expect(deferredResult).toBe('deferred-ok');
106
+ });
107
+
108
+ test('sequential mutates unaffected', async () => {
109
+ vi.spyOn(queueStore, 'readMerged').mockImplementation(async () => freshState());
110
+ vi.spyOn(queueStore, 'writeSplit').mockResolvedValue(undefined);
111
+
112
+ const r1 = await scheduler._mutateForTests(async () => 'first');
113
+ const r2 = await scheduler._mutateForTests(async () => 'second');
114
+
115
+ expect(r1).toBe('first');
116
+ expect(r2).toBe('second');
117
+ });