@fastagent-sh/fastagent 0.18.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/README.md +25 -7
  2. package/dist/agent.d.ts +1 -1
  3. package/dist/agent.js +1 -1
  4. package/dist/atomic-write.d.ts +23 -0
  5. package/dist/atomic-write.js +53 -0
  6. package/dist/{host/node.d.ts → channel.d.ts} +24 -28
  7. package/dist/channel.js +1 -0
  8. package/dist/channels/agentcore-limits.d.ts +9 -0
  9. package/dist/channels/agentcore-limits.js +9 -0
  10. package/dist/channels/agentcore-service.d.ts +55 -0
  11. package/dist/channels/agentcore-service.js +107 -0
  12. package/dist/channels/agentcore.d.ts +22 -20
  13. package/dist/channels/agentcore.js +20 -11
  14. package/dist/channels/busy.d.ts +1 -1
  15. package/dist/channels/busy.js +1 -1
  16. package/dist/channels/control.d.ts +55 -7
  17. package/dist/channels/control.js +312 -67
  18. package/dist/channels/discover.d.ts +59 -0
  19. package/dist/{engines/pi/channel.js → channels/discover.js} +19 -34
  20. package/dist/channels/feishu/card.js +1 -1
  21. package/dist/channels/feishu/context-buffer.d.ts +1 -1
  22. package/dist/channels/feishu/context-buffer.js +4 -4
  23. package/dist/channels/feishu/feishu-api.js +6 -9
  24. package/dist/channels/feishu/feishu.d.ts +1 -1
  25. package/dist/channels/feishu/feishu.js +41 -24
  26. package/dist/channels/feishu/invoke-turn.d.ts +1 -1
  27. package/dist/channels/feishu/invoke-turn.js +3 -4
  28. package/dist/channels/feishu/preview.d.ts +1 -1
  29. package/dist/channels/feishu/preview.js +7 -3
  30. package/dist/channels/feishu/ws-ingress.d.ts +1 -1
  31. package/dist/channels/github/github.d.ts +1 -1
  32. package/dist/channels/http.d.ts +11 -7
  33. package/dist/channels/http.js +1 -109
  34. package/dist/channels/kit/attachment-path.d.ts +12 -0
  35. package/dist/channels/kit/attachment-path.js +43 -0
  36. package/dist/channels/{context-buffer.d.ts → kit/context-buffer.d.ts} +9 -0
  37. package/dist/channels/{context-buffer.js → kit/context-buffer.js} +13 -2
  38. package/dist/channels/{invoke-turn-kit.d.ts → kit/invoke-turn-kit.d.ts} +14 -3
  39. package/dist/channels/{invoke-turn-kit.js → kit/invoke-turn-kit.js} +17 -6
  40. package/dist/channels/{preview-kit.d.ts → kit/preview-kit.d.ts} +3 -1
  41. package/dist/channels/{seen.js → kit/seen.js} +1 -1
  42. package/dist/channels/kit/signature.d.ts +12 -0
  43. package/dist/channels/kit/signature.js +17 -0
  44. package/dist/channels/{state.js → kit/state.js} +4 -7
  45. package/dist/channels/{stop-command.d.ts → kit/stop-command.d.ts} +1 -1
  46. package/dist/channels/{stop-command.js → kit/stop-command.js} +5 -5
  47. package/dist/channels/{tasks.d.ts → kit/tasks.d.ts} +1 -1
  48. package/dist/channels/{tasks.js → kit/tasks.js} +11 -5
  49. package/dist/channels/{thread-participants.js → kit/thread-participants.js} +1 -1
  50. package/dist/channels/{turn-queue.js → kit/turn-queue.js} +2 -2
  51. package/dist/channels/{turn-store.d.ts → kit/turn-store.d.ts} +19 -3
  52. package/dist/channels/{turn-store.js → kit/turn-store.js} +30 -3
  53. package/dist/channels/lark/lark.d.ts +1 -1
  54. package/dist/channels/serve.d.ts +73 -0
  55. package/dist/channels/serve.js +243 -0
  56. package/dist/channels/slack/bot-auth.js +3 -14
  57. package/dist/channels/slack/context-buffer.d.ts +2 -2
  58. package/dist/channels/slack/context-buffer.js +2 -2
  59. package/dist/channels/slack/invoke-turn.d.ts +2 -2
  60. package/dist/channels/slack/invoke-turn.js +13 -6
  61. package/dist/channels/slack/onboard.js +5 -5
  62. package/dist/channels/slack/onboarding-state.d.ts +7 -3
  63. package/dist/channels/slack/onboarding-state.js +13 -20
  64. package/dist/channels/slack/parse.js +2 -2
  65. package/dist/channels/slack/preview.d.ts +1 -1
  66. package/dist/channels/slack/preview.js +11 -3
  67. package/dist/channels/slack/register-webhook.js +1 -1
  68. package/dist/channels/slack/scaffold/slack-send.ts +2 -17
  69. package/dist/channels/slack/slack-api.js +23 -55
  70. package/dist/channels/slack/slack.d.ts +1 -1
  71. package/dist/channels/slack/slack.js +20 -20
  72. package/dist/channels/slack/welcomed.js +1 -1
  73. package/dist/channels/telegram/context-buffer.d.ts +2 -2
  74. package/dist/channels/telegram/context-buffer.js +2 -2
  75. package/dist/channels/telegram/invoke-turn.d.ts +1 -1
  76. package/dist/channels/telegram/invoke-turn.js +1 -1
  77. package/dist/channels/telegram/parse.d.ts +21 -1
  78. package/dist/channels/telegram/parse.js +67 -13
  79. package/dist/channels/telegram/preview.d.ts +1 -1
  80. package/dist/channels/telegram/preview.js +6 -2
  81. package/dist/channels/telegram/scaffold/channel.ts +7 -3
  82. package/dist/channels/telegram/telegram-api.js +5 -6
  83. package/dist/channels/telegram/telegram.d.ts +3 -3
  84. package/dist/channels/telegram/telegram.js +60 -72
  85. package/dist/channels/telegram/turn-store.d.ts +2 -2
  86. package/dist/channels/telegram/turn-store.js +2 -2
  87. package/dist/cli/add-slack.js +6 -5
  88. package/dist/cli/commands/add.js +1 -5
  89. package/dist/cli/commands/attach.d.ts +2 -4
  90. package/dist/cli/commands/attach.js +17 -15
  91. package/dist/cli/commands/deploy.d.ts +50 -5
  92. package/dist/cli/commands/deploy.js +183 -134
  93. package/dist/cli/commands/dev.js +25 -40
  94. package/dist/cli/commands/fire.js +1 -1
  95. package/dist/cli/commands/info.js +7 -5
  96. package/dist/cli/commands/init.js +1 -2
  97. package/dist/cli/commands/schedule.js +1 -1
  98. package/dist/cli/commands/start.js +80 -121
  99. package/dist/cli/commands/tool.js +5 -7
  100. package/dist/cli/program.js +1 -1
  101. package/dist/cli/serve.d.ts +22 -70
  102. package/dist/cli/serve.js +66 -257
  103. package/dist/cli/shared.d.ts +40 -10
  104. package/dist/cli/shared.js +53 -6
  105. package/dist/core.d.ts +3 -5
  106. package/dist/core.js +7 -5
  107. package/dist/deploy/agentcore/logs.d.ts +2 -2
  108. package/dist/deploy/agentcore/logs.js +2 -2
  109. package/dist/deploy/agentcore/plan.d.ts +12 -10
  110. package/dist/deploy/agentcore/plan.js +39 -31
  111. package/dist/deploy/agentcore/run.d.ts +5 -4
  112. package/dist/deploy/agentcore/run.js +13 -36
  113. package/dist/deploy/channel-ingress.d.ts +73 -0
  114. package/dist/deploy/channel-ingress.js +101 -0
  115. package/dist/deploy/docker/plan.d.ts +3 -7
  116. package/dist/deploy/docker/plan.js +4 -15
  117. package/dist/deploy/docker/run.d.ts +18 -1
  118. package/dist/deploy/docker/run.js +10 -0
  119. package/dist/deploy/fly/plan.d.ts +4 -5
  120. package/dist/deploy/fly/plan.js +7 -22
  121. package/dist/deploy/fly/run.d.ts +9 -23
  122. package/dist/deploy/fly/run.js +32 -68
  123. package/dist/deploy/preflight.d.ts +6 -7
  124. package/dist/deploy/preflight.js +27 -23
  125. package/dist/deploy/railway/plan.d.ts +4 -5
  126. package/dist/deploy/railway/plan.js +11 -26
  127. package/dist/deploy/railway/run.d.ts +9 -9
  128. package/dist/deploy/railway/run.js +40 -40
  129. package/dist/deploy/runner.js +22 -2
  130. package/dist/deploy/secrets.d.ts +18 -9
  131. package/dist/deploy/secrets.js +64 -12
  132. package/dist/dev-supervisor.js +11 -6
  133. package/dist/engines/pi/agent-session-factory.d.ts +104 -0
  134. package/dist/engines/pi/agent-session-factory.js +295 -0
  135. package/dist/engines/pi/auth.js +43 -43
  136. package/dist/engines/pi/config.d.ts +5 -5
  137. package/dist/engines/pi/config.js +1 -1
  138. package/dist/engines/pi/create.d.ts +67 -42
  139. package/dist/engines/pi/create.js +142 -72
  140. package/dist/engines/pi/definition.d.ts +42 -8
  141. package/dist/engines/pi/definition.js +114 -11
  142. package/dist/engines/pi/invoke-session.d.ts +22 -19
  143. package/dist/engines/pi/invoke-session.js +286 -100
  144. package/dist/engines/pi/login.js +39 -20
  145. package/dist/engines/pi/models.d.ts +14 -0
  146. package/dist/engines/pi/models.js +9 -1
  147. package/dist/engines/pi/open.d.ts +10 -8
  148. package/dist/engines/pi/open.js +21 -11
  149. package/dist/engines/pi/report.d.ts +0 -4
  150. package/dist/engines/pi/report.js +0 -7
  151. package/dist/engines/pi/search-tools.js +1 -1
  152. package/dist/engines/pi/service.d.ts +23 -0
  153. package/dist/engines/pi/service.js +27 -0
  154. package/dist/engines/pi/session-builder.js +87 -118
  155. package/dist/engines/pi/session-control.d.ts +28 -14
  156. package/dist/engines/pi/session-control.js +570 -438
  157. package/dist/engines/pi/session-inheritance.d.ts +30 -0
  158. package/dist/engines/pi/session-inheritance.js +261 -0
  159. package/dist/engines/pi/session-markers.d.ts +48 -0
  160. package/dist/engines/pi/session-markers.js +59 -0
  161. package/dist/engines/pi/session-settings.d.ts +15 -3
  162. package/dist/engines/pi/session-settings.js +22 -1
  163. package/dist/engines/pi/session-store.d.ts +140 -0
  164. package/dist/engines/pi/session-store.js +666 -0
  165. package/dist/engines/pi/tool-context.d.ts +36 -13
  166. package/dist/engines/pi/tool-context.js +51 -4
  167. package/dist/engines/pi/tool.d.ts +5 -5
  168. package/dist/engines/pi/tool.js +3 -3
  169. package/dist/engines/pi/turn-kit.d.ts +32 -6
  170. package/dist/engines/pi/turn-kit.js +28 -1
  171. package/dist/engines/pi/wake-tool.js +1 -1
  172. package/dist/env.js +1 -2
  173. package/dist/index.d.ts +1 -0
  174. package/dist/index.js +1 -0
  175. package/dist/loader.d.ts +49 -7
  176. package/dist/loader.js +79 -18
  177. package/dist/log.d.ts +3 -0
  178. package/dist/log.js +5 -1
  179. package/dist/node.d.ts +16 -0
  180. package/dist/node.js +20 -0
  181. package/dist/paths.d.ts +26 -0
  182. package/dist/paths.js +37 -2
  183. package/dist/pi.d.ts +14 -8
  184. package/dist/pi.js +6 -5
  185. package/dist/scaffold/add-channel.js +2 -2
  186. package/dist/scaffold/init.js +7 -2
  187. package/dist/scaffold/templates/persona.md +2 -2
  188. package/dist/scaffold/templates/tools/fetch-url.ts +0 -2
  189. package/dist/schedule/discover.js +3 -15
  190. package/dist/schedule/state.js +4 -9
  191. package/dist/schedule/wake-alarm.d.ts +13 -7
  192. package/dist/schedule/wake-alarm.js +88 -46
  193. package/dist/schedule/wakeups.d.ts +2 -2
  194. package/dist/schedule/wakeups.js +11 -8
  195. package/dist/service.d.ts +157 -0
  196. package/dist/service.js +376 -0
  197. package/dist/session-remote.d.ts +8 -3
  198. package/dist/session-remote.js +162 -92
  199. package/dist/session.d.ts +229 -93
  200. package/dist/session.js +61 -23
  201. package/dist/telegram.d.ts +1 -1
  202. package/dist/telegram.js +1 -1
  203. package/dist/tunnel.d.ts +18 -3
  204. package/dist/tunnel.js +32 -40
  205. package/package.json +14 -5
  206. package/dist/engines/pi/channel.d.ts +0 -37
  207. package/dist/engines/pi/harness.d.ts +0 -115
  208. package/dist/engines/pi/harness.js +0 -154
  209. package/dist/engines/pi/invoke.d.ts +0 -60
  210. package/dist/engines/pi/invoke.js +0 -459
  211. package/dist/engines/pi/read-image.d.ts +0 -4
  212. package/dist/engines/pi/read-image.js +0 -62
  213. package/dist/engines/pi/sessions.d.ts +0 -60
  214. package/dist/engines/pi/sessions.js +0 -464
  215. package/dist/host/node.js +0 -52
  216. /package/dist/channels/{preview-kit.js → kit/preview-kit.js} +0 -0
  217. /package/dist/channels/{seen.d.ts → kit/seen.d.ts} +0 -0
  218. /package/dist/channels/{state.d.ts → kit/state.d.ts} +0 -0
  219. /package/dist/channels/{text.d.ts → kit/text.d.ts} +0 -0
  220. /package/dist/channels/{text.js → kit/text.js} +0 -0
  221. /package/dist/channels/{thread-participants.d.ts → kit/thread-participants.d.ts} +0 -0
  222. /package/dist/channels/{turn-queue.d.ts → kit/turn-queue.d.ts} +0 -0
@@ -20,16 +20,20 @@
20
20
  * Locking is vendored here on `proper-lockfile`, with the same parameters pi's file backend used
21
21
  * before pi 0.80.8 stopped exporting it (upstream's stated migration path for SDK consumers is a
22
22
  * custom pi-ai `CredentialStore`, which this file is). The lock guards the WRITE path only. `read`
23
- * is pi-ai's per-request hot path, so it stays UNLOCKED; the in-place locked write opens only a
24
- * sub-millisecond torn-read window, which `read` absorbs by re-reading. The write path refuses to
25
- * overwrite a corrupt file (never clobbering other providers' credentials).
23
+ * is pi-ai's per-request hot path, so it stays UNLOCKED safe because every write that carries a
24
+ * CREDENTIAL publishes by rename ({@link writeFileAtomic}): a reader sees one whole version of the
25
+ * file or another, never a partial one, so a rotation has no torn-read window for an unlocked read
26
+ * to absorb. The one in-place write left is the `{}` bootstrap below, whose window an unlocked read
27
+ * observes as an empty file — reported as corrupt, which for a zero-byte auth.json is the right
28
+ * answer either way. The write path refuses to overwrite a corrupt file (never clobbering other
29
+ * providers' credentials).
26
30
  */
27
- import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
31
+ import { chmodSync, existsSync, readFileSync, writeFileSync } from "node:fs";
28
32
  import { homedir } from "node:os";
29
33
  import { dirname, join } from "node:path";
30
- import { GLOBAL_HOME_DIR, SECRETS_DIRNAME } from "../../paths.js";
34
+ import { GLOBAL_HOME_DIR, SECRETS_DIRNAME, SECRET_FILE_MODE, ensureSecretsDir } from "../../paths.js";
35
+ import { writeFileAtomic } from "../../atomic-write.js";
31
36
  import { log } from "../../log.js";
32
- import { setTimeout as sleep } from "node:timers/promises";
33
37
  import lockfile from "proper-lockfile";
34
38
  /**
35
39
  * The GLOBAL fastagent credentials file (distinct from pi's `~/.pi`), under the user-global machinery
@@ -46,7 +50,7 @@ function pick(creds, providerId) {
46
50
  const cred = creds[providerId];
47
51
  return cred && (cred.type === "oauth" || cred.type === "api_key") ? cred : undefined;
48
52
  }
49
- const AUTH_FILE_WRITE_OPTIONS = { encoding: "utf8", mode: 0o600 };
53
+ const AUTH_FILE_WRITE_OPTIONS = { encoding: "utf8", mode: SECRET_FILE_MODE };
50
54
  /**
51
55
  * Serialized cross-process read-modify-write of the credentials file: exponential-backoff retries,
52
56
  * 30s staleness, and compromise detection (the parameters pi's `FileAuthStorageBackend` used).
@@ -56,13 +60,15 @@ const AUTH_FILE_WRITE_OPTIONS = { encoding: "utf8", mode: 0o600 };
56
60
  * failed unlock after a successful operation rejects instead of leaving a stale lock silently.
57
61
  */
58
62
  async function withLockedAuthFile(authPath, fn) {
59
- const dir = dirname(authPath);
60
- if (!existsSync(dir))
61
- mkdirSync(dir, { recursive: true, mode: 0o700 });
63
+ // 0700 unconditionally, including on a directory an operator named with `--auth-path`: pointing a
64
+ // credential file somewhere is asking for that somewhere to hold a credential. Where the process
65
+ // cannot chmod (a mount it does not own), this raises — the write fails visibly instead of
66
+ // quietly leaving the directory readable, which is the trade this repo takes everywhere else.
67
+ await ensureSecretsDir(dirname(authPath));
62
68
  if (!existsSync(authPath)) {
63
69
  try {
64
70
  writeFileSync(authPath, "{}", { ...AUTH_FILE_WRITE_OPTIONS, flag: "wx" });
65
- chmodSync(authPath, 0o600);
71
+ chmodSync(authPath, SECRET_FILE_MODE);
66
72
  }
67
73
  catch (error) {
68
74
  // EEXIST: another process created the file between the existence check and this exclusive
@@ -89,10 +95,12 @@ async function withLockedAuthFile(authPath, fn) {
89
95
  const current = existsSync(authPath) ? readFileSync(authPath, "utf8") : undefined;
90
96
  const out = await fn(current);
91
97
  throwIfCompromised();
92
- if (out.next !== undefined) {
93
- writeFileSync(authPath, out.next, AUTH_FILE_WRITE_OPTIONS);
94
- chmodSync(authPath, 0o600);
95
- }
98
+ // Rename, not an in-place rewrite: it is what lets `read` stay unlocked, and it is the only
99
+ // spelling that applies the mode before the content is reachable — `writeFileSync`'s `mode` is
100
+ // a no-op on an existing file, so a chmod after it leaves the new credential briefly readable
101
+ // at whatever mode the old file carried.
102
+ if (out.next !== undefined)
103
+ writeFileAtomic(authPath, out.next, SECRET_FILE_MODE);
96
104
  throwIfCompromised();
97
105
  result = out.result;
98
106
  }
@@ -139,34 +147,26 @@ function decodeCreds(raw) {
139
147
  return parsed;
140
148
  }
141
149
  /**
142
- * Tolerant UNLOCKED read of the whole credentials file, shared by `read` and `list`. The only race
143
- * is a sub-millisecond in-place write during an OAuth rotation, which can yield an empty/partial
144
- * file; re-read a few times before concluding it is corrupt. A missing file reads as undefined
145
- * silently (normal not-configured); a valid file returns immediately, so the common case costs one
146
- * read.
150
+ * UNLOCKED read of the whole credentials file, shared by `read` and `list`. ONE read: the write
151
+ * publishes by rename, so this observes one whole version or another and has nothing to absorb by
152
+ * re-reading. A missing file reads as undefined silently (normal not-configured); anything that
153
+ * does not decode is a real corruption a hand-edit — and says so immediately, rather than after
154
+ * retrying a race that cannot happen.
147
155
  */
148
- async function readCreds(authPath, warn) {
149
- for (let attempt = 0; attempt < 3; attempt++) {
150
- let raw;
151
- try {
152
- raw = readFileSync(authPath, "utf8");
153
- }
154
- catch (error) {
155
- if (error.code === "ENOENT")
156
- return undefined; // missing/deleted
157
- warn(`[fastagent] cannot read ${authPath}: ${error.message}`);
158
- return undefined;
159
- }
160
- if (raw !== "") {
161
- const creds = decodeCreds(raw);
162
- if (creds !== undefined)
163
- return creds;
164
- // A partial read mid-write parses as garbage; fall through and retry. A structurally invalid
165
- // root lands here too and is reported as corrupt below.
166
- }
167
- if (attempt < 2)
168
- await sleep(2);
156
+ function readCreds(authPath, warn) {
157
+ let raw;
158
+ try {
159
+ raw = readFileSync(authPath, "utf8");
160
+ }
161
+ catch (error) {
162
+ if (error.code === "ENOENT")
163
+ return undefined; // missing/deleted
164
+ warn(`[fastagent] cannot read ${authPath}: ${error.message}`);
165
+ return undefined;
169
166
  }
167
+ const creds = raw === "" ? undefined : decodeCreds(raw);
168
+ if (creds !== undefined)
169
+ return creds;
170
170
  warn(`[fastagent] corrupt auth file ${authPath}: fix or remove it`);
171
171
  return undefined;
172
172
  }
@@ -190,13 +190,13 @@ export function fastagentCredentialStore(authPath = GLOBAL_AUTH_PATH, options =
190
190
  const warn = options.warn ?? ((message) => log.warn(message));
191
191
  return {
192
192
  async read(providerId) {
193
- const creds = await readCreds(authPath, warn);
193
+ const creds = readCreds(authPath, warn);
194
194
  return creds ? pick(creds, providerId) : undefined;
195
195
  },
196
196
  async list() {
197
197
  // Metadata only, never secrets (the pi-ai `list` contract). Foreign/old entries are filtered
198
198
  // with the same validation as `read`, so both surfaces agree on what "configured" means.
199
- const creds = await readCreds(authPath, warn);
199
+ const creds = readCreds(authPath, warn);
200
200
  if (!creds)
201
201
  return [];
202
202
  const infos = [];
@@ -1,7 +1,7 @@
1
1
  import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
2
2
  import type { FastagentTool } from "./tool.ts";
3
3
  import type { Models } from "@earendil-works/pi-ai";
4
- import type { AnyModel } from "./harness.ts";
4
+ import type { AnyModel } from "./models.ts";
5
5
  export interface FastagentConfig {
6
6
  /** "provider/modelId". Precedence: CLI --model > FASTAGENT_MODEL > config. */
7
7
  model?: string;
@@ -9,8 +9,8 @@ export interface FastagentConfig {
9
9
  * "xhigh" | "max"). Unset = pi's default. Authors tune thinking in the pi TUI while vibing — this
10
10
  * is the serving-side counterpart (fidelity). Levels a model doesn't support are clamped by pi. */
11
11
  thinkingLevel?: ThinkingLevel;
12
- /** Extra custom tools, appended after pi defaults — never replaces them. `FastagentTool` = AgentTool
13
- * plus the optional `deferred` marker (see defineTool). */
12
+ /** Extra custom tools, appended after the pi coding tools — never replaces them. `FastagentTool`
13
+ * = AgentTool plus the optional `deferred` marker (see defineTool). */
14
14
  tools?: FastagentTool[];
15
15
  /** `host` is the bind address: unset (or `0.0.0.0`) binds all interfaces — what containers need;
16
16
  * `127.0.0.1` keeps the serve (including `/control/*`) off the LAN. Precedence: `--bind` > this. */
@@ -24,7 +24,7 @@ export interface FastagentConfig {
24
24
  selfSchedule?: boolean;
25
25
  /**
26
26
  * Serve the session control plane over HTTP (`/control/*`: state/entries/events + dispatch —
27
- * steer/abort/compact/set_model…) for remote consumers: a Web panel, a desktop app, `fastagent
27
+ * steer/abort/compact + session properties and lifecycle) for remote consumers: a Web panel, a desktop app, `fastagent
28
28
  * attach`. Default off (it is a remote-control surface). When on, `dev`/`start` generate a
29
29
  * per-boot bearer token and write `<stateRoot>/control.json` for local discovery. The serve
30
30
  * binds all interfaces by default, so the routes are LAN-reachable with the token as the only
@@ -60,7 +60,7 @@ export declare function loadConfig(dir: string): Promise<LoadedConfig>;
60
60
  * lookups then miss visibly (an unknown-provider error / a login-required hint), never a mangled id
61
61
  * (`slice(0, indexOf("/"))` silently drops the last char when "/" is absent). */
62
62
  export declare function providerOf(spec: string): string;
63
- /** Resolve "provider/modelId" → a pi Model from `models`, so the harness resolves auth from the same collection. */
63
+ /** Resolve "provider/modelId" → a pi Model from `models`, so auth resolves from the same collection. */
64
64
  export declare function resolveModel(models: Models, spec: string): AnyModel;
65
65
  /** All registered "provider/modelId" specs in `models`, sorted — the list behind `fastagent models`. */
66
66
  export declare function listModels(models: Models): string[];
@@ -151,7 +151,7 @@ export function providerOf(spec) {
151
151
  const slash = spec.indexOf("/");
152
152
  return slash > 0 ? spec.slice(0, slash) : spec;
153
153
  }
154
- /** Resolve "provider/modelId" → a pi Model from `models`, so the harness resolves auth from the same collection. */
154
+ /** Resolve "provider/modelId" → a pi Model from `models`, so auth resolves from the same collection. */
155
155
  export function resolveModel(models, spec) {
156
156
  const slash = spec.indexOf("/");
157
157
  if (slash < 1 || slash === spec.length - 1) {
@@ -1,25 +1,42 @@
1
+ /**
2
+ * Agent assembly (configuration-time): the engine assets (tools, prompt) plus the reusable ladder
3
+ * that puts a pi agent together.
4
+ *
5
+ * L2 createPiAgentFromDefinition(dir, options) — load a definition directory, assemble, then L1.
6
+ * L1 createPiAgent(options) — assemble from typed parts (the canonical ctor).
7
+ * L0 createPiAgentFromSession({ sessionFactory }) — in invoke-session.ts (the turn mechanism).
8
+ *
9
+ * Above L2 sits the agent opener createPiAgentFromDir (open.ts), which both `dev` and
10
+ * `start` drive. Each rung calls the one below; options narrow as you go up (L2 owns systemPrompt/skills —
11
+ * they come from the definition; the openers own model/tools — from config resolution).
12
+ */
1
13
  import { type ExecutionEnv, type Skill, type ThinkingLevel } from "@earendil-works/pi-agent-core";
2
- import type { Models, Provider } from "@earendil-works/pi-ai";
14
+ import { type ModelRuntime } from "@earendil-works/pi-coding-agent";
15
+ import type { Provider } from "@earendil-works/pi-ai";
3
16
  import type { Agent } from "../../agent.ts";
4
17
  import { type FastagentConfig } from "./config.ts";
5
18
  import { type LoadedDefinition } from "./definition.ts";
6
- import { type AnyModel, piHarnessFactory } from "./harness.ts";
7
- import { type PiSessionStore } from "./sessions.ts";
8
19
  import type { ModuleLoadFailure } from "../../loader.ts";
9
20
  import { type ToolCollision, type MountedTool } from "./tool.ts";
10
- import { type SessionObserver } from "./invoke.ts";
11
- import { type Lease } from "./turn-kit.ts";
12
- /** pi's core default toolset (read/bash/edit/write). Rooted at the ExecutionEnv's cwd, supplied per
13
- * turn as the harness tool context hence no argument here. */
14
- export declare function piDefaultTools(): MountedTool[];
15
- /** `config.tools` semantics: extra tools APPENDED after pi's defaults, never replacing them. */
16
- export declare function resolveTools(config: FastagentConfig): MountedTool[];
21
+ import { type PiAgentSessionFactory } from "./invoke-session.ts";
22
+ import { type AnyModel } from "./models.ts";
23
+ import { type PiSessionRecordStore } from "./session-store.ts";
24
+ import { type Lease, type SessionObserver } from "./turn-kit.ts";
17
25
  /**
18
- * The full tool set an agent mounts: pi defaults + `config.tools` + discovered `tools/` (deduped,
19
- * existing win), plus the non-default tool names and collisions to report. One source for the
26
+ * Every pi coding tool, in canonical order, rooted at the workspace it operates in.
27
+ *
28
+ * pi ships two overlapping groupings and neither is the whole set: `createCodingTools` is the four it
29
+ * ACTIVATES for a terminal (read/bash/edit/write, no searching), `createReadOnlyTools` is
30
+ * read/grep/find/ls. `read` is in both; a directory agent mounts their union.
31
+ */
32
+ export declare const CODING_TOOL_NAMES: readonly ["read", "grep", "find", "ls", "bash", "edit", "write"];
33
+ export declare function piAllCodingTools(cwd: string): MountedTool[];
34
+ /**
35
+ * The full directory-agent tool set: all pi coding tools + `config.tools` + discovered `tools/`
36
+ * (deduped, existing win), plus the authored names and collisions to report. One source for the
20
37
  * dev/start openers AND `fastagent tool`, so they all mount exactly the same set.
21
38
  */
22
- export declare function resolveAgentTools(config: FastagentConfig, agentDir: string): Promise<{
39
+ export declare function resolveAgentTools(config: FastagentConfig, agentDir: string, cwd: string): Promise<{
23
40
  tools: MountedTool[];
24
41
  toolNames: string[];
25
42
  /** Tools registered but not initially active (defineTool `deferred: true`) — discovered/activated
@@ -57,20 +74,22 @@ export interface AssembleSystemPromptOptions {
57
74
  export declare function assembleSystemPrompt(options: AssembleSystemPromptOptions): string;
58
75
  /**
59
76
  * INTERNAL seam (workspace ↔ assembly): hands the hub-wiring consumer the assembly's live parts —
60
- * the SAME models collection, harness factory, and lease the agent runs with so boundary
61
- * mutations (session-control.ts) contend on the real lease and validate against the real registry.
62
- * Called synchronously, exactly once, before the agent is returned. Not part of the public surface.
77
+ * the SAME session factory and lease the agent runs with, plus the model registry behind a thunk —
78
+ * so boundary mutations (session-control.ts) contend on the real lease and validate against the real
79
+ * registry. Called synchronously, exactly once, before the agent is returned. Not public surface.
63
80
  */
64
- type OnAssembly = (parts: {
65
- models: Models;
66
- harnessFactory: ReturnType<typeof piHarnessFactory>;
81
+ export type PiAssemblyParts = {
67
82
  lease: Lease;
68
- /** The resolved configured pair — what a session without overrides runs on. */
69
- defaults: {
83
+ sessionFactory: PiAgentSessionFactory;
84
+ /** The registry and configured model, resolved on first use (a credential read is async). */
85
+ engine: () => Promise<{
86
+ modelRuntime: ModelRuntime;
70
87
  model: AnyModel;
71
- thinkingLevel: ThinkingLevel;
72
- };
73
- }) => void;
88
+ }>;
89
+ /** The configured reasoning effort — the other half of the pair a session without overrides runs on. */
90
+ thinkingLevel: ThinkingLevel;
91
+ };
92
+ type OnAssembly = (parts: PiAssemblyParts) => void;
74
93
  /** L1 options. Tier 1: model (spec) + instructions + tools. Tier 2: the injectable ports. */
75
94
  export interface CreatePiAgentOptions {
76
95
  /** Model spec "provider/modelId" (e.g. "openai-codex/gpt-5.5"), resolved against {@link models}. */
@@ -78,14 +97,18 @@ export interface CreatePiAgentOptions {
78
97
  /** Reasoning effort (pi's scale). Unset = pi's default; unsupported levels are clamped per model. */
79
98
  thinkingLevel?: ThinkingLevel;
80
99
  /**
81
- * The system prompt itself — verbatim, no engine base and no wrapping (unlike the directory path,
82
- * which assembles the engine base + AGENTS.md as segment ② + persona.md as segment ①). A plain string
83
- * or a factory re-evaluated per invoke. When {@link skills} are mounted their listing is appended.
100
+ * The system prompt itself — no engine base and no wrapping (unlike the directory path, which
101
+ * assembles the engine base + AGENTS.md as segment ② + persona.md as segment ①). A plain string or
102
+ * a factory re-evaluated per invoke. When {@link skills} are mounted their listing is appended.
103
+ *
104
+ * Not byte-for-byte verbatim: pi appends its own `Current working directory:` line to whatever
105
+ * prompt it is given. What this rung guarantees is that no engine IDENTITY is imposed — a
106
+ * hand-built agent is not told it is a coding assistant.
84
107
  */
85
108
  instructions?: string | (() => string);
86
109
  /** The tool set to mount. `FastagentTool` (AgentTool plus the optional `deferred` marker, see
87
110
  * {@link DefineToolOptions}) widens into {@link MountedTool}, which additionally admits pi's default
88
- * coding tools — they read the turn's ExecutionEnv as a fifth `execute` parameter. */
111
+ * coding tools — those bind their workspace at construction rather than reading a turn context. */
89
112
  tools?: MountedTool[];
90
113
  skills?: Skill[];
91
114
  /**
@@ -100,12 +123,15 @@ export interface CreatePiAgentOptions {
100
123
  * consulted when a provider is absent from the file (resolution order is upstream-owned).
101
124
  */
102
125
  authPath?: string;
103
- /** Session persistence. Defaults to in-memory; inject jsonlSessionStore for restart-surviving continuity. */
104
- sessions?: PiSessionStore;
105
- /** Filesystem/process environment. Defaults to a local NodeExecutionEnv at `process.cwd()`, and its
106
- * cwd is the agent's. The default coding tools (read/bash/edit/write) take it as the turn's tool
107
- * context, so injecting a constrained one narrows where the agent reads, writes and shells. It does
108
- * NOT constrain author-written `tools/`, which are code and can import anything. */
126
+ /** Session persistence. Defaults to in-memory; inject piSessionRecordStore for restart-surviving
127
+ * continuity. */
128
+ sessions?: PiSessionRecordStore;
129
+ /** Filesystem/process environment, handed to tools that read one as the turn's context. Defaults to
130
+ * a local NodeExecutionEnv at `process.cwd()`. At THIS rung nothing else consumes it: L1 loads no
131
+ * definition. It does NOT constrain the coding tools (pi's own, rooted at the workspace they were
132
+ * built for) or author-written `tools/`, which are code and can import anything. Not a
133
+ * sandbox — see {@link createPiAgentFromDefinition} for the rung where it also reads the
134
+ * definition. */
109
135
  env?: ExecutionEnv;
110
136
  /** Single-writer lease. Defaults to in-process fail-fast inProcessLease(). */
111
137
  lease?: Lease;
@@ -127,11 +153,11 @@ export interface CreatePiAgentFromDefinitionOptions {
127
153
  /** Override the engine base prompt (segment ①). Defaults to piBasePrompt({ tools, persona }) using the
128
154
  * live-read persona.md; pass base to fully opt out of persona.md. */
129
155
  base?: string;
130
- /** Override tools. Defaults to {@link piDefaultTools} (lock down with a custom list). An authored
156
+ /** Override tools. Defaults to {@link piAllCodingTools} (lock down with a custom list). An authored
131
157
  * `FastagentTool[]` (AgentTool plus the optional `deferred` marker) widens into {@link MountedTool}. */
132
158
  tools?: MountedTool[];
133
159
  /**
134
- * The agent's working directory: where the default tools operate AND whose ancestors are walked for
160
+ * The agent's working directory: where the coding tools operate AND whose ancestors are walked for
135
161
  * ② project context (AGENTS.md). Defaults to `dir`. Set it to the enclosing repo so a coding agent
136
162
  * whose definition lives in `dir` operates on — and reads the AGENTS.md of — that repo (core.md
137
163
  * scenario grid); that is what the CLI's opener does with the workspace.
@@ -145,12 +171,11 @@ export interface CreatePiAgentFromDefinitionOptions {
145
171
  * dir) — unlike the dir-less {@link createPiAgent}/{@link createPiModels}, which default global.
146
172
  */
147
173
  authPath?: string;
148
- sessions?: PiSessionStore;
149
- /** Filesystem/process environment; see {@link CreatePiAgentOptions.env}. At THIS rung it does more
150
- * than root the default tools: persona.md and skills/ are read through it too. Two surfaces stay
151
- * OUTSIDE it project context (pi's loadProjectContextFiles uses node fs directly; see
152
- * definition.ts) and author-written `tools/`, which are code and can import anything. Injecting an
153
- * env narrows the blast radius rather than closing it. */
174
+ sessions?: PiSessionRecordStore;
175
+ /** Filesystem/process environment; see {@link CreatePiAgentOptions.env}. At THIS rung it reads
176
+ * persona.md and skills/. The seven coding tools, project context (pi's
177
+ * loadProjectContextFiles uses node fs directly), and author-written `tools/` stay outside it.
178
+ * Injecting an env narrows the blast radius rather than closing it. */
154
179
  env?: ExecutionEnv;
155
180
  lease?: Lease;
156
181
  /** Observation-plane tap; see {@link CreatePiAgentOptions.observer}. */