@made-by-moonlight/athene-cli 0.9.2

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 (315) hide show
  1. package/LICENSE +22 -0
  2. package/dist/assets/plugin-registry.json +67 -0
  3. package/dist/assets/scripts/athene-doctor.ps1 +352 -0
  4. package/dist/assets/scripts/athene-doctor.sh +552 -0
  5. package/dist/assets/scripts/athene-update.ps1 +224 -0
  6. package/dist/assets/scripts/athene-update.sh +252 -0
  7. package/dist/commands/completion.d.ts +3 -0
  8. package/dist/commands/completion.d.ts.map +1 -0
  9. package/dist/commands/completion.js +26 -0
  10. package/dist/commands/completion.js.map +1 -0
  11. package/dist/commands/config.d.ts +11 -0
  12. package/dist/commands/config.d.ts.map +1 -0
  13. package/dist/commands/config.js +89 -0
  14. package/dist/commands/config.js.map +1 -0
  15. package/dist/commands/dashboard.d.ts +3 -0
  16. package/dist/commands/dashboard.d.ts.map +1 -0
  17. package/dist/commands/dashboard.js +103 -0
  18. package/dist/commands/dashboard.js.map +1 -0
  19. package/dist/commands/doctor.d.ts +3 -0
  20. package/dist/commands/doctor.d.ts.map +1 -0
  21. package/dist/commands/doctor.js +329 -0
  22. package/dist/commands/doctor.js.map +1 -0
  23. package/dist/commands/events.d.ts +3 -0
  24. package/dist/commands/events.d.ts.map +1 -0
  25. package/dist/commands/events.js +172 -0
  26. package/dist/commands/events.js.map +1 -0
  27. package/dist/commands/migrate-storage.d.ts +3 -0
  28. package/dist/commands/migrate-storage.d.ts.map +1 -0
  29. package/dist/commands/migrate-storage.js +78 -0
  30. package/dist/commands/migrate-storage.js.map +1 -0
  31. package/dist/commands/notify.d.ts +3 -0
  32. package/dist/commands/notify.d.ts.map +1 -0
  33. package/dist/commands/notify.js +143 -0
  34. package/dist/commands/notify.js.map +1 -0
  35. package/dist/commands/open.d.ts +3 -0
  36. package/dist/commands/open.d.ts.map +1 -0
  37. package/dist/commands/open.js +167 -0
  38. package/dist/commands/open.js.map +1 -0
  39. package/dist/commands/plugin.d.ts +3 -0
  40. package/dist/commands/plugin.d.ts.map +1 -0
  41. package/dist/commands/plugin.js +462 -0
  42. package/dist/commands/plugin.js.map +1 -0
  43. package/dist/commands/project.d.ts +3 -0
  44. package/dist/commands/project.d.ts.map +1 -0
  45. package/dist/commands/project.js +143 -0
  46. package/dist/commands/project.js.map +1 -0
  47. package/dist/commands/report.d.ts +19 -0
  48. package/dist/commands/report.d.ts.map +1 -0
  49. package/dist/commands/report.js +114 -0
  50. package/dist/commands/report.js.map +1 -0
  51. package/dist/commands/review-check.d.ts +3 -0
  52. package/dist/commands/review-check.d.ts.map +1 -0
  53. package/dist/commands/review-check.js +122 -0
  54. package/dist/commands/review-check.js.map +1 -0
  55. package/dist/commands/review.d.ts +3 -0
  56. package/dist/commands/review.d.ts.map +1 -0
  57. package/dist/commands/review.js +215 -0
  58. package/dist/commands/review.js.map +1 -0
  59. package/dist/commands/send.d.ts +3 -0
  60. package/dist/commands/send.d.ts.map +1 -0
  61. package/dist/commands/send.js +187 -0
  62. package/dist/commands/send.js.map +1 -0
  63. package/dist/commands/session.d.ts +3 -0
  64. package/dist/commands/session.d.ts.map +1 -0
  65. package/dist/commands/session.js +439 -0
  66. package/dist/commands/session.js.map +1 -0
  67. package/dist/commands/setup.d.ts +5 -0
  68. package/dist/commands/setup.d.ts.map +1 -0
  69. package/dist/commands/setup.js +297 -0
  70. package/dist/commands/setup.js.map +1 -0
  71. package/dist/commands/spawn.d.ts +4 -0
  72. package/dist/commands/spawn.d.ts.map +1 -0
  73. package/dist/commands/spawn.js +436 -0
  74. package/dist/commands/spawn.js.map +1 -0
  75. package/dist/commands/start.d.ts +21 -0
  76. package/dist/commands/start.d.ts.map +1 -0
  77. package/dist/commands/start.js +1836 -0
  78. package/dist/commands/start.js.map +1 -0
  79. package/dist/commands/status.d.ts +3 -0
  80. package/dist/commands/status.d.ts.map +1 -0
  81. package/dist/commands/status.js +556 -0
  82. package/dist/commands/status.js.map +1 -0
  83. package/dist/commands/update.d.ts +15 -0
  84. package/dist/commands/update.d.ts.map +1 -0
  85. package/dist/commands/update.js +652 -0
  86. package/dist/commands/update.js.map +1 -0
  87. package/dist/commands/verify.d.ts +3 -0
  88. package/dist/commands/verify.d.ts.map +1 -0
  89. package/dist/commands/verify.js +131 -0
  90. package/dist/commands/verify.js.map +1 -0
  91. package/dist/index.d.ts +3 -0
  92. package/dist/index.d.ts.map +1 -0
  93. package/dist/index.js +24 -0
  94. package/dist/index.js.map +1 -0
  95. package/dist/lib/bun-tmp-janitor.d.ts +18 -0
  96. package/dist/lib/bun-tmp-janitor.d.ts.map +1 -0
  97. package/dist/lib/bun-tmp-janitor.js +127 -0
  98. package/dist/lib/bun-tmp-janitor.js.map +1 -0
  99. package/dist/lib/caller-context.d.ts +13 -0
  100. package/dist/lib/caller-context.d.ts.map +1 -0
  101. package/dist/lib/caller-context.js +20 -0
  102. package/dist/lib/caller-context.js.map +1 -0
  103. package/dist/lib/cli-errors.d.ts +8 -0
  104. package/dist/lib/cli-errors.d.ts.map +1 -0
  105. package/dist/lib/cli-errors.js +20 -0
  106. package/dist/lib/cli-errors.js.map +1 -0
  107. package/dist/lib/completion.d.ts +13 -0
  108. package/dist/lib/completion.d.ts.map +1 -0
  109. package/dist/lib/completion.js +428 -0
  110. package/dist/lib/completion.js.map +1 -0
  111. package/dist/lib/composio-setup.d.ts +65 -0
  112. package/dist/lib/composio-setup.d.ts.map +1 -0
  113. package/dist/lib/composio-setup.js +3255 -0
  114. package/dist/lib/composio-setup.js.map +1 -0
  115. package/dist/lib/config-instruction.d.ts +2 -0
  116. package/dist/lib/config-instruction.d.ts.map +1 -0
  117. package/dist/lib/config-instruction.js +193 -0
  118. package/dist/lib/config-instruction.js.map +1 -0
  119. package/dist/lib/constants.d.ts +3 -0
  120. package/dist/lib/constants.d.ts.map +1 -0
  121. package/dist/lib/constants.js +3 -0
  122. package/dist/lib/constants.js.map +1 -0
  123. package/dist/lib/create-session-manager.d.ts +26 -0
  124. package/dist/lib/create-session-manager.d.ts.map +1 -0
  125. package/dist/lib/create-session-manager.js +55 -0
  126. package/dist/lib/create-session-manager.js.map +1 -0
  127. package/dist/lib/credential-resolver.d.ts +37 -0
  128. package/dist/lib/credential-resolver.d.ts.map +1 -0
  129. package/dist/lib/credential-resolver.js +105 -0
  130. package/dist/lib/credential-resolver.js.map +1 -0
  131. package/dist/lib/daemon.d.ts +69 -0
  132. package/dist/lib/daemon.d.ts.map +1 -0
  133. package/dist/lib/daemon.js +77 -0
  134. package/dist/lib/daemon.js.map +1 -0
  135. package/dist/lib/dashboard-rebuild.d.ts +53 -0
  136. package/dist/lib/dashboard-rebuild.d.ts.map +1 -0
  137. package/dist/lib/dashboard-rebuild.js +188 -0
  138. package/dist/lib/dashboard-rebuild.js.map +1 -0
  139. package/dist/lib/dashboard-setup.d.ts +14 -0
  140. package/dist/lib/dashboard-setup.d.ts.map +1 -0
  141. package/dist/lib/dashboard-setup.js +192 -0
  142. package/dist/lib/dashboard-setup.js.map +1 -0
  143. package/dist/lib/dashboard-url.d.ts +19 -0
  144. package/dist/lib/dashboard-url.d.ts.map +1 -0
  145. package/dist/lib/dashboard-url.js +25 -0
  146. package/dist/lib/dashboard-url.js.map +1 -0
  147. package/dist/lib/desktop-setup.d.ts +21 -0
  148. package/dist/lib/desktop-setup.d.ts.map +1 -0
  149. package/dist/lib/desktop-setup.js +556 -0
  150. package/dist/lib/desktop-setup.js.map +1 -0
  151. package/dist/lib/detect-agent.d.ts +24 -0
  152. package/dist/lib/detect-agent.d.ts.map +1 -0
  153. package/dist/lib/detect-agent.js +69 -0
  154. package/dist/lib/detect-agent.js.map +1 -0
  155. package/dist/lib/detect-env.d.ts +14 -0
  156. package/dist/lib/detect-env.d.ts.map +1 -0
  157. package/dist/lib/detect-env.js +46 -0
  158. package/dist/lib/detect-env.js.map +1 -0
  159. package/dist/lib/discord-setup.d.ts +20 -0
  160. package/dist/lib/discord-setup.d.ts.map +1 -0
  161. package/dist/lib/discord-setup.js +584 -0
  162. package/dist/lib/discord-setup.js.map +1 -0
  163. package/dist/lib/format.d.ts +11 -0
  164. package/dist/lib/format.d.ts.map +1 -0
  165. package/dist/lib/format.js +116 -0
  166. package/dist/lib/format.js.map +1 -0
  167. package/dist/lib/git-utils.d.ts +14 -0
  168. package/dist/lib/git-utils.d.ts.map +1 -0
  169. package/dist/lib/git-utils.js +45 -0
  170. package/dist/lib/git-utils.js.map +1 -0
  171. package/dist/lib/install-helpers.d.ts +24 -0
  172. package/dist/lib/install-helpers.d.ts.map +1 -0
  173. package/dist/lib/install-helpers.js +76 -0
  174. package/dist/lib/install-helpers.js.map +1 -0
  175. package/dist/lib/lifecycle-service.d.ts +11 -0
  176. package/dist/lib/lifecycle-service.d.ts.map +1 -0
  177. package/dist/lib/lifecycle-service.js +65 -0
  178. package/dist/lib/lifecycle-service.js.map +1 -0
  179. package/dist/lib/notifier-routing.d.ts +35 -0
  180. package/dist/lib/notifier-routing.d.ts.map +1 -0
  181. package/dist/lib/notifier-routing.js +133 -0
  182. package/dist/lib/notifier-routing.js.map +1 -0
  183. package/dist/lib/notify-test.d.ts +72 -0
  184. package/dist/lib/notify-test.d.ts.map +1 -0
  185. package/dist/lib/notify-test.js +674 -0
  186. package/dist/lib/notify-test.js.map +1 -0
  187. package/dist/lib/openclaw-probe.d.ts +38 -0
  188. package/dist/lib/openclaw-probe.d.ts.map +1 -0
  189. package/dist/lib/openclaw-probe.js +146 -0
  190. package/dist/lib/openclaw-probe.js.map +1 -0
  191. package/dist/lib/openclaw-setup.d.ts +19 -0
  192. package/dist/lib/openclaw-setup.d.ts.map +1 -0
  193. package/dist/lib/openclaw-setup.js +684 -0
  194. package/dist/lib/openclaw-setup.js.map +1 -0
  195. package/dist/lib/path-equality.d.ts +29 -0
  196. package/dist/lib/path-equality.d.ts.map +1 -0
  197. package/dist/lib/path-equality.js +52 -0
  198. package/dist/lib/path-equality.js.map +1 -0
  199. package/dist/lib/plugin-marketplace.d.ts +24 -0
  200. package/dist/lib/plugin-marketplace.d.ts.map +1 -0
  201. package/dist/lib/plugin-marketplace.js +175 -0
  202. package/dist/lib/plugin-marketplace.js.map +1 -0
  203. package/dist/lib/plugin-scaffold.d.ts +14 -0
  204. package/dist/lib/plugin-scaffold.d.ts.map +1 -0
  205. package/dist/lib/plugin-scaffold.js +174 -0
  206. package/dist/lib/plugin-scaffold.js.map +1 -0
  207. package/dist/lib/plugin-store.d.ts +9 -0
  208. package/dist/lib/plugin-store.d.ts.map +1 -0
  209. package/dist/lib/plugin-store.js +121 -0
  210. package/dist/lib/plugin-store.js.map +1 -0
  211. package/dist/lib/plugins.d.ts +17 -0
  212. package/dist/lib/plugins.d.ts.map +1 -0
  213. package/dist/lib/plugins.js +65 -0
  214. package/dist/lib/plugins.js.map +1 -0
  215. package/dist/lib/portfolio-display.d.ts +10 -0
  216. package/dist/lib/portfolio-display.d.ts.map +1 -0
  217. package/dist/lib/portfolio-display.js +17 -0
  218. package/dist/lib/portfolio-display.js.map +1 -0
  219. package/dist/lib/preflight.d.ts +27 -0
  220. package/dist/lib/preflight.d.ts.map +1 -0
  221. package/dist/lib/preflight.js +77 -0
  222. package/dist/lib/preflight.js.map +1 -0
  223. package/dist/lib/prevent-sleep.d.ts +34 -0
  224. package/dist/lib/prevent-sleep.d.ts.map +1 -0
  225. package/dist/lib/prevent-sleep.js +65 -0
  226. package/dist/lib/prevent-sleep.js.map +1 -0
  227. package/dist/lib/project-detection.d.ts +11 -0
  228. package/dist/lib/project-detection.d.ts.map +1 -0
  229. package/dist/lib/project-detection.js +206 -0
  230. package/dist/lib/project-detection.js.map +1 -0
  231. package/dist/lib/project-resolution.d.ts +10 -0
  232. package/dist/lib/project-resolution.d.ts.map +1 -0
  233. package/dist/lib/project-resolution.js +17 -0
  234. package/dist/lib/project-resolution.js.map +1 -0
  235. package/dist/lib/project-supervisor.d.ts +28 -0
  236. package/dist/lib/project-supervisor.d.ts.map +1 -0
  237. package/dist/lib/project-supervisor.js +167 -0
  238. package/dist/lib/project-supervisor.js.map +1 -0
  239. package/dist/lib/prompts.d.ts +7 -0
  240. package/dist/lib/prompts.d.ts.map +1 -0
  241. package/dist/lib/prompts.js +37 -0
  242. package/dist/lib/prompts.js.map +1 -0
  243. package/dist/lib/repo-utils.d.ts +16 -0
  244. package/dist/lib/repo-utils.d.ts.map +1 -0
  245. package/dist/lib/repo-utils.js +26 -0
  246. package/dist/lib/repo-utils.js.map +1 -0
  247. package/dist/lib/resolve-project.d.ts +113 -0
  248. package/dist/lib/resolve-project.d.ts.map +1 -0
  249. package/dist/lib/resolve-project.js +433 -0
  250. package/dist/lib/resolve-project.js.map +1 -0
  251. package/dist/lib/routes.d.ts +2 -0
  252. package/dist/lib/routes.d.ts.map +1 -0
  253. package/dist/lib/routes.js +5 -0
  254. package/dist/lib/routes.js.map +1 -0
  255. package/dist/lib/running-state.d.ts +76 -0
  256. package/dist/lib/running-state.d.ts.map +1 -0
  257. package/dist/lib/running-state.js +338 -0
  258. package/dist/lib/running-state.js.map +1 -0
  259. package/dist/lib/script-runner.d.ts +10 -0
  260. package/dist/lib/script-runner.d.ts.map +1 -0
  261. package/dist/lib/script-runner.js +189 -0
  262. package/dist/lib/script-runner.js.map +1 -0
  263. package/dist/lib/session-utils.d.ts +14 -0
  264. package/dist/lib/session-utils.d.ts.map +1 -0
  265. package/dist/lib/session-utils.js +58 -0
  266. package/dist/lib/session-utils.js.map +1 -0
  267. package/dist/lib/shell.d.ts +17 -0
  268. package/dist/lib/shell.d.ts.map +1 -0
  269. package/dist/lib/shell.js +90 -0
  270. package/dist/lib/shell.js.map +1 -0
  271. package/dist/lib/shutdown.d.ts +30 -0
  272. package/dist/lib/shutdown.d.ts.map +1 -0
  273. package/dist/lib/shutdown.js +177 -0
  274. package/dist/lib/shutdown.js.map +1 -0
  275. package/dist/lib/slack-setup.d.ts +17 -0
  276. package/dist/lib/slack-setup.d.ts.map +1 -0
  277. package/dist/lib/slack-setup.js +485 -0
  278. package/dist/lib/slack-setup.js.map +1 -0
  279. package/dist/lib/startup-preflight.d.ts +36 -0
  280. package/dist/lib/startup-preflight.d.ts.map +1 -0
  281. package/dist/lib/startup-preflight.js +273 -0
  282. package/dist/lib/startup-preflight.js.map +1 -0
  283. package/dist/lib/update-channel-onboarding.d.ts +52 -0
  284. package/dist/lib/update-channel-onboarding.d.ts.map +1 -0
  285. package/dist/lib/update-channel-onboarding.js +107 -0
  286. package/dist/lib/update-channel-onboarding.js.map +1 -0
  287. package/dist/lib/update-check.d.ts +161 -0
  288. package/dist/lib/update-check.d.ts.map +1 -0
  289. package/dist/lib/update-check.js +504 -0
  290. package/dist/lib/update-check.js.map +1 -0
  291. package/dist/lib/web-dir.d.ts +47 -0
  292. package/dist/lib/web-dir.d.ts.map +1 -0
  293. package/dist/lib/web-dir.js +179 -0
  294. package/dist/lib/web-dir.js.map +1 -0
  295. package/dist/lib/webhook-setup.d.ts +16 -0
  296. package/dist/lib/webhook-setup.d.ts.map +1 -0
  297. package/dist/lib/webhook-setup.js +383 -0
  298. package/dist/lib/webhook-setup.js.map +1 -0
  299. package/dist/options/version.d.ts +2 -0
  300. package/dist/options/version.d.ts.map +1 -0
  301. package/dist/options/version.js +7 -0
  302. package/dist/options/version.js.map +1 -0
  303. package/dist/program.d.ts +3 -0
  304. package/dist/program.d.ts.map +1 -0
  305. package/dist/program.js +63 -0
  306. package/dist/program.js.map +1 -0
  307. package/package.json +80 -0
  308. package/templates/rules/base.md +4 -0
  309. package/templates/rules/go.md +8 -0
  310. package/templates/rules/javascript.md +4 -0
  311. package/templates/rules/nextjs.md +7 -0
  312. package/templates/rules/pnpm-workspaces.md +4 -0
  313. package/templates/rules/python.md +8 -0
  314. package/templates/rules/react.md +8 -0
  315. package/templates/rules/typescript.md +6 -0
@@ -0,0 +1,552 @@
1
+ #!/bin/bash
2
+
3
+ set -uo pipefail
4
+
5
+ FIX_MODE=false
6
+
7
+ while [ $# -gt 0 ]; do
8
+ case "$1" in
9
+ --fix)
10
+ FIX_MODE=true
11
+ ;;
12
+ -h|--help)
13
+ cat <<'EOF'
14
+ Usage: athene doctor [--fix]
15
+
16
+ Checks install, PATH, binaries, service health, web terminal support, stale temp files, and runtime sanity.
17
+
18
+ Options:
19
+ --fix Apply safe fixes for missing launcher links, missing support dirs, node-pty spawn-helper permissions, and stale temp files
20
+ EOF
21
+ exit 0
22
+ ;;
23
+ *)
24
+ printf 'Unknown option: %s\n' "$1" >&2
25
+ exit 1
26
+ ;;
27
+ esac
28
+ shift
29
+ done
30
+
31
+ REPO_ROOT="${AO_REPO_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
32
+ SCRIPT_LAYOUT="${AO_SCRIPT_LAYOUT:-}"
33
+ if [ -z "$SCRIPT_LAYOUT" ]; then
34
+ if [ -f "$REPO_ROOT/package.json" ] && [ -f "$REPO_ROOT/dist/index.js" ] && [ ! -d "$REPO_ROOT/packages" ]; then
35
+ SCRIPT_LAYOUT="package-install"
36
+ else
37
+ SCRIPT_LAYOUT="source-checkout"
38
+ fi
39
+ fi
40
+ DEFAULT_CONFIG_HOME="${HOME:-$REPO_ROOT}"
41
+ PASS_COUNT=0
42
+ WARN_COUNT=0
43
+ FAIL_COUNT=0
44
+ FIX_COUNT=0
45
+
46
+ pass() {
47
+ PASS_COUNT=$((PASS_COUNT + 1))
48
+ printf 'PASS %s\n' "$1"
49
+ }
50
+
51
+ warn() {
52
+ WARN_COUNT=$((WARN_COUNT + 1))
53
+ printf 'WARN %s\n' "$1"
54
+ }
55
+
56
+ fail() {
57
+ FAIL_COUNT=$((FAIL_COUNT + 1))
58
+ printf 'FAIL %s\n' "$1"
59
+ }
60
+
61
+ fixed() {
62
+ FIX_COUNT=$((FIX_COUNT + 1))
63
+ printf 'FIXED %s\n' "$1"
64
+ }
65
+
66
+ strip_ansi() {
67
+ sed -E $'s/\x1B\\[[0-9;]*[A-Za-z]//g'
68
+ }
69
+
70
+ expand_home() {
71
+ case "$1" in
72
+ ~/*)
73
+ printf '%s/%s' "$DEFAULT_CONFIG_HOME" "${1#~/}"
74
+ ;;
75
+ *)
76
+ printf '%s' "$1"
77
+ ;;
78
+ esac
79
+ }
80
+
81
+ find_config() {
82
+ if [ -n "${AO_CONFIG_PATH:-}" ] && [ -f "$AO_CONFIG_PATH" ]; then
83
+ printf '%s\n' "$AO_CONFIG_PATH"
84
+ return 0
85
+ fi
86
+
87
+ local current_dir="$PWD"
88
+ while [ "$current_dir" != "/" ]; do
89
+ if [ -f "$current_dir/agent-orchestrator.yaml" ]; then
90
+ printf '%s\n' "$current_dir/agent-orchestrator.yaml"
91
+ return 0
92
+ fi
93
+ if [ -f "$current_dir/agent-orchestrator.yml" ]; then
94
+ printf '%s\n' "$current_dir/agent-orchestrator.yml"
95
+ return 0
96
+ fi
97
+ current_dir="$(dirname "$current_dir")"
98
+ done
99
+
100
+ if [ -f "$REPO_ROOT/agent-orchestrator.yaml" ]; then
101
+ printf '%s\n' "$REPO_ROOT/agent-orchestrator.yaml"
102
+ return 0
103
+ fi
104
+
105
+ if [ -f "$DEFAULT_CONFIG_HOME/.agent-orchestrator.yaml" ]; then
106
+ printf '%s\n' "$DEFAULT_CONFIG_HOME/.agent-orchestrator.yaml"
107
+ return 0
108
+ fi
109
+
110
+ return 1
111
+ }
112
+
113
+ read_config_value() {
114
+ local key="$1"
115
+ local file="$2"
116
+ local raw
117
+ local value
118
+ raw="$(grep -E "^[[:space:]]*${key}:" "$file" | head -n 1 | cut -d: -f2- || true)"
119
+ raw="$(printf '%s' "$raw" | strip_ansi)"
120
+ raw="${raw%%[[:space:]]#*}"
121
+ value="$(printf '%s' "$raw" | tr -d '"' | xargs 2>/dev/null || true)"
122
+ printf '%s' "$value"
123
+ }
124
+
125
+ ensure_dir() {
126
+ local dir_path="$1"
127
+ local label="$2"
128
+ local fix_hint="$3"
129
+ if [ -d "$dir_path" ]; then
130
+ pass "$label exists at $dir_path"
131
+ return 0
132
+ fi
133
+
134
+ if [ "$FIX_MODE" = true ]; then
135
+ if mkdir -p "$dir_path"; then
136
+ fixed "$label created at $dir_path"
137
+ return 0
138
+ fi
139
+ fail "$label could not be created at $dir_path. Fix: $fix_hint"
140
+ return 1
141
+ fi
142
+
143
+ warn "$label is missing at $dir_path. Fix: $fix_hint"
144
+ }
145
+
146
+ check_command() {
147
+ local name="$1"
148
+ local required="$2"
149
+ local fix_hint="$3"
150
+ local command_path
151
+ command_path="$(command -v "$name" 2>/dev/null || true)"
152
+ if [ -z "$command_path" ]; then
153
+ if [ "$required" = "required" ]; then
154
+ fail "$name is not in PATH. Fix: $fix_hint"
155
+ else
156
+ warn "$name is not in PATH. Fix: $fix_hint"
157
+ fi
158
+ return 1
159
+ fi
160
+
161
+ pass "$name resolves to $command_path"
162
+ return 0
163
+ }
164
+
165
+ check_node() {
166
+ if ! check_command "node" "required" "install Node.js 20+ and reopen your shell"; then
167
+ return
168
+ fi
169
+ local version major
170
+ version="$(node --version 2>/dev/null || true)"
171
+ major="${version#v}"
172
+ major="${major%%.*}"
173
+ if [ -z "$major" ] || [ "$major" -lt 20 ]; then
174
+ fail "Node.js 20+ is required, found ${version:-unknown}. Fix: install Node.js 20+"
175
+ return
176
+ fi
177
+ pass "Node.js version ${version} is supported"
178
+ }
179
+
180
+ check_git() {
181
+ if ! check_command "git" "required" "install git 2.25+ and reopen your shell"; then
182
+ return
183
+ fi
184
+ local version_output version major minor
185
+ version_output="$(git --version 2>/dev/null || true)"
186
+ version_output="$(printf '%s' "$version_output" | strip_ansi)"
187
+ version="$(printf '%s\n' "$version_output" | awk '{print $3}' | head -n 1)"
188
+ major="${version%%.*}"
189
+ minor="${version#*.}"
190
+ minor="${minor%%.*}"
191
+ if [ -z "$version" ] || [ "$major" -lt 2 ] || { [ "$major" -eq 2 ] && [ "$minor" -lt 25 ]; }; then
192
+ fail "git 2.25+ is required, found ${version:-unknown}. Fix: upgrade git"
193
+ return
194
+ fi
195
+ pass "git version ${version} supports worktrees"
196
+ }
197
+
198
+ check_pnpm() {
199
+ local pnpm_requirement="required"
200
+ local fix_hint="enable corepack or run npm install -g pnpm"
201
+ if [ "$SCRIPT_LAYOUT" = "package-install" ]; then
202
+ pnpm_requirement="optional"
203
+ fix_hint="install pnpm if you plan to use pnpm-managed repos with AO"
204
+ fi
205
+
206
+ if ! check_command "pnpm" "$pnpm_requirement" "$fix_hint"; then
207
+ return
208
+ fi
209
+ local version
210
+ version="$(pnpm --version 2>/dev/null || true)"
211
+ pass "pnpm version ${version:-unknown} is available"
212
+ }
213
+
214
+ check_launcher() {
215
+ local ao_path
216
+ ao_path="$(command -v athene 2>/dev/null || true)"
217
+ if [ -n "$ao_path" ]; then
218
+ if [ -x "$ao_path" ]; then
219
+ pass "ao launcher resolves to $ao_path"
220
+ return
221
+ fi
222
+ warn "ao launcher resolves to $ao_path, but its target is missing or not executable"
223
+ fi
224
+
225
+ if [ "$SCRIPT_LAYOUT" = "source-checkout" ] && [ "$FIX_MODE" = true ] && command -v npm >/dev/null 2>&1 && [ -d "$REPO_ROOT/packages/athene" ]; then
226
+ if (cd "$REPO_ROOT/packages/athene" && npm link --force >/dev/null 2>&1) && command -v athene >/dev/null 2>&1; then
227
+ fixed "ao launcher refreshed with npm link --force"
228
+ return
229
+ fi
230
+ if [ -t 0 ]; then
231
+ printf ' Launcher refresh failed. Retrying with sudo...\n'
232
+ if (cd "$REPO_ROOT/packages/athene" && sudo npm link --force >/dev/null 2>&1) && command -v athene >/dev/null 2>&1; then
233
+ fixed "ao launcher refreshed with sudo npm link --force"
234
+ return
235
+ fi
236
+ printf 'ERROR: sudo npm link --force failed. Inspect npm output above.\n' >&2
237
+ fi
238
+ warn "ao launcher refresh failed. Fix: cd $REPO_ROOT/packages/athene && sudo npm link --force"
239
+ return
240
+ fi
241
+
242
+ if [ "$SCRIPT_LAYOUT" = "package-install" ]; then
243
+ warn "ao launcher is not in PATH. Fix: reinstall with npm install -g @made-by-moonlight/athene@latest or run via pnpx @made-by-moonlight/athene@latest"
244
+ return
245
+ fi
246
+
247
+ warn "ao launcher is not in PATH. Fix: cd $REPO_ROOT && bash scripts/setup.sh"
248
+ }
249
+
250
+ check_tmux() {
251
+ if ! command -v tmux >/dev/null 2>&1; then
252
+ warn "tmux is not installed. Fix: install tmux for the default runtime"
253
+ return
254
+ fi
255
+ if tmux -V >/dev/null 2>&1 && tmux start-server >/dev/null 2>&1; then
256
+ pass "tmux is installed and the server can start"
257
+ return
258
+ fi
259
+ warn "tmux is installed but failed a basic server health check. Fix: restart tmux or reinstall it"
260
+ }
261
+
262
+ check_gh() {
263
+ if ! command -v gh >/dev/null 2>&1; then
264
+ warn "GitHub CLI is not installed. Fix: install gh from https://cli.github.com/"
265
+ return
266
+ fi
267
+ if gh auth status >/dev/null 2>&1; then
268
+ pass "gh is installed and authenticated"
269
+ return
270
+ fi
271
+ warn "gh is installed but not authenticated. Fix: run gh auth login"
272
+ }
273
+
274
+ check_install_layout() {
275
+ if [ "$SCRIPT_LAYOUT" = "package-install" ]; then
276
+ if [ -f "$REPO_ROOT/package.json" ]; then
277
+ pass "CLI package metadata is present at $REPO_ROOT/package.json"
278
+ else
279
+ fail "CLI package metadata is missing at $REPO_ROOT/package.json. Fix: reinstall @made-by-moonlight/athene"
280
+ fi
281
+
282
+ if [ -f "$REPO_ROOT/dist/index.js" ]; then
283
+ pass "packaged CLI entrypoint exists"
284
+ else
285
+ fail "packaged CLI entrypoint is missing. Fix: reinstall @made-by-moonlight/athene"
286
+ fi
287
+
288
+ if [ -f "$REPO_ROOT/dist/assets/scripts/athene-doctor.sh" ]; then
289
+ pass "bundled doctor script is available"
290
+ else
291
+ fail "bundled doctor script is missing. Fix: reinstall @made-by-moonlight/athene"
292
+ fi
293
+
294
+ if [ -f "$REPO_ROOT/dist/assets/scripts/athene-update.sh" ]; then
295
+ pass "bundled update script is available"
296
+ else
297
+ fail "bundled update script is missing. Fix: reinstall @made-by-moonlight/athene"
298
+ fi
299
+ return
300
+ fi
301
+
302
+ if [ -d "$REPO_ROOT/node_modules" ]; then
303
+ pass "dependencies are installed at $REPO_ROOT/node_modules"
304
+ else
305
+ fail "dependencies are missing at $REPO_ROOT/node_modules. Fix: run pnpm install"
306
+ fi
307
+
308
+ if [ -f "$REPO_ROOT/packages/core/dist/index.js" ]; then
309
+ pass "core package is built"
310
+ else
311
+ fail "core package is not built. Fix: run pnpm --filter @made-by-moonlight/athene-core build"
312
+ fi
313
+
314
+ if [ -f "$REPO_ROOT/packages/cli/dist/index.js" ]; then
315
+ pass "CLI package is built"
316
+ else
317
+ fail "CLI package is not built. Fix: run pnpm --filter @made-by-moonlight/athene-cli build"
318
+ fi
319
+ }
320
+
321
+ check_runtime_sanity() {
322
+ if [ "$SCRIPT_LAYOUT" = "package-install" ]; then
323
+ if [ ! -f "$REPO_ROOT/dist/index.js" ]; then
324
+ fail "packaged CLI entrypoint is missing. Fix: reinstall @made-by-moonlight/athene"
325
+ return
326
+ fi
327
+
328
+ if node "$REPO_ROOT/dist/index.js" --version >/dev/null 2>&1; then
329
+ pass "packaged CLI runtime sanity check passed (athene --version)"
330
+ else
331
+ fail "packaged CLI runtime sanity check failed. Fix: reinstall @made-by-moonlight/athene"
332
+ fi
333
+ return
334
+ fi
335
+
336
+ if [ ! -f "$REPO_ROOT/packages/athene/bin/athene.js" ]; then
337
+ fail "launcher entrypoint is missing. Fix: reinstall from a clean checkout"
338
+ return
339
+ fi
340
+
341
+ if node "$REPO_ROOT/packages/athene/bin/athene.js" --version >/dev/null 2>&1; then
342
+ pass "launcher runtime sanity check passed (athene --version)"
343
+ else
344
+ fail "launcher runtime sanity check failed. Fix: run pnpm build and refresh the launcher"
345
+ fi
346
+ }
347
+
348
+ check_config_dirs() {
349
+ local config_path data_dir worktree_dir
350
+ config_path="$(find_config || true)"
351
+ if [ -z "$config_path" ]; then
352
+ warn "No agent-orchestrator config was found. Fix: run athene start in a target repo"
353
+ return
354
+ fi
355
+
356
+ pass "config found at $config_path"
357
+ data_dir="$(read_config_value dataDir "$config_path")"
358
+ worktree_dir="$(read_config_value worktreeDir "$config_path")"
359
+
360
+ if [ -z "$data_dir" ]; then
361
+ data_dir="$DEFAULT_CONFIG_HOME/.agent-orchestrator"
362
+ fi
363
+ if [ -z "$worktree_dir" ]; then
364
+ worktree_dir="$DEFAULT_CONFIG_HOME/.worktrees"
365
+ fi
366
+
367
+ data_dir="$(expand_home "$data_dir")"
368
+ worktree_dir="$(expand_home "$worktree_dir")"
369
+
370
+ ensure_dir "$data_dir" "metadata directory" "mkdir -p $data_dir"
371
+ ensure_dir "$worktree_dir" "worktree directory" "mkdir -p $worktree_dir"
372
+ }
373
+
374
+ check_stale_temp_files() {
375
+ local temp_root stale_count deleted_count
376
+ temp_root="${AO_DOCTOR_TMP_ROOT:-${TMPDIR:-/tmp}/agent-orchestrator}"
377
+ if [ ! -d "$temp_root" ]; then
378
+ pass "temp root exists check skipped because $temp_root does not exist"
379
+ return
380
+ fi
381
+
382
+ stale_count="$(find "$temp_root" -maxdepth 1 -type f -mmin +60 \( -name 'ao-*.tmp' -o -name 'ao-*.pid' -o -name 'ao-*.lock' \) | wc -l | tr -d ' ')"
383
+ if [ "$stale_count" = "0" ]; then
384
+ pass "no stale temp files were detected under $temp_root"
385
+ return
386
+ fi
387
+
388
+ if [ "$FIX_MODE" = true ]; then
389
+ deleted_count="$(find "$temp_root" -maxdepth 1 -type f -mmin +60 \( -name 'ao-*.tmp' -o -name 'ao-*.pid' -o -name 'ao-*.lock' \) -delete -print | wc -l | tr -d ' ')"
390
+ if [ "$deleted_count" = "$stale_count" ]; then
391
+ fixed "$deleted_count stale temp files removed from $temp_root"
392
+ return
393
+ fi
394
+ warn "Only removed $deleted_count of $stale_count stale temp files from $temp_root. Fix: inspect that directory manually"
395
+ return
396
+ fi
397
+
398
+ warn "$stale_count stale temp files older than 60 minutes found under $temp_root. Fix: rerun athene doctor --fix"
399
+ }
400
+
401
+ file_mode_octal() {
402
+ case "$(uname -s 2>/dev/null || true)" in
403
+ Darwin|FreeBSD|OpenBSD|NetBSD)
404
+ stat -f '%Lp' "$1" 2>/dev/null || printf 'unknown'
405
+ ;;
406
+ *)
407
+ stat -c '%a' "$1" 2>/dev/null || printf 'unknown'
408
+ ;;
409
+ esac
410
+ }
411
+
412
+ resolve_node_pty_spawn_helper() {
413
+ node - "$REPO_ROOT" <<'NODE'
414
+ const fs = require("node:fs");
415
+ const { createRequire } = require("node:module");
416
+ const path = require("node:path");
417
+ const { pathToFileURL } = require("node:url");
418
+
419
+ const repoRoot = process.argv[2];
420
+
421
+ function resolvePackageJson(fromDir) {
422
+ try {
423
+ return createRequire(path.join(fromDir, "athene-doctor.js")).resolve("node-pty/package.json");
424
+ } catch {
425
+ return null;
426
+ }
427
+ }
428
+
429
+ function findPackageUp(startDir, ...segments) {
430
+ let dir = path.resolve(startDir);
431
+ while (true) {
432
+ const candidate = path.resolve(dir, "node_modules", ...segments);
433
+ if (fs.existsSync(candidate)) return candidate;
434
+ const parent = path.dirname(dir);
435
+ if (parent === dir) break;
436
+ dir = parent;
437
+ }
438
+ return null;
439
+ }
440
+
441
+ function resolveNodeModulesPackage(fromDir, ...segments) {
442
+ const packageDir = path.resolve(fromDir, "node_modules", ...segments);
443
+ return fs.existsSync(path.resolve(packageDir, "package.json")) ? packageDir : null;
444
+ }
445
+
446
+ function resolveCoreEntrypoint() {
447
+ const sourceCoreDir = path.resolve(repoRoot, "packages", "core");
448
+ const coreDir =
449
+ (fs.existsSync(path.join(sourceCoreDir, "package.json")) ? sourceCoreDir : null) ??
450
+ findPackageUp(repoRoot, "@made-by-moonlight", "core") ??
451
+ resolveNodeModulesPackage(repoRoot, "@made-by-moonlight", "core");
452
+ if (!coreDir) return null;
453
+
454
+ try {
455
+ const pkg = JSON.parse(fs.readFileSync(path.join(coreDir, "package.json"), "utf8"));
456
+ const entry = pkg.exports?.["."]?.import ?? pkg.module ?? pkg.main ?? "dist/index.js";
457
+ return path.resolve(coreDir, entry);
458
+ } catch {
459
+ return null;
460
+ }
461
+ }
462
+
463
+ async function getNodePtyPrebuildsSubdir() {
464
+ const coreEntrypoint = resolveCoreEntrypoint();
465
+ if (!coreEntrypoint || !fs.existsSync(coreEntrypoint)) return null;
466
+
467
+ const core = await import(pathToFileURL(coreEntrypoint).href);
468
+ return typeof core.getNodePtyPrebuildsSubdir === "function"
469
+ ? core.getNodePtyPrebuildsSubdir()
470
+ : null;
471
+ }
472
+
473
+ (async () => {
474
+ const packageJsonPath =
475
+ resolvePackageJson(repoRoot) ??
476
+ (() => {
477
+ const directNodePtyDir = findPackageUp(repoRoot, "node-pty");
478
+ if (directNodePtyDir) return path.join(directNodePtyDir, "package.json");
479
+
480
+ const sourceWebDir = path.resolve(repoRoot, "packages", "web");
481
+ const webDir =
482
+ (fs.existsSync(path.join(sourceWebDir, "package.json")) ? sourceWebDir : null) ??
483
+ findPackageUp(repoRoot, "@made-by-moonlight", "web") ??
484
+ resolveNodeModulesPackage(repoRoot, "@made-by-moonlight", "web");
485
+ if (!webDir) return null;
486
+
487
+ const webNodePtyDir =
488
+ resolveNodeModulesPackage(webDir, "node-pty") ?? findPackageUp(webDir, "node-pty");
489
+ return webNodePtyDir ? path.join(webNodePtyDir, "package.json") : null;
490
+ })();
491
+
492
+ const prebuildsSubdir = await getNodePtyPrebuildsSubdir();
493
+ if (!packageJsonPath || !prebuildsSubdir) process.exit(0);
494
+
495
+ console.log(path.join(path.dirname(packageJsonPath), "prebuilds", prebuildsSubdir, "spawn-helper"));
496
+ })().catch(() => process.exit(0));
497
+ NODE
498
+ }
499
+
500
+ check_node_pty_spawn_helper() {
501
+ if ! command -v node >/dev/null 2>&1; then
502
+ warn "node-pty spawn-helper check skipped because node is unavailable"
503
+ return
504
+ fi
505
+
506
+ local helper_path mode
507
+ helper_path="$(resolve_node_pty_spawn_helper 2>/dev/null || true)"
508
+ if [ -z "$helper_path" ] || [ ! -f "$helper_path" ]; then
509
+ pass "node-pty spawn-helper check skipped because no helper was found for this platform"
510
+ return
511
+ fi
512
+
513
+ mode="$(file_mode_octal "$helper_path")"
514
+ if [ -x "$helper_path" ]; then
515
+ pass "node-pty spawn-helper is executable at $helper_path (mode 0o$mode)"
516
+ return
517
+ fi
518
+
519
+ if [ "$FIX_MODE" = true ]; then
520
+ if chmod 755 "$helper_path"; then
521
+ fixed "chmod +x applied to node-pty spawn-helper at $helper_path (was 0o$mode)"
522
+ return
523
+ fi
524
+ warn "node-pty spawn-helper is not executable at $helper_path (mode 0o$mode), and chmod failed. Web dashboard terminals can fail with posix_spawnp failed. Fix: chmod +x $helper_path"
525
+ return
526
+ fi
527
+
528
+ warn "node-pty spawn-helper is not executable at $helper_path (mode 0o$mode). Web dashboard terminals can fail with posix_spawnp failed. Fix: run athene doctor --fix or chmod +x $helper_path. See ao#1770."
529
+ }
530
+
531
+ printf 'Athene Doctor\n\n'
532
+
533
+ check_node
534
+ check_git
535
+ check_pnpm
536
+ check_launcher
537
+ check_tmux
538
+ check_gh
539
+ check_config_dirs
540
+ check_stale_temp_files
541
+ check_install_layout
542
+ check_node_pty_spawn_helper
543
+ check_runtime_sanity
544
+
545
+ printf '\nResults: %s PASS, %s WARN, %s FAIL, %s FIXED\n' "$PASS_COUNT" "$WARN_COUNT" "$FAIL_COUNT" "$FIX_COUNT"
546
+
547
+ if [ "$FAIL_COUNT" -gt 0 ]; then
548
+ printf 'Environment needs attention before AO is safe to update or run.\n' >&2
549
+ exit 1
550
+ fi
551
+
552
+ printf 'Environment looks healthy enough to run Athene.\n'