Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,54 @@
# Changelog

## 2.1.0

Writes could report success for changes that never happened. 2.0.4 fixed one
command; this finishes the job, verifies every write against the database, adds
re-parenting, and closes a credential leak found on the way.

- **`complete`, `move` and `tag` still no-opped on projects.** 2.0.4 routed
`update` to `things:///update-project` but left the other three building
`things:///update`, which Things ignores for a project uuid. `open` still
exits 0, so `thingsctl complete <project>` printed `✓ Completed` while the row
stayed `status = 0`. All write commands now route by entity type, and headings
are refused outright rather than dispatched into a command that cannot apply.
- **Success is now verified against the database, not assumed.** `open` exiting
0 only means macOS handed the URL to Things. Writes poll the row until the
change is visible and report a clear failure otherwise. This is what turned
the routing bug from an error into a lie. Timeout is overridable with
`THINGSCTL_VERIFY_TIMEOUT_MS` (the URL scheme can cold-launch Things, which
takes longer than the 3s default); the MCP server defaults to 1200ms because
the wait is synchronous and blocks its event loop. Bulk `complete` now shares
one budget instead of spending the full timeout on every id.
- **Security: the auth token leaked into error output.** macOS `open` echoes the
whole failing URL, `auth-token` included, and that text was spliced into
`ThingsUrlError` — which the CLI prints to stderr and the MCP server returns
as tool output, i.e. into a model transcript. The token is now redacted before
it can reach any sink.
- **Security: `%` in an id matched every task.** `resolveTaskId` interpolated
the id straight into a `LIKE` pattern, so `complete '%' --yes-first` resolved
to an arbitrary row. Wildcards are escaped now. This mattered more once
`update` could relocate work rather than only complete it.
- **`--completed false` completed the task instead of reopening it.** The CLI
parser yields the string `'false'`, which is truthy, so the flag sent the
opposite of what it says. Booleans are normalised once, up front.
- **Added: move a to-do or project to a different parent.** Previously
impossible through the tool. `update --list` / `--list-id` moves a to-do into
a project or area, `update --area` / `--area-id` moves a project into an area,
and the move is verified against the row rather than against "something
changed". Passing the wrong pair for the type is refused with an explanation.
- `tag` now tells the truth when a tag does not exist. Things silently drops an
`add-tags` naming a tag it has never seen; that used to print a checkmark.
- `things_move`'s description said "moving it to...", which read as a re-parent
when it only ever rescheduled. Fixed, along with its success string, which
said "Moved" while its failure string said "did not reschedule".
- `thingsctl update --help` was missing every flag added here; the CLI keeps a
hand-curated flag allowlist, so a new option has to be registered in four
places. Documented; consolidating that is left as follow-up.

New: `src/lib/verify.js`, `url.buildUpdateProjectUrl` (from 2.0.4),
`db.openFresh`, `exec.redactToken`. 129 tests, up from 79 at 2.0.3.

## 2.0.4

Fix `update` silently no-opping on projects. Things applies the `update`
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,25 @@ thingsctl add "Trip prep" --checklist "Passport,Tickets,Charger"
thingsctl add "Tax filing" --when 2027-04-15 --deadline 2027-04-15 --tags Important

thingsctl update 7Ae --title "New title" --append-notes "context"
thingsctl complete 7Ae # Single
thingsctl complete 7Ae # Single (to-do or project)
thingsctl complete 7Ae 17j 9pU # Bulk
thingsctl move 7Ae --to "next week"
thingsctl move 7Ae --to "next week" # RESCHEDULES; does not change project/area
thingsctl tag 7Ae --add Urgent
```

### Moving between projects and areas

`move` reschedules. To change what a to-do or project *belongs to*, use `update`.
Things exposes different parameters for the two, and mixing them up is refused
rather than silently dropped:

```bash
thingsctl update 7Ae --list "Berlin Trip" # to-do → project or area, by title
thingsctl update 7Ae --list-id Xm55Bsr1Wmk # to-do → project or area, by uuid
thingsctl update p01 --area "Travel" # project → area, by title
thingsctl update p01 --area-id 7U6P28t2BfE # project → area, by uuid
```

### Workflows

```bash
Expand Down
5 changes: 5 additions & 0 deletions bin/thingsctl-mcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
// Force NO_COLOR for MCP responses — clients render the text content as-is.
process.env.NO_COLOR = '1';

// Write verification sleeps synchronously, which blocks this server's event
// loop. The CLI can afford a 3s worst case; a long-lived stdio server cannot,
// so default it lower here. THINGSCTL_VERIFY_TIMEOUT_MS still wins if set.
if (!process.env.THINGSCTL_VERIFY_TIMEOUT_MS) process.env.THINGSCTL_VERIFY_TIMEOUT_MS = '1200';

const { start } = require('../src/mcp/server');

start().catch((e) => {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thingsctl",
"version": "2.0.4",
"version": "2.1.0",
"description": "A full-featured command-line interface and MCP server for Things 3 on macOS.",
"main": "src/cli.js",
"type": "commonjs",
Expand Down
1 change: 1 addition & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ function dispatch(parsed) {
title: o.title, notes: o.notes,
'append-notes': o['append-notes'], 'prepend-notes': o['prepend-notes'],
when: o.when, deadline: o.deadline, 'add-tags': o['add-tags'],
list: o.list, 'list-id': o['list-id'], area: o.area, 'area-id': o['area-id'],
completed: o.completed, canceled: o.canceled,
'yes-first': opts['yes-first'],
});
Expand Down
38 changes: 32 additions & 6 deletions src/commands/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

const db = require('../lib/db');
const { resolveMany } = require('../lib/uuid');
const { buildUpdateUrl } = require('../lib/url');
const { buildUpdateUrl, buildUpdateProjectUrl } = require('../lib/url');
const { openUrl } = require('../lib/exec');
const { getToken } = require('../lib/token');
const { colors } = require('../lib/format');
const { STATUS } = require('../lib/constants');
const { STATUS, TYPE } = require('../lib/constants');
const { waitForWrite, notApplied, DEFAULT_TIMEOUT_MS } = require('../lib/verify');
const queries = require('../lib/queries');

function run(ids, opts = {}) {
const list = Array.isArray(ids) ? ids : [ids];
const database = db.open();
const { resolved, errors } = resolveMany(database, list, { yesFirst: opts['yes-first'] });
const out = [];
// One slow id should not make the whole batch slow. If Things did not take
// write #1 it is not taking #7 either, so drop to a short probe after the
// first timeout instead of burning the full budget per item.
let budgetMs = DEFAULT_TIMEOUT_MS;

for (const { error, input } of errors) {
out.push(`${colors.red('✗')} ${error.code === 'E_AMBIGUOUS' ? error.message : `Not found: ${input}`}`);
Expand All @@ -25,12 +30,33 @@ function run(ids, opts = {}) {
out.push(`${colors.dim('Already completed: ' + full.title)}`);
continue;
}
if (task.type === TYPE.HEADING) {
out.push(`${colors.red('✗')} Cannot complete a heading: ${task.title}`);
continue;
}

// Projects are only reachable through `update-project`. Sending them to
// `update` is a silent no-op — the bug this dispatch exists to prevent.
const isProject = task.type === TYPE.PROJECT;
const params = { id: task.uuid, completed: 'true', 'auth-token': getToken() };
const url = isProject ? buildUpdateProjectUrl(params) : buildUpdateUrl(params);
const label = isProject ? 'project' : 'task';

try {
openUrl(buildUpdateUrl({ id: task.uuid, completed: 'true', 'auth-token': getToken() }));
out.push(`${colors.green('✓')} Completed: ${task.title}`);
openUrl(url);
} catch (e) {
out.push(`${colors.red('✗')} Failed: ${task.title} (${e.message})`);
// e.message carries the redacted url; keep it out of per-item output anyway.
out.push(`${colors.red('✗')} Failed: ${task.title} (could not reach Things)`);
continue;
}

const { ok } = waitForWrite(task.uuid, (r) => r.status === STATUS.COMPLETED, { timeoutMs: budgetMs });
if (!ok) budgetMs = 250;
out.push(
ok
? `${colors.green('✓')} Completed ${label}: ${task.title}`
: notApplied(`complete the ${label}`, task.title)
);
}
return list.length === 1 ? out[0] : out;
}
Expand All @@ -39,7 +65,7 @@ module.exports = {
run,
mcp: {
name: 'things_complete',
description: 'Mark one or more tasks as complete.',
description: 'Mark one or more tasks or projects as complete. Verified against the database before reporting success.',
inputSchema: {
type: 'object',
properties: {
Expand Down
26 changes: 22 additions & 4 deletions src/commands/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,43 @@

const db = require('../lib/db');
const { resolveTaskId } = require('../lib/uuid');
const { buildUpdateUrl } = require('../lib/url');
const { buildUpdateUrl, buildUpdateProjectUrl } = require('../lib/url');
const { openUrl } = require('../lib/exec');
const { getToken } = require('../lib/token');
const { colors } = require('../lib/format');
const { TYPE } = require('../lib/constants');
const { waitForWrite, snapshot, modifiedSince, notApplied } = require('../lib/verify');

// NOTE: this command RESCHEDULES. It does not change which project or area a
// task belongs to — that is `update --list` / `update --area`. The name is
// historical; the description says so plainly so callers stop guessing.
function run(id, opts = {}) {
if (!id) throw new Error('Task id required');
if (!opts.to) throw new Error('--to option required');
if (opts.to === 'inbox') throw new Error('Moving to inbox is not supported via the Things URL scheme');
const database = db.open();
const ref = resolveTaskId(database, id, { yesFirst: opts['yes-first'] });
openUrl(buildUpdateUrl({ id: ref.uuid, when: opts.to, 'auth-token': getToken() }));
return `Moved "${ref.title}" to ${opts.to}`;
if (ref.type === TYPE.HEADING) {
throw new Error(`"${ref.title}" is a heading. Headings cannot be scheduled.`);
}

const params = { id: ref.uuid, when: opts.to, 'auth-token': getToken() };
const before = snapshot(ref.uuid);
openUrl(ref.type === TYPE.PROJECT ? buildUpdateProjectUrl(params) : buildUpdateUrl(params));

const { ok } = waitForWrite(ref.uuid, modifiedSince(before));
if (!ok) return notApplied('reschedule', ref.title);
return `Rescheduled "${ref.title}" to ${opts.to}`;
}

module.exports = {
run,
mcp: {
name: 'things_move',
description: 'Reschedule a task by moving it to today/anytime/someday/evening or a specific date.',
description:
'RESCHEDULE a to-do or project to today/anytime/someday/evening or a specific date. ' +
'This does NOT change which project or area it belongs to — use things_update with ' +
'list/list-id (to-dos) or area/area-id (projects) for that.',
inputSchema: {
type: 'object',
properties: {
Expand Down
23 changes: 19 additions & 4 deletions src/commands/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@

const db = require('../lib/db');
const { resolveTaskId } = require('../lib/uuid');
const { buildUpdateUrl } = require('../lib/url');
const { buildUpdateUrl, buildUpdateProjectUrl } = require('../lib/url');
const { openUrl } = require('../lib/exec');
const { getToken } = require('../lib/token');
const { colors } = require('../lib/format');
const { TYPE } = require('../lib/constants');
const { waitForWrite, snapshot, modifiedSince, notApplied } = require('../lib/verify');

function run(id, opts = {}) {
if (!id) throw new Error('Task id required');
const database = db.open();
const ref = resolveTaskId(database, id, { yesFirst: opts['yes-first'] });

if (opts.add) {
openUrl(buildUpdateUrl({ id: ref.uuid, 'add-tags': opts.add, 'auth-token': getToken() }));
return `Added tag "${opts.add}" to "${ref.title}"`;
if (ref.type === TYPE.HEADING) {
throw new Error(`"${ref.title}" is a heading. Headings cannot be tagged.`);
}
const params = { id: ref.uuid, 'add-tags': opts.add, 'auth-token': getToken() };
// Same routing rule as every other write: Things ignores `update` on a
// project, so tagging one through it was a silent no-op reporting success.
const isProject = ref.type === TYPE.PROJECT;
const before = snapshot(ref.uuid);
openUrl(isProject ? buildUpdateProjectUrl(params) : buildUpdateUrl(params));

const { ok } = waitForWrite(ref.uuid, modifiedSince(before));
if (!ok) return notApplied('tag', ref.title);
const label = isProject ? 'project ' : '';
return `${colors.green('✓')} Added tag "${opts.add}" to ${label}"${ref.title}"`;
}
if (opts.remove) {
throw new Error('Removing tags is not supported by the Things URL scheme (it would replace all tags).');
Expand All @@ -25,7 +40,7 @@ module.exports = {
run,
mcp: {
name: 'things_tag',
description: 'Add a tag to a task. Tags must already exist in Things.',
description: 'Add a tag to a to-do or project. Tags must already exist in Things. Verified against the database before reporting success.',
inputSchema: {
type: 'object',
properties: { id: { type: 'string' }, add: { type: 'string' } },
Expand Down
Loading
Loading