Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .cursor/hooks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": 1,
"hooks": {
"preToolUse": [
{
"command": "context-mode hook cursor pretooluse",
"matcher": "Shell|Read|Grep|WebFetch|mcp_web_fetch|mcp_fetch_tool|Task|MCP:ctx_execute|MCP:ctx_execute_file|MCP:ctx_batch_execute"
}
],
"postToolUse": [
{
"command": "context-mode hook cursor posttooluse"
}
],
"stop": [
{
"command": "context-mode hook cursor stop"
}
]
}
}
7 changes: 7 additions & 0 deletions .cursor/mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"mcpServers": {
"context-mode": {
"command": "context-mode"
}
}
}
85 changes: 85 additions & 0 deletions .cursor/rules/context-mode.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
description: context-mode routing rules for context window protection
alwaysApply: true
---

# context-mode

Raw tool output floods context window. Use context-mode MCP tools to keep raw data in sandbox.

## Think in Code — MANDATORY

Analyze/count/filter/compare/search/parse/transform data: **write code** via `ctx_execute(language, code)`, `console.log()` only the answer. Do NOT read raw data into context. PROGRAM the analysis, not COMPUTE it. Pure JavaScript — Node.js built-ins only (`fs`, `path`, `child_process`). `try/catch`, handle `null`/`undefined`. One script replaces ten tool calls.

## Tool Selection

0. **MEMORY**: `ctx_search(sort: "timeline")` — after resume, check prior context before asking user.
1. **GATHER**: `ctx_batch_execute(commands, queries)` — runs all commands, auto-indexes, searches. ONE call replaces many steps.
2. **FOLLOW-UP**: `ctx_search(queries: ["q1", "q2", ...])` — all follow-up questions, ONE call (default relevance mode).
3. **PROCESSING**: `ctx_execute(language, code)` | `ctx_execute_file(path, language, code)` — sandbox, only stdout enters context.
4. **WEB**: `ctx_fetch_and_index(url)` then `ctx_search(queries)` — never dump raw HTML.
5. **INDEX**: `ctx_index(content, source)` — store in FTS5 for later search.

## Parallel I/O batches

For multi-URL fetches or multi-API calls, **always** include `concurrency: N` (1-8):

- `ctx_batch_execute(commands: [3+ network commands], concurrency: 5)` — gh, curl, dig, docker inspect, multi-region cloud queries
- `ctx_fetch_and_index(requests: [{url, source}, ...], concurrency: 5)` — multi-URL batch fetch

**Use concurrency 4-8** for I/O-bound work (network calls, API queries). **Keep concurrency 1** for CPU-bound (npm test, build, lint) or commands sharing state (ports, lock files, same-repo writes).

GitHub API rate-limit: cap at 4 for `gh` calls.

## Auth (with `~/.tokens`)

- GitHub: use `gh` when logged in; else `GITHUB_TOKEN` — see `gauntletci.mdc` / `auth-tokens.mdc`.
- Other keys: read from `%USERPROFILE%\.tokens` inside `ctx_execute` only; set env vars for the subprocess; **never** index or echo token file contents.
- Do not put secret paths or values in `mcp.json`.

## Forbidden Actions

- DO NOT use Bash for >20 lines output — use `ctx_execute` or `ctx_batch_execute`.
- DO NOT use Read for analysis — use `ctx_execute_file`. Read IS correct for Edit.
- DO NOT use WebFetch — use `ctx_fetch_and_index`.
- DO NOT use curl/wget in terminal — use `ctx_fetch_and_index`.
- Bash ONLY for git, mkdir, rm, mv, navigation, short commands.
- DO NOT use `ctx_execute`/`ctx_execute_file` to create/modify files. ctx_execute is for analysis and computation only.

## File Writing Policy

ALWAYS use native file editing tools to create/modify files. NEVER use `ctx_execute`, `ctx_execute_file`, or Bash to write file content.

## Output

Terse like caveman. Technical substance exact. Only fluff die.
Drop: articles, filler (just/really/basically), pleasantries, hedging. Fragments OK. Short synonyms. Code unchanged.
Pattern: [thing] [action] [reason]. [next step]. Auto-expand for: security warnings, irreversible actions, user confusion.
Write artifacts to FILES — never inline. Return: file path + 1-line description.

## Session Continuity

Skills, roles, and decisions persist for the entire session. Do not abandon them as the conversation grows.

## Memory

Session history is persistent and searchable. On resume, search BEFORE asking the user:

| Need | Command |
|------|---------|
| What did we decide? | `ctx_search(queries: ["decision"], source: "decision", sort: "timeline")` |
| What constraints exist? | `ctx_search(queries: ["constraint"], source: "constraint")` |

DO NOT ask "what were we working on?" — SEARCH FIRST.
If search returns 0 results, proceed as a fresh session.

## ctx Commands

| Command | Action |
|---------|--------|
| `ctx stats` | Call ctx_stats MCP tool, display full output verbatim. |
| `ctx doctor` | Call ctx_doctor MCP tool, run returned shell command, display as checklist. |
| `ctx upgrade` | Call ctx_upgrade MCP tool, run returned shell command, display as checklist. |
| `ctx purge` | Call ctx_purge MCP tool with confirm: true. Warn user this is irreversible. |

After /clear or /compact: knowledge base and session stats preserved. Use `ctx purge` to start fresh.
Loading
Loading