@app-vitals/agent-admin 1.36.2 → 1.38.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/openapi.json CHANGED
@@ -3490,6 +3490,11 @@
3490
3490
  "type": "boolean",
3491
3491
  "description": "Reserved for the repo-access check (COS-44.1).",
3492
3492
  "example": false
3493
+ },
3494
+ "loopTranscriptUpload": {
3495
+ "type": "boolean",
3496
+ "description": "True when SHIPWRIGHT_TRANSCRIPT_API_ENABLED is on and this agent is listed in SHIPWRIGHT_LOOP_TRANSCRIPT_AGENT_IDS: coding-loop runs may upload a redacted transcript through the extension capability.",
3497
+ "example": false
3493
3498
  }
3494
3499
  },
3495
3500
  "required": [
@@ -3731,6 +3731,11 @@
3731
3731
  "type": "boolean",
3732
3732
  "description": "Reserved for the repo-access check (COS-44.1).",
3733
3733
  "example": false
3734
+ },
3735
+ "loopTranscriptUpload": {
3736
+ "type": "boolean",
3737
+ "description": "True when SHIPWRIGHT_TRANSCRIPT_API_ENABLED is on and this agent is listed in SHIPWRIGHT_LOOP_TRANSCRIPT_AGENT_IDS: coding-loop runs may upload a redacted transcript through the extension capability.",
3738
+ "example": false
3734
3739
  }
3735
3740
  },
3736
3741
  "required": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.36.2",
3
+ "version": "1.38.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@anthropic-ai/sdk": "0.135.0",
45
- "@app-vitals/agent-lib": "1.36.2",
45
+ "@app-vitals/agent-lib": "1.38.0",
46
46
  "@hono/zod-openapi": "^1.0.0",
47
47
  "@prisma/adapter-pg": "^7.10.0",
48
48
  "@prisma/client": "^7.10.0",
package/src/admin-boot.ts CHANGED
@@ -456,6 +456,7 @@ export async function startAdmin(
456
456
  agentTokenService,
457
457
  anthropicFederationEnabled,
458
458
  transcriptUploadEnabled: transcriptConfig.enabled,
459
+ loopTranscriptAgentIds: transcriptConfig.loopAgentIds,
459
460
  repoAccessCheckEnabled: repoAccessConfig.enabled,
460
461
  });
461
462
 
@@ -959,6 +959,92 @@ describeOrSkip("AgentCronRunService (integration)", () => {
959
959
  expect(items.some((r) => r.id === skippedWithOutcome.id)).toBe(true);
960
960
  });
961
961
 
962
+ describe("outcomes filter", () => {
963
+ async function seed() {
964
+ const agentId = await createAgent(prisma);
965
+ const cronId = await createCron(cronJobService, agentId);
966
+ const mk = (day: string, skipped: boolean, outcome: string | null) =>
967
+ runService.create(cronId, agentId, {
968
+ startedAt: new Date(`2026-01-${day}T08:00:00Z`),
969
+ skipped,
970
+ outcome,
971
+ });
972
+ const skipped = await mk("01", true, null);
973
+ const unknown = await mk("02", false, null);
974
+ const completed = await mk("03", false, "completed");
975
+ const failed = await mk("04", false, "failed");
976
+ return { agentId, ids: { skipped, unknown, completed, failed } };
977
+ }
978
+
979
+ const idsOf = (items: { id: string }[]) => items.map((r) => r.id).sort();
980
+
981
+ it("listForAgent() single outcomes value selects just that bucket", async () => {
982
+ const { agentId, ids } = await seed();
983
+ for (const key of [
984
+ "skipped",
985
+ "unknown",
986
+ "completed",
987
+ "failed",
988
+ ] as const) {
989
+ const { items, total } = await runService.listForAgent(agentId, {
990
+ outcomes: [key],
991
+ });
992
+ expect(total).toBe(1);
993
+ expect(idsOf(items)).toEqual([ids[key].id]);
994
+ }
995
+ });
996
+
997
+ it("listForAgent() multiple outcomes values are OR'd and total matches", async () => {
998
+ const { agentId, ids } = await seed();
999
+ const { items, total } = await runService.listForAgent(agentId, {
1000
+ outcomes: ["skipped", "unknown", "failed"],
1001
+ limit: 2,
1002
+ });
1003
+ expect(total).toBe(3);
1004
+ expect(items).toHaveLength(2);
1005
+ const all = await runService.listForAgent(agentId, {
1006
+ outcomes: ["skipped", "unknown", "failed"],
1007
+ });
1008
+ expect(idsOf(all.items)).toEqual(
1009
+ [ids.skipped.id, ids.unknown.id, ids.failed.id].sort(),
1010
+ );
1011
+ });
1012
+
1013
+ it("listForAgent() empty outcomes is no filter; outcomes beats outcome", async () => {
1014
+ const { agentId, ids } = await seed();
1015
+ const none = await runService.listForAgent(agentId, { outcomes: [] });
1016
+ expect(none.total).toBe(4);
1017
+ const both = await runService.listForAgent(agentId, {
1018
+ outcome: "completed",
1019
+ outcomes: ["failed"],
1020
+ });
1021
+ expect(idsOf(both.items)).toEqual([ids.failed.id]);
1022
+ });
1023
+
1024
+ it("listForAgent() legacy outcome still works", async () => {
1025
+ const { agentId, ids } = await seed();
1026
+ const { items, total } = await runService.listForAgent(agentId, {
1027
+ outcome: "completed",
1028
+ });
1029
+ expect(total).toBe(1);
1030
+ expect(idsOf(items)).toEqual([ids.completed.id]);
1031
+ });
1032
+
1033
+ it("listAcrossAgents() applies outcomes with matching total", async () => {
1034
+ const { agentId, ids } = await seed();
1035
+ const { items, total } = await runService.listAcrossAgents([agentId], {
1036
+ outcomes: ["unknown", "completed"],
1037
+ });
1038
+ expect(total).toBe(2);
1039
+ expect(idsOf(items)).toEqual([ids.unknown.id, ids.completed.id].sort());
1040
+ const single = await runService.listAcrossAgents([agentId], {
1041
+ outcomes: ["skipped"],
1042
+ });
1043
+ expect(single.total).toBe(1);
1044
+ expect(single.items[0].id).toBe(ids.skipped.id);
1045
+ });
1046
+ });
1047
+
962
1048
  it("listForAgent() never returns a second agent's runs", async () => {
963
1049
  const agentId1 = await createAgent(prisma, "Agent 1");
964
1050
  const agentId2 = await createAgent(prisma, "Agent 2");
@@ -146,6 +146,13 @@ interface ListForAgentOptions {
146
146
  * WHERE skipped = false AND outcome = value. Omitted means no filter.
147
147
  */
148
148
  outcome?: string;
149
+ /**
150
+ * Multi-select variant of `outcome`; values are OR'd. "skipped" ->
151
+ * skipped = true; "unknown" -> skipped = false AND outcome IS NULL; any
152
+ * other value -> skipped = false AND outcome = value. An empty array is no
153
+ * filter. When given, `outcomes` wins over `outcome`.
154
+ */
155
+ outcomes?: string[];
149
156
  limit?: number;
150
157
  offset?: number;
151
158
  }
@@ -171,10 +178,45 @@ interface ListAcrossAgentsOptions {
171
178
  * WHERE skipped = false AND outcome = value. Omitted means no filter.
172
179
  */
173
180
  outcome?: string;
181
+ /**
182
+ * Multi-select variant of `outcome`; values are OR'd. "skipped" ->
183
+ * skipped = true; "unknown" -> skipped = false AND outcome IS NULL; any
184
+ * other value -> skipped = false AND outcome = value. An empty array is no
185
+ * filter. When given, `outcomes` wins over `outcome`.
186
+ */
187
+ outcomes?: string[];
174
188
  limit?: number;
175
189
  offset?: number;
176
190
  }
177
191
 
192
+ /** Where-clause fragment for one outcome filter value (see `outcomes`). */
193
+ function outcomeClause(value: string): Prisma.AgentCronRunWhereInput {
194
+ if (value === "skipped") return { skipped: true };
195
+ if (value === "unknown") return { skipped: false, outcome: null };
196
+ return { skipped: false, outcome: value };
197
+ }
198
+
199
+ /**
200
+ * Translate the `outcome` / `outcomes` list options into a where fragment.
201
+ * `outcomes` (OR'd) wins over the legacy single `outcome`; an empty `outcomes`
202
+ * array is no filter (it does not fall back to `outcome`).
203
+ */
204
+ export function buildOutcomeWhere(opts?: {
205
+ outcome?: string;
206
+ outcomes?: string[];
207
+ }): Prisma.AgentCronRunWhereInput {
208
+ if (opts?.outcomes !== undefined) {
209
+ return opts.outcomes.length > 0
210
+ ? { OR: opts.outcomes.map(outcomeClause) }
211
+ : {};
212
+ }
213
+ if (opts?.outcome === "skipped") return { skipped: true };
214
+ if (opts?.outcome !== undefined) {
215
+ return { skipped: false, outcome: opts.outcome };
216
+ }
217
+ return {};
218
+ }
219
+
178
220
  export class AgentCronRunService {
179
221
  constructor(private prisma: PrismaClient) {}
180
222
 
@@ -450,12 +492,7 @@ export class AgentCronRunService {
450
492
  if (opts?.cronId) {
451
493
  where.cronId = opts.cronId;
452
494
  }
453
- if (opts?.outcome === "skipped") {
454
- where.skipped = true;
455
- } else if (opts?.outcome !== undefined) {
456
- where.skipped = false;
457
- where.outcome = opts.outcome;
458
- }
495
+ Object.assign(where, buildOutcomeWhere(opts));
459
496
 
460
497
  const [items, total] = await this.prisma.$transaction([
461
498
  this.prisma.agentCronRun.findMany({
@@ -494,12 +531,7 @@ export class AgentCronRunService {
494
531
  if (opts?.cronId) {
495
532
  where.cronId = opts.cronId;
496
533
  }
497
- if (opts?.outcome === "skipped") {
498
- where.skipped = true;
499
- } else if (opts?.outcome !== undefined) {
500
- where.skipped = false;
501
- where.outcome = opts.outcome;
502
- }
534
+ Object.assign(where, buildOutcomeWhere(opts));
503
535
 
504
536
  const [items, total] = await this.prisma.$transaction([
505
537
  this.prisma.agentCronRun.findMany({
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Unit tests for agent-cron-runs.ts's pure outcome-filter mapping
3
+ * (buildOutcomeWhere): no DB, just the where-clause shape.
4
+ */
5
+ import { describe, expect, test } from "bun:test";
6
+ import { buildOutcomeWhere } from "./agent-cron-runs.ts";
7
+
8
+ describe("buildOutcomeWhere", () => {
9
+ test("no options yields no filter", () => {
10
+ expect(buildOutcomeWhere()).toEqual({});
11
+ expect(buildOutcomeWhere({})).toEqual({});
12
+ });
13
+
14
+ test("legacy outcome: skipped matches the boolean flag only", () => {
15
+ expect(buildOutcomeWhere({ outcome: "skipped" })).toEqual({
16
+ skipped: true,
17
+ });
18
+ });
19
+
20
+ test("legacy outcome: other value requires skipped=false and equality", () => {
21
+ expect(buildOutcomeWhere({ outcome: "success" })).toEqual({
22
+ skipped: false,
23
+ outcome: "success",
24
+ });
25
+ });
26
+
27
+ test("outcomes: each value maps to its clause", () => {
28
+ expect(buildOutcomeWhere({ outcomes: ["skipped"] })).toEqual({
29
+ OR: [{ skipped: true }],
30
+ });
31
+ expect(buildOutcomeWhere({ outcomes: ["unknown"] })).toEqual({
32
+ OR: [{ skipped: false, outcome: null }],
33
+ });
34
+ expect(buildOutcomeWhere({ outcomes: ["failed"] })).toEqual({
35
+ OR: [{ skipped: false, outcome: "failed" }],
36
+ });
37
+ });
38
+
39
+ test("outcomes: multiple values are OR'd in order", () => {
40
+ expect(
41
+ buildOutcomeWhere({ outcomes: ["skipped", "unknown", "completed"] }),
42
+ ).toEqual({
43
+ OR: [
44
+ { skipped: true },
45
+ { skipped: false, outcome: null },
46
+ { skipped: false, outcome: "completed" },
47
+ ],
48
+ });
49
+ });
50
+
51
+ test("outcomes: empty array is no filter", () => {
52
+ expect(buildOutcomeWhere({ outcomes: [] })).toEqual({});
53
+ });
54
+
55
+ test("outcomes wins over outcome when both are passed", () => {
56
+ expect(
57
+ buildOutcomeWhere({ outcome: "success", outcomes: ["failed"] }),
58
+ ).toEqual({ OR: [{ skipped: false, outcome: "failed" }] });
59
+ });
60
+
61
+ test("empty outcomes still wins over outcome (no filter)", () => {
62
+ expect(buildOutcomeWhere({ outcome: "success", outcomes: [] })).toEqual({});
63
+ });
64
+ });
@@ -244,6 +244,7 @@ function buildApp(opts?: {
244
244
  cleanupMergedWorktrees?: boolean;
245
245
  cleanupAfterDays?: number;
246
246
  transcriptUploadEnabled?: boolean;
247
+ loopTranscriptAgentIds?: string[];
247
248
  repoAccessCheckEnabled?: boolean;
248
249
  }) {
249
250
  const hasAgent = opts?.hasAgent ?? true;
@@ -319,6 +320,7 @@ function buildApp(opts?: {
319
320
  sessionSecret: SESSION_SECRET,
320
321
  anthropicFederationEnabled: opts?.anthropicFederationEnabled,
321
322
  transcriptUploadEnabled: opts?.transcriptUploadEnabled,
323
+ loopTranscriptAgentIds: opts?.loopTranscriptAgentIds,
322
324
  repoAccessCheckEnabled: opts?.repoAccessCheckEnabled,
323
325
  });
324
326
  }
@@ -364,6 +366,7 @@ describe("GET /:id/config features (COS-43.1)", () => {
364
366
  expect(body.features).toEqual({
365
367
  transcriptUpload: false,
366
368
  repoAccessCheck: false,
369
+ loopTranscriptUpload: false,
367
370
  });
368
371
  });
369
372
 
@@ -374,10 +377,53 @@ describe("GET /:id/config features (COS-43.1)", () => {
374
377
  expect(body.features).toEqual({
375
378
  transcriptUpload: true,
376
379
  repoAccessCheck: false,
380
+ loopTranscriptUpload: false,
377
381
  });
378
382
  });
379
383
  });
380
384
 
385
+ describe("GET /:id/config features.loopTranscriptUpload", () => {
386
+ const loopFlag = async (opts: Parameters<typeof buildApp>[0]) => {
387
+ const res = await buildApp(opts).request(`/${KNOWN_AGENT_ID}/config`, {
388
+ headers: { Authorization: `Bearer ${VALID_ADMIN_KEY}` },
389
+ });
390
+ return (await res.json()).features.loopTranscriptUpload;
391
+ };
392
+
393
+ test("truth table: only a listed agent with the transcript flag on is true", async () => {
394
+ expect(await loopFlag({})).toBe(false);
395
+ expect(await loopFlag({ loopTranscriptAgentIds: [] })).toBe(false);
396
+ expect(
397
+ await loopFlag({
398
+ transcriptUploadEnabled: true,
399
+ loopTranscriptAgentIds: ["other-agent"],
400
+ }),
401
+ ).toBe(false);
402
+ expect(
403
+ await loopFlag({
404
+ transcriptUploadEnabled: false,
405
+ loopTranscriptAgentIds: [KNOWN_AGENT_ID],
406
+ }),
407
+ ).toBe(false);
408
+ expect(
409
+ await loopFlag({
410
+ transcriptUploadEnabled: true,
411
+ loopTranscriptAgentIds: [KNOWN_AGENT_ID],
412
+ }),
413
+ ).toBe(true);
414
+ });
415
+
416
+ test("leaves features.transcriptUpload untouched", async () => {
417
+ const res = await buildApp({
418
+ transcriptUploadEnabled: false,
419
+ loopTranscriptAgentIds: [KNOWN_AGENT_ID],
420
+ }).request(`/${KNOWN_AGENT_ID}/config`, {
421
+ headers: { Authorization: `Bearer ${VALID_ADMIN_KEY}` },
422
+ });
423
+ expect((await res.json()).features.transcriptUpload).toBe(false);
424
+ });
425
+ });
426
+
381
427
  describe("GET /:id/config features.repoAccessCheck (COS-44.1)", () => {
382
428
  test("follows the repo-access flag", async () => {
383
429
  const app = buildApp({ repoAccessCheckEnabled: true });
@@ -387,6 +433,7 @@ describe("GET /:id/config features.repoAccessCheck (COS-44.1)", () => {
387
433
  expect((await res.json()).features).toEqual({
388
434
  transcriptUpload: false,
389
435
  repoAccessCheck: true,
436
+ loopTranscriptUpload: false,
390
437
  });
391
438
  });
392
439
  });
package/src/api.ts CHANGED
@@ -108,7 +108,11 @@ export interface AgentConfigResponse {
108
108
  * COS-43.1: feature flags the runtime acts on. Optional so fixtures built
109
109
  * before it keep compiling; the live handler always populates it.
110
110
  */
111
- features?: { transcriptUpload: boolean; repoAccessCheck: boolean };
111
+ features?: {
112
+ transcriptUpload: boolean;
113
+ repoAccessCheck: boolean;
114
+ loopTranscriptUpload?: boolean;
115
+ };
112
116
  }
113
117
 
114
118
  interface AgentEnvServiceLike {
@@ -201,6 +205,12 @@ export interface AgentRuntimeDeps {
201
205
  * as `features.transcriptUpload` in the config bundle. Defaults to false.
202
206
  */
203
207
  transcriptUploadEnabled?: boolean;
208
+ /**
209
+ * SHIPWRIGHT_LOOP_TRANSCRIPT_AGENT_IDS: agent ids whose coding-loop runs
210
+ * upload transcripts. Combined with `transcriptUploadEnabled` into
211
+ * `features.loopTranscriptUpload`. Defaults to none.
212
+ */
213
+ loopTranscriptAgentIds?: readonly string[];
204
214
  /**
205
215
  * COS-44.1: SHIPWRIGHT_AGENT_REPO_ACCESS_CHECK_ENABLED is on — surfaced to the
206
216
  * runtime as `features.repoAccessCheck` in the config bundle. Defaults to false.
@@ -393,6 +403,9 @@ export function createAgentRuntimeApp(deps: AgentRuntimeDeps): OpenAPIHono {
393
403
  cleanupAfterDays: agent.cleanupAfterDays,
394
404
  features: {
395
405
  transcriptUpload: deps.transcriptUploadEnabled === true,
406
+ loopTranscriptUpload:
407
+ deps.transcriptUploadEnabled === true &&
408
+ (deps.loopTranscriptAgentIds ?? []).includes(agent.id),
396
409
  repoAccessCheck: deps.repoAccessCheckEnabled === true,
397
410
  },
398
411
  };
@@ -1104,7 +1104,9 @@ export const PutBakedMarketplacesBodySchema = z
1104
1104
 
1105
1105
  export const BakedMarketplacesResultSchema = z
1106
1106
  .object({
1107
- bakedMarketplaces: z.array(z.string()).openapi({ example: ["example-marketplace"] }),
1107
+ bakedMarketplaces: z
1108
+ .array(z.string())
1109
+ .openapi({ example: ["example-marketplace"] }),
1108
1110
  })
1109
1111
  .openapi("BakedMarketplacesResult");
1110
1112
 
@@ -1475,6 +1477,11 @@ export const AgentConfigResponseSchema = z
1475
1477
  description: "Reserved for the repo-access check (COS-44.1).",
1476
1478
  example: false,
1477
1479
  }),
1480
+ loopTranscriptUpload: z.boolean().optional().openapi({
1481
+ description:
1482
+ "True when SHIPWRIGHT_TRANSCRIPT_API_ENABLED is on and this agent is listed in SHIPWRIGHT_LOOP_TRANSCRIPT_AGENT_IDS: coding-loop runs may upload a redacted transcript through the extension capability.",
1483
+ example: false,
1484
+ }),
1478
1485
  })
1479
1486
  .optional()
1480
1487
  .openapi("AgentConfigFeatures"),
@@ -12,8 +12,19 @@ type TranscriptEnv = Readonly<Record<string, string | undefined>>;
12
12
  export interface TranscriptConfig {
13
13
  /** True only when SHIPWRIGHT_TRANSCRIPT_API_ENABLED === "enabled". */
14
14
  enabled: boolean;
15
+ /**
16
+ * Agent ids allowed to upload coding-loop run transcripts
17
+ * (SHIPWRIGHT_LOOP_TRANSCRIPT_AGENT_IDS, comma-separated). Empty by default.
18
+ */
19
+ loopAgentIds: readonly string[];
15
20
  }
16
21
 
17
22
  export function parseTranscriptConfig(env: TranscriptEnv): TranscriptConfig {
18
- return { enabled: env.SHIPWRIGHT_TRANSCRIPT_API_ENABLED === "enabled" };
23
+ return {
24
+ enabled: env.SHIPWRIGHT_TRANSCRIPT_API_ENABLED === "enabled",
25
+ loopAgentIds: (env.SHIPWRIGHT_LOOP_TRANSCRIPT_AGENT_IDS ?? "")
26
+ .split(",")
27
+ .map((id) => id.trim())
28
+ .filter(Boolean),
29
+ };
19
30
  }
@@ -30,3 +30,21 @@ describe("parseTranscriptConfig", () => {
30
30
  expect(parseTranscriptConfig({}).enabled).toBe(false);
31
31
  });
32
32
  });
33
+
34
+ describe("loop transcript allowlist", () => {
35
+ it("defaults to empty when unset or blank", () => {
36
+ expect(parseTranscriptConfig({}).loopAgentIds).toEqual([]);
37
+ expect(
38
+ parseTranscriptConfig({ SHIPWRIGHT_LOOP_TRANSCRIPT_AGENT_IDS: " , " })
39
+ .loopAgentIds,
40
+ ).toEqual([]);
41
+ });
42
+
43
+ it("parses a trimmed comma-separated list", () => {
44
+ expect(
45
+ parseTranscriptConfig({
46
+ SHIPWRIGHT_LOOP_TRANSCRIPT_AGENT_IDS: "a, b ,,c",
47
+ }).loopAgentIds,
48
+ ).toEqual(["a", "b", "c"]);
49
+ });
50
+ });