wave-agent-sdk 0.12.6 → 0.12.8

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 (34) hide show
  1. package/builtin/skills/settings/MCP.md +17 -2
  2. package/builtin/skills/settings/SKILL.md +1 -0
  3. package/dist/managers/aiManager.d.ts.map +1 -1
  4. package/dist/managers/aiManager.js +11 -0
  5. package/dist/managers/mcpManager.d.ts.map +1 -1
  6. package/dist/managers/mcpManager.js +91 -43
  7. package/dist/managers/subagentManager.d.ts +9 -0
  8. package/dist/managers/subagentManager.d.ts.map +1 -1
  9. package/dist/managers/subagentManager.js +18 -0
  10. package/dist/prompts/autoMemoryExtraction.d.ts +5 -0
  11. package/dist/prompts/autoMemoryExtraction.d.ts.map +1 -0
  12. package/dist/prompts/autoMemoryExtraction.js +136 -0
  13. package/dist/services/autoMemoryService.d.ts +24 -0
  14. package/dist/services/autoMemoryService.d.ts.map +1 -0
  15. package/dist/services/autoMemoryService.js +134 -0
  16. package/dist/services/configurationService.d.ts +6 -0
  17. package/dist/services/configurationService.d.ts.map +1 -1
  18. package/dist/services/configurationService.js +33 -0
  19. package/dist/types/configuration.d.ts +2 -0
  20. package/dist/types/configuration.d.ts.map +1 -1
  21. package/dist/types/mcp.d.ts +3 -1
  22. package/dist/types/mcp.d.ts.map +1 -1
  23. package/dist/utils/containerSetup.d.ts.map +1 -1
  24. package/dist/utils/containerSetup.js +3 -0
  25. package/package.json +1 -1
  26. package/src/managers/aiManager.ts +15 -0
  27. package/src/managers/mcpManager.ts +116 -57
  28. package/src/managers/subagentManager.ts +36 -0
  29. package/src/prompts/autoMemoryExtraction.ts +146 -0
  30. package/src/services/autoMemoryService.ts +178 -0
  31. package/src/services/configurationService.ts +43 -0
  32. package/src/types/configuration.ts +2 -0
  33. package/src/types/mcp.ts +3 -1
  34. package/src/utils/containerSetup.ts +4 -0
@@ -1 +1 @@
1
- {"version":3,"file":"configurationService.d.ts","sourceRoot":"","sources":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,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,OAAO,EACZ,UAAU,CAAC,EAAE,MAAM,GAClB,2BAA2B,CAsD7B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC9C,OAAO,GAAE,uBAA4B,GACpC,wBAAwB,CAoC1B;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,GACf,iBAAiB,GAAG,IAAI,CA6B1B;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,GACd,iBAAiB,GAAG,IAAI,CAoJ1B"}
1
+ {"version":3,"file":"configurationService.d.ts","sourceRoot":"","sources":["../../src/services/configurationService.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EACV,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,KAAK,EACN,MAAM,2BAA2B,CAAC;AAOnC,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAE7B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,aAAa,EACb,WAAW,EAGX,cAAc,EACd,YAAY,EACb,MAAM,mBAAmB,CAAC;AAK3B,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAGvC;;;;;GAKG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,oBAAoB,CAAkC;IAC9D,OAAO,CAAC,GAAG,CAA8B;IACzC,OAAO,CAAC,OAAO,CAAoB;IAEnC;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAMvC;;OAEG;IACG,uBAAuB,CAC3B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,uBAAuB,CAAC;IA4Dn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BAAkB;IAa1D;;OAEG;IACG,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAoClE;;OAEG;IACG,mBAAmB,CACvB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,IAAI,CAAC;IAuChB;;OAEG;IACG,mBAAmB,CACvB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,IAAI,CAAC;IAmChB;;OAEG;IACH,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAKjE;;;OAGG;IACH,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI;CAGnE;AAKD;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,EAAE,OAAO,EACZ,UAAU,CAAC,EAAE,MAAM,GAClB,2BAA2B,CAsD7B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3C,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC9C,OAAO,GAAE,uBAA4B,GACpC,wBAAwB,CAoC1B;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,MAAM,GACf,iBAAiB,GAAG,IAAI,CA6B1B;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,GACd,iBAAiB,GAAG,IAAI,CAyJ1B"}
@@ -208,6 +208,13 @@ export class ConfigurationService {
208
208
  result.isValid = false;
209
209
  result.errors.push("autoMemoryEnabled configuration must be a boolean");
210
210
  }
211
+ // Validate autoMemoryFrequency if present
212
+ if (config.autoMemoryFrequency !== undefined &&
213
+ (typeof config.autoMemoryFrequency !== "number" ||
214
+ config.autoMemoryFrequency <= 0)) {
215
+ result.isValid = false;
216
+ result.errors.push("autoMemoryFrequency configuration must be a positive number");
217
+ }
211
218
  // Validate models if present
212
219
  if (config.models !== undefined) {
213
220
  if (typeof config.models !== "object" || config.models === null) {
@@ -464,6 +471,28 @@ export class ConfigurationService {
464
471
  // 3. Default (true)
465
472
  return true;
466
473
  }
474
+ /**
475
+ * Resolves auto-memory extraction frequency with fallbacks
476
+ * Resolution priority: settings.json > WAVE_AUTO_MEMORY_FREQUENCY > default (1)
477
+ * @returns Resolved auto-memory extraction frequency (turns)
478
+ */
479
+ resolveAutoMemoryFrequency() {
480
+ // 1. settings.json (merged)
481
+ if (this.currentConfiguration?.autoMemoryFrequency !== undefined) {
482
+ return this.currentConfiguration.autoMemoryFrequency;
483
+ }
484
+ // 2. WAVE_AUTO_MEMORY_FREQUENCY environment variable
485
+ const envFrequency = this.env.WAVE_AUTO_MEMORY_FREQUENCY ||
486
+ process.env.WAVE_AUTO_MEMORY_FREQUENCY;
487
+ if (envFrequency) {
488
+ const parsed = parseInt(envFrequency, 10);
489
+ if (!isNaN(parsed) && parsed > 0) {
490
+ return parsed;
491
+ }
492
+ }
493
+ // 3. Default (1)
494
+ return 1;
495
+ }
467
496
  /**
468
497
  * Resolves max output tokens with fallbacks
469
498
  * Resolution priority: override > options > env (from settings.json) > process.env > default
@@ -859,6 +888,10 @@ export function loadMergedWaveConfig(workdir) {
859
888
  if (config.autoMemoryEnabled !== undefined) {
860
889
  mergedConfig.autoMemoryEnabled = config.autoMemoryEnabled;
861
890
  }
891
+ // Merge autoMemoryFrequency (last one wins)
892
+ if (config.autoMemoryFrequency !== undefined) {
893
+ mergedConfig.autoMemoryFrequency = config.autoMemoryFrequency;
894
+ }
862
895
  // Merge models
863
896
  if (config.models) {
864
897
  if (!mergedConfig.models)
@@ -32,6 +32,8 @@ export interface WaveConfiguration {
32
32
  language?: string;
33
33
  /** Whether auto-memory is enabled */
34
34
  autoMemoryEnabled?: boolean;
35
+ /** Frequency of auto-memory extraction turns */
36
+ autoMemoryFrequency?: number;
35
37
  /** Model-specific configuration overrides */
36
38
  models?: Record<string, Partial<ModelConfig>>;
37
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../../src/types/configuration.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC;IACtD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,2CAA2C;IAC3C,WAAW,CAAC,EAAE;QACZ,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;QACjB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,cAAc,CAAC,EAAE,cAAc,CAAC;QAChC;;;WAGG;QACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;KAClC,CAAC;IACF,6CAA6C;IAC7C,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzC,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;CAC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M,EAAE,CAAC;IACpB,kEAAkE;IAClE,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,uCAAuC;IACvC,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,uCAAuC;IACvC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,2DAA2D;IAC3D,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,UAAU,MAAM;IACd,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACpC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACnC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACnC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACrC"}
@@ -3,9 +3,11 @@
3
3
  * Dependencies: None
4
4
  */
5
5
  export interface McpServerConfig {
6
- command: string;
6
+ command?: string;
7
7
  args?: string[];
8
8
  env?: Record<string, string>;
9
+ url?: string;
10
+ headers?: Record<string, string>;
9
11
  }
10
12
  export interface McpConfig {
11
13
  mcpServers: Record<string, McpServerConfig>;
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/types/mcp.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B;AAED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@@ -21,6 +21,7 @@ import { SubagentManager } from "../managers/subagentManager.js";
21
21
  import { LiveConfigManager } from "../managers/liveConfigManager.js";
22
22
  import { ReversionService } from "../services/reversionService.js";
23
23
  import { MemoryService } from "../services/memory.js";
24
+ import { AutoMemoryService } from "../services/autoMemoryService.js";
24
25
  import { getGitMainRepoRoot } from "./gitUtils.js";
25
26
  import { logger } from "./globalLogger.js";
26
27
  export function setupAgentContainer(setupOptions) {
@@ -37,6 +38,8 @@ export function setupAgentContainer(setupOptions) {
37
38
  }
38
39
  const memoryService = new MemoryService(container);
39
40
  container.register("MemoryService", memoryService);
41
+ const autoMemoryService = new AutoMemoryService(container);
42
+ container.register("AutoMemoryService", autoMemoryService);
40
43
  const memoryRuleManager = new MemoryRuleManager(container, { workdir });
41
44
  container.register("MemoryRuleManager", memoryRuleManager);
42
45
  const messageManager = new MessageManager(container, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wave-agent-sdk",
3
- "version": "0.12.6",
3
+ "version": "0.12.8",
4
4
  "description": "SDK for building AI-powered development tools and agents",
5
5
  "keywords": [
6
6
  "ai",
@@ -999,6 +999,21 @@ export class AIManager {
999
999
  );
1000
1000
  }
1001
1001
 
1002
+ // Trigger auto-memory extraction if enabled and this is the main agent
1003
+ if (!this.subagentType) {
1004
+ const autoMemoryService =
1005
+ this.container.get<
1006
+ import("../services/autoMemoryService.js").AutoMemoryService
1007
+ >("AutoMemoryService");
1008
+ if (autoMemoryService) {
1009
+ // Trigger extraction, but don't block the return.
1010
+ // onTurnEnd itself returns quickly after forking.
1011
+ autoMemoryService.onTurnEnd(this.workdir).catch((err) => {
1012
+ logger?.error("Auto-memory extraction trigger failed:", err);
1013
+ });
1014
+ }
1015
+ }
1016
+
1002
1017
  return shouldContinue;
1003
1018
  } catch (error) {
1004
1019
  // Hook execution errors should not interrupt the main workflow
@@ -2,6 +2,9 @@ import { promises as fs } from "fs";
2
2
  import { join } from "path";
3
3
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
4
4
  import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
5
+ import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
6
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
7
+ import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
5
8
  import { ChatCompletionFunctionTool } from "openai/resources.js";
6
9
  import { createMcpToolPlugin, findToolServer } from "../utils/mcpUtils.js";
7
10
  import type { ToolPlugin, ToolResult, ToolContext } from "../tools/types.js";
@@ -16,7 +19,7 @@ import type {
16
19
 
17
20
  interface McpConnection {
18
21
  client: Client;
19
- transport: StdioClientTransport;
22
+ transport: Transport;
20
23
  process: null; // StdioClientTransport manages process internally
21
24
  }
22
25
 
@@ -224,50 +227,119 @@ export class McpManager {
224
227
 
225
228
  try {
226
229
  // Create transport - it will manage the process
227
- const transport = new StdioClientTransport({
228
- command: server.config.command,
229
- args: server.config.args || [],
230
- env: {
231
- ...(process.env as Record<string, string>),
232
- ...(server.config.env || {}),
233
- },
234
- cwd: this.workdir, // Use the agent's workdir as the process working directory
235
- stderr: "pipe", // Pipe stderr to capture it
236
- });
230
+ let transport: Transport;
231
+ let client: Client;
232
+ let tools: McpTool[] = [];
233
+
234
+ const createClient = () =>
235
+ new Client(
236
+ {
237
+ name: "wave-code",
238
+ version: "1.0.0",
239
+ },
240
+ {
241
+ capabilities: {
242
+ tools: {},
243
+ },
244
+ },
245
+ );
237
246
 
238
- // Handle stderr output
239
- const stderr = transport.stderr;
240
- if (stderr) {
241
- let buffer = "";
242
- stderr.on("data", (chunk: Buffer) => {
243
- buffer += chunk.toString();
244
- const lines = buffer.split("\n");
245
- buffer = lines.pop() || "";
246
- for (const line of lines) {
247
- if (line.trim()) {
248
- logger?.error(`[MCP Server ${name}] ${line}`);
249
- }
250
- }
251
- });
252
- stderr.on("end", () => {
253
- if (buffer.trim()) {
254
- logger?.error(`[MCP Server ${name}] ${buffer}`);
255
- }
256
- });
257
- }
247
+ if (server.config.url) {
248
+ const url = new URL(server.config.url);
249
+ const headers = server.config.headers;
258
250
 
259
- // Create client
260
- const client = new Client(
261
- {
262
- name: "wave-code",
263
- version: "1.0.0",
264
- },
265
- {
266
- capabilities: {
267
- tools: {},
251
+ try {
252
+ logger?.debug(
253
+ `Attempting Streamable HTTP connection for ${name} at ${url.href}`,
254
+ );
255
+ const streamableTransport = new StreamableHTTPClientTransport(url, {
256
+ requestInit: { headers },
257
+ });
258
+
259
+ const streamableClient = createClient();
260
+ await streamableClient.connect(streamableTransport);
261
+
262
+ // Try to list tools to verify connection works
263
+ const toolsResponse = await streamableClient.listTools();
264
+
265
+ transport = streamableTransport;
266
+ client = streamableClient;
267
+ tools =
268
+ toolsResponse.tools?.map((tool) => ({
269
+ name: tool.name,
270
+ description: tool.description,
271
+ inputSchema: tool.inputSchema,
272
+ })) || [];
273
+
274
+ logger?.info(`Connected to MCP server ${name} using Streamable HTTP`);
275
+ } catch (error) {
276
+ logger?.debug(
277
+ `Streamable HTTP failed for ${name}, falling back to SSE: ${error instanceof Error ? error.message : String(error)}`,
278
+ );
279
+ transport = new SSEClientTransport(url, {
280
+ requestInit: { headers },
281
+ });
282
+ client = createClient();
283
+ await client.connect(transport);
284
+
285
+ const toolsResponse = await client.listTools();
286
+ tools =
287
+ toolsResponse.tools?.map((tool) => ({
288
+ name: tool.name,
289
+ description: tool.description,
290
+ inputSchema: tool.inputSchema,
291
+ })) || [];
292
+
293
+ logger?.info(`Connected to MCP server ${name} using SSE (fallback)`);
294
+ }
295
+ } else if (server.config.command) {
296
+ transport = new StdioClientTransport({
297
+ command: server.config.command,
298
+ args: server.config.args || [],
299
+ env: {
300
+ ...(process.env as Record<string, string>),
301
+ ...(server.config.env || {}),
268
302
  },
269
- },
270
- );
303
+ cwd: this.workdir, // Use the agent's workdir as the process working directory
304
+ stderr: "pipe", // Pipe stderr to capture it
305
+ });
306
+
307
+ // Handle stderr output for StdioClientTransport
308
+ const stderr = (transport as StdioClientTransport).stderr;
309
+ if (stderr) {
310
+ let buffer = "";
311
+ stderr.on("data", (chunk: Buffer) => {
312
+ buffer += chunk.toString();
313
+ const lines = buffer.split("\n");
314
+ buffer = lines.pop() || "";
315
+ for (const line of lines) {
316
+ if (line.trim()) {
317
+ logger?.error(`[MCP Server ${name}] ${line}`);
318
+ }
319
+ }
320
+ });
321
+ stderr.on("end", () => {
322
+ if (buffer.trim()) {
323
+ logger?.error(`[MCP Server ${name}] ${buffer}`);
324
+ }
325
+ });
326
+ }
327
+
328
+ client = createClient();
329
+ await client.connect(transport);
330
+
331
+ const toolsResponse = await client.listTools();
332
+ tools =
333
+ toolsResponse.tools?.map((tool) => ({
334
+ name: tool.name,
335
+ description: tool.description,
336
+ inputSchema: tool.inputSchema,
337
+ })) || [];
338
+ } else {
339
+ throw new Error(
340
+ `MCP server ${name} configuration must include either 'command' or 'url'`,
341
+ );
342
+ }
271
343
 
272
344
  // Handle transport errors
273
345
  transport.onerror = (error: Error) => {
@@ -288,24 +360,11 @@ export class McpManager {
288
360
  });
289
361
  };
290
362
 
291
- // Connect to transport
292
- await client.connect(transport);
293
-
294
- // List available tools
295
- const toolsResponse = await client.listTools();
296
-
297
- const tools: McpTool[] =
298
- toolsResponse.tools?.map((tool) => ({
299
- name: tool.name,
300
- description: tool.description,
301
- inputSchema: tool.inputSchema,
302
- })) || [];
303
-
304
- // Store connection (we don't have direct process access with StdioClientTransport)
363
+ // Store connection
305
364
  this.connections.set(name, {
306
365
  client,
307
366
  transport,
308
- process: null, // StdioClientTransport manages the process internally
367
+ process: null,
309
368
  });
310
369
 
311
370
  // Update status
@@ -260,6 +260,42 @@ export class SubagentManager {
260
260
  return instance;
261
261
  }
262
262
 
263
+ /**
264
+ * Create a new subagent instance initialized with a copy of the current message history.
265
+ * This is used for background tasks like auto-memory extraction.
266
+ */
267
+ async forkAgent(
268
+ subagentType: string,
269
+ messages: Message[],
270
+ parameters: {
271
+ description: string;
272
+ allowedTools?: string[];
273
+ model?: string;
274
+ },
275
+ onUpdate?: () => void,
276
+ ): Promise<SubagentInstance> {
277
+ const configuration = await this.findSubagent(subagentType);
278
+ if (!configuration) {
279
+ throw new Error(`Subagent type ${subagentType} not found`);
280
+ }
281
+
282
+ const instance = await this.createInstance(
283
+ configuration,
284
+ {
285
+ ...parameters,
286
+ subagent_type: subagentType,
287
+ prompt: "", // Forked agents start with history
288
+ },
289
+ false,
290
+ onUpdate,
291
+ );
292
+
293
+ // Initialize the message manager with provided messages
294
+ instance.messageManager.setMessages(messages);
295
+
296
+ return instance;
297
+ }
298
+
263
299
  /**
264
300
  * Execute agent using subagent instance
265
301
  *
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Memory types taxonomy and examples.
3
+ */
4
+ const MEMORY_TYPES = ["user", "feedback", "project", "reference"] as const;
5
+
6
+ const TYPES_SECTION = [
7
+ "## Types of memory",
8
+ "",
9
+ "There are several discrete types of memory that you can store in your memory system:",
10
+ "",
11
+ "<types>",
12
+ "<type>",
13
+ " <name>user</name>",
14
+ " <description>Contain information about the user's role, goals, responsibilities, and knowledge. Great user memories help you tailor your future behavior to the user's preferences and perspective. Your goal in reading and writing these memories is to build up an understanding of who the user is and how you can be most helpful to them specifically. For example, you should collaborate with a senior software engineer differently than a student who is coding for the very first time. Keep in mind, that the aim here is to be helpful to the user. Avoid writing memories about the user that could be viewed as a negative judgement or that are not relevant to the work you're trying to accomplish together.</description>",
15
+ " <when_to_save>When you learn any details about the user's role, preferences, responsibilities, or knowledge</when_to_save>",
16
+ " <how_to_use>When your work should be informed by the user's profile or perspective. For example, if the user is asking you to explain a part of the code, you should answer that question in a way that is tailored to the specific details that they will find most valuable or that helps them build their mental model in relation to domain knowledge they already have.</how_to_use>",
17
+ " <examples>",
18
+ " user: I'm a data scientist investigating what logging we have in place",
19
+ " assistant: [saves user memory: user is a data scientist, currently focused on observability/logging]",
20
+ "",
21
+ " user: I've been writing Go for ten years but this is my first time touching the React side of this repo",
22
+ " assistant: [saves user memory: deep Go expertise, new to React and this project's frontend — frame frontend explanations in terms of backend analogues]",
23
+ " </examples>",
24
+ "</type>",
25
+ "<type>",
26
+ " <name>feedback</name>",
27
+ " <description>Guidance the user has given you about how to approach work — both what to avoid and what to keep doing. These are a very important type of memory to read and write as they allow you to remain coherent and responsive to the way you should approach work in the project. Record from failure AND success: if you only save corrections, you will avoid past mistakes but drift away from approaches the user has already validated, and may grow overly cautious.</description>",
28
+ ' <when_to_save>Any time the user corrects your approach ("no not that", "don\'t", "stop doing X") OR confirms a non-obvious approach worked ("yes exactly", "perfect, keep doing that", accepting an unusual choice without pushback). Corrections are easy to notice; confirmations are quieter — watch for them. In both cases, save what is applicable to future conversations, especially if surprising or not obvious from the code. Include *why* so you can judge edge cases later.</when_to_save>',
29
+ " <how_to_use>Let these memories guide your behavior so that the user does not need to offer the same guidance twice.</how_to_use>",
30
+ " <body_structure>Lead with the rule itself, then a **Why:** line (the reason the user gave — often a past incident or strong preference) and a **How to apply:** line (when/where this guidance kicks in). Knowing *why* lets you judge edge cases instead of blindly following the rule.</body_structure>",
31
+ " <examples>",
32
+ " user: don't mock the database in these tests — we got burned last quarter when mocked tests passed but the prod migration failed",
33
+ " assistant: [saves feedback memory: integration tests must hit a real database, not mocks. Reason: prior incident where mock/prod divergence masked a broken migration]",
34
+ "",
35
+ " user: stop summarizing what you just did at the end of every response, I can read the diff",
36
+ " assistant: [saves feedback memory: this user wants terse responses with no trailing summaries]",
37
+ "",
38
+ " user: yeah the single bundled PR was the right call here, splitting this one would've just been churn",
39
+ " assistant: [saves feedback memory: for refactors in this area, user prefers one bundled PR over many small ones. Confirmed after I chose this approach — a validated judgment call, not a correction]",
40
+ " </examples>",
41
+ "</type>",
42
+ "<type>",
43
+ " <name>project</name>",
44
+ " <description>Information that you learn about ongoing work, goals, initiatives, bugs, or incidents within the project that is not otherwise derivable from the code or git history. Project memories help you understand the broader context and motivation behind the work the user is doing within this working directory.</description>",
45
+ ' <when_to_save>When you learn who is doing what, why, or by when. These states change relatively quickly so try to keep your understanding of this up to date. Always convert relative dates in user messages to absolute dates when saving (e.g., "Thursday" → "2026-03-05"), so the memory remains interpretable after time passes.</when_to_save>',
46
+ " <how_to_use>Use these memories to more fully understand the details and nuance behind the user's request and make better informed suggestions.</how_to_use>",
47
+ " <body_structure>Lead with the fact or decision, then a **Why:** line (the motivation — often a constraint, deadline, or stakeholder ask) and a **How to apply:** line (how this should shape your suggestions). Project memories decay fast, so the why helps future-you judge whether the memory is still load-bearing.</body_structure>",
48
+ " <examples>",
49
+ " user: we're freezing all non-critical merges after Thursday — mobile team is cutting a release branch",
50
+ " assistant: [saves project memory: merge freeze begins 2026-03-05 for mobile release cut. Flag any non-critical PR work scheduled after that date]",
51
+ "",
52
+ " user: the reason we're ripping out the old auth middleware is that legal flagged it for storing session tokens in a way that doesn't meet the new compliance requirements",
53
+ " assistant: [saves project memory: auth middleware rewrite is driven by legal/compliance requirements around session token storage, not tech-debt cleanup — scope decisions should favor compliance over ergonomics]",
54
+ " </examples>",
55
+ "</type>",
56
+ "<type>",
57
+ " <name>reference</name>",
58
+ " <description>Stores pointers to where information can be found in external systems. These memories allow you to remember where to look to find up-to-date information outside of the project directory.</description>",
59
+ " <when_to_save>When you learn about resources in external systems and their purpose. For example, that bugs are tracked in a specific project in Linear or that feedback can be found in a specific Slack channel.</when_to_save>",
60
+ " <how_to_use>When the user references an external system or information that may be in an external system.</how_to_use>",
61
+ " <examples>",
62
+ ' user: check the Linear project "INGEST" if you want context on these tickets, that\'s where we track all pipeline bugs',
63
+ ' assistant: [saves reference memory: pipeline bugs are tracked in Linear project "INGEST"]',
64
+ "",
65
+ " user: the Grafana board at grafana.internal/d/api-latency is what oncall watches — if you're touching request handling, that's the thing that'll page someone",
66
+ " assistant: [saves reference memory: grafana.internal/d/api-latency is the oncall latency dashboard — check it when editing request-path code]",
67
+ " </examples>",
68
+ "</type>",
69
+ "</types>",
70
+ ].join("\n");
71
+
72
+ const WHAT_NOT_TO_SAVE_SECTION = [
73
+ "## What NOT to save in memory",
74
+ "",
75
+ "- Code patterns, conventions, architecture, file paths, or project structure — these can be derived by reading the current project state.",
76
+ "- Git history, recent changes, or who-changed-what — `git log` / `git blame` are authoritative.",
77
+ "- Debugging solutions or fix recipes — the fix is in the code; the commit message has the context.",
78
+ "- Anything already documented in CLAUDE.md files.",
79
+ "- Ephemeral task details: in-progress work, temporary state, current conversation context.",
80
+ "",
81
+ "These exclusions apply even when the user explicitly asks you to save. If they ask you to save a PR list or activity summary, ask what was *surprising* or *non-obvious* about it — that is the part worth keeping.",
82
+ ].join("\n");
83
+
84
+ const MEMORY_FRONTMATTER_EXAMPLE = [
85
+ "```markdown",
86
+ "---",
87
+ "name: {{memory name}}",
88
+ "description: {{one-line description — used to decide relevance in future conversations, so be specific}}",
89
+ `type: {{${MEMORY_TYPES.join(", ")}}}`,
90
+ "---",
91
+ "",
92
+ "{{memory content — for feedback/project types, structure as: rule/fact, then **Why:** and **How to apply:** lines}}",
93
+ "```",
94
+ ].join("\n");
95
+
96
+ /**
97
+ * Build the auto-memory extraction prompt for the background agent.
98
+ */
99
+ export function buildAutoMemoryExtractionPrompt(
100
+ newMessageCount: number,
101
+ existingMemoriesManifest: string,
102
+ ): string {
103
+ const manifestSection =
104
+ existingMemoriesManifest.length > 0
105
+ ? `\n\n## Existing memory files\n\n${existingMemoriesManifest}\n\nCheck this list before writing — update an existing file rather than creating a duplicate.`
106
+ : "";
107
+
108
+ const howToSave = [
109
+ "## How to save memories",
110
+ "",
111
+ "Saving a memory is a two-step process:",
112
+ "",
113
+ "**Step 1** — write the memory to its own file (e.g., `user_role.md`, `feedback_testing.md`) using this frontmatter format:",
114
+ "",
115
+ MEMORY_FRONTMATTER_EXAMPLE,
116
+ "",
117
+ "**Step 2** — add a pointer to that file in `MEMORY.md`. `MEMORY.md` is an index, not a memory — each entry should be one line, under ~150 characters: `- [Title](file.md) — one-line hook`. It has no frontmatter. Never write memory content directly into `MEMORY.md`.",
118
+ "",
119
+ "- `MEMORY.md` is always loaded into your system prompt — lines after 200 will be truncated, so keep the index concise",
120
+ "- Organize memory semantically by topic, not chronologically",
121
+ "- Update or remove memories that turn out to be wrong or outdated",
122
+ "- Do not write duplicate memories. First check if there is an existing memory you can update before writing a new one.",
123
+ ].join("\n");
124
+
125
+ return [
126
+ `You are now acting as the memory extraction subagent. Analyze the most recent ~${newMessageCount} messages above and use them to update your persistent memory systems.`,
127
+ "",
128
+ `Available tools: Read, Grep, Glob, read-only Bash (ls/find/cat/stat/wc/head/tail and similar), and Write/Edit for paths inside the memory directory only. Bash rm is not permitted. All other tools — MCP, Agent, write-capable Bash, etc — will be denied.`,
129
+ "",
130
+ `You have a limited turn budget. Edit requires a prior Read of the same file, so the efficient strategy is: turn 1 — issue all Read calls in parallel for every file you might update; turn 2 — issue all Write/Edit calls in parallel. Do not interleave reads and writes across multiple turns.`,
131
+ "",
132
+ `You MUST only use content from the last ~${newMessageCount} messages to update your persistent memories. Do not waste any turns attempting to investigate or verify that content further — no grepping source files, no reading code to confirm a pattern exists, no git commands.` +
133
+ manifestSection,
134
+ "",
135
+ "If the user explicitly asks you to remember something, save it immediately as whichever type fits best. If they ask you to forget something, find and remove the relevant entry.",
136
+ "",
137
+ TYPES_SECTION,
138
+ "",
139
+ WHAT_NOT_TO_SAVE_SECTION,
140
+ "",
141
+ howToSave,
142
+ "",
143
+ "### Task:",
144
+ "Extract new memories from the latest turns and save them to the memory directory.",
145
+ ].join("\n");
146
+ }