macro-agent 0.2.0 → 0.2.1

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 (42) hide show
  1. package/dist/acp/macro-agent.d.ts.map +1 -1
  2. package/dist/acp/macro-agent.js +18 -40
  3. package/dist/acp/macro-agent.js.map +1 -1
  4. package/dist/agent/agent-manager-v2.d.ts.map +1 -1
  5. package/dist/agent/agent-manager-v2.js +1 -1
  6. package/dist/agent/agent-manager-v2.js.map +1 -1
  7. package/dist/boot-v2.d.ts.map +1 -1
  8. package/dist/boot-v2.js +2 -0
  9. package/dist/boot-v2.js.map +1 -1
  10. package/dist/cli/acp.js +0 -0
  11. package/dist/cli/index.js +0 -0
  12. package/dist/cli/mcp.js +0 -0
  13. package/dist/dispatch/mail-inbound-consumer.d.ts +47 -0
  14. package/dist/dispatch/mail-inbound-consumer.d.ts.map +1 -1
  15. package/dist/dispatch/mail-inbound-consumer.js +117 -18
  16. package/dist/dispatch/mail-inbound-consumer.js.map +1 -1
  17. package/dist/map/repo-workspace.d.ts +46 -0
  18. package/dist/map/repo-workspace.d.ts.map +1 -0
  19. package/dist/map/repo-workspace.js +39 -0
  20. package/dist/map/repo-workspace.js.map +1 -0
  21. package/dist/map/server.d.ts.map +1 -1
  22. package/dist/map/server.js +1 -0
  23. package/dist/map/server.js.map +1 -1
  24. package/dist/map/sidecar.d.ts.map +1 -1
  25. package/dist/map/sidecar.js +63 -0
  26. package/dist/map/sidecar.js.map +1 -1
  27. package/dist/map/types.d.ts +14 -0
  28. package/dist/map/types.d.ts.map +1 -1
  29. package/dist/workspace/dataplane-adapter.d.ts +260 -0
  30. package/dist/workspace/dataplane-adapter.d.ts.map +1 -0
  31. package/dist/workspace/dataplane-adapter.js +416 -0
  32. package/dist/workspace/dataplane-adapter.js.map +1 -0
  33. package/package.json +2 -1
  34. package/src/acp/macro-agent.ts +20 -42
  35. package/src/agent/agent-manager-v2.ts +1 -0
  36. package/src/boot-v2.ts +2 -0
  37. package/src/dispatch/__tests__/mail-inbound-consumer.test.ts +211 -0
  38. package/src/dispatch/mail-inbound-consumer.ts +195 -32
  39. package/src/map/repo-workspace.ts +82 -0
  40. package/src/map/server.ts +1 -0
  41. package/src/map/sidecar.ts +85 -0
  42. package/src/map/types.ts +13 -0
@@ -0,0 +1,416 @@
1
+ /**
2
+ * Dataplane Adapter
3
+ *
4
+ * Wraps MultiAgentRepoTracker to integrate with macro-agent's event system
5
+ * and provide a simplified interface for workspace management.
6
+ *
7
+ * @module workspace/dataplane-adapter
8
+ * @implements [[s-7ktd]] Dataplane Integration section
9
+ */
10
+ import { MultiAgentRepoTracker, workerTasks, diffStacks, } from 'git-cascade';
11
+ import { DEFAULT_DATAPLANE_CONFIG } from './config.js';
12
+ /**
13
+ * DataplaneAdapter wraps MultiAgentRepoTracker for macro-agent integration.
14
+ *
15
+ * Key responsibilities:
16
+ * - Initialize dataplane with shared or dedicated database
17
+ * - Emit events on dataplane operations
18
+ * - Provide simplified API for workspace management
19
+ */
20
+ export class DataplaneAdapter {
21
+ tracker;
22
+ config;
23
+ eventListeners = new Set();
24
+ ownsDb;
25
+ /**
26
+ * Create a new DataplaneAdapter.
27
+ *
28
+ * @param config - Dataplane configuration
29
+ */
30
+ constructor(config) {
31
+ const mergedConfig = {
32
+ ...DEFAULT_DATAPLANE_CONFIG,
33
+ ...config,
34
+ repoPath: config.repoPath ?? process.cwd(),
35
+ };
36
+ this.config = {
37
+ enabled: mergedConfig.enabled ?? true,
38
+ repoPath: mergedConfig.repoPath,
39
+ tablePrefix: mergedConfig.tablePrefix ?? 'dataplane_',
40
+ verbose: mergedConfig.verbose ?? false,
41
+ skipRecovery: mergedConfig.skipRecovery ?? false,
42
+ };
43
+ // Determine if we own the database connection
44
+ this.ownsDb = !config.db;
45
+ const trackerOptions = {
46
+ repoPath: this.config.repoPath,
47
+ tablePrefix: this.config.tablePrefix,
48
+ verbose: this.config.verbose,
49
+ skipRecovery: this.config.skipRecovery,
50
+ };
51
+ if (config.db) {
52
+ trackerOptions.db = config.db;
53
+ }
54
+ else if (config.dbPath) {
55
+ trackerOptions.dbPath = config.dbPath;
56
+ }
57
+ // If neither db nor dbPath provided, tracker uses default path
58
+ this.tracker = new MultiAgentRepoTracker(trackerOptions);
59
+ }
60
+ /**
61
+ * Get whether dataplane is enabled.
62
+ */
63
+ get enabled() {
64
+ return this.config.enabled;
65
+ }
66
+ /**
67
+ * Get the repository path.
68
+ */
69
+ get repoPath() {
70
+ return this.config.repoPath;
71
+ }
72
+ /**
73
+ * Get the underlying database connection.
74
+ * Use with caution - prefer adapter methods for operations.
75
+ */
76
+ get db() {
77
+ return this.tracker.db;
78
+ }
79
+ /**
80
+ * Get the underlying tracker.
81
+ * Use with caution - prefer adapter methods for operations.
82
+ */
83
+ get rawTracker() {
84
+ return this.tracker;
85
+ }
86
+ // ─────────────────────────────────────────────────────────────────────────────
87
+ // Event System
88
+ // ─────────────────────────────────────────────────────────────────────────────
89
+ /**
90
+ * Subscribe to dataplane events.
91
+ *
92
+ * @param callback - Function called when events occur
93
+ * @returns Unsubscribe function
94
+ */
95
+ onEvent(callback) {
96
+ this.eventListeners.add(callback);
97
+ return () => this.eventListeners.delete(callback);
98
+ }
99
+ /**
100
+ * Emit an event to all listeners.
101
+ */
102
+ emit(type, data) {
103
+ const event = {
104
+ type,
105
+ timestamp: Date.now(),
106
+ data,
107
+ };
108
+ for (const listener of this.eventListeners) {
109
+ try {
110
+ listener(event);
111
+ }
112
+ catch (error) {
113
+ console.error('[DataplaneAdapter] Event listener error:', error);
114
+ }
115
+ }
116
+ }
117
+ // ─────────────────────────────────────────────────────────────────────────────
118
+ // Stream Operations
119
+ // ─────────────────────────────────────────────────────────────────────────────
120
+ /**
121
+ * Create a new stream (integration branch).
122
+ *
123
+ * @param options - Stream creation options
124
+ * @returns Stream ID
125
+ */
126
+ createStream(options) {
127
+ const streamId = this.tracker.createStream(options);
128
+ this.emit('stream:created', { streamId, ...options });
129
+ return streamId;
130
+ }
131
+ /**
132
+ * Get a stream by ID.
133
+ */
134
+ getStream(streamId) {
135
+ return this.tracker.getStream(streamId);
136
+ }
137
+ /**
138
+ * List streams with optional filters.
139
+ */
140
+ listStreams(options) {
141
+ return this.tracker.listStreams(options);
142
+ }
143
+ /**
144
+ * Update a stream.
145
+ */
146
+ updateStream(streamId, updates) {
147
+ this.tracker.updateStream(streamId, updates);
148
+ this.emit('stream:updated', { streamId, updates });
149
+ }
150
+ /**
151
+ * Abandon a stream.
152
+ */
153
+ abandonStream(streamId, options) {
154
+ this.tracker.abandonStream(streamId, options);
155
+ this.emit('stream:abandoned', { streamId, ...options });
156
+ }
157
+ /**
158
+ * Get the git branch name for a stream.
159
+ */
160
+ getStreamBranchName(streamId) {
161
+ return this.tracker.getStreamBranchName(streamId);
162
+ }
163
+ /**
164
+ * Get the HEAD commit of a stream.
165
+ */
166
+ getStreamHead(streamId) {
167
+ return this.tracker.getStreamHead(streamId);
168
+ }
169
+ // ─────────────────────────────────────────────────────────────────────────────
170
+ // Worktree Operations
171
+ // ─────────────────────────────────────────────────────────────────────────────
172
+ /**
173
+ * Create a worktree for an agent.
174
+ *
175
+ * @param options - Worktree creation options
176
+ * @returns Created worktree info
177
+ */
178
+ createWorktree(options) {
179
+ const worktree = this.tracker.createWorktree(options);
180
+ this.emit('worktree:created', { ...worktree });
181
+ return worktree;
182
+ }
183
+ /**
184
+ * Get a worktree by agent ID.
185
+ */
186
+ getWorktree(agentId) {
187
+ return this.tracker.getWorktree(agentId);
188
+ }
189
+ /**
190
+ * List all worktrees.
191
+ */
192
+ listWorktrees() {
193
+ return this.tracker.listWorktrees();
194
+ }
195
+ /**
196
+ * Update the stream associated with a worktree.
197
+ */
198
+ updateWorktreeStream(agentId, streamId) {
199
+ this.tracker.updateWorktreeStream(agentId, streamId);
200
+ }
201
+ /**
202
+ * Deallocate a worktree.
203
+ */
204
+ deallocateWorktree(agentId) {
205
+ this.tracker.deallocateWorktree(agentId);
206
+ this.emit('worktree:deallocated', { agentId });
207
+ }
208
+ // ─────────────────────────────────────────────────────────────────────────────
209
+ // Worker Task Operations
210
+ // ─────────────────────────────────────────────────────────────────────────────
211
+ /**
212
+ * Create a worker task under a stream.
213
+ *
214
+ * @param options - Task creation options
215
+ * @returns Task ID
216
+ */
217
+ createTask(options) {
218
+ const taskId = this.tracker.createTask(options);
219
+ this.emit('task:created', { taskId, ...options });
220
+ return taskId;
221
+ }
222
+ /**
223
+ * Get a task by ID.
224
+ */
225
+ getTask(taskId) {
226
+ return this.tracker.getTask(taskId);
227
+ }
228
+ /**
229
+ * List tasks for a stream.
230
+ */
231
+ listTasks(streamId, options) {
232
+ return this.tracker.listTasks(streamId, options);
233
+ }
234
+ /**
235
+ * Start a task - assigns agent and creates worker branch.
236
+ *
237
+ * @param options - Start task options
238
+ * @returns Branch name and start commit
239
+ */
240
+ startTask(options) {
241
+ const result = this.tracker.startTask(options);
242
+ this.emit('task:started', {
243
+ taskId: options.taskId,
244
+ agentId: options.agentId,
245
+ branchName: result.branchName,
246
+ startCommit: result.startCommit,
247
+ });
248
+ return result;
249
+ }
250
+ /**
251
+ * Complete a task - merges worker branch to stream.
252
+ *
253
+ * @param options - Complete task options
254
+ * @returns Merge result
255
+ */
256
+ completeTask(options) {
257
+ const result = this.tracker.completeTask(options);
258
+ this.emit('task:completed', { taskId: options.taskId, ...result });
259
+ return result;
260
+ }
261
+ /**
262
+ * Abandon a task.
263
+ *
264
+ * @param taskId - Task ID
265
+ * @param options - Options
266
+ */
267
+ abandonTask(taskId, options) {
268
+ this.tracker.abandonTask(taskId, options);
269
+ this.emit('task:abandoned', { taskId, ...options });
270
+ }
271
+ /**
272
+ * Release a task back to 'open' status.
273
+ */
274
+ releaseTask(taskId) {
275
+ this.tracker.releaseTask(taskId);
276
+ }
277
+ /**
278
+ * Detect conflicts for a task before completing.
279
+ *
280
+ * @param taskId - Task ID
281
+ * @param worktree - Worktree path
282
+ * @returns Array of conflicting file paths, empty if no conflicts
283
+ */
284
+ detectTaskConflicts(taskId, worktree) {
285
+ return workerTasks.detectTaskConflicts(this.tracker.db, this.config.repoPath, taskId, worktree);
286
+ }
287
+ /**
288
+ * Recover stale tasks that have been in_progress too long.
289
+ *
290
+ * @param thresholdMs - Tasks older than this are considered stale
291
+ * @returns Result with released task IDs
292
+ */
293
+ recoverStaleTasks(thresholdMs = 60 * 60 * 1000) {
294
+ return workerTasks.recoverStaleTasks(this.tracker.db, thresholdMs);
295
+ }
296
+ // ─────────────────────────────────────────────────────────────────────────────
297
+ // Checkpoint Operations
298
+ // ─────────────────────────────────────────────────────────────────────────────
299
+ /**
300
+ * Create checkpoints for commits made during a task.
301
+ *
302
+ * Creates a checkpoint for each commit between the task's startCommit and
303
+ * the current HEAD of the task's stream. This captures the work done during
304
+ * the task for future review and merge workflows.
305
+ *
306
+ * @param taskId - Task ID to create checkpoints for
307
+ * @param agentId - Agent ID (used as createdBy)
308
+ * @returns Array of created checkpoints
309
+ */
310
+ createCheckpointsForTask(taskId, agentId) {
311
+ const task = this.getTask(taskId);
312
+ if (!task) {
313
+ console.warn(`[DataplaneAdapter] Task not found: ${taskId}`);
314
+ return [];
315
+ }
316
+ if (!task.streamId) {
317
+ console.warn(`[DataplaneAdapter] Task ${taskId} has no streamId`);
318
+ return [];
319
+ }
320
+ if (!task.startCommit) {
321
+ console.warn(`[DataplaneAdapter] Task ${taskId} has no startCommit`);
322
+ return [];
323
+ }
324
+ try {
325
+ // Create checkpoints from task's startCommit to stream's current HEAD
326
+ const checkpoints = diffStacks.createCheckpointsFromStream(this.tracker.db, this.config.repoPath, task.streamId, {
327
+ from: task.startCommit,
328
+ createdBy: agentId,
329
+ });
330
+ return checkpoints;
331
+ }
332
+ catch (error) {
333
+ console.error(`[DataplaneAdapter] Failed to create checkpoints for task ${taskId}:`, error);
334
+ return [];
335
+ }
336
+ }
337
+ // ─────────────────────────────────────────────────────────────────────────────
338
+ // Commit Operations
339
+ // ─────────────────────────────────────────────────────────────────────────────
340
+ /**
341
+ * Commit changes in a worktree with Change tracking.
342
+ *
343
+ * @param options - Commit options
344
+ * @returns Commit hash and change ID
345
+ */
346
+ commitChanges(options) {
347
+ return this.tracker.commitChanges(options);
348
+ }
349
+ // ─────────────────────────────────────────────────────────────────────────────
350
+ // Maintenance Operations
351
+ // ─────────────────────────────────────────────────────────────────────────────
352
+ /**
353
+ * Clean up old worker branches.
354
+ *
355
+ * Deletes branches for:
356
+ * - Completed tasks older than threshold (default 24h)
357
+ * - Abandoned tasks
358
+ * - Orphaned branches (no task record)
359
+ *
360
+ * @param options - Cleanup options
361
+ * @returns Deleted branches and any errors
362
+ */
363
+ cleanupWorkerBranches(options) {
364
+ return workerTasks.cleanupWorkerBranches(this.tracker.db, this.config.repoPath, options);
365
+ }
366
+ /**
367
+ * Delete a specific worker branch.
368
+ *
369
+ * @param branchName - Branch name to delete
370
+ * @returns true if deleted, false if branch didn't exist
371
+ */
372
+ deleteWorkerBranch(branchName) {
373
+ try {
374
+ const { execSync } = require('child_process');
375
+ execSync(`git branch -D "${branchName}"`, {
376
+ cwd: this.config.repoPath,
377
+ stdio: 'pipe',
378
+ });
379
+ return true;
380
+ }
381
+ catch {
382
+ return false;
383
+ }
384
+ }
385
+ // ─────────────────────────────────────────────────────────────────────────────
386
+ // Health & Recovery
387
+ // ─────────────────────────────────────────────────────────────────────────────
388
+ /**
389
+ * Check system health.
390
+ */
391
+ healthCheck() {
392
+ return this.tracker.healthCheck();
393
+ }
394
+ // ─────────────────────────────────────────────────────────────────────────────
395
+ // Lifecycle
396
+ // ─────────────────────────────────────────────────────────────────────────────
397
+ /**
398
+ * Close the adapter and release resources.
399
+ *
400
+ * Only closes the database if we created it (not if using shared DB).
401
+ */
402
+ close() {
403
+ this.eventListeners.clear();
404
+ this.tracker.close();
405
+ }
406
+ }
407
+ /**
408
+ * Create a DataplaneAdapter instance.
409
+ *
410
+ * @param config - Configuration options
411
+ * @returns DataplaneAdapter instance
412
+ */
413
+ export function createDataplaneAdapter(config) {
414
+ return new DataplaneAdapter(config);
415
+ }
416
+ //# sourceMappingURL=dataplane-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataplane-adapter.js","sourceRoot":"","sources":["../../src/workspace/dataplane-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EACL,qBAAqB,EAiBrB,WAAW,EACX,UAAU,GACX,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AA8BvD;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAgB;IACV,OAAO,CAAwB;IAC/B,MAAM,CAEE;IACR,cAAc,GAAgC,IAAI,GAAG,EAAE,CAAC;IACxD,MAAM,CAAU;IAEjC;;;;OAIG;IACH,YAAY,MAAuB;QACjC,MAAM,YAAY,GAAG;YACnB,GAAG,wBAAwB;YAC3B,GAAG,MAAM;YACT,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,OAAO,CAAC,GAAG,EAAE;SAC3C,CAAC;QAEF,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,YAAY,CAAC,OAAO,IAAI,IAAI;YACrC,QAAQ,EAAE,YAAY,CAAC,QAAQ;YAC/B,WAAW,EAAE,YAAY,CAAC,WAAW,IAAI,YAAY;YACrD,OAAO,EAAE,YAAY,CAAC,OAAO,IAAI,KAAK;YACtC,YAAY,EAAE,YAAY,CAAC,YAAY,IAAI,KAAK;SACjD,CAAC;QAEF,8CAA8C;QAC9C,IAAI,CAAC,MAAM,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAEzB,MAAM,cAAc,GAAmB;YACrC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,QAAQ;YAC9B,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW;YACpC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO;YAC5B,YAAY,EAAE,IAAI,CAAC,MAAM,CAAC,YAAY;SACvC,CAAC;QAEF,IAAI,MAAM,CAAC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AAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;AACtC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "macro-agent",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Interact with multiple agents as if they were a single agent.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -53,6 +53,7 @@
53
53
  "@multi-agent-protocol/sdk": "^0.1.12",
54
54
  "acp-factory": "^0.1.14",
55
55
  "agent-inbox": "^0.2.2",
56
+ "agent-workspace": "^0.1.5",
56
57
  "better-sqlite3": "^12.5.0",
57
58
  "chalk": "^5.6.2",
58
59
  "commander": "^14.0.2",
@@ -205,18 +205,22 @@ export function createMacroAgent(
205
205
  method: string,
206
206
  params: Record<string, unknown>,
207
207
  ): Promise<Record<string, unknown>> {
208
+ const normalizedMethod = method.startsWith("macro/")
209
+ ? `_${method}`
210
+ : method;
211
+
208
212
  // Check if it's a stubbed peer method
209
213
  if (
210
- (STUBBED_PEER_EXTENSIONS as readonly string[]).includes(method)
214
+ (STUBBED_PEER_EXTENSIONS as readonly string[]).includes(normalizedMethod)
211
215
  ) {
212
216
  throw new ACPError(
213
- `Peer manager not available: ${method}`,
217
+ `Peer manager not available: ${normalizedMethod}`,
214
218
  "NO_PEER_MANAGER",
215
- { method },
219
+ { method: normalizedMethod },
216
220
  );
217
221
  }
218
222
 
219
- switch (method as SupportedExtension) {
223
+ switch (normalizedMethod as SupportedExtension) {
220
224
  case "_macro/spawnAgent": {
221
225
  const task = params.task as string;
222
226
  if (!task) throw RequestError.invalidParams(params, "task is required");
@@ -226,6 +230,7 @@ export function createMacroAgent(
226
230
  cwd: (params.cwd as string) ?? defaultCwd,
227
231
  role: params.role as string | undefined,
228
232
  permissionMode: params.permissionMode as "auto-approve" | undefined,
233
+ askForAllTools: params.askForAllTools as boolean | undefined,
229
234
  });
230
235
  return {
231
236
  agentId: spawned.id,
@@ -837,45 +842,18 @@ export function createMacroAgent(
837
842
  }
838
843
 
839
844
  // Handle permission requests from the underlying agent.
840
- // When the agent is in interactive mode, it yields
841
- // PermissionRequestUpdate objects instead of auto-approving.
842
- // We forward these to the client via AgentSideConnection's
843
- // requestPermission() method (JSON-RPC agent→client request).
845
+ // When the agent is in interactive mode, acp-factory yields
846
+ // PermissionRequestUpdate objects. Forward them as session updates
847
+ // instead of AgentSideConnection.requestPermission(): MAP-routed
848
+ // browser clients already consume session/update, and replies come
849
+ // back through _macro/respondToPermission or _macro/cancelPermission.
844
850
  if (isPermissionRequestUpdate(update)) {
845
- try {
846
- const permResponse = await connection.requestPermission({
847
- sessionId: params.sessionId,
848
- toolCall: {
849
- toolCallId: update.toolCall.toolCallId,
850
- title: update.toolCall.title,
851
- status: update.toolCall.status as any,
852
- rawInput: update.toolCall.rawInput,
853
- },
854
- options: update.options,
855
- });
856
- // Relay the permission response back to the agent.
857
- // ACP response: { outcome: { outcome: "selected", optionId } | { outcome: "cancelled" } }
858
- const outcome = permResponse?.outcome;
859
- if (outcome) {
860
- if (outcome.outcome === "selected" && "optionId" in outcome) {
861
- agentManager.respondToPermission(
862
- agentId,
863
- update.requestId,
864
- outcome.optionId,
865
- );
866
- } else if (outcome.outcome === "cancelled") {
867
- agentManager.cancelPermission(agentId, update.requestId);
868
- }
869
- }
870
- } catch {
871
- // If the permission request fails (e.g., client disconnected),
872
- // cancel it so the agent doesn't hang.
873
- try {
874
- agentManager.cancelPermission(agentId, update.requestId);
875
- } catch {
876
- // Best effort
877
- }
878
- }
851
+ const forwardedUpdate = { ...update, _agentId: agentId };
852
+ appendSessionUpdate(params.sessionId, forwardedUpdate as any);
853
+ await connection.sessionUpdate({
854
+ sessionId: params.sessionId,
855
+ update: forwardedUpdate as any,
856
+ });
879
857
  continue;
880
858
  }
881
859
 
@@ -577,6 +577,7 @@ export function createAgentManagerV2(
577
577
  parent,
578
578
  cwd = defaultCwd,
579
579
  permissionMode = defaultPermissionMode,
580
+ askForAllTools = false,
580
581
  subscribeParent = true,
581
582
  topics = [],
582
583
  config: agentConfig,
package/src/boot-v2.ts CHANGED
@@ -592,6 +592,8 @@ export async function bootV2(
592
592
  agentManager,
593
593
  agentStore,
594
594
  getSidecar: () => (systemRef as any).mapSidecar ?? null,
595
+ getRepoManager: () => (systemRef as any).mapSidecar?.getWorkspaceManager?.() ?? null,
596
+ getRepoTransport: () => (systemRef as any).mapSidecar?.getRepoTransport?.() ?? null,
595
597
  log: (msg) => console.log(msg),
596
598
  });
597
599