macro-agent 0.1.5 → 0.1.7
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.
- package/.claude/settings.json +128 -1
- package/.sessionlog/settings.json +4 -0
- package/CLAUDE.md +125 -10
- package/README.md +93 -31
- package/dist/acp/macro-agent.d.ts.map +1 -1
- package/dist/acp/macro-agent.js +1 -3
- package/dist/acp/macro-agent.js.map +1 -1
- package/dist/boot-v2.d.ts +1 -0
- package/dist/boot-v2.d.ts.map +1 -1
- package/dist/boot-v2.js +1 -0
- package/dist/boot-v2.js.map +1 -1
- package/dist/cognitive/workspace-handler.d.ts +17 -9
- package/dist/cognitive/workspace-handler.d.ts.map +1 -1
- package/dist/cognitive/workspace-handler.js +10 -11
- package/dist/cognitive/workspace-handler.js.map +1 -1
- package/dist/map/coordination-handler.d.ts +7 -23
- package/dist/map/coordination-handler.d.ts.map +1 -1
- package/dist/map/coordination-handler.js +124 -100
- package/dist/map/coordination-handler.js.map +1 -1
- package/dist/map/server.d.ts.map +1 -1
- package/dist/map/server.js +13 -3
- package/dist/map/server.js.map +1 -1
- package/dist/map/sidecar.d.ts.map +1 -1
- package/dist/map/sidecar.js +13 -15
- package/dist/map/sidecar.js.map +1 -1
- package/dist/map/trajectory-reporter.d.ts +4 -9
- package/dist/map/trajectory-reporter.d.ts.map +1 -1
- package/dist/map/trajectory-reporter.js +15 -129
- package/dist/map/trajectory-reporter.js.map +1 -1
- package/dist/map/types.d.ts +39 -0
- package/dist/map/types.d.ts.map +1 -1
- package/package.json +2 -3
- package/src/__tests__/e2e/cognitive-workspace.e2e.test.ts +1 -1
- package/src/acp/macro-agent.ts +1 -4
- package/src/boot-v2.ts +2 -0
- package/src/cognitive/__tests__/workspace-handler.test.ts +2 -10
- package/src/cognitive/workspace-handler.ts +18 -15
- package/src/map/__tests__/trajectory-reporter.test.ts +2 -254
- package/src/map/coordination-handler.ts +137 -120
- package/src/map/server.ts +14 -2
- package/src/map/sidecar.ts +13 -20
- package/src/map/trajectory-reporter.ts +16 -154
- package/src/map/types.ts +43 -2
- package/src/__tests__/e2e/trajectory-content.e2e.test.ts +0 -708
- package/src/map/__tests__/coordination-handler.test.ts +0 -598
package/src/map/sidecar.ts
CHANGED
|
@@ -64,6 +64,12 @@ export function createMAPSidecar(
|
|
|
64
64
|
if (config.token) {
|
|
65
65
|
parsed.searchParams.set("token", config.token);
|
|
66
66
|
}
|
|
67
|
+
// Include swarm_id for stable identity across reconnections.
|
|
68
|
+
// When set, the hub reuses the pre-registered swarm record instead
|
|
69
|
+
// of auto-generating a new one on each connection.
|
|
70
|
+
if (config.swarmId) {
|
|
71
|
+
parsed.searchParams.set("swarm_id", config.swarmId);
|
|
72
|
+
}
|
|
67
73
|
return parsed.toString();
|
|
68
74
|
}
|
|
69
75
|
|
|
@@ -107,6 +113,10 @@ export function createMAPSidecar(
|
|
|
107
113
|
role: "sidecar",
|
|
108
114
|
scopes: [scope],
|
|
109
115
|
capabilities: {
|
|
116
|
+
messaging: { canSend: true, canReceive: true },
|
|
117
|
+
mail: { canCreate: true, canJoin: true, canViewHistory: true },
|
|
118
|
+
protocols: ['acp'],
|
|
119
|
+
acp: { version: '2024-10-07' },
|
|
110
120
|
trajectory: { canReport: true, canServeContent: false },
|
|
111
121
|
tasks: {
|
|
112
122
|
canCreate: true,
|
|
@@ -253,31 +263,14 @@ export function createMAPSidecar(
|
|
|
253
263
|
const { createTrajectoryReporter } = await import("./trajectory-reporter.js");
|
|
254
264
|
trajectoryReporter = createTrajectoryReporter(connection, config);
|
|
255
265
|
|
|
256
|
-
// 4.
|
|
257
|
-
const { MacroAgentBackend } = await import("../cognitive/macro-agent-backend.js");
|
|
258
|
-
const { handleWorkspaceExecute, isWorkspaceExecuteMessage } = await import("../cognitive/workspace-handler.js");
|
|
259
|
-
const workspaceBackend = new MacroAgentBackend(agentManager, {});
|
|
260
|
-
const sendToHub = (msg: { method?: string; params?: unknown }) => {
|
|
261
|
-
if (msg.method && msg.params) {
|
|
262
|
-
connection.sendNotification(msg.method, msg.params as Record<string, unknown>);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
const workspaceHandler = {
|
|
266
|
-
handleWorkspaceExecute: (params: unknown) =>
|
|
267
|
-
handleWorkspaceExecute(
|
|
268
|
-
{ backend: workspaceBackend, sendToHub },
|
|
269
|
-
params as import("agent-workspace").WorkspaceExecuteParams,
|
|
270
|
-
),
|
|
271
|
-
isWorkspaceExecuteMessage,
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
// 5. Coordination Handler
|
|
266
|
+
// 4. Coordination Handler
|
|
275
267
|
const { setupCoordinationHandlers } = await import("./coordination-handler.js");
|
|
276
268
|
coordinationCleanup = setupCoordinationHandlers({
|
|
277
269
|
connection,
|
|
270
|
+
agentManager,
|
|
278
271
|
inboxAdapter,
|
|
279
272
|
tasksAdapter,
|
|
280
|
-
|
|
273
|
+
trajectoryReporter,
|
|
281
274
|
});
|
|
282
275
|
}
|
|
283
276
|
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
* Trajectory Reporter — builds and reports trajectory checkpoints to the MAP hub.
|
|
3
3
|
*
|
|
4
4
|
* Sends checkpoints via the `trajectory/checkpoint` JSON-RPC extension.
|
|
5
|
-
*
|
|
6
|
-
* session
|
|
7
|
-
* Supports all agent types (Claude Code, Codex, Gemini, etc.) through
|
|
8
|
-
* sessionlog's adapter system.
|
|
5
|
+
* Also handles inbound `trajectory/content.request` notifications by serving
|
|
6
|
+
* session transcript data.
|
|
9
7
|
*
|
|
10
8
|
* @module map/trajectory-reporter
|
|
11
9
|
*/
|
|
@@ -36,173 +34,37 @@ export interface TrajectoryConnection {
|
|
|
36
34
|
get isConnected(): boolean;
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
/**
|
|
40
|
-
* Resolve transcript content for a checkpoint ID using sessionlog.
|
|
41
|
-
*
|
|
42
|
-
* Two-source strategy (matching cc-swarm):
|
|
43
|
-
* 1. Live session — use sessionlog's SessionStore to find a session
|
|
44
|
-
* matching the checkpoint ID, then read its transcript from disk.
|
|
45
|
-
* 2. Committed checkpoint — use sessionlog's CheckpointStore to read
|
|
46
|
-
* content from the git history.
|
|
47
|
-
*
|
|
48
|
-
* Returns null if no content is found or sessionlog is unavailable.
|
|
49
|
-
*/
|
|
50
|
-
async function resolveContent(
|
|
51
|
-
checkpointId: string,
|
|
52
|
-
sessionDirs: string[],
|
|
53
|
-
): Promise<{
|
|
54
|
-
transcript: string;
|
|
55
|
-
metadata: Record<string, unknown>;
|
|
56
|
-
prompts: string;
|
|
57
|
-
context: string;
|
|
58
|
-
} | null> {
|
|
59
|
-
let sessionlog: typeof import("sessionlog") | null = null;
|
|
60
|
-
try {
|
|
61
|
-
sessionlog = await import("sessionlog");
|
|
62
|
-
} catch {
|
|
63
|
-
return null; // sessionlog not available
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const { readFileSync, existsSync } = await import("node:fs");
|
|
67
|
-
|
|
68
|
-
// Derive the session ID from checkpoint ID (e.g., "sess-abc-step3" → "sess-abc")
|
|
69
|
-
const sessionId = checkpointId.replace(/-step\d+$/, "");
|
|
70
|
-
|
|
71
|
-
// ── 1. Live session lookup via SessionStore ────────────────────────────
|
|
72
|
-
for (const sessionsDir of sessionDirs) {
|
|
73
|
-
if (!existsSync(sessionsDir)) continue;
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const store = sessionlog.createSessionStore(undefined, sessionsDir);
|
|
77
|
-
// Try loading by derived session ID first, then by raw checkpoint ID
|
|
78
|
-
let state = await store.load(sessionId);
|
|
79
|
-
if (!state) state = await store.load(checkpointId);
|
|
80
|
-
|
|
81
|
-
// If not found by ID, scan all sessions for checkpoint match
|
|
82
|
-
if (!state) {
|
|
83
|
-
const allSessions = await store.list();
|
|
84
|
-
state = allSessions.find((s) =>
|
|
85
|
-
s.lastCheckpointID === checkpointId ||
|
|
86
|
-
(s.turnCheckpointIDs || []).includes(checkpointId),
|
|
87
|
-
) ?? null;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (!state?.transcriptPath || !existsSync(state.transcriptPath)) continue;
|
|
91
|
-
|
|
92
|
-
const transcript = readFileSync(state.transcriptPath, "utf-8");
|
|
93
|
-
|
|
94
|
-
// Use sessionlog's prompt extraction if the agent has a TranscriptAnalyzer,
|
|
95
|
-
// otherwise fall back to the prompts stored in state
|
|
96
|
-
let prompts = "";
|
|
97
|
-
if (state.firstPrompt) {
|
|
98
|
-
// Collect from promptAttributions if available, otherwise use firstPrompt
|
|
99
|
-
const attrs = state.promptAttributions;
|
|
100
|
-
if (attrs && attrs.length > 0) {
|
|
101
|
-
prompts = attrs.map((a) => a.prompt).join("\n---\n");
|
|
102
|
-
} else {
|
|
103
|
-
prompts = state.firstPrompt;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return {
|
|
108
|
-
transcript,
|
|
109
|
-
prompts,
|
|
110
|
-
metadata: {
|
|
111
|
-
sessionID: state.sessionID,
|
|
112
|
-
phase: state.phase,
|
|
113
|
-
agentType: state.agentType,
|
|
114
|
-
stepCount: state.stepCount || 0,
|
|
115
|
-
filesTouched: state.filesTouched || [],
|
|
116
|
-
tokenUsage: state.tokenUsage || {},
|
|
117
|
-
startedAt: state.startedAt,
|
|
118
|
-
endedAt: state.endedAt,
|
|
119
|
-
source: "live",
|
|
120
|
-
},
|
|
121
|
-
context: `Session ${state.sessionID} (${state.phase})`,
|
|
122
|
-
};
|
|
123
|
-
} catch {
|
|
124
|
-
continue;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// ── 2. Committed checkpoint via CheckpointStore ────────────────────────
|
|
129
|
-
try {
|
|
130
|
-
if (sessionlog.createCheckpointStore) {
|
|
131
|
-
const store = sessionlog.createCheckpointStore();
|
|
132
|
-
const content = await store.readSessionContent(checkpointId, 0);
|
|
133
|
-
if (content) {
|
|
134
|
-
return {
|
|
135
|
-
transcript: content.transcript,
|
|
136
|
-
prompts: content.prompts,
|
|
137
|
-
metadata: { ...content.metadata, source: "committed" },
|
|
138
|
-
context: content.context,
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
} catch {
|
|
143
|
-
// Checkpoint not found or store unavailable
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
37
|
/**
|
|
150
38
|
* Create a trajectory reporter that sends checkpoints to the MAP hub
|
|
151
|
-
* and serves
|
|
39
|
+
* and serves content on demand.
|
|
152
40
|
*/
|
|
153
41
|
export function createTrajectoryReporter(
|
|
154
42
|
connection: TrajectoryConnection,
|
|
155
|
-
config: Pick<MAPSidecarConfig, "trajectorySyncLevel"
|
|
156
|
-
/** Additional session directories to search for transcripts */
|
|
157
|
-
sessionDirs?: string[];
|
|
158
|
-
},
|
|
43
|
+
config: Pick<MAPSidecarConfig, "trajectorySyncLevel">,
|
|
159
44
|
): TrajectoryReporter {
|
|
160
45
|
// Cache the resource_id from the first checkpoint response
|
|
161
46
|
// so subsequent calls reuse it (avoids creating duplicate session resources)
|
|
162
47
|
let cachedResourceId: string | undefined;
|
|
163
48
|
|
|
164
|
-
// Build session directory search list
|
|
165
|
-
const defaultDirs: string[] = [];
|
|
166
|
-
try {
|
|
167
|
-
const cwd = process.cwd();
|
|
168
|
-
defaultDirs.push(
|
|
169
|
-
`${cwd}/.git/sessionlog-sessions`,
|
|
170
|
-
`${cwd}/.swarm/sessionlog/sessions`,
|
|
171
|
-
);
|
|
172
|
-
} catch {
|
|
173
|
-
// Can't resolve paths — will use config dirs only
|
|
174
|
-
}
|
|
175
|
-
const sessionDirs = [...(config.sessionDirs ?? []), ...defaultDirs];
|
|
176
|
-
|
|
177
49
|
// Handler for inbound content requests
|
|
178
50
|
const contentHandler = async (params: unknown): Promise<void> => {
|
|
179
51
|
const req = params as TrajectoryContentRequest;
|
|
180
52
|
if (!req?.request_id) return;
|
|
181
53
|
|
|
182
54
|
try {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
context: content.context,
|
|
195
|
-
});
|
|
196
|
-
} else {
|
|
197
|
-
await connection.sendNotification("trajectory/content.response", {
|
|
198
|
-
request_id: req.request_id,
|
|
199
|
-
transcript: "",
|
|
200
|
-
metadata: { source: "macro-agent" },
|
|
201
|
-
prompts: "",
|
|
202
|
-
context: "",
|
|
203
|
-
});
|
|
204
|
-
}
|
|
55
|
+
// Respond with what we have — macro-agent doesn't store full transcripts
|
|
56
|
+
// like sessionlog does, so we send a minimal response.
|
|
57
|
+
// Future: integrate with ACP session history for richer content.
|
|
58
|
+
await connection.sendNotification("trajectory/content.response", {
|
|
59
|
+
request_id: req.request_id,
|
|
60
|
+
transcript: null,
|
|
61
|
+
metadata: {
|
|
62
|
+
source: "macro-agent",
|
|
63
|
+
note: "Full transcript serving not yet implemented",
|
|
64
|
+
},
|
|
65
|
+
});
|
|
205
66
|
} catch {
|
|
67
|
+
// Best effort
|
|
206
68
|
try {
|
|
207
69
|
await connection.sendNotification("trajectory/content.response", {
|
|
208
70
|
request_id: req.request_id,
|
package/src/map/types.ts
CHANGED
|
@@ -35,6 +35,9 @@ export interface MAPSidecarConfig {
|
|
|
35
35
|
/** Agent name for MAP registration (default: "macro-agent-sidecar") */
|
|
36
36
|
agentName?: string;
|
|
37
37
|
|
|
38
|
+
/** Swarm ID for stable identity across reconnections */
|
|
39
|
+
swarmId?: string;
|
|
40
|
+
|
|
38
41
|
/** Trajectory sync level */
|
|
39
42
|
trajectorySyncLevel?: "off" | "lifecycle" | "metrics" | "full";
|
|
40
43
|
|
|
@@ -145,8 +148,46 @@ export interface TrajectoryContentRequest {
|
|
|
145
148
|
// Coordination Wire Format
|
|
146
149
|
// =============================================================================
|
|
147
150
|
|
|
148
|
-
|
|
149
|
-
|
|
151
|
+
/** Inbound task assignment from hub */
|
|
152
|
+
export interface CoordinationTaskAssign {
|
|
153
|
+
title: string;
|
|
154
|
+
description?: string;
|
|
155
|
+
assigned_to?: string;
|
|
156
|
+
assigned_by: string;
|
|
157
|
+
priority?: string;
|
|
158
|
+
context?: Record<string, unknown>;
|
|
159
|
+
deadline?: string;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Inbound task status update from hub */
|
|
163
|
+
export interface CoordinationTaskStatus {
|
|
164
|
+
task_id: string;
|
|
165
|
+
status: string;
|
|
166
|
+
progress?: number;
|
|
167
|
+
result?: unknown;
|
|
168
|
+
error?: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** Inbound context share from hub */
|
|
172
|
+
export interface CoordinationContextShare {
|
|
173
|
+
hive_id?: string;
|
|
174
|
+
source_swarm_id: string;
|
|
175
|
+
context_type: string;
|
|
176
|
+
data: unknown;
|
|
177
|
+
target_swarm_ids?: string[];
|
|
178
|
+
ttl_seconds?: number;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Inbound message from hub */
|
|
182
|
+
export interface CoordinationMessage {
|
|
183
|
+
hive_id?: string;
|
|
184
|
+
from_swarm_id: string;
|
|
185
|
+
to_swarm_id: string;
|
|
186
|
+
content_type: string;
|
|
187
|
+
content: unknown;
|
|
188
|
+
reply_to?: string;
|
|
189
|
+
metadata?: Record<string, unknown>;
|
|
190
|
+
}
|
|
150
191
|
|
|
151
192
|
// =============================================================================
|
|
152
193
|
// Internal Bridge Types
|