@devries-cameron20 / composio Mirror · read-only / commits / b7177d6b8
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, 06:00 UTC

chore(ci): enforce ast-grep anti-slop checks (#5284)

This PR: - adds seven ast-grep rules for TypeScript SDKs/CLI, Python SDKs/providers, maintenance scripts, and CI YAML - flags double assertions, unchecked type ignores, swallowed errors, unconditional CI soft failures, and empty run steps - records 86 existing findings by rule, file, full matched source lines, and occurrence count; rejects new findings and stale allowances - provides a prune command that removes resolved allowances and refuses to add new ones - rejects blanket and unused suppressions, and documents justified exceptions and scan scope - runs the checks through `pnpm lint` and a dedicated job in Agent Substrate CI - declares the ast-grep lifecycle-script policy and installs the lint job with `--ignore-scripts` ## Validation - `CI=true pnpm install --frozen-lockfile` in a fresh detached checkout: passes with pnpm 11.8.0; installation with `--ignore-scripts` also passes - Ruff check and format checks pass for the telemetry suppression; its best-effort runtime behavior is unchanged - `pnpm test:antislop`: seven rule fixture suites and two enforcement tests pass, including hidden workflow discovery, generated/test exclusions, duplicate counts, line shifts, suppression handling, scan failures, and pruning - `pnpm run lint`: passes with existing Oxlint warnings; anti-slop reports no new findings - `actionlint .github/workflows/agent-substrate.yml`: passes - Prettier checks on all changed source, configuration, documentation, and fixtures pass - `bun run validate:agent-skills` and `bun run validate:skill-routing`: pass Inspired by [hd-lang's ast-grep controls](https://github.com/HerringtonDarkholme/hd-lang/tree/main/.ast-grep). Existing findings are adoption debt, not approved patterns. Generated code, dependencies, build output, and tests are excluded; Python examples remain covered. <!-- sdk-release-note-exempt: Internal lint rules, fixtures, and CI wiring only; published SDK behavior is unchanged. -->

Alberto Schiabel committed Nov 9, 2026 at 22:51 UTC b7177d6b82b0785839fec3df03a5786bf1da0bf3
24 files changed +1241 -3
.ast-grep/baseline.json new
+518
@@ -0,0 +1,518 @@
1 +[
2 + {
3 + "ruleId": "py-empty-except",
4 + "file": "python/composio/utils/redaction.py",
5 + "source": " except Exception:\n pass",
6 + "count": 1
7 + },
8 + {
9 + "ruleId": "py-empty-except",
10 + "file": "python/composio/utils/schema_converter.py",
11 + "source": " except Exception: # noqa: BLE001 - pydantic raises SchemaError subclasses\n pass",
12 + "count": 1
13 + },
14 + {
15 + "ruleId": "py-empty-except",
16 + "file": "python/composio/utils/schema_converter.py",
17 + "source": " except Exception:\n pass",
18 + "count": 1
19 + },
20 + {
21 + "ruleId": "py-empty-except",
22 + "file": "python/providers/typesafe/composio_typesafe/companion.py",
23 + "source": " except Exception:\n pass",
24 + "count": 1
25 + },
26 + {
27 + "ruleId": "py-unchecked-ignore",
28 + "file": "python/composio/client/__init__.py",
29 + "source": " import google.colab # type: ignore # noqa: F401",
30 + "count": 1
31 + },
32 + {
33 + "ruleId": "py-unchecked-ignore",
34 + "file": "python/composio/client/__init__.py",
35 + "source": " shell = get_ipython().__class__.__name__ # type: ignore # noqa: F821",
36 + "count": 1
37 + },
38 + {
39 + "ruleId": "py-unchecked-ignore",
40 + "file": "python/composio/core/models/_modifiers.py",
41 + "source": " return self.modifier(tool, toolkit, data) # type: ignore",
42 + "count": 1
43 + },
44 + {
45 + "ruleId": "py-unchecked-ignore",
46 + "file": "python/composio/core/models/_modifiers.py",
47 + "source": " return self.modifier(tool, toolkit, data) # type: ignore",
48 + "count": 1
49 + },
50 + {
51 + "ruleId": "py-unchecked-ignore",
52 + "file": "python/composio/core/models/auth_configs.py",
53 + "source": " type=options[\"type\"], # type: ignore",
54 + "count": 1
55 + },
56 + {
57 + "ruleId": "py-unchecked-ignore",
58 + "file": "python/composio/core/models/base.py",
59 + "source": " \"environment\": _environment, # type: ignore",
60 + "count": 1
61 + },
62 + {
63 + "ruleId": "py-unchecked-ignore",
64 + "file": "python/composio/core/models/base.py",
65 + "source": " return {k: v for k, v in payload.items()} # type: ignore",
66 + "count": 1
67 + },
68 + {
69 + "ruleId": "py-unchecked-ignore",
70 + "file": "python/composio/core/models/mcp.py",
71 + "source": " response.generate = generate # type: ignore",
72 + "count": 1
73 + },
74 + {
75 + "ruleId": "py-unchecked-ignore",
76 + "file": "python/composio/utils/openapi.py",
77 + "source": " return t.List[SubT] # type: ignore",
78 + "count": 1
79 + },
80 + {
81 + "ruleId": "py-unchecked-ignore",
82 + "file": "python/composio/utils/schema_converter.py",
83 + "source": " return t.List[t.cast(t.Type, item_type)] # type: ignore",
84 + "count": 1
85 + },
86 + {
87 + "ruleId": "py-unchecked-ignore",
88 + "file": "python/composio/utils/schema_converter.py",
89 + "source": " return t.Optional[t.cast(t.Type, base_type)] # type: ignore",
90 + "count": 1
91 + },
92 + {
93 + "ruleId": "py-unchecked-ignore",
94 + "file": "python/composio/utils/schema_converter.py",
95 + "source": " return t.Optional[union_type] # type: ignore",
96 + "count": 1
97 + },
98 + {
99 + "ruleId": "py-unchecked-ignore",
100 + "file": "python/composio/utils/schema_converter.py",
101 + "source": " union_type = reduce(lambda a, b: t.Union[a, b], cast_types) # type: ignore",
102 + "count": 1
103 + },
104 + {
105 + "ruleId": "py-unchecked-ignore",
106 + "file": "python/composio/utils/shared.py",
107 + "source": " Field(**field), # type: ignore",
108 + "count": 1
109 + },
110 + {
111 + "ruleId": "py-unchecked-ignore",
112 + "file": "python/composio/utils/shared.py",
113 + "source": " base_model = create_model(model_name, **field_definitions) # type: ignore",
114 + "count": 1
115 + },
116 + {
117 + "ruleId": "py-unchecked-ignore",
118 + "file": "python/composio/utils/shared.py",
119 + "source": " model = create_model( # type: ignore",
120 + "count": 1
121 + },
122 + {
123 + "ruleId": "py-unchecked-ignore",
124 + "file": "python/composio/utils/shared.py",
125 + "source": " return field_definitions # type: ignore",
126 + "count": 1
127 + },
128 + {
129 + "ruleId": "py-unchecked-ignore",
130 + "file": "python/examples/fastapi_app.py",
131 + "source": " return RedirectResponse(url=connection_request.redirect_url) # type: ignore",
132 + "count": 1
133 + },
134 + {
135 + "ruleId": "py-unchecked-ignore",
136 + "file": "python/examples/modifiers.py",
137 + "source": " params[\"custom_auth_params\"][\"parameters\"].append( # type: ignore",
138 + "count": 1
139 + },
140 + {
141 + "ruleId": "py-unchecked-ignore",
142 + "file": "python/providers/gemini/composio_gemini/provider.py",
143 + "source": " action_func.__signature__ = Signature(parameters=sig_params) # type: ignore",
144 + "count": 1
145 + },
146 + {
147 + "ruleId": "py-unchecked-ignore",
148 + "file": "python/providers/gemini/composio_gemini/provider.py",
149 + "source": " genai_types = None # type: ignore",
150 + "count": 1
151 + },
152 + {
153 + "ruleId": "py-unchecked-ignore",
154 + "file": "python/providers/langchain/composio_langchain/provider.py",
155 + "source": " action_func.__signature__ = Signature( # type: ignore",
156 + "count": 1
157 + },
158 + {
159 + "ruleId": "py-unchecked-ignore",
160 + "file": "python/providers/langgraph/composio_langgraph/provider.py",
161 + "source": " action_func.__signature__ = Signature( # type: ignore",
162 + "count": 1
163 + },
164 + {
165 + "ruleId": "py-unchecked-ignore",
166 + "file": "python/providers/langgraph/langgraph_demo_toolnode.py",
167 + "source": " ( # type: ignore",
168 + "count": 1
169 + },
170 + {
171 + "ruleId": "py-unchecked-ignore",
172 + "file": "python/providers/langgraph/langgraph_demo_toolnode.py",
173 + "source": " if last_message.tool_calls: # type: ignore",
174 + "count": 1
175 + },
176 + {
177 + "ruleId": "py-unchecked-ignore",
178 + "file": "python/providers/langgraph/langgraph_demo.py",
179 + "source": "for output in app.stream(inputs): # type: ignore",
180 + "count": 1
181 + },
182 + {
183 + "ruleId": "py-unchecked-ignore",
184 + "file": "python/providers/llamaindex/composio_llamaindex/provider.py",
185 + "source": " action_func.__signature__ = Signature( # type: ignore",
186 + "count": 1
187 + },
188 + {
189 + "ruleId": "ts-double-assertion",
190 + "file": "ts/packages/cli-keyring/src/stores/macos-security-ffi.ts",
191 + "source": " const ab = toArrayBuffer(address as unknown as never, 0, 8);",
192 + "count": 1
193 + },
194 + {
195 + "ruleId": "ts-double-assertion",
196 + "file": "ts/packages/cli-keyring/src/stores/macos-security-ffi.ts",
197 + "source": " const view = new Uint8Array(toArrayBuffer(Number(bytePtr) as unknown as never, 0, length));",
198 + "count": 1
199 + },
200 + {
201 + "ruleId": "ts-double-assertion",
202 + "file": "ts/packages/cli/src/commands/registration.ts",
203 + "source": " const command = child as unknown as Command.Command<string, unknown, unknown, unknown, unknown>;",
204 + "count": 1
205 + },
206 + {
207 + "ruleId": "ts-double-assertion",
208 + "file": "ts/packages/cli/src/commands/registration.ts",
209 + "source": " return Command.provideEffect(\n begun,\n CommandRegistration,\n Effect.gen(function* () {\n const identity = childIdentity(yield* CommandRegistration, command);\n const invocation = yield* CommandInvocation;\n yield* invocation.enter(identity);\n return identity;\n })\n ) as unknown as Registered<C>;",
210 + "count": 1
211 + },
212 + {
213 + "ruleId": "ts-double-assertion",
214 + "file": "ts/packages/cli/src/generation/typescript/generate-type-from-json-schema.ts",
215 + "source": " const openApi3Definition = {\n openapi: '3.1.0',\n components: {\n schemas: {\n [name]: {\n type: 'object',\n properties: processedProperties,\n },\n },\n },\n } as unknown as OpenAPI3;",
216 + "count": 1
217 + },
218 + {
219 + "ruleId": "ts-double-assertion",
220 + "file": "ts/packages/core/src/errors/ComposioError.ts",
221 + "source": " const { cause, code, stack, statusCode, meta, possibleFixes } = this as unknown as {\n cause: unknown;\n code: string | undefined;\n stack: string | undefined;\n statusCode: number | undefined;\n meta: Record<string, unknown> | undefined;\n possibleFixes: string[] | undefined;\n };",
222 + "count": 1
223 + },
224 + {
225 + "ruleId": "ts-double-assertion",
226 + "file": "ts/packages/core/src/models/Triggers.ts",
227 + "source": " originalPayload: payload as unknown as Record<string, unknown>,",
228 + "count": 1
229 + },
230 + {
231 + "ruleId": "ts-double-assertion",
232 + "file": "ts/packages/core/src/telemetry/Telemetry.ts",
233 + "source": " (instance as unknown as Record<string, Function>)[name] = async (...args: unknown[]) => {",
234 + "count": 1
235 + },
236 + {
237 + "ruleId": "ts-double-assertion",
238 + "file": "ts/packages/core/src/telemetry/Telemetry.ts",
239 + "source": " const originalMethod = (instance as unknown as Record<string, Function>)[name] as (",
240 + "count": 1
241 + },
242 + {
243 + "ruleId": "ts-double-assertion",
244 + "file": "ts/packages/core/src/utils/pinnedDispatcher.node.ts",
245 + "source": " const slots = globalThis as unknown as Record<symbol, { constructor?: { name?: string } }>;",
246 + "count": 1
247 + },
248 + {
249 + "ruleId": "ts-double-assertion",
250 + "file": "ts/packages/json-schema-to-zod/src/backend/zod-v3.ts",
251 + "source": " tuple: (items, rest) => buildTuple<S>(z.tuple(items as unknown as [S]), rest),",
252 + "count": 1
253 + },
254 + {
255 + "ruleId": "ts-double-assertion",
256 + "file": "ts/packages/json-schema-to-zod/src/backend/zod-v3.ts",
257 + "source": " union: options => z.union(options as unknown as [S, S]),",
258 + "count": 1
259 + },
260 + {
261 + "ruleId": "ts-double-assertion",
262 + "file": "ts/packages/json-schema-to-zod/src/backend/zod-v4.ts",
263 + "source": " payload.issues.push({\n input: payload.value,\n continue: true,\n ...issue,\n } as unknown as z.core.$ZodRawIssue)",
264 + "count": 1
265 + },
266 + {
267 + "ruleId": "ts-double-assertion",
268 + "file": "ts/packages/json-schema-to-zod/src/backend/zod-v4.ts",
269 + "source": " sinkFor(issue => ctx.addIssue(issue as unknown as z.core.$ZodRawIssue))",
270 + "count": 1
271 + },
272 + {
273 + "ruleId": "ts-double-assertion",
274 + "file": "ts/packages/json-schema-to-zod/src/backend/zod-v4.ts",
275 + "source": " zod.constr = Instrumented as unknown as SchemaConstructor;",
276 + "count": 1
277 + },
278 + {
279 + "ruleId": "ts-double-assertion",
280 + "file": "ts/packages/json-schema-to-zod/src/backend/zod-v4.ts",
281 + "source": " const constructor = Instrumented as unknown as SchemaConstructor;",
282 + "count": 1
283 + },
284 + {
285 + "ruleId": "ts-double-assertion",
286 + "file": "ts/packages/json-schema-to-zod/src/backend/zod-v4.ts",
287 + "source": " tuple: (items, rest) => buildTuple<S>(z.tuple(items as unknown as [S]), rest),",
288 + "count": 1
289 + },
290 + {
291 + "ruleId": "ts-double-assertion",
292 + "file": "ts/packages/json-schema-to-zod/src/backend/zod-v4.ts",
293 + "source": " union: options => z.union(options as unknown as [S, S]),",
294 + "count": 1
295 + },
296 + {
297 + "ruleId": "ts-double-assertion",
298 + "file": "ts/packages/json-schema-to-zod/src/backend/zod-v4.ts",
299 + "source": "const internals = (schema: S): Internals => (schema as unknown as { _zod: Internals })._zod;",
300 + "count": 1
301 + },
302 + {
303 + "ruleId": "ts-double-assertion",
304 + "file": "ts/packages/json-schema-to-zod/src/parsers/parse-array.ts",
305 + "source": " variants.length === 1 ? variants[0] : backend.union(variants as unknown as [S, S, ...S[]]);",
306 + "count": 1
307 + },
308 + {
309 + "ruleId": "ts-double-assertion",
310 + "file": "ts/packages/json-schema-to-zod/src/parsers/parse-literal-values.ts",
311 + "source": " return backend.union(primitives.map(value => backend.literal(value)) as unknown as [S, S]);",
312 + "count": 1
313 + },
314 + {
315 + "ruleId": "ts-double-assertion",
316 + "file": "ts/packages/json-schema-to-zod/src/utils/extend-schema.ts",
317 + "source": " const errorMessage = (jsonSchema as unknown as { errorMessage?: Record<string, string> })",
318 + "count": 1
319 + },
320 + {
321 + "ruleId": "ts-double-assertion",
322 + "file": "ts/packages/json-schema-to-zod/src/utils/its.ts",
323 + "source": " (x as unknown as { nullable: boolean }).nullable === true,",
324 + "count": 1
325 + },
326 + {
327 + "ruleId": "ts-double-assertion",
328 + "file": "ts/packages/providers/claude-agent-sdk/src/index.ts",
329 + "source": " const defineTool = sdkTool as unknown as (\n name: string,\n description: string,\n inputSchema: ZodType,\n handler: (\n args: Record<string, unknown>\n ) => Promise<{ content: Array<{ type: 'text'; text: string }> }>\n ) => ClaudeAgentTool;",
330 + "count": 1
331 + },
332 + {
333 + "ruleId": "ts-double-assertion",
334 + "file": "ts/packages/providers/cloudflare/src/index.ts",
335 + "source": " parameters: inputParameters as unknown as {\n type: 'object';\n properties: {\n [key: string]: {\n type: string;\n description?: string;\n };\n };\n required: string[];\n },",
336 + "count": 1
337 + },
338 + {
339 + "ruleId": "ts-double-assertion",
340 + "file": "ts/packages/providers/google/src/index.ts",
341 + "source": " parameters: {\n type: 'object',\n description: tool.description || '',\n properties: inputParameters?.properties || {},\n required: inputParameters?.required || [],\n } as unknown as Schema,",
342 + "count": 1
343 + },
344 + {
345 + "ruleId": "ts-double-assertion",
346 + "file": "ts/packages/providers/llamaindex/src/index.ts",
347 + "source": " return new FunctionTool(\n execute,\n {\n name: tool.slug,\n description: tool.description ?? tool.name ?? '',\n parameters: parameters as LlamaindexToolParameters,\n },\n jsonSchemaToZodSchema(parameters)\n ) as unknown as LlamaindexTool;",
348 + "count": 1
349 + },
350 + {
351 + "ruleId": "ts-empty-catch",
352 + "file": "scripts/agent-task.ts",
353 + "source": " } catch {}",
354 + "count": 1
355 + },
356 + {
357 + "ruleId": "ts-empty-catch",
358 + "file": "ts/packages/cli-keyring/src/stores/macos-security-ffi.ts",
359 + "source": " } catch {\n // Spawn failure is fine — entry may not exist.\n }",
360 + "count": 1
361 + },
362 + {
363 + "ruleId": "ts-empty-catch",
364 + "file": "ts/packages/cli-keyring/src/stores/macos-security-subprocess.ts",
365 + "source": " } catch {\n // Spawn failure (e.g. /usr/bin/security missing) — the add\n // below will hit the same failure and surface it properly.\n }",
366 + "count": 1
367 + },
368 + {
369 + "ruleId": "ts-empty-catch",
370 + "file": "ts/packages/core/scripts/generate-docs.ts",
371 + "source": " } catch {\n // Directory doesn't exist, that's fine\n }",
372 + "count": 1
373 + },
374 + {
375 + "ruleId": "ts-empty-catch",
376 + "file": "ts/packages/core/scripts/generate-docs.ts",
377 + "source": " } catch {\n // Ignore cleanup errors\n }",
378 + "count": 1
379 + },
380 + {
381 + "ruleId": "ts-empty-catch",
382 + "file": "ts/packages/core/src/platform/node.ts",
383 + "source": " } catch {\n // Walk toward the filesystem root until an existing directory is found.\n }",
384 + "count": 1
385 + },
386 + {
387 + "ruleId": "ts-empty-catch",
388 + "file": "ts/packages/core/src/utils/sensitiveFileUploadPaths.ts",
389 + "source": " } catch {\n // If realpath fails (e.g. race), use resolved path\n }",
390 + "count": 1
391 + },
392 + {
393 + "ruleId": "ts-empty-catch",
394 + "file": "ts/packages/core/src/utils/toolkitDeprecation.ts",
395 + "source": " } catch {\n // The fallback is best-effort too: a sink that throws must not fail the call.\n }",
396 + "count": 1
397 + },
398 + {
399 + "ruleId": "ts-empty-catch",
400 + "file": "ts/packages/core/src/utils/uploadDirAllowlist.node.ts",
401 + "source": " } catch {\n // ignore and fall through\n }",
402 + "count": 1
403 + },
404 + {
405 + "ruleId": "ts-empty-catch",
406 + "file": "ts/packages/core/src/utils/uploadDirAllowlist.node.ts",
407 + "source": " } catch {\n // ignore\n }",
408 + "count": 1
409 + },
410 + {
411 + "ruleId": "ts-empty-catch",
412 + "file": "ts/packages/core/src/utils/version.ts",
413 + "source": " } catch (_error) {\n // Ignore and do nothing\n }",
414 + "count": 1
415 + },
416 + {
417 + "ruleId": "yaml-continue-on-error",
418 + "file": ".github/workflows/build-cli-binaries.yml",
419 + "source": " - name: Check baked toolkit slugs freshness\n continue-on-error: true\n run: |\n set -euo pipefail\n refreshed_at=$(sed -n \"s/.*BAKED_TOOLKIT_SLUGS_REFRESHED_AT = '\\(.*\\)'.*/\\1/p\" \\\n ts/packages/cli/src/generated/toolkit-slugs.ts)\n age_days=$(( ( $(date -u +%s) - $(date -u -d \"$refreshed_at\" +%s) ) / 86400 ))\n echo \"Baked toolkit slugs were refreshed $age_days day(s) ago ($refreshed_at).\"\n if [ \"$age_days\" -gt 14 ]; then\n echo \"::warning::Baked toolkit slugs are $age_days days old. Run the 'CLI - Update Toolkit Slugs' workflow.\"\n fi",
420 + "count": 1
421 + },
422 + {
423 + "ruleId": "yaml-continue-on-error",
424 + "file": ".github/workflows/docs-agent-eval.yml",
425 + "source": " - name: Run exact-HEAD docs agent eval\n if: steps.extent.outputs.extent != 'none'\n continue-on-error: true\n working-directory: engine\n env:\n GITHUB_TOKEN: ${{ github.token }}\n run: |\n RUNMODE=Smoke\n [ '${{ steps.extent.outputs.extent }}' = deep ] && RUNMODE=Deep\n python ci/run_full_eval.py \\\n --repo \"$SOURCE_REPO\" \\\n --head-sha '${{ steps.extent.outputs.head_sha }}' \\\n --mode \"$RUNMODE\"",
426 + "count": 1
427 + },
428 + {
429 + "ruleId": "yaml-continue-on-error",
430 + "file": ".github/workflows/docs-check-links.yml",
431 + "source": " - name: Open tracking issue on failure\n if: failure() && github.event_name != 'pull_request'\n continue-on-error: true\n # Override the job-level `./docs` default: that path only exists after\n # checkout, and a pre-checkout failure would otherwise leave the runner\n # unable to start this shell, silently losing the alert.\n working-directory: ${{ github.workspace }}\n env:\n GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n GH_REPO: ${{ github.repository }}\n LABEL: docs-external-links-failure\n RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n EVENT_NAME: ${{ github.event_name }}\n run: |\n gh label create \"$LABEL\" \\\n --color B60205 \\\n --description \"Nightly docs external-link check is failing\" 2>/dev/null || true\n\n existing=$(gh issue list --label \"$LABEL\" --state open --limit 1 --json number --jq '.[0].number // empty')\n if [ -n \"$existing\" ]; then\n echo \"Issue #$existing is already open for this failure; not filing a duplicate.\"\n exit 0\n fi\n\n gh issue create \\\n --title \"Nightly docs external-link check is failing\" \\\n --label \"$LABEL\" \\\n --body \"The scheduled \\`Docs - Check Links\\` external sweep failed.\n\n - Run: $RUN_URL\n - Trigger: \\`$EVENT_NAME\\`\n\n The failing URLs are listed in the run log. External links only fail on\n evidence they are dead (404/410, or repeated network errors), so this\n usually means a linked page moved or was taken down — fix or remove the\n link in \\`docs/content\\`.\"\n",
432 + "count": 1
433 + },
434 + {
435 + "ruleId": "yaml-continue-on-error",
436 + "file": ".github/workflows/docs-rebuild-kb-semantic.yml",
437 + "source": " - name: Check semantic artifact freshness\n id: freshness\n continue-on-error: true\n run: bun run check:kb-semantic",
438 + "count": 1
439 + },
440 + {
441 + "ruleId": "yaml-continue-on-error",
442 + "file": ".github/workflows/docs-update-data.yml",
443 + "source": " - name: Close tracking issue on recovery\n if: success()\n continue-on-error: true\n env:\n GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n GH_REPO: ${{ github.repository }}\n LABEL: docs-data-sync-failure\n run: |\n existing=$(gh issue list --label \"$LABEL\" --state open --limit 1 \\\n --json number --jq '.[0].number // empty')\n if [ -n \"$existing\" ]; then\n gh issue close \"$existing\" \\\n --comment \"The docs data sync recovered in run ${{ github.run_id }}: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}.\"\n fi\n\n # A verifier crash is a tooling failure, not evidence that published guides\n # contradict production. Track it separately and close it after the verifier\n # returns either of its expected outcomes: clean (0) or findings (1).",
444 + "count": 1
445 + },
446 + {
447 + "ruleId": "yaml-continue-on-error",
448 + "file": ".github/workflows/docs-update-data.yml",
449 + "source": " - name: Generate read-only KB source token\n id: source-token\n continue-on-error: true\n uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0\n with:\n client-id: ${{ vars.RELEASE_BOT_CLIENT_ID }}\n private-key: ${{ secrets.RELEASE_BOT_APP_PRIVATE_KEY }}\n owner: ComposioHQ\n repositories: support-knowledge\n permission-contents: read",
450 + "count": 1
451 + },
452 + {
453 + "ruleId": "yaml-continue-on-error",
454 + "file": ".github/workflows/docs-update-data.yml",
455 + "source": " - name: Open tracking issue on failure\n if: failure()\n continue-on-error: true\n # Override the job-level `./docs` default. That path only exists after\n # checkout, so a failure before it (e.g. the app-token step) would leave\n # the runner unable to start this shell — and continue-on-error would\n # swallow that, losing the alert for precisely the earliest failures.\n working-directory: ${{ github.workspace }}\n env:\n GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n GH_REPO: ${{ github.repository }}\n LABEL: docs-data-sync-failure\n RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n EVENT_NAME: ${{ github.event_name }}\n run: |\n gh label create \"$LABEL\" \\\n --color B60205 \\\n --description \"Scheduled docs data sync is failing\" 2>/dev/null || true\n\n existing=$(gh issue list --label \"$LABEL\" --state open --limit 1 --json number --jq '.[0].number // empty')\n if [ -n \"$existing\" ]; then\n echo \"Issue #$existing is already open for this failure; not filing a duplicate.\"\n exit 0\n fi\n\n gh issue create \\\n --title \"Docs data sync is failing\" \\\n --label \"$LABEL\" \\\n --body \"The scheduled \\`Docs - Update Data\\` workflow failed.\n\n - Run: $RUN_URL\n - Trigger: \\`$EVENT_NAME\\`\n\n **Impact:** while this is red, \\`docs/public/data/toolkits.json\\` stops being\n refreshed. docs.composio.dev/toolkits is statically generated from that file, so\n toolkits added to production after the last successful run have no page and\n return 404. The site stays up, which is why this fails silently.\n\n **First thing to check:** the \\`COMPOSIO_DOCS_API_KEY\\` secret must have\n **production** read access against \\`backend.composio.dev\\`. Note this job does\n not use the shared \\`COMPOSIO_API_KEY\\`, which is staging-scoped.\n\n This issue is filed once, not re-filed on every run, and automatically closes\n after the next successful sync proves recovery.\"",
456 + "count": 1
457 + },
458 + {
459 + "ruleId": "yaml-continue-on-error",
460 + "file": ".github/workflows/docs-update-data.yml",
461 + "source": " - name: Request review from trigger actor\n if: steps.create-pr.outputs.pull-request-number\n continue-on-error: true\n env:\n GH_TOKEN: ${{ steps.app-token.outputs.token }}\n PR_NUMBER: ${{ steps.create-pr.outputs.pull-request-number }}\n AUTHOR: ${{ github.actor }}\n run: |\n gh pr edit \"$PR_NUMBER\" --add-reviewer \"$AUTHOR\" || \\\n gh pr edit \"$PR_NUMBER\" --add-reviewer \"Sushmithamallesh\"\n\n # A silent failure here is invisible: the workflow stops refreshing\n # public/data/toolkits.json, the docs site keeps building from the last\n # good commit, and nothing 500s — new toolkits simply 404. That is how a\n # credential failure went unnoticed for 60 consecutive runs. File one\n # tracking issue and close it after the next successful run proves recovery.",
462 + "count": 1
463 + },
464 + {
465 + "ruleId": "yaml-continue-on-error",
466 + "file": ".github/workflows/docs-update-data.yml",
467 + "source": " - name: Track KB freshness findings\n if: always() && (steps.verify-kb.outputs.exit_code == '0' || steps.verify-kb.outputs.exit_code == '1')\n continue-on-error: true\n env:\n GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n VERIFY_EXIT: ${{ steps.verify-kb.outputs.exit_code }}\n TITLE: 'KB freshness: published guides contradict production data'\n run: |\n set -euo pipefail\n # Exactly one issue carries this label, so listing by label is the lookup.\n existing=$(gh issue list --state open --label kb-freshness \\\n --json number --jq '.[0].number // empty' 2>/dev/null || true)\n\n if [ \"$VERIFY_EXIT\" = \"0\" ]; then\n if [ -n \"$existing\" ]; then\n gh issue close \"$existing\" \\\n --comment \"Verified clean against the current production catalog by run ${{ github.run_id }}.\"\n fi\n exit 0\n fi\n\n {\n echo \"\\`verify:kb\\` found published KB guides whose claims no longer match production.\"\n echo\n echo \"Fix the guide, or demote it to \\`state: needs-review\\` in \\`docs/kb/manifest.json\\`\"\n echo \"so it stops serving readers while it is wrong.\"\n echo\n cat \"$RUNNER_TEMP/kb-freshness.md\" 2>/dev/null \\\n || echo \"Report unavailable — \\`verify:kb\\` exited $VERIFY_EXIT before writing it.\"\n echo\n echo \"_Regenerated by [run ${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})._\"\n } > \"$RUNNER_TEMP/kb-issue.md\"\n\n gh label create kb-freshness --color FBCA04 \\\n --description \"Published KB guides contradicting production data\" 2>/dev/null || true\n\n if [ -n \"$existing\" ]; then\n gh issue edit \"$existing\" --body-file \"$RUNNER_TEMP/kb-issue.md\"\n else\n gh issue create --title \"$TITLE\" --label kb-freshness \\\n --body-file \"$RUNNER_TEMP/kb-issue.md\"\n fi\n",
468 + "count": 1
469 + },
470 + {
471 + "ruleId": "yaml-continue-on-error",
472 + "file": ".github/workflows/docs-update-data.yml",
473 + "source": " - name: Track KB freshness verifier health\n if: always() && steps.verify-kb.outputs.exit_code != ''\n continue-on-error: true\n env:\n GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n VERIFY_EXIT: ${{ steps.verify-kb.outputs.exit_code }}\n LABEL: kb-freshness-check-failure\n TITLE: 'KB freshness verifier is failing'\n run: |\n set -euo pipefail\n existing=$(gh issue list --state open --label \"$LABEL\" \\\n --json number --jq '.[0].number // empty' 2>/dev/null || true)\n\n if [ \"$VERIFY_EXIT\" = \"0\" ] || [ \"$VERIFY_EXIT\" = \"1\" ]; then\n if [ -n \"$existing\" ]; then\n gh issue close \"$existing\" \\\n --comment \"The verifier recovered in run ${{ github.run_id }} (exit $VERIFY_EXIT).\"\n fi\n exit 0\n fi\n\n gh label create \"$LABEL\" --color B60205 \\\n --description \"KB freshness verifier is failing\" 2>/dev/null || true\n\n {\n echo \"The KB freshness verifier exited $VERIFY_EXIT before it could classify published content.\"\n echo\n echo \"This is a verifier or workflow failure, not evidence that published guides contradict production.\"\n echo\n echo \"_Observed in [run ${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})._\"\n } > \"$RUNNER_TEMP/kb-verifier-issue.md\"\n\n if [ -n \"$existing\" ]; then\n gh issue edit \"$existing\" --body-file \"$RUNNER_TEMP/kb-verifier-issue.md\"\n else\n gh issue create --title \"$TITLE\" --label \"$LABEL\" \\\n --body-file \"$RUNNER_TEMP/kb-verifier-issue.md\"\n fi\n\n # One long-lived issue, rewritten each run. A new issue per sweep would train\n # everyone to ignore the label; a single issue that closes itself when the KB\n # is clean stays worth reading. Runs regardless of whether data changed —\n # a guide can rot while the catalog is unchanged.",
474 + "count": 1
475 + },
476 + {
477 + "ruleId": "yaml-continue-on-error",
478 + "file": ".github/workflows/docs-update-data.yml",
479 + "source": " - name: Verify KB freshness against refreshed data\n id: verify-kb\n continue-on-error: true\n env:\n # Resolves manifest.source.commit on the upstream KB repository. Without\n # read access there the check reports \"unverifiable\" and stays silent,\n # so an unset or narrow token degrades quietly rather than crying wolf.\n GH_TOKEN: ${{ steps.source-token.outputs.token }}\n run: |\n set +e\n if [ -z \"${GH_TOKEN:-}\" ]; then\n echo \"KB source token unavailable; source-pin status will be unverifiable.\"\n fi\n bun scripts/verify-kb.ts --check-links --check-source-pin \\\n --markdown \"$RUNNER_TEMP/kb-freshness.md\"\n echo \"exit_code=$?\" >> \"$GITHUB_OUTPUT\"\n cat \"$RUNNER_TEMP/kb-freshness.md\" >> \"$GITHUB_STEP_SUMMARY\"",
480 + "count": 1
481 + },
482 + {
483 + "ruleId": "yaml-continue-on-error",
484 + "file": ".github/workflows/docs-update-kb.yml",
485 + "source": " - name: Close KB refresh failure issue\n if: needs.refresh.result == 'success' && (needs.refresh.outputs.changed != 'true' || needs.propose.result == 'success')\n continue-on-error: true\n env:\n GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n GH_REPO: ${{ github.repository }}\n LABEL: docs-kb-refresh-failure\n run: |\n existing=$(gh issue list --label \"$LABEL\" --state open --limit 1 \\\n --json number --jq '.[0].number // empty')\n if [ -n \"$existing\" ]; then\n gh issue close \"$existing\" \\\n --comment \"The support knowledge publication pipeline recovered in run ${{ github.run_id }}: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}.\"\n fi\n",
486 + "count": 1
487 + },
488 + {
489 + "ruleId": "yaml-continue-on-error",
490 + "file": ".github/workflows/docs-update-kb.yml",
491 + "source": " - name: Generate read-only upstream token\n id: upstream-token\n continue-on-error: true\n uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0\n with:\n client-id: ${{ vars.RELEASE_BOT_CLIENT_ID }}\n private-key: ${{ secrets.RELEASE_BOT_APP_PRIVATE_KEY }}\n owner: ComposioHQ\n repositories: support-knowledge\n permission-contents: read",
492 + "count": 1
493 + },
494 + {
495 + "ruleId": "yaml-continue-on-error",
496 + "file": ".github/workflows/docs-update-kb.yml",
497 + "source": " - name: Open KB refresh failure issue\n if: needs.refresh.result == 'failure' || needs.propose.result == 'failure'\n continue-on-error: true\n env:\n GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}\n GH_REPO: ${{ github.repository }}\n LABEL: docs-kb-refresh-failure\n RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}\n EVENT_NAME: ${{ github.event_name }}\n REFRESH_RESULT: ${{ needs.refresh.result }}\n PROPOSE_RESULT: ${{ needs.propose.result }}\n run: |\n gh label create \"$LABEL\" \\\n --color B60205 \\\n --description \"Scheduled support knowledge refresh is failing\" 2>/dev/null || true\n\n existing=$(gh issue list --label \"$LABEL\" --state open --limit 1 \\\n --json number --jq '.[0].number // empty')\n if [ -n \"$existing\" ]; then\n echo \"Issue #$existing is already open for this failure; not filing a duplicate.\"\n exit 0\n fi\n\n gh issue create \\\n --title \"Support knowledge refresh is failing\" \\\n --label \"$LABEL\" \\\n --body \"The automated support knowledge publication pipeline failed.\n\n - Run: $RUN_URL\n - Trigger: \\`$EVENT_NAME\\`\n - Refresh job: \\`$REFRESH_RESULT\\`\n - Proposal job: \\`$PROPOSE_RESULT\\`\n\n **Impact:** docs.composio.dev/kb remains on its last successfully imported\n support-knowledge commit until this workflow recovers.\n\n **First checks:** verify that the Release Bot GitHub App can read\n \\`ComposioHQ/support-knowledge\\` and write the refresh branch and PR in\n \\`ComposioHQ/composio\\`.\"",
498 + "count": 1
499 + },
500 + {
501 + "ruleId": "yaml-continue-on-error",
502 + "file": ".github/workflows/docs.changelog-to-docs.yml",
503 + "source": " - name: Request review from pusher\n if: steps.create-pr.outputs.pull-request-number\n continue-on-error: true\n env:\n GH_TOKEN: ${{ steps.app-token.outputs.token }}\n PR_NUMBER: ${{ steps.create-pr.outputs.pull-request-number }}\n AUTHOR: ${{ github.actor }}\n run: gh pr edit \"$PR_NUMBER\" --add-reviewer \"$AUTHOR\"\n",
504 + "count": 1
505 + },
506 + {
507 + "ruleId": "yaml-continue-on-error",
508 + "file": ".github/workflows/docs.sdk-change-sync.yml",
509 + "source": " - name: Request review from pusher\n if: steps.create-pr.outputs.pull-request-number\n continue-on-error: true\n env:\n GH_TOKEN: ${{ steps.app-token.outputs.token }}\n PR_NUMBER: ${{ steps.create-pr.outputs.pull-request-number }}\n AUTHOR: ${{ github.actor }}\n run: gh pr edit \"$PR_NUMBER\" --add-reviewer \"$AUTHOR\"\n",
510 + "count": 1
511 + },
512 + {
513 + "ruleId": "yaml-continue-on-error",
514 + "file": ".github/workflows/ts.audit.yml",
515 + "source": " - name: Run pnpm audit (production dependencies only)\n id: audit\n continue-on-error: true\n run: pnpm audit --prod > audit-output.txt 2>&1",
516 + "count": 1
517 + }
518 +]
.ast-grep/rules/py-empty-except.yml new
+54
@@ -0,0 +1,54 @@
1 +id: py-empty-except
2 +language: Python
3 +severity: error
4 +message: Handle or propagate the exception; a broad except with only pass discards every failure.
5 +files: ['python/**', 'scripts/**', '.github/scripts/**']
6 +ignores:
7 + - '**/node_modules/**'
8 + - '**/.venv/**'
9 + - '**/.nox/**'
10 + - '**/build/**'
11 + - '**/dist/**'
12 + - '**/test/**'
13 + - '**/tests/**'
14 + - '**/integration_test/**'
15 + - '**/test_*.py'
16 + - '**/*_test.py'
17 +rule:
18 + kind: except_clause
19 + any:
20 + - regex: '^except\s*:'
21 + - has:
22 + field: value
23 + any:
24 + - matches: broad-exception-type
25 + - kind: as_pattern
26 + has:
27 + matches: broad-exception-type
28 + has:
29 + kind: block
30 + has:
31 + kind: pass_statement
32 + not:
33 + has:
34 + not:
35 + any:
36 + - kind: pass_statement
37 + - kind: comment
38 +utils:
39 + broad-exception-name:
40 + kind: identifier
41 + regex: '^(Exception|BaseException)$'
42 + broad-exception-type:
43 + any:
44 + - matches: broad-exception-name
45 + - kind: parenthesized_expression
46 + has:
47 + matches: broad-exception-name
48 + - kind: tuple
49 + has:
50 + any:
51 + - matches: broad-exception-name
52 + - kind: parenthesized_expression
53 + has:
54 + matches: broad-exception-name
.ast-grep/rules/py-unchecked-ignore.yml new
+21
@@ -0,0 +1,21 @@
1 +id: py-unchecked-ignore
2 +language: Python
3 +severity: error
4 +message: Fix the type error or limit type-ignore to specific error codes with an explanation.
5 +files: ['python/**', 'scripts/**', '.github/scripts/**']
6 +ignores:
7 + - '**/node_modules/**'
8 + - '**/.venv/**'
9 + - '**/.nox/**'
10 + - '**/build/**'
11 + - '**/dist/**'
12 + - '**/test/**'
13 + - '**/tests/**'
14 + - '**/integration_test/**'
15 + - '**/test_*.py'
16 + - '**/*_test.py'
17 +rule:
18 + kind: comment
19 + regex: '^#\s*type:\s*ignore\b'
20 + not:
21 + regex: '^#\s*type:\s*ignore\s*\[\s*[a-z][a-z0-9-]*(\s*,\s*[a-z][a-z0-9-]*)*\s*\]'
.ast-grep/rules/ts-double-assertion.yml new
+28
@@ -0,0 +1,28 @@
1 +id: ts-double-assertion
2 +language: Tsx
3 +severity: error
4 +message: Parse or narrow the value instead of casting through unknown or any.
5 +files: ['ts/packages/**', 'ts/scripts/**', 'scripts/**', '.github/scripts/**']
6 +ignores:
7 + - '**/node_modules/**'
8 + - '**/dist/**'
9 + - '**/generated/**'
10 + - '**/.generated/**'
11 + - '**/pack/**'
12 + - '**/*.d.ts'
13 + - '**/*.test.*'
14 + - '**/*.spec.*'
15 + - '**/__tests__/**'
16 + - '**/test/**'
17 + - '**/tests/**'
18 +rule:
19 + kind: as_expression
20 + has:
21 + any:
22 + - pattern: $VALUE as unknown
23 + - pattern: $VALUE as any
24 + - kind: parenthesized_expression
25 + has:
26 + any:
27 + - pattern: $VALUE as unknown
28 + - pattern: $VALUE as any
.ast-grep/rules/ts-empty-catch.yml new
+28
@@ -0,0 +1,28 @@
1 +id: ts-empty-catch
2 +language: Tsx
3 +severity: error
4 +message: Handle or propagate the error; an empty catch silently discards it.
5 +files: ['ts/packages/**', 'ts/scripts/**', 'scripts/**', '.github/scripts/**']
6 +ignores:
7 + - '**/node_modules/**'
8 + - '**/dist/**'
9 + - '**/generated/**'
10 + - '**/.generated/**'
11 + - '**/pack/**'
12 + - '**/*.d.ts'
13 + - '**/*.test.*'
14 + - '**/*.spec.*'
15 + - '**/__tests__/**'
16 + - '**/test/**'
17 + - '**/tests/**'
18 +rule:
19 + any:
20 + - pattern:
21 + context: 'try {} catch {}'
22 + selector: catch_clause
23 + - pattern:
24 + context: 'try {} catch ($ERROR) {}'
25 + selector: catch_clause
26 + - pattern:
27 + context: 'try {} catch ($ERROR: $TYPE) {}'
28 + selector: catch_clause
.ast-grep/rules/ts-unchecked-ignore.yml new
+20
@@ -0,0 +1,20 @@
1 +id: ts-unchecked-ignore
2 +language: Tsx
3 +severity: error
4 +message: Fix the type error or use @ts-expect-error with a specific explanation.
5 +files: ['ts/packages/**', 'ts/scripts/**', 'scripts/**', '.github/scripts/**']
6 +ignores:
7 + - '**/node_modules/**'
8 + - '**/dist/**'
9 + - '**/generated/**'
10 + - '**/.generated/**'
11 + - '**/pack/**'
12 + - '**/*.d.ts'
13 + - '**/*.test.*'
14 + - '**/*.spec.*'
15 + - '**/__tests__/**'
16 + - '**/test/**'
17 + - '**/tests/**'
18 +rule:
19 + kind: comment
20 + regex: '^\s*(//|/\*)\s*@ts-(ignore|nocheck)\b'
.ast-grep/rules/yaml-continue-on-error.yml new
+20
@@ -0,0 +1,20 @@
1 +id: yaml-continue-on-error
2 +language: Yaml
3 +severity: error
4 +message: Preserve CI failures. For an intentional soft failure, explain the outcome handling in a rule-specific suppression.
5 +files: ['.github/workflows/**', '.github/actions/**']
6 +rule:
7 + any:
8 + - kind: block_mapping
9 + - kind: flow_mapping
10 + has:
11 + any:
12 + - kind: block_mapping_pair
13 + - kind: flow_pair
14 + has:
15 + field: key
16 + regex: '^(continue-on-error|"continue-on-error"|''continue-on-error'')$'
17 + all:
18 + - has:
19 + field: value
20 + regex: '^(true|"true"|''true''|\$\{\{\s*true\s*\}\})$'
.ast-grep/rules/yaml-empty-run.yml new
+21
@@ -0,0 +1,21 @@
1 +id: yaml-empty-run
2 +language: Yaml
3 +severity: error
4 +message: Replace the empty CI run step with an executable check, or remove it.
5 +files: ['.github/workflows/**', '.github/actions/**']
6 +rule:
7 + all:
8 + - any:
9 + - kind: block_mapping_pair
10 + - kind: flow_pair
11 + has:
12 + field: key
13 + regex: '^(run|"run"|''run'')$'
14 + any:
15 + - not:
16 + has:
17 + field: value
18 + regex: '.'
19 + - has:
20 + field: value
21 + regex: '^("\s*"|''\s*''|[|>][-+]?\s*)$'
.ast-grep/tests/py-empty-except.yml new
+64
@@ -0,0 +1,64 @@
1 +id: py-empty-except
2 +valid:
3 + - |
4 + try:
5 + work()
6 + except ValueError as Exception:
7 + pass
8 + - |
9 + try:
10 + work()
11 + except (error_type(Exception), ValueError):
12 + pass
13 + - |
14 + try:
15 + work()
16 + except (FileNotFoundError, ValueError):
17 + pass
18 + - |
19 + try:
20 + work()
21 + except FileNotFoundError:
22 + pass
23 + - |
24 + try:
25 + work()
26 + except Exception:
27 + logger.exception("Failed to complete work")
28 + - |
29 + try:
30 + work()
31 + except Exception:
32 + raise
33 +invalid:
34 + - |
35 + try:
36 + work()
37 + except (Exception,):
38 + pass
39 + - |
40 + try:
41 + work()
42 + except (ValueError, Exception) as error:
43 + pass
44 + - |
45 + try:
46 + work()
47 + except (BaseException):
48 + pass
49 + - |
50 + try:
51 + work()
52 + except:
53 + pass
54 + - |
55 + try:
56 + work()
57 + except Exception as error:
58 + pass
59 + - |
60 + try:
61 + work()
62 + except BaseException:
63 + # Best effort
64 + pass
.ast-grep/tests/py-unchecked-ignore.yml new
+9
@@ -0,0 +1,9 @@
1 +id: py-unchecked-ignore
2 +valid:
3 + - 'value = external() # type: ignore[attr-defined] - upstream stub omits the field'
4 + - 'value = external() # type: ignore [attr-defined, assignment]'
5 + - 'help = "# type: ignore"'
6 +invalid:
7 + - 'value = external() # type: ignore'
8 + - 'value = external() # type: ignore - dynamic input'
9 + - 'value = external() # type: ignore[]'
.ast-grep/tests/ts-double-assertion.yml new
+11
@@ -0,0 +1,11 @@
1 +id: ts-double-assertion
2 +valid:
3 + - 'const user = parseUser(input);'
4 + - 'const config = { retries: 3 } satisfies Config;'
5 + - 'const id = value as UserId;'
6 + - 'const literal = "value as unknown as User";'
7 +invalid:
8 + - 'const user = value as unknown as User;'
9 + - 'const user = value as any as User;'
10 + - 'const user = (value as unknown) as User;'
11 + - 'const view = <Widget user={value as unknown as User} />;'
.ast-grep/tests/ts-empty-catch.yml new
+11
@@ -0,0 +1,11 @@
1 +id: ts-empty-catch
2 +valid:
3 + - 'try { work(); } catch (error) { throw error; }'
4 + - 'try { work(); } catch { return undefined; }'
5 + - 'try { work(); } catch (error: unknown) { report(error); }'
6 +invalid:
7 + - 'try { work(); } catch {}'
8 + - 'try { work(); } catch (error) {}'
9 + - 'try { work(); } catch { /* ignore */ }'
10 + - 'try { work(); } catch (error: unknown) {}'
11 + - 'try { work(); } catch (error: any) { /* ignore */ }'
.ast-grep/tests/ts-unchecked-ignore.yml new
+9
@@ -0,0 +1,9 @@
1 +id: ts-unchecked-ignore
2 +valid:
3 + - '// @ts-expect-error: upstream overload excludes this validated input'
4 + - 'const help = "// @ts-ignore";'
5 + - '// Discuss @ts-ignore with the API owner.'
6 +invalid:
7 + - '// @ts-ignore'
8 + - '// @ts-ignore: force it through'
9 + - '/* @ts-nocheck */'
.ast-grep/tests/yaml-continue-on-error.yml new
+11
@@ -0,0 +1,11 @@
1 +id: yaml-continue-on-error
2 +valid:
3 + - 'continue-on-error: false'
4 + - 'continue-on-error: ${{ matrix.experimental }}'
5 + - 'description: "continue-on-error: true"'
6 +invalid:
7 + - 'continue-on-error: true'
8 + - '"continue-on-error": true'
9 + - "'continue-on-error': 'true'"
10 + - 'continue-on-error: ${{ true }}'
11 + - 'steps: [{run: pnpm lint, continue-on-error: true}]'
.ast-grep/tests/yaml-empty-run.yml new
+17
@@ -0,0 +1,17 @@
1 +id: yaml-empty-run
2 +valid:
3 + - 'run: echo " "'
4 + - 'run: pnpm lint'
5 + - |
6 + run: |
7 + pnpm lint
8 + - 'description: "run:"'
9 +invalid:
10 + - 'run: " "'
11 + - "run: ' '"
12 + - 'run:'
13 + - 'run: ""'
14 + - "run: ''"
15 + - 'steps: [{run: ""}]'
16 + - |
17 + run: |
.github/workflows/agent-substrate.yml
+21
@@ -34,6 +34,27 @@ permissions:
34 contents: read
35
36 jobs:
37 + antislop:
38 + name: Anti-slop (TypeScript, Python, YAML)
39 + runs-on: ubuntu-latest
40 + steps:
41 + - name: Checkout Code
42 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
43 +
44 + - name: Setup Node.js, pnpm, Bun
45 + uses: ./.github/actions/setup-node-pnpm-bun
46 + with:
47 + cache-save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/next' }}
48 +
49 + - name: Install dependencies
50 + run: pnpm install --frozen-lockfile --ignore-scripts
51 +
52 + - name: Test anti-slop rules and enforcement
53 + run: pnpm test:antislop
54 +
55 + - name: Reject new anti-slop findings
56 + run: pnpm lint:antislop
57 +
58 validate:
59 name: Validate agent guidance
60 runs-on: ubuntu-latest
CONTRIBUTING.md
+24
@@ -201,6 +201,30 @@ Using an agent doesn't change your responsibility: [read the code you submit](#r
201 - Include enough context in error messages to identify the failing operation.
202 - Don't swallow errors unless the caller has an explicit fallback path.
203
204 +### Anti-slop checks
205 +
206 +Run the AST checks from the repository root:
207 +
208 +```bash
209 +pnpm lint:antislop # reject new findings and stale baseline entries
210 +pnpm test:antislop # rule fixtures and enforcement tests
211 +pnpm lint:antislop:scan # inspect all findings, including existing ones
212 +```
213 +
214 +These checks also run through `pnpm lint` and the **Anti-slop (TypeScript, Python, YAML)** CI job on every push and pull request to `next` or `master`. They supplement Oxlint and Ruff. They flag specific patterns; they cannot determine whether code was written by AI.
215 +
216 +The rules in [`.ast-grep/rules`](.ast-grep/rules) cover handwritten TypeScript SDK and CLI packages, Python SDK and providers, maintenance scripts, GitHub workflows, and composite actions. TypeScript uses the TSX parser to cover `.ts`, `.tsx`, `.mts`, and `.cts` with the same rules. Generated code, dependencies, build output, and test files are excluded. Python examples are covered; TypeScript examples and the docs site are outside this check's scope.
217 +
218 +| Language | Patterns |
219 +| ---------- | -------------------------------------------------------------------------------------------------------------------------------- |
220 +| TypeScript | Double assertions through `unknown` or `any`, empty catch blocks (including comment-only blocks), `@ts-ignore` and `@ts-nocheck` |
221 +| Python | Bare or broad `except` blocks containing only `pass`, `type: ignore` without error codes |
222 +| CI YAML | Unconditional `continue-on-error: true`, empty `run` steps |
223 +
224 +Fix a finding by parsing or narrowing input, handling the failure, or keeping the original check effective. Some soft failures are intentional, such as collecting an audit result before a later step enforces its outcome. For a justified exception, explain the invariant or later failure gate in a comment, then put a [rule-specific ast-grep suppression](https://ast-grep.github.io/guide/project/severity.html#ignore-linting-error) immediately before the matched node. For `yaml-continue-on-error`, the matched node is the containing step or job mapping, so place its suppression before the step or job. Blanket and unused suppressions fail the check. Avoid file-wide suppressions.
225 +
226 +Existing findings are recorded in [`.ast-grep/baseline.json`](.ast-grep/baseline.json) by rule, path, full matched source lines, and occurrence count. The baseline records adoption debt, not approved patterns. A new source, a changed source, a moved file, or another identical occurrence fails the check. Line-number changes alone do not. After fixing an existing finding, run `pnpm lint:antislop:prune` and include the reduced baseline in your change. Pruning refuses to add allowances. Do not regenerate or expand the baseline to pass CI.
227 +
228 ## Documentation Changes
229
230 Update docs when a change affects public behavior, install flows, examples, environment variables, release steps, or provider usage.
package.json
+6 -1
@@ -46,7 +46,11 @@
46 "typecheck": "turbo typecheck --filter=./ts/packages/**",
47 "typecheck:examples": "turbo typecheck --filter='./ts/examples/*'",
48 "lint:examples": "turbo lint --filter='./ts/examples/*'",
49 - "lint": "oxlint ts test tsdown.config.base.ts",
49 + "lint": "oxlint ts test tsdown.config.base.ts && pnpm run lint:antislop",
50 + "lint:antislop": "node scripts/check-antislop.mjs",
51 + "lint:antislop:scan": "ast-grep scan --config sgconfig.yml --error=no-suppress-all --error=unused-suppression",
52 + "lint:antislop:prune": "node scripts/check-antislop.mjs --prune",
53 + "test:antislop": "ast-grep test --config sgconfig.yml --skip-snapshot-tests && node --test test/antislop.test.mjs",
54 "lint:packages": "oxlint ts/packages",
55 "lint:fix": "oxlint --fix .",
56 "lint:fix:packages": "oxlint --fix ts/packages",
@@ -82,6 +86,7 @@
86 },
87 "devDependencies": {
88 "@arethetypeswrong/cli": "catalog:",
89 + "@ast-grep/cli": "0.51.1",
90 "@changesets/apply-release-plan": "8.1.1",
91 "@changesets/assemble-release-plan": "7.0.0",
92 "@changesets/cli": "^3.0.3",
pnpm-lock.yaml
+88 -1
@@ -138,6 +138,9 @@ importers:
138 '@arethetypeswrong/cli':
139 specifier: 'catalog:'
140 version: 0.18.5
141 + '@ast-grep/cli':
142 + specifier: 0.51.1
143 + version: 0.51.1
144 '@changesets/apply-release-plan':
145 specifier: 8.1.1
146 version: 8.1.1
@@ -2058,6 +2061,55 @@ packages:
2061 resolution: {integrity: sha512-9ytjzGwxjm9Uz7I9avfbt5vlQt6uk9uRRESzJjqrznl6WKvI6dwYTo+vJ3U02Wrq/mR3iql/PzhvHhKdJIAjDQ==}
2062 engines: {node: '>=20'}
2063
2064 + '@ast-grep/cli-darwin-arm64@0.51.1':
2065 + resolution: {integrity: sha512-C279HR4eytYkHrmqudMi+eUG3ZvuAqWc0zp9i5aPugFF389AE6N6SbiSFdKeVZXMaUVpwRbmBQbBTr5cA0Tugw==}
2066 + engines: {node: '>= 10'}
2067 + cpu: [arm64]
2068 + os: [darwin]
2069 +
2070 + '@ast-grep/cli-darwin-x64@0.51.1':
2071 + resolution: {integrity: sha512-i8wJd4amxXCvEgZDcU8QDnVE92oqJyDFPyTjaT1PVtBQ0Vb7Y55iTu1dwBwXVi0inFM2OJ4Ze57yCz1uNuXTbg==}
2072 + engines: {node: '>= 10'}
2073 + cpu: [x64]
2074 + os: [darwin]
2075 +
2076 + '@ast-grep/cli-linux-arm64-gnu@0.51.1':
2077 + resolution: {integrity: sha512-ix/97iBUPGvf9KrhKRcooSJLmwBgAo7GhKHm7VH30kpxOMUrNLqiTXJj2eZVLiO2xQdUFnbwhVn+A7blSlYLJQ==}
2078 + engines: {node: '>= 10'}
2079 + cpu: [arm64]
2080 + os: [linux]
2081 + libc: [glibc]
2082 +
2083 + '@ast-grep/cli-linux-x64-gnu@0.51.1':
2084 + resolution: {integrity: sha512-FlaaRLyopXet+zFrWOdlTbyJb+QqZzgV9jxIbgz0FoVsJSaJ6jsenO/6bgYJk4zPOCUODuvoQ1/XFlB4r6BdcQ==}
2085 + engines: {node: '>= 10'}
2086 + cpu: [x64]
2087 + os: [linux]
2088 + libc: [glibc]
2089 +
2090 + '@ast-grep/cli-win32-arm64-msvc@0.51.1':
2091 + resolution: {integrity: sha512-WRgt7DX/APxJ6KwGopM0jiC1SN4okxXh2kXY5/YliNy0oPc7ayE5FdG7Dqz40iyOE3EpQN6SZVRquvkpJEagnQ==}
2092 + engines: {node: '>= 10'}
2093 + cpu: [arm64]
2094 + os: [win32]
2095 +
2096 + '@ast-grep/cli-win32-ia32-msvc@0.51.1':
2097 + resolution: {integrity: sha512-Nclj/nsZmiT1bg1jfVL9sqpv0dzcZv6lZu1uk/UrjtvXw832yewmJucvmpAOd0fcb6l57SQ69Jqvt9MNzKwFSQ==}
2098 + engines: {node: '>= 10'}
2099 + cpu: [ia32]
2100 + os: [win32]
2101 +
2102 + '@ast-grep/cli-win32-x64-msvc@0.51.1':
2103 + resolution: {integrity: sha512-98fN1gUWJ6AMcwfFdUAQV+4haq5HAzDZWyu3W5zCZXkhhvcT3GLY9oRcACrr7yefIQohHpj5GG0rUZNlwukrMQ==}
2104 + engines: {node: '>= 10'}
2105 + cpu: [x64]
2106 + os: [win32]
2107 +
2108 + '@ast-grep/cli@0.51.1':
2109 + resolution: {integrity: sha512-xdX9+jHTZLwpYtHFRmK4Zzoe0UPmZrn037wwCHKBqaFJPC12xiGTwrZEZDMbBwRwmsGYcG1yHsb7yvEFU8EzNw==}
2110 + engines: {node: '>= 12.0.0'}
2111 + hasBin: true
2112 +
2113 '@aws-crypto/sha256-js@5.2.0':
2114 resolution: {integrity: sha512-FFQQyu7edu4ufvIZ+OadFpHHOt+eSTBaYaki44c+akjg7qZg9oOQeLlk77F6tSYqjDAFClrHJk9tMf0HdVyOvA==}
2115 engines: {node: '>=16.0.0'}
@@ -4059,7 +4111,9 @@ packages:
4111 '@smithy/core@3.36.0':
4112 resolution: {integrity: sha512-3hJiwG1F5t1SoXqp/yOCmYXziyx7ZVqF63S5W6YU201e/qwVaHPex+E/3vvyY9a3ORq/b+BydeNZpP2saQ9X2g==}
4113 engines: {node: '>=18.0.0'}
4062 - deprecated: Deprecated due to a bug in custom logger data redaction. See https://github.com/aws/aws-sdk-js-v3/issues/8393.
4114 + deprecated: |-
4115 + Deprecated due to a bug in custom logger data redaction. Upgrade to the latest version. If you used a custom logger with this
4116 + version, review your logs and rotate any credentials or other secrets. See https://github.com/aws/aws-sdk-js-v3/issues/8393.
4117
4118 '@smithy/credential-provider-imds@4.5.2':
4119 resolution: {integrity: sha512-A9uSdn72ozbRUSit0eib0TW7nXuNPlaeM0zcGkJ+nE6tFcSDbnmtwoxbTCFBukVQcszDAyvsd7+rTduPTXpygg==}
@@ -7155,6 +7209,39 @@ snapshots:
7209 typescript: 5.6.1-rc
7210 validate-npm-package-name: 5.0.1
7211
7212 + '@ast-grep/cli-darwin-arm64@0.51.1':
7213 + optional: true
7214 +
7215 + '@ast-grep/cli-darwin-x64@0.51.1':
7216 + optional: true
7217 +
7218 + '@ast-grep/cli-linux-arm64-gnu@0.51.1':
7219 + optional: true
7220 +
7221 + '@ast-grep/cli-linux-x64-gnu@0.51.1':
7222 + optional: true
7223 +
7224 + '@ast-grep/cli-win32-arm64-msvc@0.51.1':
7225 + optional: true
7226 +
7227 + '@ast-grep/cli-win32-ia32-msvc@0.51.1':
7228 + optional: true
7229 +
7230 + '@ast-grep/cli-win32-x64-msvc@0.51.1':
7231 + optional: true
7232 +
7233 + '@ast-grep/cli@0.51.1':
7234 + dependencies:
7235 + detect-libc: 2.1.2
7236 + optionalDependencies:
7237 + '@ast-grep/cli-darwin-arm64': 0.51.1
7238 + '@ast-grep/cli-darwin-x64': 0.51.1
7239 + '@ast-grep/cli-linux-arm64-gnu': 0.51.1
7240 + '@ast-grep/cli-linux-x64-gnu': 0.51.1
7241 + '@ast-grep/cli-win32-arm64-msvc': 0.51.1
7242 + '@ast-grep/cli-win32-ia32-msvc': 0.51.1
7243 + '@ast-grep/cli-win32-x64-msvc': 0.51.1
7244 +
7245 '@aws-crypto/sha256-js@5.2.0':
7246 dependencies:
7247 '@aws-crypto/util': 5.2.0
pnpm-workspace.yaml
+2
@@ -17,6 +17,8 @@ packages:
17 - ts/packages/ts-builders
18
19 allowBuilds:
20 + # The package's Node shim resolves its platform binary without postinstall.
21 + '@ast-grep/cli': false
22 '@google/genai': false
23 '@parcel/watcher': true
24 esbuild: true
python/composio/core/models/_telemetry.py
+2 -1
@@ -148,8 +148,9 @@ def _push(event: Event):
148 timeout=2.0, # 2 second timeout to prevent hanging
149 )
150 )
151 + # Telemetry failures must not fail an otherwise successful SDK operation.
152 + # ast-grep-ignore: py-empty-except
153 except (httpx.TimeoutException, httpx.HTTPError, Exception):
152 - # Silently fail - telemetry shouldn't break the application
154 pass
155
156
scripts/check-antislop.mjs new
+116
@@ -0,0 +1,116 @@
1 +import { spawnSync } from 'node:child_process';
2 +import { readFileSync, writeFileSync } from 'node:fs';
3 +import { createRequire } from 'node:module';
4 +import { dirname, resolve } from 'node:path';
5 +import { fileURLToPath } from 'node:url';
6 +
7 +const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
8 +const require = createRequire(import.meta.url);
9 +const binary = resolve(dirname(require.resolve('@ast-grep/cli/package.json')), 'ast-grep');
10 +
11 +export function scan(cwd = root) {
12 + // The package keeps a Node shim on Windows; Unix installs may replace it
13 + // with the native executable. Invoke each in its supported form.
14 + const command = process.platform === 'win32' ? process.execPath : binary;
15 + const args = [
16 + 'scan',
17 + '--config',
18 + 'sgconfig.yml',
19 + '--json=compact',
20 + '--error=no-suppress-all',
21 + '--error=unused-suppression',
22 + ];
23 + const result = spawnSync(command, process.platform === 'win32' ? [binary, ...args] : args, {
24 + cwd,
25 + encoding: 'utf8',
26 + maxBuffer: 32 * 1024 * 1024,
27 + });
28 + // ast-grep exits 1 for error diagnostics and uses other codes for scan failures.
29 + if (result.error || (result.status !== 0 && result.status !== 1)) {
30 + throw new Error(`ast-grep failed: ${result.error?.message ?? result.stderr}`);
31 + }
32 + const findings = JSON.parse(result.stdout);
33 + if (!Array.isArray(findings) || (result.status === 1 && findings.length === 0)) {
34 + throw new Error(`ast-grep did not return valid diagnostics: ${result.stderr}`);
35 + }
36 + return findings;
37 +}
38 +
39 +function key(entry) {
40 + return JSON.stringify([entry.ruleId, entry.file, entry.source]);
41 +}
42 +
43 +export function inventory(findings) {
44 + const entries = new Map();
45 + for (const finding of findings) {
46 + const entry = {
47 + ruleId: finding.ruleId,
48 + file: finding.file.replaceAll('\\', '/'),
49 + // Include the whole source line for comment-only matches. This binds a
50 + // Python type-ignore to its statement, rather than to a reusable comment.
51 + source: finding.lines.replaceAll('\r\n', '\n'),
52 + count: 1,
53 + };
54 + const existing = entries.get(key(entry));
55 + if (existing) existing.count += 1;
56 + else entries.set(key(entry), entry);
57 + }
58 + return [...entries.values()].sort((a, b) => key(a).localeCompare(key(b), 'en'));
59 +}
60 +
61 +export function compare(current, baseline) {
62 + const allowed = new Map();
63 + for (const entry of baseline) {
64 + if (
65 + typeof entry.ruleId !== 'string' ||
66 + typeof entry.file !== 'string' ||
67 + typeof entry.source !== 'string' ||
68 + !Number.isSafeInteger(entry.count) ||
69 + entry.count < 1 ||
70 + allowed.has(key(entry))
71 + ) {
72 + throw new Error('Invalid or duplicate anti-slop baseline entry');
73 + }
74 + allowed.set(key(entry), entry.count);
75 + }
76 + const observed = new Map(current.map(entry => [key(entry), entry.count]));
77 + return {
78 + added: current.filter(entry => entry.count > (allowed.get(key(entry)) ?? 0)),
79 + stale: baseline.filter(entry => entry.count > (observed.get(key(entry)) ?? 0)),
80 + };
81 +}
82 +
83 +function main() {
84 + const args = process.argv.slice(2);
85 + if (args.length > 1 || (args.length === 1 && args[0] !== '--prune')) {
86 + throw new Error('Usage: node scripts/check-antislop.mjs [--prune]');
87 + }
88 + const findings = scan();
89 + const current = inventory(findings);
90 + const baselinePath = resolve(root, '.ast-grep/baseline.json');
91 + const baseline = JSON.parse(readFileSync(baselinePath, 'utf8'));
92 + const { added, stale } = compare(current, baseline);
93 + for (const entry of added) {
94 + const finding = findings.find(item => key(inventory([item])[0]) === key(entry));
95 + console.error(
96 + `${entry.file}:${finding.range.start.line + 1}: ${entry.ruleId}: ${finding.message}`
97 + );
98 + console.error(entry.source);
99 + }
100 + if (added.length) {
101 + console.error('New anti-slop findings. Fix them or justify a rule-specific suppression.');
102 + process.exitCode = 1;
103 + } else if (args[0] === '--prune') {
104 + writeFileSync(baselinePath, `${JSON.stringify(current, null, 2)}\n`);
105 + console.log('Pruned resolved anti-slop baseline entries. No allowances added.');
106 + } else if (stale.length) {
107 + console.error(
108 + 'Resolved anti-slop findings remain in the baseline. Run pnpm lint:antislop:prune.'
109 + );
110 + process.exitCode = 1;
111 + } else {
112 + console.log(`Anti-slop passed (${findings.length} existing findings; no new findings).`);
113 + }
114 +}
115 +
116 +if (import.meta.main) main();
sgconfig.yml new
+9
@@ -0,0 +1,9 @@
1 +ruleDirs:
2 + - .ast-grep/rules
3 +testConfigs:
4 + - testDir: .ast-grep/tests
5 +# Parse both TS and TSX with the TSX grammar so the same rules cover both.
6 +languageGlobs:
7 + Tsx: ['*.ts', '*.tsx', '*.mts', '*.cts']
8 +noIgnore:
9 + - hidden
test/antislop.test.mjs new
+131
@@ -0,0 +1,131 @@
1 +import assert from 'node:assert/strict';
2 +import { spawnSync } from 'node:child_process';
3 +import {
4 + mkdtempSync,
5 + mkdirSync,
6 + rmSync,
7 + writeFileSync,
8 + readFileSync,
9 + copyFileSync,
10 + cpSync,
11 + symlinkSync,
12 +} from 'node:fs';
13 +import { tmpdir } from 'node:os';
14 +import { join } from 'node:path';
15 +import { test } from 'node:test';
16 +import { compare, inventory, scan } from '../scripts/check-antislop.mjs';
17 +
18 +test('the baseline binds allowances to source, file, rule and multiplicity', () => {
19 + const finding = {
20 + ruleId: 'ts-double-assertion',
21 + file: 'ts/packages/core/src/user.ts',
22 + lines: 'value as unknown as User',
23 + };
24 + const baseline = inventory([finding]);
25 + assert.deepEqual(compare(inventory([finding]), baseline), { added: [], stale: [] });
26 + for (const change of [
27 + { lines: 'other as unknown as User' },
28 + { file: 'ts/packages/cli/src/user.ts' },
29 + { ruleId: 'another-rule' },
30 + ]) {
31 + const result = compare(inventory([{ ...finding, ...change }]), baseline);
32 + assert.equal(result.added.length, 1);
33 + assert.equal(result.stale.length, 1);
34 + }
35 + assert.equal(compare(inventory([finding, finding]), baseline).added.length, 1);
36 + assert.equal(compare([], baseline).stale.length, 1);
37 + assert.deepEqual(
38 + inventory([{ ...finding, file: 'ts\\packages\\core\\src\\user.ts', lines: 'value\r\n' }]),
39 + inventory([{ ...finding, lines: 'value\n' }])
40 + );
41 + assert.throws(() => compare([], [...baseline, ...baseline]), /duplicate/);
42 + assert.throws(() => compare([], [{ ...baseline[0], count: -1 }]), /Invalid/);
43 +});
44 +
45 +test('scan discovers SDKs, CLI, scripts and hidden CI YAML while excluding generated code and tests', () => {
46 + const cwd = mkdtempSync(join(tmpdir(), 'composio-antislop-'));
47 + const write = (file, contents) => {
48 + const path = join(cwd, file);
49 + mkdirSync(join(path, '..'), { recursive: true });
50 + writeFileSync(path, contents);
51 + };
52 + try {
53 + copyFileSync(new URL('../sgconfig.yml', import.meta.url), join(cwd, 'sgconfig.yml'));
54 + cpSync(new URL('../.ast-grep/rules', import.meta.url), join(cwd, '.ast-grep/rules'), {
55 + recursive: true,
56 + });
57 + const cast = 'const user = value as unknown as User;';
58 + for (const file of [
59 + 'ts/packages/core/src/user.ts',
60 + 'ts/packages/cli/src/view.tsx',
61 + 'ts/scripts/check.mts',
62 + 'scripts/check.cts',
63 + ])
64 + write(file, cast);
65 + for (const file of [
66 + 'ts/vendor/sample.ts',
67 + 'ts/packages/core/generated/user.ts',
68 + 'ts/packages/slim/generated/user.ts',
69 + 'ts/packages/core/pack/generated/user.ts',
70 + 'ts/packages/core/src/user.test.ts',
71 + 'ts/packages/core/node_modules/lib/user.ts',
72 + ])
73 + write(file, cast);
74 + write('python/composio/user.py', 'user = external() # type: ignore\n');
75 + write('python/providers/sample/provider.py', 'try:\n work()\nexcept Exception:\n pass\n');
76 + write('python/tests/test_user.py', 'user = external() # type: ignore\n');
77 + write('.github/workflows/check.yaml', 'jobs:\n check:\n continue-on-error: true\n');
78 + write('.github/actions/check/action.yml', 'runs:\n steps:\n - run: ""\n');
79 + const findings = scan(cwd);
80 + assert.equal(findings.length, 8);
81 + assert.equal(new Set(findings.map(finding => finding.file)).size, 8);
82 + assert.equal(findings.filter(finding => finding.ruleId === 'ts-double-assertion').length, 4);
83 + assert.ok(findings.some(finding => finding.file === '.github/workflows/check.yaml'));
84 + assert.ok(findings.some(finding => finding.file === '.github/actions/check/action.yml'));
85 +
86 + // Exercise the public command, including the write boundary of --prune.
87 + copyFileSync(
88 + new URL('../scripts/check-antislop.mjs', import.meta.url),
89 + join(cwd, 'scripts/check-antislop.mjs')
90 + );
91 + symlinkSync(new URL('../node_modules', import.meta.url), join(cwd, 'node_modules'), 'junction');
92 + const baselinePath = join(cwd, '.ast-grep/baseline.json');
93 + writeFileSync(baselinePath, JSON.stringify(inventory(findings)) + '\n');
94 + const run = (...args) =>
95 + spawnSync(process.execPath, [join(cwd, 'scripts/check-antislop.mjs'), ...args], {
96 + cwd,
97 + encoding: 'utf8',
98 + });
99 + assert.equal(run().status, 0);
100 + write('ts/packages/core/src/user.ts', '\n\n' + cast);
101 + assert.equal(run().status, 0, 'line-number changes must not invalidate allowances');
102 + write('ts/packages/core/src/user.ts', cast + '\n' + cast);
103 + assert.equal(run().status, 1, 'another identical occurrence must fail');
104 + const beforePrune = readFileSync(baselinePath, 'utf8');
105 + assert.equal(run('--prune').status, 1, 'pruning must reject additional findings');
106 + assert.equal(readFileSync(baselinePath, 'utf8'), beforePrune);
107 + write('ts/packages/core/src/user.ts', cast);
108 + write('python/composio/user.py', 'user = parse_user(external())\n');
109 + assert.equal(run().status, 1, 'resolved findings must be removed from the baseline');
110 + assert.equal(run('--prune').status, 0);
111 + assert.equal(JSON.parse(readFileSync(baselinePath, 'utf8')).length, 7);
112 + assert.equal(run().status, 0);
113 + assert.notEqual(run('--update-baseline').status, 0, 'unknown flags must fail');
114 + write(
115 + '.github/actions/check/action.yml',
116 + 'runs:\n steps:\n # The failure is enforced by a later outcome check.\n # ast-grep-ignore: yaml-continue-on-error\n - name: Capture audit\n continue-on-error: true\n run: pnpm audit\n'
117 + );
118 + assert.ok(!scan(cwd).some(finding => finding.file === '.github/actions/check/action.yml'));
119 + write('ts/packages/core/src/suppressed.ts', '// Reason\n// ast-grep-ignore\n' + cast);
120 + assert.ok(scan(cwd).some(finding => finding.ruleId === 'no-suppress-all'));
121 + write(
122 + 'ts/packages/core/src/suppressed.ts',
123 + '// Reason\n// ast-grep-ignore: ts-double-assertion\nconst user = parseUser(input);'
124 + );
125 + assert.ok(scan(cwd).some(finding => finding.ruleId === 'unused-suppression'));
126 + write('sgconfig.yml', 'ruleDirs: [missing-rules]\n');
127 + assert.throws(() => scan(cwd), /ast-grep failed/);
128 + } finally {
129 + rmSync(cwd, { recursive: true, force: true });
130 + }
131 +});