tl-mcp: persistent HTTP daemon, expanded hooks, MCP tools, cache, pi + codex support#14
Open
carlkibler wants to merge 12 commits intoedimuj:mainfrom
Open
tl-mcp: persistent HTTP daemon, expanded hooks, MCP tools, cache, pi + codex support#14carlkibler wants to merge 12 commits intoedimuj:mainfrom
carlkibler wants to merge 12 commits intoedimuj:mainfrom
Conversation
- Add bin/tl-mcp.mjs with stdio, serve, start, stop, status subcommands - Add src/mcp-tools.mjs exposing symbols, snippet, run, impact, browse, tail, guard, diff as MCP tools (ported from upstream 0.34.1) - HTTP mode uses StreamableHTTP stateless transport on port 3742 - Daemon (start/stop/status) writes PID+port to ~/.tokenlean/ - Add @modelcontextprotocol/sdk and zod dependencies - Register tl-mcp in package.json bin section Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…docs - status: TCP probe on port instead of PID-file-only check — works with launchd, systemd, or tl-mcp start regardless of how it was started - stop: on macOS, unloads launchd agent if plist exists; falls back to PID file - start: skips spawn if port already alive (handles launchd-managed case) - install-service: prints ready-to-run launchd (macOS) or systemd (Linux) setup commands, with agent config snippet at the end - buildServer: reads version from package.json instead of hardcoding - README: add MCP Server section with quick start, persistent daemon for macOS and Linux, per-agent config examples, and MCP tools table - README: add Codex to hooks install examples in both integration + workflows sections Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add pi install/uninstall/status handlers (extension at ~/.pi/agent/extensions/) - Detect PI_CODING_AGENT env var for pi hook format - Use pi-specific tool names in nudges: grep/find/read instead of Grep/Glob/Read - Add src/pi-extension.ts template (TypeScript, copies on install) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Missing patterns added:
- git log/diff/show without truncation flags → tl-diff / tl-history
- ls -R/la, tree → tl-structure / Glob
- sed -i, awk > file → Edit tool
- cat > file, echo >>, tee → Write tool
- large JSON/YAML reads (>50KB) → tl-snippet
Persuasive nudges:
- Large file read now includes size + estimated savings (85%)
- cat read includes file size when checkable
- Per-category TTL: 5min (high-impact), 15min (medium), 30min (informational)
Codex format fix:
- Remove broken {"decision":"allow"} format for codex
- Both Claude Code and Codex now use hookSpecificOutput format
- Detect codex from transcript_path (/.codex/) when env vars absent
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add tl_structure, tl_audit, tl_deps, tl_exports. tl_structure: project overview with token estimates; replaces ls -R patterns tl_audit: mid-session token waste analysis with savings breakdown tl_deps: file dependency tree without reading implementation tl_exports: public API surface of a module or directory Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
src/mcp-cache.mjs: 256-entry LRU cache, 60s TTL, keyed on sha1(tool + sorted args + file mtimes). Opt-out: TL_MCP_CACHE=0. mcp-tools.mjs: wrap dispatchTool with cache lookup; only cache successful results. tl-mcp.mjs: build McpServer once per daemon lifecycle (was per-request), reuse across HTTP requests with fresh per-request transport. Measured: tl_symbols cold 205ms → cached 0ms (205x for repeated calls). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds GIT_VERBOSE_PATTERNS, LS_TREE_PATTERNS, WRITE_VIA_BASH_PATTERNS, SED_AWK_EDIT_PATTERNS, plus grep/find/ls-tree/git-verbose/sed-awk/write-via-bash nudges and large JSON/YAML detection to the centralised policy module. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This branch adds a persistent HTTP daemon mode to tl-mcp, expands hook coverage for Claude Code, Codex, and the Pi coding agent, and improves MCP tool surface and performance.
Rebased onto upstream main (v0.39.4) — all 396 tests pass.
tl-mcp: Persistent HTTP daemon (
bin/tl-mcp.mjs)Upstream's
tl-mcpis 48 lines of stdio-only. This adds a full daemon layer:tl-mcp start / stop / status— detached background daemon on port 3742, PID/port files in~/.tokenlean/tl-mcp serve— foreground HTTP server (StreamableHTTPServerTransport)tl-mcp install-service— generates and installs a launchd plist (macOS) or systemd user unit (Linux), ready to runtl-mcp --session-daemon— auto-spawns an HTTP sidecar for the session lifetime; cleans up on exit--idle-timeout N— auto-shutdown after N minutes of inactivityMcpServerinstance per daemon (was rebuilt per HTTP request)Agent config after
tl-mcp start:{ "mcpServers": { "tokenlean": { "type": "http", "url": "http://127.0.0.1:3742/mcp" } } }tl-hook: Expanded patterns + Codex fix + Pi support (
bin/tl-hook.mjs,src/pi-extension.ts)Codex format fix — hooks were returning
{"decision":"allow"}(wrong format); Codex uses the samehookSpecificOutputschema as Claude Code. Fixed. Codex auto-detected fromtranscript_pathin payload when env vars aren't set.New Bash patterns caught:
git log/diff/show(no truncation flags)tl-diff/tl-historyls -R/la,treetl-structure/ Globsed -i,awk > filecat > file,echo >>,teetl-snippetPersuasive messages — large file nudges now include size and estimated savings:
"[tl] 47KB — tl-symbols + tl-snippet saves ~40KB".Per-category TTL dedup: 5 min (high-impact), 15 min (medium), 30 min (informational).
Pi coding agent —
tl-hook install piwrites~/.pi/agent/extensions/tokenlean-hook.ts. Uses pi-specific tool names in messages (grep tool,find tool,read tool). Pi detected viaPI_CODING_AGENTenv var.MCP tool surface: 8 → 12 tools (
src/mcp-tools.mjs)tl_structurels -Rtl_audittl_depstl_exportsResult cache (
src/mcp-cache.mjs)256-entry LRU, 60s TTL, keyed on
sha1(tool + sorted args + file mtimes). Active in HTTP daemon mode; opt-out withTL_MCP_CACHE=0.Measured: repeated
tl_symbolscall — 205ms → 0ms (cache hit).tl-audit: MCP namespace support (
src/audit-analyze.mjs)tl-audit --savingsnow counts namespaced MCP tool calls (mcp__tokenlean__tl_symbols) as tokenlean usage. Also fixes Claude session discovery for symlinked project dirs. Includes new tests.Test plan
npm test— 396 tests, all passingtl-mcp start && tl-mcp status— daemon starts on port 3742tl-mcp stop— daemon stops cleanlytl-mcp install-service | bash— installs launchd/systemd servicetl_structurevia agent — returns project treetl_audit— returns session token analysisecho '{"tool_name":"Bash","tool_input":{"command":"git log"},...}' | tl-hook run— returns git-verbose nudgetranscript_pathcontaining/.codex/— confirms codex detectiontl-hook install pi— installs extension to~/.pi/agent/extensions/tl-audit --savingson a session with MCP usage — countsmcp__tokenlean__*calls🤖 Generated with Claude Code