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.
- package/.agents/AGENTS.md +53 -33
- package/.agents/adapters/aider/export.js +41 -14
- package/.agents/adapters/claude/export.js +54 -3
- package/.agents/adapters/copilot/export.js +1 -1
- package/.agents/adapters/cursor/export.js +1 -1
- package/.agents/adapters/drift-detector.js +86 -10
- package/.agents/adapters/gemini/export.js +1 -1
- package/.agents/adapters/pure-compiler.js +28 -6
- package/.agents/adapters/shared.js +13 -4
- package/.agents/adapters/zed/export.js +1 -1
- package/.agents/compiled/registry.v2.json +29 -25
- package/.agents/compiled/registry.v2.sha256 +1 -1
- package/.agents/core/skills/context-os/SKILL.md +34 -37
- package/.agents/core/skills/engineering-workflow/SKILL.md +24 -24
- package/.agents/core/skills/gemini-precision/EXAMPLES.md +72 -0
- package/.agents/core/skills/gemini-precision/SKILL.md +2 -1
- package/.agents/core/skills/gemini-precision/TROUBLESHOOTING.md +25 -0
- package/.agents/core/skills/gemini-precision/skill.yaml +2 -0
- package/.agents/core/skills/gstack-roles/SKILL.md +7 -6
- package/.agents/core/skills/security/SKILL.md +44 -16
- package/.agents/core/skills/security/skill.yaml +0 -1
- package/.agents/ctx.js +20 -14
- package/.agents/generated/claude/skills/context-os/SKILL.md +34 -37
- package/.agents/generated/claude/skills/engineering-workflow/SKILL.md +24 -24
- package/.agents/generated/claude/skills/gemini-precision/SKILL.md +102 -1
- package/.agents/generated/claude/skills/gstack-roles/SKILL.md +7 -6
- package/.agents/generated/claude/skills/security/SKILL.md +44 -16
- package/.agents/generated/gemini/skills/context-os/SKILL.md +34 -37
- package/.agents/generated/gemini/skills/engineering-workflow/SKILL.md +24 -24
- package/.agents/generated/gemini/skills/gemini-precision/SKILL.md +105 -1
- package/.agents/generated/gemini/skills/gstack-roles/SKILL.md +7 -6
- package/.agents/generated/gemini/skills/security/SKILL.md +44 -125
- package/.agents/plugins.js +105 -8
- package/.agents/profiles.js +32 -11
- package/.agents/resolver/canonical-resolver.js +7 -7
- package/.agents/validate.js +69 -1
- package/README.md +81 -24
- package/bin/commands/hook.js +167 -0
- package/bin/commands/scan.js +77 -0
- package/bin/commands.js +39 -1
- package/bin/index.js +151 -34
- package/bin/lib/gate.js +171 -0
- package/bin/lib/git-snapshot.js +214 -0
- package/bin/lib/scan.js +461 -0
- package/catalog/skills/adapters/EXAMPLES.md +19 -0
- package/catalog/skills/adapters/SKILL.md +101 -0
- package/catalog/skills/adapters/TROUBLESHOOTING.md +7 -0
- package/catalog/skills/adapters/VALIDATION.json +12 -0
- package/catalog/skills/adapters/skill.yaml +13 -0
- package/catalog/skills/api-design/EXAMPLES.md +91 -0
- package/catalog/skills/api-design/SKILL.md +63 -0
- package/catalog/skills/api-design/TROUBLESHOOTING.md +54 -0
- package/catalog/skills/api-design/VALIDATION.json +11 -0
- package/catalog/skills/api-design/skill.yaml +14 -0
- package/catalog/skills/architecture-diagrams/SKILL.md +108 -0
- package/catalog/skills/architecture-diagrams/VALIDATION.json +12 -0
- package/catalog/skills/architecture-diagrams/skill.yaml +9 -0
- package/catalog/skills/brutalist-design/EXAMPLES.md +59 -0
- package/catalog/skills/brutalist-design/SKILL.md +150 -0
- package/catalog/skills/brutalist-design/VALIDATION.json +12 -0
- package/catalog/skills/brutalist-design/skill.yaml +10 -0
- package/catalog/skills/ci-cd/EXAMPLES.md +79 -0
- package/catalog/skills/ci-cd/SKILL.md +69 -0
- package/catalog/skills/ci-cd/TROUBLESHOOTING.md +52 -0
- package/catalog/skills/ci-cd/VALIDATION.json +11 -0
- package/catalog/skills/ci-cd/skill.yaml +13 -0
- package/catalog/skills/database/EXAMPLES.md +74 -0
- package/catalog/skills/database/SKILL.md +101 -0
- package/catalog/skills/database/TROUBLESHOOTING.md +18 -0
- package/catalog/skills/database/VALIDATION.json +11 -0
- package/catalog/skills/database/skill.yaml +14 -0
- package/catalog/skills/ddd/EXAMPLES.md +42 -0
- package/catalog/skills/ddd/SKILL.md +247 -0
- package/catalog/skills/ddd/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/ddd/VALIDATION.json +12 -0
- package/catalog/skills/ddd/skill.yaml +14 -0
- package/catalog/skills/decisions/EXAMPLES.md +35 -0
- package/catalog/skills/decisions/SKILL.md +90 -0
- package/catalog/skills/decisions/TROUBLESHOOTING.md +13 -0
- package/catalog/skills/decisions/VALIDATION.json +12 -0
- package/catalog/skills/decisions/skill.yaml +13 -0
- package/catalog/skills/docker/EXAMPLES.md +56 -0
- package/catalog/skills/docker/SKILL.md +169 -0
- package/catalog/skills/docker/TROUBLESHOOTING.md +18 -0
- package/catalog/skills/docker/VALIDATION.json +11 -0
- package/catalog/skills/docker/skill.yaml +13 -0
- package/catalog/skills/fastapi/EXAMPLES.md +36 -0
- package/catalog/skills/fastapi/SKILL.md +171 -0
- package/catalog/skills/fastapi/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/fastapi/VALIDATION.json +12 -0
- package/catalog/skills/fastapi/skill.yaml +14 -0
- package/catalog/skills/generators/EXAMPLES.md +19 -0
- package/catalog/skills/generators/SKILL.md +110 -0
- package/catalog/skills/generators/TROUBLESHOOTING.md +7 -0
- package/catalog/skills/generators/VALIDATION.json +12 -0
- package/catalog/skills/generators/skill.yaml +22 -0
- package/catalog/skills/generators/templates/API.md +77 -0
- package/catalog/skills/generators/templates/ARCHITECTURE.md +70 -0
- package/catalog/skills/generators/templates/DATABASE.md +42 -0
- package/catalog/skills/generators/templates/DECISION.md +46 -0
- package/catalog/skills/generators/templates/PRD.md +67 -0
- package/catalog/skills/generators/templates/PROJECT_GRAPH.md +56 -0
- package/catalog/skills/generators/templates/ROADMAP.md +51 -0
- package/catalog/skills/generators/templates/TASKS.md +43 -0
- package/catalog/skills/generators/templates/UI.md +73 -0
- package/catalog/skills/graphify/EXAMPLES.md +73 -0
- package/catalog/skills/graphify/SKILL.md +130 -0
- package/catalog/skills/graphify/VALIDATION.json +12 -0
- package/catalog/skills/graphify/skill.yaml +13 -0
- package/catalog/skills/impeccable-design/EXAMPLES.md +26 -0
- package/catalog/skills/impeccable-design/SKILL.md +201 -0
- package/catalog/skills/impeccable-design/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/impeccable-design/VALIDATION.json +12 -0
- package/catalog/skills/impeccable-design/skill.yaml +15 -0
- package/catalog/skills/interview-me/SKILL.md +97 -0
- package/catalog/skills/interview-me/VALIDATION.json +12 -0
- package/catalog/skills/interview-me/skill.yaml +9 -0
- package/catalog/skills/microservices/EXAMPLES.md +38 -0
- package/catalog/skills/microservices/SKILL.md +164 -0
- package/catalog/skills/microservices/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/microservices/VALIDATION.json +12 -0
- package/catalog/skills/microservices/skill.yaml +14 -0
- package/catalog/skills/minimalist-design/EXAMPLES.md +58 -0
- package/catalog/skills/minimalist-design/SKILL.md +113 -0
- package/catalog/skills/minimalist-design/VALIDATION.json +12 -0
- package/catalog/skills/minimalist-design/skill.yaml +10 -0
- package/catalog/skills/nestjs/EXAMPLES.md +40 -0
- package/catalog/skills/nestjs/SKILL.md +139 -0
- package/catalog/skills/nestjs/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/nestjs/VALIDATION.json +12 -0
- package/catalog/skills/nestjs/skill.yaml +14 -0
- package/catalog/skills/nextjs/EXAMPLES.md +40 -0
- package/catalog/skills/nextjs/SKILL.md +163 -0
- package/catalog/skills/nextjs/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/nextjs/VALIDATION.json +12 -0
- package/catalog/skills/nextjs/skill.yaml +14 -0
- package/catalog/skills/node/EXAMPLES.md +80 -0
- package/catalog/skills/node/SKILL.md +128 -0
- package/catalog/skills/node/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/node/VALIDATION.json +12 -0
- package/catalog/skills/node/skill.yaml +14 -0
- package/catalog/skills/performance/EXAMPLES.md +30 -0
- package/catalog/skills/performance/SKILL.md +75 -0
- package/catalog/skills/performance/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/performance/VALIDATION.json +12 -0
- package/catalog/skills/performance/skill.yaml +14 -0
- package/catalog/skills/react/EXAMPLES.md +79 -0
- package/catalog/skills/react/SKILL.md +132 -0
- package/catalog/skills/react/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/react/VALIDATION.json +12 -0
- package/catalog/skills/react/skill.yaml +14 -0
- package/catalog/skills/react-best-practices/SKILL.md +158 -0
- package/catalog/skills/react-best-practices/VALIDATION.json +12 -0
- package/catalog/skills/react-best-practices/skill.yaml +13 -0
- package/catalog/skills/redesign-audit/SKILL.md +117 -0
- package/catalog/skills/redesign-audit/VALIDATION.json +12 -0
- package/catalog/skills/redesign-audit/skill.yaml +9 -0
- package/catalog/skills/security-audit/EXAMPLES.md +79 -0
- package/catalog/skills/security-audit/SKILL.md +91 -0
- package/catalog/skills/security-audit/TROUBLESHOOTING.md +46 -0
- package/catalog/skills/security-audit/VALIDATION.json +11 -0
- package/catalog/skills/security-audit/skill.yaml +14 -0
- package/catalog/skills/soft-design/EXAMPLES.md +51 -0
- package/catalog/skills/soft-design/SKILL.md +108 -0
- package/catalog/skills/soft-design/VALIDATION.json +12 -0
- package/catalog/skills/soft-design/skill.yaml +10 -0
- package/catalog/skills/state-management/EXAMPLES.md +56 -0
- package/catalog/skills/state-management/SKILL.md +168 -0
- package/catalog/skills/state-management/TROUBLESHOOTING.md +18 -0
- package/catalog/skills/state-management/VALIDATION.json +11 -0
- package/catalog/skills/state-management/skill.yaml +14 -0
- package/catalog/skills/subagent-orchestrator/SKILL.md +117 -0
- package/catalog/skills/subagent-orchestrator/VALIDATION.json +12 -0
- package/catalog/skills/subagent-orchestrator/skill.yaml +9 -0
- package/catalog/skills/system-design/EXAMPLES.md +75 -0
- package/catalog/skills/system-design/SKILL.md +419 -0
- package/catalog/skills/system-design/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/system-design/VALIDATION.json +12 -0
- package/catalog/skills/system-design/skill.yaml +14 -0
- package/catalog/skills/terraform/EXAMPLES.md +74 -0
- package/catalog/skills/terraform/SKILL.md +55 -0
- package/catalog/skills/terraform/TROUBLESHOOTING.md +53 -0
- package/catalog/skills/terraform/VALIDATION.json +11 -0
- package/catalog/skills/terraform/skill.yaml +14 -0
- package/catalog/skills/testing/EXAMPLES.md +122 -0
- package/catalog/skills/testing/SKILL.md +70 -0
- package/catalog/skills/testing/TROUBLESHOOTING.md +18 -0
- package/catalog/skills/testing/VALIDATION.json +11 -0
- package/catalog/skills/testing/skill.yaml +14 -0
- package/catalog/skills/typescript/EXAMPLES.md +64 -0
- package/catalog/skills/typescript/SKILL.md +112 -0
- package/catalog/skills/typescript/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/typescript/VALIDATION.json +12 -0
- package/catalog/skills/typescript/skill.yaml +14 -0
- package/catalog/skills/ui-design/EXAMPLES.md +21 -0
- package/catalog/skills/ui-design/SKILL.md +124 -0
- package/catalog/skills/ui-design/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/ui-design/VALIDATION.json +12 -0
- package/catalog/skills/ui-design/skill.yaml +16 -0
- package/catalog/skills/ui-ux-pro/EXAMPLES.md +62 -0
- package/catalog/skills/ui-ux-pro/SKILL.md +418 -0
- package/catalog/skills/ui-ux-pro/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/ui-ux-pro/VALIDATION.json +12 -0
- package/catalog/skills/ui-ux-pro/skill.yaml +14 -0
- package/catalog/skills/ux-design/EXAMPLES.md +36 -0
- package/catalog/skills/ux-design/SKILL.md +116 -0
- package/catalog/skills/ux-design/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/ux-design/VALIDATION.json +12 -0
- package/catalog/skills/ux-design/skill.yaml +16 -0
- package/catalog/skills/vercel-optimize/SKILL.md +83 -0
- package/catalog/skills/vercel-optimize/VALIDATION.json +12 -0
- package/catalog/skills/vercel-optimize/scripts/collect-signals.mjs +131 -0
- package/catalog/skills/vercel-optimize/scripts/gate-investigations.mjs +142 -0
- package/catalog/skills/vercel-optimize/scripts/merge-signals.mjs +143 -0
- package/catalog/skills/vercel-optimize/scripts/scan-codebase.mjs +174 -0
- package/catalog/skills/vercel-optimize/skill.yaml +15 -0
- package/catalog/skills/web-accessibility/EXAMPLES.md +39 -0
- package/catalog/skills/web-accessibility/SKILL.md +151 -0
- package/catalog/skills/web-accessibility/TROUBLESHOOTING.md +19 -0
- package/catalog/skills/web-accessibility/VALIDATION.json +12 -0
- package/catalog/skills/web-accessibility/skill.yaml +14 -0
- package/package.json +5 -2
- package/.agents/core/skills/security/security.md +0 -106
package/README.md
CHANGED
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/kok-o/contextos-agents">
|
|
3
|
+
<img src="./Frame%202.png" alt="ContextOS Logo" width="88" height="88" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h1 align="center">contextos-agents</h1>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<strong>One version-controlled source of engineering rules for supported coding agents.</strong>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://www.npmjs.com/package/contextos-agents"><img src="https://img.shields.io/npm/v/contextos-agents?color=18181b&logo=npm" alt="npm version" /></a>
|
|
15
|
+
<a href="https://www.npmjs.com/package/contextos-agents"><img src="https://img.shields.io/npm/dt/contextos-agents?color=18181b&logo=npm&label=downloads" alt="npm downloads" /></a>
|
|
16
|
+
<a href="https://nodejs.org/"><img src="https://img.shields.io/badge/node-%3E%3D22.0.0-18181b?logo=node.js" alt="Node.js" /></a>
|
|
17
|
+
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache_2.0-18181b" alt="License" /></a>
|
|
18
|
+
<a href="https://github.com/kok-o/contextos-agents/actions/workflows/validate-skills.yml"><img src="https://img.shields.io/github/actions/workflow/status/kok-o/contextos-agents/validate-skills.yml?label=ci&color=18181b&logo=github" alt="CI" /></a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
<p align="center">
|
|
22
|
+
<a href="#installation">Installation</a> •
|
|
23
|
+
<a href="./GUIDE.md">Guide</a> •
|
|
24
|
+
<a href="./docs/product/onboarding.md">Onboarding</a> •
|
|
25
|
+
<a href="./docs/ADAPTER_COMPATIBILITY.md">Adapters</a> •
|
|
26
|
+
<a href="#supported-agents--compilation">Supported Agents</a> •
|
|
27
|
+
<a href="./CONTRIBUTING.md">Contributing</a> •
|
|
28
|
+
<a href="https://www.npmjs.com/package/contextos-agents">npm</a>
|
|
29
|
+
</p>
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
ContextOS is a deterministic context and policy compiler for AI coding agents. It transforms your team's version-controlled engineering rules into focused, verifiable context for Gemini, Claude Code, Cursor, GitHub Copilot, Aider, and Zed - and detects configuration drift in CI.
|
|
11
34
|
|
|
12
35
|
## Installation
|
|
13
36
|
|
|
@@ -34,22 +57,24 @@ npx contextos-agents --skip-compile # Skip auto-compilation step
|
|
|
34
57
|
|
|
35
58
|
## Why ContextOS?
|
|
36
59
|
|
|
37
|
-
|
|
60
|
+
Modern development teams face fragmented AI tooling: engineers use Cursor, Claude Code, GitHub Copilot, Gemini, Zed, and Aider. Each tool requires its own proprietary rules format, leading to configuration drift, contradictory standards, and unvetted AI slop (`// TODO`, leaked secrets).
|
|
38
61
|
|
|
39
|
-
|
|
62
|
+
Artificially truncating skills to save tokens degrades model reasoning and induces hallucinations. Instead, ContextOS ensures that agents receive complete, high-fidelity engineering context from a single version-controlled source.
|
|
63
|
+
|
|
64
|
+
**ContextOS is not another coding agent.** It is the deterministic context compiler and policy engine for the agents your team already uses.
|
|
40
65
|
|
|
41
66
|
### The Three Pillars
|
|
42
67
|
|
|
43
|
-
1. **Portable:** Define your engineering
|
|
44
|
-
2. **Focused:** The resolver
|
|
45
|
-
3. **Verifiable:**
|
|
68
|
+
1. **Portable (Multi-Agent):** Define your engineering skills once in standard Markdown. ContextOS compiles native configurations for all supported agents (Gemini, Claude Code, Cursor, Copilot, Aider, and Zed).
|
|
69
|
+
2. **High-Fidelity & Focused:** The resolver maps domain skills to relevant tasks without lossy truncation, delivering rich, complete context to the model.
|
|
70
|
+
3. **Verifiable in CI:** Lockfile v2 provenance, dual-hash verification, and CI quality gates detect configuration drift and enforce quality guardrails before merge.
|
|
46
71
|
|
|
47
72
|
## How it works
|
|
48
73
|
|
|
49
74
|
1. Define version-controlled engineering policies once.
|
|
50
|
-
2. Resolve
|
|
75
|
+
2. Resolve the complete, relevant skill policies for the current task.
|
|
51
76
|
3. Compile native configuration for each coding agent.
|
|
52
|
-
4. Detect configuration drift in CI.
|
|
77
|
+
4. Detect configuration drift and policy violations in CI.
|
|
53
78
|
|
|
54
79
|
```bash
|
|
55
80
|
contextos resolve "review authentication changes" \
|
|
@@ -62,10 +87,10 @@ Selected:
|
|
|
62
87
|
engineering-workflow required dependency
|
|
63
88
|
|
|
64
89
|
Excluded:
|
|
65
|
-
context-manager
|
|
90
|
+
context-manager domain relevance filter
|
|
66
91
|
|
|
67
92
|
Risk: high
|
|
68
|
-
|
|
93
|
+
Context status: complete and verified
|
|
69
94
|
|
|
70
95
|
## Dynamic Skill Resolution & Unified CLI (`contextos` / `ctx.js`)
|
|
71
96
|
|
|
@@ -108,9 +133,35 @@ contextos doctor
|
|
|
108
133
|
contextos export all # Compile for all agents
|
|
109
134
|
```
|
|
110
135
|
|
|
111
|
-
###
|
|
136
|
+
### Staged Index Security Scanner (`contextos scan`)
|
|
137
|
+
|
|
138
|
+
Scan staged changes directly from the Git index for secret leaks, blocked credential files, unfinished lazy stubs, and write-scope containment:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
contextos scan --staged --enforce
|
|
142
|
+
contextos scan --staged --placeholders --scope .agents/task-scope.json --json
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Safe Git Pre-Commit Hooks (`contextos hook`)
|
|
146
|
+
|
|
147
|
+
Install or remove isolated pre-commit hooks that run fast security checks without clobbering existing developer hooks:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
contextos hook install
|
|
151
|
+
contextos hook uninstall
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### CI Quality Gate (`contextos gate`)
|
|
155
|
+
|
|
156
|
+
Run the complete 8-point production quality gate locally:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
contextos gate
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### CI Quality Gate Action (contextos-gate)
|
|
112
163
|
|
|
113
|
-
Guard your repository against skill drift,
|
|
164
|
+
Guard your repository against skill drift, missing outputs, and rule regressions using the official GitHub Composite Action:
|
|
114
165
|
|
|
115
166
|
```yaml
|
|
116
167
|
# .github/workflows/pr-gate.yml
|
|
@@ -121,9 +172,15 @@ jobs:
|
|
|
121
172
|
runs-on: ubuntu-latest
|
|
122
173
|
steps:
|
|
123
174
|
- uses: actions/checkout@v4
|
|
124
|
-
- uses: kok-o/contextos-agents/.github/actions/contextos-gate@v2.
|
|
175
|
+
- uses: kok-o/contextos-agents/.github/actions/contextos-gate@v2.1.1
|
|
176
|
+
with:
|
|
177
|
+
version: '2.1.1' # Pinned version of contextos-agents runner
|
|
178
|
+
adapters: 'all' # Adapters to verify (or specific: 'cursor', 'claude')
|
|
179
|
+
working-directory: '.' # Project root directory
|
|
125
180
|
```
|
|
126
181
|
|
|
182
|
+
The action executes the verified ContextOS quality gate in-process from the pinned package version, verifying generated AI adapter configs against source skills without executing untrusted scripts from pull requests, and without requiring a Node.js project or running `npm test`.
|
|
183
|
+
|
|
127
184
|
## Optional MCP integration (Beta)
|
|
128
185
|
|
|
129
186
|
The MCP server is a separate beta package. It is not part of the stable `contextos-agents` core.
|
|
@@ -137,9 +194,9 @@ npx contextos-mcp --dir .
|
|
|
137
194
|
|
|
138
195
|
The MCP server is read-only by default. Runtime execution remains experimental and is outside the stable core scope.
|
|
139
196
|
|
|
140
|
-
## Security
|
|
197
|
+
## Security - Third-Party Skills
|
|
141
198
|
|
|
142
|
-
ContextOS skills are **executable context**
|
|
199
|
+
ContextOS skills are **executable context** - they become part of the system prompt that controls your AI agent's behavior. A malicious skill could instruct the AI agent to exfiltrate environment variables, modify files, or ignore your project's security policies.
|
|
143
200
|
|
|
144
201
|
> [!CAUTION]
|
|
145
202
|
> **Install skills only from repositories you trust as you would trust executable code.** Skills installed via `ctx.js skill add` from npm or GitHub are not sandboxed.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bin/commands/hook.js
|
|
3
|
+
* ContextOS Git Hook Installer & Lifecycle Manager
|
|
4
|
+
*
|
|
5
|
+
* Safely installs and uninstalls the pre-commit governance hook.
|
|
6
|
+
* Preserves pre-existing user hooks, supports core.hooksPath and worktrees,
|
|
7
|
+
* and operates idempotently.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const path = require('path');
|
|
14
|
+
const { findHooksDir } = require('../lib/git-snapshot.js');
|
|
15
|
+
|
|
16
|
+
const HOOK_MARKER_START = '# BEGIN CONTEXTOS HOOK';
|
|
17
|
+
const HOOK_MARKER_END = '# END CONTEXTOS HOOK';
|
|
18
|
+
|
|
19
|
+
const HOOK_PAYLOAD = `${HOOK_MARKER_START}
|
|
20
|
+
CTX_SCOPE_ARG=""
|
|
21
|
+
if [ -f ".agents/task-scope.json" ]; then
|
|
22
|
+
CTX_SCOPE_ARG="--scope .agents/task-scope.json"
|
|
23
|
+
fi
|
|
24
|
+
|
|
25
|
+
if [ -f "./node_modules/.bin/contextos" ]; then
|
|
26
|
+
./node_modules/.bin/contextos scan --staged --enforce --placeholders $CTX_SCOPE_ARG
|
|
27
|
+
CTX_STATUS=$?
|
|
28
|
+
elif [ -f "./node_modules/.bin/contextos-agents" ]; then
|
|
29
|
+
./node_modules/.bin/contextos-agents scan --staged --enforce --placeholders $CTX_SCOPE_ARG
|
|
30
|
+
CTX_STATUS=$?
|
|
31
|
+
elif [ -f "./bin/index.js" ] && [ -f "./package.json" ]; then
|
|
32
|
+
node ./bin/index.js scan --staged --enforce --placeholders $CTX_SCOPE_ARG
|
|
33
|
+
CTX_STATUS=$?
|
|
34
|
+
else
|
|
35
|
+
echo "[ERROR] ContextOS local runner not found. Install locally (npm i -D contextos-agents) before committing." >&2
|
|
36
|
+
exit 2
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
if [ $CTX_STATUS -ne 0 ]; then
|
|
40
|
+
exit $CTX_STATUS
|
|
41
|
+
fi
|
|
42
|
+
${HOOK_MARKER_END}`;
|
|
43
|
+
|
|
44
|
+
function installHook(cwd = process.cwd()) {
|
|
45
|
+
const hooksDir = findHooksDir(cwd);
|
|
46
|
+
|
|
47
|
+
if (!hooksDir) {
|
|
48
|
+
console.error('[ERROR] Not a Git repository or Git hooks directory not found.');
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!fs.existsSync(hooksDir)) {
|
|
53
|
+
fs.mkdirSync(hooksDir, { recursive: true });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const hookFile = path.join(hooksDir, 'pre-commit');
|
|
57
|
+
|
|
58
|
+
if (fs.existsSync(hookFile)) {
|
|
59
|
+
const existing = fs.readFileSync(hookFile, 'utf8');
|
|
60
|
+
|
|
61
|
+
// Validate shebang if present
|
|
62
|
+
const shebangMatch = existing.match(/^#!([^\r\n]+)/);
|
|
63
|
+
if (shebangMatch) {
|
|
64
|
+
const interpreter = shebangMatch[1].toLowerCase();
|
|
65
|
+
const isShell = /\b(sh|bash|zsh|dash)\b/.test(interpreter);
|
|
66
|
+
if (!isShell) {
|
|
67
|
+
console.error(`[ERROR] Pre-commit hook uses non-shell interpreter (${shebangMatch[0]}). ContextOS pre-commit hook requires POSIX shell.`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Strip any existing ContextOS block (e.g. legacy trailing block from v2.1.0)
|
|
73
|
+
const stripped = existing.includes(HOOK_MARKER_START)
|
|
74
|
+
? existing.replace(new RegExp(`\\n?${HOOK_MARKER_START}[\\s\\S]*?${HOOK_MARKER_END}\\n?`, 'g'), '').trim()
|
|
75
|
+
: existing.trim();
|
|
76
|
+
|
|
77
|
+
// Place HOOK_PAYLOAD right after shebang so it runs first and cannot be bypassed by user 'exit 0'
|
|
78
|
+
let updated;
|
|
79
|
+
const strippedShebangMatch = stripped.match(/^#!.*(?:\r?\n|$)/);
|
|
80
|
+
if (strippedShebangMatch) {
|
|
81
|
+
const shebang = strippedShebangMatch[0];
|
|
82
|
+
const rest = stripped.slice(shebang.length).trim();
|
|
83
|
+
const sep = rest ? '\n\n' : '\n';
|
|
84
|
+
updated = `${shebang.trimEnd()}\n\n${HOOK_PAYLOAD}${sep}${rest}`;
|
|
85
|
+
} else {
|
|
86
|
+
updated = `#!/bin/sh\n\n${HOOK_PAYLOAD}${stripped ? `\n\n${stripped}` : ''}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fs.writeFileSync(hookFile, updated.trimEnd() + '\n', 'utf8');
|
|
90
|
+
console.log(`✓ ContextOS pre-commit hook installed in ${hookFile}`);
|
|
91
|
+
} else {
|
|
92
|
+
// Fresh hook installation with shebang
|
|
93
|
+
const fresh = `#!/bin/sh\n\n${HOOK_PAYLOAD}\n`;
|
|
94
|
+
fs.writeFileSync(hookFile, fresh, 'utf8');
|
|
95
|
+
console.log(`✓ ContextOS pre-commit hook installed in ${hookFile}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
fs.chmodSync(hookFile, 0o755);
|
|
100
|
+
} catch {
|
|
101
|
+
// Best effort on platforms that do not support POSIX file modes
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function uninstallHook(cwd = process.cwd()) {
|
|
106
|
+
const hooksDir = findHooksDir(cwd);
|
|
107
|
+
|
|
108
|
+
if (!hooksDir) {
|
|
109
|
+
console.error('[ERROR] Not a Git repository or Git hooks directory not found.');
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const hookFile = path.join(hooksDir, 'pre-commit');
|
|
114
|
+
|
|
115
|
+
if (!fs.existsSync(hookFile)) {
|
|
116
|
+
console.log('✓ No pre-commit hook found to uninstall.');
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const existing = fs.readFileSync(hookFile, 'utf8');
|
|
121
|
+
|
|
122
|
+
if (!existing.includes(HOOK_MARKER_START)) {
|
|
123
|
+
console.log('✓ No ContextOS hook block detected in pre-commit hook.');
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Remove exclusively the ContextOS demarcated block
|
|
128
|
+
const regex = new RegExp(`\\n?${HOOK_MARKER_START}[\\s\\S]*?${HOOK_MARKER_END}\\n?`, 'g');
|
|
129
|
+
const remaining = existing.replace(regex, '').trim();
|
|
130
|
+
|
|
131
|
+
// If file contains only shebang or is empty, remove it completely
|
|
132
|
+
if (!remaining || remaining === '#!/bin/sh' || remaining === '#!/bin/bash') {
|
|
133
|
+
fs.unlinkSync(hookFile);
|
|
134
|
+
console.log(`✓ ContextOS pre-commit hook uninstalled and empty ${hookFile} removed.`);
|
|
135
|
+
} else {
|
|
136
|
+
// Preserve remaining user scripts
|
|
137
|
+
fs.writeFileSync(hookFile, remaining + '\n', 'utf8');
|
|
138
|
+
console.log(`✓ ContextOS block removed from ${hookFile}; user commands preserved.`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function hookCommand(args, flags) {
|
|
143
|
+
const subCommand = args[1] ? args[1].toLowerCase().trim() : null;
|
|
144
|
+
|
|
145
|
+
if (subCommand === 'install') {
|
|
146
|
+
installHook(process.cwd());
|
|
147
|
+
process.exit(0);
|
|
148
|
+
} else if (subCommand === 'uninstall') {
|
|
149
|
+
uninstallHook(process.cwd());
|
|
150
|
+
process.exit(0);
|
|
151
|
+
} else {
|
|
152
|
+
console.log('\nUsage: contextos hook <install|uninstall>\n');
|
|
153
|
+
console.log('Commands:');
|
|
154
|
+
console.log(' install Safely install pre-commit quality gate hook');
|
|
155
|
+
console.log(' uninstall Remove ContextOS block while preserving custom hooks\n');
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
module.exports = {
|
|
161
|
+
installHook,
|
|
162
|
+
uninstallHook,
|
|
163
|
+
hookCommand,
|
|
164
|
+
HOOK_MARKER_START,
|
|
165
|
+
HOOK_MARKER_END,
|
|
166
|
+
HOOK_PAYLOAD,
|
|
167
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bin/commands/scan.js
|
|
3
|
+
* ContextOS CLI Command Handler: scan
|
|
4
|
+
*
|
|
5
|
+
* Runs security, placeholder, and write-scope checks against Git staged files.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const { runScan } = require('../lib/scan.js');
|
|
12
|
+
|
|
13
|
+
function scanCommand(args, flags = {}) {
|
|
14
|
+
const isJson = flags.json || args.includes('--json');
|
|
15
|
+
const enforce = flags.enforce || args.includes('--enforce');
|
|
16
|
+
const checkPlaceholders = flags.placeholders || args.includes('--placeholders');
|
|
17
|
+
const checkSecrets = !args.includes('--no-secrets');
|
|
18
|
+
|
|
19
|
+
const scopeIdx = args.indexOf('--scope');
|
|
20
|
+
const scopeFile = scopeIdx !== -1 && args[scopeIdx + 1] ? args[scopeIdx + 1] : null;
|
|
21
|
+
|
|
22
|
+
const projectIdx = args.indexOf('--project');
|
|
23
|
+
const projectArg = projectIdx !== -1 && args[projectIdx + 1] ? args[projectIdx + 1] : null;
|
|
24
|
+
const targetProject = flags.project || projectArg;
|
|
25
|
+
const projectDir = targetProject ? path.resolve(targetProject) : process.cwd();
|
|
26
|
+
|
|
27
|
+
const result = runScan({
|
|
28
|
+
cwd: projectDir,
|
|
29
|
+
staged: true,
|
|
30
|
+
secrets: checkSecrets,
|
|
31
|
+
placeholders: checkPlaceholders,
|
|
32
|
+
scope: scopeFile,
|
|
33
|
+
enforce,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
if (isJson) {
|
|
37
|
+
console.log(JSON.stringify(result, null, 2));
|
|
38
|
+
process.exit(result.code);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log('\n══════════════════════════════════════════════════════');
|
|
42
|
+
console.log(' ContextOS Staged Index Scanner');
|
|
43
|
+
console.log('══════════════════════════════════════════════════════\n');
|
|
44
|
+
|
|
45
|
+
if (result.code === 2) {
|
|
46
|
+
console.error(` [ERROR] ${result.error || 'Scan incomplete'}\n`);
|
|
47
|
+
process.exit(2);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
console.log(` Staged Files Scanned : ${result.stats.stagedFilesCount}`);
|
|
51
|
+
console.log(` Enforcement Mode : ${enforce ? 'STRICT (fails on findings)' : 'ADVISORY (warnings only)'}`);
|
|
52
|
+
console.log(` Scope Containment : ${result.scope.status.toUpperCase()}`);
|
|
53
|
+
console.log(` Violations Found : ${result.stats.violationsCount}\n`);
|
|
54
|
+
|
|
55
|
+
if (result.findings.length > 0) {
|
|
56
|
+
console.log(' Findings:');
|
|
57
|
+
for (const f of result.findings) {
|
|
58
|
+
const loc = f.line ? `${f.file}:${f.line}` : f.file;
|
|
59
|
+
const tag = f.severity === 'error' ? 'ERROR' : 'WARN';
|
|
60
|
+
console.log(` • [${f.ruleId}] [${tag}] ${loc}`);
|
|
61
|
+
console.log(` ${f.details}`);
|
|
62
|
+
}
|
|
63
|
+
console.log('');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
console.log('──────────────────────────────────────────────────────');
|
|
67
|
+
if (result.ok) {
|
|
68
|
+
console.log(' RESULT: PASSED (Verification completed cleanly, no blocking violations)');
|
|
69
|
+
} else {
|
|
70
|
+
console.log(' RESULT: FAILED (Commit blocked due to staged violations)');
|
|
71
|
+
}
|
|
72
|
+
console.log('──────────────────────────────────────────────────────\n');
|
|
73
|
+
|
|
74
|
+
process.exit(result.code);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = scanCommand;
|
package/bin/commands.js
CHANGED
|
@@ -195,13 +195,28 @@ const COMMAND_REGISTRY = {
|
|
|
195
195
|
requiresProject: true,
|
|
196
196
|
options: [],
|
|
197
197
|
},
|
|
198
|
+
gate: {
|
|
199
|
+
name: 'gate',
|
|
200
|
+
description: 'Run quality gate validation and drift checks without disk mutation',
|
|
201
|
+
usage: 'contextos gate [--project <dir>] [--target <adapters>] [--profile <name>] [--json]',
|
|
202
|
+
requiresProject: false,
|
|
203
|
+
options: [
|
|
204
|
+
{ flag: '--project <dir>', desc: 'Target project directory (default: cwd)' },
|
|
205
|
+
{ flag: '--target <adapters>', desc: 'Adapters to verify (gemini, claude, cursor, copilot, aider, zed, all)' },
|
|
206
|
+
{ flag: '--profile <name>', desc: 'Profile override for verification' },
|
|
207
|
+
{ flag: '--json', desc: 'Output gate report in versioned JSON format' },
|
|
208
|
+
],
|
|
209
|
+
},
|
|
198
210
|
export: {
|
|
199
211
|
name: 'export',
|
|
200
212
|
description: 'Compile skills for target agent (gemini, claude, cursor, copilot, aider, zed, all)',
|
|
201
|
-
usage: 'contextos export <target> [--profile <name>]',
|
|
213
|
+
usage: 'contextos export <target> [--check] [--project <dir>] [--profile <name>] [--json]',
|
|
202
214
|
requiresProject: true,
|
|
203
215
|
options: [
|
|
216
|
+
{ flag: '--check', desc: 'Verify synchronization without modifying disk' },
|
|
217
|
+
{ flag: '--project <dir>', desc: 'Target project directory (default: cwd)' },
|
|
204
218
|
{ flag: '--profile <name>', desc: 'Apply profile for this export run' },
|
|
219
|
+
{ flag: '--json', desc: 'Output in JSON format' },
|
|
205
220
|
],
|
|
206
221
|
},
|
|
207
222
|
profile: {
|
|
@@ -293,6 +308,29 @@ const COMMAND_REGISTRY = {
|
|
|
293
308
|
{ flag: '--continue [txId]', desc: 'Attempt to resume and complete prepared transaction' },
|
|
294
309
|
],
|
|
295
310
|
},
|
|
311
|
+
scan: {
|
|
312
|
+
name: 'scan',
|
|
313
|
+
description: 'Scan Git staged index for secrets, lazy stubs, and write-scope containment',
|
|
314
|
+
usage: 'contextos scan [--staged] [--secrets] [--placeholders] [--scope <file>] [--enforce] [--json]',
|
|
315
|
+
requiresProject: false,
|
|
316
|
+
options: [
|
|
317
|
+
{ flag: '--staged', desc: 'Scan staged changes in Git index (default)' },
|
|
318
|
+
{ flag: '--placeholders', desc: 'Detect unfinished lazy placeholder stubs in newly added code' },
|
|
319
|
+
{ flag: '--scope <file>', desc: 'Verify staged files stay within declared task scope JSON' },
|
|
320
|
+
{ flag: '--enforce', desc: 'Fail with exit code 1 if violations are detected' },
|
|
321
|
+
{ flag: '--json', desc: 'Output scan results in versioned JSON format' },
|
|
322
|
+
],
|
|
323
|
+
},
|
|
324
|
+
hook: {
|
|
325
|
+
name: 'hook',
|
|
326
|
+
description: 'Manage safe pre-commit Git governance hooks',
|
|
327
|
+
usage: 'contextos hook <install|uninstall>',
|
|
328
|
+
requiresProject: false,
|
|
329
|
+
options: [
|
|
330
|
+
{ flag: 'install', desc: 'Install or update isolated pre-commit hook' },
|
|
331
|
+
{ flag: 'uninstall', desc: 'Remove ContextOS hook block while preserving custom hooks' },
|
|
332
|
+
],
|
|
333
|
+
},
|
|
296
334
|
};
|
|
297
335
|
|
|
298
336
|
/**
|