@app-vitals/agent-admin 1.41.0 → 1.43.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.
@@ -2869,6 +2869,7 @@ export const AgentEnvScalarFieldEnum = {
2869
2869
  key: 'key',
2870
2870
  value: 'value',
2871
2871
  secret: 'secret',
2872
+ enabled: 'enabled',
2872
2873
  source: 'source',
2873
2874
  createdAt: 'createdAt',
2874
2875
  updatedAt: 'updatedAt'
@@ -189,6 +189,7 @@ export const AgentEnvScalarFieldEnum = {
189
189
  key: 'key',
190
190
  value: 'value',
191
191
  secret: 'secret',
192
+ enabled: 'enabled',
192
193
  source: 'source',
193
194
  createdAt: 'createdAt',
194
195
  updatedAt: 'updatedAt'
@@ -30,6 +30,7 @@ export type AgentEnvMinAggregateOutputType = {
30
30
  key: string | null
31
31
  value: string | null
32
32
  secret: boolean | null
33
+ enabled: boolean | null
33
34
  source: string | null
34
35
  createdAt: Date | null
35
36
  updatedAt: Date | null
@@ -41,6 +42,7 @@ export type AgentEnvMaxAggregateOutputType = {
41
42
  key: string | null
42
43
  value: string | null
43
44
  secret: boolean | null
45
+ enabled: boolean | null
44
46
  source: string | null
45
47
  createdAt: Date | null
46
48
  updatedAt: Date | null
@@ -52,6 +54,7 @@ export type AgentEnvCountAggregateOutputType = {
52
54
  key: number
53
55
  value: number
54
56
  secret: number
57
+ enabled: number
55
58
  source: number
56
59
  createdAt: number
57
60
  updatedAt: number
@@ -65,6 +68,7 @@ export type AgentEnvMinAggregateInputType = {
65
68
  key?: true
66
69
  value?: true
67
70
  secret?: true
71
+ enabled?: true
68
72
  source?: true
69
73
  createdAt?: true
70
74
  updatedAt?: true
@@ -76,6 +80,7 @@ export type AgentEnvMaxAggregateInputType = {
76
80
  key?: true
77
81
  value?: true
78
82
  secret?: true
83
+ enabled?: true
79
84
  source?: true
80
85
  createdAt?: true
81
86
  updatedAt?: true
@@ -87,6 +92,7 @@ export type AgentEnvCountAggregateInputType = {
87
92
  key?: true
88
93
  value?: true
89
94
  secret?: true
95
+ enabled?: true
90
96
  source?: true
91
97
  createdAt?: true
92
98
  updatedAt?: true
@@ -171,6 +177,7 @@ export type AgentEnvGroupByOutputType = {
171
177
  key: string
172
178
  value: string
173
179
  secret: boolean
180
+ enabled: boolean
174
181
  source: string
175
182
  createdAt: Date
176
183
  updatedAt: Date
@@ -203,6 +210,7 @@ export type AgentEnvWhereInput = {
203
210
  key?: Prisma.StringFilter<"AgentEnv"> | string
204
211
  value?: Prisma.StringFilter<"AgentEnv"> | string
205
212
  secret?: Prisma.BoolFilter<"AgentEnv"> | boolean
213
+ enabled?: Prisma.BoolFilter<"AgentEnv"> | boolean
206
214
  source?: Prisma.StringFilter<"AgentEnv"> | string
207
215
  createdAt?: Prisma.DateTimeFilter<"AgentEnv"> | Date | string
208
216
  updatedAt?: Prisma.DateTimeFilter<"AgentEnv"> | Date | string
@@ -215,6 +223,7 @@ export type AgentEnvOrderByWithRelationInput = {
215
223
  key?: Prisma.SortOrder
216
224
  value?: Prisma.SortOrder
217
225
  secret?: Prisma.SortOrder
226
+ enabled?: Prisma.SortOrder
218
227
  source?: Prisma.SortOrder
219
228
  createdAt?: Prisma.SortOrder
220
229
  updatedAt?: Prisma.SortOrder
@@ -231,6 +240,7 @@ export type AgentEnvWhereUniqueInput = Prisma.AtLeast<{
231
240
  key?: Prisma.StringFilter<"AgentEnv"> | string
232
241
  value?: Prisma.StringFilter<"AgentEnv"> | string
233
242
  secret?: Prisma.BoolFilter<"AgentEnv"> | boolean
243
+ enabled?: Prisma.BoolFilter<"AgentEnv"> | boolean
234
244
  source?: Prisma.StringFilter<"AgentEnv"> | string
235
245
  createdAt?: Prisma.DateTimeFilter<"AgentEnv"> | Date | string
236
246
  updatedAt?: Prisma.DateTimeFilter<"AgentEnv"> | Date | string
@@ -243,6 +253,7 @@ export type AgentEnvOrderByWithAggregationInput = {
243
253
  key?: Prisma.SortOrder
244
254
  value?: Prisma.SortOrder
245
255
  secret?: Prisma.SortOrder
256
+ enabled?: Prisma.SortOrder
246
257
  source?: Prisma.SortOrder
247
258
  createdAt?: Prisma.SortOrder
248
259
  updatedAt?: Prisma.SortOrder
@@ -260,6 +271,7 @@ export type AgentEnvScalarWhereWithAggregatesInput = {
260
271
  key?: Prisma.StringWithAggregatesFilter<"AgentEnv"> | string
261
272
  value?: Prisma.StringWithAggregatesFilter<"AgentEnv"> | string
262
273
  secret?: Prisma.BoolWithAggregatesFilter<"AgentEnv"> | boolean
274
+ enabled?: Prisma.BoolWithAggregatesFilter<"AgentEnv"> | boolean
263
275
  source?: Prisma.StringWithAggregatesFilter<"AgentEnv"> | string
264
276
  createdAt?: Prisma.DateTimeWithAggregatesFilter<"AgentEnv"> | Date | string
265
277
  updatedAt?: Prisma.DateTimeWithAggregatesFilter<"AgentEnv"> | Date | string
@@ -270,6 +282,7 @@ export type AgentEnvCreateInput = {
270
282
  key: string
271
283
  value: string
272
284
  secret?: boolean
285
+ enabled?: boolean
273
286
  source?: string
274
287
  createdAt?: Date | string
275
288
  updatedAt?: Date | string
@@ -282,6 +295,7 @@ export type AgentEnvUncheckedCreateInput = {
282
295
  key: string
283
296
  value: string
284
297
  secret?: boolean
298
+ enabled?: boolean
285
299
  source?: string
286
300
  createdAt?: Date | string
287
301
  updatedAt?: Date | string
@@ -292,6 +306,7 @@ export type AgentEnvUpdateInput = {
292
306
  key?: Prisma.StringFieldUpdateOperationsInput | string
293
307
  value?: Prisma.StringFieldUpdateOperationsInput | string
294
308
  secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
309
+ enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
295
310
  source?: Prisma.StringFieldUpdateOperationsInput | string
296
311
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
297
312
  updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
@@ -304,6 +319,7 @@ export type AgentEnvUncheckedUpdateInput = {
304
319
  key?: Prisma.StringFieldUpdateOperationsInput | string
305
320
  value?: Prisma.StringFieldUpdateOperationsInput | string
306
321
  secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
322
+ enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
307
323
  source?: Prisma.StringFieldUpdateOperationsInput | string
308
324
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
309
325
  updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
@@ -315,6 +331,7 @@ export type AgentEnvCreateManyInput = {
315
331
  key: string
316
332
  value: string
317
333
  secret?: boolean
334
+ enabled?: boolean
318
335
  source?: string
319
336
  createdAt?: Date | string
320
337
  updatedAt?: Date | string
@@ -325,6 +342,7 @@ export type AgentEnvUpdateManyMutationInput = {
325
342
  key?: Prisma.StringFieldUpdateOperationsInput | string
326
343
  value?: Prisma.StringFieldUpdateOperationsInput | string
327
344
  secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
345
+ enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
328
346
  source?: Prisma.StringFieldUpdateOperationsInput | string
329
347
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
330
348
  updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
@@ -336,6 +354,7 @@ export type AgentEnvUncheckedUpdateManyInput = {
336
354
  key?: Prisma.StringFieldUpdateOperationsInput | string
337
355
  value?: Prisma.StringFieldUpdateOperationsInput | string
338
356
  secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
357
+ enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
339
358
  source?: Prisma.StringFieldUpdateOperationsInput | string
340
359
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
341
360
  updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
@@ -362,6 +381,7 @@ export type AgentEnvCountOrderByAggregateInput = {
362
381
  key?: Prisma.SortOrder
363
382
  value?: Prisma.SortOrder
364
383
  secret?: Prisma.SortOrder
384
+ enabled?: Prisma.SortOrder
365
385
  source?: Prisma.SortOrder
366
386
  createdAt?: Prisma.SortOrder
367
387
  updatedAt?: Prisma.SortOrder
@@ -373,6 +393,7 @@ export type AgentEnvMaxOrderByAggregateInput = {
373
393
  key?: Prisma.SortOrder
374
394
  value?: Prisma.SortOrder
375
395
  secret?: Prisma.SortOrder
396
+ enabled?: Prisma.SortOrder
376
397
  source?: Prisma.SortOrder
377
398
  createdAt?: Prisma.SortOrder
378
399
  updatedAt?: Prisma.SortOrder
@@ -384,6 +405,7 @@ export type AgentEnvMinOrderByAggregateInput = {
384
405
  key?: Prisma.SortOrder
385
406
  value?: Prisma.SortOrder
386
407
  secret?: Prisma.SortOrder
408
+ enabled?: Prisma.SortOrder
387
409
  source?: Prisma.SortOrder
388
410
  createdAt?: Prisma.SortOrder
389
411
  updatedAt?: Prisma.SortOrder
@@ -436,6 +458,7 @@ export type AgentEnvCreateWithoutAgentInput = {
436
458
  key: string
437
459
  value: string
438
460
  secret?: boolean
461
+ enabled?: boolean
439
462
  source?: string
440
463
  createdAt?: Date | string
441
464
  updatedAt?: Date | string
@@ -446,6 +469,7 @@ export type AgentEnvUncheckedCreateWithoutAgentInput = {
446
469
  key: string
447
470
  value: string
448
471
  secret?: boolean
472
+ enabled?: boolean
449
473
  source?: string
450
474
  createdAt?: Date | string
451
475
  updatedAt?: Date | string
@@ -486,6 +510,7 @@ export type AgentEnvScalarWhereInput = {
486
510
  key?: Prisma.StringFilter<"AgentEnv"> | string
487
511
  value?: Prisma.StringFilter<"AgentEnv"> | string
488
512
  secret?: Prisma.BoolFilter<"AgentEnv"> | boolean
513
+ enabled?: Prisma.BoolFilter<"AgentEnv"> | boolean
489
514
  source?: Prisma.StringFilter<"AgentEnv"> | string
490
515
  createdAt?: Prisma.DateTimeFilter<"AgentEnv"> | Date | string
491
516
  updatedAt?: Prisma.DateTimeFilter<"AgentEnv"> | Date | string
@@ -496,6 +521,7 @@ export type AgentEnvCreateManyAgentInput = {
496
521
  key: string
497
522
  value: string
498
523
  secret?: boolean
524
+ enabled?: boolean
499
525
  source?: string
500
526
  createdAt?: Date | string
501
527
  updatedAt?: Date | string
@@ -506,6 +532,7 @@ export type AgentEnvUpdateWithoutAgentInput = {
506
532
  key?: Prisma.StringFieldUpdateOperationsInput | string
507
533
  value?: Prisma.StringFieldUpdateOperationsInput | string
508
534
  secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
535
+ enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
509
536
  source?: Prisma.StringFieldUpdateOperationsInput | string
510
537
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
511
538
  updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
@@ -516,6 +543,7 @@ export type AgentEnvUncheckedUpdateWithoutAgentInput = {
516
543
  key?: Prisma.StringFieldUpdateOperationsInput | string
517
544
  value?: Prisma.StringFieldUpdateOperationsInput | string
518
545
  secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
546
+ enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
519
547
  source?: Prisma.StringFieldUpdateOperationsInput | string
520
548
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
521
549
  updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
@@ -526,6 +554,7 @@ export type AgentEnvUncheckedUpdateManyWithoutAgentInput = {
526
554
  key?: Prisma.StringFieldUpdateOperationsInput | string
527
555
  value?: Prisma.StringFieldUpdateOperationsInput | string
528
556
  secret?: Prisma.BoolFieldUpdateOperationsInput | boolean
557
+ enabled?: Prisma.BoolFieldUpdateOperationsInput | boolean
529
558
  source?: Prisma.StringFieldUpdateOperationsInput | string
530
559
  createdAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
531
560
  updatedAt?: Prisma.DateTimeFieldUpdateOperationsInput | Date | string
@@ -539,6 +568,7 @@ export type AgentEnvSelect<ExtArgs extends runtime.Types.Extensions.InternalArgs
539
568
  key?: boolean
540
569
  value?: boolean
541
570
  secret?: boolean
571
+ enabled?: boolean
542
572
  source?: boolean
543
573
  createdAt?: boolean
544
574
  updatedAt?: boolean
@@ -551,6 +581,7 @@ export type AgentEnvSelectCreateManyAndReturn<ExtArgs extends runtime.Types.Exte
551
581
  key?: boolean
552
582
  value?: boolean
553
583
  secret?: boolean
584
+ enabled?: boolean
554
585
  source?: boolean
555
586
  createdAt?: boolean
556
587
  updatedAt?: boolean
@@ -563,6 +594,7 @@ export type AgentEnvSelectUpdateManyAndReturn<ExtArgs extends runtime.Types.Exte
563
594
  key?: boolean
564
595
  value?: boolean
565
596
  secret?: boolean
597
+ enabled?: boolean
566
598
  source?: boolean
567
599
  createdAt?: boolean
568
600
  updatedAt?: boolean
@@ -575,12 +607,13 @@ export type AgentEnvSelectScalar = {
575
607
  key?: boolean
576
608
  value?: boolean
577
609
  secret?: boolean
610
+ enabled?: boolean
578
611
  source?: boolean
579
612
  createdAt?: boolean
580
613
  updatedAt?: boolean
581
614
  }
582
615
 
583
- export type AgentEnvOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "agentId" | "key" | "value" | "secret" | "source" | "createdAt" | "updatedAt", ExtArgs["result"]["agentEnv"]>
616
+ export type AgentEnvOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "agentId" | "key" | "value" | "secret" | "enabled" | "source" | "createdAt" | "updatedAt", ExtArgs["result"]["agentEnv"]>
584
617
  export type AgentEnvInclude<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
585
618
  agent?: boolean | Prisma.AgentDefaultArgs<ExtArgs>
586
619
  }
@@ -602,6 +635,7 @@ export type $AgentEnvPayload<ExtArgs extends runtime.Types.Extensions.InternalAr
602
635
  key: string
603
636
  value: string
604
637
  secret: boolean
638
+ enabled: boolean
605
639
  source: string
606
640
  createdAt: Date
607
641
  updatedAt: Date
@@ -1034,6 +1068,7 @@ export interface AgentEnvFieldRefs {
1034
1068
  readonly key: Prisma.FieldRef<"AgentEnv", 'String'>
1035
1069
  readonly value: Prisma.FieldRef<"AgentEnv", 'String'>
1036
1070
  readonly secret: Prisma.FieldRef<"AgentEnv", 'Boolean'>
1071
+ readonly enabled: Prisma.FieldRef<"AgentEnv", 'Boolean'>
1037
1072
  readonly source: Prisma.FieldRef<"AgentEnv", 'String'>
1038
1073
  readonly createdAt: Prisma.FieldRef<"AgentEnv", 'DateTime'>
1039
1074
  readonly updatedAt: Prisma.FieldRef<"AgentEnv", 'DateTime'>
@@ -0,0 +1,3 @@
1
+ -- ATP-1.2: AgentEnv tombstones. Additive only: existing rows get enabled = true.
2
+ -- AlterTable
3
+ ALTER TABLE "AgentEnv" ADD COLUMN "enabled" BOOLEAN NOT NULL DEFAULT true;
@@ -121,6 +121,7 @@ model AgentEnv {
121
121
  key String // env var name
122
122
  value String // AES-256-GCM encrypted
123
123
  secret Boolean @default(false) // when true, GET /agents/:id/envs masks the value as ***
124
+ enabled Boolean @default(true) // ATP-1.2: false = tombstone of a deleted template row; hidden from every read
124
125
  source String @default("custom") // ATP-1.1: 'template' | 'custom'; which rows a template sync owns
125
126
  createdAt DateTime @default(now())
126
127
  updatedAt DateTime @updatedAt
package/src/admin-boot.ts CHANGED
@@ -578,14 +578,15 @@ export async function startAdmin(
578
578
  );
579
579
 
580
580
  // 3b''. Agent templates API — /templates/* — admin or account-scoped (ATP-1.3)
581
+ const templateService = new AgentTemplateService(
582
+ prisma,
583
+ crypto,
584
+ specialtyRegistry,
585
+ );
581
586
  root.route(
582
587
  "/",
583
588
  createAgentTemplatesApp({
584
- templateService: new AgentTemplateService(
585
- prisma,
586
- crypto,
587
- specialtyRegistry,
588
- ),
589
+ templateService,
589
590
  callerScopeResolver,
590
591
  sessionSecret,
591
592
  adminApiKeys,
@@ -639,6 +640,7 @@ export async function startAdmin(
639
640
  anthropicFederationEnabled,
640
641
  specialtyRegistry,
641
642
  specialtyDefaults,
643
+ templateService,
642
644
  serviceIntegrations,
643
645
  chatService: deletionChatService,
644
646
  slack: slackClient,
@@ -265,7 +265,7 @@ export function renderGithubEnterpriseSettingsPage(
265
265
  title: "GitHub Enterprise — Settings — Shipwright Admin",
266
266
  body: `${renderAdminToolbar(opts.userEmail, BASE)}
267
267
  <div class="vos-page">
268
- <div class="page-header"><h1 class="page-title">GitHub Enterprise apps</h1></div>
268
+ <div class="page-header"><h1 class="page-title">GitHub Enterprise apps</h1><a href="/admin/settings/templates" class="btn btn-secondary">Agent templates</a></div>
269
269
  ${error}${notice}${intro}
270
270
  ${appCard("installer", status.installer, opts.warnings)}
271
271
  ${appCard("lookup", status.lookup, opts.warnings)}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * admin/src/admin-ui-templates-pages.ts
3
+ * Render function for the Settings > Templates editor (ATP-2.3).
4
+ * Pure string -> string; routes live in admin-ui-templates.ts.
5
+ *
6
+ * Secret env values arrive already masked ("***") from the template service;
7
+ * the page only ever echoes what it is given, and posting the mask back keeps
8
+ * the stored secret.
9
+ */
10
+
11
+ import { renderAdminPage } from "./admin-ui-layout.ts";
12
+ import { escapeHtml, renderAdminToolbar } from "./admin-ui-styles.ts";
13
+
14
+ export const ADMIN_TEMPLATES_PATH = "/admin/settings/templates";
15
+
16
+ const BASE = ADMIN_TEMPLATES_PATH;
17
+
18
+ export interface TemplateScopeOption {
19
+ value: string;
20
+ label: string;
21
+ }
22
+
23
+ export interface TemplateItemRow {
24
+ kind: "env" | "tool" | "plugin" | "cron";
25
+ key: string;
26
+ payload: Record<string, unknown>;
27
+ }
28
+
29
+ export interface TemplatesPageOpts {
30
+ userEmail: string;
31
+ /** Accounts the caller may pick; the deployment-wide option is included only for admins. */
32
+ accountOptions: TemplateScopeOption[];
33
+ specialtyOptions: TemplateScopeOption[];
34
+ /** Selected scope ("" = deployment-wide / all types). */
35
+ accountId: string;
36
+ specialty: string;
37
+ /** Items of the template at the selected scope (empty when none exists yet). */
38
+ items: TemplateItemRow[];
39
+ templateExists: boolean;
40
+ error?: string;
41
+ notice?: string;
42
+ }
43
+
44
+ const str = (v: unknown): string => (typeof v === "string" ? v : "");
45
+
46
+ function options(opts: TemplateScopeOption[], selected: string): string {
47
+ return opts
48
+ .map(
49
+ (o) =>
50
+ `<option value="${escapeHtml(o.value)}"${o.value === selected ? " selected" : ""}>${escapeHtml(o.label)}</option>`,
51
+ )
52
+ .join("");
53
+ }
54
+
55
+ function scopePicker(o: TemplatesPageOpts): string {
56
+ return `<form method="GET" action="${BASE}" class="template-scope" style="display:flex;gap:8px;align-items:end;flex-wrap:wrap">
57
+ <label>Account <select name="accountId" class="form-input">${options(o.accountOptions, o.accountId)}</select></label>
58
+ <label>Agent type <select name="specialty" class="form-input">${options(o.specialtyOptions, o.specialty)}</select></label>
59
+ <button type="submit" class="btn btn-secondary">Open template</button>
60
+ </form>`;
61
+ }
62
+
63
+ function scopeFields(o: TemplatesPageOpts): string {
64
+ return `<input type="hidden" name="accountId" value="${escapeHtml(o.accountId)}" /><input type="hidden" name="specialty" value="${escapeHtml(o.specialty)}" />`;
65
+ }
66
+
67
+ const checked = (b: unknown, dflt = true) =>
68
+ (b === undefined ? dflt : b !== false) ? " checked" : "";
69
+
70
+ /** The editable fields of one item (shared by the existing-item and add forms). */
71
+ function itemFields(
72
+ kind: TemplateItemRow["kind"],
73
+ p: Record<string, unknown>,
74
+ ): string {
75
+ switch (kind) {
76
+ case "env":
77
+ return `<label>Value <input name="value" class="form-input" autocomplete="off" value="${escapeHtml(str(p.value))}"/></label>
78
+ <label><input type="checkbox" name="secret" value="1"${p.secret === true ? " checked" : ""} /> Secret</label>`;
79
+ case "tool":
80
+ return `<label><input type="checkbox" name="enabled" value="1"${checked(p.enabled)} /> Enabled</label>`;
81
+ case "plugin":
82
+ return `<label>Version <input name="version" class="form-input" value="${escapeHtml(str(p.version))}" placeholder="latest" /></label>
83
+ <label><input type="checkbox" name="enabled" value="1"${checked(p.enabled)} /> Enabled</label>`;
84
+ case "cron":
85
+ return `<label>Schedule <input name="schedule" class="form-input" value="${escapeHtml(str(p.schedule))}" placeholder="0 9 * * 1-5" /></label>
86
+ <label>Prompt <textarea name="prompt" class="form-input" rows="2">${escapeHtml(str(p.prompt))}</textarea></label>
87
+ <label>Channel <input name="channel" class="form-input" value="${escapeHtml(str(p.channel))}" /></label>
88
+ <label>User <input name="user" class="form-input" value="${escapeHtml(str(p.user))}" /></label>
89
+ <label>Pre-check <input name="preCheck" class="form-input" value="${escapeHtml(str(p.preCheck))}" /></label>
90
+ <label><input type="checkbox" name="silent" value="1"${p.silent === true ? " checked" : ""} /> Silent</label>
91
+ <label><input type="checkbox" name="enabled" value="1"${checked(p.enabled)} /> Enabled</label>`;
92
+ }
93
+ }
94
+
95
+ const KIND_COPY = {
96
+ env: { title: "Environment variables", key: "Name", ph: "MY_SETTING" },
97
+ tool: { title: "Tools", key: "Tool pattern", ph: "Bash(git *)" },
98
+ plugin: { title: "Plugins", key: "Plugin", ph: "shipwright@shipwright" },
99
+ cron: { title: "Crons", key: "Name", ph: "daily-digest" },
100
+ } as const;
101
+
102
+ function kindCard(o: TemplatesPageOpts, kind: TemplateItemRow["kind"]): string {
103
+ const copy = KIND_COPY[kind];
104
+ const rows = o.items
105
+ .filter((i) => i.kind === kind)
106
+ .map(
107
+ (
108
+ i,
109
+ ) => `<form method="POST" action="${BASE}/items" class="template-item" data-kind="${kind}" data-key="${escapeHtml(i.key)}" style="display:grid;gap:6px;padding:8px 0;border-bottom:1px solid #e5e7eb">
110
+ ${scopeFields(o)}<input type="hidden" name="kind" value="${kind}" /><input type="hidden" name="key" value="${escapeHtml(i.key)}" />
111
+ <strong>${escapeHtml(i.key)}</strong>
112
+ ${itemFields(kind, i.payload)}
113
+ <div style="display:flex;gap:8px"><button type="submit" class="btn btn-primary" style="font-size:12px;padding:4px 10px">Save</button>
114
+ <button type="submit" formaction="${BASE}/items/delete" class="btn btn-danger" style="font-size:12px;padding:4px 10px">Remove</button></div>
115
+ </form>`,
116
+ )
117
+ .join("");
118
+ const empty = rows ? "" : `<p class="help-text empty-state">None yet.</p>`;
119
+ return `<div class="card" id="template-${kind}">
120
+ <div class="card-title">${copy.title}</div>
121
+ ${rows}${empty}
122
+ <form method="POST" action="${BASE}/items" class="template-add" style="display:grid;gap:6px;margin-top:12px;max-width:480px">
123
+ ${scopeFields(o)}<input type="hidden" name="kind" value="${kind}" />
124
+ <label>${copy.key} <input name="key" class="form-input" required placeholder="${escapeHtml(copy.ph)}" /></label>
125
+ ${itemFields(kind, {})}
126
+ <div><button type="submit" class="btn btn-primary">Add ${kind}</button></div>
127
+ </form>
128
+ </div>`;
129
+ }
130
+
131
+ export function renderTemplatesPage(o: TemplatesPageOpts): string {
132
+ const error = o.error
133
+ ? `<div class="alert alert-error">${escapeHtml(o.error)}</div>`
134
+ : "";
135
+ const notice = o.notice
136
+ ? `<div class="alert alert-success">${escapeHtml(o.notice)}</div>`
137
+ : "";
138
+ const del = o.templateExists
139
+ ? `<form method="POST" action="${BASE}/delete" style="margin:8px 0">${scopeFields(o)}<button type="submit" class="btn btn-danger">Delete this template</button></form>`
140
+ : `<p class="help-text">No template exists for this scope yet. Adding an item creates it.</p>`;
141
+ return renderAdminPage({
142
+ title: "Templates — Settings — Shipwright Admin",
143
+ body: `${renderAdminToolbar(o.userEmail, BASE)}
144
+ <div class="vos-page">
145
+ <div class="page-header"><h1 class="page-title">Agent templates</h1></div>
146
+ ${error}${notice}
147
+ <div class="card">
148
+ <p class="help-text">Default env vars, tools, plugins and crons for new agents in a scope. Secret values are masked after saving; leave <code>***</code> to keep the stored value.</p>
149
+ ${scopePicker(o)}
150
+ ${del}
151
+ </div>
152
+ ${(["env", "tool", "plugin", "cron"] as const).map((k) => kindCard(o, k)).join("\n")}
153
+ </div>`,
154
+ });
155
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * admin/src/admin-ui-templates-pages.unit.test.ts
3
+ * Unit tests for renderTemplatesPage (ATP-2.3).
4
+ */
5
+
6
+ import { describe, expect, it } from "bun:test";
7
+ import {
8
+ renderTemplatesPage,
9
+ type TemplatesPageOpts,
10
+ } from "./admin-ui-templates-pages.ts";
11
+
12
+ const base: TemplatesPageOpts = {
13
+ userEmail: "a@x.com",
14
+ accountOptions: [{ value: "", label: "Deployment-wide" }],
15
+ specialtyOptions: [{ value: "", label: "All agent types" }],
16
+ accountId: "",
17
+ specialty: "",
18
+ items: [],
19
+ templateExists: false,
20
+ };
21
+
22
+ describe("renderTemplatesPage", () => {
23
+ it("renders a card per kind and an add form each", () => {
24
+ const html = renderTemplatesPage(base);
25
+ for (const k of ["env", "tool", "plugin", "cron"]) {
26
+ expect(html).toContain(`id="template-${k}"`);
27
+ }
28
+ expect(html).toContain("No template exists for this scope yet");
29
+ expect(html).not.toContain("Delete this template");
30
+ });
31
+
32
+ it("escapes values and shows the selected scope", () => {
33
+ const html = renderTemplatesPage({
34
+ ...base,
35
+ accountOptions: [{ value: "a1", label: "<b>Acme</b>" }],
36
+ accountId: "a1",
37
+ templateExists: true,
38
+ error: "<script>x</script>",
39
+ items: [
40
+ {
41
+ kind: "env",
42
+ key: "K",
43
+ payload: { value: "***", secret: true },
44
+ },
45
+ ],
46
+ });
47
+ expect(html).toContain("&lt;b&gt;Acme&lt;/b&gt;");
48
+ expect(html).toContain('<option value="a1" selected>');
49
+ expect(html).toContain("&lt;script&gt;x&lt;/script&gt;");
50
+ expect(html).toContain('value="***"');
51
+ expect(html).toContain("Delete this template");
52
+ expect(html).toMatch(/name="secret" value="1" checked/);
53
+ });
54
+ });