@tansr/cli 0.10.3 → 0.11.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 (133) hide show
  1. package/package.json +1 -1
  2. package/tansr-artifacts.json +1223 -831
  3. package/tansr-bg-A35DNHK2.mjs +5 -0
  4. package/tansr-chunk-2CIB4KCJ.mjs +5 -0
  5. package/{tansr-chunk-XXBNISJJ.mjs → tansr-chunk-2HZJSKHM.mjs} +2 -2
  6. package/{tansr-chunk-CJP7YEGC.mjs → tansr-chunk-2PB54HDR.mjs} +2 -2
  7. package/tansr-chunk-33QZBUL6.mjs +6 -0
  8. package/tansr-chunk-3YSQG6KY.mjs +5 -0
  9. package/tansr-chunk-4DAH4AIH.mjs +7 -0
  10. package/{tansr-chunk-HHL7HM62.mjs → tansr-chunk-4IWNKAT5.mjs} +2 -2
  11. package/tansr-chunk-4YAEV3T6.mjs +9 -0
  12. package/tansr-chunk-546BDI3V.mjs +7 -0
  13. package/tansr-chunk-6N333TUL.mjs +241 -0
  14. package/{tansr-chunk-KQVXXXEF.mjs → tansr-chunk-6QKU3GNA.mjs} +2 -2
  15. package/tansr-chunk-AHUB2IHT.mjs +5 -0
  16. package/tansr-chunk-AOH7YPF3.mjs +8 -0
  17. package/{tansr-chunk-C6COFFZK.mjs → tansr-chunk-B2O4DB4K.mjs} +2 -2
  18. package/tansr-chunk-C2NTVBEY.mjs +5 -0
  19. package/{tansr-chunk-D7VSW2LQ.mjs → tansr-chunk-C75DEEUJ.mjs} +2 -2
  20. package/tansr-chunk-ECYZ457U.mjs +5 -0
  21. package/tansr-chunk-EFN24XG3.mjs +25 -0
  22. package/tansr-chunk-ENRIN7EG.mjs +7 -0
  23. package/{tansr-chunk-RVSBSUXE.mjs → tansr-chunk-ITZBYACC.mjs} +2 -2
  24. package/{tansr-chunk-GMPMRXL4.mjs → tansr-chunk-IZZYKHSW.mjs} +3 -3
  25. package/tansr-chunk-JIC3VWLQ.mjs +252 -0
  26. package/tansr-chunk-JTGWG4BG.mjs +32 -0
  27. package/tansr-chunk-LA3LGOYQ.mjs +11 -0
  28. package/tansr-chunk-MAMODDQN.mjs +5 -0
  29. package/tansr-chunk-N644DEOO.mjs +5 -0
  30. package/tansr-chunk-NQOYEFEE.mjs +5 -0
  31. package/tansr-chunk-O7P4OFK7.mjs +7 -0
  32. package/tansr-chunk-OEHA7T4Q.mjs +26 -0
  33. package/{tansr-chunk-ZV3NCXTD.mjs → tansr-chunk-OKNSOZDU.mjs} +7 -7
  34. package/tansr-chunk-OT4KIQLR.mjs +9 -0
  35. package/tansr-chunk-OUOTEH4A.mjs +5 -0
  36. package/tansr-chunk-Q3XDAUKT.mjs +65 -0
  37. package/tansr-chunk-RFH7OCN6.mjs +5 -0
  38. package/tansr-chunk-RUYIVG72.mjs +12 -0
  39. package/tansr-chunk-SCFXBKV6.mjs +8 -0
  40. package/tansr-chunk-SHLU4JN2.mjs +5 -0
  41. package/{tansr-chunk-M774GK3P.mjs → tansr-chunk-SIV2666W.mjs} +2 -2
  42. package/tansr-chunk-SX3XZNN6.mjs +6 -0
  43. package/tansr-chunk-SXNTYWJY.mjs +8 -0
  44. package/tansr-chunk-UVL2XWKL.mjs +5 -0
  45. package/tansr-chunk-V4HGMAJS.mjs +375 -0
  46. package/{tansr-chunk-2X337GKC.mjs → tansr-chunk-W2WIN3M2.mjs} +2 -2
  47. package/tansr-chunk-WAYVH5ON.mjs +5 -0
  48. package/tansr-chunk-WPKFARCU.mjs +11 -0
  49. package/{tansr-chunk-726Y5F3M.mjs → tansr-chunk-YEYFEVYF.mjs} +2 -2
  50. package/tansr-chunk-YK3CE3JM.mjs +5 -0
  51. package/tansr-chunk-YOSRXZWY.mjs +5 -0
  52. package/tansr-compaction-history-LZXZTWBV.mjs +5 -0
  53. package/tansr-compaction-log-H2SPLK24.mjs +5 -0
  54. package/tansr-indexed-CPYJVPFI.mjs +5 -0
  55. package/tansr-lock-XWDVZMLY.mjs +5 -0
  56. package/tansr-main-6GDLXIRQ.mjs +7 -0
  57. package/tansr-render-SVMDLHLN.mjs +6 -0
  58. package/tansr-restore-7PS7WCJR.mjs +5 -0
  59. package/tansr-run-acp-entry-EQGUKZ5R.mjs +68 -0
  60. package/tansr-run-approvals-entry-SEYBHLS2.mjs +12 -0
  61. package/{tansr-run-auth-entry-7HA4C4NJ.mjs → tansr-run-auth-entry-R3GKGKWX.mjs} +2 -2
  62. package/tansr-run-doctor-B3XK72DW.mjs +11 -0
  63. package/tansr-run-headless-entry-4XTAVPTW.mjs +84 -0
  64. package/tansr-run-init-entry-GH2KDGI6.mjs +5 -0
  65. package/tansr-run-logout-entry-PLGYDEOB.mjs +5 -0
  66. package/tansr-run-mcp-serve-entry-UHK4WSKL.mjs +14 -0
  67. package/tansr-run-orchestrate-entry-M7R3433X.mjs +11 -0
  68. package/tansr-run-org-entry-UONLGJIJ.mjs +17 -0
  69. package/tansr-run-policy-entry-NNQCV5WS.mjs +16 -0
  70. package/tansr-run-profile-entry-PV6OO7FV.mjs +14 -0
  71. package/tansr-run-serve-entry-GWZQZ37P.mjs +16 -0
  72. package/tansr-run-sessions-entry-WL7YLRJL.mjs +25 -0
  73. package/tansr-run-update-entry-YI47IPCC.mjs +5 -0
  74. package/tansr-spill-YVUTIFOS.mjs +5 -0
  75. package/tansr-src-LPMSGRKO.mjs +5 -0
  76. package/{tansr-src-A6WDMY6X.mjs → tansr-src-RQJPOVDN.mjs} +50 -50
  77. package/tansr-startup-account-MYFJ3NOL.mjs +7 -0
  78. package/{tansr-startup-model-I6LOCFDP.mjs → tansr-startup-model-BCGEYUM4.mjs} +3 -3
  79. package/tansr-storage-journal-4E274MUA.mjs +5 -0
  80. package/tansr-todos-replay-TVQKP7OD.mjs +5 -0
  81. package/tansr-tui-3Q7Z3ALV.mjs +73 -0
  82. package/tansr.mjs +1 -1
  83. package/tansrd.mjs +444 -265
  84. package/tansr-bg-EAYYM4XW.mjs +0 -5
  85. package/tansr-chunk-2C6JKHKM.mjs +0 -25
  86. package/tansr-chunk-4LNN4SQL.mjs +0 -22
  87. package/tansr-chunk-5T7X32UX.mjs +0 -6
  88. package/tansr-chunk-5TJVZSZE.mjs +0 -6
  89. package/tansr-chunk-74H5GQTJ.mjs +0 -35
  90. package/tansr-chunk-7T6OLLFW.mjs +0 -12
  91. package/tansr-chunk-BX7CF5RQ.mjs +0 -25
  92. package/tansr-chunk-DN22GXHD.mjs +0 -8
  93. package/tansr-chunk-F7C6ITED.mjs +0 -5
  94. package/tansr-chunk-GDJ5YVNY.mjs +0 -5
  95. package/tansr-chunk-GR6BWQGG.mjs +0 -38
  96. package/tansr-chunk-HRKJLVKC.mjs +0 -7
  97. package/tansr-chunk-I3TOVAA6.mjs +0 -5
  98. package/tansr-chunk-IZICOKKF.mjs +0 -279
  99. package/tansr-chunk-J2LWM3S7.mjs +0 -5
  100. package/tansr-chunk-M6XHWCMA.mjs +0 -11
  101. package/tansr-chunk-MWHLITGY.mjs +0 -11
  102. package/tansr-chunk-N3R2URKL.mjs +0 -5
  103. package/tansr-chunk-NA22YT73.mjs +0 -5
  104. package/tansr-chunk-OSK64SU3.mjs +0 -5
  105. package/tansr-chunk-QEKVLX7W.mjs +0 -5
  106. package/tansr-chunk-QHEQQ2JB.mjs +0 -9
  107. package/tansr-chunk-QUFHVA3F.mjs +0 -5
  108. package/tansr-chunk-QWGSXFEJ.mjs +0 -7
  109. package/tansr-chunk-SJFDQLLC.mjs +0 -5
  110. package/tansr-chunk-X4GLXJ2Z.mjs +0 -67
  111. package/tansr-chunk-X5REV3T3.mjs +0 -8
  112. package/tansr-chunk-ZQ3ZK7IL.mjs +0 -37
  113. package/tansr-main-STVTNYAI.mjs +0 -7
  114. package/tansr-render-PUEISX75.mjs +0 -6
  115. package/tansr-run-acp-entry-6J44XOYJ.mjs +0 -63
  116. package/tansr-run-approvals-entry-HQWSIW3P.mjs +0 -12
  117. package/tansr-run-doctor-7T6IAXYE.mjs +0 -10
  118. package/tansr-run-headless-entry-XEFQC5LE.mjs +0 -78
  119. package/tansr-run-init-entry-3VKXS2WK.mjs +0 -5
  120. package/tansr-run-logout-entry-VNCNNCSS.mjs +0 -5
  121. package/tansr-run-mcp-serve-entry-5KLWER3G.mjs +0 -14
  122. package/tansr-run-orchestrate-entry-AR57AZLR.mjs +0 -11
  123. package/tansr-run-org-entry-TJPRLGCL.mjs +0 -17
  124. package/tansr-run-policy-entry-DHMQ3PAP.mjs +0 -16
  125. package/tansr-run-profile-entry-LOFPHFG4.mjs +0 -14
  126. package/tansr-run-serve-entry-CHVKUY5J.mjs +0 -99
  127. package/tansr-run-sessions-entry-JOMFB5LJ.mjs +0 -23
  128. package/tansr-run-update-entry-XI6KG7UI.mjs +0 -5
  129. package/tansr-sqlite-event-store-UQLSSZKP.mjs +0 -26
  130. package/tansr-sqlite-spool-implementation-LHEIRSUX.mjs +0 -29
  131. package/tansr-src-KOEPYVXX.mjs +0 -5
  132. package/tansr-startup-account-7ZFSP3FV.mjs +0 -7
  133. package/tansr-tui-OWG3JNA6.mjs +0 -75
@@ -1,5 +0,0 @@
1
- import { createRequire as __tansrCreateRequire } from 'module';const require=__tansrCreateRequire(import.meta.url);
2
- import { fileURLToPath as __tansrFileURLToPath } from 'url';import { dirname as __tansrDirname } from 'path';
3
- const __filename=__tansrFileURLToPath(import.meta.url);const __dirname=__tansrDirname(__filename);
4
- import{i as g,j as p,k as c}from"./tansr-chunk-HRKJLVKC.mjs";import{D as h,E as M,t as d,v as S,w,z as y}from"./tansr-chunk-IZICOKKF.mjs";import{readdir as x,stat as P}from"node:fs/promises";import l from"node:path";function R(e=process.env){return p(e)?.root??g(e)}async function b(e){try{return await P(e)}catch{return null}}async function m(e){let t=await b(S(e)),s=await M(e).catch(()=>null),n=t?.size??0,i;for(let r of s?.segments??[]){let a=await b(w(e,r.n));h(r,a!==null)&&a!==null&&(n+=a.size,(i===void 0||a.mtimeMs>i)&&(i=a.mtimeMs))}return t!==null?{mtimeMs:t.mtimeMs,bytes:n}:i!==void 0?{mtimeMs:i,bytes:n}:null}function I(e,t){let s=l.resolve(e),n=l.resolve(t);return process.platform==="win32"?s.toLowerCase()===n.toLowerCase():s===n}async function v(e,t){let s=l.join(e,"sessions"),n;try{n=(await x(s,{withFileTypes:!0})).filter(a=>a.isDirectory()).map(a=>a.name)}catch{return[]}let i=[];for(let r of n){if(t.excludeSessionId!==void 0&&r===t.excludeSessionId)continue;let a=l.join(s,r);try{let f=await m(a);if(f===null)continue;let o=await y(a);if(o.sessionId!==r||t.cwd!==void 0&&!I(o.cwd,t.cwd))continue;let u={sessionId:o.sessionId,cwd:o.cwd,createdAt:o.createdAt,updatedAt:f.mtimeMs};o.title!==void 0&&(u.title=o.title),o.firstUserMessage!==void 0&&(u.firstUserMessage=o.firstUserMessage),o.model!==void 0&&(u.model=o.model),o.provider!==void 0&&(u.provider=o.provider),i.push(u)}catch{continue}}return i}async function L(e,t={}){let s=await v(e,t),n=c(e);if(n!==null){let i=new Set(s.map(r=>r.sessionId));for(let r of await v(n,t))i.has(r.sessionId)||s.push(r)}return s.sort((i,r)=>r.updatedAt-i.updatedAt),s}async function U(e,t){let s;try{s=d(e,t)}catch{return null}if(await m(s)!==null)return s;let n=c(e);if(n===null)return null;let i=d(n,t);return await m(i)!==null?i:null}async function j(e,t){return(await L(e,{cwd:t}))[0]?.sessionId}export{R as a,m as b,L as c,U as d,j as e};
5
- //# sourceMappingURL=tansr-chunk-J2LWM3S7.mjs.map
@@ -1,11 +0,0 @@
1
- import { createRequire as __tansrCreateRequire } from 'module';const require=__tansrCreateRequire(import.meta.url);
2
- import { fileURLToPath as __tansrFileURLToPath } from 'url';import { dirname as __tansrDirname } from 'path';
3
- const __filename=__tansrFileURLToPath(import.meta.url);const __dirname=__tansrDirname(__filename);
4
- import{a as m,h as v,i as b}from"./tansr-chunk-DN22GXHD.mjs";import{A as U,C as q,F as h,I,Z as F,_ as H,d as M,j as A,l as O,t as C,x,y as N}from"./tansr-chunk-IZICOKKF.mjs";import{F as L}from"./tansr-chunk-ZQ3ZK7IL.mjs";import{m as E}from"./tansr-chunk-NA22YT73.mjs";import{F as f}from"./tansr-chunk-QWGSXFEJ.mjs";var ae="TodoWrite";function le(r){if(r===null||typeof r!="object")return null;let e=r,t=e.id,s=e.content,n=e.status;return typeof t!="string"||t.trim()===""||typeof s!="string"||s.trim()===""||typeof n!="string"||!F.includes(n)?null:{id:t,content:s,status:n}}function de(r){if(r===null||typeof r!="object")return null;let e=r;if(typeof e.merge!="boolean"||!Array.isArray(e.todos))return null;let t=[],s=new Set;for(let n of e.todos){let o=le(n);if(o===null||s.has(o.id))return null;s.add(o.id),t.push(o)}return{merge:e.merge,todos:t}}function ue(r){let e=new Map;for(let s of r)for(let n of s.blocks)n.t==="tool_result"&&e.set(n.callId,n.isError===!0);let t=[];for(let s of r)if(s.role==="assistant")for(let n of s.blocks){if(n.t!=="tool_call"||n.name!==ae||e.get(n.id)!==!1)continue;let o=de(n.args);o!==null&&t.push(o)}return t}function D(r){let e=ue(r),t=new H;for(let s of e)try{s.merge?t.merge(s.todos):t.replace(s.todos)}catch{}return{items:t.list(),sawTodoWrite:e.length>0}}async function k(r,e){let t=[],s=e.compactBoundary?.sourceSessionId;if(s!==void 0)try{let o=await v(r,s);o.ok&&t.push(o.messages)}catch{}t.push([...e.messages]);let n=D(t.flat());return n.sawTodoWrite?n.items:null}import{randomUUID as K}from"node:crypto";import{randomUUID as c}from"node:crypto";import{readFile as ce}from"node:fs/promises";var B=64;function W(r){for(let e of r){if(e.role!=="user")continue;let t=e.blocks.flatMap(s=>s.t==="text"?[s.text]:[]).join(" ").replace(/\s+/g," ").trim();if(t!=="")return t.length>B?`${t.slice(0,B)}…`:t}}var G=120,pe=/\u001b\[[0-9;]*[A-Za-z]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g,fe=/[\u0000-\u001f\u007f-\u009f]/g;function j(r){for(let e of r){if(e.role!=="user")continue;let t=e.blocks.flatMap(n=>n.t==="text"?[n.text]:[]).join(" ").replace(pe,"").replace(fe," ").replace(/\s+/g," ").trim();if(t==="")continue;let s=[...t];return s.length>G?`${s.slice(0,G).join("")}…`:t}}function J(r){return r.role==="assistant"?"assistant_message":r.blocks.some(e=>e.t==="tool_result")?"tool_result":"user_prompt"}var he="emergency_seal",me=1,S=class{#u;#c;#h;#m;#g;#l;#y;#S;#R;#k;#p;#d=null;#P=Promise.resolve();#s;#T;#a=0;#e=null;#t=null;#E=null;#I=null;#v=null;#f=null;#n=!1;#r=!1;#w=[];#_=[];#M=[];#A=[];#O=[];#C=[];#b=null;#N=null;constructor(e){this.#u=e.storageRoot,this.#s=e.sessionId,this.#T=[e.sessionId],this.#c=e.cwd,this.#h=e.model,this.#m=e.currentModel,this.#g=e.startedAt??new Date().toISOString(),this.#l=e.outputStyle,this.#y=e.usageReportingDisabled===!0,this.#S=e.platformSessionId,this.#R=e.onError,this.#k=e.segmentation===!1?{enabled:!1}:e.segmentation===void 0?{}:{...e.segmentation},this.#p=e.lockHeartbeatMs??A}#q(){if(this.#d!==null||this.#r||!Number.isFinite(this.#p)||this.#p<=0)return;let e=setInterval(()=>{let t=this.#e?.lock??this.#t;t?.touch().catch(()=>{})},this.#p);e.unref(),this.#d=e}#W(){this.#d!==null&&(clearInterval(this.#d),this.#d=null)}currentSessionId(){return this.#s}volumeIds(){return[...this.#T].reverse()}#U(e){this.#s=e,this.#T.includes(e)||this.#T.push(e)}persistedCount(){return this.#a}commitHistory(e,t){if(this.#r)return;let s=[...e],n=t?.rewritten===!0,o=t?.compaction!==void 0?{...t.compaction}:void 0;this.#o(()=>this.#H(s,n,o))}commitEmergency(e,t){if(this.#r)return Promise.resolve();let s=[...e],n={type:he,version:me,reason:t.reason,...t.signal!==void 0?{signal:t.signal}:{},at:t.at,turn:t.turn,messages:s.length,...t.partialText!==void 0&&t.partialText.length>0?{partialText:t.partialText}:{}};return this.#o(async()=>{await this.#H(s,!1),!(this.#n||this.#e===null)&&await this.#i(this.#e,n)})}appendFileCheckpoint(e){if(this.#r)return;let t=structuredClone(e);this.#o(async()=>{if(!this.#n){if(this.#e===null){this.#w.push(t);return}await this.#G(this.#e,t)}})}appendRetryLedger(e){if(this.#r)return;let t=structuredClone(e);this.#o(async()=>{if(!this.#n){if(this.#e===null){this.#_.push(t);return}try{await this.#D(this.#e,t)}catch{}}})}appendPermissionRuntime(e){if(this.#r)return;let t=structuredClone(e);this.#o(async()=>{if(!this.#n){if(this.#e===null){this.#A.push(t);return}await this.#i(this.#e,t)}})}appendCompactionAttempt(e){if(this.#r)return;let t=structuredClone(e);this.#o(async()=>{if(!this.#n){if(this.#e===null){this.#O.push(t);return}try{await this.#i(this.#e,t)}catch{}}})}appendUsageSnapshot(e){if(this.#r)return;let t=structuredClone(e);this.#o(async()=>{if(!this.#n){if(this.#N=t,this.#e===null){this.#b=t;return}try{await this.#i(this.#e,t)}catch{}}})}appendSessionEvent(e){if(this.#r)return;let t=structuredClone(e);this.#o(async()=>{if(!this.#n){if(this.#e===null){this.#C.push(t);return}try{await this.#i(this.#e,t)}catch{}}})}appendQueueEnqueue(e){return this.#L("queue_enqueue",e)}appendQueueAck(e){return this.#L("queue_ack",e)}#L(e,t){if(this.#r)return Promise.resolve();let s=structuredClone(t);return this.#o(async()=>{if(!this.#n){if(this.#e===null){this.#M.push({kind:e,payload:s});return}await this.#B(this.#e,e,s)}})}adoptSession(e){return this.#r?e.lock.release():this.#o(async()=>{if(this.#n){await e.lock.release();return}await this.#x(),await this.#F(),this.#t=e.lock,this.#E=e.lastEventId??null,this.#I=e.lastSeq??null,this.#v=e.cursor??null,this.#U(e.sessionId),this.#a=e.persistedCount,this.#f=null,this.#q()})}adoptFresh(e=c()){return this.#r?Promise.resolve():this.#o(async()=>{this.#n||(await this.#x(),await this.#F(),this.#U(e),this.#a=0,this.#E=null,this.#I=null,this.#v=null,this.#f=null)})}async#F(){this.#t!==null&&(await this.#t.release(),this.#t=null)}async close(){this.#r=!0,this.#W(),await this.#o(async()=>{await this.#x(),this.#t!==null&&(await this.#t.release(),this.#t=null)})}#o(e){let t=this.#P.then(async()=>{try{await e()}catch(s){let n=!this.#n;if(this.#n=!0,n){let o=s instanceof Error?s.message:String(s);this.#R?.(E(m.persistFailed,{message:o}))}}});return this.#P=t,t}async#x(){let e=this.#e;this.#e=null,e!==null&&(await e.writer.close(),await e.lock.release())}async#H(e,t=!1,s){if(this.#n)return;if(e.length<this.#a||t&&this.#a>0){let i=this.#s,a=this.#e!==null?this.#e.writer.nextSeq-1:this.#I;await this.#x(),this.#t!==null&&(await this.#t.release(),this.#t=null),this.#E=null,this.#I=null,this.#v=null,this.#f=t&&s!==void 0&&a!==null&&a>=0?{sourceSessionId:i,sourceSeq:a,compactionId:s.compactionId,trigger:s.trigger,...s.beforeTokens!==void 0?{beforeTokens:s.beforeTokens}:{},...s.afterTokens!==void 0?{afterTokens:s.afterTokens}:{},...s.checkpointId!==void 0?{checkpointId:s.checkpointId}:{}}:null,this.#U(c()),this.#a=0,this.#N!==null&&(this.#b=this.#N)}let n=e.slice(this.#a);if(n.length===0)return;let o=await this.#Q(e);if(this.#f!==null){let i=this.#f;this.#f=null,await this.#J(o,i)}if(this.#w.length>0){let i=this.#w;this.#w=[];for(let a of i)await this.#G(o,a)}if(this.#_.length>0){let i=this.#_;this.#_=[];for(let a of i)try{await this.#D(o,a)}catch{}}if(this.#O.length>0){let i=this.#O;this.#O=[];for(let a of i)try{await this.#i(o,a)}catch{}}if(this.#C.length>0){let i=this.#C;this.#C=[];for(let a of i)try{await this.#i(o,a)}catch{}}if(this.#b!==null){let i=this.#b;this.#b=null;try{await this.#i(o,i)}catch{}}if(this.#A.length>0){let i=this.#A;this.#A=[];for(let a of i)await this.#i(o,a)}if(this.#M.length>0){let i=this.#M;this.#M=[];for(let{kind:a,payload:l}of i)await this.#B(o,a,l)}for(let i of n){let a=c();await o.writer.append({eventId:a,sessionId:this.#s,branchId:h,kind:J(i),parentEventId:o.lastEventId,payload:i,producer:"cli",visibility:{...f.normal}}),o.lastEventId=a}this.#a=e.length,await this.#j(o)}async#j(e){let t=this.#S;if(t!==void 0)try{let s=t();if(typeof s!="string"||s==="")return;let n=x(e.sessionDir),o=JSON.parse(await ce(n,"utf8"));if(typeof o!="object"||o===null||Array.isArray(o))return;let i=o;if(i.platformSessionId===s)return;i.platformSessionId=s,await N(n,`${JSON.stringify(i,null,2)}
5
- `)}catch{}}async#J(e,t){let s=c();await e.writer.append({eventId:s,sessionId:this.#s,branchId:h,kind:"compact_boundary",parentEventId:e.lastEventId,payload:t,producer:"cli",visibility:{...f.internal}}),e.lastEventId=s}async#D(e,t){let s=c();await e.writer.append({eventId:s,sessionId:this.#s,branchId:h,kind:"event",parentEventId:e.lastEventId,payload:t,producer:"cli",visibility:{...f.internal}}),e.lastEventId=s}async#i(e,t){let s=c();await e.writer.append({eventId:s,sessionId:this.#s,branchId:h,kind:"event",parentEventId:e.lastEventId,payload:t,producer:"cli",visibility:{...f.internal}}),e.lastEventId=s}async#B(e,t,s){let n=c();await e.writer.append({eventId:n,sessionId:this.#s,branchId:h,kind:t,parentEventId:e.lastEventId,payload:s,producer:"cli",visibility:{...f.internal}}),e.lastEventId=n}async#G(e,t){let s=c();await e.writer.append({eventId:s,sessionId:this.#s,branchId:h,kind:"file_checkpoint",parentEventId:e.lastEventId,payload:t,producer:"cli",visibility:{...f.internal}}),e.lastEventId=s}async#K(e,t){let s={segmentation:this.#k};if(t===null)return I.open(e,s);try{return await I.openAt(e,t,s)}catch(n){if(n instanceof M&&n.code==="CURSOR_STALE")return I.open(e,s);throw n}}async#Q(e){if(this.#e!==null)return this.#e;let t=W(e),s=j(e),n=this.#m?.()??this.#h,o={model:n.model,provider:n.provider};t!==void 0&&(o.title=t),s!==void 0&&(o.firstUserMessage=s);let i=this.#l?.();i!==void 0&&(o.outputStyle=i);let{sessionDir:a}=await q({storageRoot:this.#u,sessionId:this.#s,cwd:this.#c,extra:o}),l,p=null,g=null;this.#t!==null?(l=this.#t,p=this.#E,g=this.#v,this.#t=null,this.#E=null,this.#I=null,this.#v=null):l=await O(a);let u;try{u=await this.#K(a,g)}catch(d){throw await l.release(),d}let y={writer:u,lock:l,lastEventId:p,sessionDir:a};if(this.#q(),u.nextSeq===0){let d={type:"session_meta",version:1,sessionId:this.#s,cwd:this.#c,startedAt:this.#g,provider:n.provider,model:n.model};t!==void 0&&(d.title=t),this.#y&&(d.usageReportingDisabled=!0);let _=c();try{await u.append({eventId:_,sessionId:this.#s,branchId:h,kind:"event",parentEventId:null,payload:d,producer:"cli",visibility:{...f.internal}})}catch(ie){throw await u.close(),await l.release(),ie}y.lastEventId=_}return this.#e=y,y}};async function ge(r){let e=i=>new S({storageRoot:r.storageRoot,sessionId:i,cwd:r.cwd,model:r.model,...r.outputStyle!==void 0?{outputStyle:r.outputStyle}:{},...r.usageReportingDisabled===!0?{usageReportingDisabled:!0}:{},...r.platformSessionId!==void 0?{platformSessionId:r.platformSessionId}:{},...r.onSinkError!==void 0?{onError:r.onSinkError}:{},...r.segmentation!==void 0?{segmentation:r.segmentation}:{}});if(r.resumeSessionId===void 0){let i=r.defaultSessionId??K();return{ok:!0,sessionId:i,sink:e(i),initialHistory:[]}}let t=await b(r.storageRoot,r.resumeSessionId);if(!t.ok)return t.reason==="not_found"?{ok:!1,key:m.resumeNotFound,params:{sessionId:r.resumeSessionId}}:{ok:!1,key:m.resumeFailed,params:{sessionId:r.resumeSessionId,message:t.detail}};let s=await k(r.storageRoot,{messages:t.messages,...t.compactBoundary!==void 0?{compactBoundary:t.compactBoundary}:{}}),n=s!==null&&s.length>0?{restoredTodos:s}:{};if(t.continuable&&t.lock!==void 0){let i=e(t.sessionId);return await i.adoptSession({sessionId:t.sessionId,lock:t.lock,persistedCount:t.journalMessageCount,lastEventId:t.lastEventId,lastSeq:t.lastSeq,cursor:t.cursor}),{ok:!0,sessionId:t.sessionId,sink:i,initialHistory:t.messages,...t.meta!==void 0?{meta:t.meta}:{},...n,resumedFromSeq:t.lastSeq,...t.lastEffectiveModel!==void 0?{lastEffectiveModel:t.lastEffectiveModel}:{},...t.usageSnapshot!==void 0?{usageSnapshot:t.usageSnapshot}:{}}}let o=K();return{ok:!0,sessionId:o,sink:e(o),initialHistory:t.messages,...t.meta!==void 0?{meta:t.meta}:{},...n,resumedFromSeq:t.lastSeq,...t.lastEffectiveModel!==void 0?{lastEffectiveModel:t.lastEffectiveModel}:{},...t.usageSnapshot!==void 0?{usageSnapshot:t.usageSnapshot}:{}}}import{createHash as ye}from"node:crypto";import{existsSync as Q}from"node:fs";import{chmod as Se,mkdir as Y,readFile as X,rename as Re,rm as V,stat as Ee,writeFile as $}from"node:fs/promises";import R from"node:path";var Z=1024*1024,ee="blobs",z=48;function P(r,e){return R.join(r,ee,e.slice(0,2),e.slice(2))}function Ie(r){let e=R.resolve(r);return/^[A-Za-z]:/.test(e)?e.charAt(0).toLowerCase()+e.slice(1):e}var T=class{#u;#c;#h;#m;#g;#l=[];#y=new Map;#S=new Map;#R=!1;constructor(e){this.#u=e.storageRoot,this.#c=e.appendRecord,this.#h=e.currentTurn,this.#m=e.maxBytes??Z,this.#g=e.onError}noteTurn(e,t){if(t===void 0)return;let s=t.replace(/\s+/g," ").trim();s!==""&&this.#S.set(e,s.length>z?`${s.slice(0,z)}…`:s)}async capture(e){let t=this.#h();for(let s of e){let n=R.resolve(s),o=Ie(n);if(this.#y.get(o)!==t)try{let i=await this.#k(n,o,t);if(i===null)continue;this.#l.push(i),this.#y.set(o,t),this.#c(this.#d(i))}catch(i){this.#P(i)}}}listRewindPoints(){let e=new Map;for(let t of this.#l){let s=e.get(t.turn);s===void 0?e.set(t.turn,{files:[t.path],capturedAt:t.capturedAt}):s.files.push(t.path)}return[...e.entries()].sort(([t],[s])=>s-t).map(([t,s])=>{let n=this.#S.get(t);return{turn:t,files:s.files,capturedAt:s.capturedAt,...n!==void 0?{label:n}:{}}})}affectedFiles(e){let t=new Set,s=[];for(let n of this.#l)n.turn<e||t.has(n.key)||(t.add(n.key),s.push(n.path));return s}async restoreToTurn(e){let t=new Map;for(let n of this.#l)n.turn<e||t.has(n.key)||t.set(n.key,n);let s={turn:e,restored:[],deleted:[],skipped:[],failed:[]};for(let n of t.values()){if(n.skipped){s.skipped.push({path:n.path,reason:"too_large"});continue}try{if(n.blobHash===null){await V(n.path,{force:!0}),s.deleted.push(n.path);continue}let o=await X(P(this.#u,n.blobHash));await Y(R.dirname(n.path),{recursive:!0}),await $(n.path,o);try{await Se(n.path,n.mode&511)}catch{}s.restored.push(n.path)}catch(o){s.failed.push({path:n.path,message:o instanceof Error?o.message:String(o)})}}return s}async#k(e,t,s){let n=Date.now(),o;try{o=await Ee(e)}catch(l){if(l.code==="ENOENT")return{key:t,path:e,turn:s,blobHash:null,mode:0,mtimeMs:0,bytes:0,capturedAt:n,skipped:!1};throw l}if(o.isDirectory())return null;if(o.size>this.#m)return{key:t,path:e,turn:s,blobHash:null,mode:o.mode,mtimeMs:o.mtimeMs,bytes:o.size,capturedAt:n,skipped:!0};let i=await X(e),a=ye("sha256").update(i).digest("hex");return await this.#p(a,i),{key:t,path:e,turn:s,blobHash:a,mode:o.mode,mtimeMs:o.mtimeMs,bytes:i.byteLength,capturedAt:n,skipped:!1}}async#p(e,t){let s=P(this.#u,e);if(Q(s))return;await Y(R.dirname(s),{recursive:!0});let n=`${s}.tmp-${process.pid}-${Date.now()}`;await $(n,t);try{await Re(n,s)}catch(o){if(await V(n,{force:!0}),!Q(s))throw o}}#d(e){return{path:e.path,blobHash:e.blobHash,mode:e.mode,mtimeMs:e.mtimeMs,turn:e.turn,bytes:e.bytes,capturedAt:e.capturedAt,...e.skipped?{skipped:!0}:{}}}#P(e){if(this.#R)return;this.#R=!0;let t=e instanceof Error?e.message:String(e);this.#g?.(E(m.checkpointFailed,{message:t}))}};var te=64,w=64,se=2e3,ve=["Turn the following user request into a short session title.","Requirements: at most 8 words; same language as the request;","reply with the title only - no quotes, no trailing punctuation, no explanations."].join(`
6
- `);function ne(r){for(let e of r){if(e.role!=="user")continue;let t=e.blocks.flatMap(s=>s.t==="text"?[s.text]:[]).join(" ").replace(/\s+/g," ").trim();if(t!=="")return t}}function re(r){let e=r.replace(/\s+/g," ").trim(),t=[['"','"'],["'","'"],["“","”"],["「","」"],["『","』"]];for(let[s,n]of t)if(e.length>s.length+n.length&&e.startsWith(s)&&e.endsWith(n)){e=e.slice(s.length,e.length-n.length).trim();break}if(e=e.replace(/[.。!!??…]+$/u,"").trim(),e!=="")return e.length>w?`${e.slice(0,w)}…`:e}function be(r,e){return e===void 0?r:e.aborted?(r.catch(()=>{}),Promise.resolve(void 0)):new Promise(t=>{let s=()=>{r.catch(()=>{}),t(void 0)};e.addEventListener("abort",s,{once:!0}),r.then(n=>{e.removeEventListener("abort",s),t(n)})})}async function oe(r){let e=r.text.slice(0,se),t={system:[],messages:[{role:"user",blocks:[{t:"text",text:`${ve}
7
-
8
- <request>
9
- ${e}
10
- </request>`}]}],tools:[],model:r.model,maxTokens:te,skipCacheWrite:!0,...r.thinkingOff===!0?{thinking:{off:!0}}:{}},s=L({observer:r.requestMeasurement,purpose:"title",face:{system:t.system,messages:t.messages,tools:t.tools},model:t.model}),n={...r.signal!==void 0?{signal:r.signal}:{},callMeta:{purpose:"title",...s!==void 0?{requestId:s.requestId}:{}}},o=r.client.stream(t,n),a=await be((async()=>{let l=[],p,g,u=!1;try{for await(let d of o){switch(d.t){case"block_start":d.block.t==="text"&&d.block.text.length>0&&l.push(d.block.text);break;case"text_delta":l.push(d.text);break;case"message_stop":p=d.usage,g=d.ttftMs,u=!0;break;case"error":s?.({outcome:"error",errorKind:d.kind});return;default:break}if(u)break}}catch{s?.({outcome:"error",errorKind:"exception"});return}finally{Promise.resolve(o.return(void 0)).catch(()=>{})}if(!u){s?.({outcome:"error",errorKind:"contract"});return}s?.({outcome:"success",...p!==void 0?{usage:p}:{},...g!==void 0?{ttftMs:g}:{},...l.length>0?{responseBlocks:[{t:"text",text:l.join("")}]}:{}});let y=re(l.join(""));if(y!==void 0)return{title:y,...p!==void 0?{usage:p}:{}}})(),r.signal);if(a===void 0||r.signal?.aborted===!0){s?.({outcome:"aborted",errorKind:"aborted"});return}return a}function ke(r,e){return{type:"cost.usage.updated",model:r.model,provider:r.provider,purpose:"title",usage:e}}function Pe(r){let e=!1,t=Promise.resolve(),s=new AbortController,n=async(o,i)=>{let a=r.modelTier();if(a===void 0)return;let l=await oe({client:a.client,model:a.model,...a.thinkingOff===!0?{thinkingOff:!0}:{},text:o,signal:s.signal,...r.requestMeasurement!==void 0?{requestMeasurement:r.requestMeasurement}:{}});if(l!==void 0&&(l.usage!==void 0&&r.onUsage?.(l.usage,a.model),!s.signal.aborted))try{await U(C(r.storageRoot,i),l.title)}catch{}};return{maybeGenerate(o){if(e||s.signal.aborted)return;let i=ne(o);if(i===void 0)return;e=!0;let a=r.currentSessionId();t=n(i,a).catch(()=>{})},suppress(){e=!0},idle(){return t},abort(){s.abort()}}}export{W as a,j as b,S as c,k as d,T as e,ke as f,Pe as g,ge as h};
11
- //# sourceMappingURL=tansr-chunk-M6XHWCMA.mjs.map
@@ -1,11 +0,0 @@
1
- import { createRequire as __tansrCreateRequire } from 'module';const require=__tansrCreateRequire(import.meta.url);
2
- import { fileURLToPath as __tansrFileURLToPath } from 'url';import { dirname as __tansrDirname } from 'path';
3
- const __filename=__tansrFileURLToPath(import.meta.url);const __dirname=__tansrDirname(__filename);
4
- import{D as be,G as Ae,ia as Ee,pa as re,wa as Q}from"./tansr-chunk-BX7CF5RQ.mjs";import{a as z,e as xe,f as ie,m as oe}from"./tansr-chunk-QHEQQ2JB.mjs";import{c as Se}from"./tansr-chunk-SJFDQLLC.mjs";import{B as ye,N as A,O as C,T as ve,k as W,s as ge}from"./tansr-chunk-I3TOVAA6.mjs";import{isDeepStrictEqual as _e,types as Oe}from"node:util";function Qe(i,x,S){let u=structuredClone(i),H=!0,O=!1,d;try{let I=S(i,()=>{if(!H||O)throw new Error("Archive governance publication is no longer available");if(O=!0,!_e(i,u))throw new Error("Archive governance candidate changed");return d=x(),d});if(Oe.isPromise(I)&&Promise.prototype.then.call(I,void 0,()=>{}),!O||d===void 0||I!==d||!_e(i,u))throw new Error("Archive governance commit must return its original synchronous publication");return I}finally{H=!1}}import{randomUUID as Te}from"node:crypto";import{closeSync as Be,lstatSync as Le,openSync as He,realpathSync as Me}from"node:fs";import{createRequire as Ne}from"node:module";import{resolve as Ie}from"node:path";import{types as qe}from"node:util";var se=class extends Error{constructor(S){super(`SDK2 host command: ${S}`);this.code=S}code},ke="sdk2-host-commands-v1",X={intent:0,"store-created":1,binding:2,ready:3},Pe=new Set;function c(i){throw new se(i)}function Z(i,x,S){(!Number.isSafeInteger(i)||Object.is(i,-0)||i<x||i>S)&&c("invalid_input")}function ae(i){let x=Me(i),S=Le(i,{bigint:!0});return(S.isSymbolicLink()||!S.isFile()||S.ino===0n||x!==Ie(i))&&c("identity_mismatch"),`${x}\0${S.dev}\0${S.ino}`}function st(i){Z(i.maxCommands,1,65536),Z(i.maxMetadataBytes,1024,67108864),Z(i.controlBytes,1024,262144),Z(i.maxDatabasePages,16,65536),i.mode!=="create"&&i.mode!=="reopen"&&c("invalid_input");let x=A({format:ke,identity:i.identity,maxCommands:i.maxCommands,maxMetadataBytes:i.maxMetadataBytes,controlBytes:i.controlBytes,maxDatabasePages:i.maxDatabasePages}),S=!1,u=!1,H=!1,O=!1,d=null,I=()=>{let t=i.assertAuthorized();qe.isPromise(t)&&W(t),t!==void 0&&c("invalid_input"),u&&c("reentrant")};I();let B=Ie(i.path);if(i.mode==="create"){let t=He(B,"wx",384);Be(t)}let G=ae(B);I();let{DatabaseSync:f}=Ne(import.meta.url)("node:sqlite"),a=new f(B),b=Te(),_=()=>{ae(B)!==G&&c("identity_mismatch"),I()},P=t=>{let e=A(t);return Buffer.byteLength(e)>i.controlBytes&&c("capacity_exceeded"),e},L=t=>{H&&c("closed"),S&&(u=!0,c("reentrant")),O&&c("reconciliation_required"),S=!0,u=!1;try{return _(),t()}finally{S=!1}},R=t=>{let e=a.prepare("SELECT * FROM host_command WHERE command_id=?").get(t);(!e||e.owner!==b)&&c("reconciliation_required");let m=e.stage;return(!Object.hasOwn(X,m)||typeof e.subject_key!="string"||typeof e.intent!="string"||!(e.binding===null||typeof e.binding=="string")||e.digest!==C(A({commandId:t,subjectKey:e.subject_key,intent:e.intent,stage:m,binding:e.binding})))&&c("identity_mismatch"),(Buffer.byteLength(e.intent)>i.controlBytes||Buffer.byteLength(e.binding??"")>i.controlBytes||e.bytes!==Buffer.byteLength(e.intent)+Buffer.byteLength(e.binding??""))&&c("identity_mismatch"),{commandId:t,subjectKey:e.subject_key,intent:e.intent,stage:m,binding:e.binding}},F=t=>{let e=a.prepare(`SELECT
5
- length(CAST(command_id AS BLOB)) AS command_size, length(CAST(subject_key AS BLOB)) AS subject_size,
6
- length(CAST(owner AS BLOB)) AS owner_size, length(CAST(stage AS BLOB)) AS stage_size,
7
- length(CAST(intent AS BLOB)) AS intent_size, length(CAST(binding AS BLOB)) AS binding_size,
8
- length(CAST(digest AS BLOB)) AS digest_size,
9
- CASE WHEN bytes BETWEEN 0 AND ? THEN bytes ELSE -1 END AS bytes
10
- FROM host_command WHERE subject_key=?`).get(i.maxMetadataBytes,t);if(!e)return null;let m=(y,q)=>typeof y=="number"&&Number.isSafeInteger(y)&&y>=0&&y<=q;(e.command_size!==67||e.subject_size!==64||e.owner_size!==36||e.digest_size!==64||!m(e.stage_size,13)||!m(e.intent_size,i.controlBytes)||!(e.binding_size===null||m(e.binding_size,i.controlBytes))||!m(e.bytes,i.maxMetadataBytes)||e.bytes!==e.intent_size+(e.binding_size??0))&&c("identity_mismatch");let o=a.prepare("SELECT command_id,subject_key,owner,intent,stage,binding,bytes,digest FROM host_command WHERE subject_key=?").get(t);(!o||o.subject_key!==t||typeof o.command_id!="string"||typeof o.intent!="string"||typeof o.owner!="string"||!/^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/.test(o.owner)||typeof o.stage!="string"||!Object.hasOwn(X,o.stage)||!(o.binding===null||typeof o.binding=="string"))&&c("identity_mismatch");let l={commandId:o.command_id,subjectKey:t,intent:o.intent,stage:o.stage,binding:o.binding};(o.command_id!==`hc-${C(t+"\0"+o.intent)}`||o.digest!==C(A(l))||o.bytes!==e.bytes||Buffer.byteLength(o.intent)!==e.intent_size||(o.binding===null?null:Buffer.byteLength(o.binding))!==e.binding_size||(l.stage==="binding"||l.stage==="ready")!=(l.binding!==null))&&c("identity_mismatch");try{(A(JSON.parse(l.intent))!==l.intent||l.binding!==null&&A(JSON.parse(l.binding))!==l.binding)&&c("identity_mismatch")}catch{c("identity_mismatch")}return Object.freeze(l)},M=(t,e)=>{d&&c("reconciliation_required"),a.exec("BEGIN IMMEDIATE");let m=!1;try{_();let o=e();return _(),m=!0,a.exec("COMMIT"),o}catch(o){try{a.exec("ROLLBACK")}catch{try{a.exec("BEGIN"),a.exec("ROLLBACK")}catch{O=!0}}throw m&&(d=t,c("commit_unknown")),o}},N=t=>{let e=Buffer.byteLength(t.intent)+Buffer.byteLength(t.binding??""),m=a.prepare("SELECT bytes FROM host_command WHERE command_id=?").get(t.commandId),o=a.prepare("SELECT records,bytes,digest FROM host_command_meta WHERE id=1").get(),l=Number(o.records),y=Number(o.bytes);(!Number.isSafeInteger(l)||!Number.isSafeInteger(y)||l<0||y<0||o.digest!==C(`${l}:${y}`))&&c("identity_mismatch");let q=l+(m?0:1),k=y+e-Number(m?.bytes??0);(!Number.isSafeInteger(k)||k<0||q>i.maxCommands||k>i.maxMetadataBytes)&&c("capacity_exceeded"),a.prepare("INSERT INTO host_command(command_id,subject_key,owner,intent,stage,binding,bytes,digest) VALUES(?,?,?,?,?,?,?,?) ON CONFLICT(command_id) DO UPDATE SET stage=excluded.stage,binding=excluded.binding,bytes=excluded.bytes,digest=excluded.digest").run(t.commandId,t.subjectKey,b,t.intent,t.stage,t.binding,e,C(A(t))),a.prepare("UPDATE host_command_meta SET records=?,bytes=?,digest=? WHERE id=1").run(q,k,C(`${q}:${k}`))};try{if(a.exec("PRAGMA journal_mode=DELETE; PRAGMA synchronous=FULL; PRAGMA foreign_keys=ON; PRAGMA temp_store=MEMORY; PRAGMA busy_timeout=0;"),i.mode==="create"&&a.exec("PRAGMA page_size=4096;"),(a.prepare("PRAGMA page_size").get()?.page_size!==4096||a.prepare(`PRAGMA max_page_count=${i.maxDatabasePages}`).get()?.max_page_count!==i.maxDatabasePages)&&c("capacity_exceeded"),i.mode==="create"){a.exec("BEGIN IMMEDIATE");try{a.exec("CREATE TABLE host_command_meta(id INTEGER PRIMARY KEY CHECK(id=1),config TEXT NOT NULL,records INTEGER NOT NULL CHECK(records>=0),bytes INTEGER NOT NULL CHECK(bytes>=0),digest TEXT NOT NULL) STRICT; CREATE TABLE host_command(command_id TEXT PRIMARY KEY,subject_key TEXT UNIQUE NOT NULL,owner TEXT NOT NULL,intent TEXT NOT NULL,stage TEXT NOT NULL,binding TEXT,bytes INTEGER NOT NULL CHECK(bytes>=0),digest TEXT NOT NULL) STRICT;"),a.prepare("INSERT INTO host_command_meta(id,config,records,bytes,digest) VALUES(1,?,0,0,?)").run(x,C("0:0")),_(),a.exec("COMMIT")}catch(t){try{a.exec("ROLLBACK")}catch{}throw t}}else{let t=a.prepare("SELECT * FROM host_command_meta WHERE id=1").get();(!t||t.config!==x)&&c("identity_mismatch");let e=a.prepare("SELECT count(*) AS records,coalesce(sum(bytes),0) AS bytes FROM host_command").get();(e.records!==t.records||e.bytes!==t.bytes||Number(e.records)>i.maxCommands||Number(e.bytes)>i.maxMetadataBytes||t.digest!==C(`${e.records}:${e.bytes}`))&&c("identity_mismatch")}_()}catch(t){try{a.close()}catch(e){throw Pe.add(a),new AggregateError([t,e],"Host command journal retains unclosed database")}throw t}return{begin(t,e){return L(()=>{/^[a-f0-9]{64}$/.test(t)||c("invalid_input");let m=P(e),o=`hc-${C(t+"\0"+m)}`;d&&d!==o&&c("reconciliation_required");let l=a.prepare("SELECT command_id FROM host_command WHERE subject_key=?").get(t);if(l){l.command_id!==o&&c("operation_conflict");let y=R(o);return _(),y.intent!==m&&c("operation_conflict"),d=null,y}return d===o&&(d=null),M(o,()=>{let y={commandId:o,subjectKey:t,intent:m,stage:"intent",binding:null};return N(y),y})})},advance(t,e,m){return L(()=>{d&&d!==t&&c("reconciliation_required");let o=R(t),l=m===void 0?o.binding:P(m);return(!Object.hasOwn(X,e)||e==="binding"&&l===null||m!==void 0&&e!=="binding"||o.binding!==null&&l!==o.binding)&&c("operation_conflict"),_(),d=null,o.stage===e?o:(X[e]!==X[o.stage]+1&&c("operation_conflict"),M(t,()=>{let y={...o,stage:e,binding:l};return N(y),y}))})},read(t){return L(()=>{d&&d!==t&&c("reconciliation_required");let e=R(t);return _(),d=null,e})},lookup(t){return L(()=>{(typeof t!="string"||!/^[a-f0-9]{64}$/.test(t))&&c("invalid_input"),d&&c("reconciliation_required"),a.exec("BEGIN");let e=!1;try{let m=F(t);return a.exec("ROLLBACK"),e=!0,_(),ae(B)!==G&&c("identity_mismatch"),m}catch(m){if(!e)try{a.exec("ROLLBACK")}catch{try{a.exec("BEGIN"),a.exec("ROLLBACK")}catch{O=!0}}throw m}})},close(){H||(S&&(u=!0,c("reentrant")),_(),a.close(),H=!0)}}}async function je(i){let{openSqliteEventStore:x}=await import("./tansr-sqlite-event-store-UQLSSZKP.mjs");return x(i)}import{types as ce}from"node:util";var de=new WeakMap,ee=(i,x)=>A(i)===A(x);function g(i="reconciliation_required"){throw new z(i)}function De(i){let x=ie(i.maxQueuedOperations,1,65536),S=ie(i.maxSubscriptions,1,4096),u=Object.freeze({...i.installation,slot:Object.freeze({...i.installation.slot})}),{source:H,materials:O,eventStore:d,readAuthority:I,retiredRecovery:B}=i;(typeof I!="function"||ce.isProxy(I))&&g("invalid_input");let G=A(u.slot),f="new",a,b,_,P,L,R,F=!1,M=!1,N=!1,t=!1,e=!1,m,o,l=[],y=new Set,q="",k="",le=null,me=new Map,pe=new Set,ue=r=>A([r.materialRequestId,r.revision]),U=()=>{if((M||t)&&(N=!0,e=!0,g("invalid_input")),f==="failed")throw a;f==="closed"&&g("unavailable")},Re=()=>{M&&(N=!0,g("invalid_input")),M=!0,N=!1;try{let r=I();ce.isPromise(r)&&(W(r),g("invalid_input"));let s=ve(r);return N&&g("invalid_input"),s}finally{M=!1}},fe=r=>{let s=Re(),n=u.control.read(),p=B===void 0?re(u):Ee(B,{spool:u.spool,slot:u.slot,storeIdentity:u.storeIdentity,ownerEpoch:u.ownerEpoch,sessionId:n?.registration.sessionId??""}),h=Q(u.spool,u.slot),v=Ae(p.guard);(!n||n.state==="unbound"||!h||h.ready===null&&v.phase!=="retired"||r&&!(v.phase==="installed"&&v.hasRuntime||v.phase==="retiring"&&v.hasRuntime&&n.state==="closing"||B!==void 0&&v.phase==="retired"&&!v.hasRuntime&&n.state==="closed")||!r&&!["installed","retiring","retired"].includes(v.phase))&&g();let E=h.plan;if((p.physicalPairDigest!==E.physicalPairDigest||p.ownerRootDigest!==E.ownerRootDigest||s.scope.applicationScopeId!==E.scope.applicationScopeId||s.scope.endUserId!==E.scope.endUserId||s.target.sessionId!==E.sessionId||P!==void 0&&P!==E.installationId)&&g("identity_mismatch"),v.phase==="retired"){let w=be({spool:u.spool,control:u.control,slot:u.slot}),T=w.retirement?.record;(n.state!=="closed"||w.writeBarrier!=="clear"||!ee(w.current,n)||!T||T.installationId!==E.installationId||T.ownerRootDigest!==p.ownerRootDigest||T.physicalPairDigest!==p.physicalPairDigest||!ee(T.finalTarget,n.target)||h.ready===null&&T.installedRecordDigest!==null)&&g()}else v.hasRuntime||g();return{view:Se({...E.createResponse,scope:s.scope,target:n.target,revision:n.revision,state:n.state,acceptedCapabilities:n.acceptedCapabilities,archiveAckFormat:n.archiveAckFormat,operationEpoch:n.epoch.active&&s.nowMs<n.epoch.expiresAtMs?{id:n.epoch.id,issuedAt:new Date(n.epoch.issuedAtMs).toISOString(),expiresAt:new Date(n.epoch.expiresAtMs).toISOString(),state:"active"}:null}),plan:E}},te=(r,s)=>{t=!0,e=!1;try{let n=ye({spool:u.spool,source:H,materials:O,...s?{materialOperation:s}:{}},()=>fe(r)),{view:p,plan:h}=n.binding;return(n.archive.bindingId!==h.bindingId||n.archive.sourceId!==h.sourceId||n.archive.sourceGeneration!==h.sourceGeneration||n.archive.revision!==p.revision||!ee(n.archive.generations,p.target.generations)||n.archive.state!==p.state||h.materialBindingId!==null!=(O!==void 0))&&g("identity_mismatch"),e&&g("invalid_input"),n}finally{t=!1}},J=()=>{for(let r of y)r.wake()},$=(r,s)=>{f==="closed"||f==="failed"||(a=r,f="failed",l.length=0,R?.close(),R=void 0,o=s,J(),V())},j=()=>{U(),t=!0,e=!1;try{fe(!1),e&&g("invalid_input")}catch(r){throw $(r,"notification-failure"),r}finally{t=!1}},he=(r,s)=>{let{view:n}=r.binding,p={revision:n.revision,generations:n.target.generations},h=[];!s&&r.archive.publishedThroughSequence!==null&&r.archive.publishedThroughSequence!==le&&h.push({...p,eventType:"archive.records-available",payload:{publishedThroughSequence:r.archive.publishedThroughSequence}}),(s||A(r.archive)!==q)&&h.push({...p,eventType:"archive.status",payload:r.archive}),(s||A(n)!==k)&&h.push({...p,eventType:"binding.status",payload:n});for(let v of r.requests)(s||me.get(v.request.materialRequestId)!==A(v))&&h.push({...p,eventType:"material.request",payload:v.request,issuedAtMs:v.issuedAtMs,deadlineMs:v.deadlineMs});return!s&&r.material&&!pe.has(ue(r.material))&&h.push({...p,eventType:"material.status",payload:r.material}),h},we=r=>{q=A(r.archive),k=A(r.binding.view),le=r.archive.publishedThroughSequence,me=new Map(r.requests.map(s=>[s.request.materialRequestId,A(s)])),r.material&&pe.add(ue(r.material))},ne=(r,s)=>{let n=d.head(b),p=n.state==="rebuilding";L!==void 0&&L!==n.generation&&!p&&g("stream_cursor_expired");let h=he(r,s||p);if(h.length){let v={generation:n.generation,after:n.head,drafts:h};if(p){let E=d.activate(b,v),D=s?[]:he(r,!1).filter(w=>w.eventType==="material.status");D.length&&d.append(b,{generation:n.generation,after:E.last,drafts:D})}else d.append(b,v)}if(f==="failed"||f==="closed")throw a??new z("unavailable");return j(),L=n.generation,we(r),J(),r.binding.view.state==="closed"&&(f="ended",R?.close(),R=void 0,l.length=0,J()),{generation:n.generation,after:n.head}};function V(){m||(m=Promise.resolve().then(()=>{if(o&&b){let r=o;o=void 0,d.retire(b,r)}for(;f==="ready"&&l.length;){let r=l.shift(),s=Q(u.spool,u.slot),n=r.state==="committed"&&r.operation?.bindingId===s?.plan.materialBindingId?r.operation??void 0:void 0;if(!n)for(;l.length&&!(l[0].state==="committed"&&l[0].operation?.bindingId===s?.plan.materialBindingId);)l.shift();ne(te(!1,n),!1)}}).catch(r=>{$(r,"notification-failure")}).finally(()=>{if(m=void 0,o&&b){let r=o;o=void 0;try{d.retire(b,r)}catch(s){a=new AggregateError([a,s],"SDK2 event retirement requires reconciliation")}}J(),f==="ready"&&l.length&&V()}))}return{start:async()=>{if(U(),!(f==="ready"||f==="ended")){f!=="new"&&g("unavailable"),f="starting";try{let r=de.get(u.spool)??new Set;r.has(G)&&g("owner_busy"),r.add(G),de.set(u.spool,r),F=!0,R=ge(u.spool,{committed(p){if(["starting","ready"].includes(f)){if(l.length>=x){$(new z("capacity_exceeded"),"notification-failure");return}l.push(p),V()}},retired(p){$(new z("reconciliation_required"),p)}});let s=te(!0),n=s.binding.plan;P=n.installationId,_=oe({applicationScopeId:n.scope.applicationScopeId,endUserId:n.scope.endUserId,bindingId:n.bindingId}),b=d.ensureStream({scope:_,installationId:P,limits:{eventRetentionMs:n.createResponse.limits.eventRetentionMs,eventRetentionFrames:n.createResponse.limits.eventRetentionFrames,eventRetentionBytes:n.createResponse.limits.eventRetentionBytes}}),d.head(b).state==="ready"&&d.retire(b,"notification-failure"),L=d.head(b).generation,ne(s,!0),f==="starting"&&(f="ready"),V()}catch(r){throw $(r,"notification-failure"),r}}},flush:async()=>{for(U(),(f==="new"||f==="starting")&&g("unavailable");m;)await m;U()},open:async r=>{j(),f!=="ready"&&f!=="ended"&&g("unavailable");let s=xe(r,["scope","signal"],["lastEventId"]);ee(oe(s.scope),_)||g("identity_mismatch");let n=s.signal;(!(n instanceof AbortSignal)||ce.isProxy(n))&&g("invalid_input"),n.throwIfAborted(),y.size>=S&&g("capacity_exceeded");let p=s.lastEventId===void 0?ne(te(!1),!0):d.inspectCursor(b,s.lastEventId);j(),n.throwIfAborted();let h=!1,v=!1,E,D,w=()=>{h=!0,E=void 0,n.removeEventListener("abort",w),y.delete(T),T.wake()},T={close:w,wake(){D?.(),D=void 0}};return y.add(T),n.addEventListener("abort",w,{once:!0}),n.aborted&&w(),{async next(){U(),(v||E)&&g("invalid_input"),v=!0;try{for(;!h;){if(j(),h||n.aborted)return null;let Y=d.head(b),K=d.readPage(b,{generation:p.generation,after:p.after,through:Y.head,maxFrames:1,maxBytes:262317});if(j(),h||n.aborted)return null;if(K.refs.length)return p={generation:p.generation,after:K.after},E=K.refs[0],E;if(f==="ended")return null;await new Promise(Ce=>{D=Ce})}return null}finally{v=!1}},encodeForSend(Y){j(),(h||n.aborted||Y!==E)&&g("identity_mismatch");let K=d.encodeForSend(Y);return j(),(h||n.aborted)&&g("identity_mismatch"),E=void 0,K.sse},close:w}},close:async()=>{if((M||t)&&(N=!0,e=!0,g("invalid_input")),!(f==="closed"&&!F)){R?.close(),R=void 0,l.length=0,f="closed";for(let r of[...y])r.close();m&&await m;try{b&&d.retire(b,"closed")}finally{F&&(de.get(u.spool)?.delete(G),F=!1)}}}}}export{Qe as a,st as b,je as c,De as d};
11
- //# sourceMappingURL=tansr-chunk-MWHLITGY.mjs.map
@@ -1,5 +0,0 @@
1
- import { createRequire as __tansrCreateRequire } from 'module';const require=__tansrCreateRequire(import.meta.url);
2
- import { fileURLToPath as __tansrFileURLToPath } from 'url';import { dirname as __tansrDirname } from 'path';
3
- const __filename=__tansrFileURLToPath(import.meta.url);const __dirname=__tansrDirname(__filename);
4
- import{Ta as c,cf as p}from"./tansr-chunk-IZICOKKF.mjs";import{m as s}from"./tansr-chunk-NA22YT73.mjs";import{Ib as l}from"./tansr-chunk-QWGSXFEJ.mjs";function A(a){let g=a.fetchImpl??fetch;return r=>{let t=r.challenge,n=c(r.call.args),o=`/v1/approvals/${t.id}/credential`,i=r.gate.adjudication,h={kind:"tansr.approval.challenge",challengeId:t.id,digest:t.digest,policyAnchor:t.policyAnchor,createdAt:t.createdAt,expiresAt:t.expiresAt,tool:{name:r.call.name,...n!==void 0?{summary:n}:{}},attribution:{decision:r.gate.decision,source:r.gate.source,...r.gate.matchedRule!==void 0?{matchedRule:r.gate.matchedRule}:{},...r.gate.sourceLayer!==void 0?{sourceLayer:r.gate.sourceLayer}:{}},...i!==void 0?{adjudication:{childAgentId:i.childAgentId,childDescription:i.childDescription,endorsed:i.endorsed,chain:i.chain.map(e=>({adjudicator:e.adjudicator,verdict:e.verdict,reason:e.reason,via:e.via,elapsedMs:e.elapsedMs}))}}:{},...r.session!==void 0?{session:r.session}:{},credential:{method:"POST",path:o,...a.credentialBaseUrl!==void 0?{url:`${a.credentialBaseUrl.replace(/\/+$/,"")}${o}`}:{}}},d=e=>{a.coordinator.cancel(t.id),a.onError?.(s(p.approvalPublishFailed,{challengeId:t.id,message:e}))};g(a.endpoint,{method:"POST",headers:{"content-type":"application/json",...a.token!==void 0?{authorization:`Bearer ${a.token}`}:{}},body:JSON.stringify(l(h))}).then(e=>{e.ok||d(`HTTP ${e.status}`)}).catch(e=>{d(e instanceof Error?e.message:String(e))})}}export{A as a};
5
- //# sourceMappingURL=tansr-chunk-N3R2URKL.mjs.map