contextos-agents 1.7.0 → 2.0.0-beta.2

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 (309) hide show
  1. package/.agents/AGENTS.md +1 -1
  2. package/.agents/adapters/aider/export.js +117 -99
  3. package/.agents/adapters/claude/export.js +68 -26
  4. package/.agents/adapters/copilot/export.js +90 -53
  5. package/.agents/adapters/cursor/export.js +80 -101
  6. package/.agents/adapters/drift-detector.js +196 -0
  7. package/.agents/adapters/gemini/export.js +76 -45
  8. package/.agents/adapters/pure-compiler.js +443 -0
  9. package/.agents/adapters/zed/export.js +104 -96
  10. package/.agents/compiled/registry.v2.json +504 -0
  11. package/.agents/compiled/registry.v2.sha256 +1 -0
  12. package/.agents/compiler/manifest-compiler.js +963 -0
  13. package/.agents/compiler/vendor/yaml.LICENSE.txt +13 -0
  14. package/.agents/compiler/vendor/yaml.SBOM.json +6 -0
  15. package/.agents/compiler/vendor/yaml.js +139 -0
  16. package/.agents/core/profiles/init.yaml +25 -0
  17. package/.agents/core/skills/context-manager/skill.yaml +3 -5
  18. package/.agents/core/skills/context-os/SKILL.md +3 -6
  19. package/.agents/core/skills/context-os/skill.yaml +3 -8
  20. package/.agents/core/skills/engineering-workflow/skill.yaml +1 -7
  21. package/.agents/core/skills/gemini-precision/skill.yaml +1 -6
  22. package/.agents/core/skills/gstack-roles/skill.yaml +3 -6
  23. package/.agents/core/skills/ponytail-mindset/skill.yaml +1 -7
  24. package/.agents/core/skills/security/skill.yaml +15 -3
  25. package/.agents/ctx.js +574 -111
  26. package/.agents/customization-dx.js +282 -0
  27. package/.agents/doctor.js +719 -64
  28. package/.agents/filesystem/index.js +71 -0
  29. package/.agents/filesystem/journaled-transaction.js +451 -0
  30. package/.agents/filesystem/lockfile-v2.js +275 -0
  31. package/.agents/filesystem/platform-hardening.js +222 -0
  32. package/.agents/filesystem/project-lock.js +218 -0
  33. package/.agents/filesystem/safe-path.js +256 -0
  34. package/.agents/generated/claude/skills/context-os/SKILL.md +1 -1
  35. package/.agents/generated/gemini/skills/context-os/SKILL.md +2 -2
  36. package/.agents/plugins/contextos/plugin.json +1 -1
  37. package/.agents/plugins.js +259 -60
  38. package/.agents/profiles.js +486 -51
  39. package/.agents/resolver.js +50 -534
  40. package/.agents/schemas/attestation.review.v1.json +111 -0
  41. package/.agents/schemas/attestation.verification.v1.json +85 -0
  42. package/.agents/schemas/lockfile.v2.schema.json +134 -0
  43. package/.agents/schemas/profile.v2.schema.json +114 -0
  44. package/.agents/schemas/runtime.thread.v1.json +192 -0
  45. package/.agents/schemas/skill.manifest.v2.json +177 -0
  46. package/.agents/schemas/verification.spec.v1.json +39 -0
  47. package/.agents/schemas/workspace.graph.schema.json +106 -0
  48. package/.agents/transaction-core/event-store.js +288 -0
  49. package/.agents/transaction-core/idempotency.js +129 -0
  50. package/.agents/transaction-core/ipc-lock.js +311 -0
  51. package/.agents/transaction-core/plugin-supply-chain-bundle.js +436 -0
  52. package/.agents/validate.js +44 -1
  53. package/.agents/watch.js +354 -102
  54. package/.agents/workspace/workspace-graph.js +778 -0
  55. package/README.md +59 -387
  56. package/benchmarks/v2/analysis/statistics.js +140 -0
  57. package/benchmarks/v2/analysis/stats.js +69 -0
  58. package/benchmarks/v2/arms/arm-definitions.js +79 -0
  59. package/benchmarks/v2/dataset.schema.json +34 -0
  60. package/benchmarks/v2/evaluators/index.js +25 -0
  61. package/benchmarks/v2/evaluators/verified-success.js +116 -0
  62. package/benchmarks/v2/harness/runner.js +88 -0
  63. package/benchmarks/v2/pilot-tasks.json +392 -0
  64. package/bin/commands/recover.js +88 -0
  65. package/bin/commands/update.js +80 -17
  66. package/bin/commands.js +62 -25
  67. package/bin/index.js +138 -81
  68. package/bin/lib/lockfile.js +5 -3
  69. package/bin/lib/safe-writer.js +34 -3
  70. package/package.json +85 -72
  71. package/registry.json +2 -2
  72. package/registry.v2.schema.json +86 -0
  73. package/.agents/core/profiles/backend.yaml +0 -47
  74. package/.agents/core/profiles/enterprise.yaml +0 -46
  75. package/.agents/core/profiles/frontend.yaml +0 -46
  76. package/.agents/core/profiles/hackathon.yaml +0 -45
  77. package/.agents/core/profiles/mvp.yaml +0 -44
  78. package/.agents/core/profiles/startup.yaml +0 -48
  79. package/.agents/core/skills/adapters/EXAMPLES.md +0 -19
  80. package/.agents/core/skills/adapters/SKILL.md +0 -105
  81. package/.agents/core/skills/adapters/TROUBLESHOOTING.md +0 -7
  82. package/.agents/core/skills/adapters/VALIDATION.json +0 -12
  83. package/.agents/core/skills/adapters/skill.yaml +0 -16
  84. package/.agents/core/skills/architecture-diagrams/SKILL.md +0 -108
  85. package/.agents/core/skills/architecture-diagrams/VALIDATION.json +0 -12
  86. package/.agents/core/skills/architecture-diagrams/skill.yaml +0 -12
  87. package/.agents/core/skills/brutalist-design/SKILL.md +0 -150
  88. package/.agents/core/skills/brutalist-design/VALIDATION.json +0 -12
  89. package/.agents/core/skills/brutalist-design/skill.yaml +0 -12
  90. package/.agents/core/skills/database/EXAMPLES.md +0 -74
  91. package/.agents/core/skills/database/SKILL.md +0 -101
  92. package/.agents/core/skills/database/TROUBLESHOOTING.md +0 -18
  93. package/.agents/core/skills/database/VALIDATION.json +0 -11
  94. package/.agents/core/skills/database/skill.yaml +0 -31
  95. package/.agents/core/skills/ddd/EXAMPLES.md +0 -42
  96. package/.agents/core/skills/ddd/SKILL.md +0 -247
  97. package/.agents/core/skills/ddd/TROUBLESHOOTING.md +0 -19
  98. package/.agents/core/skills/ddd/VALIDATION.json +0 -12
  99. package/.agents/core/skills/ddd/ddd.md +0 -178
  100. package/.agents/core/skills/ddd/skill.yaml +0 -17
  101. package/.agents/core/skills/decisions/EXAMPLES.md +0 -35
  102. package/.agents/core/skills/decisions/SKILL.md +0 -90
  103. package/.agents/core/skills/decisions/TROUBLESHOOTING.md +0 -13
  104. package/.agents/core/skills/decisions/VALIDATION.json +0 -12
  105. package/.agents/core/skills/decisions/skill.yaml +0 -16
  106. package/.agents/core/skills/docker/EXAMPLES.md +0 -56
  107. package/.agents/core/skills/docker/SKILL.md +0 -63
  108. package/.agents/core/skills/docker/TROUBLESHOOTING.md +0 -18
  109. package/.agents/core/skills/docker/VALIDATION.json +0 -11
  110. package/.agents/core/skills/docker/skill.yaml +0 -29
  111. package/.agents/core/skills/fastapi/EXAMPLES.md +0 -36
  112. package/.agents/core/skills/fastapi/SKILL.md +0 -148
  113. package/.agents/core/skills/fastapi/TROUBLESHOOTING.md +0 -19
  114. package/.agents/core/skills/fastapi/VALIDATION.json +0 -12
  115. package/.agents/core/skills/fastapi/fastapi.md +0 -112
  116. package/.agents/core/skills/fastapi/skill.yaml +0 -17
  117. package/.agents/core/skills/generators/EXAMPLES.md +0 -19
  118. package/.agents/core/skills/generators/SKILL.md +0 -112
  119. package/.agents/core/skills/generators/TROUBLESHOOTING.md +0 -7
  120. package/.agents/core/skills/generators/VALIDATION.json +0 -12
  121. package/.agents/core/skills/generators/skill.yaml +0 -25
  122. package/.agents/core/skills/generators/templates/API.md +0 -77
  123. package/.agents/core/skills/generators/templates/ARCHITECTURE.md +0 -70
  124. package/.agents/core/skills/generators/templates/DATABASE.md +0 -42
  125. package/.agents/core/skills/generators/templates/DECISION.md +0 -46
  126. package/.agents/core/skills/generators/templates/PRD.md +0 -67
  127. package/.agents/core/skills/generators/templates/PROJECT_GRAPH.md +0 -56
  128. package/.agents/core/skills/generators/templates/ROADMAP.md +0 -51
  129. package/.agents/core/skills/generators/templates/TASKS.md +0 -43
  130. package/.agents/core/skills/generators/templates/UI.md +0 -73
  131. package/.agents/core/skills/graphify/EXAMPLES.md +0 -73
  132. package/.agents/core/skills/graphify/SKILL.md +0 -130
  133. package/.agents/core/skills/graphify/VALIDATION.json +0 -12
  134. package/.agents/core/skills/graphify/skill.yaml +0 -18
  135. package/.agents/core/skills/impeccable-design/EXAMPLES.md +0 -26
  136. package/.agents/core/skills/impeccable-design/SKILL.md +0 -201
  137. package/.agents/core/skills/impeccable-design/TROUBLESHOOTING.md +0 -19
  138. package/.agents/core/skills/impeccable-design/VALIDATION.json +0 -12
  139. package/.agents/core/skills/impeccable-design/skill.yaml +0 -20
  140. package/.agents/core/skills/interview-me/SKILL.md +0 -97
  141. package/.agents/core/skills/interview-me/VALIDATION.json +0 -12
  142. package/.agents/core/skills/interview-me/skill.yaml +0 -12
  143. package/.agents/core/skills/microservices/EXAMPLES.md +0 -38
  144. package/.agents/core/skills/microservices/SKILL.md +0 -164
  145. package/.agents/core/skills/microservices/TROUBLESHOOTING.md +0 -19
  146. package/.agents/core/skills/microservices/VALIDATION.json +0 -12
  147. package/.agents/core/skills/microservices/microservices.md +0 -119
  148. package/.agents/core/skills/microservices/skill.yaml +0 -17
  149. package/.agents/core/skills/minimalist-design/SKILL.md +0 -113
  150. package/.agents/core/skills/minimalist-design/VALIDATION.json +0 -12
  151. package/.agents/core/skills/minimalist-design/skill.yaml +0 -12
  152. package/.agents/core/skills/nestjs/EXAMPLES.md +0 -40
  153. package/.agents/core/skills/nestjs/SKILL.md +0 -139
  154. package/.agents/core/skills/nestjs/TROUBLESHOOTING.md +0 -19
  155. package/.agents/core/skills/nestjs/VALIDATION.json +0 -12
  156. package/.agents/core/skills/nestjs/nestjs.md +0 -103
  157. package/.agents/core/skills/nestjs/skill.yaml +0 -17
  158. package/.agents/core/skills/nextjs/EXAMPLES.md +0 -40
  159. package/.agents/core/skills/nextjs/SKILL.md +0 -163
  160. package/.agents/core/skills/nextjs/TROUBLESHOOTING.md +0 -19
  161. package/.agents/core/skills/nextjs/VALIDATION.json +0 -12
  162. package/.agents/core/skills/nextjs/nextjs.md +0 -67
  163. package/.agents/core/skills/nextjs/skill.yaml +0 -17
  164. package/.agents/core/skills/node/EXAMPLES.md +0 -80
  165. package/.agents/core/skills/node/SKILL.md +0 -128
  166. package/.agents/core/skills/node/TROUBLESHOOTING.md +0 -19
  167. package/.agents/core/skills/node/VALIDATION.json +0 -12
  168. package/.agents/core/skills/node/node.md +0 -87
  169. package/.agents/core/skills/node/skill.yaml +0 -17
  170. package/.agents/core/skills/performance/EXAMPLES.md +0 -30
  171. package/.agents/core/skills/performance/SKILL.md +0 -75
  172. package/.agents/core/skills/performance/TROUBLESHOOTING.md +0 -19
  173. package/.agents/core/skills/performance/VALIDATION.json +0 -12
  174. package/.agents/core/skills/performance/performance.md +0 -52
  175. package/.agents/core/skills/performance/skill.yaml +0 -17
  176. package/.agents/core/skills/react/EXAMPLES.md +0 -79
  177. package/.agents/core/skills/react/SKILL.md +0 -132
  178. package/.agents/core/skills/react/TROUBLESHOOTING.md +0 -19
  179. package/.agents/core/skills/react/VALIDATION.json +0 -12
  180. package/.agents/core/skills/react/react.md +0 -93
  181. package/.agents/core/skills/react/skill.yaml +0 -17
  182. package/.agents/core/skills/react-best-practices/SKILL.md +0 -155
  183. package/.agents/core/skills/react-best-practices/VALIDATION.json +0 -12
  184. package/.agents/core/skills/react-best-practices/skill.yaml +0 -14
  185. package/.agents/core/skills/redesign-audit/SKILL.md +0 -117
  186. package/.agents/core/skills/redesign-audit/VALIDATION.json +0 -12
  187. package/.agents/core/skills/redesign-audit/skill.yaml +0 -12
  188. package/.agents/core/skills/soft-design/SKILL.md +0 -108
  189. package/.agents/core/skills/soft-design/VALIDATION.json +0 -12
  190. package/.agents/core/skills/soft-design/skill.yaml +0 -12
  191. package/.agents/core/skills/state-management/EXAMPLES.md +0 -56
  192. package/.agents/core/skills/state-management/SKILL.md +0 -48
  193. package/.agents/core/skills/state-management/TROUBLESHOOTING.md +0 -18
  194. package/.agents/core/skills/state-management/VALIDATION.json +0 -11
  195. package/.agents/core/skills/state-management/skill.yaml +0 -28
  196. package/.agents/core/skills/subagent-orchestrator/SKILL.md +0 -117
  197. package/.agents/core/skills/subagent-orchestrator/VALIDATION.json +0 -12
  198. package/.agents/core/skills/subagent-orchestrator/skill.yaml +0 -12
  199. package/.agents/core/skills/system-design/EXAMPLES.md +0 -75
  200. package/.agents/core/skills/system-design/SKILL.md +0 -419
  201. package/.agents/core/skills/system-design/TROUBLESHOOTING.md +0 -19
  202. package/.agents/core/skills/system-design/VALIDATION.json +0 -12
  203. package/.agents/core/skills/system-design/skill.yaml +0 -20
  204. package/.agents/core/skills/system-design/system-design.md +0 -112
  205. package/.agents/core/skills/testing/EXAMPLES.md +0 -71
  206. package/.agents/core/skills/testing/SKILL.md +0 -70
  207. package/.agents/core/skills/testing/TROUBLESHOOTING.md +0 -18
  208. package/.agents/core/skills/testing/VALIDATION.json +0 -11
  209. package/.agents/core/skills/testing/skill.yaml +0 -32
  210. package/.agents/core/skills/typescript/EXAMPLES.md +0 -64
  211. package/.agents/core/skills/typescript/SKILL.md +0 -112
  212. package/.agents/core/skills/typescript/TROUBLESHOOTING.md +0 -19
  213. package/.agents/core/skills/typescript/VALIDATION.json +0 -12
  214. package/.agents/core/skills/typescript/skill.yaml +0 -17
  215. package/.agents/core/skills/typescript/typescript.md +0 -71
  216. package/.agents/core/skills/ui-design/EXAMPLES.md +0 -21
  217. package/.agents/core/skills/ui-design/SKILL.md +0 -124
  218. package/.agents/core/skills/ui-design/TROUBLESHOOTING.md +0 -19
  219. package/.agents/core/skills/ui-design/VALIDATION.json +0 -12
  220. package/.agents/core/skills/ui-design/skill.yaml +0 -17
  221. package/.agents/core/skills/ui-design/ui.md +0 -88
  222. package/.agents/core/skills/ui-ux-pro/EXAMPLES.md +0 -62
  223. package/.agents/core/skills/ui-ux-pro/SKILL.md +0 -375
  224. package/.agents/core/skills/ui-ux-pro/TROUBLESHOOTING.md +0 -19
  225. package/.agents/core/skills/ui-ux-pro/VALIDATION.json +0 -12
  226. package/.agents/core/skills/ui-ux-pro/skill.yaml +0 -19
  227. package/.agents/core/skills/ux-design/EXAMPLES.md +0 -36
  228. package/.agents/core/skills/ux-design/SKILL.md +0 -116
  229. package/.agents/core/skills/ux-design/TROUBLESHOOTING.md +0 -19
  230. package/.agents/core/skills/ux-design/VALIDATION.json +0 -12
  231. package/.agents/core/skills/ux-design/skill.yaml +0 -17
  232. package/.agents/core/skills/ux-design/ux.md +0 -80
  233. package/.agents/core/skills/vercel-optimize/SKILL.md +0 -83
  234. package/.agents/core/skills/vercel-optimize/VALIDATION.json +0 -12
  235. package/.agents/core/skills/vercel-optimize/scripts/collect-signals.mjs +0 -131
  236. package/.agents/core/skills/vercel-optimize/scripts/gate-investigations.mjs +0 -142
  237. package/.agents/core/skills/vercel-optimize/scripts/merge-signals.mjs +0 -143
  238. package/.agents/core/skills/vercel-optimize/scripts/scan-codebase.mjs +0 -174
  239. package/.agents/core/skills/vercel-optimize/skill.yaml +0 -18
  240. package/.agents/core/skills/web-accessibility/EXAMPLES.md +0 -39
  241. package/.agents/core/skills/web-accessibility/SKILL.md +0 -170
  242. package/.agents/core/skills/web-accessibility/TROUBLESHOOTING.md +0 -19
  243. package/.agents/core/skills/web-accessibility/VALIDATION.json +0 -12
  244. package/.agents/core/skills/web-accessibility/accessibility.md +0 -63
  245. package/.agents/core/skills/web-accessibility/skill.yaml +0 -17
  246. package/.agents/generated/claude/skills/adapters/SKILL.md +0 -126
  247. package/.agents/generated/claude/skills/architecture-diagrams/SKILL.md +0 -101
  248. package/.agents/generated/claude/skills/brutalist-design/SKILL.md +0 -145
  249. package/.agents/generated/claude/skills/database/SKILL.md +0 -191
  250. package/.agents/generated/claude/skills/ddd/SKILL.md +0 -305
  251. package/.agents/generated/claude/skills/decisions/SKILL.md +0 -134
  252. package/.agents/generated/claude/skills/docker/SKILL.md +0 -135
  253. package/.agents/generated/claude/skills/fastapi/SKILL.md +0 -200
  254. package/.agents/generated/claude/skills/generators/SKILL.md +0 -133
  255. package/.agents/generated/claude/skills/graphify/SKILL.md +0 -198
  256. package/.agents/generated/claude/skills/impeccable-design/SKILL.md +0 -241
  257. package/.agents/generated/claude/skills/interview-me/SKILL.md +0 -90
  258. package/.agents/generated/claude/skills/microservices/SKILL.md +0 -218
  259. package/.agents/generated/claude/skills/minimalist-design/SKILL.md +0 -108
  260. package/.agents/generated/claude/skills/nestjs/SKILL.md +0 -195
  261. package/.agents/generated/claude/skills/nextjs/SKILL.md +0 -219
  262. package/.agents/generated/claude/skills/node/SKILL.md +0 -224
  263. package/.agents/generated/claude/skills/performance/SKILL.md +0 -121
  264. package/.agents/generated/claude/skills/react/SKILL.md +0 -227
  265. package/.agents/generated/claude/skills/react-best-practices/SKILL.md +0 -146
  266. package/.agents/generated/claude/skills/redesign-audit/SKILL.md +0 -112
  267. package/.agents/generated/claude/skills/soft-design/SKILL.md +0 -103
  268. package/.agents/generated/claude/skills/state-management/SKILL.md +0 -120
  269. package/.agents/generated/claude/skills/subagent-orchestrator/SKILL.md +0 -110
  270. package/.agents/generated/claude/skills/system-design/SKILL.md +0 -507
  271. package/.agents/generated/claude/skills/testing/SKILL.md +0 -157
  272. package/.agents/generated/claude/skills/typescript/SKILL.md +0 -192
  273. package/.agents/generated/claude/skills/ui-design/SKILL.md +0 -161
  274. package/.agents/generated/claude/skills/ui-ux-pro/SKILL.md +0 -451
  275. package/.agents/generated/claude/skills/ux-design/SKILL.md +0 -168
  276. package/.agents/generated/claude/skills/vercel-optimize/SKILL.md +0 -76
  277. package/.agents/generated/claude/skills/web-accessibility/SKILL.md +0 -225
  278. package/.agents/generated/gemini/skills/adapters/SKILL.md +0 -135
  279. package/.agents/generated/gemini/skills/architecture-diagrams/SKILL.md +0 -107
  280. package/.agents/generated/gemini/skills/brutalist-design/SKILL.md +0 -151
  281. package/.agents/generated/gemini/skills/database/SKILL.md +0 -200
  282. package/.agents/generated/gemini/skills/ddd/SKILL.md +0 -314
  283. package/.agents/generated/gemini/skills/decisions/SKILL.md +0 -143
  284. package/.agents/generated/gemini/skills/docker/SKILL.md +0 -144
  285. package/.agents/generated/gemini/skills/fastapi/SKILL.md +0 -209
  286. package/.agents/generated/gemini/skills/generators/SKILL.md +0 -142
  287. package/.agents/generated/gemini/skills/graphify/SKILL.md +0 -205
  288. package/.agents/generated/gemini/skills/impeccable-design/SKILL.md +0 -250
  289. package/.agents/generated/gemini/skills/interview-me/SKILL.md +0 -96
  290. package/.agents/generated/gemini/skills/microservices/SKILL.md +0 -227
  291. package/.agents/generated/gemini/skills/minimalist-design/SKILL.md +0 -114
  292. package/.agents/generated/gemini/skills/nestjs/SKILL.md +0 -204
  293. package/.agents/generated/gemini/skills/nextjs/SKILL.md +0 -298
  294. package/.agents/generated/gemini/skills/node/SKILL.md +0 -323
  295. package/.agents/generated/gemini/skills/performance/SKILL.md +0 -185
  296. package/.agents/generated/gemini/skills/react/SKILL.md +0 -332
  297. package/.agents/generated/gemini/skills/react-best-practices/SKILL.md +0 -152
  298. package/.agents/generated/gemini/skills/redesign-audit/SKILL.md +0 -118
  299. package/.agents/generated/gemini/skills/soft-design/SKILL.md +0 -109
  300. package/.agents/generated/gemini/skills/state-management/SKILL.md +0 -129
  301. package/.agents/generated/gemini/skills/subagent-orchestrator/SKILL.md +0 -116
  302. package/.agents/generated/gemini/skills/system-design/SKILL.md +0 -631
  303. package/.agents/generated/gemini/skills/testing/SKILL.md +0 -166
  304. package/.agents/generated/gemini/skills/typescript/SKILL.md +0 -275
  305. package/.agents/generated/gemini/skills/ui-design/SKILL.md +0 -170
  306. package/.agents/generated/gemini/skills/ui-ux-pro/SKILL.md +0 -460
  307. package/.agents/generated/gemini/skills/ux-design/SKILL.md +0 -177
  308. package/.agents/generated/gemini/skills/vercel-optimize/SKILL.md +0 -82
  309. package/.agents/generated/gemini/skills/web-accessibility/SKILL.md +0 -300
package/.agents/ctx.js CHANGED
@@ -36,16 +36,20 @@ function printHelp() {
36
36
  console.log(' export aider [--profile <p>] Compile skills → .aider.conf.yml + CONVENTIONS.md');
37
37
  console.log(' export zed [--profile <p>] Compile skills → .zed/rules.md & .zed/prompts/*.md');
38
38
  console.log(' export all [--profile <p>] Compile skills for all supported agents');
39
- console.log(' profile list List available project profiles');
40
- console.log(' profile show <name> Show profile configuration');
41
- console.log(' profile apply <name> Apply a profile (e.g. mvp, startup, enterprise, frontend)');
42
- console.log(' profile remove Remove active profile filter');
39
+ console.log(' profile list [--json] List available project profiles');
40
+ console.log(' profile show <name> [--json] Show profile configuration');
41
+ console.log(' profile explain <name> [--json] Detailed explanation of profile skills, policies & defaults');
42
+ console.log(' profile apply <name> Apply a profile (supports --scope <pkg> --no-export --json)');
43
+ console.log(' profile remove [--scope <pkg>] Remove active profile or scoped package override');
43
44
  console.log(' resolve <prompt> Resolve minimal skills needed for a task');
45
+ console.log(' explain [id] [--rules] Inspect rule catalog, enforcement levels, and automated checkers');
44
46
  console.log(' index Generate progressive skills-index.json');
45
47
  console.log(' detect Auto-detect project tech stack');
48
+ console.log(' compile [--check] [--sarif] Compile skill manifests into deterministic registry v2');
46
49
  console.log(' audit Alias for validate (check skills)');
47
50
  console.log(' validate Validate skill sources, frontmatter, deps & sync');
48
51
  console.log(' clean-worktrees Clean up lingering .swarm-worktrees and swarm/* branches');
52
+ console.log(' recover [--status|rollback|cont] Inspect, rollback, or resume interrupted transactions');
49
53
  console.log(' doctor Run project diagnostic health check');
50
54
  console.log(' stats Display token context savings report');
51
55
  console.log(' watch Start continuous file watcher and auto-sync daemon');
@@ -90,108 +94,189 @@ const target = args[1];
90
94
 
91
95
  // ── export ────────────────────────────────────────────────────────────────────
92
96
  if (command === 'export') {
97
+ const pureCompiler = require('./adapters/pure-compiler.js');
98
+ const driftDetector = require('./adapters/drift-detector.js');
99
+
93
100
  const profileFlagIdx = args.indexOf('--profile');
101
+ let overrideProfile = null;
94
102
  if (profileFlagIdx !== -1 && args[profileFlagIdx + 1]) {
95
103
  const profiles = require('./profiles.js');
96
- const profileName = args[profileFlagIdx + 1];
104
+ overrideProfile = args[profileFlagIdx + 1];
97
105
  try {
98
- profiles.applyProfile(profileName);
99
- console.log(`[PROFILE] Applied profile '${profileName}' for this export.\n`);
106
+ profiles.applyProfile(overrideProfile);
107
+ console.log(`[PROFILE] Applied profile '${overrideProfile}' for this export.\n`);
100
108
  } catch (err) {
101
109
  console.error(`[ERROR] ${err.message}`);
102
110
  process.exit(1);
103
111
  }
104
112
  }
105
113
 
106
- const runGemini = () => {
107
- const adapter = require('./adapters/gemini/export.js');
108
- adapter.run();
109
- };
110
-
111
- const runClaude = () => {
112
- const adapter = require('./adapters/claude/export.js');
113
- adapter.run();
114
- };
115
-
116
- const runCursor = () => {
117
- const adapter = require('./adapters/cursor/export.js');
118
- adapter.run();
119
- };
120
-
121
- const runCopilot = () => {
122
- const adapter = require('./adapters/copilot/export.js');
123
- adapter.run();
124
- };
125
-
126
- const runAider = () => {
127
- const adapter = require('./adapters/aider/export.js');
128
- adapter.run();
129
- };
130
-
131
- const runZed = () => {
132
- const adapter = require('./adapters/zed/export.js');
133
- adapter.run();
134
- };
135
-
136
- if (target === 'gemini') {
137
- runGemini();
138
- } else if (target === 'claude') {
139
- runClaude();
140
- } else if (target === 'cursor') {
141
- runCursor();
142
- } else if (target === 'copilot') {
143
- runCopilot();
144
- } else if (target === 'aider') {
145
- runAider();
146
- } else if (target === 'zed') {
147
- runZed();
148
- } else if (target === 'all') {
149
- console.log('Exporting skills for all agents...\n');
150
- runGemini();
151
- console.log('');
152
- runClaude();
153
- console.log('');
154
- runCursor();
155
- console.log('');
156
- runCopilot();
157
- console.log('');
158
- runAider();
159
- console.log('');
160
- runZed();
161
- console.log('\nAll exports complete.');
114
+ const isCheck = args.includes('--check');
115
+ const isDiff = args.includes('--diff');
116
+ const isDryRun = args.includes('--dry-run');
117
+ const asJson = args.includes('--json');
118
+
119
+ const rawTarget = args[1] && !args[1].startsWith('--') ? args[1] : 'all';
120
+
121
+ // 1. Drift Check Mode (--check)
122
+ if (isCheck) {
123
+ const drift = driftDetector.detectDrift(process.cwd(), rawTarget, { profile: overrideProfile });
124
+ if (asJson) {
125
+ console.log(JSON.stringify(drift, null, 2));
126
+ } else {
127
+ console.log('\nContextOS — Adapter Output Drift Check\n');
128
+ if (!drift.hasDrift) {
129
+ console.log(`✓ No adapter drift detected. All ${drift.projectedCount} output artifacts are synchronized.`);
130
+ } else {
131
+ console.log(`! Drift detected (${drift.totalFindings} finding(s)):\n`);
132
+ for (const [state, items] of Object.entries(drift.findings)) {
133
+ if (items.length > 0) {
134
+ console.log(` [${state}] (${items.length}):`);
135
+ for (const item of items) {
136
+ console.log(` • ${item.path || item.reason || JSON.stringify(item)}`);
137
+ }
138
+ }
139
+ }
140
+ if (drift.collisions.length > 0) {
141
+ console.log(`\n [PATH_COLLISIONS] (${drift.collisions.length}):`);
142
+ for (const c of drift.collisions) {
143
+ console.log(` • ${c.path} (between ${c.firstAdapter} and ${c.secondAdapter})`);
144
+ }
145
+ }
146
+ console.log('\nRun: node .agents/ctx.js export all to synchronize outputs with source skills.\n');
147
+ }
148
+ }
149
+ process.exit(drift.hasDrift ? 1 : 0);
150
+ }
151
+
152
+ // 2. Diff Preview Mode (--diff)
153
+ if (isDiff) {
154
+ const drift = driftDetector.detectDrift(process.cwd(), rawTarget, { profile: overrideProfile });
155
+ if (asJson) {
156
+ console.log(JSON.stringify(drift.diffs, null, 2));
157
+ } else {
158
+ console.log('\nContextOS — Adapter Output Projected Diffs\n');
159
+ if (drift.diffs.length === 0) {
160
+ console.log('✓ Disk is in sync with projected render. No diffs found.');
161
+ } else {
162
+ for (const d of drift.diffs) {
163
+ console.log(`--- ${d.path} (${d.type}) ---`);
164
+ console.log(d.diff);
165
+ console.log('');
166
+ }
167
+ }
168
+ }
169
+ process.exit(0);
170
+ }
171
+
172
+ // 3. Dry-Run Mode (--dry-run)
173
+ if (isDryRun) {
174
+ const rendered = pureCompiler.renderAdapters(process.cwd(), rawTarget, { profile: overrideProfile });
175
+ if (asJson) {
176
+ console.log(JSON.stringify(rendered, null, 2));
177
+ } else {
178
+ console.log('\nContextOS — Adapter Export Dry Run\n');
179
+ console.log(`Target: ${rawTarget}`);
180
+ console.log(`Planned artifacts: ${rendered.artifacts.length}\n`);
181
+ for (const art of rendered.artifacts) {
182
+ console.log(` + ${art.path.padEnd(50)} [${art.generator}] (${art.content.length} bytes)`);
183
+ }
184
+ if (rendered.collisions.length > 0) {
185
+ console.log(`\n! Collisions detected: ${rendered.collisions.length}`);
186
+ for (const c of rendered.collisions) {
187
+ console.log(` • ${c.path} (${c.firstAdapter} vs ${c.secondAdapter})`);
188
+ }
189
+ }
190
+ console.log('\nDry run complete. No files were written to disk.');
191
+ }
192
+ process.exit(0);
193
+ }
194
+
195
+ // 4. Live Export Execution
196
+ if (rawTarget === 'all') {
197
+ console.log('Starting pure compiler export for all adapters...');
198
+ const rendered = pureCompiler.renderAdapters(process.cwd(), 'all', { profile: overrideProfile });
199
+
200
+ if (rendered.collisions.length > 0) {
201
+ console.error(`[ERROR] Path collisions detected across adapters:`);
202
+ for (const c of rendered.collisions) {
203
+ console.error(` • ${c.path} (${c.firstAdapter} vs ${c.secondAdapter})`);
204
+ }
205
+ process.exit(1);
206
+ }
207
+
208
+ const result = pureCompiler.applyArtifacts(process.cwd(), rendered.artifacts, {
209
+ command: 'export all',
210
+ context: rendered.context,
211
+ });
212
+
213
+ if (asJson) {
214
+ console.log(JSON.stringify(result, null, 2));
215
+ } else {
216
+ console.log(`✓ All exports complete: ${result.appliedCount} artifacts applied in a single transaction (tx: ${result.txId}).`);
217
+ console.log(` Active adapters: Gemini, Claude, Cursor, Copilot, Aider, Zed`);
218
+ }
162
219
  } else {
163
- console.error(`Adapter for '${target}' not implemented yet.`);
164
- console.error('Supported agents: gemini, claude, cursor, copilot, aider, zed, all');
165
- process.exit(1);
220
+ const adapter = pureCompiler.getAdapter(rawTarget);
221
+ if (!adapter) {
222
+ if (asJson) {
223
+ console.error(JSON.stringify({ success: false, error: `Adapter for '${rawTarget}' not implemented yet.` }));
224
+ } else {
225
+ console.error(`Adapter for '${rawTarget}' not implemented yet.`);
226
+ console.error(`Supported agents: ${pureCompiler.listAdapters().join(', ')}, all`);
227
+ }
228
+ process.exit(1);
229
+ }
230
+
231
+ const result = adapter.run({ profile: overrideProfile, projectRoot: process.cwd() });
232
+ if (asJson) {
233
+ console.log(JSON.stringify(result, null, 2));
234
+ }
166
235
  }
167
236
 
168
237
  // ── profile ───────────────────────────────────────────────────────────────────
169
238
  } else if (command === 'profile') {
170
239
  const subcommand = args[1] || 'list';
171
- const profileName = args[2];
240
+ const profileName = args[2] && !args[2].startsWith('-') ? args[2] : null;
172
241
  const profiles = require('./profiles.js');
242
+ const asJson = args.includes('--json');
243
+
244
+ const scopeIdx = args.indexOf('--scope');
245
+ const scopeArg = scopeIdx !== -1 && args[scopeIdx + 1] && !args[scopeIdx + 1].startsWith('--')
246
+ ? args[scopeIdx + 1]
247
+ : (args.find(a => a.startsWith('--scope=')) || '').split('=')[1] || null;
173
248
 
174
249
  if (subcommand === 'list') {
175
250
  const list = profiles.listProfiles();
176
251
  const active = profiles.getActiveProfile();
177
- console.log('\nAvailable ContextOS Profiles:\n');
178
- for (const p of list) {
179
- const isActive = active && active.profile === p.id;
180
- const marker = isActive ? '● [ACTIVE]' : '○';
181
- console.log(` ${marker} ${p.id.padEnd(12)} - ${p.name}: ${p.description}`);
182
- if (p.exclude_skills && p.exclude_skills.length > 0) {
183
- console.log(` Excludes: ${p.exclude_skills.join(', ')}`);
252
+ if (asJson) {
253
+ console.log(JSON.stringify({ active, profiles: list }, null, 2));
254
+ } else {
255
+ console.log('\nAvailable ContextOS Profiles:\n');
256
+ for (const p of list) {
257
+ const isActive = active && active.profile === p.id;
258
+ const marker = isActive ? '● [ACTIVE]' : '○';
259
+ console.log(` ${marker} ${p.id.padEnd(12)} - ${p.name}: ${p.description}`);
260
+ if (p.exclude_skills && p.exclude_skills.length > 0) {
261
+ console.log(` Excludes: ${p.exclude_skills.join(', ')}`);
262
+ }
184
263
  }
264
+ console.log('\nApply a profile: node .agents/ctx.js profile apply <name> [--scope <pkg>]');
265
+ if (active) {
266
+ console.log(`Current active profile: ${active.profile} (${active.name || active.profile})`);
267
+ if (active.overrides && Object.keys(active.overrides).length > 0) {
268
+ console.log('Package Overrides:');
269
+ for (const [s, oProf] of Object.entries(active.overrides)) {
270
+ console.log(` • ${s} → ${oProf}`);
271
+ }
272
+ }
273
+ }
274
+ console.log('');
185
275
  }
186
- console.log('\nApply a profile: node .agents/ctx.js profile apply <name>');
187
- if (active) {
188
- console.log(`Current active profile: ${active.profile} (${active.name})`);
189
- }
190
- console.log('');
191
276
  } else if (subcommand === 'show') {
192
277
  const name = profileName || (profiles.getActiveProfile() || {}).profile;
193
278
  if (!name) {
194
- console.error('[ERROR] Usage: node ctx.js profile show <name>');
279
+ console.error('[ERROR] Usage: node ctx.js profile show <name> [--json]');
195
280
  process.exit(1);
196
281
  }
197
282
  const profile = profiles.getProfile(name);
@@ -199,52 +284,168 @@ if (command === 'export') {
199
284
  console.error(`[ERROR] Profile '${name}' not found.`);
200
285
  process.exit(1);
201
286
  }
202
- console.log(`\nProfile: ${profile.name} (${profile.id})`);
203
- console.log(`Description: ${profile.description}`);
204
- console.log(`Preferred Skills: ${(profile.prefer_skills || []).join(', ') || 'none'}`);
205
- console.log(`Excluded Skills: ${(profile.exclude_skills || []).join(', ') || 'none'}\n`);
287
+ if (asJson) {
288
+ console.log(JSON.stringify(profile, null, 2));
289
+ } else {
290
+ console.log(`\nProfile: ${profile.name} (${profile.id})`);
291
+ console.log(`Description: ${profile.description}`);
292
+ console.log(`Required Skills: ${(profile.skills?.required || profile.require_skills || []).join(', ') || 'none'}`);
293
+ console.log(`Preferred Skills: ${(profile.skills?.preferred || profile.prefer_skills || []).join(', ') || 'none'}`);
294
+ console.log(`Excluded Skills: ${(profile.skills?.excluded || profile.exclude_skills || []).join(', ') || 'none'}\n`);
295
+ }
296
+ } else if (subcommand === 'explain') {
297
+ const name = profileName || (profiles.getActiveProfile() || {}).profile;
298
+ if (!name) {
299
+ console.error('[ERROR] Usage: node ctx.js profile explain <name> [--json]');
300
+ process.exit(1);
301
+ }
302
+ try {
303
+ const explanation = profiles.explainProfile(name);
304
+ if (asJson) {
305
+ console.log(JSON.stringify(explanation, null, 2));
306
+ } else {
307
+ console.log('\n' + profiles.formatProfileExplanation(explanation) + '\n');
308
+ }
309
+ } catch (err) {
310
+ console.error(`[ERROR] ${err.message}`);
311
+ process.exit(1);
312
+ }
206
313
  } else if (subcommand === 'apply') {
207
314
  if (!profileName) {
208
- console.error('[ERROR] Usage: node ctx.js profile apply <name>');
315
+ console.error('[ERROR] Usage: node ctx.js profile apply <name> [--scope <pkg>] [--no-export] [--json]');
209
316
  process.exit(1);
210
317
  }
211
318
  try {
212
- const applied = profiles.applyProfile(profileName);
213
- console.log(`\n✓ Profile '${applied.name}' successfully applied!`);
214
- console.log(` Excluded skills: ${(applied.exclude_skills || []).join(', ') || 'none'}`);
215
- console.log(' Run: node .agents/ctx.js export all (to rebuild exports with this profile)\n');
319
+ const applied = profiles.applyProfile(profileName, process.cwd(), {
320
+ scope: scopeArg,
321
+ noExport: args.includes('--no-export'),
322
+ });
323
+ if (asJson) {
324
+ console.log(JSON.stringify(applied, null, 2));
325
+ } else {
326
+ if (scopeArg) {
327
+ console.log(`\n✓ Scoped profile override '${profileName}' applied to scope: ${scopeArg}!`);
328
+ } else {
329
+ console.log(`\n✓ Profile '${applied.name || profileName}' successfully applied as root profile!`);
330
+ console.log(` Excluded skills: ${(applied.exclude_skills || []).join(', ') || 'none'}`);
331
+ }
332
+ if (!args.includes('--no-export')) {
333
+ console.log(' Run: node .agents/ctx.js export all (to rebuild exports with this profile)\n');
334
+ }
335
+ }
216
336
  } catch (err) {
217
337
  console.error(`[ERROR] ${err.message}`);
218
338
  process.exit(1);
219
339
  }
220
340
  } else if (subcommand === 'remove' || subcommand === 'reset') {
221
- const removed = profiles.removeActiveProfile();
222
- if (removed) {
223
- console.log('\n✓ Active profile filter removed. All skills will be included.\n');
341
+ const removed = profiles.removeActiveProfile(process.cwd(), { scope: scopeArg });
342
+ if (asJson) {
343
+ console.log(JSON.stringify({ removed, scope: scopeArg }, null, 2));
224
344
  } else {
225
- console.log('\nNo active profile was set.\n');
345
+ if (removed) {
346
+ if (scopeArg) {
347
+ console.log(`\n✓ Profile override for scope '${scopeArg}' removed.\n`);
348
+ } else {
349
+ console.log('\n✓ Active profile filter removed. All skills will be included.\n');
350
+ }
351
+ } else {
352
+ console.log(`\nNo active profile${scopeArg ? ` override for '${scopeArg}'` : ''} was found.\n`);
353
+ }
226
354
  }
227
355
  } else {
228
356
  console.error(`Unknown profile subcommand: ${subcommand}`);
229
- console.error('Valid subcommands: list, show, apply, remove');
357
+ console.error('Valid subcommands: list, show, explain, apply, remove');
230
358
  process.exit(1);
231
359
  }
232
360
 
233
361
  // ── resolve ───────────────────────────────────────────────────────────────────
234
362
  } else if (command === 'resolve') {
235
- const resolver = require('./resolver.js');
363
+ const { CanonicalResolver } = require('./resolver/canonical-resolver.js');
236
364
  const promptArgs = args.slice(1).filter(a => !a.startsWith('-')).join(' ');
237
365
  const filesIdx = args.indexOf('--files');
238
366
  const files = filesIdx !== -1 && args[filesIdx + 1] ? args[filesIdx + 1].split(',') : [];
239
367
  const phaseIdx = args.indexOf('--phase');
240
- const phase = phaseIdx !== -1 && args[phaseIdx + 1] ? args[phaseIdx + 1] : 'Build';
368
+ const phase = phaseIdx !== -1 && args[phaseIdx + 1] ? args[phaseIdx + 1] : undefined;
369
+ const budgetIdx = args.indexOf('--budget');
370
+ const budget = budgetIdx !== -1 && args[budgetIdx + 1] ? parseInt(args[budgetIdx + 1], 10) : undefined;
371
+ const explain = args.includes('--explain');
372
+ const asJson = args.includes('--json');
373
+
374
+ const resolver = new CanonicalResolver({ rootDir: process.cwd() });
375
+ const result = resolver.resolve({
376
+ task: promptArgs,
377
+ files,
378
+ explicitPhase: phase,
379
+ contextBudgetTokens: budget,
380
+ });
381
+
382
+ if (asJson) {
383
+ console.log(JSON.stringify(result, null, 2));
384
+ } else if (explain) {
385
+ console.log(resolver.formatExplanation(result));
386
+ } else {
387
+ console.log('\n══════════════════════════════════════════');
388
+ console.log(' ContextOS — Dynamic Skill Resolution');
389
+ console.log('══════════════════════════════════════════');
390
+ console.log(resolver.formatDeclaration(result));
391
+ console.log('──────────────────────────────────────────\n');
392
+ }
393
+
394
+ // ── explain ───────────────────────────────────────────────────────────────────
395
+ } else if (command === 'explain') {
396
+ const { RuleCatalog } = require('./rules/rule-catalog.js');
397
+ const catalog = new RuleCatalog({ rootDir: process.cwd() });
398
+ const fs = require('fs');
241
399
 
242
- const result = resolver.resolveSkills({ prompt: promptArgs, files, phase });
243
- console.log('\n══════════════════════════════════════════');
244
- console.log(' ContextOS — Dynamic Skill Resolution');
245
- console.log('══════════════════════════════════════════');
246
- console.log(resolver.formatDeclaration(result));
247
- console.log('──────────────────────────────────────────\n');
400
+ // Load compiled registry rules if available
401
+ const registryPath = path.join(process.cwd(), '.agents', 'compiled', 'registry.v2.json');
402
+ if (fs.existsSync(registryPath)) {
403
+ try {
404
+ const reg = JSON.parse(fs.readFileSync(registryPath, 'utf8'));
405
+ catalog.loadFromRegistry(reg);
406
+ } catch {
407
+ // ignore
408
+ }
409
+ }
410
+
411
+ const asJson = args.includes('--json');
412
+ const showRules = args.includes('--rules');
413
+ const showCheckers = args.includes('--checkers');
414
+ const targetId = args.slice(1).find(a => !a.startsWith('-'));
415
+
416
+ if (asJson) {
417
+ if (showCheckers) {
418
+ console.log(JSON.stringify(catalog.getAllCheckers(), null, 2));
419
+ } else if (targetId) {
420
+ const rule = catalog.getRule(targetId);
421
+ if (rule) {
422
+ console.log(JSON.stringify(rule, null, 2));
423
+ } else {
424
+ const skillRules = catalog.getAllRules().filter(r => r.sourceSkill === targetId);
425
+ console.log(JSON.stringify({ skill: targetId, rules: skillRules }, null, 2));
426
+ }
427
+ } else {
428
+ console.log(JSON.stringify({
429
+ rules: catalog.getAllRules(),
430
+ checkers: catalog.getAllCheckers(),
431
+ }, null, 2));
432
+ }
433
+ } else if (showCheckers) {
434
+ console.log(catalog.formatCheckersSummary());
435
+ } else if (showRules) {
436
+ console.log(catalog.formatRulesSummary());
437
+ } else if (targetId) {
438
+ const rule = catalog.getRule(targetId);
439
+ if (rule) {
440
+ console.log(catalog.explainRule(targetId));
441
+ } else {
442
+ console.log(catalog.explainSkill(targetId));
443
+ }
444
+ } else {
445
+ // Default: print both rules summary and checkers
446
+ console.log(catalog.formatRulesSummary());
447
+ console.log(catalog.formatCheckersSummary());
448
+ }
248
449
 
249
450
  // ── index ─────────────────────────────────────────────────────────────────────
250
451
  } else if (command === 'index') {
@@ -257,17 +458,139 @@ if (command === 'export') {
257
458
 
258
459
  // ── detect ────────────────────────────────────────────────────────────────────
259
460
  } else if (command === 'detect') {
461
+ const { WorkspaceGraphBuilder } = require('./workspace/workspace-graph.js');
260
462
  const profiles = require('./profiles.js');
261
- const detection = profiles.detectStack(process.cwd());
262
- console.log('\nContextOS — Tech Stack Detection\n');
263
- if (detection.detected.length === 0) {
264
- console.log(' Detected stack: Generic / Vanilla JavaScript');
463
+ const asJson = args.includes('--json');
464
+ const explain = args.includes('--explain');
465
+ const scopeIdx = args.indexOf('--scope');
466
+ const scopeArg = scopeIdx !== -1 && args[scopeIdx + 1] && !args[scopeIdx + 1].startsWith('--')
467
+ ? args[scopeIdx + 1]
468
+ : (args.find(a => a.startsWith('--scope=')) || '').split('=')[1];
469
+
470
+ const builder = new WorkspaceGraphBuilder();
471
+ const graph = builder.build(process.cwd());
472
+
473
+ if (scopeArg) {
474
+ const nearestPkg = builder.findNearestPackage(scopeArg, graph);
475
+ const evidence = builder.extractPackageEvidence(scopeArg, graph);
476
+
477
+ if (asJson) {
478
+ console.log(JSON.stringify({
479
+ scope: scopeArg,
480
+ nearestPackage: nearestPkg,
481
+ evidence,
482
+ }, null, 2));
483
+ } else {
484
+ console.log('\n══════════════════════════════════════════');
485
+ console.log(' ContextOS — Workspace Scoped Detection');
486
+ console.log('══════════════════════════════════════════\n');
487
+ console.log(` Scope Path : ${scopeArg}`);
488
+ if (nearestPkg) {
489
+ console.log(` Nearest Package : ${nearestPkg.id} (${nearestPkg.ecosystem})`);
490
+ console.log(` Package Root : ${nearestPkg.root}`);
491
+ console.log(` Languages : ${nearestPkg.languages.join(', ') || 'unspecified'}`);
492
+ console.log(` Dependencies : ${nearestPkg.dependencies.length} (${nearestPkg.dependencies.slice(0, 8).join(', ')}${nearestPkg.dependencies.length > 8 ? '...' : ''})`);
493
+ console.log(` Configs : ${nearestPkg.configs.join(', ') || 'none'}`);
494
+ if (nearestPkg.internalDependencies.length > 0) {
495
+ console.log(` Internal Links : ${nearestPkg.internalDependencies.join(', ')}`);
496
+ }
497
+ if (evidence.length > 0) {
498
+ console.log('\n Scoped Evidence:');
499
+ for (const ev of evidence.slice(0, 10)) {
500
+ console.log(` • [${ev.source}] ${ev.target} (+${ev.weight}) — ${ev.description}`);
501
+ }
502
+ if (evidence.length > 10) {
503
+ console.log(` ... and ${evidence.length - 10} more signals`);
504
+ }
505
+ }
506
+ } else {
507
+ console.log(' Nearest Package : (none found)');
508
+ }
509
+ console.log('\n──────────────────────────────────────────\n');
510
+ }
511
+ } else if (asJson) {
512
+ const stack = profiles.detectStack(process.cwd());
513
+ console.log(JSON.stringify({
514
+ workspaceGraph: graph,
515
+ stack,
516
+ }, null, 2));
517
+ } else if (explain) {
518
+ console.log('\n══════════════════════════════════════════');
519
+ console.log(' ContextOS — Workspace Evidence Graph');
520
+ console.log('══════════════════════════════════════════\n');
521
+ console.log(` Repository Root : ${graph.repositoryRoot}`);
522
+ console.log(` Fingerprint : ${graph.fingerprint}`);
523
+ console.log(` Packages Found : ${graph.packages.length} ${graph.partial ? '(partial: true)' : ''}\n`);
524
+ for (const pkg of graph.packages) {
525
+ console.log(` • ${pkg.id} [${pkg.ecosystem}]`);
526
+ console.log(` Root : ${pkg.root}`);
527
+ console.log(` Manifests : ${pkg.manifests.join(', ')}`);
528
+ console.log(` Languages : ${pkg.languages.join(', ') || 'unspecified'}`);
529
+ console.log(` Dependencies : ${pkg.dependencies.length}`);
530
+ if (pkg.configs.length > 0) {
531
+ console.log(` Configs : ${pkg.configs.join(', ')}`);
532
+ }
533
+ if (pkg.internalDependencies.length > 0) {
534
+ console.log(` Internal Links : ${pkg.internalDependencies.join(', ')}`);
535
+ }
536
+ console.log('');
537
+ }
538
+ console.log('──────────────────────────────────────────\n');
265
539
  } else {
266
- console.log(` Detected stack: ${detection.detected.join(', ')}`);
540
+ const detection = profiles.detectStack(process.cwd());
541
+ console.log('\nContextOS — Workspace & Tech Stack Detection\n');
542
+ console.log(` Repository Root : ${graph.repositoryRoot}`);
543
+ console.log(` Packages Detected : ${graph.packages.map(p => `${p.id} (${p.root})`).join(', ')}`);
544
+ if (detection.detected.length === 0) {
545
+ console.log(' Detected Stack : Generic / Vanilla JavaScript');
546
+ } else {
547
+ console.log(` Detected Stack : ${detection.detected.join(', ')}`);
548
+ }
549
+ console.log(` Recommended Profile: ${detection.recommendedProfile}`);
550
+ console.log(` Recommended Skills : ${detection.recommendedSkills.join(', ')}`);
551
+ console.log(`\nCommands:`);
552
+ console.log(` node .agents/ctx.js detect --scope <path> Scope detection to a specific file/subproject`);
553
+ console.log(` node .agents/ctx.js detect --explain Display full workspace evidence graph`);
554
+ console.log(` node .agents/ctx.js profile apply ${detection.recommendedProfile}\n`);
555
+ }
556
+
557
+ // ── compile ───────────────────────────────────────────────────────────────────
558
+ } else if (command === 'compile') {
559
+ const { ManifestCompiler } = require('./compiler/manifest-compiler.js');
560
+ const checkOnly = args.includes('--check');
561
+ const asSarif = args.includes('--sarif');
562
+ const asJson = args.includes('--json');
563
+
564
+ const compiler = new ManifestCompiler();
565
+ const res = checkOnly ? compiler.compile() : compiler.compileAndWrite();
566
+
567
+ if (asSarif) {
568
+ console.log(JSON.stringify(compiler.formatSarif(), null, 2));
569
+ process.exit(res.success ? 0 : 1);
570
+ }
571
+
572
+ if (asJson) {
573
+ console.log(JSON.stringify(res, null, 2));
574
+ process.exit(res.success ? 0 : 1);
575
+ }
576
+
577
+ if (!res.success) {
578
+ console.error('\n✗ Manifest compilation failed:\n');
579
+ for (const d of res.diagnostics) {
580
+ console.error(` [${d.code}] ${d.file}${d.path ? ' ' + d.path : ''}: ${d.message}`);
581
+ if (d.remediation) console.error(` ↳ Remediation: ${d.remediation}`);
582
+ }
583
+ console.error('');
584
+ process.exit(1);
585
+ }
586
+
587
+ const skillCount = Object.keys(res.registry.skills).length;
588
+ console.log(`\n✓ Successfully compiled ${skillCount} skills into Registry v2!`);
589
+ console.log(` Source Graph Hash: ${res.registry.sourceGraphHash}`);
590
+ if (!checkOnly) {
591
+ console.log(` Registry: .agents/compiled/registry.v2.json`);
592
+ console.log(` Checksum: .agents/compiled/registry.v2.sha256\n`);
267
593
  }
268
- console.log(` Recommended Profile: ${detection.recommendedProfile}`);
269
- console.log(` Recommended Skills: ${detection.recommendedSkills.join(', ')}`);
270
- console.log(`\nApply recommended profile:\n node .agents/ctx.js profile apply ${detection.recommendedProfile}\n`);
271
594
 
272
595
  // ── validate / audit ──────────────────────────────────────────────────────────
273
596
  } else if (command === 'validate' || command === 'audit') {
@@ -370,7 +693,11 @@ if (command === 'export') {
370
693
  // ── doctor ────────────────────────────────────────────────────────────────────
371
694
  } else if (command === 'doctor') {
372
695
  const doctorModule = require('./doctor.js');
373
- const res = doctorModule.runDoctor(process.cwd(), { json: args.includes('--json') });
696
+ const res = doctorModule.runDoctor(process.cwd(), {
697
+ json: args.includes('--json'),
698
+ fix: args.includes('--fix'),
699
+ strict: args.includes('--strict')
700
+ });
374
701
  if (res && res.ok === false) {
375
702
  process.exit(1);
376
703
  }
@@ -407,6 +734,142 @@ if (command === 'export') {
407
734
  console.log(' node .agents/ctx.js doctor');
408
735
  console.log(' node .agents/ctx.js stats\n');
409
736
 
737
+ // ── recover ───────────────────────────────────────────────────────────────────
738
+ } else if (command === 'recover') {
739
+ const { JournaledTransaction, TX_STATES } = require('./filesystem/index.js');
740
+ const isStatus = args.includes('--status') || (!args.includes('--rollback') && !args.includes('--continue'));
741
+ const isRollback = args.includes('--rollback');
742
+ const isContinue = args.includes('--continue');
743
+
744
+ const pending = JournaledTransaction.listPending(process.cwd());
745
+
746
+ if (isStatus) {
747
+ console.log('\nContextOS — Transaction Recovery Status\n');
748
+ if (pending.length === 0) {
749
+ console.log('✓ No pending or interrupted transactions found. Project state is clean.');
750
+ } else {
751
+ console.log(`! Found ${pending.length} pending/interrupted transaction(s):\n`);
752
+ for (const tx of pending) {
753
+ console.log(` • ID: ${tx.txId}`);
754
+ console.log(` State: ${tx.state}`);
755
+ console.log(` Created: ${tx.createdAt || 'unknown'}`);
756
+ console.log(` Operations: ${tx.operations ? tx.operations.length : 'unknown'}`);
757
+ console.log('');
758
+ }
759
+ console.log('Run: node .agents/ctx.js recover --rollback [txId]');
760
+ console.log(' node .agents/ctx.js recover --continue [txId]\n');
761
+ }
762
+ } else if (isRollback || isContinue) {
763
+ const txIdArg = args.find(a => !a.startsWith('--') && a !== 'recover');
764
+ const targetTx = txIdArg ? pending.find(p => p.txId === txIdArg) : pending[0];
765
+
766
+ if (!targetTx) {
767
+ console.error(txIdArg ? `Transaction '${txIdArg}' not found in pending list.` : 'No pending transactions found to recover.');
768
+ process.exit(1);
769
+ }
770
+
771
+ const tx = new JournaledTransaction(process.cwd(), targetTx.txId);
772
+ if (fs.existsSync(tx.journalPath)) {
773
+ const jData = JSON.parse(fs.readFileSync(tx.journalPath, 'utf8'));
774
+ tx.state = jData.state;
775
+ tx.operations = jData.operations || [];
776
+ tx.appliedOperations = tx.operations.filter(o => o.backupFilePath);
777
+ }
778
+
779
+ if (isRollback) {
780
+ console.log(`Rolling back transaction '${targetTx.txId}'...`);
781
+ try {
782
+ tx.rollback();
783
+ console.log(`✓ Transaction '${targetTx.txId}' rolled back cleanly.`);
784
+ } catch (err) {
785
+ console.error(`Rollback failed: ${err.message}`);
786
+ process.exit(1);
787
+ }
788
+ } else if (isContinue) {
789
+ console.log(`Continuing transaction '${targetTx.txId}'...`);
790
+ try {
791
+ tx.state = TX_STATES.PREPARED;
792
+ tx.commit();
793
+ console.log(`✓ Transaction '${targetTx.txId}' committed cleanly.`);
794
+ } catch (err) {
795
+ console.error(`Continue failed: ${err.message}`);
796
+ process.exit(1);
797
+ }
798
+ }
799
+ }
800
+
801
+ // ── thread ──────────────────────────────────────────────────────────────────
802
+ } else if (command === 'thread') {
803
+ const { ThreadStore } = require('./runtime/thread-store.js');
804
+ const { evaluateMergeReadiness } = require('./runtime/state-machine.js');
805
+ const store = new ThreadStore({ baseDir: process.cwd() });
806
+ const subcmd = args[1] || 'list';
807
+ const isJson = args.includes('--json');
808
+
809
+ if (subcmd === 'list') {
810
+ const list = store.list();
811
+ if (isJson) {
812
+ console.log(JSON.stringify(list, null, 2));
813
+ } else {
814
+ console.log('\n══════════════════════════════════════════');
815
+ console.log(' ContextOS — Runtime Execution Threads');
816
+ console.log('══════════════════════════════════════════\n');
817
+ if (list.length === 0) {
818
+ console.log(' No runtime threads recorded yet.');
819
+ } else {
820
+ for (const th of list) {
821
+ const ready = th.merge?.status === 'READY' ? ' [READY TO MERGE]' : '';
822
+ console.log(` • ID: ${th.id} (rev: ${th.revision})`);
823
+ console.log(` Status : Exec: ${th.execution.status} | Verify: ${th.verification.status} | Review: ${th.review.status} | Merge: ${th.merge.status}${ready}`);
824
+ console.log(` Task : ${(th.config?.task || '').slice(0, 70)}`);
825
+ console.log(` Created : ${new Date(th.createdAt).toISOString()}`);
826
+ console.log('');
827
+ }
828
+ }
829
+ console.log('──────────────────────────────────────────\n');
830
+ }
831
+ } else if (subcmd === 'get') {
832
+ const threadId = args[2];
833
+ if (!threadId) {
834
+ console.error('Usage: node ctx.js thread get <threadId> [--json]');
835
+ process.exit(1);
836
+ }
837
+ const th = store.get(threadId);
838
+ if (!th) {
839
+ console.error(`Thread "${threadId}" not found.`);
840
+ process.exit(1);
841
+ }
842
+ console.log(JSON.stringify(th, null, 2));
843
+ } else if (subcmd === 'readiness') {
844
+ const threadId = args[2];
845
+ if (!threadId) {
846
+ console.error('Usage: node ctx.js thread readiness <threadId> [--json]');
847
+ process.exit(1);
848
+ }
849
+ const th = store.get(threadId);
850
+ if (!th) {
851
+ console.error(`Thread "${threadId}" not found.`);
852
+ process.exit(1);
853
+ }
854
+ const readiness = evaluateMergeReadiness(th);
855
+ if (isJson) {
856
+ console.log(JSON.stringify(readiness, null, 2));
857
+ } else {
858
+ console.log('\n══════════════════════════════════════════');
859
+ console.log(` ContextOS — Merge Readiness (${th.id})`);
860
+ console.log('══════════════════════════════════════════\n');
861
+ console.log(` Overall Verdict: ${readiness.isReady ? 'READY TO MERGE ✓' : 'NOT READY ✗'}\n`);
862
+ for (const c of readiness.checks) {
863
+ const mark = c.passed ? '✓' : '✗';
864
+ console.log(` ${mark} [${c.name.padEnd(24)}] ${c.message}`);
865
+ }
866
+ console.log('\n──────────────────────────────────────────\n');
867
+ }
868
+ } else {
869
+ console.error(`Unknown thread subcommand: ${subcmd}. Available: list, get, readiness`);
870
+ process.exit(1);
871
+ }
872
+
410
873
  // ── unknown ───────────────────────────────────────────────────────────────────
411
874
  } else {
412
875
  console.error(`Unknown command: ${command}`);