@neta-art/cohub-cli 6.7.0 → 6.8.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.
@@ -1,10 +1,10 @@
1
1
  import { randomUUID } from "node:crypto";
2
- import { createReadStream } from "node:fs";
3
2
  import { readdir, stat } from "node:fs/promises";
4
3
  import { basename, dirname, relative, resolve, sep } from "node:path";
5
4
  import { resolveCohubEnvironment } from "@neta-art/cohub";
6
5
  import { uploadAvatarAsset, uploadChatImageAsset } from "../avatar.js";
7
6
  import { createClient } from "../client.js";
7
+ import { putLocalFile } from "../http-put.js";
8
8
  import { table, json as outJson, jsonRequested, ok, error, handleHttp, formatEpochMs } from "../output.js";
9
9
  import { resolveSpace } from "../space.js";
10
10
  import { registerSpaceCommerce } from "./space-commerce.js";
@@ -156,19 +156,16 @@ export async function collectUploadFiles(paths) {
156
156
  return files;
157
157
  }
158
158
  async function putUploadEntry(entry, uploadUrl, headers) {
159
- const response = await fetch(uploadUrl, {
160
- method: "PUT",
159
+ await putLocalFile({
160
+ url: uploadUrl,
161
+ filePath: entry.localPath,
162
+ size: entry.size,
161
163
  headers,
162
- body: createReadStream(entry.localPath),
163
- duplex: "half",
164
+ label: entry.relativePath,
164
165
  });
165
- if (!response.ok) {
166
- const detail = await response.text().catch(() => "");
167
- throw new Error(`Failed to upload ${entry.relativePath}: HTTP ${response.status}${detail ? ` — ${detail}` : ""}`);
168
- }
169
166
  }
170
167
  async function uploadFiles(command, paths, opts) {
171
- const spaceId = resolveSpace(command);
168
+ const spaceId = await resolveSpace(command);
172
169
  const client = createClient();
173
170
  try {
174
171
  const files = await collectUploadFiles(paths);
@@ -242,7 +239,7 @@ async function sendPrompt(command, words, opts) {
242
239
  && !new Set(["off", "minimal", "low", "medium", "high", "xhigh", "max"]).has(thinkingLevel)) {
243
240
  return error("Invalid thinking level", "Use off|minimal|low|medium|high|xhigh|max");
244
241
  }
245
- const spaceId = resolveSpace(command);
242
+ const spaceId = await resolveSpace(command);
246
243
  const client = createClient();
247
244
  try {
248
245
  const schedule = opts.delayMs
@@ -304,7 +301,7 @@ async function sendPrompt(command, words, opts) {
304
301
  }
305
302
  }
306
303
  async function runCompletionCommand(command, words, opts) {
307
- const spaceId = resolveSpace(command);
304
+ const spaceId = await resolveSpace(command);
308
305
  const content = words.join(" ").trim();
309
306
  if (!content && process.stdin.isTTY) {
310
307
  return error("Message required", "Pass content args or pipe via stdin");
@@ -490,7 +487,7 @@ export function registerSpaces(program) {
490
487
  .description("Show space details")
491
488
  .option("--json", "Output as JSON")
492
489
  .action(async (id, opts) => {
493
- const spaceId = id?.trim() || resolveSpace(spacesCmd);
490
+ const spaceId = id?.trim() || await resolveSpace(spacesCmd);
494
491
  const client = createClient();
495
492
  try {
496
493
  const space = await client.spaces.get(spaceId);
@@ -562,7 +559,7 @@ export function registerSpaces(program) {
562
559
  .description("Upload the space avatar")
563
560
  .option("--json", "Output as JSON")
564
561
  .action(async (path, opts) => {
565
- const spaceId = resolveSpace(spacesCmd);
562
+ const spaceId = await resolveSpace(spacesCmd);
566
563
  const client = createClient();
567
564
  try {
568
565
  const asset = await uploadAvatarAsset({ client, purpose: "space_avatar", spaceId, path });
@@ -699,7 +696,7 @@ export function registerSpaces(program) {
699
696
  .description("Space usage statistics (default: 30 days)")
700
697
  .option("--json", "Output as JSON")
701
698
  .action(async (days, opts) => {
702
- const spaceId = resolveSpace(spacesCmd);
699
+ const spaceId = await resolveSpace(spacesCmd);
703
700
  const client = createClient();
704
701
  try {
705
702
  const usage = await client.space(spaceId).usage.get(parseInteger(days ?? "30", "days", { min: 1 }));
@@ -737,14 +734,14 @@ function registerLabels(spacesCmd) {
737
734
  const labelsCmd = spacesCmd
738
735
  .command("labels")
739
736
  .description("Manage labels")
740
- .hook("preAction", () => { resolveSpace(spacesCmd); });
737
+ .hook("preAction", async () => { await resolveSpace(spacesCmd); });
741
738
  labelsCmd
742
739
  .command("ls")
743
740
  .alias("list")
744
741
  .description("List labels")
745
742
  .option("--json", "Output as JSON")
746
743
  .action(async (opts) => {
747
- const spaceId = resolveSpace(spacesCmd);
744
+ const spaceId = await resolveSpace(spacesCmd);
748
745
  const client = createClient();
749
746
  try {
750
747
  const result = await client.space(spaceId).labels.list();
@@ -764,7 +761,7 @@ function registerLabels(spacesCmd) {
764
761
  .description("Create a label")
765
762
  .option("--json", "Output as JSON")
766
763
  .action(async (labelRef, opts) => {
767
- const spaceId = resolveSpace(spacesCmd);
764
+ const spaceId = await resolveSpace(spacesCmd);
768
765
  const client = createClient();
769
766
  try {
770
767
  const result = await client.space(spaceId).labels.create(labelRef);
@@ -784,7 +781,7 @@ function registerLabels(spacesCmd) {
784
781
  .option("--rank <n>", "Sort rank")
785
782
  .option("--json", "Output as JSON")
786
783
  .action(async (labelRef, opts) => {
787
- const spaceId = resolveSpace(spacesCmd);
784
+ const spaceId = await resolveSpace(spacesCmd);
788
785
  const client = createClient();
789
786
  try {
790
787
  const result = await client.space(spaceId).labels.update(labelRef, {
@@ -805,7 +802,7 @@ function registerLabels(spacesCmd) {
805
802
  .alias("delete")
806
803
  .description("Delete a label")
807
804
  .action(async (labelRef) => {
808
- const spaceId = resolveSpace(spacesCmd);
805
+ const spaceId = await resolveSpace(spacesCmd);
809
806
  const client = createClient();
810
807
  try {
811
808
  await client.space(spaceId).labels.delete(labelRef);
@@ -820,7 +817,7 @@ function registerLabels(spacesCmd) {
820
817
  .description("Reorder labels")
821
818
  .option("--json", "Output as JSON")
822
819
  .action(async (labelRefs, opts) => {
823
- const spaceId = resolveSpace(spacesCmd);
820
+ const spaceId = await resolveSpace(spacesCmd);
824
821
  const client = createClient();
825
822
  try {
826
823
  const result = await client.space(spaceId).labels.reorder(labelRefs);
@@ -839,7 +836,7 @@ function registerLabels(spacesCmd) {
839
836
  .option("--cursor <cursor>", "Page cursor")
840
837
  .option("--json", "Output as JSON")
841
838
  .action(async (labelRef, opts) => {
842
- const spaceId = resolveSpace(spacesCmd);
839
+ const spaceId = await resolveSpace(spacesCmd);
843
840
  const client = createClient();
844
841
  try {
845
842
  const result = await client.space(spaceId).labels.listItems(labelRef, {
@@ -864,7 +861,7 @@ function registerLabels(spacesCmd) {
864
861
  .description("Attach a label")
865
862
  .option("--json", "Output as JSON")
866
863
  .action(async (labelRef, resourceType, resourceRef, opts) => {
867
- const spaceId = resolveSpace(spacesCmd);
864
+ const spaceId = await resolveSpace(spacesCmd);
868
865
  const client = createClient();
869
866
  try {
870
867
  const result = await client.space(spaceId).labels.attach(labelRef, { resourceType: parseLabelResourceType(resourceType), resourceRef });
@@ -880,7 +877,7 @@ function registerLabels(spacesCmd) {
880
877
  .command("detach <labelRef> <resourceType> <resourceRef>")
881
878
  .description("Detach a label")
882
879
  .action(async (labelRef, resourceType, resourceRef) => {
883
- const spaceId = resolveSpace(spacesCmd);
880
+ const spaceId = await resolveSpace(spacesCmd);
884
881
  const client = createClient();
885
882
  try {
886
883
  await client.space(spaceId).labels.detach(labelRef, { resourceType: parseLabelResourceType(resourceType), resourceRef });
@@ -897,7 +894,7 @@ function registerLabels(spacesCmd) {
897
894
  .option("--remove <refs>", "Comma-separated label refs to remove")
898
895
  .option("--json", "Output as JSON")
899
896
  .action(async (resourceType, resourceRef, opts) => {
900
- const spaceId = resolveSpace(spacesCmd);
897
+ const spaceId = await resolveSpace(spacesCmd);
901
898
  const client = createClient();
902
899
  try {
903
900
  const result = await client.space(spaceId).labels.patchResourceLabels(parseLabelResourceType(resourceType), resourceRef, {
@@ -918,7 +915,7 @@ function registerLabels(spacesCmd) {
918
915
  .option("--labels <refs>", "Comma-separated label refs")
919
916
  .option("--json", "Output as JSON")
920
917
  .action(async (resourceType, resourceRef, labelRefs, opts) => {
921
- const spaceId = resolveSpace(spacesCmd);
918
+ const spaceId = await resolveSpace(spacesCmd);
922
919
  const client = createClient();
923
920
  try {
924
921
  const refs = [...parseLabelRefs(opts.labels), ...labelRefs];
@@ -936,14 +933,14 @@ function registerMods(spacesCmd) {
936
933
  const modsCmd = spacesCmd
937
934
  .command("mods")
938
935
  .description("Manage space mods")
939
- .hook("preAction", () => { resolveSpace(spacesCmd); });
936
+ .hook("preAction", async () => { await resolveSpace(spacesCmd); });
940
937
  modsCmd
941
938
  .command("ls")
942
939
  .alias("list")
943
940
  .description("List mods")
944
941
  .option("--json", "Output as JSON")
945
942
  .action(async (opts) => {
946
- const spaceId = resolveSpace(spacesCmd);
943
+ const spaceId = await resolveSpace(spacesCmd);
947
944
  const client = createClient();
948
945
  try {
949
946
  const result = await client.space(spaceId).mods.list();
@@ -969,7 +966,7 @@ function registerMods(spacesCmd) {
969
966
  .option("--json", "Output as JSON")
970
967
  .action(async (modSpaceId, opts) => {
971
968
  await confirmRestart(opts);
972
- const spaceId = resolveSpace(spacesCmd);
969
+ const spaceId = await resolveSpace(spacesCmd);
973
970
  const client = createClient();
974
971
  try {
975
972
  const result = await client.space(spaceId).mods.create({ modSpaceId, name: opts.name, mountSlug: opts.slug });
@@ -988,7 +985,7 @@ function registerMods(spacesCmd) {
988
985
  .option("--json", "Output as JSON")
989
986
  .action(async (modId, opts) => {
990
987
  await confirmRestart(opts);
991
- const spaceId = resolveSpace(spacesCmd);
988
+ const spaceId = await resolveSpace(spacesCmd);
992
989
  const client = createClient();
993
990
  try {
994
991
  const result = await client.space(spaceId).mods.update(modId, { enabled: true });
@@ -1007,7 +1004,7 @@ function registerMods(spacesCmd) {
1007
1004
  .option("--json", "Output as JSON")
1008
1005
  .action(async (modId, opts) => {
1009
1006
  await confirmRestart(opts);
1010
- const spaceId = resolveSpace(spacesCmd);
1007
+ const spaceId = await resolveSpace(spacesCmd);
1011
1008
  const client = createClient();
1012
1009
  try {
1013
1010
  const result = await client.space(spaceId).mods.update(modId, { enabled: false });
@@ -1027,7 +1024,7 @@ function registerMods(spacesCmd) {
1027
1024
  .option("--json", "Output as JSON")
1028
1025
  .action(async (modId, opts) => {
1029
1026
  await confirmRestart(opts);
1030
- const spaceId = resolveSpace(spacesCmd);
1027
+ const spaceId = await resolveSpace(spacesCmd);
1031
1028
  const client = createClient();
1032
1029
  try {
1033
1030
  const result = await client.space(spaceId).mods.remove(modId);
@@ -1111,14 +1108,14 @@ function registerFiles(spacesCmd) {
1111
1108
  const filesCmd = spacesCmd
1112
1109
  .command("files")
1113
1110
  .description("File operations")
1114
- .hook("preAction", () => { resolveSpace(spacesCmd); });
1111
+ .hook("preAction", async () => { await resolveSpace(spacesCmd); });
1115
1112
  filesCmd
1116
1113
  .command("ls [path]")
1117
1114
  .alias("list")
1118
1115
  .description("List directory tree")
1119
1116
  .option("--json", "Output as JSON")
1120
1117
  .action(async (path, opts) => {
1121
- const spaceId = resolveSpace(spacesCmd);
1118
+ const spaceId = await resolveSpace(spacesCmd);
1122
1119
  const client = createClient();
1123
1120
  try {
1124
1121
  const tree = await client.space(spaceId).files.list(path ?? "");
@@ -1143,7 +1140,7 @@ function registerFiles(spacesCmd) {
1143
1140
  .command("cat <path>")
1144
1141
  .description("Read file content")
1145
1142
  .action(async (path) => {
1146
- const spaceId = resolveSpace(spacesCmd);
1143
+ const spaceId = await resolveSpace(spacesCmd);
1147
1144
  const client = createClient();
1148
1145
  try {
1149
1146
  const file = await client.space(spaceId).files.read(path);
@@ -1173,7 +1170,7 @@ function registerFiles(spacesCmd) {
1173
1170
  }
1174
1171
  if (!content)
1175
1172
  return error("No content provided", "Use -c or pipe via stdin");
1176
- const spaceId = resolveSpace(spacesCmd);
1173
+ const spaceId = await resolveSpace(spacesCmd);
1177
1174
  const client = createClient();
1178
1175
  try {
1179
1176
  const result = await client.space(spaceId).files.write({
@@ -1197,7 +1194,7 @@ function registerFiles(spacesCmd) {
1197
1194
  .command("mkdir <path>")
1198
1195
  .description("Create a directory")
1199
1196
  .action(async (path) => {
1200
- const spaceId = resolveSpace(spacesCmd);
1197
+ const spaceId = await resolveSpace(spacesCmd);
1201
1198
  const client = createClient();
1202
1199
  try {
1203
1200
  await client.space(spaceId).files.createDir(path);
@@ -1212,7 +1209,7 @@ function registerFiles(spacesCmd) {
1212
1209
  .description("Delete a file or directory")
1213
1210
  .option("-r, --recursive", "Delete recursively")
1214
1211
  .action(async (path, opts) => {
1215
- const spaceId = resolveSpace(spacesCmd);
1212
+ const spaceId = await resolveSpace(spacesCmd);
1216
1213
  const client = createClient();
1217
1214
  try {
1218
1215
  await client.space(spaceId).files.delete(path, opts.recursive ?? false);
@@ -1226,7 +1223,7 @@ function registerFiles(spacesCmd) {
1226
1223
  .command("mv <from> <to>")
1227
1224
  .description("Move or rename")
1228
1225
  .action(async (from, to) => {
1229
- const spaceId = resolveSpace(spacesCmd);
1226
+ const spaceId = await resolveSpace(spacesCmd);
1230
1227
  const client = createClient();
1231
1228
  try {
1232
1229
  await client.space(spaceId).files.move({ fromPath: from, toPath: to });
@@ -1241,7 +1238,7 @@ function registerFiles(spacesCmd) {
1241
1238
  .description("Show pending workspace changes vs last checkpoint")
1242
1239
  .option("--json", "Output as JSON")
1243
1240
  .action(async (path, opts) => {
1244
- const spaceId = resolveSpace(spacesCmd);
1241
+ const spaceId = await resolveSpace(spacesCmd);
1245
1242
  const client = createClient();
1246
1243
  try {
1247
1244
  if (path) {
@@ -1272,14 +1269,14 @@ function registerSessions(spacesCmd) {
1272
1269
  const sessionsCmd = spacesCmd
1273
1270
  .command("sessions")
1274
1271
  .description("Browse sessions and turns")
1275
- .hook("preAction", () => { resolveSpace(spacesCmd); });
1272
+ .hook("preAction", async () => { await resolveSpace(spacesCmd); });
1276
1273
  sessionsCmd
1277
1274
  .command("ls")
1278
1275
  .alias("list")
1279
1276
  .description("List sessions")
1280
1277
  .option("--json", "Output as JSON")
1281
1278
  .action(async (opts) => {
1282
- const spaceId = resolveSpace(spacesCmd);
1279
+ const spaceId = await resolveSpace(spacesCmd);
1283
1280
  const client = createClient();
1284
1281
  try {
1285
1282
  const result = await client.space(spaceId).sessions.list();
@@ -1306,7 +1303,7 @@ function registerSessions(spacesCmd) {
1306
1303
  .option("--label <ref>", "Attach a label, e.g. Bug or Area/Frontend", collectOption, [])
1307
1304
  .option("--json", "Output as JSON")
1308
1305
  .action(async (title, opts) => {
1309
- const spaceId = resolveSpace(spacesCmd);
1306
+ const spaceId = await resolveSpace(spacesCmd);
1310
1307
  const client = createClient();
1311
1308
  try {
1312
1309
  const result = await client.space(spaceId).sessions.create({
@@ -1330,7 +1327,7 @@ function registerSessions(spacesCmd) {
1330
1327
  .description("Session details")
1331
1328
  .option("--json", "Output as JSON")
1332
1329
  .action(async (id, opts) => {
1333
- const spaceId = resolveSpace(spacesCmd);
1330
+ const spaceId = await resolveSpace(spacesCmd);
1334
1331
  const client = createClient();
1335
1332
  try {
1336
1333
  const result = await client.space(spaceId).session(id).get();
@@ -1352,7 +1349,7 @@ function registerSessions(spacesCmd) {
1352
1349
  .command("rename <id> <name>")
1353
1350
  .description("Rename a session")
1354
1351
  .action(async (id, name) => {
1355
- const spaceId = resolveSpace(spacesCmd);
1352
+ const spaceId = await resolveSpace(spacesCmd);
1356
1353
  const client = createClient();
1357
1354
  try {
1358
1355
  await client.space(spaceId).session(id).rename(name);
@@ -1368,7 +1365,7 @@ function registerSessions(spacesCmd) {
1368
1365
  .description("Stream realtime session events")
1369
1366
  .option("--json", "Output as JSON")
1370
1367
  .action(async (id, opts) => {
1371
- const spaceId = resolveSpace(spacesCmd);
1368
+ const spaceId = await resolveSpace(spacesCmd);
1372
1369
  const client = createClient();
1373
1370
  const session = client.space(spaceId).session(id);
1374
1371
  process.stdout.write(" Listening for events...\n\n");
@@ -1423,7 +1420,7 @@ function registerTurns(sessionsCmd) {
1423
1420
  .option("--limit <n>", "Page size", "30")
1424
1421
  .option("--json", "Output as JSON")
1425
1422
  .action(async (sessionId, opts) => {
1426
- const spaceId = resolveSpace(sessionsCmd);
1423
+ const spaceId = await resolveSpace(sessionsCmd);
1427
1424
  const client = createClient();
1428
1425
  try {
1429
1426
  const result = await client.space(spaceId).session(sessionId).turns.listPaginated({
@@ -1455,7 +1452,7 @@ function registerTurns(sessionsCmd) {
1455
1452
  .description("Show turn details")
1456
1453
  .option("--json", "Output as JSON")
1457
1454
  .action(async (sessionId, turnId, opts) => {
1458
- const spaceId = resolveSpace(sessionsCmd);
1455
+ const spaceId = await resolveSpace(sessionsCmd);
1459
1456
  const client = createClient();
1460
1457
  try {
1461
1458
  const result = await client.space(spaceId).session(sessionId).turns.get(turnId);
@@ -1484,7 +1481,7 @@ function registerTurns(sessionsCmd) {
1484
1481
  .description("Run a queued follow-up now")
1485
1482
  .option("--json", "Output as JSON")
1486
1483
  .action(async (sessionId, turnId, opts) => {
1487
- const spaceId = resolveSpace(sessionsCmd);
1484
+ const spaceId = await resolveSpace(sessionsCmd);
1488
1485
  const client = createClient();
1489
1486
  try {
1490
1487
  const result = await client.space(spaceId).session(sessionId).steerTurn(turnId);
@@ -1501,7 +1498,7 @@ function registerTurns(sessionsCmd) {
1501
1498
  .description("Cancel a queued follow-up")
1502
1499
  .option("--json", "Output as JSON")
1503
1500
  .action(async (sessionId, turnId, opts) => {
1504
- const spaceId = resolveSpace(sessionsCmd);
1501
+ const spaceId = await resolveSpace(sessionsCmd);
1505
1502
  const client = createClient();
1506
1503
  try {
1507
1504
  const result = await client.space(spaceId).session(sessionId).cancelTurn(turnId);
@@ -1520,7 +1517,7 @@ function registerTurns(sessionsCmd) {
1520
1517
  .option("--limit <n>", "Page size", "100")
1521
1518
  .option("--json", "Output as JSON")
1522
1519
  .action(async (sessionId, opts) => {
1523
- const spaceId = resolveSpace(sessionsCmd);
1520
+ const spaceId = await resolveSpace(sessionsCmd);
1524
1521
  const client = createClient();
1525
1522
  try {
1526
1523
  const result = await client.space(spaceId).session(sessionId).turns.index({
@@ -1554,7 +1551,7 @@ function registerTurns(sessionsCmd) {
1554
1551
  .option("--after <n>", "Turns after anchor", "20")
1555
1552
  .option("--json", "Output as JSON")
1556
1553
  .action(async (sessionId, opts) => {
1557
- const spaceId = resolveSpace(sessionsCmd);
1554
+ const spaceId = await resolveSpace(sessionsCmd);
1558
1555
  if (!opts.sequence && !opts.turn)
1559
1556
  return error("Missing anchor", "Use --sequence <n> or --turn <id>");
1560
1557
  const client = createClient();
@@ -1647,14 +1644,14 @@ function registerMembers(spacesCmd) {
1647
1644
  const memCmd = spacesCmd
1648
1645
  .command("members")
1649
1646
  .description("Member management")
1650
- .hook("preAction", () => { resolveSpace(spacesCmd); });
1647
+ .hook("preAction", async () => { await resolveSpace(spacesCmd); });
1651
1648
  memCmd
1652
1649
  .command("ls")
1653
1650
  .alias("list")
1654
1651
  .description("List space members")
1655
1652
  .option("--json", "Output as JSON")
1656
1653
  .action(async (opts) => {
1657
- const spaceId = resolveSpace(spacesCmd);
1654
+ const spaceId = await resolveSpace(spacesCmd);
1658
1655
  const client = createClient();
1659
1656
  try {
1660
1657
  const result = await client.space(spaceId).members.list();
@@ -1678,7 +1675,7 @@ function registerMembers(spacesCmd) {
1678
1675
  .command("update <userId> <role>")
1679
1676
  .description("Change member role (host | builder | guest)")
1680
1677
  .action(async (userId, role) => {
1681
- const spaceId = resolveSpace(spacesCmd);
1678
+ const spaceId = await resolveSpace(spacesCmd);
1682
1679
  const client = createClient();
1683
1680
  try {
1684
1681
  await client.space(spaceId).members.update(userId, parseChoice(role, "role", SPACE_ROLES));
@@ -1692,7 +1689,7 @@ function registerMembers(spacesCmd) {
1692
1689
  .command("remove <userId>")
1693
1690
  .description("Remove a member")
1694
1691
  .action(async (userId) => {
1695
- const spaceId = resolveSpace(spacesCmd);
1692
+ const spaceId = await resolveSpace(spacesCmd);
1696
1693
  const client = createClient();
1697
1694
  try {
1698
1695
  await client.space(spaceId).members.remove(userId);
@@ -1708,13 +1705,13 @@ function registerAccess(spacesCmd) {
1708
1705
  const accCmd = spacesCmd
1709
1706
  .command("access")
1710
1707
  .description("Access control")
1711
- .hook("preAction", () => { resolveSpace(spacesCmd); });
1708
+ .hook("preAction", async () => { await resolveSpace(spacesCmd); });
1712
1709
  accCmd
1713
1710
  .command("get")
1714
1711
  .description("Get access policy")
1715
1712
  .option("--json", "Output as JSON")
1716
1713
  .action(async (opts) => {
1717
- const spaceId = resolveSpace(spacesCmd);
1714
+ const spaceId = await resolveSpace(spacesCmd);
1718
1715
  const client = createClient();
1719
1716
  try {
1720
1717
  const policy = await client.space(spaceId).access.get();
@@ -1736,7 +1733,7 @@ function registerAccess(spacesCmd) {
1736
1733
  .option("--anonymous <role>", "Role for anonymous users (host|builder|guest|null)")
1737
1734
  .option("--json", "Output as JSON")
1738
1735
  .action(async (opts) => {
1739
- const spaceId = resolveSpace(spacesCmd);
1736
+ const spaceId = await resolveSpace(spacesCmd);
1740
1737
  const client = createClient();
1741
1738
  try {
1742
1739
  const policy = await client.space(spaceId).access.set({
@@ -1761,7 +1758,7 @@ function registerCheckpoints(spacesCmd) {
1761
1758
  const cpCmd = spacesCmd
1762
1759
  .command("checkpoints")
1763
1760
  .description("Checkpoint management")
1764
- .hook("preAction", () => { resolveSpace(spacesCmd); });
1761
+ .hook("preAction", async () => { await resolveSpace(spacesCmd); });
1765
1762
  cpCmd
1766
1763
  .command("ls")
1767
1764
  .alias("list")
@@ -1770,7 +1767,7 @@ function registerCheckpoints(spacesCmd) {
1770
1767
  .option("--cursor <cursor>", "Pagination cursor")
1771
1768
  .option("--json", "Output as JSON")
1772
1769
  .action(async (opts) => {
1773
- const spaceId = resolveSpace(spacesCmd);
1770
+ const spaceId = await resolveSpace(spacesCmd);
1774
1771
  const client = createClient();
1775
1772
  try {
1776
1773
  const result = await client.space(spaceId).checkpoints.list({
@@ -1799,7 +1796,7 @@ function registerCheckpoints(spacesCmd) {
1799
1796
  .description("Checkpoint details")
1800
1797
  .option("--json", "Output as JSON")
1801
1798
  .action(async (id, opts) => {
1802
- const spaceId = resolveSpace(spacesCmd);
1799
+ const spaceId = await resolveSpace(spacesCmd);
1803
1800
  const client = createClient();
1804
1801
  try {
1805
1802
  const result = await client.space(spaceId).checkpoints.get(id);
@@ -1822,7 +1819,7 @@ function registerCheckpoints(spacesCmd) {
1822
1819
  .description("Create a checkpoint")
1823
1820
  .option("--json", "Output as JSON")
1824
1821
  .action(async (description, opts) => {
1825
- const spaceId = resolveSpace(spacesCmd);
1822
+ const spaceId = await resolveSpace(spacesCmd);
1826
1823
  const client = createClient();
1827
1824
  try {
1828
1825
  const result = await client.space(spaceId).checkpoints.create(description ?? null);
@@ -1839,7 +1836,7 @@ function registerCheckpoints(spacesCmd) {
1839
1836
  .description("List checkpoint tree")
1840
1837
  .option("--json", "Output as JSON")
1841
1838
  .action(async (checkpointId, path, opts) => {
1842
- const spaceId = resolveSpace(spacesCmd);
1839
+ const spaceId = await resolveSpace(spacesCmd);
1843
1840
  const client = createClient();
1844
1841
  try {
1845
1842
  const tree = await client.space(spaceId).checkpoints(checkpointId).files.list(path ?? "");
@@ -1866,7 +1863,7 @@ function registerCheckpoints(spacesCmd) {
1866
1863
  .description("Show checkpoint file content")
1867
1864
  .option("--json", "Output as JSON")
1868
1865
  .action(async (checkpointId, path, opts) => {
1869
- const spaceId = resolveSpace(spacesCmd);
1866
+ const spaceId = await resolveSpace(spacesCmd);
1870
1867
  const client = createClient();
1871
1868
  try {
1872
1869
  const file = await client.space(spaceId).checkpoints(checkpointId).files.read(path);
@@ -1888,7 +1885,7 @@ function registerCheckpoints(spacesCmd) {
1888
1885
  .option("--base <checkpointId>", "Compare against another checkpoint")
1889
1886
  .option("--json", "Output as JSON")
1890
1887
  .action(async (checkpointId, path, opts) => {
1891
- const spaceId = resolveSpace(spacesCmd);
1888
+ const spaceId = await resolveSpace(spacesCmd);
1892
1889
  const client = createClient();
1893
1890
  try {
1894
1891
  if (path) {
@@ -0,0 +1,5 @@
1
+ export declare function proxyEnvPresent(env?: NodeJS.ProcessEnv): boolean;
2
+ export declare function envProxyAlreadyEnabled(execArgv?: readonly string[], env?: NodeJS.ProcessEnv): boolean;
3
+ export declare function supportsUseEnvProxy(version?: string): boolean;
4
+ export declare function shouldRelaunchWithEnvProxy(execArgv?: readonly string[], env?: NodeJS.ProcessEnv, nodeVersion?: string): boolean;
5
+ export declare const envProxyExecArgv: readonly ["--use-env-proxy"];
@@ -0,0 +1,20 @@
1
+ const PROXY_ENV_KEYS = ["http_proxy", "https_proxy", "HTTP_PROXY", "HTTPS_PROXY", "all_proxy", "ALL_PROXY"];
2
+ const USE_ENV_PROXY_FLAG = "--use-env-proxy";
3
+ export function proxyEnvPresent(env = process.env) {
4
+ return PROXY_ENV_KEYS.some((key) => Boolean(env[key]?.trim()));
5
+ }
6
+ export function envProxyAlreadyEnabled(execArgv = process.execArgv, env = process.env) {
7
+ if (execArgv.includes(USE_ENV_PROXY_FLAG) || env.NODE_USE_ENV_PROXY === "1")
8
+ return true;
9
+ return (env.NODE_OPTIONS ?? "").split(/\s+/).includes(USE_ENV_PROXY_FLAG);
10
+ }
11
+ export function supportsUseEnvProxy(version = process.versions.node) {
12
+ const [major = 0, minor = 0] = version.split(".").map((part) => Number.parseInt(part, 10));
13
+ if (!Number.isFinite(major) || !Number.isFinite(minor))
14
+ return false;
15
+ return major >= 24 || (major === 22 && minor >= 21);
16
+ }
17
+ export function shouldRelaunchWithEnvProxy(execArgv = process.execArgv, env = process.env, nodeVersion = process.versions.node) {
18
+ return supportsUseEnvProxy(nodeVersion) && proxyEnvPresent(env) && !envProxyAlreadyEnabled(execArgv, env);
19
+ }
20
+ export const envProxyExecArgv = [USE_ENV_PROXY_FLAG];
@@ -0,0 +1,18 @@
1
+ import type { Command } from "commander";
2
+ export type HelpResolution = {
3
+ kind: "passthrough";
4
+ } | {
5
+ kind: "help";
6
+ command: Command;
7
+ } | {
8
+ kind: "run-help";
9
+ } | {
10
+ kind: "unknown";
11
+ token: string;
12
+ tryCommand?: string;
13
+ suggestion?: string;
14
+ };
15
+ export declare function resolveHelpPath(program: Command, argv: string[]): HelpResolution;
16
+ export declare function formatUnknownCommandError(result: Extract<HelpResolution, {
17
+ kind: "unknown";
18
+ }>): string;