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.
- package/.agents/AGENTS.md +1 -1
- package/.agents/adapters/aider/export.js +117 -99
- package/.agents/adapters/claude/export.js +68 -26
- package/.agents/adapters/copilot/export.js +90 -53
- package/.agents/adapters/cursor/export.js +80 -101
- package/.agents/adapters/drift-detector.js +196 -0
- package/.agents/adapters/gemini/export.js +76 -45
- package/.agents/adapters/pure-compiler.js +443 -0
- package/.agents/adapters/zed/export.js +104 -96
- package/.agents/compiled/registry.v2.json +504 -0
- package/.agents/compiled/registry.v2.sha256 +1 -0
- package/.agents/compiler/manifest-compiler.js +963 -0
- package/.agents/compiler/vendor/yaml.LICENSE.txt +13 -0
- package/.agents/compiler/vendor/yaml.SBOM.json +6 -0
- package/.agents/compiler/vendor/yaml.js +139 -0
- package/.agents/core/profiles/init.yaml +25 -0
- package/.agents/core/skills/context-manager/skill.yaml +3 -5
- package/.agents/core/skills/context-os/SKILL.md +3 -6
- package/.agents/core/skills/context-os/skill.yaml +3 -8
- package/.agents/core/skills/engineering-workflow/skill.yaml +1 -7
- package/.agents/core/skills/gemini-precision/skill.yaml +1 -6
- package/.agents/core/skills/gstack-roles/skill.yaml +3 -6
- package/.agents/core/skills/ponytail-mindset/skill.yaml +1 -7
- package/.agents/core/skills/security/skill.yaml +15 -3
- package/.agents/ctx.js +574 -111
- package/.agents/customization-dx.js +282 -0
- package/.agents/doctor.js +719 -64
- package/.agents/filesystem/index.js +71 -0
- package/.agents/filesystem/journaled-transaction.js +451 -0
- package/.agents/filesystem/lockfile-v2.js +275 -0
- package/.agents/filesystem/platform-hardening.js +222 -0
- package/.agents/filesystem/project-lock.js +218 -0
- package/.agents/filesystem/safe-path.js +256 -0
- package/.agents/generated/claude/skills/context-os/SKILL.md +1 -1
- package/.agents/generated/gemini/skills/context-os/SKILL.md +2 -2
- package/.agents/plugins/contextos/plugin.json +1 -1
- package/.agents/plugins.js +259 -60
- package/.agents/profiles.js +486 -51
- package/.agents/resolver.js +50 -534
- package/.agents/schemas/attestation.review.v1.json +111 -0
- package/.agents/schemas/attestation.verification.v1.json +85 -0
- package/.agents/schemas/lockfile.v2.schema.json +134 -0
- package/.agents/schemas/profile.v2.schema.json +114 -0
- package/.agents/schemas/runtime.thread.v1.json +192 -0
- package/.agents/schemas/skill.manifest.v2.json +177 -0
- package/.agents/schemas/verification.spec.v1.json +39 -0
- package/.agents/schemas/workspace.graph.schema.json +106 -0
- package/.agents/transaction-core/event-store.js +288 -0
- package/.agents/transaction-core/idempotency.js +129 -0
- package/.agents/transaction-core/ipc-lock.js +311 -0
- package/.agents/transaction-core/plugin-supply-chain-bundle.js +436 -0
- package/.agents/validate.js +44 -1
- package/.agents/watch.js +354 -102
- package/.agents/workspace/workspace-graph.js +778 -0
- package/README.md +59 -387
- package/benchmarks/v2/analysis/statistics.js +140 -0
- package/benchmarks/v2/analysis/stats.js +69 -0
- package/benchmarks/v2/arms/arm-definitions.js +79 -0
- package/benchmarks/v2/dataset.schema.json +34 -0
- package/benchmarks/v2/evaluators/index.js +25 -0
- package/benchmarks/v2/evaluators/verified-success.js +116 -0
- package/benchmarks/v2/harness/runner.js +88 -0
- package/benchmarks/v2/pilot-tasks.json +392 -0
- package/bin/commands/recover.js +88 -0
- package/bin/commands/update.js +80 -17
- package/bin/commands.js +62 -25
- package/bin/index.js +138 -81
- package/bin/lib/lockfile.js +5 -3
- package/bin/lib/safe-writer.js +34 -3
- package/package.json +85 -72
- package/registry.json +2 -2
- package/registry.v2.schema.json +86 -0
- package/.agents/core/profiles/backend.yaml +0 -47
- package/.agents/core/profiles/enterprise.yaml +0 -46
- package/.agents/core/profiles/frontend.yaml +0 -46
- package/.agents/core/profiles/hackathon.yaml +0 -45
- package/.agents/core/profiles/mvp.yaml +0 -44
- package/.agents/core/profiles/startup.yaml +0 -48
- package/.agents/core/skills/adapters/EXAMPLES.md +0 -19
- package/.agents/core/skills/adapters/SKILL.md +0 -105
- package/.agents/core/skills/adapters/TROUBLESHOOTING.md +0 -7
- package/.agents/core/skills/adapters/VALIDATION.json +0 -12
- package/.agents/core/skills/adapters/skill.yaml +0 -16
- package/.agents/core/skills/architecture-diagrams/SKILL.md +0 -108
- package/.agents/core/skills/architecture-diagrams/VALIDATION.json +0 -12
- package/.agents/core/skills/architecture-diagrams/skill.yaml +0 -12
- package/.agents/core/skills/brutalist-design/SKILL.md +0 -150
- package/.agents/core/skills/brutalist-design/VALIDATION.json +0 -12
- package/.agents/core/skills/brutalist-design/skill.yaml +0 -12
- package/.agents/core/skills/database/EXAMPLES.md +0 -74
- package/.agents/core/skills/database/SKILL.md +0 -101
- package/.agents/core/skills/database/TROUBLESHOOTING.md +0 -18
- package/.agents/core/skills/database/VALIDATION.json +0 -11
- package/.agents/core/skills/database/skill.yaml +0 -31
- package/.agents/core/skills/ddd/EXAMPLES.md +0 -42
- package/.agents/core/skills/ddd/SKILL.md +0 -247
- package/.agents/core/skills/ddd/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/ddd/VALIDATION.json +0 -12
- package/.agents/core/skills/ddd/ddd.md +0 -178
- package/.agents/core/skills/ddd/skill.yaml +0 -17
- package/.agents/core/skills/decisions/EXAMPLES.md +0 -35
- package/.agents/core/skills/decisions/SKILL.md +0 -90
- package/.agents/core/skills/decisions/TROUBLESHOOTING.md +0 -13
- package/.agents/core/skills/decisions/VALIDATION.json +0 -12
- package/.agents/core/skills/decisions/skill.yaml +0 -16
- package/.agents/core/skills/docker/EXAMPLES.md +0 -56
- package/.agents/core/skills/docker/SKILL.md +0 -63
- package/.agents/core/skills/docker/TROUBLESHOOTING.md +0 -18
- package/.agents/core/skills/docker/VALIDATION.json +0 -11
- package/.agents/core/skills/docker/skill.yaml +0 -29
- package/.agents/core/skills/fastapi/EXAMPLES.md +0 -36
- package/.agents/core/skills/fastapi/SKILL.md +0 -148
- package/.agents/core/skills/fastapi/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/fastapi/VALIDATION.json +0 -12
- package/.agents/core/skills/fastapi/fastapi.md +0 -112
- package/.agents/core/skills/fastapi/skill.yaml +0 -17
- package/.agents/core/skills/generators/EXAMPLES.md +0 -19
- package/.agents/core/skills/generators/SKILL.md +0 -112
- package/.agents/core/skills/generators/TROUBLESHOOTING.md +0 -7
- package/.agents/core/skills/generators/VALIDATION.json +0 -12
- package/.agents/core/skills/generators/skill.yaml +0 -25
- package/.agents/core/skills/generators/templates/API.md +0 -77
- package/.agents/core/skills/generators/templates/ARCHITECTURE.md +0 -70
- package/.agents/core/skills/generators/templates/DATABASE.md +0 -42
- package/.agents/core/skills/generators/templates/DECISION.md +0 -46
- package/.agents/core/skills/generators/templates/PRD.md +0 -67
- package/.agents/core/skills/generators/templates/PROJECT_GRAPH.md +0 -56
- package/.agents/core/skills/generators/templates/ROADMAP.md +0 -51
- package/.agents/core/skills/generators/templates/TASKS.md +0 -43
- package/.agents/core/skills/generators/templates/UI.md +0 -73
- package/.agents/core/skills/graphify/EXAMPLES.md +0 -73
- package/.agents/core/skills/graphify/SKILL.md +0 -130
- package/.agents/core/skills/graphify/VALIDATION.json +0 -12
- package/.agents/core/skills/graphify/skill.yaml +0 -18
- package/.agents/core/skills/impeccable-design/EXAMPLES.md +0 -26
- package/.agents/core/skills/impeccable-design/SKILL.md +0 -201
- package/.agents/core/skills/impeccable-design/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/impeccable-design/VALIDATION.json +0 -12
- package/.agents/core/skills/impeccable-design/skill.yaml +0 -20
- package/.agents/core/skills/interview-me/SKILL.md +0 -97
- package/.agents/core/skills/interview-me/VALIDATION.json +0 -12
- package/.agents/core/skills/interview-me/skill.yaml +0 -12
- package/.agents/core/skills/microservices/EXAMPLES.md +0 -38
- package/.agents/core/skills/microservices/SKILL.md +0 -164
- package/.agents/core/skills/microservices/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/microservices/VALIDATION.json +0 -12
- package/.agents/core/skills/microservices/microservices.md +0 -119
- package/.agents/core/skills/microservices/skill.yaml +0 -17
- package/.agents/core/skills/minimalist-design/SKILL.md +0 -113
- package/.agents/core/skills/minimalist-design/VALIDATION.json +0 -12
- package/.agents/core/skills/minimalist-design/skill.yaml +0 -12
- package/.agents/core/skills/nestjs/EXAMPLES.md +0 -40
- package/.agents/core/skills/nestjs/SKILL.md +0 -139
- package/.agents/core/skills/nestjs/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/nestjs/VALIDATION.json +0 -12
- package/.agents/core/skills/nestjs/nestjs.md +0 -103
- package/.agents/core/skills/nestjs/skill.yaml +0 -17
- package/.agents/core/skills/nextjs/EXAMPLES.md +0 -40
- package/.agents/core/skills/nextjs/SKILL.md +0 -163
- package/.agents/core/skills/nextjs/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/nextjs/VALIDATION.json +0 -12
- package/.agents/core/skills/nextjs/nextjs.md +0 -67
- package/.agents/core/skills/nextjs/skill.yaml +0 -17
- package/.agents/core/skills/node/EXAMPLES.md +0 -80
- package/.agents/core/skills/node/SKILL.md +0 -128
- package/.agents/core/skills/node/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/node/VALIDATION.json +0 -12
- package/.agents/core/skills/node/node.md +0 -87
- package/.agents/core/skills/node/skill.yaml +0 -17
- package/.agents/core/skills/performance/EXAMPLES.md +0 -30
- package/.agents/core/skills/performance/SKILL.md +0 -75
- package/.agents/core/skills/performance/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/performance/VALIDATION.json +0 -12
- package/.agents/core/skills/performance/performance.md +0 -52
- package/.agents/core/skills/performance/skill.yaml +0 -17
- package/.agents/core/skills/react/EXAMPLES.md +0 -79
- package/.agents/core/skills/react/SKILL.md +0 -132
- package/.agents/core/skills/react/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/react/VALIDATION.json +0 -12
- package/.agents/core/skills/react/react.md +0 -93
- package/.agents/core/skills/react/skill.yaml +0 -17
- package/.agents/core/skills/react-best-practices/SKILL.md +0 -155
- package/.agents/core/skills/react-best-practices/VALIDATION.json +0 -12
- package/.agents/core/skills/react-best-practices/skill.yaml +0 -14
- package/.agents/core/skills/redesign-audit/SKILL.md +0 -117
- package/.agents/core/skills/redesign-audit/VALIDATION.json +0 -12
- package/.agents/core/skills/redesign-audit/skill.yaml +0 -12
- package/.agents/core/skills/soft-design/SKILL.md +0 -108
- package/.agents/core/skills/soft-design/VALIDATION.json +0 -12
- package/.agents/core/skills/soft-design/skill.yaml +0 -12
- package/.agents/core/skills/state-management/EXAMPLES.md +0 -56
- package/.agents/core/skills/state-management/SKILL.md +0 -48
- package/.agents/core/skills/state-management/TROUBLESHOOTING.md +0 -18
- package/.agents/core/skills/state-management/VALIDATION.json +0 -11
- package/.agents/core/skills/state-management/skill.yaml +0 -28
- package/.agents/core/skills/subagent-orchestrator/SKILL.md +0 -117
- package/.agents/core/skills/subagent-orchestrator/VALIDATION.json +0 -12
- package/.agents/core/skills/subagent-orchestrator/skill.yaml +0 -12
- package/.agents/core/skills/system-design/EXAMPLES.md +0 -75
- package/.agents/core/skills/system-design/SKILL.md +0 -419
- package/.agents/core/skills/system-design/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/system-design/VALIDATION.json +0 -12
- package/.agents/core/skills/system-design/skill.yaml +0 -20
- package/.agents/core/skills/system-design/system-design.md +0 -112
- package/.agents/core/skills/testing/EXAMPLES.md +0 -71
- package/.agents/core/skills/testing/SKILL.md +0 -70
- package/.agents/core/skills/testing/TROUBLESHOOTING.md +0 -18
- package/.agents/core/skills/testing/VALIDATION.json +0 -11
- package/.agents/core/skills/testing/skill.yaml +0 -32
- package/.agents/core/skills/typescript/EXAMPLES.md +0 -64
- package/.agents/core/skills/typescript/SKILL.md +0 -112
- package/.agents/core/skills/typescript/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/typescript/VALIDATION.json +0 -12
- package/.agents/core/skills/typescript/skill.yaml +0 -17
- package/.agents/core/skills/typescript/typescript.md +0 -71
- package/.agents/core/skills/ui-design/EXAMPLES.md +0 -21
- package/.agents/core/skills/ui-design/SKILL.md +0 -124
- package/.agents/core/skills/ui-design/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/ui-design/VALIDATION.json +0 -12
- package/.agents/core/skills/ui-design/skill.yaml +0 -17
- package/.agents/core/skills/ui-design/ui.md +0 -88
- package/.agents/core/skills/ui-ux-pro/EXAMPLES.md +0 -62
- package/.agents/core/skills/ui-ux-pro/SKILL.md +0 -375
- package/.agents/core/skills/ui-ux-pro/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/ui-ux-pro/VALIDATION.json +0 -12
- package/.agents/core/skills/ui-ux-pro/skill.yaml +0 -19
- package/.agents/core/skills/ux-design/EXAMPLES.md +0 -36
- package/.agents/core/skills/ux-design/SKILL.md +0 -116
- package/.agents/core/skills/ux-design/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/ux-design/VALIDATION.json +0 -12
- package/.agents/core/skills/ux-design/skill.yaml +0 -17
- package/.agents/core/skills/ux-design/ux.md +0 -80
- package/.agents/core/skills/vercel-optimize/SKILL.md +0 -83
- package/.agents/core/skills/vercel-optimize/VALIDATION.json +0 -12
- package/.agents/core/skills/vercel-optimize/scripts/collect-signals.mjs +0 -131
- package/.agents/core/skills/vercel-optimize/scripts/gate-investigations.mjs +0 -142
- package/.agents/core/skills/vercel-optimize/scripts/merge-signals.mjs +0 -143
- package/.agents/core/skills/vercel-optimize/scripts/scan-codebase.mjs +0 -174
- package/.agents/core/skills/vercel-optimize/skill.yaml +0 -18
- package/.agents/core/skills/web-accessibility/EXAMPLES.md +0 -39
- package/.agents/core/skills/web-accessibility/SKILL.md +0 -170
- package/.agents/core/skills/web-accessibility/TROUBLESHOOTING.md +0 -19
- package/.agents/core/skills/web-accessibility/VALIDATION.json +0 -12
- package/.agents/core/skills/web-accessibility/accessibility.md +0 -63
- package/.agents/core/skills/web-accessibility/skill.yaml +0 -17
- package/.agents/generated/claude/skills/adapters/SKILL.md +0 -126
- package/.agents/generated/claude/skills/architecture-diagrams/SKILL.md +0 -101
- package/.agents/generated/claude/skills/brutalist-design/SKILL.md +0 -145
- package/.agents/generated/claude/skills/database/SKILL.md +0 -191
- package/.agents/generated/claude/skills/ddd/SKILL.md +0 -305
- package/.agents/generated/claude/skills/decisions/SKILL.md +0 -134
- package/.agents/generated/claude/skills/docker/SKILL.md +0 -135
- package/.agents/generated/claude/skills/fastapi/SKILL.md +0 -200
- package/.agents/generated/claude/skills/generators/SKILL.md +0 -133
- package/.agents/generated/claude/skills/graphify/SKILL.md +0 -198
- package/.agents/generated/claude/skills/impeccable-design/SKILL.md +0 -241
- package/.agents/generated/claude/skills/interview-me/SKILL.md +0 -90
- package/.agents/generated/claude/skills/microservices/SKILL.md +0 -218
- package/.agents/generated/claude/skills/minimalist-design/SKILL.md +0 -108
- package/.agents/generated/claude/skills/nestjs/SKILL.md +0 -195
- package/.agents/generated/claude/skills/nextjs/SKILL.md +0 -219
- package/.agents/generated/claude/skills/node/SKILL.md +0 -224
- package/.agents/generated/claude/skills/performance/SKILL.md +0 -121
- package/.agents/generated/claude/skills/react/SKILL.md +0 -227
- package/.agents/generated/claude/skills/react-best-practices/SKILL.md +0 -146
- package/.agents/generated/claude/skills/redesign-audit/SKILL.md +0 -112
- package/.agents/generated/claude/skills/soft-design/SKILL.md +0 -103
- package/.agents/generated/claude/skills/state-management/SKILL.md +0 -120
- package/.agents/generated/claude/skills/subagent-orchestrator/SKILL.md +0 -110
- package/.agents/generated/claude/skills/system-design/SKILL.md +0 -507
- package/.agents/generated/claude/skills/testing/SKILL.md +0 -157
- package/.agents/generated/claude/skills/typescript/SKILL.md +0 -192
- package/.agents/generated/claude/skills/ui-design/SKILL.md +0 -161
- package/.agents/generated/claude/skills/ui-ux-pro/SKILL.md +0 -451
- package/.agents/generated/claude/skills/ux-design/SKILL.md +0 -168
- package/.agents/generated/claude/skills/vercel-optimize/SKILL.md +0 -76
- package/.agents/generated/claude/skills/web-accessibility/SKILL.md +0 -225
- package/.agents/generated/gemini/skills/adapters/SKILL.md +0 -135
- package/.agents/generated/gemini/skills/architecture-diagrams/SKILL.md +0 -107
- package/.agents/generated/gemini/skills/brutalist-design/SKILL.md +0 -151
- package/.agents/generated/gemini/skills/database/SKILL.md +0 -200
- package/.agents/generated/gemini/skills/ddd/SKILL.md +0 -314
- package/.agents/generated/gemini/skills/decisions/SKILL.md +0 -143
- package/.agents/generated/gemini/skills/docker/SKILL.md +0 -144
- package/.agents/generated/gemini/skills/fastapi/SKILL.md +0 -209
- package/.agents/generated/gemini/skills/generators/SKILL.md +0 -142
- package/.agents/generated/gemini/skills/graphify/SKILL.md +0 -205
- package/.agents/generated/gemini/skills/impeccable-design/SKILL.md +0 -250
- package/.agents/generated/gemini/skills/interview-me/SKILL.md +0 -96
- package/.agents/generated/gemini/skills/microservices/SKILL.md +0 -227
- package/.agents/generated/gemini/skills/minimalist-design/SKILL.md +0 -114
- package/.agents/generated/gemini/skills/nestjs/SKILL.md +0 -204
- package/.agents/generated/gemini/skills/nextjs/SKILL.md +0 -298
- package/.agents/generated/gemini/skills/node/SKILL.md +0 -323
- package/.agents/generated/gemini/skills/performance/SKILL.md +0 -185
- package/.agents/generated/gemini/skills/react/SKILL.md +0 -332
- package/.agents/generated/gemini/skills/react-best-practices/SKILL.md +0 -152
- package/.agents/generated/gemini/skills/redesign-audit/SKILL.md +0 -118
- package/.agents/generated/gemini/skills/soft-design/SKILL.md +0 -109
- package/.agents/generated/gemini/skills/state-management/SKILL.md +0 -129
- package/.agents/generated/gemini/skills/subagent-orchestrator/SKILL.md +0 -116
- package/.agents/generated/gemini/skills/system-design/SKILL.md +0 -631
- package/.agents/generated/gemini/skills/testing/SKILL.md +0 -166
- package/.agents/generated/gemini/skills/typescript/SKILL.md +0 -275
- package/.agents/generated/gemini/skills/ui-design/SKILL.md +0 -170
- package/.agents/generated/gemini/skills/ui-ux-pro/SKILL.md +0 -460
- package/.agents/generated/gemini/skills/ux-design/SKILL.md +0 -177
- package/.agents/generated/gemini/skills/vercel-optimize/SKILL.md +0 -82
- 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
|
|
8
|
+
const { AGENTS_MD_PATH, collectSkillDirectories, extractYamlField, stripFrontmatter } = require('../shared.js');
|
|
9
|
+
const { registerAdapter, applyArtifacts, createProvenanceHeader } = require('../pure-compiler.js');
|
|
4
10
|
|
|
5
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
22
|
-
const skillMdPath
|
|
23
|
-
const yamlPath
|
|
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:
|
|
51
|
+
prompt: `# ContextOS — ${title}\n\n${descLine}\n${body}\n`,
|
|
50
52
|
};
|
|
51
53
|
}
|
|
52
54
|
|
|
53
|
-
function
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
64
|
-
|
|
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
|
|
68
|
+
const artifacts = [];
|
|
69
|
+
const rulesLines = [];
|
|
67
70
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
`# ContextOS — AI Rules for Zed Assistant\n
|
|
71
|
-
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
149
|
+
const adapter = {
|
|
150
|
+
describe,
|
|
151
|
+
render,
|
|
152
|
+
validate,
|
|
153
|
+
run,
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
registerAdapter('zed', adapter);
|
|
157
|
+
|
|
158
|
+
module.exports = adapter;
|