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
@@ -0,0 +1,443 @@
1
+ /**
2
+ * .agents/adapters/pure-compiler.js
3
+ * ContextOS Pure Adapter Compiler Pipeline
4
+ *
5
+ * Implements the Milestone 7 pure adapter contract:
6
+ * - Pure rendering: Adapters return Artifact[] in-memory with ZERO disk side-effects
7
+ * - Deterministic provenance headers without volatile timestamps
8
+ * - Multi-adapter collision detection
9
+ * - Single-transaction application via JournaledTransaction
10
+ * - Lockfile v2 recording with exact and semantic CRLF dual hashing
11
+ */
12
+
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+ const crypto = require('crypto');
16
+
17
+ const {
18
+ resolveManagedPath,
19
+ toPosix,
20
+ ProjectMutationLock,
21
+ JournaledTransaction,
22
+ LockfileV2Manager,
23
+ computeExactHash,
24
+ computeSemanticHash,
25
+ } = require('../filesystem/index.js');
26
+
27
+ const adaptersRegistry = new Map();
28
+
29
+ /**
30
+ * Creates standardized provenance header for an artifact.
31
+ *
32
+ * @param {object} meta
33
+ * @param {string} meta.generator - e.g. "cursor@2", "gemini@2"
34
+ * @param {string} meta.sourceGraphHash - Hash of registry/skills graph
35
+ * @param {string} meta.profileId - Active profile slug
36
+ * @param {string} meta.profileHash - Active profile hash
37
+ * @param {string} [format='markdown'] - 'markdown' or 'yaml'
38
+ * @returns {string}
39
+ */
40
+ function createProvenanceHeader(meta, format = 'markdown') {
41
+ const {
42
+ generator = 'unknown@2',
43
+ sourceGraphHash = 'sha256:0000000000000000000000000000000000000000000000000000000000000000',
44
+ profileId = 'default',
45
+ profileHash = 'sha256:0000000000000000000000000000000000000000000000000000000000000000',
46
+ } = meta;
47
+
48
+ if (format === 'yaml') {
49
+ return [
50
+ '# Generated by ContextOS',
51
+ `# Adapter: ${generator}`,
52
+ `# Source graph: ${sourceGraphHash}`,
53
+ `# Profile: ${profileId} ${profileHash}`,
54
+ '# Do not edit; use .agents/project overrides.',
55
+ '',
56
+ ].join('\n');
57
+ }
58
+
59
+ return [
60
+ '<!--',
61
+ 'Generated by ContextOS',
62
+ `Adapter: ${generator}`,
63
+ `Source graph: ${sourceGraphHash}`,
64
+ `Profile: ${profileId} ${profileHash}`,
65
+ 'Do not edit; use .agents/project overrides.',
66
+ '-->\n',
67
+ ].join('\n');
68
+ }
69
+
70
+ /**
71
+ * Loads project context required for adapter rendering.
72
+ */
73
+ function loadCompilerContext(projectRoot, options = {}) {
74
+ const absRoot = path.resolve(projectRoot);
75
+
76
+ // 1. Registry v2
77
+ let registry = null;
78
+ const regPath = path.join(absRoot, '.agents', 'compiled', 'registry.v2.json');
79
+ if (fs.existsSync(regPath)) {
80
+ try {
81
+ registry = JSON.parse(fs.readFileSync(regPath, 'utf8'));
82
+ } catch {
83
+ // Fallback below
84
+ }
85
+ }
86
+
87
+ // 2. Profile v2
88
+ let profile = null;
89
+ try {
90
+ const profiles = require('../profiles.js');
91
+ profile = options.profile ? profiles.getProfile(options.profile, absRoot) : profiles.getActiveProfile(absRoot);
92
+ } catch {
93
+ profile = null;
94
+ }
95
+
96
+ // 3. Workspace Graph
97
+ let workspace = null;
98
+ try {
99
+ const { buildWorkspaceGraph } = require('../workspace/workspace-graph.js');
100
+ workspace = buildWorkspaceGraph(absRoot);
101
+ } catch {
102
+ workspace = null;
103
+ }
104
+
105
+ const sourceGraphHash = registry?.sourceGraphHash || 'sha256:0000000000000000000000000000000000000000000000000000000000000000';
106
+ const profileId = profile?.id || profile?.name || 'default';
107
+ const profileHash = profile ? computeExactHash(JSON.stringify(profile)) : 'sha256:0000000000000000000000000000000000000000000000000000000000000000';
108
+
109
+ return {
110
+ projectRoot: absRoot,
111
+ registry,
112
+ profile,
113
+ profileId,
114
+ profileHash,
115
+ sourceGraphHash,
116
+ workspace,
117
+ config: options.config || {},
118
+ };
119
+ }
120
+
121
+ const DEFAULT_ADAPTERS = ['gemini', 'claude', 'cursor', 'copilot', 'aider', 'zed'];
122
+
123
+ function ensureDefaultAdaptersLoaded() {
124
+ for (const name of DEFAULT_ADAPTERS) {
125
+ if (!adaptersRegistry.has(name)) {
126
+ try {
127
+ require(`./${name}/export.js`);
128
+ } catch {
129
+ // Best effort
130
+ }
131
+ }
132
+ }
133
+ }
134
+
135
+ /**
136
+ * Registers an adapter with the pure compiler.
137
+ */
138
+ function registerAdapter(name, adapter) {
139
+ adaptersRegistry.set(name, adapter);
140
+ }
141
+
142
+ /**
143
+ * Retrieves a registered adapter.
144
+ */
145
+ function getAdapter(name) {
146
+ ensureDefaultAdaptersLoaded();
147
+ return adaptersRegistry.get(name);
148
+ }
149
+
150
+ /**
151
+ * Lists names of all registered adapters.
152
+ */
153
+ function listAdapters() {
154
+ ensureDefaultAdaptersLoaded();
155
+ return Array.from(adaptersRegistry.keys());
156
+ }
157
+
158
+ /**
159
+ * Renders all requested adapters in-memory with strict collision detection.
160
+ *
161
+ * @param {string} projectRoot
162
+ * @param {string[]|string} adapterNames - e.g. ['cursor', 'claude'] or 'all'
163
+ * @param {object} [options]
164
+ * @returns {{ artifacts: object[], collisions: object[], context: object }}
165
+ */
166
+ function renderAdapters(projectRoot, adapterNames = 'all', options = {}) {
167
+ const context = loadCompilerContext(projectRoot, options);
168
+ const targets = adapterNames === 'all'
169
+ ? listAdapters()
170
+ : (Array.isArray(adapterNames) ? adapterNames : [adapterNames]);
171
+
172
+ const allArtifacts = [];
173
+ const pathToArtifact = new Map();
174
+ const collisions = [];
175
+
176
+ for (const name of targets) {
177
+ const adapter = getAdapter(name);
178
+ if (!adapter) {
179
+ throw new Error(`Unknown adapter '${name}'. Available: ${listAdapters().join(', ')}`);
180
+ }
181
+
182
+ const rendered = adapter.render(context);
183
+ for (const art of rendered) {
184
+ const posixPath = toPosix(art.path);
185
+ const contentBuf = Buffer.isBuffer(art.content) ? art.content : Buffer.from(String(art.content), 'utf8');
186
+
187
+ if (pathToArtifact.has(posixPath)) {
188
+ const existing = pathToArtifact.get(posixPath);
189
+ // Collision detected
190
+ collisions.push({
191
+ path: posixPath,
192
+ firstAdapter: existing.generator,
193
+ secondAdapter: art.generator || `${name}@2`,
194
+ });
195
+ } else {
196
+ const standardized = {
197
+ ...art,
198
+ path: posixPath,
199
+ content: contentBuf,
200
+ generator: art.generator || `${name}@2`,
201
+ mediaType: art.mediaType || 'text/markdown',
202
+ kind: art.kind || 'generated-adapter',
203
+ sourceSkillIds: art.sourceSkillIds || [],
204
+ inputsHash: art.inputsHash || computeExactHash(context.sourceGraphHash + context.profileHash),
205
+ };
206
+ pathToArtifact.set(posixPath, standardized);
207
+ allArtifacts.push(standardized);
208
+ }
209
+ }
210
+ }
211
+
212
+ return {
213
+ artifacts: allArtifacts,
214
+ collisions,
215
+ context,
216
+ };
217
+ }
218
+
219
+ /**
220
+ * Applies rendered artifacts to disk in a single atomic JournaledTransaction
221
+ * and updates Lockfile v2.
222
+ */
223
+ function applyArtifacts(projectRoot, artifacts, options = {}) {
224
+ const absRoot = path.resolve(projectRoot);
225
+ const ownLock = !options.lockToken;
226
+ const lock = ownLock ? new ProjectMutationLock(absRoot) : null;
227
+ const lockToken = ownLock ? lock.acquire({ command: options.command || 'export' }) : options.lockToken;
228
+
229
+ try {
230
+ const tx = new JournaledTransaction(absRoot);
231
+ const lockfileManager = new LockfileV2Manager(absRoot);
232
+ const lockfileData = lockfileManager.read() || lockfileManager.createEmpty({
233
+ profileId: options.context?.profileId || 'default',
234
+ profileHash: options.context?.profileHash,
235
+ sourceGraphHash: options.context?.sourceGraphHash,
236
+ enabledAdapters: options.enabledAdapters || listAdapters(),
237
+ });
238
+
239
+ let hasModifications = false;
240
+
241
+ for (const art of artifacts) {
242
+ const exactSha256 = computeExactHash(art.content);
243
+ const semanticTextSha256 = computeSemanticHash(art.content);
244
+ const existingRecord = lockfileData?.managedFiles?.[art.path];
245
+
246
+ let needsWrite = true;
247
+ let needsLockfileUpdate = true;
248
+
249
+ if (existingRecord) {
250
+ if (existingRecord.exactSha256 === exactSha256 && existingRecord.inputsHash === art.inputsHash) {
251
+ needsLockfileUpdate = false;
252
+ }
253
+ }
254
+
255
+ const absPath = path.resolve(absRoot, art.path);
256
+ if (fs.existsSync(absPath)) {
257
+ const diskBuf = fs.readFileSync(absPath);
258
+ if (computeExactHash(diskBuf) === exactSha256) {
259
+ needsWrite = false;
260
+ }
261
+ }
262
+
263
+ if (needsWrite) {
264
+ tx.stageWrite(art.path, art.content, { mode: art.mode || 420 });
265
+ hasModifications = true;
266
+ }
267
+
268
+ if (needsLockfileUpdate || needsWrite || !existingRecord) {
269
+ lockfileManager.recordManagedFile(lockfileData, art.path, {
270
+ exactSha256,
271
+ semanticTextSha256,
272
+ kind: art.kind,
273
+ generator: art.generator,
274
+ inputsHash: art.inputsHash,
275
+ mode: art.mode || 420,
276
+ lastTransaction: needsWrite ? tx.txId : existingRecord?.lastTransaction,
277
+ });
278
+ if (needsLockfileUpdate) hasModifications = true;
279
+ }
280
+ }
281
+
282
+ const activePaths = new Set(artifacts.map(a => toPosix(a.path)));
283
+ const activeGenerators = new Set(artifacts.map(a => a.generator));
284
+
285
+ // Support backward compatibility with Lockfile v1 (.agents/contextos.lock.json)
286
+ const v1LockPath = path.join(absRoot, '.agents', 'contextos.lock.json');
287
+ let v1Data = null;
288
+ if (fs.existsSync(v1LockPath)) {
289
+ try {
290
+ v1Data = JSON.parse(fs.readFileSync(v1LockPath, 'utf8'));
291
+ } catch {}
292
+ }
293
+
294
+ // 1. Prune stale files recorded in Lockfile v2
295
+ if (lockfileData && lockfileData.managedFiles) {
296
+ for (const [recordedPath, meta] of Object.entries(lockfileData.managedFiles)) {
297
+ if (activeGenerators.has(meta.generator) && !activePaths.has(recordedPath)) {
298
+ const absRecPath = path.resolve(absRoot, recordedPath);
299
+ if (fs.existsSync(absRecPath)) {
300
+ tx.stageDelete(recordedPath);
301
+ hasModifications = true;
302
+ }
303
+ lockfileManager.removeManagedFile(lockfileData, recordedPath);
304
+ hasModifications = true;
305
+ }
306
+ }
307
+ }
308
+
309
+ // 2. Cursor adapter rule pruning: scan .cursor/rules/*.mdc for stale managed files
310
+ if (activeGenerators.has('cursor@2')) {
311
+ const cursorRulesDir = path.join(absRoot, '.cursor', 'rules');
312
+ if (fs.existsSync(cursorRulesDir)) {
313
+ for (const file of fs.readdirSync(cursorRulesDir)) {
314
+ if (file.endsWith('.mdc')) {
315
+ const relPath = toPosix(path.relative(absRoot, path.join(cursorRulesDir, file)));
316
+ if (!activePaths.has(relPath)) {
317
+ const isManagedInV1 = Boolean(v1Data?.files?.[relPath]?.managed || v1Data?.managedFiles?.[relPath]?.managed);
318
+ const isManagedInV2 = Boolean(lockfileData?.managedFiles?.[relPath]);
319
+ let hasContextosMarker = false;
320
+ try {
321
+ const content = fs.readFileSync(path.join(cursorRulesDir, file), 'utf8');
322
+ hasContextosMarker =
323
+ content.includes('ContextOS rules for') ||
324
+ content.includes('<!-- Auto-generated by: node .agents/ctx.js export cursor -->') ||
325
+ content.includes('ContextOS — Project Operating System Rules') ||
326
+ content.includes('contextos:generator');
327
+ } catch {}
328
+
329
+ if (isManagedInV1 || isManagedInV2 || hasContextosMarker) {
330
+ tx.stageDelete(relPath);
331
+ hasModifications = true;
332
+ if (v1Data?.files?.[relPath]) { delete v1Data.files[relPath]; hasModifications = true; }
333
+ if (v1Data?.managedFiles?.[relPath]) { delete v1Data.managedFiles[relPath]; hasModifications = true; }
334
+ if (lockfileData?.managedFiles?.[relPath]) { lockfileManager.removeManagedFile(lockfileData, relPath); hasModifications = true; }
335
+ }
336
+ }
337
+ }
338
+ }
339
+ }
340
+ }
341
+
342
+ // 3. Zed adapter prompt pruning: scan .zed/prompts/*.md for stale managed files
343
+ if (activeGenerators.has('zed@2')) {
344
+ const zedPromptsDir = path.join(absRoot, '.zed', 'prompts');
345
+ if (fs.existsSync(zedPromptsDir)) {
346
+ for (const file of fs.readdirSync(zedPromptsDir)) {
347
+ if (file.endsWith('.md')) {
348
+ const relPath = toPosix(path.relative(absRoot, path.join(zedPromptsDir, file)));
349
+ if (!activePaths.has(relPath)) {
350
+ const isManagedInV1 = Boolean(v1Data?.files?.[relPath]?.managed || v1Data?.managedFiles?.[relPath]?.managed);
351
+ const isManagedInV2 = Boolean(lockfileData?.managedFiles?.[relPath]);
352
+ let hasContextosMarker = false;
353
+ try {
354
+ const content = fs.readFileSync(path.join(zedPromptsDir, file), 'utf8');
355
+ hasContextosMarker =
356
+ content.includes('<!-- Auto-generated by: node .agents/ctx.js export zed -->') ||
357
+ content.includes('# ContextOS —') ||
358
+ content.includes('# ContextOS Master Prompt') ||
359
+ content.includes('contextos:generator');
360
+ } catch {}
361
+
362
+ if (isManagedInV1 || isManagedInV2 || hasContextosMarker) {
363
+ tx.stageDelete(relPath);
364
+ hasModifications = true;
365
+ if (v1Data?.files?.[relPath]) { delete v1Data.files[relPath]; hasModifications = true; }
366
+ if (v1Data?.managedFiles?.[relPath]) { delete v1Data.managedFiles[relPath]; hasModifications = true; }
367
+ if (lockfileData?.managedFiles?.[relPath]) { lockfileManager.removeManagedFile(lockfileData, relPath); hasModifications = true; }
368
+ }
369
+ }
370
+ }
371
+ }
372
+ }
373
+ }
374
+
375
+ // Clean up empty/orphan skill directories in generated paths
376
+ const cleanupDirs = [
377
+ path.join(absRoot, '.agents', 'generated', 'gemini', 'skills'),
378
+ path.join(absRoot, '.agents', 'generated', 'claude', 'skills'),
379
+ ];
380
+ for (const parentDir of cleanupDirs) {
381
+ if (fs.existsSync(parentDir)) {
382
+ for (const entry of fs.readdirSync(parentDir)) {
383
+ const entryPath = path.join(parentDir, entry);
384
+ if (fs.statSync(entryPath).isDirectory()) {
385
+ const relMd = toPosix(path.relative(absRoot, path.join(entryPath, 'SKILL.md')));
386
+ if (!activePaths.has(relMd)) {
387
+ // Delete orphaned files inside the directory, if any. The generator writes SKILL.md and optional references.
388
+ for (const child of fs.readdirSync(entryPath)) {
389
+ tx.stageDelete(toPosix(path.relative(absRoot, path.join(entryPath, child))));
390
+ hasModifications = true;
391
+ }
392
+ const relDir = toPosix(path.relative(absRoot, entryPath));
393
+ tx.stageDeleteDir(relDir);
394
+ hasModifications = true;
395
+ }
396
+ }
397
+ }
398
+ }
399
+ }
400
+
401
+ // ONLY commit and bump revision if modifications occurred
402
+ let txResult = { txId: tx.txId, appliedCount: 0 };
403
+
404
+ if (hasModifications) {
405
+ // Persist updated v1 lockfile if present
406
+ if (v1Data && fs.existsSync(v1LockPath)) {
407
+ try {
408
+ const relV1LockPath = toPosix(path.relative(absRoot, v1LockPath));
409
+ tx.stageWrite(relV1LockPath, JSON.stringify(v1Data, null, 2) + '\n');
410
+ } catch {}
411
+ }
412
+
413
+ // Stage lockfile v2 update
414
+ lockfileData.revision += 1;
415
+ const relLockPath = toPosix(path.relative(absRoot, lockfileManager.lockfilePath));
416
+ tx.stageWrite(relLockPath, JSON.stringify(lockfileData, null, 2) + '\n');
417
+
418
+ // Commit all file modifications atomically
419
+ txResult = tx.commit();
420
+ }
421
+
422
+ return {
423
+ success: true,
424
+ txId: txResult.txId,
425
+ appliedCount: hasModifications ? artifacts.length : 0,
426
+ skipped: !hasModifications
427
+ };
428
+ } finally {
429
+ if (ownLock && lockToken && lock) {
430
+ lock.release(lockToken);
431
+ }
432
+ }
433
+ }
434
+
435
+ module.exports = {
436
+ createProvenanceHeader,
437
+ loadCompilerContext,
438
+ registerAdapter,
439
+ getAdapter,
440
+ listAdapters,
441
+ renderAdapters,
442
+ applyArtifacts,
443
+ };
@@ -1,26 +1,28 @@
1
+ /**
2
+ * .agents/adapters/zed/export.js
3
+ * ContextOS Zed IDE Pure Adapter (.zed/rules.md & .zed/prompts/*.md)
4
+ */
5
+
1
6
  const fs = require('fs');
2
7
  const path = require('path');
3
- const { AGENTS_MD_PATH, collectSkillDirectories, extractYamlField, stripFrontmatter, readMeaningfulMarkdown } = require('../shared.js');
8
+ const { AGENTS_MD_PATH, collectSkillDirectories, extractYamlField, stripFrontmatter } = require('../shared.js');
9
+ const { registerAdapter, applyArtifacts, createProvenanceHeader } = require('../pure-compiler.js');
4
10
 
5
- // Output destinations for Zed
6
- const ZED_DIR = path.join(process.cwd(), '.zed');
7
- const RULES_FILE = path.join(ZED_DIR, 'rules.md');
8
- const PROMPTS_DIR = path.join(ZED_DIR, 'prompts');
11
+ const GENERATOR_ID = 'zed@2';
9
12
 
10
- /**
11
- * Zed IDE adapter — export.js
12
- *
13
- * Generates:
14
- * 1. `.zed/rules.md` — Project assistant instructions loaded into Zed's context
15
- * 2. `.zed/prompts/*.md` — Modular slash-command prompts for Zed Assistant
16
- *
17
- * Format spec: https://zed.dev/docs/assistant
18
- */
13
+ function describe() {
14
+ return {
15
+ name: 'zed',
16
+ version: '2.0.0',
17
+ description: 'Compiles instructions and prompts for Zed IDE (.zed/rules.md and .zed/prompts/*.md)',
18
+ targetPattern: '.zed/**',
19
+ };
20
+ }
19
21
 
20
22
  function buildSkillSection(skillDir) {
21
- const skillName = path.basename(skillDir);
22
- const skillMdPath = path.join(skillDir, 'SKILL.md');
23
- const yamlPath = path.join(skillDir, 'skill.yaml');
23
+ const skillName = path.basename(skillDir);
24
+ const skillMdPath = path.join(skillDir, 'SKILL.md');
25
+ const yamlPath = path.join(skillDir, 'skill.yaml');
24
26
 
25
27
  let title = skillName;
26
28
  let description = '';
@@ -46,105 +48,111 @@ function buildSkillSection(skillDir) {
46
48
  skillName,
47
49
  title,
48
50
  section: `\n### Skill: ${title}\n${descLine}${promptRef}`,
49
- prompt: `<!-- Auto-generated by: node .agents/ctx.js export zed -->\n# ContextOS — ${title}\n\n${descLine}\n${body}\n`,
51
+ prompt: `# ContextOS — ${title}\n\n${descLine}\n${body}\n`,
50
52
  };
51
53
  }
52
54
 
53
- function run() {
54
- console.log('Starting Zed IDE adapter export...');
55
-
56
- const zedDir = path.join(process.cwd(), '.zed');
57
- const rulesFile = path.join(zedDir, 'rules.md');
58
- const promptsDir = path.join(zedDir, 'prompts');
59
- const agentsMdPath = fs.existsSync(path.join(process.cwd(), '.agents', 'AGENTS.md'))
60
- ? path.join(process.cwd(), '.agents', 'AGENTS.md')
55
+ function render(context) {
56
+ const projectRoot = context?.projectRoot || '.';
57
+ const agentsMdPath = fs.existsSync(path.join(projectRoot, '.agents', 'AGENTS.md'))
58
+ ? path.join(projectRoot, '.agents', 'AGENTS.md')
61
59
  : AGENTS_MD_PATH;
62
60
 
63
- fs.mkdirSync(zedDir, { recursive: true });
64
- fs.mkdirSync(promptsDir, { recursive: true });
61
+ const prov = createProvenanceHeader({
62
+ generator: GENERATOR_ID,
63
+ sourceGraphHash: context?.sourceGraphHash,
64
+ profileId: context?.profileId,
65
+ profileHash: context?.profileHash,
66
+ });
65
67
 
66
- const lines = [];
68
+ const artifacts = [];
69
+ const rulesLines = [];
67
70
 
68
- // ── Header ───────────────────────────────────────────────────────────────────
69
- lines.push(
70
- `# ContextOS — AI Rules for Zed Assistant\n`,
71
- `<!-- Auto-generated by: node .agents/ctx.js export zed -->\n`,
72
- `<!-- Source: .agents/core/skills/ · Do not edit manually. -->\n\n`
71
+ rulesLines.push(
72
+ prov +
73
+ `# ContextOS — AI Rules for Zed Assistant\n\n` +
74
+ `> **Core law: Do not read everything. Read only what the current task requires.**\n\n`
73
75
  );
74
76
 
75
- // ── Project Rules ────────────────────────────────────────────────────────────
76
77
  if (fs.existsSync(agentsMdPath)) {
77
78
  const agentsMd = fs.readFileSync(agentsMdPath, 'utf8');
78
- lines.push(`## Project Rules (AGENTS.md)\n\n${agentsMd}\n\n---\n`);
79
-
80
- // Also write a master prompt in .zed/prompts/contextos.md
81
- fs.writeFileSync(
82
- path.join(promptsDir, 'contextos.md'),
83
- `<!-- Auto-generated by: node .agents/ctx.js export zed -->\n# ContextOS Master Prompt\n\n${agentsMd}\n`
84
- );
79
+ rulesLines.push(`## Core Rules & Step 0\n\n${agentsMd}\n\n---\n`);
80
+
81
+ artifacts.push({
82
+ path: '.zed/prompts/contextos.md',
83
+ content: (prov + `# ContextOS Master Prompt\n\n${agentsMd}\n`).replace(/\r\n/g, '\n'),
84
+ mediaType: 'text/markdown',
85
+ kind: 'generated-adapter',
86
+ generator: GENERATOR_ID,
87
+ sourceSkillIds: ['project-rules'],
88
+ inputsHash: context?.sourceGraphHash || 'none',
89
+ });
85
90
  }
86
91
 
87
- // ── Skills ───────────────────────────────────────────────────────────────────
88
- lines.push(`\n## Skills Library\n`);
89
- lines.push(`The following specialist skills guide architecture and implementation:\n`);
90
-
91
- const skills = collectSkillDirectories();
92
- const activePromptFiles = new Set(['contextos.md']);
93
- let count = 0;
92
+ rulesLines.push(
93
+ `\n## Skills Library\n\n` +
94
+ `Each skill is also available as a slash-command prompt in \`.zed/prompts/<skill>.md\`.\n\n` +
95
+ `### Available Skills\n`
96
+ );
94
97
 
98
+ const skills = collectSkillDirectories(context?.profile);
95
99
  for (const skill of skills) {
96
- const skillData = buildSkillSection(skill);
97
- if (skillData) {
98
- lines.push(skillData.section);
99
- const promptFileName = `${skillData.skillName}.md`;
100
- activePromptFiles.add(promptFileName);
101
- fs.writeFileSync(path.join(promptsDir, promptFileName), skillData.prompt);
102
- count++;
100
+ const res = buildSkillSection(skill);
101
+ if (res) {
102
+ rulesLines.push(res.section);
103
+
104
+ artifacts.push({
105
+ path: `.zed/prompts/${res.skillName}.md`,
106
+ content: (prov + res.prompt).replace(/\r\n/g, '\n'),
107
+ mediaType: 'text/markdown',
108
+ kind: 'generated-adapter',
109
+ generator: GENERATOR_ID,
110
+ sourceSkillIds: [res.skillName],
111
+ inputsHash: context?.sourceGraphHash || 'none',
112
+ });
103
113
  }
104
114
  }
105
115
 
106
- // Clean up stale prompts from uninstalled skills/plugins safely (provenance-verified only)
107
- if (fs.existsSync(promptsDir)) {
108
- const lockfilePath = path.join(process.cwd(), '.agents', 'contextos.lock.json');
109
- let lockData = null;
110
- try {
111
- if (fs.existsSync(lockfilePath)) {
112
- lockData = JSON.parse(fs.readFileSync(lockfilePath, 'utf8'));
113
- }
114
- } catch {}
115
-
116
- for (const file of fs.readdirSync(promptsDir)) {
117
- if (file.endsWith('.md') && !activePromptFiles.has(file)) {
118
- const fullFilePath = path.join(promptsDir, file);
119
- const relPath = path.relative(process.cwd(), fullFilePath).replace(/\\/g, '/');
120
-
121
- const isManagedInLock = Boolean(lockData?.managedFiles?.[relPath]?.managed);
122
- let hasContextosMarker = false;
123
- try {
124
- const content = fs.readFileSync(fullFilePath, 'utf8');
125
- hasContextosMarker =
126
- content.includes('<!-- Auto-generated by: node .agents/ctx.js export zed -->') ||
127
- content.includes('# ContextOS —') ||
128
- content.includes('# ContextOS Master Prompt');
129
- } catch {}
130
-
131
- if (isManagedInLock || hasContextosMarker) {
132
- fs.unlinkSync(fullFilePath);
133
- if (lockData?.managedFiles?.[relPath]) {
134
- delete lockData.managedFiles[relPath];
135
- try {
136
- fs.writeFileSync(lockfilePath, JSON.stringify(lockData, null, 2) + '\n', 'utf8');
137
- } catch {}
138
- }
139
- }
140
- }
116
+ artifacts.push({
117
+ path: '.zed/rules.md',
118
+ content: rulesLines.join('').replace(/\r\n/g, '\n'),
119
+ mediaType: 'text/markdown',
120
+ kind: 'generated-adapter',
121
+ generator: GENERATOR_ID,
122
+ sourceSkillIds: skills.map(s => path.basename(s)),
123
+ inputsHash: context?.sourceGraphHash || 'none',
124
+ });
125
+
126
+ return artifacts;
127
+ }
128
+
129
+ function validate(artifacts) {
130
+ const diagnostics = [];
131
+ for (const art of artifacts) {
132
+ if (!art.content || art.content.length === 0) {
133
+ diagnostics.push({ path: art.path, message: 'Empty artifact content' });
141
134
  }
142
135
  }
136
+ return diagnostics;
137
+ }
143
138
 
144
- // Write master .zed/rules.md
145
- fs.writeFileSync(rulesFile, lines.join(''));
146
- console.log(`Generated .zed/rules.md (${count} skills) → ${rulesFile}`);
147
- console.log(`Generated .zed/prompts/*.md (${count} prompts) → ${promptsDir}`);
139
+ function run(options = {}) {
140
+ const { loadCompilerContext } = require('../pure-compiler.js');
141
+ const projectRoot = options.projectRoot || '.';
142
+ const context = loadCompilerContext(projectRoot, options);
143
+ const artifacts = render(context);
144
+ const result = applyArtifacts(projectRoot, artifacts, { command: 'export zed', context });
145
+ console.log(`✓ Zed export complete: ${result.appliedCount} files applied (tx: ${result.txId})`);
146
+ return result;
148
147
  }
149
148
 
150
- module.exports = { run };
149
+ const adapter = {
150
+ describe,
151
+ render,
152
+ validate,
153
+ run,
154
+ };
155
+
156
+ registerAdapter('zed', adapter);
157
+
158
+ module.exports = adapter;