claude-code-session-manager 0.128.0 → 0.130.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 (108) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +2 -0
  3. package/dist/assets/AgentLibrary-ctvNes4y.js +2 -0
  4. package/dist/assets/AppSettings-C03qTDSi.js +2 -0
  5. package/dist/assets/Button-fOCJry21.js +1 -0
  6. package/dist/assets/Extensions-BWiDwigT.js +13 -0
  7. package/dist/assets/{History-4rrDdWNP.js → History-BIQFPXM8.js} +2 -2
  8. package/dist/assets/Library-BGmD-xZN.js +32 -0
  9. package/dist/assets/ListDetail-BeO3lY8t.js +1 -0
  10. package/dist/assets/{Memory-DgQlvQrO.js → Memory-BeXuYIcE.js} +8 -8
  11. package/dist/assets/{Panel-DZHiD8Ar.js → Panel-OUbLHNsS.js} +1 -1
  12. package/dist/assets/ProvenanceBadge-kr7arZqu.js +1 -0
  13. package/dist/assets/Scheduler-DycegnjH.js +16 -0
  14. package/dist/assets/Settings-BSq6VASG.js +2 -0
  15. package/dist/assets/{SkillReferenceGraph-C5lKqf5y.js → SkillReferenceGraph-CvPdxg56.js} +1 -1
  16. package/dist/assets/SourceChip-C2YMnlV8.js +1 -0
  17. package/dist/assets/SystemPrompt-fpXEK_Rm.js +1 -0
  18. package/dist/assets/{TiptapBody-C2Iu6rZd.js → TiptapBody-DusJg0je.js} +1 -1
  19. package/dist/assets/{Toggle-C-oD66BG.js → Toggle-BnJF4V6k.js} +1 -1
  20. package/dist/assets/ViewTabs-BYrRSHb6.js +1 -0
  21. package/dist/assets/VoiceButton-Bk66E-fP.js +1 -0
  22. package/dist/assets/{historyTotals-CbRSLD8f.js → historyTotals-DnuVADtI.js} +1 -1
  23. package/dist/assets/{index-DtdWBGrI.css → index-Bp8XE9A6.css} +1 -1
  24. package/dist/assets/index-DfWJO7nP.js +3086 -0
  25. package/dist/index.html +2 -2
  26. package/dist-web/app.css +1 -1
  27. package/dist-web/app.js +391 -405
  28. package/package.json +1 -1
  29. package/plugins/CLAUDE.md +2 -2
  30. package/plugins/session-manager-dev/.claude-plugin/plugin.json +2 -2
  31. package/plugins/session-manager-dev/skills/builder/4-manual/SKILL.md +2 -2
  32. package/plugins/session-manager-dev/skills/develop/SKILL.md +7 -5
  33. package/plugins/session-manager-dev/skills/maintaining-md-network/SKILL.md +62 -0
  34. package/plugins/session-manager-dev/skills/maintaining-md-network/audit.md +169 -0
  35. package/plugins/session-manager-dev/skills/maintaining-md-network/drift-check.md +183 -0
  36. package/plugins/session-manager-dev/skills/maintaining-md-network/placement.md +39 -0
  37. package/plugins/session-manager-dev/skills/maintaining-md-network/plan.md +79 -0
  38. package/plugins/session-manager-dev/skills/maintaining-md-network/scripts/drift-check.cjs +400 -0
  39. package/scripts/hooks/lib/guard-inline-implementation-policy.cjs +10 -0
  40. package/scripts/scheduler-mcp-server.cjs +25 -6
  41. package/src/main/agentLibrary.cjs +36 -10
  42. package/src/main/build-info.json +4 -4
  43. package/src/main/chatRunner.cjs +8 -0
  44. package/src/main/config.cjs +15 -0
  45. package/src/main/health.cjs +49 -22
  46. package/src/main/index.cjs +32 -3
  47. package/src/main/ipcSchemas.cjs +39 -4
  48. package/src/main/lib/claude/agentModelResolve.cjs +5 -3
  49. package/src/main/lib/claude/effectiveModelInfo.cjs +14 -4
  50. package/src/main/lib/claude/modelCatalog.cjs +26 -15
  51. package/src/main/lib/claudeConfig.cjs +156 -0
  52. package/src/main/lib/effectiveSettings.cjs +120 -0
  53. package/src/main/lib/epic/delegationReadiness.cjs +3 -3
  54. package/src/main/lib/epic/developLoopSpawn.cjs +18 -0
  55. package/src/main/lib/epic/epicMint.cjs +4 -2
  56. package/src/main/lib/epic/promptSessionsCreateEpic.cjs +4 -3
  57. package/src/main/lib/feedback-remote/crossProjectFeedback.cjs +21 -21
  58. package/src/main/lib/feedback-remote/macroAdminRoutes.cjs +84 -11
  59. package/src/main/lib/git/gitWorktree.cjs +400 -9
  60. package/src/main/lib/git/runtimeStateUntrack.cjs +124 -0
  61. package/src/main/lib/mcpToolCatalog.cjs +8 -2
  62. package/src/main/lib/memoryDirResolve.cjs +2 -8
  63. package/src/main/lib/opsOwnership.cjs +63 -2
  64. package/src/main/lib/persona-macro/builtinMacros.cjs +30 -0
  65. package/src/main/lib/persona-macro/macroLibrary.cjs +34 -6
  66. package/src/main/lib/persona-macro/shippedPersonaSeeds.cjs +46 -0
  67. package/src/main/lib/prd/prdCreate.cjs +15 -0
  68. package/src/main/lib/promptSessionSchema.cjs +8 -0
  69. package/src/main/lib/updateCheck.cjs +6 -1
  70. package/src/main/pluginInstall.cjs +100 -1
  71. package/src/main/scheduler.cjs +12 -2
  72. package/src/main/seedDevPlugin.cjs +2 -1
  73. package/src/main/templates/PRD_AUTHORING.md +3 -3
  74. package/src/main/updaterIpc.cjs +5 -1
  75. package/src/main/usage.cjs +5 -20
  76. package/src/main/voiceHotkey.cjs +16 -0
  77. package/src/main/voiceSettings.cjs +24 -0
  78. package/src/main/voiceWizard.cjs +27 -36
  79. package/src/preload/api.d.ts +59 -3
  80. package/src/preload/apiSurface.json +70 -7
  81. package/src/preload/index.cjs +17 -1
  82. package/src/seed/agents/architect.md +8 -8
  83. package/src/seed/agents/demo-video-builder.md +2 -2
  84. package/src/seed/agents/validator.md +2 -2
  85. package/dist/assets/AgentLibrary-cNQU5YWy.js +0 -2
  86. package/dist/assets/Button-9dIPAOBg.js +0 -1
  87. package/dist/assets/DataModel-DrDJ6ysw.js +0 -1
  88. package/dist/assets/Hooks-Bj_jF5Pa.js +0 -3
  89. package/dist/assets/Library-D-Wsxrh7.js +0 -46
  90. package/dist/assets/ListDetail-D7Om0H8j.js +0 -1
  91. package/dist/assets/McpServers-CbIbSd5o.js +0 -2
  92. package/dist/assets/Permissions-CfzduF4B.js +0 -3
  93. package/dist/assets/Plugins-D-AG5nAo.js +0 -2
  94. package/dist/assets/ProvenanceBadge-B9JSEjll.js +0 -1
  95. package/dist/assets/SaveBar-mVKig6hL.js +0 -1
  96. package/dist/assets/Scheduler-DFTCnh60.js +0 -16
  97. package/dist/assets/ScopeSwitcher-s8J-yr7Z.js +0 -1
  98. package/dist/assets/Settings-BTmxRMaP.js +0 -4
  99. package/dist/assets/Skills-CxOacq0k.js +0 -2
  100. package/dist/assets/SystemPrompt-BCWg5FAz.js +0 -1
  101. package/dist/assets/TagLibrary-BnF0_PkG.js +0 -1
  102. package/dist/assets/ViewTabs-Cs4v7vLY.js +0 -1
  103. package/dist/assets/index-DzY_GXYY.js +0 -3081
  104. package/dist/assets/listSkills-C1aWKf0T.js +0 -1
  105. package/dist/assets/settingsSchema-bSBfHuan.js +0 -1
  106. package/dist/assets/skillFrontmatter-BEseWm8r.js +0 -10
  107. package/dist/assets/useAgentsDirWatch-CdyHxKCI.js +0 -1
  108. package/src/main/lib/epic/epicStandingInstructions.cjs +0 -73
@@ -25,8 +25,9 @@ const { REVERIFY_INTERVAL_MS } = require('./scheduler/reviewLadder.cjs');
25
25
  const { findStarvedProjects, findUnresolvableDepRoots, DEFAULT_PROJECT_CWD, DEP_HISTORY_FAIL_OPEN } = require('./lib/scheduler/schedulerBatch.cjs');
26
26
  const { auditLogPath, readTail } = require('./lib/telemetry/auditLog.cjs');
27
27
  const { checkMainDependencyHealth } = require('./lib/git/depHealth.cjs');
28
+ const { findTrackedRuntimeState } = require('./lib/git/runtimeStateUntrack.cjs');
28
29
  const { resolveBuildIdentity } = require('./lib/buildIdentity.cjs');
29
- const { computeReport, isRetentionEnabled, liveKeysFromJobs } = require('./lib/scheduler/runLogRetention.cjs');
30
+ const { computeReport, isRetentionEnabled, liveKeysFromJobs, resolveRetentionConfig } = require('./lib/scheduler/runLogRetention.cjs');
30
31
  const { allProjectCwds } = require('./lib/activeSessions.cjs');
31
32
  const { scanEpicTranscripts } = require('./lib/epic/epicTranscriptDiagnostic.cjs');
32
33
 
@@ -1271,27 +1272,7 @@ async function check(opts = {}) {
1271
1272
  // model. schedulerRunLogRetention lives in scheduler-machine.json's
1272
1273
  // `config`, same home as every other scheduler machine setting.
1273
1274
  try {
1274
- const retentionCfg = queueState?.config?.schedulerRunLogRetention;
1275
- const runsDir = schedulerPaths.runsDir();
1276
- const liveKeys = liveKeysFromJobs(queueState?.jobs || [], { runsDir });
1277
- const report = computeReport(
1278
- runsDir,
1279
- retentionCfg?.policy || {},
1280
- { liveKeys }
1281
- );
1282
- status.components.run_log_retention = {
1283
- ok: true,
1284
- path: runsDir,
1285
- totalBytes: report.usage.totalBytes,
1286
- dirCount: report.usage.dirCount,
1287
- runCount: report.usage.runCount,
1288
- oldestRunAt: report.usage.oldestRunAt,
1289
- policyConfigured: !!retentionCfg?.policy,
1290
- retentionEnabled: isRetentionEnabled(queueState?.config || {}),
1291
- wouldRemoveCount: report.eligibleSummary.count,
1292
- wouldRemoveBytes: report.eligibleSummary.bytes,
1293
- wouldRemoveDirs: report.removableDirs.length,
1294
- };
1275
+ status.components.run_log_retention = evaluateRunLogRetention(queueState);
1295
1276
  } catch (e) {
1296
1277
  status.components.run_log_retention = { ok: true, error: e.message };
1297
1278
  }
@@ -1384,6 +1365,26 @@ async function check(opts = {}) {
1384
1365
  }
1385
1366
  }
1386
1367
 
1368
+ // 6.76. Tracked runtime state: projects that committed Session Manager
1369
+ // runtime namespaces. Warning only (never flips ok) — untrack via
1370
+ // runtimeStateUntrack.untrackRuntimeState from the project's main checkout.
1371
+ try {
1372
+ const roots = [...new Set(allProjectCwds())].slice(0, 100).filter((cwd) => fs.existsSync(cwd));
1373
+ const hits = [];
1374
+ for (const cwd of roots) {
1375
+ const n = (await findTrackedRuntimeState(cwd)).length;
1376
+ if (n > 0) hits.push({ cwd, count: n });
1377
+ }
1378
+ status.components.tracked_runtime_state = hits.length === 0
1379
+ ? { ok: true }
1380
+ : { ok: true, warn: true, projects: hits };
1381
+ for (const h of hits) {
1382
+ status.issues.push(`warn: ${h.cwd} tracks ${h.count} Session Manager runtime-state file(s) in git — untrack from its main checkout`);
1383
+ }
1384
+ } catch (e) {
1385
+ status.components.tracked_runtime_state = { ok: true, error: e.message };
1386
+ }
1387
+
1387
1388
  // 6.8. Credential health (informational-but-loud): is the Claude OAuth token
1388
1389
  // usable? An expired/absent token silently voids every headless `claude -p`
1389
1390
  // job — the queue "runs" but nothing authenticates. refreshIfNeeded() reads
@@ -1420,8 +1421,34 @@ if (require.main === module) {
1420
1421
  })();
1421
1422
  }
1422
1423
 
1424
+ /**
1425
+ * Run-log retention component. Resolves the policy through runLogRetention.cjs's
1426
+ * resolveRetentionConfig (ops-retention.json first, as the runtime does).
1427
+ */
1428
+ function evaluateRunLogRetention(queueState) {
1429
+ const retentionCfg = resolveRetentionConfig(queueState?.config || {});
1430
+ const runsDir = schedulerPaths.runsDir();
1431
+ const liveKeys = liveKeysFromJobs(queueState?.jobs || [], { runsDir });
1432
+ const report = computeReport(runsDir, retentionCfg?.policy || {}, { liveKeys });
1433
+ return {
1434
+ ok: true,
1435
+ path: runsDir,
1436
+ totalBytes: report.usage.totalBytes,
1437
+ dirCount: report.usage.dirCount,
1438
+ runCount: report.usage.runCount,
1439
+ oldestRunAt: report.usage.oldestRunAt,
1440
+ policyConfigured: !!retentionCfg?.policy,
1441
+ retentionEnabled: isRetentionEnabled(queueState?.config || {}),
1442
+ policy: retentionCfg?.policy || null,
1443
+ wouldRemoveCount: report.eligibleSummary.count,
1444
+ wouldRemoveBytes: report.eligibleSummary.bytes,
1445
+ wouldRemoveDirs: report.removableDirs.length,
1446
+ };
1447
+ }
1448
+
1423
1449
  module.exports = {
1424
1450
  check,
1451
+ evaluateRunLogRetention,
1425
1452
  evaluateTickLiveness,
1426
1453
  readFreshHeartbeat,
1427
1454
  lastTickFromHeartbeat,
@@ -59,7 +59,6 @@ try {
59
59
  }
60
60
  crashDiagnostics.startCrashReporter();
61
61
  const voiceHotkey = require('./voiceHotkey.cjs');
62
- const voiceWizard = require('./voiceWizard.cjs');
63
62
  const scheduler = require('./scheduler.cjs');
64
63
  const { createAdminHttp } = require('./lib/feedback-remote/localAdminHttp.cjs');
65
64
  const prdCreate = require('./lib/prd/prdCreate.cjs');
@@ -571,7 +570,6 @@ function createWindow() {
571
570
 
572
571
  ipcMain.handle('app:version', () => app.getVersion());
573
572
 
574
- ipcMain.handle('app:update-status', () => require('./lib/updateCheck.cjs').getUpdateStatus());
575
573
 
576
574
  ipcMain.handle('app:home-dir', () => os.homedir());
577
575
 
@@ -617,6 +615,20 @@ require('./lib/persona-macro/macroJobIpc.cjs').registerMacroJobIpc(ipcMain, {
617
615
  loadJobs: async () => (await require('./lib/scheduler/queueStore.cjs').readMerged()).jobs || [],
618
616
  archivePrd: (slug, cwd) => queueOps.archiveMany([slug], cwd),
619
617
  });
618
+ // claudeConfig (lib/claudeConfig.cjs): key-scoped read/patch of Claude's JSON config files.
619
+ // A successful patch broadcasts `config:changed` so renderer state refreshes.
620
+ ipcMain.handle('claudeConfig:read', validated(schemas.claudeConfigRead, async (p) => {
621
+ if (p.cwd) configMgr.validatePath(p.cwd);
622
+ return require('./lib/claudeConfig.cjs').read(p);
623
+ }));
624
+ ipcMain.handle('claudeConfig:patch', validated(schemas.claudeConfigPatch, async (p) => {
625
+ if (p.cwd) configMgr.validatePath(p.cwd);
626
+ const result = await require('./lib/claudeConfig.cjs').patch(p);
627
+ let mtimeMs = 0;
628
+ try { mtimeMs = (await require('node:fs/promises').stat(result.path)).mtimeMs; } catch { /* ignore */ }
629
+ sendIfAlive(mainWindow, 'config:changed', { path: result.path, mtimeMs, kind: 'change' });
630
+ return result;
631
+ }));
620
632
  ipcMain.handle('macros:save', validated(schemas.macrosSave, async (payload) => {
621
633
  const macro = await macroLibrary.saveMacro(payload);
622
634
  broadcastMacrosChanged();
@@ -627,6 +639,11 @@ ipcMain.handle('macros:delete', validated(schemas.macrosDelete, async (payload)
627
639
  broadcastMacrosChanged();
628
640
  return result;
629
641
  }));
642
+ ipcMain.handle('macros:remove-from-project', validated(schemas.macrosRemoveFromProject, async (payload) => {
643
+ const result = await macroLibrary.removeMacroFromProject(payload);
644
+ if (result.ok) broadcastMacrosChanged();
645
+ return result;
646
+ }));
630
647
  ipcMain.handle('macros:set-project', validated(schemas.macrosSetProject, async (payload) => {
631
648
  const result = await macroLibrary.setMacroProject(payload);
632
649
  if (result.ok) broadcastMacrosChanged();
@@ -1043,7 +1060,6 @@ layoutStore.registerLayoutHandlers();
1043
1060
  billing.registerBillingHandlers();
1044
1061
  logs.registerLogHandlers();
1045
1062
  voiceHotkey.registerHotkeyHandlers();
1046
- voiceWizard.registerWizardHandlers();
1047
1063
  scheduler.registerScheduleHandlers();
1048
1064
  watchers.registerWatcherHandlers();
1049
1065
  queueOps.registerQueueOpsHandlers({ retireCompletedSlugs: scheduler.retireCompletedSlugs });
@@ -1467,6 +1483,19 @@ app.whenReady().then(async () => {
1467
1483
  { role: 'selectAll' },
1468
1484
  ],
1469
1485
  },
1486
+ {
1487
+ label: 'Help',
1488
+ submenu: [
1489
+ {
1490
+ label: 'Book a Free Hour with Bilko',
1491
+ click: () => {
1492
+ if (mainWindow && !mainWindow.isDestroyed()) {
1493
+ sendIfAlive(mainWindow, 'app:open-free-hour');
1494
+ }
1495
+ },
1496
+ },
1497
+ ],
1498
+ },
1470
1499
  ];
1471
1500
  Menu.setApplicationMenu(Menu.buildFromTemplate(template));
1472
1501
 
@@ -13,7 +13,8 @@ const { PromptSessionSchema, EpicTagSchema, EpicSourceSchema, EpicIntakeSectionS
13
13
  const { PrdWorkTypeSchema } = require('./lib/prd/workTypeLibrary.cjs');
14
14
  const { PERSONA_NAME_RE } = require('./agentLibrary.cjs');
15
15
  const { AgentPersonaSaveSchema } = require('./lib/persona-macro/agentPersonaSchema.cjs');
16
- const { MacroSaveSchema, MacroDeleteSchema, MacroSetProjectSchema, MacroInputSchema } = require('./lib/persona-macro/macroLibrary.cjs');
16
+ const { MacroSaveSchema, MacroDeleteSchema, MacroSetProjectSchema, MacroRemoveFromProjectSchema, MacroInputSchema } = require('./lib/persona-macro/macroLibrary.cjs');
17
+ const { MAX_SLOTS } = require('./lib/scheduler/sessionSlots.cjs');
17
18
 
18
19
  // ──────────────────────────────────────────── PTY
19
20
  const ptySpawn = z.object({
@@ -226,6 +227,8 @@ const promptSessionsCreateEpic = z.object({
226
227
  // Per-Epic runtime overrides (New Session card) — absent = use the persona's own value.
227
228
  model: z.string().min(1).max(256).optional(),
228
229
  effort: z.string().min(1).max(64).optional(),
230
+ // false = develop loop off for this Epic's whole life; absent = on.
231
+ developLoop: z.boolean().optional(),
229
232
  source: EpicSourceSchema.optional(),
230
233
  // The full first-prompt body + its labeled sections (epicIntake.ts's
231
234
  // composeEpicIntake) — both optional, since not every mint caller (e.g. a
@@ -647,10 +650,10 @@ const setConfigSchema = z.object({
647
650
 
648
651
  // Machine-wide claude -p slot pool cap (sessionSlots.cjs) — deliberately its own
649
652
  // schema/channel rather than folded into setConfigSchema: it governs the shared
650
- // process pool, not any one project's scheduler config, and its range (0-10, 0
653
+ // process pool, not any one project's scheduler config, and its range (0-MAX_SLOTS, 0
651
654
  // pauses new launches) is the single concurrency control.
652
655
  const setSessionSlotsSchema = z.object({
653
- cap: z.number().int().min(0).max(10),
656
+ cap: z.number().int().min(0).max(MAX_SLOTS),
654
657
  }).strict();
655
658
 
656
659
  // ──────────────────────────────────────────── Agent Library
@@ -660,9 +663,25 @@ const setSessionSlotsSchema = z.object({
660
663
  // Full field-level rules live in lib/persona-macro/agentPersonaSchema.cjs, mirroring
661
664
  // AgentPersonaSaveInput (src/preload/api.d.ts) field-for-field.
662
665
  const agentsSavePersona = AgentPersonaSaveSchema;
666
+ // claudeConfig:read / claudeConfig:patch — mirrors ClaudeConfigReadInput /
667
+ // ClaudeConfigPatchInput (src/preload/api.d.ts). fileId comes from the registry in
668
+ // lib/claudeConfig.cjs; `value` absent => delete the key.
669
+ const CLAUDE_CONFIG_FILE_IDS = /** @type {[string, ...string[]]} */ (Object.keys(require('./lib/claudeConfig.cjs').REGISTRY));
670
+ const claudeConfigBase = {
671
+ fileId: z.enum(CLAUDE_CONFIG_FILE_IDS),
672
+ scope: z.enum(['user', 'project', 'local']),
673
+ cwd: z.string().min(1).max(4096).nullish(),
674
+ };
675
+ const claudeConfigRead = z.object(claudeConfigBase).strict();
676
+ const claudeConfigPatch = z.object({
677
+ ...claudeConfigBase,
678
+ keyPath: z.array(z.string().min(1).max(256)).min(1).max(8),
679
+ value: z.unknown().optional(),
680
+ }).strict();
663
681
  const macrosSave = MacroSaveSchema;
664
682
  const macrosDelete = MacroDeleteSchema;
665
683
  const macrosSetProject = MacroSetProjectSchema;
684
+ const macrosRemoveFromProject = MacroRemoveFromProjectSchema;
666
685
  // Background macro job (macroJobIpc.cjs): press a built-in macro as a scheduler PRD inside an existing Epic.
667
686
  const macrosDispatchJob = z.object({
668
687
  cwd: z.string().min(1).max(4096),
@@ -805,7 +824,7 @@ const agentsGetPersonaBody = z.object({
805
824
  // ──────────────────────────────────────────── Effective model info (PRD: what-will-this-run-as)
806
825
  const agentsResolveModelInfo = z.object({
807
826
  cwd: z.string().min(1).max(4096),
808
- agentType: z.string().min(1).max(200),
827
+ agentType: z.string().min(1).max(200).optional(),
809
828
  }).strict();
810
829
 
811
830
  // ──────────────────────────────────────────── Live model/effort catalog (modelCatalog.cjs)
@@ -982,6 +1001,7 @@ const AUDIT_LOG_KIND = z.enum([
982
1001
  'epic_delete',
983
1002
  'epic_resume',
984
1003
  'epic_duplicate',
1004
+ 'epic_draft_update',
985
1005
  ]);
986
1006
  const auditLogAppend = z.object({
987
1007
  kind: AUDIT_LOG_KIND,
@@ -1254,6 +1274,15 @@ const pluginsInstall = z.object({
1254
1274
  const pluginsAbort = z.object({
1255
1275
  slug: z.string().regex(PLUGIN_SLUG_RE).min(1).max(128),
1256
1276
  }).passthrough();
1277
+ const pluginsList = z.object({}).strict();
1278
+ const pluginsSetEnabled = z.object({
1279
+ key: z.string().regex(/^[a-z0-9][a-z0-9._\-]*@[a-z0-9][a-z0-9._\-]*$/i).max(256),
1280
+ enabled: z.boolean(),
1281
+ }).strict();
1282
+ const pluginsUninstall = z.object({
1283
+ slug: z.string().regex(PLUGIN_SLUG_RE).min(1).max(128),
1284
+ marketplaceName: z.string().regex(PLUGIN_SLUG_RE).min(1).max(128),
1285
+ }).strict();
1257
1286
 
1258
1287
  // ──────────────────────────────────────────── Product telemetry (bilko.run)
1259
1288
  // Mirrors telemetrySettings.cjs's own isValid() shape — the renderer always
@@ -1432,6 +1461,9 @@ module.exports = {
1432
1461
  repoAnalyze,
1433
1462
  pluginsInstall,
1434
1463
  pluginsAbort,
1464
+ pluginsList,
1465
+ pluginsSetEnabled,
1466
+ pluginsUninstall,
1435
1467
  memoryList,
1436
1468
  memoryRead,
1437
1469
  memoryWrite,
@@ -1492,9 +1524,12 @@ module.exports = {
1492
1524
  remoteSessionPrds,
1493
1525
  exchangesList,
1494
1526
  agentsSavePersona,
1527
+ claudeConfigRead,
1528
+ claudeConfigPatch,
1495
1529
  macrosSave,
1496
1530
  macrosDelete,
1497
1531
  macrosSetProject,
1532
+ macrosRemoveFromProject,
1498
1533
  macrosDispatchJob,
1499
1534
  macrosJobStatus,
1500
1535
  agentsGetPersonaBody,
@@ -33,6 +33,7 @@ const os = require('node:os');
33
33
  const { splitFrontmatter } = require('../prd/prdFrontmatter.cjs');
34
34
  const { readActiveIndex, resolvePersonaPaths } = require('../epic/epicMint.cjs');
35
35
  const { resolveMergedPersona, PERSONA_NAME_RE } = require('../persona-macro/personaMerge.cjs');
36
+ const { readSettingsModel } = require('./modelCatalog.cjs');
36
37
  const configMgr = require('../../config.cjs');
37
38
  const { SHIPPED_PERSONA_SEEDS } = require('../persona-macro/shippedPersonaSeeds.cjs');
38
39
 
@@ -170,12 +171,13 @@ function resolveEpicModel({ cwd, claudeSessionId, fallbackModel = FALLBACK_MODEL
170
171
  const override = epicOverrideValue(epic, 'model');
171
172
  if (override && override !== 'inherit') return override;
172
173
  const agentType = epic?.agentType || null;
173
- if (!agentType) return fallbackModel;
174
+ const settingsOrFallback = () => readSettingsModel(cwd, deps) || fallbackModel || FALLBACK_MODEL;
175
+ if (!agentType) return settingsOrFallback();
174
176
  const model = readOverlayAwarePersonaModel(agentType, { ...deps, cwd });
175
- if (!model || model === 'inherit') return fallbackModel;
177
+ if (!model || model === 'inherit') return settingsOrFallback();
176
178
  return model;
177
179
  } catch {
178
- return fallbackModel;
180
+ return fallbackModel || FALLBACK_MODEL;
179
181
  }
180
182
  }
181
183
 
@@ -281,17 +281,24 @@ async function resolveEffectiveModelInfo({ cwd, agentType, deps = {} } = {}) {
281
281
  personaEffort: null,
282
282
  personaEffortSource: null,
283
283
  };
284
- if (!cwd || !agentType) return miss;
284
+ if (!cwd) return miss;
285
285
 
286
286
  try {
287
287
  const { projectRootOf } = deps.activeSessions || require('../activeSessions.cjs');
288
288
  const normalizedCwd = projectRootOf(path.resolve(cwd));
289
289
  if (!normalizedCwd) return miss;
290
290
 
291
- const { modelAlias, modelSource, provenance: personaProvenance } = await resolvePersonaModelAlias(normalizedCwd, agentType, deps);
292
- const { effort: personaEffort, source: personaEffortSource } = (deps.agentEffortResolve || require('./agentEffortResolve.cjs'))
291
+ let { modelAlias, modelSource, provenance: personaProvenance } = agentType
292
+ ? await resolvePersonaModelAlias(normalizedCwd, agentType, deps)
293
+ : { modelAlias: null, modelSource: 'fallback', provenance: {} };
294
+ if (!modelAlias) {
295
+ // No persona model (agentless, inherit or dangling): the launch uses the Claude settings model.
296
+ const settingsModel = (deps.readSettingsModel || require('./modelCatalog.cjs').readSettingsModel)(normalizedCwd, deps);
297
+ if (settingsModel) { modelAlias = settingsModel; modelSource = 'settings'; }
298
+ }
299
+ const { effort: personaEffort, source: personaEffortSource } = !agentType ? { effort: null, source: null } : (deps.agentEffortResolve || require('./agentEffortResolve.cjs'))
293
300
  .resolveEpicEffort({ cwd: normalizedCwd, agentType, deps });
294
- const result = { agentType, modelAlias, modelSource, personaProvenance, resolvedModelId: null, resolvedFrom: null, effortEnvReachable, personaEffort, personaEffortSource };
301
+ const result = { agentType: agentType || null, modelAlias, modelSource, personaProvenance, resolvedModelId: null, resolvedFrom: null, effortEnvReachable, personaEffort, personaEffortSource };
295
302
 
296
303
  if (isConcreteModelId(modelAlias)) {
297
304
  // Already a concrete pinned id — echo it back, fabricate no evidence.
@@ -299,6 +306,9 @@ async function resolveEffectiveModelInfo({ cwd, agentType, deps = {} } = {}) {
299
306
  return result;
300
307
  }
301
308
 
309
+ // Agentless: no per-agent evidence to look up (it would match every agentless job).
310
+ if (!agentType) return result;
311
+
302
312
  // Evidence is never derived via historyAggregator.cjs's resolvePricingKey
303
313
  // (which buckets any unknown id to 'sonnet' with estimated:true) —
304
314
  // deliberately: that is a pricing heuristic, and borrowing it here would
@@ -19,6 +19,7 @@
19
19
  const fs = require('node:fs');
20
20
  const os = require('node:os');
21
21
  const path = require('node:path');
22
+ const { effectiveSettings, pickByPrecedence } = require('../effectiveSettings.cjs');
22
23
 
23
24
  const CACHE_FILE = 'model-catalog.json';
24
25
  const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
@@ -114,22 +115,32 @@ function readSettingsEffortLevels(fsImpl) {
114
115
  } catch { return null; }
115
116
  }
116
117
 
118
+ function resolveRoot(cwd, d) {
119
+ if (!cwd) return null;
120
+ try { return (d.projectRootOf || require('../activeSessions.cjs').projectRootOf)(path.resolve(cwd)); } catch { return path.resolve(cwd); }
121
+ }
122
+
117
123
  function readAvailableModels(cwd, d, fsImpl) {
118
124
  const home = d.homeDir ? d.homeDir() : os.homedir();
119
- let root = null;
120
- if (cwd) {
121
- try { root = (d.projectRootOf || require('../activeSessions.cjs').projectRootOf)(path.resolve(cwd)); } catch { root = path.resolve(cwd); }
122
- }
123
- const files = [path.join(home, '.claude', 'settings.json')];
124
- if (root) files.push(path.join(root, '.claude', 'settings.json'), path.join(root, '.claude', 'settings.local.json'));
125
- let merged = null;
126
- for (const f of files) {
127
- try {
128
- const a = JSON.parse(fsImpl.readFileSync(f, 'utf8')).availableModels;
129
- if (Array.isArray(a)) merged = [...(merged || []), ...a.filter((x) => typeof x === 'string')];
130
- } catch { /* missing/unreadable scope */ }
131
- }
132
- return merged ? [...new Set(merged)] : null;
125
+ const { merged } = effectiveSettings({ home, cwd: resolveRoot(cwd, d), fs: fsImpl });
126
+ const a = merged.availableModels;
127
+ if (!Array.isArray(a)) return null;
128
+ return [...new Set(a.filter((x) => typeof x === 'string'))];
129
+ }
130
+
131
+ /**
132
+ * The `model` key of the effective Claude settings (managed > local > project > user):
133
+ * first non-empty string. Never throws; null when none.
134
+ */
135
+ function readSettingsModel(cwd, deps = {}) {
136
+ try {
137
+ const d = deps || {};
138
+ const home = d.homeDir ? d.homeDir() : os.homedir();
139
+ const layers = effectiveSettings({ home, cwd: resolveRoot(cwd, d), fs: d.fs || fs }).layers;
140
+ const m = pickByPrecedence(layers, 'model', (v) => typeof v === 'string' && v.trim() !== '');
141
+ if (typeof m === 'string') return m.trim();
142
+ } catch { /* never throws */ }
143
+ return null;
133
144
  }
134
145
 
135
146
  function readCache(file, fsImpl) {
@@ -240,4 +251,4 @@ function resolveModelCatalog({ cwd, force, deps } = {}) {
240
251
  return inFlight;
241
252
  }
242
253
 
243
- module.exports = { resolveModelCatalog, CATALOG_FLOOR, parseAliases, parseEffortLevels, scanModelIds };
254
+ module.exports = { resolveModelCatalog, readSettingsModel, CATALOG_FLOOR, parseAliases, parseEffortLevels, scanModelIds };
@@ -0,0 +1,156 @@
1
+ // @ts-check
2
+ 'use strict';
3
+
4
+ /**
5
+ * claudeConfig.cjs — registry of Claude Code's JSON config files plus a
6
+ * key-scoped patch(). patch() re-reads the file fresh under a per-file lock,
7
+ * sets (or deletes) ONE key path and writes atomically, so a stale renderer
8
+ * draft can never clobber keys the CLI (or another writer) changed meanwhile.
9
+ * Writes go through config.cjs writeJson => validatePath + validateWrite +
10
+ * lib/util/atomicFs.cjs. No IPC here.
11
+ */
12
+
13
+ const os = require('node:os');
14
+ const path = require('node:path');
15
+ const fsp = require('node:fs/promises');
16
+ const config = require('../config.cjs');
17
+
18
+ /** @typedef {'user'|'project'|'local'} Scope */
19
+ /** @typedef {{ scopes: Scope[], resolve: (scope: string, home: string, cwd?: string|null) => string|null }} FileSpec */
20
+
21
+ /** @type {Record<string, FileSpec>} */
22
+ const REGISTRY = {
23
+ settings: {
24
+ scopes: ['user', 'project', 'local'],
25
+ resolve: (scope, home, cwd) => {
26
+ if (scope === 'user') return path.join(home, '.claude', 'settings.json');
27
+ if (!cwd) return null;
28
+ if (scope === 'project') return path.join(cwd, '.claude', 'settings.json');
29
+ if (scope === 'local') return path.join(cwd, '.claude', 'settings.local.json');
30
+ return null;
31
+ },
32
+ },
33
+ claudeJson: {
34
+ scopes: ['user'],
35
+ resolve: (scope, home) => (scope === 'user' ? path.join(home, '.claude.json') : null),
36
+ },
37
+ mcpJson: {
38
+ scopes: ['project'],
39
+ resolve: (scope, _home, cwd) => (scope === 'project' && cwd ? path.join(cwd, '.mcp.json') : null),
40
+ },
41
+ };
42
+
43
+ /**
44
+ * @param {{ fileId: string, scope: string, cwd?: string|null, home?: string }} p
45
+ * @returns {string}
46
+ */
47
+ function resolvePath({ fileId, scope, cwd, home }) {
48
+ if (!Object.prototype.hasOwnProperty.call(REGISTRY, fileId)) {
49
+ throw new Error(`claudeConfig: unknown fileId "${fileId}"`);
50
+ }
51
+ const spec = REGISTRY[fileId];
52
+ if (!/** @type {string[]} */ (spec.scopes).includes(scope)) {
53
+ throw new Error(`claudeConfig: file "${fileId}" does not support scope "${scope}"`);
54
+ }
55
+ const abs = spec.resolve(scope, home || os.homedir(), cwd);
56
+ if (!abs) throw new Error(`claudeConfig: cannot resolve "${fileId}" at scope "${scope}" without a cwd`);
57
+ return abs;
58
+ }
59
+
60
+ /**
61
+ * Read + parse. Missing file => {}. Invalid JSON / non-object => throws naming the path.
62
+ * @param {string} abs
63
+ * @returns {Promise<Record<string, any>>}
64
+ */
65
+ async function readParsed(abs) {
66
+ let text;
67
+ try {
68
+ text = await fsp.readFile(abs, 'utf8');
69
+ } catch (e) {
70
+ if (/** @type {any} */ (e)?.code === 'ENOENT') return {};
71
+ throw e;
72
+ }
73
+ if (text.trim() === '') return {};
74
+ let parsed;
75
+ try {
76
+ parsed = JSON.parse(text);
77
+ } catch (e) {
78
+ throw new Error(`claudeConfig: ${abs} is not valid JSON (${/** @type {Error} */ (e).message})`);
79
+ }
80
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
81
+ throw new Error(`claudeConfig: ${abs} does not contain a JSON object`);
82
+ }
83
+ return parsed;
84
+ }
85
+
86
+ /**
87
+ * @param {{ fileId: string, scope: string, cwd?: string|null, home?: string }} p
88
+ * @returns {Promise<{ path: string, data: Record<string, any> }>}
89
+ */
90
+ async function read(p) {
91
+ const abs = resolvePath(p);
92
+ return { path: abs, data: await readParsed(abs) };
93
+ }
94
+
95
+ /** @type {Map<string, Promise<unknown>>} */
96
+ const locks = new Map();
97
+
98
+ /**
99
+ * @template T
100
+ * @param {string} key
101
+ * @param {() => Promise<T>} fn
102
+ * @returns {Promise<T>}
103
+ */
104
+ function withLock(key, fn) {
105
+ const prev = locks.get(key) || Promise.resolve();
106
+ const run = prev.then(fn, fn);
107
+ const tail = run.catch(() => {});
108
+ locks.set(key, tail);
109
+ tail.then(() => { if (locks.get(key) === tail) locks.delete(key); });
110
+ return run;
111
+ }
112
+
113
+ /** @param {string|string[]} keyPath */
114
+ function toSegments(keyPath) {
115
+ const segs = Array.isArray(keyPath) ? keyPath : String(keyPath).split('.');
116
+ if (!segs.length || segs.some((s) => typeof s !== 'string' || s === '')) {
117
+ throw new Error('claudeConfig: keyPath must be non-empty');
118
+ }
119
+ if (segs.some((s) => s === '__proto__' || s === 'constructor' || s === 'prototype')) {
120
+ throw new Error('claudeConfig: forbidden keyPath segment');
121
+ }
122
+ return segs;
123
+ }
124
+
125
+ /**
126
+ * Set one key path (value === undefined deletes it) under the per-file lock.
127
+ * @param {{ fileId: string, scope: string, cwd?: string|null, keyPath: string|string[], value: any, home?: string }} p
128
+ * @returns {Promise<{ ok: true, path: string, data: Record<string, any> }>}
129
+ */
130
+ async function patch(p) {
131
+ const abs = resolvePath(p);
132
+ const segs = toSegments(p.keyPath);
133
+ return withLock(abs, async () => {
134
+ const data = await readParsed(abs);
135
+ let node = data;
136
+ if (p.value === undefined) {
137
+ for (let i = 0; i < segs.length - 1; i++) {
138
+ const next = node[segs[i]];
139
+ if (!next || typeof next !== 'object') { node = /** @type {any} */ (null); break; }
140
+ node = next;
141
+ }
142
+ if (node) delete node[segs[segs.length - 1]];
143
+ } else {
144
+ for (let i = 0; i < segs.length - 1; i++) {
145
+ const next = node[segs[i]];
146
+ if (!next || typeof next !== 'object' || Array.isArray(next)) node[segs[i]] = {};
147
+ node = node[segs[i]];
148
+ }
149
+ node[segs[segs.length - 1]] = p.value;
150
+ }
151
+ await config.writeJson(abs, data);
152
+ return { ok: /** @type {const} */ (true), path: abs, data };
153
+ });
154
+ }
155
+
156
+ module.exports = { REGISTRY, read, patch };