@fastagent-sh/fastagent 0.14.0 → 0.15.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 (209) hide show
  1. package/README.md +3 -3
  2. package/dist/agent.d.ts +20 -0
  3. package/dist/agent.js +9 -0
  4. package/dist/channels/context-buffer.d.ts +30 -0
  5. package/dist/channels/context-buffer.js +98 -0
  6. package/dist/channels/control.d.ts +28 -0
  7. package/dist/channels/control.js +214 -0
  8. package/dist/channels/feishu/card.js +1 -1
  9. package/dist/channels/feishu/context-buffer.d.ts +8 -11
  10. package/dist/channels/feishu/context-buffer.js +6 -67
  11. package/dist/channels/feishu/feishu-api.d.ts +11 -3
  12. package/dist/channels/feishu/feishu-api.js +20 -2
  13. package/dist/channels/feishu/feishu.d.ts +28 -16
  14. package/dist/channels/feishu/feishu.js +210 -188
  15. package/dist/channels/feishu/invoke-turn.d.ts +7 -20
  16. package/dist/channels/feishu/invoke-turn.js +10 -62
  17. package/dist/channels/feishu/model.d.ts +2 -1
  18. package/dist/channels/feishu/normalize.d.ts +2 -1
  19. package/dist/channels/feishu/owned-threads.d.ts +2 -6
  20. package/dist/channels/feishu/parse.d.ts +1 -1
  21. package/dist/channels/feishu/preview.d.ts +4 -7
  22. package/dist/channels/feishu/preview.js +24 -140
  23. package/dist/channels/feishu/register-app.d.ts +2 -1
  24. package/dist/channels/feishu/register-webhook.d.ts +2 -1
  25. package/dist/channels/feishu/setup-mode.d.ts +8 -0
  26. package/dist/channels/feishu/setup-mode.js +2 -0
  27. package/dist/channels/feishu/ws-ingress.d.ts +28 -0
  28. package/dist/channels/feishu/ws-ingress.js +136 -0
  29. package/dist/channels/github/github.js +8 -6
  30. package/dist/channels/http.d.ts +14 -0
  31. package/dist/channels/http.js +35 -2
  32. package/dist/channels/invoke-turn-kit.d.ts +65 -0
  33. package/dist/channels/invoke-turn-kit.js +87 -0
  34. package/dist/channels/lark/lark.d.ts +4 -2
  35. package/dist/channels/lark/lark.js +4 -1
  36. package/dist/channels/lark/onboard.d.ts +8 -4
  37. package/dist/channels/lark/onboard.js +8 -0
  38. package/dist/channels/preview-kit.d.ts +109 -0
  39. package/dist/channels/preview-kit.js +183 -0
  40. package/dist/channels/seen.d.ts +5 -0
  41. package/dist/channels/seen.js +35 -0
  42. package/dist/channels/slack/bot-auth.d.ts +15 -0
  43. package/dist/channels/slack/bot-auth.js +146 -0
  44. package/dist/channels/slack/config-api.d.ts +60 -0
  45. package/dist/channels/slack/config-api.js +149 -0
  46. package/dist/channels/slack/context-buffer.d.ts +24 -0
  47. package/dist/channels/slack/context-buffer.js +37 -0
  48. package/dist/channels/slack/invoke-turn.d.ts +19 -0
  49. package/dist/channels/slack/invoke-turn.js +63 -0
  50. package/dist/channels/slack/manifest.d.ts +49 -0
  51. package/dist/channels/slack/manifest.js +69 -0
  52. package/dist/channels/slack/model.d.ts +67 -0
  53. package/dist/channels/slack/model.js +2 -0
  54. package/dist/channels/slack/onboard.d.ts +41 -0
  55. package/dist/channels/slack/onboard.js +120 -0
  56. package/dist/channels/slack/onboarding-state.d.ts +31 -0
  57. package/dist/channels/slack/onboarding-state.js +69 -0
  58. package/dist/channels/slack/owned-threads.d.ts +6 -0
  59. package/dist/channels/slack/owned-threads.js +43 -0
  60. package/dist/channels/slack/parse.d.ts +23 -0
  61. package/dist/channels/slack/parse.js +81 -0
  62. package/dist/channels/slack/preview.d.ts +24 -0
  63. package/dist/channels/slack/preview.js +359 -0
  64. package/dist/channels/slack/reaction.d.ts +24 -0
  65. package/dist/channels/slack/reaction.js +62 -0
  66. package/dist/channels/slack/register-webhook.d.ts +10 -0
  67. package/dist/channels/slack/register-webhook.js +49 -0
  68. package/dist/channels/slack/scaffold/channel.ts +33 -0
  69. package/dist/channels/slack/scaffold/slack-send.ts +171 -0
  70. package/dist/channels/slack/setup-server.d.ts +17 -0
  71. package/dist/channels/slack/setup-server.js +103 -0
  72. package/dist/channels/slack/slack-api.d.ts +77 -0
  73. package/dist/channels/slack/slack-api.js +415 -0
  74. package/dist/channels/slack/slack.d.ts +58 -0
  75. package/dist/channels/slack/slack.js +451 -0
  76. package/dist/channels/slack/welcomed.d.ts +5 -0
  77. package/dist/channels/slack/welcomed.js +32 -0
  78. package/dist/channels/state.js +3 -3
  79. package/dist/channels/stop-command.d.ts +6 -0
  80. package/dist/channels/stop-command.js +36 -0
  81. package/dist/channels/tasks.d.ts +13 -0
  82. package/dist/channels/tasks.js +10 -0
  83. package/dist/channels/telegram/context-buffer.d.ts +8 -17
  84. package/dist/channels/telegram/context-buffer.js +6 -85
  85. package/dist/channels/telegram/invoke-turn.d.ts +5 -22
  86. package/dist/channels/telegram/invoke-turn.js +11 -58
  87. package/dist/channels/telegram/preview.d.ts +4 -7
  88. package/dist/channels/telegram/preview.js +24 -142
  89. package/dist/channels/telegram/telegram.js +23 -9
  90. package/dist/channels/{feishu/text.d.ts → text.d.ts} +1 -1
  91. package/dist/channels/{feishu/text.js → text.js} +1 -1
  92. package/dist/channels/turn-queue.js +1 -1
  93. package/dist/channels/turn-store.d.ts +1 -1
  94. package/dist/channels/turn-store.js +2 -3
  95. package/dist/cli/add-feishu.d.ts +27 -0
  96. package/dist/{cli-add-feishu.js → cli/add-feishu.js} +167 -44
  97. package/dist/cli/add-slack.d.ts +10 -0
  98. package/dist/cli/add-slack.js +204 -0
  99. package/dist/{cli-auth.d.ts → cli/auth-view.d.ts} +1 -1
  100. package/dist/{cli-auth.js → cli/auth-view.js} +1 -1
  101. package/dist/cli/commands/add.d.ts +4 -0
  102. package/dist/cli/commands/add.js +152 -20
  103. package/dist/cli/commands/attach.d.ts +82 -0
  104. package/dist/cli/commands/attach.js +559 -0
  105. package/dist/cli/commands/chat.d.ts +1 -0
  106. package/dist/cli/commands/chat.js +6 -1
  107. package/dist/cli/commands/deploy.d.ts +2 -0
  108. package/dist/cli/commands/deploy.js +78 -22
  109. package/dist/cli/commands/dev.js +11 -5
  110. package/dist/cli/commands/fire.js +3 -3
  111. package/dist/cli/commands/info.js +2 -2
  112. package/dist/cli/commands/invoke.js +2 -3
  113. package/dist/cli/commands/login.js +14 -25
  114. package/dist/cli/commands/models.js +1 -1
  115. package/dist/cli/commands/start.js +15 -8
  116. package/dist/cli/commands/tool.js +2 -1
  117. package/dist/cli/fail.d.ts +0 -2
  118. package/dist/cli/fail.js +1 -1
  119. package/dist/{invoke-stream.d.ts → cli/invoke-stream.d.ts} +1 -1
  120. package/dist/{invoke-stream.js → cli/invoke-stream.js} +4 -0
  121. package/dist/cli/kernel.d.ts +3 -2
  122. package/dist/cli/models-view.d.ts +21 -0
  123. package/dist/cli/models-view.js +66 -0
  124. package/dist/cli/program.js +79 -21
  125. package/dist/cli/serve.d.ts +38 -18
  126. package/dist/cli/serve.js +197 -39
  127. package/dist/cli/shared.d.ts +26 -6
  128. package/dist/cli/shared.js +163 -33
  129. package/dist/collect.d.ts +14 -3
  130. package/dist/collect.js +24 -0
  131. package/dist/core.d.ts +3 -1
  132. package/dist/core.js +2 -0
  133. package/dist/deploy/docker/plan.d.ts +2 -2
  134. package/dist/deploy/docker/plan.js +8 -6
  135. package/dist/deploy/fly/plan.d.ts +3 -1
  136. package/dist/deploy/fly/plan.js +12 -7
  137. package/dist/deploy/fly/run.d.ts +5 -4
  138. package/dist/deploy/fly/run.js +16 -5
  139. package/dist/deploy/preflight.d.ts +10 -4
  140. package/dist/deploy/preflight.js +53 -9
  141. package/dist/deploy/railway/plan.d.ts +3 -1
  142. package/dist/deploy/railway/plan.js +12 -4
  143. package/dist/deploy/railway/run.d.ts +5 -4
  144. package/dist/deploy/railway/run.js +15 -5
  145. package/dist/deploy/runner.d.ts +2 -1
  146. package/dist/deploy/secrets.d.ts +2 -1
  147. package/dist/deploy/secrets.js +23 -3
  148. package/dist/dev-supervisor.d.ts +0 -2
  149. package/dist/dev-supervisor.js +7 -3
  150. package/dist/engines/pi/channel.d.ts +22 -16
  151. package/dist/engines/pi/channel.js +90 -60
  152. package/dist/engines/pi/chat.d.ts +4 -16
  153. package/dist/engines/pi/chat.js +8 -261
  154. package/dist/engines/pi/config.d.ts +14 -9
  155. package/dist/engines/pi/config.js +33 -18
  156. package/dist/engines/pi/create.d.ts +22 -2
  157. package/dist/engines/pi/create.js +20 -14
  158. package/dist/engines/pi/harness.d.ts +49 -0
  159. package/dist/engines/pi/harness.js +90 -2
  160. package/dist/engines/pi/invoke.d.ts +55 -2
  161. package/dist/engines/pi/invoke.js +304 -19
  162. package/dist/engines/pi/login.d.ts +11 -0
  163. package/dist/engines/pi/login.js +16 -4
  164. package/dist/engines/pi/models.d.ts +56 -10
  165. package/dist/engines/pi/models.js +61 -23
  166. package/dist/engines/pi/session-builder.d.ts +16 -0
  167. package/dist/engines/pi/session-builder.js +308 -0
  168. package/dist/engines/pi/session-control.d.ts +50 -0
  169. package/dist/engines/pi/session-control.js +604 -0
  170. package/dist/engines/pi/sessions.d.ts +17 -2
  171. package/dist/engines/pi/sessions.js +9 -0
  172. package/dist/engines/pi/tool-context.d.ts +18 -11
  173. package/dist/engines/pi/tool-context.js +3 -9
  174. package/dist/engines/pi/tool.d.ts +6 -8
  175. package/dist/engines/pi/tool.js +6 -1
  176. package/dist/engines/pi/wake-tool.d.ts +0 -3
  177. package/dist/engines/pi/wake-tool.js +9 -7
  178. package/dist/engines/pi/workspace.d.ts +52 -0
  179. package/dist/engines/pi/workspace.js +72 -15
  180. package/dist/feishu.d.ts +1 -1
  181. package/dist/feishu.js +1 -1
  182. package/dist/host/node.d.ts +23 -6
  183. package/dist/host/node.js +5 -4
  184. package/dist/index.d.ts +1 -0
  185. package/dist/index.js +1 -0
  186. package/dist/lark.d.ts +1 -1
  187. package/dist/lark.js +1 -1
  188. package/dist/observe.js +3 -0
  189. package/dist/pi.d.ts +5 -4
  190. package/dist/pi.js +2 -1
  191. package/dist/scaffold/add-channel.d.ts +19 -6
  192. package/dist/scaffold/add-channel.js +126 -17
  193. package/dist/scaffold/templates/fastagent.config.mjs +4 -3
  194. package/dist/schedule/wakeups.d.ts +0 -3
  195. package/dist/schedule/wakeups.js +1 -1
  196. package/dist/session-remote.d.ts +53 -0
  197. package/dist/session-remote.js +336 -0
  198. package/dist/session.d.ts +265 -0
  199. package/dist/session.js +37 -0
  200. package/dist/slack.d.ts +2 -0
  201. package/dist/slack.js +2 -0
  202. package/dist/tunnel.d.ts +7 -4
  203. package/dist/tunnel.js +21 -10
  204. package/package.json +19 -7
  205. package/dist/channels/feishu/seen.d.ts +0 -5
  206. package/dist/channels/feishu/seen.js +0 -47
  207. package/dist/cli-add-feishu.d.ts +0 -8
  208. package/dist/cli-models.d.ts +0 -11
  209. package/dist/cli-models.js +0 -20
@@ -1,15 +1,20 @@
1
1
  /**
2
- * The per-turn context a tool's `execute` can read (beyond its abort signal): the SESSION the current
3
- * turn runs in. A `defineTool` tool is built ONCE and reused across sessions, so the session can't be a
4
- * closure it rides an AsyncLocalStorage set around the harness turn (invoke.ts) and read inside
5
- * `execute` (tool.ts). Undefined outside a turn (e.g. `fastagent tool`, which runs a tool with no
6
- * session). This is what lets a tool know which conversation it is in — the mechanism the agent's
7
- * self-scheduling `wake` tool needs to fire a later turn back into the SAME session.
8
- *
9
- * Only `session` lives here (a per-turn runtime value). Deploy-time ambients a tool closes over at
10
- * build time (e.g. a stateRoot) do NOT belong here — pass them via the tool's own closure.
2
+ * Per-turn capabilities shared by every FastAgent-defined tool. A tool is built once and reused across
3
+ * turns, so current cwd/session/activation bindings ride AsyncLocalStorage rather than definition
4
+ * closures. Deploy-time ambients a tool closes over at build time do NOT belong here.
11
5
  */
12
6
  import { AsyncLocalStorage } from "node:async_hooks";
7
+ import type { SessionTreeEntry } from "@earendil-works/pi-agent-core";
8
+ /** FastAgent's read-only port over the current conversation manager. Serving and chat adapt their
9
+ * different concrete session implementations to this one tool-runtime contract. */
10
+ export interface ReadonlySessionManager {
11
+ getSessionId(): string;
12
+ getHeader(): Promise<{
13
+ id: string;
14
+ timestamp: string;
15
+ }>;
16
+ getBranch(): Promise<SessionTreeEntry[]>;
17
+ }
13
18
  /**
14
19
  * The turn's tool-activation bridge — narrow closures over the CURRENT harness (invoke.ts builds it
15
20
  * per turn), so a loader tool can activate deferred tools mid-turn without tool.ts importing the
@@ -31,8 +36,10 @@ export interface ToolActivation {
31
36
  activate(names: string[]): Promise<string[]>;
32
37
  }
33
38
  export interface TurnContext {
34
- /** The session id of the current turn. */
35
- session: string;
39
+ /** Working directory for this execution. Falls back to process.cwd() only for an unbound direct call. */
40
+ cwd?: string;
41
+ /** Current conversation manager. Absent outside a FastAgent-managed agent turn. */
42
+ sessionManager?: ReadonlySessionManager;
36
43
  /** Tool activation for the current turn. Two producers, one consumer surface: invoke.ts bridges the
37
44
  * serving harness; chat.ts bridges pi's AgentSession (chat emulates deferral — same loader, same
38
45
  * semantics). Absent only outside any turn (a bare `fastagent tool` run). */
@@ -1,13 +1,7 @@
1
1
  /**
2
- * The per-turn context a tool's `execute` can read (beyond its abort signal): the SESSION the current
3
- * turn runs in. A `defineTool` tool is built ONCE and reused across sessions, so the session can't be a
4
- * closure it rides an AsyncLocalStorage set around the harness turn (invoke.ts) and read inside
5
- * `execute` (tool.ts). Undefined outside a turn (e.g. `fastagent tool`, which runs a tool with no
6
- * session). This is what lets a tool know which conversation it is in — the mechanism the agent's
7
- * self-scheduling `wake` tool needs to fire a later turn back into the SAME session.
8
- *
9
- * Only `session` lives here (a per-turn runtime value). Deploy-time ambients a tool closes over at
10
- * build time (e.g. a stateRoot) do NOT belong here — pass them via the tool's own closure.
2
+ * Per-turn capabilities shared by every FastAgent-defined tool. A tool is built once and reused across
3
+ * turns, so current cwd/session/activation bindings ride AsyncLocalStorage rather than definition
4
+ * closures. Deploy-time ambients a tool closes over at build time do NOT belong here.
11
5
  */
12
6
  import { AsyncLocalStorage } from "node:async_hooks";
13
7
  export const turnContext = new AsyncLocalStorage();
@@ -1,16 +1,14 @@
1
1
  import type { AgentTool } from "@earendil-works/pi-agent-core";
2
2
  import { z } from "zod";
3
3
  import { type ModuleLoadFailure } from "../../loader.ts";
4
- import { type ToolActivation } from "./tool-context.ts";
4
+ import { type ReadonlySessionManager, type ToolActivation } from "./tool-context.ts";
5
5
  export interface ToolContext {
6
+ /** Working directory for this execution. */
7
+ cwd: string;
6
8
  /** Abort signal for the current turn — honor it to cancel in-flight work on cancellation. */
7
9
  signal?: AbortSignal;
8
- /** The session id of the current turn which conversation this tool is running in. A general tool
9
- * capability: partition per-conversation data, tag logs, scope state. Undefined outside a turn (a bare
10
- * `fastagent tool` run, or any call with no session). (The built-in `wake` tool is one consumer — it
11
- * fires a later turn back into this same session.) In a `fastagent chat` turn this is pi's LOCAL
12
- * chat session id, not a served session — serving-coupled consumers like wake are not mounted there. */
13
- session?: string;
10
+ /** Current conversation manager. Present during serving/chat; absent for sessionless direct calls. */
11
+ sessionManager?: ReadonlySessionManager;
14
12
  /** Tool activation for the current turn (a loader tool activates {@link DefineToolOptions.deferred}
15
13
  * tools with it — the built-in `search_tools` is one consumer). Provided by both the serving path
16
14
  * (invoke.ts, over the harness) and chat (over pi's AgentSession); undefined only outside any turn
@@ -48,7 +46,7 @@ export declare function isDeferredTool(tool: AgentTool): boolean;
48
46
  /** The same tool without the deferred marker — for a loader that must stay active (a deferred loader
49
47
  * could never be activated and would strand every deferred tool). */
50
48
  export declare function stripDeferredMarker(tool: AgentTool): AgentTool;
51
- export declare function defineTool<I extends z.ZodType>(options: DefineToolOptions<I>): AgentTool;
49
+ export declare function defineTool<I extends z.ZodType>(options: DefineToolOptions<I>): FastagentTool;
52
50
  /** A discarded same-name tool (within `tools/`, or against an existing tool). Surfaced, never silent. */
53
51
  export interface ToolCollision {
54
52
  name: string;
@@ -69,7 +69,12 @@ export function defineTool(options) {
69
69
  },
70
70
  }
71
71
  : undefined;
72
- const result = wrapResult(await options.execute(parsed.data, { signal, session: store?.session, tools }));
72
+ const result = wrapResult(await options.execute(parsed.data, {
73
+ cwd: store?.cwd ?? process.cwd(),
74
+ signal,
75
+ sessionManager: store?.sessionManager,
76
+ tools,
77
+ }));
73
78
  if (added.length > 0) {
74
79
  // A copy, not a mutation: wrapResult passes a full AgentToolResult through by REFERENCE, and an
75
80
  // author may legally return a shared/frozen result object — stamping in place would corrupt it
@@ -15,6 +15,3 @@ export declare function parseDelayMs(input: string | number): number | undefined
15
15
  export declare function withWakeTool(tools: AgentTool[], stateRoot: string, enabled: boolean): AgentTool[];
16
16
  /** Build the `wake` tool bound to `stateRoot` (where wake-ups persist). */
17
17
  export declare function makeWakeTool(stateRoot: string, now?: () => Date): AgentTool;
18
- /** Build the `unwake` tool: cancel one of THIS conversation's pending wake-ups by id (a wake/recurring
19
- * that is no longer needed). Session-scoped — a conversation can never cancel another's. */
20
- export declare function makeUnwakeTool(stateRoot: string): AgentTool;
@@ -2,7 +2,7 @@
2
2
  * The built-in `wake` tool: the agent's self-scheduling surface. Calling it records a one-shot wake-up
3
3
  * (wakeups.ts); the scheduler fires it back into the SAME session, so the agent resumes THIS
4
4
  * conversation after a delay ("check the deploy in 10 minutes"). The session comes from the turn
5
- * context (ToolContext.session, set around the harness turn); the state root is closed over at build
5
+ * context (ToolContext.sessionManager, set around the harness turn); the state root is closed over at build
6
6
  * time (where it is known — the workspace opener), never read from the turn.
7
7
  *
8
8
  * Mounted by the opener ONLY when `config.selfSchedule` is on AND on the serving path (`dev`/`start`, where
@@ -67,14 +67,15 @@ export function makeWakeTool(stateRoot, now = () => new Date()) {
67
67
  prompt: z.string().min(1).describe("the instruction for the woken turn (runs in this same conversation)"),
68
68
  }),
69
69
  execute(input, ctx) {
70
- if (!ctx.session)
70
+ const session = ctx.sessionManager?.getSessionId();
71
+ if (!session)
71
72
  return "wake is only available inside a conversation (there is no session to resume).";
72
73
  if ((input.in === undefined) === (input.cron === undefined)) {
73
74
  return "pass exactly one of `in` (one-shot) or `cron` (recurring).";
74
75
  }
75
76
  if (input.cron !== undefined) {
76
77
  // addWakeup validates the cron and DERIVES the first instant itself — one computation, one truth.
77
- const r = addWakeup(stateRoot, { session: ctx.session, prompt: input.prompt, cron: input.cron, tz: input.tz }, now());
78
+ const r = addWakeup(stateRoot, { session, prompt: input.prompt, cron: input.cron, tz: input.tz }, now());
78
79
  if (!r.ok)
79
80
  return r.error; // guardrail message the model can act on
80
81
  return `OK — recurring wake ${r.id} (cron "${input.cron}"${input.tz ? ` ${input.tz}` : ""}), first at ${r.fireAt}: ${input.prompt}. Use unwake({ id: "${r.id}" }) to stop it.`;
@@ -84,7 +85,7 @@ export function makeWakeTool(stateRoot, now = () => new Date()) {
84
85
  return `couldn't parse "in" (${JSON.stringify(input.in)}) — use a unit like "30m" / "2h" / "1d", or a number of seconds (a bare number as text like "120" is rejected).`;
85
86
  }
86
87
  const at = new Date(now().getTime() + ms);
87
- const r = addWakeup(stateRoot, { session: ctx.session, prompt: input.prompt, fireAt: at }, now());
88
+ const r = addWakeup(stateRoot, { session, prompt: input.prompt, fireAt: at }, now());
88
89
  if (!r.ok)
89
90
  return r.error; // guardrail message the model can act on
90
91
  return `OK — I'll wake up at ${r.fireAt} (id ${r.id}) to: ${input.prompt}. Use unwake({ id: "${r.id}" }) if it becomes unnecessary.`;
@@ -93,16 +94,17 @@ export function makeWakeTool(stateRoot, now = () => new Date()) {
93
94
  }
94
95
  /** Build the `unwake` tool: cancel one of THIS conversation's pending wake-ups by id (a wake/recurring
95
96
  * that is no longer needed). Session-scoped — a conversation can never cancel another's. */
96
- export function makeUnwakeTool(stateRoot) {
97
+ function makeUnwakeTool(stateRoot) {
97
98
  return defineTool({
98
99
  name: "unwake",
99
100
  description: "Cancel one of YOUR pending wake-ups (one-shot or recurring) by the id `wake` returned. Use it when " +
100
101
  "a scheduled follow-up is no longer needed — especially to stop a recurring wake once its job is done.",
101
102
  input: z.object({ id: z.string().min(1).describe("the wake-up id (returned by `wake`)") }),
102
103
  execute(input, ctx) {
103
- if (!ctx.session)
104
+ const session = ctx.sessionManager?.getSessionId();
105
+ if (!session)
104
106
  return "unwake is only available inside a conversation.";
105
- return removeWakeup(stateRoot, input.id, ctx.session)
107
+ return removeWakeup(stateRoot, input.id, session)
106
108
  ? `OK — wake-up ${input.id} cancelled.`
107
109
  : `no pending wake-up ${input.id} in this conversation (already fired, or not yours).`;
108
110
  },
@@ -1,5 +1,9 @@
1
+ import type { AgentTool } from "@earendil-works/pi-agent-core";
1
2
  import type { Agent } from "../../agent.ts";
2
3
  import { type FastagentConfig } from "./config.ts";
4
+ import type { SessionControl } from "../../session.ts";
5
+ import type { SessionObserver } from "./invoke.ts";
6
+ import type { PiSessionReader, PiSessionStore } from "./sessions.ts";
3
7
  import type { ModuleLoadFailure } from "../../loader.ts";
4
8
  import { type LoadedDefinition } from "./definition.ts";
5
9
  import type { ToolCollision } from "./tool.ts";
@@ -24,7 +28,51 @@ export interface CreatePiAgentFromWorkspaceOptions {
24
28
  * and never poll). The built-in `wake` tool mounts only when this is set AND `config.selfSchedule` is on.
25
29
  */
26
30
  serving?: boolean;
31
+ /** Assemble the session control plane over this workspace's session store and return it as
32
+ * {@link sessionControl} — the store is created inside this opener, so the hub must be wired
33
+ * here too (an external `createPiSessionControl` cannot exist before the store does).
34
+ * Default: `config.sessionControl` AND {@link serving} — the config key means "serve the control
35
+ * plane", so one-shot commands (invoke/fire) do not assemble an unused hub. Pass explicitly to
36
+ * override either way. */
37
+ sessionControl?: boolean;
38
+ /** Additional raw tap with the FULL vocabulary: run events composed after the
39
+ * {@link sessionControl} hub's observer, plus the hub's own boundary-mutation events
40
+ * (`state_changed`/`compaction_*`) via the hub's tap. TRUSTED seam: since Phase 2a an observer
41
+ * receives each run's live modulation handles (see `SessionObserver`) — for read-only consumers
42
+ * use the hub's `events()` stream instead. */
43
+ observer?: SessionObserver;
27
44
  }
45
+ /**
46
+ * The workspace assembly FRONT HALF — everything that is independent of how pi consumes the
47
+ * definition (transient harness for serving vs resident AgentSession for chat / session control):
48
+ * config → model spec → agentDir → the full tool surface ({@link resolveWorkspaceTools} — the ONE
49
+ * place it is computed) → state root → auth path. Both {@link createPiAgentFromWorkspace} and the
50
+ * session builder (session-builder.ts) consume this, so THESE inputs cannot drift between the two
51
+ * consumption shapes. (Definition loading and prompt assembly stay per-consumer: serving re-reads
52
+ * them live per invoke, the session builder snapshots at startup and lets pi append skills/env.)
53
+ */
54
+ export interface WorkspaceAssembly {
55
+ config: FastagentConfig;
56
+ configPath?: string;
57
+ /** The resolved "provider/modelId" spec in use. */
58
+ modelSpec: string;
59
+ /** Absolute agent-definition dir (config.agentDir resolved against dir; = dir when unset). */
60
+ agentDir: string;
61
+ /** Absolute state root (FASTAGENT_STATE_DIR > <dir>/.fastagent). */
62
+ stateRoot: string;
63
+ /** Absolute credentials file (--auth-path/authPath option > FASTAGENT_AUTH_PATH > <stateRoot>/auth.json). */
64
+ authPath: string;
65
+ /** The full mounted tool surface (config.tools + discovered tools/, search_tools applied). */
66
+ tools: AgentTool[];
67
+ toolNames: string[];
68
+ deferredToolNames: string[];
69
+ toolCollisions: ToolCollision[];
70
+ toolFailures: ModuleLoadFailure[];
71
+ }
72
+ export declare function resolveWorkspaceAssembly(dir: string, options?: {
73
+ model?: string;
74
+ authPath?: string;
75
+ }): Promise<WorkspaceAssembly>;
28
76
  /**
29
77
  * "Point at a workspace → agent": load the config, resolve model and tools, then L2. Throws a clear
30
78
  * error when no model source is set (fail visibly at startup). Returns everything an entry point needs
@@ -45,6 +93,10 @@ export declare function createPiAgentFromWorkspace(dir: string, options?: Create
45
93
  sessionsDir: string;
46
94
  /** Absolute credentials file in use (for the startup report). */
47
95
  authPath: string;
96
+ /** The session store in use — also a {@link PiSessionReader}. */
97
+ sessions: PiSessionStore & PiSessionReader;
98
+ /** The observation plane over this workspace's sessions; present iff `options.sessionControl`. */
99
+ sessionControl?: SessionControl;
48
100
  /** Non-default, active-by-default tool names in effect: config.tools + discovered tools/. Each name
49
101
  * lives in exactly one report slot — deferred names are in {@link deferredToolNames} instead. */
50
102
  toolNames: string[];
@@ -9,17 +9,13 @@
9
9
  * watch and can point sessions at a mounted volume.
10
10
  */
11
11
  import { mkdir } from "node:fs/promises";
12
- import { defaultAuthPath, defaultSessionsDir, loadConfig, resolveAgentDir, resolveModelSpec, resolveStateRoot, } from "./config.js";
12
+ import { defaultSessionsDir, loadConfig, resolveAgentDir, resolveAuthPath, resolveModelSpec, resolveStateRoot, } from "./config.js";
13
13
  import { createPiAgentFromDefinition, resolveWorkspaceTools } from "./create.js";
14
+ import { createPiSessionControl } from "./session-control.js";
14
15
  import { withWakeTool } from "./wake-tool.js";
15
16
  import { ensureStateRootSelfIgnored } from "./definition.js";
16
17
  import { jsonlSessionStore } from "./sessions.js";
17
- /**
18
- * "Point at a workspace → agent": load the config, resolve model and tools, then L2. Throws a clear
19
- * error when no model source is set (fail visibly at startup). Returns everything an entry point needs
20
- * to report what it assembled.
21
- */
22
- export async function createPiAgentFromWorkspace(dir, options = {}) {
18
+ export async function resolveWorkspaceAssembly(dir, options = {}) {
23
19
  const { config, path: configPath } = await loadConfig(dir);
24
20
  const modelSpec = resolveModelSpec(options.model, config);
25
21
  if (!modelSpec) {
@@ -33,18 +29,67 @@ export async function createPiAgentFromWorkspace(dir, options = {}) {
33
29
  // whole machine-state home in one knob (a container mounts one volume); the finer overrides below
34
30
  // still win for their specific path.
35
31
  const stateRoot = resolveStateRoot(dir);
32
+ // The credentials file: project-level by default (under the state root); only resolved here, never
33
+ // created (a missing file reads as not-configured — `fastagent login` creates it).
34
+ const authPath = resolveAuthPath(dir, options.authPath);
35
+ // Self-ignore the state root iff it lands in-tree — which covers everything under it (sessions, auth,
36
+ // every channel's `channels/<kind>` home). HERE, not in the serving opener: every consumer of this
37
+ // assembly can WRITE under the state root (serving: sessions/channels; the session builder: pi's
38
+ // `/login` writing auth.json), so resolving a workspace's state root must make it leak-safe.
39
+ await ensureStateRootSelfIgnored(dir, stateRoot);
40
+ return {
41
+ config,
42
+ configPath,
43
+ modelSpec,
44
+ agentDir,
45
+ stateRoot,
46
+ authPath,
47
+ tools,
48
+ toolNames,
49
+ deferredToolNames,
50
+ toolCollisions,
51
+ toolFailures,
52
+ };
53
+ }
54
+ /**
55
+ * "Point at a workspace → agent": load the config, resolve model and tools, then L2. Throws a clear
56
+ * error when no model source is set (fail visibly at startup). Returns everything an entry point needs
57
+ * to report what it assembled.
58
+ */
59
+ export async function createPiAgentFromWorkspace(dir, options = {}) {
60
+ const { config, configPath, modelSpec, agentDir, stateRoot, authPath, tools, toolNames, deferredToolNames, toolCollisions, toolFailures, } = await resolveWorkspaceAssembly(dir, options);
36
61
  // Mount the built-in `wake` tool only when BOTH: this is a long-running serve (the poller honors it) AND
37
62
  // the author opted into self-scheduling (config.selfSchedule). The workspace's own `wake` wins if defined.
38
63
  const mountedTools = withWakeTool(tools, stateRoot, !!options.serving && !!config.selfSchedule);
39
64
  const sessionsDir = options.sessionsDir ?? defaultSessionsDir(stateRoot);
40
65
  await mkdir(sessionsDir, { recursive: true });
41
- // The credentials file: project-level by default (under the self-ignored state root); only READ here,
42
- // so no mkdir (a missing file reads as not-configured `fastagent login` creates it).
43
- const authPath = options.authPath ?? defaultAuthPath(stateRoot);
44
- // Self-ignore the state root iff it lands in-tree which covers everything under it (sessions, auth,
45
- // every channel's `channels/<kind>` home), including a custom in-tree `FASTAGENT_STATE_DIR`. A
46
- // per-path override to an external volume is out-of-tree and correctly left alone.
47
- await ensureStateRootSelfIgnored(dir, stateRoot);
66
+ const sessions = jsonlSessionStore({ dir: sessionsDir, cwd: dir });
67
+ // The hub is wired HERE because the store is created here: chicken-and-egg otherwise (the hub
68
+ // needs the store; the agent needs the hub's observer). Boundary parts (models/factory/lease)
69
+ // only exist after the assembly below the hub takes them as a lazy thunk, filled by the
70
+ // assembly's onAssembly callback (assembly completes before this function returns, so every
71
+ // dispatch sees them). An extra caller observer composes after the hub's (TRUSTED seam).
72
+ let boundaryParts;
73
+ const caller = options.observer;
74
+ const wantControl = options.sessionControl ?? (config.sessionControl === true && options.serving === true);
75
+ const hub = wantControl
76
+ ? createPiSessionControl({
77
+ sessions,
78
+ boundary: () => boundaryParts,
79
+ // The caller tap's boundary-event half: state_changed/compaction_* originate in the hub
80
+ // and never cross the data plane's observer seam — without this, an audit tap wired here
81
+ // would miss exactly the mutations it most needs to see (set_model).
82
+ tap: caller ? (session, event) => caller(session, event) : undefined,
83
+ })
84
+ : undefined;
85
+ const observer = hub
86
+ ? caller
87
+ ? (session, event, run) => {
88
+ hub.observer(session, event, run);
89
+ caller(session, event, run);
90
+ }
91
+ : hub.observer
92
+ : caller;
48
93
  const { agent, definition } = await createPiAgentFromDefinition(agentDir, {
49
94
  model: modelSpec,
50
95
  thinkingLevel: config.thinkingLevel,
@@ -52,11 +97,23 @@ export async function createPiAgentFromWorkspace(dir, options = {}) {
52
97
  tools: mountedTools,
53
98
  authPath,
54
99
  // Skills are definition-only (the agent is its directory), so dev mirrors deployment exactly.
55
- sessions: jsonlSessionStore({ dir: sessionsDir, cwd: dir }),
100
+ sessions,
101
+ observer,
102
+ onAssembly: hub
103
+ ? (parts) => {
104
+ boundaryParts = {
105
+ lease: parts.lease,
106
+ models: parts.models,
107
+ harnessFactory: parts.harnessFactory,
108
+ };
109
+ }
110
+ : undefined,
56
111
  });
57
112
  return {
58
113
  agent,
59
114
  definition,
115
+ sessions,
116
+ sessionControl: hub?.control,
60
117
  agentDir,
61
118
  config,
62
119
  configPath,
package/dist/feishu.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** `@fastagent-sh/fastagent/feishu` — the canonical Feishu (open.feishu.cn) bot-channel surface. */
2
- export { feishuChannel, defaultFeishuRoute, feishuEnvelope, type FeishuChannelOptions, type FeishuMessageEvent, type FeishuMessage, type FeishuRoute, type FeishuFailure, } from "./channels/feishu/feishu.ts";
2
+ export { feishuChannel, feishuWebSocketChannel, defaultFeishuRoute, feishuEnvelope, type FeishuChannelOptions, type FeishuWebSocketChannelOptions, type FeishuMessageEvent, type FeishuMessage, type FeishuRoute, type FeishuFailure, } from "./channels/feishu/feishu.ts";
package/dist/feishu.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /** `@fastagent-sh/fastagent/feishu` — the canonical Feishu (open.feishu.cn) bot-channel surface. */
2
- export { feishuChannel, defaultFeishuRoute, feishuEnvelope, } from "./channels/feishu/feishu.js";
2
+ export { feishuChannel, feishuWebSocketChannel, defaultFeishuRoute, feishuEnvelope, } from "./channels/feishu/feishu.js";
@@ -1,4 +1,5 @@
1
1
  import type { Agent } from "../agent.ts";
2
+ import type { SessionControl } from "../session.ts";
2
3
  /** A mounted request handler (a channel's fetch, or a plain route like health). */
3
4
  export type ChannelHandler = (req: Request) => Response | Promise<Response>;
4
5
  /** This deployment's HTTP surface: route key → handler. Key is `"/path"` or `"METHOD /path"`. */
@@ -13,11 +14,26 @@ export type Routes = Record<string, ChannelHandler>;
13
14
  export interface ChannelContext {
14
15
  agent: Agent;
15
16
  stateRoot: string;
17
+ /** The serving session-control hub, when the serve wires one (`config.sessionControl`). Channels
18
+ * use it for DISPATCH only (the user-facing stop command); observation stays on the data plane. */
19
+ control?: SessionControl;
16
20
  }
17
- /** A `channels/<name>.ts` default export: receives the mount context, returns the routes it mounts.
18
- * Adapters (`telegramChannel(opts)`, `githubChannel(opts)`) RETURN one of these, so user glue holds
19
- * only policy — the framework pipes `agent`/`stateRoot` to the adapter without transiting user code. */
21
+ /** A `channels/<name>.ts` route channel: receives mount context and returns its HTTP routes. */
20
22
  export type ChannelModule = (ctx: ChannelContext) => Routes;
23
+ /** One logical long connection's lifecycle. `ready` settles after its first usable connection — and
24
+ * when `signal` aborts before one exists it must still settle: resolution then means cancellation, not
25
+ * readiness (the server skips ready-side effects once the signal is aborted; it must never hang).
26
+ * `closed` resolves after abort-driven shutdown and rejects on a terminal connection failure. */
27
+ export interface LongConnection {
28
+ ready: Promise<void>;
29
+ closed: Promise<void>;
30
+ }
31
+ /** A long-connection channel is an explicit module object rather than an HTTP-route factory.
32
+ * The adapter owns reconnects and treats `signal` as its sole shutdown command. */
33
+ export interface LongConnectionChannelModule {
34
+ name: string;
35
+ connect(ctx: ChannelContext, signal: AbortSignal): LongConnection;
36
+ }
21
37
  /** Parse a route key: `"METHOD /path"` → `{ method, path }`, or `"/path"` → `{ path }` (any method). */
22
38
  export declare function parseRouteKey(key: string): {
23
39
  method?: string;
@@ -29,13 +45,14 @@ export declare function parseRouteKey(key: string): {
29
45
  */
30
46
  export declare function router(routes: Routes): ChannelHandler;
31
47
  /**
32
- * Serve `handler` on a Node HTTP server. Thin mechanism: bind, report the port, let the caller close
33
- * it — no logging/signals/exit (the CLI owns those). `listening` resolves with the bound port (useful
34
- * for port 0) or rejects on a bind error.
48
+ * Serve `handler` on a Node HTTP server. Thin mechanism: bind, report the port, let the caller stop
49
+ * accepting or force-close active connections — no logging/signals/exit (the CLI owns those).
50
+ * `listening` resolves with the bound port (useful for port 0) or rejects on a bind error.
35
51
  */
36
52
  export declare function serveNode(handler: ChannelHandler, options: {
37
53
  port: number;
38
54
  }): {
39
55
  listening: Promise<number>;
40
56
  close: () => Promise<void>;
57
+ closeAllConnections: () => void;
41
58
  };
package/dist/host/node.js CHANGED
@@ -32,9 +32,9 @@ export function router(routes) {
32
32
  };
33
33
  }
34
34
  /**
35
- * Serve `handler` on a Node HTTP server. Thin mechanism: bind, report the port, let the caller close
36
- * it — no logging/signals/exit (the CLI owns those). `listening` resolves with the bound port (useful
37
- * for port 0) or rejects on a bind error.
35
+ * Serve `handler` on a Node HTTP server. Thin mechanism: bind, report the port, let the caller stop
36
+ * accepting or force-close active connections — no logging/signals/exit (the CLI owns those).
37
+ * `listening` resolves with the bound port (useful for port 0) or rejects on a bind error.
38
38
  */
39
39
  export function serveNode(handler, options) {
40
40
  const server = createServer(nodeListener(async (req) => handler(req)));
@@ -46,5 +46,6 @@ export function serveNode(handler, options) {
46
46
  });
47
47
  });
48
48
  const close = () => new Promise((resolve, reject) => server.close((e) => (e ? reject(e) : resolve())));
49
- return { listening, close };
49
+ const closeAllConnections = () => server.closeAllConnections();
50
+ return { listening, close, closeAllConnections };
50
51
  }
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from "./core.ts";
2
+ export * from "./session.ts";
2
3
  export * from "./pi.ts";
package/dist/index.js CHANGED
@@ -2,4 +2,5 @@
2
2
  // Contract/channel-only consumers should prefer `@fastagent-sh/fastagent/core`; pi-specific consumers
3
3
  // may use `@fastagent-sh/fastagent/pi`. The root remains the supported all-in-one surface.
4
4
  export * from "./core.js";
5
+ export * from "./session.js";
5
6
  export * from "./pi.js";
package/dist/lark.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /** `@fastagent-sh/fastagent/lark` — the Lark-international compatibility surface over the canonical
2
2
  * Feishu engine. Feishu tenants use `@fastagent-sh/fastagent/feishu`. */
3
- export { larkChannel, defaultLarkRoute, larkEnvelope, type LarkChannelOptions, type LarkMessageEvent, type LarkMessage, type LarkRoute, type LarkFailure, } from "./channels/lark/lark.ts";
3
+ export { larkChannel, larkWebSocketChannel, defaultLarkRoute, larkEnvelope, type LarkChannelOptions, type LarkWebSocketChannelOptions, type LarkMessageEvent, type LarkMessage, type LarkRoute, type LarkFailure, } from "./channels/lark/lark.ts";
package/dist/lark.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /** `@fastagent-sh/fastagent/lark` — the Lark-international compatibility surface over the canonical
2
2
  * Feishu engine. Feishu tenants use `@fastagent-sh/fastagent/feishu`. */
3
- export { larkChannel, defaultLarkRoute, larkEnvelope, } from "./channels/lark/lark.js";
3
+ export { larkChannel, larkWebSocketChannel, defaultLarkRoute, larkEnvelope, } from "./channels/lark/lark.js";
package/dist/observe.js CHANGED
@@ -28,6 +28,9 @@ export function logAgentLoop(agent, sink = (line) => log.debug(line)) {
28
28
  else if (e.type === "tool_ended") {
29
29
  sink(`[agent] tool ${e.isError ? "✗" : "✓"} ${toolName.get(e.id) ?? e.id} → ${preview(e.content)}`);
30
30
  }
31
+ else if (e.type === "retrying") {
32
+ sink(`[agent] retrying (${e.attempt}/${e.maxAttempts} in ${e.delayMs}ms): ${oneLine(e.reason)}`);
33
+ }
31
34
  else if (e.type === "completed") {
32
35
  if (thinking.trim() !== "")
33
36
  sink(`[agent] thinking: ${oneLine(thinking)}`);
package/dist/pi.d.ts CHANGED
@@ -1,15 +1,16 @@
1
1
  export { createPiAgent, createPiAgentFromDefinition, type CreatePiAgentFromDefinitionOptions, type CreatePiAgentOptions, } from "./engines/pi/create.ts";
2
2
  export { defineTool, loadTools, type DefineToolOptions, type FastagentTool, type ToolCollision, type ToolContext, } from "./engines/pi/tool.ts";
3
- export type { ToolActivation } from "./engines/pi/tool-context.ts";
3
+ export type { ReadonlySessionManager, ToolActivation } from "./engines/pi/tool-context.ts";
4
4
  export { z } from "zod";
5
- export type { AgentTool, ExecutionEnv, Session, Skill, SkillDiagnostic } from "@earendil-works/pi-agent-core";
5
+ export type { AgentTool, ExecutionEnv, Session, SessionTreeEntry, Skill, SkillDiagnostic, } from "@earendil-works/pi-agent-core";
6
6
  export { loadChannels, type ChannelCollision } from "./engines/pi/channel.ts";
7
7
  export { createPiAgentFromWorkspace, type CreatePiAgentFromWorkspaceOptions, } from "./engines/pi/workspace.ts";
8
8
  export type { LoadedDefinition, SkillCollision } from "./engines/pi/definition.ts";
9
9
  export { defineConfig, listModels, resolveModel, type FastagentConfig } from "./engines/pi/config.ts";
10
- export { inProcessLease, type Lease, type Release } from "./engines/pi/invoke.ts";
10
+ export { inProcessLease, type Lease, type Release, type SessionObserver } from "./engines/pi/invoke.ts";
11
+ export { createPiSessionControl, type CreatePiSessionControlOptions, } from "./engines/pi/session-control.ts";
11
12
  export type { AnyModel } from "./engines/pi/harness.ts";
12
- export { inMemorySessionStore, jsonlSessionStore, type PiSessionStore } from "./engines/pi/sessions.ts";
13
+ export { inMemorySessionStore, jsonlSessionStore, type PiSessionReader, type PiSessionStore, } from "./engines/pi/sessions.ts";
13
14
  export { GLOBAL_AUTH_PATH, fastagentCredentialStore, type FastagentAuthOptions } from "./engines/pi/auth.ts";
14
15
  export { createPiModels, probeAuthSource, type CreatePiModelsOptions } from "./engines/pi/models.ts";
15
16
  export type { Models } from "@earendil-works/pi-ai";
package/dist/pi.js CHANGED
@@ -6,7 +6,8 @@ export { loadChannels } from "./engines/pi/channel.js";
6
6
  export { createPiAgentFromWorkspace, } from "./engines/pi/workspace.js";
7
7
  export { defineConfig, listModels, resolveModel } from "./engines/pi/config.js";
8
8
  export { inProcessLease } from "./engines/pi/invoke.js";
9
- export { inMemorySessionStore, jsonlSessionStore } from "./engines/pi/sessions.js";
9
+ export { createPiSessionControl, } from "./engines/pi/session-control.js";
10
+ export { inMemorySessionStore, jsonlSessionStore, } from "./engines/pi/sessions.js";
10
11
  export { GLOBAL_AUTH_PATH, fastagentCredentialStore } from "./engines/pi/auth.js";
11
12
  export { createPiModels, probeAuthSource } from "./engines/pi/models.js";
12
13
  export { createProvider } from "@earendil-works/pi-ai";
@@ -1,4 +1,14 @@
1
- export type ChannelKind = "github" | "telegram" | "feishu" | "lark";
1
+ import type { FeishuSubscriptionMode } from "../channels/feishu/setup-mode.ts";
2
+ export type ChannelKind = "github" | "telegram" | "slack" | "feishu" | "lark";
3
+ /** Group-visibility choice shared by the slack/feishu/lark onboarding flows. Each channel keeps its
4
+ * own channel-level type (`SlackGroupBehavior`, `FeishuGroupBehavior`) — this is the CLI-side value. */
5
+ export type GroupBehavior = "context" | "mentions";
6
+ /** A resolved group-behavior decision plus whether the author actually chose it (flag or prompt).
7
+ * A defaulted "context" (non-interactive, no flag) must never drive a sensitive-scope write. */
8
+ export interface GroupBehaviorChoice {
9
+ behavior: GroupBehavior;
10
+ explicit: boolean;
11
+ }
2
12
  /** An env var a scaffolded channel reads. `generate` = a random-string secret the CLI can pre-fill. */
3
13
  export interface ChannelEnv {
4
14
  name: string;
@@ -9,8 +19,8 @@ export interface ChannelEnv {
9
19
  }
10
20
  /** The channel kinds `fastagent add <kind>` can scaffold. */
11
21
  export declare const CHANNEL_KINDS: ChannelKind[];
12
- /** The env vars + next-step lines a scaffolded channel needs (for the CLI to print). */
13
- export declare function channelSetup(kind: ChannelKind): {
22
+ /** The mode-specific env vars + next-step lines a scaffolded channel needs. */
23
+ export declare function channelSetup(kind: ChannelKind, ingress?: FeishuSubscriptionMode, groupBehavior?: GroupBehavior): {
14
24
  env: ChannelEnv[];
15
25
  steps: string[];
16
26
  };
@@ -19,7 +29,7 @@ export declare function channelSetup(kind: ChannelKind): {
19
29
  * copies it to `.env` finds the vars already there. No-op when there is no `.env.example` or the block
20
30
  * is already present. Placeholders only — no real secret lands in the committable template.
21
31
  */
22
- export declare function appendChannelEnv(dir: string, kind: ChannelKind): Promise<boolean>;
32
+ export declare function appendChannelEnv(dir: string, kind: ChannelKind, ingress?: FeishuSubscriptionMode): Promise<boolean>;
23
33
  export interface DotEnvWriteResult {
24
34
  /** Generated secret vars written as active `KEY=value` lines. */
25
35
  written: string[];
@@ -34,14 +44,17 @@ export interface DotEnvWriteResult {
34
44
  * (e.g. TELEGRAM_BOT_TOKEN from BotFather) are added only as commented placeholders, so the file is
35
45
  * ready to edit while no fake secret is committed to the user's mental model.
36
46
  */
37
- export declare function appendChannelDotEnv(dir: string, kind: ChannelKind, generated: Record<string, string>, overwrite?: readonly string[]): Promise<DotEnvWriteResult>;
47
+ export declare function appendChannelDotEnv(dir: string, kind: ChannelKind, generated: Record<string, string>, overwrite?: readonly string[], ingress?: FeishuSubscriptionMode): Promise<DotEnvWriteResult>;
38
48
  /** Whether a channel file already exists — checked before any mutation, so a no-clobber re-add is side-effect-free. */
39
49
  export declare function channelExists(dir: string, kind: ChannelKind): Promise<boolean>;
40
50
  /**
41
51
  * Scaffold `channels/<kind>.ts` into {@link dir}. Never clobbers an existing file (the glue is
42
52
  * authored content). The wx write is the TOCTOU safety net behind {@link channelExists}.
43
53
  */
44
- export declare function scaffoldChannel(dir: string, kind: ChannelKind): Promise<string>;
54
+ export declare function scaffoldChannel(dir: string, kind: ChannelKind, options?: {
55
+ ingress?: FeishuSubscriptionMode;
56
+ groupBehavior?: GroupBehavior;
57
+ }): Promise<string>;
45
58
  /**
46
59
  * Verify the workspace is ready to host a channel: an ESM package.json that declares
47
60
  * `@fastagent-sh/fastagent` (the channel file imports it). `add` checks and guides, never bootstraps — that