feat: Implement workflow generation command with YAML validation and LLM integration#37
Open
krishvsoni wants to merge 1 commit into
Open
Conversation
…LLM integration - Added `workflow.schema.json` for defining the structure of SkillFlow workflows. - Created `workflow.ts` to handle the `gitclaw workflow generate` command, including parsing flags and invoking the LLM. - Introduced `schemas.ts` for loading and validating workflows against the defined schema. - Developed `workflow-generator.ts` to manage LLM interactions and generate workflows based on user prompts. - Implemented tests for workflow generation and validation to ensure functionality and correctness. - Enhanced `package.json` test script for improved testing capabilities.
Author
|
Hey @shreyas-lyzr, pinging you on this one since you opened #9. Quick heads-up on scope: per your follow-up comment on the issue, this PR ships
That said, if you'd prefer to land it all in one go, I'm happy to extend this PR with:
Just let me know which way you want it:
Either way works for me, flagging early so we don't end up doing it twice. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implemented workflow generation command with YAML validation and LLM integration
Resolves #9
What changed
New files
spec/schemas/workflow.schema.jsonsrc/utils/schemas.tsloadWorkflowSchema(),getWorkflowSchemaText(),validateWorkflow(yamlText) → { valid, errors[], data? }. Hand-rolled validator (no new deps).src/utils/workflow-generator.tsgenerateWorkflow({ prompt, skills, previousWorkflow?, model?, apiKey?, llm? })— builds the system prompt + two few-shot pairs (linear pipeline, approval step), calls the LLM, strips code fences, returns YAML.llmis injectable so tests don't hit the network.src/commands/workflow.tsgitclaw workflow generatewith-d / -p / --refine / -m / --api-key / --dry-run. Runs the 2-retry validation loop and writesworkflows/<slug>.yaml.test/workflow-validator.test.tstest/workflow-generator.test.tstest/ts-resolve-hook.mjsnode --experimental-strip-typescan follow Node16-style.jsinternal imports during tests.Modified files
src/index.tsimport { handleWorkflowCommand }and an early-dispatch branch forgitclaw workflow …(mirrors the existinggitclaw plugin …pattern).package.jsontestscript preloads the resolve hook sonpm testworks out of the box.CLI surface
Why these choices
1. Schema on disk, not inlined
Single source of truth.
spec/schemas/workflow.schema.jsonis loaded at runtime and embedded verbatim into the LLM system prompt — the validator and the generator cannot drift.2. Hand-rolled validator (no AJV)
Zero new deps. AJV isn't in
package.json; rather than addajv+ajv-formats, the validator implements only what this schema needs (type,required,additionalProperties,pattern,minItems,$ref, plus adepends_oncross-field check) and exposes the same{ valid, errors[] }contract.3. LLM via
@mariozechner/pi-ai(injectable)Reuse the existing stack. pi-ai is what gitclaw already uses everywhere — supports all providers, inherits telemetry and cost tracking. The
llm?option makes it swappable, so tests stay offline.4. Retry loop, not best-effort
Bounded self-healing. When the LLM emits invalid YAML, the CLI re-prompts up to 2x with the validator's errors appended; if still invalid it prints errors + the last YAML and
exit(1)— no unbounded loop, no silent failure.5. Argv dispatch, not Commander
Match the codebase. gitclaw has no Commander dep — it uses hand-rolled argv parsing with subcommand dispatch (see
gitclaw plugin …). Theworkflowsubcommand follows the same pattern.6. Flat
requires_approval, not nestedcompliance.*Stay aligned with runtime. gitclaw's existing SkillFlow shape is flat (
skill/prompt/channel). A nestedcomplianceobject would diverge from the loader — the flat field is what the runtime can act on today.Proof
1. Tests pass — 24/24
2. Typecheck clean
3. Pre-existing tests not regressed
Existing
test/telemetry.test.ts— 8/8 still pass under the newnpm testflags.test/sdk.test.tsfails in this environment, but the failure is pre-existing and unrelated: it importsdist/exports.js, which requiresnpm run buildagainst@mariozechner/*packages that aren't installed locally. Nothing in this PR touches the SDK surface.4. End-to-end retry behavior demonstrated in tests
The "retries on invalid YAML, succeeds on second attempt" test plumbs an
LlmClientthat returns invalid YAML once, then valid YAML — and asserts the retry prompt to the LLM included the words "schema validation". From the test output above:The "give up after 2 retries" test:
5. Schema-driven safety: example violations the validator catches
name(root): missing required property "name"name: MyWorkflow(not kebab-case)name: value "MyWorkflow" does not match pattern ^[a-z0-9]+(-[a-z0-9]+)*$steps: []steps: array must have at least 1 item(s), got 0promptsteps[0]: missing required property "prompt"nonsense: truesteps[0]: unknown property "nonsense"depends_on: [does_not_exist]steps[1].depends_on: references unknown step id "does_not_exist"YAML parse error: …Issue → PR mapping (acceptance checklist)
-p "<text>"generateWorkflow+ few-shot examples;depends_onexpresses orderingworkflows/<slug>.yaml--refine <file>modesrc/utils/workflow-generator.tssrc/utils/schemas.ts+ retry loop insrc/commands/workflow.tsNotes for review
tsconfig.json.pi-agent-core+pi-ai) is lazy-imported, so it never loads in tests.OPENAI_API_KEY/<PROVIDER>_API_KEYresolution falls back through--api-key, then provider-specific env, thenOPENAI_API_KEY. Missing key produces a clear error andexit(1).