-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·236 lines (197 loc) · 6.38 KB
/
install.sh
File metadata and controls
executable file
·236 lines (197 loc) · 6.38 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
#!/usr/bin/env bash
#
# Taskmaster installer for Codex and Claude.
#
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CODEX_ROOT="$HOME/.codex"
CLAUDE_ROOT="$HOME/.claude"
CODEX_SKILL_DIR="$CODEX_ROOT/skills/taskmaster"
CLAUDE_SKILL_DIR="$CLAUDE_ROOT/skills/taskmaster"
CODEX_BIN_DIR="$CODEX_ROOT/bin"
CODEX_LAUNCHER_LINK="$CODEX_BIN_DIR/codex-taskmaster"
CODEX_SHIM_LINK="$CODEX_BIN_DIR/codex"
CLAUDE_HOOKS_DIR="$CLAUDE_ROOT/hooks"
CLAUDE_HOOK_LINK="$CLAUDE_HOOKS_DIR/taskmaster-check-completion.sh"
CLAUDE_SETTINGS_PATH="$CLAUDE_ROOT/settings.json"
CLAUDE_HOOK_COMMAND="~/.claude/hooks/taskmaster-check-completion.sh"
safe_copy() {
local src="$1"
local dst="$2"
if [[ "$(cd "$(dirname "$src")" && pwd)/$(basename "$src")" == "$(cd "$(dirname "$dst")" && pwd)/$(basename "$dst")" ]]; then
return 0
fi
cp "$src" "$dst"
}
copy_skill_files() {
local skill_dir="$1"
mkdir -p "$skill_dir/hooks"
mkdir -p "$skill_dir/docs"
safe_copy "$SCRIPT_DIR/SKILL.md" "$skill_dir/SKILL.md"
safe_copy "$SCRIPT_DIR/README.md" "$skill_dir/README.md"
safe_copy "$SCRIPT_DIR/LICENSE" "$skill_dir/LICENSE"
safe_copy "$SCRIPT_DIR/docs/SPEC.md" "$skill_dir/docs/SPEC.md"
safe_copy "$SCRIPT_DIR/install.sh" "$skill_dir/install.sh"
safe_copy "$SCRIPT_DIR/uninstall.sh" "$skill_dir/uninstall.sh"
safe_copy "$SCRIPT_DIR/taskmaster-compliance-prompt.sh" "$skill_dir/taskmaster-compliance-prompt.sh"
safe_copy "$SCRIPT_DIR/run-taskmaster-codex.sh" "$skill_dir/run-taskmaster-codex.sh"
safe_copy "$SCRIPT_DIR/check-completion.sh" "$skill_dir/check-completion.sh"
safe_copy "$SCRIPT_DIR/hooks/check-completion.sh" "$skill_dir/hooks/check-completion.sh"
safe_copy "$SCRIPT_DIR/hooks/inject-continue-codex.sh" "$skill_dir/hooks/inject-continue-codex.sh"
safe_copy "$SCRIPT_DIR/hooks/run-codex-expect-bridge.exp" "$skill_dir/hooks/run-codex-expect-bridge.exp"
chmod +x "$skill_dir/install.sh"
chmod +x "$skill_dir/uninstall.sh"
chmod +x "$skill_dir/taskmaster-compliance-prompt.sh"
chmod +x "$skill_dir/run-taskmaster-codex.sh"
chmod +x "$skill_dir/check-completion.sh"
chmod +x "$skill_dir/hooks/check-completion.sh"
chmod +x "$skill_dir/hooks/inject-continue-codex.sh"
chmod +x "$skill_dir/hooks/run-codex-expect-bridge.exp"
}
codex_detected() {
command -v codex >/dev/null 2>&1 || [[ -d "$CODEX_ROOT" ]]
}
claude_detected() {
command -v claude >/dev/null 2>&1 || [[ -d "$CLAUDE_ROOT" ]]
}
ensure_claude_stop_hook() {
local settings_path="$1"
local hook_command="$2"
if ! command -v python3 >/dev/null 2>&1; then
echo " Claude: python3 not found; add Stop hook manually -> $hook_command" >&2
return 0
fi
python3 - "$settings_path" "$hook_command" <<'PY'
import json
import os
import sys
settings_path = sys.argv[1]
hook_command = sys.argv[2]
if os.path.exists(settings_path):
try:
with open(settings_path, "r", encoding="utf-8") as f:
data = json.load(f)
except json.JSONDecodeError:
print(f" Claude: settings is not valid JSON ({settings_path}); add Stop hook manually.", file=sys.stderr)
sys.exit(0)
else:
data = {}
if not isinstance(data, dict):
print(f" Claude: settings root is not an object ({settings_path}); add Stop hook manually.", file=sys.stderr)
sys.exit(0)
container = None
if isinstance(data.get("hooks"), dict):
container = data["hooks"]
else:
container = data
stop_hooks = container.get("Stop")
if not isinstance(stop_hooks, list):
stop_hooks = []
container["Stop"] = stop_hooks
exists = False
for entry in stop_hooks:
if not isinstance(entry, dict):
continue
hooks = entry.get("hooks")
if not isinstance(hooks, list):
continue
for hook in hooks:
if not isinstance(hook, dict):
continue
if hook.get("type") == "command" and hook.get("command") == hook_command:
exists = True
break
if exists:
break
if not exists:
stop_hooks.append(
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": hook_command,
}
],
}
)
os.makedirs(os.path.dirname(settings_path), exist_ok=True)
with open(settings_path, "w", encoding="utf-8") as f:
json.dump(data, f, indent=2)
f.write("\n")
if exists:
print(" Claude: Stop hook already configured")
else:
print(" Claude: added Stop hook to settings")
PY
}
install_codex() {
copy_skill_files "$CODEX_SKILL_DIR"
mkdir -p "$CODEX_BIN_DIR"
ln -sf "$CODEX_SKILL_DIR/run-taskmaster-codex.sh" "$CODEX_LAUNCHER_LINK"
ln -sf "$CODEX_SKILL_DIR/run-taskmaster-codex.sh" "$CODEX_SHIM_LINK"
echo " Codex: installed skill files to $CODEX_SKILL_DIR"
echo " Codex: linked launcher at $CODEX_LAUNCHER_LINK"
echo " Codex: linked shim at $CODEX_SHIM_LINK"
}
install_claude() {
copy_skill_files "$CLAUDE_SKILL_DIR"
mkdir -p "$CLAUDE_HOOKS_DIR"
ln -sf "$CLAUDE_SKILL_DIR/check-completion.sh" "$CLAUDE_HOOK_LINK"
ln -sf "$CLAUDE_SKILL_DIR/taskmaster-compliance-prompt.sh" "$CLAUDE_HOOKS_DIR/taskmaster-compliance-prompt.sh"
chmod +x "$CLAUDE_HOOK_LINK"
echo " Claude: installed skill files to $CLAUDE_SKILL_DIR"
echo " Claude: linked Stop hook at $CLAUDE_HOOK_LINK"
ensure_claude_stop_hook "$CLAUDE_SETTINGS_PATH" "$CLAUDE_HOOK_COMMAND"
}
INSTALL_TARGET="${TASKMASTER_INSTALL_TARGET:-auto}"
INSTALL_CODEX=0
INSTALL_CLAUDE=0
case "$INSTALL_TARGET" in
auto)
if codex_detected; then
INSTALL_CODEX=1
fi
if claude_detected; then
INSTALL_CLAUDE=1
fi
if [[ "$INSTALL_CODEX" -eq 0 && "$INSTALL_CLAUDE" -eq 0 ]]; then
INSTALL_CODEX=1
INSTALL_CLAUDE=1
echo "No Codex/Claude install detected; defaulting to both targets."
fi
;;
codex)
INSTALL_CODEX=1
;;
claude)
INSTALL_CLAUDE=1
;;
both)
INSTALL_CODEX=1
INSTALL_CLAUDE=1
;;
*)
echo "Invalid TASKMASTER_INSTALL_TARGET='$INSTALL_TARGET' (expected: auto|codex|claude|both)" >&2
exit 4
;;
esac
echo "Installing Taskmaster..."
if [[ "$INSTALL_CODEX" -eq 1 ]]; then
install_codex
fi
if [[ "$INSTALL_CLAUDE" -eq 1 ]]; then
install_claude
fi
echo ""
echo "Done."
if [[ "$INSTALL_CODEX" -eq 1 ]]; then
echo ""
echo "Codex usage:"
echo " codex [codex args]"
fi
if [[ "$INSTALL_CLAUDE" -eq 1 ]]; then
echo ""
echo "Claude usage:"
echo " Claude Stop hook is configured at $CLAUDE_HOOK_COMMAND"
fi