Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 2 additions & 14 deletions .claude/rules/sim-workflow-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ workspace directory).
| `packages/table-cells` | Pure table cell rules (coerce, validate, currency/date/ttl parsing) shared by the table codec's offline row check and the server's writes |
| `packages/workflow-sdk` | Authoring declarations (`src/core.d.ts`, `src/workspace/*.d.ts`), type codegen from the catalog (`src/codegen/`), the cookbook |
| `packages/sim-cli/src/commands/protocol/` | `workflow-source-*` and `workspace-source-*` commands, which never import each other's command modules; `source-dir/`, `workflow-dir.ts`, `source-check.ts`, `source-write.ts`, `source-tree.ts`, `source-ui.ts` and `workspace-source-dir.ts` (the workspace directory reader a workflow check also reads declarations through) are shared |
| `apps/sim/lib/workflows/code/` | Server glue: catalog projection from the registry (`catalog/`), source-apply gates (`apply/`), stored canonical form, the feature flag, the proof corpus (`corpus/`) |
| `apps/sim/lib/workflows/code/` | Server glue: catalog projection from the registry (`catalog/`), source-apply gates (`apply/`), stored canonical form, the proof corpus (`corpus/`) |
| `apps/sim/lib/workflows/application/*source*` | Workflow source use cases: read, apply, create, catalog, resources; `source-pipeline/` holds the one plan → preview/commit flow an apply and a create share |
| `apps/sim/lib/workspace-source/` | Workspace source use cases (`application/`), one adapter per kind (`application/kinds/<kind>/`), route policies (`api/`) |
| `apps/sim/blocks/sdk-names/<type>.json` | Frozen SDK builder names, one file per block type |
Expand All @@ -69,7 +69,7 @@ server unchanged.
Both words name the same feature, split by role; follow the split rather than rename:

- **code** names the feature and its engines: the packages (`workflow-code`, `workspace-code`), the
server glue folder `lib/workflows/code/`, the `workflow-code` flag, the Code tab.
server glue folder `lib/workflows/code/`, the Code tab.
- **source** names the artifact and the operations on it: the files themselves, the use cases
(`readWorkflowSource`, `applyWorkspaceSource`), the routes (`/source`), the CLI
(`sim workflows source get`), `lib/workspace-source/`.
Expand All @@ -91,18 +91,6 @@ lock. The catalog (built from the block registry, `lib/workflows/code/catalog/`)
engine learns about blocks; engines never import the registry. See DESIGN.md "The canonical model"
and "The catalog".

## Feature flag

One global flag, `workflow-code` (`lib/core/config/feature-flags.ts`, env fallback
`WORKFLOW_CODE`), gates workflow source, workspace source, the source catalog and resources, and
the Code tab. Every source operation (the workflow source ones in
`lib/workflows/application/operations.ts` and the workspace source ones in
`lib/workspace-source/application/operations.ts`) declares `feature: WORKFLOW_CODE_FEATURE`, which
the shared use-case wrapper checks after authorization (`FEATURE_NOT_ENABLED`); a new source
operation declares the same feature, never its own check. A surface outside an operation (the Code
tab, Copilot entitlements) calls `isWorkflowCodeEnabled()` (`lib/workflows/code/feature-flag.ts`);
the UI reads it from the workspace layout's flags.

## Adding things

### A block type
Expand Down
16 changes: 2 additions & 14 deletions .cursor/rules/sim-workflow-code.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ workspace directory).
| `packages/table-cells` | Pure table cell rules (coerce, validate, currency/date/ttl parsing) shared by the table codec's offline row check and the server's writes |
| `packages/workflow-sdk` | Authoring declarations (`src/core.d.ts`, `src/workspace/*.d.ts`), type codegen from the catalog (`src/codegen/`), the cookbook |
| `packages/sim-cli/src/commands/protocol/` | `workflow-source-*` and `workspace-source-*` commands, which never import each other's command modules; `source-dir/`, `workflow-dir.ts`, `source-check.ts`, `source-write.ts`, `source-tree.ts`, `source-ui.ts` and `workspace-source-dir.ts` (the workspace directory reader a workflow check also reads declarations through) are shared |
| `apps/sim/lib/workflows/code/` | Server glue: catalog projection from the registry (`catalog/`), source-apply gates (`apply/`), stored canonical form, the feature flag, the proof corpus (`corpus/`) |
| `apps/sim/lib/workflows/code/` | Server glue: catalog projection from the registry (`catalog/`), source-apply gates (`apply/`), stored canonical form, the proof corpus (`corpus/`) |
| `apps/sim/lib/workflows/application/*source*` | Workflow source use cases: read, apply, create, catalog, resources; `source-pipeline/` holds the one plan → preview/commit flow an apply and a create share |
| `apps/sim/lib/workspace-source/` | Workspace source use cases (`application/`), one adapter per kind (`application/kinds/<kind>/`), route policies (`api/`) |
| `apps/sim/blocks/sdk-names/<type>.json` | Frozen SDK builder names, one file per block type |
Expand All @@ -49,7 +49,7 @@ server unchanged.
Both words name the same feature, split by role; follow the split rather than rename:

- **code** names the feature and its engines: the packages (`workflow-code`, `workspace-code`), the
server glue folder `lib/workflows/code/`, the `workflow-code` flag, the Code tab.
server glue folder `lib/workflows/code/`, the Code tab.
- **source** names the artifact and the operations on it: the files themselves, the use cases
(`readWorkflowSource`, `applyWorkspaceSource`), the routes (`/source`), the CLI
(`sim workflows source get`), `lib/workspace-source/`.
Expand All @@ -71,18 +71,6 @@ lock. The catalog (built from the block registry, `lib/workflows/code/catalog/`)
engine learns about blocks; engines never import the registry. See DESIGN.md "The canonical model"
and "The catalog".

## Feature flag

One global flag, `workflow-code` (`lib/core/config/feature-flags.ts`, env fallback
`WORKFLOW_CODE`), gates workflow source, workspace source, the source catalog and resources, and
the Code tab. Every source operation (the workflow source ones in
`lib/workflows/application/operations.ts` and the workspace source ones in
`lib/workspace-source/application/operations.ts`) declares `feature: WORKFLOW_CODE_FEATURE`, which
the shared use-case wrapper checks after authorization (`FEATURE_NOT_ENABLED`); a new source
operation declares the same feature, never its own check. A surface outside an operation (the Code
tab, Copilot entitlements) calls `isWorkflowCodeEnabled()` (`lib/workflows/code/feature-flag.ts`);
the UI reads it from the workspace layout's flags.

## Adding things

### A block type
Expand Down
38 changes: 1 addition & 37 deletions .github/scripts/http-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ realtime_tag=''
realtime_log=''
browsers_pid=''
local_app_url=''
extra_pids=()
extra_tags=()
extra_logs=()
# `dev` or `start`; a group sets it before start_app.
app_server=${E2E_APP_SERVER:-dev}

Expand All @@ -61,13 +58,6 @@ finish() {
tail -n 200 "$server_log"
fi
fi
for i in "${!extra_pids[@]}"; do
bash "$GITHUB_WORKSPACE/.github/scripts/stop-session.sh" "${extra_pids[$i]}" "${extra_tags[$i]}" || status=1
wait "${extra_pids[$i]}" 2>/dev/null || true
if [ "$status" -ne 0 ]; then
tail -n 100 "${extra_logs[$i]}"
fi
done
if [ -n "$realtime_pid" ]; then
bash "$GITHUB_WORKSPACE/.github/scripts/stop-session.sh" "$realtime_pid" "$realtime_tag" || status=1
wait "$realtime_pid" 2>/dev/null || true
Expand Down Expand Up @@ -132,27 +122,6 @@ start_app() {
wait_ready "$server_pid" "$local_app_url/api/health" "$label app"
}

# start_extra_app <name> <port> <label> [env-argument...]: another `next start` of the same build on
# the same database, beside the group's app, for a suite comparing two runtime configurations.
# The `env` arguments adjust its environment (`-u WORKFLOW_CODE` turns that flag off).
start_extra_app() {
local name=$1 port=$2 label=$3
shift 3
if [ "$app_server" != start ]; then
echo "::error::A second app needs the production build (next start)."
exit 1
fi
local tag="$name-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-$$" url="http://127.0.0.1:$port"
local log="$report_dir/$name-next.log"
E2E_APP="$tag" NEXT_PUBLIC_APP_URL="$url" BETTER_AUTH_URL="$url" LOG_LEVEL=INFO setsid env "$@" \
node ../../node_modules/next/dist/bin/next start --hostname 127.0.0.1 --port "$port" \
> "$log" 2>&1 &
extra_pids+=("$!")
extra_tags+=("$tag")
extra_logs+=("$log")
wait_ready "$!" "$url/api/health" "$label app"
}

# start_realtime <name> <port>: the Socket.IO server the app's browser clients connect to, so pages
# render connected rather than under a "Reconnecting..." notification. Start after start_app, which
# exports the app URL the server allows as an origin; NEXT_PUBLIC_SOCKET_URL must already be set
Expand Down Expand Up @@ -197,7 +166,6 @@ case "$group" in
export DB_TX_TRIPWIRE=throw
export NEXT_PUBLIC_CHAT_DISABLED=true
export SIM_LINKS=true
export WORKFLOW_CODE=true
export PEOPLE=true
export CRON_SECRET=people-directory-sync-local-e2e-secret
start_browser_install people chromium
Expand Down Expand Up @@ -381,22 +349,18 @@ JS
bun run test:markdown-viewer:e2e
;;

# Two apps on one build and database: the Code tab's flag on (with realtime, so canvas edits
# persist) and off, for the suite's flag-off and flag-flip checks.
# The Code tab with realtime, so canvas edits persist.
workflow-code-ui)
app_server=start
export NEXT_PUBLIC_FORCE_HOSTED=false
export NEXT_PUBLIC_CHAT_DISABLED=true
export INTERNAL_API_SECRET=workflow-code-ui-http-ci-local-secret-at-least-32-characters
export NEXT_PUBLIC_SOCKET_URL=http://127.0.0.1:3029 SOCKET_SERVER_URL=http://127.0.0.1:3029
export WORKFLOW_CODE=true
start_browser_install workflow-code-ui --only-shell chromium
start_app workflow-code-ui 3028 'workflow Code tab' record-http-status
start_realtime workflow-code-ui 3029
start_extra_app workflow-code-ui-flag-off 3030 'workflow Code tab (flag off)' -u WORKFLOW_CODE
wait_for_browsers
WORKFLOW_CODE_UI_E2E_BASE_URL="$NEXT_PUBLIC_APP_URL" \
WORKFLOW_CODE_UI_E2E_FLAG_OFF_BASE_URL=http://127.0.0.1:3030 \
WORKFLOW_CODE_UI_E2E_DATABASE_URL="$DATABASE_URL" \
WORKFLOW_CODE_UI_E2E_AUTH_SECRET="$BETTER_AUTH_SECRET" \
WORKFLOW_CODE_UI_E2E_REPORT_PATH="$report_dir/workflow-code-ui-report.json" \
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/e2e/local-files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { FeatureFlagsProvider } from '@/app/workspace/[workspaceId]/providers/fe
import { SettingsHeaderProvider, SettingsHeaderShell } from '@/components/settings/settings-header';
import { SettingsSectionProvider } from '@/components/settings/settings-panel';
const router = { back() {}, forward() {}, refresh() {}, push() {}, replace() {}, prefetch() {} };
const flags = { dashboards: false, 'workflow-tests': false, 'workflow-code': false, changelog: false, 'mothership-model-selector': false, 'mothership-plan-mode': false };
const flags = { dashboards: false, 'workflow-tests': false, changelog: false, 'mothership-model-selector': false, 'mothership-plan-mode': false };
createRoot(document.getElementById('settings')).render(
<AppRouterContext.Provider value={router}>
<PathParamsContext.Provider value={{ workspaceId: 'fixture' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Tab, Tabs } from '@/components/ui/tabs'
Build a workflow without the workflow builder: find the blocks you need, write the draft graph in batches, check each batch before committing it, test the draft, deploy it, and run it. Every step has an HTTP request and an equivalent [`sim` CLI](/cli) command, and the same operations are available to AI agents through [Sim MCP](#use-sim-mcp).

<Callout type="info">
Prefer source for whole-workflow edits. [Workflows as code](/workflows/code) (in preview) reads a workflow as TypeScript and saves the edited source in one request (`getWorkflowSource`, `applyWorkflowSource`). The operations below suit targeted changes.
Prefer source for whole-workflow edits. [Workflows as code](/workflows/code) reads a workflow as TypeScript and saves the edited source in one request (`getWorkflowSource`, `applyWorkflowSource`). The operations below suit targeted changes.
</Callout>

## Prerequisites
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/cli/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ sim tables rows query --help
| [`workflow-mcp-servers`](/cli/workflow-mcp-servers) | Expose deployed workflows as MCP tools |
| [`meta`](/cli/meta) | Inspect API availability and credential status |

To edit a workflow as a TypeScript file, or a whole workspace as a directory, use `sim workflows source` and `sim workspaces source` (in preview). See [Workflows as code](/workflows/code) and [Manage a workspace as code](/workflows/code/workspace).
To edit a workflow as a TypeScript file, or a whole workspace as a directory, use `sim workflows source` and `sim workspaces source`. See [Workflows as code](/workflows/code) and [Manage a workspace as code](/workflows/code/workspace).

The [command overview](/cli/commands) lists global options and root commands. The [complete reference](/cli/reference) contains every subcommand, argument, and option on one page. Both are generated from the CLI.

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/mcp/tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ correct its request.

## Edit a whole workflow [#workflow-source]

`getWorkflowSource` returns a workflow as TypeScript source files with its `lock` and `base`. Edit the files and send them back, with the same `lock` and `base`, through `applyWorkflowSource`, first with `query: {"dry": true}`. One call replaces a batch of graph operations. Workflows as code is in preview; see [Workflows as code](/workflows/code).
`getWorkflowSource` returns a workflow as TypeScript source files with its `lock` and `base`. Edit the files and send them back, with the same `lock` and `base`, through `applyWorkflowSource`, first with `query: {"dry": true}`. One call replaces a batch of graph operations. See [Workflows as code](/workflows/code).

## Code mode

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,6 @@ Who may sign up and sign in — the allowlists, blocklists, `REGISTRATION_MODE`,

Plain JavaScript without imports runs in isolated-vm within Node child workers in the app container. Python, Shell, imported JavaScript, sandbox/file-path execution, and Pi require the corresponding remote provider and image configuration. See [Sandboxes](/platform/self-hosting/sandboxes) for the base-image build and [Security](/platform/self-hosting/security) for the isolation comparison.

## Preview features

| Variable | Description |
|----------|-------------|
| `WORKFLOW_CODE` | Set to `true` to enable [workflows as code](/workflows/code) and [workspace as code](/workflows/code/workspace): the read-only **Code** tab in the workflow builder, and the source API and MCP operations that the `sim workflows source` and `sim workspaces source` CLI commands call. Off when unset; while off, those operations answer `403` |

## Chat and PII [#chat--pii]

| Variable | Description |
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/workflows/code/edit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Result: a workflow saved from a file you edited, with the problems found before

## Prerequisites

The Sim CLI, signed in, with [workflows as code enabled](/workflows/code). Run every command on the same `--dir`; commands that read a directory (`check`, `status`, `diff`, `params`, `apply`) default it to the current directory, while `get` and `create`, which write one, always need `--dir`.
The Sim CLI, signed in. Run every command on the same `--dir`; commands that read a directory (`check`, `status`, `diff`, `params`, `apply`) default it to the current directory, while `get` and `create`, which write one, always need `--dir`.

## 1. Read the workflow

Expand Down
1 change: 0 additions & 1 deletion apps/docs/content/docs/workflows/code/get-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ This walks through one change end to end: read a workflow as a file, edit it, ch

## Before you start

- Workflows as code is [enabled](/workflows/code) for your workspace. Where it is not, step 2 answers `403`.
- The Sim CLI is installed and you are signed in with a default workspace. See [Your first command](/cli#your-first-command).
- Optional: npm (Node.js), which the type check in step 4 uses once to install TypeScript; without it `check` reports `W_TYPES_UNCHECKED` and the compile still runs.

Expand Down
6 changes: 1 addition & 5 deletions apps/docs/content/docs/workflows/code/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ title: Workflows as code
description: Read and edit workflows and whole workspaces as TypeScript files, check them before saving, and review changes as diffs.
---

import { Callout } from '@/components/ui/callout'

Every workflow can be read and written as one TypeScript file, and a whole workspace as a directory of files. The file and the workflow builder show the same workflow: edit either one and the other follows. Use it to review agent changes as a diff, keep workflows in git, or let a coding agent such as Claude Code build and change them for you.

<Callout type="info">
Workflows as code is in preview. When it is enabled, the workflow builder shows a read-only **Code** tab and the [CLI](/cli) gains the `sim workflows source` and `sim workspaces source` commands. On a self-hosted deployment, set [`WORKFLOW_CODE`](/platform/self-hosting/environment-variables#preview-features). On Sim Cloud it is enabled per organization, workspace or user. Where it is off, the **Code** tab is not shown and a source command answers `403` with "Workflows as code is in preview and not enabled for this workspace".
</Callout>
The workflow builder shows the file in a read-only **Code** tab, and the [CLI](/cli) reads and saves it with the `sim workflows source` and `sim workspaces source` commands.

## Workflow or workspace

Expand Down
2 changes: 0 additions & 2 deletions apps/docs/content/docs/workflows/code/troubleshooting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ Ctrl-C. If the CLI says a write may have happened, `status` shows whether it did

## A command answers `403` [#forbidden]

- **"Workflows as code is in preview and not enabled for this workspace".** The feature is off for this workspace; see [Workflows as code](/workflows/code) for how it is enabled.
- **A workspace API key.** Saving a workflow acts as a person, so it needs a personal API key or an OAuth login. In a workspace directory, a workspace key can apply only some kinds and the rest are refused with `E_APPLY_FORBIDDEN`; see [Workspace API keys](/workflows/code/workspace#workspace-api-keys).

## By diagnostic code
Expand Down Expand Up @@ -153,7 +152,6 @@ You deleted or retyped a block that serves a live webhook, schedule, chat or MCP
## Other problems

- **The builder does not show a change.** An apply saves the draft. The builder shows it at once, but runs of the deployed version do not change until you deploy.
- **The Code tab is missing.** Workflows as code is not enabled for the workspace; see [Workflows as code](/workflows/code).

## Related docs

Expand Down
6 changes: 1 addition & 5 deletions apps/docs/content/docs/workflows/code/workspace.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ title: Manage a workspace as code
description: Keep a workspace's tables, knowledge bases, files, custom tools, skills and workflows in one directory, and apply it in one step.
---

import { Callout } from '@/components/ui/callout'

A whole workspace can be read and written as a directory: one folder per kind of resource, with each workflow written exactly as [workflows as code](/workflows/code) writes it. One apply creates the resources before the workflows that use them, so a coding agent can build a working setup from scratch.

<Callout type="info">
Workspace as code is in preview, behind the [same setting](/workflows/code) as workflows as code. It adds the `sim workspaces source` commands to the [CLI](/cli/workspaces#workspace-as-code).
</Callout>
The [CLI](/cli/workspaces#workspace-as-code) reads and applies the directory with the `sim workspaces source` commands.

## The directory

Expand Down
3 changes: 1 addition & 2 deletions apps/docs/openapi-v2-billing.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,7 @@
"INTEGRATION_NOT_ALLOWED",
"INSUFFICIENT_SCOPE",
"READ_ONLY_API_KEY",
"SCIM_MANAGED_MEMBERSHIP",
"FEATURE_NOT_ENABLED"
"SCIM_MANAGED_MEMBERSHIP"
],
"title": "Forbidden detail code",
"description": "Stable cause code for an actionable `403` response."
Expand Down
3 changes: 1 addition & 2 deletions apps/docs/openapi-v2-files-audit.json
Original file line number Diff line number Diff line change
Expand Up @@ -4714,8 +4714,7 @@
"INTEGRATION_NOT_ALLOWED",
"INSUFFICIENT_SCOPE",
"READ_ONLY_API_KEY",
"SCIM_MANAGED_MEMBERSHIP",
"FEATURE_NOT_ENABLED"
"SCIM_MANAGED_MEMBERSHIP"
],
"title": "Forbidden detail code",
"description": "Stable cause code for an actionable `403` response."
Expand Down
3 changes: 1 addition & 2 deletions apps/docs/openapi-v2-knowledge.json
Original file line number Diff line number Diff line change
Expand Up @@ -6130,8 +6130,7 @@
"INTEGRATION_NOT_ALLOWED",
"INSUFFICIENT_SCOPE",
"READ_ONLY_API_KEY",
"SCIM_MANAGED_MEMBERSHIP",
"FEATURE_NOT_ENABLED"
"SCIM_MANAGED_MEMBERSHIP"
],
"title": "Forbidden detail code",
"description": "Stable cause code for an actionable `403` response."
Expand Down
Loading
Loading