Files
Niche-alchemyandMert Koseoglu 6b6193e71c Fix Windows shell runtime and PowerShell UTF-8 handling (#796)
* Fix Windows shell UTF-8 handling

* Fix Windows shell UTF-8 handling

* Fix Windows shell UTF-8 handling

* Fix Windows shell UTF-8 handling

* Fix Windows shell UTF-8 handling

* fix(runtime): gate Windows bash detection through `where bash` so pwsh fallback is reachable

resolveWindowsBash() probed the well-known Git Bash paths with existsSync()
BEFORE consulting `where bash`. On a Windows runner with Git Bash installed,
that shortcut re-detected a real bash even in the 'bash unavailable' scenario,
so resolveWindowsShell() never fell through to pwsh — failing the new
'Windows prefers pwsh over powershell when bash unavailable' test.

Route availability through `where bash` (the surface the test stubs): when it
yields no real candidate, return null so the shell selector reaches pwsh. #826
is preserved — when `where bash` surfaces a Git Bash candidate we still
canonicalize to the absolute Git\\usr\\bin\\bash.exe path (WSL/WindowsApps
skipped) so native git keeps MSYS path conversion.

tests/runtime.test.ts + tests/executor.test.ts green; typecheck clean.

* docs(configs): propagate shell→javascript ctx_execute guidance to 13 adapters

Mirror the claude-code/codex change from this PR to the remaining adapter
instruction docs: the Bash/Shell routing line now recommends
ctx_execute(language: "javascript") (with `language: "shell"` only when code
matches the host shell), and grep/search guidance points at a portable
javascript filter instead of a shell grep. Keeps cross-platform parity now
that shell code is host-shell-specific on Windows.

cursor/context-mode.mdc and pi/AGENTS.md lack the analogous lines (condensed /
stub formats) and were intentionally left untouched. kimi has no doc.

---------

Co-authored-by: Mert Koseoglu <bm.ksglu@gmail.com>
2026-06-21 15:05:56 +03:00

4.1 KiB

context-mode — MANDATORY routing rules

context-mode MCP tools available. Rules protect context window from flooding. One unrouted command dumps 56 KB into context.

Think in Code — MANDATORY

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

BLOCKED — do NOT attempt

curl / wget — BLOCKED

Terminal curl/wget intercepted and blocked. Do NOT retry. Use: ctx_fetch_and_index(url, source) or ctx_execute(language: "javascript", code: "const r = await fetch(...)")

Inline HTTP — BLOCKED

fetch('http, requests.get(, requests.post(, http.get(, http.request( — intercepted. Do NOT retry. Use: ctx_execute(language, code) — only stdout enters context

WebFetch / fetch — BLOCKED

Use: ctx_fetch_and_index(url, source) then ctx_search(queries)

REDIRECTED — use sandbox

Terminal / run_in_terminal (>20 lines output)

Terminal ONLY for: git, mkdir, rm, mv, cd, ls, npm install, pip install. Otherwise: ctx_batch_execute(commands, queries) or ctx_execute(language: "javascript", code: "..."). Use language: "shell" only when code matches the host shell.

read_file (for analysis)

Reading to edit → read_file correct. Reading to analyze/explore/summarize → ctx_execute_file(path, language, code).

grep / search (large results)

Use ctx_execute(language: "javascript", code: "...") in sandbox for portable filtering/counting.

Tool selection

  1. MEMORY: ctx_search(sort: "timeline") — after resume, check prior context before asking user.
  2. GATHER: ctx_batch_execute(commands, queries) — runs all commands, auto-indexes, returns search. ONE call replaces 30+. Each command: {label: "header", command: "..."}.
  3. FOLLOW-UP: ctx_search(queries: ["q1", "q2", ...]) — all questions as array, ONE call (default relevance mode).
  4. PROCESSING: ctx_execute(language, code) | ctx_execute_file(path, language, code) — sandbox, only stdout enters context.
  5. WEB: ctx_fetch_and_index(url, source) then ctx_search(queries) — raw HTML never enters context.
  6. INDEX: ctx_index(content, source) — store in FTS5 for later search.

Parallel I/O batches

Pass concurrency: 4-8 to ctx_batch_execute and ctx_fetch_and_index for network/API batches. Keep concurrency: 1 for CPU-bound work (test, build, lint). GitHub gh: cap at 4.

Output

Write artifacts to FILES — never inline. Return: file path + 1-line description. Descriptive source labels for ctx_search(source: "label").

Session Continuity

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

Memory

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

Need Command
What were we working on? ctx_search(queries: ["summary"], source: "compaction", sort: "timeline")
What did we decide? ctx_search(queries: ["decision"], source: "decision", sort: "timeline")
What NOT to repeat? ctx_search(queries: ["rejected"], source: "rejected-approach")
What constraints exist? ctx_search(queries: ["constraint"], source: "constraint")

Note: user-prompt history not available.

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

ctx commands

Command Action
ctx stats Call ctx_stats MCP tool, display full output verbatim
ctx doctor Call ctx_doctor MCP tool, run returned shell command, display as checklist
ctx upgrade Call ctx_upgrade MCP tool, run returned shell command, display as checklist
ctx purge Call ctx_purge MCP tool with confirm: true. Warns before wiping knowledge base.

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