Skip to content

refactor(workflow-code): source pipeline plan/commit split, one findings bound, CLI source-dir split - #10238

Merged
waleedlatif1 merged 39 commits into
stagingfrom
refactor/workflow-code-wave2
Nov 20, 2026
Merged

waleedlatif1 merged 39 commits into
stagingfrom
refactor/workflow-code-wave2

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

Wave 2 of the workflows and workspace as code cleanup. Behaviour is the same except where noted below.

Source pipeline

  • The source pipeline is split into load, plan, preview, commit and effects.
  • A plan is bound to the principal that made it. It writes nothing, and the commit takes only that plan.
  • Workspace commits re-plan through planForCommit and no longer through the adapter. The adapter reads a plan only through summarizePlan.

Findings

  • One diagnostics module covers codes, severity, the factory and refusal classes.
  • boundAnswerFindings is now the single bounding policy. It is applied at every answer edge, including:
    • a workflow refused at commit inside a workspace apply;
    • findings added by an apply after planning;
    • the CLI's offline check.
  • I_FINDINGS_TRUNCATED is the only marker, and W_TOO_MANY_WARNINGS is removed.

CLI

  • source-dir.ts is split into a source-dir/ folder.
  • There is one runSourceWrite flow. Refusals are typed as SourceDirError and CliUsageError.
  • Every workflow directory gets a command lock, which removes the parent folders it created.

Other

  • Table cell rules move to a new pure package, @sim/table-cells.
  • @sim/testing gets a shared linear-growth helper.
  • withExpectedDraft runs a publish under its draft check.

Contract changes

  • Workspace findings now use the same marker text and bound as workflow findings: 1,000 total for workspace answers, with the errors-first kept set unchanged.
  • The create-name check runs at plan time, so a dry run or workspace plan reports a taken name.
  • --dry-run and plan work on a read-only standalone directory. A write to one is refused up front.
  • Telemetry error_name values follow the typed CLI errors.

Testing

  • The local gate passes: type-check for every touched workspace, the package suites, apps/sim units, integration, goldens, check:audits, check:test-types, docs compatibility and lint.
  • No golden file changed.
  • Three read-only audits (equivalence, abstraction, tests) ran against the integrated branch. Every gap they found has a test that was seen to fail with its guard reverted.

…ls package

The coerce/validate rules, row checks, select resolution and currency, date
and ttl parsing move from @sim/workspace-code/table-cells to @sim/table-cells.
isSupportedCurrencyCode has one owner there; the copy in workspace-code
kinds/table.ts is gone. Display and clock helpers move into apps/sim:
lib/table/currency-format.ts (formatter cache is now an lru-cache with a max)
and lib/table/ttl-picker.ts. workspace-code drops its zod dependency, and
check:boundaries holds the new package pure.
expectLinearGrowth (@sim/testing/helpers/scaling) times a step at n and 8n
and fails anything quadratic. It replaces workflow-code's
scaling.test-helpers (and its package export) and the chat-content
scalingRatioOver4x helper.
…ft check

Replaces the expectedDraft flag-and-assert pair: the deploy and the chat
replace each pass their publish to withExpectedDraft, which returns its
result and throws WorkflowDraftChangedError when the check refused it. The
chat replace passes its own workflow context instead of resolving it a
second time.
…factory and refusal class

- @sim/workflow-code/diagnostics: one DiagnosticSeverity, SeverityOf and severityOf
  (severity.ts), a diagnostic() factory that fills severity from the code (factory.ts),
  and refusalClass/refusalClassifier beside the edit refusals (refusals.ts)
- DIAGNOSTIC_CODES declares every code once; print's codes are a subset type of
  compile's, and DiagnosticCode is never if a code is declared twice
- workspace-code keeps only its own codes plus the three it shares with workflow
  source (E_APPLY_STALE, E_LIMIT_EXCEEDED, E_NAME_TAKEN); WorkspaceDiagnosticCode is
  never if an own code is also a workflow code; its refusalClass is the shared
  classifier with its locked and size-limit codes
- hand-built { code, severity } literals in canonicalize, print, materialize, lock,
  source-meta and structured/variables use the factory; Reporter and workspace
  diagnostic() use the shared severityOf
- OpenAPI/cli-api: the workspace enum lists the three shared codes after its own
…truncation marker

- diagnostics/bound.ts: boundDiagnostics (per-severity, per-code warning, total and
  text limits; errors that class a refusal kept first; one I_FINDINGS_TRUNCATED
  counting what was left out), boundFindingText, FINDING_LIMITS, findingsTruncated
- I_FINDINGS_TRUNCATED is declared once in workflow-code and shared by workspace
  source; W_TOO_MANY_WARNINGS is gone (Reporter records I_FINDINGS_TRUNCATED where
  its warning caps cut, counted in the warning slot as before)
- Reporter keeps its caps as a work bound (frames, did-you-mean hints, message text)
  and reads the numbers from FINDING_LIMITS; the MAX_WARNINGS/MAX_INFOS exports go
- edges: workflow source routes (apply, plan, create, v2 and internal get) and the
  SOURCE_REJECTED renderers bound through boundSourceFindings; the workspace plan
  (capFindings replaced by boundFindings, same 1,000 total and class-first rule) and
  read answer; the CLI findingsOutput cuts finding text
- OpenAPI/cli-api: W_TOO_MANY_WARNINGS removed from the workflow enum
… and commit

Move runSourceApply and source-evaluate.ts into lib/workflows/application/source-pipeline:
load, plan, outcome, commit and effects, with evaluate/ split by phase (compile, resolve,
refusals, gates, finalize). The public source use cases take exactly the wire input; the
workspace apply plans and commits each workflow through internal workflowSourceUpdate and
workflowSourceCreate pairs instead of planOnly/evaluated/shared/withinCreate/pendingResources
and a caller-minted workflowId. A commit refuses a plan made for another workflow or principal.
isResourceKind is imported from @sim/workflow-code.
The three v2 source routes answer through presentSourceOutcome, which picks exactly the
fields the response schema exposes, instead of handing the use case's result to the schema.
…nd a barrel

layout, files, written, dir-kind, write-back and command-lock modules; every
./source-dir import resolves to the barrel unchanged. The three printed-path
filters share refusedSourcePaths.
Directory readers and writers move out of the command files: workflow-dir.ts
(readBase, readLock, readSourceFiles, requireEntry, WORKFLOW_TREE and the get
and create writers), source-check.ts (the check pipeline both check commands
share), parseKinds/ONLY_KINDS_HELP into workspace-source-dir.ts and
destructiveChanges into source-status.ts.
…geError

The 50 SimApiError(message, 0, ...) calls the source commands raised for their
own refusals become SourceDirError (the directory, its records, a path it would
send or write) or CliUsageError (flags and arguments). Both extend SimApiError
with status 0, so the message, code, exit status and the unreachable-server
rule are unchanged; telemetry now names the class.
…ry workflow directory

source-write.ts owns preview, refusal exit, plan stop, confirmation and the
interrupt-deferred send and save; workflow apply/create and workspace apply each
supply a flow, and the deploy step stays workflow-only after it.

Behaviour change: workflows source get/apply/create now hold .sim/command.lock
on a standalone workflow directory too (withSourceCommandLock), so a second
command on it exits 10 (SOURCE_DIR_BUSY) instead of interleaving its writes.
…row table

sourceExitCodeRows is the one table the directory guides and each write or get
command's --help (sourceExitCodesHelp) are built from, so a renumbered code
cannot leave a stale digit in either. The busy clause joins each list instead of
a separate line; the guides and the remaining help lines interpolate the
constants. Words are unchanged; the help reflows to 100 columns, and the CLI
docs regenerate (whitespace collapses there, so only the busy clause moves).
…tic factory

The apply-side findings the pipeline raises (workflow mismatch, stale, catalog moved,
kept credential, claimed lock id, block and variable deletes, meta limits, name taken,
probable rename) take their severity from the code through diagnostic(), as the
package's findings already do.
…owns the replan rule

The workspace commit use cases took a plan or the submission to plan again,
told apart by shape, and the adapter decided which (commitsAsPlanned). The
plan now records when it resolved a stand-in id and keeps the submission it
was planned from; planForCommit plans it again at commit time. The adapter
reads a plan only through summarizePlan, so SourcePlan's layout no longer
reaches lib/workspace-source.
boundAnswerFindings owns the marker text and the refusal-first rule for both
domains; the workspace passes WORKSPACE_ANSWER_BOUND. The workspace bound
moves out of buildWorkspacePlan into the GET, plan and apply presenters and
v2WorkspaceSourceErrorPolicy, so a workflow refused at commit inside a
workspace apply, and findings an apply's writes add, are bounded too. When
the edge cuts a list it replaces the stages' own I_FINDINGS_TRUNCATED with
one marker whose counts exclude them. Route tests replace the helper test.
…n, the create-name check at plan, and per-session plan binding
@waleedlatif1
waleedlatif1 requested a review from a team as a code owner November 20, 2026 17:14
@vercel

vercel Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Nov 20, 2026 7:07pm UTC

Request Review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[High impact] The PR changes shared workflow-source paths, CLI source operations, and table-cell code.

Fix the read-only plan path before merging; preserving the original principal check is also worthwhile.

Findings

  1. P1 Read-only plans still write ▶
  2. P2 Replanning replaces the principal check ▶

Summary

Splits workflow source work into load, plan, preview, commit, and effects.

  • Workflow source plans now lead into a separate, principal-bound commit.
  • Workflow and workspace findings now share one answer cap and marker.
  • CLI source commands now share a read, preview, and write flow.
  • Table cell rules now come from a shared package.
  • Workflow deploys and chat publishes now run under one draft check.
  • Shared test helpers and workflow-code internals now have clearer package boundaries.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Source submission] --> B[Load and plan]
  B --> C{Plan accepted?}
  C -->|No| D[Return findings]
  C -->|Yes| E{Dry run?}
  E -->|Yes| F[Preview]
  E -->|No| G{Placeholder references?}
  G -->|Yes| H[Replan after resource writes]
  G -->|No| I[Commit]
  H --> I
  I --> J[Audit and notify]
  D --> K[Bound answer findings]
  F --> K
  J --> K
Loading

Reviews (1) · Last reviewed commit: "refactor(workflow-code): drop exports th..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 174 files

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread .cursor/rules/sim-workflow-code.mdc Resolved
planForCommit replanned a stand-in plan as the committing principal and
only then let commitSource check the binding, which the replanned plan
always passed. Check the original binding first, and throw a typed,
coded PlanBindingError for both bindings so tests assert the code.

Also: the stand-in filter on replan is load-bearing (without it a
resource the apply never created is written under its stand-in id);
say so and test it. Drop boundTo.principalKind (only a log line read it)
and the unused SourceSubmission export.
…n answer bounds

Each edge bounded its findings with no test that fails when it stops;
exercise them through the route. Rename the workspace POST case to the
plan-time refusal it actually models: a commit refusal is caught mid-apply
and answered 200 with failed.
Only the workspace check's bound was tested. Row writes naming 25
undeclared columns are CLI-side findings the compile does not cap, so
the default workflow bound is what lists 20 of them.
mkdir resolves '..' after following links while the cleanup climbs the
lexical path, so a dir holding '..' removed an empty folder the lock
never created and left one it did. Resolve first so both walk one path,
remove created folders on the error paths after mkdir too, and test an
empty pre-existing parent, which the climb must stop at.
apply and create skipped the refresh only on --dry-run, so a plan (no
terminal, no --yes) could rewrite .sim/sdk before previewing, and fail
on a read-only directory instead of answering. Skip it in every
read-only mode.
A lock codeFile of 'functions/' passed the prefix check, and its
recursive removal took the whole folder, files no lock named included.
Apply the codeFile path rule before pruning.
The embedded branch read every failure as a missing file, so a run
stopped during a read carried on as if the file were absent. Rethrow
once the run's signal has aborted; the host reader still names no
missing-file error, so other failures keep reading as missing.
SourceDirError and CliUsageError carry status 0 and often a null code,
which noAnswer reads as a request with no answer: a status whose own
directory refused a read reported the server unreachable, and a write
whose save-back was refused got the answer-lost hint. Give both a
LocalRefusal base and exclude it from both checks.
… it reads

The source names the credential by its stored id, not by a key; the key
a commit would allocate comes from the stored reference. The check goes
red when a dry run allocates, so only its name was wrong.
…ules

workflow-source-check.ts reads workspace declarations through it, so
the claim that the two command families never import each other holds
only for their command modules.
A get exits 13 without a login or with a refused credential, but only
the writes named it (in their shared section).
@waleedlatif1
waleedlatif1 merged commit 26caf90 into staging Nov 20, 2026
93 checks passed
@waleedlatif1
waleedlatif1 deleted the refactor/workflow-code-wave2 branch November 20, 2026 19:18

This branch was successfully deployed

1 active deployment
Preview — e5467fe9 Deployed Nov 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant