@fastagent-sh/fastagent 0.21.0 → 0.22.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 (388) hide show
  1. package/README.md +9 -12
  2. package/dist/agent.d.ts +24 -37
  3. package/dist/agent.js +7 -15
  4. package/dist/atomic-write.d.ts +13 -17
  5. package/dist/atomic-write.js +18 -29
  6. package/dist/bind.d.ts +12 -22
  7. package/dist/bind.js +18 -27
  8. package/dist/channel.d.ts +11 -33
  9. package/dist/channels/agentcore-limits.d.ts +2 -13
  10. package/dist/channels/agentcore-limits.js +2 -13
  11. package/dist/channels/agentcore-protocol.d.ts +67 -58
  12. package/dist/channels/agentcore-protocol.js +23 -15
  13. package/dist/channels/agentcore-service.d.ts +19 -33
  14. package/dist/channels/agentcore-service.js +176 -59
  15. package/dist/channels/agentcore.d.ts +39 -33
  16. package/dist/channels/agentcore.js +90 -224
  17. package/dist/channels/body.d.ts +15 -2
  18. package/dist/channels/body.js +24 -2
  19. package/dist/channels/busy.d.ts +1 -21
  20. package/dist/channels/busy.js +2 -39
  21. package/dist/channels/control.d.ts +17 -62
  22. package/dist/channels/control.js +74 -182
  23. package/dist/channels/define-channel.d.ts +39 -0
  24. package/dist/channels/define-channel.js +9 -0
  25. package/dist/channels/discover.d.ts +10 -31
  26. package/dist/channels/discover.js +37 -31
  27. package/dist/channels/feishu/bootstrap-token.d.ts +1 -8
  28. package/dist/channels/feishu/bootstrap-token.js +7 -23
  29. package/dist/channels/feishu/card.d.ts +14 -28
  30. package/dist/channels/feishu/card.js +16 -30
  31. package/dist/channels/feishu/cloud.d.ts +1 -5
  32. package/dist/channels/feishu/context-buffer.d.ts +4 -23
  33. package/dist/channels/feishu/context-buffer.js +8 -31
  34. package/dist/channels/feishu/crypto.d.ts +10 -5
  35. package/dist/channels/feishu/crypto.js +12 -19
  36. package/dist/channels/feishu/feishu-api.d.ts +2 -1
  37. package/dist/channels/feishu/feishu-api.js +5 -4
  38. package/dist/channels/feishu/feishu.d.ts +4 -10
  39. package/dist/channels/feishu/feishu.js +113 -227
  40. package/dist/channels/feishu/invoke-turn.d.ts +5 -4
  41. package/dist/channels/feishu/invoke-turn.js +36 -54
  42. package/dist/channels/feishu/model.d.ts +4 -21
  43. package/dist/channels/feishu/model.js +1 -8
  44. package/dist/channels/feishu/normalize.d.ts +2 -10
  45. package/dist/channels/feishu/normalize.js +7 -42
  46. package/dist/channels/feishu/parse.d.ts +9 -29
  47. package/dist/channels/feishu/parse.js +8 -26
  48. package/dist/channels/feishu/preview.d.ts +12 -14
  49. package/dist/channels/feishu/preview.js +108 -207
  50. package/dist/channels/feishu/register-app.d.ts +8 -23
  51. package/dist/channels/feishu/register-app.js +7 -20
  52. package/dist/channels/feishu/register-webhook.d.ts +2 -9
  53. package/dist/channels/feishu/register-webhook.js +9 -33
  54. package/dist/channels/feishu/scaffold/channel.ts +27 -19
  55. package/dist/channels/feishu/scaffold/channel.websocket.ts +31 -0
  56. package/dist/channels/feishu/setup-mode.d.ts +11 -36
  57. package/dist/channels/feishu/setup-mode.js +7 -26
  58. package/dist/channels/feishu/ws-ingress.d.ts +1 -2
  59. package/dist/channels/feishu/ws-ingress.js +6 -8
  60. package/dist/channels/http.d.ts +15 -15
  61. package/dist/channels/http.js +19 -9
  62. package/dist/channels/kit/attachment-path.d.ts +4 -5
  63. package/dist/channels/kit/attachment-path.js +10 -34
  64. package/dist/channels/kit/context-buffer.d.ts +14 -21
  65. package/dist/channels/kit/context-buffer.js +25 -38
  66. package/dist/channels/kit/delivery.d.ts +35 -0
  67. package/dist/channels/kit/delivery.js +129 -0
  68. package/dist/channels/kit/event-stream.d.ts +5 -0
  69. package/dist/channels/kit/event-stream.js +29 -0
  70. package/dist/channels/kit/invoke-turn-kit.d.ts +53 -26
  71. package/dist/channels/kit/invoke-turn-kit.js +89 -32
  72. package/dist/channels/kit/preview-kit.d.ts +18 -72
  73. package/dist/channels/kit/preview-kit.js +22 -88
  74. package/dist/channels/kit/signature.d.ts +3 -9
  75. package/dist/channels/kit/signature.js +3 -9
  76. package/dist/channels/kit/state.d.ts +1 -2
  77. package/dist/channels/kit/state.js +5 -14
  78. package/dist/channels/kit/stop-command.d.ts +1 -2
  79. package/dist/channels/kit/stop-command.js +6 -9
  80. package/dist/channels/kit/tasks.d.ts +1 -1
  81. package/dist/channels/kit/tasks.js +8 -21
  82. package/dist/channels/kit/text.d.ts +2 -16
  83. package/dist/channels/kit/text.js +23 -31
  84. package/dist/channels/kit/thread-participants.d.ts +4 -17
  85. package/dist/channels/kit/thread-participants.js +8 -55
  86. package/dist/channels/kit/transport.d.ts +26 -0
  87. package/dist/channels/kit/transport.js +20 -0
  88. package/dist/channels/kit/turn-queue.d.ts +7 -11
  89. package/dist/channels/kit/turn-queue.js +21 -39
  90. package/dist/channels/kit/turn-runner.d.ts +32 -18
  91. package/dist/channels/kit/turn-runner.js +98 -53
  92. package/dist/channels/kit/turn-store.d.ts +32 -32
  93. package/dist/channels/kit/turn-store.js +45 -88
  94. package/dist/channels/lark/lark.d.ts +1 -5
  95. package/dist/channels/lark/onboard.d.ts +3 -12
  96. package/dist/channels/lark/onboard.js +3 -13
  97. package/dist/channels/lark/scaffold/channel.ts +27 -19
  98. package/dist/channels/lark/scaffold/channel.websocket.ts +31 -0
  99. package/dist/channels/registration.d.ts +9 -35
  100. package/dist/channels/registration.js +6 -37
  101. package/dist/channels/secret.js +2 -5
  102. package/dist/channels/serve.d.ts +47 -44
  103. package/dist/channels/serve.js +165 -101
  104. package/dist/channels/slack/config-api.d.ts +4 -27
  105. package/dist/channels/slack/config-api.js +5 -34
  106. package/dist/channels/slack/context-buffer.d.ts +2 -3
  107. package/dist/channels/slack/context-buffer.js +5 -5
  108. package/dist/channels/slack/invoke-turn.d.ts +3 -1
  109. package/dist/channels/slack/invoke-turn.js +25 -34
  110. package/dist/channels/slack/manifest.js +1 -3
  111. package/dist/channels/slack/model.d.ts +1 -2
  112. package/dist/channels/slack/model.js +1 -1
  113. package/dist/channels/slack/onboard.d.ts +4 -3
  114. package/dist/channels/slack/onboard.js +8 -11
  115. package/dist/channels/slack/onboarding-state.d.ts +3 -5
  116. package/dist/channels/slack/onboarding-state.js +9 -6
  117. package/dist/channels/slack/parse.d.ts +4 -13
  118. package/dist/channels/slack/parse.js +7 -28
  119. package/dist/channels/slack/preview.d.ts +12 -2
  120. package/dist/channels/slack/preview.js +292 -269
  121. package/dist/channels/slack/reaction.d.ts +11 -3
  122. package/dist/channels/slack/reaction.js +19 -8
  123. package/dist/channels/slack/register-webhook.js +4 -7
  124. package/dist/channels/slack/scaffold/channel.ts +20 -13
  125. package/dist/channels/slack/scaffold/slack-send.ts +2 -2
  126. package/dist/channels/slack/setup-server.d.ts +1 -5
  127. package/dist/channels/slack/setup-server.js +1 -5
  128. package/dist/channels/slack/shared-api.d.ts +1 -4
  129. package/dist/channels/slack/shared-api.js +2 -13
  130. package/dist/channels/slack/slack-api.d.ts +2 -1
  131. package/dist/channels/slack/slack-api.js +6 -4
  132. package/dist/channels/slack/slack.d.ts +11 -14
  133. package/dist/channels/slack/slack.js +121 -122
  134. package/dist/channels/sse.d.ts +1 -1
  135. package/dist/channels/sse.js +1 -1
  136. package/dist/channels/telegram/context-buffer.d.ts +7 -22
  137. package/dist/channels/telegram/context-buffer.js +6 -23
  138. package/dist/channels/telegram/invoke-turn.d.ts +7 -7
  139. package/dist/channels/telegram/invoke-turn.js +24 -43
  140. package/dist/channels/telegram/parse.d.ts +24 -51
  141. package/dist/channels/telegram/parse.js +32 -84
  142. package/dist/channels/telegram/preview.d.ts +10 -1
  143. package/dist/channels/telegram/preview.js +79 -100
  144. package/dist/channels/telegram/register-webhook.js +5 -23
  145. package/dist/channels/telegram/scaffold/channel.ts +25 -18
  146. package/dist/channels/telegram/scaffold/telegram-send.ts +6 -4
  147. package/dist/channels/telegram/telegram-api.d.ts +4 -3
  148. package/dist/channels/telegram/telegram-api.js +9 -7
  149. package/dist/channels/telegram/telegram.d.ts +4 -18
  150. package/dist/channels/telegram/telegram.js +38 -94
  151. package/dist/channels/telegram/turn-store.d.ts +11 -14
  152. package/dist/channels/telegram/turn-store.js +8 -6
  153. package/dist/channels/wait-health.d.ts +4 -6
  154. package/dist/channels/wait-health.js +10 -14
  155. package/dist/cli/add-feishu.d.ts +2 -12
  156. package/dist/cli/add-feishu.js +24 -71
  157. package/dist/cli/add-slack.d.ts +5 -3
  158. package/dist/cli/add-slack.js +53 -76
  159. package/dist/cli/auth-view.d.ts +2 -16
  160. package/dist/cli/auth-view.js +2 -16
  161. package/dist/cli/commands/add.js +25 -43
  162. package/dist/cli/commands/chat.d.ts +0 -1
  163. package/dist/cli/commands/chat.js +5 -6
  164. package/dist/cli/commands/deploy/agentcore.js +60 -65
  165. package/dist/cli/commands/deploy/docker.js +50 -23
  166. package/dist/cli/commands/deploy/fly.js +23 -61
  167. package/dist/cli/commands/deploy/railway.js +23 -18
  168. package/dist/cli/commands/deploy/shared.d.ts +38 -57
  169. package/dist/cli/commands/deploy/shared.js +40 -59
  170. package/dist/cli/commands/deploy.d.ts +10 -27
  171. package/dist/cli/commands/deploy.js +38 -60
  172. package/dist/cli/commands/destroy.d.ts +4 -0
  173. package/dist/cli/commands/destroy.js +56 -0
  174. package/dist/cli/commands/dev.d.ts +2 -1
  175. package/dist/cli/commands/dev.js +20 -23
  176. package/dist/cli/commands/info.d.ts +0 -2
  177. package/dist/cli/commands/info.js +83 -49
  178. package/dist/cli/commands/init.d.ts +1 -2
  179. package/dist/cli/commands/init.js +16 -55
  180. package/dist/cli/commands/invoke.d.ts +0 -1
  181. package/dist/cli/commands/invoke.js +5 -7
  182. package/dist/cli/commands/login.d.ts +2 -1
  183. package/dist/cli/commands/login.js +33 -38
  184. package/dist/cli/commands/logs.js +3 -4
  185. package/dist/cli/commands/models.js +1 -5
  186. package/dist/cli/commands/routine-run.d.ts +6 -0
  187. package/dist/cli/commands/routine-run.js +47 -0
  188. package/dist/cli/commands/routine.d.ts +25 -0
  189. package/dist/cli/commands/routine.js +122 -0
  190. package/dist/cli/commands/start.d.ts +31 -3
  191. package/dist/cli/commands/start.js +131 -81
  192. package/dist/cli/commands/tool.js +26 -12
  193. package/dist/cli/fail.d.ts +13 -23
  194. package/dist/cli/fail.js +20 -23
  195. package/dist/cli/invoke-stream.d.ts +1 -8
  196. package/dist/cli/kernel.d.ts +6 -38
  197. package/dist/cli/kernel.js +14 -77
  198. package/dist/cli/models-view.d.ts +1 -9
  199. package/dist/cli/models-view.js +11 -22
  200. package/dist/cli/program.d.ts +5 -6
  201. package/dist/cli/program.js +120 -157
  202. package/dist/cli/serve.d.ts +57 -41
  203. package/dist/cli/serve.js +94 -121
  204. package/dist/cli/shared.d.ts +15 -61
  205. package/dist/cli/shared.js +55 -181
  206. package/dist/cli.js +1 -8
  207. package/dist/collect.d.ts +6 -0
  208. package/dist/collect.js +6 -0
  209. package/dist/core.d.ts +4 -1
  210. package/dist/core.js +9 -7
  211. package/dist/declared-secrets.d.ts +55 -0
  212. package/dist/declared-secrets.js +88 -0
  213. package/dist/deploy/agentcore/aws-cli.d.ts +91 -0
  214. package/dist/deploy/agentcore/aws-cli.js +64 -0
  215. package/dist/deploy/agentcore/destroy.d.ts +51 -0
  216. package/dist/deploy/agentcore/destroy.js +273 -0
  217. package/dist/deploy/agentcore/forwarder.js +28 -79
  218. package/dist/deploy/agentcore/logs.d.ts +2 -18
  219. package/dist/deploy/agentcore/logs.js +27 -51
  220. package/dist/deploy/agentcore/plan.d.ts +85 -105
  221. package/dist/deploy/agentcore/plan.js +152 -314
  222. package/dist/deploy/agentcore/run.d.ts +28 -28
  223. package/dist/deploy/agentcore/run.js +227 -306
  224. package/dist/deploy/agentcore/zip.d.ts +2 -15
  225. package/dist/deploy/agentcore/zip.js +3 -17
  226. package/dist/deploy/build-context.d.ts +21 -0
  227. package/dist/deploy/build-context.js +137 -0
  228. package/dist/deploy/channel-ingress.d.ts +26 -39
  229. package/dist/deploy/channel-ingress.js +57 -28
  230. package/dist/deploy/container.d.ts +20 -34
  231. package/dist/deploy/container.js +49 -100
  232. package/dist/deploy/docker/plan.d.ts +12 -11
  233. package/dist/deploy/docker/plan.js +43 -24
  234. package/dist/deploy/docker/run.d.ts +22 -25
  235. package/dist/deploy/docker/run.js +39 -37
  236. package/dist/deploy/fly/plan.d.ts +15 -44
  237. package/dist/deploy/fly/plan.js +41 -73
  238. package/dist/deploy/fly/run.d.ts +16 -51
  239. package/dist/deploy/fly/run.js +42 -95
  240. package/dist/deploy/hosts.d.ts +24 -3
  241. package/dist/deploy/hosts.js +24 -3
  242. package/dist/deploy/preflight.d.ts +47 -41
  243. package/dist/deploy/preflight.js +282 -383
  244. package/dist/deploy/railway/plan.d.ts +16 -42
  245. package/dist/deploy/railway/plan.js +42 -60
  246. package/dist/deploy/railway/run.d.ts +30 -68
  247. package/dist/deploy/railway/run.js +86 -100
  248. package/dist/deploy/registration-gate.d.ts +6 -13
  249. package/dist/deploy/residency.d.ts +37 -0
  250. package/dist/deploy/residency.js +24 -0
  251. package/dist/deploy/runner.d.ts +10 -9
  252. package/dist/deploy/runner.js +7 -18
  253. package/dist/deploy/secrets.d.ts +40 -41
  254. package/dist/deploy/secrets.js +117 -103
  255. package/dist/deploy/workspace.d.ts +50 -0
  256. package/dist/deploy/workspace.js +197 -0
  257. package/dist/dev-supervisor.d.ts +1 -9
  258. package/dist/dev-supervisor.js +21 -64
  259. package/dist/effect-port.d.ts +50 -0
  260. package/dist/effect-port.js +77 -0
  261. package/dist/engines/pi/agent-session-factory.d.ts +50 -69
  262. package/dist/engines/pi/agent-session-factory.js +249 -146
  263. package/dist/engines/pi/auth.d.ts +15 -11
  264. package/dist/engines/pi/auth.js +96 -99
  265. package/dist/engines/pi/chat.d.ts +1 -5
  266. package/dist/engines/pi/chat.js +2 -14
  267. package/dist/engines/pi/config.d.ts +53 -51
  268. package/dist/engines/pi/config.js +83 -92
  269. package/dist/engines/pi/create.d.ts +60 -75
  270. package/dist/engines/pi/create.js +108 -141
  271. package/dist/engines/pi/definition.d.ts +14 -58
  272. package/dist/engines/pi/definition.js +21 -85
  273. package/dist/engines/pi/invoke-session.d.ts +5 -25
  274. package/dist/engines/pi/invoke-session.js +209 -244
  275. package/dist/engines/pi/login.d.ts +95 -35
  276. package/dist/engines/pi/login.js +259 -107
  277. package/dist/engines/pi/machine.d.ts +31 -0
  278. package/dist/engines/pi/machine.js +106 -0
  279. package/dist/engines/pi/models.d.ts +70 -89
  280. package/dist/engines/pi/models.js +188 -81
  281. package/dist/engines/pi/open.d.ts +65 -53
  282. package/dist/engines/pi/open.js +129 -69
  283. package/dist/engines/pi/report.d.ts +3 -12
  284. package/dist/engines/pi/report.js +2 -16
  285. package/dist/engines/pi/search-tools.d.ts +1 -9
  286. package/dist/engines/pi/search-tools.js +26 -57
  287. package/dist/engines/pi/service.d.ts +2 -16
  288. package/dist/engines/pi/service.js +2 -16
  289. package/dist/engines/pi/session-builder.d.ts +5 -9
  290. package/dist/engines/pi/session-builder.js +44 -82
  291. package/dist/engines/pi/session-control.js +286 -269
  292. package/dist/engines/pi/session-effects.d.ts +14 -0
  293. package/dist/engines/pi/session-effects.js +30 -0
  294. package/dist/engines/pi/session-inheritance.d.ts +9 -18
  295. package/dist/engines/pi/session-inheritance.js +103 -160
  296. package/dist/engines/pi/session-markers.d.ts +31 -30
  297. package/dist/engines/pi/session-markers.js +26 -25
  298. package/dist/engines/pi/session-settings.d.ts +6 -22
  299. package/dist/engines/pi/session-settings.js +10 -21
  300. package/dist/engines/pi/session-store.d.ts +26 -92
  301. package/dist/engines/pi/session-store.js +96 -310
  302. package/dist/engines/pi/tool-context.d.ts +17 -45
  303. package/dist/engines/pi/tool-context.js +7 -26
  304. package/dist/engines/pi/tool.d.ts +45 -36
  305. package/dist/engines/pi/tool.js +43 -57
  306. package/dist/engines/pi/turn-kit.d.ts +14 -52
  307. package/dist/engines/pi/turn-kit.js +18 -67
  308. package/dist/engines/pi/wake-tool.d.ts +2 -10
  309. package/dist/engines/pi/wake-tool.js +7 -27
  310. package/dist/env.d.ts +27 -28
  311. package/dist/env.js +45 -50
  312. package/dist/index.js +0 -2
  313. package/dist/lark.d.ts +1 -2
  314. package/dist/lark.js +1 -2
  315. package/dist/loader.d.ts +14 -55
  316. package/dist/loader.js +24 -43
  317. package/dist/log.d.ts +2 -12
  318. package/dist/log.js +3 -24
  319. package/dist/node.d.ts +2 -15
  320. package/dist/node.js +2 -18
  321. package/dist/observe.d.ts +2 -8
  322. package/dist/open-url.d.ts +1 -1
  323. package/dist/open-url.js +1 -1
  324. package/dist/paths.d.ts +70 -134
  325. package/dist/paths.js +165 -232
  326. package/dist/pi.d.ts +4 -6
  327. package/dist/pi.js +3 -3
  328. package/dist/proxy.d.ts +16 -6
  329. package/dist/proxy.js +52 -16
  330. package/dist/runtime.d.ts +18 -12
  331. package/dist/runtime.js +18 -11
  332. package/dist/scaffold/add-channel.d.ts +14 -31
  333. package/dist/scaffold/add-channel.js +48 -112
  334. package/dist/scaffold/init.d.ts +9 -31
  335. package/dist/scaffold/init.js +45 -138
  336. package/dist/scaffold/templates/env.example +6 -4
  337. package/dist/scaffold/templates/fastagent.config.ts +36 -0
  338. package/dist/scaffold/templates.d.ts +3 -3
  339. package/dist/scaffold/templates.js +5 -8
  340. package/dist/scaffold/vendor-skill.d.ts +2 -5
  341. package/dist/scaffold/vendor-skill.js +19 -29
  342. package/dist/schedule/cron.d.ts +9 -5
  343. package/dist/schedule/cron.js +9 -11
  344. package/dist/schedule/discover.d.ts +12 -12
  345. package/dist/schedule/discover.js +43 -34
  346. package/dist/schedule/routine.d.ts +43 -0
  347. package/dist/schedule/routine.js +32 -0
  348. package/dist/schedule/run.d.ts +55 -0
  349. package/dist/schedule/run.js +146 -0
  350. package/dist/schedule/scheduler.d.ts +44 -55
  351. package/dist/schedule/scheduler.js +291 -265
  352. package/dist/schedule/state.d.ts +105 -10
  353. package/dist/schedule/state.js +293 -19
  354. package/dist/schedule/wake-alarm.d.ts +10 -23
  355. package/dist/schedule/wake-alarm.js +91 -121
  356. package/dist/schedule/wakeups.d.ts +23 -39
  357. package/dist/schedule/wakeups.js +33 -75
  358. package/dist/secrets-gate.d.ts +32 -0
  359. package/dist/secrets-gate.js +33 -0
  360. package/dist/service.d.ts +137 -98
  361. package/dist/service.js +250 -252
  362. package/dist/session-remote.d.ts +33 -44
  363. package/dist/session-remote.js +203 -192
  364. package/dist/session.d.ts +153 -228
  365. package/dist/session.js +33 -55
  366. package/dist/tunnel.d.ts +8 -36
  367. package/dist/tunnel.js +24 -65
  368. package/dist/version.d.ts +2 -2
  369. package/dist/version.js +2 -2
  370. package/package.json +10 -16
  371. package/dist/channels/agentcore-state.d.ts +0 -77
  372. package/dist/channels/agentcore-state.js +0 -276
  373. package/dist/channels/github/github.d.ts +0 -31
  374. package/dist/channels/github/github.js +0 -89
  375. package/dist/channels/github/scaffold/channel.ts +0 -25
  376. package/dist/cli/commands/attach.d.ts +0 -108
  377. package/dist/cli/commands/attach.js +0 -637
  378. package/dist/cli/commands/fire.d.ts +0 -7
  379. package/dist/cli/commands/fire.js +0 -38
  380. package/dist/cli/commands/schedule.d.ts +0 -12
  381. package/dist/cli/commands/schedule.js +0 -87
  382. package/dist/github.d.ts +0 -3
  383. package/dist/github.js +0 -2
  384. package/dist/scaffold/templates/fastagent.config.mjs +0 -23
  385. package/dist/schedule/audit.d.ts +0 -18
  386. package/dist/schedule/audit.js +0 -57
  387. package/dist/schedule/schedule.d.ts +0 -35
  388. package/dist/schedule/schedule.js +0 -23
@@ -0,0 +1,106 @@
1
+ /**
2
+ * THE MACHINE an agent runs on, as fastagent inherits it: the skills and prompt templates this box provides — found
3
+ * by pi's own Agent Skills discovery, installed pi packages included — and pi's engine settings.
4
+ *
5
+ * An agent inherits its machine the way it already inherits the `PATH`: `bash` runs whatever is installed, and a
6
+ * skill in `~/.pi/agent/skills` is available the same way. Deploying ships the project scope — the workspace — and
7
+ * nothing here is compared against a deployment, the same way nobody is told their local `ffmpeg` is not in the image.
8
+ *
9
+ * READ ONCE per process, like the environment it is. The definition is what stays live (`dev` re-reads it per turn,
10
+ * because it is what an author edits); a skill installed after boot arrives on the next start.
11
+ */
12
+ import { DefaultPackageManager, DefaultResourceLoader, SettingsManager, getAgentDir, } from "@earendil-works/pi-coding-agent";
13
+ import { log } from "../../log.js";
14
+ /** Keyed by the two places it reads: the workspace (project scope) and pi's own directory (user scope). */
15
+ const reads = new Map();
16
+ /** This process's one read of the machine, shared by the run plane and `commands()` so the two cannot disagree. */
17
+ export function readMachine(workspace) {
18
+ // pi's own answer for where its user-level resources live — asked, not spelled, since `PI_CODING_AGENT_DIR` moves it.
19
+ const agentDir = getAgentDir();
20
+ const key = `${workspace}\u0000${agentDir}`;
21
+ const cached = reads.get(key);
22
+ if (cached)
23
+ return cached;
24
+ const reading = read(workspace, agentDir);
25
+ reads.set(key, reading);
26
+ return reading;
27
+ }
28
+ async function read(workspace, agentDir) {
29
+ const files = SettingsManager.create(workspace, agentDir);
30
+ // pi reads an unparseable or locked settings file as `{}` and keeps the error for whoever asks. Nobody did, so a
31
+ // trailing comma in `~/.pi/agent/settings.json` — or pi's own TUI holding the lock at that moment — left this whole
32
+ // process on pi's defaults, silently: the read happens once.
33
+ for (const { scope, path, error } of files.drainErrors()) {
34
+ log.warn(`[fastagent] pi ${scope} settings${path ? ` (${path})` : ""} could not be read, so pi's defaults apply: ${error.message}`);
35
+ }
36
+ // INSTALLED PACKAGES, NEVER AN INSTALL. pi's loader resolves `packages` itself and installs a missing one
37
+ // (`npm install`, `git clone`), throwing out of `reload()` when that fails — measured. So fastagent resolves them
38
+ // here, telling pi to skip what is absent, and hands the loader a packageless copy of the settings so its own
39
+ // resolve has nothing to do.
40
+ const manager = new DefaultPackageManager({ cwd: workspace, agentDir, settingsManager: files });
41
+ const packages = await manager.resolve(async () => "skip");
42
+ // A package skipped is said, once: its skills would otherwise just not be there. Asked of the configured list, not
43
+ // of `onMissing` — pi never calls that under `PI_OFFLINE`, so the warning would vanish exactly when offline.
44
+ for (const { source } of manager.listConfiguredPackages().filter((configured) => !configured.installedPath)) {
45
+ log.warn(`[fastagent] pi package ${source} is not installed, so its skills and prompts are not loaded`);
46
+ }
47
+ const settings = {
48
+ global: withoutPackages(files.getGlobalSettings()),
49
+ project: withoutPackages(files.getProjectSettings()),
50
+ };
51
+ const loader = new DefaultResourceLoader({
52
+ cwd: workspace,
53
+ agentDir,
54
+ settingsManager: scopedSettings(settings),
55
+ additionalSkillPaths: fromPackages(packages.skills),
56
+ additionalPromptTemplatePaths: fromPackages(packages.prompts),
57
+ // The machine's extensions are its owner's setup, not this agent's (agent-session-factory.ts loads only the
58
+ // definition's own); context files are fastagent's own (segment ②).
59
+ noExtensions: true,
60
+ noContextFiles: true,
61
+ });
62
+ await loader.reload();
63
+ const { skills, diagnostics: skillDiagnostics } = loader.getSkills();
64
+ const { prompts, diagnostics: promptDiagnostics } = loader.getPrompts();
65
+ // Said once — this is the process's only read. A `SKILL.md` with no description, or a prompt template whose
66
+ // frontmatter does not parse, is otherwise simply absent.
67
+ for (const [kind, diagnostics] of [
68
+ ["skill", skillDiagnostics],
69
+ ["prompt template", promptDiagnostics],
70
+ ]) {
71
+ for (const diagnostic of diagnostics) {
72
+ log.warn(`[fastagent] ${kind} ${diagnostic.type}: ${diagnostic.message}${diagnostic.path ? ` (${diagnostic.path})` : ""}`);
73
+ }
74
+ }
75
+ return { skills, prompts, settingsManager: () => scopedSettings(settings) };
76
+ }
77
+ /** A package's enabled resources; the loader discovers the top-level ones itself. */
78
+ function fromPackages(resources) {
79
+ return resources.filter((r) => r.enabled && r.metadata.origin === "package").map((r) => r.path);
80
+ }
81
+ function withoutPackages({ packages: _, ...rest }) {
82
+ return rest;
83
+ }
84
+ /**
85
+ * A SettingsManager over the boot snapshot. TWO scopes, not `SettingsManager.inMemory`'s one: pi deep-merges the
86
+ * project file over the global one (a project `retry.enabled` keeps the global `retry.maxRetries`), and flattening
87
+ * them first would change that. A write stays in memory — a served turn never edits the operator's files.
88
+ */
89
+ function scopedSettings(snapshot) {
90
+ const stored = {
91
+ global: JSON.stringify(snapshot.global),
92
+ project: JSON.stringify(snapshot.project),
93
+ };
94
+ return SettingsManager.fromStorage({
95
+ withLock(scope, fn) {
96
+ const next = fn(stored[scope]);
97
+ if (next !== undefined)
98
+ stored[scope] = next;
99
+ },
100
+ });
101
+ }
102
+ /** The definition's names win: vendoring a skill into `skills/` is how an author overrides the machine's. */
103
+ export function withMachine(own, lent) {
104
+ const names = new Set(own.map((item) => item.name));
105
+ return [...own, ...lent.filter((item) => !names.has(item.name))];
106
+ }
@@ -1,93 +1,92 @@
1
1
  import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
2
- import { type Api, type Model, type Models, type Provider } from "@earendil-works/pi-ai";
2
+ import { type Api, type CredentialStore, type Model, type Models, type Provider } from "@earendil-works/pi-ai";
3
3
  import { ModelRuntime } from "@earendil-works/pi-coding-agent";
4
4
  import { type FastagentAuthOptions } from "./auth.ts";
5
- import { type InteractiveLoginKind } from "./login.ts";
6
- /** The DEFINITION-LOCAL custom-endpoint file, in pi's own models.json schema (see pi's docs/models.md):
7
- * declare a self-hosted / gateway endpoint as `{ providers: { <id>: { baseUrl, api, apiKey, models } } }`
8
- * and select it with a `<id>/<modelId>` model spec. Keys belong in the environment — `apiKey` supports
9
- * `"$ENV_VAR"` interpolation and `"!command"` — with the NAME listed in `deploy.secrets` so the value
10
- * travels to the host. Living in the agent dir is the whole point: it is part of the definition, so it
11
- * is baked into the deployed image. pi's MACHINE-GLOBAL `~/.pi/agent/models.json` stays unread — that
12
- * one is builder-machine state, and reading it would make an agent work locally and lose its model on
13
- * deploy. The NAME itself lives in the neutral paths.ts — `dev`'s watcher needs the same one, and a
14
- * second spelling would let the restart scope drift from what the worker loads. */
5
+ import { type AuthLayers } from "./config.ts";
6
+ /** The DEFINITION-LOCAL custom-endpoint file, in pi's own models.json schema (see pi's docs/models.md). */
15
7
  export interface CreatePiModelsOptions extends FastagentAuthOptions {
16
- /** Credentials file path. Defaults to the global `~/.fastagent/.secrets/auth.json`; the directory opener passes
17
- * the project-level `<root>/.secrets/auth.json`. */
8
+ /** Credentials file (default `GLOBAL_AUTH_PATH`). A named file is an instruction: no second layer. */
18
9
  authPath?: string;
19
10
  /** Extra providers registered on top of the built-ins (same id overrides a built-in). */
20
11
  providers?: Provider[];
21
12
  }
22
- /**
23
- * A `Models` with every built-in pi provider, wired to fastagent's auth: stored credentials from the
24
- * {@link CreatePiModelsOptions.authPath} file (via {@link fastagentCredentialStore}; the global
25
- * `~/.fastagent/.secrets/auth.json` unless the opener passes a project-level path), then ambient env vars. A
26
- * stored credential owns the provider; env is consulted only when nothing is stored (resolution order
27
- * is upstream-owned).
28
- */
13
+ /** A `Models` with every built-in pi provider, wired to fastagent's auth. */
29
14
  export declare function createPiModels(options?: CreatePiModelsOptions): Models;
15
+ /** The built-ins plus `providers` (a same id replaces a built-in), over any credential store. */
16
+ export declare function piModelsOver(credentials: CredentialStore, providers?: readonly Provider[]): Models;
30
17
  /**
31
- * pi's Model with the API-shape generic erased — fastagent only passes models through to the engine,
32
- * so the generic carries no information. One alias keeps the `any` auditable.
18
+ * pi's Model with the API-shape generic erased — fastagent only passes models through to the engine, so the generic
19
+ * carries no information.
33
20
  */
34
21
  export type AnyModel = Model<any>;
22
+ /** The serving default for reasoning effort, pinned to what pi's TUI defaults to (its own DEFAULT_THINKING_LEVEL). */
23
+ export declare const DEFAULT_THINKING_LEVEL: ThinkingLevel;
35
24
  /**
36
- * The serving default for reasoning effort, pinned to what pi's TUI defaults to (its own
37
- * DEFAULT_THINKING_LEVEL) — NOT inherited from the engine, whose fallback is "off": an author vibes
38
- * at "medium" in pi and must get "medium" when served (fidelity), and pinning the value here means
39
- * an upstream default change in either place cannot silently alter deployments. Models that do not
40
- * support a level are clamped by pi per model.
25
+ * The MACHINE's custom-endpoint file, in the same schema as an agent's own: endpoints a person set up for this machine
26
+ * (a local Ollama, a company gateway), which every agent here inherits the way it inherits the machine's skills.
27
+ * `FASTAGENT_MODELS_PATH` moves it. It never ships: a deployed agent has only its definition's file.
41
28
  */
42
- export declare const DEFAULT_THINKING_LEVEL: ThinkingLevel;
29
+ export declare function machineModelsPath(env?: NodeJS.ProcessEnv): string;
43
30
  /**
44
- * The `ModelRuntime`-shaped sibling of {@link createPiModels} — the SAME hub semantics (built-in
45
- * providers + fastagent's credential store at `authPath`) in the type pi's session services require
46
- * (`createAgentSessionServices({ modelRuntime })`). Built-ins PLUS the agent's own
47
- * {@link AGENT_MODELS_FILE} when `agentDir` is given (a dir-less caller gets built-ins only), and no
48
- * availability network, so the model surface equals serving's.
49
- *
50
- * `ModelRuntime` also takes `Provider` INSTANCES via `registerNativeProvider` (pi 0.83); the
51
- * declarative file is what this rung wires because it is data that travels with the definition.
31
+ * Where an agent's custom endpoints come from, for a report: the machine file, the providers the agent inherits from
32
+ * it, and the ones its own file overrides. Undefined when the machine has no file.
52
33
  */
34
+ export declare function machineModels(agentDir: string): Promise<{
35
+ path: string;
36
+ inherited: string[];
37
+ overridden: string[];
38
+ } | undefined>;
39
+ /** Whether pi ships this provider id itself, so an agent resolves it without any models.json entry. */
40
+ export declare function isBuiltinProvider(providerId: string): boolean;
41
+ /** The `ModelRuntime`-shaped sibling of {@link createPiModels}. */
53
42
  export declare function createPiModelRuntime(options?: FastagentAuthOptions & {
54
- authPath?: string;
55
- /** The agent dir, whose {@link AGENT_MODELS_FILE} declares custom endpoints. Omit for built-ins only. */
43
+ /** The credentials files to read (default: the global file alone). */
44
+ auth?: AuthLayers;
45
+ /** The agent dir, whose {@link AGENT_MODELS_FILE} declares custom endpoints. */
56
46
  agentDir?: string;
47
+ /**
48
+ * Layer the machine's models.json under the agent's (default). Off for the registry a DEPLOYED agent has, which
49
+ * `deploy` must judge by: the machine's file does not ship.
50
+ */
51
+ machineLayer?: boolean;
57
52
  /** Where the dynamic model-catalog cache goes; defaults to the agent's resolved state root. */
58
53
  stateRoot?: string;
59
- /** Extra providers for the ids the built-ins do not cover — the CODE-shaped sibling of models.json,
60
- * for what a file cannot express (minting a token per request, a test fake).
61
- *
62
- * On an id COLLISION the file wins, not this: upstream installs a native provider as the BASE and
63
- * composes the models.json entry over it. Right way round — where a deployed agent's traffic goes
64
- * is a property of the definition, not of the program that embedded it — but it does mean a same-id
65
- * file entry silently replaces the endpoint injected here. Use a distinct id to keep both. */
54
+ /** Extra providers for the ids the built-ins do not cover. */
66
55
  providers?: Provider[];
56
+ /** A credential store to use instead of the files (login verifies an entered key from memory). */
57
+ credentials?: CredentialStore;
67
58
  }): Promise<ModelRuntime>;
68
- /**
69
- * How a model's credential will REACH a deployed agent — the question `deploy` asks, which
70
- * {@link probeAuthSource} cannot answer: it flattens every models.json endpoint to the display label
71
- * "configured API key", so a self-hosted endpoint looks credential-less to the deploy gate even when
72
- * its key is sitting in an env var.
73
- *
74
- * - `envVar`: an environment variable backs it, BY NAME — the shape `deploy` already understands, so
75
- * the value carries as a host secret with no extra declaration from the author.
76
- * - `inDefinition`: the definition itself carries it (a literal `apiKey`, or a `!command` run on the
77
- * host). Nothing for `deploy` to carry — and nothing to gate on either, which is the point: the
78
- * `fastagent login` remedy is meaningless for a provider login cannot serve.
79
- *
80
- * Neither set = a stored credential or nothing at all; the existing auth.json / gate paths decide.
81
- */
59
+ /** How a model's credential will REACH a deployed agent. */
82
60
  export declare function modelCredentialCarry(runtime: ModelRuntime, spec: string): {
83
61
  envVar?: string;
84
62
  inDefinition: boolean;
85
63
  };
86
- /** Per-provider auth status for the first-run model picker: usable now (with the source label), not
87
- * configured, or configured-but-broken (expired token, refresh failure, corrupt store — kept as DATA
88
- * so the picker can show it instead of silently dropping the provider). Non-ready states carry the
89
- * provider's {@link InteractiveLoginKind}, so the picker's hint predicts what picking does — an
90
- * OAuth login, an API-key prompt, or (env-key-only providers) neither. */
64
+ /**
65
+ * EVERY provider whose `models.json` entry writes its key as a LITERAL rather than a `"$NAME"` reference or a
66
+ * `"!cmd"`. The file ships inside the image, so a literal there is a credential in a readable layer.
67
+ *
68
+ * Read from the FILE, not from `getProviderAuthStatus`: that answers "what satisfies this provider right now" and
69
+ * returns `stored` first, so a provider that has both an `auth.json` entry and a literal in the file would report
70
+ * `stored` and the literal would go unreported. The question is what the definition DECLARES, and only the file
71
+ * answers it. The three-way split mirrors pi's `configuredRequestAuthStatus`, which is not exported.
72
+ *
73
+ * The caller WARNS on this; it does not refuse. Whether a given string is a credential is the author's knowledge,
74
+ * not the framework's — pi's own docs prescribe `"apiKey": "ollama"` for a keyless local server, and no static rule
75
+ * separates that from a leaked key (an endpoint's reachability is not decidable from its URL either). FastAgent
76
+ * gates what IT causes; what the author wrote into their own committed file, it reports.
77
+ */
78
+ export declare function literalKeyProviders(agentDir: string): Promise<string[]>;
79
+ /**
80
+ * What a provider can offer as an interactive login: an OAuth flow, an API-key ENTRY prompt, or nothing ("none" — the
81
+ * key must come from the provider's env var).
82
+ */
83
+ export type InteractiveLoginKind = "oauth" | "api_key" | "none";
84
+ export declare function interactiveLoginKind(p: Provider): InteractiveLoginKind;
85
+ /** THE rule for "can this method be signed in to interactively": the auth to run for it, or undefined. */
86
+ export declare function interactiveAuth(provider: Provider, method: Exclude<InteractiveLoginKind, "none">): import("@earendil-works/pi-ai").ApiKeyAuth | import("@earendil-works/pi-ai").OAuthAuth | undefined;
87
+ /** The providers a sign-in can target: pi's built-ins plus `extra`, composed exactly as {@link createPiModels} does. */
88
+ export declare function loginProviders(extra?: readonly Provider[]): readonly Provider[];
89
+ /** Per-provider auth status for the first-run model picker. */
91
90
  export type ProviderAuthStatus = {
92
91
  state: "ready";
93
92
  source?: string;
@@ -99,37 +98,19 @@ export type ProviderAuthStatus = {
99
98
  message: string;
100
99
  login: InteractiveLoginKind;
101
100
  };
102
- /**
103
- * Probe every provider's auth once (auth is provider-scoped, so any of its models works as the probe)
104
- * — the status map behind the first-run model picker (`fastagent dev`/`start`/`invoke` with no model
105
- * set). The picker shows the FULL catalog annotated with these statuses, so "what fastagent supports"
106
- * and "what is authenticated on this machine" stay distinguishable; a needs-login choice triggers an
107
- * inline `loginFlow`. Providers with no models are omitted (nothing to pick).
108
- */
101
+ /** Probe every provider's auth once (auth is provider-scoped, so any of its models works as the probe). */
109
102
  export declare function providerAuthStatuses(models: Models): Promise<Map<string, ProviderAuthStatus>>;
103
+ /** Which source currently satisfies auth for `spec` — a startup diagnostic. */
104
+ export declare function probeAuthSource(models: Models, spec: string): Promise<string | undefined>;
110
105
  /**
111
- * Which source currently satisfies auth for `spec` — a startup diagnostic. Returns the upstream
112
- * `AuthResult.source` label: `"OAuth"` for a stored OAuth credential (e.g. a logged-in openai-codex),
113
- * `"stored credential"` for a stored API key, an env-var name like `"ANTHROPIC_API_KEY"` for env, or
114
- * undefined when unconfigured. Reporting-only; never throws.
106
+ * Verdict of {@link probeApiKey}: `rejected` is DEFINITIVE (the provider answered HTTP 401 — the key is wrong);
107
+ * everything else non-ok is `unknown`.
115
108
  */
116
- export declare function probeAuthSource(models: Models, spec: string): Promise<string | undefined>;
117
- /** Verdict of {@link probeApiKey}: `rejected` is DEFINITIVE (the provider answered HTTP 401 — the key
118
- * is wrong); everything else non-ok is `unknown` — a 403 can be a VALID key without model permission,
119
- * a 429/5xx/network failure says nothing about the key — so callers must only destroy state on
120
- * `rejected`. */
121
109
  export type KeyProbe = {
122
110
  state: "ok";
123
111
  } | {
124
112
  state: "rejected" | "unknown";
125
113
  message: string;
126
114
  };
127
- /**
128
- * Quick-fail probe for a just-stored API key: one minimal real request through the standard auth
129
- * resolution path (the same path invokes take), so a mistyped key surfaces at login time, not at the
130
- * first turn. `complete` reports provider errors as `stopReason: "error"` rather than throwing; the
131
- * HTTP status arrives via `onResponse` — when a provider path never calls it (SDK transports), fall
132
- * back to a conservative "401" match in the error text. Short timeout, no retries: feedback speed
133
- * over transient-failure tolerance (a transient lands on `unknown`, which keeps the key).
134
- */
135
- export declare function probeApiKey(models: Models, model: Model<Api>): Promise<KeyProbe>;
115
+ /** Quick-fail probe for a just-stored API key. */
116
+ export declare function probeApiKey(models: Models, model: Model<Api>, signal?: AbortSignal): Promise<KeyProbe>;