@hive3/cli 0.4.0 → 0.5.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.
- package/README.md +117 -15
- package/bin/hive.js +8 -0
- package/package.json +2 -2
- package/skills/hive3/SKILL.md +95 -12
- package/skills/hive3/agents/openai.yaml +1 -1
- package/src/api-client.js +4 -15
- package/src/area-commands.js +12 -49
- package/src/commands.js +50 -25
- package/src/config.js +25 -2
- package/src/conversations-client.js +18 -0
- package/src/conversations-commands.js +103 -0
- package/src/feedback-client.js +15 -0
- package/src/feedback-commands.js +148 -0
- package/src/feedback-replay.js +43 -0
- package/src/login.js +84 -12
- package/src/payments-client.js +13 -0
- package/src/payments-commands.js +127 -0
- package/src/selling-client.js +24 -0
- package/src/selling-commands.js +157 -0
- package/src/shared.js +19 -3
- package/src/stripe-client.js +16 -0
- package/src/stripe-commands.js +63 -0
- package/src/team-client.js +11 -0
- package/src/team-commands.js +84 -0
- package/src/usage.js +49 -21
package/src/area-commands.js
CHANGED
|
@@ -7,7 +7,7 @@ import { HiveApiError } from "./api-client.js";
|
|
|
7
7
|
import { authenticatedClient, parseBoolean, postFileToUploadUrl, readJsonObject, requiredFlagValue, writeJson } from "./shared.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @typedef {{ key: string, type: "string" | "boolean" | "switch" | "limit" | "choice" | "
|
|
10
|
+
* @typedef {{ key: string, type: "string" | "boolean" | "switch" | "limit" | "choice" | "iso-date", choices?: string[], max?: number }} FlagRule
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
/** @type {Record<string, FlagRule>} */
|
|
@@ -70,16 +70,6 @@ function convertValue(flag, rule, raw) {
|
|
|
70
70
|
if (!rule.choices?.includes(raw)) throw new Error(`${flag} must be ${rule.choices?.join(", ")}`);
|
|
71
71
|
return raw;
|
|
72
72
|
}
|
|
73
|
-
if (rule.type === "amount") {
|
|
74
|
-
if (!/^\d+(\.\d{1,2})?$/.test(raw) || Number(raw) <= 0) {
|
|
75
|
-
throw new Error(`${flag} must be a positive decimal amount with at most two decimals, for example 10.00`);
|
|
76
|
-
}
|
|
77
|
-
return raw;
|
|
78
|
-
}
|
|
79
|
-
if (rule.type === "currency") {
|
|
80
|
-
if (!/^[A-Za-z]{3}$/.test(raw)) throw new Error(`${flag} must be a three-letter currency code`);
|
|
81
|
-
return raw.toUpperCase();
|
|
82
|
-
}
|
|
83
73
|
if (rule.type === "iso-date") {
|
|
84
74
|
if (Number.isNaN(Date.parse(raw))) throw new Error(`${flag} must be an ISO-8601 date-time such as 2026-12-01T15:00:00Z`);
|
|
85
75
|
return raw;
|
|
@@ -208,42 +198,6 @@ async function runBroadcasts(args, deps) {
|
|
|
208
198
|
throw new Error(`Unknown broadcasts action: ${action || ""}`.trim());
|
|
209
199
|
}
|
|
210
200
|
|
|
211
|
-
// --- tickets --------------------------------------------------------------
|
|
212
|
-
|
|
213
|
-
async function runTickets(args, deps) {
|
|
214
|
-
const [action, ...rest] = args;
|
|
215
|
-
const client = await authenticatedClient(deps);
|
|
216
|
-
if (action === "list") {
|
|
217
|
-
const { values } = parseArgs(rest, { ...ACCOUNT, ...PAGING }, "tickets list");
|
|
218
|
-
writeJson(deps.stdout, await client.listTickets(values));
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
if (action === "mine") {
|
|
222
|
-
const { values } = parseArgs(rest, PAGING, "tickets mine");
|
|
223
|
-
writeJson(deps.stdout, await client.listMyTickets(values));
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
if (action === "get") {
|
|
227
|
-
const { positionals } = parseArgs(rest, {}, "tickets get", 1);
|
|
228
|
-
writeJson(deps.stdout, await client.getTicket(requiredId("ticket id", positionals[0])));
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
if (action === "update") {
|
|
232
|
-
const { positionals, values } = parseArgs(rest, {
|
|
233
|
-
"--name": { key: "name", type: "string" },
|
|
234
|
-
"--description": { key: "description", type: "string" },
|
|
235
|
-
"--amount": { key: "amount", type: "amount" },
|
|
236
|
-
"--currency": { key: "currency", type: "currency" },
|
|
237
|
-
"--status": { choices: ["active", "inactive"], key: "status", type: "choice" },
|
|
238
|
-
}, "tickets update", 1);
|
|
239
|
-
const id = requiredId("ticket id", positionals[0]);
|
|
240
|
-
requireChanges(values, "tickets update");
|
|
241
|
-
writeJson(deps.stdout, await client.updateTicket(id, values));
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
throw new Error(`Unknown tickets action: ${action || ""}`.trim());
|
|
245
|
-
}
|
|
246
|
-
|
|
247
201
|
// --- AI assistant ---------------------------------------------------------
|
|
248
202
|
|
|
249
203
|
const ASSISTANT_DOCUMENT_TYPES = {
|
|
@@ -370,16 +324,25 @@ async function runCredentials(args, deps) {
|
|
|
370
324
|
throw new Error(`Unknown credentials action: ${action || ""}`.trim());
|
|
371
325
|
}
|
|
372
326
|
|
|
327
|
+
// --- worlds ---------------------------------------------------------------
|
|
328
|
+
|
|
329
|
+
/** Lists the worlds an account's events may book; pass one's `id` to `events create --world`. */
|
|
330
|
+
async function runWorlds(args, deps) {
|
|
331
|
+
const { values } = parseArgs(args, ACCOUNT, "worlds");
|
|
332
|
+
const client = await authenticatedClient(deps);
|
|
333
|
+
writeJson(deps.stdout, await client.listWorlds(values.account));
|
|
334
|
+
}
|
|
335
|
+
|
|
373
336
|
/**
|
|
374
|
-
* Dispatch for the search, broadcasts,
|
|
337
|
+
* Dispatch for the search, broadcasts, assistant, credentials and worlds commands.
|
|
375
338
|
* @returns {Promise<boolean>} true when the command belonged to this module
|
|
376
339
|
*/
|
|
377
340
|
export async function runAreaCommand(command, args, deps) {
|
|
378
341
|
if (command === "search") await runSearch(args, deps);
|
|
379
342
|
else if (command === "broadcasts") await runBroadcasts(args, deps);
|
|
380
|
-
else if (command === "tickets") await runTickets(args, deps);
|
|
381
343
|
else if (command === "assistant") await runAssistant(args, deps);
|
|
382
344
|
else if (command === "credentials") await runCredentials(args, deps);
|
|
345
|
+
else if (command === "worlds") await runWorlds(args, deps);
|
|
383
346
|
else return false;
|
|
384
347
|
return true;
|
|
385
348
|
}
|
package/src/commands.js
CHANGED
|
@@ -8,12 +8,18 @@ import { clearConfig, loadConfig } from "./config.js";
|
|
|
8
8
|
import { runExtendedCommand } from "./extended-commands.js";
|
|
9
9
|
import { login, loginUsage, parseLoginArgs } from "./login.js";
|
|
10
10
|
import { runSkill } from "./skill.js";
|
|
11
|
-
import { authenticatedClient, parseBoolean, postFileToUploadUrl, requiredFlagValue, writeJson, writeLine } from "./shared.js";
|
|
11
|
+
import { authenticatedClient, parseBoolean, postFileToUploadUrl, requiredFlagValue, terminalText, writeJson, writeLine } from "./shared.js";
|
|
12
12
|
import { CURRENT_VERSION, updateUsage } from "./update.js";
|
|
13
13
|
import { commandUsage, resourceUsage, usage } from "./usage.js";
|
|
14
|
+
import { runTeamCommand } from "./team-commands.js";
|
|
15
|
+
import { runStripeCommand } from "./stripe-commands.js";
|
|
16
|
+
import { runFeedbackCommand } from "./feedback-commands.js";
|
|
17
|
+
import { runPaymentsCommand } from "./payments-commands.js";
|
|
18
|
+
import { runConversationsCommand } from "./conversations-commands.js";
|
|
19
|
+
import { runSellingCommand } from "./selling-commands.js";
|
|
14
20
|
|
|
15
21
|
// Commands that run with no arguments.
|
|
16
|
-
const SIMPLE_COMMANDS = new Set(["login", "logout", "update", "whoami", "capabilities"]);
|
|
22
|
+
const SIMPLE_COMMANDS = new Set(["login", "logout", "update", "whoami", "capabilities", "worlds"]);
|
|
17
23
|
|
|
18
24
|
function defaultDeps(overrides = {}) {
|
|
19
25
|
return {
|
|
@@ -36,6 +42,7 @@ function loginDeps(deps) {
|
|
|
36
42
|
env: deps.env,
|
|
37
43
|
fetch: deps.fetch,
|
|
38
44
|
platform: deps.platform,
|
|
45
|
+
stderr: deps.stderr,
|
|
39
46
|
stdout: deps.stdout,
|
|
40
47
|
};
|
|
41
48
|
if (deps.homeDir !== undefined) next.homeDir = deps.homeDir;
|
|
@@ -91,7 +98,7 @@ function setPayloadField(payload, key, value) {
|
|
|
91
98
|
if (value !== undefined) payload[key] = value;
|
|
92
99
|
}
|
|
93
100
|
|
|
94
|
-
async function parseResourcePayload(args, includeOwner) {
|
|
101
|
+
async function parseResourcePayload(kind, args, includeOwner) {
|
|
95
102
|
let payload = {};
|
|
96
103
|
let idempotencyKey;
|
|
97
104
|
let ownerType;
|
|
@@ -116,6 +123,9 @@ async function parseResourcePayload(args, includeOwner) {
|
|
|
116
123
|
} else if (flag === "--visibility") {
|
|
117
124
|
index += 1;
|
|
118
125
|
setPayloadField(payload, "visibility", requiredFlagValue(flag, args[index]));
|
|
126
|
+
} else if (kind === "events" && flag === "--world") {
|
|
127
|
+
index += 1;
|
|
128
|
+
setPayloadField(payload, "worldId", requiredFlagValue(flag, args[index]));
|
|
119
129
|
} else if (flag === "--file") {
|
|
120
130
|
index += 1;
|
|
121
131
|
const filePayload = await readJsonFile(requiredFlagValue(flag, args[index]));
|
|
@@ -232,12 +242,12 @@ async function runWhoami(deps) {
|
|
|
232
242
|
const result = await (await authenticatedClient(deps)).whoami();
|
|
233
243
|
const data = result.data;
|
|
234
244
|
const person = data.person;
|
|
235
|
-
writeLine(deps.stdout, `Account: ${person.displayName || person.handle || person.id}`);
|
|
236
|
-
if (person.handle) writeLine(deps.stdout, `Handle: @${person.handle}`);
|
|
237
|
-
writeLine(deps.stdout, `Scopes: ${data.credential.scopes.join(", ") || "none"}`);
|
|
245
|
+
writeLine(deps.stdout, terminalText(`Account: ${person.displayName || person.handle || person.id}`));
|
|
246
|
+
if (person.handle) writeLine(deps.stdout, terminalText(`Handle: @${person.handle}`));
|
|
247
|
+
writeLine(deps.stdout, terminalText(`Scopes: ${data.credential.scopes.join(", ") || "none"}`));
|
|
238
248
|
writeLine(deps.stdout, `Accounts this key can act on: ${data.communities.length}`);
|
|
239
249
|
for (const community of data.communities) {
|
|
240
|
-
writeLine(deps.stdout, `- ${community.name} (${community.role}): ${capabilityLabels(community.capabilities).join(", ")}`);
|
|
250
|
+
writeLine(deps.stdout, terminalText(`- ${community.name} (${community.role}): ${capabilityLabels(community.capabilities).join(", ")}`));
|
|
241
251
|
}
|
|
242
252
|
}
|
|
243
253
|
|
|
@@ -249,7 +259,7 @@ async function runCapabilities(deps) {
|
|
|
249
259
|
return;
|
|
250
260
|
}
|
|
251
261
|
for (const community of communities) {
|
|
252
|
-
writeLine(deps.stdout, `${community.name} (${community.role}): ${capabilityLabels(community.capabilities).join(", ")}`);
|
|
262
|
+
writeLine(deps.stdout, terminalText(`${community.name} (${community.role}): ${capabilityLabels(community.capabilities).join(", ")}`));
|
|
253
263
|
}
|
|
254
264
|
}
|
|
255
265
|
|
|
@@ -266,13 +276,13 @@ async function runResource(kind, args, deps) {
|
|
|
266
276
|
return;
|
|
267
277
|
}
|
|
268
278
|
if (action === "create") {
|
|
269
|
-
const { idempotencyKey, payload } = await parseResourcePayload(rest, true);
|
|
279
|
+
const { idempotencyKey, payload } = await parseResourcePayload(kind, rest, true);
|
|
270
280
|
writeJson(deps.stdout, await client.createResource(kind, payload, idempotencyKey));
|
|
271
281
|
return;
|
|
272
282
|
}
|
|
273
283
|
if (action === "update") {
|
|
274
284
|
const id = requiredFlagValue("resource id", rest[0]);
|
|
275
|
-
const { payload } = await parseResourcePayload(rest.slice(1), false);
|
|
285
|
+
const { payload } = await parseResourcePayload(kind, rest.slice(1), false);
|
|
276
286
|
writeJson(deps.stdout, await client.updateResource(kind, id, payload));
|
|
277
287
|
return;
|
|
278
288
|
}
|
|
@@ -414,18 +424,6 @@ async function runAccount(args, deps) {
|
|
|
414
424
|
writeJson(deps.stdout, await client.requestAccountExport());
|
|
415
425
|
return;
|
|
416
426
|
}
|
|
417
|
-
if (action === "deletion") {
|
|
418
|
-
const deletionAction = rest[0];
|
|
419
|
-
if (deletionAction === "cancel") {
|
|
420
|
-
if (rest.length > 1) throw new Error(`Unknown account deletion cancel option: ${rest[1]}`);
|
|
421
|
-
writeJson(deps.stdout, await client.cancelAccountDeletion());
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
if (deletionAction === "request") {
|
|
425
|
-
throw new Error("Account deletion can't be requested from the CLI. Delete your account in the Hive app under Settings.");
|
|
426
|
-
}
|
|
427
|
-
throw new Error(`Unknown account deletion action: ${deletionAction || ""}`.trim());
|
|
428
|
-
}
|
|
429
427
|
if (action === "linked-communities") {
|
|
430
428
|
const linkedAction = rest[0] ?? "list";
|
|
431
429
|
if (linkedAction === "list") {
|
|
@@ -493,14 +491,17 @@ async function runNfts(args, deps) {
|
|
|
493
491
|
function renderError(error) {
|
|
494
492
|
if (error instanceof HiveApiError) {
|
|
495
493
|
const scopeText = error.requiredScopes.length > 0 ? ` Required scopes: ${error.requiredScopes.join(", ")}.` : "";
|
|
494
|
+
const teamHint = error.requiredScopes.some(scope => scope.startsWith("team:"))
|
|
495
|
+
? " Staff: run hive3 login again (Team Tools are added automatically for staff accounts)."
|
|
496
|
+
: "";
|
|
496
497
|
if (error.code === "auth_required") return error.message;
|
|
497
498
|
if (error.code === "plan_required") {
|
|
498
499
|
return [
|
|
499
|
-
"
|
|
500
|
+
"API access needs Honey Bee or above, or current Team access on your account.",
|
|
500
501
|
"Upgrade under Settings in the Hive app. This key works again once the plan is active; you don't need to log in again.",
|
|
501
502
|
].join(" ");
|
|
502
503
|
}
|
|
503
|
-
return `Hive API error ${error.status} (${error.code}): ${error.message}.${scopeText}`;
|
|
504
|
+
return `Hive API error ${error.status} (${error.code}): ${error.message}.${scopeText}${teamHint}`;
|
|
504
505
|
}
|
|
505
506
|
return error instanceof Error ? error.message : "Hive CLI failed.";
|
|
506
507
|
}
|
|
@@ -590,6 +591,30 @@ export async function main(argv, overrides = {}) {
|
|
|
590
591
|
await runNfts(rest, deps);
|
|
591
592
|
return 0;
|
|
592
593
|
}
|
|
594
|
+
if (command === "team") {
|
|
595
|
+
await runTeamCommand(rest, deps);
|
|
596
|
+
return 0;
|
|
597
|
+
}
|
|
598
|
+
if (command === "stripe") {
|
|
599
|
+
await runStripeCommand(rest, deps);
|
|
600
|
+
return 0;
|
|
601
|
+
}
|
|
602
|
+
if (command === "feedback") {
|
|
603
|
+
await runFeedbackCommand(rest, deps);
|
|
604
|
+
return 0;
|
|
605
|
+
}
|
|
606
|
+
if (command === "payments") {
|
|
607
|
+
await runPaymentsCommand(rest, deps);
|
|
608
|
+
return 0;
|
|
609
|
+
}
|
|
610
|
+
if (command === "conversations") {
|
|
611
|
+
await runConversationsCommand(rest, deps);
|
|
612
|
+
return 0;
|
|
613
|
+
}
|
|
614
|
+
if (command === "products" || command === "subscriptions" || command === "tickets") {
|
|
615
|
+
await runSellingCommand(command, rest, deps);
|
|
616
|
+
return 0;
|
|
617
|
+
}
|
|
593
618
|
if (await runExtendedCommand(command, rest, deps)) return 0;
|
|
594
619
|
if (isResourceKind(command)) {
|
|
595
620
|
await runResource(command, rest, deps);
|
|
@@ -597,7 +622,7 @@ export async function main(argv, overrides = {}) {
|
|
|
597
622
|
}
|
|
598
623
|
throw new Error(`Unknown command: ${command}`);
|
|
599
624
|
} catch (error) {
|
|
600
|
-
writeLine(deps.stderr, renderError(error));
|
|
625
|
+
writeLine(deps.stderr, terminalText(renderError(error)));
|
|
601
626
|
return error instanceof HiveApiError && error.code === "auth_required" ? 1 : 2;
|
|
602
627
|
}
|
|
603
628
|
}
|
package/src/config.js
CHANGED
|
@@ -29,6 +29,7 @@ function configDeps(overrides = {}) {
|
|
|
29
29
|
env: process.env,
|
|
30
30
|
homeDir: os.homedir(),
|
|
31
31
|
platform: process.platform,
|
|
32
|
+
uid: typeof process.getuid === "function" ? process.getuid() : undefined,
|
|
32
33
|
};
|
|
33
34
|
for (const [key, value] of Object.entries(overrides)) {
|
|
34
35
|
if (value !== undefined) deps[key] = value;
|
|
@@ -53,16 +54,38 @@ function assertStoredConfig(value) {
|
|
|
53
54
|
});
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Another local user who owns or can write the config could swap in their own API URL and
|
|
59
|
+
* key, silently redirecting every command (and uploaded file) to a server they control.
|
|
60
|
+
*/
|
|
61
|
+
function assertPrivateConfigFile(file, info, uid) {
|
|
62
|
+
if (info.uid !== uid) {
|
|
63
|
+
throw new Error(`Refusing to load Hive CLI config ${file}: it is not owned by the current user. Remove it and run hive3 login again.`);
|
|
64
|
+
}
|
|
65
|
+
if ((info.mode & 0o022) !== 0) {
|
|
66
|
+
throw new Error(`Refusing to load Hive CLI config ${file}: it is writable by other users. Run chmod 600 on it, or remove it and run hive3 login again.`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
56
70
|
export async function loadConfig(overrides = {}) {
|
|
57
71
|
const deps = configDeps(overrides);
|
|
58
72
|
const file = configPath(deps.env, deps.platform, deps.homeDir);
|
|
73
|
+
let handle;
|
|
59
74
|
try {
|
|
60
|
-
|
|
61
|
-
return assertStoredConfig(JSON.parse(text));
|
|
75
|
+
handle = await fs.open(file, "r");
|
|
62
76
|
} catch (error) {
|
|
63
77
|
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") return null;
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
// Checked on the open handle so the file cannot be swapped between check and read.
|
|
82
|
+
if (deps.platform !== "win32" && deps.uid !== undefined) assertPrivateConfigFile(file, await handle.stat(), deps.uid);
|
|
83
|
+
return assertStoredConfig(JSON.parse(await handle.readFile("utf8")));
|
|
84
|
+
} catch (error) {
|
|
64
85
|
if (error instanceof SyntaxError) throw new Error("Hive CLI config is malformed. Run hive3 login again.");
|
|
65
86
|
throw error;
|
|
87
|
+
} finally {
|
|
88
|
+
await handle.close();
|
|
66
89
|
}
|
|
67
90
|
}
|
|
68
91
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
export function createConversationsClient(client, community = false) {
|
|
4
|
+
const root = community ? "/community-messages" : "/conversations";
|
|
5
|
+
const thread = ref => `${root}/${encodeURIComponent(ref)}/messages`;
|
|
6
|
+
const message = (id, room) => community ? `${thread(room)}/${encodeURIComponent(id)}` : `${root}/messages/${encodeURIComponent(id)}`;
|
|
7
|
+
const write = (method, path, body, idempotencyKey) => client.request(method, path, { body: { ...body, confirmed: true }, idempotencyKey });
|
|
8
|
+
return {
|
|
9
|
+
list: query => client.request("GET", root, { query }),
|
|
10
|
+
read: (ref, query) => client.request("GET", thread(ref), { query }),
|
|
11
|
+
send: (ref, body, key) => write("POST", thread(ref), body, key),
|
|
12
|
+
edit: (id, content, key, room) => write("PATCH", message(id, room), { content }, key),
|
|
13
|
+
remove: (id, key, room) => write("DELETE", message(id, room), {}, key),
|
|
14
|
+
react: (id, emoji, present, key, room) => write("POST", `${message(id, room)}/reaction`, { emoji, present }, key),
|
|
15
|
+
markRead: (ref, key) => write("POST", `${root}/${encodeURIComponent(ref)}/read`, {}, key),
|
|
16
|
+
accept: (ref, key) => write("POST", `${root}/${encodeURIComponent(ref)}/accept`, {}, key),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { authenticatedClient, parseBoolean, requiredFlagValue, writeJson, writeLine } from "./shared.js";
|
|
7
|
+
import { createConversationsClient } from "./conversations-client.js";
|
|
8
|
+
|
|
9
|
+
export function conversationsUsage() {
|
|
10
|
+
return `Usage:
|
|
11
|
+
hive3 conversations list [--requests] [--limit 1-100] [--cursor <cursor>]
|
|
12
|
+
hive3 conversations read <partner-account-id> [--limit 1-100] [--cursor <cursor>]
|
|
13
|
+
hive3 conversations send <partner-account-id> --content <text> --yes
|
|
14
|
+
hive3 conversations reply <partner-account-id> <message-id> --content <text> --yes
|
|
15
|
+
hive3 conversations edit <message-id> --content <text> --yes
|
|
16
|
+
hive3 conversations delete <message-id> --yes
|
|
17
|
+
hive3 conversations mark-read <partner-account-id> --yes
|
|
18
|
+
hive3 conversations accept <partner-account-id> --yes
|
|
19
|
+
hive3 conversations react <message-id> --emoji <emoji> --present true|false --yes
|
|
20
|
+
hive3 conversations community list [--limit 1-100] [--cursor <cursor>]
|
|
21
|
+
hive3 conversations community read <account> [--limit 1-100] [--cursor <cursor>]
|
|
22
|
+
hive3 conversations community send <account> --content <text> --yes
|
|
23
|
+
hive3 conversations community reply <account> <message-id> --content <text> --yes
|
|
24
|
+
hive3 conversations community edit <account> <message-id> --content <text> --yes
|
|
25
|
+
hive3 conversations community delete <account> <message-id> --yes
|
|
26
|
+
hive3 conversations community react <account> <message-id> --emoji <emoji> --present true|false --yes
|
|
27
|
+
|
|
28
|
+
Login needs separately approved --messages-access read|full; ordinary and Team access do not grant inbox access.
|
|
29
|
+
Send starts a DM if needed, subject to the app's membership and five-pending-message limit.
|
|
30
|
+
Use --content-file <path> instead of --content for send/reply/edit (1-4,000 characters).
|
|
31
|
+
All writes require --yes and support --idempotency-key <key> (otherwise generated); reuse the same key and payload after a lost response.
|
|
32
|
+
Reads are newest-first and return page.nextCursor; list --requests selects the message-request inbox.
|
|
33
|
+
Community list pages accepted memberships; pages may be empty after access/plan filtering, so follow nextCursor.
|
|
34
|
+
Writes are text-only; existing attachments remain readable. No attachment URLs, sender overrides, --account impersonation or staff inbox access.
|
|
35
|
+
Only your own messages may be edited/deleted. Reactions set a desired state, never toggle on retry.`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export async function runConversationsCommand(args, deps) {
|
|
39
|
+
if (!args.length || args.some(arg => arg === "--help" || arg === "-h")) { writeLine(deps.stdout, conversationsUsage()); return 0; }
|
|
40
|
+
const community = args[0] === "community";
|
|
41
|
+
const [command, ...rest] = community ? args.slice(1) : args;
|
|
42
|
+
const reads = ["list", "read"];
|
|
43
|
+
const writes = ["send", "reply", "edit", "delete", "react", ...(community ? [] : ["mark-read", "accept"])];
|
|
44
|
+
if (![...reads, ...writes].includes(command)) throw new Error(`Unknown conversations command: ${command}`);
|
|
45
|
+
const writing = writes.includes(command);
|
|
46
|
+
let room;
|
|
47
|
+
let ref;
|
|
48
|
+
let replyToMessageId;
|
|
49
|
+
if (command !== "list") {
|
|
50
|
+
if (community) room = requiredFlagValue("community account", rest.shift());
|
|
51
|
+
if (!community || ["reply", "edit", "delete", "react"].includes(command)) ref = requiredFlagValue("account or message ID", rest.shift());
|
|
52
|
+
if (command === "reply") {
|
|
53
|
+
replyToMessageId = community ? ref : requiredFlagValue("reply message ID", rest.shift());
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const allowed = writing ? ["--yes", "--idempotency-key"] : ["--limit", "--cursor"];
|
|
57
|
+
if (["send", "reply", "edit"].includes(command)) allowed.push("--content", "--content-file");
|
|
58
|
+
if (command === "react") allowed.push("--emoji", "--present");
|
|
59
|
+
if (!community && command === "list") allowed.push("--requests");
|
|
60
|
+
/** @type {Record<string, string | boolean>} */
|
|
61
|
+
const parsed = {};
|
|
62
|
+
for (let index = 0; index < rest.length; index++) {
|
|
63
|
+
const flag = rest[index];
|
|
64
|
+
if (!allowed.includes(flag)) throw new Error(`Unknown conversations option: ${flag}`);
|
|
65
|
+
if (parsed[flag] !== undefined) throw new Error(`${flag} may only be given once`);
|
|
66
|
+
parsed[flag] = flag === "--yes" || flag === "--requests" ? true : requiredFlagValue(flag, rest[++index]);
|
|
67
|
+
}
|
|
68
|
+
if (writing && !parsed["--yes"]) throw new Error(`conversations ${command} changes or sends a message. Pass --yes to confirm.`);
|
|
69
|
+
/** @type {{limit?: number, cursor?: string, requests?: boolean}} */
|
|
70
|
+
const query = {};
|
|
71
|
+
if (parsed["--limit"] !== undefined) {
|
|
72
|
+
const limit = Number(parsed["--limit"]);
|
|
73
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw new Error("--limit must be an integer between 1 and 100");
|
|
74
|
+
query.limit = limit;
|
|
75
|
+
}
|
|
76
|
+
if (typeof parsed["--cursor"] === "string") query.cursor = parsed["--cursor"];
|
|
77
|
+
if (parsed["--requests"]) query.requests = true;
|
|
78
|
+
let content;
|
|
79
|
+
if (["send", "reply", "edit"].includes(command)) {
|
|
80
|
+
if (parsed["--content"] !== undefined && parsed["--content-file"] !== undefined) throw new Error("Use either --content or --content-file");
|
|
81
|
+
const file = parsed["--content-file"];
|
|
82
|
+
content = typeof file === "string" ? await readFile(path.resolve(deps.cwd, file), "utf8") : parsed["--content"];
|
|
83
|
+
if (typeof content !== "string" || !content.trim() || Array.from(content.trim()).length > 4000) throw new Error("Message content must contain 1-4,000 characters");
|
|
84
|
+
}
|
|
85
|
+
const key = typeof parsed["--idempotency-key"] === "string" ? parsed["--idempotency-key"] : randomUUID();
|
|
86
|
+
if (!key.trim() || key.length > 128) throw new Error("--idempotency-key must contain 1-128 characters");
|
|
87
|
+
const emoji = parsed["--emoji"];
|
|
88
|
+
const present = parsed["--present"];
|
|
89
|
+
if (command === "react" && (typeof emoji !== "string" || typeof present !== "string")) throw new Error("Reactions require --emoji and --present true|false");
|
|
90
|
+
const desired = command === "react" ? parseBoolean(present, "--present") : undefined;
|
|
91
|
+
const client = createConversationsClient(await authenticatedClient(deps), community);
|
|
92
|
+
let result;
|
|
93
|
+
if (command === "list") result = await client.list(query);
|
|
94
|
+
else if (command === "read") result = await client.read(community ? room : ref, query);
|
|
95
|
+
else if (command === "send" || command === "reply") result = await client.send(community ? room : ref, { content, ...(replyToMessageId ? { replyToMessageId } : {}) }, key);
|
|
96
|
+
else if (command === "edit") result = await client.edit(ref, content, key, room);
|
|
97
|
+
else if (command === "delete") result = await client.remove(ref, key, room);
|
|
98
|
+
else if (command === "react") result = await client.react(ref, emoji, desired, key, room);
|
|
99
|
+
else if (command === "mark-read") result = await client.markRead(ref, key);
|
|
100
|
+
else result = await client.accept(ref, key);
|
|
101
|
+
writeJson(deps.stdout, result);
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
export function createFeedbackClient(client, team = false) {
|
|
4
|
+
const root = team ? "/team/feedback" : "/feedback";
|
|
5
|
+
const ticket = ref => `${root}/${encodeURIComponent(ref)}`;
|
|
6
|
+
return {
|
|
7
|
+
list: query => client.request("GET", root, { query }),
|
|
8
|
+
get: ref => client.request("GET", ticket(ref)),
|
|
9
|
+
messages: (ref, query) => client.request("GET", `${ticket(ref)}/messages`, { query }),
|
|
10
|
+
reply: (ref, body, idempotencyKey) => client.request("POST", `${ticket(ref)}/messages`, { body: { body, confirmed: true }, idempotencyKey }),
|
|
11
|
+
status: (ref, status) => client.request("PATCH", `${ticket(ref)}/status`, { body: { status, confirmed: true } }),
|
|
12
|
+
uploadUrl: kind => client.request("POST", "/feedback/upload-url", { body: { kind } }),
|
|
13
|
+
submit: (body, idempotencyKey) => client.request("POST", "/feedback", { body: { ...body, confirmed: true }, idempotencyKey }),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { readFile, stat } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { authenticatedClient, postFileToUploadUrl, requiredFlagValue, writeJson, writeLine } from "./shared.js";
|
|
7
|
+
import { createFeedbackClient } from "./feedback-client.js";
|
|
8
|
+
import { createApiClient } from "./api-client.js";
|
|
9
|
+
import { loadConfig } from "./config.js";
|
|
10
|
+
import { feedbackReplay } from "./feedback-replay.js";
|
|
11
|
+
|
|
12
|
+
const MIME = {
|
|
13
|
+
".gif": "image/gif", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".png": "image/png", ".webp": "image/webp",
|
|
14
|
+
".mp4": "video/mp4", ".webm": "video/webm", ".mov": "video/quicktime",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function feedbackUsage() {
|
|
18
|
+
return `Usage:
|
|
19
|
+
hive3 feedback submit --kind bug|suggestion --description <text> [--description-file <path>] [--image <path>]... [--video <path>] --yes
|
|
20
|
+
hive3 feedback list [--limit 1-100] [--cursor <cursor>]
|
|
21
|
+
hive3 feedback get <ticket-id-or-HV-number>
|
|
22
|
+
hive3 feedback messages <ticket> [--limit 1-100] [--cursor <cursor>]
|
|
23
|
+
hive3 feedback reply <ticket> --body <text> [--body-file <path>] --yes
|
|
24
|
+
hive3 team feedback list [--status open|in_progress|resolved|closed] [--limit 1-100] [--cursor <cursor>]
|
|
25
|
+
hive3 team feedback get <ticket>
|
|
26
|
+
hive3 team feedback messages <ticket> [--limit 1-100] [--cursor <cursor>]
|
|
27
|
+
hive3 team feedback reply <ticket> --body <text> [--body-file <path>] --yes
|
|
28
|
+
hive3 team feedback status <ticket> --status open|in_progress|resolved|closed --yes
|
|
29
|
+
|
|
30
|
+
Submit/reply support --idempotency-key <key>; otherwise a fresh key is generated.
|
|
31
|
+
Attachment retries reuse private local upload references; keep the same key and original file contents.
|
|
32
|
+
Attachments: up to 4 images (8 MiB each), 1 video (19 MiB). Replies are text-only.
|
|
33
|
+
Feedback tickets are support conversations, not paid admission tickets.
|
|
34
|
+
Team commands require team scopes and current staff access.`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function options(args, allowed) {
|
|
38
|
+
const result = { images: [], videos: [], yes: false };
|
|
39
|
+
for (let index = 0; index < args.length; index++) {
|
|
40
|
+
const flag = args[index];
|
|
41
|
+
if (flag === "--yes" && allowed.includes(flag)) { result.yes = true; continue; }
|
|
42
|
+
if (!allowed.includes(flag)) throw new Error(`Unknown feedback option: ${flag}`);
|
|
43
|
+
const value = requiredFlagValue(flag, args[++index]);
|
|
44
|
+
if (flag === "--image") result.images.push(value);
|
|
45
|
+
else if (flag === "--video") result.videos.push(value);
|
|
46
|
+
else {
|
|
47
|
+
const key = flag.slice(2);
|
|
48
|
+
if (result[key] !== undefined) throw new Error(`${flag} may only be given once`);
|
|
49
|
+
result[key] = value;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
function queryOptions(parsed) {
|
|
55
|
+
const query = {};
|
|
56
|
+
if (parsed.limit !== undefined) {
|
|
57
|
+
const limit = Number(parsed.limit);
|
|
58
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw new Error("--limit must be an integer between 1 and 100");
|
|
59
|
+
query.limit = limit;
|
|
60
|
+
}
|
|
61
|
+
if (parsed.cursor !== undefined) query.cursor = parsed.cursor;
|
|
62
|
+
if (parsed.status !== undefined) {
|
|
63
|
+
if (!["open", "in_progress", "resolved", "closed"].includes(parsed.status)) throw new Error("Invalid feedback status");
|
|
64
|
+
query.status = parsed.status;
|
|
65
|
+
}
|
|
66
|
+
return query;
|
|
67
|
+
}
|
|
68
|
+
async function textOption(parsed, name, deps) {
|
|
69
|
+
if (parsed[name] !== undefined && parsed[`${name}-file`] !== undefined) throw new Error(`Use either --${name} or --${name}-file`);
|
|
70
|
+
const file = parsed[`${name}-file`];
|
|
71
|
+
const text = file ? await readFile(path.resolve(deps.cwd, file), "utf8") : parsed[name];
|
|
72
|
+
if (!text?.trim()) throw new Error(`--${name} or --${name}-file is required`);
|
|
73
|
+
return text;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function runFeedbackCommand(args, deps) {
|
|
77
|
+
if (args.some(arg => arg === "--help" || arg === "-h") || args.length === 0) {
|
|
78
|
+
writeLine(deps.stdout, feedbackUsage());
|
|
79
|
+
return 0;
|
|
80
|
+
}
|
|
81
|
+
const team = args[0] === "team";
|
|
82
|
+
const [command, ...rest] = team ? args.slice(1) : args;
|
|
83
|
+
if (!command) { writeLine(deps.stdout, feedbackUsage()); return 0; }
|
|
84
|
+
const mutations = ["submit", "reply", "status"];
|
|
85
|
+
if (!["list", "get", "messages", ...mutations].includes(command) || (team && command === "submit") || (!team && command === "status")) throw new Error(`Unknown feedback command: ${command}`);
|
|
86
|
+
const ref = ["get", "messages", "reply", "status"].includes(command) ? requiredFlagValue("ticket", rest.shift()) : undefined;
|
|
87
|
+
const allowed = command === "submit" ? ["--kind", "--description", "--description-file", "--image", "--video", "--yes", "--idempotency-key"]
|
|
88
|
+
: command === "reply" ? ["--body", "--body-file", "--yes", "--idempotency-key"]
|
|
89
|
+
: command === "status" ? ["--status", "--yes"]
|
|
90
|
+
: command === "list" ? ["--limit", "--cursor", ...(team ? ["--status"] : [])]
|
|
91
|
+
: command === "messages" ? ["--limit", "--cursor"] : [];
|
|
92
|
+
const parsed = options(rest, allowed);
|
|
93
|
+
if (mutations.includes(command) && !parsed.yes) throw new Error(`feedback ${command} sends or changes a support ticket. Pass --yes to confirm.`);
|
|
94
|
+
const query = queryOptions(parsed);
|
|
95
|
+
let description;
|
|
96
|
+
let body;
|
|
97
|
+
const files = [];
|
|
98
|
+
if (command === "submit") {
|
|
99
|
+
if (parsed.kind !== "bug" && parsed.kind !== "suggestion") throw new Error("--kind must be bug or suggestion");
|
|
100
|
+
description = await textOption(parsed, "description", deps);
|
|
101
|
+
if (description.trim().length < 10 || description.trim().length > 5000) throw new Error("Description must be between 10 and 5,000 characters");
|
|
102
|
+
if (parsed.images.length > 4 || parsed.videos.length > 1) throw new Error("Attach up to 4 images and 1 video");
|
|
103
|
+
/** @type {Array<["image" | "video", string[], number]>} */
|
|
104
|
+
const attachmentGroups = [["image", parsed.images, 8 * 1024 * 1024], ["video", parsed.videos, 19 * 1024 * 1024]];
|
|
105
|
+
for (const [kind, paths, maxBytes] of attachmentGroups) {
|
|
106
|
+
for (const file of paths) {
|
|
107
|
+
const filePath = path.resolve(deps.cwd, file);
|
|
108
|
+
const contentType = MIME[path.extname(filePath).toLowerCase()];
|
|
109
|
+
const info = await stat(filePath);
|
|
110
|
+
if (!contentType?.startsWith(`${kind}/`)) throw new Error(`Unsupported ${kind} file: ${file}`);
|
|
111
|
+
if (!info.isFile() || info.size < 1 || info.size > maxBytes) throw new Error(`Invalid ${kind} size: ${file}`);
|
|
112
|
+
const bytes = await readFile(filePath);
|
|
113
|
+
if (bytes.length < 1 || bytes.length > maxBytes) throw new Error(`Invalid ${kind} size: ${file}`);
|
|
114
|
+
files.push({ kind, filePath, contentType, bytes });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (command === "reply") {
|
|
119
|
+
body = await textOption(parsed, "body", deps);
|
|
120
|
+
if (body.trim().length > 2000) throw new Error("Message must be between 1 and 2,000 characters");
|
|
121
|
+
}
|
|
122
|
+
if (command === "status" && !query.status) throw new Error("--status is required");
|
|
123
|
+
const idempotencyKey = parsed["idempotency-key"] ?? randomUUID();
|
|
124
|
+
if (!idempotencyKey.trim() || idempotencyKey.length > 128) throw new Error("--idempotency-key must contain 1-128 characters");
|
|
125
|
+
const config = command === "submit" ? await loadConfig({ env: deps.env, homeDir: deps.homeDir, platform: deps.platform }) : null;
|
|
126
|
+
if (command === "submit" && !config) throw new Error("Not logged in. Run hive3 login first.");
|
|
127
|
+
const client = config ? createApiClient({ apiBaseUrl: config.apiBaseUrl, apiKey: config.apiKey, fetch: deps.fetch }) : await authenticatedClient(deps);
|
|
128
|
+
const feedback = createFeedbackClient(client, team);
|
|
129
|
+
let result;
|
|
130
|
+
if (command === "list") result = await feedback.list(query);
|
|
131
|
+
else if (command === "get") result = await feedback.get(ref);
|
|
132
|
+
else if (command === "messages") result = await feedback.messages(ref, query);
|
|
133
|
+
else if (command === "reply") result = await feedback.reply(ref, body, idempotencyKey);
|
|
134
|
+
else if (command === "status") result = await feedback.status(ref, query.status);
|
|
135
|
+
else {
|
|
136
|
+
const replay = await feedbackReplay(deps, config, idempotencyKey, { kind: parsed.kind, description }, files);
|
|
137
|
+
const attachments = replay.attachments;
|
|
138
|
+
for (const file of files.slice(attachments.length)) {
|
|
139
|
+
const issued = await feedback.uploadUrl(file.kind);
|
|
140
|
+
const uploaded = await postFileToUploadUrl(client, deps, issued.data.uploadUrl, file.filePath, file.contentType, file.bytes);
|
|
141
|
+
if (!uploaded.ok || typeof uploaded.parsed.storageId !== "string") throw new Error(`Feedback attachment upload failed (${uploaded.status}): ${uploaded.parsed.error ?? "missing storageId"}`);
|
|
142
|
+
await replay.append({ kind: file.kind, storageId: uploaded.parsed.storageId });
|
|
143
|
+
}
|
|
144
|
+
result = await feedback.submit({ kind: parsed.kind, description, attachments }, idempotencyKey);
|
|
145
|
+
}
|
|
146
|
+
writeJson(deps.stdout, result);
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { configDirectory, writePrivateFile } from "./config.js";
|
|
7
|
+
|
|
8
|
+
/** Preserve upload references across dropped submission responses without retaining credentials or report text. */
|
|
9
|
+
export async function feedbackReplay(deps, config, idempotencyKey, payload, files) {
|
|
10
|
+
const binding = createHash("sha256").update(JSON.stringify([config.apiBaseUrl, config.apiKey])).digest("hex");
|
|
11
|
+
const fileName = `${createHash("sha256").update(JSON.stringify([binding, idempotencyKey])).digest("hex")}.json`;
|
|
12
|
+
const directory = path.join(configDirectory(deps.env, deps.platform, deps.homeDir), "feedback-requests");
|
|
13
|
+
const fingerprint = createHash("sha256").update(JSON.stringify({
|
|
14
|
+
kind: payload.kind, description: payload.description.trim(),
|
|
15
|
+
files: files.map(file => ({ kind: file.kind, contentType: file.contentType, sha256: createHash("sha256").update(file.bytes).digest("hex") })),
|
|
16
|
+
})).digest("hex");
|
|
17
|
+
let manifest = { binding, fingerprint, attachments: [] };
|
|
18
|
+
try {
|
|
19
|
+
const directoryInfo = await lstat(directory);
|
|
20
|
+
if (!directoryInfo.isDirectory() || directoryInfo.isSymbolicLink()) throw new Error("Refusing unsafe feedback replay directory");
|
|
21
|
+
const file = path.join(directory, fileName);
|
|
22
|
+
const info = await lstat(file);
|
|
23
|
+
if (!info.isFile() || info.isSymbolicLink()) throw new Error("Refusing unsafe feedback replay manifest");
|
|
24
|
+
const stored = JSON.parse(await readFile(file, "utf8"));
|
|
25
|
+
if (stored.binding !== binding || stored.fingerprint !== fingerprint) throw new Error("Idempotency key was already used for different feedback. Use the original payload or a new key.");
|
|
26
|
+
if (!Array.isArray(stored.attachments) || stored.attachments.length > files.length
|
|
27
|
+
|| stored.attachments.some((item, index) => !item || item.kind !== files[index].kind || typeof item.storageId !== "string" || !item.storageId)) {
|
|
28
|
+
throw new Error("Feedback replay manifest is invalid. Refusing to reupload attachments for this key.");
|
|
29
|
+
}
|
|
30
|
+
manifest = stored;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (!error || typeof error !== "object" || !("code" in error) || error.code !== "ENOENT") throw error;
|
|
33
|
+
await writePrivateFile(directory, fileName, JSON.stringify(manifest));
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
attachments: manifest.attachments,
|
|
37
|
+
async append(attachment) {
|
|
38
|
+
manifest.attachments.push(attachment);
|
|
39
|
+
// Persist each upload before submission, so both partial uploads and lost POST responses can resume.
|
|
40
|
+
await writePrivateFile(directory, fileName, JSON.stringify(manifest));
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|