Skip to content

Commit f37d9d9

Browse files
committed
improvement(tools): simplify effect projection, policy input and rule text
1 parent be60cfa commit f37d9d9

15 files changed

Lines changed: 110 additions & 153 deletions

File tree

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,8 @@ Never point a tool at `/api/...`, construct an absolute URL back to Sim, declare
190190
resources. A real external/browser route and an in-process tool may share the same operation, but
191191
neither calls the other. Follow the full transport and handler rules in the `add-tools` skill.
192192

193-
Every tool declares `effect: 'read' | 'write'`. `read` means the call changes nothing outside Sim:
194-
no create, update, delete, send, post, trigger, enqueue, consume, or mark-read; no job, run,
195-
conversation, history item, or other resource left in an account; no contact data revealed for
196-
credits; no external delivery (usage billing for the call itself does not count). Anything else,
197-
anything that depends on its params, and anything you are unsure of is `write`. Revealing a
198-
person's contact data (email, phone) for credits is `write`; company/firmographic lookups and
199-
verifications that only spend lookup credits are `read`. Classify from the API docs you researched in Step 1; the full rules are in `add-tools` →
200-
Declaring the effect, and `bun run check:tool-effects` enforces them.
193+
Every tool declares `effect: 'read' | 'write'`, classified from the API docs you researched in Step 1
194+
by the rules in `add-tools` → Declaring the effect; `bun run check:tool-effects` enforces them.
201195

202196
**types.ts:**
203197
```typescript

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ fallback, or caller-controlled `_context` authority.
187187

188188
## Declaring the effect
189189

190-
Every tool declares `effect: 'read' | 'write'` (required by `ToolConfig`; `bun run check:tool-effects`
191-
fails a registered tool without one). It is public catalog metadata: Assistant applies its read or
192-
write policy by it, and `sim blocks get` and `sim workflows source params` show it to agents.
190+
Every tool declares `effect: 'read' | 'write'` (required by `ToolConfig`, so type-check fails a tool
191+
without one). It is public catalog metadata: Assistant applies its read or write policy by it, and
192+
`sim blocks get` and `sim workflows source params` show it to agents.
193193
Labelling a write `read` is the one unsafe mistake, so classify from the provider's documented
194194
semantics, never the name alone.
195195

@@ -198,25 +198,24 @@ enqueue, consume, or mark-read; no job, run, conversation, history item, or othe
198198
an account; no contact data revealed for credits; no external delivery. Usage billing for the call
199199
itself does not count. `write` is anything else.
200200

201-
**Contact reveals:** revealing a person's contact data (email, phone) for credits is `write`;
202-
company/firmographic lookups and verifications that only spend lookup credits are `read`. An email
203-
or phone finder, a person enrichment that returns an email or phone, and a domain search that lists
204-
people's emails are `write` even over GET (carry `// tool-effect:`); a company enrichment, a people
205-
search that returns no email or phone, and an email verifier stay `read`.
201+
**Contact reveals:** revealing a person's contact data (email, phone) for credits is `write`: an
202+
email or phone finder, a person enrichment that returns an email or phone, and a domain search that
203+
lists people's emails are `write` even over GET (carry `// tool-effect:`). Company/firmographic
204+
lookups and verifications that only spend lookup credits are `read`: a company enrichment, a people
205+
search that returns no email or phone, and an email verifier.
206206

207207
- `read`: GET/HEAD reads, and POST endpoints the docs define as search, query, list, get, lookup, or
208208
verify; LLM, embedding, transcription, TTS, and media-generation calls that leave nothing in the
209-
provider account; company/firmographic enrichment and verifications that only spend lookup
210-
credits; queries the server enforces as read-only (a read-only transaction or setting, never a
211-
client-side screen alone).
209+
provider account; queries the server enforces as read-only (a read-only transaction or setting,
210+
never a client-side screen alone).
212211
- `write`: an effect that depends on the params (a `method` param or function-valued
213212
`request.method` that can pick PUT/PATCH/DELETE or a mutating POST, raw SQL or Cypher the server
214213
does not restrict to reads, a generic RPC or command); a GET whose `transformResponse` or
215214
`postProcess` then writes; a read that consumes or acknowledges (a queue receive, mark-as-read);
216215
media generation, transcription, crawls, exports, and research or agent runs that leave a job,
217-
run, asset, or history item in the provider account; a chat that keeps a conversation; a
218-
person's email or phone revealed for credits; a reveal or enrichment that creates a resource or
219-
delivers to a webhook; anything that saves to the workspace. When unsure, `write`.
216+
run, asset, or history item in the provider account; a chat that keeps a conversation; a reveal
217+
or enrichment that creates a resource or delivers to a webhook; anything that saves to the
218+
workspace. When unsure, `write`.
220219
- PUT/PATCH/DELETE are `write`. A static GET/HEAD labelled `write`, or PUT/PATCH/DELETE labelled
221220
`read`, fails the audit unless the `effect` line carries `// tool-effect: <reason>` on one of the
222221
two lines above it; use it only for a genuine exception such as a GET that writes in `postProcess`.

‎.agents/skills/validate-integration/SKILL.md‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,8 @@ For **every** tool file, check:
7878
- [ ] Tool `version` is set (`'1.0.0'` or `'2.0.0'` for V2)
7979

8080
### Effect
81-
- [ ] Every tool declares `effect`, and the label matches the API docs, not the name: `read` only
82-
when the call changes nothing outside Sim (no create, update, delete, send, trigger, consume,
83-
or mark-read, and no job, run, conversation, history item, or other resource left in the
84-
provider account, and no person's email or phone revealed for credits); a param-dependent
85-
effect (method param, raw SQL guarded only by a client-side screen, generic command), a GET
86-
whose `transformResponse`/`postProcess` writes, and anything uncertain are `write`;
87-
company/firmographic lookups and verifications that only spend lookup credits stay `read`
88-
(rules: `add-tools` → Declaring the effect)
81+
- [ ] Every tool declares `effect`, and the label matches the API docs, not the name (rules:
82+
`add-tools` → Declaring the effect)
8983
- [ ] Any `// tool-effect: <reason>` sits on a genuine verb/label exception, and
9084
`bun run check:tool-effects` passes
9185

‎CLAUDE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Use the `test-audit` skill whenever you write, change, or review tests; mechanic
5959
Build order **Tools** → **Block** → **Icon** → optional **Trigger**, from the service's API docs, using `/add-integration` (or `/add-tools`, `/add-block`, `/add-trigger`).
6060

6161
- **Tool IDs are `snake_case`** (`service_action`), registered in `tools/registry.ts`; blocks register alphabetically in `blocks/registry-maps.ts`.
62-
- **Every tool declares `effect: 'read' | 'write'`**: `read` only when the call changes nothing outside Sim (no write, send, trigger, or consume, and no job, run, or other resource left in an account; usage billing aside); `write` otherwise, including param-dependent effects and anything uncertain. Revealing a person's contact data (email, phone) for credits is `write`; company/firmographic lookups and verifications that only spend lookup credits are `read` (`check:tool-effects`; rules in `/add-tools`).
62+
- **Every tool declares `effect: 'read' | 'write'`**: `read` only when the call changes nothing outside Sim, `write` otherwise and whenever unsure (`ToolEffect` in `tools/types.ts`; `check:tool-effects`; rules in `/add-tools` → Declaring the effect).
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`).

‎apps/sim/lib/assistant-actions/application/context.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ export async function resolveAssistantActionPolicy(
117117
'This operation requires your active connected account.'
118118
)
119119
const permissions = await loadAssistantToolPermissions(scope, executor)
120-
const policy = resolveAssistantToolPolicy(permissions, input.toolId, {
121-
effect: tool.effect,
122-
version: tool.assistant.version,
123-
})
120+
const policy = resolveAssistantToolPolicy(permissions, input.toolId, tool.effect, tool.assistant)
124121
if (policy === 'block')
125122
throw new OrchestrationError('forbidden', 'This tool is blocked in your account permissions.')
126123
return { binding, policy: policy === 'allow' && !canAutoApprove ? ('ask' as const) : policy }

‎apps/sim/lib/assistant-actions/application/tool-permissions.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ export const readOrganizationToolPermissions = defineAuthorizedOrganizationUseCa
5555
description: config.description,
5656
effect: config.effect,
5757
version: config.assistant.version,
58-
policy: resolveAssistantToolPolicy(permissions, toolId, {
59-
effect: config.effect,
60-
version: config.assistant.version,
61-
}),
58+
policy: resolveAssistantToolPolicy(
59+
permissions,
60+
toolId,
61+
config.effect,
62+
config.assistant
63+
),
6264
inherited: permissions.overrides[toolId] === undefined,
6365
},
6466
]

‎apps/sim/lib/assistant-actions/tool-permissions.integration.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -833,15 +833,17 @@ describe('organization Assistant tool permissions', () => {
833833
const saved = await loadAssistantToolPermissions({ ...input, userId: ownerId })
834834
const tool = getToolMetadata('gmail_list_labels_v2')
835835
if (!tool?.assistant) throw new Error('Fixture operation is unavailable')
836-
const operation = { effect: tool.effect, version: tool.assistant.version }
837-
expect(resolveAssistantToolPolicy(saved, 'gmail_list_labels_v2', operation)).toBe('allow')
838836
expect(
839-
resolveAssistantToolPolicy(saved, 'gmail_list_labels_v2', {
840-
...operation,
841-
version: operation.version + 1,
837+
resolveAssistantToolPolicy(saved, 'gmail_list_labels_v2', tool.effect, tool.assistant)
838+
).toBe('allow')
839+
expect(
840+
resolveAssistantToolPolicy(saved, 'gmail_list_labels_v2', tool.effect, {
841+
version: tool.assistant.version + 1,
842842
})
843843
).toBe('ask')
844-
expect(resolveAssistantToolPolicy(saved, 'future_operation', operation)).toBe('ask')
844+
expect(resolveAssistantToolPolicy(saved, 'future_operation', tool.effect, tool.assistant)).toBe(
845+
'ask'
846+
)
845847
})
846848

847849
it.each(['ask', 'block'] as const)(

‎apps/sim/lib/assistant-actions/tool-permissions.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { sameResourceScopeCondition } from '@/lib/core/resource-scope.server'
1515
import { isManagedCredentialGroupBindingLive } from '@/lib/credential-groups/credentials'
1616
import { acquireAdvisoryXactLock, withLockTimeout } from '@/lib/db/advisory-locks'
1717
import type { DbOrTx, DbTransaction } from '@/lib/db/types'
18-
import type { ToolEffect } from '@/tools/types'
18+
import type { AssistantOperationMetadata, ToolEffect } from '@/tools/types'
1919

2020
/** One serialization point for settings changes and admission, including accounts with no saved preference. */
2121
export async function lockAssistantToolPermissions(
@@ -107,15 +107,16 @@ export async function loadAssistantToolPermissions(
107107
export function resolveAssistantToolPolicy(
108108
permissions: AssistantToolPermissions,
109109
toolId: string,
110-
operation: { effect: ToolEffect; version: number }
110+
effect: ToolEffect,
111+
assistant: Pick<AssistantOperationMetadata, 'version'>
111112
) {
112113
const override = permissions.overrides[toolId]
113114
if (override) {
114115
if (override.policy === 'block') return 'block'
115-
if (override.version !== operation.version) return 'ask'
116+
if (override.version !== assistant.version) return 'ask'
116117
return override.policy
117118
}
118-
return operation.effect === 'read' ? permissions.readPolicy : permissions.writePolicy
119+
return effect === 'read' ? permissions.readPolicy : permissions.writePolicy
119120
}
120121

121122
/** Caller holds the account policy lock and has already checked the expected revision. */

‎apps/sim/lib/workflows/code/catalog/project.ts‎

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -464,22 +464,43 @@ function projectOutput(definition: unknown): CatalogOutput | undefined {
464464
}
465465

466466
/**
467-
* Per operation, the block outputs its tool declares and which of them it may return as `null`,
468-
* when the operation picks the tool (`tools.selector: 'operation'`). Kept only where that differs
469-
* from every block output, non-null.
467+
* Each operation's tool id, when the operation alone picks a tool in `tools.access` for every
468+
* operation (`tools.selector: 'operation'`); `null` otherwise.
470469
*/
471-
function projectOperationOutputs(
470+
function resolveOperationTools(
472471
block: BlockConfig,
473-
operations: readonly string[],
474-
outputNames: readonly string[]
475-
): CatalogBlock['operationOutputs'] {
472+
operations: readonly string[]
473+
): Map<string, string> | null {
476474
const selectTool = block.tools.config?.tool
477-
if (!selectTool) return undefined
478-
const projected: NonNullable<CatalogBlock['operationOutputs']> = {}
475+
if (!selectTool || operations.length === 0) return null
476+
const access = new Set(block.tools.access)
477+
const operationTools = new Map<string, string>()
479478
for (const operation of operations) {
480479
const probe = probeThunk(selectTool, { operation })
481-
if (!probe.ok || typeof probe.result !== 'string') continue
482-
const toolOutputs = getToolOutputsMetadata(probe.result)
480+
if (
481+
!probe.ok ||
482+
!readsOnly(probe.reads, OPERATION_ONLY) ||
483+
typeof probe.result !== 'string' ||
484+
!access.has(probe.result)
485+
) {
486+
return null
487+
}
488+
operationTools.set(operation, probe.result)
489+
}
490+
return operationTools
491+
}
492+
493+
/**
494+
* Per operation, the block outputs its tool declares and which of them it may return as `null`.
495+
* Kept only where that differs from every block output, non-null.
496+
*/
497+
function projectOperationOutputs(
498+
operationTools: ReadonlyMap<string, string>,
499+
outputNames: readonly string[]
500+
): CatalogBlock['operationOutputs'] {
501+
const projected: NonNullable<CatalogBlock['operationOutputs']> = {}
502+
for (const [operation, toolId] of operationTools) {
503+
const toolOutputs = getToolOutputsMetadata(toolId)
483504
if (!toolOutputs) continue
484505
const names = outputNames.filter((name) => Object.hasOwn(toolOutputs, name))
485506
const nullable = names.filter((name) => toolOutputs[name]?.nullable === true)
@@ -497,41 +518,31 @@ function projectOperationOutputs(
497518
*/
498519
function projectEffects(
499520
block: BlockConfig,
500-
operations: readonly string[],
501-
selector: CatalogBlock['tools']['selector']
521+
operationTools: ReadonlyMap<string, string> | null
502522
): Pick<CatalogBlock, 'effect' | 'operationEffects'> {
503523
if (block.tools.access.length === 0) return {}
504-
const effects = block.tools.access.map((toolId) => getToolMetadata(toolId)?.effect ?? 'write')
505-
const effect = effects.every((entry) => entry === 'read') ? 'read' : 'write'
506-
const selectTool = block.tools.config?.tool
507-
if (effect === 'read' || selector !== 'operation' || !selectTool) return { effect }
524+
const accessEffects = new Map(
525+
block.tools.access.map(
526+
(toolId) => [toolId, getToolMetadata(toolId)?.effect ?? 'write'] as const
527+
)
528+
)
529+
const effect = [...accessEffects.values()].every((entry) => entry === 'read') ? 'read' : 'write'
530+
if (effect === 'read' || !operationTools) return { effect }
508531
const operationEffects: NonNullable<CatalogBlock['operationEffects']> = {}
509-
for (const operation of operations) {
510-
const probe = probeThunk(selectTool, { operation })
511-
if (!probe.ok || typeof probe.result !== 'string') continue
512-
const operationEffect = getToolMetadata(probe.result)?.effect ?? 'write'
532+
for (const [operation, toolId] of operationTools) {
533+
const operationEffect = accessEffects.get(toolId) ?? 'write'
513534
if (operationEffect !== effect) operationEffects[operation] = operationEffect
514535
}
515536
return Object.keys(operationEffects).length > 0 ? { effect, operationEffects } : { effect }
516537
}
517538

518-
function projectTools(block: BlockConfig, operations: readonly string[]): CatalogBlock['tools'] {
539+
function projectTools(
540+
block: BlockConfig,
541+
operationTools: ReadonlyMap<string, string> | null
542+
): CatalogBlock['tools'] {
519543
const access = [...block.tools.access]
520-
const selectTool = block.tools.config?.tool
521-
if (!selectTool) return { access, selector: 'single' }
522-
const accessSet = new Set(access)
523-
const perOperation =
524-
operations.length > 0 &&
525-
operations.every((operation) => {
526-
const probe = probeThunk(selectTool, { operation })
527-
return (
528-
probe.ok &&
529-
readsOnly(probe.reads, OPERATION_ONLY) &&
530-
typeof probe.result === 'string' &&
531-
accessSet.has(probe.result)
532-
)
533-
})
534-
return { access, selector: perOperation ? 'operation' : 'opaque' }
544+
if (!block.tools.config?.tool) return { access, selector: 'single' }
545+
return { access, selector: operationTools ? 'operation' : 'opaque' }
535546
}
536547

537548
function projectGraph(block: BlockConfig): CatalogBlockGraph {
@@ -614,6 +625,7 @@ function builtInOutputs(block: BlockConfig): BlockConfig['outputs'] {
614625
/** Projects one registry block (built-in or custom) into the core-shard shape. */
615626
export function projectBlock(block: BlockConfig): CatalogBlock {
616627
const operations = operationOptions(block).map((operation) => operation.id)
628+
const operationTools = resolveOperationTools(block, operations)
617629
const tagSurface = block.subBlocks.some((subBlock) => subBlockSurface(subBlock) === 'trigger')
618630
const ctx: SubBlockContext = {
619631
operations,
@@ -626,7 +638,7 @@ export function projectBlock(block: BlockConfig): CatalogBlock {
626638
name: block.name,
627639
category: block.category,
628640
subBlocks: block.subBlocks.map((subBlock) => projectSubBlock(subBlock, ctx)),
629-
tools: projectTools(block, operations),
641+
tools: projectTools(block, operationTools),
630642
outputs: projectOutputRecord(builtInOutputs(block)),
631643
graph: projectGraph(block),
632644
}
@@ -639,15 +651,11 @@ export function projectBlock(block: BlockConfig): CatalogBlock {
639651
? { status: block.sunset.status, replacedBy: block.sunset.replacedBy }
640652
: { status: block.sunset.status }
641653
}
642-
if (projected.tools.selector === 'operation') {
643-
const operationOutputs = projectOperationOutputs(
644-
block,
645-
operations,
646-
Object.keys(projected.outputs)
647-
)
654+
if (operationTools) {
655+
const operationOutputs = projectOperationOutputs(operationTools, Object.keys(projected.outputs))
648656
if (operationOutputs) projected.operationOutputs = operationOutputs
649657
}
650-
Object.assign(projected, projectEffects(block, operations, projected.tools.selector))
658+
Object.assign(projected, projectEffects(block, operationTools))
651659
if (Object.keys(lifecycle).length > 0) projected.lifecycle = lifecycle
652660
if (block.hideFromToolbar) projected.addable = false
653661
assign(projected, 'triggerAllowed', block.triggerAllowed)

‎apps/sim/tools/sailpoint/definitions.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,7 @@ import type {
7575
SailPointSourceItemRef,
7676
} from '@/tools/sailpoint/types'
7777
import { SAILPOINT_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
78-
import type {
79-
InternalToolConfig,
80-
ToolConfig,
81-
ToolEffect,
82-
ToolParameterItemSchema,
83-
} from '@/tools/types'
78+
import type { InternalToolConfig, ToolConfig, ToolParameterItemSchema } from '@/tools/types'
8479

8580
type ToolParams = ToolConfig['params']
8681

@@ -205,7 +200,7 @@ interface SailPointDefinition<P extends SailPointCredentials> {
205200
id: string
206201
name: string
207202
description: string
208-
effect: ToolEffect
203+
effect: ToolConfig['effect']
209204
params: ToolParams
210205
input: (params: P) => Record<string, unknown>
211206
outputs: ToolConfig['outputs']

0 commit comments

Comments
 (0)