@devries-cameron20 / composio Mirror · read-only / commits / 3a16c75d7
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 09:45 UTC

refactor(cli): use Option combinators in place of isSome ternaries (#4909)

This PR: - Adds an "`Option`: combinators, not `isSome` ternaries" section to the effect-v4 skill (`references/core-patterns.md`, linked from `SKILL.md`): a rewrite table checked against `effect@4.0.3` and two excerpts quoted from code this PR rewrites (`upgradeCmd`, `isTelemetryDebugEnabled`). - Rewrites 13 sites in 12 CLI source files: - 5 × `Option.isSome(o) ? f(o.value) : undefined` → `Option.getOrUndefined(Option.map(o, f))`, each feeding a `?: T` field or return. - 2 × `Option.isSome(o) ? f(o.value) : x` → `Option.match(o, { onNone, onSome })`. - 2 × `Option.isSome(o) ? o.value : yield* fallback` → `yield* Option.match(o, { onSome: Effect.succeed, onNone: () => fallback })`. - 2 × `Option.match(o, { onNone: () => false, ... })` / `Option.isSome(o) && p(o.value)` → `Option.exists(o, p)`. - 1 × `Option.getOrUndefined(o) ?? x` → `Option.getOrElse(o, () => x)`. - 1 × `Option.getOrUndefined(a) ?? Option.getOrUndefined(b)` → `Option.getOrUndefined(Option.orElse(a, () => b))`. - Keeps behaviour the same: same values, fallbacks stay lazy, and effects run on the same branch as before with the same error types. - Leaves 20 candidate sites in 10 files untouched because open CLI PRs (#4897, #4804, #4754, #4745, #4849, #4817, #4900, #4457) change those files. They can follow once those PRs merge. - Leaves `if (Option.isSome(...))` guards and early returns as they are, along with one `isSome && length > 0 ? value : yield* fetch` site in `consumer-short-term-cache.ts` where the combinator form read worse. `cli-keyring`, `json-schema-to-effect-schema`, and the CLI tests had no candidates. ## Context The pattern came up while reviewing #4900 (https://github.com/ComposioHQ/composio/pull/4900). Once #4900 merges, the skill section will also get its examples (`Option.as`, `Option.filter`, `Effect.transposeOption`). This PR has no user-visible effect, so it has no changeset or CHANGELOG line. ## Verification - `pnpm typecheck`: 14/14 tasks successful - `pnpm --filter @composio/cli test`: validators OK (`command tests OK: 57 commands checked against 52 test files, 18 exemptions remaining.`), Vitest 152 files passed, 1676 tests passed, 1 skipped - `pnpm --filter @composio/cli run lint:effect`: 0 errors, 0 warnings - `pnpm --filter @composio/cli exec oxlint <12 touched files>`: 0 warnings, 0 errors - `npx prettier --check <touched files>`: all files formatted - `node .agents/skills/effect-v4/scripts/check-examples.mjs`: all checked blocks compile (5 in core-patterns.md) - `pnpm validate:agent-skills`: 19 skills validated - `pnpm validate:skill-routing`: 19 probes over 19 skills passed

Alberto Schiabel committed Oct 16, 2026 at 00:48 UTC 3a16c75d7388b643b97ee96ec0754f0f6d8ca444
14 files changed +95 -37
.agents/skills/effect-v4/SKILL.md
+2 -1
@@ -19,7 +19,8 @@ See [versions.json](versions.json) for the full matrix (also `typescript`, `vite
19 ## Read next
20
21 - [references/core-patterns.md](references/core-patterns.md) — services, layers, typed
22 - errors, Schema, choosing between `Effect.gen` and `Effect.fn`, driving time in tests with
22 + errors, Schema, choosing between `Effect.gen` and `Effect.fn`, `Option` combinators in
23 + place of `isSome` ternaries, driving time in tests with
24 `TestClock` (fork, adjust until the fiber settles, join) instead of `it.live`, and the v3→v4 rename table
25 (labeled historical, for recognizing stale patterns).
26 - [references/cli-surface.md](references/cli-surface.md) — `effect/cli`:
.agents/skills/effect-v4/references/core-patterns.md
+53
@@ -190,6 +190,59 @@ When in doubt: value → `Effect.gen`; function → a plain arrow returning `Eff
190 upgrading to `Effect.fn` when failure attribution in error reports is worth the annotation.
191 Do not migrate one form to the other wholesale.
192
193 +## `Option`: combinators, not `isSome` ternaries
194 +
195 +Transform an `Option` with the module's combinators instead of unwrapping it with
196 +`Option.isSome(x) ? … x.value … : …` and rebuilding it. The combinator names the intent,
197 +and the `None` branch cannot be forgotten or written twice. Rewrites checked against
198 +`effect@4.0.3` (`ts/vendor/effect/packages/effect/src/Option.ts`, `Effect.ts`):
199 +
200 +| Instead of | Write |
201 +| --------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
202 +| `Option.map(o, () => b)` | `Option.as(o, b)` |
203 +| `cond ? Option.none() : Option.map(o, f)` | `Option.map(Option.filter(o, () => !cond), f)`; filter once into a local when the condition guards several uses |
204 +| `Option.match(o, { onNone: () => true, onSome: a => a === b })` | `Option.isNone(o) \|\| Option.contains(o, b)` (there is no `Option.forAll`) |
205 +| `Option.match(o, { onNone: () => false, onSome: p })`, `Option.isSome(o) && p(o.value)` | `Option.exists(o, p)` |
206 +| `Option.flatMap(Option.filter(o, p), f)` | `pipe(o, Option.filter(p), Option.flatMap(f))` |
207 +| `Option.isSome(o) ? f(o.value) : x` | `Option.match(o, { onNone: () => x, onSome: f })` |
208 +| `Option.isSome(o) ? f(o.value) : undefined` | `Option.getOrUndefined(Option.map(o, f))` |
209 +| `Option.getOrUndefined(o) ?? x` | `Option.getOrElse(o, () => x)` |
210 +| `Option.getOrUndefined(a) ?? Option.getOrUndefined(b)` | `Option.getOrUndefined(Option.orElse(a, () => b))` |
211 +| `Option.isSome(o) ? Option.some(yield* f(o.value)) : Option.none()` | `yield* Effect.transposeOption(Option.map(o, f))` |
212 +| `Option.isSome(o) ? o.value : yield* fallback` | `yield* Option.match(o, { onSome: Effect.succeed, onNone: () => fallback })` |
213 +
214 +The `??` rows are equivalent only while the `Option`'s value type excludes `null` and
215 +`undefined`. Keep fallbacks lazy (`() => x`) so a `None`-only computation or effect still
216 +runs only on `None`.
217 +
218 +Call `Option.getOrUndefined` only where the value leaves for a plain `?: T` parameter. From
219 +`upgradeCmd` in `ts/packages/cli/src/commands/upgrade.cmd.ts`, where `tag` feeds
220 +`upgrade(options: { prerelease?: boolean; tag?: string })`:
221 +
222 +```ts no-check
223 +({ beta, version }) =>
224 + Effect.gen(function* () {
225 + const upgradeBinary = yield* UpgradeBinary;
226 + const tag = Option.getOrUndefined(Option.map(version, normalizeReleaseTag));
227 + const newReleaseTag = yield* upgradeBinary.upgrade({ prerelease: beta, tag });
228 + // ...
229 + });
230 +```
231 +
232 +A fallback lookup that runs only when the `Option` is empty, from `isTelemetryDebugEnabled`
233 +in `ts/packages/cli/src/services/runtime-flags.ts`:
234 +
235 +```ts no-check
236 +export const isTelemetryDebugEnabled: Effect.Effect<boolean> = Effect.gen(function* () {
237 + // ...
238 + const bootstrap = yield* Effect.serviceOption(TelemetryDebugMode);
239 + return yield* Option.match(bootstrap, {
240 + onSome: Effect.succeed,
241 + onNone: () => Effect.orDie(DEBUG_CONFIG.TELEMETRY_DEBUG),
242 + });
243 +});
244 +```
245 +
246 ## Time in tests: drive `TestClock`, never wait on a real clock
247
248 `it.effect` from `@effect/vitest` runs the test on a `TestClock` parked at epoch. Any sleep
ts/packages/cli/src/commands/artifacts.cmd.ts
+4 -3
@@ -12,9 +12,10 @@ const cwdCmd = Command.make('cwd').pipe(
12 Effect.gen(function* () {
13 const ui = yield* TerminalUI;
14 const artifacts = yield* resolveCliSessionArtifacts();
15 - const directoryPath = Option.isSome(artifacts)
16 - ? artifacts.value.directoryPath
17 - : yield* resolveArtifactsRoot;
15 + const directoryPath = yield* Option.match(artifacts, {
16 + onSome: ({ directoryPath }) => Effect.succeed(directoryPath),
17 + onNone: () => resolveArtifactsRoot,
18 + });
19 yield* ui.output(directoryPath, { force: true });
20 })
21 )
ts/packages/cli/src/commands/auth-configs/commands/auth-configs.create.cmd.ts
+5 -3
@@ -71,12 +71,14 @@ export const authConfigsCmd$Create = Command.make(
71 }
72
73 // Parse scopes into array
74 - const scopesList = Option.isSome(scopes)
75 - ? scopes.value
74 + const scopesList = Option.getOrUndefined(
75 + Option.map(scopes, value =>
76 + value
77 .split(',')
78 .map(s => s.trim())
79 .filter(Boolean)
79 - : undefined;
80 + )
81 + );
82
83 // Build create params based on whether auth scheme is provided
84 const nameValue = Option.getOrUndefined(name);
ts/packages/cli/src/commands/auth-configs/commands/auth-configs.list.cmd.ts
+5 -3
@@ -49,9 +49,11 @@ export const authConfigsCmd$List = Command.make(
49 );
50
51 if (result.items.length === 0) {
52 - const hint = Option.isSome(toolkits)
53 - ? `No auth configs found for toolkit "${toolkits.value}". Verify the toolkit slug with:\n> composio dev toolkits list`
54 - : 'No auth configs found. Try broadening your search.';
52 + const hint = Option.match(toolkits, {
53 + onNone: () => 'No auth configs found. Try broadening your search.',
54 + onSome: toolkit =>
55 + `No auth configs found for toolkit "${toolkit}". Verify the toolkit slug with:\n> composio dev toolkits list`,
56 + });
57 yield* ui.log.warn(hint);
58 return;
59 }
ts/packages/cli/src/commands/projects/commands/projects.list.cmd.ts
+1 -1
@@ -27,7 +27,7 @@ export const projectsCmd$List = Command.make('list', { orgId, limit }, ({ orgId,
27 return;
28 }
29
30 - const resolvedOrgId = Option.getOrUndefined(orgId) ?? Option.getOrUndefined(ctx.data.orgId);
30 + const resolvedOrgId = Option.getOrUndefined(Option.orElse(orgId, () => ctx.data.orgId));
31 if (!resolvedOrgId) {
32 yield* ui.log.warn('No current org is configured.');
33 yield* ui.outro('Hint: run `composio orgs switch` first, or pass `--org-id`.');
ts/packages/cli/src/commands/triggers/commands/triggers.status.cmd.ts
+1 -1
@@ -50,7 +50,7 @@ const limit = Flag.Int('limit').pipe(
50 );
51
52 const csvOption = (opt: Option.Option<string>): string[] | undefined =>
53 - Option.isSome(opt) ? parseCsv(opt.value) : undefined;
53 + Option.getOrUndefined(Option.map(opt, parseCsv));
54
55 /**
56 * Display active trigger instances with optional filters.
ts/packages/cli/src/commands/upgrade.cmd.ts
+1 -1
@@ -45,7 +45,7 @@ export const upgradeCmd = Command.make(
45 ({ beta, version }) =>
46 Effect.gen(function* () {
47 const upgradeBinary = yield* UpgradeBinary;
48 - const tag = Option.isSome(version) ? normalizeReleaseTag(version.value) : undefined;
48 + const tag = Option.getOrUndefined(Option.map(version, normalizeReleaseTag));
49 const newReleaseTag = yield* upgradeBinary.upgrade({ prerelease: beta, tag });
50 yield* installSkillSafe({
51 releaseTag: newReleaseTag ?? tag ?? `@composio/cli@${APP_VERSION}`,
ts/packages/cli/src/effects/with-log-level.ts
+2 -3
@@ -8,9 +8,8 @@ import { APP_CONFIG } from 'src/config';
8 */
9 export const setMinimumLogLevel = (logLevelFromCLI: Option.Option<LogLevel.LogLevel>) =>
10 APP_CONFIG.LOG_LEVEL.pipe(
11 - Effect.map(
12 - (logLevelFromEnv): LogLevel.LogLevel =>
13 - Option.getOrUndefined(logLevelFromCLI) ?? logLevelFromEnv ?? 'Info'
11 + Effect.map((logLevelFromEnv): LogLevel.LogLevel =>
12 + Option.getOrElse(logLevelFromCLI, () => logLevelFromEnv ?? 'Info')
13 ),
14 Effect.map(logLevel => Layer.succeed(References.MinimumLogLevel, logLevel)),
15 Layer.unwrap
ts/packages/cli/src/services/agent-host-env.ts
+1 -1
@@ -54,7 +54,7 @@ export const probeHostInstallation = (host: AgentHost) =>
54 // Presence means an actual directory: a file at the config path (or an
55 // unreadable one) must not report the host as installed.
56 const dirInfo = yield* Effect.option(fs.stat(yield* hostConfigDirectory(host)));
57 - const configDirPresent = Option.isSome(dirInfo) && dirInfo.value.type === 'Directory';
57 + const configDirPresent = Option.exists(dirInfo, info => info.type === 'Directory');
58 const found = yield* Effect.forEach(KNOWN_BINARY_PATHS[host], entry =>
59 exists(path.resolve(os.homedir, entry))
60 );
ts/packages/cli/src/services/consumer-short-term-cache.ts
+9 -11
@@ -474,20 +474,18 @@ export const refreshConsumerConnectedToolkitsCache = (params?: {
474 expiresAt: new Date(Date.now() + CACHE_TTL_MS).toISOString(),
475 toolRouterAuthConfigs: mergeAuthConfigMappings({
476 current: currentEntry?.toolRouterAuthConfigs,
477 - next: Option.isSome(directToolkits)
478 - ? {
479 - authConfigs: directToolkits.value.authConfigs,
480 - }
481 - : undefined,
477 + next: Option.getOrUndefined(
478 + Option.map(directToolkits, ({ authConfigs }) => ({ authConfigs }))
479 + ),
480 }),
481 toolRouterConnectedAccounts: mergeConnectedAccountMappings({
482 current: currentEntry?.toolRouterConnectedAccounts,
485 - next: Option.isSome(directToolkits)
486 - ? {
487 - connectedAccounts: directToolkits.value.connectedAccounts,
488 - availableConnectedAccounts: directToolkits.value.availableConnectedAccounts,
489 - }
490 - : undefined,
483 + next: Option.getOrUndefined(
484 + Option.map(directToolkits, ({ connectedAccounts, availableConnectedAccounts }) => ({
485 + connectedAccounts,
486 + availableConnectedAccounts,
487 + }))
488 + ),
489 }),
490 ...searchSessionFields,
491 },
ts/packages/cli/src/services/runtime-flags.ts
+4 -3
@@ -115,7 +115,8 @@ export const isTelemetryDebugEnabled: Effect.Effect<boolean> = Effect.gen(functi
115 const parsed = Option.flatten(yield* Effect.serviceOption(debugSettings['telemetry-debug']));
116 if (Option.isSome(parsed)) return parsed.value;
117 const bootstrap = yield* Effect.serviceOption(TelemetryDebugMode);
118 - return Option.isSome(bootstrap)
119 - ? bootstrap.value
120 - : yield* Effect.orDie(DEBUG_CONFIG.TELEMETRY_DEBUG);
118 + return yield* Option.match(bootstrap, {
119 + onSome: Effect.succeed,
120 + onNone: () => Effect.orDie(DEBUG_CONFIG.TELEMETRY_DEBUG),
121 + });
122 });
ts/packages/cli/src/services/tool-input-validation.ts
+4 -1
@@ -358,7 +358,10 @@ export class ToolInputSchemaCompileError extends Data.TaggedError('ToolInputSche
358
359 const getObjectSchemaProperties = (schema: Record<string, unknown>): ReadonlyArray<string> => {
360 const objectSchema = decodeObjectSchemaWithProperties(schema);
361 - return Option.isSome(objectSchema) ? Object.keys(objectSchema.value.properties) : [];
361 + return Option.match(objectSchema, {
362 + onNone: () => [],
363 + onSome: ({ properties }) => Object.keys(properties),
364 + });
365 };
366
367 const normalizeKey = (value: string) => value.toLowerCase().replace(/[^a-z0-9]/g, '');
ts/packages/cli/src/services/toolkit-slug-catalog.ts
+3 -5
@@ -67,11 +67,9 @@ const refreshInBackgroundIfStale = (
67 ) =>
68 Effect.gen(function* () {
69 const now = yield* DateTime.now;
70 - const isFresh = Option.match(learned, {
71 - onNone: () => false,
72 - onSome: known =>
73 - Duration.isLessThan(DateTime.distance(known.refreshedAt, now), REFRESH_AFTER),
74 - });
70 + const isFresh = Option.exists(learned, known =>
71 + Duration.isLessThan(DateTime.distance(known.refreshedAt, now), REFRESH_AFTER)
72 + );
73
74 if (isFresh) return;
75