@ai-devkit/agent-manager 0.42.1 → 0.42.3

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 (64) hide show
  1. package/dist/__tests__/capacity/codex.test.js +41 -48
  2. package/dist/__tests__/capacity/codex.test.js.map +1 -1
  3. package/dist/__tests__/capacity/openai.test.js +9 -1
  4. package/dist/__tests__/capacity/openai.test.js.map +1 -1
  5. package/dist/__tests__/capacity/wham.test.js +21 -6
  6. package/dist/__tests__/capacity/wham.test.js.map +1 -1
  7. package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js +9 -1
  8. package/dist/__tests__/harnesses/devin/DevinAgentMapper.test.js.map +1 -1
  9. package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js +12 -1
  10. package/dist/__tests__/harnesses/gemini/GeminiCliAdapter.test.js.map +1 -1
  11. package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js +20 -1
  12. package/dist/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.js.map +1 -1
  13. package/dist/__tests__/runtime/ManagedAgentRuntime.test.js +12 -12
  14. package/dist/__tests__/runtime/ManagedAgentRuntime.test.js.map +1 -1
  15. package/dist/capacity/providers/openai-subscription.d.ts +1 -5
  16. package/dist/capacity/providers/openai-subscription.d.ts.map +1 -1
  17. package/dist/capacity/providers/openai-subscription.js +37 -13
  18. package/dist/capacity/providers/openai-subscription.js.map +1 -1
  19. package/dist/capacity/sources/codex.d.ts +1 -8
  20. package/dist/capacity/sources/codex.d.ts.map +1 -1
  21. package/dist/capacity/sources/codex.js +10 -19
  22. package/dist/capacity/sources/codex.js.map +1 -1
  23. package/dist/harnesses/antigravity/AntigravitySessionParser.d.ts +1 -1
  24. package/dist/harnesses/antigravity/AntigravitySessionParser.js +4 -4
  25. package/dist/harnesses/antigravity/AntigravitySessionParser.js.map +1 -1
  26. package/dist/harnesses/codex/CodexSessionParser.js +3 -3
  27. package/dist/harnesses/codex/CodexSessionParser.js.map +1 -1
  28. package/dist/harnesses/copilot/CopilotSessionParser.js +3 -3
  29. package/dist/harnesses/copilot/CopilotSessionParser.js.map +1 -1
  30. package/dist/harnesses/devin/DevinAgentMapper.js +2 -2
  31. package/dist/harnesses/devin/DevinAgentMapper.js.map +1 -1
  32. package/dist/harnesses/gemini/GeminiSessionParser.js +3 -3
  33. package/dist/harnesses/gemini/GeminiSessionParser.js.map +1 -1
  34. package/dist/harnesses/grok/GrokSessionParser.d.ts +1 -1
  35. package/dist/harnesses/grok/GrokSessionParser.js +4 -4
  36. package/dist/harnesses/grok/GrokSessionParser.js.map +1 -1
  37. package/dist/harnesses/kiro/KiroSessionParser.d.ts +1 -1
  38. package/dist/harnesses/kiro/KiroSessionParser.js +2 -2
  39. package/dist/harnesses/kiro/KiroSessionParser.js.map +1 -1
  40. package/dist/harnesses/opencode/OpenCodeAgentMapper.d.ts.map +1 -1
  41. package/dist/harnesses/opencode/OpenCodeAgentMapper.js +3 -4
  42. package/dist/harnesses/opencode/OpenCodeAgentMapper.js.map +1 -1
  43. package/dist/harnesses/pi/PiSessionParser.js +1 -1
  44. package/dist/harnesses/pi/PiSessionParser.js.map +1 -1
  45. package/package.json +1 -1
  46. package/src/__tests__/capacity/codex.test.ts +42 -47
  47. package/src/__tests__/capacity/fixtures/wham-usage.json +14 -1
  48. package/src/__tests__/capacity/openai.test.ts +12 -1
  49. package/src/__tests__/capacity/wham.test.ts +20 -2
  50. package/src/__tests__/harnesses/devin/DevinAgentMapper.test.ts +14 -1
  51. package/src/__tests__/harnesses/gemini/GeminiCliAdapter.test.ts +13 -1
  52. package/src/__tests__/harnesses/opencode/OpenCodeAgentMapper.test.ts +19 -1
  53. package/src/__tests__/runtime/ManagedAgentRuntime.test.ts +11 -6
  54. package/src/capacity/providers/openai-subscription.ts +42 -20
  55. package/src/capacity/sources/codex.ts +7 -18
  56. package/src/harnesses/antigravity/AntigravitySessionParser.ts +4 -4
  57. package/src/harnesses/codex/CodexSessionParser.ts +4 -4
  58. package/src/harnesses/copilot/CopilotSessionParser.ts +4 -4
  59. package/src/harnesses/devin/DevinAgentMapper.ts +2 -2
  60. package/src/harnesses/gemini/GeminiSessionParser.ts +4 -4
  61. package/src/harnesses/grok/GrokSessionParser.ts +4 -4
  62. package/src/harnesses/kiro/KiroSessionParser.ts +2 -2
  63. package/src/harnesses/opencode/OpenCodeAgentMapper.ts +3 -5
  64. package/src/harnesses/pi/PiSessionParser.ts +1 -1
@@ -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);
@@ -1,4 +1,4 @@
1
- import type { CapacityWindow, ProviderCapacitySnapshot } from "../types.js";
1
+ import type { Availability, CapacityWindow, ProviderCapacitySnapshot } from "../types.js";
2
2
 
3
3
  const WHAM_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
4
4
  const OPENAI_WHOAMI_URL = "https://auth.openai.com/api/accounts/v1/user-auth-credential/whoami";
@@ -13,11 +13,6 @@ export type OpenAiSubscriptionCapacityOptions = {
13
13
  timeoutMs?: number;
14
14
  };
15
15
 
16
- export type WhamUsageSnapshot = {
17
- windows: CapacityWindow[];
18
- creditsRemaining: number | null;
19
- };
20
-
21
16
  type UnknownRecord = Record<string, unknown>;
22
17
 
23
18
  function record(value: unknown): UnknownRecord | null {
@@ -30,6 +25,14 @@ function finiteNumber(value: unknown): number | null {
30
25
  return typeof value === "number" && Number.isFinite(value) ? value : null;
31
26
  }
32
27
 
28
+ function numericValue(value: unknown): number | null {
29
+ const direct = finiteNumber(value);
30
+ if (direct !== null) return direct;
31
+ if (typeof value !== "string" || value.trim().length === 0) return null;
32
+ const parsed = Number(value);
33
+ return Number.isFinite(parsed) ? parsed : null;
34
+ }
35
+
33
36
  function nonEmptyText(value: unknown): string | null {
34
37
  return typeof value === "string" && value.length > 0 ? value : null;
35
38
  }
@@ -78,16 +81,42 @@ function extraWindows(value: unknown): CapacityWindow[] {
78
81
  });
79
82
  }
80
83
 
81
- export function parseWhamUsage(raw: unknown): WhamUsageSnapshot {
84
+ function spendControlWindow(value: unknown): CapacityWindow | null {
85
+ const limit = record(record(value)?.individual_limit);
86
+ if (!limit) return null;
87
+ return {
88
+ id: "spend-control",
89
+ label: "Spend control",
90
+ durationMinutes: null,
91
+ usedPercent: finiteNumber(limit.used_percent),
92
+ resetsAt: resetTime(limit.reset_at),
93
+ limitType: "CREDIT_LIMIT",
94
+ total: numericValue(limit.limit),
95
+ current: numericValue(limit.used),
96
+ remaining: numericValue(limit.remaining),
97
+ };
98
+ }
99
+
100
+ function availability(windows: CapacityWindow[], spendControl: UnknownRecord | null): Availability {
101
+ if (spendControl?.reached === true) return "no";
102
+ return windows.some((window) => window.usedPercent !== null) ? "yes" : "unknown";
103
+ }
104
+
105
+ export function parseWhamUsage(raw: unknown): ProviderCapacitySnapshot {
82
106
  const response = record(raw) ?? {};
83
107
  const limits = record(response.rate_limit) ?? {};
84
108
  const credits = record(response.credits) ?? {};
109
+ const spendControl = record(response.spend_control);
110
+ const windows = [
111
+ toRateWindow(limits.primary_window, "session", "Session"),
112
+ toRateWindow(limits.secondary_window, "weekly", "Weekly"),
113
+ ...extraWindows(response.additional_rate_limits),
114
+ spendControlWindow(spendControl),
115
+ ].filter((window): window is CapacityWindow => window !== null);
85
116
  return {
86
- windows: [
87
- toRateWindow(limits.primary_window, "session", "Session"),
88
- toRateWindow(limits.secondary_window, "weekly", "Weekly"),
89
- ...extraWindows(response.additional_rate_limits),
90
- ].filter((window): window is CapacityWindow => window !== null),
117
+ authenticated: true,
118
+ available: availability(windows, spendControl),
119
+ windows,
91
120
  creditsRemaining: finiteNumber(credits.balance),
92
121
  };
93
122
  }
@@ -126,14 +155,7 @@ export async function fetchOpenAiSubscriptionCapacity(
126
155
  } catch {
127
156
  throw new Error("OpenAI usage response is not valid JSON");
128
157
  }
129
- const snapshot = parseWhamUsage(raw);
130
- const hasUsage = snapshot.windows.some((window) => window.usedPercent !== null);
131
- return {
132
- authenticated: true,
133
- available: hasUsage ? "yes" : "unknown",
134
- windows: snapshot.windows,
135
- creditsRemaining: snapshot.creditsRemaining,
136
- };
158
+ return parseWhamUsage(raw);
137
159
  }
138
160
 
139
161
  export async function fetchOpenAiPatAccountId(
@@ -2,7 +2,6 @@ import { spawn } from "node:child_process";
2
2
  import {
3
3
  fetchOpenAiPatAccountId,
4
4
  fetchOpenAiSubscriptionCapacity,
5
- parseWhamUsage,
6
5
  resetTime,
7
6
  safeIdentifier,
8
7
  } from "../providers/openai-subscription.js";
@@ -12,11 +11,10 @@ import {
12
11
  type CodexCredentialOptions,
13
12
  } from "../../harnesses/codex/credentials.js";
14
13
 
15
- type CodexUsageSource = "pat" | "oauth" | "cli";
16
14
  type UsageSnapshot = {
17
15
  windows: CapacityWindow[];
18
16
  creditsRemaining: number | null;
19
- source: CodexUsageSource;
17
+ available: CapacityReport["available"] | null;
20
18
  };
21
19
 
22
20
  type UnknownRecord = Record<string, unknown>;
@@ -48,11 +46,6 @@ function nonEmptyText(value: unknown): string | null {
48
46
  return typeof value === "string" && value.length > 0 ? value : null;
49
47
  }
50
48
 
51
- export function parseUsage(raw: unknown, source: "pat" | "oauth"): UsageSnapshot {
52
- const { windows, creditsRemaining } = parseWhamUsage(raw);
53
- return { windows, creditsRemaining, source };
54
- }
55
-
56
49
  function cliWindow(value: unknown, id: string, label: string): CapacityWindow | null {
57
50
  const input = record(value);
58
51
  if (!input) return null;
@@ -86,7 +79,7 @@ function parseCliUsage(raw: unknown): UsageSnapshot {
86
79
  }
87
80
  }
88
81
  const unique = [...new Map(windows.map((window) => [window.id, window])).values()];
89
- return { windows: unique, creditsRemaining: null, source: "cli" };
82
+ return { windows: unique, creditsRemaining: null, available: null };
90
83
  }
91
84
 
92
85
  function capacityFromSnapshot(
@@ -99,12 +92,15 @@ function capacityFromSnapshot(
99
92
  const reached = nonEmptyText(rateLimits?.rateLimitReachedType);
100
93
  const resetCredits =
101
94
  record(record(raw)?.rateLimitResetCredits) ?? record(record(raw)?.usageLimitResetCredits);
95
+ let available = snapshot.available;
96
+ if (reached) available = "no";
97
+ else if (available === null) available = hasUsage ? "yes" : "unknown";
102
98
  return {
103
99
  harness: "codex",
104
100
  provider: "openai",
105
101
  generatedAt: options.checkedAt,
106
102
  authenticated: true,
107
- available: reached ? "no" : hasUsage ? "yes" : "unknown",
103
+ available,
108
104
  windows: snapshot.windows,
109
105
  creditsRemaining: snapshot.creditsRemaining ?? finiteNumber(resetCredits?.availableCount),
110
106
  };
@@ -214,16 +210,11 @@ async function cliFallback(options: CodexProbeOptions): Promise<CapacityReport>
214
210
  async function subscriptionSnapshot(
215
211
  access: string,
216
212
  accountId: string,
217
- source: "pat" | "oauth",
218
213
  options: CodexProbeOptions,
219
214
  ): Promise<UsageSnapshot> {
220
215
  const snapshot = await fetchOpenAiSubscriptionCapacity({ access, accountId }, options);
221
216
  if (snapshot.authenticated === false) throw new Error("unauthorized");
222
- return {
223
- windows: snapshot.windows,
224
- creditsRemaining: snapshot.creditsRemaining,
225
- source,
226
- };
217
+ return snapshot;
227
218
  }
228
219
 
229
220
  export async function probeCodexCapacity(options: CodexProbeOptions): Promise<CapacityReport> {
@@ -236,7 +227,6 @@ export async function probeCodexCapacity(options: CodexProbeOptions): Promise<Ca
236
227
  const snapshot = await subscriptionSnapshot(
237
228
  credentials.personalAccessToken,
238
229
  accountId,
239
- "pat",
240
230
  options,
241
231
  );
242
232
  return capacityFromSnapshot(snapshot, options);
@@ -250,7 +240,6 @@ export async function probeCodexCapacity(options: CodexProbeOptions): Promise<Ca
250
240
  const snapshot = await subscriptionSnapshot(
251
241
  credentials.oauth.access,
252
242
  credentials.oauth.accountId,
253
- "oauth",
254
243
  options,
255
244
  );
256
245
  return capacityFromSnapshot(snapshot, options);
@@ -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