Skip to content
Open
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
10 changes: 10 additions & 0 deletions .eca-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@
"icon": "🪨",
"featured": false
},
{
"name": "subteam",
"description": "Coordinator-led feature workflow with prefixed planning, critique, implementation, and validation subagents plus hook-assisted rendezvous",
"source": "plugins/subteam",
"category": "Workflow",
"tags": ["subagent", "workflow", "planning", "validation", "hooks"],
"author": "editor-code-assistant",
"icon": "🧑‍🤝‍🧑",
"featured": false
},
{
"name": "allium",
"description": "Durable behavioural intent for ECA: capture what software is meant to do, surface ambiguity, spot spec-code drift, and generate tests; optional Allium CLI adds validation and analysis",
Expand Down
5 changes: 4 additions & 1 deletion plugins/context-mode/.mcp.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"mcpServers": {
"context-mode": {
"command": "${plugin:root}/hooks/ctx-server.sh"
"command": "${plugin:root}/hooks/ctx-server.sh",
"env": {
"CONTEXT_MODE_PLATFORM": "eca"
}
}
}
}
43 changes: 30 additions & 13 deletions plugins/context-mode/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# context-mode

> ECA plugin for [context-mode](https://github.com/mksglu/context-mode) — saves up to 98% of your context window by routing large output through a sandboxed execution engine with BM25-indexed search and session continuity across compactions.
> ECA plugin for [context-mode](https://github.com/mksglu/context-mode) — saves context by routing large output through sandboxed execution, BM25-indexed search, and session continuity hooks.

## What it does

- **Sandboxed execution** — `ctx_execute` and `ctx_execute_file` run code in an isolated subprocess; only `console.log()` output enters context
- **FTS5 knowledge base** — `ctx_batch_execute` auto-indexes all command output; `ctx_search` retrieves only the relevant chunks
- **Session continuity** — every file edit, git operation, decision, and error is captured to SQLite; after compaction the agent resumes with full context restored
- **Routing enforcement** — a `preToolCall` hook intercepts `eca__shell_command` / `eca__read_file` / `eca__grep` and nudges the agent toward sandbox tools; `curl`/`wget` are blocked
- **Sandboxed execution** — `ctx_execute` and `ctx_execute_file` run code in an isolated subprocess; only intentional stdout enters context
- **FTS5 knowledge base** — `ctx_batch_execute` auto-indexes command output; `ctx_search` retrieves only relevant chunks
- **Session continuity** — ECA hooks capture prompts/tool calls and preserve resume snapshots across compaction through this plugin's local adapter bridge
- **Routing policy** — rules and skills steer large shell/read/grep work toward sandbox tools; the `preToolCall` hook denies direct `curl`/`wget`-style fetches through `hooks/ctx-eca-adapter.mjs`

## Prerequisites

Install the `context-mode` npm package. With [mise](https://mise.jdx.dev/):
Install the `context-mode` npm package globally. The plugin supplies its own ECA hook adapter bridge, so it does not require an upstream ECA hook dispatcher.

With [mise](https://mise.jdx.dev/):

```toml
# ~/.config/mise/config.toml
Expand All @@ -25,6 +27,8 @@ Or globally:
npm install -g context-mode
```

The MCP server is started through `hooks/ctx-server.sh` so the package can keep its sandbox runtime setup intact.

## Commands

| Command | Description |
Expand All @@ -41,35 +45,48 @@ npm install -g context-mode
| `context-mode__ctx_execute` | Run code in a sandbox (JS, TS, Python, Shell, Ruby, Go, Rust, Perl) |
| `context-mode__ctx_execute_file` | Load a file into `FILE_CONTENT` and analyze it in a sandbox |
| `context-mode__ctx_batch_execute` | Run multiple commands, auto-index output, search results — one call |
| `context-mode__ctx_index` | Store content in the FTS5 knowledge base |
| `context-mode__ctx_index` | Store file/directory content in the FTS5 knowledge base |
| `context-mode__ctx_search` | BM25 search across indexed content |
| `context-mode__ctx_fetch_and_index` | Fetch a URL, convert HTML to markdown, index for search |
| `context-mode__ctx_stats` | Context savings breakdown |
| `context-mode__ctx_doctor` | Diagnose runtimes, hooks, FTS5, version |
| `context-mode__ctx_upgrade` | Upgrade context-mode in place |
| `context-mode__ctx_purge` | Wipe the indexed knowledge base |

## ECA hooks

This plugin registers ECA-native hooks:

- `chatStart` — inject routing guidance and resume context
- `preRequest` — capture prompts and add lightweight guidance
- `preToolCall` — deny direct context-flooding fetches and route large work
- `postToolCall` — capture successful and failed tool results for continuity
- `preCompact` — persist a resume snapshot before compaction
- `postCompact` — inject the saved snapshot after compaction

ECA `sessionStart` output is not used for model context; startup context belongs in `chatStart`.

## Usage

Once installed, context-mode works automatically. The routing rules guide the agent toward sandbox tools for any operation that produces large output.
Once installed, the MCP server works through `.mcp.json` and hook continuity works through `hooks/ctx-eca-adapter.mjs`. The rules guide the agent toward sandbox tools for operations that may produce large output.

**Check everything is working:**

```
```text
ctx doctor
```

**See context savings:**

```
```text
ctx stats
```

**After compaction:** the agent automatically resumes from the session state captured in SQLite — no manual intervention needed.
**After compaction:** `preCompact` saves a snapshot and `postCompact` injects it into ECA's compact summary, so the agent can continue with restored session context.

## Session continuity

Every significant tool call is tracked:
Session history is searchable:

| Need | Command |
|------|---------|
Expand All @@ -86,6 +103,6 @@ The core paradigm: write code that processes data and `console.log()` only the a
context-mode__ctx_execute("javascript", `
const { execSync } = await import('node:child_process');
const prs = JSON.parse(execSync('gh pr list --json number,title,state --limit 20').toString());
prs.forEach(p => console.log(\`#\${p.number} [\${p.state}] \${p.title}\`));
prs.forEach(p => console.log('#' + p.number + ' [' + p.state + '] ' + p.title));
`)
```
9 changes: 9 additions & 0 deletions plugins/context-mode/hooks/ctx-chatstart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail

if ! command -v context-mode &>/dev/null; then
exit 0
fi

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
exec node "$SCRIPT_DIR/ctx-eca-adapter.mjs" chatstart
Loading