File size: 15,269 Bytes
3fbbaab
 
 
 
 
 
 
e120a7d
 
3fbbaab
 
 
e18385d
 
3fbbaab
 
e18385d
6b5b728
 
 
e18385d
 
 
 
 
 
 
6b5b728
 
 
 
 
 
 
 
 
 
 
 
e18385d
 
 
 
 
 
 
 
 
 
 
6b5b728
 
 
e120a7d
 
6b5b728
 
 
 
e120a7d
6b5b728
 
 
e18385d
 
6b5b728
e18385d
 
 
 
6b5b728
f33924d
e120a7d
f33924d
 
 
e18385d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b5b728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e120a7d
6b5b728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e18385d
 
 
6b5b728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e18385d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e120a7d
e18385d
 
 
 
 
 
 
 
 
 
 
 
6b5b728
 
 
 
3fbbaab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b5b728
 
 
 
 
 
 
 
 
 
 
 
 
3fbbaab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b5b728
 
 
 
3fbbaab
 
 
 
 
 
 
e120a7d
3fbbaab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b5b728
 
 
 
e120a7d
6b5b728
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3fbbaab
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# Entity Onboarding

ctx treats skills, agents, MCP servers, and harnesses as wiki entities that can
be indexed, linked in the knowledge graph, and recommended from the same
surface. The important distinction is install behavior:

- Skills and agents are local Claude Code assets.
- MCP servers are recorded first, then installed only when the user opts in.
- Harnesses are recorded first. A harness describes the machinery around the
  model: runtime, tools, access boundaries, memory, verification, and approval
  policy. Adding one never executes upstream setup commands.

After adding any entity, drain the durable wiki queue when you want the local
runtime graph to see it immediately:

```bash

ctx-wiki-worker --wiki ~/.claude/skill-wiki --limit 1

ctx-scan-repo --repo . --recommend

```

If a persisted semantic vector index exists, that worker pass also runs a
best-effort incremental attach into `graphify-out/entity-overlays.jsonl` so the
new entity can connect to existing graph nodes without a full all-pairs
semantic rebuild. The wiki page remains the source of truth; if incremental
attach is skipped or fails, the worker still queues the normal incremental
graph export job.

## Updating the Graph and LLM Wiki

Use this sequence for every accepted skill, agent, MCP server, or harness
change. The graph and LLM-wiki are shippable artifacts, not scratch output, so
the update is treated like a release step.

1. Add or update the entity through the matching command:
   `ctx-skill-add`, `ctx-agent-add`, `ctx-mcp-add`, or `ctx-harness-add`.
2. If the entity already exists, read the update review. It lists changed
   fields, likely benefits, regressions, and security findings. Do not pass
   `--update-existing` until those findings are acceptable.
3. Run the security/cyber check below.
4. Park heavyweight graph artifacts locally before rebuilds:
   `python scripts/graph_artifact_guard.py park`. This keeps background Git
   integrations from repeatedly LFS-cleaning the full wiki tarball while it is
   still changing.
5. Drain the wiki queue for local runtime use:
   `ctx-wiki-worker --wiki ~/.claude/skill-wiki --limit 1`. This updates the
   wiki index, attempts incremental ANN graph attach when a vector index exists,
   and queues the normal incremental graph export.
6. Rebuild the curated wiki graph with `ctx-wiki-graphify` before shipping
   release artifacts or when you need a full graph/export reconciliation.
7. Repack `graph/wiki-graph.tar.gz` through the artifact promotion path:
   write a staged tarball, validate it, atomically promote it, and keep the
   generated `*.promotion.json` metadata with the previous/current hashes.
   Never commit local review reports or raw caches.
8. Refresh the bulk skill index when shipping large skill updates.
   This adds first-class `skill` nodes, skill pages under `entities/skills/`, install
   commands, duplicate hints, and metadata-only quality/security signals:

   ```bash

   python src/import_skills_sh_catalog.py --from-api-union <raw.json> \

     --catalog-out graph/<skill-index>.json.gz \

     --wiki-tar graph/wiki-graph.tar.gz \

     --update-wiki-tar

   ```
9. Refresh published counts with `python src/update_repo_stats.py`.
10. Verify the changed entity can be recommended through
   `ctx-scan-repo --repo . --recommend` or `ctx__recommend_bundle`.
11. Unpark and stage the graph artifacts once the release candidate is final:
    `python scripts/graph_artifact_guard.py unpark`, then `git add` the graph

    artifacts intentionally. Run `python scripts/graph_artifact_guard.py prune`

    after interrupted Git/LFS runs or after release staging.


The durable wiki worker drains `entity-upsert`, `graph-export`,
`skill-index-refresh`, `tar-refresh`, and `artifact-promotion` jobs. Use
`ctx-wiki-worker --wiki ~/.claude/skill-wiki --limit 1` for a controlled
single-job drain, or omit `--limit` to drain the ready queue.

For a manual attach dry-run against an existing vector index:

```bash

ctx-incremental-attach attach \

  --index-dir ~/.claude/skill-wiki/.embedding-cache/graph/vector-index \

  --overlay ~/.claude/skill-wiki/graphify-out/entity-overlays.jsonl \

  --node-id skill:fastapi-review \

  --type skill \

  --label fastapi-review \

  --text-file ~/.claude/skill-wiki/entities/skills/fastapi-review.md \

  --dry-run

```

Use `ctx-incremental-attach calibrate --graph ~/.claude/skill-wiki/graphify-out/graph.json`
to inspect the current graph's semantic and degree distributions before
changing attach thresholds.

Validate the attach quality before relying on a new ANN backend or changed
threshold:

```bash

ctx-incremental-shadow \

  --index-dir ~/.claude/skill-wiki/.embedding-cache/graph/vector-index \

  --graph ~/.claude/skill-wiki/graphify-out/graph.json \

  --sample-size 100 \

  --min-overlap 0.85

```

The shadow gate pretends sampled existing nodes are new, compares incremental
attach neighbors to batch graph semantic neighbors, reports precision/recall
for top 5/10/20, score deltas, and bad examples, then exits non-zero if
recall at the largest top-k is below the overlap floor.

## Repair Incremental Attach

If the worker says `incremental attach skipped (no vector index)`, build the
persisted semantic index once:

```bash

ctx-wiki-graphify \

  --wiki-dir ~/.claude/skill-wiki \

  --incremental \

  --graph-only \

  --semantic-vector-index numpy-flat

```

`numpy-flat` is exact and portable. `--semantic-vector-index auto` keeps the
portable exact backend at this graph size and can switch to the optional ANN
backend only above the configured node threshold. `hnswlib` is optional and
should be shadow-gated before release use.

Then process pending entity updates:

```bash

ctx-wiki-worker --wiki ~/.claude/skill-wiki

```

That is the supported "attach pending" flow today: the queue is durable, so
failed or skipped entity-upsert jobs remain visible to the worker and can be
retried after the index exists. Use manual `ctx-incremental-attach attach
--dry-run` for one-off debugging, not as the normal bulk path.

## Security and Cyber Check

Run this before applying `--update-existing`, before installing a harness with
approved commands, and before shipping a refreshed graph tarball.

- Inspect changed entity markdown and frontmatter for shell commands, setup
  commands, install commands, URLs, requested permissions, and model/provider
  access.
- Treat these as manual-review blockers: `curl | sh`, `wget | bash`,
  `Invoke-Expression`, broad `rm -rf`, `git reset --hard`, `chmod 777`, secret
  upload, disabled auth/TLS/sandboxing/audit/tests, or unpinned package sources.
- For MCP and harness updates, check network access, filesystem scope, auth
  material, command transports, and whether setup or verify commands execute
  remote code.
- Prefer dry-run first: `ctx-harness-install <slug> --dry-run` and
  `ctx-harness-install <slug> --update --dry-run`.
- If a candidate is useful but risky, document the safer install path or keep it
  as metadata instead of shipping it as an installed skill.

## Updating an Existing Entity

The add commands are non-destructive by default when the target skill, agent,
MCP server, or harness already exists. The first add attempt prints an update
review instead of replacing files. That review lists changed fields, expected
benefits, possible regressions, security findings, and a recommendation.

Use this flow for every entity type:

1. Run the normal add command.
2. If ctx prints `Existing <type> already exists`, read the benefits and risks.
3. Keep the current entity by doing nothing, or re-run with `--skip-existing`
   in batch jobs where you do not want reviews.
4. Apply the replacement only after review with `--update-existing`.
5. Drain the queue with `ctx-wiki-worker --wiki ~/.claude/skill-wiki --limit 1`
   for immediate local recommendation use, or rebuild with `ctx-wiki-graphify`
   when the update should be reconciled into shipped graph artifacts.

Examples:

```bash

ctx-skill-add --skill-path ./SKILL.md --name fastapi-review

ctx-skill-add --skill-path ./SKILL.md --name fastapi-review --update-existing



ctx-agent-add --agent-path ./code-reviewer.md --name code-reviewer

ctx-agent-add --agent-path ./code-reviewer.md --name code-reviewer --update-existing



ctx-mcp-add --from-json ./github-mcp.json

ctx-mcp-add --from-json ./github-mcp.json --update-existing



ctx-harness-add --from-json ./text-to-cad-harness.json

ctx-harness-add --from-json ./text-to-cad-harness.json --update-existing

```

`ctx-harness-install --update` is different: it refreshes an installed harness
checkout under `~/.claude/harnesses/<slug>`. Catalog entity replacement uses
`ctx-harness-add --update-existing`.

## Removing or Retiring an Entity

Removal has three separate meanings. First decide which one you need.

- **Catalog removal** stops ctx from showing the entity in the wiki, graph, and
  recommendations. Use the dashboard: `ctx-monitor serve`, open **Manage**,
  search for the slug and type, then choose **Delete selected**. This deletes
  the wiki page and queues an `entity-upsert` delete plus `graph-export` job.
- **Runtime unload** removes a currently loaded entity from the live manifest.
  Use the dashboard **Loaded** page. MCP unloads call the Claude MCP removal
  path when available; skill and agent unloads remove the manifest row.
- **Installed-file removal** is type-specific. Use
  `ctx-harness-install <slug> --uninstall` for harness checkouts,
  `ctx-mcp-uninstall <slug>` for installed MCPs, and `ctx-lifecycle archive`
  then `ctx-lifecycle purge` for stale local skills that should be deleted
  after the configured grace period.

After deleting an entity page, drain or rebuild before trusting recommendation
results:

```bash

ctx-wiki-worker --wiki ~/.claude/skill-wiki --limit 1

ctx-scan-repo --repo . --recommend

```

If you need an auditable manual flow without the browser, use the dashboard
local API only from loopback with the per-process monitor token printed into
the served page. The API route is `POST /api/entity/delete` with
`{"slug": "...", "entity_type": "skill|agent|mcp-server|harness"}`.

## Add a Skill

Use this when you have a local `SKILL.md` that should be installed under
`~/.claude/skills/<name>/SKILL.md` and mirrored into the wiki.

```bash

ctx-skill-add \

  --skill-path ./SKILL.md \

  --name fastapi-review

```

What happens:

1. The name is validated.
2. Intake checks run against the markdown.
3. The skill is copied into `~/.claude/skills/`.
4. A wiki page is created under `entities/skills/`.
5. The wiki index and log are updated.

## Add an Agent

Use this when you have a local Claude Code agent markdown file.

```bash

ctx-agent-add \

  --agent-path ./code-reviewer.md \

  --name code-reviewer

```

Batch-add every top-level `.md` file in a directory:

```bash

ctx-agent-add --scan-dir ./agents --skip-existing

```

Agents are copied into `~/.claude/agents/` and mirrored into
`entities/agents/`. Re-run `ctx-wiki-graphify` after adding agents if you want
graph recommendations to include them.

## Add an MCP Server

Use this when you want the MCP server available as a recommendation before
installing it into a host.

Create `github-mcp.json`:

```json

{

  "name": "GitHub MCP",

  "slug": "github-mcp",

  "description": "MCP server for GitHub repository and issue workflows.",

  "github_url": "https://github.com/modelcontextprotocol/servers",

  "sources": ["manual"],

  "tags": ["github", "automation", "repository"],

  "transports": ["stdio"]

}

```

Add it:

```bash

ctx-mcp-add --from-json ./github-mcp.json

```

MCP pages live under `entities/mcp-servers/<shard>/<slug>.md`. The add command
detects existing pages by slug and, when possible, canonical GitHub URL. If a
match exists, ctx prints the update review and skips replacement unless
`--update-existing` is passed.

## Add a Harness

Use this when a repo provides the runtime around a model rather than just a
tool. Harness examples include coding-agent loops, CAD-generation runtimes,
browser-automation runners, evaluation loops, and local-model workbenches.

Example: add `earthtojake/text-to-cad` as a harness recommendation.

```bash

ctx-harness-add \

  --repo https://github.com/earthtojake/text-to-cad \

  --name "Text to CAD" \

  --description "Harness for turning text prompts into CAD artifacts." \

  --tag cad --tag 3d --tag automation \

  --model-provider openai \

  --runtime python \

  --capability "Generate CAD artifacts from natural language" \

  --setup-command "pip install -e ." \

  --verify-command "pytest"

```

Or load one JSON record:

```json

{

  "repo_url": "https://github.com/earthtojake/text-to-cad",

  "name": "Text to CAD",

  "description": "Harness for turning text prompts into CAD artifacts.",

  "tags": ["cad", "3d", "automation"],

  "model_providers": ["openai"],

  "runtimes": ["python"],

  "capabilities": ["Generate CAD artifacts from natural language"],

  "setup_commands": ["pip install -e ."],

  "verify_commands": ["pytest"],

  "sources": ["manual"]

}

```

```bash

ctx-harness-add --from-json ./text-to-cad-harness.json

```

Harness pages live under `entities/harnesses/<slug>.md`. Setup and verification
commands are documentation only; ctx records them so the user can inspect and
decide before running anything.

To inspect and install a harness:

```bash

ctx-harness-install text-to-cad --dry-run

ctx-harness-install text-to-cad

ctx-harness-install text-to-cad --update --dry-run

ctx-harness-install text-to-cad --uninstall --dry-run

```

The installer clones or copies the harness into `~/.claude/harnesses/<slug>` and
writes `~/.claude/harness-installs/<slug>.json`. It does not run setup commands
unless you pass `--approve-commands`, and it does not run verification commands
unless you also pass `--run-verify`.

```bash

ctx-harness-install text-to-cad --approve-commands --run-verify

ctx-harness-install text-to-cad --update --approve-commands --run-verify

ctx-harness-install text-to-cad --uninstall

ctx-harness-install text-to-cad --uninstall --keep-files

```

## Initialize Model Choice

During setup, record whether you use Claude Code or your own model. Plain
`ctx-init` starts a small wizard when it is attached to an interactive
terminal; use `ctx-init --wizard` to force the prompts, or pass explicit flags
such as `--model-mode skip` for non-interactive automation.

```bash

ctx-init

ctx-init --wizard

ctx-init --model-mode skip

```

For Claude Code:

```bash

ctx-init --model-mode claude-code --goal "maintain a FastAPI service"

```

For a custom model:

```bash

ctx-init \

  --model-mode custom \

  --model openai/gpt-5.5 \

  --goal "build CAD artifacts from text prompts"

```

Add `--validate-model` only when you want `ctx-init` to make one small provider
call. Without that flag, setup writes `~/.claude/ctx-model-profile.json` and
prints harness recommendations without calling the model.