Repository navigation
fix(db): resolve a shared title to the to-do, not the repeating template - #163
Merged
Merged
Conversation
A repeating to-do is stored twice: the template carrying the recurrence rule, and the instance Things generated from it, sharing its title. GetTask's exact-title path took the first row with LIMIT 1, so `things complete "Water plants"` could land on the template and hit the repeating-write refusal from #143 while an actionable instance sat next to it. Both title lookups now order templates last, via templatesLastOrder: "<recurrence column> IS NOT NULL ASC, t.index ASC". The exact-title path gets a deterministic single result; FindTasksByTitle, which feeds the disambiguation picker, offers the instance first. Ordering rather than filtering keeps a template reachable when it is the only match, so `things show` on a template-only title still works. On a schema with no recurrence column the expression is constant and the index order is unchanged. Closes #156
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
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
Both title lookups in
internal/dbnow sort repeating templates last, through a sharedtemplatesLastOrder():GetTask's exact-title path gains that ordering ahead of itsLIMIT 1, so the single row it returns is the generated to-do.FindTasksByTitle, which feeds the disambiguation picker, keeps returning both but offers the instance first.Why
A repeating to-do exists twice in the database: the template carrying the recurrence rule, and the instance Things generated from it, sharing its title. The exact-title path took whichever row came first under
LIMIT 1, sothings complete "Water plants"could land on the template and hit the repeating-write refusal from #143 while a perfectly completable instance sat next to it.I ordered rather than raised an
AmbiguousTaskError, which was the other option on the table. Three reasons:--jsonconsumers would have to handle a new failure for a case that has an obvious right answer.things show "Pay rent"on a template with no live instance — a real state, between generated occurrences — would report "not found". With ordering it is only deprioritised, so it still resolves when nothing else matches.To reach a template deliberately, use its UUID or the numeric index from
things repeating. That is now documented in bothREADME.mdandinternal/skill/SKILL.md.SearchTasksis deliberately untouched: search is a listing, and a user searching for "water" should see both rows in index order rather than have the CLI express a preference.How tested
make test(race) andmake lintclean.New tests in
internal/db/tasks_test.go, seeding a template (recurrence rule,start=2, nostartDate) and an instance (start=1, scheduled, no rule) with the same title — and giving the template the lower"index", so plain index order alone would still pick it:TestGetTaskExactTitlePrefersInstance— the exact-title path returns the instance.TestGetTaskExactTitleTemplateOnly— a template with no instance still resolves, proving this orders rather than filters.TestFindTasksByTitleOrdersTemplatesLast— the LIKE path returns both, instance first.TestGetTaskAmbiguousListsInstanceFirst— the candidates inAmbiguousTaskErrorcarry the same order, so the picker offers the instance as option 1.TestTitleLookupsWithoutRecurrenceColumn— with the column dropped the ordering expression is constant, and lookups fall back to index order instead of failing.And
TestRunShowPrefersGeneratedTodoOverTemplateincmd/things, drivingthings --json show "Water plants"end to end.I checked the tests are not vacuous by reverting the ordering to plain
t."index" ASC— the three ordering tests failed, the template-only and no-column tests stayed green.Closes #156