Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
feat(cli): resolve the agent session a command runs in (#5314)
## Summary This PR: - adds `resolveAgentSession` (`ts/packages/cli/src/services/agent-session.ts`), which answers "which Claude Code or Codex chat is this command part of?", or "none" - derives the agent session ID as the UUID v5 of `<host>:<host session ID>` under a fixed namespace, so the host's own session ID stays inside the resolver - declares the five variables it reads as `HOST_CONFIG.AGENT_SESSION`; `HOST_CONFIG.AGENT_HOST` and `agent_host_env` are unchanged - exports `telemetryDisabled` next to `TELEMETRY_CONFIG` and makes the analytics dispatcher use it in place of its private copy - adds `uniku@^0.7.0` to the CLI for `uniku/uuid/v5` **This PR sends nothing new.** Nothing calls `resolveAgentSession` yet: no analytics property, request header or log line changes. It is the base of a four-PR stack. The next three attach the agent session to analytics events, to first-party requests, and add a compaction count; each of those sends data and waits for the disclosure decision before merge. ## Changes - **Resolution order.** A pair exported by a Composio plugin hook (`COMPOSIO_AGENT_HOST` + `COMPOSIO_AGENT_SESSION_ID`, host `claude` or `codex`) wins, because child processes inherit it and a nested host should report its parent's chat. Otherwise the host's own variable is used: `CLAUDE_CODE_SESSION_ID` for `claude`; `CODEX_SESSION_ID`, then `CODEX_THREAD_ID`, for `codex`. An export with an unknown host or only one of its two variables is ignored. Variables from both hosts with no export resolve none. - **The telemetry gate lives in the resolver.** `resolveAgentSession` returns none when `TELEMETRY_CONFIG.DISABLED` is true (`COMPOSIO_CLI_TELEMETRY_DISABLED`, `COMPOSIO_DISABLE_TELEMETRY`, `TELEMETRY_DISABLED`, `CI`, `NODE_ENV=test`), before it reads any session variable, so later consumers are suppressed by construction. It does not require a PostHog key, which source builds lack. - **`uniku@0.7.0` needs a temporary `minimumReleaseAgeExclude` entry.** It was published on 2026-11-11, inside the three-day `minimumReleaseAge`, and is the first release with `uuid/v5`. The exclusion is for that exact version. Checked by hand: published by GitHub Actions with npm provenance, no install scripts. Without the entry, `pnpm install --frozen-lockfile` fails with `ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION`. It can be removed after 2026-11-14. - **Lockfile.** Updated with `pnpm --filter @composio/cli add`. Besides `uniku` and its `@noble/hashes` dependency, pnpm rewrote the peer suffix of the `@openai/agents` and `@openai/agents-core` 0.21.0 entries (it now lists `supports-color`); no version changed. - **README.** The two hook variables are listed in the table of coordination variables. ## Type of change - [ ] Bug fix - [x] New feature - [x] Refactor/Chore - [ ] Documentation - [ ] Breaking change ## How Has This Been Tested? All run locally from the repository root on the pushed tree: | Check | Command | Result | | --- | --- | --- | | Focused tests | `pnpm --filter @composio/cli exec vitest run test/src/services/agent-session.test.ts test/src/config/host.test.ts test/src/analytics.dispatch.test.ts` | pass, 3 files, 74 tests | | Full CLI suite | `pnpm --filter @composio/cli test` | pass, 225 files, 2977 tests passed, 1 skipped | | CLI typecheck | `pnpm --filter @composio/cli run typecheck` | pass | | Workspace typecheck | `pnpm typecheck` | pass, 14 of 14 tasks | | Effect diagnostics | `pnpm --filter @composio/cli run lint:effect` | pass, 0 errors, 0 warnings | | Lint | `pnpm lint:packages` | pass, 0 errors (38 existing warnings, none in touched files) | | Lint boundaries | `pnpm --filter @composio/cli run validate:boundaries` | pass, 5 registered disables, none added | | Clean install | `pnpm install --frozen-lockfile` | pass | The new suite gives the resolver an isolated `ConfigProvider.fromEnvRecord`, so its results do not depend on the shell that runs it (an agent host's own session variables, `CI`, or `NODE_ENV=test`). The gate tests run each of the five switches against both a host variable and a hook export. Removing the gate makes all ten fail, and skipping it only for the hook export makes the five hook cases fail. The derivation tests use fixed vectors with made-up session IDs. ## Checklist - [ ] I have read the Code of Conduct and this PR adheres to it - [ ] I have read and understand every line of this diff, including any LLM-generated code - [x] Any third-party docs links or promotional content follow the [third-party links policy](https://github.com/ComposioHQ/composio/blob/next/CONTRIBUTING.md#third-party-links-in-docs) - [x] I ran linters/tests locally and they passed - [x] I updated documentation as needed - [x] I added tests or explain why not applicable - [ ] I added a changeset if this change affects published packages No changeset: `@composio/cli` is ignored by Changesets. No `CHANGELOG.md` note either, because nothing user-visible changes until the next PR in the stack. ## Additional context - Both hook values and the host variables are read through `optionalString`, so surrounding whitespace is dropped and a blank value reads as unset. Nothing else is normalized: the same session ID in a different case derives a different ID. - `selectHostSession` and `deriveAgentSessionId` are exported as pure functions so they can be tested directly. Neither reads a telemetry switch; consumers go through `resolveAgentSession`.