@indigoai-us/hq-cli 5.9.0 → 5.10.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.10.0] — 2026-05-04
4
+
5
+ ### Added
6
+
7
+ - **`hq cloud demote company <slug>` subcommand** — inverse of
8
+ `hq cloud provision company`. Converts a cloud-backed company back to local-only
9
+ after its entity has been soft-tombstoned in hq-console (Settings → Delete company).
10
+ Removes `companies/<slug>/.hq/config.json`, flips `cloud: true → false` in
11
+ `companies/<slug>/company.yaml`, and strips `cloud_uid` + `bucket_name` from
12
+ `companies/manifest.yaml`. Default safety check verifies the cloud entity is
13
+ `deleted=true`; `--force` skips the check (used by AppBar HQ Sync's Path A after
14
+ it has already verified). All side-effects atomic + idempotent. Exit codes mirror
15
+ `cloud provision` (0 ok, 1 vault HTTP, 2 validation).
16
+
3
17
  ## [5.9.0] — 2026-05-04
4
18
 
5
19
  ### Added
@@ -0,0 +1,90 @@
1
+ /**
2
+ * `hq cloud demote company <slug>` — convert a cloud-backed company back to
3
+ * local-only after hq-pro has soft-tombstoned its entity (Settings → Delete
4
+ * company in hq-console).
5
+ *
6
+ * Inverse of `hq cloud provision company <slug>`. Both commands live here in
7
+ * hq-cli so the file-touching contract (manifest patch + per-folder config
8
+ * write + company.yaml mutation) is single-sourced. AppBar HQ Sync's Path A
9
+ * shells out to this command on the `deleted=true` branch instead of
10
+ * re-implementing the file mutations in Rust.
11
+ *
12
+ * Side-effects (all atomic + idempotent):
13
+ * 1. Remove `companies/<slug>/.hq/config.json`.
14
+ * 2. Flip `cloud: true → false` in `companies/<slug>/company.yaml`. Without
15
+ * this flip the next `provisionCompany` would re-mint a fresh cloud
16
+ * company — exactly what the user just deleted.
17
+ * 3. Strip `cloud_uid` + `bucket_name` from `companies/manifest.yaml`'s
18
+ * `companies.<slug>` entry. The slug entry + other fields stay.
19
+ *
20
+ * Safety check (default on): `findCompanyBySlug` MUST return an entity with
21
+ * `deleted: true`. A live entity, or no entity at all, refuses with code 2.
22
+ * `--force` skips the network call (AppBar passes it because Path A just
23
+ * checked).
24
+ *
25
+ * Exit codes (mirrors cloud-provision):
26
+ * 0 — success or idempotent no-op.
27
+ * 1 — vault HTTP failure during the safety check.
28
+ * 2 — validation (bad slug, missing dir/manifest, cloud not deleted).
29
+ */
30
+ import { Command } from "commander";
31
+ import { type VaultClient } from "./cloud-provision.js";
32
+ /** Final stdout JSON shape. AppBar parses this. */
33
+ export interface DemoteResult {
34
+ ok: boolean;
35
+ company_slug: string;
36
+ /** True if `.hq/config.json` was actually deleted (false if absent). */
37
+ config_removed: boolean;
38
+ /** True if `company.yaml`'s `cloud` was changed (true→false or absent→false). */
39
+ yaml_flipped: boolean;
40
+ /** True if manifest had `cloud_uid` / `bucket_name` to strip. */
41
+ manifest_stripped: boolean;
42
+ /**
43
+ * `true` when the cloud entity verified as `deleted=true`. `null` when
44
+ * `--force` was used and the verify was skipped. (`false` is unreachable —
45
+ * a non-deleted entity throws code 2 before reaching the result.)
46
+ */
47
+ cloud_was_deleted: boolean | null;
48
+ }
49
+ export interface DemoteCompanyOptions {
50
+ slug: string;
51
+ hqRoot: string;
52
+ vaultApiUrl: string;
53
+ /** Skip the `findCompanyBySlug` safety check. AppBar uses this. */
54
+ force?: boolean;
55
+ /** Injected vault HTTP client (override for tests). */
56
+ vaultClient?: VaultClient;
57
+ /** Injected access-token resolver (override for tests). */
58
+ resolveAccessToken?: () => Promise<string>;
59
+ }
60
+ /**
61
+ * Flip `cloud: true → false` in `companies/<slug>/company.yaml`. All other
62
+ * keys + ordering preserved (js-yaml round-trip). Atomic (tmp + rename).
63
+ *
64
+ * Returns true if the file was changed, false if no-op (file missing, or
65
+ * `cloud` was already `false`).
66
+ *
67
+ * NOTE: js-yaml doesn't preserve comments, but this matches what
68
+ * `patchManifest` already does — accepted trade-off.
69
+ */
70
+ export declare function flipCompanyYamlCloudOff(hqRoot: string, slug: string): boolean;
71
+ /**
72
+ * Remove `cloud_uid` + `bucket_name` from `companies.<slug>` in
73
+ * `companies/manifest.yaml`. The slug entry is preserved (other fields like
74
+ * `name`/`status`/`path` stay). Atomic (tmp + rename).
75
+ *
76
+ * Returns true if the file was changed, false if no-op (manifest missing,
77
+ * slug missing, or both fields already absent).
78
+ */
79
+ export declare function stripManifestCloudForSlug(hqRoot: string, slug: string): boolean;
80
+ /**
81
+ * Run the full demote flow. Returns a `DemoteResult` on success; throws
82
+ * `ProvisionError` (codes 1 or 2) on any failure.
83
+ */
84
+ export declare function demoteCompany(options: DemoteCompanyOptions): Promise<DemoteResult>;
85
+ /**
86
+ * Register `demote company <slug>` under the `cloud` command group. Wired in
87
+ * `src/index.ts` alongside `registerCloudProvisionCommands(cloudCmd)`.
88
+ */
89
+ export declare function registerCloudDemoteCommands(program: Command): void;
90
+ //# sourceMappingURL=cloud-demote.d.ts.map
@@ -0,0 +1,193 @@
1
+ /**
2
+ * `hq cloud demote company <slug>` — convert a cloud-backed company back to
3
+ * local-only after hq-pro has soft-tombstoned its entity (Settings → Delete
4
+ * company in hq-console).
5
+ *
6
+ * Inverse of `hq cloud provision company <slug>`. Both commands live here in
7
+ * hq-cli so the file-touching contract (manifest patch + per-folder config
8
+ * write + company.yaml mutation) is single-sourced. AppBar HQ Sync's Path A
9
+ * shells out to this command on the `deleted=true` branch instead of
10
+ * re-implementing the file mutations in Rust.
11
+ *
12
+ * Side-effects (all atomic + idempotent):
13
+ * 1. Remove `companies/<slug>/.hq/config.json`.
14
+ * 2. Flip `cloud: true → false` in `companies/<slug>/company.yaml`. Without
15
+ * this flip the next `provisionCompany` would re-mint a fresh cloud
16
+ * company — exactly what the user just deleted.
17
+ * 3. Strip `cloud_uid` + `bucket_name` from `companies/manifest.yaml`'s
18
+ * `companies.<slug>` entry. The slug entry + other fields stay.
19
+ *
20
+ * Safety check (default on): `findCompanyBySlug` MUST return an entity with
21
+ * `deleted: true`. A live entity, or no entity at all, refuses with code 2.
22
+ * `--force` skips the network call (AppBar passes it because Path A just
23
+ * checked).
24
+ *
25
+ * Exit codes (mirrors cloud-provision):
26
+ * 0 — success or idempotent no-op.
27
+ * 1 — vault HTTP failure during the safety check.
28
+ * 2 — validation (bad slug, missing dir/manifest, cloud not deleted).
29
+ */
30
+
31
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6b5cd717-bba0-5dd4-a743-a070e8a62a6b")}catch(e){}}();
32
+ import * as fs from "node:fs";
33
+ import * as path from "node:path";
34
+ import * as yaml from "js-yaml";
35
+ import chalk from "chalk";
36
+ import { ProvisionError, companyConfigPath, companyDirPath, createDefaultVaultClient, manifestPath, validateManifestAndDir, validateSlug, } from "./cloud-provision.js";
37
+ import { DEFAULT_HQ_ROOT, DEFAULT_VAULT_API_URL, ensureCognitoToken, } from "../utils/cognito-session.js";
38
+ // ── Helpers ──────────────────────────────────────────────────────────────────
39
+ /**
40
+ * Flip `cloud: true → false` in `companies/<slug>/company.yaml`. All other
41
+ * keys + ordering preserved (js-yaml round-trip). Atomic (tmp + rename).
42
+ *
43
+ * Returns true if the file was changed, false if no-op (file missing, or
44
+ * `cloud` was already `false`).
45
+ *
46
+ * NOTE: js-yaml doesn't preserve comments, but this matches what
47
+ * `patchManifest` already does — accepted trade-off.
48
+ */
49
+ export function flipCompanyYamlCloudOff(hqRoot, slug) {
50
+ const yPath = path.join(companyDirPath(hqRoot, slug), "company.yaml");
51
+ if (!fs.existsSync(yPath))
52
+ return false;
53
+ const raw = fs.readFileSync(yPath, "utf-8");
54
+ const parsed = yaml.load(raw) ?? {};
55
+ if (parsed.cloud === false)
56
+ return false;
57
+ parsed.cloud = false;
58
+ const dump = yaml.dump(parsed, { lineWidth: -1, noRefs: true });
59
+ const tmp = `${yPath}.tmp.${process.pid}`;
60
+ fs.writeFileSync(tmp, dump);
61
+ fs.renameSync(tmp, yPath);
62
+ return true;
63
+ }
64
+ /**
65
+ * Remove `cloud_uid` + `bucket_name` from `companies.<slug>` in
66
+ * `companies/manifest.yaml`. The slug entry is preserved (other fields like
67
+ * `name`/`status`/`path` stay). Atomic (tmp + rename).
68
+ *
69
+ * Returns true if the file was changed, false if no-op (manifest missing,
70
+ * slug missing, or both fields already absent).
71
+ */
72
+ export function stripManifestCloudForSlug(hqRoot, slug) {
73
+ const mPath = manifestPath(hqRoot);
74
+ if (!fs.existsSync(mPath))
75
+ return false;
76
+ const raw = fs.readFileSync(mPath, "utf-8");
77
+ const parsed = yaml.load(raw) ?? {};
78
+ const companies = parsed.companies;
79
+ if (!companies || !(slug in companies))
80
+ return false;
81
+ const entry = companies[slug];
82
+ if (!entry || typeof entry !== "object")
83
+ return false;
84
+ const obj = entry;
85
+ const hadCloudUid = "cloud_uid" in obj;
86
+ const hadBucketName = "bucket_name" in obj;
87
+ if (!hadCloudUid && !hadBucketName)
88
+ return false;
89
+ delete obj.cloud_uid;
90
+ delete obj.bucket_name;
91
+ const dump = yaml.dump(parsed, { lineWidth: -1, noRefs: true });
92
+ const tmp = `${mPath}.tmp.${process.pid}`;
93
+ fs.writeFileSync(tmp, dump);
94
+ fs.renameSync(tmp, mPath);
95
+ return true;
96
+ }
97
+ // ── Orchestrator ─────────────────────────────────────────────────────────────
98
+ /**
99
+ * Run the full demote flow. Returns a `DemoteResult` on success; throws
100
+ * `ProvisionError` (codes 1 or 2) on any failure.
101
+ */
102
+ export async function demoteCompany(options) {
103
+ validateSlug(options.slug);
104
+ // Fails with code 2 if the manifest is missing/malformed, the slug is not
105
+ // present under `.companies`, or `companies/<slug>/` doesn't exist on disk.
106
+ // Without this, a `--force` demote against a missing or renamed slug would
107
+ // be a silent no-op (all helpers return false but we'd still report ok=true).
108
+ validateManifestAndDir(options.hqRoot, options.slug);
109
+ let cloudWasDeleted = null;
110
+ if (!options.force) {
111
+ const accessToken = options.resolveAccessToken
112
+ ? await options.resolveAccessToken()
113
+ : await ensureCognitoToken();
114
+ const client = options.vaultClient ??
115
+ createDefaultVaultClient(options.vaultApiUrl, accessToken);
116
+ let entity;
117
+ try {
118
+ entity = await client.findCompanyBySlug(options.slug);
119
+ }
120
+ catch (err) {
121
+ if (err instanceof ProvisionError)
122
+ throw err;
123
+ throw new ProvisionError(1, `Vault GET by-slug failed: ${err instanceof Error ? err.message : String(err)}`);
124
+ }
125
+ if (!entity) {
126
+ throw new ProvisionError(2, `Refusing to demote '${options.slug}': no cloud entity found. Pass --force to demote anyway.`);
127
+ }
128
+ // `deleted` is added by hq-pro and isn't in the static VaultEntity type.
129
+ const deleted = entity.deleted === true;
130
+ if (!deleted) {
131
+ throw new ProvisionError(2, `Refusing to demote '${options.slug}': cloud entity is not deleted (uid=${entity.uid}). Pass --force to demote anyway.`);
132
+ }
133
+ cloudWasDeleted = true;
134
+ }
135
+ const cPath = companyConfigPath(options.hqRoot, options.slug);
136
+ let configRemoved = false;
137
+ if (fs.existsSync(cPath)) {
138
+ fs.rmSync(cPath);
139
+ configRemoved = true;
140
+ }
141
+ const yamlFlipped = flipCompanyYamlCloudOff(options.hqRoot, options.slug);
142
+ const manifestStripped = stripManifestCloudForSlug(options.hqRoot, options.slug);
143
+ return {
144
+ ok: true,
145
+ company_slug: options.slug,
146
+ config_removed: configRemoved,
147
+ yaml_flipped: yamlFlipped,
148
+ manifest_stripped: manifestStripped,
149
+ cloud_was_deleted: cloudWasDeleted,
150
+ };
151
+ }
152
+ // ── Commander wiring ─────────────────────────────────────────────────────────
153
+ /**
154
+ * Register `demote company <slug>` under the `cloud` command group. Wired in
155
+ * `src/index.ts` alongside `registerCloudProvisionCommands(cloudCmd)`.
156
+ */
157
+ export function registerCloudDemoteCommands(program) {
158
+ const demoteCmd = program
159
+ .command("demote")
160
+ .description("Demote a cloud-backed entity back to local-only");
161
+ demoteCmd
162
+ .command("company")
163
+ .description("Demote a cloud-backed company to local-only after the cloud entity " +
164
+ "has been soft-tombstoned in hq-console. Removes .hq/config.json, " +
165
+ "flips company.yaml `cloud: false`, and strips the manifest cloud refs.")
166
+ .argument("<slug>", "Company slug")
167
+ .option("--hq-root <path>", `Local HQ tree root (default: ${DEFAULT_HQ_ROOT})`, DEFAULT_HQ_ROOT)
168
+ .option("--vault-api-url <url>", `Vault API URL (default: ${DEFAULT_VAULT_API_URL})`, DEFAULT_VAULT_API_URL)
169
+ .option("--force", "Skip the safety check that the cloud entity is actually deleted=true. " +
170
+ "AppBar HQ Sync passes this because its Path A just verified.")
171
+ .action(async (slug, options) => {
172
+ try {
173
+ const result = await demoteCompany({
174
+ slug,
175
+ hqRoot: options.hqRoot,
176
+ vaultApiUrl: options.vaultApiUrl,
177
+ force: options.force,
178
+ });
179
+ process.stdout.write(JSON.stringify(result) + "\n");
180
+ process.exit(0);
181
+ }
182
+ catch (err) {
183
+ if (err instanceof ProvisionError) {
184
+ process.stderr.write(chalk.red(`[hq cloud demote] ${err.message}\n`));
185
+ process.exit(err.code);
186
+ }
187
+ process.stderr.write(chalk.red(`[hq cloud demote] Unexpected error: ${err instanceof Error ? err.message : String(err)}\n`));
188
+ process.exit(1);
189
+ }
190
+ });
191
+ }
192
+ //# sourceMappingURL=cloud-demote.js.map
193
+ //# debugId=6b5cd717-bba0-5dd4-a743-a070e8a62a6b
@@ -0,0 +1,53 @@
1
+ import { Command } from "commander";
2
+ export declare const VALID_ROLES: Set<string>;
3
+ export type Role = "owner" | "admin" | "member" | "guest";
4
+ export interface PendingInvite {
5
+ membershipKey: string;
6
+ personUid?: string;
7
+ inviteeEmail?: string;
8
+ companyUid: string;
9
+ role: string;
10
+ status: string;
11
+ inviteToken?: string;
12
+ invitedBy: string;
13
+ invitedAt: string;
14
+ }
15
+ export interface InviteOptions {
16
+ target: string;
17
+ role: string;
18
+ paths?: string;
19
+ companyUid: string;
20
+ callerUid: string;
21
+ token: string;
22
+ }
23
+ export interface InviteResult {
24
+ inviteToken: string;
25
+ magicLink: string;
26
+ membership: {
27
+ role: string;
28
+ status: string;
29
+ };
30
+ }
31
+ export interface DetectedTarget {
32
+ type: "email" | "person";
33
+ value: string;
34
+ }
35
+ export declare function detectTarget(target: string): DetectedTarget | null;
36
+ export declare function shortDate(iso: string): string;
37
+ /**
38
+ * Resolve the caller's personUid by reading their own membership list.
39
+ * The server infers the JWT identity, so this returns the canonical
40
+ * personUid attached to the caller's active memberships.
41
+ */
42
+ export declare function getCallerPersonUid(token: string): Promise<string>;
43
+ /** Send a `/membership/invite` request and return the magic link. */
44
+ export declare function inviteMember(options: InviteOptions): Promise<InviteResult>;
45
+ export declare class InviteHttpError extends Error {
46
+ status: number;
47
+ constructor(status: number, message: string);
48
+ }
49
+ export declare function formatInviteHttpError(status: number, fallback: string): string;
50
+ export declare function listPendingInvites(token: string, companyUid: string): Promise<PendingInvite[]>;
51
+ export declare function revokeInvite(token: string, tokenOrKey: string, companyUid: string): Promise<void>;
52
+ export declare function registerMembersCommand(program: Command): void;
53
+ //# sourceMappingURL=members.d.ts.map
@@ -0,0 +1,240 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1b3646e3-32c8-5601-9dba-1d7c0f6cf972")}catch(e){}}();
3
+ import chalk from "chalk";
4
+ import { ensureCognitoToken } from "../utils/cognito-session.js";
5
+ import { vaultApiFetch, getCompanyUid } from "../utils/vault-api.js";
6
+ const EMAIL_PATTERN = /^[^\s]+@[^\s]+$/;
7
+ const PERSON_UID_PATTERN = /^prs_[A-Za-z0-9_-]+$/;
8
+ export const VALID_ROLES = new Set(["owner", "admin", "member", "guest"]);
9
+ export function detectTarget(target) {
10
+ if (EMAIL_PATTERN.test(target)) {
11
+ return { type: "email", value: target.trim().toLowerCase() };
12
+ }
13
+ if (PERSON_UID_PATTERN.test(target)) {
14
+ return { type: "person", value: target };
15
+ }
16
+ return null;
17
+ }
18
+ export function shortDate(iso) {
19
+ return iso.slice(0, 10);
20
+ }
21
+ /**
22
+ * Resolve the caller's personUid by reading their own membership list.
23
+ * The server infers the JWT identity, so this returns the canonical
24
+ * personUid attached to the caller's active memberships.
25
+ */
26
+ export async function getCallerPersonUid(token) {
27
+ const res = await vaultApiFetch({ token, path: "/membership/me" });
28
+ if (!res.ok) {
29
+ throw new Error("Failed to resolve caller identity — run `hq login` and try again");
30
+ }
31
+ const data = (await res.json());
32
+ const personUid = data.memberships.find((m) => m.personUid)?.personUid;
33
+ if (!personUid) {
34
+ throw new Error("Your account has no person entity yet. Run `hq onboard create-company` or accept an invite first.");
35
+ }
36
+ return personUid;
37
+ }
38
+ /** Send a `/membership/invite` request and return the magic link. */
39
+ export async function inviteMember(options) {
40
+ if (!VALID_ROLES.has(options.role)) {
41
+ throw new Error(`Invalid role '${options.role}': must be one of owner, admin, member, guest`);
42
+ }
43
+ if (options.paths && options.role !== "guest") {
44
+ throw new Error("--paths is only valid with --role guest (allowedPrefixes are only meaningful for the guest role)");
45
+ }
46
+ const detected = detectTarget(options.target);
47
+ if (!detected) {
48
+ throw new Error(`Invalid target '${options.target}': must be an email address or a personUid matching prs_<alphanumeric>`);
49
+ }
50
+ const allowedPrefixes = options.paths
51
+ ? options.paths.split(",").map((p) => p.trim()).filter(Boolean)
52
+ : undefined;
53
+ const body = {
54
+ companyUid: options.companyUid,
55
+ role: options.role,
56
+ invitedBy: options.callerUid,
57
+ };
58
+ if (detected.type === "email")
59
+ body.inviteeEmail = detected.value;
60
+ else
61
+ body.personUid = detected.value;
62
+ if (allowedPrefixes)
63
+ body.allowedPrefixes = allowedPrefixes;
64
+ const res = await vaultApiFetch({
65
+ token: options.token,
66
+ path: "/membership/invite",
67
+ method: "POST",
68
+ body,
69
+ });
70
+ if (!res.ok) {
71
+ const err = (await res.json().catch(() => ({})));
72
+ throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText);
73
+ }
74
+ const data = (await res.json());
75
+ return {
76
+ inviteToken: data.inviteToken,
77
+ magicLink: `hq://accept/${data.inviteToken}`,
78
+ membership: data.membership,
79
+ };
80
+ }
81
+ export class InviteHttpError extends Error {
82
+ status;
83
+ constructor(status, message) {
84
+ super(message);
85
+ this.status = status;
86
+ this.name = "InviteHttpError";
87
+ }
88
+ }
89
+ export function formatInviteHttpError(status, fallback) {
90
+ if (status === 401)
91
+ return "Not authenticated — please run `hq login`";
92
+ if (status === 403) {
93
+ return "Not authorized — only admins and owners can invite members";
94
+ }
95
+ if (status === 409) {
96
+ return "This person already has a membership or pending invite for this company";
97
+ }
98
+ if (status >= 500)
99
+ return `Server error: ${fallback}`;
100
+ return fallback;
101
+ }
102
+ export async function listPendingInvites(token, companyUid) {
103
+ const res = await vaultApiFetch({
104
+ token,
105
+ path: `/membership/company/${encodeURIComponent(companyUid)}/pending`,
106
+ });
107
+ if (!res.ok) {
108
+ const err = (await res.json().catch(() => ({})));
109
+ throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText);
110
+ }
111
+ const data = (await res.json());
112
+ return data.invites;
113
+ }
114
+ export async function revokeInvite(token, tokenOrKey, companyUid) {
115
+ const res = await vaultApiFetch({
116
+ token,
117
+ path: "/membership/revoke",
118
+ method: "POST",
119
+ body: { membershipKey: tokenOrKey, companyUid },
120
+ });
121
+ if (!res.ok) {
122
+ const err = (await res.json().catch(() => ({})));
123
+ throw new InviteHttpError(res.status, err.message ?? err.error ?? res.statusText);
124
+ }
125
+ }
126
+ export function registerMembersCommand(program) {
127
+ const members = program
128
+ .command("members")
129
+ .description("Manage company memberships and invites")
130
+ .option("--company <slug>", "Company slug (resolves to companyUid)");
131
+ members
132
+ .command("invite <target>")
133
+ .description("Invite a person to the company by email or personUid (prints a magic link)")
134
+ .option("--role <role>", "Role for the invitee: owner, admin, member, or guest", "member")
135
+ .option("--paths <prefixes>", "Comma-separated allowed prefixes (only valid with --role guest)")
136
+ .action(async (target, opts) => {
137
+ try {
138
+ const token = await ensureCognitoToken();
139
+ const companySlug = members.opts().company;
140
+ const companyUid = await getCompanyUid(token, companySlug);
141
+ const callerUid = await getCallerPersonUid(token);
142
+ const result = await inviteMember({
143
+ target,
144
+ role: opts.role,
145
+ paths: opts.paths,
146
+ companyUid,
147
+ callerUid,
148
+ token,
149
+ });
150
+ console.log(chalk.green(`Invited ${target} as ${result.membership.role} (status: ${result.membership.status})`));
151
+ console.log();
152
+ console.log(chalk.bold("Magic link:"));
153
+ console.log(` ${result.magicLink}`);
154
+ console.log();
155
+ console.log(chalk.dim("Share this link with the invitee. They can run `hq onboard join --invite-token <token>` to accept."));
156
+ }
157
+ catch (err) {
158
+ if (err instanceof InviteHttpError) {
159
+ console.error(chalk.red(formatInviteHttpError(err.status, err.message)));
160
+ process.exit(1);
161
+ }
162
+ console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
163
+ process.exit(1);
164
+ }
165
+ });
166
+ members
167
+ .command("list")
168
+ .description("List pending invites for the company")
169
+ .action(async () => {
170
+ try {
171
+ const token = await ensureCognitoToken();
172
+ const companySlug = members.opts().company;
173
+ const companyUid = await getCompanyUid(token, companySlug);
174
+ const invites = await listPendingInvites(token, companyUid);
175
+ if (invites.length === 0) {
176
+ console.log(chalk.gray("No pending invites for this company."));
177
+ return;
178
+ }
179
+ const targetW = Math.max(6, ...invites.map((i) => (i.inviteeEmail ?? i.personUid ?? "").length));
180
+ const roleW = Math.max(4, ...invites.map((i) => i.role.length));
181
+ const byW = Math.max(10, ...invites.map((i) => i.invitedBy.length));
182
+ const keyW = Math.max(14, ...invites.map((i) => i.membershipKey.length));
183
+ console.log(chalk.bold([
184
+ "TARGET".padEnd(targetW),
185
+ "ROLE".padEnd(roleW),
186
+ "INVITED_BY".padEnd(byW),
187
+ "INVITED_AT",
188
+ "MEMBERSHIP_KEY".padEnd(keyW),
189
+ ].join(" ")));
190
+ for (const inv of invites) {
191
+ const target = inv.inviteeEmail ?? inv.personUid ?? "";
192
+ console.log([
193
+ target.padEnd(targetW),
194
+ inv.role.padEnd(roleW),
195
+ inv.invitedBy.padEnd(byW),
196
+ shortDate(inv.invitedAt),
197
+ inv.membershipKey.padEnd(keyW),
198
+ ].join(" "));
199
+ }
200
+ }
201
+ catch (err) {
202
+ if (err instanceof InviteHttpError) {
203
+ const msg = err.status === 403
204
+ ? "Not authorized — only admins and owners can list invites"
205
+ : formatInviteHttpError(err.status, err.message);
206
+ console.error(chalk.red(msg));
207
+ process.exit(1);
208
+ }
209
+ console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
210
+ process.exit(1);
211
+ }
212
+ });
213
+ members
214
+ .command("revoke <tokenOrKey>")
215
+ .description("Revoke a pending invite (accepts the inviteToken or membershipKey)")
216
+ .action(async (tokenOrKey) => {
217
+ try {
218
+ const token = await ensureCognitoToken();
219
+ const companySlug = members.opts().company;
220
+ const companyUid = await getCompanyUid(token, companySlug);
221
+ await revokeInvite(token, tokenOrKey, companyUid);
222
+ console.log(chalk.green(`Revoked invite '${tokenOrKey}'`));
223
+ }
224
+ catch (err) {
225
+ if (err instanceof InviteHttpError) {
226
+ const msg = err.status === 403
227
+ ? "Not authorized — only admins and owners can revoke invites"
228
+ : err.status === 404
229
+ ? "Invite not found — it may have already been accepted or revoked"
230
+ : formatInviteHttpError(err.status, err.message);
231
+ console.error(chalk.red(msg));
232
+ process.exit(1);
233
+ }
234
+ console.error(chalk.red("Error:"), err instanceof Error ? err.message : String(err));
235
+ process.exit(1);
236
+ }
237
+ });
238
+ }
239
+ //# sourceMappingURL=members.js.map
240
+ //# debugId=1b3646e3-32c8-5601-9dba-1d7c0f6cf972
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * HQ CLI - Module management, package management, and cloud sync for HQ
4
4
  */
5
5
 
6
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ad8b9496-9cb2-5e12-ae08-5b29ef77c209")}catch(e){}}();
6
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e834c407-cd5c-5dc1-af3b-7f041af651ef")}catch(e){}}();
7
7
  import { Command } from "commander";
8
8
  import { initSentry, Sentry } from "./sentry.js";
9
9
  import { registerAddCommand } from "./commands/add.js";
@@ -12,6 +12,7 @@ import { registerListCommand } from "./commands/list.js";
12
12
  import { registerUpdateCommand } from "./commands/update.js";
13
13
  import { registerCloudCommands } from "./commands/cloud.js";
14
14
  import { registerCloudProvisionCommands } from "./commands/cloud-provision.js";
15
+ import { registerCloudDemoteCommands } from "./commands/cloud-demote.js";
15
16
  import { registerLoginCommand } from "./commands/login.js";
16
17
  import { registerLogoutCommand } from "./commands/logout.js";
17
18
  import { registerWhoamiCommand } from "./commands/whoami.js";
@@ -26,6 +27,7 @@ import { registerSecretsCommand } from "./commands/secrets.js";
26
27
  import { registerRunCommand } from "./commands/run.js";
27
28
  import { registerGroupsCommand } from "./commands/groups.js";
28
29
  import { registerFilesCommand } from "./commands/files.js";
30
+ import { registerMembersCommand } from "./commands/members.js";
29
31
  initSentry();
30
32
  const program = new Command();
31
33
  program
@@ -64,6 +66,7 @@ const cloudCmd = program
64
66
  .command("cloud")
65
67
  .description("Cloud commands — provision entities and manage cloud-backed companies");
66
68
  registerCloudProvisionCommands(cloudCmd);
69
+ registerCloudDemoteCommands(cloudCmd);
67
70
  // Team commands (top-level)
68
71
  registerTeamSyncCommand(program);
69
72
  // Auth commands (top-level — Cognito OAuth)
@@ -79,6 +82,8 @@ registerRunCommand(program);
79
82
  registerGroupsCommand(program);
80
83
  // Files ACL management (subcommand group — hq files share|unshare|acl)
81
84
  registerFilesCommand(program);
85
+ // Membership management (subcommand group — hq members invite|list|revoke)
86
+ registerMembersCommand(program);
82
87
  // Onboarding (top-level — Cognito + vault-service provisioning)
83
88
  registerOnboardCommand(program);
84
89
  (async () => {
@@ -94,4 +99,4 @@ registerOnboardCommand(program);
94
99
  }
95
100
  })();
96
101
  //# sourceMappingURL=index.js.map
97
- //# debugId=ad8b9496-9cb2-5e12-ae08-5b29ef77c209
102
+ //# debugId=e834c407-cd5c-5dc1-af3b-7f041af651ef
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoai-us/hq-cli",
3
- "version": "5.9.0",
3
+ "version": "5.10.1",
4
4
  "description": "HQ by Indigo management CLI — modules and cloud sync",
5
5
  "main": "dist/index.js",
6
6
  "bin": {