context-mode 2.0.0-next.32 → 2.0.0-next.34

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.
@@ -9,7 +9,7 @@
9
9
  "name": "context-mode",
10
10
  "skills": "./claude-code/skills",
11
11
  "source": "./",
12
- "version": "2.0.0-next.32"
12
+ "version": "2.0.0-next.34"
13
13
  }
14
14
  ]
15
15
  }
@@ -13,5 +13,5 @@
13
13
  },
14
14
  "name": "context-mode",
15
15
  "skills": "./claude-code/skills",
16
- "version": "2.0.0-next.32"
16
+ "version": "2.0.0-next.34"
17
17
  }
@@ -8,5 +8,5 @@
8
8
  "mcpServers": "./.codex-plugin/mcp.json",
9
9
  "name": "context-mode",
10
10
  "skills": "./codex/skills/",
11
- "version": "2.0.0-next.32"
11
+ "version": "2.0.0-next.34"
12
12
  }
package/README.md CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  **A free, local plugin for 10 coding agents. It keeps tool output out of your agent's context window and keeps all usage data on your machine. The plugin is free forever.**
4
4
 
5
- [![npm downloads](https://img.shields.io/npm/dt/context-mode?label=npm%20downloads)](https://www.npmjs.com/package/context-mode) [![GitHub stars](https://img.shields.io/github/stars/mksglu/context-mode?style=flat&color=yellow)](https://github.com/mksglu/context-mode) [![Discord](https://img.shields.io/discord/1478479412700909750?label=Discord&logo=discord&color=5865f2)](https://discord.gg/DCN9jUgN5v) [![License: ELv2](https://img.shields.io/badge/License-ELv2-blue.svg)](https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/LICENSE)
5
+ [![npm downloads](https://img.shields.io/npm/dt/context-mode?label=npm%20downloads)](https://www.npmjs.com/package/context-mode) [![GitHub stars](https://img.shields.io/github/stars/mksglu/context-mode?style=flat&color=yellow)](https://github.com/mksglu/context-mode) [![Discord](https://img.shields.io/discord/1478479412700909750?label=Discord&logo=discord&color=5865f2)](https://discord.gg/DCN9jUgN5v) [![License: ELv2](https://img.shields.io/badge/License-ELv2-blue.svg)](https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/LICENSE)
6
6
 
7
- **33K GitHub stars · 683K npm downloads** (read 2026-11-01, [stats.json](https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/stats.json)) · on the Hacker News front page and GitHub Trending: [charts and sources](#adoption-stars-and-npm-downloads)
7
+ **33K GitHub stars · 683K npm downloads** (read 2026-11-01, [stats.json](https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/stats.json)) · on the Hacker News front page and GitHub Trending: [charts and sources](#adoption-stars-and-npm-downloads)
8
8
 
9
9
  > The Context Mode plugin is free and local, with its source open on GitHub. **Context Mode Gateway** is a separate hosted service with its own account and subscription. It takes the same idea from tool output to the whole conversation: Gateway Recall keeps long sessions searchable, and Gateway Memory shares what your agents learn across sessions and tools. [See how the Gateway works](https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=quote)
10
10
 
11
11
  <picture>
12
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/hero-dark.png">
13
- <img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/hero-light.png" alt="Context Mode plugin: free and local, zero telemetry, the plugin keeps your data on your machine. Bench of 2026-11-01: 99.4% of output bytes saved (median of 36 rows with 10 KB or more of raw output). A full debugging session (row g-session-total): 281,261 B raw to 3,266 B in context, about 70K to 817 tokens (an estimate at 4 B per token). Resume after compaction (row e-long-session): a 442,893 B transcript to a 2,019 B block, about 111K to 505 tokens (an estimate). Runs in 10 coding agents with 9 MCP tools.">
12
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/hero-dark.png">
13
+ <img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/hero-light.png" alt="Context Mode plugin: free and local, zero telemetry, the plugin keeps your data on your machine. Bench of 2026-11-01: 99.4% of output bytes saved (median of 36 rows with 10 KB or more of raw output). A full debugging session (row g-session-total): 281,261 B raw to 3,266 B in context, about 70K to 817 tokens (an estimate at 4 B per token). Resume after compaction (row e-long-session): a 442,893 B transcript to a 2,019 B block, about 111K to 505 tokens (an estimate). Runs in 10 coding agents with 9 MCP tools.">
14
14
  </picture>
15
15
 
16
16
  **Contents:** [Why](#why) · [Adoption](#adoption-stars-and-npm-downloads) · [Install](#install) · [Try it](#try-it) · [Use cases](#use-cases) · [Benchmarks](#benchmarks) · [How it works](#how-it-works) · [Tools](#tools) · [Security and privacy](#security-and-privacy) · [Context Mode Gateway](#context-mode-gateway) · [License](#license) · [Community](#community)
@@ -30,8 +30,8 @@ The Context Mode plugin runs that work in a local sandbox, keeps the full output
30
30
  ## Adoption: stars and npm downloads
31
31
 
32
32
  <table><tr>
33
- <td width="50%"><a href="https://contextmode.ai/open-source/stats?utm_source=github&utm_medium=readme&utm_content=adoption#stars"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/star-history-dark.png"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/star-history-light.png" alt="Line chart of cumulative GitHub stars for mksglu/context-mode since 2026-02-23. A daily job redraws it."></picture></a></td>
34
- <td width="50%"><a href="https://contextmode.ai/open-source/stats?utm_source=github&utm_medium=readme&utm_content=adoption#daily"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/npm-downloads-dark.png"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/npm-downloads-light.png" alt="Area chart of npm downloads per day for context-mode, the last 90 days. A daily job redraws it."></picture></a></td>
33
+ <td width="50%"><a href="https://contextmode.ai/open-source/stats?utm_source=github&utm_medium=readme&utm_content=adoption#stars"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/star-history-dark.png"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/star-history-light.png" alt="Line chart of cumulative GitHub stars for mksglu/context-mode since 2026-02-23. A daily job redraws it."></picture></a></td>
34
+ <td width="50%"><a href="https://contextmode.ai/open-source/stats?utm_source=github&utm_medium=readme&utm_content=adoption#daily"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/npm-downloads-dark.png"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/npm-downloads-light.png" alt="Area chart of npm downloads per day for context-mode, the last 90 days. A daily job redraws it."></picture></a></td>
35
35
  </tr></table>
36
36
 
37
37
  Open the [interactive chart](https://contextmode.ai/open-source/stats?utm_source=github&utm_medium=readme&utm_content=adoption#daily) and point at a bar to read its value. Tabs there show days, weeks, months and years. Stars come from the GitHub GraphQL API (`starredAt`); npm downloads come from `api.npmjs.org/downloads/range`. The total up to 2026-10-29 is 683K npm downloads (`stats.json` keeps a daily copy). A daily job redraws both charts.
@@ -40,15 +40,15 @@ Open the [interactive chart](https://contextmode.ai/open-source/stats?utm_source
40
40
  - **GitHub Trending.** A bot that watches GitHub Trending logged the repo there on 14 days from 2026-04-24 to 2026-10-17 ([uibm/trending-watcher](https://github.com/uibm/trending-watcher/issues?q=%22mksglu%2Fcontext-mode%22)).
41
41
 
42
42
  <picture>
43
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/stargazers-dark.png">
44
- <img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/stargazers-light.png" alt="Companies that stargazers of mksglu/context-mode name in their GitHub profile, Microsoft, Tencent, Alibaba, ByteDance, Google and more.">
43
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/stargazers-dark.png">
44
+ <img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/stargazers-light.png" alt="Companies that stargazers of mksglu/context-mode name in their GitHub profile, Microsoft, Tencent, Alibaba, ByteDance, Google and more.">
45
45
  </picture>
46
46
 
47
- Starred by engineers at these companies: each name is the company field of 2 or more stargazer profiles, read with the GitHub GraphQL API on 2026-11-01 ([data](https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/docs/assets/readme/data/stargazer-companies.json)).
47
+ Starred by engineers at these companies: each name is the company field of 2 or more stargazer profiles, read with the GitHub GraphQL API on 2026-11-01 ([data](https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/docs/assets/readme/data/stargazer-companies.json)).
48
48
 
49
49
  ## Install
50
50
 
51
- The plugin needs Node 24.15.0 or later (the `engines` field in [package.json](https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/package.json)). On Windows you also need Git for Windows: the shell tools run in Git Bash, and `context-mode doctor` checks that Git Bash is there.
51
+ The plugin needs Node 24.15.0 or later (the `engines` field in [package.json](https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/package.json)). On Windows you also need Git for Windows: the shell tools run in Git Bash, and `context-mode doctor` checks that Git Bash is there.
52
52
 
53
53
  Open your agent and copy its own install command. Each block also has the update, check and remove steps. Step-by-step guide: [Install](https://contextmode.ai/docs/engine/install?utm_source=github&utm_medium=readme&utm_content=install).
54
54
  The npm commands use `@next`, the current 2.0 release tag; a plain `npm i -g context-mode` installs 1.x. Claude Code, Codex, Gemini CLI and Qwen Code install from GitHub, and each of their commands names the `release` branch.
@@ -164,7 +164,7 @@ CI runs setup, doctor, a hook and an MCP handshake for all 10 agents from the pa
164
164
 
165
165
  ## Try it
166
166
 
167
- Paste one of these prompts into your agent after the install. Each one ran once, live, in Claude Code 2.1.312, and its answer matched the source data ([evidence and rerun steps](https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/bench/evidence/try-it-2026-11-02/README.md)). The headline numbers in [Benchmarks](#benchmarks) use the median of 5 runs. Other agents do the same job with the same tools: `ctx_execute`, `ctx_index` and `ctx_search`.
167
+ Paste one of these prompts into your agent after the install. Each one ran once, live, in Claude Code 2.1.312, and its answer matched the source data ([evidence and rerun steps](https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/bench/evidence/try-it-2026-11-02/README.md)). The headline numbers in [Benchmarks](#benchmarks) use the median of 5 runs. Other agents do the same job with the same tools: `ctx_execute`, `ctx_index` and `ctx_search`.
168
168
  Then run `/ctx-stats` in your agent to see how much output stayed out of the context. Every agent gets this command with the plugin skills (`skills/ctx-stats`).
169
169
  ```text
170
170
  On https://react.dev/reference/react/useEffect, show me the example that connects to a chat server and cleans up, and list the rules for the dependency array.
@@ -210,7 +210,7 @@ Real tool output from public projects, run through Context Mode. Bench of 2026-1
210
210
  | Read a 60 KB source file | Read, sent to `ctx_execute` by the hook | 61,576 B | 374 B | 99.4% |
211
211
  | Debug for a full session: 8 outputs, 3 searches | All hooks and tools | 281,261 B | 3,266 B | 98.8% |
212
212
 
213
- Source: [bench/results/2026-11-01-darwin-arm64.json](https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/bench/results/2026-11-01-darwin-arm64.json), one row per line; each input is named in `bench/fixtures/data/SOURCE.md`.
213
+ Source: [bench/results/2026-11-01-darwin-arm64.json](https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/bench/results/2026-11-01-darwin-arm64.json), one row per line; each input is named in `bench/fixtures/data/SOURCE.md`.
214
214
 
215
215
  The agent gets the part it asks for. The full output stays in the local index, and `ctx_search` reads it back.
216
216
  The Context7 row has 6,917 B of raw output, under the 10 KB line of the headline rule, so the headline leaves it out.
@@ -218,8 +218,8 @@ The Context7 row has 6,917 B of raw output, under the 10 KB line of the headline
218
218
  ## Benchmarks
219
219
 
220
220
  <picture>
221
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/fig-saving-dark.png">
222
- <img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/fig-saving-light.png" alt="Bar chart: median output bytes saved per category for rows of 10 KB or more. Sandbox 99.5%, Batch 93.1%, Externalize 98.3%, Hook redirect 99.8%, Session total 98.8%. The table below adds Retrieval, 77.2%.">
221
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/fig-saving-dark.png">
222
+ <img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/fig-saving-light.png" alt="Bar chart: median output bytes saved per category for rows of 10 KB or more. Sandbox 99.5%, Batch 93.1%, Externalize 98.3%, Hook redirect 99.8%, Session total 98.8%. The table below adds Retrieval, 77.2%.">
223
223
  </picture>
224
224
 
225
225
  Rule for every headline number in this README: rows with 10 KB or more of raw output, median of 5 runs per row, measured with `ctx_bytes` against `raw_bytes`; a category is the median of its rows; 1 KB = 1,024 B.
@@ -240,8 +240,8 @@ Reproduce: `cd bench && node run.mjs`. Method, data files and rerun steps: [Benc
240
240
  ### Longer sessions
241
241
 
242
242
  <picture>
243
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/fig-oss-dark.png">
244
- <img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/fig-oss-light.png" alt="A session grows, the context stays small. The PreToolUse hook sends a tool call to ctx_execute or ctx_index; the full output goes into context.db and a small reply returns. At compaction a snapshot keeps the state, and ctx_resume and ctx_search read it back.">
243
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/fig-oss-dark.png">
244
+ <img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/fig-oss-light.png" alt="A session grows, the context stays small. The PreToolUse hook sends a tool call to ctx_execute or ctx_index; the full output goes into context.db and a small reply returns. At compaction a snapshot keeps the state, and ctx_resume and ctx_search read it back.">
245
245
  </picture>
246
246
 
247
247
  Say you debug a slow test all afternoon. The agent reads files, runs the suite and fetches docs, and each result goes into the context window. When the window is full, the host compacts it, and from then on the agent sees a short summary plus your next message.
@@ -266,8 +266,8 @@ Source: rows `g-hook-kiro` to `g-hook-claude-code`, `g-search-latency` and `g-in
266
266
  ## How it works
267
267
 
268
268
  <picture>
269
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/fig-flow-dark.png">
270
- <img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/fig-flow-light.png" alt="One tool call, step by step: the agent runs a tool, the PreToolUse hook denies a big Read and names the ctx_execute call, the MCP server runs it in the sandbox, SQLite FTS5 keeps the output, and after compaction a state block of at most 2,048 B comes back.">
269
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/fig-flow-dark.png">
270
+ <img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/fig-flow-light.png" alt="One tool call, step by step: the agent runs a tool, the PreToolUse hook denies a big Read and names the ctx_execute call, the MCP server runs it in the sandbox, SQLite FTS5 keeps the output, and after compaction a state block of at most 2,048 B comes back.">
271
271
  </picture>
272
272
 
273
273
  1. Your agent calls a tool: it reads a file, runs a command or fetches a page.
@@ -301,7 +301,7 @@ Commands in the agent: `/ctx-stats` shows the `ctx_stats` result, `/ctx-doctor`
301
301
  - The plugin keeps all its data on your machine, in `~/.context-mode`: one `context.db` per project. `ctx_purge` deletes it by session, source or project. Read the [Security guide](https://contextmode.ai/docs/engine/security?utm_source=github&utm_medium=readme&utm_content=security).
302
302
  - The plugin has zero telemetry: usage data, events and crash reports stay on your machine. It uses the network at these call sites, each one started by you or your agent:
303
303
  - `ctx_index` of a URL the agent asks for: `src/core/sandbox/fetch.ts`. It blocks private and link-local addresses, checks each address the host name points to, connects to the address it checked, and checks again at each redirect.
304
- - `context-mode doctor`: `git ls-remote` to the release repository, to check for a new version (`src/core/ops/doctor-env.ts`).
304
+ - `context-mode doctor`: one read of the npm dist-tags of `context-mode`, with `git ls-remote` of the release tags as the fallback when npm is down, to check for a new version (`src/core/ops/doctor-env.ts`).
305
305
  - `ctx_upgrade`: `git clone --depth 1` of the release branch (`src/core/ops/release-fetch.ts`). `context-mode upgrade`: `npm i -g context-mode@next` (`src/cli/commands.ts`).
306
306
  - The debug report: `gh issue create`, after you press a key (`src/cli/commands.ts`).
307
307
  - Install and update: your agent's own install command, npm or git.
@@ -322,16 +322,16 @@ With the Gateway on, your requests pass through its server; the plugin keeps its
322
322
  | Context Mode plugin | On your machine | One project, local `context.db` | Free |
323
323
  | Context Mode Gateway | Hosted service | All sessions and agents | Subscription, separate from the plugin |
324
324
 
325
- <a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/docs/assets/readme/gateway/live.mp4"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/gateway/live.webp" width="100%" alt="Gateway Live screen during a session: money saved, bytes kept out per request, history kept and sent, and a feed of each request with its cost and saving"></a>
325
+ <a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/docs/assets/readme/gateway/live.mp4"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/gateway/live.webp" width="100%" alt="Gateway Live screen during a session: money saved, bytes kept out per request, history kept and sent, and a feed of each request with its cost and saving"></a>
326
326
 
327
327
  **Live.** One session as it runs: money saved this session, bytes kept out per request, history kept and sent, and a feed of each request with its cost and saving. Click the image for the full video.
328
328
 
329
329
  Docs: [How saving works](https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=live)
330
330
 
331
331
  <table>
332
- <tr><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/docs/assets/readme/gateway/overview.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/gateway/overview-1200.webp" alt="Gateway Overview: money saved, AI spend, prompt-cache discount and cost per request over 30 days"></a><br><b>Overview.</b> Your spend and what the Gateway saved, per day, in one view.<br>Docs: <a href="https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=overview">How saving works</a></td><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/docs/assets/readme/gateway/analytics.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/gateway/analytics-1200.webp" alt="Gateway Analytics: saved money over time, split by source"></a><br><b>Analytics.</b> Where each saving comes from: hidden tools, archived old results, large outputs kept in the archive and trimmed context.<br>Docs: <a href="https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=analytics">How saving works</a></td></tr>
333
- <tr><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/docs/assets/readme/gateway/spend.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/gateway/spend-1200.webp" alt="Gateway Spend: spend per day by model, cost per request and cache hit rate"></a><br><b>Spend.</b> Spend per day and per model, cost per request and the cache hit rate, to help you plan a budget.<br>Docs: <a href="https://contextmode.ai/docs/prompt-caching?utm_source=github&utm_medium=readme&utm_content=spend">Prompt caching</a></td><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/docs/assets/readme/gateway/memory.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/gateway/memory-top-1200.webp" alt="Gateway Memory: money saved by Recall and searches per day"></a><br><b>Memory.</b> Facts and decisions carry across sessions and agents. The screen shows what Recall saved and how many searches found an answer.<br>Docs: <a href="https://contextmode.ai/docs/memory?utm_source=github&utm_medium=readme&utm_content=memory">Memory</a></td></tr>
334
- <tr><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/docs/assets/readme/gateway/skills.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/gateway/skills-1200.webp" alt="Gateway Skills: import from GitHub and the list of installed skills"></a><br><b>Skills.</b> Add a skill once and all your clients use it when it helps. Import skills from GitHub and see the installed ones.<br>Docs: <a href="https://contextmode.ai/docs/skills?utm_source=github&utm_medium=readme&utm_content=skills">Skills</a></td><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.32/docs/assets/readme/gateway/protect.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.32/docs/assets/readme/gateway/protect-1200.webp" alt="Gateway Protect: a new command rule that blocks terraform destroy"></a><br><b>Protect.</b> Rules that check each shell command before it runs. Here, a rule that stops <code>terraform destroy</code>.<br>Docs: <a href="https://contextmode.ai/docs/protect?utm_source=github&utm_medium=readme&utm_content=protect">Protect</a></td></tr>
332
+ <tr><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/docs/assets/readme/gateway/overview.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/gateway/overview-1200.webp" alt="Gateway Overview: money saved, AI spend, prompt-cache discount and cost per request over 30 days"></a><br><b>Overview.</b> Your spend and what the Gateway saved, per day, in one view.<br>Docs: <a href="https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=overview">How saving works</a></td><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/docs/assets/readme/gateway/analytics.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/gateway/analytics-1200.webp" alt="Gateway Analytics: saved money over time, split by source"></a><br><b>Analytics.</b> Where each saving comes from: hidden tools, archived old results, large outputs kept in the archive and trimmed context.<br>Docs: <a href="https://contextmode.ai/docs/how-saving-works?utm_source=github&utm_medium=readme&utm_content=analytics">How saving works</a></td></tr>
333
+ <tr><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/docs/assets/readme/gateway/spend.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/gateway/spend-1200.webp" alt="Gateway Spend: spend per day by model, cost per request and cache hit rate"></a><br><b>Spend.</b> Spend per day and per model, cost per request and the cache hit rate, to help you plan a budget.<br>Docs: <a href="https://contextmode.ai/docs/prompt-caching?utm_source=github&utm_medium=readme&utm_content=spend">Prompt caching</a></td><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/docs/assets/readme/gateway/memory.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/gateway/memory-top-1200.webp" alt="Gateway Memory: money saved by Recall and searches per day"></a><br><b>Memory.</b> Facts and decisions carry across sessions and agents. The screen shows what Recall saved and how many searches found an answer.<br>Docs: <a href="https://contextmode.ai/docs/memory?utm_source=github&utm_medium=readme&utm_content=memory">Memory</a></td></tr>
334
+ <tr><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/docs/assets/readme/gateway/skills.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/gateway/skills-1200.webp" alt="Gateway Skills: import from GitHub and the list of installed skills"></a><br><b>Skills.</b> Add a skill once and all your clients use it when it helps. Import skills from GitHub and see the installed ones.<br>Docs: <a href="https://contextmode.ai/docs/skills?utm_source=github&utm_medium=readme&utm_content=skills">Skills</a></td><td width="50%"><a href="https://github.com/mksglu/context-mode/blob/v2.0.0-next.34/docs/assets/readme/gateway/protect.webp"><img src="https://raw.githubusercontent.com/mksglu/context-mode/v2.0.0-next.34/docs/assets/readme/gateway/protect-1200.webp" alt="Gateway Protect: a new command rule that blocks terraform destroy"></a><br><b>Protect.</b> Rules that check each shell command before it runs. Here, a rule that stops <code>terraform destroy</code>.<br>Docs: <a href="https://contextmode.ai/docs/protect?utm_source=github&utm_medium=readme&utm_content=protect">Protect</a></td></tr>
335
335
  </table>
336
336
 
337
337
  Numbers in these screens come from the author's own account over 30 days (Oct 3 - Nov 1, 2026), so read them as one account's usage. Click an image for the full size.
package/SHA256SUMS CHANGED
@@ -1,21 +1,21 @@
1
- 0c02ddf3b7dc39607eed438eb49a8805b853252dbcf65c68787272f75d8d7bd4 .claude-plugin/marketplace.json
2
- 87891812200ff35334fdd4b5973dedb8d97938aefe65d923bcf1e55f3302bb54 .claude-plugin/plugin.json
1
+ fc1510dd8a82990cc44b8bba7c82c3bf28026845e58ec070109d49dbb89ee4ad .claude-plugin/marketplace.json
2
+ f1c9c67818e936eb45e5e539d32c66d7b3f140b482bea308d0ab57d1a481ef01 .claude-plugin/plugin.json
3
3
  187503e1455560d4ab5a72e3b8cd2f274abd4ccc5faa60dd66c37e44bb5f10c2 .codex-plugin/hooks.json
4
4
  4edea851775bc3f0418f8d9cf6ead74f2767c3a9e3b8c05749eacb78ebb3b896 .codex-plugin/mcp.json
5
- 3f2f4f050c6eb72ca8584ce7ea684bb56969522384752767409b23c55c47f72a .codex-plugin/plugin.json
5
+ fb1cfbb525c68ceb5f62b1fc2b428295e4da799f2e79d410a0a1ba14b434675f .codex-plugin/plugin.json
6
6
  92f11a867c41c9e575ccb978ff205ae2011c244a14aa3c576e914e537105caa0 LICENSE
7
- 21603a0f2d02ff2645554b2a9116620b2a65d2cdf8b102276f74fc9d3f5ea8b9 README.md
7
+ d3d6930a4afd1498f23e01eeb8c6c0f906378b4b66a4e8fa4e168c80b18e63c6 README.md
8
8
  1773e40a89384dd1af9023ba533da1908f3e2435dbaaa7cc941edf0514148313 claude-code/skills/ctx-doctor/SKILL.md
9
9
  d12b50ba56fa8632a778948b72137c32e043b0c11b0402f07ddef1578406d495 claude-code/skills/ctx-stats/SKILL.md
10
10
  d8f835d2f2b3eb70c5902f8707e7c5857977cec9e20ace76c499378a04e178e0 claude-code/skills/ctx-upgrade/SKILL.md
11
- 17041e9411380381aa112c21375e1a64ef6c394d864c37dfa9a80faaef0701bd cli.mjs
11
+ 6916189e2eb1b6b06b8a6a9b0c142ecdd505534e9059894b58d80450d061f449 cli.mjs
12
12
  83c297020ed0c592fc68c9c482546a6999d41df5d06d8a329498f10edb1bd38e codex/skills/ctx-doctor/SKILL.md
13
13
  5652e791d5fa00033aebb0f6f85b6a3c9db8ab45cfc402e74ffc5f87bdc08922 codex/skills/ctx-stats/SKILL.md
14
14
  5c12cdd19a5e3ed7d9ba3a47b24d03864a28d36cf7006876284ee07cd4221ec4 codex/skills/ctx-upgrade/SKILL.md
15
- 4c2e7e96e40fc77997742b4b1eb98dc73ffa404f8d87ba25c9e4c984cef03d69 copilot/plugin.json
15
+ a5cfa9cea261772cc68da4d45b79454d110dc625b192e952ec999f5d060ceb00 copilot/plugin.json
16
16
  e3bc6cae0bd51b806d81631879711bbc48c679fc929b2642ed4634438364167d fixtures/hook-roundtrip.json
17
- 7164426814b71d347dd307d50d86a69b93cbf7e7d206c4f32f9a1eff12a6aa90 gemini-extension.json
18
- f2708704cbfe732fa11e3be7263fb0e5b39b5700f30d0d7f4d47583a749e15a5 hook.mjs
17
+ 702459fef08cd18a91469839cf0f02329f74e98464cf27be1cb6ba51f254f169 gemini-extension.json
18
+ a0cbe7f0b62c6655ea253e1793b362dfc1f403d6356de5ca1112d96b5b143385 hook.mjs
19
19
  1f8d8650d2b38737522cab6b875878e8baf84a74acf98cd924c7af22852d873f hooks/claude-code.json
20
20
  2524a0eb52683b65c65943c5097db513e9845ba14e84324b39e9a8ea2bb43193 hooks/codex.json
21
21
  b656fed2b754ebcfd4c156bee81d5879c21a8083fc0d6b8e3241462b63a214b6 hooks/copilot-cli.json
@@ -24,16 +24,16 @@ f336d1db67de49e641687bbd41ba1a9424e31dfe2377b2284bf44358288ebd8b hooks/kiro.jso
24
24
  017c9cc3997dd53231b8548b1a1609fddc51177af53501565a4f334602039860 hooks/qwen.json
25
25
  33f69267645338d0dc392ce551dcd7c69a0b508113469d6ea637d3f34239ef1d hooks/vscode.json
26
26
  085630bccf2073ac9a62be24ef91dfc47d106092dc82c822db70890b7d3ae1c0 hooks/zcode.json
27
- 1e933bf7d4853afbf426eaf3655f33c0a1f2c7e85ecacde2571c74d293383725 opencode/plugin.js
28
- 707e3d2b2e2b9ce945dfceccff84da62c2c2d21d22def9868baaa0c13c17fbb4 package.json
29
- a7c3b7436ffd3c589b6a8f5c059b9d4a4eed66ba5cefa51426917b97b9129aab pi/index.js
27
+ 331f7558c7278137428c451f940daa2f04fc235f9f4e073db8307d96e62b8e86 opencode/plugin.js
28
+ 1c966e87bed9283a53d86e20952bb10ef511bd5ab934a2dc791bf5ff925b5ffc package.json
29
+ aa81e4e82350a802e4788a744138b574999dd18d12d2f2d22b5a1ea1cd715b53 pi/index.js
30
30
  8712881622c9905aa4836af50d903042d34a91506264e459bc7839331f6f0192 pi/skills/ctx-doctor/SKILL.md
31
31
  4ff03de9581acbb827266eb9461aa34c8da5c3d01d51a3738064e582bf466a79 pi/skills/ctx-stats/SKILL.md
32
32
  db6f9c006bc864a7271f1eeffb1e316ebb537a3414f1c22f8b9de0a896e8e3c5 pi/skills/ctx-upgrade/SKILL.md
33
- aa67b34d43b58b75b7d3112151612f6bfacdc9d77e06b5aa46a61db52f776f46 qwen-extension.json
34
- f1983e6e298f644607b0cf5d2ec956c659d0f5890e4d6b6adc5f6b09318f4f56 run.mjs
35
- f1983e6e298f644607b0cf5d2ec956c659d0f5890e4d6b6adc5f6b09318f4f56 search.mjs
36
- 93c32bb45a0ac8af1bdb9dd951ca2ed24533eea5a174811013c437141dc32e48 server.mjs
33
+ 566e19dac5ce43b1a671b994ab3050c29c9a588fd92973d20655620e88503aa2 qwen-extension.json
34
+ 163265ea9d2093a44f0a4ef77437704c3eb6821edc9a89b3220628031fe6b0b8 run.mjs
35
+ 163265ea9d2093a44f0a4ef77437704c3eb6821edc9a89b3220628031fe6b0b8 search.mjs
36
+ 2dd7a9f3c2ee6b9bac7a637fdb976bd0b6c228c027c0e2c962522fabe2a340c2 server.mjs
37
37
  e5503a22a6238901484d123efc11d2d933aa9a54c6ac2018812cfa65ec4e53e3 skills/ctx-doctor/SKILL.md
38
38
  ad3b9875600f3d7a4970ed91ad9331903c2aa5e77d9f742c6a212015a021ad18 skills/ctx-stats/SKILL.md
39
39
  c1cac75b7506ee0d06089ce611ac6dc9314cf12435da318ce88ad50e2c5debbf skills/ctx-upgrade/SKILL.md
package/cli.mjs CHANGED
@@ -326,7 +326,6 @@ var STATS_WAYS = Object.freeze([
326
326
  var STATS_INDEX_TOOLS = Object.freeze(["ctx_index", "ctx_search"]);
327
327
  var PURGE_SCOPES = Object.freeze(["session", "source", "project"]);
328
328
  var RELEASE_REPO_URL = "https://github.com/mksglu/context-mode.git";
329
- var RELEASE_BRANCH = "release";
330
329
  var DOCTOR_CHECK_ORDER = Object.freeze(["D1", "D2", "D3", "D4", "D5", "D5b", "D6", "D7", "D8", "D9", "D10", "D11"]);
331
330
  var DOCTOR_LABEL = Object.freeze({
332
331
  D1: "version",
@@ -344,7 +343,9 @@ var DOCTOR_LABEL = Object.freeze({
344
343
  });
345
344
  var REPORT_SOURCE_LABEL = "ctx_doctor:report";
346
345
  var REPORT_POINTER = `ctx_search({queries:["FAIL","PASS","UNKNOWN"], source:${JSON.stringify(REPORT_SOURCE_LABEL)}})`;
347
- var D1_GIT_CHECK_FIX = `git ls-remote ${RELEASE_REPO_URL} ${RELEASE_BRANCH}`;
346
+ var GIT_LS_REMOTE_TAG_ARGS = Object.freeze(["--tags", "--refs"]);
347
+ var RELEASE_TAG_PATTERN = "v*";
348
+ var D1_GIT_CHECK_FIX = `git ls-remote --tags --refs ${RELEASE_REPO_URL} "${RELEASE_TAG_PATTERN}"`;
348
349
  var D2_NODE_FIX = `install Node ${NODE_MIN} or later`;
349
350
  var D3_PARTS = Object.freeze(["MCP entry", "hook entries", "hook timeout"]);
350
351
  var AGENT_HOME_DIR = Object.freeze({
@@ -11,5 +11,5 @@
11
11
  }
12
12
  },
13
13
  "name": "context-mode",
14
- "version": "2.0.0-next.32"
14
+ "version": "2.0.0-next.34"
15
15
  }
@@ -11,5 +11,5 @@
11
11
  }
12
12
  },
13
13
  "name": "context-mode",
14
- "version": "2.0.0-next.32"
14
+ "version": "2.0.0-next.34"
15
15
  }
package/hook.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import{createRequire as __cmRequire}from"node:module";if(typeof process.getBuiltinModule!=="function")process.getBuiltinModule=(id)=>__cmRequire(import.meta.url)(id);
2
2
  var Oe=["claude-code","codex","gemini","qwen","copilot-cli","vscode","kiro","zcode","pi","opencode"];var te="context-mode",ot=Object.freeze(["ctx_execute","ctx_batch","ctx_index","ctx_search","ctx_resume","ctx_stats","ctx_doctor","ctx_upgrade","ctx_purge"]);function k(e,t){if(t==="")return e;let n=e;for(let o of ot)n=n.split(o).join(t+o);return n}var X=16384;var Qo=2048;var Zo=640,ln="</context_mode_state>",un=1048576,er=65536,tr=4096,nr=96,or=256,rr=48;function sr(e,t,n,o="",r=""){let s=r===""?[e]:[e,r];return o+"ctx_search({queries:["+s.map(i=>JSON.stringify(i)).join(",")+"], source:"+JSON.stringify(t)+"}) searches the whole output ("+n+" B)."}var ir=3,ne=4096;var dn=85,fn=340,xn=Object.freeze({toolerr:900,decision:700,prompt:500,edit:400,index:200});var cr=.7,ar=.7,lr=.3,pn=Object.freeze([1e3,881,780,696,625,565,515,473,438,408,383,361,344,329,316,306,297,289,283,278,273,270,267,264,262,260,258,257,256,255,254,253,253,252,252,252,251,251,251,251,251,251,251,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250,250]),ur='context-mode: earlier work of this session is in ctx_resume (state block) and ctx_search(scope:"session", sort:"timeline").';var $a=6e5;var ue=5e3,rt="-wal",st="-shm",dr=".tmp",fr=255,xr=11,pr=26;var M=5e3;var _n=0;var _r=16,Re=6;var Er="projects",mr="context.db";var En=".git",mn="worktree ",gn="gitdir: ",gr="commondir",hr="HEAD",it="--workspace-folder",xp=Object.freeze(["shell","powershell","javascript","typescript","python"]);var Sr=80;var pp=Object.freeze({NO_COLOR:"1",FORCE_COLOR:"0"});var _p=Object.freeze({"claude-code":"CLAUDE_CODE_SESSION_ID"}),Ae="24.15.0",ct="~/.context-mode";var br="CONTEXT_MODE_REQUIRE_SECURITY",Or=".claude",at="agents",lt=".md",hn="plugins",Tr="installed_plugins.json",de=":",Rr="@";var Ep=Object.freeze(["local","project"]),mp=Object.freeze({local:0,project:1,user:2,managed:2}),Sn="---",Ar="tools",Nr="disallowedTools",bn="mcp__",On="__",yr="mcp_",Cr="_-.:",$o=10;function Qa(e){if(e===void 0||e.trim()==="")return $o;let t=Number(e);return Number.isSafeInteger(t)&&t>0?t:$o}var gp=Qa(process.env.CTX_MCP_HINT_EVERY);var H=32;var Tn="context-mode: ",Ir=Object.freeze({curl:"This curl/wget call",http:"This inline HTTP call",build:"This build command",webfetch:"WebFetch"}),kr=" sends its body into the conversation.",Dr="Run it here instead; the full output is indexed and only the part that matches your intent comes back.",Lr="Tool: ",wr="state what you need",Pr="ctx_execute",Ur=Object.freeze(["ctx_index","ctx_search"]),Ne="Blocked by security policy: matches deny pattern ",ut="context-mode: your deny rules could not be read. Fix: run ctx_doctor.",dt="context-mode: could not parse this command; it may be blocked by your own rules. Run it through ctx_execute instead.",Mr="hook-errors.log";var Hr=Object.freeze(["tool_name","toolName","tool"]),Fr=Object.freeze(["hook_event_name","hookEventName","type"]),vr=Object.freeze(["tool_input","toolArgs","input","args"]),jr=Object.freeze(["cwd","directory"]),Gr=Object.freeze(["pretooluse","beforetool","tool_call","execute.before","tool.execute.before"]),Br="CM_HOOK_FAULT",hp=Object.freeze(["decode","project","policy","store","encode"]),ye=Object.freeze({shell:Object.freeze(["Bash","bash","shell"]),read:Object.freeze(["Read","read_file"]),grep:Object.freeze(["Grep","grep_search"]),fetch:Object.freeze(["WebFetch","web_fetch","fetch"])});function Wr(e,t){return`${Tn}the hook failed (${e}). Fix: run ${t}ctx_doctor.`}var Rn=Object.freeze({read:"Read the file in parts with offset and limit, or process it with ctx_execute(language, code); only what you print comes back.",shell:"Run the command with ctx_execute(language, code) or ctx_batch instead; only the part that matches your intent comes back.",grep:"Search with ctx_execute(language, code), or index the files with ctx_index and query them with ctx_search.",fetch:"Index the URL with ctx_index and query it with ctx_search."});var Sp=Object.freeze(["pwd","whoami","uname","id","realpath","ln"]),bp=Object.freeze(["status"]),Op=Object.freeze(["--version","-v"]),Tp=Object.freeze(["cp","mv","rm"]),Rp=Object.freeze(["-v","--verbose"]),D=Object.freeze({identity:".",length:"length",pipeLength:"| length",fieldSep:"."}),Kr="{prefix}",Xr=", then ",qr="context-mode: your deny rules could not be read, so they are not applied. Fix: run ctx_doctor.",Yr=Object.freeze(["claude.ai","claude.site","claudeusercontent.com"]),Vr=Object.freeze(["curl","wget"]),zr=Object.freeze({curl:{short:"s",long:"--silent"},wget:{short:"q",long:"--quiet"}}),Jr=Object.freeze(["-v","--verbose","--trace","--trace-ascii"]),$r="-D",Qr=Object.freeze(["gradlew","gradle","mvnw","mvn","sbt"]),Ce="fetch(",Zr="'\"`",es="http",ts=Object.freeze(["requests.get(","requests.post(","requests.put(","http.get(","http.request("]),ns=Object.freeze(["cat","head","tail","sed","less","jq","bat","more"]),os=Object.freeze(["head","tail"]),An=Object.freeze(["-n","-c","--lines","--bytes"]),ft="sed",rs=Object.freeze(["-n","--quiet","--silent"]),ss="jq",xt=Object.freeze(["file_path","absolute_path","path"]),pt="ctx_",is="Bash",cs=Object.freeze(["Write","Edit"]),as=Object.freeze(["file_path","path"]),Nn="Exit code ",Ie="resume-hint",yn="compact-state",Cn="pending-compact",_t="pending_compact:",In="1",kn=2048,Dn=5,ls=340,Ln="compacted:",us="recall_units_seen:",ds=64,fs="recall_seen:",wn="<context_mode_recall>",Pn="</context_mode_recall>",xs="recall",Un="This session may have run before. Call {prefix}ctx_resume for a summary of what happened.",ps="subagent:",_s="run.mjs",Es="node",ms=`context-mode: This command sends its body into the conversation.
3
- Run the command on the line above with Bash instead. It runs the same command in the same folder, indexes the full output and prints only the part that matches your intent, with the same exit code.`,Et="--agent",gs=1e3;var Ap=Object.freeze(["Scope","Produced","Returned","Saved","Reduction %"]);var Np=Object.freeze(["Ready. Your savings show up here after the first tool call.","Large outputs from ctx_execute, ctx_batch and ctx_index stay in the","sandbox, and only the short answer goes to the chat."]),yp=Object.freeze([["index","Content indexed"],["edit","File edits"],["toolerr","Issues kept"],["decision","Your decisions"],["cmd","Other tool calls"],["prompt","Your prompts"]]),Cp=Object.freeze(["ctx_resume brings back your last task, files changed and open issues","after a compact or a restart; ctx_search finds indexed content by words."]);var Ip=Object.freeze([["sandbox","\u2588","sandbox run"],["index","\u2593","index + search"],["redirect","\u2592","hook sent to sandbox"],["replace","\u2591","hook cut down"]]),kp=Object.freeze(["ctx_index","ctx_search"]);var Dp=Object.freeze(["session","source","project"]);var mt="decision";var Mn="AskUserQuestion",hs="answers",gt="option",Ss=" | ",Za="https://github.com/mksglu/context-mode.git",el="release";var Lp=Object.freeze(["D1","D2","D3","D4","D5","D5b","D6","D7","D8","D9","D10","D11"]),wp=Object.freeze({D1:"version",D2:"node",D3:"host config",D4:"old entries",D5:"hook round trip",D5b:"double-fire",D6:"MCP",D7:"project and worktree",D8:"context.db",D9:"index",D10:"enforcement mode",D11:"shell"});var bs=256,tl="ctx_doctor:report";var Pp=`ctx_search({queries:["FAIL","PASS","UNKNOWN"], source:${JSON.stringify(tl)}})`;var Up=`git ls-remote ${Za} ${el}`;var Mp=`install Node ${Ae} or later`;var Hp=Object.freeze(["MCP entry","hook entries","hook timeout"]);var Os=Object.freeze({"claude-code":[".claude"],codex:[".codex"],gemini:[".gemini"],qwen:[".qwen"],"copilot-cli":[".copilot"],vscode:[".vscode"],kiro:[".kiro"],zcode:[".zcode"],pi:[".pi"],opencode:[".config","opencode"]});var Fp=Object.freeze(["upgrade","uninstall"]);var vp=Object.freeze(["clone","--depth","1","--branch"]),jp=Object.freeze(["rev-parse","HEAD"]);var Gp=Object.freeze(["pi","opencode"]);var Bp=Object.freeze({GIT_TERMINAL_PROMPT:"0"}),Wp=Object.freeze({GIT_CONFIG_COUNT:"1",GIT_CONFIG_KEY_0:"core.autocrlf",GIT_CONFIG_VALUE_0:"false"});var Kp=Object.freeze(["shell","bash","sh"]),Xp=Object.freeze([["..","bin","bash.exe"],["..","..","bin","bash.exe"]]);var qp=Object.freeze(["doctor-env.ts","doctor-config.ts","doctor-hook.ts","doctor-db.ts","doctor-heal.ts","release-fetch.ts","verify-sums.ts","plugin-swap.ts","host-write.ts","v1-remove.ts","uninstall.ts"]);var Yp=Object.freeze({"claude-code":{root:"plugin",file:["hooks","claude-code.json"],key:["hooks"],shape:"nested",timeoutKey:"timeout",matcher:!0},codex:{root:"home",file:[".codex","hooks.json"],key:["hooks"],shape:"nested",timeoutKey:"timeout",matcher:!0},gemini:{root:"plugin",file:["hooks","hooks.json"],key:["hooks"],shape:"nested",timeoutKey:"timeout",matcher:!1},qwen:{root:"plugin",file:["hooks","qwen.json"],key:["hooks"],shape:"nested",timeoutKey:"timeout",matcher:!0},"copilot-cli":{root:"home",file:[".copilot","hooks","context-mode.json"],key:["hooks"],shape:"flat",timeoutKey:"timeoutSec",matcher:!1},vscode:{root:"home",file:[".copilot","hooks","context-mode-vscode.json"],key:["hooks"],shape:"flat",timeoutKey:"timeout",matcher:!1},kiro:{root:"home",file:[".kiro","hooks","context-mode.json"],key:["hooks"],shape:"kiro",timeoutKey:"timeout",matcher:!1},zcode:{root:"home",file:[".zcode","cli","config.json"],key:["hooks","events"],shape:"zcode",timeoutKey:"timeoutMs",matcher:!0},pi:null,opencode:null}),Vp=Object.freeze(["PreToolUse","PostToolUse"]);var zp=Object.freeze([["@mcp","mcp"],["shell","shell"]]);var Jp=Object.freeze(["features","hooks"]);var $p=Object.freeze(["",rt,st]);var Qp=Object.freeze({"claude-code":"claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",codex:"rewrite config.toml's [mcp_servers.context-mode*] block to the v2 entry, then restart Codex",gemini:"gemini extensions install https://github.com/mksglu/context-mode --ref release --auto-update",qwen:"qwen extensions install https://github.com/mksglu/context-mode --ref release --auto-update"});var Zp=Object.freeze(["afteragentresponse.mjs","aftermodel.mjs","aftertool.mjs","agentspawn.mjs","beforeagent.mjs","beforetool.mjs","posttooluse.mjs","precompact.mjs","precompress.mjs","pretooluse.mjs","sessionend.mjs","sessionstart.mjs","stop.mjs","userpromptsubmit.mjs"]);var e_=Object.freeze(["hooks","codex"]);var t_=Object.freeze([".mjs",".sh"]);var ht="CLAUDE_CONFIG_DIR";var nl=Object.freeze(["Code","User"]);var ol="mcp.json",n_=Object.freeze(["agents","default.json"]);var o_=Object.freeze(["steering","KIRO.md"]);var r_=Object.freeze(["opencode.jsonc","opencode.json"]);var s_=Object.freeze(["content","platform.json"]);var Ts="custom";var rl=Object.freeze(["/","\\"]),sl="${/}",i_=Object.freeze([...rl,sl]),Te=Object.freeze({hook:"old context-mode hook entry: command contains context-mode and an old script name or context-mode hook",cacheHealHook:"old context-mode cache-heal SessionStart hook entry",cacheHealFile:"old context-mode cache-heal script file",statusLine:"old context-mode statusLine (context-mode statusline): report only, never removed",mcpEntry:"old context-mode MCP entry mcpServers.context-mode",codexHook:"old context-mode Codex hook entry: context-mode hook codex or hooks/codex/*.mjs",codexToml:"old context-mode config.toml [mcp_servers.context-mode*] section",hookFile:"old context-mode hook file context-mode.json (runs context-mode hook)",vscodeMcp:"old context-mode MCP entry servers.context-mode in .vscode/mcp.json: report only, never removed",kiroHook:"old Kiro hook entry: command contains context-mode and an old script name or context-mode hook",kiroAgentFile:"old context-mode Kiro agent file agents/*.json with name context-mode",kiroSteering:"old context-mode Kiro steering doc .kiro/steering/KIRO.md: manual review, report only, never removed",piNpm:"old context-mode Pi package npm:context-mode",opencodePlugin:"old context-mode OpenCode plugin spec context-mode",zcodeHook:"old context-mode ZCode hook entry: command contains context-mode hook",dataDir:"old context-mode data dir <agent home>/context-mode/",dataDirShared:"old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",dataRoot:"old context-mode content under ~/.context-mode/",tmpFile:"old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"}),c_=Object.freeze([Te.statusLine,Te.vscodeMcp,Te.dataDirShared,Te.tmpFile,Te.kiroSteering]);var a_=te+"_";var l_=Object.freeze(["opencode","plugin.js"]);var il=Object.freeze(["features","mcp"]),cl="omit_tools_from",al=Object.freeze(["deferred"]),ll="default_tools_approval_mode",ul="approve",u_=Object.freeze({codex:{file:[".codex","config.toml"],key:["mcp_servers",te],fields:{[cl]:al,[ll]:ul}},vscode:{file:[ol],key:["servers",te]},kiro:{file:[".kiro","settings","mcp.json"],key:["mcpServers",te]},zcode:{file:[".zcode","cli","config.json"],key:["mcp","servers",te],fields:{type:"stdio",enabled:!0,timeoutMs:$a},also:[[il,!0]]}});var d_=Object.freeze({NODE_ENV:Object.freeze(["development","production","test"])}),dl="Environment: ";var fl="Docs: ";var xl="Report file: ",pl="File it: ",_l="Or open: ",El=" --",f_=Object.freeze([dl,fl,xl,pl,El.trim(),_l]),ml="mksglu/context-mode",gl="agent-report.yml";var x_=Object.freeze(["Summary","ctx-report","What happened","Hook errors","Journal rows","Agent config","Expected","Steps","Environment"]);var p_=Object.freeze(["CODEX_HOME","CLAUDE_CONFIG_DIR","CLAUDE_PLUGIN_ROOT","COPILOT_HOME","KIRO_HOME","OPENCODE_CONFIG_DIR","PI_CODING_AGENT_DIR","XDG_CONFIG_HOME","SHELL"]),__=Object.freeze(["node","git","sh"]),E_=Object.freeze(["token","secret","password","apikey","api_key","authorization","bearer"]);var m_=Object.freeze({"claude-code":["claude plugin marketplace add mksglu/context-mode#release","claude plugin install context-mode@context-mode"],codex:["codex plugin marketplace add mksglu/context-mode@release","codex plugin add context-mode@context-mode"],gemini:["gemini extensions install https://github.com/mksglu/context-mode --ref release"],qwen:["qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release"],opencode:["opencode plugin add context-mode@next"],pi:["pi install npm:context-mode@next"],"copilot-cli":["npm i -g context-mode@next","context-mode setup --agents copilot-cli"],vscode:["npm i -g context-mode@next","context-mode setup --agents vscode"],kiro:["npm i -g context-mode@next","context-mode setup --agents kiro"],zcode:["npm i -g context-mode@next","context-mode setup --agents zcode"]}),g_=`https://github.com/${ml}/issues/new?template=${gl}`;import{dirname as Px,join as Ux}from"node:path";var Hn="mcp__plugin_context-mode_context-mode__",hl=["SessionStart","UserPromptSubmit","PreToolUse","PostToolUse"],Rs="mcp__",As="__",Sl={startup:"startup",resume:"resume",clear:"clear",compact:"compact"};function bl(e,t){if(e.startsWith(t))return e.slice(t.length);if(!e.startsWith(Rs))return e;let n=e.slice(Rs.length),o=n.indexOf(As);return o<0?e:"mcp:"+n.slice(0,o)+":"+n.slice(o+As.length)}function Ol(e){if(e===void 0)return"";if(typeof e=="string")return e;if(Array.isArray(e))return ys(e).text;if(typeof e=="object"&&e!==null){let t=e;if(typeof t.stdout=="string"||typeof t.stderr=="string"){let n=typeof t.stdout=="string"?t.stdout:"",o=typeof t.stderr=="string"?t.stderr:"";return o===""?n:n===""?o:n+`
3
+ Run the command on the line above with Bash instead. It runs the same command in the same folder, indexes the full output and prints only the part that matches your intent, with the same exit code.`,Et="--agent",gs=1e3;var Ap=Object.freeze(["Scope","Produced","Returned","Saved","Reduction %"]);var Np=Object.freeze(["Ready. Your savings show up here after the first tool call.","Large outputs from ctx_execute, ctx_batch and ctx_index stay in the","sandbox, and only the short answer goes to the chat."]),yp=Object.freeze([["index","Content indexed"],["edit","File edits"],["toolerr","Issues kept"],["decision","Your decisions"],["cmd","Other tool calls"],["prompt","Your prompts"]]),Cp=Object.freeze(["ctx_resume brings back your last task, files changed and open issues","after a compact or a restart; ctx_search finds indexed content by words."]);var Ip=Object.freeze([["sandbox","\u2588","sandbox run"],["index","\u2593","index + search"],["redirect","\u2592","hook sent to sandbox"],["replace","\u2591","hook cut down"]]),kp=Object.freeze(["ctx_index","ctx_search"]);var Dp=Object.freeze(["session","source","project"]);var mt="decision";var Mn="AskUserQuestion",hs="answers",gt="option",Ss=" | ",Za="https://github.com/mksglu/context-mode.git";var Lp=Object.freeze(["D1","D2","D3","D4","D5","D5b","D6","D7","D8","D9","D10","D11"]),wp=Object.freeze({D1:"version",D2:"node",D3:"host config",D4:"old entries",D5:"hook round trip",D5b:"double-fire",D6:"MCP",D7:"project and worktree",D8:"context.db",D9:"index",D10:"enforcement mode",D11:"shell"});var bs=256,el="ctx_doctor:report";var Pp=`ctx_search({queries:["FAIL","PASS","UNKNOWN"], source:${JSON.stringify(el)}})`;var Up=Object.freeze(["--tags","--refs"]),tl="v*";var Mp=`git ls-remote --tags --refs ${Za} "${tl}"`;var Hp=`install Node ${Ae} or later`;var Fp=Object.freeze(["MCP entry","hook entries","hook timeout"]);var Os=Object.freeze({"claude-code":[".claude"],codex:[".codex"],gemini:[".gemini"],qwen:[".qwen"],"copilot-cli":[".copilot"],vscode:[".vscode"],kiro:[".kiro"],zcode:[".zcode"],pi:[".pi"],opencode:[".config","opencode"]});var vp=Object.freeze(["upgrade","uninstall"]);var jp=Object.freeze(["clone","--depth","1","--branch"]),Gp=Object.freeze(["rev-parse","HEAD"]);var Bp=Object.freeze(["pi","opencode"]);var Wp=Object.freeze({GIT_TERMINAL_PROMPT:"0"}),Kp=Object.freeze({GIT_CONFIG_COUNT:"1",GIT_CONFIG_KEY_0:"core.autocrlf",GIT_CONFIG_VALUE_0:"false"});var Xp=Object.freeze(["shell","bash","sh"]),qp=Object.freeze([["..","bin","bash.exe"],["..","..","bin","bash.exe"]]);var Yp=Object.freeze(["doctor-env.ts","doctor-config.ts","doctor-hook.ts","doctor-db.ts","doctor-heal.ts","release-fetch.ts","verify-sums.ts","plugin-swap.ts","host-write.ts","v1-remove.ts","uninstall.ts"]);var Vp=Object.freeze({"claude-code":{root:"plugin",file:["hooks","claude-code.json"],key:["hooks"],shape:"nested",timeoutKey:"timeout",matcher:!0},codex:{root:"home",file:[".codex","hooks.json"],key:["hooks"],shape:"nested",timeoutKey:"timeout",matcher:!0},gemini:{root:"plugin",file:["hooks","hooks.json"],key:["hooks"],shape:"nested",timeoutKey:"timeout",matcher:!1},qwen:{root:"plugin",file:["hooks","qwen.json"],key:["hooks"],shape:"nested",timeoutKey:"timeout",matcher:!0},"copilot-cli":{root:"home",file:[".copilot","hooks","context-mode.json"],key:["hooks"],shape:"flat",timeoutKey:"timeoutSec",matcher:!1},vscode:{root:"home",file:[".copilot","hooks","context-mode-vscode.json"],key:["hooks"],shape:"flat",timeoutKey:"timeout",matcher:!1},kiro:{root:"home",file:[".kiro","hooks","context-mode.json"],key:["hooks"],shape:"kiro",timeoutKey:"timeout",matcher:!1},zcode:{root:"home",file:[".zcode","cli","config.json"],key:["hooks","events"],shape:"zcode",timeoutKey:"timeoutMs",matcher:!0},pi:null,opencode:null}),zp=Object.freeze(["PreToolUse","PostToolUse"]);var Jp=Object.freeze([["@mcp","mcp"],["shell","shell"]]);var $p=Object.freeze(["features","hooks"]);var Qp=Object.freeze(["",rt,st]);var Zp=Object.freeze({"claude-code":"claude plugin marketplace update context-mode && claude plugin update context-mode@context-mode",codex:"rewrite config.toml's [mcp_servers.context-mode*] block to the v2 entry, then restart Codex",gemini:"gemini extensions install https://github.com/mksglu/context-mode --ref release --auto-update",qwen:"qwen extensions install https://github.com/mksglu/context-mode --ref release --auto-update"});var e_=Object.freeze(["afteragentresponse.mjs","aftermodel.mjs","aftertool.mjs","agentspawn.mjs","beforeagent.mjs","beforetool.mjs","posttooluse.mjs","precompact.mjs","precompress.mjs","pretooluse.mjs","sessionend.mjs","sessionstart.mjs","stop.mjs","userpromptsubmit.mjs"]);var t_=Object.freeze(["hooks","codex"]);var n_=Object.freeze([".mjs",".sh"]);var ht="CLAUDE_CONFIG_DIR";var nl=Object.freeze(["Code","User"]);var ol="mcp.json",o_=Object.freeze(["agents","default.json"]);var r_=Object.freeze(["steering","KIRO.md"]);var s_=Object.freeze(["opencode.jsonc","opencode.json"]);var i_=Object.freeze(["content","platform.json"]);var Ts="custom";var rl=Object.freeze(["/","\\"]),sl="${/}",c_=Object.freeze([...rl,sl]),Te=Object.freeze({hook:"old context-mode hook entry: command contains context-mode and an old script name or context-mode hook",cacheHealHook:"old context-mode cache-heal SessionStart hook entry",cacheHealFile:"old context-mode cache-heal script file",statusLine:"old context-mode statusLine (context-mode statusline): report only, never removed",mcpEntry:"old context-mode MCP entry mcpServers.context-mode",codexHook:"old context-mode Codex hook entry: context-mode hook codex or hooks/codex/*.mjs",codexToml:"old context-mode config.toml [mcp_servers.context-mode*] section",hookFile:"old context-mode hook file context-mode.json (runs context-mode hook)",vscodeMcp:"old context-mode MCP entry servers.context-mode in .vscode/mcp.json: report only, never removed",kiroHook:"old Kiro hook entry: command contains context-mode and an old script name or context-mode hook",kiroAgentFile:"old context-mode Kiro agent file agents/*.json with name context-mode",kiroSteering:"old context-mode Kiro steering doc .kiro/steering/KIRO.md: manual review, report only, never removed",piNpm:"old context-mode Pi package npm:context-mode",opencodePlugin:"old context-mode OpenCode plugin spec context-mode",zcodeHook:"old context-mode ZCode hook entry: command contains context-mode hook",dataDir:"old context-mode data dir <agent home>/context-mode/",dataDirShared:"old context-mode data dir ~/.gemini/context-mode/: delete only after a prompt (Antigravity shares it)",dataRoot:"old context-mode content under ~/.context-mode/",tmpFile:"old context-mode temp file context-mode-* under the OS temp dir: report only, safe to keep"}),a_=Object.freeze([Te.statusLine,Te.vscodeMcp,Te.dataDirShared,Te.tmpFile,Te.kiroSteering]);var l_=te+"_";var u_=Object.freeze(["opencode","plugin.js"]);var il=Object.freeze(["features","mcp"]),cl="omit_tools_from",al=Object.freeze(["deferred"]),ll="default_tools_approval_mode",ul="approve",d_=Object.freeze({codex:{file:[".codex","config.toml"],key:["mcp_servers",te],fields:{[cl]:al,[ll]:ul}},vscode:{file:[ol],key:["servers",te]},kiro:{file:[".kiro","settings","mcp.json"],key:["mcpServers",te]},zcode:{file:[".zcode","cli","config.json"],key:["mcp","servers",te],fields:{type:"stdio",enabled:!0,timeoutMs:$a},also:[[il,!0]]}});var f_=Object.freeze({NODE_ENV:Object.freeze(["development","production","test"])}),dl="Environment: ";var fl="Docs: ";var xl="Report file: ",pl="File it: ",_l="Or open: ",El=" --",x_=Object.freeze([dl,fl,xl,pl,El.trim(),_l]),ml="mksglu/context-mode",gl="agent-report.yml";var p_=Object.freeze(["Summary","ctx-report","What happened","Hook errors","Journal rows","Agent config","Expected","Steps","Environment"]);var __=Object.freeze(["CODEX_HOME","CLAUDE_CONFIG_DIR","CLAUDE_PLUGIN_ROOT","COPILOT_HOME","KIRO_HOME","OPENCODE_CONFIG_DIR","PI_CODING_AGENT_DIR","XDG_CONFIG_HOME","SHELL"]),E_=Object.freeze(["node","git","sh"]),m_=Object.freeze(["token","secret","password","apikey","api_key","authorization","bearer"]);var g_=Object.freeze({"claude-code":["claude plugin marketplace add mksglu/context-mode#release","claude plugin install context-mode@context-mode"],codex:["codex plugin marketplace add mksglu/context-mode@release","codex plugin add context-mode@context-mode"],gemini:["gemini extensions install https://github.com/mksglu/context-mode --ref release"],qwen:["qwen extensions install https://github.com/mksglu/context-mode:context-mode --ref release"],opencode:["opencode plugin add context-mode@next"],pi:["pi install npm:context-mode@next"],"copilot-cli":["npm i -g context-mode@next","context-mode setup --agents copilot-cli"],vscode:["npm i -g context-mode@next","context-mode setup --agents vscode"],kiro:["npm i -g context-mode@next","context-mode setup --agents kiro"],zcode:["npm i -g context-mode@next","context-mode setup --agents zcode"]}),h_=`https://github.com/${ml}/issues/new?template=${gl}`;import{dirname as Px,join as Ux}from"node:path";var Hn="mcp__plugin_context-mode_context-mode__",hl=["SessionStart","UserPromptSubmit","PreToolUse","PostToolUse"],Rs="mcp__",As="__",Sl={startup:"startup",resume:"resume",clear:"clear",compact:"compact"};function bl(e,t){if(e.startsWith(t))return e.slice(t.length);if(!e.startsWith(Rs))return e;let n=e.slice(Rs.length),o=n.indexOf(As);return o<0?e:"mcp:"+n.slice(0,o)+":"+n.slice(o+As.length)}function Ol(e){if(e===void 0)return"";if(typeof e=="string")return e;if(Array.isArray(e))return ys(e).text;if(typeof e=="object"&&e!==null){let t=e;if(typeof t.stdout=="string"||typeof t.stderr=="string"){let n=typeof t.stdout=="string"?t.stdout:"",o=typeof t.stderr=="string"?t.stderr:"";return o===""?n:n===""?o:n+`
4
4
  `+o}}return typeof e=="object"&&e!==null&&Ns(e)?e.content:JSON.stringify(e)}function Ns(e){let t=e;return t.mode==="content"&&typeof t.content=="string"}function ys(e){let t=[],n=!1;for(let o of e){let r=typeof o=="object"&&o!==null?o:{};r.type==="text"&&typeof r.text=="string"?t.push(r.text):n=!0}return{text:t.join(`
5
5
  `),keep:n}}function Tl(e){let t=Ol(e),o={isError:typeof e=="object"&&e!==null&&e.is_error===!0,bytes:Buffer.byteLength(t),text:t};if(typeof e=="object"&&e!==null&&!Array.isArray(e)&&Ns(e)&&(o.shape=e),Array.isArray(e)&&(o.blocks=!0,ys(e).keep&&(o.keep=!0)),typeof e=="object"&&e!==null){let r=e;typeof r.persistedOutputPath=="string"&&r.persistedOutputPath!==""&&typeof r.persistedOutputSize=="number"&&r.persistedOutputSize>o.bytes&&(o.persistedPath=r.persistedOutputPath)}return o}function oe(e,t,n,o){if(typeof e!="object"||e===null||Array.isArray(e))throw new Error(t+": hook payload is not a JSON object");let r=e,s=hl.find(c=>c===r.hook_event_name);if(s===void 0)throw new Error(t+": unknown hook event "+String(r.hook_event_name));let i={event:s,agent:t,sessionId:String(r.session_id??""),cwd:String(r.cwd??"")};if(typeof r.agent_id=="string"&&(i.agentId=r.agent_id,typeof r.agent_type=="string"&&(i.agentType=r.agent_type)),s==="SessionStart"&&typeof r.source=="string"&&o[r.source]!==void 0&&(i.source=o[r.source]),s==="UserPromptSubmit"&&typeof r.prompt=="string"&&(i.prompt=r.prompt),s==="PreToolUse"||s==="PostToolUse"){let c=String(r.tool_name??""),a=typeof r.tool_input=="object"&&r.tool_input!==null?r.tool_input:{},l={name:c,canonicalName:bl(c,n),input:a};typeof r.tool_use_id=="string"&&r.tool_use_id!==""&&(l.callId=r.tool_use_id),i.tool=l}return s==="PostToolUse"&&(i.result=Tl(r.tool_response)),i}function Rl(e,t){return e.tool?.canonicalName==="Bash"?{stdout:t,stderr:"",interrupted:!1}:e.result?.shape!==void 0?{...e.result.shape,content:t}:e.result?.blocks===!0?[{type:"text",text:t}]:t}function F(e,t,n){let o=r=>({stdout:JSON.stringify({hookSpecificOutput:{hookEventName:e.event,...r}}),exitCode:0});switch(t.kind){case"allow":return{stdout:"",exitCode:0};case"hint":return o({additionalContext:t.text});case"deny":return o({permissionDecision:"deny",permissionDecisionReason:t.rewritten===void 0?t.reason:t.rewritten+`
6
6
  `+t.reason});case"replace":return n&&e.event==="PostToolUse"?o({updatedToolOutput:Rl(e,t.output)}):{stdout:"",exitCode:0}}}var Al={PreToolUse:["tool_name"],PostToolUse:["tool_name","tool_response"]};function Nl(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}function yl(e){if(typeof e!="object"||e===null||Array.isArray(e))return;let t=e;if(t.hook_event_name===void 0)throw new Error("claude-code: missing required field hook_event_name");for(let n of Al[t.hook_event_name]??[])if(t[n]===void 0)throw new Error("claude-code: missing required field "+n)}function Cs(e){yl(e);let t=oe(e,"claude-code",Hn,Sl);if(t.cwd===""&&(t.cwd=process.env.CLAUDE_PROJECT_DIR||process.cwd()),t.event==="PostToolUse"&&t.tool!==void 0&&t.tool.callId===void 0){let n=typeof t.tool.input.command=="string"?t.tool.input.command:JSON.stringify(t.tool.input);t.tool.callId="h"+Nl(t.tool.name+"\0"+n+"\0"+String(t.turn??0))}return t}function Is(e,t,n){return F(e,t,!0)}var Fn="mcp__context_mode__",Il={startup:"startup",resume:"resume",clear:"clear",compact:"compact",fork:"resume"};function ks(e){return oe(e,"codex",Fn,Il)}function Ds(e,t,n){return F(e,t,!1)}var bt="mcp_context-mode_",Ls={SessionStart:"SessionStart",BeforeAgent:"UserPromptSubmit",BeforeTool:"PreToolUse",AfterTool:"PostToolUse",PreCompress:"PreCompact"},ws={startup:"startup",resume:"resume",clear:"clear"},Dl=["SessionStart","UserPromptSubmit","PostToolUse"],Ll=["UserPromptSubmit","PreToolUse"],St={stdout:"",exitCode:0};function N(e,t){return Object.hasOwn(e,t)?e[t]:void 0}var Ps={run_shell_command:"Bash",read_file:"Read",grep_search:"Grep",web_fetch:"WebFetch"};function wl(e,t){if(e.startsWith(bt))return e.slice(bt.length);if(Object.hasOwn(Ps,e))return Ps[e];if(typeof t!="object"||t===null)return e;let n=t,o=N(n,"server_name"),r=N(n,"tool_name");return typeof o!="string"||typeof r!="string"?e:"mcp:"+o+":"+r}function Pl(e){let t=typeof e=="object"&&e!==null?e:void 0,n=t===void 0?void 0:N(t,"llmContent"),o=e===void 0?"":typeof e=="string"?e:typeof n=="string"?n:JSON.stringify(e),r=t===void 0?void 0:N(t,"error");return{isError:r!=null,bytes:Buffer.byteLength(o),text:o}}function Us(e){if(typeof e!="object"||e===null||Array.isArray(e))throw new Error("gemini: hook payload is not a JSON object");let t=e,n=N(t,"hook_event_name"),o=typeof n=="string"&&Object.hasOwn(Ls,n)?Ls[n]:void 0;if(o===void 0)throw new Error("gemini: unknown hook event "+String(n));let r={event:o,agent:"gemini",sessionId:String(N(t,"session_id")??""),cwd:String(N(t,"cwd")??"")},s=N(t,"source");o==="SessionStart"&&typeof s=="string"&&Object.hasOwn(ws,s)&&(r.source=ws[s]);let i=N(t,"prompt");if(o==="UserPromptSubmit"&&typeof i=="string"&&(r.prompt=i),o==="PreToolUse"||o==="PostToolUse"){let c=String(N(t,"tool_name")??""),a=N(t,"tool_input");r.tool={name:c,canonicalName:wl(c,N(t,"mcp_context")),input:typeof a=="object"&&a!==null&&!Array.isArray(a)?a:{}}}return o==="PostToolUse"&&(r.result=Pl(N(t,"tool_response"))),r}function Ms(e,t,n){switch(t.kind){case"allow":return St;case"hint":return Dl.includes(e.event)?{stdout:JSON.stringify({hookSpecificOutput:{additionalContext:t.text}}),exitCode:0}:St;case"deny":return Ll.includes(e.event)?{stdout:JSON.stringify({decision:"deny",reason:t.rewritten===void 0?t.reason:t.rewritten+`
@@ -22,9 +22,9 @@ Run the command on the line above with Bash instead. It runs the same command in
22
22
  `)d(),x++;else if(id.includes(p))l(),x++;else if(p===";")d(),x++;else if(p==="|")m==="|"?(d(),x+=Ht):(u(),x++);else if(p==="&")m==="&"?(d(),x+=Ht):((s||o.words.length>0)&&f(p,!1),x++);else if(p==="#"&&!s)for(;x<a&&e.charAt(x)!==`
23
23
  `;)x++;else if(p===">"){let E=Zi;s&&i&&dd(r)?(E=r,r="",s=!1):s&&l();let h=x+1;if(e.charAt(h)===">"&&h++,e.charAt(h)==="&")for(h++;h<a&&!co.includes(e.charAt(h));)h++;else c=E===Zi||E===tc?"file":"skip";x=h}else if(p==="("&&s&&i&&r.includes(ao)){let E=je(e,x),h=e.slice(x+1,E<0?a:E);l();for(let S of h.trim()===""?[]:ud(h)){let _=nc(S)[0]?.[0]?.words[0];o.words.push(_??S.trim())}x=E<0?a:E+1,x<a&&!co.includes(e.charAt(x))&&(o.chained=!0,x=ld(e,x))}else if(p==="["&&!s&&e.startsWith(ao,je(e,x)+1)&&je(e,x)>=0){let E=je(e,x);f(e.slice(x,E+1),!1),x=E+1}else if(Ge.includes(p)&&(p!=="["||!s)||(p==="$"||p==="@")&&Ge.includes(m)&&m!=="["){let E=p==="$"||p==="@"?x+1:x,h=je(e,E);f(e.slice(x,h<0?a:h+1),!0),x=h<0?a:h+1}else f(p,!1),x++}return d(),t}var fd=["get-content","gc","cat","type"],xd=["[io.file]::","[system.io.file]::"],pd=["readalltext","readalllines","readallbytes","readlines"],fo=["path","literalpath"],oc=["totalcount","head","first","tail","last"],rc=[...fo,...oc,"encoding","readcount","delimiter","filter","include","exclude","stream","credential"],_d=["raw","wait","force","asbytestream"],Ed=[...rc,..._d],md=["out-string","write-output","echo","write","out-host","write-host","out-default","tee-object"],gd=["cd","chdir","sl","set-location","pushd","push-location"],hd=["powershell","powershell.exe","pwsh","pwsh.exe"],Sd=["cmd","cmd.exe"],bd=["/c","/k","/r"],Od="command",ie="-";function lo(e){let t=Math.max(e.lastIndexOf("\\"),e.lastIndexOf("/"));return(t>=0&&t<e.length-1?e.slice(t+1):e).toLowerCase()}function xo(e,t){let n=e.slice(ie.length),o=n.indexOf(":"),r=(o<0?n:n.slice(0,o)).toLowerCase(),s=o<0?void 0:n.slice(o+1);if(r==="")return{full:void 0,inline:s};if(t.includes(r))return{full:r,inline:s};let i=t.filter(c=>c.startsWith(r));return{full:i.length===1?i[0]:void 0,inline:s}}function Td(e){if(e.length===0)return null;let t=lo(e[0]);if(!fd.includes(t)){let r=e[0].toLowerCase(),s=xd.find(i=>r.startsWith(i));return s===void 0||!pd.includes(r.slice(s.length))||e.length<cd?null:{file:e[1],bounded:!1}}let n=[],o=!1;for(let r=1;r<e.length;r++){let s=e[r];if(!s.startsWith(ie)||s.length===ie.length){n.push(s);continue}let i=xo(s,Ed);if(i.full===void 0||!rc.includes(i.full))continue;let c=i.inline??e[++r];if(c===void 0)return null;fo.includes(i.full)&&n.push(c),oc.includes(i.full)&&(o=!0)}return n.length===1?{file:n[0],bounded:o}:null}function Rd(e,t){if(hd.includes(e)){for(let n=1;n<t.length;n++){let o=t[n];if(!o.startsWith(ie)||o.length===ie.length)continue;let r=xo(o,[Od]);if(r.full!==void 0)return[...r.inline===void 0?[]:[r.inline],...t.slice(n+1)].join(" ")}return null}if(Sd.includes(e)){for(let n=1;n<t.length;n++)if(bd.includes(t[n].toLowerCase()))return t.slice(n+1).join(" ")}return null}function Ad(e){for(let t=1;t<e.length;t++){let n=e[t];if(n.toLowerCase()==="/d")continue;if(!n.startsWith(ie)||n.length===ie.length)return n;let o=xo(n,fo);if(o.full!==void 0)return o.inline??e[t+1]??null}return null}function sc(e,t,n,o){let r=t;for(let s of nc(e)){let i=s[0];if(i.words.length===0)continue;let c=lo(i.words[0]);if(s.length===1&&gd.includes(c)){let d=Ad(i.words);d!==null&&(r=Qi(r,d));continue}let a=n<H?Rd(c,i.words):null;if(a!==null){sc(a,r,n+1,o);continue}if(i.toFile||i.chained)continue;let l=Td(i.words);if(l===null||l.bounded)continue;let u=!0;for(let d=1;d<s.length;d++)if(s[d].toFile||!md.includes(lo(s[d].words[0]??""))){u=!1;break}u&&o.push(Qi(r,l.file))}}function ic(e,t){let n=[];return sc(e,t,0,n),n}import{join as Bt}from"node:path";var cc=`\r
24
24
  `,Nd=`
25
- `;function Gt(e){let t=e.length>0&&e.charCodeAt(0)===65279?e.slice(1):e;return t.indexOf(cc)<0?t:t.split(cc).join(Nd)}import{basename as V_,dirname as z_,join as ac,posix as J_,resolve as $_,win32 as Q_}from"node:path";var yd=Object.freeze({NODE_TOO_OLD:"Node <v> is below 24.15.0. Fix: install Node 24.15.0 or later.",NO_SQLITE:"node:sqlite failed to load. Fix: run ctx_doctor.",DB_GONE:"context.db path vanished. Fix: run ctx_doctor.",NO_PROJECT:"Project source <kind> is missing. Fix: run ctx_doctor.",UNKNOWN_FIELD:'Unknown field "<f>". Fix: use "queries".',TIMEOUT:"Timed out after <ms> ms. Fix: pass background: true.",NO_GIT_BASH:"Git Bash not found. Fix: install Git for Windows.",NO_RUNTIME:"No <lang> runtime on PATH. Fix: install it or pick another language.",FETCH_FAILED:"Fetch failed: <code>. Fix: check the URL or proxy.",SSRF:"Blocked private address <host>. Fix: use a public URL.",OUTSIDE_ROOT:"Path <p> is outside the project. Fix: use a path inside <root>.",INVALID_ARGS:"Invalid argument <field>. Fix: <action>.",ONE_OF_INPUT:"Pass exactly one of <names>. Fix: drop the extra field.",SPAWN_FAILED:"Failed to start the process: <detail>. Fix: check the command and PATH.",DB_CORRUPT:"context.db failed integrity_check. Fix: run ctx_doctor.",SCHEMA_STALE:"context.db schema is version <found>, expected <want>. Fix: run ctx_doctor.",NO_GIT_DIR:"No git repository at <path>. Fix: run context-mode inside a git repository.",NO_HOME:"Env var <name> is not set. Fix: set <name> to your home directory.",PLUGIN_ROOT_MISSING:"Plugin root for <agent> not found at <path>. Fix: run ctx_upgrade.",BUNDLE_HASH_MISMATCH:"Fetched bundle hash does not match SHA256SUMS. Fix: run ctx_upgrade again.",CONFIG_PARSE_FAILED:"<agent> config at <path> did not parse as <format>. Fix: fix the syntax error and re-run ctx_upgrade."});function Cd(e,t){let n=yd[e],o="",r=0;for(;r<n.length;){if(n[r]!=="<"){o+=n[r],r+=1;continue}let s=r+1;for(;s<n.length&&n[s]!=="<"&&n[s]!==">";)s+=1;if(s>=n.length){o+=n.slice(r);break}if(n[s]==="<"){o+="<",r+=1;continue}let i=n.slice(r+1,s),c=t[i];if(c===void 0)throw new Error("formatError: missing var "+i+" for "+e);o+=String(c),r=s+1}return o}var T=class extends Error{code;vars;constructor(t,n){super(Cd(t,n??{})),this.code=t,this.vars=n??{}}toLine(){return this.message}};var{mkdirSync:Id,realpathSync:kd}=process.getBuiltinModule("node:fs");function ge(e,t=process.platform){let n=o=>o!==void 0&&o!=="";return t==="win32"?n(e.USERPROFILE)?e.USERPROFILE:n(e.HOMEDRIVE)&&n(e.HOMEPATH)?e.HOMEDRIVE+e.HOMEPATH:n(e.HOME)?e.HOME:null:n(e.HOME)?e.HOME:n(e.USERPROFILE)?e.USERPROFILE:null}function Be(e,t){let n=e[ht];return n!==void 0&&n!==""?n:ac(t,...Os["claude-code"])}function Dd(e,t=process.platform){let n=ge(e,t);if(n!==null)return n;throw new T("NO_HOME",{name:t==="win32"?"USERPROFILE":"HOME"})}function lc(e){let t=ac(Dd(e),ct.slice(1));return Id(t,{recursive:!0}),kd.native(t)}var{readFileSync:xc}=process.getBuiltinModule("node:fs");function he(e){return e.agentId!==void 0&&e.agentId!==""}function Eo(e,t){if(t===null)return"C";let n=re(e.agent),o=new Set(t);for(let r of ot)if(o.has(n.toolNamePrefix+r))return"A";for(let r of n.nativeTools.shell)if(o.has(r))return"B";return"C"}function mo(e,t){if(!he(e))return null;let n=re(e.agent);if(t.manifestTools!==void 0)return fc(t.manifestTools.map(c=>po(n,c)));let o=e.agentType??"",r=Ld(o,t);if(r===null)return null;let s=(r.tools??Hd(n)).map(c=>po(n,c)),i=r.disallowed.map(c=>po(n,c));return fc(s.filter(c=>!i.some(a=>vd(a,c))))}function Ld(e,t){if(!wd(e))return null;let n=Pd(t.env);if(e.indexOf(de)>=0){if(n!==null){let s=Ud(Be(t.env,n),e);if(s!==null)return s}}else{let s=_o(Bt(t.projectDir,Or,at,e+lt));if(s!==null)return s;if(n!==null){let i=_o(Bt(Be(t.env,n),at,e+lt));if(i!==null)return i}}let r=t.cliAgents;if(r!==void 0&&Object.prototype.hasOwnProperty.call(r,e)){let s=r[e];return{tools:Array.isArray(s.tools)?s.tools:null,disallowed:Array.isArray(s.disallowedTools)?s.disallowedTools:[]}}return null}function wd(e){if(e===""||e==="."||e===".."||e.indexOf("/")>=0||e.indexOf("\\")>=0)return!1;for(let t of e.split(de))if(t===""||t==="."||t==="..")return!1;return!0}function Pd(e){return ge(e)}function Ud(e,t){let n=t.indexOf(de),o=t.slice(0,n),r=t.slice(n+de.length);if(r.indexOf(de)>=0)return null;let s;try{s=JSON.parse(Gt(xc(Bt(e,hn,Tr),"utf8")))}catch{return null}let i=s?.plugins;if(i===null||typeof i!="object")return null;for(let c of Object.keys(i)){let a=c.indexOf(Rr);if((a<0?c:c.slice(0,a))!==o)continue;let l=i[c];if(Array.isArray(l))for(let u of l){let d=u?.installPath;if(typeof d!="string"||d==="")continue;let f=_o(Bt(d,at,r+lt));if(f!==null)return f}}return null}function _o(e){let t;try{t=xc(e,"utf8")}catch{return null}return Md(t)}function Md(e){let t=e.split(`
25
+ `;function Gt(e){let t=e.length>0&&e.charCodeAt(0)===65279?e.slice(1):e;return t.indexOf(cc)<0?t:t.split(cc).join(Nd)}import{basename as z_,dirname as J_,join as ac,posix as $_,resolve as Q_,win32 as Z_}from"node:path";var yd=Object.freeze({NODE_TOO_OLD:"Node <v> is below 24.15.0. Fix: install Node 24.15.0 or later.",NO_SQLITE:"node:sqlite failed to load. Fix: run ctx_doctor.",DB_GONE:"context.db path vanished. Fix: run ctx_doctor.",NO_PROJECT:"Project source <kind> is missing. Fix: run ctx_doctor.",UNKNOWN_FIELD:'Unknown field "<f>". Fix: use "queries".',TIMEOUT:"Timed out after <ms> ms. Fix: pass background: true.",NO_GIT_BASH:"Git Bash not found. Fix: install Git for Windows.",NO_RUNTIME:"No <lang> runtime on PATH. Fix: install it or pick another language.",FETCH_FAILED:"Fetch failed: <code>. Fix: check the URL or proxy.",SSRF:"Blocked private address <host>. Fix: use a public URL.",OUTSIDE_ROOT:"Path <p> is outside the project. Fix: use a path inside <root>.",INVALID_ARGS:"Invalid argument <field>. Fix: <action>.",ONE_OF_INPUT:"Pass exactly one of <names>. Fix: drop the extra field.",SPAWN_FAILED:"Failed to start the process: <detail>. Fix: check the command and PATH.",DB_CORRUPT:"context.db failed integrity_check. Fix: run ctx_doctor.",SCHEMA_STALE:"context.db schema is version <found>, expected <want>. Fix: run ctx_doctor.",NO_GIT_DIR:"No git repository at <path>. Fix: run context-mode inside a git repository.",NO_HOME:"Env var <name> is not set. Fix: set <name> to your home directory.",PLUGIN_ROOT_MISSING:"Plugin root for <agent> not found at <path>. Fix: run ctx_upgrade.",BUNDLE_HASH_MISMATCH:"Fetched bundle hash does not match SHA256SUMS. Fix: run ctx_upgrade again.",CONFIG_PARSE_FAILED:"<agent> config at <path> did not parse as <format>. Fix: fix the syntax error and re-run ctx_upgrade."});function Cd(e,t){let n=yd[e],o="",r=0;for(;r<n.length;){if(n[r]!=="<"){o+=n[r],r+=1;continue}let s=r+1;for(;s<n.length&&n[s]!=="<"&&n[s]!==">";)s+=1;if(s>=n.length){o+=n.slice(r);break}if(n[s]==="<"){o+="<",r+=1;continue}let i=n.slice(r+1,s),c=t[i];if(c===void 0)throw new Error("formatError: missing var "+i+" for "+e);o+=String(c),r=s+1}return o}var T=class extends Error{code;vars;constructor(t,n){super(Cd(t,n??{})),this.code=t,this.vars=n??{}}toLine(){return this.message}};var{mkdirSync:Id,realpathSync:kd}=process.getBuiltinModule("node:fs");function ge(e,t=process.platform){let n=o=>o!==void 0&&o!=="";return t==="win32"?n(e.USERPROFILE)?e.USERPROFILE:n(e.HOMEDRIVE)&&n(e.HOMEPATH)?e.HOMEDRIVE+e.HOMEPATH:n(e.HOME)?e.HOME:null:n(e.HOME)?e.HOME:n(e.USERPROFILE)?e.USERPROFILE:null}function Be(e,t){let n=e[ht];return n!==void 0&&n!==""?n:ac(t,...Os["claude-code"])}function Dd(e,t=process.platform){let n=ge(e,t);if(n!==null)return n;throw new T("NO_HOME",{name:t==="win32"?"USERPROFILE":"HOME"})}function lc(e){let t=ac(Dd(e),ct.slice(1));return Id(t,{recursive:!0}),kd.native(t)}var{readFileSync:xc}=process.getBuiltinModule("node:fs");function he(e){return e.agentId!==void 0&&e.agentId!==""}function Eo(e,t){if(t===null)return"C";let n=re(e.agent),o=new Set(t);for(let r of ot)if(o.has(n.toolNamePrefix+r))return"A";for(let r of n.nativeTools.shell)if(o.has(r))return"B";return"C"}function mo(e,t){if(!he(e))return null;let n=re(e.agent);if(t.manifestTools!==void 0)return fc(t.manifestTools.map(c=>po(n,c)));let o=e.agentType??"",r=Ld(o,t);if(r===null)return null;let s=(r.tools??Hd(n)).map(c=>po(n,c)),i=r.disallowed.map(c=>po(n,c));return fc(s.filter(c=>!i.some(a=>vd(a,c))))}function Ld(e,t){if(!wd(e))return null;let n=Pd(t.env);if(e.indexOf(de)>=0){if(n!==null){let s=Ud(Be(t.env,n),e);if(s!==null)return s}}else{let s=_o(Bt(t.projectDir,Or,at,e+lt));if(s!==null)return s;if(n!==null){let i=_o(Bt(Be(t.env,n),at,e+lt));if(i!==null)return i}}let r=t.cliAgents;if(r!==void 0&&Object.prototype.hasOwnProperty.call(r,e)){let s=r[e];return{tools:Array.isArray(s.tools)?s.tools:null,disallowed:Array.isArray(s.disallowedTools)?s.disallowedTools:[]}}return null}function wd(e){if(e===""||e==="."||e===".."||e.indexOf("/")>=0||e.indexOf("\\")>=0)return!1;for(let t of e.split(de))if(t===""||t==="."||t==="..")return!1;return!0}function Pd(e){return ge(e)}function Ud(e,t){let n=t.indexOf(de),o=t.slice(0,n),r=t.slice(n+de.length);if(r.indexOf(de)>=0)return null;let s;try{s=JSON.parse(Gt(xc(Bt(e,hn,Tr),"utf8")))}catch{return null}let i=s?.plugins;if(i===null||typeof i!="object")return null;for(let c of Object.keys(i)){let a=c.indexOf(Rr);if((a<0?c:c.slice(0,a))!==o)continue;let l=i[c];if(Array.isArray(l))for(let u of l){let d=u?.installPath;if(typeof d!="string"||d==="")continue;let f=_o(Bt(d,at,r+lt));if(f!==null)return f}}return null}function _o(e){let t;try{t=xc(e,"utf8")}catch{return null}return Md(t)}function Md(e){let t=e.split(`
26
26
  `).map(i=>i.endsWith("\r")?i.slice(0,-1):i);if(t.length===0||t[0].trim()!==Sn)return null;let n=-1;for(let i=1;i<t.length;i++)if(t[i].trim()===Sn){n=i;break}if(n<0)return null;let o=t.slice(1,n),r=uc(o,Ar),s=uc(o,Nr);return{tools:r!==null&&r.length>0?r:null,disallowed:s??[]}}function uc(e,t){for(let n=0;n<e.length;n++){let o=e[n];if(!o.startsWith(t+":"))continue;let r=o.slice(t.length+1).trim();if(r===""){let s=[];for(let i=n+1;i<e.length;i++){let c=e[i].trim();if(!c.startsWith("-"))break;s.push(dc(c.slice(1).trim()))}return s.filter(i=>i!=="")}return r.startsWith("[")&&r.endsWith("]")&&(r=r.slice(1,-1)),r.split(",").map(s=>dc(s.trim())).filter(s=>s!=="")}return null}function dc(e){return e.length>1&&(e[0]==='"'||e[0]==="'")&&e.endsWith(e[0])?e.slice(1,-1):e}function Hd(e){let t=e.nativeTools;return[...t.shell,...t.read??[],...t.grep??[],...t.webfetch??[],...t.edit??[],...ot.map(n=>e.toolNamePrefix+n)]}function po(e,t){let n=t.indexOf("("),o=(n>=0?t.slice(0,n):t).trim();return e.id==="gemini"&&o.startsWith(yr)?Fd(o):o}function Fd(e){let t="";for(let n of e){let o=n>="a"&&n<="z"||n>="A"&&n<="Z"||n>="0"&&n<="9"||Cr.indexOf(n)>=0;t+=o?n:"_"}return t}function vd(e,t){if(e.endsWith("*"))return t.startsWith(e.slice(0,-1));if(e===t)return!0;if(e.startsWith(bn)){let n=e.slice(bn.length);if(n!==""&&n.indexOf(On)<0)return t.startsWith(e+On)}return!1}function fc(e){return[...new Set(e.filter(t=>t!==""))]}var ce="",pc=Object.freeze({sudo:{valueShorts:"ugpChDrtUTR",valueLongs:["--user","--group","--prompt","--chdir","--host"],assignments:!0,duration:!1,refuseShorts:ce},env:{valueShorts:"uCS",valueLongs:["--unset","--chdir","--split-string"],assignments:!0,duration:!1,refuseShorts:ce},time:{valueShorts:"fo",valueLongs:["--format","--output"],assignments:!1,duration:!1,refuseShorts:ce},nice:{valueShorts:"n",valueLongs:["--adjustment"],assignments:!1,duration:!1,refuseShorts:ce},timeout:{valueShorts:"sk",valueLongs:["--signal","--kill-after"],assignments:!1,duration:!0,refuseShorts:ce},command:{valueShorts:ce,valueLongs:[],assignments:!1,duration:!1,refuseShorts:"vV"},xargs:{valueShorts:"aEdILnPs",valueLongs:["--arg-file","--delimiter","--max-args","--max-procs","--max-chars"],assignments:!1,duration:!1,refuseShorts:ce}}),jd=["bash","sh","zsh"],Gd="c",Bd=" -c",Wd=["-o","+o","-O","+O"],Wt="-",Kd="+",go="--",Xd="smhd",qd=".",_c=e=>e!==""&&e>="0"&&e<="9";function Yd(e){if(e===""||!_c(e.charAt(0)))return!1;for(let t=0;t<e.length;t++){let n=e.charAt(t);if(!(_c(n)||n===qd))return t===e.length-1&&Xd.includes(n)}return!0}function Vd(e,t){let n=0;for(;n<t.length;){let o=t[n];if(o===go){n++;break}if(e.assignments&&Pt(o)){n++;continue}if(o.startsWith(go)){n++,e.valueLongs.includes(o)&&n++;continue}if(o.startsWith(Wt)&&o.length>Wt.length){n++;for(let r of e.refuseShorts)if(o.includes(r))return null;for(let r=Wt.length;r<o.length;r++)if(e.valueShorts.includes(o.charAt(r))){r===o.length-1&&n++;break}continue}break}if(e.duration){if(n>=t.length||!Yd(t[n]))return null;n++}return n<t.length?t.slice(n):null}function zd(e){let t=!1;for(let n=0;n<e.length;n++){let o=e[n];if(!o.startsWith(go)){if(o.startsWith(Wt)||o.startsWith(Kd)){o.includes(Gd)&&(t=!0),Wd.includes(o)&&n++;continue}return t?o:null}}return null}function Ec(e,t){let n={...e};return n.insideConstruct===void 0&&t.insideConstruct!==void 0&&(n.insideConstruct=t.insideConstruct),n}function ho(e,t,n,o){let r=[...t],s=e.argv0,i=e.args,c=e.redirectsToFile;for(;;){let a=s.toLowerCase();if(jd.includes(a)){let d=zd(i),f=d!==null&&n<H?ve(d):null;if(f===null||!f.ok)break;for(let x of f.commands){let p=Ec(x,e);p.redirectsToFile=x.redirectsToFile||c,p.endsInBoundedSink=x.endsInBoundedSink||e.endsInBoundedSink,ho(p,[...r,a+Bd],n+1,o)}return}let l=Object.hasOwn(pc,a)?pc[a]:void 0,u=l===void 0?null:Vd(l,i);if(u===null)break;r.push(a),s=ro(u[0]),i=u.slice(1),c=c||so(s,i)}if(o.push({...e,argv0:s,args:i,redirectsToFile:c,wrappedBy:r}),!(n>=H))for(let a of wt(e.raw)){let l=ve(a.body);if(l.ok)for(let u of l.commands)ho(Ec(u,e),[...t,a.wrapper],n+1,o)}}function mc(e){let t=[];for(let n of e)ho(n,[],0,t);return t}import{isAbsolute as $d,join as So,relative as Qd,sep as bo}from"node:path";var{readFileSync:Jd}=process.getBuiltinModule("node:fs"),gc=".claude",Zd="settings.local.json",hc="settings.json",ef="Bash",tf="Read",Sc=":*",bc="//",Oc="~/",Tc="./",Rc="..",nf=`
27
- \r`,of=Object.freeze({tool:ef});function rf(e,t){if(t!=="claude-code")return[];let n=ge(process.env),o=process.env[ht],r=o!==void 0&&o!==""?o:n===null?null:Be(process.env,n),s=[So(e,gc,Zd),So(e,gc,hc)];return r===null?s:[...s,So(r,hc)]}function Ac(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function sf(e){let t;try{t=Gt(Jd(e,"utf8"))}catch(s){return s.code==="ENOENT"?{kind:"absent"}:{kind:"bad"}}let n;try{n=JSON.parse(t)}catch{return{kind:"bad"}}if(!Ac(n))return{kind:"bad"};let o=n.permissions;if(o===void 0)return{kind:"ok",deny:[]};if(!Ac(o))return{kind:"bad"};let r=o.deny;return r===void 0?{kind:"ok",deny:[]}:!Array.isArray(r)||!r.every(s=>typeof s=="string")?{kind:"bad"}:{kind:"ok",deny:r}}function Nc(e,t){let n=[];for(let o of rf(e,t)){let r=sf(o);if(r.kind==="bad")return null;r.kind==="ok"&&n.push(...r.deny)}return n}function cf(e,t){let n=[],o=0;for(;o<e.length;){let r=e[o];if(r==="*"&&t&&e[o+1]==="*"){let s=e[o+2]==="/";n.push({t:s?"globstarDir":"globstar"}),o+=s?3:2;continue}r==="*"?(n.length===0||n[n.length-1].t!=="star")&&n.push({t:"star"}):r==="?"?n.push({t:"any1"}):n.push({t:"lit",c:r}),o++}return n}function Y(e,t,n){let o=cf(e,n),r=t.length,s=new Uint8Array(r+1);s[r]=1;for(let i=o.length-1;i>=0;i--){let c=o[i],a=new Uint8Array(r+1),l=0;for(let u=r;u>=0;u--){let d=u<r,f=d?t[u]:"";switch(c.t){case"lit":a[u]=d&&f===c.c?s[u+1]:0;break;case"any1":a[u]=d&&!(n&&f==="/")?s[u+1]:0;break;case"star":a[u]=s[u]||(d&&!(n&&f==="/")?a[u+1]:0);break;case"globstar":a[u]=s[u]||(d?a[u+1]:0);break;case"globstarDir":d&&f==="/"&&s[u+1]&&(l=1),a[u]=s[u]||l;break}}s=a}return s[0]===1}function af(e){let t=e.indexOf("(");if(t<1||!e.endsWith(")"))return null;let n=e.slice(t+1,e.length-1);return n===""?null:{tool:e.slice(0,t),glob:n}}function lf(e,t){if(!e.endsWith(Sc))return Y(e,t,!1);let n=e.slice(0,e.length-Sc.length);if(Y(n,t,!1))return!0;for(let o=0;o<t.length;o++)if(nf.includes(t[o])&&Y(n,t.slice(0,o),!1))return!0;return!1}var uf=/^[A-Za-z]:(?=\/)/;function We(e){return bo==="/"?e:e.split(bo).join("/")}function df(e,t,n){if(e.startsWith(Tc)){if(n===void 0)return!1;let r=Qd(n,t);return r===""||r===Rc||r.startsWith(Rc+bo)||$d(r)?!1:Y(e.slice(Tc.length),We(r),!0)}let o=We(t);if(e.startsWith(bc)){let r=We(e.slice(bc.length-1));return Y(r,o,!0)||Y(r,o.replace(uf,""),!0)}if(e.startsWith(Oc)){let r=ge(process.env);return r!==null&&Y(We(r)+e.slice(Oc.length-1),o,!0)}return Y(We(e),o,!0)}function V(e,t,n=of){for(let o of t){let r=af(o);if(r===null||r.tool!==n.tool)continue;if(n.tool===tf?df(r.glob,e,n.projectDir):lf(r.glob,e))return o}return null}var mE=Object.freeze({ctx_execute:'Example: `ctx_execute({language:"shell",code:"git log --oneline -5"})`. Required: language, code.\nRuns code in a sandboxed subprocess in the project directory (shell, powershell, javascript, typescript, python, or another runtime on PATH); only what the code prints comes back. For a large file, set `file` to its local path: the code gets it in the CTX_FILE environment variable. Set `intent` when output may be large: the matching sections come back and the full output is indexed for ctx_search. `timeoutMs` defaults to and caps at 600000; then the whole process tree is killed.',ctx_batch:'Example: `ctx_batch({commands:["git log --oneline -5"],queries:["recent changes"]})`. Required: commands, queries.\nRuns several shell commands, then answers several search queries over their combined output, in one call. Use it to collect facts from more than one command at once, for example test results plus recent commits, when you need specific answers rather than the full text. Returns the matching sections and a one-line footer.',ctx_index:'Example: `ctx_index({path:"docs/api.md"})`. Required: one of path, content, url.\nStores content so it can be searched later: a local file or folder (nested .gitignore files are respected), raw text, or a URL, which is fetched and converted to Markdown. Use it for documentation or large files you will query more than once, then use ctx_search instead of reading the content again. Returns the source label and how many chunks were stored.',ctx_search:'Example: `ctx_search({queries:["auth middleware"]})`. Required: queries.\nSearches content stored with ctx_index and earlier sandbox output in this project. Pass several queries in one call. By default it searches the current worktree; set `scope` to `project` for all worktrees or `session` for this session only. Results from the current session rank first, then by relevance, ranked with measurably better recall than plain keyword search. Set `sort` to `timeline` for oldest-first order across this session, prior sessions and memory, paged with `after`; `offset` is for relevance order only. Set `source` to `decision` to search only rows where the user answered a question. Every hit names its source. When nothing matches, the reply states the scope and how many sources are indexed.',ctx_resume:"Example: `ctx_resume({})`. Required: none.\nReturns a summary of up to 2 KB for this session: the last task and user request, files changed, open errors, and search terms for ctx_search. A large row is shown as a pointer line instead of its full text; call `ctx_resume(seq: N)` with that line's number to read the full row. Call it with no `seq` to get the state block on demand. Use it after the conversation was compacted or resumed, before you repeat earlier work.",ctx_stats:"Example: `ctx_stats({})`. Required: none.\nReports the bytes context-mode kept out of the chat: a text report (bars, per tool, per agent) and a Markdown table. Show the text block to the user unchanged, in a code block. Use it when the user asks what it saved.",ctx_doctor:"Example: `ctx_doctor({})`. Required: none.\nChecks this context-mode install and reports a table with one row per check: version, Node and node:sqlite, host config and hooks for this agent, MCP connection, project and worktree, database health, index contents, and hook timing. Each failed row names its cause, the fix and a docs link. Use it when the user asks whether context-mode works, or after a context-mode error. Run each Fix first, then call ctx_doctor again. If a FAIL stays, show the user the report file it names (it holds paths and environment details) and ask before you run the printed gh issue command.\n",ctx_upgrade:"Example: `ctx_upgrade({})`. Required: none.\nUpdates context-mode to the latest release for this agent and rewrites only context-mode's own entries in the host config. User entries and user settings such as hook timeouts are kept, and old entries are erased. Returns a table of what changed and whether a restart is needed. Use it only when the user asks to update context-mode.",ctx_purge:'Example: `ctx_purge({source:"old-docs"})`. Required: one of session, source, project.\nDeletes stored data: one session, one indexed source, or everything stored for this project. This cannot be undone. Use it only when the user asks to forget or reset data.'}),yc='context-mode: {size}-byte file, over the one-read limit. Run ctx_execute(language, code, file="{path}") and print only the answer.';var ff="{size}",xf="{path}";function Kt(e,t,n=""){return k(yc,n).split(ff).join(String(t)).split(xf).join(e)}var{statSync:pf}=process.getBuiltinModule("node:fs"),Dc="Bash",To="Read",_f="WebFetch",Ef="ctx_execute",mf="ctx_batch",Lc="shell",gf="1",z="-",Ro="--",hf="=",Sf=".",Cc=",",Oo="p",bf=["-e","--expression"],Of=";&|(`\n\r",le=Object.freeze({kind:"allow"}),G=e=>({kind:"deny",reason:e}),ae=e=>typeof e=="string"?e:void 0,Ic=e=>e!=null,J=(e,t)=>e.includes(t);function wc(e,t,n){let o=e.tool;if(o===void 0)return le;let r=o.canonicalName,s=o.input,i;if(n===null){if(process.env[br]===gf)return G(k(ut,t.toolNamePrefix));process.stderr.write(qr+`
27
+ \r`,of=Object.freeze({tool:ef});function rf(e,t){if(t!=="claude-code")return[];let n=ge(process.env),o=process.env[ht],r=o!==void 0&&o!==""?o:n===null?null:Be(process.env,n),s=[So(e,gc,Zd),So(e,gc,hc)];return r===null?s:[...s,So(r,hc)]}function Ac(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function sf(e){let t;try{t=Gt(Jd(e,"utf8"))}catch(s){return s.code==="ENOENT"?{kind:"absent"}:{kind:"bad"}}let n;try{n=JSON.parse(t)}catch{return{kind:"bad"}}if(!Ac(n))return{kind:"bad"};let o=n.permissions;if(o===void 0)return{kind:"ok",deny:[]};if(!Ac(o))return{kind:"bad"};let r=o.deny;return r===void 0?{kind:"ok",deny:[]}:!Array.isArray(r)||!r.every(s=>typeof s=="string")?{kind:"bad"}:{kind:"ok",deny:r}}function Nc(e,t){let n=[];for(let o of rf(e,t)){let r=sf(o);if(r.kind==="bad")return null;r.kind==="ok"&&n.push(...r.deny)}return n}function cf(e,t){let n=[],o=0;for(;o<e.length;){let r=e[o];if(r==="*"&&t&&e[o+1]==="*"){let s=e[o+2]==="/";n.push({t:s?"globstarDir":"globstar"}),o+=s?3:2;continue}r==="*"?(n.length===0||n[n.length-1].t!=="star")&&n.push({t:"star"}):r==="?"?n.push({t:"any1"}):n.push({t:"lit",c:r}),o++}return n}function Y(e,t,n){let o=cf(e,n),r=t.length,s=new Uint8Array(r+1);s[r]=1;for(let i=o.length-1;i>=0;i--){let c=o[i],a=new Uint8Array(r+1),l=0;for(let u=r;u>=0;u--){let d=u<r,f=d?t[u]:"";switch(c.t){case"lit":a[u]=d&&f===c.c?s[u+1]:0;break;case"any1":a[u]=d&&!(n&&f==="/")?s[u+1]:0;break;case"star":a[u]=s[u]||(d&&!(n&&f==="/")?a[u+1]:0);break;case"globstar":a[u]=s[u]||(d?a[u+1]:0);break;case"globstarDir":d&&f==="/"&&s[u+1]&&(l=1),a[u]=s[u]||l;break}}s=a}return s[0]===1}function af(e){let t=e.indexOf("(");if(t<1||!e.endsWith(")"))return null;let n=e.slice(t+1,e.length-1);return n===""?null:{tool:e.slice(0,t),glob:n}}function lf(e,t){if(!e.endsWith(Sc))return Y(e,t,!1);let n=e.slice(0,e.length-Sc.length);if(Y(n,t,!1))return!0;for(let o=0;o<t.length;o++)if(nf.includes(t[o])&&Y(n,t.slice(0,o),!1))return!0;return!1}var uf=/^[A-Za-z]:(?=\/)/;function We(e){return bo==="/"?e:e.split(bo).join("/")}function df(e,t,n){if(e.startsWith(Tc)){if(n===void 0)return!1;let r=Qd(n,t);return r===""||r===Rc||r.startsWith(Rc+bo)||$d(r)?!1:Y(e.slice(Tc.length),We(r),!0)}let o=We(t);if(e.startsWith(bc)){let r=We(e.slice(bc.length-1));return Y(r,o,!0)||Y(r,o.replace(uf,""),!0)}if(e.startsWith(Oc)){let r=ge(process.env);return r!==null&&Y(We(r)+e.slice(Oc.length-1),o,!0)}return Y(We(e),o,!0)}function V(e,t,n=of){for(let o of t){let r=af(o);if(r===null||r.tool!==n.tool)continue;if(n.tool===tf?df(r.glob,e,n.projectDir):lf(r.glob,e))return o}return null}var gE=Object.freeze({ctx_execute:'Example: `ctx_execute({language:"shell",code:"git log --oneline -5"})`. Required: language, code.\nRuns code in a sandboxed subprocess in the project directory (shell, powershell, javascript, typescript, python, or another runtime on PATH); only what the code prints comes back. For a large file, set `file` to its local path: the code gets it in the CTX_FILE environment variable. Set `intent` when output may be large: the matching sections come back and the full output is indexed for ctx_search. `timeoutMs` defaults to and caps at 600000; then the whole process tree is killed.',ctx_batch:'Example: `ctx_batch({commands:["git log --oneline -5"],queries:["recent changes"]})`. Required: commands, queries.\nRuns several shell commands, then answers several search queries over their combined output, in one call. Use it to collect facts from more than one command at once, for example test results plus recent commits, when you need specific answers rather than the full text. Returns the matching sections and a one-line footer.',ctx_index:'Example: `ctx_index({path:"docs/api.md"})`. Required: one of path, content, url.\nStores content so it can be searched later: a local file or folder (nested .gitignore files are respected), raw text, or a URL, which is fetched and converted to Markdown. Use it for documentation or large files you will query more than once, then use ctx_search instead of reading the content again. Returns the source label and how many chunks were stored.',ctx_search:'Example: `ctx_search({queries:["auth middleware"]})`. Required: queries.\nSearches content stored with ctx_index and earlier sandbox output in this project. Pass several queries in one call. By default it searches the current worktree; set `scope` to `project` for all worktrees or `session` for this session only. Results from the current session rank first, then by relevance, ranked with measurably better recall than plain keyword search. Set `sort` to `timeline` for oldest-first order across this session, prior sessions and memory, paged with `after`; `offset` is for relevance order only. Set `source` to `decision` to search only rows where the user answered a question. Every hit names its source. When nothing matches, the reply states the scope and how many sources are indexed.',ctx_resume:"Example: `ctx_resume({})`. Required: none.\nReturns a summary of up to 2 KB for this session: the last task and user request, files changed, open errors, and search terms for ctx_search. A large row is shown as a pointer line instead of its full text; call `ctx_resume(seq: N)` with that line's number to read the full row. Call it with no `seq` to get the state block on demand. Use it after the conversation was compacted or resumed, before you repeat earlier work.",ctx_stats:"Example: `ctx_stats({})`. Required: none.\nReports the bytes context-mode kept out of the chat: a text report (bars, per tool, per agent) and a Markdown table. Show the text block to the user unchanged, in a code block. Use it when the user asks what it saved.",ctx_doctor:"Example: `ctx_doctor({})`. Required: none.\nChecks this context-mode install and reports a table with one row per check: version, Node and node:sqlite, host config and hooks for this agent, MCP connection, project and worktree, database health, index contents, and hook timing. Each failed row names its cause, the fix and a docs link. Use it when the user asks whether context-mode works, or after a context-mode error. Run each Fix first, then call ctx_doctor again. If a FAIL stays, show the user the report file it names (it holds paths and environment details) and ask before you run the printed gh issue command.\n",ctx_upgrade:"Example: `ctx_upgrade({})`. Required: none.\nUpdates context-mode to the latest release for this agent and rewrites only context-mode's own entries in the host config. User entries and user settings such as hook timeouts are kept, and old entries are erased. Returns a table of what changed and whether a restart is needed. Use it only when the user asks to update context-mode.",ctx_purge:'Example: `ctx_purge({source:"old-docs"})`. Required: one of session, source, project.\nDeletes stored data: one session, one indexed source, or everything stored for this project. This cannot be undone. Use it only when the user asks to forget or reset data.'}),yc='context-mode: {size}-byte file, over the one-read limit. Run ctx_execute(language, code, file="{path}") and print only the answer.';var ff="{size}",xf="{path}";function Kt(e,t,n=""){return k(yc,n).split(ff).join(String(t)).split(xf).join(e)}var{statSync:pf}=process.getBuiltinModule("node:fs"),Dc="Bash",To="Read",_f="WebFetch",Ef="ctx_execute",mf="ctx_batch",Lc="shell",gf="1",z="-",Ro="--",hf="=",Sf=".",Cc=",",Oo="p",bf=["-e","--expression"],Of=";&|(`\n\r",le=Object.freeze({kind:"allow"}),G=e=>({kind:"deny",reason:e}),ae=e=>typeof e=="string"?e:void 0,Ic=e=>e!=null,J=(e,t)=>e.includes(t);function wc(e,t,n){let o=e.tool;if(o===void 0)return le;let r=o.canonicalName,s=o.input,i;if(n===null){if(process.env[br]===gf)return G(k(ut,t.toolNamePrefix));process.stderr.write(qr+`
28
28
  `),i=[]}else i=n;let c=Tf(r,s,e.cwd,i);return c!==null?G(Ne+c):r===_f?yf(s,t):r===Dc?Cf(e,t,s,i):r===To?Pf(e,t,s):le}function Pc(e,t,n,o){let r=e==="webfetch",s=r?Ur.map(c=>n.toolNamePrefix+c).join(Xr):n.toolNamePrefix+Pr,i=JSON.stringify(r?{url:t}:{language:Lc,code:t,intent:o??wr});return[Tn+Ir[e]+kr,Dr,Lr+s,i].join(`
29
29
  `)}function Uc(e){for(let t of xt){let n=ae(e[t]);if(n!==void 0&&n!=="")return n}}function Tf(e,t,n,o){if(o.length===0)return null;let r=s=>V(qt(n,s),o,{tool:To,projectDir:n});if(e===Dc){let s=ae(t.command);return s===void 0?null:V(s,o)}if(e===To){let s=Uc(t);return s===void 0?null:r(s)}if(e===Ef){let s=ae(t.file),i=s===void 0||s===""?null:r(s);if(i!==null)return i;let c=ae(t.code);return t.language===Lc&&c!==void 0?V(c,o):null}if(e===mf&&Array.isArray(t.commands))for(let s of t.commands){let i=typeof s=="string"?V(s,o):null;if(i!==null)return i}return null}function Rf(e,t){return t.length===0?null:V([e.argv0,...e.args].join(" "),t)??V(e.raw,t)}function Af(e,t){if(t.length===0)return!1;for(let n=0;n<=e.length;n++)if(!(n>0&&!Of.includes(e.charAt(n-1)))&&V(e.slice(n).trimStart(),t)!==null)return!0;return!1}function Nf(e){let t;try{t=new URL(e).hostname.toLowerCase()}catch{return!1}return Yr.some(n=>t===n||t.endsWith(Sf+n))}function yf(e,t){let n=ae(e.url)??"";return Nf(n)?le:G(Pc("webfetch",n,t))}function Cf(e,t,n,o){let r=ae(n.command)??"",s=ve(r);if(!s.ok)return Af(r,o)?G(k(dt,t.toolNamePrefix)):kc(r,e.cwd,t)??le;let i=mc(s.commands);for(let c of i){let a=Rf(c,o);if(a!==null)return G(Ne+a)}if(!Le(t)||he(e))for(let c of i){let a=If(c);if(a!==null)return G(Pc(a,r,t,ae(n.description)))}return Uf(i,e.cwd,t)??kc(r,e.cwd,t)??le}function If(e){let t=e.argv0.toLowerCase();return J(Vr,t)&&kf(t,e)?"curl":Lf(e.raw)?"http":J(Qr,t)?"build":null}function kf(e,t){return t.redirectsToFile?!Df(e,t.args):!t.endsInBoundedSink}function Df(e,t){let n=zr[e],o=!1;for(let r=0;r<t.length;r++){let s=t[r];if(s===Ro)break;if(J(Jr,s)||s===$r&&t[r+1]===z)return!1;(s===n.long||s.startsWith(z)&&!s.startsWith(Ro)&&s.includes(n.short,z.length))&&(o=!0)}return o}function Lf(e){let t=e.toLowerCase();for(let n of ts)if(t.includes(n))return!0;for(let n=t.indexOf(Ce);n>=0;n=t.indexOf(Ce,n+1)){let o=t.charAt(n+Ce.length);if(o!==""&&Zr.includes(o)&&t.startsWith(es,n+Ce.length+o.length))return!0}return!1}var wf="cd";function Ao(e){try{let t=pf(e);return t.isFile()?t.size:-1}catch{return-1}}function Pf(e,t,n){if(!Ic(n.offset)&&!Ic(n.limit)){let o=Uc(n);if(o!==void 0){let r=qt(e.cwd,o),s=Ao(r);if(s>X)return G(Kt(r,s,t.toolNamePrefix))}}return le}function Uf(e,t,n){if(n.nativeTools.read!==void 0&&n.nativeTools.read.length>0&&Yn(n))return null;let o=t,r=null;for(let s of e){let i=s.argv0.toLowerCase();if(i===wf&&s.args.length===1&&s.insideConstruct===void 0&&(o=qt(o,s.args[0])),s.redirectsToFile||s.endsInBoundedSink||s.pipesOut===!0||s.insideConstruct!==void 0||!J(ns,i))continue;let c=Ff(i,s.args);if(c===null)continue;if(c.bounded){r=le;continue}let a=qt(o,c.file),l=Ao(a);if(l>X)return G(Kt(a,l,n.toolNamePrefix))}return r}function kc(e,t,n){if(n.nativeTools.read!==void 0&&n.nativeTools.read.length>0&&Yn(n))return null;for(let o of ic(e,t)){let r=Ao(o);if(r>X)return G(Kt(o,r,n.toolNamePrefix))}return null}var Xt=e=>e!==""&&[...e].every(t=>t>="0"&&t<="9");function Mf(e){if(J(An,e))return 1;for(let t of An)if(t.startsWith(Ro)?e.startsWith(t+hf):e.startsWith(t))return 0;return e.startsWith(z)&&Xt(e.slice(z.length))?0:-1}function Hf(e){if(e===Oo)return"all";if(!e.endsWith(Oo))return null;let t=e.slice(0,e.length-Oo.length),n=t.indexOf(Cc);return(n<0?Xt(t):Xt(t.slice(0,n))&&Xt(t.slice(n+Cc.length)))?"range":null}function Ff(e,t){let n=[],o=!1,r=!1,s;for(let i=0;i<t.length;i++){let c=t[i];if(J(os,e)){let a=Mf(c);if(a>=0){o=!0,i+=a;continue}}if(e===ft&&J(rs,c)){r=!0;continue}if(e===ft&&J(bf,c)){s=t[i+1],i++;continue}c.startsWith(z)&&c!==z||n.push(c)}if(e===ft){if(!r)return null;s===void 0&&(s=n.shift());let i=s===void 0?null:Hf(s);if(i===null)return null;o=i==="range"}return e===ss&&n.shift()!==D.identity?null:n.length===1&&n[0]!==z?{file:n[0],bounded:o}:null}import{basename as Yf,dirname as Vt,join as Xe,resolve as jc}from"node:path";import{dirname as Mc,sep as jf}from"node:path";var{realpathSync:vf}=process.getBuiltinModule("node:fs");function Gf(e){try{return vf.native(e)}catch{return}}function Yt(e){return e.split(jf).filter(t=>t!=="")}function Hc(e){let t=e.map(Gf).filter(s=>s!==void 0);if(t.length===0)throw new RangeError("commonRoot needs at least one existing path");let n=t[0],o=Yt(n).length;for(let s of t){let i=Yt(s),c=Yt(n),a=0;for(;a<o&&a<i.length&&i[a]===c[a];)a+=1;o=a}let r=n;for(;Yt(r).length>o&&Mc(r)!==r;)r=Mc(r);return r}var Bf=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Wf=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],w=(e,t)=>e>>>t|e<<32-t;function Fc(e){let t=Buffer.from(e,"utf8"),n=t.length*8,o=Math.ceil((t.length+9)/64)*64,r=Buffer.alloc(o);t.copy(r),r[t.length]=128,r.writeUInt32BE(Math.floor(n/4294967296),o-8),r.writeUInt32BE(n>>>0,o-4);let s=Wf.slice(),i=new Uint32Array(64);for(let c=0;c<o;c+=64){for(let E=0;E<16;E++)i[E]=r.readUInt32BE(c+E*4);for(let E=16;E<64;E++){let h=w(i[E-15],7)^w(i[E-15],18)^i[E-15]>>>3,S=w(i[E-2],17)^w(i[E-2],19)^i[E-2]>>>10;i[E]=i[E-16]+h+i[E-7]+S>>>0}let[a,l,u,d,f,x,p,m]=s;for(let E=0;E<64;E++){let h=m+(w(f,6)^w(f,11)^w(f,25))+(f&x^~f&p)+Bf[E]+i[E]>>>0,S=(w(a,2)^w(a,13)^w(a,22))+(a&l^a&u^l&u)>>>0;m=p,p=x,x=f,f=d+h>>>0,d=u,u=l,l=a,a=h+S>>>0}s[0]=s[0]+a>>>0,s[1]=s[1]+l>>>0,s[2]=s[2]+u>>>0,s[3]=s[3]+d>>>0,s[4]=s[4]+f>>>0,s[5]=s[5]+x>>>0,s[6]=s[6]+p>>>0,s[7]=s[7]+m>>>0}return s.map(c=>c.toString(16).padStart(8,"0")).join("")}var{existsSync:Kf,readFileSync:Xf,realpathSync:vc,statSync:qf}=process.getBuiltinModule("node:fs");function Vf(e){switch(e){case"claude-code":return"env:CLAUDE_PROJECT_DIR";case"codex":case"copilot-cli":case"kiro":return"arg:--agent+cwd";case"vscode":return"arg:workspaceFolder";case"gemini":case"qwen":case"zcode":case"opencode":return"spawn-cwd";case"pi":return"pi:ctx.cwd"}}function Ke(e){return e===void 0||e===""?void 0:e}function zf(e,t){switch(e){case"env:CLAUDE_PROJECT_DIR":return Ke(t.env.CLAUDE_PROJECT_DIR)??Ke(t.cwd)??process.cwd();case"arg:--agent+cwd":case"spawn-cwd":return Ke(t.cwd);case"arg:workspaceFolder":{let n=t.argv.indexOf(it);return n<0?void 0:Ke(t.argv[n+1])}case"pi:ctx.cwd":return Ke(t.piCwd)}}function Jf(e){let t;try{t=vc.native(e)}catch{throw new T("NO_GIT_DIR",{path:e})}let n=t;for(;;){let o=$f(Xe(t,En));if(o!==null){let s=Gc(Xe(o,gr));return{commonDir:vc.native(s===null?o:jc(o,s)),worktree:t,start:n}}let r=Vt(t);if(r===t)return{commonDir:null,start:n};t=r}}function $f(e){let t;try{if(qf(e).isDirectory())t=e;else{let n=Gc(e);if(n===null||!n.startsWith(gn))return null;t=jc(Vt(e),n.slice(gn.length))}}catch{return null}return Kf(Xe(t,hr))?t:null}function Gc(e){let t;try{t=Xf(e,"utf8")}catch{return null}let n=t.indexOf(`
30
30
  `),o=(n<0?t:t.slice(0,n)).trim();return o===""?null:o}function Qf(e,t){let{spawnSync:n}=process.getBuiltinModule("node:child_process"),o=n("git",t,{cwd:e,shell:!1,encoding:"utf8",stdio:["ignore","pipe","pipe"],windowsHide:!0});if(o.error!==void 0||o.status!==0)throw new T("NO_GIT_DIR",{path:e});return o.stdout.split(`
@@ -134,7 +134,7 @@ INSERT INTO chunks(source_id, session_id, worktree, agent, ord, body, title) VAL
134
134
  AND (:scope <> 'worktree' OR chunks.worktree = :worktree)
135
135
  AND (:source IS NULL OR s.label = :source)
136
136
  ${ta}`,oa=`
137
- ORDER BY (session_id = :session_id) DESC, (worktree = :worktree) DESC, full DESC, score DESC, source_id DESC, ord ASC`,pm=`
137
+ ORDER BY (session_id = :session_id) DESC, (worktree = :worktree) DESC, full DESC, score DESC, source_id DESC, ord ASC`,_m=`
138
138
  WITH m AS (${na}
139
139
  ), r AS (
140
140
  SELECT *,
@@ -143,11 +143,11 @@ WITH m AS (${na}
143
143
  FROM m
144
144
  )
145
145
  SELECT rid, source_id, session_id, worktree, ord, full, 1.0 / (:k + rank_a) + 1.0 / (:k + rank_b) AS score
146
- FROM r${oa}`,_m=`
146
+ FROM r${oa}`,Em=`
147
147
  WITH m AS (${na}
148
148
  )
149
149
  SELECT rid, source_id, session_id, worktree, ord, full, -bm AS score
150
- FROM m${oa}`;var Em=`
150
+ FROM m${oa}`;var mm=`
151
151
  SELECT t.rowid AS rid, c.source_id AS source_id, c.session_id AS session_id, c.worktree AS worktree, c.ord AS ord
152
152
  FROM chunks_tri t JOIN chunks c ON c.rowid = t.rowid JOIN sources s ON s.id = c.source_id
153
153
  WHERE chunks_tri MATCH :match
@@ -157,7 +157,7 @@ WHERE chunks_tri MATCH :match
157
157
  ${ta}
158
158
  ORDER BY bm25(chunks_tri, 1.0, ${ea}) ASC, c.source_id DESC, c.ord ASC`;var R0="INSERT INTO chunks_tri(rowid, body, title) VALUES (?, ?, ?)",A0="INSERT INTO chunks_tri(chunks_tri, rowid, body, title) SELECT 'delete', rowid, body, title FROM chunks";function ra(e,t,n){let o=ko(e,t,n);return ia(e,o,t,n),o}function ko(e,t,n){let o=0;for(let r of n)o+=r.bytes;return P(e,r=>{let s=r.raw.prepare(O0).get({session_id:t.sessionId,worktree:t.worktree,agent:t.agent,kind:t.kind,label:t.label,bytes_total:o,chunk_count:n.length,created_ts:t.createdAt,created_at:new Date(t.createdAt).toISOString()});return Number(s.id)})}function sa(e,t,n,o,r){try{ia(e,t,n,o),Lo(e,t,n.sessionId,r)}catch(s){throw P(e,i=>{N0(i.raw,{sourceId:t}),i.raw.prepare("DELETE FROM sources WHERE id = ?").run(t)}),s}}function ia(e,t,n,o){let r=[],s=[],i=0;for(let c of o)s.length>0&&i+c.bytes>un&&(r.push(s),s=[],i=0),s.push(c),i+=c.bytes;s.length>0&&r.push(s);for(let c of r)P(e,a=>{let l=a.raw.prepare(T0),u=a.raw.prepare(R0);for(let d of c){let f=d.title??"",x=l.run(t,n.sessionId,n.worktree,n.agent,d.ord,d.text,f).lastInsertRowid;u.run(x,d.text,f)}})}function N0(e,t){if(t==="all")return e.exec("INSERT INTO chunks_tri(chunks_tri) VALUES ('delete-all')"),e.exec("DELETE FROM line_units"),Number(e.prepare("DELETE FROM chunks").run().changes);let[n,o]="sourceId"in t?["source_id = ?",t.sourceId]:["source_id IN (SELECT id FROM sources WHERE label = ?)",t.label];return e.prepare(A0+" WHERE "+n).run(o),e.prepare("DELETE FROM line_units WHERE "+n).run(o),Number(e.prepare("DELETE FROM chunks WHERE "+n).run(o).changes)}function Do(e){let t=[],n="";for(let o of e)o.trim()===""||o==="\0"?(n!==""&&t.push(n),n=""):n+=o==='"'?'""':o;return n!==""&&t.push(n),t.map(o=>`"${o}"*`).join(" ")}function y0(e){return[...new Set(Do(e).split(" ").filter(n=>n!==""))].join(" OR ")}var C0=new Set(["a","an","the","and","or","of","to","in","on","at","by","is","be","it","as","do","i","for","are","but","not","you","all","can","had","her","was","one","our","out","has","his","how","its","may","who","did","get","got","let","she","too","will","with","this","that","from","they","been","have","some","them","than","each","into","your","could","would","about","which","their","there","other","should","also","very","when","what","then","these","those","being","does","both","while","where","here","were","much","any","my","me","we"]);function I0(e){let t=[...new Set(Do(e).split(" ").filter(o=>o!==""))],n=t.filter(o=>!C0.has(o.slice(1,-2).toLowerCase()));return n.length>0?n:t}var Zt=`
159
159
  AND (:scope <> 'session' OR session_id = :session_id)
160
- AND (:scope <> 'worktree' OR worktree = :worktree)`,mm=`
160
+ AND (:scope <> 'worktree' OR worktree = :worktree)`,gm=`
161
161
  WITH e AS (
162
162
  SELECT seq, kind, key, path, body, created_at FROM events
163
163
  WHERE created_at > :after${Zt}
@@ -165,7 +165,7 @@ WITH e AS (
165
165
  )
166
166
  SELECT seq, kind, key, path, body, created_at FROM e
167
167
  WHERE created_at <= IFNULL((SELECT created_at FROM e ORDER BY created_at, seq LIMIT 1 OFFSET :off), created_at)
168
- ORDER BY created_at ASC, seq ASC`,gm=`
168
+ ORDER BY created_at ASC, seq ASC`,hm=`
169
169
  WITH s AS (
170
170
  SELECT id, label, created_ts FROM sources
171
171
  WHERE created_ts > :after${Zt}
@@ -174,7 +174,7 @@ WITH s AS (
174
174
  )
175
175
  SELECT id, label, created_ts FROM s
176
176
  WHERE created_ts <= IFNULL((SELECT created_ts FROM s ORDER BY created_ts, id LIMIT 1 OFFSET :off), created_ts)
177
- ORDER BY created_ts ASC, id ASC`;var hm=`
177
+ ORDER BY created_ts ASC, id ASC`;var Sm=`
178
178
  SELECT EXISTS(SELECT 1 FROM events WHERE created_at > :after${Zt} AND (:source IS NULL OR kind = :source))
179
179
  OR EXISTS(SELECT 1 FROM sources WHERE created_ts > :after${Zt} AND (:source IS NULL OR label = :source)
180
180
  AND label <> :reserved) AS more`;var k0=`CREATE VIRTUAL TABLE r USING fts5(body, ${Jt}, content='')`,D0="INSERT INTO r(rowid, body) VALUES (?, ?)",L0="SELECT rowid AS id, bm25(r) AS bm FROM r WHERE r MATCH ?";function W(e,t,n="all"){let o=e.map(()=>0),r=n==="any"?y0(t):Do(t);if(r===""||e.length===0)return o;let s=process.getBuiltinModule("node:sqlite");if(s===void 0)throw new T("NO_SQLITE");let i=new s.DatabaseSync(":memory:");try{i.exec(k0);let c=i.prepare(D0);i.exec("BEGIN");for(let a=0;a<e.length;a++)c.run(a+1,e[a]);i.exec("COMMIT");for(let a of i.prepare(L0).all(r))o[Number(a.id)-1]=-a.bm;return o}finally{i.close()}}var w0="s";function ca(e){return w0+e.toString(36)}function Lo(e,t,n,o){let r=0;for(;r<o.length;){let s=r,i=0;for(;s<o.length&&(s===r||i+o[s].body.length<=un);)i+=o[s].body.length,s++;let c=r;P(e,a=>{let l=a.raw.prepare("INSERT INTO line_units(body, source_id, session_id, ord) VALUES (?, ?, ?, ?)");for(let u=c;u<s;u++){let d=o[u];l.run(d.body,t,n,d.ord)}}),r=s}}function aa(e,t){return t===e?e:e+" "+t}function la(e,t,n,o){let r=I0(n).join(" OR ");return r===""||t===""?[]:e.raw.prepare("SELECT u.source_id AS source_id, u.ord AS ord, u.body AS body, -bm25(line_units) AS score, s.label AS label FROM line_units u JOIN sources s ON s.id = u.source_id WHERE line_units MATCH ? AND u.session_id = ? ORDER BY bm25(line_units) LIMIT ?").all(r,t,o).map(i=>({sourceId:Number(i.source_id),ord:Number(i.ord),label:i.label,body:i.body,score:i.score}))}function P0(e){let t=0;for(;t<e.length&&(e[t]===" "||e[t]===" ");)t++;return t}function wo(e){let t=e.split(`