From 11145b228ee287faa43d21031c7abc44c26c28e7 Mon Sep 17 00:00:00 2001 From: Ansho Rei Date: Sun, 23 Aug 2026 14:14:14 +0200 Subject: [PATCH] (c092ea7) Ship the opencode tool definitions with the binary, behind install-tool `.opencode/tools/worklane.ts` was the second agent asset and the only one that existed nowhere but a checkout. `cargo install` places binaries and nothing else, so anyone who installed worklane got the skills and never the tools, and the copy that did exist was reachable only from this repo. It is now `assets/TOOL.ts`, embedded with `include_str!` like every other asset, and `install-tool` writes it where opencode looks. Its own command rather than a flag on `install-skill`, because the two artifacts are not alike. A skill is inert markdown and one path serves both agents. The tool is executable TypeScript and serves one: Claude Code has no directory it scans for a tool definition, `claude mcp add` is the only way a tool enters its list, and its plugin system adopts agents, hooks, monitors, workflows, output-styles and themes and nothing named tools. Reaching it would mean an MCP server, which is a different artifact and not this file. So somebody on Claude Code takes the documents and never the wrapper, which is the choice this command exists to give them. The path was measured rather than guessed, as the ticket asked. 1.15.10 loads `~/.config/opencode/tool/` and `~/.config/opencode/tools/` both: each was served in turn from a directory outside any project and `/experimental/tool/ids` came back with all eleven worklane tools. Singular is the target, the spelling opencode's own documentation puts first the way it writes `agent(s)` and `skill(s)`. `tools_root()` follows `XDG_CONFIG_HOME` where `skills_root()` does not, because opencode's config root is an XDG path and `~/.claude` is not; `opencode debug paths` reports `$XDG_CONFIG_HOME/opencode` with it set. An empty value counts as unset, the convention `colors_wanted` already follows. `opencode_tool_dir` takes both variables as arguments for the reason `colors_wanted` does: a threaded test binary cannot mutate the process environment to reach one branch at a time. The file name is load bearing and now pinned by a test. opencode builds each tool id as the file name then the export, so `worklane.ts` plus eleven `export const` lines is what makes them `worklane_add` through `worklane_uncheck`. Renaming the file renames every tool and every permission rule naming one. The closing line is not the skills' "on their next session". opencode reads its config once at startup and never reloads it, so a running one keeps the tools it began with and the honest instruction is to restart it. Nothing else has to be installed, which is worth saying because the file is executable and reads as though it wants a toolchain. Criterion 6 asked the command to name the plugin package and Bun as runtime requirements and both are wrong: a copy in a project with no `node_modules` above it registered all eleven tools on a machine with no `bun` on `PATH`. opencode is a Bun binary and the import resolves inside it. The message says the opposite, and the reasoning is on the ticket. `install_each` is the outcome loop both commands now share, with the compare-and-refuse invocation passed in: that line is the only part of an outcome that has to name the command it came from. What each command says after the loop stays with the command. `every_tool_the_wrapper_exports_is_a_real_subcommand` guards the direction that breaks at call time, a tool wrapping a command that has been renamed or dropped. Deliberately not the reverse: the wrapper has no tool for `relate`, `campaign`, `assign` or `tags`, so an agent holding the tools cannot reach campaigns or relations at all, and a test asserting that gap would fail on a decision nobody has taken rather than on a mistake. Its own ticket. Co-Authored-By: Claude Opus 5 (1M context) --- AGENTS.md | 11 +- README.md | 1 + .opencode/tools/worklane.ts => assets/TOOL.ts | 0 src/command.rs | 17 ++ src/handlers.rs | 68 +++++++- src/install.rs | 155 +++++++++++++++++- src/main.rs | 3 + tests/cmd_install_tool.rs | 149 +++++++++++++++++ 8 files changed, 391 insertions(+), 13 deletions(-) rename .opencode/tools/worklane.ts => assets/TOOL.ts (100%) create mode 100644 tests/cmd_install_tool.rs diff --git a/AGENTS.md b/AGENTS.md index a63a2f1..c831ec3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,6 +13,7 @@ - `assets/SKILL.md` - the agent skill for the CLI itself, embedded with `include_str!` - `assets/REVIEW.md` - the agent skill for reviewing a finished ticket, shipped the same way. Assets are named after the role they teach; `SKILL.md` keeps its name because the role it teaches is the CLI - `assets/PLAN.md` - the agent skill for grooming the whole board: priorities, due dates, tags and campaigns +- `assets/TOOL.ts` - the opencode tool definitions wrapping the CLI, embedded the same way and installed by `install-tool`. The only asset that is not a document and the only one that reaches a single agent - `tests/` - Integration tests using `assert_cmd` and `assert_fs`, one file per command - Unit tests live beside the code in `#[cfg(test)] mod tests`, in `util.rs`, `handlers.rs` and `tui.rs` - Ticket files stored as `.md` in `.worklane//` directories @@ -332,7 +333,7 @@ and this file is for what someone changing worklane's own code needs. - **A modified copy is refused, not overwritten.** Someone may have edited it on purpose, and the message names `--print` so it can be diffed and `--force` so it can be replaced. A read error is not treated as absent either: the write reports the real reason - Three tests guard the document rather than the mechanism, and they are the ones that earn their keep: the frontmatter has to parse (both agents silently ignore a document without it), every `worklane ` the skill shows has to be a real subcommand, and every subcommand outside `NOT_FOR_AGENTS` has to appear in the skill. The last one catches a new command that nothing tells an agent about - `install-skill` looks for no board. The skill is what teaches an agent worklane, so needing a `.worklane` to install it would put it out of reach exactly when it is wanted -- The assets under `.opencode/` are the user's, not this repo's to ship. Do not embed or install them. `reviewing-agent.md` there is the prior art the review skill grew out of and is deliberately **left in place**: its content is now in `assets/REVIEW.md`, but deleting a file under `.opencode/` is not this repo's call. Whether the stale copies there go is b2c5531's question +- The **agent files** under `.opencode/` are the user's, not this repo's to ship. Do not embed or install them. `reviewing-agent.md` there is the prior art the review skill grew out of and is deliberately **left in place**: its content is now in `assets/REVIEW.md`, but deleting a file under `.opencode/` is not this repo's call. Whether the stale copies there go is b2c5531's question. The tool file is the exception and no longer lives there: it was `.opencode/tools/worklane.ts`, which meant it existed only inside a checkout, and it is now `assets/TOOL.ts` and shipped like every other asset - **`install-skill` writes every shipped document, and the name narrows it.** One document teaches the CLI and the others teach a job done with it, so a person who learned the invocation before a document existed still receives it. Requiring a name per document would mean a new skill silently never arrives for anyone who does not read the changelog - **`--print` requires the name.** It exists so a modified copy can be diffed, and a diff is against one document; printing them concatenated would be neither of them. The unnamed case errors with the list of names rather than guessing, the same choice the `comment --` body makes - The refusal message names the document it is about, `install-skill worklane --print`, since with several installed "compare with --print" does not say compare what @@ -341,6 +342,14 @@ and this file is for what someone changing worklane's own code needs. - The review skill's own rules are guarded by `the_review_skill_keeps_the_decisions_that_define_it`, because each of them is a line an edit could drop without breaking anything: **the reviewer never ticks a criterion** (a tick is the implementer's claim, unticking is the review disagreeing, and one mark for both loses the disagreement), **never moves the ticket** (`mv` belongs to whoever does the work, the reviewer's half is the recommendation), and **never reviews the working tree when no commit names the ticket** (it says what it searched for and stops, since an untraceable ticket in `reviewing` is itself the finding) - **The plan skill is the one that can do damage, so its rules are the ones under test.** `set --tags` replaces the whole field, so a sweep that restates a ticket's tags incompletely deletes the rest, and a due date is neither validated nor clearable. `the_plan_skill_keeps_the_rules_that_bound_a_sweep` pins propose-then-apply and those two traps, because a document that loses them still reads like a plan - `.opencode/agent/feature-planner-agent.md` is **deliberately not folded into `PLAN.md`**. It decomposes a feature request into new tickets, which is intake; `PLAN.md` orders the tickets that already exist. Merging them would give one document two jobs and a frontmatter description that fits neither, which is the same reason the review skill is its own document +- **`install-tool` is a second command, not a flag on `install-skill`, because the two artifacts are not alike.** A skill is inert markdown that any agent can read and it reaches both from one path; the tool is executable TypeScript that reaches opencode alone. Claude Code has no directory it scans for a tool definition at all: `claude mcp add` with a `stdio`, `sse` or `http` transport is the only way a tool enters its tool list, and its plugin system adopts `agents`, `hooks`, `monitors`, `workflows`, `output-styles` and `themes` and nothing named tools. So an MCP server, a different artifact, would be what reached it. Verified against Claude Code 2.1.238 +- **`tools_root()` follows `XDG_CONFIG_HOME`, `skills_root()` does not.** `~/.claude` is not an XDG path and opencode's config root is: `opencode debug paths` reports `$XDG_CONFIG_HOME/opencode` with the variable set and `~/.config/opencode` without. An empty value counts as unset, the convention `colors_wanted` follows for `NO_COLOR`. `opencode_tool_dir` takes both variables as arguments for the reason `colors_wanted` does, since a threaded test binary cannot mutate the process environment to reach one branch at a time +- **Singular `tool`, and it was measured, not guessed.** opencode 1.15.10 loads `~/.config/opencode/tool/` and `~/.config/opencode/tools/` both: each was served in turn from a directory outside any project and `/experimental/tool/ids` registered all eleven worklane tools. The singular is the spelling opencode's own documentation puts first, the way it writes `agent(s)` and `skill(s)`. `opencode serve` plus that endpoint is how to check this again; there is no `opencode debug tool` to ask +- **`worklane.ts` is the file name the tool ids are built from.** opencode names each tool as the file then the export, so the file's eleven `export const` lines become `worklane_add` through `worklane_uncheck`. Renaming the file renames every tool and every permission rule that mentions one, which is why `TOOL.relative` is pinned by a test rather than left as a detail +- **The tool needs nothing installed beside opencode**, which is worth stating because the file is executable and reads as though it wants a toolchain. It is loaded into opencode's own Bun runtime and the `@opencode-ai/plugin` import resolves there: a copy in a project with no `node_modules` anywhere above it registered all eleven tools, on a machine with no `bun` on `PATH`. c092ea7's criterion 6 named those two as runtime requirements and it was wrong about both +- **The closing line differs from the skills', and that is not a wording choice.** opencode reads its config once at startup and never reloads it, so a running one keeps the tools it began with; the skills' "on their next session" would be a claim that is not true here +- **The wrapper is behind the CLI and nothing guards it.** It has no tool for `relate`, `campaign`, `assign` or `tags`, so an agent holding the tools cannot reach campaigns or relations at all. `every_tool_the_wrapper_exports_is_a_real_subcommand` catches the drift in the direction that breaks at call time, a tool for a command that no longer exists, and deliberately not the reverse: the gap is real, nobody has decided to close it, and a test asserting it would fail on that decision rather than on a mistake +- **Installing it globally reproduces fb3dec6 for the wrapper.** Global tools apply in every project including this one, so once `install-tool` has run, an agent working on worklane uses the installed copy of `assets/TOOL.ts` and not the tree it is editing. Same trap as the `worklane` on `PATH`, second instance - `every_agent_facing_subcommand_is_documented` stays on `SKILL` alone. It owns the CLI surface; a role document uses the handful of commands its job needs, and requiring the rest would fill a review document with `init` and campaigns to satisfy a test. The two checks that do run over every document are the frontmatter and that no document shows a command that does not exist ### Color and Output diff --git a/README.md b/README.md index 7f150cc..0bcccb1 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ Worklane is a local Kanban flow for agentic software development. | `worklane tags` | Lists the tags the board carries as the tag, a tab and how many tickets carry it, one per line, unstyled and alphabetical. Case sensitive like `ls --tag`, so `bug` and `Bug` list separately and land next to each other. Every status, done included. The one command that answers what tags exist rather than what carries a tag already known | | `worklane completions ` | Prints a completion script for `fish`, `bash`, `zsh`, `elvish` or `powershell`. See below | | `worklane install-skill [skill]` | Writes the embedded agent skills to `~/.claude/skills//SKILL.md`, which Claude Code and opencode both read. Three ship: `worklane` teaches the CLI, `worklane-review` reviews a finished ticket against the code that claims to close it, `worklane-plan` grooms the board as a whole, its priorities, due dates, tags and campaigns. Every document unless one is named. Leaves a modified copy alone unless `--force`; `--print` writes one to stdout instead and needs the name | +| `worklane install-tool` | Writes the embedded opencode tool definitions to `$XDG_CONFIG_HOME/opencode/tool/worklane.ts`, or `~/.config/opencode/tool/` without it, where opencode loads them for every project. One file and so no name to pass. `--force` and `--print` behave as they do for a skill. opencode only: it registers the eleven `worklane_*` tools from the file name and its exports, and Claude Code has no directory it scans for a tool definition, so reaching it would mean an MCP server rather than this. Restart opencode after installing, since it reads its config at startup and never reloads it. Nothing else to install: the file runs inside opencode's own runtime, so neither Bun nor `@opencode-ai/plugin` has to be on the machine | ## Completions diff --git a/.opencode/tools/worklane.ts b/assets/TOOL.ts similarity index 100% rename from .opencode/tools/worklane.ts rename to assets/TOOL.ts diff --git a/src/command.rs b/src/command.rs index e5c62ff..bc8a41a 100644 --- a/src/command.rs +++ b/src/command.rs @@ -281,6 +281,23 @@ pub enum Command { #[arg(long)] print: bool, }, + + /// Install the opencode tool definitions that wrap the worklane CLI + /// + /// One artifact, so no name to pass where `install-skill` takes an optional one: + /// `--print` here can only mean the one file. opencode alone, and globally, so the + /// tools are there in every project rather than in a checkout that happens to carry + /// them. Claude Code has no directory it scans for a tool definition; reaching it + /// would mean an MCP server, which is not this file. + InstallTool { + /// Overwrite an existing copy that has been modified + #[arg(long)] + force: bool, + + /// Write it to stdout instead of installing it + #[arg(long)] + print: bool, + }, } /// What a campaign can be asked for. diff --git a/src/handlers.rs b/src/handlers.rs index 76e82e3..9769dfd 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -1562,9 +1562,38 @@ pub fn cmd_install_skill(skill: Option<&str>, force: bool, print: bool) -> Resul }; let root = install::skills_root()?; + let written = install_each(&chosen, &root, force, |asset| { + format!("worklane install-skill {} --print", asset.name) + })?; + + // Once, and only when something arrived: repeating it per document would make the + // instruction look like part of each outcome rather than the one thing to do next. + if written { + println!("Claude Code and opencode pick it up on their next session"); + } + + Ok(()) +} + +/// Write each asset under `root` and report what happened to it. +/// +/// Shared by both install commands, which differ in what they install and in what they +/// say afterwards, never in how an outcome is reported. `compare` is the invocation the +/// refusal points at, which is the one line that has to name the command it came from. +/// +/// Returns whether anything was written, because that is what decides the closing line: +/// each command has its own thing to say about what picks the asset up, and neither +/// should say it once per asset. +fn install_each( + chosen: &[&install::Asset], + root: &Path, + force: bool, + compare: impl Fn(&install::Asset) -> String, +) -> Result { let mut written = false; + for asset in chosen { - match asset.install(&root, force)? { + match asset.install(root, force)? { install::Outcome::Written(path) => { println!("Installed the {} {} to: {}", asset.name, asset.what, path.display()); written = true; @@ -1574,18 +1603,41 @@ pub fn cmd_install_skill(skill: Option<&str>, force: bool, print: bool) -> Resul } install::Outcome::Refused(path) => { println!("Differs from the version in this binary: {}", path.display()); - println!( - "Compare with `worklane install-skill {} --print`, or overwrite with --force", - asset.name - ); + println!("Compare with `{}`, or overwrite with --force", compare(asset)); } } } - // Once, and only when something arrived: repeating it per document would make the - // instruction look like part of each outcome rather than the one thing to do next. + Ok(written) +} + +/// Install the opencode tool definitions. +/// +/// No name argument, where `install-skill` has an optional one: there is a single tool +/// file, so a name could only be right or wrong, and `--print` needs no help deciding +/// what to print. +pub fn cmd_install_tool(force: bool, print: bool) -> Result<()> { + if print { + print!("{}", install::TOOL.content); + return Ok(()); + } + + let chosen: Vec<&install::Asset> = install::TOOLS.iter().collect(); + let root = install::tools_root()?; + let written = + install_each(&chosen, &root, force, |_| "worklane install-tool --print".to_string())?; + + // Not "on its next session", which is what the skills say: opencode reads its config + // once at startup and does not reload it, so a running one keeps the tools it began + // with. The second line is there because the file is executable and looks like it + // needs a toolchain: it does not, it runs inside opencode. if written { - println!("Claude Code and opencode pick it up on their next session"); + println!( + "opencode loads it in every project. Restart it: the config is read at startup and never reloaded" + ); + println!( + "Nothing else to install. It runs in opencode's own runtime, so neither Bun nor @opencode-ai/plugin is needed on this machine" + ); } Ok(()) diff --git a/src/install.rs b/src/install.rs index bc5e947..3655d84 100644 --- a/src/install.rs +++ b/src/install.rs @@ -11,9 +11,11 @@ //! has learned the invocation should not have to learn a new name for each document //! added later, or the new one silently never arrives. //! -//! The machinery is written once for both kinds of asset this repo will ship. The tool -//! file for opencode is executable code needing Bun, so it gets its own command and its -//! own root, but the compare-and-refuse logic is the same and lives here. +//! The machinery is written once for both kinds of asset. The tool file is executable +//! code and reaches opencode alone, so it gets its own command and its own root, but the +//! compare-and-refuse logic is the same and lives here. What it needs at runtime is +//! opencode and nothing else: it is loaded into opencode's own runtime, so neither Bun +//! nor `@opencode-ai/plugin` has to be installed for the import in it to resolve. use std::io; use std::path::{Path, PathBuf}; @@ -73,6 +75,33 @@ pub const PLAN_SKILL: Asset = Asset { /// statement that took it: a `const` is inlined at each use and the borrow dies there. pub static SKILLS: [Asset; 3] = [SKILL, REVIEW_SKILL, PLAN_SKILL]; +/// The opencode tool definitions, the second kind of asset this binary carries. +/// +/// Executable TypeScript rather than a document, and it reaches one agent where a skill +/// reaches both: opencode loads a `.ts` file from its tool directory and Claude Code has +/// no directory it scans for one, so this is not the artifact that would reach it. That +/// asymmetry is the whole reason it is its own command with its own root rather than a +/// flag on `install-skill`. +/// +/// Flat in the root rather than in a directory of its own, and the file name is load +/// bearing: opencode builds each tool id as the file name then the export, so this file +/// is what makes them `worklane_add` and `worklane_mv` rather than `tool_add`. A skill +/// carries the equivalent in its frontmatter `name:`, which its directory has to agree +/// with; a tool carries it in the file name alone. +pub const TOOL: Asset = Asset { + name: "worklane", + what: "tool", + relative: "worklane.ts", + content: include_str!("../assets/TOOL.ts"), +}; + +/// Every tool this binary carries. +/// +/// One, and an array anyway: it is what keeps the install loop the same shape as the +/// skills', so a second tool needs no new machinery. A `static` for the reason `SKILLS` +/// is one. +pub static TOOLS: [Asset; 1] = [TOOL]; + /// The skill a name on the command line asks for. pub fn skill_named(name: &str) -> Result<&'static Asset> { SKILLS @@ -106,6 +135,48 @@ pub fn skills_root() -> Result { Ok(Path::new(&home).join(".claude/skills")) } +/// Where the tool has to sit for opencode to load it in every project. +/// +/// `XDG_CONFIG_HOME` when it is set and non-empty, `~/.config` otherwise, which is what +/// opencode itself resolves: `opencode debug paths` reports its config root under +/// `$XDG_CONFIG_HOME/opencode` with the variable set and `~/.config/opencode` without. +/// An empty value counts as unset, the convention `colors_wanted` already follows for +/// `NO_COLOR`. Checked against opencode 1.15.10. +/// +/// Singular `tool`, though 1.15.10 loads `tools` as well: each was served in turn from a +/// directory outside any project and registered all eleven worklane tools. The singular +/// is the spelling opencode's own documentation puts first, the way it writes `agent(s)` +/// and `skill(s)`. +/// +/// One agent, unlike `skills_root`. Claude Code has no path that belongs here at all: a +/// tool reaches it through an MCP server, which is a different artifact and not one this +/// binary carries. +pub fn tools_root() -> Result { + let xdg = std::env::var_os("XDG_CONFIG_HOME"); + let home = std::env::var_os("HOME"); + + opencode_tool_dir(xdg.as_deref().map(Path::new), home.as_deref().map(Path::new)) +} + +/// `tools_root` with the two variables passed in rather than read. +/// +/// The seam exists for the reason `colors_wanted` has one: both branches and the failure +/// have to be reachable from a test, and a threaded test binary cannot mutate the process +/// environment to reach them one at a time. +fn opencode_tool_dir(xdg: Option<&Path>, home: Option<&Path>) -> Result { + if let Some(xdg) = xdg.filter(|value| !value.as_os_str().is_empty()) { + return Ok(xdg.join("opencode/tool")); + } + + let home = home.ok_or_else(|| { + anyhow!( + "cannot tell where your opencode config lives because neither XDG_CONFIG_HOME nor HOME is set in the environment" + ) + })?; + + Ok(home.join(".config/opencode/tool")) +} + #[derive(Debug, PartialEq, Eq)] pub enum Outcome { Written(PathBuf), @@ -331,7 +402,7 @@ mod tests { /// Subcommands the skill has no business teaching: the board is interactive and /// belongs to a person, `install-skill` is how the document arrived, and `help` /// is clap's own. - const NOT_FOR_AGENTS: [&str; 3] = ["tui", "install-skill", "help"]; + const NOT_FOR_AGENTS: [&str; 4] = ["tui", "install-skill", "install-tool", "help"]; /// The converse, and the one that goes stale on its own: a *new* subcommand absent /// from the skill is invisible to an agent, and nothing else would notice. @@ -417,4 +488,80 @@ mod tests { ); } } + + // ------------------------------------------------------------ the tool -- + + /// `XDG_CONFIG_HOME` wins, because it is what opencode itself resolves its config + /// root from: `opencode debug paths` reports `$XDG_CONFIG_HOME/opencode` with it set. + #[test] + fn the_tool_root_follows_xdg_config_home_when_it_is_set() { + let root = opencode_tool_dir(Some(Path::new("/tmp/xdg")), Some(Path::new("/home/x"))); + assert_eq!(root.unwrap(), Path::new("/tmp/xdg/opencode/tool")); + } + + /// An empty value counts as unset, the convention `colors_wanted` already follows, so + /// a wrapper script that cleared an inherited one still lands in the home directory + /// rather than at `/opencode/tool`. + #[test] + fn an_empty_xdg_config_home_falls_back_to_the_home_directory() { + let root = opencode_tool_dir(Some(Path::new("")), Some(Path::new("/home/x"))); + assert_eq!(root.unwrap(), Path::new("/home/x/.config/opencode/tool")); + + let unset = opencode_tool_dir(None, Some(Path::new("/home/x"))); + assert_eq!(unset.unwrap(), Path::new("/home/x/.config/opencode/tool")); + } + + /// Neither one set is the case that has to fail rather than guess: writing to a + /// relative `.config/opencode/tool` would put the tool wherever the caller happened + /// to be standing. + #[test] + fn neither_variable_set_is_an_error_rather_than_a_relative_path() { + let error = opencode_tool_dir(None, None).unwrap_err().to_string(); + assert!(error.contains("XDG_CONFIG_HOME"), "{error}"); + assert!(error.contains("HOME"), "{error}"); + } + + /// The file name is the tool id prefix, not decoration: opencode names each tool as + /// the file then the export, so a renamed file renames all eleven tools and every + /// permission rule that mentions one. + #[test] + fn the_tool_lands_flat_in_the_root_under_the_name_that_prefixes_its_ids() { + let root = opencode_tool_dir(None, Some(Path::new("/home/x"))).unwrap(); + + assert_eq!(TOOL.path(&root), Path::new("/home/x/.config/opencode/tool/worklane.ts")); + assert_eq!(TOOL.relative, "worklane.ts"); + } + + /// Every tool the file exports names a real subcommand. + /// + /// The guard the fish completion lists already have, pointed the other way: this + /// catches a tool wrapping a command that has been renamed or dropped, which would + /// fail only when an agent finally called it. It cannot catch the reverse, a + /// subcommand the wrapper never grew a tool for, and the wrapper is behind by + /// several: `relate`, `campaign`, `assign` and `tags` have no tool. That is its own + /// ticket, and asserting it here would fail on a gap nobody has decided to close. + #[test] + fn every_tool_the_wrapper_exports_is_a_real_subcommand() { + use clap::CommandFactory; + + let commands: Vec = crate::Cli::command() + .get_subcommands() + .map(|command| command.get_name().to_string()) + .collect(); + + let exported: Vec<&str> = TOOL + .content + .lines() + .filter_map(|line| line.strip_prefix("export const ")) + .filter_map(|rest| rest.split_whitespace().next()) + .collect(); + + assert_eq!(exported.len(), 11, "{exported:?}"); + for name in exported { + assert!( + commands.iter().any(|command| command == name), + "the wrapper exports {name:?}, which is not a subcommand: {commands:?}" + ); + } + } } diff --git a/src/main.rs b/src/main.rs index ae51ec8..f18a7d2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,6 +92,9 @@ fn main() -> Result<()> { Some(Command::InstallSkill { skill, force, print }) => { cmd_install_skill(skill.as_deref(), force, print) } + // No board either, and one agent rather than both: opencode loads the tool file, + // Claude Code has no path for one. + Some(Command::InstallTool { force, print }) => cmd_install_tool(force, print), } } diff --git a/tests/cmd_install_tool.rs b/tests/cmd_install_tool.rs new file mode 100644 index 0000000..5395820 --- /dev/null +++ b/tests/cmd_install_tool.rs @@ -0,0 +1,149 @@ +use assert_cmd::Command; +use assert_fs::TempDir; + +const BIN_NAME: &str = env!("CARGO_BIN_EXE_worklane"); + +/// The tool as this test's binary carries it, so the print path is pinned to the file in +/// the repo rather than to a description of it. +const TOOL: &str = include_str!("../assets/TOOL.ts"); + +/// `XDG_CONFIG_HOME` is redirected, and `HOME` with it, so the suite never writes into +/// the config of whoever runs it. Both, because the fallback reads `HOME` and a machine +/// that has neither set is not the case under test here. +fn run(config: &TempDir, args: &[&str]) -> std::process::Output { + let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); + cmd.env("XDG_CONFIG_HOME", config.path()) + .env("HOME", config.path()) + .args(args); + cmd.assert().get_output().clone() +} + +fn installed(config: &TempDir) -> std::path::PathBuf { + config.path().join("opencode/tool/worklane.ts") +} + +fn stdout(output: &std::process::Output) -> String { + String::from_utf8(output.stdout.clone()).unwrap() +} + +/// Nothing about the tool needs a board, and it is wanted before there is one. +/// +/// The file name is asserted, not just the directory: opencode names each tool as the +/// file then the export, so `worklane.ts` is what makes them `worklane_add` and +/// `worklane_mv`. +#[test] +fn the_tool_installs_outside_a_worklane_directory() { + let config = TempDir::new().unwrap(); + let output = run(&config, &["install-tool"]); + + assert!(output.status.success()); + assert_eq!(std::fs::read_to_string(installed(&config)).unwrap(), TOOL); + assert!( + stdout(&output).contains("Installed the worklane tool"), + "{}", + stdout(&output) + ); +} + +/// What the message has to carry, and it is not the skills' "next session": opencode +/// reads its config once at startup and never reloads it, so a running one keeps the +/// tools it began with. The second half is there because the file is executable and +/// looks like it needs a toolchain, which it does not. +#[test] +fn the_tool_says_to_restart_opencode_and_that_nothing_else_is_needed() { + let config = TempDir::new().unwrap(); + let out = stdout(&run(&config, &["install-tool"])); + + assert!(out.contains("Restart it"), "{out}"); + assert!(out.contains("never reloaded"), "{out}"); + assert!(out.contains("Nothing else to install"), "{out}"); + assert!(out.contains("Bun"), "{out}"); +} + +/// Installing twice is a no-op rather than a rewrite, exactly as `install-skill` is. +#[test] +fn a_second_install_reports_the_copy_unchanged() { + let config = TempDir::new().unwrap(); + run(&config, &["install-tool"]); + let out = stdout(&run(&config, &["install-tool"])); + + assert!(out.contains("Already up to date"), "{out}"); + assert!(!out.contains("Installed the"), "{out}"); +} + +/// An edited copy is somebody's work, and the refusal names the invocation that shows +/// what it would be replaced with. `--print` there and not a skill name: there is one +/// tool file, so nothing has to say which. +#[test] +fn a_modified_copy_is_refused_until_force() { + let config = TempDir::new().unwrap(); + run(&config, &["install-tool"]); + std::fs::write(installed(&config), "// hand written\n").unwrap(); + + let refused = stdout(&run(&config, &["install-tool"])); + assert!(refused.contains("Differs from the version in this binary"), "{refused}"); + assert!(refused.contains("worklane install-tool --print"), "{refused}"); + assert_eq!(std::fs::read_to_string(installed(&config)).unwrap(), "// hand written\n"); + + let forced = stdout(&run(&config, &["install-tool", "--force"])); + assert!(forced.contains("Installed the worklane tool"), "{forced}"); + assert_eq!(std::fs::read_to_string(installed(&config)).unwrap(), TOOL); +} + +/// `--print` is for diffing against an installed copy, so it writes nothing. +#[test] +fn print_writes_the_tool_to_stdout_and_installs_nothing() { + let config = TempDir::new().unwrap(); + let output = run(&config, &["install-tool", "--print"]); + + assert_eq!(stdout(&output), TOOL); + assert!(!installed(&config).exists()); +} + +/// With no `XDG_CONFIG_HOME` the tool lands under `HOME`, which is the same answer +/// opencode gives: its config root is `$XDG_CONFIG_HOME/opencode` when that is set and +/// `~/.config/opencode` when it is not. +#[test] +fn the_tool_falls_back_to_the_home_directory_without_xdg_config_home() { + let home = TempDir::new().unwrap(); + let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); + let output = cmd + .env_remove("XDG_CONFIG_HOME") + .env("HOME", home.path()) + .arg("install-tool") + .assert() + .success() + .get_output() + .clone(); + + let path = home.path().join(".config/opencode/tool/worklane.ts"); + assert_eq!(std::fs::read_to_string(&path).unwrap(), TOOL); + assert!( + stdout(&output).contains(&path.display().to_string()), + "{}", + stdout(&output) + ); +} + +/// The two commands are independent, which is the whole point of them being two: a +/// person on Claude Code takes the skills and never the tool, and one who wants the +/// tools is not made to take a second copy of the documents to get them. +#[test] +fn each_install_command_leaves_the_other_target_alone() { + let config = TempDir::new().unwrap(); + run(&config, &["install-tool"]); + + assert!(installed(&config).exists()); + assert!(!config.path().join(".claude/skills").exists()); + + let skills_only = TempDir::new().unwrap(); + run(&skills_only, &["install-skill"]); + + assert!( + skills_only + .path() + .join(".claude/skills/worklane/SKILL.md") + .exists() + ); + assert!(!installed(&skills_only).exists()); +}