@entelligentsia/forgecli 0.15.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1202) hide show
  1. package/CHANGELOG.md +105 -0
  2. package/dist/CHANGELOG-pi.md +55 -0
  3. package/dist/bin/argv.d.ts +2 -0
  4. package/dist/bin/argv.js +3 -1
  5. package/dist/bin/argv.js.map +1 -1
  6. package/dist/bin/config.d.ts +5 -0
  7. package/dist/bin/config.js +34 -13
  8. package/dist/bin/config.js.map +1 -1
  9. package/dist/bin/forge.js +14 -58
  10. package/dist/bin/forge.js.map +1 -1
  11. package/dist/bin/shared-parser.d.ts +23 -0
  12. package/dist/bin/shared-parser.js +12 -0
  13. package/dist/bin/shared-parser.js.map +1 -0
  14. package/dist/bin/update-cli.js +7 -1
  15. package/dist/bin/update-cli.js.map +1 -1
  16. package/dist/extensions/forgecli/add-pipeline.js.map +1 -1
  17. package/dist/extensions/forgecli/add-task.js.map +1 -1
  18. package/dist/extensions/forgecli/approve.d.ts +4 -6
  19. package/dist/extensions/forgecli/approve.js +8 -73
  20. package/dist/extensions/forgecli/approve.js.map +1 -1
  21. package/dist/extensions/forgecli/ask-user-tool.js.map +1 -1
  22. package/dist/extensions/forgecli/audience-gate.d.ts +1 -1
  23. package/dist/extensions/forgecli/audience-gate.js.map +1 -1
  24. package/dist/extensions/forgecli/calibrate.d.ts +4 -1
  25. package/dist/extensions/forgecli/calibrate.js +10 -20
  26. package/dist/extensions/forgecli/calibrate.js.map +1 -1
  27. package/dist/extensions/forgecli/collate.d.ts +4 -6
  28. package/dist/extensions/forgecli/collate.js +8 -73
  29. package/dist/extensions/forgecli/collate.js.map +1 -1
  30. package/dist/extensions/forgecli/commit.d.ts +4 -6
  31. package/dist/extensions/forgecli/commit.js +8 -73
  32. package/dist/extensions/forgecli/commit.js.map +1 -1
  33. package/dist/extensions/forgecli/config-command.js.map +1 -1
  34. package/dist/extensions/forgecli/config-layer.js +4 -2
  35. package/dist/extensions/forgecli/config-layer.js.map +1 -1
  36. package/dist/extensions/forgecli/config-tui/component.d.ts +1 -1
  37. package/dist/extensions/forgecli/config-tui/component.js +25 -21
  38. package/dist/extensions/forgecli/config-tui/component.js.map +1 -1
  39. package/dist/extensions/forgecli/config-tui/handler.js +3 -6
  40. package/dist/extensions/forgecli/config-tui/handler.js.map +1 -1
  41. package/dist/extensions/forgecli/config-tui/keys.js.map +1 -1
  42. package/dist/extensions/forgecli/config-tui/plugin-config-reader.js.map +1 -1
  43. package/dist/extensions/forgecli/config-tui/screens/advanced-menu.d.ts +2 -2
  44. package/dist/extensions/forgecli/config-tui/screens/advanced-menu.js +10 -8
  45. package/dist/extensions/forgecli/config-tui/screens/advanced-menu.js.map +1 -1
  46. package/dist/extensions/forgecli/config-tui/screens/confirm-quit.d.ts +2 -2
  47. package/dist/extensions/forgecli/config-tui/screens/confirm-quit.js +2 -5
  48. package/dist/extensions/forgecli/config-tui/screens/confirm-quit.js.map +1 -1
  49. package/dist/extensions/forgecli/config-tui/screens/override-editor.d.ts +2 -2
  50. package/dist/extensions/forgecli/config-tui/screens/override-editor.js +15 -11
  51. package/dist/extensions/forgecli/config-tui/screens/override-editor.js.map +1 -1
  52. package/dist/extensions/forgecli/config-tui/screens/overrides-list-phases.d.ts +2 -2
  53. package/dist/extensions/forgecli/config-tui/screens/overrides-list-phases.js +15 -11
  54. package/dist/extensions/forgecli/config-tui/screens/overrides-list-phases.js.map +1 -1
  55. package/dist/extensions/forgecli/config-tui/screens/overrides-list.d.ts +2 -2
  56. package/dist/extensions/forgecli/config-tui/screens/overrides-list.js +7 -4
  57. package/dist/extensions/forgecli/config-tui/screens/overrides-list.js.map +1 -1
  58. package/dist/extensions/forgecli/config-tui/screens/persona-editor.d.ts +2 -2
  59. package/dist/extensions/forgecli/config-tui/screens/persona-editor.js +6 -12
  60. package/dist/extensions/forgecli/config-tui/screens/persona-editor.js.map +1 -1
  61. package/dist/extensions/forgecli/config-tui/screens/persona-picker.d.ts +2 -2
  62. package/dist/extensions/forgecli/config-tui/screens/persona-picker.js +3 -6
  63. package/dist/extensions/forgecli/config-tui/screens/persona-picker.js.map +1 -1
  64. package/dist/extensions/forgecli/config-tui/screens/personas-list.d.ts +2 -2
  65. package/dist/extensions/forgecli/config-tui/screens/personas-list.js +2 -2
  66. package/dist/extensions/forgecli/config-tui/screens/personas-list.js.map +1 -1
  67. package/dist/extensions/forgecli/config-tui/screens/shared.d.ts +1 -1
  68. package/dist/extensions/forgecli/config-tui/screens/shared.js +4 -5
  69. package/dist/extensions/forgecli/config-tui/screens/shared.js.map +1 -1
  70. package/dist/extensions/forgecli/config-tui/screens/show-resolved.d.ts +2 -2
  71. package/dist/extensions/forgecli/config-tui/screens/show-resolved.js +9 -11
  72. package/dist/extensions/forgecli/config-tui/screens/show-resolved.js.map +1 -1
  73. package/dist/extensions/forgecli/config-tui/screens/tier-menu.d.ts +2 -2
  74. package/dist/extensions/forgecli/config-tui/screens/tier-menu.js +9 -2
  75. package/dist/extensions/forgecli/config-tui/screens/tier-menu.js.map +1 -1
  76. package/dist/extensions/forgecli/config-tui/screens/tier-picker.d.ts +2 -2
  77. package/dist/extensions/forgecli/config-tui/screens/tier-picker.js +12 -3
  78. package/dist/extensions/forgecli/config-tui/screens/tier-picker.js.map +1 -1
  79. package/dist/extensions/forgecli/config-tui/screens/types.d.ts +1 -1
  80. package/dist/extensions/forgecli/config-tui/screens.d.ts +10 -10
  81. package/dist/extensions/forgecli/config-tui/screens.js +16 -16
  82. package/dist/extensions/forgecli/config-tui/screens.js.map +1 -1
  83. package/dist/extensions/forgecli/config-tui/state/buffer.d.ts +2 -2
  84. package/dist/extensions/forgecli/config-tui/state/buffer.js +1 -2
  85. package/dist/extensions/forgecli/config-tui/state/buffer.js.map +1 -1
  86. package/dist/extensions/forgecli/config-tui/state/constants.js.map +1 -1
  87. package/dist/extensions/forgecli/config-tui/state/index.d.ts +3 -3
  88. package/dist/extensions/forgecli/config-tui/state/index.js +2 -2
  89. package/dist/extensions/forgecli/config-tui/state/index.js.map +1 -1
  90. package/dist/extensions/forgecli/config-tui/state/init.js +1 -0
  91. package/dist/extensions/forgecli/config-tui/state/init.js.map +1 -1
  92. package/dist/extensions/forgecli/config-tui/state/model.d.ts +4 -0
  93. package/dist/extensions/forgecli/config-tui/state/reducer.js +2 -4
  94. package/dist/extensions/forgecli/config-tui/state/reducer.js.map +1 -1
  95. package/dist/extensions/forgecli/config-tui/state/selectors.d.ts +1 -1
  96. package/dist/extensions/forgecli/config-tui/state/selectors.js +7 -6
  97. package/dist/extensions/forgecli/config-tui/state/selectors.js.map +1 -1
  98. package/dist/extensions/forgecli/config-tui/state.d.ts +3 -3
  99. package/dist/extensions/forgecli/config-tui/state.js +2 -2
  100. package/dist/extensions/forgecli/config-tui/state.js.map +1 -1
  101. package/dist/extensions/forgecli/config-tui/theme.js +1 -1
  102. package/dist/extensions/forgecli/config-tui/theme.js.map +1 -1
  103. package/dist/extensions/forgecli/config-tui/tier-meta.js.map +1 -1
  104. package/dist/extensions/forgecli/config-writer.js +4 -2
  105. package/dist/extensions/forgecli/config-writer.js.map +1 -1
  106. package/dist/extensions/forgecli/enhance.d.ts +4 -6
  107. package/dist/extensions/forgecli/enhance.js +9 -74
  108. package/dist/extensions/forgecli/enhance.js.map +1 -1
  109. package/dist/extensions/forgecli/fix-bug.d.ts +4 -1
  110. package/dist/extensions/forgecli/fix-bug.js +202 -100
  111. package/dist/extensions/forgecli/fix-bug.js.map +1 -1
  112. package/dist/extensions/forgecli/forge-artifact-tool.d.ts +9 -0
  113. package/dist/extensions/forgecli/forge-artifact-tool.js +255 -0
  114. package/dist/extensions/forgecli/forge-artifact-tool.js.map +1 -0
  115. package/dist/extensions/forgecli/forge-commands.js.map +1 -1
  116. package/dist/extensions/forgecli/forge-header.d.ts +1 -1
  117. package/dist/extensions/forgecli/forge-header.js +1 -1
  118. package/dist/extensions/forgecli/forge-header.js.map +1 -1
  119. package/dist/extensions/forgecli/forge-init/phase-descriptors.d.ts +72 -0
  120. package/dist/extensions/forgecli/forge-init/phase-descriptors.js +359 -0
  121. package/dist/extensions/forgecli/forge-init/phase-descriptors.js.map +1 -0
  122. package/dist/extensions/forgecli/forge-init/phase4-register.d.ts +20 -0
  123. package/dist/extensions/forgecli/forge-init/phase4-register.js +353 -0
  124. package/dist/extensions/forgecli/forge-init/phase4-register.js.map +1 -0
  125. package/dist/extensions/forgecli/forge-init/prompts.d.ts +10 -0
  126. package/dist/extensions/forgecli/forge-init/prompts.js +91 -0
  127. package/dist/extensions/forgecli/forge-init/prompts.js.map +1 -0
  128. package/dist/extensions/forgecli/forge-init/verifiers.d.ts +20 -0
  129. package/dist/extensions/forgecli/forge-init/verifiers.js +81 -0
  130. package/dist/extensions/forgecli/forge-init/verifiers.js.map +1 -0
  131. package/dist/extensions/forgecli/forge-init.js +107 -751
  132. package/dist/extensions/forgecli/forge-init.js.map +1 -1
  133. package/dist/extensions/forgecli/forge-root.d.ts +0 -1
  134. package/dist/extensions/forgecli/forge-root.js +1 -11
  135. package/dist/extensions/forgecli/forge-root.js.map +1 -1
  136. package/dist/extensions/forgecli/forge-subagent.d.ts +11 -1
  137. package/dist/extensions/forgecli/forge-subagent.js +9 -2
  138. package/dist/extensions/forgecli/forge-subagent.js.map +1 -1
  139. package/dist/extensions/forgecli/forge-tools.d.ts +27 -7
  140. package/dist/extensions/forgecli/forge-tools.js +116 -71
  141. package/dist/extensions/forgecli/forge-tools.js.map +1 -1
  142. package/dist/extensions/forgecli/forge-update-command.d.ts +32 -11
  143. package/dist/extensions/forgecli/forge-update-command.js +207 -150
  144. package/dist/extensions/forgecli/forge-update-command.js.map +1 -1
  145. package/dist/extensions/forgecli/friction-emit.d.ts +4 -2
  146. package/dist/extensions/forgecli/friction-emit.js +15 -16
  147. package/dist/extensions/forgecli/friction-emit.js.map +1 -1
  148. package/dist/extensions/forgecli/health-check.js +11 -7
  149. package/dist/extensions/forgecli/health-check.js.map +1 -1
  150. package/dist/extensions/forgecli/hook-dispatcher.d.ts +1 -0
  151. package/dist/extensions/forgecli/hook-dispatcher.js +7 -2
  152. package/dist/extensions/forgecli/hook-dispatcher.js.map +1 -1
  153. package/dist/extensions/forgecli/hooks/check-update.js.map +1 -1
  154. package/dist/extensions/forgecli/hooks/forge-permissions.js.map +1 -1
  155. package/dist/extensions/forgecli/hooks/post-init-hook.js +2 -2
  156. package/dist/extensions/forgecli/hooks/post-init-hook.js.map +1 -1
  157. package/dist/extensions/forgecli/hooks/post-sprint-hook.js +2 -2
  158. package/dist/extensions/forgecli/hooks/post-sprint-hook.js.map +1 -1
  159. package/dist/extensions/forgecli/hooks/write-guard.js +6 -4
  160. package/dist/extensions/forgecli/hooks/write-guard.js.map +1 -1
  161. package/dist/extensions/forgecli/implement.d.ts +4 -6
  162. package/dist/extensions/forgecli/implement.js +8 -73
  163. package/dist/extensions/forgecli/implement.js.map +1 -1
  164. package/dist/extensions/forgecli/index.js +59 -76
  165. package/dist/extensions/forgecli/index.js.map +1 -1
  166. package/dist/extensions/forgecli/input-router.js +4 -1
  167. package/dist/extensions/forgecli/input-router.js.map +1 -1
  168. package/dist/extensions/forgecli/lib/catalog-helpers.d.ts +13 -0
  169. package/dist/extensions/forgecli/lib/catalog-helpers.js +52 -0
  170. package/dist/extensions/forgecli/lib/catalog-helpers.js.map +1 -0
  171. package/dist/extensions/forgecli/lib/catalog-loader.d.ts +46 -0
  172. package/dist/extensions/forgecli/lib/catalog-loader.js +176 -0
  173. package/dist/extensions/forgecli/lib/catalog-loader.js.map +1 -0
  174. package/dist/extensions/forgecli/lib/catalog-types.d.ts +16 -0
  175. package/dist/extensions/forgecli/lib/catalog-types.js +156 -0
  176. package/dist/extensions/forgecli/lib/catalog-types.js.map +1 -0
  177. package/dist/extensions/forgecli/lib/exec-helpers.d.ts +25 -0
  178. package/dist/extensions/forgecli/lib/exec-helpers.js +52 -0
  179. package/dist/extensions/forgecli/lib/exec-helpers.js.map +1 -0
  180. package/dist/extensions/forgecli/lib/forge-config.d.ts +20 -0
  181. package/dist/extensions/forgecli/lib/forge-config.js +43 -0
  182. package/dist/extensions/forgecli/lib/forge-config.js.map +1 -0
  183. package/dist/extensions/forgecli/lib/frontmatter-parser.d.ts +13 -0
  184. package/dist/extensions/forgecli/lib/frontmatter-parser.js +56 -0
  185. package/dist/extensions/forgecli/lib/frontmatter-parser.js.map +1 -0
  186. package/dist/extensions/forgecli/lib/manifest-checker.d.ts +22 -0
  187. package/dist/extensions/forgecli/lib/manifest-checker.js +64 -0
  188. package/dist/extensions/forgecli/lib/manifest-checker.js.map +1 -0
  189. package/dist/extensions/forgecli/lib/orchestrator-preflight.d.ts +46 -0
  190. package/dist/extensions/forgecli/lib/orchestrator-preflight.js +64 -0
  191. package/dist/extensions/forgecli/lib/orchestrator-preflight.js.map +1 -0
  192. package/dist/extensions/forgecli/lib/orchestrator-types.d.ts +20 -0
  193. package/dist/extensions/forgecli/lib/orchestrator-types.js +14 -0
  194. package/dist/extensions/forgecli/lib/orchestrator-types.js.map +1 -0
  195. package/dist/extensions/forgecli/lib/parsers.d.ts +25 -0
  196. package/dist/extensions/forgecli/lib/parsers.js +164 -0
  197. package/dist/extensions/forgecli/lib/parsers.js.map +1 -0
  198. package/dist/extensions/forgecli/lib/shared-fs-utils.d.ts +12 -0
  199. package/dist/extensions/forgecli/lib/shared-fs-utils.js +37 -0
  200. package/dist/extensions/forgecli/lib/shared-fs-utils.js.map +1 -0
  201. package/dist/extensions/forgecli/lib/spawn-store-cli.d.ts +44 -0
  202. package/dist/extensions/forgecli/lib/spawn-store-cli.js +103 -0
  203. package/dist/extensions/forgecli/lib/spawn-store-cli.js.map +1 -0
  204. package/dist/extensions/forgecli/lib/state-helpers.d.ts +33 -0
  205. package/dist/extensions/forgecli/lib/state-helpers.js +69 -0
  206. package/dist/extensions/forgecli/lib/state-helpers.js.map +1 -0
  207. package/dist/extensions/forgecli/lib/store-cli-timeouts.d.ts +4 -0
  208. package/dist/extensions/forgecli/lib/store-cli-timeouts.js +10 -0
  209. package/dist/extensions/forgecli/lib/store-cli-timeouts.js.map +1 -0
  210. package/dist/extensions/forgecli/lib/versions.d.ts +56 -0
  211. package/dist/extensions/forgecli/lib/versions.js +116 -0
  212. package/dist/extensions/forgecli/lib/versions.js.map +1 -0
  213. package/dist/extensions/forgecli/loaders/persona-skill-loader.js +2 -2
  214. package/dist/extensions/forgecli/loaders/persona-skill-loader.js.map +1 -1
  215. package/dist/extensions/forgecli/materialize.js.map +1 -1
  216. package/dist/extensions/forgecli/migrate.js +1 -1
  217. package/dist/extensions/forgecli/migrate.js.map +1 -1
  218. package/dist/extensions/forgecli/migration-engine.d.ts +6 -0
  219. package/dist/extensions/forgecli/migration-engine.js +62 -45
  220. package/dist/extensions/forgecli/migration-engine.js.map +1 -1
  221. package/dist/extensions/forgecli/model-resolver.js.map +1 -1
  222. package/dist/extensions/forgecli/model-validator.js.map +1 -1
  223. package/dist/extensions/forgecli/parsers/persona-skill-loader.d.ts +45 -0
  224. package/dist/extensions/forgecli/parsers/persona-skill-loader.js +201 -0
  225. package/dist/extensions/forgecli/parsers/persona-skill-loader.js.map +1 -0
  226. package/dist/extensions/forgecli/parsers/workflow-loader.d.ts +41 -0
  227. package/dist/extensions/forgecli/parsers/workflow-loader.js +83 -0
  228. package/dist/extensions/forgecli/parsers/workflow-loader.js.map +1 -0
  229. package/dist/extensions/forgecli/paths/migrator.js +2 -7
  230. package/dist/extensions/forgecli/paths/migrator.js.map +1 -1
  231. package/dist/extensions/forgecli/plan.d.ts +4 -6
  232. package/dist/extensions/forgecli/plan.js +9 -73
  233. package/dist/extensions/forgecli/plan.js.map +1 -1
  234. package/dist/extensions/forgecli/quiz-agent.js.map +1 -1
  235. package/dist/extensions/forgecli/read-command.js +1 -1
  236. package/dist/extensions/forgecli/read-command.js.map +1 -1
  237. package/dist/extensions/forgecli/regenerate.js +1 -3
  238. package/dist/extensions/forgecli/regenerate.js.map +1 -1
  239. package/dist/extensions/forgecli/remove-command.js.map +1 -1
  240. package/dist/extensions/forgecli/report-bug.js +2 -2
  241. package/dist/extensions/forgecli/report-bug.js.map +1 -1
  242. package/dist/extensions/forgecli/retrospective.d.ts +2 -1
  243. package/dist/extensions/forgecli/retrospective.js +6 -36
  244. package/dist/extensions/forgecli/retrospective.js.map +1 -1
  245. package/dist/extensions/forgecli/review-code.d.ts +4 -6
  246. package/dist/extensions/forgecli/review-code.js +8 -73
  247. package/dist/extensions/forgecli/review-code.js.map +1 -1
  248. package/dist/extensions/forgecli/review-plan.d.ts +4 -6
  249. package/dist/extensions/forgecli/review-plan.js +8 -73
  250. package/dist/extensions/forgecli/review-plan.js.map +1 -1
  251. package/dist/extensions/forgecli/review-server.js +3 -5
  252. package/dist/extensions/forgecli/review-server.js.map +1 -1
  253. package/dist/extensions/forgecli/run-sprint.d.ts +3 -1
  254. package/dist/extensions/forgecli/run-sprint.js +74 -67
  255. package/dist/extensions/forgecli/run-sprint.js.map +1 -1
  256. package/dist/extensions/forgecli/run-task.d.ts +3 -0
  257. package/dist/extensions/forgecli/run-task.js +136 -105
  258. package/dist/extensions/forgecli/run-task.js.map +1 -1
  259. package/dist/extensions/forgecli/session-registry.js.map +1 -1
  260. package/dist/extensions/forgecli/skill-curation-flag.js +5 -5
  261. package/dist/extensions/forgecli/skill-curation-flag.js.map +1 -1
  262. package/dist/extensions/forgecli/skill-curator-subagent.js +4 -8
  263. package/dist/extensions/forgecli/skill-curator-subagent.js.map +1 -1
  264. package/dist/extensions/forgecli/skill-retriever.js +5 -5
  265. package/dist/extensions/forgecli/skill-retriever.js.map +1 -1
  266. package/dist/extensions/forgecli/skill-usage-tracker.js +5 -5
  267. package/dist/extensions/forgecli/skill-usage-tracker.js.map +1 -1
  268. package/dist/extensions/forgecli/status-command.js.map +1 -1
  269. package/dist/extensions/forgecli/store-error-remediation.d.ts +65 -0
  270. package/dist/extensions/forgecli/store-error-remediation.js +307 -0
  271. package/dist/extensions/forgecli/store-error-remediation.js.map +1 -0
  272. package/dist/extensions/forgecli/store-query.js.map +1 -1
  273. package/dist/extensions/forgecli/store-repair.js.map +1 -1
  274. package/dist/extensions/forgecli/store-resolver.js +4 -13
  275. package/dist/extensions/forgecli/store-resolver.js.map +1 -1
  276. package/dist/extensions/forgecli/store-validator.js +6 -11
  277. package/dist/extensions/forgecli/store-validator.js.map +1 -1
  278. package/dist/extensions/forgecli/subagent/agents.d.ts +4 -0
  279. package/dist/extensions/forgecli/subagent/agents.js +5 -8
  280. package/dist/extensions/forgecli/subagent/agents.js.map +1 -1
  281. package/dist/extensions/forgecli/subagent/index.js +1 -1
  282. package/dist/extensions/forgecli/subagent/index.js.map +1 -1
  283. package/dist/extensions/forgecli/test-orchestrate.js +1 -1
  284. package/dist/extensions/forgecli/test-orchestrate.js.map +1 -1
  285. package/dist/extensions/forgecli/thread-switcher.js +8 -18
  286. package/dist/extensions/forgecli/thread-switcher.js.map +1 -1
  287. package/dist/extensions/forgecli/transition-guard.js +20 -61
  288. package/dist/extensions/forgecli/transition-guard.js.map +1 -1
  289. package/dist/extensions/forgecli/update-tools.js +1 -2
  290. package/dist/extensions/forgecli/update-tools.js.map +1 -1
  291. package/dist/extensions/forgecli/validate.d.ts +4 -6
  292. package/dist/extensions/forgecli/validate.js +8 -73
  293. package/dist/extensions/forgecli/validate.js.map +1 -1
  294. package/dist/extensions/forgecli/viewport-events.js +2 -2
  295. package/dist/extensions/forgecli/viewport-events.js.map +1 -1
  296. package/dist/extensions/forgecli/wf-engine/engine.d.ts +1 -1
  297. package/dist/extensions/forgecli/wf-engine/engine.js +52 -32
  298. package/dist/extensions/forgecli/wf-engine/engine.js.map +1 -1
  299. package/dist/extensions/forgecli/wf-engine/event-parser.js.map +1 -1
  300. package/dist/extensions/forgecli/wf-engine/id-gen.js +4 -1
  301. package/dist/extensions/forgecli/wf-engine/id-gen.js.map +1 -1
  302. package/dist/extensions/forgecli/wf-engine/loader.d.ts +1 -1
  303. package/dist/extensions/forgecli/wf-engine/loader.js +8 -8
  304. package/dist/extensions/forgecli/wf-engine/loader.js.map +1 -1
  305. package/dist/extensions/forgecli/wf-engine/predicate.js +14 -7
  306. package/dist/extensions/forgecli/wf-engine/predicate.js.map +1 -1
  307. package/dist/extensions/forgecli/wf-engine/prompt-compiler.js.map +1 -1
  308. package/dist/extensions/forgecli/wf-engine/register.js +1 -1
  309. package/dist/extensions/forgecli/wf-engine/register.js.map +1 -1
  310. package/dist/extensions/forgecli/wf-engine/remit-check.js +3 -3
  311. package/dist/extensions/forgecli/wf-engine/remit-check.js.map +1 -1
  312. package/dist/extensions/forgecli/wf-engine/state-store.js +7 -3
  313. package/dist/extensions/forgecli/wf-engine/state-store.js.map +1 -1
  314. package/dist/extensions/forgecli/wf-engine/worker.js +3 -3
  315. package/dist/extensions/forgecli/wf-engine/worker.js.map +1 -1
  316. package/dist/extensions/forgecli/whats-new-widget.js +8 -6
  317. package/dist/extensions/forgecli/whats-new-widget.js.map +1 -1
  318. package/dist/extensions/forgecli/whats-new.js +1 -2
  319. package/dist/extensions/forgecli/whats-new.js.map +1 -1
  320. package/dist/forge-payload/.base-pack/skills/architect-skills.md +1 -0
  321. package/dist/forge-payload/.base-pack/skills/bug-fixer-skills.md +1 -0
  322. package/dist/forge-payload/.base-pack/skills/collator-skills.md +1 -0
  323. package/dist/forge-payload/.base-pack/skills/engineer-skills.md +1 -0
  324. package/dist/forge-payload/.base-pack/skills/generic-skills.md +1 -0
  325. package/dist/forge-payload/.base-pack/skills/qa-engineer-skills.md +1 -0
  326. package/dist/forge-payload/.base-pack/skills/supervisor-skills.md +1 -0
  327. package/dist/forge-payload/.base-pack/workflows/_fragments/generation-instructions.md +81 -0
  328. package/dist/forge-payload/.base-pack/workflows/_fragments/iron-laws.md +72 -0
  329. package/dist/forge-payload/.base-pack/workflows/_fragments/store-cli-verbs.md +11 -1
  330. package/dist/forge-payload/.base-pack/workflows/_fragments/store-write-verification.md +11 -0
  331. package/dist/forge-payload/.base-pack/workflows/architect_approve.md +11 -12
  332. package/dist/forge-payload/.base-pack/workflows/architect_review_sprint_completion.md +4 -1
  333. package/dist/forge-payload/.base-pack/workflows/architect_sprint_intake.md +10 -1
  334. package/dist/forge-payload/.base-pack/workflows/architect_sprint_plan.md +8 -1
  335. package/dist/forge-payload/.base-pack/workflows/collator_agent.md +18 -1
  336. package/dist/forge-payload/.base-pack/workflows/commit_task.md +5 -10
  337. package/dist/forge-payload/.base-pack/workflows/enhance.md +7 -0
  338. package/dist/forge-payload/.base-pack/workflows/fix_bug.md +9 -2
  339. package/dist/forge-payload/.base-pack/workflows/implement_plan.md +22 -35
  340. package/dist/forge-payload/.base-pack/workflows/migrate_structural.md +9 -0
  341. package/dist/forge-payload/.base-pack/workflows/orchestrate_task.md +4 -0
  342. package/dist/forge-payload/.base-pack/workflows/plan_task.md +17 -21
  343. package/dist/forge-payload/.base-pack/workflows/review_code.md +13 -20
  344. package/dist/forge-payload/.base-pack/workflows/review_plan.md +10 -21
  345. package/dist/forge-payload/.base-pack/workflows/sprint_retrospective.md +10 -1
  346. package/dist/forge-payload/.base-pack/workflows/update_implementation.md +5 -10
  347. package/dist/forge-payload/.base-pack/workflows/update_plan.md +5 -10
  348. package/dist/forge-payload/.base-pack/workflows/validate_task.md +11 -12
  349. package/dist/forge-payload/.claude-plugin/plugin.json +5 -5
  350. package/dist/forge-payload/.schemas/_defs/phaseSummary.schema.json +18 -0
  351. package/dist/forge-payload/.schemas/bug.schema.json +8 -24
  352. package/dist/forge-payload/.schemas/config.schema.json +165 -33
  353. package/dist/forge-payload/.schemas/enum-catalog.json +71 -0
  354. package/dist/forge-payload/.schemas/migrations.json +371 -149
  355. package/dist/forge-payload/.schemas/task.schema.json +6 -21
  356. package/dist/forge-payload/.schemas/transitions/bug.json +31 -0
  357. package/dist/forge-payload/.schemas/transitions/sprint.json +46 -0
  358. package/dist/forge-payload/.schemas/transitions/task.json +109 -0
  359. package/dist/forge-payload/commands/health.md +3 -3
  360. package/dist/forge-payload/hooks/check-update.cjs +255 -0
  361. package/dist/forge-payload/hooks/forge-permissions.cjs +171 -0
  362. package/dist/forge-payload/hooks/forge-permissions.js +6 -0
  363. package/dist/forge-payload/hooks/post-init.cjs +120 -0
  364. package/dist/forge-payload/hooks/post-sprint.cjs +108 -0
  365. package/dist/forge-payload/hooks/triage-error.cjs +104 -0
  366. package/dist/forge-payload/hooks/triage-error.js +6 -0
  367. package/dist/forge-payload/hooks/validate-write.cjs +250 -0
  368. package/dist/forge-payload/hooks/validate-write.js +25 -11
  369. package/dist/forge-payload/integrity.json +13 -7
  370. package/dist/forge-payload/meta/workflows/_fragments/generation-instructions.md +81 -0
  371. package/dist/forge-payload/meta/workflows/_fragments/iron-laws.md +72 -0
  372. package/dist/forge-payload/meta/workflows/_fragments/store-cli-verbs.md +11 -1
  373. package/dist/forge-payload/meta/workflows/_fragments/store-write-verification.md +11 -0
  374. package/dist/forge-payload/meta/workflows/meta-approve.md +9 -11
  375. package/dist/forge-payload/meta/workflows/meta-collate.md +16 -0
  376. package/dist/forge-payload/meta/workflows/meta-commit.md +3 -9
  377. package/dist/forge-payload/meta/workflows/meta-enhance.md +16 -1
  378. package/dist/forge-payload/meta/workflows/meta-fix-bug.md +8 -2
  379. package/dist/forge-payload/meta/workflows/meta-implement.md +20 -35
  380. package/dist/forge-payload/meta/workflows/meta-migrate.md +18 -0
  381. package/dist/forge-payload/meta/workflows/meta-orchestrate.md +2 -0
  382. package/dist/forge-payload/meta/workflows/meta-plan-task.md +15 -21
  383. package/dist/forge-payload/meta/workflows/meta-quiz-agent.md +4 -1
  384. package/dist/forge-payload/meta/workflows/meta-retrospective.md +8 -0
  385. package/dist/forge-payload/meta/workflows/meta-review-implementation.md +11 -19
  386. package/dist/forge-payload/meta/workflows/meta-review-plan.md +10 -16
  387. package/dist/forge-payload/meta/workflows/meta-review-sprint-completion.md +3 -0
  388. package/dist/forge-payload/meta/workflows/meta-sprint-intake.md +8 -0
  389. package/dist/forge-payload/meta/workflows/meta-sprint-plan.md +5 -0
  390. package/dist/forge-payload/meta/workflows/meta-update-implementation.md +3 -9
  391. package/dist/forge-payload/meta/workflows/meta-update-plan.md +3 -9
  392. package/dist/forge-payload/meta/workflows/meta-validate.md +9 -11
  393. package/dist/forge-payload/schemas/structure-manifest.json +8 -6
  394. package/dist/forge-payload/tools/build-context-pack.cjs +3 -2
  395. package/dist/forge-payload/tools/friction-emit.cjs +2 -1
  396. package/dist/forge-payload/tools/lib/frontmatter.cjs +62 -0
  397. package/dist/forge-payload/tools/lib/fsutil.cjs +61 -0
  398. package/dist/forge-payload/tools/lib/json-io.cjs +43 -0
  399. package/dist/forge-payload/tools/lib/schema-loader.cjs +139 -0
  400. package/dist/forge-payload/tools/lib/slug.cjs +39 -0
  401. package/dist/forge-payload/tools/lib/store-facade.cjs +6 -5
  402. package/dist/forge-payload/tools/preflight-gate.cjs +55 -7
  403. package/dist/forge-payload/tools/seed-store.cjs +1 -13
  404. package/dist/forge-payload/tools/store-cli.cjs +55 -108
  405. package/dist/forge-payload/tools/store.cjs +26 -37
  406. package/dist/forge-payload/tools/substitute-placeholders.cjs +74 -35
  407. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts +1 -1
  408. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.d.ts.map +1 -1
  409. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +23 -0
  410. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
  411. package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts +2 -2
  412. package/node_modules/@earendil-works/pi-agent-core/dist/agent.d.ts.map +1 -1
  413. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js +1 -1
  414. package/node_modules/@earendil-works/pi-agent-core/dist/agent.js.map +1 -1
  415. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.d.ts +2 -2
  416. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.d.ts.map +1 -1
  417. package/node_modules/@earendil-works/pi-agent-core/dist/harness/agent-harness.js.map +1 -1
  418. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.d.ts +5 -5
  419. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.d.ts.map +1 -1
  420. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/branch-summarization.js.map +1 -1
  421. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.d.ts +4 -4
  422. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.d.ts.map +1 -1
  423. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.js.map +1 -1
  424. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.d.ts +1 -1
  425. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.d.ts.map +1 -1
  426. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/utils.js.map +1 -1
  427. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.d.ts +1 -1
  428. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.d.ts.map +1 -1
  429. package/node_modules/@earendil-works/pi-agent-core/dist/harness/env/nodejs.js.map +1 -1
  430. package/node_modules/@earendil-works/pi-agent-core/dist/harness/execution-env.d.ts +4 -0
  431. package/node_modules/@earendil-works/pi-agent-core/dist/harness/execution-env.d.ts.map +1 -0
  432. package/node_modules/@earendil-works/pi-agent-core/dist/harness/execution-env.js +3 -0
  433. package/node_modules/@earendil-works/pi-agent-core/dist/harness/execution-env.js.map +1 -0
  434. package/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.d.ts +2 -2
  435. package/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.d.ts.map +1 -1
  436. package/node_modules/@earendil-works/pi-agent-core/dist/harness/messages.js.map +1 -1
  437. package/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.d.ts +1 -1
  438. package/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.d.ts.map +1 -1
  439. package/node_modules/@earendil-works/pi-agent-core/dist/harness/prompt-templates.js.map +1 -1
  440. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.d.ts +1 -1
  441. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.d.ts.map +1 -1
  442. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-repo.js.map +1 -1
  443. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.d.ts +1 -1
  444. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.d.ts.map +1 -1
  445. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/jsonl-storage.js.map +1 -1
  446. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.d.ts +1 -1
  447. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.d.ts.map +1 -1
  448. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-repo.js.map +1 -1
  449. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.d.ts +1 -1
  450. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.d.ts.map +1 -1
  451. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/memory-storage.js.map +1 -1
  452. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/jsonl.d.ts +20 -0
  453. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/jsonl.d.ts.map +1 -0
  454. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/jsonl.js +92 -0
  455. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/jsonl.js.map +1 -0
  456. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/memory.d.ts +18 -0
  457. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/memory.d.ts.map +1 -0
  458. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/memory.js +42 -0
  459. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/memory.js.map +1 -0
  460. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/shared.d.ts +10 -0
  461. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/shared.d.ts.map +1 -0
  462. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/shared.js +31 -0
  463. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo/shared.js.map +1 -0
  464. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.d.ts +2 -2
  465. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.d.ts.map +1 -1
  466. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/repo-utils.js.map +1 -1
  467. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.d.ts +2 -2
  468. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.d.ts.map +1 -1
  469. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/session.js.map +1 -1
  470. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/storage/jsonl.d.ts +30 -0
  471. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/storage/jsonl.d.ts.map +1 -0
  472. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/storage/jsonl.js +170 -0
  473. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/storage/jsonl.js.map +1 -0
  474. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/storage/memory.d.ts +26 -0
  475. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/storage/memory.d.ts.map +1 -0
  476. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/storage/memory.js +90 -0
  477. package/node_modules/@earendil-works/pi-agent-core/dist/harness/session/storage/memory.js.map +1 -0
  478. package/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.d.ts +1 -1
  479. package/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.d.ts.map +1 -1
  480. package/node_modules/@earendil-works/pi-agent-core/dist/harness/skills.js.map +1 -1
  481. package/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.d.ts +1 -1
  482. package/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.d.ts.map +1 -1
  483. package/node_modules/@earendil-works/pi-agent-core/dist/harness/system-prompt.js.map +1 -1
  484. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.d.ts +10 -22
  485. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.d.ts.map +1 -1
  486. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js +17 -23
  487. package/node_modules/@earendil-works/pi-agent-core/dist/harness/types.js.map +1 -1
  488. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.d.ts +1 -1
  489. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.d.ts.map +1 -1
  490. package/node_modules/@earendil-works/pi-agent-core/dist/harness/utils/shell-output.js.map +1 -1
  491. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts +19 -19
  492. package/node_modules/@earendil-works/pi-agent-core/dist/index.d.ts.map +1 -1
  493. package/node_modules/@earendil-works/pi-agent-core/dist/index.js.map +1 -1
  494. package/node_modules/@earendil-works/pi-agent-core/dist/node.d.ts +2 -2
  495. package/node_modules/@earendil-works/pi-agent-core/dist/node.d.ts.map +1 -1
  496. package/node_modules/@earendil-works/pi-agent-core/dist/node.js.map +1 -1
  497. package/node_modules/@earendil-works/pi-agent-core/package.json +9 -10
  498. package/node_modules/@earendil-works/pi-ai/dist/api-registry.d.ts +1 -1
  499. package/node_modules/@earendil-works/pi-ai/dist/api-registry.d.ts.map +1 -1
  500. package/node_modules/@earendil-works/pi-ai/dist/api-registry.js.map +1 -1
  501. package/node_modules/@earendil-works/pi-ai/dist/bedrock-provider.d.ts +2 -2
  502. package/node_modules/@earendil-works/pi-ai/dist/bedrock-provider.d.ts.map +1 -1
  503. package/node_modules/@earendil-works/pi-ai/dist/bedrock-provider.js.map +1 -1
  504. package/node_modules/@earendil-works/pi-ai/dist/cli.d.ts.map +1 -1
  505. package/node_modules/@earendil-works/pi-ai/dist/cli.js +14 -0
  506. package/node_modules/@earendil-works/pi-ai/dist/cli.js.map +1 -1
  507. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts +1 -1
  508. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.d.ts.map +1 -1
  509. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +10 -2
  510. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js.map +1 -1
  511. package/node_modules/@earendil-works/pi-ai/dist/image-models.d.ts +2 -2
  512. package/node_modules/@earendil-works/pi-ai/dist/image-models.d.ts.map +1 -1
  513. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.d.ts.map +1 -1
  514. package/node_modules/@earendil-works/pi-ai/dist/image-models.generated.js.map +1 -1
  515. package/node_modules/@earendil-works/pi-ai/dist/image-models.js.map +1 -1
  516. package/node_modules/@earendil-works/pi-ai/dist/images-api-registry.d.ts +1 -1
  517. package/node_modules/@earendil-works/pi-ai/dist/images-api-registry.d.ts.map +1 -1
  518. package/node_modules/@earendil-works/pi-ai/dist/images-api-registry.js.map +1 -1
  519. package/node_modules/@earendil-works/pi-ai/dist/images.d.ts +2 -2
  520. package/node_modules/@earendil-works/pi-ai/dist/images.d.ts.map +1 -1
  521. package/node_modules/@earendil-works/pi-ai/dist/images.js.map +1 -1
  522. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +29 -29
  523. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
  524. package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
  525. package/node_modules/@earendil-works/pi-ai/dist/models.d.ts +2 -2
  526. package/node_modules/@earendil-works/pi-ai/dist/models.d.ts.map +1 -1
  527. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts +317 -509
  528. package/node_modules/@earendil-works/pi-ai/dist/models.generated.d.ts.map +1 -1
  529. package/node_modules/@earendil-works/pi-ai/dist/models.generated.js +400 -620
  530. package/node_modules/@earendil-works/pi-ai/dist/models.generated.js.map +1 -1
  531. package/node_modules/@earendil-works/pi-ai/dist/models.js.map +1 -1
  532. package/node_modules/@earendil-works/pi-ai/dist/oauth.d.ts +1 -1
  533. package/node_modules/@earendil-works/pi-ai/dist/oauth.d.ts.map +1 -1
  534. package/node_modules/@earendil-works/pi-ai/dist/oauth.js.map +1 -1
  535. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.d.ts +1 -1
  536. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.d.ts.map +1 -1
  537. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js +5 -2
  538. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js.map +1 -1
  539. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.d.ts +23 -6
  540. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.d.ts.map +1 -1
  541. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js +11 -23
  542. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js.map +1 -1
  543. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.d.ts +1 -1
  544. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.d.ts.map +1 -1
  545. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.js +2 -1
  546. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.js.map +1 -1
  547. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare.d.ts +1 -1
  548. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare.d.ts.map +1 -1
  549. package/node_modules/@earendil-works/pi-ai/dist/providers/cloudflare.js.map +1 -1
  550. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts +1 -1
  551. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.d.ts.map +1 -1
  552. package/node_modules/@earendil-works/pi-ai/dist/providers/faux.js.map +1 -1
  553. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot-headers.d.ts +1 -1
  554. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot-headers.d.ts.map +1 -1
  555. package/node_modules/@earendil-works/pi-ai/dist/providers/github-copilot-headers.js.map +1 -1
  556. package/node_modules/@earendil-works/pi-ai/dist/providers/google-shared.d.ts +1 -1
  557. package/node_modules/@earendil-works/pi-ai/dist/providers/google-shared.d.ts.map +1 -1
  558. package/node_modules/@earendil-works/pi-ai/dist/providers/google-shared.js.map +1 -1
  559. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.d.ts +2 -2
  560. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.d.ts.map +1 -1
  561. package/node_modules/@earendil-works/pi-ai/dist/providers/google-vertex.js.map +1 -1
  562. package/node_modules/@earendil-works/pi-ai/dist/providers/google.d.ts +2 -2
  563. package/node_modules/@earendil-works/pi-ai/dist/providers/google.d.ts.map +1 -1
  564. package/node_modules/@earendil-works/pi-ai/dist/providers/google.js.map +1 -1
  565. package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.d.ts +1 -1
  566. package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.d.ts.map +1 -1
  567. package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.js.map +1 -1
  568. package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.d.ts +1 -1
  569. package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.d.ts.map +1 -1
  570. package/node_modules/@earendil-works/pi-ai/dist/providers/images/register-builtins.js.map +1 -1
  571. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.d.ts +1 -1
  572. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.d.ts.map +1 -1
  573. package/node_modules/@earendil-works/pi-ai/dist/providers/mistral.js.map +1 -1
  574. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.d.ts +1 -1
  575. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.d.ts.map +1 -1
  576. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.js +12 -3
  577. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.js.map +1 -1
  578. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.d.ts +1 -1
  579. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.d.ts.map +1 -1
  580. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.js +2 -1
  581. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.js.map +1 -1
  582. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-prompt-cache.d.ts +3 -0
  583. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-prompt-cache.d.ts.map +1 -0
  584. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-prompt-cache.js +10 -0
  585. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-prompt-cache.js.map +1 -0
  586. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses-shared.d.ts +2 -2
  587. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses-shared.d.ts.map +1 -1
  588. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses-shared.js.map +1 -1
  589. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.d.ts +1 -1
  590. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.d.ts.map +1 -1
  591. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.js +2 -1
  592. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.js.map +1 -1
  593. package/node_modules/@earendil-works/pi-ai/dist/providers/register-builtins.d.ts +10 -10
  594. package/node_modules/@earendil-works/pi-ai/dist/providers/register-builtins.d.ts.map +1 -1
  595. package/node_modules/@earendil-works/pi-ai/dist/providers/register-builtins.js +13 -2
  596. package/node_modules/@earendil-works/pi-ai/dist/providers/register-builtins.js.map +1 -1
  597. package/node_modules/@earendil-works/pi-ai/dist/providers/simple-options.d.ts +3 -3
  598. package/node_modules/@earendil-works/pi-ai/dist/providers/simple-options.d.ts.map +1 -1
  599. package/node_modules/@earendil-works/pi-ai/dist/providers/simple-options.js +6 -11
  600. package/node_modules/@earendil-works/pi-ai/dist/providers/simple-options.js.map +1 -1
  601. package/node_modules/@earendil-works/pi-ai/dist/providers/transform-messages.d.ts +1 -1
  602. package/node_modules/@earendil-works/pi-ai/dist/providers/transform-messages.d.ts.map +1 -1
  603. package/node_modules/@earendil-works/pi-ai/dist/providers/transform-messages.js.map +1 -1
  604. package/node_modules/@earendil-works/pi-ai/dist/stream.d.ts +3 -3
  605. package/node_modules/@earendil-works/pi-ai/dist/stream.d.ts.map +1 -1
  606. package/node_modules/@earendil-works/pi-ai/dist/stream.js.map +1 -1
  607. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts +13 -3
  608. package/node_modules/@earendil-works/pi-ai/dist/types.d.ts.map +1 -1
  609. package/node_modules/@earendil-works/pi-ai/dist/types.js.map +1 -1
  610. package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.d.ts +3 -3
  611. package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.d.ts.map +1 -1
  612. package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.js +2 -2
  613. package/node_modules/@earendil-works/pi-ai/dist/utils/event-stream.js.map +1 -1
  614. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.d.ts +1 -1
  615. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.d.ts.map +1 -1
  616. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/anthropic.js.map +1 -1
  617. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.d.ts +19 -0
  618. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.d.ts.map +1 -0
  619. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.js +55 -0
  620. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.js.map +1 -0
  621. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.d.ts +3 -3
  622. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.d.ts.map +1 -1
  623. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js +45 -69
  624. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js.map +1 -1
  625. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.d.ts +6 -5
  626. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.d.ts.map +1 -1
  627. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.js +1 -0
  628. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.js.map +1 -1
  629. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.d.ts +1 -1
  630. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.d.ts.map +1 -1
  631. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.js +1 -1
  632. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/openai-codex.js.map +1 -1
  633. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.d.ts +9 -2
  634. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.d.ts.map +1 -1
  635. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/types.js.map +1 -1
  636. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts +1 -1
  637. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.d.ts.map +1 -1
  638. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js.map +1 -1
  639. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.d.ts +1 -1
  640. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.d.ts.map +1 -1
  641. package/node_modules/@earendil-works/pi-ai/dist/utils/validation.js.map +1 -1
  642. package/node_modules/@earendil-works/pi-ai/package.json +15 -16
  643. package/node_modules/@earendil-works/pi-coding-agent/CHANGELOG.md +55 -0
  644. package/node_modules/@earendil-works/pi-coding-agent/README.md +6 -4
  645. package/node_modules/@earendil-works/pi-coding-agent/dist/bun/cli.d.ts.map +1 -1
  646. package/node_modules/@earendil-works/pi-coding-agent/dist/bun/cli.js.map +1 -1
  647. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/args.d.ts +1 -1
  648. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/args.d.ts.map +1 -1
  649. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/args.js.map +1 -1
  650. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/config-selector.d.ts +2 -2
  651. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/config-selector.d.ts.map +1 -1
  652. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/config-selector.js.map +1 -1
  653. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/file-processor.d.ts.map +1 -1
  654. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/file-processor.js.map +1 -1
  655. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/initial-message.d.ts +1 -1
  656. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/initial-message.d.ts.map +1 -1
  657. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/initial-message.js.map +1 -1
  658. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/list-models.d.ts +1 -1
  659. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/list-models.d.ts.map +1 -1
  660. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/list-models.js.map +1 -1
  661. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/session-picker.d.ts +1 -1
  662. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/session-picker.d.ts.map +1 -1
  663. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/session-picker.js.map +1 -1
  664. package/node_modules/@earendil-works/pi-coding-agent/dist/cli.d.ts.map +1 -1
  665. package/node_modules/@earendil-works/pi-coding-agent/dist/cli.js +4 -10
  666. package/node_modules/@earendil-works/pi-coding-agent/dist/cli.js.map +1 -1
  667. package/node_modules/@earendil-works/pi-coding-agent/dist/config.d.ts.map +1 -1
  668. package/node_modules/@earendil-works/pi-coding-agent/dist/config.js +13 -14
  669. package/node_modules/@earendil-works/pi-coding-agent/dist/config.js.map +1 -1
  670. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-runtime.d.ts +9 -9
  671. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-runtime.d.ts.map +1 -1
  672. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-runtime.js +6 -6
  673. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-runtime.js.map +1 -1
  674. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-services.d.ts +7 -7
  675. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-services.d.ts.map +1 -1
  676. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-services.js +3 -2
  677. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-services.js.map +1 -1
  678. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.d.ts +23 -21
  679. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.d.ts.map +1 -1
  680. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.js +99 -137
  681. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.js.map +1 -1
  682. package/node_modules/@earendil-works/pi-coding-agent/dist/core/auth-guidance.d.ts.map +1 -1
  683. package/node_modules/@earendil-works/pi-coding-agent/dist/core/auth-guidance.js.map +1 -1
  684. package/node_modules/@earendil-works/pi-coding-agent/dist/core/auth-storage.d.ts +1 -1
  685. package/node_modules/@earendil-works/pi-coding-agent/dist/core/auth-storage.d.ts.map +1 -1
  686. package/node_modules/@earendil-works/pi-coding-agent/dist/core/auth-storage.js +3 -2
  687. package/node_modules/@earendil-works/pi-coding-agent/dist/core/auth-storage.js.map +1 -1
  688. package/node_modules/@earendil-works/pi-coding-agent/dist/core/bash-executor.d.ts +1 -1
  689. package/node_modules/@earendil-works/pi-coding-agent/dist/core/bash-executor.d.ts.map +1 -1
  690. package/node_modules/@earendil-works/pi-coding-agent/dist/core/bash-executor.js.map +1 -1
  691. package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/branch-summarization.d.ts +3 -3
  692. package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  693. package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/branch-summarization.js.map +1 -1
  694. package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/compaction.d.ts +2 -2
  695. package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/compaction.d.ts.map +1 -1
  696. package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/compaction.js.map +1 -1
  697. package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/index.d.ts +3 -3
  698. package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/index.d.ts.map +1 -1
  699. package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/index.js.map +1 -1
  700. package/node_modules/@earendil-works/pi-coding-agent/dist/core/exec.d.ts.map +1 -1
  701. package/node_modules/@earendil-works/pi-coding-agent/dist/core/exec.js.map +1 -1
  702. package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/index.d.ts +1 -1
  703. package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/index.d.ts.map +1 -1
  704. package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/index.js +8 -6
  705. package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/index.js.map +1 -1
  706. package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/template.js +6 -3
  707. package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/tool-renderer.d.ts +2 -2
  708. package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  709. package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/tool-renderer.js.map +1 -1
  710. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/index.d.ts +8 -8
  711. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/index.d.ts.map +1 -1
  712. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/index.js.map +1 -1
  713. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/loader.d.ts +2 -2
  714. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
  715. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/loader.js +12 -29
  716. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
  717. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/runner.d.ts +6 -6
  718. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/runner.d.ts.map +1 -1
  719. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/runner.js.map +1 -1
  720. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/types.d.ts +19 -19
  721. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/types.d.ts.map +1 -1
  722. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/types.js.map +1 -1
  723. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/wrapper.d.ts +2 -2
  724. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/wrapper.d.ts.map +1 -1
  725. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/wrapper.js.map +1 -1
  726. package/node_modules/@earendil-works/pi-coding-agent/dist/core/footer-data-provider.d.ts.map +1 -1
  727. package/node_modules/@earendil-works/pi-coding-agent/dist/core/footer-data-provider.js.map +1 -1
  728. package/node_modules/@earendil-works/pi-coding-agent/dist/core/http-dispatcher.d.ts +21 -0
  729. package/node_modules/@earendil-works/pi-coding-agent/dist/core/http-dispatcher.d.ts.map +1 -0
  730. package/node_modules/@earendil-works/pi-coding-agent/dist/core/http-dispatcher.js +48 -0
  731. package/node_modules/@earendil-works/pi-coding-agent/dist/core/http-dispatcher.js.map +1 -0
  732. package/node_modules/@earendil-works/pi-coding-agent/dist/core/index.d.ts +8 -8
  733. package/node_modules/@earendil-works/pi-coding-agent/dist/core/index.d.ts.map +1 -1
  734. package/node_modules/@earendil-works/pi-coding-agent/dist/core/index.js.map +1 -1
  735. package/node_modules/@earendil-works/pi-coding-agent/dist/core/keybindings.d.ts.map +1 -1
  736. package/node_modules/@earendil-works/pi-coding-agent/dist/core/keybindings.js.map +1 -1
  737. package/node_modules/@earendil-works/pi-coding-agent/dist/core/model-registry.d.ts +4 -4
  738. package/node_modules/@earendil-works/pi-coding-agent/dist/core/model-registry.d.ts.map +1 -1
  739. package/node_modules/@earendil-works/pi-coding-agent/dist/core/model-registry.js +7 -3
  740. package/node_modules/@earendil-works/pi-coding-agent/dist/core/model-registry.js.map +1 -1
  741. package/node_modules/@earendil-works/pi-coding-agent/dist/core/model-resolver.d.ts +1 -1
  742. package/node_modules/@earendil-works/pi-coding-agent/dist/core/model-resolver.d.ts.map +1 -1
  743. package/node_modules/@earendil-works/pi-coding-agent/dist/core/model-resolver.js.map +1 -1
  744. package/node_modules/@earendil-works/pi-coding-agent/dist/core/package-manager.d.ts +2 -1
  745. package/node_modules/@earendil-works/pi-coding-agent/dist/core/package-manager.d.ts.map +1 -1
  746. package/node_modules/@earendil-works/pi-coding-agent/dist/core/package-manager.js +48 -32
  747. package/node_modules/@earendil-works/pi-coding-agent/dist/core/package-manager.js.map +1 -1
  748. package/node_modules/@earendil-works/pi-coding-agent/dist/core/prompt-templates.d.ts +1 -1
  749. package/node_modules/@earendil-works/pi-coding-agent/dist/core/prompt-templates.d.ts.map +1 -1
  750. package/node_modules/@earendil-works/pi-coding-agent/dist/core/prompt-templates.js +6 -20
  751. package/node_modules/@earendil-works/pi-coding-agent/dist/core/prompt-templates.js.map +1 -1
  752. package/node_modules/@earendil-works/pi-coding-agent/dist/core/resolve-config-value.d.ts.map +1 -1
  753. package/node_modules/@earendil-works/pi-coding-agent/dist/core/resolve-config-value.js.map +1 -1
  754. package/node_modules/@earendil-works/pi-coding-agent/dist/core/resource-loader.d.ts +9 -9
  755. package/node_modules/@earendil-works/pi-coding-agent/dist/core/resource-loader.d.ts.map +1 -1
  756. package/node_modules/@earendil-works/pi-coding-agent/dist/core/resource-loader.js +38 -31
  757. package/node_modules/@earendil-works/pi-coding-agent/dist/core/resource-loader.js.map +1 -1
  758. package/node_modules/@earendil-works/pi-coding-agent/dist/core/sdk.d.ts +13 -13
  759. package/node_modules/@earendil-works/pi-coding-agent/dist/core/sdk.d.ts.map +1 -1
  760. package/node_modules/@earendil-works/pi-coding-agent/dist/core/sdk.js +9 -4
  761. package/node_modules/@earendil-works/pi-coding-agent/dist/core/sdk.js.map +1 -1
  762. package/node_modules/@earendil-works/pi-coding-agent/dist/core/session-manager.d.ts +1 -1
  763. package/node_modules/@earendil-works/pi-coding-agent/dist/core/session-manager.d.ts.map +1 -1
  764. package/node_modules/@earendil-works/pi-coding-agent/dist/core/session-manager.js +32 -24
  765. package/node_modules/@earendil-works/pi-coding-agent/dist/core/session-manager.js.map +1 -1
  766. package/node_modules/@earendil-works/pi-coding-agent/dist/core/settings-manager.d.ts +3 -0
  767. package/node_modules/@earendil-works/pi-coding-agent/dist/core/settings-manager.d.ts.map +1 -1
  768. package/node_modules/@earendil-works/pi-coding-agent/dist/core/settings-manager.js +26 -13
  769. package/node_modules/@earendil-works/pi-coding-agent/dist/core/settings-manager.js.map +1 -1
  770. package/node_modules/@earendil-works/pi-coding-agent/dist/core/skills.d.ts +2 -2
  771. package/node_modules/@earendil-works/pi-coding-agent/dist/core/skills.d.ts.map +1 -1
  772. package/node_modules/@earendil-works/pi-coding-agent/dist/core/skills.js +8 -22
  773. package/node_modules/@earendil-works/pi-coding-agent/dist/core/skills.js.map +1 -1
  774. package/node_modules/@earendil-works/pi-coding-agent/dist/core/slash-commands.d.ts +1 -1
  775. package/node_modules/@earendil-works/pi-coding-agent/dist/core/slash-commands.d.ts.map +1 -1
  776. package/node_modules/@earendil-works/pi-coding-agent/dist/core/slash-commands.js.map +1 -1
  777. package/node_modules/@earendil-works/pi-coding-agent/dist/core/source-info.d.ts +1 -1
  778. package/node_modules/@earendil-works/pi-coding-agent/dist/core/source-info.d.ts.map +1 -1
  779. package/node_modules/@earendil-works/pi-coding-agent/dist/core/source-info.js.map +1 -1
  780. package/node_modules/@earendil-works/pi-coding-agent/dist/core/system-prompt.d.ts +1 -1
  781. package/node_modules/@earendil-works/pi-coding-agent/dist/core/system-prompt.d.ts.map +1 -1
  782. package/node_modules/@earendil-works/pi-coding-agent/dist/core/system-prompt.js +1 -0
  783. package/node_modules/@earendil-works/pi-coding-agent/dist/core/system-prompt.js.map +1 -1
  784. package/node_modules/@earendil-works/pi-coding-agent/dist/core/telemetry.d.ts +1 -1
  785. package/node_modules/@earendil-works/pi-coding-agent/dist/core/telemetry.d.ts.map +1 -1
  786. package/node_modules/@earendil-works/pi-coding-agent/dist/core/telemetry.js.map +1 -1
  787. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/bash.d.ts +2 -2
  788. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/bash.d.ts.map +1 -1
  789. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/bash.js +9 -3
  790. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/bash.js.map +1 -1
  791. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit-diff.d.ts +3 -1
  792. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit-diff.d.ts.map +1 -1
  793. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit-diff.js +8 -1
  794. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit-diff.js.map +1 -1
  795. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit.d.ts +5 -3
  796. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit.d.ts.map +1 -1
  797. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit.js +3 -2
  798. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit.js.map +1 -1
  799. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/find.d.ts +2 -2
  800. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/find.d.ts.map +1 -1
  801. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/find.js.map +1 -1
  802. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/grep.d.ts +2 -2
  803. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/grep.d.ts.map +1 -1
  804. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/grep.js.map +1 -1
  805. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/index.d.ts +17 -17
  806. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/index.d.ts.map +1 -1
  807. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/index.js.map +1 -1
  808. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/ls.d.ts +2 -2
  809. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/ls.d.ts.map +1 -1
  810. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/ls.js.map +1 -1
  811. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/output-accumulator.d.ts +3 -1
  812. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/output-accumulator.d.ts.map +1 -1
  813. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/output-accumulator.js +9 -3
  814. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/output-accumulator.js.map +1 -1
  815. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/path-utils.d.ts.map +1 -1
  816. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/path-utils.js +3 -22
  817. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/path-utils.js.map +1 -1
  818. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/read.d.ts +2 -2
  819. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/read.d.ts.map +1 -1
  820. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/read.js.map +1 -1
  821. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/render-utils.d.ts.map +1 -1
  822. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/render-utils.js.map +1 -1
  823. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/tool-definition-wrapper.d.ts +1 -1
  824. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
  825. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/tool-definition-wrapper.js.map +1 -1
  826. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/truncate.d.ts.map +1 -1
  827. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/truncate.js +12 -2
  828. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/truncate.js.map +1 -1
  829. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/write.d.ts +1 -1
  830. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/write.d.ts.map +1 -1
  831. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/write.js.map +1 -1
  832. package/node_modules/@earendil-works/pi-coding-agent/dist/index.d.ts +30 -29
  833. package/node_modules/@earendil-works/pi-coding-agent/dist/index.d.ts.map +1 -1
  834. package/node_modules/@earendil-works/pi-coding-agent/dist/index.js +2 -1
  835. package/node_modules/@earendil-works/pi-coding-agent/dist/index.js.map +1 -1
  836. package/node_modules/@earendil-works/pi-coding-agent/dist/main.d.ts +1 -1
  837. package/node_modules/@earendil-works/pi-coding-agent/dist/main.d.ts.map +1 -1
  838. package/node_modules/@earendil-works/pi-coding-agent/dist/main.js +7 -6
  839. package/node_modules/@earendil-works/pi-coding-agent/dist/main.js.map +1 -1
  840. package/node_modules/@earendil-works/pi-coding-agent/dist/migrations.d.ts.map +1 -1
  841. package/node_modules/@earendil-works/pi-coding-agent/dist/migrations.js.map +1 -1
  842. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/index.d.ts +5 -5
  843. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/index.d.ts.map +1 -1
  844. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/index.js.map +1 -1
  845. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/armin.d.ts.map +1 -1
  846. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/armin.js.map +1 -1
  847. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  848. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/assistant-message.js.map +1 -1
  849. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/bash-execution.d.ts +1 -1
  850. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  851. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/bash-execution.js.map +1 -1
  852. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/bordered-loader.d.ts +1 -1
  853. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  854. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  855. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/branch-summary-message.d.ts +1 -1
  856. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  857. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  858. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.d.ts +1 -1
  859. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  860. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  861. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/config-selector.d.ts +2 -2
  862. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  863. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/config-selector.js +1 -1
  864. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/config-selector.js.map +1 -1
  865. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/countdown-timer.d.ts +2 -2
  866. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/countdown-timer.d.ts.map +1 -1
  867. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/countdown-timer.js +2 -2
  868. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/countdown-timer.js.map +1 -1
  869. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/custom-editor.d.ts +1 -1
  870. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  871. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/custom-editor.js.map +1 -1
  872. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/custom-message.d.ts +2 -2
  873. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/custom-message.d.ts.map +1 -1
  874. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/custom-message.js.map +1 -1
  875. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/daxnuts.d.ts.map +1 -1
  876. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/daxnuts.js.map +1 -1
  877. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/diff.d.ts.map +1 -1
  878. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/diff.js.map +1 -1
  879. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/dynamic-border.d.ts.map +1 -1
  880. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/dynamic-border.js.map +1 -1
  881. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/earendil-announcement.d.ts.map +1 -1
  882. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/earendil-announcement.js.map +1 -1
  883. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/extension-editor.d.ts +1 -1
  884. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  885. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/extension-editor.js.map +1 -1
  886. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  887. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/extension-input.js.map +1 -1
  888. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  889. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/extension-selector.js.map +1 -1
  890. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/footer.d.ts +4 -3
  891. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/footer.d.ts.map +1 -1
  892. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/footer.js +16 -7
  893. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/footer.js.map +1 -1
  894. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/index.d.ts +31 -31
  895. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/index.d.ts.map +1 -1
  896. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/index.js.map +1 -1
  897. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  898. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  899. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/login-dialog.d.ts +10 -2
  900. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  901. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/login-dialog.js +31 -6
  902. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/login-dialog.js.map +1 -1
  903. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/model-selector.d.ts +2 -2
  904. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  905. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/model-selector.js.map +1 -1
  906. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/oauth-selector.d.ts +1 -1
  907. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  908. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  909. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  910. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  911. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/session-selector-search.d.ts +1 -1
  912. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  913. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  914. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/session-selector.d.ts +3 -3
  915. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  916. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/session-selector.js.map +1 -1
  917. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/settings-selector.d.ts +3 -1
  918. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  919. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/settings-selector.js +15 -0
  920. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/settings-selector.js.map +1 -1
  921. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  922. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  923. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts +1 -1
  924. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  925. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  926. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  927. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/theme-selector.js.map +1 -1
  928. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  929. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  930. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts +1 -1
  931. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  932. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tool-execution.js.map +1 -1
  933. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tree-selector.d.ts +1 -1
  934. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  935. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/tree-selector.js.map +1 -1
  936. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  937. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  938. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  939. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/user-message.js.map +1 -1
  940. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts +4 -3
  941. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  942. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/interactive-mode.js +37 -14
  943. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/interactive-mode.js.map +1 -1
  944. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.d.ts +1 -1
  945. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  946. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js +37 -28
  947. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js.map +1 -1
  948. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/print-mode.d.ts +1 -1
  949. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/print-mode.d.ts.map +1 -1
  950. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/print-mode.js.map +1 -1
  951. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-client.d.ts +5 -5
  952. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  953. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-client.js +1 -1
  954. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-client.js.map +1 -1
  955. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-mode.d.ts +2 -2
  956. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  957. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-mode.js.map +1 -1
  958. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-types.d.ts +4 -4
  959. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  960. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-types.js.map +1 -1
  961. package/node_modules/@earendil-works/pi-coding-agent/dist/package-manager-cli.d.ts.map +1 -1
  962. package/node_modules/@earendil-works/pi-coding-agent/dist/package-manager-cli.js +40 -1
  963. package/node_modules/@earendil-works/pi-coding-agent/dist/package-manager-cli.js.map +1 -1
  964. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/changelog.d.ts +1 -1
  965. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/changelog.d.ts.map +1 -1
  966. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/changelog.js.map +1 -1
  967. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/clipboard-image.d.ts.map +1 -1
  968. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/clipboard-image.js.map +1 -1
  969. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/clipboard.d.ts.map +1 -1
  970. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/clipboard.js.map +1 -1
  971. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/exif-orientation.d.ts +1 -1
  972. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/exif-orientation.d.ts.map +1 -1
  973. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/exif-orientation.js.map +1 -1
  974. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-convert.d.ts.map +1 -1
  975. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-convert.js.map +1 -1
  976. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize.d.ts.map +1 -1
  977. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize.js.map +1 -1
  978. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/paths.d.ts +16 -1
  979. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/paths.d.ts.map +1 -1
  980. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/paths.js +49 -7
  981. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/paths.js.map +1 -1
  982. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/shell.d.ts.map +1 -1
  983. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/shell.js.map +1 -1
  984. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/syntax-highlight.d.ts.map +1 -1
  985. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/syntax-highlight.js.map +1 -1
  986. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/tools-manager.d.ts.map +1 -1
  987. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/tools-manager.js.map +1 -1
  988. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/version-check.d.ts +2 -1
  989. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/version-check.d.ts.map +1 -1
  990. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/version-check.js +9 -4
  991. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/version-check.js.map +1 -1
  992. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/windows-self-update.d.ts.map +1 -1
  993. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/windows-self-update.js.map +1 -1
  994. package/node_modules/@earendil-works/pi-coding-agent/docs/custom-provider.md +44 -12
  995. package/node_modules/@earendil-works/pi-coding-agent/docs/index.md +6 -4
  996. package/node_modules/@earendil-works/pi-coding-agent/docs/models.md +8 -2
  997. package/node_modules/@earendil-works/pi-coding-agent/docs/packages.md +5 -4
  998. package/node_modules/@earendil-works/pi-coding-agent/docs/quickstart.md +3 -1
  999. package/node_modules/@earendil-works/pi-coding-agent/docs/sdk.md +2 -0
  1000. package/node_modules/@earendil-works/pi-coding-agent/docs/termux.md +1 -1
  1001. package/node_modules/@earendil-works/pi-coding-agent/docs/usage.md +2 -2
  1002. package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/custom-provider-anthropic/package.json +2 -2
  1003. package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  1004. package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/custom-provider-gitlab-duo/test.ts +1 -1
  1005. package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/doom-overlay/doom-component.ts +2 -2
  1006. package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/doom-overlay/index.ts +3 -3
  1007. package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/overlay-qa-tests.ts +97 -66
  1008. package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/overlay-test.ts +7 -4
  1009. package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/plan-mode/index.ts +1 -1
  1010. package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/sandbox/package.json +2 -2
  1011. package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/subagent/index.ts +1 -1
  1012. package/node_modules/@earendil-works/pi-coding-agent/examples/extensions/with-deps/package.json +3 -3
  1013. package/node_modules/@earendil-works/pi-coding-agent/npm-shrinkwrap.json +1425 -0
  1014. package/node_modules/@earendil-works/pi-coding-agent/package.json +32 -31
  1015. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.d.ts.map +1 -1
  1016. package/node_modules/@earendil-works/pi-tui/dist/autocomplete.js.map +1 -1
  1017. package/node_modules/@earendil-works/pi-tui/dist/components/box.d.ts +1 -1
  1018. package/node_modules/@earendil-works/pi-tui/dist/components/box.d.ts.map +1 -1
  1019. package/node_modules/@earendil-works/pi-tui/dist/components/box.js.map +1 -1
  1020. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.d.ts +1 -1
  1021. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.d.ts.map +1 -1
  1022. package/node_modules/@earendil-works/pi-tui/dist/components/cancellable-loader.js.map +1 -1
  1023. package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts +3 -3
  1024. package/node_modules/@earendil-works/pi-tui/dist/components/editor.d.ts.map +1 -1
  1025. package/node_modules/@earendil-works/pi-tui/dist/components/editor.js.map +1 -1
  1026. package/node_modules/@earendil-works/pi-tui/dist/components/image.d.ts +2 -2
  1027. package/node_modules/@earendil-works/pi-tui/dist/components/image.d.ts.map +1 -1
  1028. package/node_modules/@earendil-works/pi-tui/dist/components/image.js.map +1 -1
  1029. package/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts +1 -1
  1030. package/node_modules/@earendil-works/pi-tui/dist/components/input.d.ts.map +1 -1
  1031. package/node_modules/@earendil-works/pi-tui/dist/components/input.js.map +1 -1
  1032. package/node_modules/@earendil-works/pi-tui/dist/components/loader.d.ts +5 -5
  1033. package/node_modules/@earendil-works/pi-tui/dist/components/loader.d.ts.map +1 -1
  1034. package/node_modules/@earendil-works/pi-tui/dist/components/loader.js +4 -4
  1035. package/node_modules/@earendil-works/pi-tui/dist/components/loader.js.map +1 -1
  1036. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts +1 -1
  1037. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.d.ts.map +1 -1
  1038. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js.map +1 -1
  1039. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts +1 -1
  1040. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.d.ts.map +1 -1
  1041. package/node_modules/@earendil-works/pi-tui/dist/components/select-list.js.map +1 -1
  1042. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts +1 -1
  1043. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.d.ts.map +1 -1
  1044. package/node_modules/@earendil-works/pi-tui/dist/components/settings-list.js.map +1 -1
  1045. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.d.ts +1 -1
  1046. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.d.ts.map +1 -1
  1047. package/node_modules/@earendil-works/pi-tui/dist/components/spacer.js.map +1 -1
  1048. package/node_modules/@earendil-works/pi-tui/dist/components/text.d.ts +1 -1
  1049. package/node_modules/@earendil-works/pi-tui/dist/components/text.d.ts.map +1 -1
  1050. package/node_modules/@earendil-works/pi-tui/dist/components/text.js.map +1 -1
  1051. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.d.ts +1 -1
  1052. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.d.ts.map +1 -1
  1053. package/node_modules/@earendil-works/pi-tui/dist/components/truncated-text.js.map +1 -1
  1054. package/node_modules/@earendil-works/pi-tui/dist/editor-component.d.ts +2 -2
  1055. package/node_modules/@earendil-works/pi-tui/dist/editor-component.d.ts.map +1 -1
  1056. package/node_modules/@earendil-works/pi-tui/dist/editor-component.js.map +1 -1
  1057. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts +22 -22
  1058. package/node_modules/@earendil-works/pi-tui/dist/index.d.ts.map +1 -1
  1059. package/node_modules/@earendil-works/pi-tui/dist/index.js.map +1 -1
  1060. package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts +1 -1
  1061. package/node_modules/@earendil-works/pi-tui/dist/keybindings.d.ts.map +1 -1
  1062. package/node_modules/@earendil-works/pi-tui/dist/keybindings.js.map +1 -1
  1063. package/node_modules/@earendil-works/pi-tui/dist/terminal.d.ts.map +1 -1
  1064. package/node_modules/@earendil-works/pi-tui/dist/terminal.js +25 -15
  1065. package/node_modules/@earendil-works/pi-tui/dist/terminal.js.map +1 -1
  1066. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts +2 -2
  1067. package/node_modules/@earendil-works/pi-tui/dist/tui.d.ts.map +1 -1
  1068. package/node_modules/@earendil-works/pi-tui/dist/tui.js.map +1 -1
  1069. package/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  1070. package/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  1071. package/node_modules/@earendil-works/pi-tui/package.json +8 -11
  1072. package/package.json +13 -8
  1073. package/dist/bin/forgecli.d.ts +0 -2
  1074. package/dist/bin/forgecli.js +0 -6
  1075. package/dist/bin/forgecli.js.map +0 -1
  1076. package/node_modules/koffi/CHANGELOG.md +0 -1093
  1077. package/node_modules/koffi/LICENSE.txt +0 -22
  1078. package/node_modules/koffi/README.md +0 -43
  1079. package/node_modules/koffi/build/koffi/darwin_arm64/koffi.node +0 -0
  1080. package/node_modules/koffi/build/koffi/darwin_x64/koffi.node +0 -0
  1081. package/node_modules/koffi/build/koffi/freebsd_arm64/koffi.node +0 -0
  1082. package/node_modules/koffi/build/koffi/freebsd_ia32/koffi.node +0 -0
  1083. package/node_modules/koffi/build/koffi/freebsd_x64/koffi.node +0 -0
  1084. package/node_modules/koffi/build/koffi/linux_arm64/koffi.node +0 -0
  1085. package/node_modules/koffi/build/koffi/linux_armhf/koffi.node +0 -0
  1086. package/node_modules/koffi/build/koffi/linux_ia32/koffi.node +0 -0
  1087. package/node_modules/koffi/build/koffi/linux_loong64/koffi.node +0 -0
  1088. package/node_modules/koffi/build/koffi/linux_riscv64d/koffi.node +0 -0
  1089. package/node_modules/koffi/build/koffi/linux_x64/koffi.node +0 -0
  1090. package/node_modules/koffi/build/koffi/musl_arm64/koffi.node +0 -0
  1091. package/node_modules/koffi/build/koffi/musl_x64/koffi.node +0 -0
  1092. package/node_modules/koffi/build/koffi/openbsd_ia32/koffi.node +0 -0
  1093. package/node_modules/koffi/build/koffi/openbsd_x64/koffi.node +0 -0
  1094. package/node_modules/koffi/build/koffi/win32_arm64/koffi.exp +0 -0
  1095. package/node_modules/koffi/build/koffi/win32_arm64/koffi.lib +0 -0
  1096. package/node_modules/koffi/build/koffi/win32_arm64/koffi.node +0 -0
  1097. package/node_modules/koffi/build/koffi/win32_ia32/koffi.exp +0 -0
  1098. package/node_modules/koffi/build/koffi/win32_ia32/koffi.lib +0 -0
  1099. package/node_modules/koffi/build/koffi/win32_ia32/koffi.node +0 -0
  1100. package/node_modules/koffi/build/koffi/win32_x64/koffi.exp +0 -0
  1101. package/node_modules/koffi/build/koffi/win32_x64/koffi.lib +0 -0
  1102. package/node_modules/koffi/build/koffi/win32_x64/koffi.node +0 -0
  1103. package/node_modules/koffi/doc/benchmarks.md +0 -126
  1104. package/node_modules/koffi/doc/callbacks.md +0 -210
  1105. package/node_modules/koffi/doc/contribute.md +0 -148
  1106. package/node_modules/koffi/doc/functions.md +0 -250
  1107. package/node_modules/koffi/doc/index.md +0 -61
  1108. package/node_modules/koffi/doc/input.md +0 -471
  1109. package/node_modules/koffi/doc/migration.md +0 -159
  1110. package/node_modules/koffi/doc/misc.md +0 -180
  1111. package/node_modules/koffi/doc/output.md +0 -305
  1112. package/node_modules/koffi/doc/packaging.md +0 -88
  1113. package/node_modules/koffi/doc/platforms.md +0 -36
  1114. package/node_modules/koffi/doc/pointers.md +0 -328
  1115. package/node_modules/koffi/doc/start.md +0 -118
  1116. package/node_modules/koffi/doc/unions.md +0 -186
  1117. package/node_modules/koffi/doc/variables.md +0 -102
  1118. package/node_modules/koffi/index.d.ts +0 -288
  1119. package/node_modules/koffi/index.js +0 -634
  1120. package/node_modules/koffi/indirect.js +0 -533
  1121. package/node_modules/koffi/lib/native/base/base.cc +0 -11015
  1122. package/node_modules/koffi/lib/native/base/base.hh +0 -6003
  1123. package/node_modules/koffi/lib/native/base/crc.inc +0 -2214
  1124. package/node_modules/koffi/lib/native/base/crc_gen.py +0 -72
  1125. package/node_modules/koffi/lib/native/base/mimetypes.inc +0 -1248
  1126. package/node_modules/koffi/lib/native/base/mimetypes_gen.py +0 -58
  1127. package/node_modules/koffi/lib/native/base/tower.cc +0 -821
  1128. package/node_modules/koffi/lib/native/base/tower.hh +0 -81
  1129. package/node_modules/koffi/lib/native/base/unicode.inc +0 -408
  1130. package/node_modules/koffi/lib/native/base/unicode_gen.py +0 -152
  1131. package/node_modules/koffi/package.json +0 -38
  1132. package/node_modules/koffi/src/cnoke/LICENSE.txt +0 -22
  1133. package/node_modules/koffi/src/cnoke/README.md +0 -99
  1134. package/node_modules/koffi/src/cnoke/assets/FindCNoke.cmake +0 -127
  1135. package/node_modules/koffi/src/cnoke/assets/toolchains.json +0 -126
  1136. package/node_modules/koffi/src/cnoke/assets/win_delay_hook.c +0 -36
  1137. package/node_modules/koffi/src/cnoke/cnoke.js +0 -170
  1138. package/node_modules/koffi/src/cnoke/package.json +0 -24
  1139. package/node_modules/koffi/src/cnoke/src/builder.js +0 -511
  1140. package/node_modules/koffi/src/cnoke/src/index.js +0 -10
  1141. package/node_modules/koffi/src/cnoke/src/tools.js +0 -407
  1142. package/node_modules/koffi/src/koffi/CMakeLists.txt +0 -182
  1143. package/node_modules/koffi/src/koffi/src/abi_arm32.cc +0 -1018
  1144. package/node_modules/koffi/src/koffi/src/abi_arm32_asm.S +0 -169
  1145. package/node_modules/koffi/src/koffi/src/abi_arm64.cc +0 -1295
  1146. package/node_modules/koffi/src/koffi/src/abi_arm64_asm.S +0 -195
  1147. package/node_modules/koffi/src/koffi/src/abi_arm64_asm.asm +0 -174
  1148. package/node_modules/koffi/src/koffi/src/abi_loong64.cc +0 -5
  1149. package/node_modules/koffi/src/koffi/src/abi_loong64_asm.S +0 -204
  1150. package/node_modules/koffi/src/koffi/src/abi_riscv64.cc +0 -915
  1151. package/node_modules/koffi/src/koffi/src/abi_riscv64_asm.S +0 -203
  1152. package/node_modules/koffi/src/koffi/src/abi_x64_sysv.cc +0 -939
  1153. package/node_modules/koffi/src/koffi/src/abi_x64_sysv_asm.S +0 -231
  1154. package/node_modules/koffi/src/koffi/src/abi_x64_win.cc +0 -715
  1155. package/node_modules/koffi/src/koffi/src/abi_x64_win_asm.S +0 -166
  1156. package/node_modules/koffi/src/koffi/src/abi_x64_win_asm.asm +0 -192
  1157. package/node_modules/koffi/src/koffi/src/abi_x86.cc +0 -860
  1158. package/node_modules/koffi/src/koffi/src/abi_x86_asm.S +0 -193
  1159. package/node_modules/koffi/src/koffi/src/abi_x86_asm.asm +0 -177
  1160. package/node_modules/koffi/src/koffi/src/call.cc +0 -1326
  1161. package/node_modules/koffi/src/koffi/src/call.hh +0 -179
  1162. package/node_modules/koffi/src/koffi/src/errno.inc +0 -462
  1163. package/node_modules/koffi/src/koffi/src/ffi.cc +0 -2702
  1164. package/node_modules/koffi/src/koffi/src/ffi.hh +0 -354
  1165. package/node_modules/koffi/src/koffi/src/init.js +0 -105
  1166. package/node_modules/koffi/src/koffi/src/parser.cc +0 -220
  1167. package/node_modules/koffi/src/koffi/src/parser.hh +0 -54
  1168. package/node_modules/koffi/src/koffi/src/util.cc +0 -1807
  1169. package/node_modules/koffi/src/koffi/src/util.hh +0 -221
  1170. package/node_modules/koffi/src/koffi/src/uv.cc +0 -193
  1171. package/node_modules/koffi/src/koffi/src/uv.def +0 -10
  1172. package/node_modules/koffi/src/koffi/src/uv.hh +0 -40
  1173. package/node_modules/koffi/src/koffi/src/win32.cc +0 -198
  1174. package/node_modules/koffi/src/koffi/src/win32.hh +0 -119
  1175. package/node_modules/koffi/src/koffi/tools/write_trampolines.js +0 -77
  1176. package/node_modules/koffi/vendor/node-addon-api/LICENSE.md +0 -9
  1177. package/node_modules/koffi/vendor/node-addon-api/README.md +0 -95
  1178. package/node_modules/koffi/vendor/node-addon-api/napi-inl.deprecated.h +0 -186
  1179. package/node_modules/koffi/vendor/node-addon-api/napi-inl.h +0 -7033
  1180. package/node_modules/koffi/vendor/node-addon-api/napi.h +0 -3309
  1181. package/node_modules/koffi/vendor/node-api-headers/LICENSE +0 -21
  1182. package/node_modules/koffi/vendor/node-api-headers/README.md +0 -95
  1183. package/node_modules/koffi/vendor/node-api-headers/def/js_native_api.def +0 -125
  1184. package/node_modules/koffi/vendor/node-api-headers/def/node_api.def +0 -157
  1185. package/node_modules/koffi/vendor/node-api-headers/include/js_native_api.h +0 -591
  1186. package/node_modules/koffi/vendor/node-api-headers/include/js_native_api_types.h +0 -210
  1187. package/node_modules/koffi/vendor/node-api-headers/include/node_api.h +0 -265
  1188. package/node_modules/koffi/vendor/node-api-headers/include/node_api_types.h +0 -58
  1189. package/node_modules/koffi/vendor/node-api-headers/include/uv/aix.h +0 -32
  1190. package/node_modules/koffi/vendor/node-api-headers/include/uv/bsd.h +0 -34
  1191. package/node_modules/koffi/vendor/node-api-headers/include/uv/darwin.h +0 -61
  1192. package/node_modules/koffi/vendor/node-api-headers/include/uv/errno.h +0 -483
  1193. package/node_modules/koffi/vendor/node-api-headers/include/uv/linux.h +0 -34
  1194. package/node_modules/koffi/vendor/node-api-headers/include/uv/os390.h +0 -33
  1195. package/node_modules/koffi/vendor/node-api-headers/include/uv/posix.h +0 -31
  1196. package/node_modules/koffi/vendor/node-api-headers/include/uv/sunos.h +0 -44
  1197. package/node_modules/koffi/vendor/node-api-headers/include/uv/threadpool.h +0 -37
  1198. package/node_modules/koffi/vendor/node-api-headers/include/uv/tree.h +0 -521
  1199. package/node_modules/koffi/vendor/node-api-headers/include/uv/unix.h +0 -512
  1200. package/node_modules/koffi/vendor/node-api-headers/include/uv/version.h +0 -43
  1201. package/node_modules/koffi/vendor/node-api-headers/include/uv/win.h +0 -698
  1202. package/node_modules/koffi/vendor/node-api-headers/include/uv.h +0 -1990
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard-image.d.ts","sourceRoot":"","sources":["../../src/utils/clipboard-image.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,cAAc,GAAG;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AASF,wBAAgB,gBAAgB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAE9E;AAMD,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAazE;AAmND,wBAAsB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAClD,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;CAC3B,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CA2CjC","sourcesContent":["import { spawnSync } from \"child_process\";\nimport { randomUUID } from \"crypto\";\nimport { readFileSync, unlinkSync } from \"fs\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\n\nimport { clipboard } from \"./clipboard-native.js\";\nimport { loadPhoton } from \"./photon.js\";\n\nexport type ClipboardImage = {\n\tbytes: Uint8Array;\n\tmimeType: string;\n};\n\nconst SUPPORTED_IMAGE_MIME_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"] as const;\n\nconst DEFAULT_LIST_TIMEOUT_MS = 1000;\nconst DEFAULT_READ_TIMEOUT_MS = 3000;\nconst DEFAULT_POWERSHELL_TIMEOUT_MS = 5000;\nconst DEFAULT_MAX_BUFFER_BYTES = 50 * 1024 * 1024;\n\nexport function isWaylandSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.WAYLAND_DISPLAY) || env.XDG_SESSION_TYPE === \"wayland\";\n}\n\nfunction baseMimeType(mimeType: string): string {\n\treturn mimeType.split(\";\")[0]?.trim().toLowerCase() ?? mimeType.toLowerCase();\n}\n\nexport function extensionForImageMimeType(mimeType: string): string | null {\n\tswitch (baseMimeType(mimeType)) {\n\t\tcase \"image/png\":\n\t\t\treturn \"png\";\n\t\tcase \"image/jpeg\":\n\t\t\treturn \"jpg\";\n\t\tcase \"image/webp\":\n\t\t\treturn \"webp\";\n\t\tcase \"image/gif\":\n\t\t\treturn \"gif\";\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\nfunction selectPreferredImageMimeType(mimeTypes: string[]): string | null {\n\tconst normalized = mimeTypes\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean)\n\t\t.map((t) => ({ raw: t, base: baseMimeType(t) }));\n\n\tfor (const preferred of SUPPORTED_IMAGE_MIME_TYPES) {\n\t\tconst match = normalized.find((t) => t.base === preferred);\n\t\tif (match) {\n\t\t\treturn match.raw;\n\t\t}\n\t}\n\n\tconst anyImage = normalized.find((t) => t.base.startsWith(\"image/\"));\n\treturn anyImage?.raw ?? null;\n}\n\nfunction isSupportedImageMimeType(mimeType: string): boolean {\n\tconst base = baseMimeType(mimeType);\n\treturn SUPPORTED_IMAGE_MIME_TYPES.some((t) => t === base);\n}\n\n/**\n * Convert unsupported image formats to PNG using Photon.\n * Returns null if conversion is unavailable or fails.\n */\nasync function convertToPng(bytes: Uint8Array): Promise<Uint8Array | null> {\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst image = photon.PhotonImage.new_from_byteslice(bytes);\n\t\ttry {\n\t\t\treturn image.get_bytes();\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction runCommand(\n\tcommand: string,\n\targs: string[],\n\toptions?: { timeoutMs?: number; maxBufferBytes?: number; env?: NodeJS.ProcessEnv },\n): { stdout: Buffer; ok: boolean } {\n\tconst timeoutMs = options?.timeoutMs ?? DEFAULT_READ_TIMEOUT_MS;\n\tconst maxBufferBytes = options?.maxBufferBytes ?? DEFAULT_MAX_BUFFER_BYTES;\n\n\tconst result = spawnSync(command, args, {\n\t\ttimeout: timeoutMs,\n\t\tmaxBuffer: maxBufferBytes,\n\t\tenv: options?.env,\n\t});\n\n\tif (result.error) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tif (result.status !== 0) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tconst stdout = Buffer.isBuffer(result.stdout)\n\t\t? result.stdout\n\t\t: Buffer.from(result.stdout ?? \"\", typeof result.stdout === \"string\" ? \"utf-8\" : undefined);\n\n\treturn { ok: true, stdout };\n}\n\nfunction readClipboardImageViaWlPaste(): ClipboardImage | null {\n\tconst list = runCommand(\"wl-paste\", [\"--list-types\"], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\tif (!list.ok) {\n\t\treturn null;\n\t}\n\n\tconst types = list.stdout\n\t\t.toString(\"utf-8\")\n\t\t.split(/\\r?\\n/)\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean);\n\n\tconst selectedType = selectPreferredImageMimeType(types);\n\tif (!selectedType) {\n\t\treturn null;\n\t}\n\n\tconst data = runCommand(\"wl-paste\", [\"--type\", selectedType, \"--no-newline\"]);\n\tif (!data.ok || data.stdout.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn { bytes: data.stdout, mimeType: baseMimeType(selectedType) };\n}\n\nfunction isWSL(env: NodeJS.ProcessEnv = process.env): boolean {\n\tif (env.WSL_DISTRO_NAME || env.WSLENV) {\n\t\treturn true;\n\t}\n\n\ttry {\n\t\tconst release = readFileSync(\"/proc/version\", \"utf-8\");\n\t\treturn /microsoft|wsl/i.test(release);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * On WSL, the Linux clipboard (Wayland/X11) does not receive image data from\n * Windows screenshots (Win+Shift+S). PowerShell can access the Windows clipboard\n * directly, so we use it as a fallback.\n */\nfunction readClipboardImageViaPowerShell(): ClipboardImage | null {\n\tconst tmpFile = join(tmpdir(), `pi-wsl-clip-${randomUUID()}.png`);\n\n\ttry {\n\t\tconst winPathResult = runCommand(\"wslpath\", [\"-w\", tmpFile], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\t\tif (!winPathResult.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst winPath = winPathResult.stdout.toString(\"utf-8\").trim();\n\t\tif (!winPath) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst psQuotedWinPath = winPath.replaceAll(\"'\", \"''\");\n\t\tconst psScript = [\n\t\t\t\"Add-Type -AssemblyName System.Windows.Forms\",\n\t\t\t\"Add-Type -AssemblyName System.Drawing\",\n\t\t\t`$path = '${psQuotedWinPath}'`,\n\t\t\t\"$img = [System.Windows.Forms.Clipboard]::GetImage()\",\n\t\t\t\"if ($img) { $img.Save($path, [System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'ok' } else { Write-Output 'empty' }\",\n\t\t].join(\"; \");\n\n\t\tconst result = runCommand(\"powershell.exe\", [\"-NoProfile\", \"-Command\", psScript], {\n\t\t\ttimeoutMs: DEFAULT_POWERSHELL_TIMEOUT_MS,\n\t\t});\n\t\tif (!result.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst output = result.stdout.toString(\"utf-8\").trim();\n\t\tif (output !== \"ok\") {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst bytes = readFileSync(tmpFile);\n\t\tif (bytes.length === 0) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn { bytes: new Uint8Array(bytes), mimeType: \"image/png\" };\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\ttry {\n\t\t\tunlinkSync(tmpFile);\n\t\t} catch {\n\t\t\t// Ignore cleanup errors.\n\t\t}\n\t}\n}\n\nfunction readClipboardImageViaXclip(): ClipboardImage | null {\n\tconst targets = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", \"TARGETS\", \"-o\"], {\n\t\ttimeoutMs: DEFAULT_LIST_TIMEOUT_MS,\n\t});\n\n\tlet candidateTypes: string[] = [];\n\tif (targets.ok) {\n\t\tcandidateTypes = targets.stdout\n\t\t\t.toString(\"utf-8\")\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((t) => t.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\tconst preferred = candidateTypes.length > 0 ? selectPreferredImageMimeType(candidateTypes) : null;\n\tconst tryTypes = preferred ? [preferred, ...SUPPORTED_IMAGE_MIME_TYPES] : [...SUPPORTED_IMAGE_MIME_TYPES];\n\n\tfor (const mimeType of tryTypes) {\n\t\tconst data = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", mimeType, \"-o\"]);\n\t\tif (data.ok && data.stdout.length > 0) {\n\t\t\treturn { bytes: data.stdout, mimeType: baseMimeType(mimeType) };\n\t\t}\n\t}\n\n\treturn null;\n}\n\nasync function readClipboardImageViaNativeClipboard(): Promise<ClipboardImage | null> {\n\tif (!clipboard || !clipboard.hasImage()) {\n\t\treturn null;\n\t}\n\n\tconst imageData = await clipboard.getImageBinary();\n\tif (!imageData || imageData.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst bytes = imageData instanceof Uint8Array ? imageData : Uint8Array.from(imageData);\n\treturn { bytes, mimeType: \"image/png\" };\n}\n\nexport async function readClipboardImage(options?: {\n\tenv?: NodeJS.ProcessEnv;\n\tplatform?: NodeJS.Platform;\n}): Promise<ClipboardImage | null> {\n\tconst env = options?.env ?? process.env;\n\tconst platform = options?.platform ?? process.platform;\n\n\tif (env.TERMUX_VERSION) {\n\t\treturn null;\n\t}\n\n\tlet image: ClipboardImage | null = null;\n\n\tif (platform === \"linux\") {\n\t\tconst wsl = isWSL(env);\n\t\tconst wayland = isWaylandSession(env);\n\n\t\tif (wayland || wsl) {\n\t\t\timage = readClipboardImageViaWlPaste() ?? readClipboardImageViaXclip();\n\t\t}\n\n\t\tif (!image && wsl) {\n\t\t\timage = readClipboardImageViaPowerShell();\n\t\t}\n\n\t\tif (!image && !wayland) {\n\t\t\timage = await readClipboardImageViaNativeClipboard();\n\t\t}\n\t} else {\n\t\timage = await readClipboardImageViaNativeClipboard();\n\t}\n\n\tif (!image) {\n\t\treturn null;\n\t}\n\n\t// Convert unsupported formats (e.g., BMP from WSLg) to PNG\n\tif (!isSupportedImageMimeType(image.mimeType)) {\n\t\tconst pngBytes = await convertToPng(image.bytes);\n\t\tif (!pngBytes) {\n\t\t\treturn null;\n\t\t}\n\t\treturn { bytes: pngBytes, mimeType: \"image/png\" };\n\t}\n\n\treturn image;\n}\n"]}
1
+ {"version":3,"file":"clipboard-image.d.ts","sourceRoot":"","sources":["../../src/utils/clipboard-image.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,cAAc,GAAG;IAC5B,KAAK,EAAE,UAAU,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CACjB,CAAC;AASF,wBAAgB,gBAAgB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAE9E;AAMD,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAazE;AAmND,wBAAsB,kBAAkB,CAAC,OAAO,CAAC,EAAE;IAClD,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;CAC3B,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CA2CjC","sourcesContent":["import { spawnSync } from \"child_process\";\nimport { randomUUID } from \"crypto\";\nimport { readFileSync, unlinkSync } from \"fs\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\n\nimport { clipboard } from \"./clipboard-native.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport type ClipboardImage = {\n\tbytes: Uint8Array;\n\tmimeType: string;\n};\n\nconst SUPPORTED_IMAGE_MIME_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"] as const;\n\nconst DEFAULT_LIST_TIMEOUT_MS = 1000;\nconst DEFAULT_READ_TIMEOUT_MS = 3000;\nconst DEFAULT_POWERSHELL_TIMEOUT_MS = 5000;\nconst DEFAULT_MAX_BUFFER_BYTES = 50 * 1024 * 1024;\n\nexport function isWaylandSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.WAYLAND_DISPLAY) || env.XDG_SESSION_TYPE === \"wayland\";\n}\n\nfunction baseMimeType(mimeType: string): string {\n\treturn mimeType.split(\";\")[0]?.trim().toLowerCase() ?? mimeType.toLowerCase();\n}\n\nexport function extensionForImageMimeType(mimeType: string): string | null {\n\tswitch (baseMimeType(mimeType)) {\n\t\tcase \"image/png\":\n\t\t\treturn \"png\";\n\t\tcase \"image/jpeg\":\n\t\t\treturn \"jpg\";\n\t\tcase \"image/webp\":\n\t\t\treturn \"webp\";\n\t\tcase \"image/gif\":\n\t\t\treturn \"gif\";\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\nfunction selectPreferredImageMimeType(mimeTypes: string[]): string | null {\n\tconst normalized = mimeTypes\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean)\n\t\t.map((t) => ({ raw: t, base: baseMimeType(t) }));\n\n\tfor (const preferred of SUPPORTED_IMAGE_MIME_TYPES) {\n\t\tconst match = normalized.find((t) => t.base === preferred);\n\t\tif (match) {\n\t\t\treturn match.raw;\n\t\t}\n\t}\n\n\tconst anyImage = normalized.find((t) => t.base.startsWith(\"image/\"));\n\treturn anyImage?.raw ?? null;\n}\n\nfunction isSupportedImageMimeType(mimeType: string): boolean {\n\tconst base = baseMimeType(mimeType);\n\treturn SUPPORTED_IMAGE_MIME_TYPES.some((t) => t === base);\n}\n\n/**\n * Convert unsupported image formats to PNG using Photon.\n * Returns null if conversion is unavailable or fails.\n */\nasync function convertToPng(bytes: Uint8Array): Promise<Uint8Array | null> {\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst image = photon.PhotonImage.new_from_byteslice(bytes);\n\t\ttry {\n\t\t\treturn image.get_bytes();\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction runCommand(\n\tcommand: string,\n\targs: string[],\n\toptions?: { timeoutMs?: number; maxBufferBytes?: number; env?: NodeJS.ProcessEnv },\n): { stdout: Buffer; ok: boolean } {\n\tconst timeoutMs = options?.timeoutMs ?? DEFAULT_READ_TIMEOUT_MS;\n\tconst maxBufferBytes = options?.maxBufferBytes ?? DEFAULT_MAX_BUFFER_BYTES;\n\n\tconst result = spawnSync(command, args, {\n\t\ttimeout: timeoutMs,\n\t\tmaxBuffer: maxBufferBytes,\n\t\tenv: options?.env,\n\t});\n\n\tif (result.error) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tif (result.status !== 0) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tconst stdout = Buffer.isBuffer(result.stdout)\n\t\t? result.stdout\n\t\t: Buffer.from(result.stdout ?? \"\", typeof result.stdout === \"string\" ? \"utf-8\" : undefined);\n\n\treturn { ok: true, stdout };\n}\n\nfunction readClipboardImageViaWlPaste(): ClipboardImage | null {\n\tconst list = runCommand(\"wl-paste\", [\"--list-types\"], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\tif (!list.ok) {\n\t\treturn null;\n\t}\n\n\tconst types = list.stdout\n\t\t.toString(\"utf-8\")\n\t\t.split(/\\r?\\n/)\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean);\n\n\tconst selectedType = selectPreferredImageMimeType(types);\n\tif (!selectedType) {\n\t\treturn null;\n\t}\n\n\tconst data = runCommand(\"wl-paste\", [\"--type\", selectedType, \"--no-newline\"]);\n\tif (!data.ok || data.stdout.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn { bytes: data.stdout, mimeType: baseMimeType(selectedType) };\n}\n\nfunction isWSL(env: NodeJS.ProcessEnv = process.env): boolean {\n\tif (env.WSL_DISTRO_NAME || env.WSLENV) {\n\t\treturn true;\n\t}\n\n\ttry {\n\t\tconst release = readFileSync(\"/proc/version\", \"utf-8\");\n\t\treturn /microsoft|wsl/i.test(release);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * On WSL, the Linux clipboard (Wayland/X11) does not receive image data from\n * Windows screenshots (Win+Shift+S). PowerShell can access the Windows clipboard\n * directly, so we use it as a fallback.\n */\nfunction readClipboardImageViaPowerShell(): ClipboardImage | null {\n\tconst tmpFile = join(tmpdir(), `pi-wsl-clip-${randomUUID()}.png`);\n\n\ttry {\n\t\tconst winPathResult = runCommand(\"wslpath\", [\"-w\", tmpFile], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\t\tif (!winPathResult.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst winPath = winPathResult.stdout.toString(\"utf-8\").trim();\n\t\tif (!winPath) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst psQuotedWinPath = winPath.replaceAll(\"'\", \"''\");\n\t\tconst psScript = [\n\t\t\t\"Add-Type -AssemblyName System.Windows.Forms\",\n\t\t\t\"Add-Type -AssemblyName System.Drawing\",\n\t\t\t`$path = '${psQuotedWinPath}'`,\n\t\t\t\"$img = [System.Windows.Forms.Clipboard]::GetImage()\",\n\t\t\t\"if ($img) { $img.Save($path, [System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'ok' } else { Write-Output 'empty' }\",\n\t\t].join(\"; \");\n\n\t\tconst result = runCommand(\"powershell.exe\", [\"-NoProfile\", \"-Command\", psScript], {\n\t\t\ttimeoutMs: DEFAULT_POWERSHELL_TIMEOUT_MS,\n\t\t});\n\t\tif (!result.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst output = result.stdout.toString(\"utf-8\").trim();\n\t\tif (output !== \"ok\") {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst bytes = readFileSync(tmpFile);\n\t\tif (bytes.length === 0) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn { bytes: new Uint8Array(bytes), mimeType: \"image/png\" };\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\ttry {\n\t\t\tunlinkSync(tmpFile);\n\t\t} catch {\n\t\t\t// Ignore cleanup errors.\n\t\t}\n\t}\n}\n\nfunction readClipboardImageViaXclip(): ClipboardImage | null {\n\tconst targets = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", \"TARGETS\", \"-o\"], {\n\t\ttimeoutMs: DEFAULT_LIST_TIMEOUT_MS,\n\t});\n\n\tlet candidateTypes: string[] = [];\n\tif (targets.ok) {\n\t\tcandidateTypes = targets.stdout\n\t\t\t.toString(\"utf-8\")\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((t) => t.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\tconst preferred = candidateTypes.length > 0 ? selectPreferredImageMimeType(candidateTypes) : null;\n\tconst tryTypes = preferred ? [preferred, ...SUPPORTED_IMAGE_MIME_TYPES] : [...SUPPORTED_IMAGE_MIME_TYPES];\n\n\tfor (const mimeType of tryTypes) {\n\t\tconst data = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", mimeType, \"-o\"]);\n\t\tif (data.ok && data.stdout.length > 0) {\n\t\t\treturn { bytes: data.stdout, mimeType: baseMimeType(mimeType) };\n\t\t}\n\t}\n\n\treturn null;\n}\n\nasync function readClipboardImageViaNativeClipboard(): Promise<ClipboardImage | null> {\n\tif (!clipboard || !clipboard.hasImage()) {\n\t\treturn null;\n\t}\n\n\tconst imageData = await clipboard.getImageBinary();\n\tif (!imageData || imageData.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst bytes = imageData instanceof Uint8Array ? imageData : Uint8Array.from(imageData);\n\treturn { bytes, mimeType: \"image/png\" };\n}\n\nexport async function readClipboardImage(options?: {\n\tenv?: NodeJS.ProcessEnv;\n\tplatform?: NodeJS.Platform;\n}): Promise<ClipboardImage | null> {\n\tconst env = options?.env ?? process.env;\n\tconst platform = options?.platform ?? process.platform;\n\n\tif (env.TERMUX_VERSION) {\n\t\treturn null;\n\t}\n\n\tlet image: ClipboardImage | null = null;\n\n\tif (platform === \"linux\") {\n\t\tconst wsl = isWSL(env);\n\t\tconst wayland = isWaylandSession(env);\n\n\t\tif (wayland || wsl) {\n\t\t\timage = readClipboardImageViaWlPaste() ?? readClipboardImageViaXclip();\n\t\t}\n\n\t\tif (!image && wsl) {\n\t\t\timage = readClipboardImageViaPowerShell();\n\t\t}\n\n\t\tif (!image && !wayland) {\n\t\t\timage = await readClipboardImageViaNativeClipboard();\n\t\t}\n\t} else {\n\t\timage = await readClipboardImageViaNativeClipboard();\n\t}\n\n\tif (!image) {\n\t\treturn null;\n\t}\n\n\t// Convert unsupported formats (e.g., BMP from WSLg) to PNG\n\tif (!isSupportedImageMimeType(image.mimeType)) {\n\t\tconst pngBytes = await convertToPng(image.bytes);\n\t\tif (!pngBytes) {\n\t\t\treturn null;\n\t\t}\n\t\treturn { bytes: pngBytes, mimeType: \"image/png\" };\n\t}\n\n\treturn image;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard-image.js","sourceRoot":"","sources":["../../src/utils/clipboard-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,MAAM,0BAA0B,GAAG,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,CAAU,CAAC;AAEnG,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AACrC,MAAM,6BAA6B,GAAG,IAAI,CAAC;AAC3C,MAAM,wBAAwB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAElD,MAAM,UAAU,gBAAgB,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG,EAAW;IAC/E,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,GAAG,CAAC,gBAAgB,KAAK,SAAS,CAAC;AAAA,CAC1E;AAED,SAAS,YAAY,CAAC,QAAgB,EAAU;IAC/C,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,WAAW,EAAE,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC;A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E,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;IACnD,CAAC;IAED,OAAO,KAAK,CAAC;AAAA,CACb","sourcesContent":["import { spawnSync } from \"child_process\";\nimport { randomUUID } from \"crypto\";\nimport { readFileSync, unlinkSync } from \"fs\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\n\nimport { clipboard } from \"./clipboard-native.js\";\nimport { loadPhoton } from \"./photon.js\";\n\nexport type ClipboardImage = {\n\tbytes: Uint8Array;\n\tmimeType: string;\n};\n\nconst SUPPORTED_IMAGE_MIME_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"] as const;\n\nconst DEFAULT_LIST_TIMEOUT_MS = 1000;\nconst DEFAULT_READ_TIMEOUT_MS = 3000;\nconst DEFAULT_POWERSHELL_TIMEOUT_MS = 5000;\nconst DEFAULT_MAX_BUFFER_BYTES = 50 * 1024 * 1024;\n\nexport function isWaylandSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.WAYLAND_DISPLAY) || env.XDG_SESSION_TYPE === \"wayland\";\n}\n\nfunction baseMimeType(mimeType: string): string {\n\treturn mimeType.split(\";\")[0]?.trim().toLowerCase() ?? mimeType.toLowerCase();\n}\n\nexport function extensionForImageMimeType(mimeType: string): string | null {\n\tswitch (baseMimeType(mimeType)) {\n\t\tcase \"image/png\":\n\t\t\treturn \"png\";\n\t\tcase \"image/jpeg\":\n\t\t\treturn \"jpg\";\n\t\tcase \"image/webp\":\n\t\t\treturn \"webp\";\n\t\tcase \"image/gif\":\n\t\t\treturn \"gif\";\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\nfunction selectPreferredImageMimeType(mimeTypes: string[]): string | null {\n\tconst normalized = mimeTypes\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean)\n\t\t.map((t) => ({ raw: t, base: baseMimeType(t) }));\n\n\tfor (const preferred of SUPPORTED_IMAGE_MIME_TYPES) {\n\t\tconst match = normalized.find((t) => t.base === preferred);\n\t\tif (match) {\n\t\t\treturn match.raw;\n\t\t}\n\t}\n\n\tconst anyImage = normalized.find((t) => t.base.startsWith(\"image/\"));\n\treturn anyImage?.raw ?? null;\n}\n\nfunction isSupportedImageMimeType(mimeType: string): boolean {\n\tconst base = baseMimeType(mimeType);\n\treturn SUPPORTED_IMAGE_MIME_TYPES.some((t) => t === base);\n}\n\n/**\n * Convert unsupported image formats to PNG using Photon.\n * Returns null if conversion is unavailable or fails.\n */\nasync function convertToPng(bytes: Uint8Array): Promise<Uint8Array | null> {\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst image = photon.PhotonImage.new_from_byteslice(bytes);\n\t\ttry {\n\t\t\treturn image.get_bytes();\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction runCommand(\n\tcommand: string,\n\targs: string[],\n\toptions?: { timeoutMs?: number; maxBufferBytes?: number; env?: NodeJS.ProcessEnv },\n): { stdout: Buffer; ok: boolean } {\n\tconst timeoutMs = options?.timeoutMs ?? DEFAULT_READ_TIMEOUT_MS;\n\tconst maxBufferBytes = options?.maxBufferBytes ?? DEFAULT_MAX_BUFFER_BYTES;\n\n\tconst result = spawnSync(command, args, {\n\t\ttimeout: timeoutMs,\n\t\tmaxBuffer: maxBufferBytes,\n\t\tenv: options?.env,\n\t});\n\n\tif (result.error) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tif (result.status !== 0) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tconst stdout = Buffer.isBuffer(result.stdout)\n\t\t? result.stdout\n\t\t: Buffer.from(result.stdout ?? \"\", typeof result.stdout === \"string\" ? \"utf-8\" : undefined);\n\n\treturn { ok: true, stdout };\n}\n\nfunction readClipboardImageViaWlPaste(): ClipboardImage | null {\n\tconst list = runCommand(\"wl-paste\", [\"--list-types\"], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\tif (!list.ok) {\n\t\treturn null;\n\t}\n\n\tconst types = list.stdout\n\t\t.toString(\"utf-8\")\n\t\t.split(/\\r?\\n/)\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean);\n\n\tconst selectedType = selectPreferredImageMimeType(types);\n\tif (!selectedType) {\n\t\treturn null;\n\t}\n\n\tconst data = runCommand(\"wl-paste\", [\"--type\", selectedType, \"--no-newline\"]);\n\tif (!data.ok || data.stdout.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn { bytes: data.stdout, mimeType: baseMimeType(selectedType) };\n}\n\nfunction isWSL(env: NodeJS.ProcessEnv = process.env): boolean {\n\tif (env.WSL_DISTRO_NAME || env.WSLENV) {\n\t\treturn true;\n\t}\n\n\ttry {\n\t\tconst release = readFileSync(\"/proc/version\", \"utf-8\");\n\t\treturn /microsoft|wsl/i.test(release);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * On WSL, the Linux clipboard (Wayland/X11) does not receive image data from\n * Windows screenshots (Win+Shift+S). PowerShell can access the Windows clipboard\n * directly, so we use it as a fallback.\n */\nfunction readClipboardImageViaPowerShell(): ClipboardImage | null {\n\tconst tmpFile = join(tmpdir(), `pi-wsl-clip-${randomUUID()}.png`);\n\n\ttry {\n\t\tconst winPathResult = runCommand(\"wslpath\", [\"-w\", tmpFile], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\t\tif (!winPathResult.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst winPath = winPathResult.stdout.toString(\"utf-8\").trim();\n\t\tif (!winPath) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst psQuotedWinPath = winPath.replaceAll(\"'\", \"''\");\n\t\tconst psScript = [\n\t\t\t\"Add-Type -AssemblyName System.Windows.Forms\",\n\t\t\t\"Add-Type -AssemblyName System.Drawing\",\n\t\t\t`$path = '${psQuotedWinPath}'`,\n\t\t\t\"$img = [System.Windows.Forms.Clipboard]::GetImage()\",\n\t\t\t\"if ($img) { $img.Save($path, [System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'ok' } else { Write-Output 'empty' }\",\n\t\t].join(\"; \");\n\n\t\tconst result = runCommand(\"powershell.exe\", [\"-NoProfile\", \"-Command\", psScript], {\n\t\t\ttimeoutMs: DEFAULT_POWERSHELL_TIMEOUT_MS,\n\t\t});\n\t\tif (!result.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst output = result.stdout.toString(\"utf-8\").trim();\n\t\tif (output !== \"ok\") {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst bytes = readFileSync(tmpFile);\n\t\tif (bytes.length === 0) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn { bytes: new Uint8Array(bytes), mimeType: \"image/png\" };\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\ttry {\n\t\t\tunlinkSync(tmpFile);\n\t\t} catch {\n\t\t\t// Ignore cleanup errors.\n\t\t}\n\t}\n}\n\nfunction readClipboardImageViaXclip(): ClipboardImage | null {\n\tconst targets = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", \"TARGETS\", \"-o\"], {\n\t\ttimeoutMs: DEFAULT_LIST_TIMEOUT_MS,\n\t});\n\n\tlet candidateTypes: string[] = [];\n\tif (targets.ok) {\n\t\tcandidateTypes = targets.stdout\n\t\t\t.toString(\"utf-8\")\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((t) => t.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\tconst preferred = candidateTypes.length > 0 ? selectPreferredImageMimeType(candidateTypes) : null;\n\tconst tryTypes = preferred ? [preferred, ...SUPPORTED_IMAGE_MIME_TYPES] : [...SUPPORTED_IMAGE_MIME_TYPES];\n\n\tfor (const mimeType of tryTypes) {\n\t\tconst data = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", mimeType, \"-o\"]);\n\t\tif (data.ok && data.stdout.length > 0) {\n\t\t\treturn { bytes: data.stdout, mimeType: baseMimeType(mimeType) };\n\t\t}\n\t}\n\n\treturn null;\n}\n\nasync function readClipboardImageViaNativeClipboard(): Promise<ClipboardImage | null> {\n\tif (!clipboard || !clipboard.hasImage()) {\n\t\treturn null;\n\t}\n\n\tconst imageData = await clipboard.getImageBinary();\n\tif (!imageData || imageData.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst bytes = imageData instanceof Uint8Array ? imageData : Uint8Array.from(imageData);\n\treturn { bytes, mimeType: \"image/png\" };\n}\n\nexport async function readClipboardImage(options?: {\n\tenv?: NodeJS.ProcessEnv;\n\tplatform?: NodeJS.Platform;\n}): Promise<ClipboardImage | null> {\n\tconst env = options?.env ?? process.env;\n\tconst platform = options?.platform ?? process.platform;\n\n\tif (env.TERMUX_VERSION) {\n\t\treturn null;\n\t}\n\n\tlet image: ClipboardImage | null = null;\n\n\tif (platform === \"linux\") {\n\t\tconst wsl = isWSL(env);\n\t\tconst wayland = isWaylandSession(env);\n\n\t\tif (wayland || wsl) {\n\t\t\timage = readClipboardImageViaWlPaste() ?? readClipboardImageViaXclip();\n\t\t}\n\n\t\tif (!image && wsl) {\n\t\t\timage = readClipboardImageViaPowerShell();\n\t\t}\n\n\t\tif (!image && !wayland) {\n\t\t\timage = await readClipboardImageViaNativeClipboard();\n\t\t}\n\t} else {\n\t\timage = await readClipboardImageViaNativeClipboard();\n\t}\n\n\tif (!image) {\n\t\treturn null;\n\t}\n\n\t// Convert unsupported formats (e.g., BMP from WSLg) to PNG\n\tif (!isSupportedImageMimeType(image.mimeType)) {\n\t\tconst pngBytes = await convertToPng(image.bytes);\n\t\tif (!pngBytes) {\n\t\t\treturn null;\n\t\t}\n\t\treturn { bytes: pngBytes, mimeType: \"image/png\" };\n\t}\n\n\treturn image;\n}\n"]}
1
+ {"version":3,"file":"clipboard-image.js","sourceRoot":"","sources":["../../src/utils/clipboard-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,QA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IAAI,CAAC;IAExC,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QAC1B,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;QACvB,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;QAEtC,IAAI,OAAO,IAAI,GAAG,EAAE,CAAC;YACpB,KAAK,GAAG,4BAA4B,EAAE,IAAI,0BAA0B,EAAE,CAAC;QACxE,CAAC;QAED,IAAI,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC;YACnB,KAAK,GAAG,+BAA+B,EAAE,CAAC;QAC3C,CAAC;QAED,IAAI,CAAC,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;YACxB,KAAK,GAAG,MAAM,oCAAoC,EAAE,CAAC;QACtD,CAAC;IACF,CAAC;SAAM,CAAC;QACP,KAAK,GAAG,MAAM,oCAAoC,EAAE,CAAC;IACtD,CAAC;IAED,IAAI,CAAC,KAAK,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACb,CAAC;IAED,2DAA2D;IAC3D,IAAI,CAAC,wBAAwB,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC/C,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACjD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,OAAO,IAAI,CAAC;QACb,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;IACnD,CAAC;IAED,OAAO,KAAK,CAAC;AAAA,CACb","sourcesContent":["import { spawnSync } from \"child_process\";\nimport { randomUUID } from \"crypto\";\nimport { readFileSync, unlinkSync } from \"fs\";\nimport { tmpdir } from \"os\";\nimport { join } from \"path\";\n\nimport { clipboard } from \"./clipboard-native.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport type ClipboardImage = {\n\tbytes: Uint8Array;\n\tmimeType: string;\n};\n\nconst SUPPORTED_IMAGE_MIME_TYPES = [\"image/png\", \"image/jpeg\", \"image/webp\", \"image/gif\"] as const;\n\nconst DEFAULT_LIST_TIMEOUT_MS = 1000;\nconst DEFAULT_READ_TIMEOUT_MS = 3000;\nconst DEFAULT_POWERSHELL_TIMEOUT_MS = 5000;\nconst DEFAULT_MAX_BUFFER_BYTES = 50 * 1024 * 1024;\n\nexport function isWaylandSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.WAYLAND_DISPLAY) || env.XDG_SESSION_TYPE === \"wayland\";\n}\n\nfunction baseMimeType(mimeType: string): string {\n\treturn mimeType.split(\";\")[0]?.trim().toLowerCase() ?? mimeType.toLowerCase();\n}\n\nexport function extensionForImageMimeType(mimeType: string): string | null {\n\tswitch (baseMimeType(mimeType)) {\n\t\tcase \"image/png\":\n\t\t\treturn \"png\";\n\t\tcase \"image/jpeg\":\n\t\t\treturn \"jpg\";\n\t\tcase \"image/webp\":\n\t\t\treturn \"webp\";\n\t\tcase \"image/gif\":\n\t\t\treturn \"gif\";\n\t\tdefault:\n\t\t\treturn null;\n\t}\n}\n\nfunction selectPreferredImageMimeType(mimeTypes: string[]): string | null {\n\tconst normalized = mimeTypes\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean)\n\t\t.map((t) => ({ raw: t, base: baseMimeType(t) }));\n\n\tfor (const preferred of SUPPORTED_IMAGE_MIME_TYPES) {\n\t\tconst match = normalized.find((t) => t.base === preferred);\n\t\tif (match) {\n\t\t\treturn match.raw;\n\t\t}\n\t}\n\n\tconst anyImage = normalized.find((t) => t.base.startsWith(\"image/\"));\n\treturn anyImage?.raw ?? null;\n}\n\nfunction isSupportedImageMimeType(mimeType: string): boolean {\n\tconst base = baseMimeType(mimeType);\n\treturn SUPPORTED_IMAGE_MIME_TYPES.some((t) => t === base);\n}\n\n/**\n * Convert unsupported image formats to PNG using Photon.\n * Returns null if conversion is unavailable or fails.\n */\nasync function convertToPng(bytes: Uint8Array): Promise<Uint8Array | null> {\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst image = photon.PhotonImage.new_from_byteslice(bytes);\n\t\ttry {\n\t\t\treturn image.get_bytes();\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction runCommand(\n\tcommand: string,\n\targs: string[],\n\toptions?: { timeoutMs?: number; maxBufferBytes?: number; env?: NodeJS.ProcessEnv },\n): { stdout: Buffer; ok: boolean } {\n\tconst timeoutMs = options?.timeoutMs ?? DEFAULT_READ_TIMEOUT_MS;\n\tconst maxBufferBytes = options?.maxBufferBytes ?? DEFAULT_MAX_BUFFER_BYTES;\n\n\tconst result = spawnSync(command, args, {\n\t\ttimeout: timeoutMs,\n\t\tmaxBuffer: maxBufferBytes,\n\t\tenv: options?.env,\n\t});\n\n\tif (result.error) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tif (result.status !== 0) {\n\t\treturn { ok: false, stdout: Buffer.alloc(0) };\n\t}\n\n\tconst stdout = Buffer.isBuffer(result.stdout)\n\t\t? result.stdout\n\t\t: Buffer.from(result.stdout ?? \"\", typeof result.stdout === \"string\" ? \"utf-8\" : undefined);\n\n\treturn { ok: true, stdout };\n}\n\nfunction readClipboardImageViaWlPaste(): ClipboardImage | null {\n\tconst list = runCommand(\"wl-paste\", [\"--list-types\"], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\tif (!list.ok) {\n\t\treturn null;\n\t}\n\n\tconst types = list.stdout\n\t\t.toString(\"utf-8\")\n\t\t.split(/\\r?\\n/)\n\t\t.map((t) => t.trim())\n\t\t.filter(Boolean);\n\n\tconst selectedType = selectPreferredImageMimeType(types);\n\tif (!selectedType) {\n\t\treturn null;\n\t}\n\n\tconst data = runCommand(\"wl-paste\", [\"--type\", selectedType, \"--no-newline\"]);\n\tif (!data.ok || data.stdout.length === 0) {\n\t\treturn null;\n\t}\n\n\treturn { bytes: data.stdout, mimeType: baseMimeType(selectedType) };\n}\n\nfunction isWSL(env: NodeJS.ProcessEnv = process.env): boolean {\n\tif (env.WSL_DISTRO_NAME || env.WSLENV) {\n\t\treturn true;\n\t}\n\n\ttry {\n\t\tconst release = readFileSync(\"/proc/version\", \"utf-8\");\n\t\treturn /microsoft|wsl/i.test(release);\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * On WSL, the Linux clipboard (Wayland/X11) does not receive image data from\n * Windows screenshots (Win+Shift+S). PowerShell can access the Windows clipboard\n * directly, so we use it as a fallback.\n */\nfunction readClipboardImageViaPowerShell(): ClipboardImage | null {\n\tconst tmpFile = join(tmpdir(), `pi-wsl-clip-${randomUUID()}.png`);\n\n\ttry {\n\t\tconst winPathResult = runCommand(\"wslpath\", [\"-w\", tmpFile], { timeoutMs: DEFAULT_LIST_TIMEOUT_MS });\n\t\tif (!winPathResult.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst winPath = winPathResult.stdout.toString(\"utf-8\").trim();\n\t\tif (!winPath) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst psQuotedWinPath = winPath.replaceAll(\"'\", \"''\");\n\t\tconst psScript = [\n\t\t\t\"Add-Type -AssemblyName System.Windows.Forms\",\n\t\t\t\"Add-Type -AssemblyName System.Drawing\",\n\t\t\t`$path = '${psQuotedWinPath}'`,\n\t\t\t\"$img = [System.Windows.Forms.Clipboard]::GetImage()\",\n\t\t\t\"if ($img) { $img.Save($path, [System.Drawing.Imaging.ImageFormat]::Png); Write-Output 'ok' } else { Write-Output 'empty' }\",\n\t\t].join(\"; \");\n\n\t\tconst result = runCommand(\"powershell.exe\", [\"-NoProfile\", \"-Command\", psScript], {\n\t\t\ttimeoutMs: DEFAULT_POWERSHELL_TIMEOUT_MS,\n\t\t});\n\t\tif (!result.ok) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst output = result.stdout.toString(\"utf-8\").trim();\n\t\tif (output !== \"ok\") {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst bytes = readFileSync(tmpFile);\n\t\tif (bytes.length === 0) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn { bytes: new Uint8Array(bytes), mimeType: \"image/png\" };\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\ttry {\n\t\t\tunlinkSync(tmpFile);\n\t\t} catch {\n\t\t\t// Ignore cleanup errors.\n\t\t}\n\t}\n}\n\nfunction readClipboardImageViaXclip(): ClipboardImage | null {\n\tconst targets = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", \"TARGETS\", \"-o\"], {\n\t\ttimeoutMs: DEFAULT_LIST_TIMEOUT_MS,\n\t});\n\n\tlet candidateTypes: string[] = [];\n\tif (targets.ok) {\n\t\tcandidateTypes = targets.stdout\n\t\t\t.toString(\"utf-8\")\n\t\t\t.split(/\\r?\\n/)\n\t\t\t.map((t) => t.trim())\n\t\t\t.filter(Boolean);\n\t}\n\n\tconst preferred = candidateTypes.length > 0 ? selectPreferredImageMimeType(candidateTypes) : null;\n\tconst tryTypes = preferred ? [preferred, ...SUPPORTED_IMAGE_MIME_TYPES] : [...SUPPORTED_IMAGE_MIME_TYPES];\n\n\tfor (const mimeType of tryTypes) {\n\t\tconst data = runCommand(\"xclip\", [\"-selection\", \"clipboard\", \"-t\", mimeType, \"-o\"]);\n\t\tif (data.ok && data.stdout.length > 0) {\n\t\t\treturn { bytes: data.stdout, mimeType: baseMimeType(mimeType) };\n\t\t}\n\t}\n\n\treturn null;\n}\n\nasync function readClipboardImageViaNativeClipboard(): Promise<ClipboardImage | null> {\n\tif (!clipboard || !clipboard.hasImage()) {\n\t\treturn null;\n\t}\n\n\tconst imageData = await clipboard.getImageBinary();\n\tif (!imageData || imageData.length === 0) {\n\t\treturn null;\n\t}\n\n\tconst bytes = imageData instanceof Uint8Array ? imageData : Uint8Array.from(imageData);\n\treturn { bytes, mimeType: \"image/png\" };\n}\n\nexport async function readClipboardImage(options?: {\n\tenv?: NodeJS.ProcessEnv;\n\tplatform?: NodeJS.Platform;\n}): Promise<ClipboardImage | null> {\n\tconst env = options?.env ?? process.env;\n\tconst platform = options?.platform ?? process.platform;\n\n\tif (env.TERMUX_VERSION) {\n\t\treturn null;\n\t}\n\n\tlet image: ClipboardImage | null = null;\n\n\tif (platform === \"linux\") {\n\t\tconst wsl = isWSL(env);\n\t\tconst wayland = isWaylandSession(env);\n\n\t\tif (wayland || wsl) {\n\t\t\timage = readClipboardImageViaWlPaste() ?? readClipboardImageViaXclip();\n\t\t}\n\n\t\tif (!image && wsl) {\n\t\t\timage = readClipboardImageViaPowerShell();\n\t\t}\n\n\t\tif (!image && !wayland) {\n\t\t\timage = await readClipboardImageViaNativeClipboard();\n\t\t}\n\t} else {\n\t\timage = await readClipboardImageViaNativeClipboard();\n\t}\n\n\tif (!image) {\n\t\treturn null;\n\t}\n\n\t// Convert unsupported formats (e.g., BMP from WSLg) to PNG\n\tif (!isSupportedImageMimeType(image.mimeType)) {\n\t\tconst pngBytes = await convertToPng(image.bytes);\n\t\tif (!pngBytes) {\n\t\t\treturn null;\n\t\t}\n\t\treturn { bytes: pngBytes, mimeType: \"image/png\" };\n\t}\n\n\treturn image;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAkCA,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA4FjE","sourcesContent":["import { execSync, spawn } from \"child_process\";\nimport { platform } from \"os\";\nimport { isWaylandSession } from \"./clipboard-image.js\";\nimport { clipboard } from \"./clipboard-native.js\";\n\ntype NativeClipboardExecOptions = {\n\tinput: string;\n\ttimeout: number;\n\tstdio: [\"pipe\", \"ignore\", \"ignore\"];\n};\n\nfunction copyToX11Clipboard(options: NativeClipboardExecOptions): void {\n\ttry {\n\t\texecSync(\"xclip -selection clipboard\", options);\n\t} catch {\n\t\texecSync(\"xsel --clipboard --input\", options);\n\t}\n}\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\nfunction isRemoteSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tlet copied = false;\n\n\tconst p = platform();\n\n\t// Prefer direct clipboard writes. Emitting OSC 52 first can make terminals\n\t// write the same native clipboard concurrently with the addon, and very large\n\t// OSC 52 payloads can desynchronize terminal rendering.\n\t//\n\t// On Linux, skip the native addon. The underlying `clipboard-rs` crate is\n\t// X11-only and does not retain selection ownership after `set_text`\n\t// resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even\n\t// some X11 sessions the call resolves successfully without populating the\n\t// clipboard. The platform tools below (wl-copy, xclip, xsel) properly\n\t// daemonize and keep ownership.\n\ttry {\n\t\tif (clipboard && p !== \"linux\") {\n\t\t\tawait clipboard.setText(text);\n\t\t\tcopied = true;\n\t\t}\n\t} catch {\n\t\t// Fall through to platform-specific clipboard tools.\n\t}\n\n\tconst remote = isRemoteSession();\n\tif (copied && !remote) {\n\t\treturn;\n\t}\n\n\tconst options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: [\"pipe\", \"ignore\", \"ignore\"] };\n\n\tif (!copied) {\n\t\ttry {\n\t\t\tif (p === \"darwin\") {\n\t\t\t\texecSync(\"pbcopy\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else if (p === \"win32\") {\n\t\t\t\texecSync(\"clip\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else {\n\t\t\t\t// Linux. Try Termux, Wayland, or X11 clipboard tools.\n\t\t\t\tif (process.env.TERMUX_VERSION) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\texecSync(\"termux-clipboard-set\", options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall back to Wayland or X11 tools.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!copied) {\n\t\t\t\t\tconst hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);\n\t\t\t\t\tconst hasX11Display = Boolean(process.env.DISPLAY);\n\t\t\t\t\tconst isWayland = isWaylandSession();\n\t\t\t\t\tif (isWayland && hasWaylandDisplay) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Verify wl-copy exists (spawn errors are async and won't be caught)\n\t\t\t\t\t\t\texecSync(\"which wl-copy\", { stdio: \"ignore\" });\n\t\t\t\t\t\t\t// wl-copy with execSync hangs due to fork behavior; use spawn instead\n\t\t\t\t\t\t\tconst proc = spawn(\"wl-copy\", [], { stdio: [\"pipe\", \"ignore\", \"ignore\"] });\n\t\t\t\t\t\t\tproc.stdin.on(\"error\", () => {\n\t\t\t\t\t\t\t\t// Ignore EPIPE errors if wl-copy exits early\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tproc.stdin.write(text);\n\t\t\t\t\t\t\tproc.stdin.end();\n\t\t\t\t\t\t\tproc.unref();\n\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tif (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to OSC 52 fallback.\n\t\t}\n\t}\n\n\tif (remote || !copied) {\n\t\tconst osc52Copied = emitOsc52(text);\n\t\tcopied = copied || osc52Copied;\n\t}\n\n\tif (!copied) {\n\t\tthrow new Error(\"Failed to copy to clipboard\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"clipboard.d.ts","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAkCA,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA4FjE","sourcesContent":["import { execSync, spawn } from \"child_process\";\nimport { platform } from \"os\";\nimport { isWaylandSession } from \"./clipboard-image.ts\";\nimport { clipboard } from \"./clipboard-native.ts\";\n\ntype NativeClipboardExecOptions = {\n\tinput: string;\n\ttimeout: number;\n\tstdio: [\"pipe\", \"ignore\", \"ignore\"];\n};\n\nfunction copyToX11Clipboard(options: NativeClipboardExecOptions): void {\n\ttry {\n\t\texecSync(\"xclip -selection clipboard\", options);\n\t} catch {\n\t\texecSync(\"xsel --clipboard --input\", options);\n\t}\n}\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\nfunction isRemoteSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tlet copied = false;\n\n\tconst p = platform();\n\n\t// Prefer direct clipboard writes. Emitting OSC 52 first can make terminals\n\t// write the same native clipboard concurrently with the addon, and very large\n\t// OSC 52 payloads can desynchronize terminal rendering.\n\t//\n\t// On Linux, skip the native addon. The underlying `clipboard-rs` crate is\n\t// X11-only and does not retain selection ownership after `set_text`\n\t// resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even\n\t// some X11 sessions the call resolves successfully without populating the\n\t// clipboard. The platform tools below (wl-copy, xclip, xsel) properly\n\t// daemonize and keep ownership.\n\ttry {\n\t\tif (clipboard && p !== \"linux\") {\n\t\t\tawait clipboard.setText(text);\n\t\t\tcopied = true;\n\t\t}\n\t} catch {\n\t\t// Fall through to platform-specific clipboard tools.\n\t}\n\n\tconst remote = isRemoteSession();\n\tif (copied && !remote) {\n\t\treturn;\n\t}\n\n\tconst options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: [\"pipe\", \"ignore\", \"ignore\"] };\n\n\tif (!copied) {\n\t\ttry {\n\t\t\tif (p === \"darwin\") {\n\t\t\t\texecSync(\"pbcopy\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else if (p === \"win32\") {\n\t\t\t\texecSync(\"clip\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else {\n\t\t\t\t// Linux. Try Termux, Wayland, or X11 clipboard tools.\n\t\t\t\tif (process.env.TERMUX_VERSION) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\texecSync(\"termux-clipboard-set\", options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall back to Wayland or X11 tools.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!copied) {\n\t\t\t\t\tconst hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);\n\t\t\t\t\tconst hasX11Display = Boolean(process.env.DISPLAY);\n\t\t\t\t\tconst isWayland = isWaylandSession();\n\t\t\t\t\tif (isWayland && hasWaylandDisplay) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Verify wl-copy exists (spawn errors are async and won't be caught)\n\t\t\t\t\t\t\texecSync(\"which wl-copy\", { stdio: \"ignore\" });\n\t\t\t\t\t\t\t// wl-copy with execSync hangs due to fork behavior; use spawn instead\n\t\t\t\t\t\t\tconst proc = spawn(\"wl-copy\", [], { stdio: [\"pipe\", \"ignore\", \"ignore\"] });\n\t\t\t\t\t\t\tproc.stdin.on(\"error\", () => {\n\t\t\t\t\t\t\t\t// Ignore EPIPE errors if wl-copy exits early\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tproc.stdin.write(text);\n\t\t\t\t\t\t\tproc.stdin.end();\n\t\t\t\t\t\t\tproc.unref();\n\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tif (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to OSC 52 fallback.\n\t\t}\n\t}\n\n\tif (remote || !copied) {\n\t\tconst osc52Copied = emitOsc52(text);\n\t\tcopied = copied || osc52Copied;\n\t}\n\n\tif (!copied) {\n\t\tthrow new Error(\"Failed to copy to clipboard\");\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAQlD,SAAS,kBAAkB,CAAC,OAAmC,EAAQ;IACtE,IAAI,CAAC;QACJ,QAAQ,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACR,QAAQ,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;AAAA,CACD;AAED,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAEzC,SAAS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E,GAAG,EAAE,CAAC;gCAC5B,6CAA6C;4BADhB,CAE7B,CAAC,CAAC;4BACH,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;4BACvB,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;4BACjB,IAAI,CAAC,KAAK,EAAE,CAAC;4BACb,MAAM,GAAG,IAAI,CAAC;wBACf,CAAC;wBAAC,MAAM,CAAC;4BACR,IAAI,aAAa,EAAE,CAAC;gCACnB,kBAAkB,CAAC,OAAO,CAAC,CAAC;gCAC5B,MAAM,GAAG,IAAI,CAAC;4BACf,CAAC;wBACF,CAAC;oBACF,CAAC;yBAAM,IAAI,aAAa,EAAE,CAAC;wBAC1B,kBAAkB,CAAC,OAAO,CAAC,CAAC;wBAC5B,MAAM,GAAG,IAAI,CAAC;oBACf,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QAAC,MAAM,CAAC;YACR,mCAAmC;QACpC,CAAC;IACF,CAAC;IAED,IAAI,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,GAAG,MAAM,IAAI,WAAW,CAAC;IAChC,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAChD,CAAC;AAAA,CACD","sourcesContent":["import { execSync, spawn } from \"child_process\";\nimport { platform } from \"os\";\nimport { isWaylandSession } from \"./clipboard-image.js\";\nimport { clipboard } from \"./clipboard-native.js\";\n\ntype NativeClipboardExecOptions = {\n\tinput: string;\n\ttimeout: number;\n\tstdio: [\"pipe\", \"ignore\", \"ignore\"];\n};\n\nfunction copyToX11Clipboard(options: NativeClipboardExecOptions): void {\n\ttry {\n\t\texecSync(\"xclip -selection clipboard\", options);\n\t} catch {\n\t\texecSync(\"xsel --clipboard --input\", options);\n\t}\n}\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\nfunction isRemoteSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tlet copied = false;\n\n\tconst p = platform();\n\n\t// Prefer direct clipboard writes. Emitting OSC 52 first can make terminals\n\t// write the same native clipboard concurrently with the addon, and very large\n\t// OSC 52 payloads can desynchronize terminal rendering.\n\t//\n\t// On Linux, skip the native addon. The underlying `clipboard-rs` crate is\n\t// X11-only and does not retain selection ownership after `set_text`\n\t// resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even\n\t// some X11 sessions the call resolves successfully without populating the\n\t// clipboard. The platform tools below (wl-copy, xclip, xsel) properly\n\t// daemonize and keep ownership.\n\ttry {\n\t\tif (clipboard && p !== \"linux\") {\n\t\t\tawait clipboard.setText(text);\n\t\t\tcopied = true;\n\t\t}\n\t} catch {\n\t\t// Fall through to platform-specific clipboard tools.\n\t}\n\n\tconst remote = isRemoteSession();\n\tif (copied && !remote) {\n\t\treturn;\n\t}\n\n\tconst options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: [\"pipe\", \"ignore\", \"ignore\"] };\n\n\tif (!copied) {\n\t\ttry {\n\t\t\tif (p === \"darwin\") {\n\t\t\t\texecSync(\"pbcopy\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else if (p === \"win32\") {\n\t\t\t\texecSync(\"clip\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else {\n\t\t\t\t// Linux. Try Termux, Wayland, or X11 clipboard tools.\n\t\t\t\tif (process.env.TERMUX_VERSION) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\texecSync(\"termux-clipboard-set\", options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall back to Wayland or X11 tools.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!copied) {\n\t\t\t\t\tconst hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);\n\t\t\t\t\tconst hasX11Display = Boolean(process.env.DISPLAY);\n\t\t\t\t\tconst isWayland = isWaylandSession();\n\t\t\t\t\tif (isWayland && hasWaylandDisplay) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Verify wl-copy exists (spawn errors are async and won't be caught)\n\t\t\t\t\t\t\texecSync(\"which wl-copy\", { stdio: \"ignore\" });\n\t\t\t\t\t\t\t// wl-copy with execSync hangs due to fork behavior; use spawn instead\n\t\t\t\t\t\t\tconst proc = spawn(\"wl-copy\", [], { stdio: [\"pipe\", \"ignore\", \"ignore\"] });\n\t\t\t\t\t\t\tproc.stdin.on(\"error\", () => {\n\t\t\t\t\t\t\t\t// Ignore EPIPE errors if wl-copy exits early\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tproc.stdin.write(text);\n\t\t\t\t\t\t\tproc.stdin.end();\n\t\t\t\t\t\t\tproc.unref();\n\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tif (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to OSC 52 fallback.\n\t\t}\n\t}\n\n\tif (remote || !copied) {\n\t\tconst osc52Copied = emitOsc52(text);\n\t\tcopied = copied || osc52Copied;\n\t}\n\n\tif (!copied) {\n\t\tthrow new Error(\"Failed to copy to clipboard\");\n\t}\n}\n"]}
1
+ {"version":3,"file":"clipboard.js","sourceRoot":"","sources":["../../src/utils/clipboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAQlD,SAAS,kBAAkB,CAAC,OAAmC,EAAQ;IACtE,IAAI,CAAC;QACJ,QAAQ,CAAC,4BAA4B,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACR,QAAQ,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;AAAA,CACD;AAED,MAAM,wBAAwB,GAAG,OAAO,CAAC;AAEzC,SAAS,eAAe,CAAC,GAAG,GAAsB,OAAO,CAAC,GAAG,EAAW;IACvE,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC;AAAA,CAC5E;AAED,SAAS,SAAS,CAAC,IAAY,EAAW;IACzC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACrD,IAAI,OAAO,CAAC,MAAM,GAAG,wBAAwB,EAAE,CAAC;QAC/C,OAAO,KAAK,CAAC;IACd,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,OAAO,MAAM,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC;AAAA,CACZ;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAY,EAAiB;IAClE,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,MAAM,CAAC,GAAG,QAA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,IAAI,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;QACvB,MAAM,WAAW,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,GAAG,MAAM,IAAI,WAAW,CAAC;IAChC,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;IAChD,CAAC;AAAA,CACD","sourcesContent":["import { execSync, spawn } from \"child_process\";\nimport { platform } from \"os\";\nimport { isWaylandSession } from \"./clipboard-image.ts\";\nimport { clipboard } from \"./clipboard-native.ts\";\n\ntype NativeClipboardExecOptions = {\n\tinput: string;\n\ttimeout: number;\n\tstdio: [\"pipe\", \"ignore\", \"ignore\"];\n};\n\nfunction copyToX11Clipboard(options: NativeClipboardExecOptions): void {\n\ttry {\n\t\texecSync(\"xclip -selection clipboard\", options);\n\t} catch {\n\t\texecSync(\"xsel --clipboard --input\", options);\n\t}\n}\n\nconst MAX_OSC52_ENCODED_LENGTH = 100_000;\n\nfunction isRemoteSession(env: NodeJS.ProcessEnv = process.env): boolean {\n\treturn Boolean(env.SSH_CONNECTION || env.SSH_CLIENT || env.MOSH_CONNECTION);\n}\n\nfunction emitOsc52(text: string): boolean {\n\tconst encoded = Buffer.from(text).toString(\"base64\");\n\tif (encoded.length > MAX_OSC52_ENCODED_LENGTH) {\n\t\treturn false;\n\t}\n\tprocess.stdout.write(`\\x1b]52;c;${encoded}\\x07`);\n\treturn true;\n}\n\nexport async function copyToClipboard(text: string): Promise<void> {\n\tlet copied = false;\n\n\tconst p = platform();\n\n\t// Prefer direct clipboard writes. Emitting OSC 52 first can make terminals\n\t// write the same native clipboard concurrently with the addon, and very large\n\t// OSC 52 payloads can desynchronize terminal rendering.\n\t//\n\t// On Linux, skip the native addon. The underlying `clipboard-rs` crate is\n\t// X11-only and does not retain selection ownership after `set_text`\n\t// resolves, so on Wayland-only compositors (Hyprland, Niri, ...) and even\n\t// some X11 sessions the call resolves successfully without populating the\n\t// clipboard. The platform tools below (wl-copy, xclip, xsel) properly\n\t// daemonize and keep ownership.\n\ttry {\n\t\tif (clipboard && p !== \"linux\") {\n\t\t\tawait clipboard.setText(text);\n\t\t\tcopied = true;\n\t\t}\n\t} catch {\n\t\t// Fall through to platform-specific clipboard tools.\n\t}\n\n\tconst remote = isRemoteSession();\n\tif (copied && !remote) {\n\t\treturn;\n\t}\n\n\tconst options: NativeClipboardExecOptions = { input: text, timeout: 5000, stdio: [\"pipe\", \"ignore\", \"ignore\"] };\n\n\tif (!copied) {\n\t\ttry {\n\t\t\tif (p === \"darwin\") {\n\t\t\t\texecSync(\"pbcopy\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else if (p === \"win32\") {\n\t\t\t\texecSync(\"clip\", options);\n\t\t\t\tcopied = true;\n\t\t\t} else {\n\t\t\t\t// Linux. Try Termux, Wayland, or X11 clipboard tools.\n\t\t\t\tif (process.env.TERMUX_VERSION) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\texecSync(\"termux-clipboard-set\", options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t// Fall back to Wayland or X11 tools.\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!copied) {\n\t\t\t\t\tconst hasWaylandDisplay = Boolean(process.env.WAYLAND_DISPLAY);\n\t\t\t\t\tconst hasX11Display = Boolean(process.env.DISPLAY);\n\t\t\t\t\tconst isWayland = isWaylandSession();\n\t\t\t\t\tif (isWayland && hasWaylandDisplay) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t// Verify wl-copy exists (spawn errors are async and won't be caught)\n\t\t\t\t\t\t\texecSync(\"which wl-copy\", { stdio: \"ignore\" });\n\t\t\t\t\t\t\t// wl-copy with execSync hangs due to fork behavior; use spawn instead\n\t\t\t\t\t\t\tconst proc = spawn(\"wl-copy\", [], { stdio: [\"pipe\", \"ignore\", \"ignore\"] });\n\t\t\t\t\t\t\tproc.stdin.on(\"error\", () => {\n\t\t\t\t\t\t\t\t// Ignore EPIPE errors if wl-copy exits early\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tproc.stdin.write(text);\n\t\t\t\t\t\t\tproc.stdin.end();\n\t\t\t\t\t\t\tproc.unref();\n\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\tif (hasX11Display) {\n\t\t\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (hasX11Display) {\n\t\t\t\t\t\tcopyToX11Clipboard(options);\n\t\t\t\t\t\tcopied = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} catch {\n\t\t\t// Fall through to OSC 52 fallback.\n\t\t}\n\t}\n\n\tif (remote || !copied) {\n\t\tconst osc52Copied = emitOsc52(text);\n\t\tcopied = copied || osc52Copied;\n\t}\n\n\tif (!copied) {\n\t\tthrow new Error(\"Failed to copy to clipboard\");\n\t}\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { PhotonImageType } from "./photon.js";
1
+ import type { PhotonImageType } from "./photon.ts";
2
2
  type Photon = typeof import("@silvia-odwyer/photon-node");
3
3
  export declare function applyExifOrientation(photon: Photon, image: PhotonImageType, originalBytes: Uint8Array): PhotonImageType;
4
4
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"exif-orientation.d.ts","sourceRoot":"","sources":["../../src/utils/exif-orientation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,KAAK,MAAM,GAAG,cAAc,4BAA4B,CAAC,CAAC;AAgJ1D,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,eAAe,EACtB,aAAa,EAAE,UAAU,GACvB,eAAe,CAgCjB","sourcesContent":["import type { PhotonImageType } from \"./photon.js\";\n\ntype Photon = typeof import(\"@silvia-odwyer/photon-node\");\n\nfunction readOrientationFromTiff(bytes: Uint8Array, tiffStart: number): number {\n\tif (tiffStart + 8 > bytes.length) return 1;\n\n\tconst byteOrder = (bytes[tiffStart] << 8) | bytes[tiffStart + 1];\n\tconst le = byteOrder === 0x4949;\n\n\tconst read16 = (pos: number): number => {\n\t\tif (le) return bytes[pos] | (bytes[pos + 1] << 8);\n\t\treturn (bytes[pos] << 8) | bytes[pos + 1];\n\t};\n\n\tconst read32 = (pos: number): number => {\n\t\tif (le) return bytes[pos] | (bytes[pos + 1] << 8) | (bytes[pos + 2] << 16) | (bytes[pos + 3] << 24);\n\t\treturn ((bytes[pos] << 24) | (bytes[pos + 1] << 16) | (bytes[pos + 2] << 8) | bytes[pos + 3]) >>> 0;\n\t};\n\n\tconst ifdOffset = read32(tiffStart + 4);\n\tconst ifdStart = tiffStart + ifdOffset;\n\tif (ifdStart + 2 > bytes.length) return 1;\n\n\tconst entryCount = read16(ifdStart);\n\tfor (let i = 0; i < entryCount; i++) {\n\t\tconst entryPos = ifdStart + 2 + i * 12;\n\t\tif (entryPos + 12 > bytes.length) return 1;\n\n\t\tif (read16(entryPos) === 0x0112) {\n\t\t\tconst value = read16(entryPos + 8);\n\t\t\treturn value >= 1 && value <= 8 ? value : 1;\n\t\t}\n\t}\n\n\treturn 1;\n}\n\nfunction findJpegTiffOffset(bytes: Uint8Array): number {\n\tlet offset = 2;\n\twhile (offset < bytes.length - 1) {\n\t\tif (bytes[offset] !== 0xff) return -1;\n\t\tconst marker = bytes[offset + 1];\n\t\tif (marker === 0xff) {\n\t\t\toffset++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (marker === 0xe1) {\n\t\t\tif (offset + 4 >= bytes.length) return -1;\n\t\t\tconst segmentStart = offset + 4;\n\t\t\tif (segmentStart + 6 > bytes.length) return -1;\n\t\t\tif (!hasExifHeader(bytes, segmentStart)) return -1;\n\t\t\treturn segmentStart + 6;\n\t\t}\n\n\t\tif (offset + 4 > bytes.length) return -1;\n\t\tconst length = (bytes[offset + 2] << 8) | bytes[offset + 3];\n\t\toffset += 2 + length;\n\t}\n\n\treturn -1;\n}\n\nfunction findWebpTiffOffset(bytes: Uint8Array): number {\n\tlet offset = 12;\n\twhile (offset + 8 <= bytes.length) {\n\t\tconst chunkId = String.fromCharCode(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]);\n\t\tconst chunkSize =\n\t\t\tbytes[offset + 4] | (bytes[offset + 5] << 8) | (bytes[offset + 6] << 16) | (bytes[offset + 7] << 24);\n\t\tconst dataStart = offset + 8;\n\n\t\tif (chunkId === \"EXIF\") {\n\t\t\tif (dataStart + chunkSize > bytes.length) return -1;\n\t\t\t// Some WebP files have \"Exif\\0\\0\" prefix before the TIFF header\n\t\t\tconst tiffStart = chunkSize >= 6 && hasExifHeader(bytes, dataStart) ? dataStart + 6 : dataStart;\n\t\t\treturn tiffStart;\n\t\t}\n\n\t\t// RIFF chunks are padded to even size\n\t\toffset = dataStart + chunkSize + (chunkSize % 2);\n\t}\n\n\treturn -1;\n}\n\nfunction hasExifHeader(bytes: Uint8Array, offset: number): boolean {\n\treturn (\n\t\tbytes[offset] === 0x45 &&\n\t\tbytes[offset + 1] === 0x78 &&\n\t\tbytes[offset + 2] === 0x69 &&\n\t\tbytes[offset + 3] === 0x66 &&\n\t\tbytes[offset + 4] === 0x00 &&\n\t\tbytes[offset + 5] === 0x00\n\t);\n}\n\nfunction getExifOrientation(bytes: Uint8Array): number {\n\tlet tiffOffset = -1;\n\n\t// JPEG: starts with FF D8\n\tif (bytes.length >= 2 && bytes[0] === 0xff && bytes[1] === 0xd8) {\n\t\ttiffOffset = findJpegTiffOffset(bytes);\n\t}\n\t// WebP: starts with RIFF....WEBP\n\telse if (\n\t\tbytes.length >= 12 &&\n\t\tbytes[0] === 0x52 &&\n\t\tbytes[1] === 0x49 &&\n\t\tbytes[2] === 0x46 &&\n\t\tbytes[3] === 0x46 &&\n\t\tbytes[8] === 0x57 &&\n\t\tbytes[9] === 0x45 &&\n\t\tbytes[10] === 0x42 &&\n\t\tbytes[11] === 0x50\n\t) {\n\t\ttiffOffset = findWebpTiffOffset(bytes);\n\t}\n\n\tif (tiffOffset === -1) return 1;\n\treturn readOrientationFromTiff(bytes, tiffOffset);\n}\n\ntype DstIndexFn = (x: number, y: number, w: number, h: number) => number;\n\nfunction rotate90(photon: Photon, image: PhotonImageType, dstIndex: DstIndexFn): PhotonImageType {\n\tconst w = image.get_width();\n\tconst h = image.get_height();\n\tconst src = image.get_raw_pixels();\n\tconst dst = new Uint8Array(src.length);\n\n\tfor (let y = 0; y < h; y++) {\n\t\tfor (let x = 0; x < w; x++) {\n\t\t\tconst srcIdx = (y * w + x) * 4;\n\t\t\tconst dstIdx = dstIndex(x, y, w, h) * 4;\n\t\t\tdst[dstIdx] = src[srcIdx];\n\t\t\tdst[dstIdx + 1] = src[srcIdx + 1];\n\t\t\tdst[dstIdx + 2] = src[srcIdx + 2];\n\t\t\tdst[dstIdx + 3] = src[srcIdx + 3];\n\t\t}\n\t}\n\n\treturn new photon.PhotonImage(dst, h, w);\n}\n\n// Flip orientations mutate in-place. Rotations return a new image (caller must free the old one if different).\nexport function applyExifOrientation(\n\tphoton: Photon,\n\timage: PhotonImageType,\n\toriginalBytes: Uint8Array,\n): PhotonImageType {\n\tconst orientation = getExifOrientation(originalBytes);\n\tif (orientation === 1) return image;\n\n\tswitch (orientation) {\n\t\tcase 2:\n\t\t\tphoton.fliph(image);\n\t\t\treturn image;\n\t\tcase 3:\n\t\t\tphoton.fliph(image);\n\t\t\tphoton.flipv(image);\n\t\t\treturn image;\n\t\tcase 4:\n\t\t\tphoton.flipv(image);\n\t\t\treturn image;\n\t\tcase 5: {\n\t\t\tconst rotated = rotate90(photon, image, (x, y, _w, h) => x * h + (h - 1 - y));\n\t\t\tphoton.fliph(rotated);\n\t\t\treturn rotated;\n\t\t}\n\t\tcase 6:\n\t\t\treturn rotate90(photon, image, (x, y, _w, h) => x * h + (h - 1 - y));\n\t\tcase 7: {\n\t\t\tconst rotated = rotate90(photon, image, (x, y, w, h) => (w - 1 - x) * h + y);\n\t\t\tphoton.fliph(rotated);\n\t\t\treturn rotated;\n\t\t}\n\t\tcase 8:\n\t\t\treturn rotate90(photon, image, (x, y, w, h) => (w - 1 - x) * h + y);\n\t\tdefault:\n\t\t\treturn image;\n\t}\n}\n"]}
1
+ {"version":3,"file":"exif-orientation.d.ts","sourceRoot":"","sources":["../../src/utils/exif-orientation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD,KAAK,MAAM,GAAG,cAAc,4BAA4B,CAAC,CAAC;AAgJ1D,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,eAAe,EACtB,aAAa,EAAE,UAAU,GACvB,eAAe,CAgCjB","sourcesContent":["import type { PhotonImageType } from \"./photon.ts\";\n\ntype Photon = typeof import(\"@silvia-odwyer/photon-node\");\n\nfunction readOrientationFromTiff(bytes: Uint8Array, tiffStart: number): number {\n\tif (tiffStart + 8 > bytes.length) return 1;\n\n\tconst byteOrder = (bytes[tiffStart] << 8) | bytes[tiffStart + 1];\n\tconst le = byteOrder === 0x4949;\n\n\tconst read16 = (pos: number): number => {\n\t\tif (le) return bytes[pos] | (bytes[pos + 1] << 8);\n\t\treturn (bytes[pos] << 8) | bytes[pos + 1];\n\t};\n\n\tconst read32 = (pos: number): number => {\n\t\tif (le) return bytes[pos] | (bytes[pos + 1] << 8) | (bytes[pos + 2] << 16) | (bytes[pos + 3] << 24);\n\t\treturn ((bytes[pos] << 24) | (bytes[pos + 1] << 16) | (bytes[pos + 2] << 8) | bytes[pos + 3]) >>> 0;\n\t};\n\n\tconst ifdOffset = read32(tiffStart + 4);\n\tconst ifdStart = tiffStart + ifdOffset;\n\tif (ifdStart + 2 > bytes.length) return 1;\n\n\tconst entryCount = read16(ifdStart);\n\tfor (let i = 0; i < entryCount; i++) {\n\t\tconst entryPos = ifdStart + 2 + i * 12;\n\t\tif (entryPos + 12 > bytes.length) return 1;\n\n\t\tif (read16(entryPos) === 0x0112) {\n\t\t\tconst value = read16(entryPos + 8);\n\t\t\treturn value >= 1 && value <= 8 ? value : 1;\n\t\t}\n\t}\n\n\treturn 1;\n}\n\nfunction findJpegTiffOffset(bytes: Uint8Array): number {\n\tlet offset = 2;\n\twhile (offset < bytes.length - 1) {\n\t\tif (bytes[offset] !== 0xff) return -1;\n\t\tconst marker = bytes[offset + 1];\n\t\tif (marker === 0xff) {\n\t\t\toffset++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (marker === 0xe1) {\n\t\t\tif (offset + 4 >= bytes.length) return -1;\n\t\t\tconst segmentStart = offset + 4;\n\t\t\tif (segmentStart + 6 > bytes.length) return -1;\n\t\t\tif (!hasExifHeader(bytes, segmentStart)) return -1;\n\t\t\treturn segmentStart + 6;\n\t\t}\n\n\t\tif (offset + 4 > bytes.length) return -1;\n\t\tconst length = (bytes[offset + 2] << 8) | bytes[offset + 3];\n\t\toffset += 2 + length;\n\t}\n\n\treturn -1;\n}\n\nfunction findWebpTiffOffset(bytes: Uint8Array): number {\n\tlet offset = 12;\n\twhile (offset + 8 <= bytes.length) {\n\t\tconst chunkId = String.fromCharCode(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]);\n\t\tconst chunkSize =\n\t\t\tbytes[offset + 4] | (bytes[offset + 5] << 8) | (bytes[offset + 6] << 16) | (bytes[offset + 7] << 24);\n\t\tconst dataStart = offset + 8;\n\n\t\tif (chunkId === \"EXIF\") {\n\t\t\tif (dataStart + chunkSize > bytes.length) return -1;\n\t\t\t// Some WebP files have \"Exif\\0\\0\" prefix before the TIFF header\n\t\t\tconst tiffStart = chunkSize >= 6 && hasExifHeader(bytes, dataStart) ? dataStart + 6 : dataStart;\n\t\t\treturn tiffStart;\n\t\t}\n\n\t\t// RIFF chunks are padded to even size\n\t\toffset = dataStart + chunkSize + (chunkSize % 2);\n\t}\n\n\treturn -1;\n}\n\nfunction hasExifHeader(bytes: Uint8Array, offset: number): boolean {\n\treturn (\n\t\tbytes[offset] === 0x45 &&\n\t\tbytes[offset + 1] === 0x78 &&\n\t\tbytes[offset + 2] === 0x69 &&\n\t\tbytes[offset + 3] === 0x66 &&\n\t\tbytes[offset + 4] === 0x00 &&\n\t\tbytes[offset + 5] === 0x00\n\t);\n}\n\nfunction getExifOrientation(bytes: Uint8Array): number {\n\tlet tiffOffset = -1;\n\n\t// JPEG: starts with FF D8\n\tif (bytes.length >= 2 && bytes[0] === 0xff && bytes[1] === 0xd8) {\n\t\ttiffOffset = findJpegTiffOffset(bytes);\n\t}\n\t// WebP: starts with RIFF....WEBP\n\telse if (\n\t\tbytes.length >= 12 &&\n\t\tbytes[0] === 0x52 &&\n\t\tbytes[1] === 0x49 &&\n\t\tbytes[2] === 0x46 &&\n\t\tbytes[3] === 0x46 &&\n\t\tbytes[8] === 0x57 &&\n\t\tbytes[9] === 0x45 &&\n\t\tbytes[10] === 0x42 &&\n\t\tbytes[11] === 0x50\n\t) {\n\t\ttiffOffset = findWebpTiffOffset(bytes);\n\t}\n\n\tif (tiffOffset === -1) return 1;\n\treturn readOrientationFromTiff(bytes, tiffOffset);\n}\n\ntype DstIndexFn = (x: number, y: number, w: number, h: number) => number;\n\nfunction rotate90(photon: Photon, image: PhotonImageType, dstIndex: DstIndexFn): PhotonImageType {\n\tconst w = image.get_width();\n\tconst h = image.get_height();\n\tconst src = image.get_raw_pixels();\n\tconst dst = new Uint8Array(src.length);\n\n\tfor (let y = 0; y < h; y++) {\n\t\tfor (let x = 0; x < w; x++) {\n\t\t\tconst srcIdx = (y * w + x) * 4;\n\t\t\tconst dstIdx = dstIndex(x, y, w, h) * 4;\n\t\t\tdst[dstIdx] = src[srcIdx];\n\t\t\tdst[dstIdx + 1] = src[srcIdx + 1];\n\t\t\tdst[dstIdx + 2] = src[srcIdx + 2];\n\t\t\tdst[dstIdx + 3] = src[srcIdx + 3];\n\t\t}\n\t}\n\n\treturn new photon.PhotonImage(dst, h, w);\n}\n\n// Flip orientations mutate in-place. Rotations return a new image (caller must free the old one if different).\nexport function applyExifOrientation(\n\tphoton: Photon,\n\timage: PhotonImageType,\n\toriginalBytes: Uint8Array,\n): PhotonImageType {\n\tconst orientation = getExifOrientation(originalBytes);\n\tif (orientation === 1) return image;\n\n\tswitch (orientation) {\n\t\tcase 2:\n\t\t\tphoton.fliph(image);\n\t\t\treturn image;\n\t\tcase 3:\n\t\t\tphoton.fliph(image);\n\t\t\tphoton.flipv(image);\n\t\t\treturn image;\n\t\tcase 4:\n\t\t\tphoton.flipv(image);\n\t\t\treturn image;\n\t\tcase 5: {\n\t\t\tconst rotated = rotate90(photon, image, (x, y, _w, h) => x * h + (h - 1 - y));\n\t\t\tphoton.fliph(rotated);\n\t\t\treturn rotated;\n\t\t}\n\t\tcase 6:\n\t\t\treturn rotate90(photon, image, (x, y, _w, h) => x * h + (h - 1 - y));\n\t\tcase 7: {\n\t\t\tconst rotated = rotate90(photon, image, (x, y, w, h) => (w - 1 - x) * h + y);\n\t\t\tphoton.fliph(rotated);\n\t\t\treturn rotated;\n\t\t}\n\t\tcase 8:\n\t\t\treturn rotate90(photon, image, (x, y, w, h) => (w - 1 - x) * h + y);\n\t\tdefault:\n\t\t\treturn image;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"exif-orientation.js","sourceRoot":"","sources":["../../src/utils/exif-orientation.ts"],"names":[],"mappings":"AAIA,SAAS,uBAAuB,CAAC,KAAiB,EAAE,SAAiB,EAAU;IAC9E,IAAI,SAAS,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM;QAAE,OAAO,CAAC,CAAC;IAE3C,MAAM,SAAS,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;IACjE,MAAM,EAAE,GAAG,SAAS,KAAK,MAAM,CAAC;I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C,CAAC;QACtE,KAAK,CAAC,EAAE,CAAC;YACR,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAC7E,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACtB,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,KAAK,CAAC;YACL,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACrE;YACC,OAAO,KAAK,CAAC;IACf,CAAC;AAAA,CACD","sourcesContent":["import type { PhotonImageType } from \"./photon.js\";\n\ntype Photon = typeof import(\"@silvia-odwyer/photon-node\");\n\nfunction readOrientationFromTiff(bytes: Uint8Array, tiffStart: number): number {\n\tif (tiffStart + 8 > bytes.length) return 1;\n\n\tconst byteOrder = (bytes[tiffStart] << 8) | bytes[tiffStart + 1];\n\tconst le = byteOrder === 0x4949;\n\n\tconst read16 = (pos: number): number => {\n\t\tif (le) return bytes[pos] | (bytes[pos + 1] << 8);\n\t\treturn (bytes[pos] << 8) | bytes[pos + 1];\n\t};\n\n\tconst read32 = (pos: number): number => {\n\t\tif (le) return bytes[pos] | (bytes[pos + 1] << 8) | (bytes[pos + 2] << 16) | (bytes[pos + 3] << 24);\n\t\treturn ((bytes[pos] << 24) | (bytes[pos + 1] << 16) | (bytes[pos + 2] << 8) | bytes[pos + 3]) >>> 0;\n\t};\n\n\tconst ifdOffset = read32(tiffStart + 4);\n\tconst ifdStart = tiffStart + ifdOffset;\n\tif (ifdStart + 2 > bytes.length) return 1;\n\n\tconst entryCount = read16(ifdStart);\n\tfor (let i = 0; i < entryCount; i++) {\n\t\tconst entryPos = ifdStart + 2 + i * 12;\n\t\tif (entryPos + 12 > bytes.length) return 1;\n\n\t\tif (read16(entryPos) === 0x0112) {\n\t\t\tconst value = read16(entryPos + 8);\n\t\t\treturn value >= 1 && value <= 8 ? value : 1;\n\t\t}\n\t}\n\n\treturn 1;\n}\n\nfunction findJpegTiffOffset(bytes: Uint8Array): number {\n\tlet offset = 2;\n\twhile (offset < bytes.length - 1) {\n\t\tif (bytes[offset] !== 0xff) return -1;\n\t\tconst marker = bytes[offset + 1];\n\t\tif (marker === 0xff) {\n\t\t\toffset++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (marker === 0xe1) {\n\t\t\tif (offset + 4 >= bytes.length) return -1;\n\t\t\tconst segmentStart = offset + 4;\n\t\t\tif (segmentStart + 6 > bytes.length) return -1;\n\t\t\tif (!hasExifHeader(bytes, segmentStart)) return -1;\n\t\t\treturn segmentStart + 6;\n\t\t}\n\n\t\tif (offset + 4 > bytes.length) return -1;\n\t\tconst length = (bytes[offset + 2] << 8) | bytes[offset + 3];\n\t\toffset += 2 + length;\n\t}\n\n\treturn -1;\n}\n\nfunction findWebpTiffOffset(bytes: Uint8Array): number {\n\tlet offset = 12;\n\twhile (offset + 8 <= bytes.length) {\n\t\tconst chunkId = String.fromCharCode(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]);\n\t\tconst chunkSize =\n\t\t\tbytes[offset + 4] | (bytes[offset + 5] << 8) | (bytes[offset + 6] << 16) | (bytes[offset + 7] << 24);\n\t\tconst dataStart = offset + 8;\n\n\t\tif (chunkId === \"EXIF\") {\n\t\t\tif (dataStart + chunkSize > bytes.length) return -1;\n\t\t\t// Some WebP files have \"Exif\\0\\0\" prefix before the TIFF header\n\t\t\tconst tiffStart = chunkSize >= 6 && hasExifHeader(bytes, dataStart) ? dataStart + 6 : dataStart;\n\t\t\treturn tiffStart;\n\t\t}\n\n\t\t// RIFF chunks are padded to even size\n\t\toffset = dataStart + chunkSize + (chunkSize % 2);\n\t}\n\n\treturn -1;\n}\n\nfunction hasExifHeader(bytes: Uint8Array, offset: number): boolean {\n\treturn (\n\t\tbytes[offset] === 0x45 &&\n\t\tbytes[offset + 1] === 0x78 &&\n\t\tbytes[offset + 2] === 0x69 &&\n\t\tbytes[offset + 3] === 0x66 &&\n\t\tbytes[offset + 4] === 0x00 &&\n\t\tbytes[offset + 5] === 0x00\n\t);\n}\n\nfunction getExifOrientation(bytes: Uint8Array): number {\n\tlet tiffOffset = -1;\n\n\t// JPEG: starts with FF D8\n\tif (bytes.length >= 2 && bytes[0] === 0xff && bytes[1] === 0xd8) {\n\t\ttiffOffset = findJpegTiffOffset(bytes);\n\t}\n\t// WebP: starts with RIFF....WEBP\n\telse if (\n\t\tbytes.length >= 12 &&\n\t\tbytes[0] === 0x52 &&\n\t\tbytes[1] === 0x49 &&\n\t\tbytes[2] === 0x46 &&\n\t\tbytes[3] === 0x46 &&\n\t\tbytes[8] === 0x57 &&\n\t\tbytes[9] === 0x45 &&\n\t\tbytes[10] === 0x42 &&\n\t\tbytes[11] === 0x50\n\t) {\n\t\ttiffOffset = findWebpTiffOffset(bytes);\n\t}\n\n\tif (tiffOffset === -1) return 1;\n\treturn readOrientationFromTiff(bytes, tiffOffset);\n}\n\ntype DstIndexFn = (x: number, y: number, w: number, h: number) => number;\n\nfunction rotate90(photon: Photon, image: PhotonImageType, dstIndex: DstIndexFn): PhotonImageType {\n\tconst w = image.get_width();\n\tconst h = image.get_height();\n\tconst src = image.get_raw_pixels();\n\tconst dst = new Uint8Array(src.length);\n\n\tfor (let y = 0; y < h; y++) {\n\t\tfor (let x = 0; x < w; x++) {\n\t\t\tconst srcIdx = (y * w + x) * 4;\n\t\t\tconst dstIdx = dstIndex(x, y, w, h) * 4;\n\t\t\tdst[dstIdx] = src[srcIdx];\n\t\t\tdst[dstIdx + 1] = src[srcIdx + 1];\n\t\t\tdst[dstIdx + 2] = src[srcIdx + 2];\n\t\t\tdst[dstIdx + 3] = src[srcIdx + 3];\n\t\t}\n\t}\n\n\treturn new photon.PhotonImage(dst, h, w);\n}\n\n// Flip orientations mutate in-place. Rotations return a new image (caller must free the old one if different).\nexport function applyExifOrientation(\n\tphoton: Photon,\n\timage: PhotonImageType,\n\toriginalBytes: Uint8Array,\n): PhotonImageType {\n\tconst orientation = getExifOrientation(originalBytes);\n\tif (orientation === 1) return image;\n\n\tswitch (orientation) {\n\t\tcase 2:\n\t\t\tphoton.fliph(image);\n\t\t\treturn image;\n\t\tcase 3:\n\t\t\tphoton.fliph(image);\n\t\t\tphoton.flipv(image);\n\t\t\treturn image;\n\t\tcase 4:\n\t\t\tphoton.flipv(image);\n\t\t\treturn image;\n\t\tcase 5: {\n\t\t\tconst rotated = rotate90(photon, image, (x, y, _w, h) => x * h + (h - 1 - y));\n\t\t\tphoton.fliph(rotated);\n\t\t\treturn rotated;\n\t\t}\n\t\tcase 6:\n\t\t\treturn rotate90(photon, image, (x, y, _w, h) => x * h + (h - 1 - y));\n\t\tcase 7: {\n\t\t\tconst rotated = rotate90(photon, image, (x, y, w, h) => (w - 1 - x) * h + y);\n\t\t\tphoton.fliph(rotated);\n\t\t\treturn rotated;\n\t\t}\n\t\tcase 8:\n\t\t\treturn rotate90(photon, image, (x, y, w, h) => (w - 1 - x) * h + y);\n\t\tdefault:\n\t\t\treturn image;\n\t}\n}\n"]}
1
+ {"version":3,"file":"exif-orientation.js","sourceRoot":"","sources":["../../src/utils/exif-orientation.ts"],"names":[],"mappings":"AAIA,SAAS,uBAAuB,CAAC,KAAiB,EAAE,SAAiB,EAAU;IAC9E,IAAI,SAAS,GAAG,CAAC,GAAG,KAAK,CAAC,MAAM;QAAE,OAAO,CAAC,CAAC;IAE3C,MAAM,SAAS,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC;IACjE,MAAM,EAAE,GAAG,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AC,GAAG,CAAC,CAAC,CAAC,CAAC;QACtE,KAAK,CAAC,EAAE,CAAC;YACR,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAC7E,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACtB,OAAO,OAAO,CAAC;QAChB,CAAC;QACD,KAAK,CAAC;YACL,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACrE;YACC,OAAO,KAAK,CAAC;IACf,CAAC;AAAA,CACD","sourcesContent":["import type { PhotonImageType } from \"./photon.ts\";\n\ntype Photon = typeof import(\"@silvia-odwyer/photon-node\");\n\nfunction readOrientationFromTiff(bytes: Uint8Array, tiffStart: number): number {\n\tif (tiffStart + 8 > bytes.length) return 1;\n\n\tconst byteOrder = (bytes[tiffStart] << 8) | bytes[tiffStart + 1];\n\tconst le = byteOrder === 0x4949;\n\n\tconst read16 = (pos: number): number => {\n\t\tif (le) return bytes[pos] | (bytes[pos + 1] << 8);\n\t\treturn (bytes[pos] << 8) | bytes[pos + 1];\n\t};\n\n\tconst read32 = (pos: number): number => {\n\t\tif (le) return bytes[pos] | (bytes[pos + 1] << 8) | (bytes[pos + 2] << 16) | (bytes[pos + 3] << 24);\n\t\treturn ((bytes[pos] << 24) | (bytes[pos + 1] << 16) | (bytes[pos + 2] << 8) | bytes[pos + 3]) >>> 0;\n\t};\n\n\tconst ifdOffset = read32(tiffStart + 4);\n\tconst ifdStart = tiffStart + ifdOffset;\n\tif (ifdStart + 2 > bytes.length) return 1;\n\n\tconst entryCount = read16(ifdStart);\n\tfor (let i = 0; i < entryCount; i++) {\n\t\tconst entryPos = ifdStart + 2 + i * 12;\n\t\tif (entryPos + 12 > bytes.length) return 1;\n\n\t\tif (read16(entryPos) === 0x0112) {\n\t\t\tconst value = read16(entryPos + 8);\n\t\t\treturn value >= 1 && value <= 8 ? value : 1;\n\t\t}\n\t}\n\n\treturn 1;\n}\n\nfunction findJpegTiffOffset(bytes: Uint8Array): number {\n\tlet offset = 2;\n\twhile (offset < bytes.length - 1) {\n\t\tif (bytes[offset] !== 0xff) return -1;\n\t\tconst marker = bytes[offset + 1];\n\t\tif (marker === 0xff) {\n\t\t\toffset++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (marker === 0xe1) {\n\t\t\tif (offset + 4 >= bytes.length) return -1;\n\t\t\tconst segmentStart = offset + 4;\n\t\t\tif (segmentStart + 6 > bytes.length) return -1;\n\t\t\tif (!hasExifHeader(bytes, segmentStart)) return -1;\n\t\t\treturn segmentStart + 6;\n\t\t}\n\n\t\tif (offset + 4 > bytes.length) return -1;\n\t\tconst length = (bytes[offset + 2] << 8) | bytes[offset + 3];\n\t\toffset += 2 + length;\n\t}\n\n\treturn -1;\n}\n\nfunction findWebpTiffOffset(bytes: Uint8Array): number {\n\tlet offset = 12;\n\twhile (offset + 8 <= bytes.length) {\n\t\tconst chunkId = String.fromCharCode(bytes[offset], bytes[offset + 1], bytes[offset + 2], bytes[offset + 3]);\n\t\tconst chunkSize =\n\t\t\tbytes[offset + 4] | (bytes[offset + 5] << 8) | (bytes[offset + 6] << 16) | (bytes[offset + 7] << 24);\n\t\tconst dataStart = offset + 8;\n\n\t\tif (chunkId === \"EXIF\") {\n\t\t\tif (dataStart + chunkSize > bytes.length) return -1;\n\t\t\t// Some WebP files have \"Exif\\0\\0\" prefix before the TIFF header\n\t\t\tconst tiffStart = chunkSize >= 6 && hasExifHeader(bytes, dataStart) ? dataStart + 6 : dataStart;\n\t\t\treturn tiffStart;\n\t\t}\n\n\t\t// RIFF chunks are padded to even size\n\t\toffset = dataStart + chunkSize + (chunkSize % 2);\n\t}\n\n\treturn -1;\n}\n\nfunction hasExifHeader(bytes: Uint8Array, offset: number): boolean {\n\treturn (\n\t\tbytes[offset] === 0x45 &&\n\t\tbytes[offset + 1] === 0x78 &&\n\t\tbytes[offset + 2] === 0x69 &&\n\t\tbytes[offset + 3] === 0x66 &&\n\t\tbytes[offset + 4] === 0x00 &&\n\t\tbytes[offset + 5] === 0x00\n\t);\n}\n\nfunction getExifOrientation(bytes: Uint8Array): number {\n\tlet tiffOffset = -1;\n\n\t// JPEG: starts with FF D8\n\tif (bytes.length >= 2 && bytes[0] === 0xff && bytes[1] === 0xd8) {\n\t\ttiffOffset = findJpegTiffOffset(bytes);\n\t}\n\t// WebP: starts with RIFF....WEBP\n\telse if (\n\t\tbytes.length >= 12 &&\n\t\tbytes[0] === 0x52 &&\n\t\tbytes[1] === 0x49 &&\n\t\tbytes[2] === 0x46 &&\n\t\tbytes[3] === 0x46 &&\n\t\tbytes[8] === 0x57 &&\n\t\tbytes[9] === 0x45 &&\n\t\tbytes[10] === 0x42 &&\n\t\tbytes[11] === 0x50\n\t) {\n\t\ttiffOffset = findWebpTiffOffset(bytes);\n\t}\n\n\tif (tiffOffset === -1) return 1;\n\treturn readOrientationFromTiff(bytes, tiffOffset);\n}\n\ntype DstIndexFn = (x: number, y: number, w: number, h: number) => number;\n\nfunction rotate90(photon: Photon, image: PhotonImageType, dstIndex: DstIndexFn): PhotonImageType {\n\tconst w = image.get_width();\n\tconst h = image.get_height();\n\tconst src = image.get_raw_pixels();\n\tconst dst = new Uint8Array(src.length);\n\n\tfor (let y = 0; y < h; y++) {\n\t\tfor (let x = 0; x < w; x++) {\n\t\t\tconst srcIdx = (y * w + x) * 4;\n\t\t\tconst dstIdx = dstIndex(x, y, w, h) * 4;\n\t\t\tdst[dstIdx] = src[srcIdx];\n\t\t\tdst[dstIdx + 1] = src[srcIdx + 1];\n\t\t\tdst[dstIdx + 2] = src[srcIdx + 2];\n\t\t\tdst[dstIdx + 3] = src[srcIdx + 3];\n\t\t}\n\t}\n\n\treturn new photon.PhotonImage(dst, h, w);\n}\n\n// Flip orientations mutate in-place. Rotations return a new image (caller must free the old one if different).\nexport function applyExifOrientation(\n\tphoton: Photon,\n\timage: PhotonImageType,\n\toriginalBytes: Uint8Array,\n): PhotonImageType {\n\tconst orientation = getExifOrientation(originalBytes);\n\tif (orientation === 1) return image;\n\n\tswitch (orientation) {\n\t\tcase 2:\n\t\t\tphoton.fliph(image);\n\t\t\treturn image;\n\t\tcase 3:\n\t\t\tphoton.fliph(image);\n\t\t\tphoton.flipv(image);\n\t\t\treturn image;\n\t\tcase 4:\n\t\t\tphoton.flipv(image);\n\t\t\treturn image;\n\t\tcase 5: {\n\t\t\tconst rotated = rotate90(photon, image, (x, y, _w, h) => x * h + (h - 1 - y));\n\t\t\tphoton.fliph(rotated);\n\t\t\treturn rotated;\n\t\t}\n\t\tcase 6:\n\t\t\treturn rotate90(photon, image, (x, y, _w, h) => x * h + (h - 1 - y));\n\t\tcase 7: {\n\t\t\tconst rotated = rotate90(photon, image, (x, y, w, h) => (w - 1 - x) * h + y);\n\t\t\tphoton.fliph(rotated);\n\t\t\treturn rotated;\n\t\t}\n\t\tcase 8:\n\t\t\treturn rotate90(photon, image, (x, y, w, h) => (w - 1 - x) * h + y);\n\t\tdefault:\n\t\t\treturn image;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"image-convert.d.ts","sourceRoot":"","sources":["../../src/utils/image-convert.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAsB,YAAY,CACjC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CA8BpD","sourcesContent":["import { applyExifOrientation } from \"./exif-orientation.js\";\nimport { loadPhoton } from \"./photon.js\";\n\n/**\n * Convert image to PNG format for terminal display.\n * Kitty graphics protocol requires PNG format (f=100).\n */\nexport async function convertToPng(\n\tbase64Data: string,\n\tmimeType: string,\n): Promise<{ data: string; mimeType: string } | null> {\n\t// Already PNG, no conversion needed\n\tif (mimeType === \"image/png\") {\n\t\treturn { data: base64Data, mimeType };\n\t}\n\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\t// Photon not available, can't convert\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst bytes = new Uint8Array(Buffer.from(base64Data, \"base64\"));\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(bytes);\n\t\tconst image = applyExifOrientation(photon, rawImage, bytes);\n\t\tif (image !== rawImage) rawImage.free();\n\t\ttry {\n\t\t\tconst pngBuffer = image.get_bytes();\n\t\t\treturn {\n\t\t\t\tdata: Buffer.from(pngBuffer).toString(\"base64\"),\n\t\t\t\tmimeType: \"image/png\",\n\t\t\t};\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\t// Conversion failed\n\t\treturn null;\n\t}\n}\n"]}
1
+ {"version":3,"file":"image-convert.d.ts","sourceRoot":"","sources":["../../src/utils/image-convert.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAsB,YAAY,CACjC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CA8BpD","sourcesContent":["import { applyExifOrientation } from \"./exif-orientation.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\n/**\n * Convert image to PNG format for terminal display.\n * Kitty graphics protocol requires PNG format (f=100).\n */\nexport async function convertToPng(\n\tbase64Data: string,\n\tmimeType: string,\n): Promise<{ data: string; mimeType: string } | null> {\n\t// Already PNG, no conversion needed\n\tif (mimeType === \"image/png\") {\n\t\treturn { data: base64Data, mimeType };\n\t}\n\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\t// Photon not available, can't convert\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst bytes = new Uint8Array(Buffer.from(base64Data, \"base64\"));\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(bytes);\n\t\tconst image = applyExifOrientation(photon, rawImage, bytes);\n\t\tif (image !== rawImage) rawImage.free();\n\t\ttry {\n\t\t\tconst pngBuffer = image.get_bytes();\n\t\t\treturn {\n\t\t\t\tdata: Buffer.from(pngBuffer).toString(\"base64\"),\n\t\t\t\tmimeType: \"image/png\",\n\t\t\t};\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\t// Conversion failed\n\t\treturn null;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"image-convert.js","sourceRoot":"","sources":["../../src/utils/image-convert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,UAAkB,EAClB,QAAgB,EACqC;IACrD,oCAAoC;IACpC,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;QAC9B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;IACvC,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,UAAU,EAAE,CAAC;IAClC,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,sCAAsC;QACtC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,CAAC;QACJ,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;QAChE,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC9D,MAAM,KAAK,GAAG,oBAAoB,CAAC,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC5D,IAAI,KAAK,KAAK,QAAQ;YAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACxC,IAAI,CAAC;YACJ,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;YACpC,OAAO;gBACN,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAC/C,QAAQ,EAAE,WAAW;aACrB,CAAC;QACH,CAAC;gBAAS,CAAC;YACV,KAAK,CAAC,IAAI,EAAE,CAAC;QACd,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,oBAAoB;QACpB,OAAO,IAAI,CAAC;IACb,CAAC;AAAA,CACD","sourcesContent":["import { applyExifOrientation } from \"./exif-orientation.js\";\nimport { loadPhoton } from \"./photon.js\";\n\n/**\n * Convert image to PNG format for terminal display.\n * Kitty graphics protocol requires PNG format (f=100).\n */\nexport async function convertToPng(\n\tbase64Data: string,\n\tmimeType: string,\n): Promise<{ data: string; mimeType: string } | null> {\n\t// Already PNG, no conversion needed\n\tif (mimeType === \"image/png\") {\n\t\treturn { data: base64Data, mimeType };\n\t}\n\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\t// Photon not available, can't convert\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst bytes = new Uint8Array(Buffer.from(base64Data, \"base64\"));\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(bytes);\n\t\tconst image = applyExifOrientation(photon, rawImage, bytes);\n\t\tif (image !== rawImage) rawImage.free();\n\t\ttry {\n\t\t\tconst pngBuffer = image.get_bytes();\n\t\t\treturn {\n\t\t\t\tdata: Buffer.from(pngBuffer).toString(\"base64\"),\n\t\t\t\tmimeType: \"image/png\",\n\t\t\t};\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\t// Conversion failed\n\t\treturn null;\n\t}\n}\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b,CAAC;AAAA,CACD","sourcesContent":["import { applyExifOrientation } from \"./exif-orientation.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\n/**\n * Convert image to PNG format for terminal display.\n * Kitty graphics protocol requires PNG format (f=100).\n */\nexport async function convertToPng(\n\tbase64Data: string,\n\tmimeType: string,\n): Promise<{ data: string; mimeType: string } | null> {\n\t// Already PNG, no conversion needed\n\tif (mimeType === \"image/png\") {\n\t\treturn { data: base64Data, mimeType };\n\t}\n\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\t// Photon not available, can't convert\n\t\treturn null;\n\t}\n\n\ttry {\n\t\tconst bytes = new Uint8Array(Buffer.from(base64Data, \"base64\"));\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(bytes);\n\t\tconst image = applyExifOrientation(photon, rawImage, bytes);\n\t\tif (image !== rawImage) rawImage.free();\n\t\ttry {\n\t\t\tconst pngBuffer = image.get_bytes();\n\t\t\treturn {\n\t\t\t\tdata: Buffer.from(pngBuffer).toString(\"base64\"),\n\t\t\t\tmimeType: \"image/png\",\n\t\t\t};\n\t\t} finally {\n\t\t\timage.free();\n\t\t}\n\t} catch {\n\t\t// Conversion failed\n\t\treturn null;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"image-resize.d.ts","sourceRoot":"","sources":["../../src/utils/image-resize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAI1D,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;CACpB;AA2BD;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAuG/G;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAO5E","sourcesContent":["import type { ImageContent } from \"@earendil-works/pi-ai\";\nimport { applyExifOrientation } from \"./exif-orientation.js\";\nimport { loadPhoton } from \"./photon.js\";\n\nexport interface ImageResizeOptions {\n\tmaxWidth?: number; // Default: 2000\n\tmaxHeight?: number; // Default: 2000\n\tmaxBytes?: number; // Default: 4.5MB of base64 payload (below Anthropic's 5MB limit)\n\tjpegQuality?: number; // Default: 80\n}\n\nexport interface ResizedImage {\n\tdata: string; // base64\n\tmimeType: string;\n\toriginalWidth: number;\n\toriginalHeight: number;\n\twidth: number;\n\theight: number;\n\twasResized: boolean;\n}\n\n// 4.5MB of base64 payload. Provides headroom below Anthropic's 5MB limit.\nconst DEFAULT_MAX_BYTES = 4.5 * 1024 * 1024;\n\nconst DEFAULT_OPTIONS: Required<ImageResizeOptions> = {\n\tmaxWidth: 2000,\n\tmaxHeight: 2000,\n\tmaxBytes: DEFAULT_MAX_BYTES,\n\tjpegQuality: 80,\n};\n\ninterface EncodedCandidate {\n\tdata: string;\n\tencodedSize: number;\n\tmimeType: string;\n}\n\nfunction encodeCandidate(buffer: Uint8Array, mimeType: string): EncodedCandidate {\n\tconst data = Buffer.from(buffer).toString(\"base64\");\n\treturn {\n\t\tdata,\n\t\tencodedSize: Buffer.byteLength(data, \"utf-8\"),\n\t\tmimeType,\n\t};\n}\n\n/**\n * Resize an image to fit within the specified max dimensions and encoded file size.\n * Returns null if the image cannot be resized below maxBytes.\n *\n * Uses Photon (Rust/WASM) for image processing. If Photon is not available,\n * returns null.\n *\n * Strategy for staying under maxBytes:\n * 1. First resize to maxWidth/maxHeight\n * 2. Try both PNG and JPEG formats, pick the smaller one\n * 3. If still too large, try JPEG with decreasing quality\n * 4. If still too large, progressively reduce dimensions until 1x1\n */\nexport async function resizeImage(img: ImageContent, options?: ImageResizeOptions): Promise<ResizedImage | null> {\n\tconst opts = { ...DEFAULT_OPTIONS, ...options };\n\tconst inputBuffer = Buffer.from(img.data, \"base64\");\n\tconst inputBase64Size = Buffer.byteLength(img.data, \"utf-8\");\n\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\tlet image: ReturnType<typeof photon.PhotonImage.new_from_byteslice> | undefined;\n\ttry {\n\t\tconst inputBytes = new Uint8Array(inputBuffer);\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(inputBytes);\n\t\timage = applyExifOrientation(photon, rawImage, inputBytes);\n\t\tif (image !== rawImage) rawImage.free();\n\n\t\tconst originalWidth = image.get_width();\n\t\tconst originalHeight = image.get_height();\n\t\tconst format = img.mimeType?.split(\"/\")[1] ?? \"png\";\n\n\t\t// Check if already within all limits (dimensions AND encoded size)\n\t\tif (originalWidth <= opts.maxWidth && originalHeight <= opts.maxHeight && inputBase64Size < opts.maxBytes) {\n\t\t\treturn {\n\t\t\t\tdata: img.data,\n\t\t\t\tmimeType: img.mimeType ?? `image/${format}`,\n\t\t\t\toriginalWidth,\n\t\t\t\toriginalHeight,\n\t\t\t\twidth: originalWidth,\n\t\t\t\theight: originalHeight,\n\t\t\t\twasResized: false,\n\t\t\t};\n\t\t}\n\n\t\t// Calculate initial dimensions respecting max limits\n\t\tlet targetWidth = originalWidth;\n\t\tlet targetHeight = originalHeight;\n\n\t\tif (targetWidth > opts.maxWidth) {\n\t\t\ttargetHeight = Math.round((targetHeight * opts.maxWidth) / targetWidth);\n\t\t\ttargetWidth = opts.maxWidth;\n\t\t}\n\t\tif (targetHeight > opts.maxHeight) {\n\t\t\ttargetWidth = Math.round((targetWidth * opts.maxHeight) / targetHeight);\n\t\t\ttargetHeight = opts.maxHeight;\n\t\t}\n\n\t\tfunction tryEncodings(width: number, height: number, jpegQualities: number[]): EncodedCandidate[] {\n\t\t\tconst resized = photon!.resize(image!, width, height, photon!.SamplingFilter.Lanczos3);\n\n\t\t\ttry {\n\t\t\t\tconst candidates: EncodedCandidate[] = [encodeCandidate(resized.get_bytes(), \"image/png\")];\n\t\t\t\tfor (const quality of jpegQualities) {\n\t\t\t\t\tcandidates.push(encodeCandidate(resized.get_bytes_jpeg(quality), \"image/jpeg\"));\n\t\t\t\t}\n\t\t\t\treturn candidates;\n\t\t\t} finally {\n\t\t\t\tresized.free();\n\t\t\t}\n\t\t}\n\n\t\tconst qualitySteps = Array.from(new Set([opts.jpegQuality, 85, 70, 55, 40]));\n\t\tlet currentWidth = targetWidth;\n\t\tlet currentHeight = targetHeight;\n\n\t\twhile (true) {\n\t\t\tconst candidates = tryEncodings(currentWidth, currentHeight, qualitySteps);\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tif (candidate.encodedSize < opts.maxBytes) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: candidate.data,\n\t\t\t\t\t\tmimeType: candidate.mimeType,\n\t\t\t\t\t\toriginalWidth,\n\t\t\t\t\t\toriginalHeight,\n\t\t\t\t\t\twidth: currentWidth,\n\t\t\t\t\t\theight: currentHeight,\n\t\t\t\t\t\twasResized: true,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentWidth === 1 && currentHeight === 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst nextWidth = currentWidth === 1 ? 1 : Math.max(1, Math.floor(currentWidth * 0.75));\n\t\t\tconst nextHeight = currentHeight === 1 ? 1 : Math.max(1, Math.floor(currentHeight * 0.75));\n\t\t\tif (nextWidth === currentWidth && nextHeight === currentHeight) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcurrentWidth = nextWidth;\n\t\t\tcurrentHeight = nextHeight;\n\t\t}\n\n\t\treturn null;\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\tif (image) {\n\t\t\timage.free();\n\t\t}\n\t}\n}\n\n/**\n * Format a dimension note for resized images.\n * This helps the model understand the coordinate mapping.\n */\nexport function formatDimensionNote(result: ResizedImage): string | undefined {\n\tif (!result.wasResized) {\n\t\treturn undefined;\n\t}\n\n\tconst scale = result.originalWidth / result.width;\n\treturn `[Image: original ${result.originalWidth}x${result.originalHeight}, displayed at ${result.width}x${result.height}. Multiply coordinates by ${scale.toFixed(2)} to map to original image.]`;\n}\n"]}
1
+ {"version":3,"file":"image-resize.d.ts","sourceRoot":"","sources":["../../src/utils/image-resize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAI1D,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;CACpB;AA2BD;;;;;;;;;;;;GAYG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAuG/G;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,GAAG,SAAS,CAO5E","sourcesContent":["import type { ImageContent } from \"@earendil-works/pi-ai\";\nimport { applyExifOrientation } from \"./exif-orientation.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport interface ImageResizeOptions {\n\tmaxWidth?: number; // Default: 2000\n\tmaxHeight?: number; // Default: 2000\n\tmaxBytes?: number; // Default: 4.5MB of base64 payload (below Anthropic's 5MB limit)\n\tjpegQuality?: number; // Default: 80\n}\n\nexport interface ResizedImage {\n\tdata: string; // base64\n\tmimeType: string;\n\toriginalWidth: number;\n\toriginalHeight: number;\n\twidth: number;\n\theight: number;\n\twasResized: boolean;\n}\n\n// 4.5MB of base64 payload. Provides headroom below Anthropic's 5MB limit.\nconst DEFAULT_MAX_BYTES = 4.5 * 1024 * 1024;\n\nconst DEFAULT_OPTIONS: Required<ImageResizeOptions> = {\n\tmaxWidth: 2000,\n\tmaxHeight: 2000,\n\tmaxBytes: DEFAULT_MAX_BYTES,\n\tjpegQuality: 80,\n};\n\ninterface EncodedCandidate {\n\tdata: string;\n\tencodedSize: number;\n\tmimeType: string;\n}\n\nfunction encodeCandidate(buffer: Uint8Array, mimeType: string): EncodedCandidate {\n\tconst data = Buffer.from(buffer).toString(\"base64\");\n\treturn {\n\t\tdata,\n\t\tencodedSize: Buffer.byteLength(data, \"utf-8\"),\n\t\tmimeType,\n\t};\n}\n\n/**\n * Resize an image to fit within the specified max dimensions and encoded file size.\n * Returns null if the image cannot be resized below maxBytes.\n *\n * Uses Photon (Rust/WASM) for image processing. If Photon is not available,\n * returns null.\n *\n * Strategy for staying under maxBytes:\n * 1. First resize to maxWidth/maxHeight\n * 2. Try both PNG and JPEG formats, pick the smaller one\n * 3. If still too large, try JPEG with decreasing quality\n * 4. If still too large, progressively reduce dimensions until 1x1\n */\nexport async function resizeImage(img: ImageContent, options?: ImageResizeOptions): Promise<ResizedImage | null> {\n\tconst opts = { ...DEFAULT_OPTIONS, ...options };\n\tconst inputBuffer = Buffer.from(img.data, \"base64\");\n\tconst inputBase64Size = Buffer.byteLength(img.data, \"utf-8\");\n\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\tlet image: ReturnType<typeof photon.PhotonImage.new_from_byteslice> | undefined;\n\ttry {\n\t\tconst inputBytes = new Uint8Array(inputBuffer);\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(inputBytes);\n\t\timage = applyExifOrientation(photon, rawImage, inputBytes);\n\t\tif (image !== rawImage) rawImage.free();\n\n\t\tconst originalWidth = image.get_width();\n\t\tconst originalHeight = image.get_height();\n\t\tconst format = img.mimeType?.split(\"/\")[1] ?? \"png\";\n\n\t\t// Check if already within all limits (dimensions AND encoded size)\n\t\tif (originalWidth <= opts.maxWidth && originalHeight <= opts.maxHeight && inputBase64Size < opts.maxBytes) {\n\t\t\treturn {\n\t\t\t\tdata: img.data,\n\t\t\t\tmimeType: img.mimeType ?? `image/${format}`,\n\t\t\t\toriginalWidth,\n\t\t\t\toriginalHeight,\n\t\t\t\twidth: originalWidth,\n\t\t\t\theight: originalHeight,\n\t\t\t\twasResized: false,\n\t\t\t};\n\t\t}\n\n\t\t// Calculate initial dimensions respecting max limits\n\t\tlet targetWidth = originalWidth;\n\t\tlet targetHeight = originalHeight;\n\n\t\tif (targetWidth > opts.maxWidth) {\n\t\t\ttargetHeight = Math.round((targetHeight * opts.maxWidth) / targetWidth);\n\t\t\ttargetWidth = opts.maxWidth;\n\t\t}\n\t\tif (targetHeight > opts.maxHeight) {\n\t\t\ttargetWidth = Math.round((targetWidth * opts.maxHeight) / targetHeight);\n\t\t\ttargetHeight = opts.maxHeight;\n\t\t}\n\n\t\tfunction tryEncodings(width: number, height: number, jpegQualities: number[]): EncodedCandidate[] {\n\t\t\tconst resized = photon!.resize(image!, width, height, photon!.SamplingFilter.Lanczos3);\n\n\t\t\ttry {\n\t\t\t\tconst candidates: EncodedCandidate[] = [encodeCandidate(resized.get_bytes(), \"image/png\")];\n\t\t\t\tfor (const quality of jpegQualities) {\n\t\t\t\t\tcandidates.push(encodeCandidate(resized.get_bytes_jpeg(quality), \"image/jpeg\"));\n\t\t\t\t}\n\t\t\t\treturn candidates;\n\t\t\t} finally {\n\t\t\t\tresized.free();\n\t\t\t}\n\t\t}\n\n\t\tconst qualitySteps = Array.from(new Set([opts.jpegQuality, 85, 70, 55, 40]));\n\t\tlet currentWidth = targetWidth;\n\t\tlet currentHeight = targetHeight;\n\n\t\twhile (true) {\n\t\t\tconst candidates = tryEncodings(currentWidth, currentHeight, qualitySteps);\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tif (candidate.encodedSize < opts.maxBytes) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: candidate.data,\n\t\t\t\t\t\tmimeType: candidate.mimeType,\n\t\t\t\t\t\toriginalWidth,\n\t\t\t\t\t\toriginalHeight,\n\t\t\t\t\t\twidth: currentWidth,\n\t\t\t\t\t\theight: currentHeight,\n\t\t\t\t\t\twasResized: true,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentWidth === 1 && currentHeight === 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst nextWidth = currentWidth === 1 ? 1 : Math.max(1, Math.floor(currentWidth * 0.75));\n\t\t\tconst nextHeight = currentHeight === 1 ? 1 : Math.max(1, Math.floor(currentHeight * 0.75));\n\t\t\tif (nextWidth === currentWidth && nextHeight === currentHeight) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcurrentWidth = nextWidth;\n\t\t\tcurrentHeight = nextHeight;\n\t\t}\n\n\t\treturn null;\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\tif (image) {\n\t\t\timage.free();\n\t\t}\n\t}\n}\n\n/**\n * Format a dimension note for resized images.\n * This helps the model understand the coordinate mapping.\n */\nexport function formatDimensionNote(result: ResizedImage): string | undefined {\n\tif (!result.wasResized) {\n\t\treturn undefined;\n\t}\n\n\tconst scale = result.originalWidth / result.width;\n\treturn `[Image: original ${result.originalWidth}x${result.originalHeight}, displayed at ${result.width}x${result.height}. Multiply coordinates by ${scale.toFixed(2)} to map to original image.]`;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"image-resize.js","sourceRoot":"","sources":["../../src/utils/image-resize.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAmBzC,0EAA0E;AAC1E,MAAM,iBAAiB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5C,MAAM,eAAe,GAAiC;IACrD,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,iBAAiB;IAC3B,WAAW,EAAE,EAAE;CACf,CAAC;AAQF,SAAS,eAAe,CAAC,MAAkB,EAAE,QAAgB,EAAoB;IAChF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACpD,OAAO;QACN,IAAI;QACJ,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC;QAC7C,QAAQ;KACR,CAAC;AAAA,CACF;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAiB,EAAE,OAA4B,EAAgC;IAChH,MAAM,IAAI,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,EAAE,CAAC;IAChD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACpD,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAE7D,MAAM,MAAM,GAAG,MAAM,UAAU,EAAE,CAAC;IAClC,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,KAA2E,CAAC;IAChF,IAAI,CAAC;QACJ,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AK,CAAC;IAClD,OAAO,oBAAoB,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,cAAc,kBAAkB,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,6BAA6B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC;AAAA,CAClM","sourcesContent":["import type { ImageContent } from \"@earendil-works/pi-ai\";\nimport { applyExifOrientation } from \"./exif-orientation.js\";\nimport { loadPhoton } from \"./photon.js\";\n\nexport interface ImageResizeOptions {\n\tmaxWidth?: number; // Default: 2000\n\tmaxHeight?: number; // Default: 2000\n\tmaxBytes?: number; // Default: 4.5MB of base64 payload (below Anthropic's 5MB limit)\n\tjpegQuality?: number; // Default: 80\n}\n\nexport interface ResizedImage {\n\tdata: string; // base64\n\tmimeType: string;\n\toriginalWidth: number;\n\toriginalHeight: number;\n\twidth: number;\n\theight: number;\n\twasResized: boolean;\n}\n\n// 4.5MB of base64 payload. Provides headroom below Anthropic's 5MB limit.\nconst DEFAULT_MAX_BYTES = 4.5 * 1024 * 1024;\n\nconst DEFAULT_OPTIONS: Required<ImageResizeOptions> = {\n\tmaxWidth: 2000,\n\tmaxHeight: 2000,\n\tmaxBytes: DEFAULT_MAX_BYTES,\n\tjpegQuality: 80,\n};\n\ninterface EncodedCandidate {\n\tdata: string;\n\tencodedSize: number;\n\tmimeType: string;\n}\n\nfunction encodeCandidate(buffer: Uint8Array, mimeType: string): EncodedCandidate {\n\tconst data = Buffer.from(buffer).toString(\"base64\");\n\treturn {\n\t\tdata,\n\t\tencodedSize: Buffer.byteLength(data, \"utf-8\"),\n\t\tmimeType,\n\t};\n}\n\n/**\n * Resize an image to fit within the specified max dimensions and encoded file size.\n * Returns null if the image cannot be resized below maxBytes.\n *\n * Uses Photon (Rust/WASM) for image processing. If Photon is not available,\n * returns null.\n *\n * Strategy for staying under maxBytes:\n * 1. First resize to maxWidth/maxHeight\n * 2. Try both PNG and JPEG formats, pick the smaller one\n * 3. If still too large, try JPEG with decreasing quality\n * 4. If still too large, progressively reduce dimensions until 1x1\n */\nexport async function resizeImage(img: ImageContent, options?: ImageResizeOptions): Promise<ResizedImage | null> {\n\tconst opts = { ...DEFAULT_OPTIONS, ...options };\n\tconst inputBuffer = Buffer.from(img.data, \"base64\");\n\tconst inputBase64Size = Buffer.byteLength(img.data, \"utf-8\");\n\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\tlet image: ReturnType<typeof photon.PhotonImage.new_from_byteslice> | undefined;\n\ttry {\n\t\tconst inputBytes = new Uint8Array(inputBuffer);\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(inputBytes);\n\t\timage = applyExifOrientation(photon, rawImage, inputBytes);\n\t\tif (image !== rawImage) rawImage.free();\n\n\t\tconst originalWidth = image.get_width();\n\t\tconst originalHeight = image.get_height();\n\t\tconst format = img.mimeType?.split(\"/\")[1] ?? \"png\";\n\n\t\t// Check if already within all limits (dimensions AND encoded size)\n\t\tif (originalWidth <= opts.maxWidth && originalHeight <= opts.maxHeight && inputBase64Size < opts.maxBytes) {\n\t\t\treturn {\n\t\t\t\tdata: img.data,\n\t\t\t\tmimeType: img.mimeType ?? `image/${format}`,\n\t\t\t\toriginalWidth,\n\t\t\t\toriginalHeight,\n\t\t\t\twidth: originalWidth,\n\t\t\t\theight: originalHeight,\n\t\t\t\twasResized: false,\n\t\t\t};\n\t\t}\n\n\t\t// Calculate initial dimensions respecting max limits\n\t\tlet targetWidth = originalWidth;\n\t\tlet targetHeight = originalHeight;\n\n\t\tif (targetWidth > opts.maxWidth) {\n\t\t\ttargetHeight = Math.round((targetHeight * opts.maxWidth) / targetWidth);\n\t\t\ttargetWidth = opts.maxWidth;\n\t\t}\n\t\tif (targetHeight > opts.maxHeight) {\n\t\t\ttargetWidth = Math.round((targetWidth * opts.maxHeight) / targetHeight);\n\t\t\ttargetHeight = opts.maxHeight;\n\t\t}\n\n\t\tfunction tryEncodings(width: number, height: number, jpegQualities: number[]): EncodedCandidate[] {\n\t\t\tconst resized = photon!.resize(image!, width, height, photon!.SamplingFilter.Lanczos3);\n\n\t\t\ttry {\n\t\t\t\tconst candidates: EncodedCandidate[] = [encodeCandidate(resized.get_bytes(), \"image/png\")];\n\t\t\t\tfor (const quality of jpegQualities) {\n\t\t\t\t\tcandidates.push(encodeCandidate(resized.get_bytes_jpeg(quality), \"image/jpeg\"));\n\t\t\t\t}\n\t\t\t\treturn candidates;\n\t\t\t} finally {\n\t\t\t\tresized.free();\n\t\t\t}\n\t\t}\n\n\t\tconst qualitySteps = Array.from(new Set([opts.jpegQuality, 85, 70, 55, 40]));\n\t\tlet currentWidth = targetWidth;\n\t\tlet currentHeight = targetHeight;\n\n\t\twhile (true) {\n\t\t\tconst candidates = tryEncodings(currentWidth, currentHeight, qualitySteps);\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tif (candidate.encodedSize < opts.maxBytes) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: candidate.data,\n\t\t\t\t\t\tmimeType: candidate.mimeType,\n\t\t\t\t\t\toriginalWidth,\n\t\t\t\t\t\toriginalHeight,\n\t\t\t\t\t\twidth: currentWidth,\n\t\t\t\t\t\theight: currentHeight,\n\t\t\t\t\t\twasResized: true,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentWidth === 1 && currentHeight === 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst nextWidth = currentWidth === 1 ? 1 : Math.max(1, Math.floor(currentWidth * 0.75));\n\t\t\tconst nextHeight = currentHeight === 1 ? 1 : Math.max(1, Math.floor(currentHeight * 0.75));\n\t\t\tif (nextWidth === currentWidth && nextHeight === currentHeight) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcurrentWidth = nextWidth;\n\t\t\tcurrentHeight = nextHeight;\n\t\t}\n\n\t\treturn null;\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\tif (image) {\n\t\t\timage.free();\n\t\t}\n\t}\n}\n\n/**\n * Format a dimension note for resized images.\n * This helps the model understand the coordinate mapping.\n */\nexport function formatDimensionNote(result: ResizedImage): string | undefined {\n\tif (!result.wasResized) {\n\t\treturn undefined;\n\t}\n\n\tconst scale = result.originalWidth / result.width;\n\treturn `[Image: original ${result.originalWidth}x${result.originalHeight}, displayed at ${result.width}x${result.height}. Multiply coordinates by ${scale.toFixed(2)} to map to original image.]`;\n}\n"]}
1
+ {"version":3,"file":"image-resize.js","sourceRoot":"","sources":["../../src/utils/image-resize.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAmBzC,0EAA0E;AAC1E,MAAM,iBAAiB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAE5C,MAAM,eAAe,GAAiC;IACrD,QAAQ,EAAE,IAAI;IACd,SAAS,EAAE,IAAI;IACf,QAAQ,EAAE,iBAAiB;IAC3B,WAAW,EAAE,EAAE;CACf,CAAC;AAQF,SAAS,eAAe,CAAC,MAAkB,EAAE,QAAgB,EAAoB;IAChF,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACpD,OAAO;QACN,IAAI;QACJ,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC;QAC7C,QAAQ;KACR,CAAC;AAAA,CACF;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAiB,EAAE,OAA4B,EAAgC;IAChH,MAAM,IAAI,GAAG,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,EAAE,CAAC;IAChD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACpD,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,CAAC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CACD;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAoB,EAAsB;IAC7E,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,KAAK,GAAG,MAAM,CAAC,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC;IAClD,OAAO,oBAAoB,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,cAAc,kBAAkB,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,MAAM,6BAA6B,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,6BAA6B,CAAC;AAAA,CAClM","sourcesContent":["import type { ImageContent } from \"@earendil-works/pi-ai\";\nimport { applyExifOrientation } from \"./exif-orientation.ts\";\nimport { loadPhoton } from \"./photon.ts\";\n\nexport interface ImageResizeOptions {\n\tmaxWidth?: number; // Default: 2000\n\tmaxHeight?: number; // Default: 2000\n\tmaxBytes?: number; // Default: 4.5MB of base64 payload (below Anthropic's 5MB limit)\n\tjpegQuality?: number; // Default: 80\n}\n\nexport interface ResizedImage {\n\tdata: string; // base64\n\tmimeType: string;\n\toriginalWidth: number;\n\toriginalHeight: number;\n\twidth: number;\n\theight: number;\n\twasResized: boolean;\n}\n\n// 4.5MB of base64 payload. Provides headroom below Anthropic's 5MB limit.\nconst DEFAULT_MAX_BYTES = 4.5 * 1024 * 1024;\n\nconst DEFAULT_OPTIONS: Required<ImageResizeOptions> = {\n\tmaxWidth: 2000,\n\tmaxHeight: 2000,\n\tmaxBytes: DEFAULT_MAX_BYTES,\n\tjpegQuality: 80,\n};\n\ninterface EncodedCandidate {\n\tdata: string;\n\tencodedSize: number;\n\tmimeType: string;\n}\n\nfunction encodeCandidate(buffer: Uint8Array, mimeType: string): EncodedCandidate {\n\tconst data = Buffer.from(buffer).toString(\"base64\");\n\treturn {\n\t\tdata,\n\t\tencodedSize: Buffer.byteLength(data, \"utf-8\"),\n\t\tmimeType,\n\t};\n}\n\n/**\n * Resize an image to fit within the specified max dimensions and encoded file size.\n * Returns null if the image cannot be resized below maxBytes.\n *\n * Uses Photon (Rust/WASM) for image processing. If Photon is not available,\n * returns null.\n *\n * Strategy for staying under maxBytes:\n * 1. First resize to maxWidth/maxHeight\n * 2. Try both PNG and JPEG formats, pick the smaller one\n * 3. If still too large, try JPEG with decreasing quality\n * 4. If still too large, progressively reduce dimensions until 1x1\n */\nexport async function resizeImage(img: ImageContent, options?: ImageResizeOptions): Promise<ResizedImage | null> {\n\tconst opts = { ...DEFAULT_OPTIONS, ...options };\n\tconst inputBuffer = Buffer.from(img.data, \"base64\");\n\tconst inputBase64Size = Buffer.byteLength(img.data, \"utf-8\");\n\n\tconst photon = await loadPhoton();\n\tif (!photon) {\n\t\treturn null;\n\t}\n\n\tlet image: ReturnType<typeof photon.PhotonImage.new_from_byteslice> | undefined;\n\ttry {\n\t\tconst inputBytes = new Uint8Array(inputBuffer);\n\t\tconst rawImage = photon.PhotonImage.new_from_byteslice(inputBytes);\n\t\timage = applyExifOrientation(photon, rawImage, inputBytes);\n\t\tif (image !== rawImage) rawImage.free();\n\n\t\tconst originalWidth = image.get_width();\n\t\tconst originalHeight = image.get_height();\n\t\tconst format = img.mimeType?.split(\"/\")[1] ?? \"png\";\n\n\t\t// Check if already within all limits (dimensions AND encoded size)\n\t\tif (originalWidth <= opts.maxWidth && originalHeight <= opts.maxHeight && inputBase64Size < opts.maxBytes) {\n\t\t\treturn {\n\t\t\t\tdata: img.data,\n\t\t\t\tmimeType: img.mimeType ?? `image/${format}`,\n\t\t\t\toriginalWidth,\n\t\t\t\toriginalHeight,\n\t\t\t\twidth: originalWidth,\n\t\t\t\theight: originalHeight,\n\t\t\t\twasResized: false,\n\t\t\t};\n\t\t}\n\n\t\t// Calculate initial dimensions respecting max limits\n\t\tlet targetWidth = originalWidth;\n\t\tlet targetHeight = originalHeight;\n\n\t\tif (targetWidth > opts.maxWidth) {\n\t\t\ttargetHeight = Math.round((targetHeight * opts.maxWidth) / targetWidth);\n\t\t\ttargetWidth = opts.maxWidth;\n\t\t}\n\t\tif (targetHeight > opts.maxHeight) {\n\t\t\ttargetWidth = Math.round((targetWidth * opts.maxHeight) / targetHeight);\n\t\t\ttargetHeight = opts.maxHeight;\n\t\t}\n\n\t\tfunction tryEncodings(width: number, height: number, jpegQualities: number[]): EncodedCandidate[] {\n\t\t\tconst resized = photon!.resize(image!, width, height, photon!.SamplingFilter.Lanczos3);\n\n\t\t\ttry {\n\t\t\t\tconst candidates: EncodedCandidate[] = [encodeCandidate(resized.get_bytes(), \"image/png\")];\n\t\t\t\tfor (const quality of jpegQualities) {\n\t\t\t\t\tcandidates.push(encodeCandidate(resized.get_bytes_jpeg(quality), \"image/jpeg\"));\n\t\t\t\t}\n\t\t\t\treturn candidates;\n\t\t\t} finally {\n\t\t\t\tresized.free();\n\t\t\t}\n\t\t}\n\n\t\tconst qualitySteps = Array.from(new Set([opts.jpegQuality, 85, 70, 55, 40]));\n\t\tlet currentWidth = targetWidth;\n\t\tlet currentHeight = targetHeight;\n\n\t\twhile (true) {\n\t\t\tconst candidates = tryEncodings(currentWidth, currentHeight, qualitySteps);\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tif (candidate.encodedSize < opts.maxBytes) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata: candidate.data,\n\t\t\t\t\t\tmimeType: candidate.mimeType,\n\t\t\t\t\t\toriginalWidth,\n\t\t\t\t\t\toriginalHeight,\n\t\t\t\t\t\twidth: currentWidth,\n\t\t\t\t\t\theight: currentHeight,\n\t\t\t\t\t\twasResized: true,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (currentWidth === 1 && currentHeight === 1) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tconst nextWidth = currentWidth === 1 ? 1 : Math.max(1, Math.floor(currentWidth * 0.75));\n\t\t\tconst nextHeight = currentHeight === 1 ? 1 : Math.max(1, Math.floor(currentHeight * 0.75));\n\t\t\tif (nextWidth === currentWidth && nextHeight === currentHeight) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcurrentWidth = nextWidth;\n\t\t\tcurrentHeight = nextHeight;\n\t\t}\n\n\t\treturn null;\n\t} catch {\n\t\treturn null;\n\t} finally {\n\t\tif (image) {\n\t\t\timage.free();\n\t\t}\n\t}\n}\n\n/**\n * Format a dimension note for resized images.\n * This helps the model understand the coordinate mapping.\n */\nexport function formatDimensionNote(result: ResizedImage): string | undefined {\n\tif (!result.wasResized) {\n\t\treturn undefined;\n\t}\n\n\tconst scale = result.originalWidth / result.width;\n\treturn `[Image: original ${result.originalWidth}x${result.originalHeight}, displayed at ${result.width}x${result.height}. Multiply coordinates by ${scale.toFixed(2)} to map to original image.]`;\n}\n"]}
@@ -1,3 +1,15 @@
1
+ export interface PathInputOptions {
2
+ /** Trim leading/trailing whitespace before normalization. */
3
+ trim?: boolean;
4
+ /** Expand leading `~` to a home directory. Defaults to true. */
5
+ expandTilde?: boolean;
6
+ /** Home directory used for `~` expansion. Defaults to `os.homedir()`. */
7
+ homeDir?: string;
8
+ /** Strip a leading `@`, used for CLI @file paths. */
9
+ stripAtPrefix?: boolean;
10
+ /** Normalize unicode space variants to regular spaces. */
11
+ normalizeUnicodeSpaces?: boolean;
12
+ }
1
13
  /**
2
14
  * Resolve a path to its canonical (real) form, following symlinks.
3
15
  * Falls back to the raw path if resolution fails (e.g. the target does
@@ -7,10 +19,13 @@
7
19
  export declare function canonicalizePath(path: string): string;
8
20
  /**
9
21
  * Returns true if the value is NOT a package source (npm:, git:, etc.)
10
- * or a URL protocol. Bare names and relative paths without ./ prefix
22
+ * or a remote URL protocol. Bare names, relative paths, and file: URLs
11
23
  * are considered local.
12
24
  */
13
25
  export declare function isLocalPath(value: string): boolean;
26
+ export declare function normalizePath(input: string, options?: PathInputOptions): string;
27
+ export declare function resolvePath(input: string, baseDir?: string, options?: PathInputOptions): string;
14
28
  export declare function getCwdRelativePath(filePath: string, cwd: string): string | undefined;
15
29
  export declare function formatPathRelativeToCwdOrAbsolute(filePath: string, cwd: string): string;
30
+ export declare function markPathIgnoredByCloudSync(path: string): void;
16
31
  //# sourceMappingURL=paths.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/utils/paths.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMrD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAclD;AAMD,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CASpF;AAED,wBAAgB,iCAAiC,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAGvF","sourcesContent":["import { realpathSync } from \"node:fs\";\nimport { isAbsolute, relative, resolve as resolvePath, sep } from \"node:path\";\n\n/**\n * Resolve a path to its canonical (real) form, following symlinks.\n * Falls back to the raw path if resolution fails (e.g. the target does\n * not exist yet), so that callers never crash on missing filesystem\n * entries.\n */\nexport function canonicalizePath(path: string): string {\n\ttry {\n\t\treturn realpathSync(path);\n\t} catch {\n\t\treturn path;\n\t}\n}\n\n/**\n * Returns true if the value is NOT a package source (npm:, git:, etc.)\n * or a URL protocol. Bare names and relative paths without ./ prefix\n * are considered local.\n */\nexport function isLocalPath(value: string): boolean {\n\tconst trimmed = value.trim();\n\t// Known non-local prefixes\n\tif (\n\t\ttrimmed.startsWith(\"npm:\") ||\n\t\ttrimmed.startsWith(\"git:\") ||\n\t\ttrimmed.startsWith(\"github:\") ||\n\t\ttrimmed.startsWith(\"http:\") ||\n\t\ttrimmed.startsWith(\"https:\") ||\n\t\ttrimmed.startsWith(\"ssh:\")\n\t) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nfunction resolveAgainstCwd(filePath: string, cwd: string): string {\n\treturn isAbsolute(filePath) ? resolvePath(filePath) : resolvePath(cwd, filePath);\n}\n\nexport function getCwdRelativePath(filePath: string, cwd: string): string | undefined {\n\tconst resolvedCwd = resolvePath(cwd);\n\tconst resolvedPath = resolveAgainstCwd(filePath, resolvedCwd);\n\tconst relativePath = relative(resolvedCwd, resolvedPath);\n\tconst isInsideCwd =\n\t\trelativePath === \"\" ||\n\t\t(relativePath !== \"..\" && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath));\n\n\treturn isInsideCwd ? relativePath || \".\" : undefined;\n}\n\nexport function formatPathRelativeToCwdOrAbsolute(filePath: string, cwd: string): string {\n\tconst absolutePath = resolveAgainstCwd(filePath, cwd);\n\treturn (getCwdRelativePath(absolutePath, cwd) ?? absolutePath).split(sep).join(\"/\");\n}\n"]}
1
+ {"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/utils/paths.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,gBAAgB;IAChC,6DAA6D;IAC7D,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,gEAAgE;IAChE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,0DAA0D;IAC1D,sBAAsB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMrD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAclD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAsBnF;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,MAAsB,EAAE,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAIlH;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CASpF;AAED,wBAAgB,iCAAiC,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAGvF;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAe7D","sourcesContent":["import { realpathSync } from \"node:fs\";\nimport { homedir } from \"node:os\";\nimport { isAbsolute, join, resolve as nodeResolvePath, relative, sep } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { spawnProcessSync } from \"./child-process.ts\";\n\nconst UNICODE_SPACES = /[\\u00A0\\u2000-\\u200A\\u202F\\u205F\\u3000]/g;\n\nexport interface PathInputOptions {\n\t/** Trim leading/trailing whitespace before normalization. */\n\ttrim?: boolean;\n\t/** Expand leading `~` to a home directory. Defaults to true. */\n\texpandTilde?: boolean;\n\t/** Home directory used for `~` expansion. Defaults to `os.homedir()`. */\n\thomeDir?: string;\n\t/** Strip a leading `@`, used for CLI @file paths. */\n\tstripAtPrefix?: boolean;\n\t/** Normalize unicode space variants to regular spaces. */\n\tnormalizeUnicodeSpaces?: boolean;\n}\n\n/**\n * Resolve a path to its canonical (real) form, following symlinks.\n * Falls back to the raw path if resolution fails (e.g. the target does\n * not exist yet), so that callers never crash on missing filesystem\n * entries.\n */\nexport function canonicalizePath(path: string): string {\n\ttry {\n\t\treturn realpathSync(path);\n\t} catch {\n\t\treturn path;\n\t}\n}\n\n/**\n * Returns true if the value is NOT a package source (npm:, git:, etc.)\n * or a remote URL protocol. Bare names, relative paths, and file: URLs\n * are considered local.\n */\nexport function isLocalPath(value: string): boolean {\n\tconst trimmed = value.trim();\n\t// Known non-local prefixes. file: URLs are local paths and are intentionally resolved by resolvePath().\n\tif (\n\t\ttrimmed.startsWith(\"npm:\") ||\n\t\ttrimmed.startsWith(\"git:\") ||\n\t\ttrimmed.startsWith(\"github:\") ||\n\t\ttrimmed.startsWith(\"http:\") ||\n\t\ttrimmed.startsWith(\"https:\") ||\n\t\ttrimmed.startsWith(\"ssh:\")\n\t) {\n\t\treturn false;\n\t}\n\treturn true;\n}\n\nexport function normalizePath(input: string, options: PathInputOptions = {}): string {\n\tlet normalized = options.trim ? input.trim() : input;\n\tif (options.normalizeUnicodeSpaces) {\n\t\tnormalized = normalized.replace(UNICODE_SPACES, \" \");\n\t}\n\tif (options.stripAtPrefix && normalized.startsWith(\"@\")) {\n\t\tnormalized = normalized.slice(1);\n\t}\n\n\tif (options.expandTilde ?? true) {\n\t\tconst home = options.homeDir ?? homedir();\n\t\tif (normalized === \"~\") return home;\n\t\tif (normalized.startsWith(\"~/\") || (process.platform === \"win32\" && normalized.startsWith(\"~\\\\\"))) {\n\t\t\treturn join(home, normalized.slice(2));\n\t\t}\n\t}\n\n\tif (/^file:\\/\\//.test(normalized)) {\n\t\treturn fileURLToPath(normalized);\n\t}\n\n\treturn normalized;\n}\n\nexport function resolvePath(input: string, baseDir: string = process.cwd(), options: PathInputOptions = {}): string {\n\tconst normalized = normalizePath(input, options);\n\tconst normalizedBaseDir = normalizePath(baseDir);\n\treturn isAbsolute(normalized) ? nodeResolvePath(normalized) : nodeResolvePath(normalizedBaseDir, normalized);\n}\n\nexport function getCwdRelativePath(filePath: string, cwd: string): string | undefined {\n\tconst resolvedCwd = resolvePath(cwd);\n\tconst resolvedPath = resolvePath(filePath, resolvedCwd);\n\tconst relativePath = relative(resolvedCwd, resolvedPath);\n\tconst isInsideCwd =\n\t\trelativePath === \"\" ||\n\t\t(relativePath !== \"..\" && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath));\n\n\treturn isInsideCwd ? relativePath || \".\" : undefined;\n}\n\nexport function formatPathRelativeToCwdOrAbsolute(filePath: string, cwd: string): string {\n\tconst absolutePath = resolvePath(filePath, cwd);\n\treturn (getCwdRelativePath(absolutePath, cwd) ?? absolutePath).split(sep).join(\"/\");\n}\n\nexport function markPathIgnoredByCloudSync(path: string): void {\n\tconst attrs =\n\t\tprocess.platform === \"darwin\"\n\t\t\t? [\"com.dropbox.ignored\", \"com.apple.fileprovider.ignore#P\"]\n\t\t\t: process.platform === \"linux\"\n\t\t\t\t? [\"user.com.dropbox.ignored\"]\n\t\t\t\t: [];\n\n\tfor (const attr of attrs) {\n\t\tif (process.platform === \"darwin\") {\n\t\t\tspawnProcessSync(\"xattr\", [\"-w\", attr, \"1\", path], { encoding: \"utf-8\", stdio: \"ignore\" });\n\t\t} else {\n\t\t\tspawnProcessSync(\"setfattr\", [\"-n\", attr, \"-v\", \"1\", path], { encoding: \"utf-8\", stdio: \"ignore\" });\n\t\t}\n\t}\n}\n"]}
@@ -1,5 +1,9 @@
1
1
  import { realpathSync } from "node:fs";
2
- import { isAbsolute, relative, resolve as resolvePath, sep } from "node:path";
2
+ import { homedir } from "node:os";
3
+ import { isAbsolute, join, resolve as nodeResolvePath, relative, sep } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { spawnProcessSync } from "./child-process.js";
6
+ const UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g;
3
7
  /**
4
8
  * Resolve a path to its canonical (real) form, following symlinks.
5
9
  * Falls back to the raw path if resolution fails (e.g. the target does
@@ -16,12 +20,12 @@ export function canonicalizePath(path) {
16
20
  }
17
21
  /**
18
22
  * Returns true if the value is NOT a package source (npm:, git:, etc.)
19
- * or a URL protocol. Bare names and relative paths without ./ prefix
23
+ * or a remote URL protocol. Bare names, relative paths, and file: URLs
20
24
  * are considered local.
21
25
  */
22
26
  export function isLocalPath(value) {
23
27
  const trimmed = value.trim();
24
- // Known non-local prefixes
28
+ // Known non-local prefixes. file: URLs are local paths and are intentionally resolved by resolvePath().
25
29
  if (trimmed.startsWith("npm:") ||
26
30
  trimmed.startsWith("git:") ||
27
31
  trimmed.startsWith("github:") ||
@@ -32,19 +36,57 @@ export function isLocalPath(value) {
32
36
  }
33
37
  return true;
34
38
  }
35
- function resolveAgainstCwd(filePath, cwd) {
36
- return isAbsolute(filePath) ? resolvePath(filePath) : resolvePath(cwd, filePath);
39
+ export function normalizePath(input, options = {}) {
40
+ let normalized = options.trim ? input.trim() : input;
41
+ if (options.normalizeUnicodeSpaces) {
42
+ normalized = normalized.replace(UNICODE_SPACES, " ");
43
+ }
44
+ if (options.stripAtPrefix && normalized.startsWith("@")) {
45
+ normalized = normalized.slice(1);
46
+ }
47
+ if (options.expandTilde ?? true) {
48
+ const home = options.homeDir ?? homedir();
49
+ if (normalized === "~")
50
+ return home;
51
+ if (normalized.startsWith("~/") || (process.platform === "win32" && normalized.startsWith("~\\"))) {
52
+ return join(home, normalized.slice(2));
53
+ }
54
+ }
55
+ if (/^file:\/\//.test(normalized)) {
56
+ return fileURLToPath(normalized);
57
+ }
58
+ return normalized;
59
+ }
60
+ export function resolvePath(input, baseDir = process.cwd(), options = {}) {
61
+ const normalized = normalizePath(input, options);
62
+ const normalizedBaseDir = normalizePath(baseDir);
63
+ return isAbsolute(normalized) ? nodeResolvePath(normalized) : nodeResolvePath(normalizedBaseDir, normalized);
37
64
  }
38
65
  export function getCwdRelativePath(filePath, cwd) {
39
66
  const resolvedCwd = resolvePath(cwd);
40
- const resolvedPath = resolveAgainstCwd(filePath, resolvedCwd);
67
+ const resolvedPath = resolvePath(filePath, resolvedCwd);
41
68
  const relativePath = relative(resolvedCwd, resolvedPath);
42
69
  const isInsideCwd = relativePath === "" ||
43
70
  (relativePath !== ".." && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath));
44
71
  return isInsideCwd ? relativePath || "." : undefined;
45
72
  }
46
73
  export function formatPathRelativeToCwdOrAbsolute(filePath, cwd) {
47
- const absolutePath = resolveAgainstCwd(filePath, cwd);
74
+ const absolutePath = resolvePath(filePath, cwd);
48
75
  return (getCwdRelativePath(absolutePath, cwd) ?? absolutePath).split(sep).join("/");
49
76
  }
77
+ export function markPathIgnoredByCloudSync(path) {
78
+ const attrs = process.platform === "darwin"
79
+ ? ["com.dropbox.ignored", "com.apple.fileprovider.ignore#P"]
80
+ : process.platform === "linux"
81
+ ? ["user.com.dropbox.ignored"]
82
+ : [];
83
+ for (const attr of attrs) {
84
+ if (process.platform === "darwin") {
85
+ spawnProcessSync("xattr", ["-w", attr, "1", path], { encoding: "utf-8", stdio: "ignore" });
86
+ }
87
+ else {
88
+ spawnProcessSync("setfattr", ["-n", attr, "-v", "1", path], { encoding: "utf-8", stdio: "ignore" });
89
+ }
90
+ }
91
+ }
50
92
  //# sourceMappingURL=paths.js.map