Repository navigation
feat(tags): create tags from the CLI - #150
Merged
Merged
Conversation
Add `things tag add <name>...` and a `--create-tags` flag on add, project add, edit, project edit and import. The Things URL scheme applies only tags that already exist, so missing ones are created over AppleScript before the write. Existing names are skipped, matched case-insensitively as Things matches them. `--create-tags` and `--strict-tags` ask for opposite things and are rejected together. `tag add` reads the tag list back to confirm the creation landed, which `--no-verify` skips. Closes #144
…al writes Apply code review findings: - the --strict-tags hint joined tag names with ", ", suggesting a command that would create a tag literally named "focus,". It now emits space-separated, quoted names. - `--no-verify` help now mentions that it also gates the tag-creation read-back. - a failed read-back after `tag add` now names the tags that were already sent, instead of exiting non-zero with no record of them. - `tag add` validates its arguments before opening the database, so a blank name reports itself rather than a missing-database error.
ryanlewis
added a commit
that referenced
this pull request
Sep 5, 2026
## What changed A TOML config file supplies defaults for existing flags, so they can be set once instead of typed every time. The file is read from `$XDG_CONFIG_HOME/things-cli/config.toml`, falling back to `~/.config/things-cli/config.toml`. `--config PATH` and `$THINGS_CLI_CONFIG` override the location. A missing file is not an error. Keys are the flag name in snake_case, and each maps onto a flag that already exists: | Key | Flag | Type | Default | | --- | --- | --- | --- | | `json` | `--json` | boolean | `false` | | `color` | `--color` | `"auto"`, `"always"`, `"never"` | `"auto"` | | `db` | `--db` | path (must exist) | auto-detected | | `no_verify` | `--no-verify` | boolean | `false` | | `strict_tags` | `--strict-tags` | boolean | `false` | | `create_tags` | `--create-tags` | boolean | `false` | The hyphenated spelling (`no-verify`) is accepted too; writing a setting under both spellings in one file is an error rather than a coin flip. `strict_tags` and `create_tags` are mutually exclusive, and setting both to `true` is an error that names the file. New subcommands: - `things config path` — the file in use and whether it exists (`--json` gives path, exists, source). - `things config show` — the defaults the file establishes, each marked `config` or `default`. - `things config init` — writes a fully commented template. Refuses to overwrite; `--force` replaces. ## Why Closes #159, and unblocks #153, which needs somewhere to keep a persistent setting. ## How it works The file only seeds kong's flag resolution — it registers a `kong.Resolver`, and kong skips resolvers for flags already given on the command line. So precedence is flag > config file > built-in default with no second code path, and no command reads config values itself. `--strict-tags` and `--create-tags` are `xor`-ed, and kong counts a resolved value as set for that check, so the resolver takes care not to break the precedence rule for them: a `false` value for either is never passed on (false means the same as absent), and neither is passed on when the other was given on the command line. So `things add x --strict-tags` still wins over `create_tags = true` in the file rather than failing with "can't be used together". `--config` has to be read before the parser exists, because the file supplies the defaults the parser resolves against, so it is picked off `os.Args` the same way kong would read it (both `--config PATH` and `--config=PATH`, nothing after `--`). Config problems carry a `*config.Error`, which `main` prints on its own rather than under a usage dump for a command that was typed correctly: ``` Error: config file ~/.config/things-cli/config.toml: unknown key "verbose" (valid keys: json, color, db, no_verify, strict_tags) Error: config file ~/.config/things-cli/config.toml: invalid TOML: line 3, column 8: incomplete number Error: config file ~/.config/things-cli/config.toml: key "color" must be one of auto, always, never, got "pink" ``` ## Adding a key later `config.Keys` in `internal/config/config.go` is the single registry. One entry — the TOML name, the flag name it seeds, the built-in default, and the template comment — feeds the resolver, `config show`, and the `config init` template at once. So a new key is: the flag itself (wherever it lives), one `config.Keys` entry, and the docs tables in `README.md` and `docs/_tabs/commands.md`. `TestConfigKeysMatchFlags` walks the kong model and fails if a key names a flag that does not exist or disagrees with kong about its default, so the registry cannot drift away from the CLI silently. The `--yes` flag from #158 is one registry entry plus its docs-table rows once it lands. ## How tested `make test` (`go test -race ./...`) and `make lint` both clean. New tests cover: default path from `$HOME` and `$XDG_CONFIG_HOME`; `--config` > env > default precedence; missing file; every key round-tripping; the hyphenated alias; unknown key, malformed TOML, wrong type, table value, bad enum value, duplicate spelling, and a `db` path that does not exist; the template being fully commented out and reloading as empty. At the CLI level: the six cases of the `strict_tags`/`create_tags` interaction (either from the file, either flag beating the other's config value, both false, one true one false) and both true being rejected at load; config values reaching global flags and the per-command `--strict-tags`; a flag beating the config file; a flag beating a stale `db` entry; an empty `db` staying unset; env var selection; `config path` / `show` / `init` in both plain and JSON form; `init` refusing to overwrite and `--force` overwriting; and the parse error staying unwrappable to `*config.Error`. The test harness in `run_test.go` now builds its parser from the same `parserOptions` function `main` uses, so a kong option cannot be added to one and forgotten in the other. It also points `HOME`, `XDG_CONFIG_HOME`, and `THINGS_CLI_CONFIG` at a temp directory, so tests never read or write a real config file. ## Notes - Uses `github.com/pelletier/go-toml/v2` v2.2.4 with a hand-written resolver rather than `alecthomas/kong-toml`. kong-toml keys off the hyphenated flag name (`no-verify`), and #159 specifies snake_case; it also reports unknown keys through kong's validation, which prints a usage dump. The resolver is ~30 lines and gives the key spelling and the error shape the issue asks for. kong-toml also still pins go-toml v1, which is deprecated. - A config file that fails to load stops every command, including `things --help` and `things config show`. The error names the file, the key, and the problem, so the file can be edited or removed; making `config show` able to report on a file it could not load would need a second parse pass, which did not seem worth it. - An explicit `--config` path that does not exist is silently ignored, per "missing file is not an error" in #159. `things config path` reports `(not found)`, which is how a typo is diagnosed. Erroring instead would break `things --config /new/path.toml config init`. - Rebased onto main after #150 and #157 merged. `jsonRequested` now takes the default the config file establishes as its starting point, so a parse failure under `json = true` is still rendered as JSON. - `internal/skill/SKILL.md` gained a section telling agents that a config file can flip `json` and `no_verify`, and to pass the flags they depend on explicitly. Closes #159
This was referenced Sep 5, 2026
ryanlewis
added a commit
that referenced
this pull request
Sep 5, 2026
…oting (#168) ## What changed Six small fixes to code already on main, all found by review passes on #162 and #163. **`--json` parse failures (#157).** - `renderError` used a default `json.Encoder`, which escapes `<`, `>` and `&` into `\u00xx`. Every kong parse error carries them, so the most common `--json` failure came out as `expected \"<task>\"` — line noise, in the field whose doc says it reads as the plain-text error does. `SetEscapeHTML(false)`. - `jsonRequested` recognised only bare `--json` and `--json=true|false`, so `things --json=1 …` and `things --json=yes …` fell through to kong's usage block on stdout: exactly what the function exists to prevent. Values now go through `kongBool`, which mirrors kong's bool mapper — `true/1/yes`, `false/0/no`, case-insensitive. `strconv.ParseBool` was the wrong set in both directions: it accepts `T`, which kong rejects, and rejects `yes`, which kong accepts. - It also missed clustered shorts, so `things -jv --bogus` did the same thing. It now walks a cluster and stops at the first short that takes a value, because that one swallows the rest of the cluster as its value — `-pj` is `--project=j`, not `--json`. - The JSON branch exited 1 where kong's plain-text path exits 80, so the same failure returned a different code depending on the flag. `parseExitCode` now reads kong's own `ExitCoder`, which also gets the cases right where kong raises a parse error with no code of its own and exits 1 rather than 80 — this CLI installs a config resolver, so that path is reachable. - `SKILL.md` and the `jsonErrorPayload` doc both told agents to parse stdout whether or not the command succeeded. The write commands (`add`, `edit`, `complete`, `cancel`, `log`, `open`) print nothing on success, so an agent following that tried to parse an empty string. **Tag hint quoting (#150).** `tagAddHint` builds a copy-pastable `things tag add …` suggestion, but quoted a handful of characters with `strconv.Quote`, which is Go syntax rather than shell. `things tag add R&D` backgrounds a command and runs `D`; `a;b` leaves an unquoted `;`; `"a$HOME"` expands. It now uses POSIX single-quoting driven by a character allow-list, so a character the list forgot is merely quoted unnecessarily rather than left live. A name starting with `-` also gets a `--` separator: quoting stops the shell splitting it but not kong reading it as a flag. ## Why the two hand-maintained lists have tests that derive them `boolShorts` and `kongBool` both restate something kong owns, which is exactly the kind of thing that rots silently. - `TestBoolShortsMatchesGrammar` walks the real kong model and fails if a boolean short exists that `boolShorts` does not list, or if a letter in `boolShorts` is value-taking anywhere. (`-f` is deliberately absent: boolean on `config init`, a value flag on `import`. Treating an ambiguous letter as value-taking only costs a fallback to kong's plain-text usage; the reverse would misread a filename.) - `TestKongBoolMatchesKong` runs each candidate value through an actual `parser.Parse` and asserts `kongBool` agrees on both acceptance and result. ## How tested `make test` (race) and `make lint` clean. New and extended tests: the `jsonRequested` table gains cluster cases (`-jv`, `-vj`, `-pj`, `-fj`), `yes`/`no` casing, config-default interaction, and values kong rejects; `TestRenderErrorDoesNotEscapeHTML`; the two derivation tests above; and `tags_test.go` cases for `&`, `$`, `'`, empty, and a leading dash. Checked against the built binary: `things --json show` → `{"error":"error","message":"expected \"<task>\""}` on stdout, exit 80, empty stderr. `things -jv --bogus` and `things --json=1 --bogus` likewise. `things -pj --bogus` correctly keeps kong's usage block, since `-pj` is not a JSON request. `things --json=T lst` also keeps the plain path, matching kong's rejection of `T`. Closes #164
ryanlewis
added a commit
that referenced
this pull request
Sep 5, 2026
…st (#176) Tidy of the bundled agent skill before v0.7.0. Six PRs edited `internal/skill/SKILL.md` piecemeal since v0.6.0 (#150, #151/#166, #157/#168, #160, #169, #170/#173, #172) and it had drifted into a pile of overlapping notes. ## Audited against the CLI Built the binary and checked every command and flag the skill mentions against `./things --help` and each subcommand's `--help`, in both directions. Both now come back clean: no flag in the help is missing from the skill, and no flag named in the skill is absent from the CLI. ## What moved Reordered so the first screen is what an agent needs before it acts: | Before | After | | --- | --- | | Safety → Output → Config → Commands → Repeating → Confirming → Tags → `--agent` → Refs → Values → Flows → Completions → Tips | Safety → **Referring to an item** → Output and `--json` → **Writes: what Things refuses or drops** (4 numbered rules) → Config → Command reference → `--agent` → Values → Flows → Completions | "Referring to an item" moved up from near the bottom — how refs and UUIDs work is prerequisite to almost everything else, and the index-cache trap (any `list` or `search` overwrites it, *including one the agent runs itself*) was buried. The four scattered write-refusal topics are now one section of numbered rules that the rest of the document cross-references by number instead of restating. ## What was cut - **Tips** — every bullet restated an earlier section. Kept its one unique line, about when to reach for `open`. - `--yes` and the project confirmation were stated in **four** places, `--json` in **three**, repeating behaviour in **four**. Each is now in one place. - Comments in the command block that only restated `--help`. Net **14% shorter** (19,107 → ~16,500 chars) while covering more surface. ## What was stale or missing - `open` was listed as a write that "modifies the user's real data". It reveals an item in the app and pulls focus; it writes nothing. - **Absent entirely**: the `skill` subcommands (`list`/`show`/`install`/`uninstall`), `version`, `--db`, `--config`, `$THINGS_CLI_CONFIG`, `--no-hints`. - `--when ""` / `--deadline ""` clear a value on `edit`/`project edit` (and only there) — undocumented. - `tag add` prints its result on success, so the blanket "write commands print nothing" was wrong for it; it is also covered by the `--no-verify` read-back, which rule 1 did not mention. - "Things3 must be running" applied only to `--create-tags`, but `tag add` uses the same AppleScript path. ## One code change `internal/output/agent.go` — a self-contradiction in the `--agent` brief for a **repeating project**, from my #172: `closingOut` guarded the to-do branch on `!t.Repeating` but not the project branch, so the brief offered `things complete <uuid> --yes` / `cancel --yes` directly above a note saying there were none — commands `checkRepeating` refuses anyway. Guarded both branches, with a regression test (`TestPrintAgentBriefRepeatingProject`; there was no test for a repeating project brief). This is outside a docs-only brief, and I flagged it rather than slipping it in: it is here because the skill now documents the corrected behaviour, so doc and code had to move together. The alternative was to document the bug as if it were intended. Happy to split it out if preferred. ## How tested `make test` (`go test -race ./...`) and `make lint` (0 issues) pass; `gofmt` clean. `internal/skill/skill_test.go` asserts the frontmatter and a set of command references, all still present. Verified the rendered install output via `things skill show claude`. README's Agent skill section was checked and needs no change — its subcommand table, flag table and the three default install paths all match `internal/skill/{claude,codex,pi}.go`.
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.
What changed
Two ways to create a Things tag from the CLI, where before there were none.
things tag add <name>...creates tags on their own:Names that already exist are skipped rather than duplicated, matched case-insensitively as Things matches them, and duplicate arguments are collapsed the same way.
--jsonreports{"created": [...], "skipped": [...]}. The tag list is read back afterwards to confirm the creation landed;--no-verifyskips that, as it does forcomplete/cancel.--create-tagsonadd,project add,edit,project editandimportcreates the missing tags before the write, so the write applies all of them:It sits alongside the existing
--strict-tags. The two ask for opposite things, so kong rejects them together (--strict-tags and --create-tags can't be used together). With--create-tagsset, an unreadable database is a hard failure rather than the usual warn-and-continue — without it the CLI cannot tell which tags are missing.Why
The Things URL scheme applies only tags that already exist and drops the rest silently. #141 made that visible (warning plus
--strict-tags), but left the user to switch to the app to fix it. AppleScript can create tags, so the CLI now does — before the URL-scheme write, so Things has the tag by the time it applies it.Tag names come from the command line, so
internal/thingsgainedappleScriptString, which renders a name as an AppleScript string literal with backslash, quote, newline, carriage return and tab escaped. Every other script in that file interpolates a UUID read out of the database; this is the first one that interpolates user input.Closes #144
How tested
make test(go test -race ./...) andmake lintare green. New tests:internal/things: the exact script textCreateTagproduces, the escaping table (quotes, backslashes, control characters, UTF-8), and a name that tries to close the string literal early.cmd/things: creation of only the missing tags, case-insensitive and duplicate skipping, blank-name rejection, JSON output, read-back failure and--no-verify, creation failure naming the tag;--create-tagsordering (AppleScript create, then thethings:///addwrite) on all five commands, a creation failure blocking the write, and the--strict-tags/--create-tagsconflict against a real kong parser.Every write goes through the mocked
execCommandseam — no realosascriptand nothings:///URLs against the app. The tests assert the exact script text rather than just that something ran.Docs updated:
README.md,docs/_tabs/commands.md, andinternal/skill/SKILL.md(the flag lists, the "tags must already exist" section, andtag addin the safety list of writes).Notes
things tag add "a,b"is allowed through. Things itself permits a comma in a tag name, but--tags/--add-tagssplit on commas, so such a tag can't be applied from this CLI afterwards. Left as a pass-through rather than a guard.ImportCmdis touched only for the flag embed and the oneverifyTagscall; theStrictTagsembed struct is renamedTagFlagsnow that it carries two flags.