bdy 1.25.37-dev → 1.25.38-dev-pr

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.
Files changed (110) hide show
  1. package/distTs/package.json +2 -1
  2. package/distTs/src/agent/agent.js +65 -6
  3. package/distTs/src/api/client.js +191 -1
  4. package/distTs/src/autocomplete.js +90 -0
  5. package/distTs/src/cliError.js +5 -0
  6. package/distTs/src/cliIndex.js +3 -0
  7. package/distTs/src/command/artifact/downloadDir.js +110 -0
  8. package/distTs/src/command/autocomplete/install.js +16 -0
  9. package/distTs/src/command/autocomplete/uninstall.js +16 -0
  10. package/distTs/src/command/autocomplete.js +14 -0
  11. package/distTs/src/command/environment/resolve.js +39 -0
  12. package/distTs/src/command/login.js +1 -1
  13. package/distTs/src/command/package/create.js +64 -0
  14. package/distTs/src/command/package/delete.js +38 -0
  15. package/distTs/src/command/package/docker/login.js +26 -0
  16. package/distTs/src/command/package/docker.js +11 -0
  17. package/distTs/src/command/package/download.js +138 -0
  18. package/distTs/src/command/package/get.js +36 -0
  19. package/distTs/src/command/package/list.js +31 -0
  20. package/distTs/src/command/package/publish.js +241 -0
  21. package/distTs/src/command/package/version/delete.js +39 -0
  22. package/distTs/src/command/package/version/get.js +45 -0
  23. package/distTs/src/command/package/version/list.js +47 -0
  24. package/distTs/src/command/package/version.js +16 -0
  25. package/distTs/src/command/package.js +26 -0
  26. package/distTs/src/command/pipeline/run/apply.js +62 -0
  27. package/distTs/src/command/pr/comment/add.js +66 -0
  28. package/distTs/src/command/pr/comment/list.js +169 -0
  29. package/distTs/src/command/pr/comment/status.js +48 -0
  30. package/distTs/src/command/pr/comment.js +19 -0
  31. package/distTs/src/command/pr/create.js +43 -0
  32. package/distTs/src/command/pr/diff.js +227 -0
  33. package/distTs/src/command/pr/file/list.js +124 -0
  34. package/distTs/src/command/pr/file/mark.js +45 -0
  35. package/distTs/src/command/pr/file.js +16 -0
  36. package/distTs/src/command/pr/get.js +29 -0
  37. package/distTs/src/command/pr/list.js +79 -0
  38. package/distTs/src/command/pr/merge.js +66 -0
  39. package/distTs/src/command/pr/review/request.js +29 -0
  40. package/distTs/src/command/pr/review/start.js +29 -0
  41. package/distTs/src/command/pr/review/verdict.js +81 -0
  42. package/distTs/src/command/pr/review.js +18 -0
  43. package/distTs/src/command/pr/shared.js +595 -0
  44. package/distTs/src/command/pr/state.js +38 -0
  45. package/distTs/src/command/pr/summary.js +316 -0
  46. package/distTs/src/command/pr/update.js +54 -0
  47. package/distTs/src/command/pr/updateBranch.js +22 -0
  48. package/distTs/src/command/pr/versions.js +42 -0
  49. package/distTs/src/command/pr.js +39 -0
  50. package/distTs/src/command/scrape/validation.js +154 -0
  51. package/distTs/src/command/scrape.js +144 -0
  52. package/distTs/src/command/suiteLink.js +14 -0
  53. package/distTs/src/command/tests/visual/result/download.js +31 -0
  54. package/distTs/src/command/tests/visual/result/get.js +68 -0
  55. package/distTs/src/command/tests/visual/result/list.js +49 -0
  56. package/distTs/src/command/tests/visual/result.js +23 -0
  57. package/distTs/src/command/tests/visual/session/get.js +70 -0
  58. package/distTs/src/command/tests/visual/session/list.js +69 -0
  59. package/distTs/src/command/tests/visual/session/open.js +22 -0
  60. package/distTs/src/command/tests/visual/session/reviewUrl.js +37 -0
  61. package/distTs/src/command/tests/visual/session/update.js +26 -0
  62. package/distTs/src/command/tests/visual/shared/context.js +144 -0
  63. package/distTs/src/command/tests/visual/shared/diffRegions.js +172 -0
  64. package/distTs/src/command/tests/visual/shared/format.js +21 -0
  65. package/distTs/src/command/tests/visual/shared/lookup.js +107 -0
  66. package/distTs/src/command/tests/visual/shared/options.js +90 -0
  67. package/distTs/src/command/tests/visual/shared/review.js +146 -0
  68. package/distTs/src/command/tests/visual/shared/reviewUrl.js +62 -0
  69. package/distTs/src/command/tests/visual/shared/session.js +217 -0
  70. package/distTs/src/command/tests/visual/snapshot/get.js +46 -0
  71. package/distTs/src/command/tests/visual/snapshot/list.js +68 -0
  72. package/distTs/src/command/tests/visual/snapshot/open.js +26 -0
  73. package/distTs/src/command/tests/visual/snapshot/reviewUrl.js +48 -0
  74. package/distTs/src/command/tests/visual/snapshot.js +28 -0
  75. package/distTs/src/command/tests/visual/suite/create.js +38 -0
  76. package/distTs/src/command/tests/visual/suite/delete.js +29 -0
  77. package/distTs/src/command/tests/visual/suite/get.js +43 -0
  78. package/distTs/src/command/tests/visual/suite/list.js +35 -0
  79. package/distTs/src/command/tests/visual/suite/open.js +20 -0
  80. package/distTs/src/command/tests/visual/suite/update.js +47 -0
  81. package/distTs/src/command/tests/visual/suite.js +30 -0
  82. package/distTs/src/command/tunnel/http.js +1 -1
  83. package/distTs/src/command/tunnel/start.js +1 -1
  84. package/distTs/src/command/tunnel/tcp.js +1 -1
  85. package/distTs/src/command/tunnel/tls.js +1 -1
  86. package/distTs/src/command/ut/upload.js +86 -0
  87. package/distTs/src/command/ut.js +12 -0
  88. package/distTs/src/command/vt/close.js +27 -0
  89. package/distTs/src/command/vt/compare/validation.js +46 -0
  90. package/distTs/src/command/vt/compare.js +100 -0
  91. package/distTs/src/command/vt/exec.js +82 -0
  92. package/distTs/src/command/vt/installBrowser.js +20 -0
  93. package/distTs/src/command/vt/shared/validation.js +145 -0
  94. package/distTs/src/command/vt/storybook.js +138 -0
  95. package/distTs/src/command/vt.js +20 -0
  96. package/distTs/src/command/yaml/agents.js +88 -0
  97. package/distTs/src/command/yaml/init.js +110 -0
  98. package/distTs/src/main.js +190 -0
  99. package/distTs/src/output/pipeline.js +54 -56
  100. package/distTs/src/output.js +83 -26
  101. package/distTs/src/texts.js +450 -1
  102. package/distTs/src/tunnel/output/interactive/tunnel.js +28 -11
  103. package/distTs/src/tunnel/output/noninteractive/tunnel.js +17 -1
  104. package/distTs/src/tunnel/output/noninteractive/tunnelJsonl.js +8 -0
  105. package/distTs/src/types/options.js +2 -0
  106. package/distTs/src/types/scrape.js +2 -0
  107. package/distTs/src/types/tunnel.js +6 -1
  108. package/distTs/src/types/visualTests.js +2 -0
  109. package/distTs/src/utils.js +134 -3
  110. package/package.json +2 -1
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bdy",
3
3
  "preferGlobal": false,
4
- "version": "1.25.37-dev",
4
+ "version": "1.25.38-dev-pr",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
7
7
  "homepage": "https://buddy.works/docs/cli",
@@ -32,6 +32,7 @@
32
32
  "e2e:target": "vitest run --config e2e/vitest.config.mts e2e/modules/target/",
33
33
  "e2e:environment": "vitest run --config e2e/vitest.config.mts e2e/modules/environment/",
34
34
  "e2e:yaml": "vitest run --config e2e/vitest.config.mts e2e/modules/yaml/",
35
+ "e2e:pr": "vitest run --config e2e/vitest.config.mts e2e/modules/pr/",
35
36
  "unit": "vitest run --config vitest.config.mts"
36
37
  },
37
38
  "files": [
@@ -26,6 +26,9 @@ class Agent extends events_1.default {
26
26
  socket;
27
27
  manager;
28
28
  updateStatusExpiry;
29
+ replaceTunnelExpiry;
30
+ replacedTunnelId;
31
+ replacementTunnelId;
29
32
  onRefresh;
30
33
  constructor(id, host, token, service, target, tunneling, proxy, tags, api, disabled) {
31
34
  super();
@@ -43,6 +46,9 @@ class Agent extends events_1.default {
43
46
  this.api = api;
44
47
  this.manager = null;
45
48
  this.updateStatusExpiry = null;
49
+ this.replaceTunnelExpiry = null;
50
+ this.replacedTunnelId = null;
51
+ this.replacementTunnelId = null;
46
52
  this.onRefresh = null;
47
53
  this.socket = new client_1.default(host, id, token);
48
54
  this.socket.on(tunnel_1.TUNNEL_SOCKET_EVENT.FETCH_SUCCESS, (data) => this._onSocketFetch(data));
@@ -62,6 +68,7 @@ class Agent extends events_1.default {
62
68
  if (this.updateStatusExpiry)
63
69
  clearTimeout(this.updateStatusExpiry);
64
70
  this.updateStatusExpiry = null;
71
+ this.clearTunnelReplacement();
65
72
  this.manager = null;
66
73
  this.onRefresh = null;
67
74
  this.api = null;
@@ -70,11 +77,25 @@ class Agent extends events_1.default {
70
77
  }
71
78
  _onSocketTunnel(data, action) {
72
79
  if (action === 'DEL') {
73
- this.destroyTunnel(data.id);
74
- if (!this.service && this.tunnels.length <= 0)
75
- output_1.default.exitError(texts_1.ERR_TUNNEL_REMOVED);
80
+ if (this.service) {
81
+ this.destroyTunnel(data.id);
82
+ return;
83
+ }
84
+ // A rename or a region change arrives as DEL of the old tunnel and ADD of its
85
+ // replacement. The session survives it: the old tunnel stops quietly and waits for
86
+ // the ADD; without one in time the tunnel was deleted for good.
87
+ if (!this.destroyTunnel(data.id, false))
88
+ return;
89
+ if (this.tunnels.length > 0)
90
+ return;
91
+ this.awaitTunnelReplacement(data.id);
76
92
  }
77
93
  else {
94
+ // The ADD names the replacement - the fetch alone cannot tell it from any other
95
+ // tunnel of the agent
96
+ if (this.replacedTunnelId && action === 'ADD' && data.id !== this.replacedTunnelId) {
97
+ this.replacementTunnelId = data.id;
98
+ }
78
99
  logger_1.default.debug('Socket fetch tunnel after sync push');
79
100
  if (this.socket) {
80
101
  this.socket.fetch(!this.disabled, null, null, false, [], false, 1000);
@@ -141,7 +162,10 @@ class Agent extends events_1.default {
141
162
  await this.makeAction(data.agent.action);
142
163
  this.reclearLostUpdateStatus(data.agent.action);
143
164
  const filtered = (data.tunnels || []).filter((t) => !!t.domain);
144
- this.refreshTunnels(filtered);
165
+ if (this.replacedTunnelId)
166
+ this.resolveTunnelReplacement(filtered);
167
+ else
168
+ this.refreshTunnels(filtered);
145
169
  }
146
170
  catch (err) {
147
171
  logger_1.default.error('Fetch error');
@@ -483,14 +507,49 @@ class Agent extends events_1.default {
483
507
  tunnel.on(tunnel_1.TUNNEL_EVENT.STOPPED, () => this.update());
484
508
  tunnel.on(tunnel_1.TUNNEL_EVENT.HTTP_REQUEST, (t, logRequest) => this.httpRequest(t.id, logRequest));
485
509
  }
486
- destroyTunnel(id) {
510
+ destroyTunnel(id, emitStopped = true) {
487
511
  const tunnel = this.tunnels.find((t) => t.id === id);
488
512
  if (!tunnel)
489
513
  return null;
490
514
  this.tunnels = this.tunnels.filter((t) => t.id !== tunnel.id);
491
- tunnel.stop();
515
+ tunnel.stop(emitStopped);
492
516
  tunnel.removeAllListeners();
493
517
  return tunnel;
494
518
  }
519
+ // No fetch of its own: the ADD that names the replacement triggers one.
520
+ awaitTunnelReplacement(id) {
521
+ this.clearTunnelReplacement();
522
+ this.replacedTunnelId = id;
523
+ this.replaceTunnelExpiry = setTimeout(() => this.tunnelRemoved(), utils_1.AGENT_TUNNEL_REPLACE_TIMEOUT_MS);
524
+ }
525
+ resolveTunnelReplacement(tunnels) {
526
+ // A fetch answered before the ADD (one from the refresh loop, a stale one listing the
527
+ // old tunnel, or one that caught the backend between the delete and the create)
528
+ // decides nothing - only the one listing the tunnel the ADD named does.
529
+ const replacementId = this.replacementTunnelId;
530
+ if (!replacementId || !tunnels.some((t) => t.id === replacementId))
531
+ return;
532
+ const replacedId = this.replacedTunnelId;
533
+ this.clearTunnelReplacement();
534
+ this.refreshTunnels(tunnels.filter((t) => t.id !== replacedId));
535
+ const replacement = this.tunnels.find((t) => t.id === replacementId);
536
+ if (!replacement)
537
+ return this.tunnelRemoved();
538
+ this.emit(tunnel_1.AGENT_EVENT.TUNNEL_REPLACED, replacement);
539
+ }
540
+ // Ends the session the way a stopped tunnel always has (the output's own exit, a
541
+ // `stopped` record in jsonl); the error exit is only for a session nothing renders.
542
+ tunnelRemoved() {
543
+ this.clearTunnelReplacement();
544
+ if (!this.emit(tunnel_1.AGENT_EVENT.TUNNEL_REMOVED))
545
+ output_1.default.exitError(texts_1.ERR_TUNNEL_REMOVED);
546
+ }
547
+ clearTunnelReplacement() {
548
+ if (this.replaceTunnelExpiry)
549
+ clearTimeout(this.replaceTunnelExpiry);
550
+ this.replaceTunnelExpiry = null;
551
+ this.replacedTunnelId = null;
552
+ this.replacementTunnelId = null;
553
+ }
495
554
  }
496
555
  exports.default = Agent;
@@ -254,6 +254,7 @@ class ApiClient {
254
254
  else {
255
255
  let message;
256
256
  let nonJsonBody = false;
257
+ let errorBody;
257
258
  try {
258
259
  const json = await responseBody.json();
259
260
  logger_1.default.debug('API CLIENT PARSED RESPONSE:');
@@ -262,6 +263,7 @@ class ApiClient {
262
263
  const value = json?.errors?.[0]?.message ?? json?.error_description ?? json?.error;
263
264
  if (typeof value === 'string')
264
265
  message = value;
266
+ errorBody = json;
265
267
  }
266
268
  catch (err) {
267
269
  nonJsonBody = true;
@@ -270,7 +272,10 @@ class ApiClient {
270
272
  // Edge/WAF throttling uses 403 with an HTML body. Preserve the legacy
271
273
  // rate-limit classification; JSON 403 responses still report API errors.
272
274
  const error = (0, texts_1.ERR_API_DETAILS)(status === 403 && nonJsonBody ? 429 : status, message, path, this.baseUrl, rateLimitReset);
273
- throw new cliError_1.default(error.code, error.message, error.hint);
275
+ const cliError = new cliError_1.default(error.code, error.message, error.hint);
276
+ cliError.status = status;
277
+ cliError.body = errorBody;
278
+ throw cliError;
274
279
  }
275
280
  }
276
281
  // Set by the CLI bootstrap (Input.restApiTokenClient); the transport layer
@@ -812,6 +817,191 @@ class ApiClient {
812
817
  parseResponseBody: false,
813
818
  });
814
819
  }
820
+ // Pull request methods (Buddy-hosted repositories)
821
+ pullsPath(workspace, project, number) {
822
+ const base = `/workspaces/${encodeURIComponent(workspace)}/projects/${encodeURIComponent(project)}/repository/pulls`;
823
+ return number === undefined ? base : `${base}/${encodeURIComponent(number)}`;
824
+ }
825
+ static compactQuery(query) {
826
+ const result = {};
827
+ for (const [key, value] of Object.entries(query)) {
828
+ if (value !== undefined && value !== null && value !== '') {
829
+ result[key] = String(value);
830
+ }
831
+ }
832
+ return result;
833
+ }
834
+ async getPullRequests(workspace, project, query = {}) {
835
+ return await this.request({
836
+ method: 'GET',
837
+ path: this.pullsPath(workspace, project),
838
+ query: ApiClient.compactQuery(query),
839
+ parseResponseBody: true,
840
+ });
841
+ }
842
+ async getPullRequest(workspace, project, number) {
843
+ return await this.request({
844
+ method: 'GET',
845
+ path: this.pullsPath(workspace, project, number),
846
+ parseResponseBody: true,
847
+ });
848
+ }
849
+ async createPullRequest(workspace, project, body) {
850
+ return await this.request({
851
+ method: 'POST',
852
+ path: this.pullsPath(workspace, project),
853
+ body,
854
+ parseResponseBody: true,
855
+ });
856
+ }
857
+ async updatePullRequest(workspace, project, number, body) {
858
+ return await this.request({
859
+ method: 'PATCH',
860
+ path: this.pullsPath(workspace, project, number),
861
+ body,
862
+ parseResponseBody: true,
863
+ });
864
+ }
865
+ async mergePullRequest(workspace, project, number, body) {
866
+ return await this.request({
867
+ method: 'PUT',
868
+ path: `${this.pullsPath(workspace, project, number)}/merge`,
869
+ body,
870
+ parseResponseBody: true,
871
+ });
872
+ }
873
+ async updatePullRequestBranch(workspace, project, number) {
874
+ return await this.request({
875
+ method: 'PUT',
876
+ path: `${this.pullsPath(workspace, project, number)}/update-branch`,
877
+ parseResponseBody: true,
878
+ });
879
+ }
880
+ async getPullRequestVersions(workspace, project, number) {
881
+ return await this.request({
882
+ method: 'GET',
883
+ path: `${this.pullsPath(workspace, project, number)}/versions`,
884
+ parseResponseBody: true,
885
+ });
886
+ }
887
+ async getPullRequestFiles(workspace, project, number, query = {}) {
888
+ return await this.request({
889
+ method: 'GET',
890
+ path: `${this.pullsPath(workspace, project, number)}/files`,
891
+ query: ApiClient.compactQuery(query),
892
+ parseResponseBody: true,
893
+ });
894
+ }
895
+ async markPullRequestFilesViewed(workspace, project, number, body) {
896
+ return await this.request({
897
+ method: 'POST',
898
+ path: `${this.pullsPath(workspace, project, number)}/files/viewed`,
899
+ body,
900
+ parseResponseBody: true,
901
+ });
902
+ }
903
+ async getPullRequestDiff(workspace, project, number, query) {
904
+ return await this.request({
905
+ method: 'GET',
906
+ path: `${this.pullsPath(workspace, project, number)}/diff`,
907
+ query: ApiClient.compactQuery(query),
908
+ parseResponseBody: true,
909
+ });
910
+ }
911
+ async getPullRequestReview(workspace, project, number) {
912
+ return await this.request({
913
+ method: 'GET',
914
+ path: `${this.pullsPath(workspace, project, number)}/review`,
915
+ parseResponseBody: true,
916
+ });
917
+ }
918
+ async startPullRequestReview(workspace, project, number, version) {
919
+ return await this.request({
920
+ method: 'POST',
921
+ path: `${this.pullsPath(workspace, project, number)}/review`,
922
+ body: { version },
923
+ parseResponseBody: true,
924
+ });
925
+ }
926
+ async submitPullRequestVerdict(workspace, project, number, body) {
927
+ return await this.request({
928
+ method: 'PUT',
929
+ path: `${this.pullsPath(workspace, project, number)}/review`,
930
+ body,
931
+ parseResponseBody: true,
932
+ });
933
+ }
934
+ async getPullRequestReviews(workspace, project, number) {
935
+ return await this.request({
936
+ method: 'GET',
937
+ path: `${this.pullsPath(workspace, project, number)}/reviews`,
938
+ parseResponseBody: true,
939
+ });
940
+ }
941
+ async requestPullRequestReview(workspace, project, number, reviewers) {
942
+ return await this.request({
943
+ method: 'POST',
944
+ path: `${this.pullsPath(workspace, project, number)}/reviewers`,
945
+ body: { reviewers },
946
+ parseResponseBody: true,
947
+ });
948
+ }
949
+ async getPullRequestActivity(workspace, project, number, since) {
950
+ return await this.request({
951
+ method: 'GET',
952
+ path: `${this.pullsPath(workspace, project, number)}/activity`,
953
+ query: ApiClient.compactQuery({ since }),
954
+ parseResponseBody: true,
955
+ });
956
+ }
957
+ async addPullRequestComment(workspace, project, number, comment) {
958
+ return await this.request({
959
+ method: 'POST',
960
+ path: `${this.pullsPath(workspace, project, number)}/comments`,
961
+ body: { comment },
962
+ parseResponseBody: true,
963
+ });
964
+ }
965
+ async getPullRequestThreads(workspace, project, number, query = {}) {
966
+ return await this.request({
967
+ method: 'GET',
968
+ path: `${this.pullsPath(workspace, project, number)}/threads`,
969
+ query: ApiClient.compactQuery(query),
970
+ parseResponseBody: true,
971
+ });
972
+ }
973
+ async getPullRequestThread(workspace, project, number, threadId, version) {
974
+ return await this.request({
975
+ method: 'GET',
976
+ path: `${this.pullsPath(workspace, project, number)}/threads/${encodeURIComponent(threadId)}`,
977
+ query: ApiClient.compactQuery({ version }),
978
+ parseResponseBody: true,
979
+ });
980
+ }
981
+ async addPullRequestThread(workspace, project, number, body) {
982
+ return await this.request({
983
+ method: 'POST',
984
+ path: `${this.pullsPath(workspace, project, number)}/threads`,
985
+ body,
986
+ parseResponseBody: true,
987
+ });
988
+ }
989
+ async addPullRequestThreadComment(workspace, project, number, threadId, comment) {
990
+ return await this.request({
991
+ method: 'POST',
992
+ path: `${this.pullsPath(workspace, project, number)}/threads/${encodeURIComponent(threadId)}/comments`,
993
+ body: { comment },
994
+ parseResponseBody: true,
995
+ });
996
+ }
997
+ async updatePullRequestThread(workspace, project, number, threadId, body) {
998
+ return await this.request({
999
+ method: 'PATCH',
1000
+ path: `${this.pullsPath(workspace, project, number)}/threads/${encodeURIComponent(threadId)}`,
1001
+ body,
1002
+ parseResponseBody: true,
1003
+ });
1004
+ }
815
1005
  // Environment methods
816
1006
  async getEnvironments(workspace, project) {
817
1007
  const query = {};
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const logger_1 = __importDefault(require("./logger"));
7
+ class Autocomplete {
8
+ getCommandsMap(command) {
9
+ const commands = {};
10
+ command.commands.forEach((c) => {
11
+ const map = this.getCommandsMap(c);
12
+ const name = c.name() || 'bdy';
13
+ commands[name] = map;
14
+ c.aliases().forEach((a) => {
15
+ commands[a] = map;
16
+ });
17
+ });
18
+ command.options.forEach((o) => {
19
+ const name = `--${o.name()}`;
20
+ commands[name] = {};
21
+ });
22
+ let lastArg = commands;
23
+ command.registeredArguments.forEach((a) => {
24
+ logger_1.default.info(a);
25
+ let name;
26
+ if (a.required) {
27
+ name = `<${a.name()}>`;
28
+ }
29
+ else {
30
+ name = `[${a.name()}]`;
31
+ }
32
+ name = name.replaceAll(':', '꞉'); // U+A789 MODIFIER LETTER COLON - looks like : but doesn't trigger tabtab delimiter
33
+ lastArg[name] = {};
34
+ lastArg = lastArg[name];
35
+ });
36
+ return commands;
37
+ }
38
+ init(rootCommand) {
39
+ // COMP_LINE is set by all shells (bash natively, zsh/fish via tabtab scripts) when invoking completion
40
+ if (!process.env.COMP_LINE)
41
+ return false;
42
+ const tabtab = require('tabtab');
43
+ const env = tabtab.parseEnv(process.env);
44
+ if (!env.complete)
45
+ return false;
46
+ let map = {
47
+ bdy: this.getCommandsMap(rootCommand)
48
+ };
49
+ const s = (env.partial || '').trim().split(' ').filter((n) => !n.startsWith('--'));
50
+ const last = s[s.length - 1];
51
+ for (let i = 0; i < s.length - 1; i += 1) {
52
+ const name = s[i];
53
+ if (!map[name]) {
54
+ const arg = Object.keys(map).find((k) => k.startsWith('<') || k.startsWith('['));
55
+ if (arg) {
56
+ map = map[arg];
57
+ }
58
+ else {
59
+ return true;
60
+ }
61
+ }
62
+ else {
63
+ map = map[name];
64
+ }
65
+ }
66
+ if (map[last])
67
+ map = map[last];
68
+ else {
69
+ const arg = Object.keys(map).find((k) => k.startsWith('<') || k.startsWith('['));
70
+ if (arg)
71
+ map = map[arg];
72
+ }
73
+ tabtab.log(Object.keys(map));
74
+ return true;
75
+ }
76
+ async install() {
77
+ const tabtab = require('tabtab');
78
+ await tabtab.install({
79
+ name: process.title,
80
+ completer: process.title
81
+ });
82
+ }
83
+ async uninstall() {
84
+ const tabtab = require('tabtab');
85
+ await tabtab.uninstall({
86
+ name: process.title
87
+ });
88
+ }
89
+ }
90
+ exports.default = new Autocomplete();
@@ -13,6 +13,11 @@ var SemanticExitCode;
13
13
  class CliError extends Error {
14
14
  code;
15
15
  hint;
16
+ // Set by ApiClient for API errors: the HTTP status and the parsed JSON body,
17
+ // so a command can read fields the API sends next to `errors` (e.g. the
18
+ // current version in a 409 of a pull request verdict).
19
+ status;
20
+ body;
16
21
  constructor(code, message, hint = null, options) {
17
22
  super(message, options);
18
23
  this.code = code;
@@ -33,6 +33,7 @@ const register_1 = __importDefault(require("./command/register"));
33
33
  const mcp_1 = __importDefault(require("./command/mcp"));
34
34
  const discover_1 = __importDefault(require("./command/discover"));
35
35
  const context_1 = __importDefault(require("./command/context"));
36
+ const pr_1 = __importDefault(require("./command/pr"));
36
37
  const input_1 = __importDefault(require("./input"));
37
38
  const cliCommand_1 = __importDefault(require("./cliCommand"));
38
39
  const client_1 = __importDefault(require("./api/client"));
@@ -50,6 +51,7 @@ function cliIndex() {
50
51
  program.hook('preAction', pre_1.default);
51
52
  program.configureHelp({
52
53
  formatHelp: utils_1.formatHelp,
54
+ subcommandTerm: utils_1.subcommandTerm,
53
55
  });
54
56
  // root options must come before the subcommand, so -v here can't
55
57
  // shadow subcommand flags like `sandbox create -v <variable>`
@@ -76,6 +78,7 @@ function cliIndex() {
76
78
  program.addCommand(logout_1.default);
77
79
  program.addCommand(workspace_1.default);
78
80
  program.addCommand(project_1.default);
81
+ program.addCommand(pr_1.default);
79
82
  program.addCommand(yaml_1.default);
80
83
  program.addCommand(api_1.default);
81
84
  program.addCommand(mcp_1.default);
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.prepareDownloadDirectory = prepareDownloadDirectory;
7
+ exports.downloadArtifactVersionToDirectory = downloadArtifactVersionToDirectory;
8
+ const utils_1 = require("../../utils");
9
+ const texts_1 = require("../../texts");
10
+ const output_1 = __importDefault(require("../../output"));
11
+ const logger_1 = __importDefault(require("../../logger"));
12
+ const path_1 = require("path");
13
+ const fs_1 = __importDefault(require("fs"));
14
+ const promises_1 = __importDefault(require("node:stream/promises"));
15
+ /**
16
+ * Makes sure `path` is a directory the artifact can be unpacked into: created
17
+ * when missing, wiped with `replace`, and otherwise required to be empty
18
+ * unless `merge` is set. Returns the absolute path.
19
+ */
20
+ function prepareDownloadDirectory(path, options) {
21
+ const dirPath = (0, path_1.resolve)(path);
22
+ const exists = fs_1.default.existsSync(dirPath);
23
+ if (!exists) {
24
+ try {
25
+ fs_1.default.mkdirSync(dirPath, {
26
+ recursive: true,
27
+ });
28
+ }
29
+ catch (err) {
30
+ logger_1.default.error(err);
31
+ output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_MKDIR)(dirPath));
32
+ }
33
+ }
34
+ else if (options.replace) {
35
+ try {
36
+ fs_1.default.rmSync(dirPath, {
37
+ recursive: true,
38
+ force: true,
39
+ });
40
+ fs_1.default.mkdirSync(dirPath, {
41
+ recursive: true,
42
+ });
43
+ }
44
+ catch (err) {
45
+ logger_1.default.error(err);
46
+ output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_REPLACE)(dirPath));
47
+ }
48
+ }
49
+ try {
50
+ const stat = fs_1.default.statSync(dirPath);
51
+ if (!stat.isDirectory()) {
52
+ output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_IS_FILE)(dirPath));
53
+ }
54
+ }
55
+ catch (err) {
56
+ logger_1.default.error(err);
57
+ output_1.default.exitError(texts_1.ERR_SWW);
58
+ }
59
+ let empty = true;
60
+ try {
61
+ const entries = fs_1.default.readdirSync(dirPath);
62
+ empty = !entries.length;
63
+ }
64
+ catch (err) {
65
+ logger_1.default.error(err);
66
+ output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_READDIR)(dirPath));
67
+ }
68
+ if (!empty && !options.merge) {
69
+ output_1.default.exitError((0, texts_1.ERR_ARTIFACT_DOWNLOAD_NOT_EMPTY_DIR)(dirPath));
70
+ }
71
+ return dirPath;
72
+ }
73
+ // Returns the number of files unpacked.
74
+ async function downloadArtifactVersionToDirectory(client, workspace, artifactId, versionId, dirPath, quiet = false) {
75
+ const { v4 } = require('uuid');
76
+ const ArchiverExtract = require('../../unzipper').default;
77
+ const { UNZIPPER_FORMAT } = require('../../unzipper');
78
+ const zipPath = (0, path_1.join)((0, utils_1.getHomeDirectory)(), `${v4()}.zip`);
79
+ const clearZip = () => {
80
+ try {
81
+ fs_1.default.rmSync(zipPath);
82
+ }
83
+ catch {
84
+ // do nothing
85
+ }
86
+ };
87
+ // Progress rewrites the previous line, which only works on a terminal; a
88
+ // piped stdout would otherwise get one line per extracted file.
89
+ const say = output_1.default.progress(quiet || !output_1.default.isStdOutTTY());
90
+ say(texts_1.TXT_ARTIFACT_DOWNLOADING_ZIP);
91
+ const body = await client.downloadArtifactVersion(workspace, artifactId, versionId);
92
+ let count = 0;
93
+ try {
94
+ await promises_1.default.pipeline(body, fs_1.default.createWriteStream(zipPath));
95
+ say(texts_1.TXT_ARTIFACT_DOWNLOADED_ZIP, true, true);
96
+ say(texts_1.TXT_ARTIFACT_UNZIPPING);
97
+ await ArchiverExtract.extract(UNZIPPER_FORMAT.ZIP, zipPath, dirPath, async () => {
98
+ count += 1;
99
+ say((0, texts_1.TXT_ARTIFACT_UNZIPPING_COUNT)(count), true, true);
100
+ });
101
+ clearZip();
102
+ say(texts_1.TXT_ARTIFACT_UNZIPPED, true, true);
103
+ }
104
+ catch (err) {
105
+ logger_1.default.error(err);
106
+ clearZip();
107
+ output_1.default.exitError(texts_1.ERR_SWW);
108
+ }
109
+ return count;
110
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const autocomplete_1 = __importDefault(require("../../autocomplete"));
8
+ const texts_1 = require("../../texts");
9
+ const output_1 = __importDefault(require("../../output"));
10
+ const commandAutocompleteInstall = (0, utils_1.newCommand)('install', texts_1.DESC_COMMAND_AUTOCOMPLETE_INSTALL);
11
+ commandAutocompleteInstall.alias('i');
12
+ commandAutocompleteInstall.action(async () => {
13
+ await autocomplete_1.default.install();
14
+ output_1.default.exitSuccess(texts_1.TXT_AUTOCOMPLETE_INSTALLED);
15
+ });
16
+ exports.default = commandAutocompleteInstall;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../../utils");
7
+ const autocomplete_1 = __importDefault(require("../../autocomplete"));
8
+ const texts_1 = require("../../texts");
9
+ const output_1 = __importDefault(require("../../output"));
10
+ const commandAutocompleteUninstall = (0, utils_1.newCommand)('uninstall', texts_1.DESC_COMMAND_AUTOCOMPLETE_UNINSTALL);
11
+ commandAutocompleteUninstall.alias('u');
12
+ commandAutocompleteUninstall.action(async () => {
13
+ await autocomplete_1.default.uninstall();
14
+ output_1.default.exitSuccess(texts_1.TXT_AUTOCOMPLETE_UNINSTALLED);
15
+ });
16
+ exports.default = commandAutocompleteUninstall;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = require("../utils");
7
+ const install_1 = __importDefault(require("./autocomplete/install"));
8
+ const uninstall_1 = __importDefault(require("./autocomplete/uninstall"));
9
+ const texts_1 = require("../texts");
10
+ const commandAutocomplete = (0, utils_1.newCommand)('autocomplete', texts_1.DESC_COMMAND_AUTOCOMPLETE);
11
+ commandAutocomplete.alias('ac');
12
+ commandAutocomplete.addCommand(install_1.default);
13
+ commandAutocomplete.addCommand(uninstall_1.default);
14
+ exports.default = commandAutocomplete;