contextos-agents 2.0.0 → 2.1.1

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 (223) hide show
  1. package/.agents/AGENTS.md +53 -33
  2. package/.agents/adapters/aider/export.js +41 -14
  3. package/.agents/adapters/claude/export.js +54 -3
  4. package/.agents/adapters/copilot/export.js +1 -1
  5. package/.agents/adapters/cursor/export.js +1 -1
  6. package/.agents/adapters/drift-detector.js +86 -10
  7. package/.agents/adapters/gemini/export.js +1 -1
  8. package/.agents/adapters/pure-compiler.js +28 -6
  9. package/.agents/adapters/shared.js +13 -4
  10. package/.agents/adapters/zed/export.js +1 -1
  11. package/.agents/compiled/registry.v2.json +29 -25
  12. package/.agents/compiled/registry.v2.sha256 +1 -1
  13. package/.agents/core/skills/context-os/SKILL.md +34 -37
  14. package/.agents/core/skills/engineering-workflow/SKILL.md +24 -24
  15. package/.agents/core/skills/gemini-precision/EXAMPLES.md +72 -0
  16. package/.agents/core/skills/gemini-precision/SKILL.md +2 -1
  17. package/.agents/core/skills/gemini-precision/TROUBLESHOOTING.md +25 -0
  18. package/.agents/core/skills/gemini-precision/skill.yaml +2 -0
  19. package/.agents/core/skills/gstack-roles/SKILL.md +7 -6
  20. package/.agents/core/skills/security/SKILL.md +44 -16
  21. package/.agents/core/skills/security/skill.yaml +0 -1
  22. package/.agents/ctx.js +20 -14
  23. package/.agents/generated/claude/skills/context-os/SKILL.md +34 -37
  24. package/.agents/generated/claude/skills/engineering-workflow/SKILL.md +24 -24
  25. package/.agents/generated/claude/skills/gemini-precision/SKILL.md +102 -1
  26. package/.agents/generated/claude/skills/gstack-roles/SKILL.md +7 -6
  27. package/.agents/generated/claude/skills/security/SKILL.md +44 -16
  28. package/.agents/generated/gemini/skills/context-os/SKILL.md +34 -37
  29. package/.agents/generated/gemini/skills/engineering-workflow/SKILL.md +24 -24
  30. package/.agents/generated/gemini/skills/gemini-precision/SKILL.md +105 -1
  31. package/.agents/generated/gemini/skills/gstack-roles/SKILL.md +7 -6
  32. package/.agents/generated/gemini/skills/security/SKILL.md +44 -125
  33. package/.agents/plugins.js +105 -8
  34. package/.agents/profiles.js +32 -11
  35. package/.agents/resolver/canonical-resolver.js +7 -7
  36. package/.agents/validate.js +69 -1
  37. package/README.md +81 -24
  38. package/bin/commands/hook.js +167 -0
  39. package/bin/commands/scan.js +77 -0
  40. package/bin/commands.js +39 -1
  41. package/bin/index.js +151 -34
  42. package/bin/lib/gate.js +171 -0
  43. package/bin/lib/git-snapshot.js +214 -0
  44. package/bin/lib/scan.js +461 -0
  45. package/catalog/skills/adapters/EXAMPLES.md +19 -0
  46. package/catalog/skills/adapters/SKILL.md +101 -0
  47. package/catalog/skills/adapters/TROUBLESHOOTING.md +7 -0
  48. package/catalog/skills/adapters/VALIDATION.json +12 -0
  49. package/catalog/skills/adapters/skill.yaml +13 -0
  50. package/catalog/skills/api-design/EXAMPLES.md +91 -0
  51. package/catalog/skills/api-design/SKILL.md +63 -0
  52. package/catalog/skills/api-design/TROUBLESHOOTING.md +54 -0
  53. package/catalog/skills/api-design/VALIDATION.json +11 -0
  54. package/catalog/skills/api-design/skill.yaml +14 -0
  55. package/catalog/skills/architecture-diagrams/SKILL.md +108 -0
  56. package/catalog/skills/architecture-diagrams/VALIDATION.json +12 -0
  57. package/catalog/skills/architecture-diagrams/skill.yaml +9 -0
  58. package/catalog/skills/brutalist-design/EXAMPLES.md +59 -0
  59. package/catalog/skills/brutalist-design/SKILL.md +150 -0
  60. package/catalog/skills/brutalist-design/VALIDATION.json +12 -0
  61. package/catalog/skills/brutalist-design/skill.yaml +10 -0
  62. package/catalog/skills/ci-cd/EXAMPLES.md +79 -0
  63. package/catalog/skills/ci-cd/SKILL.md +69 -0
  64. package/catalog/skills/ci-cd/TROUBLESHOOTING.md +52 -0
  65. package/catalog/skills/ci-cd/VALIDATION.json +11 -0
  66. package/catalog/skills/ci-cd/skill.yaml +13 -0
  67. package/catalog/skills/database/EXAMPLES.md +74 -0
  68. package/catalog/skills/database/SKILL.md +101 -0
  69. package/catalog/skills/database/TROUBLESHOOTING.md +18 -0
  70. package/catalog/skills/database/VALIDATION.json +11 -0
  71. package/catalog/skills/database/skill.yaml +14 -0
  72. package/catalog/skills/ddd/EXAMPLES.md +42 -0
  73. package/catalog/skills/ddd/SKILL.md +247 -0
  74. package/catalog/skills/ddd/TROUBLESHOOTING.md +19 -0
  75. package/catalog/skills/ddd/VALIDATION.json +12 -0
  76. package/catalog/skills/ddd/skill.yaml +14 -0
  77. package/catalog/skills/decisions/EXAMPLES.md +35 -0
  78. package/catalog/skills/decisions/SKILL.md +90 -0
  79. package/catalog/skills/decisions/TROUBLESHOOTING.md +13 -0
  80. package/catalog/skills/decisions/VALIDATION.json +12 -0
  81. package/catalog/skills/decisions/skill.yaml +13 -0
  82. package/catalog/skills/docker/EXAMPLES.md +56 -0
  83. package/catalog/skills/docker/SKILL.md +169 -0
  84. package/catalog/skills/docker/TROUBLESHOOTING.md +18 -0
  85. package/catalog/skills/docker/VALIDATION.json +11 -0
  86. package/catalog/skills/docker/skill.yaml +13 -0
  87. package/catalog/skills/fastapi/EXAMPLES.md +36 -0
  88. package/catalog/skills/fastapi/SKILL.md +171 -0
  89. package/catalog/skills/fastapi/TROUBLESHOOTING.md +19 -0
  90. package/catalog/skills/fastapi/VALIDATION.json +12 -0
  91. package/catalog/skills/fastapi/skill.yaml +14 -0
  92. package/catalog/skills/generators/EXAMPLES.md +19 -0
  93. package/catalog/skills/generators/SKILL.md +110 -0
  94. package/catalog/skills/generators/TROUBLESHOOTING.md +7 -0
  95. package/catalog/skills/generators/VALIDATION.json +12 -0
  96. package/catalog/skills/generators/skill.yaml +22 -0
  97. package/catalog/skills/generators/templates/API.md +77 -0
  98. package/catalog/skills/generators/templates/ARCHITECTURE.md +70 -0
  99. package/catalog/skills/generators/templates/DATABASE.md +42 -0
  100. package/catalog/skills/generators/templates/DECISION.md +46 -0
  101. package/catalog/skills/generators/templates/PRD.md +67 -0
  102. package/catalog/skills/generators/templates/PROJECT_GRAPH.md +56 -0
  103. package/catalog/skills/generators/templates/ROADMAP.md +51 -0
  104. package/catalog/skills/generators/templates/TASKS.md +43 -0
  105. package/catalog/skills/generators/templates/UI.md +73 -0
  106. package/catalog/skills/graphify/EXAMPLES.md +73 -0
  107. package/catalog/skills/graphify/SKILL.md +130 -0
  108. package/catalog/skills/graphify/VALIDATION.json +12 -0
  109. package/catalog/skills/graphify/skill.yaml +13 -0
  110. package/catalog/skills/impeccable-design/EXAMPLES.md +26 -0
  111. package/catalog/skills/impeccable-design/SKILL.md +201 -0
  112. package/catalog/skills/impeccable-design/TROUBLESHOOTING.md +19 -0
  113. package/catalog/skills/impeccable-design/VALIDATION.json +12 -0
  114. package/catalog/skills/impeccable-design/skill.yaml +15 -0
  115. package/catalog/skills/interview-me/SKILL.md +97 -0
  116. package/catalog/skills/interview-me/VALIDATION.json +12 -0
  117. package/catalog/skills/interview-me/skill.yaml +9 -0
  118. package/catalog/skills/microservices/EXAMPLES.md +38 -0
  119. package/catalog/skills/microservices/SKILL.md +164 -0
  120. package/catalog/skills/microservices/TROUBLESHOOTING.md +19 -0
  121. package/catalog/skills/microservices/VALIDATION.json +12 -0
  122. package/catalog/skills/microservices/skill.yaml +14 -0
  123. package/catalog/skills/minimalist-design/EXAMPLES.md +58 -0
  124. package/catalog/skills/minimalist-design/SKILL.md +113 -0
  125. package/catalog/skills/minimalist-design/VALIDATION.json +12 -0
  126. package/catalog/skills/minimalist-design/skill.yaml +10 -0
  127. package/catalog/skills/nestjs/EXAMPLES.md +40 -0
  128. package/catalog/skills/nestjs/SKILL.md +139 -0
  129. package/catalog/skills/nestjs/TROUBLESHOOTING.md +19 -0
  130. package/catalog/skills/nestjs/VALIDATION.json +12 -0
  131. package/catalog/skills/nestjs/skill.yaml +14 -0
  132. package/catalog/skills/nextjs/EXAMPLES.md +40 -0
  133. package/catalog/skills/nextjs/SKILL.md +163 -0
  134. package/catalog/skills/nextjs/TROUBLESHOOTING.md +19 -0
  135. package/catalog/skills/nextjs/VALIDATION.json +12 -0
  136. package/catalog/skills/nextjs/skill.yaml +14 -0
  137. package/catalog/skills/node/EXAMPLES.md +80 -0
  138. package/catalog/skills/node/SKILL.md +128 -0
  139. package/catalog/skills/node/TROUBLESHOOTING.md +19 -0
  140. package/catalog/skills/node/VALIDATION.json +12 -0
  141. package/catalog/skills/node/skill.yaml +14 -0
  142. package/catalog/skills/performance/EXAMPLES.md +30 -0
  143. package/catalog/skills/performance/SKILL.md +75 -0
  144. package/catalog/skills/performance/TROUBLESHOOTING.md +19 -0
  145. package/catalog/skills/performance/VALIDATION.json +12 -0
  146. package/catalog/skills/performance/skill.yaml +14 -0
  147. package/catalog/skills/react/EXAMPLES.md +79 -0
  148. package/catalog/skills/react/SKILL.md +132 -0
  149. package/catalog/skills/react/TROUBLESHOOTING.md +19 -0
  150. package/catalog/skills/react/VALIDATION.json +12 -0
  151. package/catalog/skills/react/skill.yaml +14 -0
  152. package/catalog/skills/react-best-practices/SKILL.md +158 -0
  153. package/catalog/skills/react-best-practices/VALIDATION.json +12 -0
  154. package/catalog/skills/react-best-practices/skill.yaml +13 -0
  155. package/catalog/skills/redesign-audit/SKILL.md +117 -0
  156. package/catalog/skills/redesign-audit/VALIDATION.json +12 -0
  157. package/catalog/skills/redesign-audit/skill.yaml +9 -0
  158. package/catalog/skills/security-audit/EXAMPLES.md +79 -0
  159. package/catalog/skills/security-audit/SKILL.md +91 -0
  160. package/catalog/skills/security-audit/TROUBLESHOOTING.md +46 -0
  161. package/catalog/skills/security-audit/VALIDATION.json +11 -0
  162. package/catalog/skills/security-audit/skill.yaml +14 -0
  163. package/catalog/skills/soft-design/EXAMPLES.md +51 -0
  164. package/catalog/skills/soft-design/SKILL.md +108 -0
  165. package/catalog/skills/soft-design/VALIDATION.json +12 -0
  166. package/catalog/skills/soft-design/skill.yaml +10 -0
  167. package/catalog/skills/state-management/EXAMPLES.md +56 -0
  168. package/catalog/skills/state-management/SKILL.md +168 -0
  169. package/catalog/skills/state-management/TROUBLESHOOTING.md +18 -0
  170. package/catalog/skills/state-management/VALIDATION.json +11 -0
  171. package/catalog/skills/state-management/skill.yaml +14 -0
  172. package/catalog/skills/subagent-orchestrator/SKILL.md +117 -0
  173. package/catalog/skills/subagent-orchestrator/VALIDATION.json +12 -0
  174. package/catalog/skills/subagent-orchestrator/skill.yaml +9 -0
  175. package/catalog/skills/system-design/EXAMPLES.md +75 -0
  176. package/catalog/skills/system-design/SKILL.md +419 -0
  177. package/catalog/skills/system-design/TROUBLESHOOTING.md +19 -0
  178. package/catalog/skills/system-design/VALIDATION.json +12 -0
  179. package/catalog/skills/system-design/skill.yaml +14 -0
  180. package/catalog/skills/terraform/EXAMPLES.md +74 -0
  181. package/catalog/skills/terraform/SKILL.md +55 -0
  182. package/catalog/skills/terraform/TROUBLESHOOTING.md +53 -0
  183. package/catalog/skills/terraform/VALIDATION.json +11 -0
  184. package/catalog/skills/terraform/skill.yaml +14 -0
  185. package/catalog/skills/testing/EXAMPLES.md +122 -0
  186. package/catalog/skills/testing/SKILL.md +70 -0
  187. package/catalog/skills/testing/TROUBLESHOOTING.md +18 -0
  188. package/catalog/skills/testing/VALIDATION.json +11 -0
  189. package/catalog/skills/testing/skill.yaml +14 -0
  190. package/catalog/skills/typescript/EXAMPLES.md +64 -0
  191. package/catalog/skills/typescript/SKILL.md +112 -0
  192. package/catalog/skills/typescript/TROUBLESHOOTING.md +19 -0
  193. package/catalog/skills/typescript/VALIDATION.json +12 -0
  194. package/catalog/skills/typescript/skill.yaml +14 -0
  195. package/catalog/skills/ui-design/EXAMPLES.md +21 -0
  196. package/catalog/skills/ui-design/SKILL.md +124 -0
  197. package/catalog/skills/ui-design/TROUBLESHOOTING.md +19 -0
  198. package/catalog/skills/ui-design/VALIDATION.json +12 -0
  199. package/catalog/skills/ui-design/skill.yaml +16 -0
  200. package/catalog/skills/ui-ux-pro/EXAMPLES.md +62 -0
  201. package/catalog/skills/ui-ux-pro/SKILL.md +418 -0
  202. package/catalog/skills/ui-ux-pro/TROUBLESHOOTING.md +19 -0
  203. package/catalog/skills/ui-ux-pro/VALIDATION.json +12 -0
  204. package/catalog/skills/ui-ux-pro/skill.yaml +14 -0
  205. package/catalog/skills/ux-design/EXAMPLES.md +36 -0
  206. package/catalog/skills/ux-design/SKILL.md +116 -0
  207. package/catalog/skills/ux-design/TROUBLESHOOTING.md +19 -0
  208. package/catalog/skills/ux-design/VALIDATION.json +12 -0
  209. package/catalog/skills/ux-design/skill.yaml +16 -0
  210. package/catalog/skills/vercel-optimize/SKILL.md +83 -0
  211. package/catalog/skills/vercel-optimize/VALIDATION.json +12 -0
  212. package/catalog/skills/vercel-optimize/scripts/collect-signals.mjs +131 -0
  213. package/catalog/skills/vercel-optimize/scripts/gate-investigations.mjs +142 -0
  214. package/catalog/skills/vercel-optimize/scripts/merge-signals.mjs +143 -0
  215. package/catalog/skills/vercel-optimize/scripts/scan-codebase.mjs +174 -0
  216. package/catalog/skills/vercel-optimize/skill.yaml +15 -0
  217. package/catalog/skills/web-accessibility/EXAMPLES.md +39 -0
  218. package/catalog/skills/web-accessibility/SKILL.md +151 -0
  219. package/catalog/skills/web-accessibility/TROUBLESHOOTING.md +19 -0
  220. package/catalog/skills/web-accessibility/VALIDATION.json +12 -0
  221. package/catalog/skills/web-accessibility/skill.yaml +14 -0
  222. package/package.json +5 -2
  223. package/.agents/core/skills/security/security.md +0 -106
@@ -32,7 +32,7 @@ Activate whenever writing authentication, authorization, session management, dat
32
32
 
33
33
  #### 1. Injection (SQL, NoSQL, Command)
34
34
 
35
- - Always use parameterized queries — never concatenate user input into SQL or shell commands.
35
+ - Always use parameterized queries - never concatenate user input into SQL or shell commands.
36
36
  - Use ORMs (Prisma, Drizzle, SQLAlchemy) with strict schema validation.
37
37
  - Validate and sanitize all user input before processing.
38
38
 
@@ -81,14 +81,20 @@ When building AI workflows, tools, or MCP servers:
81
81
  - Never allow untrusted content to override system instructions or tool execution permissions.
82
82
  2. **Tool Execution Boundaries**:
83
83
  - Destructive operations (database drops, file deletions, payment triggers) MUST require explicit user confirmation.
84
- - Restrict file system tools to the workspace root — block directory traversal (`../`).
84
+ - Restrict file system tools to the workspace root - block directory traversal (`../`).
85
85
  3. **Secret Masking & Output Sanitization**:
86
86
  - Scrub API keys (`sk-...`, `Bearer ...`), tokens, and credentials before writing to agent logs or step summaries.
87
+ 4. **Sandbox Execution & Write Isolation (Supply-Chain Defense)**:
88
+ - Target code is inspected strictly read-only; never execute target-controlled builds or tests with write access to the repository root.
89
+ - Restrict process write boundaries strictly to an isolated temporary `scratch/` directory.
90
+ - Enforce zero outbound external network access during security audits to prevent secret exfiltration via malicious scripts or dependencies.
91
+ - Promote verified non-secret results to retained `artifacts/` only via trusted parent-side inspection code.
87
92
 
88
93
  ---
89
94
 
90
95
  ## Code Examples
91
96
 
97
+
92
98
  ### Timing-Safe Secret Verification
93
99
 
94
100
  ```javascript
@@ -104,28 +110,50 @@ export function verifyWebhookSignature(payload, signature, secret) {
104
110
  }
105
111
  ```
106
112
 
107
- ### Safe SSRF Prevention Wrapper
113
+ ### SSRF Prevention Requirements (OWASP Compliant)
108
114
 
109
- ```typescript
110
- import dns from 'node:dns/promises';
115
+ Per [OWASP SSRF Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html), naive application-level DNS pre-checks followed by standard `fetch(url)` are fundamentally flawed due to DNS rebinding (TOCTOU) and unvalidated HTTP 3xx redirects.
116
+
117
+ #### Mandatory Architectural Controls
111
118
 
112
- export async function validateSafeUrl(urlString: string): Promise<URL> {
119
+ 1. **Network-Layer Defense (Primary)**: For user-supplied arbitrary webhooks or URLs, route all outbound traffic through an isolated egress forward proxy (e.g., Smokescreen, Envoy, Squid) configured with firewall-level IP filters blocking RFC 1918, RFC 6598, link-local (`169.254.169.254`), loopback, and IPv6 local addresses at the socket handshake level.
120
+ 2. **Positive Destination Allowlist**: If fetching from known external partners, validate destination hostname against a strict positive allowlist.
121
+ 3. **Disable Automatic Redirects**: Always set `redirect: 'error'` or `'manual'`. Never follow HTTP redirects automatically without re-validating the target URL against allowlist rules.
122
+ 4. **Protocol & Credential Restrictions**: Enforce `https:` exclusively; reject embedded credentials (`user:pass@host`) and non-standard ports.
123
+
124
+ ```typescript
125
+ /**
126
+ * Verified Allowlist-based HTTP Client (OWASP SSRF Prevention)
127
+ * Enforces HTTPS, strict destination allowlist, and rejects HTTP redirects.
128
+ */
129
+ export async function fetchFromAllowlist(
130
+ urlString: string,
131
+ allowedHostnames: ReadonlySet<string>,
132
+ options: RequestInit = {}
133
+ ): Promise<Response> {
113
134
  const parsed = new URL(urlString);
135
+
136
+ // 1. Enforce HTTPS only
114
137
  if (parsed.protocol !== 'https:') {
115
- throw new Error('Only HTTPS protocol is permitted');
138
+ throw new Error(`SSRF blocked: protocol "${parsed.protocol}" is not permitted; HTTPS required`);
139
+ }
140
+
141
+ // 2. Reject credentials in URL
142
+ if (parsed.username || parsed.password) {
143
+ throw new Error('SSRF blocked: URL credentials (user:password@host) are prohibited');
116
144
  }
117
145
 
118
- const { address } = await dns.lookup(parsed.hostname);
119
- if (
120
- address.startsWith('127.') ||
121
- address.startsWith('10.') ||
122
- address.startsWith('192.168.') ||
123
- address === '169.254.169.254'
124
- ) {
125
- throw new Error('Access to private/metadata IP addresses is blocked');
146
+ // 3. Strict positive destination allowlist (prevents internal network probing)
147
+ const normalizedHost = parsed.hostname.toLowerCase();
148
+ if (!allowedHostnames.has(normalizedHost)) {
149
+ throw new Error(`SSRF blocked: destination host "${normalizedHost}" is not in the approved allowlist`);
126
150
  }
127
151
 
128
- return parsed;
152
+ // 4. Disable automatic redirects to prevent redirection to private IPs or metadata endpoints
153
+ return fetch(urlString, {
154
+ ...options,
155
+ redirect: 'error'
156
+ });
129
157
  }
130
158
  ```
131
159
 
@@ -12,7 +12,6 @@ resources:
12
12
  - SKILL.md
13
13
  - TROUBLESHOOTING.md
14
14
  - VALIDATION.json
15
- - security.md
16
15
  rules:
17
16
  - id: SEC-001
18
17
  level: must
package/.agents/ctx.js CHANGED
@@ -97,25 +97,31 @@ if (command === 'export') {
97
97
  const pureCompiler = require('./adapters/pure-compiler.js');
98
98
  const driftDetector = require('./adapters/drift-detector.js');
99
99
 
100
+ const isCheck = args.includes('--check');
101
+ const isDiff = args.includes('--diff');
102
+ const isDryRun = args.includes('--dry-run');
103
+ const asJson = args.includes('--json');
104
+
100
105
  const profileFlagIdx = args.indexOf('--profile');
101
106
  let overrideProfile = null;
102
107
  if (profileFlagIdx !== -1 && args[profileFlagIdx + 1]) {
103
108
  const profiles = require('./profiles.js');
104
109
  overrideProfile = args[profileFlagIdx + 1];
105
110
  try {
106
- profiles.applyProfile(overrideProfile);
107
- console.log(`[PROFILE] Applied profile '${overrideProfile}' for this export.\n`);
111
+ const prof = profiles.getProfile(overrideProfile, process.cwd());
112
+ if (!prof) {
113
+ throw new Error(`Profile '${overrideProfile}' not found`);
114
+ }
115
+ if (!isCheck && !isDryRun && !isDiff) {
116
+ profiles.applyProfile(overrideProfile);
117
+ console.log(`[PROFILE] Applied profile '${overrideProfile}' for this export.\n`);
118
+ }
108
119
  } catch (err) {
109
120
  console.error(`[ERROR] ${err.message}`);
110
- process.exit(1);
121
+ process.exit(2);
111
122
  }
112
123
  }
113
124
 
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
125
  const rawTarget = args[1] && !args[1].startsWith('--') ? args[1] : 'all';
120
126
 
121
127
  // 1. Drift Check Mode (--check)
@@ -125,7 +131,7 @@ if (command === 'export') {
125
131
  console.log(JSON.stringify(drift, null, 2));
126
132
  } else {
127
133
  console.log('\nContextOS — Adapter Output Drift Check\n');
128
- if (!drift.hasDrift) {
134
+ if (!drift.hasDrift && !drift.hasError) {
129
135
  console.log(`✓ No adapter drift detected. All ${drift.projectedCount} output artifacts are synchronized.`);
130
136
  } else {
131
137
  console.log(`! Drift detected (${drift.totalFindings} finding(s)):\n`);
@@ -146,7 +152,7 @@ if (command === 'export') {
146
152
  console.log('\nRun: node .agents/ctx.js export all to synchronize outputs with source skills.\n');
147
153
  }
148
154
  }
149
- process.exit(drift.hasDrift ? 1 : 0);
155
+ process.exit(drift.code !== undefined ? drift.code : (drift.hasDrift ? 1 : 0));
150
156
  }
151
157
 
152
158
  // 2. Diff Preview Mode (--diff)
@@ -247,8 +253,8 @@ if (command === 'export') {
247
253
  : (args.find(a => a.startsWith('--scope=')) || '').split('=')[1] || null;
248
254
 
249
255
  if (subcommand === 'list') {
250
- const list = profiles.listProfiles();
251
- const active = profiles.getActiveProfile();
256
+ const list = profiles.listProfiles(process.cwd());
257
+ const active = profiles.getActiveProfile(process.cwd());
252
258
  if (asJson) {
253
259
  console.log(JSON.stringify({ active, profiles: list }, null, 2));
254
260
  } else {
@@ -279,7 +285,7 @@ if (command === 'export') {
279
285
  console.error('[ERROR] Usage: node ctx.js profile show <name> [--json]');
280
286
  process.exit(1);
281
287
  }
282
- const profile = profiles.getProfile(name);
288
+ const profile = profiles.getProfile(name, process.cwd());
283
289
  if (!profile) {
284
290
  console.error(`[ERROR] Profile '${name}' not found.`);
285
291
  process.exit(1);
@@ -300,7 +306,7 @@ if (command === 'export') {
300
306
  process.exit(1);
301
307
  }
302
308
  try {
303
- const explanation = profiles.explainProfile(name);
309
+ const explanation = profiles.explainProfile(name, process.cwd());
304
310
  if (asJson) {
305
311
  console.log(JSON.stringify(explanation, null, 2));
306
312
  } else {
@@ -2,11 +2,11 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- Deterministic context compiler and policy engine for AI coding agents. Standardizes software engineering workflows across requirements, architecture, atomic task planning, implementation, verification, and release.
5
+ Deterministic context compiler and policy engine for AI coding agents. Governs repository policy configuration, skill dependency graphs, profile management, and multi-agent configuration export.
6
6
 
7
7
  ## When to Use
8
8
 
9
- Activate as the root meta-orchestrator across all development phases to ensure role consistency, quality gates, and structured execution.
9
+ Activate when managing project configuration, resolving skill dependencies, compiling rules for editors, or defining repository-level agent standards. (For task-specific file and context budgeting, use `context-manager`).
10
10
 
11
11
  ## Rules & Patterns
12
12
 
@@ -40,10 +40,10 @@ intent:
40
40
  For each required layer, load the skill graph:
41
41
 
42
42
  1. Read `skill.yaml` from each relevant skill directory
43
- 2. Resolve `requires` — load mandatory dependencies
44
- 3. Check `conflicts` — ensure no incompatible skills are loaded
45
- 4. Apply `optional` — suggest but don't force
46
- 5. Respect project profile (if set) — apply rules from `profiles/`
43
+ 2. Resolve `requires` - load mandatory dependencies
44
+ 3. Check `conflicts` - ensure no incompatible skills are loaded
45
+ 4. Apply `optional` - suggest but don't force
46
+ 5. Respect project profile (if set) - apply rules from `profiles/`
47
47
 
48
48
  **Dependency resolution example:**
49
49
 
@@ -61,48 +61,45 @@ Suggested: [tailwind, prisma, next-auth]
61
61
 
62
62
  Assemble context from three levels:
63
63
 
64
- **Level 1 — Vision (always available):**
64
+ **Level 1 - Vision (always available):**
65
65
 
66
- - `docs/PRD.md` — what are we building
67
- - `docs/ROADMAP.md` — where are we going
68
- - `docs/PROJECT_GRAPH.md` — project structure
66
+ - `docs/PRD.md` - what are we building
67
+ - `docs/ROADMAP.md` - where are we going
68
+ - `docs/PROJECT_GRAPH.md` - project structure
69
+ - `docs/API.md` - API specification (optional, when backend API layer is present)
70
+ - `docs/UI.md` - UI/UX specification (optional, when UI layer is present)
69
71
 
70
- **Level 2 — Architecture (load when needed):**
72
+ **Level 2 - Architecture (load when needed):**
71
73
 
72
- - `docs/ARCHITECTURE.md` — system design
73
- - `docs/DATABASE.md` — data model
74
- - `docs/API.md` — API contracts
75
- - `docs/decisions/` — prior decisions
74
+ - `docs/ARCHITECTURE.md` - system design and boundaries
75
+ - `docs/decisions/` - architecture decision records (ADRs)
76
+ - `docs/PRODUCT_BOUNDARIES.md` - maturity boundaries and non-promises
77
+ - `references/context-rules.md` - dynamic context selection and compilation rules
76
78
 
77
- **Level 3 — Development (load per task):**
79
+ **Level 3 - Task-Specific Context (load per task):**
78
80
 
79
- - Relevant skill `.md` files
80
- - `docs/UI.md` — for frontend tasks
81
- - `docs/TASKS.md` — current sprint
81
+ - Relevant skill documents from `.agents/skills/`
82
+ - Target code and test files within planned blast radius
82
83
 
83
- **Context Filtering Rules:**
84
- See `references/context-rules.md` for the full mapping of task types to required documents.
84
+ ### Stage 4: Focused Context Selection
85
85
 
86
- ### Stage 4: Prompt Optimization
86
+ Before sending context to the AI coding assistant:
87
87
 
88
- Before sending to the AI agent:
88
+ 1. Select only skills relevant to the task domain and touched files
89
+ 2. Prioritize: task goal > architectural constraints > project conventions
90
+ 3. Include active Decision Records that affect the target component
91
+ 4. Enforce quality guardrails and verification criteria
89
92
 
90
- 1. Remove sections not relevant to the current task
91
- 2. Prioritize: current task context > architecture > vision
92
- 3. Include recent Decision Records that affect the current task
93
- 4. Add coding rules from the loaded skills
94
-
95
- ## Commands
93
+ ## Core CLI Commands
96
94
 
97
95
  | Command | Action |
98
96
  | --- | --- |
99
- | `ctx init` | Analyze project idea, generate all docs |
100
- | `ctx plan` | Generate development plan from PRD |
101
- | `ctx compile` | Compile context for a specific task |
102
- | `ctx update` | Update changed documents |
103
- | `ctx graph` | Show/update Project Graph |
104
- | `ctx doctor` | Validate skill dependencies, check for conflicts |
105
- | `ctx explain` | Explain why specific context was loaded |
97
+ | `contextos init` | Initialize `.agents/` folder and bootstrap profiles |
98
+ | `contextos export <agent>` | Compile skills for target agent (`gemini`, `claude`, `cursor`, `copilot`, `aider`, `zed`, `all`) |
99
+ | `contextos resolve "<task>"` | Dynamically resolve relevant skills, rules, and risk level for task |
100
+ | `contextos validate` | Validate skill schemas, dependencies, and detect configuration drift |
101
+ | `contextos doctor` | Pre-flight diagnostics for skills, profiles, and compiler synchronization |
102
+ | `contextos watch` | Background file watcher for continuous auto-compilation |
106
103
 
107
104
  ## Project Initialization Flow
108
105
 
@@ -120,7 +117,7 @@ When user says something like "Сделай CRM для стоматологии"
120
117
  3. **Select profile** (startup/enterprise/mvp/hackathon)
121
118
  4. **Resolve skills** (Stage 2)
122
119
  5. **Generate all documents** using `generators/` skill
123
- 6. **Create Project Graph** — the master map of modules → features → tasks → files → skills
120
+ 6. **Create Project Graph** - the master map of modules -> features -> tasks -> files -> skills
124
121
  7. **Output agent config** using `adapters/` skill
125
122
 
126
123
  ## Skill Discovery
@@ -37,7 +37,7 @@ Inspired by [addyosmani/agent-skills](https://github.com/addyosmani/agent-skills
37
37
 
38
38
  ---
39
39
 
40
- ### Phase 1: DEFINE — /spec
40
+ ### Phase 1: DEFINE - /spec
41
41
 
42
42
  **Auto-activates → `[ROLE: Product Manager]`**
43
43
 
@@ -71,8 +71,8 @@ Before writing the spec, if there is ambiguity, high blast radius, or multiple a
71
71
  ### Technical Approach
72
72
  [Read the relevant code. Understand what changes where.]
73
73
  Files affected:
74
- - `src/X.js` — [what changes]
75
- - `src/Y.js` — [what changes]
74
+ - `src/X.js` - [what changes]
75
+ - `src/Y.js` - [what changes]
76
76
 
77
77
  ### Acceptance Criteria
78
78
  - [ ] Given [context], when [action], then [result]
@@ -85,7 +85,7 @@ Files affected:
85
85
 
86
86
  ---
87
87
 
88
- ### Phase 2: PLAN — /plan
88
+ ### Phase 2: PLAN - /plan
89
89
 
90
90
  **Auto-activates → `[ROLE: Architect]`**
91
91
 
@@ -103,7 +103,7 @@ Organize tasks as **Thin Vertical Slices** rather than horizontal layers:
103
103
  - Each task must be **completable in < 2 hours** of focused work.
104
104
  - Each task must be **independently testable**.
105
105
  - Tasks must be **ordered by dependency** (blocking tasks first).
106
- - Each task gets a **test requirement** — no task without a test.
106
+ - Each task gets a **test requirement** - no task without a test.
107
107
 
108
108
  #### Plan Template
109
109
 
@@ -128,13 +128,13 @@ Organize tasks as **Thin Vertical Slices** rather than horizontal layers:
128
128
  - [Risk 1]: [Mitigation]
129
129
  - [Risk 2]: [Mitigation]
130
130
 
131
- ### STOP — Awaiting Approval
131
+ ### STOP - Awaiting Approval
132
132
  Do not proceed to BUILD until this plan is approved.
133
133
  ```
134
134
 
135
135
  ---
136
136
 
137
- ### Phase 3: BUILD — /build
137
+ ### Phase 3: BUILD - /build
138
138
 
139
139
  **Auto-activates → `[ROLE: Senior Developer]`**
140
140
 
@@ -142,12 +142,12 @@ Implement one task at a time. Commit after each task.
142
142
 
143
143
  #### Build Rules
144
144
 
145
- 1. **One task per commit** — atomic, descriptive commit messages.
146
- 2. **Write the test FIRST** (TDD — red-green-refactor).
147
- 3. **No dead code** — if it's not tested, it's not shipped.
148
- 4. **No TODOs in committed code** — resolve or create a tracked issue.
149
- 5. **Read before writing** — understand the surrounding code before changing it.
150
- 6. **Limit the blast radius** — modify ONLY the files explicitly listed in the current task's plan. Do NOT rewrite adjacent components, hooks, or utilities unless strictly required AND approved.
145
+ 1. **One task per commit** - atomic, descriptive commit messages.
146
+ 2. **Write the test FIRST** (TDD - red-green-refactor).
147
+ 3. **No dead code** - if it's not tested, it's not shipped.
148
+ 4. **No TODOs in committed code** - resolve or create a tracked issue.
149
+ 5. **Read before writing** - understand the surrounding code before changing it.
150
+ 6. **Limit the blast radius** - modify ONLY the files explicitly listed in the current task's plan. Do NOT rewrite adjacent components, hooks, or utilities unless strictly required AND approved.
151
151
 
152
152
  #### Commit Message Format
153
153
 
@@ -164,7 +164,7 @@ Types: `feat`, `fix`, `refactor`, `test`, `docs`, `chore`
164
164
 
165
165
  ---
166
166
 
167
- ### Phase 4: VERIFY — /test
167
+ ### Phase 4: VERIFY - /test
168
168
 
169
169
  **Auto-activates → `[ROLE: QA Lead]`**
170
170
 
@@ -185,7 +185,7 @@ Tests are proof, not an afterthought.
185
185
 
186
186
  For complex React components, prioritize testing _user behavior_ over internal state:
187
187
 
188
- - Use **React Testing Library** (`userEvent`, `screen.getByRole`) — test what the user sees.
188
+ - Use **React Testing Library** (`userEvent`, `screen.getByRole`) - test what the user sees.
189
189
  - Use **Playwright** for critical user flows (login, checkout, form submit).
190
190
  - Do NOT test implementation details (internal state, private methods, component structure).
191
191
  - Focus on: "When user clicks X, does Y appear?" not "Does `useState` hold the right value?"
@@ -212,7 +212,7 @@ Before moving to Review, verify:
212
212
 
213
213
  ---
214
214
 
215
- ### Phase 5: REVIEW — /review
215
+ ### Phase 5: REVIEW - /review
216
216
 
217
217
  **Auto-activates → `[ROLE: Staff Engineer]` + `[ROLE: Senior Designer]` for UI tasks**
218
218
 
@@ -232,7 +232,7 @@ Inspired by [obra/superpowers](https://github.com/obra/superpowers):
232
232
 
233
233
  ---
234
234
 
235
- ### Phase 5.5: SIMPLIFY — /simplify
235
+ ### Phase 5.5: SIMPLIFY - /simplify
236
236
 
237
237
  **Auto-activates → `[ROLE: Staff Engineer]` (Ponytail Mindset)**
238
238
 
@@ -245,7 +245,7 @@ Before merging, ruthlessly simplify:
245
245
 
246
246
  ---
247
247
 
248
- ### Phase 6: SHIP — /ship
248
+ ### Phase 6: SHIP - /ship
249
249
 
250
250
  **Auto-activates → `[ROLE: Release Engineer]`**
251
251
 
@@ -259,8 +259,7 @@ Only ship when all gates are green.
259
259
  - [ ] Docs updated (README, API docs, changelogs)
260
260
  - [ ] Breaking changes documented
261
261
  - [ ] Rollback plan exists
262
- - [ ] Vercel Preview Deployment is successful and manually verified
263
- - [ ] Core Web Vitals pass in preview (LCP < 2.5s, CLS < 0.1, INP < 200ms)
262
+ - [ ] Preview / staging deployment verified (if applicable, e.g. Vercel Preview and Core Web Vitals for frontend deployments)
264
263
 
265
264
  #### Operational Self-Improvement
266
265
 
@@ -303,6 +302,7 @@ export async function POST(req) {
303
302
  - [ ] Implementation plan broken down into vertical tasks < 2 hours each.
304
303
  - [ ] Tests written before implementation (TDD/BDD).
305
304
  - [ ] Code reviewed against correctness, security, performance, and design gates.
305
+ - [ ] Staged security and quality check passes (`contextos scan --staged --enforce`).
306
306
  - [ ] Simplification ladder executed before shipping.
307
307
 
308
308
  ---
@@ -329,10 +329,10 @@ export async function POST(req) {
329
329
 
330
330
  When completing a task or workflow, you must explicitly report your final status as the last part of your output:
331
331
 
332
- - **DONE** — completed with evidence.
333
- - **DONE_WITH_CONCERNS** — completed, but list concerns.
334
- - **BLOCKED** — cannot proceed; state blocker and what was tried.
335
- - **NEEDS_CONTEXT** — missing info; state exactly what is needed.
332
+ - **DONE** - completed with evidence.
333
+ - **DONE_WITH_CONCERNS** - completed, but list concerns.
334
+ - **BLOCKED** - cannot proceed; state blocker and what was tried.
335
+ - **NEEDS_CONTEXT** - missing info; state exactly what is needed.
336
336
 
337
337
 
338
338
  # engineering-workflow Examples — Anti-patterns vs ContextOS Standard
@@ -43,6 +43,7 @@ Activate whenever:
43
43
  1. Run the project validator or compiler (`node .agents/ctx.js validate`, `tsc --noEmit`, etc.).
44
44
  2. Run unit and integration tests (`npm test`, `pytest`, etc.).
45
45
  3. Run linter and formatting checks (`npm run lint:md`, `eslint`, etc.).
46
+ 4. Run staged security and quality scanner (`contextos scan --staged --enforce`).
46
47
  - If a test or validation fails, do not guess: read the exact error trace, fix the root cause, and re-run until green.
47
48
 
48
49
  ### 4. Surgical Blast Radius Containment
@@ -78,7 +79,7 @@ Activate whenever:
78
79
  **Eliminate the "black box" by narrating technical decisions.**
79
80
 
80
81
  - Avoid executing long, silent chains of tool calls without user visibility.
81
- - Provide a concise 1–2 sentence transparent status update before key operations:
82
+ - Provide a concise 1-2 sentence transparent status update before key operations:
82
83
  - State what was inspected or verified from the code.
83
84
  - State the architectural decision made and the immediate next action.
84
85
  - Keep narration crisp and actionable without excessive verbosity.
@@ -163,3 +164,103 @@ export async function updateUser(id, data, session) {
163
164
  - Pairs with `engineering-workflow` to enforce the 6-phase pipeline.
164
165
  - Enforces the 7-rung ladder of `ponytail-mindset`.
165
166
  - Acts as the baseline behavioral guardrail across all Gemini and Antigravity operations.
167
+
168
+
169
+ # gemini-precision Examples - Anti-patterns vs ContextOS Standard
170
+
171
+ ## Example 1: Read-Before-Write Invariant (Zero Assumptions)
172
+
173
+ ### Anti-pattern: Hallucinated Import and Signature
174
+
175
+ ```typescript
176
+ // BAD: Assuming the module exists and export is a default function
177
+ import hashPassword from 'src/utils/crypto';
178
+ const hash = hashPassword(password);
179
+ ```
180
+
181
+ ### Best practice: ContextOS Standard (Inspected Active Codebase First)
182
+
183
+ ```typescript
184
+ // GOOD: Inspected src/lib/auth.ts via view_file before writing code
185
+ import { hashSecret, ARGON2_CONFIG } from '../lib/auth.js';
186
+ const hash = await hashSecret(password, ARGON2_CONFIG);
187
+ ```
188
+
189
+ ---
190
+
191
+ ## Example 2: Zero-Placeholder Invariant (Complete Code Only)
192
+
193
+ ### Anti-pattern: Lazy Stubs and Ellipsis Comments
194
+
195
+ ```typescript
196
+ // BAD: Emitting incomplete code with TODOs and ellipsis
197
+ export function processTransaction(tx: Transaction) {
198
+ // TODO: validate transaction balance
199
+ // ... rest of implementation stays here ...
200
+ return { status: 'ok' };
201
+ }
202
+ ```
203
+
204
+ ### Best practice: ContextOS Standard (100% Drop-in Compilable)
205
+
206
+ ```typescript
207
+ // GOOD: Fully implemented logic with complete error handling
208
+ export function processTransaction(tx: Transaction): TransactionResult {
209
+ if (!tx.amount || tx.amount <= 0) {
210
+ throw new ValidationError('Transaction amount must be positive');
211
+ }
212
+ if (tx.senderBalance < tx.amount) {
213
+ throw new InsufficientFundsError(tx.senderId, tx.amount);
214
+ }
215
+ return {
216
+ status: 'ok',
217
+ transactionId: tx.id,
218
+ newBalance: tx.senderBalance - tx.amount,
219
+ };
220
+ }
221
+ ```
222
+
223
+ ---
224
+
225
+ ## Example 3: Mandatory Proof-of-Work Invariant
226
+
227
+ ### Anti-pattern: Claiming Task Complete Without Evidence
228
+
229
+ ```text
230
+ BAD: "I have updated the authentication handler. The code looks correct and is ready to merge."
231
+ ```
232
+
233
+ ### Best practice: ContextOS Standard (Verified with Automated Gates)
234
+
235
+ ```bash
236
+ # GOOD: Run test suite, staged scanner, and consistency checks
237
+ npm test
238
+ contextos scan --staged --enforce
239
+ node .agents/ctx.js validate
240
+ ```
241
+
242
+ # gemini-precision Troubleshooting & Common Failure Modes
243
+
244
+ ## 1. Test Failure Investigation (No Guesswork)
245
+
246
+ - **Symptom**: Test fails during `npm test` after code modifications.
247
+ - **Root Cause**: Trying to patch the code without reading the exact assertion diff.
248
+ - **Fix**: Never guess the fix. View the test file line where assertion failed, inspect expected vs actual output, and resolve the root discrepancy.
249
+
250
+ ## 2. Accidental Staged Secrets or Placeholders
251
+
252
+ - **Symptom**: `contextos scan --staged --enforce` fails with exit code 1.
253
+ - **Root Cause**: Committed temporary `.env` file or left an unfinished `// TODO: implement later` stub in added lines.
254
+ - **Fix**: Remove or redact the secret before committing. Fully implement the logic or replace the placeholder with an explicit tracked issue rather than committed code stubs.
255
+
256
+ ## 3. Scope Creep and Excessive Blast Radius
257
+
258
+ - **Symptom**: Unrelated files reformatted or imports reordered across the repository.
259
+ - **Root Cause**: Full-file rewrite instead of targeted surgical replacement.
260
+ - **Fix**: Use targeted chunks that touch only the lines specified in the task plan. Avoid modifying unrelated styling or formatting.
261
+
262
+ ## 4. Forbidden Long Dashes
263
+
264
+ - **Symptom**: Linter or compliance check flags unicode dashes in text.
265
+ - **Root Cause**: Using typography dashes (`\u2014` or `\u2013`) instead of standard ASCII hyphens.
266
+ - **Fix**: Replace all em-dashes and en-dashes with standard ASCII hyphens (` - `) or appropriate punctuation (parentheses, commas, colons).
@@ -10,7 +10,7 @@ Activate on every task to declare explicit specialist role and mindset before be
10
10
 
11
11
  ## Rules & Patterns
12
12
 
13
- Inspired by [Garry Tan's gstack](https://github.com/garrytan/gstack) — shipping 810× more logical code than a solo dev in 2013.
13
+ Inspired by [Garry Tan's gstack](https://github.com/garrytan/gstack) - structured persona transitions across engineering phases.
14
14
 
15
15
  ## Core Principle
16
16
 
@@ -18,13 +18,14 @@ Inspired by [Garry Tan's gstack](https://github.com/garrytan/gstack) — shippin
18
18
 
19
19
  ## Role Identification Protocol
20
20
 
21
- At the start of each task or major phase switch, declare your role:
21
+ At the start of each task or major phase switch, declare your role using the ContextOS standard format:
22
22
 
23
- ```
24
- [ROLE: <Role Name>] — <One-line description of your mandate for this task>
23
+ ```text
24
+ [DOMAIN: <Domain>] [PHASE: <Phase>] [ROLE: <Role Name>]
25
+ Skills loaded: <skill-1>, <skill-2>
25
26
  ```
26
27
 
27
- > **Anti-Spam Invariant**: Declare this role **strictly once per phase**. Never prefix intermediate tool calls, file operations, or step updates with role tags.
28
+ > **Anti-Spam Invariant**: Declare this role header **strictly once per phase**. Never prefix intermediate tool calls, file operations, or step updates with role tags.
28
29
 
29
30
  Then execute ONLY within the constraints of that role.
30
31
 
@@ -103,7 +104,7 @@ THINK PLAN BUILD REVIEW TEST SHIP
103
104
  2. **One role at a time.** Don't mix QA and implementation in the same response.
104
105
  3. **Declare before acting.** Always state `[ROLE: X]` before switching modes.
105
106
  4. **Escalate correctly.** If a QA finds an architectural problem → escalate to Architect role.
106
- 5. **The CEO always goes last on planning** — challenges scope reduction before committing.
107
+ 5. **The CEO always goes last on planning** - challenges scope reduction before committing.
107
108
 
108
109
  ## Example Usage
109
110