chamba 0.7.0 → 0.9.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 (134) hide show
  1. package/LICENSE +53 -14
  2. package/README.md +34 -8
  3. package/dist/commands/advanced.js +7 -278
  4. package/dist/commands/dev.js +11 -612
  5. package/dist/commands/doctor.js +1 -29
  6. package/dist/commands/menu.js +1 -80
  7. package/dist/commands/onboard.js +6 -230
  8. package/dist/commands/settings.js +15 -349
  9. package/dist/lib/agent-commands.js +2 -0
  10. package/dist/lib/agent-context.js +6 -210
  11. package/dist/lib/browser.js +1 -40
  12. package/dist/lib/chamba-yaml.js +10 -191
  13. package/dist/lib/constants.js +1 -125
  14. package/dist/lib/dockerfile-builder.js +41 -261
  15. package/dist/lib/env.js +2 -78
  16. package/dist/lib/git-env.js +1 -21
  17. package/dist/lib/global-config.js +4 -66
  18. package/dist/lib/pnpm-store.js +1 -19
  19. package/dist/lib/ports.js +1 -210
  20. package/dist/lib/safe-rm.js +1 -36
  21. package/dist/lib/sessions.js +2 -34
  22. package/dist/lib/shadows.js +1 -176
  23. package/dist/lib/skills.js +2 -0
  24. package/dist/lib/templates.js +1 -0
  25. package/dist/lib/webterm.js +1 -305
  26. package/dist/lib/workspace-identity.js +4 -260
  27. package/package.json +4 -4
  28. package/templates/Dockerfile +15 -22
  29. package/templates/claude-statusline.sh +5 -7
  30. package/templates/context/baseline.md +4 -2
  31. package/templates/context/web-pane-craft.md +1 -1
  32. package/templates/pane-apps/client/assets/api-BBDf_rzz.js +12 -0
  33. package/templates/pane-apps/client/assets/api-DNLbSBpK.css +1 -0
  34. package/templates/pane-apps/client/assets/bee-B7t97l5B.webp +0 -0
  35. package/templates/pane-apps/client/assets/buzz-CUUsbnXH.mp3 +0 -0
  36. package/templates/pane-apps/client/assets/c-BNa-DeUl.json +3552 -0
  37. package/templates/pane-apps/client/assets/cpp-B-T4NRoH.json +20239 -0
  38. package/templates/pane-apps/client/assets/csharp-BbxHChhA.json +6010 -0
  39. package/templates/pane-apps/client/assets/css-CWCxuwmz.json +1860 -0
  40. package/templates/pane-apps/client/assets/diff-B-2N89g8.json +154 -0
  41. package/templates/pane-apps/client/assets/docker-DWTvYW26.json +103 -0
  42. package/templates/pane-apps/client/assets/files-BkmyervY.js +1 -0
  43. package/templates/pane-apps/client/assets/go-B2hyYeNg.json +3156 -0
  44. package/templates/pane-apps/client/assets/graphql-Z6Id2aNO.json +1292 -0
  45. package/templates/pane-apps/client/assets/home-3SeGzySM.css +1 -0
  46. package/templates/pane-apps/client/assets/home-Cu9xOd2i.js +1 -0
  47. package/templates/pane-apps/client/assets/html-BtzvlIfu.json +2627 -0
  48. package/templates/pane-apps/client/assets/ini-Bn3Twap1.json +108 -0
  49. package/templates/pane-apps/client/assets/java-C7t2dwLO.json +1885 -0
  50. package/templates/pane-apps/client/assets/javascript-DuC2v0C0.json +5996 -0
  51. package/templates/pane-apps/client/assets/json-CwdkWeV5.json +206 -0
  52. package/templates/pane-apps/client/assets/jsonc-MYWDbTU3.json +206 -0
  53. package/templates/pane-apps/client/assets/jsx-Cn8EZuIC.json +5996 -0
  54. package/templates/pane-apps/client/assets/kotlin-CFNOz1gw.json +580 -0
  55. package/templates/pane-apps/client/assets/make-BVnlFCcl.json +629 -0
  56. package/templates/pane-apps/client/assets/markdown-B4Xk2WM_.json +3263 -0
  57. package/templates/pane-apps/client/assets/php-CAQzQmmI.json +4188 -0
  58. package/templates/pane-apps/client/assets/pop-D5ZANBC3.mp3 +0 -0
  59. package/templates/pane-apps/client/assets/python-CYQee8m4.json +4174 -0
  60. package/templates/pane-apps/client/assets/reviews-DMrGB-kG.js +153 -0
  61. package/templates/pane-apps/client/assets/reviews-nK_yRav9.css +1 -0
  62. package/templates/pane-apps/client/assets/ruby-D7R58tus.json +3114 -0
  63. package/templates/pane-apps/client/assets/rust-BFBbFiei.json +1103 -0
  64. package/templates/pane-apps/client/assets/scss-TQRhBkPG.json +1874 -0
  65. package/templates/pane-apps/client/assets/shellscript-DieAkC4W.json +2375 -0
  66. package/templates/pane-apps/client/assets/specs-Cabb15F0.js +13 -0
  67. package/templates/pane-apps/client/assets/sql-Bxd030LV.json +634 -0
  68. package/templates/pane-apps/client/assets/toml-ChrKGzsV.json +430 -0
  69. package/templates/pane-apps/client/assets/tsx-D2e90MFw.json +5996 -0
  70. package/templates/pane-apps/client/assets/typescript-DonXQ_n1.json +5747 -0
  71. package/templates/pane-apps/client/assets/useNow-BHFKFraS.js +1 -0
  72. package/templates/pane-apps/client/assets/xml-B17r2RXF.json +382 -0
  73. package/templates/pane-apps/client/assets/yaml-CKn4h1zy.json +627 -0
  74. package/templates/pane-apps/client/home/index.html +16 -0
  75. package/templates/pane-apps/client/reviews/index.html +17 -0
  76. package/templates/pane-apps/client/specs/index.html +4 -2
  77. package/templates/pane-apps/server/home.mjs +12 -0
  78. package/templates/pane-apps/server/reviews.mjs +21 -0
  79. package/templates/pane-apps/server/specs.mjs +5 -1588
  80. package/templates/skills/chamba-statusline/SKILL.md +7 -19
  81. package/templates/skills/dx-review/SKILL.md +136 -0
  82. package/templates/skills/dx-review/references/acts.md +233 -0
  83. package/templates/skills/dx-spec/SKILL.md +230 -30
  84. package/templates/skills/dx-spec/references/principles-template.md +2 -0
  85. package/templates/skills/dx-spec/references/review-guide.md +6 -52
  86. package/templates/skills/dx-spec/references/spec-guide.md +25 -5
  87. package/templates/skills/dx-spec/references/stages.md +149 -60
  88. package/templates/skills/dx-spec-execute/SKILL.md +217 -38
  89. package/templates/startup.mjs +22 -16
  90. package/templates/tool-helper.sh +168 -0
  91. package/templates/webterm/README.md +82 -27
  92. package/templates/webterm/color.js +61 -0
  93. package/templates/webterm/config.js +55 -4
  94. package/templates/webterm/context/claude.md +0 -1
  95. package/templates/webterm/public/app/alerts.js +95 -14
  96. package/templates/webterm/public/app/anchored.js +81 -0
  97. package/templates/webterm/public/app/composer.js +37 -3
  98. package/templates/webterm/public/app/connection.js +23 -0
  99. package/templates/webterm/public/app/dom.js +3 -0
  100. package/templates/webterm/public/app/frames.js +52 -18
  101. package/templates/webterm/public/app/home-host.js +16 -0
  102. package/templates/webterm/public/app/main.js +24 -8
  103. package/templates/webterm/public/app/new-session.js +13 -41
  104. package/templates/webterm/public/app/palette.js +58 -0
  105. package/templates/webterm/public/app/pane-shape.js +169 -0
  106. package/templates/webterm/public/app/pane-shell.js +240 -135
  107. package/templates/webterm/public/app/pane.js +39 -24
  108. package/templates/webterm/public/app/reviews-host.js +19 -0
  109. package/templates/webterm/public/app/specs-host.js +12 -218
  110. package/templates/webterm/public/app/state.js +5 -0
  111. package/templates/webterm/public/app/tabs.js +6 -2
  112. package/templates/webterm/public/app/theme.js +75 -27
  113. package/templates/webterm/public/app/tool-host.js +318 -0
  114. package/templates/webterm/public/app/workspace-color.js +192 -0
  115. package/templates/webterm/public/index.html +22 -4
  116. package/templates/webterm/public/styles.css +195 -21
  117. package/templates/webterm/server.js +198 -150
  118. package/templates/webterm/tool-document.js +3 -2
  119. package/templates/webterm/tools/commands.js +61 -0
  120. package/templates/webterm/tools/home.js +58 -0
  121. package/templates/webterm/tools/index.js +26 -0
  122. package/templates/webterm/tools/mount.js +337 -0
  123. package/templates/webterm/tools/paths.js +34 -0
  124. package/templates/webterm/tools/reviews.js +137 -0
  125. package/templates/webterm/tools/specs.js +154 -0
  126. package/templates/webterm/typed-line.js +70 -7
  127. package/templates/context/context-usage.md +0 -1
  128. package/templates/context-usage.sh +0 -266
  129. package/templates/pane-apps/client/assets/specs-B1970L17.css +0 -1
  130. package/templates/pane-apps/client/assets/specs-cEee_SPn.js +0 -23
  131. package/templates/skills/dx-spec-config/SKILL.md +0 -313
  132. package/templates/skills/dx-spec-config/references/principles-template.md +0 -12
  133. package/templates/specs.sh +0 -106
  134. package/templates/webterm/specs.js +0 -358
@@ -0,0 +1,13 @@
1
+ import{A as e,D as t,E as n,O as r,S as i,_ as a,a as o,c as s,d as c,f as l,g as u,h as d,i as f,l as p,m,n as h,o as g,p as _,t as ee,u as te,v,w as y,x as b}from"./api-BBDf_rzz.js";import{a as ne,i as x,n as S,o as re}from"./files-BkmyervY.js";var C=e(),w=r();function ie(e){let t=e.replace(/\r\n?/g,`
2
+ `).trim(),n=5381;for(let e=0;e<t.length;e++)n=(n*33^t.charCodeAt(e))>>>0;return n.toString(36)}function ae(e,t){return t?.readHash?t.readHash===e?{read:!0,changed:!1}:{read:!1,changed:!0}:{read:!1,changed:!1}}function T(e){return e===`markdown`||e===`text`}function E(e){let t=[],n=[];if(e.kind===`markdown`&&typeof e.text==`string`)for(let r of te(e.text)){let i=ie(r.heading?`## ${r.heading}\n${r.body}`:r.body);t.push({heading:r.heading,body:r.body,hash:i}),n.push(c(e.path,r.heading))}else{let r=e.text,i=ie(typeof r==`string`?r:e.fingerprint??e.path);t.push({heading:null,body:typeof r==`string`?r:``,hash:i}),n.push(c(e.path,null))}let r=g(n);return t.map((e,t)=>({...e,id:r[t]}))}function oe(e,t,n){let r=c(t,n);return e.find(e=>e.id===r)??null}var se=600;function ce(e,t){let[n,r]=(0,C.useState)(t.empty),[i,a]=(0,C.useState)(null),o=(0,C.useRef)(t);o.current=t;let s=(0,C.useRef)(n),c=(0,C.useRef)(null),l=(0,C.useRef)(null),u=(0,C.useRef)(!1),d=(0,C.useRef)(0),f=(0,C.useRef)(0),p=(0,C.useRef)(!1),m=(0,C.useCallback)(e=>{s.current=e,r(e)},[]),h=(0,C.useCallback)(()=>{if(e===null)return;let t=e,n=d.current;o.current.get(t).then(e=>{if(d.current===n){if(f.current>0||l.current!==null){p.current=!0;return}u.current=!0,m(e),a(null)}}).catch(()=>{d.current===n&&(u.current=!1,a(o.current.whenUnreadable))})},[e,m]),g=(0,C.useCallback)(()=>{f.current>0||!p.current||(p.current=!1,h())},[h]),_=(0,C.useCallback)(t=>{if(e===null||!u.current||o.current.persist===!1){g();return}let n=d.current;f.current+=1,o.current.put(e,t).then(()=>a(null),()=>a(o.current.whenUnwritable)).finally(()=>{d.current===n&&(--f.current,g())})},[e,g]);return(0,C.useEffect)(()=>{d.current+=1,u.current=!1,f.current=0,p.current=!1,m(o.current.empty()),a(null),h()},[h,m]),(0,C.useEffect)(()=>()=>{c.current&&clearTimeout(c.current),l.current&&_(l.current),l.current=null,c.current=null},[_]),{value:n,update:(0,C.useCallback)((e,t=!1)=>{let n=e(s.current);if(n!==s.current){if(m(n),c.current&&clearTimeout(c.current),c.current=null,t){l.current=null,_(n);return}l.current=n,c.current=setTimeout(()=>{c.current=null;let e=l.current;l.current=null,e&&_(e)},se)}},[m,_]),reload:h,failure:i}}var D=t();function le(e){if(e===null)return[];let t=[],n=e.protocol.filter(e=>e.status!==`done`).length;n>0&&t.push(`${n} ${n===1?`stage`:`stages`} not done`);let r=e.phases.filter(e=>e.status!==`done`).length;r>0&&t.push(`${r} ${r===1?`phase`:`phases`} not done`);let i=e.awaiting.length;return i>0&&t.push(`${i} ${i===1?`thing`:`things`} waiting for an answer`),t}function ue(e){let t=le(e.state);return(0,D.jsx)(`div`,{className:`dialog-shade`,children:(0,D.jsxs)(`div`,{className:`dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":`Archive this spec`,children:[(0,D.jsx)(`h2`,{className:`rail-head`,children:`Archive this spec`}),(0,D.jsxs)(`div`,{className:`dialog-body`,children:[(0,D.jsx)(`p`,{className:`rail-fact muted`,children:`It moves to:`}),(0,D.jsx)(`p`,{className:`archive-target`,children:e.filed}),t.length===0?(0,D.jsx)(`p`,{className:`rail-fact muted`,children:`Nothing is left open.`}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`p`,{className:`rail-fact`,children:[`Still open in `,e.name,`:`]}),(0,D.jsx)(`ul`,{className:`archive-open`,children:t.map(e=>(0,D.jsx)(`li`,{children:e},e))})]}),(0,D.jsx)(`p`,{className:`rail-fact muted`,children:`The tool writes the sign-off and moves the directory. It deletes nothing.`})]}),e.failure!==null&&(0,D.jsx)(`p`,{className:`notice notice-failure`,children:e.failure}),(0,D.jsxs)(`div`,{className:`dialog-acts`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:e.onCancel,disabled:e.working,children:`Cancel`}),(0,D.jsx)(`button`,{type:`button`,className:`send`,onClick:e.onArchive,disabled:e.working,children:e.working?`Archiving…`:`Archive`})]})]})})}var de=new Set(`address article aside audio blockquote br button canvas details div dl dd dt fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 header hr iframe img input label li main nav ol p picture pre section select span style summary svg table tbody td textarea tfoot th thead tr ul video`.split(` `)),fe=new Set(`br hr img input source track wbr col`.split(` `)),pe=/^\s{0,3}(#{1,6})\s+(.*?)\s*#*\s*$/,O=/^(\s*)([-*+]|\d{1,9}[.)])(\s+)(.*)$/,me=/^\s{0,3}([-*_])\s*(?:\1\s*){2,}$/,he=/^\s{0,3}\|?\s*:?-{1,}:?\s*(\|\s*:?-{1,}:?\s*)*\|?\s*$/;function ge(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`)}function _e(e){let t=e.match(/^\s{0,3}<([a-zA-Z][a-zA-Z0-9-]*)(?=[\s/>])/);if(!t)return null;let n=t[1].toLowerCase();return de.has(n)?n:null}function ve(e){let t=ge(e),n=[];t=t.replace(/(`+)([\s\S]*?)\1/g,(e,t,r)=>(n.push(r.replace(/^ (.*) $/,`$1`)),`\uE000c${n.length-1}\uE000`));let r=e=>e.replace(/"/g,`&quot;`);return t=t.replace(/!\[([^\]]*)\]\(([^)\s]+)(?:\s+"[^)]*")?\)/g,(e,t,n)=>`<img alt="${r(t)}" src="${r(n)}">`),t=t.replace(/\[([^\]]+)\]\(([^)\s]+)(?:\s+"[^)]*")?\)/g,(e,t,n)=>`<a href="${r(n)}">${t}</a>`),t=t.replace(/&lt;((?:https?|mailto):[^\s&]+)&gt;/g,`<a href="$1">$1</a>`),t=t.replace(/\*\*(?!\s)([\s\S]+?)(?<!\s)\*\*/g,`<strong>$1</strong>`),t=t.replace(/(^|[^\w\\])__(?!\s)([\s\S]+?)(?<!\s)__(?!\w)/g,`$1<strong>$2</strong>`),t=t.replace(/(^|[^\w*\\])\*(?!\s)([^*\n]+?)(?<!\s)\*(?!\w)/g,`$1<em>$2</em>`),t=t.replace(/(^|[^\w_\\])_(?!\s)([^_\n]+?)(?<!\s)_(?!\w)/g,`$1<em>$2</em>`),t=t.replace(/~~(?!\s)([\s\S]+?)(?<!\s)~~/g,`<del>$1</del>`),t=t.replace(/\uE000c(\d+)\uE000/g,(e,t)=>`<code>${n[+t]}</code>`),t}function k(e){return!e.trim()||o.test(e)||pe.test(e)||me.test(e)||O.test(e)||/^\s{0,3}>/.test(e)||_e(e)!==null||/^\s{0,3}<!--/.test(e)}function A(e){let t=e.replace(/\r\n?/g,`
3
+ `).split(`
4
+ `),n=[],r=0;for(;r<t.length;){let e=t[r];if(!e.trim()){r++;continue}let i=e.match(o);if(i){let e=i[2],a=i[3].trim().split(/\s+/)[0],o=[];for(r++;r<t.length;){let n=t[r].trim();if(n.startsWith(e[0].repeat(e.length))&&/^(`+|~+)$/.test(n)){r++;break}o.push(t[r]),r++}let s=a?` class="language-${ge(a)}"`:``;n.push(`<pre><code${s}>${ge(o.join(`
5
+ `))}</code></pre>`);continue}if(/^\s{0,3}<!--/.test(e)){for(;r<t.length&&!t[r].includes(`-->`);)r++;r++;continue}let a=_e(e);if(a){let i=[t[r]];if(fe.has(a)||/\/>\s*$/.test(e)||e.includes(`</${a}>`))r++;else{let e=1;for(r++;r<t.length&&e>0;){let n=(t[r].match(RegExp(`<${a}(?=[\\s/>])`,`gi`))||[]).length,o=(t[r].match(RegExp(`</${a}\\s*>`,`gi`))||[]).length;e+=n-o,i.push(t[r]),r++}}n.push(i.join(`
6
+ `));continue}let s=e.match(pe);if(s){let e=s[1].length;n.push(`<h${e}>${ve(s[2])}</h${e}>`),r++;continue}if(me.test(e)){n.push(`<hr>`),r++;continue}if(/^\s{0,3}>/.test(e)){let e=[];for(;r<t.length&&(/^\s{0,3}>/.test(t[r])||t[r].trim()&&e.length>0&&!k(t[r]));)e.push(t[r].replace(/^\s{0,3}>\s?/,``)),r++;n.push(`<blockquote>${A(e.join(`
7
+ `))}</blockquote>`);continue}if(e.includes(`|`)&&r+1<t.length&&he.test(t[r+1])&&t[r+1].includes(`-`)){let e=e=>{let t=e.trim();return t.startsWith(`|`)&&(t=t.slice(1)),t.endsWith(`|`)&&!t.endsWith(`\\|`)&&(t=t.slice(0,-1)),t.split(/(?<!\\)\|/).map(e=>e.trim().replace(/\\\|/g,`|`))},i=e(t[r]),a=e(t[r+1]).map(e=>e.startsWith(`:`)&&e.endsWith(`:`)?`center`:e.endsWith(`:`)?`right`:e.startsWith(`:`)?`left`:``),o=e=>a[e]?` class="cell-${a[e]}"`:``,s=[];for(r+=2;r<t.length&&t[r].trim()&&t[r].includes(`|`);)s.push(e(t[r])),r++;n.push(`<table><thead><tr>${i.map((e,t)=>`<th${o(t)}>${ve(e)}</th>`).join(``)}</tr></thead><tbody>${s.map(e=>`<tr>${e.map((e,t)=>`<td${o(t)}>${ve(e)}</td>`).join(``)}</tr>`).join(``)}</tbody></table>`);continue}if(O.test(e)){let[e,i]=ye(t,r);n.push(e),r=i;continue}let c=[];for(;r<t.length&&!k(t[r]);)c.push(t[r].replace(/\s+$/,``)),r++;n.push(`<p>${ve(c.join(`
8
+ `)).replace(/\n/g,`<br>
9
+ `)}</p>`)}return n.join(`
10
+ `)}function ye(e,t){let n=e[t].match(O);if(!n)return[``,t+1];let r=n[1].length,i=/\d/.test(n[2]),a=[],o=t,s=null;for(;o<e.length;){let t=e[o];if(!t.trim()){let t=o+1;for(;t<e.length&&!e[t].trim();)t++;if(t>=e.length)break;let n=e[t].match(O),a=e[t].match(/^\s*/)[0].length,c=n!==null&&/\d/.test(n[2])===i;if(s&&(c&&a>=r||!n&&a>r)){s.push(``),o=t;continue}break}let n=t.match(O),c=t.match(/^\s*/)[0].length;if(n&&c<=r){if(/\d/.test(n[2])!==i)break;s=[n[4]],a.push({lines:s,offset:n[1].length+n[2].length+n[3].length}),o++;continue}if(c>r&&s){s.push(t.slice(Math.min(c,a[a.length-1].offset))),o++;continue}break}let c=a.map(e=>{let t=e.lines.join(`
11
+ `),n=``,r=``,i=t.match(/^\[([ xX])\]\s+([\s\S]*)$/);i&&(n=` class="task"`,r=`<span class="task-box${i[1]===` `?``:` is-done`}"></span>`,t=i[2]);let a=A(t),o=a.match(/^<p>([\s\S]*?)<\/p>([\s\S]*)$/);return o&&!o[1].includes(`<p>`)&&(a=o[1]+o[2]),`<li${n}>${r}${a}</li>`}).join(`
12
+ `);return[(i?`<ol>`:`<ul>`)+c+(i?`</ol>`:`</ul>`),o]}var be=new Set(`p br hr span div a em strong b i u s del ins code pre kbd blockquote ul ol li dl dt dd h1 h2 h3 h4 h5 h6 table thead tbody tr th td caption img details summary figure figcaption sup sub small mark`.split(` `)),xe=new Set([`title`,`class`]),Se={a:new Set([`href`]),img:new Set([`src`,`alt`,`width`,`height`]),ol:new Set([`start`]),details:new Set([`open`]),th:new Set([`colspan`,`rowspan`]),td:new Set([`colspan`,`rowspan`])},j=new Set([`script`,`style`,`textarea`,`title`,`xmp`,`noembed`,`noframes`,`noscript`,`template`]),M={href:`a`,src:`img`},N=new Set([`http:`,`https:`,`mailto:`]);function Ce(e){let t=e.trim();if(t===``)return!1;let n;try{n=new URL(t)}catch{return!0}return N.has(n.protocol)}function we(e,t){return t.includes(`:`)?!1:xe.has(t)?!0:Se[e]?.has(t)??!1}function Te(e){for(let t of[...e.children])Te(t);for(let t of[...e.children]){let e=t.tagName.toLowerCase();if(!be.has(e)){j.has(e)?t.remove():t.replaceWith(...t.childNodes);continue}for(let n of[...t.attributes]){let r=n.name.toLowerCase();if(!we(e,r)){t.removeAttribute(n.name);continue}M[r]===e&&!Ce(n.value)&&t.removeAttribute(n.name)}}return e}function Ee(e,t,n={}){let r=new DOMParser().parseFromString(A(t),`text/html`);Te(r.body),n.imageUrl&&De(r.body,n.imageUrl);let i=e.ownerDocument;e.replaceChildren(...[...r.body.childNodes].map(e=>i.adoptNode(e)))}function De(e,t){for(let n of e.querySelectorAll(`img`)){let e=n.getAttribute(`src`);if(e===null)continue;let r=t(e);r!==null&&n.setAttribute(`src`,r)}}function P({source:e,imageUrl:t,className:n}){let r=(0,C.useRef)(null);return(0,C.useEffect)(()=>{r.current&&Ee(r.current,e,t?{imageUrl:t}:{})},[e,t]),(0,D.jsx)(`div`,{className:n?`prose ${n}`:`prose`,ref:r})}function Oe(e){if(F(e)){if(e.kind===`execution`)return{kind:`execution`};if(e.kind===`checkpoint`&&typeof e.after==`string`&&e.after!==``)return{kind:`checkpoint`,after:e.after}}return{kind:`spec`}}var F=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ke=(e,t=``)=>typeof e==`string`?e:t;function I(e){let t=[];for(let n of Array.isArray(e)?e:[]){if(!F(n)||typeof n.id!=`string`)continue;let e=[];for(let t of Array.isArray(n.options)?n.options:[])!F(t)||typeof t.id!=`string`||e.push({id:t.id,said:ke(t.said,t.id),...t.recommended===!0?{recommended:!0}:{}});t.push({id:n.id,ask:ke(n.ask),options:e,multi:n.multi===!0,...typeof n.invite==`string`&&n.invite!==``?{invite:n.invite}:{}})}return t}function Ae(e){if(!F(e))return{kind:`gate`,asks:``,offer:null};if(e.kind===`decision`){let t=ke(e.heading),n=I(e.questions);return t!==``&&n.length===1?{kind:`decision`,heading:t,questions:n}:{kind:`gate`,asks:``,offer:null}}return e.kind===`round`||Array.isArray(e.questions)?{kind:`round`,questions:I(e.questions)}:{kind:`gate`,asks:ke(e.asks),offer:je(e.offer)}}function je(e){if(!F(e))return null;let t=ke(e.said);return t===``?null:{said:t,preset:e.preset===!0}}function L(e,t){return e.map(e=>{let n=t.get(e.id),r=n?.chosen??[],i=n?.said??``;return{question:e.id,chosen:r,said:i,answered:r.length>0||i.trim()!==``}})}var R=50,z=600,Me={gate:`What should change?`,round:`Anything else?`,decision:`Your words`};function Ne(e){return e.split(`
13
+ `).find(e=>e.trim()!==``)?.trim()??e}function Pe(e){let[t,n]=(0,C.useState)(()=>e.draft?.given??new Map),[r,i]=(0,C.useState)(()=>e.draft?.said??``),a=e.onDraft;(0,C.useEffect)(()=>{a({given:t,said:r})},[t,r,a]);let o=(0,C.useRef)(null),s=(0,C.useRef)(null);(0,C.useEffect)(()=>{let t=e.summon??0;if(!e.settled||s.current===t)return;s.current=t;let n=()=>o.current?.scrollIntoView?.({block:`start`}),r=setTimeout(n,R),i=[o.current?.parentElement,o.current?.previousElementSibling].filter(e=>e instanceof Element),a=typeof ResizeObserver==`function`&&i.length>0?new ResizeObserver(n):null;for(let e of i)a?.observe(e);let c=setTimeout(()=>a?.disconnect(),z);return()=>{clearTimeout(r),clearTimeout(c),a?.disconnect()}},[e.settled,e.summon]);let c=e.ask.kind===`gate`?e.ask.offer:null,[l,u]=(0,C.useState)(c?.preset===!0),d=e.ask.kind===`gate`?[]:e.ask.questions,f=(t,n=[])=>e.onAnswer({outcome:t,said:r.trim(),questions:n,accepted:t===`approved`&&c!==null&&l}),p=()=>{let n=e.ask.kind===`decision`&&d[0]!==void 0?new Map(t).set(d[0].id,{chosen:t.get(d[0].id)?.chosen??[],said:r.trim()}):t;f(`answered`,L(d,n))},m=(e,t,r)=>n(n=>{let i=new Map(n),a=i.get(e)??{chosen:[],said:``},o=r?a.chosen.includes(t)?a.chosen.filter(e=>e!==t):[...a.chosen,t]:[t];return i.set(e,{...a,chosen:o}),i}),h=(e,t)=>n(n=>{let r=new Map(n),i=r.get(e)??{chosen:[],said:``};return r.set(e,{...i,said:t}),r});return(0,D.jsxs)(`section`,{className:`ask`,"aria-label":e.title,ref:o,children:[(0,D.jsxs)(`div`,{className:`ask-head`,children:[(0,D.jsx)(`h2`,{children:e.title}),e.file!==``&&(0,D.jsxs)(`p`,{className:`ask-about`,children:[`about `,(0,D.jsx)(`b`,{children:e.file}),e.ask.kind===`decision`&&(0,D.jsxs)(D.Fragment,{children:[` › `,(0,D.jsx)(`b`,{children:e.ask.heading})]})]})]}),e.ask.kind===`gate`&&e.ask.asks!==``&&(0,D.jsx)(P,{className:`ask-asks`,source:e.ask.asks}),d.length>0&&(0,D.jsx)(`ol`,{className:`questions`,children:d.map(n=>(0,D.jsxs)(`li`,{children:[(0,D.jsx)(P,{className:`question-ask`,source:n.ask}),(0,D.jsx)(`ul`,{className:`choices`,children:n.options.map(e=>(0,D.jsx)(`li`,{className:e.recommended?`is-recommended`:void 0,children:(0,D.jsxs)(`label`,{children:[(0,D.jsx)(`input`,{type:n.multi?`checkbox`:`radio`,name:n.id,checked:t.get(n.id)?.chosen.includes(e.id)??!1,onChange:()=>m(n.id,e.id,n.multi)}),(0,D.jsxs)(`span`,{className:`choice-title`,children:[e.said,e.recommended&&(0,D.jsx)(`span`,{className:`choice-flag`,children:`recommended`})]})]})},e.id))}),e.ask.kind===`round`&&(0,D.jsx)(`textarea`,{className:`question-said`,value:t.get(n.id)?.said??``,placeholder:n.invite??`Your words`,"aria-label":`Anything to add about: ${Ne(n.ask)}`,onChange:e=>h(n.id,e.target.value)})]},n.id))}),(0,D.jsx)(`textarea`,{className:`field-dump`,value:r,placeholder:Me[e.ask.kind],"aria-label":e.ask.kind===`decision`?`Your words`:`Anything else`,onChange:e=>i(e.target.value)}),c!==null&&(0,D.jsxs)(`label`,{className:`ask-offer`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked)}),(0,D.jsx)(`span`,{children:c.said})]}),e.failure!==null&&(0,D.jsx)(`p`,{className:`notice notice-failure`,children:e.failure}),e.asked!==null&&(0,D.jsxs)(`p`,{className:`ask-asked`,children:[`Asked in the terminal: “`,e.asked,`”. This is still waiting for your answer.`]}),(0,D.jsxs)(`div`,{className:`form-acts`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:e.onDismiss,children:`Later`}),(0,D.jsx)(`button`,{type:`button`,className:`ask-question`,disabled:e.sending||r.trim()===``,title:`Send this to the agent in the terminal, and answer nothing`,onClick:()=>void e.onAsk(r.trim()).then(e=>{e&&i(``)}),children:`Ask`}),e.ask.kind===`gate`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`button`,{type:`button`,disabled:e.sending||r.trim()===``,onClick:()=>f(`changes`),children:`Request changes`}),(0,D.jsx)(`button`,{type:`button`,className:`send`,disabled:e.sending,onClick:()=>f(`approved`),children:`Approve`})]}),e.ask.kind!==`gate`&&(0,D.jsx)(`button`,{type:`button`,className:`send`,disabled:e.sending,onClick:p,children:e.sending?`Sending…`:`Submit`})]})]})}function Fe(){return`a-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`}function Ie(e,t,n=``){return{id:Fe(),unit:e.unit,file:e.file,heading:e.heading,kind:t,quote:e.quote,text:n}}function Le(e){return e.quote?`“${Re(e.quote)}”`:e.heading?`${e.file} - ${e.heading}`:e.file||`this spec`}function Re(e,t=80){let n=e.replace(/\s+/g,` `).trim();return n.length<=t?n:`${n.slice(0,t-1)}…`}function ze(e){return e.filter(e=>e.kind===`remove`||e.text.trim()!==``)}function Be(e){return{queued:e.map(e=>e.id),comments:ze(e).map(e=>({unit:e.unit,file:e.file,heading:e.heading,kind:e.kind,quote:e.quote,text:e.text.trim(),assets:[]}))}}function Ve(e){let t=ze(e);if(t.length===0)return``;let n=t.filter(e=>e.kind===`remove`).length,r=t.length-n,i=[];r>0&&i.push(`${r} ${r===1?`comment`:`comments`}`),n>0&&i.push(`${n} to remove`);let a=t[0];return`${i.join(`, `)} - first on ${Le(a)}`}function He(){return{version:1,units:{},dismissed:[]}}function B(e){return{version:1,entry:e,annotations:[]}}var V=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Ue=(e,t=``)=>typeof e==`string`?e:t;function We(e){let t;try{t=JSON.parse(e||`null`)}catch{return He()}if(!V(t)||t.version!==1)return He();let n=He();if(V(t.units))for(let[e,r]of Object.entries(t.units)){if(!V(r))continue;let t={};typeof r.readHash==`string`&&(t.readHash=r.readHash),typeof r.readAt==`string`&&(t.readAt=r.readAt),n.units[e]=t}return Array.isArray(t.dismissed)&&(n.dismissed=t.dismissed.filter(e=>typeof e==`string`)),n}function H(e,t){let n;try{n=JSON.parse(e||`null`)}catch{return B(t)}if(!V(n)||n.version!==1)return B(t);let r=[];if(Array.isArray(n.annotations))for(let e of n.annotations)!V(e)||typeof e.id!=`string`||typeof e.unit!=`string`||e.id===``||e.unit===``||r.push({id:e.id,unit:e.unit,file:Ue(e.file),heading:Ue(e.heading),kind:e.kind===`remove`?`remove`:`comment`,quote:Ue(e.quote),text:Ue(e.text)});return{version:1,entry:Ue(n.entry,t),annotations:r}}var Ge=`quality-review`,Ke=[{id:`exploration`,title:`High-level exploration`,group:`discovery`,about:`We think the problem through together first - directions to take, risks, and what is still unclear.`},{id:`interview`,title:`Interview`,group:`discovery`,about:`I ask you focused questions until nothing important is left open.`},{id:`research`,title:`Research`,group:`discovery`,about:`I look outside your code - a library, a protocol, an algorithm, a subject area - and write up what I find.`},{id:`codebase-analysis`,title:`Codebase analysis`,group:`discovery`,about:`I read the parts of your code this work touches and note what shapes the design.`},{id:`technical-specs`,title:`Technical specs`,group:`deliverables`,about:`A written specification another agent can build from without asking you anything.`},{id:`ui-mocks`,title:`UI mocks`,group:`deliverables`,about:`Mock screens you open in your browser and comment on before anything is built.`},{id:`execution-plan`,title:`Execution plan`,group:`deliverables`,about:`The work split into phases, each with a goal and a way to tell it is done.`},{id:Ge,title:`Specs quality review`,group:`deliverables`,about:`Fresh helper agents review everything we wrote, and I fix what is plainly wrong and bring the judgment calls to you.`}],U=[`exploration`,`ui-mocks`];function W(e){return Ke.find(t=>t.id===e)??null}function qe(e){return[...e].sort((e,t)=>e.startedAt===t.startedAt?0:e.startedAt?t.startedAt?e.startedAt<t.startedAt?-1:1:-1:1)}var Je=`final`;function Ye(e,t){if(e===`final`)return Je;let n=t.find(t=>t.id===e);return n===void 0?null:n.title}var Xe=[`consistency and completeness`,`principles alignment`,`better ways to do this`],G=[{id:`per-phase`,said:`a commit per phase`},{id:`single`,said:`a single commit at the end`},{id:`none`,said:`no commits`}],K=[{id:`current`,said:`the current branch`},{id:`new`,said:`a new branch`}],Ze=[{id:`none`,said:`none`},{id:`chosen`,said:`after chosen phases`},{id:`every`,said:`every phase`}];function Qe(e){return{commits:`per-phase`,branch:`current`,branchName:`spec/${e}`,pauses:`none`,pausePhases:[],checkpoints:[{after:Je,why:`judges the finished work as a whole`,panel:[...Xe],chosen:!0}]}}function $e(e,t=new Date){let{said:n,at:r}=e.activity;if(n===``||r===``||e.log.reduce((e,t)=>t.at>e?t.at:e,``)>r)return null;let i=Date.parse(r);return Number.isNaN(i)||t.getTime()-i>18e5?null:{said:n,at:r}}function q(e,t){return{version:1,name:e,created:t,status:`specifying`,protocol:[],modes:{imagination:!1},wish:{imagination:!1},stageSettings:{research:null},activity:{said:``,at:``},awaiting:[],phases:[],runRecommendations:null,runDecisions:null,reviews:[],approvals:[],log:[]}}var J=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Y=(e,t=``)=>typeof e==`string`?e:t,et=(e,t,n)=>t.includes(e)?e:n,tt=[`specifying`,`ready`,`executing`,`complete`],nt=[`waiting`,`running`,`done`],X=[`gate`,`round`,`protocol`],rt=[`focused`,`named`,`broad`],it=G.map(e=>e.id),at=K.map(e=>e.id),ot=Ze.map(e=>e.id);function st(e){if(!J(e)||e.scope===void 0)return null;let t=et(e.scope,rt,`focused`);return{scope:t,subject:t===`named`?Z(Y(e.subject)):``}}function Z(e,t=200){return e.replace(/\p{C}+/gu,` `).replace(/\s+/g,` `).trim().slice(0,t)}function ct(e){if(!J(e))return null;let t=[];for(let n of Array.isArray(e.checkpoints)?e.checkpoints:[]){if(!J(n))continue;let e=Array.isArray(n.panel)?n.panel.filter(e=>typeof e==`string`).map(e=>Z(e)):[];t.push({after:p(Y(n.after)),why:Z(Y(n.why)),panel:e,chosen:n.chosen!==!1&&e.length>0})}return{commits:et(e.commits,it,`per-phase`),branch:et(e.branch,at,`current`),branchName:Z(Y(e.branchName)),pauses:et(e.pauses,ot,`none`),pausePhases:Array.isArray(e.pausePhases)?e.pausePhases.filter(e=>typeof e==`string`).map(e=>p(e)):[],checkpoints:t}}function lt(e){if(!J(e))return null;let t=ct(e);if(t===null)return null;let n={};if(J(e.pauseReasons))for(let[t,r]of Object.entries(e.pauseReasons)){if(typeof r!=`string`)continue;let e=Z(r);e!==``&&(n[p(t)]=e)}return{...t,pauseReasons:n,noPauseReason:Z(Y(e.noPauseReason))}}function ut(e,t=``,n=``){let r;try{r=JSON.parse(e||`null`)}catch{return q(t,n)}if(!J(r)||r.version!==1)return q(t,n);let i=q(Y(r.name,t),Y(r.created,n)),a=Y(r.status);if(tt.includes(a)&&(i.status=a),Array.isArray(r.protocol))for(let e of r.protocol){if(!J(e)||!W(Y(e.id)))continue;let t=Y(e.status);i.protocol.push({id:Y(e.id),status:nt.includes(t)?t:`waiting`,artifacts:Array.isArray(e.artifacts)?e.artifacts.filter(e=>typeof e==`string`):[],startedAt:Y(e.startedAt)})}if(J(r.modes)&&(i.modes.imagination=r.modes.imagination===!0),J(r.wish)&&(i.wish.imagination=r.wish.imagination===!0),J(r.stageSettings)&&(i.stageSettings={research:st(r.stageSettings.research)}),J(r.activity)&&(i.activity={said:Y(r.activity.said),at:Y(r.activity.at)}),Array.isArray(r.awaiting))for(let e of r.awaiting){if(!J(e)||!e.id)continue;let t=Y(e.kind);i.awaiting.push({id:Y(e.id),kind:X.includes(t)?t:`round`,title:Y(e.title),file:Y(e.file),payload:Y(e.payload),declaredAt:Y(e.declaredAt)})}if(Array.isArray(r.phases))for(let e of r.phases){if(!J(e)||!e.id)continue;let t=Y(e.status);i.phases.push({id:Y(e.id),title:Y(e.title),status:nt.includes(t)?t:`waiting`})}i.runRecommendations=lt(r.runRecommendations);let o=ct(r.runDecisions);if(o!==null&&J(r.runDecisions)&&(i.runDecisions={...o,decidedAt:Y(r.runDecisions.decidedAt)}),Array.isArray(r.reviews))for(let e of r.reviews)!J(e)||typeof e.round!=`number`||i.reviews.push({round:e.round,verdict:Y(e.verdict),findings:typeof e.findings==`number`?e.findings:0,judgments:typeof e.judgments==`number`?e.judgments:0,source:Oe(e.source),at:Y(e.at)});if(Array.isArray(r.approvals))for(let e of r.approvals)!J(e)||!e.id||i.approvals.push({id:Y(e.id),at:Y(e.at),outcome:Y(e.outcome)});if(Array.isArray(r.log))for(let e of r.log)J(e)&&i.log.push({at:Y(e.at),said:Y(e.said)});return i}var Q=h(`specs`);Q.receive;var dt=Q.credentialsReady,ft=Q.onChange,pt=Q.onSession,mt=Q.openOutside,ht=Q.deliver,gt=Q.sayWaiting,_t=Q.listen;function vt(e){return Q.askTheme(e)}var yt=ee({prefix:`specs`,label:`Specs`,credentialsReady:dt});yt.keyHeader;var $=yt.ask;function bt(){return $(`dashboard`)}function xt(e){return $(`entry?path=${encodeURIComponent(e)}`)}function St(e){return $(`archive?entry=${encodeURIComponent(e)}`,{method:`POST`})}function Ct(e){return $(`file?path=${encodeURIComponent(e)}`)}async function wt(e){let t=await $(`state?entry=${encodeURIComponent(e)}`);return We(JSON.stringify(t))}function Tt(e,t){return $(`state?entry=${encodeURIComponent(e)}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)})}async function Et(e){let t=await $(`pending?entry=${encodeURIComponent(e)}`);return H(JSON.stringify(t),e).annotations}function Dt(e,t){return $(`pending?entry=${encodeURIComponent(e)}`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...B(e),annotations:t})})}function Ot(e){return $(`feedback?entry=${encodeURIComponent(e)}`)}function kt(e,t){return $(`feedback?entry=${encodeURIComponent(e)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)})}async function At(e){let t=await $(`protocol?entry=${encodeURIComponent(e)}`);return ut(JSON.stringify(t))}function jt(e,t){return $(`round?entry=${encodeURIComponent(e)}&id=${encodeURIComponent(t)}`)}function Mt(e){return $(`intake`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)})}async function Nt(e,t){let n=await $(`confirm?entry=${encodeURIComponent(e)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});return{state:ut(JSON.stringify(n.state)),change:n.change}}async function Pt(e,t){let n=await $(`decide?entry=${encodeURIComponent(e)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(t)});return ut(JSON.stringify(n))}function Ft(e,t,n){return $(`answer?entry=${encodeURIComponent(e)}&id=${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)})}var It=yt.rawUrl;yt.fileUrl;var Lt=`archive`;function Rt(e){let t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}function zt(e,t){let n=e.split(`/`).pop()??e;return`${Lt}/${Rt(t)}-${n}`}var Bt=30,Vt=108,Ht=8,Ut=240;function Wt(e){let t=e.lastIndexOf(`/`);return t===-1?``:e.slice(0,t)}function Gt({unit:e,state:t,name:n,onToggle:r}){let i=t?.read??!1;return(0,D.jsxs)(`button`,{type:`button`,className:`mark`,"aria-pressed":i,title:i?`Mark as unread`:`Mark as read`,onClick:()=>r(e),children:[`✓`,(0,D.jsxs)(`span`,{className:`visually-hidden`,children:[i?`Mark as unread`:`Mark as read`,`: `,n]})]})}function Kt({at:e,onPick:t,onDismiss:r}){return(0,D.jsxs)(`div`,{className:`annotate`,style:{top:e.top,left:e.left},children:[(0,D.jsxs)(`button`,{type:`button`,className:`annotate-drop`,title:`Ask for this to be removed`,onClick:()=>t(`remove`),children:[(0,D.jsx)(n,{}),(0,D.jsx)(`span`,{className:`visually-hidden`,children:`Ask for this to be removed`})]}),(0,D.jsxs)(`button`,{type:`button`,title:`Say something about this`,onClick:()=>t(`comment`),children:[(0,D.jsx)(d,{}),(0,D.jsx)(`span`,{className:`visually-hidden`,children:`Say something about this`})]}),(0,D.jsxs)(`button`,{type:`button`,className:`annotate-close`,title:`Dismiss`,onClick:r,children:[(0,D.jsx)(m,{}),(0,D.jsx)(`span`,{className:`visually-hidden`,children:`Dismiss`})]})]})}function qt({at:e,onAdd:t,onDismiss:n}){let[r,i]=(0,C.useState)(``),a=(0,C.useRef)(null);return(0,C.useEffect)(()=>{let e=e=>{let t=e.target;t!==null&&a.current?.contains(t)===!0||n()},t=e=>{e.key===`Escape`&&n()};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[n]),(0,D.jsxs)(`div`,{className:`annotate-composer`,style:{top:e.top,left:e.left},ref:a,children:[(0,D.jsx)(`p`,{className:`composer-target`,children:e.quote===``?e.name:`“${e.quote}”`}),(0,D.jsx)(`textarea`,{autoFocus:!0,value:r,placeholder:`What about it?`,"aria-label":`Your comment`,onChange:e=>i(e.target.value)}),(0,D.jsxs)(`div`,{className:`composer-acts`,children:[(0,D.jsx)(`button`,{type:`button`,className:`composer-cancel`,onClick:n,children:`Cancel`}),(0,D.jsx)(`button`,{type:`button`,className:`composer-add`,disabled:r.trim()===``,onClick:()=>t(r.trim()),children:`Add`})]})]})}function Jt(e){let{entry:t,file:n,units:r,text:i,marks:a,raw:o,landOn:c,onLanded:l,onCurrent:u,onOpen:f,onLeave:p}=e,m=Wt(n.path),h=(0,C.useRef)(null),g=(0,C.useCallback)(e=>{let n=x(m,e);return n===null?null:It(o,t?`${t}/${n}`:n)},[m,t,o]),_=r[0],ee=(0,C.useMemo)(()=>{let e=It(o,t?`${t}/${n.path}`:n.path);return _===void 0?e:`${e}?v=${encodeURIComponent(_.hash)}`},[t,n.path,o,_]),[te,v]=(0,C.useState)(null),[y,b]=(0,C.useState)(null),ne=(0,C.useCallback)(()=>b(null),[]),re=(0,C.useCallback)(e=>{let t=h.current,n=t===null?e.left:t.clientWidth+t.scrollLeft-Ut;b({...e,left:Math.max(0,Math.min(e.left,n))})},[]),w=`${e.reader}/${t}/${n.path}`,ie=(0,C.useRef)(w);(0,C.useEffect)(()=>{ie.current!==w&&(ie.current=w,v(null),b(null))},[w]);let ae=(0,C.useCallback)(e=>{let t=(e instanceof Element?e:e?.parentElement)?.closest?.(`[data-unit]`),n=t instanceof HTMLElement?t.dataset.unit:void 0;return r.find(e=>e.id===n)??null},[r]),T=e.onAnnotate,E=T!==null,oe=(0,C.useCallback)((e,t,r,i)=>{let a=h.current;if(!a||!E)return;let o=a.getBoundingClientRect(),s=e.top-o.top+a.scrollTop,c=e.left-o.left+a.scrollLeft,l=s-a.scrollTop>=38;v({unit:t?.id??_?.id??``,file:n.path,heading:t?.heading??``,quote:r,name:i,top:l?s-Bt-Ht:s+e.height+Ht,left:Math.max(0,Math.min(c,a.clientWidth+a.scrollLeft-Vt))})},[E,n.path,_]);(0,C.useEffect)(()=>{let e=h.current;if(!e||typeof IntersectionObserver!=`function`)return;let t=[...e.querySelectorAll(`[data-unit]`)];if(t.length===0)return;let n=new Map,r=new IntersectionObserver(e=>{for(let t of e)n.set(t.target.getAttribute(`data-unit`)??``,t);let t=[...n.values()].filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0]?.target.getAttribute(`data-unit`);t&&u(t)},{root:e,rootMargin:`0px 0px -65% 0px`,threshold:0});for(let e of t)r.observe(e);return()=>r.disconnect()},[u,r]),(0,C.useEffect)(()=>{if(c===null)return;let e=[...h.current?.querySelectorAll(`[data-unit]`)??[]].find(e=>e.dataset.unit===c);e&&(e.scrollIntoView?.({block:`start`}),l())},[c,l,r]),(0,C.useEffect)(()=>{let e=h.current;if(!e)return;let t=t=>{if(t.target?.closest?.(`.annotate, .annotate-composer`))return;let n=document.getSelection(),r=n?.toString()??``;if(!n||n.isCollapsed||r.trim()===``){v(null);return}let i=n.anchorNode;if(!i||!e.contains(i))return;let a=n.getRangeAt(0).getBoundingClientRect();oe(a,ae(i),r,r)};return e.addEventListener(`mouseup`,t),()=>e.removeEventListener(`mouseup`,t)},[oe,ae]),(0,C.useEffect)(()=>{let e=h.current;if(!e)return;let t=e=>{let t=e.target;if(t instanceof HTMLImageElement){e.preventDefault(),oe(t.getBoundingClientRect(),ae(t),``,t.alt||n.name);return}let r=t?.closest?.(`a`);if(!r)return;let i=r.getAttribute(`href`);if(i===null)return;e.preventDefault();let[a,o=``]=i.split(`#`);if(a===``){f(n.path,o);return}let s=x(m,a);if(s!==null){f(s,o);return}let c=S(a);c!==null&&p(c)};return e.addEventListener(`click`,t),()=>e.removeEventListener(`click`,t)},[m,n.name,n.path,p,f,oe,ae]);let se=e.failure===null&&!e.loading,ce=r.filter(e=>a[e.id]?.read).length,le=r.filter(e=>a[e.id]?.changed).length;return(0,D.jsxs)(`div`,{className:`doc`,ref:h,children:[te!==null&&T!==null&&(0,D.jsx)(Kt,{at:te,onPick:e=>{e===`comment`?re(te):T(te,e),v(null),document.getSelection()?.removeAllRanges()},onDismiss:()=>v(null)}),y!==null&&T!==null&&(0,D.jsx)(qt,{at:y,onAdd:e=>{T(y,`comment`,e),b(null)},onDismiss:ne}),e.failure!==null&&(0,D.jsx)(`p`,{className:`notice notice-failure`,children:e.failure}),e.failure===null&&e.loading&&(0,D.jsxs)(`p`,{className:`notice`,children:[`Reading `,n.name,`…`]}),se&&(0,D.jsxs)(`div`,{className:`doc-facts`,children:[(0,D.jsxs)(`span`,{children:[n.path,` · `,s(n.size)]}),r.length>0&&(0,D.jsxs)(`span`,{children:[`· `,ce,` of `,r.length,` read`]}),le>0&&(0,D.jsxs)(`span`,{className:`doc-changed`,children:[`· `,le,` changed since you read `,le===1?`it`:`them`]}),n.kind!==`markdown`&&_!==void 0&&(0,D.jsx)(Gt,{unit:_,state:a[_.id],name:n.name,onToggle:e.onToggleRead}),E&&(0,D.jsx)(`span`,{className:`doc-facts-acts`,children:(0,D.jsxs)(`button`,{type:`button`,className:`annotate-whole`,title:`Say something about this artifact`,onClick:e=>oe(e.currentTarget.getBoundingClientRect(),_??null,``,n.name),children:[(0,D.jsx)(d,{size:13}),(0,D.jsx)(`span`,{className:`visually-hidden`,children:`Say something about this artifact`})]})})]}),se&&n.kind===`markdown`&&r.map(t=>{let r=a[t.id];return(0,D.jsxs)(C.Fragment,{children:[(0,D.jsxs)(`section`,{"data-unit":t.id,className:`doc-section${r?.read?` is-read`:``}`,children:[(0,D.jsx)(`div`,{className:`sec-mark`,children:(0,D.jsx)(Gt,{unit:t,state:r,name:t.heading??n.name,onToggle:e.onToggleRead})}),t.heading!==null&&(0,D.jsxs)(`h2`,{children:[t.heading,r?.changed&&(0,D.jsx)(`span`,{className:`sec-changed`,children:`changed since you read it`})]}),t.heading===null&&r?.changed&&(0,D.jsx)(`p`,{className:`sec-changed`,children:`changed since you read it`}),(0,D.jsx)(P,{source:t.body,imageUrl:g})]}),e.under?.unit===t.id&&e.under.node]},t.id)}),se&&n.kind===`html`&&(0,D.jsx)(`iframe`,{className:`art-frame`,title:n.name,src:ee,sandbox:`allow-scripts allow-forms`,referrerPolicy:`no-referrer`}),se&&n.kind===`image`&&(0,D.jsx)(`p`,{className:`art-image`,children:(0,D.jsx)(`img`,{src:ee,alt:n.name})}),se&&n.kind===`text`&&(0,D.jsx)(`pre`,{className:`plain`,children:i??``}),se&&n.kind===`binary`&&(0,D.jsxs)(`p`,{className:`notice`,children:[n.name,` is `,s(n.size),` of something this tool does not render. It is in the spec directory, where the agent beside you can read it.`]})]})}function Yt(e){let t=(0,C.useId)();return(0,D.jsxs)(`div`,{className:e.className??`run-field`,children:[(0,D.jsx)(`span`,{id:t,children:e.label}),(0,D.jsxs)(`div`,{className:`run-with`,children:[(0,D.jsx)(`select`,{"aria-labelledby":t,value:e.value,onChange:t=>e.onPick(t.target.value),children:e.options.map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.said},e.id))}),e.children]})]})}function Xt(e){let t=Qe(e.slug),n=e.decided??e.recommended??t;return{...n,branchName:n.branchName||t.branchName}}var Zt=0,Qt=()=>`k${++Zt}`;function $t(e){return e.map(e=>({key:Qt(),after:e.after,why:e.why,chosen:e.chosen,panel:e.panel.map(e=>({key:Qt(),focus:e})),typing:``}))}function en(e){return[...e.panel.map(e=>e.focus),e.typing].map(e=>e.trim()).filter(e=>e!==``)}function tn(e){return e.map(e=>({after:e.after,why:e.why,chosen:e.chosen,panel:en(e)}))}function nn(e){let[t]=(0,C.useState)(()=>Xt(e)),[n,r]=(0,C.useState)(t.commits),[a,o]=(0,C.useState)(t.branch),[s,c]=(0,C.useState)(t.branchName),[l,u]=(0,C.useState)(t.pauses),[d,f]=(0,C.useState)(t.pausePhases),[p,h]=(0,C.useState)(()=>$t(t.checkpoints)),g=e.decided!==null,_=g?null:e.recommended,ee=e.phases.filter(e=>e.status===`done`).length,te=e.phases.length>0,v=d.filter(t=>!e.phases.some(e=>e.id===t)),y=_?.pauses===`chosen`?_.pausePhases.map(t=>({id:t,place:Ye(t,e.phases)??t,said:Object.hasOwn(_.pauseReasons,t)?_.pauseReasons[t]:``})).filter(e=>e.said!==``):[],b=_?.pauses===`none`?_.noPauseReason:``,ne=(l===`chosen`?v.length:0)+p.filter(t=>t.chosen&&Ye(t.after,e.phases)===null).length,x=(e,t)=>e.map(e=>e.id===t&&_!==null?{...e,said:`${e.said} (recommended)`}:e),S=(e,t)=>h(n=>n.map(n=>n.key===e?t(n):n)),re=e=>e.typing.trim()===``?e:{...e,panel:[...e.panel,{key:Qt(),focus:e.typing.trim()}],typing:``},w=(e,t)=>S(e,e=>{let n=e.panel.find(e=>e.key===t),r=re(e);return{...r,panel:r.panel.filter(e=>e.key!==t),typing:n?.focus??r.typing}});return(0,D.jsx)(`div`,{className:`dialog-shade`,children:(0,D.jsxs)(`div`,{className:`dialog dialog-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`Execute this spec`,children:[(0,D.jsx)(`h2`,{className:`rail-head`,children:`Execute this spec`}),(0,D.jsxs)(`div`,{className:`dialog-body`,children:[(0,D.jsxs)(`p`,{className:`rail-fact muted`,children:[`Set up the run for `,(0,D.jsx)(`b`,{children:e.name}),`.`,_!==null&&` Pre-filled from the recommendations in the plan - change anything.`]}),g&&(0,D.jsxs)(`p`,{className:`run-banner`,children:[(0,D.jsx)(`b`,{children:`Resuming a run in progress.`}),` `,(0,D.jsxs)(`span`,{className:`muted`,children:[ee,` of `,e.phases.length,` phases done - these are the choices this run started with.`]})]}),(0,D.jsx)(Yt,{label:`Commits`,options:x(G,_?.commits),value:n,onPick:r}),(0,D.jsx)(Yt,{label:`Branch`,options:x(K,_?.branch),value:a,onPick:o,children:a===`new`&&(0,D.jsx)(`input`,{value:s,"aria-label":`The branch to make`,onChange:e=>c(e.target.value)})}),(0,D.jsx)(Yt,{label:`Pauses`,options:x(Ze.filter(e=>e.id!==`chosen`||te),_?.pauses),value:l,onPick:u}),(l===`chosen`||y.length>0||b!==``)&&(0,D.jsxs)(`div`,{className:`run-phases`,children:[l===`chosen`&&(0,D.jsxs)(D.Fragment,{children:[e.phases.map(e=>(0,D.jsxs)(`label`,{children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:d.includes(e.id),onChange:()=>f(t=>t.includes(e.id)?t.filter(t=>t!==e.id):[...t,e.id])}),e.title]},e.id)),v.map(e=>(0,D.jsxs)(`p`,{className:`run-stale`,children:[e,` is not in the plan any more - re-place this pause`]},e))]}),y.map(e=>(0,D.jsxs)(`p`,{className:`run-why`,children:[(0,D.jsxs)(`b`,{children:[`After `,e.place,`:`]}),` `,e.said]},e.id)),b!==``&&(0,D.jsxs)(`p`,{className:`run-why`,children:[(0,D.jsx)(`b`,{children:`No pause recommended:`}),` `,b]})]}),(0,D.jsx)(`h3`,{className:`run-head`,children:`Review checkpoints`}),p.length===0&&(0,D.jsx)(`p`,{className:`rail-fact muted`,children:`None proposed.`}),p.map(t=>{let n=Ye(t.after,e.phases),r=n===null?`somewhere the plan no longer holds`:`after ${n}`;return(0,D.jsxs)(`div`,{className:`run-checkpoint`,children:[(0,D.jsxs)(`label`,{className:`run-checkpoint-head`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:t.chosen,onChange:()=>S(t.key,e=>({...e,chosen:!e.chosen}))}),(0,D.jsx)(`span`,{children:r})]}),t.why!==``&&(0,D.jsx)(`p`,{className:`run-why`,children:t.why}),t.chosen&&n===null&&(0,D.jsx)(`p`,{className:`run-stale`,children:`This checkpoint has nowhere to sit - untick it, or re-place it in the plan`}),t.chosen&&en(t).length===0&&(0,D.jsx)(`p`,{className:`run-stale`,children:`Nobody is on this panel, so this checkpoint will not run`}),(0,D.jsxs)(`div`,{className:`run-panel`,children:[t.panel.map((e,n)=>(0,D.jsxs)(`span`,{className:`run-reviewer`,children:[(0,D.jsx)(`button`,{type:`button`,className:`run-focus`,title:`Change this reviewer`,onClick:()=>w(t.key,e.key),children:e.focus}),(0,D.jsx)(`button`,{type:`button`,className:`run-drop`,"aria-label":`Drop reviewer ${n+1} ${r}`,onClick:()=>S(t.key,t=>({...t,panel:t.panel.filter(t=>t.key!==e.key)})),children:(0,D.jsx)(m,{size:11})})]},e.key)),(0,D.jsxs)(`span`,{className:`run-new`,children:[(0,D.jsx)(`input`,{value:t.typing,"aria-label":`New reviewer ${r}`,placeholder:`What the next reviewer judges`,onChange:e=>S(t.key,t=>({...t,typing:e.target.value})),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),S(t.key,re))}}),(0,D.jsxs)(`button`,{type:`button`,"aria-label":`Add a reviewer ${r}`,onClick:()=>S(t.key,re),children:[(0,D.jsx)(i,{size:11}),`add`]})]})]})]},t.key)})]}),ne>0&&(0,D.jsxs)(`p`,{className:`notice notice-failure`,children:[ne===1?`One choice names`:`${ne} choices name`,` a phase this plan no longer holds. Re-place `,ne===1?`it`:`them`,` before you run.`]}),e.failure!==null&&(0,D.jsx)(`p`,{className:`notice notice-failure`,children:e.failure}),(0,D.jsxs)(`div`,{className:`dialog-acts`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:e.onCancel,disabled:e.working,children:`Cancel`}),(0,D.jsx)(`button`,{type:`button`,className:`send`,disabled:e.working||ne>0,onClick:()=>e.onRun({commits:n,branch:a,branchName:s.trim(),pauses:l,pausePhases:l===`chosen`?d:[],checkpoints:tn(p)}),children:e.working?`Starting…`:g?`Resume`:`Run`})]})]})})}function rn(e){return new Promise((t,n)=>{let r=new FileReader;r.onerror=()=>n(Error(`${e.name} could not be read`)),r.onload=()=>{let n=String(r.result??``);t({name:e.name,type:e.type,data:n.slice(n.indexOf(`,`)+1)})},r.readAsDataURL(e)})}var an=0;function on(e){let[t,n]=(0,C.useState)(()=>e.draft?.name??``),[r,i]=(0,C.useState)(()=>e.draft?.text??``),[a,o]=(0,C.useState)(()=>e.draft?.attachments??[]),[s,c]=(0,C.useState)(null),[l,u]=(0,C.useState)(()=>e.draft?.imagination===!0),d=e.onDraft;(0,C.useEffect)(()=>{d({name:t,text:r,attachments:a,imagination:l})},[t,r,a,l,d]);let f=(0,C.useCallback)(async e=>{let t=[...e??[]];if(t.length!==0){c(null);try{let e=await Promise.all(t.map(rn));o(t=>[...t,...e.map(e=>(an+=1,{key:`f${an}`,file:e}))])}catch(e){c(e.message)}}},[]),m=t.trim()!==``&&(r.trim()!==``||a.length>0),h=p(t.trim());return(0,D.jsx)(`div`,{className:`dialog-shade`,children:(0,D.jsxs)(`div`,{className:`dialog dialog-wide`,role:`dialog`,"aria-modal":`true`,"aria-label":`A new spec`,children:[(0,D.jsx)(`h2`,{className:`rail-head`,children:`A new piece of work`}),(0,D.jsxs)(`div`,{className:`dialog-body`,children:[(0,D.jsxs)(`label`,{className:`field`,children:[(0,D.jsx)(`span`,{children:`Working name`}),(0,D.jsx)(`input`,{value:t,placeholder:`What would you call it?`,onChange:e=>n(e.target.value)}),h!==``&&(0,D.jsxs)(`span`,{className:`field-slug`,children:[`Saved as `,(0,D.jsx)(`code`,{children:h})]})]}),(0,D.jsxs)(`label`,{className:`field`,children:[(0,D.jsx)(`span`,{children:`What is it about?`}),(0,D.jsx)(`textarea`,{className:`field-dump`,value:r,placeholder:`Say as much or as little as you have. Drop or paste files in here too.`,onChange:e=>i(e.target.value),onPaste:e=>void f(e.clipboardData?.files??null),onDragOver:e=>e.preventDefault(),onDrop:e=>{e.preventDefault(),f(e.dataTransfer?.files??null)}})]}),a.length>0&&(0,D.jsx)(`ul`,{className:`attached`,children:a.map(e=>(0,D.jsxs)(`li`,{children:[e.file.name,(0,D.jsx)(`button`,{type:`button`,onClick:()=>o(t=>t.filter(t=>t.key!==e.key)),children:`drop`})]},e.key))}),(0,D.jsxs)(`label`,{className:`flavour`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:l,onChange:()=>u(!l)}),(0,D.jsxs)(`span`,{className:`flavour-what`,children:[`Imagination mode`,(0,D.jsx)(`span`,{className:`flavour-hint`,children:`Explore the ideal version first, before feasibility - best for open-ended or user-facing work. Confirmed with the steps.`})]})]})]}),s!==null&&(0,D.jsx)(`p`,{className:`notice notice-failure`,children:s}),e.failure!==null&&(0,D.jsx)(`p`,{className:`notice notice-failure`,children:e.failure}),(0,D.jsxs)(`div`,{className:`dialog-acts`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:e.onCancel,children:`Cancel`}),(0,D.jsx)(`button`,{type:`button`,className:`send`,disabled:!m||e.filing,onClick:()=>void e.onFile({name:t.trim(),text:r.trim(),attachments:a.map(e=>e.file),wish:{imagination:l}}),children:e.filing?`Submitting…`:`Submit`})]})]})})}function sn(e){let t=[];for(let n of e){let e=t[t.length-1];e&&e.dir===n.dir?e.files.push(n):t.push({dir:n.dir,files:[n]})}return t}function cn(e){return e.openSpec===null?(0,D.jsx)(ln,{...e}):(0,D.jsx)(un,{...e})}function ln(e){let t=e.specs.filter(e=>!e.archived),n=e.specs.filter(e=>e.archived),r=t=>(0,D.jsx)(`li`,{children:(0,D.jsxs)(`button`,{type:`button`,className:`nav-entry`,onClick:()=>e.onOpenSpec(t.path),children:[(0,D.jsx)(`span`,{className:`nav-entry-name`,children:t.name}),t.status!==null&&(0,D.jsx)(`span`,{className:`nav-entry-status`,children:t.status}),t.awaiting>0&&(0,D.jsx)(`span`,{className:`nav-entry-awaiting`,title:`waiting for you`,children:t.awaiting})]})},t.path);return(0,D.jsxs)(`nav`,{className:`nav`,"aria-label":`Specs`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`nav-new`,onClick:e.onNewSpec,children:[(0,D.jsx)(i,{size:12}),`New spec`]}),(0,D.jsx)(`h2`,{className:`nav-head`,children:`Specs`}),t.length===0?(0,D.jsx)(`p`,{className:`nav-empty`,children:`none yet`}):(0,D.jsx)(`ul`,{className:`nav-list`,children:t.map(r)}),n.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`h2`,{className:`nav-head`,children:`Archive`}),(0,D.jsx)(`ul`,{className:`nav-list nav-archived`,children:n.map(r)})]})]})}function un(e){let t=e.spec?.name??e.openSpec??``;return(0,D.jsxs)(`nav`,{className:`nav`,"aria-label":t,children:[(0,D.jsxs)(`button`,{type:`button`,className:`nav-back`,onClick:e.onBack,children:[(0,D.jsx)(_,{size:11}),`All specs`]}),(0,D.jsxs)(`div`,{className:`nav-title`,children:[(0,D.jsx)(`div`,{className:`nav-title-name`,children:t}),e.spec?.status!=null&&(0,D.jsx)(`div`,{className:`nav-title-status`,children:e.spec.status})]}),sn(e.artifacts).map(t=>(0,D.jsxs)(`div`,{children:[t.dir!==``&&(0,D.jsxs)(`p`,{className:`nav-dir`,children:[t.dir,`/`]}),(0,D.jsx)(`ul`,{className:`nav-list`,children:t.files.map(t=>(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`button`,{type:`button`,className:`nav-artifact`,"aria-current":t.path===e.openArtifact?`true`:void 0,onClick:()=>e.onOpenArtifact(t.path),children:t.name}),t.path===e.openArtifact&&e.units.length>1&&(0,D.jsx)(`ul`,{className:`nav-sections`,children:e.units.filter(e=>e.heading!==null).map(t=>(0,D.jsx)(`li`,{children:(0,D.jsxs)(`button`,{type:`button`,className:e.marks[t.id]?.read?`is-read`:void 0,"aria-current":t.id===e.currentUnit?`true`:void 0,onClick:()=>e.onOpenUnit(t.id),children:[t.heading,e.marks[t.id]?.changed&&(0,D.jsx)(`span`,{className:`nav-changed`,title:`Changed since you read it`,children:`●`})]})},t.id))})]},t.path))})]},t.dir||`.`))]})}var dn=[{id:`discovery`,head:`Before writing anything down`,said:`What we do first.`},{id:`deliverables`,head:`What this work produces`,said:`What we end up with.`}],fn=[{id:`focused`,said:`focused - the agent decides what to research`},{id:`named`,said:`focused on...`},{id:`broad`,said:`broad - deep research, can use many tokens`}];function pn(e){return new Map(e.stages.map(e=>[e.id,e]))}function mn(e){let t=(0,C.useMemo)(()=>pn(e.proposal),[e.proposal]),{held:n}=e,[r,i]=(0,C.useState)(()=>n===null?new Set([...t.values()].filter(e=>e.recommended).map(e=>e.id)):new Set(n.stages.map(e=>e.id))),[a,o]=(0,C.useState)(n===null?e.wish:n.imagination),[s,c]=(0,C.useState)(n?.settings.research?.scope??`focused`),[l,u]=(0,C.useState)(n?.settings.research?.subject??``),[d,f]=(0,C.useState)(``),p=U.some(e=>r.has(e)),m=n===null&&e.wish,h=(0,C.useMemo)(()=>new Set((n?.stages??[]).filter(e=>e.status!==`waiting`).map(e=>e.id)),[n]),g=e=>{h.has(e)||i(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_=(0,C.useMemo)(()=>{if(n===null)return!0;let e=new Set(n.stages.map(e=>e.id));if(e.size!==r.size||![...r].every(t=>e.has(t))||(a&&p)!==n.imagination)return!0;if(r.has(`research`)){let e=n.settings.research??{scope:`focused`,subject:``};if(s!==e.scope||s===`named`&&l.trim()!==e.subject)return!0}return!1},[n,r,a,p,s,l]);return(0,D.jsx)(`div`,{className:`doc`,children:(0,D.jsxs)(`div`,{className:`prose form`,children:[(0,D.jsxs)(`h1`,{children:[`The steps for `,e.name]}),n===null?e.proposal.note!==``&&(0,D.jsx)(`p`,{className:`lede`,children:e.proposal.note}):(0,D.jsx)(`p`,{className:`lede`,children:`Change what this work does. A step already under way stays where it is.`}),dn.map(e=>(0,D.jsxs)(`section`,{children:[(0,D.jsx)(`h2`,{children:e.head}),(0,D.jsx)(`ul`,{className:`choices`,children:Ke.filter(t=>t.group===e.id).map(e=>{let n=t.get(e.id),i=h.has(e.id);return(0,D.jsxs)(`li`,{className:n?.recommended?`is-recommended`:void 0,children:[(0,D.jsxs)(`label`,{children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:r.has(e.id),disabled:i,onChange:()=>g(e.id)}),(0,D.jsxs)(`span`,{className:`choice-title`,children:[e.title,n?.recommended&&(0,D.jsx)(`span`,{className:`choice-flag`,children:`recommended`}),i&&(0,D.jsx)(`span`,{className:`choice-flag choice-locked`,children:`under way`})]})]}),(0,D.jsx)(`p`,{className:`choice-about`,children:e.about}),n?.why!==void 0&&n.why!==``&&(0,D.jsx)(`p`,{className:`choice-why`,children:n.why}),e.id===`research`&&r.has(e.id)&&(0,D.jsx)(`div`,{className:`extras`,children:(0,D.jsx)(Yt,{className:`extra`,label:`Scope`,options:fn,value:s,onPick:c,children:s===`named`&&(0,D.jsx)(`input`,{value:l,"aria-label":`What to research`,placeholder:`What to research`,onChange:e=>u(e.target.value)})})})]},e.id)})})]},e.id)),p&&(0,D.jsxs)(`section`,{children:[(0,D.jsx)(`h2`,{children:`Imagination mode`}),(0,D.jsxs)(`label`,{className:`choice-mode`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:a,onChange:e=>o(e.target.checked)}),(0,D.jsxs)(`span`,{children:[`Imagine the ideal version first, as if anything were possible - trimming it back to what can be built comes after. Best while you are still deciding what this should be.`,m&&(0,D.jsx)(`span`,{className:`choice-flag`,children:`asked for at intake`})]})]})]}),(0,D.jsxs)(`section`,{children:[(0,D.jsx)(`h2`,{children:`Anything else`}),(0,D.jsx)(`textarea`,{className:`field-dump`,value:d,placeholder:`Anything the steps above do not cover.`,onChange:e=>f(e.target.value)})]}),e.failure!==null&&(0,D.jsx)(`p`,{className:`notice notice-failure`,children:e.failure}),(0,D.jsxs)(`div`,{className:`form-acts`,children:[e.onCancel!==null&&(0,D.jsx)(`button`,{type:`button`,onClick:e.onCancel,children:`Cancel`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>e.onAsk(d.trim()||`about the steps for this work`),children:`Ask`}),(0,D.jsx)(`button`,{type:`button`,className:`send`,disabled:e.sending||r.size===0||!_,onClick:()=>e.onConfirm({stages:[...r],imagination:a&&p,note:d,settings:{research:r.has(`research`)?{scope:s,subject:s===`named`?l.trim():``}:null}}),children:e.sending?n===null?`Confirming…`:`Updating…`:n===null?`Confirm ${r.size} ${r.size===1?`step`:`steps`}`:`Update protocol`})]})]})})}var hn={waiting:`○`,running:`◐`,done:`●`},gn=6e4;function _n(e,t){let n=new Set([...e.phases.map(e=>e.id),Je]),r=[];for(let n of e.phases){if(n.id===`final`)continue;let e=t.get(n.id)??[];e.length>0&&r.push({id:n.id,place:`after ${n.title||n.id}`,rounds:e})}let i=t.get(`final`)??[];i.length>0&&r.push({id:Je,place:`Final review`,rounds:i});let a=e.reviews.filter(e=>e.source.kind===`execution`||e.source.kind===`checkpoint`&&!n.has(e.source.after));return a.length>0&&r.push({id:`no-place`,place:``,rounds:a}),r}function vn(e){let t=new Map;for(let n of e.reviews){if(n.source.kind!==`checkpoint`)continue;let e=t.get(n.source.after);e===void 0?t.set(n.source.after,[n]):e.push(n)}return t}function yn(e,t){let n=e.runDecisions,r=e=>t.has(e),i=(n?.checkpoints??[]).filter(e=>e.chosen),a=e.phases.map(e=>{let t=[];if(n!==null&&((n.pauses===`every`||n.pauses===`chosen`&&n.pausePhases.includes(e.id))&&t.push({kind:`pause`,said:`Pause after this phase`}),i.some(t=>t.after===e.id))){let n=r(e.id);t.push({kind:`review`,ran:n,said:n?`Reviewed after this phase`:`Review after this phase`})}return{id:e.id,label:e.title||e.id,status:e.status,artifacts:[],marks:t}});if(i.some(e=>e.after===`final`)&&a.length>0){let e=r(Je);a.push({id:Je,label:`Final review`,status:e?`done`:`waiting`,artifacts:[],className:`board-final`,marks:[{kind:`review`,ran:e,said:e?`Reviewed after the last phase`:`Review after the last phase`}]})}return a}function bn(e){return(0,D.jsx)(`ul`,{className:`board-list`,children:e.map(e=>(0,D.jsxs)(`li`,{className:`board-review`,children:[(0,D.jsxs)(`p`,{className:`board-stage-name`,children:[`round `,e.round,`: `,e.verdict]}),(0,D.jsxs)(`p`,{className:`rail-fact muted`,children:[e.findings,` `,e.findings===1?`finding`:`findings`,e.judgments>0?`, ${e.judgments} for you`:``]})]},`${xn(e.source)}-${e.round}-${e.at}`))})}function xn(e){return e.kind===`checkpoint`?`checkpoint:${e.after}`:e.kind}function Sn(e){let{flag:t}=e,n=t.kind===`pause`?``:t.ran?` is-ran`:` is-waiting`,r=f({className:`board-tip`,side:`bottom`,delay:250});return(0,D.jsxs)(`span`,{className:`board-flag${n}`,...r.anchor,children:[t.kind===`pause`?(0,D.jsx)(b,{size:13}):(0,D.jsx)(y,{size:13}),(0,D.jsx)(`span`,{className:`visually-hidden`,children:t.said}),r.says(t.said)]})}function Cn(e){let{row:t}=e,n=(0,D.jsx)(`span`,{className:`board-mark`,"aria-hidden":`true`,children:hn[t.status]}),r=t.artifacts.length===1?t.artifacts[0]:null,i=t.artifacts.length>1;return(0,D.jsxs)(`li`,{className:`board-stage is-${t.status}${t.className?` ${t.className}`:``}`,children:[(0,D.jsxs)(`p`,{className:`board-stage-name`,children:[n,r!==null&&(0,D.jsx)(`button`,{type:`button`,title:`Open ${r}`,onClick:()=>e.onOpen(r),children:t.label}),i&&(0,D.jsxs)(`button`,{type:`button`,"aria-expanded":e.open,onClick:e.onFold,children:[t.label,(0,D.jsx)(`span`,{className:`board-chevron`,"aria-hidden":`true`,children:e.open?`▾`:`▸`})]}),r===null&&!i&&t.label,t.marks!==void 0&&t.marks.length>0&&(0,D.jsx)(`span`,{className:`board-marks`,children:t.marks.map(e=>(0,D.jsx)(Sn,{flag:e},e.kind))})]}),i&&e.open&&(0,D.jsx)(`ul`,{className:`board-artifacts`,children:t.artifacts.map(t=>(0,D.jsx)(`li`,{children:(0,D.jsx)(`button`,{type:`button`,onClick:()=>e.onOpen(t),children:t})},t))})]})}function wn(e){let{state:t}=e,n=t.awaiting.length>0,[r,i]=(0,C.useState)({}),o=e=>i(t=>({...t,[e]:!t[e]})),[s,c]=(0,C.useState)(()=>new Date),l=t.activity.said!==``;(0,C.useEffect)(()=>{if(!l)return;let e=setInterval(()=>c(new Date),gn);return()=>clearInterval(e)},[l]);let u=$e(t,s),d=t.reviews.filter(e=>e.source.kind===`spec`),f=vn(t),p=_n(t,f),m=t=>(0,D.jsx)(`ul`,{className:`board-list`,children:t.map(t=>(0,D.jsx)(Cn,{row:t,onOpen:e.onOpen,open:r[t.id]===!0,onFold:()=>o(t.id)},t.id))});return(0,D.jsxs)(`section`,{className:`board`,children:[(0,D.jsxs)(`div`,{className:`board-head`,children:[(0,D.jsx)(`h2`,{className:`rail-head`,children:`Protocol`}),e.onAmend!==null&&t.protocol.length>0&&(0,D.jsx)(`button`,{type:`button`,className:`board-amend`,title:`Edit the protocol`,"aria-label":`Edit the protocol`,onClick:e.onAmend,children:(0,D.jsx)(a,{size:12})})]}),t.protocol.length===0?(0,D.jsx)(`p`,{className:`rail-fact muted`,children:n?`The steps are waiting for you.`:`No steps yet.`}):m(qe(t.protocol).map(e=>({id:e.id,label:W(e.id)?.title??e.id,status:e.status,artifacts:e.artifacts}))),u!==null&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`h2`,{className:`rail-head`,children:`Now`}),(0,D.jsxs)(`p`,{className:`board-now`,title:u.at,children:[(0,D.jsx)(`span`,{className:`pulse`,"aria-hidden":`true`}),u.said]})]}),t.phases.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`h2`,{className:`rail-head`,children:`Execution`}),m(yn(t,f))]}),t.reviews.length>0&&(0,D.jsxs)(`div`,{className:`board-log`,children:[d.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`h2`,{className:`rail-head`,children:`Specs review`}),bn(d)]}),p.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`h2`,{className:`rail-head`,children:`Execution review`}),(0,D.jsx)(`ul`,{className:`board-list board-nested`,children:p.map(e=>(0,D.jsxs)(`li`,{className:`board-under`,children:[e.place!==``&&(0,D.jsx)(`p`,{className:`board-under-name`,children:e.place}),bn(e.rounds)]},e.id))})]})]})]})}function Tn(e){let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString()}function En(e){return(0,D.jsxs)(`section`,{children:[(0,D.jsx)(`h2`,{className:`rail-head`,children:`Needs you`}),(0,D.jsx)(`ul`,{className:`rail-awaiting`,children:e.awaiting.map(t=>(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`button`,{type:`button`,className:`send`,onClick:()=>e.onAnswer(t.id),children:t.title}),t.file!==``&&(0,D.jsx)(`p`,{className:`rail-fact muted`,children:t.file})]},t.id))})]})}function Dn(e){let[t,n]=(0,C.useState)(null),r=e.queue.length>0,i=ze(e.queue).length;return(0,D.jsxs)(`section`,{className:`rail-annotations`,children:[(0,D.jsx)(`h2`,{className:`rail-head`,children:r?`Annotations (${e.queue.length})`:`Annotations`}),r&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`ul`,{className:`queue`,children:e.queue.map(r=>(0,D.jsxs)(`li`,{className:`queued is-${r.kind}`,children:[(0,D.jsx)(`p`,{className:`queued-target`,children:Le(r)}),r.kind===`remove`?(0,D.jsx)(`p`,{className:`queued-kind`,children:`Asking for this to be removed`}):t===r.id?(0,D.jsx)(`textarea`,{value:r.text,placeholder:`What about it?`,"aria-label":`Comment on ${Le(r)}`,onChange:t=>e.onEdit(r.id,t.target.value)}):r.text===``?(0,D.jsx)(`p`,{className:`queued-empty`,children:`Nothing written yet - this one will not be sent`}):(0,D.jsx)(`p`,{className:`queued-text`,children:r.text}),(0,D.jsxs)(`div`,{className:`queued-acts`,children:[r.kind===`comment`&&(0,D.jsx)(`button`,{type:`button`,onClick:()=>n(t===r.id?null:r.id),children:t===r.id?`done`:`edit`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>e.onSendOne(r.id),disabled:e.sending,children:`send now`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>e.onDrop(r.id),children:`drop`})]})]},r.id))}),(0,D.jsx)(`button`,{type:`button`,className:`send`,onClick:e.onSendBatch,disabled:e.sending||i===0,children:e.sending?`Sending…`:`Send`})]}),e.filed.length>0&&(0,D.jsx)(`ul`,{className:`filed`,children:e.filed.slice().reverse().map((t,n)=>(0,D.jsxs)(`li`,{children:[(0,D.jsxs)(`span`,{className:`filed-round`,children:[`round `,e.filed.length-n]}),(0,D.jsxs)(`span`,{className:`filed-count`,children:[t.comments.length,` `,t.comments.length===1?`note`:`notes`]}),(0,D.jsx)(`span`,{className:`filed-when`,children:Tn(t.submittedAt)})]},t.submittedAt||String(n)))})]})}function On(e){let t=e.queue.length>0,n=!t&&e.filed.length>0,r=(0,D.jsx)(Dn,{...e});return(0,D.jsxs)(`aside`,{className:`rail`,"aria-label":`Status`,children:[e.spec!==null&&(0,D.jsxs)(`section`,{children:[(0,D.jsx)(`h2`,{className:`rail-head`,children:`Spec`}),(0,D.jsx)(`p`,{className:`rail-fact`,children:e.spec.name}),(0,D.jsxs)(`p`,{className:`rail-fact muted`,children:[e.spec.files,` `,e.spec.files===1?`artifact`:`artifacts`,e.spec.archived?` · archived`:``]}),(0,D.jsxs)(`p`,{className:`rail-fact muted`,children:[`last changed `,Tn(e.spec.modified)]})]}),e.spec!==null&&(0,D.jsxs)(`section`,{children:[(0,D.jsx)(`h2`,{className:`rail-head`,children:`Actions`}),(0,D.jsxs)(`div`,{className:`rail-acts`,children:[(0,D.jsxs)(`button`,{type:`button`,className:`rail-act`,onClick:e.onContinue,children:[(0,D.jsx)(u,{size:15}),`Continue`]}),e.executable&&(0,D.jsxs)(`button`,{type:`button`,className:`rail-act`,onClick:e.onExecute,children:[(0,D.jsx)(v,{size:15}),`Execute`]}),e.onQualityReview!==null&&(0,D.jsxs)(`button`,{type:`button`,className:`rail-act`,onClick:e.onQualityReview,children:[(0,D.jsx)(y,{size:15}),`Specs quality review`]}),!e.spec.archived&&(0,D.jsxs)(`button`,{type:`button`,className:`rail-act`,onClick:e.onArchive,children:[(0,D.jsx)(l,{size:15}),`Archive`]})]})]}),e.protocol!==null&&e.protocol.awaiting.length>0&&(0,D.jsx)(En,{awaiting:e.protocol.awaiting,onAnswer:e.onAnswer}),t&&r,e.protocol!==null&&(0,D.jsx)(wn,{state:e.protocol,onOpen:e.onOpenArtifact,onAmend:e.onAmend}),n&&r,e.sent!==null&&(0,D.jsx)(`p`,{className:`rail-fact muted`,children:e.sent}),e.failure!==null&&(0,D.jsx)(`p`,{className:`notice notice-failure`,children:e.failure})]})}var kn={units:[],text:null,loading:!1,failure:null,from:null};function An(e,t){return e?`${e}/${t.path}`:t.path}function jn(e,t){let[n,r]=(0,C.useState)(kn),i=(0,C.useRef)(null),a=(0,C.useCallback)((e,t)=>{let n=An(e,t);if(i.current=n,!T(t.kind)){let e=E({path:t.path,kind:t.kind,fingerprint:t.hash??`${t.size}:${t.modified}`});r({units:e,text:null,loading:!1,failure:null,from:n});return}r(e=>({...e,loading:!0})),Ct(n).then(e=>{if(i.current!==n)return;let a=E({path:t.path,kind:t.kind,text:e.text});r({units:a,text:e.text,loading:!1,failure:null,from:n})}).catch(e=>{i.current===n&&r({units:[],text:null,loading:!1,failure:e.message,from:n})})},[]);(0,C.useEffect)(()=>{if(!t){i.current=null,r(kn);return}a(e,t)},[e,t,a]),(0,C.useEffect)(()=>{if(!t)return;let n=An(e,t);return ft(r=>{r.path===n&&a(e,t)})},[e,t,a]);let o=t?An(e,t):null;return n.from===o?{units:n.units,text:n.text,loading:n.loading,failure:n.failure}:{units:[],text:null,loading:o!==null,failure:null}}function Mn(e){let[t,n]=(0,C.useState)({for:null,state:null}),[r,i]=(0,C.useState)(null),a=(0,C.useRef)(null),o=(0,C.useCallback)(()=>{if(e===null){a.current=null,n({for:null,state:null});return}a.current=e,At(e).then(t=>{a.current===e&&(n({for:e,state:t}),i(null))}).catch(t=>{a.current===e&&i(t.message)})},[e]);return(0,C.useEffect)(o,[o]),(0,C.useEffect)(()=>{if(e!==null)return ft(t=>{t.entry===e&&o()})},[e,o]),{state:t.for===e?t.state:null,failure:r,refresh:o}}var Nn={openSpec:null,openArtifact:null,answering:null,shade:null,draft:null,intake:null};function Pn(){let[e,t]=(0,C.useState)(null),[n,r]=(0,C.useState)(null),[i,a]=(0,C.useState)(null),[o,s]=(0,C.useState)(null),[c,l]=(0,C.useState)(null),[u,d]=(0,C.useState)(null),[f,p]=(0,C.useState)(null),[m,h]=(0,C.useState)(null),[g,_]=(0,C.useState)(null),[ee,te]=(0,C.useState)(null),[v,y]=(0,C.useState)(!1),[b,x]=(0,C.useState)(null),[S,w]=(0,C.useState)(null),ie=ne({onSession:pt,askTheme:vt}),T=(0,C.useRef)(new Map),E=(0,C.useRef)(null),[se,le]=(0,C.useState)(null),de=(0,C.useRef)(Nn),fe=(0,C.useRef)(null),pe=(0,C.useRef)(null);(0,C.useEffect)(()=>{dt().then(e=>r(e.raw))},[]);let O=(0,C.useCallback)(()=>{bt().then(e=>{t(e),a(null)}).catch(e=>a(e.message))},[]);(0,C.useEffect)(O,[O]),(0,C.useEffect)(()=>ft(O),[O]);let me=(0,C.useCallback)(e=>{l(e),p(null),d(null),X(!1),Ue(e=>e===`intake`?e:null),x(null)},[]),he=(0,C.useRef)(null),ge=(0,C.useCallback)(e=>{he.current=e,xt(e).then(t=>{he.current===e&&(d(t),s(null))}).catch(t=>{he.current===e&&s(t.message)})},[]);(0,C.useEffect)(()=>{c!==null&&ge(c)},[c,ge]);let[_e,ve]=(0,C.useState)([]),k=(0,C.useCallback)(e=>{Ot(e).then(t=>{he.current===e&&ve(t.rounds)}).catch(()=>ve([]))},[]);(0,C.useEffect)(()=>{c===null?ve([]):k(c)},[c,k]);let A=u?.archived!==!0,ye=u!==null&&!u.archived,be=ce(c,{get:wt,put:Tt,empty:He,whenUnwritable:`Your marks are not being saved - the state file cannot be written.`,whenUnreadable:`This spec’s saved state could not be read, so nothing is being saved.`,persist:A}),xe=ce(ye?c:null,{get:Et,put:Dt,empty:()=>[],whenUnwritable:`Your annotations are not being saved - the queue file cannot be written.`,whenUnreadable:`This spec’s queued annotations could not be read, so nothing is being saved.`}),Se=xe.reload;(0,C.useEffect)(()=>{if(c!==null)return ft(e=>{if(e.entry===c){if(e.path.endsWith(`/.specs/pending-annotations.json`)){Se();return}ge(c),k(c)}})},[c,ge,k,Se]);let j=(0,C.useMemo)(()=>u?.files??[],[u]);(0,C.useEffect)(()=>{j.length!==0&&(j.some(e=>e.path===f)||p(j[0].path))},[j,f]);let M=j.find(e=>e.path===f)??null,N=jn(c??``,M),Ce=(0,C.useMemo)(()=>{let e={};for(let t of N.units)e[t.id]=ae(t.hash,be.value.units[t.id]);return e},[N.units,be.value]);(0,C.useEffect)(()=>{g===null||M===null||N.units.length===0||(h(oe(N.units,M.path,g)?.id??null),_(null))},[N.units,M,g]);let we=(0,C.useCallback)((e,t)=>{p(e),_(t===``?null:t)},[]),Te=be.update,Ee=(0,C.useCallback)(e=>{Te(t=>{let n=t.units[e.id],r={...t.units};if(n?.readHash===e.hash){let{readHash:t,readAt:i,...a}=n;r[e.id]=a}else r[e.id]={...n,readHash:e.hash,readAt:new Date().toISOString()};return{...t,units:r}})},[Te]),De=(0,C.useCallback)(()=>h(null),[]),P=e?.entries.find(e=>e.path===c)??null,Oe=xe.value,F=xe.update,ke=(0,C.useCallback)((e,t,n=``)=>{F(r=>[...r,Ie(e,t,n)],!0),x(null)},[F]),I=(0,C.useCallback)(async e=>{let t=await ht(e);return t.ok?!0:t.error===`no-session`?(w(e),!1):(x(`No agent was told: ${t.error}`),!1)},[]),je=(0,C.useCallback)(async e=>{if(!(c===null||ze(e).length===0)){y(!0),x(null);try{let t=await kt(c,Be(e)),n=new Set(e.map(e=>e.id));F(e=>e.filter(e=>!n.has(e.id)),!0),k(c),await I({event:`annotations`,detail:Ve(e),path:t.path})||x(e=>e??`Round ${t.round} was filed. Nobody has been told yet.`)}catch(e){x(`That could not be filed: ${e.message}`)}finally{y(!1)}}},[c,I,k,F]),L=Mn(c),[R,z]=(0,C.useState)(null),[Me,Ne]=(0,C.useState)(0),[Fe,Le]=(0,C.useState)(null),[Re,B]=(0,C.useState)(null),[V,Ue]=(0,C.useState)(null),[We,H]=(0,C.useState)(null),[Ke,U]=(0,C.useState)(!1),W=(0,C.useCallback)(e=>{H(null),U(!1),Ue(e)},[]),[qe,Je]=(0,C.useState)(0);(0,C.useEffect)(()=>{de.current={openSpec:c,openArtifact:f,answering:R,shade:V===`intake`?`intake`:null}},[c,f,R,V]);let Ye=(0,C.useCallback)(e=>{if(E.current===e)return;let t=de.current,n=e===null?void 0:T.current.get(e);if(E.current===null&&n===void 0){E.current=e,le(e),x(null);return}E.current!==null&&T.current.set(E.current,{...t,draft:fe.current,intake:pe.current}),E.current=e,le(e);let r=n??Nn;de.current=r,fe.current=r.draft,pe.current=r.intake,l(r.openSpec),p(r.openArtifact),z(r.answering),Ue(r.shade),Je(e=>e+1),X(!1),x(null),B(null),H(null),U(!1),r.openSpec!==t.openSpec&&(d(null),h(null),_(null),te(null))},[]);(0,C.useEffect)(()=>pt(e=>Ye(e.sid)),[Ye]);let Xe=L.state?.awaiting.length??0;(0,C.useEffect)(()=>{gt(Xe)},[Xe]),(0,C.useEffect)(()=>{if(c===null||R===null){Le(null);return}let e=!0;return jt(c,R).then(t=>{if(!e)return;Le(t),B(null);let n=typeof t.file==`string`?t.file:``;n!==``&&we(n,``)}).catch(t=>{e&&B(t.message)}),()=>{e=!1}},[c,R,we]);let G=L.state?.awaiting.find(e=>e.id===R)??null,K=G?.kind??null,Ze=Fe===null?null:Fe.payload??Fe,Qe=Ze===null?null:Ae(Ze),$e=Qe?.kind===`decision`&&M!==null&&M.path===(G?.file??``)?oe(N.units,M.path,Qe.heading)?.id??null:null;(0,C.useEffect)(()=>{let e=L.state?.awaiting;R===null||e===void 0||e.some(e=>e.id===R)||z(null)},[R,L.state]);let q=c===null||R===null?null:`${c}:${R}`,J=(0,C.useCallback)((e,t)=>{X(!1),K===`protocol`&&z(null),we(e,t)},[K,we]),Y=(0,C.useCallback)(e=>{X(!1),K===`protocol`&&z(null),h(e)},[K]),[et,tt]=(0,C.useState)(null),[nt,X]=(0,C.useState)(!1),rt=(0,C.useMemo)(()=>{if(K===`protocol`&&Ze!==null)return{proposal:Ze,held:null};let e=L.state;return!nt||e===null||e.protocol.length===0?null:{proposal:{stages:[],note:``},held:{stages:e.protocol,imagination:e.modes.imagination,settings:e.stageSettings}}},[nt,K,Ze,L.state]),it=(0,C.useCallback)(e=>{if(q===null||R===null)return Promise.resolve(!1);let t=G?.file??``;return I({event:`question`,detail:`${G?.title??R}: ${e}`,...t===``?{}:{path:`${c}/${t}`}}).then(t=>(t&&tt({for:q,said:e}),t))},[R,q,G,c,I]),at=(0,C.useCallback)(e=>{q!==null&&(fe.current={for:q,...e})},[q]),ot=(0,C.useCallback)(async e=>{if(!(c===null||R===null)){y(!0),B(null);try{let t=await Ft(c,R,e);z(null),fe.current=null,L.refresh(),await I({event:G?.kind===`gate`?`gate`:`answers`,detail:`${G?.title??R}: ${t.outcome}`,path:t.path})}catch(e){B(e.message)}finally{y(!1)}}},[R,G,c,L,I]),st=(0,C.useCallback)(e=>{pe.current=e},[]),Z=(0,C.useCallback)(e=>{if(e!==null&&e!==E.current){let t=T.current.get(e);if(t!==void 0){T.current.set(e,{...t,shade:null,intake:null});return}}W(null),pe.current=null},[W]),ct=(0,C.useCallback)(async e=>{let t=E.current;U(!0),H(null);try{let n=await Mt(e);Z(t),l(n.entry),p(n.path.slice(n.entry.length+1)),d(null),O(),await I({event:`brief`,detail:n.entry})}catch(e){H(e.message)}finally{U(!1)}},[Z,O,I]),lt=(0,C.useCallback)(async e=>{if(c===null)return null;y(!0),B(null);try{let{change:t}=await Nt(c,e);if(z(null),X(!1),L.refresh(),t.amended&&!t.changed)return null;await I({event:t.amended?`amendment`:`answers`,detail:t.amended?`${P?.name??c}: ${t.said}`:`protocol confirmed - ${t.said}`,path:`${c}/README.md`})}catch(e){let t=e.message;return B(t),t}finally{y(!1)}return null},[c,L,I,P?.name]),ut=(0,C.useCallback)(()=>{P!==null&&(x(null),I({event:`brief`,detail:P.name}).then(e=>{e&&x(`An agent was asked to pick this spec up.`)}))},[I,P]),Q=(0,C.useMemo)(()=>A&&j.some(e=>e.path===`plan/PLAN.md`),[j,A]),_t=(0,C.useCallback)(async e=>{if(!(c===null||P===null)){U(!0),H(null);try{await Pt(c,e),W(null),L.refresh(),x(null),await I({event:`execute`,detail:P.name})?x(`The run was started in the session beside this pane.`):x(e=>e??`The run is set up. Nobody has been told yet.`)}catch(e){H(e.message)}finally{U(!1)}}},[c,L,I,W,P]),yt=(0,C.useCallback)(()=>{let e=L.state?.protocol??[];x(null),lt({stages:[...e.map(e=>e.id),Ge],imagination:null,note:``,settings:{research:null}}).then(e=>{e!==null&&x(`Specs quality review was not added: ${e}`)})},[lt,L.state]),$=(0,C.useMemo)(()=>{let e=L.state?.protocol??[];return A&&e.length>0&&!e.some(e=>e.id===`quality-review`)},[A,L.state]),Ct=(0,C.useCallback)(async()=>{if(c!==null){U(!0),H(null);try{let e=await St(c);W(null),d(null),p(e.path.slice(e.entry.length+1)),l(e.entry),x(`Signed off, and filed as ${e.entry}.`)}catch(e){H(e.message)}finally{U(!1)}}},[c,W]);if(n===null||e===null)return(0,D.jsx)(`p`,{className:`notice notice-failure`,children:i??`Waiting for the pane to hand over…`});let At=R===null||Qe===null||K===`protocol`?null:(0,D.jsx)(Pe,{title:G?.title??R,ask:Qe,file:G?.file??``,onAnswer:e=>void ot(e),onAsk:it,asked:et?.for===q?et.said:null,onDismiss:()=>z(null),settled:M===null||!N.loading,summon:Me,sending:v,failure:Re,draft:fe.current?.for===q?fe.current:null,onDraft:at},q);return(0,D.jsxs)(`div`,{className:c===null?`workspace is-alone`:`workspace`,children:[(0,D.jsx)(cn,{specs:e.entries,openSpec:c,spec:P,onOpenSpec:me,onBack:()=>me(null),artifacts:j,openArtifact:f,onOpenArtifact:e=>J(e,``),units:N.units,currentUnit:ee,marks:Ce,onOpenUnit:Y,onNewSpec:()=>W(`intake`)}),(0,D.jsxs)(`main`,{className:`stage`,"data-theme":ie.theme,children:[(0,D.jsx)(re,{theme:ie.theme,kept:ie.kept,onToggle:ie.toggle}),rt===null?M===null?(0,D.jsxs)(`div`,{className:`doc`,children:[S!==null&&At!==null?null:(0,D.jsx)(`p`,{className:`notice`,children:o??(e.entries.length===0?`No work here yet. Start a piece with New spec.`:c===null?`Nothing is open. Pick a piece of work on the left.`:u===null?`Opening…`:`This spec holds nothing to read yet.`)}),At]}):(0,D.jsxs)(`div`,{className:`doc-and-ask`,children:[(0,D.jsx)(Jt,{reader:se??``,entry:c??``,file:M,units:N.units,text:N.text,marks:Ce,loading:N.loading,failure:N.failure,raw:n,onToggleRead:Ee,landOn:m,onLanded:De,onCurrent:te,onOpen:we,onLeave:e=>void mt(e),onAnnotate:ye?ke:null,under:$e===null?null:{unit:$e,node:At}}),$e===null&&At]}):(0,D.jsx)(mn,{name:P?.name??c??``,proposal:rt.proposal,held:rt.held,wish:L.state?.wish.imagination===!0,onConfirm:e=>void lt(e),onAsk:e=>void I({event:`question`,detail:`the steps: ${e}`}),onCancel:rt.held===null?null:()=>X(!1),sending:v,failure:Re},`${c}:${rt.held===null?`propose:${rt.proposal.offeredAt??``}`:`amend`}`)]}),c!==null&&(0,D.jsx)(On,{spec:P,failure:be.failure??xe.failure,queue:Oe,filed:_e,onEdit:(e,t)=>F(n=>n.map(n=>n.id===e?{...n,text:t}:n)),onDrop:e=>F(t=>t.filter(t=>t.id!==e),!0),onSendOne:e=>{let t=Oe.find(t=>t.id===e);t&&je([t])},onSendBatch:()=>void je(Oe),sending:v,sent:b,onContinue:ut,onExecute:()=>W(`execute`),executable:Q,onQualityReview:$?yt:null,onArchive:()=>W(`archive`),protocol:L.state,onOpenArtifact:e=>J(e,``),onAnswer:e=>{if(X(!1),e!==R){z(e);return}let t=G?.file??``;t!==``&&we(t,``),Ne(e=>e+1)},onAmend:A?()=>{B(null),X(!0)}:null}),V===`archive`&&P!==null&&c!==null&&(0,D.jsx)(ue,{name:P.name,filed:zt(c,new Date),state:L.state,onArchive:()=>void Ct(),onCancel:()=>W(null),working:Ke,failure:We}),V===`execute`&&P!==null&&c!==null&&(0,D.jsx)(nn,{name:P.name,slug:c.slice(c.lastIndexOf(`/`)+1),phases:L.state?.phases??[],recommended:L.state?.runRecommendations??null,decided:L.state?.runDecisions??null,onRun:e=>void _t(e),onCancel:()=>W(null),working:Ke,failure:We},c),V===`intake`&&(0,D.jsx)(on,{onFile:ct,onCancel:()=>Z(E.current),filing:Ke,failure:We,draft:pe.current,onDraft:st},qe),S!==null&&(0,D.jsx)(Fn,{onCancel:()=>{w(null),x(`Nobody was told: there was no session in this window.`)},onConfirm:()=>{let e=S;w(null),ht({...e,create:!0}).then(e=>{x(e.ok?`A session was started, and it opens on this.`:`A session could not be started: ${e.error}`)})}})]})}function Fn({onCancel:e,onConfirm:t}){return(0,D.jsx)(`div`,{className:`dialog-shade`,children:(0,D.jsxs)(`div`,{className:`dialog`,role:`dialog`,"aria-modal":`true`,"aria-label":`No session is running`,children:[(0,D.jsx)(`div`,{className:`dialog-body`,children:(0,D.jsx)(`p`,{children:`No session is running in this window. Start one and let it pick this up?`})}),(0,D.jsxs)(`div`,{className:`dialog-acts`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:e,children:`Not now`}),(0,D.jsx)(`button`,{type:`button`,className:`send`,onClick:t,children:`Start`})]})]})})}_t();var In=document.getElementById(`root`);In&&(0,w.createRoot)(In).render((0,D.jsx)(C.StrictMode,{children:(0,D.jsx)(Pn,{})}));