Skip to content

feat(llm): run build --deep on a Claude subscription, and pin number formatting - #107

Closed
christian-jorge wants to merge 2 commits into
trailhq:mainfrom
christian-jorge:feat/subscription-provider
Closed

christian-jorge wants to merge 2 commits into
trailhq:mainfrom
christian-jorge:feat/subscription-provider

Conversation

@christian-jorge

Copy link
Copy Markdown

graft build --deep was gated on GRAFT_API_KEY, so a developer already paying for a Claude subscription still had to buy separate API credits for concept nodes and per-symbol summaries. This adds a third provider, claude-cli, that drives the locally installed and already-signed-in Claude Code binary in headless mode.

$ env -u GRAFT_API_KEY graft build ./repo --deep

→ no API key found; using your signed-in Claude Code CLI (sonnet).
✓ concepts: 12 nodes, 22 links from 9 files
✓ wiring: 97 nodes, 158 edges — meaning: 97 computed

Explicit-first selection. An existing key-based setup resolves to exactly the provider it always did; the CLI is only inferred when no key is configured at all, and the run says so out loud.

The CLI is an agent, so the adapter narrows it to a completions call. --tools "" removes every built-in tool, so a summarization turn cannot touch the filesystem. --setting-sources "", --strict-mcp-config, --disable-slash-commands and a replacing --system-prompt keep the user own hooks, MCP servers, skills and CLAUDE.md out of the prompt — without that, a personal “always answer in Portuguese” memory silently rewrites every summary written into the graph. That is tested.

Structured output is emulated. There is no tool_choice on this wire, so the tool own schema travels in the prompt and the reply is parsed back into a synthetic ToolCall, with fence recovery, string-aware brace scanning and one corrective retry. synthesize and crux see the shape they already get from Anthropic. The prompt goes over stdin, never argv — a 24k-char file summary would blow the 32767-char Windows command-line limit.

Honest limits: temperature and maxTokens have no flag and are dropped, and each call is a process spawn, so throughput is lower than HTTP (raise -j). 19 tests, all process-free via an injectable runner — nothing spawns claude, hits the network, or needs a key.

Also here: a locale bug that bites today

Nine bare toLocaleString() calls followed the machine locale. On a pt-BR/de-DE host graft rendered 1990 as 1.990 — and graft explicitly asks the reading agent to sum those numbers across calls and report a turn total. An agent reading 1.990 gets 1.99, so the headline “tokens saved” metric came out ~1000x low for a large share of users. This is what makes three tests fail on main today; formatCount pins it to en-US, because that line is a data interchange format that happens to be human-readable.

The rmDir() test helper also lands here because every later part needs it: Windows only marks a file deleted and keeps it in its directory until the last handle closes, so bare rmSync teardowns made a different test fail on each full run while every one passed in isolation.


Part of a stack. This work started as an audit of main and is split by area so each piece is reviewable on its own. Order, each based on the one before it:

  1. feat/subscription-provider — --deep without an API key, + the locale bug
  2. fix/graph-extraction — Python imports, JSX edges, WASM leak
  3. fix/query-and-viz-security — ReDoS, DNS rebinding, XSS, --in
  4. fix/hosts-settings-safety — the settings.json wipe
  5. fix/llm-build-robustness — the concept-layer wipe, usage accounting
  6. fix/windows-and-cli-ux — the dead npm path on Windows
  7. chore/ci-and-packaging — type-check the tests, run the packaged artifact
  8. docs/config-reference — the config surface the above introduced

Cross-fork PRs can only target main, so GitHub shows the cumulative diff here. This PR own diff: main...christian-jorge:Graft:feat/subscription-provider

Every link in the stack is green on its own: tsc clean and the full suite at 0 failures on Windows. Happy to reorder, rebase, drop any piece, or squash the lot back into one — just say which.

🤖 Generated with Claude Code

christian-jorge and others added 2 commits August 13, 2026 14:53
…ting

Adds a third transport, `claude-cli`, that drives the locally installed and
already-signed-in Claude Code binary in headless mode. `--deep` previously
required GRAFT_API_KEY, so a developer paying for a Claude subscription still
had to buy separate API credits for concept nodes and per-symbol summaries.

The CLI is a coding agent, not a completions endpoint, so the adapter narrows
it: every built-in tool is disabled, and the user's settings, hooks, MCP
servers and CLAUDE.md are kept out of the run — without that a personal
"always answer in Portuguese" memory silently rewrites every summary in the
graph. Structured output is emulated (no tool_choice on this wire) and
transient failures are retried with backoff.

Provider selection is explicit-first: an existing key-based setup resolves
exactly as it did before. The CLI is only inferred when no key is configured.

Also pins the savings/stats number formatting to en-US. Nine bare
toLocaleString() calls followed the machine locale, so a pt-BR host rendered
1990 as "1.990" — and graft explicitly asks the reading agent to SUM those
numbers across calls, making its headline metric ~1000x low. This was already
failing three tests upstream.

681 tests, 0 failures.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Windows only *marks* a file deleted and keeps it in its directory until the
last handle closes, so an rmdir racing a just-closed parse or an exiting child
throws ENOTEMPTY. Bare rmSync teardowns made a DIFFERENT test fail on each full
run while every one passed in isolation. Callers move over in later changes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant