Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6b56b5f
test(workflow-code): give the near-maxBlocks scaling case a timeout t…
waleedlatif1 Nov 22, 2026
a184906
fix(sim-cli): read a workspace diff filter with the shared linear nor…
waleedlatif1 Nov 22, 2026
491a150
fix(sim-cli): read table column calls in linear time
waleedlatif1 Nov 22, 2026
97c1f0a
refactor(sim-cli): import normalizeWorkflowBlockName instead of resta…
waleedlatif1 Nov 22, 2026
14a00a4
test(workflow-code): give the package's scaling cases a timeout that …
waleedlatif1 Nov 22, 2026
0ad36bb
refactor(workflow-code): count UTF-8 bytes with @sim/utils/paste utf8…
waleedlatif1 Nov 22, 2026
65cf15b
refactor(workflow-code): derive REFUSABLE_WARNING_CODES from the refu…
waleedlatif1 Nov 22, 2026
d597b48
refactor(workflow-code): share memberName and babelMessage instead of…
waleedlatif1 Nov 22, 2026
1da9ebe
refactor(workflow-code): build subflow repair messages from the runti…
waleedlatif1 Nov 22, 2026
392e219
refactor(workspace-code): print declaration numbers with workflow-cod…
waleedlatif1 Nov 22, 2026
5c9d29e
refactor(workflow-sdk): strip line comments without a cross-line whit…
waleedlatif1 Nov 22, 2026
ba42e99
perf(workspace-code): meet server changes with local ones through a m…
waleedlatif1 Nov 22, 2026
3138620
test(workflow-sdk): drop the embedded-text drift tests check:workflow…
waleedlatif1 Nov 22, 2026
9fcbb6c
fix(sim-cli): name every strict check warning in the directory guides
waleedlatif1 Nov 22, 2026
6773811
docs(workflow-code): correct staged-blob expiry and the rule's stale …
waleedlatif1 Nov 22, 2026
3af4fb1
docs(workflow-code): list every diagnostic code in SYNTAX.md and test…
waleedlatif1 Nov 22, 2026
638ad2a
test(sim-cli): check the scripting docs' source exit-code tables agai…
waleedlatif1 Nov 22, 2026
83c49a0
perf(workspace-source): upload staged blobs four at a time
waleedlatif1 Nov 22, 2026
3294b9f
refactor(workspace-source): share named.ts changedFields with the MCP…
waleedlatif1 Nov 22, 2026
550436e
refactor: drop dead exports the feature carried over
waleedlatif1 Nov 22, 2026
36ff416
test(workflow-sdk): keep the source type-check command on the TypeScr…
waleedlatif1 Nov 22, 2026
cd4b31d
refactor(workflow-code): simplify pass over the audit changes
waleedlatif1 Nov 22, 2026
40d988f
test: pin the root-file kind branch of sourceStatus and refuse an emp…
waleedlatif1 Nov 22, 2026
495bf5b
Merge remote-tracking branch 'origin/staging' into refactor/workflow-…
waleedlatif1 Nov 22, 2026
a99c574
test(workflow-sdk): move the SYNTAX.md diagnostics-table check out of…
waleedlatif1 Nov 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .claude/rules/sim-workflow-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ satisfy.
2. A codec `packages/workspace-code/src/kinds/<kind>.ts` with tests; `KIND_LAYOUTS`, and
`BLOB_KIND_CODECS` if it holds blobs (`src/kinds/registry.ts`); its diagnostic codes.
3. An adapter `apps/sim/lib/workspace-source/application/kinds/<kind>/adapter.ts` calling the
kind's own use cases; `KIND_ADAPTERS` (`application/registry.ts`) and `NOUNS`
(`application/findings.ts`); an integration test.
kind's own use cases; `KIND_ADAPTERS` (`application/registry.ts`); an integration test.
4. If workflows name it by key: `WORKFLOW_RESOURCE_KINDS`, the live loader in
`lib/workspaces/resource-keys.ts`, the manifest in `read-source-resources.ts` and
`codegen/workspace.ts`, and `PENDABLE_REFERENCES` in
Expand Down Expand Up @@ -222,5 +221,6 @@ Behaviour is proven by properties over the real registry, not restated unit test
- The Code tab and the CLI have HTTP e2e scripts (`apps/sim/scripts/test-workflow-code-ui-e2e.ts`,
`test-workflow-source-e2e.ts`, `test-workspace-source-e2e.ts`).
- Generated artifacts and their checks: `generate:sdk-names` (`check:sdk-names`,
`check:sdk-names-frozen`), the SDK embedded text (its `*-text.test.ts`), goldens
(`check:workflow-code-golden`).
`check:sdk-names-frozen`), `generate:workflow-sdk-embedded-text`
(`check:workflow-sdk-embedded-text`), `generate:sdk-fixture-catalog`
(`check:sdk-fixture-catalog`), goldens (`check:workflow-code-golden`).
8 changes: 4 additions & 4 deletions .cursor/rules/sim-workflow-code.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ satisfy.
2. A codec `packages/workspace-code/src/kinds/<kind>.ts` with tests; `KIND_LAYOUTS`, and
`BLOB_KIND_CODECS` if it holds blobs (`src/kinds/registry.ts`); its diagnostic codes.
3. An adapter `apps/sim/lib/workspace-source/application/kinds/<kind>/adapter.ts` calling the
kind's own use cases; `KIND_ADAPTERS` (`application/registry.ts`) and `NOUNS`
(`application/findings.ts`); an integration test.
kind's own use cases; `KIND_ADAPTERS` (`application/registry.ts`); an integration test.
4. If workflows name it by key: `WORKFLOW_RESOURCE_KINDS`, the live loader in
`lib/workspaces/resource-keys.ts`, the manifest in `read-source-resources.ts` and
`codegen/workspace.ts`, and `PENDABLE_REFERENCES` in
Expand Down Expand Up @@ -202,5 +201,6 @@ Behaviour is proven by properties over the real registry, not restated unit test
- The Code tab and the CLI have HTTP e2e scripts (`apps/sim/scripts/test-workflow-code-ui-e2e.ts`,
`test-workflow-source-e2e.ts`, `test-workspace-source-e2e.ts`).
- Generated artifacts and their checks: `generate:sdk-names` (`check:sdk-names`,
`check:sdk-names-frozen`), the SDK embedded text (its `*-text.test.ts`), goldens
(`check:workflow-code-golden`).
`check:sdk-names-frozen`), `generate:workflow-sdk-embedded-text`
(`check:workflow-sdk-embedded-text`), `generate:sdk-fixture-catalog`
(`check:sdk-fixture-catalog`), goldens (`check:workflow-code-golden`).
2 changes: 1 addition & 1 deletion apps/docs/content/docs/workflows/code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Nothing in the file runs on your machine. Sim reads it statically, checks it aga
sim workflows source check --dir ./support-triage
```

It exits 1 on an error, and on a missing required field, an unknown option or output path, a wrong value kind, an out-of-range value, an unwired condition or router branch or a literal secret in a block you added since the get (`--strict` fails on these in every block, except an unwired branch on a block the get printed, which the stored workflow may hold; `--no-strict` never fails on a warning). It also adds the blocks the workflow now uses to `tsconfig.json`. Your editor type-checks the file against the generated declarations, and `bunx -p typescript@7.0.2 tsc -p ./support-triage` checks it from the command line with the TypeScript release the declarations are built for; `-p ./support-triage/tsconfig.full.json` type-checks against every block.
It exits 1 on an error, and on the warnings `sim workflows source check --help` lists (a missing required field, an unknown option, an unwired condition or router branch, a literal secret and more) in a block you added since the get (`--strict` fails on these in every block, except an unwired branch on a block the get printed, which the stored workflow may hold; `--no-strict` never fails on a warning). It also adds the blocks the workflow now uses to `tsconfig.json`. Your editor type-checks the file against the generated declarations, and `bunx -p typescript@7.0.2 tsc -p ./support-triage` checks it from the command line with the TypeScript release the declarations are built for; `-p ./support-triage/tsconfig.full.json` type-checks against every block.

3. See what changed, and whether someone changed the workflow since your `get`:

Expand Down
4 changes: 2 additions & 2 deletions apps/sim/lib/workspace-source/api/route-policies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { utf8ByteLength } from '@sim/utils/paste'
import { boundAnswerFindings } from '@sim/workflow-code/diagnostics'
import { utf8Bytes } from '@sim/workflow-code/limits'
import { type BlobEntry, budgetOfPath, WORKSPACE_ANSWER_BOUND } from '@sim/workspace-code'
import { KIND_LAYOUTS } from '@sim/workspace-code/kinds/registry'
import { workflowCodec, workflowFolder } from '@sim/workspace-code/kinds/workflow'
Expand Down Expand Up @@ -78,7 +78,7 @@ export function workspaceApplyRateCost(
const kind = kindOfPath(path)
if (kind === 'workflow') workflowPaths.push(path)
else if (kind && budgetOfPath(KIND_LAYOUTS[kind], path) !== 'workflow') {
textBytes += utf8Bytes(text)
textBytes += utf8ByteLength(text)
}
}
const { groups } = workflowCodec.group(workflowPaths)
Expand Down
16 changes: 3 additions & 13 deletions apps/sim/lib/workspace-source/application/kinds/mcp/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import { createLogger } from '@sim/logger'
import { mapWithConcurrency } from '@sim/utils/concurrency'
import { getErrorMessage } from '@sim/utils/errors'
import { isRecordLike } from '@sim/utils/object'
import { didYouMean, type Json, type SourceSpan } from '@sim/workflow-code'
import { didYouMean, type SourceSpan } from '@sim/workflow-code'
import { SOURCE_ENTRY_FILE } from '@sim/workflow-code/limits'
import {
type BaseResource,
Expand Down Expand Up @@ -75,6 +74,7 @@ import {
resolveStoredHeaders,
storedFingerprint,
} from '@/lib/workspace-source/application/kinds/mcp/stored'
import { changedFields } from '@/lib/workspace-source/application/kinds/named'
import {
holdsIn,
refuseUnreadAdopt,
Expand Down Expand Up @@ -122,16 +122,6 @@ function serverIdOf(ctx: SourceContext, url: string): string {
return generateMcpServerId(ctx.workspace.workspaceId, url)
}

/** The top-level declaration fields whose canonical values differ. */
function changedFields(before: McpServerDecl, after: McpServerDecl): string[] {
const a = mcpCodec.canonical(before)
const b = mcpCodec.canonical(after)
if (!isRecordLike(a) || !isRecordLike(b)) return []
return Object.keys(b).filter(
(field) => fingerprintOf(b[field] as Json) !== fingerprintOf(a[field] as Json)
)
}

function baseOf(record: StoredServer): BaseResource {
return { id: record.id, fingerprint: storedFingerprint(record.state) }
}
Expand Down Expand Up @@ -243,7 +233,7 @@ async function planServer(
}
}
const record = planned.stored
const changed = changedFields(declOf(record.state), decl)
const changed = changedFields(mcpCodec.canonical(declOf(record.state)), mcpCodec.canonical(decl))
if (planned.action === 'adopt' && !resumed) {
const refused = refuseUnreadAdopt(change, record, changed)
if (refused) return refused
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/lib/workspace-source/application/kinds/named.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function planNamedUndeclared<K extends NamedKindName, S>(
}

/** The top-level declaration fields whose canonical values differ. */
function changedFields(before: Json, after: Json): string[] {
export function changedFields(before: Json, after: Json): string[] {
if (!isRecordLike(before) || !isRecordLike(after)) return []
return Object.keys(after).filter(
(field) => fingerprintOf(after[field] as Json) !== fingerprintOf(before[field] as Json)
Expand Down
4 changes: 2 additions & 2 deletions apps/sim/lib/workspace-source/application/plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { mapWithConcurrency } from '@sim/utils/concurrency'
import { utf8Bytes } from '@sim/workflow-code/limits'
import { utf8ByteLength } from '@sim/utils/paste'
import {
APPLY_ORDER,
type BlobEntry,
Expand Down Expand Up @@ -227,7 +227,7 @@ function checkLimits(
const bytes: Record<SourceBudget, number> = { declaration: 0, workflow: 0, rows: 0 }
for (const [path, text] of Object.entries(files)) {
const kind = kindOfPath(path)
if (kind) bytes[budgetOfPath(KIND_LAYOUTS[kind], path)] += utf8Bytes(text)
if (kind) bytes[budgetOfPath(KIND_LAYOUTS[kind], path)] += utf8ByteLength(text)
}
const { maxDeclarationBytes, maxRowsBytes, maxWorkflowBytes } = WORKSPACE_SOURCE_LIMITS
if (bytes.rows > maxRowsBytes) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { chunkArray } from '@sim/utils/helpers'
import { utf8Bytes } from '@sim/workflow-code/limits'
import { utf8ByteLength } from '@sim/utils/paste'
import {
APPLY_ORDER,
budgetOfPath,
Expand Down Expand Up @@ -76,7 +76,7 @@ function directoryBudget() {
spend(kind: WorkspaceKind, read: { text: Record<string, string>; blobs: ReadBlob[] }) {
const bytes: DirectoryBudgets = { declaration: 0, workflow: 0, rows: 0 }
for (const [path, text] of Object.entries(read.text)) {
bytes[budgetOfPath(adapterOf(kind).codec, path)] += utf8Bytes(text)
bytes[budgetOfPath(adapterOf(kind).codec, path)] += utf8ByteLength(text)
}
for (const budget of SOURCE_BUDGETS) {
if (spent[budget] + bytes[budget] > limits[budget]) {
Expand Down
10 changes: 8 additions & 2 deletions apps/sim/lib/workspace-source/staging/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { db } from '@sim/db'
import { workspace, workspaceSourceStagedBlob } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { sha256Hex } from '@sim/security/hash'
import { mapWithConcurrency } from '@sim/utils/concurrency'
import { generateId, generateShortId } from '@sim/utils/id'
import { WORKSPACE_SOURCE_LIMITS } from '@sim/workspace-code/limits'
import { and, asc, eq, gt, inArray, isNull, lt, lte, notInArray, sql } from 'drizzle-orm'
Expand Down Expand Up @@ -50,6 +51,9 @@ const SWEEP_BATCH = 500

const STORAGE_CONTEXT = 'workspace' as const

/** Blob uploads one staging request runs at once; the bytes are already in memory. */
const UPLOAD_CONCURRENCY = 4

const QUOTA_UNAVAILABLE = 'Could not check the storage quota for staging; retry shortly.'

/** A staged blob as an apply reads it. */
Expand Down Expand Up @@ -268,7 +272,9 @@ export async function stageBlobs(
: null,
])
try {
for (const blob of fresh) {
// A failed upload starts no more, and throws once those running have settled, so every object
// written is in `keys` by the time `finally` removes the ones no row recorded.
await mapWithConcurrency(fresh, UPLOAD_CONCURRENCY, async (blob) => {
const key = newStorageKey(target, blob.sha256)
await uploadFile({
file: blob.bytes,
Expand All @@ -280,7 +286,7 @@ export async function stageBlobs(
persistMetadata: false,
})
keys.set(blob.sha256, key)
}
})
recorded = await db.transaction(async (tx) => {
await acquireAdvisoryXactLock(
tx,
Expand Down
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/sim-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"@sim/utils": "workspace:*",
"@sim/workflow-code": "workspace:*",
"@sim/workflow-sdk": "workspace:*",
"@sim/workflow-types": "workspace:*",
"@sim/workspace-code": "workspace:*",
"@types/js-yaml": "4.0.9",
"@types/node": "24.19.2",
Expand Down
17 changes: 2 additions & 15 deletions packages/sim-cli/src/commands/protocol/source-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { setSoftExitCode } from '../../embed-context'
import { SourceDirError } from './local-errors'
import { printProtocolResult } from './result'
import { digest, readFolderWritten, readSourceText } from './source-dir'
import { STRICT_FINDINGS } from './source-strict'
import {
cachedCatalog,
cachedSourceCatalog,
Expand Down Expand Up @@ -68,21 +69,7 @@ const SERVER_ONLY_CODES: ReadonlySet<string> = new Set(['E_STORED_VALUE_MISSING'
* Warnings an apply saves as written although the block they name is broken: a strict check
* fails on them (see {@link StrictMode}).
*/
const STRICT_CODES: ReadonlySet<string> = new Set([
'W_REQUIRED_MISSING',
'W_UNKNOWN_OPTION',
'W_UNKNOWN_OUTPUT_PATH',
'W_VALUE_KIND',
'W_OUT_OF_RANGE',
'W_LITERAL_SECRET',
'W_TABLE_UNKNOWN_COLUMN',
'W_CHILD_INPUT_UNKNOWN',
'W_CHILD_RESULT_PATH',
'W_BRANCH_UNWIRED',
'W_UNRESOLVED_REF',
'W_REF_OUT_OF_SCOPE',
'W_LOOP_CONDITION_SYNTAX',
])
const STRICT_CODES: ReadonlySet<string> = new Set(STRICT_FINDINGS.keys())

/**
* {@link STRICT_CODES} warnings the stored workflow exempts, which a check never fails on a block
Expand Down
43 changes: 43 additions & 0 deletions packages/sim-cli/src/commands/protocol/source-exit-codes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ const WORKFLOW_SDK_README = readFileSync(
'utf8'
)

const SCRIPTING_DOCS = readFileSync(
join(import.meta.dirname, '../../../../../apps/docs/content/docs/cli/scripting.mdx'),
'utf8'
)

/** The codes of each `| Code | <commands> |` table in the scripting docs, by its header cell. */
const DOCS_TABLES = new Map(
SCRIPTING_DOCS.split(/\n\s*\n/).flatMap((block) => {
const header = block.match(/^\| Code \| (.+) \|$/m)
if (!header) return []
const codes = [...block.matchAll(/^\| `(\d+)` \|/gm)].map((match) => Number(match[1]))
return [[header[1], codes] as const]
})
)

function docsTable(heading: string): number[] {
const codes = DOCS_TABLES.get(heading)
if (!codes) throw new Error(`scripting.mdx has no exit-code table headed ${heading}`)
return codes
}

describe('the exit-code tables an agent or a reader relies on', () => {
it.each([
['the workflow directory guide', WORKFLOW_TREE.agents],
Expand All @@ -35,6 +56,28 @@ describe('the exit-code tables an agent or a reader relies on', () => {
})
})

describe('the exit-code tables of the CLI scripting docs', () => {
it.each([
['workflows source apply', '`sim workflows source apply` or `create`'],
['workflows source create', '`sim workflows source apply` or `create`'],
['workflows source get', '`sim workflows source get --dir` or `sim workspaces source get`'],
['workspaces source get', '`sim workflows source get --dir` or `sim workspaces source get`'],
['workspaces source apply', '`sim workspaces source apply`'],
] as const)('list every code %s names in its --help', (command, heading) => {
const help = sourceExitCodesHelp(command).replace(/\s+/g, ' ')
const named = [...help.matchAll(/(?:: |; )(\d+) /g)].map((match) => Number(match[1]))
expect(named.length).toBeGreaterThan(0)
expect(docsTable(heading)).toEqual(expect.arrayContaining(named))
})

it('name only codes a source command exits with', () => {
const sourceTables = [...DOCS_TABLES].filter(([heading]) => heading.includes(' source '))
expect(sourceTables.length).toBeGreaterThanOrEqual(5)
for (const [, codes] of sourceTables)
expect(SOURCE_EXIT_CODES).toEqual(expect.arrayContaining(codes))
})
})

describe('the exit codes a get names in its --help', () => {
it.each(['workflows source get', 'workspaces source get'] as const)(
'%s names exit 13 for a missing or refused login',
Expand Down
7 changes: 6 additions & 1 deletion packages/sim-cli/src/commands/protocol/source-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ function realPath(path: string): string {
}
}

/** A relative filter as given, with `/` separators and its leading `./` and trailing `/` dropped. */
export function givenFilterPath(filter: string): string {
return stripTrailingSlashes(filter.replace(/\\/g, '/').replace(/^(\.\/)+/, ''))
}

/**
* The directory-relative forms of one filter: as given (`./` and a trailing `/` dropped, an empty
* one meaning the whole directory) and resolved from the current directory, so both
Expand All @@ -353,7 +358,7 @@ function realPath(path: string): string {
function filterForms(filter: string, dir: string): string[] {
const forms = new Set<string>()
if (!isAbsolute(filter)) {
const given = stripTrailingSlashes(filter.replace(/\\/g, '/').replace(/^(\.\/)+/, ''))
const given = givenFilterPath(filter)
forms.add(given === '' ? '.' : given)
}
const resolved = relative(realPath(resolve(dir)), realPath(resolve(filter)))
Expand Down
28 changes: 28 additions & 0 deletions packages/sim-cli/src/commands/protocol/source-strict.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* The warnings a check fails on as errors: an apply saves each as written although the block it
* names is broken. One table, so `check --help` and the directory guides name the same findings.
*/

import type { DiagnosticCode } from '@sim/workflow-code/diagnostics/codes'

/** Each strict warning code with what it finds, as the guides phrase it. */
export const STRICT_FINDINGS: ReadonlyMap<string, string> = new Map([
['W_REQUIRED_MISSING', 'a missing required field'],
['W_UNKNOWN_OPTION', 'an unknown option'],
['W_UNKNOWN_OUTPUT_PATH', 'an unknown output path'],
['W_VALUE_KIND', 'a wrong value kind'],
['W_OUT_OF_RANGE', 'an out-of-range value'],
['W_LITERAL_SECRET', 'a literal secret'],
['W_TABLE_UNKNOWN_COLUMN', 'a table write to an unknown column'],
['W_CHILD_INPUT_UNKNOWN', 'an input a child workflow does not declare'],
['W_CHILD_RESULT_PATH', "a path a child workflow's result does not hold"],
['W_BRANCH_UNWIRED', 'an unwired condition or router branch'],
['W_UNRESOLVED_REF', 'a reference that names nothing'],
['W_REF_OUT_OF_SCOPE', 'an iteration field read outside its loop or parallel'],
['W_LOOP_CONDITION_SYNTAX', 'a loop condition that is not a JavaScript expression'],
] satisfies Array<[DiagnosticCode, string]>)

const phrases = [...STRICT_FINDINGS.values()]

/** Every {@link STRICT_FINDINGS} phrase as one clause: `a, b, … or z`. */
export const STRICT_FINDINGS_CLAUSE = `${phrases.slice(0, -1).join(', ')} or ${phrases.at(-1)}`
Loading
Loading