TokenSave: Scoped Graphs and Safer Upgrades

  • TokenSave
  • Rust
  • MCP
  • code analysis

In my previous article, I described how I added build context to TokenSave and how I coordinated the first index build when multiple agents open the same checkout. Both changes raised follow-up questions. Where does a build configuration constrain a graph walk? What happens when processes indexing different repositories have to write to the same database?

I worked on those questions alongside Vue extraction, PowerShell search handling, and release reliability. This article follows selected contributions through the TokenSave release of December 5, 2026. It was the last release built from the single-crate layout, so it also had to prepare installed binaries for the next major line. Release notes.

Contents

Applying build configuration at every graph hop

The first version of build-context intersected the direct dependents of a symbol with the source files in a selected build. That works for one hop. For a transitive walk, filtering the final results would allow a path to pass through an excluded file. If App.cs references LegacyAdapter.cs and that adapter references Parser.cs, a build that excludes the adapter should never report that path, even if it includes the other two files.

I reused the existing graph traversal and applied source membership before following each hop. The CMake adapter gets membership from the translation units listed in a compilation database. The MSBuild adapter derives it from supported static project declarations and bounded local imports. Both produce a source set for one request, so every hop sees the same membership and the next request can pick up edits to build metadata. That choice puts metadata reading on the query path and keeps ordinary indexing independent of the selected build. Scoped traversal PR, implementation notes.

I preserved the existing direct-dependent mode and added explicit bounded walks. The regression checks both directions, verifies that metadata edits take effect on the next request, and exercises the excluded-file case. The walk reports truncation if it exhausts its graph node budget. The result is a view of indexed relationships within one source set. Build target dependencies and generated-source provenance remain outside that view. Scoped traversal PR.

Keeping Vue symbols in the original file

A parser can extract a Vue script from a copied substring, but all the positions it produces would then be relative to that substring. That leaves the extractor responsible for translating line, column, and byte offsets back to the component. Those positions matter when a caller lookup sends an agent to a specific line in a .vue file.

I implemented the extractor from a proposal by @jmcollin. I reused the HTML grammar to find inline script bodies and passed their ranges in the original file to the existing JavaScript and TypeScript extraction code. The lang attribute selects the grammar for each block. The markup tree stays alive while the extractor processes one script at a time, and all symbols use the component’s original file path and coordinates. I also gave the component node a file-qualified identity so a class of the same name can coexist in the script. Vue extraction PR, tagged extractor.

Supporting Vue in every build tier required linking the HTML grammar in lite and medium as well as full. The Windows lite compile check and 50 focused Vue, Svelte, Astro, and TypeScript integration tests passed. I did not measure binary size or indexing throughput. Template component references and fields synthesized by Vue compiler macros remain follow-up work. Vue extraction PR.

Adapting PowerShell searches conservatively

In the previous article, I described the syntax-based PowerShell hook. A follow-up report showed that the hook could stay silent for two different reasons. The bundled grammar could fail to parse an unquoted comma-separated path list, and a pattern containing regex alternation could parse successfully but still fall outside the identifier searches the hook can advise on. Both cases had looked the same to the caller.

I kept the existing parser and added argument binding for the supported Select-String forms. For example, the hook can now recognize this quoted path list and suggest a graph search for Widget scoped to src.

Select-String -Path 'src\*.rs', 'src\**\*.rs' -Pattern 'Widget'

For a wildcard path, the hook takes the longest directory prefix before the first wildcard. That directory scopes the suggestion, while PowerShell remains responsible for the original glob and regex semantics. Pipelines, multiple patterns, unsupported filters, and syntax the parser cannot handle stay on the native path. I added a debug reason for each decision, so a syntax failure can be distinguished from an intentionally skipped query. PowerShell hook PR, tagged classifier.

Waiting at the shared database boundary

The checkout-local startup lock I described previously coordinates processes building the same graph. Initializing different checkouts can still bring several processes to the shared SQLite project registry at once. In the case reported by @vianbas, a short-lived SQLite lock could make startup skip registration even though the local index had been built.

I moved the existing five-second SQLite busy timeout ahead of both the read-only compatibility check and the writable registry setup. Either connection can encounter the contention, and setting the timeout after the first database operation leaves that operation exposed. SQLite handles the wait at the point of contention, with the same connection ownership and a bounded delay. In ten Linux lite runs of the reported scenario, all nine repositories were registered each time, including eight initialized concurrently. That validation exercised lock release during startup. Timeout exhaustion, Windows, and macOS were outside the run. Registry startup PR.

Testing the package users actually install

I added a crates.io fallback for stable upgrades when a GitHub binary is unavailable. The upgrader checks the local toolchain, builds the selected crate version in a staging location, and validates the executable before replacing the current installation. I kept checksum failures fatal because a missing asset and a failed integrity check require different recovery. Cargo-managed installations retain their receipts. A standalone executable built locally needs a manual upgrade or reinstall before it can resume verified GitHub upgrades. Upgrade fallback PR, tagged upgrade guide.

The packaged-crate smoke tests then exposed a Windows crash at the end of tokensave init. A source checkout already carried a vendored libsql fix for closing a SQLite connection twice. Cargo strips [patch.crates-io] from the published manifest, and our package left out the vendored copy. The package therefore used the registry version of libsql, which still had the bug.

I raised the libsql requirement to 0.10.0, the registry release with the upstream fix. Its disconnect path clears the raw pointer after closing it, so a second pass reaches SQLite with a null pointer. The vendored copy still carries a separate failed-open fix, but the double-close correction now reaches the crate users actually install. The failure happened after indexing had reported success, which made the packaged end-to-end test especially important. A test of the extractor or a successful build from the workspace would miss the teardown behavior of the published dependency. Packaged libsql fix PR.

Opening a release candidate channel without changing the default

The next major line moves the code intelligence engine into a separate tokensave-core crate. Release candidates for that line needed a path to users who ask for them, without moving everyone else. Before this release, stable and prerelease versions were separate channels. The updater never offered a prerelease to a stable installation, and GitHub prerelease discovery ranked releases by listing order rather than by version.

I put the choice in a small selection module shared by the GitHub and crates.io sources. Stable remains the default. A candidate is eligible only when its version is newer than both the running version and the newest stable release, so an installed candidate moves to the matching stable release once it exists and is never downgraded. Consent comes from one of three places. The upgrade_prerelease setting opts in, and TOKENSAVE_UPGRADE_PRERELEASE overrides it for one run. Without either, an interactive tokensave upgrade shows the current, stable, and candidate versions and asks, defaulting to No. A non-interactive run picks stable and never prompts. I deliberately added no CLI flag, so a generic confirmation option in a script cannot opt a machine into a candidate. A candidate selected from GitHub never falls back to crates.io. Release candidate PR, tagged selection policy.

To opt in persistently, merge this key into an existing ~/.tokensave/config.toml:

upgrade_prerelease = true

The policy depends on correct ordering, so I made version comparison follow SemVer precedence. With that change, 8.0.0-rc.2 sorts before 8.0.0-rc.10, and both sort before 8.0.0. The same change removed an unnecessary cost from a major upgrade. Previously, the first MCP call reindexed every project whose recorded version was a major release behind, even when the schema had not changed. Reindexing now depends on the schema, plus the existing backfill for projects without a recorded version. A future major release that does need a rebuild has to bump the schema version explicitly. Agent integrations are still refreshed when an upgrade crosses a minor version or switches between candidate and stable releases.

The updater can only install what a release publishes, and the release workflow skipped prereleases entirely. In a follow-up, I let it build tokensave-beta archives for a GitHub prerelease. A guard requires the tag to be a SemVer prerelease equal to the Cargo.toml version, so the binary reports the same version the updater compares. Candidates cover the five platform slugs the updater can request, with a single signed Windows build, and they do not update Homebrew, Scoop, or release-drift state. The stable matrix is unchanged. Release candidate archives PR, tagged release guide.

I also recorded how already-installed 7.x binaries will reach 8.0.0. Releases up to 7.18.1 query the original repository endpoint, which redirects to tokensave-dev/tokensave-cli. Their stable-only discovery ignores candidates, and the archive names and SHA256SUMS contract stay the same. Based on that static review and live API checks, I concluded that no transitional 7.x release is needed for discovery and installation. The conclusion has limits. No 8.0.0 artifacts existed at the cutoff, so I have not run released 7.x binaries against a staged 8.0.0 release on Linux, macOS, or Windows. No real candidate had been published through the new workflow either. Tagged compatibility audit.