@automaton-labs/aib 0.0.6 → 0.0.7

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 (247) hide show
  1. package/dist/bin/cli.js +4 -2
  2. package/dist/commands/apply-module-plan.js +3 -3
  3. package/dist/commands/background-command.js +2 -0
  4. package/dist/commands/captured-input.js +1 -2
  5. package/dist/commands/config-command.js +2 -2
  6. package/dist/commands/config-output.js +10 -10
  7. package/dist/commands/control-plane-command.js +1 -0
  8. package/dist/commands/declaration-command.js +7 -0
  9. package/dist/commands/declaration-execution-cache.js +1 -0
  10. package/dist/commands/declaration-format.js +1 -0
  11. package/dist/commands/declaration-preview-cache.js +2 -0
  12. package/dist/commands/doctor.js +3 -2
  13. package/dist/commands/execution-command.js +1 -1
  14. package/dist/commands/file-command.js +1 -0
  15. package/dist/commands/file-move-to-dir-execution-cache.js +1 -0
  16. package/dist/commands/file-move-to-dir-preview-cache.js +2 -0
  17. package/dist/commands/file-move-to-dir.js +5 -0
  18. package/dist/commands/file-mutation-runtime.js +1 -0
  19. package/dist/commands/file-refactor-batch-execution-cache.js +1 -0
  20. package/dist/commands/file-refactor-batch-preview-cache.js +2 -0
  21. package/dist/commands/file-refactor-batch.js +5 -0
  22. package/dist/commands/file-rename-execution-cache.js +1 -0
  23. package/dist/commands/file-rename-preview-cache.js +2 -0
  24. package/dist/commands/file-rename.js +5 -0
  25. package/dist/commands/help-command.js +5 -5
  26. package/dist/commands/host-command.js +1 -0
  27. package/dist/commands/inspect-cycles.js +3 -3
  28. package/dist/commands/inspect-format.js +15 -15
  29. package/dist/commands/inspect-tree.js +2 -2
  30. package/dist/commands/inspect.js +12 -12
  31. package/dist/commands/move-to-file.js +2 -2
  32. package/dist/commands/ota-command.js +2 -0
  33. package/dist/commands/quick-read.js +4 -4
  34. package/dist/commands/refactor-batch.js +4 -4
  35. package/dist/commands/rename-entities.js +4 -4
  36. package/dist/commands/result-view.js +6 -5
  37. package/dist/commands/worker-command.js +1 -0
  38. package/dist/config/defaults.js +1 -1
  39. package/dist/config/env-vars.js +1 -1
  40. package/dist/config/path-aliases.js +1 -1
  41. package/dist/config/resolve-command-alias.js +1 -1
  42. package/dist/content/content-bundle.js +1 -1
  43. package/dist/dsl/aib-dsl.js +1 -1
  44. package/dist/dsl/declaration-dsl.js +1 -0
  45. package/dist/dsl/file-move-to-dir-dsl.js +1 -0
  46. package/dist/dsl/file-refactor-batch-dsl.js +1 -0
  47. package/dist/dsl/file-rename-dsl.js +1 -0
  48. package/dist/help/{json/bootstrap.md → bootstrap.bash.md} +214 -392
  49. package/dist/help/bootstrap.md +101 -137
  50. package/dist/help/{json/full.md → bootstrap.pwsh.md} +214 -392
  51. package/dist/help/docs/dsl.md +4 -3
  52. package/dist/help/docs/file.move.md +46 -0
  53. package/dist/help/docs/file.rename.md +35 -0
  54. package/dist/help/docs/inspect.code.md +5 -5
  55. package/dist/help/docs/inspect.deps.md +7 -7
  56. package/dist/help/docs/inspect.file.md +2 -1
  57. package/dist/help/docs/inspect.graph.md +3 -3
  58. package/dist/help/docs/inspect.md +5 -5
  59. package/dist/help/docs/mutation.md +23 -13
  60. package/dist/help/docs/patterns.md +1 -5
  61. package/dist/help/docs/qr.md +7 -22
  62. package/dist/help/docs/quick-map.md +1 -0
  63. package/dist/help/docs/recipe.file-layout.md +15 -0
  64. package/dist/help/docs/rg.md +22 -0
  65. package/dist/help/docs/selectors.md +3 -2
  66. package/dist/help/docs/session.md +1 -1
  67. package/dist/help/dsl/bootstrap.bash.md +907 -0
  68. package/dist/help/dsl/bootstrap.md +101 -137
  69. package/dist/help/dsl/bootstrap.pwsh.md +907 -0
  70. package/dist/help/dsl/docs/dsl.md +4 -3
  71. package/dist/help/dsl/docs/file.move.md +46 -0
  72. package/dist/help/dsl/docs/file.rename.md +35 -0
  73. package/dist/help/dsl/docs/inspect.code.md +5 -5
  74. package/dist/help/dsl/docs/inspect.deps.md +7 -7
  75. package/dist/help/dsl/docs/inspect.file.md +2 -1
  76. package/dist/help/dsl/docs/inspect.graph.md +3 -3
  77. package/dist/help/dsl/docs/inspect.md +5 -5
  78. package/dist/help/dsl/docs/mutation.md +23 -13
  79. package/dist/help/dsl/docs/patterns.md +1 -5
  80. package/dist/help/dsl/docs/qr.md +7 -22
  81. package/dist/help/dsl/docs/quick-map.md +1 -0
  82. package/dist/help/dsl/docs/recipe.file-layout.md +15 -0
  83. package/dist/help/dsl/docs/rg.md +22 -0
  84. package/dist/help/dsl/docs/selectors.md +3 -2
  85. package/dist/help/dsl/docs/session.md +1 -1
  86. package/dist/help/dsl/full.md +101 -137
  87. package/dist/help/dsl/help-index.md +44 -0
  88. package/dist/help/dsl/tokens/qr.inline.examples.md +2 -0
  89. package/dist/help/dsl/tokens/stdin.examples.bash.md +8 -0
  90. package/dist/help/dsl/tokens/stdin.examples.pwsh.md +8 -0
  91. package/dist/help/dsl/tokens/stdin.examples.with-qr.bash.md +12 -0
  92. package/dist/help/dsl/tokens/stdin.examples.with-qr.pwsh.md +12 -0
  93. package/dist/help/dsl/topics/dsl.md +4 -3
  94. package/dist/help/dsl/topics/file.move.md +44 -0
  95. package/dist/help/dsl/topics/file.rename.md +33 -0
  96. package/dist/help/dsl/topics/inspect.code.md +5 -5
  97. package/dist/help/dsl/topics/inspect.deps.md +7 -7
  98. package/dist/help/dsl/topics/inspect.file.md +2 -1
  99. package/dist/help/dsl/topics/inspect.graph.md +3 -3
  100. package/dist/help/dsl/topics/inspect.md +5 -5
  101. package/dist/help/dsl/topics/mutation.md +23 -13
  102. package/dist/help/dsl/topics/patterns.md +1 -5
  103. package/dist/help/dsl/topics/qr.md +7 -22
  104. package/dist/help/dsl/topics/quick-map.md +1 -0
  105. package/dist/help/dsl/topics/recipe.file-layout.md +13 -0
  106. package/dist/help/dsl/topics/rg.md +20 -0
  107. package/dist/help/dsl/topics/selectors.md +3 -2
  108. package/dist/help/dsl/topics/session.md +1 -1
  109. package/dist/help/full.md +101 -137
  110. package/dist/help/help-index.md +44 -0
  111. package/dist/help/help-meta.json +43 -27
  112. package/dist/help/index.md +32 -75
  113. package/dist/help/tokens/qr.inline.examples.md +2 -0
  114. package/dist/help/tokens/stdin.examples.bash.md +8 -0
  115. package/dist/help/tokens/stdin.examples.pwsh.md +8 -0
  116. package/dist/help/tokens/stdin.examples.with-qr.bash.md +12 -0
  117. package/dist/help/tokens/stdin.examples.with-qr.pwsh.md +12 -0
  118. package/dist/help/topics/dsl.md +4 -3
  119. package/dist/help/topics/file.move.md +44 -0
  120. package/dist/help/topics/file.rename.md +33 -0
  121. package/dist/help/topics/inspect.code.md +5 -5
  122. package/dist/help/topics/inspect.deps.md +7 -7
  123. package/dist/help/topics/inspect.file.md +2 -1
  124. package/dist/help/topics/inspect.graph.md +3 -3
  125. package/dist/help/topics/inspect.md +5 -5
  126. package/dist/help/topics/mutation.md +23 -13
  127. package/dist/help/topics/patterns.md +1 -5
  128. package/dist/help/topics/qr.md +7 -22
  129. package/dist/help/topics/quick-map.md +1 -0
  130. package/dist/help/topics/recipe.file-layout.md +13 -0
  131. package/dist/help/topics/rg.md +20 -0
  132. package/dist/help/topics/selectors.md +3 -2
  133. package/dist/help/topics/session.md +1 -1
  134. package/dist/host/capabilities.js +1 -0
  135. package/dist/ide-launch/common.cjs +162 -162
  136. package/dist/managed-host/extension-vsix-resolver.js +1 -1
  137. package/dist/managed-host/manage-serve-web-host.cjs +141 -141
  138. package/dist/managed-host/serve-web-autostart.js +1 -1
  139. package/dist/managed-host/serve-web-host.cjs +1781 -1570
  140. package/dist/payloads/read-stdin-json.js +1 -1
  141. package/dist/rg-wrapper/core.js +6 -0
  142. package/dist/rg-wrapper/options.js +1 -0
  143. package/dist/rtk-wrapper/core.js +2 -0
  144. package/dist/runtime/input-source.js +1 -1
  145. package/dist/runtime/run-command.js +1 -1
  146. package/dist/selectors/parse-entities.js +1 -1
  147. package/dist/session/daemon-state.js +2 -0
  148. package/dist/session/server.js +7 -8
  149. package/dist/shared/operations.js +1 -1
  150. package/dist/shared/protocol.js +1 -1
  151. package/dist/shared/routes.js +1 -1
  152. package/dist/shared/stdin-examples.js +1 -3
  153. package/dist/shared/types.js +1 -1
  154. package/dist/tool-runtime/runtime-tools.js +1 -0
  155. package/dist/workers/control-plane/aib-control-plane-worker.cjs +80 -0
  156. package/dist/workers/control-plane/client-config.default.json +3 -0
  157. package/dist/workers/product-storage.js +1 -0
  158. package/dist/workers/registry.js +1 -0
  159. package/extension/vscode-refactor-bridge-extension.vsix +0 -0
  160. package/package.json +6 -4
  161. package/runtimes/launcher/linux-x64/aib +0 -0
  162. package/runtimes/launcher/win-x64/aib.exe +0 -0
  163. package/runtimes/tools/rg/darwin-arm64/rg +0 -0
  164. package/runtimes/tools/rg/darwin-x64/rg +0 -0
  165. package/runtimes/tools/rg/linux-arm64/rg +0 -0
  166. package/runtimes/tools/rg/linux-x64/rg +0 -0
  167. package/runtimes/tools/rg/manifest.json +36 -0
  168. package/runtimes/tools/rg/win32-x64/rg.exe +0 -0
  169. package/runtimes/tools/rtk/darwin-arm64/rtk +0 -0
  170. package/runtimes/tools/rtk/darwin-x64/rtk +0 -0
  171. package/runtimes/tools/rtk/linux-arm64/rtk +0 -0
  172. package/runtimes/tools/rtk/linux-x64/rtk +0 -0
  173. package/runtimes/tools/rtk/manifest.json +36 -0
  174. package/runtimes/tools/rtk/win32-x64/rtk.exe +0 -0
  175. package/dist/help/json/docs/basics.md +0 -15
  176. package/dist/help/json/docs/config-setup.aliases.md +0 -56
  177. package/dist/help/json/docs/config-setup.excludes.md +0 -45
  178. package/dist/help/json/docs/config-setup.import-normalize.md +0 -86
  179. package/dist/help/json/docs/config-setup.import-rules.md +0 -96
  180. package/dist/help/json/docs/config-setup.tsconfigs.md +0 -33
  181. package/dist/help/json/docs/dsl.md +0 -25
  182. package/dist/help/json/docs/first-setup.md +0 -292
  183. package/dist/help/json/docs/help-format.md +0 -9
  184. package/dist/help/json/docs/help-protocol.md +0 -26
  185. package/dist/help/json/docs/imports.normalize.md +0 -47
  186. package/dist/help/json/docs/inspect.code.md +0 -41
  187. package/dist/help/json/docs/inspect.cycles.md +0 -38
  188. package/dist/help/json/docs/inspect.deps.md +0 -46
  189. package/dist/help/json/docs/inspect.duplicates.md +0 -65
  190. package/dist/help/json/docs/inspect.exports.md +0 -40
  191. package/dist/help/json/docs/inspect.file.md +0 -38
  192. package/dist/help/json/docs/inspect.graph.md +0 -139
  193. package/dist/help/json/docs/inspect.imports.md +0 -15
  194. package/dist/help/json/docs/inspect.md +0 -88
  195. package/dist/help/json/docs/inspect.members.md +0 -32
  196. package/dist/help/json/docs/inspect.tree.md +0 -32
  197. package/dist/help/json/docs/inspect.usages.md +0 -61
  198. package/dist/help/json/docs/modulePlan.md +0 -73
  199. package/dist/help/json/docs/move.md +0 -56
  200. package/dist/help/json/docs/mutation.md +0 -65
  201. package/dist/help/json/docs/patterns.md +0 -76
  202. package/dist/help/json/docs/prefs.md +0 -40
  203. package/dist/help/json/docs/qr.md +0 -37
  204. package/dist/help/json/docs/quick-map.md +0 -30
  205. package/dist/help/json/docs/refactor.batch.md +0 -72
  206. package/dist/help/json/docs/rename.md +0 -47
  207. package/dist/help/json/docs/reveal.md +0 -30
  208. package/dist/help/json/docs/selectors.md +0 -23
  209. package/dist/help/json/docs/session.md +0 -77
  210. package/dist/help/json/docs/view.md +0 -30
  211. package/dist/help/json/snippets/agents.md +0 -14
  212. package/dist/help/json/topics/basics.md +0 -13
  213. package/dist/help/json/topics/config-setup.aliases.md +0 -54
  214. package/dist/help/json/topics/config-setup.excludes.md +0 -43
  215. package/dist/help/json/topics/config-setup.import-normalize.md +0 -84
  216. package/dist/help/json/topics/config-setup.import-rules.md +0 -94
  217. package/dist/help/json/topics/config-setup.tsconfigs.md +0 -31
  218. package/dist/help/json/topics/dsl.md +0 -23
  219. package/dist/help/json/topics/first-setup.md +0 -290
  220. package/dist/help/json/topics/help-format.md +0 -7
  221. package/dist/help/json/topics/help-protocol.md +0 -24
  222. package/dist/help/json/topics/imports.normalize.md +0 -45
  223. package/dist/help/json/topics/inspect.code.md +0 -39
  224. package/dist/help/json/topics/inspect.cycles.md +0 -36
  225. package/dist/help/json/topics/inspect.deps.md +0 -44
  226. package/dist/help/json/topics/inspect.duplicates.md +0 -37
  227. package/dist/help/json/topics/inspect.exports.md +0 -38
  228. package/dist/help/json/topics/inspect.file.md +0 -36
  229. package/dist/help/json/topics/inspect.graph.md +0 -137
  230. package/dist/help/json/topics/inspect.imports.md +0 -13
  231. package/dist/help/json/topics/inspect.md +0 -86
  232. package/dist/help/json/topics/inspect.members.md +0 -30
  233. package/dist/help/json/topics/inspect.tree.md +0 -22
  234. package/dist/help/json/topics/inspect.usages.md +0 -59
  235. package/dist/help/json/topics/modulePlan.md +0 -60
  236. package/dist/help/json/topics/move.md +0 -46
  237. package/dist/help/json/topics/mutation.md +0 -63
  238. package/dist/help/json/topics/patterns.md +0 -74
  239. package/dist/help/json/topics/prefs.md +0 -38
  240. package/dist/help/json/topics/qr.md +0 -35
  241. package/dist/help/json/topics/quick-map.md +0 -28
  242. package/dist/help/json/topics/refactor.batch.md +0 -61
  243. package/dist/help/json/topics/rename.md +0 -42
  244. package/dist/help/json/topics/reveal.md +0 -28
  245. package/dist/help/json/topics/selectors.md +0 -21
  246. package/dist/help/json/topics/session.md +0 -59
  247. package/dist/help/json/topics/view.md +0 -28
@@ -1,16 +1,16 @@
1
- "use strict";var ht=exports&&exports.__createBinding||(Object.create?(function(e,t,n,s){s===void 0&&(s=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,s,i)}):(function(e,t,n,s){s===void 0&&(s=n),e[s]=t[n]})),gt=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),ve=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(n){var s=[];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(s[s.length]=i);return s},e(t)};return function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var s=e(t),i=0;i<s.length;i++)s[i]!=="default"&&ht(n,t,s[i]);return gt(n,t),n}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.runInspect=Ce;const L=ve(require("node:path")),ye=ve(require("node:fs")),bt=require("node:crypto"),It=require("../client/http-client"),xt=require("../shared/routes"),At=require("../shared/protocol"),E=require("../shared/errors"),V=require("../shared/agent-text"),ie=require("./shared"),$=require("./inspect-format"),w=require("./module-plan-cache"),he=require("./json-file-input"),ge=require("./inspect-graph"),De=require("./inspect-cycles"),be=require("./inspect-imports"),oe=require("./inspect-tree"),Y=require("../config/path-display"),S=require("./session-workspace"),St=require("./entity-resolution");async function Ce(e,t,n,s={},i={}){if(Et(t))return Nt(e,t);if((0,ge.isInspectGraphRequest)(t,n))return(0,ge.runInspectGraph)(e,t,n);if((0,De.isInspectCyclesRequest)(t,n))return(0,De.runInspectCycles)(e,t,n);if((0,oe.isInspectTreeRequest)(t,n))return(0,oe.runInspectTree)(e,t,n);if(t[0]==="imports")return(0,be.runInspectImports)(e,t,n);const o=Xt(e,t,n);if(o&&Yt(o))return qt(e,t,o,s,i);i.allowModulePlan!==!0&&Un(t,n)&&ct();const l=await(0,ie.resolveCompatibleTargetInstance)(e,At.CLI_COMMAND_IDS.inspect,s),r=await(0,ie.fetchEffectiveConfig)(l.entry,s),c=mn(e,t,n,r,i.allowModulePlan===!0,i.forceResults===!0);an(e,c),await _t(l.entry,c.payload,r,s),sn(e,c);const u=await(0,It.postJson)(l.entry,xt.EXTENSION_ROUTES.inspect,c.payload,(0,ie.extensionRequestOptions)(s));on(e,c,u);const d=(0,$.formatInspectResponse)(u,r,c.formatOptions);return Ct(rn(vt(e,u,d,c),c.revision),c)}async function _t(e,t,n,s){const i=Array.isArray(t.requests)?t.requests.filter(p):[],o=new Map;for(const l of i){const r=a(l.op);if(r!=="code"&&r!=="slice"&&r!=="dependencies"&&r!=="members"&&r!=="usages")continue;const c=a(l.sourceFile),u=a(l.symbolName);if(!c||!u)continue;const d=a(l.symbolKind);if(d==="constructor")continue;const m={raw:u,symbolName:u,symbolKind:d},y=o.get(c)??[];y.push(m),o.set(c,y)}for(const[l,r]of o)await(0,St.ensureSelectorsResolvable)(e,l,r,n,(0,ie.extensionRequestOptions)(s))}function Et(e){return e[0]==="usages"&&F(e,"--from-file")!==null}function Nt(e,t){const n=F(t,"--from-file");if(!n)throw new E.CliError("USAGES_FROM_FILE_REQUIRED","inspect usages --from-file expects a saved usages handle or JSON file.");const s=(0,S.resolveSessionFileArgument)(e,n),i=(0,he.readJsonObjectFile)(e,s,"INVALID_USAGES_ARTIFACT"),o=R(t,"--focus"),l=Ie(e,{detail:F(t,"--detail")??"locations",all:t.includes("--all"),limit:H(t,"--limit"),maxCodeLines:H(t,"--max-code-lines")??H(t,"--maxCodeLines")});if(l.detail==="summary")throw new E.CliError("INVALID_USAGES_DETAIL","inspect usages --from-file --detail expects locations or code.");if(l.detail!=="locations"&&l.detail!=="code")throw new E.CliError("INVALID_USAGES_DETAIL","inspect usages --detail expects locations or code.");const r=Oe(e,i,o,l);return(0,V.attachAgentText)(r,xe(e,r))}function vt(e,t,n,s){const i=s.usagesDetails??[],o=Dt(n,s);if(i.length===0||i.every(m=>m===null||m.detail==="summary"))return o;const l=Array.isArray(t.results)?t.results.filter(p):[];if(l.length===0)return o;const r=Array.isArray(o.results)?o.results.filter(p):[o],c=Array.isArray(s.payload.requests)?s.payload.requests.filter(p):[],u=l.map((m,y)=>{const h=i[y],A=r[y]??{};if(c[y]?.targetLocalUsagesHidden===!0&&(m.targetLocalUsagesHidden=!0),m.op!=="usages"||h===void 0||h===null||h.detail==="summary")return A;const I=Oe(e,m,[],h,!0);return Tt(A,I),I});Mt(e,u),Ut(u);const d=u.length===1?u[0]:{results:u};return(0,V.attachAgentText)(d,Bt(e,d,o))}function Dt(e,t){const n=Array.isArray(t.payload.requests)?t.payload.requests.filter(p):[],s=Array.isArray(e.results)?e.results.filter(p):null;return s?(s.forEach((i,o)=>Pe(i,n[o])),e):(Pe(e,n[0]),e)}function Pe(e,t){t?.targetLocalUsagesHidden===!0&&(e.targetLocalUsagesHidden=!0,e.scope==="excluding target"&&delete e.scope)}function Ct(e,t){return Fe(e,t.dslDiagnostics??[])}function Fe(e,t){if(t.length===0)return e;const n=(0,V.readAgentText)(e),s=Pt(t);return(0,V.attachAgentText)({...e,dslDiagnostics:t.map(i=>({line:i.line,message:i.message}))},n?`${n.trimEnd()}
1
+ "use strict";var bt=exports&&exports.__createBinding||(Object.create?(function(e,t,n,s){s===void 0&&(s=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,s,i)}):(function(e,t,n,s){s===void 0&&(s=n),e[s]=t[n]})),It=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),Fe=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(n){var s=[];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(s[s.length]=i);return s},e(t)};return function(t){if(t&&t.__esModule)return t;var n={};if(t!=null)for(var s=e(t),i=0;i<s.length;i++)s[i]!=="default"&&bt(n,t,s[i]);return It(n,t),n}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.runInspect=Ce;const M=Fe(require("node:path")),ye=Fe(require("node:fs")),xt=require("node:crypto"),At=require("../client/http-client"),St=require("../shared/routes"),_t=require("../shared/protocol"),E=require("../shared/errors"),z=require("../shared/agent-text"),re=require("./shared"),k=require("./inspect-format"),w=require("./module-plan-cache"),he=require("./json-file-input"),ge=require("./inspect-graph"),be=require("./inspect-cycles"),Ie=require("./inspect-imports"),ee=require("./inspect-tree"),Q=require("../config/path-display"),A=require("./session-workspace"),Et=require("./entity-resolution");async function Ce(e,t,n,s={},i={}){if(vt(t))return Dt(e,t);const o=qt(e,t,n);if(o&&en(o))return Zt(e,t,o,s,i);if((0,ge.isInspectGraphRequest)(t,n))return(0,ge.runInspectGraph)(e,t,n);if((0,be.isInspectCyclesRequest)(t,n))return(0,be.runInspectCycles)(e,t,n);if((0,ee.isInspectTreeRequest)(t,n))return(0,ee.runInspectTree)(e,t,n);if(t[0]==="imports")return(0,Ie.runInspectImports)(e,t,n);i.allowModulePlan!==!0&&jn(t,n)&&ft();const c=await(0,re.resolveCompatibleTargetInstance)(e,_t.CLI_COMMAND_IDS.inspect,s),l=await(0,re.fetchEffectiveConfig)(c.entry,s),a=bn(e,t,n,l,i.allowModulePlan===!0,i.forceResults===!0);pn(e,a),await Nt(c.entry,a.payload,l,s),cn(e,a);const f=await(0,At.postJson)(c.entry,St.EXTENSION_ROUTES.inspect,a.payload,(0,re.extensionRequestOptions)(s));an(e,a,f);const d=(0,k.formatInspectResponse)(f,l,a.formatOptions);return Pt(un(Ft(e,f,d,a),a.revision),a)}async function Nt(e,t,n,s){const i=Array.isArray(t.requests)?t.requests.filter(p):[],o=new Map;for(const c of i){const l=r(c.op);if(l!=="code"&&l!=="slice"&&l!=="dependencies"&&l!=="members"&&l!=="usages")continue;const a=r(c.sourceFile),f=r(c.symbolName);if(!a||!f)continue;const d=r(c.symbolKind);if(d==="constructor")continue;const y={raw:f,symbolName:f,symbolKind:d},m=o.get(a)??[];m.push(y),o.set(a,m)}for(const[c,l]of o)await(0,Et.ensureSelectorsResolvable)(e,c,l,n,(0,re.extensionRequestOptions)(s))}function vt(e){return e[0]==="usages"&&O(e,"--from-file")!==null}function Dt(e,t){const n=O(t,"--from-file");if(!n)throw new E.CliError("USAGES_FROM_FILE_REQUIRED","inspect usages --from-file expects a saved usages handle or JSON file.");const s=(0,A.resolveSessionFileArgument)(e,n),i=(0,he.readJsonObjectFile)(e,s,"INVALID_USAGES_ARTIFACT"),o=K(t,"--focus"),c=xe(e,{detail:O(t,"--detail")??"locations",all:t.includes("--all"),limit:J(t,"--limit"),maxCodeLines:J(t,"--max-code-lines")??J(t,"--maxCodeLines")});if(c.detail==="summary")throw new E.CliError("INVALID_USAGES_DETAIL","inspect usages --from-file --detail expects locations or code.");if(c.detail!=="locations"&&c.detail!=="code")throw new E.CliError("INVALID_USAGES_DETAIL","inspect usages --detail expects locations or code.");const l=Te(e,i,o,c);return(0,z.attachAgentText)(l,Ae(e,l))}function Ft(e,t,n,s){const i=s.usagesDetails??[],o=Ct(n,s);if(i.length===0||i.every(y=>y===null||y.detail==="summary"))return o;const c=Array.isArray(t.results)?t.results.filter(p):[];if(c.length===0)return o;const l=Array.isArray(o.results)?o.results.filter(p):[o],a=Array.isArray(s.payload.requests)?s.payload.requests.filter(p):[],f=c.map((y,m)=>{const h=i[m],N=l[m]??{};if(a[m]?.targetLocalUsagesHidden===!0&&(y.targetLocalUsagesHidden=!0),y.op!=="usages"||h===void 0||h===null||h.detail==="summary")return N;const I=Te(e,y,[],h,!0);return Mt(N,I),I});kt(e,f),Bt(f);const d=f.length===1?f[0]:{results:f};return(0,z.attachAgentText)(d,Rt(e,d,o))}function Ct(e,t){const n=Array.isArray(t.payload.requests)?t.payload.requests.filter(p):[],s=Array.isArray(e.results)?e.results.filter(p):null;return s?(s.forEach((i,o)=>Pe(i,n[o])),e):(Pe(e,n[0]),e)}function Pe(e,t){t?.targetLocalUsagesHidden===!0&&(e.targetLocalUsagesHidden=!0,e.scope==="excluding target"&&delete e.scope)}function Pt(e,t){return Le(e,t.dslDiagnostics??[])}function Le(e,t){if(t.length===0)return e;const n=(0,z.readAgentText)(e),s=Lt(t);return(0,z.attachAgentText)({...e,dslDiagnostics:t.map(i=>({line:i.line,message:i.message}))},n?`${n.trimEnd()}
2
2
 
3
- ${s}`:s)}function Pt(e){return["dsl errors:",...e.map(t=>`line ${t.line}: ${t.message}`)].join(`
4
- `)}function Le(e){const t=e.dslDiagnostics;if(!Array.isArray(t))return{};const n=t.flatMap(s=>{if(!p(s))return[];const i=typeof s.line=="number"&&Number.isFinite(s.line)?s.line:null,o=typeof s.message=="string"&&s.message.length>0?s.message:null;return i!==null&&o!==null?[{line:i,message:o}]:[]});return n.length>0?{dslDiagnostics:n}:{}}function Oe(e,t,n,s,i=!1){const o=s.detail==="code"?Kt(e,t,n,s):jt(e,t,n,s);return $t(e,o,i),o}function Ft(e,t){return Ot(t??(0,S.readSessionStringPref)(e,"inspect.usages.detail","locations"))}function Ie(e,t){const n=t.all===!0,s=n?Number.MAX_SAFE_INTEGER:t.limit??(0,S.readSessionNumberPref)(e,"inspect.usages.maxLocations",12),i=n?Number.MAX_SAFE_INTEGER:t.limit??(0,S.readSessionNumberPref)(e,"inspect.usages.maxCodeBlocks",8);return{detail:Ft(e,t.detail),locationLimit:s,codeBlockLimit:i,maxCodeLines:t.maxCodeLines??(0,S.readSessionNumberPref)(e,"inspect.code.maxNonEmptyLines",120),all:n}}function Lt(e){return typeof e=="string"?e:null}function Ot(e){const t=e.trim().toLowerCase();if(t==="location")return"locations";if(t==="locations"||t==="code"||t==="summary")return t;throw new E.CliError("INVALID_USAGES_DETAIL","usages detail expects summary, locations, or code.",{detail:e})}function Tt(e,t){for(const n of["summary","saved","next","input","targetLocalUsagesHidden"])e[n]!==void 0&&(t[n]=e[n])}function $t(e,t,n){const s=Array.isArray(t.__viewItems)?t.__viewItems.filter(p):[];if(delete t.__viewItems,s.length===0)return;const i=Z({version:1,kind:"usages",source:"inspect",detail:a(t.detail)??"locations",target:a(t.target)??"",items:s}),o=(0,S.saveSessionResultViewJson)(e,Te(i),i);o&&(t.view=o.saved,n&&(t.__viewRecord=i))}function Mt(e,t){const n=t.map(r=>p(r.__viewRecord)?r.__viewRecord:null).filter(r=>r!==null&&a(r.kind)==="usages");if(n.length<=1)return;const s=Array.from(new Set(n.map(r=>a(r.detail)??"").filter(r=>r!==""))),i=n.flatMap(r=>Array.isArray(r.items)?r.items.filter(p):[]);if(i.length===0)return;const o=Z({version:1,kind:"usages",source:"inspect",detail:s.length===1?s[0]:"mixed",items:i}),l=(0,S.saveSessionResultViewJson)(e,Te(o),o);if(l)for(const r of t)p(r.__viewRecord)&&a(r.__viewRecord.kind)==="usages"&&(r.viewAllUsages=l.saved)}function Ut(e){for(const t of e)delete t.__viewRecord,delete t.__viewItems}function Te(e){return`res_${(0,bt.createHash)("sha256").update(JSON.stringify(e)).digest("hex").slice(0,8)}`}function Z(e){const t={};for(const[n,s]of Object.entries(e))s!==void 0&&s!==""&&(t[n]=s);return t}function Bt(e,t,n){if(Array.isArray(t.results)){const i=[],o=t.results.filter(p);let l=[];const r=()=>{if(l.length===0)return;const c=(0,$.formatInspectMixedAgentText)({results:l});c&&i.push(c),l=[]};for(const c of o){const u=a(c.detail);if(u==="locations"||u==="code"){r();const d=xe(e,c);d&&i.push(d);continue}if(a(c.op)==="usages"){r();const d=Rt(c);d&&i.push(d);continue}l.push(c)}return r(),kt(i,o),i.length>0?i.join(`
3
+ ${s}`:s)}function Lt(e){return["dsl errors:",...e.map(t=>`line ${t.line}: ${t.message}`)].join(`
4
+ `)}function Oe(e){const t=e.dslDiagnostics;if(!Array.isArray(t))return{};const n=t.flatMap(s=>{if(!p(s))return[];const i=typeof s.line=="number"&&Number.isFinite(s.line)?s.line:null,o=typeof s.message=="string"&&s.message.length>0?s.message:null;return i!==null&&o!==null?[{line:i,message:o}]:[]});return n.length>0?{dslDiagnostics:n}:{}}function Te(e,t,n,s,i=!1){const o=s.detail==="code"?zt(e,t,n,s):Vt(e,t,n,s);return Ut(e,o,i),o}function Ot(e,t){return $t(t??(0,A.readSessionStringPref)(e,"inspect.usages.detail","locations"))}function xe(e,t){const n=t.all===!0,s=n?Number.MAX_SAFE_INTEGER:t.limit??(0,A.readSessionNumberPref)(e,"inspect.usages.maxLocations",12),i=n?Number.MAX_SAFE_INTEGER:t.limit??(0,A.readSessionNumberPref)(e,"inspect.usages.maxCodeBlocks",8);return{detail:Ot(e,t.detail),locationLimit:s,codeBlockLimit:i,maxCodeLines:t.maxCodeLines??(0,A.readSessionNumberPref)(e,"inspect.code.maxNonEmptyLines",120),all:n}}function Tt(e){return typeof e=="string"?e:null}function $t(e){const t=e.trim().toLowerCase();if(t==="location")return"locations";if(t==="locations"||t==="code"||t==="summary")return t;throw new E.CliError("INVALID_USAGES_DETAIL","usages detail expects summary, locations, or code.",{detail:e})}function Mt(e,t){for(const n of["summary","saved","next","input","targetLocalUsagesHidden"])e[n]!==void 0&&(t[n]=e[n])}function Ut(e,t,n){const s=Array.isArray(t.__viewItems)?t.__viewItems.filter(p):[];if(delete t.__viewItems,s.length===0)return;const i=te({version:1,kind:"usages",source:"inspect",detail:r(t.detail)??"locations",target:r(t.target)??"",items:s}),o=(0,A.saveSessionResultViewJson)(e,$e(i),i);o&&(t.view=o.saved,n&&(t.__viewRecord=i))}function kt(e,t){const n=t.map(l=>p(l.__viewRecord)?l.__viewRecord:null).filter(l=>l!==null&&r(l.kind)==="usages");if(n.length<=1)return;const s=Array.from(new Set(n.map(l=>r(l.detail)??"").filter(l=>l!==""))),i=n.flatMap(l=>Array.isArray(l.items)?l.items.filter(p):[]);if(i.length===0)return;const o=te({version:1,kind:"usages",source:"inspect",detail:s.length===1?s[0]:"mixed",items:i}),c=(0,A.saveSessionResultViewJson)(e,$e(o),o);if(c)for(const l of t)p(l.__viewRecord)&&r(l.__viewRecord.kind)==="usages"&&(l.viewAllUsages=c.saved)}function Bt(e){for(const t of e)delete t.__viewRecord,delete t.__viewItems}function $e(e){return`res_${(0,xt.createHash)("sha256").update(JSON.stringify(e)).digest("hex").slice(0,8)}`}function te(e){const t={};for(const[n,s]of Object.entries(e))s!==void 0&&s!==""&&(t[n]=s);return t}function Rt(e,t,n){if(Array.isArray(t.results)){const i=[],o=t.results.filter(p);let c=[];const l=()=>{if(c.length===0)return;const a=(0,k.formatInspectMixedAgentText)({results:c});a&&i.push(a),c=[]};for(const a of o){const f=r(a.detail);if(f==="locations"||f==="code"){l();const d=Ae(e,a);d&&i.push(d);continue}if(r(a.op)==="usages"){l();const d=Kt(a);d&&i.push(d);continue}c.push(a)}return l(),jt(i,o),i.length>0?i.join(`
5
5
 
6
- `):null}const s=a(t.detail);return s==="locations"||s==="code"?xe(e,t):(0,V.readAgentText)(n)}function kt(e,t){const n=Array.from(new Set(t.map(i=>a(i.viewAllUsages)??"").filter(i=>i!=="")));if(n.length===0)return;const s=t.every(i=>a(i.op)==="usages");e.push(s?`view all: ${n[0]}`:["view all:",`usages: ${n[0]}`].join(`
7
- `))}function Rt(e){const t=[],n=a(e.target);t.push(n?`usages ${n}`:"usages");const s=a(e.summary);s&&t.push(s),Ae(t,e);const i=Array.isArray(e.items)?e.items.filter(p):[];for(const o of i){const l=a(o.entity)??"",r=a(o.summary)??"";t.push(`${l}: ${r}`.trim());const c=Array.isArray(o.usedBy)?o.usedBy.filter(u=>typeof u=="string"):[];t.push(...c)}return t.length>1?t.join(`
8
- `):null}function jt(e,t,n,s){const i=$e(t,n),o=[],r=i.map(c=>{const u=re(c);let d=0,m=0;const y=[],h=Array.isArray(c.usedBy)?c.usedBy.filter(p).flatMap(I=>{const O=Array.isArray(I.locations)?I.locations.filter(p):[],v=Q(e,a(I.file)??""),b=[],_=O.flatMap(D=>{const P=typeof D.line=="number"?D.line:0,f=p(D.container)?le(D.container):"";return d>=s.locationLimit?(m+=1,b.push({line:P,...f!==""?{container:f}:{}}),o.push(Z({name:u,text:f?`${v}:${P} ${f}`:`${v}:${P}`})),[]):(d+=1,[{line:P,...f!==""?{container:f}:{}}])});return b.length>0&&y.push({file:v,locations:b}),_.length>0?[{file:v,locations:_}]:[]}):[],A={entity:u,referenceCount:j(c.referenceCount),usedBy:h,...m>0?{hidden:`+ ${m} more locations`}:{}},C=y.length>0?{entity:u,referenceCount:m,usedBy:y}:null;return{displayItem:A,hiddenItem:C}}).map(c=>c.displayItem);return{op:"usages",detail:"locations",target:Q(e,a(t.targetPath)??""),summary:a(t.summary)??"",referenceCount:j(t.referenceCount),itemCount:j(t.itemCount),fileCount:j(t.fileCount),scopeLabel:Ue(e,t),targetMode:a(t.targetMode)??"",queryMode:a(t.queryMode)??"",targetLocalUsagesHidden:t.targetLocalUsagesHidden===!0,unused:Me(i),items:r,...o.length>0?{__viewItems:o}:{}}}function Kt(e,t,n,s){const i=s.maxCodeLines,o=[],l=new Set,r=new Map,c=new Map,u=[],d=$e(t,n);for(const m of d){const y=re(m),h=Array.isArray(m.usedBy)?m.usedBy.filter(p):[];for(const A of h){const C=a(A.file);if(!C)continue;const I=Array.isArray(A.locations)?A.locations.filter(p):[];for(const O of I){const v=p(O.container)?O.container:null,b=v&&p(v.range)?v.range:null,_=b&&p(b.start)?b.start:null,D=b&&p(b.end)?b.end:null;if(!_||!D||typeof _.line!="number"||typeof _.character!="number"||typeof D.line!="number"||typeof D.character!="number")continue;const P=`${y}:${C}:${_.line}:${_.character}:${D.line}:${D.character}`;if(l.has(P))continue;l.add(P);const f=r.get(y)??0,M=Wt(C,_.line,_.character,D.line,D.character),U=_.line+1,G={entity:y,file:Q(e,C),container:v?le(v):"",line:U,code:M};if(f>=s.codeBlockLimit){c.set(y,(c.get(y)??0)+1),u.push(Z({name:y,text:Ke(G,!1).join(`
9
- `).trim()}));continue}r.set(y,f+1);const x=Qt(M),ee=`code omitted: ${x} non-empty lines; exceeds inspect.code.maxNonEmptyLines=${i}`;x>i&&u.push(Z({name:y,text:Ke(G,!1).join(`
10
- `).trim()})),o.push({entity:y,file:Q(e,C),container:v?le(v):"",line:U,...x<=i?{code:M}:{omitted:ee,compactCode:wt(M)}})}}}return{op:"usages",detail:"code",target:Q(e,a(t.targetPath)??""),summary:a(t.summary)??"",referenceCount:j(t.referenceCount),itemCount:j(t.itemCount),fileCount:j(t.fileCount),scopeLabel:Ue(e,t),targetMode:a(t.targetMode)??"",queryMode:a(t.queryMode)??"",targetLocalUsagesHidden:t.targetLocalUsagesHidden===!0,unused:Me(d),blocks:o,hiddenBlocks:Array.from(c.entries()).map(([m,y])=>({entity:m,hidden:`+ ${y} more code blocks`})),...u.length>0?{__viewItems:u}:{}}}function $e(e,t){const n=Array.isArray(e.items)?e.items.filter(p):[];if(t.length===0)return n;const s=new Set(t.map(i=>i.trim()).filter(Boolean));return n.filter(i=>{const o=Vt(i),l=re(i);return s.has(o)||s.has(l)})}function Vt(e){return p(e.entity)?a(e.entity.name)??"":""}function re(e){return p(e.entity)?le(e.entity):""}function Me(e){return e.filter(t=>j(t.referenceCount)===0).map(t=>re(t)).filter(t=>t!=="")}function Ue(e,t){const n=K(t.usageScopes)??[];return n.length===0?"project":n.length===1?Q(e,n[0]):`${n.length} scopes`}function wt(e){const n=e.trim().split(/\r?\n/).map(i=>i.trimEnd()).filter(i=>i.trim()!=="")[0]??"";if(!n)return"";const s=n.indexOf("{");return s>=0?`${n.slice(0,s+1)}...}`:`${n} ...`}function Gt(e,t,n){const s=e.slice(0,t),i=e.length-s.length;return i>0?`${s.join(", ")}, + ${i} ${n}`:s.join(", ")}function j(e){return typeof e=="number"&&Number.isFinite(e)?e:0}function le(e){const t=Array.isArray(e.path)?e.path.filter(n=>typeof n=="string"&&n.trim()!==""):[];return t.length>0?t.join("."):a(e.name)??""}function xe(e,t){const n=a(t.detail);if(j(t.referenceCount)===0){const r=a(t.target),c=a(t.scopeLabel)??"project",u=[r?`usages ${r}`:"usages",`0 refs in ${c}`];Ae(u,t);const d=j(t.itemCount);return(a(t.targetMode)==="directory"||a(t.queryMode)!=="explicit")&&d>0&&u.push(`symbols checked: ${d}`),u.join(`
11
- `)}const s=[`usages ${n??"detail"}`];if(Ae(s,t),n==="code"){const r=Array.isArray(t.blocks)?t.blocks.filter(p):[],{ownerGroups:c,standalone:u}=ae(r,d=>a(d.entity)??"");for(const[d,m]of c){s.push(""),s.push(`// ${d}:`);for(const[y,h]of Se(m,A=>ce(a(A.entity)??"").name))y&&s.push(`// ${y}`),s.push(...Re(e,t,h))}if(u.length>0){c.length>0&&s.push("");for(const[d,m]of Se(u,y=>a(y.entity)??""))d&&s.push(`// ${d}`),s.push(...Re(e,t,m))}return ke(s,t),Be(s,t),s.join(`
6
+ `):null}const s=r(t.detail);return s==="locations"||s==="code"?Ae(e,t):(0,z.readAgentText)(n)}function jt(e,t){const n=Array.from(new Set(t.map(i=>r(i.viewAllUsages)??"").filter(i=>i!=="")));if(n.length===0)return;const s=t.every(i=>r(i.op)==="usages");e.push(s?`view all: ${n[0]}`:["view all:",`usages: ${n[0]}`].join(`
7
+ `))}function Kt(e){const t=[],n=r(e.target);t.push(n?`usages ${n}`:"usages");const s=r(e.summary);s&&t.push(s),Se(t,e);const i=Array.isArray(e.items)?e.items.filter(p):[];for(const o of i){const c=r(o.entity)??"",l=r(o.summary)??"";t.push(`${c}: ${l}`.trim());const a=Array.isArray(o.usedBy)?o.usedBy.filter(f=>typeof f=="string"):[];t.push(...a)}return t.length>1?t.join(`
8
+ `):null}function Vt(e,t,n,s){const i=Me(t,n),o=[],l=i.map(a=>{const f=le(a);let d=0,y=0;const m=[],h=Array.isArray(a.usedBy)?a.usedBy.filter(p).flatMap(I=>{const T=Array.isArray(I.locations)?I.locations.filter(p):[],S=X(e,r(I.file)??""),L=[],C=T.flatMap(D=>{const F=typeof D.line=="number"?D.line:0,u=p(D.container)?ce(D.container):"";return d>=s.locationLimit?(y+=1,L.push({line:F,...u!==""?{container:u}:{}}),o.push(te({name:f,text:u?`${S}:${F} ${u}`:`${S}:${F}`})),[]):(d+=1,[{line:F,...u!==""?{container:u}:{}}])});return L.length>0&&m.push({file:S,locations:L}),C.length>0?[{file:S,locations:C}]:[]}):[],N={entity:f,referenceCount:V(a.referenceCount),usedBy:h,...y>0?{hidden:`+ ${y} more locations`}:{}},P=m.length>0?{entity:f,referenceCount:y,usedBy:m}:null;return{displayItem:N,hiddenItem:P}}).map(a=>a.displayItem);return{op:"usages",detail:"locations",target:X(e,r(t.targetPath)??""),summary:r(t.summary)??"",referenceCount:V(t.referenceCount),itemCount:V(t.itemCount),fileCount:V(t.fileCount),scopeLabel:ke(e,t),targetMode:r(t.targetMode)??"",queryMode:r(t.queryMode)??"",targetLocalUsagesHidden:t.targetLocalUsagesHidden===!0,unused:Ue(i),items:l,...o.length>0?{__viewItems:o}:{}}}function zt(e,t,n,s){const i=s.maxCodeLines,o=[],c=new Set,l=new Map,a=new Map,f=[],d=Me(t,n);for(const y of d){const m=le(y),h=Array.isArray(y.usedBy)?y.usedBy.filter(p):[];for(const N of h){const P=r(N.file);if(!P)continue;const I=Array.isArray(N.locations)?N.locations.filter(p):[];for(const T of I){const S=p(T.container)?T.container:null,L=S&&p(S.range)?S.range:null,C=L&&p(L.start)?L.start:null,D=L&&p(L.end)?L.end:null;if(!C||!D||typeof C.line!="number"||typeof C.character!="number"||typeof D.line!="number"||typeof D.character!="number")continue;const F=`${m}:${P}:${C.line}:${C.character}:${D.line}:${D.character}`;if(c.has(F))continue;c.add(F);const u=l.get(m)??0,$=Xt(P,C.line,C.character,D.line,D.character),g=C.line+1,_={entity:m,file:X(e,P),container:S?ce(S):"",line:g,code:$};if(u>=s.codeBlockLimit){a.set(m,(a.get(m)??0)+1),f.push(te({name:m,text:Ve(_,!1).join(`
9
+ `).trim()}));continue}l.set(m,u+1);const x=Yt($),ne=`code omitted: ${x} non-empty lines; exceeds inspect.code.maxNonEmptyLines=${i}`;x>i&&f.push(te({name:m,text:Ve(_,!1).join(`
10
+ `).trim()})),o.push({entity:m,file:X(e,P),container:S?ce(S):"",line:g,...x<=i?{code:$}:{omitted:ne,compactCode:wt($)}})}}}return{op:"usages",detail:"code",target:X(e,r(t.targetPath)??""),summary:r(t.summary)??"",referenceCount:V(t.referenceCount),itemCount:V(t.itemCount),fileCount:V(t.fileCount),scopeLabel:ke(e,t),targetMode:r(t.targetMode)??"",queryMode:r(t.queryMode)??"",targetLocalUsagesHidden:t.targetLocalUsagesHidden===!0,unused:Ue(d),blocks:o,hiddenBlocks:Array.from(a.entries()).map(([y,m])=>({entity:y,hidden:`+ ${m} more code blocks`})),...f.length>0?{__viewItems:f}:{}}}function Me(e,t){const n=Array.isArray(e.items)?e.items.filter(p):[];if(t.length===0)return n;const s=new Set(t.map(i=>i.trim()).filter(Boolean));return n.filter(i=>{const o=Gt(i),c=le(i);return s.has(o)||s.has(c)})}function Gt(e){return p(e.entity)?r(e.entity.name)??"":""}function le(e){return p(e.entity)?ce(e.entity):""}function Ue(e){return e.filter(t=>V(t.referenceCount)===0).map(t=>le(t)).filter(t=>t!=="")}function ke(e,t){const n=R(t.usageScopes)??[];return n.length===0?"project":n.length===1?X(e,n[0]):`${n.length} scopes`}function wt(e){const n=e.trim().split(/\r?\n/).map(i=>i.trimEnd()).filter(i=>i.trim()!=="")[0]??"";if(!n)return"";const s=n.indexOf("{");return s>=0?`${n.slice(0,s+1)}...}`:`${n} ...`}function Ht(e,t,n){const s=e.slice(0,t),i=e.length-s.length;return i>0?`${s.join(", ")}, + ${i} ${n}`:s.join(", ")}function V(e){return typeof e=="number"&&Number.isFinite(e)?e:0}function ce(e){const t=Array.isArray(e.path)?e.path.filter(n=>typeof n=="string"&&n.trim()!==""):[];return t.length>0?t.join("."):r(e.name)??""}function Ae(e,t){const n=r(t.detail);if(V(t.referenceCount)===0){const l=r(t.target),a=r(t.scopeLabel)??"project",f=[l?`usages ${l}`:"usages",`0 refs in ${a}`];Se(f,t);const d=V(t.itemCount);return(r(t.targetMode)==="directory"||r(t.queryMode)!=="explicit")&&d>0&&f.push(`symbols checked: ${d}`),f.join(`
11
+ `)}const s=[`usages ${n??"detail"}`];if(Se(s,t),n==="code"){const l=Array.isArray(t.blocks)?t.blocks.filter(p):[],{ownerGroups:a,standalone:f}=ae(l,d=>r(d.entity)??"");for(const[d,y]of a){s.push(""),s.push(`// ${d}:`);for(const[m,h]of _e(y,N=>ue(r(N.entity)??"").name))m&&s.push(`// ${m}`),s.push(...je(e,t,h))}if(f.length>0){a.length>0&&s.push("");for(const[d,y]of _e(f,m=>r(m.entity)??""))d&&s.push(`// ${d}`),s.push(...je(e,t,y))}return Re(s,t),Be(s,t),s.join(`
12
12
  `).replace(/\n{3,}/g,`
13
13
 
14
- `).trimEnd()}const i=Array.isArray(t.items)?t.items.filter(p).filter(r=>j(r.referenceCount)>0):[],{ownerGroups:o,standalone:l}=ae(i,r=>a(r.entity)??"");for(const[r,c]of o){s.push(""),s.push(`// ${r}:`);for(const u of c)s.push(...Ve(u,!1))}l.length>0&&o.length>0&&s.push("");for(const r of l)s.push(...Ve(r,!0));return ke(s,t),Be(s,t),s.join(`
15
- `).trimEnd()}function Be(e,t){const n=a(t.view);n&&(e.length>0&&e[e.length-1]!==""&&e.push(""),e.push(`view: ${n}`))}function ke(e,t){const n=Array.isArray(t.unused)?t.unused.filter(s=>typeof s=="string"&&s!==""):[];if(n.length!==0){if(a(t.queryMode)==="explicit"){e.push(""),e.push(`unused: ${Gt(n,2,"more")}`);return}a(t.targetMode)==="file"&&(e.push(""),e.push(`unused symbols: ${n.length}`))}}function Ae(e,t){t.targetLocalUsagesHidden===!0&&e.push("target-local usages hidden; use +includeTarget to show")}function Re(e,t,n){const s=[],i=Se(n,r=>a(r.file)??"");for(const[r,c]of i)r&&s.push(`// ${r}`),s.push(...zt(e,c));const o=a(n[0]?.entity)??"",l=Jt(t,"hiddenBlocks",o);return l&&s.push(`// ${l}`),s}function zt(e,t){const n=[],{ownerGroups:s,standalone:i}=ae(t,o=>a(o.container)??"");for(const[o,l]of s)n.push(`// ${o}:`),n.push(...je(e,l));return i.length>0&&n.push(...je(e,i)),n}function je(e,t){const n=[];for(const s of t){if(typeof s.code=="string")n.push(s.code.trimEnd());else if(typeof s.omitted=="string"){const i=(0,S.useSessionGuidance)(e,"inspect.usages.codeOmitted",s.omitted)??"code omitted";n.push(`// ${i}`),typeof s.compactCode=="string"&&s.compactCode!==""&&n.push(s.compactCode)}n.push("")}return n}function Ke(e,t=!0){const n=[],s=a(e.entity);t&&s&&n.push(`// ${s}`);const i=a(e.file)??"",o=typeof e.line=="number"?` l${e.line}`:"";(i||o)&&n.push(`// ${i}${o}`.trim());const l=a(e.code);return l&&n.push(l.trimEnd()),n}function Ve(e,t){const n=a(e.entity)??"",s=ce(n),i=[`${t?n:s.name}:`],o=Array.isArray(e.usedBy)?e.usedBy.filter(p):[];for(const r of o){const c=a(r.file)??"",u=Array.isArray(r.locations)?r.locations.filter(p):[];if(u.length!==0){if(u.length===1){const[d]=u,m=typeof d?.line=="number"?d.line:0,y=a(d?.container);i.push(y?`${c}:${m} ${y}`:`${c}:${m}`);continue}i.push(`${c}:`),i.push(...Ht(u))}}const l=a(e.hidden);return l&&i.push(l),i}function Ht(e){const t=[],{ownerGroups:n,standalone:s}=ae(e,i=>a(i.container)??"");for(const[i,o]of n){t.push(`// ${i}:`);for(const l of o){const r=typeof l.line=="number"?l.line:0,c=ce(a(l.container)??"").name;t.push(c?`${c} l${r}`:`l${r}`)}}for(const i of s){const o=typeof i.line=="number"?i.line:0,l=a(i.container);t.push(l?`${l} l${o}`:`l${o}`)}return t}function Jt(e,t,n){const i=(Array.isArray(e[t])?e[t].filter(p):[]).find(o=>a(o.entity)===n);return i?a(i.hidden):null}function ae(e,t){const n=new Map,s=[];for(const i of e){const o=ce(t(i));if(!o.owner){s.push(i);continue}const l=n.get(o.owner)??[];l.push(i),n.set(o.owner,l)}return{ownerGroups:Array.from(n.entries()),standalone:s}}function ce(e){const t=e.lastIndexOf(".");return t<=0||t>=e.length-1?{owner:null,name:e}:{owner:e.slice(0,t),name:e.slice(t+1)}}function Se(e,t){const n=new Map;for(const s of e){const i=t(s),o=n.get(i)??[];o.push(s),n.set(i,o)}return Array.from(n.entries())}function Wt(e,t,n,s,i){const o=ye.readFileSync(e,"utf8"),l=we(o,t,n),r=we(o,s,i);return o.slice(l,r)}function we(e,t,n){let s=0,i=0;for(;i<e.length&&s<t;){const o=e.charCodeAt(i);o===13?(i+=e.charCodeAt(i+1)===10?2:1,s+=1):o===10?(i+=1,s+=1):i+=1}return Math.max(0,Math.min(i+n,e.length))}function Qt(e){return e.split(/\r?\n/).filter(t=>t.trim()!=="").length}function Q(e,t){const n=L.relative(e,t);return(n&&!n.startsWith("..")&&!L.isAbsolute(n)?n:t).replace(/\\/g,"/")}async function qt(e,t,n,s,i){const o=pe(n),l=[],r=[],c=[],u=(0,Y.buildDisplayPathAliases)(e,(0,S.readEffectiveSessionPathAliases)(e)),d=[];for(const b of o){if(!p(b))throw new E.CliError("INVALID_INSPECT_REQUEST","Inspect request must be an object.");a(b.op)==="graph"?(r.push(Zt(b)),d.push("graph")):a(b.op)==="imports"?(c.push(b),d.push("imports")):(l.push(b),d.push("inspect"))}const m=l.length>0?en((0,V.stripAgentText)(await Ce(e,["--stdin"],{requests:l},s,{...i,forceResults:!0}))):[],y=r.length>0?tn((0,V.stripAgentText)((0,ge.runInspectGraph)(e,["graph","--stdin"],{requests:r}))):[],h=c.map(b=>(0,be.buildInspectImportsResult)(e,{file:a(b.file)??a(b.fromFile)??a(b.sourceFile)??a(n.file)??"",ranges:B(b.ranges)!==!1,dynamic:B(b.dynamic)!==!1},u)),A=[];let C=0,I=0,O=0;for(const b of d)if(b==="graph"){const _=y[I++];_&&A.push(_)}else if(b==="imports"){const _=h[O++];_&&A.push(_)}else{const _=m[C++];_&&A.push(_)}const v={results:(0,be.mergeDirectoryFallbackResults)(A)};return Fe((0,V.attachAgentText)(v,(0,$.formatInspectMixedAgentText)(v)),Le(n).dslDiagnostics??[])}function Xt(e,t,n){if(t[0]==="graph")return null;if(t.includes("--stdin"))return p(n)?n:null;const s=F(t,"--from-json");return s?(0,he.readJsonObjectFile)(e,s,"INVALID_INSPECT_JSON_FILE"):null}function Yt(e){return pe(e).some(t=>p(t)&&(a(t.op)==="graph"||a(t.op)==="imports"))}function Zt(e){const t={...e};return delete t.op,delete t.sourceFile,t}function en(e){return Array.isArray(e.results)?e.results.filter(p).map(Ge):[Ge(e)]}function Ge(e){return e.op==="dependencies"?{...e,op:"deps"}:e}function tn(e){return Array.isArray(e.results)?e.results.filter(p).map(t=>({op:"graph",...t})):[{op:"graph",...nn(e)}]}function nn(e){const t={...e};return delete t.operation,delete t.next,delete t.last,typeof t.saved=="string"&&delete t.graphFile,t}function sn(e,t){(Array.isArray(t.payload.requests)?t.payload.requests:[]).forEach((s,i)=>{if(!p(s)||s.op!=="modulePlan"||s.previewFiles!==!0)return;const o=(0,w.normalizeModulePlanCacheRequest)(s),l=(0,w.buildModulePlanId)(o),r=a(s.previewDir),c=(0,w.resolveModulePlanPreviewDir)(e,l,r??void 0);s.previewDir=c,s.previewPatch=s.previewPatch!==!1,t.cachePlans.push({index:i,planId:l,normalizedRequest:o,previewDir:c})})}function on(e,t,n){if(!(t.cachePlans.length===0||!Array.isArray(n.results)))for(const s of t.cachePlans){const i=n.results[s.index];if(!p(i))continue;const o=a(s.normalizedRequest.sourceFile);if(!o)continue;const l=(0,w.hashFile)(o),r=(0,w.buildModulePlanHash)(s.normalizedRequest,l,i),c={planId:s.planId,planHash:r,createdAt:new Date().toISOString(),cwd:L.resolve(e),sourceFile:o,sourceHash:l,executable:i.ok!==!1,normalizedRequest:s.normalizedRequest,inspectPayload:t.payload,previewDir:s.previewDir,previewResult:i};(0,w.writeModulePlanRecord)(e,c),i.planId=s.planId,i.planHash=r,i.cached=!0,i.executable=i.ok!==!1,i.next=i.ok===!1?`Revise with: aib modulePlan revise --plan ${s.planId} --stdin`:`Run modulePlan apply ${s.planId} if the plan matches intent.`}}function rn(e,t){if(!t||!Array.isArray(e.results)||!p(e.results[0]))return e;const n=e.results[0];n.operation="modulePlan.revise",n.fromPlanId=t.fromPlanId,n.changes=t.changes;const s=En(n),i=t.previousBlocking.filter(o=>!s.includes(o));return i.length>0&&(n.resolved=i),n.remainingBlocking=Array.isArray(n.blocking)?n.blocking:[],delete n.blocking,delete n.boundary,delete n.targets,delete n.moduleCount,delete n.preview,delete n.facade,n.next=n.ok===!1||n.executable===!1?`Revise again from ${typeof n.planId=="string"?n.planId:t.fromPlanId}.`:`aib modulePlan apply ${typeof n.planId=="string"?n.planId:t.fromPlanId}`,(0,V.attachAgentText)(e,ln(n))}function ln(e){const t=[`modulePlan.revise ${typeof e.planId=="string"?e.planId:""}`.trim()];if(typeof e.fromPlanId=="string"&&t.push(`from: ${e.fromPlanId}`),typeof e.integrity=="string"&&t.push(e.integrity),p(e.api)&&typeof e.api.status=="string"){const n=typeof e.api.before=="number"?e.api.before:null,s=typeof e.api.after=="number"?e.api.after:null;t.push(n!==null&&s!==null?`api: ${e.api.status} ${n}->${s}`:`api: ${e.api.status}`)}if(typeof e.cycles=="string"&&t.push(`cycles: ${e.cycles}`),Array.isArray(e.changes)&&e.changes.length>0){t.push("changes:");for(const n of e.changes.filter(s=>typeof s=="string"))t.push(n)}return Array.isArray(e.resolved)&&e.resolved.length>0&&t.push(`resolved: ${e.resolved.length}`),Array.isArray(e.remainingBlocking)&&t.push(`remainingBlocking: ${e.remainingBlocking.length}`),typeof e.next=="string"&&t.push(`next: ${e.next}`),t.join(`
16
- `)}function an(e,t){if(!Array.isArray(t.payload.requests))return;const n=t.payload.requests.filter(p),s=new Map,i=[],o=new Map;for(let l=0;l<n.length;l+=1){const r=n[l],c=a(r.sourceFile);if(!c||!cn(a(r.op))||!Pn(c)){o.set(l,i.length),i.push(r);continue}let u=s.get(c);u?o.set(l,i.findIndex(m=>a(m.sourceFile)===c&&m.op==="directoryFallback")):(u=un(e,c),s.set(c,u),o.set(l,i.length),i.push(fn(u)));const d=dn(a(r.op));u.ops.includes(d)||u.ops.push(d)}s.size!==0&&(t.payload.requests=i,t.formatOptions.toFiles&&(t.formatOptions.toFiles=ue(t.formatOptions.toFiles,o,i.length)),t.formatOptions.saves&&(t.formatOptions.saves=ue(t.formatOptions.saves,o,i.length)),t.formatOptions.shows&&(t.formatOptions.shows=ze(t.formatOptions.shows,o,i.length)),t.formatOptions.ranges&&(t.formatOptions.ranges=ze(t.formatOptions.ranges,o,i.length)),t.formatOptions.parentNames&&(t.formatOptions.parentNames=ue(t.formatOptions.parentNames,o,i.length)),t.usagesDetails&&(t.usagesDetails=ue(t.usagesDetails,o,i.length)))}function cn(e){return e==="file"||e==="exports"||e==="members"||e==="code"||e==="dependencies"||e==="slice"}function un(e,t){const n=pn(e,t),s=(0,S.readEffectiveSessionPathAliases)(e),i=(0,Y.compactDisplayPath)(e,t,(0,Y.buildDisplayPathAliases)(e,s)),o=(0,oe.buildInspectTreeResult)(e,{scope:t,displayScope:i,depth:n,limit:40,aliases:s}),l=[];return{sourceFile:t,displayPath:i,ops:l,command:`aib inspect tree ${i} --depth ${n}`,result:{op:"directoryFallback",ok:!0,sourceFile:t,directory:i,skippedOps:l,command:`aib inspect tree ${i} --depth ${n}`,tree:o,lines:Array.isArray(o.lines)?o.lines:[]}}}function fn(e){return{op:"directoryFallback",sourceFile:e.sourceFile,fallback:e.result}}function pn(e,t){for(let n=1;n<=4;n+=1){const s=(0,oe.buildInspectTreeResult)(e,{scope:t,depth:n,limit:1});if(typeof s.files=="number"&&s.files>0)return n}return 2}function ue(e,t,n){const s=Array.from({length:n},()=>null);for(const[i,o]of t.entries())s[o]===null&&(s[o]=e[i]??null);return s}function ze(e,t,n){const s=Array.from({length:n},()=>!1);for(const[i,o]of t.entries())s[o]=s[o]||(e[i]??!1);return s}function dn(e){return e==="dependencies"?"deps":e??"inspect"}function mn(e,t,n,s,i,o){const l=Je(t),c=!(t.includes("--no-ranges")||t.includes("--noRanges"))&&(l==="code"||l==="file")||t.includes("--ranges")||l==="exports"&&(0,S.readSessionBooleanPref)(e,"inspect.exports.ranges",!1),u=t.includes("--details"),d=t.includes("--resolve-star")||l==="exports"&&(0,S.readSessionBooleanPref)(e,"inspect.exports.resolveStar",!1),m=t.includes("--local-only"),y=Fn(e,t),h=nt(t,"--offset"),A=H(t,"--limit")??(l==="members"?(0,S.readSessionNumberPref)(e,"inspect.members.maxItems",20):null),C=t.includes("--all")||l==="members"&&(0,S.readSessionBooleanPref)(e,"inspect.members.all",!1),I=F(t,"--to-file")??void 0,O=F(t,"--save")??void 0,v=l==="code"&&(t.includes("--no-show")||t.includes("--noShow")),b=t.includes("--show"),_=v?!1:b||l==="code"&&(0,S.readSessionBooleanPref)(e,"inspect.code.show",!0),D=(0,S.readSessionBooleanPref)(e,"inspect.code.meta",!0),P=l==="usages"?Ie(e,{detail:F(t,"--detail"),all:t.includes("--all"),limit:H(t,"--limit"),maxCodeLines:H(t,"--max-code-lines")??H(t,"--maxCodeLines")}):null,f=F(t,"--bundle-save")??void 0,M=F(t,"--preview-dir")??void 0,U=F(t,"--from-json")??void 0,G=F(t,"--parent")??void 0,x=G?(0,$.parseInspectSelector)(G,s).symbolName:void 0,ee=(0,Y.buildDisplayPathAliases)(e,(0,S.readEffectiveSessionPathAliases)(e)),te=[];if(I!==void 0&&O!==void 0)throw new E.CliError("INSPECT_OUTPUT_TARGET_CONFLICT","Use either --to-file or --save, not both.");const q={cwd:e,includeRanges:c,displayPathAliases:ee,pathAliasHints:te,details:u,localOnly:m,maxCodeLines:y,forceResults:o,show:_,codeMeta:D,...x!==void 0?{parentName:x,parentNames:[x]}:{},...I!==void 0?{toFile:I}:{},...O!==void 0?{save:O}:{},...f!==void 0?{bundleSave:f}:{},...M!==void 0?{previewDir:k(e,M)}:{}};if(U!==void 0){if(t.includes("--stdin")||n!==void 0)throw new E.CliError("INSPECT_INPUT_SOURCE_CONFLICT","Use either inspect --stdin or inspect --from-json, not both.");if(t.includes("--revise"))throw new E.CliError("INSPECT_REVISE_FROM_JSON_UNSUPPORTED","modulePlan revise currently expects --stdin.");const g=He((0,he.readJsonObjectFile)(e,U,"INVALID_INSPECT_JSON_FILE"),Je(t)),z=c||st(g),N=We(e,g,s,z,d,m,{memberOffset:h,memberLimit:A,memberAll:C},i);return{payload:N.payload,cachePlans:[],formatOptions:{...q,includeRanges:z,toFiles:N.toFiles,saves:N.saves,shows:N.shows,ranges:N.ranges,parentNames:N.parentNames,...f===void 0&&N.bundleSave!==void 0?{bundleSave:N.bundleSave}:{}},usagesDetails:N.usagesDetails}}if(n!==void 0){if(!p(n))throw new E.CliError("INVALID_INSPECT_STDIN","inspect input expects a JSON object payload.");if(t.includes("--revise"))return yn(e,t,n,s);const g=He(n,l),z=c||st(g),N=We(e,g,s,z,d,m,{memberOffset:h,memberLimit:A,memberAll:C},i);return{payload:N.payload,cachePlans:[],formatOptions:{...q,includeRanges:z,toFiles:N.toFiles,saves:N.saves,shows:N.shows,ranges:N.ranges,parentNames:N.parentNames,...f===void 0&&N.bundleSave!==void 0?{bundleSave:N.bundleSave}:{}},usagesDetails:N.usagesDetails,...Le(n)}}return{payload:hn(e,t,s,c,d,m,{memberOffset:h,memberLimit:A,memberAll:C},i),formatOptions:q,cachePlans:[],...P!==null?{usagesDetails:[P]}:{}}}function He(e,t){return!t||e.op!==void 0?e:{op:t,...e}}function Je(e){return e.filter(n=>!n.startsWith("--")&&!it(e,n))[0]??null}function yn(e,t,n,s){const i=F(t,"--plan");if(!i)throw new E.CliError("MODULE_PLAN_REVISE_PLAN_REQUIRED","modulePlan revise expects --plan <planId>.");const o=(0,w.readModulePlanRecord)(e,i),l=gn(e,o.previewResult,o.normalizedRequest,n,s),r=(0,w.buildModulePlanId)(l),c=(0,w.resolveModulePlanPreviewDir)(e,r);return{payload:{requests:[{...l,previewFiles:!0,previewPatch:!0,previewDir:c}]},formatOptions:{cwd:e,includeRanges:!1,displayPathAliases:(0,Y.buildDisplayPathAliases)(e,(0,S.readEffectiveSessionPathAliases)(e)),pathAliasHints:[],localOnly:!1,details:!1,maxCodeLines:(0,S.readSessionNumberPref)(e,"inspect.code.maxNonEmptyLines",120),codeMeta:(0,S.readSessionBooleanPref)(e,"inspect.code.meta",!0),previewDir:c},cachePlans:[{index:0,planId:r,normalizedRequest:l,previewDir:c}],revision:{fromPlanId:i,changes:Sn(e,o.normalizedRequest,l),previousBlocking:_n(o.previewResult,s)}}}function hn(e,t,n,s,i,o,l,r){const c=t.filter(I=>!I.startsWith("--")&&!it(t,I)),[u,d,m]=c;if(!u||!d)throw new E.CliError("INVALID_INSPECT_COMMAND","Expected: aib inspect <file|imports|exports|members|code|slice|deps|usages|duplicates> <file-or-dir> [entity].",{examples:["aib inspect file src/example.ts","aib inspect imports src/example.ts","aib inspect exports src/example.ts","aib inspect members src/example.ts c:Example","aib inspect code src/example.ts f:helper","aib inspect deps src/example.ts c:Example","aib inspect usages src/example.ts f:helper --scope src/main","aib inspect duplicates src/scripts --detail code"]});if(!rt(u))throw new E.CliError("INVALID_INSPECT_OP","Expected inspect op to be file, imports, exports, members, code, slice, deps, usages, duplicates, graph, tree, or cycles.");if(at(u,r),F(t,"--save")&&u!=="code"&&u!=="slice"&&u!=="usages"&&u!=="duplicate"&&u!=="duplicates")throw new E.CliError("INVALID_INSPECT_SAVE","inspect --save can be used only with code, slice, usages, or duplicates operations.");const y=lt(u),h={op:y,sourceFile:k(e,d),ranges:s||y==="code"||y==="slice",resolveStar:i,localOnly:y==="file"&&o};if(tt(h,l),y==="members"||y==="code"||y==="dependencies"||y==="slice"){if(!m)throw new E.CliError("INSPECT_ENTITY_REQUIRED",`inspect ${u} expects an entity selector.`);_e(h,m,n)}if(y==="usages"&&m&&_e(h,m,n),y==="duplicates"){h.detail=F(t,"--detail")??"locations",h.mode=F(t,"--mode")??"both";const I=H(t,"--limit"),O=nt(t,"--offset");I!==null&&(h.limit=I),O!==null&&(h.offset=O);const v=Bn(t,n);v.length>0&&(h.kinds=v);const b=de([...m?[m]:[],...R(t,"--entity"),...R(t,"--entities").flatMap(P=>P.split(","))],n);b.length>0&&(h.duplicateEntities=b);const _=de([...R(t,"--exclude"),...R(t,"--excludes").flatMap(P=>P.split(","))],n);_.length>0&&(h.duplicateExclude=_);const D=ft(e,[...R(t,"--path-exclude"),...R(t,"--path-excludes").flatMap(P=>P.split(",")),...R(t,"--exclude-path"),...R(t,"--exclude-paths").flatMap(P=>P.split(","))]);D.length>0&&(h.duplicatePathExclude=D)}const A=R(t,"--scope");if(y==="usages"&&A.length>0&&(h.scope=A.map(I=>k(e,I))),y==="duplicates"&&A.length>0&&(h.scope=A.map(I=>k(e,I))),y==="usages"){h.excludeTarget=t.includes("--exclude-target")||t.includes("--excludeTarget")||!1;const I=t.includes("--include-target")||t.includes("--includeTarget"),O=(0,S.readSessionBooleanPref)(e,"inspect.usages.excludeTarget",!1);I?h.excludeTarget=!1:h.excludeTarget===!0||O?h.excludeTarget=!0:Ze(e,a(h.sourceFile)??"",K(h.scope)??[])&&(h.excludeTarget=!0,h.targetLocalUsagesHidden=!0)}const C=F(t,"--parent");if(C){const I=(0,$.parseInspectSelector)(C,n);h.parentName=I.symbolName,I.symbolKind&&(h.parentKind=I.symbolKind)}return{requests:[h]}}function We(e,t,n,s,i,o,l,r){const c=pe(t),u=[],d=[],m=[],y=[],h=[],A=[],C=Lt(t.detail),I=B(t.all),O=J(t.limit),v=J(t.maxCodeLines),b=B(t.excludeTarget),_=B(t.includeTarget),D=a(t.bundleSave)??a(t.bundle)??a(t.saveBundle)??void 0;return{payload:{requests:c.map((f,M)=>{if(!p(f))throw new E.CliError("INVALID_INSPECT_REQUEST",`Inspect request at index ${M} must be an object.`);const U=a(f.op),G=a(f.sourceFile)??a(f.file)??(U==="usages"?a(f.target)??a(f.usageTarget)??a(f.dir):null)??(U==="duplicate"||U==="duplicates"?a(f.target)??a(f.dir)??ut(f.scope)??ut(f.scopes):null);if(!U||!rt(U))throw new E.CliError("INVALID_INSPECT_OP",`Inspect request at index ${M} has invalid op.`);if(at(U,r),!G)throw new E.CliError("SOURCE_FILE_REQUIRED",`Inspect request at index ${M} requires sourceFile or file.`);const x=lt(U),te=B(f.ranges)??B(f.includeRanges)??(x==="code"||x==="slice"||x==="file"?!0:x==="exports"?(0,S.readSessionBooleanPref)(e,"inspect.exports.ranges",!1):s),q=te||x==="code"||x==="slice",g={op:x,sourceFile:k(e,G),ranges:q,resolveStar:B(f.resolveStar)??(x==="exports"?(0,S.readSessionBooleanPref)(e,"inspect.exports.resolveStar",!1):i),localOnly:x==="file"&&(f.localOnly===!0||o)};if(x==="usages"){A.push(Ie(e,{detail:a(f.detail)??C,all:B(f.all)??I,limit:J(f.limit)??O,maxCodeLines:J(f.maxCodeLines)??v}));const T=K(f.scope)??K(f.scopes);T&&T.length>0&&(g.scope=T.map(se=>k(e,se)));const W=B(f.includeTarget)??_,X=B(f.excludeTarget)??b,ne=(0,S.readSessionBooleanPref)(e,"inspect.usages.excludeTarget",!1);W===!0?g.excludeTarget=!1:X!==null?g.excludeTarget=X:ne?g.excludeTarget=!0:Ze(e,g.sourceFile,K(g.scope)??[])&&(g.excludeTarget=!0,g.targetLocalUsagesHidden=!0),Array.isArray(f.entities)&&(g.usageEntities=$n(f.entities,n))}else A.push(null);if(x==="duplicates"){g.detail=a(f.detail)??a(t.detail)??"locations",g.mode=a(f.mode)??a(t.mode)??"both",g.limit=J(f.limit)??J(t.limit)??10,g.offset=fe(f.offset)??fe(t.offset)??0;const T=K(f.scope)??K(f.scopes)??K(t.scope)??K(t.scopes);T&&T.length>0&&(g.scope=T.map(yt=>k(e,yt)));const W=kn(f.kinds??t.kinds,n);W.length>0&&(g.kinds=W);const X=de(f.entities??f.entity??t.entities??t.entity,n);X.length>0&&(g.duplicateEntities=X);const ne=de(f.exclude??f.excludes??t.exclude??t.excludes,n);ne.length>0&&(g.duplicateExclude=ne);const se=ft(e,f.pathExclude??f.pathExcludes??f.excludePath??f.excludePaths??t.pathExclude??t.pathExcludes??t.excludePath??t.excludePaths);se.length>0&&(g.duplicatePathExclude=se)}if(x==="modulePlan"){g.modules=Tn(e,f.modules,n);const T=a(f.facade)??a(f.facadeFile);if(T&&(g.facadeFile=k(e,T)),f.previewFiles===!0||f.preview==="files"){g.previewFiles=!0;const W=a(f.previewDir)??a(f.outputDir);W&&(g.previewDir=k(e,W)),g.previewPatch=f.previewPatch!==!1}}tt(g,{memberOffset:fe(f.offset)??fe(f.memberOffset)??l.memberOffset,memberLimit:J(f.limit)??J(f.memberLimit)??l.memberLimit??(x==="members"?(0,S.readSessionNumberPref)(e,"inspect.members.maxItems",20):null),memberAll:B(f.all)??B(f.memberAll)??(x==="members"?(0,S.readSessionBooleanPref)(e,"inspect.members.all",!1):l.memberAll)});const z=a(f.id);z&&(g.id=z);const N=x==="modulePlan"?null:a(f.toFile)??a(f.outputFile),me=x==="modulePlan"?null:a(f.save);if(N&&x!=="code"&&x!=="slice")throw new E.CliError("INVALID_INSPECT_TO_FILE",`Inspect request at index ${M} can use toFile only with code or slice operations.`);if(me&&x!=="code"&&x!=="slice"&&x!=="usages"&&x!=="duplicates")throw new E.CliError("INVALID_INSPECT_SAVE",`Inspect request at index ${M} can use save only with code, slice, usages, or duplicates operations.`);if(N&&me)throw new E.CliError("INSPECT_OUTPUT_TARGET_CONFLICT",`Inspect request at index ${M} must use either toFile or save, not both.`);u.push(N),d.push(me);const mt=typeof f.show=="boolean"?f.show:null;m.push(mt??(x==="code"&&(0,S.readSessionBooleanPref)(e,"inspect.code.show",!0))),y.push(te);const Ee=a(f.entity);Ee&&_e(g,Ee,n);const Ne=a(f.parent);if(Ne){const T=(0,$.parseInspectSelector)(Ne,n);g.parentName=T.symbolName,T.symbolKind&&(g.parentKind=T.symbolKind),h.push(T.symbolName)}else h.push(null);return g})},toFiles:u,saves:d,shows:m,ranges:y,parentNames:h,usagesDetails:A,...D!==void 0?{bundleSave:D}:{}}}function _e(e,t,n){const s=(0,$.parseInspectSelector)(t,n);e.symbolName=s.symbolName,s.symbolKind&&(e.symbolKind=s.symbolKind)}function gn(e,t,n,s,i){const o=Nn(n),l=[...bn(e,s),...In(e,t,s,i)];if(l.length===0)throw new E.CliError("MODULE_PLAN_REVISE_MOVES_REQUIRED","modulePlan revise expects moves or applySuggestedFixes.");for(const r of l)An(o,r,i);return o}function bn(e,t){return(Array.isArray(t.moves)?t.moves:[]).filter(p).map(s=>{const i=a(s.entity)??a(s.symbol)??a(s.selector),o=a(s.to)??a(s.target)??a(s.toFile)??a(s.targetFile);return i&&o?{selector:i,toFile:k(e,o)}:null}).filter(s=>s!==null)}function In(e,t,n,s){const i=n.applySuggestedFixes,o=xn(t,s),l=i===!0||i==="all"?o.map((r,c)=>c):Array.isArray(i)?i:[];return l.length===0?[]:l.map(r=>typeof r=="number"?r:typeof r=="string"?Number(r):NaN).filter(r=>Number.isInteger(r)&&r>=0&&r<o.length).map(r=>({selector:o[r].selector,toFile:k(e,o[r].toFile)}))}function xn(e,t){const n=p(e.boundary)?e.boundary:{},s=Array.isArray(n.nonExportedImports)?n.nonExportedImports.filter(p):[],i=[];for(const o of s){const l=Array.isArray(o.suggestedFixes)?o.suggestedFixes.filter(p):[];for(const r of l){if(r.kind!=="moveSymbol")continue;const c=Qe(r.symbol,t),u=a(r.toFile);c&&u&&i.push({selector:c,toFile:u})}}return i}function Qe(e,t){if(!p(e))return null;const n=a(e.name),s=a(e.kind);if(!n||!s)return null;const i=t.entityKindAliases[s];return i?`${i}${t.selectorSeparator}${n}`:`${s}:${n}`}function An(e,t,n){const s=Array.isArray(e.modules)?e.modules.filter(p):[],i=(0,$.parseInspectSelector)(t.selector,n);let o=null;for(const c of s){const u=Array.isArray(c.symbols)?c.symbols:[],d=[];for(const m of u)o===null&&qe(m,i)?o=m:d.push(m);c.symbols=d}if(o===null)throw new E.CliError("MODULE_PLAN_REVISE_SYMBOL_NOT_FOUND",`Symbol not found in cached module plan: ${t.selector}`,{symbol:t.selector});let l=s.find(c=>a(c.targetFile)===t.toFile);l||(l={targetFile:t.toFile,symbols:[]},s.push(l));const r=Array.isArray(l.symbols)?l.symbols:[];r.some(c=>qe(c,i))||r.push(o),l.symbols=r,e.modules=s.filter(c=>Array.isArray(c.symbols)&&c.symbols.length>0)}function qe(e,t){if(!p(e))return!1;const n=a(e.raw),s=a(e.symbolName),i=a(e.symbolKind);return n===t.raw||s===t.symbolName&&(!t.symbolKind||i===t.symbolKind)}function Sn(e,t,n){const s=Ye(t),i=Ye(n),o=[];for(const[l,r]of i.entries()){const c=s.get(l);c&&c!==r&&o.push(`${l}: ${Xe(e,c)} -> ${Xe(e,r)}`)}return o}function _n(e,t){const n=p(e.boundary)?e.boundary:{};return(Array.isArray(n.nonExportedImports)?n.nonExportedImports.filter(p):[]).flatMap(i=>{const o=a(i.code)??"MODULE_PLAN_BOUNDARY_WARNING";return(Array.isArray(i.symbols)?i.symbols.filter(p):[]).map(r=>Qe(r,t)).filter(r=>typeof r=="string").map(r=>`${o}: ${r}`)})}function En(e){return(Array.isArray(e.blocking)?e.blocking.filter(p):[]).flatMap(n=>{const s=a(n.code)??"MODULE_PLAN_BOUNDARY_WARNING";return(Array.isArray(n.symbols)?n.symbols.filter(o=>typeof o=="string"):[]).map(o=>`${s}: ${o}`)})}function Xe(e,t){return L.relative(e,t).replace(/\\/g,"/")}function Ye(e){const t=new Map,n=Array.isArray(e.modules)?e.modules.filter(p):[];for(const s of n){const i=a(s.targetFile);if(!i)continue;const o=Array.isArray(s.symbols)?s.symbols.filter(p):[];for(const l of o){const r=a(l.raw),c=a(l.symbolName),u=a(l.symbolKind),d=r??(c?`${u??"symbol"}:${c}`:null);d&&t.set(d,i)}}return t}function Nn(e){return JSON.parse(JSON.stringify(e))}function k(e,t){return L.normalize(L.isAbsolute(t)?t:L.resolve(e,t))}function Ze(e,t,n){const s=L.normalize(t);return n.length===0?!et(s,e):n.some(i=>vn(i,s))}function vn(e,t){const n=L.normalize(e),s=L.normalize(t);return et(n,s)||Cn(n)?!1:Dn(s,n)}function Dn(e,t){const n=L.relative(L.normalize(t),L.normalize(e));return n!==""&&!n.startsWith("..")&&!L.isAbsolute(n)}function et(e,t){return L.normalize(e).toLowerCase()===L.normalize(t).toLowerCase()}function Cn(e){try{return ye.statSync(e).isFile()}catch{return!1}}function Pn(e){try{return ye.statSync(e).isDirectory()}catch{return!1}}function tt(e,t){if(t.memberAll){e.memberAll=!0;return}typeof t.memberOffset=="number"&&(e.memberOffset=t.memberOffset),typeof t.memberLimit=="number"&&(e.memberLimit=t.memberLimit)}function Fn(e,t){const n=F(t,"--max-lines");if(!n)return(0,S.readSessionNumberPref)(e,"inspect.code.maxNonEmptyLines",120);const s=Number(n);if(!Number.isInteger(s)||s<1)throw new E.CliError("INVALID_MAX_LINES","Expected --max-lines to be a positive integer.");return s}function H(e,t){const n=F(e,t);if(!n)return null;const s=Number(n);if(!Number.isInteger(s)||s<1)throw new E.CliError("INVALID_INSPECT_LIMIT",`Expected ${t} to be a positive integer.`);return s}function nt(e,t){const n=F(e,t);if(!n)return null;const s=Number(n);if(!Number.isInteger(s)||s<0)throw new E.CliError("INVALID_INSPECT_OFFSET",`Expected ${t} to be a non-negative integer.`);return s}function J(e){const t=typeof e=="number"?e:typeof e=="string"?Number(e):NaN;return Number.isInteger(t)&&t>0?t:null}function fe(e){const t=typeof e=="number"?e:typeof e=="string"?Number(e):NaN;return Number.isInteger(t)&&t>=0?t:null}function B(e){return typeof e=="boolean"?e:null}function st(e){return pe(e).some(n=>p(n)&&(n.ranges===!0||n.includeRanges===!0))}function pe(e){const t=On(e),n=Array.isArray(e.requests)?e.requests:[e],s=[];for(const i of n){if(!p(i)){s.push(i);continue}const o={...t,...i};delete o.requests;const l=Array.isArray(o.entities)?o.entities:null;if(!l){delete o.entities,s.push(o);continue}const r=a(o.op);if(r==="usages"||r==="duplicate"||r==="duplicates"){s.push(o);continue}delete o.entities;for(const c of l){if(p(c)){const u=Array.isArray(c.entities)?c.entities:null;if(u){const d={...c};delete d.entities;for(const m of u)s.push(Ln(o,d,m));continue}s.push({...o,...c});continue}if(typeof c!="string"||c.trim()===""){s.push({...o,entity:c});continue}s.push({...o,entity:c.trim()})}}return s}function Ln(e,t,n){return p(n)?{...e,...t,...n}:typeof n=="string"&&n.trim()!==""?{...e,...t,entity:n.trim()}:{...e,...t,entity:n}}function On(e){const t={};for(const n of["op","sourceFile","file","target","usageTarget","dir","scope","scopes","excludeTarget","includeTarget","ranges","includeRanges","resolveStar","localOnly","parent","offset","limit","all","memberOffset","memberLimit","memberAll","detail","mode","kinds","entities","entity","exclude","excludes","pathExclude","pathExcludes","excludePath","excludePaths","toFile","outputFile","save","show","bundleSave","bundle","saveBundle","previewFiles","preview","previewDir","outputDir","previewPatch","modules","facade","facadeFile"])e[n]!==void 0&&(t[n]=e[n]);return t}function F(e,t){const n=e.indexOf(t);if(n<0)return null;const s=e[n+1];return s&&!s.startsWith("--")?s:null}function R(e,t){const n=[];for(let s=0;s<e.length;s+=1){if(e[s]!==t)continue;const i=e[s+1];i&&!i.startsWith("--")&&n.push(i)}return n}function it(e,t){const n=e.indexOf(t);return n>0&&(e[n-1]==="--parent"||e[n-1]==="--max-lines"||e[n-1]==="--to-file"||e[n-1]==="--save"||e[n-1]==="--bundle-save"||e[n-1]==="--preview-dir"||e[n-1]==="--from-json"||e[n-1]==="--from-dsl"||e[n-1]==="--from"||e[n-1]==="--offset"||e[n-1]==="--limit"||e[n-1]==="--max-code-lines"||e[n-1]==="--maxCodeLines"||e[n-1]==="--scope"||e[n-1]==="--detail"||e[n-1]==="--mode"||e[n-1]==="--kind"||e[n-1]==="--kinds"||e[n-1]==="--entity"||e[n-1]==="--entities"||e[n-1]==="--exclude"||e[n-1]==="--excludes"||e[n-1]==="--path-exclude"||e[n-1]==="--path-excludes"||e[n-1]==="--exclude-path"||e[n-1]==="--exclude-paths")}function Tn(e,t,n){return Array.isArray(t)?t.filter(p).map(s=>{const i=a(s.target)??a(s.targetFile)??a(s.file),o=Array.isArray(s.entities)?s.entities:Array.isArray(s.symbols)?s.symbols:[];return{...i?{targetFile:k(e,i)}:{},symbols:o.map(l=>Mn(l,n)).filter(p)}}):[]}function $n(e,t){return e.flatMap(n=>ot(n,t,{})).filter(p)}function ot(e,t,n){if(typeof e=="string"&&e.trim()!==""){const c=(0,$.parseInspectSelector)(e,t);return[{...n,raw:e.trim(),symbolName:c.symbolName,...c.symbolKind?{symbolKind:c.symbolKind}:{}}]}if(!p(e))return[];const s=a(e.parent),i={...n};if(s){const c=(0,$.parseInspectSelector)(s,t);i.parentName=c.symbolName,c.symbolKind&&(i.parentKind=c.symbolKind)}const o=Array.isArray(e.entities)?e.entities:null;if(o)return o.flatMap(c=>ot(c,t,i));const l=a(e.entity)??a(e.selector)??a(e.raw);if(!l)return[];const r=(0,$.parseInspectSelector)(l,t);return[{...i,raw:l,symbolName:r.symbolName,...r.symbolKind?{symbolKind:r.symbolKind}:{}}]}function Mn(e,t){if(typeof e=="string"&&e.trim()!==""){const s=(0,$.parseInspectSelector)(e,t);return{raw:e.trim(),symbolName:s.symbolName,...s.symbolKind?{symbolKind:s.symbolKind}:{}}}if(!p(e))return null;const n=a(e.entity)??a(e.selector)??a(e.raw);if(n){const s=(0,$.parseInspectSelector)(n,t);return{raw:n,symbolName:s.symbolName,...s.symbolKind?{symbolKind:s.symbolKind}:{}}}return e}function rt(e){return e==="file"||e==="exports"||e==="imports"||e==="members"||e==="code"||e==="deps"||e==="slice"||e==="modulePlan"||e==="usages"||e==="duplicate"||e==="duplicates"||e==="tree"||e==="cycles"}function lt(e){return e==="deps"?"dependencies":e==="duplicate"?"duplicates":e==="cycles"?"cycles":e==="imports"?"imports":e}function at(e,t){e!=="modulePlan"||t||ct()}function ct(){throw new E.CliError("INSPECT_MODULE_PLAN_UNSUPPORTED","inspect is limited to file, exports, members, code, slice, deps, usages, duplicates, graph, tree, cycles, and imports. Use modulePlan preview/revise/apply/validate for module extraction plans.")}function Un(e,t){return e[0]==="modulePlan"?!0:!e.includes("--stdin")||!p(t)?!1:a(t.op)==="modulePlan"?!0:(Array.isArray(t.requests)?t.requests:[]).some(i=>p(i)&&a(i.op)==="modulePlan")}function a(e){return typeof e=="string"&&e.trim()!==""?e.trim():null}function K(e){return typeof e=="string"&&e.trim()!==""?[e.trim()]:Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.trim()!=="").map(t=>t.trim()):null}function ut(e){if(typeof e=="string"&&e.trim()!=="")return e.trim();if(!Array.isArray(e))return null;const t=e.find(n=>typeof n=="string"&&n.trim()!=="");return typeof t=="string"?t.trim():null}function Bn(e,t){const n=[...R(e,"--kind"),...R(e,"--kinds").flatMap(s=>s.split(","))];return dt(n,t)}function kn(e,t){const n=K(e)??[];return dt(n.flatMap(s=>s.split(",")),t)}function de(e,t){return(Array.isArray(e)?e:typeof e=="string"?e.split(","):e&&typeof e=="object"&&!Array.isArray(e)?[e]:[]).flatMap(s=>{if(typeof s=="string"){const l=s.trim();if(!l)return[];const r=(0,$.parseInspectSelector)(l,t);return[pt(r.symbolName,r.symbolKind??null)]}if(!p(s))return[];const i=a(s.entity)??a(s.selector)??a(s.name);if(!i)return[];const o=(0,$.parseInspectSelector)(i,t);return[pt(o.symbolName,o.symbolKind??null)]})}function ft(e,t){return(Array.isArray(t)?t:typeof t=="string"?t.split(","):[]).filter(s=>typeof s=="string").map(s=>s.trim()).filter(s=>s.length>0).map(s=>L.isAbsolute(s)?s:L.resolve(e,s)).map(s=>s.replace(/\\/g,"/"))}function pt(e,t){return t?{symbolName:e,symbolKind:t}:{symbolName:e}}function dt(e,t){const n=new Map;for(const[i,o]of Object.entries(t.entityKindAliases))n.set(i.toLowerCase(),i),n.set(String(o).toLowerCase(),i);const s=e.map(i=>n.get(i.trim().toLowerCase())??"").filter(i=>i!=="");return Array.from(new Set(s))}function p(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}
14
+ `).trimEnd()}const i=Array.isArray(t.items)?t.items.filter(p).filter(l=>V(l.referenceCount)>0):[],{ownerGroups:o,standalone:c}=ae(i,l=>r(l.entity)??"");for(const[l,a]of o){s.push(""),s.push(`// ${l}:`);for(const f of a)s.push(...ze(f,!1))}c.length>0&&o.length>0&&s.push("");for(const l of c)s.push(...ze(l,!0));return Re(s,t),Be(s,t),s.join(`
15
+ `).trimEnd()}function Be(e,t){const n=r(t.view);n&&(e.length>0&&e[e.length-1]!==""&&e.push(""),e.push(`view: ${n}`))}function Re(e,t){const n=Array.isArray(t.unused)?t.unused.filter(s=>typeof s=="string"&&s!==""):[];if(n.length!==0){if(r(t.queryMode)==="explicit"){e.push(""),e.push(`unused: ${Ht(n,2,"more")}`);return}r(t.targetMode)==="file"&&(e.push(""),e.push(`unused symbols: ${n.length}`))}}function Se(e,t){t.targetLocalUsagesHidden===!0&&e.push("target-local usages hidden; use +includeTarget to show")}function je(e,t,n){const s=[],i=_e(n,l=>r(l.file)??"");for(const[l,a]of i)l&&s.push(`// ${l}`),s.push(...Jt(e,a));const o=r(n[0]?.entity)??"",c=Qt(t,"hiddenBlocks",o);return c&&s.push(`// ${c}`),s}function Jt(e,t){const n=[],{ownerGroups:s,standalone:i}=ae(t,o=>r(o.container)??"");for(const[o,c]of s)n.push(`// ${o}:`),n.push(...Ke(e,c));return i.length>0&&n.push(...Ke(e,i)),n}function Ke(e,t){const n=[];for(const s of t){if(typeof s.code=="string")n.push(s.code.trimEnd());else if(typeof s.omitted=="string"){const i=(0,A.useSessionGuidance)(e,"inspect.usages.codeOmitted",s.omitted)??"code omitted";n.push(`// ${i}`),typeof s.compactCode=="string"&&s.compactCode!==""&&n.push(s.compactCode)}n.push("")}return n}function Ve(e,t=!0){const n=[],s=r(e.entity);t&&s&&n.push(`// ${s}`);const i=r(e.file)??"",o=typeof e.line=="number"?` l${e.line}`:"";(i||o)&&n.push(`// ${i}${o}`.trim());const c=r(e.code);return c&&n.push(c.trimEnd()),n}function ze(e,t){const n=r(e.entity)??"",s=ue(n),i=[`${t?n:s.name}:`],o=Array.isArray(e.usedBy)?e.usedBy.filter(p):[];for(const l of o){const a=r(l.file)??"",f=Array.isArray(l.locations)?l.locations.filter(p):[];if(f.length!==0){if(f.length===1){const[d]=f,y=typeof d?.line=="number"?d.line:0,m=r(d?.container);i.push(m?`${a}:${y} ${m}`:`${a}:${y}`);continue}i.push(`${a}:`),i.push(...Wt(f))}}const c=r(e.hidden);return c&&i.push(c),i}function Wt(e){const t=[],{ownerGroups:n,standalone:s}=ae(e,i=>r(i.container)??"");for(const[i,o]of n){t.push(`// ${i}:`);for(const c of o){const l=typeof c.line=="number"?c.line:0,a=ue(r(c.container)??"").name;t.push(a?`${a} l${l}`:`l${l}`)}}for(const i of s){const o=typeof i.line=="number"?i.line:0,c=r(i.container);t.push(c?`${c} l${o}`:`l${o}`)}return t}function Qt(e,t,n){const i=(Array.isArray(e[t])?e[t].filter(p):[]).find(o=>r(o.entity)===n);return i?r(i.hidden):null}function ae(e,t){const n=new Map,s=[];for(const i of e){const o=ue(t(i));if(!o.owner){s.push(i);continue}const c=n.get(o.owner)??[];c.push(i),n.set(o.owner,c)}return{ownerGroups:Array.from(n.entries()),standalone:s}}function ue(e){const t=e.lastIndexOf(".");return t<=0||t>=e.length-1?{owner:null,name:e}:{owner:e.slice(0,t),name:e.slice(t+1)}}function _e(e,t){const n=new Map;for(const s of e){const i=t(s),o=n.get(i)??[];o.push(s),n.set(i,o)}return Array.from(n.entries())}function Xt(e,t,n,s,i){const o=ye.readFileSync(e,"utf8"),c=Ge(o,t,n),l=Ge(o,s,i);return o.slice(c,l)}function Ge(e,t,n){let s=0,i=0;for(;i<e.length&&s<t;){const o=e.charCodeAt(i);o===13?(i+=e.charCodeAt(i+1)===10?2:1,s+=1):o===10?(i+=1,s+=1):i+=1}return Math.max(0,Math.min(i+n,e.length))}function Yt(e){return e.split(/\r?\n/).filter(t=>t.trim()!=="").length}function X(e,t){return(0,Q.compactDisplayPath)(e,t,(0,Q.buildDisplayPathAliases)(e,(0,A.readEffectiveSessionPathAliases)(e)))}async function Zt(e,t,n,s,i){const o=pe(n),c=[],l=[],a=[],f=[],d=[],y=(0,Q.buildDisplayPathAliases)(e,(0,A.readEffectiveSessionPathAliases)(e)),m=[];for(const g of o){if(!p(g))throw new E.CliError("INVALID_INSPECT_REQUEST","Inspect request must be an object.");const _=r(g.op);_==="graph"?(l.push(on(g)),m.push("graph")):_==="imports"?(a.push(g),m.push("imports")):_==="tree"?(f.push(g),m.push("tree")):_==="cycles"?(d.push(g),m.push("cycles")):(c.push(g),m.push("inspect"))}const h=await tn(e,c,s,i),N=l.length>0?rn((0,z.stripAgentText)((0,ge.runInspectGraph)(e,["graph","--stdin"],{requests:l}))):[],P=a.map(g=>(0,Ie.buildInspectImportsResult)(e,{file:r(g.file)??r(g.fromFile)??r(g.sourceFile)??r(n.file)??"",ranges:B(g.ranges)!==!1,dynamic:B(g.dynamic)!==!1},y)),I=f.map(g=>(0,ee.buildInspectTreeResult)(e,sn(g))),T=d.length>0?we((0,z.stripAgentText)((0,be.runInspectCycles)(e,["--stdin"],{requests:d}))):[],S=[];let L=0,C=0,D=0,F=0,u=0;for(const g of m)if(g==="graph"){const _=N[C++];_&&S.push(_)}else if(g==="imports"){const _=P[D++];_&&S.push(_)}else if(g==="tree"){const _=I[F++];_&&S.push(_)}else if(g==="cycles"){const _=T[u++];_&&S.push(_)}else{const _=h[L++];_&&S.push(_)}const $={ok:!S.some(g=>g.ok===!1),...S.some(g=>g.op==="runtimeFailure")?{partial:!0}:{},results:(0,Ie.mergeDirectoryFallbackResults)(S)};return Le((0,z.attachAgentText)($,(0,k.formatInspectMixedAgentText)($)),Oe(n).dslDiagnostics??[])}function qt(e,t,n){if(t[0]==="graph")return null;if(t.includes("--stdin"))return p(n)?n:null;const s=O(t,"--from-json");return s?(0,he.readJsonObjectFile)(e,s,"INVALID_INSPECT_JSON_FILE"):null}function en(e){return pe(e).some(t=>p(t)&&(r(t.op)==="graph"||r(t.op)==="imports"||r(t.op)==="tree"||r(t.op)==="cycles"))}async function tn(e,t,n,s){if(t.length===0)return[];try{return we((0,z.stripAgentText)(await Ce(e,["--stdin"],{requests:t},n,{...s,forceResults:!0})))}catch(i){return t.map(o=>nn(e,o,i))}}function nn(e,t,n){const s=p(n)&&p(n.details)?n.details:{},i=n instanceof E.CliError?n.code:"RUNTIME_INSPECT_FAILED",o=n instanceof Error?n.message:String(n),c=r(t.file)??r(t.sourceFile)??r(t.fromFile)??r(t.target)??"",l=c?M.resolve(e,c):"";return{ok:!1,op:"runtimeFailure",requestedOp:r(t.op)??"file",...r(t.entity)?{entity:r(t.entity)}:{},...l?{sourceFile:l,file:X(e,l)}:{},code:i,error:o,...Array.isArray(s.hints)?{hints:s.hints}:{}}}function sn(e){const t={scope:r(e.scope)??r(e.file)??r(e.dir)??r(e.directory)??""},n=r(e.displayScope)??r(e.display_scope),s=G(e.depth),i=Y(e.minDepth)??Y(e.min_depth),o=G(e.limit),c=R(e.exclude)??R(e.excludes),l=R(e.only),a=B(e.onlyDirs)??B(e.only_dirs);return n!==null&&(t.displayScope=n),s!==null&&(t.depth=s),i!==null&&(t.minDepth=i),o!==null&&(t.limit=o),c!==null&&(t.exclude=c),l!==null&&(t.only=l),a!==null&&(t.onlyDirs=a),t}function on(e){const t={...e};return delete t.op,delete t.sourceFile,t}function we(e){return Array.isArray(e.results)?e.results.filter(p).map(He):[He(e)]}function He(e){return e.op==="dependencies"?{...e,op:"deps"}:e}function rn(e){return Array.isArray(e.results)?e.results.filter(p).map(t=>({op:"graph",...t})):[{op:"graph",...ln(e)}]}function ln(e){const t={...e};return delete t.operation,delete t.next,delete t.last,typeof t.saved=="string"&&delete t.graphFile,t}function cn(e,t){(Array.isArray(t.payload.requests)?t.payload.requests:[]).forEach((s,i)=>{if(!p(s)||s.op!=="modulePlan"||s.previewFiles!==!0)return;const o=(0,w.normalizeModulePlanCacheRequest)(s),c=(0,w.buildModulePlanId)(o),l=r(s.previewDir),a=(0,w.resolveModulePlanPreviewDir)(e,c,l??void 0);s.previewDir=a,s.previewPatch=s.previewPatch!==!1,t.cachePlans.push({index:i,planId:c,normalizedRequest:o,previewDir:a})})}function an(e,t,n){if(!(t.cachePlans.length===0||!Array.isArray(n.results)))for(const s of t.cachePlans){const i=n.results[s.index];if(!p(i))continue;const o=r(s.normalizedRequest.sourceFile);if(!o)continue;const c=(0,w.hashFile)(o),l=(0,w.buildModulePlanHash)(s.normalizedRequest,c,i),a={planId:s.planId,planHash:l,createdAt:new Date().toISOString(),cwd:M.resolve(e),sourceFile:o,sourceHash:c,executable:i.ok!==!1,normalizedRequest:s.normalizedRequest,inspectPayload:t.payload,previewDir:s.previewDir,previewResult:i};(0,w.writeModulePlanRecord)(e,a),i.planId=s.planId,i.planHash=l,i.cached=!0,i.executable=i.ok!==!1,i.next=i.ok===!1?`Revise with: aib modulePlan revise --plan ${s.planId} --stdin`:`Run modulePlan apply ${s.planId} if the plan matches intent.`}}function un(e,t){if(!t||!Array.isArray(e.results)||!p(e.results[0]))return e;const n=e.results[0];n.operation="modulePlan.revise",n.fromPlanId=t.fromPlanId,n.changes=t.changes;const s=Fn(n),i=t.previousBlocking.filter(o=>!s.includes(o));return i.length>0&&(n.resolved=i),n.remainingBlocking=Array.isArray(n.blocking)?n.blocking:[],delete n.blocking,delete n.boundary,delete n.targets,delete n.moduleCount,delete n.preview,delete n.facade,n.next=n.ok===!1||n.executable===!1?`Revise again from ${typeof n.planId=="string"?n.planId:t.fromPlanId}.`:`aib modulePlan apply ${typeof n.planId=="string"?n.planId:t.fromPlanId}`,(0,z.attachAgentText)(e,fn(n))}function fn(e){const t=[`modulePlan.revise ${typeof e.planId=="string"?e.planId:""}`.trim()];if(typeof e.fromPlanId=="string"&&t.push(`from: ${e.fromPlanId}`),typeof e.integrity=="string"&&t.push(e.integrity),p(e.api)&&typeof e.api.status=="string"){const n=typeof e.api.before=="number"?e.api.before:null,s=typeof e.api.after=="number"?e.api.after:null;t.push(n!==null&&s!==null?`api: ${e.api.status} ${n}->${s}`:`api: ${e.api.status}`)}if(typeof e.cycles=="string"&&t.push(`cycles: ${e.cycles}`),Array.isArray(e.changes)&&e.changes.length>0){t.push("changes:");for(const n of e.changes.filter(s=>typeof s=="string"))t.push(n)}return Array.isArray(e.resolved)&&e.resolved.length>0&&t.push(`resolved: ${e.resolved.length}`),Array.isArray(e.remainingBlocking)&&t.push(`remainingBlocking: ${e.remainingBlocking.length}`),typeof e.next=="string"&&t.push(`next: ${e.next}`),t.join(`
16
+ `)}function pn(e,t){if(!Array.isArray(t.payload.requests))return;const n=t.payload.requests.filter(p),s=new Map,i=[],o=new Map;for(let c=0;c<n.length;c+=1){const l=n[c],a=r(l.sourceFile);if(!a||!dn(r(l.op))||!Tn(a)){o.set(c,i.length),i.push(l);continue}let f=s.get(a);f?o.set(c,i.findIndex(y=>r(y.sourceFile)===a&&y.op==="directoryFallback")):(f=mn(e,a),s.set(a,f),o.set(c,i.length),i.push(yn(f)));const d=gn(r(l.op));f.ops.includes(d)||f.ops.push(d)}s.size!==0&&(t.payload.requests=i,t.formatOptions.toFiles&&(t.formatOptions.toFiles=fe(t.formatOptions.toFiles,o,i.length)),t.formatOptions.saves&&(t.formatOptions.saves=fe(t.formatOptions.saves,o,i.length)),t.formatOptions.shows&&(t.formatOptions.shows=Je(t.formatOptions.shows,o,i.length)),t.formatOptions.ranges&&(t.formatOptions.ranges=Je(t.formatOptions.ranges,o,i.length)),t.formatOptions.parentNames&&(t.formatOptions.parentNames=fe(t.formatOptions.parentNames,o,i.length)),t.usagesDetails&&(t.usagesDetails=fe(t.usagesDetails,o,i.length)))}function dn(e){return e==="file"||e==="exports"||e==="members"||e==="code"||e==="dependencies"||e==="slice"}function mn(e,t){const n=hn(e,t),s=(0,A.readEffectiveSessionPathAliases)(e),i=(0,Q.compactDisplayPath)(e,t,(0,Q.buildDisplayPathAliases)(e,s)),o=(0,ee.buildInspectTreeResult)(e,{scope:t,displayScope:i,depth:n,limit:40,aliases:s}),c=[];return{sourceFile:t,displayPath:i,ops:c,command:`aib inspect tree ${i} --depth ${n}`,result:{op:"directoryFallback",ok:!0,sourceFile:t,directory:i,skippedOps:c,command:`aib inspect tree ${i} --depth ${n}`,tree:o,lines:Array.isArray(o.lines)?o.lines:[]}}}function yn(e){return{op:"directoryFallback",sourceFile:e.sourceFile,fallback:e.result}}function hn(e,t){for(let n=1;n<=4;n+=1){const s=(0,ee.buildInspectTreeResult)(e,{scope:t,depth:n,limit:1});if(typeof s.files=="number"&&s.files>0)return n}return 2}function fe(e,t,n){const s=Array.from({length:n},()=>null);for(const[i,o]of t.entries())s[o]===null&&(s[o]=e[i]??null);return s}function Je(e,t,n){const s=Array.from({length:n},()=>!1);for(const[i,o]of t.entries())s[o]=s[o]||(e[i]??!1);return s}function gn(e){return e==="dependencies"?"deps":e??"inspect"}function bn(e,t,n,s,i,o){const c=Qe(t),a=!(t.includes("--no-ranges")||t.includes("--noRanges"))&&(c==="code"||c==="file")||t.includes("--ranges")||c==="exports"&&(0,A.readSessionBooleanPref)(e,"inspect.exports.ranges",!1),f=t.includes("--details"),d=t.includes("--resolve-star")||c==="exports"&&(0,A.readSessionBooleanPref)(e,"inspect.exports.resolveStar",!1),y=t.includes("--local-only"),m=$n(e,t),h=it(t,"--offset"),N=J(t,"--limit")??(c==="members"?(0,A.readSessionNumberPref)(e,"inspect.members.maxItems",20):null),P=t.includes("--all")||c==="members"&&(0,A.readSessionBooleanPref)(e,"inspect.members.all",!1),I=O(t,"--to-file")??void 0,T=O(t,"--save")??void 0,S=c==="code"&&(t.includes("--no-show")||t.includes("--noShow")),L=t.includes("--show"),C=S?!1:L||c==="code"&&(0,A.readSessionBooleanPref)(e,"inspect.code.show",!0),D=(0,A.readSessionBooleanPref)(e,"inspect.code.meta",!0),F=c==="usages"?xe(e,{detail:O(t,"--detail"),all:t.includes("--all"),limit:J(t,"--limit"),maxCodeLines:J(t,"--max-code-lines")??J(t,"--maxCodeLines")}):null,u=O(t,"--bundle-save")??void 0,$=O(t,"--preview-dir")??void 0,g=O(t,"--from-json")??void 0,_=O(t,"--parent")??void 0,x=_?(0,k.parseInspectSelector)(_,s).symbolName:void 0,ne=(0,Q.buildDisplayPathAliases)(e,(0,A.readEffectiveSessionPathAliases)(e)),se=[];if(I!==void 0&&T!==void 0)throw new E.CliError("INSPECT_OUTPUT_TARGET_CONFLICT","Use either --to-file or --save, not both.");const Z={cwd:e,includeRanges:a,displayPathAliases:ne,pathAliasHints:se,details:f,localOnly:y,maxCodeLines:m,forceResults:o,show:C,codeMeta:D,...x!==void 0?{parentName:x,parentNames:[x]}:{},...I!==void 0?{toFile:I}:{},...T!==void 0?{save:T}:{},...u!==void 0?{bundleSave:u}:{},...$!==void 0?{previewDir:j(e,$)}:{}};if(g!==void 0){if(t.includes("--stdin")||n!==void 0)throw new E.CliError("INSPECT_INPUT_SOURCE_CONFLICT","Use either inspect --stdin or inspect --from-json, not both.");if(t.includes("--revise"))throw new E.CliError("INSPECT_REVISE_FROM_JSON_UNSUPPORTED","modulePlan revise currently expects --stdin.");const b=We((0,he.readJsonObjectFile)(e,g,"INVALID_INSPECT_JSON_FILE"),Qe(t)),H=a||ot(b),v=Xe(e,b,s,H,d,y,{memberOffset:h,memberLimit:N,memberAll:P},i);return{payload:v.payload,cachePlans:[],formatOptions:{...Z,includeRanges:H,toFiles:v.toFiles,saves:v.saves,shows:v.shows,ranges:v.ranges,parentNames:v.parentNames,...u===void 0&&v.bundleSave!==void 0?{bundleSave:v.bundleSave}:{}},usagesDetails:v.usagesDetails}}if(n!==void 0){if(!p(n))throw new E.CliError("INVALID_INSPECT_STDIN","inspect input expects a JSON object payload.");if(t.includes("--revise"))return In(e,t,n,s);const b=We(n,c),H=a||ot(b),v=Xe(e,b,s,H,d,y,{memberOffset:h,memberLimit:N,memberAll:P},i);return{payload:v.payload,cachePlans:[],formatOptions:{...Z,includeRanges:H,toFiles:v.toFiles,saves:v.saves,shows:v.shows,ranges:v.ranges,parentNames:v.parentNames,...u===void 0&&v.bundleSave!==void 0?{bundleSave:v.bundleSave}:{}},usagesDetails:v.usagesDetails,...Oe(n)}}return{payload:xn(e,t,s,a,d,y,{memberOffset:h,memberLimit:N,memberAll:P},i),formatOptions:Z,cachePlans:[],...F!==null?{usagesDetails:[F]}:{}}}function We(e,t){return!t||e.op!==void 0?e:{op:t,...e}}function Qe(e){return e.filter(n=>!n.startsWith("--")&&!rt(e,n))[0]??null}function In(e,t,n,s){const i=O(t,"--plan");if(!i)throw new E.CliError("MODULE_PLAN_REVISE_PLAN_REQUIRED","modulePlan revise expects --plan <planId>.");const o=(0,w.readModulePlanRecord)(e,i),c=An(e,o.previewResult,o.normalizedRequest,n,s),l=(0,w.buildModulePlanId)(c),a=(0,w.resolveModulePlanPreviewDir)(e,l);return{payload:{requests:[{...c,previewFiles:!0,previewPatch:!0,previewDir:a}]},formatOptions:{cwd:e,includeRanges:!1,displayPathAliases:(0,Q.buildDisplayPathAliases)(e,(0,A.readEffectiveSessionPathAliases)(e)),pathAliasHints:[],localOnly:!1,details:!1,maxCodeLines:(0,A.readSessionNumberPref)(e,"inspect.code.maxNonEmptyLines",120),codeMeta:(0,A.readSessionBooleanPref)(e,"inspect.code.meta",!0),previewDir:a},cachePlans:[{index:0,planId:l,normalizedRequest:c,previewDir:a}],revision:{fromPlanId:i,changes:vn(e,o.normalizedRequest,c),previousBlocking:Dn(o.previewResult,s)}}}function xn(e,t,n,s,i,o,c,l){const a=t.filter(I=>!I.startsWith("--")&&!rt(t,I)),[f,d,y]=a;if(!f||!d)throw new E.CliError("INVALID_INSPECT_COMMAND","Expected: aib inspect <file|imports|exports|members|code|slice|deps|usages|duplicates> <file-or-dir> [entity].",{examples:["aib inspect file src/example.ts","aib inspect imports src/example.ts","aib inspect exports src/example.ts","aib inspect members src/example.ts c:Example","aib inspect code src/example.ts f:helper","aib inspect deps src/example.ts c:Example","aib inspect usages src/example.ts f:helper --scope src/main","aib inspect duplicates src/scripts --detail code"]});if(!ct(f))throw new E.CliError("INVALID_INSPECT_OP","Expected inspect op to be file, imports, exports, members, code, slice, deps, usages, duplicates, graph, tree, or cycles.");if(ut(f,l),O(t,"--save")&&f!=="code"&&f!=="slice"&&f!=="usages"&&f!=="duplicate"&&f!=="duplicates")throw new E.CliError("INVALID_INSPECT_SAVE","inspect --save can be used only with code, slice, usages, or duplicates operations.");const m=at(f),h={op:m,sourceFile:j(e,d),ranges:s||m==="code"||m==="slice",resolveStar:i,localOnly:m==="file"&&o};if(st(h,c),m==="members"||m==="code"||m==="dependencies"||m==="slice"){if(!y)throw new E.CliError("INSPECT_ENTITY_REQUIRED",`inspect ${f} expects an entity selector.`);Ee(h,y,n)}if(m==="usages"&&y&&Ee(h,y,n),m==="duplicates"){h.detail=O(t,"--detail")??"locations",h.mode=O(t,"--mode")??"both";const I=J(t,"--limit"),T=it(t,"--offset");I!==null&&(h.limit=I),T!==null&&(h.offset=T);const S=Kn(t,n);S.length>0&&(h.kinds=S);const L=de([...y?[y]:[],...K(t,"--entity"),...K(t,"--entities").flatMap(F=>F.split(","))],n);L.length>0&&(h.duplicateEntities=L);const C=de([...K(t,"--exclude"),...K(t,"--excludes").flatMap(F=>F.split(","))],n);C.length>0&&(h.duplicateExclude=C);const D=dt(e,[...K(t,"--path-exclude"),...K(t,"--path-excludes").flatMap(F=>F.split(",")),...K(t,"--exclude-path"),...K(t,"--exclude-paths").flatMap(F=>F.split(","))]);D.length>0&&(h.duplicatePathExclude=D)}const N=K(t,"--scope");if(m==="usages"&&N.length>0&&(h.scope=N.map(I=>j(e,I))),m==="duplicates"&&N.length>0&&(h.scope=N.map(I=>j(e,I))),m==="usages"){h.excludeTarget=t.includes("--exclude-target")||t.includes("--excludeTarget")||!1;const I=t.includes("--include-target")||t.includes("--includeTarget"),T=(0,A.readSessionBooleanPref)(e,"inspect.usages.excludeTarget",!1);I?h.excludeTarget=!1:h.excludeTarget===!0||T?h.excludeTarget=!0:tt(e,r(h.sourceFile)??"",R(h.scope)??[])&&(h.excludeTarget=!0,h.targetLocalUsagesHidden=!0)}const P=O(t,"--parent");if(P){const I=(0,k.parseInspectSelector)(P,n);h.parentName=I.symbolName,I.symbolKind&&(h.parentKind=I.symbolKind)}return{requests:[h]}}function Xe(e,t,n,s,i,o,c,l){const a=pe(t),f=[],d=[],y=[],m=[],h=[],N=[],P=Tt(t.detail),I=B(t.all),T=G(t.limit),S=G(t.maxCodeLines),L=B(t.excludeTarget),C=B(t.includeTarget),D=r(t.bundleSave)??r(t.bundle)??r(t.saveBundle)??void 0;return{payload:{requests:a.map((u,$)=>{if(!p(u))throw new E.CliError("INVALID_INSPECT_REQUEST",`Inspect request at index ${$} must be an object.`);const g=r(u.op),_=r(u.sourceFile)??r(u.file)??(g==="usages"?r(u.target)??r(u.usageTarget)??r(u.dir):null)??(g==="duplicate"||g==="duplicates"?r(u.target)??r(u.dir)??pt(u.scope)??pt(u.scopes):null);if(!g||!ct(g))throw new E.CliError("INVALID_INSPECT_OP",`Inspect request at index ${$} has invalid op.`);if(ut(g,l),!_)throw new E.CliError("SOURCE_FILE_REQUIRED",`Inspect request at index ${$} requires sourceFile or file.`);const x=at(g),se=B(u.ranges)??B(u.includeRanges)??(x==="code"||x==="slice"||x==="file"?!0:x==="exports"?(0,A.readSessionBooleanPref)(e,"inspect.exports.ranges",!1):s),Z=se||x==="code"||x==="slice",b={op:x,sourceFile:j(e,_),ranges:Z,resolveStar:B(u.resolveStar)??(x==="exports"?(0,A.readSessionBooleanPref)(e,"inspect.exports.resolveStar",!1):i),localOnly:x==="file"&&(u.localOnly===!0||o)};if(x==="usages"){N.push(xe(e,{detail:r(u.detail)??P,all:B(u.all)??I,limit:G(u.limit)??T,maxCodeLines:G(u.maxCodeLines)??S}));const U=R(u.scope)??R(u.scopes);U&&U.length>0&&(b.scope=U.map(oe=>j(e,oe)));const W=B(u.includeTarget)??C,q=B(u.excludeTarget)??L,ie=(0,A.readSessionBooleanPref)(e,"inspect.usages.excludeTarget",!1);W===!0?b.excludeTarget=!1:q!==null?b.excludeTarget=q:ie?b.excludeTarget=!0:tt(e,b.sourceFile,R(b.scope)??[])&&(b.excludeTarget=!0,b.targetLocalUsagesHidden=!0),Array.isArray(u.entities)&&(b.usageEntities=Bn(u.entities,n))}else N.push(null);if(x==="duplicates"){b.detail=r(u.detail)??r(t.detail)??"locations",b.mode=r(u.mode)??r(t.mode)??"both",b.limit=G(u.limit)??G(t.limit)??10,b.offset=Y(u.offset)??Y(t.offset)??0;const U=R(u.scope)??R(u.scopes)??R(t.scope)??R(t.scopes);U&&U.length>0&&(b.scope=U.map(gt=>j(e,gt)));const W=Vn(u.kinds??t.kinds,n);W.length>0&&(b.kinds=W);const q=de(u.entities??u.entity??t.entities??t.entity,n);q.length>0&&(b.duplicateEntities=q);const ie=de(u.exclude??u.excludes??t.exclude??t.excludes,n);ie.length>0&&(b.duplicateExclude=ie);const oe=dt(e,u.pathExclude??u.pathExcludes??u.excludePath??u.excludePaths??t.pathExclude??t.pathExcludes??t.excludePath??t.excludePaths);oe.length>0&&(b.duplicatePathExclude=oe)}if(x==="modulePlan"){b.modules=kn(e,u.modules,n);const U=r(u.facade)??r(u.facadeFile);if(U&&(b.facadeFile=j(e,U)),u.previewFiles===!0||u.preview==="files"){b.previewFiles=!0;const W=r(u.previewDir)??r(u.outputDir);W&&(b.previewDir=j(e,W)),b.previewPatch=u.previewPatch!==!1}}st(b,{memberOffset:Y(u.offset)??Y(u.memberOffset)??c.memberOffset,memberLimit:G(u.limit)??G(u.memberLimit)??c.memberLimit??(x==="members"?(0,A.readSessionNumberPref)(e,"inspect.members.maxItems",20):null),memberAll:B(u.all)??B(u.memberAll)??(x==="members"?(0,A.readSessionBooleanPref)(e,"inspect.members.all",!1):c.memberAll)});const H=r(u.id);H&&(b.id=H);const v=x==="modulePlan"?null:r(u.toFile)??r(u.outputFile),me=x==="modulePlan"?null:r(u.save);if(v&&x!=="code"&&x!=="slice")throw new E.CliError("INVALID_INSPECT_TO_FILE",`Inspect request at index ${$} can use toFile only with code or slice operations.`);if(me&&x!=="code"&&x!=="slice"&&x!=="usages"&&x!=="duplicates")throw new E.CliError("INVALID_INSPECT_SAVE",`Inspect request at index ${$} can use save only with code, slice, usages, or duplicates operations.`);if(v&&me)throw new E.CliError("INSPECT_OUTPUT_TARGET_CONFLICT",`Inspect request at index ${$} must use either toFile or save, not both.`);f.push(v),d.push(me);const ht=typeof u.show=="boolean"?u.show:null;y.push(ht??(x==="code"&&(0,A.readSessionBooleanPref)(e,"inspect.code.show",!0))),m.push(se);const Ne=r(u.symbolKind)??r(u.kind),ve=r(u.entity)??r(u.selector)??r(u.symbol)??r(u.symbolName)??r(u.name);ve&&Ee(b,ve,n),Ne&&(b.symbolKind=Ne);const De=r(u.parent);if(De){const U=(0,k.parseInspectSelector)(De,n);b.parentName=U.symbolName,U.symbolKind&&(b.parentKind=U.symbolKind),h.push(U.symbolName)}else h.push(null);return b})},toFiles:f,saves:d,shows:y,ranges:m,parentNames:h,usagesDetails:N,...D!==void 0?{bundleSave:D}:{}}}function Ee(e,t,n){const s=(0,k.parseInspectSelector)(t,n);e.symbolName=s.symbolName,s.symbolKind&&(e.symbolKind=s.symbolKind)}function An(e,t,n,s,i){const o=Cn(n),c=[...Sn(e,s),..._n(e,t,s,i)];if(c.length===0)throw new E.CliError("MODULE_PLAN_REVISE_MOVES_REQUIRED","modulePlan revise expects moves or applySuggestedFixes.");for(const l of c)Nn(o,l,i);return o}function Sn(e,t){return(Array.isArray(t.moves)?t.moves:[]).filter(p).map(s=>{const i=r(s.entity)??r(s.symbol)??r(s.selector),o=r(s.to)??r(s.target)??r(s.toFile)??r(s.targetFile);return i&&o?{selector:i,toFile:j(e,o)}:null}).filter(s=>s!==null)}function _n(e,t,n,s){const i=n.applySuggestedFixes,o=En(t,s),c=i===!0||i==="all"?o.map((l,a)=>a):Array.isArray(i)?i:[];return c.length===0?[]:c.map(l=>typeof l=="number"?l:typeof l=="string"?Number(l):NaN).filter(l=>Number.isInteger(l)&&l>=0&&l<o.length).map(l=>({selector:o[l].selector,toFile:j(e,o[l].toFile)}))}function En(e,t){const n=p(e.boundary)?e.boundary:{},s=Array.isArray(n.nonExportedImports)?n.nonExportedImports.filter(p):[],i=[];for(const o of s){const c=Array.isArray(o.suggestedFixes)?o.suggestedFixes.filter(p):[];for(const l of c){if(l.kind!=="moveSymbol")continue;const a=Ye(l.symbol,t),f=r(l.toFile);a&&f&&i.push({selector:a,toFile:f})}}return i}function Ye(e,t){if(!p(e))return null;const n=r(e.name),s=r(e.kind);if(!n||!s)return null;const i=t.entityKindAliases[s];return i?`${i}${t.selectorSeparator}${n}`:`${s}:${n}`}function Nn(e,t,n){const s=Array.isArray(e.modules)?e.modules.filter(p):[],i=(0,k.parseInspectSelector)(t.selector,n);let o=null;for(const a of s){const f=Array.isArray(a.symbols)?a.symbols:[],d=[];for(const y of f)o===null&&Ze(y,i)?o=y:d.push(y);a.symbols=d}if(o===null)throw new E.CliError("MODULE_PLAN_REVISE_SYMBOL_NOT_FOUND",`Symbol not found in cached module plan: ${t.selector}`,{symbol:t.selector});let c=s.find(a=>r(a.targetFile)===t.toFile);c||(c={targetFile:t.toFile,symbols:[]},s.push(c));const l=Array.isArray(c.symbols)?c.symbols:[];l.some(a=>Ze(a,i))||l.push(o),c.symbols=l,e.modules=s.filter(a=>Array.isArray(a.symbols)&&a.symbols.length>0)}function Ze(e,t){if(!p(e))return!1;const n=r(e.raw),s=r(e.symbolName),i=r(e.symbolKind);return n===t.raw||s===t.symbolName&&(!t.symbolKind||i===t.symbolKind)}function vn(e,t,n){const s=et(t),i=et(n),o=[];for(const[c,l]of i.entries()){const a=s.get(c);a&&a!==l&&o.push(`${c}: ${qe(e,a)} -> ${qe(e,l)}`)}return o}function Dn(e,t){const n=p(e.boundary)?e.boundary:{};return(Array.isArray(n.nonExportedImports)?n.nonExportedImports.filter(p):[]).flatMap(i=>{const o=r(i.code)??"MODULE_PLAN_BOUNDARY_WARNING";return(Array.isArray(i.symbols)?i.symbols.filter(p):[]).map(l=>Ye(l,t)).filter(l=>typeof l=="string").map(l=>`${o}: ${l}`)})}function Fn(e){return(Array.isArray(e.blocking)?e.blocking.filter(p):[]).flatMap(n=>{const s=r(n.code)??"MODULE_PLAN_BOUNDARY_WARNING";return(Array.isArray(n.symbols)?n.symbols.filter(o=>typeof o=="string"):[]).map(o=>`${s}: ${o}`)})}function qe(e,t){return M.relative(e,t).replace(/\\/g,"/")}function et(e){const t=new Map,n=Array.isArray(e.modules)?e.modules.filter(p):[];for(const s of n){const i=r(s.targetFile);if(!i)continue;const o=Array.isArray(s.symbols)?s.symbols.filter(p):[];for(const c of o){const l=r(c.raw),a=r(c.symbolName),f=r(c.symbolKind),d=l??(a?`${f??"symbol"}:${a}`:null);d&&t.set(d,i)}}return t}function Cn(e){return JSON.parse(JSON.stringify(e))}function j(e,t){return M.normalize(M.isAbsolute(t)?t:M.resolve(e,t))}function tt(e,t,n){const s=M.normalize(t);return n.length===0?!nt(s,e):n.some(i=>Pn(i,s))}function Pn(e,t){const n=M.normalize(e),s=M.normalize(t);return nt(n,s)||On(n)?!1:Ln(s,n)}function Ln(e,t){const n=M.relative(M.normalize(t),M.normalize(e));return n!==""&&!n.startsWith("..")&&!M.isAbsolute(n)}function nt(e,t){return M.normalize(e).toLowerCase()===M.normalize(t).toLowerCase()}function On(e){try{return ye.statSync(e).isFile()}catch{return!1}}function Tn(e){try{return ye.statSync(e).isDirectory()}catch{return!1}}function st(e,t){if(t.memberAll){e.memberAll=!0;return}typeof t.memberOffset=="number"&&(e.memberOffset=t.memberOffset),typeof t.memberLimit=="number"&&(e.memberLimit=t.memberLimit)}function $n(e,t){const n=O(t,"--max-lines");if(!n)return(0,A.readSessionNumberPref)(e,"inspect.code.maxNonEmptyLines",120);const s=Number(n);if(!Number.isInteger(s)||s<1)throw new E.CliError("INVALID_MAX_LINES","Expected --max-lines to be a positive integer.");return s}function J(e,t){const n=O(e,t);if(!n)return null;const s=Number(n);if(!Number.isInteger(s)||s<1)throw new E.CliError("INVALID_INSPECT_LIMIT",`Expected ${t} to be a positive integer.`);return s}function it(e,t){const n=O(e,t);if(!n)return null;const s=Number(n);if(!Number.isInteger(s)||s<0)throw new E.CliError("INVALID_INSPECT_OFFSET",`Expected ${t} to be a non-negative integer.`);return s}function G(e){const t=typeof e=="number"?e:typeof e=="string"?Number(e):NaN;return Number.isInteger(t)&&t>0?t:null}function Y(e){const t=typeof e=="number"?e:typeof e=="string"?Number(e):NaN;return Number.isInteger(t)&&t>=0?t:null}function B(e){return typeof e=="boolean"?e:null}function ot(e){return pe(e).some(n=>p(n)&&(n.ranges===!0||n.includeRanges===!0))}function pe(e){const t=Un(e),n=Array.isArray(e.requests)?e.requests:[e],s=[];for(const i of n){if(!p(i)){s.push(i);continue}const o={...t,...i};delete o.requests;const c=Array.isArray(o.entities)?o.entities:null;if(!c){delete o.entities,s.push(o);continue}const l=r(o.op);if(l==="usages"||l==="duplicate"||l==="duplicates"){s.push(o);continue}delete o.entities;for(const a of c){if(p(a)){const f=Array.isArray(a.entities)?a.entities:null;if(f){const d={...a};delete d.entities;for(const y of f)s.push(Mn(o,d,y));continue}s.push({...o,...a});continue}if(typeof a!="string"||a.trim()===""){s.push({...o,entity:a});continue}s.push({...o,entity:a.trim()})}}return s}function Mn(e,t,n){return p(n)?{...e,...t,...n}:typeof n=="string"&&n.trim()!==""?{...e,...t,entity:n.trim()}:{...e,...t,entity:n}}function Un(e){const t={};for(const n of["op","sourceFile","file","target","usageTarget","dir","scope","scopes","excludeTarget","includeTarget","ranges","includeRanges","resolveStar","localOnly","parent","offset","limit","all","memberOffset","memberLimit","memberAll","detail","mode","kinds","entities","entity","exclude","excludes","pathExclude","pathExcludes","excludePath","excludePaths","toFile","outputFile","save","show","bundleSave","bundle","saveBundle","previewFiles","preview","previewDir","outputDir","previewPatch","modules","facade","facadeFile"])e[n]!==void 0&&(t[n]=e[n]);return t}function O(e,t){const n=e.indexOf(t);if(n<0)return null;const s=e[n+1];return s&&!s.startsWith("--")?s:null}function K(e,t){const n=[];for(let s=0;s<e.length;s+=1){if(e[s]!==t)continue;const i=e[s+1];i&&!i.startsWith("--")&&n.push(i)}return n}function rt(e,t){const n=e.indexOf(t);return n>0&&(e[n-1]==="--parent"||e[n-1]==="--max-lines"||e[n-1]==="--to-file"||e[n-1]==="--save"||e[n-1]==="--bundle-save"||e[n-1]==="--preview-dir"||e[n-1]==="--from-json"||e[n-1]==="--from-dsl"||e[n-1]==="--from"||e[n-1]==="--offset"||e[n-1]==="--limit"||e[n-1]==="--max-code-lines"||e[n-1]==="--maxCodeLines"||e[n-1]==="--scope"||e[n-1]==="--detail"||e[n-1]==="--mode"||e[n-1]==="--kind"||e[n-1]==="--kinds"||e[n-1]==="--entity"||e[n-1]==="--entities"||e[n-1]==="--exclude"||e[n-1]==="--excludes"||e[n-1]==="--path-exclude"||e[n-1]==="--path-excludes"||e[n-1]==="--exclude-path"||e[n-1]==="--exclude-paths")}function kn(e,t,n){return Array.isArray(t)?t.filter(p).map(s=>{const i=r(s.target)??r(s.targetFile)??r(s.file),o=Array.isArray(s.entities)?s.entities:Array.isArray(s.symbols)?s.symbols:[];return{...i?{targetFile:j(e,i)}:{},symbols:o.map(c=>Rn(c,n)).filter(p)}}):[]}function Bn(e,t){return e.flatMap(n=>lt(n,t,{})).filter(p)}function lt(e,t,n){if(typeof e=="string"&&e.trim()!==""){const a=(0,k.parseInspectSelector)(e,t);return[{...n,raw:e.trim(),symbolName:a.symbolName,...a.symbolKind?{symbolKind:a.symbolKind}:{}}]}if(!p(e))return[];const s=r(e.parent),i={...n};if(s){const a=(0,k.parseInspectSelector)(s,t);i.parentName=a.symbolName,a.symbolKind&&(i.parentKind=a.symbolKind)}const o=Array.isArray(e.entities)?e.entities:null;if(o)return o.flatMap(a=>lt(a,t,i));const c=r(e.entity)??r(e.selector)??r(e.raw);if(!c)return[];const l=(0,k.parseInspectSelector)(c,t);return[{...i,raw:c,symbolName:l.symbolName,...l.symbolKind?{symbolKind:l.symbolKind}:{}}]}function Rn(e,t){if(typeof e=="string"&&e.trim()!==""){const s=(0,k.parseInspectSelector)(e,t);return{raw:e.trim(),symbolName:s.symbolName,...s.symbolKind?{symbolKind:s.symbolKind}:{}}}if(!p(e))return null;const n=r(e.entity)??r(e.selector)??r(e.raw);if(n){const s=(0,k.parseInspectSelector)(n,t);return{raw:n,symbolName:s.symbolName,...s.symbolKind?{symbolKind:s.symbolKind}:{}}}return e}function ct(e){return e==="file"||e==="exports"||e==="imports"||e==="members"||e==="code"||e==="deps"||e==="slice"||e==="modulePlan"||e==="usages"||e==="duplicate"||e==="duplicates"||e==="tree"||e==="cycles"}function at(e){return e==="deps"?"dependencies":e==="duplicate"?"duplicates":e==="cycles"?"cycles":e==="imports"?"imports":e}function ut(e,t){e!=="modulePlan"||t||ft()}function ft(){throw new E.CliError("INSPECT_MODULE_PLAN_UNSUPPORTED","inspect is limited to file, exports, members, code, slice, deps, usages, duplicates, graph, tree, cycles, and imports. Use modulePlan preview/revise/apply/validate for module extraction plans.")}function jn(e,t){return e[0]==="modulePlan"?!0:!e.includes("--stdin")||!p(t)?!1:r(t.op)==="modulePlan"?!0:(Array.isArray(t.requests)?t.requests:[]).some(i=>p(i)&&r(i.op)==="modulePlan")}function r(e){return typeof e=="string"&&e.trim()!==""?e.trim():null}function R(e){return typeof e=="string"&&e.trim()!==""?[e.trim()]:Array.isArray(e)?e.filter(t=>typeof t=="string"&&t.trim()!=="").map(t=>t.trim()):null}function pt(e){if(typeof e=="string"&&e.trim()!=="")return e.trim();if(!Array.isArray(e))return null;const t=e.find(n=>typeof n=="string"&&n.trim()!=="");return typeof t=="string"?t.trim():null}function Kn(e,t){const n=[...K(e,"--kind"),...K(e,"--kinds").flatMap(s=>s.split(","))];return yt(n,t)}function Vn(e,t){const n=R(e)??[];return yt(n.flatMap(s=>s.split(",")),t)}function de(e,t){return(Array.isArray(e)?e:typeof e=="string"?e.split(","):e&&typeof e=="object"&&!Array.isArray(e)?[e]:[]).flatMap(s=>{if(typeof s=="string"){const c=s.trim();if(!c)return[];const l=(0,k.parseInspectSelector)(c,t);return[mt(l.symbolName,l.symbolKind??null)]}if(!p(s))return[];const i=r(s.entity)??r(s.selector)??r(s.name);if(!i)return[];const o=(0,k.parseInspectSelector)(i,t);return[mt(o.symbolName,o.symbolKind??null)]})}function dt(e,t){return(Array.isArray(t)?t:typeof t=="string"?t.split(","):[]).filter(s=>typeof s=="string").map(s=>s.trim()).filter(s=>s.length>0).map(s=>M.isAbsolute(s)?s:M.resolve(e,s)).map(s=>s.replace(/\\/g,"/"))}function mt(e,t){return t?{symbolName:e,symbolKind:t}:{symbolName:e}}function yt(e,t){const n=new Map;for(const[i,o]of Object.entries(t.entityKindAliases))n.set(i.toLowerCase(),i),n.set(String(o).toLowerCase(),i);const s=e.map(i=>n.get(i.trim().toLowerCase())??"").filter(i=>i!=="");return Array.from(new Set(s))}function p(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}
@@ -1,2 +1,2 @@
1
- "use strict";var Y=exports&&exports.__createBinding||(Object.create?(function(e,t,r,n){n===void 0&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}):(function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]})),Q=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),w=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(r){var n=[];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(n[n.length]=i);return n},e(t)};return function(t){if(t&&t.__esModule)return t;var r={};if(t!=null)for(var n=e(t),i=0;i<n.length;i++)n[i]!=="default"&&Y(r,t,n[i]);return Q(r,t),r}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.runMoveToFile=oe;const F=w(require("node:path")),j=w(require("node:fs")),p=require("zod"),Z=require("../client/http-client"),W=require("../shared/agent-text"),E=require("../shared/errors"),ee=require("../shared/routes"),te=require("../shared/protocol"),z=require("../config/import-rules"),D=require("../config/mutation-comments"),x=require("./shared"),re=require("../selectors/parse-entities"),ne=require("./entity-resolution"),h=require("./move-preview-cache"),T=require("../metrics/central-metrics"),k=require("../shared/event-loop"),C=require("../diagnostics/module-plan-timeline"),ie=require("../config/env-vars"),N=p.z.object({sourceFile:p.z.string().min(1),targetFile:p.z.string().min(1),entities:p.z.union([p.z.array(p.z.string().min(1)).min(1),p.z.string().min(1)]),execute:p.z.boolean().optional()});async function oe(e,t,r={},n=[],i={}){const l=Me(n,"--preview");if(l)return le(e,l,r);const f=N.parse(t);return V(e,f,r,void 0,i)}async function le(e,t,r){const n=(0,h.readMovePreviewRecord)(e,t);if((0,h.hashFile)(n.sourceFile)!==n.sourceHash)throw new E.CliError("MOVE_PREVIEW_SOURCE_CHANGED","Source file changed after move preview. Rerun move preview.",{previewId:t,sourceFile:u(e,n.sourceFile)});const l=j.existsSync(n.targetFile),f=(0,h.hashFileIfExists)(n.targetFile);if(l!==n.targetExisted||f!==n.targetHash)throw new E.CliError("MOVE_PREVIEW_TARGET_CHANGED","Target file changed after move preview. Rerun move preview.",{previewId:t,targetFile:u(e,n.targetFile)});const o=N.parse({...n.normalizedPayload,execute:!0}),c=await V(e,o,r,{previewId:t}),a={...c,operation:"move.toFile.apply",...c.ok===!1?{next:"Fix the move request and rerun preview."}:{}};return(0,W.attachAgentText)(a,B(a))}async function V(e,t,r,n,i={}){const l=await(0,x.resolveCompatibleTargetInstance)(e,te.CLI_COMMAND_IDS.moveToFile,r),f=await(0,x.fetchEffectiveConfig)(l.entry,r),o=(0,re.parseEntitySelectors)(t.entities,f),c=K(e,t.sourceFile),a=K(e,t.targetFile),_=r.importRules??(0,z.readConfigImportRules)(e),I=r.mutationComments??(0,D.normalizeMutationCommentsPolicy)(void 0),y=t.execute===!0,g=[],b=typeof i.metricsContext?.executionId=="string"?i.metricsContext.executionId:void 0;(0,C.recordModulePlanTimeline)(e,b,"moveToFile.resolveSelectors.start",{sourceFile:u(e,c),targetFile:u(e,a),entityCount:o.length,execute:y}),await(0,ne.ensureSelectorsResolvable)(l.entry,c,o,f,(0,x.extensionRequestOptions)(r)),(0,C.recordModulePlanTimeline)(e,b,"moveToFile.resolveSelectors.end",{sourceFile:u(e,c),targetFile:u(e,a),entityCount:o.length,execute:y});for(const s of o){await(0,k.yieldToEventLoop)(),(0,C.recordModulePlanTimeline)(e,b,"moveToFile.entity.start",{sourceFile:u(e,c),targetFile:u(e,a),entity:s.raw,execute:y});const M=(0,T.startCentralMetricSpan)({kind:"mutation.entity",operation:y?"move.toFile.execute":"move.toFile.preview",cwd:F.resolve(e),sourceFile:u(e,c),targetFile:u(e,a),entity:s.raw,...i.metricsContext??{}});try{const m=process.env[ie.CLI_ENV.testMoveToFileFailEntity];if(y&&m&&s.raw===m)throw new E.CliError("TS_MOVE_TO_FILE_UNSUPPORTED_BY_ENGINE","TypeScript refactor failed: Debug Failure. False expression: Expected symbol to be a module",{diagnostic:"typescript-refactor-limitation",hint:"TypeScript move-to-file can fail on symbols that depend on default imports from CommonJS `export =` packages, e.g. `fast-json-stable-stringify`. If smaller moves still fail, use manual extraction.",next:"Retry with a smaller move or use manual extraction if TypeScript rejects the refactor."});const S=await(0,Z.postJson)(l.entry,ee.EXTENSION_ROUTES.moveRefactor,{sourceFile:c,targetFile:a,symbolName:s.symbolName,symbolKind:s.symbolKind,execute:y,importRules:(0,z.importRulesToJson)(_),mutationComments:(0,D.mutationCommentsPolicyToJson)(I),impactMetrics:(0,T.mutationImpactMetricsEnabled)()},(0,x.extensionRequestOptions)(r));g.push({entity:s.raw,...ue(e,s.raw,S)}),(0,C.recordModulePlanTimeline)(e,b,"moveToFile.entity.end",{sourceFile:u(e,c),targetFile:u(e,a),entity:s.raw,execute:y,ok:!0}),M.end(se(e,S,g[g.length-1]??{},o.length)),H(i,s.raw,g,o.length),await(0,k.yieldToEventLoop)()}catch(m){g.push(fe(s.raw,m)),(0,C.recordModulePlanTimeline)(e,b,"moveToFile.entity.end",{sourceFile:u(e,c),targetFile:u(e,a),entity:s.raw,execute:y,ok:!1,error:m instanceof Error?m.message:String(m)}),M.end({ok:!1,code:m instanceof E.CliError?m.code:"MOVE_TO_FILE_FAILED",error:m instanceof Error?m.message:String(m),totalEntities:o.length}),H(i,s.raw,g,o.length),await(0,k.yieldToEventLoop)();break}}const A=g.every(s=>s.ok!==!1),X=g.filter(s=>s.ok===!1).length,$=ye(c,a,o.map(s=>s.raw),y),O=L(g,"changedFiles"),q=L(g,"savedFiles"),v={...A?{}:{ok:!1},operation:y?"move.toFile.execute":"move.toFile.preview",source:u(e,c),target:u(e,a),...o.length===1?{move:o[0].raw}:{moves:o.map(s=>s.raw)},summary:A?ge(y,o.length,O,q,a):de(o.length,X),...!y&&O.length>0?{files:P(O,5)}:{},...y&&q.length>0?{filesWritten:P(q,5)}:{},...A?{}:{results:g}};if(!y&&A){const s=(0,h.buildMovePreviewId)($),M=(0,h.hashFile)(c),m=(0,h.hashFileIfExists)(a),S=(0,h.buildMovePreviewHash)($,M,m,v);(0,h.writeMovePreviewRecord)(e,{previewId:s,previewHash:S,createdAt:new Date().toISOString(),cwd:F.resolve(e),sourceFile:c,sourceHash:M,targetFile:a,targetExisted:j.existsSync(a),targetHash:m,normalizedPayload:$,previewResult:v}),v.previewId=s,v.next=`aib move toFile apply ${s}`}return ae(e,v,i.metricsContext),(0,W.attachAgentText)(v,B(v))}function ae(e,t,r){(0,T.recordCentralMetric)({kind:"mutation.summary",operation:typeof t.operation=="string"?t.operation:"move.toFile",cwd:F.resolve(e),ok:t.ok!==!1,sourceFile:typeof t.source=="string"?t.source:null,targetFile:typeof t.target=="string"?t.target:null,summary:typeof t.summary=="string"?t.summary:null,filesWrittenCount:Array.isArray(t.filesWritten)?t.filesWritten.filter(n=>typeof n=="string"&&!n.startsWith("+")).length:0,...r??{}})}function se(e,t,r,n){const i=d(t.referenceImpact)?t.referenceImpact:{},l=d(t.operationSummary)?t.operationSummary:{};return{ok:t.ok!==!1,totalEntities:n,editCount:typeof l.editCount=="number"?l.editCount:null,changedFileCount:Array.isArray(r.allChangedFiles)?r.allChangedFiles.length:0,savedFileCount:Array.isArray(r.allSavedFiles)?r.allSavedFiles.length:0,...(0,T.mutationImpactMetricsEnabled)()?{impactCollectionMs:typeof i.impactCollectionMs=="number"?i.impactCollectionMs:null,impact:ce(i),changedFiles:Array.isArray(r.allChangedFiles)?r.allChangedFiles:[],savedFiles:Array.isArray(r.allSavedFiles)?r.allSavedFiles:[]}:{},configFilePath:typeof t.configFilePath=="string"?u(e,t.configFilePath):null}}function ce(e){return{referenceCount:typeof e.referenceCount=="number"?e.referenceCount:null,definitionCount:typeof e.definitionCount=="number"?e.definitionCount:null,realReferenceCount:typeof e.realReferenceCount=="number"?e.realReferenceCount:null,importExportReferenceCount:typeof e.importExportReferenceCount=="number"?e.importExportReferenceCount:null,fileCount:typeof e.fileCount=="number"?e.fileCount:null,realReferenceFileCount:typeof e.realReferenceFileCount=="number"?e.realReferenceFileCount:null,impactCollectionMs:typeof e.impactCollectionMs=="number"?e.impactCollectionMs:null}}function H(e,t,r,n){e.onProgress&&e.onProgress({entity:t,completedEntities:r.length,totalEntities:n,filesWritten:L(r,"savedFiles"),ok:r.every(i=>i.ok!==!1)})}function ue(e,t,r){const n=d(r.operationSummary)?r.operationSummary:{},i=Array.isArray(n.changedFiles)?n.changedFiles.filter(o=>typeof o=="string").map(o=>u(e,o)):[],l=Array.isArray(r.savedFiles)?r.savedFiles.filter(o=>typeof o=="string").map(o=>u(e,o)):[],f=Array.isArray(n.warnings)?n.warnings.filter(d).map(o=>typeof o.code=="string"?o.code:"MOVE_WARNING"):[];return R({entity:t,ok:r.ok!==!1,applied:typeof r.applied=="boolean"?r.applied:null,editCount:typeof n.editCount=="number"?n.editCount:null,allChangedFiles:i,changedFiles:P(i,5),allSavedFiles:l,savedFiles:P(l,5),warnings:f,code:typeof r.code=="string"?r.code:typeof r.errorCode=="string"?r.errorCode:null,error:typeof r.error=="string"?r.error:null,hint:typeof r.hint=="string"?r.hint:null})}function fe(e,t){const r=t instanceof E.CliError&&d(t.details)?t.details:{},n=d(r.details)?r.details:{},i=d(n.diagnostic)?n.diagnostic:{},l=Array.isArray(i.hints)?i.hints.filter(d).map(o=>typeof o.description=="string"?o.description:"").filter(o=>o.length>0):[],f=typeof r.hint=="string"?r.hint:typeof n.hint=="string"?n.hint:l[0]??null;return R({entity:e,ok:!1,code:t instanceof E.CliError?t.code:"MOVE_TO_FILE_FAILED",error:me(t instanceof Error?t.message:String(t)),diagnostic:typeof i.kind=="string"?i.kind:null,hint:f,next:"Retry with a smaller move or use manual extraction if TypeScript rejects the refactor."})}function me(e){return e.replace(/^TypeScript refactor failed: Debug Failure\. False expression: /,"")}function ye(e,t,r,n){return{sourceFile:e,targetFile:t,entities:r,execute:n}}function ge(e,t,r,n,i){const l=j.existsSync(i)?"target exists":"target will be created";return e?`${t} ${t===1?"symbol":"symbols"}, ${n.length} ${n.length===1?"file":"files"} written`:`${t} ${t===1?"symbol":"symbols"}, ${r.length} ${r.length===1?"file":"files"}; ${l}`}function de(e,t){return`${e} ${e===1?"symbol":"symbols"}, ${t} failed`}function L(e,t){const r=t==="changedFiles"?"allChangedFiles":"allSavedFiles";return Array.from(new Set(e.flatMap(n=>Array.isArray(n[r])?n[r].filter(i=>typeof i=="string"&&!i.startsWith("+")):Array.isArray(n[t])?n[t].filter(i=>typeof i=="string"&&!i.startsWith("+")):[]))).sort((n,i)=>n.localeCompare(i))}function P(e,t){const r=e.slice(0,t),n=e.length-r.length;return n>0?[...r,`+ ${n} more`]:r}function B(e){const t=typeof e.operation=="string"?e.operation:"";if(t!=="move.toFile.preview"&&t!=="move.toFile.execute"&&t!=="move.toFile.apply")return null;const r=[],n=typeof e.previewId=="string"?e.previewId:"";r.push(e.ok===!1?`${t} failed`:n&&t==="move.toFile.preview"?`${t} ${n}`:t);const i=ve(e),l=_e(e.results),f=Fe(e.results),o=l?U(l.entity):null,c=o?i.indexOf(o):-1,a=c>=0?i.slice(c+1):[],_=Array.isArray(e.filesWritten)?e.filesWritten:e.files,I=Ee(_);return r.push(pe(t,e,i.length,f.length,l?1:0,a.length,I)),e.ok!==!1?G(r,"moves:",e.target,i):f.length>0&&G(r,"moves:",e.target,f),he(r,l),a.length>0&&(r.push("not run:"),r.push(J(a,15))),Array.isArray(_)&&_.length>0&&(r.push(t==="move.toFile.preview"?"files:":"filesWritten:"),be(r,_)),typeof e.next=="string"&&r.push(`next: ${e.next}`),r.join(`
2
- `)}function pe(e,t,r,n,i,l,f){const o=`${r} ${r===1?"symbol":"symbols"}`;if(t.ok===!1){const a=[o];return n>0&&a.push(`${n} applied`),i>0&&a.push(`${i} failed`),l>0&&a.push(`${l} not run`),a.join(", ")}if(e==="move.toFile.preview")return`${o}, 1 target ready`;const c=`${f} ${f===1?"file":"files"} written`;return`${o}, 1 target moved; ${c}`}function G(e,t,r,n){typeof r!="string"||n.length===0||(e.push(t),e.push(`${r}: ${J(n,15)}`))}function he(e,t){if(!t)return;const r=typeof t.entity=="string"?t.entity:"symbol",n=typeof t.code=="string"?t.code:"MOVE_TO_FILE_FAILED",i=typeof t.error=="string"?t.error:"Move failed.";e.push("failed:"),e.push(r),e.push(`code: ${n}`),e.push(i),typeof t.hint=="string"&&e.push(`hint: ${t.hint}`)}function ve(e){return typeof e.move=="string"?[e.move]:Array.isArray(e.moves)?e.moves.filter(t=>typeof t=="string"):[]}function Fe(e){return Array.isArray(e)?e.filter(d).filter(t=>t.ok!==!1).map(t=>U(t.entity)).filter(t=>!!t):[]}function _e(e){return Array.isArray(e)?e.filter(d).find(t=>t.ok===!1)??null:null}function Ee(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&!t.startsWith("+")).length:0}function J(e,t){const r=e.slice(0,t),n=e.length-r.length;return n>0?`${r.join(", ")}, + ${n} more`:r.join(", ")}function be(e,t){if(Array.isArray(t))for(const r of t)typeof r=="string"&&e.push(r)}function U(e){return typeof e=="string"&&e.length>0?e:null}function K(e,t){const r=t.trim();return F.normalize(F.isAbsolute(r)?r:F.resolve(e,r))}function u(e,t){return F.relative(e,t).replace(/\\/g,"/")}function Me(e,t){const r=e.indexOf(t);if(r<0)return null;const n=e[r+1];return n&&!n.startsWith("--")?n:null}function R(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t==null?!1:!(Array.isArray(t)&&t.length===0)))}function d(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}
1
+ "use strict";var Y=exports&&exports.__createBinding||(Object.create?(function(e,t,r,n){n===void 0&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}):(function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]})),Q=exports&&exports.__setModuleDefault||(Object.create?(function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}):function(e,t){e.default=t}),k=exports&&exports.__importStar||(function(){var e=function(t){return e=Object.getOwnPropertyNames||function(r){var n=[];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(n[n.length]=i);return n},e(t)};return function(t){if(t&&t.__esModule)return t;var r={};if(t!=null)for(var n=e(t),i=0;i<n.length;i++)n[i]!=="default"&&Y(r,t,n[i]);return Q(r,t),r}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.runMoveToFile=oe;const F=k(require("node:path")),j=k(require("node:fs")),p=require("zod"),Z=require("../client/http-client"),w=require("../shared/agent-text"),E=require("../shared/errors"),ee=require("../shared/routes"),te=require("../shared/protocol"),W=require("../config/import-rules"),z=require("../config/mutation-comments"),x=require("./shared"),re=require("../selectors/parse-entities"),ne=require("./entity-resolution"),h=require("./move-preview-cache"),T=require("../metrics/central-metrics"),D=require("../shared/event-loop"),C=require("../diagnostics/module-plan-timeline"),ie=require("../config/env-vars"),N=p.z.object({sourceFile:p.z.string().min(1),targetFile:p.z.string().min(1),entities:p.z.union([p.z.array(p.z.string().min(1)).min(1),p.z.string().min(1)]),execute:p.z.boolean().optional()});async function oe(e,t,r={},n=[],i={}){const l=be(n,"--preview");if(l)return le(e,l,r);const f=N.parse(t);return V(e,f,r,void 0,i)}async function le(e,t,r){const n=(0,h.readMovePreviewRecord)(e,t);if((0,h.hashFile)(n.sourceFile)!==n.sourceHash)throw new E.CliError("MOVE_PREVIEW_SOURCE_CHANGED","Source file changed after move preview. Rerun move preview.",{previewId:t,sourceFile:u(e,n.sourceFile)});const l=j.existsSync(n.targetFile),f=(0,h.hashFileIfExists)(n.targetFile);if(l!==n.targetExisted||f!==n.targetHash)throw new E.CliError("MOVE_PREVIEW_TARGET_CHANGED","Target file changed after move preview. Rerun move preview.",{previewId:t,targetFile:u(e,n.targetFile)});const o=N.parse({...n.normalizedPayload,execute:!0}),c=await V(e,o,r,{previewId:t}),a={...c,operation:"move.toFile.apply",...c.ok===!1?{next:"Fix the move request and rerun preview."}:{}};return(0,w.attachAgentText)(a,B(a))}async function V(e,t,r,n,i={}){const l=await(0,x.resolveCompatibleTargetInstance)(e,te.CLI_COMMAND_IDS.moveToFile,r),f=await(0,x.fetchEffectiveConfig)(l.entry,r),o=(0,re.parseEntitySelectors)(t.entities,f),c=J(e,t.sourceFile),a=J(e,t.targetFile),_=r.importRules??(0,W.readConfigImportRules)(e),O=r.mutationComments??(0,z.normalizeMutationCommentsPolicy)(void 0),y=t.execute===!0,d=[],M=typeof i.metricsContext?.executionId=="string"?i.metricsContext.executionId:void 0;(0,C.recordModulePlanTimeline)(e,M,"moveToFile.resolveSelectors.start",{sourceFile:u(e,c),targetFile:u(e,a),entityCount:o.length,execute:y}),await(0,ne.ensureSelectorsResolvable)(l.entry,c,o,f,(0,x.extensionRequestOptions)(r)),(0,C.recordModulePlanTimeline)(e,M,"moveToFile.resolveSelectors.end",{sourceFile:u(e,c),targetFile:u(e,a),entityCount:o.length,execute:y});for(const s of o){await(0,D.yieldToEventLoop)(),(0,C.recordModulePlanTimeline)(e,M,"moveToFile.entity.start",{sourceFile:u(e,c),targetFile:u(e,a),entity:s.raw,execute:y});const b=(0,T.startCentralMetricSpan)({kind:"mutation.entity",operation:y?"move.toFile.execute":"move.toFile.preview",cwd:F.resolve(e),sourceFile:u(e,c),targetFile:u(e,a),entity:s.raw,...i.metricsContext??{}});try{const m=process.env[ie.CLI_ENV.testMoveToFileFailEntity];if(y&&m&&s.raw===m)throw new E.CliError("TS_MOVE_TO_FILE_UNSUPPORTED_BY_ENGINE","TypeScript refactor failed: Debug Failure. False expression: Expected symbol to be a module",{diagnostic:"typescript-refactor-limitation",hint:"TypeScript move-to-file can fail on symbols that depend on default imports from CommonJS `export =` packages, e.g. `fast-json-stable-stringify`. If smaller moves still fail, use manual extraction.",next:"Retry with a smaller move or use manual extraction if TypeScript rejects the refactor."});const S=await(0,Z.postJson)(l.entry,ee.EXTENSION_ROUTES.moveRefactor,{sourceFile:c,targetFile:a,symbolName:s.symbolName,symbolKind:s.symbolKind,execute:y,importRules:(0,W.importRulesToJson)(_),mutationComments:(0,z.mutationCommentsPolicyToJson)(O),impactMetrics:(0,T.mutationImpactMetricsEnabled)()},(0,x.extensionRequestOptions)(r));d.push({entity:s.raw,...ue(e,s.raw,S)}),(0,C.recordModulePlanTimeline)(e,M,"moveToFile.entity.end",{sourceFile:u(e,c),targetFile:u(e,a),entity:s.raw,execute:y,ok:!0}),b.end(se(e,S,d[d.length-1]??{},o.length)),H(i,s.raw,d,o.length),await(0,D.yieldToEventLoop)()}catch(m){d.push(fe(s.raw,m)),(0,C.recordModulePlanTimeline)(e,M,"moveToFile.entity.end",{sourceFile:u(e,c),targetFile:u(e,a),entity:s.raw,execute:y,ok:!1,error:m instanceof Error?m.message:String(m)}),b.end({ok:!1,code:m instanceof E.CliError?m.code:"MOVE_TO_FILE_FAILED",error:m instanceof Error?m.message:String(m),totalEntities:o.length}),H(i,s.raw,d,o.length),await(0,D.yieldToEventLoop)();break}}const A=d.every(s=>s.ok!==!1),X=d.filter(s=>s.ok===!1).length,P=ye(c,a,o.map(s=>s.raw),y),$=L(d,"changedFiles"),q=L(d,"savedFiles"),v={...A?{}:{ok:!1},operation:y?"move.toFile.execute":"move.toFile.preview",source:u(e,c),target:u(e,a),...o.length===1?{move:o[0].raw}:{moves:o.map(s=>s.raw)},summary:A?ge(y,o.length,$,q,a):de(o.length,X),...!y&&$.length>0?{files:I($,5)}:{},...y&&q.length>0?{filesWritten:I(q,5)}:{},...A?{}:{results:d}};if(!y&&A){const s=(0,h.buildMovePreviewId)(P),b=(0,h.hashFile)(c),m=(0,h.hashFileIfExists)(a),S=(0,h.buildMovePreviewHash)(P,b,m,v);(0,h.writeMovePreviewRecord)(e,{previewId:s,previewHash:S,createdAt:new Date().toISOString(),cwd:F.resolve(e),sourceFile:c,sourceHash:b,targetFile:a,targetExisted:j.existsSync(a),targetHash:m,normalizedPayload:P,previewResult:v}),v.previewId=s,v.next=`aib move toFile apply ${s}`}return ae(e,v,i.metricsContext),(0,w.attachAgentText)(v,B(v))}function ae(e,t,r){(0,T.recordCentralMetric)({kind:"mutation.summary",operation:typeof t.operation=="string"?t.operation:"move.toFile",cwd:F.resolve(e),ok:t.ok!==!1,sourceFile:typeof t.source=="string"?t.source:null,targetFile:typeof t.target=="string"?t.target:null,summary:typeof t.summary=="string"?t.summary:null,filesWrittenCount:Array.isArray(t.filesWritten)?t.filesWritten.filter(n=>typeof n=="string"&&!n.startsWith("+")).length:0,...r??{}})}function se(e,t,r,n){const i=g(t.referenceImpact)?t.referenceImpact:{},l=g(t.operationSummary)?t.operationSummary:{};return{ok:t.ok!==!1,totalEntities:n,editCount:typeof l.editCount=="number"?l.editCount:null,changedFileCount:Array.isArray(r.allChangedFiles)?r.allChangedFiles.length:0,savedFileCount:Array.isArray(r.allSavedFiles)?r.allSavedFiles.length:0,...(0,T.mutationImpactMetricsEnabled)()?{impactCollectionMs:typeof i.impactCollectionMs=="number"?i.impactCollectionMs:null,impact:ce(i),changedFiles:Array.isArray(r.allChangedFiles)?r.allChangedFiles:[],savedFiles:Array.isArray(r.allSavedFiles)?r.allSavedFiles:[]}:{},configFilePath:typeof t.configFilePath=="string"?u(e,t.configFilePath):null}}function ce(e){return{referenceCount:typeof e.referenceCount=="number"?e.referenceCount:null,definitionCount:typeof e.definitionCount=="number"?e.definitionCount:null,realReferenceCount:typeof e.realReferenceCount=="number"?e.realReferenceCount:null,importExportReferenceCount:typeof e.importExportReferenceCount=="number"?e.importExportReferenceCount:null,fileCount:typeof e.fileCount=="number"?e.fileCount:null,realReferenceFileCount:typeof e.realReferenceFileCount=="number"?e.realReferenceFileCount:null,impactCollectionMs:typeof e.impactCollectionMs=="number"?e.impactCollectionMs:null}}function H(e,t,r,n){e.onProgress&&e.onProgress({entity:t,completedEntities:r.length,totalEntities:n,filesWritten:L(r,"savedFiles"),ok:r.every(i=>i.ok!==!1)})}function ue(e,t,r){const n=g(r.operationSummary)?r.operationSummary:{},i=Array.isArray(n.changedFiles)?n.changedFiles.filter(o=>typeof o=="string").map(o=>u(e,o)):[],l=Array.isArray(r.savedFiles)?r.savedFiles.filter(o=>typeof o=="string").map(o=>u(e,o)):[],f=Array.isArray(n.warnings)?n.warnings.filter(g).map(o=>typeof o.code=="string"?o.code:"MOVE_WARNING"):[];return K({entity:t,ok:r.ok!==!1&&r.applied!==!1,applied:typeof r.applied=="boolean"?r.applied:null,editCount:typeof n.editCount=="number"?n.editCount:null,allChangedFiles:i,changedFiles:I(i,5),allSavedFiles:l,savedFiles:I(l,5),warnings:f,code:typeof r.code=="string"?r.code:typeof r.errorCode=="string"?r.errorCode:null,error:typeof r.error=="string"?r.error:null,hint:typeof r.hint=="string"?r.hint:null})}function fe(e,t){const r=t instanceof E.CliError&&g(t.details)?t.details:{},n=g(r.details)?r.details:g(r.payload)?r.payload:{},i=g(n.diagnostic)?n.diagnostic:{},l=Array.isArray(i.hints)?i.hints.filter(g).map(o=>typeof o.description=="string"?o.description:"").filter(o=>o.length>0):[],f=typeof r.hint=="string"?r.hint:typeof n.hint=="string"?n.hint:l[0]??null;return K({entity:e,ok:!1,code:t instanceof E.CliError?t.code:"MOVE_TO_FILE_FAILED",error:me(t instanceof Error?t.message:String(t)),diagnostic:typeof i.kind=="string"?i.kind:null,...process.env.AIB_MOVE_TO_FILE_DEBUG_REMOTE_ERROR==="1"?{remoteDetails:n}:{},hint:f,next:"Retry with a smaller move or use manual extraction if TypeScript rejects the refactor."})}function me(e){return e.replace(/^TypeScript refactor failed: Debug Failure\. False expression: /,"")}function ye(e,t,r,n){return{sourceFile:e,targetFile:t,entities:r,execute:n}}function ge(e,t,r,n,i){const l=j.existsSync(i)?"target exists":"target will be created";return e?`${t} ${t===1?"symbol":"symbols"}, ${n.length} ${n.length===1?"file":"files"} written`:`${t} ${t===1?"symbol":"symbols"}, ${r.length} ${r.length===1?"file":"files"}; ${l}`}function de(e,t){return`${e} ${e===1?"symbol":"symbols"}, ${t} failed`}function L(e,t){const r=t==="changedFiles"?"allChangedFiles":"allSavedFiles";return Array.from(new Set(e.flatMap(n=>Array.isArray(n[r])?n[r].filter(i=>typeof i=="string"&&!i.startsWith("+")):Array.isArray(n[t])?n[t].filter(i=>typeof i=="string"&&!i.startsWith("+")):[]))).sort((n,i)=>n.localeCompare(i))}function I(e,t){const r=e.slice(0,t),n=e.length-r.length;return n>0?[...r,`+ ${n} more`]:r}function B(e){const t=typeof e.operation=="string"?e.operation:"";if(t!=="move.toFile.preview"&&t!=="move.toFile.execute"&&t!=="move.toFile.apply")return null;const r=[],n=typeof e.previewId=="string"?e.previewId:"";r.push(e.ok===!1?`${t} failed`:n&&t==="move.toFile.preview"?`${t} ${n}`:t);const i=ve(e),l=_e(e.results),f=Fe(e.results),o=l?U(l.entity):null,c=o?i.indexOf(o):-1,a=c>=0?i.slice(c+1):[],_=Array.isArray(e.filesWritten)?e.filesWritten:e.files,O=Ee(_);return r.push(pe(t,e,i.length,f.length,l?1:0,a.length,O)),e.ok!==!1?G(r,"moves:",e.target,i):f.length>0&&G(r,"moves:",e.target,f),he(r,l),a.length>0&&(r.push("not run:"),r.push(R(a,15))),Array.isArray(_)&&_.length>0&&(r.push(t==="move.toFile.preview"?"files:":"filesWritten:"),Me(r,_)),typeof e.next=="string"&&r.push(`next: ${e.next}`),r.join(`
2
+ `)}function pe(e,t,r,n,i,l,f){const o=`${r} ${r===1?"symbol":"symbols"}`;if(t.ok===!1){const a=[o];return n>0&&a.push(`${n} applied`),i>0&&a.push(`${i} failed`),l>0&&a.push(`${l} not run`),a.join(", ")}if(e==="move.toFile.preview")return`${o}, 1 target ready`;const c=`${f} ${f===1?"file":"files"} written`;return`${o}, 1 target moved; ${c}`}function G(e,t,r,n){typeof r!="string"||n.length===0||(e.push(t),e.push(`${r}: ${R(n,15)}`))}function he(e,t){if(!t)return;const r=typeof t.entity=="string"?t.entity:"symbol",n=typeof t.code=="string"?t.code:"MOVE_TO_FILE_FAILED",i=typeof t.error=="string"?t.error:"Move failed.";e.push("failed:"),e.push(r),e.push(`code: ${n}`),e.push(i),process.env.AIB_MOVE_TO_FILE_DEBUG_REMOTE_ERROR==="1"&&g(t.remoteDetails)&&e.push(`remoteDetails: ${JSON.stringify(t.remoteDetails)}`),typeof t.hint=="string"&&e.push(`hint: ${t.hint}`)}function ve(e){return typeof e.move=="string"?[e.move]:Array.isArray(e.moves)?e.moves.filter(t=>typeof t=="string"):[]}function Fe(e){return Array.isArray(e)?e.filter(g).filter(t=>t.ok!==!1).map(t=>U(t.entity)).filter(t=>!!t):[]}function _e(e){return Array.isArray(e)?e.filter(g).find(t=>t.ok===!1)??null:null}function Ee(e){return Array.isArray(e)?e.filter(t=>typeof t=="string"&&!t.startsWith("+")).length:0}function R(e,t){const r=e.slice(0,t),n=e.length-r.length;return n>0?`${r.join(", ")}, + ${n} more`:r.join(", ")}function Me(e,t){if(Array.isArray(t))for(const r of t)typeof r=="string"&&e.push(r)}function U(e){return typeof e=="string"&&e.length>0?e:null}function J(e,t){const r=t.trim();return F.normalize(F.isAbsolute(r)?r:F.resolve(e,r))}function u(e,t){return F.relative(e,t).replace(/\\/g,"/")}function be(e,t){const r=e.indexOf(t);if(r<0)return null;const n=e[r+1];return n&&!n.startsWith("--")?n:null}function K(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t==null?!1:!(Array.isArray(t)&&t.length===0)))}function g(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}
@@ -0,0 +1,2 @@
1
+ "use strict";var _=exports&&exports.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.runOtaCommand=H;const d=_(require("node:fs")),l=_(require("node:path")),J=require("node:crypto"),R=require("../session/daemon-state"),W=require("../workers/product-storage"),U=1;async function H(t){const e=At(t);return e.action==="status"?X(e):e.action==="stop"?K(e):e.action==="run-once"?$(e):e.action==="rollback"?Y(e):e.action==="cleanup"?Z(e):e.action==="watch"?Q(e):{ok:!1,command:"ota",error:`Unknown ota action: ${e.action}`,availableActions:["run-once","watch","stop","status","rollback","cleanup"]}}function X(t){const e=yt(t),n=b(t.watchPath);return{ok:!0,command:"ota",action:"status",lanes:e,daemon:wt(t),watch:bt(n,t)}}function K(t){const e=b(t.watchPath),n=e?.status==="running"&&V(e.pid);return k(t.stopPath,{schemaVersion:1,requestedAt:new Date().toISOString(),pid:process.pid,targetPid:n?e.pid:null}),{ok:!0,command:"ota",action:"stop",stopped:n,skipped:!n,reason:n?"stop requested":"no running ota watch"}}async function Q(t){const e=dt(t);if(e)return{ok:!0,command:"ota",action:"watch",skipped:!0,blocked:!0,reason:e};const n=b(t.watchPath);if(n?.status==="running"){if(V(n.pid))return{ok:!0,command:"ota",action:"watch",skipped:!0,reason:"ota watch is already running",pid:n.pid};D(t,{...n,status:"stale",updatedAt:new Date().toISOString(),finishedAt:new Date().toISOString()})}d.default.rmSync(t.stopPath,{force:!0});const a=Date.now();let i=0;for(;i<t.maxAttempts&&Date.now()-a<=t.timeoutMs;){if(i+=1,D(t,{schemaVersion:1,updatedAt:new Date().toISOString(),status:"running",pid:process.pid,startedAt:new Date(a).toISOString(),targetLanes:["cli-package"],intervalMs:t.intervalMs,timeoutMs:t.timeoutMs,maxAttempts:t.maxAttempts,attempts:i,stopPath:t.stopPath}),d.default.existsSync(t.stopPath))return j(t,"stopped",i,{ok:!0,command:"ota",action:"watch",stopped:!0,attempts:i});const r=$(t);if(r.activated===!0||r.skipped===!0)return j(t,r.activated===!0?"activated":"skipped",i,r);await Ct(t.intervalMs)}return j(t,"timeout",i,{ok:!1,command:"ota",action:"watch",status:"timeout",attempts:i,elapsedMs:Date.now()-a,watchPath:t.watchPath})}function $(t){return B(t,()=>{const e=m(t.statusPath),n=C(t.extensionStatusPath),a=ot(t,e,n);if(a.blocked)return{ok:!0,command:"ota",action:"run-once",blocked:!0,reason:a.reason??"OTA activation is blocked",...a.lane?{lane:a.lane}:{},...a.groupId?{activationGroupId:a.groupId}:{},...a.statusPath?{statusPath:a.statusPath}:{}};if(a.items.length===0)return{ok:!0,command:"ota",action:"run-once",skipped:!0,reason:"no pending OTA activation"};const i=new Date().toISOString();let r=e,o=n;for(const s of a.items)s.lane==="cli-package"&&e?.pending&&(r=rt(e,t,i),O(t.statusPath,r)),s.lane==="extension-vsix"&&n?.pending&&(o=st(n,i),G(t.extensionStatusPath,o));for(const s of a.items){if(s.lane==="cli-package"&&r?.activating){const v=it(r,t,i);O(t.statusPath,v),k(t.pointerPath,{schemaVersion:1,updatedAt:v.updatedAt,packageVersion:r.activating.packageVersion,artifactVersion:r.activating.artifactVersion,activeRoot:r.activating.packageRoot,activeCliPath:r.activating.cliPath,entry:r.activating.entry})}s.lane==="extension-vsix"&&o?.activating&&G(t.extensionStatusPath,ct(o,i))}return{ok:!0,command:"ota",action:"run-once",activated:!0,lanes:a.items.map(s=>s.lane),...a.groupId?{activationGroupId:a.groupId}:{}}})}function Y(t){return B(t,()=>{const e=m(t.statusPath),n=C(t.extensionStatusPath),a=ht(t,e,n),i=new Date().toISOString(),r=[];if(e?.previous&&(!a||e.active?.activationGroup?.id===a||e.previous.activationGroup?.id===a)){const o=ut(e,t,i);O(t.statusPath,o),k(t.pointerPath,{schemaVersion:1,updatedAt:o.updatedAt,packageVersion:o.active.packageVersion,artifactVersion:o.active.artifactVersion,activeRoot:o.active.packageRoot,activeCliPath:o.active.cliPath,entry:o.active.entry}),r.push("cli-package")}return n?.previous&&(!a||n.active?.activationGroup?.id===a||n.previous.activationGroup?.id===a)&&(G(t.extensionStatusPath,lt(n,i)),r.push("extension-vsix")),r.length===0?{ok:!0,command:"ota",action:"rollback",skipped:!0,reason:a?`no previous OTA state for activation group ${a}`:"no previous OTA state"}:{ok:!0,command:"ota",action:"rollback",rolledBack:!0,lanes:r,...a?{activationGroupId:a}:{}}})}function Z(t){if(A(t).killSwitches.includes("ota-cleanup"))return{ok:!0,command:"ota",action:"cleanup",skipped:!0,reason:"OTA cleanup is disabled by policy kill-switch ota-cleanup"};const n=tt(t);let a=0,i=0;const r=[];if(!t.dryRun)for(const o of n)try{d.default.rmSync(o.path,{recursive:!0,force:!0}),a+=1}catch(s){i+=1,r.push({lane:o.lane,path:o.path,error:s instanceof Error?s.message:String(s)})}return{ok:i===0,command:"ota",action:"cleanup",dryRun:t.dryRun,candidates:n.length,removed:a,failed:i,byLane:at(n),...r.length>0?{failures:r}:{}}}function tt(t){const e=m(t.statusPath),n=C(t.extensionStatusPath);return[...L({lane:"cli-package",versionsRoot:l.default.join(t.productStorageRoot,"cli-package","versions"),protectedRoots:et(e),keepRecent:t.keepRecent}),...L({lane:"extension-vsix",versionsRoot:l.default.join(t.productStorageRoot,"extension","versions"),protectedRoots:nt(n),keepRecent:t.keepRecent}),...q(l.default.join(t.productStorageRoot,"cli-package"),".package-staging-","cli-package",t.stagingMaxAgeMs),...q(l.default.join(t.productStorageRoot,"extension"),".vsix-staging-","extension-vsix",t.stagingMaxAgeMs)]}function L(t){if(!d.default.existsSync(t.versionsRoot))return[];const e=d.default.readdirSync(t.versionsRoot,{withFileTypes:!0}).filter(n=>n.isDirectory()).map(n=>{const a=l.default.join(t.versionsRoot,n.name);return{lane:t.lane,kind:"version-root",path:a,mtimeMs:d.default.statSync(a).mtimeMs}}).filter(n=>!t.protectedRoots.has(l.default.resolve(n.path)));return e.sort((n,a)=>a.mtimeMs-n.mtimeMs),e.slice(t.keepRecent)}function q(t,e,n,a){if(!d.default.existsSync(t))return[];const i=Date.now();return d.default.readdirSync(t,{withFileTypes:!0}).filter(r=>r.isDirectory()&&r.name.startsWith(e)).map(r=>{const o=l.default.join(t,r.name);return{lane:n,kind:"staging-dir",path:o,mtimeMs:d.default.statSync(o).mtimeMs}}).filter(r=>i-r.mtimeMs>=a)}function et(t){return new Set([t?.active?.packageRoot,t?.previous?.packageRoot,t?.pending?.packageRoot,t?.activating?.packageRoot].filter(e=>typeof e=="string").map(e=>l.default.resolve(e)))}function nt(t){return new Set([t?.active?.vsixPath?l.default.dirname(t.active.vsixPath):void 0,t?.previous?.vsixPath?l.default.dirname(t.previous.vsixPath):void 0,t?.pending?.vsixPath?l.default.dirname(t.pending.vsixPath):void 0,t?.activating?.vsixPath?l.default.dirname(t.activating.vsixPath):void 0].filter(e=>typeof e=="string").map(e=>l.default.resolve(e)))}function at(t){const e={};for(const n of t){const a=e[n.lane]??{candidates:0,versionRoots:0,stagingDirs:0};a.candidates=Number(a.candidates)+1,n.kind==="version-root"?a.versionRoots=Number(a.versionRoots)+1:a.stagingDirs=Number(a.stagingDirs)+1,e[n.lane]=a}return e}function it(t,e,n=new Date().toISOString()){const a=t.activating??t.pending;return{schemaVersion:1,updatedAt:n,statusPath:e.statusPath,activePointerPath:e.pointerPath,activeRoot:a.packageRoot,activeCliPath:a.cliPath,active:{packageVersion:a.packageVersion,artifactVersion:a.artifactVersion,packageRoot:a.packageRoot,cliPath:a.cliPath,entry:a.entry,activatedAt:n,fileCount:a.fileCount,...a.activationGroup?{activationGroup:a.activationGroup}:{}},...t.active?{previous:{packageVersion:t.active.packageVersion,packageRoot:t.active.packageRoot,cliPath:t.active.cliPath,entry:t.active.entry,savedAt:n,...t.active.activationGroup?{activationGroup:t.active.activationGroup}:{}}}:t.previous?{previous:t.previous}:{},...t.staged?{staged:t.staged}:{}}}function rt(t,e,n){if(t.activating)return t;const a=t.pending;return{schemaVersion:1,updatedAt:n,statusPath:e.statusPath,activePointerPath:e.pointerPath,...t.activeRoot?{activeRoot:t.activeRoot}:{},...t.activeCliPath?{activeCliPath:t.activeCliPath}:{},...t.active?{active:t.active}:{},...t.previous?{previous:t.previous}:{},...t.staged?{staged:t.staged}:{},activating:{...a,activatingAt:n},...t.lastError?{lastError:t.lastError}:{}}}function ot(t,e,n){const a=[...e?.activating||e?.pending?[{lane:"cli-package",pending:e.activating??e.pending,status:e,statusPath:t.statusPath}]:[],...n?.activating||n?.pending?[{lane:"extension-vsix",pending:n.activating??n.pending,status:n,statusPath:t.extensionStatusPath}]:[]];if(a.length===0)return{items:[]};const i=I(t);if(i)return{items:[],blocked:!0,reason:i};for(const u of a){const g=M(t,u.lane);if(g)return{items:[],blocked:!0,reason:g,lane:u.lane,statusPath:u.statusPath};if(u.pending.reason)return{items:[],blocked:!0,reason:u.pending.reason,lane:u.lane,statusPath:u.statusPath};if(!(u.lane==="cli-package"?d.default.existsSync(u.pending.cliPath):d.default.existsSync(u.pending.vsixPath)))return{items:[],blocked:!0,reason:`${u.lane} pending artifact is missing`,lane:u.lane,statusPath:u.statusPath};const P=pt(u);if(P)return{items:[],blocked:!0,reason:P,lane:u.lane,statusPath:u.statusPath};const y=vt(t,u);if(y)return{items:[],blocked:!0,reason:y,lane:u.lane,statusPath:u.statusPath};const E=u.lane==="cli-package"?gt(t):null;if(E)return{items:[],blocked:!0,reason:E,lane:u.lane,statusPath:u.statusPath}}const r=a.find(u=>u.pending.activationGroup)?.pending.activationGroup;if(!r)return{items:[{lane:a[0].lane}]};const o=ft(t,r);if(o)return{items:[],blocked:!0,reason:o,groupId:r.id};const s=r.requiredLanes.length>0?r.requiredLanes:[a[0].lane],v=a.filter(u=>u.pending.activationGroup?.id===r.id);for(const u of s)if(!v.some(g=>g.lane===u))return{items:[],blocked:!0,reason:`activation group ${r.id} is missing required lane ${u}`,groupId:r.id};return{items:v.map(u=>({lane:u.lane})),groupId:r.id}}function ct(t,e=new Date().toISOString()){const n=t.activating??t.pending;return{schemaVersion:1,updatedAt:e,statusPath:t.statusPath,activeVsixPath:n.vsixPath,active:{extensionVersion:n.extensionVersion,artifactVersion:n.artifactVersion,vsixPath:n.vsixPath,entry:n.entry,activatedAt:e,sizeBytes:n.sizeBytes,sha256:n.sha256,...n.activationGroup?{activationGroup:n.activationGroup}:{}},...t.active?{previous:{extensionVersion:t.active.extensionVersion,vsixPath:t.active.vsixPath,entry:t.active.entry,savedAt:e,...t.active.activationGroup?{activationGroup:t.active.activationGroup}:{}}}:t.previous?{previous:t.previous}:{},...t.staged?{staged:t.staged}:{}}}function st(t,e){if(t.activating)return t;const n=t.pending;return{schemaVersion:1,updatedAt:e,statusPath:t.statusPath,...t.activeVsixPath?{activeVsixPath:t.activeVsixPath}:{},...t.active?{active:t.active}:{},...t.previous?{previous:t.previous}:{},...t.staged?{staged:t.staged}:{},activating:{...n,activatingAt:e},...t.delayedActivation?{delayedActivation:t.delayedActivation}:{},...t.lastError?{lastError:t.lastError}:{}}}function ut(t,e,n){const a=t.active,i=t.previous;return{schemaVersion:1,updatedAt:n,statusPath:e.statusPath,activePointerPath:e.pointerPath,activeRoot:i.packageRoot,activeCliPath:i.cliPath,active:{packageVersion:i.packageVersion,artifactVersion:`rollback:${i.packageVersion}`,packageRoot:i.packageRoot,cliPath:i.cliPath,entry:i.entry,activatedAt:n,fileCount:0,...i.activationGroup?{activationGroup:i.activationGroup}:{}},...a?{previous:{packageVersion:a.packageVersion,packageRoot:a.packageRoot,cliPath:a.cliPath,entry:a.entry,savedAt:n,...a.activationGroup?{activationGroup:a.activationGroup}:{}}}:{}}}function lt(t,e){const n=t.active,a=t.previous;return{schemaVersion:1,updatedAt:e,statusPath:t.statusPath,activeVsixPath:a.vsixPath,active:{extensionVersion:a.extensionVersion,artifactVersion:`rollback:${a.extensionVersion}`,vsixPath:a.vsixPath,entry:a.entry,activatedAt:e,sizeBytes:d.default.existsSync(a.vsixPath)?d.default.statSync(a.vsixPath).size:0,sha256:d.default.existsSync(a.vsixPath)?jt(a.vsixPath):"",...a.activationGroup?{activationGroup:a.activationGroup}:{}},...n?{previous:{extensionVersion:n.extensionVersion,vsixPath:n.vsixPath,entry:n.entry,savedAt:e,...n.activationGroup?{activationGroup:n.activationGroup}:{}}}:{}}}function I(t){return A(t).killSwitches.includes("ota-activation")?"OTA activation is disabled by policy kill-switch ota-activation":null}function dt(t){const e=A(t);return e.killSwitches.includes("ota-watch")?"OTA watch is disabled by policy kill-switch ota-watch":e.killSwitches.includes("ota-activation")?"OTA watch is disabled because OTA activation is disabled":null}function M(t,e){const n=A(t),a=[`${e}-activation`];e==="cli-package"&&a.push("cli-package-activation"),e==="extension-vsix"&&a.push("extension-vsix-activation");const i=a.find(r=>n.killSwitches.includes(r));return i?`${e} activation is disabled by policy kill-switch ${i}`:null}function vt(t,e){const n=e.pending.activationGroup,a=e.status.active?.activationGroup;if(n?.sequence!==void 0&&a?.sequence!==void 0)return n.sequence<=a.sequence&&n.allowDowngrade!==!0?`${e.lane} activation sequence ${n.sequence} is not newer than active sequence ${a.sequence}`:null;const i=e.lane==="cli-package"?e.pending.packageVersion:e.pending.extensionVersion,r=e.lane==="cli-package"?e.status.active?.packageVersion:e.status.active?.extensionVersion;return r&&Mt(i,r)<=0&&n?.allowDowngrade!==!0?`${e.lane} version ${i} is not newer than active version ${r}`:null}function pt(t){return t.pending.productStorageSchema!==void 0&&t.pending.productStorageSchema>U?`${t.lane} requires unsupported product storage schema ${t.pending.productStorageSchema}`:t.pending.nonReversibleMigration===!0?`${t.lane} requires a non-reversible storage migration`:null}function gt(t){const e=(0,R.readCliDaemonIdentity)(t.productStorageRoot);if(!e)return null;const n=z(e,t);return n.status==="dead"||n.status==="stale"||n.status==="stopped"?null:e.runningExecutions.length>0?`daemon has running executions: ${e.runningExecutions.map(i=>i.executionId).slice(0,3).join(", ")}`:e.activeInvokeCount>0?`daemon has ${e.activeInvokeCount} active invoke${e.activeInvokeCount===1?"":"s"}`:null}function ft(t,e){if(!e.channel)return null;const n=It(t);return n&&n!==e.channel?`activation group ${e.id} is scoped to channel ${e.channel}, but cached channel is ${n}`:null}function ht(t,e,n){return t.lane&&t.lane!=="cli-package"&&t.lane!=="extension-vsix"?t.lane:e?.active?.activationGroup?.id??n?.active?.activationGroup?.id??null}function B(t,e){d.default.mkdirSync(l.default.dirname(t.activationLockPath),{recursive:!0});try{T(t.activationLockPath)}catch(n){if(Ot(n))if(kt(t.activationLockPath))T(t.activationLockPath);else return{ok:!0,command:"ota",action:"run-once",blocked:!0,reason:"ota activation already locked",lockPath:t.activationLockPath};else throw n}try{return e()}finally{d.default.rmSync(t.activationLockPath,{recursive:!0,force:!0})}}function T(t){d.default.mkdirSync(t),k(l.default.join(t,"owner.json"),{schemaVersion:1,pid:process.pid,acquiredAt:new Date().toISOString()})}function kt(t){const e=l.default.join(t,"owner.json"),n=mt(e);return n&&V(n.pid)||!n&&!Pt(t)?!1:(d.default.rmSync(t,{recursive:!0,force:!0}),!0)}function mt(t){try{const e=JSON.parse(d.default.readFileSync(t,"utf8"));return e?.schemaVersion===1&&Number.isInteger(e.pid)?e:null}catch{return null}}function Pt(t){try{const e=d.default.statSync(t);return Date.now()-e.mtimeMs>6e4}catch{return!0}}function j(t,e,n,a){const i=a.ok!==!1&&e!=="timeout";return D(t,{schemaVersion:1,updatedAt:new Date().toISOString(),status:e,pid:process.pid,startedAt:b(t.watchPath)?.startedAt??new Date().toISOString(),finishedAt:new Date().toISOString(),targetLanes:["cli-package"],intervalMs:t.intervalMs,timeoutMs:t.timeoutMs,maxAttempts:t.maxAttempts,attempts:n,stopPath:t.stopPath,lastResult:a}),{ok:i,command:"ota",action:"watch",status:e,attempts:n,result:a,...i?{}:{watchPath:t.watchPath}}}function yt(t){const e=t.lane?[t.lane]:["cli-package","extension-vsix","worker-registry","worker-bundle","launcher-pack","policy-config","background-schedule"],n={};for(const a of e)n[a]=xt(a,t);return n}function xt(t,e){return t==="cli-package"?Vt(m(e.statusPath),e):t==="extension-vsix"?S(t,l.default.join(e.productStorageRoot,"extension","activation-status.json"),e):t==="worker-registry"?S(t,l.default.join(e.productStorageRoot,"workers","activation-status.json"),e):t==="launcher-pack"?S(t,l.default.join(e.productStorageRoot,"launchers","activation-status.json"),e):t==="policy-config"?N(t,l.default.join(e.productStorageRoot,"control-plane","policy-config.json"),"configVersion",e):t==="background-schedule"?N(t,l.default.join(e.productStorageRoot,"background","schedule-config.json"),"configVersion",e):t==="worker-bundle"?St(e):{lane:t,status:"unknown",error:`Unknown OTA lane: ${t}`,availableLanes:["cli-package","extension-vsix","worker-bundle","worker-registry","launcher-pack","policy-config","background-schedule"]}}function Vt(t,e){const n=I(e)??M(e,"cli-package");if(!t){const i={lane:"cli-package",status:n?"policy-disabled":"inactive",...n?{blocker:n}:{}};return e.verbose?{...i,statusPath:e.statusPath,activePointerPath:e.pointerPath}:i}const a={lane:"cli-package",status:t.activating?"activating":n||t.pending?.reason?"pending-blocked":t.pending?"pending-ready":t.active?"active":t.lastError?"error":"inactive",...t.active?.packageVersion?{activeVersion:t.active.packageVersion}:{},...t.activating?.packageVersion?{activatingVersion:t.activating.packageVersion}:{},...t.pending?.packageVersion?{pendingVersion:t.pending.packageVersion}:{},...n||t.pending?.reason?{blocker:n??t.pending.reason,statusPath:e.statusPath}:{},...t.previous?.packageVersion?{previousVersion:t.previous.packageVersion}:{},...t.lastError?{lastError:c(t.lastError.error)??"unknown error",statusPath:e.statusPath}:{}};return e.verbose?{...a,statusPath:e.statusPath,activePointerPath:e.pointerPath,active:t.active??null,pending:t.pending??null,activating:t.activating??null,previous:t.previous??null,staged:t.staged??null,lastError:t.lastError??null}:a}function S(t,e,n){const a=t==="extension-vsix"?I(n)??M(n,t):null,i=w(e);if(!i){const y={lane:t,status:a?"policy-disabled":"inactive",...a?{blocker:a}:{}};return n.verbose?{...y,statusPath:e}:y}const r=h(i.active),o=h(i.staged),s=h(i.pending),v=h(i.activating),u=h(i.delayedActivation),g=h(i.lastError),p=h(i.previous),P={lane:t,status:v?"activating":a||c(s?.reason)?"pending-blocked":s?"pending-ready":u?"pending-blocked":o?"staged":r?"active":g?"error":"inactive",...c(r?.packageVersion)?{activeVersion:c(r?.packageVersion)}:{},...c(r?.extensionVersion)?{activeVersion:c(r?.extensionVersion)}:{},...c(r?.launcherVersion)?{activeVersion:c(r?.launcherVersion)}:{},...c(r?.registryVersion)?{activeVersion:c(r?.registryVersion)}:{},...c(o?.packageVersion)?{stagedVersion:c(o?.packageVersion)}:{},...c(o?.extensionVersion)?{stagedVersion:c(o?.extensionVersion)}:{},...c(o?.launcherVersion)?{stagedVersion:c(o?.launcherVersion)}:{},...c(o?.registryVersion)?{stagedVersion:c(o?.registryVersion)}:{},...c(s?.packageVersion)?{pendingVersion:c(s?.packageVersion)}:{},...c(s?.extensionVersion)?{pendingVersion:c(s?.extensionVersion)}:{},...c(v?.packageVersion)?{activatingVersion:c(v?.packageVersion)}:{},...c(v?.extensionVersion)?{activatingVersion:c(v?.extensionVersion)}:{},...c(p?.packageVersion)?{previousVersion:c(p?.packageVersion)}:{},...c(p?.extensionVersion)?{previousVersion:c(p?.extensionVersion)}:{},...c(p?.launcherVersion)?{previousVersion:c(p?.launcherVersion)}:{},...c(p?.registryVersion)?{previousVersion:c(p?.registryVersion)}:{},...a||c(s?.reason)?{blocker:a??c(s?.reason),statusPath:e}:{},...c(u?.reason)&&!a&&!c(s?.reason)?{blocker:c(u?.reason),statusPath:e}:{},...c(g?.error)?{lastError:c(g?.error),statusPath:e}:{}};return n.verbose?{...P,statusPath:e,active:f(r),staged:f(o),pending:f(s),activating:f(v),previous:f(p),delayedActivation:f(u),lastError:f(g)}:P}function St(t){const e=l.default.join(t.productStorageRoot,"workers","bundles");if(!d.default.existsSync(e))return t.verbose?{lane:"worker-bundle",status:"inactive",root:e}:{lane:"worker-bundle",status:"inactive"};const n=[];for(const a of d.default.readdirSync(e)){const i=l.default.join(e,a,"activation-status.json");d.default.existsSync(i)&&n.push({workerId:a,...S("worker-bundle",i,t)})}return{lane:"worker-bundle",status:n.length>0?"configured":"inactive",count:n.length,bundles:n}}function N(t,e,n,a){const i=w(e);if(!i)return a.verbose?{lane:t,status:"inactive",configPath:e}:{lane:t,status:"inactive"};const r={lane:t,status:"configured",...c(i[n])?{version:c(i[n])}:{},...typeof i.enabled=="boolean"?{enabled:i.enabled}:{},...Array.isArray(i.routes)?{routeCount:i.routes.length}:{}};return a.verbose?{...r,configPath:e}:r}function bt(t,e){if(!t){const i={status:"inactive"};return e.verbose?{...i,statusPath:e.watchPath,stopPath:e.stopPath}:i}const n=t.status==="running"&&V(t.pid),a={status:n?"running":t.status==="running"?"stale":t.status,pid:t.pid,attempts:t.attempts,startedAt:t.startedAt,updatedAt:t.updatedAt,...t.finishedAt?{finishedAt:t.finishedAt}:{},...t.status==="running"&&!n?{statusPath:e.watchPath}:{},...t.lastResult&&(t.lastResult.ok===!1||e.verbose)?{lastResult:t.lastResult}:{}};return e.verbose?{...a,statusPath:e.watchPath,stopPath:e.stopPath}:a}function wt(t){const e=(0,R.readCliDaemonIdentity)(t.productStorageRoot);if(!e){const i={status:"unknown"};return t.verbose?{...i,identityPath:t.daemonIdentityPath}:i}const n=z(e,t),a={status:n.status,pid:e.pid,activeInvokeCount:e.activeInvokeCount,runningExecutionCount:e.runningExecutions.length,packageMismatch:n.packageMismatch,updatedAt:e.updatedAt};return t.verbose?{...a,identityPath:t.daemonIdentityPath,daemonId:e.daemonId,startedAt:e.startedAt,heartbeatAt:e.heartbeatAt,invokeProtocol:e.invokeProtocol,supportedModes:e.supportedModes,runningExecutions:e.runningExecutions,cliPath:e.cliPath,packageRoot:e.packageRoot,expectedCliPath:m(t.statusPath)?.active?.cliPath??null}:a}function z(t,e){const n=Date.parse(t.heartbeatAt),a=!Number.isFinite(n)||Date.now()-n>3e4,i=V(t.pid),r=m(e.statusPath)?.active?.cliPath,o=typeof r=="string"&&l.default.resolve(r)!==l.default.resolve(t.cliPath);return t.status==="stopped"?{status:"stopped",packageMismatch:o}:i?a?{status:"stale",packageMismatch:o}:t.activeInvokeCount>0||t.runningExecutions.length>0?{status:"busy",packageMismatch:o}:{status:"idle",packageMismatch:o}:{status:"dead",packageMismatch:o}}function At(t){const e=(0,W.productStorageRoot)(),n=l.default.join(e,"ota"),a=Rt(t),i={action:a,lane:null,verbose:!1,dryRun:!0,keepRecent:2,stagingMaxAgeMs:1440*60*1e3,intervalMs:1e3,timeoutMs:6e4,maxAttempts:60,productStorageRoot:e,statusPath:l.default.join(e,"cli-package","activation-status.json"),pointerPath:l.default.join(e,"cli-package","active-pointer.json"),extensionStatusPath:l.default.join(e,"extension","activation-status.json"),watchPath:l.default.join(n,"watch-status.json"),stopPath:l.default.join(n,"watch-stop.json"),activationLockPath:l.default.join(n,"activation.lock"),daemonIdentityPath:(0,R.cliDaemonIdentityPath)(e)},r=t[0]==="watch"&&t[1]==="stop"?2:1;for(let o=r;o<t.length;o+=1){const s=t[o],v=t[o+1];if(s==="--verbose"||s==="-v"){i.verbose=!0;continue}if(s==="--apply"){i.dryRun=!1;continue}if(s==="--dry-run"){i.dryRun=!0;continue}if(s==="--keep-recent"&&v){i.keepRecent=x(v,i.keepRecent,0,1e3),o+=1;continue}if(s==="--staging-max-age-ms"&&v){i.stagingMaxAgeMs=x(v,i.stagingMaxAgeMs,0,720*60*60*1e3),o+=1;continue}if(a==="status"&&s&&!s.startsWith("-")&&!i.lane){i.lane=s;continue}if(s==="--interval-ms"&&v){i.intervalMs=x(v,i.intervalMs,50,6e4),o+=1;continue}if(s==="--timeout-ms"&&v){i.timeoutMs=x(v,i.timeoutMs,1,1440*60*1e3),o+=1;continue}if(s==="--max-attempts"&&v){i.maxAttempts=x(v,i.maxAttempts,1,1e5),o+=1;continue}}return i}function Rt(t){const e=t[0]??"status";return e==="watch"&&t[1]==="stop"?"stop":e}function x(t,e,n,a){const i=Number.parseInt(t,10);return Number.isFinite(i)?Math.max(n,Math.min(a,i)):e}function m(t){try{const e=JSON.parse(d.default.readFileSync(t,"utf8"));return e&&e.schemaVersion===1?e:null}catch{return null}}function O(t,e){k(t,e)}function C(t){try{const e=JSON.parse(d.default.readFileSync(t,"utf8"));return e&&e.schemaVersion===1?e:null}catch{return null}}function G(t,e){k(t,e)}function b(t){try{const e=JSON.parse(d.default.readFileSync(t,"utf8"));return e&&e.schemaVersion===1?e:null}catch{return null}}function w(t){try{const e=JSON.parse(d.default.readFileSync(t,"utf8"));return h(e)}catch{return null}}function h(t){return t&&typeof t=="object"&&!Array.isArray(t)?t:null}function c(t){return typeof t=="string"&&t.trim()?t:null}function A(t){const e=w(l.default.join(t.productStorageRoot,"control-plane","policy-config.json"));return{killSwitches:Array.isArray(e?.killSwitches)?e.killSwitches.filter(a=>typeof a=="string"):[]}}function It(t){const e=w(l.default.join(t.productStorageRoot,"control-plane","manifest-cache.json"));return c(e?.channel)}function Mt(t,e){const n=F(t),a=F(e),i=Math.max(n.length,a.length);for(let r=0;r<i;r+=1){const o=n[r]??0,s=a[r]??0;if(o!==s)return o>s?1:-1}return t.localeCompare(e)}function F(t){return t.match(/\d+/g)?.map(e=>Number.parseInt(e,10)).filter(e=>Number.isFinite(e))??[]}function jt(t){return(0,J.createHash)("sha256").update(d.default.readFileSync(t)).digest("hex")}function f(t){return t===null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"?t:Array.isArray(t)?t.map(e=>f(e)):t&&typeof t=="object"?Object.fromEntries(Object.entries(t).map(([e,n])=>[e,f(n)])):null}function D(t,e){k(t.watchPath,e)}function k(t,e){d.default.mkdirSync(l.default.dirname(t),{recursive:!0});const n=`${t}.tmp-${process.pid}-${Date.now()}`;d.default.writeFileSync(n,`${JSON.stringify(e,null,2)}
2
+ `,"utf8"),d.default.renameSync(n,t)}function V(t){try{return process.kill(t,0),!0}catch{return!1}}function Ot(t){return!!t&&typeof t=="object"&&t.code==="EEXIST"}function Ct(t){return new Promise(e=>setTimeout(e,t))}
@@ -1,11 +1,11 @@
1
- "use strict";var R=exports&&exports.__createBinding||(Object.create?(function(e,n,r,t){t===void 0&&(t=r);var i=Object.getOwnPropertyDescriptor(n,r);(!i||("get"in i?!n.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return n[r]}}),Object.defineProperty(e,t,i)}):(function(e,n,r,t){t===void 0&&(t=r),e[t]=n[r]})),m=exports&&exports.__setModuleDefault||(Object.create?(function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}):function(e,n){e.default=n}),h=exports&&exports.__importStar||(function(){var e=function(n){return e=Object.getOwnPropertyNames||function(r){var t=[];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[t.length]=i);return t},e(n)};return function(n){if(n&&n.__esModule)return n;var r={};if(n!=null)for(var t=e(n),i=0;i<t.length;i++)t[i]!=="default"&&R(r,n,t[i]);return m(r,n),r}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.runQuickReadCommand=y;const p=h(require("node:fs/promises")),q=h(require("node:path")),_=require("../config/path-display"),F=require("../config/path-aliases"),N=require("../shared/agent-text"),f=require("../shared/errors"),A=require("./session-workspace"),v=80;async function y(e,n,r={}){const t=(0,A.readEffectiveSessionPathAliases)(e),i=(0,_.buildDisplayPathAliases)(e,t),s=n.includes("--stdin")?x(e,t,i,r.rawStdin??await U()):w(e,t,i,n),u=await O(I(s)),l={ok:u.some(o=>o.error===void 0),blocks:u.map(o=>({file:o.file,...o.window!==void 0?{window:o.window}:{},...o.content!==void 0?{content:o.content}:{},...o.error!==void 0?{error:o.error}:{}}))};return(0,N.attachAgentText)(l,W(u))}function I(e){const n=new Set(e.filter(i=>i.windows.some(s=>s.kind==="all")).map(i=>i.resolvedFile));if(n.size===0)return e;const r=new Set,t=[];for(const i of e){if(!n.has(i.resolvedFile)){t.push(i);continue}r.has(i.resolvedFile)||(r.add(i.resolvedFile),t.push({...i,windows:[{kind:"all"}]}))}return t}async function O(e){const n=new Map;for(const t of e)n.has(t.resolvedFile)||n.set(t.resolvedFile,$(t.resolvedFile));const r=[];for(const t of e){const i=await n.get(t.resolvedFile);if(i.error!==void 0||i.lines===void 0){r.push({file:t.displayFile,error:i.error??"read failed"});continue}for(const s of t.windows)r.push({file:t.displayFile,window:B(s),content:S(i.lines,s).join(`
2
- `)})}return r}async function $(e){let n;try{n=await p.stat(e)}catch(t){return{error:(typeof t=="object"&&t!==null&&"code"in t?String(t.code):"")==="ENOENT"?"file not found":"cannot stat file"}}if(n.isDirectory())return{error:"is a directory"};if(!n.isFile())return{error:"not a regular file"};let r;try{r=await p.readFile(e)}catch{return{error:"cannot read file"}}return Q(r)?{error:"binary file"}:{lines:C(r.toString("utf8"))}}function Q(e){const n=Math.min(e.length,8192);for(let r=0;r<n;r+=1)if(e[r]===0)return!0;return!1}function C(e){const n=e.replace(/\r\n/g,`
1
+ "use strict";var R=exports&&exports.__createBinding||(Object.create?(function(e,n,r,t){t===void 0&&(t=r);var i=Object.getOwnPropertyDescriptor(n,r);(!i||("get"in i?!n.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return n[r]}}),Object.defineProperty(e,t,i)}):(function(e,n,r,t){t===void 0&&(t=r),e[t]=n[r]})),m=exports&&exports.__setModuleDefault||(Object.create?(function(e,n){Object.defineProperty(e,"default",{enumerable:!0,value:n})}):function(e,n){e.default=n}),h=exports&&exports.__importStar||(function(){var e=function(n){return e=Object.getOwnPropertyNames||function(r){var t=[];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[t.length]=i);return t},e(n)};return function(n){if(n&&n.__esModule)return n;var r={};if(n!=null)for(var t=e(n),i=0;i<t.length;i++)t[i]!=="default"&&R(r,n,t[i]);return m(r,n),r}})();Object.defineProperty(exports,"__esModule",{value:!0}),exports.runQuickReadCommand=Q;const p=h(require("node:fs/promises")),q=h(require("node:path")),w=require("../config/path-display"),A=require("../config/path-aliases"),F=require("../shared/agent-text"),f=require("../shared/errors"),N=require("./session-workspace"),I=80;async function Q(e,n,r={}){const t=(0,N.readEffectiveSessionPathAliases)(e),i=(0,w.buildDisplayPathAliases)(e,t),s=n.includes("--stdin")?S(e,t,i,r.rawStdin??await V()):_(e,t,i,n),u=await y(v(s)),l={ok:u.some(o=>o.error===void 0),blocks:u.map(o=>({file:o.file,...o.window!==void 0?{window:o.window}:{},...o.content!==void 0?{content:o.content}:{},...o.error!==void 0?{error:o.error}:{}}))};return(0,F.attachAgentText)(l,W(u))}function v(e){const n=new Set(e.filter(i=>i.windows.some(s=>s.kind==="all")).map(i=>i.resolvedFile));if(n.size===0)return e;const r=new Set,t=[];for(const i of e){if(!n.has(i.resolvedFile)){t.push(i);continue}r.has(i.resolvedFile)||(r.add(i.resolvedFile),t.push({...i,windows:[{kind:"all"}]}))}return t}async function y(e){const n=new Map;for(const t of e)n.has(t.resolvedFile)||n.set(t.resolvedFile,O(t.resolvedFile));const r=[];for(const t of e){const i=await n.get(t.resolvedFile);if(i.error!==void 0||i.lines===void 0){r.push({file:t.displayFile,error:i.error??"read failed"});continue}for(const s of t.windows)r.push({file:t.displayFile,window:B(s),content:x(i.lines,s).join(`
2
+ `)})}return r}async function O(e){let n;try{n=await p.stat(e)}catch(t){return{error:(typeof t=="object"&&t!==null&&"code"in t?String(t.code):"")==="ENOENT"?"file not found":"cannot stat file"}}if(n.isDirectory())return{error:"is a directory"};if(!n.isFile())return{error:"not a regular file"};let r;try{r=await p.readFile(e)}catch{return{error:"cannot read file"}}return $(r)?{error:"binary file"}:{lines:C(r.toString("utf8"))}}function $(e){const n=Math.min(e.length,8192);for(let r=0;r<n;r+=1)if(e[r]===0)return!0;return!1}function C(e){const n=e.replace(/\r\n/g,`
3
3
  `).replace(/\r/g,`
4
4
  `);return n.endsWith(`
5
5
  `)?n.slice(0,-1).split(`
6
6
  `):n.split(`
7
- `)}function S(e,n){return n.kind==="all"?e:n.kind==="head"?e.slice(0,n.count):n.kind==="tail"?e.slice(Math.max(0,e.length-n.count)):e.slice(n.offset-1,n.offset-1+n.limit)}function x(e,n,r,t){const i=t.replace(/^\uFEFF/,"").split(/\r?\n/),s=[];for(let u=0;u<i.length;u+=1){const c=i[u]?.trim()??"";if(!c||c.startsWith("#"))continue;const l=L(c);if(l.length===0)continue;const o=l[0]==="qr"?l.slice(1):l;try{s.push(...w(e,n,r,o))}catch(a){throw a instanceof f.CliError?new f.CliError(a.code,`qr stdin line ${u+1}: ${a.message}`,a.details):a}}if(s.length===0)throw new f.CliError("QR_STDIN_EMPTY","qr --stdin expects at least one qr line.");return s}function w(e,n,r,t){const i=t.filter(a=>a!=="--stdin"),s=i[0]==="qr"?i.slice(1):i,u=s.findIndex(T),c=u===-1?s:s.slice(0,u),l=u===-1?[]:s.slice(u);if(c.length===0)throw new f.CliError("QR_FILE_REQUIRED","qr expects a file path.");const o=b(l);return c.map(a=>M(e,n,r,a,o))}function M(e,n,r,t,i){if(!t||t.startsWith("-")||E(t))throw new f.CliError("QR_FILE_REQUIRED","qr expects a file path before window flags.");const s=q.resolve(e,(0,F.expandPathAliasValue)(e,t,n));return{file:t,resolvedFile:s,displayFile:(0,_.compactDisplayPath)(e,s,r),windows:i}}function b(e){let n=!1,r=null,t=null,i=null,s=null;for(let l=0;l<e.length;l+=1){const o=e[l]??"",a=P(o);if(a){c(a.key,a.value);continue}if(o==="-a"||o==="--all"||o==="a"||o==="all"||o==="+all"){n=!0;continue}if(o==="-h"||o==="--head"){r=d(e,++l,o);continue}if(o==="-t"||o==="--tail"){t=d(e,++l,o);continue}if(o==="-o"||o==="--offset"){i=d(e,++l,o);continue}if(o==="-l"||o==="--limit"){s=d(e,++l,o);continue}throw new f.CliError("QR_UNKNOWN_ARGUMENT",`Unknown qr argument: ${o}`)}if(i===null!=(s===null))throw new f.CliError("QR_RANGE_INCOMPLETE","qr range reads require both o=<line> and l=<count>.");if(n)return[{kind:"all"}];const u=[];return r!==null&&u.push({kind:"head",count:r}),i!==null&&s!==null&&u.push({kind:"range",offset:i,limit:s}),t!==null&&u.push({kind:"tail",count:t}),u.length>0?u:[{kind:"head",count:v}];function c(l,o){if(l==="a"||l==="all"){n=D(o,l);return}const a=g(o,l);if(l==="h"||l==="head"){r=a;return}if(l==="t"||l==="tail"){t=a;return}if(l==="o"||l==="offset"){i=a;return}if(l==="l"||l==="limit"){s=a;return}throw new f.CliError("QR_UNKNOWN_ARGUMENT",`Unknown qr window field: ${l}`)}}function D(e,n){if(e==="true"||e==="1"||e==="yes")return!0;if(e==="false"||e==="0"||e==="no")return!1;throw new f.CliError("QR_INVALID_BOOLEAN",`${n} expects true or false.`)}function P(e){const n=e.indexOf("=");return n<=0?null:{key:e.slice(0,n),value:e.slice(n+1)}}function d(e,n,r){const t=e[n];if(!t||t.startsWith("-"))throw new f.CliError("QR_MISSING_FLAG_VALUE",`Expected a positive integer after ${r}.`);return g(t,r)}function g(e,n){const r=Number(e);if(!Number.isInteger(r)||r<1)throw new f.CliError("QR_INVALID_NUMBER",`${n} expects a positive integer.`);return r}function E(e){return/^(?:h|head|t|tail|o|offset|l|limit|a|all)=/.test(e)||e==="+all"}function T(e){return e.startsWith("-")||E(e)||e==="a"||e==="all"}function W(e){return e.map(n=>{if(n.error!==void 0)return`// ${n.file} - ${n.error}`;const r=`// ${n.file}${n.window?` ${n.window}`:""}`;return n.content?`${r}
7
+ `)}function x(e,n){return n.kind==="all"?e:n.kind==="head"?e.slice(0,n.count):n.kind==="tail"?e.slice(Math.max(0,e.length-n.count)):e.slice(n.offset-1,n.offset-1+n.limit)}function S(e,n,r,t){const i=t.replace(/^\uFEFF/,"").split(/\r?\n/),s=[];for(let u=0;u<i.length;u+=1){const c=i[u]?.trim()??"";if(!c||c.startsWith("#"))continue;const l=j(c);if(l.length===0)continue;const o=l[0]==="qr"?l.slice(1):l;try{s.push(..._(e,n,r,o))}catch(a){throw a instanceof f.CliError?new f.CliError(a.code,`qr stdin line ${u+1}: ${a.message}`,a.details):a}}if(s.length===0)throw new f.CliError("QR_STDIN_EMPTY","qr --stdin expects at least one qr line.");return s}function _(e,n,r,t){const i=t.filter(c=>c!=="--stdin"),s=i[0]==="qr"?i.slice(1):i,u=b(s);if(u.length===0)throw new f.CliError("QR_FILE_REQUIRED","qr expects a file path.");return u.map(c=>D(e,n,r,c.file,M(c.windowArgs)))}function b(e){const n=[];for(let r=0;r<e.length;r+=1){const t=e[r]??"";if(T(t)){if(n.length===0)throw new f.CliError("QR_FILE_REQUIRED","qr expects a file path before window flags.");n[n.length-1].windowArgs.push(t),U(t)&&(r+=1,n[n.length-1].windowArgs.push(e[r]??""));continue}n.push({file:t,windowArgs:[]})}return n}function D(e,n,r,t,i){if(!t||t.startsWith("-")||E(t))throw new f.CliError("QR_FILE_REQUIRED","qr expects a file path before window flags.");const s=q.resolve(e,(0,A.expandPathAliasValue)(e,t,n));return{file:t,resolvedFile:s,displayFile:(0,w.compactDisplayPath)(e,s,r),windows:i}}function M(e){let n=!1,r=null,t=null,i=null,s=null;for(let l=0;l<e.length;l+=1){const o=e[l]??"",a=P(o);if(a){c(a.key,a.value);continue}if(o==="-a"||o==="--all"||o==="a"||o==="all"||o==="+all"){n=!0;continue}if(o==="-h"||o==="--head"){r=d(e,++l,o);continue}if(o==="-t"||o==="--tail"){t=d(e,++l,o);continue}if(o==="-o"||o==="--offset"){i=d(e,++l,o);continue}if(o==="-l"||o==="--limit"){s=d(e,++l,o);continue}throw new f.CliError("QR_UNKNOWN_ARGUMENT",`Unknown qr argument: ${o}`)}if(i===null&&s!==null&&(r=s,s=null),i===null!=(s===null))throw new f.CliError("QR_RANGE_INCOMPLETE","qr range reads require both o=<line> and l=<count>.");if(n)return[{kind:"all"}];const u=[];return r!==null&&u.push({kind:"head",count:r}),i!==null&&s!==null&&u.push({kind:"range",offset:i,limit:s}),t!==null&&u.push({kind:"tail",count:t}),u.length>0?u:[{kind:"head",count:I}];function c(l,o){if(l==="a"||l==="all"){n=L(o,l);return}const a=g(o,l);if(l==="h"||l==="head"){r=a;return}if(l==="t"||l==="tail"){t=a;return}if(l==="o"||l==="offset"){i=a;return}if(l==="l"||l==="limit"){s=a;return}throw new f.CliError("QR_UNKNOWN_ARGUMENT",`Unknown qr window field: ${l}`)}}function L(e,n){if(e==="true"||e==="1"||e==="yes")return!0;if(e==="false"||e==="0"||e==="no")return!1;throw new f.CliError("QR_INVALID_BOOLEAN",`${n} expects true or false.`)}function P(e){const n=e.indexOf("=");return n<=0?null:{key:e.slice(0,n),value:e.slice(n+1)}}function d(e,n,r){const t=e[n];if(!t||t.startsWith("-"))throw new f.CliError("QR_MISSING_FLAG_VALUE",`Expected a positive integer after ${r}.`);return g(t,r)}function g(e,n){const r=Number(e);if(!Number.isInteger(r)||r<1)throw new f.CliError("QR_INVALID_NUMBER",`${n} expects a positive integer.`);return r}function E(e){return/^(?:h|head|t|tail|o|offset|l|limit|a|all)=/.test(e)||e==="+all"}function T(e){return e.startsWith("-")||E(e)||e==="a"||e==="all"}function U(e){return["-h","--head","-t","--tail","-o","--offset","-l","--limit"].includes(e)}function W(e){return e.map(n=>{if(n.error!==void 0)return`// ${n.file} - ${n.error}`;const r=`// ${n.file}${n.window?` ${n.window}`:""}`;return n.content?`${r}
8
8
  ${n.content}`:`${r}
9
9
  `}).join(`
10
10
 
11
- `)}function B(e){return e.kind==="all"?"all":e.kind==="head"?`h=${e.count}`:e.kind==="tail"?`t=${e.count}`:`o=${e.offset} l=${e.limit}`}function L(e){const n=[];let r="",t=null;for(let i=0;i<e.length;i+=1){const s=e[i]??"";if(t){s===t?t=null:r+=s;continue}if(s==='"'||s==="'"){t=s;continue}if(/\s/.test(s)){r.length>0&&(n.push(r),r="");continue}r+=s}if(t)throw new f.CliError("QR_UNTERMINATED_QUOTE","qr input has an unterminated quote.");return r.length>0&&n.push(r),n}async function U(){const e=[];for await(const n of process.stdin)e.push(Buffer.isBuffer(n)?n:Buffer.from(String(n)));return Buffer.concat(e).toString("utf8")}
11
+ `)}function B(e){return e.kind==="all"?"all":e.kind==="head"?`h=${e.count}`:e.kind==="tail"?`t=${e.count}`:`o=${e.offset} l=${e.limit}`}function j(e){const n=[];let r="",t=null;for(let i=0;i<e.length;i+=1){const s=e[i]??"";if(t){s===t?t=null:r+=s;continue}if(s==='"'||s==="'"){t=s;continue}if(/\s/.test(s)){r.length>0&&(n.push(r),r="");continue}r+=s}if(t)throw new f.CliError("QR_UNTERMINATED_QUOTE","qr input has an unterminated quote.");return r.length>0&&n.push(r),n}async function V(){const e=[];for await(const n of process.stdin)e.push(Buffer.isBuffer(n)?n:Buffer.from(String(n)));return Buffer.concat(e).toString("utf8")}