-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjustfile
More file actions
333 lines (279 loc) · 10.1 KB
/
Copy pathjustfile
File metadata and controls
333 lines (279 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# Shellsmith – AI dev workflow
# Usage: nix develop --command just setup
set shell := ["bash", "-euo", "pipefail", "-c"]
root := justfile_directory()
timestamp := `date +%Y%m%d-%H%M%S`
# Default recipe: run full setup
setup: link zshrc npm
@echo ""
@echo "shellsmith: setup complete"
@echo " Run: source ~/.zshrc"
# Symlink config files (with backup)
link:
#!/usr/bin/env bash
set -euo pipefail
TIMESTAMP="{{ timestamp }}"
backup_and_link() {
local source="$1" target="$2"
if [[ -L "$target" ]] && [[ "$(readlink "$target")" == "$source" ]]; then
echo " ok: $target"
return
fi
if [[ -e "$target" ]] || [[ -L "$target" ]]; then
local backup="${target}.backup.${TIMESTAMP}"
mv "$target" "$backup"
echo " backup: $target → $backup"
fi
mkdir -p "$(dirname "$target")"
ln -sf "$source" "$target"
echo " linked: $source → $target"
}
backup_and_link "{{ root }}/nvim" "$HOME/.config/nvim"
backup_and_link "{{ root }}/tmux/tmux.conf" "$HOME/.tmux.conf"
# Inject shell config into ~/.zshrc between markers
zshrc:
#!/usr/bin/env bash
set -euo pipefail
ZSHRC="$HOME/.zshrc"
MARKER_START="# >>> shellsmith >>>"
MARKER_END="# <<< shellsmith <<<"
BLOCK_FILE="{{ root }}/shell/zshrc_block.zsh"
FULL_BLOCK="$(printf '%s\n%s\n%s' "$MARKER_START" "$(cat "$BLOCK_FILE")" "$MARKER_END")"
touch "$ZSHRC"
# Remove old development-wf markers if present
if grep -qF "# >>> development-wf >>>" "$ZSHRC"; then
tmpfile="$(mktemp)"
awk '
/^# >>> development-wf >>>/ { skip=1; next }
/^# <<< development-wf <<</ { skip=0; next }
!skip { print }
' "$ZSHRC" > "$tmpfile"
mv "$tmpfile" "$ZSHRC"
echo " removed old development-wf block"
fi
if grep -qF "$MARKER_START" "$ZSHRC"; then
tmpfile="$(mktemp)"
awk -v start="$MARKER_START" -v end="$MARKER_END" -v block="$FULL_BLOCK" '
$0 == start { skip=1; print block; next }
$0 == end { skip=0; next }
!skip { print }
' "$ZSHRC" > "$tmpfile"
mv "$tmpfile" "$ZSHRC"
echo " updated shellsmith block in ~/.zshrc"
else
printf '\n%s\n' "$FULL_BLOCK" >> "$ZSHRC"
echo " appended shellsmith block to ~/.zshrc"
fi
# Install npm globals not covered by Nix
npm:
#!/usr/bin/env bash
set -euo pipefail
export NPM_CONFIG_PREFIX="$HOME/.local"
PACKAGES=(
"@mariozechner/pi-coding-agent"
)
for pkg in "${PACKAGES[@]}"; do
if npm list -g --prefix="$HOME/.local" "$pkg" &>/dev/null 2>&1; then
echo " ok: $pkg"
else
npm install -g "$pkg"
echo " installed: $pkg"
fi
done
# Run environment diagnostics
doctor:
bash {{ root }}/scripts/doctor.sh
# Show current state
status:
#!/usr/bin/env bash
set -euo pipefail
echo "=== Symlinks ==="
for pair in "$HOME/.config/nvim:{{ root }}/nvim" "$HOME/.tmux.conf:{{ root }}/tmux/tmux.conf"; do
target="${pair%%:*}"
expected="${pair#*:}"
if [[ -L "$target" ]] && [[ "$(readlink "$target")" == "$expected" ]]; then
echo " ok: $target → $expected"
else
echo " MISSING: $target"
fi
done
echo ""
echo "=== Shell block ==="
if grep -qF "# >>> shellsmith >>>" "$HOME/.zshrc" 2>/dev/null; then
echo " ok: shellsmith block in ~/.zshrc"
else
echo " MISSING: shellsmith block in ~/.zshrc"
fi
echo ""
echo "=== MCP servers ==="
python3 "{{ root }}/mcp/status.py" short
echo ""
echo "=== Key binaries ==="
for cmd in nvim tmux fzf jq claude node just; do
if loc="$(command -v "$cmd" 2>/dev/null)"; then
echo " ok: $cmd → $loc"
else
echo " MISSING: $cmd"
fi
done
# Remove symlinks and zshrc block
clean:
#!/usr/bin/env bash
set -euo pipefail
echo "Cleaning shellsmith..."
for target in "$HOME/.config/nvim" "$HOME/.tmux.conf"; do
if [[ -L "$target" ]]; then
rm "$target"
echo " removed: $target"
fi
done
if grep -qF "# >>> shellsmith >>>" "$HOME/.zshrc" 2>/dev/null; then
tmpfile="$(mktemp)"
awk '
/^# >>> shellsmith >>>/ { skip=1; next }
/^# <<< shellsmith <<</ { skip=0; next }
!skip { print }
' "$HOME/.zshrc" > "$tmpfile"
mv "$tmpfile" "$HOME/.zshrc"
echo " removed: shellsmith block from ~/.zshrc"
fi
echo "done (nvim/ and tmux/ configs are still in this repo)"
# Configure MCP servers for Claude Code / Pi
# Usage: just mcp (interactive picker)
# just mcp github (single server)
# just mcp github jira (multiple servers)
mcp *SERVERS:
{{ root }}/mcp/setup.sh {{ SERVERS }}
# List available MCP server templates
mcp-list:
#!/usr/bin/env bash
set -euo pipefail
echo "Available MCP servers:"
for f in "{{ root }}"/mcp/*.json; do
[[ -f "$f" ]] || continue
name="$(basename "$f" .json)"
desc=$(python3 -c "import json; d=json.load(open('$f')); k=list(d.keys())[0]; print(d[k].get('description',''))" 2>/dev/null || echo "")
echo " $name — $desc"
done
# Show MCP servers currently configured in Claude Code
mcp-status:
@echo "=== MCP servers in ~/.claude.json ==="
@python3 "{{ root }}/mcp/status.py" full
# Create a backup snapshot of current configs
backup:
#!/usr/bin/env bash
set -euo pipefail
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
BACKUP_DIR="$HOME/.local/share/shellsmith/backups/$TIMESTAMP"
mkdir -p "$BACKUP_DIR"
echo "Creating backup snapshot: $TIMESTAMP"
# Backup nvim config if it exists
if [[ -d "$HOME/.config/nvim" ]]; then
cp -r "$HOME/.config/nvim" "$BACKUP_DIR/nvim"
echo " backed up: ~/.config/nvim → $BACKUP_DIR/nvim"
fi
# Backup tmux config if it exists
if [[ -f "$HOME/.tmux.conf" ]]; then
cp "$HOME/.tmux.conf" "$BACKUP_DIR/tmux.conf"
echo " backed up: ~/.tmux.conf → $BACKUP_DIR/tmux.conf"
fi
# Backup zshrc if it exists
if [[ -f "$HOME/.zshrc" ]]; then
cp "$HOME/.zshrc" "$BACKUP_DIR/zshrc"
echo " backed up: ~/.zshrc → $BACKUP_DIR/zshrc"
fi
echo "Backup saved to: $BACKUP_DIR"
# Restore configs from a backup snapshot
restore:
#!/usr/bin/env bash
set -euo pipefail
BACKUP_BASE="$HOME/.local/share/shellsmith/backups"
if [[ ! -d "$BACKUP_BASE" ]]; then
echo "error: no backups found in $BACKUP_BASE"
exit 1
fi
# List available backups
echo "Available backups:"
mapfile -t backups < <(ls -1d "$BACKUP_BASE"/*/ 2>/dev/null | sort -r)
if [[ ${#backups[@]} -eq 0 ]]; then
echo " (none)"
exit 1
fi
for i in "${!backups[@]}"; do
timestamp=$(basename "${backups[$i]}")
echo " [$((i+1))] $timestamp"
done
echo ""
read -p "Select backup to restore (number): " selection
# Validate selection
if ! [[ "$selection" =~ ^[0-9]+$ ]] || ((selection < 1 || selection > ${#backups[@]})); then
echo "error: invalid selection"
exit 1
fi
selected_backup="${backups[$((selection-1))]}"
timestamp=$(basename "$selected_backup")
echo "Restoring from: $timestamp"
# Create restore snapshot before overwriting
restore_snapshot="$HOME/.local/share/shellsmith/backups/.pre-restore-$(date +%Y%m%d-%H%M%S)"
mkdir -p "$restore_snapshot"
# Restore nvim
if [[ -d "$selected_backup/nvim" ]]; then
if [[ -d "$HOME/.config/nvim" ]]; then
cp -r "$HOME/.config/nvim" "$restore_snapshot/nvim"
fi
rm -rf "$HOME/.config/nvim"
cp -r "$selected_backup/nvim" "$HOME/.config/nvim"
echo " restored: ~/.config/nvim"
fi
# Restore tmux.conf
if [[ -f "$selected_backup/tmux.conf" ]]; then
if [[ -f "$HOME/.tmux.conf" ]]; then
cp "$HOME/.tmux.conf" "$restore_snapshot/tmux.conf"
fi
cp "$selected_backup/tmux.conf" "$HOME/.tmux.conf"
echo " restored: ~/.tmux.conf"
fi
# Restore zshrc
if [[ -f "$selected_backup/zshrc" ]]; then
if [[ -f "$HOME/.zshrc" ]]; then
cp "$HOME/.zshrc" "$restore_snapshot/zshrc"
fi
cp "$selected_backup/zshrc" "$HOME/.zshrc"
echo " restored: ~/.zshrc"
fi
echo "Restore complete (pre-restore snapshot saved to: $restore_snapshot)"
# Update flake and npm globals
update:
nix flake update
# ── Orchestrator ─────────────────────────────────────────────────────────────
# Install orchestrator dependencies and create state dirs
orch-setup:
pip3 install --user anthropic pyyaml
mkdir -p ~/.local/share/shellsmith/orchestrator/tasks
mkdir -p ~/.local/share/shellsmith/orchestrator/logs
mkdir -p ~/.local/share/shellsmith/orchestrator/workdirs
chmod +x {{ root }}/orchestrator/ralph/ralph.sh
@command -v jq >/dev/null || echo "WARNING: jq not found — enter nix develop shell"
@command -v claude >/dev/null || echo "WARNING: claude not found — enter nix develop shell"
@echo "orchestrator: setup complete"
# Submit a task for async planning
orchestrate +TASK:
python3 {{ root }}/orchestrator/orch.py run "{{ TASK }}"
# List all orchestrator tasks
orch-status:
python3 {{ root }}/orchestrator/orch.py status
# Show orchestrator task details
orch-show ID:
python3 {{ root }}/orchestrator/orch.py show {{ ID }}
# Approve a planned task — launches ralph in background
orch-approve ID *ARGS:
python3 {{ root }}/orchestrator/orch.py approve {{ ID }} {{ ARGS }}
# Show ralph story progress for a task
orch-stories ID:
python3 {{ root }}/orchestrator/orch.py stories {{ ID }}
# Cancel an orchestrator task
orch-cancel ID:
python3 {{ root }}/orchestrator/orch.py cancel {{ ID }}
# Show orchestrator task logs
orch-logs ID:
python3 {{ root }}/orchestrator/orch.py logs {{ ID }}