@leuduan/lagent 0.0.0-stage → 44.0.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 (328) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +157 -2
  3. package/dist/chunks/2GCIWSOA.js +5 -0
  4. package/dist/chunks/2P47AHNK.js +7 -0
  5. package/dist/chunks/34KW6VNQ.js +1 -0
  6. package/dist/chunks/3UMZMPWW.js +1 -0
  7. package/dist/chunks/5IRF47YB.js +1 -0
  8. package/dist/chunks/6DRCKZ2C.js +1 -0
  9. package/dist/chunks/6FRNHMCV.js +1 -0
  10. package/dist/chunks/7LI64H5X.js +17 -0
  11. package/dist/chunks/7VAPNE3L.js +1 -0
  12. package/dist/chunks/ASSQZH3F.js +1 -0
  13. package/dist/chunks/B4FXK5ER.js +77 -0
  14. package/dist/chunks/BBCW2FZK.js +1 -0
  15. package/dist/chunks/BPRCULZH.js +1 -0
  16. package/dist/chunks/CANPZYTH.js +24 -0
  17. package/dist/chunks/CQEVREBT.js +1 -0
  18. package/dist/chunks/CUK7CGC7.js +1 -0
  19. package/dist/chunks/D4PQP5MA.js +3 -0
  20. package/dist/chunks/DDANMY45.js +3 -0
  21. package/dist/chunks/DDZ7YF26.js +1 -0
  22. package/dist/chunks/EMRB4KCN.js +6 -0
  23. package/dist/chunks/EPYQ5M3B.js +3 -0
  24. package/dist/chunks/FJLU4UH3.js +1 -0
  25. package/dist/chunks/G44LG6VL.js +1 -0
  26. package/dist/chunks/GGSVIIWJ.js +2 -0
  27. package/dist/chunks/HK6ZSONF.js +1 -0
  28. package/dist/chunks/IAAEP6VL.js +30 -0
  29. package/dist/chunks/JCTBX33H.js +36 -0
  30. package/dist/chunks/JFX2MXBA.js +4 -0
  31. package/dist/chunks/JFZZXVWD.js +15 -0
  32. package/dist/chunks/KUZCL2SH.js +1 -0
  33. package/dist/chunks/MHC6VPB4.js +7 -0
  34. package/dist/chunks/MMNNZCBO.js +5 -0
  35. package/dist/chunks/MNJ4SRF7.js +1 -0
  36. package/dist/chunks/N6IXG2VL.js +1 -0
  37. package/dist/chunks/OCBPT7KE.js +1 -0
  38. package/dist/chunks/OL5A6ITQ.js +1 -0
  39. package/dist/chunks/PUSUPTAT.js +1 -0
  40. package/dist/chunks/Q75FUN7D.js +2 -0
  41. package/dist/chunks/Q7S5LFGN.js +1 -0
  42. package/dist/chunks/RCIHV3KG.js +1 -0
  43. package/dist/chunks/S34ZA2R6.js +1 -0
  44. package/dist/chunks/SS3B5W34.js +12 -0
  45. package/dist/chunks/VYMT4TXD.js +1 -0
  46. package/dist/chunks/W57RW55W.js +1 -0
  47. package/dist/compositions/base.d.ts +11 -0
  48. package/dist/compositions/codex.d.ts +66 -0
  49. package/dist/compositions/codexPrompts.d.ts +56 -0
  50. package/dist/context.d.ts +109 -0
  51. package/dist/index.d.ts +55 -0
  52. package/dist/index.js +1 -0
  53. package/dist/journal/catalog.d.ts +112 -0
  54. package/dist/journal/forkChain.d.ts +16 -0
  55. package/dist/journal/index.d.ts +15 -0
  56. package/dist/journal/journal.d.ts +475 -0
  57. package/dist/journal/projection.d.ts +87 -0
  58. package/dist/journal/store.d.ts +181 -0
  59. package/dist/llm/client.d.ts +135 -0
  60. package/dist/llm/content.d.ts +52 -0
  61. package/dist/llm/failure.d.ts +82 -0
  62. package/dist/llm/index.d.ts +22 -0
  63. package/dist/llm/index.js +1 -0
  64. package/dist/llm/primitives.d.ts +286 -0
  65. package/dist/llm/prompt.d.ts +21 -0
  66. package/dist/llm/provider.d.ts +74 -0
  67. package/dist/llm/readLedger.d.ts +24 -0
  68. package/dist/llm/request.d.ts +58 -0
  69. package/dist/loop/agent.d.ts +18 -0
  70. package/dist/loop/authorization.d.ts +41 -0
  71. package/dist/loop/auxiliary.d.ts +58 -0
  72. package/dist/loop/chunks.d.ts +27 -0
  73. package/dist/loop/completion.d.ts +17 -0
  74. package/dist/loop/errors.d.ts +139 -0
  75. package/dist/loop/hooks.d.ts +274 -0
  76. package/dist/loop/index.d.ts +16 -0
  77. package/dist/loop/runner.d.ts +134 -0
  78. package/dist/loop/runtime.d.ts +76 -0
  79. package/dist/loop/strategy.d.ts +80 -0
  80. package/dist/loop/surfacePrepare.d.ts +30 -0
  81. package/dist/loop/tool.d.ts +106 -0
  82. package/dist/loop/toolCalls.d.ts +35 -0
  83. package/dist/plugin.d.ts +50 -0
  84. package/dist/plugin.js +1 -0
  85. package/dist/plugins/agentsMd.d.ts +80 -0
  86. package/dist/plugins/agentsMd.js +1 -0
  87. package/dist/plugins/ask/index.d.ts +26 -0
  88. package/dist/plugins/ask/index.js +1 -0
  89. package/dist/plugins/ask/service.d.ts +125 -0
  90. package/dist/plugins/ask/tools.d.ts +9 -0
  91. package/dist/plugins/commands/index.d.ts +43 -0
  92. package/dist/plugins/commands/index.js +1 -0
  93. package/dist/plugins/commands/output.d.ts +115 -0
  94. package/dist/plugins/commands/record.d.ts +558 -0
  95. package/dist/plugins/commands/service.d.ts +321 -0
  96. package/dist/plugins/commands/shell.d.ts +25 -0
  97. package/dist/plugins/commands/tools.d.ts +10 -0
  98. package/dist/plugins/compaction/checkpoint.d.ts +94 -0
  99. package/dist/plugins/compaction/config.d.ts +133 -0
  100. package/dist/plugins/compaction/estimate.d.ts +37 -0
  101. package/dist/plugins/compaction/index.d.ts +87 -0
  102. package/dist/plugins/compaction/index.js +7 -0
  103. package/dist/plugins/compaction/planner.d.ts +207 -0
  104. package/dist/plugins/compaction/prune.d.ts +9 -0
  105. package/dist/plugins/compaction/record.d.ts +227 -0
  106. package/dist/plugins/compaction/segments.d.ts +23 -0
  107. package/dist/plugins/compaction/state.d.ts +68 -0
  108. package/dist/plugins/compaction/summarize.d.ts +13 -0
  109. package/dist/plugins/dateAndBranch.d.ts +47 -0
  110. package/dist/plugins/dateAndBranch.js +1 -0
  111. package/dist/plugins/delegations/answers.d.ts +39 -0
  112. package/dist/plugins/delegations/assignmentKey.d.ts +22 -0
  113. package/dist/plugins/delegations/cleanup.d.ts +161 -0
  114. package/dist/plugins/delegations/constraint.d.ts +76 -0
  115. package/dist/plugins/delegations/index.d.ts +39 -0
  116. package/dist/plugins/delegations/index.js +1 -0
  117. package/dist/plugins/delegations/notices.d.ts +261 -0
  118. package/dist/plugins/delegations/obligations.d.ts +210 -0
  119. package/dist/plugins/delegations/record.d.ts +633 -0
  120. package/dist/plugins/delegations/request.d.ts +384 -0
  121. package/dist/plugins/delegations/role.d.ts +30 -0
  122. package/dist/plugins/delegations/service.d.ts +563 -0
  123. package/dist/plugins/delegations/standing.d.ts +19 -0
  124. package/dist/plugins/delegations/stopCheck.d.ts +21 -0
  125. package/dist/plugins/delegations/tools.d.ts +71 -0
  126. package/dist/plugins/delegations/waitContracts.d.ts +118 -0
  127. package/dist/plugins/delegations/waitResolver.d.ts +116 -0
  128. package/dist/plugins/diagnostics/digest.d.ts +14 -0
  129. package/dist/plugins/diagnostics/index.d.ts +68 -0
  130. package/dist/plugins/diagnostics/index.js +1 -0
  131. package/dist/plugins/fileTools/config.d.ts +10 -0
  132. package/dist/plugins/fileTools/editFiles.d.ts +117 -0
  133. package/dist/plugins/fileTools/fsRead.d.ts +17 -0
  134. package/dist/plugins/fileTools/gitDiscovery.d.ts +9 -0
  135. package/dist/plugins/fileTools/index.d.ts +18 -0
  136. package/dist/plugins/fileTools/index.js +1 -0
  137. package/dist/plugins/fileTools/ripgrep.d.ts +20 -0
  138. package/dist/plugins/fileTools/textEdit.d.ts +67 -0
  139. package/dist/plugins/fileTools/tools.d.ts +6 -0
  140. package/dist/plugins/historyRecall/history.d.ts +9 -0
  141. package/dist/plugins/historyRecall/index.d.ts +31 -0
  142. package/dist/plugins/historyRecall/index.js +1 -0
  143. package/dist/plugins/historyRecall/render.d.ts +34 -0
  144. package/dist/plugins/historyRecall/tools.d.ts +4 -0
  145. package/dist/plugins/mcp/catalog.d.ts +36 -0
  146. package/dist/plugins/mcp/config.d.ts +63 -0
  147. package/dist/plugins/mcp/connection.d.ts +53 -0
  148. package/dist/plugins/mcp/errors.d.ts +32 -0
  149. package/dist/plugins/mcp/index.d.ts +33 -0
  150. package/dist/plugins/mcp/index.js +5 -0
  151. package/dist/plugins/mcp/mount.d.ts +98 -0
  152. package/dist/plugins/mcp/names.d.ts +25 -0
  153. package/dist/plugins/mcp/render.d.ts +29 -0
  154. package/dist/plugins/mcp/slots.d.ts +15 -0
  155. package/dist/plugins/mcp/stdio.d.ts +49 -0
  156. package/dist/plugins/mcp/tools.d.ts +41 -0
  157. package/dist/plugins/mcp/version.d.ts +2 -0
  158. package/dist/plugins/routeNotice.d.ts +22 -0
  159. package/dist/plugins/routeNotice.js +1 -0
  160. package/dist/plugins/sandbox/absent.d.ts +33 -0
  161. package/dist/plugins/sandbox/client.d.ts +39 -0
  162. package/dist/plugins/sandbox/files.d.ts +28 -0
  163. package/dist/plugins/sandbox/index.d.ts +52 -0
  164. package/dist/plugins/sandbox/index.js +4 -0
  165. package/dist/plugins/sandbox/mode.d.ts +57 -0
  166. package/dist/plugins/sandbox/policy.d.ts +163 -0
  167. package/dist/plugins/sandbox/protocol.d.ts +107 -0
  168. package/dist/plugins/sandbox/service.d.ts +153 -0
  169. package/dist/plugins/sandbox/worker.d.ts +12 -0
  170. package/dist/plugins/sandbox/worker.js +1 -0
  171. package/dist/plugins/schedules/index.d.ts +21 -0
  172. package/dist/plugins/schedules/index.js +5 -0
  173. package/dist/plugins/schedules/record.d.ts +396 -0
  174. package/dist/plugins/schedules/service.d.ts +120 -0
  175. package/dist/plugins/schedules/time.d.ts +26 -0
  176. package/dist/plugins/schedules/tools.d.ts +6 -0
  177. package/dist/plugins/skills/discovery.d.ts +83 -0
  178. package/dist/plugins/skills/index.d.ts +31 -0
  179. package/dist/plugins/skills/index.js +1 -0
  180. package/dist/plugins/skills/tools.d.ts +11 -0
  181. package/dist/plugins/subAgents/availableRoutes.d.ts +53 -0
  182. package/dist/plugins/subAgents/index.d.ts +67 -0
  183. package/dist/plugins/subAgents/index.js +1 -0
  184. package/dist/plugins/subAgents/tools.d.ts +67 -0
  185. package/dist/plugins/threadDirs.d.ts +36 -0
  186. package/dist/plugins/threadDirs.js +1 -0
  187. package/dist/plugins/toolPolicy/index.d.ts +61 -0
  188. package/dist/plugins/toolPolicy/index.js +1 -0
  189. package/dist/plugins/truncateToolOutput.d.ts +30 -0
  190. package/dist/plugins/truncateToolOutput.js +6 -0
  191. package/dist/plugins/usage/index.d.ts +26 -0
  192. package/dist/plugins/usage/index.js +1 -0
  193. package/dist/plugins/usage/tracker.d.ts +34 -0
  194. package/dist/plugins/verify/index.d.ts +27 -0
  195. package/dist/plugins/verify/index.js +6 -0
  196. package/dist/plugins/verify/judgement.d.ts +16 -0
  197. package/dist/plugins/verify/record.d.ts +382 -0
  198. package/dist/plugins/verify/service.d.ts +93 -0
  199. package/dist/plugins/verify/state.d.ts +58 -0
  200. package/dist/plugins/webTools/html.d.ts +23 -0
  201. package/dist/plugins/webTools/index.d.ts +34 -0
  202. package/dist/plugins/webTools/index.js +1 -0
  203. package/dist/plugins/webTools/network.d.ts +23 -0
  204. package/dist/plugins/webTools/web.d.ts +32 -0
  205. package/dist/plugins/workflows/assignment.d.ts +20 -0
  206. package/dist/plugins/workflows/cleanup.d.ts +38 -0
  207. package/dist/plugins/workflows/definition.d.ts +184 -0
  208. package/dist/plugins/workflows/entryPlan.d.ts +95 -0
  209. package/dist/plugins/workflows/hostBindings.d.ts +146 -0
  210. package/dist/plugins/workflows/index.d.ts +28 -0
  211. package/dist/plugins/workflows/index.js +11 -0
  212. package/dist/plugins/workflows/observations.d.ts +81 -0
  213. package/dist/plugins/workflows/participantModels.d.ts +28 -0
  214. package/dist/plugins/workflows/participants.d.ts +143 -0
  215. package/dist/plugins/workflows/policy.d.ts +112 -0
  216. package/dist/plugins/workflows/record.d.ts +2849 -0
  217. package/dist/plugins/workflows/routing.d.ts +116 -0
  218. package/dist/plugins/workflows/schema.d.ts +26 -0
  219. package/dist/plugins/workflows/service.d.ts +477 -0
  220. package/dist/plugins/workflows/state.d.ts +373 -0
  221. package/dist/plugins/workflows/stopCheck.d.ts +13 -0
  222. package/dist/plugins/workflows/tools.d.ts +13 -0
  223. package/dist/plugins/workflows/view.d.ts +103 -0
  224. package/dist/plugins/workflows/workStatus.d.ts +21 -0
  225. package/dist/plugins/workspaceNotice.d.ts +36 -0
  226. package/dist/plugins/workspaceNotice.js +1 -0
  227. package/dist/providers/anthropic.d.ts +178 -0
  228. package/dist/providers/anthropicMessages.d.ts +66 -0
  229. package/dist/providers/codex.d.ts +71 -0
  230. package/dist/providers/codexAuth.d.ts +116 -0
  231. package/dist/providers/deepseek.d.ts +59 -0
  232. package/dist/providers/failure.d.ts +23 -0
  233. package/dist/providers/gateway.d.ts +24 -0
  234. package/dist/providers/index.d.ts +18 -0
  235. package/dist/providers/index.js +6 -0
  236. package/dist/providers/openaiChat.d.ts +73 -0
  237. package/dist/providers/openaiResponses.d.ts +109 -0
  238. package/dist/providers/opencodeCopilot.d.ts +23 -0
  239. package/dist/providers/opencodeGo.d.ts +109 -0
  240. package/dist/providers/shared.d.ts +112 -0
  241. package/dist/providers/stream.d.ts +156 -0
  242. package/dist/records/index.d.ts +13 -0
  243. package/dist/records/index.js +1 -0
  244. package/dist/records/journal.d.ts +2968 -0
  245. package/dist/records/toolResult.d.ts +65 -0
  246. package/dist/services/agents.d.ts +62 -0
  247. package/dist/services/catalogContributions.d.ts +73 -0
  248. package/dist/services/confinement/files.d.ts +118 -0
  249. package/dist/services/confinement/service.d.ts +219 -0
  250. package/dist/services/core.d.ts +28 -0
  251. package/dist/services/extensionEvents.d.ts +181 -0
  252. package/dist/services/journal.d.ts +26 -0
  253. package/dist/services/llm.d.ts +82 -0
  254. package/dist/services/modes.d.ts +65 -0
  255. package/dist/services/plugins.d.ts +34 -0
  256. package/dist/services/presets/definition.d.ts +154 -0
  257. package/dist/services/presets/installations.d.ts +139 -0
  258. package/dist/services/prompts.d.ts +85 -0
  259. package/dist/services/threads/activation.d.ts +100 -0
  260. package/dist/services/threads/admission.d.ts +174 -0
  261. package/dist/services/threads/birth.d.ts +219 -0
  262. package/dist/services/threads/index.d.ts +14 -0
  263. package/dist/services/threads/runEvents.d.ts +79 -0
  264. package/dist/services/threads/runOwner.d.ts +368 -0
  265. package/dist/services/threads/service.d.ts +450 -0
  266. package/dist/services/threads/thread.d.ts +268 -0
  267. package/dist/services/threads/view.d.ts +93 -0
  268. package/dist/services/tools.d.ts +118 -0
  269. package/dist/state/birth.d.ts +62 -0
  270. package/dist/state/chain.d.ts +46 -0
  271. package/dist/state/confirmations.d.ts +64 -0
  272. package/dist/state/continuation.d.ts +167 -0
  273. package/dist/state/decide.d.ts +72 -0
  274. package/dist/state/dispatches.d.ts +54 -0
  275. package/dist/state/errors.d.ts +26 -0
  276. package/dist/state/forks.d.ts +61 -0
  277. package/dist/state/holds.d.ts +104 -0
  278. package/dist/state/inbox.d.ts +188 -0
  279. package/dist/state/index.d.ts +31 -0
  280. package/dist/state/inputs.d.ts +58 -0
  281. package/dist/state/installations.d.ts +28 -0
  282. package/dist/state/limits.d.ts +14 -0
  283. package/dist/state/prompt.d.ts +13 -0
  284. package/dist/state/recovery.d.ts +7 -0
  285. package/dist/state/replace.d.ts +33 -0
  286. package/dist/state/requests.d.ts +129 -0
  287. package/dist/state/route.d.ts +61 -0
  288. package/dist/state/summary.d.ts +16 -0
  289. package/dist/state/surface.d.ts +153 -0
  290. package/dist/state/surfaceRead.d.ts +20 -0
  291. package/dist/state/thread.d.ts +73 -0
  292. package/dist/state/turns.d.ts +87 -0
  293. package/dist/state/waits.d.ts +38 -0
  294. package/dist/state/wake.d.ts +32 -0
  295. package/dist/stores/durableObject.d.ts +23 -0
  296. package/dist/stores/durableObject.js +1 -0
  297. package/dist/stores/durableObjectConnection.d.ts +27 -0
  298. package/dist/stores/memory.d.ts +29 -0
  299. package/dist/stores/sql.d.ts +59 -0
  300. package/dist/stores/sqlite.d.ts +31 -0
  301. package/dist/stores/sqlite.js +1 -0
  302. package/dist/sys/environment.d.ts +42 -0
  303. package/dist/sys/git.d.ts +47 -0
  304. package/dist/sys/paths.d.ts +9 -0
  305. package/dist/sys/spawn.d.ts +186 -0
  306. package/dist/testing/clock.d.ts +17 -0
  307. package/dist/testing/fakeLlm.d.ts +76 -0
  308. package/dist/testing/fedLlm.d.ts +34 -0
  309. package/dist/testing/helpers.d.ts +362 -0
  310. package/dist/testing/index.d.ts +13 -0
  311. package/dist/testing/index.js +1 -0
  312. package/dist/testing/processes.d.ts +13 -0
  313. package/dist/testing/settlement.d.ts +6 -0
  314. package/dist/testing/tmpDirs.d.ts +17 -0
  315. package/dist/util/async.d.ts +8 -0
  316. package/dist/util/diff.d.ts +25 -0
  317. package/dist/util/dispatch.d.ts +8 -0
  318. package/dist/util/errors.d.ts +28 -0
  319. package/dist/util/foldState.d.ts +17 -0
  320. package/dist/util/freeze.d.ts +2 -0
  321. package/dist/util/ids.d.ts +2 -0
  322. package/dist/util/json.d.ts +37 -0
  323. package/dist/util/jsonSchema.d.ts +7 -0
  324. package/dist/util/log.d.ts +6 -0
  325. package/dist/util/retries.d.ts +25 -0
  326. package/dist/util/text.d.ts +21 -0
  327. package/dist/util/timers.d.ts +43 -0
  328. package/package.json +183 -3
@@ -0,0 +1,47 @@
1
+ /** Variables that select a repository, an index or an object store other than the working directory's. */
2
+ export declare const GIT_REPOSITORY_VARIABLES: readonly ["GIT_DIR", "GIT_WORK_TREE", "GIT_INDEX_FILE", "GIT_OBJECT_DIRECTORY", "GIT_ALTERNATE_OBJECT_DIRECTORIES", "GIT_COMMON_DIR", "GIT_NAMESPACE"];
3
+ /**
4
+ * Where a repository keeps its metadata, as found from a path in its working tree. Read from the
5
+ * filesystem alone, without running git, so it costs a few `stat`s and runs nothing the repository
6
+ * configures.
7
+ */
8
+ export type RepositoryLocation = {
9
+ /** The working tree's top directory: the one holding `.git`. */
10
+ readonly worktree: string;
11
+ /**
12
+ * The `.git` entry itself, with its symbolic links resolved: the git directory, or the pointer
13
+ * file a linked worktree or a submodule has, under whatever name it really has.
14
+ */
15
+ readonly dotGit: string;
16
+ /** The git directory: `.git` itself, or the `gitdir:` target its pointer file names. */
17
+ readonly gitDir: string;
18
+ /**
19
+ * The shared git directory the git directory's `commondir` names, as a linked worktree's does;
20
+ * else `null`.
21
+ */
22
+ readonly commonDir: string | null;
23
+ };
24
+ /**
25
+ * The repository containing `path`: the nearest directory at or above it holding a `.git` entry,
26
+ * so a nested repository is found before the one around it. `path` need not exist. The walk starts
27
+ * from `path` with its symbolic links resolved, as git's own discovery does from the physical
28
+ * working directory, so a workspace reached through a link is found in the repository it lives in,
29
+ * not among the link's own parents; the worktree, git and common directories are given resolved
30
+ * too. A `.git` file that names no git directory is taken as its own, so it still marks the
31
+ * repository. `null` outside every repository.
32
+ */
33
+ export declare function findRepository(path: string): RepositoryLocation | null;
34
+ /** What a repository's `HEAD` names: a branch, or a commit it is detached at. */
35
+ export type GitHead = {
36
+ readonly kind: 'branch';
37
+ readonly name: string;
38
+ } | {
39
+ readonly kind: 'detached';
40
+ readonly commit: string;
41
+ };
42
+ /**
43
+ * The `HEAD` of the worktree `repository` locates, read from its git directory without running git:
44
+ * a branch by its short name (`ref: refs/heads/main` is `main`, another ref its full name), a commit
45
+ * id as a detached head at its first seven digits; `null` when it cannot be read or says neither.
46
+ */
47
+ export declare function readHead(repository: RepositoryLocation): GitHead | null;
@@ -0,0 +1,9 @@
1
+ /** Whether `candidate` is `root` or a path inside it, by whole segments: `/a/bc` is not inside `/a/b`. Both normalized. */
2
+ export declare const isWithin: (candidate: string, root: string) => boolean;
3
+ /** A path as results show it: relative to the cwd inside it, absolute outside it. */
4
+ export declare function displayPath(cwd: string, path: string): string;
5
+ /**
6
+ * `path` normalized, refused when relative: a relative path would mean the process's directory,
7
+ * which is the host's to choose. `what` names the setting in the error.
8
+ */
9
+ export declare function absolutePath(path: string, what: string): string;
@@ -0,0 +1,186 @@
1
+ import type { Readable, Writable } from 'node:stream';
2
+ /**
3
+ * Process containment for everything lagent runs: one process group per command, a bounded stop,
4
+ * and cleanup however lagent ends. POSIX only.
5
+ *
6
+ * Every command is spawned detached, so it leads a new session and process group whose id is its
7
+ * pid, with no controlling terminal. A short `/bin/sh` wrapper holds it at a startup gate until the
8
+ * group is registered with the exit listener and the reaper, joins stderr into stdout unless the
9
+ * streams are wired as separate pipes, and then `exec`s the command, so the leader keeps the pid
10
+ * and therefore the group. If lagent dies before the gate opens, the wrapper reads EOF and runs
11
+ * nothing. Nothing is inherited implicitly: every spawn names its whole environment.
12
+ *
13
+ * Process-wide, because process exit is: the exit listener and the reaper are installed with the
14
+ * first spawn and shared by every root in the process. Stopping commands while the process lives
15
+ * is their owners' job, through the signal every spawn requires.
16
+ */
17
+ /** How long SIGTERM gets before SIGKILL, and SIGKILL before a stop is reported failed. */
18
+ export declare const DEFAULT_KILL_GRACE_MS = 3000;
19
+ /** A command never passed its startup gate; a wrapper group may still need cleanup. */
20
+ export declare class CommandStartFailure extends Error {
21
+ readonly stopFailed: boolean;
22
+ readonly code: string | undefined;
23
+ constructor(cause: unknown, cleanup: {
24
+ readonly stopFailed: boolean;
25
+ });
26
+ }
27
+ /**
28
+ * A process's whole environment; an `undefined` value leaves the variable unset. lagent never
29
+ * builds one from its own: a host does (`sys/environment`), and every spawn passes one.
30
+ */
31
+ export type SpawnEnvironment = Readonly<Record<string, string | undefined>>;
32
+ /**
33
+ * How the command's standard streams are wired. `joined`: no input, and stderr joined into stdout
34
+ * as one `output` stream, in exact order. `pipes`: a writable stdin and separate stdout and stderr,
35
+ * for a process that speaks a protocol on its standard streams.
36
+ */
37
+ export type SpawnStdio = 'joined' | 'pipes';
38
+ export type SpawnOptions = {
39
+ /** A shell command line, run by `/bin/sh -c`, or an argv run without a shell. */
40
+ command: string | readonly [string, ...string[]];
41
+ cwd: string;
42
+ /**
43
+ * The command's whole environment, passed as it is. An argv's program is resolved through its
44
+ * `PATH`, or the shell's default search path when it has none.
45
+ */
46
+ env: SpawnEnvironment;
47
+ /** Defaults to `joined`. */
48
+ stdio?: SpawnStdio;
49
+ /** The owner: aborting it stops the command's group within the bound. */
50
+ signal: AbortSignal;
51
+ /** Stops the group when this elapses; omitted for a command meant to outlive its call. */
52
+ timeoutMs?: number;
53
+ killGraceMs?: number;
54
+ /**
55
+ * Awaited after the group is registered and before the gate opens, with the group's id: what a
56
+ * caller must have durable before the command runs — a record that it may have started, say — goes
57
+ * here. A rejection kills the group, which has run nothing, and rejects the spawn.
58
+ */
59
+ beforeRelease?: (pgid: number) => void | Promise<void>;
60
+ };
61
+ /** Why lagent stopped a group: its deadline, its owner's signal, or an explicit `stop()`. */
62
+ export type StopCause = 'timeout' | 'abort' | 'stop';
63
+ export type SpawnResult = {
64
+ /** `null` when the leader never exited, or was killed by a signal. */
65
+ exitCode: number | null;
66
+ exitSignal: NodeJS.Signals | null;
67
+ /** `null` when the leader exited on its own. */
68
+ stoppedBy: StopCause | null;
69
+ /** The leader exited leaving processes in its group, and they were stopped. */
70
+ leftoversStopped: boolean;
71
+ /**
72
+ * A live process remained in the group when the bound ran out. The group stays tracked by the
73
+ * exit listener and the reaper, and is polled until it empties.
74
+ */
75
+ stopFailed: boolean;
76
+ durationMs: number;
77
+ };
78
+ /** A spawned process group, whichever way its streams are wired. */
79
+ export interface SpawnedGroup {
80
+ readonly pid: number;
81
+ /**
82
+ * Settles within `2 × killGraceMs` of the deadline, the abort, `stop()`, or the leader exiting
83
+ * with processes left behind, and sooner once the leader, the group and the pipe are all done.
84
+ * Never rejects.
85
+ */
86
+ readonly result: Promise<SpawnResult>;
87
+ /** Stops the group, as an abort would, and resolves with `result`. */
88
+ stop(): Promise<SpawnResult>;
89
+ }
90
+ /** A group spawned with `stdio: 'joined'`. */
91
+ export interface SpawnedCommand extends SpawnedGroup {
92
+ /** stdout with stderr joined, in exact order. Destroyed once the command settles. */
93
+ readonly output: Readable;
94
+ }
95
+ /**
96
+ * A group spawned with `stdio: 'pipes'`. Every stream is destroyed once the command settles.
97
+ *
98
+ * Read stdout and stderr continuously, from the start, even when only one matters. A child blocks
99
+ * on a write once that pipe's buffer fills, so an unread stderr eventually hangs a process that
100
+ * only logs to it. Keep a bounded tail if the content is not needed.
101
+ */
102
+ export interface SpawnedPipes extends SpawnedGroup {
103
+ readonly stdin: Writable;
104
+ readonly stdout: Readable;
105
+ readonly stderr: Readable;
106
+ }
107
+ /**
108
+ * Spawns a command in a process group of its own. Resolves once the group is registered,
109
+ * `beforeRelease` has settled and the command released; rejects, having run nothing, when it cannot
110
+ * be spawned or registered, when `beforeRelease` rejects, or when `signal` aborts first.
111
+ * Each rejection owns a `CommandStartFailure` recording cleanup of its gated wrapper, with the
112
+ * original failure as its cause.
113
+ */
114
+ export declare function spawnCommand(options: SpawnOptions & {
115
+ stdio?: 'joined';
116
+ }): Promise<SpawnedCommand>;
117
+ export declare function spawnCommand(options: SpawnOptions & {
118
+ stdio: 'pipes';
119
+ }): Promise<SpawnedPipes>;
120
+ export declare function spawnCommand(options: SpawnOptions): Promise<SpawnedCommand | SpawnedPipes>;
121
+ /**
122
+ * Runs a command to completion and collects its output: for tools that need a command's answer,
123
+ * not its stream. Output is held in memory, so use it only for commands whose output is bounded.
124
+ */
125
+ export declare function runToCompletion(options: SpawnOptions & {
126
+ stdio?: 'joined';
127
+ }): Promise<SpawnResult & {
128
+ output: string;
129
+ }>;
130
+ /** How {@link readLines} hands a command's stdout over. */
131
+ export type LineReader = {
132
+ /**
133
+ * Called with each line of stdout, without its delimiter, as it arrives. Returning `false` stops the
134
+ * group: no later line is delivered, and the result reports `stoppedBy: 'stop'`.
135
+ */
136
+ onLine: (line: string, clipped: boolean) => boolean | void;
137
+ /**
138
+ * What ends a line: a newline, or NUL for output whose records may hold a newline, such as paths
139
+ * printed with `--null`.
140
+ */
141
+ delimiter: '\n' | '\0';
142
+ /** A longer line reaches `onLine` cut to this many characters, with `clipped` set; the rest is never held. */
143
+ maxLineChars: number;
144
+ };
145
+ /**
146
+ * Hands a spawned command's stdout to `onLine` line by line, holding at most one line, and waits for
147
+ * the command to end: for output whose size is not bounded, such as a search's, where the caller
148
+ * stops the command once it has what it needs. The command gets no input. stderr is read separately
149
+ * and kept as a bounded tail, for diagnostics.
150
+ */
151
+ export declare function readLines(command: SpawnedPipes, reader: LineReader): Promise<SpawnResult & {
152
+ stderr: string;
153
+ }>;
154
+ /** Whether any process remains in the group; a zombie still counts. */
155
+ export declare function groupAlive(pgid: number): boolean;
156
+ /** Live groups, as the exit listener and the reaper know them. One per process. */
157
+ declare class Containment {
158
+ private readonly groups;
159
+ private readonly stuck;
160
+ private reaper;
161
+ private exitListener;
162
+ private watcher;
163
+ /**
164
+ * Adds a group to the exit listener's set and the reaper's. A reaper that died is replaced and
165
+ * given every live group; this fails only when its replacement fails too.
166
+ */
167
+ register(pgid: number): Promise<void>;
168
+ /** Forgets a group proven empty. A reaper that misses the line is replaced from `groups` anyway. */
169
+ unregister(pgid: number): void;
170
+ /** Keeps a group whose stop failed tracked, polling it until it empties. */
171
+ watchUntilEmpty(pgid: number): void;
172
+ /** The groups currently tracked, for tests and diagnostics. */
173
+ tracked(): number[];
174
+ /** The current reaper's pid, for tests. */
175
+ reaperPid(): number | undefined;
176
+ /** Kills the current reaper, as the OOM killer might, for tests. */
177
+ killReaper(): void;
178
+ private ensureReaper;
179
+ /** A reaper that died while lagent lives is replaced at once, seeded with every live group. */
180
+ private onReaperExit;
181
+ /** Node runs nothing asynchronous in `exit`, so this is a synchronous SIGKILL of every live group. */
182
+ private installExitListener;
183
+ }
184
+ /** The process's containment state; exported for tests. */
185
+ export declare const containment: Containment;
186
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { Clock } from '../util/timers.js';
2
+ /**
3
+ * A {@link Clock} a test moves by hand. Wall time and elapsed time move apart: `advance` moves
4
+ * both, as time passing does; `jump` sets the wall clock forward or back without any timer
5
+ * noticing, as a clock change does; `elapse` lets timers run without the wall clock moving.
6
+ */
7
+ export type ManualClock = Clock & {
8
+ /** Lets `ms` pass: the wall clock moves, and every timer due by then fires, in order. */
9
+ advance(ms: number): void;
10
+ /** Moves the wall clock by `ms`, either way; no timer fires. */
11
+ jump(ms: number): void;
12
+ /** Lets `ms` of timer time pass with the wall clock standing still. */
13
+ elapse(ms: number): void;
14
+ /** The delay of each pending timer from now, soonest first. */
15
+ pending(): number[];
16
+ };
17
+ export declare function manualClock(start?: number): ManualClock;
@@ -0,0 +1,76 @@
1
+ import type { z } from 'zod';
2
+ import type { ConversationMessage, LLMStreamChunk, MalformedToolCall, ModelResponse, ResponseFinish } from '../llm/primitives.js';
3
+ import type { LLMClient, StreamingLLMResponse } from '../llm/client.js';
4
+ import type { ModelRequest } from '../llm/request.js';
5
+ import { LLMStreamChunkSchema } from '../llm/primitives.js';
6
+ /** A chunk as a test writes one: anything the schema defaults may be left out. */
7
+ export type FakeChunk = z.input<typeof LLMStreamChunkSchema>;
8
+ /** Every request the fake was handed, exactly as the loop built it. */
9
+ export type FakeChatRequest = ModelRequest;
10
+ /**
11
+ * A canned reply: a message, a message streamed as `chunks`, or `chunks` followed by a `failure`
12
+ * that `completed()` throws, as an adapter throws a `ResponseSettlementError` for a response it
13
+ * could not settle.
14
+ */
15
+ export type FakeChatReply = ConversationMessage | {
16
+ chunks: FakeChunk[];
17
+ message: ConversationMessage;
18
+ } | {
19
+ chunks: FakeChunk[];
20
+ failure: Error;
21
+ };
22
+ export type FakeChatHandler = (messages: ModelRequest['messages'], request: ModelRequest) => FakeChatReply | Promise<FakeChatReply>;
23
+ /** How a {@link FakeStream} settles: with the message, with a whole response, or by throwing the failure. */
24
+ type FakeSettlement = ConversationMessage | ModelResponse | Error;
25
+ export interface FakeStreamOptions {
26
+ readonly finish?: ResponseFinish;
27
+ readonly readFailure?: boolean;
28
+ }
29
+ /**
30
+ * A response stream that keeps the reader rules a real adapter does (see `StreamingLLMResponse`): it
31
+ * is read once, `completed()` drains it when unread, reports the outcome of a read that ended (a
32
+ * failed read throws its failure again) and throws while a read is under way. `chunks` is any
33
+ * source, so a test can feed one live; `settled` is what `completed()` gives for a read that ran
34
+ * through or was left early, read when asked so it can depend on the source: a message (or a whole
35
+ * response, finish included), or an error thrown as an adapter throws a `ResponseSettlementError`. `options.readFailure` makes the error be
36
+ * thrown by the read, after the chunks, as a transport failure is; `options.finish` is the reply's
37
+ * finish, `completed` otherwise. Unlike a real adapter, a reader that left early still gets the whole
38
+ * message.
39
+ */
40
+ export declare class FakeStream implements StreamingLLMResponse {
41
+ private claimed;
42
+ private readonly ledger;
43
+ private failure;
44
+ private readonly chunks;
45
+ private readonly settled;
46
+ private readonly options;
47
+ constructor(chunks: Iterable<FakeChunk> | AsyncIterable<FakeChunk>, settled: FakeSettlement | (() => FakeSettlement), options?: FakeStreamOptions);
48
+ [Symbol.asyncIterator](): AsyncIterator<LLMStreamChunk>;
49
+ private read;
50
+ private settlement;
51
+ completed(): Promise<ModelResponse>;
52
+ }
53
+ /** Scripted stand-in for an LLM provider: the handler inspects the conversation and picks a canned reply. */
54
+ export declare class FakeLLMClient implements LLMClient {
55
+ readonly providerName = "fake";
56
+ readonly requests: FakeChatRequest[];
57
+ private readonly handler;
58
+ constructor(handler: FakeChatHandler);
59
+ /** Replies in order; an extra call throws so unexpected loops fail loudly. */
60
+ static scripted(...responses: ConversationMessage[]): FakeLLMClient;
61
+ chat(request: ModelRequest): Promise<StreamingLLMResponse>;
62
+ }
63
+ export declare const assistant: (content: string, extra?: Partial<ConversationMessage>) => ConversationMessage;
64
+ /** A reply asking for `toolCalls`; omitted arguments are `{}`, and a malformed call stays malformed. */
65
+ export declare const withToolCalls: (toolCalls: ({
66
+ call_id: string;
67
+ name: string;
68
+ arguments?: Record<string, unknown>;
69
+ } | MalformedToolCall)[], content?: string | null) => ConversationMessage;
70
+ /**
71
+ * A response that streams one chunk, calls `streamed`, and then waits until `request` is aborted
72
+ * without ending: a connection that goes quiet mid-response. A test that restarts the host while it
73
+ * waits finds the model request unanswered.
74
+ */
75
+ export declare function stallingStream(request: ModelRequest, streamed: () => void): FakeStream;
76
+ export {};
@@ -0,0 +1,34 @@
1
+ import type { ConversationMessage } from '../llm/primitives.js';
2
+ import type { LLMClient, StreamingLLMResponse } from '../llm/client.js';
3
+ import type { ModelRequest } from '../llm/request.js';
4
+ import { type FakeChunk } from './fakeLlm.js';
5
+ /** One model call whose stream the test feeds: `push` chunks, then `finish` or `fail`. */
6
+ export declare class FedCall {
7
+ readonly request: ModelRequest;
8
+ private readonly queue;
9
+ private ended;
10
+ /** The text fed so far, which a cut-off reply carries. */
11
+ private text;
12
+ private wake;
13
+ constructor(request: ModelRequest);
14
+ push(chunk: FakeChunk): void;
15
+ finish(content: string, extra?: Partial<ConversationMessage>): void;
16
+ fail(error: unknown): void;
17
+ /**
18
+ * Reads what the test feeds, as a response stream keeps the reader rules: a failure ends the read
19
+ * and is what `completed()` throws, a cancel ends it quietly with what arrived as a cut-off reply,
20
+ * and a reader that stops before `finish` gets no answer.
21
+ */
22
+ readonly stream: StreamingLLMResponse;
23
+ private feed;
24
+ }
25
+ /** A provider whose every call is a {@link FedCall}, handed to the test in order. */
26
+ export declare class FedLLM implements LLMClient {
27
+ readonly providerName = "fake";
28
+ readonly calls: FedCall[];
29
+ private readonly waiting;
30
+ private taken;
31
+ chat(request: ModelRequest): Promise<StreamingLLMResponse>;
32
+ /** The next call the loop makes, once it has made it. */
33
+ next(): Promise<FedCall>;
34
+ }