Commit graph

59 commits

Author SHA1 Message Date
matt wilkie
f3d57da63a
fix(release): ship beads-release formula (#3631)
Merged after maintainer review for release prep. CI was green and PR was approved.
2026-05-02 14:02:36 -07:00
matt wilkie
52fc26afb9 Fix gate and cook regressions (bd-r2l) 2026-04-25 17:41:39 -07:00
Graeme Foster
6681fdc974
fix(formula): carry step metadata through cook and pour (GH#3341) (#3359)
TOML and JSON formulas accepted `metadata = { ... }` on a step
without error, but the field was silently dropped:

  - `formula.Step` had no `Metadata` field, so the TOML/JSON parsers
    discarded the table during decode.
  - `processStepToIssue` built the template issue with no metadata.
  - `cloneSubgraph` omitted `Metadata` when spawning the mol/wisp,
    so even if the template carried it, the poured bead did not.

Add `Step.Metadata map[string]interface{}` so the parser keeps the
table, marshal it to JSON in `processStepToIssue`, and copy the raw
bytes through in `cloneSubgraph`. `bd cook` now shows `metadata`
under each step, and `bd mol pour` / `bd mol wisp` land the bead
with the declared keys.
2026-04-20 18:05:19 -07:00
Okano, Osamu
9b4896f0e8
Fix formula search paths for worktree-aware beads dirs (#3235)
* fix(formula): resolve worktree-aware search paths (beads-oto)

intent(formula): worktree users should resolve formulas from the active shared .beads registry instead of cwd-only paths

decision(formula-search): route CLI help, formula lookup, and distill output hints through formula.DefaultSearchPaths so search path display matches runtime behavior

constraint(worktree): keep cwd/.beads fallback when no beads project is resolved so local formula registries still work before init

* fix(formula): align mol seed help with resolved search paths

intent(formula-help): worktree users should see the active beads workspace path instead of stale cwd-based guidance
constraint(formula-runtime): seed already resolves formulas through the shared default search helper so this change only updates the displayed contract

* test(formula): isolate worktree parser repo hooks

intent(formula-tests): keep worktree search path coverage focused on formula resolution instead of developer git hook state
constraint(git-test-repos): global core.hooksPath can inject failing pre-commit hooks into temp repos and break the setup commit
decision(formula-tests): reuse ForceRepoLocalHooksPath so the new worktree test follows the repo's existing git test isolation rule

* test(formula): simplify search-path test setup (beads-6kum)

intent(formula-tests): keep the new search-path coverage easy to extend without re-reading repetitive test scaffolding
constraint(formula-tests): helper extraction must preserve the hook-isolation and cache-reset behavior added for worktree coverage
decision(formula-tests): centralize repo init, fixture writing, and canonical path handling into local test helpers so each case stays focused on its assertions
2026-04-13 11:01:28 -07:00
maphew
97889d9a79 fix: include convoy-type formulas in bd formula list text output
bd formula list counted convoy formulas in the header total but omitted
them from the rendered output because typeOrder only had workflow,
expansion, and aspect sections. Add convoy to the type order, add the
🚐 icon, register TypeConvoy as a valid FormulaType, and update the
--type flag help text.

Fixes steveyegge/beads#2825
🤖 Generated with [Nori](https://nori.ai)

Co-Authored-By: Nori <contact@tilework.tech>
2026-03-30 06:45:14 -07:00
Harry
a82d500129 cleanup: remove remaining Gas Town terminology from help text, docs, and comments
Replace Gas Town-specific terminology with generic equivalents across
user-facing help text, documentation, code comments, MCP integration,
and scripts.

Terminology replacements:
- polecat → agent/worker
- witness → observer
- deacon → patrol system
- refinery → processor
- mayor → coordinator
- crew → assistant
- gt (command) → bd
- Gas Town role lists → generic role descriptions

Changes by category:
- User-facing help text (7 files): create.go, state.go, mol_bond.go,
  gate.go, mol_ready_gated.go, memory.go, swarm.go
- Documentation (5 files): dolt-concurrency.md (reframed for standalone
  beads), MOLECULES.md, LABELS.md, CLI_REFERENCE.md,
  CONTRIBUTOR_NAMESPACE_ISOLATION.md
- Code comments (5 files): dolt.go, doctor/artifacts.go,
  fix/artifacts.go, store.go, queries.go, formula/types.go
- MCP integration (2 files): tools.py comments, test docstring
- Scripts (1 file): release.sh

Backwards compatibility: Doctor artifact detection patterns for
polecats/crew/refinery directories are retained with updated comments
noting they exist for orchestrator backwards compatibility. MCP redirect
test paths also retained for the same reason.

Fixes #2758

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-22 13:27:43 -07:00
Gas City
f286e39ad0 fix: formula extends merges child steps by ID instead of appending
Child steps with the same ID as a parent step now replace the parent
step in-place (preserving DAG position) rather than being appended,
which caused Validate() to reject the formula with "duplicate id".
This matches the documented behavior and how vars already work.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-13 23:49:44 +00:00
mayor
c459812ef4 fix: default bd mol wisp create to root-only unless formula sets pour=true
Wisp creation was materializing child step issues for every formula,
causing ~12 orphan DB rows per patrol cycle. Wisps are vapor (ephemeral)
by definition — child steps should only be materialized when the formula
explicitly sets pour=true (e.g. release workflows needing checkpoint
recovery). Adds Pour field to Formula and TemplateSubgraph types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 14:50:20 -08:00
maphew
2b1d84d33f fix: propagate notes field from formula steps to issues (#2155)
Formula TOML [[steps]] can define a notes field, but it was silently
discarded during pour because formula.Step had no Notes field.

Add Notes field to formula.Step struct, map it to issue.Notes in
processStepToIssue(), and include it in variable substitution in
substituteStepVars().

Fixes #2155

Amp-Thread-ID: https://ampcode.com/threads/T-019ca75d-c29a-74d8-9f43-9bdad824dabe
Co-authored-by: Amp <amp@ampcode.com>
2026-02-28 20:19:43 -07:00
Xexr
8561884cba
feat(cook): support standalone expansion formula execution in bd mol wisp (#1903)
Expansion formulas (e.g. rule-of-five, spec-brainstorm-expansion) could
only run via Compose workflow wrappers that resolve {target} placeholders.
Running them directly with `bd mol wisp` produced an empty epic with no
child steps.

Add MaterializeExpansion() to convert a standalone expansion formula's
Template into Steps using a synthetic "main" target. Call it in
resolveAndCookFormulaWithVars() before cooking to subgraph so the normal
pipeline processes the expanded steps.

Also fix propagateTargetDeps() to carry the target step's dependencies
into the root steps of each expansion, and rebuild stepMap after each
UpdateDependenciesForExpansion call so subsequent iterations see resolved
references.

All 9 expansion formulas now work standalone:
  bd mol wisp rule-of-five --dry-run → 6 issues
  bd mol wisp spec-multimodal-scope-questions-expansion \
    --var feature=X --var brief=Y --dry-run → 9 issues

Closes #663

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/leeloo
Rig: beads
Role: crew
2026-02-22 13:00:25 -08:00
beads/crew/leeloo
e75188802f
fix(cook): propagate cross-expansion dependencies to expanded steps
When bd cook expands placeholder steps via compose.expand, the target
step's Needs/DependsOn were discarded. The first substep of each
expansion started with needs:[] instead of inheriting the parent step's
dependencies, causing molecules to execute steps out of order.

Add propagateTargetDeps() to copy the target step's dependencies to the
root steps of each expansion. Also rebuild stepMap after each
UpdateDependenciesForExpansion call so subsequent iterations see resolved
(not stale) dependency references.

Fixes both ApplyExpansions (compose.expand/map) and
ApplyInlineExpansions (step.expand).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/leeloo
Rig: beads
Role: crew
2026-02-22 14:25:03 +00:00
beads/crew/emma
08a3e25a05 fix(formula): distinguish "no default" from default="" in VarDef
VarDef.Default was a plain string, so Go zero value "" was
indistinguishable from an explicit default="". This caused 50+ formula
variables with default="" (meaning "optional, skip if empty") to be
treated as required, breaking gt sling for operational formulas.

Change Default from string to *string: nil = no default specified,
non-nil (including &"") = has explicit default. Mechanical change
across all consumer sites with consistent nil-check pattern.

Fixes: steveyegge/gastown#1551

Co-authored-by: julianknutsen <julianknutsen@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Executed-By: beads/crew/emma
Rig: beads
Role: crew
2026-02-16 20:12:52 -08:00
beads/crew/lizzy
2bb827facb style: run gofmt across entire codebase (bd-nmk12)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 19:35:20 -08:00
obsidian
001a6aebc0 fix: accept simple string vars in TOML [vars] section
Add UnmarshalTOML method to VarDef to handle both simple string
assignments and full table definitions:

  [vars]
  wisp_type = "patrol"           # simple string -> Default = "patrol"

  [vars.component]               # table with full definition
  description = "Component name"
  required = true

Fixes bd-8l59: Formula parser rejects simple string vars in [vars] section

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-03 14:13:13 -08:00
Steve Brown
823efe63ca
fix: add toml tags for snake_case fields in formula structs
BurntSushi/toml cannot match TOML keys like `depends_on` to Go struct
fields like `DependsOn` because the underscore breaks field name matching.
Only `json:` tags were present, causing these fields to be silently ignored
when parsing .formula.toml files.

This adds `toml:` tags to all snake_case fields:
- Step.DependsOn, Step.Needs (step dependencies)
- Step.WaitsFor (fanout gate)
- Step.ExpandVars (expansion variables)
- Step.OnComplete (completion hooks)
- OnCompleteSpec.ForEach (iteration)
- ComposeRules.BondPoints (composition)
- BondPoint.AfterStep, BondPoint.BeforeStep (attachment points)

Added TestParseTOML_SnakeCaseFields to verify depends_on, needs, and
waits_for are correctly parsed from TOML formulas.

Fixes: https://github.com/steveyegge/beads/issues/1449
2026-02-02 21:23:08 -08:00
obsidian
aaa8c3d032 test: add gate field parsing tests (bd-4bt1)
Add tests for parsing the Gate field in formula steps:
- TestParse_GateField: JSON parsing with all gate fields
- TestParse_GateFieldTOML: TOML parsing
- TestParse_GateFieldMinimal: minimal gate with only type
- TestParse_GateFieldWithAllTypes: all gate types (gh:run, gh:pr, timer, human, bead, mail)
- TestParse_GateInChildStep: gate in nested child steps

The Gate struct and Step.Gate field already existed. These tests
verify TOML and JSON parsing works correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-02 13:45:10 -08:00
jasper
b73085962c feat: Implement Step.Gate evaluation (Phase 1: Human Gates)
This implements Phase 1 of the Step.Gate feature (bd-7zka.2):

- bd cook now creates gate issues for steps with gate fields
- Gate issues have type=gate and block the gated step via dependency
- bd list filters out gate issues by default (use --include-gates to show)
- New bd gate command with list and resolve subcommands

Gate types supported in Phase 1:
- human: Manual closure via bd close or bd gate resolve

Implementation details:
- createGateIssue() in cook.go creates gate issues with proper metadata
- collectSteps() creates gate dependencies when processing gated steps
- IssueFilter.ExcludeTypes added to storage layer for type-based filtering
- Gate command provides dedicated UX for gate management

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-01 16:25:59 -08:00
beads/crew/emma
6893eb6080 feat: add negation support for step conditions (!{{var}})
Adds "!{{var}}" syntax for negated truthy checks in Step.Condition.
Useful for "skip this step if feature is enabled" patterns.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 00:37:59 -08:00
beads/crew/emma
ee34a74e90 feat: implement Step.Condition evaluation in bd cook (bd-7zka.1)
Add compile-time step filtering based on formula variables:
- New EvaluateStepCondition function for {{var}} truthy and equality checks
- FilterStepsByCondition to exclude steps based on conditions
- Integration into pour, wisp, and mol bond commands
- Supports: {{var}}, {{var}} == value, {{var}} != value

Steps with conditions that evaluate to false are excluded from the
cooked formula, along with their children.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-31 00:33:11 -08:00
Steve Yegge
5f3cb0fdf3 refactor: remove Gas Town references from codebase
Replace Gas Town-specific terminology with generic orchestrator concepts:
- "Gas Town" → "orchestrator" or "multi-clone"
- Hardcoded ~/gt/ paths → GT_ROOT environment variable
- signalGasTownActivity → signalOrchestratorActivity
- GUPP → hook-based work assignment

Updated 21 files across CHANGELOG, cmd/bd/, internal/, docs/, scripts.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Executed-By: beads/crew/dave
Rig: beads
Role: crew
2025-12-30 14:13:32 -08:00
Steve Yegge
b273465966 chore: remove stale TODOs for implemented Expand/ExpandVars (bd-qe7j)
- Step.Expand and Step.ExpandVars are implemented in ApplyInlineExpansions
  (expand.go), but had stale TODO comments claiming they were not
- Updated doc comments to reference the implementation
- Updated bd-7zka to reflect which features are still not implemented
  (Step.Condition and Step.Gate remain as future work)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-30 00:39:16 -08:00
Steve Yegge
27de61fbd0 chore: Convert scattered TODOs to tracked issues (bd-lrj8)
Created 7 new beads to track TODOs that were previously inline comments:

- bd-7l27: Integrate migration detection into bd doctor (5 files)
- bd-6x6g: Add multi-repo target repo switching in bd create
- bd-ag35: Add daemon RPC endpoints for config and stale check
- bd-2dwo: Remove deprecated daemon logger function
- bd-0qx5: Implement Jira issue timestamp comparison for sync
- bd-7zka: Implement formula features (repeat, for_each, branch, gate, split)
- bd-h048: Refactor sync_test to use direct import logic

Updated 16 TODO comments to include bead ID references for tracking.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 16:34:24 -08:00
Steve Yegge
f46cc2e798 chore: remove issue ID references from comments and changelogs
Strip (bd-xxx), (gt-xxx) suffixes from code comments and changelog
entries. The descriptions remain meaningful without the ephemeral
issue IDs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 10:05:16 -08:00
Steve Yegge
dfc796589f feat: add pour warning for vapor-phase formulas, improve help text, add doctor check
- Add Phase field to Formula type to indicate recommended instantiation phase
- Add warning in 'bd mol pour' when formula has phase="vapor"
- Improve pour/wisp help text with clear comparison of when to use each
- Add CheckPersistentMolIssues doctor check to detect mol- issues in JSONL
- Update beads-release.formula.json with phase="vapor"

This helps prevent accidental persistence of ephemeral workflow issues.
2025-12-28 01:34:01 -08:00
Steve Yegge
1611f16751 refactor: remove unused bd pin/unpin/hook commands (bd-x0zl)
Analysis found these commands are dead code:
- gt never calls `bd pin` - uses `bd update --status=pinned` instead
- Beads.Pin() wrapper exists but is never called
- bd hook functionality duplicated by gt mol status
- Code comment says "pinned field is cosmetic for bd hook visibility"

Removed:
- cmd/bd/pin.go
- cmd/bd/unpin.go
- cmd/bd/hook.go

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 16:02:15 -08:00
Steve Yegge
c8b912cbe6 bd sync: 2025-12-27 15:56:42 2025-12-27 15:56:42 -08:00
Ryan Snodgrass
350a78f1ba
fix: resolve all golangci-lint errors
Fixes 15 pre-existing lint issues:

errcheck (6 issues):
- mol_distill.go: Add _ = for f.Close() and os.Remove()
- routed.go: Add _ = for routedStorage.Close() (4 locations)

gosec (8 issues):
- maintenance.go, routes.go: Add nolint for G304 (file paths from known dirs)
- mol_distill.go: Add nolint for G304 (file creation in known search paths)
- formula.go: Change WriteFile permissions from 0644 to 0600 (G306)
- gate.go: Add nolint for G204 (exec.Command with trusted AwaitID fields)

misspell (1 issue):
- gate.go: Fix "cancelled" -> "canceled" in comment

unparam (2 issues):
- cook.go, controlflow.go: Add nolint for functions returning always-nil error

Also:
- Update pre-commit-hooks to v6.0.0
- Add lint step to "Landing the Plane" session-end protocol
2025-12-26 19:20:03 -05:00
Steve Yegge
df5d4b384c Add TOML support for formulas (gt-xmyha)
- Add TOML parsing using BurntSushi/toml
- Update formula loader to try .toml first, fall back to .json
- Add `bd formula convert` command for JSON→TOML migration
- Multi-line string support for readable descriptions
- Cache git worktree/reporoot checks for performance

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 21:59:19 -08:00
Steve Yegge
e91f0de8d1 feat(formula): Add inline step expansion (gt-8tmz.35)
Steps can now declare their own expansion using the Expand field:

  steps:
    - id: design
      expand: rule-of-five
      expand_vars:
        iterations: 3

This is more convenient than compose.expand for single-step expansions.
The step is replaced by the expansion template with variables substituted.

Reuses existing expandStep() and mergeVars() from gt-8tmz.34.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 20:46:12 -08:00
Steve Yegge
f82c75c39e feat(formula): Validate expanded step IDs are unique (gt-8tmz.36) 2025-12-25 20:19:55 -08:00
Steve Yegge
e8458935f9 feat(formula): Implement expansion var overrides (gt-8tmz.34)
- Add vars parameter to expandStep for {varname} substitution
- Add mergeVars to combine formula defaults with rule overrides
- Update ApplyExpansions to merge and pass vars for expand/map rules
- Apply var substitution to step ID, title, description, assignee,
  labels, and dependencies
- Add comprehensive tests for var overrides functionality

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 20:07:29 -08:00
Steve Yegge
f3a5e02a35 feat(close): Add --suggest-next flag to show newly unblocked issues (GH#679)
When closing an issue, the new --suggest-next flag returns a list of
issues that became unblocked (ready to work on) as a result of the close.

This helps agents and users quickly identify what work is now available
after completing a blocker.

Example:
  $ bd close bd-5 --suggest-next
  ✓ Closed bd-5: Completed

  Newly unblocked:
    • bd-7 "Implement feature X" (P1)
    • bd-8 "Write tests for X" (P2)

Implementation:
- Added GetNewlyUnblockedByClose to storage interface
- Implemented efficient single-query for SQLite using blocked_issues_cache
- Added SuggestNext field to CloseArgs in RPC protocol
- Added CloseResult type for structured response
- CLI handles both daemon and direct modes

Thanks to @kraitsura for the detailed feature request and design.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 20:05:04 -08:00
Steve Yegge
cfecadc8a5 docs: Clarify formulas are JSON, add distillation and sharing docs
- Fix YAML → JSON references in formula.go and types.go
- Update MOLECULES.md with ephemeral proto architecture
- Add Distillation section: extract formulas from completed work
- Add Sharing section: Mol Mall formula marketplace
- Update Layer Cake diagram to show ephemeral proto flow

Related: bd-1dez (Mol Mall epic)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 18:43:08 -08:00
Steve Yegge
ea9f1d2760 Add edge case tests for expression evaluator (code review)
Test cases for:
- Unary minus in expression: 3*-2 -> -6
- Parenthesized negative: (-5) -> -5
- Unary minus after power: 2^-1 -> 0 (truncated)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 17:55:42 -08:00
Steve Yegge
030838cfde Implement computed range expansion for loops (gt-8tmz.27)
Add support for for-each expansion over computed ranges:

  loop:
    range: "1..2^{disks}-1"  # Evaluated at cook time
    var: move_num
    body: [...]

Features:
- Range field in LoopSpec for computed iterations
- Var field to expose iteration value to body steps
- Expression evaluator supporting + - * / ^ and parentheses
- Variable substitution in range expressions using {name} syntax
- Title/description variable substitution in expanded steps

Example use case: Towers of Hanoi formula where step count is 2^n-1

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 17:48:35 -08:00
Steve Yegge
ba17898365 Implement fanout gate: waits-for children aggregation (gt-8tmz.38)
- Add children-of(step-id) syntax for explicit spawner reference
- Add WaitsForSpec type and ParseWaitsFor() helper
- Update cook.go to create DepWaitsFor dependencies with metadata
- Infer spawner from first needs entry when using all-children
- Add validation tests for children-of() syntax
- Add unit tests for ParseWaitsFor()

This completes the Christmas Ornament aggregation pattern:
- survey-workers does for-each → creates N children
- aggregate waits-for children-of(survey-workers)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 17:33:54 -08:00
Steve Yegge
73e56d0876 Fix in-place mutation in ApplyBranches/ApplyGates (gt-v1pcg)
- ApplyBranches and ApplyGates now clone steps before modifying,
  matching the immutability pattern of ApplyLoops and ApplyAdvice
- Added internal applyBranchesWithMap/applyGatesWithMap for efficiency
- ApplyControlFlow builds stepMap once for both (gt-gpgdv optimization)
- Added cloneStepsRecursive helper
- Added TestApplyBranches_Immutability and TestApplyGates_Immutability

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 16:48:37 -08:00
Steve Yegge
d2f71773cb fix: Chain iterations after nested loop expansion (gt-zn35j)
Fixes a bug where outer iteration chaining was lost when nested loops
were expanded. The problem was:

1. chainLoopIterations set: outer.iter2.inner depends on outer.iter1.inner
2. ApplyLoops recursively expanded nested loops
3. outer.iter2.inner became outer.iter2.inner.iter1.work, etc.
4. The dependency was lost (referenced non-existent ID)

The fix:
- Move recursive ApplyLoops BEFORE chaining
- Add chainExpandedIterations that finds iteration boundaries by ID prefix
- Works with variable step counts per iteration (nested loops expand differently)

Now outer.iter2's first step correctly depends on outer.iter1's LAST step,
ensuring sequential execution of outer iterations.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 16:35:28 -08:00
Steve Yegge
bce4f8f2d4 feat: Add source tracing metadata to cooked steps (gt-8tmz.18)
Add SourceFormula and SourceLocation fields to track where each step
came from during the cooking process. This enables debugging of complex
compositions with inheritance, expansion, and advice.

Changes:
- Added SourceFormula and SourceLocation fields to Step struct (formula/types.go)
- Added same fields to Issue struct (types/types.go)
- Added SetSourceInfo() to parser.go - sets source on all steps after parsing
- Updated cook.go to copy source fields from Step to Issue
- Updated dry-run output to display source info: [from: formula@location]
- Updated advice.go to set source on advice-generated steps
- Updated controlflow.go to preserve source on loop-expanded steps
- Updated expand.go to preserve source on template-expanded steps

The source location format is:
- steps[N] - regular step at index N
- steps[N].children[M] - child step
- steps[N].loop.body[M] - loop body step
- template[N] - expansion template step
- advice - step inserted by advice transformation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 16:27:48 -08:00
Steve Yegge
b43358b600 feat: Add nested loop support in control flow (gt-zn35j)
Enables loops within loop bodies to be properly expanded:

- Copy Loop field in expandLoopIteration (was intentionally omitted)
- Add cloneLoopSpec for deep copying of LoopSpec with body steps
- Recursively call ApplyLoops at end of expandLoop to expand nested loops
- Also copy OnComplete field for consistency

Nested IDs follow natural chaining pattern:
  outer.iter1.inner.iter2.step

Tested with 2-level and 3-level nesting scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 16:22:58 -08:00
Steve Yegge
a42fac8cb9 feat: Add on_complete/for-each runtime expansion types (gt-8tmz.8)
Implements the schema and validation for runtime dynamic expansion:

- Add OnCompleteSpec type for step completion triggers
- Add on_complete field to Step struct
- Validate for_each path format (must start with "output.")
- Validate bond is required with for_each (and vice versa)
- Validate parallel and sequential are mutually exclusive
- Add cloneOnComplete for proper step cloning
- Add comprehensive tests for parsing and validation

The runtime executor (in gastown) will interpret these fields to:
- Bond N molecules when step completes based on output.collection
- Run bonded molecules in parallel or sequential order
- Pass item/index context via vars substitution

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 16:07:57 -08:00
Steve Yegge
8b5168f1a3 fix: Control flow review fixes (gt-8tmz.4)
Critical bug fixes identified during code review:

1. External dependency rewriting: Dependencies on steps OUTSIDE the loop
   are now preserved as-is instead of being incorrectly prefixed.

2. Children dependency rewriting: Child step dependencies are now properly
   rewritten with iteration context.

3. Missing fields: Added Expand, ExpandVars, Gate fields to loop expansion.

4. Condition validation: Loop `until` conditions are now validated with
   ParseCondition to catch syntax errors early.

5. Label format: Changed gate and loop labels from colon-delimited to
   JSON format for unambiguous parsing:
   - gate:{"condition":"expr"}
   - loop:{"until":"expr","max":N}

Added TestApplyLoops_ExternalDependencies to verify the fix.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 15:02:07 -08:00
Steve Yegge
4f065024b5 feat: Implement control flow operators (gt-8tmz.4)
Add loop, branch, and gate operators for formula step transformation:

- LoopSpec: Fixed-count loops expand body N times with chained iterations.
  Conditional loops expand once with runtime metadata labels.
- BranchRule: Fork-join patterns wire dependencies for parallel paths.
- GateRule: Adds condition labels for runtime evaluation before steps.

Types added to types.go:
- LoopSpec (count/until/max/body)
- BranchRule (from/steps/join)
- GateRule (before/condition)
- Loop field on Step
- Branch/Gate arrays on ComposeRules

New controlflow.go with ApplyLoops, ApplyBranches, ApplyGates, and
ApplyControlFlow convenience function. Wired into cook.go before
advice and expansion operators.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 14:52:21 -08:00
Steve Yegge
c9aa755ddc fix: Address code review issues in condition evaluator
- Empty set 'all' returns false (avoids premature gate passing)
- Add proper error handling for Atoi in count comparisons
- Extract inline regex to package-level var (performance)
- Handle == and != in compareString function
- Add nil/bool value handling in compare function
- Add tests for edge cases: empty children, nil output, bool values

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 14:00:56 -08:00
Steve Yegge
f56f3615e8 feat: Add condition evaluator for gates and loops (gt-8tmz.7)
Implements mechanical condition evaluation for formula control flow:
- Step status checks: step.status == 'complete'
- Step output access: step.output.approved == true
- Aggregates: children(step).all(status == 'complete'), steps.complete >= 3
- External checks: file.exists('go.mod'), env.CI == 'true'

Conditions are intentionally limited to keep evaluation decidable.
No arbitrary code execution allowed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 13:54:21 -08:00
Steve Yegge
fd57f61f34 fix: Prevent aspect self-matching infinite recursion (gt-8tmz.16)
ApplyAdvice now collects original step IDs before applying rules and
only matches steps in that set. This prevents advice patterns (like "*")
from matching their own inserted before/after steps.

Added test case demonstrating that a "*" pattern only adds advice to
original steps, not to inserted steps.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 12:21:23 -08:00
Steve Yegge
516c62e543 feat: Add aspect composition support (gt-8tmz.5)
- Add Aspects field to ComposeRules for listing aspect formulas
- Apply aspects during cooking after expansions
- Aspects are loaded by name and their advice rules are applied

Usage in formula:
  "compose": {
    "aspects": ["security-audit", "logging"]
  }

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 12:15:12 -08:00
Steve Yegge
de1a9559fa fix: Map expansion now matches nested child steps (gt-8tmz.33)
The map rule was only iterating over top-level steps, missing nested
children. Now uses buildStepMap to include all steps at any depth.

Added test case for map expansion over nested children.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 12:08:05 -08:00
Steve Yegge
acb4aeee55 Fix misleading comment in replaceStep 2025-12-25 11:51:03 -08:00
Steve Yegge
b82d0e7c0f Fix expansion operators: update dependencies after expansion
When a step is expanded (e.g., implement -> implement.draft, implement.refine-1,
etc.), any steps that depended on the original step should now depend on the
last step of the expansion.

Call UpdateDependenciesForExpansion after both expand and map operations.

Fixes gt-8tmz.3

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-25 11:44:28 -08:00