@minhpnq1807/contextos 0.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.
- package/.agents/plugins/marketplace.json +20 -0
- package/CHANGELOG.md +16 -0
- package/DEMO.md +57 -0
- package/LICENSE +21 -0
- package/README.md +388 -0
- package/bin/ctx.js +261 -0
- package/package.json +63 -0
- package/plugins/ctx/.codex-plugin/plugin.json +35 -0
- package/plugins/ctx/.mcp.json +10 -0
- package/plugins/ctx/bin/on-prompt.js +25 -0
- package/plugins/ctx/bin/on-session-start.js +22 -0
- package/plugins/ctx/bin/on-stop.js +17 -0
- package/plugins/ctx/hooks.json +35 -0
- package/plugins/ctx/lib/analyzer.js +321 -0
- package/plugins/ctx/lib/ctx-mcp-client.js +52 -0
- package/plugins/ctx/lib/embedding-scorer.js +248 -0
- package/plugins/ctx/lib/file-embedding-retriever.js +116 -0
- package/plugins/ctx/lib/fs-utils.js +28 -0
- package/plugins/ctx/lib/global-hooks.js +110 -0
- package/plugins/ctx/lib/graph-retriever.js +226 -0
- package/plugins/ctx/lib/hook-io.js +65 -0
- package/plugins/ctx/lib/import-graph.js +124 -0
- package/plugins/ctx/lib/measure.js +263 -0
- package/plugins/ctx/lib/prompt-hook.js +72 -0
- package/plugins/ctx/lib/reader.js +57 -0
- package/plugins/ctx/lib/reporter.js +105 -0
- package/plugins/ctx/lib/scheduler.js +45 -0
- package/plugins/ctx/lib/score-context.js +55 -0
- package/plugins/ctx/lib/stats.js +127 -0
- package/plugins/ctx/lib/stop-hook.js +32 -0
- package/plugins/ctx/mcp/contextos-server.js +50 -0
- package/plugins/ctx/mcp/server.js +83 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "contextos",
|
|
3
|
+
"interface": {
|
|
4
|
+
"displayName": "ContextOS"
|
|
5
|
+
},
|
|
6
|
+
"plugins": [
|
|
7
|
+
{
|
|
8
|
+
"name": "ctx",
|
|
9
|
+
"source": {
|
|
10
|
+
"source": "local",
|
|
11
|
+
"path": "./plugins/ctx"
|
|
12
|
+
},
|
|
13
|
+
"policy": {
|
|
14
|
+
"installation": "AVAILABLE",
|
|
15
|
+
"authentication": "ON_INSTALL"
|
|
16
|
+
},
|
|
17
|
+
"category": "Coding"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
Initial public release.
|
|
6
|
+
|
|
7
|
+
- Adds the `ctx` Codex plugin installer.
|
|
8
|
+
- Registers `ctx-mcp` for semantic AGENTS.md rule scoring.
|
|
9
|
+
- Injects prompt-specific ContextOS rules and suggested files through Codex hooks.
|
|
10
|
+
- Reports Stop-hook rule outcomes as `followed`, `ignored`, or `unknown`.
|
|
11
|
+
- Provides `ctx debug`, `ctx report`, `ctx evidence`, `ctx stats`, and `ctx embeddings warm`.
|
|
12
|
+
- Includes CI checks for plugin validation, unit tests, and MCP protocol/performance smoke.
|
|
13
|
+
|
|
14
|
+
Known release note:
|
|
15
|
+
|
|
16
|
+
- `npm audit` currently reports transitive dependency vulnerabilities in the local embedding stack. They are not fixed with `npm audit fix --force` because that can introduce breaking dependency upgrades. Revisit before a wider public launch.
|
package/DEMO.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# ContextOS Demo Script
|
|
2
|
+
|
|
3
|
+
Use this script to record the README demo GIF or terminal clip.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @minhpnq1807/contextos
|
|
9
|
+
ctx install
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Restart Codex after install.
|
|
13
|
+
|
|
14
|
+
## Recording Flow
|
|
15
|
+
|
|
16
|
+
1. Open a project with an `AGENTS.md`.
|
|
17
|
+
2. Start Codex.
|
|
18
|
+
3. Submit:
|
|
19
|
+
|
|
20
|
+
```text
|
|
21
|
+
kiểm tra flow kiểm duyệt upload
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
4. Show the `hook context` block:
|
|
25
|
+
|
|
26
|
+
```text
|
|
27
|
+
## Critical ContextOS rules
|
|
28
|
+
...
|
|
29
|
+
## Suggested files to check
|
|
30
|
+
...
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
5. Let the task finish so the Stop hook runs.
|
|
34
|
+
6. Show:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
ctx evidence
|
|
38
|
+
ctx stats
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Expected Talking Points
|
|
42
|
+
|
|
43
|
+
- ContextOS does not replace Codex or wrap the CLI.
|
|
44
|
+
- It runs as a Codex plugin with hooks plus `ctx-mcp`.
|
|
45
|
+
- It uses local embeddings to bridge vocabulary mismatch such as `kiểm duyệt` and `moderation`.
|
|
46
|
+
- It reports `followed`, `ignored`, and `unknown` outcomes after the task.
|
|
47
|
+
|
|
48
|
+
## Current Release Checks
|
|
49
|
+
|
|
50
|
+
Run before recording:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npm run validate:plugin
|
|
54
|
+
npm test
|
|
55
|
+
npm run test:mcp
|
|
56
|
+
npm pack --dry-run
|
|
57
|
+
```
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ContextOS
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
# ContextOS
|
|
2
|
+
|
|
3
|
+
ContextOS (`ctx`) is a Codex companion plugin for task-aware project context.
|
|
4
|
+
|
|
5
|
+
It reads `AGENTS.md` guidance, scores the rules against the current prompt, suggests relevant files, records what context would have been injected, and reports lightweight compliance evidence after the task finishes.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @minhpnq1807/contextos
|
|
11
|
+
ctx install
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Restart Codex after installing, then use Codex normally. ContextOS runs through Codex hooks and the `ctx-mcp` MCP server.
|
|
15
|
+
|
|
16
|
+
You can also run without a global install:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npx @minhpnq1807/contextos install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Demo Flow
|
|
23
|
+
|
|
24
|
+
Use this flow for a 60-second demo recording:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
ctx install
|
|
28
|
+
codex
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Prompt Codex:
|
|
32
|
+
|
|
33
|
+
```text
|
|
34
|
+
kiểm tra flow kiểm duyệt upload
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Expected result:
|
|
38
|
+
|
|
39
|
+
- `UserPromptSubmit` injects relevant AGENTS.md rules.
|
|
40
|
+
- ContextOS suggests upload/moderation files.
|
|
41
|
+
- `Stop` prints a ContextOS report with rule outcomes.
|
|
42
|
+
- `ctx evidence` shows the specific evidence behind the last report.
|
|
43
|
+
|
|
44
|
+
## Before / After
|
|
45
|
+
|
|
46
|
+
Without ContextOS, Codex receives the full AGENTS.md context passively and can miss task-relevant rules in large context windows.
|
|
47
|
+
|
|
48
|
+
With ContextOS, each prompt gets a compact block:
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
## Critical ContextOS rules
|
|
52
|
+
- Use code-review-graph before reading files.
|
|
53
|
+
- All shell commands must run as minh_dev.
|
|
54
|
+
|
|
55
|
+
## Suggested files to check
|
|
56
|
+
- services/content-service/src/infrastructure/services/content-moderation.service.ts
|
|
57
|
+
- webapp/src/features/dashboard/components/moderation-status-badge.tsx
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## What It Does
|
|
61
|
+
|
|
62
|
+
- Hooks into Codex `UserPromptSubmit`, `SessionStart`, and `Stop`.
|
|
63
|
+
- Registers a `ctx-mcp` MCP server that owns model loading and semantic scoring.
|
|
64
|
+
- Reads the active `AGENTS.md` chain for the current workspace.
|
|
65
|
+
- Scores rules by relevance to the user prompt.
|
|
66
|
+
- Finds likely relevant files with a hybrid retriever:
|
|
67
|
+
- first, local prompt/file heuristics create seed candidates;
|
|
68
|
+
- then, if `.code-review-graph/graph.db` exists, ContextOS queries `code-review-graph` semantic search and re-ranks graph-backed matches;
|
|
69
|
+
- if no graph exists or graph lookup times out, it falls back to local heuristics.
|
|
70
|
+
- Stores scheduled context and hook telemetry under `$CODEX_HOME/contextos`.
|
|
71
|
+
- Reports rule outcomes as `followed`, `ignored`, or `unknown`.
|
|
72
|
+
- Injects `additionalContext` into Codex by default.
|
|
73
|
+
|
|
74
|
+
By default, ContextOS runs in injection mode. It adds task-relevant rules and files to the model context so the agent has the right project guidance at the moment it starts working.
|
|
75
|
+
|
|
76
|
+
## Install
|
|
77
|
+
|
|
78
|
+
From the package:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
npx @minhpnq1807/contextos install
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
From this repository during local development:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
rtk node bin/ctx.js install
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`ctx install` does three things:
|
|
91
|
+
|
|
92
|
+
1. Copies this package into `$CODEX_HOME/marketplaces/contextos`.
|
|
93
|
+
2. Registers and installs `ctx@contextos` through Codex plugin marketplace commands.
|
|
94
|
+
3. Downloads and caches the required local MiniLM embedding model under `$CODEX_HOME/contextos/models`.
|
|
95
|
+
4. Warms `$CODEX_HOME/contextos/embeddings.db` for AGENTS rules and project file paths.
|
|
96
|
+
5. Registers the `ctx-mcp` MCP server and merges ContextOS global hooks into `$CODEX_HOME/hooks.json`.
|
|
97
|
+
|
|
98
|
+
Restart Codex after installing.
|
|
99
|
+
|
|
100
|
+
The embedding model is mandatory. `ctx install` intentionally fails if the model cannot be prepared, because otherwise the first prompt hook would have to cold-load or download the model.
|
|
101
|
+
|
|
102
|
+
## Modes
|
|
103
|
+
|
|
104
|
+
Injection mode is the default:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
ctx install
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
In injection mode, ContextOS analyzes each prompt, stores runtime data, and returns task-relevant `additionalContext` to Codex. Codex may display that injected context in the UI.
|
|
111
|
+
|
|
112
|
+
Quiet mode:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
ctx install --quiet
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Quiet mode analyzes and measures prompts but returns an empty `additionalContext`, so Codex does not show a `hook context` block.
|
|
119
|
+
|
|
120
|
+
Explicit injection mode is also accepted:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
ctx install --inject
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Development copy mode:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
ctx install --copy
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Copies only the plugin payload into `$CODEX_HOME/plugins/ctx`. This is mostly for local experiments.
|
|
133
|
+
|
|
134
|
+
## Troubleshooting
|
|
135
|
+
|
|
136
|
+
### `ctx-mcp bridge socket not found`
|
|
137
|
+
|
|
138
|
+
Restart Codex after `ctx install`. The bridge socket is owned by the long-running `ctx-mcp` MCP server, so it exists only after Codex starts the server.
|
|
139
|
+
|
|
140
|
+
### `ContextOS model cache missing`
|
|
141
|
+
|
|
142
|
+
Run:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
ctx embeddings warm -- "kiểm tra flow kiểm duyệt upload"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Then restart Codex.
|
|
149
|
+
|
|
150
|
+
### No report found
|
|
151
|
+
|
|
152
|
+
Run at least one Codex task with ContextOS enabled and let the task finish so the `Stop` hook can write `last-report.json`.
|
|
153
|
+
|
|
154
|
+
### `Average efficiency: unknown`
|
|
155
|
+
|
|
156
|
+
ContextOS only reports efficiency when git diff/status contains concrete evidence. Runtime-only rules, such as tool usage order, are shown as `unknown` unless they leave evidence in changed files.
|
|
157
|
+
|
|
158
|
+
## Commands
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
ctx install
|
|
162
|
+
ctx install --quiet
|
|
163
|
+
ctx install --inject
|
|
164
|
+
ctx install --copy
|
|
165
|
+
ctx debug -- "fix auth login bug"
|
|
166
|
+
ctx report
|
|
167
|
+
ctx evidence
|
|
168
|
+
ctx stats
|
|
169
|
+
ctx embeddings warm -- "fix upload moderation flow"
|
|
170
|
+
ctx --version
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### `ctx debug`
|
|
174
|
+
|
|
175
|
+
Runs ContextOS scheduling locally for a fake task and prints rule scores plus the final context that would be injected.
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
ctx debug -- "fix upload moderation flow"
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### `ctx report`
|
|
182
|
+
|
|
183
|
+
Shows the last Stop-hook report.
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
ctx report
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### `ctx evidence`
|
|
190
|
+
|
|
191
|
+
Shows detailed rule-by-rule evidence for the last report:
|
|
192
|
+
|
|
193
|
+
- status
|
|
194
|
+
- rule text
|
|
195
|
+
- source file
|
|
196
|
+
- score
|
|
197
|
+
- evidence reason
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
ctx evidence
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### `ctx stats`
|
|
204
|
+
|
|
205
|
+
Shows aggregate runtime stats:
|
|
206
|
+
|
|
207
|
+
- prompts analyzed
|
|
208
|
+
- reports generated
|
|
209
|
+
- injected vs quiet prompts
|
|
210
|
+
- average prompt analysis time
|
|
211
|
+
- average efficiency
|
|
212
|
+
- followed / ignored / unknown counts
|
|
213
|
+
- hook event counts
|
|
214
|
+
- last prompt and suggested files
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
ctx stats
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### `ctx embeddings`
|
|
221
|
+
|
|
222
|
+
Builds local embeddings for semantic rule scoring.
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
ctx embeddings warm -- "fix upload moderation flow"
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
`warm` downloads/loads the local `Xenova/all-MiniLM-L6-v2` model if needed and stores rule/prompt vectors plus project file path vectors in `$CODEX_HOME/contextos/embeddings.db`.
|
|
229
|
+
|
|
230
|
+
## Runtime Files
|
|
231
|
+
|
|
232
|
+
ContextOS writes runtime data to:
|
|
233
|
+
|
|
234
|
+
```text
|
|
235
|
+
$CODEX_HOME/contextos/
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Important files:
|
|
239
|
+
|
|
240
|
+
```text
|
|
241
|
+
debug.log hook event log
|
|
242
|
+
ctx-mcp.sock private hook bridge owned by ctx-mcp
|
|
243
|
+
last-prompt-context.json latest scheduled context
|
|
244
|
+
last-report.json latest compliance report
|
|
245
|
+
prompt-history.jsonl prompt scheduling history
|
|
246
|
+
report-history.jsonl report history
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
These files are local telemetry only. Hooks do not make network calls.
|
|
250
|
+
|
|
251
|
+
## Project Understanding
|
|
252
|
+
|
|
253
|
+
ContextOS does not try to replace `code-review-graph`. It uses it as the project-understanding layer when the target repo has already built a graph database.
|
|
254
|
+
|
|
255
|
+
For file suggestions, ContextOS now runs a local RAG-style retrieval pass:
|
|
256
|
+
|
|
257
|
+
```text
|
|
258
|
+
prompt
|
|
259
|
+
-> UserPromptSubmit hook calls ctx-mcp bridge
|
|
260
|
+
-> ctx-mcp reads AGENTS.md and scores rules with local MiniLM
|
|
261
|
+
-> run file-path embedding search against embeddings.db for semantic file candidates
|
|
262
|
+
-> scan filenames for initial seed candidates
|
|
263
|
+
-> expand candidates through relative import graph links
|
|
264
|
+
-> query code-review-graph semantic_search_nodes with seed entity names
|
|
265
|
+
-> merge graph matches with heuristic matches
|
|
266
|
+
-> inject top suggested files with graph evidence reasons
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
This keeps the hook fast and local while still using graph semantics when available. The graph search path is visible in runtime data through file reasons such as `graph:content-moderation.service`.
|
|
270
|
+
|
|
271
|
+
Configuration:
|
|
272
|
+
|
|
273
|
+
```text
|
|
274
|
+
CONTEXTOS_GRAPH_RETRIEVAL=0 disable graph-backed file retrieval
|
|
275
|
+
CONTEXTOS_GRAPH_TIMEOUT_MS=80 graph lookup timeout
|
|
276
|
+
CONTEXTOS_CRG_PYTHON=/path/python Python with code_review_graph installed
|
|
277
|
+
CONTEXTOS_EMBEDDINGS=0 disable embedding rule scoring
|
|
278
|
+
CONTEXTOS_MCP_BRIDGE_TIMEOUT_MS=1000 ctx-mcp hook bridge timeout
|
|
279
|
+
CONTEXTOS_EMBEDDING_TIMEOUT_MS=800 embedding scoring timeout inside ctx-mcp/debug
|
|
280
|
+
CONTEXTOS_FILE_EMBEDDINGS=0 disable file-path embedding retrieval
|
|
281
|
+
CONTEXTOS_FILE_EMBEDDING_TIMEOUT_MS=80 file embedding lookup timeout
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Hook Flow
|
|
285
|
+
|
|
286
|
+
```text
|
|
287
|
+
Codex prompt
|
|
288
|
+
-> UserPromptSubmit hook
|
|
289
|
+
-> call ctx-mcp through private bridge
|
|
290
|
+
-> ctx-mcp scores rules and relevant files
|
|
291
|
+
-> write last-prompt-context.json
|
|
292
|
+
-> return additionalContext unless quiet mode is enabled
|
|
293
|
+
-> Codex runs task
|
|
294
|
+
-> Stop hook
|
|
295
|
+
-> read git diff/status
|
|
296
|
+
-> measure rule evidence
|
|
297
|
+
-> write last-report.json and report-history.jsonl
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
## Rule Outcomes
|
|
301
|
+
|
|
302
|
+
ContextOS uses a heuristic diff-based measurement.
|
|
303
|
+
|
|
304
|
+
```text
|
|
305
|
+
followed = evidence in the diff suggests the rule was applied
|
|
306
|
+
ignored = evidence in the diff suggests the rule was violated
|
|
307
|
+
unknown = the rule was relevant, but the diff does not prove either way
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Example `unknown`: a rule says shell commands must run as `minh_dev`, but git diff does not record shell user identity. ContextOS cannot prove the rule was followed from code changes alone.
|
|
311
|
+
|
|
312
|
+
## Development
|
|
313
|
+
|
|
314
|
+
Install dependencies:
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
rtk npm install
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Run tests:
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
rtk npm test
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
Run MCP protocol and warm performance smoke:
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
rtk npm run test:mcp
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Validate plugin schema:
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
rtk npm run validate:plugin
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
Check the npm package contents:
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
npm pack --dry-run
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
Smoke test prompt hook:
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
printf '%s' '{"prompt":"fix auth validation","cwd":"'$PWD'","hook_event_name":"UserPromptSubmit"}' \
|
|
348
|
+
| node plugins/ctx/bin/on-prompt.js
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Smoke test Stop hook:
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
printf '%s' '{"cwd":"'$PWD'","hook_event_name":"Stop"}' \
|
|
355
|
+
| node plugins/ctx/bin/on-stop.js
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
## Project Layout
|
|
359
|
+
|
|
360
|
+
```text
|
|
361
|
+
bin/ctx.js CLI
|
|
362
|
+
plugins/ctx/hooks.json plugin hook declaration
|
|
363
|
+
plugins/ctx/bin/ hook entrypoints
|
|
364
|
+
plugins/ctx/mcp/server.js ctx-mcp MCP server and hook bridge
|
|
365
|
+
plugins/ctx/lib/reader.js AGENTS.md reader
|
|
366
|
+
plugins/ctx/lib/analyzer.js rule/file scoring
|
|
367
|
+
plugins/ctx/lib/embedding-scorer.js local embedding rule scoring
|
|
368
|
+
plugins/ctx/lib/score-context.js shared MCP scoring pipeline
|
|
369
|
+
plugins/ctx/lib/ctx-mcp-client.js hook bridge client
|
|
370
|
+
plugins/ctx/lib/import-graph.js relative import graph traversal
|
|
371
|
+
plugins/ctx/lib/graph-retriever.js code-review-graph retrieval bridge
|
|
372
|
+
plugins/ctx/lib/scheduler.js context layout
|
|
373
|
+
plugins/ctx/lib/measure.js diff-based compliance checks
|
|
374
|
+
plugins/ctx/lib/reporter.js report/evidence formatting
|
|
375
|
+
plugins/ctx/lib/stats.js runtime stats
|
|
376
|
+
plugins/ctx/lib/global-hooks.js Codex global hook installer
|
|
377
|
+
test/ unit tests
|
|
378
|
+
contextos-plan.jsx implementation plan/reference
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
## Limitations
|
|
382
|
+
|
|
383
|
+
- Codex CLI only.
|
|
384
|
+
- Local marketplace plugin hooks may not fire reliably in current Codex builds, so `ctx install` also installs global hooks.
|
|
385
|
+
- Injection mode may show a visible `hook context` block in Codex.
|
|
386
|
+
- Quiet mode does not inject context into the model; it only records and measures.
|
|
387
|
+
- Compliance is heuristic and mostly based on git diff/status.
|
|
388
|
+
- Some rules can only be `unknown` unless ContextOS records richer telemetry such as tool calls or shell command metadata.
|