-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·418 lines (368 loc) · 15.6 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·418 lines (368 loc) · 15.6 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/lib/json-node.sh"
source "$SCRIPT_DIR/lib/codex-config.sh"
require_node
case "$(uname -s)" in
MINGW*|MSYS*|CYGWIN*) IS_WINDOWS=true ;;
*) IS_WINDOWS=false ;;
esac
MODEL_PROFILE="maximum"
CROSS_MODEL_REVIEWER="fable-high"
CROSS_MODEL_REVIEWER_SET=false
while [ $# -gt 0 ]; do
case "$1" in
--model-profile)
shift
if [ $# -eq 0 ]; then
echo "Missing value for --model-profile (expected: mixed or maximum)" >&2
exit 1
fi
MODEL_PROFILE="$1"
;;
--model-profile=*)
MODEL_PROFILE="${1#*=}"
;;
--cross-model-reviewer)
shift
if [ $# -eq 0 ]; then
echo "Missing value for --cross-model-reviewer (expected: fable-high or opus-4.8-xhigh)" >&2
exit 1
fi
CROSS_MODEL_REVIEWER="$1"
CROSS_MODEL_REVIEWER_SET=true
;;
--cross-model-reviewer=*)
CROSS_MODEL_REVIEWER="${1#*=}"
CROSS_MODEL_REVIEWER_SET=true
;;
esac
shift
done
if [ "$CROSS_MODEL_REVIEWER_SET" = "false" ]; then
EXISTING_CROSS_MODEL_REVIEWER="$(json_get_file ".codex-sdlc/manifest.json" 'data.model_profile?.cross_model_reviewer || ""')"
[ -n "$EXISTING_CROSS_MODEL_REVIEWER" ] || EXISTING_CROSS_MODEL_REVIEWER="$(json_get_file ".codex-sdlc/model-profile.json" 'data.policy?.cross_model_reviewer || ""')"
[ -z "$EXISTING_CROSS_MODEL_REVIEWER" ] || CROSS_MODEL_REVIEWER="$EXISTING_CROSS_MODEL_REVIEWER"
fi
case "$MODEL_PROFILE" in
mixed|maximum) ;;
*)
echo "Unsupported model profile: $MODEL_PROFILE (expected: mixed or maximum)" >&2
exit 1
;;
esac
case "$CROSS_MODEL_REVIEWER" in
fable-high|opus-4.8-xhigh) ;;
*)
echo "Unsupported cross-model reviewer: $CROSS_MODEL_REVIEWER (expected: fable-high or opus-4.8-xhigh)" >&2
exit 1
;;
esac
require_gpt56_codex_version
WIZARD_VERSION="$(json_get_file "$SCRIPT_DIR/package.json" 'data.version || "unknown"')"
[ -z "$WIZARD_VERSION" ] && WIZARD_VERSION="unknown"
print_feedback_guidance() {
local command_name="$1"
local failure_point="$2"
local repo_shape="${3:-unknown}"
echo ""
echo "Likely wizard-level failure detected."
echo "Report bugs or improvements back to codex-sdlc-wizard."
echo "No issue will be posted automatically."
echo "Issue-ready details:"
echo " wizard version: $WIZARD_VERSION"
echo " command: $command_name"
echo " repo shape: $repo_shape"
echo " failure point: $failure_point"
}
require_bundle_file() {
local path="$1"
local label="$2"
if [ ! -f "$path" ]; then
print_feedback_guidance "install" "missing bundled runtime file: $label" "unknown"
exit 1
fi
}
for required in \
"AGENTS.md" \
"SDLC-LOOP.md" \
"START-SDLC.md" \
"PROVE-IT.md" \
"start-sdlc.sh" \
"start-sdlc.ps1" \
".codex/config.toml" \
".codex/hooks.json" \
".codex/unix-hooks.json" \
".codex/windows-hooks.json" \
".codex/hooks/bash-guard.sh" \
".codex/hooks/session-start.sh" \
".codex/hooks/git-guard.cjs" \
".codex/hooks/fable-review.cjs" \
".codex/hooks/dual-review.cjs" \
".codex/hooks/session-start.cjs" \
".codex/hooks/compact-guard.cjs" \
".codex/hooks/git-guard.ps1" \
".codex/hooks/session-start.ps1" \
"lib/merge-hooks.cjs" \
"lib/merge-gitattributes.cjs" \
"lib/managed-file-hash.cjs" \
"lib/remove-retired-files.cjs" \
"lib/refresh-manifest-hashes.cjs" \
".agents/skills/sdlc/SKILL.md"; do
require_bundle_file "$SCRIPT_DIR/$required" "$required"
done
CODEX_HOME_DIR="${CODEX_HOME:-$HOME/.codex}"
SKILLS_ROOT="$CODEX_HOME_DIR/skills"
SKILLS_BACKUP_ROOT="$CODEX_HOME_DIR/backups/skills"
GLOBAL_HELPER_SKILLS=("feedback" "setup-wizard" "update-wizard")
INSTALL_TOUCHED_FILES=()
mark_install_touched() {
INSTALL_TOUCHED_FILES+=("$1")
}
copy_if_missing() {
local source="$1"
local target="$2"
local label="$3"
if [ ! -f "$target" ]; then
cp "$source" "$target"
mark_install_touched "$target"
echo "Created $label"
else
echo "$label already exists - skipping (review manually)"
fi
}
install_repo_skill() {
local name="$1"
local source="$SCRIPT_DIR/.agents/skills/$name/SKILL.md"
local target=".agents/skills/$name/SKILL.md"
mkdir -p "$(dirname "$target")"
if [ -f "$target" ]; then
echo "$target already exists - skipping (review manually)"
else
cp "$source" "$target"
mark_install_touched "$target"
echo "Installed $target"
fi
}
install_global_skill() {
local skill_path="$1"
local skill_name
local source_template
local target_path
[ -d "$skill_path" ] || return 0
skill_name="$(basename "$skill_path")"
source_template="$skill_path/SKILL.template.md"
target_path="$SKILLS_ROOT/$skill_name"
if [ ! -f "$source_template" ]; then
echo "Error: expected wizard skill template is missing: skill-sources/$skill_name/SKILL.template.md" >&2
exit 1
fi
if [ -d "$target_path" ]; then
cp -R "$target_path" "$SKILLS_BACKUP_ROOT/$skill_name.bak.$(date +%s)"
rm -rf "$target_path"
echo "Backed up existing Codex skill: $skill_name"
fi
cp -R "$skill_path" "$SKILLS_ROOT/"
mv "$target_path/SKILL.template.md" "$target_path/SKILL.md"
echo "Installed Codex skill: $skill_name"
}
global_skill_matches_bundle() {
local skill_name="$1"
local bundled_path="$SCRIPT_DIR/skill-sources/$skill_name"
local target_path="$SKILLS_ROOT/$skill_name"
[ -d "$bundled_path" ] || return 1
[ -d "$target_path" ] || return 1
SOURCE_PATH="$bundled_path" TARGET_PATH="$target_path" node <<'NODE'
const fs = require("fs");
const path = require("path");
function files(root, relative = "") {
const current = path.join(root, relative);
const entries = fs.readdirSync(current, { withFileTypes: true });
return entries.flatMap((entry) => {
const child = path.join(relative, entry.name);
return entry.isDirectory() ? files(root, child) : [child.split(path.sep).join("/")];
});
}
const sourceRoot = process.env.SOURCE_PATH;
const targetRoot = process.env.TARGET_PATH;
const sourceFiles = files(sourceRoot).sort();
const expectedFiles = sourceFiles
.map((file) => file === "SKILL.template.md" ? "SKILL.md" : file)
.sort();
const targetFiles = files(targetRoot).sort();
if (JSON.stringify(expectedFiles) !== JSON.stringify(targetFiles)) process.exit(1);
for (const sourceRelative of sourceFiles) {
const targetRelative = sourceRelative === "SKILL.template.md" ? "SKILL.md" : sourceRelative;
const source = fs.readFileSync(path.join(sourceRoot, sourceRelative));
const target = fs.readFileSync(path.join(targetRoot, targetRelative));
if (!source.equals(target)) process.exit(1);
}
NODE
}
remove_wizard_managed_global_skill() {
local skill_name="$1"
local reason="$2"
local target_path="$SKILLS_ROOT/$skill_name"
[ -d "$target_path" ] || return 0
if ! global_skill_matches_bundle "$skill_name"; then
echo "Preserved user-owned global Codex skill: $skill_name"
return 0
fi
mkdir -p "$SKILLS_BACKUP_ROOT"
cp -R "$target_path" "$SKILLS_BACKUP_ROOT/$skill_name.bak.$(date +%s)"
rm -rf "$target_path"
echo "Removed wizard-managed global Codex skill: $skill_name ($reason)"
}
prune_legacy_global_skill() {
local legacy_name="$1"
local canonical_name="$2"
local legacy_path="$SKILLS_ROOT/$legacy_name"
[ -d "$legacy_path" ] || return 0
mkdir -p "$SKILLS_BACKUP_ROOT"
cp -R "$legacy_path" "$SKILLS_BACKUP_ROOT/$legacy_name.bak.$(date +%s)"
rm -rf "$legacy_path"
echo "Removed legacy Codex skill: $legacy_name (canonical: $canonical_name)"
}
write_model_profile() {
write_model_profile_metadata ".codex-sdlc/model-profile.json" "$MODEL_PROFILE" "$CROSS_MODEL_REVIEWER"
mark_install_touched ".codex-sdlc/model-profile.json"
echo "Wrote .codex-sdlc/model-profile.json ($MODEL_PROFILE)"
}
install_agents_baseline() {
local source="$SCRIPT_DIR/templates/AGENTS.baseline.md"
local target="AGENTS.md"
local reasoning_baseline
reasoning_baseline="$(profile_reasoning "$MODEL_PROFILE")"
if [ -f "$target" ]; then
if [ "${CODEX_SDLC_SETUP_GENERATED_AGENTS:-false}" = "true" ]; then
echo "AGENTS.md generated earlier in this setup - keeping it"
elif cmp -s "$target" <(sed \
-e "s|{{MODEL_PROFILE}}|$MODEL_PROFILE|g" \
-e "s|{{REASONING_BASELINE}}|$reasoning_baseline|g" \
"$source"); then
echo "AGENTS.md already matches the wizard baseline - keeping it"
elif [ -f ".codex-sdlc/manifest.json" ] && \
[ "$(json_get_file ".codex-sdlc/manifest.json" 'data.generated_files?.["AGENTS.md"] || ""')" = \
"$(node "$SCRIPT_DIR/lib/managed-file-hash.cjs" hash "$target")" ]
then
echo "AGENTS.md is wizard-managed - keeping it; profile guidance will be refreshed if needed"
else
echo "AGENTS.md is user-owned or customized - preserving it"
fi
return 0
fi
sed \
-e "s|{{MODEL_PROFILE}}|$MODEL_PROFILE|g" \
-e "s|{{REASONING_BASELINE}}|$reasoning_baseline|g" \
"$source" > "$target"
mark_install_touched "$target"
echo "Created AGENTS.md"
}
if [ "$IS_WINDOWS" = "true" ]; then
HOOKS_TEMPLATE="$SCRIPT_DIR/.codex/windows-hooks.json"
else
HOOKS_TEMPLATE="$SCRIPT_DIR/.codex/unix-hooks.json"
fi
HOOKS_MERGE_STATUS="$(node "$SCRIPT_DIR/lib/merge-hooks.cjs" --status .codex/hooks.json "$HOOKS_TEMPLATE")"
if [ "$HOOKS_MERGE_STATUS" = "target-broken" ]; then
echo "Error: .codex/hooks.json must contain a valid hooks object before baseline installation" >&2
exit 1
fi
echo "Installing SDLC Wizard for Codex CLI..."
GITATTRIBUTES_STATUS="$(node "$SCRIPT_DIR/lib/merge-gitattributes.cjs" --status .gitattributes)"
node "$SCRIPT_DIR/lib/merge-gitattributes.cjs" .gitattributes
if [ "$GITATTRIBUTES_STATUS" = "merge" ]; then
echo "Merged .gitattributes hook shell LF rule"
fi
install_agents_baseline
copy_if_missing "$SCRIPT_DIR/SDLC-LOOP.md" "SDLC-LOOP.md" "SDLC-LOOP.md"
copy_if_missing "$SCRIPT_DIR/START-SDLC.md" "START-SDLC.md" "START-SDLC.md"
copy_if_missing "$SCRIPT_DIR/PROVE-IT.md" "PROVE-IT.md" "PROVE-IT.md"
mkdir -p "$SKILLS_ROOT" "$SKILLS_BACKUP_ROOT"
for skill_name in "${GLOBAL_HELPER_SKILLS[@]}"; do
install_global_skill "$SCRIPT_DIR/skill-sources/$skill_name"
done
remove_wizard_managed_global_skill "sdlc" "repo-scoped .agents/skills/sdlc is the canonical \$sdlc entrypoint"
prune_legacy_global_skill "codex-sdlc" "sdlc"
mkdir -p .codex/hooks
node "$SCRIPT_DIR/lib/remove-retired-files.cjs"
merge_codex_config_profile ".codex/config.toml" "$MODEL_PROFILE"
mark_install_touched ".codex/config.toml"
echo "Merged repo-local Codex config for model profile '$MODEL_PROFILE'"
if [ -f ".codex/hooks.json" ]; then
cp .codex/hooks.json ".codex/hooks.json.bak.$(date +%s)"
echo "Backed up existing hooks.json"
fi
cp "$SCRIPT_DIR/.codex/hooks/"*.sh .codex/hooks/
chmod +x .codex/hooks/*.sh
cp "$SCRIPT_DIR/.codex/hooks/"*.cjs .codex/hooks/
rm -f .codex/hooks/git-guard.js .codex/hooks/session-start.js
mark_install_touched ".codex/hooks/git-guard.js"
mark_install_touched ".codex/hooks/session-start.js"
if [ "$IS_WINDOWS" = "true" ]; then
node "$SCRIPT_DIR/lib/merge-hooks.cjs" .codex/hooks.json "$HOOKS_TEMPLATE"
cp "$SCRIPT_DIR/.codex/hooks/git-guard.ps1" .codex/hooks/
cp "$SCRIPT_DIR/.codex/hooks/session-start.ps1" .codex/hooks/
copy_if_missing "$SCRIPT_DIR/start-sdlc.ps1" "start-sdlc.ps1" "start-sdlc.ps1"
echo "Installed .codex/hooks.json (universal Node hooks)"
echo "Installed Node and PowerShell hook scripts"
else
node "$SCRIPT_DIR/lib/merge-hooks.cjs" .codex/hooks.json "$HOOKS_TEMPLATE"
copy_if_missing "$SCRIPT_DIR/start-sdlc.sh" "start-sdlc.sh" "start-sdlc.sh"
chmod +x start-sdlc.sh
echo "Installed .codex/hooks.json (universal Node hooks)"
fi
if [ "$HOOKS_MERGE_STATUS" = "merge" ]; then
mark_install_touched ".codex/hooks.json"
fi
for touched_hook in \
.codex/hooks/bash-guard.sh \
.codex/hooks/session-start.sh \
.codex/hooks/git-guard.cjs \
.codex/hooks/fable-review.cjs \
.codex/hooks/dual-review.cjs \
.codex/hooks/session-start.cjs \
.codex/hooks/compact-guard.cjs; do
[ -f "$touched_hook" ] && mark_install_touched "$touched_hook"
done
if [ "$IS_WINDOWS" = "true" ]; then
mark_install_touched ".codex/hooks/git-guard.ps1"
mark_install_touched ".codex/hooks/session-start.ps1"
fi
echo "Installed shell hook scripts"
install_repo_skill sdlc
write_model_profile
node "$SCRIPT_DIR/lib/refresh-manifest-hashes.cjs" \
".codex-sdlc/manifest.json" "${INSTALL_TOUCHED_FILES[@]}"
echo ""
echo "SDLC Wizard for Codex installed."
START_MODEL="$(profile_model "$MODEL_PROFILE")"
START_REASONING="$(profile_reasoning "$MODEL_PROFILE")"
echo "Recommended start: codex -m $START_MODEL -c 'model_reasoning_effort=\"$START_REASONING\"'"
echo "Use plain 'codex' instead if you want to rely on trusted repo-local config."
echo "Fresh-session note: if you ran this from inside an existing Codex session, exit and reopen Codex in this repo so repo-local config, hooks, and skills load."
echo "Hook review note: if Codex says hooks need review, open /hooks after restart and review pending repo hooks before relying on enforcement."
echo "Start new with selected profile: codex -m $START_MODEL -c 'model_reasoning_effort=\"$START_REASONING\"'"
echo "Resume with selected profile: codex resume -m $START_MODEL -c 'model_reasoning_effort=\"$START_REASONING\"'"
echo "If resume warns it came back with a different model, resume explicitly with: codex resume -m gpt-5.6-sol -c 'model_reasoning_effort=\"high\"'"
echo "If you normally use yolo-style sessions, use the canonical full-trust Codex flag:"
echo " codex --dangerously-bypass-approvals-and-sandbox -m $START_MODEL -c 'model_reasoning_effort=\"$START_REASONING\"'"
echo " codex resume --dangerously-bypass-approvals-and-sandbox -m $START_MODEL -c 'model_reasoning_effort=\"$START_REASONING\"'"
echo "Codex may accept --yolo as shorthand; this wizard prints the canonical full-trust flag."
echo "Full-auto is not full-trust: full-trust bypasses sandbox and approval prompts."
echo "Full-trust warning: only use that variant in repos you fully trust."
echo "Model profile: '$MODEL_PROFILE'."
echo " - maximum: gpt-5.6-sol high throughout for flagship stability and depth; Sol high is the default normal driver for meaningful SDLC work."
echo " - mixed: experimental explicit opt-in using gpt-5.6-terra medium + gpt-5.6-sol review for measured speed, latency, or token-efficiency trials; invoke review with an explicit high effort override."
echo " - reasoning: keep Sol high as the standing root driver; escalate only difficult or high-risk slices to xhigh."
echo " - escalation: Max is single-task reasoning; Ultra is subagent-backed parallel work. Most tasks do not need either, and neither is a default wizard profile."
echo "Wrote repo-local .codex/config.toml model keys for this profile; mixed is experimental wizard policy, not a native Codex mode."
echo "Codex loads project config only after the repo is trusted, and trusted project config overrides your user-level ~/.codex/config.toml."
echo "If confidence drops below 95%, research more first. If it still stays below 95%, escalate review to xhigh."
echo "Repo-scoped skills are still a work in progress. Today the supported public workflow skill is '\$sdlc'."
echo "Codex treats same-name skills from different scopes as distinct choices; normal setup installs global helper skills only and keeps repo-scoped '\$sdlc' canonical."
echo "Additional repo-scoped workflows stay unnamed until their public contracts are ready."
echo "Auth-heavy note: for Windows / WAM / MFA or other live sign-in flows, the prompt itself stays user-owned."
echo "This wizard still owns command shape, checks, and the verify/resume steps after you complete sign-in."
echo "If auth, license, tenant, or permission state decides what work is possible, add a repo-local doctor / check-capability / Test-*Access helper."