@fastagent-sh/fastagent 0.14.0 → 0.16.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 (277) hide show
  1. package/README.md +16 -6
  2. package/dist/agent.d.ts +20 -0
  3. package/dist/agent.js +9 -0
  4. package/dist/channels/agentcore-limits.d.ts +7 -0
  5. package/dist/channels/agentcore-limits.js +9 -0
  6. package/dist/channels/agentcore-state.d.ts +83 -0
  7. package/dist/channels/agentcore-state.js +258 -0
  8. package/dist/channels/agentcore.d.ts +98 -0
  9. package/dist/channels/agentcore.js +260 -0
  10. package/dist/channels/busy.d.ts +23 -0
  11. package/dist/channels/busy.js +53 -0
  12. package/dist/channels/context-buffer.d.ts +35 -0
  13. package/dist/channels/context-buffer.js +103 -0
  14. package/dist/channels/control.d.ts +28 -0
  15. package/dist/channels/control.js +214 -0
  16. package/dist/channels/feishu/card.js +1 -1
  17. package/dist/channels/feishu/context-buffer.d.ts +15 -13
  18. package/dist/channels/feishu/context-buffer.js +62 -69
  19. package/dist/channels/feishu/feishu-api.d.ts +11 -3
  20. package/dist/channels/feishu/feishu-api.js +24 -3
  21. package/dist/channels/feishu/feishu.d.ts +27 -27
  22. package/dist/channels/feishu/feishu.js +318 -207
  23. package/dist/channels/feishu/invoke-turn.d.ts +7 -20
  24. package/dist/channels/feishu/invoke-turn.js +44 -79
  25. package/dist/channels/feishu/model.d.ts +2 -2
  26. package/dist/channels/feishu/normalize.d.ts +2 -1
  27. package/dist/channels/feishu/normalize.js +0 -1
  28. package/dist/channels/feishu/parse.d.ts +22 -8
  29. package/dist/channels/feishu/parse.js +24 -7
  30. package/dist/channels/feishu/preview.d.ts +4 -7
  31. package/dist/channels/feishu/preview.js +27 -142
  32. package/dist/channels/feishu/register-app.d.ts +2 -1
  33. package/dist/channels/feishu/register-webhook.d.ts +2 -1
  34. package/dist/channels/feishu/scaffold/channel.ts +9 -8
  35. package/dist/channels/feishu/scaffold/feishu-send.ts +6 -4
  36. package/dist/channels/feishu/setup-mode.d.ts +37 -0
  37. package/dist/channels/feishu/setup-mode.js +28 -0
  38. package/dist/channels/feishu/ws-ingress.d.ts +28 -0
  39. package/dist/channels/feishu/ws-ingress.js +136 -0
  40. package/dist/channels/github/github.js +16 -7
  41. package/dist/channels/http.d.ts +14 -0
  42. package/dist/channels/http.js +36 -3
  43. package/dist/channels/invoke-turn-kit.d.ts +65 -0
  44. package/dist/channels/invoke-turn-kit.js +87 -0
  45. package/dist/channels/lark/lark.d.ts +4 -2
  46. package/dist/channels/lark/lark.js +4 -1
  47. package/dist/channels/lark/onboard.d.ts +8 -4
  48. package/dist/channels/lark/onboard.js +8 -0
  49. package/dist/channels/lark/scaffold/channel.ts +9 -8
  50. package/dist/channels/lark/scaffold/lark-send.ts +6 -4
  51. package/dist/channels/preview-kit.d.ts +115 -0
  52. package/dist/channels/preview-kit.js +184 -0
  53. package/dist/channels/seen.d.ts +5 -0
  54. package/dist/channels/seen.js +35 -0
  55. package/dist/channels/slack/bot-auth.d.ts +15 -0
  56. package/dist/channels/slack/bot-auth.js +146 -0
  57. package/dist/channels/slack/config-api.d.ts +60 -0
  58. package/dist/channels/slack/config-api.js +149 -0
  59. package/dist/channels/slack/context-buffer.d.ts +24 -0
  60. package/dist/channels/slack/context-buffer.js +37 -0
  61. package/dist/channels/slack/invoke-turn.d.ts +19 -0
  62. package/dist/channels/slack/invoke-turn.js +63 -0
  63. package/dist/channels/slack/manifest.d.ts +49 -0
  64. package/dist/channels/slack/manifest.js +69 -0
  65. package/dist/channels/slack/model.d.ts +67 -0
  66. package/dist/channels/slack/model.js +2 -0
  67. package/dist/channels/slack/onboard.d.ts +41 -0
  68. package/dist/channels/slack/onboard.js +120 -0
  69. package/dist/channels/slack/onboarding-state.d.ts +31 -0
  70. package/dist/channels/slack/onboarding-state.js +69 -0
  71. package/dist/channels/slack/parse.d.ts +38 -0
  72. package/dist/channels/slack/parse.js +124 -0
  73. package/dist/channels/slack/preview.d.ts +23 -0
  74. package/dist/channels/slack/preview.js +403 -0
  75. package/dist/channels/slack/reaction.d.ts +24 -0
  76. package/dist/channels/slack/reaction.js +62 -0
  77. package/dist/channels/slack/register-webhook.d.ts +10 -0
  78. package/dist/channels/slack/register-webhook.js +49 -0
  79. package/dist/channels/slack/scaffold/channel.ts +33 -0
  80. package/dist/channels/slack/scaffold/slack-send.ts +171 -0
  81. package/dist/channels/slack/setup-server.d.ts +17 -0
  82. package/dist/channels/slack/setup-server.js +103 -0
  83. package/dist/channels/slack/slack-api.d.ts +57 -0
  84. package/dist/channels/slack/slack-api.js +399 -0
  85. package/dist/channels/slack/slack.d.ts +51 -0
  86. package/dist/channels/slack/slack.js +496 -0
  87. package/dist/channels/slack/welcomed.d.ts +5 -0
  88. package/dist/channels/slack/welcomed.js +32 -0
  89. package/dist/channels/state.d.ts +11 -4
  90. package/dist/channels/state.js +22 -15
  91. package/dist/channels/stop-command.d.ts +6 -0
  92. package/dist/channels/stop-command.js +36 -0
  93. package/dist/channels/tasks.d.ts +7 -0
  94. package/dist/channels/tasks.js +25 -0
  95. package/dist/channels/telegram/context-buffer.d.ts +8 -17
  96. package/dist/channels/telegram/context-buffer.js +6 -85
  97. package/dist/channels/telegram/invoke-turn.d.ts +5 -22
  98. package/dist/channels/telegram/invoke-turn.js +11 -58
  99. package/dist/channels/telegram/parse.d.ts +0 -7
  100. package/dist/channels/telegram/parse.js +4 -2
  101. package/dist/channels/telegram/preview.d.ts +4 -7
  102. package/dist/channels/telegram/preview.js +24 -142
  103. package/dist/channels/telegram/scaffold/telegram-send.ts +6 -3
  104. package/dist/channels/telegram/telegram.js +24 -10
  105. package/dist/channels/{feishu/text.d.ts → text.d.ts} +15 -1
  106. package/dist/channels/{feishu/text.js → text.js} +15 -1
  107. package/dist/channels/thread-participants.d.ts +21 -0
  108. package/dist/channels/thread-participants.js +132 -0
  109. package/dist/channels/turn-queue.js +8 -1
  110. package/dist/channels/turn-store.d.ts +1 -1
  111. package/dist/channels/turn-store.js +2 -3
  112. package/dist/cli/add-feishu.d.ts +30 -0
  113. package/dist/cli/add-feishu.js +366 -0
  114. package/dist/cli/add-slack.d.ts +11 -0
  115. package/dist/cli/add-slack.js +199 -0
  116. package/dist/{cli-auth.d.ts → cli/auth-view.d.ts} +1 -1
  117. package/dist/{cli-auth.js → cli/auth-view.js} +1 -1
  118. package/dist/cli/commands/add.d.ts +4 -0
  119. package/dist/cli/commands/add.js +191 -60
  120. package/dist/cli/commands/attach.d.ts +82 -0
  121. package/dist/cli/commands/attach.js +563 -0
  122. package/dist/cli/commands/chat.d.ts +1 -0
  123. package/dist/cli/commands/chat.js +12 -7
  124. package/dist/cli/commands/deploy.d.ts +3 -1
  125. package/dist/cli/commands/deploy.js +384 -82
  126. package/dist/cli/commands/dev.js +34 -26
  127. package/dist/cli/commands/fire.js +17 -18
  128. package/dist/cli/commands/info.js +36 -29
  129. package/dist/cli/commands/init.d.ts +1 -1
  130. package/dist/cli/commands/init.js +65 -53
  131. package/dist/cli/commands/invoke.js +11 -9
  132. package/dist/cli/commands/login.js +48 -45
  133. package/dist/cli/commands/models.js +1 -1
  134. package/dist/cli/commands/schedule.js +6 -8
  135. package/dist/cli/commands/start.js +102 -39
  136. package/dist/cli/commands/tool.js +23 -18
  137. package/dist/cli/fail.d.ts +17 -2
  138. package/dist/cli/fail.js +25 -1
  139. package/dist/{invoke-stream.d.ts → cli/invoke-stream.d.ts} +1 -1
  140. package/dist/{invoke-stream.js → cli/invoke-stream.js} +4 -0
  141. package/dist/cli/kernel.d.ts +3 -2
  142. package/dist/cli/models-view.d.ts +21 -0
  143. package/dist/cli/models-view.js +66 -0
  144. package/dist/cli/program.js +135 -56
  145. package/dist/cli/serve.d.ts +60 -20
  146. package/dist/cli/serve.js +252 -47
  147. package/dist/cli/shared.d.ts +40 -7
  148. package/dist/cli/shared.js +180 -38
  149. package/dist/collect.d.ts +14 -3
  150. package/dist/collect.js +24 -0
  151. package/dist/core.d.ts +3 -1
  152. package/dist/core.js +2 -0
  153. package/dist/deploy/agentcore/plan.d.ts +117 -0
  154. package/dist/deploy/agentcore/plan.js +721 -0
  155. package/dist/deploy/agentcore/run.d.ts +73 -0
  156. package/dist/deploy/agentcore/run.js +412 -0
  157. package/dist/deploy/agentcore/zip.d.ts +17 -0
  158. package/dist/deploy/agentcore/zip.js +68 -0
  159. package/dist/deploy/container.d.ts +26 -25
  160. package/dist/deploy/container.js +93 -89
  161. package/dist/deploy/docker/plan.d.ts +3 -3
  162. package/dist/deploy/docker/plan.js +20 -23
  163. package/dist/deploy/fly/plan.d.ts +5 -1
  164. package/dist/deploy/fly/plan.js +39 -26
  165. package/dist/deploy/fly/run.d.ts +17 -5
  166. package/dist/deploy/fly/run.js +52 -7
  167. package/dist/deploy/preflight.d.ts +20 -8
  168. package/dist/deploy/preflight.js +267 -71
  169. package/dist/deploy/railway/plan.d.ts +10 -1
  170. package/dist/deploy/railway/plan.js +53 -20
  171. package/dist/deploy/railway/run.d.ts +13 -5
  172. package/dist/deploy/railway/run.js +22 -7
  173. package/dist/deploy/runner.d.ts +7 -3
  174. package/dist/deploy/runner.js +9 -3
  175. package/dist/deploy/secrets.d.ts +2 -1
  176. package/dist/deploy/secrets.js +23 -3
  177. package/dist/dev-supervisor.d.ts +11 -10
  178. package/dist/dev-supervisor.js +56 -50
  179. package/dist/engines/pi/auth.d.ts +8 -7
  180. package/dist/engines/pi/auth.js +12 -10
  181. package/dist/engines/pi/channel.d.ts +22 -16
  182. package/dist/engines/pi/channel.js +92 -62
  183. package/dist/engines/pi/chat.d.ts +4 -16
  184. package/dist/engines/pi/chat.js +8 -261
  185. package/dist/engines/pi/config.d.ts +20 -55
  186. package/dist/engines/pi/config.js +49 -121
  187. package/dist/engines/pi/create.d.ts +30 -10
  188. package/dist/engines/pi/create.js +33 -26
  189. package/dist/engines/pi/definition.d.ts +7 -26
  190. package/dist/engines/pi/definition.js +8 -54
  191. package/dist/engines/pi/harness.d.ts +49 -0
  192. package/dist/engines/pi/harness.js +90 -2
  193. package/dist/engines/pi/invoke.d.ts +55 -2
  194. package/dist/engines/pi/invoke.js +304 -19
  195. package/dist/engines/pi/login.d.ts +12 -1
  196. package/dist/engines/pi/login.js +16 -4
  197. package/dist/engines/pi/models.d.ts +59 -13
  198. package/dist/engines/pi/models.js +62 -24
  199. package/dist/engines/pi/open.d.ts +114 -0
  200. package/dist/engines/pi/open.js +127 -0
  201. package/dist/engines/pi/session-builder.d.ts +16 -0
  202. package/dist/engines/pi/session-builder.js +308 -0
  203. package/dist/engines/pi/session-control.d.ts +50 -0
  204. package/dist/engines/pi/session-control.js +604 -0
  205. package/dist/engines/pi/sessions.d.ts +17 -2
  206. package/dist/engines/pi/sessions.js +9 -0
  207. package/dist/engines/pi/tool-context.d.ts +18 -11
  208. package/dist/engines/pi/tool-context.js +3 -9
  209. package/dist/engines/pi/tool.d.ts +6 -8
  210. package/dist/engines/pi/tool.js +10 -1
  211. package/dist/engines/pi/wake-tool.d.ts +0 -3
  212. package/dist/engines/pi/wake-tool.js +9 -7
  213. package/dist/env.d.ts +16 -4
  214. package/dist/env.js +43 -5
  215. package/dist/feishu.d.ts +1 -1
  216. package/dist/feishu.js +1 -1
  217. package/dist/host/node.d.ts +25 -8
  218. package/dist/host/node.js +5 -4
  219. package/dist/index.d.ts +1 -0
  220. package/dist/index.js +1 -0
  221. package/dist/lark.d.ts +1 -1
  222. package/dist/lark.js +1 -1
  223. package/dist/loader.d.ts +2 -2
  224. package/dist/loader.js +3 -3
  225. package/dist/log.d.ts +1 -1
  226. package/dist/log.js +1 -1
  227. package/dist/observe.js +3 -0
  228. package/dist/paths.d.ts +138 -0
  229. package/dist/paths.js +326 -0
  230. package/dist/pi.d.ts +6 -5
  231. package/dist/pi.js +4 -3
  232. package/dist/runtime.d.ts +7 -5
  233. package/dist/runtime.js +2 -2
  234. package/dist/scaffold/add-channel.d.ts +26 -9
  235. package/dist/scaffold/add-channel.js +175 -40
  236. package/dist/scaffold/init.d.ts +32 -41
  237. package/dist/scaffold/init.js +161 -185
  238. package/dist/scaffold/templates/env.example +15 -6
  239. package/dist/scaffold/templates/fastagent.config.mjs +5 -4
  240. package/dist/scaffold/templates/gitignore +14 -6
  241. package/dist/scaffold/templates/persona.md +4 -2
  242. package/dist/scaffold/templates/secrets.gitignore +5 -0
  243. package/dist/scaffold/templates.d.ts +1 -7
  244. package/dist/scaffold/templates.js +3 -25
  245. package/dist/scaffold/vendor-skill.d.ts +2 -2
  246. package/dist/scaffold/vendor-skill.js +13 -13
  247. package/dist/schedule/discover.js +4 -4
  248. package/dist/schedule/scheduler.d.ts +40 -1
  249. package/dist/schedule/scheduler.js +89 -56
  250. package/dist/schedule/state.js +1 -1
  251. package/dist/schedule/wake-alarm.d.ts +47 -0
  252. package/dist/schedule/wake-alarm.js +136 -0
  253. package/dist/schedule/wakeups.d.ts +1 -3
  254. package/dist/schedule/wakeups.js +19 -1
  255. package/dist/session-remote.d.ts +53 -0
  256. package/dist/session-remote.js +336 -0
  257. package/dist/session.d.ts +265 -0
  258. package/dist/session.js +37 -0
  259. package/dist/slack.d.ts +2 -0
  260. package/dist/slack.js +2 -0
  261. package/dist/tunnel.d.ts +7 -4
  262. package/dist/tunnel.js +23 -12
  263. package/package.json +22 -7
  264. package/dist/channels/feishu/owned-threads.d.ts +0 -11
  265. package/dist/channels/feishu/owned-threads.js +0 -47
  266. package/dist/channels/feishu/seen.d.ts +0 -5
  267. package/dist/channels/feishu/seen.js +0 -47
  268. package/dist/cli-add-feishu.d.ts +0 -8
  269. package/dist/cli-add-feishu.js +0 -223
  270. package/dist/cli-models.d.ts +0 -11
  271. package/dist/cli-models.js +0 -20
  272. package/dist/engines/pi/workspace.d.ts +0 -56
  273. package/dist/engines/pi/workspace.js +0 -72
  274. package/dist/scaffold/templates/gitignore.agentdir-root +0 -5
  275. package/dist/scaffold/templates/gitignore.kit +0 -2
  276. package/dist/workspace.d.ts +0 -9
  277. package/dist/workspace.js +0 -45
@@ -8,14 +8,18 @@ import { fastagentVersion } from "../version.js";
8
8
  import { buildProgram } from "./kernel.js";
9
9
  // Help groups (clig: most common commands first) — the authoring loop leads, operations close.
10
10
  // Shared flags — same name, same meaning, on every command that supports them (clig: consistency).
11
- const DIR_ARG = { name: "[dir]", description: "workspace directory", default: "." };
11
+ const DIR_ARG = {
12
+ name: "[dir]",
13
+ description: "workspace directory (the agent is here, or in a directory inside it)",
14
+ default: ".",
15
+ };
12
16
  const MODEL = {
13
17
  flags: "--model <provider/modelId>",
14
18
  description: "model override (precedence: --model > FASTAGENT_MODEL > config)",
15
19
  };
16
20
  const AUTH_PATH = {
17
21
  flags: "--auth-path <file>",
18
- description: "credentials file (default: <state root>/auth.json; env: FASTAGENT_AUTH_PATH)",
22
+ description: "credentials file (default: <agent dir>/.secrets/auth.json; env: FASTAGENT_AUTH_PATH)",
19
23
  };
20
24
  const JSON_FLAG = { flags: "--json", description: "machine-readable JSON output" };
21
25
  const NO_INPUT = {
@@ -26,37 +30,49 @@ const PORT = { flags: "--port <n>", description: "HTTP port" };
26
30
  const TUNNEL = {
27
31
  flags: "--tunnel",
28
32
  description: "expose a public HTTPS URL via a Cloudflare quick tunnel (needs cloudflared) and auto-register " +
29
- "webhook channels (telegram, feishu, lark; github prints the URL) — for hosting a bot from your " +
33
+ "webhook channels (telegram, onboarded slack, feishu, lark; github/manual slack print the URL) — for hosting a bot from your " +
30
34
  "own box without deploying (the quick-tunnel URL is ephemeral, not for production)",
31
35
  };
32
36
  const init = {
33
37
  name: "init",
34
38
  summary: "scaffold a runnable agent and install its dependencies",
35
- description: "Scaffold a runnable agent in dir (default .) and run npm install. Default is a self-iterating " +
36
- "agent: persona.md (its identity), a writing-great-skills example skill, a fetch-url code tool, " +
37
- "config, package.json, .gitignore. Never overwrites existing files; an existing AGENTS.md is kept " +
38
- "as project context.",
39
+ description: "Scaffold a runnable agent and run npm install. By default the agent goes into ./fastagent/ in dir " +
40
+ "(default .; --agent-dir names it otherwise) the rest of the directory gets zero writes, and it is " +
41
+ "the WORKSPACE the agent works ON when you point fastagent there. Default content is a " +
42
+ "self-iterating agent: persona.md (its identity), a writing-great-skills " +
43
+ "example skill, a fetch-url code tool, config, package.json, .gitignore. An existing AGENTS.md is " +
44
+ "kept as project context.",
39
45
  args: [DIR_ARG],
40
46
  flags: [
41
47
  { flags: "--minimal", description: "persona.md + the example skill + config only (no code tool / package.json)" },
42
48
  { flags: "--no-install", description: "scaffold everything but skip npm install" },
43
- { flags: "--flat", description: "force the flat layout (skip host-signal detection)", conflicts: ["agentDir"] },
44
- { flags: "--agent-dir <name>", description: "force the agent kit into ./<name>" },
49
+ { flags: "--agent-dir <name>", description: "name the agent directory (default fastagent; . = dir itself)" },
50
+ {
51
+ flags: "--flat",
52
+ description: "alias for --agent-dir . — the directory IS the agent; keeps existing files",
53
+ // Two spellings of ONE knob: `--flat --agent-dir bot` names the same thing twice with different
54
+ // values, which is a usage error, not a precedence question to settle silently.
55
+ conflicts: ["agentDir"],
56
+ },
45
57
  ],
46
58
  examples: [
47
- { cmd: "fastagent init my-agent", note: "a new agent dir, ready to dev" },
48
- { cmd: "fastagent init", note: "initialize the current directory" },
59
+ { cmd: "fastagent init", note: "the agent lands in ./fastagent/" },
60
+ { cmd: "fastagent init my-project", note: "my-project/fastagent/ (created)" },
61
+ { cmd: "fastagent init . --agent-dir bot", note: "./bot/ — any name works" },
62
+ { cmd: "fastagent init . --flat", note: "this repo IS the agent" },
49
63
  ],
50
- notes: 'Layout: flat by default ("a directory is an agent"); when an existing toolchain/deploy claims ' +
51
- "the directory (tsconfig/framework config, a non-JS build manifest like " +
52
- "go.mod/pyproject.toml/Cargo.toml, Dockerfile/fly/railway, or occupied tools/, channels/, or " +
53
- "skills/), the kit goes into ./agent and config.agentDir points there the reason is printed, " +
54
- "no prompt.",
64
+ notes: "An agent is a directory holding a fastagent.config.* never its NAME, so --agent-dir can call it " +
65
+ "anything (the name decides only which agent answers when a workspace holds several: see " +
66
+ "FASTAGENT_AGENT). What the agent works ON (its cwd, where its AGENTS.md context is read from) is " +
67
+ "whatever directory you later point fastagent at: point at the project and the agent inside it " +
68
+ "serves with the project as its workspace; point at the agent directory (all a deployed box may " +
69
+ "hold) and it works on itself. A directory resolves to ONE agent, at it or one level inside.",
55
70
  run: async (args, f) => (await import("./commands/init.js")).runInit(args[0], {
56
71
  minimal: f.minimal === true,
57
72
  install: f.install !== false,
58
- flat: f.flat === true,
59
- agentDir: f.agentDir,
73
+ // `--flat` is the spelling for the common case of the same knob (they conflict, so only one is
74
+ // ever set); both land in ONE value, so the scaffolder never sees two ways to say ".".
75
+ agentDir: f.flat === true ? "." : typeof f.agentDir === "string" ? f.agentDir : undefined,
60
76
  }),
61
77
  };
62
78
  const dev = {
@@ -64,8 +80,8 @@ const dev = {
64
80
  summary: "serve the agent locally, restarting on code edits",
65
81
  description: "Assemble the agent in dir (default .) and serve a local HTTP channel. persona.md/AGENTS.md/skills " +
66
82
  "are re-read every turn (edits go live next turn); edits to code inputs — tools/, channels/, " +
67
- "fastagent.config.*, package.json, .env — restart the worker. Files the agent writes as work " +
68
- "product never trigger a restart.",
83
+ "fastagent.config.*, package.json, .secrets/.env — restart the worker. Files the agent writes as " +
84
+ "work product never trigger a restart.",
69
85
  args: [DIR_ARG],
70
86
  flags: [
71
87
  PORT,
@@ -77,7 +93,7 @@ const dev = {
77
93
  ],
78
94
  examples: [
79
95
  { cmd: "fastagent dev" },
80
- { cmd: "fastagent dev --tunnel", note: "public URL + auto-registered webhooks" },
96
+ { cmd: "fastagent dev --tunnel", note: "public URL + registered/guided webhooks" },
81
97
  ],
82
98
  run: async (args, f) => (await import("./commands/dev.js")).runDev(args[0], {
83
99
  port: f.port,
@@ -88,16 +104,38 @@ const dev = {
88
104
  input: f.input !== false,
89
105
  }),
90
106
  };
107
+ const attach = {
108
+ name: "attach",
109
+ summary: "watch a session's live events from a running serve and steer it",
110
+ description: "Attach to a session served by a running dev/start with `sessionControl: true` in the config: " +
111
+ "stream its live events (text, tools, run boundaries), steer the active run by typing — or, with " +
112
+ "no run active, start one (detaching cancels a run YOU started) — /abort to stop a run. Discovers " +
113
+ "the local endpoint from <stateRoot>/control.json; --url/--token reach a remote serve. The same " +
114
+ "wire protocol a Web panel or desktop app uses.",
115
+ args: [{ name: "<session>", description: "the session id to attach to" }, DIR_ARG],
116
+ flags: [
117
+ { flags: "--url <url>", description: "control endpoint (skip control.json discovery)" },
118
+ { flags: "--token <token>", description: "bearer token for --url" },
119
+ ],
120
+ examples: [{ cmd: "fastagent attach tg-chat-42" }],
121
+ run: async (args, f) => (await import("./commands/attach.js")).runAttach(args[0], args[1], {
122
+ url: f.url,
123
+ token: f.token,
124
+ }),
125
+ };
91
126
  const chat = {
92
127
  name: "chat",
93
128
  summary: "open the SAME assembled agent in pi's interactive TUI",
94
129
  description: "Open the SAME assembled agent in pi's interactive TUI (the real harness, not a crude REPL) — to " +
95
- "try it locally before serving. Same model/tool/skill resolution as dev; pi handles login, " +
96
- "sessions, and /resume natively.",
130
+ "try it locally before serving. Same model/tool/skill/auth resolution as dev; pi handles " +
131
+ "rendering, sessions, and /resume natively (its /login writes to the same fastagent auth file).",
97
132
  args: [DIR_ARG],
98
- flags: [MODEL],
133
+ flags: [MODEL, AUTH_PATH],
99
134
  examples: [{ cmd: "fastagent chat" }],
100
- run: async (args, f) => (await import("./commands/chat.js")).runChat(args[0], { model: f.model }),
135
+ run: async (args, f) => (await import("./commands/chat.js")).runChat(args[0], {
136
+ model: f.model,
137
+ authPath: f.authPath,
138
+ }),
101
139
  };
102
140
  const info = {
103
141
  name: "info",
@@ -192,14 +230,14 @@ const start = {
192
230
  ],
193
231
  notes: "Precedence chains:\n" +
194
232
  " port: --port > PORT env > fastagent.config.ts http.port > 8787\n" +
195
- " state: FASTAGENT_STATE_DIR > <dir>/.fastagentthe ONE machine-state\n" +
196
- " root (auth, sessions, channel state all derive from it); point\n" +
197
- " it at a mounted volume so a redeploy that replaces the\n" +
198
- " directory never wipes state\n" +
233
+ " state: FASTAGENT_STATE_DIR > <agent dir>/.statemutable machine state\n" +
234
+ " (sessions, channel state, schedule state); point it at a mounted\n" +
235
+ " volume so a redeploy that replaces the directory never wipes it\n" +
236
+ " secrets: FASTAGENT_SECRETS_DIR > <agent dir>/.secrets — .env + auth.json\n" +
199
237
  " sessions: --sessions-dir > FASTAGENT_SESSIONS_DIR > <state>/sessions\n" +
200
- " auth: --auth-path > FASTAGENT_AUTH_PATH > <state>/auth.json\n" +
201
- " (project-level; point it at ~/.fastagent/auth.json to share one\n" +
202
- " credential across projects)",
238
+ " auth: --auth-path > FASTAGENT_AUTH_PATH > <secrets>/auth.json\n" +
239
+ " (project-level; point it at ~/.fastagent/.secrets/auth.json to\n" +
240
+ " share one credential across projects)",
203
241
  run: async (args, f) => (await import("./commands/start.js")).runStart(args[0], {
204
242
  port: f.port,
205
243
  model: f.model,
@@ -211,37 +249,70 @@ const start = {
211
249
  };
212
250
  /** The retired app-creation flag — parsed so it can explain itself, hidden from help. */
213
251
  const CREATE_APP = { flags: "--create-app", description: "(retired)", hidden: true };
252
+ const INGRESS = {
253
+ flags: "--ingress <mode>",
254
+ description: "Feishu/Lark ingress: websocket or webhook (interactive when omitted)",
255
+ };
256
+ const GROUP_BEHAVIOR = {
257
+ flags: "--group-behavior <behavior>",
258
+ description: "Slack/Feishu/Lark groups: context (recommended) or mentions (least privilege)",
259
+ };
260
+ const NO_ONBOARD = {
261
+ flags: "--no-onboard",
262
+ description: "Slack: scaffold only; skip internal-app creation/OAuth",
263
+ };
264
+ const REPLACE_CONFIG = {
265
+ flags: "--replace-config",
266
+ description: "Slack: replace the local App Configuration token pair (repairs automatic dev/deploy Request URL " +
267
+ "updates after the tokens expire or are revoked; runs on the machine that onboarded the app)",
268
+ };
214
269
  const channelSub = (kind, summary, description, notes) => ({
215
270
  name: kind,
216
271
  summary,
217
272
  description,
218
273
  args: [DIR_ARG],
219
- flags: [CREATE_APP],
274
+ flags: [
275
+ CREATE_APP,
276
+ ...(kind === "feishu" || kind === "lark"
277
+ ? [INGRESS, GROUP_BEHAVIOR]
278
+ : kind === "slack"
279
+ ? [GROUP_BEHAVIOR, NO_ONBOARD, REPLACE_CONFIG]
280
+ : []),
281
+ ],
220
282
  examples: [{ cmd: `fastagent add ${kind}` }],
221
283
  ...(notes ? { notes } : {}),
222
- run: async (args, f) => (await import("./commands/add.js")).runAddChannel(kind, args[0], { createApp: f.createApp === true }),
284
+ run: async (args, f) => (await import("./commands/add.js")).runAddChannel(kind, args[0], {
285
+ createApp: f.createApp === true,
286
+ ingress: f.ingress,
287
+ groupBehavior: f.groupBehavior,
288
+ onboard: f.onboard !== false,
289
+ replaceConfig: f.replaceConfig === true,
290
+ }),
223
291
  });
224
292
  const add = {
225
293
  name: "add",
226
- summary: "connect a channel (github, telegram, feishu, lark) or vendor a skill",
227
- description: "Scaffold channels/<kind>.ts — third-party adapter glue with the policy to edit (github maps " +
228
- "events in on(); telegram/feishu/lark route in the optional route()) — or vendor an Agent Skills " +
294
+ summary: "connect a channel (github, telegram, slack, feishu, lark) or vendor a skill",
295
+ description: "Scaffold channels/<kind>.ts — first-party adapter glue with the policy to edit (github maps " +
296
+ "events in on(); telegram/slack/feishu/lark route in the optional route()) — or vendor an Agent Skills " +
229
297
  "skill into skills/<name>/.",
230
298
  subcommands: [
231
299
  channelSub("github", "scaffold the GitHub webhook channel (issues/PRs → agent turns)", "Scaffold channels/github.ts — webhook adapter glue that maps repository events (issues, PRs, " +
232
300
  "comments) to agent turns in its on() policy."),
233
301
  channelSub("telegram", "scaffold the Telegram bot channel (durable turns, live preview)", "Scaffold channels/telegram.ts — the Telegram bot channel with durable turns, a live-preview " +
234
302
  "message pump, and an optional route() policy."),
235
- channelSub("feishu", "scaffold the Feishu channel AND create/configure the platform app", "Scaffold channels/feishu.ts AND create/configure the Feishu platform app (scan-to-create), " +
236
- "writing credentials to .env.", "Feishu (open.feishu.cn) is the canonical implementation. `add feishu` also CREATES + " +
237
- 'configures the platform app (confirm a link in the app the platform\'s "scan to create" ' +
238
- "flow; one version-publish action remains) and writes credentials to .env; a persisted " +
239
- "ID/Secret pair resumes missing-Token setup instead of creating another app."),
240
- channelSub("lark", "scaffold the Lark (international) channel with guided credential setup", "Scaffold channels/lark.ts the Lark international profile over the Feishu engine — and guide " +
241
- "credential setup against the intl developer console.", "Lark international (open.larksuite.com) is Feishu's compatibility profile with degraded " +
242
- "control-plane setup: opens the intl developer console only for a new/partial pair, validates " +
243
- "App ID/Secret, then probes webhook-mode + Token automation; an explicit config-route 404 " +
244
- "falls back to a hidden Token prompt + manual mode/URL setup."),
303
+ channelSub("slack", "scaffold the Slack Events API channel (files, threads, context, live preview)", "Choose group visibility, scaffold channels/slack.ts plus slack-send.ts, create a single-workspace " +
304
+ "internal Slack app from a manifest, and install it through OAuth. The channel provides signed " +
305
+ "Events API ingress, durable turns, files, threads, context, and an edited live preview.", "Automated onboarding requires Slack App Configuration access + refresh tokens and a temporary " +
306
+ "cloudflared tunnel. They stay in owner-readable local state and are never deployed; --no-onboard " +
307
+ "keeps the explicit manual/scaffold-only path."),
308
+ channelSub("feishu", "scaffold the Feishu channel AND create/configure the platform app", "Choose WebSocket or webhook, scaffold channels/feishu.ts, and create/configure the Feishu app " +
309
+ "through scan-to-create, writing the matching credentials to .env.", "Feishu (open.feishu.cn) is the canonical implementation. WebSocket needs only App ID/Secret and " +
310
+ "no public URL; webhook additionally captures the Verification Token through a temporary tunnel. " +
311
+ "Context-aware groups (recommended) request admin approval for im:message.group_msg before publish."),
312
+ channelSub("lark", "scaffold the Lark (international) channel with guided credential setup", "Choose WebSocket or webhook, scaffold channels/lark.ts, and guide credential setup against the " +
313
+ "international developer console.", "Lark international (open.larksuite.com) is Feishu's compatibility profile. WebSocket stops after " +
314
+ "App ID/Secret validation; webhook and recommended context-aware group setup probe config " +
315
+ "automation and fall back to explicit manual steps on the international config-route 404."),
245
316
  {
246
317
  name: "skill",
247
318
  summary: "vendor an Agent Skills skill into skills/<name>/ (copied in, git-tracked)",
@@ -269,19 +340,22 @@ const add = {
269
340
  };
270
341
  const deploy = {
271
342
  name: "deploy",
272
- summary: "generate deploy artifacts + a runbook for docker, fly, or railway (--run drives it)",
343
+ summary: "generate deploy artifacts + a runbook for docker, fly, railway, or agentcore (--run drives it)",
273
344
  description: "Generate Dockerfile/.dockerignore plus the target config and print an ordered runbook. " +
274
345
  "docker: fastagent.compose.yml, loopback port, persistent state volume. fly: fly.toml " +
275
346
  "(autostop=suspend, state→volume). railway: railway.json (healthcheck /health); its " +
276
- "volume/variables/App-Sleeping are dashboard/CLI steps the runbook states. Durable ingress " +
277
- "remains operator-owned.",
278
- args: [{ name: "<host>", description: "deploy target", choices: ["docker", "fly", "railway"] }, DIR_ARG],
347
+ "volume/variables/App-Sleeping are dashboard/CLI steps the runbook states. agentcore: one " +
348
+ "CloudFormation stack (AWS Bedrock AgentCore Runtime + forwarder Lambda for webhooks + " +
349
+ "EventBridge rules for schedules; linux/arm64 image built locally). Durable ingress " +
350
+ "remains operator-owned (agentcore's forwarder URL is the exception — the stack owns it).",
351
+ args: [{ name: "<host>", description: "deploy target", choices: ["docker", "fly", "railway", "agentcore"] }, DIR_ARG],
279
352
  flags: [
280
353
  {
281
354
  flags: "--run",
282
355
  description: "drive the target CLI to completion. Docker runs `docker compose up -d --build`; with a tunnel " +
283
356
  "service, reads its URL and registers webhooks. Fly/Railway provision app/service + volume + " +
284
- "secrets + deploy + webhook setup. Carries your local credential (env key or OAuth auth.json). " +
357
+ "secrets + deploy + webhook setup. AgentCore builds/pushes the arm64 image and deploys the " +
358
+ "stack (aws + docker CLIs). Carries your local credential (env key or OAuth auth.json). " +
285
359
  "Stops at a gate (missing CLI/daemon/login/secret) with one actionable line. Without it: prints " +
286
360
  "the runbook",
287
361
  },
@@ -306,11 +380,13 @@ const deploy = {
306
380
  },
307
381
  MODEL,
308
382
  AUTH_PATH,
383
+ NO_INPUT,
309
384
  ],
310
385
  examples: [
311
386
  { cmd: "fastagent deploy fly --run", note: "provision + deploy + webhooks" },
312
387
  { cmd: "fastagent deploy docker --tunnel --run", note: "Compose + a public URL" },
313
388
  { cmd: "fastagent deploy railway", note: "print the runbook only" },
389
+ { cmd: "fastagent deploy agentcore --run", note: "arm64 image + stack + webhooks" },
314
390
  ],
315
391
  notes: "Definition-read-only: the only writes are generated artifacts (never clobbered without " +
316
392
  "--force). A routine redeploy of an already-provisioned agent is just the host's own command " +
@@ -324,6 +400,7 @@ const deploy = {
324
400
  intoLinked: f.intoLinked === true,
325
401
  model: f.model,
326
402
  authPath: f.authPath,
403
+ input: f.input !== false,
327
404
  }),
328
405
  };
329
406
  const schedule = {
@@ -370,10 +447,11 @@ const schedule = {
370
447
  const login = {
371
448
  name: "login",
372
449
  summary: "authenticate a model provider (subscription/OAuth or API key)",
373
- description: "Authenticate a model provider into the project-level <state root>/auth.json default " +
374
- "<cwd>/.fastagent/auth.json (run from $HOME for the global ~/.fastagent/auth.json): pick a method " +
375
- "(subscription/OAuth or API key), then a provider that offers it (configured status shown). " +
376
- "[provider] takes the method from what that provider supports, asked only when both.",
450
+ description: "Authenticate a model provider into the project-level <agent dir>/.secrets/auth.json (outside an " +
451
+ "agent it writes the global ~/.fastagent/.secrets/auth.json, and says so): pick a method " +
452
+ "(subscription/OAuth or API " +
453
+ "key), then a provider that offers it (configured status shown). [provider] takes the method from " +
454
+ "what that provider supports, asked only when both.",
377
455
  args: [{ name: "[provider]", description: "provider id (skip the provider menu)" }],
378
456
  flags: [AUTH_PATH, NO_INPUT],
379
457
  examples: [{ cmd: "fastagent login" }, { cmd: "fastagent login openai" }],
@@ -395,6 +473,7 @@ export const specs = [
395
473
  schedule,
396
474
  dev,
397
475
  chat,
476
+ attach,
398
477
  start,
399
478
  add,
400
479
  deploy,
@@ -1,28 +1,68 @@
1
- /**
2
- * The serving spine shared by `dev` (its worker) and `start`: route assembly from discovered
3
- * channels/, the Node host binding, the scheduler lifecycle, and the optional Cloudflare quick
4
- * tunnel. Bodies moved verbatim from cli.ts; `values.tunnel` became a parameter.
5
- */
6
1
  import type { Agent } from "../agent.ts";
2
+ import { type LoadedLongConnectionChannel } from "../engines/pi/channel.ts";
7
3
  import { type Routes } from "../host/node.ts";
4
+ import type { LoadedSchedule } from "../schedule/schedule.ts";
5
+ import type { SessionControl } from "../session.ts";
6
+ export interface ServingSurface {
7
+ routes: Routes;
8
+ longConnections: LoadedLongConnectionChannel[];
9
+ /** Route-channel basenames; the tunnel registers only this subset. */
10
+ routeChannels: string[];
11
+ builtinInvoke: boolean;
12
+ /** Marks the built-in health route ready after every long-connection channel first connects. */
13
+ markReady(): void;
14
+ }
15
+ /**
16
+ * The surface this deployment serves: default `GET /health` plus discovered channels, or the default
17
+ * POST `/invoke` only when neither a route nor a long-connection channel was declared.
18
+ */
19
+ export declare function routesFor(agentDir: string, agent: Agent, stateRoot: string, control?: SessionControl, options?: {
20
+ builtinInvoke?: boolean;
21
+ }): Promise<ServingSurface>;
22
+ /**
23
+ * Mount the session control plane (`/control/*`) when the agent enabled it
24
+ * (`config.sessionControl`): merge the bearer-authenticated routes and return an announcer that
25
+ * writes `<stateRoot>/control.json` — `{ url, token }`, 0600 — once the port is known. The file is
26
+ * the LOCAL discovery channel (`fastagent attach`, a local desktop app); filesystem permissions are
27
+ * its trust boundary, and each boot overwrites it with a fresh per-boot token. A user channel
28
+ * colliding on `/control/*` fails startup — the same disposition as a channel-channel collision
29
+ * (routesFor): `sessionControl` is an explicit opt-in, so declaring both is a configuration error,
30
+ * and silently shadowing either side would serve a surface the author didn't write.
31
+ */
32
+ export declare function mountSessionControl(routes: Routes, control: SessionControl | undefined, stateRoot: string, options?: {
33
+ tunnel?: boolean;
34
+ agent?: Agent;
35
+ }): {
36
+ routes: Routes;
37
+ announce: (boundPort: number) => void;
38
+ };
8
39
  /**
9
- * The routes this deployment serves: a default `GET /health` plus the workspace's discovered
10
- * `channels/` — or the default invoke channel at POST /invoke when none are declared.
40
+ * Mount the AgentCore Runtime adapter (`POST /invocations` + `GET /ping`) over the serving routes —
41
+ * the deployed container's ONLY reachable surface (channels/agentcore.ts). Wired by `start` when
42
+ * `FASTAGENT_AGENTCORE=1` (set by the generated deploy artifacts, never by hand). A channel colliding
43
+ * on either path fails startup, same disposition as the control-plane mount: the adapter's paths are
44
+ * the platform's contract, so a channel shadowing them would silently unserve the whole deployment.
11
45
  */
12
- export declare function routesFor(workspaceDir: string, agent: Agent, stateRoot: string): Promise<Routes>;
13
- /** Serve `routes` via the Node host. serveNode owns binding; the CLI owns policy (errors, ready signal, log). */
14
- export declare function serve(routes: Routes, port: number, onListening?: (boundPort: number) => void): void;
46
+ export declare function mountAgentcore(routes: Routes, options: {
47
+ agent: Agent;
48
+ stateRoot: string;
49
+ schedules: LoadedSchedule[];
50
+ onStateReady?: () => void;
51
+ }): Routes;
15
52
  /**
16
- * Start a Cloudflare tunnel + announce/register webhooks once the server is bound unless this is a
17
- * watch-supervisor worker, where the supervisor owns the long-lived tunnel so the public URL survives
18
- * reloads.
53
+ * Bind HTTP, open long-connection channels, and report ready only when both forms are usable. Each
54
+ * adapter owns reconnects; a terminal close rejects `closed` and fails the process visibly. Abort is
55
+ * the sole clean-shutdown command.
19
56
  */
20
- export declare function maybeTunnel(workspaceDir: string, boundPort: number, tunnel: boolean): void;
57
+ export declare function serve(surface: ServingSurface, port: number, onListening?: (boundPort: number) => void): void;
58
+ /** Start a Cloudflare tunnel for route channels only. */
59
+ export declare function maybeTunnel(agentDir: string, routeChannels: string[], boundPort: number, tunnel: boolean, stateRoot?: string): void;
21
60
  /**
22
- * Load and start the workspace's `schedules/` — a time-trigger firing the agent on each cron. Starts iff
23
- * there are static schedules OR `selfSchedule` is on (the scheduler also polls the agent's self-scheduled
24
- * wake-ups, which the built-in `wake` tool creates only when opted in). Shares the SAME (trace-wrapped)
25
- * agent the routes serve, so a scheduled turn is observed like any other. Best-effort stop on exit; dev's
26
- * watch restart re-reads schedules with the worker (schedules are a code input). Single-process.
61
+ * Load and start the agent's `schedules/` — a time-trigger firing the agent on each cron. Starts iff
62
+ * there are static schedules OR `selfSchedule` is on. Best-effort stop on process signals. Returns the
63
+ * loaded schedules so a serving surface that needs them (the AgentCore adapter's fire binding) shares
64
+ * ONE load instead of re-discovering. `externalClock` (AgentCore) arms no resident cron timers.
27
65
  */
28
- export declare function startSchedules(workspaceDir: string, agent: Agent, stateRoot: string, selfSchedule: boolean): Promise<void>;
66
+ export declare function startSchedules(agentDir: string, agent: Agent, stateRoot: string, selfSchedule: boolean, options?: {
67
+ externalClock?: boolean;
68
+ }): Promise<LoadedSchedule[]>;