chainlesschain 0.81.0 → 0.143.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 (209) hide show
  1. package/bin/chainlesschain.js +0 -0
  2. package/package.json +1 -1
  3. package/src/commands/a2a.js +62 -0
  4. package/src/commands/activitypub.js +61 -0
  5. package/src/commands/agent-network.js +254 -1
  6. package/src/commands/agent.js +117 -0
  7. package/src/commands/audit.js +302 -0
  8. package/src/commands/automation.js +271 -1
  9. package/src/commands/bi.js +61 -0
  10. package/src/commands/bm25.js +78 -0
  11. package/src/commands/browse.js +64 -0
  12. package/src/commands/ccron.js +78 -0
  13. package/src/commands/codegen.js +224 -0
  14. package/src/commands/collab.js +341 -0
  15. package/src/commands/compliance.js +1075 -0
  16. package/src/commands/compt.js +78 -0
  17. package/src/commands/consol.js +231 -0
  18. package/src/commands/cowork.js +263 -0
  19. package/src/commands/crosschain.js +62 -0
  20. package/src/commands/dao.js +62 -0
  21. package/src/commands/dbevo.js +284 -0
  22. package/src/commands/dev.js +252 -0
  23. package/src/commands/did.js +358 -0
  24. package/src/commands/dlp.js +61 -0
  25. package/src/commands/economy.js +56 -0
  26. package/src/commands/encrypt.js +341 -0
  27. package/src/commands/evolution.js +56 -0
  28. package/src/commands/evomap.js +61 -0
  29. package/src/commands/export.js +256 -1
  30. package/src/commands/fflag.js +178 -0
  31. package/src/commands/fusion.js +258 -0
  32. package/src/commands/git.js +45 -0
  33. package/src/commands/governance.js +325 -0
  34. package/src/commands/hardening.js +411 -0
  35. package/src/commands/hmemory.js +56 -0
  36. package/src/commands/hook.js +148 -0
  37. package/src/commands/import.js +252 -0
  38. package/src/commands/incentive.js +322 -0
  39. package/src/commands/inference.js +42 -0
  40. package/src/commands/infra.js +244 -0
  41. package/src/commands/instinct.js +260 -0
  42. package/src/commands/ipfs.js +318 -0
  43. package/src/commands/itbudget.js +45 -0
  44. package/src/commands/kg.js +387 -0
  45. package/src/commands/llm.js +263 -0
  46. package/src/commands/lowcode.js +44 -0
  47. package/src/commands/matrix.js +62 -0
  48. package/src/commands/mcp.js +221 -0
  49. package/src/commands/mcpscaf.js +41 -0
  50. package/src/commands/meminj.js +41 -0
  51. package/src/commands/memory.js +248 -0
  52. package/src/commands/multimodal.js +296 -0
  53. package/src/commands/nlprog.js +356 -0
  54. package/src/commands/nostr.js +62 -0
  55. package/src/commands/note.js +244 -0
  56. package/src/commands/ops.js +354 -0
  57. package/src/commands/orchestrate.js +166 -0
  58. package/src/commands/orchgov.js +45 -0
  59. package/src/commands/org.js +277 -0
  60. package/src/commands/p2p.js +390 -0
  61. package/src/commands/pdfp.js +78 -0
  62. package/src/commands/perception.js +290 -0
  63. package/src/commands/perf.js +39 -0
  64. package/src/commands/perm.js +45 -0
  65. package/src/commands/permmem.js +251 -0
  66. package/src/commands/pipeline.js +57 -1
  67. package/src/commands/planmode.js +45 -0
  68. package/src/commands/plugin-ecosystem.js +273 -0
  69. package/src/commands/pqc.js +393 -0
  70. package/src/commands/promcomp.js +82 -0
  71. package/src/commands/quantization.js +351 -0
  72. package/src/commands/rcache.js +271 -0
  73. package/src/commands/recommend.js +382 -0
  74. package/src/commands/runtime.js +307 -0
  75. package/src/commands/scim.js +262 -0
  76. package/src/commands/seshhook.js +41 -0
  77. package/src/commands/seshsearch.js +41 -0
  78. package/src/commands/seshtail.js +41 -0
  79. package/src/commands/seshu.js +41 -0
  80. package/src/commands/session.js +258 -0
  81. package/src/commands/sganal.js +78 -0
  82. package/src/commands/siem.js +40 -0
  83. package/src/commands/skill.js +267 -1
  84. package/src/commands/slotfill.js +41 -0
  85. package/src/commands/social.js +290 -0
  86. package/src/commands/sso.js +186 -1
  87. package/src/commands/svccont.js +45 -0
  88. package/src/commands/sync.js +256 -0
  89. package/src/commands/tech.js +338 -0
  90. package/src/commands/tenant.js +351 -0
  91. package/src/commands/tms.js +45 -0
  92. package/src/commands/tokens.js +269 -0
  93. package/src/commands/topiccls.js +45 -0
  94. package/src/commands/trust.js +249 -0
  95. package/src/commands/uprof.js +45 -0
  96. package/src/commands/vcheck.js +78 -0
  97. package/src/commands/wallet.js +277 -0
  98. package/src/commands/webfetch.js +41 -0
  99. package/src/commands/workflow.js +171 -0
  100. package/src/commands/zkp.js +62 -0
  101. package/src/harness/prompt-compressor.js +331 -0
  102. package/src/index.js +65 -1
  103. package/src/lib/a2a-protocol.js +105 -0
  104. package/src/lib/activitypub-bridge.js +105 -0
  105. package/src/lib/agent-coordinator.js +325 -0
  106. package/src/lib/agent-economy.js +105 -0
  107. package/src/lib/agent-network.js +387 -0
  108. package/src/lib/agent-router.js +395 -0
  109. package/src/lib/aiops.js +478 -0
  110. package/src/lib/app-builder.js +105 -0
  111. package/src/lib/audit-logger.js +379 -0
  112. package/src/lib/automation-engine.js +330 -0
  113. package/src/lib/autonomous-agent.js +105 -0
  114. package/src/lib/autonomous-developer.js +350 -0
  115. package/src/lib/bi-engine.js +105 -0
  116. package/src/lib/bm25-search.js +81 -0
  117. package/src/lib/browser-automation.js +105 -0
  118. package/src/lib/code-agent.js +323 -0
  119. package/src/lib/collaboration-governance.js +364 -0
  120. package/src/lib/community-governance.js +436 -0
  121. package/src/lib/compliance-framework-reporter.js +105 -0
  122. package/src/lib/compliance-manager.js +434 -0
  123. package/src/lib/compression-telemetry.js +81 -0
  124. package/src/lib/content-recommendation.js +469 -0
  125. package/src/lib/content-recommender.js +105 -0
  126. package/src/lib/cowork-cron.js +81 -0
  127. package/src/lib/cowork-task-runner.js +105 -0
  128. package/src/lib/cross-chain.js +105 -0
  129. package/src/lib/crypto-manager.js +350 -0
  130. package/src/lib/dao-governance.js +105 -0
  131. package/src/lib/dbevo.js +338 -0
  132. package/src/lib/decentral-infra.js +340 -0
  133. package/src/lib/did-manager.js +367 -0
  134. package/src/lib/dlp-engine.js +105 -0
  135. package/src/lib/evolution-system.js +105 -0
  136. package/src/lib/evomap-manager.js +105 -0
  137. package/src/lib/execution-backend.js +105 -0
  138. package/src/lib/feature-flags.js +85 -0
  139. package/src/lib/git-integration.js +105 -0
  140. package/src/lib/hardening-manager.js +348 -0
  141. package/src/lib/hierarchical-memory.js +105 -0
  142. package/src/lib/hook-manager.js +380 -0
  143. package/src/lib/inference-network.js +105 -0
  144. package/src/lib/instinct-manager.js +332 -0
  145. package/src/lib/ipfs-storage.js +334 -0
  146. package/src/lib/iteration-budget.js +105 -0
  147. package/src/lib/knowledge-exporter.js +381 -0
  148. package/src/lib/knowledge-graph.js +432 -0
  149. package/src/lib/knowledge-importer.js +379 -0
  150. package/src/lib/llm-providers.js +391 -0
  151. package/src/lib/matrix-bridge.js +105 -0
  152. package/src/lib/mcp-registry.js +333 -0
  153. package/src/lib/mcp-scaffold.js +81 -0
  154. package/src/lib/memory-injection.js +81 -0
  155. package/src/lib/memory-manager.js +330 -0
  156. package/src/lib/multimodal.js +346 -0
  157. package/src/lib/nl-programming.js +343 -0
  158. package/src/lib/nostr-bridge.js +105 -0
  159. package/src/lib/note-versioning.js +327 -0
  160. package/src/lib/orchestrator.js +105 -0
  161. package/src/lib/org-manager.js +323 -0
  162. package/src/lib/p2p-manager.js +387 -0
  163. package/src/lib/pdf-parser.js +81 -0
  164. package/src/lib/perception.js +346 -0
  165. package/src/lib/perf-tuning.js +109 -1
  166. package/src/lib/permanent-memory.js +320 -0
  167. package/src/lib/permission-engine.js +81 -0
  168. package/src/lib/pipeline-orchestrator.js +105 -0
  169. package/src/lib/plan-mode.js +81 -0
  170. package/src/lib/plugin-ecosystem.js +377 -0
  171. package/src/lib/pqc-manager.js +368 -0
  172. package/src/lib/prompt-compressor.js +1 -10
  173. package/src/lib/protocol-fusion.js +417 -0
  174. package/src/lib/quantization.js +325 -0
  175. package/src/lib/response-cache.js +327 -0
  176. package/src/lib/scim-manager.js +329 -0
  177. package/src/lib/service-container.js +81 -0
  178. package/src/lib/session-consolidator.js +105 -0
  179. package/src/lib/session-hooks.js +81 -0
  180. package/src/lib/session-manager.js +329 -0
  181. package/src/lib/session-search.js +81 -0
  182. package/src/lib/session-tail.js +81 -0
  183. package/src/lib/session-usage.js +83 -0
  184. package/src/lib/siem-exporter.js +105 -0
  185. package/src/lib/skill-loader.js +377 -0
  186. package/src/lib/slot-filler.js +81 -0
  187. package/src/lib/social-graph-analytics.js +81 -0
  188. package/src/lib/social-graph.js +81 -0
  189. package/src/lib/social-manager.js +326 -0
  190. package/src/lib/sso-manager.js +332 -0
  191. package/src/lib/sub-agent-registry.js +110 -0
  192. package/src/lib/sync-manager.js +326 -0
  193. package/src/lib/task-model-selector.js +81 -0
  194. package/src/lib/tech-learning-engine.js +369 -0
  195. package/src/lib/tenant-saas.js +460 -0
  196. package/src/lib/threat-intel.js +335 -0
  197. package/src/lib/todo-manager.js +105 -0
  198. package/src/lib/token-incentive.js +293 -0
  199. package/src/lib/token-tracker.js +329 -0
  200. package/src/lib/topic-classifier.js +105 -0
  201. package/src/lib/trust-security.js +390 -0
  202. package/src/lib/ueba.js +389 -0
  203. package/src/lib/universal-runtime.js +325 -0
  204. package/src/lib/user-profile.js +81 -0
  205. package/src/lib/version-checker.js +81 -0
  206. package/src/lib/wallet-manager.js +326 -0
  207. package/src/lib/web-fetch.js +81 -0
  208. package/src/lib/workflow-engine.js +322 -0
  209. package/src/lib/zkp-engine.js +105 -0
@@ -20,8 +20,51 @@ import {
20
20
  cancelJob,
21
21
  deleteJob,
22
22
  getQuantizationStats,
23
+ /* V2 (Phase 20) */
24
+ MODEL_MATURITY_V2,
25
+ JOB_TICKET_V2,
26
+ getDefaultMaxActiveModelsPerOwnerV2,
27
+ getMaxActiveModelsPerOwnerV2,
28
+ setMaxActiveModelsPerOwnerV2,
29
+ getDefaultMaxRunningJobsPerOwnerV2,
30
+ getMaxRunningJobsPerOwnerV2,
31
+ setMaxRunningJobsPerOwnerV2,
32
+ getDefaultModelIdleMsV2,
33
+ getModelIdleMsV2,
34
+ setModelIdleMsV2,
35
+ getDefaultJobStuckMsV2,
36
+ getJobStuckMsV2,
37
+ setJobStuckMsV2,
38
+ registerModelV2,
39
+ getModelV2,
40
+ setModelMaturityV2,
41
+ activateModel,
42
+ deprecateModel,
43
+ retireModel,
44
+ touchModelUsage,
45
+ enqueueJobTicketV2,
46
+ getJobTicketV2,
47
+ setJobTicketStatusV2,
48
+ startJobTicket,
49
+ completeJobTicket,
50
+ failJobTicket,
51
+ cancelJobTicket,
52
+ getActiveModelCount,
53
+ getRunningJobCount,
54
+ autoRetireIdleModels,
55
+ autoFailStuckJobTickets,
56
+ getQuantizationStatsV2,
23
57
  } from "../lib/quantization.js";
24
58
 
59
+ function _parseMetaV2(s) {
60
+ if (!s) return undefined;
61
+ try {
62
+ return JSON.parse(s);
63
+ } catch {
64
+ throw new Error(`--metadata must be valid JSON`);
65
+ }
66
+ }
67
+
25
68
  function _dbFromCtx(cmd) {
26
69
  const root = cmd?.parent?.parent ?? cmd?.parent;
27
70
  return root?._db;
@@ -276,5 +319,313 @@ export function registerQuantizationCommand(program) {
276
319
  console.log(`Avg duration: ${s.avgDurationMs}ms`);
277
320
  });
278
321
 
322
+ /* ═════════════════════════════════════════════════════ *
323
+ * Phase 20 V2 — Model Maturity + Job Ticket Lifecycle
324
+ * ═════════════════════════════════════════════════════ */
325
+
326
+ quant
327
+ .command("model-maturities-v2")
328
+ .description("List Phase 20 V2 model maturity states")
329
+ .option("--json", "JSON output")
330
+ .action((opts) => {
331
+ const v = Object.values(MODEL_MATURITY_V2);
332
+ if (opts.json) return console.log(JSON.stringify(v, null, 2));
333
+ for (const s of v) console.log(s);
334
+ });
335
+
336
+ quant
337
+ .command("job-ticket-lifecycles-v2")
338
+ .description("List Phase 20 V2 job-ticket lifecycle states")
339
+ .option("--json", "JSON output")
340
+ .action((opts) => {
341
+ const v = Object.values(JOB_TICKET_V2);
342
+ if (opts.json) return console.log(JSON.stringify(v, null, 2));
343
+ for (const s of v) console.log(s);
344
+ });
345
+
346
+ quant
347
+ .command("default-max-active-models-per-owner")
348
+ .description("Show default V2 per-owner active-model cap")
349
+ .action(() => console.log(getDefaultMaxActiveModelsPerOwnerV2()));
350
+
351
+ quant
352
+ .command("max-active-models-per-owner")
353
+ .description("Show current V2 per-owner active-model cap")
354
+ .action(() => console.log(getMaxActiveModelsPerOwnerV2()));
355
+
356
+ quant
357
+ .command("set-max-active-models-per-owner <n>")
358
+ .description("Set V2 per-owner active-model cap")
359
+ .action((n) => console.log(setMaxActiveModelsPerOwnerV2(n)));
360
+
361
+ quant
362
+ .command("default-max-running-jobs-per-owner")
363
+ .description("Show default V2 per-owner running-job cap")
364
+ .action(() => console.log(getDefaultMaxRunningJobsPerOwnerV2()));
365
+
366
+ quant
367
+ .command("max-running-jobs-per-owner")
368
+ .description("Show current V2 per-owner running-job cap")
369
+ .action(() => console.log(getMaxRunningJobsPerOwnerV2()));
370
+
371
+ quant
372
+ .command("set-max-running-jobs-per-owner <n>")
373
+ .description("Set V2 per-owner running-job cap")
374
+ .action((n) => console.log(setMaxRunningJobsPerOwnerV2(n)));
375
+
376
+ quant
377
+ .command("default-model-idle-ms")
378
+ .description("Show default V2 model-idle threshold")
379
+ .action(() => console.log(getDefaultModelIdleMsV2()));
380
+
381
+ quant
382
+ .command("model-idle-ms")
383
+ .description("Show current V2 model-idle threshold")
384
+ .action(() => console.log(getModelIdleMsV2()));
385
+
386
+ quant
387
+ .command("set-model-idle-ms <ms>")
388
+ .description("Set V2 model-idle threshold (ms)")
389
+ .action((ms) => console.log(setModelIdleMsV2(ms)));
390
+
391
+ quant
392
+ .command("default-job-stuck-ms")
393
+ .description("Show default V2 job-stuck threshold")
394
+ .action(() => console.log(getDefaultJobStuckMsV2()));
395
+
396
+ quant
397
+ .command("job-stuck-ms")
398
+ .description("Show current V2 job-stuck threshold")
399
+ .action(() => console.log(getJobStuckMsV2()));
400
+
401
+ quant
402
+ .command("set-job-stuck-ms <ms>")
403
+ .description("Set V2 job-stuck threshold (ms)")
404
+ .action((ms) => console.log(setJobStuckMsV2(ms)));
405
+
406
+ quant
407
+ .command("active-model-count")
408
+ .description("Count active V2 models (optionally scoped by owner)")
409
+ .option("-o, --owner <id>", "Owner ID")
410
+ .action((opts) => console.log(getActiveModelCount(opts.owner)));
411
+
412
+ quant
413
+ .command("running-job-count")
414
+ .description("Count running V2 job tickets (optionally scoped by owner)")
415
+ .option("-o, --owner <id>", "Owner ID")
416
+ .action((opts) => console.log(getRunningJobCount(opts.owner)));
417
+
418
+ quant
419
+ .command("register-model-v2 <model-id>")
420
+ .description("Register a V2 model")
421
+ .requiredOption("-o, --owner <id>", "Owner ID")
422
+ .option("-f, --family <name>", "Model family (e.g. llama)")
423
+ .option("-i, --initial-status <status>", "Initial status")
424
+ .option("-m, --metadata <json>", "Metadata JSON")
425
+ .option("--json", "JSON output")
426
+ .action((modelId, opts) => {
427
+ const db = _dbFromCtx(quant);
428
+ const rec = registerModelV2(db, {
429
+ modelId,
430
+ ownerId: opts.owner,
431
+ family: opts.family,
432
+ initialStatus: opts.initialStatus,
433
+ metadata: _parseMetaV2(opts.metadata),
434
+ });
435
+ if (opts.json) return console.log(JSON.stringify(rec, null, 2));
436
+ console.log(`Registered model ${modelId} (${rec.status})`);
437
+ });
438
+
439
+ quant
440
+ .command("model-v2 <model-id>")
441
+ .description("Show a V2 model")
442
+ .option("--json", "JSON output")
443
+ .action((id, opts) => {
444
+ const rec = getModelV2(id);
445
+ if (!rec) {
446
+ console.error(`Unknown model: ${id}`);
447
+ process.exitCode = 1;
448
+ return;
449
+ }
450
+ if (opts.json) return console.log(JSON.stringify(rec, null, 2));
451
+ console.log(`${rec.modelId} [${rec.status}] owner=${rec.ownerId}`);
452
+ });
453
+
454
+ quant
455
+ .command("set-model-maturity-v2 <model-id> <status>")
456
+ .description("Transition V2 model maturity")
457
+ .option("-r, --reason <text>", "Reason")
458
+ .option("-m, --metadata <json>", "Metadata patch (JSON)")
459
+ .action((id, status, opts) => {
460
+ const db = _dbFromCtx(quant);
461
+ const rec = setModelMaturityV2(db, id, status, {
462
+ reason: opts.reason,
463
+ metadata: _parseMetaV2(opts.metadata),
464
+ });
465
+ console.log(`${id} → ${rec.status}`);
466
+ });
467
+
468
+ quant
469
+ .command("activate-model <model-id>")
470
+ .description("Transition a V2 model to ACTIVE")
471
+ .option("-r, --reason <text>", "Reason")
472
+ .action((id, opts) => {
473
+ const rec = activateModel(_dbFromCtx(quant), id, opts.reason);
474
+ console.log(`${id} → ${rec.status}`);
475
+ });
476
+
477
+ quant
478
+ .command("deprecate-model <model-id>")
479
+ .description("Transition a V2 model to DEPRECATED")
480
+ .option("-r, --reason <text>", "Reason")
481
+ .action((id, opts) => {
482
+ const rec = deprecateModel(_dbFromCtx(quant), id, opts.reason);
483
+ console.log(`${id} → ${rec.status}`);
484
+ });
485
+
486
+ quant
487
+ .command("retire-model <model-id>")
488
+ .description("Transition a V2 model to RETIRED")
489
+ .option("-r, --reason <text>", "Reason")
490
+ .action((id, opts) => {
491
+ const rec = retireModel(_dbFromCtx(quant), id, opts.reason);
492
+ console.log(`${id} → ${rec.status}`);
493
+ });
494
+
495
+ quant
496
+ .command("touch-model-usage <model-id>")
497
+ .description("Bump lastUsedAt for a V2 model")
498
+ .action((id) => {
499
+ const rec = touchModelUsage(id);
500
+ console.log(`${id} lastUsedAt=${rec.lastUsedAt}`);
501
+ });
502
+
503
+ quant
504
+ .command("enqueue-job-ticket-v2 <ticket-id>")
505
+ .description("Enqueue a V2 quantization job ticket")
506
+ .requiredOption("-o, --owner <id>", "Owner ID")
507
+ .requiredOption("-M, --model <id>", "Model ID")
508
+ .requiredOption("-t, --quant-type <type>", "Quant type (gguf/gptq)")
509
+ .option("-l, --level <lvl>", "Level (e.g. Q4_K_M)")
510
+ .option("-m, --metadata <json>", "Metadata JSON")
511
+ .option("--json", "JSON output")
512
+ .action((ticketId, opts) => {
513
+ const db = _dbFromCtx(quant);
514
+ const rec = enqueueJobTicketV2(db, {
515
+ ticketId,
516
+ ownerId: opts.owner,
517
+ modelId: opts.model,
518
+ quantType: opts.quantType,
519
+ level: opts.level,
520
+ metadata: _parseMetaV2(opts.metadata),
521
+ });
522
+ if (opts.json) return console.log(JSON.stringify(rec, null, 2));
523
+ console.log(`Enqueued ticket ${ticketId} (${rec.status})`);
524
+ });
525
+
526
+ quant
527
+ .command("job-ticket-v2 <ticket-id>")
528
+ .description("Show a V2 job ticket")
529
+ .option("--json", "JSON output")
530
+ .action((id, opts) => {
531
+ const rec = getJobTicketV2(id);
532
+ if (!rec) {
533
+ console.error(`Unknown ticket: ${id}`);
534
+ process.exitCode = 1;
535
+ return;
536
+ }
537
+ if (opts.json) return console.log(JSON.stringify(rec, null, 2));
538
+ console.log(`${rec.ticketId} [${rec.status}] owner=${rec.ownerId}`);
539
+ });
540
+
541
+ quant
542
+ .command("set-job-ticket-status-v2 <ticket-id> <status>")
543
+ .description("Transition V2 job ticket status")
544
+ .option("-r, --reason <text>", "Reason")
545
+ .option("-m, --metadata <json>", "Metadata patch (JSON)")
546
+ .action((id, status, opts) => {
547
+ const db = _dbFromCtx(quant);
548
+ const rec = setJobTicketStatusV2(db, id, status, {
549
+ reason: opts.reason,
550
+ metadata: _parseMetaV2(opts.metadata),
551
+ });
552
+ console.log(`${id} → ${rec.status}`);
553
+ });
554
+
555
+ quant
556
+ .command("start-job-ticket <ticket-id>")
557
+ .description("Transition a V2 job ticket to RUNNING")
558
+ .option("-r, --reason <text>", "Reason")
559
+ .action((id, opts) => {
560
+ const rec = startJobTicket(_dbFromCtx(quant), id, opts.reason);
561
+ console.log(`${id} → ${rec.status}`);
562
+ });
563
+
564
+ quant
565
+ .command("complete-job-ticket <ticket-id>")
566
+ .description("Transition a V2 job ticket to COMPLETED")
567
+ .option("-r, --reason <text>", "Reason")
568
+ .action((id, opts) => {
569
+ const rec = completeJobTicket(_dbFromCtx(quant), id, opts.reason);
570
+ console.log(`${id} → ${rec.status}`);
571
+ });
572
+
573
+ quant
574
+ .command("fail-job-ticket <ticket-id>")
575
+ .description("Transition a V2 job ticket to FAILED")
576
+ .option("-r, --reason <text>", "Reason")
577
+ .action((id, opts) => {
578
+ const rec = failJobTicket(_dbFromCtx(quant), id, opts.reason);
579
+ console.log(`${id} → ${rec.status}`);
580
+ });
581
+
582
+ quant
583
+ .command("cancel-job-ticket <ticket-id>")
584
+ .description("Transition a V2 job ticket to CANCELED")
585
+ .option("-r, --reason <text>", "Reason")
586
+ .action((id, opts) => {
587
+ const rec = cancelJobTicket(_dbFromCtx(quant), id, opts.reason);
588
+ console.log(`${id} → ${rec.status}`);
589
+ });
590
+
591
+ quant
592
+ .command("auto-retire-idle-models")
593
+ .description("Flip idle V2 models (active+deprecated) → RETIRED")
594
+ .option("--json", "JSON output")
595
+ .action((opts) => {
596
+ const r = autoRetireIdleModels(_dbFromCtx(quant));
597
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
598
+ console.log(`Retired ${r.count} idle model(s)`);
599
+ });
600
+
601
+ quant
602
+ .command("auto-fail-stuck-job-tickets")
603
+ .description("Flip stuck RUNNING V2 tickets → FAILED")
604
+ .option("--json", "JSON output")
605
+ .action((opts) => {
606
+ const r = autoFailStuckJobTickets(_dbFromCtx(quant));
607
+ if (opts.json) return console.log(JSON.stringify(r, null, 2));
608
+ console.log(`Failed ${r.count} stuck ticket(s)`);
609
+ });
610
+
611
+ quant
612
+ .command("stats-v2")
613
+ .description("Phase 20 V2 statistics")
614
+ .option("--json", "JSON output")
615
+ .action((opts) => {
616
+ const s = getQuantizationStatsV2();
617
+ if (opts.json) return console.log(JSON.stringify(s, null, 2));
618
+ console.log(
619
+ `Models(V2)=${s.totalModelsV2} Tickets(V2)=${s.totalTicketsV2} ` +
620
+ `caps: active-models/owner=${s.maxActiveModelsPerOwner} running-jobs/owner=${s.maxRunningJobsPerOwner}`,
621
+ );
622
+ console.log("models-by-status:");
623
+ for (const [k, v] of Object.entries(s.modelsByStatus))
624
+ console.log(` ${k.padEnd(12)} ${v}`);
625
+ console.log("tickets-by-status:");
626
+ for (const [k, v] of Object.entries(s.ticketsByStatus))
627
+ console.log(` ${k.padEnd(12)} ${v}`);
628
+ });
629
+
279
630
  program.addCommand(quant);
280
631
  }
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Response Cache V2 commands
3
+ * `cc rcache ...` — in-memory governance layer for cache profiles
4
+ * + refresh jobs, independent of SQLite llm_cache table.
5
+ */
6
+
7
+ import { logger } from "../lib/logger.js";
8
+ import {
9
+ PROFILE_MATURITY_V2,
10
+ REFRESH_JOB_LIFECYCLE_V2,
11
+ getMaxActiveProfilesPerOwnerV2,
12
+ setMaxActiveProfilesPerOwnerV2,
13
+ getMaxPendingRefreshJobsPerProfileV2,
14
+ setMaxPendingRefreshJobsPerProfileV2,
15
+ getProfileIdleMsV2,
16
+ setProfileIdleMsV2,
17
+ getRefreshStuckMsV2,
18
+ setRefreshStuckMsV2,
19
+ registerProfileV2,
20
+ getProfileV2,
21
+ listProfilesV2,
22
+ setProfileStatusV2,
23
+ activateProfileV2,
24
+ suspendProfileV2,
25
+ archiveProfileV2,
26
+ touchProfileV2,
27
+ getActiveProfileCountV2,
28
+ createRefreshJobV2,
29
+ getRefreshJobV2,
30
+ listRefreshJobsV2,
31
+ setRefreshJobStatusV2,
32
+ startRefreshJobV2,
33
+ completeRefreshJobV2,
34
+ failRefreshJobV2,
35
+ cancelRefreshJobV2,
36
+ getPendingRefreshJobCountV2,
37
+ autoSuspendIdleProfilesV2,
38
+ autoFailStuckRefreshJobsV2,
39
+ getResponseCacheStatsV2,
40
+ } from "../lib/response-cache.js";
41
+
42
+ const out = (obj) => console.log(JSON.stringify(obj, null, 2));
43
+ const tryRun = (fn) => {
44
+ try {
45
+ fn();
46
+ } catch (err) {
47
+ logger.error(err.message);
48
+ process.exit(1);
49
+ }
50
+ };
51
+
52
+ export function registerRCacheCommand(program) {
53
+ const root = program
54
+ .command("rcache")
55
+ .description("Response cache V2 — profile maturity + refresh jobs");
56
+
57
+ root
58
+ .command("profile-maturities-v2")
59
+ .description("List V2 profile maturity states")
60
+ .action(() => out(Object.values(PROFILE_MATURITY_V2)));
61
+
62
+ root
63
+ .command("refresh-job-lifecycles-v2")
64
+ .description("List V2 refresh-job lifecycle states")
65
+ .action(() => out(Object.values(REFRESH_JOB_LIFECYCLE_V2)));
66
+
67
+ root
68
+ .command("stats-v2")
69
+ .description("V2 response cache stats")
70
+ .action(() => out(getResponseCacheStatsV2()));
71
+
72
+ root
73
+ .command("get-max-active-profiles-v2")
74
+ .description("Get max active profiles per owner (V2)")
75
+ .action(() =>
76
+ out({ maxActiveProfilesPerOwner: getMaxActiveProfilesPerOwnerV2() }),
77
+ );
78
+
79
+ root
80
+ .command("set-max-active-profiles-v2 <n>")
81
+ .description("Set max active profiles per owner (V2)")
82
+ .action((n) =>
83
+ tryRun(() => {
84
+ setMaxActiveProfilesPerOwnerV2(Number(n));
85
+ out({ maxActiveProfilesPerOwner: getMaxActiveProfilesPerOwnerV2() });
86
+ }),
87
+ );
88
+
89
+ root
90
+ .command("get-max-pending-refresh-jobs-v2")
91
+ .description("Get max pending refresh jobs per profile (V2)")
92
+ .action(() =>
93
+ out({
94
+ maxPendingRefreshJobsPerProfile: getMaxPendingRefreshJobsPerProfileV2(),
95
+ }),
96
+ );
97
+
98
+ root
99
+ .command("set-max-pending-refresh-jobs-v2 <n>")
100
+ .description("Set max pending refresh jobs per profile (V2)")
101
+ .action((n) =>
102
+ tryRun(() => {
103
+ setMaxPendingRefreshJobsPerProfileV2(Number(n));
104
+ out({
105
+ maxPendingRefreshJobsPerProfile:
106
+ getMaxPendingRefreshJobsPerProfileV2(),
107
+ });
108
+ }),
109
+ );
110
+
111
+ root
112
+ .command("get-profile-idle-ms-v2")
113
+ .description("Get profile idle threshold (V2)")
114
+ .action(() => out({ profileIdleMs: getProfileIdleMsV2() }));
115
+
116
+ root
117
+ .command("set-profile-idle-ms-v2 <ms>")
118
+ .description("Set profile idle threshold (V2)")
119
+ .action((ms) =>
120
+ tryRun(() => {
121
+ setProfileIdleMsV2(Number(ms));
122
+ out({ profileIdleMs: getProfileIdleMsV2() });
123
+ }),
124
+ );
125
+
126
+ root
127
+ .command("get-refresh-stuck-ms-v2")
128
+ .description("Get refresh-job stuck threshold (V2)")
129
+ .action(() => out({ refreshStuckMs: getRefreshStuckMsV2() }));
130
+
131
+ root
132
+ .command("set-refresh-stuck-ms-v2 <ms>")
133
+ .description("Set refresh-job stuck threshold (V2)")
134
+ .action((ms) =>
135
+ tryRun(() => {
136
+ setRefreshStuckMsV2(Number(ms));
137
+ out({ refreshStuckMs: getRefreshStuckMsV2() });
138
+ }),
139
+ );
140
+
141
+ root
142
+ .command("active-profile-count-v2 <ownerId>")
143
+ .description("Active profile count for owner (V2)")
144
+ .action((ownerId) =>
145
+ out({ ownerId, count: getActiveProfileCountV2(ownerId) }),
146
+ );
147
+
148
+ root
149
+ .command("pending-refresh-job-count-v2 <profileId>")
150
+ .description("Pending refresh-job count for profile (V2)")
151
+ .action((profileId) =>
152
+ out({ profileId, count: getPendingRefreshJobCountV2(profileId) }),
153
+ );
154
+
155
+ root
156
+ .command("register-profile-v2 <id>")
157
+ .description("Register a V2 profile")
158
+ .requiredOption("-o, --owner <id>", "owner id")
159
+ .requiredOption("-l, --label <label>", "profile label")
160
+ .action((id, opts) =>
161
+ tryRun(() =>
162
+ out(registerProfileV2(id, { ownerId: opts.owner, label: opts.label })),
163
+ ),
164
+ );
165
+
166
+ root
167
+ .command("get-profile-v2 <id>")
168
+ .description("Get a V2 profile")
169
+ .action((id) => out(getProfileV2(id)));
170
+
171
+ root
172
+ .command("list-profiles-v2")
173
+ .description("List V2 profiles")
174
+ .option("-o, --owner <id>", "filter by owner")
175
+ .option("-s, --status <status>", "filter by status")
176
+ .action((opts) =>
177
+ out(listProfilesV2({ ownerId: opts.owner, status: opts.status })),
178
+ );
179
+
180
+ root
181
+ .command("set-profile-status-v2 <id> <next>")
182
+ .description("Set V2 profile status")
183
+ .action((id, next) => tryRun(() => out(setProfileStatusV2(id, next))));
184
+
185
+ root
186
+ .command("activate-profile-v2 <id>")
187
+ .description("Activate a V2 profile")
188
+ .action((id) => tryRun(() => out(activateProfileV2(id))));
189
+
190
+ root
191
+ .command("suspend-profile-v2 <id>")
192
+ .description("Suspend a V2 profile")
193
+ .action((id) => tryRun(() => out(suspendProfileV2(id))));
194
+
195
+ root
196
+ .command("archive-profile-v2 <id>")
197
+ .description("Archive a V2 profile")
198
+ .action((id) => tryRun(() => out(archiveProfileV2(id))));
199
+
200
+ root
201
+ .command("touch-profile-v2 <id>")
202
+ .description("Touch a V2 profile")
203
+ .action((id) => tryRun(() => out(touchProfileV2(id))));
204
+
205
+ root
206
+ .command("create-refresh-job-v2 <id>")
207
+ .description("Create a V2 refresh job")
208
+ .requiredOption("-p, --profile <id>", "profile id")
209
+ .option("-k, --kind <kind>", "job kind", "warm")
210
+ .action((id, opts) =>
211
+ tryRun(() =>
212
+ out(
213
+ createRefreshJobV2(id, { profileId: opts.profile, kind: opts.kind }),
214
+ ),
215
+ ),
216
+ );
217
+
218
+ root
219
+ .command("get-refresh-job-v2 <id>")
220
+ .description("Get a V2 refresh job")
221
+ .action((id) => out(getRefreshJobV2(id)));
222
+
223
+ root
224
+ .command("list-refresh-jobs-v2")
225
+ .description("List V2 refresh jobs")
226
+ .option("-p, --profile <id>", "filter by profile")
227
+ .option("-s, --status <status>", "filter by status")
228
+ .action((opts) =>
229
+ out(
230
+ listRefreshJobsV2({
231
+ profileId: opts.profile,
232
+ status: opts.status,
233
+ }),
234
+ ),
235
+ );
236
+
237
+ root
238
+ .command("set-refresh-job-status-v2 <id> <next>")
239
+ .description("Set V2 refresh-job status")
240
+ .action((id, next) => tryRun(() => out(setRefreshJobStatusV2(id, next))));
241
+
242
+ root
243
+ .command("start-refresh-job-v2 <id>")
244
+ .description("Start a V2 refresh job")
245
+ .action((id) => tryRun(() => out(startRefreshJobV2(id))));
246
+
247
+ root
248
+ .command("complete-refresh-job-v2 <id>")
249
+ .description("Complete a V2 refresh job")
250
+ .action((id) => tryRun(() => out(completeRefreshJobV2(id))));
251
+
252
+ root
253
+ .command("fail-refresh-job-v2 <id>")
254
+ .description("Fail a V2 refresh job")
255
+ .action((id) => tryRun(() => out(failRefreshJobV2(id))));
256
+
257
+ root
258
+ .command("cancel-refresh-job-v2 <id>")
259
+ .description("Cancel a V2 refresh job")
260
+ .action((id) => tryRun(() => out(cancelRefreshJobV2(id))));
261
+
262
+ root
263
+ .command("auto-suspend-idle-profiles-v2")
264
+ .description("Auto-suspend idle V2 profiles")
265
+ .action(() => out(autoSuspendIdleProfilesV2()));
266
+
267
+ root
268
+ .command("auto-fail-stuck-refresh-jobs-v2")
269
+ .description("Auto-fail stuck V2 refresh jobs")
270
+ .action(() => out(autoFailStuckRefreshJobsV2()));
271
+ }