maestro-agent-sdk 0.1.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 (196) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +24 -0
  3. package/README.md +133 -0
  4. package/dist/agents/contracts.d.ts +49 -0
  5. package/dist/agents/contracts.d.ts.map +1 -0
  6. package/dist/agents/contracts.js +2 -0
  7. package/dist/agents/contracts.js.map +1 -0
  8. package/dist/agents/rollout/shared.d.ts +24 -0
  9. package/dist/agents/rollout/shared.d.ts.map +1 -0
  10. package/dist/agents/rollout/shared.js +105 -0
  11. package/dist/agents/rollout/shared.js.map +1 -0
  12. package/dist/core/agent.d.ts +71 -0
  13. package/dist/core/agent.d.ts.map +1 -0
  14. package/dist/core/agent.js +22 -0
  15. package/dist/core/agent.js.map +1 -0
  16. package/dist/core/loop.d.ts +26 -0
  17. package/dist/core/loop.d.ts.map +1 -0
  18. package/dist/core/loop.js +317 -0
  19. package/dist/core/loop.js.map +1 -0
  20. package/dist/index.d.ts +49 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +53 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/mcp/client.d.ts +79 -0
  25. package/dist/mcp/client.d.ts.map +1 -0
  26. package/dist/mcp/client.js +176 -0
  27. package/dist/mcp/client.js.map +1 -0
  28. package/dist/mcp/pool-cache.d.ts +103 -0
  29. package/dist/mcp/pool-cache.d.ts.map +1 -0
  30. package/dist/mcp/pool-cache.js +249 -0
  31. package/dist/mcp/pool-cache.js.map +1 -0
  32. package/dist/mcp/pool.d.ts +65 -0
  33. package/dist/mcp/pool.d.ts.map +1 -0
  34. package/dist/mcp/pool.js +86 -0
  35. package/dist/mcp/pool.js.map +1 -0
  36. package/dist/media/file-events.d.ts +8 -0
  37. package/dist/media/file-events.d.ts.map +1 -0
  38. package/dist/media/file-events.js +15 -0
  39. package/dist/media/file-events.js.map +1 -0
  40. package/dist/memory/active-task-template.d.ts +34 -0
  41. package/dist/memory/active-task-template.d.ts.map +1 -0
  42. package/dist/memory/active-task-template.js +63 -0
  43. package/dist/memory/active-task-template.js.map +1 -0
  44. package/dist/memory/compressor.d.ts +87 -0
  45. package/dist/memory/compressor.d.ts.map +1 -0
  46. package/dist/memory/compressor.js +164 -0
  47. package/dist/memory/compressor.js.map +1 -0
  48. package/dist/memory/hash.d.ts +17 -0
  49. package/dist/memory/hash.d.ts.map +1 -0
  50. package/dist/memory/hash.js +20 -0
  51. package/dist/memory/hash.js.map +1 -0
  52. package/dist/memory/prune.d.ts +117 -0
  53. package/dist/memory/prune.d.ts.map +1 -0
  54. package/dist/memory/prune.js +416 -0
  55. package/dist/memory/prune.js.map +1 -0
  56. package/dist/memory/reminder.d.ts +57 -0
  57. package/dist/memory/reminder.d.ts.map +1 -0
  58. package/dist/memory/reminder.js +57 -0
  59. package/dist/memory/reminder.js.map +1 -0
  60. package/dist/memory/scrubber.d.ts +28 -0
  61. package/dist/memory/scrubber.d.ts.map +1 -0
  62. package/dist/memory/scrubber.js +147 -0
  63. package/dist/memory/scrubber.js.map +1 -0
  64. package/dist/memory/token-estimate.d.ts +10 -0
  65. package/dist/memory/token-estimate.d.ts.map +1 -0
  66. package/dist/memory/token-estimate.js +69 -0
  67. package/dist/memory/token-estimate.js.map +1 -0
  68. package/dist/platform/config.d.ts +12 -0
  69. package/dist/platform/config.d.ts.map +1 -0
  70. package/dist/platform/config.js +54 -0
  71. package/dist/platform/config.js.map +1 -0
  72. package/dist/platform/jsonl.d.ts +15 -0
  73. package/dist/platform/jsonl.d.ts.map +1 -0
  74. package/dist/platform/jsonl.js +80 -0
  75. package/dist/platform/jsonl.js.map +1 -0
  76. package/dist/platform/lifecycle.d.ts +22 -0
  77. package/dist/platform/lifecycle.d.ts.map +1 -0
  78. package/dist/platform/lifecycle.js +60 -0
  79. package/dist/platform/lifecycle.js.map +1 -0
  80. package/dist/platform/logger.d.ts +26 -0
  81. package/dist/platform/logger.d.ts.map +1 -0
  82. package/dist/platform/logger.js +41 -0
  83. package/dist/platform/logger.js.map +1 -0
  84. package/dist/platform/mcp-config.d.ts +15 -0
  85. package/dist/platform/mcp-config.d.ts.map +1 -0
  86. package/dist/platform/mcp-config.js +8 -0
  87. package/dist/platform/mcp-config.js.map +1 -0
  88. package/dist/provider.d.ts +81 -0
  89. package/dist/provider.d.ts.map +1 -0
  90. package/dist/provider.js +444 -0
  91. package/dist/provider.js.map +1 -0
  92. package/dist/providers/anthropic.d.ts +132 -0
  93. package/dist/providers/anthropic.d.ts.map +1 -0
  94. package/dist/providers/anthropic.js +518 -0
  95. package/dist/providers/anthropic.js.map +1 -0
  96. package/dist/providers/base.d.ts +140 -0
  97. package/dist/providers/base.d.ts.map +1 -0
  98. package/dist/providers/base.js +2 -0
  99. package/dist/providers/base.js.map +1 -0
  100. package/dist/providers/deepseek.d.ts +118 -0
  101. package/dist/providers/deepseek.d.ts.map +1 -0
  102. package/dist/providers/deepseek.js +467 -0
  103. package/dist/providers/deepseek.js.map +1 -0
  104. package/dist/registry.d.ts +3 -0
  105. package/dist/registry.d.ts.map +1 -0
  106. package/dist/registry.js +94 -0
  107. package/dist/registry.js.map +1 -0
  108. package/dist/session-store.d.ts +133 -0
  109. package/dist/session-store.d.ts.map +1 -0
  110. package/dist/session-store.js +277 -0
  111. package/dist/session-store.js.map +1 -0
  112. package/dist/skills/curator.d.ts +104 -0
  113. package/dist/skills/curator.d.ts.map +1 -0
  114. package/dist/skills/curator.js +162 -0
  115. package/dist/skills/curator.js.map +1 -0
  116. package/dist/skills/index-builder.d.ts +42 -0
  117. package/dist/skills/index-builder.d.ts.map +1 -0
  118. package/dist/skills/index-builder.js +94 -0
  119. package/dist/skills/index-builder.js.map +1 -0
  120. package/dist/skills/loader.d.ts +107 -0
  121. package/dist/skills/loader.d.ts.map +1 -0
  122. package/dist/skills/loader.js +286 -0
  123. package/dist/skills/loader.js.map +1 -0
  124. package/dist/skills/preprocess.d.ts +45 -0
  125. package/dist/skills/preprocess.d.ts.map +1 -0
  126. package/dist/skills/preprocess.js +126 -0
  127. package/dist/skills/preprocess.js.map +1 -0
  128. package/dist/skills/usage.d.ts +75 -0
  129. package/dist/skills/usage.d.ts.map +1 -0
  130. package/dist/skills/usage.js +147 -0
  131. package/dist/skills/usage.js.map +1 -0
  132. package/dist/state/todos.d.ts +95 -0
  133. package/dist/state/todos.d.ts.map +1 -0
  134. package/dist/state/todos.js +198 -0
  135. package/dist/state/todos.js.map +1 -0
  136. package/dist/storage/conversations.d.ts +28 -0
  137. package/dist/storage/conversations.d.ts.map +1 -0
  138. package/dist/storage/conversations.js +8 -0
  139. package/dist/storage/conversations.js.map +1 -0
  140. package/dist/sub-agent/runner.d.ts +78 -0
  141. package/dist/sub-agent/runner.d.ts.map +1 -0
  142. package/dist/sub-agent/runner.js +215 -0
  143. package/dist/sub-agent/runner.js.map +1 -0
  144. package/dist/tools/builtin/agent.d.ts +33 -0
  145. package/dist/tools/builtin/agent.d.ts.map +1 -0
  146. package/dist/tools/builtin/agent.js +76 -0
  147. package/dist/tools/builtin/agent.js.map +1 -0
  148. package/dist/tools/builtin/bash.d.ts +11 -0
  149. package/dist/tools/builtin/bash.d.ts.map +1 -0
  150. package/dist/tools/builtin/bash.js +91 -0
  151. package/dist/tools/builtin/bash.js.map +1 -0
  152. package/dist/tools/builtin/edit.d.ts +21 -0
  153. package/dist/tools/builtin/edit.d.ts.map +1 -0
  154. package/dist/tools/builtin/edit.js +238 -0
  155. package/dist/tools/builtin/edit.js.map +1 -0
  156. package/dist/tools/builtin/read.d.ts +17 -0
  157. package/dist/tools/builtin/read.d.ts.map +1 -0
  158. package/dist/tools/builtin/read.js +139 -0
  159. package/dist/tools/builtin/read.js.map +1 -0
  160. package/dist/tools/builtin/sandbox.d.ts +16 -0
  161. package/dist/tools/builtin/sandbox.d.ts.map +1 -0
  162. package/dist/tools/builtin/sandbox.js +58 -0
  163. package/dist/tools/builtin/sandbox.js.map +1 -0
  164. package/dist/tools/builtin/skill_view.d.ts +37 -0
  165. package/dist/tools/builtin/skill_view.d.ts.map +1 -0
  166. package/dist/tools/builtin/skill_view.js +82 -0
  167. package/dist/tools/builtin/skill_view.js.map +1 -0
  168. package/dist/tools/builtin/todo_write.d.ts +29 -0
  169. package/dist/tools/builtin/todo_write.d.ts.map +1 -0
  170. package/dist/tools/builtin/todo_write.js +96 -0
  171. package/dist/tools/builtin/todo_write.js.map +1 -0
  172. package/dist/tools/builtin/web_fetch.d.ts +10 -0
  173. package/dist/tools/builtin/web_fetch.d.ts.map +1 -0
  174. package/dist/tools/builtin/web_fetch.js +150 -0
  175. package/dist/tools/builtin/web_fetch.js.map +1 -0
  176. package/dist/tools/builtin/write.d.ts +35 -0
  177. package/dist/tools/builtin/write.d.ts.map +1 -0
  178. package/dist/tools/builtin/write.js +70 -0
  179. package/dist/tools/builtin/write.js.map +1 -0
  180. package/dist/tools/file-state.d.ts +99 -0
  181. package/dist/tools/file-state.d.ts.map +1 -0
  182. package/dist/tools/file-state.js +133 -0
  183. package/dist/tools/file-state.js.map +1 -0
  184. package/dist/tools/hooks/sandbox-fs.d.ts +25 -0
  185. package/dist/tools/hooks/sandbox-fs.d.ts.map +1 -0
  186. package/dist/tools/hooks/sandbox-fs.js +48 -0
  187. package/dist/tools/hooks/sandbox-fs.js.map +1 -0
  188. package/dist/tools/registry.d.ts +102 -0
  189. package/dist/tools/registry.d.ts.map +1 -0
  190. package/dist/tools/registry.js +93 -0
  191. package/dist/tools/registry.js.map +1 -0
  192. package/dist/types.d.ts +109 -0
  193. package/dist/types.d.ts.map +1 -0
  194. package/dist/types.js +20 -0
  195. package/dist/types.js.map +1 -0
  196. package/package.json +72 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yeonwoo Jeong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,24 @@
1
+ maestro-agent-sdk
2
+ =================
3
+
4
+ This project is a derivative work based on the Maestro agent runtime
5
+ originally developed by Nous Research as part of the hermes-agent project:
6
+
7
+ https://github.com/NousResearch/hermes-agent
8
+ Snapshot reference: v0.13.0 (2026-05-07)
9
+ Original license: MIT
10
+
11
+ Original copyright (MIT):
12
+ Copyright (c) 2025-2026 Nous Research
13
+
14
+ Changes in this distribution:
15
+ - Ported the Maestro Python runtime to TypeScript.
16
+ - Decoupled the agent loop, tool registry, providers (Anthropic, DeepSeek),
17
+ skills system, and memory compressor into an embeddable npm package.
18
+ - Removed the Telegram / Discord / Slack gateway, cron scheduler, and other
19
+ end-user surfaces that exist in the upstream standalone application.
20
+ - Replaced the host process's bespoke logger/lifecycle/config with
21
+ injectable interfaces so the SDK can be embedded by any host application.
22
+
23
+ The upstream MIT license terms continue to apply to the ported code; see
24
+ LICENSE for the SDK distribution license (also MIT).
package/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # maestro-agent-sdk
2
+
3
+ [![CI](https://github.com/maestrojeong/maestro-agent-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/maestrojeong/maestro-agent-sdk/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/maestro-agent-sdk.svg)](https://www.npmjs.com/package/maestro-agent-sdk)
5
+ [![license](https://img.shields.io/npm/l/maestro-agent-sdk.svg)](./LICENSE)
6
+
7
+ **Embeddable, provider-agnostic TypeScript agent SDK** — pluggable providers, built-in tools, skills, memory, and MCP.
8
+
9
+ > **Status:** Early port (v0.1.x). Active development. API surface may change before 1.0.
10
+
11
+ This package extracts the Maestro agent runtime — originally built into [Nous Research's `hermes-agent`](https://github.com/NousResearch/hermes-agent) — into a standalone npm package you can drop into any TypeScript / Node app.
12
+
13
+ ## What's in the box
14
+
15
+ - **Agent loop** — provider-driven tool-calling loop with iteration cap, abort signal, and event stream.
16
+ - **Pluggable providers** — first-class adapters for Anthropic (Claude) and DeepSeek V4; provider-neutral message schema so adding OpenAI / Gemini / Ollama is a thin file.
17
+ - **Built-in tools** — `bash`, `read`, `write`, `edit`, `agent` (sub-agent delegation), `todo_write`, `skill_view`, `web_fetch`. Bring your own via `ToolRegistry`.
18
+ - **MCP** — built-in client pool (stdio + SSE) so any MCP server (`@modelcontextprotocol/sdk`) shows up as tools.
19
+ - **Skills** — Anthropic-style `SKILL.md` packages with FTS-style indexing and on-demand expansion.
20
+ - **Memory** — automatic context compression (summarization + pruning) when the token budget is hit.
21
+ - **Filesystem sandbox** — optional path-allowlist hook for read/write/edit/bash.
22
+ - **Host integration via DI** — `setLogger`, `setMcpResolver`, `setConversationReader` let you embed without inheriting any one host's opinions.
23
+
24
+ ## Install
25
+
26
+ ```bash
27
+ npm install maestro-agent-sdk
28
+ # or
29
+ bun add maestro-agent-sdk
30
+ ```
31
+
32
+ Requires Node.js 20+.
33
+
34
+ ## Quick start
35
+
36
+ ```ts
37
+ import {
38
+ AIAgent,
39
+ AnthropicProvider,
40
+ bashTool,
41
+ createReadTool,
42
+ createWriteTool,
43
+ ToolRegistry,
44
+ runConversation,
45
+ } from "maestro-agent-sdk";
46
+
47
+ const provider = new AnthropicProvider({ apiKey: process.env.ANTHROPIC_API_KEY! });
48
+
49
+ const tools = new ToolRegistry();
50
+ tools.register(bashTool());
51
+ tools.register(createReadTool());
52
+ tools.register(createWriteTool());
53
+
54
+ const agent = new AIAgent(provider, tools, {
55
+ model: "claude-sonnet-4-6",
56
+ systemPrompt: "You are a helpful assistant.",
57
+ maxIterations: 30,
58
+ maxTokens: 4096,
59
+ });
60
+
61
+ for await (const event of runConversation(agent, "List files in /tmp.")) {
62
+ if (event.type === "text_delta") process.stdout.write(event.content);
63
+ if (event.type === "tool_use") console.error(`\n[tool] ${event.name}`);
64
+ }
65
+ ```
66
+
67
+ More runnable examples live under [`examples/`](./examples).
68
+
69
+ ## Architecture
70
+
71
+ ```
72
+ src/
73
+ ├── core/ AIAgent class + run_conversation loop
74
+ ├── tools/ ToolRegistry + builtin tools + hooks (sandbox-fs)
75
+ ├── providers/ Provider adapters (anthropic, deepseek)
76
+ ├── mcp/ MCP client pool (stdio + SSE)
77
+ ├── skills/ SKILL.md loader, index builder, usage tracker, curator
78
+ ├── memory/ Context compressor, token estimator, reminders, scrubber
79
+ ├── state/ Per-session todo store
80
+ ├── sub-agent/ Sub-agent runner for the `agent` tool
81
+ ├── platform/ Injectable host adapters (logger, lifecycle, config, jsonl, mcp-config)
82
+ ├── agents/ Cross-agent rollout helpers + per-agent registry contract
83
+ ├── storage/ ConversationReader DI (host supplies past turns for cross-agent forks)
84
+ └── media/ File-event extraction from inline `[FILE:/path]` tags
85
+ ```
86
+
87
+ The `platform/`, `storage/`, and `agents/contracts` modules expose **injection points** so the SDK never assumes a particular host process.
88
+
89
+ ## Host integration (DI)
90
+
91
+ ```ts
92
+ import {
93
+ setLogger,
94
+ setMcpResolver,
95
+ setConversationReader,
96
+ } from "maestro-agent-sdk";
97
+
98
+ // 1) Replace the console logger with your structured logger (pino, winston, ...).
99
+ setLogger(myPinoLogger);
100
+
101
+ // 2) Provide MCP server specs per-query.
102
+ setMcpResolver((opts) => ({
103
+ "playwright": { command: "playwright-mcp", args: [] },
104
+ "fs": { command: "mcp-fs", args: ["--root", opts.cwd] },
105
+ }));
106
+
107
+ // 3) Back-fill conversation history for cross-agent forks.
108
+ setConversationReader((userId, topic, groupId) => myStore.read({ userId, topic, groupId }));
109
+ ```
110
+
111
+ ## Development
112
+
113
+ ```bash
114
+ git clone git@github.com:maestrojeong/maestro-agent-sdk.git
115
+ cd maestro-agent-sdk
116
+ npm install
117
+ npm run typecheck # tsc --noEmit
118
+ npm run build # tsc + tsc-alias → dist/
119
+ npm test # vitest, 343 tests
120
+ ```
121
+
122
+ ### Known gaps
123
+
124
+ Two test files are currently excluded in `vitest.config.ts`:
125
+
126
+ - `maestro-registry.test.ts`
127
+ - `maestro-session-store.test.ts`
128
+
129
+ They rely on host-side helpers (`appendConversationEvent`, `getConversationPath`) and on the strict workspace-root check that the SDK loosened. They'll come back online once we wire them through the `ConversationReader` DI hook.
130
+
131
+ ## License
132
+
133
+ MIT. See [LICENSE](./LICENSE) and [NOTICE](./NOTICE) for upstream attribution to Nous Research.
@@ -0,0 +1,49 @@
1
+ import type { ConversationEntry } from "../storage/conversations.js";
2
+ import type { AgentKind, EffortLevel } from "../types.js";
3
+ /**
4
+ * Per-agent runtime config contract.
5
+ *
6
+ * The SDK ships `maestroRegistry` (see `src/registry.ts`) which implements
7
+ * this interface. Hosts that orchestrate multiple agents (claude, codex,
8
+ * maestro) typically build sibling registries for the others and select
9
+ * between them at query time.
10
+ */
11
+ export interface WriteRolloutOptions {
12
+ cwd: string;
13
+ entries: ConversationEntry[];
14
+ reuseSessionId?: string;
15
+ }
16
+ export interface WriteRolloutResult {
17
+ sessionId: string;
18
+ rolloutPath: string;
19
+ }
20
+ export interface ForkRegistryOptions {
21
+ parentSessionId: string;
22
+ cwd: string;
23
+ userId: number | string;
24
+ topicName: string;
25
+ groupId?: number;
26
+ title?: string;
27
+ }
28
+ export interface ForkRegistryResult {
29
+ forkId: string;
30
+ rolloutPath: string;
31
+ }
32
+ export interface CleanupRolloutsOptions {
33
+ cwd: string;
34
+ sessionIds: string[];
35
+ }
36
+ export interface AgentRegistry {
37
+ kind: AgentKind;
38
+ defaultModel: string;
39
+ defaultEffort?: EffortLevel;
40
+ expandModelAlias(s: string): string;
41
+ validateModel(s: string): boolean;
42
+ validEfforts: readonly EffortLevel[];
43
+ validateEffort(s: EffortLevel): boolean;
44
+ footerLabel(model: string, effort?: EffortLevel): string;
45
+ writeRollout(opts: WriteRolloutOptions): WriteRolloutResult;
46
+ forkSession(opts: ForkRegistryOptions): Promise<ForkRegistryResult>;
47
+ cleanupRollouts(opts: CleanupRolloutsOptions): Promise<void>;
48
+ }
49
+ //# sourceMappingURL=contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.d.ts","sourceRoot":"","sources":["../../src/agents/contracts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtD;;;;;;;GAOG;AAEH,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,WAAW,CAAC;IAC5B,gBAAgB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACpC,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,YAAY,EAAE,SAAS,WAAW,EAAE,CAAC;IACrC,cAAc,CAAC,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;IACxC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IACzD,YAAY,CAAC,IAAI,EAAE,mBAAmB,GAAG,kBAAkB,CAAC;IAC5D,WAAW,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACpE,eAAe,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9D"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.js","sourceRoot":"","sources":["../../src/agents/contracts.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Helpers shared by every agent's rollout encoder.
3
+ *
4
+ * Ported from clawgram. The cwd-validation step that hard-references
5
+ * WORKSPACE_DIR/ONBOARDING_DIR is loosened in the SDK build: hosts may
6
+ * route any cwd through the agent loop, and the SDK has no business
7
+ * dictating where a session may live. The other helpers (UUID shape,
8
+ * `extractChatPairs`) are kept verbatim.
9
+ */
10
+ import type { ConversationEntry } from "../../storage/conversations.js";
11
+ export declare function clone<T>(obj: T): T;
12
+ export declare function assertUuidLike(label: string, value: string): void;
13
+ /** Best-effort guarantee that the resumed cwd will exist when the SDK stats it. */
14
+ export declare function ensureCwdExists(cwd: string): void;
15
+ export type ChatPair = {
16
+ userText: string;
17
+ assistantText: string;
18
+ };
19
+ interface ExtractOptions {
20
+ includeToolAnnotations: boolean;
21
+ }
22
+ export declare function extractChatPairs(entries: ConversationEntry[], opts?: ExtractOptions): ChatPair[];
23
+ export {};
24
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/agents/rollout/shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,wBAAgB,KAAK,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAElC;AAID,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIjE;AAED,mFAAmF;AACnF,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAMjD;AAOD,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,UAAU,cAAc;IACtB,sBAAsB,EAAE,OAAO,CAAC;CACjC;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,EAAE,EAC5B,IAAI,GAAE,cAAiD,GACtD,QAAQ,EAAE,CAwEZ"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Helpers shared by every agent's rollout encoder.
3
+ *
4
+ * Ported from clawgram. The cwd-validation step that hard-references
5
+ * WORKSPACE_DIR/ONBOARDING_DIR is loosened in the SDK build: hosts may
6
+ * route any cwd through the agent loop, and the SDK has no business
7
+ * dictating where a session may live. The other helpers (UUID shape,
8
+ * `extractChatPairs`) are kept verbatim.
9
+ */
10
+ import { mkdirSync } from "node:fs";
11
+ import { logger } from "../../platform/logger.js";
12
+ export function clone(obj) {
13
+ return structuredClone(obj);
14
+ }
15
+ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
16
+ export function assertUuidLike(label, value) {
17
+ if (!UUID_RE.test(value)) {
18
+ throw new Error(`rollout: ${label} is not a UUID-shaped string: ${value}`);
19
+ }
20
+ }
21
+ /** Best-effort guarantee that the resumed cwd will exist when the SDK stats it. */
22
+ export function ensureCwdExists(cwd) {
23
+ try {
24
+ mkdirSync(cwd, { recursive: true });
25
+ }
26
+ catch (err) {
27
+ logger.warn({ err, cwd }, "rollout: ensureCwdExists failed — caller should pre-create cwd");
28
+ }
29
+ }
30
+ function truncate(text, n) {
31
+ const cps = Array.from(text);
32
+ return cps.length > n ? `${cps.slice(0, n).join("")}…` : text;
33
+ }
34
+ export function extractChatPairs(entries, opts = { includeToolAnnotations: true }) {
35
+ const pairs = [];
36
+ let pendingUser = null;
37
+ let pendingAssistantParts = [];
38
+ let toolBuffer = [];
39
+ const flushAssistant = () => {
40
+ if (pendingUser === null)
41
+ return;
42
+ const tools = opts.includeToolAnnotations && toolBuffer.length > 0 ? `\n\n${toolBuffer.join("\n")}` : "";
43
+ const assistantText = pendingAssistantParts.join("").trim() + tools;
44
+ if (assistantText.trim()) {
45
+ pairs.push({ userText: pendingUser, assistantText });
46
+ }
47
+ pendingUser = null;
48
+ pendingAssistantParts = [];
49
+ toolBuffer = [];
50
+ };
51
+ for (const entry of entries) {
52
+ const ev = entry.event;
53
+ switch (ev.type) {
54
+ case "user_message": {
55
+ flushAssistant();
56
+ pendingUser = ev.content;
57
+ break;
58
+ }
59
+ case "session":
60
+ if (pendingAssistantParts.length > 0 || toolBuffer.length > 0) {
61
+ flushAssistant();
62
+ }
63
+ break;
64
+ case "text": {
65
+ if (pendingUser === null) {
66
+ pendingUser = "(continued)";
67
+ }
68
+ pendingAssistantParts.push(ev.content);
69
+ break;
70
+ }
71
+ case "result": {
72
+ if (pendingUser === null) {
73
+ pendingUser = "(continued)";
74
+ }
75
+ pendingAssistantParts = [ev.content];
76
+ flushAssistant();
77
+ break;
78
+ }
79
+ case "text_delta":
80
+ break;
81
+ case "tool_use": {
82
+ const u = ev;
83
+ toolBuffer.push(`[Tool: ${u.name} ${truncate(JSON.stringify(u.input), 200)}]`);
84
+ break;
85
+ }
86
+ case "tool_result": {
87
+ const u = ev;
88
+ toolBuffer.push(`[Tool result: ${truncate(u.content, 200)}]`);
89
+ break;
90
+ }
91
+ case "error": {
92
+ const u = ev;
93
+ toolBuffer.push(`[Error: ${truncate(u.content, 200)}]`);
94
+ break;
95
+ }
96
+ case "tool_progress":
97
+ case "tool_use_summary":
98
+ case "file":
99
+ break;
100
+ }
101
+ }
102
+ flushAssistant();
103
+ return pairs;
104
+ }
105
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/agents/rollout/shared.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,71 @@
1
+ import type { Provider } from "../providers/base.js";
2
+ import type { ToolRegistry } from "../tools/registry.js";
3
+ import type { EffortLevel } from "../types.js";
4
+ /**
5
+ * AIAgent — minimal TS port of upstream `run_agent.py::AIAgent`.
6
+ *
7
+ * Upstream's AIAgent takes ~60 constructor params (credentials, callbacks,
8
+ * checkpoints, prefill messages, smart routing, reasoning configs, etc.).
9
+ * Phase 1 keeps the bare minimum needed to run a conversation against
10
+ * Anthropic with a tool registry — the rest of upstream's surface area is
11
+ * deferred or dropped because Clawgram owns the equivalent (gateway,
12
+ * permissions, conversation log, etc.).
13
+ */
14
+ export interface AIAgentConfig {
15
+ /** Resolved model id (e.g. `claude-sonnet-4-6`). */
16
+ model: string;
17
+ /** System prompt — built by Clawgram's prompt-builder before calling. */
18
+ systemPrompt: string;
19
+ /** Hard cap on tool-calling iterations. Default 90 to match upstream. */
20
+ maxIterations?: number;
21
+ /** Per-API-call max output tokens. Default 4096. */
22
+ maxTokens?: number;
23
+ /**
24
+ * Extended thinking budget in tokens. When > 0 the Anthropic provider sends
25
+ * `thinking: { type: "enabled", budget_tokens }` and auto-boosts max_tokens
26
+ * past the budget (Anthropic requires max_tokens > budget_tokens). Omit to
27
+ * skip thinking — the model emits no reasoning chain.
28
+ *
29
+ * Maps from `AgentQueryOptions.effort` in `maestroProvider`; values follow
30
+ * the rough scale claude-agent-sdk uses internally (low ≈ 2K, xhigh ≈ 32K).
31
+ */
32
+ thinkingBudget?: number;
33
+ /**
34
+ * Native effort level — passed straight through to providers that map it
35
+ * themselves (DeepSeek's `reasoning_effort`). Anthropic ignores this and
36
+ * uses `thinkingBudget`; both fields are populated by the call site so
37
+ * the provider picks its preferred shape.
38
+ */
39
+ effort?: EffortLevel;
40
+ /** External abort signal — wired to the AgentQueryOptions.abortController. */
41
+ abortSignal?: AbortSignal;
42
+ /**
43
+ * Per-iteration system-reminder builder. Invoked by `runConversation`
44
+ * just before pushing each `tool_result` user message; the returned text
45
+ * is appended as a trailing `text` block on that user message so the
46
+ * model sees a fresh "iterations remaining" line on every turn.
47
+ *
48
+ * Freezing the reminder into the canonical `messages` array (rather than
49
+ * mutating wireMessages on-the-fly) keeps Anthropic's prefix cache intact:
50
+ * each historical user message permanently carries the budget that was
51
+ * live at THAT turn, byte-stable across future calls.
52
+ *
53
+ * Return `null`/empty to skip injection for a given iteration (e.g. when
54
+ * the caller has nothing dynamic to surface). The FIRST user message's
55
+ * reminder is built by the caller before the loop starts — this callback
56
+ * only fires for subsequent tool_result turns.
57
+ */
58
+ buildIterReminder?: (iterationsRemaining: number) => string | null;
59
+ }
60
+ export declare class AIAgent {
61
+ readonly provider: Provider;
62
+ readonly tools: ToolRegistry;
63
+ readonly config: Required<Pick<AIAgentConfig, "model" | "systemPrompt" | "maxIterations" | "maxTokens">> & {
64
+ thinkingBudget?: number;
65
+ effort?: EffortLevel;
66
+ abortSignal?: AbortSignal;
67
+ buildIterReminder?: (iterationsRemaining: number) => string | null;
68
+ };
69
+ constructor(provider: Provider, tools: ToolRegistry, config: AIAgentConfig);
70
+ }
71
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/core/agent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;;;;;;GASG;AAEH,MAAM,WAAW,aAAa;IAC5B,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,YAAY,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,oDAAoD;IACpD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,8EAA8E;IAC9E,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;;;;;;;;;;;;;;OAeG;IACH,iBAAiB,CAAC,EAAE,CAAC,mBAAmB,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;CACpE;AAED,qBAAa,OAAO;IAClB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,QAAQ,CACvB,IAAI,CAAC,aAAa,EAAE,OAAO,GAAG,cAAc,GAAG,eAAe,GAAG,WAAW,CAAC,CAC9E,GAAG;QACF,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,WAAW,CAAC,EAAE,WAAW,CAAC;QAC1B,iBAAiB,CAAC,EAAE,CAAC,mBAAmB,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;KACpE,CAAC;gBAEU,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa;CAgB3E"}
@@ -0,0 +1,22 @@
1
+ export class AIAgent {
2
+ provider;
3
+ tools;
4
+ config;
5
+ constructor(provider, tools, config) {
6
+ this.provider = provider;
7
+ this.tools = tools;
8
+ this.config = {
9
+ model: config.model,
10
+ systemPrompt: config.systemPrompt,
11
+ maxIterations: config.maxIterations ?? 90,
12
+ maxTokens: config.maxTokens ?? 4096,
13
+ ...(config.thinkingBudget && config.thinkingBudget > 0
14
+ ? { thinkingBudget: config.thinkingBudget }
15
+ : {}),
16
+ ...(config.effort ? { effort: config.effort } : {}),
17
+ ...(config.abortSignal ? { abortSignal: config.abortSignal } : {}),
18
+ ...(config.buildIterReminder ? { buildIterReminder: config.buildIterReminder } : {}),
19
+ };
20
+ }
21
+ }
22
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../../src/core/agent.ts"],"names":[],"mappings":"AA8DA,MAAM,OAAO,OAAO;IACT,QAAQ,CAAW;IACnB,KAAK,CAAe;IACpB,MAAM,CAOb;IAEF,YAAY,QAAkB,EAAE,KAAmB,EAAE,MAAqB;QACxE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG;YACZ,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,YAAY,EAAE,MAAM,CAAC,YAAY;YACjC,aAAa,EAAE,MAAM,CAAC,aAAa,IAAI,EAAE;YACzC,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,IAAI;YACnC,GAAG,CAAC,MAAM,CAAC,cAAc,IAAI,MAAM,CAAC,cAAc,GAAG,CAAC;gBACpD,CAAC,CAAC,EAAE,cAAc,EAAE,MAAM,CAAC,cAAc,EAAE;gBAC3C,CAAC,CAAC,EAAE,CAAC;YACP,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnD,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAClE,GAAG,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACrF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ import type { AIAgent } from "../core/agent.js";
2
+ import type { ProviderMessage } from "../providers/base.js";
3
+ import type { UnifiedEvent } from "../types.js";
4
+ /**
5
+ * run_conversation — Maestro agent loop (TS port).
6
+ *
7
+ * Yields UnifiedEvents so the Clawgram dispatcher can stream them to telegram
8
+ * without caring about the underlying provider format.
9
+ *
10
+ * Multi-turn: the caller owns the `messages` array and passes it in
11
+ * pre-populated with prior history (loaded from `~/.maestro/sessions/<id>.jsonl`
12
+ * by `maestroProvider`) plus the new user prompt as the last entry. The loop
13
+ * mutates that array in place, appending assistant turns and tool-result
14
+ * user turns as the conversation progresses; once the generator drains, the
15
+ * caller persists the final `messages` back to disk for the next resume.
16
+ *
17
+ * This shape avoids returning the final history through the async iterator
18
+ * (which would either require a special "internal" UnifiedEvent variant or a
19
+ * companion side-channel — both worse than just sharing the array).
20
+ *
21
+ * Upstream reference: `run_agent.py::AIAgent.run_conversation` — same control
22
+ * flow, just `client.chat.completions.create` swapped for `provider.complete`
23
+ * and OpenAI message blocks swapped for Anthropic blocks.
24
+ */
25
+ export declare function runConversation(agent: AIAgent, messages: ProviderMessage[]): AsyncGenerator<UnifiedEvent>;
26
+ //# sourceMappingURL=loop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop.d.ts","sourceRoot":"","sources":["../../src/core/loop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAc,YAAY,EAAE,MAAM,SAAS,CAAC;AAkBxD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAuB,eAAe,CACpC,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,eAAe,EAAE,GAC1B,cAAc,CAAC,YAAY,CAAC,CAiS9B"}