Skip to content

feat(autodev): autodev.toml schema reader + parameterised hook prompt#17

Merged
bahadirarda merged 1 commit into
mainfrom
feat/autodev-toml-schema
May 7, 2026
Merged

feat(autodev): autodev.toml schema reader + parameterised hook prompt#17
bahadirarda merged 1 commit into
mainfrom
feat/autodev-toml-schema

Conversation

@bahadirarda
Copy link
Copy Markdown
Contributor

Summary

Phase 2-4 of the autodev hook redesign. Builds on PR #16 (cwd guard) by adding the schema reader for <project>/.clawtool/autodev.toml, parameterising the continuation prompt, and adding the enabled = false operator-pause path.

Pipeline order in runAutodevHook

1. cwd guard      — exit 0 silently when no marker resolves upward from $PWD
2. config load    — parse the marker; fail-soft to defaults on read/parse error
3. enabled guard  — exit 0 silently when `enabled = false`
4. arm-flag guard — exit 0 silently when `autodev.enabled` flag absent
5. cap guard      — emit cap-reached message + exit when counter ≥ cap
6. fire           — increment counter, emit parameterised prompt

Schema

name = "myproj"                     # `Project: myproj` line in prompt
enabled = true                      # nil → true; &false → operator-pause
cap_per_session = 200               # overrides global 200 cap; non-positive → 200

[loop]
steps = [
    "step one",
    "step two",
]
stop_command = "/myproj-stop"       # empty → /clawtool-autodev-stop default

Backwards-compat

  • A minimal marker (e.g. name = "..." alone) parses cleanly. Empty [loop] steps → historical 5-step clawtool fallback. No operator action required for existing armed projects.
  • The .clawtool/autodev.toml shipped in PR feat(autodev): cwd guard — .clawtool/autodev.toml as project opt-in marker #16 is fully schema-compliant; verified by TestRunAutodevHook_RealClawtoolMarker_ParsesCleanly (regression guard against schema breakage).
  • Fail-soft parser: malformed TOML returns zero-config rather than blocking the hook. A Stop-hook fires every turn-end; a parse error must not silently disarm the loop.

Files

  • internal/cli/autodev_config.go (+105 lines) — autodevConfig struct, loadAutodevConfig, the three effective* helpers
  • internal/cli/autodev.go (+94/-17 lines) — pipeline ordering in runAutodevHook, autodevHookPrompt(triggerN, cfg) parameterisation, renderAutodevLoopSteps helper with historical fallback
  • internal/cli/autodev_config_test.go (+330 lines) — 10 new tests covering schema parse paths, fail-soft cases, prompt rendering, the live clawtool marker

Verification

gofmt -l                           # clean
go vet ./internal/cli/             # clean
go test -race -count=1 -timeout=60s -run \
  "TestRunAutodevHook|TestFindAutodevTOML|TestLoadAutodevConfig|TestAutodevHookPrompt" \
  ./internal/cli/ -v               # 15/15 PASS
go test -race -count=1 -timeout=180s ./internal/cli/   # ok 14.643s

What this unlocks

  • Operators can now author per-project loop steps without a Go PR. Edit .clawtool/autodev.toml, save, next turn-end picks up the new template.
  • enabled = false lets an operator pause the loop in a specific project without removing the marker (which would also drop forward-compat schema fields).
  • Cap-per-session lets long-running refactors raise the budget for a particular project, and short-running utilities lower it.
  • ADR-039 Phase A.5 (the --include-features ideator flag) now has a place to plug into: [loop] steps can reference clawtool ideate --include-features once that source-tier ships.

Wiki context

ADR-037 (wiki/decisions/037-autodev-hook-redesign.md, gitignored). This PR ships axes 2-4 of the four-axis design; the firing pipeline in §3 is now in place. ADR-037 §3 axes still pending: quiet-state gate (§3a), substrate probe code/wiki/stalled mode selection (§3b), autodev.lock JSON staleness rules (§3c). Those land in follow-up PRs.

Hygiene

Commit ran via mcp__clawtool__Commit (Conventional Commits + pre_commit rules.toml gate). gofmt-clean and race-clean rules trigger on this changeset (Go files touched) — both verified clean above. No internal-doc-id leakage in user-facing surfaces (CLI help, command help, prompt template). The [[037 Autodev hook redesign]] reference in the in-source comment is intentional — it's a Go source comment, not a user-facing surface, and the ADR is the canonical design record for this code.

Phase 2-4 of the autodev hook redesign. The hook now reads
`<project>/.clawtool/autodev.toml` and emits a project-parameterised
continuation prompt instead of the historical hardcoded clawtool-flavored
template.

Pipeline order in `runAutodevHook` (see in-source comment for the full
docblock):

  1. cwd guard — exit 0 silently when no marker resolves upward from $PWD
  2. config load — parse the marker; fail-soft to defaults on read or parse
     error so a broken TOML does not silently disarm the hook
  3. enabled guard — exit 0 silently when `enabled = false` (operator-pause)
  4. arm-flag guard — exit 0 silently when `autodev.enabled` flag absent
  5. cap guard — emit cap-reached message and exit when counter exceeds
     per-session cap (project override or 200 default)
  6. fire — increment counter, emit parameterised prompt

Schema (forward-compatible — fields documented in `docs/autodev.md` arrives
in a follow-up):

  name              string  surfaces as `Project: <name>` line
  enabled           *bool   nil → true; &false → operator-pause
  cap_per_session   int     overrides global 200 cap; non-positive → 200
  [loop] steps      []str   numbered list in the prompt; empty → historical
                            5-step clawtool fallback
  [loop] stop_command str   surfaced in cap-reached + step fallback;
                            empty → /clawtool-autodev-stop default

Backwards-compat:
- A minimal marker file (just `name = "..."`) parses cleanly and yields the
  historical prompt content via the steps-fallback. No operator action
  required for existing armed projects whose markers omit `[loop] steps`.
- The `.clawtool/autodev.toml` shipped in this repo last commit is fully
  schema-compliant; verified by `TestRunAutodevHook_RealClawtoolMarker_
  ParsesCleanly`.

Tests (10 new, all 15 in the suite race-clean):
  - TestLoadAutodevConfig_FullSchema
  - TestLoadAutodevConfig_DefaultsWhenFieldsMissing
  - TestLoadAutodevConfig_DisabledExplicit
  - TestLoadAutodevConfig_NonPositiveCapClamped
  - TestLoadAutodevConfig_FailsSoftOnMalformedTOML
  - TestLoadAutodevConfig_FailsSoftOnMissingFile
  - TestRunAutodevHook_DisabledExplicit_ExitsZero
  - TestAutodevHookPrompt_CustomLoopStepsRendered
  - TestAutodevHookPrompt_DefaultStepsFallback
  - TestRunAutodevHook_RealClawtoolMarker_ParsesCleanly

Verified clean: gofmt, go vet, go test -race ./internal/cli/.
@bahadirarda bahadirarda merged commit 7acde35 into main May 7, 2026
5 checks passed
@bahadirarda bahadirarda deleted the feat/autodev-toml-schema branch May 7, 2026 14:11
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