Repository navigation
feat(cli/dir): add semver comparison and the install manifest - #2123
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Partial, skipped, and concurrent operations can leave the manifest incomplete or incorrectly remove rows.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds semantic-version utilities and persistent install-manifest bookkeeping for dirctl installs and uninstalls.
Changes:
- Adds semantic-version comparison helpers.
- Records successfully installed artifacts and removes cleared manifest rows.
- Adds
--pinsupport and skill-bundle file discovery.
File summaries
| File | Description |
|---|---|
docs/content/dir/dir-cli-reference.md |
Documents manifests and pinning. |
cli/util/pkgver/pkgver.go |
Adds semantic-version utilities. |
cli/util/pkgver/pkgver_test.go |
Tests version behavior. |
cli/internal/pkgstate/pkgstate.go |
Implements manifest persistence. |
cli/internal/pkgstate/pkgstate_test.go |
Tests manifest operations. |
cli/internal/agentinstall/entry.go |
Builds and clears manifest entries. |
cli/internal/agentinstall/entry_test.go |
Tests entry construction. |
cli/internal/agentinstall/derive.go |
Captures bundle file lists. |
cli/internal/agentinstall/apply.go |
Uses artifact constants. |
cli/internal/agentcfg/skill_engine.go |
Standardizes skill outcomes. |
cli/internal/agentcfg/result.go |
Adds artifact constants and server identity. |
cli/internal/agentcfg/mcp_engine.go |
Records MCP server keys. |
cli/cmd/install/uninstall.go |
Records uninstall results. |
cli/cmd/install/run.go |
Adds the run-command pin flag. |
cli/cmd/install/options.go |
Adds pin state. |
cli/cmd/install/manifest.go |
Wires manifest updates. |
cli/cmd/install/manifest_test.go |
Tests manifest wiring. |
cli/cmd/install/install.go |
Integrates pinning and recording. |
cli/cmd/install/install_test.go |
Tests pin behavior. |
cli/cmd/install/flags.go |
Defines --pin. |
cli/cmd/install/batch.go |
Records batch operations. |
cli/cmd/install/batch_test.go |
Tests per-record batch outcomes. |
api/exportfmt/skill_bundle_extract.go |
Lists bundle files. |
api/exportfmt/exportfmt_test.go |
Tests bundle file discovery. |
Review details
- Files reviewed: 24/24 changed files
- Comments generated: 3
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🟡 Changes recommended
Shared skill deduplication can leave manifest rows missing or stale, and version comparison is not yet centralized as specified.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
cli/util/pkgver/pkgver.go:9
- The promised centralization is not in effect:
cli/util/records.LatestByNamestill importsx/mod/semverand uses its owncanonicalVersion/semver.Compare, whilepkgverhas no production callers. Batch install, pull, and export therefore bypass this package, contrary to the stated invariant. RefactorLatestByNameto usepkgverso version-ordering semantics have one implementation.
- Files reviewed: 24/24 changed files
- Comments generated: 2
- Review effort level: Balanced
akijakya
left a comment
There was a problem hiding this comment.
On the suppressed finding about pkgver not being centralized: correct, and fixed in a8cce2f.
records.LatestByName used x/mod/semver and its own canonicalVersion, so batch install, pull, and export ordered versions through a second implementation while pkgver had no production callers at all. The package doc's invariant was simply not true. LatestByName now calls pkgver.Canonical and pkgver.Compare, and canonicalVersion is deleted. Two tests lock in the behaviour that motivated the package: 1.10.0 beating 1.9.0, and an unorderable version never displacing a comparable one while still being kept when nothing comparable exists.
cli/util/reference still imports semver and I left it deliberately. parseNameAndVersion uses semver.IsValid to decide whether the text after the last colon looks like a version rather than a port number, so it is a parse heuristic about shape, not a decision about which of two versions is newer. Folding it in would change how references parse for no gain against the invariant, which is about ordering.
Signed-off-by: András Jáky <[email protected]>
Two review findings, both about a row claiming less than what is on disk. A row now names every artifact dirctl wrote and has not since removed, not only the artifacts the newest install produced. Entry gains WithCarriedArtifacts, and recordInstalls merges the previous row into the new one rather than replacing it wholesale. Without this, a reinstall whose skill succeeded but whose MCP config could not be read wrote a row naming only the skill, silently dropping the earlier server key that is still in that config and that nothing else would ever remove. The same merge covers a new version renaming its MCP server, since plain install removes nothing first and both keys end up on disk. Cleared now requires a confirmation rather than merely no failure: at least one artifact removed or found already absent, and none failed. A skip on its own means the artifact's location could not be resolved for this scope, so nothing was removed and nothing was even looked at, while whatever the row recorded may still be on disk. Dropping the row there threw away the only note of what to clean up. A skip alongside a real removal still clears, which is the common case of an agent holding an MCP entry at a scope where it has no skill location. Signed-off-by: András Jáky <[email protected]>
…gh pkgver Three review findings. Claude Code and Claude Desktop share one skills folder, and so do Zed and Codex CLI, so the skill is written once. Install and Uninstall used to pass over the second agent in silence, which left it with no outcome and so no manifest row, and meant uninstalling for only one of a pair could never clear the other's row. dedupeSkill becomes claimSkillPath and returns the resolved path, and both flows now report an ActionUnchanged outcome naming that same path for the agent that shares it. The plan and summary gain one line per shared agent, which is also more honest than saying nothing about an agent the artifact serves. records.LatestByName went through x/mod/semver and its own canonicalVersion, so batch install, pull, and export bypassed pkgver entirely and the package's stated invariant was not true. It now calls pkgver.Canonical and pkgver.Compare, and canonicalVersion is gone. util/reference still calls semver.IsValid, deliberately: it is testing whether a colon-suffix looks like a version while parsing a reference, not ordering two versions. The docs and package comments claimed that uninstall already removes the recorded artifacts without re-fetching the record. It does not. It resolves and pulls the record, derives its current artifacts, removes those, and only then deletes rows. Every such claim now says the fields are recorded so that manifest-driven uninstall and upgrade can do that. Signed-off-by: András Jáky <[email protected]>
a8cce2f to
cab9ea5
Compare
Adds the three leaf packages the rest of dirctl package management is built on, plus the wiring that makes
installanduninstallkeep a record of what they did. No new user-facing commands: both behave as they do today and additionally write a manifest row.cli/util/pkgveris semantic version comparison. The server compares versions as SQL text, soversion > ?against a text column ranks v1.10.0 below v1.9.0; every client-side "is this newer?" decision now orders versions in the CLI instead.Canonicaladds the "v" prefix records commonly omit and returns""for anythinggolang.org/x/mod/semverrejects, which doubles as the comparability test. The short formsv1andv1.0canonicalize tov1.0.0rather than fail, deliberately: a record tagged1.0is still orderable. Strings likemain,latest,2026-08-14and1.0.0.0carry no ordering at all and must never be auto-upgraded across.Comparesorts those below every real version so a mixed list still sorts,Newestreturns the highest entry as the caller spelled it, andIsPrereleasekeeps release candidates out of upgrade suggestions.cli/internal/pkgstateis the manifest at$XDG_CONFIG_HOME/dirctl/installed.json, keyed by (name, agent, scope). Each row stores the artifacts that were actually written — skill path, skill file list, MCP server keys — rather than what the record's modules imply. Nothing reads those fields yet: today'suninstallstill resolves and pulls the record, derives its current artifacts, removes those, and only then deletes rows. They are recorded so that manifest-driven uninstall and upgrade can remove exactly what was written, without re-fetching a record that may since have been garbage-collected upstream. There is notypefield, because one record can yield both a skill and MCP servers, so the artifact kind is derived for display.Originseparatesdirectoryrows frombuiltinones. Writes are temp-file plus rename. A missing file reads as empty, a corrupt file degrades to an empty-but-flagged manifest with a warning, and a forwardschemaVersionis additionally frozen so a newer dirctl's rows are never overwritten. Losing the manifest never fails an install. The path is injected by callers and onlyDefaultPathreads the environment, so the tests are hermetic.api/exportfmt.SkillBundleFileslists a bundle's regular files.TarEntry's fields are unexported, so this is the one accessor callers outsideexportfmthave for entry names; a plain-textSKILL.mdartifact reports the single file the extractor creates for it.DeriveArtifactscalls it once, where a malformed bundle can still be reported as an error, which keepsSkillFilesa plain accessor.agentinstallgainsSlug,HasSkill,MCPServerNames,SkillFiles,BuildEntry, andCleared, sinceArtifacts's fields are unexported andcli/cmd/installcannot build a row from them.agentcfg.Outcomegains aServerfield: one agent produces one outcome per MCP server, all sharing a config path, so nothing else told them apart and a row could not honestly claim only the keys that were written.ArtifactMCPandArtifactSkillreplace the artifact-kind string literals in the two placement engines.runApplyCmdandrunBatchrecord rows after a successful apply, one per agent that actually received an artifact. Agents whose outcomes were all skipped or failed are not recorded, so a later listing never claims an install that did not happen; on uninstall, an agent whose removal failed keeps its row, because its artifacts are still on disk. Dry runs record nothing, and project-scope installs are not tracked in this iteration — the row shape already carriesscope, so a committed per-project manifest is a later addition rather than a rewrite.--pinis added as a local flag oninstallandinstall run, implied whenever the reference carries an explicit:version. It is flag-bound rather than a plain field because the local e2e suite runs dirctl in-process against a package-leveloptssingleton, so anything the harness does not reset leaks between specs.records.LatestByNameis refactored ontopkgver, so batch install, pull, and export no longer carry a second version-ordering implementation, andcanonicalVersionis deleted.cli/util/referencekeeps its ownsemver.IsValidcall on purpose: it decides whether the text after a reference's last colon looks like a version rather than a port, which is a question about shape, not about which of two versions is newer.Shared skill locations are recorded for every agent they serve. Claude Code and Claude Desktop share one skills folder, and so do Zed and Codex CLI, so the skill is written once;
InstallandUninstallnow report anActionUnchangedoutcome naming that path for the agent that shares it, instead of passing over it in silence. Without that the manifest held a row for the first agent only, and uninstalling for one of a pair could never clear the other's row. The plan and summary gain one line per shared agent.list,outdated,upgrade, andpin/unpinstay out of scope. This PR only makes the manifest exist and stay correct. One known gap is deferred with them: uninstalling a shared skill for only one agent of a pair leaves the other's row pointing at a path that is gone. Reconciling it correctly means clearing just that row's skill fields and dropping the row only once nothing is left in it, which is the per-artifact reconciliation the upgrade path has to build anyway.Closes #2028.
Validation:
task testacross all seven modules: pass.cd cli && go test ./util/pkgver/... ./internal/pkgstate/... ./internal/agentinstall/... ./cmd/install/...andcd api && go test ./exportfmt/...pass, and./cmd/install/...passes at-count=2, which is what catches the in-processoptssingleton trap.task lint:go: 0 issues in every module, with pinned golangci-lint 2.13.2.pkgvertruth table is verified againstgolang.org/x/mod/semverrather than assumed, including the short forms it accepts and each string it rejects.dirctl install --help,install run --help, andinstall uninstall --helpconfirm--pinrenders as a boolean and appears only on the two install entry points.