@geminixiang/mikan 1.0.0-beta.53 → 1.0.0-beta.55

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 (556) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +3 -2
  3. package/dist/adapters/commands/admin.d.ts.map +1 -0
  4. package/dist/{commands → adapters/commands}/admin.js +4 -8
  5. package/dist/adapters/commands/admin.js.map +1 -0
  6. package/dist/adapters/commands/login.d.ts.map +1 -0
  7. package/dist/adapters/commands/login.js +166 -0
  8. package/dist/adapters/commands/login.js.map +1 -0
  9. package/dist/adapters/commands/manifest.d.ts.map +1 -0
  10. package/dist/{commands → adapters/commands}/manifest.js +0 -7
  11. package/dist/adapters/commands/manifest.js.map +1 -0
  12. package/dist/{commands → adapters/commands}/model.d.ts +6 -0
  13. package/dist/adapters/commands/model.d.ts.map +1 -0
  14. package/dist/{commands → adapters/commands}/model.js +56 -44
  15. package/dist/adapters/commands/model.js.map +1 -0
  16. package/dist/adapters/commands/new.d.ts.map +1 -0
  17. package/dist/{commands → adapters/commands}/new.js +7 -8
  18. package/dist/adapters/commands/new.js.map +1 -0
  19. package/dist/adapters/commands/registry.d.ts.map +1 -0
  20. package/dist/{commands → adapters/commands}/registry.js +1 -3
  21. package/dist/adapters/commands/registry.js.map +1 -0
  22. package/dist/adapters/commands/sandbox.d.ts.map +1 -0
  23. package/dist/{commands → adapters/commands}/sandbox.js +22 -21
  24. package/dist/adapters/commands/sandbox.js.map +1 -0
  25. package/dist/adapters/commands/session-view.d.ts.map +1 -0
  26. package/dist/{commands → adapters/commands}/session-view.js +8 -11
  27. package/dist/adapters/commands/session-view.js.map +1 -0
  28. package/dist/{commands → adapters/commands}/types.d.ts +6 -6
  29. package/dist/adapters/commands/types.d.ts.map +1 -0
  30. package/dist/adapters/commands/types.js.map +1 -0
  31. package/dist/adapters/commands/utils.d.ts +14 -0
  32. package/dist/adapters/commands/utils.d.ts.map +1 -0
  33. package/dist/{commands → adapters/commands}/utils.js +18 -1
  34. package/dist/adapters/commands/utils.js.map +1 -0
  35. package/dist/adapters/discord/bot.d.ts.map +1 -1
  36. package/dist/adapters/discord/bot.js +4 -5
  37. package/dist/adapters/discord/bot.js.map +1 -1
  38. package/dist/adapters/github/bot.d.ts.map +1 -1
  39. package/dist/adapters/github/bot.js +3 -4
  40. package/dist/adapters/github/bot.js.map +1 -1
  41. package/dist/adapters/github/client.d.ts.map +1 -1
  42. package/dist/adapters/github/client.js +5 -18
  43. package/dist/adapters/github/client.js.map +1 -1
  44. package/dist/adapters/github/tool-pack.d.ts +1 -1
  45. package/dist/adapters/github/tool-pack.d.ts.map +1 -1
  46. package/dist/adapters/github/tool-pack.js.map +1 -1
  47. package/dist/adapters/github/tools/checks.js +1 -1
  48. package/dist/adapters/github/tools/checks.js.map +1 -1
  49. package/dist/adapters/github/tools/issue.js +1 -1
  50. package/dist/adapters/github/tools/issue.js.map +1 -1
  51. package/dist/adapters/github/tools/pr.js +1 -1
  52. package/dist/adapters/github/tools/pr.js.map +1 -1
  53. package/dist/adapters/github/tools/read.d.ts.map +1 -1
  54. package/dist/adapters/github/tools/read.js +53 -53
  55. package/dist/adapters/github/tools/read.js.map +1 -1
  56. package/dist/adapters/github/tools/review-reply.js +1 -1
  57. package/dist/adapters/github/tools/review-reply.js.map +1 -1
  58. package/dist/adapters/github/tools/sync.js +1 -1
  59. package/dist/adapters/github/tools/sync.js.map +1 -1
  60. package/dist/adapters/intake.d.ts +1 -1
  61. package/dist/adapters/intake.d.ts.map +1 -1
  62. package/dist/adapters/intake.js +2 -6
  63. package/dist/adapters/intake.js.map +1 -1
  64. package/dist/adapters/markdown-tables.d.ts +0 -13
  65. package/dist/adapters/markdown-tables.d.ts.map +1 -1
  66. package/dist/adapters/markdown-tables.js +26 -38
  67. package/dist/adapters/markdown-tables.js.map +1 -1
  68. package/dist/adapters/shared.js +1 -1
  69. package/dist/adapters/shared.js.map +1 -1
  70. package/dist/adapters/slack/bot.d.ts +7 -4
  71. package/dist/adapters/slack/bot.d.ts.map +1 -1
  72. package/dist/adapters/slack/bot.js +104 -122
  73. package/dist/adapters/slack/bot.js.map +1 -1
  74. package/dist/adapters/slack/response-lifecycle.d.ts.map +1 -1
  75. package/dist/adapters/slack/response-lifecycle.js +33 -25
  76. package/dist/adapters/slack/response-lifecycle.js.map +1 -1
  77. package/dist/adapters/slack/tool-pack.d.ts +1 -1
  78. package/dist/adapters/slack/tool-pack.d.ts.map +1 -1
  79. package/dist/adapters/slack/tool-pack.js.map +1 -1
  80. package/dist/adapters/slack/update-diagnostics.d.ts.map +1 -1
  81. package/dist/adapters/slack/update-diagnostics.js +8 -24
  82. package/dist/adapters/slack/update-diagnostics.js.map +1 -1
  83. package/dist/adapters/telegram/bot.d.ts.map +1 -1
  84. package/dist/adapters/telegram/bot.js +3 -4
  85. package/dist/adapters/telegram/bot.js.map +1 -1
  86. package/dist/adapters/types.d.ts +2 -4
  87. package/dist/adapters/types.d.ts.map +1 -1
  88. package/dist/adapters/types.js.map +1 -1
  89. package/dist/{web → adapters/web}/admin/portal.d.ts +3 -3
  90. package/dist/adapters/web/admin/portal.d.ts.map +1 -0
  91. package/dist/{web → adapters/web}/admin/portal.js +535 -709
  92. package/dist/adapters/web/admin/portal.js.map +1 -0
  93. package/dist/{web → adapters/web}/admin/provider-models.d.ts +1 -1
  94. package/dist/adapters/web/admin/provider-models.d.ts.map +1 -0
  95. package/dist/adapters/web/admin/provider-models.js.map +1 -0
  96. package/dist/{web → adapters/web}/admin/types.d.ts +5 -5
  97. package/dist/adapters/web/admin/types.d.ts.map +1 -0
  98. package/dist/adapters/web/admin/types.js.map +1 -0
  99. package/dist/adapters/web/login/oauth.d.ts.map +1 -0
  100. package/dist/{web → adapters/web}/login/oauth.js +50 -54
  101. package/dist/adapters/web/login/oauth.js.map +1 -0
  102. package/dist/{web → adapters/web}/login/portal.d.ts +2 -2
  103. package/dist/adapters/web/login/portal.d.ts.map +1 -0
  104. package/dist/{web → adapters/web}/login/portal.js +6 -6
  105. package/dist/adapters/web/login/portal.js.map +1 -0
  106. package/dist/{web → adapters/web}/login/types.d.ts +1 -1
  107. package/dist/adapters/web/login/types.d.ts.map +1 -0
  108. package/dist/adapters/web/login/types.js.map +1 -0
  109. package/dist/{web → adapters/web}/portal-shell.d.ts +2 -2
  110. package/dist/adapters/web/portal-shell.d.ts.map +1 -0
  111. package/dist/{web → adapters/web}/portal-shell.js +2 -2
  112. package/dist/adapters/web/portal-shell.js.map +1 -0
  113. package/dist/{web → adapters/web}/server.d.ts +5 -5
  114. package/dist/adapters/web/server.d.ts.map +1 -0
  115. package/dist/{web → adapters/web}/server.js +4 -7
  116. package/dist/adapters/web/server.js.map +1 -0
  117. package/dist/adapters/web/session-view/portal.d.ts.map +1 -0
  118. package/dist/{web → adapters/web}/session-view/portal.js +9 -9
  119. package/dist/adapters/web/session-view/portal.js.map +1 -0
  120. package/dist/{web → adapters/web}/session-view/types.d.ts +3 -3
  121. package/dist/adapters/web/session-view/types.d.ts.map +1 -0
  122. package/dist/adapters/web/session-view/types.js.map +1 -0
  123. package/dist/adapters/web/token-store.d.ts.map +1 -0
  124. package/dist/adapters/web/token-store.js.map +1 -0
  125. package/dist/adapters/web/types.d.ts.map +1 -0
  126. package/dist/adapters/web/types.js.map +1 -0
  127. package/dist/cli/arg-grammar.d.ts +24 -0
  128. package/dist/cli/arg-grammar.d.ts.map +1 -1
  129. package/dist/cli/arg-grammar.js +39 -8
  130. package/dist/cli/arg-grammar.js.map +1 -1
  131. package/dist/cli/boot.d.ts.map +1 -1
  132. package/dist/cli/boot.js +48 -62
  133. package/dist/cli/boot.js.map +1 -1
  134. package/dist/cli/download.d.ts.map +1 -1
  135. package/dist/cli/download.js +51 -54
  136. package/dist/cli/download.js.map +1 -1
  137. package/dist/cli/office.d.ts.map +1 -1
  138. package/dist/cli/office.js +9 -26
  139. package/dist/cli/office.js.map +1 -1
  140. package/dist/cli/onboard.d.ts.map +1 -1
  141. package/dist/cli/onboard.js +15 -11
  142. package/dist/cli/onboard.js.map +1 -1
  143. package/dist/cli/sessions.d.ts.map +1 -1
  144. package/dist/cli/sessions.js +49 -52
  145. package/dist/cli/sessions.js.map +1 -1
  146. package/dist/config.d.ts +4 -28
  147. package/dist/config.d.ts.map +1 -1
  148. package/dist/config.js +7 -112
  149. package/dist/config.js.map +1 -1
  150. package/dist/dream/index.d.ts.map +1 -1
  151. package/dist/dream/index.js +8 -2
  152. package/dist/dream/index.js.map +1 -1
  153. package/dist/dream/types.d.ts +1 -1
  154. package/dist/dream/types.d.ts.map +1 -1
  155. package/dist/dream/types.js.map +1 -1
  156. package/dist/env-manifest.d.ts +2 -0
  157. package/dist/env-manifest.d.ts.map +1 -1
  158. package/dist/env-manifest.js +29 -8
  159. package/dist/env-manifest.js.map +1 -1
  160. package/dist/events/index.d.ts +150 -0
  161. package/dist/events/index.d.ts.map +1 -0
  162. package/dist/{harness/event-format.js → events/index.js} +80 -2
  163. package/dist/events/index.js.map +1 -0
  164. package/dist/{events.d.ts → events/watcher.d.ts} +4 -4
  165. package/dist/events/watcher.d.ts.map +1 -0
  166. package/dist/{events.js → events/watcher.js} +8 -8
  167. package/dist/events/watcher.js.map +1 -0
  168. package/dist/file-guards.d.ts.map +1 -0
  169. package/dist/file-guards.js.map +1 -0
  170. package/dist/harness/execution-env.d.ts +19 -0
  171. package/dist/harness/execution-env.d.ts.map +1 -0
  172. package/dist/harness/execution-env.js +262 -0
  173. package/dist/harness/execution-env.js.map +1 -0
  174. package/dist/harness/execution-resolver.d.ts +25 -0
  175. package/dist/harness/execution-resolver.d.ts.map +1 -0
  176. package/dist/{execution-resolver.js → harness/execution-resolver.js} +12 -21
  177. package/dist/harness/execution-resolver.js.map +1 -0
  178. package/dist/harness/index.d.ts +9 -9
  179. package/dist/harness/index.d.ts.map +1 -1
  180. package/dist/harness/index.js +8 -8
  181. package/dist/harness/index.js.map +1 -1
  182. package/dist/harness/mcp.d.ts +38 -0
  183. package/dist/harness/mcp.d.ts.map +1 -0
  184. package/dist/{mcp/loader.js → harness/mcp.js} +155 -6
  185. package/dist/harness/mcp.js.map +1 -0
  186. package/dist/harness/models.js +1 -1
  187. package/dist/harness/models.js.map +1 -1
  188. package/dist/harness/open-connector.d.ts.map +1 -0
  189. package/dist/{mcp → harness}/open-connector.js +1 -1
  190. package/dist/harness/open-connector.js.map +1 -0
  191. package/dist/{agent → harness}/presenter.d.ts +2 -9
  192. package/dist/harness/presenter.d.ts.map +1 -0
  193. package/dist/{agent → harness}/presenter.js +170 -146
  194. package/dist/harness/presenter.js.map +1 -0
  195. package/dist/{agent → harness}/prompt.d.ts +10 -3
  196. package/dist/harness/prompt.d.ts.map +1 -0
  197. package/dist/{agent → harness}/prompt.js +137 -41
  198. package/dist/harness/prompt.js.map +1 -0
  199. package/dist/harness/runner.d.ts +2 -109
  200. package/dist/harness/runner.d.ts.map +1 -1
  201. package/dist/harness/runner.js +499 -467
  202. package/dist/harness/runner.js.map +1 -1
  203. package/dist/harness/session.d.ts +119 -0
  204. package/dist/harness/session.d.ts.map +1 -0
  205. package/dist/harness/session.js +561 -0
  206. package/dist/harness/session.js.map +1 -0
  207. package/dist/harness/skills.d.ts +10 -2
  208. package/dist/harness/skills.d.ts.map +1 -1
  209. package/dist/harness/skills.js +62 -39
  210. package/dist/harness/skills.js.map +1 -1
  211. package/dist/harness/{subagent-runner.d.ts → subagent.d.ts} +25 -6
  212. package/dist/harness/subagent.d.ts.map +1 -0
  213. package/dist/harness/{subagent-runner.js → subagent.js} +106 -54
  214. package/dist/harness/subagent.js.map +1 -0
  215. package/dist/harness/tools/attach.d.ts.map +1 -0
  216. package/dist/harness/tools/attach.js.map +1 -0
  217. package/dist/{tools → harness/tools}/event.d.ts +3 -32
  218. package/dist/harness/tools/event.d.ts.map +1 -0
  219. package/dist/harness/tools/event.js +178 -0
  220. package/dist/harness/tools/event.js.map +1 -0
  221. package/dist/harness/tools/generate-image.d.ts.map +1 -0
  222. package/dist/harness/tools/generate-image.js.map +1 -0
  223. package/dist/harness/tools/host-fn-tool.d.ts.map +1 -0
  224. package/dist/harness/tools/host-fn-tool.js.map +1 -0
  225. package/dist/{tools → harness/tools}/index.d.ts +5 -6
  226. package/dist/harness/tools/index.d.ts.map +1 -0
  227. package/dist/{tools → harness/tools}/index.js +12 -16
  228. package/dist/harness/tools/index.js.map +1 -0
  229. package/dist/harness/tools/pi-tools.d.ts +18 -0
  230. package/dist/harness/tools/pi-tools.d.ts.map +1 -0
  231. package/dist/harness/tools/pi-tools.js +84 -0
  232. package/dist/harness/tools/pi-tools.js.map +1 -0
  233. package/dist/harness/tools/react.d.ts.map +1 -0
  234. package/dist/harness/tools/react.js.map +1 -0
  235. package/dist/{tools → harness/tools}/sandbox.d.ts +2 -2
  236. package/dist/harness/tools/sandbox.d.ts.map +1 -0
  237. package/dist/{tools → harness/tools}/sandbox.js +1 -1
  238. package/dist/harness/tools/sandbox.js.map +1 -0
  239. package/dist/{tools → harness/tools}/subagent.d.ts +28 -1
  240. package/dist/harness/tools/subagent.d.ts.map +1 -0
  241. package/dist/{tools → harness/tools}/subagent.js +218 -2
  242. package/dist/harness/tools/subagent.js.map +1 -0
  243. package/dist/{tools → harness/tools}/types.d.ts +0 -33
  244. package/dist/harness/tools/types.d.ts.map +1 -0
  245. package/dist/harness/tools/types.js.map +1 -0
  246. package/dist/harness/types.d.ts +180 -97
  247. package/dist/harness/types.d.ts.map +1 -1
  248. package/dist/harness/types.js +1 -1
  249. package/dist/harness/types.js.map +1 -1
  250. package/dist/index.d.ts +12 -11
  251. package/dist/index.d.ts.map +1 -1
  252. package/dist/index.js +6 -6
  253. package/dist/index.js.map +1 -1
  254. package/dist/main.js +10 -12
  255. package/dist/main.js.map +1 -1
  256. package/dist/observability/index.d.ts +33 -0
  257. package/dist/observability/index.d.ts.map +1 -0
  258. package/dist/observability/index.js +256 -0
  259. package/dist/observability/index.js.map +1 -0
  260. package/dist/observability/instrument.js +7 -1
  261. package/dist/observability/instrument.js.map +1 -1
  262. package/dist/observability/otel.d.ts +10 -0
  263. package/dist/observability/otel.d.ts.map +1 -0
  264. package/dist/observability/otel.js +183 -0
  265. package/dist/observability/otel.js.map +1 -0
  266. package/dist/observability/sentry.d.ts +22 -5
  267. package/dist/observability/sentry.d.ts.map +1 -1
  268. package/dist/observability/sentry.js +68 -23
  269. package/dist/observability/sentry.js.map +1 -1
  270. package/dist/observability/types.d.ts +6 -2
  271. package/dist/observability/types.d.ts.map +1 -1
  272. package/dist/observability/types.js.map +1 -1
  273. package/dist/office/index.d.ts +2 -3
  274. package/dist/office/index.d.ts.map +1 -1
  275. package/dist/office/index.js +172 -140
  276. package/dist/office/index.js.map +1 -1
  277. package/dist/{workspace-projection/index.d.ts → office/projection.d.ts} +2 -2
  278. package/dist/office/projection.d.ts.map +1 -0
  279. package/dist/{workspace-projection/index.js → office/projection.js} +2 -2
  280. package/dist/office/projection.js.map +1 -0
  281. package/dist/office/types.d.ts +29 -2
  282. package/dist/office/types.d.ts.map +1 -1
  283. package/dist/office/types.js.map +1 -1
  284. package/dist/process-lifecycle.d.ts +1 -1
  285. package/dist/process-lifecycle.d.ts.map +1 -1
  286. package/dist/process-lifecycle.js +3 -3
  287. package/dist/process-lifecycle.js.map +1 -1
  288. package/dist/runtime/conversation-runtime.d.ts.map +1 -1
  289. package/dist/runtime/conversation-runtime.js +106 -107
  290. package/dist/runtime/conversation-runtime.js.map +1 -1
  291. package/dist/runtime/session-lifecycle.d.ts +10 -0
  292. package/dist/runtime/session-lifecycle.d.ts.map +1 -1
  293. package/dist/runtime/session-lifecycle.js +42 -24
  294. package/dist/runtime/session-lifecycle.js.map +1 -1
  295. package/dist/runtime/types.d.ts +3 -3
  296. package/dist/runtime/types.d.ts.map +1 -1
  297. package/dist/runtime/types.js.map +1 -1
  298. package/dist/sandbox/cloudflare.d.ts +1 -0
  299. package/dist/sandbox/cloudflare.d.ts.map +1 -1
  300. package/dist/sandbox/cloudflare.js +41 -50
  301. package/dist/sandbox/cloudflare.js.map +1 -1
  302. package/dist/sandbox/container.d.ts.map +1 -1
  303. package/dist/sandbox/container.js +7 -4
  304. package/dist/sandbox/container.js.map +1 -1
  305. package/dist/sandbox/host.d.ts.map +1 -1
  306. package/dist/sandbox/host.js +27 -35
  307. package/dist/sandbox/host.js.map +1 -1
  308. package/dist/sandbox/index.d.ts.map +1 -1
  309. package/dist/sandbox/index.js +8 -15
  310. package/dist/sandbox/index.js.map +1 -1
  311. package/dist/{provisioner.d.ts → sandbox/provisioner.d.ts} +2 -2
  312. package/dist/sandbox/provisioner.d.ts.map +1 -0
  313. package/dist/{provisioner.js → sandbox/provisioner.js} +3 -3
  314. package/dist/sandbox/provisioner.js.map +1 -0
  315. package/dist/sandbox/types.d.ts +2 -0
  316. package/dist/sandbox/types.d.ts.map +1 -1
  317. package/dist/sandbox/types.js.map +1 -1
  318. package/dist/sandbox/utils.d.ts +5 -0
  319. package/dist/sandbox/utils.d.ts.map +1 -1
  320. package/dist/sandbox/utils.js +14 -0
  321. package/dist/sandbox/utils.js.map +1 -1
  322. package/dist/sessions/chat-history-sync.d.ts.map +1 -1
  323. package/dist/sessions/chat-history-sync.js +72 -62
  324. package/dist/sessions/chat-history-sync.js.map +1 -1
  325. package/dist/sessions/migrate-common.d.ts +43 -0
  326. package/dist/sessions/migrate-common.d.ts.map +1 -0
  327. package/dist/sessions/migrate-common.js +99 -0
  328. package/dist/sessions/migrate-common.js.map +1 -0
  329. package/dist/sessions/migrate-pi-084.d.ts.map +1 -1
  330. package/dist/sessions/migrate-pi-084.js +152 -203
  331. package/dist/sessions/migrate-pi-084.js.map +1 -1
  332. package/dist/sessions/migrate-v3.d.ts +5 -0
  333. package/dist/sessions/migrate-v3.d.ts.map +1 -1
  334. package/dist/sessions/migrate-v3.js +161 -209
  335. package/dist/sessions/migrate-v3.js.map +1 -1
  336. package/dist/{harness → sessions}/session-store.d.ts +12 -1
  337. package/dist/sessions/session-store.d.ts.map +1 -0
  338. package/dist/{harness → sessions}/session-store.js +74 -35
  339. package/dist/sessions/session-store.js.map +1 -0
  340. package/dist/sessions/store.d.ts +1 -1
  341. package/dist/sessions/store.d.ts.map +1 -1
  342. package/dist/sessions/store.js +18 -17
  343. package/dist/sessions/store.js.map +1 -1
  344. package/dist/sessions/types.d.ts +40 -1
  345. package/dist/sessions/types.d.ts.map +1 -1
  346. package/dist/sessions/types.js +1 -1
  347. package/dist/sessions/types.js.map +1 -1
  348. package/dist/types.d.ts +7 -99
  349. package/dist/types.d.ts.map +1 -1
  350. package/dist/types.js.map +1 -1
  351. package/dist/vault/index.d.ts.map +1 -1
  352. package/dist/vault/index.js +70 -53
  353. package/dist/vault/index.js.map +1 -1
  354. package/package.json +10 -4
  355. package/dist/adapters/slack/tools/attach.d.ts.map +0 -1
  356. package/dist/adapters/slack/tools/attach.js.map +0 -1
  357. package/dist/agent/catalog.d.ts +0 -22
  358. package/dist/agent/catalog.d.ts.map +0 -1
  359. package/dist/agent/catalog.js +0 -104
  360. package/dist/agent/catalog.js.map +0 -1
  361. package/dist/agent/execution.d.ts +0 -25
  362. package/dist/agent/execution.d.ts.map +0 -1
  363. package/dist/agent/execution.js +0 -171
  364. package/dist/agent/execution.js.map +0 -1
  365. package/dist/agent/presenter.d.ts.map +0 -1
  366. package/dist/agent/presenter.js.map +0 -1
  367. package/dist/agent/prompt.d.ts.map +0 -1
  368. package/dist/agent/prompt.js.map +0 -1
  369. package/dist/agent/runner.d.ts +0 -3
  370. package/dist/agent/runner.d.ts.map +0 -1
  371. package/dist/agent/runner.js +0 -452
  372. package/dist/agent/runner.js.map +0 -1
  373. package/dist/agent/types.d.ts +0 -101
  374. package/dist/agent/types.d.ts.map +0 -1
  375. package/dist/agent/types.js +0 -3
  376. package/dist/agent/types.js.map +0 -1
  377. package/dist/agent-events.d.ts +0 -6
  378. package/dist/agent-events.d.ts.map +0 -1
  379. package/dist/agent-events.js +0 -44
  380. package/dist/agent-events.js.map +0 -1
  381. package/dist/commands/admin.d.ts.map +0 -1
  382. package/dist/commands/admin.js.map +0 -1
  383. package/dist/commands/auto-reply.d.ts +0 -8
  384. package/dist/commands/auto-reply.d.ts.map +0 -1
  385. package/dist/commands/auto-reply.js +0 -65
  386. package/dist/commands/auto-reply.js.map +0 -1
  387. package/dist/commands/login.d.ts.map +0 -1
  388. package/dist/commands/login.js +0 -158
  389. package/dist/commands/login.js.map +0 -1
  390. package/dist/commands/manifest.d.ts.map +0 -1
  391. package/dist/commands/manifest.js.map +0 -1
  392. package/dist/commands/model.d.ts.map +0 -1
  393. package/dist/commands/model.js.map +0 -1
  394. package/dist/commands/new.d.ts.map +0 -1
  395. package/dist/commands/new.js.map +0 -1
  396. package/dist/commands/registry.d.ts.map +0 -1
  397. package/dist/commands/registry.js.map +0 -1
  398. package/dist/commands/sandbox.d.ts.map +0 -1
  399. package/dist/commands/sandbox.js.map +0 -1
  400. package/dist/commands/session-view.d.ts.map +0 -1
  401. package/dist/commands/session-view.js.map +0 -1
  402. package/dist/commands/types.d.ts.map +0 -1
  403. package/dist/commands/types.js.map +0 -1
  404. package/dist/commands/utils.d.ts +0 -11
  405. package/dist/commands/utils.d.ts.map +0 -1
  406. package/dist/commands/utils.js.map +0 -1
  407. package/dist/events.d.ts.map +0 -1
  408. package/dist/events.js.map +0 -1
  409. package/dist/execution-resolver.d.ts +0 -27
  410. package/dist/execution-resolver.d.ts.map +0 -1
  411. package/dist/execution-resolver.js.map +0 -1
  412. package/dist/harness/event-format.d.ts +0 -33
  413. package/dist/harness/event-format.d.ts.map +0 -1
  414. package/dist/harness/event-format.js.map +0 -1
  415. package/dist/harness/session-store.d.ts.map +0 -1
  416. package/dist/harness/session-store.js.map +0 -1
  417. package/dist/harness/settings.d.ts +0 -29
  418. package/dist/harness/settings.d.ts.map +0 -1
  419. package/dist/harness/settings.js +0 -40
  420. package/dist/harness/settings.js.map +0 -1
  421. package/dist/harness/subagent-runner.d.ts.map +0 -1
  422. package/dist/harness/subagent-runner.js.map +0 -1
  423. package/dist/harness/subagent-slots.d.ts +0 -28
  424. package/dist/harness/subagent-slots.d.ts.map +0 -1
  425. package/dist/harness/subagent-slots.js +0 -72
  426. package/dist/harness/subagent-slots.js.map +0 -1
  427. package/dist/harness/usage.d.ts +0 -11
  428. package/dist/harness/usage.d.ts.map +0 -1
  429. package/dist/harness/usage.js +0 -38
  430. package/dist/harness/usage.js.map +0 -1
  431. package/dist/mcp/catalog.d.ts +0 -5
  432. package/dist/mcp/catalog.d.ts.map +0 -1
  433. package/dist/mcp/catalog.js +0 -68
  434. package/dist/mcp/catalog.js.map +0 -1
  435. package/dist/mcp/loader.d.ts +0 -12
  436. package/dist/mcp/loader.d.ts.map +0 -1
  437. package/dist/mcp/loader.js.map +0 -1
  438. package/dist/mcp/open-connector.d.ts.map +0 -1
  439. package/dist/mcp/open-connector.js.map +0 -1
  440. package/dist/mcp/types.d.ts +0 -66
  441. package/dist/mcp/types.d.ts.map +0 -1
  442. package/dist/mcp/types.js.map +0 -1
  443. package/dist/packages/index.d.ts +0 -169
  444. package/dist/packages/index.d.ts.map +0 -1
  445. package/dist/packages/index.js +0 -721
  446. package/dist/packages/index.js.map +0 -1
  447. package/dist/packages/types.d.ts +0 -100
  448. package/dist/packages/types.d.ts.map +0 -1
  449. package/dist/packages/types.js.map +0 -1
  450. package/dist/provisioner.d.ts.map +0 -1
  451. package/dist/provisioner.js.map +0 -1
  452. package/dist/subagent-progress.d.ts +0 -39
  453. package/dist/subagent-progress.d.ts.map +0 -1
  454. package/dist/subagent-progress.js +0 -225
  455. package/dist/subagent-progress.js.map +0 -1
  456. package/dist/tools/bash.d.ts +0 -12
  457. package/dist/tools/bash.d.ts.map +0 -1
  458. package/dist/tools/bash.js +0 -80
  459. package/dist/tools/bash.js.map +0 -1
  460. package/dist/tools/edit.d.ts +0 -11
  461. package/dist/tools/edit.d.ts.map +0 -1
  462. package/dist/tools/edit.js +0 -132
  463. package/dist/tools/edit.js.map +0 -1
  464. package/dist/tools/event.d.ts.map +0 -1
  465. package/dist/tools/event.js +0 -255
  466. package/dist/tools/event.js.map +0 -1
  467. package/dist/tools/generate-image.d.ts.map +0 -1
  468. package/dist/tools/generate-image.js.map +0 -1
  469. package/dist/tools/host-fn-tool.d.ts.map +0 -1
  470. package/dist/tools/host-fn-tool.js.map +0 -1
  471. package/dist/tools/index.d.ts.map +0 -1
  472. package/dist/tools/index.js.map +0 -1
  473. package/dist/tools/react.d.ts.map +0 -1
  474. package/dist/tools/react.js.map +0 -1
  475. package/dist/tools/read.d.ts +0 -12
  476. package/dist/tools/read.d.ts.map +0 -1
  477. package/dist/tools/read.js +0 -140
  478. package/dist/tools/read.js.map +0 -1
  479. package/dist/tools/sandbox.d.ts.map +0 -1
  480. package/dist/tools/sandbox.js.map +0 -1
  481. package/dist/tools/subagent.d.ts.map +0 -1
  482. package/dist/tools/subagent.js.map +0 -1
  483. package/dist/tools/types.d.ts.map +0 -1
  484. package/dist/tools/types.js.map +0 -1
  485. package/dist/tools/write.d.ts +0 -10
  486. package/dist/tools/write.d.ts.map +0 -1
  487. package/dist/tools/write.js +0 -23
  488. package/dist/tools/write.js.map +0 -1
  489. package/dist/trigger.d.ts +0 -23
  490. package/dist/trigger.d.ts.map +0 -1
  491. package/dist/trigger.js +0 -97
  492. package/dist/trigger.js.map +0 -1
  493. package/dist/utils/file-guards.d.ts.map +0 -1
  494. package/dist/utils/file-guards.js.map +0 -1
  495. package/dist/web/admin/portal.d.ts.map +0 -1
  496. package/dist/web/admin/portal.js.map +0 -1
  497. package/dist/web/admin/provider-models.d.ts.map +0 -1
  498. package/dist/web/admin/provider-models.js.map +0 -1
  499. package/dist/web/admin/types.d.ts.map +0 -1
  500. package/dist/web/admin/types.js.map +0 -1
  501. package/dist/web/login/oauth.d.ts.map +0 -1
  502. package/dist/web/login/oauth.js.map +0 -1
  503. package/dist/web/login/portal.d.ts.map +0 -1
  504. package/dist/web/login/portal.js.map +0 -1
  505. package/dist/web/login/types.d.ts.map +0 -1
  506. package/dist/web/login/types.js.map +0 -1
  507. package/dist/web/portal-shell.d.ts.map +0 -1
  508. package/dist/web/portal-shell.js.map +0 -1
  509. package/dist/web/server.d.ts.map +0 -1
  510. package/dist/web/server.js.map +0 -1
  511. package/dist/web/session-view/portal.d.ts.map +0 -1
  512. package/dist/web/session-view/portal.js.map +0 -1
  513. package/dist/web/session-view/types.d.ts.map +0 -1
  514. package/dist/web/session-view/types.js +0 -2
  515. package/dist/web/session-view/types.js.map +0 -1
  516. package/dist/web/token-store.d.ts.map +0 -1
  517. package/dist/web/token-store.js.map +0 -1
  518. package/dist/web/types.d.ts.map +0 -1
  519. package/dist/web/types.js +0 -2
  520. package/dist/web/types.js.map +0 -1
  521. package/dist/workspace-projection/index.d.ts.map +0 -1
  522. package/dist/workspace-projection/index.js.map +0 -1
  523. package/dist/workspace-projection/types.d.ts +0 -29
  524. package/dist/workspace-projection/types.d.ts.map +0 -1
  525. package/dist/workspace-projection/types.js +0 -2
  526. package/dist/workspace-projection/types.js.map +0 -1
  527. /package/dist/{commands → adapters/commands}/admin.d.ts +0 -0
  528. /package/dist/{commands → adapters/commands}/login.d.ts +0 -0
  529. /package/dist/{commands → adapters/commands}/manifest.d.ts +0 -0
  530. /package/dist/{commands → adapters/commands}/new.d.ts +0 -0
  531. /package/dist/{commands → adapters/commands}/registry.d.ts +0 -0
  532. /package/dist/{commands → adapters/commands}/sandbox.d.ts +0 -0
  533. /package/dist/{commands → adapters/commands}/session-view.d.ts +0 -0
  534. /package/dist/{commands → adapters/commands}/types.js +0 -0
  535. /package/dist/{web → adapters/web}/admin/provider-models.js +0 -0
  536. /package/dist/{mcp → adapters/web/admin}/types.js +0 -0
  537. /package/dist/{web → adapters/web}/login/oauth.d.ts +0 -0
  538. /package/dist/{packages → adapters/web/login}/types.js +0 -0
  539. /package/dist/{web → adapters/web}/session-view/portal.d.ts +0 -0
  540. /package/dist/{tools → adapters/web/session-view}/types.js +0 -0
  541. /package/dist/{web → adapters/web}/token-store.d.ts +0 -0
  542. /package/dist/{web → adapters/web}/token-store.js +0 -0
  543. /package/dist/{web → adapters/web}/types.d.ts +0 -0
  544. /package/dist/{web/admin → adapters/web}/types.js +0 -0
  545. /package/dist/{utils/file-guards.d.ts → file-guards.d.ts} +0 -0
  546. /package/dist/{utils/file-guards.js → file-guards.js} +0 -0
  547. /package/dist/{mcp → harness}/open-connector.d.ts +0 -0
  548. /package/dist/{adapters/slack → harness}/tools/attach.d.ts +0 -0
  549. /package/dist/{adapters/slack → harness}/tools/attach.js +0 -0
  550. /package/dist/{tools → harness/tools}/generate-image.d.ts +0 -0
  551. /package/dist/{tools → harness/tools}/generate-image.js +0 -0
  552. /package/dist/{tools → harness/tools}/host-fn-tool.d.ts +0 -0
  553. /package/dist/{tools → harness/tools}/host-fn-tool.js +0 -0
  554. /package/dist/{tools → harness/tools}/react.d.ts +0 -0
  555. /package/dist/{tools → harness/tools}/react.js +0 -0
  556. /package/dist/{web/login → harness/tools}/types.js +0 -0
@@ -1,721 +0,0 @@
1
- /**
2
- * The packages module in one file: the package source grammar, git/local
3
- * materialization, inspection, conversation-scope resolution with skill
4
- * mounts, and the admin add/refresh/remove operations. Exported types live
5
- * in `types.ts`.
6
- */
7
- import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
8
- import { execFileSync } from "node:child_process";
9
- import { createHash } from "node:crypto";
10
- import { cpSync, existsSync, lstatSync, realpathSync, rmSync, statSync, writeFileSync, } from "node:fs";
11
- import { ensureDirExists, readTextFileIfExists } from "../utils/file-guards.js";
12
- import * as log from "../log.js";
13
- import { officeStateDir } from "../office/index.js";
14
- import { loadSkillsFromDir } from "../harness/index.js";
15
- import { loadGlobalSettings, resolveConversationSettings } from "../config.js";
16
- import { applyConversationSettings, applyGlobalSettings } from "../settings-mutation.js";
17
- // ── Package source grammar ────────────────────────────────────────────────────
18
- /**
19
- * The package source grammar: one place that turns a human-written source
20
- * string into a {@link ParsedSource}, and one place that decides when two
21
- * sources are the same package ({@link sourceIdentity}).
22
- *
23
- * Only git and local-path sources are implemented. The tagged union and the
24
- * identity function are the seams a future `npm:` source slots into: adding it
25
- * means a new arm here and a new materializer, with nothing downstream —
26
- * resolution, scope precedence, the portal — needing to know.
27
- *
28
- * Grammar:
29
- *
30
- * <locator>[@<ref>][#<subpath>]
31
- *
32
- * locator: https://… http://… ssh://… git://… file://…
33
- * git@host:owner/repo
34
- * git:<any of the above, or host/owner/repo shorthand>
35
- * github:owner/repo
36
- * /abs/path ./rel/path (local, used by reference)
37
- *
38
- * `@<ref>` is recognized only when what follows the last `@` contains no `/`
39
- * and no `:` — otherwise the `@` belongs to the URL's authority
40
- * (`git@github.com:…`). A consequence: refs containing a slash
41
- * (`release/1.0`) cannot be written in the string form; pin to a tag or a
42
- * commit sha instead. The admin portal takes the URL and the ref as separate
43
- * inputs and assembles a canonical string, so this only constrains
44
- * hand-edited settings.
45
- */
46
- const PROTOCOL_PREFIXES = ["https://", "http://", "ssh://", "git://", "file://"];
47
- const SCP_LIKE = /^[^@/\s]+@[^:/\s]+:/;
48
- /**
49
- * Parse a source string. Throws with a user-facing message rather than
50
- * returning undefined: every caller (portal, settings load, CLI) needs to tell
51
- * the human what was wrong with what they typed.
52
- */
53
- export function parseSource(source) {
54
- const trimmed = source.trim();
55
- if (!trimmed)
56
- throw new Error("Package source is empty");
57
- const { rest: withoutSubpath, subpath } = splitSubpath(trimmed);
58
- const { rest: locator, ref } = splitRef(withoutSubpath);
59
- if (locator.startsWith("github:")) {
60
- const repo = stripGitSuffix(locator.slice("github:".length).replace(/^\/+/, ""));
61
- if (!repo.includes("/")) {
62
- throw new Error(`github: source must be owner/repo, got ${JSON.stringify(locator)}`);
63
- }
64
- return gitSource(`https://github.com/${repo}.git`, ref, subpath);
65
- }
66
- if (locator.startsWith("git:")) {
67
- const inner = locator.slice("git:".length);
68
- if (isProtocolUrl(inner) || SCP_LIKE.test(inner))
69
- return gitSource(inner, ref, subpath);
70
- // Shorthand: host/owner/repo — only meaningful with the git: prefix,
71
- // since bare host/owner/repo is ambiguous with a relative path.
72
- if (!inner.includes("/")) {
73
- throw new Error(`git: source must include a path, got ${JSON.stringify(locator)}`);
74
- }
75
- return gitSource(`https://${stripGitSuffix(inner)}.git`, ref, subpath);
76
- }
77
- if (isProtocolUrl(locator) || SCP_LIKE.test(locator))
78
- return gitSource(locator, ref, subpath);
79
- if (isAbsolute(locator) || locator.startsWith("./") || locator.startsWith("../")) {
80
- if (ref)
81
- throw new Error("A local path source cannot carry an @ref");
82
- if (subpath)
83
- throw new Error("A local path source cannot carry a #subpath");
84
- return { type: "local", path: resolve(locator) };
85
- }
86
- throw new Error(`Unrecognized package source ${JSON.stringify(source)}. ` +
87
- "Use a git URL, github:owner/repo, git:host/owner/repo, or an absolute/relative path.");
88
- }
89
- function gitSource(url, ref, subpath) {
90
- return { type: "git", url, ...(ref ? { ref } : {}), ...(subpath ? { subpath } : {}) };
91
- }
92
- function isProtocolUrl(value) {
93
- return PROTOCOL_PREFIXES.some((prefix) => value.startsWith(prefix));
94
- }
95
- function stripGitSuffix(value) {
96
- return value.replace(/\.git$/, "").replace(/\/+$/, "");
97
- }
98
- function splitSubpath(source) {
99
- const hash = source.indexOf("#");
100
- if (hash === -1)
101
- return { rest: source };
102
- const subpath = source.slice(hash + 1).trim();
103
- if (!subpath)
104
- return { rest: source.slice(0, hash) };
105
- assertSafeRelativePath(subpath, "#subpath");
106
- return { rest: source.slice(0, hash), subpath };
107
- }
108
- /**
109
- * Split a trailing `@ref`. The `@` in `git@github.com:owner/repo` is part of
110
- * the authority, not a ref, so a candidate only counts when its suffix looks
111
- * like a bare ref (no `/`, no `:`).
112
- */
113
- function splitRef(source) {
114
- const at = source.lastIndexOf("@");
115
- if (at <= 0)
116
- return { rest: source };
117
- const candidate = source.slice(at + 1);
118
- if (!candidate || candidate.includes("/") || candidate.includes(":"))
119
- return { rest: source };
120
- return { rest: source.slice(0, at), ref: candidate };
121
- }
122
- /** Reject traversal and absolute escapes in the parts that become paths. */
123
- function assertSafeRelativePath(value, label) {
124
- if (isAbsolute(value) || value.split(/[\\/]/).some((segment) => segment === "..")) {
125
- throw new Error(`${label} must be a relative path without '..': ${JSON.stringify(value)}`);
126
- }
127
- }
128
- /**
129
- * Identity of the package a source refers to — the key for deduplication and
130
- * for letting a conversation's copy shadow the global one.
131
- *
132
- * Deliberate choices:
133
- * - The ref is excluded: the same repo pinned to two refs in two scopes is one
134
- * package installed twice, and the narrower scope wins.
135
- * - The subpath is included: two skill packages living at different paths in one
136
- * monorepo are two packages.
137
- * - Transport is excluded: `git@github.com:o/r`, `https://github.com/o/r.git`
138
- * and `ssh://git@github.com/o/r` all identify the same package, so mixing
139
- * SSH and HTTPS spellings across scopes still dedups.
140
- */
141
- export function sourceIdentity(parsed) {
142
- if (parsed.type === "local")
143
- return `local:${parsed.path}`;
144
- const repo = gitRepoPath(parsed.url);
145
- return parsed.subpath ? `git:${repo}#${parsed.subpath}` : `git:${repo}`;
146
- }
147
- /**
148
- * Transport-independent `<host>/<path>` of a git URL, lowercased host, no
149
- * `.git` suffix, no credentials. It is the base of the on-disk clone layout,
150
- * so it must stay free of anything that is not a safe path segment.
151
- */
152
- export function gitRepoPath(url) {
153
- let remainder = url;
154
- for (const prefix of PROTOCOL_PREFIXES) {
155
- if (remainder.startsWith(prefix)) {
156
- remainder = remainder.slice(prefix.length);
157
- break;
158
- }
159
- }
160
- // Drop any credentials in the authority (`user:pass@host`, `git@host`).
161
- const scpMatch = /^([^@/\s]+@)?([^:/\s]+)[:/](.+)$/.exec(remainder);
162
- if (!scpMatch)
163
- return sanitizeRepoPath(stripGitSuffix(remainder));
164
- const host = (scpMatch[2] ?? "").toLowerCase();
165
- const path = stripGitSuffix((scpMatch[3] ?? "").replace(/^\/+/, ""));
166
- return sanitizeRepoPath(`${host}/${path}`);
167
- }
168
- /**
169
- * `file://` URLs used in tests and local mirrors have no host, so the repo path
170
- * is an absolute filesystem path. Keep every segment filesystem-safe and drop
171
- * traversal, since this string becomes a directory under the state dir.
172
- */
173
- function sanitizeRepoPath(value) {
174
- const segments = value
175
- .split(/[\\/]/)
176
- .map((segment) => segment.replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^\.+$/, ""))
177
- .filter((segment) => segment.length > 0);
178
- if (segments.length === 0)
179
- throw new Error(`Cannot derive a package path from ${value}`);
180
- return segments.join("/");
181
- }
182
- /**
183
- * Canonical string form, used when writing settings so the stored value is
184
- * stable regardless of how the human spelled it.
185
- */
186
- export function formatSource(parsed) {
187
- if (parsed.type === "local")
188
- return parsed.path;
189
- const ref = parsed.ref ? `@${parsed.ref}` : "";
190
- const subpath = parsed.subpath ? `#${parsed.subpath}` : "";
191
- return `${parsed.url}${ref}${subpath}`;
192
- }
193
- /** Git operations get a bounded wall clock so a hung remote cannot wedge a save. */
194
- const GIT_TIMEOUT_MS = 120_000;
195
- const MATERIALIZED_REF_FILE = "mikan-ref";
196
- /**
197
- * How far materialization may go to produce the package's files.
198
- *
199
- * - `offline`: use what is already on disk; never touch the network. This is
200
- * what a conversation load uses, so no chat reply can ever wait on a remote.
201
- * - `fetch`: clone a package that is not on disk yet, reuse an existing clone
202
- * when it already has the requested ref, or switch it to a new ref. What the
203
- * portal uses when a source is added.
204
- * - `refresh`: additionally re-fetch an existing clone, resetting and cleaning
205
- * it first. What the portal's Update action uses.
206
- *
207
- * One mode rather than two booleans: "re-fetch an existing clone but refuse to
208
- * create a missing one" is not a state any caller wants, and expressing it
209
- * should not be possible.
210
- */
211
- /**
212
- * Root of a scope's host-only assets: `<stateDir>/global` or
213
- * `<stateDir>/conversations/<id>`. The two are isomorphic by design — both
214
- * hold conversation-scoped settings and package checkouts.
215
- */
216
- export function packageScopeDir(scope, address, stateDir) {
217
- if (scope === "global")
218
- return join(stateDir, "global");
219
- if (!address)
220
- throw new Error("A conversation-scoped package needs an office address");
221
- return officeStateDir(stateDir, address);
222
- }
223
- /**
224
- * Where a git checkout lives.
225
- *
226
- * The unpinned checkout keeps the original path for compatibility. Explicit
227
- * refs get a sibling keyed by the ref, so two refs can never reset each
228
- * other's working tree; subpaths of one ref therefore still share a checkout.
229
- */
230
- export function gitCloneDir(url, scopeDir, ref) {
231
- const repoPath = gitRepoPath(url).split("/");
232
- const repoName = repoPath[repoPath.length - 1] ?? "repo";
233
- const parent = repoPath.slice(0, -1);
234
- const checkoutName = ref === undefined || ref === "HEAD"
235
- ? repoName
236
- : `${repoName}.mikan-${createHash("sha256").update(ref).digest("hex")}`;
237
- return join(scopeDir, "git", ...parent, checkoutName);
238
- }
239
- /**
240
- * Materialize one source and return where its files ended up. Throws with a
241
- * message meant to be shown to a human — callers render it next to the input
242
- * that produced it.
243
- */
244
- export function materializeSource(source, options) {
245
- const parsed = parseSource(source);
246
- const scopeDir = packageScopeDir(options.scope, options.address, options.stateDir);
247
- const dir = parsed.type === "local"
248
- ? materializeLocal(parsed)
249
- : materializeGit(parsed, scopeDir, options.mode ?? "fetch");
250
- return {
251
- source,
252
- parsed,
253
- identity: sourceIdentity(parsed),
254
- dir,
255
- scope: options.scope,
256
- };
257
- }
258
- function materializeLocal(parsed) {
259
- if (!existsSync(parsed.path)) {
260
- throw new Error(`Path does not exist on the mikan host: ${parsed.path}`);
261
- }
262
- if (!statSync(parsed.path).isDirectory()) {
263
- throw new Error(`Package path must be a directory: ${parsed.path}`);
264
- }
265
- return parsed.path;
266
- }
267
- function materializeGit(parsed, scopeDir, mode) {
268
- const requestedRef = parsed.ref ?? "HEAD";
269
- const cloneDir = gitCloneDir(parsed.url, scopeDir, requestedRef);
270
- migrateLegacyCheckout(parsed.url, scopeDir, cloneDir, requestedRef);
271
- const alreadyCloned = existsSync(join(cloneDir, ".git"));
272
- const markerPath = join(cloneDir, ".git", MATERIALIZED_REF_FILE);
273
- const recordedRef = alreadyCloned ? readTextFileIfExists(markerPath)?.trim() : undefined;
274
- const canReuse = alreadyCloned &&
275
- mode !== "refresh" &&
276
- (recordedRef === requestedRef ||
277
- (mode === "offline" &&
278
- recordedRef === undefined &&
279
- markerlessCheckoutMatchesRef(cloneDir, requestedRef)));
280
- if (canReuse) {
281
- return resolveSubpath(cloneDir, parsed);
282
- }
283
- if (mode === "offline") {
284
- throw new Error(`Not fetched on this host yet: ${describeRef(parsed)}`);
285
- }
286
- // An incomplete checkout must not retain a marker from an earlier attempt:
287
- // otherwise a retry could mistake an interrupted fetch or checkout for success.
288
- if (alreadyCloned)
289
- rmSync(markerPath, { force: true });
290
- if (!alreadyCloned) {
291
- // A leftover directory without .git means a previous attempt died partway.
292
- if (existsSync(cloneDir))
293
- rmSync(cloneDir, { recursive: true, force: true });
294
- ensureDirExists(cloneDir);
295
- git(cloneDir, ["init", "-q"]);
296
- git(cloneDir, ["remote", "add", "origin", parsed.url]);
297
- }
298
- else {
299
- // Reconcile: drop anything a previous checkout left behind so the new ref
300
- // lands on a clean tree.
301
- git(cloneDir, ["remote", "set-url", "origin", parsed.url]);
302
- git(cloneDir, ["reset", "--hard", "-q"]);
303
- git(cloneDir, ["clean", "-qfd"]);
304
- }
305
- // One fetch shape for every kind of ref — tag, branch, or commit sha — and
306
- // `HEAD` for "whatever the remote's default branch is now".
307
- try {
308
- git(cloneDir, ["fetch", "--depth", "1", "origin", requestedRef]);
309
- }
310
- catch (err) {
311
- if (!alreadyCloned)
312
- rmSync(cloneDir, { recursive: true, force: true });
313
- throw new Error(`Could not fetch ${describeRef(parsed)}: ${gitErrorText(err)}`, { cause: err });
314
- }
315
- git(cloneDir, ["checkout", "-q", "--detach", "FETCH_HEAD"]);
316
- const dir = resolveSubpath(cloneDir, parsed);
317
- // This is the completion marker, not merely a fetched-ref marker. Write it
318
- // only after checkout and subpath validation have both succeeded.
319
- writeFileSync(markerPath, `${requestedRef}\n`);
320
- return dir;
321
- }
322
- /**
323
- * Before keyed checkout paths existed, every ref used the legacy repo path.
324
- * Copy a matching complete checkout on first use of its keyed path so offline
325
- * loads keep working. Markerless legacy checkouts are accepted only when git
326
- * can prove the requested ref is the checked-out commit; a different or
327
- * unprovable pinned ref is rebuilt by fetch/refresh instead.
328
- */
329
- function migrateLegacyCheckout(url, scopeDir, cloneDir, requestedRef) {
330
- const legacyDir = gitCloneDir(url, scopeDir);
331
- if (cloneDir === legacyDir || existsSync(cloneDir))
332
- return;
333
- const legacyMarker = join(legacyDir, ".git", MATERIALIZED_REF_FILE);
334
- if (!existsSync(join(legacyDir, ".git")))
335
- return;
336
- const recordedRef = readTextFileIfExists(legacyMarker)?.trim();
337
- if (recordedRef !== requestedRef) {
338
- if (recordedRef !== undefined || !markerlessCheckoutMatchesRef(legacyDir, requestedRef)) {
339
- return;
340
- }
341
- }
342
- ensureDirExists(dirname(cloneDir));
343
- cpSync(legacyDir, cloneDir, { recursive: true });
344
- }
345
- /**
346
- * Legacy checkouts have no completion marker. Accept them offline only when
347
- * the checkout is clean and the local git metadata identifies the requested
348
- * commit/ref; never infer a pinned ref from HEAD alone.
349
- */
350
- function markerlessCheckoutMatchesRef(cloneDir, requestedRef) {
351
- let head;
352
- try {
353
- head = git(cloneDir, ["rev-parse", "--verify", "HEAD"]).trim();
354
- if (!head || git(cloneDir, ["status", "--porcelain", "--untracked-files=no"]).trim()) {
355
- return false;
356
- }
357
- }
358
- catch {
359
- return false;
360
- }
361
- if (requestedRef === "HEAD")
362
- return true;
363
- try {
364
- if (git(cloneDir, ["rev-parse", "--verify", `${requestedRef}^{commit}`]).trim() === head) {
365
- return true;
366
- }
367
- }
368
- catch {
369
- // A shallow legacy fetch may retain only FETCH_HEAD, not a local ref.
370
- }
371
- try {
372
- if (git(cloneDir, ["symbolic-ref", "--quiet", "--short", "HEAD"]).trim() === requestedRef) {
373
- return true;
374
- }
375
- }
376
- catch {
377
- // Detached checkouts do not have a symbolic branch.
378
- }
379
- const fetchHead = readTextFileIfExists(join(cloneDir, ".git", "FETCH_HEAD"));
380
- if (!fetchHead)
381
- return false;
382
- return fetchHead.split("\n").some((line) => {
383
- const match = /^(\w+)\s+.*(?:branch|tag) '([^']+)'/.exec(line);
384
- return match?.[1] === head && match[2] === requestedRef;
385
- });
386
- }
387
- function resolveSubpath(cloneDir, parsed) {
388
- if (!parsed.subpath)
389
- return cloneDir;
390
- const dir = join(cloneDir, parsed.subpath);
391
- if (!existsSync(dir)) {
392
- throw new Error(`Subpath not found in repository: ${parsed.subpath}`);
393
- }
394
- // A symlink inside the repository must not select files outside the clone:
395
- // the returned directory is mounted into the runtime, so follow
396
- // links before deciding the subpath stayed inside.
397
- const relation = relative(realpathSync(cloneDir), realpathSync(dir));
398
- if (isAbsolute(relation) || relation === ".." || relation.startsWith(`..${sep}`)) {
399
- throw new Error(`Subpath escapes repository: ${parsed.subpath}`);
400
- }
401
- return dir;
402
- }
403
- function git(cwd, args) {
404
- return execFileSync("git", args, {
405
- cwd,
406
- timeout: GIT_TIMEOUT_MS,
407
- encoding: "utf-8",
408
- stdio: ["ignore", "pipe", "pipe"],
409
- env: {
410
- ...process.env,
411
- // Never block a portal save on an interactive credential prompt.
412
- GIT_TERMINAL_PROMPT: "0",
413
- GIT_SSH_COMMAND: process.env.GIT_SSH_COMMAND ?? "ssh -o BatchMode=yes -o ConnectTimeout=10",
414
- },
415
- });
416
- }
417
- function describeRef(parsed) {
418
- return parsed.ref ? `${parsed.url} at ${parsed.ref}` : parsed.url;
419
- }
420
- /** Prefer git's stderr over the generic "Command failed" wrapper. */
421
- function gitErrorText(err) {
422
- if (err && typeof err === "object" && "stderr" in err) {
423
- const stderr = err.stderr;
424
- const text = typeof stderr === "string" ? stderr.trim() : "";
425
- if (text)
426
- return text.split("\n").slice(-3).join(" ");
427
- }
428
- return err instanceof Error ? err.message : String(err);
429
- }
430
- /**
431
- * Inventory both scopes for one conversation. Never throws and never fetches:
432
- * the portal renders this on page load, so it reports the current on-disk
433
- * truth rather than going to the network behind the admin's back.
434
- */
435
- export async function inspectConversationPackages(options) {
436
- const conversationIdentities = new Set(declaredSources("conversation", options).map(safeIdentityOrEmpty).filter(Boolean));
437
- return {
438
- global: await Promise.all(declaredSources("global", options).map((source) => describe(source, "global", options, conversationIdentities))),
439
- conversation: await Promise.all(declaredSources("conversation", options).map((source) => describe(source, "conversation", options, new Set()))),
440
- };
441
- }
442
- /** Sources one scope declares, or an empty list when its settings are unreadable. */
443
- function declaredSources(scope, options) {
444
- try {
445
- const settings = scope === "global" ? loadGlobalSettings() : resolveConversationSettings(options.office);
446
- return settings.packages ?? [];
447
- }
448
- catch {
449
- return [];
450
- }
451
- }
452
- function safeIdentityOrEmpty(source) {
453
- try {
454
- return sourceIdentity(parseSource(source));
455
- }
456
- catch {
457
- return "";
458
- }
459
- }
460
- async function describe(source, scope, options, shadowedBy) {
461
- const base = { source, scope, ready: false, skills: [] };
462
- let identity;
463
- try {
464
- identity = sourceIdentity(parseSource(source));
465
- }
466
- catch (err) {
467
- return { ...base, error: messageOf(err) };
468
- }
469
- let dir;
470
- try {
471
- dir = materializeSource(source, {
472
- scope,
473
- address: options.office.address,
474
- stateDir: options.office.workspace.stateDir,
475
- mode: "offline",
476
- }).dir;
477
- }
478
- catch (err) {
479
- return { ...base, error: messageOf(err) };
480
- }
481
- return {
482
- ...base,
483
- ready: true,
484
- dir,
485
- ...(shadowedBy.has(identity) ? { shadowed: true } : {}),
486
- skills: contributedSkills(dir),
487
- };
488
- }
489
- function contributedSkills(dir) {
490
- const skillsDir = join(dir, "skills");
491
- return loadSkillsFromDir({ dir: skillsDir, source: "package", rejectSymlinks: true }).skills.map((skill) => skill.name);
492
- }
493
- /** Conventional resource directory inside a package, mirroring pi's layout. */
494
- const SKILLS_SUBDIR = "skills";
495
- /** Slug length cap; long identities keep a digest tail instead of colliding. */
496
- const SLUG_MAX_LENGTH = 96;
497
- /**
498
- * Where package resources appear inside the sandbox.
499
- *
500
- * Deliberately OUTSIDE `/workspace`. In `full` workspace-mount mode
501
- * `/workspace` is the entire working directory, so a `/workspace/packages`
502
- * mount would shadow a real `packages/` directory in the user's tree — mikan's
503
- * own repository has one. Living outside also keeps
504
- * `translateMountedRuntimePathToHost` correct by construction: it maps only
505
- * the `/workspace` prefix and returns everything else untouched, so a package
506
- * path can never be mistranslated into a host path that does not exist.
507
- *
508
- * Skills are referenced by absolute path in the system prompt, so the location
509
- * costs nothing in usability.
510
- */
511
- const PACKAGE_RUNTIME_ROOT = "/mikan/packages";
512
- /** Runtime path a package's skills directory is mounted at. */
513
- export function packageSkillRuntimeDir(slug) {
514
- return `${PACKAGE_RUNTIME_ROOT}/${slug}/${SKILLS_SUBDIR}`;
515
- }
516
- /**
517
- * Read-only mounts exposing every resolved package's skills to the sandbox.
518
- *
519
- * Read-only rather than read-write because the host owns these files: the
520
- * directory is a git checkout that an update replaces wholesale, so an agent
521
- * edit would be silently discarded on the next refresh. Making the filesystem
522
- * refuse the write turns a confusing data-loss bug into an obvious error.
523
- *
524
- * This pure step consumes an already resolved package set and never reaches the network.
525
- */
526
- export function conversationPackageSkillMounts(packages) {
527
- return packages.skillDirs.flatMap(({ slug, dir }) => isNonSymlinkDirectory(dir)
528
- ? [{ source: dir, target: packageSkillRuntimeDir(slug), readOnly: true }]
529
- : []);
530
- }
531
- /**
532
- * Resolve the package set for one conversation. Reads both scopes' settings,
533
- * dedups, and reports the directories to load from.
534
- */
535
- export function resolveConversationPackages(options) {
536
- const declarations = [...readScope("global", options), ...readScope("conversation", options)];
537
- const errors = [];
538
- const byIdentity = new Map();
539
- for (const declaration of declarations) {
540
- let identity;
541
- try {
542
- identity = sourceIdentity(parseSource(declaration.source));
543
- }
544
- catch (err) {
545
- errors.push({ source: declaration.source, message: messageOf(err) });
546
- continue;
547
- }
548
- // Later scopes overwrite earlier ones: global is read first, so a
549
- // conversation declaring the same package shadows it.
550
- const existing = byIdentity.get(identity);
551
- if (existing && existing.scope !== declaration.scope) {
552
- log.logInfo(`Package ${identity} declared in both scopes; using the conversation's copy`);
553
- }
554
- const materialized = materialize(declaration, options, errors);
555
- if (materialized)
556
- byIdentity.set(identity, materialized);
557
- else
558
- byIdentity.delete(identity);
559
- }
560
- const packages = [...byIdentity.values()].toSorted(scopeOrder);
561
- return {
562
- packages,
563
- skillDirs: packages.flatMap(packageSkillDir),
564
- errors,
565
- };
566
- }
567
- function readScope(scope, options) {
568
- try {
569
- const sources = scope === "global"
570
- ? loadGlobalSettings().packages
571
- : resolveConversationSettings(options.office).packages;
572
- return (sources ?? []).map((source) => ({ source, scope }));
573
- }
574
- catch (err) {
575
- // Unreadable settings must not take the conversation down; the other
576
- // scope, and the convention directories, still load.
577
- log.logWarning(`Could not read ${scope} package list`, messageOf(err));
578
- return [];
579
- }
580
- }
581
- function materialize(declaration, options, errors) {
582
- try {
583
- return materializeSource(declaration.source, {
584
- scope: declaration.scope,
585
- address: options.office.address,
586
- stateDir: options.office.workspace.stateDir,
587
- mode: options.fetchMissing ? "fetch" : "offline",
588
- });
589
- }
590
- catch (err) {
591
- errors.push({ source: declaration.source, message: messageOf(err) });
592
- return undefined;
593
- }
594
- }
595
- function packageSkillDir(pkg) {
596
- const dir = join(pkg.dir, SKILLS_SUBDIR);
597
- return isNonSymlinkDirectory(dir) ? [{ slug: packageSlug(pkg), dir }] : [];
598
- }
599
- function isNonSymlinkDirectory(path) {
600
- if (!existsSync(path))
601
- return false;
602
- try {
603
- const stats = lstatSync(path);
604
- return !stats.isSymbolicLink() && stats.isDirectory();
605
- }
606
- catch (err) {
607
- log.logWarning(`Could not inspect package skills directory ${path}`, messageOf(err));
608
- return false;
609
- }
610
- }
611
- /**
612
- * Filesystem-safe, collision-resistant name for a package, used as the mount
613
- * path segment for its skills. Derived from the identity rather than the
614
- * source string so the same package spelled two ways gets one name.
615
- */
616
- function packageSlug(pkg) {
617
- const readable = pkg.identity
618
- .replace(/^(git|local):/, "")
619
- .toLowerCase()
620
- .replace(/[^a-z0-9._-]+/g, "-")
621
- .replace(/^-+|-+$/g, "");
622
- if (readable.length <= SLUG_MAX_LENGTH)
623
- return readable;
624
- // Truncation alone would let two long identities sharing a prefix (deeply
625
- // nested self-hosted groups, file:// paths) land on the same slug — and
626
- // therefore the same mount target, where one package's skills would quietly
627
- // replace the other's. The digest makes the tail collision-resistant.
628
- const digest = createHash("sha256").update(pkg.identity).digest("hex").slice(0, 8);
629
- return `${readable.slice(0, SLUG_MAX_LENGTH - digest.length - 1)}-${digest}`;
630
- }
631
- /** Global packages load before conversation ones. */
632
- function scopeRank(scope) {
633
- return scope === "global" ? 0 : 1;
634
- }
635
- function scopeOrder(a, b) {
636
- return scopeRank(a.scope) - scopeRank(b.scope);
637
- }
638
- function messageOf(err) {
639
- return err instanceof Error ? err.message : String(err);
640
- }
641
- /**
642
- * Add a source to a scope, or move an existing one to a new ref. Fetches and
643
- * validates before writing, and is idempotent: adding a source already present
644
- * re-materializes it and leaves the list unchanged.
645
- */
646
- export function addPackage(scope, rawSource, context) {
647
- const source = formatSource(parseSource(rawSource));
648
- const materialized = materializeSource(source, {
649
- scope,
650
- address: context.office.address,
651
- stateDir: context.office.workspace.stateDir,
652
- mode: "fetch",
653
- });
654
- const existing = declaredSources(scope, context);
655
- // Replace any entry for the same package so re-adding with a new ref moves
656
- // the pin instead of leaving two conflicting lines in settings.
657
- const identity = sameIdentityFilter(source);
658
- writePackages(scope, [...existing.filter((entry) => !identity(entry)), source], context);
659
- return { source, dir: materialized.dir };
660
- }
661
- /**
662
- * Drop a source from a scope's list. The materialized clone is left on disk —
663
- * removal is a declaration change, and keeping the checkout makes re-adding
664
- * instant and lets an admin undo a mistake without a network round trip.
665
- */
666
- export function removePackage(scope, rawSource, context) {
667
- const existing = declaredSources(scope, context);
668
- const remaining = existing.filter((entry) => entry !== rawSource);
669
- if (remaining.length === existing.length)
670
- return false;
671
- writePackages(scope, remaining, context);
672
- return true;
673
- }
674
- /** Re-fetch a package that is already declared, moving it to its ref's current tip. */
675
- export function refreshPackage(scope, rawSource, context) {
676
- if (!declaredSources(scope, context).includes(rawSource)) {
677
- throw new Error(`Not declared in the ${scope} scope: ${rawSource}`);
678
- }
679
- const materialized = materializeSource(rawSource, {
680
- scope,
681
- address: context.office.address,
682
- stateDir: context.office.workspace.stateDir,
683
- mode: "refresh",
684
- });
685
- return { source: rawSource, dir: materialized.dir };
686
- }
687
- function sameIdentityFilter(source) {
688
- const target = safeIdentity(source);
689
- return (entry) => safeIdentity(entry) === target;
690
- }
691
- /**
692
- * Identity of a declared entry, falling back to the raw string when it does
693
- * not parse. A malformed entry must still be matchable so an admin can replace
694
- * or remove the exact line they typed.
695
- */
696
- function safeIdentity(source) {
697
- try {
698
- return sourceIdentity(parseSource(source));
699
- }
700
- catch {
701
- return `raw:${source}`;
702
- }
703
- }
704
- /**
705
- * Writes go through the settings-mutation seam rather than touching config
706
- * directly, so package edits obey the same runner-cache policy as every other
707
- * portal write. Packages are not a cached-runner key, so this writes and
708
- * leaves live conversations alone until their next harness instance.
709
- */
710
- function writePackages(scope, packages, context) {
711
- if (scope === "global") {
712
- applyGlobalSettings(context.runtime, { packages });
713
- return;
714
- }
715
- const result = applyConversationSettings(context.runtime, context.office, {
716
- packages,
717
- });
718
- if (!result.ok)
719
- throw new Error("Conversation is busy; try again when the current run ends");
720
- }
721
- //# sourceMappingURL=index.js.map