@higherdev/cli 0.14.4 → 0.14.5

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.
package/README.md CHANGED
@@ -67,6 +67,10 @@ branch, bootstraps an empty repository unless `--no-bootstrap` is set, and invit
67
67
  the repository is missing, approve private creation interactively, use `--create` to force it, or
68
68
  `--no-create` to fail. Fully flagged calls remain non-interactive for scripts and Mel.
69
69
 
70
+ `hd env set` and `hd env rm` also update GitHub Actions secrets on the current workspace repository.
71
+ They require the operator's authenticated `gh` account to have repository admin permission. Secret values are sent
72
+ to `gh` through stdin and are never printed.
73
+
70
74
  Inside the TUI, use `/board`, `/inbox`, `/ticket`, `/queue`, `/cancel`, `/epic new`,
71
75
  `/epic approve`, `/epics`, `/architect` (or `/plan`), `/decide`, `/agents add`, `/agents rm`, `/env`, `/settings`, `/workspace`,
72
76
  `/workspace new`, `/workspace set`, `/workspace rotate-key`, `/feed`,
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import { loadConfig } from "./config.js";
8
8
  import { epicProgressRows, readEpicSpec } from "./epics.js";
9
9
  import { banner, c, statusChip, table, truncate, usage } from "./out.js";
10
10
  import { WORKSPACE_USAGE, workspaceNew, workspaceRotateKey, workspaceSet, workspaceUse } from "./workspace-commands.js";
11
+ import { defaultGh, requireAdminRepo } from "./workspace-preflight.js";
11
12
  function fail(message) {
12
13
  console.error(message);
13
14
  process.exit(1);
@@ -349,7 +350,18 @@ async function cmdCaps(argv) {
349
350
  const result = await updateCaps({ [provider]: cap });
350
351
  console.log(`${provider} ${result.provider_caps[provider]}`);
351
352
  }
352
- async function cmdEnv(argv) {
353
+ async function currentWorkspaceRepo() {
354
+ const current = loadConfig().slug;
355
+ const workspace = (await listWorkspaces()).find((item) => item.slug === current);
356
+ if (!workspace)
357
+ throw new Error(`No workspace ${current}.`);
358
+ return workspace.repo;
359
+ }
360
+ function githubSecretMissing(error) {
361
+ const message = error instanceof Error ? error.message : String(error);
362
+ return /404|not found|does not exist/i.test(message);
363
+ }
364
+ export async function cmdEnv(argv, deps = {}) {
353
365
  const [action, ...args] = argv;
354
366
  if (action === "ls") {
355
367
  const { env } = await listWorkspaceEnv();
@@ -359,18 +371,43 @@ async function cmdEnv(argv) {
359
371
  return;
360
372
  }
361
373
  if (action === "set" && args.length) {
374
+ const assignments = [];
362
375
  for (const assignment of args) {
363
376
  const at = assignment.indexOf("=");
364
377
  if (at < 1)
365
378
  fail("usage: hd env set NAME=VALUE [NAME=VALUE...]");
366
- await setWorkspaceEnv(assignment.slice(0, at), assignment.slice(at + 1));
379
+ assignments.push({ name: assignment.slice(0, at), value: assignment.slice(at + 1) });
367
380
  }
368
- console.log(`set ${args.length} variable${args.length === 1 ? "" : "s"}`);
381
+ for (const assignment of assignments)
382
+ await setWorkspaceEnv(assignment.name, assignment.value);
383
+ const repo = await currentWorkspaceRepo();
384
+ const gh = deps.gh ?? defaultGh;
385
+ await requireAdminRepo(repo, gh);
386
+ for (const assignment of assignments) {
387
+ try {
388
+ await gh(["secret", "set", assignment.name, "--repo", repo], assignment.value);
389
+ }
390
+ catch {
391
+ throw new Error(`Workspace has ${assignment.name}, but GitHub Actions on ${repo} does not.`);
392
+ }
393
+ }
394
+ console.log(`synced ${assignments.map(({ name }) => name).join(", ")} to ${repo}`);
369
395
  return;
370
396
  }
371
397
  if (action === "rm" && args.length === 1) {
372
- await removeWorkspaceEnv(args[0]);
373
- console.log(`removed ${args[0]}`);
398
+ const name = args[0];
399
+ await removeWorkspaceEnv(name);
400
+ const repo = await currentWorkspaceRepo();
401
+ const gh = deps.gh ?? defaultGh;
402
+ await requireAdminRepo(repo, gh);
403
+ try {
404
+ await gh(["secret", "delete", name, "--repo", repo, "--yes"]);
405
+ }
406
+ catch (error) {
407
+ if (!githubSecretMissing(error))
408
+ throw new Error(`Workspace removed ${name}, but GitHub Actions on ${repo} may still have it.`);
409
+ }
410
+ console.log(`synced removal of ${name} to ${repo}`);
374
411
  return;
375
412
  }
376
413
  fail("usage: hd env ls | set NAME=VALUE [NAME=VALUE...] | rm NAME");
@@ -437,7 +474,7 @@ export async function main(argv = process.argv.slice(2), deps = {}) {
437
474
  return;
438
475
  }
439
476
  if (cmd === "env") {
440
- await cmdEnv(rest);
477
+ await cmdEnv(rest, deps);
441
478
  return;
442
479
  }
443
480
  if (cmd === "pause" || cmd === "off") {
@@ -19,14 +19,39 @@ function errorMessage(error) {
19
19
  const value = error;
20
20
  return value.stderr?.trim() || value.message || String(error);
21
21
  }
22
- export async function defaultGh(args) {
22
+ export async function defaultGh(args, stdin) {
23
23
  try {
24
+ if (stdin !== undefined) {
25
+ return await new Promise((resolve, reject) => {
26
+ const child = execFile("gh", args, { encoding: "utf8", maxBuffer: 1024 * 1024 }, (error, stdout, stderr) => error ? reject(new Error(stderr.trim() || error.message)) : resolve(stdout));
27
+ child.stdin?.end(stdin);
28
+ });
29
+ }
24
30
  return (await exec("gh", args, { encoding: "utf8", maxBuffer: 1024 * 1024 })).stdout;
25
31
  }
26
32
  catch (error) {
27
33
  throw new Error(errorMessage(error));
28
34
  }
29
35
  }
36
+ export async function requireAdminRepo(repo, gh = defaultGh) {
37
+ try {
38
+ await gh(["--version"]);
39
+ }
40
+ catch {
41
+ throw new Error("GitHub CLI is unavailable. Install it if needed, then run `gh auth login`.");
42
+ }
43
+ let view;
44
+ try {
45
+ view = JSON.parse(await gh(["repo", "view", repo, "--json", "viewerPermission"]));
46
+ }
47
+ catch (error) {
48
+ throw new Error(`GitHub repository ${repo} was not found or is inaccessible: ${errorMessage(error)}`);
49
+ }
50
+ const permission = view.viewerPermission || "";
51
+ if (permission.toUpperCase() !== "ADMIN") {
52
+ throw new Error(`Repository admin permission is required; viewer has ${permission || "none"}.`);
53
+ }
54
+ }
30
55
  async function repoView(repo, gh) {
31
56
  return JSON.parse(await gh(["repo", "view", repo, "--json", "defaultBranchRef,isEmpty,viewerPermission"]));
32
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@higherdev/cli",
3
- "version": "0.14.4",
3
+ "version": "0.14.5",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "hd": "dist/index.js"