@devries-cameron20 / composio-1 / commits / c770db8b4
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

refactor(cli): declare shared-flag support and map commands to files (#5136)

This PR: - builds on top of https://github.com/ComposioHQ/composio/pull/5135 - adds `CommandMeta.sharedFlags` (`{ userId?: boolean, projectName?: boolean }`, inherited per flag; `NO_SHARED_FLAGS` for both) in place of the hand-typed `rejectsSharedFlags('dev …')` strings. The selected command rejects an unsupported flag right after it began, with a message and `CommandInputError.command` that name the command that ran, not the group that declared the restriction: `composio dev logs tools --project-name x` now says "`composio dev logs tools` cannot target another project yet. …" where it said `composio dev logs`. `dev logs`, `dev projects` and `dev auth-configs` subcommands are also recorded against their own path (`dev logs tools`) instead of the group's (the gap noted in #5134) - adds a test over all 54 rejection cases (flag before and after the subcommand) that checks the message, the `command`, the option, exit code 1 and the recorded path. The `dev --mode` toggle keeps `rejectSharedFlags` with its own wording - adds a generated `src/commands/COMMANDS.md`: one row per registration with its tree, source `.cmd.ts`, other registrations of the same definition (root shortcuts), login, and visibility. `test/src/commands/commands-map.test.ts` builds it by walking the tree and finding each definition among the `.cmd.ts` exports by name and `examples` identity, so no command declares its own file. It fails while the file is stale; `pnpm --filter @composio/cli run commands:map` rewrites it - adds `test/src/commands/command-references.test.ts`: every `composio <words>` in a string literal under `src/` has to resolve on the command tree - fixes the hints that test found: `composio dev orgs list|switch` → `composio orgs list|switch` (orgs list intro and hint, missing-org error, the unused `dev.orgs.switch` hint node is removed), and root `triggers list` with an unknown toolkit → `composio search "<what you want to do>"` instead of the non-existent `composio toolkits list`, since toolkits are listed only under `dev` (`dev triggers list` keeps `composio dev toolkits list`) - behaviour change: a dev leaf command given a flag it cannot honor now rejects the flag before it checks the login, which group-level rejections already did, and the rejection names the exact subcommand. Both are noted in CHANGELOG under Patch, with the corrected hints Verification: `pnpm typecheck`, `pnpm --filter @composio/cli run lint:effect`, `pnpm --filter @composio/cli test` (222 files, 2893 passed, 1 skipped), `oxlint ts/packages/cli`.

Alberto Schiabel committed Oct 28, 2026 at 19:06 UTC c770db8b473a020b317f6b7957a02124f50dead3
26 files changed +655 -117
ts/packages/cli/AGENTS.md
+5 -2
@@ -31,7 +31,7 @@ Signals belong to the runner, the one place that installs SIGINT, SIGTERM and SI
31
32 Errors are captured via the custom `effect-errors/` module (source-mapped stack traces, Effect span timelines, formatted output).
33
34 -The invocation learns which command it runs after `effect/cli` parsed argv, never from argv itself ([ADR 0001](docs/adr/0001-command-identity-after-parse.md)). A command's identity (`src/invocation/command-identity.ts`) is its command registration: the command path from the root plus the `CommandMeta` it declares (one `Command.annotate` key, set with `withCommandMeta`: the lifecycle `telemetryFamily`; `requiresLogin`; and `hooks`, the invocation hooks the command turns off, by name, with `false` or a predicate over its parsed input; subcommands inherit the last two, except a hook predicate, which applies only where it is declared). Every group registers its subcommands with `withRegisteredSubcommands` (`src/commands/registration.ts`), which provides each registration's identity around its dispatch; only the selected command's handler calls `CommandInvocation.begin`, which runs the command's invocation hooks and then reports the invoked event (whose toolkit lookup for `execute` is a backend request, so the backend mismatch warning comes first), then the command checks a required login. `--help` and `--version` (the `Help` and `Version` actions in `root-help.ts`) and a parse failure (`CliError.ShowHelp.commandPath`, canonical names only, `failure_reason_code: "parse_error"`) begin the command `effect/cli` names, with no parsed input and so no hooks. So does a group run with no subcommand, whose own handler only shows its help (the bare root command included), unless the group declares that handler an action of its own (`withRegisteredSubcommands(subcommands, { ownAction: true })`: `dev`, `setup`, `generate`); `help …` turns every hook off in its `CommandMeta`. `test/src/commands/registration.test.ts` pins the handler composition order this relies on. Telemetry families and hook opt-outs are declared on root registrations in `src/commands/index.ts`; `dev` commands report the generic family.
34 +The invocation learns which command it runs after `effect/cli` parsed argv, never from argv itself ([ADR 0001](docs/adr/0001-command-identity-after-parse.md)). A command's identity (`src/invocation/command-identity.ts`) is its command registration: the command path from the root plus the `CommandMeta` it declares (one `Command.annotate` key, set with `withCommandMeta`: the lifecycle `telemetryFamily`; `requiresLogin`; `hooks`, the invocation hooks the command turns off, by name, with `false` or a predicate over its parsed input; and `sharedFlags`, the `dev` shared flags it cannot honor; subcommands inherit the last three, except a hook predicate, which applies only where it is declared). Every group registers its subcommands with `withRegisteredSubcommands` (`src/commands/registration.ts`), which provides each registration's identity around its dispatch; only the selected command's handler calls `CommandInvocation.begin`, which runs the command's invocation hooks and then reports the invoked event (whose toolkit lookup for `execute` is a backend request, so the backend mismatch warning comes first), then the command rejects a shared flag it cannot honor and checks a required login. `--help` and `--version` (the `Help` and `Version` actions in `root-help.ts`) and a parse failure (`CliError.ShowHelp.commandPath`, canonical names only, `failure_reason_code: "parse_error"`) begin the command `effect/cli` names, with no parsed input and so no hooks. So does a group run with no subcommand, whose own handler only shows its help (the bare root command included), unless the group declares that handler an action of its own (`withRegisteredSubcommands(subcommands, { ownAction: true })`: `dev`, `setup`, `generate`); `help …` turns every hook off in its `CommandMeta`. `test/src/commands/registration.test.ts` pins the handler composition order this relies on. Telemetry families and hook opt-outs are declared on root registrations in `src/commands/index.ts`; `dev` commands report the generic family.
35
36 ### Commands — `src/commands/`
37
@@ -67,6 +67,8 @@ Each command uses `effect/cli`'s `Command.make()` pattern. Current top-level com
67
68 Named options use `Flag.String()`, `Flag.Boolean()`, `Flag.Int()`, `Flag.Literals()`, `Flag.Directory()` (from `effect/cli`); positionals use `Argument.String()` / `Argument.variadic()`. Both share `.withDefault`/`.withDescription`/`.withAlias`/`.optional` combinators. Feature flags live in `feature-tags.ts` and `experimental-features.ts`.
69
70 +To find a command's source, grep [`src/commands/COMMANDS.md`](src/commands/COMMANDS.md) for its path: one row per command registration with its tree (root or `dev`), the `.cmd.ts` file that defines it, other registrations of the same definition (root shortcuts such as `link`), whether it needs a login, and whether it is unlisted or experimental. It is generated from the command tree (`test/src/commands/commands-map.test.ts`, which finds each registration's definition among the `.cmd.ts` exports); after adding, moving, or renaming a command, run `pnpm --filter @composio/cli run commands:map` and commit the result. `pnpm test` fails while it is stale.
71 +
72 #### Command module layout
73
74 Every command is a directory named after the command, holding files that share the command's dotted basename. A group is a directory named after the group, whose entry file `<group>.cmd.ts` only lists subcommands.
@@ -90,7 +92,8 @@ Rules:
92
93 - `<group>.<name>.cmd.ts` declares the surface and nothing else: flag and argument constants, `Command.withDescription`, `Command.withExamples`, and the three-argument `Command.make(name, flags, handler)` with the handler imported from the sibling `.handler.ts`. It yields no service and contains no branching. `Command.withHandler` is reserved for `src/commands/index.ts`, where the root handler is attached at assembly time.
94 - `<group>.<name>.handler.ts` exports the handler as a function of a plain params type it declares itself; the command proves it provides those params when it passes the handler to `Command.make`. Do not derive the params type from the `Command` value (no phantom commands, no `GetCmdParams`).
93 -- A command that exists in both the root tree and the `dev` tree is defined once. The group supplies what differs between the two surfaces through `Command.withSharedFlags` and `Command.provide`, not through a second `Command.make` with a copied description. `--user-id` and `--project-name` are shared flags of the `dev` group (`dev.cmd.ts`), accepted before or after the subcommand name and documented once on every `dev` page; a handler reads them, and the tree it runs in, from `CommandSurface` (`surface.ts`) and never declares either flag itself, since `withSharedFlags` rejects a duplicate on a direct subcommand. A `dev` command that cannot honor one of them yet (it cannot target another project, or it does not act for a user) pipes `rejectsSharedFlags` (`surface.ts`), and the `dev` group's own `--mode` toggle calls `rejectSharedFlags`, so the flag fails with a `CommandInputError` instead of being ignored. `execute` and `playground-execute` keep two registrations because their names differ; they share one handler.
95 +- A command that exists in both the root tree and the `dev` tree is defined once. The group supplies what differs between the two surfaces through `Command.withSharedFlags` and `Command.provide`, not through a second `Command.make` with a copied description. `--user-id` and `--project-name` are shared flags of the `dev` group (`dev.cmd.ts`), accepted before or after the subcommand name and documented once on every `dev` page; a handler reads them, and the tree it runs in, from `CommandSurface` (`surface.ts`) and never declares either flag itself, since `withSharedFlags` rejects a duplicate on a direct subcommand. A `dev` command that cannot honor one of them yet (it cannot target another project, or it does not act for a user) declares it in its `CommandMeta`: `withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })` for both, `{ sharedFlags: { projectName: false } }` for one, piped where its group registers it, or on a group entry for every subcommand under it. The selected command rejects such a flag right after it began, with a `CommandInputError` naming the command that ran (`dev logs tools`, not the `dev logs` group that declared it), which telemetry records too; never type a command path for the message. The `dev` group's own `--mode` toggle calls `rejectSharedFlags` (`surface.ts`) with its own wording. `execute` and `playground-execute` keep two registrations because their names differ; they share one handler.
96 +- A hint, example, or message that names a command (`composio …`) names a real registration on the tree it names: `orgs` is a root command, so `composio dev orgs switch` is wrong. `test/src/commands/command-references.test.ts` finds every `composio <words>` in a string or template literal under `src/` and fails when the words stop at a group or before any command; prose that only reads like a command goes in its `NOT_COMMANDS` list.
97 - A handler that acts as a user gets it, and the project it was resolved against, from `actingUser` (fails with `MissingActingUserError`, an expected failure whose message fits the tree) or `actingUserOption` (for a command that also runs without one) in `surface.ts`; both name a fallback test user on stderr. A handler never reads `--user-id` or a test user id to resolve one itself, never prints that notice, and lets `MissingActingUserError` through instead of wrapping it in its own error (its tag is the `error_name` telemetry reports). An empty consumer user id counts as none. A `--user-id` that only filters results (`dev logs`, `dev triggers listen`, `dev connected-accounts list`) stays a raw flag.
98 - Logic shared across groups belongs in `src/effects/` or `src/services/`, never in another command's directory.
99 - A group registers its subcommands with `withRegisteredSubcommands` (`src/commands/registration.ts`), never `Command.withSubcommands`, so each subcommand gets its command identity.
ts/packages/cli/CHANGELOG.md
+18
@@ -106,6 +106,24 @@
106 `failure_reason_code: "parse_error"`. Every other command path and event
107 family is unchanged.
108
109 +- Hints no longer name commands that do not exist. `composio orgs list` and
110 + the "No current org configured" error pointed at `composio dev orgs list` and
111 + `composio dev orgs switch`; they now name `composio orgs list` and
112 + `composio orgs switch`. `composio triggers list` with an unknown toolkit
113 + pointed at `composio toolkits list`; it now suggests
114 + `composio search "<what you want to do>"` to find the toolkit.
115 + `composio dev triggers list` still names `composio dev toolkits list`.
116 +
117 +- A `composio dev` command that cannot honor `--user-id` or `--project-name`
118 + now rejects it before checking that you are logged in, and the message names
119 + the exact subcommand you ran instead of the group that declared the
120 + restriction: `composio dev logs tools --project-name x` now names
121 + `composio dev logs tools`, where it named `composio dev logs`. Telemetry
122 + records the failure against that subcommand too. A group run on its own
123 + rejects the flag the same way instead of printing its help:
124 + `composio dev projects --user-id x` fails with that error, while
125 + `composio dev projects --help` still prints the help.
126 +
127 - CLI telemetry now records a command that prints its own
128 failure and exits 1 (a failed API request, an alias conflict on
129 `composio link`, a `--fail-fast` listener stop) as failed instead of
ts/packages/cli/package.json
+1
@@ -31,6 +31,7 @@
31 "validate:skills": "tsx ./scripts/validate-skills.ts",
32 "validate:boundaries": "tsx ./scripts/validate-lint-boundaries.ts",
33 "validate:command-tests": "tsx ./scripts/validate-command-tests.ts",
34 + "commands:map": "vitest run test/src/commands/commands-map.test.ts --update",
35 "lint:effect": "tsx ./scripts/check-effect-diagnostics.ts",
36 "install:binary": "bun run ./scripts/install-binary.ts ./dist/composio",
37 "table:metrics": "bun run ./scripts/optimize-metrics-table.ts",
ts/packages/cli/src/commands/COMMANDS.md new
+92
@@ -0,0 +1,92 @@
1 +<!-- Generated from the command tree by `pnpm --filter @composio/cli run commands:map`. Do not edit; `pnpm test` fails while it is stale. -->
2 +
3 +# Commands
4 +
5 +Every command registration of the CLI and the file that defines it. To find a command, grep this file for its path.
6 +
7 +- **Tree**: `dev` for commands under `composio dev` (developer mode), `root` otherwise.
8 +- **Also at**: other registrations of the same definition, such as a root shortcut.
9 +- **Login**: the command needs a logged-in user (`requiresLogin`, inherited from its group).
10 +- **Visibility**: `unlisted` commands are left out of help but still run; `experimental` ones exist only while their experimental feature is enabled.
11 +- `composio help <command>` mirrors every row and is not listed.
12 +
13 +| Command | Tree | Source | Alias | Also at | Login | Visibility |
14 +| ------------------------------- | ---- | ----------------------------------------------------------------------------------------- | ----- | ----------------------------- | ----- | ------------ |
15 +| `composio` | root | `ts/packages/cli/src/commands/$default.cmd.ts` | | | no | listed |
16 +| `agent` | root | `ts/packages/cli/src/commands/agent/agent.cmd.ts` | | | no | listed |
17 +| `agent claim` | root | `ts/packages/cli/src/commands/agent/claim/agent.claim.cmd.ts` | | | no | listed |
18 +| `agent inbox` | root | `ts/packages/cli/src/commands/agent/inbox/agent.inbox.cmd.ts` | | | no | listed |
19 +| `agent login` | root | `ts/packages/cli/src/commands/agent/login/agent.login.cmd.ts` | | | no | listed |
20 +| `agent signup` | root | `ts/packages/cli/src/commands/agent/signup/agent.signup.cmd.ts` | | | no | listed |
21 +| `agent whoami` | root | `ts/packages/cli/src/commands/agent/whoami/agent.whoami.cmd.ts` | | | no | listed |
22 +| `artifacts` | root | `ts/packages/cli/src/commands/artifacts/artifacts.cmd.ts` | | | no | listed |
23 +| `artifacts cwd` | root | `ts/packages/cli/src/commands/artifacts/cwd/artifacts.cwd.cmd.ts` | | | no | listed |
24 +| `config` | root | `ts/packages/cli/src/commands/config/config.cmd.ts` | | | no | listed |
25 +| `config experimental` | root | `ts/packages/cli/src/commands/config/config.experimental.cmd.ts` | | | no | listed |
26 +| `connections` | root | `ts/packages/cli/src/commands/connections/connections.cmd.ts` | | | yes | listed |
27 +| `connections list` | root | `ts/packages/cli/src/commands/connections/list/connections.list.cmd.ts` | | | yes | listed |
28 +| `connections remove` | root | `ts/packages/cli/src/commands/connections/remove/connections.remove.cmd.ts` | | | yes | listed |
29 +| `debug` | root | `ts/packages/cli/src/commands/debug/debug.cmd.ts` | | | no | unlisted |
30 +| `debug api-info` | root | `ts/packages/cli/src/commands/debug/api-info/debug.api-info.cmd.ts` | | | no | unlisted |
31 +| `debug generate-graph` | root | `ts/packages/cli/src/commands/debug/generate-graph/debug.generate-graph.cmd.ts` | | | no | unlisted |
32 +| `debug who-is-my-master` | root | `ts/packages/cli/src/commands/debug/who-is-my-master/debug.who-is-my-master.cmd.ts` | | | no | unlisted |
33 +| `dev` | dev | `ts/packages/cli/src/commands/dev.cmd.ts` | | | no | listed |
34 +| `dev auth-configs` | dev | `ts/packages/cli/src/commands/auth-configs/auth-configs.cmd.ts` | | | yes | listed |
35 +| `dev auth-configs create` | dev | `ts/packages/cli/src/commands/auth-configs/create/auth-configs.create.cmd.ts` | | | yes | listed |
36 +| `dev auth-configs info` | dev | `ts/packages/cli/src/commands/auth-configs/info/auth-configs.info.cmd.ts` | | | yes | listed |
37 +| `dev auth-configs list` | dev | `ts/packages/cli/src/commands/auth-configs/list/auth-configs.list.cmd.ts` | | | yes | listed |
38 +| `dev connected-accounts` | dev | `ts/packages/cli/src/commands/connected-accounts/connected-accounts.cmd.ts` | | | yes | listed |
39 +| `dev connected-accounts info` | dev | `ts/packages/cli/src/commands/connected-accounts/info/connected-accounts.info.cmd.ts` | | | yes | listed |
40 +| `dev connected-accounts link` | dev | `ts/packages/cli/src/commands/connected-accounts/link/connected-accounts.link.cmd.ts` | | `link` | yes | listed |
41 +| `dev connected-accounts list` | dev | `ts/packages/cli/src/commands/connected-accounts/list/connected-accounts.list.cmd.ts` | | | yes | listed |
42 +| `dev connected-accounts whoami` | dev | `ts/packages/cli/src/commands/connected-accounts/whoami/connected-accounts.whoami.cmd.ts` | | | yes | listed |
43 +| `dev init` | dev | `ts/packages/cli/src/commands/init.cmd.ts` | | | no | listed |
44 +| `dev listen` | dev | `ts/packages/cli/src/commands/triggers/commands/triggers.listen.cmd.ts` | | `dev triggers listen` | yes | listed |
45 +| `dev logs` | dev | `ts/packages/cli/src/commands/logs/logs.cmd.ts` | | | yes | listed |
46 +| `dev logs tools` | dev | `ts/packages/cli/src/commands/logs/tools/logs.tools.cmd.ts` | | | yes | listed |
47 +| `dev logs triggers` | dev | `ts/packages/cli/src/commands/logs/triggers/logs.triggers.cmd.ts` | | | yes | listed |
48 +| `dev playground-execute` | dev | `ts/packages/cli/src/commands/tools/commands/tools.execute.cmd.ts` | | | yes | listed |
49 +| `dev projects` | dev | `ts/packages/cli/src/commands/projects/projects.cmd.ts` | | | no | listed |
50 +| `dev projects list` | dev | `ts/packages/cli/src/commands/projects/list/projects.list.cmd.ts` | | | yes | listed |
51 +| `dev projects switch` | dev | `ts/packages/cli/src/commands/projects/switch/projects.switch.cmd.ts` | | | no | listed |
52 +| `dev toolkits` | dev | `ts/packages/cli/src/commands/toolkits/toolkits.cmd.ts` | | | yes | listed |
53 +| `dev toolkits info` | dev | `ts/packages/cli/src/commands/toolkits/info/toolkits.info.cmd.ts` | | | yes | listed |
54 +| `dev toolkits list` | dev | `ts/packages/cli/src/commands/toolkits/list/toolkits.list.cmd.ts` | | | yes | listed |
55 +| `dev toolkits search` | dev | `ts/packages/cli/src/commands/toolkits/search/toolkits.search.cmd.ts` | | | yes | listed |
56 +| `dev toolkits version` | dev | `ts/packages/cli/src/commands/toolkits/version/toolkits.version.cmd.ts` | | | yes | listed |
57 +| `dev triggers` | dev | `ts/packages/cli/src/commands/triggers/triggers.cmd.ts` | | | yes | listed |
58 +| `dev triggers create` | dev | `ts/packages/cli/src/commands/triggers/create/triggers.create.cmd.ts` | | | yes | listed |
59 +| `dev triggers disable` | dev | `ts/packages/cli/src/commands/triggers/disable/triggers.disable.cmd.ts` | | | yes | listed |
60 +| `dev triggers enable` | dev | `ts/packages/cli/src/commands/triggers/enable/triggers.enable.cmd.ts` | | | yes | listed |
61 +| `dev triggers info` | dev | `ts/packages/cli/src/commands/triggers/info/triggers.info.cmd.ts` | | `triggers info` | yes | listed |
62 +| `dev triggers list` | dev | `ts/packages/cli/src/commands/triggers/list/triggers.list.cmd.ts` | | `triggers list` | yes | listed |
63 +| `dev triggers listen` | dev | `ts/packages/cli/src/commands/triggers/commands/triggers.listen.cmd.ts` | | `dev listen` | yes | listed |
64 +| `dev triggers status` | dev | `ts/packages/cli/src/commands/triggers/status/triggers.status.cmd.ts` | | | yes | listed |
65 +| `execute` | root | `ts/packages/cli/src/commands/tools/commands/tools.execute.cmd.ts` | | | yes | listed |
66 +| `generate` | root | `ts/packages/cli/src/commands/generate/generate.cmd.ts` | | | no | listed |
67 +| `generate py` | root | `ts/packages/cli/src/commands/generate/py/generate.py.cmd.ts` | | | no | listed |
68 +| `generate ts` | root | `ts/packages/cli/src/commands/generate/ts/generate.ts.cmd.ts` | | | no | listed |
69 +| `help` | root | `ts/packages/cli/src/commands/root-help.ts` | | | no | listed |
70 +| `install` | root | `ts/packages/cli/src/commands/install/install.cmd.ts` | | | no | listed |
71 +| `link` | root | `ts/packages/cli/src/commands/connected-accounts/link/connected-accounts.link.cmd.ts` | | `dev connected-accounts link` | yes | listed |
72 +| `listen` | root | `ts/packages/cli/src/commands/listen.cmd.ts` | | | yes | experimental |
73 +| `login` | root | `ts/packages/cli/src/commands/login/login.cmd.ts` | | | no | listed |
74 +| `logout` | root | `ts/packages/cli/src/commands/logout.cmd.ts` | | | no | listed |
75 +| `orgs` | root | `ts/packages/cli/src/commands/orgs/orgs.cmd.ts` | | | yes | listed |
76 +| `orgs list` | root | `ts/packages/cli/src/commands/orgs/list/orgs.list.cmd.ts` | | | yes | listed |
77 +| `orgs switch` | root | `ts/packages/cli/src/commands/orgs/switch/orgs.switch.cmd.ts` | | | yes | listed |
78 +| `proxy` | root | `ts/packages/cli/src/commands/proxy.cmd.ts` | | | yes | listed |
79 +| `run` | root | `ts/packages/cli/src/commands/run.cmd.ts` | | | no | listed |
80 +| `search` | root | `ts/packages/cli/src/commands/tools/search/tools.search.cmd.ts` | | | yes | listed |
81 +| `setup` | root | `ts/packages/cli/src/commands/setup.cmd.ts` | | | no | listed |
82 +| `setup skill` | root | `ts/packages/cli/src/commands/setup-skill.cmd.ts` | | | no | listed |
83 +| `signup` | root | `ts/packages/cli/src/commands/signup/signup.cmd.ts` | | | no | listed |
84 +| `tools` | root | `ts/packages/cli/src/commands/tools/tools.cmd.ts` | | | yes | listed |
85 +| `tools info` | root | `ts/packages/cli/src/commands/tools/info/tools.info.cmd.ts` | | | yes | listed |
86 +| `tools list` | root | `ts/packages/cli/src/commands/tools/list/tools.list.cmd.ts` | | | yes | listed |
87 +| `triggers` | root | `ts/packages/cli/src/commands/triggers/root-triggers.cmd.ts` | | | yes | listed |
88 +| `triggers info` | root | `ts/packages/cli/src/commands/triggers/info/triggers.info.cmd.ts` | | `dev triggers info` | yes | listed |
89 +| `triggers list` | root | `ts/packages/cli/src/commands/triggers/list/triggers.list.cmd.ts` | | `dev triggers list` | yes | listed |
90 +| `upgrade` | root | `ts/packages/cli/src/commands/upgrade/upgrade.cmd.ts` | | | no | listed |
91 +| `version` | root | `ts/packages/cli/src/commands/version.cmd.ts` | | | no | listed |
92 +| `whoami` | root | `ts/packages/cli/src/commands/whoami.cmd.ts` | | | no | listed |
ts/packages/cli/src/commands/connected-accounts/connected-accounts.cmd.ts
+3 -3
@@ -1,6 +1,6 @@
1 import { withCommandMeta } from 'src/invocation/command-identity';
2 import { Command } from 'effect/cli';
3 -import { rejectsSharedFlags } from 'src/commands/surface';
3 +import { NO_SHARED_FLAGS } from 'src/commands/surface';
4 import { connectedAccountsCmd$List } from './list/connected-accounts.list.cmd';
5 import { connectedAccountsCmd$Info } from './info/connected-accounts.info.cmd';
6 import { connectedAccountsCmd$Whoami } from './whoami/connected-accounts.whoami.cmd';
@@ -20,8 +20,8 @@ export const connectedAccountsCmd = Command.make('connected-accounts').pipe(
20 withRegisteredSubcommands([
21 connectedAccountsCmd$Link,
22 connectedAccountsCmd$List,
23 - connectedAccountsCmd$Info.pipe(rejectsSharedFlags('dev connected-accounts info')),
24 - connectedAccountsCmd$Whoami.pipe(rejectsSharedFlags('dev connected-accounts whoami')),
23 + connectedAccountsCmd$Info.pipe(withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })),
24 + connectedAccountsCmd$Whoami.pipe(withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })),
25 ]),
26 withCommandMeta({ requiresLogin: true })
27 );
ts/packages/cli/src/commands/dev.cmd.ts
+6 -8
@@ -15,7 +15,7 @@ import { ComposioCliUserConfig, resolveCliConfigPath } from 'src/services/cli-us
15 import { Stdin } from 'src/services/stdin';
16 import { TerminalUI } from 'src/services/terminal-ui';
17 import type { CommandVisibility } from './feature-tags';
18 -import { CommandSurface, rejectSharedFlags, rejectsSharedFlags } from './surface';
18 +import { CommandSurface, NO_SHARED_FLAGS, rejectSharedFlags } from './surface';
19 import { withRegisteredSubcommands } from 'src/commands/registration';
20
21 const devMode = Flag.Literals('mode', ['on', 'off'] as const).pipe(
@@ -41,15 +41,15 @@ const projectName = Flag.String('project-name').pipe(
41 );
42
43 export const devSubcommands = [
44 - initCmd.pipe(rejectsSharedFlags('dev init')),
44 + initCmd.pipe(withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })),
45 devToolsCmd$Execute,
46 triggersCmd$Listen.pipe(withCommandMeta({ requiresLogin: true })),
47 - logsCmd.pipe(rejectsSharedFlags('dev logs', ['--project-name'])),
47 + logsCmd.pipe(withCommandMeta({ sharedFlags: { projectName: false } })),
48 toolkitsCmd,
49 - authConfigsCmd.pipe(rejectsSharedFlags('dev auth-configs')),
49 + authConfigsCmd.pipe(withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })),
50 connectedAccountsCmd,
51 triggersCmd,
52 - projectsCmd.pipe(rejectsSharedFlags('dev projects')),
52 + projectsCmd.pipe(withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })),
53 ] as const;
54
55 const describeCurrentMode = (enabled: boolean) =>
@@ -177,9 +177,7 @@ const toggleRejections = {
177 export const buildDevCommand = (visibility: CommandVisibility) =>
178 visibility.isDevModeEnabled
179 ? makeDevCommand(visibility, input =>
180 - rejectSharedFlags('dev', undefined, toggleRejections).pipe(
181 - Effect.andThen(developerModeHandler(input))
182 - )
180 + rejectSharedFlags('dev', toggleRejections).pipe(Effect.andThen(developerModeHandler(input)))
181 ).pipe(
182 withRegisteredSubcommands([...devSubcommands], { ownAction: true }),
183 Command.withSharedFlags({ userId, projectName }),
ts/packages/cli/src/commands/orgs/list/orgs.list.format.ts
+3 -3
@@ -3,13 +3,13 @@ import type { OrganizationSummary } from 'src/services/composio-account';
3
4 // --- stderr -----------------------------------------------------------------------------------
5
6 -/** The intro both trees print; `orgs list` is reachable from the root as well. */
7 -export const ORGS_LIST_INTRO = 'composio dev orgs list';
6 +/** The intro `orgs list` prints; `orgs` is a root command only. */
7 +export const ORGS_LIST_INTRO = 'composio orgs list';
8 export const LOADING_ORGANIZATIONS_MESSAGE = 'Loading organizations...';
9 export const FETCH_ORGANIZATIONS_FAILED_MESSAGE = 'Failed to fetch organizations';
10 export const NO_ORGANIZATIONS_MESSAGE = 'No organizations found.';
11 export const ORGS_LIST_OUTRO =
12 - 'Hint: run `composio dev orgs switch` to switch the default global org/project.';
12 + 'Hint: run `composio orgs switch` to switch the default global org/project.';
13
14 export const loadedOrganizationsMessage = (count: number) => `Loaded ${count} orgs`;
15
ts/packages/cli/src/commands/registration.ts
+17 -5
@@ -11,7 +11,8 @@
11 */
12 import { Effect, Option } from 'effect';
13 import { Command } from 'effect/cli';
14 -import type { NotLoggedInError } from 'src/commands/errors';
14 +import type { CommandInputError, NotLoggedInError } from 'src/commands/errors';
15 +import { type CommandSurface, rejectUnsupportedSharedFlags } from 'src/commands/surface';
16 import { assertLoggedIn } from 'src/effects/require-auth';
17 import {
18 childIdentity,
@@ -23,23 +24,34 @@ import type { ComposioUserContext } from 'src/services/user-context';
24 /**
25 * Records the running registration as the command this invocation runs, with the input
26 * `effect/cli` parsed for it (none for a group that only shows its help, so, like `--help`, it
26 - * runs no invocation hook), then enforces what its `CommandMeta` requires: a login fails after
27 - * the identity is recorded, so `NotLoggedInError` is reported against the command the user ran.
27 + * runs no invocation hook), then enforces what its `CommandMeta` requires: a shared flag it cannot
28 + * honor, then a login. Both fail after the identity is recorded, so the failure is reported
29 + * against the command the user ran, even when a group above it declared the requirement.
30 */
31 const beginSelected = (input: Option.Option<unknown>) =>
32 Effect.gen(function* () {
33 const identity = yield* CommandRegistration;
34 const invocation = yield* CommandInvocation;
35 yield* invocation.begin(identity, input);
36 + yield* rejectUnsupportedSharedFlags(identity);
37 if (identity.meta.requiresLogin) {
38 yield* assertLoggedIn;
39 }
40 });
41
39 -/** A command as a group registers it: its handler may now fail with `NotLoggedInError`. */
42 +/**
43 + * A command as a group registers it: its handler may now fail with `NotLoggedInError` or a
44 + * rejected shared flag's `CommandInputError`.
45 + */
46 export type Registered<C> =
47 C extends Command.Command<infer Name, infer Input, infer ContextInput, infer E, infer R>
42 - ? Command.Command<Name, Input, ContextInput, E | NotLoggedInError, R | ComposioUserContext>
48 + ? Command.Command<
49 + Name,
50 + Input,
51 + ContextInput,
52 + E | NotLoggedInError | CommandInputError,
53 + R | ComposioUserContext | CommandSurface
54 + >
55 : never;
56
57 /**
ts/packages/cli/src/commands/root-help.ts
+4 -3
@@ -1,6 +1,7 @@
1 import { Console, Context, Effect } from 'effect';
2 import { CliConfig, CliOutput, Command, GlobalFlag } from 'effect/cli';
3 -import type { NotLoggedInError } from 'src/commands/errors';
3 +import type { CommandInputError, NotLoggedInError } from 'src/commands/errors';
4 +import type { CommandSurface } from 'src/commands/surface';
5 import { beginAtCommandPath } from 'src/invocation/command-identity';
6 import type { ComposioUserContext } from 'src/services/user-context';
7 import { withRegisteredSubcommands } from 'src/commands/registration';
@@ -61,8 +62,8 @@ export const buildHelpCommand = (commands: ReadonlyArray<Command.Command.Any>) =
62 string,
63 Record<never, never>,
64 Record<never, never>,
64 - NotLoggedInError,
65 - RootHelpContext | ComposioUserContext
65 + CommandInputError | NotLoggedInError,
66 + RootHelpContext | ComposioUserContext | CommandSurface
67 > =>
68 Command.make(name, {}, () => showCommandHelp(path)).pipe(
69 Command.withDescription(description ?? 'Show command help.'),
ts/packages/cli/src/commands/surface.ts
+45 -28
@@ -1,7 +1,7 @@
1 -import { Context, Data, Effect, Layer, Option, pipe } from 'effect';
2 -import { Command } from 'effect/cli';
1 +import { Array as Arr, Context, Data, Effect, Layer, Option, pipe } from 'effect';
2 import { commandInputError } from 'src/commands/errors';
3 import { ExpectedFailure } from 'src/effects/expected-failure';
4 +import type { CommandIdentity, SharedFlagName } from 'src/invocation/command-identity';
5 import {
6 resolveCommandProject,
7 type ProjectMode,
@@ -249,40 +249,57 @@ export const actingUserOption = () =>
249 /** A shared flag of the `dev` group. */
250 export type SharedFlag = '--user-id' | '--project-name';
251
252 +/**
253 + * `CommandMeta.sharedFlags` for a `dev` command, or a group, that honors neither shared flag:
254 + * it cannot target another project and does not act as a user.
255 + */
256 +export const NO_SHARED_FLAGS = { userId: false, projectName: false } as const;
257 +
258 +/** The shared flags, in the order a rejection reports them when several are given. */
259 +const SHARED_FLAGS: ReadonlyArray<{ readonly name: SharedFlagName; readonly flag: SharedFlag }> = [
260 + { name: 'projectName', flag: '--project-name' },
261 + { name: 'userId', flag: '--user-id' },
262 +];
263 +
264 const unsupportedSharedFlag = (command: string): Record<SharedFlag, string> => ({
265 '--project-name': `\`composio ${command}\` cannot target another project yet. Remove --project-name, or run it from that project's directory.`,
266 '--user-id': `\`composio ${command}\` does not act as a user. Remove --user-id.`,
267 });
268
257 -/**
258 - * Fails with a `CommandInputError` when the surface carries one of `flags`, for a `dev` command
259 - * that cannot honor it. Without it the flag would be accepted and ignored. `messages` defaults
260 - * to the wording for a command that runs against the directory's project.
261 - */
262 -export const rejectSharedFlags = (
263 - command: string,
264 - flags: ReadonlyArray<SharedFlag> = ['--project-name', '--user-id'],
265 - messages: Record<SharedFlag, string> = unsupportedSharedFlag(command)
266 -) =>
269 +/** The first shared flag the surface carries among those `rejects` picks, if any. */
270 +const givenSharedFlag = (rejects: (name: SharedFlagName) => boolean) =>
271 Effect.gen(function* () {
272 const surface = yield* CommandSurface;
269 - const values: Record<SharedFlag, Option.Option<string>> = {
270 - '--project-name': surface.projectName,
271 - '--user-id': surface.userId,
272 - };
273 - const given = flags.find(flag => Option.isSome(values[flag]));
274 - if (given !== undefined) {
275 - return yield* commandInputError(command)(messages[given], given);
276 - }
273 + return Arr.findFirst(SHARED_FLAGS, ({ name }) => rejects(name) && Option.isSome(surface[name]));
274 });
275
276 /**
280 - * Applies `rejectSharedFlags` to a `dev` command, or to a group entry and every subcommand
281 - * under it. `flags` defaults to both.
277 + * Fails with a `CommandInputError` when the surface carries either shared flag, with `messages`
278 + * for its wording: the `dev` group's own `--mode` toggle, which changes a global setting.
279 + */
280 +export const rejectSharedFlags = (command: string, messages: Record<SharedFlag, string>) =>
281 + Effect.flatMap(
282 + givenSharedFlag(() => true),
283 + Option.match({
284 + onNone: () => Effect.void,
285 + onSome: ({ flag }) => Effect.fail(commandInputError(command)(messages[flag], flag)),
286 + })
287 + );
288 +
289 +/**
290 + * Fails with a `CommandInputError` when the surface carries a shared flag the selected command
291 + * cannot honor (`CommandMeta.sharedFlags`), naming the command that ran even when a group above
292 + * it declared so. Without it the flag would be accepted and ignored. The registration runs it
293 + * right after the command began (`src/commands/registration.ts`).
294 */
283 -export const rejectsSharedFlags =
284 - (command: string, flags?: ReadonlyArray<SharedFlag>) =>
285 - <const Name extends string, Input, ContextInput, E, R>(
286 - self: Command.Command<Name, Input, ContextInput, E, R>
287 - ) =>
288 - Command.provideEffectDiscard(self, rejectSharedFlags(command, flags));
295 +export const rejectUnsupportedSharedFlags = (identity: CommandIdentity) =>
296 + Effect.flatMap(
297 + givenSharedFlag(name => identity.meta.unsupportedSharedFlags.includes(name)),
298 + Option.match({
299 + onNone: () => Effect.void,
300 + onSome: ({ flag }) => {
301 + const command = identity.path.join(' ');
302 + return Effect.fail(commandInputError(command)(unsupportedSharedFlag(command)[flag], flag));
303 + },
304 + })
305 + );
ts/packages/cli/src/commands/toolkits/toolkits.cmd.ts
+3 -3
@@ -1,6 +1,6 @@
1 import { withCommandMeta } from 'src/invocation/command-identity';
2 import { Command } from 'effect/cli';
3 -import { rejectsSharedFlags } from 'src/commands/surface';
3 +import { NO_SHARED_FLAGS } from 'src/commands/surface';
4 import { toolkitsCmd$List } from './list/toolkits.list.cmd';
5 import { toolkitsCmd$Info } from './info/toolkits.info.cmd';
6 import { toolkitsCmd$Search } from './search/toolkits.search.cmd';
@@ -20,8 +20,8 @@ export const toolkitsCmd = Command.make('toolkits').pipe(
20 withRegisteredSubcommands([
21 toolkitsCmd$List,
22 toolkitsCmd$Info,
23 - toolkitsCmd$Search.pipe(rejectsSharedFlags('dev toolkits search')),
24 - toolkitsCmd$Version.pipe(rejectsSharedFlags('dev toolkits version')),
23 + toolkitsCmd$Search.pipe(withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })),
24 + toolkitsCmd$Version.pipe(withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })),
25 ]),
26 withCommandMeta({ requiresLogin: true })
27 );
ts/packages/cli/src/commands/triggers/list/triggers.list.handler.ts
+22 -8
@@ -1,6 +1,7 @@
1 import { Effect } from 'effect';
2 import { commandInputError } from 'src/commands/errors';
3 import { CommandSurface } from 'src/commands/surface';
4 +import { commandHintStep } from 'src/services/command-hints';
5 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
6 import { TerminalUI } from 'src/services/terminal-ui';
7 import { clampLimit } from 'src/ui/clamp-limit';
@@ -13,11 +14,26 @@ export type TriggersListParams = {
14
15 const invalidToolkit = commandInputError('triggers list');
16
16 -/** The commands the hints name, on the tree the command runs in. */
17 +const findToolkitHint = commandHintStep('Find the toolkit for a task with', 'root.search', {
18 + query: '<what you want to do>',
19 +});
20 +
21 +/**
22 + * The hints, on the tree the command runs in. Toolkits are listed only under `dev`, so the root
23 + * tree finds a toolkit through `composio search` instead.
24 + */
25 const triggersListHints = Effect.map(CommandSurface, ({ tree }) =>
26 tree === 'dev'
19 - ? { noResultsCommand: 'composio dev toolkits list', infoCommand: 'composio dev triggers info' }
20 - : { noResultsCommand: 'composio toolkits list', infoCommand: 'composio triggers info' }
27 + ? {
28 + invalidToolkitHint: commandHintStep('List valid toolkits with', 'dev.toolkits.list'),
29 + noResultsHint: commandHintStep('Verify the toolkit slug with', 'dev.toolkits.list'),
30 + infoCommand: 'composio dev triggers info',
31 + }
32 + : {
33 + invalidToolkitHint: findToolkitHint,
34 + noResultsHint: findToolkitHint,
35 + infoCommand: 'composio triggers info',
36 + }
37 );
38
39 /**
@@ -32,7 +48,7 @@ const triggersListHints = Effect.map(CommandSurface, ({ tree }) =>
48 export const runTriggersList = ({ toolkit, limit }: TriggersListParams) =>
49 Effect.gen(function* () {
50 const ui = yield* TerminalUI;
35 - const { noResultsCommand, infoCommand } = yield* triggersListHints;
51 + const { invalidToolkitHint, noResultsHint, infoCommand } = yield* triggersListHints;
52 const repo = yield* ComposioToolkitsRepository;
53 const clampedLimit = clampLimit(limit);
54
@@ -40,7 +56,7 @@ export const runTriggersList = ({ toolkit, limit }: TriggersListParams) =>
56 Effect.catchTag('services/InvalidToolkitsError', error =>
57 Effect.gen(function* () {
58 const availableExample = error.availableToolkits.slice(0, 8).join(', ');
43 - yield* ui.log.step(`List valid toolkits with:\n> ${noResultsCommand}`);
59 + yield* ui.log.step(invalidToolkitHint);
60 return yield* Effect.fail(
61 invalidToolkit(
62 `Toolkit "${toolkit}" is not available. ${availableExample ? `Examples: ${availableExample}` : ''}`,
@@ -58,9 +74,7 @@ export const runTriggersList = ({ toolkit, limit }: TriggersListParams) =>
74 const triggerTypes = allTriggerTypes.slice(0, clampedLimit);
75
76 if (triggerTypes.length === 0) {
61 - yield* ui.log.warn(
62 - `No trigger types found in toolkit "${toolkit}". Verify the toolkit slug with:\n> ${noResultsCommand}`
63 - );
77 + yield* ui.log.warn(`No trigger types found in toolkit "${toolkit}". ${noResultsHint}`);
78 return;
79 }
80
ts/packages/cli/src/commands/triggers/triggers.cmd.ts
+7 -7
@@ -1,6 +1,6 @@
1 import { withCommandMeta } from 'src/invocation/command-identity';
2 import { Command } from 'effect/cli';
3 -import { rejectsSharedFlags } from 'src/commands/surface';
3 +import { NO_SHARED_FLAGS } from 'src/commands/surface';
4 import { triggersCmd$Info } from './info/triggers.info.cmd';
5 import { triggersCmd$List } from './list/triggers.list.cmd';
6 import { triggersCmd$Status } from './status/triggers.status.cmd';
@@ -22,12 +22,12 @@ export const triggersCmd = Command.make('triggers').pipe(
22 Command.withDescription('Inspect and subscribe to trigger events.'),
23 withRegisteredSubcommands([
24 triggersCmd$Listen,
25 - triggersCmd$List.pipe(rejectsSharedFlags('dev triggers list')),
26 - triggersCmd$Info.pipe(rejectsSharedFlags('dev triggers info')),
27 - triggersCmd$Status.pipe(rejectsSharedFlags('dev triggers status')),
28 - triggersCmd$Create.pipe(rejectsSharedFlags('dev triggers create', ['--project-name'])),
29 - triggersCmd$Enable.pipe(rejectsSharedFlags('dev triggers enable')),
30 - triggersCmd$Disable.pipe(rejectsSharedFlags('dev triggers disable')),
25 + triggersCmd$List.pipe(withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })),
26 + triggersCmd$Info.pipe(withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })),
27 + triggersCmd$Status.pipe(withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })),
28 + triggersCmd$Create.pipe(withCommandMeta({ sharedFlags: { projectName: false } })),
29 + triggersCmd$Enable.pipe(withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })),
30 + triggersCmd$Disable.pipe(withCommandMeta({ sharedFlags: NO_SHARED_FLAGS })),
31 ]),
32 withCommandMeta({ requiresLogin: true })
33 );
ts/packages/cli/src/invocation/command-identity.ts
+28 -6
@@ -34,6 +34,9 @@ export type InvocationHookName = (typeof INVOCATION_HOOKS)[number];
34 */
35 export type HookPolicy = boolean | ((input: unknown) => boolean);
36
37 +/** The `dev` group's shared flags (`--user-id`, `--project-name`), by their `CommandSurface` field. */
38 +export type SharedFlagName = 'userId' | 'projectName';
39 +
40 /**
41 * What a command declares about itself, under one annotation key (`Command.annotate`, or
42 * `withCommandMeta`). Every field is optional; what an absent field means is set once, in
@@ -57,6 +60,13 @@ export interface CommandMetaShape {
60 * `HookPolicy`).
61 */
62 readonly hooks?: Partial<Readonly<Record<InvocationHookName, HookPolicy>>>;
63 + /**
64 + * Which of the `dev` group's shared flags the command can honor. Every one can unless the
65 + * command, or a group above it, says `false`; inherited per flag. A flag the command cannot
66 + * honor fails with `CommandInputError` right after the command began, naming the command that
67 + * ran (`src/commands/registration.ts`), instead of being accepted and ignored.
68 + */
69 + readonly sharedFlags?: Partial<Readonly<Record<SharedFlagName, boolean>>>;
70 }
71
72 export const CommandMeta = Context.Reference<CommandMetaShape>('commands/CommandMeta', {
@@ -68,6 +78,8 @@ export interface ResolvedCommandMeta {
78 readonly telemetryFamily: TelemetryFamily;
79 readonly requiresLogin: boolean;
80 readonly hooks: Readonly<Record<InvocationHookName, HookPolicy>>;
81 + /** The shared flags the command cannot honor, declared on itself or on a group above it. */
82 + readonly unsupportedSharedFlags: ReadonlyArray<SharedFlagName>;
83 }
84
85 const EVERY_HOOK: ResolvedCommandMeta['hooks'] = {
@@ -77,6 +89,8 @@ const EVERY_HOOK: ResolvedCommandMeta['hooks'] = {
89 backgroundUpdateCheck: true,
90 };
91
92 +const SHARED_FLAG_NAMES: ReadonlyArray<SharedFlagName> = ['userId', 'projectName'];
93 +
94 /** The hook policies a subcommand inherits from `hooks`: the booleans; a predicate runs the hook. */
95 const inheritedHooks = (hooks: ResolvedCommandMeta['hooks']): ResolvedCommandMeta['hooks'] =>
96 EffectRecord.map(hooks, policy => (Predicate.isBoolean(policy) ? policy : true));
@@ -89,6 +103,12 @@ export const resolveCommandMeta = (
103 telemetryFamily: own.telemetryFamily ?? 'command',
104 requiresLogin: own.requiresLogin ?? parent?.requiresLogin ?? false,
105 hooks: { ...(parent === undefined ? EVERY_HOOK : inheritedHooks(parent.hooks)), ...own.hooks },
106 + unsupportedSharedFlags: SHARED_FLAG_NAMES.filter(flag => {
107 + const declared = own.sharedFlags?.[flag];
108 + return declared === undefined
109 + ? (parent?.unsupportedSharedFlags.includes(flag) ?? false)
110 + : !declared;
111 + }),
112 });
113
114 /** Whether `hook` runs for a command with `meta`, given the input `effect/cli` parsed for it. */
@@ -107,8 +127,9 @@ export const commandMetaOf = (command: Command.Command.Any): CommandMetaShape =>
127
128 /**
129 * Adds `meta` to what `self` already declares in its `CommandMeta` annotation; a hook policy
110 - * replaces only that hook's. `withCommandMeta({ requiresLogin: true })` makes a command, or a
111 - * group entry and every subcommand under it, require a logged-in user.
130 + * replaces only that hook's, and a shared-flag declaration only that flag's.
131 + * `withCommandMeta({ requiresLogin: true })` makes a command, or a group entry and every
132 + * subcommand under it, require a logged-in user.
133 */
134 export const withCommandMeta =
135 (meta: CommandMetaShape) =>
@@ -120,6 +141,7 @@ export const withCommandMeta =
141 ...current,
142 ...meta,
143 hooks: { ...current.hooks, ...meta.hooks },
144 + sharedFlags: { ...current.sharedFlags, ...meta.sharedFlags },
145 });
146 };
147
@@ -140,10 +162,10 @@ export const ROOT_IDENTITY: CommandIdentity = {
162 export const childIdentity = (
163 parent: CommandIdentity,
164 child: Command.Command.Any
143 -): CommandIdentity => ({
144 - path: [...parent.path, child.name],
145 - meta: resolveCommandMeta(parent.meta, commandMetaOf(child)),
146 -});
165 +): CommandIdentity => {
166 + const path = [...parent.path, child.name];
167 + return { path, meta: resolveCommandMeta(parent.meta, commandMetaOf(child)) };
168 +};
169
170 /** The command path as telemetry records it: the names joined by spaces, `composio` for the root. */
171 export const commandPathOf = (identity: CommandIdentity): string =>
ts/packages/cli/src/services/command-hints.ts
-5
@@ -22,7 +22,6 @@ export type CommandHintId =
22 | 'dev.playgroundExecute.getSchema'
23 | 'dev.logs.tools'
24 | 'dev.logs.triggers'
25 - | 'dev.orgs.switch'
25 | 'dev.projects.list'
26 | 'dev.toolkits.list'
27 | 'dev.connectedAccounts.link'
@@ -95,10 +94,6 @@ export const COMMAND_HINTS: Record<CommandHintId, CommandHintNode> = {
94 'dev.logs.triggers': {
95 example: params => `composio dev logs triggers "${getParam(params, 'logId', '<log_id>')}"`,
96 },
98 - 'dev.orgs.switch': {
99 - example: () => 'composio dev orgs switch',
100 - links: ['dev.init', 'dev.projects.list'],
101 - },
97 'dev.projects.list': {
98 example: () => 'composio dev projects list',
99 links: ['dev.init'],
ts/packages/cli/src/services/command-project.ts
+1 -1
@@ -49,7 +49,7 @@ export class ProjectResolutionError extends Data.TaggedError('services/ProjectRe
49 const missingOrg = () =>
50 new ProjectResolutionError({
51 reason: 'missing_org',
52 - message: 'No current org configured. Run `composio login` or `composio dev orgs switch`.',
52 + message: 'No current org configured. Run `composio login` or `composio orgs switch`.',
53 });
54
55 /**
ts/packages/cli/test/__utils__/command-tree.ts new
+48
@@ -0,0 +1,48 @@
1 +import type { Command } from 'effect/cli';
2 +import { buildRootCommand } from 'src/commands';
3 +import type { CommandVisibility } from 'src/commands/feature-tags';
4 +import {
5 + childIdentity,
6 + type CommandIdentity,
7 + ROOT_IDENTITY,
8 +} from 'src/invocation/command-identity';
9 +
10 +/** Developer mode on and every experimental feature enabled: the whole command tree. */
11 +export const EVERY_FEATURE: CommandVisibility = {
12 + isDevModeEnabled: true,
13 + isExperimentalFeatureEnabled: () => true,
14 +};
15 +
16 +/** One command registration of the tree, as `withRegisteredSubcommands` identifies it. */
17 +export interface Registration {
18 + readonly identity: CommandIdentity;
19 + readonly command: Command.Command.Any;
20 + /** The registration, or a group above it, is `Command.unlisted`. */
21 + readonly unlisted: boolean;
22 +}
23 +
24 +const subcommandsOf = (command: Command.Command.Any) =>
25 + command.subcommands.flatMap(group => group.commands);
26 +
27 +/**
28 + * Every registration under `root` (the root first, then depth first in registration order),
29 + * walked through the public `Command` fields only. `help`'s mirror of the tree is left out below
30 + * `help` itself.
31 + */
32 +export const registrationsOf = (
33 + root: Command.Command.Any = buildRootCommand(EVERY_FEATURE)
34 +): ReadonlyArray<Registration> => {
35 + const walk = (
36 + command: Command.Command.Any,
37 + identity: CommandIdentity,
38 + unlisted: boolean
39 + ): ReadonlyArray<Registration> => [
40 + { identity, command, unlisted },
41 + ...(identity.path.length === 1 && identity.path[0] === 'help'
42 + ? []
43 + : subcommandsOf(command).flatMap(child =>
44 + walk(child, childIdentity(identity, child), unlisted || child.unlisted)
45 + )),
46 + ];
47 + return walk(root, ROOT_IDENTITY, false);
48 +};
ts/packages/cli/test/src/commands/command-references.test.ts new
+114
@@ -0,0 +1,114 @@
1 +/**
2 + * Every `composio …` command a user-facing string names (hints, help examples, error messages,
3 + * intros) is a real command registration on the tree it names: `composio dev orgs switch` would
4 + * fail, since `orgs` is a root command only.
5 + *
6 + * Collects the text of every string and template literal under `src/` with the TypeScript
7 + * compiler, finds each `composio <words>` in it, and walks the words down the command tree
8 + * (`test/__utils__/command-tree.ts`). The walk stops at the first word that is not a subcommand;
9 + * the reference is broken when it stopped at a group whose next word looks like a subcommand
10 + * name, or before any command at all, unless that text is prose listed in `NOT_COMMANDS`.
11 + */
12 +import * as fs from 'node:fs';
13 +import * as path from 'node:path';
14 +import { describe, expect, it } from '@effect/vitest';
15 +import type { Command } from 'effect/cli';
16 +import ts from 'typescript';
17 +import { registrationsOf } from 'test/__utils__/command-tree';
18 +
19 +const srcDir = path.resolve(import.meta.dirname, '../../../src');
20 +
21 +const sourceFiles = fs
22 + .readdirSync(srcDir, { recursive: true, encoding: 'utf8' })
23 + .filter(file => /\.tsx?$/.test(file) && !file.endsWith('.d.ts'))
24 + .map(file => path.join(srcDir, file));
25 +
26 +/** The text of every string literal and template literal piece in `file`. */
27 +const literalsOf = (file: string): ReadonlyArray<string> => {
28 + const source = ts.createSourceFile(
29 + file,
30 + fs.readFileSync(file, 'utf8'),
31 + ts.ScriptTarget.Latest,
32 + true
33 + );
34 + const texts: string[] = [];
35 + const visit = (node: ts.Node) => {
36 + if (
37 + ts.isStringLiteral(node) ||
38 + ts.isNoSubstitutionTemplateLiteral(node) ||
39 + ts.isTemplateHead(node) ||
40 + ts.isTemplateMiddle(node) ||
41 + ts.isTemplateTail(node)
42 + ) {
43 + texts.push(node.text);
44 + }
45 + ts.forEachChild(node, visit);
46 + };
47 + visit(source);
48 + return texts;
49 +};
50 +
51 +const REFERENCE = /(?<![\w@/.-])composio((?: [a-z][a-z0-9-]*)+)/g;
52 +
53 +const references = sourceFiles.flatMap(file =>
54 + literalsOf(file).flatMap(text =>
55 + [...text.matchAll(REFERENCE)].map(match => ({
56 + file: path.relative(srcDir, file).split(path.sep).join('/'),
57 + words: match[1]!.trim().split(' '),
58 + }))
59 + )
60 +);
61 +
62 +const root = registrationsOf()[0]!.command;
63 +
64 +const childNamed = (command: Command.Command.Any, word: string) =>
65 + command.subcommands
66 + .flatMap(group => group.commands)
67 + .find(child => child.name === word || child.alias === word);
68 +
69 +/** The command path `words` resolves to, and the first word past it, if any. */
70 +const resolve = (words: ReadonlyArray<string>) => {
71 + const walk = (
72 + command: Command.Command.Any,
73 + names: ReadonlyArray<string>,
74 + rest: ReadonlyArray<string>
75 + ): {
76 + readonly command: Command.Command.Any;
77 + readonly names: ReadonlyArray<string>;
78 + readonly next: string | undefined;
79 + } => {
80 + const [word, ...tail] = rest;
81 + const child = word === undefined ? undefined : childNamed(command, word);
82 + return child === undefined
83 + ? { command, names, next: word }
84 + : walk(child, [...names, child.name], tail);
85 + };
86 + return walk(root, [], words);
87 +};
88 +
89 +/** Prose that reads like a command reference, as `<file>: composio <words>`. */
90 +const NOT_COMMANDS: ReadonlyArray<string> = [
91 + // The approval page's title: "The composio cli wants to execute TOOL".
92 + 'services/tool-permissions.ts: composio cli wants to execute',
93 +];
94 +
95 +const unresolved = references.flatMap(({ file, words }) => {
96 + const { command, names, next } = resolve(words);
97 + const stoppedInGroup =
98 + next !== undefined && (names.length === 0 || command.subcommands.length > 0);
99 + return stoppedInGroup ? [`${file}: composio ${words.join(' ')}`] : [];
100 +});
101 +
102 +describe('command references in user-facing strings', () => {
103 + it('finds the references', () => {
104 + expect(references.length).toBeGreaterThan(100);
105 + });
106 +
107 + it('name real commands on the tree they name', () => {
108 + expect(unresolved.filter(reference => !NOT_COMMANDS.includes(reference))).toEqual([]);
109 + });
110 +
111 + it('lists no prose that is gone', () => {
112 + expect(NOT_COMMANDS.filter(reference => !unresolved.includes(reference))).toEqual([]);
113 + });
114 +});
ts/packages/cli/test/src/commands/commands-map.test.ts new
+149
@@ -0,0 +1,149 @@
1 +/**
2 + * Keeps `src/commands/COMMANDS.md` in step with the command tree: one row per command
3 + * registration, with the file that defines it. `pnpm --filter @composio/cli run commands:map`
4 + * rewrites the file; `pnpm test` fails while it is stale.
5 + *
6 + * A registration's source file is the `.cmd.ts` module that exports its definition, so no command
7 + * declares its own file. A definition is recognised by its name and its `examples` array:
8 + * `effect/cli` 4.0.5 creates that array in `Command.make` and `Command.withExamples` and every
9 + * other combinator (`withRegisteredSubcommands`, `withCommandMeta`, `Command.provide`, …) carries
10 + * it over unchanged, so two definitions with the same name and description (`signup` and
11 + * `agent signup`) stay apart. Should an upgrade copy it, every row fails to match below, loudly.
12 + * Commands assembled by a function rather than exported are listed in `ASSEMBLED`.
13 + */
14 +import * as path from 'node:path';
15 +import { describe, expect, it } from '@effect/vitest';
16 +import { Command } from 'effect/cli';
17 +import * as prettier from 'prettier';
18 +import { buildRootCommand } from 'src/commands';
19 +import { commandPathOf } from 'src/invocation/command-identity';
20 +import { EVERY_FEATURE, type Registration, registrationsOf } from 'test/__utils__/command-tree';
21 +import { collectCommandTests } from '../../../scripts/command-tests';
22 +
23 +const packageRoot = path.resolve(import.meta.dirname, '../../..');
24 +const repoRoot = path.resolve(packageRoot, '../../..');
25 +const commandsDir = path.join(packageRoot, 'src', 'commands');
26 +
27 +const repoPath = (file: string) => path.relative(repoRoot, file).split(path.sep).join('/');
28 +
29 +/** Commands built by a function at assembly time, by command path, with the file that builds them. */
30 +const ASSEMBLED: Readonly<Record<string, string>> = {
31 + dev: 'dev.cmd.ts',
32 + help: 'root-help.ts',
33 +};
34 +
35 +const definitions = await Promise.all(
36 + collectCommandTests(packageRoot).commands.map(async file => {
37 + const module: Record<string, unknown> = await import(path.join(commandsDir, file));
38 + return {
39 + file: repoPath(path.join(commandsDir, file)),
40 + commands: Object.values(module).filter(Command.isCommand),
41 + };
42 + })
43 +);
44 +
45 +const sameDefinition = (a: Command.Command.Any, b: Command.Command.Any) =>
46 + a.name === b.name && a.examples === b.examples;
47 +
48 +/** The `.cmd.ts` file that exports `registration`'s definition, or why there is not one. */
49 +const sourceOf = ({ identity, command }: Registration): string => {
50 + const assembled = ASSEMBLED[identity.path.join(' ')];
51 + if (assembled !== undefined) {
52 + return repoPath(path.join(commandsDir, assembled));
53 + }
54 + const files = [
55 + ...new Set(
56 + definitions
57 + .filter(({ commands }) => commands.some(candidate => sameDefinition(candidate, command)))
58 + .map(({ file }) => file)
59 + ),
60 + ];
61 + if (files.length !== 1) {
62 + throw new Error(
63 + `\`${commandPathOf(identity)}\` matches ${files.length === 0 ? 'no exported command' : files.join(', ')}; export its definition from one .cmd.ts file, or list it in ASSEMBLED.`
64 + );
65 + }
66 + return files[0]!;
67 +};
68 +
69 +const registrations = registrationsOf();
70 +const withoutExperiments = new Set(
71 + registrationsOf(
72 + buildRootCommand({ ...EVERY_FEATURE, isExperimentalFeatureEnabled: () => false })
73 + ).map(({ identity }) => commandPathOf(identity))
74 +);
75 +
76 +const rows = registrations
77 + .map(registration => ({
78 + registration,
79 + path: commandPathOf(registration.identity),
80 + source: sourceOf(registration),
81 + }))
82 + .toSorted((a, b) =>
83 + a.path === 'composio'
84 + ? -1
85 + : b.path === 'composio'
86 + ? 1
87 + : a.path < b.path
88 + ? -1
89 + : a.path > b.path
90 + ? 1
91 + : 0
92 + );
93 +
94 +/** Other registrations of the same definition: a root shortcut and its place in a group. */
95 +const alsoAt = (row: (typeof rows)[number]) =>
96 + rows
97 + .filter(
98 + other => other !== row && sameDefinition(other.registration.command, row.registration.command)
99 + )
100 + .map(other => `\`${other.path}\``)
101 + .join(', ');
102 +
103 +const visibility = ({ registration, path }: (typeof rows)[number]) =>
104 + registration.unlisted ? 'unlisted' : withoutExperiments.has(path) ? 'listed' : 'experimental';
105 +
106 +const code = (text: string | undefined) => (text ? `\`${text}\`` : '');
107 +
108 +const COMMANDS_MD = [
109 + '<!-- Generated from the command tree by `pnpm --filter @composio/cli run commands:map`. Do not edit; `pnpm test` fails while it is stale. -->',
110 + '',
111 + '# Commands',
112 + '',
113 + 'Every command registration of the CLI and the file that defines it. To find a command, grep this file for its path.',
114 + '',
115 + '- **Tree**: `dev` for commands under `composio dev` (developer mode), `root` otherwise.',
116 + '- **Also at**: other registrations of the same definition, such as a root shortcut.',
117 + '- **Login**: the command needs a logged-in user (`requiresLogin`, inherited from its group).',
118 + '- **Visibility**: `unlisted` commands are left out of help but still run; `experimental` ones exist only while their experimental feature is enabled.',
119 + '- `composio help <command>` mirrors every row and is not listed.',
120 + '',
121 + '| Command | Tree | Source | Alias | Also at | Login | Visibility |',
122 + '| --- | --- | --- | --- | --- | --- | --- |',
123 + ...rows.map(row => {
124 + const { registration, path, source } = row;
125 + const cells = [
126 + code(path),
127 + registration.identity.path[0] === 'dev' ? 'dev' : 'root',
128 + code(source),
129 + code(registration.command.alias),
130 + alsoAt(row),
131 + registration.identity.meta.requiresLogin ? 'yes' : 'no',
132 + visibility(row),
133 + ];
134 + return `| ${cells.join(' | ')} |`;
135 + }),
136 + '',
137 +].join('\n');
138 +
139 +describe('src/commands/COMMANDS.md', () => {
140 + it('is current (regenerate with `pnpm --filter @composio/cli run commands:map`)', async () => {
141 + const file = path.join(commandsDir, 'COMMANDS.md');
142 + // Formatted as the commit hook formats Markdown, so a commit leaves the file current.
143 + const formatted = await prettier.format(COMMANDS_MD, {
144 + ...(await prettier.resolveConfig(file)),
145 + filepath: file,
146 + });
147 + await expect(formatted).toMatchFileSnapshot(file);
148 + });
149 +});
ts/packages/cli/test/src/commands/orgs/list/orgs.list.cmd.test.ts
+3 -3
@@ -52,10 +52,10 @@ describe('CLI: composio orgs list', () => {
52 ]),
53 ]);
54 expect(stderr).toEqual([
55 - '-- composio dev orgs list --',
55 + '-- composio orgs list --',
56 'Loaded 2 orgs',
57 ' Other Org (org_0)\n✓ Current Org (org_1)',
58 - '-- Hint: run `composio dev orgs switch` to switch the default global org/project. --',
58 + '-- Hint: run `composio orgs switch` to switch the default global org/project. --',
59 ]);
60 expect(defaultLimit.limits).toEqual([50]);
61 })
@@ -91,7 +91,7 @@ describe('CLI: composio orgs list', () => {
91 expect(stdout).toEqual([]);
92 expect(stderr).toContain('No organizations found.');
93 expect(stderr).not.toContain(
94 - '-- Hint: run `composio dev orgs switch` to switch the default global org/project. --'
94 + '-- Hint: run `composio orgs switch` to switch the default global org/project. --'
95 );
96 })
97 );
ts/packages/cli/test/src/commands/registration.test.ts
+3 -1
@@ -8,6 +8,7 @@ import { Effect, Exit, Option, Ref } from 'effect';
8 import { CliError, Command } from 'effect/cli';
9 import { NotLoggedInError } from 'src/commands/errors';
10 import { withRegisteredSubcommands } from 'src/commands/registration';
11 +import { CommandSurface } from 'src/commands/surface';
12 import { CommandInvocation, commandPathOf, withCommandMeta } from 'src/invocation/command-identity';
13 import { TestLive } from 'test/__utils__';
14
@@ -72,6 +73,7 @@ const traced = (args: ReadonlyArray<string>) =>
73 enter: identity => note(`enter ${commandPathOf(identity)}`),
74 runId: Effect.succeedNone,
75 }),
76 + Effect.provide(CommandSurface.root),
77 Effect.exit
78 );
79 return { exit, trace: yield* Ref.get(trace) };
@@ -186,7 +188,7 @@ describe('effect/cli handler composition', () => {
188
189 // A guard a group pipes on itself wraps its whole dispatch, so it runs before the selected
190 // command is reached: only the registrations entered so far are known. A required login is
189 - // `CommandMeta` for this reason; the `dev` group's `rejectsSharedFlags` guards are not yet.
191 + // `CommandMeta` for this reason, and so is a shared flag a command cannot honor.
192 it.effect('a group-level guard runs before the selected command begins', () =>
193 Effect.gen(function* () {
194 const { exit, trace } = yield* traced(['guarded', 'leaf']);
ts/packages/cli/test/src/commands/surface.test.ts
+72 -23
@@ -1,5 +1,5 @@
1 import { describe, expect, it, layer } from '@effect/vitest';
2 -import { ConfigProvider, Effect, FileSystem, Path } from 'effect';
2 +import { Cause, ConfigProvider, Effect, Exit, FileSystem, Path } from 'effect';
3 import { buildRootCommand } from 'src/commands';
4 import { CommandInputError } from 'src/commands/errors';
5 import { ComposioCliUserConfig } from 'src/services/cli-user-config';
@@ -7,7 +7,14 @@ import { ProjectResolutionError } from 'src/services/command-project';
7 import type { ConnectedAccountItem } from 'src/models/connected-accounts';
8 import { NodeProcess } from 'src/services/node-process';
9 import { ComposioUserContext } from 'src/services/user-context';
10 -import { cli, MockConsole, TestLive } from 'test/__utils__';
10 +import {
11 + cli,
12 + cliExit,
13 + MockConsole,
14 + recordedInvocationCalls,
15 + resetInvocationCalls,
16 + TestLive,
17 +} from 'test/__utils__';
18 import { exitCodeOf } from 'test/__utils__/exit-code';
19 import { makeOrgProject } from 'test/__utils__/models/account';
20
@@ -344,29 +351,58 @@ describe('CommandSurface: playground-execute --parallel finds its command name',
351 });
352
353 // `dev logs tools|triggers` honor --user-id as their filter and reject only --project-name.
354 +// `dev logs`, `dev auth-configs` and `dev projects` declare the flags unsupported for every
355 +// command under them; the message still names the command that ran.
356 const rejectingCommands = [
348 - { path: ['init'], flags: ['--project-name', '--user-id'] },
349 - { path: ['logs', 'tools'], flags: ['--project-name'] },
350 - { path: ['logs', 'triggers'], flags: ['--project-name'] },
351 - { path: ['auth-configs', 'list'], flags: ['--project-name', '--user-id'] },
352 - { path: ['projects', 'list'], flags: ['--project-name', '--user-id'] },
353 - { path: ['toolkits', 'search', 'email'], flags: ['--project-name', '--user-id'] },
354 - { path: ['toolkits', 'version', 'gmail'], flags: ['--project-name', '--user-id'] },
355 - { path: ['connected-accounts', 'info', 'ca_1'], flags: ['--project-name', '--user-id'] },
356 - { path: ['connected-accounts', 'whoami', 'ca_1'], flags: ['--project-name', '--user-id'] },
357 - { path: ['triggers', 'list', 'gmail'], flags: ['--project-name', '--user-id'] },
358 - { path: ['triggers', 'info', 'GMAIL_NEW_GMAIL_MESSAGE'], flags: ['--project-name', '--user-id'] },
359 - { path: ['triggers', 'status'], flags: ['--project-name', '--user-id'] },
357 + { command: ['init'], args: [], flags: ['--project-name', '--user-id'] },
358 + { command: ['logs', 'tools'], args: [], flags: ['--project-name'] },
359 + { command: ['logs', 'triggers'], args: [], flags: ['--project-name'] },
360 + { command: ['auth-configs', 'list'], args: [], flags: ['--project-name', '--user-id'] },
361 + { command: ['projects', 'list'], args: [], flags: ['--project-name', '--user-id'] },
362 + { command: ['toolkits', 'search'], args: ['email'], flags: ['--project-name', '--user-id'] },
363 + { command: ['toolkits', 'version'], args: ['gmail'], flags: ['--project-name', '--user-id'] },
364 {
361 - path: ['triggers', 'create', 'GMAIL_NEW_GMAIL_MESSAGE'],
362 - flags: ['--project-name'],
365 + command: ['connected-accounts', 'info'],
366 + args: ['ca_1'],
367 + flags: ['--project-name', '--user-id'],
368 },
364 - { path: ['triggers', 'enable', 'ti_1'], flags: ['--project-name', '--user-id'] },
365 - { path: ['triggers', 'disable', 'ti_1'], flags: ['--project-name', '--user-id'] },
366 -].flatMap(({ path, flags }) =>
367 - flags.map(flag => ({ path, flag, name: `dev ${path.join(' ')} ${flag}` }))
369 + {
370 + command: ['connected-accounts', 'whoami'],
371 + args: ['ca_1'],
372 + flags: ['--project-name', '--user-id'],
373 + },
374 + { command: ['triggers', 'list'], args: ['gmail'], flags: ['--project-name', '--user-id'] },
375 + {
376 + command: ['triggers', 'info'],
377 + args: ['GMAIL_NEW_GMAIL_MESSAGE'],
378 + flags: ['--project-name', '--user-id'],
379 + },
380 + { command: ['triggers', 'status'], args: [], flags: ['--project-name', '--user-id'] },
381 + { command: ['triggers', 'create'], args: ['GMAIL_NEW_GMAIL_MESSAGE'], flags: ['--project-name'] },
382 + { command: ['triggers', 'enable'], args: ['ti_1'], flags: ['--project-name', '--user-id'] },
383 + { command: ['triggers', 'disable'], args: ['ti_1'], flags: ['--project-name', '--user-id'] },
384 +].flatMap(({ command, args, flags }) =>
385 + flags.flatMap(flag =>
386 + (['before', 'after'] as const).map(position => {
387 + const path = ['dev', ...command].join(' ');
388 + return {
389 + argv:
390 + position === 'before'
391 + ? ['dev', flag, 'other', ...command, ...args]
392 + : ['dev', ...command, ...args, flag, 'other'],
393 + flag,
394 + path,
395 + name: `${path} ${flag} (${position} the command)`,
396 + };
397 + })
398 + )
399 );
400
401 +const rejectionMessage = (command: string, flag: string) =>
402 + flag === '--project-name'
403 + ? `\`composio ${command}\` cannot target another project yet. Remove --project-name, or run it from that project's directory.`
404 + : `\`composio ${command}\` does not act as a user. Remove --user-id.`;
405 +
406 describe('CommandSurface: dev commands that cannot honor a shared flag reject it', () => {
407 layer(
408 TestLive({
@@ -375,13 +411,26 @@ describe('CommandSurface: dev commands that cannot honor a shared flag reject it
411 }),
412 })
413 )(it => {
378 - it.effect.each(rejectingCommands)('rejects `$name`', ({ path, flag }) =>
414 + it.effect.each(rejectingCommands)('rejects `$name`', ({ argv, flag, path }) =>
415 Effect.gen(function* () {
416 const userContext = yield* ComposioUserContext;
417 yield* userContext.login('test_api_key', 'org_test');
382 - const error = yield* Effect.flip(cli(['dev', flag, 'other', ...path]));
418 + yield* resetInvocationCalls;
419 + const { exit, exitCode } = yield* cliExit(argv);
420 + expect(exitCode).toBe(1);
421 + const error = Exit.isFailure(exit) ? Cause.squash(exit.cause) : undefined;
422 expect(error).toBeInstanceOf(CommandInputError);
384 - expect(error).toMatchObject({ option: flag });
423 + expect(error).toMatchObject({
424 + command: path,
425 + option: flag,
426 + message: rejectionMessage(path, flag),
427 + });
428 + const lifecycle = (yield* recordedInvocationCalls).flatMap(call =>
429 + call.service === 'CommandLifecycleTelemetry' && call.event !== 'pluginHintShown'
430 + ? [`${call.event} ${call.context.commandPath}`]
431 + : []
432 + );
433 + expect(lifecycle).toEqual([`invoked ${path}`, `failed ${path}`]);
434 })
435 );
436 });
ts/packages/cli/test/src/commands/triggers/list/triggers.list.cmd.test.ts
+7 -4
@@ -71,9 +71,10 @@ describe('CLI: composio dev triggers list', () => {
71 );
72
73 layer(TestLive({ baseConfigProvider: testConfigProvider, toolkitsData }))(
74 - '[Given] root triggers list with nonexistent toolkit [Then] shows root toolkit hint',
74 + '[Given] root triggers list with nonexistent toolkit [Then] points at search',
75 it => {
76 - it.effect('uses root toolkit command in the no-results hint', () =>
76 + // Toolkits are listed only under `dev`; root users find one through `composio search`.
77 + it.effect('names `composio search` in the invalid-toolkit hint', () =>
78 Effect.gen(function* () {
79 const failure = yield* cli(['triggers', 'list', 'nonexistent']).pipe(Effect.flip);
80 expect(failure).toMatchObject({
@@ -84,8 +85,10 @@ describe('CLI: composio dev triggers list', () => {
85 const lines = yield* MockConsole.getLines({ stripAnsi: true });
86 const output = lines.join('\n');
87
87 - expect(output).toContain('composio toolkits list');
88 - expect(output).not.toContain('composio dev toolkits list');
88 + expect(output).toContain(
89 + 'Find the toolkit for a task with:\n> composio search "<what you want to do>"'
90 + );
91 + expect(output).not.toContain('composio dev');
92 })
93 );
94 }
ts/packages/cli/test/src/invocation/command-identity.test.ts
+2 -2
@@ -168,10 +168,10 @@ describe('lifecycle telemetry from the command identity', () => {
168 family: 'command',
169 outcome: 'failed',
170 },
171 - // `rejectsSharedFlags` on the `logs` group fails before `dev logs tools` is reached.
171 + // The `logs` group declares --project-name unsupported; its subcommand rejects it once it began.
172 {
173 args: ['dev', 'logs', 'tools', '--project-name', 'p'],
174 - path: 'dev logs',
174 + path: 'dev logs tools',
175 family: 'command',
176 outcome: 'failed',
177 },
ts/packages/cli/test/src/invocation/invocation.test.ts
+1 -1
@@ -93,7 +93,7 @@ describe('runInvocation', () => {
93 name: 'connections list without a current org',
94 args: ['connections', 'list'],
95 input: loggedInWithoutOrg,
96 - message: 'No current org configured. Run `composio login` or `composio dev orgs switch`.',
96 + message: 'No current org configured. Run `composio login` or `composio orgs switch`.',
97 },
98 {
99 name: 'dev connected-accounts info without an id',
ts/packages/cli/test/src/services/command-project.test.ts
+1 -1
@@ -85,7 +85,7 @@ describe('resolveCommandProject', () => {
85 expect(error).toBeInstanceOf(ProjectResolutionError);
86 expect(error).toMatchObject({
87 reason: 'missing_org',
88 - message: 'No current org configured. Run `composio login` or `composio dev orgs switch`.',
88 + message: 'No current org configured. Run `composio login` or `composio orgs switch`.',
89 });
90 expect(fetchSpy).not.toHaveBeenCalled();
91 }).pipe(Effect.provide(Layer.mergeAll(singleton, userContext(Option.none()), noLocalProject)))