Molecule spawning now creates ephemeral issues that can be bulk-deleted when closed using `bd cleanup --ephemeral`. This supports the ephemeral molecule workflow pattern where execution traces are cleaned up while outcomes persist. Changes: - Add `ephemeral` parameter to cloneSubgraph() and spawnMolecule() - mol spawn: ephemeral=true by default, add --persistent flag to opt out - mol run: ephemeral=true (molecule execution) - mol bond: ephemeral=true (bonded protos) - template instantiate: ephemeral=false (deprecated, backwards compat) This is Tier 1 of the ephemeral molecule workflow epic (bd-2vh3). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
78 lines
3.1 KiB
Go
78 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
)
|
|
|
|
// Molecule commands - work templates for agent workflows
|
|
//
|
|
// Terminology:
|
|
// - Proto: Uninstantiated template (easter egg: 'protomolecule' alias)
|
|
// - Molecule: A spawned instance of a proto
|
|
// - Spawn: Instantiate a proto, creating real issues from the template
|
|
// - Bond: Polymorphic combine operation (proto+proto, proto+mol, mol+mol)
|
|
// - Distill: Extract ad-hoc epic → reusable proto
|
|
// - Compound: Result of bonding
|
|
//
|
|
// Usage:
|
|
// bd mol catalog # List available protos
|
|
// bd mol show <id> # Show proto/molecule structure
|
|
// bd mol spawn <id> --var key=value # Instantiate proto → molecule
|
|
|
|
// MoleculeLabel is the label used to identify molecules (templates)
|
|
// Molecules use the same label as templates - they ARE templates with workflow semantics
|
|
const MoleculeLabel = BeadsTemplateLabel
|
|
|
|
// MoleculeSubgraph is an alias for TemplateSubgraph
|
|
// Molecules and templates share the same subgraph structure
|
|
type MoleculeSubgraph = TemplateSubgraph
|
|
|
|
var molCmd = &cobra.Command{
|
|
Use: "mol",
|
|
Aliases: []string{"protomolecule"}, // Easter egg for The Expanse fans
|
|
Short: "Molecule commands (work templates)",
|
|
Long: `Manage molecules - work templates for agent workflows.
|
|
|
|
Protos are template epics with the "template" label. They define a DAG of work
|
|
that can be spawned to create real issues (molecules).
|
|
|
|
The molecule metaphor:
|
|
- A proto is an uninstantiated template (reusable work pattern)
|
|
- Spawning creates a molecule (real issues) from the proto
|
|
- Variables ({{key}}) are substituted during spawning
|
|
- Bonding combines protos or molecules into compounds
|
|
- Distilling extracts a proto from an ad-hoc epic
|
|
|
|
Commands:
|
|
catalog List available protos
|
|
show Show proto/molecule structure and variables
|
|
spawn Instantiate a proto → molecule
|
|
bond Polymorphic combine: proto+proto, proto+mol, mol+mol
|
|
run Spawn + assign + pin for durable execution
|
|
distill Extract proto from ad-hoc epic (reverse of spawn)`,
|
|
}
|
|
|
|
// =============================================================================
|
|
// Molecule Helper Functions
|
|
// =============================================================================
|
|
|
|
// spawnMolecule creates new issues from the proto with variable substitution.
|
|
// This instantiates a proto (template) into a molecule (real issues).
|
|
// Wraps cloneSubgraph from template.go and returns InstantiateResult.
|
|
// If ephemeral is true, spawned issues are marked for bulk deletion when closed.
|
|
func spawnMolecule(ctx context.Context, s storage.Storage, subgraph *MoleculeSubgraph, vars map[string]string, assignee string, actorName string, ephemeral bool) (*InstantiateResult, error) {
|
|
return cloneSubgraph(ctx, s, subgraph, vars, assignee, actorName, ephemeral)
|
|
}
|
|
|
|
// printMoleculeTree prints the molecule structure as a tree
|
|
func printMoleculeTree(subgraph *MoleculeSubgraph, parentID string, depth int, isRoot bool) {
|
|
printTemplateTree(subgraph, parentID, depth, isRoot)
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(molCmd)
|
|
}
|