pantheon-opencode 1.6.1 → 1.6.2-beta.10

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.
Files changed (169) hide show
  1. package/AGENTS.global.md +11 -11
  2. package/AGENTS.md +2 -2
  3. package/CHANGELOG.md +179 -0
  4. package/README.md +268 -20
  5. package/README.pt-BR.md +34 -11
  6. package/bin/pantheon-init.mjs +301 -32
  7. package/package.json +13 -4
  8. package/plugin.json +1 -1
  9. package/prompts/README.md +58 -0
  10. package/prompts/debug-issue.prompt.md +46 -0
  11. package/prompts/dynamic/agora-generated.txt +38 -0
  12. package/prompts/dynamic/orchestrate-generated.txt +51 -0
  13. package/prompts/focus.prompt.md +42 -0
  14. package/prompts/implement-feature.prompt.md +39 -0
  15. package/prompts/optimize-database.prompt.md +58 -0
  16. package/prompts/orchestrate-with-zeus.prompt.md +441 -0
  17. package/prompts/plan-architecture.prompt.md +59 -0
  18. package/prompts/quick-discovery-large-codebase.prompt.md +294 -0
  19. package/prompts/quick-plan-large-feature.prompt.md +197 -0
  20. package/prompts/semantic-summarize.md +50 -0
  21. package/prompts/sketch.prompt.md +91 -0
  22. package/prompts/subtask.prompt.md +131 -0
  23. package/pyproject.toml +1 -1
  24. package/scripts/build-agents-md.mjs +1 -1
  25. package/scripts/decision-router-budget.mjs +780 -0
  26. package/scripts/decision-router-v2-budget.mjs +218 -0
  27. package/scripts/decision-router-v2-egress.mjs +272 -0
  28. package/scripts/decision-router.mjs +758 -0
  29. package/scripts/docs-check-changelog.mjs +5 -3
  30. package/scripts/doctor.mjs +213 -45
  31. package/scripts/install/agents-md.mjs +2 -1
  32. package/scripts/install/component-selection.mjs +9 -4
  33. package/scripts/install/config-migration.mjs +344 -393
  34. package/scripts/install/config-paths.mjs +15 -0
  35. package/scripts/install/decision-layer-preview.mjs +376 -0
  36. package/scripts/install/decision-router-config.mjs +560 -0
  37. package/scripts/install/health-check.mjs +20 -11
  38. package/scripts/install/interactive.mjs +103 -14
  39. package/scripts/install/interrupt.mjs +4 -3
  40. package/scripts/install/mcp-permissions.mjs +164 -0
  41. package/scripts/install/migrate.mjs +123 -72
  42. package/scripts/install/opencode-version.mjs +31 -13
  43. package/scripts/install/opencode-wildcard.mjs +106 -0
  44. package/scripts/install/opencode.mjs +411 -184
  45. package/scripts/install/plan-artifact.mjs +12 -1
  46. package/scripts/install/plan.mjs +8 -1
  47. package/scripts/install/plugin.mjs +18 -1
  48. package/scripts/install/state.mjs +12 -0
  49. package/scripts/install/strings.mjs +22 -0
  50. package/scripts/install/v2-capabilities.mjs +5 -6
  51. package/scripts/install/venv.mjs +34 -17
  52. package/scripts/mcp_resources.py +11 -9
  53. package/scripts/package-evidence.mjs +1 -0
  54. package/scripts/release-notes.mjs +30 -7
  55. package/scripts/restore.mjs +22 -10
  56. package/scripts/sandbox-env.sh +174 -0
  57. package/scripts/setup-v2-config.mjs +1703 -0
  58. package/scripts/setup.mjs +415 -0
  59. package/scripts/sync-tui.mjs +9 -1
  60. package/scripts/test-opencode-v2-sandbox.sh +448 -157
  61. package/scripts/update-skills-lock.mjs +30 -0
  62. package/scripts/versioning.mjs +41 -5
  63. package/skills-lock.json +10 -10
  64. package/src/agents/aphrodite.md +11 -3
  65. package/src/agents/apollo.md +6 -0
  66. package/src/agents/athena.md +7 -1
  67. package/src/agents/demeter.md +6 -2
  68. package/src/agents/gaia.md +5 -0
  69. package/src/agents/hephaestus.md +7 -2
  70. package/src/agents/hermes.md +14 -13
  71. package/src/agents/iris.md +6 -2
  72. package/src/agents/mnemosyne.md +21 -50
  73. package/src/agents/nyx.md +6 -2
  74. package/src/agents/prometheus.md +5 -1
  75. package/src/agents/talos.md +10 -1
  76. package/src/agents/themis.md +5 -1
  77. package/src/agents/zeus.md +61 -65
  78. package/src/instructions/agent-return-format.instructions.md +1 -1
  79. package/src/instructions/memory-protocol.instructions.md +3 -3
  80. package/src/instructions/test-economy.instructions.md +6 -6
  81. package/src/mcp/eval_store.py +11 -4
  82. package/src/mcp/mcp_resources.py +11 -9
  83. package/src/mcp/memory_mcp.py +293 -150
  84. package/src/mcp/pantheon_vision.py +37 -36
  85. package/src/pantheon/cost-command.ts +30 -133
  86. package/src/pantheon/jev-decision-tool.ts +347 -0
  87. package/src/pantheon/jev-decisions.ts +625 -0
  88. package/src/pantheon/local-decision-agents.ts +170 -0
  89. package/src/pantheon/local-decision-budget.ts +1046 -0
  90. package/src/pantheon/local-decision-egress-gate.ts +144 -0
  91. package/src/pantheon/local-decision-prompt.ts +256 -0
  92. package/src/pantheon/local-decision-provider-matrix.ts +44 -0
  93. package/src/pantheon/local-decision-router.ts +225 -0
  94. package/src/pantheon/local-decision-skills.ts +281 -0
  95. package/src/pantheon/local-decision-tool.ts +160 -0
  96. package/src/pantheon/local-decision-turn.ts +101 -0
  97. package/src/pantheon/local-decision-usage-evidence.internal.ts +168 -0
  98. package/src/pantheon/local-orchestration.ts +322 -0
  99. package/src/pantheon/model-pricing.ts +1 -536
  100. package/src/pantheon/pantheon-decision-catalog.ts +101 -0
  101. package/src/pantheon/v2-decision-budget.ts +456 -0
  102. package/src/pantheon/v2-decision-contracts.ts +300 -0
  103. package/src/pantheon/v2-decision-egress.ts +203 -0
  104. package/src/pantheon/v2-decision-events.ts +180 -0
  105. package/src/pantheon/v2-decision-heuristic.ts +121 -0
  106. package/src/pantheon/v2-decision-points/p1-agent.ts +91 -0
  107. package/src/pantheon/v2-decision-points/p10-claims.ts +243 -0
  108. package/src/pantheon/v2-decision-points/p11-catalog.ts +220 -0
  109. package/src/pantheon/v2-decision-points/p2-skill.ts +83 -0
  110. package/src/pantheon/v2-decision-points/p3-complexity.ts +108 -0
  111. package/src/pantheon/v2-decision-points/p4-memory.ts +137 -0
  112. package/src/pantheon/v2-decision-points/p5-themis-verify.ts +190 -0
  113. package/src/pantheon/v2-decision-points/p6-council.ts +161 -0
  114. package/src/pantheon/v2-decision-points/p7-loop.ts +263 -0
  115. package/src/pantheon/v2-decision-points/p8-guardrail.ts +367 -0
  116. package/src/pantheon/v2-decision-points/p9-memory-compaction.ts +304 -0
  117. package/src/pantheon/v2-decision-points.ts +242 -0
  118. package/src/pantheon/v2-decision-policy.ts +166 -0
  119. package/src/pantheon/v2-decision-premises.ts +146 -0
  120. package/src/pantheon/v2-decision-prompt-surface.ts +115 -0
  121. package/src/pantheon/v2-decision-rank.ts +91 -0
  122. package/src/pantheon/v2-decision-registry.ts +391 -0
  123. package/src/pantheon/v2-decision-resource-ids.ts +127 -0
  124. package/src/pantheon/v2-decision-shadow.ts +123 -0
  125. package/src/pantheon/v2-decision-telemetry.ts +214 -0
  126. package/src/pantheon/v2-decision-verify.ts +51 -0
  127. package/src/pantheon/v2-hook-engine.ts +307 -0
  128. package/src/pantheon/v2-native-decisions.ts +365 -0
  129. package/src/pantheon/v2-shell-hooks.ts +66 -2
  130. package/src/pantheon/v2-tools.ts +38 -15
  131. package/src/pantheon/v2-vision.ts +34 -29
  132. package/src/pantheon/vision.ts +43 -10
  133. package/src/plugin-v2.ts +449 -79
  134. package/src/plugin.ts +4 -0
  135. package/src/plugins/tui/THIRD_PARTY_NOTICES.md +24 -0
  136. package/src/plugins/tui/dist/server-v2.d.ts +22 -0
  137. package/src/plugins/tui/dist/server-v2.d.ts.map +1 -0
  138. package/src/plugins/tui/dist/server-v2.js +26 -0
  139. package/src/plugins/tui/dist/server-v2.js.map +1 -0
  140. package/src/plugins/tui/dist/tui-v2.d.ts +54 -51
  141. package/src/plugins/tui/dist/tui-v2.d.ts.map +1 -1
  142. package/src/plugins/tui/dist/tui-v2.js +762 -529
  143. package/src/plugins/tui/dist/tui-v2.js.map +1 -1
  144. package/src/plugins/tui/dist/tui.js +1 -1
  145. package/src/plugins/tui/index-v2.ts +3 -6
  146. package/src/plugins/tui/package-lock.json +17 -2
  147. package/src/plugins/tui/package.json +6 -3
  148. package/src/plugins/tui/src/context-gauge.ts +59 -0
  149. package/src/plugins/tui/src/cost-data.ts +607 -0
  150. package/src/plugins/tui/src/index-v2.tsx +360 -242
  151. package/src/plugins/tui/src/model-pricing.ts +536 -0
  152. package/src/plugins/tui/src/model-usage-limits.ts +4 -0
  153. package/src/plugins/tui/src/server-v2.ts +21 -0
  154. package/src/plugins/tui/src/sidebar-width.ts +129 -0
  155. package/src/plugins/tui/tsconfig.typecheck.json +1 -1
  156. package/src/plugins/tui/tsdown.config.ts +34 -5
  157. package/src/routing.yml +72 -13
  158. package/src/skills/README.md +4 -0
  159. package/src/skills/agent-coordination/SKILL.md +0 -3
  160. package/src/skills/artifact-management/SKILL.md +0 -3
  161. package/src/skills/auto-continue/SKILL.md +0 -3
  162. package/src/skills/code-review-checklist/SKILL.md +0 -3
  163. package/src/skills/context-compression/SKILL.md +0 -3
  164. package/src/skills/memory-bank/SKILL.md +6 -28
  165. package/src/skills/session-goal/SKILL.md +0 -3
  166. package/src/skills/simplify/SKILL.md +5 -4
  167. package/src/skills/tdd-with-agents/SKILL.md +0 -3
  168. package/src/skills/visual-review-pipeline/SKILL.md +0 -1
  169. package/src/pantheon/memory-context.ts +0 -1017
@@ -17,8 +17,9 @@
17
17
  #
18
18
  # Modes (run sequentially; a failure stops later checks):
19
19
  # --prepare Build tarball, install pantheon-opencode + the OpenCode V2
20
- # binary in the sandbox prefix, headless init, and generate
21
- # the project config and sandbox run-test.sh.
20
+ # binary in the sandbox prefix, headless init with the
21
+ # default components plus opt-in runtime, and generate the
22
+ # project config and sandbox run-test.sh.
22
23
  # --run v2 Base validation: opencode mcp list + doctor (config is
23
24
  # regenerated first).
24
25
  # --prompts Prompt battery via `opencode run --format json`.
@@ -49,21 +50,81 @@
49
50
  # sandbox root that overlaps either protected repo.
50
51
  # PANTHEON_SANDBOX_MODEL Model used by init/prompts
51
52
  # (default: opencode-go/mimo-v2.5)
53
+ # PANTHEON_V2_CONFIG Config file path (must be inside the sandbox root)
54
+ # PANTHEON_V2_DB Database path (must be inside the sandbox root)
52
55
  # PANTHEON_PROMPT_TIMEOUT Per-prompt timeout in seconds (default: 300)
53
56
  # Exit codes: 0 = every required check returned explicit PASS,
54
57
  # 1 = any failure or untested check (see reports in the sandbox root),
55
58
  # 2 = usage error, 3 = sandbox not prepared.
56
59
  set -euo pipefail
57
60
 
58
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
61
+ # Keep this bootstrap self-contained: do not source, execute, create, chmod, or
62
+ # clean up anything until both the configured root and adjacent helper pass the
63
+ # same basic path checks. The sourced helper repeats these checks for callers.
64
+ BOOTSTRAP_NORMALIZED=""
65
+ bootstrap_normalize_path() {
66
+ local path="$1" current="/" rest component normalized=""
67
+ local LC_ALL=C
68
+
69
+ [[ "$path" == /* && ! "$path" =~ [[:cntrl:]] ]] || return 1
70
+ rest="${path#/}"
71
+ while [[ -n "$rest" ]]; do
72
+ if [[ "$rest" == */* ]]; then
73
+ component="${rest%%/*}"
74
+ rest="${rest#*/}"
75
+ else
76
+ component="$rest"
77
+ rest=""
78
+ fi
79
+ case "$component" in
80
+ '' | .) continue ;;
81
+ ..) return 1 ;;
82
+ esac
83
+ if [[ "$current" == / ]]; then
84
+ current="/$component"
85
+ else
86
+ current="$current/$component"
87
+ fi
88
+ [[ ! -L "$current" ]] || return 1
89
+ normalized="$current"
90
+ done
91
+ BOOTSTRAP_NORMALIZED="${normalized:-/}"
92
+ }
93
+
94
+ bootstrap_fail() {
95
+ printf '%s\n' 'ERROR: sandbox preflight validation failed.' >&2
96
+ exit 2
97
+ }
98
+
99
+ BOOTSTRAP_ROOT="${PANTHEON_SANDBOX_ROOT:-${HOME:-}/pantheon-sandbox}"
100
+ bootstrap_normalize_path "$BOOTSTRAP_ROOT" || bootstrap_fail
101
+ SANDBOX_ROOT="$BOOTSTRAP_NORMALIZED"
102
+ [[ "$SANDBOX_ROOT" != / ]] || bootstrap_fail
103
+
104
+ BOOTSTRAP_ENTRY="${BASH_SOURCE[0]}"
105
+ if [[ "$BOOTSTRAP_ENTRY" != /* ]]; then
106
+ BOOTSTRAP_ENTRY="$PWD/$BOOTSTRAP_ENTRY"
107
+ fi
108
+ bootstrap_normalize_path "$BOOTSTRAP_ENTRY" || bootstrap_fail
109
+ BOOTSTRAP_ENTRY="$BOOTSTRAP_NORMALIZED"
110
+ [[ -f "$BOOTSTRAP_ENTRY" && ! -L "$BOOTSTRAP_ENTRY" ]] || bootstrap_fail
111
+ SCRIPT_DIR="${BOOTSTRAP_ENTRY%/*}"
112
+ [[ "${SCRIPT_DIR##*/}" == scripts \
113
+ && "${BOOTSTRAP_ENTRY##*/}" == test-opencode-v2-sandbox.sh ]] || bootstrap_fail
114
+
115
+ SANDBOX_ENV_HELPER="$SCRIPT_DIR/sandbox-env.sh"
116
+ bootstrap_normalize_path "$SANDBOX_ENV_HELPER" || bootstrap_fail
117
+ [[ "$BOOTSTRAP_NORMALIZED" == "$SANDBOX_ENV_HELPER" \
118
+ && -f "$SANDBOX_ENV_HELPER" && ! -L "$SANDBOX_ENV_HELPER" ]] || bootstrap_fail
119
+
120
+ source "$SANDBOX_ENV_HELPER"
121
+ pantheon_validate_sandbox_root "$SANDBOX_ROOT" || exit 2
59
122
  # Derived from this script's own location so the sandbox is always built from
60
123
  # the checkout that CONTAINS this harness. It must never be inferred from a
61
124
  # sibling directory: a sibling may be a different checkout (or a different
62
125
  # branch) with unrelated uncommitted work, and --prepare runs `npm pack` inside
63
126
  # it, writing a tarball into that tree.
64
127
  REPO_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
65
-
66
- SANDBOX_ROOT="${PANTHEON_SANDBOX_ROOT:-$HOME/pantheon-sandbox}"
67
128
  SANDBOX_HOME="$SANDBOX_ROOT/home"
68
129
  NPM_PREFIX="$SANDBOX_HOME/.npm-global"
69
130
 
@@ -137,19 +198,31 @@ sandbox_bin() { # echoes the V2 binary path; rc 1 if missing
137
198
  # ── Sandbox environment isolation ─────────────────────────────────────────────
138
199
 
139
200
  sandbox_env() {
140
- export HOME="$SANDBOX_HOME"
141
- export PATH="$NPM_PREFIX/bin:$HOME/.config/opencode/.venv/bin:$PATH"
142
- export npm_config_prefix="$NPM_PREFIX"
143
- export XDG_STATE_HOME="$SANDBOX_HOME/.local/state"
144
- # Do not inherit an OpenChamber/developer-machine config selector. The V2
145
- # project config is created by prepare_project and is the only config this
146
- # gate is allowed to inspect.
147
- export OPENCODE_CONFIG_DIR="$(dirname "$V2_CONFIG")"
201
+ pantheon_validate_sandbox_config_path "$SANDBOX_ROOT" "$V2_CONFIG" || return $?
202
+ pantheon_validate_sandbox_file_path "$SANDBOX_ROOT" "$V2_DB" || return $?
203
+ pantheon_sandbox_env \
204
+ "$SANDBOX_ROOT" \
205
+ "$SANDBOX_HOME" \
206
+ "$NPM_PREFIX" \
207
+ "$SANDBOX_HOME/.config/opencode/.venv" \
208
+ "$(dirname "$V2_CONFIG")"
148
209
  export OPENCODE_DB="$V2_DB"
210
+ pantheon_validate_sandbox_file_path "$SANDBOX_ROOT" "$OPENCODE_DB" || return $?
149
211
  export PANTHEON_V2_PORT="$V2_PORT"
150
212
  export PORT="$V2_PORT"
151
- unset OPENCODE_CONFIG OPENCODE_CONFIG_CONTENT OPENCODE_CONFIG_PROJECT_DISABLE
213
+ pantheon_validate_sandbox_path "$SANDBOX_ROOT" || return $?
214
+ pantheon_validate_sandbox_config_path "$SANDBOX_ROOT" "$V2_CONFIG" || return $?
215
+ pantheon_validate_sandbox_file_path "$SANDBOX_ROOT" "$V2_DB" || return $?
216
+ pantheon_validate_sandbox_file_path "$SANDBOX_ROOT" "$OPENCODE_DB" || return $?
217
+ pantheon_validate_sandbox_path "$(dirname "$V2_DB")" || return $?
218
+ pantheon_validate_sandbox_path "$(dirname "$V2_SERVICE_STATE")" || return $?
152
219
  mkdir -p "$SANDBOX_ROOT" "$(dirname "$V2_DB")" "$(dirname "$V2_SERVICE_STATE")"
220
+ pantheon_validate_sandbox_path "$SANDBOX_ROOT" || return $?
221
+ pantheon_validate_sandbox_config_path "$SANDBOX_ROOT" "$V2_CONFIG" || return $?
222
+ pantheon_validate_sandbox_file_path "$SANDBOX_ROOT" "$V2_DB" || return $?
223
+ pantheon_validate_sandbox_file_path "$SANDBOX_ROOT" "$OPENCODE_DB" || return $?
224
+ pantheon_validate_sandbox_path "$(dirname "$V2_DB")" || return $?
225
+ pantheon_validate_sandbox_path "$(dirname "$V2_SERVICE_STATE")" || return $?
153
226
  }
154
227
 
155
228
  stop_v2_service() {
@@ -157,6 +230,7 @@ stop_v2_service() {
157
230
  kill "$V2_SERVER_PID" 2>/dev/null || true
158
231
  wait "$V2_SERVER_PID" 2>/dev/null || true
159
232
  fi
233
+ pantheon_validate_sandbox_path "$V2_SERVICE_STATE" || return $?
160
234
  rm -f "$V2_SERVICE_STATE"
161
235
  V2_SERVER_PID=""
162
236
  }
@@ -164,23 +238,22 @@ stop_v2_service() {
164
238
  print_v2_diagnostics() {
165
239
  printf '%s\n' '--- V2 service registration ---' >&2
166
240
  if [ -f "$V2_SERVICE_STATE" ]; then
167
- cat "$V2_SERVICE_STATE" >&2 || true
168
- printf '\n' >&2
241
+ printf '%s\n' 'service registration exists (contents omitted)' >&2
169
242
  else
170
- printf 'missing service registration: %s\n' "$V2_SERVICE_STATE" >&2
243
+ printf '%s\n' 'service registration is missing' >&2
171
244
  fi
172
245
  printf '%s\n' '--- V2 service log ---' >&2
173
246
  if [ -f "$V2_SERVER_LOG" ]; then
174
- tail -200 "$V2_SERVER_LOG" >&2 || true
247
+ printf '%s\n' 'service log exists (contents omitted)' >&2
175
248
  else
176
- printf 'missing service log: %s\n' "$V2_SERVER_LOG" >&2
249
+ printf '%s\n' 'service log is missing' >&2
177
250
  fi
178
- local runtime_log="$HOME/.local/share/opencode/log/opencode.log"
251
+ local runtime_log="$LOG_PATH"
179
252
  printf '%s\n' '--- OpenCode runtime log ---' >&2
180
253
  if [ -f "$runtime_log" ]; then
181
- tail -200 "$runtime_log" >&2 || true
254
+ printf '%s\n' 'runtime log exists (contents omitted)' >&2
182
255
  else
183
- printf 'missing runtime log: %s\n' "$runtime_log" >&2
256
+ printf '%s\n' 'runtime log is missing' >&2
184
257
  fi
185
258
  }
186
259
 
@@ -224,8 +297,7 @@ PY
224
297
  fi
225
298
  sleep 1
226
299
  done
227
- printf 'Timed out after %ss waiting for V2 service registration matching url=%s pid=%s.\n' \
228
- "$V2_HANDSHAKE_TIMEOUT" "$registration_url" "$registration_pid" >&2
300
+ printf '%s\n' 'ERROR: timed out waiting for V2 service registration.' >&2
229
301
  print_v2_diagnostics
230
302
  return 1
231
303
  }
@@ -291,7 +363,7 @@ PY
291
363
  }
292
364
 
293
365
  wait_for_v2_handshakes() {
294
- local runtime_log="$HOME/.local/share/opencode/log/opencode.log"
366
+ local runtime_log="$LOG_PATH"
295
367
  local names=(
296
368
  pantheon-code-mode
297
369
  pantheon-memory
@@ -337,7 +409,14 @@ wait_for_v2_handshakes() {
337
409
  }
338
410
 
339
411
  start_v2_service() { # binary project
340
- local bin="$1" project="$2" ready=0 attempt
412
+ local bin="$1" project="$2" ready=0 attempt runtime_log
413
+ # Re-apply the shared environment at the actual direct-CI launch boundary;
414
+ # do not rely on whichever XDG variables the parent shell inherited.
415
+ sandbox_env || return $?
416
+ runtime_log="$LOG_PATH"
417
+ pantheon_validate_sandbox_config_path "$SANDBOX_ROOT" "$V2_CONFIG" || return $?
418
+ pantheon_validate_sandbox_file_path "$SANDBOX_ROOT" "$V2_DB" || return $?
419
+ pantheon_validate_sandbox_file_path "$SANDBOX_ROOT" "$OPENCODE_DB" || return $?
341
420
  if [ -n "$V2_SERVER_PID" ] && kill -0 "$V2_SERVER_PID" 2>/dev/null; then
342
421
  return 0
343
422
  fi
@@ -350,8 +429,16 @@ start_v2_service() { # binary project
350
429
  die "dedicated V2 port ${V2_PORT} is already in use; refusing to reuse an unrelated service"
351
430
  fi
352
431
 
353
- rm -f "$V2_SERVER_LOG" "$V2_SERVICE_STATE" "$HOME/.local/share/opencode/log/opencode.log"
354
- (cd "$project" && "$bin" serve --hostname "$V2_LOOPBACK_HOST" --port "$V2_PORT" --service) \
432
+ pantheon_validate_sandbox_path "$project" || return $?
433
+ pantheon_validate_sandbox_path "$V2_SERVER_LOG" || return $?
434
+ pantheon_validate_sandbox_path "$V2_SERVICE_STATE" || return $?
435
+ pantheon_validate_sandbox_path "$runtime_log" || return $?
436
+ rm -f "$V2_SERVER_LOG" "$V2_SERVICE_STATE" "$runtime_log"
437
+ (
438
+ sandbox_env || exit $?
439
+ cd "$project"
440
+ exec "$bin" serve --hostname "$V2_LOOPBACK_HOST" --port "$V2_PORT" --service
441
+ ) \
355
442
  >"$V2_SERVER_LOG" 2>&1 &
356
443
  V2_SERVER_PID=$!
357
444
 
@@ -384,67 +471,174 @@ trap stop_v2_service EXIT
384
471
  # ── Gate (b): sandbox run-test.sh with pantheon://agents content validation ──
385
472
 
386
473
  write_run_test_sh() {
474
+ local path expected_repo_q
475
+ pantheon_validate_sandbox_root "$SANDBOX_ROOT" || return $?
476
+ for path in \
477
+ "$SANDBOX_ROOT/.repo-dir" \
478
+ "$SANDBOX_ROOT/sandbox-env.sh" \
479
+ "$SANDBOX_ROOT/run-test.sh" \
480
+ "$SANDBOX_ROOT/start-pantheon.sh"; do
481
+ pantheon_validate_sandbox_path "$path" || return $?
482
+ done
483
+
387
484
  # Quoted heredoc: the body is emitted verbatim, so nothing inside is expanded
388
- # at generation time. REPO_DIR is the one value the body needs, and it is
389
- # handed over as its own generated file instead of a placeholder baked into
390
- # the shell source: interpolating it meant escaping for TWO languages (sed
391
- # replacement text AND the double-quoted shell context it lands in), and only
392
- # the first set was escaped — a path containing `$`, a backtick, a backslash
393
- # or a quote was silently rewritten or executed by the generated script.
485
+ # at generation time. Keep the metadata file for format/integrity checking,
486
+ # but do not trust it as the source selector: the runner below also embeds a
487
+ # safely quoted expected value and requires the file to match it exactly.
394
488
  printf '%s\n' "$REPO_DIR" > "$SANDBOX_ROOT/.repo-dir"
395
- cat > "$SANDBOX_ROOT/run-test.sh" <<'RUNTEST'
396
- #!/usr/bin/env bash
489
+ cp "$SANDBOX_ENV_HELPER" "$SANDBOX_ROOT/sandbox-env.sh"
490
+ # Keep a trusted copy of the generated source path in the runner. Bash's %q
491
+ # emits a shell word (including ANSI-C quoting when needed), so adversarial
492
+ # path characters cannot become code when this assignment is evaluated.
493
+ printf -v expected_repo_q '%q' "$REPO_DIR"
494
+ {
495
+ printf '%s\n' '#!/usr/bin/env bash'
496
+ printf 'EXPECTED_REPO_DIR=%s\n' "$expected_repo_q"
497
+ cat <<'RUNTEST'
397
498
  # Generated by pantheon-opencode scripts/test-opencode-v2-sandbox.sh --prepare
398
499
  # Validates the global install: the V2 binary, exactly 5 connected MCPs, doctor
399
500
  # 0 errors, AND the CONTENT of pantheon://agents (zeus/hermes present).
400
501
  set -euo pipefail
401
502
 
402
- SANDBOX_DIR="$(cd "$(dirname "$0")" && pwd)"
503
+ pantheon_launcher_preflight() {
504
+ local entrypoint="$1" current="/" component helper
505
+ local -a components
506
+ local LC_ALL=C
507
+
508
+ [[ ! "$entrypoint" =~ [[:cntrl:]] ]] || {
509
+ printf '%s\n' 'ERROR: sandbox launcher preflight validation failed.' >&2
510
+ return 2
511
+ }
512
+ if [[ "$entrypoint" != /* ]]; then entrypoint="$PWD/$entrypoint"; fi
513
+ IFS='/' read -r -a components <<< "$entrypoint"
514
+ for component in "${components[@]}"; do
515
+ case "$component" in
516
+ '' | .) continue ;;
517
+ ..)
518
+ printf '%s\n' 'ERROR: sandbox launcher preflight validation failed.' >&2
519
+ return 2
520
+ ;;
521
+ esac
522
+ if [[ "$current" == / ]]; then
523
+ current="/$component"
524
+ else
525
+ current="$current/$component"
526
+ fi
527
+ if [[ -L "$current" ]]; then
528
+ printf '%s\n' 'ERROR: sandbox launcher preflight validation failed.' >&2
529
+ return 2
530
+ fi
531
+ done
532
+
533
+ if [[ ! -f "$current" || -L "$current" ]]; then
534
+ printf '%s\n' 'ERROR: sandbox launcher preflight validation failed.' >&2
535
+ return 2
536
+ fi
537
+ SANDBOX_DIR="${current%/*}"
538
+ [[ -n "$SANDBOX_DIR" ]] || SANDBOX_DIR=/
539
+ if [[ "$SANDBOX_DIR" == / ]]; then
540
+ printf '%s\n' 'ERROR: sandbox launcher preflight validation failed.' >&2
541
+ return 2
542
+ fi
543
+ helper="$SANDBOX_DIR/sandbox-env.sh"
544
+ if [[ ! -f "$helper" || -L "$helper" ]]; then
545
+ printf '%s\n' 'ERROR: sandbox launcher preflight validation failed.' >&2
546
+ return 2
547
+ fi
548
+ SANDBOX_ENV_HELPER="$helper"
549
+ }
550
+
551
+ pantheon_launcher_preflight "$0" || exit $?
552
+ source "$SANDBOX_ENV_HELPER"
553
+ pantheon_validate_sandbox_root "$SANDBOX_DIR" || exit $?
403
554
  SANDBOX_HOME="$SANDBOX_DIR/home"
404
555
  NPM_PREFIX="$SANDBOX_HOME/.npm-global"
405
556
  PANTHEON_GLOBAL="$SANDBOX_HOME/.config/opencode"
406
557
  SANDBOX_VENV="$PANTHEON_GLOBAL/.venv"
407
- # The checkout this harness ran from, written by the generator into the
408
- # .repo-dir file next to this script. It used to be a placeholder baked into
409
- # this line and substituted with sed afterwards, but the sandbox lives outside
410
- # any repo so the value cannot be derived from this file's own location either.
411
- # Reading a file the generator wrote keeps the path out of the shell source, so
412
- # no escaping can be wrong. PANTHEON_REPO may still override it; the generator's
413
- # --reset guard refuses to run when that points inside a repo, so an override
414
- # can never turn this into a repo-wiping target.
415
- REPO_DIR="${PANTHEON_REPO:-$(cat "$SANDBOX_DIR/.repo-dir")}"
558
+ V2_CONFIG="${PANTHEON_V2_CONFIG:-$SANDBOX_DIR/project-v2/opencode.json}"
559
+ V2_DB="${PANTHEON_V2_DB:-$SANDBOX_DIR/opencode-v2.db}"
560
+ pantheon_validate_sandbox_config_path "$SANDBOX_DIR" "$V2_CONFIG" || exit $?
561
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$V2_DB" || exit $?
562
+ # Validate the generated metadata against the trusted path embedded above before
563
+ # using it. Python opens with O_NOFOLLOW and verifies the complete byte stream,
564
+ # avoiding both symlink traversal and shell-read quirks such as ignored NULs.
565
+ # Keep diagnostics value-free: failed opens and validation details are hidden.
566
+ if ! python3 - "$SANDBOX_DIR/.repo-dir" "$EXPECTED_REPO_DIR" 2>/dev/null <<'CHECK_REPO_METADATA'
567
+ import os
568
+ import stat
569
+ import sys
570
+
571
+ metadata_path, expected_text = sys.argv[1:]
572
+ expected = os.fsencode(expected_text)
573
+ if not os.path.isabs(expected) or any(byte < 0x20 or byte == 0x7f for byte in expected):
574
+ raise SystemExit(1)
575
+ no_follow = getattr(os, "O_NOFOLLOW", None)
576
+ if no_follow is None:
577
+ raise SystemExit(1)
578
+ try:
579
+ if not stat.S_ISREG(os.stat(metadata_path, follow_symlinks=False).st_mode):
580
+ raise SystemExit(1)
581
+ descriptor = os.open(metadata_path, os.O_RDONLY | no_follow | os.O_NONBLOCK)
582
+ try:
583
+ if not stat.S_ISREG(os.fstat(descriptor).st_mode):
584
+ raise SystemExit(1)
585
+ content = os.read(descriptor, len(expected) + 2)
586
+ if content != expected + b"\n" or os.read(descriptor, 1):
587
+ raise SystemExit(1)
588
+ finally:
589
+ os.close(descriptor)
590
+ if not os.path.isdir(os.fsdecode(expected)):
591
+ raise SystemExit(1)
592
+ except OSError:
593
+ raise SystemExit(1)
594
+ CHECK_REPO_METADATA
595
+ then
596
+ printf '%s\n' 'ERROR: sandbox repository metadata validation failed.' >&2
597
+ exit 2
598
+ fi
599
+ REPO_DIR="${PANTHEON_REPO:-$EXPECTED_REPO_DIR}"
416
600
 
417
601
  echo "=== Pantheon Sandbox Test (OpenCode V2) ==="
418
- echo "Sandbox: $SANDBOX_DIR"
419
- echo "Repo: $REPO_DIR"
420
602
 
421
- export HOME="$SANDBOX_HOME"
422
- export PATH="$NPM_PREFIX/bin:$SANDBOX_VENV/bin:$PATH"
423
- export npm_config_prefix="$NPM_PREFIX"
424
- export XDG_STATE_HOME="$SANDBOX_HOME/.local/state"
425
603
  # The V2 CLI resolves `mcp list` through its service. Keep generated sandbox
426
604
  # runs isolated from any config/database/port inherited from the host.
427
- V2_CONFIG="$SANDBOX_DIR/project-v2/opencode.json"
428
- V2_DB="${PANTHEON_V2_DB:-$SANDBOX_DIR/opencode-v2.db}"
429
605
  V2_PORT="${PANTHEON_V2_PORT:-49376}"
430
606
  V2_LOOPBACK_HOST="${PANTHEON_V2_HOST:-127.0.0.1}"
431
607
  V2_HANDSHAKE_TIMEOUT="${PANTHEON_V2_HANDSHAKE_TIMEOUT:-60}"
432
608
  V2_MCP_LIST_TIMEOUT="${PANTHEON_V2_MCP_LIST_TIMEOUT:-15}"
609
+ pantheon_validate_sandbox_config_path "$SANDBOX_DIR" "$V2_CONFIG" || exit $?
610
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$V2_DB" || exit $?
611
+ pantheon_sandbox_env \
612
+ "$SANDBOX_DIR" \
613
+ "$SANDBOX_HOME" \
614
+ "$NPM_PREFIX" \
615
+ "$SANDBOX_VENV" \
616
+ "$(dirname "$V2_CONFIG")"
617
+ pantheon_validate_sandbox_config_path "$SANDBOX_DIR" "$V2_CONFIG" || exit $?
618
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$V2_DB" || exit $?
433
619
  V2_SERVER_LOG="$SANDBOX_DIR/v2-server.log"
434
620
  V2_SERVICE_STATE="$SANDBOX_HOME/.local/state/opencode/service.json"
435
621
  V2_SERVER_PID=""
436
- export OPENCODE_CONFIG_DIR="$(dirname "$V2_CONFIG")"
437
622
  export OPENCODE_DB="$V2_DB"
623
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$OPENCODE_DB" || exit $?
438
624
  export PANTHEON_V2_PORT="$V2_PORT"
439
625
  export PORT="$V2_PORT"
440
626
  unset OPENCODE_CONFIG OPENCODE_CONFIG_CONTENT OPENCODE_CONFIG_PROJECT_DISABLE
627
+ pantheon_validate_sandbox_path "$V2_SERVICE_STATE" || exit $?
628
+ pantheon_validate_sandbox_path "$(dirname "$V2_SERVICE_STATE")" || exit $?
441
629
  mkdir -p "$(dirname "$V2_SERVICE_STATE")"
630
+ pantheon_validate_sandbox_config_path "$SANDBOX_DIR" "$V2_CONFIG" || exit $?
631
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$V2_DB" || exit $?
632
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$OPENCODE_DB" || exit $?
633
+ pantheon_validate_sandbox_path "$V2_SERVICE_STATE" || exit $?
634
+ pantheon_validate_sandbox_path "$(dirname "$V2_SERVICE_STATE")" || exit $?
442
635
 
443
636
  stop_v2_service() {
444
637
  if [ -n "$V2_SERVER_PID" ] && kill -0 "$V2_SERVER_PID" 2>/dev/null; then
445
638
  kill "$V2_SERVER_PID" 2>/dev/null || true
446
639
  wait "$V2_SERVER_PID" 2>/dev/null || true
447
640
  fi
641
+ pantheon_validate_sandbox_path "$V2_SERVICE_STATE" || return $?
448
642
  rm -f "$V2_SERVICE_STATE"
449
643
  V2_SERVER_PID=""
450
644
  }
@@ -452,16 +646,24 @@ stop_v2_service() {
452
646
  print_v2_diagnostics() {
453
647
  printf '%s\n' '--- V2 service registration ---' >&2
454
648
  if [ -f "$V2_SERVICE_STATE" ]; then
455
- cat "$V2_SERVICE_STATE" >&2 || true
456
- printf '\n' >&2
649
+ printf '%s\n' 'service registration exists (contents omitted)' >&2
457
650
  else
458
- printf 'missing service registration: %s\n' "$V2_SERVICE_STATE" >&2
651
+ printf '%s\n' 'service registration is missing' >&2
459
652
  fi
460
653
  printf '%s\n' '--- V2 service log ---' >&2
461
- [ -f "$V2_SERVER_LOG" ] && tail -200 "$V2_SERVER_LOG" >&2 || true
462
- local runtime_log="$HOME/.local/share/opencode/log/opencode.log"
654
+ if [ -f "$V2_SERVER_LOG" ]; then
655
+ printf '%s\n' 'service log exists (contents omitted)' >&2
656
+ else
657
+ printf '%s\n' 'service log is missing' >&2
658
+ fi
659
+ local runtime_log
660
+ runtime_log="$LOG_PATH"
463
661
  printf '%s\n' '--- OpenCode runtime log ---' >&2
464
- [ -f "$runtime_log" ] && tail -200 "$runtime_log" >&2 || true
662
+ if [ -f "$runtime_log" ]; then
663
+ printf '%s\n' 'runtime log exists (contents omitted)' >&2
664
+ else
665
+ printf '%s\n' 'runtime log is missing' >&2
666
+ fi
465
667
  }
466
668
 
467
669
  wait_for_v2_service_registration() {
@@ -502,8 +704,7 @@ PY
502
704
  fi
503
705
  sleep 1
504
706
  done
505
- printf 'ERROR: timed out after %ss waiting for V2 service registration matching url=%s pid=%s\n' \
506
- "$V2_HANDSHAKE_TIMEOUT" "$registration_url" "$registration_pid" >&2
707
+ printf '%s\n' 'ERROR: timed out waiting for V2 service registration.' >&2
507
708
  print_v2_diagnostics
508
709
  return 1
509
710
  }
@@ -566,7 +767,10 @@ PY
566
767
  }
567
768
 
568
769
  start_v2_service() {
569
- local bin="$1" project="$2" attempt ready=0
770
+ local bin="$1" project="$2" attempt ready=0 runtime_log
771
+ pantheon_validate_sandbox_config_path "$SANDBOX_DIR" "$V2_CONFIG" || return $?
772
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$V2_DB" || return $?
773
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$OPENCODE_DB" || return $?
570
774
  if [ -n "$V2_SERVER_PID" ] && kill -0 "$V2_SERVER_PID" 2>/dev/null; then
571
775
  return 0
572
776
  fi
@@ -575,7 +779,12 @@ start_v2_service() {
575
779
  echo "ERROR: dedicated V2 port $V2_PORT is already in use" >&2
576
780
  return 1
577
781
  fi
578
- rm -f "$V2_SERVER_LOG" "$V2_SERVICE_STATE" "$HOME/.local/share/opencode/log/opencode.log"
782
+ runtime_log="$LOG_PATH"
783
+ pantheon_validate_sandbox_path "$project" || return $?
784
+ pantheon_validate_sandbox_path "$V2_SERVER_LOG" || return $?
785
+ pantheon_validate_sandbox_path "$V2_SERVICE_STATE" || return $?
786
+ pantheon_validate_sandbox_path "$runtime_log" || return $?
787
+ rm -f "$V2_SERVER_LOG" "$V2_SERVICE_STATE" "$runtime_log"
579
788
  (cd "$project" && "$bin" serve --hostname "$V2_LOOPBACK_HOST" --port "$V2_PORT" --service) \
580
789
  >"$V2_SERVER_LOG" 2>&1 &
581
790
  V2_SERVER_PID=$!
@@ -603,7 +812,8 @@ start_v2_service() {
603
812
  }
604
813
 
605
814
  wait_for_v2_handshakes() {
606
- local runtime_log="$HOME/.local/share/opencode/log/opencode.log"
815
+ local runtime_log
816
+ runtime_log="$LOG_PATH"
607
817
  local names=(pantheon-code-mode pantheon-memory pantheon-persistence pantheon-resources pantheon-vision)
608
818
  local attempt name ready connected_names connected_count
609
819
  for attempt in $(seq 1 "$V2_HANDSHAKE_TIMEOUT"); do
@@ -642,8 +852,9 @@ rewrite_v2_mcp_config() {
642
852
  local config_path="$V2_CONFIG"
643
853
  local runtime_dir="$SANDBOX_DIR/project-v2/.opencode"
644
854
  local python_bin="$SANDBOX_DIR/project-v2/.venv/bin/python3"
645
- [ -f "$config_path" ] || { echo "ERROR: V2 config was not generated: $config_path" >&2; return 1; }
646
- [ -x "$python_bin" ] || { echo "ERROR: V2 MCP Python is missing: $python_bin" >&2; return 1; }
855
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$config_path" || return $?
856
+ [ -f "$config_path" ] || { echo 'ERROR: sandbox config is unavailable.' >&2; return 1; }
857
+ [ -x "$python_bin" ] || { echo 'ERROR: sandbox MCP runtime is unavailable.' >&2; return 1; }
647
858
  CONFIG_PATH="$config_path" RUNTIME_DIR="$runtime_dir" MCP_PYTHON="$python_bin" \
648
859
  python3 - <<'PY'
649
860
  import json
@@ -662,29 +873,44 @@ managed = {
662
873
  }
663
874
  try:
664
875
  config = json.loads(config_path.read_text(encoding="utf-8"))
665
- except (OSError, json.JSONDecodeError) as exc:
666
- raise SystemExit(f"cannot read V2 config {config_path}: {exc}")
876
+ except (OSError, json.JSONDecodeError):
877
+ raise SystemExit("ERROR: sandbox config validation failed.") from None
667
878
  if not isinstance(config, dict):
668
- raise SystemExit(f"V2 config must be an object: {config_path}")
879
+ raise SystemExit("ERROR: sandbox config validation failed.")
669
880
  mcp = config.setdefault("mcp", {})
670
881
  if not isinstance(mcp, dict):
671
- raise SystemExit("V2 config mcp section must be an object")
882
+ raise SystemExit("ERROR: sandbox config validation failed.")
883
+ servers = mcp.setdefault("servers", {})
884
+ if not isinstance(servers, dict):
885
+ raise SystemExit("ERROR: sandbox config validation failed.")
672
886
  for name, script in managed.items():
673
- entry = mcp.get(name) if isinstance(mcp.get(name), dict) else {}
887
+ entry = servers.get(name) if isinstance(servers.get(name), dict) else {}
674
888
  entry.pop("disabled", None)
675
889
  entry.update(type="local", cwd=runtime_dir, command=[python_bin, f"scripts/{script}"], enabled=True)
676
- mcp[name] = entry
890
+ servers[name] = entry
677
891
  tmp_path = config_path.with_name(config_path.name + ".sandbox-tmp")
678
- tmp_path.write_text(json.dumps(config, indent=2) + "\n", encoding="utf-8")
679
- os.replace(tmp_path, config_path)
680
- validated = json.loads(config_path.read_text(encoding="utf-8"))
892
+ try:
893
+ tmp_path.write_text(json.dumps(config, indent=2) + "\n", encoding="utf-8")
894
+ os.replace(tmp_path, config_path)
895
+ except OSError:
896
+ try:
897
+ tmp_path.unlink()
898
+ except OSError:
899
+ pass
900
+ raise SystemExit("ERROR: sandbox config validation failed.") from None
901
+ try:
902
+ validated = json.loads(config_path.read_text(encoding="utf-8"))
903
+ except (OSError, json.JSONDecodeError):
904
+ raise SystemExit("ERROR: sandbox config validation failed.") from None
905
+ if not isinstance(validated, dict):
906
+ raise SystemExit("ERROR: sandbox config validation failed.")
681
907
  for name, script in managed.items():
682
- entry = validated.get("mcp", {}).get(name)
908
+ entry = validated.get("mcp", {}).get("servers", {}).get(name)
683
909
  expected = {"type": "local", "cwd": runtime_dir, "command": [python_bin, f"scripts/{script}"], "enabled": True}
684
910
  if not isinstance(entry, dict) or any(entry.get(key) != value for key, value in expected.items()):
685
- raise SystemExit(f"stale or invalid paths remain for {name} in {config_path}")
911
+ raise SystemExit("ERROR: sandbox MCP validation failed.")
686
912
  if not Path(entry["cwd"]).is_dir() or not Path(entry["command"][0]).is_file() or not (Path(entry["cwd"]) / entry["command"][1]).is_file():
687
- raise SystemExit(f"active sandbox path is missing for {name}: {entry}")
913
+ raise SystemExit("ERROR: sandbox MCP validation failed.")
688
914
  PY
689
915
  }
690
916
 
@@ -724,11 +950,11 @@ check_mcp() { # label binary project
724
950
  local label="$1" bin="$2" project="$3" out connected_count rc=0 list_file list_pid
725
951
  local final_file final_pid final_rc final_count
726
952
  if ! command -v "$bin" >/dev/null 2>&1; then
727
- record_status "$label MCP" "FAIL" "binary '$bin' is not installed in the sandbox prefix"
953
+ record_status "$label MCP" "FAIL" "MCP connectivity check failed"
728
954
  return 0
729
955
  fi
730
956
  if [ ! -d "$project" ]; then
731
- record_status "$label MCP" "FAIL" "project directory is missing: $project"
957
+ record_status "$label MCP" "FAIL" "MCP connectivity check failed"
732
958
  return 0
733
959
  fi
734
960
  if ! start_v2_service "$bin" "$project"; then
@@ -747,9 +973,8 @@ check_mcp() { # label binary project
747
973
  if ! wait_for_v2_mcp_registrations "$project/.opencode" "$project/.venv/bin/python3"; then
748
974
  kill "$list_pid" 2>/dev/null || true
749
975
  wait "$list_pid" 2>/dev/null || true
750
- echo "--- mcp list output (preserved at $list_file) ---" >&2
751
- cat "$list_file" >&2 || true
752
- record_status "$label MCP" "FAIL" "MCP registrations did not match the active sandbox"
976
+ rm -f "$list_file"
977
+ record_status "$label MCP" "FAIL" "MCP registration check failed"
753
978
  return 0
754
979
  fi
755
980
  if wait_for_v2_handshakes; then
@@ -757,9 +982,8 @@ check_mcp() { # label binary project
757
982
  else
758
983
  kill "$list_pid" 2>/dev/null || true
759
984
  wait "$list_pid" 2>/dev/null || true
760
- echo "--- mcp list output (preserved at $list_file) ---" >&2
761
- cat "$list_file" >&2 || true
762
- record_status "$label MCP" "FAIL" "MCP handshakes did not become ready after mcp list started"
985
+ rm -f "$list_file"
986
+ record_status "$label MCP" "FAIL" "MCP connectivity check failed"
763
987
  return 0
764
988
  fi
765
989
  if wait "$list_pid"; then
@@ -767,7 +991,7 @@ check_mcp() { # label binary project
767
991
  else
768
992
  rc=$?
769
993
  fi
770
- out="$(cat "$list_file")"
994
+ out="$(cat "$list_file" 2>/dev/null || true)"
771
995
  rm -f "$list_file"
772
996
  connected_count="$(printf '%s' "$out" | grep -Eic '(^|[^[:alnum:]_])connected([^[:alnum:]_]|$)' || true)"
773
997
  if [ "$rc" -eq 0 ] && [ "$connected_count" -ne 5 ]; then
@@ -783,16 +1007,15 @@ check_mcp() { # label binary project
783
1007
  else
784
1008
  final_rc=$?
785
1009
  fi
786
- out="$(cat "$final_file")"
1010
+ out="$(cat "$final_file" 2>/dev/null || true)"
787
1011
  rm -f "$final_file"
788
1012
  if [ "$final_rc" -ne 0 ]; then
789
1013
  rc="$final_rc"
790
1014
  fi
791
1015
  fi
792
1016
  out="$(printf '%s' "$out" | sed -E $'s/\x1B\\[[0-?]*[ -/]*[@-~]//g')"
793
- printf '%s\n' "$out"
794
1017
  if [ "$rc" -ne 0 ]; then
795
- record_status "$label MCP" "FAIL" "mcp list exited $rc (see output above)"
1018
+ record_status "$label MCP" "FAIL" "MCP connectivity check failed"
796
1019
  return 0
797
1020
  fi
798
1021
  connected_count="$(printf '%s' "$out" | grep -Eic '(^|[^[:alnum:]_])connected([^[:alnum:]_]|$)')" || connected_count=0
@@ -805,7 +1028,7 @@ check_mcp() { # label binary project
805
1028
  && printf '%s' "$out" | grep -Fq 'pantheon-vision'; then
806
1029
  record_status "$label MCP" "PASS" "exactly 5 connected MCPs"
807
1030
  else
808
- record_status "$label MCP" "FAIL" "expected exactly 5 connected MCPs; found $connected_count or failures reported"
1031
+ record_status "$label MCP" "FAIL" "MCP connectivity check failed"
809
1032
  fi
810
1033
  }
811
1034
 
@@ -821,13 +1044,18 @@ npm install -g "$TGZ"
821
1044
  if ! git -C "$REPO_DIR" ls-files --error-unmatch -- "$TGZ" >/dev/null 2>&1; then rm -f -- "$TGZ"; fi
822
1045
 
823
1046
  echo "--- Init (headless) ---"
824
- pantheon-opencode init --headless -y
1047
+ pantheon-opencode init --headless -y \
1048
+ --components agents,skills,instructions,commands,plugins,runtime
825
1049
  rewrite_v2_mcp_config
826
- node "$REPO_DIR/scripts/validate-sandbox-install.mjs" \
1050
+ if ! node "$REPO_DIR/scripts/validate-sandbox-install.mjs" \
827
1051
  --repo "$REPO_DIR" \
828
1052
  --install "$NPM_PREFIX/lib/node_modules/pantheon-opencode" \
829
1053
  --project-config "$V2_CONFIG" \
830
- --config "$PANTHEON_GLOBAL/opencode.json"
1054
+ --config "$PANTHEON_GLOBAL/opencode.json" \
1055
+ >/dev/null 2>&1; then
1056
+ echo 'ERROR: sandbox package/config validation failed.' >&2
1057
+ exit 1
1058
+ fi
831
1059
 
832
1060
  echo "--- MCP Validation ---"
833
1061
  check_mcp "V2" opencode2 "$SANDBOX_DIR/project-v2"
@@ -850,7 +1078,7 @@ fi
850
1078
  echo "--- Gate (b): pantheon://agents CONTENT check ---"
851
1079
  RESOURCES_SRV="$PANTHEON_GLOBAL/scripts/mcp_resources.py"
852
1080
  if [ ! -f "$RESOURCES_SRV" ]; then
853
- record_status "pantheon://agents resource" "FAIL" "resources server not found at $RESOURCES_SRV"
1081
+ record_status "pantheon://agents resource" "FAIL" "resources server is unavailable"
854
1082
  else
855
1083
  set +e
856
1084
  AGENTS_CONTENT="$("$SANDBOX_VENV/bin/python" - "$RESOURCES_SRV" <<'PYEOF'
@@ -889,6 +1117,8 @@ if [ "$FINAL_VERDICT" != "PASS" ]; then
889
1117
  fi
890
1118
  echo "Next: open the isolated TUI with: $SANDBOX_DIR/start-pantheon.sh"
891
1119
  RUNTEST
1120
+ } > "$SANDBOX_ROOT/run-test.sh"
1121
+ pantheon_validate_sandbox_path "$SANDBOX_ROOT/run-test.sh" || return $?
892
1122
  chmod +x "$SANDBOX_ROOT/run-test.sh"
893
1123
 
894
1124
  cat > "$SANDBOX_ROOT/start-pantheon.sh" <<'STARTPANTHEON'
@@ -897,20 +1127,82 @@ RUNTEST
897
1127
  # Launches the installed OpenCode beta with only this sandbox's HOME/config/db.
898
1128
  set -euo pipefail
899
1129
 
900
- SANDBOX_DIR="$(cd "$(dirname "$0")" && pwd)"
1130
+ pantheon_launcher_preflight() {
1131
+ local entrypoint="$1" current="/" component helper
1132
+ local -a components
1133
+ local LC_ALL=C
1134
+
1135
+ [[ ! "$entrypoint" =~ [[:cntrl:]] ]] || {
1136
+ printf '%s\n' 'ERROR: sandbox launcher preflight validation failed.' >&2
1137
+ return 2
1138
+ }
1139
+ if [[ "$entrypoint" != /* ]]; then entrypoint="$PWD/$entrypoint"; fi
1140
+ IFS='/' read -r -a components <<< "$entrypoint"
1141
+ for component in "${components[@]}"; do
1142
+ case "$component" in
1143
+ '' | .) continue ;;
1144
+ ..)
1145
+ printf '%s\n' 'ERROR: sandbox launcher preflight validation failed.' >&2
1146
+ return 2
1147
+ ;;
1148
+ esac
1149
+ if [[ "$current" == / ]]; then
1150
+ current="/$component"
1151
+ else
1152
+ current="$current/$component"
1153
+ fi
1154
+ if [[ -L "$current" ]]; then
1155
+ printf '%s\n' 'ERROR: sandbox launcher preflight validation failed.' >&2
1156
+ return 2
1157
+ fi
1158
+ done
1159
+
1160
+ if [[ ! -f "$current" || -L "$current" ]]; then
1161
+ printf '%s\n' 'ERROR: sandbox launcher preflight validation failed.' >&2
1162
+ return 2
1163
+ fi
1164
+ SANDBOX_DIR="${current%/*}"
1165
+ [[ -n "$SANDBOX_DIR" ]] || SANDBOX_DIR=/
1166
+ if [[ "$SANDBOX_DIR" == / ]]; then
1167
+ printf '%s\n' 'ERROR: sandbox launcher preflight validation failed.' >&2
1168
+ return 2
1169
+ fi
1170
+ helper="$SANDBOX_DIR/sandbox-env.sh"
1171
+ if [[ ! -f "$helper" || -L "$helper" ]]; then
1172
+ printf '%s\n' 'ERROR: sandbox launcher preflight validation failed.' >&2
1173
+ return 2
1174
+ fi
1175
+ SANDBOX_ENV_HELPER="$helper"
1176
+ }
1177
+
1178
+ pantheon_launcher_preflight "$0" || exit $?
1179
+ source "$SANDBOX_ENV_HELPER"
1180
+ pantheon_validate_sandbox_root "$SANDBOX_DIR" || exit $?
901
1181
  SANDBOX_HOME="$SANDBOX_DIR/home"
902
1182
  NPM_PREFIX="$SANDBOX_HOME/.npm-global"
903
1183
  SANDBOX_VENV="$SANDBOX_HOME/.config/opencode/.venv"
904
1184
  V2_PORT="${PANTHEON_V2_PORT:-49376}"
1185
+ V2_CONFIG="${PANTHEON_V2_CONFIG:-$SANDBOX_DIR/project-v2/opencode.json}"
1186
+ V2_DB="${PANTHEON_V2_DB:-$SANDBOX_DIR/opencode-v2.db}"
1187
+ pantheon_validate_sandbox_config_path "$SANDBOX_DIR" "$V2_CONFIG" || exit $?
1188
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$V2_DB" || exit $?
905
1189
  if [[ ! "$V2_PORT" =~ ^[0-9]{1,5}$ ]]; then
906
- echo "ERROR: PANTHEON_V2_PORT must be an integer from 1 through 65535 (got '$V2_PORT')" >&2
1190
+ echo 'ERROR: PANTHEON_V2_PORT must be an integer from 1 through 65535.' >&2
907
1191
  exit 1
908
1192
  fi
909
1193
  V2_PORT=$((10#$V2_PORT))
910
1194
  if [ "$V2_PORT" -lt 1 ] || [ "$V2_PORT" -gt 65535 ]; then
911
- echo "ERROR: PANTHEON_V2_PORT must be an integer from 1 through 65535 (got '$V2_PORT')" >&2
1195
+ echo 'ERROR: PANTHEON_V2_PORT must be an integer from 1 through 65535.' >&2
912
1196
  exit 1
913
1197
  fi
1198
+ pantheon_sandbox_env \
1199
+ "$SANDBOX_DIR" \
1200
+ "$SANDBOX_HOME" \
1201
+ "$NPM_PREFIX" \
1202
+ "$SANDBOX_VENV" \
1203
+ "$(dirname "$V2_CONFIG")"
1204
+ pantheon_validate_sandbox_config_path "$SANDBOX_DIR" "$V2_CONFIG" || exit $?
1205
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$V2_DB" || exit $?
914
1206
  if ! python3 - "$V2_PORT" "$NPM_PREFIX" <<'CHECKPORT'
915
1207
  import errno
916
1208
  import os
@@ -1002,26 +1294,21 @@ then
1002
1294
  exit 1
1003
1295
  fi
1004
1296
 
1005
- export HOME="$SANDBOX_HOME"
1006
- export PATH="$NPM_PREFIX/bin:$SANDBOX_VENV/bin:$PATH"
1007
- export npm_config_prefix="$NPM_PREFIX"
1008
- export XDG_CONFIG_HOME="$SANDBOX_HOME/.config"
1009
- export XDG_CONFIG_DIRS="$SANDBOX_HOME/.config/xdg"
1010
- export XDG_DATA_HOME="$SANDBOX_HOME/.local/share"
1011
- export XDG_DATA_DIRS="$SANDBOX_HOME/.local/share/xdg"
1012
- export XDG_STATE_HOME="$SANDBOX_HOME/.local/state"
1013
- export XDG_CACHE_HOME="$SANDBOX_HOME/.cache"
1014
- export OPENCODE_CONFIG_DIR="$SANDBOX_DIR/project-v2"
1015
- export OPENCODE_DB="${PANTHEON_V2_DB:-$SANDBOX_DIR/opencode-v2.db}"
1297
+ export OPENCODE_DB="$V2_DB"
1298
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$OPENCODE_DB" || exit $?
1016
1299
  export PANTHEON_V2_PORT="$V2_PORT"
1017
1300
  export PORT="$PANTHEON_V2_PORT"
1018
1301
  unset OPENCODE_CONFIG OPENCODE_CONFIG_CONTENT OPENCODE_CONFIG_PROJECT_DISABLE \
1019
1302
  OPENCODE_DATA_DIR OPENCODE_STATE_DIR OPENCODE_CACHE_DIR OPENCODE_STORAGE_PATH
1020
1303
 
1304
+ pantheon_validate_sandbox_config_path "$SANDBOX_DIR" "$V2_CONFIG" || exit $?
1305
+ pantheon_validate_sandbox_file_path "$SANDBOX_DIR" "$V2_DB" || exit $?
1306
+ pantheon_validate_sandbox_path "$SANDBOX_DIR/project-v2" || exit $?
1021
1307
  "$NPM_PREFIX/bin/opencode2" service set port "$V2_PORT"
1022
1308
  cd "$SANDBOX_DIR/project-v2"
1023
1309
  exec "$NPM_PREFIX/bin/opencode2" "$@"
1024
1310
  STARTPANTHEON
1311
+ pantheon_validate_sandbox_path "$SANDBOX_ROOT/start-pantheon.sh" || return $?
1025
1312
  chmod +x "$SANDBOX_ROOT/start-pantheon.sh"
1026
1313
  }
1027
1314
 
@@ -1092,26 +1379,26 @@ cmd_reset() {
1092
1379
  # generated script pack a tarball into it.
1093
1380
  local protected canonical_root canonical_home canonical_protected
1094
1381
  canonical_root="$(canonicalize_path "$SANDBOX_ROOT")" \
1095
- || die "refusing to reset sandbox root that cannot be canonicalized: $SANDBOX_ROOT"
1382
+ || die "refusing to reset unsafe sandbox root"
1096
1383
  canonical_home="$(canonicalize_path "$HOME")" \
1097
- || die "refusing to reset because HOME cannot be canonicalized: $HOME"
1384
+ || die "refusing to reset unsafe sandbox root"
1098
1385
  [ "$canonical_root" != "/" ] \
1099
- || die "refusing to reset unsafe sandbox root: $SANDBOX_ROOT (filesystem root)"
1386
+ || die "refusing to reset unsafe sandbox root"
1100
1387
  [ "$canonical_root" != "$canonical_home" ] \
1101
- || die "refusing to reset unsafe sandbox root: $SANDBOX_ROOT (HOME)"
1388
+ || die "refusing to reset unsafe sandbox root"
1102
1389
  if path_is_same_or_descendant "$canonical_home" "$canonical_root"; then
1103
- die "refusing to reset unsafe sandbox root: $SANDBOX_ROOT (it is an ancestor of HOME $HOME)"
1390
+ die "refusing to reset unsafe sandbox root"
1104
1391
  fi
1105
1392
 
1106
1393
  for protected in "$REPO_DIR" "${PANTHEON_REPO:-}"; do
1107
1394
  [ -n "$protected" ] || continue
1108
1395
  canonical_protected="$(canonicalize_path "$protected")" \
1109
- || die "refusing to reset because protected repo path cannot be canonicalized: $protected"
1396
+ || die "refusing to reset unsafe sandbox root"
1110
1397
  if path_is_same_or_descendant "$canonical_root" "$canonical_protected"; then
1111
- die "refusing to reset unsafe sandbox root: $SANDBOX_ROOT (it is equal to or inside the repo $protected)"
1398
+ die "refusing to reset unsafe sandbox root"
1112
1399
  fi
1113
1400
  if path_is_same_or_descendant "$canonical_protected" "$canonical_root"; then
1114
- die "refusing to reset unsafe sandbox root: $SANDBOX_ROOT (it is an ancestor of the repo $protected)"
1401
+ die "refusing to reset unsafe sandbox root"
1115
1402
  fi
1116
1403
  done
1117
1404
  log "Resetting sandbox: $SANDBOX_ROOT"
@@ -1123,7 +1410,7 @@ install_binaries() {
1123
1410
  local tgz_path
1124
1411
  if [ -n "$SANDBOX_TARBALL" ]; then
1125
1412
  [ -f "$SANDBOX_TARBALL" ] \
1126
- || die "PANTHEON_SANDBOX_TARBALL does not exist: $SANDBOX_TARBALL"
1413
+ || die "sandbox package artifact is unavailable"
1127
1414
  tgz_path="$(cd "$(dirname "$SANDBOX_TARBALL")" && pwd)/$(basename "$SANDBOX_TARBALL")"
1128
1415
  log "--- Installing pantheon-opencode (from supplied release tarball) ---"
1129
1416
  else
@@ -1151,8 +1438,8 @@ prepare_project() {
1151
1438
  pan="$(sandbox_bin_for "pantheon-opencode")" \
1152
1439
  || die "pantheon-opencode not installed in sandbox prefix — run $0 --prepare first"
1153
1440
  log "--- Regenerating config in $dir ---"
1154
- (cd "$dir" && "$pan" init --project --version "$TARGET_VERSION" --model "$PANTHEON_SANDBOX_MODEL" -y) \
1155
- || die "init --project --version $TARGET_VERSION failed in $dir"
1441
+ (cd "$dir" && "$pan" init --project --version "$TARGET_VERSION" --model "$PANTHEON_SANDBOX_MODEL" --components agents,skills,instructions,commands,plugins,runtime -y) \
1442
+ || die "sandbox project initialization failed"
1156
1443
  rewrite_v2_mcp_config
1157
1444
  validate_sandbox_install
1158
1445
  }
@@ -1164,14 +1451,14 @@ prepare_project() {
1164
1451
  rewrite_v2_mcp_config() {
1165
1452
  local runtime_dir="$(project_dir)/.opencode"
1166
1453
  local python_bin="$(project_dir)/.venv/bin/python3"
1167
- [ -f "$V2_CONFIG" ] || die "V2 config was not generated: $V2_CONFIG"
1168
- [ -x "$python_bin" ] || die "V2 MCP Python is missing: $python_bin"
1454
+ pantheon_validate_sandbox_config_path "$SANDBOX_ROOT" "$V2_CONFIG" || return $?
1455
+ [ -f "$V2_CONFIG" ] || die "sandbox config is unavailable"
1456
+ [ -x "$python_bin" ] || die "sandbox MCP runtime is unavailable"
1169
1457
 
1170
1458
  CONFIG_PATH="$V2_CONFIG" RUNTIME_DIR="$runtime_dir" MCP_PYTHON="$python_bin" \
1171
1459
  python3 - <<'PY'
1172
1460
  import json
1173
1461
  import os
1174
- import sys
1175
1462
  from pathlib import Path
1176
1463
 
1177
1464
  config_path = Path(os.environ["CONFIG_PATH"])
@@ -1187,16 +1474,19 @@ managed = {
1187
1474
 
1188
1475
  try:
1189
1476
  config = json.loads(config_path.read_text(encoding="utf-8"))
1190
- except (OSError, json.JSONDecodeError) as exc:
1191
- raise SystemExit(f"cannot read V2 config {config_path}: {exc}")
1477
+ except (OSError, json.JSONDecodeError):
1478
+ raise SystemExit("ERROR: sandbox config validation failed.") from None
1192
1479
  if not isinstance(config, dict):
1193
- raise SystemExit(f"V2 config must be an object: {config_path}")
1480
+ raise SystemExit("ERROR: sandbox config validation failed.")
1194
1481
  mcp = config.setdefault("mcp", {})
1195
1482
  if not isinstance(mcp, dict):
1196
- raise SystemExit("V2 config mcp section must be an object")
1483
+ raise SystemExit("ERROR: sandbox config validation failed.")
1484
+ servers = mcp.setdefault("servers", {})
1485
+ if not isinstance(servers, dict):
1486
+ raise SystemExit("ERROR: sandbox config validation failed.")
1197
1487
 
1198
1488
  for name, script in managed.items():
1199
- entry = mcp.get(name)
1489
+ entry = servers.get(name)
1200
1490
  if not isinstance(entry, dict):
1201
1491
  entry = {}
1202
1492
  # Do not retain command/cwd values from the merged config. These are the
@@ -1208,25 +1498,25 @@ for name, script in managed.items():
1208
1498
  command=[python_bin, f"scripts/{script}"],
1209
1499
  enabled=True,
1210
1500
  )
1211
- mcp[name] = entry
1501
+ servers[name] = entry
1212
1502
 
1213
1503
  tmp_path = config_path.with_name(config_path.name + ".sandbox-tmp")
1214
1504
  try:
1215
1505
  tmp_path.write_text(json.dumps(config, indent=2) + "\n", encoding="utf-8")
1216
1506
  os.replace(tmp_path, config_path)
1217
- except OSError as exc:
1507
+ except OSError:
1218
1508
  try:
1219
1509
  tmp_path.unlink()
1220
1510
  except OSError:
1221
1511
  pass
1222
- raise SystemExit(f"cannot rewrite V2 config {config_path}: {exc}")
1512
+ raise SystemExit("ERROR: sandbox config validation failed.") from None
1223
1513
 
1224
1514
  try:
1225
1515
  validated = json.loads(config_path.read_text(encoding="utf-8"))
1226
- except (OSError, json.JSONDecodeError) as exc:
1227
- raise SystemExit(f"cannot validate rewritten V2 config {config_path}: {exc}")
1516
+ except (OSError, json.JSONDecodeError):
1517
+ raise SystemExit("ERROR: sandbox config validation failed.") from None
1228
1518
  for name, script in managed.items():
1229
- entry = validated.get("mcp", {}).get(name)
1519
+ entry = validated.get("mcp", {}).get("servers", {}).get(name)
1230
1520
  expected = {
1231
1521
  "type": "local",
1232
1522
  "cwd": runtime_dir,
@@ -1234,11 +1524,11 @@ for name, script in managed.items():
1234
1524
  "enabled": True,
1235
1525
  }
1236
1526
  if not isinstance(entry, dict) or any(entry.get(key) != value for key, value in expected.items()):
1237
- raise SystemExit(f"stale or invalid paths remain for {name} in {config_path}")
1527
+ raise SystemExit("ERROR: sandbox MCP validation failed.")
1238
1528
  if not Path(entry["cwd"]).is_dir() or not Path(entry["command"][0]).is_file():
1239
- raise SystemExit(f"active sandbox path is missing for {name}: {entry}")
1529
+ raise SystemExit("ERROR: sandbox MCP validation failed.")
1240
1530
  if not (Path(entry["cwd"]) / entry["command"][1]).is_file():
1241
- raise SystemExit(f"active sandbox MCP script is missing for {name}: {entry}")
1531
+ raise SystemExit("ERROR: sandbox MCP validation failed.")
1242
1532
  PY
1243
1533
  }
1244
1534
 
@@ -1248,19 +1538,24 @@ validate_sandbox_install() {
1248
1538
  --install "$NPM_PREFIX/lib/node_modules/pantheon-opencode" \
1249
1539
  --project-config "$V2_CONFIG" \
1250
1540
  --config "$SANDBOX_HOME/.config/opencode/opencode.json" \
1541
+ >/dev/null 2>&1 \
1251
1542
  || die "sandbox package/config validation failed"
1252
1543
  }
1253
1544
 
1254
1545
  cmd_prepare() {
1546
+ sandbox_env
1547
+ pantheon_validate_sandbox_path "$NPM_PREFIX" || die "invalid sandbox path"
1255
1548
  mkdir -p "$SANDBOX_HOME" "$NPM_PREFIX"
1549
+ pantheon_validate_sandbox_path "$NPM_PREFIX" || die "invalid sandbox path"
1256
1550
  write_run_test_sh
1257
- sandbox_env
1258
1551
  install_binaries
1259
1552
  local pan
1260
1553
  pan="$(sandbox_bin_for "pantheon-opencode")" \
1261
1554
  || die "pantheon-opencode not found in sandbox prefix after install"
1262
- log "--- Headless init (global venv + runtime) ---"
1263
- "$pan" init --headless -y --model "$PANTHEON_SANDBOX_MODEL" \
1555
+ log "--- Headless init (default components + runtime) ---"
1556
+ "$pan" init --headless -y \
1557
+ --components agents,skills,instructions,commands,plugins,runtime \
1558
+ --model "$PANTHEON_SANDBOX_MODEL" \
1264
1559
  || die "pantheon-opencode init --headless failed"
1265
1560
  prepare_project
1266
1561
  write_extract_py
@@ -1407,10 +1702,11 @@ run_prompt() { # v idx current_bin — exactly one attempt
1407
1702
  }
1408
1703
 
1409
1704
  check_mcp_list() { # v
1410
- local v="$1" bin out connected_count rc=0 last_out='' last_rc=0
1705
+ local v="$1" bin out connected_count rc=0
1411
1706
  local list_file list_pid final_file final_pid final_rc
1412
1707
  if ! bin="$(sandbox_bin)"; then
1413
- record "$v" "mcp-list" "FAIL" "binary not installed in sandbox prefix"
1708
+ printf '%s\n' 'MCP connectivity check failed' >&2
1709
+ record "$v" "mcp-list" "FAIL" "MCP connectivity check failed"
1414
1710
  return 0
1415
1711
  fi
1416
1712
  if ! start_v2_service "$bin" "$(project_dir)"; then
@@ -1428,7 +1724,8 @@ check_mcp_list() { # v
1428
1724
  kill "$list_pid" 2>/dev/null || true
1429
1725
  wait "$list_pid" 2>/dev/null || true
1430
1726
  rm -f "$list_file"
1431
- record "$v" "mcp-list" "FAIL" "MCP registrations did not match the active sandbox"
1727
+ printf '%s\n' 'MCP registration check failed' >&2
1728
+ record "$v" "mcp-list" "FAIL" "MCP registration check failed"
1432
1729
  return 0
1433
1730
  fi
1434
1731
  if wait_for_v2_handshakes; then
@@ -1437,7 +1734,8 @@ check_mcp_list() { # v
1437
1734
  kill "$list_pid" 2>/dev/null || true
1438
1735
  wait "$list_pid" 2>/dev/null || true
1439
1736
  rm -f "$list_file"
1440
- record "$v" "mcp-list" "FAIL" "MCP handshakes did not become ready after mcp list started"
1737
+ printf '%s\n' 'MCP connectivity check failed' >&2
1738
+ record "$v" "mcp-list" "FAIL" "MCP connectivity check failed"
1441
1739
  return 0
1442
1740
  fi
1443
1741
  if wait "$list_pid"; then
@@ -1445,7 +1743,7 @@ check_mcp_list() { # v
1445
1743
  else
1446
1744
  rc=$?
1447
1745
  fi
1448
- out="$(cat "$list_file")"
1746
+ out="$(cat "$list_file" 2>/dev/null || true)"
1449
1747
  rm -f "$list_file"
1450
1748
  connected_count="$(printf '%s' "$out" | grep -Eic '(^|[^[:alnum:]_])connected([^[:alnum:]_]|$)' || true)"
1451
1749
  if [ "$rc" -eq 0 ] && [ "$connected_count" -ne 5 ]; then
@@ -1461,15 +1759,13 @@ check_mcp_list() { # v
1461
1759
  else
1462
1760
  final_rc=$?
1463
1761
  fi
1464
- out="$(cat "$final_file")"
1762
+ out="$(cat "$final_file" 2>/dev/null || true)"
1465
1763
  rm -f "$final_file"
1466
1764
  if [ "$final_rc" -ne 0 ]; then
1467
1765
  rc="$final_rc"
1468
1766
  fi
1469
1767
  fi
1470
1768
  out="$(printf '%s' "$out" | sed -E $'s/\x1B\\[[0-?]*[ -/]*[@-~]//g')"
1471
- last_out="$out"
1472
- last_rc="$rc"
1473
1769
  connected_count="$(printf '%s' "$out" | grep -Eic '(^|[^[:alnum:]_])connected([^[:alnum:]_]|$)' || true)"
1474
1770
  if [ "$rc" -eq 0 ] \
1475
1771
  && [ "$connected_count" -eq 5 ] \
@@ -1479,18 +1775,13 @@ check_mcp_list() { # v
1479
1775
  && printf '%s' "$out" | grep -Fq 'pantheon-persistence' \
1480
1776
  && printf '%s' "$out" | grep -Fq 'pantheon-resources' \
1481
1777
  && printf '%s' "$out" | grep -Fq 'pantheon-vision'; then
1482
- printf '%s\n' "$out"
1483
1778
  record "$v" "mcp-list" "PASS" "exactly 5 connected MCPs"
1484
1779
  return 0
1485
1780
  fi
1486
1781
 
1487
- printf '%s\n' '--- mcp list output (last attempt) ---' >&2
1488
- printf '%s\n' "$last_out" >&2
1489
- printf 'mcp list exit=%s; connected=%s; expected exactly 5\n' \
1490
- "$last_rc" "$connected_count" >&2
1782
+ printf '%s\n' 'MCP connectivity check failed' >&2
1491
1783
  print_v2_diagnostics
1492
- record "$v" "mcp-list" "FAIL" \
1493
- "expected exactly 5 connected MCPs; last exit $last_rc found $connected_count"
1784
+ record "$v" "mcp-list" "FAIL" "MCP connectivity check failed"
1494
1785
  }
1495
1786
 
1496
1787
  check_doctor() { # v