Skip to content

Switch to code-factory template + structured template inputs#115

Merged
neekolas merged 25 commits intomainfrom
04-20-add_template_inputs
Apr 21, 2026
Merged

Switch to code-factory template + structured template inputs#115
neekolas merged 25 commits intomainfrom
04-20-add_template_inputs

Conversation

@neekolas
Copy link
Copy Markdown
Contributor

@neekolas neekolas commented Apr 21, 2026

Summary

Adds the wiring needed to route task_requested workflows through the new code-factory Coder template when a repo has a .code-factory/config.toml, while keeping the legacy template behavior untouched for repos without one.

What changed

Workflow: runCreateTask

  • Adds a new lookup-repo-config step (between lookup-coder-user and create-coder-task) that reads the per-repo RepoConfigDO.
  • If the DO returns null, the flow is unchanged: prompt = issue URL, legacy template.
  • If a config is present, the workflow builds a JSON TemplateInputs payload and passes templateName: config.codeFactoryTemplate into coder.create(...).
  • RunCreateTaskContext gains an env: { REPO_CONFIG_DO } seam; TaskRunnerWorkflow threads this.env.REPO_CONFIG_DO through to the step factory.

New TemplateInputs schema (src/workflows/steps/template-inputs.ts)

  • Zod schema matching the contract expected by the new template (repo_url, base_branch?, repo_name, ai_prompt, ai_provider, extra_volumes?, size, docker).
  • buildTemplateInputs() composes the payload from (repository, issue, settings). ai_prompt is pre-filled for the /coder-task skill:
    ISSUE_URL: <url>
    REPO_OWNER: <owner>
    REPO_NAME: <name>
    ISSUE_ID: <id>
    
    Use the /coder-task skill to resolve the issue
    

Event shape

  • TaskRequestedEvent.issue gains id: number. The router now populates it from payload.issue.id.

AppConfig

  • Adds codeFactoryTemplate: z.string().min(1).default("code-factory"). Intentionally not wired to an env var in loadConfig — the template name is hardcoded and used only on the new-config branch.

RepoConfigSchema

  • HarnessProviderSchema enum updated: "claude""claude_code" (and the resolved default). Matches the Terraform template's ai_provider values.
  • Volume-size normalization. Adds a reusable VolumeSizeSchema that accepts common variants (10gb, 10GB, 10G, 10gi, 500mb, 2tb, 64k, with optional whitespace) and transforms to the canonical Kubernetes binary-SI form (10Gi). Wired into both the stored (write-path) and resolved (read-path) schemas, so:
    • New writes persist canonical values.
    • Legacy stored values get normalized on read — no migration needed.
    • The buildTemplateInputs consumer receives already-canonical sizes.
  • Resolved default size updated from "10gb""10Gi".

CoderService.create

  • Gains optional templateName?: string (mirrored on the TaskRunner interface). When provided, overrides the runner-configured template at the endpoint-resolution step. All other semantics unchanged.

Test coverage

  • create-task.test.ts: step-order assertion updated to include lookup-repo-config; new cases cover both branches — null config (legacy prompt, no templateName override) and present config (JSON TemplateInputs with codeFactoryTemplate, asserting the full ai_prompt block).
  • repo-config-schema.test.ts: test.each over 13 size-input variants → canonical form, re-normalization of legacy stored values on read, and test.each over invalid formats → rejection. Existing fixtures updated (claudeclaude_code, 20gb20Gi, 10gb10Gi).
  • repo-config-do.test.ts, router.test.ts, task-runner-workflow.test.ts, instance-id.test.ts: fixture shapes updated for the new issue.id field and canonical volume sizes.

All 373 tests pass; typecheck + biome lint/format clean.

Test plan

  • npx tsc --noEmit passes
  • npm test — 373 passing (pre-existing terraform-submodule suites still skipped due to bun:test imports — unrelated)
  • Dev-deploy smoke-test: exercise issues.assigned against a repo with and without .code-factory/config.toml, verify TaskRunnerWorkflow instance logs show the new lookup-repo-config step and correct template selection.

Note

Switch task creation to use code-factory template with structured inputs when repo config exists

  • runCreateTask now performs a lookup-repo-config step via RepoConfigDO; if a config is found, it builds structured TemplateInputs JSON (including ai_provider, volumes, and ISSUE_ID) and targets the code-factory template instead of passing a plain issue URL.
  • Adds buildTemplateInputs and buildAiPrompt helpers in template-inputs.ts to construct the structured payload from repository, issue, and repo config settings.
  • Normalizes volume size strings (e.g. 10gb10Gi) via a new VolumeSizeSchema and normalizeVolumeSize util in repo-config-schema.ts; invalid formats are now rejected on parse.
  • Renames the harness provider value from claude to claude_code in HarnessProviderSchema and updates the default accordingly.
  • TaskRequestedEvent now includes issue.id, and CoderService.create accepts an optional templateName override.
  • Behavioral Change: repos without a stored config retain legacy behavior (plain issue URL, no template override); repos with config get the new template and JSON input format.

Macroscope summarized 045a242.

neekolas and others added 23 commits April 20, 2026 23:26
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ure Zed LSP

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ard preconditions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ll EARS-17 test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…al-storage

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Declares var.docker_enabled (default false) in the workspace-pod module,
wraps the DOCKER_HOST env and dind container in dynamic blocks gated on
that variable, and moves the kubernetes_pod_v1/kubernetes_deployment_v1
resources to root scope so terraform test assertions can reference them
directly. Threads docker_enabled = local.docker through the module call
so the TaskMetadata docker field controls sidecar presence end-to-end.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ker_enabled"

This reverts commit 6870e616c17a5197ecd9aa5e0f845aa8ae14039f.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…mapping

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown
Contributor

cloudflare-workers-and-pages Bot commented Apr 21, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
task-action 045a242 Apr 21 2026, 06:43 AM

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@neekolas neekolas changed the title chore(terraform): ignore .terraform/ cache and pin tflint ruleset Switch to code-factory template + structured template inputs Apr 21, 2026
@neekolas neekolas marked this pull request as ready for review April 21, 2026 06:43
@neekolas neekolas merged commit bddc757 into main Apr 21, 2026
5 checks passed
@neekolas neekolas deleted the 04-20-add_template_inputs branch April 21, 2026 06:43
@macroscopeapp
Copy link
Copy Markdown

macroscopeapp Bot commented Apr 21, 2026

Approvability

Verdict: Needs human review

This PR introduces significant new runtime behavior: conditional template selection based on repo config, new JSON structured inputs for task creation, volume size normalization, and provider enum changes. While well-tested, the changes affect production task creation workflows and warrant human review.

You can customize Macroscope's approvability policy. Learn more.

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