contextos-agents 2.0.0-beta.3 → 2.1.0

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 (57) 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 +1 -1
  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 +80 -7
  7. package/.agents/adapters/gemini/export.js +1 -1
  8. package/.agents/adapters/pure-compiler.js +10 -0
  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 +16 -10
  23. package/.agents/doctor.js +7 -20
  24. package/.agents/generated/claude/skills/context-os/SKILL.md +34 -37
  25. package/.agents/generated/claude/skills/engineering-workflow/SKILL.md +24 -24
  26. package/.agents/generated/claude/skills/gemini-precision/SKILL.md +102 -1
  27. package/.agents/generated/claude/skills/gstack-roles/SKILL.md +7 -6
  28. package/.agents/generated/claude/skills/security/SKILL.md +44 -16
  29. package/.agents/generated/gemini/skills/context-os/SKILL.md +34 -37
  30. package/.agents/generated/gemini/skills/engineering-workflow/SKILL.md +24 -24
  31. package/.agents/generated/gemini/skills/gemini-precision/SKILL.md +105 -1
  32. package/.agents/generated/gemini/skills/gstack-roles/SKILL.md +7 -6
  33. package/.agents/generated/gemini/skills/security/SKILL.md +44 -125
  34. package/.agents/plugins.js +5 -4
  35. package/.agents/resolver/canonical-resolver.js +7 -7
  36. package/.agents/validate.js +69 -1
  37. package/LICENSE +201 -21
  38. package/NOTICE +4 -0
  39. package/README.md +87 -34
  40. package/bin/commands/hook.js +129 -0
  41. package/bin/commands/scan.js +70 -0
  42. package/bin/commands/update.js +7 -8
  43. package/bin/commands.js +39 -1
  44. package/bin/index.js +144 -33
  45. package/bin/lib/gate.js +171 -0
  46. package/bin/lib/git-snapshot.js +187 -0
  47. package/bin/lib/scan.js +380 -0
  48. package/package.json +10 -12
  49. package/.agents/core/skills/security/security.md +0 -106
  50. package/benchmarks/v2/analysis/statistics.js +0 -140
  51. package/benchmarks/v2/analysis/stats.js +0 -69
  52. package/benchmarks/v2/arms/arm-definitions.js +0 -79
  53. package/benchmarks/v2/dataset.schema.json +0 -34
  54. package/benchmarks/v2/evaluators/index.js +0 -25
  55. package/benchmarks/v2/evaluators/verified-success.js +0 -116
  56. package/benchmarks/v2/harness/runner.js +0 -88
  57. package/benchmarks/v2/pilot-tasks.json +0 -392
package/LICENSE CHANGED
@@ -1,21 +1,201 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 contextos-agents contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or exemplary damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 ContextOS Contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ ContextOS (contextos-agents)
2
+ Copyright 2026 ContextOS Contributors
3
+
4
+ This product includes software developed at ContextOS (https://github.com/kok-o/contextos-agents).
package/README.md CHANGED
@@ -1,13 +1,36 @@
1
- # <img src="./Frame%202.png" height="40" align="absmiddle" /> contextos-agents
2
-
3
- [![npm version](https://img.shields.io/npm/v/contextos-agents.svg)](https://www.npmjs.com/package/contextos-agents)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
- [![Node.js](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen.svg)](https://nodejs.org/)
6
- [![CI](https://github.com/kok-o/contextos-agents/actions/workflows/validate-skills.yml/badge.svg)](https://github.com/kok-o/contextos-agents/actions/workflows/validate-skills.yml)
7
-
8
- **One source of truth for every coding agent.**
9
-
10
- ContextOS is a deterministic context and policy compiler for AI coding agents. It transforms your team's version-controlled engineering rules into a minimal, verifiable context payload for Cursor, Claude Code, GitHub Copilot, Aider, and Zed—and detects configuration drift in CI.
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
- Most AI coding assistants suffer from two extremes: they either operate in a vacuum with zero knowledge of your architectural standards, or they are choked with massive monolithic system prompts that cause context overflow and lazy code stubs (`// TODO`).
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
- **ContextOS is not another coding agent.** It governs the context and policies used by the agents your team already has.
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 rules once. ContextOS exports optimized configurations for all major AI editors (Cursor, Claude Code, Copilot, Aider, Zed).
44
- 2. **Minimal:** The dynamic resolver selects only the relevant skills and rules needed for a specific task, eliminating prompt bloat and token waste.
45
- 3. **Verifiable:** Lockfiles, provenance, drift detection, and CI gates make generated agent configuration reproducible and auditable.
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 only the policies relevant to the current task.
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 context budget
90
+ context-manager domain relevance filter
66
91
 
67
92
  Risk: high
68
- Estimated context: 2,840 tokens
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
- ### CI Quality Gate Action (`contextos-gate`)
136
+ ### Staged Index Security Scanner (`contextos scan`)
112
137
 
113
- Guard your repository against skill drift, secret leaks, and rule regressions using the official GitHub Composite Action:
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)
163
+
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,29 +172,31 @@ 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@main
175
+ - uses: kok-o/contextos-agents/.github/actions/contextos-gate@v2.0.0
176
+ with:
177
+ version: '2.0.0' # 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
 
127
- ## ContextOS MCP Bridge (Beta)
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`.
128
183
 
129
- ContextOS provides a read-only **Model Context Protocol (MCP)** server to allow compatible agents (like Claude Desktop) to dynamically read project rules, resolve context, and check project status.
184
+ ## Optional MCP integration (Beta)
130
185
 
131
- > [!WARNING]
132
- > **Separation of Concerns:** The MCP Bridge and experimental runtime orchestration tools are distributed separately in the `@contextos/mcp` package (Beta). The `--with-mcp` flag in the Core CLI is deprecated.
186
+ The MCP server is a separate beta package. It is not part of the stable `contextos-agents` core.
133
187
 
134
- Install the optional MCP Bridge:
188
+ Install it separately if you want to try the beta integration:
135
189
 
136
- `ash
190
+ ```bash
137
191
  npm install --save-dev @contextos/mcp
138
192
  npx contextos-mcp --dir .
139
- `
193
+ ```
140
194
 
141
- The MCP Bridge is read-only by default. Experimental execution tools require
142
- the explicit --enable-runtime flag and should only be used in trusted repositories.
195
+ The MCP server is read-only by default. Runtime execution remains experimental and is outside the stable core scope.
143
196
 
144
- ## Security — Third-Party Skills
197
+ ## Security - Third-Party Skills
145
198
 
146
- 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.
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.
147
200
 
148
201
  > [!CAUTION]
149
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.
@@ -154,4 +207,4 @@ We are open to pull requests! See [CONTRIBUTING.md](./CONTRIBUTING.md) for a ste
154
207
 
155
208
  ## License
156
209
 
157
- Distributed under the MIT License. You can freely use, modify, and distribute this code.
210
+ Distributed under the Apache License, Version 2.0. See [LICENSE](./LICENSE) and [NOTICE](./NOTICE) for details.
@@ -0,0 +1,129 @@
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
+ npx contextos-agents scan --staged --enforce || exit 1
21
+ ${HOOK_MARKER_END}`;
22
+
23
+ function installHook(cwd = process.cwd()) {
24
+ const hooksDir = findHooksDir(cwd);
25
+
26
+ if (!hooksDir) {
27
+ console.error('[ERROR] Not a Git repository or Git hooks directory not found.');
28
+ process.exit(1);
29
+ }
30
+
31
+ if (!fs.existsSync(hooksDir)) {
32
+ fs.mkdirSync(hooksDir, { recursive: true });
33
+ }
34
+
35
+ const hookFile = path.join(hooksDir, 'pre-commit');
36
+
37
+ if (fs.existsSync(hookFile)) {
38
+ const existing = fs.readFileSync(hookFile, 'utf8');
39
+
40
+ if (existing.includes(HOOK_MARKER_START)) {
41
+ // Replace existing block cleanly
42
+ const regex = new RegExp(`${HOOK_MARKER_START}[\\s\\S]*?${HOOK_MARKER_END}`);
43
+ const updated = existing.replace(regex, HOOK_PAYLOAD);
44
+ fs.writeFileSync(hookFile, updated, 'utf8');
45
+ console.log(`✓ ContextOS pre-commit hook updated in ${hookFile}`);
46
+ } else {
47
+ // Append while preserving user's existing hook script
48
+ const separator = existing.endsWith('\n') ? '\n' : '\n\n';
49
+ const updated = existing + separator + HOOK_PAYLOAD + '\n';
50
+ fs.writeFileSync(hookFile, updated, 'utf8');
51
+ console.log(`✓ ContextOS pre-commit hook appended to existing hook in ${hookFile}`);
52
+ }
53
+ } else {
54
+ // Fresh hook installation with shebang
55
+ const fresh = `#!/bin/sh\n\n${HOOK_PAYLOAD}\n`;
56
+ fs.writeFileSync(hookFile, fresh, 'utf8');
57
+ console.log(`✓ ContextOS pre-commit hook installed in ${hookFile}`);
58
+ }
59
+
60
+ try {
61
+ fs.chmodSync(hookFile, 0o755);
62
+ } catch {
63
+ // Best effort on platforms that do not support POSIX file modes
64
+ }
65
+ }
66
+
67
+ function uninstallHook(cwd = process.cwd()) {
68
+ const hooksDir = findHooksDir(cwd);
69
+
70
+ if (!hooksDir) {
71
+ console.error('[ERROR] Not a Git repository or Git hooks directory not found.');
72
+ process.exit(1);
73
+ }
74
+
75
+ const hookFile = path.join(hooksDir, 'pre-commit');
76
+
77
+ if (!fs.existsSync(hookFile)) {
78
+ console.log('✓ No pre-commit hook found to uninstall.');
79
+ return;
80
+ }
81
+
82
+ const existing = fs.readFileSync(hookFile, 'utf8');
83
+
84
+ if (!existing.includes(HOOK_MARKER_START)) {
85
+ console.log('✓ No ContextOS hook block detected in pre-commit hook.');
86
+ return;
87
+ }
88
+
89
+ // Remove exclusively the ContextOS demarcated block
90
+ const regex = new RegExp(`\\n?${HOOK_MARKER_START}[\\s\\S]*?${HOOK_MARKER_END}\\n?`, 'g');
91
+ const remaining = existing.replace(regex, '').trim();
92
+
93
+ // If file contains only shebang or is empty, remove it completely
94
+ if (!remaining || remaining === '#!/bin/sh' || remaining === '#!/bin/bash') {
95
+ fs.unlinkSync(hookFile);
96
+ console.log(`✓ ContextOS pre-commit hook uninstalled and empty ${hookFile} removed.`);
97
+ } else {
98
+ // Preserve remaining user scripts
99
+ fs.writeFileSync(hookFile, remaining + '\n', 'utf8');
100
+ console.log(`✓ ContextOS block removed from ${hookFile}; user commands preserved.`);
101
+ }
102
+ }
103
+
104
+ function hookCommand(args, flags) {
105
+ const subCommand = args[1] ? args[1].toLowerCase().trim() : null;
106
+
107
+ if (subCommand === 'install') {
108
+ installHook(process.cwd());
109
+ process.exit(0);
110
+ } else if (subCommand === 'uninstall') {
111
+ uninstallHook(process.cwd());
112
+ process.exit(0);
113
+ } else {
114
+ console.log('\nUsage: contextos hook <install|uninstall>\n');
115
+ console.log('Commands:');
116
+ console.log(' install Safely install pre-commit quality gate hook');
117
+ console.log(' uninstall Remove ContextOS block while preserving custom hooks\n');
118
+ process.exit(1);
119
+ }
120
+ }
121
+
122
+ module.exports = {
123
+ installHook,
124
+ uninstallHook,
125
+ hookCommand,
126
+ HOOK_MARKER_START,
127
+ HOOK_MARKER_END,
128
+ HOOK_PAYLOAD,
129
+ };
@@ -0,0 +1,70 @@
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 { runScan } = require('../lib/scan.js');
11
+
12
+ function scanCommand(args, flags) {
13
+ const isJson = flags.json || args.includes('--json');
14
+ const enforce = flags.enforce || args.includes('--enforce');
15
+ const checkPlaceholders = flags.placeholders || args.includes('--placeholders');
16
+ const checkSecrets = !args.includes('--no-secrets');
17
+
18
+ const scopeIdx = args.indexOf('--scope');
19
+ const scopeFile = scopeIdx !== -1 && args[scopeIdx + 1] ? args[scopeIdx + 1] : null;
20
+
21
+ const result = runScan({
22
+ cwd: process.cwd(),
23
+ staged: true,
24
+ secrets: checkSecrets,
25
+ placeholders: checkPlaceholders,
26
+ scope: scopeFile,
27
+ enforce,
28
+ });
29
+
30
+ if (isJson) {
31
+ console.log(JSON.stringify(result, null, 2));
32
+ process.exit(result.code);
33
+ }
34
+
35
+ console.log('\n══════════════════════════════════════════════════════');
36
+ console.log(' ContextOS Staged Index Scanner');
37
+ console.log('══════════════════════════════════════════════════════\n');
38
+
39
+ if (result.code === 2) {
40
+ console.error(` [ERROR] ${result.error || 'Scan incomplete'}\n`);
41
+ process.exit(2);
42
+ }
43
+
44
+ console.log(` Staged Files Scanned : ${result.stats.stagedFilesCount}`);
45
+ console.log(` Enforcement Mode : ${enforce ? 'STRICT (fails on findings)' : 'ADVISORY (warnings only)'}`);
46
+ console.log(` Violations Found : ${result.stats.violationsCount}\n`);
47
+
48
+ if (result.findings.length > 0) {
49
+ console.log(' Findings:');
50
+ for (const f of result.findings) {
51
+ const loc = f.line ? `${f.file}:${f.line}` : f.file;
52
+ const tag = f.severity === 'error' ? 'ERROR' : 'WARN';
53
+ console.log(` • [${f.ruleId}] [${tag}] ${loc}`);
54
+ console.log(` ${f.details}`);
55
+ }
56
+ console.log('');
57
+ }
58
+
59
+ console.log('──────────────────────────────────────────────────────');
60
+ if (result.ok) {
61
+ console.log(' RESULT: PASSED (No blocking violations in staged index)');
62
+ } else {
63
+ console.log(' RESULT: FAILED (Commit blocked due to staged violations)');
64
+ }
65
+ console.log('──────────────────────────────────────────────────────\n');
66
+
67
+ process.exit(result.code);
68
+ }
69
+
70
+ module.exports = scanCommand;
@@ -32,6 +32,7 @@ const {
32
32
  } = require('../lib/safe-writer.js');
33
33
 
34
34
  const pkg = require('../../package.json');
35
+ const profiles = require('../../.agents/profiles.js');
35
36
 
36
37
  /**
37
38
  * Collect all distributable files from the source .agents directory.
@@ -112,13 +113,9 @@ function planUpdate(projectDir, sourceAgentsDir, options = {}) {
112
113
  // Determine active profile exclusions if available
113
114
  let excludedSkills = [];
114
115
  try {
115
- const profilesPath = path.join(projectDir, '.agents', 'profiles.js');
116
- if (fs.existsSync(profilesPath)) {
117
- const profilesModule = require(profilesPath);
118
- const active = profilesModule.getActiveProfile(projectDir);
119
- if (active && Array.isArray(active.exclude_skills)) {
120
- excludedSkills = active.exclude_skills;
121
- }
116
+ const active = profiles.getActiveProfile(projectDir);
117
+ if (active && Array.isArray(active.exclude_skills)) {
118
+ excludedSkills = active.exclude_skills;
122
119
  }
123
120
  } catch {}
124
121
 
@@ -299,7 +296,9 @@ function runUpdate(projectDir = process.cwd(), options = {}) {
299
296
 
300
297
  // Re-compile if ctx.js exists and not skipped
301
298
  if (!options.skipCompile) {
302
- const ctxPath = path.join(projectDir, '.agents', 'ctx.js');
299
+ // Run the compiler shipped with this package. The project's .agents/ctx.js
300
+ // is user-controlled and must never be executed implicitly during update.
301
+ const ctxPath = path.join(sourceAgentsDir, 'ctx.js');
303
302
  if (fs.existsSync(ctxPath)) {
304
303
  try {
305
304
  const { execFileSync } = require('child_process');