@bastani/atomic 0.9.17-alpha.1 → 0.9.18-alpha.1

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 (311) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +8 -0
  3. package/dist/builtin/intercom/index.bundle.mjs +349 -57517
  4. package/dist/builtin/intercom/package.json +1 -1
  5. package/dist/builtin/mcp/index.bundle.mjs +28948 -58339
  6. package/dist/builtin/mcp/package.json +1 -1
  7. package/dist/builtin/mcp/xdg-open +1267 -0
  8. package/dist/builtin/subagents/package.json +1 -1
  9. package/dist/builtin/subagents/src/extension/index.bundle.mjs +7929 -78021
  10. package/dist/builtin/web-access/index.bundle.mjs +70791 -57707
  11. package/dist/builtin/web-access/package.json +1 -1
  12. package/dist/builtin/workflows/builtin/adversarial-verification.js +0 -1
  13. package/dist/builtin/workflows/builtin/{chunk-3y1hmzw6.js → chunk-6v0yv8tj.js} +1 -1
  14. package/dist/builtin/workflows/builtin/{chunk-w9c7rkrk.js → chunk-brerg33r.js} +5 -7
  15. package/dist/builtin/workflows/builtin/{chunk-bz1c9732.js → chunk-ngffz3y8.js} +1 -1
  16. package/dist/builtin/workflows/builtin/{chunk-6rbajjf5.js → chunk-szz1ajz9.js} +1 -3
  17. package/dist/builtin/workflows/builtin/classify-and-act.js +0 -1
  18. package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +0 -1
  19. package/dist/builtin/workflows/builtin/generate-and-filter.js +0 -1
  20. package/dist/builtin/workflows/builtin/goal.js +2 -5
  21. package/dist/builtin/workflows/builtin/index.js +4 -7
  22. package/dist/builtin/workflows/builtin/loop-until-done.js +0 -1
  23. package/dist/builtin/workflows/builtin/open-claude-design.js +1 -4
  24. package/dist/builtin/workflows/builtin/ralph.js +2 -5
  25. package/dist/builtin/workflows/builtin/steering-context.js +0 -1
  26. package/dist/builtin/workflows/builtin/tournament.js +0 -1
  27. package/dist/builtin/workflows/package.json +1 -1
  28. package/dist/builtin/workflows/src/extension/index.bundle.mjs +39989 -81500
  29. package/dist/builtin/workflows/src/index.js +1253 -58524
  30. package/dist/bun/cli.js.map +1 -1
  31. package/dist/bun/split-loader.js +2 -0
  32. package/dist/bun/split-loader.js.map +1 -1
  33. package/dist/cli/args.js.map +1 -1
  34. package/dist/cli/auth-command.js.map +1 -1
  35. package/dist/cli/session-picker.js.map +1 -1
  36. package/dist/cli/startup-ui.js.map +1 -1
  37. package/dist/cli.js +5 -2
  38. package/dist/cli.js.map +1 -1
  39. package/dist/core/agent-session-extension-bindings.d.ts +19 -2
  40. package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
  41. package/dist/core/agent-session-extension-bindings.js +253 -74
  42. package/dist/core/agent-session-extension-bindings.js.map +1 -1
  43. package/dist/core/agent-session-methods.d.ts +8 -3
  44. package/dist/core/agent-session-methods.d.ts.map +1 -1
  45. package/dist/core/agent-session-methods.js.map +1 -1
  46. package/dist/core/agent-session-prompt.d.ts +2 -7
  47. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  48. package/dist/core/agent-session-prompt.js +1 -35
  49. package/dist/core/agent-session-prompt.js.map +1 -1
  50. package/dist/core/agent-session-services.d.ts.map +1 -1
  51. package/dist/core/agent-session-services.js +2 -0
  52. package/dist/core/agent-session-services.js.map +1 -1
  53. package/dist/core/agent-session-types.d.ts +2 -0
  54. package/dist/core/agent-session-types.d.ts.map +1 -1
  55. package/dist/core/agent-session-types.js.map +1 -1
  56. package/dist/core/agent-session.d.ts +1 -0
  57. package/dist/core/agent-session.d.ts.map +1 -1
  58. package/dist/core/agent-session.js +2 -0
  59. package/dist/core/agent-session.js.map +1 -1
  60. package/dist/core/auth-guidance.js.map +1 -1
  61. package/dist/core/auth-storage-backends.js.map +1 -1
  62. package/dist/core/auth-storage.js.map +1 -1
  63. package/dist/core/bash-executor.js.map +1 -1
  64. package/dist/core/builtin-packages.d.ts +8 -0
  65. package/dist/core/builtin-packages.d.ts.map +1 -1
  66. package/dist/core/builtin-packages.js +11 -5
  67. package/dist/core/builtin-packages.js.map +1 -1
  68. package/dist/core/event-bus.d.ts +11 -0
  69. package/dist/core/event-bus.d.ts.map +1 -1
  70. package/dist/core/event-bus.js +96 -0
  71. package/dist/core/event-bus.js.map +1 -1
  72. package/dist/core/experimental.js.map +1 -1
  73. package/dist/core/export-html/index.js.map +1 -1
  74. package/dist/core/extensions/builtin-extension-entry-labels.d.ts +6 -0
  75. package/dist/core/extensions/builtin-extension-entry-labels.d.ts.map +1 -0
  76. package/dist/core/extensions/builtin-extension-entry-labels.js +22 -0
  77. package/dist/core/extensions/builtin-extension-entry-labels.js.map +1 -0
  78. package/dist/core/extensions/host-module-bridge.d.ts +22 -0
  79. package/dist/core/extensions/host-module-bridge.d.ts.map +1 -0
  80. package/dist/core/extensions/host-module-bridge.js +39 -0
  81. package/dist/core/extensions/host-module-bridge.js.map +1 -0
  82. package/dist/core/extensions/loader-api.d.ts.map +1 -1
  83. package/dist/core/extensions/loader-api.js +2 -2
  84. package/dist/core/extensions/loader-api.js.map +1 -1
  85. package/dist/core/extensions/loader-core.js.map +1 -1
  86. package/dist/core/extensions/loader-discovery.js.map +1 -1
  87. package/dist/core/extensions/loader-host-modules.d.ts +10 -0
  88. package/dist/core/extensions/loader-host-modules.d.ts.map +1 -0
  89. package/dist/core/extensions/loader-host-modules.js +88 -0
  90. package/dist/core/extensions/loader-host-modules.js.map +1 -0
  91. package/dist/core/extensions/loader-runtime.d.ts.map +1 -1
  92. package/dist/core/extensions/loader-runtime.js +1 -0
  93. package/dist/core/extensions/loader-runtime.js.map +1 -1
  94. package/dist/core/extensions/loader-virtual-modules.d.ts +5 -2
  95. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  96. package/dist/core/extensions/loader-virtual-modules.js +51 -71
  97. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  98. package/dist/core/extensions/loader.d.ts +1 -1
  99. package/dist/core/extensions/loader.js.map +1 -1
  100. package/dist/core/extensions/native-builtin-entries.d.ts +6 -0
  101. package/dist/core/extensions/native-builtin-entries.d.ts.map +1 -0
  102. package/dist/core/extensions/native-builtin-entries.js +23 -0
  103. package/dist/core/extensions/native-builtin-entries.js.map +1 -0
  104. package/dist/core/extensions/runtime-types.d.ts +2 -0
  105. package/dist/core/extensions/runtime-types.d.ts.map +1 -1
  106. package/dist/core/extensions/runtime-types.js.map +1 -1
  107. package/dist/core/keybindings.js.map +1 -1
  108. package/dist/core/lifecycle-timings.d.ts +21 -0
  109. package/dist/core/lifecycle-timings.d.ts.map +1 -0
  110. package/dist/core/lifecycle-timings.js +57 -0
  111. package/dist/core/lifecycle-timings.js.map +1 -0
  112. package/dist/core/mandatory-resource-loader.d.ts.map +1 -1
  113. package/dist/core/mandatory-resource-loader.js +43 -0
  114. package/dist/core/mandatory-resource-loader.js.map +1 -1
  115. package/dist/core/model-runtime.d.ts +8 -0
  116. package/dist/core/model-runtime.d.ts.map +1 -1
  117. package/dist/core/model-runtime.js +82 -0
  118. package/dist/core/model-runtime.js.map +1 -1
  119. package/dist/core/models-store.js.map +1 -1
  120. package/dist/core/package-manager-auto-resources.js.map +1 -1
  121. package/dist/core/package-manager-env.js.map +1 -1
  122. package/dist/core/package-manager-git.js.map +1 -1
  123. package/dist/core/package-manager-manifest.js.map +1 -1
  124. package/dist/core/package-manager-npm.js.map +1 -1
  125. package/dist/core/package-manager-paths.js.map +1 -1
  126. package/dist/core/package-manager-resolver.js.map +1 -1
  127. package/dist/core/project-trust.js.map +1 -1
  128. package/dist/core/prompt-templates-async.js.map +1 -1
  129. package/dist/core/prompt-templates.js.map +1 -1
  130. package/dist/core/provider-attribution.js.map +1 -1
  131. package/dist/core/remote-catalog-provider.js.map +1 -1
  132. package/dist/core/resource-loader-assets.js.map +1 -1
  133. package/dist/core/resource-loader-context-files.js.map +1 -1
  134. package/dist/core/resource-loader-core.d.ts +5 -1
  135. package/dist/core/resource-loader-core.d.ts.map +1 -1
  136. package/dist/core/resource-loader-core.js +90 -1
  137. package/dist/core/resource-loader-core.js.map +1 -1
  138. package/dist/core/resource-loader-discovery.js.map +1 -1
  139. package/dist/core/resource-loader-paths.js.map +1 -1
  140. package/dist/core/resource-loader-source-info.js.map +1 -1
  141. package/dist/core/resource-loader-types.d.ts +16 -0
  142. package/dist/core/resource-loader-types.d.ts.map +1 -1
  143. package/dist/core/resource-loader-types.js.map +1 -1
  144. package/dist/core/sdk.d.ts.map +1 -1
  145. package/dist/core/sdk.js +4 -1
  146. package/dist/core/sdk.js.map +1 -1
  147. package/dist/core/session-manager-core.js.map +1 -1
  148. package/dist/core/session-manager-list.js.map +1 -1
  149. package/dist/core/session-manager-paths.js.map +1 -1
  150. package/dist/core/settings-manager-core.d.ts +6 -0
  151. package/dist/core/settings-manager-core.d.ts.map +1 -1
  152. package/dist/core/settings-manager-core.js +24 -0
  153. package/dist/core/settings-manager-core.js.map +1 -1
  154. package/dist/core/settings-manager-ui-accessors.js.map +1 -1
  155. package/dist/core/settings-storage.js.map +1 -1
  156. package/dist/core/skills-async.js.map +1 -1
  157. package/dist/core/skills.js.map +1 -1
  158. package/dist/core/slash-commands.d.ts.map +1 -1
  159. package/dist/core/slash-commands.js +0 -6
  160. package/dist/core/slash-commands.js.map +1 -1
  161. package/dist/core/system-prompt.js.map +1 -1
  162. package/dist/core/telemetry.js.map +1 -1
  163. package/dist/core/timings.js.map +1 -1
  164. package/dist/core/tools/bash.js.map +1 -1
  165. package/dist/core/tools/output-accumulator.js.map +1 -1
  166. package/dist/core/tools/powershell.js.map +1 -1
  167. package/dist/core/tools/read.js.map +1 -1
  168. package/dist/core/tools/session-temp-cleanup.js.map +1 -1
  169. package/dist/core/tools/session-temp-dir.js.map +1 -1
  170. package/dist/core/tools/todos-paths.js.map +1 -1
  171. package/dist/core/trust-manager.js.map +1 -1
  172. package/dist/index.d.ts +1 -1
  173. package/dist/index.js.map +1 -1
  174. package/dist/main-deferred-startup.d.ts +16 -0
  175. package/dist/main-deferred-startup.d.ts.map +1 -1
  176. package/dist/main-deferred-startup.js +14 -0
  177. package/dist/main-deferred-startup.js.map +1 -1
  178. package/dist/main-session.js.map +1 -1
  179. package/dist/main.d.ts.map +1 -1
  180. package/dist/main.js +41 -22
  181. package/dist/main.js.map +1 -1
  182. package/dist/migrations.js.map +1 -1
  183. package/dist/modes/interactive/chat-input-actions.js.map +1 -1
  184. package/dist/modes/interactive/components/config-selector-list.js.map +1 -1
  185. package/dist/modes/interactive/components/config-selector-project-scope.js.map +1 -1
  186. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  187. package/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
  188. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  189. package/dist/modes/interactive/components/startup-identity.d.ts.map +1 -1
  190. package/dist/modes/interactive/components/startup-identity.js +4 -0
  191. package/dist/modes/interactive/components/startup-identity.js.map +1 -1
  192. package/dist/modes/interactive/external-editor.js.map +1 -1
  193. package/dist/modes/interactive/interactive-editor-actions.js +13 -5
  194. package/dist/modes/interactive/interactive-editor-actions.js.map +1 -1
  195. package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
  196. package/dist/modes/interactive/interactive-input-handling.js +2 -5
  197. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  198. package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
  199. package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
  200. package/dist/modes/interactive/interactive-mode-surface.d.ts +8 -8
  201. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  202. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  203. package/dist/modes/interactive/interactive-onboarding.js +1 -1
  204. package/dist/modes/interactive/interactive-onboarding.js.map +1 -1
  205. package/dist/modes/interactive/interactive-prompt-restore.d.ts.map +1 -1
  206. package/dist/modes/interactive/interactive-prompt-restore.js +2 -1
  207. package/dist/modes/interactive/interactive-prompt-restore.js.map +1 -1
  208. package/dist/modes/interactive/interactive-prompt-turn.js.map +1 -1
  209. package/dist/modes/interactive/interactive-render-chat.js +2 -0
  210. package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
  211. package/dist/modes/interactive/interactive-resource-disclosure.js +21 -53
  212. package/dist/modes/interactive/interactive-resource-disclosure.js.map +1 -1
  213. package/dist/modes/interactive/interactive-resource-paths.js +29 -5
  214. package/dist/modes/interactive/interactive-resource-paths.js.map +1 -1
  215. package/dist/modes/interactive/interactive-resource-rendering.js +66 -69
  216. package/dist/modes/interactive/interactive-resource-rendering.js.map +1 -1
  217. package/dist/modes/interactive/interactive-startup-chat-container.d.ts.map +1 -1
  218. package/dist/modes/interactive/interactive-startup-chat-container.js +2 -0
  219. package/dist/modes/interactive/interactive-startup-chat-container.js.map +1 -1
  220. package/dist/modes/interactive/interactive-startup.d.ts +2 -0
  221. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  222. package/dist/modes/interactive/interactive-startup.js +30 -10
  223. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  224. package/dist/modes/interactive/interactive-tui.d.ts.map +1 -1
  225. package/dist/modes/interactive/interactive-tui.js +12 -2
  226. package/dist/modes/interactive/interactive-tui.js.map +1 -1
  227. package/dist/modes/interactive/theme/global-theme.js.map +1 -1
  228. package/dist/modes/interactive/theme/theme-loading.js.map +1 -1
  229. package/dist/modes/interactive-engine/create-isolated-runtime.js.map +1 -1
  230. package/dist/modes/interactive-engine/engine-child-liveness.d.ts +2 -0
  231. package/dist/modes/interactive-engine/engine-child-liveness.d.ts.map +1 -1
  232. package/dist/modes/interactive-engine/engine-child-liveness.js +16 -2
  233. package/dist/modes/interactive-engine/engine-child-liveness.js.map +1 -1
  234. package/dist/modes/interactive-engine/engine-custom-ui.js.map +1 -1
  235. package/dist/modes/interactive-engine/engine-monitor.d.ts +5 -0
  236. package/dist/modes/interactive-engine/engine-monitor.d.ts.map +1 -1
  237. package/dist/modes/interactive-engine/engine-monitor.js +24 -0
  238. package/dist/modes/interactive-engine/engine-monitor.js.map +1 -1
  239. package/dist/modes/interactive-engine/engine-render-service.js.map +1 -1
  240. package/dist/modes/interactive-engine/extension-ui-bridge.d.ts +3 -1
  241. package/dist/modes/interactive-engine/extension-ui-bridge.d.ts.map +1 -1
  242. package/dist/modes/interactive-engine/extension-ui-bridge.js +6 -0
  243. package/dist/modes/interactive-engine/extension-ui-bridge.js.map +1 -1
  244. package/dist/modes/interactive-engine/isolated-runtime.d.ts +21 -2
  245. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  246. package/dist/modes/interactive-engine/isolated-runtime.js +160 -7
  247. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  248. package/dist/modes/interactive-engine/protocol.d.ts +9 -4
  249. package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
  250. package/dist/modes/interactive-engine/protocol.js +8 -4
  251. package/dist/modes/interactive-engine/protocol.js.map +1 -1
  252. package/dist/modes/interactive-engine/resource-readiness-error.d.ts +6 -0
  253. package/dist/modes/interactive-engine/resource-readiness-error.d.ts.map +1 -0
  254. package/dist/modes/interactive-engine/resource-readiness-error.js +11 -0
  255. package/dist/modes/interactive-engine/resource-readiness-error.js.map +1 -0
  256. package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
  257. package/dist/modes/rpc/rpc-client-process.js +3 -0
  258. package/dist/modes/rpc/rpc-client-process.js.map +1 -1
  259. package/dist/modes/rpc/rpc-client.d.ts +1 -0
  260. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  261. package/dist/modes/rpc/rpc-client.js +5 -1
  262. package/dist/modes/rpc/rpc-client.js.map +1 -1
  263. package/dist/modes/rpc/rpc-command-handler.d.ts +4 -1
  264. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  265. package/dist/modes/rpc/rpc-command-handler.js +59 -18
  266. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  267. package/dist/modes/rpc/rpc-mode.d.ts +4 -13
  268. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  269. package/dist/modes/rpc/rpc-mode.js +31 -2
  270. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  271. package/dist/modes/rpc/rpc-resource-readiness.d.ts +11 -0
  272. package/dist/modes/rpc/rpc-resource-readiness.d.ts.map +1 -0
  273. package/dist/modes/rpc/rpc-resource-readiness.js +51 -0
  274. package/dist/modes/rpc/rpc-resource-readiness.js.map +1 -0
  275. package/dist/modes/rpc/rpc-session-binding.d.ts +2 -0
  276. package/dist/modes/rpc/rpc-session-binding.d.ts.map +1 -1
  277. package/dist/modes/rpc/rpc-session-binding.js +21 -0
  278. package/dist/modes/rpc/rpc-session-binding.js.map +1 -1
  279. package/dist/modes/rpc/rpc-types.d.ts +7 -0
  280. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  281. package/dist/modes/rpc/rpc-types.js.map +1 -1
  282. package/dist/package-manager-cli-parser.js.map +1 -1
  283. package/dist/package-manager-cli.js.map +1 -1
  284. package/dist/rpc-entry.js.map +1 -1
  285. package/dist/self-update-plan.js.map +1 -1
  286. package/dist/utils/changelog.d.ts +1 -1
  287. package/dist/utils/changelog.js.map +1 -1
  288. package/dist/utils/module-require.js.map +1 -1
  289. package/dist/utils/pi-user-agent.js.map +1 -1
  290. package/dist/utils/shell.js.map +1 -1
  291. package/dist/utils/tools-manager.js.map +1 -1
  292. package/dist/utils/version-check.js.map +1 -1
  293. package/dist/utils/windows-self-update.js.map +1 -1
  294. package/docs/development.md +28 -1
  295. package/docs/extensions.md +5 -3
  296. package/docs/quickstart.md +1 -3
  297. package/docs/sdk.md +2 -0
  298. package/docs/usage.md +3 -1
  299. package/docs/windows.md +8 -0
  300. package/npm-shrinkwrap.json +32 -32
  301. package/package.json +4 -4
  302. package/dist/builtin/workflows/builtin/chunk-4febxsv4.js +0 -264
  303. package/dist/builtin/workflows/builtin/chunk-5wgwscd0.js +0 -4
  304. package/dist/builtin/workflows/builtin/chunk-dattsgxg.js +0 -529
  305. package/dist/builtin/workflows/builtin/chunk-gdx0avpx.js +0 -70082
  306. package/dist/builtin/workflows/builtin/chunk-qx2ptjs3.js +0 -215
  307. package/dist/builtin/workflows/builtin/chunk-x2ghn0je.js +0 -4110
  308. package/dist/core/atomic-guide-command.d.ts +0 -41
  309. package/dist/core/atomic-guide-command.d.ts.map +0 -1
  310. package/dist/core/atomic-guide-command.js +0 -311
  311. package/dist/core/atomic-guide-command.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"session-temp-dir.js","sourceRoot":"","sources":["../../../src/core/tools/session-temp-dir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAc,MAAM,SAAS,CAAC;AAC5F,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EACN,4CAA4C,EAC5C,8BAA8B,GAC9B,MAAM,iCAAiC,CAAC;AAEzC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAE3C,8DAA8D;AAC9D,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAE5C,0EAA0E;AAC1E,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC,MAAM,0BAA0B,GAAG,SAAS,CAAC;AAC7C,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAExC;;;;;;;;GAQG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAAa,EAAE,QAAgB;IACxE,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,mBAAmB,EAAE,GAAG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GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACzE,CAAC;IACD,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,OAAO;QACN,OAAO;YACN,IAAI,QAAQ,EAAE,CAAC;gBACd,OAAO;YACR,CAAC;YACD,QAAQ,GAAG,IAAI,CAAC;YAChB,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;gBAC5B,MAAM,SAAS,GAAG,CAAC,mBAAmB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;gBAC3D,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;oBACnB,mBAAmB,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;gBAC1C,CAAC;qBAAM,CAAC;oBACP,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBAClC,CAAC;YACF,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,SAAiB;IACvD,eAAe,GAAG,SAAS,CAAC;IAC5B,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC;AAC7C,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,2BAA2B;IAC1C,OAAO,IAAI,GAAG,CAAC,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC;AAC5C,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,kCAAkC;IACjD,eAAe,GAAG,SAAS,CAAC;IAC5B,mBAAmB,CAAC,KAAK,EAAE,CAAC;IAC5B,WAAW,CAAC,KAAK,EAAE,CAAC;IACpB,oBAAoB,GAAG,SAAS,CAAC;IACjC,kBAAkB,GAAG,SAAS,CAAC;IAC/B,4CAA4C,EAAE,CAAC;AAChD,CAAC","sourcesContent":["/**\n * Owner- and session-scoped temp storage for tool output files.\n *\n * Every file a tool spills to the system temp directory (bash overflow logs,\n * `OutputAccumulator` spill files, and the in-memory-session tool-result fallback)\n * lands under:\n *\n * ```text\n * <tmpdir>/<APP_NAME>-<owner>/<sanitized-session-id>/\n * ```\n *\n * The owner segment mirrors the upstream Claude Code `claude-{uid}` convention\n * (mehmoodosman/claude-code): a shared multi-user temp directory must never let\n * one account write into (or read) another account's tree. The session segment\n * makes the tree reapable as a unit by the age-based sweeper in\n * `session-temp-cleanup.ts` once the session is long gone.\n */\n\nimport { createHash } from \"node:crypto\";\nimport { chmodSync, lstatSync, mkdirSync, realpathSync, rmSync, type Stats } from \"node:fs\";\nimport { tmpdir, userInfo } from \"node:os\";\nimport { dirname, join, sep } from \"node:path\";\nimport { APP_NAME } from \"../../config.ts\";\nimport { getErrnoCode } from \"./errno.ts\";\nimport {\n\tresetWindowsDirectorySecurityStateForTesting,\n\tverifyWindowsDirectorySecurity,\n} from \"./windows-directory-security.ts\";\n\n/** Directory mode for every directory this module creates (owner-only). */\nexport const SESSION_TEMP_DIR_MODE = 0o700;\n\n/** File mode for persisted tool-output files (owner-only). */\nexport const SESSION_TEMP_FILE_MODE = 0o600;\n\n/** Longest path component this module will emit for a sanitized value. */\nconst MAX_PATH_COMPONENT_LENGTH = 64;\n\nconst FALLBACK_SESSION_COMPONENT = \"session\";\nconst FALLBACK_OWNER_COMPONENT = \"user\";\n\n/**\n * Reduce a value to a single safe path component.\n *\n * Disallowed characters collapse to `_`; leading `.`/`_` and trailing `.`/`_`\n * are stripped so the result can never be `.`, `..`, a hidden sweeper marker\n * file name, or anything that escapes the parent directory. Trimming uses a\n * linear scan rather than a `/^[._]+|[._]+$/` regex to avoid polynomial-time\n * backtracking on adversarial ids (CodeQL js/polynomial-redos).\n */\nexport function sanitizeTempPathComponent(value: string, fallback: string): string {\n\tconst collapsed = value.replace(/[^a-zA-Z0-9._-]+/g, \"_\");\n\tlet start = 0;\n\tlet end = collapsed.length;\n\twhile (start < end && (collapsed[start] === \"_\" || collapsed[start] === \".\")) {\n\t\tstart++;\n\t}\n\twhile (end > start && (collapsed[end - 1] === \"_\" || collapsed[end - 1] === \".\")) {\n\t\tend--;\n\t}\n\tconst sanitized = collapsed.slice(start, end).slice(0, MAX_PATH_COMPONENT_LENGTH);\n\treturn sanitized.length > 0 ? sanitized : fallback;\n}\n\nlet cachedOwnerComponent: string | undefined;\n\n/**\n * Derive the owner component for a named (non-uid) account.\n *\n * Sanitizing a name to a safe path component is lossy, and two distinct\n * accounts can reduce to the same component (`aliceé` and `aliceø` both yield\n * `alice_`). Where the system temp directory is machine-wide and\n * shared-accessible, that would put two accounts in one tree. Appending a short\n * digest of the raw identity keeps distinct accounts on distinct roots, with\n * the readable component in front so the directory stays recognizable.\n *\n * This prevents collision; it is not owner verification. Ownership is proven\n * separately by `verifyOwnedDirectory` — a uid check on POSIX, an owner-SID\n * and DACL check on Windows.\n *\n * Exported as a pure function so the collision property can be tested directly:\n * its only caller reaches this branch on Windows, which a POSIX test host\n * cannot enter.\n */\nexport function deriveOwnerComponent(rawIdentity: string): string {\n\t// Windows account names are case-insensitive, so `Alice` and `alice` are one\n\t// account and must resolve to one root. Normalize before both the readable\n\t// component and the digest: normalizing only the digest would still emit two\n\t// spellings of one directory, which NTFS then treats as the same path while\n\t// the sweeper's bookkeeping sees two.\n\tconst normalized = rawIdentity.toLowerCase();\n\tconst readable = sanitizeTempPathComponent(normalized, FALLBACK_OWNER_COMPONENT);\n\tconst digest = createHash(\"sha256\").update(normalized).digest(\"hex\").slice(0, 8);\n\treturn `${readable}-${digest}`;\n}\n\n/**\n * Assemble the account identity used where there is no uid.\n *\n * `userInfo().username` returns the bare account name, so `CONTOSO\\Alice` and\n * `FABRIKAM\\Alice` would otherwise be one identity and share a tree. Exported\n * for tests: its caller only reaches this branch on Windows.\n */\nexport function windowsPrincipal(name: string | undefined): string {\n\tconst account = name || process.env.USERNAME || process.env.USER || \"\";\n\t// USERDOMAIN is the NetBIOS domain and is set for both domain and local\n\t// accounts; USERDNSDOMAIN appears only on domain-joined hosts and\n\t// distinguishes two forests that share a NetBIOS name. Neither is\n\t// authoritative on its own, so both take part in the identity.\n\tconst domain = process.env.USERDNSDOMAIN || process.env.USERDOMAIN || \"\";\n\treturn domain ? `${domain}\\\\${account}` : account;\n}\n\n/**\n * Identify the account that owns the temp tree.\n *\n * POSIX uses the numeric uid, which is already collision-free. Windows has no\n * `process.getuid`, so the domain-qualified principal stands in.\n */\nfunction ownerComponent(): string {\n\tif (cachedOwnerComponent !== undefined) {\n\t\treturn cachedOwnerComponent;\n\t}\n\tconst uid = typeof process.getuid === \"function\" ? process.getuid() : undefined;\n\tif (typeof uid === \"number\" && Number.isFinite(uid)) {\n\t\tcachedOwnerComponent = String(uid);\n\t\treturn cachedOwnerComponent;\n\t}\n\tlet name: string | undefined;\n\ttry {\n\t\tname = userInfo().username;\n\t} catch {\n\t\t// A container without a passwd entry cannot name the account; the env\n\t\t// fallback inside windowsPrincipal still separates the common case.\n\t\tname = undefined;\n\t}\n\tcachedOwnerComponent = deriveOwnerComponent(windowsPrincipal(name));\n\treturn cachedOwnerComponent;\n}\n\ninterface BaseTempDirs {\n\traw: string;\n\tcanonical: string;\n}\n\nlet cachedBaseTempDirs: BaseTempDirs | undefined;\n\n/**\n * Preserve the OS-provided temp spelling for returned paths while caching a\n * canonical form for internal component checks (macOS `/var` → `/private/var`,\n * for example). Nothing below the base is resolved through `realpath`.\n */\nfunction baseTempDirs(): BaseTempDirs {\n\tconst raw = tmpdir();\n\tif (cachedBaseTempDirs?.raw === raw) {\n\t\treturn cachedBaseTempDirs;\n\t}\n\tlet canonical = raw;\n\ttry {\n\t\tcanonical = realpathSync(raw);\n\t} catch {\n\t\t// An unresolvable temp directory is checked as given.\n\t}\n\tcachedBaseTempDirs = { raw, canonical };\n\treturn cachedBaseTempDirs;\n}\n\n/** `<tmpdir>/<APP_NAME>-<owner>` — the root every session temp tree lives under. */\nexport function getTempRootDir(): string {\n\tconst app = sanitizeTempPathComponent(APP_NAME, \"atomic\");\n\treturn join(baseTempDirs().raw, `${app}-${ownerComponent()}`);\n}\n\n/**\n * The temp directory path for a session, without creating it.\n *\n * Falls back to the process-scoped component when no session id is available,\n * so a tool running outside a transcript session still writes inside the\n * owner-scoped root instead of directly into the system temp directory.\n */\nexport function resolveSessionTempDirPath(sessionId?: string): string {\n\tconst id = sessionId ?? activeSessionId ?? `pid-${process.pid}`;\n\treturn join(getTempRootDir(), sanitizeTempPathComponent(id, FALLBACK_SESSION_COMPONENT));\n}\n\nconst ensuredDirs = new Set<string>();\n\n/** An existing real directory — not a symlink, not a file, not missing. */\nfunction isRealDirectory(path: string): boolean {\n\ttry {\n\t\tconst stat = lstatSync(path);\n\t\treturn stat.isDirectory() && !stat.isSymbolicLink();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/** Raised when a temp directory cannot be created or trusted; callers degrade to no spill file. */\nexport class TempDirRefusedError extends Error {\n\tconstructor(path: string, reason: string) {\n\t\tsuper(`Refusing to use temp directory ${path}: ${reason}`);\n\t\tthis.name = \"TempDirRefusedError\";\n\t}\n}\n\n/**\n * Confirm one existing component is a directory this account owns, at mode 0700.\n *\n * A looser mode is tightened and re-checked; a component owned by another\n * account, or one whose mode cannot be tightened, is refused rather than used.\n *\n * Windows has no uid or POSIX mode, so the proof comes from the security\n * descriptor instead: the owner SID must be a trusted principal and the DACL\n * must grant access to trusted principals only\n * (see `windows-directory-security.ts`). Node exposes neither — `lstatSync`\n * reports uid/gid 0 on Windows — so the read goes through a PowerShell\n * `Get-Acl` subprocess. Successful verifications are cached per path per\n * process, keyed to the directory's metadata identity so a swapped directory\n * or an in-place DACL edit forces a fresh read. Domain-qualifying the\n * principal (see `windowsPrincipal`) stops two accounts *colliding* by\n * accident, which is a different problem and is not a substitute for this\n * verification.\n */\nfunction verifyOwnedDirectory(path: string, known?: Stats): void {\n\tlet stat = known ?? lstatSync(path);\n\tif (stat.isSymbolicLink()) {\n\t\tthrow new TempDirRefusedError(path, \"it is a symbolic link\");\n\t}\n\tif (!stat.isDirectory()) {\n\t\tthrow new TempDirRefusedError(path, \"it is not a directory\");\n\t}\n\tif (process.platform === \"win32\") {\n\t\tconst refusal = verifyWindowsDirectorySecurity(path);\n\t\tif (refusal !== undefined) {\n\t\t\tthrow new TempDirRefusedError(path, refusal);\n\t\t}\n\t\treturn;\n\t}\n\tconst uid = typeof process.getuid === \"function\" ? process.getuid() : undefined;\n\tif (typeof uid === \"number\" && stat.uid !== uid) {\n\t\tthrow new TempDirRefusedError(path, \"it is owned by another account\");\n\t}\n\tif ((stat.mode & 0o777) === SESSION_TEMP_DIR_MODE) {\n\t\treturn;\n\t}\n\ttry {\n\t\tchmodSync(path, SESSION_TEMP_DIR_MODE);\n\t\tstat = lstatSync(path);\n\t} catch {\n\t\tthrow new TempDirRefusedError(path, \"its permissions could not be tightened\");\n\t}\n\tif ((stat.mode & 0o777) !== SESSION_TEMP_DIR_MODE) {\n\t\tthrow new TempDirRefusedError(path, \"its permissions could not be tightened\");\n\t}\n}\n\n/**\n * Create or adopt one path component, never following a link to get there.\n *\n * Creation is non-recursive on purpose: `mkdir -p` resolves an existing symlink\n * on the way down, which is how a link planted at the predictable owner root\n * redirects every later write outside the tree.\n */\nfunction ensureOwnedDirectory(path: string): void {\n\tlet stat: Stats | undefined;\n\ttry {\n\t\tstat = lstatSync(path);\n\t} catch {\n\t\tstat = undefined;\n\t}\n\tif (stat === undefined) {\n\t\ttry {\n\t\t\tmkdirSync(path, { recursive: false, mode: SESSION_TEMP_DIR_MODE });\n\t\t} catch (error) {\n\t\t\t// A concurrent creator winning the race is fine; anything else is not.\n\t\t\tif (getErrnoCode(error) !== \"EEXIST\") {\n\t\t\t\tthrow new TempDirRefusedError(path, \"it could not be created\");\n\t\t\t}\n\t\t}\n\t\tverifyOwnedDirectory(path);\n\t\treturn;\n\t}\n\tverifyOwnedDirectory(path, stat);\n}\n\n/**\n * Adopt the final component, replacing something that is not a directory.\n *\n * Only the leaf gets this treatment: a stale file or link left where a session\n * directory belongs is ours to clear, and removing a symlink removes the link\n * alone. A parent — above all the owner root — is refused instead, because\n * deleting it would be acting on a directory this process does not own.\n */\nfunction ensureLeafDirectory(dir: string): void {\n\ttry {\n\t\tif (!lstatSync(dir).isDirectory()) {\n\t\t\trmSync(dir, { force: true });\n\t\t}\n\t} catch {\n\t\t// Nothing at the path yet, or it cannot be inspected; creation decides.\n\t}\n\tensureOwnedDirectory(dir);\n}\n\n/** Map a lexical temp child to the same path below the canonical temp base. */\nfunction canonicalTempChild(dir: string, base: BaseTempDirs): string | undefined {\n\tfor (const candidate of [base.raw, base.canonical]) {\n\t\tconst prefix = `${candidate}${sep}`;\n\t\tif (dir.startsWith(prefix)) {\n\t\t\treturn join(base.canonical, dir.slice(prefix.length));\n\t\t}\n\t}\n\treturn undefined;\n}\n/**\n * Create `dir` with owner-only permissions, validating every component below the\n * system temp directory.\n *\n * Temp children always revalidate the canonical owner root and every later\n * component, even after a cache hit. A system temp reaper can delete a session\n * tree, and an attacker must not turn a memoized path into a symlink bypass.\n * Caller-owned paths outside the temp base may use the memo after confirming\n * the leaf is still a real directory.\n *\n * Throws {@link TempDirRefusedError} when a component cannot be trusted. Every\n * caller treats that as \"no spill file\", never as a fatal error: failing closed\n * loses a convenience artifact, while failing open writes tool output into a\n * directory someone else controls.\n */\nexport function ensureTempDir(dir: string): string {\n\tconst base = baseTempDirs();\n\tconst checkedDir = canonicalTempChild(dir, base);\n\tif (checkedDir !== undefined) {\n\t\tconst prefix = `${base.canonical}${sep}`;\n\t\tconst parts = checkedDir\n\t\t\t.slice(prefix.length)\n\t\t\t.split(sep)\n\t\t\t.filter((part) => part.length > 0);\n\t\tlet current = base.canonical;\n\t\tfor (const part of parts.slice(0, -1)) {\n\t\t\tcurrent = join(current, part);\n\t\t\tensureOwnedDirectory(current);\n\t\t}\n\t\tensureLeafDirectory(checkedDir);\n\t} else {\n\t\t// A caller-supplied directory outside the system temp base (a session\n\t\t// directory, for instance) is the caller's to own; only the leaf is ours.\n\t\tif (!(ensuredDirs.has(dir) && isRealDirectory(dir))) {\n\t\t\tmkdirSync(dirname(dir), { recursive: true, mode: SESSION_TEMP_DIR_MODE });\n\t\t\tensureLeafDirectory(dir);\n\t\t}\n\t}\n\tensuredDirs.add(dir);\n\treturn dir;\n}\n\n/**\n * Resolve and create the temp directory for a session.\n *\n * Pass an already-resolved directory to reuse a caller-provided path (still\n * created lazily with the same mode).\n */\nexport function getSessionTempDir(sessionId?: string): string {\n\treturn ensureTempDir(resolveSessionTempDirPath(sessionId));\n}\n\n/** Create `explicitDir` when supplied, otherwise the active session's temp directory. */\nexport function ensureSessionTempDir(explicitDir?: string): string {\n\treturn ensureTempDir(explicitDir ?? resolveSessionTempDirPath());\n}\n\nlet activeSessionId: string | undefined;\n\n/**\n * Refcounted protection for directories the sweeper must not reap.\n *\n * A count rather than a set, because protection has more than one holder and\n * more than one lifetime: a session protects its own tree, and one session can\n * be replaced by another wrapping the same paths. Releasing one holder must not\n * unprotect a directory another is still using, and a session that is gone must\n * stop protecting a tree the startup sweep exists to collect.\n */\nconst protectedPathCounts = new Map<string, number>();\n\n/** A protection claim held by one owner; releasing twice is a no-op. */\nexport interface ProtectedPathLease {\n\trelease(): void;\n}\n\n/** Protect `paths` until the returned lease is released. */\nexport function acquireProtectedPaths(paths: readonly string[]): ProtectedPathLease {\n\tconst claimed = paths.filter((path) => path.length > 0);\n\tfor (const path of claimed) {\n\t\tprotectedPathCounts.set(path, (protectedPathCounts.get(path) ?? 0) + 1);\n\t}\n\tlet released = false;\n\treturn {\n\t\trelease() {\n\t\t\tif (released) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treleased = true;\n\t\t\tfor (const path of claimed) {\n\t\t\t\tconst remaining = (protectedPathCounts.get(path) ?? 0) - 1;\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\tprotectedPathCounts.set(path, remaining);\n\t\t\t\t} else {\n\t\t\t\t\tprotectedPathCounts.delete(path);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n}\n\n/**\n * Make `sessionId` the default target for writers without a session handle.\n *\n * Deliberately separate from protection: a disposed session must stop protecting\n * its tree, but whichever session ran last still names where an unattached\n * writer spills.\n */\nexport function setActiveSessionTempId(sessionId: string): string {\n\tactiveSessionId = sessionId;\n\treturn resolveSessionTempDirPath(sessionId);\n}\n\n/** Directories this process must not reap: session temp trees and live tool-results. */\nexport function getProtectedSessionTempDirs(): ReadonlySet<string> {\n\treturn new Set(protectedPathCounts.keys());\n}\n\n/** Test seam: forget the process-level active/protected session state. */\nexport function resetSessionTempDirStateForTesting(): void {\n\tactiveSessionId = undefined;\n\tprotectedPathCounts.clear();\n\tensuredDirs.clear();\n\tcachedOwnerComponent = undefined;\n\tcachedBaseTempDirs = undefined;\n\tresetWindowsDirectorySecurityStateForTesting();\n}\n"]}
1
+ {"version":3,"file":"session-temp-dir.js","sourceRoot":"","sources":["../../../src/core/tools/session-temp-dir.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAc,MAAM,SAAS,CAAC;AAC5F,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EACN,4CAA4C,EAC5C,8BAA8B,GAC9B,MAAM,iCAAiC,CAAC;AAEzC,2EAA2E;AAC3E,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAE3C,8DAA8D;AAC9D,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAE5C,0EAA0E;AAC1E,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC,MAAM,0BAA0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IACpB,oBAAoB,GAAG,SAAS,CAAC;IACjC,kBAAkB,GAAG,SAAS,CAAC;IAC/B,4CAA4C,EAAE,CAAC;AAChD,CAAC","sourcesContent":["/**\n * Owner- and session-scoped temp storage for tool output files.\n *\n * Every file a tool spills to the system temp directory (bash overflow logs,\n * `OutputAccumulator` spill files, and the in-memory-session tool-result fallback)\n * lands under:\n *\n * ```text\n * <tmpdir>/<APP_NAME>-<owner>/<sanitized-session-id>/\n * ```\n *\n * The owner segment mirrors the upstream Claude Code `claude-{uid}` convention\n * (mehmoodosman/claude-code): a shared multi-user temp directory must never let\n * one account write into (or read) another account's tree. The session segment\n * makes the tree reapable as a unit by the age-based sweeper in\n * `session-temp-cleanup.ts` once the session is long gone.\n */\n\nimport { createHash } from \"node:crypto\";\nimport { chmodSync, lstatSync, mkdirSync, realpathSync, rmSync, type Stats } from \"node:fs\";\nimport { tmpdir, userInfo } from \"node:os\";\nimport { dirname, join, sep } from \"node:path\";\nimport { APP_NAME } from \"../../config.js\";\nimport { getErrnoCode } from \"./errno.ts\";\nimport {\n\tresetWindowsDirectorySecurityStateForTesting,\n\tverifyWindowsDirectorySecurity,\n} from \"./windows-directory-security.ts\";\n\n/** Directory mode for every directory this module creates (owner-only). */\nexport const SESSION_TEMP_DIR_MODE = 0o700;\n\n/** File mode for persisted tool-output files (owner-only). */\nexport const SESSION_TEMP_FILE_MODE = 0o600;\n\n/** Longest path component this module will emit for a sanitized value. */\nconst MAX_PATH_COMPONENT_LENGTH = 64;\n\nconst FALLBACK_SESSION_COMPONENT = \"session\";\nconst FALLBACK_OWNER_COMPONENT = \"user\";\n\n/**\n * Reduce a value to a single safe path component.\n *\n * Disallowed characters collapse to `_`; leading `.`/`_` and trailing `.`/`_`\n * are stripped so the result can never be `.`, `..`, a hidden sweeper marker\n * file name, or anything that escapes the parent directory. Trimming uses a\n * linear scan rather than a `/^[._]+|[._]+$/` regex to avoid polynomial-time\n * backtracking on adversarial ids (CodeQL js/polynomial-redos).\n */\nexport function sanitizeTempPathComponent(value: string, fallback: string): string {\n\tconst collapsed = value.replace(/[^a-zA-Z0-9._-]+/g, \"_\");\n\tlet start = 0;\n\tlet end = collapsed.length;\n\twhile (start < end && (collapsed[start] === \"_\" || collapsed[start] === \".\")) {\n\t\tstart++;\n\t}\n\twhile (end > start && (collapsed[end - 1] === \"_\" || collapsed[end - 1] === \".\")) {\n\t\tend--;\n\t}\n\tconst sanitized = collapsed.slice(start, end).slice(0, MAX_PATH_COMPONENT_LENGTH);\n\treturn sanitized.length > 0 ? sanitized : fallback;\n}\n\nlet cachedOwnerComponent: string | undefined;\n\n/**\n * Derive the owner component for a named (non-uid) account.\n *\n * Sanitizing a name to a safe path component is lossy, and two distinct\n * accounts can reduce to the same component (`aliceé` and `aliceø` both yield\n * `alice_`). Where the system temp directory is machine-wide and\n * shared-accessible, that would put two accounts in one tree. Appending a short\n * digest of the raw identity keeps distinct accounts on distinct roots, with\n * the readable component in front so the directory stays recognizable.\n *\n * This prevents collision; it is not owner verification. Ownership is proven\n * separately by `verifyOwnedDirectory` — a uid check on POSIX, an owner-SID\n * and DACL check on Windows.\n *\n * Exported as a pure function so the collision property can be tested directly:\n * its only caller reaches this branch on Windows, which a POSIX test host\n * cannot enter.\n */\nexport function deriveOwnerComponent(rawIdentity: string): string {\n\t// Windows account names are case-insensitive, so `Alice` and `alice` are one\n\t// account and must resolve to one root. Normalize before both the readable\n\t// component and the digest: normalizing only the digest would still emit two\n\t// spellings of one directory, which NTFS then treats as the same path while\n\t// the sweeper's bookkeeping sees two.\n\tconst normalized = rawIdentity.toLowerCase();\n\tconst readable = sanitizeTempPathComponent(normalized, FALLBACK_OWNER_COMPONENT);\n\tconst digest = createHash(\"sha256\").update(normalized).digest(\"hex\").slice(0, 8);\n\treturn `${readable}-${digest}`;\n}\n\n/**\n * Assemble the account identity used where there is no uid.\n *\n * `userInfo().username` returns the bare account name, so `CONTOSO\\Alice` and\n * `FABRIKAM\\Alice` would otherwise be one identity and share a tree. Exported\n * for tests: its caller only reaches this branch on Windows.\n */\nexport function windowsPrincipal(name: string | undefined): string {\n\tconst account = name || process.env.USERNAME || process.env.USER || \"\";\n\t// USERDOMAIN is the NetBIOS domain and is set for both domain and local\n\t// accounts; USERDNSDOMAIN appears only on domain-joined hosts and\n\t// distinguishes two forests that share a NetBIOS name. Neither is\n\t// authoritative on its own, so both take part in the identity.\n\tconst domain = process.env.USERDNSDOMAIN || process.env.USERDOMAIN || \"\";\n\treturn domain ? `${domain}\\\\${account}` : account;\n}\n\n/**\n * Identify the account that owns the temp tree.\n *\n * POSIX uses the numeric uid, which is already collision-free. Windows has no\n * `process.getuid`, so the domain-qualified principal stands in.\n */\nfunction ownerComponent(): string {\n\tif (cachedOwnerComponent !== undefined) {\n\t\treturn cachedOwnerComponent;\n\t}\n\tconst uid = typeof process.getuid === \"function\" ? process.getuid() : undefined;\n\tif (typeof uid === \"number\" && Number.isFinite(uid)) {\n\t\tcachedOwnerComponent = String(uid);\n\t\treturn cachedOwnerComponent;\n\t}\n\tlet name: string | undefined;\n\ttry {\n\t\tname = userInfo().username;\n\t} catch {\n\t\t// A container without a passwd entry cannot name the account; the env\n\t\t// fallback inside windowsPrincipal still separates the common case.\n\t\tname = undefined;\n\t}\n\tcachedOwnerComponent = deriveOwnerComponent(windowsPrincipal(name));\n\treturn cachedOwnerComponent;\n}\n\ninterface BaseTempDirs {\n\traw: string;\n\tcanonical: string;\n}\n\nlet cachedBaseTempDirs: BaseTempDirs | undefined;\n\n/**\n * Preserve the OS-provided temp spelling for returned paths while caching a\n * canonical form for internal component checks (macOS `/var` → `/private/var`,\n * for example). Nothing below the base is resolved through `realpath`.\n */\nfunction baseTempDirs(): BaseTempDirs {\n\tconst raw = tmpdir();\n\tif (cachedBaseTempDirs?.raw === raw) {\n\t\treturn cachedBaseTempDirs;\n\t}\n\tlet canonical = raw;\n\ttry {\n\t\tcanonical = realpathSync(raw);\n\t} catch {\n\t\t// An unresolvable temp directory is checked as given.\n\t}\n\tcachedBaseTempDirs = { raw, canonical };\n\treturn cachedBaseTempDirs;\n}\n\n/** `<tmpdir>/<APP_NAME>-<owner>` — the root every session temp tree lives under. */\nexport function getTempRootDir(): string {\n\tconst app = sanitizeTempPathComponent(APP_NAME, \"atomic\");\n\treturn join(baseTempDirs().raw, `${app}-${ownerComponent()}`);\n}\n\n/**\n * The temp directory path for a session, without creating it.\n *\n * Falls back to the process-scoped component when no session id is available,\n * so a tool running outside a transcript session still writes inside the\n * owner-scoped root instead of directly into the system temp directory.\n */\nexport function resolveSessionTempDirPath(sessionId?: string): string {\n\tconst id = sessionId ?? activeSessionId ?? `pid-${process.pid}`;\n\treturn join(getTempRootDir(), sanitizeTempPathComponent(id, FALLBACK_SESSION_COMPONENT));\n}\n\nconst ensuredDirs = new Set<string>();\n\n/** An existing real directory — not a symlink, not a file, not missing. */\nfunction isRealDirectory(path: string): boolean {\n\ttry {\n\t\tconst stat = lstatSync(path);\n\t\treturn stat.isDirectory() && !stat.isSymbolicLink();\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/** Raised when a temp directory cannot be created or trusted; callers degrade to no spill file. */\nexport class TempDirRefusedError extends Error {\n\tconstructor(path: string, reason: string) {\n\t\tsuper(`Refusing to use temp directory ${path}: ${reason}`);\n\t\tthis.name = \"TempDirRefusedError\";\n\t}\n}\n\n/**\n * Confirm one existing component is a directory this account owns, at mode 0700.\n *\n * A looser mode is tightened and re-checked; a component owned by another\n * account, or one whose mode cannot be tightened, is refused rather than used.\n *\n * Windows has no uid or POSIX mode, so the proof comes from the security\n * descriptor instead: the owner SID must be a trusted principal and the DACL\n * must grant access to trusted principals only\n * (see `windows-directory-security.ts`). Node exposes neither — `lstatSync`\n * reports uid/gid 0 on Windows — so the read goes through a PowerShell\n * `Get-Acl` subprocess. Successful verifications are cached per path per\n * process, keyed to the directory's metadata identity so a swapped directory\n * or an in-place DACL edit forces a fresh read. Domain-qualifying the\n * principal (see `windowsPrincipal`) stops two accounts *colliding* by\n * accident, which is a different problem and is not a substitute for this\n * verification.\n */\nfunction verifyOwnedDirectory(path: string, known?: Stats): void {\n\tlet stat = known ?? lstatSync(path);\n\tif (stat.isSymbolicLink()) {\n\t\tthrow new TempDirRefusedError(path, \"it is a symbolic link\");\n\t}\n\tif (!stat.isDirectory()) {\n\t\tthrow new TempDirRefusedError(path, \"it is not a directory\");\n\t}\n\tif (process.platform === \"win32\") {\n\t\tconst refusal = verifyWindowsDirectorySecurity(path);\n\t\tif (refusal !== undefined) {\n\t\t\tthrow new TempDirRefusedError(path, refusal);\n\t\t}\n\t\treturn;\n\t}\n\tconst uid = typeof process.getuid === \"function\" ? process.getuid() : undefined;\n\tif (typeof uid === \"number\" && stat.uid !== uid) {\n\t\tthrow new TempDirRefusedError(path, \"it is owned by another account\");\n\t}\n\tif ((stat.mode & 0o777) === SESSION_TEMP_DIR_MODE) {\n\t\treturn;\n\t}\n\ttry {\n\t\tchmodSync(path, SESSION_TEMP_DIR_MODE);\n\t\tstat = lstatSync(path);\n\t} catch {\n\t\tthrow new TempDirRefusedError(path, \"its permissions could not be tightened\");\n\t}\n\tif ((stat.mode & 0o777) !== SESSION_TEMP_DIR_MODE) {\n\t\tthrow new TempDirRefusedError(path, \"its permissions could not be tightened\");\n\t}\n}\n\n/**\n * Create or adopt one path component, never following a link to get there.\n *\n * Creation is non-recursive on purpose: `mkdir -p` resolves an existing symlink\n * on the way down, which is how a link planted at the predictable owner root\n * redirects every later write outside the tree.\n */\nfunction ensureOwnedDirectory(path: string): void {\n\tlet stat: Stats | undefined;\n\ttry {\n\t\tstat = lstatSync(path);\n\t} catch {\n\t\tstat = undefined;\n\t}\n\tif (stat === undefined) {\n\t\ttry {\n\t\t\tmkdirSync(path, { recursive: false, mode: SESSION_TEMP_DIR_MODE });\n\t\t} catch (error) {\n\t\t\t// A concurrent creator winning the race is fine; anything else is not.\n\t\t\tif (getErrnoCode(error) !== \"EEXIST\") {\n\t\t\t\tthrow new TempDirRefusedError(path, \"it could not be created\");\n\t\t\t}\n\t\t}\n\t\tverifyOwnedDirectory(path);\n\t\treturn;\n\t}\n\tverifyOwnedDirectory(path, stat);\n}\n\n/**\n * Adopt the final component, replacing something that is not a directory.\n *\n * Only the leaf gets this treatment: a stale file or link left where a session\n * directory belongs is ours to clear, and removing a symlink removes the link\n * alone. A parent — above all the owner root — is refused instead, because\n * deleting it would be acting on a directory this process does not own.\n */\nfunction ensureLeafDirectory(dir: string): void {\n\ttry {\n\t\tif (!lstatSync(dir).isDirectory()) {\n\t\t\trmSync(dir, { force: true });\n\t\t}\n\t} catch {\n\t\t// Nothing at the path yet, or it cannot be inspected; creation decides.\n\t}\n\tensureOwnedDirectory(dir);\n}\n\n/** Map a lexical temp child to the same path below the canonical temp base. */\nfunction canonicalTempChild(dir: string, base: BaseTempDirs): string | undefined {\n\tfor (const candidate of [base.raw, base.canonical]) {\n\t\tconst prefix = `${candidate}${sep}`;\n\t\tif (dir.startsWith(prefix)) {\n\t\t\treturn join(base.canonical, dir.slice(prefix.length));\n\t\t}\n\t}\n\treturn undefined;\n}\n/**\n * Create `dir` with owner-only permissions, validating every component below the\n * system temp directory.\n *\n * Temp children always revalidate the canonical owner root and every later\n * component, even after a cache hit. A system temp reaper can delete a session\n * tree, and an attacker must not turn a memoized path into a symlink bypass.\n * Caller-owned paths outside the temp base may use the memo after confirming\n * the leaf is still a real directory.\n *\n * Throws {@link TempDirRefusedError} when a component cannot be trusted. Every\n * caller treats that as \"no spill file\", never as a fatal error: failing closed\n * loses a convenience artifact, while failing open writes tool output into a\n * directory someone else controls.\n */\nexport function ensureTempDir(dir: string): string {\n\tconst base = baseTempDirs();\n\tconst checkedDir = canonicalTempChild(dir, base);\n\tif (checkedDir !== undefined) {\n\t\tconst prefix = `${base.canonical}${sep}`;\n\t\tconst parts = checkedDir\n\t\t\t.slice(prefix.length)\n\t\t\t.split(sep)\n\t\t\t.filter((part) => part.length > 0);\n\t\tlet current = base.canonical;\n\t\tfor (const part of parts.slice(0, -1)) {\n\t\t\tcurrent = join(current, part);\n\t\t\tensureOwnedDirectory(current);\n\t\t}\n\t\tensureLeafDirectory(checkedDir);\n\t} else {\n\t\t// A caller-supplied directory outside the system temp base (a session\n\t\t// directory, for instance) is the caller's to own; only the leaf is ours.\n\t\tif (!(ensuredDirs.has(dir) && isRealDirectory(dir))) {\n\t\t\tmkdirSync(dirname(dir), { recursive: true, mode: SESSION_TEMP_DIR_MODE });\n\t\t\tensureLeafDirectory(dir);\n\t\t}\n\t}\n\tensuredDirs.add(dir);\n\treturn dir;\n}\n\n/**\n * Resolve and create the temp directory for a session.\n *\n * Pass an already-resolved directory to reuse a caller-provided path (still\n * created lazily with the same mode).\n */\nexport function getSessionTempDir(sessionId?: string): string {\n\treturn ensureTempDir(resolveSessionTempDirPath(sessionId));\n}\n\n/** Create `explicitDir` when supplied, otherwise the active session's temp directory. */\nexport function ensureSessionTempDir(explicitDir?: string): string {\n\treturn ensureTempDir(explicitDir ?? resolveSessionTempDirPath());\n}\n\nlet activeSessionId: string | undefined;\n\n/**\n * Refcounted protection for directories the sweeper must not reap.\n *\n * A count rather than a set, because protection has more than one holder and\n * more than one lifetime: a session protects its own tree, and one session can\n * be replaced by another wrapping the same paths. Releasing one holder must not\n * unprotect a directory another is still using, and a session that is gone must\n * stop protecting a tree the startup sweep exists to collect.\n */\nconst protectedPathCounts = new Map<string, number>();\n\n/** A protection claim held by one owner; releasing twice is a no-op. */\nexport interface ProtectedPathLease {\n\trelease(): void;\n}\n\n/** Protect `paths` until the returned lease is released. */\nexport function acquireProtectedPaths(paths: readonly string[]): ProtectedPathLease {\n\tconst claimed = paths.filter((path) => path.length > 0);\n\tfor (const path of claimed) {\n\t\tprotectedPathCounts.set(path, (protectedPathCounts.get(path) ?? 0) + 1);\n\t}\n\tlet released = false;\n\treturn {\n\t\trelease() {\n\t\t\tif (released) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\treleased = true;\n\t\t\tfor (const path of claimed) {\n\t\t\t\tconst remaining = (protectedPathCounts.get(path) ?? 0) - 1;\n\t\t\t\tif (remaining > 0) {\n\t\t\t\t\tprotectedPathCounts.set(path, remaining);\n\t\t\t\t} else {\n\t\t\t\t\tprotectedPathCounts.delete(path);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t};\n}\n\n/**\n * Make `sessionId` the default target for writers without a session handle.\n *\n * Deliberately separate from protection: a disposed session must stop protecting\n * its tree, but whichever session ran last still names where an unattached\n * writer spills.\n */\nexport function setActiveSessionTempId(sessionId: string): string {\n\tactiveSessionId = sessionId;\n\treturn resolveSessionTempDirPath(sessionId);\n}\n\n/** Directories this process must not reap: session temp trees and live tool-results. */\nexport function getProtectedSessionTempDirs(): ReadonlySet<string> {\n\treturn new Set(protectedPathCounts.keys());\n}\n\n/** Test seam: forget the process-level active/protected session state. */\nexport function resetSessionTempDirStateForTesting(): void {\n\tactiveSessionId = undefined;\n\tprotectedPathCounts.clear();\n\tensuredDirs.clear();\n\tcachedOwnerComponent = undefined;\n\tcachedBaseTempDirs = undefined;\n\tresetWindowsDirectorySecurityStateForTesting();\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"todos-paths.js","sourceRoot":"","sources":["../../../src/core/tools/todos-paths.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEzE,MAAM,aAAa,GAAG,GAAG,eAAe,QAAQ,CAAC;AACjD,MAAM,aAAa,GAAG,GAAG,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;AAE5D,MAAM,UAAU,WAAW,CAAC,GAAW;IACtC,MAAM,YAAY,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC;IAChD,IAAI,YAAY,EAAE,IAAI,EAAE,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC3C,MAAM,YAAY,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC;IAChD,IAAI,YAAY,EAAE,IAAI,EAAE,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,aAAa,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,EAAU;IACvD,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,EAAU;IACvD,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import path from \"node:path\";\nimport { APP_NAME, CONFIG_DIR_NAME, getEnvValue } from \"../../config.ts\";\n\nconst TODO_DIR_NAME = `${CONFIG_DIR_NAME}/todos`;\nconst TODO_PATH_ENV = `${APP_NAME.toUpperCase()}_TODO_PATH`;\n\nexport function getTodosDir(cwd: string): string {\n\tconst overridePath = getEnvValue(TODO_PATH_ENV);\n\tif (overridePath?.trim()) {\n\t\treturn path.resolve(cwd, overridePath.trim());\n\t}\n\treturn path.resolve(cwd, TODO_DIR_NAME);\n}\n\nexport function getTodosDirLabel(cwd: string): string {\n\tconst overridePath = getEnvValue(TODO_PATH_ENV);\n\tif (overridePath?.trim()) {\n\t\treturn path.resolve(cwd, overridePath.trim());\n\t}\n\treturn TODO_DIR_NAME;\n}\n\nexport function getTodoPath(todosDir: string, id: string): string {\n\treturn path.join(todosDir, `${id}.md`);\n}\n\nexport function getLockPath(todosDir: string, id: string): string {\n\treturn path.join(todosDir, `${id}.lock`);\n}\n"]}
1
+ {"version":3,"file":"todos-paths.js","sourceRoot":"","sources":["../../../src/core/tools/todos-paths.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEzE,MAAM,aAAa,GAAG,GAAG,eAAe,QAAQ,CAAC;AACjD,MAAM,aAAa,GAAG,GAAG,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;AAE5D,MAAM,UAAU,WAAW,CAAC,GAAW;IACtC,MAAM,YAAY,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC;IAChD,IAAI,YAAY,EAAE,IAAI,EAAE,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC3C,MAAM,YAAY,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC;IAChD,IAAI,YAAY,EAAE,IAAI,EAAE,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,aAAa,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,EAAU;IACvD,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,QAAgB,EAAE,EAAU;IACvD,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["import path from \"node:path\";\nimport { APP_NAME, CONFIG_DIR_NAME, getEnvValue } from \"../../config.js\";\n\nconst TODO_DIR_NAME = `${CONFIG_DIR_NAME}/todos`;\nconst TODO_PATH_ENV = `${APP_NAME.toUpperCase()}_TODO_PATH`;\n\nexport function getTodosDir(cwd: string): string {\n\tconst overridePath = getEnvValue(TODO_PATH_ENV);\n\tif (overridePath?.trim()) {\n\t\treturn path.resolve(cwd, overridePath.trim());\n\t}\n\treturn path.resolve(cwd, TODO_DIR_NAME);\n}\n\nexport function getTodosDirLabel(cwd: string): string {\n\tconst overridePath = getEnvValue(TODO_PATH_ENV);\n\tif (overridePath?.trim()) {\n\t\treturn path.resolve(cwd, overridePath.trim());\n\t}\n\treturn TODO_DIR_NAME;\n}\n\nexport function getTodoPath(todosDir: string, id: string): string {\n\treturn path.join(todosDir, `${id}.md`);\n}\n\nexport function getLockPath(todosDir: string, id: string): string {\n\treturn path.join(todosDir, `${id}.lock`);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"trust-manager.js","sourceRoot":"","sources":["../../src/core/trust-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAsB9E,MAAM,CAAC,MAAM,wCAAwC,GAAG;IACvD,eAAe;IACf,YAAY;IACZ,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,WAAW;IACX,kBAAkB;CACT,CAAC;AAEX,SAAS,YAAY,CAAC,GAAW;IAChC,OAAO,gBAAgB,CAAC,WAAW,CAAC,GAAG,CAAC,CA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3C,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,SAAS,EAAE,CAAC;gBAC5C,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;gBAC/B,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;oBACvB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;gBAClB,CAAC;qBAAM,CAAC;oBACP,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;gBACtB,CAAC;YACF,CAAC;YACD,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport lockfile from \"proper-lockfile\";\nimport { CONFIG_DIR_NAMES } from \"../config.ts\";\nimport { parseJsonFileContent } from \"../utils/json.ts\";\nimport { canonicalizePath, getHomeDir, resolvePath } from \"../utils/paths.ts\";\n\nexport type ProjectTrustDecision = boolean | null;\n\nexport interface ProjectTrustStoreEntry {\n\tpath: string;\n\tdecision: boolean;\n}\n\nexport interface ProjectTrustUpdate {\n\tpath: string;\n\tdecision: ProjectTrustDecision;\n}\n\nexport interface ProjectTrustOption {\n\tlabel: string;\n\ttrusted: boolean;\n\tupdates: ProjectTrustUpdate[];\n\tsavedPath?: string;\n}\n\ntype TrustFile = Record<string, boolean | null | undefined>;\nexport const TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES = [\n\t\"settings.json\",\n\t\"extensions\",\n\t\"skills\",\n\t\"prompts\",\n\t\"themes\",\n\t\"SYSTEM.md\",\n\t\"APPEND_SYSTEM.md\",\n] as const;\n\nfunction normalizeCwd(cwd: string): string {\n\treturn canonicalizePath(resolvePath(cwd));\n}\n\nfunction findNearestTrustEntry(data: TrustFile, cwd: string): ProjectTrustStoreEntry | null {\n\tlet currentDir = normalizeCwd(cwd);\n\twhile (true) {\n\t\tconst value = data[currentDir];\n\t\tif (value === true || value === false) {\n\t\t\treturn { path: currentDir, decision: value };\n\t\t}\n\n\t\tconst parentDir = dirname(currentDir);\n\t\tif (parentDir === currentDir) {\n\t\t\treturn null;\n\t\t}\n\t\tcurrentDir = parentDir;\n\t}\n}\n\nexport function getProjectTrustPath(cwd: string): string {\n\treturn normalizeCwd(cwd);\n}\n\nexport function getProjectTrustParentPath(cwd: string): string | undefined {\n\tconst trustPath = getProjectTrustPath(cwd);\n\tconst parentDir = dirname(trustPath);\n\treturn parentDir === trustPath ? undefined : parentDir;\n}\n\nexport function getProjectTrustOptions(cwd: string, options?: { includeSessionOnly?: boolean }): ProjectTrustOption[] {\n\tconst trustPath = getProjectTrustPath(cwd);\n\tconst trustOptions: ProjectTrustOption[] = [\n\t\t{ label: \"Trust\", trusted: true, updates: [{ path: trustPath, decision: true }], savedPath: trustPath },\n\t];\n\tconst parentPath = getProjectTrustParentPath(cwd);\n\tif (parentPath !== undefined) {\n\t\ttrustOptions.push({\n\t\t\tlabel: `Trust parent folder (${parentPath})`,\n\t\t\ttrusted: true,\n\t\t\tupdates: [\n\t\t\t\t{ path: parentPath, decision: true },\n\t\t\t\t{ path: trustPath, decision: null },\n\t\t\t],\n\t\t\tsavedPath: parentPath,\n\t\t});\n\t}\n\tif (options?.includeSessionOnly) {\n\t\ttrustOptions.push({ label: \"Trust (this session only)\", trusted: true, updates: [] });\n\t}\n\ttrustOptions.push({\n\t\tlabel: \"Do not trust\",\n\t\ttrusted: false,\n\t\tupdates: [{ path: trustPath, decision: false }],\n\t\tsavedPath: trustPath,\n\t});\n\tif (options?.includeSessionOnly) {\n\t\ttrustOptions.push({ label: \"Do not trust (this session only)\", trusted: false, updates: [] });\n\t}\n\treturn trustOptions;\n}\n\nfunction readTrustFile(path: string): TrustFile {\n\tif (!existsSync(path)) {\n\t\treturn {};\n\t}\n\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = parseJsonFileContent(readFileSync(path, \"utf-8\"));\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`Failed to read trust store ${path}: ${message}`);\n\t}\n\n\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\tthrow new Error(`Invalid trust store ${path}: expected an object`);\n\t}\n\n\tconst data: TrustFile = {};\n\tfor (const [key, value] of Object.entries(parsed)) {\n\t\tif (value !== true && value !== false && value !== null) {\n\t\t\tthrow new Error(`Invalid trust store ${path}: value for ${JSON.stringify(key)} must be true, false, or null`);\n\t\t}\n\t\tdata[key] = value;\n\t}\n\treturn data;\n}\n\nfunction writeTrustFile(path: string, data: TrustFile): void {\n\tconst sorted: TrustFile = {};\n\tfor (const key of Object.keys(data).sort()) {\n\t\tconst value = data[key];\n\t\tif (value === true || value === false || value === null) {\n\t\t\tsorted[key] = value;\n\t\t}\n\t}\n\tmkdirSync(dirname(path), { recursive: true });\n\twriteFileSync(path, `${JSON.stringify(sorted, null, 2)}\\n`, \"utf-8\");\n}\n\nfunction acquireTrustLockSync(path: string): () => void {\n\tconst trustDir = dirname(path);\n\tmkdirSync(trustDir, { recursive: true });\n\tconst maxAttempts = 10;\n\tconst delayMs = 20;\n\tlet lastError: unknown;\n\n\tfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\n\t\ttry {\n\t\t\treturn lockfile.lockSync(trustDir, { realpath: false, lockfilePath: `${path}.lock` });\n\t\t} catch (error) {\n\t\t\tconst code =\n\t\t\t\ttypeof error === \"object\" && error !== null && \"code\" in error\n\t\t\t\t\t? String((error as { code?: unknown }).code)\n\t\t\t\t\t: undefined;\n\t\t\tif (code !== \"ELOCKED\" || attempt === maxAttempts) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tlastError = error;\n\t\t\tconst start = Date.now();\n\t\t\twhile (Date.now() - start < delayMs) {\n\t\t\t\t// Sleep synchronously to avoid changing trust store callers to async.\n\t\t\t}\n\t\t}\n\t}\n\n\tif (lastError instanceof Error) {\n\t\tthrow lastError;\n\t}\n\tthrow new Error(\"Failed to acquire trust store lock\");\n}\n\nfunction withTrustFileLock<T>(path: string, fn: () => T): T {\n\tconst release = acquireTrustLockSync(path);\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\trelease();\n\t}\n}\n\nexport function hasProjectConfigDir(cwd: string): boolean {\n\tconst projectCwd = canonicalizePath(resolvePath(cwd));\n\treturn CONFIG_DIR_NAMES.some((configDirName) => existsSync(join(projectCwd, configDirName)));\n}\nfunction hasTrustRequiringConfigResources(cwd: string): boolean {\n\tconst projectCwd = canonicalizePath(resolvePath(cwd));\n\treturn CONFIG_DIR_NAMES.some((configDirName) => {\n\t\tconst configDir = join(projectCwd, configDirName);\n\t\treturn TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES.some((entry) => existsSync(join(configDir, entry)));\n\t});\n}\n\n/**\n * Returns true when cwd has project-local resources that must be gated by\n * project trust: trust-requiring entries under cwd/.atomic or cwd/.pi, or\n * .agents/skills in cwd or one of its ancestors. Returns false for inert\n * state-only config directories. The user-global ~/.agents/skills directory is\n * always treated as a trusted user resource and ignored, even when cwd is $HOME.\n */\nexport function hasTrustRequiringProjectResources(cwd: string): boolean {\n\tif (hasTrustRequiringConfigResources(cwd)) {\n\t\treturn true;\n\t}\n\n\tconst userGlobalSkillsDir = canonicalizePath(resolvePath(join(getHomeDir(), \".agents\", \"skills\")));\n\tlet currentDir = canonicalizePath(resolvePath(cwd));\n\twhile (true) {\n\t\tconst skillsDir = canonicalizePath(resolvePath(join(currentDir, \".agents\", \"skills\")));\n\t\tif (skillsDir !== userGlobalSkillsDir && existsSync(skillsDir)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst parentDir = dirname(currentDir);\n\t\tif (parentDir === currentDir) {\n\t\t\treturn false;\n\t\t}\n\t\tcurrentDir = parentDir;\n\t}\n}\n\nexport function hasProjectTrustInputs(cwd: string): boolean {\n\tlet currentDir = canonicalizePath(resolvePath(cwd));\n\tif (hasTrustRequiringConfigResources(currentDir)) {\n\t\treturn true;\n\t}\n\tconst userGlobalSkillsDir = canonicalizePath(resolvePath(join(getHomeDir(), \".agents\", \"skills\")));\n\tconst contextFileNames = [\"AGENTS.override.md\", \"AGENTS.md\", \"AGENTS.MD\", \"CLAUDE.md\", \"CLAUDE.MD\"];\n\n\twhile (true) {\n\t\tfor (const contextFileName of contextFileNames) {\n\t\t\tif (existsSync(join(currentDir, contextFileName))) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tconst skillsDir = canonicalizePath(resolvePath(join(currentDir, \".agents\", \"skills\")));\n\t\tif (skillsDir !== userGlobalSkillsDir && existsSync(skillsDir)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst parentDir = dirname(currentDir);\n\t\tif (parentDir === currentDir) {\n\t\t\treturn false;\n\t\t}\n\t\tcurrentDir = parentDir;\n\t}\n}\n\nexport class ProjectTrustStore {\n\tprivate trustPath: string;\n\n\tconstructor(agentDir: string) {\n\t\tthis.trustPath = join(resolvePath(agentDir), \"trust.json\");\n\t}\n\n\tget(cwd: string): ProjectTrustDecision {\n\t\treturn this.getEntry(cwd)?.decision ?? null;\n\t}\n\n\tgetEntry(cwd: string): ProjectTrustStoreEntry | null {\n\t\treturn withTrustFileLock(this.trustPath, () => {\n\t\t\tconst data = readTrustFile(this.trustPath);\n\t\t\treturn findNearestTrustEntry(data, cwd);\n\t\t});\n\t}\n\n\tset(cwd: string, decision: ProjectTrustDecision): void {\n\t\tthis.setMany([{ path: cwd, decision }]);\n\t}\n\n\tsetMany(decisions: ProjectTrustUpdate[]): void {\n\t\twithTrustFileLock(this.trustPath, () => {\n\t\t\tconst data = readTrustFile(this.trustPath);\n\t\t\tfor (const { path, decision } of decisions) {\n\t\t\t\tconst key = normalizeCwd(path);\n\t\t\t\tif (decision === null) {\n\t\t\t\t\tdelete data[key];\n\t\t\t\t} else {\n\t\t\t\t\tdata[key] = decision;\n\t\t\t\t}\n\t\t\t}\n\t\t\twriteTrustFile(this.trustPath, data);\n\t\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AAC;IAC5D,CAAC;IAED,GAAG,CAAC,GAAW;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,IAAI,IAAI,CAAC;IAC7C,CAAC;IAED,QAAQ,CAAC,GAAW;QACnB,OAAO,iBAAiB,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;YAC7C,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC3C,OAAO,qBAAqB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,GAAG,CAAC,GAAW,EAAE,QAA8B;QAC9C,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,CAAC,SAA+B;QACtC,iBAAiB,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;YACtC,MAAM,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC3C,KAAK,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,SAAS,EAAE,CAAC;gBAC5C,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;gBAC/B,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;oBACvB,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;gBAClB,CAAC;qBAAM,CAAC;oBACP,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;gBACtB,CAAC;YACF,CAAC;YACD,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["import { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport lockfile from \"proper-lockfile\";\nimport { CONFIG_DIR_NAMES } from \"../config.js\";\nimport { parseJsonFileContent } from \"../utils/json.ts\";\nimport { canonicalizePath, getHomeDir, resolvePath } from \"../utils/paths.ts\";\n\nexport type ProjectTrustDecision = boolean | null;\n\nexport interface ProjectTrustStoreEntry {\n\tpath: string;\n\tdecision: boolean;\n}\n\nexport interface ProjectTrustUpdate {\n\tpath: string;\n\tdecision: ProjectTrustDecision;\n}\n\nexport interface ProjectTrustOption {\n\tlabel: string;\n\ttrusted: boolean;\n\tupdates: ProjectTrustUpdate[];\n\tsavedPath?: string;\n}\n\ntype TrustFile = Record<string, boolean | null | undefined>;\nexport const TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES = [\n\t\"settings.json\",\n\t\"extensions\",\n\t\"skills\",\n\t\"prompts\",\n\t\"themes\",\n\t\"SYSTEM.md\",\n\t\"APPEND_SYSTEM.md\",\n] as const;\n\nfunction normalizeCwd(cwd: string): string {\n\treturn canonicalizePath(resolvePath(cwd));\n}\n\nfunction findNearestTrustEntry(data: TrustFile, cwd: string): ProjectTrustStoreEntry | null {\n\tlet currentDir = normalizeCwd(cwd);\n\twhile (true) {\n\t\tconst value = data[currentDir];\n\t\tif (value === true || value === false) {\n\t\t\treturn { path: currentDir, decision: value };\n\t\t}\n\n\t\tconst parentDir = dirname(currentDir);\n\t\tif (parentDir === currentDir) {\n\t\t\treturn null;\n\t\t}\n\t\tcurrentDir = parentDir;\n\t}\n}\n\nexport function getProjectTrustPath(cwd: string): string {\n\treturn normalizeCwd(cwd);\n}\n\nexport function getProjectTrustParentPath(cwd: string): string | undefined {\n\tconst trustPath = getProjectTrustPath(cwd);\n\tconst parentDir = dirname(trustPath);\n\treturn parentDir === trustPath ? undefined : parentDir;\n}\n\nexport function getProjectTrustOptions(cwd: string, options?: { includeSessionOnly?: boolean }): ProjectTrustOption[] {\n\tconst trustPath = getProjectTrustPath(cwd);\n\tconst trustOptions: ProjectTrustOption[] = [\n\t\t{ label: \"Trust\", trusted: true, updates: [{ path: trustPath, decision: true }], savedPath: trustPath },\n\t];\n\tconst parentPath = getProjectTrustParentPath(cwd);\n\tif (parentPath !== undefined) {\n\t\ttrustOptions.push({\n\t\t\tlabel: `Trust parent folder (${parentPath})`,\n\t\t\ttrusted: true,\n\t\t\tupdates: [\n\t\t\t\t{ path: parentPath, decision: true },\n\t\t\t\t{ path: trustPath, decision: null },\n\t\t\t],\n\t\t\tsavedPath: parentPath,\n\t\t});\n\t}\n\tif (options?.includeSessionOnly) {\n\t\ttrustOptions.push({ label: \"Trust (this session only)\", trusted: true, updates: [] });\n\t}\n\ttrustOptions.push({\n\t\tlabel: \"Do not trust\",\n\t\ttrusted: false,\n\t\tupdates: [{ path: trustPath, decision: false }],\n\t\tsavedPath: trustPath,\n\t});\n\tif (options?.includeSessionOnly) {\n\t\ttrustOptions.push({ label: \"Do not trust (this session only)\", trusted: false, updates: [] });\n\t}\n\treturn trustOptions;\n}\n\nfunction readTrustFile(path: string): TrustFile {\n\tif (!existsSync(path)) {\n\t\treturn {};\n\t}\n\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = parseJsonFileContent(readFileSync(path, \"utf-8\"));\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new Error(`Failed to read trust store ${path}: ${message}`);\n\t}\n\n\tif (typeof parsed !== \"object\" || parsed === null || Array.isArray(parsed)) {\n\t\tthrow new Error(`Invalid trust store ${path}: expected an object`);\n\t}\n\n\tconst data: TrustFile = {};\n\tfor (const [key, value] of Object.entries(parsed)) {\n\t\tif (value !== true && value !== false && value !== null) {\n\t\t\tthrow new Error(`Invalid trust store ${path}: value for ${JSON.stringify(key)} must be true, false, or null`);\n\t\t}\n\t\tdata[key] = value;\n\t}\n\treturn data;\n}\n\nfunction writeTrustFile(path: string, data: TrustFile): void {\n\tconst sorted: TrustFile = {};\n\tfor (const key of Object.keys(data).sort()) {\n\t\tconst value = data[key];\n\t\tif (value === true || value === false || value === null) {\n\t\t\tsorted[key] = value;\n\t\t}\n\t}\n\tmkdirSync(dirname(path), { recursive: true });\n\twriteFileSync(path, `${JSON.stringify(sorted, null, 2)}\\n`, \"utf-8\");\n}\n\nfunction acquireTrustLockSync(path: string): () => void {\n\tconst trustDir = dirname(path);\n\tmkdirSync(trustDir, { recursive: true });\n\tconst maxAttempts = 10;\n\tconst delayMs = 20;\n\tlet lastError: unknown;\n\n\tfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\n\t\ttry {\n\t\t\treturn lockfile.lockSync(trustDir, { realpath: false, lockfilePath: `${path}.lock` });\n\t\t} catch (error) {\n\t\t\tconst code =\n\t\t\t\ttypeof error === \"object\" && error !== null && \"code\" in error\n\t\t\t\t\t? String((error as { code?: unknown }).code)\n\t\t\t\t\t: undefined;\n\t\t\tif (code !== \"ELOCKED\" || attempt === maxAttempts) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tlastError = error;\n\t\t\tconst start = Date.now();\n\t\t\twhile (Date.now() - start < delayMs) {\n\t\t\t\t// Sleep synchronously to avoid changing trust store callers to async.\n\t\t\t}\n\t\t}\n\t}\n\n\tif (lastError instanceof Error) {\n\t\tthrow lastError;\n\t}\n\tthrow new Error(\"Failed to acquire trust store lock\");\n}\n\nfunction withTrustFileLock<T>(path: string, fn: () => T): T {\n\tconst release = acquireTrustLockSync(path);\n\ttry {\n\t\treturn fn();\n\t} finally {\n\t\trelease();\n\t}\n}\n\nexport function hasProjectConfigDir(cwd: string): boolean {\n\tconst projectCwd = canonicalizePath(resolvePath(cwd));\n\treturn CONFIG_DIR_NAMES.some((configDirName) => existsSync(join(projectCwd, configDirName)));\n}\nfunction hasTrustRequiringConfigResources(cwd: string): boolean {\n\tconst projectCwd = canonicalizePath(resolvePath(cwd));\n\treturn CONFIG_DIR_NAMES.some((configDirName) => {\n\t\tconst configDir = join(projectCwd, configDirName);\n\t\treturn TRUST_REQUIRING_PROJECT_CONFIG_RESOURCES.some((entry) => existsSync(join(configDir, entry)));\n\t});\n}\n\n/**\n * Returns true when cwd has project-local resources that must be gated by\n * project trust: trust-requiring entries under cwd/.atomic or cwd/.pi, or\n * .agents/skills in cwd or one of its ancestors. Returns false for inert\n * state-only config directories. The user-global ~/.agents/skills directory is\n * always treated as a trusted user resource and ignored, even when cwd is $HOME.\n */\nexport function hasTrustRequiringProjectResources(cwd: string): boolean {\n\tif (hasTrustRequiringConfigResources(cwd)) {\n\t\treturn true;\n\t}\n\n\tconst userGlobalSkillsDir = canonicalizePath(resolvePath(join(getHomeDir(), \".agents\", \"skills\")));\n\tlet currentDir = canonicalizePath(resolvePath(cwd));\n\twhile (true) {\n\t\tconst skillsDir = canonicalizePath(resolvePath(join(currentDir, \".agents\", \"skills\")));\n\t\tif (skillsDir !== userGlobalSkillsDir && existsSync(skillsDir)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst parentDir = dirname(currentDir);\n\t\tif (parentDir === currentDir) {\n\t\t\treturn false;\n\t\t}\n\t\tcurrentDir = parentDir;\n\t}\n}\n\nexport function hasProjectTrustInputs(cwd: string): boolean {\n\tlet currentDir = canonicalizePath(resolvePath(cwd));\n\tif (hasTrustRequiringConfigResources(currentDir)) {\n\t\treturn true;\n\t}\n\tconst userGlobalSkillsDir = canonicalizePath(resolvePath(join(getHomeDir(), \".agents\", \"skills\")));\n\tconst contextFileNames = [\"AGENTS.override.md\", \"AGENTS.md\", \"AGENTS.MD\", \"CLAUDE.md\", \"CLAUDE.MD\"];\n\n\twhile (true) {\n\t\tfor (const contextFileName of contextFileNames) {\n\t\t\tif (existsSync(join(currentDir, contextFileName))) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tconst skillsDir = canonicalizePath(resolvePath(join(currentDir, \".agents\", \"skills\")));\n\t\tif (skillsDir !== userGlobalSkillsDir && existsSync(skillsDir)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst parentDir = dirname(currentDir);\n\t\tif (parentDir === currentDir) {\n\t\t\treturn false;\n\t\t}\n\t\tcurrentDir = parentDir;\n\t}\n}\n\nexport class ProjectTrustStore {\n\tprivate trustPath: string;\n\n\tconstructor(agentDir: string) {\n\t\tthis.trustPath = join(resolvePath(agentDir), \"trust.json\");\n\t}\n\n\tget(cwd: string): ProjectTrustDecision {\n\t\treturn this.getEntry(cwd)?.decision ?? null;\n\t}\n\n\tgetEntry(cwd: string): ProjectTrustStoreEntry | null {\n\t\treturn withTrustFileLock(this.trustPath, () => {\n\t\t\tconst data = readTrustFile(this.trustPath);\n\t\t\treturn findNearestTrustEntry(data, cwd);\n\t\t});\n\t}\n\n\tset(cwd: string, decision: ProjectTrustDecision): void {\n\t\tthis.setMany([{ path: cwd, decision }]);\n\t}\n\n\tsetMany(decisions: ProjectTrustUpdate[]): void {\n\t\twithTrustFileLock(this.trustPath, () => {\n\t\t\tconst data = readTrustFile(this.trustPath);\n\t\t\tfor (const { path, decision } of decisions) {\n\t\t\t\tconst key = normalizeCwd(path);\n\t\t\t\tif (decision === null) {\n\t\t\t\t\tdelete data[key];\n\t\t\t\t} else {\n\t\t\t\t\tdata[key] = decision;\n\t\t\t\t}\n\t\t\t}\n\t\t\twriteTrustFile(this.trustPath, data);\n\t\t});\n\t}\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { type Args, parseArgs } from "./cli/args.ts";
2
- export { APP_NAME, APP_TITLE, CONFIG_DIR_NAME, CONFIG_DIR_NAMES, ENV_CODEX_FAST_MODE, getAgentConfigPaths, getAgentDir, getAgentDirs, getBundledInteractiveAssetPath, getChangelogPath, getDocsPath, getEnvNames, getEnvValue, getExamplesPath, getExportTemplateDir, getInteractiveAssetsDir, getLegacyAgentDir, getPackageDir, getPackageJsonPath, getProjectConfigDirs, getProjectConfigPaths, getReadmePath, getThemesDir, getUserConfigDirs, getUserConfigPaths, hasEnvValue, isBunBinary, LEGACY_CONFIG_DIR_NAME, LEGACY_ENV_PREFIX, PACKAGE_NAME, setEnvValue, VERSION, WORKFLOW_STAGE_SUBAGENT_GUARD_ENV, } from "./config.ts";
2
+ export { APP_NAME, APP_TITLE, CONFIG_DIR_NAME, CONFIG_DIR_NAMES, ENV_CODEX_FAST_MODE, getAgentConfigPaths, getAgentDir, getAgentDirs, getBundledInteractiveAssetPath, getChangelogPath, getDocsPath, getEnvNames, getEnvValue, getExamplesPath, getExportTemplateDir, getInteractiveAssetsDir, getLegacyAgentDir, getPackageDir, getPackageJsonPath, getProjectConfigDirs, getProjectConfigPaths, getReadmePath, getThemesDir, getUserConfigDirs, getUserConfigPaths, hasEnvValue, isBunBinary, LEGACY_CONFIG_DIR_NAME, LEGACY_ENV_PREFIX, PACKAGE_NAME, setEnvValue, VERSION, WORKFLOW_STAGE_SUBAGENT_GUARD_ENV, } from "./config.js";
3
3
  export { AgentSession, type AgentSessionConfig, type AgentSessionEvent, type AgentSessionEventListener, type CompactionReason, type ModelCycleResult, type ParsedSkillBlock, type PromptOptions, parseSkillBlock, type SessionStats, } from "./core/agent-session.ts";
4
4
  export { AuthStorage, readStoredCredential } from "./core/auth-storage.ts";
5
5
  export { type AuthStorageBackend, FileAuthStorageBackend, InMemoryAuthStorageBackend, } from "./core/auth-storage-backends.ts";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAE1B,OAAO,EAAa,SAAS,EAAE,MAAM,eAAe,CAAC;AACrD,eAAe;AACf,OAAO,EACN,QAAQ,EACR,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,8BAA8B,EAC9B,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,iBAAiB,E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BAAyB,CAAC;AAC9F,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC3G,OAAO,EAAE,oCAAoC,EAAE,MAAM,iBAAiB,CAAC;AACvE,kBAAkB;AAClB,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["// Core session management\n\nexport { type Args, parseArgs } from \"./cli/args.ts\";\n// Config paths\nexport {\n\tAPP_NAME,\n\tAPP_TITLE,\n\tCONFIG_DIR_NAME,\n\tCONFIG_DIR_NAMES,\n\tENV_CODEX_FAST_MODE,\n\tgetAgentConfigPaths,\n\tgetAgentDir,\n\tgetAgentDirs,\n\tgetBundledInteractiveAssetPath,\n\tgetChangelogPath,\n\tgetDocsPath,\n\tgetEnvNames,\n\tgetEnvValue,\n\tgetExamplesPath,\n\tgetExportTemplateDir,\n\tgetInteractiveAssetsDir,\n\tgetLegacyAgentDir,\n\tgetPackageDir,\n\tgetPackageJsonPath,\n\tgetProjectConfigDirs,\n\tgetProjectConfigPaths,\n\tgetReadmePath,\n\tgetThemesDir,\n\tgetUserConfigDirs,\n\tgetUserConfigPaths,\n\thasEnvValue,\n\tisBunBinary,\n\tLEGACY_CONFIG_DIR_NAME,\n\tLEGACY_ENV_PREFIX,\n\tPACKAGE_NAME,\n\tsetEnvValue,\n\tVERSION,\n\tWORKFLOW_STAGE_SUBAGENT_GUARD_ENV,\n} from \"./config.ts\";\nexport {\n\tAgentSession,\n\ttype AgentSessionConfig,\n\ttype AgentSessionEvent,\n\ttype AgentSessionEventListener,\n\ttype CompactionReason,\n\ttype ModelCycleResult,\n\ttype ParsedSkillBlock,\n\ttype PromptOptions,\n\tparseSkillBlock,\n\ttype SessionStats,\n} from \"./core/agent-session.ts\";\n// Auth and model runtime\nexport { AuthStorage, readStoredCredential } from \"./core/auth-storage.ts\";\nexport {\n\ttype AuthStorageBackend,\n\tFileAuthStorageBackend,\n\tInMemoryAuthStorageBackend,\n} from \"./core/auth-storage-backends.ts\";\nexport { type BashResult, executeBashWithOperations } from \"./core/bash-executor.ts\";\nexport { getBuiltinPackagePaths } from \"./core/builtin-packages.ts\";\nexport {\n\ttype CallbackActivityDescriptor,\n\ttype CallbackActivityKind,\n\trunCallback,\n\trunSynchronousCallback,\n} from \"./core/callback-activity.ts\";\n// Cloudflare AI Gateway over the Workers AI binding (no API token; see docs/providers.md)\nexport {\n\ttype AiGatewayBinding,\n\ttype AiGatewayBindingGateway,\n\ttype AiGatewayUniversalRequestLike,\n\tCLOUDFLARE_GATEWAY_BINDING_AUTH_SENTINEL,\n\tcreateGatewayBindingFetch,\n\ttype GatewayBindingFetchOptions,\n} from \"./core/cloudflare-gateway-binding.ts\";\nexport {\n\tCODEX_FAST_MODE_SERVICE_TIER,\n\ttype CodexFastModeResolvedSettings,\n\ttype CodexFastModeScope,\n\tformatCodexFastModeModelLabel,\n\tgetCodexFastModeScope,\n\thasSupportedCodexFastModeModel,\n\tisCodexFastModeCandidateModelId,\n\tisCodexFastModeEnabledForScope,\n\tisCodexFastModeSupportedModel,\n\tisCodexFastModeSupportedProvider,\n\tshouldApplyCodexFastMode,\n\tshouldApplyCodexFastModeForScope,\n\tusesChatGptCodexTransport,\n\tusesFirstPartyCodexRouting,\n\twithCodexFastModeHeaders,\n} from \"./core/codex-fast-mode.ts\";\nexport {\n\tCODEX_FAST_MODE_ORIGINATOR,\n\tCODEX_FAST_MODE_ROUTING_HEADER,\n} from \"./core/codex-fast-mode-transport.ts\";\n// Compaction\nexport {\n\ttype BranchPreparation,\n\ttype BranchSummaryResult,\n\ttype CollectEntriesResult,\n\ttype CompactedTranscript,\n\ttype CompactionPlannerModel,\n\ttype CompactionPlanOptions,\n\ttype CompactionRung,\n\ttype CompactionRungResult,\n\ttype CompactionRunRequest,\n\ttype CompactionUrgency,\n\tcalculateContextTokens,\n\tcollectEntriesForBranchSummary,\n\tDEFAULT_COMPACTION_SETTINGS,\n\testimateTokens,\n\ttype FileOperations,\n\ttype GenerateBranchSummaryOptions,\n\tgenerateBranchSummary,\n\tgetLastAssistantUsage,\n\ttype LineRange,\n\ttype PlannerAuth,\n\ttype PlannerBudget,\n\ttype PlannerLimitClass,\n\ttype PlannerOutcome,\n\tprepareBranchEntries,\n\tprepareCompactionBoundary,\n\trunVerbatimCompaction,\n\tserializeConversation,\n\tserializeConversationForCompaction,\n\tshouldCompact,\n\tstartNewContextWindow,\n\ttype VerbatimCompactionDetails,\n\ttype VerbatimCompactionParameters,\n\ttype VerbatimCompactionPreparation,\n\ttype VerbatimCompactionResult,\n} from \"./core/compaction/index.ts\";\nexport { createEventBus, type EventBus, type EventBusController } from \"./core/event-bus.ts\";\nexport { areExperimentalFeaturesEnabled } from \"./core/experimental.ts\";\nexport { sessionScopedExtensionState } from \"./core/extension-session-state.ts\";\nexport {\n\tparseFlattenedKeyPath,\n\treconstructFlattenedKeys,\n\tunflattenArgumentsWithSchema,\n} from \"./core/flattened-tool-arguments.ts\";\n// Footer data provider (git branch + extension statuses - data not otherwise available to extensions)\nexport type { ReadonlyFooterDataProvider } from \"./core/footer-data-provider.ts\";\nexport {\n\tRUNTIME_INTERCOM_GROUP_ENV,\n\treadRuntimeIntercomGroup,\n\truntimeIntercomGroupEnvKey,\n} from \"./core/intercom-runtime-group.ts\";\nexport { convertToLlm } from \"./core/messages.ts\";\nexport type {\n\tModelFallbackFailureKind,\n\tModelFallbackFailureSignal,\n\tModelFallbackFailureSource,\n} from \"./core/model-fallback-failures.ts\";\nexport {\n\terrorMessage,\n\tisRetryableModelFailure,\n\tisRetryableSameModelFailure,\n\tmodelFailureMessage,\n\tnormalizeModelFailureSignal,\n} from \"./core/model-fallback-failures.ts\";\nexport { ModelRegistry } from \"./core/model-registry.ts\";\nexport {\n\ttype CreateModelRuntimeOptions,\n\tCredentialSynchronizationError,\n\ttype CredentialSynchronizationOperation,\n\tModelRuntime,\n\ttype ModelRuntimeAuthOverrides,\n} from \"./core/model-runtime.js\";\nexport type {\n\tPackageManager,\n\tPathMetadata,\n\tProgressCallback,\n\tProgressEvent,\n\tResolvedPaths,\n\tResolvedResource,\n} from \"./core/package-manager.ts\";\nexport { DefaultPackageManager } from \"./core/package-manager.ts\";\nexport type {\n\tDefaultResourceLoaderInheritanceSnapshot,\n\tResourceCollision,\n\tResourceDiagnostic,\n\tResourceLoader,\n\tSkillCandidate,\n\tSkillCatalog,\n\tSkillCatalogCommand,\n\tSkillResolution,\n} from \"./core/resource-loader.ts\";\nexport {\n\tbuildSkillCatalog,\n\tDefaultResourceLoader,\n\tgetSkillCatalog,\n\tloadProjectContextFiles,\n} from \"./core/resource-loader.ts\";\nexport { nextRetryDecision, type RetryDecision, type RetryPolicySettings } from \"./core/retry-policy.ts\";\n// SDK for programmatic usage\nexport {\n\tAgentSessionRuntime,\n\ttype AgentSessionRuntimeDiagnostic,\n\ttype AgentSessionServices,\n\ttype CreateAgentSessionFromServicesOptions,\n\ttype CreateAgentSessionOptions,\n\ttype CreateAgentSessionResult,\n\ttype CreateAgentSessionRuntimeFactory,\n\ttype CreateAgentSessionRuntimeResult,\n\ttype CreateAgentSessionServicesOptions,\n\t// Factory\n\tcreateAgentSession,\n\tcreateAgentSessionFromServices,\n\tcreateAgentSessionRuntime,\n\tcreateAgentSessionServices,\n\tcreateBashTool,\n\t// Tool factories (for custom cwd)\n\tcreateCodingTools,\n\tcreateEditTool,\n\tcreateFindTool,\n\tcreateLsTool,\n\tcreatePowerShellTool,\n\tcreateReadOnlyTools,\n\tcreateReadTool,\n\tcreateSearchTool,\n\tcreateStructuredOutputCapture,\n\tcreateStructuredOutputTool,\n\tcreateWriteTool,\n\ttype JsonObject,\n\ttype JsonPrimitive,\n\ttype JsonValue,\n\ttype MessageEndEvent,\n\ttype MessageStartEvent,\n\ttype MessageUpdateEvent,\n\ttype PromptTemplate,\n\tSTRUCTURED_OUTPUT_TOOL_NAME,\n\ttype StructuredOutputCapture,\n\ttype StructuredOutputFileCapture,\n\ttype StructuredOutputToolOptions,\n\ttype ToolExecutionEndEvent,\n\ttype ToolExecutionStartEvent,\n\ttype ToolExecutionUpdateEvent,\n} from \"./core/sdk.ts\";\nexport {\n\ttype BranchSummaryEntry,\n\tbuildContextEntries,\n\tbuildSessionContext,\n\ttype CompactionEntry,\n\tCURRENT_SESSION_VERSION,\n\ttype CustomEntry,\n\ttype CustomMessageEntry,\n\ttype FileEntry,\n\tgetLatestCompactionBoundaryEntry,\n\ttype ModelChangeEntry,\n\tmigrateSessionEntries,\n\ttype NewSessionOptions,\n\tparseSessionEntries,\n\ttype SessionContext,\n\ttype SessionEntry,\n\ttype SessionEntryBase,\n\ttype SessionHeader,\n\ttype SessionInfo,\n\ttype SessionInfoEntry,\n\tSessionManager,\n\ttype SessionMessageEntry,\n\ttype SessionNameState,\n\ttype SessionTreeNode,\n\ttype SessionWorkflowMetadata,\n\tsessionEntryToContextMessages,\n\ttype ThinkingLevelChangeEntry,\n} from \"./core/session-manager.ts\";\nexport {\n\tWORKFLOW_SESSION_METADATA_ENV,\n\tworkflowSessionMetadataFromEnv,\n} from \"./core/session-manager-classification.ts\";\nexport type { DefaultProjectTrust } from \"./core/settings-manager.ts\";\nexport {\n\ttype CompactionSettings,\n\ttype ImageSettings,\n\ttype PackageSource,\n\ttype RetrySettings,\n\tSettingsManager,\n\ttype SettingsManagerCreateOptions,\n} from \"./core/settings-manager.ts\";\n// Skills\nexport {\n\tformatSkillsForPrompt,\n\ttype LoadSkillsFromDirOptions,\n\ttype LoadSkillsResult,\n\tloadSkills,\n\tloadSkillsFromDir,\n\ttype Skill,\n\ttype SkillFrontmatter,\n} from \"./core/skills.ts\";\nexport { createSyntheticSourceInfo } from \"./core/source-info.ts\";\nexport { type EditDiffResult, generateDiffString, generateUnifiedPatch } from \"./core/tools/edit-diff.ts\";\n// Builtin tool definitions reusable by first-party extensions (e.g. workflows\n// invoking the structured ask_user_question UI deterministically).\n// Tools\nexport {\n\tBASH_SHELL_PRESENTATION,\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tbashToolSystemPromptContribution,\n\tcreateAskUserQuestionToolDefinition,\n\tcreateBashToolDefinition,\n\tcreateEditToolDefinition,\n\tcreateFindToolDefinition,\n\tcreateLocalBashOperations,\n\tcreateLocalPowerShellOperations,\n\tcreateLsToolDefinition,\n\tcreatePowerShellToolDefinition,\n\tcreateReadToolDefinition,\n\tcreateSearchToolDefinition,\n\tcreateWriteToolDefinition,\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n\teditToolSystemPromptContribution,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n\tfindToolSystemPromptContribution,\n\tformatSize,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n\tlsToolSystemPromptContribution,\n\ttype PowerShellOperations,\n\ttype PowerShellSpawnContext,\n\ttype PowerShellSpawnHook,\n\ttype PowerShellToolDetails,\n\ttype PowerShellToolInput,\n\ttype PowerShellToolOptions,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n\treadToolSystemPromptContribution,\n\ttype SearchToolDetails,\n\ttype SearchToolInput,\n\ttype SearchToolOptions,\n\ttype ShellToolPresentation,\n\tsearchToolSystemPromptContribution,\n\ttype ToolsOptions,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n\ttype WriteOperations,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n\twithFileMutationQueue,\n\twriteToolSystemPromptContribution,\n} from \"./core/tools/index.ts\";\nexport {\n\thasProjectTrustInputs,\n\thasTrustRequiringProjectResources,\n\ttype ProjectTrustDecision,\n\tProjectTrustStore,\n\ttype ProjectTrustStoreEntry,\n\ttype ProjectTrustUpdate,\n\tTRUST_REQUIRING_PROJECT_CONFIG_RESOURCES,\n} from \"./core/trust-manager.ts\";\nexport { StringEnum, type StringEnumOptions } from \"./core/typebox-compat.ts\";\nexport * from \"./index-extensions.js\";\n// Main entry point\nexport { type MainOptions, main } from \"./main.ts\";\nexport {\n\tInteractiveMode,\n\ttype InteractiveModeOptions,\n\ttype ModelInfo,\n\ttype PrintModeOptions,\n\tRpcClient,\n\ttype RpcClientOptions,\n\ttype RpcCommand,\n\ttype RpcEvent,\n\ttype RpcEventListener,\n\ttype RpcExtensionUIRequest,\n\ttype RpcExtensionUIResponse,\n\ttype RpcResponse,\n\ttype RpcSessionState,\n\trunPrintMode,\n\trunRpcMode,\n} from \"./modes/index.ts\";\n// UI components for extensions\nexport {\n\tArminComponent,\n\tAssistantMessageComponent,\n\tBashExecutionComponent,\n\tBorderedLoader,\n\tBranchSummaryMessageComponent,\n\ttype ChatMessageEntry,\n\ttype ChatMessageRenderOptions,\n\t// Internal host seam for bundled workflow stage chat; not yet a stable extension API.\n\tChatSessionHost,\n\ttype ChatSessionHostBashRequest,\n\ttype ChatSessionHostCommands,\n\ttype ChatSessionHostEntry,\n\ttype ChatSessionHostOpts,\n\ttype ChatSessionHostStyle,\n\ttype ChatSessionSubmitMode,\n\tChatTranscriptComponent,\n\ttype ChatTranscriptEntryLike,\n\ttype ChatTranscriptRenderer,\n\ttype ChatTranscriptRole,\n\tCustomEditor,\n\tCustomEntryComponent,\n\tCustomMessageComponent,\n\tchatEntriesFromAgentMessages,\n\tDynamicBorder,\n\tExtensionEditorComponent,\n\tExtensionInputComponent,\n\tExtensionSelectorComponent,\n\tFooterComponent,\n\tkeyHint,\n\tkeyHintIfBound,\n\tkeyText,\n\tLiveChatEntriesController,\n\tLoginDialogComponent,\n\tModelSelectorComponent,\n\tOAuthSelectorComponent,\n\ttype RenderDiffOptions,\n\trawKeyHint,\n\trenderChatMessageEntry,\n\trenderDiff,\n\tScrollableChatTranscriptComponent,\n\tScrollableComponentViewport,\n\tSessionSelectorComponent,\n\ttype SettingsCallbacks,\n\ttype SettingsConfig,\n\tSettingsSelectorComponent,\n\tShowImagesSelectorComponent,\n\tSkillInvocationMessageComponent,\n\tThemeSelectorComponent,\n\tThinkingSelectorComponent,\n\tToolExecutionComponent,\n\ttype ToolExecutionOptions,\n\tTRANSCRIPT_JUMP_TO_END_URL,\n\tTranscriptFollowIndicator,\n\tTreeSelectorComponent,\n\ttruncateToVisualLines,\n\tUsageMeterComponent,\n\tUserMessageComponent,\n\tUserMessageSelectorComponent,\n\ttype VisualTruncateResult,\n\tWorkingStatusComponent,\n\ttype WorkingStatusComponentOptions,\n} from \"./modes/interactive/components/index.ts\";\n// Theme utilities for custom tools and extensions\nexport {\n\tgetLanguageFromPath,\n\tgetMarkdownTheme,\n\tgetSelectListTheme,\n\tgetSettingsListTheme,\n\thighlightCode,\n\tinitTheme,\n\tTheme,\n\ttype ThemeColor,\n} from \"./modes/interactive/theme/theme.ts\";\n// Run modes for programmatic SDK usage\nexport { pickWhimsicalWorkingMessage } from \"./modes/interactive/whimsical-messages.ts\";\n// Experimental Harness factory\nexport {\n\ttype BuildCodingAgentHarnessSystemPromptOptions,\n\tbuildCodingAgentHarnessSystemPrompt,\n\ttype CodingAgentHarnessTool,\n\ttype CreateCodingAgentHarnessOptions,\n\tcreateCodingAgentHarness,\n} from \"./server/create-harness.ts\";\nexport { createChildProcessEnvironment } from \"./utils/child-process.ts\";\n// Clipboard utilities\nexport { copyToClipboard } from \"./utils/clipboard.ts\";\nexport { parseFrontmatter, stripFrontmatter } from \"./utils/frontmatter.ts\";\nexport {\n\tisSafeFsWatchPathError,\n\tisUnsafeWindowsShortPath,\n\tresolveNativeWatchPath,\n\tSAFE_FS_WATCH_CANONICALIZATION_FAILED,\n\tSAFE_FS_WATCH_UNSAFE_WINDOWS_SHORT_PATH,\n\ttype SafeFsWatchErrorCode,\n\ttype SafeFsWatchPathError,\n\twatchWithErrorHandler,\n} from \"./utils/fs-watch.ts\";\nexport { createGitEnvironment, GIT_LOCAL_ENV_VARS } from \"./utils/git-env.ts\";\nexport { convertToPng } from \"./utils/image-convert.ts\";\nexport { formatDimensionNote, type ResizedImage, resizeImage } from \"./utils/image-resize.ts\";\nexport { INTERACTIVE_ENGINE_ENV_VARS, scrubInteractiveEngineEnv } from \"./utils/interactive-engine-env.ts\";\nexport { detectSupportedImageMimeTypeFromFile } from \"./utils/mime.ts\";\n// Shell utilities\nexport { getPowerShellConfig, getShellConfig } from \"./utils/shell.ts\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAE1B,OAAO,EAAa,SAAS,EAAE,MAAM,eAAe,CAAC;AACrD,eAAe;AACf,OAAO,EACN,QAAQ,EACR,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,YAAY,EACZ,8BAA8B,EAC9B,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,iBAAiB,EACjB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,WAAW,EACX,sBAAsB,EACtB,iBAAiB,EACjB,YAAY,EACZ,WAAW,EACX,OAAO,EACP,iCAAiC,GACjC,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,YAAY,EAQZ,eAAe,GAEf,MAAM,yBAAyB,CAAC;AACjC,yBAAyB;AACzB,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAEN,sBAAsB,EACtB,0BAA0B,GAC1B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAmB,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACrF,OAAO,EAAE,sBAAsB,EAAE,MAA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AAmB,EACnB,oBAAoB,EACpB,4BAA4B,EAE5B,sBAAsB,GAEtB,MAAM,yCAAyC,CAAC;AACjD,kDAAkD;AAClD,OAAO,EACN,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,SAAS,EACT,KAAK,GAEL,MAAM,oCAAoC,CAAC;AAC5C,uCAAuC;AACvC,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,+BAA+B;AAC/B,OAAO,EAEN,mCAAmC,EAGnC,wBAAwB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAAE,MAAM,0BAA0B,CAAC;AACzE,sBAAsB;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EACN,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACtB,qCAAqC,EACrC,uCAAuC,EAGvC,qBAAqB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAqB,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC9F,OAAO,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC3G,OAAO,EAAE,oCAAoC,EAAE,MAAM,iBAAiB,CAAC;AACvE,kBAAkB;AAClB,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["// Core session management\n\nexport { type Args, parseArgs } from \"./cli/args.ts\";\n// Config paths\nexport {\n\tAPP_NAME,\n\tAPP_TITLE,\n\tCONFIG_DIR_NAME,\n\tCONFIG_DIR_NAMES,\n\tENV_CODEX_FAST_MODE,\n\tgetAgentConfigPaths,\n\tgetAgentDir,\n\tgetAgentDirs,\n\tgetBundledInteractiveAssetPath,\n\tgetChangelogPath,\n\tgetDocsPath,\n\tgetEnvNames,\n\tgetEnvValue,\n\tgetExamplesPath,\n\tgetExportTemplateDir,\n\tgetInteractiveAssetsDir,\n\tgetLegacyAgentDir,\n\tgetPackageDir,\n\tgetPackageJsonPath,\n\tgetProjectConfigDirs,\n\tgetProjectConfigPaths,\n\tgetReadmePath,\n\tgetThemesDir,\n\tgetUserConfigDirs,\n\tgetUserConfigPaths,\n\thasEnvValue,\n\tisBunBinary,\n\tLEGACY_CONFIG_DIR_NAME,\n\tLEGACY_ENV_PREFIX,\n\tPACKAGE_NAME,\n\tsetEnvValue,\n\tVERSION,\n\tWORKFLOW_STAGE_SUBAGENT_GUARD_ENV,\n} from \"./config.js\";\nexport {\n\tAgentSession,\n\ttype AgentSessionConfig,\n\ttype AgentSessionEvent,\n\ttype AgentSessionEventListener,\n\ttype CompactionReason,\n\ttype ModelCycleResult,\n\ttype ParsedSkillBlock,\n\ttype PromptOptions,\n\tparseSkillBlock,\n\ttype SessionStats,\n} from \"./core/agent-session.ts\";\n// Auth and model runtime\nexport { AuthStorage, readStoredCredential } from \"./core/auth-storage.ts\";\nexport {\n\ttype AuthStorageBackend,\n\tFileAuthStorageBackend,\n\tInMemoryAuthStorageBackend,\n} from \"./core/auth-storage-backends.ts\";\nexport { type BashResult, executeBashWithOperations } from \"./core/bash-executor.ts\";\nexport { getBuiltinPackagePaths } from \"./core/builtin-packages.ts\";\nexport {\n\ttype CallbackActivityDescriptor,\n\ttype CallbackActivityKind,\n\trunCallback,\n\trunSynchronousCallback,\n} from \"./core/callback-activity.ts\";\n// Cloudflare AI Gateway over the Workers AI binding (no API token; see docs/providers.md)\nexport {\n\ttype AiGatewayBinding,\n\ttype AiGatewayBindingGateway,\n\ttype AiGatewayUniversalRequestLike,\n\tCLOUDFLARE_GATEWAY_BINDING_AUTH_SENTINEL,\n\tcreateGatewayBindingFetch,\n\ttype GatewayBindingFetchOptions,\n} from \"./core/cloudflare-gateway-binding.ts\";\nexport {\n\tCODEX_FAST_MODE_SERVICE_TIER,\n\ttype CodexFastModeResolvedSettings,\n\ttype CodexFastModeScope,\n\tformatCodexFastModeModelLabel,\n\tgetCodexFastModeScope,\n\thasSupportedCodexFastModeModel,\n\tisCodexFastModeCandidateModelId,\n\tisCodexFastModeEnabledForScope,\n\tisCodexFastModeSupportedModel,\n\tisCodexFastModeSupportedProvider,\n\tshouldApplyCodexFastMode,\n\tshouldApplyCodexFastModeForScope,\n\tusesChatGptCodexTransport,\n\tusesFirstPartyCodexRouting,\n\twithCodexFastModeHeaders,\n} from \"./core/codex-fast-mode.ts\";\nexport {\n\tCODEX_FAST_MODE_ORIGINATOR,\n\tCODEX_FAST_MODE_ROUTING_HEADER,\n} from \"./core/codex-fast-mode-transport.ts\";\n// Compaction\nexport {\n\ttype BranchPreparation,\n\ttype BranchSummaryResult,\n\ttype CollectEntriesResult,\n\ttype CompactedTranscript,\n\ttype CompactionPlannerModel,\n\ttype CompactionPlanOptions,\n\ttype CompactionRung,\n\ttype CompactionRungResult,\n\ttype CompactionRunRequest,\n\ttype CompactionUrgency,\n\tcalculateContextTokens,\n\tcollectEntriesForBranchSummary,\n\tDEFAULT_COMPACTION_SETTINGS,\n\testimateTokens,\n\ttype FileOperations,\n\ttype GenerateBranchSummaryOptions,\n\tgenerateBranchSummary,\n\tgetLastAssistantUsage,\n\ttype LineRange,\n\ttype PlannerAuth,\n\ttype PlannerBudget,\n\ttype PlannerLimitClass,\n\ttype PlannerOutcome,\n\tprepareBranchEntries,\n\tprepareCompactionBoundary,\n\trunVerbatimCompaction,\n\tserializeConversation,\n\tserializeConversationForCompaction,\n\tshouldCompact,\n\tstartNewContextWindow,\n\ttype VerbatimCompactionDetails,\n\ttype VerbatimCompactionParameters,\n\ttype VerbatimCompactionPreparation,\n\ttype VerbatimCompactionResult,\n} from \"./core/compaction/index.ts\";\nexport { createEventBus, type EventBus, type EventBusController } from \"./core/event-bus.ts\";\nexport { areExperimentalFeaturesEnabled } from \"./core/experimental.ts\";\nexport { sessionScopedExtensionState } from \"./core/extension-session-state.ts\";\nexport {\n\tparseFlattenedKeyPath,\n\treconstructFlattenedKeys,\n\tunflattenArgumentsWithSchema,\n} from \"./core/flattened-tool-arguments.ts\";\n// Footer data provider (git branch + extension statuses - data not otherwise available to extensions)\nexport type { ReadonlyFooterDataProvider } from \"./core/footer-data-provider.ts\";\nexport {\n\tRUNTIME_INTERCOM_GROUP_ENV,\n\treadRuntimeIntercomGroup,\n\truntimeIntercomGroupEnvKey,\n} from \"./core/intercom-runtime-group.ts\";\nexport { convertToLlm } from \"./core/messages.ts\";\nexport type {\n\tModelFallbackFailureKind,\n\tModelFallbackFailureSignal,\n\tModelFallbackFailureSource,\n} from \"./core/model-fallback-failures.ts\";\nexport {\n\terrorMessage,\n\tisRetryableModelFailure,\n\tisRetryableSameModelFailure,\n\tmodelFailureMessage,\n\tnormalizeModelFailureSignal,\n} from \"./core/model-fallback-failures.ts\";\nexport { ModelRegistry } from \"./core/model-registry.ts\";\nexport {\n\ttype CreateModelRuntimeOptions,\n\tCredentialSynchronizationError,\n\ttype CredentialSynchronizationOperation,\n\tModelRuntime,\n\ttype ModelRuntimeAuthOverrides,\n} from \"./core/model-runtime.js\";\nexport type {\n\tPackageManager,\n\tPathMetadata,\n\tProgressCallback,\n\tProgressEvent,\n\tResolvedPaths,\n\tResolvedResource,\n} from \"./core/package-manager.ts\";\nexport { DefaultPackageManager } from \"./core/package-manager.ts\";\nexport type {\n\tDefaultResourceLoaderInheritanceSnapshot,\n\tResourceCollision,\n\tResourceDiagnostic,\n\tResourceLoader,\n\tSkillCandidate,\n\tSkillCatalog,\n\tSkillCatalogCommand,\n\tSkillResolution,\n} from \"./core/resource-loader.ts\";\nexport {\n\tbuildSkillCatalog,\n\tDefaultResourceLoader,\n\tgetSkillCatalog,\n\tloadProjectContextFiles,\n} from \"./core/resource-loader.ts\";\nexport { nextRetryDecision, type RetryDecision, type RetryPolicySettings } from \"./core/retry-policy.ts\";\n// SDK for programmatic usage\nexport {\n\tAgentSessionRuntime,\n\ttype AgentSessionRuntimeDiagnostic,\n\ttype AgentSessionServices,\n\ttype CreateAgentSessionFromServicesOptions,\n\ttype CreateAgentSessionOptions,\n\ttype CreateAgentSessionResult,\n\ttype CreateAgentSessionRuntimeFactory,\n\ttype CreateAgentSessionRuntimeResult,\n\ttype CreateAgentSessionServicesOptions,\n\t// Factory\n\tcreateAgentSession,\n\tcreateAgentSessionFromServices,\n\tcreateAgentSessionRuntime,\n\tcreateAgentSessionServices,\n\tcreateBashTool,\n\t// Tool factories (for custom cwd)\n\tcreateCodingTools,\n\tcreateEditTool,\n\tcreateFindTool,\n\tcreateLsTool,\n\tcreatePowerShellTool,\n\tcreateReadOnlyTools,\n\tcreateReadTool,\n\tcreateSearchTool,\n\tcreateStructuredOutputCapture,\n\tcreateStructuredOutputTool,\n\tcreateWriteTool,\n\ttype JsonObject,\n\ttype JsonPrimitive,\n\ttype JsonValue,\n\ttype MessageEndEvent,\n\ttype MessageStartEvent,\n\ttype MessageUpdateEvent,\n\ttype PromptTemplate,\n\tSTRUCTURED_OUTPUT_TOOL_NAME,\n\ttype StructuredOutputCapture,\n\ttype StructuredOutputFileCapture,\n\ttype StructuredOutputToolOptions,\n\ttype ToolExecutionEndEvent,\n\ttype ToolExecutionStartEvent,\n\ttype ToolExecutionUpdateEvent,\n} from \"./core/sdk.ts\";\nexport {\n\ttype BranchSummaryEntry,\n\tbuildContextEntries,\n\tbuildSessionContext,\n\ttype CompactionEntry,\n\tCURRENT_SESSION_VERSION,\n\ttype CustomEntry,\n\ttype CustomMessageEntry,\n\ttype FileEntry,\n\tgetLatestCompactionBoundaryEntry,\n\ttype ModelChangeEntry,\n\tmigrateSessionEntries,\n\ttype NewSessionOptions,\n\tparseSessionEntries,\n\ttype SessionContext,\n\ttype SessionEntry,\n\ttype SessionEntryBase,\n\ttype SessionHeader,\n\ttype SessionInfo,\n\ttype SessionInfoEntry,\n\tSessionManager,\n\ttype SessionMessageEntry,\n\ttype SessionNameState,\n\ttype SessionTreeNode,\n\ttype SessionWorkflowMetadata,\n\tsessionEntryToContextMessages,\n\ttype ThinkingLevelChangeEntry,\n} from \"./core/session-manager.ts\";\nexport {\n\tWORKFLOW_SESSION_METADATA_ENV,\n\tworkflowSessionMetadataFromEnv,\n} from \"./core/session-manager-classification.ts\";\nexport type { DefaultProjectTrust } from \"./core/settings-manager.ts\";\nexport {\n\ttype CompactionSettings,\n\ttype ImageSettings,\n\ttype PackageSource,\n\ttype RetrySettings,\n\tSettingsManager,\n\ttype SettingsManagerCreateOptions,\n} from \"./core/settings-manager.ts\";\n// Skills\nexport {\n\tformatSkillsForPrompt,\n\ttype LoadSkillsFromDirOptions,\n\ttype LoadSkillsResult,\n\tloadSkills,\n\tloadSkillsFromDir,\n\ttype Skill,\n\ttype SkillFrontmatter,\n} from \"./core/skills.ts\";\nexport { createSyntheticSourceInfo } from \"./core/source-info.ts\";\nexport { type EditDiffResult, generateDiffString, generateUnifiedPatch } from \"./core/tools/edit-diff.ts\";\n// Builtin tool definitions reusable by first-party extensions (e.g. workflows\n// invoking the structured ask_user_question UI deterministically).\n// Tools\nexport {\n\tBASH_SHELL_PRESENTATION,\n\ttype BashOperations,\n\ttype BashSpawnContext,\n\ttype BashSpawnHook,\n\ttype BashToolDetails,\n\ttype BashToolInput,\n\ttype BashToolOptions,\n\tbashToolSystemPromptContribution,\n\tcreateAskUserQuestionToolDefinition,\n\tcreateBashToolDefinition,\n\tcreateEditToolDefinition,\n\tcreateFindToolDefinition,\n\tcreateLocalBashOperations,\n\tcreateLocalPowerShellOperations,\n\tcreateLsToolDefinition,\n\tcreatePowerShellToolDefinition,\n\tcreateReadToolDefinition,\n\tcreateSearchToolDefinition,\n\tcreateWriteToolDefinition,\n\tDEFAULT_MAX_BYTES,\n\tDEFAULT_MAX_LINES,\n\ttype EditOperations,\n\ttype EditToolDetails,\n\ttype EditToolInput,\n\ttype EditToolOptions,\n\teditToolSystemPromptContribution,\n\ttype FindOperations,\n\ttype FindToolDetails,\n\ttype FindToolInput,\n\ttype FindToolOptions,\n\tfindToolSystemPromptContribution,\n\tformatSize,\n\ttype LsOperations,\n\ttype LsToolDetails,\n\ttype LsToolInput,\n\ttype LsToolOptions,\n\tlsToolSystemPromptContribution,\n\ttype PowerShellOperations,\n\ttype PowerShellSpawnContext,\n\ttype PowerShellSpawnHook,\n\ttype PowerShellToolDetails,\n\ttype PowerShellToolInput,\n\ttype PowerShellToolOptions,\n\ttype ReadOperations,\n\ttype ReadToolDetails,\n\ttype ReadToolInput,\n\ttype ReadToolOptions,\n\treadToolSystemPromptContribution,\n\ttype SearchToolDetails,\n\ttype SearchToolInput,\n\ttype SearchToolOptions,\n\ttype ShellToolPresentation,\n\tsearchToolSystemPromptContribution,\n\ttype ToolsOptions,\n\ttype TruncationOptions,\n\ttype TruncationResult,\n\ttruncateHead,\n\ttruncateLine,\n\ttruncateTail,\n\ttype WriteOperations,\n\ttype WriteToolInput,\n\ttype WriteToolOptions,\n\twithFileMutationQueue,\n\twriteToolSystemPromptContribution,\n} from \"./core/tools/index.ts\";\nexport {\n\thasProjectTrustInputs,\n\thasTrustRequiringProjectResources,\n\ttype ProjectTrustDecision,\n\tProjectTrustStore,\n\ttype ProjectTrustStoreEntry,\n\ttype ProjectTrustUpdate,\n\tTRUST_REQUIRING_PROJECT_CONFIG_RESOURCES,\n} from \"./core/trust-manager.ts\";\nexport { StringEnum, type StringEnumOptions } from \"./core/typebox-compat.ts\";\nexport * from \"./index-extensions.js\";\n// Main entry point\nexport { type MainOptions, main } from \"./main.ts\";\nexport {\n\tInteractiveMode,\n\ttype InteractiveModeOptions,\n\ttype ModelInfo,\n\ttype PrintModeOptions,\n\tRpcClient,\n\ttype RpcClientOptions,\n\ttype RpcCommand,\n\ttype RpcEvent,\n\ttype RpcEventListener,\n\ttype RpcExtensionUIRequest,\n\ttype RpcExtensionUIResponse,\n\ttype RpcResponse,\n\ttype RpcSessionState,\n\trunPrintMode,\n\trunRpcMode,\n} from \"./modes/index.ts\";\n// UI components for extensions\nexport {\n\tArminComponent,\n\tAssistantMessageComponent,\n\tBashExecutionComponent,\n\tBorderedLoader,\n\tBranchSummaryMessageComponent,\n\ttype ChatMessageEntry,\n\ttype ChatMessageRenderOptions,\n\t// Internal host seam for bundled workflow stage chat; not yet a stable extension API.\n\tChatSessionHost,\n\ttype ChatSessionHostBashRequest,\n\ttype ChatSessionHostCommands,\n\ttype ChatSessionHostEntry,\n\ttype ChatSessionHostOpts,\n\ttype ChatSessionHostStyle,\n\ttype ChatSessionSubmitMode,\n\tChatTranscriptComponent,\n\ttype ChatTranscriptEntryLike,\n\ttype ChatTranscriptRenderer,\n\ttype ChatTranscriptRole,\n\tCustomEditor,\n\tCustomEntryComponent,\n\tCustomMessageComponent,\n\tchatEntriesFromAgentMessages,\n\tDynamicBorder,\n\tExtensionEditorComponent,\n\tExtensionInputComponent,\n\tExtensionSelectorComponent,\n\tFooterComponent,\n\tkeyHint,\n\tkeyHintIfBound,\n\tkeyText,\n\tLiveChatEntriesController,\n\tLoginDialogComponent,\n\tModelSelectorComponent,\n\tOAuthSelectorComponent,\n\ttype RenderDiffOptions,\n\trawKeyHint,\n\trenderChatMessageEntry,\n\trenderDiff,\n\tScrollableChatTranscriptComponent,\n\tScrollableComponentViewport,\n\tSessionSelectorComponent,\n\ttype SettingsCallbacks,\n\ttype SettingsConfig,\n\tSettingsSelectorComponent,\n\tShowImagesSelectorComponent,\n\tSkillInvocationMessageComponent,\n\tThemeSelectorComponent,\n\tThinkingSelectorComponent,\n\tToolExecutionComponent,\n\ttype ToolExecutionOptions,\n\tTRANSCRIPT_JUMP_TO_END_URL,\n\tTranscriptFollowIndicator,\n\tTreeSelectorComponent,\n\ttruncateToVisualLines,\n\tUsageMeterComponent,\n\tUserMessageComponent,\n\tUserMessageSelectorComponent,\n\ttype VisualTruncateResult,\n\tWorkingStatusComponent,\n\ttype WorkingStatusComponentOptions,\n} from \"./modes/interactive/components/index.ts\";\n// Theme utilities for custom tools and extensions\nexport {\n\tgetLanguageFromPath,\n\tgetMarkdownTheme,\n\tgetSelectListTheme,\n\tgetSettingsListTheme,\n\thighlightCode,\n\tinitTheme,\n\tTheme,\n\ttype ThemeColor,\n} from \"./modes/interactive/theme/theme.ts\";\n// Run modes for programmatic SDK usage\nexport { pickWhimsicalWorkingMessage } from \"./modes/interactive/whimsical-messages.ts\";\n// Experimental Harness factory\nexport {\n\ttype BuildCodingAgentHarnessSystemPromptOptions,\n\tbuildCodingAgentHarnessSystemPrompt,\n\ttype CodingAgentHarnessTool,\n\ttype CreateCodingAgentHarnessOptions,\n\tcreateCodingAgentHarness,\n} from \"./server/create-harness.ts\";\nexport { createChildProcessEnvironment } from \"./utils/child-process.ts\";\n// Clipboard utilities\nexport { copyToClipboard } from \"./utils/clipboard.ts\";\nexport { parseFrontmatter, stripFrontmatter } from \"./utils/frontmatter.ts\";\nexport {\n\tisSafeFsWatchPathError,\n\tisUnsafeWindowsShortPath,\n\tresolveNativeWatchPath,\n\tSAFE_FS_WATCH_CANONICALIZATION_FAILED,\n\tSAFE_FS_WATCH_UNSAFE_WINDOWS_SHORT_PATH,\n\ttype SafeFsWatchErrorCode,\n\ttype SafeFsWatchPathError,\n\twatchWithErrorHandler,\n} from \"./utils/fs-watch.ts\";\nexport { createGitEnvironment, GIT_LOCAL_ENV_VARS } from \"./utils/git-env.ts\";\nexport { convertToPng } from \"./utils/image-convert.ts\";\nexport { formatDimensionNote, type ResizedImage, resizeImage } from \"./utils/image-resize.ts\";\nexport { INTERACTIVE_ENGINE_ENV_VARS, scrubInteractiveEngineEnv } from \"./utils/interactive-engine-env.ts\";\nexport { detectSupportedImageMimeTypeFromFile } from \"./utils/mime.ts\";\n// Shell utilities\nexport { getPowerShellConfig, getShellConfig } from \"./utils/shell.ts\";\n"]}
@@ -17,6 +17,16 @@ export interface ComputeDeferExtensionsInput {
17
17
  provider?: string;
18
18
  model?: string;
19
19
  }
20
+ export interface ComputeInteractiveEngineResourceDeferralInput {
21
+ interactiveEngineChild: boolean;
22
+ hasSessionStartEvent: boolean;
23
+ shouldResolveProjectTrust: boolean;
24
+ storedProjectTrust: boolean | null;
25
+ resolvedExtensionPathCount: number;
26
+ resolvedResourcePathCount: number;
27
+ hasSystemPromptInput: boolean;
28
+ unknownFlagCount: number;
29
+ }
20
30
  export interface ComputeStartupInputCaptureInput {
21
31
  appMode: AppMode;
22
32
  stdinIsTTY: boolean;
@@ -29,5 +39,11 @@ export interface ComputeStartupInputCaptureInput {
29
39
  }
30
40
  export declare function computeStartupInputCaptureEnabled(input: ComputeStartupInputCaptureInput): boolean;
31
41
  export declare function computeDeferExtensions(input: ComputeDeferExtensionsInput): boolean;
42
+ /**
43
+ * The isolated engine may bind its minimal RPC session before loading optional
44
+ * bundled resources. User-selected paths and trust-sensitive startup stay
45
+ * synchronous because they can affect the first visible or interactive state.
46
+ */
47
+ export declare function computeInteractiveEngineResourceDeferral(input: ComputeInteractiveEngineResourceDeferralInput): boolean;
32
48
  export declare function formatScopedModelList(scopedModels: ScopedModel[]): string;
33
49
  //# sourceMappingURL=main-deferred-startup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"main-deferred-startup.d.ts","sourceRoot":"","sources":["../src/main-deferred-startup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,WAAW,2BAA2B;IAC3C,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,IAAI,CAAC,EA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AAC;IAClD,0BAA0B,EAAE,MAAM,CAAC;IACnC,yBAAyB,EAAE,MAAM,CAAC;IAClC,uBAAuB,EAAE,MAAM,CAAC;CAChC;AAED,wBAAgB,iCAAiC,CAAC,KAAK,EAAE,+BAA+B,GAAG,OAAO,CA0BjG;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO,CAelF;AAED;;;;GAIG;AACH,wBAAgB,wCAAwC,CACvD,KAAK,EAAE,6CAA6C,GAClD,OAAO,CAUT;AAED,wBAAgB,qBAAqB,CAAC,YAAY,EAAE,WAAW,EAAE,GAAG,MAAM,CAOzE"}
@@ -38,6 +38,20 @@ export function computeDeferExtensions(input) {
38
38
  input.model === undefined &&
39
39
  input.unknownFlagCount === 0);
40
40
  }
41
+ /**
42
+ * The isolated engine may bind its minimal RPC session before loading optional
43
+ * bundled resources. User-selected paths and trust-sensitive startup stay
44
+ * synchronous because they can affect the first visible or interactive state.
45
+ */
46
+ export function computeInteractiveEngineResourceDeferral(input) {
47
+ return (input.interactiveEngineChild &&
48
+ !input.hasSessionStartEvent &&
49
+ (!input.shouldResolveProjectTrust || input.storedProjectTrust !== null) &&
50
+ input.resolvedExtensionPathCount === 0 &&
51
+ input.resolvedResourcePathCount === 0 &&
52
+ !input.hasSystemPromptInput &&
53
+ input.unknownFlagCount === 0);
54
+ }
41
55
  export function formatScopedModelList(scopedModels) {
42
56
  return scopedModels
43
57
  .map((scoped) => {
@@ -1 +1 @@
1
- {"version":3,"file":"main-deferred-startup.js","sourceRoot":"","sources":["../src/main-deferred-startup.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AA0ChE,MAAM,UAAU,iCAAiC,CAAC,KAAsC;IACvF,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC5E,MAAM,cAAc,GAAG,qB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,IAAI,KAAK,CAAC,kBAAkB,KAAK,IAAI,CAAC;QACvE,KAAK,CAAC,0BAA0B,KAAK,CAAC;QACtC,KAAK,CAAC,yBAAyB,KAAK,CAAC;QACrC,CAAC,KAAK,CAAC,oBAAoB;QAC3B,KAAK,CAAC,QAAQ,KAAK,SAAS;QAC5B,KAAK,CAAC,KAAK,KAAK,SAAS;QACzB,KAAK,CAAC,gBAAgB,KAAK,CAAC,CAC5B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,YAA2B;IAChE,OAAO,YAAY;SACjB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QACf,MAAM,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9E,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,cAAc,EAAE,CAAC;IAC9C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC","sourcesContent":["import type { Args } from \"./cli/args.ts\";\nimport type { ScopedModel } from \"./core/model-resolver-types.ts\";\nimport type { ProjectTrustStore } from \"./core/trust-manager.ts\";\nimport { hasProjectTrustInputs } from \"./core/trust-manager.ts\";\nimport type { AppMode } from \"./main-app-mode.ts\";\n\nexport interface ComputeDeferExtensionsInput {\n\tappMode: AppMode;\n\tstdinIsTTY: boolean;\n\thasSessionStartEvent: boolean;\n\thelp?: boolean;\n\tlistModels?: Args[\"listModels\"];\n\tshouldResolveProjectTrust: boolean;\n\tstoredProjectTrust: boolean | null;\n\tresolvedExtensionPathCount: number;\n\tresolvedResourcePathCount: number;\n\thasSystemPromptInput: boolean;\n\tunknownFlagCount: number;\n\tprovider?: string;\n\tmodel?: string;\n}\n\nexport interface ComputeStartupInputCaptureInput {\n\tappMode: AppMode;\n\tstdinIsTTY: boolean;\n\tparsed: Pick<\n\t\tArgs,\n\t\t| \"help\"\n\t\t| \"listModels\"\n\t\t| \"projectTrustOverride\"\n\t\t| \"systemPrompt\"\n\t\t| \"appendSystemPrompt\"\n\t\t| \"unknownFlags\"\n\t\t| \"provider\"\n\t\t| \"model\"\n\t\t| \"resume\"\n\t\t| \"session\"\n\t>;\n\tsessionCwd: string;\n\tprojectTrustStore: Pick<ProjectTrustStore, \"get\">;\n\tresolvedExtensionPathCount: number;\n\tresolvedResourcePathCount: number;\n\tdeprecationWarningCount: number;\n}\n\nexport function computeStartupInputCaptureEnabled(input: ComputeStartupInputCaptureInput): boolean {\n\tif (input.parsed.resume || input.parsed.session !== undefined) return false;\n\tconst hasTrustInputs = hasProjectTrustInputs(input.sessionCwd);\n\t// Explicit extension and resource paths make startup slower without adding a\n\t// pre-TUI stdin consumer, so their longer typing window makes capture more\n\t// necessary. Ignore their counts here while computeDeferExtensions continues\n\t// to use the real counts when deciding whether to defer the actual loading.\n\treturn (\n\t\tinput.deprecationWarningCount === 0 &&\n\t\tcomputeDeferExtensions({\n\t\t\tappMode: input.appMode,\n\t\t\tstdinIsTTY: input.stdinIsTTY,\n\t\t\thasSessionStartEvent: false,\n\t\t\thelp: input.parsed.help,\n\t\t\tlistModels: input.parsed.listModels,\n\t\t\tshouldResolveProjectTrust: input.parsed.projectTrustOverride === undefined && hasTrustInputs,\n\t\t\tstoredProjectTrust: hasTrustInputs ? input.projectTrustStore.get(input.sessionCwd) : null,\n\t\t\tresolvedExtensionPathCount: 0,\n\t\t\tresolvedResourcePathCount: 0,\n\t\t\thasSystemPromptInput:\n\t\t\t\tinput.parsed.systemPrompt !== undefined || (input.parsed.appendSystemPrompt?.length ?? 0) > 0,\n\t\t\tunknownFlagCount: input.parsed.unknownFlags.size,\n\t\t\tprovider: input.parsed.provider,\n\t\t\tmodel: input.parsed.model,\n\t\t})\n\t);\n}\n\nexport function computeDeferExtensions(input: ComputeDeferExtensionsInput): boolean {\n\treturn (\n\t\tinput.appMode === \"interactive\" &&\n\t\tinput.stdinIsTTY &&\n\t\t!input.hasSessionStartEvent &&\n\t\t!input.help &&\n\t\tinput.listModels === undefined &&\n\t\t(!input.shouldResolveProjectTrust || input.storedProjectTrust !== null) &&\n\t\tinput.resolvedExtensionPathCount === 0 &&\n\t\tinput.resolvedResourcePathCount === 0 &&\n\t\t!input.hasSystemPromptInput &&\n\t\tinput.provider === undefined &&\n\t\tinput.model === undefined &&\n\t\tinput.unknownFlagCount === 0\n\t);\n}\n\nexport function formatScopedModelList(scopedModels: ScopedModel[]): string {\n\treturn scopedModels\n\t\t.map((scoped) => {\n\t\t\tconst thinkingSuffix = scoped.thinkingLevel ? `:${scoped.thinkingLevel}` : \"\";\n\t\t\treturn `${scoped.model.id}${thinkingSuffix}`;\n\t\t})\n\t\t.join(\", \");\n}\n"]}
1
+ {"version":3,"file":"main-deferred-startup.js","sourceRoot":"","sources":["../src/main-deferred-startup.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAqDhE,MAAM,UAAU,iCAAiC,CAAC,KAAsC;IACvF,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,OAAO,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC5E,MAAM,cAAc,GAAG,qBAAqB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC/D,6EAA6E;IAC7E,2EAA2E;IAC3E,6EAA6E;IAC7E,4EAA4E;IAC5E,OAAO,CACN,KAAK,CAAC,uBAAuB,KAAK,CAAC;QACnC,sBAAsB,CAAC;YACtB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,oBAAoB,EAAE,KAAK;YAC3B,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,IAAI;YACvB,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,UAAU;YACnC,yBAAyB,EAAE,KAAK,CAAC,MAAM,CAAC,oBAAoB,KAAK,SAAS,IAAI,cAA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C,yBAAyB,IAAI,KAAK,CAAC,kBAAkB,KAAK,IAAI,CAAC;QACvE,KAAK,CAAC,0BAA0B,KAAK,CAAC;QACtC,KAAK,CAAC,yBAAyB,KAAK,CAAC;QACrC,CAAC,KAAK,CAAC,oBAAoB;QAC3B,KAAK,CAAC,gBAAgB,KAAK,CAAC,CAC5B,CAAC;AACH,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,YAA2B;IAChE,OAAO,YAAY;SACjB,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QACf,MAAM,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9E,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,cAAc,EAAE,CAAC;IAC9C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC","sourcesContent":["import type { Args } from \"./cli/args.ts\";\nimport type { ScopedModel } from \"./core/model-resolver-types.ts\";\nimport type { ProjectTrustStore } from \"./core/trust-manager.ts\";\nimport { hasProjectTrustInputs } from \"./core/trust-manager.ts\";\nimport type { AppMode } from \"./main-app-mode.ts\";\n\nexport interface ComputeDeferExtensionsInput {\n\tappMode: AppMode;\n\tstdinIsTTY: boolean;\n\thasSessionStartEvent: boolean;\n\thelp?: boolean;\n\tlistModels?: Args[\"listModels\"];\n\tshouldResolveProjectTrust: boolean;\n\tstoredProjectTrust: boolean | null;\n\tresolvedExtensionPathCount: number;\n\tresolvedResourcePathCount: number;\n\thasSystemPromptInput: boolean;\n\tunknownFlagCount: number;\n\tprovider?: string;\n\tmodel?: string;\n}\n\nexport interface ComputeInteractiveEngineResourceDeferralInput {\n\tinteractiveEngineChild: boolean;\n\thasSessionStartEvent: boolean;\n\tshouldResolveProjectTrust: boolean;\n\tstoredProjectTrust: boolean | null;\n\tresolvedExtensionPathCount: number;\n\tresolvedResourcePathCount: number;\n\thasSystemPromptInput: boolean;\n\tunknownFlagCount: number;\n}\n\nexport interface ComputeStartupInputCaptureInput {\n\tappMode: AppMode;\n\tstdinIsTTY: boolean;\n\tparsed: Pick<\n\t\tArgs,\n\t\t| \"help\"\n\t\t| \"listModels\"\n\t\t| \"projectTrustOverride\"\n\t\t| \"systemPrompt\"\n\t\t| \"appendSystemPrompt\"\n\t\t| \"unknownFlags\"\n\t\t| \"provider\"\n\t\t| \"model\"\n\t\t| \"resume\"\n\t\t| \"session\"\n\t>;\n\tsessionCwd: string;\n\tprojectTrustStore: Pick<ProjectTrustStore, \"get\">;\n\tresolvedExtensionPathCount: number;\n\tresolvedResourcePathCount: number;\n\tdeprecationWarningCount: number;\n}\n\nexport function computeStartupInputCaptureEnabled(input: ComputeStartupInputCaptureInput): boolean {\n\tif (input.parsed.resume || input.parsed.session !== undefined) return false;\n\tconst hasTrustInputs = hasProjectTrustInputs(input.sessionCwd);\n\t// Explicit extension and resource paths make startup slower without adding a\n\t// pre-TUI stdin consumer, so their longer typing window makes capture more\n\t// necessary. Ignore their counts here while computeDeferExtensions continues\n\t// to use the real counts when deciding whether to defer the actual loading.\n\treturn (\n\t\tinput.deprecationWarningCount === 0 &&\n\t\tcomputeDeferExtensions({\n\t\t\tappMode: input.appMode,\n\t\t\tstdinIsTTY: input.stdinIsTTY,\n\t\t\thasSessionStartEvent: false,\n\t\t\thelp: input.parsed.help,\n\t\t\tlistModels: input.parsed.listModels,\n\t\t\tshouldResolveProjectTrust: input.parsed.projectTrustOverride === undefined && hasTrustInputs,\n\t\t\tstoredProjectTrust: hasTrustInputs ? input.projectTrustStore.get(input.sessionCwd) : null,\n\t\t\tresolvedExtensionPathCount: 0,\n\t\t\tresolvedResourcePathCount: 0,\n\t\t\thasSystemPromptInput:\n\t\t\t\tinput.parsed.systemPrompt !== undefined || (input.parsed.appendSystemPrompt?.length ?? 0) > 0,\n\t\t\tunknownFlagCount: input.parsed.unknownFlags.size,\n\t\t\tprovider: input.parsed.provider,\n\t\t\tmodel: input.parsed.model,\n\t\t})\n\t);\n}\n\nexport function computeDeferExtensions(input: ComputeDeferExtensionsInput): boolean {\n\treturn (\n\t\tinput.appMode === \"interactive\" &&\n\t\tinput.stdinIsTTY &&\n\t\t!input.hasSessionStartEvent &&\n\t\t!input.help &&\n\t\tinput.listModels === undefined &&\n\t\t(!input.shouldResolveProjectTrust || input.storedProjectTrust !== null) &&\n\t\tinput.resolvedExtensionPathCount === 0 &&\n\t\tinput.resolvedResourcePathCount === 0 &&\n\t\t!input.hasSystemPromptInput &&\n\t\tinput.provider === undefined &&\n\t\tinput.model === undefined &&\n\t\tinput.unknownFlagCount === 0\n\t);\n}\n\n/**\n * The isolated engine may bind its minimal RPC session before loading optional\n * bundled resources. User-selected paths and trust-sensitive startup stay\n * synchronous because they can affect the first visible or interactive state.\n */\nexport function computeInteractiveEngineResourceDeferral(\n\tinput: ComputeInteractiveEngineResourceDeferralInput,\n): boolean {\n\treturn (\n\t\tinput.interactiveEngineChild &&\n\t\t!input.hasSessionStartEvent &&\n\t\t(!input.shouldResolveProjectTrust || input.storedProjectTrust !== null) &&\n\t\tinput.resolvedExtensionPathCount === 0 &&\n\t\tinput.resolvedResourcePathCount === 0 &&\n\t\t!input.hasSystemPromptInput &&\n\t\tinput.unknownFlagCount === 0\n\t);\n}\n\nexport function formatScopedModelList(scopedModels: ScopedModel[]): string {\n\treturn scopedModels\n\t\t.map((scoped) => {\n\t\t\tconst thinkingSuffix = scoped.thinkingLevel ? `:${scoped.thinkingLevel}` : \"\";\n\t\t\treturn `${scoped.model.id}${thinkingSuffix}`;\n\t\t})\n\t\t.join(\", \");\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"main-session.js","sourceRoot":"","sources":["../src/main-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,wBAAwB,C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,EAAE,WAAW,EAAE,CAAC,CAAC;QAC5G,EAAE,CAAC,gBAAgB,CAAC,eAAe,CAAC,gBAAgB,EAAE,CAAC,CAAC;QAExD,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,MAAM,MAAM,GAAG,CAAC,MAA0B,EAAE,EAAE;YAC7C,IAAI,OAAO,EAAE,CAAC;gBACb,OAAO;YACR,CAAC;YACD,OAAO,GAAG,IAAI,CAAC;YACf,EAAE,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,CAAC,MAAM,CAAC,CAAC;QACjB,CAAC,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,0BAA0B,CAC9C,6BAA6B,CAAC,KAAK,CAAC,EACpC,CAAC,UAAU,EAAE,QAAQ,CAAC,EACtB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,EACzE,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,EACvB,EAAE,GAAG,EAAE,EAAE,EAAE,CACX,CAAC;QACF,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACtB,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACtB,EAAE,CAAC,KAAK,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { createInterface } from \"node:readline\";\nimport { ProcessTerminal, setCapabilityOverrides, setKeybindings, TuiMainScreen } from \"@earendil-works/pi-tui\";\nimport chalk from \"chalk\";\nimport type { Args } from \"./cli/args.ts\";\nimport { selectSession } from \"./cli/session-picker.ts\";\nimport { getAgentDir } from \"./config.ts\";\nimport { KeybindingsManager } from \"./core/keybindings.ts\";\nimport { formatMissingSessionCwdPrompt, type SessionCwdIssue } from \"./core/session-cwd.ts\";\nimport { assertValidSessionId, SessionManager } from \"./core/session-manager.ts\";\nimport { workflowSessionMetadataFromEnv } from \"./core/session-manager-classification.ts\";\nimport type { SettingsManager } from \"./core/settings-manager.ts\";\nimport { ExtensionSelectorComponent } from \"./modes/interactive/components/extension-selector.ts\";\nimport { initTheme, stopThemeWatcher } from \"./modes/interactive/theme/theme.ts\";\nimport { resolvePath } from \"./utils/paths.ts\";\n\n/** Result from resolving a session argument */\ntype ResolvedSession =\n\t| { type: \"path\"; path: string } // Direct file path\n\t| { type: \"local\"; path: string } // Found in current project\n\t| { type: \"global\"; path: string; cwd: string } // Found in different project\n\t| { type: \"not_found\"; arg: string }; // Not found anywhere\n\n/**\n * Resolve a session argument to a file path.\n * If it looks like a path, use as-is. Otherwise try to match as session ID prefix.\n */\nasync function findLocalSessionByExactId(\n\tsessionId: string,\n\tcwd: string,\n\tsessionDir?: string,\n): Promise<{ type: \"local\"; path: string } | undefined> {\n\tconst localSessions = await SessionManager.list(cwd, sessionDir);\n\tconst localMatch = localSessions.find((s) => s.id === sessionId);\n\treturn localMatch ? { type: \"local\", path: localMatch.path } : undefined;\n}\n\nasync function resolveSessionPath(sessionArg: string, cwd: string, sessionDir?: string): Promise<ResolvedSession> {\n\t// If it looks like a file path, resolve it before handing it to the session manager.\n\tif (sessionArg.includes(\"/\") || sessionArg.includes(\"\\\\\") || sessionArg.endsWith(\".jsonl\")) {\n\t\treturn { type: \"path\", path: resolvePath(sessionArg, cwd) };\n\t}\n\n\t// Try to match as session ID in current project first\n\tconst localSessions = await SessionManager.list(cwd, sessionDir);\n\tconst localMatch =\n\t\tlocalSessions.find((s) => s.id === sessionArg) ?? localSessions.find((s) => s.id.startsWith(sessionArg));\n\n\tif (localMatch) {\n\t\treturn { type: \"local\", path: localMatch.path };\n\t}\n\n\t// Try global search across all projects\n\tconst allSessions = await SessionManager.listAll(sessionDir);\n\tconst globalMatch =\n\t\tallSessions.find((s) => s.id === sessionArg) ?? allSessions.find((s) => s.id.startsWith(sessionArg));\n\n\tif (globalMatch) {\n\t\treturn { type: \"global\", path: globalMatch.path, cwd: globalMatch.cwd };\n\t}\n\n\t// Not found anywhere\n\treturn { type: \"not_found\", arg: sessionArg };\n}\n\n/** Prompt user for yes/no confirmation */\nasync function promptConfirm(message: string): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst rl = createInterface({\n\t\t\tinput: process.stdin,\n\t\t\toutput: process.stdout,\n\t\t});\n\t\trl.question(`${message} [y/N] `, (answer) => {\n\t\t\trl.close();\n\t\t\tresolve(answer.toLowerCase() === \"y\" || answer.toLowerCase() === \"yes\");\n\t\t});\n\t});\n}\n\nexport function validateForkFlags(parsed: Args): void {\n\tif (!parsed.fork) return;\n\n\tconst conflictingFlags = [\n\t\tparsed.session ? \"--session\" : undefined,\n\t\tparsed.continue ? \"--continue\" : undefined,\n\t\tparsed.resume ? \"--resume\" : undefined,\n\t\tparsed.noSession ? \"--no-session\" : undefined,\n\t].filter((flag): flag is string => flag !== undefined);\n\n\tif (conflictingFlags.length > 0) {\n\t\tconsole.error(chalk.red(`Error: --fork cannot be combined with ${conflictingFlags.join(\", \")}`));\n\t\tprocess.exit(1);\n\t}\n}\n\nexport function validateSessionIdFlags(parsed: Args): void {\n\tif (parsed.sessionId === undefined) return;\n\n\tconst conflictingFlags = [\n\t\tparsed.session ? \"--session\" : undefined,\n\t\tparsed.continue ? \"--continue\" : undefined,\n\t\tparsed.resume ? \"--resume\" : undefined,\n\t].filter((flag): flag is string => flag !== undefined);\n\n\tif (conflictingFlags.length > 0) {\n\t\tconsole.error(chalk.red(`Error: --session-id cannot be combined with ${conflictingFlags.join(\", \")}`));\n\t\tprocess.exit(1);\n\t}\n\n\ttry {\n\t\tassertValidSessionId(parsed.sessionId);\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exit(1);\n\t}\n}\nfunction forkSessionOrExit(sourcePath: string, cwd: string, sessionDir?: string, sessionId?: string): SessionManager {\n\ttry {\n\t\treturn SessionManager.forkFrom(sourcePath, cwd, sessionDir, { id: sessionId });\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exit(1);\n\t}\n}\n\nfunction openSessionOrExit(path: string, sessionDir?: string): SessionManager {\n\ttry {\n\t\treturn SessionManager.open(path, sessionDir);\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exit(1);\n\t}\n}\n\nexport function applyInheritedWorkflowSessionClassification(\n\tsessionManager: SessionManager,\n\tenv: Record<string, string | undefined> = process.env,\n): SessionManager {\n\tconst metadata = workflowSessionMetadataFromEnv(env);\n\tif (metadata) sessionManager.markSessionInternal(metadata);\n\treturn sessionManager;\n}\n\nexport async function createSessionManager(\n\tparsed: Args,\n\tcwd: string,\n\tsessionDir: string | undefined,\n\tsettingsManager: SettingsManager,\n): Promise<SessionManager> {\n\tif (parsed.noSession || parsed.help || parsed.listModels !== undefined) {\n\t\treturn SessionManager.inMemory(cwd, parsed.sessionId !== undefined ? { id: parsed.sessionId } : undefined);\n\t}\n\n\tif (parsed.fork) {\n\t\tif (parsed.sessionId) {\n\t\t\tconst existingTarget = await findLocalSessionByExactId(parsed.sessionId, cwd, sessionDir);\n\t\t\tif (existingTarget) {\n\t\t\t\tconsole.error(chalk.red(`Session already exists with id '${parsed.sessionId}'`));\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t}\n\n\t\tconst resolved = await resolveSessionPath(parsed.fork, cwd, sessionDir);\n\n\t\tswitch (resolved.type) {\n\t\t\tcase \"path\":\n\t\t\tcase \"local\":\n\t\t\tcase \"global\":\n\t\t\t\treturn forkSessionOrExit(resolved.path, cwd, sessionDir, parsed.sessionId);\n\n\t\t\tcase \"not_found\":\n\t\t\t\tconsole.error(chalk.red(`No session found matching '${resolved.arg}'`));\n\t\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tif (parsed.session) {\n\t\tconst resolved = await resolveSessionPath(parsed.session, cwd, sessionDir);\n\n\t\tswitch (resolved.type) {\n\t\t\tcase \"path\":\n\t\t\tcase \"local\":\n\t\t\t\treturn openSessionOrExit(resolved.path, sessionDir);\n\n\t\t\tcase \"global\": {\n\t\t\t\tconsole.log(chalk.yellow(`Session found in different project: ${resolved.cwd}`));\n\t\t\t\tconst shouldFork = await promptConfirm(\"Fork this session into current directory?\");\n\t\t\t\tif (!shouldFork) {\n\t\t\t\t\tconsole.log(chalk.dim(\"Aborted.\"));\n\t\t\t\t\tprocess.exit(0);\n\t\t\t\t}\n\t\t\t\treturn forkSessionOrExit(resolved.path, cwd, sessionDir);\n\t\t\t}\n\n\t\t\tcase \"not_found\":\n\t\t\t\tconsole.error(chalk.red(`No session found matching '${resolved.arg}'`));\n\t\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tif (parsed.resume) {\n\t\tinitTheme(settingsManager.getTheme(), true);\n\t\ttry {\n\t\t\tconst selectedPath = await selectSession(\n\t\t\t\t(onProgress) => SessionManager.list(cwd, sessionDir, onProgress),\n\t\t\t\t(onProgress) => SessionManager.listAll(sessionDir, onProgress),\n\t\t\t\tsettingsManager,\n\t\t\t);\n\t\t\tif (!selectedPath) {\n\t\t\t\tconsole.log(chalk.dim(\"No session selected\"));\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t\treturn openSessionOrExit(selectedPath, sessionDir);\n\t\t} finally {\n\t\t\tstopThemeWatcher();\n\t\t}\n\t}\n\n\tif (parsed.continue) {\n\t\treturn SessionManager.continueRecent(cwd, sessionDir);\n\t}\n\n\tif (parsed.sessionId) {\n\t\tconst existingSession = await findLocalSessionByExactId(parsed.sessionId, cwd, sessionDir);\n\t\tif (existingSession) {\n\t\t\treturn openSessionOrExit(existingSession.path, sessionDir);\n\t\t}\n\t\tconsole.error(chalk.yellow(`No session found with id '${parsed.sessionId}'; creating a new session.`));\n\t}\n\n\treturn SessionManager.create(cwd, sessionDir, { id: parsed.sessionId });\n}\n\nexport async function promptForMissingSessionCwd(\n\tissue: SessionCwdIssue,\n\tsettingsManager: SettingsManager,\n): Promise<string | undefined> {\n\tsetCapabilityOverrides(settingsManager.getTerminalCapabilityOverrides());\n\tinitTheme(settingsManager.getTheme());\n\tsetKeybindings(KeybindingsManager.create());\n\n\treturn new Promise((resolve) => {\n\t\tconst ui = new TuiMainScreen(new ProcessTerminal(), settingsManager.getShowHardwareCursor(), getAgentDir());\n\t\tui.setClearOnShrink(settingsManager.getClearOnShrink());\n\n\t\tlet settled = false;\n\t\tconst finish = (result: string | undefined) => {\n\t\t\tif (settled) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsettled = true;\n\t\t\tui.stop();\n\t\t\tresolve(result);\n\t\t};\n\n\t\tconst selector = new ExtensionSelectorComponent(\n\t\t\tformatMissingSessionCwdPrompt(issue),\n\t\t\t[\"Continue\", \"Cancel\"],\n\t\t\t(option) => finish(option === \"Continue\" ? issue.fallbackCwd : undefined),\n\t\t\t() => finish(undefined),\n\t\t\t{ tui: ui },\n\t\t);\n\t\tui.addChild(selector);\n\t\tui.setFocus(selector);\n\t\tui.start();\n\t});\n}\n"]}
1
+ {"version":3,"file":"main-session.js","sourceRoot":"","sources":["../src/main-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAChH,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,6BAA6B,EAAwB,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,2BAA2B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V,OAAO,CAAC,MAAM,CAAC,CAAC;QACjB,CAAC,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,0BAA0B,CAC9C,6BAA6B,CAAC,KAAK,CAAC,EACpC,CAAC,UAAU,EAAE,QAAQ,CAAC,EACtB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,EACzE,GAAG,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,EACvB,EAAE,GAAG,EAAE,EAAE,EAAE,CACX,CAAC;QACF,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACtB,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACtB,EAAE,CAAC,KAAK,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { createInterface } from \"node:readline\";\nimport { ProcessTerminal, setCapabilityOverrides, setKeybindings, TuiMainScreen } from \"@earendil-works/pi-tui\";\nimport chalk from \"chalk\";\nimport type { Args } from \"./cli/args.ts\";\nimport { selectSession } from \"./cli/session-picker.ts\";\nimport { getAgentDir } from \"./config.js\";\nimport { KeybindingsManager } from \"./core/keybindings.ts\";\nimport { formatMissingSessionCwdPrompt, type SessionCwdIssue } from \"./core/session-cwd.ts\";\nimport { assertValidSessionId, SessionManager } from \"./core/session-manager.ts\";\nimport { workflowSessionMetadataFromEnv } from \"./core/session-manager-classification.ts\";\nimport type { SettingsManager } from \"./core/settings-manager.ts\";\nimport { ExtensionSelectorComponent } from \"./modes/interactive/components/extension-selector.ts\";\nimport { initTheme, stopThemeWatcher } from \"./modes/interactive/theme/theme.ts\";\nimport { resolvePath } from \"./utils/paths.ts\";\n\n/** Result from resolving a session argument */\ntype ResolvedSession =\n\t| { type: \"path\"; path: string } // Direct file path\n\t| { type: \"local\"; path: string } // Found in current project\n\t| { type: \"global\"; path: string; cwd: string } // Found in different project\n\t| { type: \"not_found\"; arg: string }; // Not found anywhere\n\n/**\n * Resolve a session argument to a file path.\n * If it looks like a path, use as-is. Otherwise try to match as session ID prefix.\n */\nasync function findLocalSessionByExactId(\n\tsessionId: string,\n\tcwd: string,\n\tsessionDir?: string,\n): Promise<{ type: \"local\"; path: string } | undefined> {\n\tconst localSessions = await SessionManager.list(cwd, sessionDir);\n\tconst localMatch = localSessions.find((s) => s.id === sessionId);\n\treturn localMatch ? { type: \"local\", path: localMatch.path } : undefined;\n}\n\nasync function resolveSessionPath(sessionArg: string, cwd: string, sessionDir?: string): Promise<ResolvedSession> {\n\t// If it looks like a file path, resolve it before handing it to the session manager.\n\tif (sessionArg.includes(\"/\") || sessionArg.includes(\"\\\\\") || sessionArg.endsWith(\".jsonl\")) {\n\t\treturn { type: \"path\", path: resolvePath(sessionArg, cwd) };\n\t}\n\n\t// Try to match as session ID in current project first\n\tconst localSessions = await SessionManager.list(cwd, sessionDir);\n\tconst localMatch =\n\t\tlocalSessions.find((s) => s.id === sessionArg) ?? localSessions.find((s) => s.id.startsWith(sessionArg));\n\n\tif (localMatch) {\n\t\treturn { type: \"local\", path: localMatch.path };\n\t}\n\n\t// Try global search across all projects\n\tconst allSessions = await SessionManager.listAll(sessionDir);\n\tconst globalMatch =\n\t\tallSessions.find((s) => s.id === sessionArg) ?? allSessions.find((s) => s.id.startsWith(sessionArg));\n\n\tif (globalMatch) {\n\t\treturn { type: \"global\", path: globalMatch.path, cwd: globalMatch.cwd };\n\t}\n\n\t// Not found anywhere\n\treturn { type: \"not_found\", arg: sessionArg };\n}\n\n/** Prompt user for yes/no confirmation */\nasync function promptConfirm(message: string): Promise<boolean> {\n\treturn new Promise((resolve) => {\n\t\tconst rl = createInterface({\n\t\t\tinput: process.stdin,\n\t\t\toutput: process.stdout,\n\t\t});\n\t\trl.question(`${message} [y/N] `, (answer) => {\n\t\t\trl.close();\n\t\t\tresolve(answer.toLowerCase() === \"y\" || answer.toLowerCase() === \"yes\");\n\t\t});\n\t});\n}\n\nexport function validateForkFlags(parsed: Args): void {\n\tif (!parsed.fork) return;\n\n\tconst conflictingFlags = [\n\t\tparsed.session ? \"--session\" : undefined,\n\t\tparsed.continue ? \"--continue\" : undefined,\n\t\tparsed.resume ? \"--resume\" : undefined,\n\t\tparsed.noSession ? \"--no-session\" : undefined,\n\t].filter((flag): flag is string => flag !== undefined);\n\n\tif (conflictingFlags.length > 0) {\n\t\tconsole.error(chalk.red(`Error: --fork cannot be combined with ${conflictingFlags.join(\", \")}`));\n\t\tprocess.exit(1);\n\t}\n}\n\nexport function validateSessionIdFlags(parsed: Args): void {\n\tif (parsed.sessionId === undefined) return;\n\n\tconst conflictingFlags = [\n\t\tparsed.session ? \"--session\" : undefined,\n\t\tparsed.continue ? \"--continue\" : undefined,\n\t\tparsed.resume ? \"--resume\" : undefined,\n\t].filter((flag): flag is string => flag !== undefined);\n\n\tif (conflictingFlags.length > 0) {\n\t\tconsole.error(chalk.red(`Error: --session-id cannot be combined with ${conflictingFlags.join(\", \")}`));\n\t\tprocess.exit(1);\n\t}\n\n\ttry {\n\t\tassertValidSessionId(parsed.sessionId);\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exit(1);\n\t}\n}\nfunction forkSessionOrExit(sourcePath: string, cwd: string, sessionDir?: string, sessionId?: string): SessionManager {\n\ttry {\n\t\treturn SessionManager.forkFrom(sourcePath, cwd, sessionDir, { id: sessionId });\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exit(1);\n\t}\n}\n\nfunction openSessionOrExit(path: string, sessionDir?: string): SessionManager {\n\ttry {\n\t\treturn SessionManager.open(path, sessionDir);\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exit(1);\n\t}\n}\n\nexport function applyInheritedWorkflowSessionClassification(\n\tsessionManager: SessionManager,\n\tenv: Record<string, string | undefined> = process.env,\n): SessionManager {\n\tconst metadata = workflowSessionMetadataFromEnv(env);\n\tif (metadata) sessionManager.markSessionInternal(metadata);\n\treturn sessionManager;\n}\n\nexport async function createSessionManager(\n\tparsed: Args,\n\tcwd: string,\n\tsessionDir: string | undefined,\n\tsettingsManager: SettingsManager,\n): Promise<SessionManager> {\n\tif (parsed.noSession || parsed.help || parsed.listModels !== undefined) {\n\t\treturn SessionManager.inMemory(cwd, parsed.sessionId !== undefined ? { id: parsed.sessionId } : undefined);\n\t}\n\n\tif (parsed.fork) {\n\t\tif (parsed.sessionId) {\n\t\t\tconst existingTarget = await findLocalSessionByExactId(parsed.sessionId, cwd, sessionDir);\n\t\t\tif (existingTarget) {\n\t\t\t\tconsole.error(chalk.red(`Session already exists with id '${parsed.sessionId}'`));\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t}\n\n\t\tconst resolved = await resolveSessionPath(parsed.fork, cwd, sessionDir);\n\n\t\tswitch (resolved.type) {\n\t\t\tcase \"path\":\n\t\t\tcase \"local\":\n\t\t\tcase \"global\":\n\t\t\t\treturn forkSessionOrExit(resolved.path, cwd, sessionDir, parsed.sessionId);\n\n\t\t\tcase \"not_found\":\n\t\t\t\tconsole.error(chalk.red(`No session found matching '${resolved.arg}'`));\n\t\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tif (parsed.session) {\n\t\tconst resolved = await resolveSessionPath(parsed.session, cwd, sessionDir);\n\n\t\tswitch (resolved.type) {\n\t\t\tcase \"path\":\n\t\t\tcase \"local\":\n\t\t\t\treturn openSessionOrExit(resolved.path, sessionDir);\n\n\t\t\tcase \"global\": {\n\t\t\t\tconsole.log(chalk.yellow(`Session found in different project: ${resolved.cwd}`));\n\t\t\t\tconst shouldFork = await promptConfirm(\"Fork this session into current directory?\");\n\t\t\t\tif (!shouldFork) {\n\t\t\t\t\tconsole.log(chalk.dim(\"Aborted.\"));\n\t\t\t\t\tprocess.exit(0);\n\t\t\t\t}\n\t\t\t\treturn forkSessionOrExit(resolved.path, cwd, sessionDir);\n\t\t\t}\n\n\t\t\tcase \"not_found\":\n\t\t\t\tconsole.error(chalk.red(`No session found matching '${resolved.arg}'`));\n\t\t\t\tprocess.exit(1);\n\t\t}\n\t}\n\n\tif (parsed.resume) {\n\t\tinitTheme(settingsManager.getTheme(), true);\n\t\ttry {\n\t\t\tconst selectedPath = await selectSession(\n\t\t\t\t(onProgress) => SessionManager.list(cwd, sessionDir, onProgress),\n\t\t\t\t(onProgress) => SessionManager.listAll(sessionDir, onProgress),\n\t\t\t\tsettingsManager,\n\t\t\t);\n\t\t\tif (!selectedPath) {\n\t\t\t\tconsole.log(chalk.dim(\"No session selected\"));\n\t\t\t\tprocess.exit(0);\n\t\t\t}\n\t\t\treturn openSessionOrExit(selectedPath, sessionDir);\n\t\t} finally {\n\t\t\tstopThemeWatcher();\n\t\t}\n\t}\n\n\tif (parsed.continue) {\n\t\treturn SessionManager.continueRecent(cwd, sessionDir);\n\t}\n\n\tif (parsed.sessionId) {\n\t\tconst existingSession = await findLocalSessionByExactId(parsed.sessionId, cwd, sessionDir);\n\t\tif (existingSession) {\n\t\t\treturn openSessionOrExit(existingSession.path, sessionDir);\n\t\t}\n\t\tconsole.error(chalk.yellow(`No session found with id '${parsed.sessionId}'; creating a new session.`));\n\t}\n\n\treturn SessionManager.create(cwd, sessionDir, { id: parsed.sessionId });\n}\n\nexport async function promptForMissingSessionCwd(\n\tissue: SessionCwdIssue,\n\tsettingsManager: SettingsManager,\n): Promise<string | undefined> {\n\tsetCapabilityOverrides(settingsManager.getTerminalCapabilityOverrides());\n\tinitTheme(settingsManager.getTheme());\n\tsetKeybindings(KeybindingsManager.create());\n\n\treturn new Promise((resolve) => {\n\t\tconst ui = new TuiMainScreen(new ProcessTerminal(), settingsManager.getShowHardwareCursor(), getAgentDir());\n\t\tui.setClearOnShrink(settingsManager.getClearOnShrink());\n\n\t\tlet settled = false;\n\t\tconst finish = (result: string | undefined) => {\n\t\t\tif (settled) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsettled = true;\n\t\t\tui.stop();\n\t\t\tresolve(result);\n\t\t};\n\n\t\tconst selector = new ExtensionSelectorComponent(\n\t\t\tformatMissingSessionCwdPrompt(issue),\n\t\t\t[\"Continue\", \"Cancel\"],\n\t\t\t(option) => finish(option === \"Continue\" ? issue.fallbackCwd : undefined),\n\t\t\t() => finish(undefined),\n\t\t\t{ tui: ui },\n\t\t);\n\t\tui.addChild(selector);\n\t\tui.setFocus(selector);\n\t\tui.start();\n\t});\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAiGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAenD,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AACpE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AA6JnD,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,iBAihB/D"}
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAkGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAenD,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAC;AACpE,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AA6JnD,wBAAsB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,WAAW,iBAqiB/D"}