Skip to content

feat(cli/dir): add semver comparison and the install manifest - #2123

Merged
akijakya merged 3 commits into
mainfrom
feat/semver-comparison-and-install-manifest
Sep 9, 2026
Merged

akijakya merged 3 commits into
mainfrom
feat/semver-comparison-and-install-manifest

Conversation

@akijakya

@akijakya akijakya commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Adds the three leaf packages the rest of dirctl package management is built on, plus the wiring that makes install and uninstall keep 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/pkgver is semantic version comparison. The server compares versions as SQL text, so version > ? 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. Canonical adds the "v" prefix records commonly omit and returns "" for anything golang.org/x/mod/semver rejects, which doubles as the comparability test. The short forms v1 and v1.0 canonicalize to v1.0.0 rather than fail, deliberately: a record tagged 1.0 is still orderable. Strings like main, latest, 2026-08-14 and 1.0.0.0 carry no ordering at all and must never be auto-upgraded across. Compare sorts those below every real version so a mixed list still sorts, Newest returns the highest entry as the caller spelled it, and IsPrerelease keeps release candidates out of upgrade suggestions.

cli/internal/pkgstate is 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's uninstall still 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 no type field, because one record can yield both a skill and MCP servers, so the artifact kind is derived for display. Origin separates directory rows from builtin ones. 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 forward schemaVersion is 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 only DefaultPath reads the environment, so the tests are hermetic.

api/exportfmt.SkillBundleFiles lists a bundle's regular files. TarEntry's fields are unexported, so this is the one accessor callers outside exportfmt have for entry names; a plain-text SKILL.md artifact reports the single file the extractor creates for it. DeriveArtifacts calls it once, where a malformed bundle can still be reported as an error, which keeps SkillFiles a plain accessor.

agentinstall gains Slug, HasSkill, MCPServerNames, SkillFiles, BuildEntry, and Cleared, since Artifacts's fields are unexported and cli/cmd/install cannot build a row from them. agentcfg.Outcome gains a Server field: 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. ArtifactMCP and ArtifactSkill replace the artifact-kind string literals in the two placement engines.

runApplyCmd and runBatch record 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 carries scope, so a committed per-project manifest is a later addition rather than a rewrite. --pin is added as a local flag on install and install 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-level opts singleton, so anything the harness does not reset leaks between specs.

records.LatestByName is refactored onto pkgver, so batch install, pull, and export no longer carry a second version-ordering implementation, and canonicalVersion is deleted. cli/util/reference keeps its own semver.IsValid call 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; Install and Uninstall now report an ActionUnchanged outcome 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, and pin/unpin stay 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 test across all seven modules: pass. cd cli && go test ./util/pkgver/... ./internal/pkgstate/... ./internal/agentinstall/... ./cmd/install/... and cd api && go test ./exportfmt/... pass, and ./cmd/install/... passes at -count=2, which is what catches the in-process opts singleton trap.
  • task lint:go: 0 issues in every module, with pinned golangci-lint 2.13.2.
  • The pkgver truth table is verified against golang.org/x/mod/semver rather than assumed, including the short forms it accepts and each string it rejects.
  • dirctl install --help, install run --help, and install uninstall --help confirm --pin renders as a boolean and appears only on the two install entry points.

@akijakya
akijakya requested a review from a team as a code owner September 8, 2026 12:45
@akijakya akijakya added kind/feature Categorizes issue or PR as related to a new feature. area/cli/dir area/cli labels Sep 8, 2026
@github-actions github-actions Bot added the size/L Denotes a PR that changes 1000-1999 lines label Sep 8, 2026
@akijakya akijakya self-assigned this Sep 8, 2026
@akijakya
akijakya requested a balanced review from Copilot September 8, 2026 14:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 --pin support 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.

Comment thread cli/cmd/install/manifest.go Resolved
Comment thread cli/cmd/install/manifest.go Resolved
Comment thread cli/internal/agentinstall/entry.go Resolved
@codecov

codecov Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

@github-actions github-actions Bot added size/XL Denotes a PR that changes 2000+ lines and removed size/L Denotes a PR that changes 1000-1999 lines labels Sep 8, 2026
@akijakya
akijakya requested a balanced review from Copilot September 9, 2026 07:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.LatestByName still imports x/mod/semver and uses its own canonicalVersion/semver.Compare, while pkgver has no production callers. Batch install, pull, and export therefore bypass this package, contrary to the stated invariant. Refactor LatestByName to use pkgver so version-ordering semantics have one implementation.
  • Files reviewed: 24/24 changed files
  • Comments generated: 2
  • Review effort level: Balanced

Comment thread cli/internal/agentinstall/entry.go Resolved
Comment thread docs/content/dir/dir-cli-reference.md Resolved

@akijakya akijakya left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@akijakya
akijakya enabled auto-merge (squash) September 9, 2026 11:18
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]>
@akijakya
akijakya force-pushed the feat/semver-comparison-and-install-manifest branch from a8cce2f to cab9ea5 Compare September 9, 2026 11:18
@akijakya
akijakya merged commit ad1c172 into main Sep 9, 2026
11 checks passed
@akijakya
akijakya deleted the feat/semver-comparison-and-install-manifest branch September 9, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli/dir area/cli kind/feature Categorizes issue or PR as related to a new feature. size/XL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Package management foundations: semantic version comparison and the install manifest

3 participants