@ai-devkit/agent-manager 0.42.0 → 0.42.2

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 (53) hide show
  1. package/README.md +1 -1
  2. package/dist/AgentManager.d.ts +5 -3
  3. package/dist/AgentManager.d.ts.map +1 -1
  4. package/dist/AgentManager.js +12 -2
  5. package/dist/AgentManager.js.map +1 -1
  6. package/dist/__tests__/AgentManager.test.js +29 -4
  7. package/dist/__tests__/AgentManager.test.js.map +1 -1
  8. package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js +9 -1
  9. package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js.map +1 -1
  10. package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js +12 -1
  11. package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js.map +1 -1
  12. package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js +20 -1
  13. package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js.map +1 -1
  14. package/dist/__tests__/runtime/ManagedAgentRuntime.test.js +12 -12
  15. package/dist/__tests__/runtime/ManagedAgentRuntime.test.js.map +1 -1
  16. package/dist/harnesses/antigravity/AntigravitySessionParser.d.ts +1 -1
  17. package/dist/harnesses/antigravity/AntigravitySessionParser.js +4 -4
  18. package/dist/harnesses/antigravity/AntigravitySessionParser.js.map +1 -1
  19. package/dist/harnesses/codex/CodexSessionParser.js +3 -3
  20. package/dist/harnesses/codex/CodexSessionParser.js.map +1 -1
  21. package/dist/harnesses/copilot/CopilotSessionParser.js +3 -3
  22. package/dist/harnesses/copilot/CopilotSessionParser.js.map +1 -1
  23. package/dist/harnesses/devin/DevinAgentMapper.js +2 -2
  24. package/dist/harnesses/devin/DevinAgentMapper.js.map +1 -1
  25. package/dist/harnesses/gemini/GeminiSessionParser.js +3 -3
  26. package/dist/harnesses/gemini/GeminiSessionParser.js.map +1 -1
  27. package/dist/harnesses/grok/GrokSessionParser.d.ts +1 -1
  28. package/dist/harnesses/grok/GrokSessionParser.js +4 -4
  29. package/dist/harnesses/grok/GrokSessionParser.js.map +1 -1
  30. package/dist/harnesses/kiro/KiroSessionParser.d.ts +1 -1
  31. package/dist/harnesses/kiro/KiroSessionParser.js +2 -2
  32. package/dist/harnesses/kiro/KiroSessionParser.js.map +1 -1
  33. package/dist/harnesses/opencode/OpenCodeAgentMapper.d.ts.map +1 -1
  34. package/dist/harnesses/opencode/OpenCodeAgentMapper.js +3 -4
  35. package/dist/harnesses/opencode/OpenCodeAgentMapper.js.map +1 -1
  36. package/dist/harnesses/pi/PiSessionParser.js +1 -1
  37. package/dist/harnesses/pi/PiSessionParser.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/AgentManager.ts +21 -5
  40. package/src/__tests__/AgentManager.test.ts +29 -4
  41. package/src/__tests__/harnesses/devin/DevinAgentMapper.test.ts +14 -1
  42. package/src/__tests__/harnesses/gemini/GeminiCliAdapter.test.ts +13 -1
  43. package/src/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.ts +19 -1
  44. package/src/__tests__/runtime/ManagedAgentRuntime.test.ts +11 -6
  45. package/src/harnesses/antigravity/AntigravitySessionParser.ts +4 -4
  46. package/src/harnesses/codex/CodexSessionParser.ts +4 -4
  47. package/src/harnesses/copilot/CopilotSessionParser.ts +4 -4
  48. package/src/harnesses/devin/DevinAgentMapper.ts +2 -2
  49. package/src/harnesses/gemini/GeminiSessionParser.ts +4 -4
  50. package/src/harnesses/grok/GrokSessionParser.ts +4 -4
  51. package/src/harnesses/kiro/KiroSessionParser.ts +2 -2
  52. package/src/harnesses/opencode/OpenCodeAgentMapper.ts +3 -5
  53. package/src/harnesses/pi/PiSessionParser.ts +1 -1
@@ -61,10 +61,12 @@ export interface AgentManagerOptions {
61
61
  onRuntimeDiscoveryError?: (error: unknown) => void;
62
62
  /**
63
63
  * Daemon-side enriched agents ({@link DaemonClient.listAgents} wire
64
- * shape: `AgentInfo` with `lastActive` as an ISO string). A non-null
64
+ * shape: `AgentInfo` with `lastActive` as an ISO string). A non-empty
65
65
  * result is authoritative for every harness type — all local adapters
66
- * are skipped. Returning null or throwing forces the local path;
67
- * omitting it disables daemon consumption.
66
+ * are skipped. An empty result is cross-checked against local detection
67
+ * (local wins on disagreement, with a warning). Returning null or
68
+ * throwing forces the local path; omitting it disables daemon
69
+ * consumption.
68
70
  */
69
71
  fetchEnrichedAgents?: () => Promise<Array<
70
72
  Omit<AgentInfo, "lastActive" | "type" | "status"> & {
@@ -190,9 +192,14 @@ export class AgentManager {
190
192
  const allAgents: AgentInfo[] = [];
191
193
  const errors: Array<{ type: string; error: Error }> = [];
192
194
 
193
- // A non-null daemon answer is authoritative for every harness type, so
194
- // local adapters only run when the daemon is absent.
195
+ // A non-empty daemon answer is authoritative for every harness type, so
196
+ // local adapters only run when the daemon is absent — or when it
197
+ // returns an empty list. An empty answer must not be authoritative
198
+ // (issue #371): a daemon-side discovery bug would otherwise mask every
199
+ // running agent forever. When local adapters disagree with the empty
200
+ // answer the local result wins, with a warning.
195
201
  let daemonAgents: AgentInfo[] | null = null;
202
+ let daemonAnsweredEmpty = false;
196
203
  if (this.options.fetchEnrichedAgents) {
197
204
  try {
198
205
  const enriched = await this.options.fetchEnrichedAgents();
@@ -203,6 +210,8 @@ export class AgentManager {
203
210
  status: a.status as AgentStatus,
204
211
  lastActive: new Date(a.lastActive),
205
212
  }));
213
+ daemonAnsweredEmpty = daemonAgents.length === 0;
214
+ if (daemonAnsweredEmpty) daemonAgents = null;
206
215
  }
207
216
  } catch {
208
217
  daemonAgents = null;
@@ -264,6 +273,13 @@ export class AgentManager {
264
273
  }
265
274
  }
266
275
 
276
+ if (daemonAnsweredEmpty && allAgents.length > 0) {
277
+ console.error(
278
+ `Warning: devkitd reported no agents but local detection found ${allAgents.length} — ` +
279
+ "the daemon's process sweep may be broken; showing local results.",
280
+ );
281
+ }
282
+
267
283
  // Log errors if any (but don't throw - partial results are useful)
268
284
  if (errors.length > 0) {
269
285
  console.error(`Warning: ${errors.length} adapter(s) failed:`);
@@ -548,17 +548,42 @@ describe("AgentManager", () => {
548
548
  expect(agents.map((a) => a.name).sort()).toEqual(["daemon-claude", "daemon-codex"]);
549
549
  });
550
550
 
551
- it("treats an empty daemon answer as authoritative", async () => {
551
+ it("falls back to local adapters when the daemon returns an empty list and local finds agents", async () => {
552
552
  const local = new MockAdapter("claude", [createMockAgent({ name: "local-claude" })]);
553
553
  const detectSpy = vi.spyOn(local, "detectAgents");
554
+ const warnSpy = vi.spyOn(console, "error").mockImplementation(() => {});
554
555
  const m = new AgentManager(new AgentRegistry(path.join(tmpDir, "agents.json")), undefined, {
555
556
  fetchEnrichedAgents: async () => [],
556
557
  });
557
558
  m.registerAdapter(local);
558
559
 
559
- const agents = await m.listAgents();
560
- expect(detectSpy).not.toHaveBeenCalled();
561
- expect(agents).toEqual([]);
560
+ try {
561
+ const agents = await m.listAgents();
562
+ expect(detectSpy).toHaveBeenCalled();
563
+ expect(agents.map((a) => a.name)).toEqual(["local-claude"]);
564
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining("daemon"));
565
+ } finally {
566
+ warnSpy.mockRestore();
567
+ }
568
+ });
569
+
570
+ it("returns empty without a warning when the daemon and local adapters are both empty", async () => {
571
+ const local = new MockAdapter("claude");
572
+ const detectSpy = vi.spyOn(local, "detectAgents");
573
+ const warnSpy = vi.spyOn(console, "error").mockImplementation(() => {});
574
+ const m = new AgentManager(new AgentRegistry(path.join(tmpDir, "agents.json")), undefined, {
575
+ fetchEnrichedAgents: async () => [],
576
+ });
577
+ m.registerAdapter(local);
578
+
579
+ try {
580
+ const agents = await m.listAgents();
581
+ expect(detectSpy).toHaveBeenCalled();
582
+ expect(agents).toEqual([]);
583
+ expect(warnSpy).not.toHaveBeenCalled();
584
+ } finally {
585
+ warnSpy.mockRestore();
586
+ }
562
587
  });
563
588
  });
564
589
 
@@ -56,7 +56,7 @@ describe("DevinAgentMapper", () => {
56
56
  const agent = mapper.mapSessionToAgent(
57
57
  session(),
58
58
  {
59
- lastRole: "assistant",
59
+ lastRole: "user",
60
60
  lastTimeUpdated: Date.now() - 10 * 60 * 1000,
61
61
  summary: "",
62
62
  },
@@ -65,6 +65,19 @@ describe("DevinAgentMapper", () => {
65
65
  expect(agent.status).toBe(AgentStatus.IDLE);
66
66
  });
67
67
 
68
+ it("keeps stale sessions awaiting input waiting", () => {
69
+ const agent = mapper.mapSessionToAgent(
70
+ session(),
71
+ {
72
+ lastRole: "assistant",
73
+ lastTimeUpdated: Date.now() - 10 * 60 * 1000,
74
+ summary: "",
75
+ },
76
+ proc(),
77
+ );
78
+ expect(agent.status).toBe(AgentStatus.WAITING);
79
+ });
80
+
68
81
  it("falls back to session title then directory for summary and project path", () => {
69
82
  const agent = mapper.mapSessionToAgent(
70
83
  session({ title: "Hello Greeting Session" }),
@@ -823,10 +823,22 @@ describe("GeminiCliAdapter", () => {
823
823
  summary: "",
824
824
  sessionStart: new Date(),
825
825
  lastActive: new Date(Date.now() - 10 * 60 * 1000),
826
- lastMessageType: "gemini",
826
+ lastMessageType: "user",
827
827
  };
828
828
  expect(parser.determineStatus(session)).toBe(AgentStatus.IDLE);
829
829
  });
830
+
831
+ it('should stay "waiting" past the idle threshold when awaiting input', () => {
832
+ const session = {
833
+ sessionId: "s",
834
+ projectPath: "",
835
+ summary: "",
836
+ sessionStart: new Date(),
837
+ lastActive: new Date(Date.now() - 10 * 60 * 1000),
838
+ lastMessageType: "gemini",
839
+ };
840
+ expect(parser.determineStatus(session)).toBe(AgentStatus.WAITING);
841
+ });
830
842
  });
831
843
 
832
844
  describe("parseSession", () => {
@@ -58,7 +58,7 @@ describe("OpenCodeAgentMapper", () => {
58
58
  {
59
59
  lastRole: "assistant",
60
60
  lastTimeUpdated: staleTime,
61
- lastAssistantCompleted: true,
61
+ lastAssistantCompleted: false,
62
62
  lastAssistantErrored: false,
63
63
  summary: "",
64
64
  },
@@ -68,6 +68,24 @@ describe("OpenCodeAgentMapper", () => {
68
68
  expect(agent.status).toBe(AgentStatus.IDLE);
69
69
  });
70
70
 
71
+ it("keeps stale sessions awaiting input waiting", () => {
72
+ const staleTime = Date.now() - 10 * 60 * 1000;
73
+
74
+ const agent = mapper.mapSessionToAgent(
75
+ { sessionId: "sess-4", directory: "/old", timeCreated: staleTime },
76
+ {
77
+ lastRole: "assistant",
78
+ lastTimeUpdated: staleTime,
79
+ lastAssistantCompleted: true,
80
+ lastAssistantErrored: false,
81
+ summary: "",
82
+ },
83
+ { pid: 126, command: "opencode", cwd: "/old" },
84
+ );
85
+
86
+ expect(agent.status).toBe(AgentStatus.WAITING);
87
+ });
88
+
71
89
  it("maps unmatched processes as running process-only agents", () => {
72
90
  const agent = mapper.mapProcessOnlyAgent({ pid: 500, command: "opencode", cwd: "/repo" });
73
91
 
@@ -78,7 +78,10 @@ const startOpts: StartAgentOptions = {
78
78
  name: "agent1",
79
79
  cwd: "/work",
80
80
  pollIntervalMs: 1,
81
- pollTimeoutMs: 50,
81
+ // Success paths need several real 1ms polls to see a stable PID. Under a busy
82
+ // test run those sleeps stretch, so give them ample time; they still finish in
83
+ // milliseconds. Tests that expect a timeout set their own short pollTimeoutMs.
84
+ pollTimeoutMs: 5_000,
82
85
  };
83
86
 
84
87
  describe("managed agent runtime defaults", () => {
@@ -347,7 +350,7 @@ describe("startAgent", () => {
347
350
  const tmux = makeTmux();
348
351
  const registry = makeRegistry();
349
352
 
350
- const entry = await startAgent({ ...startOpts, pollTimeoutMs: 250 }, { tmux, registry });
353
+ const entry = await startAgent(startOpts, { tmux, registry });
351
354
 
352
355
  expect(tmux.createSession).toHaveBeenCalledWith("agent1", "/work");
353
356
  expect(tmux.sendKeys).toHaveBeenCalledWith("agent1", "claude");
@@ -393,7 +396,7 @@ describe("startAgent", () => {
393
396
  cwd: "/work",
394
397
  kind: "claude",
395
398
  args: [],
396
- timeoutMs: 50,
399
+ timeoutMs: startOpts.pollTimeoutMs,
397
400
  });
398
401
  expect(entry).toMatchObject({
399
402
  name: "agent1",
@@ -502,11 +505,13 @@ describe("startAgent", () => {
502
505
  } as Partial<TmuxManager>);
503
506
  const registry = makeRegistry();
504
507
 
505
- const err = await startAgent(startOpts, { tmux, registry }).catch((e) => e);
508
+ const err = await startAgent({ ...startOpts, pollTimeoutMs: 20 }, { tmux, registry }).catch(
509
+ (e) => e,
510
+ );
506
511
 
507
512
  expect(err).toBeInstanceOf(AgentPidPollTimeoutError);
508
513
  expect(err.command).toBe("claude");
509
- expect(err.timeoutMs).toBe(50);
514
+ expect(err.timeoutMs).toBe(20);
510
515
  expect(tmux.killSession).toHaveBeenLastCalledWith("agent1");
511
516
  expect(registry.register).not.toHaveBeenCalled();
512
517
  });
@@ -524,7 +529,7 @@ describe("startAgent", () => {
524
529
  const tmux = makeTmux({ findAgentPid } as Partial<TmuxManager>);
525
530
  const registry = makeRegistry();
526
531
 
527
- const entry = await startAgent({ ...startOpts, pollTimeoutMs: 250 }, { tmux, registry });
532
+ const entry = await startAgent(startOpts, { tmux, registry });
528
533
 
529
534
  expect(findAgentPid).toHaveBeenCalledTimes(7);
530
535
  expect(entry.pid).toBe(42);
@@ -130,17 +130,17 @@ export class AntigravitySessionParser {
130
130
  }
131
131
 
132
132
  /**
133
+ * - last turn is an assistant reply → WAITING (awaiting input)
133
134
  * - past the idle threshold → IDLE
134
- * - last turn is an assistant reply → WAITING (awaiting user)
135
135
  * - otherwise (last turn was a user message, or unknown) → RUNNING
136
136
  */
137
137
  determineStatus(session: AntigravitySession): AgentStatus {
138
- if (isIdle(session.lastActive)) {
139
- return AgentStatus.IDLE;
140
- }
141
138
  if (session.lastRole === "assistant") {
142
139
  return AgentStatus.WAITING;
143
140
  }
141
+ if (isIdle(session.lastActive)) {
142
+ return AgentStatus.IDLE;
143
+ }
144
144
  return AgentStatus.RUNNING;
145
145
  }
146
146
 
@@ -188,10 +188,6 @@ export class CodexSessionParser {
188
188
  }
189
189
 
190
190
  determineStatus(session: CodexSession): AgentStatus {
191
- if (isIdle(session.lastActive)) {
192
- return AgentStatus.IDLE;
193
- }
194
-
195
191
  if (
196
192
  session.lastPayloadType === "agent_message" ||
197
193
  session.lastPayloadType === "task_complete" ||
@@ -200,6 +196,10 @@ export class CodexSessionParser {
200
196
  return AgentStatus.WAITING;
201
197
  }
202
198
 
199
+ if (isIdle(session.lastActive)) {
200
+ return AgentStatus.IDLE;
201
+ }
202
+
203
203
  return AgentStatus.RUNNING;
204
204
  }
205
205
 
@@ -276,14 +276,14 @@ export class CopilotSessionParser {
276
276
  }
277
277
 
278
278
  determineStatus(session: CopilotSession): AgentStatus {
279
- if (isIdle(session.lastActive)) {
280
- return AgentStatus.IDLE;
281
- }
282
-
283
279
  if (session.lastEventType !== undefined && WAITING_EVENTS.has(session.lastEventType)) {
284
280
  return AgentStatus.WAITING;
285
281
  }
286
282
 
283
+ if (isIdle(session.lastActive)) {
284
+ return AgentStatus.IDLE;
285
+ }
286
+
287
287
  return AgentStatus.RUNNING;
288
288
  }
289
289
 
@@ -33,7 +33,7 @@ export class DevinAgentMapper {
33
33
  }
34
34
 
35
35
  private determineStatus(stats: DevinSessionStats, lastActive: Date): AgentStatus {
36
- if (isIdle(lastActive)) return AgentStatus.IDLE;
37
- return stats.lastRole === "assistant" ? AgentStatus.WAITING : AgentStatus.RUNNING;
36
+ if (stats.lastRole === "assistant") return AgentStatus.WAITING;
37
+ return isIdle(lastActive) ? AgentStatus.IDLE : AgentStatus.RUNNING;
38
38
  }
39
39
  }
@@ -141,14 +141,14 @@ export class GeminiSessionParser {
141
141
  }
142
142
 
143
143
  determineStatus(session: GeminiSession): AgentStatus {
144
- if (isIdle(session.lastActive)) {
145
- return AgentStatus.IDLE;
146
- }
147
-
148
144
  if (session.lastMessageType === "gemini" || session.lastMessageType === "assistant") {
149
145
  return AgentStatus.WAITING;
150
146
  }
151
147
 
148
+ if (isIdle(session.lastActive)) {
149
+ return AgentStatus.IDLE;
150
+ }
151
+
152
152
  return AgentStatus.RUNNING;
153
153
  }
154
154
 
@@ -119,17 +119,17 @@ export class GrokSessionParser {
119
119
  /**
120
120
  * Determine agent status from parsed session state.
121
121
  *
122
+ * - last transcript turn is an assistant message → WAITING (awaiting input)
122
123
  * - past the idle threshold → IDLE
123
- * - last transcript turn is an assistant message → WAITING (awaiting user)
124
124
  * - otherwise (last turn was a user message, or unknown) → RUNNING
125
125
  */
126
126
  determineStatus(session: GrokSession): AgentStatus {
127
- if (isIdle(session.lastActive)) {
128
- return AgentStatus.IDLE;
129
- }
130
127
  if (session.lastRole === "assistant") {
131
128
  return AgentStatus.WAITING;
132
129
  }
130
+ if (isIdle(session.lastActive)) {
131
+ return AgentStatus.IDLE;
132
+ }
133
133
  return AgentStatus.RUNNING;
134
134
  }
135
135
 
@@ -132,15 +132,15 @@ export class KiroSessionParser {
132
132
  }
133
133
 
134
134
  /**
135
- * - past the idle threshold → IDLE
136
135
  * - last event is an assistant reply without a tool call → WAITING
136
+ * - past the idle threshold → IDLE
137
137
  * - otherwise (user prompt, tool call or tool result) → RUNNING
138
138
  */
139
139
  determineStatus(session: KiroSession): AgentStatus {
140
- if (isIdle(session.lastActive)) return AgentStatus.IDLE;
141
140
  if (session.lastEventKind === "AssistantMessage" && !session.lastAssistantHasToolUse) {
142
141
  return AgentStatus.WAITING;
143
142
  }
143
+ if (isIdle(session.lastActive)) return AgentStatus.IDLE;
144
144
  return AgentStatus.RUNNING;
145
145
  }
146
146
 
@@ -40,12 +40,10 @@ export class OpenCodeAgentMapper {
40
40
  }
41
41
 
42
42
  private determineStatus(stats: OpenCodeSessionStats, lastActive: Date): AgentStatus {
43
- if (isIdle(lastActive)) return AgentStatus.IDLE;
44
-
45
- if (stats.lastRole === "assistant" && !stats.lastAssistantCompleted) {
46
- return AgentStatus.RUNNING;
43
+ if (stats.lastRole === "assistant" && stats.lastAssistantCompleted) {
44
+ return AgentStatus.WAITING;
47
45
  }
48
- if (stats.lastRole === "assistant") return AgentStatus.WAITING;
46
+ if (isIdle(lastActive)) return AgentStatus.IDLE;
49
47
  return AgentStatus.RUNNING;
50
48
  }
51
49
  }
@@ -174,8 +174,8 @@ export class PiSessionParser {
174
174
  }
175
175
 
176
176
  determineStatus(session: PiSession): AgentStatus {
177
- if (isIdle(session.lastActive)) return AgentStatus.IDLE;
178
177
  if (session.lastRole === "assistant") return AgentStatus.WAITING;
178
+ if (isIdle(session.lastActive)) return AgentStatus.IDLE;
179
179
  return AgentStatus.RUNNING;
180
180
  }
181
181