macro-agent 0.0.15 → 0.0.17

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 (44) hide show
  1. package/dist/acp/index.d.ts +1 -1
  2. package/dist/acp/index.d.ts.map +1 -1
  3. package/dist/acp/index.js.map +1 -1
  4. package/dist/acp/macro-agent.d.ts +21 -0
  5. package/dist/acp/macro-agent.d.ts.map +1 -1
  6. package/dist/acp/macro-agent.js +182 -0
  7. package/dist/acp/macro-agent.js.map +1 -1
  8. package/dist/acp/types.d.ts +31 -2
  9. package/dist/acp/types.d.ts.map +1 -1
  10. package/dist/acp/types.js.map +1 -1
  11. package/dist/agent/agent-manager.d.ts.map +1 -1
  12. package/dist/agent/agent-manager.js +23 -5
  13. package/dist/agent/agent-manager.js.map +1 -1
  14. package/dist/map/adapter/acp-over-map.d.ts +15 -0
  15. package/dist/map/adapter/acp-over-map.d.ts.map +1 -1
  16. package/dist/map/adapter/acp-over-map.js +204 -9
  17. package/dist/map/adapter/acp-over-map.js.map +1 -1
  18. package/dist/store/event-store.d.ts.map +1 -1
  19. package/dist/store/event-store.js +92 -53
  20. package/dist/store/event-store.js.map +1 -1
  21. package/dist/store/instance.d.ts +0 -2
  22. package/dist/store/instance.d.ts.map +1 -1
  23. package/dist/store/instance.js +1 -24
  24. package/dist/store/instance.js.map +1 -1
  25. package/package.json +3 -3
  26. package/references/acp-factory-ref/package-lock.json +2 -2
  27. package/references/acp-factory-ref/package.json +2 -2
  28. package/references/claude-code-acp/package-lock.json +2 -2
  29. package/references/claude-code-acp/package.json +1 -1
  30. package/references/claude-code-acp/src/acp-agent.ts +3 -6
  31. package/src/acp/__tests__/history.test.ts +526 -0
  32. package/src/acp/__tests__/integration.test.ts +2 -1
  33. package/src/acp/index.ts +4 -0
  34. package/src/acp/macro-agent.ts +329 -85
  35. package/src/acp/types.ts +39 -2
  36. package/src/agent/__tests__/agent-manager.test.ts +4 -6
  37. package/src/agent/agent-manager.ts +24 -5
  38. package/src/map/adapter/__tests__/acp-over-map-history.test.ts +664 -0
  39. package/src/map/adapter/__tests__/acp-over-map-persistence.e2e.test.ts +440 -0
  40. package/src/map/adapter/acp-over-map.ts +246 -7
  41. package/src/store/__tests__/event-store.test.ts +4 -12
  42. package/src/store/__tests__/instance.test.ts +5 -7
  43. package/src/store/event-store.ts +115 -57
  44. package/src/store/instance.ts +1 -29
package/src/acp/types.ts CHANGED
@@ -630,10 +630,44 @@ export interface ResumeAgentResponse {
630
630
  /** The resumed agent's ID */
631
631
  agentId: AgentId;
632
632
 
633
- /** The agent's session ID */
633
+ /** The agent's session ID (from resume) */
634
634
  sessionId: string;
635
635
  }
636
636
 
637
+ // ─────────────────────────────────────────────────────────────────
638
+ // History Extension Types
639
+ // ─────────────────────────────────────────────────────────────────
640
+
641
+ /**
642
+ * A historical turn in a session conversation
643
+ */
644
+ export interface HistoryTurn {
645
+ /** Turn role */
646
+ role: "user" | "assistant";
647
+ /** Timestamp of the turn */
648
+ timestamp: number;
649
+ /** Turn content — plain text for user, structured parts for assistant */
650
+ content: unknown;
651
+ }
652
+
653
+ /**
654
+ * Request for _macro/getHistory extension
655
+ */
656
+ export interface GetHistoryRequest {
657
+ /** ACP session ID to get history for */
658
+ sessionId: string;
659
+ /** Maximum number of turns to return */
660
+ limit?: number;
661
+ }
662
+
663
+ /**
664
+ * Response for _macro/getHistory extension
665
+ */
666
+ export interface GetHistoryResponse {
667
+ /** Conversation turns in chronological order */
668
+ turns: HistoryTurn[];
669
+ }
670
+
637
671
  // ─────────────────────────────────────────────────────────────────
638
672
  // Extension Method Types (Union)
639
673
  // ─────────────────────────────────────────────────────────────────
@@ -657,7 +691,8 @@ export type ACPExtensionMethod =
657
691
  | "_macro/checkCapability"
658
692
  | "_macro/respondToPermission"
659
693
  | "_macro/cancelPermission"
660
- | "_macro/resume";
694
+ | "_macro/resume"
695
+ | "_macro/getHistory";
661
696
 
662
697
  /**
663
698
  * Map of extension methods to their request types
@@ -679,6 +714,7 @@ export interface ACPExtensionRequests {
679
714
  "_macro/respondToPermission": RespondToPermissionRequest;
680
715
  "_macro/cancelPermission": CancelPermissionRequest;
681
716
  "_macro/resume": ResumeAgentRequest;
717
+ "_macro/getHistory": GetHistoryRequest;
682
718
  }
683
719
 
684
720
  /**
@@ -701,6 +737,7 @@ export interface ACPExtensionResponses {
701
737
  "_macro/respondToPermission": RespondToPermissionResponse;
702
738
  "_macro/cancelPermission": CancelPermissionResponse;
703
739
  "_macro/resume": ResumeAgentResponse;
740
+ "_macro/getHistory": GetHistoryResponse;
704
741
  }
705
742
 
706
743
  // ─────────────────────────────────────────────────────────────────
@@ -720,7 +720,7 @@ describe("AgentManager Integration (with mocked acp-factory)", () => {
720
720
  );
721
721
  });
722
722
 
723
- it("should fall back to session_id if provider_session_id is not set", async () => {
723
+ it("should create new session if provider_session_id is not set", async () => {
724
724
  // Create agent directly without provider_session_id
725
725
  const agentId = "agent_no_provider";
726
726
  const sessionId = "session_no_provider";
@@ -744,11 +744,9 @@ describe("AgentManager Integration (with mocked acp-factory)", () => {
744
744
 
745
745
  await agentManager.resume(agentId);
746
746
 
747
- // Should fall back to the macro-agent session_id
748
- expect(mockHandle.loadSession).toHaveBeenCalledWith(
749
- sessionId,
750
- "/tmp",
751
- );
747
+ // Should create a new session instead of loading with invalid macro-agent session_id
748
+ expect(mockHandle.createSession).toHaveBeenCalledWith("/tmp");
749
+ expect(mockHandle.loadSession).not.toHaveBeenCalled();
752
750
  });
753
751
  });
754
752
 
@@ -901,16 +901,34 @@ export function createAgentManager(
901
901
  );
902
902
  }
903
903
 
904
- // Spawn new process and load existing session
904
+ // Spawn new process
905
905
  const handle = await AgentFactory.spawn(defaultAgentType, {
906
906
  permissionMode: defaultPermissionMode,
907
907
  });
908
908
 
909
- // Load the existing session using the provider's session ID (e.g., Claude Code UUID)
910
- // Falls back to macro-agent session_id for backwards compatibility
911
- const loadSessionId = agent.provider_session_id ?? agent.session_id;
912
909
  const agentCwd = agent.cwd ?? defaultCwd;
913
- const session = await handle.loadSession(loadSessionId, agentCwd);
910
+ let session;
911
+
912
+ if (agent.provider_session_id) {
913
+ // Load existing session using the provider's session ID (e.g., Claude Code UUID)
914
+ session = await handle.loadSession(agent.provider_session_id, agentCwd);
915
+ } else {
916
+ // No provider session ID available (agent predates this feature or wasn't persisted).
917
+ // Create a new session instead of loading with the macro-agent session_id
918
+ // which is not a valid provider session ID (e.g., Claude Code expects UUIDs).
919
+ session = await handle.createSession(agentCwd);
920
+
921
+ // Store the provider session ID for future resumes
922
+ eventStore.emit({
923
+ type: "status",
924
+ source: { agent_id: agentId },
925
+ payload: {
926
+ status_type: "started",
927
+ summary: "Agent session created (no provider session to resume)",
928
+ provider_session_id: session.id,
929
+ },
930
+ });
931
+ }
914
932
 
915
933
  // Track active session
916
934
  const activeSession: ActiveSession = {
@@ -929,6 +947,7 @@ export function createAgentManager(
929
947
  payload: {
930
948
  status_type: "started",
931
949
  summary: "Agent session resumed",
950
+ provider_session_id: session.id,
932
951
  },
933
952
  });
934
953