@testmuai/kane-cli 0.6.8 → 0.6.10

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 (170) hide show
  1. package/dist/ChatSurface-PLXUGRBV.js +8 -0
  2. package/dist/{ChromeProfilePicker-FJOUNY2B.js → ChromeProfilePicker-IDKFTIHW.js} +1 -1
  3. package/dist/{CliFeedbackPrompt-HC4NNBTK.js → CliFeedbackPrompt-SZOU5FGZ.js} +1 -1
  4. package/dist/{CliUploadProgress-VIEZQNZ5.js → CliUploadProgress-W2FC33Q4.js} +1 -1
  5. package/dist/{ConfigView-LK5F4F7W.js → ConfigView-JB2NSZ2N.js} +1 -1
  6. package/dist/EvidenceViewOffer-5YST67KY.js +2 -0
  7. package/dist/{FolderPicker-3S57MSC6.js → FolderPicker-SPNZESAR.js} +1 -1
  8. package/dist/{HelpView-BQ3TS7WE.js → HelpView-XBDXXHFB.js} +1 -1
  9. package/dist/{InfoBox-4HVXV3TD.js → InfoBox-2T7GYSFT.js} +1 -1
  10. package/dist/{LinksBox-3B2KO5S4.js → LinksBox-2NNZZDQT.js} +1 -1
  11. package/dist/{ProfilesView-FLRMROUR.js → ProfilesView-KJZVGU5B.js} +1 -1
  12. package/dist/{ProjectPicker-R3KLRGHH.js → ProjectPicker-AUTZNEPE.js} +1 -1
  13. package/dist/{SaveSessionPrompt-P7HSG7R7.js → SaveSessionPrompt-LHLSJQSQ.js} +1 -1
  14. package/dist/SingleShotApp-Z2HGSZXG.js +2 -0
  15. package/dist/{SummaryBox-HCDIWKPS.js → SummaryBox-5G7WULUN.js} +1 -1
  16. package/dist/TestMdRunView-B4IZHRDT.js +2 -0
  17. package/dist/{WhoamiView-ZD6FIBMK.js → WhoamiView-XNWBDMQR.js} +1 -1
  18. package/dist/bind-FEOGBJ2O.js +6 -0
  19. package/dist/bootstrap-T6DSUI34.js +2 -0
  20. package/dist/{bridge-D2HETW5M.js → bridge-WMGH3O3B.js} +1 -1
  21. package/dist/{changelog-QB7S4VV4.js → changelog-AGFDNTTW.js} +1 -1
  22. package/dist/{chat-committer-MWZ4JQMM.js → chat-committer-4ENYH3RC.js} +1 -1
  23. package/dist/{chat-controller-YX5A7R52.js → chat-controller-M4QYRH7Y.js} +1 -1
  24. package/dist/chunk-26H3PDVN.js +4 -0
  25. package/dist/{chunk-5VC7MBHR.js → chunk-2H3XNXL3.js} +1 -1
  26. package/dist/chunk-2KS2YRIS.js +2 -0
  27. package/dist/{chunk-K7P6VNLI.js → chunk-2OQLMW3F.js} +1 -1
  28. package/dist/chunk-2XMJ6YAE.js +2 -0
  29. package/dist/{chunk-HCWEZCKP.js → chunk-3KN2UW37.js} +1 -1
  30. package/dist/{chunk-D5IZ77YG.js → chunk-4OSW2WEN.js} +35 -35
  31. package/dist/chunk-5EOX4MEY.js +2 -0
  32. package/dist/{chunk-NKUA3TSO.js → chunk-5F7PU5AJ.js} +1 -1
  33. package/dist/{chunk-YTK3IQUB.js → chunk-5LTUYXMP.js} +2 -2
  34. package/dist/{chunk-QOGQBVTP.js → chunk-5Z7GAIPP.js} +2 -2
  35. package/dist/{chunk-QFD6CB4P.js → chunk-6CGNLFSN.js} +1 -1
  36. package/dist/{chunk-NKCXCCPM.js → chunk-6JTEWZ75.js} +1 -1
  37. package/dist/{chunk-GFKIE3AL.js → chunk-6MTVGARW.js} +1 -1
  38. package/dist/{chunk-GO4CBUB6.js → chunk-6NWPK2MS.js} +1 -1
  39. package/dist/{chunk-3BIEIXJK.js → chunk-6ZJ7ZFEX.js} +1 -1
  40. package/dist/{chunk-ELN3EN4K.js → chunk-76I6NJBX.js} +1 -1
  41. package/dist/{chunk-IQFUBT6Z.js → chunk-7APDXIKI.js} +1 -1
  42. package/dist/{chunk-TFVMSEIA.js → chunk-7C6G4V43.js} +1 -1
  43. package/dist/{chunk-PV4EDQY4.js → chunk-7LWXIRI3.js} +1 -1
  44. package/dist/{chunk-L3HG5ONB.js → chunk-A46NBRAP.js} +1 -1
  45. package/dist/{chunk-66LXV7NN.js → chunk-AYDUHTPA.js} +1 -1
  46. package/dist/chunk-BKM2LWU2.js +3 -0
  47. package/dist/{chunk-JKHQBGFY.js → chunk-C3OGWCII.js} +2 -2
  48. package/dist/{chunk-TRXNJZSL.js → chunk-DHF3VO2R.js} +1 -1
  49. package/dist/{chunk-TBXIOT6M.js → chunk-ECFOND7B.js} +1 -1
  50. package/dist/chunk-EV3EHXEI.js +4 -0
  51. package/dist/{chunk-OYOTWI53.js → chunk-FEF75YKV.js} +1 -1
  52. package/dist/chunk-FHKDTM5L.js +6 -0
  53. package/dist/{chunk-EQORZ6RT.js → chunk-FYDBD7Q4.js} +1 -1
  54. package/dist/{chunk-FCZ2YFD3.js → chunk-GWJ76BLF.js} +2 -2
  55. package/dist/chunk-J44RN3FB.js +2 -0
  56. package/dist/{chunk-VZHXNQDO.js → chunk-J4WS2SXT.js} +1 -1
  57. package/dist/chunk-JHHMXU76.js +2 -0
  58. package/dist/chunk-JHPZXF77.js +14 -0
  59. package/dist/chunk-JTCW76YG.js +12 -0
  60. package/dist/{chunk-K5JGCJ2K.js → chunk-K7USHLVZ.js} +4 -4
  61. package/dist/{chunk-Q3WHZ26R.js → chunk-KA7Q5IIC.js} +1 -1
  62. package/dist/chunk-KFUZYEHX.js +2 -0
  63. package/dist/chunk-KK7DYHK6.js +347 -0
  64. package/dist/{chunk-AXJIXRYF.js → chunk-LPBAQQ7E.js} +1 -1
  65. package/dist/{chunk-ATO6NM45.js → chunk-MJF3USZF.js} +2 -2
  66. package/dist/{chunk-B22NUHB2.js → chunk-MSK7AC4E.js} +2 -2
  67. package/dist/{chunk-EYZWG32F.js → chunk-OESHJ4J2.js} +2 -2
  68. package/dist/chunk-OIYGGEUL.js +6 -0
  69. package/dist/chunk-Q2F5QB2W.js +2 -0
  70. package/dist/{chunk-D4WLVWJQ.js → chunk-QGBLC4ZJ.js} +1 -1
  71. package/dist/chunk-QPT4ERGK.js +47 -0
  72. package/dist/{chunk-K4ERF7GT.js → chunk-RH4GCEFX.js} +1 -1
  73. package/dist/{chunk-TAUSKB3O.js → chunk-RLZA4VJT.js} +1 -1
  74. package/dist/{chunk-VRVSOGXH.js → chunk-SACSQY3Q.js} +1 -1
  75. package/dist/{chunk-LEA6IHXC.js → chunk-SDRFTIRU.js} +1 -1
  76. package/dist/{chunk-SHAA6FOD.js → chunk-SKRZN25J.js} +1 -1
  77. package/dist/chunk-TLL7KFLY.js +6 -0
  78. package/dist/{chunk-MEHEGW3V.js → chunk-TW3K2DKB.js} +1 -1
  79. package/dist/chunk-VOHQA2SP.js +2 -0
  80. package/dist/{chunk-BLHCGRSK.js → chunk-VYQMCLKG.js} +1 -1
  81. package/dist/{chunk-F4FXE466.js → chunk-W54W762O.js} +1 -1
  82. package/dist/{chunk-27GF2OQ7.js → chunk-WSZ7IENQ.js} +3 -3
  83. package/dist/{chunk-YKZIACYJ.js → chunk-WV42KKEU.js} +1 -1
  84. package/dist/chunk-XY5KWIRF.js +3 -0
  85. package/dist/{chunk-YEMR62WY.js → chunk-XZW3TBOV.js} +1 -1
  86. package/dist/chunk-Y5RNCJAN.js +19 -0
  87. package/dist/{chunk-BUVRZXO3.js → chunk-YJIESLN6.js} +1 -1
  88. package/dist/{chunk-A6TFZQV6.js → chunk-YOFKDRY4.js} +1 -1
  89. package/dist/{chunk-N5YIMTGV.js → chunk-YVXC46DY.js} +1 -1
  90. package/dist/{chunk-6WHKJSMJ.js → chunk-Z25FKS3Y.js} +1 -1
  91. package/dist/{chunk-NVGTSXCJ.js → chunk-ZFFRHV5U.js} +1 -1
  92. package/dist/chunk-ZPENY2Q3.js +4 -0
  93. package/dist/{config-JV7HNJ3I.js → config-7WI6TBDV.js} +1 -1
  94. package/dist/{cover-cmd-L2HSVDLH.js → cover-cmd-J2ZJUL6P.js} +1 -1
  95. package/dist/{credentials-TQW3TT2I.js → credentials-MX5ABDPF.js} +1 -1
  96. package/dist/docx-convert-IAX54REO.js +2 -0
  97. package/dist/{dossier-ZHSHATVU.js → dossier-UVTGCL7T.js} +1 -1
  98. package/dist/{evidence-ZFYDHO73.js → evidence-TZYIOSPG.js} +1 -1
  99. package/dist/{evolve-cmd-YGJECGND.js → evolve-cmd-IDS5ZIUY.js} +1 -1
  100. package/dist/exit-manager-MXUD7GQ7.js +2 -0
  101. package/dist/{explain-cmd-E366QTAD.js → explain-cmd-NPKN63XL.js} +1 -1
  102. package/dist/{explain-cmd-327F6ESA.js → explain-cmd-R3WCNR2A.js} +1 -1
  103. package/dist/extract-bind-CISTQFI3.js +8 -0
  104. package/dist/{extract-cmd-TQ2MYXOG.js → extract-cmd-HG3DHHSL.js} +1 -1
  105. package/dist/{gaps-cmd-IAEXXESW.js → gaps-cmd-XLVUFSTY.js} +1 -1
  106. package/dist/{generate-headless-XXECVP6L.js → generate-headless-4VJMAHCU.js} +2 -2
  107. package/dist/index.js +67 -65
  108. package/dist/ingest-UAIKHOB4.js +2 -0
  109. package/dist/ingest-cmd-7HJLRLMG.js +4 -0
  110. package/dist/interactive-bind-IXFRXBBL.js +10 -0
  111. package/dist/{lifecycle-cmd-KZOC4WDW.js → lifecycle-cmd-VTFZ3TF2.js} +1 -1
  112. package/dist/{list-cmd-6X5U46RD.js → list-cmd-KXL4WQII.js} +1 -1
  113. package/dist/list-commands-BJYJ34HT.js +2 -0
  114. package/dist/{logical-ids-RFGWBVML.js → logical-ids-LMBNMENR.js} +1 -1
  115. package/dist/login-flow-KW5T7WRJ.js +2 -0
  116. package/dist/pdf-convert-S7VYE6AV.js +2 -0
  117. package/dist/{persist-recorded-session-DT3K6ZYQ.js → persist-recorded-session-QR7RVAXR.js} +1 -1
  118. package/dist/{pipeline-5N7HWGAL.js → pipeline-L6V24KGN.js} +1 -1
  119. package/dist/{readmodel-V3DVL6NP.js → readmodel-AGAPK2AI.js} +1 -1
  120. package/dist/reconcile-cmd-E2MMQM7Z.js +2 -0
  121. package/dist/{recording-banner-QI77ERTZ.js → recording-banner-QAIKLV6E.js} +1 -1
  122. package/dist/{require-project-folder-2UAXXZA4.js → require-project-folder-OANMHOVE.js} +1 -1
  123. package/dist/{review-cmd-XVWPSWU2.js → review-cmd-2FCGP55U.js} +1 -1
  124. package/dist/run-FYJZCWYS.js +2 -0
  125. package/dist/run-IOBBB7GN.js +2 -0
  126. package/dist/{run-test-md-DKRJOUFA.js → run-test-md-5E53A5DT.js} +2 -2
  127. package/dist/{sessions-cmd-STHKGDX4.js → sessions-cmd-DTQYDZNT.js} +1 -1
  128. package/dist/{skill-installer-TK5REDD6.js → skill-installer-LGEIIQ4Q.js} +1 -1
  129. package/dist/{spawner-K7LWPNIC.js → spawner-6FHAXNOA.js} +1 -1
  130. package/dist/store-id-EOSGEKVK.js +2 -0
  131. package/dist/tcg-generate-CEDA6DZJ.js +2 -0
  132. package/dist/testmd-actions-2OFH5GRJ.js +2 -0
  133. package/dist/token-refresh-R75DGT4X.js +2 -0
  134. package/dist/{validate-basic-XEJGB4GN.js → validate-basic-Z46MAH2G.js} +1 -1
  135. package/dist/{version-check-IT7T5YKJ.js → version-check-64M5JQQ7.js} +1 -1
  136. package/dist/{view-cmd-G4PGJRQH.js → view-cmd-PG66UQK7.js} +1 -1
  137. package/dist/walk-session-7PM2RXEF.js +2 -0
  138. package/package.json +10 -6
  139. package/dist/ChatSurface-QLRMFZJG.js +0 -8
  140. package/dist/EvidenceViewOffer-HZ4WZKGM.js +0 -2
  141. package/dist/SingleShotApp-ZBZY7KGR.js +0 -2
  142. package/dist/TestMdRunView-GQP2QGFU.js +0 -2
  143. package/dist/bind-RSVQXQJT.js +0 -6
  144. package/dist/chunk-35RV2AAV.js +0 -12
  145. package/dist/chunk-4GXOBABK.js +0 -4
  146. package/dist/chunk-BSFONZ2E.js +0 -2
  147. package/dist/chunk-E4EHWO3J.js +0 -4
  148. package/dist/chunk-FXPPQL4D.js +0 -6
  149. package/dist/chunk-K4LCN5X4.js +0 -6
  150. package/dist/chunk-M5JQXOCE.js +0 -12
  151. package/dist/chunk-PXPXK4Q7.js +0 -2
  152. package/dist/chunk-QZ7DZXLQ.js +0 -14
  153. package/dist/chunk-RHNKYNNZ.js +0 -6
  154. package/dist/chunk-XSAZDIQV.js +0 -347
  155. package/dist/chunk-XWIN3S7O.js +0 -4
  156. package/dist/exit-manager-VCSIUYBR.js +0 -2
  157. package/dist/extract-bind-7UZXDON6.js +0 -5
  158. package/dist/ingest-CBQAXVH6.js +0 -2
  159. package/dist/ingest-cmd-JN6PLDE3.js +0 -3
  160. package/dist/interactive-bind-WA2YVAUW.js +0 -7
  161. package/dist/list-commands-I577A5LK.js +0 -2
  162. package/dist/login-flow-OVEZXSMW.js +0 -2
  163. package/dist/pdf-convert-KYXI4FU4.js +0 -2
  164. package/dist/reconcile-cmd-HYYH3SZS.js +0 -2
  165. package/dist/run-RYIYWV63.js +0 -2
  166. package/dist/run-VMKZDO7J.js +0 -2
  167. package/dist/tcg-generate-6EJLU5KX.js +0 -2
  168. package/dist/testmd-actions-Q2XWL7P5.js +0 -2
  169. package/dist/token-refresh-NQZJEUQE.js +0 -2
  170. package/dist/walk-session-HCTG4LN2.js +0 -2
@@ -1,7 +1,7 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{c as H,d as z}from"./chunk-2YQ6TW77.js";import{b as p,c as E,d as j,e as y,f as M,g as C,i as A,l as D,m as F,p as T,r as $,s as O}from"./chunk-RKWJG3WW.js";import{a as B}from"./chunk-NKCXCCPM.js";import{h as R,i as k}from"./chunk-M5JQXOCE.js";import{a as P}from"./chunk-PXPXK4Q7.js";import{e as q}from"./chunk-UR6MHSHU.js";import{existsSync as f,mkdirSync as V,readFileSync as Z,renameSync as N,writeFileSync as K}from"fs";import{join as Q}from"path";function fe(e){D(p(e));let t=p(e);if(!f(t))return;let n=Q(t,"meta.json"),r=y(e);if(f(n)&&!f(r))try{V(j(e),{recursive:!0}),N(n,r)}catch(o){process.stderr.write(`warn: meta.json migration failed: ${o.message}
2
+ import{c as H,d as z}from"./chunk-2YQ6TW77.js";import{b as p,c as E,d as j,e as y,f as M,g as C,i as A,l as D,m as F,p as T,r as $,s as O}from"./chunk-RKWJG3WW.js";import{a as B}from"./chunk-6JTEWZ75.js";import{p as R,q as k}from"./chunk-Y5RNCJAN.js";import{a as P}from"./chunk-2KS2YRIS.js";import{e as q}from"./chunk-UR6MHSHU.js";import{existsSync as f,mkdirSync as V,readFileSync as Z,renameSync as N,writeFileSync as K}from"fs";import{join as Q}from"path";function fe(e){D(p(e));let t=p(e);if(!f(t))return;let n=Q(t,"meta.json"),r=y(e);if(f(n)&&!f(r))try{V(j(e),{recursive:!0}),N(n,r)}catch(o){process.stderr.write(`warn: meta.json migration failed: ${o.message}
3
3
  `)}let i=C(e);if(f(i)){let o="python";try{let c=new B().load();c.code_export?.language&&(o=c.code_export.language)}catch{}let a=M(e,"playwright",o);if(!f(a))try{N(i,a)}catch(c){process.stderr.write(`warn: generated-code migration failed: ${c.message}
4
4
  `)}}if(f(r))try{let o=JSON.parse(Z(r,"utf8"));"md5sum"in o&&(delete o.md5sum,K(r,JSON.stringify(o,null,2)+`
5
5
  `,"utf8"))}catch(o){process.stderr.write(`warn: meta.json md5sum strip failed: ${o.message}
6
- `)}}async function ye(e){if(!e.isInteractive)return{recovered:!1};if(W(e.creds))return{recovered:!1};let{SingleShotApp:t}=await import("./SingleShotApp-ZBZY7KGR.js"),{ScrollbackProvider:n}=await import("./scrollback-JLPJR25X.js"),{render:r}=await import("./build-JIKYOZUH.js"),i=await import("./react-QWOAB3TB.js"),o={current:null},a={current:!1},{waitUntilExit:c,unmount:l}=r(i.default.createElement(n,null,i.default.createElement(t,{resultRef:o,mode:"login",loginCompleteRef:a})),{exitOnCtrlC:!1});k(()=>l()),await c();try{process.stdin.setRawMode?.(!1)}catch{}return process.stdout.write("\x1B[?25h"),a.current?{recovered:!0}:(R(0,"Startup gate cancelled"),{recovered:!1})}function W(e){let t=e.getActiveProfile(),n=e.getDefaultEnv();if(!t||!!!(e.loadBasicAuth(t,n)||e.loadCredentials(t,n)))return!1;let i=e.loadProfileConfig(t,n)??{};return!!i.project_id&&!!i.folder_id}var J=q(H(),1);import{existsSync as v,readFileSync as U,readdirSync as X,statSync as Y}from"fs";import{dirname as ee,isAbsolute as te,join as g,relative as x,resolve as re,sep as h}from"path";import{createHash as ne}from"crypto";var S="testmd-bundle.json",d=class extends Error{constructor(t){super(t),this.name="BundleUsageError"}},_=e=>e.split(h).join("/");function I(e){if(!v(e))return[];let t=[];for(let n of X(e).sort()){let r=g(e,n);Y(r).isDirectory()?t.push(...I(r)):t.push(r)}return t}function se(e){let t=e.map(r=>ee(r).split(h)),n=t[0];for(let r of t.slice(1)){let i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;n=n.slice(0,i)}return n.join(h)||h}function ie(e){for(let t of e){let n=F(t,U(t,"utf8"));for(let r of n.steps)if(r.body.kind==="import_ref"&&te(r.body.path))throw new d(`bundle sync: absolute @import is not portable after unzip: ${t} step ${r.index} (@import ${r.body.path})`)}}function G(e){let t=re(e),n=T(t);if(!n?.commit_id||!n?.test_id)throw new d(`bundle sync: ${t} is not authored \u2014 run \`kane-cli testmd run\` first (output-<stem>/.internal/meta.json needs commit_id + test_id)`);let r;try{r=O(t)}catch(s){throw s instanceof $?new d(`bundle sync: ${s.message}`):s}let i=[t];for(let s of r.steps)for(let u of s.trace.slice(1))i.includes(u.file)||i.push(u.file);ie(i);let o=[];for(let s of r.unitFiles){if(s.file===t)continue;let u=p(s.file);o.includes(u)||o.push(u)}let a=[...i],c=s=>{v(s)&&a.push(s)};c(E(t)),a.push(y(t)),c(g(p(t),".internal","execution.json")),a.push(...I(A(t)));for(let s of o)c(g(s,"Result.md")),a.push(...I(g(s,".internal","steps")));let l=se(a);if(v(g(l,S)))throw new d(`bundle sync: a real file named ${S} exists at the zip root (${l}) \u2014 it would collide with the generated manifest`);let b=a.map(s=>{let u=U(s);return{abs:s,rel:_(x(l,s)),sha256:ne("sha256").update(u).digest("hex"),bytes:u.length}}).sort((s,u)=>s.rel<u.rel?-1:1),m=_(x(l,t)),L={schema_version:2,entry:m,commit_id:n.commit_id,test_id:n.test_id,testcase_id:n.testcase_id??null,project_id:n.project_id??null,folder_id:n.folder_id??null,org_id:n.org_id??null,created_at:new Date().toISOString(),producer:{name:"kane-cli",version:P},files:b.map(s=>({path:s.rel,sha256:s.sha256,bytes:s.bytes})),units:r.unitFiles.filter(s=>s.file!==t).map(s=>({path:_(x(l,s.file)),kind:s.kind}))};return{zipRoot:l,entry:m,files:b,manifest:L}}var w=e=>e instanceof Error?e.message:String(e);function oe(e){return new Promise((t,n)=>{let r=(0,J.default)("zip",{zlib:{level:6}}),i=[];r.on("data",o=>i.push(o)),r.on("error",n),r.on("end",()=>t(Buffer.concat(i))),r.append(JSON.stringify(e.manifest,null,2)+`
6
+ `)}}async function ye(e){if(!e.isInteractive)return{recovered:!1};if(W(e.creds))return{recovered:!1};let{SingleShotApp:t}=await import("./SingleShotApp-Z2HGSZXG.js"),{ScrollbackProvider:n}=await import("./scrollback-JLPJR25X.js"),{render:r}=await import("./build-JIKYOZUH.js"),i=await import("./react-QWOAB3TB.js"),o={current:null},a={current:!1},{waitUntilExit:c,unmount:l}=r(i.default.createElement(n,null,i.default.createElement(t,{resultRef:o,mode:"login",loginCompleteRef:a})),{exitOnCtrlC:!1});k(()=>l()),await c();try{process.stdin.setRawMode?.(!1)}catch{}return process.stdout.write("\x1B[?25h"),a.current?{recovered:!0}:(R(0,"Startup gate cancelled"),{recovered:!1})}function W(e){let t=e.getActiveProfile(),n=e.getDefaultEnv();if(!t||!!!(e.loadBasicAuth(t,n)||e.loadCredentials(t,n)))return!1;let i=e.loadProfileConfig(t,n)??{};return!!i.project_id&&!!i.folder_id}var J=q(H(),1);import{existsSync as v,readFileSync as U,readdirSync as X,statSync as Y}from"fs";import{dirname as ee,isAbsolute as te,join as g,relative as x,resolve as re,sep as h}from"path";import{createHash as ne}from"crypto";var S="testmd-bundle.json",d=class extends Error{constructor(t){super(t),this.name="BundleUsageError"}},_=e=>e.split(h).join("/");function I(e){if(!v(e))return[];let t=[];for(let n of X(e).sort()){let r=g(e,n);Y(r).isDirectory()?t.push(...I(r)):t.push(r)}return t}function se(e){let t=e.map(r=>ee(r).split(h)),n=t[0];for(let r of t.slice(1)){let i=0;for(;i<n.length&&i<r.length&&n[i]===r[i];)i++;n=n.slice(0,i)}return n.join(h)||h}function ie(e){for(let t of e){let n=F(t,U(t,"utf8"));for(let r of n.steps)if(r.body.kind==="import_ref"&&te(r.body.path))throw new d(`bundle sync: absolute @import is not portable after unzip: ${t} step ${r.index} (@import ${r.body.path})`)}}function G(e){let t=re(e),n=T(t);if(!n?.commit_id||!n?.test_id)throw new d(`bundle sync: ${t} is not authored \u2014 run \`kane-cli testmd run\` first (output-<stem>/.internal/meta.json needs commit_id + test_id)`);let r;try{r=O(t)}catch(s){throw s instanceof $?new d(`bundle sync: ${s.message}`):s}let i=[t];for(let s of r.steps)for(let u of s.trace.slice(1))i.includes(u.file)||i.push(u.file);ie(i);let o=[];for(let s of r.unitFiles){if(s.file===t)continue;let u=p(s.file);o.includes(u)||o.push(u)}let a=[...i],c=s=>{v(s)&&a.push(s)};c(E(t)),a.push(y(t)),c(g(p(t),".internal","execution.json")),a.push(...I(A(t)));for(let s of o)c(g(s,"Result.md")),a.push(...I(g(s,".internal","steps")));let l=se(a);if(v(g(l,S)))throw new d(`bundle sync: a real file named ${S} exists at the zip root (${l}) \u2014 it would collide with the generated manifest`);let b=a.map(s=>{let u=U(s);return{abs:s,rel:_(x(l,s)),sha256:ne("sha256").update(u).digest("hex"),bytes:u.length}}).sort((s,u)=>s.rel<u.rel?-1:1),m=_(x(l,t)),L={schema_version:2,entry:m,commit_id:n.commit_id,test_id:n.test_id,testcase_id:n.testcase_id??null,project_id:n.project_id??null,folder_id:n.folder_id??null,org_id:n.org_id??null,created_at:new Date().toISOString(),producer:{name:"kane-cli",version:P},files:b.map(s=>({path:s.rel,sha256:s.sha256,bytes:s.bytes})),units:r.unitFiles.filter(s=>s.file!==t).map(s=>({path:_(x(l,s.file)),kind:s.kind}))};return{zipRoot:l,entry:m,files:b,manifest:L}}var w=e=>e instanceof Error?e.message:String(e);function oe(e){return new Promise((t,n)=>{let r=(0,J.default)("zip",{zlib:{level:6}}),i=[];r.on("data",o=>i.push(o)),r.on("error",n),r.on("end",()=>t(Buffer.concat(i))),r.append(JSON.stringify(e.manifest,null,2)+`
7
7
  `,{name:S});for(let o of e.files)r.file(o.abs,{name:o.rel});r.finalize()})}async function ae(e){let{plan:t,controller:n,testId:r,sessionId:i,commitId:o}=e,a;try{a=await oe(t)}catch(l){return{ok:!1,stage:"zip",error:w(l)}}let c;try{let l={key:"testmd",content_type:"application/zip",filename:`${o}-testmd.zip`},m=(await n.getPresignedUrls(r,i,[l])).urls?.testmd?.upload_url;if(!m)return{ok:!1,stage:"presign",error:"presign response missing testmd upload_url"};c=m}catch(l){return{ok:!1,stage:"presign",error:w(l)}}try{await z(c,a,"application/zip")}catch(l){return{ok:!1,stage:"upload",error:w(l)}}return{ok:!0,bytes:a.length}}async function Ee(e){let t;try{t=G(e.sourcePath)}catch(n){return n instanceof d?{ok:!1,stage:"collect",error:n.message}:{ok:!1,stage:"collect",error:w(n)}}return ae({...e,plan:t})}function je(e){return e.shouldUploadPipeline&&e.uploadSucceeded&&!!e.metaCommitId&&!!e.metaTestId}export{fe as a,ye as b,Ee as c,je as d};
@@ -0,0 +1,2 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import{c as d}from"./chunk-FHKDTM5L.js";function c(e){return{id:e.id,text:e.question,risk:["high","med","low"].includes(e.risk)?e.risk:"med",rationale:e.rationale,options:e.options.map(n=>({label:n.label,detail:n.description??""})),recommended_index:e.recommendedOptionIndex,allow_free_text:e.allowFreeText,kind:e.kind,consequence:e.consequence,evidence_count:e.evidence_count,multi_select:e.multiSelect}}function l(e){return{id:e.id,header:e.kind??"question",question:e.text,kind:e.kind??"clarify",multiSelect:e.multi_select??!1,options:e.options.map((n,s)=>({id:`o${s}`,label:n.label,description:n.detail||void 0})),recommendedOptionIndex:e.recommended_index,risk:e.risk,rationale:e.rationale,consequence:e.consequence??"",evidence_count:e.evidence_count,allowFreeText:e.allow_free_text}}function m(e,n){e.save({agent_state:n.agent_state,pending:{questions:n.pending.questions.map(l),proposals:n.pending.proposals??[]},assumed:n.assumed.map(s=>({questionId:s.question_id,optionId:s.option_id,flagged:!0,eventId:`assumed:${n.sid}:${s.question_id}`}))}),e.release()}function f(e,n,s){let t=d(e,n),o=[];for(let[i,a]of Object.entries(t.state.read_basis))(s.heads.get(i)??null)!==a&&o.push(i);let r=t.state.pending.questions.filter(i=>!t.isApplied(`resolveq:${n}:${i.id}`)&&!t.isApplied(`assumed:${n}:${i.id}`));return{handle:t,represent:[...t.state.pending.proposals],questions:r,staleBasis:o}}export{c as a,m as b,f as c};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{a as f}from"./chunk-N5YIMTGV.js";import{y as t}from"./chunk-PXPXK4Q7.js";import{a as x}from"./chunk-HCBYKLMW.js";import{a as r,b as n}from"./chunk-C44QQJR4.js";import{a as B}from"./chunk-6YGTRKDT.js";import{e as p}from"./chunk-UR6MHSHU.js";var c=p(B(),1);var e=p(x(),1);function v(){return[{name:"convert",label:"Converting session data",status:"pending"},{name:"zip",label:"Compressing artifacts",status:"pending"},{name:"presign",label:"Requesting upload URLs",status:"pending"},{name:"upload",label:"Uploading to KaneAI",status:"pending"},{name:"atomic_replace",label:"Replacing local output",status:"pending"},{name:"commit_lock",label:"Committing to TMS",status:"pending"},{name:"finalize",label:"Finalizing test case",status:"pending"},{name:"code_export",label:"Downloading test code",status:"pending"}]}function U(s,o,d,a){return s.map(l=>l.name===o?{...l,status:d,detail:a}:l)}function R(s){let o=s/1e3;if(o<60)return`${o.toFixed(1)}s`;let d=Math.floor(o/60),a=Math.round(o%60);return`${d}m ${a}s`}function D(s){let[o,d]=(0,c.useState)(0),a=c.default.useRef(Date.now());return(0,c.useEffect)(()=>{if(!s)return;a.current=Date.now();let l=setInterval(()=>{d(Date.now()-a.current)},100);return()=>clearInterval(l)},[s]),o}function h({steps:s,status:o,testUrl:d,error:a}){let l=D(o==="uploading");return o==="uploading"?(0,e.jsxs)(r,{flexDirection:"column",paddingX:1,paddingY:1,children:[(0,e.jsxs)(r,{children:[(0,e.jsx)(n,{color:t.orange,children:"\u2601 "}),(0,e.jsx)(n,{color:t.orange,bold:!0,children:"Saving to KaneAI"}),(0,e.jsxs)(n,{color:t.dim,children:[" ",R(l)]})]}),(0,e.jsx)(r,{flexDirection:"column",marginTop:1,children:s.filter(i=>i.status!=="skipped").map((i,S,T)=>{let b=S===T.length-1?"\u2514\u2500":"\u251C\u2500",u=i.status==="done",m=i.status==="running",g=i.status==="failed";return(0,e.jsxs)(r,{children:[(0,e.jsxs)(n,{color:t.dim,children:[" ",b," "]}),(0,e.jsx)(r,{width:3,children:m?(0,e.jsx)(f,{}):u?(0,e.jsx)(n,{color:t.green,children:"\u2713"}):g?(0,e.jsx)(n,{color:t.red,children:"\u2717"}):(0,e.jsx)(n,{color:t.muted,children:"\u25CB"})}),(0,e.jsx)(n,{color:u?t.dim:m?void 0:g?t.red:t.muted,children:i.label}),i.detail&&(0,e.jsxs)(n,{color:t.dim,children:[" ",i.detail]})]},i.name)})}),(0,e.jsx)(r,{marginTop:1,children:(0,e.jsx)(n,{color:t.muted,children:" press Ctrl+C twice to force exit"})})]}):o==="success"?(0,e.jsx)(e.Fragment,{}):(0,e.jsxs)(r,{flexDirection:"column",paddingX:1,paddingY:1,children:[(0,e.jsxs)(r,{children:[(0,e.jsx)(n,{color:t.red,children:"\u2601 "}),(0,e.jsx)(n,{color:t.red,bold:!0,children:"Save failed"})]}),a&&(0,e.jsxs)(r,{marginTop:0,children:[(0,e.jsx)(n,{color:t.dim,children:" "}),(0,e.jsx)(n,{color:t.dim,children:a})]})]})}export{v as a,U as b,h as c};
2
+ import{a as f}from"./chunk-YVXC46DY.js";import{y as t}from"./chunk-2KS2YRIS.js";import{a as x}from"./chunk-HCBYKLMW.js";import{a as r,b as n}from"./chunk-C44QQJR4.js";import{a as B}from"./chunk-6YGTRKDT.js";import{e as p}from"./chunk-UR6MHSHU.js";var c=p(B(),1);var e=p(x(),1);function v(){return[{name:"convert",label:"Converting session data",status:"pending"},{name:"zip",label:"Compressing artifacts",status:"pending"},{name:"presign",label:"Requesting upload URLs",status:"pending"},{name:"upload",label:"Uploading to KaneAI",status:"pending"},{name:"atomic_replace",label:"Replacing local output",status:"pending"},{name:"commit_lock",label:"Committing to TMS",status:"pending"},{name:"finalize",label:"Finalizing test case",status:"pending"},{name:"code_export",label:"Downloading test code",status:"pending"}]}function U(s,o,d,a){return s.map(l=>l.name===o?{...l,status:d,detail:a}:l)}function R(s){let o=s/1e3;if(o<60)return`${o.toFixed(1)}s`;let d=Math.floor(o/60),a=Math.round(o%60);return`${d}m ${a}s`}function D(s){let[o,d]=(0,c.useState)(0),a=c.default.useRef(Date.now());return(0,c.useEffect)(()=>{if(!s)return;a.current=Date.now();let l=setInterval(()=>{d(Date.now()-a.current)},100);return()=>clearInterval(l)},[s]),o}function h({steps:s,status:o,testUrl:d,error:a}){let l=D(o==="uploading");return o==="uploading"?(0,e.jsxs)(r,{flexDirection:"column",paddingX:1,paddingY:1,children:[(0,e.jsxs)(r,{children:[(0,e.jsx)(n,{color:t.orange,children:"\u2601 "}),(0,e.jsx)(n,{color:t.orange,bold:!0,children:"Saving to KaneAI"}),(0,e.jsxs)(n,{color:t.dim,children:[" ",R(l)]})]}),(0,e.jsx)(r,{flexDirection:"column",marginTop:1,children:s.filter(i=>i.status!=="skipped").map((i,S,T)=>{let b=S===T.length-1?"\u2514\u2500":"\u251C\u2500",u=i.status==="done",m=i.status==="running",g=i.status==="failed";return(0,e.jsxs)(r,{children:[(0,e.jsxs)(n,{color:t.dim,children:[" ",b," "]}),(0,e.jsx)(r,{width:3,children:m?(0,e.jsx)(f,{}):u?(0,e.jsx)(n,{color:t.green,children:"\u2713"}):g?(0,e.jsx)(n,{color:t.red,children:"\u2717"}):(0,e.jsx)(n,{color:t.muted,children:"\u25CB"})}),(0,e.jsx)(n,{color:u?t.dim:m?void 0:g?t.red:t.muted,children:i.label}),i.detail&&(0,e.jsxs)(n,{color:t.dim,children:[" ",i.detail]})]},i.name)})}),(0,e.jsx)(r,{marginTop:1,children:(0,e.jsx)(n,{color:t.muted,children:" press Ctrl+C twice to force exit"})})]}):o==="success"?(0,e.jsx)(e.Fragment,{}):(0,e.jsxs)(r,{flexDirection:"column",paddingX:1,paddingY:1,children:[(0,e.jsxs)(r,{children:[(0,e.jsx)(n,{color:t.red,children:"\u2601 "}),(0,e.jsx)(n,{color:t.red,bold:!0,children:"Save failed"})]}),a&&(0,e.jsxs)(r,{marginTop:0,children:[(0,e.jsx)(n,{color:t.dim,children:" "}),(0,e.jsx)(n,{color:t.dim,children:a})]})]})}export{v as a,U as b,h as c};
@@ -0,0 +1,2 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import{extname as o}from"path";var n=[{kind:"text",media_type:"text/plain",extensions:[".txt"],cite:"verbatim",maxBytes:2e6},{kind:"markdown",media_type:"text/markdown",extensions:[".md",".markdown"],cite:"verbatim",maxBytes:2e6},{kind:"image",media_type:"image/png",extensions:[".png"],cite:"anchor-only",maxBytes:5e6},{kind:"image",media_type:"image/jpeg",extensions:[".jpg",".jpeg"],cite:"anchor-only",maxBytes:5e6},{kind:"image",media_type:"image/webp",extensions:[".webp"],cite:"anchor-only",maxBytes:5e6},{kind:"text",media_type:"application/json",extensions:[".json"],cite:"verbatim",maxBytes:2e6},{kind:"text",media_type:"application/yaml",extensions:[".yaml",".yml"],cite:"verbatim",maxBytes:2e6},{kind:"text",media_type:"application/toml",extensions:[".toml"],cite:"verbatim",maxBytes:2e6},{kind:"text",media_type:"application/xml",extensions:[".xml"],cite:"verbatim",maxBytes:2e6},{kind:"text",media_type:"text/plain",extensions:[".log"],cite:"verbatim",maxBytes:2e6},{kind:"pdf",media_type:"application/pdf",extensions:[".pdf"],cite:"verbatim",maxBytes:25e6,sniff:e=>e.subarray(0,5).toString("latin1")==="%PDF-"},{kind:"docx",media_type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",extensions:[".docx"],cite:"verbatim",maxBytes:25e6,sniff:e=>e.length>=4&&e[0]===80&&e[1]===75&&e[2]===3&&e[3]===4,sniffFail:e=>e.length>=8&&e.subarray(0,8).equals(s)?"DOCX_ENCRYPTED_OR_LEGACY: password-protected Office file (or a legacy .doc renamed .docx) \u2014 remove the password / save as .docx and re-ingest":void 0}],s=Buffer.from([208,207,17,224,161,177,26,225]),d={pdf:"pdf",docx:"docx"},x=new Set(Object.keys(d));function r(e){let a=o(e).toLowerCase(),i=n.find(t=>t.extensions.includes(a));return i?{ok:!0,media:i}:{ok:!1,code:"UNSUPPORTED_MEDIA",allowlist:n.flatMap(t=>t.extensions)}}export{d as a,x as b,r as c};
@@ -0,0 +1,14 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import{b as j}from"./chunk-5Z7GAIPP.js";import{a as U}from"./chunk-DNNZ353O.js";import{d as F}from"./chunk-QM4S2APK.js";import{a as x}from"./chunk-SDRFTIRU.js";import{a as D,b as M,e as G,f as N}from"./chunk-A46NBRAP.js";import{b as V}from"./chunk-MBXWXBDM.js";import{d as b,e as $,g as P}from"./chunk-5YPBPZUR.js";function W(e,n,t,i,o){let d=t.rows.filter(p=>{let u=i.get(p.temp_ref);return u!==void 0&&u!=="reject"});if(d.length===0)return{record:null,errors:null};let s={version:1,read_basis:n.latestHash,source:{source_id:t.source_id,source_cid:n.heads.get(t.source_id)??""},use_cases:d.map(p=>p.uc)},g=new Map;for(let p of d){let u=i.get(p.temp_ref);typeof u=="object"?g.set(p.temp_ref,{resolution:"edited",edit:u.edited}):g.set(p.temp_ref,{resolution:p.uc.matches_existing&&p.uc.changed?"edited":"approved"})}let l=ee(s,n,t.staged_source_cid);if(l.errors!==null)return{record:null,errors:l.errors};let r=l.proposal,f=s.source.source_cid?L(e,n,s.source.source_cid):null;if(f!==null){r=Z(r,f);let p=G(r,z(f),n);if(p.length>0)return{record:null,errors:[{code:"HELD_CITES_STALE",detail:"the source moved after this plan staged \u2014 its quotes no longer verify against the current head; re-run kane-cli maintain reconcile to re-stage"},...p]}}let m=`held-${(n.latestHash??"root").slice(-12)}-${d.length}`;return N({contextDir:e,graph:n,proposal:r,proposalId:m,verdicts:g,by:o,autoName:!0})}function z(e){return e.replace(/\n$/,"").split(`
3
+ `).map((t,i)=>`${String(i+1).padStart(4,"0")}| ${t}`).join(`
4
+ `)}function Z(e,n){let t=n.replace(/\n$/,""),i=z(n),o=d=>{if(!d?.quote)return d;let s=M(i,d.anchor);if(s!==null&&s.includes(d.quote))return d;let g=t.indexOf(d.quote);if(g===-1||t.indexOf(d.quote,g+1)!==-1)return d;let l=t.slice(0,g).split(`
5
+ `).length,r=l+d.quote.replace(/\n$/,"").split(`
6
+ `).length-1;return{...d,anchor:`L${l}-L${r}`}};return{...e,use_cases:e.use_cases.map(d=>({...d,cite:o(d.cite)??d.cite,...d.criteria?{criteria:d.criteria.map(s=>({...s,cite:o(s.cite)??s.cite}))}:{},...d.updated?.criteria?{updated:{...d.updated,criteria:d.updated.criteria.map(s=>({...s,cite:o(s.cite)??s.cite}))}}:{}}))}}function ee(e,n,t){let i=[],o=n.mediaOf(e.source.source_cid).images??[],d=t!==void 0?n.mediaOf(t).images??[]:null,s=(l,r)=>{let f=l?D(l.anchor):null;if(!l||f?.kind!=="img-part")return l;if(d===null)return i.push({code:"HELD_CITES_STALE",detail:`${r}: this plan predates image-part staging \u2014 ${l.anchor} cannot be verified against the version it staged under; re-run kane-cli maintain reconcile to re-stage`}),l;let m=d.find(c=>c.ref===f.ref)?.blob;if(m===void 0)return i.push({code:"HELD_CITES_STALE",detail:`${r}: ${l.anchor} names no decodable image of the staged version \u2014 re-run kane-cli maintain reconcile to re-stage`}),l;if(o.some(c=>c.ref===f.ref&&c.blob===m))return l;let p=o.filter(c=>c.blob===m),u=p.filter(c=>c.delivery==="selected");if(u.length===1)return{...l,anchor:`img#${u[0].ref}`};if(p.length===1)return{...l,anchor:`img#${p[0].ref}`};if(p.length===0){let c=d.find(h=>h.ref===f.ref)?.appearance;if(c!==void 0){let h=o.filter(v=>v.appearance===c),E=h.filter(v=>v.delivery==="selected");if(E.length===1)return{...l,anchor:`img#${E[0].ref}`};if(h.length===1)return{...l,anchor:`img#${h[0].ref}`}}}return i.push({code:"HELD_CITES_STALE",detail:`${r}: the image behind ${l.anchor} is ${p.length===0?"no longer in":"ambiguous in"} the current head \u2014 re-run kane-cli maintain reconcile to re-stage`}),l};return{proposal:{...e,use_cases:e.use_cases.map(l=>({...l,cite:s(l.cite,l.temp_ref)??l.cite,...l.criteria?{criteria:l.criteria.map(r=>({...r,cite:s(r.cite,l.temp_ref)??r.cite}))}:{},...l.updated?.criteria?{updated:{...l.updated,criteria:l.updated.criteria.map(r=>({...r,cite:s(r.cite,l.temp_ref)??r.cite}))}}:{}}))},errors:i.length>0?i:null}}function J(e,n,t=[]){let i=j(e,n),o=new Set,d=[],s=f=>{!f||o.has(f)||(o.add(f),d.push(y(e,f)))};for(let f of i.pairs)s(f.scenario),s(f.test);for(let[f,m]of i.verifies){s(f);for(let p of m)s(p)}if(t.length===0)return{stale_refs:d};let g=f=>`${String(f.props.source_id)}\0${String(f.props.anchor)}`,l=new Set;for(let{cid:f}of e.byLabel(b.USECASE))if(e.tipOf(f)===n)for(let m of e.edgesInto(f)){if(m.type!==$.DERIVES)continue;let p=m.props.claim;typeof p=="string"&&t.includes(p)&&l.add(g(m))}if(l.size===0)return{stale_refs:d};let r=new Set;for(let[f,m]of i.verifies)if(e.edgesInto(f).some(u=>u.type===$.DERIVES&&l.has(g(u)))){r.add(y(e,f));for(let u of m)r.add(y(e,u))}return{stale_refs:d,...r.size>0?{direct_refs:[...r]}:{}}}var B="this release plans changes only \u2014 blast-radius impact and drift meaning-checks are not measured, and REMOVE rows are never executed automatically",te="suite untouched; graph updated";function T(e,n){return!e.superseded.has(n)&&e.trust.get(n)!=="archived"}function y(e,n,t=new Set){let i=e.nameOf.get(n);if(i!==void 0)return i;if(t.has(n))return n;t.add(n);for(let[o,d]of e.superseded){if(d!==n)continue;let s=y(e,o,t);if(s!==o)return s}return n}function C(e){return String(e).slice(0,19)}function A(e,n,t){let i=e.edgesFrom(n).find(o=>o.type===t);return i?e.tipOf(i.dst):null}function Y(e,n){let t=e.nodeLabel.get(n);if(t===b.USECASE)return n;if(t===b.SCENARIO)return A(e,n,$.BELONGS_TO);if(t===b.AC){let i=A(e,n,$.SCOPED_TO);return i?e.nodeLabel.get(i)===b.USECASE?i:A(e,i,$.BELONGS_TO):null}if(t===b.TEST){let i=A(e,n,$.AUTOMATES);return i?A(e,i,$.BELONGS_TO):null}return null}function q(e,n){let t=[],i=new Map;for(let o of e.derivesInto(n))i.set(String(o.props.source_id),o);for(let[o,d]of i){let s=e.heads.get(o);if(s==null){t.push(`DERIVES pin ${o} @ ${C(d.props.source_cid)} \u2014 source retired`);continue}if(s!==d.props.source_cid){let g=e.convChains.get(o)?.chain;if(g&&g.includes(String(d.props.source_cid)))continue;t.push(`DERIVES pin ${o} @ ${C(d.props.source_cid)} \u2014 source head moved to ${C(s)}`)}}for(let o of e.edgesFrom(n))P(o.type)?.pin?.comparesTo==="dst_tip"&&e.superseded.has(o.dst)&&t.push(`${o.type} pin \u2192 ${y(e,o.dst)} \u2014 target superseded`);return t.join("; ")||"structural pin broken"}var ne=new Set([b.USECASE,b.SCENARIO,b.AC,b.TEST]);function O(e,n){return e.ref<n.ref?-1:e.ref>n.ref?1:0}function L(e,n,t){let i=U(e,n,t);return i===null?null:i.toString("utf8")}function re(e,n,t,i,o){let d=t.props.quote;if(typeof d=="string"&&d.length>0)return i.includes(d);let s=String(t.props.source_cid);o.has(s)||o.set(s,L(e,n,s));let g=o.get(s);if(g===null)return!1;let l=M(g,String(t.props.anchor));return l===null?!1:l.split(`
7
+ `).some(r=>r.trim().length>0&&i.includes(r.trim()))}function se(e,n,t){let i=D(String(n.props.anchor));if(i?.kind!=="img-part")return!1;let d=(e.mediaOf(String(n.props.source_cid)).images??[]).find(r=>r.ref===i.ref),s=d?.blob;if(s===void 0)return!1;let g=e.mediaOf(t).images??[];if(g.some(r=>r.blob===s))return!0;let l=d?.appearance;return l!==void 0&&g.filter(r=>r.appearance===l).length===1}var K=128*1024,X=64*1024;function oe(e,n){let t=e.split(`
8
+ `),i=n.split(`
9
+ `),o=0;for(;o<t.length&&o<i.length&&t[o]===i[o];)o++;let d=t.length,s=i.length;for(;d>o&&s>o&&t[d-1]===i[s-1];)d--,s--;if(d===o&&s===o)return"";let g=t.slice(o,d),l=i.slice(o,s),f=ie(g,l,2e3),m=[];if(f===null)m.push(`@@ old L${o+1}-L${d} \u2192 new L${o+1}-L${s} @@`,...g.map(p=>`- ${p}`),...l.map(p=>`+ ${p}`));else{let p=f.map((c,h)=>c.op==="="?-1:h).filter(c=>c>=0),u=0;for(;u<p.length;){let c=u;for(;c+1<p.length&&p[c+1]-p[c]<=3;)c++;let h=Math.max(p[u]-1,0),E=Math.min(p[c]+1,f.length-1),v=f.slice(h,E+1),S=o+(v[0].ai??0)+1,w=o+(v[0].bi??0)+1,a=v.filter(R=>R.op!=="+").length,_=v.filter(R=>R.op!=="-").length;m.push(`@@ old L${S}-L${S+Math.max(a-1,0)} \u2192 new L${w}-L${w+Math.max(_-1,0)} @@`);for(let R of v)m.push(R.op==="="?` ${R.line}`:`${R.op} ${R.line}`);u=c+1}}return m.join(`
10
+ `)}function ie(e,n,t){let i=e.length,o=n.length,d=Math.min(i+o,t),s=new Map([[1,0]]),g=[],l=!1;for(let p=0;p<=d&&!l;p++){g.push(new Map(s));for(let u=-p;u<=p;u+=2){let c=u===-p||u!==p&&(s.get(u-1)??0)<(s.get(u+1)??0)?s.get(u+1)??0:(s.get(u-1)??0)+1,h=c-u;for(;c<i&&h<o&&e[c]===n[h];)c++,h++;if(s.set(u,c),c>=i&&h>=o){l=!0;break}}}if(!l)return null;let r=i,f=o,m=[];for(let p=g.length-1;p>0;p--){let u=g[p],c=r-f,h=c===-p||c!==p&&(u.get(c-1)??0)<(u.get(c+1)??0)?c+1:c-1,E=u.get(h)??0,v=E-h;for(;r>E&&f>v;)m.push({op:"=",line:e[r-1],ai:r-1,bi:f-1}),r--,f--;p>0&&(r===E?(m.push({op:"+",line:n[f-1],ai:r,bi:f-1}),f--):(m.push({op:"-",line:e[r-1],ai:r-1,bi:f}),r--))}for(;r>0&&f>0;)m.push({op:"=",line:e[r-1],ai:r-1,bi:f-1}),r--,f--;for(;r>0;)m.push({op:"-",line:e[r-1],ai:r-1,bi:0}),r--;for(;f>0;)m.push({op:"+",line:n[f-1],ai:0,bi:f-1}),f--;return m.reverse()}function ce(e){let n=Buffer.byteLength(e,"utf8");if(n<=K+X)return{diff:e,truncated:!1};let t=Buffer.from(e,"utf8"),i=K;for(;i>0&&(t[i]&192)===128;)i--;let o=n-X;for(;o<n&&(t[o]&192)===128;)o++;let d=t.subarray(0,i).toString("utf8"),s=t.subarray(o).toString("utf8");return{diff:`${d}
11
+ \u2026 [diff truncated: ${n-i-(n-o)} bytes omitted] \u2026
12
+ ${s}`,truncated:!0}}function ae(e,n){let t=x(e),i=t.heads.get(n);if(typeof i!="string")return null;let o=[];for(let u of V(e).records){let c=u.source_head_moves?.[n];c!==void 0&&c!==o[o.length-1]&&o.push(c)}let d=o.lastIndexOf(i),s=d>0?o[d-1]:null;if(typeof s!="string"||s===i)return null;let g=L(e,t,s),l=L(e,t,i);if(g===null||l===null)return null;let{diff:r,truncated:f}=ce(oe(g,l)),m=new Set,p=[];for(let u of t.edgesFrom(s))u.type!==$.DERIVES||t.nodeLabel.get(u.dst)!==b.USECASE||m.has(u.dst)||(m.add(u.dst),p.push({id:u.dst,title:String(t.getNode(u.dst)?.content.title??"")}));return{source_id:n,old_head:s,new_head:i,diff:r,...f?{truncated:!0}:{},prior_ucs:p}}function de(e,n,t){let i=e.getNode(n)?.content??{},o=e.getNode(t)?.content??{},s=[...new Set([...Object.keys(i),...Object.keys(o)])].sort().filter(g=>JSON.stringify(i[g])!==JSON.stringify(o[g]));return s.length>0?`updated: ${s.join(", ")}`:"updated"}function le(e,n,t,i,o,d,s){let g=new Set((s?.rows??[]).map(c=>c.matched_cid).filter(c=>!!c)),l=[];for(let[c,h]of t.superseded)h===null||c===h||n.superseded.has(c)||t.nodeLabel.get(c)===b.USECASE&&l.push({kind:"MODIFY",ref:y(t,c),old_cid:c,new_cid:h,summary:de(t,c,h)});let r=d.map(c=>({kind:"ADD",ref:y(t,c),cid:c}));for(let c of s?.rows??[])c.kind==="MODIFY"&&c.matched_cid?l.push({kind:"MODIFY",ref:y(t,c.matched_cid),old_cid:c.matched_cid,new_cid:null,summary:`${c.why} (staged)`}):c.kind==="ADD"&&r.push({kind:"ADD",ref:c.title,cid:null});let f=[],m=L(e,t,o),p=new Map;for(let{cid:c}of t.byLabel(b.USECASE)){if(!T(t,c)||g.has(c))continue;let h=t.derivesInto(c),E=h.filter(w=>String(w.props.source_id)===i);E.length===0||E.some(w=>w.props.source_cid===o)||E.some(w=>{let a=String(w.props.anchor),_=D(a);return _?.kind==="img-whole"?!1:_?.kind==="img-part"?se(t,w,o):m!==null&&re(e,t,w,m,p)})||h.some(w=>{let a=String(w.props.source_id);if(a===i)return!1;let _=t.heads.get(a);return _!=null})||f.push({kind:"ARCHIVE",ref:y(t,c),cid:c,why:`evidence decayed: no quote from ${i} relocates into @${C(o)}, no other live source, no fresh evidence this run`,impact:J(t,t.tipOf(c))})}let u=(c,h)=>c.ref<h.ref?-1:c.ref>h.ref?1:0;return[...l.sort(u),...r.sort(u),...f.sort(u)]}function Ee(e,n,t,i,o){let d=n.rows.find(u=>u.temp_ref===t);if(!d)return{ok:!1,message:`held item ${t} missing from the plan artifact`};let s=d,g=x(e);if(s.matched_cid){let u=g.tipOf(s.matched_cid);if(g.superseded.get(u)===null)return{ok:!1,message:`use-case for "${s.title}" was retired meanwhile \u2014 nothing to update`};u!==s.matched_cid&&(s={...s,matched_cid:u,uc:{...s.uc,matches_existing:{cid:u}}})}let l=o?{edited:o}:"approve",r=W(e,g,{source_id:n.source_id,...n.staged_source_cid!==void 0?{staged_source_cid:n.staged_source_cid}:{},rows:[s]},new Map([[s.temp_ref,l]]),i);if(r.errors)return{ok:!1,message:r.errors.map(u=>`${u.code}: ${u.detail}`).join("; ")};let f=x(e),m=s.matched_cid?f.tipOf(s.matched_cid):r.record?.nodes.find(u=>u.label==="usecase")?.cid??r.record?.review[0]?.id;return{ok:!0,ref:m?y(f,m):s.title,kind:s.kind}}async function ve(e,n,t,i={}){let o=x(e),d=o.heads.get(n)??null,s=new Set(o.staleList().filter(a=>a.state==="stale").map(a=>a.cid)),g=await t.reingest(n);if(g.status==="unchanged"&&!i.resumeHeld)return{source_id:n,changed:!1,head:{status:g.status,before:d,after:g.cid},note:`nothing to reconcile \u2014 ${n} is unchanged`,skipped_arms:B,changeset:[],rows:[]};let l=i.resumeHeld?{minted:[],matched:[],held:i.resumeHeld}:await t.reextract(n),r=x(e),f=l.minted.map(a=>{let _=y(r,a);return{kind:"ADD",origin:"content-change",ref:_,reason:`new use-case extracted from ${n}`,provenance:`extraction commit \u2014 DERIVES ${n} @ ${C(g.cid)}`,action:`kane-cli design tests --use-case ${_}`}}),m=r.staleList().filter(a=>a.state==="stale"&&!s.has(a.cid)&&T(r,a.cid)).map(a=>a.cid),p=m.map(a=>{let _=y(r,a),R=ne.has(r.nodeLabel.get(a)??"");return{kind:"MODIFY",origin:"structural-stale",ref:_,reason:"stale (structural)",provenance:q(r,a),action:R?`kane-cli maintain evolve ${_}`:`kane-cli design explain ${_}`}}),u=[],c=[];for(let a of l.held?.rows??[])if(a.kind==="ADD")u.push({kind:"ADD",origin:"content-change",ref:a.title,held_ref:a.temp_ref,reason:`${a.why} (staged \u2014 commits on approval)`,provenance:`staged extraction of ${n} @ ${C(g.cid)}`,action:"approve to commit + design"});else{let _=a.matched_cid?r.tipOf(a.matched_cid):null,R=_?r.getNode(_)?.content.criteria??[]:[],I=(a.uc.updated?.criteria??[]).map(k=>typeof k=="string"?k:k.text),Q=[...I.filter(k=>!R.includes(k)),...a.uc.updated?.criteria!==void 0?R.filter(k=>!I.includes(k)):[]],H=_?J(r,_,Q):void 0;c.push({kind:"MODIFY",origin:"content-change",ref:a.matched_cid?y(r,a.matched_cid):a.title,held_ref:a.temp_ref,reason:`${a.why} (staged \u2014 commits on approval)`,provenance:`staged extraction of ${n} @ ${C(g.cid)}`,action:"approve to commit the updated version (old\u2192new redirect)",...H?{impact:H}:{}})}let h=new Set;for(let a of[...l.minted,...l.matched])h.add(r.tipOf(a));for(let a of l.held?.rows??[])a.matched_cid&&h.add(r.tipOf(a.matched_cid));for(let a of m){let _=Y(r,r.tipOf(a));_&&r.nodeLabel.get(_)===b.USECASE&&h.add(r.tipOf(_))}let E=[];for(let a of await F(r,"design")){if(a.kind!=="no-verifies")continue;let _=r.resolve(a.ref);if(!_)continue;let R=Y(r,_.tip);!R||!h.has(r.tipOf(R))||E.push({kind:"ADD",origin:"content-change",ref:a.ref,reason:a.why,provenance:`gaps engine (design) \u2014 uncovered AC of touched use-case ${y(r,R)}`,action:a.ready_command})}let v=[];for(let{cid:a}of r.byLabel(b.USECASE))T(r,a)&&r.stale(a)==="orphaned"&&v.push({kind:"REMOVE",ref:y(r,a),reason:"orphaned \u2014 no live source evidences this use-case",provenance:q(r,a),action:"plan-only \u2014 REMOVE is not executed in this release"});let S=new Set,w=[...f.sort(O),...u.sort(O),...E.sort(O),...c.sort(O),...p.sort(O),...v.sort(O)].filter(a=>{let _=`${a.kind}\0${a.ref}`;return S.has(_)?!1:(S.add(_),!0)});return{source_id:n,changed:!0,head:{status:g.status,before:d,after:g.cid},note:te,skipped_arms:B,changeset:le(e,o,r,n,g.cid,l.minted,l.held),rows:w,...l.held?{held:l.held}:{}}}function be(e,n){return async t=>{let{ingestFile:i}=await import("./ingest-UAIKHOB4.js"),{convertPdf:o}=await import("./pdf-convert-S7VYE6AV.js"),{convertDocx:d}=await import("./docx-convert-IAX54REO.js"),s=await i({contextDir:e,filePath:n,asId:t,converters:{pdf:o,docx:d}});return{status:s.status,cid:s.cid}}}function Re(e,n={}){return async t=>{let i=[],[{runExtract:o},{resolveAgentAuthEnv:d},{runAgent:s},{preflightTurn:g}]=await Promise.all([import("./run-FYJZCWYS.js"),import("./spawner-6FHAXNOA.js"),import("./bridge-WMGH3O3B.js"),import("./turn-preflight-JGYT7LXP.js")]),l=await d(),r=new Set(x(e).byLabel(b.USECASE).map(S=>S.cid)),f=ae(e,t)??void 0,m=0,p=await o({mode:"override",...f?{changeContext:f}:{}},{contextDir:e,agent:s,preflightTurn:()=>g(l),ask:async()=>[],review:async S=>{if(!n.stage)return new Map(S.map(a=>[a.temp_ref,{resolution:a.matches_existing&&a.changed?"edited":"skipped"}]));let w=new Map;for(let a of S){if(a.matches_existing&&!a.changed){w.set(a.temp_ref,{resolution:"skipped"});continue}i.push({kind:a.matches_existing?"MODIFY":"ADD",temp_ref:a.temp_ref,title:a.title,why:a.matches_existing?`updated: ${Object.keys(a.updated??{}).join(", ")||"content"}`:`newly extracted from ${t}`,...a.matches_existing?{matched_cid:a.matches_existing.cid,updated:a.updated}:{},uc:a}),w.set(a.temp_ref,{resolution:"rejected"})}return w},confirmStale:async()=>!1,out:S=>process.stderr.write(S+`
13
+ `),progress:S=>process.stderr.write(S+`
14
+ `),emit:S=>{S.type==="commit"&&typeof S.assumed=="number"&&(m+=S.assumed)},isTTY:!1,auth:l});if(p!==0)throw new Error(`reconcile: re-extract of ${t} failed (exit ${p})`);let u=x(e),c=u.heads.get(t),h=[],E=[];if(typeof c=="string"){let S=new Set;for(let w of u.edgesFrom(c))w.type!==$.DERIVES||u.nodeLabel.get(w.dst)!==b.USECASE||S.has(w.dst)||(S.add(w.dst),!(n.stage&&u.trust.get(w.dst)==="archived")&&(r.has(w.dst)?E:h).push(w.dst))}let v=x(e).heads.get(t);return{minted:h,matched:E,defaultsTaken:m,...n.stage?{held:{source_id:t,...v!=null?{staged_source_cid:v}:{},rows:i}}:{}}}}export{Ee as a,ve as b,be as c,Re as d};
@@ -0,0 +1,12 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import{f as He}from"./chunk-K7USHLVZ.js";import{a as he,e as Be,g as je,h as We}from"./chunk-ZFFRHV5U.js";import{a as Te,b as Ne}from"./chunk-JFAFKHDX.js";import{a as Ge,b as qe,c as Le}from"./chunk-J44RN3FB.js";import{a as Me}from"./chunk-GG43HSU2.js";import{c as Ie}from"./chunk-OSALXGD4.js";import{b as Pe}from"./chunk-JHHMXU76.js";import{a as se,b as Ae}from"./chunk-DNNZ353O.js";import{b as Fe}from"./chunk-YKTYVJBN.js";import{a as Ue}from"./chunk-CVOGP253.js";import{b as Oe}from"./chunk-FHKDTM5L.js";import{a as V}from"./chunk-NVGBE2DR.js";import{a as R}from"./chunk-SDRFTIRU.js";import{e as z,f as re}from"./chunk-A46NBRAP.js";import{b as Ee}from"./chunk-IAHKTEET.js";import{d as j}from"./chunk-5YPBPZUR.js";import{a as Re}from"./chunk-5EOX4MEY.js";import{appendFileSync as ot,mkdirSync as pe,writeFileSync as _e}from"fs";import{dirname as nt,extname as at,join as U}from"path";var E=class extends Error{code;constructor(e,c){super(`${e}: ${c}`),this.name="ProposalAdapterError",this.code=e}};function ze(s){return s.version===2}function Ve(s,e){if(s.read_basis.length!==1)throw new E("READ_BASIS_COUNT",`read_basis must have exactly 1 element, got ${s.read_basis.length}`);let c=s.read_basis[0],u=s.use_cases.map(i=>{if(i.cite.length!==1)throw new E("CITE_COUNT",`${i.temp_ref}: cite must have exactly 1 element, got ${i.cite.length}`);let g=i.cite[0];if(g.source_id!==c.source_id)throw new E("SOURCE_MISMATCH",`${i.temp_ref}: cite source ${g.source_id} != read_basis source ${c.source_id} (single-source)`);return{temp_ref:i.temp_ref,title:i.title,...i.description!==void 0?{description:i.description}:{},...i.summary!==void 0?{summary:i.summary}:{},...i.actors!==void 0?{actors:i.actors}:{},...i.value!==void 0?{value:i.value}:{},risk:i.risk,cite:{anchor:g.anchor,quote:g.quote},...i.criteria!=null&&i.criteria.length>0?{criteria:i.criteria.map((d,_)=>{if(d.cite.source_id!==c.source_id)throw new E("SOURCE_MISMATCH",`${i.temp_ref}.criteria[${_}]: cite source ${d.cite.source_id} != read_basis source ${c.source_id} (single-source)`);return{text:d.text,cite:{anchor:d.cite.anchor,quote:d.cite.quote}}})}:{},depends_on_hint:i.depends_on_hint,matches_existing:i.matches_existing,...i.conflicts_with!=null?{conflicts_with:i.conflicts_with}:{},...i.changed?{changed:!0}:{},...i.updated!=null?{updated:{...i.updated.title!=null?{title:i.updated.title}:{},...i.updated.description!=null?{description:i.updated.description}:{},...i.updated.summary!=null?{summary:i.updated.summary}:{},...i.updated.actors!=null?{actors:i.updated.actors}:{},...i.updated.value!=null?{value:i.updated.value}:{},...i.updated.risk!=null?{risk:i.updated.risk}:{},...i.updated.criteria!=null?{criteria:i.updated.criteria.map((d,_)=>{if(d.cite.source_id!==c.source_id)throw new E("SOURCE_MISMATCH",`${i.temp_ref}.updated.criteria[${_}]: cite source ${d.cite.source_id} != read_basis source ${c.source_id} (single-source)`);return{text:d.text,cite:{anchor:d.cite.anchor,quote:d.cite.quote}}})}:{}}}:{},...i.change_note!=null?{change_note:i.change_note}:{}}});return{version:1,read_basis:e,source:{source_id:c.source_id,source_cid:c.source_cid},use_cases:u}}function Je(s){let{contextDir:e,graph:c}=s,u=s.maxDigestBytes??4096,i={},g=[];for(let[l,f]of c.heads){if(i[l]=f,typeof f!="string")continue;let x=c.mediaOf(f),k=c.getNode(f)?.content?.blob;if(typeof k=="string")if(x.format==="image")g.push({source_id:l,cid:f,format:"image",blobRef:{path:V(e,k),cid:k}});else{let n=se(e,c,f)?.toString("utf8")??"";g.push({source_id:l,cid:f,format:x.format,text:n})}}g.sort((l,f)=>l.source_id<f.source_id?-1:1);let d=[];for(let l of c.byLabel(j.STYLENOTE).sort((f,x)=>f.cid<x.cid?-1:1))c.superseded.has(l.cid)||d.push(`\u2022 ${String(l.content.statement)} [${String(l.content.learned_from_kind)}]`);let _="";for(let l of d){if(Buffer.byteLength(_+l+`
3
+ `,"utf8")>u)break;_+=l+`
4
+ `}return{read_basis:i,sources:g,styleNoteDigest:_}}function Ke(s,e){let c=Je({contextDir:s,graph:e}).styleNoteDigest;return c.length>0?c:void 0}function ct(s,e){let c=(s.images??[]).filter(u=>u.delivery==="selected");if(c.length!==0)return c.map(u=>({ref:u.ref,...u.page!==void 0?{page:u.page}:{},...u.loc!==void 0?{loc:u.loc}:{},media_type:u.media_type,blob_ref:{path:V(e,u.blob),cid:u.blob}}))}function dt(s){return s.length>8&&s[0]===137&&s[1]===80&&s[2]===78&&s[3]===71?"image/png":s.length>3&&s[0]===255&&s[1]===216&&s[2]===255?"image/jpeg":s.length>12&&s.toString("ascii",0,4)==="RIFF"&&s.toString("ascii",8,12)==="WEBP"?"image/webp":null}function Xe(s){return s.toISOString().replace(/[-:]/g,"").slice(0,15)}function ut(s){return s.startsWith("su-conv-")?`conv-${Ee(Buffer.from(s,"utf8")).slice(0,8)}`:s}function et(s){return s.source_id.startsWith("su-conv-")?"the conversation":s.source_id}function lt(s,e,c){return`reading ${et(s)}${c>1?` (source ${e} of ${c})`:""}`}function J(s){return s.toLowerCase().trim().replace(/\s+/g," ")}function Ye(s,e){let c=new Map,u=new Map,i=new Map;for(let{cid:d,content:_}of e.byLabel(j.USECASE)){if(e.superseded.has(d))continue;(e.trust.get(d)==="archived"?i:u).set(J(String(_.title??"")),d)}let g=d=>e.trust.get(d)==="archived"?{cid:d,archived:!0,reason:e.archivedReason.get(d)}:{cid:d};for(let d of s.use_cases){if(d.matches_existing){let f=d.matches_existing.cid;if(e.superseded.has(f)){let x=e.tipOf(f);f=e.superseded.has(x)?null:x}if(f!==null){c.set(d.temp_ref,g(f));continue}}let _=u.get(J(d.title));if(_){c.set(d.temp_ref,{cid:_});continue}let l=i.get(J(d.title));l&&c.set(d.temp_ref,g(l))}return c}var Qe=/^(\S+)\.criteria\[(\d+)\]/;function mt(s,e,c){if(e.length===0||!e.every(i=>Qe.test(i.detail)))return!1;let u=new Map;for(let i of e){let g=Qe.exec(i.detail),d=u.get(g[1])??new Set;d.add(Number(g[2])),u.set(g[1],d)}for(let i of s.use_cases){let g=u.get(i.temp_ref);g?.size&&(i.criteria=(i.criteria??[]).filter((d,_)=>!g.has(_)),c(`${i.temp_ref}: dropped ${g.size} criteria with unverifiable cites \u2014 committed without them (criteria are hints, not oracles)`))}return!0}async function Ze(s,e,c,u,i=()=>{},g){let d=(_,l)=>i(_,l,s.session_id);return je(s,e,c,u,i,{async onProposalEvent(_){let l=_,f=null,x=null;if(ze(l))try{f=Ve(l,s.read_basis),d("adapter",{ok:!0,use_cases:f.use_cases.length})}catch(k){x=k instanceof E?k.message:String(k),d("adapter",{ok:!1,error:x})}else f=l;return f&&f.use_cases.length===0&&e.out("warning: the agent proposed ZERO use-cases for this source"),f&&g&&await g(f),{proposal:f,error:x}}})}var gt=new Set(["agent","ci","override"]);async function Jt(s,e){let c=s.mode??"interactive";if(c==="interactive"){if(!e.isTTY)return e.out("extract: --mode interactive needs a TTY (use --mode agent|ci|override headless)"),2}else if(!gt.has(c))return e.out(`extract: unknown mode "${c}" \u2014 interactive | agent | ci | override`),2;let u=e.telemetry?.enabled?e.telemetry:void 0,i=Xe(e.now?.()??new Date),g=u?Re(u.ids.context_instance_id??null,"extract",u.ids.session_id):U(e.contextDir,"logs",`extract-${i}.log`);pe(nt(g),{recursive:!0});let d=`run-${i}-${Math.random().toString(36).slice(2,8)}`,_=t=>t==="error"||t==="failed_proposal"?"error":t==="repair_respawn"?"warn":"info",l=(t,a,m)=>{try{ot(g,JSON.stringify({ts:new Date().toISOString(),level:_(t),run_id:d,...u?{user_session_id:u.ids.session_id}:{},...m?{session_id:m}:{},kind:t,data:a})+`
5
+ `)}catch{}u?.wireTrace(t,a,m)};e.out(`trace: ${he(g)}`),u&&e.out(u.banner()),e.emit?.({type:"run_start",mode:c,trace:g});let f=Fe();if(f&&e.out(f),e.preflightTurn){let t=await e.preflightTurn();if(l("preflight",t),!t.ok)return e.out(t.message??"error: turn-endpoint preflight failed"),e.emit?.({type:"error",message:t.message??"error: turn-endpoint preflight failed",code:"PREFLIGHT"}),2}let x=R(e.contextDir),k=Ke(e.contextDir,x);if(s.source){if(s.resume){let a="error: --source cannot be combined with --resume (the resumed session already has its scope)";return e.out(a),e.emit?.({type:"error",message:a,code:"SOURCE_WITH_RESUME"}),2}let t=x.heads.get(s.source);if(typeof t!="string"){let a=t===null?`error: --source ${s.source} was ingested but is retired \u2014 re-ingest it to extract again`:`error: --source ${s.source} is not an ingested source (kane-cli context list shows them)`;return e.out(a),e.emit?.({type:"error",message:a,code:"SOURCE_UNKNOWN"}),2}}let n=null;if(s.resume){try{n=Le(e.contextDir,s.resume,x)}catch(m){return e.out(`error: ${m instanceof Error?m.message:String(m)}`),e.emit?.({type:"error",message:`error: ${m instanceof Error?m.message:String(m)}`}),1}let t=n.handle.state.change_basis;if(t&&(x.heads.get(t.source_id)??null)!==t.new_head){let m=`error: ${t.source_id} moved while this reconcile extraction was paused \u2014 its recorded change context no longer matches; re-run kane-cli maintain reconcile against the current file (session ${s.resume} is defunct and can be ignored)`;return e.out(m),e.emit?.({type:"error",message:m,code:"CHANGE_BASIS_MOVED"}),n.handle.release(),2}n.staleBasis.length>0&&e.out(`note: changed since the pause: ${n.staleBasis.join(", ")} \u2014 re-presented items may be stale`);let a=n.handle.state.held_receipts??[];if(a.length>0)if(e.chat?.holdReceipt)for(let m of a)e.chat.holdReceipt(m);else e={...e,initialMessage:[a.join(`
6
+
7
+ `),e.initialMessage].filter(Boolean).join(`
8
+
9
+ `)};n.handle.state.assumed.length>0&&e.out(`note: ${n.handle.state.assumed.length} default(s) were assumed while you were away \u2014 kane-cli context sessions show ${s.resume} lists them`)}let xe=x.extractedSourceCids,K=!!(s.force||n?.handle.state.force),y=[],P=[];for(let[t,a]of x.heads.entries())if(a!=null&&!(s.source&&t!==s.source)){if(!s.source&&!n&&t.startsWith("su-conv-")){e.out(`skipped: ${t} \u2014 conversation source (extract it explicitly with --source ${t})`),P.push({source_id:t,reason:"conversation"});continue}if(n){let m=t in n.handle.state.read_basis,I=n.handle.state.corpus_cursor.remaining.includes(t);if(!m&&!I)continue;if(I&&!K&&xe.has(a)){e.out(`cached: ${t} @ ${a.slice(0,19)} already extracted \u2014 skipping`),P.push({source_id:t,reason:"cached"});continue}}else if(!K&&xe.has(a)){e.out(`cached: ${t} @ ${a.slice(0,19)} already extracted \u2014 skipping`),P.push({source_id:t,reason:"cached"});continue}y.push({source_id:t,cid:a})}let tt=t=>{let a=He(e.contextDir,t);a&&e.out(`note: a reconcile plan for ${t} is pending (${a.pending} item(s)) \u2014 resume with \`kane-cli maintain reconcile --apply ${a.path}\``)};for(let t of P)t.reason==="cached"&&tt(t.source_id);if(e.emit?.({type:"corpus",sources:y,skipped:P}),y.length===0){if(n){let m=`error: resumed session's paused source (${Object.keys(n.handle.state.read_basis).join(", ")||"unknown"}) is no longer in the corpus \u2014 restore/re-ingest it and re-run --resume ${s.resume}, or discard with: kane-cli context sessions clean ${s.resume}`;return e.out(m),e.emit?.({type:"error",message:m,code:"SOURCE_MISSING"}),n.handle.release(),2}let t=P.length>0&&P.every(a=>a.reason==="conversation");return e.out(s.source?`extract: nothing to do \u2014 ${s.source} is already extracted at its current snapshot (--force to re-run)`:t?"extract: nothing to do \u2014 only conversation sources here (extract one explicitly with --source <id>)":"extract: nothing to do \u2014 every ingested source is already extracted"),0}let X=new Map;if(n&&n.questions.length>0&&!s.message){e.out(`re-presenting ${n.questions.length} unanswered question(s) from the paused session`);let t=await e.ask(n.questions.map(Ge));for(let a of t)X.set(a.id,a)}let H=e.by??{kind:"human",id:"owner"},A=c==="interactive"&&!s.plan&&!!e.chat,ie=0,ye=0;try{for(let t of y){let a=R(e.contextDir),m={current:a};e.chat?.attachOnCommitted?.(r=>{m.current=r});let I=a.getNode(t.cid),Y=String(I?.content.blob??""),oe=se(e.contextDir,a,t.cid);if(!oe)return e.out(`error: ${t.source_id}: blob ${Y} missing from .context/blobs`),e.emit?.({type:"error",source_id:t.source_id,message:`error: ${t.source_id}: blob ${Y} missing from .context/blobs`,code:"BLOB_MISSING"}),1;let G=a.mediaOf(t.cid),ne=G.media_type.startsWith("image/");if(!ne){let r=dt(oe);if(r){e.out(`skipping ${t.source_id}: binary ${r} ingested before image support \u2014 re-ingest it (kane-cli context ingest) to extract from it`),e.emit?.({type:"source_skipped",source_id:t.source_id,reason:"binary_pre_media"});continue}}let q=ne?`0001| (image source ${t.source_id} \u2014 the content is attached as an image; cite it with anchor img#whole)`:Ae(oe),ve=Xe(e.now?.()??new Date),M=`${ve}-${t.source_id}`,be=!!(n&&t.source_id in n.handle.state.read_basis)?s.resume:`ext-${ve}-${ut(t.source_id)}`,T="";if(A){let r=Ie({contextDir:e.contextDir,graph:R(e.contextDir),sessionStamp:be,by:H});r.errors===null||r.errors[0]?.code==="CONV_SOURCE_EXISTS"?(T=r.sourceId,e.chat.attachConversationSource?.(T),m.current=R(e.contextDir)):e.out(`warning: conversation source unavailable (${r.errors[0]?.detail}) \u2014 chat adds will not land this session`)}let $={type:"run_config",version:1,session_id:be,mode:c,source:{source_id:t.source_id,source_cid:t.cid,kind:Pe.has(G.format)?G.format:at(t.source_id)||"md",numbered_text:q,...(()=>{let r=ct(G,e.contextDir);return r?{images:r}:{}})()},existing_use_cases:a.byLabel(j.USECASE).filter(({cid:r})=>a.trust.get(r)!=="archived"&&!a.superseded.has(r)).map(({cid:r,content:o})=>({id:r,title:String(o.title??""),summary:String(o.summary??"")})),read_basis:m.current.latestHash,max_free_text_rounds:Be,graph_reads:!0,verb:"extract",...k!==void 0?{style_note_digest:k}:{},...s.changeContext&&s.changeContext.source_id===t.source_id?{change_context:s.changeContext}:{},topology:Ue(),...A?{chat:!0}:{},...ne?{image_sources:[{source_id:t.source_id,source_cid:t.cid,media_type:G.media_type,blob_ref:{path:V(e.contextDir,Y),cid:Y}}]}:{},...n&&t.source_id in n.handle.state.read_basis?{resume:{agent_state:n.handle.state.agent_state}}:{}};A||e.out(n&&t.source_id in n.handle.state.read_basis?`resuming: ${t.source_id} (session ${s.resume})`:`extracting: ${t.source_id} @ ${t.cid.slice(0,19)}`),e.emit?.({type:"source_start",source_id:t.source_id,cid:t.cid,index:y.indexOf(t)+1,total:y.length,resumed:!!(n&&t.source_id in n.handle.state.read_basis)}),e.chat?.ledger?.({kind:"banner",text:lt(t,y.indexOf(t)+1,y.length)}),e.chat?.setWorking?.(`Reading ${et(t)}\u2026`);let $e=new Map;l("spawn",{source_id:t.source_id,source_cid:t.cid,resume:!!n,chat:A},$.session_id);let Se=!1,rt=async r=>{let o=z(r,q,R(e.contextDir));if(l("kane_validate",{errors:o.map(p=>p.code)},$.session_id),o.length>0){e.chat.submit("[auto-repair] the proposal failed validation: "+o.map(p=>`${p.code}: ${p.detail}`).join("; ")+" \u2014 please re-finalize with these fixed.");return}let v=R(e.contextDir),C=Ye(r,v),ee=U(e.contextDir,"proposals",M);pe(ee,{recursive:!0}),_e(U(ee,"proposal.json"),JSON.stringify(r,null,2)+`
10
+ `);let it=new Map(r.use_cases.map(p=>[p.temp_ref,{resolution:"skipped"}])),te=re({contextDir:e.contextDir,graph:v,proposal:r,proposalId:M,verdicts:it,by:{kind:"ai",id:"extract-agent"},autoName:!0});if(te.errors){e.chat.ledger?.({kind:"commit",ok:!1,line:"commit failed \u2014 nothing landed",warnings:te.errors.map(p=>`${p.code}: ${p.detail}`)});return}Se=!0;let F=te.record.nodes.length;ie+=F;let B=r.use_cases.length-F;{let p=R(e.contextDir),De=new Map;for(let{cid:b,content:D}of p.byLabel(j.USECASE))p.superseded.has(b)||De.set(J(String(D.title??"")),b);let fe=[];for(let b of r.use_cases){let D=null;if(b.matches_existing?.cid&&p.hasNode(b.matches_existing.cid)){let W=p.tipOf(b.matches_existing.cid);D=p.superseded.has(W)?null:W}D=D??De.get(J(b.title))??null,D&&fe.push({ref:b.temp_ref,cid:D,...p.displayNameOf(D)?{id:p.displayNameOf(D)}:{}})}fe.length>0&&e.chat.registerAliases?.(fe),m.current=p;let ke=b=>{for(let[D,W]of p.names)if(W===b&&!p.superseded.has(W))return D},Ce=Me({verb:"extract",commitN:1,phase:"proposal",committed:te.record.nodes.map(b=>({cid:b.cid,...ke(b.cid)?{logical_id:ke(b.cid)}:{}})),reused:B},p);e.emit?.(Ce.event),e.chat.holdReceipt?.(Ce.text)}l("commit",{derived:F,evidence_matched:B,chat:!0},$.session_id),e.chat.ledger?.({kind:"commit",ok:!0,line:F===0&&B>0?`all ${B} matched existing \u2014 nothing new to save`:`saved ${F} use-case${F===1?"":"s"} as drafts`+(B>0?` \xB7 ${B} matched existing`:"")})},we=!!(n&&t.source_id in n.handle.state.read_basis),Q=we&&X.size>0?{...e,ask:async r=>r.every(o=>X.has(o.id))?(n.handle.markApplied(r.map(o=>`resolveq:${s.resume}:${o.id}`)),e.out(`answered ${r.length} re-asked question(s) from the held resume answers`),r.map(o=>X.get(o.id))):e.ask(r)}:e;we&&s.message&&(Q={...Q,initialMessage:s.message});let h=await Ze($,{...Q,graphSlot:m},$e,a,l,A?rt:void 0);if(e.chat?.setWorking?.(null),h.error)return e.out(`error: agent failed for ${t.source_id}: ${h.error}`),e.emit?.({type:"error",source_id:t.source_id,message:`error: agent failed for ${t.source_id}: ${h.error}`}),1;if(h.highRisk)return e.out(`error: ${h.highRisk.length} high-risk decision${h.highRisk.length===1?"":"s"} need a human \u2014 ci mode won't guess. Re-run with --mode agent to pause for review.`),e.emit?.({type:"error",source_id:t.source_id,message:`error: high-risk question(s) in ci mode (fail-closed): ${h.highRisk.map(r=>r.id).join(", ")}`,code:"HIGH_RISK_CI"}),1;if(h.paused){let r=y.slice(y.indexOf(t)+1).map(ee=>ee.source_id),o=n?.handle??Oe(e.contextDir,{sid:$.session_id,mode:"agent",created_at:(e.now?.()??new Date).toISOString(),expires_at:new Date((e.now?.()??new Date).getTime()+1440*60*1e3).toISOString(),agent_state:h.paused.agent_state,pending:{questions:[],proposals:[]},assumed:[],read_basis:{[t.source_id]:t.cid},corpus_cursor:{remaining:r},conv_source:T,verb:"extract",...K?{force:!0}:{},...s.changeContext?{change_basis:{source_id:s.changeContext.source_id,new_head:s.changeContext.new_head}}:{},...u?{user_session_id:u.ids.session_id}:{}});T&&o.state.conv_source!==T&&o.save({conv_source:T});let v=e.chat?.drainHeldReceipts?.()??[];(v.length>0||(o.state.held_receipts?.length??0)>0)&&o.save({held_receipts:v}),n?.handle&&o.save({read_basis:{[t.source_id]:t.cid},corpus_cursor:{remaining:r},...K&&!o.state.force?{force:!0}:{},...u&&o.state.user_session_id!==u.ids.session_id?{user_session_id:u.ids.session_id}:{}}),qe(o,h.paused),l("session_paused",{sid:o.state.sid},$.session_id);let C=`kane-cli context extract --resume ${o.state.sid} --mode ${c}`;return e.out(`paused: session ${o.state.sid} saved \u2014 resume with: ${C}`),e.emit?.({type:"session_paused",sid:o.state.sid,source_id:t.source_id,mode:c,resume:C,expires_at:o.state.expires_at,pending_questions:h.paused.pending.questions}),e.chat?.ledger?.({kind:"pause",sid:o.state.sid,expires_at:o.state.expires_at,resume:C,messageForm:`${C} --message "<your words>"`}),3}if(A){if(ye+=h.assumedDefaults??0,h.error)return 1;if(!Se){let r=y.length-y.indexOf(t)-1;return e.out(`done \u2014 nothing committed for ${t.source_id} (no finalize before the session ended)`+(r>0?`; stopping here \u2014 ${r} remaining source(s) not extracted (re-run kane-cli context extract to continue)`:"")),n&&t.source_id in n.handle.state.read_basis&&(n.handle.complete(),n=null),0}n&&t.source_id in n.handle.state.read_basis&&(n.handle.complete(),n=null);continue}if(!h.proposal)return e.out(`error: agent ended without a proposal for ${t.source_id}`),e.emit?.({type:"error",source_id:t.source_id,message:`error: agent ended without a proposal for ${t.source_id}`}),1;let w=z(h.proposal,q,a);if(l("kane_validate",{errors:w.map(r=>r.code)},$.session_id),w.length>0&&mt(h.proposal,w,r=>e.out(r))&&(l("criteria_dropped",{source_id:t.source_id},$.session_id),w=z(h.proposal,q,a)),w.length>0){if(e.out("the agent's proposal didn't validate \u2014 retrying once"),e.emit?.({type:"validate_failed",source_id:t.source_id,codes:w.map(r=>r.code),repairing:!0}),l("repair_respawn",{source_id:t.source_id},$.session_id),h=await Ze($,{...Q,graphSlot:m},$e,a,l),h.error||!h.proposal)return e.out(`error: repair run failed for ${t.source_id}`),e.emit?.({type:"error",source_id:t.source_id,message:`error: repair run failed for ${t.source_id}`}),1;if(w=z(h.proposal,q,a),w.length>0){for(let r of w)e.out(` ${r.detail}`);return e.emit?.({type:"validate_failed",source_id:t.source_id,codes:w.map(r=>r.code),repairing:!1}),e.emit?.({type:"error",source_id:t.source_id,message:`error: proposal failed validation after repair (${w.map(r=>r.code).join(", ")})`}),1}}let S=h.proposal,Z=Ye(S,a),ae=U(e.contextDir,"proposals",M);if(pe(ae,{recursive:!0}),_e(U(ae,"proposal.json"),JSON.stringify(S,null,2)+`
11
+ `),s.plan){e.out(`plan: ${S.use_cases.length} use-case(s) proposed from ${t.source_id} (nothing committed)`);for(let r of S.use_cases){let o=Z.get(r.temp_ref),v=o?o.archived?` \u2248 matches ARCHIVED ${o.cid.slice(0,19)}${o.reason?` \u2014 previously rejected: "${o.reason}"`:" \u2014 previously rejected"}`:` \u2248 matches ${o.cid.slice(0,19)}`:"";e.out(` [${r.risk}] ${r.title} \u2014 cite ${r.cite.anchor}${v}`)}e.emit?.({type:"plan",source_id:t.source_id,use_cases:S.use_cases.map(r=>{let o=Z.get(r.temp_ref);return{risk:r.risk,title:r.title,anchor:r.cite.anchor,...o?{match:o.cid,match_archived:!!o.archived}:{}}})}),h.assumedDefaults&&e.out(`assumed: ${h.assumedDefaults} default(s) auto-taken (flagged)`);continue}for(let r of S.use_cases){if(!r.conflicts_with?.length)continue;let o=r.conflicts_with.filter(C=>a.resolve(C)!==null),v=r.conflicts_with.filter(C=>a.resolve(C)===null);v.length>0&&(e.out(`note: ${r.temp_ref}: dropped unresolvable conflict hint(s): ${v.join(", ")}`),r.conflicts_with=o.length>0?o:void 0)}l("review_start",{use_cases:S.use_cases.length,flags:Z.size},$.session_id);let L=await e.review(S.use_cases,Z);l("review_verdicts",[...L.entries()].map(([r,o])=>({ref:r,resolution:o.resolution})),$.session_id),_e(U(ae,"review.json"),JSON.stringify(S.use_cases.map(r=>{let o=L.get(r.temp_ref)??{resolution:"skipped"};return{id:r.temp_ref,kind:"review-item",resolution:o.resolution,edit:o.edit??null,reason:o.reason??null,...o.supersedeTarget?{supersede_target:o.supersedeTarget}:{},by:H}}),null,2)+`
12
+ `);let ce=a,O=re({contextDir:e.contextDir,graph:ce,proposal:S,proposalId:M,verdicts:L,by:H,autoName:!0});if(O.errors&&O.errors[0]?.code==="STALE_BASIS"){if(!await e.confirmStale(`the context changed while you reviewed (${O.errors[0].detail}) \u2014 commit against the new head anyway?`))return e.out("aborted: proposal not committed"),e.emit?.({type:"error",source_id:t.source_id,message:"aborted: proposal not committed",code:"STALE_BASIS"}),e.emit?.({type:"done",status:"aborted",exit_code:1}),1;ce=R(e.contextDir),O=re({contextDir:e.contextDir,graph:ce,proposal:S,proposalId:M,verdicts:L,by:H,allowStaleBasis:!0,autoName:!0})}if(O.errors){for(let r of O.errors)e.out(` ${r.detail}`);return e.emit?.({type:"error",source_id:t.source_id,message:`error: commit failed: ${O.errors.map(r=>`${r.code}: ${r.detail}`).join("; ")}`}),1}let st=new Date().toISOString();for(let r of S.use_cases){let o=L.get(r.temp_ref)??{resolution:"skipped"};for(let v of Ne({ts:st,command:"context extract",id:r.temp_ref,by:H},o.resolution))Te(e.contextDir,v)}let N=O.record,de=new Map(N.review.map(r=>[r.id,r.resolution])),ue=[...de.values()].filter(r=>r==="approved"||r==="edited").length,le=[...de.values()].filter(r=>r==="rejected").length,me=N.nodes.filter(r=>!de.has(r.cid)).length,ge=N.supersessions.filter(r=>r.kind==="node"&&r.new!==r.old).length;l("commit",{trusted:ue,derived:me,archived:le},$.session_id),e.out(`committed: ${ue} trusted, ${me} derived (queued), ${le} archived`+(ge>0?`, ${ge} superseded`:"")),h.assumedDefaults&&e.out(`assumed: ${h.assumedDefaults} default(s) auto-taken (flagged)`),e.emit?.({type:"commit",source_id:t.source_id,proposal_id:M,trusted:ue,derived:me,archived:le,superseded:ge,assumed:h.assumedDefaults??0,evidence_matched:Math.max(0,S.use_cases.length-N.nodes.length),minted:N.nodes.map(r=>{let o=N.names?.find(v=>v.cid===r.cid)?.slug;return{cid:r.cid,...o?{logical_id:o}:{}}})}),n&&t.source_id in n.handle.state.read_basis&&(n.handle.complete(),e.out(`session ${s.resume} complete`),e.emit?.({type:"session_complete",sid:s.resume,source_id:t.source_id}),u?.event("ASR_SESSION_COMPLETE",{}),n=null)}}finally{n?.handle.release()}if(A){let t=e.chat?.state.ledger.filter(I=>I.kind==="answer"&&I.receipt.form==="assumed").length??0,a=ye+t,m=e.chat?.state.credits?.total;e.chat?.ledger?.({kind:"summary",lines:[`saved ${ie} use-case${ie===1?"":"s"} across ${y.length} source${y.length===1?"":"s"}`,...a>0?[`${a} assumed default(s)`]:[],...m!==void 0?[`credits used: ${m.toFixed(1)}`]:[],`trace: ${he(g)}`]})}return s.plan||We(e.contextDir),0}export{ct as a,ut as b,et as c,lt as d,Ye as e,Jt as f};
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{closeSync as A,existsSync as $,mkdirSync as h,openSync as k,readFileSync as p,readdirSync as w,renameSync as S,rmSync as g,writeFileSync as m}from"fs";import{join as l}from"path";var a=class extends Error{constructor(r,t){super(`${r}: ${t}`);this.code=r}},d=e=>l(e,"reconcile","plans");function u(e,n){let r=`${e}.tmp-${process.pid}`;m(r,n,{mode:384}),S(r,e)}function N(e,n){let r=d(e);h(r,{recursive:!0});let t=l(r,`${n.created}-${n.source_id}.json`);return u(t,JSON.stringify(n,null,2)+`
3
- `),t}function y(e,n){let r=n;if(r===void 0){let s=d(e),c=[];try{c=w(s).filter(P=>P.endsWith(".json")).sort()}catch{}if(c.length===0)return{error:`no stored plans under ${s} \u2014 run reconcile --plan first`};r=l(s,c[c.length-1])}if(!$(r))return{error:`no such plan file: ${r}`};let t;try{t=p(r,"utf8")}catch(s){return{error:`cannot read plan ${r}: ${s instanceof Error?s.message:String(s)}`}}let i;try{i=JSON.parse(t)}catch(s){return{error:`corrupted plan ${r}: ${s instanceof Error?s.message:String(s)}`}}let o=i?.version;return o===1?{error:`plan predates the vocabulary change \u2014 recompute with --from <file> --source-id <id> (${r})`}:o!==2?{error:`unsupported plan version ${String(o)} in ${r} (expected 2)`}:Array.isArray(i.rows)?{plan:i,path:r}:{error:`not a reconcile plan \u2014 ${r} has no rows[] (hand-edited?)`}}function R(e){let n=e.archive_state??{};return(e.changeset??[]).filter(r=>r.kind==="ARCHIVE"&&n[r.ref]===void 0).map(r=>r.ref)}function D(e,n,r){let t=y("",e);if("error"in t)throw new a("PLAN_UNREADABLE",t.error);let i=t.plan,o=i.archive_state??{};if(o[n]!==void 0)throw new a("ROW_ALREADY_APPLIED",`archive ${n} already ${o[n].outcome}`);o[n]={at:new Date().toISOString(),outcome:r},i.archive_state=o,u(e,JSON.stringify(i,null,2)+`
4
- `)}function _(e,n){let r=d(e),t=[];try{t=w(r).filter(i=>i.endsWith(`-${n}.json`)).sort()}catch{}return t.length===0?null:y(e,l(r,t[t.length-1]))}function O(e,n){let r=_(e,n);if(r===null||"error"in r)return null;let t=r.plan.rows.filter(i=>i.applied===void 0).length+R(r.plan).length;return t>0?{path:r.path,created:r.plan.created,pending:t}:null}function I(e,n,r){let t;try{t=JSON.parse(p(e,"utf8"))}catch(o){throw new a("PLAN_UNREADABLE",`${e}: ${o instanceof Error?o.message:String(o)}`)}let i=t.rows?.[n];if(!i)throw new a("ROW_MISSING",`${e} has no row ${n}`);if(i.applied)throw new a("ROW_ALREADY_APPLIED",`row ${n} of ${e} was already applied (${i.applied.outcome} at ${i.applied.at})`);i.applied={at:new Date().toISOString(),outcome:r},u(e,JSON.stringify(t,null,2)+`
2
+ import{closeSync as A,existsSync as $,mkdirSync as h,openSync as k,readFileSync as p,readdirSync as w,renameSync as _,rmSync as g,writeFileSync as m}from"fs";import{join as l}from"path";var a=class extends Error{constructor(r,t){super(`${r}: ${t}`);this.code=r}},d=e=>l(e,"reconcile","plans");function u(e,n){let r=`${e}.tmp-${process.pid}`;m(r,n,{mode:384}),_(r,e)}function N(e,n){let r=d(e);h(r,{recursive:!0});let t=l(r,`${n.created}-${n.source_id}.json`);return u(t,JSON.stringify(n,null,2)+`
3
+ `),t}function y(e,n){let r=n;if(r===void 0){let o=d(e),c=[];try{c=w(o).filter(P=>P.endsWith(".json")).sort()}catch{}if(c.length===0)return{error:`no stored plans under ${o} \u2014 run reconcile --plan first`};r=l(o,c[c.length-1])}if(!$(r))return{error:`no such plan file: ${r}`};let t;try{t=p(r,"utf8")}catch(o){return{error:`cannot read plan ${r}: ${o instanceof Error?o.message:String(o)}`}}let i;try{i=JSON.parse(t)}catch(o){return{error:`corrupted plan ${r}: ${o instanceof Error?o.message:String(o)}`}}let s=i?.version;return s===1?{error:`plan predates the vocabulary change \u2014 recompute with --from <file> --source-id <id> (${r})`}:s!==2?{error:`unsupported plan version ${String(s)} in ${r} (expected 2)`}:Array.isArray(i.rows)?{plan:i,path:r}:{error:`not a reconcile plan \u2014 ${r} has no rows[] (hand-edited?)`}}function S(e){let n=e.archive_state??{};return(e.changeset??[]).filter(r=>r.kind==="ARCHIVE"&&n[r.ref]===void 0).map(r=>r.ref)}function D(e,n,r){let t=y("",e);if("error"in t)throw new a("PLAN_UNREADABLE",t.error);let i=t.plan,s=i.archive_state??{};if(s[n]!==void 0)throw new a("ROW_ALREADY_APPLIED",`archive ${n} already ${s[n].outcome}`);s[n]={at:new Date().toISOString(),outcome:r},i.archive_state=s,u(e,JSON.stringify(i,null,2)+`
4
+ `)}function R(e,n){let r=d(e),t=[];try{t=w(r).filter(i=>i.endsWith(`-${n}.json`)).sort()}catch{}return t.length===0?null:y(e,l(r,t[t.length-1]))}function O(e,n){let r=R(e,n);if(r===null||"error"in r)return null;let t=r.plan.rows.filter(i=>i.applied===void 0).length+S(r.plan).length;return t>0?{path:r.path,created:r.plan.created,pending:t}:null}function I(e,n,r){let t;try{t=JSON.parse(p(e,"utf8"))}catch(s){throw new a("PLAN_UNREADABLE",`${e}: ${s instanceof Error?s.message:String(s)}`)}let i=t.rows?.[n];if(!i)throw new a("ROW_MISSING",`${e} has no row ${n}`);if(i.applied)throw new a("ROW_ALREADY_APPLIED",`row ${n} of ${e} was already applied (${i.applied.outcome} at ${i.applied.at})`);i.applied={at:new Date().toISOString(),outcome:r},u(e,JSON.stringify(t,null,2)+`
5
5
  `)}function x(e){let n=d(e);h(n,{recursive:!0});let r=l(n,".walk-lock");for(let t=0;t<2;t++)try{let i=k(r,"wx");return m(i,`${process.pid}
6
- `),A(i),()=>{try{g(r)}catch{}}}catch(i){if(i.code!=="EEXIST")throw i;let o=f(r);if(!Number.isFinite(o)){let c=Date.now()+50;for(;Date.now()<c;);o=f(r)}if(Number.isFinite(o)&&v(o))throw new a("WALK_LOCKED",`another reconcile walk is running (pid ${o}) \u2014 remove ${r} if that process is gone`);try{g(r)}catch{}}throw new a("WALK_LOCKED",`could not take the walk lock at ${l(n,".walk-lock")}`)}function f(e){try{return parseInt(p(e,"utf8").trim(),10)}catch{return NaN}}function v(e){try{return process.kill(e,0),!0}catch{return!1}}export{N as a,y as b,R as c,D as d,_ as e,O as f,I as g,x as h};
6
+ `),A(i),()=>{try{g(r)}catch{}}}catch(i){if(i.code!=="EEXIST")throw i;let s=f(r);if(!Number.isFinite(s)){let c=Date.now()+50;for(;Date.now()<c;);s=f(r)}if(Number.isFinite(s)&&v(s))throw new a("WALK_LOCKED",`another reconcile walk is running (pid ${s}) \u2014 remove ${r} if that process is gone`);try{g(r)}catch{}}throw new a("WALK_LOCKED",`could not take the walk lock at ${l(n,".walk-lock")}`)}function f(e){try{return parseInt(p(e,"utf8").trim(),10)}catch{return NaN}}function v(e){try{return process.kill(e,0),!0}catch{return!1}}export{N as a,y as b,S as c,D as d,R as e,O as f,I as g,x as h};
@@ -1,2 +1,2 @@
1
1
  import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
- import{c as L}from"./chunk-RFHMDQXZ.js";import{Q as O,S}from"./chunk-EYZWG32F.js";import{e as P,f as R}from"./chunk-M5JQXOCE.js";import{y as s}from"./chunk-PXPXK4Q7.js";import{a as y}from"./chunk-HCBYKLMW.js";import{a as E,b as o,i as h}from"./chunk-C44QQJR4.js";import{a as B}from"./chunk-6YGTRKDT.js";import{e as d}from"./chunk-UR6MHSHU.js";var n=d(B(),1);import{basename as D}from"path";var r=d(y(),1),U="evidence-view-server";function Q({packPath:m,viewerBase:w,onDone:V,openUrl:k}){let[t,a]=(0,n.useState)("ask"),[g,b]=(0,n.useState)(null),[l,p]=(0,n.useState)(null),f=(0,n.useRef)(null),u=(0,n.useRef)(!1),x=async()=>{let e=f.current;f.current=null,e&&(R(U),await e.close())},v=()=>{u.current||(u.current=!0,V())};return h((e,i)=>{u.current||(t==="ask"?e==="y"||e==="Y"?a("starting"):(e==="n"||e==="N"||i.return||i.escape)&&v():t==="serving"&&(e==="q"||e==="Q"||i.escape)&&x().then(v))}),(0,n.useEffect)(()=>{if(t!=="starting")return;let e=!1;return(async()=>{try{let i=D(m),c=await O({packs:new Map([[i,m]]),allowedOrigins:[new URL(w).origin]});if(e){await c.close();return}f.current=c,P(U,()=>{c.close()});let T=S(c.urlFor(i),w);b(T);try{await(k??(q=>L(q)))(T)}catch{p("could not open browser \u2014 open the URL manually")}a("serving")}catch(i){p(`evidence view failed \u2014 ${i.message}`),a("failed")}})(),()=>{e=!0}},[t]),(0,n.useEffect)(()=>{if(t!=="failed")return;let e=setTimeout(v,0);return()=>clearTimeout(e)},[t]),(0,n.useEffect)(()=>()=>{x()},[]),t==="ask"?(0,r.jsxs)(o,{children:["View evidence in browser? ",(0,r.jsx)(o,{color:s.dim,children:"(y/N)"})]}):t==="serving"||t==="starting"?(0,r.jsxs)(E,{flexDirection:"column",children:[g?(0,r.jsxs)(o,{children:["viewer ",(0,r.jsx)(o,{color:s.orange,children:g})]}):(0,r.jsx)(o,{color:s.dim,children:"starting\u2026"}),l?(0,r.jsx)(o,{color:"yellow",children:l}):null,t==="serving"?(0,r.jsx)(o,{color:s.dim,children:"Press q when done"}):null]}):l?(0,r.jsx)(o,{color:"yellow",children:l}):null}export{Q as a};
2
+ import{c as L}from"./chunk-RFHMDQXZ.js";import{Q as O,S}from"./chunk-OESHJ4J2.js";import{m as P,n as R}from"./chunk-Y5RNCJAN.js";import{y as s}from"./chunk-2KS2YRIS.js";import{a as y}from"./chunk-HCBYKLMW.js";import{a as E,b as o,i as h}from"./chunk-C44QQJR4.js";import{a as B}from"./chunk-6YGTRKDT.js";import{e as d}from"./chunk-UR6MHSHU.js";var n=d(B(),1);import{basename as D}from"path";var r=d(y(),1),U="evidence-view-server";function Q({packPath:m,viewerBase:w,onDone:V,openUrl:k}){let[t,a]=(0,n.useState)("ask"),[g,b]=(0,n.useState)(null),[l,p]=(0,n.useState)(null),f=(0,n.useRef)(null),u=(0,n.useRef)(!1),x=async()=>{let e=f.current;f.current=null,e&&(R(U),await e.close())},v=()=>{u.current||(u.current=!0,V())};return h((e,i)=>{u.current||(t==="ask"?e==="y"||e==="Y"?a("starting"):(e==="n"||e==="N"||i.return||i.escape)&&v():t==="serving"&&(e==="q"||e==="Q"||i.escape)&&x().then(v))}),(0,n.useEffect)(()=>{if(t!=="starting")return;let e=!1;return(async()=>{try{let i=D(m),c=await O({packs:new Map([[i,m]]),allowedOrigins:[new URL(w).origin]});if(e){await c.close();return}f.current=c,P(U,()=>{c.close()});let T=S(c.urlFor(i),w);b(T);try{await(k??(q=>L(q)))(T)}catch{p("could not open browser \u2014 open the URL manually")}a("serving")}catch(i){p(`evidence view failed \u2014 ${i.message}`),a("failed")}})(),()=>{e=!0}},[t]),(0,n.useEffect)(()=>{if(t!=="failed")return;let e=setTimeout(v,0);return()=>clearTimeout(e)},[t]),(0,n.useEffect)(()=>()=>{x()},[]),t==="ask"?(0,r.jsxs)(o,{children:["View evidence in browser? ",(0,r.jsx)(o,{color:s.dim,children:"(y/N)"})]}):t==="serving"||t==="starting"?(0,r.jsxs)(E,{flexDirection:"column",children:[g?(0,r.jsxs)(o,{children:["viewer ",(0,r.jsx)(o,{color:s.orange,children:g})]}):(0,r.jsx)(o,{color:s.dim,children:"starting\u2026"}),l?(0,r.jsx)(o,{color:"yellow",children:l}):null,t==="serving"?(0,r.jsx)(o,{color:s.dim,children:"Press q when done"}):null]}):l?(0,r.jsx)(o,{color:"yellow",children:l}):null}export{Q as a};
@@ -0,0 +1,2 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+ import{a as E}from"./chunk-YCCUBQY4.js";import{y as a}from"./chunk-2KS2YRIS.js";import{a as B}from"./chunk-HCBYKLMW.js";import{a as b,b as n,i as C,k as O}from"./chunk-C44QQJR4.js";import{a as D}from"./chunk-6YGTRKDT.js";import{e as v}from"./chunk-UR6MHSHU.js";var o=v(B(),1);function W(d){let e=d.findIndex(c=>c.free);return e>=0?e:null}var L=60,F=100;function H({headline:d,ask:e=!1,rows:c,sel:t,focused:T,legend:u,freeText:l=null,freeTextNote:m}){let{stdout:i}=O(),r=i?.columns??80,f=r<L,A=Math.min(r-1,F),s=x=>T&&t===x?(0,o.jsx)(n,{color:a.assuranceAccent,children:"\u276F"}):" ",g=e?`? ${d}`:d,p=0,w=c.map((x,S)=>x.free?l?(0,o.jsxs)(b,{flexDirection:"column",children:[(0,o.jsxs)(b,{children:[(0,o.jsxs)(n,{children:[(0,o.jsx)(n,{color:a.assuranceAccent,children:"\u276F"})," ",(0,o.jsx)(n,{color:a.dim,children:"\u270E "})]}),(0,o.jsx)(E,{value:l.value,onChange:l.onChange,onSubmit:l.onSubmit,onCancel:l.onCancel,placeholder:x.label})]}),m?(0,o.jsx)(n,{color:a.muted,children:` ${m}`}):null]},x.key):(0,o.jsxs)(n,{children:[s(S)," ",(0,o.jsx)(n,{color:a.dim,children:`\u270E ${x.label}`})]},x.key):(p+=1,(0,o.jsxs)(n,{bold:T&&t===S,children:[s(S),` ${p}. ${x.label}`,x.detail?(0,o.jsx)(n,{color:a.dim,bold:!1,children:` \u2014 ${x.detail}`}):null]},x.key)));if(f)return(0,o.jsxs)(b,{marginTop:1,marginBottom:1,flexDirection:"column",children:[(0,o.jsx)(n,{bold:!0,color:a.assuranceAccent,children:g}),w,(0,o.jsx)(n,{color:a.muted,children:u})]});let h=Math.max(2,A-(3+g.length+1)),P=Math.max(2,A-(3+u.length+1));return(0,o.jsxs)(b,{marginTop:1,marginBottom:1,flexDirection:"column",children:[(0,o.jsxs)(n,{color:a.assuranceAccent,children:["\u2500\u2500 ",(0,o.jsx)(n,{bold:!0,children:g}),` ${"\u2500".repeat(h)}`]}),(0,o.jsx)(n,{children:" "}),w,(0,o.jsx)(n,{children:" "}),(0,o.jsxs)(n,{color:a.assuranceAccent,children:["\u2500\u2500 ",(0,o.jsx)(n,{color:a.muted,children:u}),` ${"\u2500".repeat(P)}`]})]})}var R=v(B(),1),N="ctrl+t thinking \xB7 ctrl+c exit";function $(d,e){if(d.length<=e)return d;if(e<=1)return"\u2026";let c=Math.ceil((e-1)/2),t=Math.floor((e-1)/2);return`${d.slice(0,c)}\u2026${t>0?d.slice(-t):""}`}function q({verb:d,subject:e,pendingCount:c,creditsTotal:t,state:T,hints:u=N}){let{stdout:l}=O(),m=l?.columns??80,i=[];i.push(d),T&&i.push(T),t!==void 0&&i.push(`${t.toFixed(1)} credits`);let r=c?`[${c} pending]`:null,f=" \xB7 ",s=[...i,...r?[r]:[]].join(f).length,g,p=[...i,...e?[e]:[],...r?[r]:[],u].join(f);if(p.length<=m)g=p;else{let w=m-s-(e?f.length:0)-f.length-u.length;if(e&&w>=8)g=[...i,$(e,w),...r?[r]:[],u].join(f);else{let h=m-s-(e?f.length:0);g=[...i,...e&&h>=4?[$(e,h)]:[],...r?[r]:[]].join(f)}}if(T){let w=` \xB7 ${T}`,h=g.indexOf(w);if(h>=0)return(0,R.jsxs)(n,{color:a.dim,children:[g.slice(0,h+3),(0,R.jsx)(n,{color:a.assuranceAccent,children:T}),g.slice(h+w.length)]})}return(0,R.jsx)(n,{color:a.dim,children:g})}var M=v(D(),1);function J({onToggleThinking:d,onCtrlC:e,explorer:c,panel:t}){let u=(0,M.useRef)(null),l=(0,M.useRef)(""),m=()=>{u.current&&clearTimeout(u.current),u.current=null,l.current=""};return(0,M.useEffect)(()=>m,[]),C((i,r)=>{if(r.ctrl&&i==="t"){d();return}if(r.ctrl&&i==="c"){e();return}if(!r.ctrl&&i.includes("")){e();return}if(!r.ctrl&&i.includes("")){d();return}if(c&&c.isOpen()){let f=()=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{m(),c.onBack()},150)};if(u.current){if(r.upArrow||r.downArrow||r.return){m(),r.return?c.onEnter():c.onMove(r.upArrow?-1:1);return}if(l.current+=i,l.current==="["){f();return}let A=l.current;m();let s=/^\[([ABCD])/.exec(A);if(s){(s[1]==="A"||s[1]==="B")&&c.onMove(s[1]==="A"?-1:1);return}c.onBack();return}if(r.upArrow){c.onMove(-1);return}if(r.downArrow){c.onMove(1);return}if(r.return){c.onEnter();return}if(r.escape){l.current="",f();return}return}if(t&&t.isFocused()){let f=()=>{u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{m(),t.onBack()},150)};if(u.current){if(r.upArrow||r.downArrow||r.return||r.leftArrow||r.rightArrow){m(),r.return?t.onSelect():r.leftArrow?t.onLeft?.():r.rightArrow?t.onRight?.():t.onMove(r.upArrow?-1:1);return}if(l.current+=i,l.current==="["){f();return}let A=l.current;m();let s=/^\[([ABCD])/.exec(A);if(s){s[1]==="A"||s[1]==="B"?t.onMove(s[1]==="A"?-1:1):s[1]==="C"?t.onRight?.():t.onLeft?.();return}t.onBack();return}if(r.upArrow){t.onMove(-1);return}if(r.downArrow){t.onMove(1);return}if(r.leftArrow){t.onLeft?.();return}if(r.rightArrow){t.onRight?.();return}if(r.return){t.onSelect();return}if(r.escape){l.current="",f();return}if(/^[1-9]$/.test(i)){t.onDigit(Number(i));return}if(r.tab){t.onTab?.();return}if(i===" "&&t.isMulti()){t.onSpace();return}if(i&&!r.ctrl&&!r.meta){t.onType(i);return}return}}),null}export{W as a,H as b,q as c,J as d};