@indigoai-us/hq-cli 5.77.14 → 5.79.0

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 (309) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/assets/scaffold/core/scripts/archive-old-threads.sh +86 -0
  3. package/assets/scaffold/core/scripts/backfill-company-skill-mirrors.sh +73 -0
  4. package/assets/scaffold/core/scripts/backfill-workspace-mirror.sh +51 -0
  5. package/assets/scaffold/core/scripts/codex-skill-bridge.sh +550 -0
  6. package/assets/scaffold/core/scripts/detect-stale-core-policy-mirror.sh +185 -0
  7. package/assets/scaffold/core/scripts/hq-status-summary.sh +187 -0
  8. package/assets/scaffold/core/scripts/ontology-readme-drift.sh +264 -0
  9. package/assets/scaffold/core/scripts/qmd-reindex-after-sync.sh +93 -0
  10. package/assets/scaffold/core/scripts/rebuild-all-indexes.sh +69 -0
  11. package/assets/scaffold/core/scripts/rebuild-companies-index.sh +206 -0
  12. package/assets/scaffold/core/scripts/rebuild-company-knowledge-index.sh +127 -0
  13. package/assets/scaffold/core/scripts/rebuild-orchestrator-index.sh +86 -0
  14. package/assets/scaffold/core/scripts/rebuild-projects-index.sh +105 -0
  15. package/assets/scaffold/core/scripts/rebuild-public-knowledge-index.sh +83 -0
  16. package/assets/scaffold/core/scripts/rebuild-reports-index.sh +114 -0
  17. package/assets/scaffold/core/scripts/rebuild-social-drafts-index.sh +135 -0
  18. package/assets/scaffold/core/scripts/rebuild-threads-index.sh +82 -0
  19. package/assets/scaffold/core/scripts/rebuild-workers-index.sh +97 -0
  20. package/assets/scaffold/core/scripts/resize-screenshot.sh +47 -0
  21. package/assets/scaffold/core/scripts/token-usage-report.sh +254 -0
  22. package/assets/scaffold/core/scripts/worktree.sh +136 -0
  23. package/dist/commands/agents.js +28 -12
  24. package/dist/commands/api-keys.js +100 -20
  25. package/dist/commands/core.d.ts +90 -0
  26. package/dist/commands/core.js +279 -0
  27. package/dist/commands/files-browse.d.ts +21 -0
  28. package/dist/commands/files-browse.js +145 -24
  29. package/dist/commands/files.js +33 -7
  30. package/dist/commands/meetings.js +16 -9
  31. package/dist/commands/members.js +16 -5
  32. package/dist/commands/pack-install.d.ts +14 -0
  33. package/dist/commands/pack-install.js +42 -2
  34. package/dist/commands/pkg-install.js +39 -2
  35. package/dist/commands/run.js +6 -2
  36. package/dist/commands/secrets.js +120 -65
  37. package/dist/main.js +6 -0
  38. package/dist/utils/api-key-command-gate.d.ts +45 -0
  39. package/dist/utils/api-key-command-gate.js +51 -0
  40. package/dist/utils/hq-roots.d.ts +91 -0
  41. package/dist/utils/hq-roots.js +212 -0
  42. package/dist/utils/resolve-vault-credential.d.ts +63 -3
  43. package/dist/utils/resolve-vault-credential.js +152 -6
  44. package/dist/utils/run-bundled-script.d.ts +66 -0
  45. package/dist/utils/run-bundled-script.js +80 -0
  46. package/dist/utils/vault-api.d.ts +21 -0
  47. package/dist/utils/vault-api.js +74 -3
  48. package/package.json +7 -1
  49. package/.claude/policies/hq-cli-interactive-reads-use-sts-vend.md +0 -49
  50. package/.github/workflows/ci.yml +0 -46
  51. package/.github/workflows/publish.yml +0 -36
  52. package/.github/workflows/scripts/smoke-test-pkg.sh +0 -97
  53. package/e2e/cli.test.ts +0 -128
  54. package/eslint.config.js +0 -37
  55. package/pnpm-workspace.yaml +0 -4
  56. package/scripts/chmod-bins.mjs +0 -49
  57. package/scripts/generate-dsn.mjs +0 -26
  58. package/scripts/generate-scan-packages-table.mjs +0 -113
  59. package/scripts/smoke-sources-signals.sh +0 -103
  60. package/src/bin/hq-auth-refresh.ts +0 -43
  61. package/src/cli-version.ts +0 -13
  62. package/src/commands/__fixtures__/make-tar.ts +0 -126
  63. package/src/commands/_patterns.ts +0 -10
  64. package/src/commands/add.ts +0 -75
  65. package/src/commands/agents.test.ts +0 -527
  66. package/src/commands/agents.ts +0 -923
  67. package/src/commands/api-keys.test.ts +0 -291
  68. package/src/commands/api-keys.ts +0 -382
  69. package/src/commands/artifact-verify.test.ts +0 -177
  70. package/src/commands/auth.test.ts +0 -82
  71. package/src/commands/auth.ts +0 -213
  72. package/src/commands/billing.test.ts +0 -158
  73. package/src/commands/billing.ts +0 -146
  74. package/src/commands/channels.test.ts +0 -74
  75. package/src/commands/channels.ts +0 -91
  76. package/src/commands/cloud-demote.test.ts +0 -401
  77. package/src/commands/cloud-demote.ts +0 -278
  78. package/src/commands/cloud-provision.test.ts +0 -1117
  79. package/src/commands/cloud-provision.ts +0 -942
  80. package/src/commands/cloud.pull-all.test.ts +0 -711
  81. package/src/commands/cloud.pull-per-company.test.ts +0 -188
  82. package/src/commands/cloud.push-all.test.ts +0 -485
  83. package/src/commands/cloud.scope-excluded-warning.test.ts +0 -22
  84. package/src/commands/cloud.selectors.test.ts +0 -208
  85. package/src/commands/cloud.status.test.ts +0 -160
  86. package/src/commands/cloud.test.ts +0 -41
  87. package/src/commands/cloud.ts +0 -2130
  88. package/src/commands/company.test.ts +0 -202
  89. package/src/commands/company.ts +0 -148
  90. package/src/commands/creators.test.ts +0 -60
  91. package/src/commands/creators.ts +0 -117
  92. package/src/commands/crm.test.ts +0 -179
  93. package/src/commands/crm.ts +0 -236
  94. package/src/commands/db-migrate.ts +0 -55
  95. package/src/commands/db-provision.ts +0 -114
  96. package/src/commands/db-sql.ts +0 -124
  97. package/src/commands/db-status.ts +0 -108
  98. package/src/commands/db.ts +0 -26
  99. package/src/commands/dm.test.ts +0 -748
  100. package/src/commands/dm.ts +0 -1226
  101. package/src/commands/feedback.test.ts +0 -413
  102. package/src/commands/feedback.ts +0 -169
  103. package/src/commands/files-browse.test.ts +0 -1249
  104. package/src/commands/files-browse.ts +0 -1506
  105. package/src/commands/files-delete.test.ts +0 -484
  106. package/src/commands/files-recovery.test.ts +0 -370
  107. package/src/commands/files.test.ts +0 -722
  108. package/src/commands/files.ts +0 -1446
  109. package/src/commands/group-grants.test.ts +0 -330
  110. package/src/commands/group-grants.ts +0 -455
  111. package/src/commands/groups.test.ts +0 -44
  112. package/src/commands/groups.ts +0 -368
  113. package/src/commands/integrations.test.ts +0 -633
  114. package/src/commands/integrations.ts +0 -507
  115. package/src/commands/list.ts +0 -85
  116. package/src/commands/login.ts +0 -52
  117. package/src/commands/logout.ts +0 -30
  118. package/src/commands/marketplace-install.test.ts +0 -543
  119. package/src/commands/marketplace-security.test.ts +0 -646
  120. package/src/commands/mcp-registration.test.ts +0 -2787
  121. package/src/commands/mcp-registration.ts +0 -2612
  122. package/src/commands/mcp-status.test.ts +0 -483
  123. package/src/commands/mcp-status.ts +0 -575
  124. package/src/commands/mcp-status.us011.test.ts +0 -243
  125. package/src/commands/meetings.test.ts +0 -522
  126. package/src/commands/meetings.ts +0 -789
  127. package/src/commands/members.test.ts +0 -1474
  128. package/src/commands/members.ts +0 -1181
  129. package/src/commands/onboard-identity-guard.test.ts +0 -99
  130. package/src/commands/onboard-identity-guard.ts +0 -103
  131. package/src/commands/onboard-join.test.ts +0 -96
  132. package/src/commands/onboard-join.ts +0 -101
  133. package/src/commands/onboard-warning.test.ts +0 -26
  134. package/src/commands/onboard-warning.ts +0 -12
  135. package/src/commands/onboard.ts +0 -267
  136. package/src/commands/outposts-heartbeat.test.ts +0 -299
  137. package/src/commands/outposts-heartbeat.ts +0 -310
  138. package/src/commands/outposts-replica-sync.test.ts +0 -272
  139. package/src/commands/outposts-self-deploy.test.ts +0 -243
  140. package/src/commands/outposts.test.ts +0 -1039
  141. package/src/commands/outposts.ts +0 -1935
  142. package/src/commands/pack-install-secret-authorization.test.ts +0 -115
  143. package/src/commands/pack-install.test.ts +0 -1469
  144. package/src/commands/pack-install.ts +0 -2256
  145. package/src/commands/pack-update-cache.test.ts +0 -149
  146. package/src/commands/packs-update-api-key.test.ts +0 -105
  147. package/src/commands/packs.test.ts +0 -88
  148. package/src/commands/packs.ts +0 -622
  149. package/src/commands/people.test.ts +0 -807
  150. package/src/commands/people.ts +0 -422
  151. package/src/commands/pkg-install.dispatch.test.ts +0 -103
  152. package/src/commands/pkg-install.ts +0 -221
  153. package/src/commands/pkg-list.test.ts +0 -79
  154. package/src/commands/pkg-list.ts +0 -13
  155. package/src/commands/pkg-remove.ts +0 -71
  156. package/src/commands/pkg-update.ts +0 -189
  157. package/src/commands/publish.test.ts +0 -650
  158. package/src/commands/publish.ts +0 -580
  159. package/src/commands/reindex.test.ts +0 -259
  160. package/src/commands/reindex.ts +0 -274
  161. package/src/commands/rescue.test.ts +0 -39
  162. package/src/commands/rescue.ts +0 -210
  163. package/src/commands/run.env-local.test.ts +0 -88
  164. package/src/commands/run.test.ts +0 -45
  165. package/src/commands/run.ts +0 -190
  166. package/src/commands/safe-extract.test.ts +0 -459
  167. package/src/commands/safe-extract.ts +0 -444
  168. package/src/commands/secrets-scope.test.ts +0 -56
  169. package/src/commands/secrets-scope.ts +0 -32
  170. package/src/commands/secrets.parse-destination.test.ts +0 -38
  171. package/src/commands/secrets.test.ts +0 -2050
  172. package/src/commands/secrets.ts +0 -2249
  173. package/src/commands/signals.ts +0 -351
  174. package/src/commands/skill.test.ts +0 -770
  175. package/src/commands/skill.ts +0 -796
  176. package/src/commands/sources.ts +0 -362
  177. package/src/commands/sync-mode.test.ts +0 -366
  178. package/src/commands/sync-mode.ts +0 -387
  179. package/src/commands/sync-narrow.test.ts +0 -633
  180. package/src/commands/sync-narrow.ts +0 -555
  181. package/src/commands/sync.ts +0 -165
  182. package/src/commands/team-sync.ts +0 -628
  183. package/src/commands/update.ts +0 -71
  184. package/src/commands/whoami.ts +0 -83
  185. package/src/commands/workers.test.ts +0 -158
  186. package/src/commands/workers.ts +0 -301
  187. package/src/index.test.ts +0 -32
  188. package/src/index.ts +0 -20
  189. package/src/lib/db/control-plane.test.ts +0 -59
  190. package/src/lib/db/control-plane.ts +0 -113
  191. package/src/lib/db/local.test.ts +0 -81
  192. package/src/lib/db/local.ts +0 -148
  193. package/src/lib/db/migrate.test.ts +0 -133
  194. package/src/lib/db/migrate.ts +0 -137
  195. package/src/lib/db/paths.test.ts +0 -112
  196. package/src/lib/db/paths.ts +0 -128
  197. package/src/lib/db/remote-engine.test.ts +0 -44
  198. package/src/lib/db/remote-engine.ts +0 -148
  199. package/src/lib/db/remote-sql.test.ts +0 -32
  200. package/src/lib/db/remote-sql.ts +0 -62
  201. package/src/lib/db/sql.test.ts +0 -106
  202. package/src/lib/db/sql.ts +0 -192
  203. package/src/lib/hq-cloud-dep.smoke.test.ts +0 -75
  204. package/src/lib/local-tree-diff.test.ts +0 -301
  205. package/src/lib/local-tree-diff.ts +0 -362
  206. package/src/lib/narrow-hint-banner.test.ts +0 -235
  207. package/src/lib/narrow-hint-banner.ts +0 -212
  208. package/src/lib/plan-limit-nag.test.ts +0 -317
  209. package/src/lib/plan-limit-nag.ts +0 -264
  210. package/src/main.ts +0 -371
  211. package/src/node-preflight.test.ts +0 -60
  212. package/src/node-preflight.ts +0 -67
  213. package/src/outpost/session-heartbeat-bounds.test.ts +0 -195
  214. package/src/outpost/session-heartbeat-guard.test.ts +0 -105
  215. package/src/outpost/session-heartbeat-publisher.test.ts +0 -178
  216. package/src/outpost/session-heartbeat-publisher.ts +0 -186
  217. package/src/outpost/session-heartbeat-retain-guard.test.ts +0 -126
  218. package/src/outpost/session-heartbeat.test.ts +0 -459
  219. package/src/outpost/session-heartbeat.ts +0 -877
  220. package/src/packaging.test.ts +0 -109
  221. package/src/run/__fixtures__/discover-schemas/example.env.schema +0 -4
  222. package/src/run/discover-schemas.test.ts +0 -153
  223. package/src/run/discover-schemas.ts +0 -79
  224. package/src/run/hq-plugin.test.ts +0 -371
  225. package/src/run/hq-plugin.ts +0 -277
  226. package/src/run/varlock-shape.test.ts +0 -57
  227. package/src/schemas/hq-package.schema.json +0 -155
  228. package/src/sentry-before-send.test.ts +0 -359
  229. package/src/sentry-before-send.ts +0 -221
  230. package/src/sentry-epipe.test.ts +0 -37
  231. package/src/sentry-release.test.ts +0 -54
  232. package/src/sentry.test.ts +0 -24
  233. package/src/sentry.ts +0 -54
  234. package/src/strategies/link.ts +0 -62
  235. package/src/strategies/merge.ts +0 -142
  236. package/src/types.ts +0 -146
  237. package/src/utils/__fixtures__/scan-packages.generated-block.sh +0 -23
  238. package/src/utils/auth-error.test.ts +0 -40
  239. package/src/utils/auth-error.ts +0 -42
  240. package/src/utils/billing-gate.test.ts +0 -95
  241. package/src/utils/billing-gate.ts +0 -228
  242. package/src/utils/breadcrumb-buffer.ts +0 -18
  243. package/src/utils/cli-telemetry.test.ts +0 -153
  244. package/src/utils/cli-telemetry.ts +0 -61
  245. package/src/utils/cognito-session.machine.test.ts +0 -109
  246. package/src/utils/cognito-session.refresh.test.ts +0 -84
  247. package/src/utils/cognito-session.test.ts +0 -328
  248. package/src/utils/cognito-session.ts +0 -448
  249. package/src/utils/company-selection-error.test.ts +0 -42
  250. package/src/utils/company-selection-error.ts +0 -45
  251. package/src/utils/contribution-table.ts +0 -83
  252. package/src/utils/environmental-error.test.ts +0 -45
  253. package/src/utils/environmental-error.ts +0 -39
  254. package/src/utils/epipe.test.ts +0 -28
  255. package/src/utils/epipe.ts +0 -29
  256. package/src/utils/expected-cli-error.test.ts +0 -28
  257. package/src/utils/expected-cli-error.ts +0 -39
  258. package/src/utils/feedback-diagnostics.test.ts +0 -183
  259. package/src/utils/feedback-diagnostics.ts +0 -123
  260. package/src/utils/feedback-screenshots.test.ts +0 -134
  261. package/src/utils/feedback-screenshots.ts +0 -124
  262. package/src/utils/feedback-versions.test.ts +0 -98
  263. package/src/utils/feedback-versions.ts +0 -68
  264. package/src/utils/git.ts +0 -74
  265. package/src/utils/integrity.ts +0 -59
  266. package/src/utils/intercepted-process-exit.test.ts +0 -37
  267. package/src/utils/intercepted-process-exit.ts +0 -36
  268. package/src/utils/login-provider.test.ts +0 -42
  269. package/src/utils/login-provider.ts +0 -30
  270. package/src/utils/manifest.test.ts +0 -167
  271. package/src/utils/manifest.ts +0 -131
  272. package/src/utils/pack-contributions.test.ts +0 -603
  273. package/src/utils/pack-contributions.ts +0 -450
  274. package/src/utils/people.ts +0 -215
  275. package/src/utils/registry-client.ts +0 -204
  276. package/src/utils/registry.ts +0 -90
  277. package/src/utils/resolve-vault-credential.test.ts +0 -69
  278. package/src/utils/resolve-vault-credential.ts +0 -60
  279. package/src/utils/sandbox-runner-client.test.ts +0 -279
  280. package/src/utils/sandbox-runner-client.ts +0 -260
  281. package/src/utils/secrets-cache.ts +0 -183
  282. package/src/utils/sentry-identity.ts +0 -45
  283. package/src/utils/settle-with-timeout.test.ts +0 -21
  284. package/src/utils/settle-with-timeout.ts +0 -22
  285. package/src/utils/user-yaml-error.test.ts +0 -24
  286. package/src/utils/user-yaml-error.ts +0 -30
  287. package/src/utils/vault-api.test.ts +0 -536
  288. package/src/utils/vault-api.ts +0 -382
  289. package/src/utils/version-check.test.ts +0 -176
  290. package/src/utils/version-check.ts +0 -155
  291. package/src/utils/version-gate.test.ts +0 -1024
  292. package/src/utils/version-gate.ts +0 -702
  293. package/test/commands/db-tenant-isolation.test.ts +0 -94
  294. package/test/commands/db.test.ts +0 -85
  295. package/test/commands/signals.test.ts +0 -207
  296. package/test/commands/sources.test.ts +0 -231
  297. package/test/e2e/smoke-install-mcp.sh +0 -113
  298. package/test/fixtures/hq-pack-smoke-mcp/mcp/smoke-http.json +0 -1
  299. package/test/fixtures/hq-pack-smoke-mcp/package.yaml +0 -11
  300. package/test/fixtures/signals/action_item/sample.md +0 -16
  301. package/test/fixtures/signals/summary/sample.md +0 -12
  302. package/test/fixtures/sources/meetings/sample.md +0 -25
  303. package/test/helpers/cli-runner.ts +0 -150
  304. package/test/helpers/s3-list-mock.ts +0 -79
  305. package/test/helpers/vault-service-mock.ts +0 -295
  306. package/test/sources-signals/smoke.test.ts +0 -228
  307. package/tsconfig.json +0 -20
  308. package/vitest.config.ts +0 -11
  309. package/vitest.e2e.config.ts +0 -7
@@ -0,0 +1,550 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -euo pipefail
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ if [[ -d "${SCRIPT_DIR}/../.claude" ]]; then
7
+ DEFAULT_HQ_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
8
+ else
9
+ DEFAULT_HQ_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"
10
+ fi
11
+
12
+ HQ_ROOT="${HQ_ROOT:-${DEFAULT_HQ_ROOT}}"
13
+ COMMAND=""
14
+ REPAIR_LOCAL_CONFIG=0
15
+ DRY_RUN=0
16
+ OLD_ROOTS=()
17
+ STATUS_FAILURES=0
18
+
19
+ usage() {
20
+ cat <<'EOF'
21
+ Usage:
22
+ scripts/codex-skill-bridge.sh status [--root <path>]
23
+ scripts/codex-skill-bridge.sh install [--root <path>] [--repair-local-config] [--old-root <path>]
24
+ scripts/codex-skill-bridge.sh doctor [--root <path>] [--old-root <path>] [--dry-run]
25
+
26
+ Commands:
27
+ status Show bridge health, output-style bridge health, and stale HQ roots without changing files.
28
+ install Install or repair HQ-owned Claude -> Codex bridges.
29
+ doctor Repair bridges and rewrite local machine config from old HQ roots to this root.
30
+
31
+ Options:
32
+ --root <path> HQ root to repair. Defaults to this script's parent.
33
+ --old-root <path> Old HQ root to rewrite. Repeatable. Auto-detected when omitted.
34
+ --repair-local-config With install, also rewrite local config paths.
35
+ --dry-run With doctor, print intended config rewrites without changing files.
36
+ EOF
37
+ }
38
+
39
+ fail() {
40
+ echo "$*" >&2
41
+ exit 1
42
+ }
43
+
44
+ canonical_dir() {
45
+ local path="$1"
46
+ (cd "${path}" && pwd)
47
+ }
48
+
49
+ configure_paths() {
50
+ HQ_ROOT="$(canonical_dir "${HQ_ROOT}")"
51
+ SKILLS_SOURCE_DIR="${HQ_ROOT}/.claude/skills"
52
+ CLAUDE_SOURCE_DIR="${HQ_ROOT}/.claude"
53
+ COMMANDS_SOURCE_DIR="${CLAUDE_SOURCE_DIR}/commands"
54
+ HOOKS_SOURCE_DIR="${CLAUDE_SOURCE_DIR}/hooks"
55
+ POLICIES_SOURCE_DIR="${CLAUDE_SOURCE_DIR}/policies"
56
+ SETTINGS_SOURCE_FILE="${CLAUDE_SOURCE_DIR}/settings.json"
57
+ OUTPUT_STYLES_SOURCE_DIR="${CLAUDE_SOURCE_DIR}/output-styles"
58
+ GLOBAL_SKILLS_TARGET_DIR="${HOME}/.codex/skills/hq"
59
+ GLOBAL_AGENTS_SKILLS_TARGET_DIR="${HOME}/.agents/skills/hq"
60
+ REPO_AGENTS_SKILLS_TARGET_DIR="${HQ_ROOT}/.agents/skills"
61
+ PROJECT_CODEX_DIR="${HQ_ROOT}/.codex"
62
+ PROJECT_CLAUDE_TARGET_DIR="${PROJECT_CODEX_DIR}/claude"
63
+ PROJECT_PROMPTS_TARGET_DIR="${PROJECT_CODEX_DIR}/prompts"
64
+ PROJECT_OUTPUT_STYLE_TARGET_FILE="${PROJECT_CODEX_DIR}/output-style.md"
65
+ LEGACY_CODEX_DIR="${HQ_ROOT}/.Codex"
66
+ LEGACY_CLAUDE_TARGET_DIR="${LEGACY_CODEX_DIR}/claude"
67
+ LEGACY_PROMPTS_TARGET_DIR="${LEGACY_CODEX_DIR}/prompts"
68
+ LEGACY_OUTPUT_STYLE_TARGET_FILE="${LEGACY_CODEX_DIR}/output-style.md"
69
+ }
70
+
71
+ parse_args() {
72
+ while (($#)); do
73
+ case "$1" in
74
+ status|install|doctor)
75
+ [[ -z "${COMMAND}" ]] || fail "Only one command may be provided."
76
+ COMMAND="$1"
77
+ shift
78
+ ;;
79
+ --root)
80
+ [[ $# -ge 2 ]] || fail "--root requires a path."
81
+ HQ_ROOT="$2"
82
+ shift 2
83
+ ;;
84
+ --root=*)
85
+ HQ_ROOT="${1#--root=}"
86
+ shift
87
+ ;;
88
+ --old-root)
89
+ [[ $# -ge 2 ]] || fail "--old-root requires a path."
90
+ OLD_ROOTS+=("$2")
91
+ shift 2
92
+ ;;
93
+ --old-root=*)
94
+ OLD_ROOTS+=("${1#--old-root=}")
95
+ shift
96
+ ;;
97
+ --repair-local-config)
98
+ REPAIR_LOCAL_CONFIG=1
99
+ shift
100
+ ;;
101
+ --dry-run)
102
+ DRY_RUN=1
103
+ shift
104
+ ;;
105
+ -h|--help)
106
+ usage
107
+ exit 0
108
+ ;;
109
+ *)
110
+ fail "Unknown argument: $1"
111
+ ;;
112
+ esac
113
+ done
114
+
115
+ [[ -n "${COMMAND}" ]] || {
116
+ usage
117
+ exit 1
118
+ }
119
+ }
120
+
121
+ skill_count() {
122
+ find "${SKILLS_SOURCE_DIR}" -mindepth 1 -maxdepth 1 \( -type d -o -type l \) -exec test -f '{}/SKILL.md' \; -print 2>/dev/null | wc -l | tr -d '[:space:]'
123
+ }
124
+
125
+ command_count() {
126
+ find "${COMMANDS_SOURCE_DIR}" -mindepth 1 -maxdepth 1 -type f -name '*.md' 2>/dev/null | wc -l | tr -d '[:space:]'
127
+ }
128
+
129
+ hook_count() {
130
+ find "${HOOKS_SOURCE_DIR}" -mindepth 1 -maxdepth 1 -type f 2>/dev/null | wc -l | tr -d '[:space:]'
131
+ }
132
+
133
+ policy_count() {
134
+ find "${POLICIES_SOURCE_DIR}" -mindepth 1 -maxdepth 1 -type f -name '*.md' 2>/dev/null | wc -l | tr -d '[:space:]'
135
+ }
136
+
137
+ openai_yaml_count() {
138
+ find "${SKILLS_SOURCE_DIR}" -mindepth 1 -maxdepth 1 \( -type d -o -type l \) -exec sh -c 'test -f "$1/SKILL.md" && test -f "$1/agents/openai.yaml"' _ '{}' \; -print 2>/dev/null | wc -l | tr -d '[:space:]'
139
+ }
140
+
141
+ commands_with_skills_count() {
142
+ local count=0
143
+ while IFS= read -r cmd_file; do
144
+ local cmd_name
145
+ cmd_name="$(basename "${cmd_file}" .md)"
146
+ if [[ -f "${SKILLS_SOURCE_DIR}/${cmd_name}/SKILL.md" ]]; then
147
+ (( count++ )) || true
148
+ fi
149
+ done < <(find "${COMMANDS_SOURCE_DIR}" -mindepth 1 -maxdepth 1 -type f -name '*.md' 2>/dev/null)
150
+ echo "${count}"
151
+ }
152
+
153
+ print_coverage_report() {
154
+ local total_cmds with_skills without_skills
155
+ total_cmds="$(command_count)"
156
+ with_skills="$(commands_with_skills_count)"
157
+ without_skills=$(( total_cmds - with_skills ))
158
+
159
+ echo "Codex coverage: ${with_skills}/${total_cmds} commands have skills"
160
+
161
+ if (( without_skills > 0 )); then
162
+ echo
163
+ echo "Commands without skills (${without_skills}):"
164
+ while IFS= read -r cmd_file; do
165
+ local cmd_name
166
+ cmd_name="$(basename "${cmd_file}" .md)"
167
+ if [[ ! -d "${SKILLS_SOURCE_DIR}/${cmd_name}" ]]; then
168
+ echo " - ${cmd_name}"
169
+ fi
170
+ done < <(find "${COMMANDS_SOURCE_DIR}" -mindepth 1 -maxdepth 1 -type f -name '*.md' 2>/dev/null | sort)
171
+ else
172
+ echo "All commands have corresponding skills."
173
+ fi
174
+ }
175
+
176
+ normalize_link_target() {
177
+ local target="$1"
178
+ local link_target
179
+
180
+ link_target="$(readlink "${target}")"
181
+ if [[ "${link_target}" = /* ]]; then
182
+ printf '%s\n' "${link_target}"
183
+ return
184
+ fi
185
+
186
+ local target_dir resolved_path
187
+ target_dir="$(cd "$(dirname "${target}")" && pwd)"
188
+ resolved_path="${target_dir}/${link_target}"
189
+
190
+ if [[ -e "${resolved_path}" ]]; then
191
+ if [[ -d "${resolved_path}" ]]; then
192
+ (cd "${resolved_path}" && pwd)
193
+ else
194
+ local resolved_dir resolved_base
195
+ resolved_dir="$(cd "$(dirname "${resolved_path}")" && pwd)"
196
+ resolved_base="$(basename "${resolved_path}")"
197
+ printf '%s/%s\n' "${resolved_dir}" "${resolved_base}"
198
+ fi
199
+ return
200
+ fi
201
+
202
+ printf '%s\n' "${resolved_path}"
203
+ }
204
+
205
+ strip_known_hq_subpath() {
206
+ local path="$1"
207
+
208
+ case "${path}" in
209
+ */.claude/output-styles/*.md) printf '%s\n' "${path%%/.claude/output-styles/*}" ;;
210
+ */.claude/skills) printf '%s\n' "${path%/.claude/skills}" ;;
211
+ */.claude/commands) printf '%s\n' "${path%/.claude/commands}" ;;
212
+ */.claude) printf '%s\n' "${path%/.claude}" ;;
213
+ *) return 1 ;;
214
+ esac
215
+ }
216
+
217
+ active_output_style_name() {
218
+ [[ -f "${SETTINGS_SOURCE_FILE}" ]] || return 1
219
+ sed -n 's/.*"outputStyle"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "${SETTINGS_SOURCE_FILE}" | tail -n 1
220
+ }
221
+
222
+ output_style_slug() {
223
+ printf '%s' "$1" \
224
+ | tr '[:upper:]' '[:lower:]' \
225
+ | sed 's/[[:space:]_]\+/-/g; s/[^a-z0-9.-]/-/g; s/-\+/-/g; s/^-//; s/-$//'
226
+ }
227
+
228
+ resolve_output_style_source_file() {
229
+ local style_name slug source
230
+ style_name="$(active_output_style_name || true)"
231
+ [[ -n "${style_name}" ]] || return 1
232
+ slug="$(output_style_slug "${style_name}")"
233
+ source="${OUTPUT_STYLES_SOURCE_DIR}/${slug}.md"
234
+ [[ -f "${source}" ]] || return 1
235
+ printf '%s\n' "${source}"
236
+ }
237
+
238
+ print_output_style_status() {
239
+ local style_name source
240
+ style_name="$(active_output_style_name || true)"
241
+ echo "Active output style: ${style_name:-not configured}"
242
+
243
+ if source="$(resolve_output_style_source_file)"; then
244
+ print_link_status "Project Codex output-style bridge" "${source}" "${PROJECT_OUTPUT_STYLE_TARGET_FILE}"
245
+ if [[ -e "${LEGACY_CODEX_DIR}" || -L "${LEGACY_OUTPUT_STYLE_TARGET_FILE}" ]]; then
246
+ echo
247
+ print_link_status "Legacy .Codex output-style bridge" "${source}" "${LEGACY_OUTPUT_STYLE_TARGET_FILE}"
248
+ fi
249
+ else
250
+ echo "Project Codex output-style bridge:"
251
+ echo " source: unavailable"
252
+ echo " target: ${PROJECT_OUTPUT_STYLE_TARGET_FILE}"
253
+ echo " status: active output style has no .claude/output-styles/*.md bridge source"
254
+ STATUS_FAILURES=$(( STATUS_FAILURES + 1 ))
255
+ fi
256
+ }
257
+
258
+ is_hq_root_like() {
259
+ local path="$1"
260
+ [[ "${path}" != *'{'* ]] || return 1
261
+ [[ "${path}" != *'}'* ]] || return 1
262
+ [[ "${path}" != "/Documents/HQ" ]] || return 1
263
+ [[ "$(basename "${path}")" == "HQ" ]]
264
+ }
265
+
266
+ bridge_target_is_repairable() {
267
+ local current_target="$1"
268
+ local source="$2"
269
+ local expected_suffix target_root
270
+
271
+ expected_suffix="${source#"${HQ_ROOT}"}"
272
+ target_root="$(strip_known_hq_subpath "${current_target}" 2>/dev/null || true)"
273
+
274
+ [[ -n "${target_root}" ]] || return 1
275
+ is_hq_root_like "${target_root}" || return 1
276
+ [[ "${target_root}" != "${HQ_ROOT}" ]] || return 1
277
+ [[ "${current_target#"${target_root}"}" == "${expected_suffix}" ]]
278
+ }
279
+
280
+ print_link_status() {
281
+ local label="$1"
282
+ local source="$2"
283
+ local target="$3"
284
+
285
+ echo "${label}:"
286
+ echo " source: ${source}"
287
+ echo " target: ${target}"
288
+
289
+ if [[ -L "${target}" ]]; then
290
+ local resolved_target
291
+ resolved_target="$(normalize_link_target "${target}")"
292
+ echo " bridge: installed"
293
+ echo " points to: ${resolved_target}"
294
+ if [[ "${resolved_target}" == "${source}" ]]; then
295
+ echo " status: healthy"
296
+ elif bridge_target_is_repairable "${resolved_target}" "${source}"; then
297
+ echo " status: stale HQ root (repairable)"
298
+ STATUS_FAILURES=$(( STATUS_FAILURES + 1 ))
299
+ else
300
+ echo " status: unexpected target"
301
+ STATUS_FAILURES=$(( STATUS_FAILURES + 1 ))
302
+ fi
303
+ elif [[ -e "${target}" ]]; then
304
+ echo " bridge: blocked"
305
+ echo " status: target exists and is not a symlink"
306
+ STATUS_FAILURES=$(( STATUS_FAILURES + 1 ))
307
+ else
308
+ echo " bridge: not installed"
309
+ STATUS_FAILURES=$(( STATUS_FAILURES + 1 ))
310
+ fi
311
+ }
312
+
313
+ repair_or_create_symlink() {
314
+ local label="$1"
315
+ local source="$2"
316
+ local target="$3"
317
+
318
+ mkdir -p "$(dirname "${target}")"
319
+
320
+ if [[ -L "${target}" ]]; then
321
+ local resolved_target
322
+ resolved_target="$(normalize_link_target "${target}")"
323
+ if [[ "${resolved_target}" == "${source}" ]]; then
324
+ echo "${label} already installed."
325
+ return
326
+ fi
327
+
328
+ if bridge_target_is_repairable "${resolved_target}" "${source}"; then
329
+ if (( DRY_RUN )); then
330
+ echo "Would repair ${label}: ${resolved_target} -> ${source}"
331
+ return
332
+ fi
333
+ rm "${target}"
334
+ ln -s "${source}" "${target}"
335
+ echo "Repaired ${label}: ${resolved_target} -> ${source}"
336
+ return
337
+ fi
338
+
339
+ echo "Refusing to replace existing symlink: ${target} -> ${resolved_target}" >&2
340
+ exit 1
341
+ fi
342
+
343
+ if [[ -e "${target}" ]]; then
344
+ echo "Refusing to overwrite existing path: ${target}" >&2
345
+ exit 1
346
+ fi
347
+
348
+ if (( DRY_RUN )); then
349
+ echo "Would install ${label}: ${target} -> ${source}"
350
+ return
351
+ fi
352
+
353
+ ln -s "${source}" "${target}"
354
+ echo "Installed ${label}."
355
+ }
356
+
357
+ config_files() {
358
+ for file in \
359
+ "${HQ_ROOT}/.mcp.json" \
360
+ "${HQ_ROOT}/.claude/settings.json" \
361
+ "${HQ_ROOT}/.claude/settings.local.json" \
362
+ "${HQ_ROOT}/.codex/config.toml" \
363
+ "${HQ_ROOT}/.Codex/config.toml"
364
+ do
365
+ [[ -f "${file}" ]] && printf '%s\n' "${file}"
366
+ done
367
+ }
368
+
369
+ extract_hq_roots_from_file() {
370
+ local file="$1"
371
+ grep -Eoh '/[^"[:space:]]+/HQ(/|$)' "${file}" 2>/dev/null | sed 's#/$##' || true
372
+ }
373
+
374
+ collect_stale_roots() {
375
+ local include_explicit="${1:-0}"
376
+ local roots_file
377
+ roots_file="$(mktemp)"
378
+
379
+ if (( include_explicit )); then
380
+ for root in "${OLD_ROOTS[@]-}"; do
381
+ [[ -n "${root}" ]] && printf '%s\n' "${root}" >> "${roots_file}"
382
+ done
383
+ fi
384
+
385
+ for target in \
386
+ "${GLOBAL_SKILLS_TARGET_DIR}" \
387
+ "${GLOBAL_AGENTS_SKILLS_TARGET_DIR}" \
388
+ "${REPO_AGENTS_SKILLS_TARGET_DIR}" \
389
+ "${PROJECT_CLAUDE_TARGET_DIR}" \
390
+ "${PROJECT_PROMPTS_TARGET_DIR}" \
391
+ "${PROJECT_OUTPUT_STYLE_TARGET_FILE}" \
392
+ "${LEGACY_CLAUDE_TARGET_DIR}" \
393
+ "${LEGACY_PROMPTS_TARGET_DIR}" \
394
+ "${LEGACY_OUTPUT_STYLE_TARGET_FILE}"
395
+ do
396
+ if [[ -L "${target}" ]]; then
397
+ strip_known_hq_subpath "$(normalize_link_target "${target}")" 2>/dev/null >> "${roots_file}" || true
398
+ fi
399
+ done
400
+
401
+ while IFS= read -r file; do
402
+ extract_hq_roots_from_file "${file}" >> "${roots_file}"
403
+ done < <(config_files)
404
+
405
+ sort -u "${roots_file}" | while IFS= read -r root; do
406
+ [[ -n "${root}" ]] || continue
407
+ [[ "${root}" != "${HQ_ROOT}" ]] || continue
408
+ is_hq_root_like "${root}" || continue
409
+ printf '%s\n' "${root}"
410
+ done
411
+
412
+ rm -f "${roots_file}"
413
+ }
414
+
415
+ print_stale_root_report() {
416
+ local roots
417
+ roots="$(collect_stale_roots 0)"
418
+
419
+ if [[ -z "${roots}" ]]; then
420
+ echo "Stale HQ roots: none detected"
421
+ return
422
+ fi
423
+
424
+ echo "Stale HQ roots detected:"
425
+ printf '%s\n' "${roots}" | sed 's/^/ - /'
426
+ }
427
+
428
+ rewrite_local_config_roots() {
429
+ local roots rewritten_any=0
430
+ roots="$(collect_stale_roots 1)"
431
+
432
+ if [[ -z "${roots}" ]]; then
433
+ echo "No stale local config roots to rewrite."
434
+ return
435
+ fi
436
+
437
+ while IFS= read -r file; do
438
+ local changed_file=0
439
+ while IFS= read -r old_root; do
440
+ [[ -n "${old_root}" ]] || continue
441
+ if grep -qF "${old_root}" "${file}"; then
442
+ if (( DRY_RUN )); then
443
+ echo "Would rewrite ${file}: ${old_root} -> ${HQ_ROOT}"
444
+ else
445
+ OLD_ROOT="${old_root}" NEW_ROOT="${HQ_ROOT}" perl -0pi -e 's/\Q$ENV{OLD_ROOT}\E/$ENV{NEW_ROOT}/g' "${file}"
446
+ changed_file=1
447
+ fi
448
+ fi
449
+ done <<< "${roots}"
450
+
451
+ if (( changed_file )); then
452
+ echo "Rewrote local config paths in ${file}."
453
+ rewritten_any=1
454
+ fi
455
+ done < <(config_files)
456
+
457
+ if (( ! rewritten_any && ! DRY_RUN )); then
458
+ echo "No local config files needed rewriting."
459
+ fi
460
+ }
461
+
462
+ print_status() {
463
+ local skill_total skill_with skill_without
464
+ skill_total="$(skill_count)"
465
+ skill_with="$(openai_yaml_count)"
466
+ skill_without=$(( skill_total - skill_with ))
467
+ STATUS_FAILURES=0
468
+
469
+ echo "HQ Claude source: ${CLAUDE_SOURCE_DIR}"
470
+ echo "Skills in source: ${skill_total} (${skill_with} with agents/openai.yaml, ${skill_without} without)"
471
+ echo "Hooks in source: $(hook_count)"
472
+ echo "Policies in source: $(policy_count)"
473
+ echo
474
+
475
+ print_link_status "Global skills bridge (legacy)" "${SKILLS_SOURCE_DIR}" "${GLOBAL_SKILLS_TARGET_DIR}"
476
+ echo
477
+ print_link_status "Global agents skills bridge" "${SKILLS_SOURCE_DIR}" "${GLOBAL_AGENTS_SKILLS_TARGET_DIR}"
478
+ echo
479
+ print_link_status "Repo agents skills bridge" "${SKILLS_SOURCE_DIR}" "${REPO_AGENTS_SKILLS_TARGET_DIR}"
480
+ echo
481
+ print_link_status "Project Claude mirror" "${CLAUDE_SOURCE_DIR}" "${PROJECT_CLAUDE_TARGET_DIR}"
482
+ echo
483
+ print_output_style_status
484
+
485
+ if [[ -e "${LEGACY_CODEX_DIR}" || -L "${LEGACY_CLAUDE_TARGET_DIR}" || -L "${LEGACY_PROMPTS_TARGET_DIR}" ]]; then
486
+ echo
487
+ print_link_status "Legacy .Codex Claude mirror" "${CLAUDE_SOURCE_DIR}" "${LEGACY_CLAUDE_TARGET_DIR}"
488
+ fi
489
+
490
+ echo
491
+ print_stale_root_report
492
+
493
+ return "${STATUS_FAILURES}"
494
+ }
495
+
496
+ validate_sources() {
497
+ [[ -d "${SKILLS_SOURCE_DIR}" ]] || fail "Missing skills source directory: ${SKILLS_SOURCE_DIR}"
498
+ [[ -d "${CLAUDE_SOURCE_DIR}" ]] || fail "Missing Claude source directory: ${CLAUDE_SOURCE_DIR}"
499
+ }
500
+
501
+ install_bridge() {
502
+ local output_style_source
503
+
504
+ validate_sources
505
+ output_style_source="$(resolve_output_style_source_file)" || fail "Active outputStyle must have a matching ${OUTPUT_STYLES_SOURCE_DIR}/<style>.md file."
506
+
507
+ repair_or_create_symlink "global Codex skill bridge (legacy)" "${SKILLS_SOURCE_DIR}" "${GLOBAL_SKILLS_TARGET_DIR}"
508
+ repair_or_create_symlink "global agents skill bridge" "${SKILLS_SOURCE_DIR}" "${GLOBAL_AGENTS_SKILLS_TARGET_DIR}"
509
+ repair_or_create_symlink "repo agents skill bridge" "${SKILLS_SOURCE_DIR}" "${REPO_AGENTS_SKILLS_TARGET_DIR}"
510
+ repair_or_create_symlink "project Codex Claude mirror" "${CLAUDE_SOURCE_DIR}" "${PROJECT_CLAUDE_TARGET_DIR}"
511
+ repair_or_create_symlink "project Codex output-style bridge" "${output_style_source}" "${PROJECT_OUTPUT_STYLE_TARGET_FILE}"
512
+
513
+ if [[ -e "${LEGACY_CODEX_DIR}" || -L "${LEGACY_CLAUDE_TARGET_DIR}" || -L "${LEGACY_PROMPTS_TARGET_DIR}" ]]; then
514
+ repair_or_create_symlink "legacy .Codex Claude mirror" "${CLAUDE_SOURCE_DIR}" "${LEGACY_CLAUDE_TARGET_DIR}"
515
+ repair_or_create_symlink "legacy .Codex output-style bridge" "${output_style_source}" "${LEGACY_OUTPUT_STYLE_TARGET_FILE}"
516
+ fi
517
+
518
+ if (( REPAIR_LOCAL_CONFIG )); then
519
+ echo
520
+ rewrite_local_config_roots
521
+ fi
522
+
523
+ echo
524
+ print_status
525
+ }
526
+
527
+ doctor_bridge() {
528
+ validate_sources
529
+ REPAIR_LOCAL_CONFIG=1
530
+ install_bridge
531
+ }
532
+
533
+ main() {
534
+ parse_args "$@"
535
+ configure_paths
536
+
537
+ case "${COMMAND}" in
538
+ status)
539
+ print_status
540
+ ;;
541
+ install)
542
+ install_bridge
543
+ ;;
544
+ doctor)
545
+ doctor_bridge
546
+ ;;
547
+ esac
548
+ }
549
+
550
+ main "$@"