@ai-devkit/agent-manager 0.35.0 → 0.36.0
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/dist/__tests__/adapters/AntigravityCliAdapter.test.js +381 -0
- package/dist/__tests__/adapters/AntigravityCliAdapter.test.js.map +1 -0
- package/dist/__tests__/adapters/KiroAdapter.test.js +607 -0
- package/dist/__tests__/adapters/KiroAdapter.test.js.map +1 -0
- package/dist/__tests__/capacity/claude.test.js +485 -0
- package/dist/__tests__/capacity/claude.test.js.map +1 -0
- package/dist/__tests__/capacity/openai.test.js +672 -0
- package/dist/__tests__/capacity/openai.test.js.map +1 -0
- package/dist/__tests__/capacity/wham.test.js +144 -0
- package/dist/__tests__/capacity/wham.test.js.map +1 -0
- package/dist/__tests__/utils/agents.test.js +6 -0
- package/dist/__tests__/utils/agents.test.js.map +1 -1
- package/dist/adapters/AgentAdapter.d.ts +1 -1
- package/dist/adapters/AgentAdapter.d.ts.map +1 -1
- package/dist/adapters/AgentAdapter.js.map +1 -1
- package/dist/adapters/AntigravityCliAdapter.d.ts +57 -0
- package/dist/adapters/AntigravityCliAdapter.d.ts.map +1 -0
- package/dist/adapters/AntigravityCliAdapter.js +273 -0
- package/dist/adapters/AntigravityCliAdapter.js.map +1 -0
- package/dist/adapters/KiroAdapter.d.ts +46 -0
- package/dist/adapters/KiroAdapter.d.ts.map +1 -0
- package/dist/adapters/KiroAdapter.js +344 -0
- package/dist/adapters/KiroAdapter.js.map +1 -0
- package/dist/adapters/index.d.ts +2 -0
- package/dist/adapters/index.d.ts.map +1 -1
- package/dist/adapters/index.js +2 -0
- package/dist/adapters/index.js.map +1 -1
- package/dist/capacity/claude.d.ts +17 -0
- package/dist/capacity/claude.d.ts.map +1 -0
- package/dist/capacity/claude.js +271 -0
- package/dist/capacity/claude.js.map +1 -0
- package/dist/capacity/codex.d.ts +1 -2
- package/dist/capacity/codex.d.ts.map +1 -1
- package/dist/capacity/codex.js +5 -47
- package/dist/capacity/codex.js.map +1 -1
- package/dist/capacity/index.d.ts +11 -0
- package/dist/capacity/index.d.ts.map +1 -1
- package/dist/capacity/index.js +17 -0
- package/dist/capacity/index.js.map +1 -1
- package/dist/capacity/openai.d.ts +48 -0
- package/dist/capacity/openai.d.ts.map +1 -0
- package/dist/capacity/openai.js +312 -0
- package/dist/capacity/openai.js.map +1 -0
- package/dist/capacity/wham.d.ts +16 -0
- package/dist/capacity/wham.d.ts.map +1 -0
- package/dist/capacity/wham.js +66 -0
- package/dist/capacity/wham.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/readiness/AgentReadiness.d.ts +1 -1
- package/dist/readiness/AgentReadiness.d.ts.map +1 -1
- package/dist/readiness/AgentReadiness.js.map +1 -1
- package/dist/runtime/ManagedAgentRuntime.js +3 -1
- package/dist/runtime/ManagedAgentRuntime.js.map +1 -1
- package/dist/runtime/herdr/HerdrAgentDiscovery.js +10 -0
- package/dist/runtime/herdr/HerdrAgentDiscovery.js.map +1 -1
- package/dist/utils/agents.d.ts +1 -1
- package/dist/utils/agents.d.ts.map +1 -1
- package/dist/utils/agents.js +11 -0
- package/dist/utils/agents.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/adapters/AntigravityCliAdapter.test.ts +324 -0
- package/src/__tests__/adapters/KiroAdapter.test.ts +534 -0
- package/src/__tests__/capacity/claude.test.ts +467 -0
- package/src/__tests__/capacity/fixtures/claude-credentials.json +7 -0
- package/src/__tests__/capacity/fixtures/claude-usage-malformed.json +1 -0
- package/src/__tests__/capacity/fixtures/claude-usage-partial.json +15 -0
- package/src/__tests__/capacity/fixtures/claude-usage.json +63 -0
- package/src/__tests__/capacity/fixtures/openai-auth.json +6 -0
- package/src/__tests__/capacity/fixtures/openai-codex-auth.json +9 -0
- package/src/__tests__/capacity/fixtures/openai-usage-completions.json +67 -0
- package/src/__tests__/capacity/fixtures/openai-usage-responses.json +20 -0
- package/src/__tests__/capacity/fixtures/wham-usage.json +32 -0
- package/src/__tests__/capacity/openai.test.ts +570 -0
- package/src/__tests__/capacity/wham.test.ts +104 -0
- package/src/__tests__/utils/agents.test.ts +7 -0
- package/src/adapters/AgentAdapter.ts +2 -0
- package/src/adapters/AntigravityCliAdapter.ts +356 -0
- package/src/adapters/KiroAdapter.ts +456 -0
- package/src/adapters/index.ts +2 -0
- package/src/capacity/claude.ts +313 -0
- package/src/capacity/codex.ts +25 -134
- package/src/capacity/index.ts +33 -4
- package/src/capacity/openai.ts +361 -0
- package/src/capacity/wham.ts +84 -0
- package/src/index.ts +10 -1
- package/src/readiness/AgentReadiness.ts +4 -1
- package/src/runtime/ManagedAgentRuntime.ts +2 -0
- package/src/runtime/herdr/HerdrAgentDiscovery.ts +5 -1
- package/src/utils/agents.ts +11 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/__tests__/capacity/openai.test.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { readFileSync } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\nimport { describe, expect, it, vi } from \"vitest\";\nimport {\n buildOpenAiReport,\n parseOpenAiUsage,\n probeOpenAiCapacity,\n resolveOpenAiApiKey,\n resolveOpenAiCredential,\n} from \"../../capacity/openai.js\";\n\nconst checkedAt = \"2026-09-26T10:00:00.000Z\";\nconst fixture = (name: string) =>\n readFile(fileURLToPath(new URL(`./fixtures/${name}`, import.meta.url)), \"utf8\");\nconst fixtureString = (name: string) =>\n readFileSync(fileURLToPath(new URL(`./fixtures/${name}`, import.meta.url)), \"utf8\");\n\ndescribe(\"OpenAI credential resolution\", () => {\n it(\"prefers OPENAI_API_KEY without reading Pi auth\", async () => {\n const readAuth = vi.fn(async () => fixture(\"openai-auth.json\"));\n await expect(\n resolveOpenAiApiKey({\n env: { OPENAI_API_KEY: \"env-openai-test-key\" },\n readFile: readAuth,\n }),\n ).resolves.toBe(\"env-openai-test-key\");\n expect(readAuth).not.toHaveBeenCalled();\n });\n\n it(\"reads the Pi openai api_key credential from ~/.pi/agent/auth.json\", async () => {\n const readAuth = vi.fn(async () => fixture(\"openai-auth.json\"));\n await expect(\n resolveOpenAiApiKey({ env: { HOME: \"/users/test\" }, readFile: readAuth }),\n ).resolves.toBe(\"pi-openai-test-key\");\n expect(readAuth).toHaveBeenCalledWith(\"/users/test/.pi/agent/auth.json\", \"utf8\");\n });\n\n it.each([\n [\n \"missing\",\n async () => Promise.reject(Object.assign(new Error(\"missing\"), { code: \"ENOENT\" })),\n ],\n [\"invalid JSON\", async () => \"{\"],\n [\"wrong credential type\", async () => JSON.stringify({ openai: { type: \"oauth\", key: \"x\" } })],\n [\"missing key\", async () => JSON.stringify({ openai: { type: \"api_key\" } })],\n ])(\"fails clearly for %s credentials without exposing file content\", async (_name, readAuth) => {\n await expect(\n resolveOpenAiApiKey({\n env: { HOME: \"/users/test\" },\n readFile: readAuth,\n }),\n ).rejects.toThrow(/OpenAI credentials not found|OpenAI Pi auth file/);\n });\n});\n\ndescribe(\"OpenAI tiered credential resolution\", () => {\n const oauthFixture = () => fixture(\"openai-codex-auth.json\");\n const bothCredentials = JSON.stringify({\n openai: { type: \"api_key\", key: \"pi-openai-test-key\" },\n \"openai-codex\": {\n type: \"oauth\",\n access: \"fixture-header.eyJleHAiOjE3OTMwMDAwMDB9.fixture-signature\",\n refresh: \"fixture-refresh-token\",\n expires: 1793000000000,\n accountId: \"fixture-chatgpt-account-id\",\n },\n });\n\n it(\"prefers the Pi openai platform credential over the openai-codex OAuth login\", async () => {\n await expect(\n resolveOpenAiCredential({\n env: { HOME: \"/users/test\" },\n readFile: async () => bothCredentials,\n }),\n ).resolves.toEqual({ kind: \"platform\", key: \"pi-openai-test-key\" });\n });\n\n it(\"resolves the Pi openai-codex OAuth login when no platform credential exists\", async () => {\n await expect(\n resolveOpenAiCredential({\n env: { HOME: \"/users/test\" },\n readFile: async () => oauthFixture(),\n }),\n ).resolves.toEqual({\n kind: \"oauth\",\n access: \"fixture-header.eyJleHAiOjE3OTMwMDAwMDB9.fixture-signature\",\n accountId: \"fixture-chatgpt-account-id\",\n expiresMs: 1793000000000,\n });\n });\n\n it(\"normalizes second-based expires values to epoch milliseconds\", async () => {\n const auth = JSON.stringify({\n \"openai-codex\": {\n type: \"oauth\",\n access: \"fixture-access\",\n refresh: \"fixture-refresh\",\n expires: 1793000000,\n accountId: \"fixture-chatgpt-account-id\",\n },\n });\n await expect(\n resolveOpenAiCredential({ env: { HOME: \"/users/test\" }, readFile: async () => auth }),\n ).resolves.toMatchObject({ kind: \"oauth\", expiresMs: 1793000000000 });\n });\n\n it(\"keeps a null expiry for OAuth logins without usable expires metadata\", async () => {\n const auth = JSON.stringify({\n \"openai-codex\": {\n type: \"oauth\",\n access: \"fixture-access\",\n accountId: \"fixture-chatgpt-account-id\",\n },\n });\n await expect(\n resolveOpenAiCredential({ env: { HOME: \"/users/test\" }, readFile: async () => auth }),\n ).resolves.toMatchObject({ kind: \"oauth\", expiresMs: null });\n });\n\n it.each([\n [\"wrong credential type\", JSON.stringify({ \"openai-codex\": { type: \"api_key\", key: \"x\" } })],\n [\"missing access token\", JSON.stringify({ \"openai-codex\": { type: \"oauth\", accountId: \"a\" } })],\n [\"missing account id\", JSON.stringify({ \"openai-codex\": { type: \"oauth\", access: \"t\" } })],\n ])(\n \"skips a malformed openai-codex credential (%s) with a sanitized error\",\n async (_name, auth) => {\n await expect(\n resolveOpenAiCredential({ env: { HOME: \"/users/test\" }, readFile: async () => auth }),\n ).rejects.toThrow(\"OpenAI credentials not found\");\n },\n );\n\n it(\"still throws for OAuth-only machines on the legacy platform-key resolver\", async () => {\n await expect(\n resolveOpenAiApiKey({\n env: { HOME: \"/users/test\" },\n readFile: async () => oauthFixture(),\n }),\n ).rejects.toThrow(\"OpenAI credentials not found\");\n });\n});\n\ndescribe(\"OpenAI OAuth capacity probe\", () => {\n const freshOauth = () => fixture(\"openai-codex-auth.json\");\n const whamResponse = () => new Response(fixtureString(\"wham-usage.json\"), { status: 200 });\n\n it(\"reports wham usage windows for a fresh Pi OAuth login\", async () => {\n const fetch = vi.fn(async () => whamResponse());\n const report = await probeOpenAiCapacity({\n checkedAt,\n env: { HOME: \"/users/test\" },\n readFile: async () => freshOauth(),\n fetch,\n });\n expect(fetch).toHaveBeenCalledWith(\n \"https://chatgpt.com/backend-api/wham/usage\",\n expect.objectContaining({\n method: \"GET\",\n headers: {\n Authorization: \"Bearer fixture-header.eyJleHAiOjE3OTMwMDAwMDB9.fixture-signature\",\n \"ChatGPT-Account-Id\": \"fixture-chatgpt-account-id\",\n },\n }),\n );\n expect(report).toMatchObject({\n harness: \"pi\",\n provider: \"openai\",\n generatedAt: checkedAt,\n authenticated: true,\n available: \"yes\",\n creditsRemaining: 4.5,\n });\n expect(report.windows.map((window) => window.id)).toEqual([\"session\", \"weekly\"]);\n expect(JSON.stringify(report)).not.toContain(\"fixture-signature\");\n });\n\n it(\"does not fetch and reports an authenticated-but-stale state for expired logins\", async () => {\n const staleAuth = JSON.stringify({\n \"openai-codex\": {\n type: \"oauth\",\n access: \"stale-fixture-access\",\n expires: 1790000000000,\n accountId: \"fixture-chatgpt-account-id\",\n },\n });\n const fetch = vi.fn();\n const report = await probeOpenAiCapacity({\n checkedAt,\n env: { HOME: \"/users/test\" },\n readFile: async () => staleAuth,\n fetch,\n });\n expect(fetch).not.toHaveBeenCalled();\n expect(report).toEqual({\n harness: \"pi\",\n provider: \"openai\",\n generatedAt: checkedAt,\n authenticated: true,\n available: \"unknown\",\n windows: [],\n creditsRemaining: null,\n });\n });\n\n it(\"treats second-based expiry metadata as stale the same way\", async () => {\n const staleAuth = JSON.stringify({\n \"openai-codex\": {\n type: \"oauth\",\n access: \"stale-fixture-access\",\n expires: 1790000000,\n accountId: \"fixture-chatgpt-account-id\",\n },\n });\n const fetch = vi.fn();\n const report = await probeOpenAiCapacity({\n checkedAt,\n env: { HOME: \"/users/test\" },\n readFile: async () => staleAuth,\n fetch,\n });\n expect(fetch).not.toHaveBeenCalled();\n expect(report.available).toBe(\"unknown\");\n });\n\n it(\"falls back to the JWT exp when expires metadata is missing\", async () => {\n const expiredJwtAuth = JSON.stringify({\n \"openai-codex\": {\n type: \"oauth\",\n access: \"h.eyJleHAiOjE3ODkwMDAwMDB9.s\",\n accountId: \"fixture-chatgpt-account-id\",\n },\n });\n const noFetch = vi.fn();\n await expect(\n probeOpenAiCapacity({\n checkedAt,\n env: { HOME: \"/users/test\" },\n readFile: async () => expiredJwtAuth,\n fetch: noFetch,\n }),\n ).resolves.toMatchObject({ authenticated: true, available: \"unknown\" });\n expect(noFetch).not.toHaveBeenCalled();\n\n const futureJwtAuth = JSON.stringify({\n \"openai-codex\": {\n type: \"oauth\",\n access: \"h.eyJleHAiOjE3OTMwMDAwMDB9.s\",\n accountId: \"fixture-chatgpt-account-id\",\n },\n });\n const fetch = vi.fn(async () => whamResponse());\n await expect(\n probeOpenAiCapacity({\n checkedAt,\n env: { HOME: \"/users/test\" },\n readFile: async () => futureJwtAuth,\n fetch,\n }),\n ).resolves.toMatchObject({ authenticated: true, available: \"yes\" });\n expect(fetch).toHaveBeenCalledOnce();\n });\n\n it(\"treats unparseable JWT payloads as unknown expiry and probes anyway\", async () => {\n const auth = JSON.stringify({\n \"openai-codex\": {\n type: \"oauth\",\n access: \"fixture-header.bm90LWpzb24.fixture-signature\",\n accountId: \"fixture-chatgpt-account-id\",\n },\n });\n const fetch = vi.fn(async () => whamResponse());\n await expect(\n probeOpenAiCapacity({\n checkedAt,\n env: { HOME: \"/users/test\" },\n readFile: async () => auth,\n fetch,\n }),\n ).resolves.toMatchObject({ authenticated: true, available: \"yes\" });\n expect(fetch).toHaveBeenCalledOnce();\n });\n\n it(\"treats non-JWT and exp-less access tokens as unknown expiry and probes anyway\", async () => {\n for (const access of [\"opaque-fixture-access\", \"h.eyJzdWIiOiJ4In0.s\"]) {\n const auth = JSON.stringify({\n \"openai-codex\": {\n type: \"oauth\",\n access,\n accountId: \"fixture-chatgpt-account-id\",\n },\n });\n const fetch = vi.fn(async () => whamResponse());\n await expect(\n probeOpenAiCapacity({\n checkedAt,\n env: { HOME: \"/users/test\" },\n readFile: async () => auth,\n fetch,\n }),\n ).resolves.toMatchObject({ authenticated: true, available: \"yes\" });\n expect(fetch).toHaveBeenCalledOnce();\n }\n });\n\n it(\"reports unknown availability when wham returns no usable windows\", async () => {\n const report = await probeOpenAiCapacity({\n checkedAt,\n env: { HOME: \"/users/test\" },\n readFile: async () => freshOauth(),\n fetch: vi.fn(async () => new Response(\"{}\", { status: 200 })),\n });\n expect(report).toMatchObject({ authenticated: true, available: \"unknown\", windows: [] });\n });\n\n it(\"reports unauthenticated when wham rejects the OAuth token\", async () => {\n for (const status of [401, 403]) {\n const report = await probeOpenAiCapacity({\n checkedAt,\n env: { HOME: \"/users/test\" },\n readFile: async () => freshOauth(),\n fetch: vi.fn(async () => new Response(\"denied\", { status })),\n });\n expect(report).toMatchObject({\n authenticated: false,\n available: \"unknown\",\n windows: [],\n creditsRemaining: null,\n });\n }\n });\n\n it(\"throws sanitized errors for transport failures without leaking tokens\", async () => {\n const probe = (fetch: unknown) =>\n probeOpenAiCapacity({\n checkedAt,\n env: { HOME: \"/users/test\" },\n readFile: async () => freshOauth(),\n fetch: fetch as typeof globalThis.fetch,\n timeoutMs: 10,\n });\n await expect(\n probe(\n (_url: string, init: RequestInit) =>\n new Promise((_resolve, reject) =>\n init.signal?.addEventListener(\"abort\", () => reject(new Error(\"aborted\"))),\n ),\n ),\n ).rejects.toThrow(\"OpenAI usage request failed\");\n await expect(probe(vi.fn(async () => new Response(\"boom\", { status: 503 })))).rejects.toThrow(\n \"OpenAI usage request failed: HTTP 503\",\n );\n await expect(\n probe(vi.fn(async () => new Response(\"not-json\", { status: 200 }))),\n ).rejects.toThrow(\"OpenAI usage response is not valid JSON\");\n try {\n await probe(vi.fn(async () => new Response(\"boom\", { status: 503 })));\n } catch (error) {\n expect(String(error)).not.toContain(\"fixture-signature\");\n expect(String(error)).not.toContain(\"fixture-chatgpt-account-id\");\n }\n });\n});\n\ndescribe(\"OpenAI usage mapping\", () => {\n it(\"sums per-model input and output tokens into UTC day buckets\", async () => {\n const buckets = parseOpenAiUsage(JSON.parse(await fixture(\"openai-usage-completions.json\")));\n expect(buckets).toEqual([\n { startMs: 1790380800000, tokens: 2000 },\n { startMs: 1790294400000, tokens: 5000 },\n { startMs: 1789862400000, tokens: 1000 },\n { startMs: 1789689600000, tokens: 19998 },\n ]);\n });\n\n it(\"keeps empty buckets and skips entries it cannot place in time\", () => {\n expect(\n parseOpenAiUsage({\n object: \"list\",\n data: [\n null,\n 42,\n { aggregation_timestamp: 1790380800 },\n { aggregation_timestamp: \"yesterday\", results: [] },\n { aggregation_timestamp: 1790294400, results: null },\n ],\n }),\n ).toEqual([\n { startMs: 1790380800000, tokens: 0 },\n { startMs: 1790294400000, tokens: 0 },\n ]);\n });\n\n it(\"rejects responses without a usage data array\", () => {\n expect(() => parseOpenAiUsage({ object: \"list\" })).toThrow(\"Invalid OpenAI usage response\");\n expect(() => parseOpenAiUsage({ data: {} })).toThrow(\"Invalid OpenAI usage response\");\n });\n\n it(\"builds today and 7-day windows without faked limits\", async () => {\n const buckets = [\n ...parseOpenAiUsage(JSON.parse(await fixture(\"openai-usage-completions.json\"))),\n ...parseOpenAiUsage(JSON.parse(await fixture(\"openai-usage-responses.json\"))),\n ];\n const report = buildOpenAiReport(buckets, checkedAt);\n expect(report).toMatchObject({\n harness: \"pi\",\n provider: \"openai\",\n generatedAt: checkedAt,\n authenticated: true,\n available: \"yes\",\n creditsRemaining: null,\n });\n expect(report.windows).toEqual([\n {\n id: \"openai:tokens:today\",\n label: \"Tokens · today (UTC)\",\n limitType: \"TOKENS_LIMIT\",\n durationMinutes: 1440,\n usedPercent: null,\n resetsAt: \"2026-09-27T00:00:00.000Z\",\n total: null,\n current: 2000,\n remaining: null,\n },\n {\n id: \"openai:tokens:week\",\n label: \"Tokens · 7 days\",\n limitType: \"TOKENS_LIMIT\",\n durationMinutes: 10080,\n usedPercent: null,\n resetsAt: null,\n total: null,\n current: 13000,\n remaining: null,\n },\n ]);\n });\n\n it(\"reports zero usage for days without buckets\", () => {\n const report = buildOpenAiReport([], checkedAt);\n expect(report.windows.map((window) => window.current)).toEqual([0, 0]);\n expect(report.windows[0].resetsAt).toBe(\"2026-09-27T00:00:00.000Z\");\n });\n});\n\ndescribe(\"OpenAI request\", () => {\n it(\"GETs both usage endpoints for the trailing week with only Bearer authentication\", async () => {\n const fetch = vi.fn(async (url: string) =>\n url.includes(\"/responses?\")\n ? new Response(await fixture(\"openai-usage-responses.json\"), {\n status: 200,\n })\n : new Response(await fixture(\"openai-usage-completions.json\"), {\n status: 200,\n }),\n );\n const report = await probeOpenAiCapacity({\n checkedAt,\n env: { OPENAI_API_KEY: \"request-test-key\" },\n fetch,\n });\n const query = \"start_time=1789812000&end_time=1790416800\";\n expect(fetch).toHaveBeenCalledTimes(2);\n expect(fetch).toHaveBeenCalledWith(\n `https://api.openai.com/v1/organization/usage/completions?${query}`,\n expect.objectContaining({\n method: \"GET\",\n headers: { Authorization: \"Bearer request-test-key\" },\n }),\n );\n expect(fetch).toHaveBeenCalledWith(\n `https://api.openai.com/v1/organization/usage/responses?${query}`,\n expect.objectContaining({\n headers: { Authorization: \"Bearer request-test-key\" },\n }),\n );\n expect(report.windows.map((window) => window.current)).toEqual([2000, 13000]);\n expect(JSON.stringify(report)).not.toContain(\"request-test-key\");\n });\n\n it(\"reports unauthenticated for rejected keys\", async () => {\n const report = await probeOpenAiCapacity({\n checkedAt,\n env: { OPENAI_API_KEY: \"rejected-key\" },\n fetch: vi.fn(async () => new Response(\"denied\", { status: 401 })),\n });\n expect(report).toMatchObject({\n authenticated: false,\n available: \"unknown\",\n windows: [],\n creditsRemaining: null,\n });\n });\n\n it(\"degrades to authentication-only when usage requires an admin key\", async () => {\n const fetch = vi.fn(async (url: string) =>\n url.endsWith(\"/models\")\n ? new Response(\"{}\", { status: 200 })\n : new Response(\"forbidden\", { status: 403 }),\n );\n const report = await probeOpenAiCapacity({\n checkedAt,\n env: { OPENAI_API_KEY: \"member-key\" },\n fetch,\n });\n expect(fetch).toHaveBeenCalledWith(\n \"https://api.openai.com/v1/models\",\n expect.objectContaining({\n headers: { Authorization: \"Bearer member-key\" },\n }),\n );\n expect(report).toMatchObject({\n authenticated: true,\n available: \"unknown\",\n windows: [],\n });\n });\n\n it(\"falls back to unauthenticated when the degraded check rejects the key\", async () => {\n const fetch = vi.fn(async (url: string) =>\n url.endsWith(\"/models\")\n ? new Response(\"denied\", { status: 401 })\n : new Response(\"forbidden\", { status: 403 }),\n );\n const report = await probeOpenAiCapacity({\n checkedAt,\n env: { OPENAI_API_KEY: \"revoked-key\" },\n fetch,\n });\n expect(report).toMatchObject({ authenticated: false, windows: [] });\n });\n\n it(\"sanitizes network failures on the platform key path\", async () => {\n await expect(\n probeOpenAiCapacity({\n checkedAt,\n env: { OPENAI_API_KEY: \"network-key\" },\n fetch: vi.fn(async () => Promise.reject(new Error(\"ECONNRESET secret\"))),\n }),\n ).rejects.toThrow(\"OpenAI usage request failed\");\n await expect(\n probeOpenAiCapacity({\n checkedAt,\n env: { OPENAI_API_KEY: \"network-key\" },\n fetch: vi.fn(async (url: string) =>\n url.endsWith(\"/models\")\n ? Promise.reject(new Error(\"ECONNRESET secret\"))\n : new Response(\"forbidden\", { status: 403 }),\n ),\n }),\n ).rejects.toThrow(\"OpenAI usage request failed\");\n });\n\n it(\"rejects other statuses and malformed JSON responses with sanitized errors\", async () => {\n await expect(\n probeOpenAiCapacity({\n checkedAt,\n env: { OPENAI_API_KEY: \"never-expose-this-key\" },\n fetch: vi.fn(async () => new Response(\"private body\", { status: 503 })),\n }),\n ).rejects.toThrow(\"OpenAI usage request failed: HTTP 503\");\n await expect(\n probeOpenAiCapacity({\n checkedAt,\n env: { OPENAI_API_KEY: \"never-expose-this-key\" },\n fetch: vi.fn(async () => new Response(\"not-json\", { status: 200 })),\n }),\n ).rejects.toThrow(\"OpenAI usage response is not valid JSON\");\n });\n});\n"],"names":["readFile","readFileSync","fileURLToPath","describe","expect","it","vi","buildOpenAiReport","parseOpenAiUsage","probeOpenAiCapacity","resolveOpenAiApiKey","resolveOpenAiCredential","checkedAt","fixture","name","URL","url","fixtureString","readAuth","fn","env","OPENAI_API_KEY","resolves","toBe","not","toHaveBeenCalled","HOME","toHaveBeenCalledWith","each","Promise","reject","Object","assign","Error","code","JSON","stringify","openai","type","key","_name","rejects","toThrow","oauthFixture","bothCredentials","access","refresh","expires","accountId","toEqual","kind","expiresMs","auth","toMatchObject","freshOauth","whamResponse","Response","status","fetch","report","objectContaining","method","headers","Authorization","harness","provider","generatedAt","authenticated","available","creditsRemaining","windows","map","window","id","toContain","staleAuth","expiredJwtAuth","noFetch","futureJwtAuth","toHaveBeenCalledOnce","probe","timeoutMs","_url","init","_resolve","signal","addEventListener","error","String","buckets","parse","startMs","tokens","object","data","aggregation_timestamp","results","label","limitType","durationMinutes","usedPercent","resetsAt","total","current","remaining","includes","query","toHaveBeenCalledTimes","endsWith"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,mBAAmB;AAC5C,SAASC,YAAY,QAAQ,UAAU;AACvC,SAASC,aAAa,QAAQ,WAAW;AACzC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAS;AAClD,SACEC,iBAAiB,EACjBC,gBAAgB,EAChBC,mBAAmB,EACnBC,mBAAmB,EACnBC,uBAAuB,QAClB,2BAA2B;AAElC,MAAMC,YAAY;AAClB,MAAMC,UAAU,CAACC,OACfd,SAASE,cAAc,IAAIa,IAAI,CAAC,WAAW,EAAED,MAAM,EAAE,YAAYE,GAAG,IAAI;AAC1E,MAAMC,gBAAgB,CAACH,OACrBb,aAAaC,cAAc,IAAIa,IAAI,CAAC,WAAW,EAAED,MAAM,EAAE,YAAYE,GAAG,IAAI;AAE9Eb,SAAS,gCAAgC;IACvCE,GAAG,kDAAkD;QACnD,MAA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YAC/CqC,OAAOpD,GAAGa,EAAE,CAAC,UAAY,IAAIqC,SAAS,YAAY;oBAAEC,QAAQ;gBAAI;QAClE,IACAhB,OAAO,CAACC,OAAO,CAAC;IACpB;AACF"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { parseWhamUsage, toRateWindow } from "../../capacity/wham.js";
|
|
5
|
+
const fixture = (name)=>readFile(fileURLToPath(new URL(`./fixtures/${name}`, import.meta.url)), "utf8");
|
|
6
|
+
describe("wham usage parsing", ()=>{
|
|
7
|
+
it("maps primary and secondary rate windows onto session and weekly", async ()=>{
|
|
8
|
+
const snapshot = parseWhamUsage(JSON.parse(await fixture("wham-usage.json")));
|
|
9
|
+
expect(snapshot.windows).toEqual([
|
|
10
|
+
{
|
|
11
|
+
id: "session",
|
|
12
|
+
label: "Session",
|
|
13
|
+
durationMinutes: 300,
|
|
14
|
+
usedPercent: 12.5,
|
|
15
|
+
resetsAt: "2026-09-27T13:52:07.000Z"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
id: "weekly",
|
|
19
|
+
label: "Weekly",
|
|
20
|
+
durationMinutes: 10080,
|
|
21
|
+
usedPercent: 43.2,
|
|
22
|
+
resetsAt: "2026-10-04T08:52:07.000Z"
|
|
23
|
+
}
|
|
24
|
+
]);
|
|
25
|
+
expect(snapshot.creditsRemaining).toBe(4.5);
|
|
26
|
+
});
|
|
27
|
+
it("accepts epoch seconds and ISO strings for reset_at", ()=>{
|
|
28
|
+
expect(toRateWindow({
|
|
29
|
+
used_percent: 1,
|
|
30
|
+
reset_at: 1_787_220_000
|
|
31
|
+
}, "a", "A")?.resetsAt).toBe("2026-08-20T10:00:00.000Z");
|
|
32
|
+
expect(toRateWindow({
|
|
33
|
+
used_percent: 1,
|
|
34
|
+
reset_at: "2026-08-20T10:00:00Z"
|
|
35
|
+
}, "a", "A")?.resetsAt).toBe("2026-08-20T10:00:00.000Z");
|
|
36
|
+
expect(toRateWindow({
|
|
37
|
+
used_percent: 1,
|
|
38
|
+
reset_at: "nope"
|
|
39
|
+
}, "a", "A")?.resetsAt).toBeNull();
|
|
40
|
+
});
|
|
41
|
+
it("maps additional_rate_limits into scoped windows and tolerates non-array values", ()=>{
|
|
42
|
+
const scoped = parseWhamUsage({
|
|
43
|
+
rate_limit: {},
|
|
44
|
+
additional_rate_limits: [
|
|
45
|
+
{
|
|
46
|
+
limit_name: "code-review",
|
|
47
|
+
rate_limit: {
|
|
48
|
+
primary_window: {
|
|
49
|
+
used_percent: 10,
|
|
50
|
+
limit_window_seconds: 3600,
|
|
51
|
+
reset_at: 100
|
|
52
|
+
},
|
|
53
|
+
secondary_window: {
|
|
54
|
+
used_percent: 20,
|
|
55
|
+
limit_window_seconds: 7200,
|
|
56
|
+
reset_at: 200
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
});
|
|
62
|
+
expect(scoped.windows.map((window)=>window.id)).toEqual([
|
|
63
|
+
"code-review:primary",
|
|
64
|
+
"code-review:secondary"
|
|
65
|
+
]);
|
|
66
|
+
expect(parseWhamUsage({
|
|
67
|
+
additional_rate_limits: null
|
|
68
|
+
}).windows).toEqual([]);
|
|
69
|
+
});
|
|
70
|
+
it("falls back to positional ids and inline windows for degraded extra limits", ()=>{
|
|
71
|
+
const scoped = parseWhamUsage({
|
|
72
|
+
additional_rate_limits: [
|
|
73
|
+
null,
|
|
74
|
+
42,
|
|
75
|
+
{
|
|
76
|
+
primary_window: {
|
|
77
|
+
used_percent: 5
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
limit_name: "not/safe",
|
|
82
|
+
primary_window: {
|
|
83
|
+
used_percent: 6
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
limit_name: "token-123456",
|
|
88
|
+
primary_window: {
|
|
89
|
+
used_percent: 7
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
limit_name: "ok",
|
|
94
|
+
secondary_window: {
|
|
95
|
+
used_percent: 8
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
});
|
|
100
|
+
expect(scoped.windows.map((window)=>window.id)).toEqual([
|
|
101
|
+
"extra-3:primary",
|
|
102
|
+
"extra-4:primary",
|
|
103
|
+
"extra-5:primary",
|
|
104
|
+
"ok:secondary"
|
|
105
|
+
]);
|
|
106
|
+
});
|
|
107
|
+
it("parses non-object payloads into an empty snapshot", ()=>{
|
|
108
|
+
expect(parseWhamUsage(null)).toEqual({
|
|
109
|
+
windows: [],
|
|
110
|
+
creditsRemaining: null
|
|
111
|
+
});
|
|
112
|
+
expect(parseWhamUsage(42)).toEqual({
|
|
113
|
+
windows: [],
|
|
114
|
+
creditsRemaining: null
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
it("never invents usage for windows it cannot parse", ()=>{
|
|
118
|
+
const snapshot = parseWhamUsage({
|
|
119
|
+
rate_limit: {
|
|
120
|
+
primary_window: {
|
|
121
|
+
limit_window_seconds: 18000
|
|
122
|
+
},
|
|
123
|
+
secondary_window: null
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
expect(snapshot.windows).toEqual([
|
|
127
|
+
{
|
|
128
|
+
id: "session",
|
|
129
|
+
label: "Session",
|
|
130
|
+
durationMinutes: 300,
|
|
131
|
+
usedPercent: null,
|
|
132
|
+
resetsAt: null
|
|
133
|
+
}
|
|
134
|
+
]);
|
|
135
|
+
expect(parseWhamUsage({}).creditsRemaining).toBeNull();
|
|
136
|
+
expect(parseWhamUsage({
|
|
137
|
+
credits: {
|
|
138
|
+
balance: "nan"
|
|
139
|
+
}
|
|
140
|
+
}).creditsRemaining).toBeNull();
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=wham.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/__tests__/capacity/wham.test.ts"],"sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport { fileURLToPath } from \"node:url\";\nimport { describe, expect, it } from \"vitest\";\nimport { parseWhamUsage, toRateWindow } from \"../../capacity/wham.js\";\n\nconst fixture = (name: string) =>\n readFile(fileURLToPath(new URL(`./fixtures/${name}`, import.meta.url)), \"utf8\");\n\ndescribe(\"wham usage parsing\", () => {\n it(\"maps primary and secondary rate windows onto session and weekly\", async () => {\n const snapshot = parseWhamUsage(JSON.parse(await fixture(\"wham-usage.json\")));\n expect(snapshot.windows).toEqual([\n {\n id: \"session\",\n label: \"Session\",\n durationMinutes: 300,\n usedPercent: 12.5,\n resetsAt: \"2026-09-27T13:52:07.000Z\",\n },\n {\n id: \"weekly\",\n label: \"Weekly\",\n durationMinutes: 10080,\n usedPercent: 43.2,\n resetsAt: \"2026-10-04T08:52:07.000Z\",\n },\n ]);\n expect(snapshot.creditsRemaining).toBe(4.5);\n });\n\n it(\"accepts epoch seconds and ISO strings for reset_at\", () => {\n expect(toRateWindow({ used_percent: 1, reset_at: 1_787_220_000 }, \"a\", \"A\")?.resetsAt).toBe(\n \"2026-08-20T10:00:00.000Z\",\n );\n expect(\n toRateWindow({ used_percent: 1, reset_at: \"2026-08-20T10:00:00Z\" }, \"a\", \"A\")?.resetsAt,\n ).toBe(\"2026-08-20T10:00:00.000Z\");\n expect(toRateWindow({ used_percent: 1, reset_at: \"nope\" }, \"a\", \"A\")?.resetsAt).toBeNull();\n });\n\n it(\"maps additional_rate_limits into scoped windows and tolerates non-array values\", () => {\n const scoped = parseWhamUsage({\n rate_limit: {},\n additional_rate_limits: [\n {\n limit_name: \"code-review\",\n rate_limit: {\n primary_window: { used_percent: 10, limit_window_seconds: 3600, reset_at: 100 },\n secondary_window: { used_percent: 20, limit_window_seconds: 7200, reset_at: 200 },\n },\n },\n ],\n });\n expect(scoped.windows.map((window) => window.id)).toEqual([\n \"code-review:primary\",\n \"code-review:secondary\",\n ]);\n expect(parseWhamUsage({ additional_rate_limits: null }).windows).toEqual([]);\n });\n\n it(\"falls back to positional ids and inline windows for degraded extra limits\", () => {\n const scoped = parseWhamUsage({\n additional_rate_limits: [\n null,\n 42,\n { primary_window: { used_percent: 5 } },\n { limit_name: \"not/safe\", primary_window: { used_percent: 6 } },\n { limit_name: \"token-123456\", primary_window: { used_percent: 7 } },\n { limit_name: \"ok\", secondary_window: { used_percent: 8 } },\n ],\n });\n expect(scoped.windows.map((window) => window.id)).toEqual([\n \"extra-3:primary\",\n \"extra-4:primary\",\n \"extra-5:primary\",\n \"ok:secondary\",\n ]);\n });\n\n it(\"parses non-object payloads into an empty snapshot\", () => {\n expect(parseWhamUsage(null)).toEqual({ windows: [], creditsRemaining: null });\n expect(parseWhamUsage(42)).toEqual({ windows: [], creditsRemaining: null });\n });\n\n it(\"never invents usage for windows it cannot parse\", () => {\n const snapshot = parseWhamUsage({\n rate_limit: {\n primary_window: { limit_window_seconds: 18000 },\n secondary_window: null,\n },\n });\n expect(snapshot.windows).toEqual([\n {\n id: \"session\",\n label: \"Session\",\n durationMinutes: 300,\n usedPercent: null,\n resetsAt: null,\n },\n ]);\n expect(parseWhamUsage({}).creditsRemaining).toBeNull();\n expect(parseWhamUsage({ credits: { balance: \"nan\" } }).creditsRemaining).toBeNull();\n });\n});\n"],"names":["readFile","fileURLToPath","describe","expect","it","parseWhamUsage","toRateWindow","fixture","name","URL","url","snapshot","JSON","parse","windows","toEqual","id","label","durationMinutes","usedPercent","resetsAt","creditsRemaining","toBe","used_percent","reset_at","toBeNull","scoped","rate_limit","additional_rate_limits","limit_name","primary_window","limit_window_seconds","secondary_window","map","window","credits","balance"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,mBAAmB;AAC5C,SAASC,aAAa,QAAQ,WAAW;AACzC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AAC9C,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
|
18
18
|
expect(AGENTS.grok_cli.matches("/Users/dev/.grok/bin/grok --always-approve")).toBe(true);
|
|
19
19
|
expect(AGENTS.grok_cli.matches("node /repo/feature-grok-cli/script.js")).toBe(false);
|
|
20
20
|
});
|
|
21
|
+
it("includes Kiro as a startable agent", ()=>{
|
|
22
|
+
expect(AGENTS.kiro.command).toBe("kiro-cli");
|
|
23
|
+
expect(AGENTS.kiro.matches("kiro-cli")).toBe(true);
|
|
24
|
+
expect(AGENTS.kiro.matches("/usr/local/bin/kiro --model x")).toBe(true);
|
|
25
|
+
expect(AGENTS.kiro.matches("node /repo/feature-kiro-adapter/script.js")).toBe(false);
|
|
26
|
+
});
|
|
21
27
|
});
|
|
22
28
|
|
|
23
29
|
//# sourceMappingURL=agents.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/__tests__/utils/agents.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { AGENTS } from \"../../../src/utils/agents.js\";\n\ndescribe(\"AGENTS\", () => {\n it(\"includes Copilot as a startable agent\", () => {\n expect(AGENTS.copilot.command).toBe(\"copilot\");\n expect(AGENTS.copilot.matches(\"/opt/homebrew/Caskroom/copilot-cli/1.0.60/copilot\")).toBe(true);\n expect(AGENTS.copilot.matches(\"node /repo/feature-cli-copilot-cli/script.js\")).toBe(false);\n });\n\n it(\"includes Pi as a startable agent\", () => {\n expect(AGENTS.pi.command).toBe(\"pi\");\n expect(AGENTS.pi.matches(\"pi\")).toBe(true);\n expect(AGENTS.pi.matches(\"/usr/local/bin/pi --model x\")).toBe(true);\n expect(AGENTS.pi.matches(\"node /repo/feature-pi-adapter/script.js\")).toBe(false);\n });\n\n it(\"includes Grok as a startable agent\", () => {\n expect(AGENTS.grok_cli.command).toBe(\"grok\");\n expect(AGENTS.grok_cli.matches(\"grok\")).toBe(true);\n expect(AGENTS.grok_cli.matches(\"/Users/dev/.grok/bin/grok --always-approve\")).toBe(true);\n expect(AGENTS.grok_cli.matches(\"node /repo/feature-grok-cli/script.js\")).toBe(false);\n });\n});\n"],"names":["describe","expect","it","AGENTS","copilot","command","toBe","matches","pi","grok_cli"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AAC9C,SAASC,MAAM,QAAQ,+BAA+B;AAEtDH,SAAS,UAAU;IACjBE,GAAG,yCAAyC;QAC1CD,OAAOE,OAAOC,OAAO,CAACC,OAAO,EAAEC,IAAI,CAAC;QACpCL,OAAOE,OAAOC,OAAO,CAACG,OAAO,CAAC,sDAAsDD,IAAI,CAAC;QACzFL,OAAOE,OAAOC,OAAO,CAACG,OAAO,CAAC,iDAAiDD,IAAI,CAAC;IACtF;IAEAJ,GAAG,oCAAoC;QACrCD,OAAOE,OAAOK,EAAE,CAACH,OAAO,EAAEC,IAAI,CAAC;QAC/BL,OAAOE,OAAOK,EAAE,CAACD,OAAO,CAAC,OAAOD,IAAI,CAAC;QACrCL,OAAOE,OAAOK,EAAE,CAACD,OAAO,CAAC,gCAAgCD,IAAI,CAAC;QAC9DL,OAAOE,OAAOK,EAAE,CAACD,OAAO,CAAC,4CAA4CD,IAAI,CAAC;IAC5E;IAEAJ,GAAG,sCAAsC;QACvCD,OAAOE,OAAOM,QAAQ,CAACJ,OAAO,EAAEC,IAAI,CAAC;QACrCL,OAAOE,OAAOM,QAAQ,CAACF,OAAO,CAAC,SAASD,IAAI,CAAC;QAC7CL,OAAOE,OAAOM,QAAQ,CAACF,OAAO,CAAC,+CAA+CD,IAAI,CAAC;QACnFL,OAAOE,OAAOM,QAAQ,CAACF,OAAO,CAAC,0CAA0CD,IAAI,CAAC;IAChF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/__tests__/utils/agents.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport { AGENTS } from \"../../../src/utils/agents.js\";\n\ndescribe(\"AGENTS\", () => {\n it(\"includes Copilot as a startable agent\", () => {\n expect(AGENTS.copilot.command).toBe(\"copilot\");\n expect(AGENTS.copilot.matches(\"/opt/homebrew/Caskroom/copilot-cli/1.0.60/copilot\")).toBe(true);\n expect(AGENTS.copilot.matches(\"node /repo/feature-cli-copilot-cli/script.js\")).toBe(false);\n });\n\n it(\"includes Pi as a startable agent\", () => {\n expect(AGENTS.pi.command).toBe(\"pi\");\n expect(AGENTS.pi.matches(\"pi\")).toBe(true);\n expect(AGENTS.pi.matches(\"/usr/local/bin/pi --model x\")).toBe(true);\n expect(AGENTS.pi.matches(\"node /repo/feature-pi-adapter/script.js\")).toBe(false);\n });\n\n it(\"includes Grok as a startable agent\", () => {\n expect(AGENTS.grok_cli.command).toBe(\"grok\");\n expect(AGENTS.grok_cli.matches(\"grok\")).toBe(true);\n expect(AGENTS.grok_cli.matches(\"/Users/dev/.grok/bin/grok --always-approve\")).toBe(true);\n expect(AGENTS.grok_cli.matches(\"node /repo/feature-grok-cli/script.js\")).toBe(false);\n });\n\n it(\"includes Kiro as a startable agent\", () => {\n expect(AGENTS.kiro.command).toBe(\"kiro-cli\");\n expect(AGENTS.kiro.matches(\"kiro-cli\")).toBe(true);\n expect(AGENTS.kiro.matches(\"/usr/local/bin/kiro --model x\")).toBe(true);\n expect(AGENTS.kiro.matches(\"node /repo/feature-kiro-adapter/script.js\")).toBe(false);\n });\n});\n"],"names":["describe","expect","it","AGENTS","copilot","command","toBe","matches","pi","grok_cli","kiro"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AAC9C,SAASC,MAAM,QAAQ,+BAA+B;AAEtDH,SAAS,UAAU;IACjBE,GAAG,yCAAyC;QAC1CD,OAAOE,OAAOC,OAAO,CAACC,OAAO,EAAEC,IAAI,CAAC;QACpCL,OAAOE,OAAOC,OAAO,CAACG,OAAO,CAAC,sDAAsDD,IAAI,CAAC;QACzFL,OAAOE,OAAOC,OAAO,CAACG,OAAO,CAAC,iDAAiDD,IAAI,CAAC;IACtF;IAEAJ,GAAG,oCAAoC;QACrCD,OAAOE,OAAOK,EAAE,CAACH,OAAO,EAAEC,IAAI,CAAC;QAC/BL,OAAOE,OAAOK,EAAE,CAACD,OAAO,CAAC,OAAOD,IAAI,CAAC;QACrCL,OAAOE,OAAOK,EAAE,CAACD,OAAO,CAAC,gCAAgCD,IAAI,CAAC;QAC9DL,OAAOE,OAAOK,EAAE,CAACD,OAAO,CAAC,4CAA4CD,IAAI,CAAC;IAC5E;IAEAJ,GAAG,sCAAsC;QACvCD,OAAOE,OAAOM,QAAQ,CAACJ,OAAO,EAAEC,IAAI,CAAC;QACrCL,OAAOE,OAAOM,QAAQ,CAACF,OAAO,CAAC,SAASD,IAAI,CAAC;QAC7CL,OAAOE,OAAOM,QAAQ,CAACF,OAAO,CAAC,+CAA+CD,IAAI,CAAC;QACnFL,OAAOE,OAAOM,QAAQ,CAACF,OAAO,CAAC,0CAA0CD,IAAI,CAAC;IAChF;IAEAJ,GAAG,sCAAsC;QACvCD,OAAOE,OAAOO,IAAI,CAACL,OAAO,EAAEC,IAAI,CAAC;QACjCL,OAAOE,OAAOO,IAAI,CAACH,OAAO,CAAC,aAAaD,IAAI,CAAC;QAC7CL,OAAOE,OAAOO,IAAI,CAACH,OAAO,CAAC,kCAAkCD,IAAI,CAAC;QAClEL,OAAOE,OAAOO,IAAI,CAACH,OAAO,CAAC,8CAA8CD,IAAI,CAAC;IAChF;AACF"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* Type of AI agent
|
|
9
9
|
*/
|
|
10
|
-
export type AgentType = "claude" | "gemini_cli" | "grok_cli" | "codex" | "opencode" | "copilot" | "pi" | "other";
|
|
10
|
+
export type AgentType = "claude" | "gemini_cli" | "grok_cli" | "kiro" | "antigravity_cli" | "codex" | "opencode" | "copilot" | "pi" | "other";
|
|
11
11
|
/**
|
|
12
12
|
* Current status of an agent
|
|
13
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentAdapter.d.ts","s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pE;;;;OAIG;IACH,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC;IAE7C;;;;;OAKG;IACH,eAAe,CAAC,eAAe,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,mBAAmB,EAAE,CAAC;IAEjG;;;;;;;;;OASG;IACH,YAAY,CAAC,IAAI,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAEpE;;;;;;OAMG;IACH,gBAAgB,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;CACjE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/adapters/AgentAdapter.ts"],"sourcesContent":["/**\n * Agent Adapter Interface\n *\n * Defines the contract for detecting and managing different types of AI agents.\n * Each adapter is responsible for detecting agents of a specific type (e.g., claude).\n */\n\n/**\n * Type of AI agent\n */\nexport type AgentType =\n | \"claude\"\n | \"gemini_cli\"\n | \"grok_cli\"\n | \"codex\"\n | \"opencode\"\n | \"copilot\"\n | \"pi\"\n | \"other\";\n\n/**\n * Current status of an agent\n */\nexport enum AgentStatus {\n RUNNING = \"running\",\n WAITING = \"waiting\",\n IDLE = \"idle\",\n UNKNOWN = \"unknown\",\n}\n\n/**\n * Information about a detected agent\n */\nexport interface AgentInfo {\n /** Project-based name (e.g., \"ai-devkit\" or \"ai-devkit (merry)\") */\n name: string;\n\n /** Type of agent */\n type: AgentType;\n\n /** Current status */\n status: AgentStatus;\n\n /** Last user prompt from history */\n summary: string;\n\n /** Process ID */\n pid: number;\n\n /** Working directory/project path */\n projectPath: string;\n\n /** Session UUID */\n sessionId: string;\n\n /** Timestamp of last activity */\n lastActive: Date;\n\n /** Whether the live process is pinned in the agent console */\n pinned?: boolean;\n\n /** Path to the session JSONL file on disk */\n sessionFilePath?: string;\n}\n\n/**\n * Information about a running process\n */\nexport interface ProcessInfo {\n /** Process ID */\n pid: number;\n\n /** Parent process ID, populated by process discovery when available */\n ppid?: number;\n\n /** Process command */\n command: string;\n\n /** Working directory */\n cwd: string;\n\n /** Terminal TTY (e.g., \"ttys030\") */\n tty: string;\n\n /** Process start time, populated by process enrichment */\n startTime?: Date;\n}\n\n/**\n * A single message in a conversation\n */\nexport interface ConversationMessage {\n role: \"user\" | \"assistant\" | \"system\";\n content: string;\n timestamp?: string;\n}\n\n/**\n * A historical session discovered on disk (running or not).\n *\n * Used by `listSessions` to surface enough context for a user to identify\n * a session and resume it via the originating tool's resume command.\n */\nexport interface SessionSummary {\n /** Tool that produced this session */\n type: AgentType;\n\n /**\n * ID accepted by the tool's resume command. Adapters MUST pass this\n * through verbatim — no normalization, no encoding/decoding — so it\n * round-trips into `claude --resume <id>` (and equivalents).\n */\n sessionId: string;\n\n /** Working directory the session was started in (best-known value) */\n cwd: string;\n\n /**\n * Trimmed first user message; empty string if none. Adapters apply\n * the same noise-filter their existing parsers use (skip tool_result\n * blocks, request-interruption notices, system-injected skill\n * content). The CLI table renderer substitutes a placeholder for\n * empty values; JSON output keeps the empty string raw.\n */\n firstUserMessage: string;\n\n /** Last activity timestamp (from session content; falls back to file mtime) */\n lastActive: Date;\n\n /** Session start time (from session content; falls back to file birthtime/mtime) */\n startedAt: Date;\n\n /** Absolute path to the session file on disk (debug/diagnostics) */\n sessionFilePath: string;\n}\n\n/**\n * Filters passed by the CLI to {@link AgentAdapter.listSessions}.\n *\n * The CLI is the source of truth for filter defaults and semantics\n * (e.g. cwd defaults to process.cwd(); --all clears it). Adapters apply\n * the values they receive — they don't invent defaults.\n */\nexport interface ListSessionsOptions {\n /**\n * Filter to sessions whose recorded cwd matches this path using strict\n * equality (no prefix/ancestor matching in v1). Undefined = no cwd\n * filter.\n */\n cwd?: string;\n\n /**\n * Filter to a single tool. Enforced by `AgentManager.listSessions`,\n * which skips adapters whose `type` doesn't match. Adapters MAY\n * ignore this field — by the time their `listSessions` runs, the\n * type filter is already satisfied. Undefined = include every\n * registered adapter.\n */\n type?: AgentType;\n}\n\nexport interface AgentDetectionContext {\n /** One enriched process snapshot shared across this manager refresh. */\n readonly processes: readonly ProcessInfo[];\n}\n\n/**\n * Agent Adapter Interface\n *\n * Implementations must provide detection logic for a specific agent type.\n */\nexport interface AgentAdapter {\n /** Type of agent this adapter handles */\n readonly type: AgentType;\n\n /** Executable basenames required for shared process discovery. */\n readonly processNames?: readonly string[];\n\n /**\n * Detect running agents of this type\n * @returns List of detected agents\n */\n detectAgents(context?: AgentDetectionContext): Promise<AgentInfo[]>;\n\n /**\n * Check if this adapter can handle the given process\n * @param processInfo Process information\n * @returns True if this adapter can handle the process\n */\n canHandle(processInfo: ProcessInfo): boolean;\n\n /**\n * Read the full conversation from a session file\n * @param sessionFilePath Path to the session JSONL file\n * @param options.verbose Include tool call/result details\n * @returns Array of conversation messages\n */\n getConversation(sessionFilePath: string, options?: { verbose?: boolean }): ConversationMessage[];\n\n /**\n * Enumerate historical sessions for this tool from disk.\n *\n * Applies `opts.cwd` as a strict-equality filter when set. Returns\n * {@link SessionSummary} entries unsorted; sorting and global filters\n * are handled by `AgentManager` and the CLI.\n *\n * @param opts Filter options computed by the CLI\n * @returns Array of sessions discovered on disk\n */\n listSessions(opts?: ListSessionsOptions): Promise<SessionSummary[]>;\n\n /**\n * Resolve exact historical session matches without enumerating every summary.\n *\n * Built-in adapters implement this using their provider-native storage shape.\n * The method remains optional so external adapters can fall back to\n * {@link listSessions} until they adopt direct lookup.\n */\n findSessionsById?(sessionId: string): Promise<SessionSummary[]>;\n}\n"],"names":["AgentStatus"],"mappings":"AAAA;;;;;CAKC,GAED;;CAEC,
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/AgentAdapter.ts"],"sourcesContent":["/**\n * Agent Adapter Interface\n *\n * Defines the contract for detecting and managing different types of AI agents.\n * Each adapter is responsible for detecting agents of a specific type (e.g., claude).\n */\n\n/**\n * Type of AI agent\n */\nexport type AgentType =\n | \"claude\"\n | \"gemini_cli\"\n | \"grok_cli\"\n | \"kiro\"\n | \"antigravity_cli\"\n | \"codex\"\n | \"opencode\"\n | \"copilot\"\n | \"pi\"\n | \"other\";\n\n/**\n * Current status of an agent\n */\nexport enum AgentStatus {\n RUNNING = \"running\",\n WAITING = \"waiting\",\n IDLE = \"idle\",\n UNKNOWN = \"unknown\",\n}\n\n/**\n * Information about a detected agent\n */\nexport interface AgentInfo {\n /** Project-based name (e.g., \"ai-devkit\" or \"ai-devkit (merry)\") */\n name: string;\n\n /** Type of agent */\n type: AgentType;\n\n /** Current status */\n status: AgentStatus;\n\n /** Last user prompt from history */\n summary: string;\n\n /** Process ID */\n pid: number;\n\n /** Working directory/project path */\n projectPath: string;\n\n /** Session UUID */\n sessionId: string;\n\n /** Timestamp of last activity */\n lastActive: Date;\n\n /** Whether the live process is pinned in the agent console */\n pinned?: boolean;\n\n /** Path to the session JSONL file on disk */\n sessionFilePath?: string;\n}\n\n/**\n * Information about a running process\n */\nexport interface ProcessInfo {\n /** Process ID */\n pid: number;\n\n /** Parent process ID, populated by process discovery when available */\n ppid?: number;\n\n /** Process command */\n command: string;\n\n /** Working directory */\n cwd: string;\n\n /** Terminal TTY (e.g., \"ttys030\") */\n tty: string;\n\n /** Process start time, populated by process enrichment */\n startTime?: Date;\n}\n\n/**\n * A single message in a conversation\n */\nexport interface ConversationMessage {\n role: \"user\" | \"assistant\" | \"system\";\n content: string;\n timestamp?: string;\n}\n\n/**\n * A historical session discovered on disk (running or not).\n *\n * Used by `listSessions` to surface enough context for a user to identify\n * a session and resume it via the originating tool's resume command.\n */\nexport interface SessionSummary {\n /** Tool that produced this session */\n type: AgentType;\n\n /**\n * ID accepted by the tool's resume command. Adapters MUST pass this\n * through verbatim — no normalization, no encoding/decoding — so it\n * round-trips into `claude --resume <id>` (and equivalents).\n */\n sessionId: string;\n\n /** Working directory the session was started in (best-known value) */\n cwd: string;\n\n /**\n * Trimmed first user message; empty string if none. Adapters apply\n * the same noise-filter their existing parsers use (skip tool_result\n * blocks, request-interruption notices, system-injected skill\n * content). The CLI table renderer substitutes a placeholder for\n * empty values; JSON output keeps the empty string raw.\n */\n firstUserMessage: string;\n\n /** Last activity timestamp (from session content; falls back to file mtime) */\n lastActive: Date;\n\n /** Session start time (from session content; falls back to file birthtime/mtime) */\n startedAt: Date;\n\n /** Absolute path to the session file on disk (debug/diagnostics) */\n sessionFilePath: string;\n}\n\n/**\n * Filters passed by the CLI to {@link AgentAdapter.listSessions}.\n *\n * The CLI is the source of truth for filter defaults and semantics\n * (e.g. cwd defaults to process.cwd(); --all clears it). Adapters apply\n * the values they receive — they don't invent defaults.\n */\nexport interface ListSessionsOptions {\n /**\n * Filter to sessions whose recorded cwd matches this path using strict\n * equality (no prefix/ancestor matching in v1). Undefined = no cwd\n * filter.\n */\n cwd?: string;\n\n /**\n * Filter to a single tool. Enforced by `AgentManager.listSessions`,\n * which skips adapters whose `type` doesn't match. Adapters MAY\n * ignore this field — by the time their `listSessions` runs, the\n * type filter is already satisfied. Undefined = include every\n * registered adapter.\n */\n type?: AgentType;\n}\n\nexport interface AgentDetectionContext {\n /** One enriched process snapshot shared across this manager refresh. */\n readonly processes: readonly ProcessInfo[];\n}\n\n/**\n * Agent Adapter Interface\n *\n * Implementations must provide detection logic for a specific agent type.\n */\nexport interface AgentAdapter {\n /** Type of agent this adapter handles */\n readonly type: AgentType;\n\n /** Executable basenames required for shared process discovery. */\n readonly processNames?: readonly string[];\n\n /**\n * Detect running agents of this type\n * @returns List of detected agents\n */\n detectAgents(context?: AgentDetectionContext): Promise<AgentInfo[]>;\n\n /**\n * Check if this adapter can handle the given process\n * @param processInfo Process information\n * @returns True if this adapter can handle the process\n */\n canHandle(processInfo: ProcessInfo): boolean;\n\n /**\n * Read the full conversation from a session file\n * @param sessionFilePath Path to the session JSONL file\n * @param options.verbose Include tool call/result details\n * @returns Array of conversation messages\n */\n getConversation(sessionFilePath: string, options?: { verbose?: boolean }): ConversationMessage[];\n\n /**\n * Enumerate historical sessions for this tool from disk.\n *\n * Applies `opts.cwd` as a strict-equality filter when set. Returns\n * {@link SessionSummary} entries unsorted; sorting and global filters\n * are handled by `AgentManager` and the CLI.\n *\n * @param opts Filter options computed by the CLI\n * @returns Array of sessions discovered on disk\n */\n listSessions(opts?: ListSessionsOptions): Promise<SessionSummary[]>;\n\n /**\n * Resolve exact historical session matches without enumerating every summary.\n *\n * Built-in adapters implement this using their provider-native storage shape.\n * The method remains optional so external adapters can fall back to\n * {@link listSessions} until they adopt direct lookup.\n */\n findSessionsById?(sessionId: string): Promise<SessionSummary[]>;\n}\n"],"names":["AgentStatus"],"mappings":"AAAA;;;;;CAKC,GAED;;CAEC,GAaD;;CAEC,GACD,OAAO,IAAA,AAAKA,qCAAAA;;;;;WAAAA;MAKX"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { AgentAdapter, AgentInfo, ProcessInfo, ConversationMessage, SessionSummary, ListSessionsOptions } from "./AgentAdapter.js";
|
|
2
|
+
export declare class AntigravityCliAdapter implements AgentAdapter {
|
|
3
|
+
readonly type: "antigravity_cli";
|
|
4
|
+
private base;
|
|
5
|
+
constructor();
|
|
6
|
+
canHandle(processInfo: ProcessInfo): boolean;
|
|
7
|
+
private isAgyExecutable;
|
|
8
|
+
detectAgents(): Promise<AgentInfo[]>;
|
|
9
|
+
/**
|
|
10
|
+
* Read cache/last_conversations.json into a cwd -> conversationId map. The
|
|
11
|
+
* CLI rewrites this as the current conversation per workspace changes.
|
|
12
|
+
*/
|
|
13
|
+
private readRegistry;
|
|
14
|
+
private transcriptPath;
|
|
15
|
+
private mapSessionToAgent;
|
|
16
|
+
private mapProcessOnlyAgent;
|
|
17
|
+
getConversation(sessionFilePath: string, options?: {
|
|
18
|
+
verbose?: boolean;
|
|
19
|
+
}): ConversationMessage[];
|
|
20
|
+
listSessions(opts?: ListSessionsOptions): Promise<SessionSummary[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Parse a conversation into an {@link AntigravitySession} from its
|
|
23
|
+
* transcript.jsonl. Returns null when the transcript is missing — i.e. there
|
|
24
|
+
* is no real session to surface.
|
|
25
|
+
*/
|
|
26
|
+
private readSession;
|
|
27
|
+
/**
|
|
28
|
+
* Determine agent status from parsed session state.
|
|
29
|
+
*
|
|
30
|
+
* - past the idle threshold → IDLE
|
|
31
|
+
* - last transcript turn is an assistant message → WAITING (awaiting user)
|
|
32
|
+
* - otherwise (last turn was a user message, or unknown) → RUNNING
|
|
33
|
+
*/
|
|
34
|
+
private determineStatus;
|
|
35
|
+
/**
|
|
36
|
+
* Single pass over transcript.jsonl. Each line is a
|
|
37
|
+
* { source, type, created_at, content } record. User turns are
|
|
38
|
+
* `type: 'USER_INPUT'` with the real prompt wrapped in
|
|
39
|
+
* <USER_REQUEST>...</USER_REQUEST>; the model's reply is `type:
|
|
40
|
+
* 'PLANNER_RESPONSE'`. Other MODEL records (tool calls like RUN_COMMAND) and
|
|
41
|
+
* SYSTEM records (conversation history, checkpoints) are execution detail and
|
|
42
|
+
* are skipped unless verbose.
|
|
43
|
+
*/
|
|
44
|
+
private parseTranscript;
|
|
45
|
+
/** Flatten a transcript record's content (string or text-block array) to text. */
|
|
46
|
+
private extractText;
|
|
47
|
+
/**
|
|
48
|
+
* Extract the prompt inside <USER_REQUEST>...</USER_REQUEST>. Returns null when
|
|
49
|
+
* the record has no such tag (context injection rather than a prompt). Falls
|
|
50
|
+
* back to the trimmed text when a USER_INPUT record has no wrapper.
|
|
51
|
+
*/
|
|
52
|
+
private extractUserRequest;
|
|
53
|
+
/** Resolve a conversation dir, transcript path, or bare id to the transcript file. */
|
|
54
|
+
private resolveTranscriptPath;
|
|
55
|
+
private parseTimestamp;
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=AntigravityCliAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AntigravityCliAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/AntigravityCliAdapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AA6D3B,qBAAa,qBAAsB,YAAW,YAAY;IACxD,QAAQ,CAAC,IAAI,EAAG,iBAAiB,CAAU;IAE3C,OAAO,CAAC,IAAI,CAAS;;IASrB,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO;IAI5C,OAAO,CAAC,eAAe;IAMjB,YAAY,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IA0B1C;;;OAGG;IACH,OAAO,CAAC,YAAY;IAqBpB,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,mBAAmB;IAc3B,eAAe,CAAC,eAAe,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,mBAAmB,EAAE;IAO1F,YAAY,CAAC,IAAI,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IA0BzE;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAoBnB;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;IAWvB;;;;;;;;OAQG;IACH,OAAO,CAAC,eAAe;IAqDvB,kFAAkF;IAClF,OAAO,CAAC,WAAW;IAgBnB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAO1B,sFAAsF;IACtF,OAAO,CAAC,qBAAqB;IAO7B,OAAO,CAAC,cAAc;CAKvB"}
|