Skip to content

Commit 4637bc8

Browse files
somanshreddyclaude
andcommitted
docs: document single-use command tree invariant
The builder's PreRunE mutates Cobra flag annotations to bypass required-flag validation for --request-schema / --response-schema. This is safe because each CLI invocation builds a fresh command tree. Document this invariant in CLAUDE.md and AGENTS.md so future changes don't accidentally introduce command reuse. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7bbf538 commit 4637bc8

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Files in `gen/` are deleted and regenerated by `make generate`. Never put hand-w
4444
### `command.Spec` is immutable
4545
`Spec` is a generated, read-only definition. Never mutate it at runtime. Column definitions, poll configs, and other runtime enhancements are external lookup data in `cmd/heygen/`, passed to the formatter or builder as separate arguments.
4646

47+
### Cobra command tree is single-use
48+
`newRootCmd()` builds a fresh Cobra command tree for each CLI invocation. Command instances are never reused across executions — each `main()` call and each test creates a new tree. This is load-bearing: the builder's `PreRunE` mutates Cobra flag annotations to bypass required-flag validation for `--request-schema` / `--response-schema`. If command reuse were ever introduced (e.g., embedding as a library), those mutations would leak between executions.
49+
4750
### Codegen requires examples
4851
`make generate` fails if any command lacks examples. Examples live in `codegen/examples/{group}.yaml`. When adding a new endpoint to the OpenAPI spec, add matching examples or codegen will reject it.
4952

CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ Files in `gen/` are deleted and regenerated by `make generate`. Never put hand-w
4242
### `command.Spec` is immutable
4343
`Spec` is a generated, read-only definition. Never mutate it at runtime. Column definitions, poll configs, and other runtime enhancements are external lookup data in `cmd/heygen/`, passed to the formatter or builder as separate arguments.
4444

45+
### Cobra command tree is single-use
46+
`newRootCmd()` builds a fresh Cobra command tree for each CLI invocation. Command instances are never reused across executions — each `main()` call and each test creates a new tree. This is load-bearing: the builder's `PreRunE` mutates Cobra flag annotations to bypass required-flag validation for `--request-schema` / `--response-schema`. If command reuse were ever introduced (e.g., embedding as a library), those mutations would leak between executions.
47+
4548
### Codegen requires examples
4649
`make generate` fails if any command lacks examples. Examples live in `codegen/examples/{group}.yaml`. When adding a new endpoint to the OpenAPI spec, add matching examples or codegen will reject it.
4750

0 commit comments

Comments
 (0)