feat(cli): import/export verbs + Pathbase round-trip#58
Open
eliothedeman wants to merge 2 commits intomainfrom
Open
feat(cli): import/export verbs + Pathbase round-trip#58eliothedeman wants to merge 2 commits intomainfrom
eliothedeman wants to merge 2 commits intomainfrom
Conversation
|
🔍 Preview deployed: https://69e3b4ef.toolpath.pages.dev |
Collapse the external-boundary CLI surface to `import` and `export`, with Pathbase as a peer source/target to claude/gemini/codex/opencode/pi/git/github. New commands: - `path import <source>` — ingest into ~/.toolpath/documents/<cache-id>.json - `path export <target>` — emit from toolpath into external formats - `path cache ls | rm` — list / remove cached documents New sources/targets: - `import pathbase <id-or-url>` — GET /api/v1/traces/:id into the cache - `export pathbase --input <ref>` — POST the document to /api/v1/traces Shared plumbing: - cmd_pathbase.rs — HTTP client, session storage, `traces_post` / `traces_get` - cmd_cache.rs — cache dir (0700), file writes (0600), `cache_ref` (id or path) `<ref>` accepted by export/upload resolves as a bare cache id first, falling back to a filesystem path. `--no-cache` on import sends JSON to stdout for shell composition. Deprecated (hidden aliases, one-release overlap, stderr warning): - `path derive` → `import` - `path incept` / `path project claude` → `export claude` Server endpoints `POST/GET /api/v1/traces[/:id]` don't exist yet — the CLI surfaces a clean connection/404 error until they ship.
Blockers: - Fix wasm/emscripten build: `cmd_cache` unconditionally imported from `cmd_pathbase` (which is cfg-gated off emscripten). Extract `config_dir` into a new un-gated `config` module; both `cmd_cache` and `cmd_pathbase` use it. - Fix cache id collisions across repos on the same branch. Fold an 8-hex hash of the canonical repo path into git cache ids (`git-a1b2c3d4-path-main` vs `git-e5f6a7b8-path-main`). Replace the ad-hoc `cache_id_for_doc` with a composable `doc_inner_id` + `make_id`. Robustness: - `write_cached` now uses `OpenOptions::create_new` when `!force`, so concurrent imports can't silently stomp each other (was a TOCTOU race between the exists-check and the write). - `make_id` strips a trailing `.json` so a trace id like `trc.json` doesn't produce `pathbase-trc.json` and then fail `cache_path`'s suffix validator. UX: - `export pathbase --url` warns when its host differs from the session's server — previously would just 401. - `cache_ref` file-not-found branch hints at `path cache ls` + dropping the extension for typo recovery. Tests: - New `MockServer` (raw TcpListener) exercises `traces_post` / `traces_get` success, 401, 404, and 5xx with server-supplied error messages. No new dependencies. - Two-repo cache-id integration test: import `main` from two distinct git fixtures, assert two cache entries instead of a collision. - `--pretty` propagates through `--no-cache` to stdout. - Multi-session claude import emits one cache entry per session. - Total: 165 unit + 26 integration, zero failures. Release: - Bump toolpath-cli 0.4.0 → 0.5.0. CHANGELOG + site/_data/crates.json updated per the release checklist.
943387c to
1a3f081
Compare
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
Collapse the external-boundary CLI surface to two symmetric verbs, with Pathbase as a peer source/target to
claude,gemini,codex,opencode,pi,git, andgithub— not a privileged verb pair.path import <source>— ingest into~/.toolpath/documents/<cache-id>.jsonpath export <target>— emit from toolpath into external formatspath cache ls | rm— list / remove cached documentsThe Pathbase round-trip (asked for)
path import pathbase <id-or-url>—GET /api/v1/traces/:id→ cachepath export pathbase --input <ref>—POST /api/v1/traces← cache or file<ref>accepted by export resolves as a bare cache id first, falling back to a filesystem path. Auth reuses the existingpath auth login/~/.toolpath/credentials.jsonflow.New files
crates/toolpath-cli/src/cmd_pathbase.rs— shared HTTP/session plumbing (extracted fromcmd_auth.rs), plustraces_post/traces_get/require_sessioncrates/toolpath-cli/src/cmd_cache.rs— cache directory (0700), file writes (0600),cache_refresolver,ls/rmsubcommands, slug generationcrates/toolpath-cli/src/cmd_import.rs— per-source handlers (wascmd_derive.rs), plusPathbasesourcecrates/toolpath-cli/src/cmd_export.rs—Claude+Pathbasetargets (supersedescmd_incept.rs+cmd_project.rs)Deprecations
One-release overlap; each prints a stderr warning and delegates into the new handler:
path derive→path import(stdout preserved via implicit--no-cache)path incept→path export claude --project <dir>path project claude→path export claudeErgonomics
--no-cacheon import sends JSON to stdout for shell composition withrender | query | validate--forceto overwrite an existing cache entry; default is error-on-exists for uniformity across every source$TOOLPATH_CONFIG_DIRoverrides the cache root (already honored by the credentials helper)Test plan
cargo build --workspace(excl. toolpath-desktop)cargo test --workspace(excl. toolpath-desktop) — 33 binaries, 0 failures, 156 unit + 24 integration on toolpath-clicargo clippy --workspace --all-targets -- -D warnings— clean (includes fix for a pre-existingneedless_borrowintoolpath-convo/src/lib.rs:1026and an#[allow(deprecated)]for the pre-existingassert_cmd::cargo_bininrender_md_snapshots.rs)path import git --repo . --branch mainwrites cache + prints pathpath cache lssurfaces the entry;path cache rmremoves itpath import git --no-cache | path render mdcomposespath derive gitstill works and warnspath export pathbase --input <ref>without login errors withNot logged in. Run \path auth login`.`path import pathbase <id>without login errors the same wayFollow-ups (out of scope)
POST/GET /api/v1/traces[/:id]gemini/codex/opencode/pitargets (each needs aConversationProjectorimpl in the respective crate)toolpath-desktop's upload stub to callcmd_pathbase::traces_postonce the server is realpath cache gc— size-based pruningderive/incept/projectaliases one release later