feat(extensions): run extensions - #523
Merged
scottlovegrove merged 2 commits intoSep 11, 2026
Merged
Conversation
This was referenced Sep 10, 2026
doistbot
reviewed
Sep 10, 2026
doistbot
left a comment
Member
There was a problem hiding this comment.
This slice wires up extension execution: arguments pass through verbatim, the host shares the child's stdio streams, exit codes propagate, and the environment gets the TD_* contract with no credentials injected. Security-wise this looks solid — argument-array spawning with no shell interpolation on POSIX, and the Windows sh -c fallback keeps user input as positional parameters, so nothing user-controlled can escape into a command.
Few things worth tightening:
- The Windows
.cmd/.batbranch can't work:spawn()withoutshell: truecan't launch these viaCreateProcess, so valid extensions resolved by discovery will always fail withEXTENSION_NOT_EXECUTABLE. Run them throughcmd.exe /d /s /cinstead. buildExtensionEnvleaks an inheritedTD_USERinto nestedtdinvocations when no--useris given — the existing test only passes because it stubs the variable toundefined. Delete${prefix}_USERwhen no user is supplied, matching theextraloop's behavior.- Node-shebang replacement drops the interpreter's options, so directives like
#!/usr/bin/node --conditions=developmentbreak. Parse the Node directive (includingenv -Sforms) and prepend its options before the script path.
I also included a few optional follow-up notes in the details below.
Optional follow-up notes (7)
src/lib/extensions/dispatch.test.ts:136:
expect(env.TD_EXTENSION).toBe(process.env.TD_EXTENSION)can never fail:buildExtensionEnvspreadsprocess.env, so the two are identical by construction. If the intent is "the TDC prefix doesn't leak TD_* variables", assertexpect(env.TD_EXTENSION).toBeUndefined().src/lib/extensions/dispatch.ts:91:
ExtensionEnvOptionsre-declaresuserandextraon top of the existingDispatchOptionsin./types.ts, which already definesuserandenvwith the same "merged last" child-environment semantics. ComposeDispatchOptions(or reuse its fields) and keep one name for the child env override — the currentenv/extrasplit is an easy way for the dispatch and manager layers to drift.src/lib/extensions/dispatch.test.ts:112: Hardcoded
'TODOIST_API_TOKEN'duplicates the canonicalTOKEN_ENV_VARfrom../auth-store.js(also re-exported by../auth.js). Import that constant so the pass-through test stays in sync if the token env var name changes.src/lib/extensions/dispatch.test.ts:41: This test asserts POSIX-only behavior but has no platform guard, so running
npm teston Windows fails atexpect(plan.command).toBe(join(dir, 'td-shell'))because the Windows branch routes throughsh. Skip it on Windows (e.g.,it.skipIf(process.platform === 'win32')) or branch the expectation.src/lib/extensions/dispatch.ts:49:
buildSpawnPlanstats the executable here viaisExecutable, thenreadShebangopens the same path again on line 66. SincereadShebangalready has a file handle, it can callhandle.stat()there to answer both "is this a runnable file" and "what is its shebang" in a single open. That removes the duplicate I/O and closes the TOCTOU window where the file changes between the two checks.src/lib/extensions/dispatch.test.ts:22:
buildSpawnPlan's Windows branches have no coverage:.exe/.cmd/.batfiles that should run directly, and every other script that should becomesh -c '"$0" "$@"'. Thatshquoting is what preserves argument passthrough on Windows, and CI runs only on Linux, so a regression there would pass silently. Add a platform-forced test (e.g., temporarily redefineprocess.platformaswin32and restore it) covering both branches.src/lib/extensions/dispatch.test.ts:195: The signal branch in dispatchExtension is untested: a child killed by a signal must yield 128+signal (e.g. 130 for SIGINT), and a regression that resolves with
code ?? 0would make the host silently report success after an extension is killed. A fixture that runsprocess.kill(process.pid, 'SIGKILL')(POSIX) would pin this. The three--exit-codecases at lines 196-198 only cover the normal-close path.
scottlovegrove
added this pull request to stack #528
September 10, 2026 16:03
scottlovegrove
force-pushed
the
feat/extensions-3-dispatch
branch
from
September 10, 2026 16:11
e1dd57e to
855d15e
Compare
scottlovegrove
force-pushed
the
feat/extensions-3-dispatch
branch
from
September 10, 2026 16:25
855d15e to
f4a077c
Compare
scottlovegrove
force-pushed
the
feat/extensions-3-dispatch
branch
from
September 10, 2026 16:51
f4a077c to
384d258
Compare
scottlovegrove
force-pushed
the
feat/extensions-3-dispatch
branch
from
September 10, 2026 16:56
384d258 to
82671ca
Compare
scottlovegrove
removed this pull request from stack #528
September 10, 2026 16:57
scottlovegrove
added this pull request to stack #529
September 10, 2026 16:58
scottlovegrove
removed this pull request from stack #529
September 10, 2026 16:59
scottlovegrove
added this pull request to stack #530
September 10, 2026 16:59
Contributor
|
✅ |
The execution half of the contract: arguments reach the extension exactly as the user typed them, the three standard streams are the host's own, and the host exits with whatever the extension exited with. Node-shebang scripts are launched with the host's own Node, which makes them work on Windows and pins them to the Node version the CLI already requires. Other scripts run directly on POSIX and through sh on Windows. The environment adds the documented TD_* contract. No credential is ever injected: an extension that needs a token runs `td auth token view`.
Review feedback on the dispatch slice: - run a .cmd or .bat through the command interpreter. A batch file is not a program, so spawning it directly fails on every supported Node version, which would have made those extensions unrunnable - keep the options a node shebang asked for, including the env -S form. A script that needs --conditions to resolve its imports was losing it - clear an inherited user variable when no --user was given, so a nested call does not keep acting as the account the outer call chose - ask for the file's type and its shebang through one open, which also removes the window in which the file could change between two checks - the child environment override is now the same field name the manager already uses Adds coverage for the Windows branches by declaring the platform, for node shebang forms, and for a child killed by a signal.
scottlovegrove
force-pushed
the
feat/extensions-3-dispatch
branch
from
September 11, 2026 09:44
82671ca to
5482db5
Compare
scottlovegrove
added a commit
that referenced
this pull request
Sep 11, 2026
Slice 1 of 7. Replaces #520, which was one 3.7k-line PR; this is the same work split along doistbot's suggested plan, with its review feedback already applied. The vocabulary every later slice builds on: the types describing an installed extension, the naming rules derived from the host binary name (`td` gives `td-<name>` directories, `td-extension.json` and `.td-manifest.json`), one parser shared by install sources and by git remotes read back off disk, manifest reading and writing including the `package.json` fallback for Node extensions, and per-extension state kept outside the extension directory so that deleting that directory by hand is still a clean uninstall. Nothing is wired up yet. See [the spec](https://github.com/Doist/todoist-cli/blob/main/docs/specs/extensions.md) for where this is going. **Stack:** #521 core · #522 discovery · #523 dispatch · #524 tools · #525 install · #526 upgrade · #527 manager
scottlovegrove
added a commit
that referenced
this pull request
Sep 11, 2026
Slice 2 of 7, on top of slice 1. Discovery walks the extensions directory and works out what each entry is: a symlink or path file is a local install, a `.git` directory is a clone, anything else is a release binary. It runs on every invocation of the CLI, including the common case of no extensions at all, so it costs one `readdir` plus a couple of small file reads and never spawns a process or touches the network. The git remote is read out of `.git/config` rather than by asking git. Also adds the test fixture helpers, which build real extension directories in a temporary location so later slices can install and run something genuine rather than a mock. **Stack:** #521 core · #522 discovery · #523 dispatch · #524 tools · #525 install · #526 upgrade · #527 manager
scottlovegrove
added a commit
that referenced
this pull request
Sep 11, 2026
Slice 4 of 7, on top of slice 3. The outside world an install has to talk to, plus the one operation that needs no installer. - A subprocess wrapper that captures a bounded tail of output, since npm runs extension lifecycle scripts that could otherwise print without end. - Git operations, with working-tree state reported as clean, dirty or unknown, so that "could not tell" is never mistaken for "safe to delete". - npm dependency installation, run without the CLI's own credentials, invoked through the command interpreter on Windows because a `.cmd` shim cannot be spawned directly on supported Node versions, and without writing a lockfile into a clone that has none. - The GitHub client: releases, asset downloads and checksum verification. - Removal, which deletes only the link for a local install and refuses a clone with uncommitted or unreadable state unless forced. **Stack:** #521 core · #522 discovery · #523 dispatch · #524 tools · #525 install · #526 upgrade · #527 manager
scottlovegrove
added a commit
that referenced
this pull request
Sep 11, 2026
Slice 5 of 7, on top of slice 4. Installs from a release binary, a git clone, or a local directory. Everything is assembled in a staging directory and moved into place only once complete, with the previous install moved aside rather than deleted, so a failure part-way through leaves the working extension recoverable. The trust warning is printed before anything is downloaded, cloned or executed. Release assets are matched by platform and architecture, verified against the release's checksums when it publishes any, and recorded in a manifest that carries the author's description and version requirement. **Stack:** #521 core · #522 discovery · #523 dispatch · #524 tools · #525 install · #526 upgrade · #527 manager
scottlovegrove
added a commit
that referenced
this pull request
Sep 11, 2026
Slice 6 of 7, on top of slice 5. Clones fast-forward, release binaries are re-downloaded when the tag moves, and local installs are left alone because the user's own directory is already the source of truth. Pins are honoured unless forced, and a forced upgrade clears the pin it just moved past rather than leaving a stale one to skip every later upgrade. Dependencies are reinstalled only when `package.json` or the lockfile changed. Upgrading many extensions bounds how many talk to GitHub at once, and warns about trust once for the whole run rather than once per extension. **Stack:** #521 core · #522 discovery · #523 dispatch · #524 tools · #525 install · #526 upgrade · #527 manager
scottlovegrove
added a commit
that referenced
this pull request
Sep 11, 2026
Slice 7 of 7, on top of slice 6. This completes the library half of phase 1. Ties the slices together behind `createExtensionManager`, which is the only thing a host CLI needs to call. Includes the version-range check behind an extension's `requires` field. A range the running CLI does not satisfy is a warning rather than a refusal: upgrading the CLI should not silently break an extension that still works. Also records the subsystem in `CODEBASE.md`, including why nothing in the directory imports from the rest of the repo. Next, in a separate PR: the `td extension` command group, the `src/index.ts` wiring, the command-token lookup change, `--user` scoping, doctor checks and `SKILL_CONTENT`. **Stack:** #521 core · #522 discovery · #523 dispatch · #524 tools · #525 install · #526 upgrade · #527 manager
Contributor
|
🎉 This PR is included in version 5.4.0-next.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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.
Slice 3 of 7, on top of slice 2.
The execution half of the contract: arguments reach the extension exactly as the user typed them, the three standard streams are the host's own, and the host exits with whatever the extension exited with.
Node-shebang scripts are launched with the host's own Node, which makes them work on Windows and pins them to the Node version the CLI already requires. Other scripts run directly on POSIX and through
shon Windows.The environment adds the documented
TD_*contract. No credential is ever injected: an extension that needs a token runstd auth token view. A token the user exported themselves is inherited like any other variable, which the spec records as a deliberate exception, and there is now a test pinning that behaviour so it cannot change by accident.Stack: #521 core · #522 discovery · #523 dispatch · #524 tools · #525 install · #526 upgrade · #527 manager