The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 15:45 UTC
chore(lint): enforce flatMapConditionalToFilterOrFail (#25082)
Julius Marminge committed
Oct 25, 2026 at 23:01 UTC
931bd53614874db79830ec5bd2bcee4a1f952416
11 files changed
+137
-129
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
+9
-9
@@ -2912,15 +2912,15 @@ export const makeCodexAdapterV2 = Effect.fn("makeCodexAdapterV2")(function* (
2912
: null,
2913
),
2914
Effect.orElseSucceed(() => null),
2915
- Effect.flatMap((response) =>
2916
- response === null
2917
- ? client.raw
2918
- .request("thread/resume", {
2919
- threadId: input.nativeThreadId,
2920
- excludeTurns: true,
2921
- })
2922
- .pipe(Effect.flatMap(decodeCodexChildModel))
2923
- : Effect.succeed(response),
2915
+ Effect.filterOrElse(
2916
+ (response) => !(response === null),
2917
+ (_response) =>
2918
+ client.raw
2919
+ .request("thread/resume", {
2920
+ threadId: input.nativeThreadId,
2921
+ excludeTurns: true,
2922
+ })
2923
+ .pipe(Effect.flatMap(decodeCodexChildModel)),
2924
),
2925
Effect.timeout("5 seconds"),
2926
Effect.flatMap((response) =>
apps/server/src/orchestration-v2/CommandOutputHub.test.ts
+3
-2
@@ -163,8 +163,9 @@ const subscribeFrames = (threadId: ThreadId) =>
163
164
const takeFrame = (frames: Queue.Queue<OrchestrationV2CommandOutputFrame | "ended">) =>
165
Queue.take(frames).pipe(
166
- Effect.flatMap((frame) =>
167
- frame === "ended" ? Effect.die("command output stream ended early") : Effect.succeed(frame),
166
+ Effect.filterOrElse(
167
+ (frame) => !(frame === "ended"),
168
+ (_frame) => Effect.die("command output stream ended early"),
169
),
170
);
171
apps/server/src/orchestration-v2/Orchestrator.ts
+14
-15
@@ -11981,21 +11981,20 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
11981
}
11982
11983
const plan = yield* dispatchOnce(command).pipe(
11984
- Effect.flatMap((planned) =>
11985
- planned.events.length > 0 ||
11986
- command.type === "thread.background-work.settle" ||
11987
- command.type === "thread.stop" ||
11988
- command.type === "subagent.stop" ||
11989
- // A second Stop sharing, or one after the share already ended, is not an error.
11990
- command.type === "thread.guest-share.close"
11991
- ? Effect.succeed(planned)
11992
- : Effect.fail(
11993
- new OrchestratorDispatchError({
11994
- commandId: command.commandId,
11995
- commandType: command.type,
11996
- cause: "Command produced no domain events.",
11997
- }),
11998
- ),
11984
+ Effect.filterOrFail(
11985
+ (planned) =>
11986
+ planned.events.length > 0 ||
11987
+ command.type === "thread.background-work.settle" ||
11988
+ command.type === "thread.stop" ||
11989
+ command.type === "subagent.stop" ||
11990
+ // Closing a share again, or after it ended, is not an error.
11991
+ command.type === "thread.guest-share.close",
11992
+ (_planned) =>
11993
+ new OrchestratorDispatchError({
11994
+ commandId: command.commandId,
11995
+ commandType: command.type,
11996
+ cause: "Command produced no domain events.",
11997
+ }),
11998
),
11999
Effect.catch((cause) =>
12000
Effect.gen(function* () {
apps/server/src/orchestration-v2/ProviderEventIngestor.ts
+1
@@ -830,6 +830,7 @@ export const layer: Layer.Layer<
830
),
831
),
832
),
833
+ // @effect-diagnostics-next-line flatMapConditionalToFilterOrFail:off - The predicate narrows the captured event for the subagent update.
834
Effect.flatMap((storedEvents) =>
835
storedEvents.length === 0 || input.event.type !== "subagent.updated"
836
? Effect.succeed(storedEvents)
apps/server/src/orchestration-v2/ThreadManagementService.ts
+16
-18
@@ -707,15 +707,14 @@ const make = Effect.gen(function* () {
707
cause,
708
}),
709
),
710
- Effect.flatMap((projection) =>
711
- projection.thread.projectId === input.projectId && projection.thread.deletedAt === null
712
- ? Effect.succeed(projection)
713
- : Effect.fail(
714
- new ThreadManagementThreadNotFoundError({
715
- projectId: input.projectId,
716
- threadId: input.threadId,
717
- }),
718
- ),
710
+ Effect.filterOrFail(
711
+ (projection) =>
712
+ projection.thread.projectId === input.projectId && projection.thread.deletedAt === null,
713
+ (_projection) =>
714
+ new ThreadManagementThreadNotFoundError({
715
+ projectId: input.projectId,
716
+ threadId: input.threadId,
717
+ }),
718
),
719
);
720
@@ -734,15 +733,14 @@ const make = Effect.gen(function* () {
733
cause,
734
}),
735
),
737
- Effect.flatMap((projection) =>
738
- projection.thread.projectId === input.projectId && projection.thread.deletedAt === null
739
- ? Effect.succeed(projection)
740
- : Effect.fail(
741
- new ThreadManagementThreadNotFoundError({
742
- projectId: input.projectId,
743
- threadId: input.threadId,
744
- }),
745
- ),
736
+ Effect.filterOrFail(
737
+ (projection) =>
738
+ projection.thread.projectId === input.projectId && projection.thread.deletedAt === null,
739
+ (_projection) =>
740
+ new ThreadManagementThreadNotFoundError({
741
+ projectId: input.projectId,
742
+ threadId: input.threadId,
743
+ }),
744
),
745
);
746
apps/server/src/vcs/GitVcsDriverCore.ts
+3
-2
@@ -3961,8 +3961,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
3961
},
3962
);
3963
return run.pipe(
3964
- Effect.flatMap((result) =>
3965
- result.exitCode !== 0 && isRefLockFailure(result.stderr) ? run : Effect.succeed(result),
3964
+ Effect.filterOrElse(
3965
+ (result) => !(result.exitCode !== 0 && isRefLockFailure(result.stderr)),
3966
+ (_result) => run,
3967
),
3968
);
3969
};
packages/client-runtime/src/state/server.ts
+13
-13
@@ -1275,20 +1275,20 @@ export function createServerEnvironmentAtoms<R, E>(
1275
refreshTrigger: ({ environmentId }) => usageScanSettingsAtom(environmentId),
1276
execute: (input, emit) =>
1277
request(WS_METHODS.serverGetUsageSummary, input).pipe(
1278
- Effect.flatMap((summary) =>
1279
- summary.sources.some((source) => source.refreshing === true)
1280
- ? emit(summary).pipe(
1281
- Effect.andThen(
1282
- request(WS_METHODS.serverGetUsageSummary, { ...input, awaitRefresh: true }),
1283
- ),
1284
- Effect.catch((error) =>
1285
- Effect.logWarning("Could not refresh slow usage sources.").pipe(
1286
- Effect.annotateLogs({ ...safeErrorLogAttributes(error) }),
1287
- Effect.as(summary),
1288
- ),
1278
+ Effect.filterOrElse(
1279
+ (summary) => !summary.sources.some((source) => source.refreshing === true),
1280
+ (summary) =>
1281
+ emit(summary).pipe(
1282
+ Effect.andThen(
1283
+ request(WS_METHODS.serverGetUsageSummary, { ...input, awaitRefresh: true }),
1284
+ ),
1285
+ Effect.catch((error) =>
1286
+ Effect.logWarning("Could not refresh slow usage sources.").pipe(
1287
+ Effect.annotateLogs({ ...safeErrorLogAttributes(error) }),
1288
+ Effect.as(summary),
1289
),
1290
- )
1291
- : Effect.succeed(summary),
1290
+ ),
1291
+ ),
1292
),
1293
),
1294
}),
packages/provider-cursor/src/server/driver.ts
+17
-14
@@ -225,21 +225,24 @@ export const CursorDriver: ProviderDriver<
225
},
226
auth.usesApiKey ? "api-key" : "browser",
227
).pipe(
228
- Effect.flatMap((snapshot) =>
229
- effectiveConfig.enabled &&
230
- snapshot.installed &&
231
- snapshot.auth.status === "authenticated"
232
- ? host.settings.get.pipe(
233
- Effect.flatMap((settings) =>
234
- readCursorUsageLimits(
235
- effectiveConfig,
236
- { ...processEnv, CURSOR_API_KEY: apiKey },
237
- settings.cursorKeychainUsageEnabled,
238
- ),
228
+ Effect.filterOrElse(
229
+ (snapshot) =>
230
+ !(
231
+ effectiveConfig.enabled &&
232
+ snapshot.installed &&
233
+ snapshot.auth.status === "authenticated"
234
+ ),
235
+ (snapshot) =>
236
+ host.settings.get.pipe(
237
+ Effect.flatMap((settings) =>
238
+ readCursorUsageLimits(
239
+ effectiveConfig,
240
+ { ...processEnv, CURSOR_API_KEY: apiKey },
241
+ settings.cursorKeychainUsageEnabled,
242
),
240
- Effect.map((usageLimits) => ({ ...snapshot, usageLimits })),
241
- )
242
- : Effect.succeed(snapshot),
243
+ ),
244
+ Effect.map((usageLimits) => ({ ...snapshot, usageLimits })),
245
+ ),
246
),
247
),
248
),
packages/provider-grok/src/server/driver.ts
+15
-10
@@ -168,16 +168,21 @@ export const GrokDriver: ProviderDriver<GrokSettings, GrokDriverEnv, Path.Path>
168
const textGeneration = yield* makeGrokTextGeneration(effectiveConfig, processEnv);
169
170
const checkProvider = checkGrokProviderStatus(effectiveConfig, processEnv, cwd).pipe(
171
- Effect.flatMap((snapshot) =>
172
- effectiveConfig.enabled && snapshot.installed && snapshot.auth.status === "authenticated"
173
- ? readGrokAccount(processEnv).pipe(
174
- Effect.map(({ email, usageLimits }) => ({
175
- ...snapshot,
176
- auth: email ? { ...snapshot.auth, email } : snapshot.auth,
177
- usageLimits,
178
- })),
179
- )
180
- : Effect.succeed(snapshot),
171
+ Effect.filterOrElse(
172
+ (snapshot) =>
173
+ !(
174
+ effectiveConfig.enabled &&
175
+ snapshot.installed &&
176
+ snapshot.auth.status === "authenticated"
177
+ ),
178
+ (snapshot) =>
179
+ readGrokAccount(processEnv).pipe(
180
+ Effect.map(({ email, usageLimits }) => ({
181
+ ...snapshot,
182
+ auth: email ? { ...snapshot.auth, email } : snapshot.auth,
183
+ usageLimits,
184
+ })),
185
+ ),
186
),
187
Effect.map(stampIdentity),
188
Effect.provideService(HttpClient.HttpClient, httpClient),
packages/source-control-github/src/server/GitHubPullRequestApi.ts
+45
-46
@@ -1578,18 +1578,16 @@ export const make = Effect.gen(function* () {
1578
),
1579
),
1580
listActionRequiredRuns(input).pipe(
1581
- Effect.flatMap((runs) =>
1582
- runs.length > workflowApprovalLimit
1583
- ? Effect.fail(
1584
- new GitHubWorkflowApprovalRefusedError({
1585
- cwd: input.cwd,
1586
- number: input.number,
1587
- reason: "run-list-truncated",
1588
- observedCount: runs.length,
1589
- limit: workflowApprovalLimit,
1590
- }),
1591
- )
1592
- : Effect.succeed(runs),
1581
+ Effect.filterOrFail(
1582
+ (runs) => !(runs.length > workflowApprovalLimit),
1583
+ (runs) =>
1584
+ new GitHubWorkflowApprovalRefusedError({
1585
+ cwd: input.cwd,
1586
+ number: input.number,
1587
+ reason: "run-list-truncated",
1588
+ observedCount: runs.length,
1589
+ limit: workflowApprovalLimit,
1590
+ }),
1591
),
1592
),
1593
],
@@ -1836,40 +1834,41 @@ export const make = Effect.gen(function* () {
1834
(batch) => batch.items.length > 0 || input.cursor !== undefined || hasQuery,
1835
() => read(false),
1836
),
1839
- Effect.flatMap((batch) => {
1840
- if (!stacks || batch.items.length === 0) return Effect.succeed(batch);
1841
- return Effect.forEach(
1842
- batch.items,
1843
- (item) => {
1844
- const lookup = pullRequestLookup({
1845
- repository: input.repository,
1846
- number: item.number,
1847
- });
1848
- if (lookup === null) return Effect.succeed(item);
1849
- return GraphQLResolver.request(lookup, stackMembershipResolver).pipe(
1850
- Effect.map((result) => {
1851
- const pullRequest = result.repository?.pullRequest;
1852
- const stack = pullRequest == null ? undefined : toStackMembership(pullRequest);
1853
- return stack === undefined ? item : { ...item, stack };
1854
- }),
1855
- Effect.catch((error) =>
1856
- Effect.logWarning("Pull request stack membership enrichment failed", {
1857
- operation: "listPullRequestStackMemberships",
1858
- host: input.host,
1859
- error: error._tag,
1860
- }).pipe(Effect.as(item)),
1861
- ),
1862
- );
1863
- },
1864
- { concurrency: "unbounded" },
1865
- ).pipe(
1866
- Effect.provideService(GitHubGraphQlClient.GitHubGraphQlTarget, {
1867
- host: input.host,
1868
- operation: "listPullRequestStackMemberships",
1869
- }),
1870
- Effect.map((items) => ({ ...batch, items })),
1871
- );
1872
- }),
1837
+ Effect.filterOrElse(
1838
+ (batch) => !stacks || batch.items.length === 0,
1839
+ (batch) =>
1840
+ Effect.forEach(
1841
+ batch.items,
1842
+ (item) => {
1843
+ const lookup = pullRequestLookup({
1844
+ repository: input.repository,
1845
+ number: item.number,
1846
+ });
1847
+ if (lookup === null) return Effect.succeed(item);
1848
+ return GraphQLResolver.request(lookup, stackMembershipResolver).pipe(
1849
+ Effect.map((result) => {
1850
+ const pullRequest = result.repository?.pullRequest;
1851
+ const stack = pullRequest == null ? undefined : toStackMembership(pullRequest);
1852
+ return stack === undefined ? item : { ...item, stack };
1853
+ }),
1854
+ Effect.catch((error) =>
1855
+ Effect.logWarning("Pull request stack membership enrichment failed", {
1856
+ operation: "listPullRequestStackMemberships",
1857
+ host: input.host,
1858
+ error: error._tag,
1859
+ }).pipe(Effect.as(item)),
1860
+ ),
1861
+ );
1862
+ },
1863
+ { concurrency: "unbounded" },
1864
+ ).pipe(
1865
+ Effect.provideService(GitHubGraphQlClient.GitHubGraphQlTarget, {
1866
+ host: input.host,
1867
+ operation: "listPullRequestStackMemberships",
1868
+ }),
1869
+ Effect.map((items) => ({ ...batch, items })),
1870
+ ),
1871
+ ),
1872
);
1873
},
1874
tsconfig.base.json
+1
@@ -24,6 +24,7 @@
24
"namespaceImportPackages": ["@effect/platform-node", "effect"],
25
"effectFn": ["span", "inferred-span", "suggested-span"],
26
"diagnosticSeverity": {
27
+ "flatMapConditionalToFilterOrFail": "error",
28
"catchConditionalRefailToCatchIf": "error",
29
"tryCatchInEffectGen": "error",
30
"schemaStructWithTag": "error",