Skip to content

feat(dag): add workflow draft action for schema-checked graph authoring - #264

Merged
LeXwDeX merged 4 commits into
devfrom
feat/workflow-draft-action
Aug 14, 2026
Merged

feat(dag): add workflow draft action for schema-checked graph authoring#264
LeXwDeX merged 4 commits into
devfrom
feat/workflow-draft-action

Conversation

@LeXwDeX

@LeXwDeX LeXwDeX commented Aug 14, 2026

Copy link
Copy Markdown
Owner

Summary

Models writing workflow YAML by hand drift on field names and structure (live-observed in this session: objective at top level, worker instead of worker_type) even with the reference template in context. YAML is an unvalidated text channel — prompting alone cannot reach zero drift. This PR closes the gap at three layers:

1. workflow(action="draft") — harness-rendered specs (root fix)

  • Pass the structured config through the tool parameter schema (reuses WorkflowGraphSchema); the harness renders it to .opencode/workflow-drafts/<name>.yaml via yaml.stringify, runs the portable authoring check, and returns the spec_path with node count or diagnostics.
  • Unknown fields (worker, top-level objective, missing config) are rejected by the provider-side tool-call schema before anything is written; YAML syntax/indentation errors disappear because rendering is code.
  • Draft directory is outside the saved-workflow library scan paths; workflow names are whitelist-validated against path escape.
  • spec_path contract unchanged: start/extend/replan/validate still accept only file paths; draft only produces the file.

2. Routing guide carries the minimal complete start spec inline

  • workflow-routing.md (the tool description) now includes a one-hop minimal start YAML example plus field-ownership rules (objective lives inside config; block fields are exhaustive; never worker/prompt/agent).
  • Always-on description budget 5k → 6.5k (two test assertions updated with rationale).

3. Drift-aware diagnostics

  • schemaDiagnostics maps high-frequency wrong fields (worker/workers/agentworker_type, prompt/taskinstruction, top-level objectiveconfig.objective, blocksnodes) to Did you mean "..."? hints, matching both message text and diagnostic path (decode leaves carry only the tag; the field name lives in the path).

Why this design

The tool parameter schema is the only layer the provider enforces structurally (OpenAI tools contract). Moving graph serialization from free-text YAML into the harness puts field-name errors under that enforcement — the same reasoning as the params-object-root contract from #262, applied to the authoring side.

Test plan

  • 5 new draft tests: render round-trip (multi-line instruction text with colons/quotes survives), bad-dependency diagnostics without workflow creation, unsafe workflow-name rejection, schema-level drift rejection (worker, top-level objective, missing config), mixed blocks+nodes owned by authoring layer
  • New drift-hint test: worker: general yields Did you mean "worker_type"?
  • bun test test/dag 496/496 green
  • core test/plugin/command.test.ts 21/21 green
  • tsgo --noEmit clean in packages/opencode and packages/core

Models writing workflow YAML by hand drift on field names and structure
(live-observed: objective at top level, worker instead of worker_type) even
with the reference template in context — YAML is an unvalidated text channel,
so prompting alone cannot reach zero. This closes the gap at three layers:

- workflow(action="draft"): pass the structured config through the tool
  parameter schema; the harness renders YAML to .opencode/workflow-drafts/,
  validates it, and returns the spec_path. Unknown fields are rejected by
  the provider-side schema before any file is written; YAML syntax errors
  disappear because rendering is code. spec_path contract unchanged.
- routing guide now carries the minimal complete start-spec example inline
  (one hop) plus the field-ownership rules; description budget 5k -> 6.5k.
- schemaDiagnostics maps high-frequency drift fields (worker/agent ->
  worker_type, prompt -> instruction, top-level objective -> config) to
  "Did you mean" hints, matching both message text and diagnostic path.

Verified: test/dag 496/496 green incl. 5 new draft tests (render round-trip,
bad-dependency diagnostics, unsafe-name rejection, schema drift rejection,
drift hint); core command tests 21/21; tsgo clean in both packages.
Comment thread packages/opencode/src/dag/validation.ts Fixed
Comment thread packages/opencode/src/dag/validation.ts Fixed
The draft action commit (76df802) added the 11th parameter-union branch
but missed test/tool/__snapshots__/parameters.test.ts.snap; the stale
snapshot failed 'tool parameters > JSON Schema (wire shape) > workflow'
deterministically (surfaced as an external red gate during a concurrent
verification run). Regenerated via bun test --update-snapshots; full
test/tool + workflow-tool suites green (384 pass).
The draft-action commit spliced the heading onto the preceding paragraph
line, dropping it from rendered markdown structure.
The RegExp escape forms tripped two unnecessary-escape warnings, pushing
CI's oxlint count past the --max-warnings=4852 ratchet. Diagnostic paths
are JSON.stringify-segmented, so a plain ["field"] substring check
covers the same matches without the regex.
@LeXwDeX
LeXwDeX merged commit 4367b77 into dev Aug 14, 2026
5 checks passed
@LeXwDeX
LeXwDeX deleted the feat/workflow-draft-action branch August 14, 2026 16:06
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.

2 participants