@neta-art/cohub-cli 2.2.10 → 2.3.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.
@@ -3,6 +3,39 @@ import { createClient } from "../client.js";
3
3
  import { json as outJson, jsonRequested, ok, error, handleHttp } from "../output.js";
4
4
  export function registerProfile(program) {
5
5
  const profileCmd = program.command("profile").description("Manage your profile");
6
+ profileCmd
7
+ .command("get <username>")
8
+ .description("Show a public user profile")
9
+ .option("--json", "Output as JSON")
10
+ .action(async (username, opts) => {
11
+ const client = createClient();
12
+ try {
13
+ const result = await client.users.getByUsername(username);
14
+ if (jsonRequested(opts))
15
+ return outJson(result);
16
+ const handle = result.profile.username ? `@${result.profile.username}` : result.profile.userUuid;
17
+ console.log(`\n ${result.profile.displayName} (${handle})`);
18
+ console.log(` Spaces: ${result.spaces.length}`);
19
+ console.log(` Works: ${result.works.length}\n`);
20
+ if (result.spaces.length > 0) {
21
+ console.log(" Spaces:");
22
+ for (const space of result.spaces) {
23
+ console.log(` - ${space.name} [${space.accessLabel}] ${space.spaceUrl}`);
24
+ }
25
+ console.log("");
26
+ }
27
+ if (result.works.length > 0) {
28
+ console.log(" Works:");
29
+ for (const work of result.works) {
30
+ console.log(` - ${work.title} ${work.publicUrl}`);
31
+ }
32
+ console.log("");
33
+ }
34
+ }
35
+ catch (e) {
36
+ handleHttp(e);
37
+ }
38
+ });
6
39
  profileCmd
7
40
  .command("update")
8
41
  .description("Update your profile")
@@ -0,0 +1,2 @@
1
+ import type { Command } from "commander";
2
+ export declare function registerReferrals(program: Command): void;
@@ -0,0 +1,84 @@
1
+ import { createClient } from "../client.js";
2
+ import { error, handleHttp, json as outJson, jsonRequested, ok, table } from "../output.js";
3
+ function referralUrl(code) {
4
+ const origin = process.env.COHUB_WEB_URL?.replace(/\/+$/, "") ?? "https://cohub.run";
5
+ return `${origin}/referrals/${code}`;
6
+ }
7
+ async function confirmRotate(opts) {
8
+ if (opts.yes)
9
+ return;
10
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
11
+ return error("Confirmation required", "Pass --yes to replace the referral link.");
12
+ }
13
+ process.stdout.write("The current referral link will stop working. Continue? [y/N] ");
14
+ const chunks = [];
15
+ for await (const chunk of process.stdin) {
16
+ chunks.push(chunk);
17
+ break;
18
+ }
19
+ const answer = Buffer.concat(chunks).toString().trim().toLowerCase();
20
+ if (answer !== "y" && answer !== "yes")
21
+ return error("Cancelled");
22
+ }
23
+ export function registerReferrals(program) {
24
+ const command = program
25
+ .command("referrals")
26
+ .description("View and manage your referral link")
27
+ .option("--json", "Output as JSON")
28
+ .action(async (opts) => {
29
+ const client = createClient();
30
+ try {
31
+ const result = await client.referrals.getMine();
32
+ const output = { ...result, url: referralUrl(result.code) };
33
+ if (jsonRequested(opts))
34
+ return outJson(output);
35
+ console.log(`\nReferral link: ${output.url}`);
36
+ console.log(`Rewarded: ${result.summary.rewarded}`);
37
+ console.log(`Earned: $${result.summary.earnedUsd.toFixed(2)}\n`);
38
+ }
39
+ catch (error) {
40
+ handleHttp(error);
41
+ }
42
+ });
43
+ command
44
+ .command("ls")
45
+ .alias("list")
46
+ .description("List your referrals")
47
+ .option("--json", "Output as JSON")
48
+ .action(async (opts) => {
49
+ const client = createClient();
50
+ try {
51
+ const result = await client.referrals.getMine();
52
+ if (jsonRequested(opts))
53
+ return outJson(result);
54
+ table(result.items, [
55
+ { key: "id", label: "ID" },
56
+ { key: "status", label: "Status" },
57
+ { key: "claimedAt", label: "Claimed" },
58
+ { key: "rewardedAt", label: "Rewarded" },
59
+ ]);
60
+ }
61
+ catch (error) {
62
+ handleHttp(error);
63
+ }
64
+ });
65
+ command
66
+ .command("rotate")
67
+ .description("Replace your referral link")
68
+ .option("-y, --yes", "Confirm replacement")
69
+ .option("--json", "Output as JSON")
70
+ .action(async (opts) => {
71
+ await confirmRotate(opts);
72
+ const client = createClient();
73
+ try {
74
+ const result = await client.referrals.rotateCode();
75
+ const output = { ...result, url: referralUrl(result.code) };
76
+ if (jsonRequested(opts))
77
+ return outJson(output);
78
+ ok(`Referral link rotated: ${output.url}`);
79
+ }
80
+ catch (error) {
81
+ handleHttp(error);
82
+ }
83
+ });
84
+ }
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import { registerModels } from "./commands/models.js";
10
10
  import { registerProfile } from "./commands/profile.js";
11
11
  import { registerSearch } from "./commands/search.js";
12
12
  import { registerReferences } from "./commands/references.js";
13
+ import { registerReferrals } from "./commands/referrals.js";
13
14
  import { registerPrompt, registerSpaces } from "./commands/spaces.js";
14
15
  import { maybeHandleRunCommand } from "./commands/run.js";
15
16
  import { registerSandbox } from "./commands/sandbox.js";
@@ -68,6 +69,7 @@ registerGenerations(program);
68
69
  registerModels(program);
69
70
  registerSearch(program);
70
71
  registerReferences(program);
72
+ registerReferrals(program);
71
73
  registerTasks(program);
72
74
  registerCronJobs(program);
73
75
  registerWorks(program);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neta-art/cohub-cli",
3
- "version": "2.2.10",
3
+ "version": "2.3.0",
4
4
  "description": "CLI for Cohub — spaces, sessions, and agent collaboration.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -13,10 +13,10 @@
13
13
  "README.md"
14
14
  ],
15
15
  "dependencies": {
16
- "@neta-art/generation": "^0.1.12",
16
+ "@neta-art/generation": "^0.1.13",
17
17
  "commander": "^14.0.3",
18
18
  "sharp": "^0.34.5",
19
- "@neta-art/cohub": "2.9.0"
19
+ "@neta-art/cohub": "2.10.0"
20
20
  },
21
21
  "publishConfig": {
22
22
  "access": "public"