@indigoai-us/hq-cli 5.77.14 → 5.78.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 (308) hide show
  1. package/CHANGELOG.md +23 -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/members.js +16 -5
  31. package/dist/commands/pack-install.d.ts +14 -0
  32. package/dist/commands/pack-install.js +42 -2
  33. package/dist/commands/pkg-install.js +39 -2
  34. package/dist/commands/run.js +6 -2
  35. package/dist/commands/secrets.js +120 -65
  36. package/dist/main.js +6 -0
  37. package/dist/utils/api-key-command-gate.d.ts +45 -0
  38. package/dist/utils/api-key-command-gate.js +51 -0
  39. package/dist/utils/hq-roots.d.ts +91 -0
  40. package/dist/utils/hq-roots.js +212 -0
  41. package/dist/utils/resolve-vault-credential.d.ts +63 -3
  42. package/dist/utils/resolve-vault-credential.js +152 -6
  43. package/dist/utils/run-bundled-script.d.ts +66 -0
  44. package/dist/utils/run-bundled-script.js +80 -0
  45. package/dist/utils/vault-api.d.ts +21 -0
  46. package/dist/utils/vault-api.js +74 -3
  47. package/package.json +7 -1
  48. package/.claude/policies/hq-cli-interactive-reads-use-sts-vend.md +0 -49
  49. package/.github/workflows/ci.yml +0 -46
  50. package/.github/workflows/publish.yml +0 -36
  51. package/.github/workflows/scripts/smoke-test-pkg.sh +0 -97
  52. package/e2e/cli.test.ts +0 -128
  53. package/eslint.config.js +0 -37
  54. package/pnpm-workspace.yaml +0 -4
  55. package/scripts/chmod-bins.mjs +0 -49
  56. package/scripts/generate-dsn.mjs +0 -26
  57. package/scripts/generate-scan-packages-table.mjs +0 -113
  58. package/scripts/smoke-sources-signals.sh +0 -103
  59. package/src/bin/hq-auth-refresh.ts +0 -43
  60. package/src/cli-version.ts +0 -13
  61. package/src/commands/__fixtures__/make-tar.ts +0 -126
  62. package/src/commands/_patterns.ts +0 -10
  63. package/src/commands/add.ts +0 -75
  64. package/src/commands/agents.test.ts +0 -527
  65. package/src/commands/agents.ts +0 -923
  66. package/src/commands/api-keys.test.ts +0 -291
  67. package/src/commands/api-keys.ts +0 -382
  68. package/src/commands/artifact-verify.test.ts +0 -177
  69. package/src/commands/auth.test.ts +0 -82
  70. package/src/commands/auth.ts +0 -213
  71. package/src/commands/billing.test.ts +0 -158
  72. package/src/commands/billing.ts +0 -146
  73. package/src/commands/channels.test.ts +0 -74
  74. package/src/commands/channels.ts +0 -91
  75. package/src/commands/cloud-demote.test.ts +0 -401
  76. package/src/commands/cloud-demote.ts +0 -278
  77. package/src/commands/cloud-provision.test.ts +0 -1117
  78. package/src/commands/cloud-provision.ts +0 -942
  79. package/src/commands/cloud.pull-all.test.ts +0 -711
  80. package/src/commands/cloud.pull-per-company.test.ts +0 -188
  81. package/src/commands/cloud.push-all.test.ts +0 -485
  82. package/src/commands/cloud.scope-excluded-warning.test.ts +0 -22
  83. package/src/commands/cloud.selectors.test.ts +0 -208
  84. package/src/commands/cloud.status.test.ts +0 -160
  85. package/src/commands/cloud.test.ts +0 -41
  86. package/src/commands/cloud.ts +0 -2130
  87. package/src/commands/company.test.ts +0 -202
  88. package/src/commands/company.ts +0 -148
  89. package/src/commands/creators.test.ts +0 -60
  90. package/src/commands/creators.ts +0 -117
  91. package/src/commands/crm.test.ts +0 -179
  92. package/src/commands/crm.ts +0 -236
  93. package/src/commands/db-migrate.ts +0 -55
  94. package/src/commands/db-provision.ts +0 -114
  95. package/src/commands/db-sql.ts +0 -124
  96. package/src/commands/db-status.ts +0 -108
  97. package/src/commands/db.ts +0 -26
  98. package/src/commands/dm.test.ts +0 -748
  99. package/src/commands/dm.ts +0 -1226
  100. package/src/commands/feedback.test.ts +0 -413
  101. package/src/commands/feedback.ts +0 -169
  102. package/src/commands/files-browse.test.ts +0 -1249
  103. package/src/commands/files-browse.ts +0 -1506
  104. package/src/commands/files-delete.test.ts +0 -484
  105. package/src/commands/files-recovery.test.ts +0 -370
  106. package/src/commands/files.test.ts +0 -722
  107. package/src/commands/files.ts +0 -1446
  108. package/src/commands/group-grants.test.ts +0 -330
  109. package/src/commands/group-grants.ts +0 -455
  110. package/src/commands/groups.test.ts +0 -44
  111. package/src/commands/groups.ts +0 -368
  112. package/src/commands/integrations.test.ts +0 -633
  113. package/src/commands/integrations.ts +0 -507
  114. package/src/commands/list.ts +0 -85
  115. package/src/commands/login.ts +0 -52
  116. package/src/commands/logout.ts +0 -30
  117. package/src/commands/marketplace-install.test.ts +0 -543
  118. package/src/commands/marketplace-security.test.ts +0 -646
  119. package/src/commands/mcp-registration.test.ts +0 -2787
  120. package/src/commands/mcp-registration.ts +0 -2612
  121. package/src/commands/mcp-status.test.ts +0 -483
  122. package/src/commands/mcp-status.ts +0 -575
  123. package/src/commands/mcp-status.us011.test.ts +0 -243
  124. package/src/commands/meetings.test.ts +0 -522
  125. package/src/commands/meetings.ts +0 -789
  126. package/src/commands/members.test.ts +0 -1474
  127. package/src/commands/members.ts +0 -1181
  128. package/src/commands/onboard-identity-guard.test.ts +0 -99
  129. package/src/commands/onboard-identity-guard.ts +0 -103
  130. package/src/commands/onboard-join.test.ts +0 -96
  131. package/src/commands/onboard-join.ts +0 -101
  132. package/src/commands/onboard-warning.test.ts +0 -26
  133. package/src/commands/onboard-warning.ts +0 -12
  134. package/src/commands/onboard.ts +0 -267
  135. package/src/commands/outposts-heartbeat.test.ts +0 -299
  136. package/src/commands/outposts-heartbeat.ts +0 -310
  137. package/src/commands/outposts-replica-sync.test.ts +0 -272
  138. package/src/commands/outposts-self-deploy.test.ts +0 -243
  139. package/src/commands/outposts.test.ts +0 -1039
  140. package/src/commands/outposts.ts +0 -1935
  141. package/src/commands/pack-install-secret-authorization.test.ts +0 -115
  142. package/src/commands/pack-install.test.ts +0 -1469
  143. package/src/commands/pack-install.ts +0 -2256
  144. package/src/commands/pack-update-cache.test.ts +0 -149
  145. package/src/commands/packs-update-api-key.test.ts +0 -105
  146. package/src/commands/packs.test.ts +0 -88
  147. package/src/commands/packs.ts +0 -622
  148. package/src/commands/people.test.ts +0 -807
  149. package/src/commands/people.ts +0 -422
  150. package/src/commands/pkg-install.dispatch.test.ts +0 -103
  151. package/src/commands/pkg-install.ts +0 -221
  152. package/src/commands/pkg-list.test.ts +0 -79
  153. package/src/commands/pkg-list.ts +0 -13
  154. package/src/commands/pkg-remove.ts +0 -71
  155. package/src/commands/pkg-update.ts +0 -189
  156. package/src/commands/publish.test.ts +0 -650
  157. package/src/commands/publish.ts +0 -580
  158. package/src/commands/reindex.test.ts +0 -259
  159. package/src/commands/reindex.ts +0 -274
  160. package/src/commands/rescue.test.ts +0 -39
  161. package/src/commands/rescue.ts +0 -210
  162. package/src/commands/run.env-local.test.ts +0 -88
  163. package/src/commands/run.test.ts +0 -45
  164. package/src/commands/run.ts +0 -190
  165. package/src/commands/safe-extract.test.ts +0 -459
  166. package/src/commands/safe-extract.ts +0 -444
  167. package/src/commands/secrets-scope.test.ts +0 -56
  168. package/src/commands/secrets-scope.ts +0 -32
  169. package/src/commands/secrets.parse-destination.test.ts +0 -38
  170. package/src/commands/secrets.test.ts +0 -2050
  171. package/src/commands/secrets.ts +0 -2249
  172. package/src/commands/signals.ts +0 -351
  173. package/src/commands/skill.test.ts +0 -770
  174. package/src/commands/skill.ts +0 -796
  175. package/src/commands/sources.ts +0 -362
  176. package/src/commands/sync-mode.test.ts +0 -366
  177. package/src/commands/sync-mode.ts +0 -387
  178. package/src/commands/sync-narrow.test.ts +0 -633
  179. package/src/commands/sync-narrow.ts +0 -555
  180. package/src/commands/sync.ts +0 -165
  181. package/src/commands/team-sync.ts +0 -628
  182. package/src/commands/update.ts +0 -71
  183. package/src/commands/whoami.ts +0 -83
  184. package/src/commands/workers.test.ts +0 -158
  185. package/src/commands/workers.ts +0 -301
  186. package/src/index.test.ts +0 -32
  187. package/src/index.ts +0 -20
  188. package/src/lib/db/control-plane.test.ts +0 -59
  189. package/src/lib/db/control-plane.ts +0 -113
  190. package/src/lib/db/local.test.ts +0 -81
  191. package/src/lib/db/local.ts +0 -148
  192. package/src/lib/db/migrate.test.ts +0 -133
  193. package/src/lib/db/migrate.ts +0 -137
  194. package/src/lib/db/paths.test.ts +0 -112
  195. package/src/lib/db/paths.ts +0 -128
  196. package/src/lib/db/remote-engine.test.ts +0 -44
  197. package/src/lib/db/remote-engine.ts +0 -148
  198. package/src/lib/db/remote-sql.test.ts +0 -32
  199. package/src/lib/db/remote-sql.ts +0 -62
  200. package/src/lib/db/sql.test.ts +0 -106
  201. package/src/lib/db/sql.ts +0 -192
  202. package/src/lib/hq-cloud-dep.smoke.test.ts +0 -75
  203. package/src/lib/local-tree-diff.test.ts +0 -301
  204. package/src/lib/local-tree-diff.ts +0 -362
  205. package/src/lib/narrow-hint-banner.test.ts +0 -235
  206. package/src/lib/narrow-hint-banner.ts +0 -212
  207. package/src/lib/plan-limit-nag.test.ts +0 -317
  208. package/src/lib/plan-limit-nag.ts +0 -264
  209. package/src/main.ts +0 -371
  210. package/src/node-preflight.test.ts +0 -60
  211. package/src/node-preflight.ts +0 -67
  212. package/src/outpost/session-heartbeat-bounds.test.ts +0 -195
  213. package/src/outpost/session-heartbeat-guard.test.ts +0 -105
  214. package/src/outpost/session-heartbeat-publisher.test.ts +0 -178
  215. package/src/outpost/session-heartbeat-publisher.ts +0 -186
  216. package/src/outpost/session-heartbeat-retain-guard.test.ts +0 -126
  217. package/src/outpost/session-heartbeat.test.ts +0 -459
  218. package/src/outpost/session-heartbeat.ts +0 -877
  219. package/src/packaging.test.ts +0 -109
  220. package/src/run/__fixtures__/discover-schemas/example.env.schema +0 -4
  221. package/src/run/discover-schemas.test.ts +0 -153
  222. package/src/run/discover-schemas.ts +0 -79
  223. package/src/run/hq-plugin.test.ts +0 -371
  224. package/src/run/hq-plugin.ts +0 -277
  225. package/src/run/varlock-shape.test.ts +0 -57
  226. package/src/schemas/hq-package.schema.json +0 -155
  227. package/src/sentry-before-send.test.ts +0 -359
  228. package/src/sentry-before-send.ts +0 -221
  229. package/src/sentry-epipe.test.ts +0 -37
  230. package/src/sentry-release.test.ts +0 -54
  231. package/src/sentry.test.ts +0 -24
  232. package/src/sentry.ts +0 -54
  233. package/src/strategies/link.ts +0 -62
  234. package/src/strategies/merge.ts +0 -142
  235. package/src/types.ts +0 -146
  236. package/src/utils/__fixtures__/scan-packages.generated-block.sh +0 -23
  237. package/src/utils/auth-error.test.ts +0 -40
  238. package/src/utils/auth-error.ts +0 -42
  239. package/src/utils/billing-gate.test.ts +0 -95
  240. package/src/utils/billing-gate.ts +0 -228
  241. package/src/utils/breadcrumb-buffer.ts +0 -18
  242. package/src/utils/cli-telemetry.test.ts +0 -153
  243. package/src/utils/cli-telemetry.ts +0 -61
  244. package/src/utils/cognito-session.machine.test.ts +0 -109
  245. package/src/utils/cognito-session.refresh.test.ts +0 -84
  246. package/src/utils/cognito-session.test.ts +0 -328
  247. package/src/utils/cognito-session.ts +0 -448
  248. package/src/utils/company-selection-error.test.ts +0 -42
  249. package/src/utils/company-selection-error.ts +0 -45
  250. package/src/utils/contribution-table.ts +0 -83
  251. package/src/utils/environmental-error.test.ts +0 -45
  252. package/src/utils/environmental-error.ts +0 -39
  253. package/src/utils/epipe.test.ts +0 -28
  254. package/src/utils/epipe.ts +0 -29
  255. package/src/utils/expected-cli-error.test.ts +0 -28
  256. package/src/utils/expected-cli-error.ts +0 -39
  257. package/src/utils/feedback-diagnostics.test.ts +0 -183
  258. package/src/utils/feedback-diagnostics.ts +0 -123
  259. package/src/utils/feedback-screenshots.test.ts +0 -134
  260. package/src/utils/feedback-screenshots.ts +0 -124
  261. package/src/utils/feedback-versions.test.ts +0 -98
  262. package/src/utils/feedback-versions.ts +0 -68
  263. package/src/utils/git.ts +0 -74
  264. package/src/utils/integrity.ts +0 -59
  265. package/src/utils/intercepted-process-exit.test.ts +0 -37
  266. package/src/utils/intercepted-process-exit.ts +0 -36
  267. package/src/utils/login-provider.test.ts +0 -42
  268. package/src/utils/login-provider.ts +0 -30
  269. package/src/utils/manifest.test.ts +0 -167
  270. package/src/utils/manifest.ts +0 -131
  271. package/src/utils/pack-contributions.test.ts +0 -603
  272. package/src/utils/pack-contributions.ts +0 -450
  273. package/src/utils/people.ts +0 -215
  274. package/src/utils/registry-client.ts +0 -204
  275. package/src/utils/registry.ts +0 -90
  276. package/src/utils/resolve-vault-credential.test.ts +0 -69
  277. package/src/utils/resolve-vault-credential.ts +0 -60
  278. package/src/utils/sandbox-runner-client.test.ts +0 -279
  279. package/src/utils/sandbox-runner-client.ts +0 -260
  280. package/src/utils/secrets-cache.ts +0 -183
  281. package/src/utils/sentry-identity.ts +0 -45
  282. package/src/utils/settle-with-timeout.test.ts +0 -21
  283. package/src/utils/settle-with-timeout.ts +0 -22
  284. package/src/utils/user-yaml-error.test.ts +0 -24
  285. package/src/utils/user-yaml-error.ts +0 -30
  286. package/src/utils/vault-api.test.ts +0 -536
  287. package/src/utils/vault-api.ts +0 -382
  288. package/src/utils/version-check.test.ts +0 -176
  289. package/src/utils/version-check.ts +0 -155
  290. package/src/utils/version-gate.test.ts +0 -1024
  291. package/src/utils/version-gate.ts +0 -702
  292. package/test/commands/db-tenant-isolation.test.ts +0 -94
  293. package/test/commands/db.test.ts +0 -85
  294. package/test/commands/signals.test.ts +0 -207
  295. package/test/commands/sources.test.ts +0 -231
  296. package/test/e2e/smoke-install-mcp.sh +0 -113
  297. package/test/fixtures/hq-pack-smoke-mcp/mcp/smoke-http.json +0 -1
  298. package/test/fixtures/hq-pack-smoke-mcp/package.yaml +0 -11
  299. package/test/fixtures/signals/action_item/sample.md +0 -16
  300. package/test/fixtures/signals/summary/sample.md +0 -12
  301. package/test/fixtures/sources/meetings/sample.md +0 -25
  302. package/test/helpers/cli-runner.ts +0 -150
  303. package/test/helpers/s3-list-mock.ts +0 -79
  304. package/test/helpers/vault-service-mock.ts +0 -295
  305. package/test/sources-signals/smoke.test.ts +0 -228
  306. package/tsconfig.json +0 -20
  307. package/vitest.config.ts +0 -11
  308. package/vitest.e2e.config.ts +0 -7
@@ -1,796 +0,0 @@
1
- /**
2
- * `hq skill` subcommand group (US-017).
3
- *
4
- * Terminal / scriptable access to the skill collaboration loop:
5
- *
6
- * hq skill suggest <uid|path> Propose a change to a skill from working edits.
7
- * hq skill list-suggestions Show the review inbox (suggestions on skills you own).
8
- * hq skill review <sgn_…> Accept (merge) or decline a pending suggestion.
9
- *
10
- * This is a THIN front-end over the SAME wired hq-pro routes the MCP surface
11
- * (US-007) and the console merge path (US-009) use — there is NO forked
12
- * suggestion or merge logic here. The CLI reads the local working SKILL.md,
13
- * computes the proposed content (+ its base for a diff), and POSTs to:
14
- *
15
- * CREATE POST /v1/files/skills/company/{slug}/{skillUid}/suggestions
16
- * LIST POST /v1/files/skills/company/{slug}/suggestions/list
17
- * ACCEPT POST /v1/files/skills/company/{slug}/{skillUid}/suggestions/{id}/accept
18
- * DECLINE POST /v1/files/skills/company/{slug}/{skillUid}/suggestions/{id}/decline
19
- *
20
- * The skill routes are keyed on the company SLUG (path param, resolved
21
- * server-side via findEntityBySlug) — NOT the companyUid the vault/ACL routes
22
- * use — so this module resolves a slug (from `--company` or the active company)
23
- * and passes it straight through.
24
- *
25
- * Lock semantics (AC3): a suggest against a skill the caller cannot WRITE still
26
- * SUCCEEDS as a proposal. The CREATE route is MEMBER-gated (never write-gated),
27
- * so this command performs NO client-side lock/permission pre-check — it always
28
- * posts and renders whatever the server returns. A locked-out member lands a
29
- * suggestion, never a hard permission error.
30
- *
31
- * Attribution (AC4): the invoking identity (from the Cognito JWT) is the server-
32
- * derived `authorPersonUid`; the CLI never sends an author. An optional
33
- * `--note` rides as `authorNote` (the change's rationale / failure context).
34
- */
35
-
36
- import * as fs from "node:fs";
37
- import * as path from "node:path";
38
- import { createHash } from "node:crypto";
39
- import { Command } from "commander";
40
- import chalk from "chalk";
41
- import yaml from "js-yaml";
42
- import simpleGit from "simple-git";
43
- import { ensureCognitoToken, DEFAULT_HQ_ROOT } from "../utils/cognito-session.js";
44
- import { vaultApiFetch } from "../utils/vault-api.js";
45
-
46
- // ---------------------------------------------------------------------------
47
- // Patterns
48
- // ---------------------------------------------------------------------------
49
-
50
- /**
51
- * A `skl_…` argument to `suggest` is a skill UID (resolve the local file from
52
- * it); anything else is a filesystem path. Lenient on the suffix (the strict
53
- * `skl_<ulid>` shape is `isSkillUid` on the server) so a hand-typed / fixture
54
- * uid still routes to the uid branch.
55
- */
56
- export const SKILL_UID_PATTERN = /^skl_[A-Za-z0-9]+$/;
57
- /** A `sgn_…` suggestion id — the `review` target and the LIST row key. */
58
- export const SUGGESTION_ID_PATTERN = /^sgn_[A-Za-z0-9]+$/;
59
-
60
- const VALID_LIST_STATUSES = ["open", "accepted", "declined", "all"] as const;
61
- type ListStatus = (typeof VALID_LIST_STATUSES)[number];
62
-
63
- // ---------------------------------------------------------------------------
64
- // Pure helpers (exported for unit tests)
65
- // ---------------------------------------------------------------------------
66
-
67
- const FRONTMATTER_RE = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/;
68
-
69
- /**
70
- * Read the top-level `skill_uid` from a SKILL.md's YAML frontmatter. Mirrors
71
- * hq-pro's `parseSkillFrontmatter` (block extraction → YAML parse → read the
72
- * top-level `skill_uid` string). Returns `undefined` when there is no
73
- * frontmatter, it fails to parse, or `skill_uid` is absent / not a `skl_…`
74
- * string. Never throws.
75
- */
76
- export function parseSkillUid(md: string): string | undefined {
77
- const match = md.match(FRONTMATTER_RE);
78
- if (!match) return undefined;
79
- let doc: unknown;
80
- try {
81
- doc = yaml.load(match[1]);
82
- } catch {
83
- return undefined;
84
- }
85
- if (!doc || typeof doc !== "object" || Array.isArray(doc)) return undefined;
86
- const uid = (doc as Record<string, unknown>).skill_uid;
87
- return typeof uid === "string" && SKILL_UID_PATTERN.test(uid) ? uid : undefined;
88
- }
89
-
90
- /** sha256 hex of a string — the base-version fingerprint the server records (AC2). */
91
- export function sha256Hex(content: string): string {
92
- return createHash("sha256").update(content, "utf8").digest("hex");
93
- }
94
-
95
- export interface SuggestionCreateBody {
96
- proposedContent: string;
97
- baseContent?: string;
98
- baseContentHash?: string;
99
- authorNote?: string;
100
- }
101
-
102
- /**
103
- * Build the CREATE request body from the resolved proposed content and an
104
- * optional base. Mirrors the server's two payload shapes:
105
- * - `baseContent` present → the server derives the unified diff + base hash
106
- * (the diff-by-default path). A no-op (base === proposed) is rejected here
107
- * rather than round-tripped to an EmptySuggestion 400.
108
- * - no base → a `full-file` proposal; the server REQUIRES a `baseContentHash`,
109
- * so we fingerprint the proposed content (a "here is my whole file" proposal
110
- * with no base to diff against).
111
- * An empty / whitespace-only note is dropped (kept absent, not blank).
112
- */
113
- export function buildSuggestionCreateBody(input: {
114
- proposedContent: string;
115
- baseContent?: string;
116
- note?: string;
117
- }): SuggestionCreateBody {
118
- const body: SuggestionCreateBody = { proposedContent: input.proposedContent };
119
- if (input.baseContent !== undefined) {
120
- if (input.baseContent === input.proposedContent) {
121
- throw new Error(
122
- "No changes to propose — the working SKILL.md matches its base.",
123
- );
124
- }
125
- body.baseContent = input.baseContent;
126
- } else {
127
- body.baseContentHash = sha256Hex(input.proposedContent);
128
- }
129
- const note = input.note?.trim();
130
- if (note) body.authorNote = note;
131
- return body;
132
- }
133
-
134
- /**
135
- * Map an hq-pro skill route error to a single user-facing line. Pure so the
136
- * status → copy mapping is unit-tested independently of the network. Prefers the
137
- * server's own `error` / `message` (they carry the actionable specifics — e.g.
138
- * "Skill not found", "You need write access to this skill…").
139
- */
140
- export function mapSkillError(status: number, body: Record<string, unknown>): string {
141
- const server =
142
- (typeof body.error === "string" && body.error) ||
143
- (typeof body.message === "string" && body.message) ||
144
- "";
145
- if (status === 401) return "Not authenticated — please run `hq login`";
146
- if (status === 403) return server || "Not authorized";
147
- if (status === 404) return server || "Not found";
148
- if (status === 409) return server || "Conflict — please retry";
149
- if (status === 422) return server || "Company vault not provisioned";
150
- if (status >= 500) return `Server error: ${server || status}`;
151
- return server || `Request failed (${status})`;
152
- }
153
-
154
- /** LIST inbox row shape returned by `suggestionToWire` on the server. */
155
- export interface SuggestionRow {
156
- suggestionId: string;
157
- skillUid: string;
158
- authorPersonUid: string;
159
- status: string;
160
- baseChanged: boolean;
161
- presentation?: string;
162
- unifiedDiff?: string;
163
- fullContent?: string;
164
- baseContentHash?: string;
165
- currentContentHash?: string;
166
- authorNote?: string;
167
- createdAt: string;
168
- path: string;
169
- }
170
-
171
- function shortDate(iso: string): string {
172
- return typeof iso === "string" ? iso.slice(0, 10) : "";
173
- }
174
-
175
- /**
176
- * Render the review inbox as a table (one row per suggestion), optionally
177
- * printing each suggestion's unified diff (or full proposed file, when the base
178
- * drifted / the proposal is full-file) beneath its row. Pure → snapshot-testable.
179
- */
180
- export function formatSuggestionsList(
181
- suggestions: SuggestionRow[],
182
- opts: { showDiff?: boolean } = {},
183
- ): string {
184
- if (suggestions.length === 0) {
185
- return chalk.gray("No suggestions match — the review inbox is empty.");
186
- }
187
- const idW = Math.max(13, ...suggestions.map((s) => s.suggestionId.length));
188
- const skillW = Math.max(8, ...suggestions.map((s) => s.skillUid.length));
189
- const authW = Math.max(6, ...suggestions.map((s) => s.authorPersonUid.length));
190
- const statusW = Math.max(6, ...suggestions.map((s) => s.status.length));
191
-
192
- const lines: string[] = [];
193
- lines.push(
194
- chalk.bold(
195
- [
196
- "SUGGESTION_ID".padEnd(idW),
197
- "SKILL".padEnd(skillW),
198
- "AUTHOR".padEnd(authW),
199
- "STATUS".padEnd(statusW),
200
- "BASE",
201
- "CREATED",
202
- ].join(" "),
203
- ),
204
- );
205
- for (const s of suggestions) {
206
- lines.push(
207
- [
208
- s.suggestionId.padEnd(idW),
209
- s.skillUid.padEnd(skillW),
210
- s.authorPersonUid.padEnd(authW),
211
- s.status.padEnd(statusW),
212
- s.baseChanged ? chalk.yellow("changed") : "ok".padEnd(7),
213
- shortDate(s.createdAt),
214
- ].join(" "),
215
- );
216
- if (s.authorNote) {
217
- lines.push(chalk.dim(` note: ${s.authorNote}`));
218
- }
219
- if (opts.showDiff) {
220
- const diff =
221
- s.presentation === "diff" && s.unifiedDiff
222
- ? s.unifiedDiff
223
- : (s.fullContent ?? "");
224
- const label =
225
- s.presentation === "diff" && s.unifiedDiff
226
- ? "diff"
227
- : `full file${s.baseChanged ? " (base changed)" : ""}`;
228
- lines.push(chalk.dim(` ── ${label} ──`));
229
- for (const dl of diff.split("\n")) {
230
- lines.push(colorizeDiffLine(` ${dl}`));
231
- }
232
- }
233
- }
234
- return lines.join("\n");
235
- }
236
-
237
- /** Colour a unified-diff line (green add / red del / dim header). Pure. */
238
- function colorizeDiffLine(line: string): string {
239
- const trimmed = line.trimStart();
240
- if (trimmed.startsWith("+")) return chalk.green(line);
241
- if (trimmed.startsWith("-")) return chalk.red(line);
242
- if (trimmed.startsWith("@@")) return chalk.cyan(line);
243
- return chalk.dim(line);
244
- }
245
-
246
- // ---------------------------------------------------------------------------
247
- // Company slug + local skill resolution
248
- // ---------------------------------------------------------------------------
249
-
250
- /** Read `.hq/config.json`'s `activeCompany` (mirrors signals/sources). */
251
- export function readActiveCompanySlug(hqRoot: string): string | undefined {
252
- const configPath = path.join(hqRoot, ".hq", "config.json");
253
- if (!fs.existsSync(configPath)) return undefined;
254
- try {
255
- const cfg = JSON.parse(fs.readFileSync(configPath, "utf-8")) as {
256
- activeCompany?: unknown;
257
- };
258
- return typeof cfg.activeCompany === "string" && cfg.activeCompany.length > 0
259
- ? cfg.activeCompany
260
- : undefined;
261
- } catch {
262
- return undefined;
263
- }
264
- }
265
-
266
- /**
267
- * The skill routes are keyed on the company SLUG. Precedence: explicit
268
- * `--company` → `.hq/config.json` activeCompany. Throws with actionable copy
269
- * when neither is available.
270
- */
271
- export function resolveCompanySlug(
272
- flag: string | undefined,
273
- hqRoot: string = DEFAULT_HQ_ROOT,
274
- ): string {
275
- const slug = flag ?? readActiveCompanySlug(hqRoot);
276
- if (!slug) {
277
- throw new Error(
278
- "No company specified. Pass --company <slug> (or set an active company in .hq/config.json).",
279
- );
280
- }
281
- return slug;
282
- }
283
-
284
- export interface ResolvedSkillTarget {
285
- /** Absolute path to the SKILL.md. */
286
- filePath: string;
287
- /** The `skl_…` uid read from its frontmatter (or the uid arg). */
288
- skillUid: string;
289
- /** The working-tree SKILL.md content — the proposed content. */
290
- content: string;
291
- }
292
-
293
- /**
294
- * Recursively find a SKILL.md whose frontmatter `skill_uid` equals `uid`,
295
- * searching each root breadth-first with a bounded depth (skips VCS / build /
296
- * dependency dirs). Returns the first match's absolute path, or null.
297
- */
298
- export function findSkillFileByUid(
299
- roots: string[],
300
- uid: string,
301
- maxDepth = 6,
302
- ): string | null {
303
- const SKIP = new Set([
304
- "node_modules",
305
- ".git",
306
- "dist",
307
- "build",
308
- ".next",
309
- "coverage",
310
- ]);
311
- const queue: Array<{ dir: string; depth: number }> = [];
312
- for (const r of roots) {
313
- if (fs.existsSync(r)) queue.push({ dir: r, depth: 0 });
314
- }
315
- while (queue.length > 0) {
316
- const { dir, depth } = queue.shift()!;
317
- let entries: fs.Dirent[];
318
- try {
319
- entries = fs.readdirSync(dir, { withFileTypes: true });
320
- } catch {
321
- continue;
322
- }
323
- for (const entry of entries) {
324
- const full = path.join(dir, entry.name);
325
- if (entry.isDirectory()) {
326
- if (depth < maxDepth && !SKIP.has(entry.name)) {
327
- queue.push({ dir: full, depth: depth + 1 });
328
- }
329
- } else if (entry.isFile() && entry.name === "SKILL.md") {
330
- let content: string;
331
- try {
332
- content = fs.readFileSync(full, "utf-8");
333
- } catch {
334
- continue;
335
- }
336
- if (parseSkillUid(content) === uid) return full;
337
- }
338
- }
339
- }
340
- return null;
341
- }
342
-
343
- /**
344
- * Resolve a `suggest` target (a `skl_…` uid OR a filesystem path) to the local
345
- * SKILL.md, its uid, and its content. A uid is resolved by scanning the company
346
- * skills dir and the cwd; a path is read directly (a directory → its SKILL.md),
347
- * with the uid read from the file's frontmatter.
348
- */
349
- export function resolveSkillTarget(
350
- target: string,
351
- deps: { cwd: string; hqRoot: string; companySlug: string },
352
- ): ResolvedSkillTarget {
353
- if (SKILL_UID_PATTERN.test(target)) {
354
- const roots = Array.from(
355
- new Set([
356
- path.join(deps.hqRoot, "companies", deps.companySlug, "skills"),
357
- deps.cwd,
358
- ]),
359
- );
360
- const filePath = findSkillFileByUid(roots, target);
361
- if (!filePath) {
362
- throw new Error(
363
- `Could not find a local SKILL.md with skill_uid '${target}' under ${roots.join(", ")}. ` +
364
- "Pass the path to the edited SKILL.md instead.",
365
- );
366
- }
367
- return { filePath, skillUid: target, content: fs.readFileSync(filePath, "utf-8") };
368
- }
369
-
370
- // Filesystem path — accept either a SKILL.md file or a directory containing one.
371
- let filePath = path.resolve(deps.cwd, target);
372
- if (fs.existsSync(filePath) && fs.statSync(filePath).isDirectory()) {
373
- filePath = path.join(filePath, "SKILL.md");
374
- }
375
- if (!fs.existsSync(filePath)) {
376
- throw new Error(
377
- `No SKILL.md found at '${target}'. Pass the path to a SKILL.md (or its directory), or a skl_… uid.`,
378
- );
379
- }
380
- const content = fs.readFileSync(filePath, "utf-8");
381
- const skillUid = parseSkillUid(content);
382
- if (!skillUid) {
383
- throw new Error(
384
- `The SKILL.md at '${filePath}' has no skill_uid in its frontmatter — it is not registered yet. ` +
385
- "Sync / reindex the skill first so it has a stable identity, then suggest against it.",
386
- );
387
- }
388
- return { filePath, skillUid, content };
389
- }
390
-
391
- /**
392
- * Read the committed (HEAD) version of a file from its git repo — the diff base
393
- * for "propose my working changes". Returns null when the file is untracked, not
394
- * in a repo, or git is unavailable (the caller then falls back to full-file, or
395
- * errors under `--diff`). Never throws.
396
- */
397
- export async function readGitBase(filePath: string): Promise<string | null> {
398
- try {
399
- const git = simpleGit(path.dirname(filePath));
400
- const top = (await git.revparse(["--show-toplevel"])).trim();
401
- const rel = path.relative(top, filePath);
402
- return await git.show([`HEAD:${rel}`]);
403
- } catch {
404
- return null;
405
- }
406
- }
407
-
408
- // ---------------------------------------------------------------------------
409
- // Network helpers
410
- // ---------------------------------------------------------------------------
411
-
412
- async function readJsonBody(res: Response): Promise<Record<string, unknown>> {
413
- return (await res.json().catch(() => ({}))) as Record<string, unknown>;
414
- }
415
-
416
- /** Print the mapped error for a non-2xx response and exit(1). Returns never. */
417
- async function failFromResponse(res: Response): Promise<never> {
418
- const body = await readJsonBody(res);
419
- console.error(chalk.red(mapSkillError(res.status, body)));
420
- process.exit(1);
421
- }
422
-
423
- function skillRoutePrefix(slug: string): string {
424
- return `/v1/files/skills/company/${encodeURIComponent(slug)}`;
425
- }
426
-
427
- /** Injectable git-base seam so `suggest` is testable without a real repo. */
428
- export type GitBaseReader = (filePath: string) => Promise<string | null>;
429
-
430
- // ---------------------------------------------------------------------------
431
- // Command registration
432
- // ---------------------------------------------------------------------------
433
-
434
- export function registerSkillCommand(
435
- program: Command,
436
- deps: { gitBase?: GitBaseReader } = {},
437
- ): Command {
438
- const gitBase = deps.gitBase ?? readGitBase;
439
-
440
- const skill = program
441
- .command("skill")
442
- .description("Propose, review, and merge skill changes from the terminal")
443
- .option("--company <slug>", "Company slug (defaults to the active company)");
444
-
445
- // ── suggest ────────────────────────────────────────────────────────────────
446
- skill
447
- .command("suggest <target>")
448
- .description(
449
- "Create a suggestion from a local SKILL.md (a skl_… uid or a path). Never blocked by a skill lock — a suggestion is always a proposal.",
450
- )
451
- .option(
452
- "--diff",
453
- "Require a diff base (git HEAD, or --base): fail if none is found. Default falls back to a full-file proposal.",
454
- )
455
- .option("--base <file>", "Explicit base file to diff the working SKILL.md against")
456
- .option(
457
- "--note <text>",
458
- "Author note — the rationale / failure context attached to the suggestion",
459
- )
460
- .action(
461
- async (
462
- target: string,
463
- opts: { diff?: boolean; base?: string; note?: string },
464
- ) => {
465
- try {
466
- const companySlug = resolveCompanySlug(
467
- skill.opts().company as string | undefined,
468
- );
469
- const resolved = resolveSkillTarget(target, {
470
- cwd: process.cwd(),
471
- hqRoot: DEFAULT_HQ_ROOT,
472
- companySlug,
473
- });
474
-
475
- // Base resolution: explicit --base wins; otherwise diff against git
476
- // HEAD when the file is tracked. No base + --diff → hard error; no
477
- // base without --diff → a full-file proposal.
478
- let baseContent: string | undefined;
479
- let baseSource = "";
480
- if (opts.base !== undefined) {
481
- const basePath = path.resolve(process.cwd(), opts.base);
482
- if (!fs.existsSync(basePath)) {
483
- console.error(chalk.red(`Base file not found: ${opts.base}`));
484
- process.exit(1);
485
- }
486
- baseContent = fs.readFileSync(basePath, "utf-8");
487
- baseSource = opts.base;
488
- } else {
489
- const fromGit = await gitBase(resolved.filePath);
490
- if (fromGit !== null) {
491
- baseContent = fromGit;
492
- baseSource = "git HEAD";
493
- }
494
- }
495
-
496
- if (baseContent === undefined && opts.diff) {
497
- console.error(
498
- chalk.red(
499
- `--diff needs a base, but none was found for ${resolved.filePath}. ` +
500
- "Pass --base <file>, or commit a base version first.",
501
- ),
502
- );
503
- process.exit(1);
504
- }
505
- if (baseContent !== undefined && baseContent === resolved.content) {
506
- console.error(
507
- chalk.red(
508
- `No changes to propose — the working SKILL.md matches its base (${baseSource}).`,
509
- ),
510
- );
511
- process.exit(1);
512
- }
513
-
514
- const body = buildSuggestionCreateBody({
515
- proposedContent: resolved.content,
516
- baseContent,
517
- note: opts.note,
518
- });
519
-
520
- const token = await ensureCognitoToken();
521
- const res = await vaultApiFetch({
522
- token,
523
- path: `${skillRoutePrefix(companySlug)}/${encodeURIComponent(resolved.skillUid)}/suggestions`,
524
- method: "POST",
525
- body: body as unknown as Record<string, unknown>,
526
- });
527
- if (!res.ok) await failFromResponse(res);
528
-
529
- const data = (await res.json()) as {
530
- suggestionId: string;
531
- skillUid: string;
532
- status: string;
533
- authorPersonUid: string;
534
- payloadFormat: string;
535
- authorNote?: string;
536
- };
537
-
538
- console.log(chalk.green(`Suggestion created: ${data.suggestionId}`));
539
- console.log(` Skill: ${data.skillUid}`);
540
- console.log(` Status: ${data.status}`);
541
- // AC4 — attribution is server-derived from the invoking identity.
542
- console.log(` Author: ${data.authorPersonUid}`);
543
- console.log(
544
- ` Change: ${data.payloadFormat === "diff" ? `diff vs ${baseSource || "base"}` : "full file"}`,
545
- );
546
- if (data.authorNote) console.log(` Note: ${data.authorNote}`);
547
- console.log(
548
- chalk.dim(
549
- ` The skill owner can review it: hq skill review ${data.suggestionId} --accept|--decline`,
550
- ),
551
- );
552
- } catch (err) {
553
- console.error(
554
- chalk.red("Error:"),
555
- err instanceof Error ? err.message : String(err),
556
- );
557
- process.exit(1);
558
- }
559
- },
560
- );
561
-
562
- // ── list-suggestions ─────────────────────────────────────────────────────────
563
- skill
564
- .command("list-suggestions")
565
- .description(
566
- "List the review inbox — open suggestions on skills you own (or one skill via --skill)",
567
- )
568
- .option("--skill <skillUid>", "Scope to one skill (skl_…); requires write access on it")
569
- .option(
570
- "--status <status>",
571
- "open | accepted | declined | all (default: open)",
572
- )
573
- .option("--show-diff", "Print each suggestion's unified diff / proposed file")
574
- .option("--json", "Emit raw JSON instead of a table")
575
- .action(
576
- async (opts: {
577
- skill?: string;
578
- status?: string;
579
- showDiff?: boolean;
580
- json?: boolean;
581
- }) => {
582
- try {
583
- const companySlug = resolveCompanySlug(
584
- skill.opts().company as string | undefined,
585
- );
586
- const status = (opts.status ?? "open") as ListStatus;
587
- if (!VALID_LIST_STATUSES.includes(status)) {
588
- console.error(
589
- chalk.red(
590
- `Invalid --status '${opts.status}': must be one of ${VALID_LIST_STATUSES.join(", ")}`,
591
- ),
592
- );
593
- process.exit(1);
594
- }
595
- if (opts.skill !== undefined && !SKILL_UID_PATTERN.test(opts.skill)) {
596
- console.error(chalk.red(`Invalid --skill '${opts.skill}': must be a skl_… uid`));
597
- process.exit(1);
598
- }
599
-
600
- const body: Record<string, unknown> = { status };
601
- if (opts.skill !== undefined) body.skillUid = opts.skill;
602
-
603
- const token = await ensureCognitoToken();
604
- const res = await vaultApiFetch({
605
- token,
606
- path: `${skillRoutePrefix(companySlug)}/suggestions/list`,
607
- method: "POST",
608
- body,
609
- });
610
- if (!res.ok) await failFromResponse(res);
611
-
612
- const data = (await res.json()) as {
613
- suggestions: SuggestionRow[];
614
- count: number;
615
- };
616
- if (opts.json) {
617
- console.log(JSON.stringify(data, null, 2));
618
- return;
619
- }
620
- console.log(formatSuggestionsList(data.suggestions, { showDiff: opts.showDiff }));
621
- } catch (err) {
622
- console.error(
623
- chalk.red("Error:"),
624
- err instanceof Error ? err.message : String(err),
625
- );
626
- process.exit(1);
627
- }
628
- },
629
- );
630
-
631
- // ── review ─────────────────────────────────────────────────────────────────
632
- skill
633
- .command("review <suggestionId>")
634
- .description("Accept (merge) or decline a pending suggestion")
635
- .option("--accept", "Accept the suggestion — merges the proposed change into the skill")
636
- .option("--decline", "Decline the suggestion — leaves the skill unchanged")
637
- .option("--reason <text>", "Reason recorded on a decline")
638
- .option("--skill <skillUid>", "Scope the lookup to one skill (skl_…)")
639
- .option(
640
- "--acknowledge-base-changed",
641
- "On accept: overwrite with the full proposed file even if the skill changed since the suggestion",
642
- )
643
- .action(
644
- async (
645
- suggestionId: string,
646
- opts: {
647
- accept?: boolean;
648
- decline?: boolean;
649
- reason?: string;
650
- skill?: string;
651
- acknowledgeBaseChanged?: boolean;
652
- },
653
- ) => {
654
- try {
655
- if (!SUGGESTION_ID_PATTERN.test(suggestionId)) {
656
- console.error(
657
- chalk.red(`Invalid suggestion id '${suggestionId}': must be a sgn_… id`),
658
- );
659
- process.exit(1);
660
- }
661
- const accept = opts.accept === true;
662
- const decline = opts.decline === true;
663
- if (accept === decline) {
664
- console.error(
665
- chalk.red("Pass exactly one of --accept or --decline."),
666
- );
667
- process.exit(1);
668
- }
669
- if (opts.skill !== undefined && !SKILL_UID_PATTERN.test(opts.skill)) {
670
- console.error(chalk.red(`Invalid --skill '${opts.skill}': must be a skl_… uid`));
671
- process.exit(1);
672
- }
673
-
674
- const companySlug = resolveCompanySlug(
675
- skill.opts().company as string | undefined,
676
- );
677
- const token = await ensureCognitoToken();
678
-
679
- // Resolve the suggestion's skillUid + live path from the SAME LIST route
680
- // the console uses — accept/decline are path↔uid guarded, so the path
681
- // must come from the authoritative row, never guessed. `all` so an
682
- // already-resolved suggestion yields a precise "already <status>" error.
683
- const listBody: Record<string, unknown> = { status: "all" };
684
- if (opts.skill !== undefined) listBody.skillUid = opts.skill;
685
- const listRes = await vaultApiFetch({
686
- token,
687
- path: `${skillRoutePrefix(companySlug)}/suggestions/list`,
688
- method: "POST",
689
- body: listBody,
690
- });
691
- if (!listRes.ok) await failFromResponse(listRes);
692
- const { suggestions } = (await listRes.json()) as {
693
- suggestions: SuggestionRow[];
694
- };
695
- const row = suggestions.find((s) => s.suggestionId === suggestionId);
696
- if (!row) {
697
- console.error(
698
- chalk.red(
699
- `Suggestion ${suggestionId} is not in your review inbox. ` +
700
- "If it targets a skill you don't own, scope the lookup with --skill <skl_…>.",
701
- ),
702
- );
703
- process.exit(1);
704
- }
705
- if (row.status !== "open") {
706
- console.error(
707
- chalk.yellow(`Suggestion ${suggestionId} is already ${row.status} — nothing to do.`),
708
- );
709
- process.exit(1);
710
- }
711
-
712
- if (accept) {
713
- if (!row.path) {
714
- console.error(
715
- chalk.red(
716
- "Could not resolve the live skill path for this suggestion — the skill may have been removed.",
717
- ),
718
- );
719
- process.exit(1);
720
- }
721
- const acceptBody: Record<string, unknown> = { path: row.path };
722
- if (opts.acknowledgeBaseChanged) acceptBody.acknowledgeBaseChanged = true;
723
- const res = await vaultApiFetch({
724
- token,
725
- path: `${skillRoutePrefix(companySlug)}/${encodeURIComponent(row.skillUid)}/suggestions/${encodeURIComponent(suggestionId)}/accept`,
726
- method: "POST",
727
- body: acceptBody,
728
- });
729
- if (!res.ok) {
730
- const errBody = await readJsonBody(res);
731
- // AC4 (US-009): the base drifted — guide the operator to re-run
732
- // with acknowledgement rather than silently overwriting.
733
- if (
734
- res.status === 409 &&
735
- errBody.code === "WRITE_SKILL_SUGGESTION_BASE_CHANGED"
736
- ) {
737
- console.error(
738
- chalk.yellow(
739
- "The skill changed since this suggestion was written. Re-run with " +
740
- "--acknowledge-base-changed to overwrite it with the full proposed file.",
741
- ),
742
- );
743
- process.exit(1);
744
- }
745
- console.error(chalk.red(mapSkillError(res.status, errBody)));
746
- process.exit(1);
747
- }
748
- const data = (await res.json()) as {
749
- skillUid: string;
750
- suggestionId: string;
751
- acceptedBy: string;
752
- };
753
- console.log(
754
- chalk.green("Suggestion accepted — merged and closed."),
755
- );
756
- console.log(` Skill: ${data.skillUid}`);
757
- console.log(` Suggestion: ${data.suggestionId}`);
758
- console.log(` Accepted by: ${data.acceptedBy}`);
759
- return;
760
- }
761
-
762
- // Decline.
763
- const declineBody: Record<string, unknown> = {};
764
- if (opts.reason !== undefined) declineBody.reason = opts.reason;
765
- const res = await vaultApiFetch({
766
- token,
767
- path: `${skillRoutePrefix(companySlug)}/${encodeURIComponent(row.skillUid)}/suggestions/${encodeURIComponent(suggestionId)}/decline`,
768
- method: "POST",
769
- body: declineBody,
770
- });
771
- if (!res.ok) await failFromResponse(res);
772
- const data = (await res.json()) as {
773
- skillUid: string;
774
- suggestionId: string;
775
- declinedBy: string;
776
- reason?: string;
777
- };
778
- console.log(
779
- chalk.green("Suggestion declined — the skill was left unchanged."),
780
- );
781
- console.log(` Skill: ${data.skillUid}`);
782
- console.log(` Suggestion: ${data.suggestionId}`);
783
- console.log(` Declined by: ${data.declinedBy}`);
784
- if (data.reason) console.log(` Reason: ${data.reason}`);
785
- } catch (err) {
786
- console.error(
787
- chalk.red("Error:"),
788
- err instanceof Error ? err.message : String(err),
789
- );
790
- process.exit(1);
791
- }
792
- },
793
- );
794
-
795
- return skill;
796
- }