@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,35 +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 P,b as q}from"./tansr-chunk-AMMPDY4V.mjs";import{i as pe,j as me}from"./tansr-chunk-QUFHVA3F.mjs";import{$ as ie,$a as fe,Pa as ue,Xa as le,_a as ce,ca as ae,da as de,ef as f,ff as ge}from"./tansr-chunk-IZICOKKF.mjs";import{f as oe,m}from"./tansr-chunk-NA22YT73.mjs";import{Eb as se,Fb as Y,Y as W}from"./tansr-chunk-QWGSXFEJ.mjs";import{a as Oe}from"./tansr-chunk-RRAMVVYF.mjs";var L={requestCompleted:"request.completed",requestUnhandled:"request.unhandled",executionRejected:"execution.rejected",executionResult:"execution.result",logRepeated:"log.repeated",logOverflow:"log.overflow",sessionCreated:"session.created",sessionEnded:"session.ended",sessionRejected:"session.rejected",sessionIdHintIgnored:"session.id_hint_ignored",sseOpened:"sse.opened",sseClosed:"sse.closed",storeCommitFailed:"store.commit_failed",storeCreateFailed:"store.create_failed",storeError:"store.error",upstreamRejected:"upstream.rejected",storeSegmentSealed:"store.segment_sealed",storeSegmentCommitted:"store.segment_committed",storeHotFull:"store.hot_full",storeHotRecovered:"store.hot_recovered",storeEvicted:"store.evicted",storeOrphanGc:"store.orphan_gc",sessionRetentionSwept:"session.retention_swept",bridgePermissionReceipt:"bridge.permission_receipt",notifyDeliveryFailed:"notify.delivery_failed",platformWarning:"platform.warning",admissionRejected:"admission.rejected",serverListening:"server.listening",serverClosed:"server.closed",serverDraining:"server.draining",serverCloseTimeout:"server.close_timeout",processUnhandledRejection:"process.unhandled_rejection",processUncaughtException:"process.uncaught_exception",processDrainFailed:"process.drain_failed",processHardExit:"process.hard_exit",serverDeprecatedOption:"server.deprecated_option",apiLegacyPrefixMixed:"api.legacy_prefix_mixed",apiLegacyPrefixRejected:"api.legacy_prefix_rejected"},cr=Object.values(L);var ye={debug:0,info:1,warn:2,error:3},Me=/^(prompt|messages?|content|body|args|stdout|stderr|requestBody|responseBody)$/i;function xe(r){let e=128,t=(n,i,u="")=>{if(se.test(u)||Me.test(u)&&u!=="message")return"[redacted]";if(--e<0||i>4)return"[truncated]";if(typeof n=="string")return n.length>4096?"[oversized]":Y(n).slice(0,1024);if(n==null||typeof n=="boolean"||typeof n=="number")return n;if(typeof n!="object")return"[unsupported]";let p=Array.isArray(n);if(p&&Object.getOwnPropertyDescriptor(n,"length")?.value>32)return"[oversized]";let c=p?[]:{};for(let s of Object.keys(n).slice(0,32)){let d=Object.getOwnPropertyDescriptor(n,s),l=d&&"value"in d?t(d.value,i+1,s):"[accessor]";Object.defineProperty(c,s.slice(0,128),{value:l,enumerable:!0,configurable:!0})}return c},o=t(r,0);return Buffer.byteLength(JSON.stringify(o))<=8192?o:{fields:"[oversized]",...Object.fromEntries(["endUserId","sessionId","code","reason","count"].filter(n=>typeof o[n]=="string"||typeof o[n]=="number").map(n=>[n,o[n]]))}}function mr(r,e={}){let t=e.level??"warn",o=e.now??Date.now,n=new Map,i=o(),u=0,p=0,c=V(r),s=()=>{for(let l of n.values())l.suppressed&&(c(l.level,"log.repeated",{...l.fields,originalEvent:l.event,suppressed:l.suppressed,windowMs:1e4}),l.suppressed=0);p&&(c("warn","log.overflow",{suppressed:p,maxGroups:128,windowMs:1e4}),p=0)},d=(l,v,y={},g)=>{try{let _=o();if(_-i>=1e4&&(s(),n.clear(),u=0,i=_),v==="server.closed"&&s(),ye[l]<ye[t])return;let S=xe(y),E=Object.fromEntries(["endUserId","code","reason"].filter(k=>typeof S[k]=="string").map(k=>[k,S[k]])),h=/^[a-z][a-z0-9_.]{0,127}$/.test(v)?v:"host.event",b=JSON.stringify([l,h,E]),x=n.get(b);if(!x){if(n.size>=128){p++;return}x={level:l,event:h,fields:E,sent:0,suppressed:0},n.set(b,x)}if(x.sent>=4||u>=64){x.suppressed++;return}x.sent++,u++,c(l,h,S,g)}catch{}};return{info:l=>d("info","host.info",{message:l},l),error:l=>d("error","host.error",{message:l},l),log:d,flush:s}}function j(r){return r instanceof Error?r.message:String(r)}function Ae(r,e,t){let o;try{o=JSON.stringify({level:r,event:e,...t??{}})}catch{o=JSON.stringify({level:r,event:e,fields:"[unserializable]"})}return o}function V(r){return(e,t,o,n)=>{if(r!==void 0)try{let i=xe(o??{}),u=n===void 0?void 0:n.length>4096?"[oversized]":Y(n);if(typeof r.log=="function"){r.log(e,t,i,u);return}let p=u??Ae(e,t,i);e==="error"||e==="warn"?r.error(p):r.info(p)}catch{}}}var z={unauthorized:"server.error.unauthorized",notFound:"server.error.not_found",sessionNotFound:"server.error.session_not_found",methodNotAllowed:"server.error.method_not_allowed",invalidJson:"server.error.invalid_json",invalidBody:"server.error.invalid_body",promptRequired:"server.error.prompt_required",bodyTooLarge:"server.error.body_too_large",invalidLastEventId:"server.error.invalid_last_event_id",sessionEnded:"server.error.session_ended",createFailed:"server.error.create_failed",approvalInvalidBody:"server.error.approval_invalid_body",approvalRejected:"server.error.approval_rejected",listening:"server.log.listening",closed:"server.log.closed",internalError:"server.error.internal_error",requestUnhandled:"server.log.request_unhandled",processFatal:"server.log.process_fatal",draining:"server.error.draining",v2Forbidden:"server.v2.error.forbidden",v2ValidationFailed:"server.v2.error.validation_failed",v2PayloadTooLarge:"server.v2.error.payload_too_large",v2SessionLimit:"server.v2.error.session_limit",v2ResumeUnavailable:"server.v2.error.resume_unavailable",v2MidturnBlocks:"server.v2.error.midturn_blocks",v2ReceiptRejected:"server.v2.error.receipt_rejected",v2StoreCorrupted:"server.v2.error.store_corrupted",v2CreateFailed:"server.v2.error.create_failed",v2UpstreamUnavailable:"server.v2.error.upstream_unavailable",v2NotifyFailed:"server.v2.log.notify_failed",rateLimited:"server.error.rate_limited",overloaded:"server.error.overloaded",materialRequired:"kernel.context.material_required",admissionRejected:"server.log.admission_rejected",drainStarted:"server.log.draining",drained:"server.log.drained",upstreamUnavailable:"server.error.upstream_unavailable",v2PlatformCapabilityDisabled:"server.v2.error.platform_capability_disabled",v2PlatformUnavailable:"server.v2.error.platform_unavailable",v2PlatformAudioRejected:"server.v2.error.platform_audio_rejected",v2PlatformAudioUnexpected:"server.v2.error.platform_audio_unexpected",v2PlanConcurrencyLimited:"server.v2.error.plan_concurrency_limited",v2PlanDenied:"server.v2.error.plan_denied"},yr=Object.values(z);var br=["log","drain-exit"],He=2048,Fe=1e4;function je(r,e,t){let o=r instanceof Error&&typeof r.stack=="string"?r.stack:void 0;return{origin:e,message:j(r),stack:o===void 0?void 0:o.slice(0,He),policy:t}}function Q(r){let e=r.target??process,t=r.exit??(d=>process.exit(d)),o=r.drainTimeoutMs??Fe,n=V(r.logger),i=!1,u=(d,l)=>{let v=je(d,l,r.onFatal);n("error",l==="unhandledRejection"?L.processUnhandledRejection:L.processUncaughtException,{...v},m(z.processFatal,{origin:l,policy:r.onFatal,message:v.message})),!(r.onFatal!=="drain-exit"||i)&&(i=!0,p())},p=()=>{let d=!1,l=()=>{d||(d=!0,clearTimeout(v),t(1))},v=setTimeout(l,o);if(v.unref?.(),r.drain===void 0){l();return}let y;try{y=r.drain()}catch(g){n("error",L.processDrainFailed,{message:j(g)}),l();return}y.then(l,g=>{n("error",L.processDrainFailed,{message:j(g)}),l()})},c=d=>u(d,"unhandledRejection"),s=d=>u(d,"uncaughtException");return e.on("unhandledRejection",c),e.on("uncaughtException",s),()=>{e.off("unhandledRejection",c),e.off("uncaughtException",s)}}var Ne=["SIGINT","SIGTERM","SIGHUP","SIGBREAK"],$={secondSignal:"cli.process.hard_exit.second_signal",drainTimeout:"cli.process.hard_exit.drain_timeout",invalidBudget:"cli.process.invalid_budget"},De=3e3,Ue=P.aborted;function ve(r){switch(r){case"SIGHUP":return"hangup";case"SIGINT":case"SIGBREAK":return"interrupt";default:return"terminate"}}function Ge(r=process,e=Ne){return t=>{let o=n=>{t(typeof n=="string"?n:e[0])};for(let n of e)r.on(n,o);return()=>{for(let n of e)r.removeListener(n,o)}}}var Be={setTimeout:(r,e)=>{let t=setTimeout(r,e);return t.unref(),t},clearTimeout:r=>{clearTimeout(r)}};function Se(r,e){if(typeof e!="number"||!Number.isFinite(e)||e<=0)throw new TypeError(m($.invalidBudget,{name:r,value:String(e)}))}function he(r){Se("hardExitAfterMs",r.hardExitAfterMs),r.hangupBudgetMs!==void 0&&Se("hangupBudgetMs",r.hangupBudgetMs);let e=r.timers??Be,t=r.now??Date.now,o=r.exit??(g=>{process.exit(g)}),n=r.exitCode??Ue,i=Math.min(r.hardExitAfterMs,r.hangupBudgetMs??De),u="idle",p=null,c=0,s=null,d=()=>{},l=()=>{s!==null&&(e.clearTimeout(s),s=null)},v=(g,_)=>{if(u==="exiting"||u==="disposed"||p===null)return;u="exiting",l(),d();let S={signal:_,reason:g,budgetMs:p.budgetMs,elapsedMs:Math.max(0,t()-c),exitCode:n};try{r.onHardExit?.(S)}catch{}o(n)},y=g=>{if(u==="disposed"||u==="exiting")return;if(u==="draining"){let h={signal:g,kind:ve(g),budgetMs:p?.budgetMs??r.hardExitAfterMs};try{r.onSecondSignal?.(h)}catch{}v("second_signal",g);return}let _=ve(g),S=_==="hangup"?i:r.hardExitAfterMs;p={signal:g,kind:_,budgetMs:S},c=t(),u="draining",s=e.setTimeout(()=>{s=null,v("drain_timeout",g)},S);let E;try{E=r.drain(p)}catch(h){r.onDrainError?.(h,p);return}if(E!==null&&typeof E=="object"&&typeof E.then=="function"){let h=p;Promise.resolve(E).then(void 0,b=>{r.onDrainError?.(b,h)})}};return d=(r.signalSource??Ge())(g=>{y(g??"SIGINT")}),{get state(){return u},get signal(){return p?.signal??null},request(g){y(g??"SIGINT")},dispose(){u!=="disposed"&&(u="disposed",l(),d())}}}function Ee(r,e={}){let t=n=>{try{r.write(n)}catch{}},o=e.log??((n,i)=>{t(JSON.stringify({event:n,...i})+`
5
- `)});return{onSecondSignal(n){t(m($.secondSignal,{signal:n.signal})+`
6
- `)},onHardExit(n){n.reason==="drain_timeout"&&t(m($.drainTimeout,{signal:n.signal,ms:n.budgetMs})+`
7
- `);try{o(L.processHardExit,{signal:n.signal,reason:n.reason,budgetMs:n.budgetMs,elapsedMs:n.elapsedMs,exitCode:n.exitCode})}catch{}}}}var N=["text","json","stream-json"];var Ke={"-p":"prompt","--prompt":"prompt","--max-turns":"maxTurns","--model":"model","--lang":"lang","--resume":"resume","--max-budget-usd":"maxBudgetUsd","--output-format":"outputFormat","--input-format":"inputFormat","--permission-mode":"permissionMode","--allowedTools":"allowedTools","--disallowedTools":"disallowedTools","--effort":"effort","--output-style":"outputStyle","--context-scheme":"contextScheme","--sessions-dir":"sessionsDir","--checkpoints-dir":"checkpointsDir","--cwd":"cwd","--restore":"restore"},Je={"--json":"json","--verbose":"verbose","--continue":"continueSession","--cc-compat":"ccCompat","--bg":"bg","--trust-project-hooks":"trustProjectHooks"};function R(r,e){return{ok:!1,error:e?{key:r,params:e}:{key:r}}}function qe(r){if(!/^\d+$/.test(r))return;let e=Number(r);return Number.isSafeInteger(e)&&e>0?e:void 0}function We(r){if(!/^\d+(\.\d+)?$/.test(r))return;let e=Number(r);return Number.isFinite(e)&&e>0?e:void 0}function Ye(r){let e=r.split(",").map(t=>t.trim()).filter(t=>t!=="");if(e.length===0)return{ok:!1,bad:r};for(let t of e)if(ue(t)===null)return{ok:!1,bad:t};return{ok:!0,rules:e}}function M(r){return r.outputFormat??(r.json?"stream-json":"text")}function X(r){if(r.inputFormat==="ndjson"&&(!r.prompt?.trim()||M(r)!=="stream-json"||r.ccCompat||r.bg))return{key:f.ndjsonRequirements}}function be(r){let e={json:!1};for(let o=0;o<r.length;o++){let n=r[o],i=n,u;if(n.startsWith("--")){let s=n.indexOf("=");s!==-1&&(i=n.slice(0,s),u=n.slice(s+1))}let p=Je[i];if(p!==void 0){if(u!==void 0)return R(f.noValueAllowed,{flag:i});e[p]=!0;continue}if(i==="-w"||i==="--worktree"){let s;if(u!==void 0)s=u;else{let d=r[o+1];d!==void 0&&!(d.startsWith("-")&&d!=="-")&&(s=d,o++)}e.worktree=s!==void 0?{name:s}:{};continue}let c=Ke[i];if(c!==void 0){let s;if(u!==void 0)s=u;else{let d=r[o+1];if(d===void 0||d.startsWith("-")&&d!=="-")return R(f.missingValue,{flag:i});s=d,o++}if(c==="maxTurns"){let d=qe(s);if(d===void 0)return R(f.invalidNumber,{flag:i,value:s});e.maxTurns=d}else if(c==="maxBudgetUsd"){let d=We(s);if(d===void 0)return R(f.invalidNumber,{flag:i,value:s});e.maxBudgetUsd=d}else if(c==="inputFormat"){if(s!=="text"&&s!=="ndjson")return R(f.invalidChoice,{flag:i,value:s,expected:"text|ndjson"});e.inputFormat=s}else if(c==="outputFormat"){if(!N.includes(s))return R(f.invalidChoice,{flag:i,value:s,expected:N.join("|")});e.outputFormat=s}else if(c==="permissionMode"){if(!W.includes(s))return R(f.invalidChoice,{flag:i,value:s,expected:W.join("|")});e.permissionMode=s}else if(c==="effort"){let d=me(s);if(d===void 0)return R(f.invalidChoice,{flag:i,value:s,expected:pe.join("|")});e.effort=d}else if(c==="allowedTools"||c==="disallowedTools"){let d=Ye(s);if(!d.ok)return R(f.invalidRule,{flag:i,rule:d.bad});e[c]=[...e[c]??[],...d.rules]}else e[c]=s;continue}return n.startsWith("-")&&n!=="-"?R(f.unknownFlag,{flag:i}):R(f.unexpectedArg,{arg:n})}let t=X(e);return t!==void 0?{ok:!1,error:t}:e.continueSession===!0&&e.resume!==void 0?R(f.conflictingFlags,{a:"--continue",b:"--resume"}):e.ccCompat===!0&&M(e)!=="stream-json"?R(f.ccCompatRequiresStreamJson):e.bg===!0&&e.prompt===void 0?R(f.bgRequiresPrompt):e.cwd!==void 0&&e.worktree!==void 0?R(f.conflictingFlags,{a:"--cwd",b:"-w/--worktree"}):{ok:!0,options:e}}function Ve(r){let e=[];for(let t=0;t<r.length;t++){let o=r[t];if(o!=="--bg"){if(o==="-w"||o==="--worktree"||o==="--cwd"){let n=r[t+1];n!==void 0&&!(n.startsWith("-")&&n!=="-")&&t++;continue}o.startsWith("--worktree=")||o.startsWith("--cwd=")||e.push(o)}}return e}function ze(r=process.stdin){return{controlStream:r,isTTY:r.isTTY===!0,readAll:()=>_e(r)}}async function _e(r){let e=[];for await(let t of r)e.push(typeof t=="string"?Buffer.from(t,"utf8"):t);return Buffer.concat(e).toString("utf8")}async function Z(r,e){let t=r.prompt,o=!e.isTTY;if(t!==void 0&&t!==""){if(!o)return{ok:!0,prompt:t};let n=(await e.readAll()).trim();return n===""?{ok:!0,prompt:t}:{ok:!0,prompt:`${t}
8
-
9
- ${n}`}}if(o){let n=(await e.readAll()).trim();if(n!=="")return{ok:!0,prompt:n}}return{ok:!1,error:{key:f.missingPrompt}}}import{randomUUID as Ze}from"node:crypto";var D=class{#s=new TextDecoder("utf-8");#e;#t="";#r=!1;#n=0;constructor(e=8388608){this.#e=e}get droppedLines(){return this.#n}push(e){let t=typeof e=="string"?e:this.#s.decode(e,{stream:!0});return this.#o(t)}flush(){let e=this.#s.decode(),t=this.#o(e);if(!this.#r&&this.#t.length>0){let o=this.#t.replace(/\r$/,"");o.length>0&&t.push(o)}else this.#r&&(this.#n+=1);return this.#t="",this.#r=!1,t}#o(e){let t=[],o=e;for(;;){let n=o.indexOf(`
10
- `);if(n===-1){if(this.#r)break;this.#t+=o,this.#t.length>this.#e&&(this.#t="",this.#r=!0);break}let i=o.slice(0,n);if(o=o.slice(n+1),this.#r){this.#r=!1,this.#n+=1;continue}let u=(this.#t+i).replace(/\r$/,"");if(this.#t="",u.length>this.#e){this.#n+=1;continue}u.length>0&&t.push(u)}return t}};var U=r=>typeof r=="object"&&r!==null&&!Array.isArray(r),w=r=>({outcome:"rejected",code:r});async function Re(r,e,t){if(e==="input_capabilities")return r.inputCapabilities();if(!U(t)||typeof t.inputId!="string"||!U(t.target)||typeof t.target.turnId!="string"||typeof t.target.historyEpoch!="string")return w("invalid_input");let o={turnId:t.target.turnId,historyEpoch:t.target.historyEpoch};if(e==="input_status")return{receipt:r.getInputStatus(t.inputId,o)};if(e!=="steer")return w("method_not_found");if(t.ack==="durable")return w("durable_unsupported");if(t.ack!==void 0&&t.ack!=="memory")return w("invalid_input");let n=t.content;return!U(n)||!(typeof n.text=="string"&&!("blocks"in n))&&!(Array.isArray(n.blocks)&&n.blocks.length>0&&!("text"in n)&&n.blocks.every(i=>U(i)&&i.t==="text"&&typeof i.text=="string"))?w("content_unsupported"):r.submitInput({inputId:t.inputId,target:o,content:n,ack:"memory"})}function ke(r,e,t,o){let n=new D(65536),i=new Set,u=!1,p=0,c,s=E=>{if(c===void 0)try{e.write(JSON.stringify(E)+`
11
- `)||r.pause()}catch(h){c={error:h},S()}},d=(E,h)=>s({type:"tansr.input.response",v:1,id:E,result:h}),l=()=>{u||r.resume()},v=E=>{for(let h of E){if(u)break;let b;try{b=JSON.parse(h)}catch{d(null,w("invalid_frame"));continue}if(typeof b!="object"||b===null||Array.isArray(b)){d(null,w("invalid_frame"));continue}let x=b,k=x.id;if(typeof k!="string"&&typeof k!="number"||x.v!==1){d(null,w("invalid_frame"));continue}if(x.method==="cancel"){o(),d(k,{outcome:"cancel_requested"});continue}if(x.method!=="steer"&&x.method!=="input_status"&&x.method!=="input_capabilities"){d(k,w("method_not_found"));continue}let C=Re(t,x.method,x.params).then(O=>d(k,O),()=>d(k,w("input_failed")));i.add(C),C.then(()=>i.delete(C),()=>i.delete(C))}for(;!u&&p<n.droppedLines;)p++,d(null,w("frame_too_large"))},y=E=>{u||v(n.push(E))},g=()=>{u||(v(n.flush()),S())},_=()=>{d(null,w("input_failed")),S()};function S(){u=!0,r.off("data",y),r.off("end",g),r.off("error",_),e.off("drain",l),r.pause()}return s({type:"tansr.input.ready",v:1,capabilities:t.inputCapabilities(),maxLineCodeUnits:64*1024}),u||(r.on("data",y),r.on("end",g),r.on("error",_),e.on("drain",l),e.writableNeedDrain&&r.pause()),{stop:S,async close(){if(S(),await Promise.allSettled([...i]),c!==void 0)throw c.error}}}function Qe(r){return{input_tokens:r.inputTokens,output_tokens:r.outputTokens,...r.cacheReadInputTokens!==void 0?{cache_read_input_tokens:r.cacheReadInputTokens}:{},...r.cacheCreationInputTokens!==void 0?{cache_creation_input_tokens:r.cacheCreationInputTokens}:{}}}function $e(r){return r.exitCode===0?"success":r.reason==="max_turns"?"error_max_turns":"error_during_execution"}var A=class{#s;#e;#t;#r;#n=new Map;#o=new Map;#i=[];constructor(e,t){this.#s=e,this.#e=t.sessionId,this.#t=t.model,this.#r=t.toolNames}#a(e){let t;try{t=JSON.stringify(e)}catch(o){t=JSON.stringify({type:"system",subtype:"serialization_error",session_id:this.#e,message:o instanceof Error?o.message:String(o)})}this.#s.write(t+`
12
- `)}writeInit(){this.#a({type:"system",subtype:"init",session_id:this.#e,model:this.#t.model,tools:[...this.#r]})}render(e){switch(e.type){case"msg.block.start":e.blockType==="text"&&this.#n.set(e.index,"");break;case"msg.text.delta":{let t=this.#n.get(e.index);t!==void 0&&this.#n.set(e.index,t+e.text);break}case"msg.block.end":{let t=this.#n.get(e.index);t!==void 0&&(this.#n.delete(e.index),t!==""&&(this.#i.push(t),this.#a({type:"assistant",message:{role:"assistant",content:[{type:"text",text:t}]},session_id:this.#e})));break}case"msg.retracted":this.#n.delete(e.index);break;case"tool.proposed":this.#a({type:"assistant",message:{role:"assistant",content:[{type:"tool_use",id:e.toolCallId,name:e.name,input:e.args}]},session_id:this.#e});break;case"tool.output.delta":{let t=this.#o.get(e.toolCallId)??"";this.#o.set(e.toolCallId,t+e.chunk);break}case"tool.completed":case"tool.failed":{let t=this.#o.get(e.toolCallId);this.#o.delete(e.toolCallId);let o=e.type==="tool.failed",n=o?e.message:e.content??t;this.#a({type:"user",message:{role:"user",content:[{type:"tool_result",tool_use_id:e.toolCallId,content:n!==void 0?[{type:"text",text:n}]:[],...o?{is_error:!0}:{}}]},session_id:this.#e});break}default:break}}writeResult(e){this.#a({type:"result",subtype:$e(e),is_error:e.exitCode!==0,session_id:this.#e,...e.exitCode===0?{result:this.#i.join(`
13
- `)}:{},...e.usage!==void 0?{usage:Qe(e.usage)}:{},...e.error!==void 0?{error:e.error}:{}})}};function we(r,e){return JSON.stringify({type:"error",scope:"serialization",message:e,...r!==void 0?{seq:r}:{}})}function Te(r){try{return JSON.stringify(r)}catch(e){let t=e instanceof Error?e.message:String(e);return we(typeof r.seq=="number"?r.seq:void 0,t)}}function ee(r,e){r.write(Te(e)+`
14
- `)}function re(r,e){let t;try{t=JSON.stringify(e)}catch(o){t=we(void 0,o instanceof Error?o.message:String(o))}r.write(t+`
15
- `)}function Xe(r){try{return JSON.stringify(r)??"undefined"}catch{return"<unserializable>"}}var H=class{#s;#e;#t;#r=new Map;#n=new Map;#o=new Map;constructor(e,t,o={}){this.#s=e,this.#e=t,this.#t=o.verbose===!0}#i(e){return this.#o.get(e)??e}render(e){switch(e.type){case"msg.block.start":this.#n.set(e.index,e.blockType),e.blockType==="text"&&this.#r.set(e.index,"");break;case"msg.text.delta":{let t=this.#r.get(e.index);t!==void 0&&this.#r.set(e.index,t+e.text);break}case"msg.block.end":{let t=this.#r.get(e.index);t!==void 0&&(this.#r.delete(e.index),t!==""&&this.#s.write(t+`
16
- `));break}case"msg.retracted":this.#r.delete(e.index);break;case"turn.started":this.#t&&this.#e.write(m(f.turnStarted)+`
17
- `);break;case"tool.proposed":this.#o.set(e.toolCallId,e.name),this.#t&&this.#e.write(m(f.toolProposed,{name:e.name,args:Xe(e.args)})+`
18
- `);break;case"tool.permission.decided":if(this.#t){let t={name:this.#i(e.toolCallId),decision:e.decision,source:e.decisionSource};this.#e.write((e.matchedRule!==void 0?m(f.toolPermissionDecidedRule,{...t,rule:e.matchedRule}):m(f.toolPermissionDecided,t))+`
19
- `)}break;case"tool.started":this.#e.write(m(f.toolStarted,{name:this.#i(e.toolCallId)})+`
20
- `);break;case"tool.completed":this.#e.write(m(f.toolCompleted,{name:this.#i(e.toolCallId),duration:oe(e.durationMs)})+`
21
- `);break;case"tool.failed":this.#e.write(m(f.toolFailed,{name:this.#i(e.toolCallId),errorType:e.errorType,message:e.message})+`
22
- `);break;case"tool.permission.requested":this.#e.write(m(f.toolPermissionRequested,{name:e.name})+`
23
- `);break;case"turn.error":this.#e.write(m(f.turnError,{message:e.message})+`
24
- `);break;default:break}}};var er=1e4,rr={isTTY:!0,readAll:()=>Promise.resolve("")};function tr(r,e){if(r===void 0)return{...e};let t=(u,p)=>u===void 0&&p===void 0?void 0:(u??0)+(p??0),o=t(r.cacheReadInputTokens,e.cacheReadInputTokens),n=t(r.cacheCreationInputTokens,e.cacheCreationInputTokens),i=t(r.reasoningOutputTokens,e.reasoningOutputTokens);return{inputTokens:r.inputTokens+e.inputTokens,outputTokens:r.outputTokens+e.outputTokens,...o!==void 0?{cacheReadInputTokens:o}:{},...n!==void 0?{cacheCreationInputTokens:n}:{},...i!==void 0?{reasoningOutputTokens:i}:{}}}async function nr(r,e){let t=e.stdin??rr,o=X(r);if(o!==void 0||r.inputFormat==="ndjson"&&t.controlStream===void 0)return e.stderr.write(m(o?.key??f.ndjsonRequirements)+`
25
- `),P.usage;let n=r.inputFormat==="ndjson"?{ok:!0,prompt:r.prompt}:await Z(r,t);if(!n.ok)return e.stderr.write(m(n.error.key,n.error.params)+`
26
- `),P.usage;let i=M(r),u=e.model??{provider:"cli",model:r.model??"default"},p=e.sessionId??Ze();if(e.effortDiagnostic!==void 0&&i==="text"&&r.verbose===!0){let a=e.effortDiagnostic,T=a.source==="flag"?"--effort":a.source==="env"?"TANSR_EFFORT":"config";e.stderr.write((a.thinking!==void 0?m(f.effortApplied,{level:a.level,source:T,budget:a.thinking.budget,maxTokens:a.maxTokens}):m(f.effortDefault,{level:a.level,source:T}))+`
27
- `)}let c=e.queryHooks?.([n.prompt]),s;if(e.compaction!==void 0&&e.contextWindowTokens!==void 0){let{manager:a,...T}=e.compaction,te=ce(T,e.compactionManagerOptions,{client:e.client,contextWindowTokens:e.contextWindowTokens,...e.transcriptHint!==void 0?{transcriptHint:e.transcriptHint}:{}}),ne=ie(e.reminders);ne!==void 0&&te.registerPostCompactInvalidation(ne),s={...T,manager:te}}let l=(e.runQueryImpl??le)({...e.sessionCapture!==void 0?{sessionCapture:e.sessionCapture,sessionCaptureInputStart:e.initialHistory?.length??0}:{},...e.contextMaterials!==void 0?{contextMaterials:e.contextMaterials}:{},...e.onInputsConsumed===void 0?{}:{onInputsConsumed:a=>e.onInputsConsumed(a.map(T=>T.text))},client:e.client,executor:e.executor,system:e.system,tools:e.tools,model:u,maxTokens:e.maxTokens??ae,...e.maxOutputTokens!==void 0?{maxOutputTokens:e.maxOutputTokens}:{},maxTokensEscalation:{ceilingTokens:de},...e.thinking!==void 0?{thinking:e.thinking}:{},sessionId:p,initialMessages:[...e.initialHistory??[],{role:"user",blocks:[{t:"text",text:n.prompt}]}],...e.contextWindowTokens!==void 0?{contextWindowTokens:e.contextWindowTokens}:{},...s!==void 0?{compaction:s}:{},...r.maxTurns!==void 0?{maxTurns:r.maxTurns}:{},...e.reminders!==void 0?{reminders:e.reminders}:{},...e.sessionEvents!==void 0?{sessionEvents:e.sessionEvents}:{},...c!==void 0?{hooks:c}:{},...e.budget!==void 0?{budget:e.budget}:{},...e.toolResultBudget!==void 0?{toolResultBudget:e.toolResultBudget}:{},...e.requestMeasurement!==void 0?{requestMeasurement:e.requestMeasurement}:{}}),v=e.forceExit??(a=>process.exit(a)),y=Ee(e.stderr),g=he({hardExitAfterMs:er,...e.processLifecycle,...e.onSigint!==void 0?{signalSource:e.onSigint}:{},drain:a=>{a.kind==="interrupt"&&e.stderr.write(m(f.interruptAbort)+`
28
- `),l.abort()},exitCode:P.aborted,exit:v,onSecondSignal:y.onSecondSignal,onHardExit:y.onHardExit}),_=()=>{g.dispose()},S=Q({logger:{info:a=>e.stderr.write(a+`
29
- `),error:a=>e.stderr.write(a+`
30
- `)},onFatal:"log",...e.processGuardTarget!==void 0?{target:e.processGuardTarget}:{}}),E=i==="text"?new H(e.stdout,e.stderr,{verbose:r.verbose===!0}):void 0,h=i==="stream-json"&&r.ccCompat===!0?new A(e.stdout,{sessionId:p,model:u,toolNames:e.tools.map(a=>a.name)}):void 0;h?.writeInit();let b,x,k=e.restoredFrom!==void 0,C,O=a=>{e.trackEvent?.(a),a.type==="cost.usage.updated"&&(x=tr(x,a.usage)),a.type==="session.compacted"&&(k=!0),(a.type==="turn.completed"||a.type==="turn.aborted")&&(b=a.reason),a.type==="turn.error"&&a.errorKind==="internal_error"&&!a.recoverable&&(C=a.message),i==="stream-json"?h!==void 0?h.render(a):ee(e.stdout,a):E?.render(a)},G=a=>{h!==void 0?h.writeResult(a):re(e.stdout,a)},B=()=>{for(let a of e.drainSideEvents?.()??[])O(a)};e.resumedFromSeq!==void 0&&O({type:"session.resumed",fromSeq:e.resumedFromSeq,sessionId:p,seq:0,ts:Date.now(),v:"v0",source:"cli"}),e.restoredFrom!==void 0&&O({type:"session.restored",checkpointId:e.restoredFrom.checkpointId,fromMessages:e.restoredFrom.fromMessages,toMessages:e.restoredFrom.toMessages,sessionId:p,seq:e.resumedFromSeq!==void 0?1:0,ts:Date.now(),v:"v0",source:"cli"});let Le=async()=>{if(e.onFinalMessages!==void 0)try{await e.onFinalMessages(l.messages(),{rewritten:k})}catch(a){let T=a instanceof Error?a.message:String(a);e.stderr.write(m(f.internalError,{message:T})+`
31
- `)}},Ie=a=>{if(e.stderr.write(m(f.internalError,{message:a})+`
32
- `),i!=="text"){let T={type:"result",sessionId:p,exitCode:P.modelError,error:a,...x!==void 0?{usage:x}:{}};G(T)}return P.modelError},F=r.inputFormat==="ndjson"?new fe(p):void 0;F?.bind(l);let K=F===void 0?void 0:ke(t.controlStream,e.stdout,F,()=>l.abort());try{B();for await(let a of l.events)(a.type==="turn.completed"||a.type==="turn.aborted")&&K?.stop(),B(),O(a);B()}catch(a){C=a instanceof Error?a.message:String(a),K!==void 0&&l.abort("internal_error")}finally{try{await K?.close()}finally{F?.finish(l),S();try{await Le()}finally{_()}}}if(C!==void 0)return Ie(C);if(b===void 0){if(e.stderr.write(m(f.internalError,{message:m(f.noTerminalEvent)})+`
33
- `),i!=="text"){let a={type:"result",sessionId:p,exitCode:P.modelError,error:m(f.noTerminalEvent),...x!==void 0?{usage:x}:{}};G(a)}return P.modelError}let J=q(b);if(i!=="text"){let a={type:"result",sessionId:p,reason:b,exitCode:J,...x!==void 0?{usage:x}:{}};G(a)}else{let a=ge(b);e.stderr.write(m(f.summary,{reason:a!==void 0?m(a):b,exitCode:J})+`
34
- `)}return J}import{timingSafeEqual as or}from"node:crypto";var Pe=Oe("node:http");var sr=/^\/v1\/approvals\/([^/]+)\/credential$/,ir={unknown_challenge:404,expired:410,digest_mismatch:409,already_resolved:409},ar=64*1024;function Ce(r){let e=r.trim();if(e==="")return null;let t=e.lastIndexOf(":"),o=t===-1?"127.0.0.1":e.slice(0,t),n=t===-1?e:e.slice(t+1);if(!/^\d+$/.test(n))return null;let i=Number(n);return!Number.isInteger(i)||i<0||i>65535||o===""?null:{host:o,port:i}}function dr(r,e){if(r===void 0||!r.startsWith("Bearer "))return!1;let t=Buffer.from(r.slice(7)),o=Buffer.from(e);return t.length!==o.length?!1:or(t,o)}function I(r,e,t){let o=JSON.stringify(t);r.writeHead(e,{"content-type":"application/json"}),r.end(o)}function ur(r){return new Promise(e=>{let t=[],o=0,n=!1;r.on("data",i=>{if(!n){if(o+=i.length,o>ar){n=!0,t.length=0;return}t.push(i)}}),r.on("end",()=>e(n?null:Buffer.concat(t).toString("utf8"))),r.on("error",()=>e(null))})}async function lr(r){let e=Ce(r.listen);if(e===null)throw new Error(`approval-listener:监听地址不合法,收到 ${r.listen}`);let t=async(c,s)=>{let d=(()=>{try{return new URL(c.url??"/","http://localhost").pathname}catch{return"/"}})(),l=sr.exec(d);if(l===null){I(s,404,{error:"not_found"});return}if(!dr(c.headers.authorization,r.token)){I(s,401,{error:"unauthorized"});return}if(c.method!=="POST"){s.setHeader("allow","POST"),I(s,405,{error:"method_not_allowed"});return}let v=await ur(c);if(v===null){I(s,413,{error:"body_too_large"});return}let y;try{let S=JSON.parse(v===""?"{}":v);if(typeof S!="object"||S===null||Array.isArray(S)){I(s,400,{error:"invalid_body"});return}y=S}catch{I(s,400,{error:"invalid_json"});return}if(typeof y.digest!="string"||y.digest===""||y.verdict!=="approve"&&y.verdict!=="deny"||typeof y.approver!="string"||y.approver.trim()===""){I(s,400,{error:"invalid_body"});return}let g=decodeURIComponent(l[1]),_=r.coordinator.submit({challengeId:g,digest:y.digest,verdict:y.verdict,approver:y.approver});if(_.code==="accepted"){I(s,200,{challengeId:g,result:"accepted"});return}I(s,ir[_.code]??409,{error:`approval_${_.code}`})},o=Pe.createServer((c,s)=>{t(c,s)});await new Promise((c,s)=>{let d=l=>s(l);o.once("error",d),o.listen(e.port,e.host,()=>{o.removeListener("error",d),c()})});let n=o.address(),i=typeof n=="object"&&n!==null?n.port:e.port,u=e.host==="0.0.0.0"||e.host==="::"?"127.0.0.1":e.host;return{url:`http://${u.includes(":")?`[${u}]`:u}:${i}`,close:()=>new Promise(c=>{o.close(()=>c()),o.closeAllConnections?.()})}}export{z as a,yr as b,L as c,cr as d,mr as e,j as f,V as g,br as h,He as i,Fe as j,je as k,Q as l,De as m,he as n,Ee as o,M as p,be as q,Ve as r,ze as s,D as t,Re as u,nr as v,Pe as w,Ce as x,lr as y};
35
- //# sourceMappingURL=tansr-chunk-74H5GQTJ.mjs.map
@@ -1,12 +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 T,b as G,f as U}from"./tansr-chunk-WW5ZPL6Q.mjs";import{a as S}from"./tansr-chunk-S3KHAGOR.mjs";import{a as D,b as N}from"./tansr-chunk-NROI7AG5.mjs";import{a as f}from"./tansr-chunk-AMMPDY4V.mjs";import{m as _,x as F}from"./tansr-chunk-X5REV3T3.mjs";import{h as K}from"./tansr-chunk-XXBNISJJ.mjs";import{a as A}from"./tansr-chunk-2QKLANZQ.mjs";import{d as v,i as x,o as I,p as b,r as P,s as R,v as h,y as O}from"./tansr-chunk-HRKJLVKC.mjs";import{ef as L}from"./tansr-chunk-IZICOKKF.mjs";import{d as E}from"./tansr-chunk-DIT3PBNB.mjs";import{k as w,m as i,o as C}from"./tansr-chunk-NA22YT73.mjs";import X from"node:os";import{readFile as J,rm as Y,stat as j}from"node:fs/promises";import B from"node:os";import{dirname as q}from"node:path";async function H(e,t){try{let[r,o]=await Promise.all([J(e),J(t)]);return r.equals(o)}catch{return!1}}async function M(e){let t=e.env,r=e.homedir??B.homedir(),o=R(t,r),d=P(t,r),g={...e.cipher!==void 0?{cipher:e.cipher}:{},...e.secretStore!==void 0?{secretStore:e.secretStore}:{}},n=await h(o,g),k=a=>{if(e.expectedKeyId!==void 0&&!(a.status==="ok"&&(a.version===3?a.credentials.derivedApp?.keyId:a.credentials.keyId)===e.expectedKeyId))throw Object.assign(new Error("credential_changed"),{code:"credential_changed"})};if(k(n),n.status==="missing")return{existed:!1};let s;if(e.keepRemote===!0)s={kind:"skipped",reason:"keep-remote"};else if(n.status==="ok"&&n.version===3){let a=n.credentials.derivedApp;if(a===null)s={kind:"skipped",reason:"no-derived"};else{e.onStep?.("revoke");let l=N({baseUrl:n.credentials.apiBaseUrl,pat:n.credentials.pat,...e.fetchImpl!==void 0?{fetchImpl:e.fetchImpl}:{}});try{s={kind:"disabled",appName:(await l.updateApp(a.keyId,{status:"disabled"})).name}}catch(c){s={kind:"failed",failure:c instanceof D?{kind:c.kind,code:c.code,status:c.status}:{kind:"network",code:"network_error",status:0}}}}}else n.status==="ok"?s={kind:"skipped",reason:"no-control"}:s={kind:"skipped",reason:"unreadable"};let p=o!==d&&await H(o,d),u=await G(o);if(e.expectedKeyId!==void 0&&k(await h(o,g)),await O(o,{...e.secretStore!==void 0?{secretStore:e.secretStore}:{}}),p&&await Y(d,{force:!0}),u!==null)try{await U(T(t,r),u.keyId)}catch{}await _(t,r);let y=K(x(t,r)),m={version:1,state:"uninited"};try{await j(q(y)),await I(y,JSON.stringify(m,null,2)+`
5
- `,{mode:v})}catch{}return{existed:!0,summary:{protection:n.status==="ok"?n.protection:null,unreadableReason:n.status==="legacy"?"legacy":n.status==="corrupt"?n.reason:null,remote:s}}}function W(e,t){let r=S,o=[];return e.remote.kind==="disabled"?o.push(i(r.remoteDisabled,{appName:e.remote.appName})):e.remote.kind==="failed"?o.push(i(r.remoteFailed,{code:e.remote.failure.code,url:E(t)})):e.remote.reason==="keep-remote"&&o.push(i(r.remoteSkipped)),o.push(e.protection!==null?i(r.localCleared,{protection:e.protection}):i(r.localClearedUnreadable,{reason:e.unreadableReason??"unknown"})),o.push(i(r.identityKept)),o}function z(e){let t={keepRemote:!1};for(let r of e){if(r==="--keep-remote"){t.keepRemote=!0;continue}return r.startsWith("-")?{ok:!1,key:L.unknownFlag,params:{flag:r}}:{ok:!1,key:L.unexpectedArg,params:{arg:r}}}return{ok:!0,args:t}}async function ye(e,t={}){let r=t.stdout??process.stdout,o=t.stderr??process.stderr,d=t.env??process.env,g=t.cwd??process.cwd(),n=t.platform??process.platform,k=t.homedir??X.homedir(),s=await F({cwd:g,env:d,...t.loadOptions!==void 0?{loadOptions:t.loadOptions}:{}});w(C({configLocale:s.loaded.locale,env:d}));let p=z(e);if(!p.ok)return o.write(i(p.key,p.params)+`
6
- `),f.usage;let u=t.cipher??(n==="win32"?A():void 0),y=t.secretStore!==void 0?t.secretStore:b(n),m=S,a;try{a=await M({env:d,homedir:k,...t.fetchImpl!==void 0?{fetchImpl:t.fetchImpl}:{},...u!==void 0?{cipher:u}:{},secretStore:y,keepRemote:p.args.keepRemote,...t.expectedKeyId!==void 0?{expectedKeyId:t.expectedKeyId}:{},onStep:l=>{l==="revoke"&&r.write(i(m.stepRevoke)+`
7
- `)}})}catch(l){let c=l.code??"unknown";return o.write(i(m.failLocalClear,{code:c})+`
8
- `),f.modelError}if(!a.existed)return r.write(i(m.notLoggedIn)+`
9
- `),f.ok;for(let l of W(a.summary,d))r.write(l+`
10
- `);return r.write(i(m.done)+`
11
- `),f.ok}export{M as a,W as b,z as c,ye as d};
12
- //# sourceMappingURL=tansr-chunk-7T6OLLFW.mjs.map