@rubytech/create-sitedesk-code 0.1.507 → 0.1.509
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/index.js +53 -0
- package/package.json +2 -2
- package/payload/platform/config/brand.json +12 -0
- package/payload/platform/docs/superpowers/plans/2026-07-26-task-1926-portal-push-concurrency-guard.md +482 -0
- package/payload/platform/docs/superpowers/specs/2026-07-26-task-1926-portal-push-concurrency-guard-design.md +200 -0
- package/payload/platform/plugins/admin/PLUGIN.md +10 -5
- package/payload/platform/plugins/admin/skills/platform-architecture/SKILL.md +96 -13
- package/payload/platform/plugins/admin/skills/whats-new/SKILL.md +13 -0
- package/payload/platform/plugins/cloudflare/bin/portal-index-push.mjs +68 -28
- package/payload/platform/plugins/cloudflare/mcp/__tests__/portal-index-push.test.ts +271 -29
- package/payload/platform/plugins/cloudflare/skills/data-portal/schema.sql +5 -4
- package/payload/platform/plugins/docs/references/admin-ui.md +95 -12
- package/payload/platform/plugins/memory/PLUGIN.md +6 -3
- package/payload/platform/scripts/__tests__/check-brand-cache.test.sh +231 -0
- package/payload/platform/scripts/__tests__/provision-honours-disabled-agents.test.sh +84 -0
- package/payload/platform/scripts/check-brand-cache.sh +138 -0
- package/payload/platform/scripts/check-risk-class.mjs +7 -2
- package/payload/platform/scripts/check-specialist-tool-surface.mjs +5 -2
- package/payload/platform/scripts/lib/canonical-tool-names.mjs +7 -4
- package/payload/platform/scripts/lib/provision-account-dir.sh +43 -0
- package/payload/platform/services/claude-session-manager/dist/account-dir-schema-reconcile.d.ts +1 -1
- package/payload/platform/services/claude-session-manager/dist/account-dir-schema-reconcile.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/account-dir-schema-reconcile.js +56 -3
- package/payload/platform/services/claude-session-manager/dist/account-dir-schema-reconcile.js.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/tool-surface.d.ts +19 -5
- package/payload/platform/services/claude-session-manager/dist/tool-surface.d.ts.map +1 -1
- package/payload/platform/services/claude-session-manager/dist/tool-surface.js +50 -11
- package/payload/platform/services/claude-session-manager/dist/tool-surface.js.map +1 -1
- package/payload/server/maxy-edge.js +15 -10
- package/payload/server/public/activity.html +5 -5
- package/payload/server/public/agents.html +4 -4
- package/payload/server/public/assets/{AdminLoginScreens-YT7jsh_H.js → AdminLoginScreens-8Jk7hnWH.js} +1 -1
- package/payload/server/public/assets/{AdminShell-Ckht9hmU.js → AdminShell-BMPEWNZk.js} +1 -1
- package/payload/server/public/assets/{activity-DH3Wgc3O.js → activity-ByWYF5dC.js} +1 -1
- package/payload/server/public/assets/admin-CnUWbKcx.js +1 -0
- package/payload/server/public/assets/agents-C0rTfrYd.js +1 -0
- package/payload/server/public/assets/{browser-Bym8QhfA.js → browser-4tTaem8N.js} +1 -1
- package/payload/server/public/assets/{calendar-CFnufJOy.js → calendar-BEjnkKG1.js} +1 -1
- package/payload/server/public/assets/chat-DBgzjDIE.js +1 -0
- package/payload/server/public/assets/chevron-left-DqYv3oFh.js +1 -0
- package/payload/server/public/assets/chevron-right-CQfPGsFb.js +1 -0
- package/payload/server/public/assets/clock-Dn6FHB51.js +1 -0
- package/payload/server/public/assets/data-D_e6Vdfd.js +1 -0
- package/payload/server/public/assets/{file-text-zch0E1GJ.js → file-text-DMKw3nIk.js} +1 -1
- package/payload/server/public/assets/{graph-BavHLzpV.js → graph-C3vW8lvw.js} +1 -1
- package/payload/server/public/assets/{graph-labels-CBwh4g-6.js → graph-labels-BZgd0L6n.js} +1 -1
- package/payload/server/public/assets/{maximize-2-bTn_Ozpi.js → maximize-2-la3IBA3M.js} +1 -1
- package/payload/server/public/assets/{operator-a4IOwf62.js → operator-RRRdqoRQ.js} +1 -1
- package/payload/server/public/assets/{page-3T2mE63b.js → page-BWFHRIAH.js} +1 -1
- package/payload/server/public/assets/{page-D6M1CmPe.js → page-DC11gesX.js} +1 -1
- package/payload/server/public/assets/{public-B3y_YU1G.js → public-DQbbLHQN.js} +1 -1
- package/payload/server/public/assets/{rotate-ccw-BGvzNB1b.js → rotate-ccw-OQD5si8N.js} +1 -1
- package/payload/server/public/assets/{routines-C7Dr16am.js → routines-asrBGZUR.js} +1 -1
- package/payload/server/public/assets/{skills-DFeb3XO3.js → skills-D4ECwoxa.js} +1 -1
- package/payload/server/public/assets/{tasks-CSfnCKJe.js → tasks-U3QdbUsO.js} +1 -1
- package/payload/server/public/assets/{time-entry-format-BgZqOOqG.js → time-entry-format-BgdTKgYr.js} +1 -1
- package/payload/server/public/assets/{triangle-alert-DBJ7xz_t.js → triangle-alert-Ck_3VhT9.js} +1 -1
- package/payload/server/public/assets/{useCopyFeedback-BFOujMl-.js → useCopyFeedback-BdUwyNpa.js} +1 -1
- package/payload/server/public/assets/useSubAccountSwitcher-CJKjEPNN.js +9 -0
- package/payload/server/public/assets/useSubAccountSwitcher-DOWQXDT8.css +1 -0
- package/payload/server/public/assets/{useVoiceRecorder-BP6CpYQD.js → useVoiceRecorder-ChnBrzbZ.js} +1 -1
- package/payload/server/public/assets/{wrench-DdaRhfzS.js → wrench-Cpee3C3J.js} +1 -1
- package/payload/server/public/brand/fonts/inter-600.woff2 +0 -0
- package/payload/server/public/brand/fonts/inter-700.woff2 +0 -0
- package/payload/server/public/brand/fonts/inter-800.woff2 +0 -0
- package/payload/server/public/brand-defaults.css +22 -1
- package/payload/server/public/browser.html +4 -4
- package/payload/server/public/calendar.html +7 -7
- package/payload/server/public/chat.html +13 -13
- package/payload/server/public/data.html +11 -11
- package/payload/server/public/graph.html +9 -9
- package/payload/server/public/index.html +14 -14
- package/payload/server/public/operator.html +14 -14
- package/payload/server/public/public.html +13 -13
- package/payload/server/public/routines.html +6 -6
- package/payload/server/public/skills.html +5 -5
- package/payload/server/public/tasks.html +6 -6
- package/payload/server/server.js +1139 -427
- package/payload/server/public/assets/admin-DetvulAu.js +0 -1
- package/payload/server/public/assets/agents-X_IvDHLZ.js +0 -1
- package/payload/server/public/assets/chat-wrckyIpw.js +0 -1
- package/payload/server/public/assets/chevron-left-Dtk3jEK5.js +0 -1
- package/payload/server/public/assets/chevron-right-Dih6IZ8B.js +0 -1
- package/payload/server/public/assets/clock-iJCrrmWM.js +0 -1
- package/payload/server/public/assets/data-D76--TYs.js +0 -1
- package/payload/server/public/assets/useSubAccountSwitcher-0PfRrN6i.js +0 -9
- package/payload/server/public/assets/useSubAccountSwitcher-BkQ5tA8A.css +0 -1
|
@@ -45,10 +45,20 @@ afterEach(() => rmSync(dir, { recursive: true, force: true }))
|
|
|
45
45
|
function fakeClient() {
|
|
46
46
|
const calls: { sql: string; params: unknown[] }[] = []
|
|
47
47
|
const rows = new Set<string>()
|
|
48
|
+
// The pointer is modelled because the flip is read back (Task 1926): a client
|
|
49
|
+
// that always answers "no pointer" would make every push read as superseded.
|
|
50
|
+
let pointer: number | null = null
|
|
48
51
|
return {
|
|
49
52
|
calls,
|
|
50
53
|
async query(sql: string, params: unknown[] = []) {
|
|
51
54
|
calls.push({ sql, params })
|
|
55
|
+
if (/SELECT\s+currentGeneration/i.test(sql)) {
|
|
56
|
+
return pointer === null ? [] : [{ currentGeneration: pointer }]
|
|
57
|
+
}
|
|
58
|
+
if (/INSERT INTO directory_state/i.test(sql)) {
|
|
59
|
+
pointer = Number(params[1])
|
|
60
|
+
return []
|
|
61
|
+
}
|
|
52
62
|
// The open paren is load-bearing: `INSERT INTO directory_state` would
|
|
53
63
|
// otherwise register as a row insert and inflate every count.
|
|
54
64
|
if (/INSERT INTO directory \(/i.test(sql)) {
|
|
@@ -308,15 +318,24 @@ function generationClient() {
|
|
|
308
318
|
})
|
|
309
319
|
return []
|
|
310
320
|
}
|
|
321
|
+
if (/SELECT\s+MAX\(generation\)/i.test(sql)) {
|
|
322
|
+
const mine = rows.filter((r) => r.accountId === String(params[0]))
|
|
323
|
+
return [{ g: mine.length ? Math.max(...mine.map((r) => r.generation)) : null }]
|
|
324
|
+
}
|
|
311
325
|
if (/DELETE FROM directory\b/i.test(sql)) {
|
|
312
326
|
const g = Number(params[1])
|
|
313
|
-
//
|
|
314
|
-
//
|
|
315
|
-
//
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
327
|
+
// The post-flip sweep removes strictly OLDER generations
|
|
328
|
+
// (`generation < ?`, Task 1926). `generation != ?` is the shape it
|
|
329
|
+
// replaced and `generation = ?` was the Task 1923 pre-stage clear; both
|
|
330
|
+
// stay modelled so a regression to either shape is visible here.
|
|
331
|
+
for (let i = rows.length - 1; i >= 0; i--) {
|
|
332
|
+
const n = rows[i].generation
|
|
333
|
+
const hit = /generation\s*<\s*\?/i.test(sql)
|
|
334
|
+
? n < g
|
|
335
|
+
: /generation\s*!=\s*\?/i.test(sql)
|
|
336
|
+
? n !== g
|
|
337
|
+
: n === g
|
|
338
|
+
if (hit) rows.splice(i, 1)
|
|
320
339
|
}
|
|
321
340
|
return []
|
|
322
341
|
}
|
|
@@ -374,12 +393,20 @@ function wedgeableClient(seed: { pointer: number; current?: string[]; orphans: s
|
|
|
374
393
|
rows.push({ accountId, relPath, generation })
|
|
375
394
|
return []
|
|
376
395
|
}
|
|
396
|
+
if (/SELECT\s+MAX\(generation\)/i.test(sql)) {
|
|
397
|
+
const mine = rows.filter((r) => r.accountId === String(params[0]))
|
|
398
|
+
return [{ g: mine.length ? Math.max(...mine.map((r) => r.generation)) : null }]
|
|
399
|
+
}
|
|
377
400
|
if (/DELETE FROM directory\b/i.test(sql)) {
|
|
378
401
|
const g = Number(params[1])
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
402
|
+
for (let i = rows.length - 1; i >= 0; i--) {
|
|
403
|
+
const n = rows[i].generation
|
|
404
|
+
const hit = /generation\s*<\s*\?/i.test(sql)
|
|
405
|
+
? n < g
|
|
406
|
+
: /generation\s*!=\s*\?/i.test(sql)
|
|
407
|
+
? n !== g
|
|
408
|
+
: n === g
|
|
409
|
+
if (hit) rows.splice(i, 1)
|
|
383
410
|
}
|
|
384
411
|
return []
|
|
385
412
|
}
|
|
@@ -395,14 +422,18 @@ function wedgeableClient(seed: { pointer: number; current?: string[]; orphans: s
|
|
|
395
422
|
}
|
|
396
423
|
}
|
|
397
424
|
|
|
398
|
-
describe('a partial stage self-heals (Task 1923)', () => {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
425
|
+
describe('a partial stage self-heals (Task 1923, by the Task 1926 generation claim)', () => {
|
|
426
|
+
// The wedge: a stage that died mid-batch left rows at current + 1 while the
|
|
427
|
+
// pointer stayed at current, so every later run recomputed the SAME target
|
|
428
|
+
// and its first INSERT hit UNIQUE(accountId, relPath, generation). The index
|
|
429
|
+
// froze at the stale generation until an operator hand-cleared the orphans,
|
|
430
|
+
// which is what held gls-data for ~6 h on 2026-07-22.
|
|
431
|
+
//
|
|
432
|
+
// Task 1923 healed that with a DELETE before the stage. Task 1926 heals it by
|
|
433
|
+
// claiming above the orphans instead, which needs no DELETE before the flip
|
|
434
|
+
// at all — and that pre-flip DELETE was the statement a concurrent peer could
|
|
435
|
+
// aim at the live tree.
|
|
436
|
+
it('claims above the orphans rather than colliding with them, and sweeps them after the flip', async () => {
|
|
406
437
|
const c = wedgeableClient({
|
|
407
438
|
pointer: 5,
|
|
408
439
|
current: ['output', 'output/report.pdf', 'quotes', 'quotes/CR2969'],
|
|
@@ -412,21 +443,20 @@ describe('a partial stage self-heals (Task 1923)', () => {
|
|
|
412
443
|
const r = await push(c, { log: (l: string) => lines.push(l) })
|
|
413
444
|
|
|
414
445
|
expect(r.rows).toBe(7)
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
expect(
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
// pointer names: the clear scopes to `next`, never to a reader-visible row.
|
|
423
|
-
expect(clear).toContain('cleared=3')
|
|
446
|
+
// 7, not 6: the orphans sit at 6, so this run claims the one above them.
|
|
447
|
+
expect(c.pointerValue()).toBe(7)
|
|
448
|
+
// Nothing survives at a generation the pointer does not name: the sweep
|
|
449
|
+
// took both the stale tree at 5 and the orphans at 6.
|
|
450
|
+
expect(c.rows.every((row) => row.generation === 7)).toBe(true)
|
|
451
|
+
// No statement deletes anything before the flip any more.
|
|
452
|
+
expect(lines.some((l) => l.includes('op=stage-clear'))).toBe(false)
|
|
424
453
|
})
|
|
425
454
|
|
|
426
|
-
it('
|
|
455
|
+
it('re-stages onto a fresh generation with no orphans present', async () => {
|
|
427
456
|
const c = wedgeableClient({ pointer: 5, orphans: [] })
|
|
428
457
|
const lines: string[] = []
|
|
429
458
|
await push(c, { log: (l: string) => lines.push(l) })
|
|
459
|
+
expect(c.pointerValue()).toBe(6)
|
|
430
460
|
expect(lines.some((l) => l.includes('op=stage-clear'))).toBe(false)
|
|
431
461
|
})
|
|
432
462
|
})
|
|
@@ -505,3 +535,215 @@ describe('the index replace is atomic', () => {
|
|
|
505
535
|
expect(c.calls.filter((x) => /INSERT|DELETE|directory_state/i.test(x.sql))).toEqual([])
|
|
506
536
|
})
|
|
507
537
|
})
|
|
538
|
+
|
|
539
|
+
// Task 1926. Two pushes of ONE account are reachable: the admin server's 60s
|
|
540
|
+
// loop (pushAllAccounts) and a hand-run `--account <id>` are separate OS
|
|
541
|
+
// processes calling the same pushAccount, so no in-process lock can see both.
|
|
542
|
+
// These tests drive both writers against ONE store and snapshot the reader's
|
|
543
|
+
// view after every statement, so "never a half-built tree" stays a measured
|
|
544
|
+
// property rather than a claim.
|
|
545
|
+
//
|
|
546
|
+
// Statement-level atomicity matches SQLite: each exec() applies whole.
|
|
547
|
+
function sharedStore() {
|
|
548
|
+
const rows: { accountId: string; relPath: string; generation: number }[] = []
|
|
549
|
+
let pointer: number | null = null
|
|
550
|
+
const pointerHistory: number[] = []
|
|
551
|
+
const snapshots: string[][] = []
|
|
552
|
+
const deletesAtPointer: number[] = []
|
|
553
|
+
|
|
554
|
+
const visible = () =>
|
|
555
|
+
pointer === null
|
|
556
|
+
? []
|
|
557
|
+
: rows.filter((r) => r.generation === pointer).map((r) => r.relPath).sort()
|
|
558
|
+
|
|
559
|
+
// The three DELETE shapes this file can issue. Order matters: `!=` and `<`
|
|
560
|
+
// must be tested before `=`, or `generation != ?` would read as an equality.
|
|
561
|
+
const deleteMatcher = (sql: string, g: number) => {
|
|
562
|
+
if (/generation\s*<\s*\?/i.test(sql)) return (n: number) => n < g
|
|
563
|
+
if (/generation\s*!=\s*\?/i.test(sql)) return (n: number) => n !== g
|
|
564
|
+
return (n: number) => n === g
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
return {
|
|
568
|
+
rows,
|
|
569
|
+
snapshots,
|
|
570
|
+
deletesAtPointer,
|
|
571
|
+
pointerHistory,
|
|
572
|
+
visible,
|
|
573
|
+
pointerValue: () => pointer,
|
|
574
|
+
seed(generation: number, relPaths: string[]) {
|
|
575
|
+
for (const relPath of relPaths) rows.push({ accountId: 'acc-1', relPath, generation })
|
|
576
|
+
pointer = generation
|
|
577
|
+
pointerHistory.push(generation)
|
|
578
|
+
},
|
|
579
|
+
async exec(sql: string, params: unknown[] = []) {
|
|
580
|
+
const out = await (async () => {
|
|
581
|
+
if (/SELECT\s+currentGeneration/i.test(sql)) {
|
|
582
|
+
return pointer === null ? [] : [{ currentGeneration: pointer }]
|
|
583
|
+
}
|
|
584
|
+
if (/SELECT\s+MAX\(generation\)/i.test(sql)) {
|
|
585
|
+
const mine = rows.filter((r) => r.accountId === String(params[0]))
|
|
586
|
+
return [{ g: mine.length ? Math.max(...mine.map((r) => r.generation)) : null }]
|
|
587
|
+
}
|
|
588
|
+
if (/INSERT INTO directory_state/i.test(sql)) {
|
|
589
|
+
const g = Number(params[1])
|
|
590
|
+
// The upsert's WHERE, modelled: with the guard present the pointer
|
|
591
|
+
// moves forward only. Without it, every flip lands.
|
|
592
|
+
const forwardOnly =
|
|
593
|
+
/excluded\.currentGeneration\s*>\s*directory_state\.currentGeneration/i.test(sql)
|
|
594
|
+
if (pointer === null || !forwardOnly || g > pointer) {
|
|
595
|
+
pointer = g
|
|
596
|
+
pointerHistory.push(g)
|
|
597
|
+
}
|
|
598
|
+
return []
|
|
599
|
+
}
|
|
600
|
+
if (/INSERT INTO directory \(/i.test(sql)) {
|
|
601
|
+
const accountId = String(params[0])
|
|
602
|
+
const relPath = String(params[1])
|
|
603
|
+
const generation = Number(params[6])
|
|
604
|
+
if (
|
|
605
|
+
rows.some(
|
|
606
|
+
(r) => r.accountId === accountId && r.relPath === relPath && r.generation === generation,
|
|
607
|
+
)
|
|
608
|
+
) {
|
|
609
|
+
throw new Error(
|
|
610
|
+
'd1 query failed: HTTP 500 — UNIQUE constraint failed: directory.accountId, directory.relPath, directory.generation',
|
|
611
|
+
)
|
|
612
|
+
}
|
|
613
|
+
rows.push({ accountId, relPath, generation })
|
|
614
|
+
return []
|
|
615
|
+
}
|
|
616
|
+
if (/DELETE FROM directory\b/i.test(sql)) {
|
|
617
|
+
const g = Number(params[1])
|
|
618
|
+
const matches = deleteMatcher(sql, g)
|
|
619
|
+
// The bug's signature: a DELETE that removes rows at the generation
|
|
620
|
+
// the pointer names is a reader-visible deletion of the live tree.
|
|
621
|
+
if (pointer !== null && matches(pointer) && rows.some((r) => r.generation === pointer)) {
|
|
622
|
+
deletesAtPointer.push(pointer)
|
|
623
|
+
}
|
|
624
|
+
for (let i = rows.length - 1; i >= 0; i--) if (matches(rows[i].generation)) rows.splice(i, 1)
|
|
625
|
+
return []
|
|
626
|
+
}
|
|
627
|
+
if (/SELECT COUNT/i.test(sql)) {
|
|
628
|
+
if (/generation\s*=\s*\?/i.test(sql)) {
|
|
629
|
+
const g = Number(params[1])
|
|
630
|
+
return [{ n: rows.filter((r) => r.generation === g).length }]
|
|
631
|
+
}
|
|
632
|
+
return [{ n: rows.filter((r) => r.generation === pointer).length }]
|
|
633
|
+
}
|
|
634
|
+
return []
|
|
635
|
+
})()
|
|
636
|
+
snapshots.push(visible())
|
|
637
|
+
return out
|
|
638
|
+
},
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/** A one-shot rendezvous: `reached` settles when the writer parks, `open()` frees it. */
|
|
643
|
+
function gate() {
|
|
644
|
+
let hit!: () => void
|
|
645
|
+
let open!: () => void
|
|
646
|
+
const reached = new Promise<void>((r) => (hit = r))
|
|
647
|
+
const opened = new Promise<void>((r) => (open = r))
|
|
648
|
+
return { reached, opened, hit: () => hit(), open: () => open() }
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/** A client that parks once, either before or after the matching statement. */
|
|
652
|
+
function pausingClient(
|
|
653
|
+
store: ReturnType<typeof sharedStore>,
|
|
654
|
+
g: ReturnType<typeof gate>,
|
|
655
|
+
at: { before?: (sql: string) => boolean; after?: (sql: string) => boolean },
|
|
656
|
+
) {
|
|
657
|
+
let armed = true
|
|
658
|
+
const calls: { sql: string; params: unknown[] }[] = []
|
|
659
|
+
return {
|
|
660
|
+
calls,
|
|
661
|
+
async query(sql: string, params: unknown[] = []) {
|
|
662
|
+
calls.push({ sql, params })
|
|
663
|
+
if (armed && at.before?.(sql)) {
|
|
664
|
+
armed = false
|
|
665
|
+
g.hit()
|
|
666
|
+
await g.opened
|
|
667
|
+
}
|
|
668
|
+
const out = await store.exec(sql, params)
|
|
669
|
+
if (armed && at.after?.(sql)) {
|
|
670
|
+
armed = false
|
|
671
|
+
g.hit()
|
|
672
|
+
await g.opened
|
|
673
|
+
}
|
|
674
|
+
return out
|
|
675
|
+
},
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
const plainClient = (store: ReturnType<typeof sharedStore>) => ({
|
|
680
|
+
query: (sql: string, params: unknown[] = []) => store.exec(sql, params),
|
|
681
|
+
})
|
|
682
|
+
|
|
683
|
+
describe('two concurrent pushes of one account (Task 1926)', () => {
|
|
684
|
+
// The task file's own interleave. B reads the pointer, then stalls. A stages,
|
|
685
|
+
// flips and sweeps a whole publish. B resumes holding a stale `current`.
|
|
686
|
+
//
|
|
687
|
+
// Before the guard: B recomputed next = current + 1 = the generation the
|
|
688
|
+
// pointer now names, its pre-stage COUNT returned A's live rows, and its
|
|
689
|
+
// DELETE emptied the tree a client was reading.
|
|
690
|
+
it('a peer holding a stale pointer never empties or halves the live tree', async () => {
|
|
691
|
+
const store = sharedStore()
|
|
692
|
+
store.seed(5, ['output', 'output/report.pdf', 'quotes', 'quotes/CR2969'])
|
|
693
|
+
const g = gate()
|
|
694
|
+
const b = pausingClient(store, g, { after: (sql) => /SELECT\s+currentGeneration/i.test(sql) })
|
|
695
|
+
|
|
696
|
+
// Captured rather than awaited bare: B throwing for an unrelated reason
|
|
697
|
+
// would otherwise surface as a passing test.
|
|
698
|
+
const bRun = push(b, { log: () => {} }).catch((e: unknown) => e)
|
|
699
|
+
await g.reached
|
|
700
|
+
await push(plainClient(store), { log: () => {} })
|
|
701
|
+
g.open()
|
|
702
|
+
const bResult = await bRun
|
|
703
|
+
|
|
704
|
+
expect(bResult).not.toBeInstanceOf(Error)
|
|
705
|
+
// 4 is the seeded tree, 7 is a complete walk of the fixture. Any other
|
|
706
|
+
// count is a tree a client could see half-built.
|
|
707
|
+
expect(store.snapshots.every((s) => s.length === 4 || s.length === 7)).toBe(true)
|
|
708
|
+
expect(store.deletesAtPointer).toEqual([])
|
|
709
|
+
expect(store.visible().length).toBe(7)
|
|
710
|
+
// B resumed holding a stale pointer of 5, saw A's rows at 6 in the MAX, and
|
|
711
|
+
// claimed 7. Nothing was staged over and nothing was deleted at a live one.
|
|
712
|
+
expect(store.pointerValue()).toBe(7)
|
|
713
|
+
})
|
|
714
|
+
|
|
715
|
+
// The other order: A stages a whole generation, then stalls before its flip.
|
|
716
|
+
// B starts fresh, sees A's staged rows in the MAX, claims the generation
|
|
717
|
+
// above, and publishes. A wakes holding a generation that is now behind.
|
|
718
|
+
it('a writer overtaken while staging leaves the winner live and says so', async () => {
|
|
719
|
+
const store = sharedStore()
|
|
720
|
+
store.seed(5, ['output', 'output/report.pdf', 'quotes', 'quotes/CR2969'])
|
|
721
|
+
const g = gate()
|
|
722
|
+
const a = pausingClient(store, g, { before: (sql) => /INSERT INTO directory_state/i.test(sql) })
|
|
723
|
+
const lines: string[] = []
|
|
724
|
+
|
|
725
|
+
const aRun = push(a, { log: (l: string) => lines.push(l) })
|
|
726
|
+
await g.reached
|
|
727
|
+
await push(plainClient(store), { log: () => {} })
|
|
728
|
+
g.open()
|
|
729
|
+
const aResult = await aRun
|
|
730
|
+
|
|
731
|
+
expect(store.snapshots.every((s) => s.length === 4 || s.length === 7)).toBe(true)
|
|
732
|
+
expect(store.deletesAtPointer).toEqual([])
|
|
733
|
+
// The pointer never goes backward, which is what keeps the loser harmless.
|
|
734
|
+
expect(store.pointerHistory).toEqual([...store.pointerHistory].sort((x, y) => x - y))
|
|
735
|
+
expect(store.pointerValue()).toBe(7)
|
|
736
|
+
|
|
737
|
+
const contended = lines.find((l) => l.includes('op=stage-contended'))!
|
|
738
|
+
expect(contended).toContain('account=acc-1')
|
|
739
|
+
expect(contended).toContain('generation=6')
|
|
740
|
+
expect(contended).toContain('pointer=7')
|
|
741
|
+
expect(contended).toContain('action=superseded')
|
|
742
|
+
expect(lines.some((l) => l.includes('op=flip'))).toBe(false)
|
|
743
|
+
// No sweep and no verify from the loser: both would act on, and measure,
|
|
744
|
+
// the WINNER's tree and report a failure where nothing failed.
|
|
745
|
+
expect(a.calls.some((c) => /DELETE FROM directory/i.test(c.sql))).toBe(false)
|
|
746
|
+
expect(lines.some((l) => l.includes('op=verify'))).toBe(false)
|
|
747
|
+
expect(aResult.superseded).toBe(true)
|
|
748
|
+
})
|
|
749
|
+
})
|
|
@@ -150,10 +150,11 @@ CREATE UNIQUE INDEX IF NOT EXISTS auth_attempts_scope_window ON auth_attempts (s
|
|
|
150
150
|
-- No backfill follows it: the push replaces every row each cycle.
|
|
151
151
|
--
|
|
152
152
|
-- `generation` is which staging round a row belongs to (Task 1910). The push
|
|
153
|
-
--
|
|
154
|
-
--
|
|
155
|
-
--
|
|
156
|
-
--
|
|
153
|
+
-- claims a generation above every generation the account already holds, writes
|
|
154
|
+
-- the whole tree there, moves the pointer below in ONE forward-only statement,
|
|
155
|
+
-- then deletes strictly older generations (Task 1926). Uniqueness is scoped by
|
|
156
|
+
-- generation because two of them hold the same relPath between the write and
|
|
157
|
+
-- the flip; UNIQUE (accountId, relPath) would reject the staged write outright.
|
|
157
158
|
-- ALTER TABLE directory ADD COLUMN generation INTEGER NOT NULL DEFAULT 0;
|
|
158
159
|
CREATE TABLE IF NOT EXISTS directory (
|
|
159
160
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -151,8 +151,11 @@ not-found|rm-error>`.
|
|
|
151
151
|
|
|
152
152
|
### Agents
|
|
153
153
|
|
|
154
|
-
The Agents surface (`/agents`) is the admin view of the account's agents
|
|
155
|
-
|
|
154
|
+
The Agents surface (`/agents`) is the admin view of the account's agents. Each
|
|
155
|
+
card is tagged by **origin**, which says who put the agent there and therefore
|
|
156
|
+
what the operator may do with it. Origin is a different question to `kind`, which
|
|
157
|
+
says what shape the agent is: a shipped specialist and a user-created one are
|
|
158
|
+
both `kind: 'specialist'` and differ only by origin.
|
|
156
159
|
|
|
157
160
|
- **Public agents** — the per-agent directories under `<accountDir>/agents/<slug>/`,
|
|
158
161
|
each carrying a `config.json` (`displayName`, `status`, `model`,
|
|
@@ -163,19 +166,63 @@ kinds, each card tagged `Public` or `Specialist`:
|
|
|
163
166
|
to the public URL (computed client-side: an `admin.` host maps to the `public.`
|
|
164
167
|
host), plus a **delete** behind a confirm that runs the loud-fail `DELETE`
|
|
165
168
|
(graph projection cleanup precedes file removal).
|
|
166
|
-
- **User-created specialists** — the agent files under
|
|
169
|
+
- **User-created specialists** (`origin: 'specialist'`) — the agent files under
|
|
167
170
|
`<accountDir>/plugins/<plugin>/agents/<plugin>--<name>.md` (written by
|
|
168
|
-
`agent-builder`).
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
`agent-builder`). The specialist modal shows the model, tools, the owning
|
|
172
|
+
plugin's skills, and the system-prompt body. Specialists are authored, edited,
|
|
173
|
+
and deleted through chat (`agent-builder` / `specialist-management`), so the
|
|
174
|
+
specialist modal offers no delete or open-agent link.
|
|
175
|
+
- **Shipped specialists** (`origin: 'shipped'`) — the union of
|
|
176
|
+
`<accountDir>/specialists/agents/`, `<accountDir>/specialists/agents-disabled/`
|
|
177
|
+
and `PLATFORM_ROOT/templates/specialists/agents/`, in that precedence order.
|
|
178
|
+
`sidebar-artefacts.ts` reads the same union minus the quarantine directory, so
|
|
179
|
+
a disabled agent still appears there through its bundled-template row. The
|
|
180
|
+
route once walked only the account plugins tree, so the twelve
|
|
181
|
+
highest-capability agents on the box were the ones the operator could not see.
|
|
182
|
+
These are the only agents that can be disabled, and the route enforces that
|
|
183
|
+
rather than relying on the UI to withhold the control.
|
|
175
184
|
|
|
176
185
|
The former "Public" flyout toggle in the account menu was removed; this page is
|
|
177
186
|
the sole agent surface.
|
|
178
187
|
|
|
188
|
+
**Risk class.** Every classified card carries a green/amber/red badge derived
|
|
189
|
+
from the agent's declared `tools:` line: green when every tool is `read`, amber
|
|
190
|
+
when the worst is `write_local`, red on any `exec` or `external`, and red when
|
|
191
|
+
any tool resolves to no class at all. Resolution has two sources, because
|
|
192
|
+
frontmatter names tools in Claude Code's namespace: a plugin tool is a direct
|
|
193
|
+
lookup in `ToolSurface.riskByTool`, which is keyed by the same
|
|
194
|
+
canonical `mcp__plugin_<p>_<p>__<tool>` string frontmatter writes, and the
|
|
195
|
+
eleven built-ins carry their own table in `server/lib/agent-risk.ts`. An empty
|
|
196
|
+
tool list is red: no `tools:` line means the full surface, not none of it.
|
|
197
|
+
|
|
198
|
+
A public agent carries `risk: null` and shows no badge. Its tool surface
|
|
199
|
+
resolves through `ADMIN_CORE_TOOLS` plus the plugin allowlists rather than a
|
|
200
|
+
`tools:` line, and classifying its empty list would paint every public agent red
|
|
201
|
+
on a premise nothing established.
|
|
202
|
+
|
|
203
|
+
The detail modal renders one chip per declared tool carrying **that tool's own**
|
|
204
|
+
class, so a `read` tool inside a red agent still reads as harmless; a tool with
|
|
205
|
+
no class is dashed and uncoloured rather than painted as if it were understood.
|
|
206
|
+
Badge colours come from the shared semantic status set: `-solid` with white text
|
|
207
|
+
for the badge, `-tint` with `-textOnTint` for a chip, never white.
|
|
208
|
+
|
|
209
|
+
**Disable.** `<accountDir>/specialists/agents/` is the live dispatchable set —
|
|
210
|
+
`spawn-context.ts` reads it to build the spawn manifest — so disabling **moves**
|
|
211
|
+
the agent file to `<accountDir>/specialists/agents-disabled/` and records the
|
|
212
|
+
basename in a 0600 `<accountDir>/agents-disabled.json`. A flag alone would leave
|
|
213
|
+
the agent running while the card claimed otherwise.
|
|
214
|
+
|
|
215
|
+
The file is moved, never deleted: a premium `--` agent and an operator-edited
|
|
216
|
+
override each exist only in the account dir, so deleting one and later restoring
|
|
217
|
+
from the bundled template would hand back a different agent than the operator
|
|
218
|
+
switched off. A disabled agent stays listed, marked `Disabled`, because an agent
|
|
219
|
+
that vanished from the surface that disabled it could never be switched back on.
|
|
220
|
+
|
|
221
|
+
`provision-account-dir.sh` re-reads the store after its core-specialist recopy
|
|
222
|
+
and removes anything named in it, so an upgrade does not silently re-deliver a
|
|
223
|
+
disabled agent. An unreadable store withholds nothing and says so: a corrupt
|
|
224
|
+
file is not evidence that an agent was disabled.
|
|
225
|
+
|
|
179
226
|
**Account scope.** The route (`server/routes/admin/agents.ts`) never infers an
|
|
180
227
|
account from device state. The two reads resolve from the caller's admin session
|
|
181
228
|
(`requireAdminSession` + the shared `accountDirForSession` in
|
|
@@ -189,8 +236,10 @@ explicit `?plugin=` parameter, not inferred from `--` in the slug.
|
|
|
189
236
|
|
|
190
237
|
| Route | Behaviour |
|
|
191
238
|
|-------|-----------|
|
|
192
|
-
| `GET /api/admin/agents` | Session-scoped. Lists the session account's public `agents/*/` dirs (never the `admin` agent)
|
|
193
|
-
| `GET /api/admin/agents/:slug` | Session-scoped. Without `?plugin=`, returns a public agent's config fields + four owned docs + a `present` map (a missing or unreadable doc is `''`/`present.<role>=false`, never a 500). With `?plugin=`,
|
|
239
|
+
| `GET /api/admin/agents` | Session-scoped. Lists the session account's public `agents/*/` dirs (never the `admin` agent), its user-created specialists from `plugins/*/agents/*.md`, and its shipped specialists, each row tagged `kind` and `origin` and carrying `risk`, `riskiestTool`, `unresolved` and `disabled`. Returns `{agents, accountId, skipped, specialistsSkipped, shippedSkipped}`. 401 when the session maps to no account. |
|
|
240
|
+
| `GET /api/admin/agents/:slug` | Session-scoped. Without `?plugin=` or `?origin=`, returns a public agent's config fields + four owned docs + a `present` map (a missing or unreadable doc is `''`/`present.<role>=false`, never a 500). With `?plugin=`, that plugin's user-created specialist; with `?origin=shipped`, the shipped one. Both specialist shapes add `{risk, riskiestTool, unresolved, byTool, disabled}`, where `byTool` is one class per declared tool. Selection is explicit rather than inferred, because a premium file and a user-created specialist under a plugin of the same name produce the same slug. Unknown 404s, 401 as above. |
|
|
241
|
+
| `POST /api/admin/agents/:slug/disable?accountId=` | Shipped agents only, enforced here: a slug present in none of the three shipped directories 404s. Moves the file from `specialists/agents/` to `specialists/agents-disabled/` and records the basename in the 0600 store. Returns `{ok, moved}`; `moved:false` means the agent existed only as a bundled template, so nothing was there to move and the store entry is what stops the next provisioning run delivering it. The store is read strictly before anything moves, so an unreadable store 500s with the file untouched rather than rewriting the file whole from an empty set and dropping every other disabled agent. Same `accountId` contract as delete. |
|
|
242
|
+
| `POST /api/admin/agents/:slug/enable?accountId=` | Covers both of disable's outcomes. Returns `{ok, restored}`: a quarantined file moves back (`restored:true`); a bundled-only agent has nothing to move, so clearing the store entry is the whole job (`restored:false`), which is what stops provisioning withholding it. Treating that second case as "nothing to restore" made disable a one-way door. 404 only when neither directory nor store knows the agent. |
|
|
194
243
|
| `DELETE /api/admin/agents/:slug?accountId=` | Public agents only, on the named validated account. Removes the dir after `deleteAgentProjection`; refuses the `admin` slug (403) and a missing/unknown `accountId` (400) with no write. Loud-fail: a graph-cleanup throw aborts the file removal. |
|
|
195
244
|
| `POST /api/admin/agents/:slug/project?accountId=` | Re-projects the named account's on-disk agent into the graph. Same `accountId` contract as delete. |
|
|
196
245
|
|
|
@@ -217,6 +266,40 @@ Agents page survived undiagnosed on a multi-account install.
|
|
|
217
266
|
- `op=delete accountId=<id8> slug=<…> outcome=<ok|failed>` with
|
|
218
267
|
`reason=<graph-cleanup-failed|rm-error>` on failure (files preserved on a
|
|
219
268
|
graph-cleanup throw).
|
|
269
|
+
- `op=classify account=<id8> agent=<name> origin=<shipped|public|specialist>
|
|
270
|
+
risk=<green|amber|red> riskiestTool=<tool> tools=<n> unresolved=<comma-list|none>
|
|
271
|
+
disabled=<bool>` — one line per classified agent per listing, so it fires on
|
|
272
|
+
every page load. `riskiestTool` makes a wrong class diagnosable without
|
|
273
|
+
re-deriving it. Its value is the FULL canonical tool name, while the card
|
|
274
|
+
renders only the segment after the plugin prefix. One load
|
|
275
|
+
showing `riskiest tool: memory-update` on the card and
|
|
276
|
+
`riskiestTool=mcp__plugin_memory_memory__memory-update` on this line is the
|
|
277
|
+
confirmation that both derive from one value.
|
|
278
|
+
**A non-empty `unresolved=` is the one to act on**: the agent
|
|
279
|
+
is forced red, and the cause is that the built-in table or the registry
|
|
280
|
+
mapping has drifted, not that the agent changed.
|
|
281
|
+
- `op=risk-surface status=load-failed reason=<msg>` — the plugin registry did
|
|
282
|
+
not parse, so every row is forced red and the listing returns
|
|
283
|
+
`riskSurfaceFailed: true`. Without the forced red, every plugin tool would
|
|
284
|
+
land in `unresolved` and a registry outage would read as agent drift across
|
|
285
|
+
every card at once; without the response field, a red row would be
|
|
286
|
+
indistinguishable from a genuinely dangerous agent, because nothing resolved
|
|
287
|
+
so `unresolved` is empty and the per-tool explanation cannot fire.
|
|
288
|
+
- `op=disabled-store status=parse-failed reason=<msg>` — the listing then treats
|
|
289
|
+
every agent as enabled, which is what they actually are. A read surface shows
|
|
290
|
+
the true dispatchable set rather than a comforting one.
|
|
291
|
+
- `op=<disable|enable> accountId=<id8> slug=<…> outcome=<ok|failed>`, with
|
|
292
|
+
`moved=<bool>` on disable and `reason=nothing-quarantined` on a failed enable.
|
|
293
|
+
|
|
294
|
+
**Disable is a no-event failure, so it needs a standing check.** If the store
|
|
295
|
+
names an agent whose file is still in `specialists/agents/`, nothing throws, the
|
|
296
|
+
card reads disabled, and the agent keeps being dispatched. The five-minute
|
|
297
|
+
`account-dir-schema-reconcile` pass reports it as
|
|
298
|
+
`[fs-reconcile] op=agent-parity account=<id8> disabled=<n> stillOnDisk=<list>`,
|
|
299
|
+
fired only on disagreement. The per-cycle heartbeat is `agent-drift=0` on that
|
|
300
|
+
pass's summary line, which is what makes the absence of a per-account line
|
|
301
|
+
readable as "clean" rather than "never audited" — grep the summary line, not the
|
|
302
|
+
per-account one, to confirm the check is running.
|
|
220
303
|
|
|
221
304
|
### Graph
|
|
222
305
|
|
|
@@ -168,9 +168,12 @@ tools:
|
|
|
168
168
|
adminAllowlist: true
|
|
169
169
|
riskClass: read
|
|
170
170
|
hidden:
|
|
171
|
-
- session-compact
|
|
172
|
-
|
|
173
|
-
-
|
|
171
|
+
- name: session-compact
|
|
172
|
+
riskClass: write_local
|
|
173
|
+
- name: session-compact-status
|
|
174
|
+
riskClass: read
|
|
175
|
+
- name: image-fetch
|
|
176
|
+
riskClass: read
|
|
174
177
|
skills:
|
|
175
178
|
- skills/conversational-memory/SKILL.md
|
|
176
179
|
- skills/preference-audit/SKILL.md
|