@axiomantic/garden 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Axiomantic / Agora Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,149 @@
1
+ <div align="center">
2
+
3
+ # Garden
4
+
5
+ **Multi-Agent Swarm Orchestration, Empirical Dialectics & Ceremonies on top of Rhizo & Vine**
6
+
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
8
+ [![tmux](https://img.shields.io/badge/tmux-3.0%2B-green.svg)](https://github.com/tmux/tmux)
9
+ [![Rhizo](https://img.shields.io/badge/Rhizo-0.1.3%2B-red.svg)](https://github.com/axiomantic/rhizo)
10
+ [![Vine](https://img.shields.io/badge/Vine-0.1.0%2B-purple.svg)](https://github.com/axiomantic/vine)
11
+ [![Platform](https://img.shields.io/badge/Platform-macOS%20%7C%20Linux-blue.svg)](README.md)
12
+
13
+ *Where `rhizo` provides inter-agent transport and `vine` provides workspace virtualization, `garden` provides the institutional intellect, empirical deliberation, and synchronized swarm execution.*
14
+
15
+ </div>
16
+
17
+ ---
18
+
19
+ ## What is Garden?
20
+
21
+ **Garden** is an agentic engineering framework and skill library for orchestrating heterogeneous teams of AI coding assistants (Claude Code, OpenCode, Antigravity, Cursor, Codex).
22
+
23
+ Instead of treating AI agents as isolated single-turn chatbots, Garden provisions **coordinated worker swarms** inside multiplexed `tmux` sessions, balances specialized personas with designated foundation models and harnesses, drives **empirically grounded dialectical deliberation**, schedules distributed fencing mutexes, and integrates code through isolated APFS Copy-on-Write strands verified by Vine's Two-Key Gate.
24
+
25
+ ```mermaid
26
+ flowchart TD
27
+ subgraph Layer3["Layer 3: Garden (Methodology, Ceremonies & Swarms)"]
28
+ direction TB
29
+ GardenSkill["garden (Master Entrypoint)"]
30
+ P1["choose-personas (Team & Models)"]
31
+ P2["launch-workers (tmux & Terminal Viewer)"]
32
+ P3["dialectical-pump (Research ➔ Design ➔ Audit)"]
33
+ P4["plan-implementation (Locks & Strands)"]
34
+ P5["orchestrate-swarm (Dispatch & Weave)"]
35
+ GardenSkill --> P1 --> P2 --> P3 --> P4 --> P5
36
+ end
37
+
38
+ subgraph Layer2["Layer 2: Vine (Workstream Integrator)"]
39
+ Strands["APFS CoW Strands (Sub-second isolated workspaces)"]
40
+ TwoKey["Two-Key Gate (Mechanical merge-tree + semantic test suite)"]
41
+ Weave["Trunk Weaving (Fast-forward verified branches)"]
42
+ end
43
+
44
+ subgraph Layer1["Layer 1: Rhizo (Inter-Agent Transport)"]
45
+ Bus["Redis Message Bus (O2O, Multicast, RPC)"]
46
+ Locks["Distributed Mutexes & Monotonic Fencing Tokens"]
47
+ Queues["Worker Queues with Leases & Dead-Letter Escalation"]
48
+ end
49
+
50
+ Layer3 --> Layer2
51
+ Layer3 --> Layer1
52
+ Layer2 -.-> Layer1
53
+ ```
54
+
55
+ ---
56
+
57
+ ## The 5 Core Skills (+ Master Entrypoint)
58
+
59
+ Garden is organized into a clean, batteries-included catalog of self-explanatory skills:
60
+
61
+ | Skill | Role | Description |
62
+ | :--- | :--- | :--- |
63
+ | **[`garden`](skills/garden/SKILL.md)** | **Master Entrypoint** | The sovereign ceremony director. Guides orchestrator and operator step-by-step across all phases from initial task to woven code. |
64
+ | **[`choose-personas`](skills/choose-personas/SKILL.md)** | **Team Calibration** | Formulates a balanced triad of specialized personas (e.g. Architect, Auditor, DevEx Lead) with explicitly recommended **coding harnesses** and **model tiers**, confirmed interactively with the operator. |
65
+ | **[`launch-workers`](skills/launch-workers/SKILL.md)** | **Fleet Provisioning** | Boots a structured `tmux` session with named worker panes, injects environment variables, registers identities via `rhizo open`, arms listeners, and pops open your preferred OS terminal viewer (Ghostty / Terminal.app). |
66
+ | **[`dialectical-pump`](skills/dialectical-pump/SKILL.md)** | **Empirical Deliberation** | Drives multi-perspective thesis/antithesis/synthesis debates. Strictly prohibits theatrical roleplay: every turn requires tool execution (reading files, running tests, checking ASTs). Produces `understanding.md`, `design.md`, and `audit_report.md`. |
67
+ | **[`plan-implementation`](skills/plan-implementation/SKILL.md)** | **Master Scheduling** | Authors `implementation_plan.md` defining task assignment matrices, `rhizo` distributed fencing locks, `vine` strand workflows, dynamic markdown checkboxes, harness To-Do integration, and emergent design addenda. |
68
+ | **[`orchestrate-swarm`](skills/orchestrate-swarm/SKILL.md)** | **Main-Chat Governor** | Governs execution from the primary chat session: dispatches tasks over Redis, tracks heartbeats, ratifies emergent design addenda, verifies Two-Key gate passes, and triggers `vine weave`. |
69
+
70
+ ---
71
+
72
+ ## System Prerequisites
73
+
74
+ 1. **`tmux`** (3.0+):
75
+ ```bash
76
+ brew install tmux
77
+ ```
78
+ 2. **`rhizo`** (Coordination Engine):
79
+ ```bash
80
+ npm install -g @axiomantic/rhizo
81
+ ```
82
+ 3. **`vine`** (Workspace Virtualization Engine):
83
+ ```bash
84
+ npm install -g @axiomantic/vine
85
+ ```
86
+ 4. **Redis or Valkey** (local or remote):
87
+ ```bash
88
+ brew install redis && brew services start redis
89
+ ```
90
+
91
+ ---
92
+
93
+ ## 30-Second Quickstart
94
+
95
+ ### 1. Launch Garden on Any Task
96
+ In your primary AI coding assistant (Antigravity, Claude Code, OpenCode):
97
+
98
+ ```text
99
+ User: "garden: Implement high-throughput batch claim leases with Redis pipeline support"
100
+ ```
101
+
102
+ ### 2. Interactive Team Calibration (`choose-personas`)
103
+ Garden inspects your repository and suggests a balanced persona roster with recommended harnesses and models:
104
+ - **Marcus Vance** (Staff Systems Architect) $\to$ **Antigravity** | **Gemini 3.8 Flash**
105
+ - **Caleb Thorne** (Refactoring & Code Quality Purist) $\to$ **Claude Code CLI** | **Claude 3 Opus**
106
+ - **Elena Rostova** (DevEx & API Lead) $\to$ **Antigravity** | **Gemini 3.8 Flash**
107
+
108
+ Confirm or adjust the roster with a single click.
109
+
110
+ ### 3. Automatic Fleet Provisioning (`launch-workers`)
111
+ Garden executes [`scripts/launch_tmux_swarm.sh`](scripts/launch_tmux_swarm.sh):
112
+ - Creates tmux session `garden-<project>` with dedicated panes for each worker.
113
+ - Sets environment variables and registers each agent via `rhizo open`.
114
+ - Arms background listeners (`rhizo listen`).
115
+ - Automatically pops open a visible **Ghostty** or **Terminal.app** window on macOS so you can watch the swarm running live.
116
+
117
+ ### 4. The Dialectical Pump (`dialectical-pump`)
118
+ The personas deliberate across three empirical stages:
119
+ 1. **Research**: Workers read code and run tests $\to$ synthesize `understanding.md` $\to$ verify against automated **Fact-Check Gate**.
120
+ 2. **Architecture**: Triad debates trade-offs $\to$ produces ratified `design.md`.
121
+ 3. **Audit**: Auditor generates `audit_report.md` $\to$ triad resolves every finding before coding begins.
122
+
123
+ ### 5. Ceremonial Planning (`plan-implementation`)
124
+ Garden authors `implementation_plan.md`:
125
+ - Schedules distributed fencing locks (`rhizo lock file:<path> --fencing`).
126
+ - Assigns tasks and defines APFS CoW strands (`vine new <task_id> --worktree`).
127
+ - Sets up dynamic progress checkboxes and harness To-Do tracking.
128
+
129
+ ### 6. Live Orchestration & Trunk Weaving (`orchestrate-swarm`)
130
+ The main chat orchestrator dispatches work over Redis. Workers code in isolated strands, run unit tests, and verify the Two-Key Gate (`vine gate`). When passed, the orchestrator executes `vine weave` to fast-forward verified code into `main` with zero merge conflicts!
131
+
132
+ ---
133
+
134
+ ## Core Invariants
135
+
136
+ 1. **The Supreme Orchestrator Invariant**:
137
+ The main chat session coordinates, reviews, and integrates. Intensive multi-file edits are executed by the worker fleet in isolated strands.
138
+ 2. **Empirical Grounding Protocol (Zero Theatrical Dialogue)**:
139
+ Dialectical deliberations must cite hard evidence from real tool calls (line citations, test outputs, compiler errors). Theatrical roleplay is strictly banned.
140
+ 3. **Two-Key Gate Verification**:
141
+ No code is merged into the trunk without passing both Key 1 (in-memory `git merge-tree` mechanical check) and Key 2 (live semantic compiler and test suite run).
142
+ 4. **Zero Dirty Commits**:
143
+ All agent identity files, session state, and temporary lockfiles are strictly ignored in `.gitignore`.
144
+
145
+ ---
146
+
147
+ ## License
148
+
149
+ MIT © Axiomantic / Garden Contributors
package/SKILL.md ADDED
@@ -0,0 +1,133 @@
1
+ ---
2
+ name: garden
3
+ description: "Master entrypoint and end-to-end ceremony director for multi-agent swarms operating on top of Rhizo (transport) and Vine (workspace integrator). Guides the user and orchestrator session through the full lifecycle: persona selection with harness/model pairing, tmux worker fleet provisioning with live terminal viewer, 3-stage empirical dialectical pump (research, design, audit), master implementation planning with locking/strand schedules, and live swarm execution with Two-Key gate verification and fast-forward trunk weaving. Triggers: 'garden', 'run garden', 'swarm this project', 'orchestrate with garden', 'start garden swarm', 'run the full garden ceremony'."
4
+ ---
5
+
6
+ # Garden: Multi-Agent Swarm Ceremony & Orchestration Engine
7
+
8
+ > **The Sovereign Orchestration Layer for Autonomous AI Swarms**
9
+ > *Where `rhizo` is the transport nervous system and `vine` is the workspace integrator, `garden` is the institutional intellect, deliberation crucible, and master ceremony conductor.*
10
+
11
+ ---
12
+
13
+ ## 1. Architectural Architecture & Layering
14
+
15
+ Garden coordinates teams of heterogeneous AI coding assistants across terminals and machines:
16
+
17
+ ```mermaid
18
+ flowchart TD
19
+ subgraph Garden["Garden Layer (Methodology & Ceremonies)"]
20
+ Phase1["Phase 1: choose-personas (Team Selection & Models)"]
21
+ Phase2["Phase 2: launch-workers (tmux & Terminal Viewer)"]
22
+ Phase3["Phase 3: dialectical-pump (Research ➔ Design ➔ Audit)"]
23
+ Phase4["Phase 4: plan-implementation (Locking & Strands)"]
24
+ Phase5["Phase 5: orchestrate-swarm (Dispatch & Vine Weaving)"]
25
+ end
26
+
27
+ subgraph Infrastructure["Coordination Infrastructure"]
28
+ Rhizo["Rhizo (Redis Bus, Fencing Mutexes, Work Queues)"]
29
+ Vine["Vine (APFS CoW Strands, Two-Key Gate, Weaving)"]
30
+ end
31
+
32
+ Phase1 --> Phase2 --> Phase3 --> Phase4 --> Phase5
33
+ Phase2 -.-> Rhizo
34
+ Phase3 -.-> Rhizo
35
+ Phase4 -.-> Rhizo & Vine
36
+ Phase5 -.-> Rhizo & Vine
37
+ ```
38
+
39
+ ---
40
+
41
+ ## 2. The 5-Phase End-to-End Ceremony
42
+
43
+ When invoked, the Orchestrator (the primary conversation chat) executes these five phases sequentially. Never skip phases or invert the order.
44
+
45
+ ```mermaid
46
+ sequenceDiagram
47
+ autonumber
48
+ actor User as Human Operator
49
+ participant Orch as Main Chat (Orchestrator)
50
+ participant Swarm as Tmux Worker Swarm
51
+ participant Bus as Rhizo (Redis)
52
+ participant Gate as Vine (Strands & Gate)
53
+
54
+ User->>Orch: "garden: implement feature X"
55
+ Note over Orch: Phase 1: Team Calibration
56
+ Orch->>User: Suggests Persona Roster (Roles, Harnesses, Models) via ask_question
57
+ User-->>Orch: Ratifies / Adjusts Roster
58
+
59
+ Note over Orch: Phase 2: Fleet Provisioning
60
+ Orch->>Swarm: Executes launch-workers (tmux panes + Ghostty/Terminal viewer)
61
+ Swarm->>Bus: rhizo open + rhizo listen (Workers armed)
62
+
63
+ Note over Orch: Phase 3: Empirical Dialectic
64
+ Orch->>Swarm: Dispatches dialectical-pump
65
+ Note over Swarm: 1. Research ➔ understanding.md ➔ Fact-Check Gate<br/>2. Architecture ➔ design.md<br/>3. Adversarial Audit ➔ audit_report.md ➔ Remediation
66
+ Swarm-->>Orch: Ratified design.md & cleared audit report
67
+
68
+ Note over Orch: Phase 4: Master Planning
69
+ Orch->>Orch: Authors implementation_plan.md (Locks, Strands, To-Do list)
70
+
71
+ Note over Orch: Phase 5: Swarm Execution & Weaving
72
+ loop For Each Plan Task
73
+ Orch->>Bus: Dispatch task (rhizo send / enqueue)
74
+ Bus->>Swarm: Worker claims lease (rhizo claim)
75
+ Swarm->>Gate: Creates strand (vine new)
76
+ Swarm->>Swarm: Implements code + verifies tests
77
+ Swarm->>Gate: Verifies Two-Key Gate (vine gate)
78
+ Swarm->>Orch: Reports gate pass (rhizo reply)
79
+ Orch->>Gate: Fast-forward merge (vine weave)
80
+ Orch->>Orch: Updates plan checkbox & Harness To-Do
81
+ end
82
+ Orch->>User: Mission Accomplished Summary
83
+ ```
84
+
85
+ ---
86
+
87
+ ## 3. Phase Transition Protocols & Quality Gates
88
+
89
+ ### Gate 1 $\to$ 2: Persona Ratification Gate
90
+ - **Condition**: Operator has confirmed the roster via `ask_question`.
91
+ - **Artifact**: `garden-swarm.json` persisted in the project directory.
92
+ - **Action**: Call `launch-workers`.
93
+
94
+ ### Gate 2 $\to$ 3: Cluster Readiness Gate
95
+ - **Condition**: All worker panes booted, heartbeats active in Redis.
96
+ - **Verification**: `rhizo who --json` confirms 100% of agents online and tagged.
97
+ - **Action**: Call `dialectical-pump`.
98
+
99
+ ### Gate 3 $\to$ 4: Design Audit Clearance Gate
100
+ - **Condition**:
101
+ 1. `understanding.md` passed the Fact-Check Gate (zero ungrounded claims).
102
+ 2. `design.md` authored and debated by the triadic pump.
103
+ 3. `audit_report.md` contains 0 open `CRIT` or `BLOCKER` defects.
104
+ - **Action**: Call `plan-implementation`.
105
+
106
+ ### Gate 4 $\to$ 5: Plan Alignment Gate
107
+ - **Condition**: `implementation_plan.md` complete with task matrix, locking schedule, vine strand lifecycles, and emergent design addendum protocol.
108
+ - **Action**: Call `orchestrate-swarm`.
109
+
110
+ ---
111
+
112
+ ## 4. Sub-Skill Reference Map
113
+
114
+ When executing Garden, invoke the sub-skills at their designated phases:
115
+
116
+ | Phase | Skill Name | Description | Primary Artifacts |
117
+ | :--- | :--- | :--- | :--- |
118
+ | **Phase 1** | [`choose-personas`](../choose-personas/SKILL.md) | Analyzes task, formulates 3 balanced personas with suggested **coding harness** and **model**, and confirms with operator. | `garden-swarm.json` |
119
+ | **Phase 2** | [`launch-workers`](../launch-workers/SKILL.md) | Provisions tmux session with worker panes, registers `rhizo open`, arms listeners, and launches OS terminal viewer (Ghostty / Terminal.app). | Live tmux session, visible terminal |
120
+ | **Phase 3** | [`dialectical-pump`](../dialectical-pump/SKILL.md) | Drives empirical multi-persona debate grounded in tool calls (file reading, test running, AST inspecting). Produces research, design, and audit docs. | `understanding.md`, `design.md`, `audit_report.md` |
121
+ | **Phase 4** | [`plan-implementation`](../plan-implementation/SKILL.md) | Authors master implementation plan detailing task assignments, `rhizo` locks (`--fencing`), `vine` strands, dynamic checkboxes, and To-Do tracking. | `implementation_plan.md` |
122
+ | **Phase 5** | [`orchestrate-swarm`](../orchestrate-swarm/SKILL.md) | Main-chat governor: dispatches tasks over Redis, tracks heartbeats, approves emergent design addenda, and executes `vine weave` upon Two-Key gate pass. | Completed code, woven trunk, git commits |
123
+
124
+ ---
125
+
126
+ ## 5. Invariants & Rules of Engagement
127
+
128
+ 1. **The Supreme Orchestrator Invariant**:
129
+ The primary conversation session acts as the Supreme Orchestrator. It coordinates, plans, reviews, and merges. It delegates intensive multi-file edits to the worker fleet.
130
+ 2. **Zero Theatrical Dialogue**:
131
+ In dialectical deliberations, every assertion must be backed by empirical evidence (line citations, test execution outputs, compiler errors).
132
+ 3. **No Unmanaged Daemons / Zero Dirty Commits**:
133
+ All coordination metadata (`.rhizo.*`, `.vine.*`, `*.lock`) must remain in `.gitignore`. Workers must adhere to the Two-Key Gate before any code touches the canonical trunk.
package/bin/garden ADDED
Binary file
package/bin/run.js ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const { spawnSync } = require('child_process');
5
+
6
+ function findBinary() {
7
+ const ext = process.platform === 'win32' ? '.exe' : '';
8
+ const arch = process.arch;
9
+ const platform = process.platform;
10
+
11
+ for (const name of ['garden']) {
12
+ const directBin = path.join(__dirname, `${name}${ext}`);
13
+ if (fs.existsSync(directBin)) return directBin;
14
+
15
+ const platformBin = path.join(__dirname, `${name}-${platform}-${arch}${ext}`);
16
+ if (fs.existsSync(platformBin)) return platformBin;
17
+
18
+ const vendorBin = path.join(__dirname, '..', 'vendor', 'bin', `${name}${ext}`);
19
+ if (fs.existsSync(vendorBin)) return vendorBin;
20
+ }
21
+
22
+ return null;
23
+ }
24
+
25
+ const binPath = findBinary();
26
+ if (!binPath) {
27
+ console.error(`Error: @axiomantic/garden native binary not found for ${process.platform}-${process.arch}.`);
28
+ console.error(`Please visit https://github.com/axiomantic/garden/releases to download.`);
29
+ process.exit(1);
30
+ }
31
+
32
+ try {
33
+ fs.chmodSync(binPath, 0o755);
34
+ } catch (_) {}
35
+
36
+ const res = spawnSync(binPath, process.argv.slice(2), {
37
+ stdio: 'inherit',
38
+ env: process.env
39
+ });
40
+
41
+ if (res.error) {
42
+ console.error(`Failed to execute binary: ${res.error.message}`);
43
+ process.exit(1);
44
+ }
45
+
46
+ process.exit(res.status !== null ? res.status : (res.signal ? 1 : 0));
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@axiomantic/garden",
3
+ "version": "0.1.0",
4
+ "description": "Multi-Agent Swarm Orchestration, Empirical Dialectics & Ceremonies on top of Rhizo & Vine",
5
+ "main": "bin/run.js",
6
+ "bin": {
7
+ "garden": "bin/run.js"
8
+ },
9
+ "skills": "./skills",
10
+ "files": [
11
+ "bin/",
12
+ "scripts/",
13
+ "skills/",
14
+ "SKILL.md",
15
+ "README.md",
16
+ "LICENSE"
17
+ ],
18
+ "scripts": {
19
+ "postinstall": "node scripts/postinstall.js"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/axiomantic/garden.git"
27
+ },
28
+ "keywords": [
29
+ "multi-agent",
30
+ "ai-agents",
31
+ "orchestration",
32
+ "tmux",
33
+ "dialectics",
34
+ "rhizo",
35
+ "vine",
36
+ "garden",
37
+ "swarm"
38
+ ],
39
+ "author": "Axiomantic",
40
+ "license": "MIT",
41
+ "bugs": {
42
+ "url": "https://github.com/axiomantic/garden/issues"
43
+ },
44
+ "homepage": "https://github.com/axiomantic/garden#readme"
45
+ }
@@ -0,0 +1,233 @@
1
+ #!/usr/bin/env bash
2
+ # scripts/launch_tmux_swarm.sh
3
+ # Provisions a dedicated tmux session for a Garden worker swarm, registers identities
4
+ # on the Rhizo Redis bus, arms listeners, and opens a visible terminal viewer (Ghostty/Terminal.app).
5
+
6
+ set -euo pipefail
7
+
8
+ usage() {
9
+ cat <<EOF
10
+ Usage: $(basename "$0") [options]
11
+
12
+ Options:
13
+ --session-name <name> tmux session name (default: garden-<dirname>)
14
+ --project-dir <path> Target project working directory (default: current directory)
15
+ --swarm-file <path> Path to garden-swarm.json manifest
16
+ --terminal-app <app> Terminal viewer app: Ghostty | Terminal | iTerm | none (default: auto)
17
+ --force Kill existing tmux session if running
18
+ --help Show this help message
19
+ EOF
20
+ exit 0
21
+ }
22
+
23
+ SESSION_NAME=""
24
+ PROJECT_DIR="$(pwd)"
25
+ SWARM_FILE=""
26
+ TERMINAL_APP="auto"
27
+ FORCE=0
28
+
29
+ while [[ $# -gt 0 ]]; do
30
+ case "$1" in
31
+ --session-name)
32
+ SESSION_NAME="$2"
33
+ shift 2
34
+ ;;
35
+ --project-dir)
36
+ PROJECT_DIR="$(cd "$2" && pwd)"
37
+ shift 2
38
+ ;;
39
+ --swarm-file)
40
+ SWARM_FILE="$2"
41
+ shift 2
42
+ ;;
43
+ --terminal-app)
44
+ TERMINAL_APP="$2"
45
+ shift 2
46
+ ;;
47
+ --force)
48
+ FORCE=1
49
+ shift
50
+ ;;
51
+ --help|-h)
52
+ usage
53
+ ;;
54
+ *)
55
+ echo "Unknown option: $1" >&2
56
+ usage
57
+ ;;
58
+ esac
59
+ done
60
+
61
+ # Prerequisite Checks
62
+ if ! command -v tmux >/dev/null 2>&1; then
63
+ echo "Error: tmux is required but not found in PATH." >&2
64
+ echo "Install via Homebrew: brew install tmux" >&2
65
+ exit 1
66
+ fi
67
+
68
+ if ! command -v rhizo >/dev/null 2>&1; then
69
+ echo "Error: rhizo is required but not found in PATH." >&2
70
+ echo "Install via npm: npm install -g @axiomantic/rhizo" >&2
71
+ exit 1
72
+ fi
73
+
74
+ RHIZO_BIN="rhizo"
75
+
76
+ if [[ -z "$SESSION_NAME" ]]; then
77
+ PROJECT_BASE="$(basename "$PROJECT_DIR" | tr '[:upper:]' '[:lower:]' | tr -c 'a-z0-9_-' '_')"
78
+ SESSION_NAME="garden-${PROJECT_BASE}"
79
+ fi
80
+
81
+ if tmux has-session -t "$SESSION_NAME" 2>/dev/null; then
82
+ if [[ $FORCE -eq 1 ]]; then
83
+ echo "[garden] Killing existing tmux session: $SESSION_NAME"
84
+ tmux kill-session -t "$SESSION_NAME"
85
+ else
86
+ echo "Error: tmux session '$SESSION_NAME' already exists. Use --force to recreate." >&2
87
+ exit 1
88
+ fi
89
+ fi
90
+
91
+ # Parse swarm workers from JSON manifest or default trio
92
+ declare -a WORKER_NAMES=()
93
+ declare -a WORKER_TAGS=()
94
+ declare -a WORKER_COMMANDS=()
95
+
96
+ if [[ -z "$SWARM_FILE" && -f "$PROJECT_DIR/garden-swarm.json" ]]; then
97
+ SWARM_FILE="$PROJECT_DIR/garden-swarm.json"
98
+ fi
99
+
100
+ if [[ -n "$SWARM_FILE" && -f "$SWARM_FILE" ]]; then
101
+ if ! command -v jq >/dev/null 2>&1 && ! command -v python3 >/dev/null 2>&1; then
102
+ echo "Error: python3 or jq is required to parse $SWARM_FILE" >&2
103
+ exit 1
104
+ fi
105
+
106
+ # Parse JSON using python3 into tab-separated lines: name <tab> tags <tab> command
107
+ PARSED_LINES=$(python3 -c "
108
+ import json, sys
109
+ with open('$SWARM_FILE', 'r') as f:
110
+ data = json.load(f)
111
+ workers = data.get('workers', [])
112
+ for w in workers:
113
+ name = w.get('name', 'worker')
114
+ tags = ','.join(w.get('tags', []))
115
+ cmd = w.get('startup_command', '')
116
+ print(f'{name}\t{tags}\t{cmd}')
117
+ ")
118
+
119
+ while IFS=$'\t' read -r wname wtags wcmd; do
120
+ [[ -z "$wname" ]] && continue
121
+ WORKER_NAMES+=("$wname")
122
+ WORKER_TAGS+=("$wtags")
123
+ WORKER_COMMANDS+=("$wcmd")
124
+ done <<< "$PARSED_LINES"
125
+ fi
126
+
127
+ # Fallback default trio if no manifest was provided
128
+ if [[ ${#WORKER_NAMES[@]} -eq 0 ]]; then
129
+ WORKER_NAMES=("architect" "auditor" "implementer")
130
+ WORKER_TAGS=("systems,architecture" "qa,audit,review" "dev,devex,build")
131
+ WORKER_COMMANDS=("" "" "")
132
+ fi
133
+
134
+ echo "[garden] Provisioning tmux session: $SESSION_NAME for project: $PROJECT_DIR"
135
+
136
+ # 1. Create first worker window (index 0)
137
+ FIRST_NAME="${WORKER_NAMES[0]}"
138
+ FIRST_TAGS="${WORKER_TAGS[0]}"
139
+ FIRST_CMD="${WORKER_COMMANDS[0]}"
140
+
141
+ tmux new-session -d -s "$SESSION_NAME" -n "$FIRST_NAME" -c "$PROJECT_DIR"
142
+ tmux send-keys -t "$SESSION_NAME:0" "cd $(printf %q "$PROJECT_DIR")" C-m
143
+ tmux send-keys -t "$SESSION_NAME:0" "export RHIZO_AGENT_NAME=$(printf %q "$FIRST_NAME")" C-m
144
+ tmux send-keys -t "$SESSION_NAME:0" "$RHIZO_BIN open $(printf %q "$FIRST_NAME") $(printf %q "$FIRST_TAGS")" C-m
145
+
146
+ if [[ -n "$FIRST_CMD" ]]; then
147
+ tmux send-keys -t "$SESSION_NAME:0" "$FIRST_CMD" C-m
148
+ else
149
+ tmux send-keys -t "$SESSION_NAME:0" "$RHIZO_BIN listen $(printf %q "$FIRST_NAME")" C-m
150
+ fi
151
+
152
+ # 2. Create subsequent worker windows
153
+ for (( i=1; i<${#WORKER_NAMES[@]}; i++ )); do
154
+ WNAME="${WORKER_NAMES[$i]}"
155
+ WTAGS="${WORKER_TAGS[$i]}"
156
+ WCMD="${WORKER_COMMANDS[$i]}"
157
+
158
+ tmux new-window -t "$SESSION_NAME" -n "$WNAME" -c "$PROJECT_DIR"
159
+ tmux send-keys -t "$SESSION_NAME:$i" "cd $(printf %q "$PROJECT_DIR")" C-m
160
+ tmux send-keys -t "$SESSION_NAME:$i" "export RHIZO_AGENT_NAME=$(printf %q "$WNAME")" C-m
161
+ tmux send-keys -t "$SESSION_NAME:$i" "$RHIZO_BIN open $(printf %q "$WNAME") $(printf %q "$WTAGS")" C-m
162
+
163
+ if [[ -n "$WCMD" ]]; then
164
+ tmux send-keys -t "$SESSION_NAME:$i" "$WCMD" C-m
165
+ else
166
+ tmux send-keys -t "$SESSION_NAME:$i" "$RHIZO_BIN listen $(printf %q "$WNAME")" C-m
167
+ fi
168
+ done
169
+
170
+ # Select window 0 initially
171
+ tmux select-window -t "$SESSION_NAME:0"
172
+
173
+ echo "[garden] Spawned ${#WORKER_NAMES[@]} worker windows in tmux session '$SESSION_NAME'."
174
+
175
+ # 3. Launch OS-level Terminal Viewer
176
+ if [[ "$TERMINAL_APP" == "auto" ]]; then
177
+ if [[ -d "/Applications/Ghostty.app" ]]; then
178
+ TERMINAL_APP="Ghostty"
179
+ elif [[ -d "/Applications/iTerm.app" ]]; then
180
+ TERMINAL_APP="iTerm"
181
+ elif [[ "$(uname -s)" == "Darwin" ]]; then
182
+ TERMINAL_APP="Terminal"
183
+ else
184
+ TERMINAL_APP="none"
185
+ fi
186
+ fi
187
+
188
+ if [[ "$TERMINAL_APP" != "none" && "$(uname -s)" == "Darwin" ]]; then
189
+ echo "[garden] Launching viewer in $TERMINAL_APP..."
190
+ case "$TERMINAL_APP" in
191
+ Ghostty|ghostty)
192
+ # Launch Ghostty with attach command
193
+ open -a Ghostty --args -e tmux attach-session -t "$SESSION_NAME" || true
194
+ ;;
195
+ iTerm|iterm)
196
+ osascript -e "
197
+ tell application \"iTerm\"
198
+ activate
199
+ set newWindow to (create window with default profile)
200
+ tell current session of newWindow
201
+ write text \"tmux attach-session -t $SESSION_NAME\"
202
+ end tell
203
+ end tell
204
+ " >/dev/null 2>&1 || true
205
+ ;;
206
+ Terminal|terminal)
207
+ osascript -e "
208
+ tell application \"Terminal\"
209
+ activate
210
+ do script \"tmux attach-session -t $SESSION_NAME\"
211
+ end tell
212
+ " >/dev/null 2>&1 || true
213
+ ;;
214
+ *)
215
+ echo "[garden] Unknown terminal app '$TERMINAL_APP'; skipping auto-launch." >&2
216
+ ;;
217
+ esac
218
+ fi
219
+
220
+ # Output JSON summary for caller agents / orchestrator
221
+ cat <<EOF
222
+ {
223
+ "status": "ready",
224
+ "session_name": "$SESSION_NAME",
225
+ "project_dir": "$PROJECT_DIR",
226
+ "terminal_app": "$TERMINAL_APP",
227
+ "workers": [
228
+ $(for (( i=0; i<${#WORKER_NAMES[@]}; i++ )); do
229
+ echo " {\"window\": $i, \"name\": \"${WORKER_NAMES[$i]}\", \"tags\": \"${WORKER_TAGS[$i]}\"}$(if [[ $i -lt $((${#WORKER_NAMES[@]} - 1)) ]]; then echo ","; fi)"
230
+ done)
231
+ ]
232
+ }
233
+ EOF