@app-vitals/agent-admin 1.52.0 → 1.52.1
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@app-vitals/agent-admin",
|
|
3
|
-
"version": "1.52.
|
|
3
|
+
"version": "1.52.1",
|
|
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.52.
|
|
45
|
+
"@app-vitals/agent-lib": "1.52.1",
|
|
46
46
|
"@hono/zod-openapi": "^1.0.0",
|
|
47
47
|
"@prisma/adapter-pg": "^7.10.0",
|
|
48
48
|
"@prisma/client": "^7.10.0",
|
|
@@ -577,6 +577,95 @@ describeOrSkip("AgentCronJobService (integration)", () => {
|
|
|
577
577
|
expect(systemJobs.length).toBe(FIXTURE_CRONS.length);
|
|
578
578
|
});
|
|
579
579
|
|
|
580
|
+
// Coding -> specialist shape: an orphan parent whose children are also
|
|
581
|
+
// orphans. parentCron is onDelete: Cascade, so a per-row delete of a child
|
|
582
|
+
// after its parent was deleted used to throw.
|
|
583
|
+
async function seedOrphanLoop(agentId: string): Promise<string[]> {
|
|
584
|
+
const parent = await prisma.agentCronJob.create({
|
|
585
|
+
data: {
|
|
586
|
+
agentId,
|
|
587
|
+
name: "shipwright-loop",
|
|
588
|
+
system: true,
|
|
589
|
+
schedule: "*/30 * * * *",
|
|
590
|
+
prompt: "/shipwright:loop",
|
|
591
|
+
},
|
|
592
|
+
});
|
|
593
|
+
const ids = [parent.id];
|
|
594
|
+
for (const name of ["shipwright-dev-task", "shipwright-review"]) {
|
|
595
|
+
const child = await prisma.agentCronJob.create({
|
|
596
|
+
data: {
|
|
597
|
+
agentId,
|
|
598
|
+
name,
|
|
599
|
+
system: true,
|
|
600
|
+
schedule: "0 * * * *",
|
|
601
|
+
prompt: `/${name}`,
|
|
602
|
+
parentCronId: parent.id,
|
|
603
|
+
},
|
|
604
|
+
});
|
|
605
|
+
ids.push(child.id);
|
|
606
|
+
}
|
|
607
|
+
return ids;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
it("reconcileSystemCrons() deletes an orphan parent together with its orphan children without throwing", async () => {
|
|
611
|
+
const agentId = await createAgent(prisma);
|
|
612
|
+
const orphanIds = await seedOrphanLoop(agentId);
|
|
613
|
+
|
|
614
|
+
const result = await service.reconcileSystemCrons(agentId);
|
|
615
|
+
|
|
616
|
+
expect(result.deleted).toBe(orphanIds.length);
|
|
617
|
+
expect(result.created).toBe(FIXTURE_CRONS.length);
|
|
618
|
+
expect(
|
|
619
|
+
await prisma.agentCronJob.count({ where: { id: { in: orphanIds } } }),
|
|
620
|
+
).toBe(0);
|
|
621
|
+
const names = (await service.list(agentId)).map((j) => j.name).sort();
|
|
622
|
+
expect(names).toEqual(FIXTURE_CRONS.map((c) => c.name).sort());
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
it("reconcileSystemCrons() detaches a surviving cron whose parentCronId points at an orphan", async () => {
|
|
626
|
+
const agentId = await createAgent(prisma);
|
|
627
|
+
const orphanIds = await seedOrphanLoop(agentId);
|
|
628
|
+
const orphanParentId = orphanIds[0] as string;
|
|
629
|
+
const userCron = await prisma.agentCronJob.create({
|
|
630
|
+
data: {
|
|
631
|
+
agentId,
|
|
632
|
+
name: "my-cron",
|
|
633
|
+
system: false,
|
|
634
|
+
schedule: "0 3 * * *",
|
|
635
|
+
prompt: "/mine",
|
|
636
|
+
parentCronId: orphanParentId,
|
|
637
|
+
},
|
|
638
|
+
});
|
|
639
|
+
// A system cron that is still a default, also linked to the orphan.
|
|
640
|
+
const defaultCron = await prisma.agentCronJob.create({
|
|
641
|
+
data: {
|
|
642
|
+
agentId,
|
|
643
|
+
name: "fixture-standalone",
|
|
644
|
+
system: true,
|
|
645
|
+
schedule: "0 7 * * 1",
|
|
646
|
+
prompt: "/fixture:standalone\n/fixture:follow-up",
|
|
647
|
+
parentCronId: orphanParentId,
|
|
648
|
+
},
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
const result = await service.reconcileSystemCrons(agentId);
|
|
652
|
+
|
|
653
|
+
expect(result.deleted).toBe(orphanIds.length);
|
|
654
|
+
expect(
|
|
655
|
+
await prisma.agentCronJob.count({ where: { id: { in: orphanIds } } }),
|
|
656
|
+
).toBe(0);
|
|
657
|
+
const userAfter = await prisma.agentCronJob.findUnique({
|
|
658
|
+
where: { id: userCron.id },
|
|
659
|
+
});
|
|
660
|
+
expect(userAfter).not.toBeNull();
|
|
661
|
+
expect(userAfter?.parentCronId).toBeNull();
|
|
662
|
+
const defaultAfter = await prisma.agentCronJob.findUnique({
|
|
663
|
+
where: { id: defaultCron.id },
|
|
664
|
+
});
|
|
665
|
+
expect(defaultAfter).not.toBeNull();
|
|
666
|
+
expect(defaultAfter?.parentCronId).toBeNull();
|
|
667
|
+
});
|
|
668
|
+
|
|
580
669
|
it("reconcileSystemCrons() for an unknown specialty changes nothing (no fallback)", async () => {
|
|
581
670
|
const agentId = await createAgent(prisma, "Renamed Agent", "renamed-type");
|
|
582
671
|
|
package/src/agent-cron-jobs.ts
CHANGED
|
@@ -666,11 +666,27 @@ export async function applySystemCronDefaults(
|
|
|
666
666
|
}
|
|
667
667
|
|
|
668
668
|
// Orphan pass: delete any system cron whose name is not in the defaults.
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
669
|
+
// parentCron is onDelete: Cascade, so deleting an orphan parent would
|
|
670
|
+
// cascade to its children — and a per-row delete of an already-cascaded
|
|
671
|
+
// child throws. Detach survivors first, then delete the orphan set in one
|
|
672
|
+
// statement.
|
|
673
|
+
const orphanIds = existingSystemCrons
|
|
674
|
+
.filter((cron) => !cron.name || !systemCronNames.has(cron.name))
|
|
675
|
+
.map((cron) => cron.id);
|
|
676
|
+
|
|
677
|
+
if (orphanIds.length > 0) {
|
|
678
|
+
await tx.agentCronJob.updateMany({
|
|
679
|
+
where: {
|
|
680
|
+
agentId,
|
|
681
|
+
parentCronId: { in: orphanIds },
|
|
682
|
+
id: { notIn: orphanIds },
|
|
683
|
+
},
|
|
684
|
+
data: { parentCronId: null },
|
|
685
|
+
});
|
|
686
|
+
const result = await tx.agentCronJob.deleteMany({
|
|
687
|
+
where: { agentId, id: { in: orphanIds } },
|
|
688
|
+
});
|
|
689
|
+
deleted = result.count;
|
|
674
690
|
}
|
|
675
691
|
|
|
676
692
|
return { created, updated, deleted };
|
|
@@ -97,7 +97,7 @@ type FakeCronRow = AgentCronJob;
|
|
|
97
97
|
* In-memory prisma double covering only what reconcileSystemCrons() touches:
|
|
98
98
|
* agent.findUnique (specialty resolution),
|
|
99
99
|
* agentCronJob.findMany, and a $transaction exposing
|
|
100
|
-
* agentCronJob.{create,update,delete}.
|
|
100
|
+
* agentCronJob.{create,update,delete,updateMany,deleteMany}.
|
|
101
101
|
*/
|
|
102
102
|
function makeFakePrisma(opts: {
|
|
103
103
|
specialty: string;
|
|
@@ -191,6 +191,48 @@ function makeFakePrisma(opts: {
|
|
|
191
191
|
rows.delete(where.id);
|
|
192
192
|
return row;
|
|
193
193
|
},
|
|
194
|
+
async updateMany({
|
|
195
|
+
where,
|
|
196
|
+
data,
|
|
197
|
+
}: {
|
|
198
|
+
where: {
|
|
199
|
+
agentId?: string;
|
|
200
|
+
parentCronId?: { in: string[] };
|
|
201
|
+
id?: { notIn: string[] };
|
|
202
|
+
};
|
|
203
|
+
data: Partial<FakeCronRow>;
|
|
204
|
+
}): Promise<{ count: number }> {
|
|
205
|
+
let count = 0;
|
|
206
|
+
for (const [id, row] of rows) {
|
|
207
|
+
if (where.agentId !== undefined && row.agentId !== where.agentId)
|
|
208
|
+
continue;
|
|
209
|
+
if (
|
|
210
|
+
where.parentCronId &&
|
|
211
|
+
!where.parentCronId.in.includes(row.parentCronId ?? "")
|
|
212
|
+
)
|
|
213
|
+
continue;
|
|
214
|
+
if (where.id && where.id.notIn.includes(id)) continue;
|
|
215
|
+
rows.set(id, { ...row, ...data } as FakeCronRow);
|
|
216
|
+
count++;
|
|
217
|
+
}
|
|
218
|
+
return { count };
|
|
219
|
+
},
|
|
220
|
+
async deleteMany({
|
|
221
|
+
where,
|
|
222
|
+
}: {
|
|
223
|
+
where: { agentId?: string; id: { in: string[] } };
|
|
224
|
+
}): Promise<{ count: number }> {
|
|
225
|
+
let count = 0;
|
|
226
|
+
for (const id of where.id.in) {
|
|
227
|
+
const row = rows.get(id);
|
|
228
|
+
if (!row) continue;
|
|
229
|
+
if (where.agentId !== undefined && row.agentId !== where.agentId)
|
|
230
|
+
continue;
|
|
231
|
+
rows.delete(id);
|
|
232
|
+
count++;
|
|
233
|
+
}
|
|
234
|
+
return { count };
|
|
235
|
+
},
|
|
194
236
|
};
|
|
195
237
|
|
|
196
238
|
const agent = {
|
|
@@ -624,6 +624,47 @@ describeOrSkip("AgentTemplateReconcileService (integration)", () => {
|
|
|
624
624
|
expect(crons).toEqual([]); // fx-loop was FIXTURE's system cron
|
|
625
625
|
});
|
|
626
626
|
|
|
627
|
+
it("deletes an orphan system-cron parent with its children and detaches survivors", async () => {
|
|
628
|
+
const agentId = await agent();
|
|
629
|
+
const parent = await prisma.agentCronJob.create({
|
|
630
|
+
data: {
|
|
631
|
+
agentId,
|
|
632
|
+
name: "shipwright-loop",
|
|
633
|
+
system: true,
|
|
634
|
+
schedule: "*/30 * * * *",
|
|
635
|
+
prompt: "/shipwright:loop",
|
|
636
|
+
},
|
|
637
|
+
});
|
|
638
|
+
for (const name of ["shipwright-dev-task", "shipwright-review"]) {
|
|
639
|
+
await prisma.agentCronJob.create({
|
|
640
|
+
data: {
|
|
641
|
+
agentId,
|
|
642
|
+
name,
|
|
643
|
+
system: true,
|
|
644
|
+
schedule: "0 * * * *",
|
|
645
|
+
prompt: `/${name}`,
|
|
646
|
+
parentCronId: parent.id,
|
|
647
|
+
},
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
const userCron = await prisma.agentCronJob.create({
|
|
651
|
+
data: {
|
|
652
|
+
agentId,
|
|
653
|
+
name: "my-cron",
|
|
654
|
+
system: false,
|
|
655
|
+
schedule: "0 3 * * *",
|
|
656
|
+
prompt: "/mine",
|
|
657
|
+
parentCronId: parent.id,
|
|
658
|
+
},
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
await service.reconcile(agentId);
|
|
662
|
+
|
|
663
|
+
const rows = await prisma.agentCronJob.findMany({ where: { agentId } });
|
|
664
|
+
expect(rows.map((r) => r.name).sort()).toEqual(["fx-loop", "my-cron"]);
|
|
665
|
+
expect(rows.find((r) => r.id === userCron.id)?.parentCronId).toBeNull();
|
|
666
|
+
});
|
|
667
|
+
|
|
627
668
|
it("a template cron named like a specialty system cron overrides it in place", async () => {
|
|
628
669
|
const agentId = await agent();
|
|
629
670
|
await service.reconcile(agentId);
|
|
@@ -158,6 +158,31 @@ describeOrSkip("PATCH /agents/:id specialty (integration)", () => {
|
|
|
158
158
|
},
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
|
+
// Loop crons: a parent and children linked via parentCronId. Deleting the
|
|
162
|
+
// parent cascades to the children, which the orphan pass must tolerate.
|
|
163
|
+
const loop = await prisma.agentCronJob.create({
|
|
164
|
+
data: {
|
|
165
|
+
agentId: agent.id,
|
|
166
|
+
name: "shipwright-loop",
|
|
167
|
+
system: true,
|
|
168
|
+
schedule: "*/30 * * * *",
|
|
169
|
+
prompt: "/shipwright:loop",
|
|
170
|
+
enabled: false,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
for (const name of ["shipwright-loop-dev", "shipwright-loop-review"]) {
|
|
174
|
+
await prisma.agentCronJob.create({
|
|
175
|
+
data: {
|
|
176
|
+
agentId: agent.id,
|
|
177
|
+
name,
|
|
178
|
+
system: true,
|
|
179
|
+
schedule: "0 * * * *",
|
|
180
|
+
prompt: `/${name}`,
|
|
181
|
+
enabled: false,
|
|
182
|
+
parentCronId: loop.id,
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
}
|
|
161
186
|
const userCron = await prisma.agentCronJob.create({
|
|
162
187
|
data: {
|
|
163
188
|
agentId: agent.id,
|
|
@@ -191,7 +216,9 @@ describeOrSkip("PATCH /agents/:id specialty (integration)", () => {
|
|
|
191
216
|
});
|
|
192
217
|
|
|
193
218
|
expect(res.status).toBe(200);
|
|
194
|
-
|
|
219
|
+
const body = await res.json();
|
|
220
|
+
expect(body.specialty).toBe("specialist");
|
|
221
|
+
expect(body.warning).toBeUndefined();
|
|
195
222
|
const row = await prisma.agent.findUniqueOrThrow({
|
|
196
223
|
where: { id: agent.id },
|
|
197
224
|
});
|