pi-branch-out 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 Warren Winter
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,148 @@
1
+ # branch-out for Pi (`pi-branch-out`)
2
+
3
+ Fork the current Pi session into a split terminal pane or new tab with rotating layout policies, and with optional model and message queuing. Routing, split geometry, and focus behavior are all config-driven.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pi install npm:pi-branch-out
9
+ ```
10
+
11
+ From the dot314 git bundle (filtered install):
12
+
13
+ ```json
14
+ {
15
+ "packages": [
16
+ {
17
+ "source": "git:github.com/w-winter/dot314",
18
+ "extensions": ["extensions/branch-out/index.ts"],
19
+ "skills": [],
20
+ "themes": [],
21
+ "prompts": []
22
+ }
23
+ ]
24
+ }
25
+ ```
26
+
27
+ After installing, copy `extensions/branch-out/config.json.example` to `extensions/branch-out/config.json` and adjust to taste.
28
+
29
+ ## Command
30
+
31
+ ```text
32
+ /branch [--model <query>] [message]
33
+ ```
34
+
35
+ Both arguments are optional and independent.
36
+
37
+ - **`--model <query>`** — target model for the child session. Accepts a fully qualified `provider/model-id` or a fuzzy query scoped to the current provider. If the query does not resolve safely the child keeps the parent's model.
38
+ - **`message`** — prefilled text in the child session's editor with a 10-second auto-submit countdown. Typing anything or pressing `Esc` cancels the countdown; `Enter` sends immediately.
39
+
40
+ ## Config
41
+
42
+ Config lives in `extensions/branch-out/config.json` next to the extension.
43
+
44
+ ```json
45
+ {
46
+ "launchMode": "split",
47
+ "splitDirection": "right",
48
+ "preserveFocus": true
49
+ }
50
+ ```
51
+
52
+ ### `launchMode`
53
+
54
+ | Value | Behavior |
55
+ |-------|----------|
56
+ | `"split"` | Open in a new split pane inside the current window (default) |
57
+ | `"tab"` | Open in a new tab / surface |
58
+
59
+ ### `splitDirection`
60
+
61
+ Accepts a single value or a **comma-separated fallback list**. The first entry supported by the active backend is used; if none match, `right` is the final default.
62
+
63
+ ```json
64
+ "splitDirection": "counterclockwise,right"
65
+ ```
66
+
67
+ This is useful when `splitDirection` is a rotating policy (unsupported by iTerm2). The fallback `right` kicks in automatically on that backend.
68
+
69
+ #### Static directions
70
+
71
+ | Value | Effect |
72
+ |-------|--------|
73
+ | `"right"` | Split to the right of the current pane |
74
+ | `"down"` | Split below the current pane |
75
+ | `"left"` | Split to the left of the current pane |
76
+ | `"up"` | Split above the current pane |
77
+
78
+ #### Rotating layout policies (`cmux` and `tmux` only)
79
+
80
+ `clockwise` and `counterclockwise` are stateful layout policies. On the first `/branch` call the current pane is split in the policy's initial direction. On each subsequent call the policy picks the next queued managed leaf and splits it in that leaf's assigned direction, building a balanced recursive tree rather than a linear stack.
81
+
82
+ | Value | Pattern |
83
+ |-------|--------|
84
+ | `"clockwise"` | First split right → children split up/down → grandchildren split right/left → … |
85
+ | `"counterclockwise"` | First split right → children split down/up → grandchildren split left/right → … |
86
+
87
+ State is persisted per backend and workspace key in `/tmp/pi-branch-out-layout-state.json`. Stale entries are pruned against live pane/surface lists on each call. To reset the policy entirely:
88
+
89
+ ```bash
90
+ rm /tmp/pi-branch-out-layout-state.json
91
+ ```
92
+
93
+ ### `preserveFocus`
94
+
95
+ | Value | Behavior |
96
+ |-------|----------|
97
+ | `true` | Focus stays in the pane that ran `/branch` (default) |
98
+ | `false` | Focus moves to the newly created pane |
99
+
100
+ ## Terminal backend routing
101
+
102
+ Routing is automatic and tried in this order:
103
+
104
+ 1. `--branch-out-terminal` flag override (always wins)
105
+ 2. cmux — detected via `CMUX_SOCKET_PATH`
106
+ 3. tmux — detected via `TMUX`
107
+ 4. iTerm2 — detected via `TERM_PROGRAM=iTerm.app`
108
+ 5. Terminal.app — detected via `TERM_PROGRAM=Apple_Terminal`
109
+ 6. Ghostty — detected via `GHOSTTY_RESOURCES_DIR` or `TERM_PROGRAM` containing `ghostty`
110
+ 7. Fallback Alacritty window
111
+
112
+ ### Backend capability matrix
113
+
114
+ | Backend | `tab` | `split` — static directions | `split` — rotating policies |
115
+ |---------|-------|------------------------------|--------------------------|
116
+ | cmux | ✓ | `left` `right` `up` `down` | `clockwise` `counterclockwise` |
117
+ | tmux | ✓ | `left` `right` `up` `down` | `clockwise` `counterclockwise` |
118
+ | iTerm2 | ✓ | `right` `down` | — (use fallback list) |
119
+ | Terminal.app | ✓ | — (error) | — (error) |
120
+ | Ghostty | — (new window) | — (error) | — (error) |
121
+
122
+ Backends that don't support the requested `splitDirection` fail fast with an explicit error rather than silently doing something else. Use a comma-separated fallback list in `splitDirection` to handle this gracefully (e.g. `"counterclockwise,right"` works on all split-capable backends).
123
+
124
+ ## Examples
125
+
126
+ ```text
127
+ /branch
128
+ ```
129
+ Fork current session and open in a new pane/tab using config defaults.
130
+
131
+ ```text
132
+ /branch explore the auth edge cases
133
+ ```
134
+ Fork with a queued message. The child session opens with `"explore the auth edge cases"` prefilled in the editor and a 10-second auto-submit countdown.
135
+
136
+ ```text
137
+ /branch --model flash
138
+ ```
139
+ Fork using a fuzzy model query. If the current provider is Anthropic, `flash` would resolve to the closest Gemini Flash match available; if unresolvable the child keeps the parent's model.
140
+
141
+ ```text
142
+ /branch --model gemini/flash-2.5 try rewriting the parser without recursion
143
+ ```
144
+ Fork with both a target model and a queued message.
145
+
146
+ ## Upstream credit
147
+
148
+ An earlier version of this extension began as an iteration on davidgasquez's [`branch-term.ts`](https://github.com/davidgasquez/dotfiles/blob/main/agents/pi/extensions/branch-term.ts), MIT license.
@@ -0,0 +1,9 @@
1
+ # Third-Party Notices
2
+
3
+ ## davidgasquez/dotfiles
4
+
5
+ - **URL:** https://github.com/davidgasquez/dotfiles
6
+ - **License:** MIT
7
+ - **Copyright:** © 2016 David Gasquez
8
+
9
+ `extensions/branch-out/index.ts` began as an iteration on [`branch-term.ts`](https://github.com/davidgasquez/dotfiles/blob/main/agents/pi/extensions/branch-term.ts). The original provides `/branch` with session forking into a new Alacritty window. This version extends it with backend-aware routing (cmux, tmux, iTerm2, Terminal.app, Ghostty), config-driven split/tab launch mode, static and rotating layout policies, split-direction fallback lists, `preserveFocus` behavior, and optional model and message queuing for the child session; see README for details.
@@ -0,0 +1,5 @@
1
+ {
2
+ "launchMode": "split",
3
+ "splitDirection": "right",
4
+ "preserveFocus": true
5
+ }