@leuduan/lagent 0.0.0-stage → 0.1.2

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 (327) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +144 -2
  3. package/dist/chunks/2O7ZGEIT.js +1 -0
  4. package/dist/chunks/2OSESBIL.js +1 -0
  5. package/dist/chunks/34KW6VNQ.js +1 -0
  6. package/dist/chunks/37YOGDGY.js +1 -0
  7. package/dist/chunks/3LQHQRIU.js +6 -0
  8. package/dist/chunks/3QCW4WDJ.js +1 -0
  9. package/dist/chunks/4XVRUSCQ.js +1 -0
  10. package/dist/chunks/6ECI2GGV.js +1 -0
  11. package/dist/chunks/74HKUGRR.js +1 -0
  12. package/dist/chunks/ADHERZLW.js +2 -0
  13. package/dist/chunks/AP6Q4EPT.js +36 -0
  14. package/dist/chunks/BM3S37EZ.js +1 -0
  15. package/dist/chunks/C5LYCXJG.js +1 -0
  16. package/dist/chunks/CDQG7RKA.js +1 -0
  17. package/dist/chunks/D7E6EWIE.js +3 -0
  18. package/dist/chunks/DDANMY45.js +3 -0
  19. package/dist/chunks/DRYAN665.js +1 -0
  20. package/dist/chunks/DXFXAYDN.js +17 -0
  21. package/dist/chunks/EGZI4XQX.js +24 -0
  22. package/dist/chunks/ENWFSU27.js +41 -0
  23. package/dist/chunks/G6RXC3AL.js +1 -0
  24. package/dist/chunks/G74AGRAJ.js +15 -0
  25. package/dist/chunks/GQGNVSKB.js +1 -0
  26. package/dist/chunks/IJ2WNMD5.js +7 -0
  27. package/dist/chunks/J5S4URAW.js +1 -0
  28. package/dist/chunks/JPZFKSWT.js +1 -0
  29. package/dist/chunks/KESCTXGO.js +5 -0
  30. package/dist/chunks/L3N4FIEN.js +1 -0
  31. package/dist/chunks/NAOUTU7A.js +4 -0
  32. package/dist/chunks/NDIM7MEW.js +1 -0
  33. package/dist/chunks/O4PPOM5Z.js +2 -0
  34. package/dist/chunks/OVZFGILJ.js +1 -0
  35. package/dist/chunks/P5ZHHOOM.js +6 -0
  36. package/dist/chunks/PUSUPTAT.js +1 -0
  37. package/dist/chunks/QMMLQJBS.js +1 -0
  38. package/dist/chunks/RK3VP2Q4.js +3 -0
  39. package/dist/chunks/SGGMBSBA.js +1 -0
  40. package/dist/chunks/SL2YLB2F.js +1 -0
  41. package/dist/chunks/TOOIB6J2.js +1 -0
  42. package/dist/chunks/TYTQRLTX.js +1 -0
  43. package/dist/chunks/UC3FVVJ2.js +5 -0
  44. package/dist/chunks/UCTEU62F.js +1 -0
  45. package/dist/chunks/UD3VJER6.js +1 -0
  46. package/dist/chunks/UKXMCHHT.js +1 -0
  47. package/dist/chunks/WUUKTSRT.js +7 -0
  48. package/dist/chunks/X65X4KP5.js +7 -0
  49. package/dist/chunks/YIR5MYGU.js +1 -0
  50. package/dist/chunks/YLNJXQ3Z.js +1 -0
  51. package/dist/context.d.ts +101 -0
  52. package/dist/index.d.ts +47 -0
  53. package/dist/index.js +77 -0
  54. package/dist/journal/catalog.d.ts +112 -0
  55. package/dist/journal/forkChain.d.ts +16 -0
  56. package/dist/journal/index.d.ts +15 -0
  57. package/dist/journal/journal.d.ts +475 -0
  58. package/dist/journal/projection.d.ts +87 -0
  59. package/dist/journal/store.d.ts +181 -0
  60. package/dist/kit/claim.d.ts +13 -0
  61. package/dist/kit/drain.d.ts +10 -0
  62. package/dist/kit/extension.d.ts +180 -0
  63. package/dist/kit/grants.d.ts +9 -0
  64. package/dist/kit/modes.d.ts +65 -0
  65. package/dist/kit/retries.d.ts +25 -0
  66. package/dist/kit/scope.d.ts +32 -0
  67. package/dist/kit/service.d.ts +7 -0
  68. package/dist/kit/strategy.d.ts +10 -0
  69. package/dist/kit/timers.d.ts +43 -0
  70. package/dist/kit/tool.d.ts +72 -0
  71. package/dist/llm/client.d.ts +135 -0
  72. package/dist/llm/content.d.ts +52 -0
  73. package/dist/llm/door.d.ts +21 -0
  74. package/dist/llm/door.js +1 -0
  75. package/dist/llm/failure.d.ts +82 -0
  76. package/dist/llm/index.d.ts +16 -0
  77. package/dist/llm/primitives.d.ts +286 -0
  78. package/dist/llm/prompt.d.ts +21 -0
  79. package/dist/llm/provider.d.ts +63 -0
  80. package/dist/llm/readLedger.d.ts +24 -0
  81. package/dist/llm/request.d.ts +58 -0
  82. package/dist/loop/agent.d.ts +134 -0
  83. package/dist/loop/auxiliary.d.ts +54 -0
  84. package/dist/loop/chain.d.ts +46 -0
  85. package/dist/loop/chunks.d.ts +27 -0
  86. package/dist/loop/continuation.d.ts +166 -0
  87. package/dist/loop/decide.d.ts +64 -0
  88. package/dist/loop/errors.d.ts +162 -0
  89. package/dist/loop/forks.d.ts +61 -0
  90. package/dist/loop/holds.d.ts +104 -0
  91. package/dist/loop/hooks.d.ts +241 -0
  92. package/dist/loop/inbox.d.ts +188 -0
  93. package/dist/loop/index.d.ts +37 -0
  94. package/dist/loop/limits.d.ts +14 -0
  95. package/dist/loop/opening.d.ts +42 -0
  96. package/dist/loop/prepare.d.ts +30 -0
  97. package/dist/loop/projections.d.ts +307 -0
  98. package/dist/loop/replace.d.ts +33 -0
  99. package/dist/loop/requests.d.ts +129 -0
  100. package/dist/loop/route.d.ts +53 -0
  101. package/dist/loop/runtime.d.ts +85 -0
  102. package/dist/loop/state.d.ts +70 -0
  103. package/dist/loop/strategy.d.ts +71 -0
  104. package/dist/loop/summary.d.ts +3 -0
  105. package/dist/loop/surface.d.ts +153 -0
  106. package/dist/loop/threadState.d.ts +72 -0
  107. package/dist/loop/tool.d.ts +101 -0
  108. package/dist/loop/toolCalls.d.ts +42 -0
  109. package/dist/loop/wake.d.ts +32 -0
  110. package/dist/models/config/agent.d.ts +18 -0
  111. package/dist/models/config/prompt.d.ts +18 -0
  112. package/dist/models/door.d.ts +12 -0
  113. package/dist/models/door.js +1 -0
  114. package/dist/models/index.d.ts +7 -0
  115. package/dist/models/jsonSchema.d.ts +7 -0
  116. package/dist/models/wire/journal.d.ts +2772 -0
  117. package/dist/models/wire/primitives.d.ts +65 -0
  118. package/dist/plugin.d.ts +53 -0
  119. package/dist/plugin.js +1 -0
  120. package/dist/plugins/agentsMd.d.ts +76 -0
  121. package/dist/plugins/agentsMd.js +1 -0
  122. package/dist/plugins/ask/askQuestion.d.ts +9 -0
  123. package/dist/plugins/ask/index.d.ts +26 -0
  124. package/dist/plugins/ask/index.js +1 -0
  125. package/dist/plugins/ask/service.d.ts +125 -0
  126. package/dist/plugins/commands/background.d.ts +8 -0
  127. package/dist/plugins/commands/foreground.d.ts +4 -0
  128. package/dist/plugins/commands/index.d.ts +40 -0
  129. package/dist/plugins/commands/index.js +1 -0
  130. package/dist/plugins/commands/output.d.ts +115 -0
  131. package/dist/plugins/commands/record.d.ts +549 -0
  132. package/dist/plugins/commands/service.d.ts +314 -0
  133. package/dist/plugins/commands/shell.d.ts +25 -0
  134. package/dist/plugins/compaction/checkpoint.d.ts +91 -0
  135. package/dist/plugins/compaction/config.d.ts +133 -0
  136. package/dist/plugins/compaction/estimate.d.ts +29 -0
  137. package/dist/plugins/compaction/index.d.ts +2 -0
  138. package/dist/plugins/compaction/index.js +7 -0
  139. package/dist/plugins/compaction/log.d.ts +61 -0
  140. package/dist/plugins/compaction/planner.d.ts +207 -0
  141. package/dist/plugins/compaction/preset.d.ts +86 -0
  142. package/dist/plugins/compaction/prune.d.ts +9 -0
  143. package/dist/plugins/compaction/records.d.ts +227 -0
  144. package/dist/plugins/compaction/segments.d.ts +23 -0
  145. package/dist/plugins/compaction/shared.d.ts +14 -0
  146. package/dist/plugins/compaction/summarize.d.ts +13 -0
  147. package/dist/plugins/dateAndBranch.d.ts +47 -0
  148. package/dist/plugins/dateAndBranch.js +1 -0
  149. package/dist/plugins/delegations/answers.d.ts +39 -0
  150. package/dist/plugins/delegations/assignmentKey.d.ts +22 -0
  151. package/dist/plugins/delegations/cleanup.d.ts +161 -0
  152. package/dist/plugins/delegations/constraint.d.ts +76 -0
  153. package/dist/plugins/delegations/index.d.ts +39 -0
  154. package/dist/plugins/delegations/index.js +1 -0
  155. package/dist/plugins/delegations/notices.d.ts +261 -0
  156. package/dist/plugins/delegations/obligations.d.ts +210 -0
  157. package/dist/plugins/delegations/record.d.ts +632 -0
  158. package/dist/plugins/delegations/request.d.ts +381 -0
  159. package/dist/plugins/delegations/role.d.ts +30 -0
  160. package/dist/plugins/delegations/service.d.ts +562 -0
  161. package/dist/plugins/delegations/standing.d.ts +19 -0
  162. package/dist/plugins/delegations/stopCheck.d.ts +21 -0
  163. package/dist/plugins/delegations/testing.d.ts +16 -0
  164. package/dist/plugins/delegations/tools.d.ts +71 -0
  165. package/dist/plugins/delegations/waitBook.d.ts +116 -0
  166. package/dist/plugins/delegations/waits.d.ts +118 -0
  167. package/dist/plugins/diagnostics/digest.d.ts +14 -0
  168. package/dist/plugins/diagnostics/index.d.ts +68 -0
  169. package/dist/plugins/diagnostics/index.js +1 -0
  170. package/dist/plugins/historyRecall/history.d.ts +9 -0
  171. package/dist/plugins/historyRecall/index.d.ts +31 -0
  172. package/dist/plugins/historyRecall/index.js +1 -0
  173. package/dist/plugins/historyRecall/render.d.ts +34 -0
  174. package/dist/plugins/historyRecall/tools.d.ts +4 -0
  175. package/dist/plugins/mcp/catalog.d.ts +36 -0
  176. package/dist/plugins/mcp/config.d.ts +63 -0
  177. package/dist/plugins/mcp/connection.d.ts +53 -0
  178. package/dist/plugins/mcp/errors.d.ts +32 -0
  179. package/dist/plugins/mcp/index.d.ts +33 -0
  180. package/dist/plugins/mcp/index.js +5 -0
  181. package/dist/plugins/mcp/mount.d.ts +98 -0
  182. package/dist/plugins/mcp/names.d.ts +25 -0
  183. package/dist/plugins/mcp/render.d.ts +29 -0
  184. package/dist/plugins/mcp/slots.d.ts +15 -0
  185. package/dist/plugins/mcp/stdio.d.ts +49 -0
  186. package/dist/plugins/mcp/tool.d.ts +41 -0
  187. package/dist/plugins/providers/anthropic.d.ts +175 -0
  188. package/dist/plugins/providers/anthropicMessages.d.ts +65 -0
  189. package/dist/plugins/providers/codex.d.ts +60 -0
  190. package/dist/plugins/providers/codexAuth.d.ts +116 -0
  191. package/dist/plugins/providers/deepseek.d.ts +55 -0
  192. package/dist/plugins/providers/door.d.ts +61 -0
  193. package/dist/plugins/providers/door.js +1 -0
  194. package/dist/plugins/providers/failure.d.ts +23 -0
  195. package/dist/plugins/providers/gateway.d.ts +23 -0
  196. package/dist/plugins/providers/index.d.ts +6 -0
  197. package/dist/plugins/providers/openaiChat.d.ts +62 -0
  198. package/dist/plugins/providers/openaiResponses.d.ts +100 -0
  199. package/dist/plugins/providers/opencodeCopilot.d.ts +23 -0
  200. package/dist/plugins/providers/opencodeGo.d.ts +98 -0
  201. package/dist/plugins/providers/shared.d.ts +104 -0
  202. package/dist/plugins/providers/stream.d.ts +154 -0
  203. package/dist/plugins/routeContext.d.ts +22 -0
  204. package/dist/plugins/routeContext.js +1 -0
  205. package/dist/plugins/schedules/index.d.ts +21 -0
  206. package/dist/plugins/schedules/index.js +5 -0
  207. package/dist/plugins/schedules/record.d.ts +396 -0
  208. package/dist/plugins/schedules/service.d.ts +120 -0
  209. package/dist/plugins/schedules/time.d.ts +26 -0
  210. package/dist/plugins/schedules/tools.d.ts +6 -0
  211. package/dist/plugins/skills/discovery.d.ts +54 -0
  212. package/dist/plugins/skills/index.d.ts +31 -0
  213. package/dist/plugins/skills/index.js +1 -0
  214. package/dist/plugins/skills/tool.d.ts +11 -0
  215. package/dist/plugins/store/durableObject.d.ts +23 -0
  216. package/dist/plugins/store/durableObject.js +1 -0
  217. package/dist/plugins/store/durableObjectConnection.d.ts +27 -0
  218. package/dist/plugins/store/memory.d.ts +29 -0
  219. package/dist/plugins/store/sql.d.ts +59 -0
  220. package/dist/plugins/store/sqlite.d.ts +31 -0
  221. package/dist/plugins/store/sqlite.js +1 -0
  222. package/dist/plugins/subAgents/availableRoutes.d.ts +53 -0
  223. package/dist/plugins/subAgents/fork.d.ts +32 -0
  224. package/dist/plugins/subAgents/index.d.ts +67 -0
  225. package/dist/plugins/subAgents/index.js +1 -0
  226. package/dist/plugins/subAgents/tool.d.ts +38 -0
  227. package/dist/plugins/toolPolicy/index.d.ts +61 -0
  228. package/dist/plugins/toolPolicy/index.js +1 -0
  229. package/dist/plugins/tools/editFiles.d.ts +128 -0
  230. package/dist/plugins/tools/fsRead.d.ts +17 -0
  231. package/dist/plugins/tools/html.d.ts +23 -0
  232. package/dist/plugins/tools/index.d.ts +59 -0
  233. package/dist/plugins/tools/index.js +1 -0
  234. package/dist/plugins/tools/network.d.ts +23 -0
  235. package/dist/plugins/tools/ripgrep.d.ts +20 -0
  236. package/dist/plugins/tools/textEdit.d.ts +67 -0
  237. package/dist/plugins/tools/web.d.ts +32 -0
  238. package/dist/plugins/truncateToolOutput.d.ts +26 -0
  239. package/dist/plugins/truncateToolOutput.js +1 -0
  240. package/dist/plugins/usage/index.d.ts +24 -0
  241. package/dist/plugins/usage/index.js +1 -0
  242. package/dist/plugins/usage/tracker.d.ts +34 -0
  243. package/dist/plugins/verify/facts.d.ts +356 -0
  244. package/dist/plugins/verify/index.d.ts +75 -0
  245. package/dist/plugins/verify/index.js +1 -0
  246. package/dist/plugins/verify/service.d.ts +90 -0
  247. package/dist/plugins/workflows/assignment.d.ts +16 -0
  248. package/dist/plugins/workflows/bindings.d.ts +95 -0
  249. package/dist/plugins/workflows/cleanup.d.ts +38 -0
  250. package/dist/plugins/workflows/definition.d.ts +184 -0
  251. package/dist/plugins/workflows/fold.d.ts +373 -0
  252. package/dist/plugins/workflows/index.d.ts +28 -0
  253. package/dist/plugins/workflows/index.js +6 -0
  254. package/dist/plugins/workflows/observations.d.ts +81 -0
  255. package/dist/plugins/workflows/participants.d.ts +143 -0
  256. package/dist/plugins/workflows/policy.d.ts +112 -0
  257. package/dist/plugins/workflows/providers.d.ts +146 -0
  258. package/dist/plugins/workflows/record.d.ts +2863 -0
  259. package/dist/plugins/workflows/routing.d.ts +116 -0
  260. package/dist/plugins/workflows/schema.d.ts +26 -0
  261. package/dist/plugins/workflows/service.d.ts +477 -0
  262. package/dist/plugins/workflows/submit.d.ts +8 -0
  263. package/dist/plugins/workflows/view.d.ts +103 -0
  264. package/dist/plugins/workflows/work.d.ts +21 -0
  265. package/dist/plugins/workspaceContext.d.ts +38 -0
  266. package/dist/plugins/workspaceContext.js +1 -0
  267. package/dist/presets/agents.d.ts +7 -0
  268. package/dist/presets/base.d.ts +10 -0
  269. package/dist/presets/codex.d.ts +60 -0
  270. package/dist/presets/index.d.ts +4 -0
  271. package/dist/presets/prompts.d.ts +56 -0
  272. package/dist/sandbox/absent.d.ts +32 -0
  273. package/dist/sandbox/client.d.ts +39 -0
  274. package/dist/sandbox/files.d.ts +28 -0
  275. package/dist/sandbox/index.d.ts +49 -0
  276. package/dist/sandbox/index.js +4 -0
  277. package/dist/sandbox/mode.d.ts +57 -0
  278. package/dist/sandbox/policy.d.ts +86 -0
  279. package/dist/sandbox/protocol.d.ts +107 -0
  280. package/dist/sandbox/service.d.ts +143 -0
  281. package/dist/sandbox/worker.d.ts +12 -0
  282. package/dist/sandbox/worker.js +1 -0
  283. package/dist/services/admission.d.ts +174 -0
  284. package/dist/services/agents.d.ts +37 -0
  285. package/dist/services/birth.d.ts +220 -0
  286. package/dist/services/contributions.d.ts +73 -0
  287. package/dist/services/core.d.ts +34 -0
  288. package/dist/services/journal.d.ts +26 -0
  289. package/dist/services/launches.d.ts +104 -0
  290. package/dist/services/llm.d.ts +80 -0
  291. package/dist/services/owner.d.ts +367 -0
  292. package/dist/services/preset.d.ts +154 -0
  293. package/dist/services/presets.d.ts +139 -0
  294. package/dist/services/prompts.d.ts +67 -0
  295. package/dist/services/runEvents.d.ts +79 -0
  296. package/dist/services/thread.d.ts +267 -0
  297. package/dist/services/threadActivation.d.ts +100 -0
  298. package/dist/services/threadDirs.d.ts +38 -0
  299. package/dist/services/threadView.d.ts +92 -0
  300. package/dist/services/threads.d.ts +449 -0
  301. package/dist/services/tools.d.ts +41 -0
  302. package/dist/sys/environment.d.ts +47 -0
  303. package/dist/sys/git.d.ts +60 -0
  304. package/dist/sys/paths.d.ts +56 -0
  305. package/dist/sys/spawn.d.ts +176 -0
  306. package/dist/testing/clock.d.ts +17 -0
  307. package/dist/testing/fakeLlm.d.ts +74 -0
  308. package/dist/testing/fedLlm.d.ts +32 -0
  309. package/dist/testing/helpers.d.ts +344 -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/sandbox.d.ts +71 -0
  314. package/dist/testing/settlement.d.ts +6 -0
  315. package/dist/testing/tmpDirs.d.ts +17 -0
  316. package/dist/util/async.d.ts +8 -0
  317. package/dist/util/diff.d.ts +25 -0
  318. package/dist/util/dispatch.d.ts +8 -0
  319. package/dist/util/errors.d.ts +28 -0
  320. package/dist/util/foldState.d.ts +17 -0
  321. package/dist/util/freeze.d.ts +2 -0
  322. package/dist/util/ids.d.ts +2 -0
  323. package/dist/util/json.d.ts +37 -0
  324. package/dist/util/log.d.ts +6 -0
  325. package/dist/util/text.d.ts +21 -0
  326. package/dist/util/version.d.ts +2 -0
  327. package/package.json +175 -3
@@ -0,0 +1,314 @@
1
+ import { Service, type Context } from '@leuduan/cordis';
2
+ import { z } from 'zod';
3
+ import type { SpawnResult, SpawnedCommand } from '../../sys/spawn.js';
4
+ import type { Seq } from '../../models/index.js';
5
+ import type { Launched, LaunchProvenance } from '../../services/launches.js';
6
+ import { CommandOutput } from './output.js';
7
+ import { type CommandEnded, type CommandRecord, type CommandStarted } from './record.js';
8
+ declare module '@leuduan/cordis' {
9
+ interface Context {
10
+ /** Background commands, owned by the thread that started them (optional plugin). */
11
+ commands: CommandsService;
12
+ }
13
+ interface Events {
14
+ /**
15
+ * A background command was started and is now in the live set `ctx.commands.list` reads: a host
16
+ * showing running commands refreshes on it, since the start row is written before the command
17
+ * is listed. Its end needs no counterpart: the end row is written once it no longer runs.
18
+ */
19
+ 'lagent/commands/started'(threadId: string, commandId: string): void;
20
+ }
21
+ }
22
+ export declare const CommandsConfigSchema: z.ZodObject<{
23
+ environment: z.ZodRecord<z.ZodString, z.ZodString>;
24
+ defaultTimeoutSeconds: z.ZodDefault<z.ZodNumber>;
25
+ maxTimeoutSeconds: z.ZodDefault<z.ZodNumber>;
26
+ killGraceSeconds: z.ZodDefault<z.ZodNumber>;
27
+ maxOutputChars: z.ZodDefault<z.ZodNumber>;
28
+ maxLogBytes: z.ZodDefault<z.ZodNumber>;
29
+ maxBackgroundCommands: z.ZodDefault<z.ZodNumber>;
30
+ }, z.core.$strict>;
31
+ export type CommandsConfig = z.output<typeof CommandsConfigSchema>;
32
+ export type CommandsConfigInput = z.input<typeof CommandsConfigSchema>;
33
+ /** Where a thread's command logs go inside its directory. */
34
+ export declare const COMMANDS_DIR = "commands";
35
+ /** The `workdir` parameter of both command tools; its description steers models away from a `cd` prefix. */
36
+ export declare const WorkdirParameter: z.ZodDefault<z.ZodNullable<z.ZodString>>;
37
+ /** A command's id: the `tool/call` row that started it, unique in the journal and across restarts. */
38
+ export declare const commandId: (callSeq: Seq) => string;
39
+ /** Where command `id` of `threadId` logs: `<thread dir>/commands/<id>.log`. */
40
+ export declare const commandLogPath: (ctx: Context, threadId: string, id: string) => string;
41
+ /** The segment a log rotates into: `<id>.1.log`, the output before the current segment. */
42
+ export declare const olderLogPath: (logPath: string) => string;
43
+ /**
44
+ * What this process can say about a recorded command it does not run: `exited`, when the end row
45
+ * says so and the stop did not fail; otherwise `orphaned`: started by a previous process and not
46
+ * owned here, with no claim about its process group. The reaper makes such a group almost always
47
+ * gone, but not while a stop is still in its grace period, nor after one that failed.
48
+ */
49
+ export type RecordedStatus = {
50
+ readonly kind: 'exited' | 'orphaned';
51
+ readonly detail: string;
52
+ };
53
+ /** What a host sees of a background command. */
54
+ export type CommandInfo = {
55
+ readonly id: string;
56
+ readonly threadId: string;
57
+ readonly command: string;
58
+ readonly cwd: string;
59
+ /** `orphaned`: recorded by another lagent process, and whether it still runs is not known to have ended. */
60
+ readonly status: 'running' | 'exited' | 'orphaned';
61
+ readonly startedAt: number;
62
+ readonly durationMs: number;
63
+ readonly exitCode: number | null;
64
+ readonly exitSignal: NodeJS.Signals | null;
65
+ /** Why lagent stopped it, when it did. */
66
+ readonly stopReason: string | null;
67
+ readonly stopFailed: boolean;
68
+ readonly logPath: string;
69
+ /** What the launch handler selected for it, from the live launch or the start row; `null` for a plain launch. */
70
+ readonly launch: LaunchProvenance | null;
71
+ };
72
+ /**
73
+ * What stands between a thread's command work and its end, each item saying why: `draining`, work
74
+ * this process runs and is ending, whose end it will record; `unresolved`, work whose end nothing
75
+ * establishes: a stop that failed, a command no process here saw end, records that cannot be read.
76
+ * Both empty: every command it started is known to have ended.
77
+ */
78
+ export type CommandWork = {
79
+ readonly draining: readonly string[];
80
+ readonly unresolved: readonly string[];
81
+ };
82
+ /**
83
+ * Whether the command work of `threadId`, and with `descendants` of every thread under it, is known
84
+ * to have ended: the one answer a cleanup or a quiescence check reads before it certifies a thread
85
+ * quiet, whether or not the commands plugin is mounted. On affirmative evidence only, from each
86
+ * thread's rows: its folds when it is loaded, else its catalog entry, which the plugin contributes
87
+ * while mounted; an entry without it is unresolved, never read as none.
88
+ *
89
+ * A background command has ended once its end row says its stop succeeded; one the mounted service
90
+ * still starts or runs, or whose end row is on its way, is draining; any other is unresolved. A
91
+ * `run_command` call has ended once its result carries the tool's own report that the stop
92
+ * succeeded, and never ran while no dispatch of it was allowed; one launched without that report is
93
+ * draining while the service is mounted and the thread's run is running here, which is the run
94
+ * serving it or one that may still write its result, and unresolved otherwise. A stop that failed,
95
+ * and records that cannot be read, are unresolved. Synchronous, so a write may decide on it.
96
+ */
97
+ export declare function commandWork(ctx: Context, threadId: string, options: {
98
+ readonly descendants: boolean;
99
+ }): CommandWork;
100
+ /** What starts a background command: whose call, what to run, where, and whether its exit notifies. */
101
+ export type StartRequest = {
102
+ readonly threadId: string;
103
+ readonly callSeq: Seq;
104
+ readonly command: string;
105
+ readonly cwd: string;
106
+ /** The thread's working directory, which a launch handler treats as the root it protects. */
107
+ readonly threadCwd: string;
108
+ readonly notify: 'exit' | null;
109
+ };
110
+ /** A background command and everything the tools report about it. */
111
+ export declare class BackgroundCommand {
112
+ result: SpawnResult | null;
113
+ endedAt: number | null;
114
+ /** Why lagent stopped it; the first reason wins. */
115
+ stopReason: string | null;
116
+ readonly ended: Promise<void>;
117
+ readonly startedAt: number;
118
+ readonly id: string;
119
+ readonly threadId: string;
120
+ readonly command: string;
121
+ readonly cwd: string;
122
+ readonly output: CommandOutput;
123
+ readonly process: SpawnedCommand;
124
+ readonly notify: 'exit' | null;
125
+ readonly launch: LaunchProvenance | null;
126
+ constructor(id: string, threadId: string, command: string, cwd: string, output: CommandOutput, process: SpawnedCommand,
127
+ /** `exit`: a natural exit wakes the thread that started it with a notice. */
128
+ notify: 'exit' | null,
129
+ /** What the launch handler selected for it. */
130
+ launch: LaunchProvenance | null,
131
+ /** The launch handler's report on the command, which joins its output once it ended. */
132
+ diagnostics: Promise<string | null>, onEnd: (command: BackgroundCommand) => void);
133
+ get running(): boolean;
134
+ get logPath(): string;
135
+ get durationMs(): number;
136
+ info(): CommandInfo;
137
+ }
138
+ /**
139
+ * A command the journal records and this process does not run: started by a previous lagent
140
+ * process, or by this one and since forgotten. This process cannot read its output as it arrives
141
+ * or stop it; it can say what the rows record, and read whatever log it left.
142
+ */
143
+ export declare class RecordedCommand {
144
+ readonly threadId: string;
145
+ readonly record: CommandRecord;
146
+ readonly logPaths: readonly string[];
147
+ readonly status: RecordedStatus;
148
+ readonly ownedHere: boolean;
149
+ constructor(threadId: string, record: CommandRecord,
150
+ /** The current log segment, then the older one when it exists. */
151
+ logPaths: readonly string[], status: RecordedStatus,
152
+ /** Started by this service instance, and since dropped from what it tracks. */
153
+ ownedHere: boolean);
154
+ get id(): string;
155
+ get started(): CommandStarted;
156
+ get ended(): CommandEnded | null;
157
+ /** Whether its end is not vouched for: no end row, or one whose stop failed. Such commands are listed. */
158
+ get orphaned(): boolean;
159
+ /** The one status line every tool result about it opens with. */
160
+ statusLine(): string;
161
+ info(): CommandInfo;
162
+ }
163
+ /** What `lookup` found: the caller's command, one the journal records, or why there is none to act on. */
164
+ export type CommandLookup = {
165
+ command: BackgroundCommand;
166
+ } | {
167
+ recorded: RecordedCommand;
168
+ } | {
169
+ error: string;
170
+ };
171
+ /**
172
+ * The background commands of this process. A command belongs to the thread that started it, and
173
+ * only that thread's tools may read or stop it; that is an access rule, not a lifetime. The
174
+ * command, its log writer and its read cursor live here, on the root, so releasing or reinstalling
175
+ * a thread's activation leaves them untouched.
176
+ *
177
+ * A command runs until it exits, is stopped, the root is disposed, or — for a delegated thread —
178
+ * its turn ends any way but `blocked`, since its caller may never follow up and cannot see the
179
+ * command. Cancelling a turn does not stop one: outliving the turn is the point.
180
+ *
181
+ * Commands are process-local, and the journal records their starts and ends: a reopened root
182
+ * starts with none of its own, and lists the ones whose end no process vouched for — started by a
183
+ * previous process and never seen to end, or ended by a stop that failed — as not owned here
184
+ * (`record.ts`).
185
+ */
186
+ export declare class CommandsService extends Service<CommandsConfigInput> {
187
+ static inject: string[];
188
+ readonly config: CommandsConfig;
189
+ /** This instance's identity in start rows: per root, so a root reopened in one process owns none of its predecessor's commands. */
190
+ readonly instanceId: `${string}-${string}-${string}-${string}-${string}`;
191
+ private readonly commands;
192
+ private readonly starting;
193
+ /** End rows and exit notices on their way to the journal; shutdown waits for them while the journal is still open. */
194
+ private readonly writes;
195
+ /** Every launch, foreground or background, from its preparation until its command and report settled. */
196
+ private readonly operations;
197
+ private readonly lifetime;
198
+ constructor(ctx: Context, config: CommandsConfigInput);
199
+ /**
200
+ * Launches one command of either kind through `ctx.launches`: the one place a command starts, so
201
+ * the shutdown that stops them all sees every one. Refused once shut down. `options.signal` owns
202
+ * the command, and shutdown stops it too.
203
+ */
204
+ launch(request: {
205
+ command: string;
206
+ workdir: string;
207
+ threadId: string;
208
+ threadCwd: string;
209
+ }, options: {
210
+ signal: AbortSignal;
211
+ timeoutMs?: number;
212
+ beforeRelease?: (pgid: number, launch: LaunchProvenance | null) => Promise<void>;
213
+ }): Promise<Launched>;
214
+ /**
215
+ * Starts a background command for `threadId`, or finds the one this dispatch already started:
216
+ * a call re-dispatched in the same process keeps its id and gets its command back.
217
+ */
218
+ start(request: StartRequest): Promise<{
219
+ command: BackgroundCommand;
220
+ reused: boolean;
221
+ }>;
222
+ /** `threadId`'s command `id`, live or recorded, or a message saying why there is none to act on. */
223
+ lookup(threadId: string, id: string): CommandLookup;
224
+ /**
225
+ * One thread's background commands, oldest first: the ones this process runs or ran, and the
226
+ * recorded ones whose end no process vouched for.
227
+ */
228
+ list(filter: {
229
+ threadId: string;
230
+ }): CommandInfo[];
231
+ /**
232
+ * The background commands this process holds for `threadId`, by id: `starting` while its launch
233
+ * is under way, its start row perhaps not yet written; `running`; `ended` once it exited, its end
234
+ * row written or on its way. What {@link commandWork} reads of this process.
235
+ */
236
+ live(threadId: string): ReadonlyMap<string, 'starting' | 'running' | 'ended'>;
237
+ /**
238
+ * Stops command `id` this process runs, within the bound of `sys/spawn`, recording why; resolves
239
+ * with its final state once it has ended. A tool looks the command up first, for its caller's thread.
240
+ */
241
+ stop(id: string, reason?: string): Promise<CommandInfo>;
242
+ /** Stops every running background command, or one thread's, in parallel. */
243
+ stopAll(filter?: {
244
+ threadId?: string;
245
+ }, reason?: string): Promise<void>;
246
+ /**
247
+ * Blocks until `command` exits, until the wait elapses or `signal` aborts, or with
248
+ * `until: 'output'`, until half a second after new output first arrives, so a burst of lines
249
+ * comes back as one result. Unread output already waiting ends an `output` wait at once.
250
+ */
251
+ wait(command: BackgroundCommand, options: {
252
+ waitMs: number;
253
+ until: 'output' | 'exit';
254
+ signal: AbortSignal;
255
+ }): Promise<void>;
256
+ private spawn;
257
+ private forThread;
258
+ /**
259
+ * The recorded commands of `threadId` another instance started and whose end no process vouched
260
+ * for. This instance's own records are never listed from the journal: one it runs is live, and
261
+ * one it does not run has an end row, written when it ended or when its start was never released.
262
+ */
263
+ private orphans;
264
+ private recorded;
265
+ /**
266
+ * What the rows let this process say. An end row whose stop succeeded is the answer; anything
267
+ * else was started by a previous process and is not owned here, and nothing is claimed about its
268
+ * process group.
269
+ */
270
+ private recordedStatus;
271
+ /**
272
+ * Writes the end row; a journal that refuses is reported, never thrown into the command's settling.
273
+ * The write is tracked until it lands, so shutdown can wait for it.
274
+ */
275
+ private recordEnd;
276
+ /**
277
+ * Tracks a write until it lands, so shutdown can wait for it; a journal that refuses is reported,
278
+ * never thrown into the command's settling.
279
+ */
280
+ private track;
281
+ /**
282
+ * Tells the thread that started a notifying command that it exited, with one `send` whose group
283
+ * carries the end row: a developer-role notice under `cmdexit_<id>`, a reactive cause that runs an
284
+ * idle thread and releases none of its holds. It joins the next model step, after the start's own
285
+ * result: a run's that holds the thread, or the turn that resumes the thread's parked calls. A send
286
+ * the thread refuses writes nothing, and the command is listed as an orphan at the next start, as
287
+ * one whose end row failed is.
288
+ */
289
+ private notifyEnd;
290
+ /**
291
+ * Records the end, through the exit notice for a notifying command that exited on its own, then
292
+ * keeps a bounded number of each thread's ended commands; a dropped id answers from its record.
293
+ */
294
+ private onEnd;
295
+ /**
296
+ * Root disposal: no launch is admitted, every group stops in parallel
297
+ * within the same bound as one stop, foreground and background alike, and launches still being
298
+ * prepared are abandoned. Starts still at their gate settle first, so each either lands and is
299
+ * stopped or is recorded as never released, and nothing ends after the journal has closed.
300
+ * Idempotent.
301
+ */
302
+ private shutdown;
303
+ private markShutdown;
304
+ }
305
+ /**
306
+ * The last `maxChars` characters of a command's log, read from `paths` newest segment first, for a
307
+ * command this process cannot read live; with the bytes left out before them and the segments that
308
+ * were read. `null` when no segment exists.
309
+ */
310
+ export declare function readLogTail(paths: readonly string[], maxChars: number): Promise<{
311
+ text: string;
312
+ omittedBytes: number;
313
+ read: string[];
314
+ } | null>;
@@ -0,0 +1,25 @@
1
+ import { type SpawnEnvironment } from '../../sys/spawn.js';
2
+ /** The tools whose `command` runs through `/bin/sh -c`. */
3
+ export declare const SHELL_TOOLS: Set<string>;
4
+ /**
5
+ * What `/bin/sh` is here, read once at mount, in the environment commands run with: see
6
+ * {@link shellDescription}.
7
+ */
8
+ export declare function describeShell(environment: SpawnEnvironment): Promise<string>;
9
+ /**
10
+ * The `$BASH_VERSION` the probe printed on its marked line; `null` when it failed, printed no such
11
+ * line, or the shell is not bash.
12
+ */
13
+ export declare function bashVersionOf(probe: {
14
+ exitCode: number | null;
15
+ output: string;
16
+ }): string | null;
17
+ /**
18
+ * The prompt line for a `/bin/sh` resolving to `target`: the program it links to, such as dash, and
19
+ * bash's version when it is bash, as macOS's `/bin/sh` is without being a link. Dash reports no
20
+ * version.
21
+ */
22
+ export declare function shellDescription({ target, bashVersion }: {
23
+ target: string;
24
+ bashVersion: string | null;
25
+ }): string;
@@ -0,0 +1,91 @@
1
+ import { type ContentPart } from '../../llm/index.js';
2
+ /**
3
+ * The texts the strategy writes: the instruction its summary call ends on, and the checkpoint that
4
+ * stands in for a span. Everything here but the summary is written by code, so the pointers in it
5
+ * are exact and no model-written text speaks with more than a note's authority.
6
+ */
7
+ /** A message before a span, named in the instruction by its role and the start of its text. */
8
+ export type Boundary = {
9
+ readonly role: string;
10
+ readonly text: string;
11
+ };
12
+ /**
13
+ * The instruction after the surface prefix. It names the span by the message just before it, the
14
+ * last of the pinned opening or the direct developer input the segment follows, by its role and a
15
+ * bounded quote, since nothing can be inserted into the prefix without breaking it; with no such
16
+ * message the whole prefix is the span. It asks for the state as of the cut, since the summarizer
17
+ * never sees the retained tail, in the checkpoint's structured sections.
18
+ */
19
+ export declare function renderInstruction(options: {
20
+ readonly boundary: Boundary | null;
21
+ readonly quoteChars: number;
22
+ /** Whether the span holds an earlier checkpoint, which the new one merges rather than copies. */
23
+ readonly merges: boolean;
24
+ readonly cap: number;
25
+ /** What a person asked the summary to pay particular attention to. */
26
+ readonly focus: string | null;
27
+ }): string;
28
+ /**
29
+ * A bounded quote of a message's text, to name it in the instruction: whitespace, control
30
+ * characters and lone surrogates, which the quoting would write as six characters, flattened to
31
+ * single spaces, cut at `limit` characters with an ellipsis, and quoted as
32
+ * a JSON string. The quoting at most doubles a character, so `2 * limit + 3` characters bound it.
33
+ */
34
+ export declare const quote: (text: string, limit: number) => string;
35
+ /** The person's latest input as a checkpoint copies it: whole, or its beginning and where to find the rest. */
36
+ export type CopiedInput = {
37
+ readonly text: string;
38
+ /** Its history number, which names it in full. */
39
+ readonly number: number;
40
+ /** Its whole length in characters, when the copy is cut. */
41
+ readonly cutFrom: number | null;
42
+ /** Parts that are not text, which are not copied. */
43
+ readonly attachments: number;
44
+ };
45
+ /**
46
+ * Copies an input from its original row: whole up to `limit` characters, beyond that its first
47
+ * half and its history number. Never from a checkpoint's text, so two compactions hand the model
48
+ * the same words rather than a summary of a summary.
49
+ */
50
+ export declare function copyInput(content: readonly ContentPart[], number: number, limit: number): CopiedInput;
51
+ /** The messages a checkpoint stands for, by history number, through every earlier replacement. */
52
+ export type ReplacedRange = {
53
+ readonly first: number;
54
+ readonly last: number;
55
+ readonly count: number;
56
+ };
57
+ /**
58
+ * The checkpoint: a code-written preamble, the model's summary, the person's latest input when
59
+ * the span held it, and a code-written footer naming the replaced messages. One `user` message
60
+ * framed as historical notes that introduce no instructions: a summary is model-written and may be
61
+ * wrong, so it must not speak as the harness.
62
+ *
63
+ * `recall` is the footer's line on how to read the replaced messages back (`renderRecall`, owned by the recall plugin),
64
+ * which a strategy passes only when the thread's agent has both of the recall plugin's tools granted, and
65
+ * `null` otherwise.
66
+ */
67
+ export declare function renderCheckpoint(parts: {
68
+ readonly summary: string;
69
+ readonly copied: CopiedInput | null;
70
+ readonly replaced: ReplacedRange;
71
+ readonly recall: string | null;
72
+ }): string;
73
+ /** The copied input as the checkpoint carries it, marked as the person's own words. */
74
+ export declare function renderCopiedInput(copied: CopiedInput): string;
75
+ /** Text the checkpoint did not write, kept from ending one of its sections early or opening another. */
76
+ export declare const neutralize: (text: string) => string;
77
+ /**
78
+ * The checkpoint with an empty summary and the widest footer, two different seven-digit numbers,
79
+ * and the longest recall line whether or not the agent has the recall tools: what its code-written
80
+ * framing comes to at most, for budgets.
81
+ */
82
+ export declare const EMPTY_CHECKPOINT: string;
83
+ /**
84
+ * The longest instruction a summary call may end on, for budgets: the boundary quoted at its limit
85
+ * and truncated, of characters the quoting doubles, asking to merge an earlier checkpoint.
86
+ */
87
+ export declare const widestInstruction: (options: {
88
+ readonly quoteChars: number;
89
+ readonly cap: number;
90
+ readonly focus: string | null;
91
+ }) => string;
@@ -0,0 +1,133 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The route the summary call runs on, merged over the turn's route as a turn's selection is over
4
+ * the thread's: the turn's provider and model unless they are named. Naming another provider or
5
+ * model is the host's choice and depends on what it has registered, so none is assumed; it forgoes
6
+ * the cached prefix a summary call on the turn's model reads.
7
+ *
8
+ * `thinkingEffort` is a ceiling, `low` by default: the call runs at the lower of it and the turn's
9
+ * effort, so a turn at `none` summarizes at `none`, with no reasoning allowance, and a turn whose
10
+ * effort is left to its provider leaves the summary's there too. Effort sits outside the cached
11
+ * prefix, and a long span at `high` costs more than any allowance.
12
+ */
13
+ export declare const SummarizerSchema: z.ZodObject<{
14
+ provider: z.ZodOptional<z.ZodString>;
15
+ model: z.ZodOptional<z.ZodString>;
16
+ thinkingEffort: z.ZodDefault<z.ZodEnum<{
17
+ low: "low";
18
+ high: "high";
19
+ none: "none";
20
+ medium: "medium";
21
+ max: "max";
22
+ }>>;
23
+ }, z.core.$strict>;
24
+ /**
25
+ * The `summarize` strategy's budgets: it replaces a span with a checkpoint a summary call wrote.
26
+ * Fractions are of the route's declared window; token counts are tokens.
27
+ */
28
+ export declare const SummarizeStrategySchema: z.ZodObject<{
29
+ kind: z.ZodLiteral<"summarize">;
30
+ target: z.ZodDefault<z.ZodNumber>;
31
+ tail: z.ZodDefault<z.ZodNumber>;
32
+ opening: z.ZodDefault<z.ZodNumber>;
33
+ summaryCap: z.ZodDefault<z.ZodNumber>;
34
+ summaryFloor: z.ZodDefault<z.ZodNumber>;
35
+ reasoningAllowance: z.ZodDefault<z.ZodNumber>;
36
+ replyReserve: z.ZodDefault<z.ZodNumber>;
37
+ checkpointRatio: z.ZodDefault<z.ZodNumber>;
38
+ copiedInputChars: z.ZodDefault<z.ZodNumber>;
39
+ boundaryQuoteChars: z.ZodDefault<z.ZodNumber>;
40
+ breaker: z.ZodDefault<z.ZodNumber>;
41
+ withoutWindow: z.ZodDefault<z.ZodObject<{
42
+ tailTokens: z.ZodDefault<z.ZodNumber>;
43
+ openingTokens: z.ZodDefault<z.ZodNumber>;
44
+ }, z.core.$strict>>;
45
+ summarizer: z.ZodDefault<z.ZodObject<{
46
+ provider: z.ZodOptional<z.ZodString>;
47
+ model: z.ZodOptional<z.ZodString>;
48
+ thinkingEffort: z.ZodDefault<z.ZodEnum<{
49
+ low: "low";
50
+ high: "high";
51
+ none: "none";
52
+ medium: "medium";
53
+ max: "max";
54
+ }>>;
55
+ }, z.core.$strict>>;
56
+ }, z.core.$strict>;
57
+ /**
58
+ * The `prune` strategy's settings: it rewrites old tool results to a one-line stand-in and calls
59
+ * no model.
60
+ */
61
+ export declare const PruneStrategySchema: z.ZodObject<{
62
+ kind: z.ZodLiteral<"prune">;
63
+ keepRecent: z.ZodDefault<z.ZodNumber>;
64
+ minTokens: z.ZodDefault<z.ZodNumber>;
65
+ }, z.core.$strict>;
66
+ /**
67
+ * The compaction plugin's configuration, all of it JSON so a preset can record it: when pressure
68
+ * acts, and the strategy, `summarize` with its defaults unless another is chosen. Whose threads is
69
+ * where it is placed: installed on one, or mounted on the root for an agent selector.
70
+ */
71
+ export declare const CompactionConfigSchema: z.ZodObject<{
72
+ threshold: z.ZodDefault<z.ZodNumber>;
73
+ strategy: z.ZodPrefault<z.ZodDiscriminatedUnion<[z.ZodObject<{
74
+ kind: z.ZodLiteral<"summarize">;
75
+ target: z.ZodDefault<z.ZodNumber>;
76
+ tail: z.ZodDefault<z.ZodNumber>;
77
+ opening: z.ZodDefault<z.ZodNumber>;
78
+ summaryCap: z.ZodDefault<z.ZodNumber>;
79
+ summaryFloor: z.ZodDefault<z.ZodNumber>;
80
+ reasoningAllowance: z.ZodDefault<z.ZodNumber>;
81
+ replyReserve: z.ZodDefault<z.ZodNumber>;
82
+ checkpointRatio: z.ZodDefault<z.ZodNumber>;
83
+ copiedInputChars: z.ZodDefault<z.ZodNumber>;
84
+ boundaryQuoteChars: z.ZodDefault<z.ZodNumber>;
85
+ breaker: z.ZodDefault<z.ZodNumber>;
86
+ withoutWindow: z.ZodDefault<z.ZodObject<{
87
+ tailTokens: z.ZodDefault<z.ZodNumber>;
88
+ openingTokens: z.ZodDefault<z.ZodNumber>;
89
+ }, z.core.$strict>>;
90
+ summarizer: z.ZodDefault<z.ZodObject<{
91
+ provider: z.ZodOptional<z.ZodString>;
92
+ model: z.ZodOptional<z.ZodString>;
93
+ thinkingEffort: z.ZodDefault<z.ZodEnum<{
94
+ low: "low";
95
+ high: "high";
96
+ none: "none";
97
+ medium: "medium";
98
+ max: "max";
99
+ }>>;
100
+ }, z.core.$strict>>;
101
+ }, z.core.$strict>, z.ZodObject<{
102
+ kind: z.ZodLiteral<"prune">;
103
+ keepRecent: z.ZodDefault<z.ZodNumber>;
104
+ minTokens: z.ZodDefault<z.ZodNumber>;
105
+ }, z.core.$strict>], "kind">>;
106
+ }, z.core.$strict>;
107
+ /** The configuration as a host writes it: everything optional with its default. */
108
+ export type CompactionConfig = z.input<typeof CompactionConfigSchema>;
109
+ /** The configuration with every default applied, as the preset reads it. */
110
+ export type ResolvedCompactionConfig = z.output<typeof CompactionConfigSchema>;
111
+ /** The `summarize` branch with its defaults applied. */
112
+ export type SummarizeStrategyConfig = z.output<typeof SummarizeStrategySchema>;
113
+ /** The `prune` branch with its defaults applied. */
114
+ export type PruneStrategyConfig = z.output<typeof PruneStrategySchema>;
115
+ /**
116
+ * What a strategy's per-thread plugin is mounted with: its thread, the thread's agent, and the
117
+ * configuration's shared `threshold` beside the strategy's own branch, as the configuration has them.
118
+ */
119
+ export type StrategyOptions<Strategy> = {
120
+ readonly threadId: string;
121
+ readonly agentName: string;
122
+ readonly threshold: number;
123
+ readonly strategy: Strategy;
124
+ };
125
+ /**
126
+ * What a host may pass to `thread.compact({ options })` for this strategy: nothing, or what the
127
+ * summary should pay particular attention to, as a person typing `/compact <focus>` would say it.
128
+ */
129
+ export declare const CompactRequestOptionsSchema: z.ZodNullable<z.ZodObject<{
130
+ focus: z.ZodOptional<z.ZodString>;
131
+ }, z.core.$strict>>;
132
+ /** The `options` a host passes to `thread.compact()` for this strategy; see `CompactRequestOptionsSchema`. */
133
+ export type CompactRequestOptions = z.input<typeof CompactRequestOptionsSchema>;
@@ -0,0 +1,29 @@
1
+ import type { ContentPart, ConversationMessage, PromptBlock, ToolSpec } from '../../llm/index.js';
2
+ import type { DeepReadonly } from '../../util/json.js';
3
+ /**
4
+ * A character-based estimate of what a request costs in tokens, for a strategy that budgets the
5
+ * surface: four characters to a token, with a little framing per part and per message, as DeepSeek
6
+ * Harness prices content. It is an estimate and never a measurement: a strategy measures with the
7
+ * usage a provider reported where it has one, estimates what came since, and calibrates the
8
+ * estimate when a provider refuses a request as too long. Images, CJK text and other content whose
9
+ * characters say little about its tokens are exactly what that calibration exists for.
10
+ */
11
+ export declare const CHARS_PER_TOKEN = 4;
12
+ /** Tokens for `text`. */
13
+ export declare const estimateText: (text: string) => number;
14
+ /** Tokens for a content list, each part with its framing. */
15
+ export declare function estimateContent(parts: readonly ContentPart[]): number;
16
+ /**
17
+ * Tokens for one message as a request carries it: its content, the reasoning it replays as text,
18
+ * and the tool calls it asked for. Provider state replayed in its place is not priced, since it is
19
+ * opaque; a usage anchor measures it.
20
+ */
21
+ export declare function estimateMessage(message: DeepReadonly<ConversationMessage>): number;
22
+ /**
23
+ * Tokens for everything a request sends ahead of its messages: the system prompt, guidance blocks
24
+ * included, and the tool definitions it advertises.
25
+ */
26
+ export declare function estimateHead(head: {
27
+ readonly systemPrompt: readonly PromptBlock[];
28
+ readonly tools: readonly ToolSpec[];
29
+ }): number;
@@ -0,0 +1,2 @@
1
+ export type { CompactionConfig, CompactRequestOptions, PruneStrategyConfig, SummarizeStrategyConfig } from './config.js';
2
+ export { compaction } from './preset.js';