Skip to content

Commit fdddeb2

Browse files
authored
chore(checks): enforce agent-guidance rules with checks (#10778)
Turn enforceable agent-guidance rules into checks (registry invariants, source audits, exhaustive types, sandbox and permission-group tests) and correct the guidance lines they make false.
1 parent 9df5008 commit fdddeb2

39 files changed

Lines changed: 1336 additions & 175 deletions

‎.agents/skills/add-block/SKILL.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@ Use `wandConfig` on fields that are hard to fill by hand — timestamps (`genera
626626
**Write operation ids and tool ids as string literals** in the `operation` dropdown `options` and
627627
`tools.access`, never through constants (`id: SEARCH`, `access: [SEARCH]`). `scripts/generate-docs.ts`
628628
reads them from source with regexes, so a constant parses as empty: the docs page loses its whole
629-
Actions section and the integration catalog ships blank operation descriptions, with no check failing.
629+
Actions section and the integration catalog ships blank operation descriptions. `generate:docs` now
630+
fails on an id it can't read (in `tools.access` only, a spread of a same-file `const` string array is resolved).
630631

631632
**Preferred:** Use tool names directly as dropdown option IDs to avoid switch cases:
632633
```typescript

‎.agents/skills/add-column-type/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Prefer set-based SQL. When the transform genuinely needs JS (`currency`'s separa
119119
- **Import cycles.** `column-types/select.ts` imports `lib/table/select-values.ts`, so `select-values.ts` must **not** import the registry — that closes a cycle and fails at module init. Inside a type's own helper module the string literal is the implementation, not a config leak.
120120
- **The client-safe boundary.** `registry.ts` and everything it imports must stay free of `@sim/db`, `drizzle-orm`, and `next/server` — the tables grid imports it directly. A React icon is fine (it's a component *reference*, never called server-side). Only `registry.server.ts` may touch drizzle.
121121
- **Don't re-export the registry from `@/lib/table`.** Dozens of server modules import that barrel; routing this through it pulls `@sim/emcn/icons` into all of them. Deep-import `@/lib/table/column-types`.
122-
- **`import.ts`'s `coerceValue` is a SECOND write path and is not opt-in.** Importing into a column of your type always hits it, and its `default` arm silently `String(value)`s — so a missing `case` stores text in a column whose `jsonbCast` is numeric, and then every filter and sort on that column errors in Postgres. Add a `case`, even though the switch compiles without one. (It is deliberately separate from the registry's `coerce`: an import wants an unparseable value to survive as its raw string so the row error can name it.)
122+
- **`import.ts`'s `coerceValue` is a SECOND write path and is not opt-in.** Importing into a column of your type always hits it, and the switch is exhaustive (`colType satisfies never`), so a new type fails to compile until you add its `case`. Pick the arm deliberately: falling back to `String(value)` stores text in a column whose `jsonbCast` may be numeric, and then every filter and sort on that column errors in Postgres. (It is deliberately separate from the registry's `coerce`: an import wants an unparseable value to survive as its raw string so the row error can name it.)
123123
- **CSV inference** is an ordered heuristic in `import.ts`, deliberately not registry-driven. A new type is not inferred from a CSV unless you extend `inferColumnType` — usually you should not, since inference cannot supply configuration (an option set, a currency code).
124124

125125
## If your type owns metadata, read this

‎.agents/skills/v2-api-conventions/SKILL.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Each rule below guards a caller-visible failure: a non-integer `limit` reaching
3030

3131
## Rule 1 — the envelope is produced by helpers, never by hand
3232

33-
`v2Data`, `v2Error`, and the typed error helpers in `response.ts` (`v2ValidationError`, `v2RateLimitError`, `v2HttpError`, `v2InsufficientScope`, `v2HeadNoEffect`, `v2UploadDataPlaneError`) are the only things that build a v2 body. They also set `Cache-Control: private, no-store`, which every v2 response needs because every v2 response is authed per-caller data.
33+
`v2Data`, `v2Error`, and the typed error helpers in `response.ts` (`v2ValidationError`, `v2RateLimitError`, `v2HttpError`, `v2InsufficientScope`, `v2HeadNoEffect`, `v2NoContent`, `v2UploadDataPlaneError`) are the only things that build a v2 body. They also set `Cache-Control: private, no-store`, which every v2 response needs because every v2 response is authed per-caller data.
3434

3535
A route built with `defineV2JsonRoute` gets this for free: its `present` returns the *body shape* and the builder renders it. Never call `NextResponse.json` from a v2 route.
3636

‎.claude/rules/sim-settings-pages.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ and — on activatable rows only — the hover band. Never hand-roll any of it,
186186
overlay. Prefer `href` when the destination is a route, so the row keeps
187187
prefetch, middle-click, and open-in-new-tab. Always pass `clickLabel` with
188188
either — the overlay holds no text, so it is the control's *only* accessible
189-
name. The prop is optional in the type (nothing enforces it), so omitting it
190-
ships a nameless button rather than failing the build.
189+
name. The props type requires it whenever `onClick` or `href` is set.
191190
- `navigable` — appends the one canonical chevron. Set it on rows that open a
192191
detail page; leave it off when `onClick` acts in place (revealing a folder).
193192
Never import an arrow yourself: `lucide-react` and `@sim/emcn/icons` ship

‎.cursor/rules/sim-settings-pages.mdc‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ and — on activatable rows only — the hover band. Never hand-roll any of it,
182182
overlay. Prefer `href` when the destination is a route, so the row keeps
183183
prefetch, middle-click, and open-in-new-tab. Always pass `clickLabel` with
184184
either — the overlay holds no text, so it is the control's *only* accessible
185-
name. The prop is optional in the type (nothing enforces it), so omitting it
186-
ships a nameless button rather than failing the build.
185+
name. The props type requires it whenever `onClick` or `href` is set.
187186
- `navigable` — appends the one canonical chevron. Set it on rows that open a
188187
detail page; leave it off when `onClick` acts in place (revealing a folder).
189188
Never import an arrow yourself: `lucide-react` and `@sim/emcn/icons` ship

‎CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Build order **Tools** → **Block** → **Icon** → optional **Trigger**, from
6363
- **Type coercions go in `tools.config.params`** (runs at execution), never `tools.config.tool` (runs at serialization, where `Number()` destroys `<Block.output>` references).
6464
- **Requests made for a workspace use `outboundFetch`** (`@/lib/core/network/outbound-fetch.server`), never the global `fetch` or another imported `fetch`, so an organization with a dedicated egress gateway keeps its static IPs; `check:organization-egress` enforces this, and a request that rightly goes direct (Sim's own infrastructure, an operator-local server) takes `// egress-direct: <reason>`. AWS SDK clients signing with customer credentials take `organizationAwsRequestHandler()`: no audit catches a missing one, so reviewers check it.
6565
- A surface listing integrations to a viewer reads `useIntegrationAccess`, never a raw catalog (`check:integration-access`).
66-
- Table column types are registry entries in `apps/sim/lib/table/column-types/`; never add a per-type `case` elsewhere except the one documented import-path switch (`coerceValue` in `lib/table/import.ts`), which every new type extends: a missed arm fails silently. Use `/add-column-type`.
66+
- Table column types are registry entries in `apps/sim/lib/table/column-types/`; never add a per-type `case` elsewhere except the one documented import-path switch (`coerceValue` in `lib/table/import.ts`), which every new type extends (its exhaustive `switch` fails to compile until it does). Use `/add-column-type`.
6767

6868
## How your work is checked
6969

‎apps/sim/app/api/v2/lib/response.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ export function v2HeadNoEffect(options: V2SuccessOptions = {}): NextResponse {
165165
return new NextResponse(null, { status: options.status ?? 200, headers: successHeaders(options) })
166166
}
167167

168+
/** A bodiless `204 No Content` (+ rate-limit headers), for a write with nothing to return. */
169+
export function v2NoContent(options: Omit<V2SuccessOptions, 'status'> = {}): NextResponse {
170+
return new NextResponse(null, { status: 204, headers: successHeaders(options) })
171+
}
172+
168173
/** `{ data }` (+ rate-limit headers). */
169174
export function v2Data<T>(data: T, options: V2SuccessOptions = {}): NextResponse {
170175
return NextResponse.json(

‎apps/sim/app/api/v2/uploads/[uploadId]/parts/[partNumber]/route.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createLogger } from '@sim/logger'
2-
import { type NextRequest, NextResponse } from 'next/server'
2+
import type { NextRequest, NextResponse } from 'next/server'
33
import { localUploadPartContract } from '@/lib/api/contracts/upload-sessions'
44
import { parseRequest } from '@/lib/api/server'
55
import { V2_PARSE_DEFAULTS } from '@/lib/api/server/routes'
@@ -18,6 +18,7 @@ import {
1818
v2CaughtOrchestrationError,
1919
v2Error,
2020
v2HttpError,
21+
v2NoContent,
2122
v2UploadDataPlaneError,
2223
} from '@/app/api/v2/lib/response'
2324

@@ -116,7 +117,7 @@ export const PUT = withRouteHandler(
116117
error,
117118
})
118119
}
119-
return new NextResponse(null, { status: 204 })
120+
return v2NoContent()
120121
},
121122
{
122123
typedErrorResponse: ({ error }) => v2HttpError(error),

‎apps/sim/app/api/v2/uploads/[uploadId]/route.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createLogger } from '@sim/logger'
2-
import { type NextRequest, NextResponse } from 'next/server'
2+
import type { NextRequest, NextResponse } from 'next/server'
33
import { localPutUploadContract } from '@/lib/api/contracts/upload-sessions'
44
import { parseRequest } from '@/lib/api/server'
55
import { V2_PARSE_DEFAULTS } from '@/lib/api/server/routes'
@@ -10,7 +10,12 @@ import {
1010
getOwnedUploadSession,
1111
uploadSessionObjectMetadata,
1212
} from '@/lib/uploads/upload-session/service'
13-
import { v2Error, v2HttpError, v2UploadDataPlaneError } from '@/app/api/v2/lib/response'
13+
import {
14+
v2Error,
15+
v2HttpError,
16+
v2NoContent,
17+
v2UploadDataPlaneError,
18+
} from '@/app/api/v2/lib/response'
1419

1520
const logger = createLogger('LocalUpload')
1621

@@ -106,7 +111,7 @@ export const PUT = withRouteHandler(
106111
error,
107112
})
108113
}
109-
return new NextResponse(null, { status: 204 })
114+
return v2NoContent()
110115
},
111116
{
112117
typedErrorResponse: ({ error }) => v2HttpError(error),

‎apps/sim/app/workspace/[workspaceId]/settings/[section]/settings.tsx‎

Lines changed: 107 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -102,76 +102,128 @@ function SettingsPageContent({ section }: SettingsPageProps) {
102102

103103
return (
104104
<SettingsSectionProvider section={effectiveSection} meta={meta ?? undefined}>
105-
{effectiveSection === 'general' && <General />}
106-
{effectiveSection === 'desktop' && <Desktop />}
107-
{effectiveSection === 'browser' && <Browser />}
108-
{effectiveSection === 'terminal' && <Terminal />}
109-
{effectiveSection === 'secrets' && <Secrets />}
110-
{effectiveSection === 'connected-accounts' && organizationId && (
105+
<SettingsSectionBody
106+
section={effectiveSection}
107+
organizationId={organizationId}
108+
workspaceId={hostContext.workspace.id}
109+
isHostOrganizationAdmin={hostContext.viewer.isHostOrganizationAdmin}
110+
/>
111+
</SettingsSectionProvider>
112+
)
113+
}
114+
115+
interface SettingsSectionBodyProps {
116+
section: SettingsSection
117+
organizationId: string | null
118+
workspaceId: string
119+
isHostOrganizationAdmin: boolean
120+
}
121+
122+
/**
123+
* The one place a section id becomes its page. Exhaustive over {@link SettingsSection}: a new
124+
* section fails compilation here until it renders something.
125+
*/
126+
function SettingsSectionBody({
127+
section,
128+
organizationId,
129+
workspaceId,
130+
isHostOrganizationAdmin,
131+
}: SettingsSectionBodyProps) {
132+
switch (section) {
133+
case 'general':
134+
return <General />
135+
case 'desktop':
136+
return <Desktop />
137+
case 'browser':
138+
return <Browser />
139+
case 'terminal':
140+
return <Terminal />
141+
case 'secrets':
142+
return <Secrets />
143+
case 'connected-accounts':
144+
return organizationId ? (
111145
<OrganizationConnectedAccounts organizationId={organizationId} />
112-
)}
113-
{effectiveSection === 'access-control' && organizationId && (
146+
) : null
147+
case 'access-control':
148+
return organizationId ? (
114149
<AccessControl
115150
organizationId={organizationId}
116-
isOrganizationAdmin={hostContext.viewer.isHostOrganizationAdmin}
117-
requestsHref={`/workspace/${hostContext.workspace.id}/settings/requests`}
151+
isOrganizationAdmin={isHostOrganizationAdmin}
152+
requestsHref={`/workspace/${workspaceId}/settings/requests`}
118153
/>
119-
)}
120-
{effectiveSection === 'requests' && organizationId && (
154+
) : null
155+
case 'requests':
156+
return organizationId ? (
121157
<AccessRequestsSettings
122-
scope={{ kind: 'workspace', workspaceId: hostContext.workspace.id }}
123-
reviewOrganizationId={
124-
hostContext.viewer.isHostOrganizationAdmin ? organizationId : undefined
125-
}
158+
scope={{ kind: 'workspace', workspaceId }}
159+
reviewOrganizationId={isHostOrganizationAdmin ? organizationId : undefined}
126160
/>
127-
)}
128-
{effectiveSection === 'custom-blocks' && <CustomBlocks />}
129-
{effectiveSection === 'audit-logs' && organizationId && (
130-
<AuditLogs organizationId={organizationId} />
131-
)}
132-
{effectiveSection === 'usage' && organizationId && (
161+
) : null
162+
case 'custom-blocks':
163+
return <CustomBlocks />
164+
case 'audit-logs':
165+
return organizationId ? <AuditLogs organizationId={organizationId} /> : null
166+
case 'usage':
167+
return organizationId ? (
133168
<UsageMonitoring
134169
organizationId={organizationId}
135-
eventsHref={`/workspace/${hostContext.workspace.id}/settings/usage/events`}
136-
auditLogsHref={`/workspace/${hostContext.workspace.id}/settings/audit-logs`}
170+
eventsHref={`/workspace/${workspaceId}/settings/usage/events`}
171+
auditLogsHref={`/workspace/${workspaceId}/settings/audit-logs`}
137172
/>
138-
)}
139-
{effectiveSection === 'apikeys' && <ApiKeys scope='combined' />}
140-
{billingEnabled && effectiveSection === 'billing' && (
173+
) : null
174+
case 'apikeys':
175+
return <ApiKeys scope='combined' />
176+
case 'billing':
177+
return (
141178
<Billing
142179
scope={organizationId ? 'organization' : 'account'}
143180
organizationId={organizationId ?? undefined}
144-
creditUsageHref={`/workspace/${hostContext.workspace.id}/settings/billing/credit-usage`}
181+
creditUsageHref={`/workspace/${workspaceId}/settings/billing/credit-usage`}
145182
/>
146-
)}
147-
{effectiveSection === 'teammates' && <Teammates />}
148-
{effectiveSection === 'organization' && organizationId && (
183+
)
184+
case 'teammates':
185+
return <Teammates />
186+
case 'organization':
187+
return organizationId ? (
149188
<TeamManagement
150189
organizationId={organizationId}
151-
billingHref={`/workspace/${hostContext.workspace.id}/settings/billing`}
190+
billingHref={`/workspace/${workspaceId}/settings/billing`}
152191
/>
153-
)}
154-
{effectiveSection === 'sso' && organizationId && <SSO organizationId={organizationId} />}
155-
{effectiveSection === 'data-retention' && organizationId && (
156-
<DataRetentionSettings organizationId={organizationId} />
157-
)}
158-
{effectiveSection === 'data-drains' && organizationId && (
159-
<DataDrainsSettings organizationId={organizationId} />
160-
)}
161-
{effectiveSection === 'security' && organizationId && (
192+
) : null
193+
case 'sso':
194+
return organizationId ? <SSO organizationId={organizationId} /> : null
195+
case 'data-retention':
196+
return organizationId ? <DataRetentionSettings organizationId={organizationId} /> : null
197+
case 'data-drains':
198+
return organizationId ? <DataDrainsSettings organizationId={organizationId} /> : null
199+
case 'security':
200+
return organizationId ? (
162201
<OrganizationSecuritySettings organizationId={organizationId} />
163-
)}
164-
{effectiveSection === 'byok' && <BYOK />}
165-
{effectiveSection === 'sandboxes' && <Sandboxes />}
166-
{effectiveSection === 'mcp' && <MCP />}
167-
{effectiveSection === 'forks' && <Forks />}
168-
{effectiveSection === 'custom-tools' && <CustomTools />}
169-
{effectiveSection === 'workflow-mcp-servers' && <WorkflowMcpServers />}
170-
{effectiveSection === 'inbox' && <Inbox />}
171-
{effectiveSection === 'recently-deleted' && <RecentlyDeleted />}
172-
{effectiveSection === 'self-host' && <SelfHost />}
173-
{effectiveSection === 'admin' && <Admin />}
174-
{effectiveSection === 'mothership' && <Mothership />}
175-
</SettingsSectionProvider>
176-
)
202+
) : null
203+
case 'byok':
204+
return <BYOK />
205+
case 'sandboxes':
206+
return <Sandboxes />
207+
case 'mcp':
208+
return <MCP />
209+
case 'forks':
210+
return <Forks />
211+
case 'custom-tools':
212+
return <CustomTools />
213+
case 'workflow-mcp-servers':
214+
return <WorkflowMcpServers />
215+
case 'inbox':
216+
return <Inbox />
217+
case 'recently-deleted':
218+
return <RecentlyDeleted />
219+
case 'self-host':
220+
return <SelfHost />
221+
case 'admin':
222+
return <Admin />
223+
case 'mothership':
224+
return <Mothership />
225+
default:
226+
section satisfies never
227+
return null
228+
}
177229
}

0 commit comments

Comments
 (0)