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
@@ -23,6 +23,13 @@ import type {
23
23
  TaskBridge,
24
24
  } from "./types.js";
25
25
  import type { AgentLifecycleCallback } from "../agent/types.js";
26
+ import {
27
+ REPO_PROTOCOL_VERSION,
28
+ RepoClient,
29
+ RepoManager,
30
+ type RepoClientTransport,
31
+ type WorkspaceCapability,
32
+ } from "./repo-workspace.js";
26
33
 
27
34
  /**
28
35
  * Create a MAP sidecar that connects macro-agent to an OpenHive MAP hub.
@@ -55,8 +62,25 @@ export function createMAPSidecar(
55
62
  let dispatchSpawnHandlerCleanup: (() => void) | null = null;
56
63
  let dispatchMessageHandlerCleanup: (() => void) | null = null;
57
64
  let dispatchPermissionsHandlerCleanup: (() => void) | null = null;
65
+ let workspaceManager: RepoManager | null = null;
66
+ let workspaceTransport: RepoClientTransport | null = null;
58
67
  let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
59
68
 
69
+ // Resolve the workspace capability from env vars. Setting OPENHIVE_WORKSPACE_DECLARE=off
70
+ // disables both explicit declare AND trajectory-handler bootstrap on the hub side.
71
+ const workspaceCapability: WorkspaceCapability = {
72
+ protocolVersion: REPO_PROTOCOL_VERSION,
73
+ declare: {
74
+ enabled: process.env.OPENHIVE_WORKSPACE_DECLARE !== "off",
75
+ defaultVisibility:
76
+ (process.env.OPENHIVE_WORKSPACE_VISIBILITY as
77
+ | "private"
78
+ | "hub_local"
79
+ | "federated") ?? "hub_local",
80
+ },
81
+ list: { enabled: true },
82
+ };
83
+
60
84
  /**
61
85
  * Build the MAP connection URL with auth token.
62
86
  */
@@ -121,6 +145,8 @@ export function createMAPSidecar(
121
145
  }
122
146
  lifecycleCallback = null;
123
147
  taskBridge = null;
148
+ workspaceManager = null;
149
+ workspaceTransport = null;
124
150
  }
125
151
 
126
152
  /**
@@ -147,6 +173,7 @@ export function createMAPSidecar(
147
173
  canUpdate: true,
148
174
  canList: true,
149
175
  },
176
+ workspace: workspaceCapability,
150
177
  },
151
178
  metadata: {
152
179
  systemId: config.systemId ?? "macro-agent",
@@ -624,6 +651,56 @@ export function createMAPSidecar(
624
651
  actionCleanup();
625
652
  };
626
653
  }
654
+
655
+ // 6. Workspace (kinds/repo) — declare attached repos to the hub.
656
+ // Discovers repos from WORKSPACE_* env vars (set by openhive's swarm-spawn
657
+ // flow when spawning with a `repo_id`) plus OPENHIVE_WORKSPACE_REPOS for
658
+ // multi-repo declarations. Skipped entirely when capability.declare is off.
659
+ if (workspaceCapability.declare.enabled) {
660
+ try {
661
+ // OpenHive's MAP server registers x-workspace/repo.* as request handlers
662
+ // (additionalHandlers), not notification handlers — so route notify
663
+ // through callExtension and ignore the (void) response.
664
+ const repoTransport: RepoClientTransport = {
665
+ notify: async (method: string, params: unknown) => {
666
+ await connection.callExtension(method, params);
667
+ },
668
+ request: (method: string, params: unknown) =>
669
+ connection.callExtension(method, params),
670
+ };
671
+ const manager = new RepoManager();
672
+ const single =
673
+ process.env.WORKSPACE_REPO_URL && process.env.WORKSPACE_LOCAL_PATH
674
+ ? [{
675
+ remoteUrl: process.env.WORKSPACE_REPO_URL,
676
+ localPath: process.env.WORKSPACE_LOCAL_PATH,
677
+ }]
678
+ : [];
679
+ const multi = process.env.OPENHIVE_WORKSPACE_REPOS
680
+ ? (JSON.parse(process.env.OPENHIVE_WORKSPACE_REPOS) as Array<{
681
+ remoteUrl: string;
682
+ localPath: string;
683
+ }>)
684
+ : [];
685
+ for (const cfg of [...single, ...multi]) {
686
+ await manager.attach(cfg);
687
+ }
688
+ if (manager.list().length > 0) {
689
+ const client = new RepoClient(repoTransport);
690
+ await client.declare(RepoClient.snapshot(manager));
691
+ workspaceManager = manager;
692
+ workspaceTransport = repoTransport;
693
+ console.log(
694
+ `[map-sidecar] Declared ${manager.list().length} workspace(s) to hub`,
695
+ );
696
+ }
697
+ } catch (err) {
698
+ // Non-fatal — sidecar continues without workspace declarations
699
+ console.warn(
700
+ `[map-sidecar] Workspace declare failed: ${(err as Error).message}`,
701
+ );
702
+ }
703
+ }
627
704
  }
628
705
 
629
706
  return {
@@ -708,5 +785,13 @@ export function createMAPSidecar(
708
785
  );
709
786
  }
710
787
  },
788
+
789
+ getWorkspaceManager() {
790
+ return workspaceManager;
791
+ },
792
+
793
+ getRepoTransport() {
794
+ return workspaceTransport;
795
+ },
711
796
  };
712
797
  }
package/src/map/types.ts CHANGED
@@ -127,6 +127,19 @@ export interface MAPSidecar {
127
127
  participantId: string,
128
128
  content: string,
129
129
  ): Promise<void>;
130
+
131
+ /**
132
+ * Access the sidecar's workspace RepoManager (if workspace declarations
133
+ * are enabled and the sidecar is connected). Used by mail-inbound-consumer
134
+ * for pre-spawn repo mount.
135
+ */
136
+ getWorkspaceManager?(): unknown;
137
+
138
+ /**
139
+ * Access the sidecar's repo client transport for declaring newly-attached
140
+ * repos to the hub. Used by mail-inbound-consumer after pre-spawn clone.
141
+ */
142
+ getRepoTransport?(): { notify(method: string, params: unknown): Promise<void>; request(method: string, params: unknown): Promise<unknown> } | null;
130
143
  }
131
144
 
132
145
  // =============================================================================