@dadado/agent-kit-cli 6.17.0 → 6.19.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.
Files changed (63) hide show
  1. package/dashboard/dashboard-data.mjs +8 -3
  2. package/dashboard/dashboard.html +140 -0
  3. package/dashboard/lib/guards.d.mts +20 -0
  4. package/dashboard/lib/guards.mjs +307 -0
  5. package/dashboard/lib/semantic-model.mjs +228 -1
  6. package/dist/{add-DRV3T42D.js → add-MRI5BXHH.js} +3 -3
  7. package/dist/{chunk-3IEE6Q37.js → chunk-2TX6NJEG.js} +1 -1
  8. package/dist/{chunk-IOQ6YXA3.js → chunk-3HNTNYPR.js} +1 -1
  9. package/dist/{chunk-MEZU47IB.js → chunk-5EBT3V7G.js} +1 -1
  10. package/dist/{chunk-5IJQGIOY.js → chunk-677W4QO3.js} +63 -1
  11. package/dist/{chunk-SKC6QZW4.js → chunk-6WUKLS4D.js} +1 -1
  12. package/dist/{chunk-YO4BLHDT.js → chunk-6XJZLH53.js} +149 -18
  13. package/dist/{chunk-J3YLSHRK.js → chunk-7MUTZHWP.js} +23 -4
  14. package/dist/{chunk-CJ3JAH7L.js → chunk-BGL5DRK2.js} +2 -2
  15. package/dist/{chunk-IJQAFPY3.js → chunk-C4LCOOL4.js} +3 -1
  16. package/dist/chunk-DTSL2RH7.js +433 -0
  17. package/dist/{chunk-4DLMU44M.js → chunk-EBDQYFA4.js} +71 -4
  18. package/dist/{chunk-AQTCXUYS.js → chunk-EOQMAU2J.js} +1 -1
  19. package/dist/{chunk-RAMT55TC.js → chunk-G2Z37XFM.js} +3 -3
  20. package/dist/{chunk-HKZH2IEE.js → chunk-GTP224FI.js} +1 -1
  21. package/dist/{chunk-QYIV6ZP6.js → chunk-HJWSOZXS.js} +52 -12
  22. package/dist/{chunk-AZCPUJJO.js → chunk-IQQQDEQ4.js} +2 -2
  23. package/dist/{chunk-ZFJIJUZ4.js → chunk-MPCNPZJZ.js} +1 -1
  24. package/dist/{hook-2YEC7GT5.js → chunk-NL3I2BWA.js} +104 -113
  25. package/dist/{chunk-WGAOM37Y.js → chunk-OKQ37A7E.js} +9 -9
  26. package/dist/{chunk-WRCXRV2U.js → chunk-P7732A25.js} +10 -0
  27. package/dist/{chunk-6RRG3WOE.js → chunk-Q35TWISF.js} +22 -1
  28. package/dist/{chunk-WA7IBNIL.js → chunk-QBYJNGCD.js} +2 -2
  29. package/dist/chunk-QWTBYXHN.js +751 -0
  30. package/dist/{chunk-SC2DBY2R.js → chunk-R4DUO5DA.js} +1 -0
  31. package/dist/{chunk-2Y27P6KC.js → chunk-SGTTC2JP.js} +4 -3
  32. package/dist/{chunk-TICKIKCQ.js → chunk-U23SLQGX.js} +5 -5
  33. package/dist/chunk-UATQQDVR.js +297 -0
  34. package/dist/{chunk-3YTFXTXH.js → chunk-UXQH2CNC.js} +2 -1
  35. package/dist/{chunk-VBQHBSIB.js → chunk-VJWWJA36.js} +3 -3
  36. package/dist/{chunk-OQNJRQPZ.js → chunk-W3ZJVBNY.js} +7 -4
  37. package/dist/{chunk-XDCCYBCJ.js → chunk-ZMYV6PRE.js} +13 -0
  38. package/dist/{commands-3O2HFLTW.js → commands-NL6UOEP7.js} +51 -17
  39. package/dist/{conflicts-UY6VTYIO.js → conflicts-XMN4PBCZ.js} +8 -8
  40. package/dist/{contribute-RF47NPZ2.js → contribute-QDTEJ42W.js} +4 -4
  41. package/dist/{countdown-JX3DZ2QU.js → countdown-7ONIVAG6.js} +40 -12
  42. package/dist/{dashboard-YNCFISNO.js → dashboard-P65XHYCU.js} +1 -1
  43. package/dist/{dashboard-broadcast-NK7PU72L.js → dashboard-broadcast-GYK34QYL.js} +1 -1
  44. package/dist/{diff-SVFAUOVP.js → diff-RLB7R2NE.js} +5 -5
  45. package/dist/{doctor-ATKYRCT4.js → doctor-OXMDSOXL.js} +11 -11
  46. package/dist/{engine-info-R6GXZ2VO.js → engine-info-BBI5QO5Y.js} +3 -3
  47. package/dist/{ground-control-D2X6CI66.js → ground-control-IDCXN5FK.js} +5 -5
  48. package/dist/hook-B4VUQOQF.js +108 -0
  49. package/dist/index.js +28 -28
  50. package/dist/{init-LUJRWMHC.js → init-BYONEUCW.js} +14 -14
  51. package/dist/{install-VQSO2JR7.js → install-HOR6VR44.js} +14 -14
  52. package/dist/{mission-control-JIF6GFSV.js → mission-control-QJBSZVNI.js} +2 -2
  53. package/dist/{queue-IEOXOBNL.js → queue-OJHKFKK3.js} +55 -11
  54. package/dist/{run-L63NZHAJ.js → run-PFANZJ5Y.js} +175 -27
  55. package/dist/{run-plan-BWJX6R7Q.js → run-plan-7EB4ERSQ.js} +46 -16
  56. package/dist/{scan-BWA64R7I.js → scan-K3T5RQLC.js} +1 -1
  57. package/dist/session-start-OSFSF4OZ.js +74 -0
  58. package/dist/sessions-WQU5DONU.js +102 -0
  59. package/dist/{setup-global-2X5TMDCB.js → setup-global-O34KFL2C.js} +6 -6
  60. package/dist/{status-MOOZCB5D.js → status-QB2FFYUP.js} +8 -8
  61. package/dist/{update-NMSO56CQ.js → update-N2EKKSE7.js} +16 -11
  62. package/package.json +1 -1
  63. package/dist/sessions-O7MYEMCT.js +0 -343
@@ -35,6 +35,7 @@ import { PIPELINE_CACHE_ENV, readCachedPipeline } from "./lib/pipeline-cache.mjs
35
35
  import { selectWorkspaceProcesses } from "./lib/processes.mjs";
36
36
  import { collectRunLogs } from "./lib/run-logs.mjs";
37
37
  import {
38
+ attachTodoEvidenceRefs,
38
39
  buildMissionControlView,
39
40
  collectDeferredCheckIds,
40
41
  collectReadinessPendingFromReport,
@@ -168,12 +169,13 @@ function redactTerminalOutput(text) {
168
169
 
169
170
  const SNAPSHOT = {
170
171
  _schema: {
171
- version: "1.11.0",
172
+ version: "1.12.0",
172
173
  description: "Mission Control dashboard data model",
173
174
  fields: {
174
175
  generatedAt: "ISO-8601 timestamp of snapshot generation",
175
176
  dashboardDataVersion: "Semantic version of the data model schema",
176
- plans: "Active plans from .cursor/plans/*.plan.md with frontmatter parsing",
177
+ plans:
178
+ "Active plans from .cursor/plans/*.plan.md with frontmatter parsing; todos.items[].evidenceRefs ({prs[] {repo|null, number}, shas[], structured}) from each to-do evidence field, refs only (1.12.0)",
177
179
  system:
178
180
  "System metadata: repoRoot, listen port, handoff state, allowlisted config summary, package info, version, name, contextPacks, detachedAuditSessions ({count, oldestAgeSeconds}|null; host-wide detached agent-kit-audit-* PTYs)",
179
181
  agents: "Agent definitions from .cursor/agents/*.md",
@@ -205,7 +207,7 @@ const SNAPSHOT = {
205
207
  },
206
208
  },
207
209
  generatedAt: new Date().toISOString(),
208
- dashboardDataVersion: "1.11.0",
210
+ dashboardDataVersion: "1.12.0",
209
211
  plans: [],
210
212
  system: {
211
213
  repoRoot: ROOT,
@@ -255,6 +257,9 @@ if (existsSync(plansDir)) {
255
257
  for (const m of fm.matchAll(todoRegex)) {
256
258
  todos.push({ id: m[1], content: m[2], status: m[3] });
257
259
  }
260
+ // Structured delivery refs (`<repo>#<n>`, merge SHAs) from each to-do's
261
+ // `evidence:` field (1.12.0). Refs only; the evidence prose never ships.
262
+ attachTodoEvidenceRefs(fm, todos);
258
263
  }
259
264
 
260
265
  const totalTodos = todos.length;
@@ -6248,6 +6248,143 @@ function personaOptionHtml(selected) {
6248
6248
  );
6249
6249
  }
6250
6250
 
6251
+ /* Model roles (roles key; docs/model-roles-capability-matrix.md). Empty = not set:
6252
+ the field is cleared and the command default or the Audits section applies. */
6253
+ const ROLE_WORKER_BACKEND_OPTIONS = ['auto', 'claude', 'cursor-agent', 'codex', 'openrouter', 'cursor-acp'];
6254
+ const ROLE_REVIEWER_BACKEND_OPTIONS = ['auto', 'claude', 'cursor-agent'];
6255
+ const ROLE_REVIEWER_SCOPE_OPTIONS = ['off', 'tick', 'plan'];
6256
+ const ROLE_MODEL_SUGGESTIONS = [
6257
+ 'opus',
6258
+ 'sonnet',
6259
+ 'haiku',
6260
+ 'fable',
6261
+ 'claude-opus-5-5',
6262
+ 'claude-sonnet-5-5',
6263
+ 'claude-haiku-5-5',
6264
+ 'claude-fable-5-2',
6265
+ ];
6266
+
6267
+ function roleSelectHtml(options, selected, unsetLabel) {
6268
+ const cur = typeof selected === 'string' ? selected : '';
6269
+ const unset = `<option value=""${cur === '' ? ' selected' : ''}>${escapeHtml(unsetLabel)}</option>`;
6270
+ return (
6271
+ unset +
6272
+ options
6273
+ .map((v) => `<option value="${escapeAttr(v)}"${v === cur ? ' selected' : ''}>${escapeHtml(v)}</option>`)
6274
+ .join('')
6275
+ );
6276
+ }
6277
+
6278
+ function formatWorkerTypeMap(map) {
6279
+ if (!map || typeof map !== 'object') return '';
6280
+ return Object.entries(map)
6281
+ .map(([type, model]) => `${type}=${model}`)
6282
+ .join(', ');
6283
+ }
6284
+
6285
+ function parseWorkerTypeMap(text) {
6286
+ const out = {};
6287
+ for (const part of String(text || '').split(',')) {
6288
+ const [type, model] = part.split('=').map((s) => (s || '').trim());
6289
+ if (type && model) out[type] = model;
6290
+ }
6291
+ return out;
6292
+ }
6293
+
6294
+ function renderRolesFieldset(cfg) {
6295
+ const roles = cfg.roles && typeof cfg.roles === 'object' ? cfg.roles : {};
6296
+ const worker = roles.worker || {};
6297
+ const sub = roles.subworker || {};
6298
+ const rev = roles.reviewer || {};
6299
+ const enabled = rev.enabled === true ? 'on' : rev.enabled === false ? 'off' : '';
6300
+ return `
6301
+ <fieldset class="config-fieldset config-fieldset-wide">
6302
+ <legend>Model roles</legend>
6303
+ <datalist id="config-role-model-suggestions">
6304
+ ${ROLE_MODEL_SUGGESTIONS.map((m) => `<option value="${escapeAttr(m)}"></option>`).join('')}
6305
+ </datalist>
6306
+ <datalist id="config-role-subworker-suggestions">
6307
+ <option value="auto"></option>
6308
+ ${ROLE_MODEL_SUGGESTIONS.map((m) => `<option value="${escapeAttr(m)}"></option>`).join('')}
6309
+ </datalist>
6310
+ <p class="config-hint">Read by run-plan, run-plan-all and the countdown tick job when no --backend / --model flag is given. A plan's worker_backend / worker_model frontmatter wins over these. Empty = not set.</p>
6311
+ <div class="config-row">
6312
+ <label for="config-role-worker-backend">Worker backend</label>
6313
+ <select id="config-role-worker-backend" name="roleWorkerBackend" data-focus-key="config-role-worker-backend">
6314
+ ${roleSelectHtml(ROLE_WORKER_BACKEND_OPTIONS, worker.backend, 'Not set (command default)')}
6315
+ </select>
6316
+ <span class="config-hint">codex, openrouter and cursor-acp bill their own accounts and never fall back to another backend.</span>
6317
+ </div>
6318
+ <div class="config-row">
6319
+ <label for="config-role-worker-model">Worker model</label>
6320
+ <input type="text" id="config-role-worker-model" name="roleWorkerModel" list="config-role-model-suggestions" value="${escapeAttr(worker.model || '')}" maxlength="128" placeholder="backend default" data-focus-key="config-role-worker-model" />
6321
+ <span class="config-hint">Alias or full id for the worker backend. cursor-acp cannot select a model.</span>
6322
+ </div>
6323
+ <div class="config-row">
6324
+ <label for="config-role-subworker-model">Subworker model</label>
6325
+ <input type="text" id="config-role-subworker-model" name="roleSubworkerModel" list="config-role-subworker-suggestions" value="${escapeAttr(sub.model || '')}" maxlength="128" placeholder="same as worker" data-focus-key="config-role-subworker-model" />
6326
+ <span class="config-hint">Claude Code only (subagents without their own model). auto is reserved and not implemented yet.</span>
6327
+ </div>
6328
+ <div class="config-row">
6329
+ <label for="config-role-subworker-map">Subworker model per worker_type</label>
6330
+ <input type="text" id="config-role-subworker-map" name="roleSubworkerMap" value="${escapeAttr(formatWorkerTypeMap(sub.byWorkerType))}" maxlength="1024" placeholder="docs-repo=haiku, tech-lead=opus" data-focus-key="config-role-subworker-map" />
6331
+ <span class="config-hint">Picked by the next to-do's worker_type; wins over the subworker model.</span>
6332
+ </div>
6333
+ <div class="config-row">
6334
+ <label for="config-role-reviewer-enabled">Reviewer</label>
6335
+ <select id="config-role-reviewer-enabled" name="roleReviewerEnabled" data-focus-key="config-role-reviewer-enabled">
6336
+ ${roleSelectHtml(['on', 'off'], enabled, 'Not set (Audits section)')}
6337
+ </select>
6338
+ <span class="config-hint">Saved for the reviewer role. Review runs still follow the Audits section until the reviewer role ships.</span>
6339
+ </div>
6340
+ <div class="config-row">
6341
+ <label for="config-role-reviewer-scope">Reviewer scope</label>
6342
+ <select id="config-role-reviewer-scope" name="roleReviewerScope" data-focus-key="config-role-reviewer-scope">
6343
+ ${roleSelectHtml(ROLE_REVIEWER_SCOPE_OPTIONS, rev.scope, 'Not set')}
6344
+ </select>
6345
+ <span class="config-hint">tick = after each tick, plan = once per plan, off = none.</span>
6346
+ </div>
6347
+ <div class="config-row">
6348
+ <label for="config-role-reviewer-backend">Reviewer backend</label>
6349
+ <select id="config-role-reviewer-backend" name="roleReviewerBackend" data-focus-key="config-role-reviewer-backend">
6350
+ ${roleSelectHtml(ROLE_REVIEWER_BACKEND_OPTIONS, rev.backend, 'Not set')}
6351
+ </select>
6352
+ </div>
6353
+ <div class="config-row">
6354
+ <label for="config-role-reviewer-model">Reviewer model</label>
6355
+ <input type="text" id="config-role-reviewer-model" name="roleReviewerModel" list="config-role-model-suggestions" value="${escapeAttr(rev.model || '')}" maxlength="128" placeholder="not set" data-focus-key="config-role-reviewer-model" />
6356
+ </div>
6357
+ <div class="config-row">
6358
+ <label for="config-role-reviewer-advisor">Reviewer advisor model</label>
6359
+ <input type="text" id="config-role-reviewer-advisor" name="roleReviewerAdvisor" list="config-role-model-suggestions" value="${escapeAttr(rev.advisorModel || '')}" maxlength="128" placeholder="not set" data-focus-key="config-role-reviewer-advisor" />
6360
+ </div>
6361
+ <button type="button" class="btn-config-copy" data-focus-key="config-copy-roles" onclick="return copyConfigSnippet('roles')">Copy config.json snippet</button>
6362
+ </fieldset>`;
6363
+ }
6364
+
6365
+ function collectRolesPayload() {
6366
+ const val = (id) => (document.getElementById(id)?.value || '').trim();
6367
+ const orNull = (v) => (v ? v : null);
6368
+ const enabled = val('config-role-reviewer-enabled');
6369
+ return {
6370
+ worker: {
6371
+ backend: orNull(val('config-role-worker-backend')),
6372
+ model: orNull(val('config-role-worker-model')),
6373
+ },
6374
+ subworker: {
6375
+ model: orNull(val('config-role-subworker-model')),
6376
+ byWorkerType: parseWorkerTypeMap(val('config-role-subworker-map')),
6377
+ },
6378
+ reviewer: {
6379
+ enabled: enabled === 'on' ? true : enabled === 'off' ? false : null,
6380
+ scope: orNull(val('config-role-reviewer-scope')),
6381
+ backend: orNull(val('config-role-reviewer-backend')),
6382
+ model: orNull(val('config-role-reviewer-model')),
6383
+ advisorModel: orNull(val('config-role-reviewer-advisor')),
6384
+ },
6385
+ };
6386
+ }
6387
+
6251
6388
  function renderConfigSection(d) {
6252
6389
  const cfg = d?.system?.config && !d.system.config.error ? d.system.config : {};
6253
6390
  const epr = cfg.externalPlanReview || {};
@@ -6337,6 +6474,7 @@ function renderConfigSection(d) {
6337
6474
  <button type="button" class="btn-config-copy" data-focus-key="config-copy-updateCheck" onclick="return copyConfigSnippet('updateCheck')">Copy config.json snippet</button>
6338
6475
  <button type="button" class="btn-config-copy" data-focus-key="config-copy-updateApply" onclick="return copyStaticConfigSnippet('updateApply')" title="Copy-only; never writable via this tab">Copy updateApply.auto snippet</button>
6339
6476
  </fieldset>
6477
+ ${renderRolesFieldset(cfg)}
6340
6478
  <fieldset class="config-fieldset config-fieldset-wide">
6341
6479
  <legend>Audits (external plan review)</legend>
6342
6480
  <div class="config-row config-row-inline">
@@ -6471,6 +6609,7 @@ function collectMissionConfigPayload() {
6471
6609
  modes: {},
6472
6610
  },
6473
6611
  };
6612
+ if (document.getElementById('config-role-worker-backend')) payload.roles = collectRolesPayload();
6474
6613
  for (const mode of CONFIG_PERSONA_MODES) {
6475
6614
  const el = document.getElementById(`config-persona-${mode.id}`);
6476
6615
  if (!el) continue;
@@ -6487,6 +6626,7 @@ const CONFIG_SNIPPET_GROUPS = {
6487
6626
  updateCheck: ['updateCheck'],
6488
6627
  audits: ['externalPlanReview'],
6489
6628
  personas: ['agentPersona'],
6629
+ roles: ['roles'],
6490
6630
  };
6491
6631
 
6492
6632
  function copyConfigSnippet(group) {
@@ -37,6 +37,26 @@ export const CONFIG_PERSONA_MODES: readonly ["continue-plan", "run-plan", "cli-r
37
37
  export const CONFIG_REVIEW_BACKENDS: readonly ["auto", "claude", "cursor"];
38
38
  export const CONFIG_REVIEW_MODES: readonly ["paste", "autonomous"];
39
39
  export const CONFIG_REVIEW_PREFLIGHT: readonly ["off", "warn", "block"];
40
+ export interface RoleCapability {
41
+ readonly workerModel: boolean;
42
+ readonly subworkerModel: boolean;
43
+ readonly reviewer: boolean;
44
+ }
45
+ export const ROLE_CAPABILITIES: Readonly<
46
+ Record<"claude" | "cursor-agent" | "codex" | "openrouter" | "cursor-acp", RoleCapability>
47
+ >;
48
+ export const CONFIG_ROLE_WORKER_BACKENDS: readonly string[];
49
+ export const CONFIG_ROLE_REVIEWER_BACKENDS: readonly string[];
50
+ export const CONFIG_ROLE_REVIEWER_SCOPES: readonly string[];
51
+ export const ROLE_MODEL_ID: RegExp;
52
+ export function validateRolesPatch(
53
+ roles: unknown,
54
+ ): { ok: true; patch: Record<string, Record<string, unknown>> } | { ok: false; error: string };
55
+ export function mergeRoles(
56
+ existing: unknown,
57
+ patch: Record<string, Record<string, unknown>>,
58
+ ): Record<string, Record<string, unknown>>;
59
+ export function allowlistRoles(raw: unknown): Record<string, Record<string, unknown>> | null;
40
60
 
41
61
  export function escapePerlDoubleQuoted(value: string): string;
42
62
  export function resolveSnapshotRepoRoot(env: ProcessEnvLike | undefined, kitRoot: string): string;
@@ -584,6 +584,299 @@ export const CONFIG_REVIEW_MODES = Object.freeze(["paste", "autonomous"]);
584
584
  /** Allowed externalPlanReview.preflight values (audits pre-flight on plan-run commands). */
585
585
  export const CONFIG_REVIEW_PREFLIGHT = Object.freeze(["off", "warn", "block"]);
586
586
 
587
+ /**
588
+ * Per-backend role capabilities (docs/model-roles-capability-matrix.md).
589
+ * Mirror of ROLE_CAPABILITIES in packages/cli/src/plan-loop/model-roles.ts;
590
+ * a parity test keeps the two equal.
591
+ */
592
+ export const ROLE_CAPABILITIES = Object.freeze({
593
+ claude: Object.freeze({ workerModel: true, subworkerModel: true, reviewer: true }),
594
+ "cursor-agent": Object.freeze({ workerModel: true, subworkerModel: false, reviewer: true }),
595
+ codex: Object.freeze({ workerModel: true, subworkerModel: false, reviewer: false }),
596
+ openrouter: Object.freeze({ workerModel: true, subworkerModel: false, reviewer: false }),
597
+ "cursor-acp": Object.freeze({ workerModel: false, subworkerModel: false, reviewer: false }),
598
+ });
599
+
600
+ /** roles.worker.backend values: auto plus every kit backend id. */
601
+ export const CONFIG_ROLE_WORKER_BACKENDS = Object.freeze([
602
+ "auto",
603
+ ...Object.keys(ROLE_CAPABILITIES),
604
+ ]);
605
+
606
+ /** roles.reviewer.backend values (kit ids; the audits launcher's `cursor` is `cursor-agent`). */
607
+ export const CONFIG_ROLE_REVIEWER_BACKENDS = Object.freeze(["auto", "claude", "cursor-agent"]);
608
+
609
+ /** roles.reviewer.scope values. */
610
+ export const CONFIG_ROLE_REVIEWER_SCOPES = Object.freeze(["off", "tick", "plan"]);
611
+
612
+ /** Role model id: aliases, full ids, OpenRouter vendor/model, Cursor [k=v] parameters. */
613
+ export const ROLE_MODEL_ID = /^[A-Za-z0-9._:/+=,[\]-]{1,128}$/;
614
+
615
+ /** roles.subworker.byWorkerType keys (plan worker_type values). */
616
+ const ROLE_WORKER_TYPE_KEY = /^[a-z0-9][a-z0-9_-]{0,63}$/;
617
+
618
+ /**
619
+ * Validate one `roles` write. `null` clears a field. Values the capability
620
+ * matrix marks unsupported are rejected when the same write pins the backend.
621
+ * @param {unknown} roles
622
+ * @returns {{ ok: true, patch: Record<string, unknown> } | { ok: false, error: string }}
623
+ */
624
+ export function validateRolesPatch(roles) {
625
+ if (!roles || typeof roles !== "object" || Array.isArray(roles)) {
626
+ return { ok: false, error: "roles must be an object" };
627
+ }
628
+ for (const key of Object.keys(roles)) {
629
+ if (!["worker", "subworker", "reviewer"].includes(key)) {
630
+ return { ok: false, error: `unknown roles key: ${key}` };
631
+ }
632
+ }
633
+ /** @param {unknown} v @param {string} where */
634
+ const model = (v, where) => {
635
+ if (v === null || v === "") return { ok: true, value: null };
636
+ if (typeof v !== "string" || !ROLE_MODEL_ID.test(v.trim())) {
637
+ return { ok: false, error: `${where} must be a model id` };
638
+ }
639
+ return { ok: true, value: v.trim() };
640
+ };
641
+ /** @type {Record<string, Record<string, unknown>>} */
642
+ const patch = {};
643
+ /** @type {string | null | undefined} */
644
+ let workerBackend;
645
+ if ("worker" in roles) {
646
+ const w = roles.worker;
647
+ if (!w || typeof w !== "object" || Array.isArray(w)) {
648
+ return { ok: false, error: "roles.worker must be an object" };
649
+ }
650
+ /** @type {Record<string, unknown>} */
651
+ const wp = {};
652
+ for (const key of Object.keys(w)) {
653
+ if (key !== "backend" && key !== "model") {
654
+ return { ok: false, error: `unknown roles.worker key: ${key}` };
655
+ }
656
+ }
657
+ if ("backend" in w) {
658
+ if (w.backend === null || w.backend === "") {
659
+ wp.backend = null;
660
+ } else if (
661
+ typeof w.backend !== "string" ||
662
+ !CONFIG_ROLE_WORKER_BACKENDS.includes(w.backend)
663
+ ) {
664
+ return {
665
+ ok: false,
666
+ error: `roles.worker.backend must be one of: ${CONFIG_ROLE_WORKER_BACKENDS.join(", ")}`,
667
+ };
668
+ } else {
669
+ wp.backend = w.backend;
670
+ }
671
+ workerBackend = /** @type {string | null} */ (wp.backend);
672
+ }
673
+ if ("model" in w) {
674
+ const m = model(w.model, "roles.worker.model");
675
+ if (!m.ok) return { ok: false, error: m.error };
676
+ if (
677
+ m.value &&
678
+ workerBackend &&
679
+ workerBackend !== "auto" &&
680
+ !ROLE_CAPABILITIES[workerBackend].workerModel
681
+ ) {
682
+ return {
683
+ ok: false,
684
+ error: `roles.worker.model is not supported on ${workerBackend} (capability matrix)`,
685
+ };
686
+ }
687
+ wp.model = m.value;
688
+ }
689
+ patch.worker = wp;
690
+ }
691
+ if ("subworker" in roles) {
692
+ const s = roles.subworker;
693
+ if (!s || typeof s !== "object" || Array.isArray(s)) {
694
+ return { ok: false, error: "roles.subworker must be an object" };
695
+ }
696
+ /** @type {Record<string, unknown>} */
697
+ const sp = {};
698
+ for (const key of Object.keys(s)) {
699
+ if (key !== "model" && key !== "byWorkerType") {
700
+ return { ok: false, error: `unknown roles.subworker key: ${key}` };
701
+ }
702
+ }
703
+ let anyModel = false;
704
+ if ("model" in s) {
705
+ const m = model(s.model, "roles.subworker.model");
706
+ if (!m.ok) return { ok: false, error: m.error };
707
+ sp.model = m.value;
708
+ if (m.value && m.value !== "auto") anyModel = true;
709
+ }
710
+ if ("byWorkerType" in s) {
711
+ const map = s.byWorkerType;
712
+ if (map === null) {
713
+ sp.byWorkerType = null;
714
+ } else if (!map || typeof map !== "object" || Array.isArray(map)) {
715
+ return { ok: false, error: "roles.subworker.byWorkerType must be an object" };
716
+ } else {
717
+ /** @type {Record<string, string | null>} */
718
+ const mp = {};
719
+ for (const [type, value] of Object.entries(map)) {
720
+ if (!ROLE_WORKER_TYPE_KEY.test(type)) {
721
+ return {
722
+ ok: false,
723
+ error: `roles.subworker.byWorkerType key ${type} is not a worker_type`,
724
+ };
725
+ }
726
+ const m = model(value, `roles.subworker.byWorkerType.${type}`);
727
+ if (!m.ok) return { ok: false, error: m.error };
728
+ mp[type] = m.value;
729
+ if (m.value) anyModel = true;
730
+ }
731
+ sp.byWorkerType = mp;
732
+ }
733
+ }
734
+ if (
735
+ anyModel &&
736
+ workerBackend &&
737
+ workerBackend !== "auto" &&
738
+ !ROLE_CAPABILITIES[workerBackend].subworkerModel
739
+ ) {
740
+ return {
741
+ ok: false,
742
+ error: `roles.subworker model is not supported on ${workerBackend} (capability matrix)`,
743
+ };
744
+ }
745
+ patch.subworker = sp;
746
+ }
747
+ if ("reviewer" in roles) {
748
+ const r = roles.reviewer;
749
+ if (!r || typeof r !== "object" || Array.isArray(r)) {
750
+ return { ok: false, error: "roles.reviewer must be an object" };
751
+ }
752
+ /** @type {Record<string, unknown>} */
753
+ const rp = {};
754
+ for (const key of Object.keys(r)) {
755
+ if (!["enabled", "scope", "backend", "model", "advisorModel"].includes(key)) {
756
+ return { ok: false, error: `unknown roles.reviewer key: ${key}` };
757
+ }
758
+ }
759
+ if ("enabled" in r) {
760
+ if (r.enabled !== null && typeof r.enabled !== "boolean") {
761
+ return { ok: false, error: "roles.reviewer.enabled must be boolean" };
762
+ }
763
+ rp.enabled = r.enabled;
764
+ }
765
+ if ("scope" in r) {
766
+ if (r.scope !== null && !CONFIG_ROLE_REVIEWER_SCOPES.includes(r.scope)) {
767
+ return { ok: false, error: "roles.reviewer.scope must be off, tick, or plan" };
768
+ }
769
+ rp.scope = r.scope;
770
+ }
771
+ if ("backend" in r) {
772
+ if (r.backend !== null && !CONFIG_ROLE_REVIEWER_BACKENDS.includes(r.backend)) {
773
+ return { ok: false, error: "roles.reviewer.backend must be auto, claude, or cursor-agent" };
774
+ }
775
+ rp.backend = r.backend;
776
+ }
777
+ for (const key of ["model", "advisorModel"]) {
778
+ if (key in r) {
779
+ const m = model(r[key], `roles.reviewer.${key}`);
780
+ if (!m.ok) return { ok: false, error: m.error };
781
+ rp[key] = m.value;
782
+ }
783
+ }
784
+ patch.reviewer = rp;
785
+ }
786
+ return { ok: true, patch };
787
+ }
788
+
789
+ /**
790
+ * Merge a validated roles patch: per role, `null` deletes the field, `byWorkerType`
791
+ * replaces the whole map, and empty roles drop out.
792
+ * @param {unknown} existing
793
+ * @param {Record<string, Record<string, unknown>>} patch
794
+ */
795
+ export function mergeRoles(existing, patch) {
796
+ /** @type {Record<string, Record<string, unknown>>} */
797
+ const base =
798
+ existing && typeof existing === "object" && !Array.isArray(existing)
799
+ ? /** @type {any} */ ({ ...existing })
800
+ : {};
801
+ for (const [role, fields] of Object.entries(patch)) {
802
+ const prevRaw = base[role];
803
+ /** @type {Record<string, unknown>} */
804
+ const next =
805
+ prevRaw && typeof prevRaw === "object" && !Array.isArray(prevRaw) ? { ...prevRaw } : {};
806
+ for (const [key, value] of Object.entries(fields)) {
807
+ if (value === null) {
808
+ delete next[key];
809
+ } else if (key === "byWorkerType" && value && typeof value === "object") {
810
+ // The map is replaced as a whole (the Config tab sends the full map);
811
+ // null entries are dropped and an empty map clears the field.
812
+ /** @type {Record<string, unknown>} */
813
+ const map = {};
814
+ for (const [type, m] of Object.entries(value)) {
815
+ if (m !== null) map[type] = m;
816
+ }
817
+ if (Object.keys(map).length > 0) next.byWorkerType = map;
818
+ else delete next.byWorkerType;
819
+ } else {
820
+ next[key] = value;
821
+ }
822
+ }
823
+ if (Object.keys(next).length > 0) base[role] = next;
824
+ else delete base[role];
825
+ }
826
+ return base;
827
+ }
828
+
829
+ /**
830
+ * UI-safe copy of `roles` (strings truncated, unknown keys dropped).
831
+ * @param {unknown} raw
832
+ */
833
+ export function allowlistRoles(raw) {
834
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
835
+ /** @type {Record<string, Record<string, unknown>>} */
836
+ const out = {};
837
+ const src = /** @type {Record<string, any>} */ (raw);
838
+ const str = (/** @type {unknown} */ v, /** @type {number} */ n) =>
839
+ typeof v === "string" ? truncateStr(v, n) : undefined;
840
+ if (src.worker && typeof src.worker === "object") {
841
+ const w = {};
842
+ const b = str(src.worker.backend, 32);
843
+ const m = str(src.worker.model, 128);
844
+ if (b) w.backend = b;
845
+ if (m) w.model = m;
846
+ out.worker = w;
847
+ }
848
+ if (src.subworker && typeof src.subworker === "object") {
849
+ const s = {};
850
+ const m = str(src.subworker.model, 128);
851
+ if (m) s.model = m;
852
+ if (src.subworker.byWorkerType && typeof src.subworker.byWorkerType === "object") {
853
+ /** @type {Record<string, string>} */
854
+ const map = {};
855
+ for (const [type, value] of Object.entries(src.subworker.byWorkerType).slice(0, 64)) {
856
+ const v = str(value, 128);
857
+ if (v) map[truncateStr(type, 64)] = v;
858
+ }
859
+ s.byWorkerType = map;
860
+ }
861
+ out.subworker = s;
862
+ }
863
+ if (src.reviewer && typeof src.reviewer === "object") {
864
+ const r = {};
865
+ if (typeof src.reviewer.enabled === "boolean") r.enabled = src.reviewer.enabled;
866
+ for (const [key, n] of [
867
+ ["scope", 16],
868
+ ["backend", 32],
869
+ ["model", 128],
870
+ ["advisorModel", 128],
871
+ ]) {
872
+ const v = str(src.reviewer[key], n);
873
+ if (v) r[key] = v;
874
+ }
875
+ out.reviewer = r;
876
+ }
877
+ return out;
878
+ }
879
+
587
880
  /**
588
881
  * True when the remote address is loopback (IPv4, IPv6, or IPv4-mapped IPv6).
589
882
  * @param {string | undefined | null} addr
@@ -655,6 +948,7 @@ export function validateConfigWriteBody(body) {
655
948
  "fieldReportReviewCadence",
656
949
  "agentPersona",
657
950
  "updateCheck",
951
+ "roles",
658
952
  ]);
659
953
  for (const key of Object.keys(body)) {
660
954
  if (!allowedTop.has(key)) {
@@ -902,6 +1196,12 @@ export function validateConfigWriteBody(body) {
902
1196
  }
903
1197
  }
904
1198
 
1199
+ if ("roles" in body) {
1200
+ const roles = validateRolesPatch(body.roles);
1201
+ if (!roles.ok) return roles;
1202
+ if (Object.keys(roles.patch).length > 0) patch.roles = roles.patch;
1203
+ }
1204
+
905
1205
  if (Object.keys(patch).length === 0) {
906
1206
  return { ok: false, error: "no editable fields in body" };
907
1207
  }
@@ -959,6 +1259,11 @@ export function mergeConfigAllowlist(existing, patch) {
959
1259
  base.updateCheck && typeof base.updateCheck === "object" ? { ...base.updateCheck } : {};
960
1260
  base.updateCheck = { ...prev, ...patch.updateCheck };
961
1261
  }
1262
+ if (patch.roles && typeof patch.roles === "object") {
1263
+ const roles = mergeRoles(base.roles, patch.roles);
1264
+ if (Object.keys(roles).length > 0) base.roles = roles;
1265
+ else delete base.roles;
1266
+ }
962
1267
  return base;
963
1268
  }
964
1269
 
@@ -1031,6 +1336,8 @@ export function allowlistConfig(raw) {
1031
1336
  }
1032
1337
  summary.externalPlanReview = epr;
1033
1338
  }
1339
+ const roles = allowlistRoles(raw.roles);
1340
+ if (roles) summary.roles = roles;
1034
1341
  if (raw.agentPersona && typeof raw.agentPersona === "object") {
1035
1342
  const modes = {};
1036
1343
  if (raw.agentPersona.modes && typeof raw.agentPersona.modes === "object") {