@specset/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/dist/main.js CHANGED
@@ -118,17 +118,17 @@ var require_visit = __commonJS({
118
118
  visit.BREAK = BREAK;
119
119
  visit.SKIP = SKIP;
120
120
  visit.REMOVE = REMOVE;
121
- function visit_(key, node, visitor, path6) {
122
- const ctrl = callVisitor(key, node, visitor, path6);
121
+ function visit_(key, node, visitor, path10) {
122
+ const ctrl = callVisitor(key, node, visitor, path10);
123
123
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
124
- replaceNode(key, path6, ctrl);
125
- return visit_(key, ctrl, visitor, path6);
124
+ replaceNode(key, path10, ctrl);
125
+ return visit_(key, ctrl, visitor, path10);
126
126
  }
127
127
  if (typeof ctrl !== "symbol") {
128
128
  if (identity.isCollection(node)) {
129
- path6 = Object.freeze(path6.concat(node));
129
+ path10 = Object.freeze(path10.concat(node));
130
130
  for (let i2 = 0; i2 < node.items.length; ++i2) {
131
- const ci = visit_(i2, node.items[i2], visitor, path6);
131
+ const ci = visit_(i2, node.items[i2], visitor, path10);
132
132
  if (typeof ci === "number")
133
133
  i2 = ci - 1;
134
134
  else if (ci === BREAK)
@@ -139,13 +139,13 @@ var require_visit = __commonJS({
139
139
  }
140
140
  }
141
141
  } else if (identity.isPair(node)) {
142
- path6 = Object.freeze(path6.concat(node));
143
- const ck = visit_("key", node.key, visitor, path6);
142
+ path10 = Object.freeze(path10.concat(node));
143
+ const ck = visit_("key", node.key, visitor, path10);
144
144
  if (ck === BREAK)
145
145
  return BREAK;
146
146
  else if (ck === REMOVE)
147
147
  node.key = null;
148
- const cv = visit_("value", node.value, visitor, path6);
148
+ const cv = visit_("value", node.value, visitor, path10);
149
149
  if (cv === BREAK)
150
150
  return BREAK;
151
151
  else if (cv === REMOVE)
@@ -166,17 +166,17 @@ var require_visit = __commonJS({
166
166
  visitAsync.BREAK = BREAK;
167
167
  visitAsync.SKIP = SKIP;
168
168
  visitAsync.REMOVE = REMOVE;
169
- async function visitAsync_(key, node, visitor, path6) {
170
- const ctrl = await callVisitor(key, node, visitor, path6);
169
+ async function visitAsync_(key, node, visitor, path10) {
170
+ const ctrl = await callVisitor(key, node, visitor, path10);
171
171
  if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
172
- replaceNode(key, path6, ctrl);
173
- return visitAsync_(key, ctrl, visitor, path6);
172
+ replaceNode(key, path10, ctrl);
173
+ return visitAsync_(key, ctrl, visitor, path10);
174
174
  }
175
175
  if (typeof ctrl !== "symbol") {
176
176
  if (identity.isCollection(node)) {
177
- path6 = Object.freeze(path6.concat(node));
177
+ path10 = Object.freeze(path10.concat(node));
178
178
  for (let i2 = 0; i2 < node.items.length; ++i2) {
179
- const ci = await visitAsync_(i2, node.items[i2], visitor, path6);
179
+ const ci = await visitAsync_(i2, node.items[i2], visitor, path10);
180
180
  if (typeof ci === "number")
181
181
  i2 = ci - 1;
182
182
  else if (ci === BREAK)
@@ -187,13 +187,13 @@ var require_visit = __commonJS({
187
187
  }
188
188
  }
189
189
  } else if (identity.isPair(node)) {
190
- path6 = Object.freeze(path6.concat(node));
191
- const ck = await visitAsync_("key", node.key, visitor, path6);
190
+ path10 = Object.freeze(path10.concat(node));
191
+ const ck = await visitAsync_("key", node.key, visitor, path10);
192
192
  if (ck === BREAK)
193
193
  return BREAK;
194
194
  else if (ck === REMOVE)
195
195
  node.key = null;
196
- const cv = await visitAsync_("value", node.value, visitor, path6);
196
+ const cv = await visitAsync_("value", node.value, visitor, path10);
197
197
  if (cv === BREAK)
198
198
  return BREAK;
199
199
  else if (cv === REMOVE)
@@ -220,23 +220,23 @@ var require_visit = __commonJS({
220
220
  }
221
221
  return visitor;
222
222
  }
223
- function callVisitor(key, node, visitor, path6) {
223
+ function callVisitor(key, node, visitor, path10) {
224
224
  if (typeof visitor === "function")
225
- return visitor(key, node, path6);
225
+ return visitor(key, node, path10);
226
226
  if (identity.isMap(node))
227
- return visitor.Map?.(key, node, path6);
227
+ return visitor.Map?.(key, node, path10);
228
228
  if (identity.isSeq(node))
229
- return visitor.Seq?.(key, node, path6);
229
+ return visitor.Seq?.(key, node, path10);
230
230
  if (identity.isPair(node))
231
- return visitor.Pair?.(key, node, path6);
231
+ return visitor.Pair?.(key, node, path10);
232
232
  if (identity.isScalar(node))
233
- return visitor.Scalar?.(key, node, path6);
233
+ return visitor.Scalar?.(key, node, path10);
234
234
  if (identity.isAlias(node))
235
- return visitor.Alias?.(key, node, path6);
235
+ return visitor.Alias?.(key, node, path10);
236
236
  return void 0;
237
237
  }
238
- function replaceNode(key, path6, node) {
239
- const parent = path6[path6.length - 1];
238
+ function replaceNode(key, path10, node) {
239
+ const parent = path10[path10.length - 1];
240
240
  if (identity.isCollection(parent)) {
241
241
  parent.items[key] = node;
242
242
  } else if (identity.isPair(parent)) {
@@ -844,10 +844,10 @@ var require_Collection = __commonJS({
844
844
  var createNode = require_createNode();
845
845
  var identity = require_identity();
846
846
  var Node = require_Node();
847
- function collectionFromPath(schema, path6, value2) {
847
+ function collectionFromPath(schema, path10, value2) {
848
848
  let v = value2;
849
- for (let i2 = path6.length - 1; i2 >= 0; --i2) {
850
- const k = path6[i2];
849
+ for (let i2 = path10.length - 1; i2 >= 0; --i2) {
850
+ const k = path10[i2];
851
851
  if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
852
852
  const a3 = [];
853
853
  a3[k] = v;
@@ -866,7 +866,7 @@ var require_Collection = __commonJS({
866
866
  sourceObjects: /* @__PURE__ */ new Map()
867
867
  });
868
868
  }
869
- var isEmptyPath = (path6) => path6 == null || typeof path6 === "object" && !!path6[Symbol.iterator]().next().done;
869
+ var isEmptyPath = (path10) => path10 == null || typeof path10 === "object" && !!path10[Symbol.iterator]().next().done;
870
870
  var Collection = class extends Node.NodeBase {
871
871
  constructor(type2, schema) {
872
872
  super(type2);
@@ -896,11 +896,11 @@ var require_Collection = __commonJS({
896
896
  * be a Pair instance or a `{ key, value }` object, which may not have a key
897
897
  * that already exists in the map.
898
898
  */
899
- addIn(path6, value2) {
900
- if (isEmptyPath(path6))
899
+ addIn(path10, value2) {
900
+ if (isEmptyPath(path10))
901
901
  this.add(value2);
902
902
  else {
903
- const [key, ...rest] = path6;
903
+ const [key, ...rest] = path10;
904
904
  const node = this.get(key, true);
905
905
  if (identity.isCollection(node))
906
906
  node.addIn(rest, value2);
@@ -914,8 +914,8 @@ var require_Collection = __commonJS({
914
914
  * Removes a value from the collection.
915
915
  * @returns `true` if the item was found and removed.
916
916
  */
917
- deleteIn(path6) {
918
- const [key, ...rest] = path6;
917
+ deleteIn(path10) {
918
+ const [key, ...rest] = path10;
919
919
  if (rest.length === 0)
920
920
  return this.delete(key);
921
921
  const node = this.get(key, true);
@@ -929,8 +929,8 @@ var require_Collection = __commonJS({
929
929
  * scalar values from their surrounding node; to disable set `keepScalar` to
930
930
  * `true` (collections are always returned intact).
931
931
  */
932
- getIn(path6, keepScalar) {
933
- const [key, ...rest] = path6;
932
+ getIn(path10, keepScalar) {
933
+ const [key, ...rest] = path10;
934
934
  const node = this.get(key, true);
935
935
  if (rest.length === 0)
936
936
  return !keepScalar && identity.isScalar(node) ? node.value : node;
@@ -948,8 +948,8 @@ var require_Collection = __commonJS({
948
948
  /**
949
949
  * Checks if the collection includes a value with the key `key`.
950
950
  */
951
- hasIn(path6) {
952
- const [key, ...rest] = path6;
951
+ hasIn(path10) {
952
+ const [key, ...rest] = path10;
953
953
  if (rest.length === 0)
954
954
  return this.has(key);
955
955
  const node = this.get(key, true);
@@ -959,8 +959,8 @@ var require_Collection = __commonJS({
959
959
  * Sets a value in this collection. For `!!set`, `value` needs to be a
960
960
  * boolean to add/remove the item from the set.
961
961
  */
962
- setIn(path6, value2) {
963
- const [key, ...rest] = path6;
962
+ setIn(path10, value2) {
963
+ const [key, ...rest] = path10;
964
964
  if (rest.length === 0) {
965
965
  this.set(key, value2);
966
966
  } else {
@@ -3472,9 +3472,9 @@ var require_Document = __commonJS({
3472
3472
  this.contents.add(value2);
3473
3473
  }
3474
3474
  /** Adds a value to the document. */
3475
- addIn(path6, value2) {
3475
+ addIn(path10, value2) {
3476
3476
  if (assertCollection(this.contents))
3477
- this.contents.addIn(path6, value2);
3477
+ this.contents.addIn(path10, value2);
3478
3478
  }
3479
3479
  /**
3480
3480
  * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
@@ -3549,14 +3549,14 @@ var require_Document = __commonJS({
3549
3549
  * Removes a value from the document.
3550
3550
  * @returns `true` if the item was found and removed.
3551
3551
  */
3552
- deleteIn(path6) {
3553
- if (Collection.isEmptyPath(path6)) {
3552
+ deleteIn(path10) {
3553
+ if (Collection.isEmptyPath(path10)) {
3554
3554
  if (this.contents == null)
3555
3555
  return false;
3556
3556
  this.contents = null;
3557
3557
  return true;
3558
3558
  }
3559
- return assertCollection(this.contents) ? this.contents.deleteIn(path6) : false;
3559
+ return assertCollection(this.contents) ? this.contents.deleteIn(path10) : false;
3560
3560
  }
3561
3561
  /**
3562
3562
  * Returns item at `key`, or `undefined` if not found. By default unwraps
@@ -3571,10 +3571,10 @@ var require_Document = __commonJS({
3571
3571
  * scalar values from their surrounding node; to disable set `keepScalar` to
3572
3572
  * `true` (collections are always returned intact).
3573
3573
  */
3574
- getIn(path6, keepScalar) {
3575
- if (Collection.isEmptyPath(path6))
3574
+ getIn(path10, keepScalar) {
3575
+ if (Collection.isEmptyPath(path10))
3576
3576
  return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
3577
- return identity.isCollection(this.contents) ? this.contents.getIn(path6, keepScalar) : void 0;
3577
+ return identity.isCollection(this.contents) ? this.contents.getIn(path10, keepScalar) : void 0;
3578
3578
  }
3579
3579
  /**
3580
3580
  * Checks if the document includes a value with the key `key`.
@@ -3585,10 +3585,10 @@ var require_Document = __commonJS({
3585
3585
  /**
3586
3586
  * Checks if the document includes a value at `path`.
3587
3587
  */
3588
- hasIn(path6) {
3589
- if (Collection.isEmptyPath(path6))
3588
+ hasIn(path10) {
3589
+ if (Collection.isEmptyPath(path10))
3590
3590
  return this.contents !== void 0;
3591
- return identity.isCollection(this.contents) ? this.contents.hasIn(path6) : false;
3591
+ return identity.isCollection(this.contents) ? this.contents.hasIn(path10) : false;
3592
3592
  }
3593
3593
  /**
3594
3594
  * Sets a value in this document. For `!!set`, `value` needs to be a
@@ -3605,13 +3605,13 @@ var require_Document = __commonJS({
3605
3605
  * Sets a value in this document. For `!!set`, `value` needs to be a
3606
3606
  * boolean to add/remove the item from the set.
3607
3607
  */
3608
- setIn(path6, value2) {
3609
- if (Collection.isEmptyPath(path6)) {
3608
+ setIn(path10, value2) {
3609
+ if (Collection.isEmptyPath(path10)) {
3610
3610
  this.contents = value2;
3611
3611
  } else if (this.contents == null) {
3612
- this.contents = Collection.collectionFromPath(this.schema, Array.from(path6), value2);
3612
+ this.contents = Collection.collectionFromPath(this.schema, Array.from(path10), value2);
3613
3613
  } else if (assertCollection(this.contents)) {
3614
- this.contents.setIn(path6, value2);
3614
+ this.contents.setIn(path10, value2);
3615
3615
  }
3616
3616
  }
3617
3617
  /**
@@ -5568,9 +5568,9 @@ var require_cst_visit = __commonJS({
5568
5568
  visit.BREAK = BREAK;
5569
5569
  visit.SKIP = SKIP;
5570
5570
  visit.REMOVE = REMOVE;
5571
- visit.itemAtPath = (cst, path6) => {
5571
+ visit.itemAtPath = (cst, path10) => {
5572
5572
  let item = cst;
5573
- for (const [field, index] of path6) {
5573
+ for (const [field, index] of path10) {
5574
5574
  const tok = item?.[field];
5575
5575
  if (tok && "items" in tok) {
5576
5576
  item = tok.items[index];
@@ -5579,23 +5579,23 @@ var require_cst_visit = __commonJS({
5579
5579
  }
5580
5580
  return item;
5581
5581
  };
5582
- visit.parentCollection = (cst, path6) => {
5583
- const parent = visit.itemAtPath(cst, path6.slice(0, -1));
5584
- const field = path6[path6.length - 1][0];
5582
+ visit.parentCollection = (cst, path10) => {
5583
+ const parent = visit.itemAtPath(cst, path10.slice(0, -1));
5584
+ const field = path10[path10.length - 1][0];
5585
5585
  const coll = parent?.[field];
5586
5586
  if (coll && "items" in coll)
5587
5587
  return coll;
5588
5588
  throw new Error("Parent collection not found");
5589
5589
  };
5590
- function _visit(path6, item, visitor) {
5591
- let ctrl = visitor(item, path6);
5590
+ function _visit(path10, item, visitor) {
5591
+ let ctrl = visitor(item, path10);
5592
5592
  if (typeof ctrl === "symbol")
5593
5593
  return ctrl;
5594
5594
  for (const field of ["key", "value"]) {
5595
5595
  const token = item[field];
5596
5596
  if (token && "items" in token) {
5597
5597
  for (let i2 = 0; i2 < token.items.length; ++i2) {
5598
- const ci = _visit(Object.freeze(path6.concat([[field, i2]])), token.items[i2], visitor);
5598
+ const ci = _visit(Object.freeze(path10.concat([[field, i2]])), token.items[i2], visitor);
5599
5599
  if (typeof ci === "number")
5600
5600
  i2 = ci - 1;
5601
5601
  else if (ci === BREAK)
@@ -5606,10 +5606,10 @@ var require_cst_visit = __commonJS({
5606
5606
  }
5607
5607
  }
5608
5608
  if (typeof ctrl === "function" && field === "key")
5609
- ctrl = ctrl(item, path6);
5609
+ ctrl = ctrl(item, path10);
5610
5610
  }
5611
5611
  }
5612
- return typeof ctrl === "function" ? ctrl(item, path6) : ctrl;
5612
+ return typeof ctrl === "function" ? ctrl(item, path10) : ctrl;
5613
5613
  }
5614
5614
  exports.visit = visit;
5615
5615
  }
@@ -6894,14 +6894,14 @@ var require_parser = __commonJS({
6894
6894
  case "scalar":
6895
6895
  case "single-quoted-scalar":
6896
6896
  case "double-quoted-scalar": {
6897
- const fs3 = this.flowScalar(this.type);
6897
+ const fs4 = this.flowScalar(this.type);
6898
6898
  if (atNextItem || it.value) {
6899
- map.items.push({ start, key: fs3, sep: [] });
6899
+ map.items.push({ start, key: fs4, sep: [] });
6900
6900
  this.onKeyLine = true;
6901
6901
  } else if (it.sep) {
6902
- this.stack.push(fs3);
6902
+ this.stack.push(fs4);
6903
6903
  } else {
6904
- Object.assign(it, { key: fs3, sep: [] });
6904
+ Object.assign(it, { key: fs4, sep: [] });
6905
6905
  this.onKeyLine = true;
6906
6906
  }
6907
6907
  return;
@@ -7029,13 +7029,13 @@ var require_parser = __commonJS({
7029
7029
  case "scalar":
7030
7030
  case "single-quoted-scalar":
7031
7031
  case "double-quoted-scalar": {
7032
- const fs3 = this.flowScalar(this.type);
7032
+ const fs4 = this.flowScalar(this.type);
7033
7033
  if (!it || it.value)
7034
- fc.items.push({ start: [], key: fs3, sep: [] });
7034
+ fc.items.push({ start: [], key: fs4, sep: [] });
7035
7035
  else if (it.sep)
7036
- this.stack.push(fs3);
7036
+ this.stack.push(fs4);
7037
7037
  else
7038
- Object.assign(it, { key: fs3, sep: [] });
7038
+ Object.assign(it, { key: fs4, sep: [] });
7039
7039
  return;
7040
7040
  }
7041
7041
  case "flow-map-end":
@@ -7582,10 +7582,10 @@ var require_GraphQLError = __commonJS({
7582
7582
  */
7583
7583
  constructor(message, ...rawArgs) {
7584
7584
  var _this$nodes, _nodeLocations$, _ref;
7585
- const { nodes, source, positions, path: path6, originalError, extensions } = toNormalizedOptions(rawArgs);
7585
+ const { nodes, source, positions, path: path10, originalError, extensions } = toNormalizedOptions(rawArgs);
7586
7586
  super(message);
7587
7587
  this.name = "GraphQLError";
7588
- this.path = path6 !== null && path6 !== void 0 ? path6 : void 0;
7588
+ this.path = path10 !== null && path10 !== void 0 ? path10 : void 0;
7589
7589
  this.originalError = originalError !== null && originalError !== void 0 ? originalError : void 0;
7590
7590
  this.nodes = undefinedIfEmpty(
7591
7591
  Array.isArray(nodes) ? nodes : nodes ? [nodes] : void 0
@@ -10805,14 +10805,14 @@ var require_visitor = __commonJS({
10805
10805
  let node = root2;
10806
10806
  let key = void 0;
10807
10807
  let parent = void 0;
10808
- const path6 = [];
10808
+ const path10 = [];
10809
10809
  const ancestors = [];
10810
10810
  do {
10811
10811
  index++;
10812
10812
  const isLeaving = index === keys.length;
10813
10813
  const isEdited = isLeaving && edits.length !== 0;
10814
10814
  if (isLeaving) {
10815
- key = ancestors.length === 0 ? void 0 : path6[path6.length - 1];
10815
+ key = ancestors.length === 0 ? void 0 : path10[path10.length - 1];
10816
10816
  node = parent;
10817
10817
  parent = ancestors.pop();
10818
10818
  if (isEdited) {
@@ -10846,7 +10846,7 @@ var require_visitor = __commonJS({
10846
10846
  if (node === null || node === void 0) {
10847
10847
  continue;
10848
10848
  }
10849
- path6.push(key);
10849
+ path10.push(key);
10850
10850
  }
10851
10851
  let result;
10852
10852
  if (!Array.isArray(node)) {
@@ -10856,13 +10856,13 @@ var require_visitor = __commonJS({
10856
10856
  `Invalid AST Node: ${(0, _inspect.inspect)(node)}.`
10857
10857
  );
10858
10858
  const visitFn = isLeaving ? (_enterLeaveMap$get = enterLeaveMap.get(node.kind)) === null || _enterLeaveMap$get === void 0 ? void 0 : _enterLeaveMap$get.leave : (_enterLeaveMap$get2 = enterLeaveMap.get(node.kind)) === null || _enterLeaveMap$get2 === void 0 ? void 0 : _enterLeaveMap$get2.enter;
10859
- result = visitFn === null || visitFn === void 0 ? void 0 : visitFn.call(visitor, node, key, parent, path6, ancestors);
10859
+ result = visitFn === null || visitFn === void 0 ? void 0 : visitFn.call(visitor, node, key, parent, path10, ancestors);
10860
10860
  if (result === BREAK) {
10861
10861
  break;
10862
10862
  }
10863
10863
  if (result === false) {
10864
10864
  if (!isLeaving) {
10865
- path6.pop();
10865
+ path10.pop();
10866
10866
  continue;
10867
10867
  }
10868
10868
  } else if (result !== void 0) {
@@ -10871,7 +10871,7 @@ var require_visitor = __commonJS({
10871
10871
  if ((0, _ast.isNode)(result)) {
10872
10872
  node = result;
10873
10873
  } else {
10874
- path6.pop();
10874
+ path10.pop();
10875
10875
  continue;
10876
10876
  }
10877
10877
  }
@@ -10881,7 +10881,7 @@ var require_visitor = __commonJS({
10881
10881
  edits.push([key, node]);
10882
10882
  }
10883
10883
  if (isLeaving) {
10884
- path6.pop();
10884
+ path10.pop();
10885
10885
  } else {
10886
10886
  var _node$kind;
10887
10887
  stack = {
@@ -16152,8 +16152,8 @@ var require_printPathArray = __commonJS({
16152
16152
  value: true
16153
16153
  });
16154
16154
  exports.printPathArray = printPathArray;
16155
- function printPathArray(path6) {
16156
- return path6.map(
16155
+ function printPathArray(path10) {
16156
+ return path10.map(
16157
16157
  (key) => typeof key === "number" ? "[" + key.toString() + "]" : "." + key
16158
16158
  ).join("");
16159
16159
  }
@@ -16176,9 +16176,9 @@ var require_Path = __commonJS({
16176
16176
  typename
16177
16177
  };
16178
16178
  }
16179
- function pathToArray(path6) {
16179
+ function pathToArray(path10) {
16180
16180
  const flattened = [];
16181
- let curr = path6;
16181
+ let curr = path10;
16182
16182
  while (curr) {
16183
16183
  flattened.push(curr.key);
16184
16184
  curr = curr.prev;
@@ -16209,21 +16209,21 @@ var require_coerceInputValue = __commonJS({
16209
16209
  function coerceInputValue(inputValue, type2, onError = defaultOnError) {
16210
16210
  return coerceInputValueImpl(inputValue, type2, onError, void 0);
16211
16211
  }
16212
- function defaultOnError(path6, invalidValue, error3) {
16212
+ function defaultOnError(path10, invalidValue, error3) {
16213
16213
  let errorPrefix = "Invalid value " + (0, _inspect.inspect)(invalidValue);
16214
- if (path6.length > 0) {
16215
- errorPrefix += ` at "value${(0, _printPathArray.printPathArray)(path6)}"`;
16214
+ if (path10.length > 0) {
16215
+ errorPrefix += ` at "value${(0, _printPathArray.printPathArray)(path10)}"`;
16216
16216
  }
16217
16217
  error3.message = errorPrefix + ": " + error3.message;
16218
16218
  throw error3;
16219
16219
  }
16220
- function coerceInputValueImpl(inputValue, type2, onError, path6) {
16220
+ function coerceInputValueImpl(inputValue, type2, onError, path10) {
16221
16221
  if ((0, _definition.isNonNullType)(type2)) {
16222
16222
  if (inputValue != null) {
16223
- return coerceInputValueImpl(inputValue, type2.ofType, onError, path6);
16223
+ return coerceInputValueImpl(inputValue, type2.ofType, onError, path10);
16224
16224
  }
16225
16225
  onError(
16226
- (0, _Path.pathToArray)(path6),
16226
+ (0, _Path.pathToArray)(path10),
16227
16227
  inputValue,
16228
16228
  new _GraphQLError.GraphQLError(
16229
16229
  `Expected non-nullable type "${(0, _inspect.inspect)(
@@ -16240,16 +16240,16 @@ var require_coerceInputValue = __commonJS({
16240
16240
  const itemType = type2.ofType;
16241
16241
  if ((0, _isIterableObject.isIterableObject)(inputValue)) {
16242
16242
  return Array.from(inputValue, (itemValue, index) => {
16243
- const itemPath = (0, _Path.addPath)(path6, index, void 0);
16243
+ const itemPath = (0, _Path.addPath)(path10, index, void 0);
16244
16244
  return coerceInputValueImpl(itemValue, itemType, onError, itemPath);
16245
16245
  });
16246
16246
  }
16247
- return [coerceInputValueImpl(inputValue, itemType, onError, path6)];
16247
+ return [coerceInputValueImpl(inputValue, itemType, onError, path10)];
16248
16248
  }
16249
16249
  if ((0, _definition.isInputObjectType)(type2)) {
16250
16250
  if (!(0, _isObjectLike.isObjectLike)(inputValue) || Array.isArray(inputValue)) {
16251
16251
  onError(
16252
- (0, _Path.pathToArray)(path6),
16252
+ (0, _Path.pathToArray)(path10),
16253
16253
  inputValue,
16254
16254
  new _GraphQLError.GraphQLError(
16255
16255
  `Expected type "${type2.name}" to be an object.`
@@ -16267,7 +16267,7 @@ var require_coerceInputValue = __commonJS({
16267
16267
  } else if ((0, _definition.isNonNullType)(field.type)) {
16268
16268
  const typeStr = (0, _inspect.inspect)(field.type);
16269
16269
  onError(
16270
- (0, _Path.pathToArray)(path6),
16270
+ (0, _Path.pathToArray)(path10),
16271
16271
  inputValue,
16272
16272
  new _GraphQLError.GraphQLError(
16273
16273
  `Field "${field.name}" of required type "${typeStr}" was not provided.`
@@ -16280,7 +16280,7 @@ var require_coerceInputValue = __commonJS({
16280
16280
  fieldValue,
16281
16281
  field.type,
16282
16282
  onError,
16283
- (0, _Path.addPath)(path6, field.name, type2.name)
16283
+ (0, _Path.addPath)(path10, field.name, type2.name)
16284
16284
  );
16285
16285
  }
16286
16286
  for (const fieldName of Object.keys(inputValue)) {
@@ -16290,7 +16290,7 @@ var require_coerceInputValue = __commonJS({
16290
16290
  Object.keys(type2.getFields())
16291
16291
  );
16292
16292
  onError(
16293
- (0, _Path.pathToArray)(path6),
16293
+ (0, _Path.pathToArray)(path10),
16294
16294
  inputValue,
16295
16295
  new _GraphQLError.GraphQLError(
16296
16296
  `Field "${fieldName}" is not defined by type "${type2.name}".` + (0, _didYouMean.didYouMean)(suggestions)
@@ -16302,7 +16302,7 @@ var require_coerceInputValue = __commonJS({
16302
16302
  const keys = Object.keys(coercedValue);
16303
16303
  if (keys.length !== 1) {
16304
16304
  onError(
16305
- (0, _Path.pathToArray)(path6),
16305
+ (0, _Path.pathToArray)(path10),
16306
16306
  inputValue,
16307
16307
  new _GraphQLError.GraphQLError(
16308
16308
  `Exactly one key must be specified for OneOf type "${type2.name}".`
@@ -16313,7 +16313,7 @@ var require_coerceInputValue = __commonJS({
16313
16313
  const value2 = coercedValue[key];
16314
16314
  if (value2 === null) {
16315
16315
  onError(
16316
- (0, _Path.pathToArray)(path6).concat(key),
16316
+ (0, _Path.pathToArray)(path10).concat(key),
16317
16317
  value2,
16318
16318
  new _GraphQLError.GraphQLError(`Field "${key}" must be non-null.`)
16319
16319
  );
@@ -16327,10 +16327,10 @@ var require_coerceInputValue = __commonJS({
16327
16327
  parseResult = type2.parseValue(inputValue);
16328
16328
  } catch (error3) {
16329
16329
  if (error3 instanceof _GraphQLError.GraphQLError) {
16330
- onError((0, _Path.pathToArray)(path6), inputValue, error3);
16330
+ onError((0, _Path.pathToArray)(path10), inputValue, error3);
16331
16331
  } else {
16332
16332
  onError(
16333
- (0, _Path.pathToArray)(path6),
16333
+ (0, _Path.pathToArray)(path10),
16334
16334
  inputValue,
16335
16335
  new _GraphQLError.GraphQLError(
16336
16336
  `Expected type "${type2.name}". ` + error3.message,
@@ -16344,7 +16344,7 @@ var require_coerceInputValue = __commonJS({
16344
16344
  }
16345
16345
  if (parseResult === void 0) {
16346
16346
  onError(
16347
- (0, _Path.pathToArray)(path6),
16347
+ (0, _Path.pathToArray)(path10),
16348
16348
  inputValue,
16349
16349
  new _GraphQLError.GraphQLError(`Expected type "${type2.name}".`)
16350
16350
  );
@@ -16582,11 +16582,11 @@ var require_values = __commonJS({
16582
16582
  coercedValues[varName] = (0, _coerceInputValue.coerceInputValue)(
16583
16583
  value2,
16584
16584
  varType,
16585
- (path6, invalidValue, error3) => {
16585
+ (path10, invalidValue, error3) => {
16586
16586
  let prefix = `Variable "$${varName}" got invalid value ` + (0, _inspect.inspect)(invalidValue);
16587
- if (path6.length > 0) {
16587
+ if (path10.length > 0) {
16588
16588
  prefix += ` at "${varName}${(0, _printPathArray.printPathArray)(
16589
- path6
16589
+ path10
16590
16590
  )}"`;
16591
16591
  }
16592
16592
  onError(
@@ -18329,7 +18329,7 @@ var require_locatedError = __commonJS({
18329
18329
  exports.locatedError = locatedError;
18330
18330
  var _toError = require_toError();
18331
18331
  var _GraphQLError = require_GraphQLError();
18332
- function locatedError(rawOriginalError, nodes, path6) {
18332
+ function locatedError(rawOriginalError, nodes, path10) {
18333
18333
  var _nodes;
18334
18334
  const originalError = (0, _toError.toError)(rawOriginalError);
18335
18335
  if (isLocatedGraphQLError(originalError)) {
@@ -18339,7 +18339,7 @@ var require_locatedError = __commonJS({
18339
18339
  nodes: (_nodes = originalError.nodes) !== null && _nodes !== void 0 ? _nodes : nodes,
18340
18340
  source: originalError.source,
18341
18341
  positions: originalError.positions,
18342
- path: path6,
18342
+ path: path10,
18343
18343
  originalError
18344
18344
  });
18345
18345
  }
@@ -18535,27 +18535,27 @@ var require_execute = __commonJS({
18535
18535
  rootType,
18536
18536
  operation.selectionSet
18537
18537
  );
18538
- const path6 = void 0;
18538
+ const path10 = void 0;
18539
18539
  switch (operation.operation) {
18540
18540
  case _ast.OperationTypeNode.QUERY:
18541
- return executeFields(exeContext, rootType, rootValue, path6, rootFields);
18541
+ return executeFields(exeContext, rootType, rootValue, path10, rootFields);
18542
18542
  case _ast.OperationTypeNode.MUTATION:
18543
18543
  return executeFieldsSerially(
18544
18544
  exeContext,
18545
18545
  rootType,
18546
18546
  rootValue,
18547
- path6,
18547
+ path10,
18548
18548
  rootFields
18549
18549
  );
18550
18550
  case _ast.OperationTypeNode.SUBSCRIPTION:
18551
- return executeFields(exeContext, rootType, rootValue, path6, rootFields);
18551
+ return executeFields(exeContext, rootType, rootValue, path10, rootFields);
18552
18552
  }
18553
18553
  }
18554
- function executeFieldsSerially(exeContext, parentType, sourceValue, path6, fields) {
18554
+ function executeFieldsSerially(exeContext, parentType, sourceValue, path10, fields) {
18555
18555
  return (0, _promiseReduce.promiseReduce)(
18556
18556
  fields.entries(),
18557
18557
  (results, [responseName, fieldNodes]) => {
18558
- const fieldPath = (0, _Path.addPath)(path6, responseName, parentType.name);
18558
+ const fieldPath = (0, _Path.addPath)(path10, responseName, parentType.name);
18559
18559
  const result = executeField(
18560
18560
  exeContext,
18561
18561
  parentType,
@@ -18578,12 +18578,12 @@ var require_execute = __commonJS({
18578
18578
  /* @__PURE__ */ Object.create(null)
18579
18579
  );
18580
18580
  }
18581
- function executeFields(exeContext, parentType, sourceValue, path6, fields) {
18581
+ function executeFields(exeContext, parentType, sourceValue, path10, fields) {
18582
18582
  const results = /* @__PURE__ */ Object.create(null);
18583
18583
  let containsPromise = false;
18584
18584
  try {
18585
18585
  for (const [responseName, fieldNodes] of fields.entries()) {
18586
- const fieldPath = (0, _Path.addPath)(path6, responseName, parentType.name);
18586
+ const fieldPath = (0, _Path.addPath)(path10, responseName, parentType.name);
18587
18587
  const result = executeField(
18588
18588
  exeContext,
18589
18589
  parentType,
@@ -18611,7 +18611,7 @@ var require_execute = __commonJS({
18611
18611
  }
18612
18612
  return (0, _promiseForObject.promiseForObject)(results);
18613
18613
  }
18614
- function executeField(exeContext, parentType, source, fieldNodes, path6) {
18614
+ function executeField(exeContext, parentType, source, fieldNodes, path10) {
18615
18615
  var _fieldDef$resolve;
18616
18616
  const fieldDef = getFieldDef(exeContext.schema, parentType, fieldNodes[0]);
18617
18617
  if (!fieldDef) {
@@ -18624,7 +18624,7 @@ var require_execute = __commonJS({
18624
18624
  fieldDef,
18625
18625
  fieldNodes,
18626
18626
  parentType,
18627
- path6
18627
+ path10
18628
18628
  );
18629
18629
  try {
18630
18630
  const args = (0, _values.getArgumentValues)(
@@ -18637,7 +18637,7 @@ var require_execute = __commonJS({
18637
18637
  let completed;
18638
18638
  if ((0, _isPromise.isPromise)(result)) {
18639
18639
  completed = result.then(
18640
- (resolved) => completeValue(exeContext, returnType, fieldNodes, info, path6, resolved)
18640
+ (resolved) => completeValue(exeContext, returnType, fieldNodes, info, path10, resolved)
18641
18641
  );
18642
18642
  } else {
18643
18643
  completed = completeValue(
@@ -18645,7 +18645,7 @@ var require_execute = __commonJS({
18645
18645
  returnType,
18646
18646
  fieldNodes,
18647
18647
  info,
18648
- path6,
18648
+ path10,
18649
18649
  result
18650
18650
  );
18651
18651
  }
@@ -18654,7 +18654,7 @@ var require_execute = __commonJS({
18654
18654
  const error3 = (0, _locatedError.locatedError)(
18655
18655
  rawError,
18656
18656
  fieldNodes,
18657
- (0, _Path.pathToArray)(path6)
18657
+ (0, _Path.pathToArray)(path10)
18658
18658
  );
18659
18659
  return handleFieldError(error3, returnType, exeContext);
18660
18660
  });
@@ -18664,18 +18664,18 @@ var require_execute = __commonJS({
18664
18664
  const error3 = (0, _locatedError.locatedError)(
18665
18665
  rawError,
18666
18666
  fieldNodes,
18667
- (0, _Path.pathToArray)(path6)
18667
+ (0, _Path.pathToArray)(path10)
18668
18668
  );
18669
18669
  return handleFieldError(error3, returnType, exeContext);
18670
18670
  }
18671
18671
  }
18672
- function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path6) {
18672
+ function buildResolveInfo(exeContext, fieldDef, fieldNodes, parentType, path10) {
18673
18673
  return {
18674
18674
  fieldName: fieldDef.name,
18675
18675
  fieldNodes,
18676
18676
  returnType: fieldDef.type,
18677
18677
  parentType,
18678
- path: path6,
18678
+ path: path10,
18679
18679
  schema: exeContext.schema,
18680
18680
  fragments: exeContext.fragments,
18681
18681
  rootValue: exeContext.rootValue,
@@ -18690,7 +18690,7 @@ var require_execute = __commonJS({
18690
18690
  exeContext.errors.push(error3);
18691
18691
  return null;
18692
18692
  }
18693
- function completeValue(exeContext, returnType, fieldNodes, info, path6, result) {
18693
+ function completeValue(exeContext, returnType, fieldNodes, info, path10, result) {
18694
18694
  if (result instanceof Error) {
18695
18695
  throw result;
18696
18696
  }
@@ -18700,7 +18700,7 @@ var require_execute = __commonJS({
18700
18700
  returnType.ofType,
18701
18701
  fieldNodes,
18702
18702
  info,
18703
- path6,
18703
+ path10,
18704
18704
  result
18705
18705
  );
18706
18706
  if (completed === null) {
@@ -18719,7 +18719,7 @@ var require_execute = __commonJS({
18719
18719
  returnType,
18720
18720
  fieldNodes,
18721
18721
  info,
18722
- path6,
18722
+ path10,
18723
18723
  result
18724
18724
  );
18725
18725
  }
@@ -18732,7 +18732,7 @@ var require_execute = __commonJS({
18732
18732
  returnType,
18733
18733
  fieldNodes,
18734
18734
  info,
18735
- path6,
18735
+ path10,
18736
18736
  result
18737
18737
  );
18738
18738
  }
@@ -18742,7 +18742,7 @@ var require_execute = __commonJS({
18742
18742
  returnType,
18743
18743
  fieldNodes,
18744
18744
  info,
18745
- path6,
18745
+ path10,
18746
18746
  result
18747
18747
  );
18748
18748
  }
@@ -18751,7 +18751,7 @@ var require_execute = __commonJS({
18751
18751
  "Cannot complete value of unexpected output type: " + (0, _inspect.inspect)(returnType)
18752
18752
  );
18753
18753
  }
18754
- function completeListValue(exeContext, returnType, fieldNodes, info, path6, result) {
18754
+ function completeListValue(exeContext, returnType, fieldNodes, info, path10, result) {
18755
18755
  if (!(0, _isIterableObject.isIterableObject)(result)) {
18756
18756
  throw new _GraphQLError.GraphQLError(
18757
18757
  `Expected Iterable, but did not find one for field "${info.parentType.name}.${info.fieldName}".`
@@ -18760,7 +18760,7 @@ var require_execute = __commonJS({
18760
18760
  const itemType = returnType.ofType;
18761
18761
  let containsPromise = false;
18762
18762
  const completedResults = Array.from(result, (item, index) => {
18763
- const itemPath = (0, _Path.addPath)(path6, index, void 0);
18763
+ const itemPath = (0, _Path.addPath)(path10, index, void 0);
18764
18764
  try {
18765
18765
  let completedItem;
18766
18766
  if ((0, _isPromise.isPromise)(item)) {
@@ -18818,7 +18818,7 @@ var require_execute = __commonJS({
18818
18818
  }
18819
18819
  return serializedResult;
18820
18820
  }
18821
- function completeAbstractValue(exeContext, returnType, fieldNodes, info, path6, result) {
18821
+ function completeAbstractValue(exeContext, returnType, fieldNodes, info, path10, result) {
18822
18822
  var _returnType$resolveTy;
18823
18823
  const resolveTypeFn = (_returnType$resolveTy = returnType.resolveType) !== null && _returnType$resolveTy !== void 0 ? _returnType$resolveTy : exeContext.typeResolver;
18824
18824
  const contextValue = exeContext.contextValue;
@@ -18837,7 +18837,7 @@ var require_execute = __commonJS({
18837
18837
  ),
18838
18838
  fieldNodes,
18839
18839
  info,
18840
- path6,
18840
+ path10,
18841
18841
  result
18842
18842
  )
18843
18843
  );
@@ -18854,7 +18854,7 @@ var require_execute = __commonJS({
18854
18854
  ),
18855
18855
  fieldNodes,
18856
18856
  info,
18857
- path6,
18857
+ path10,
18858
18858
  result
18859
18859
  );
18860
18860
  }
@@ -18902,7 +18902,7 @@ var require_execute = __commonJS({
18902
18902
  }
18903
18903
  return runtimeType;
18904
18904
  }
18905
- function completeObjectValue(exeContext, returnType, fieldNodes, info, path6, result) {
18905
+ function completeObjectValue(exeContext, returnType, fieldNodes, info, path10, result) {
18906
18906
  const subFieldNodes = collectSubfields(exeContext, returnType, fieldNodes);
18907
18907
  if (returnType.isTypeOf) {
18908
18908
  const isTypeOf = returnType.isTypeOf(result, exeContext.contextValue, info);
@@ -18915,7 +18915,7 @@ var require_execute = __commonJS({
18915
18915
  exeContext,
18916
18916
  returnType,
18917
18917
  result,
18918
- path6,
18918
+ path10,
18919
18919
  subFieldNodes
18920
18920
  );
18921
18921
  });
@@ -18924,7 +18924,7 @@ var require_execute = __commonJS({
18924
18924
  throw invalidReturnTypeError(returnType, result, fieldNodes);
18925
18925
  }
18926
18926
  }
18927
- return executeFields(exeContext, returnType, result, path6, subFieldNodes);
18927
+ return executeFields(exeContext, returnType, result, path10, subFieldNodes);
18928
18928
  }
18929
18929
  function invalidReturnTypeError(returnType, result, fieldNodes) {
18930
18930
  return new _GraphQLError.GraphQLError(
@@ -19992,13 +19992,13 @@ var require_subscribe = __commonJS({
19992
19992
  }
19993
19993
  );
19994
19994
  }
19995
- const path6 = (0, _Path.addPath)(void 0, responseName, rootType.name);
19995
+ const path10 = (0, _Path.addPath)(void 0, responseName, rootType.name);
19996
19996
  const info = (0, _execute.buildResolveInfo)(
19997
19997
  exeContext,
19998
19998
  fieldDef,
19999
19999
  fieldNodes,
20000
20000
  rootType,
20001
- path6
20001
+ path10
20002
20002
  );
20003
20003
  try {
20004
20004
  var _fieldDef$subscribe;
@@ -20018,7 +20018,7 @@ var require_subscribe = __commonJS({
20018
20018
  throw (0, _locatedError.locatedError)(
20019
20019
  error3,
20020
20020
  fieldNodes,
20021
- (0, _Path.pathToArray)(path6)
20021
+ (0, _Path.pathToArray)(path10)
20022
20022
  );
20023
20023
  }
20024
20024
  }
@@ -27487,8 +27487,8 @@ var require_schemes = __commonJS({
27487
27487
  wsComponents.secure = void 0;
27488
27488
  }
27489
27489
  if (wsComponents.resourceName) {
27490
- const [path6, query] = wsComponents.resourceName.split("?");
27491
- wsComponents.path = path6 && path6 !== "/" ? path6 : void 0;
27490
+ const [path10, query] = wsComponents.resourceName.split("?");
27491
+ wsComponents.path = path10 && path10 !== "/" ? path10 : void 0;
27492
27492
  wsComponents.query = query;
27493
27493
  wsComponents.resourceName = void 0;
27494
27494
  }
@@ -30813,12 +30813,12 @@ var require_dist2 = __commonJS({
30813
30813
  throw new Error(`Unknown format "${name2}"`);
30814
30814
  return f;
30815
30815
  };
30816
- function addFormats(ajv, list, fs3, exportName) {
30816
+ function addFormats(ajv, list, fs4, exportName) {
30817
30817
  var _a;
30818
30818
  var _b;
30819
30819
  (_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
30820
30820
  for (const f of list)
30821
- ajv.addFormat(f, fs3[f]);
30821
+ ajv.addFormat(f, fs4[f]);
30822
30822
  }
30823
30823
  module.exports = exports = formatsPlugin;
30824
30824
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -36675,6 +36675,1141 @@ var status = buildCommand({
36675
36675
  }
36676
36676
  });
36677
36677
 
36678
+ // apps/cli/src/util/downloadCommand.ts
36679
+ import path5 from "node:path";
36680
+ async function resolveDownloadCli(config2, hostOverride) {
36681
+ const orgId = activeOrgId(config2, hostOverride);
36682
+ if (!orgId) {
36683
+ return new Error(
36684
+ "No active organization. Run `specset org use <slug>` first."
36685
+ );
36686
+ }
36687
+ const resolved = await resolveAuthorizedClient(config2, hostOverride);
36688
+ if (resolved instanceof Error) {
36689
+ return resolved;
36690
+ }
36691
+ const token = getHostConfig(
36692
+ config2,
36693
+ resolveActiveHost(config2, hostOverride)
36694
+ ).token;
36695
+ if (!token) {
36696
+ return new Error(`Not logged in to ${resolved.host}.`);
36697
+ }
36698
+ return { client: resolved.client, host: resolved.host, token, orgId };
36699
+ }
36700
+ function printOutcome(proc, json, outcome, cwd) {
36701
+ if (outcome.kind === "inventory") {
36702
+ const lines2 = outcome.items.map((item) => {
36703
+ const selector = item.index !== void 0 ? `--asset ${item.asset} --index ${item.index}` : `--asset ${item.asset}`;
36704
+ const availability = item.available ? "" : " (not available)";
36705
+ return ` ${selector.padEnd(28)} ${item.label}${availability}`;
36706
+ });
36707
+ printResult(
36708
+ proc,
36709
+ json,
36710
+ outcome,
36711
+ [`Assets for ${outcome.entity}:`, ...lines2].join("\n")
36712
+ );
36713
+ return;
36714
+ }
36715
+ const lines = outcome.files.map((file) => {
36716
+ const sizeMb = (file.bytes / (1024 * 1024)).toFixed(1);
36717
+ const relative = path5.relative(cwd, file.path) || file.path;
36718
+ return ` ${relative} (${sizeMb} MB)`;
36719
+ });
36720
+ printResult(
36721
+ proc,
36722
+ json,
36723
+ outcome,
36724
+ [
36725
+ `Saved ${outcome.files.length} file${outcome.files.length === 1 ? "" : "s"} for ${outcome.entity}`,
36726
+ ...lines
36727
+ ].join("\n")
36728
+ );
36729
+ }
36730
+
36731
+ // apps/cli/src/util/fileDownload.ts
36732
+ import path7 from "node:path";
36733
+
36734
+ // apps/cli/src/graphql/files.ts
36735
+ var documentDownloadDocument = graphql(`
36736
+ query Cli_documentDownload($id: ID!) {
36737
+ document(id: $id) {
36738
+ id
36739
+ title
36740
+ fileResource {
36741
+ id
36742
+ numPages
36743
+ targetFile {
36744
+ downloadUrl
36745
+ filename
36746
+ mimeType
36747
+ }
36748
+ }
36749
+ }
36750
+ }
36751
+ `);
36752
+ var fileResourceDownloadDocument = graphql(`
36753
+ query Cli_fileResourceDownload($id: ID!) {
36754
+ fileResource(id: $id) {
36755
+ id
36756
+ name
36757
+ numPages
36758
+ targetFile {
36759
+ downloadUrl
36760
+ filename
36761
+ mimeType
36762
+ }
36763
+ }
36764
+ }
36765
+ `);
36766
+ var specSectionDownloadDocument = graphql(`
36767
+ query Cli_specSectionDownload($id: ID!) {
36768
+ specSection(id: $id) {
36769
+ id
36770
+ sectionNumber
36771
+ title
36772
+ specSectionFiles {
36773
+ id
36774
+ archivedAt
36775
+ pages
36776
+ endPage
36777
+ fileResource {
36778
+ id
36779
+ targetFile {
36780
+ downloadUrl
36781
+ filename
36782
+ mimeType
36783
+ }
36784
+ }
36785
+ specFile {
36786
+ id
36787
+ title
36788
+ fileResource {
36789
+ id
36790
+ targetFile {
36791
+ downloadUrl
36792
+ filename
36793
+ mimeType
36794
+ }
36795
+ }
36796
+ }
36797
+ }
36798
+ }
36799
+ }
36800
+ `);
36801
+ var specSectionIdByNumberDocument = graphql(`
36802
+ query Cli_specSectionIdByNumber($projectId: ID!, $sectionNumber: String!) {
36803
+ specSectionByNumber(projectId: $projectId, sectionNumber: $sectionNumber) {
36804
+ id
36805
+ }
36806
+ }
36807
+ `);
36808
+ var submittalDownloadDocument = graphql(`
36809
+ query Cli_submittalDownload($id: ID!) {
36810
+ submittal(id: $id) {
36811
+ id
36812
+ formattedSubmittalNumber
36813
+ title
36814
+ revision
36815
+ compiledSubmittal {
36816
+ id
36817
+ targetFile {
36818
+ downloadUrl
36819
+ filename
36820
+ mimeType
36821
+ }
36822
+ }
36823
+ compiledCoverSheet {
36824
+ id
36825
+ targetFile {
36826
+ downloadUrl
36827
+ filename
36828
+ mimeType
36829
+ }
36830
+ }
36831
+ coverSheet {
36832
+ id
36833
+ targetFile {
36834
+ downloadUrl
36835
+ filename
36836
+ mimeType
36837
+ }
36838
+ }
36839
+ attachments {
36840
+ id
36841
+ order
36842
+ description
36843
+ type
36844
+ document {
36845
+ id
36846
+ title
36847
+ fileResource {
36848
+ id
36849
+ targetFile {
36850
+ downloadUrl
36851
+ filename
36852
+ mimeType
36853
+ }
36854
+ }
36855
+ }
36856
+ fileResource {
36857
+ id
36858
+ targetFile {
36859
+ downloadUrl
36860
+ filename
36861
+ mimeType
36862
+ }
36863
+ }
36864
+ }
36865
+ }
36866
+ }
36867
+ `);
36868
+ var rfiDownloadDocument = graphql(`
36869
+ query Cli_rfiDownload($id: ID!) {
36870
+ rfi(id: $id) {
36871
+ id
36872
+ rfiNumber
36873
+ rfiShortNumber
36874
+ subject
36875
+ attachments {
36876
+ id
36877
+ order
36878
+ document {
36879
+ id
36880
+ title
36881
+ fileResource {
36882
+ id
36883
+ targetFile {
36884
+ downloadUrl
36885
+ filename
36886
+ mimeType
36887
+ }
36888
+ }
36889
+ }
36890
+ }
36891
+ responses {
36892
+ id
36893
+ attachments {
36894
+ id
36895
+ document {
36896
+ id
36897
+ title
36898
+ fileResource {
36899
+ id
36900
+ targetFile {
36901
+ downloadUrl
36902
+ filename
36903
+ mimeType
36904
+ }
36905
+ }
36906
+ }
36907
+ }
36908
+ }
36909
+ }
36910
+ }
36911
+ `);
36912
+
36913
+ // apps/cli/src/graphql/refs.ts
36914
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
36915
+ function parseEntityRef(value2) {
36916
+ const trimmed = value2.trim();
36917
+ const citation = trimmed.match(/^sb:\/\/([a-z]+)\/([^#?]+)/i);
36918
+ if (citation) {
36919
+ return {
36920
+ kind: "citation",
36921
+ scheme: citation[1].toLowerCase(),
36922
+ id: citation[2]
36923
+ };
36924
+ }
36925
+ if (UUID_RE.test(trimmed)) {
36926
+ return { kind: "uuid", id: trimmed };
36927
+ }
36928
+ return { kind: "key", value: trimmed };
36929
+ }
36930
+ var SCHEME_COMMANDS = {
36931
+ drawing: "specset drawings download",
36932
+ doc: "specset docs download",
36933
+ spec: "specset specs download",
36934
+ sub: "specset submittals download",
36935
+ subatt: "specset submittals download --list (attachments are addressed via their parent submittal)",
36936
+ rfi: "specset rfis download",
36937
+ file: "specset files download"
36938
+ };
36939
+ function requireRefId(ref, acceptedSchemes) {
36940
+ if (ref.kind === "uuid") {
36941
+ return ref.id;
36942
+ }
36943
+ if (ref.kind === "citation") {
36944
+ if (acceptedSchemes.includes(ref.scheme)) {
36945
+ return ref.id;
36946
+ }
36947
+ const suggestion = SCHEME_COMMANDS[ref.scheme];
36948
+ return new Error(
36949
+ `This is an sb://${ref.scheme} citation${suggestion ? ` \u2014 use \`${suggestion}\`` : ", which no download command handles yet"}.`
36950
+ );
36951
+ }
36952
+ return new Error(
36953
+ `"${ref.value}" is neither an sb:// citation URL nor a UUID.`
36954
+ );
36955
+ }
36956
+
36957
+ // apps/cli/src/util/download.ts
36958
+ import { createWriteStream } from "node:fs";
36959
+ import fs2 from "node:fs/promises";
36960
+ import path6 from "node:path";
36961
+ import { Readable } from "node:stream";
36962
+ import { pipeline } from "node:stream/promises";
36963
+ var MAX_REDIRECTS = 5;
36964
+ async function downloadToFile(opts) {
36965
+ let currentUrl = opts.url;
36966
+ let response = null;
36967
+ const originalOrigin = new URL(opts.url).origin;
36968
+ for (let hop = 0; hop <= MAX_REDIRECTS; hop += 1) {
36969
+ const sameOrigin = new URL(currentUrl).origin === originalOrigin;
36970
+ const headers = {};
36971
+ if (sameOrigin) {
36972
+ headers["authorization"] = `Bearer ${opts.token}`;
36973
+ if (opts.orgId) {
36974
+ headers["x-org-id"] = opts.orgId;
36975
+ }
36976
+ }
36977
+ const res = await fetch(currentUrl, { headers, redirect: "manual" });
36978
+ if (res.status >= 300 && res.status < 400) {
36979
+ const location = res.headers.get("location");
36980
+ if (!location) {
36981
+ throw new Error(`Redirect from ${currentUrl} carried no Location`);
36982
+ }
36983
+ await res.arrayBuffer().catch(() => void 0);
36984
+ currentUrl = new URL(location, currentUrl).toString();
36985
+ continue;
36986
+ }
36987
+ response = res;
36988
+ break;
36989
+ }
36990
+ if (!response) {
36991
+ throw new Error(`Too many redirects downloading ${opts.url}`);
36992
+ }
36993
+ if (!response.ok) {
36994
+ const detail = await response.text().catch(() => "");
36995
+ throw new Error(
36996
+ `Download failed (${response.status})${detail ? `: ${detail.slice(0, 300)}` : ""}`
36997
+ );
36998
+ }
36999
+ if (!response.body) {
37000
+ throw new Error("Download response had no body");
37001
+ }
37002
+ await fs2.mkdir(path6.dirname(opts.destPath), { recursive: true });
37003
+ await pipeline(
37004
+ Readable.fromWeb(response.body),
37005
+ createWriteStream(opts.destPath)
37006
+ );
37007
+ const stat = await fs2.stat(opts.destPath);
37008
+ return {
37009
+ path: opts.destPath,
37010
+ bytes: stat.size,
37011
+ contentType: response.headers.get("content-type")
37012
+ };
37013
+ }
37014
+ function deriveFilename(parts, extension) {
37015
+ const base = parts.filter((part) => Boolean(part && part.trim())).join(" - ").replace(/[\u0000-\u001f/\\:*?"<>|]/g, "_").replace(/\s+/g, " ").trim().slice(0, 150);
37016
+ return `${base || "download"}${extension}`;
37017
+ }
37018
+ async function resolveDestPath(opts) {
37019
+ if (!opts.out) {
37020
+ return path6.join(opts.cwd, opts.defaultFilename);
37021
+ }
37022
+ const resolved = path6.resolve(opts.cwd, opts.out);
37023
+ if (opts.out.endsWith("/") || opts.out.endsWith(path6.sep)) {
37024
+ return path6.join(resolved, opts.defaultFilename);
37025
+ }
37026
+ const stat = await fs2.stat(resolved).catch(() => null);
37027
+ if (stat?.isDirectory()) {
37028
+ return path6.join(resolved, opts.defaultFilename);
37029
+ }
37030
+ return resolved;
37031
+ }
37032
+
37033
+ // apps/cli/src/util/fileDownload.ts
37034
+ async function fetchOne(ctx, target, defaultFilename, label) {
37035
+ const destPath = await resolveDestPath({
37036
+ out: ctx.out,
37037
+ cwd: ctx.cwd,
37038
+ defaultFilename
37039
+ });
37040
+ try {
37041
+ const downloaded = await downloadToFile({
37042
+ url: target.downloadUrl,
37043
+ token: ctx.token,
37044
+ orgId: ctx.orgId,
37045
+ destPath
37046
+ });
37047
+ return { label, ...downloaded };
37048
+ } catch (err) {
37049
+ return err instanceof Error ? err : new Error(String(err));
37050
+ }
37051
+ }
37052
+ async function fetchMany(ctx, items) {
37053
+ const dir = ctx.out ? path7.resolve(ctx.cwd, ctx.out) : ctx.cwd;
37054
+ const files = [];
37055
+ for (const item of items) {
37056
+ try {
37057
+ const downloaded = await downloadToFile({
37058
+ url: item.target.downloadUrl,
37059
+ token: ctx.token,
37060
+ orgId: ctx.orgId,
37061
+ destPath: path7.join(dir, item.filename)
37062
+ });
37063
+ files.push({ label: item.label, ...downloaded });
37064
+ } catch (err) {
37065
+ return err instanceof Error ? err : new Error(String(err));
37066
+ }
37067
+ }
37068
+ return files;
37069
+ }
37070
+ async function downloadDocumentAsset(ctx, opts) {
37071
+ const id = requireRefId(parseEntityRef(opts.ref), ["doc"]);
37072
+ if (id instanceof Error) {
37073
+ return id;
37074
+ }
37075
+ let document;
37076
+ try {
37077
+ const result = await ctx.client.request(documentDownloadDocument, { id });
37078
+ document = result.document;
37079
+ } catch (err) {
37080
+ return new Error(formatGraphQLError(err));
37081
+ }
37082
+ if (!document) {
37083
+ return new Error(
37084
+ `Document "${id}" not found (is the right org/host active?).`
37085
+ );
37086
+ }
37087
+ const target = document.fileResource.targetFile;
37088
+ const file = await fetchOne(
37089
+ ctx,
37090
+ target,
37091
+ target.filename || deriveFilename([document.title], ".pdf"),
37092
+ document.title
37093
+ );
37094
+ if (file instanceof Error) {
37095
+ return file;
37096
+ }
37097
+ return { kind: "downloaded", entity: document.title, files: [file] };
37098
+ }
37099
+ async function downloadFileResourceAsset(ctx, opts) {
37100
+ const id = requireRefId(parseEntityRef(opts.ref), ["file"]);
37101
+ if (id instanceof Error) {
37102
+ return id;
37103
+ }
37104
+ let fileResource;
37105
+ try {
37106
+ const result = await ctx.client.request(fileResourceDownloadDocument, {
37107
+ id
37108
+ });
37109
+ fileResource = result.fileResource;
37110
+ } catch (err) {
37111
+ return new Error(formatGraphQLError(err));
37112
+ }
37113
+ const target = fileResource.targetFile;
37114
+ const file = await fetchOne(
37115
+ ctx,
37116
+ target,
37117
+ target.filename || deriveFilename([fileResource.name], ""),
37118
+ fileResource.name
37119
+ );
37120
+ if (file instanceof Error) {
37121
+ return file;
37122
+ }
37123
+ return { kind: "downloaded", entity: fileResource.name, files: [file] };
37124
+ }
37125
+ async function downloadSpecSectionAsset(ctx, opts) {
37126
+ const parsed = parseEntityRef(opts.ref);
37127
+ let id;
37128
+ if (parsed.kind === "key") {
37129
+ if (!opts.projectId) {
37130
+ return new Error(
37131
+ `"${opts.ref}" looks like a section number \u2014 pass --project <id> so it can be resolved.`
37132
+ );
37133
+ }
37134
+ let section;
37135
+ try {
37136
+ const result = await ctx.client.request(specSectionIdByNumberDocument, {
37137
+ projectId: opts.projectId,
37138
+ sectionNumber: parsed.value
37139
+ });
37140
+ section = result.specSectionByNumber;
37141
+ } catch (err) {
37142
+ return new Error(formatGraphQLError(err));
37143
+ }
37144
+ if (!section) {
37145
+ return new Error(
37146
+ `No spec section numbered "${parsed.value}" in this project.`
37147
+ );
37148
+ }
37149
+ id = section.id;
37150
+ } else {
37151
+ const resolved = requireRefId(parsed, ["spec"]);
37152
+ if (resolved instanceof Error) {
37153
+ return resolved;
37154
+ }
37155
+ id = resolved;
37156
+ }
37157
+ let specSection;
37158
+ try {
37159
+ const result = await ctx.client.request(specSectionDownloadDocument, {
37160
+ id
37161
+ });
37162
+ specSection = result.specSection;
37163
+ } catch (err) {
37164
+ return new Error(formatGraphQLError(err));
37165
+ }
37166
+ if (!specSection) {
37167
+ return new Error(
37168
+ `Spec section "${id}" not found (is the right org/host active?).`
37169
+ );
37170
+ }
37171
+ const label = `${specSection.sectionNumber} ${specSection.title}`;
37172
+ const sectionFile = specSection.specSectionFiles.find(
37173
+ (file2) => !file2.archivedAt
37174
+ );
37175
+ if (!sectionFile) {
37176
+ return new Error(`Spec section ${label} has no source file.`);
37177
+ }
37178
+ if (opts.asset === "section") {
37179
+ const target2 = sectionFile.fileResource?.targetFile;
37180
+ if (!target2) {
37181
+ return new Error(
37182
+ `Spec section ${label} has no per-section PDF (pages ${sectionFile.pages.join(", ")} of the spec file) \u2014 try --asset book for the whole spec file.`
37183
+ );
37184
+ }
37185
+ const file2 = await fetchOne(
37186
+ ctx,
37187
+ target2,
37188
+ deriveFilename([specSection.sectionNumber, specSection.title], ".pdf"),
37189
+ label
37190
+ );
37191
+ if (file2 instanceof Error) {
37192
+ return file2;
37193
+ }
37194
+ return { kind: "downloaded", entity: label, files: [file2] };
37195
+ }
37196
+ const specFile = sectionFile.specFile;
37197
+ const target = specFile.fileResource.targetFile;
37198
+ const file = await fetchOne(
37199
+ ctx,
37200
+ target,
37201
+ target.filename || deriveFilename([specFile.title || specSection.sectionNumber], ".pdf"),
37202
+ specFile.title || label
37203
+ );
37204
+ if (file instanceof Error) {
37205
+ return file;
37206
+ }
37207
+ return { kind: "downloaded", entity: label, files: [file] };
37208
+ }
37209
+ async function downloadSubmittalAsset(ctx, opts) {
37210
+ const id = requireRefId(parseEntityRef(opts.ref), ["sub"]);
37211
+ if (id instanceof Error) {
37212
+ return id;
37213
+ }
37214
+ let submittal;
37215
+ try {
37216
+ const result = await ctx.client.request(submittalDownloadDocument, { id });
37217
+ submittal = result.submittal;
37218
+ } catch (err) {
37219
+ return new Error(formatGraphQLError(err));
37220
+ }
37221
+ if (!submittal) {
37222
+ return new Error(
37223
+ `Submittal "${id}" not found (is the right org/host active?).`
37224
+ );
37225
+ }
37226
+ const label = [
37227
+ submittal.formattedSubmittalNumber,
37228
+ submittal.revision ? `Rev ${submittal.revision}` : null,
37229
+ submittal.title
37230
+ ].filter(Boolean).join(" ");
37231
+ const compiled = submittal.compiledSubmittal?.targetFile ?? null;
37232
+ const cover = (submittal.compiledCoverSheet ?? submittal.coverSheet)?.targetFile;
37233
+ const attachments = [...submittal.attachments].sort((a3, b) => a3.order - b.order).map((attachment, i2) => ({
37234
+ index: i2 + 1,
37235
+ label: attachment.description || attachment.document.title || `Attachment ${i2 + 1}`,
37236
+ target: attachment.fileResource?.targetFile ?? attachment.document.fileResource.targetFile
37237
+ }));
37238
+ const inventory = [
37239
+ {
37240
+ asset: "compiled",
37241
+ label: "Compiled submittal package",
37242
+ available: Boolean(compiled)
37243
+ },
37244
+ { asset: "cover", label: "Cover sheet", available: Boolean(cover) },
37245
+ ...attachments.map((attachment) => ({
37246
+ asset: "attachment",
37247
+ index: attachment.index,
37248
+ label: attachment.label,
37249
+ available: true
37250
+ }))
37251
+ ];
37252
+ const asset = opts.asset ?? (compiled ? "compiled" : void 0);
37253
+ if (opts.list || !asset) {
37254
+ return { kind: "inventory", entity: label, items: inventory };
37255
+ }
37256
+ if (asset === "compiled" || asset === "cover") {
37257
+ const target = asset === "compiled" ? compiled : cover;
37258
+ if (!target) {
37259
+ return new Error(
37260
+ `Submittal ${label} has no ${asset === "compiled" ? "compiled package" : "cover sheet"} \u2014 run with --list to see available assets.`
37261
+ );
37262
+ }
37263
+ const file = await fetchOne(
37264
+ ctx,
37265
+ target,
37266
+ target.filename || deriveFilename([label, asset], ".pdf"),
37267
+ `${label} (${asset})`
37268
+ );
37269
+ if (file instanceof Error) {
37270
+ return file;
37271
+ }
37272
+ return { kind: "downloaded", entity: label, files: [file] };
37273
+ }
37274
+ if (attachments.length === 0) {
37275
+ return new Error(`Submittal ${label} has no attachments.`);
37276
+ }
37277
+ const chosen = opts.all ? attachments : opts.index !== void 0 ? attachments.filter((attachment) => attachment.index === opts.index) : attachments.length === 1 ? attachments : null;
37278
+ if (!chosen) {
37279
+ return { kind: "inventory", entity: label, items: inventory };
37280
+ }
37281
+ if (chosen.length === 0) {
37282
+ return new Error(
37283
+ `No attachment #${opts.index} \u2014 indices run 1 to ${attachments.length}.`
37284
+ );
37285
+ }
37286
+ const files = await fetchMany(
37287
+ ctx,
37288
+ chosen.map((attachment) => ({
37289
+ target: attachment.target,
37290
+ filename: attachment.target.filename || deriveFilename([label, attachment.label], ".pdf"),
37291
+ label: attachment.label
37292
+ }))
37293
+ );
37294
+ if (files instanceof Error) {
37295
+ return files;
37296
+ }
37297
+ return { kind: "downloaded", entity: label, files };
37298
+ }
37299
+ async function downloadRfiAsset(ctx, opts) {
37300
+ const id = requireRefId(parseEntityRef(opts.ref), ["rfi"]);
37301
+ if (id instanceof Error) {
37302
+ return id;
37303
+ }
37304
+ let rfi;
37305
+ try {
37306
+ const result = await ctx.client.request(rfiDownloadDocument, { id });
37307
+ rfi = result.rfi;
37308
+ } catch (err) {
37309
+ return new Error(formatGraphQLError(err));
37310
+ }
37311
+ if (!rfi) {
37312
+ return new Error(`RFI "${id}" not found (is the right org/host active?).`);
37313
+ }
37314
+ const label = [rfi.rfiNumber || rfi.rfiShortNumber, rfi.subject].filter(Boolean).join(" ");
37315
+ const attachments = [
37316
+ ...[...rfi.attachments].sort((a3, b) => a3.order - b.order).map((attachment) => ({
37317
+ label: attachment.document.title,
37318
+ target: attachment.document.fileResource.targetFile
37319
+ })),
37320
+ ...rfi.responses.flatMap(
37321
+ (response) => response.attachments.map((attachment) => ({
37322
+ label: `${attachment.document.title} (response)`,
37323
+ target: attachment.document.fileResource.targetFile
37324
+ }))
37325
+ )
37326
+ ].map((attachment, i2) => ({ ...attachment, index: i2 + 1 }));
37327
+ if (attachments.length === 0) {
37328
+ return new Error(`RFI ${label} has no attachments.`);
37329
+ }
37330
+ const inventory = attachments.map((attachment) => ({
37331
+ asset: "attachment",
37332
+ index: attachment.index,
37333
+ label: attachment.label,
37334
+ available: true
37335
+ }));
37336
+ const chosen = opts.list ? null : opts.all ? attachments : opts.index !== void 0 ? attachments.filter((attachment) => attachment.index === opts.index) : attachments.length === 1 ? attachments : null;
37337
+ if (!chosen) {
37338
+ return { kind: "inventory", entity: label, items: inventory };
37339
+ }
37340
+ if (chosen.length === 0) {
37341
+ return new Error(
37342
+ `No attachment #${opts.index} \u2014 indices run 1 to ${attachments.length}.`
37343
+ );
37344
+ }
37345
+ const files = await fetchMany(
37346
+ ctx,
37347
+ chosen.map((attachment) => ({
37348
+ target: attachment.target,
37349
+ filename: attachment.target.filename || deriveFilename([label, attachment.label], ".pdf"),
37350
+ label: attachment.label
37351
+ }))
37352
+ );
37353
+ if (files instanceof Error) {
37354
+ return files;
37355
+ }
37356
+ return { kind: "downloaded", entity: label, files };
37357
+ }
37358
+
37359
+ // apps/cli/src/commands/docs/download.ts
37360
+ async function docsDownloadCommand(flags, ref) {
37361
+ const cli = await resolveDownloadCli(this.config, flags.host);
37362
+ if (cli instanceof Error) {
37363
+ return cli;
37364
+ }
37365
+ const outcome = await downloadDocumentAsset(
37366
+ { ...cli, cwd: process.cwd(), out: flags.out },
37367
+ { ref }
37368
+ );
37369
+ if (outcome instanceof Error) {
37370
+ return outcome;
37371
+ }
37372
+ printOutcome(this.process, flags.json ?? false, outcome, process.cwd());
37373
+ }
37374
+ var docsDownload = buildCommand({
37375
+ func: docsDownloadCommand,
37376
+ parameters: {
37377
+ positional: {
37378
+ kind: "tuple",
37379
+ parameters: [
37380
+ {
37381
+ brief: "Document reference: sb://doc/<uuid> citation or bare UUID",
37382
+ parse: String,
37383
+ placeholder: "ref"
37384
+ }
37385
+ ]
37386
+ },
37387
+ flags: {
37388
+ out: {
37389
+ kind: "parsed",
37390
+ parse: String,
37391
+ brief: "Destination path or directory (defaults to the stored filename in the cwd)",
37392
+ optional: true
37393
+ },
37394
+ host: {
37395
+ kind: "parsed",
37396
+ parse: String,
37397
+ brief: "Host to call (defaults to the active host)",
37398
+ optional: true
37399
+ },
37400
+ json: {
37401
+ kind: "boolean",
37402
+ brief: "Emit the download metadata as JSON",
37403
+ optional: true
37404
+ }
37405
+ }
37406
+ },
37407
+ docs: {
37408
+ brief: "Download a project document (also covers RFI attachments and closeout documents)"
37409
+ }
37410
+ });
37411
+
37412
+ // apps/cli/src/commands/drawings/download.ts
37413
+ import path8 from "node:path";
37414
+
37415
+ // apps/cli/src/graphql/agentTools.ts
37416
+ var agentToolsDocument = graphql(`
37417
+ query Cli_agentTools($orgId: ID!, $projectId: ID) {
37418
+ agentTools(orgId: $orgId, projectId: $projectId) {
37419
+ instructions
37420
+ tools {
37421
+ name
37422
+ description
37423
+ inputSchema
37424
+ projectScoped
37425
+ }
37426
+ }
37427
+ }
37428
+ `);
37429
+ var runAgentToolDocument = graphql(`
37430
+ mutation Cli_runAgentTool(
37431
+ $orgId: ID!
37432
+ $toolName: String!
37433
+ $input: JSON
37434
+ $projectId: ID
37435
+ ) {
37436
+ runAgentTool(
37437
+ orgId: $orgId
37438
+ toolName: $toolName
37439
+ input: $input
37440
+ projectId: $projectId
37441
+ )
37442
+ }
37443
+ `);
37444
+ function normalizeProjectId(value2) {
37445
+ const match = value2.match(/^sb:\/\/project\/([^#?]+)/);
37446
+ return match ? match[1] : value2;
37447
+ }
37448
+
37449
+ // apps/cli/src/graphql/drawings.ts
37450
+ var drawingSheetDownloadDocument = graphql(`
37451
+ query Cli_drawingSheetDownload($id: ID!) {
37452
+ drawingSheet(id: $id) {
37453
+ id
37454
+ sheetNumber
37455
+ title
37456
+ currentRevision {
37457
+ id
37458
+ page
37459
+ image {
37460
+ id
37461
+ downloadUrl
37462
+ filename
37463
+ mimeType
37464
+ }
37465
+ fileResource {
37466
+ id
37467
+ name
37468
+ numPages
37469
+ targetFile {
37470
+ id
37471
+ downloadUrl
37472
+ filename
37473
+ mimeType
37474
+ }
37475
+ }
37476
+ drawingFile {
37477
+ id
37478
+ title
37479
+ startPage
37480
+ endPage
37481
+ fileResource {
37482
+ id
37483
+ name
37484
+ targetFile {
37485
+ id
37486
+ downloadUrl
37487
+ filename
37488
+ mimeType
37489
+ }
37490
+ }
37491
+ }
37492
+ }
37493
+ }
37494
+ }
37495
+ `);
37496
+ var drawingSheetByNumberDocument = graphql(`
37497
+ query Cli_drawingSheetByNumber($projectId: ID!, $sheetNumber: String!) {
37498
+ drawingSheetByNumber(projectId: $projectId, sheetNumber: $sheetNumber) {
37499
+ id
37500
+ }
37501
+ }
37502
+ `);
37503
+ var drawingSheetsLookupDocument = graphql(`
37504
+ query Cli_drawingSheetsLookup($projectId: ID!) {
37505
+ drawingSheets(projectId: $projectId) {
37506
+ id
37507
+ sheetNumber
37508
+ title
37509
+ }
37510
+ }
37511
+ `);
37512
+ function parseDrawingSheetRef(value2) {
37513
+ const ref = parseEntityRef(value2);
37514
+ if (ref.kind === "key") {
37515
+ return { kind: "sheetNumber", sheetNumber: ref.value };
37516
+ }
37517
+ const id = requireRefId(ref, ["drawing"]);
37518
+ if (id instanceof Error) {
37519
+ return id;
37520
+ }
37521
+ return { kind: "id", id };
37522
+ }
37523
+
37524
+ // apps/cli/src/util/drawingDownload.ts
37525
+ var DRAWING_DOWNLOAD_FORMATS = ["image", "pdf", "file"];
37526
+ function extensionFor(mimeType) {
37527
+ switch (mimeType) {
37528
+ case "image/png":
37529
+ return ".png";
37530
+ case "image/jpeg":
37531
+ return ".jpg";
37532
+ case "application/pdf":
37533
+ return ".pdf";
37534
+ default:
37535
+ return "";
37536
+ }
37537
+ }
37538
+ function pickAsset(sheet, revision, format) {
37539
+ if (format === "image") {
37540
+ const image = revision.image;
37541
+ if (!image) {
37542
+ return new Error(
37543
+ `Sheet ${sheet.sheetNumber} has no rendered image \u2014 try format "pdf".`
37544
+ );
37545
+ }
37546
+ return {
37547
+ url: image.downloadUrl,
37548
+ filename: deriveFilename(
37549
+ [sheet.sheetNumber, sheet.title],
37550
+ extensionFor(image.mimeType) || ".png"
37551
+ )
37552
+ };
37553
+ }
37554
+ if (format === "pdf") {
37555
+ const target2 = revision.fileResource?.targetFile;
37556
+ if (!target2) {
37557
+ return new Error(
37558
+ `Sheet ${sheet.sheetNumber} has no per-sheet PDF (page ${revision.page} of the drawing file) \u2014 try format "file" to fetch the whole drawing set.`
37559
+ );
37560
+ }
37561
+ return {
37562
+ url: target2.downloadUrl,
37563
+ filename: deriveFilename(
37564
+ [sheet.sheetNumber, sheet.title],
37565
+ extensionFor(target2.mimeType) || ".pdf"
37566
+ )
37567
+ };
37568
+ }
37569
+ const drawingFile = revision.drawingFile;
37570
+ const target = drawingFile?.fileResource?.targetFile;
37571
+ if (!drawingFile || !target) {
37572
+ return new Error(
37573
+ `Sheet ${sheet.sheetNumber} has no downloadable drawing file.`
37574
+ );
37575
+ }
37576
+ return {
37577
+ url: target.downloadUrl,
37578
+ filename: target.filename || deriveFilename([drawingFile.title || sheet.sheetNumber], ".pdf")
37579
+ };
37580
+ }
37581
+ async function downloadDrawingSheetAsset(req) {
37582
+ const parsedRef = parseDrawingSheetRef(req.ref);
37583
+ if (parsedRef instanceof Error) {
37584
+ return parsedRef;
37585
+ }
37586
+ let sheetId;
37587
+ if (parsedRef.kind === "id") {
37588
+ sheetId = parsedRef.id;
37589
+ } else {
37590
+ if (!req.projectId) {
37591
+ return new Error(
37592
+ `"${req.ref}" looks like a sheet number \u2014 a project id is required to resolve it.`
37593
+ );
37594
+ }
37595
+ let byNumber;
37596
+ try {
37597
+ const result = await req.client.request(drawingSheetByNumberDocument, {
37598
+ projectId: req.projectId,
37599
+ sheetNumber: parsedRef.sheetNumber
37600
+ });
37601
+ byNumber = result.drawingSheetByNumber;
37602
+ } catch (err) {
37603
+ return new Error(formatGraphQLError(err));
37604
+ }
37605
+ if (!byNumber) {
37606
+ let sample = "";
37607
+ try {
37608
+ const result = await req.client.request(drawingSheetsLookupDocument, {
37609
+ projectId: req.projectId
37610
+ });
37611
+ sample = result.drawingSheets.slice(0, 8).map((sheet2) => sheet2.sheetNumber).join(", ");
37612
+ } catch {
37613
+ }
37614
+ return new Error(
37615
+ `No sheet numbered "${parsedRef.sheetNumber}" in this project.${sample ? ` First sheets: ${sample}\u2026` : ""}`
37616
+ );
37617
+ }
37618
+ sheetId = byNumber.id;
37619
+ }
37620
+ let sheet;
37621
+ try {
37622
+ const result = await req.client.request(drawingSheetDownloadDocument, {
37623
+ id: sheetId
37624
+ });
37625
+ sheet = result.drawingSheet;
37626
+ } catch (err) {
37627
+ return new Error(formatGraphQLError(err));
37628
+ }
37629
+ if (!sheet) {
37630
+ return new Error(
37631
+ `Drawing sheet "${sheetId}" not found (is the right org/host active?).`
37632
+ );
37633
+ }
37634
+ const revision = sheet.currentRevision;
37635
+ if (!revision) {
37636
+ return new Error(
37637
+ `Sheet ${sheet.sheetNumber} has no current revision to download.`
37638
+ );
37639
+ }
37640
+ const asset = pickAsset(sheet, revision, req.format);
37641
+ if (asset instanceof Error) {
37642
+ return asset;
37643
+ }
37644
+ const destPath = await resolveDestPath({
37645
+ out: req.out,
37646
+ cwd: req.cwd,
37647
+ defaultFilename: asset.filename
37648
+ });
37649
+ let downloaded;
37650
+ try {
37651
+ downloaded = await downloadToFile({
37652
+ url: asset.url,
37653
+ token: req.token,
37654
+ orgId: req.orgId,
37655
+ destPath
37656
+ });
37657
+ } catch (err) {
37658
+ return err instanceof Error ? err : new Error(String(err));
37659
+ }
37660
+ return {
37661
+ sheetId: sheet.id,
37662
+ sheetNumber: sheet.sheetNumber,
37663
+ title: sheet.title,
37664
+ format: req.format,
37665
+ page: revision.page,
37666
+ path: downloaded.path,
37667
+ bytes: downloaded.bytes,
37668
+ contentType: downloaded.contentType
37669
+ };
37670
+ }
37671
+
37672
+ // apps/cli/src/commands/drawings/download.ts
37673
+ function parseFormat(value2) {
37674
+ if (DRAWING_DOWNLOAD_FORMATS.includes(value2)) {
37675
+ return value2;
37676
+ }
37677
+ throw new Error(
37678
+ `Invalid format "${value2}" (expected ${DRAWING_DOWNLOAD_FORMATS.join("|")})`
37679
+ );
37680
+ }
37681
+ async function drawingsDownloadCommand(flags, ref) {
37682
+ const cli = await resolveDownloadCli(this.config, flags.host);
37683
+ if (cli instanceof Error) {
37684
+ return cli;
37685
+ }
37686
+ const result = await downloadDrawingSheetAsset({
37687
+ client: cli.client,
37688
+ token: cli.token,
37689
+ orgId: cli.orgId,
37690
+ ref,
37691
+ projectId: flags.project ? normalizeProjectId(flags.project) : void 0,
37692
+ format: flags.format,
37693
+ out: flags.out,
37694
+ cwd: process.cwd()
37695
+ });
37696
+ if (result instanceof Error) {
37697
+ return result;
37698
+ }
37699
+ const sizeMb = (result.bytes / (1024 * 1024)).toFixed(1);
37700
+ printResult(
37701
+ this.process,
37702
+ flags.json ?? false,
37703
+ result,
37704
+ [
37705
+ `Saved ${result.sheetNumber} \u2014 ${result.title} (${result.format}, ${sizeMb} MB)`,
37706
+ ` ${path8.relative(process.cwd(), result.path) || result.path}`
37707
+ ].join("\n")
37708
+ );
37709
+ }
37710
+ var drawingsDownload = buildCommand({
37711
+ func: drawingsDownloadCommand,
37712
+ parameters: {
37713
+ positional: {
37714
+ kind: "tuple",
37715
+ parameters: [
37716
+ {
37717
+ brief: "Sheet reference: sb://drawing/<uuid> citation, bare UUID, or sheet number (with --project)",
37718
+ parse: String,
37719
+ placeholder: "ref"
37720
+ }
37721
+ ]
37722
+ },
37723
+ flags: {
37724
+ project: {
37725
+ kind: "parsed",
37726
+ parse: String,
37727
+ brief: "Project scope, required for sheet-number refs (UUID or sb://project/ URL)",
37728
+ optional: true
37729
+ },
37730
+ format: {
37731
+ kind: "parsed",
37732
+ parse: parseFormat,
37733
+ brief: "Asset to download: image (rendered PNG), pdf (single-sheet PDF), or file (whole drawing file PDF)",
37734
+ default: "image"
37735
+ },
37736
+ out: {
37737
+ kind: "parsed",
37738
+ parse: String,
37739
+ brief: "Destination path or directory (defaults to a derived filename in the cwd)",
37740
+ optional: true
37741
+ },
37742
+ host: {
37743
+ kind: "parsed",
37744
+ parse: String,
37745
+ brief: "Host to call (defaults to the active host)",
37746
+ optional: true
37747
+ },
37748
+ json: {
37749
+ kind: "boolean",
37750
+ brief: "Emit the download metadata as JSON",
37751
+ optional: true
37752
+ }
37753
+ }
37754
+ },
37755
+ docs: {
37756
+ brief: "Download a drawing sheet as an image or PDF"
37757
+ }
37758
+ });
37759
+
37760
+ // apps/cli/src/commands/files/download.ts
37761
+ async function filesDownloadCommand(flags, ref) {
37762
+ const cli = await resolveDownloadCli(this.config, flags.host);
37763
+ if (cli instanceof Error) {
37764
+ return cli;
37765
+ }
37766
+ const outcome = await downloadFileResourceAsset(
37767
+ { ...cli, cwd: process.cwd(), out: flags.out },
37768
+ { ref }
37769
+ );
37770
+ if (outcome instanceof Error) {
37771
+ return outcome;
37772
+ }
37773
+ printOutcome(this.process, flags.json ?? false, outcome, process.cwd());
37774
+ }
37775
+ var filesDownload = buildCommand({
37776
+ func: filesDownloadCommand,
37777
+ parameters: {
37778
+ positional: {
37779
+ kind: "tuple",
37780
+ parameters: [
37781
+ {
37782
+ brief: "File resource reference: sb://file/<uuid> citation or bare UUID",
37783
+ parse: String,
37784
+ placeholder: "ref"
37785
+ }
37786
+ ]
37787
+ },
37788
+ flags: {
37789
+ out: {
37790
+ kind: "parsed",
37791
+ parse: String,
37792
+ brief: "Destination path or directory (defaults to the stored filename in the cwd)",
37793
+ optional: true
37794
+ },
37795
+ host: {
37796
+ kind: "parsed",
37797
+ parse: String,
37798
+ brief: "Host to call (defaults to the active host)",
37799
+ optional: true
37800
+ },
37801
+ json: {
37802
+ kind: "boolean",
37803
+ brief: "Emit the download metadata as JSON",
37804
+ optional: true
37805
+ }
37806
+ }
37807
+ },
37808
+ docs: {
37809
+ brief: "Download a raw file resource by id (the universal escape hatch)"
37810
+ }
37811
+ });
37812
+
36678
37813
  // apps/cli/src/commands/host/list.ts
36679
37814
  async function hostListCommand(flags) {
36680
37815
  const hosts = Object.keys(this.config.hosts).sort();
@@ -37478,8 +38613,8 @@ function getErrorMap() {
37478
38613
 
37479
38614
  // node_modules/zod/v3/helpers/parseUtil.js
37480
38615
  var makeIssue = (params) => {
37481
- const { data, path: path6, errorMaps, issueData } = params;
37482
- const fullPath = [...path6, ...issueData.path || []];
38616
+ const { data, path: path10, errorMaps, issueData } = params;
38617
+ const fullPath = [...path10, ...issueData.path || []];
37483
38618
  const fullIssue = {
37484
38619
  ...issueData,
37485
38620
  path: fullPath
@@ -37594,11 +38729,11 @@ var errorUtil;
37594
38729
 
37595
38730
  // node_modules/zod/v3/types.js
37596
38731
  var ParseInputLazyPath = class {
37597
- constructor(parent, value2, path6, key) {
38732
+ constructor(parent, value2, path10, key) {
37598
38733
  this._cachedPath = [];
37599
38734
  this.parent = parent;
37600
38735
  this.data = value2;
37601
- this._path = path6;
38736
+ this._path = path10;
37602
38737
  this._key = key;
37603
38738
  }
37604
38739
  get path() {
@@ -41231,10 +42366,10 @@ function mergeDefs(...defs) {
41231
42366
  function cloneDef(schema) {
41232
42367
  return mergeDefs(schema._zod.def);
41233
42368
  }
41234
- function getElementAtPath(obj, path6) {
41235
- if (!path6)
42369
+ function getElementAtPath(obj, path10) {
42370
+ if (!path10)
41236
42371
  return obj;
41237
- return path6.reduce((acc, key) => acc?.[key], obj);
42372
+ return path10.reduce((acc, key) => acc?.[key], obj);
41238
42373
  }
41239
42374
  function promiseAllObject(promisesObj) {
41240
42375
  const keys = Object.keys(promisesObj);
@@ -41595,11 +42730,11 @@ function aborted(x, startIndex = 0) {
41595
42730
  }
41596
42731
  return false;
41597
42732
  }
41598
- function prefixIssues(path6, issues) {
42733
+ function prefixIssues(path10, issues) {
41599
42734
  return issues.map((iss) => {
41600
42735
  var _a;
41601
42736
  (_a = iss).path ?? (_a.path = []);
41602
- iss.path.unshift(path6);
42737
+ iss.path.unshift(path10);
41603
42738
  return iss;
41604
42739
  });
41605
42740
  }
@@ -48332,40 +49467,6 @@ var StdioServerTransport = class {
48332
49467
  }
48333
49468
  };
48334
49469
 
48335
- // apps/cli/src/graphql/agentTools.ts
48336
- var agentToolsDocument = graphql(`
48337
- query Cli_agentTools($orgId: ID!, $projectId: ID) {
48338
- agentTools(orgId: $orgId, projectId: $projectId) {
48339
- instructions
48340
- tools {
48341
- name
48342
- description
48343
- inputSchema
48344
- projectScoped
48345
- }
48346
- }
48347
- }
48348
- `);
48349
- var runAgentToolDocument = graphql(`
48350
- mutation Cli_runAgentTool(
48351
- $orgId: ID!
48352
- $toolName: String!
48353
- $input: JSON
48354
- $projectId: ID
48355
- ) {
48356
- runAgentTool(
48357
- orgId: $orgId
48358
- toolName: $toolName
48359
- input: $input
48360
- projectId: $projectId
48361
- )
48362
- }
48363
- `);
48364
- function normalizeProjectId(value2) {
48365
- const match = value2.match(/^sb:\/\/project\/([^#?]+)/);
48366
- return match ? match[1] : value2;
48367
- }
48368
-
48369
49470
  // apps/cli/src/version.ts
48370
49471
  import { readFileSync } from "node:fs";
48371
49472
  function cliVersion() {
@@ -48688,10 +49789,245 @@ var orgUse = buildCommand({
48688
49789
  }
48689
49790
  });
48690
49791
 
49792
+ // apps/cli/src/commands/rfis/download.ts
49793
+ async function rfisDownloadCommand(flags, ref) {
49794
+ const cli = await resolveDownloadCli(this.config, flags.host);
49795
+ if (cli instanceof Error) {
49796
+ return cli;
49797
+ }
49798
+ const outcome = await downloadRfiAsset(
49799
+ { ...cli, cwd: process.cwd(), out: flags.out },
49800
+ { ref, index: flags.index, all: flags.all, list: flags.list }
49801
+ );
49802
+ if (outcome instanceof Error) {
49803
+ return outcome;
49804
+ }
49805
+ printOutcome(this.process, flags.json ?? false, outcome, process.cwd());
49806
+ }
49807
+ var rfisDownload = buildCommand({
49808
+ func: rfisDownloadCommand,
49809
+ parameters: {
49810
+ positional: {
49811
+ kind: "tuple",
49812
+ parameters: [
49813
+ {
49814
+ brief: "RFI reference: sb://rfi/<uuid> citation or bare UUID",
49815
+ parse: String,
49816
+ placeholder: "ref"
49817
+ }
49818
+ ]
49819
+ },
49820
+ flags: {
49821
+ index: {
49822
+ kind: "parsed",
49823
+ parse: numberParser,
49824
+ brief: "Attachment number from --list (1-based)",
49825
+ optional: true
49826
+ },
49827
+ all: {
49828
+ kind: "boolean",
49829
+ brief: "Download every attachment (--out names a directory)",
49830
+ optional: true
49831
+ },
49832
+ list: {
49833
+ kind: "boolean",
49834
+ brief: "List attachments instead of downloading",
49835
+ optional: true
49836
+ },
49837
+ out: {
49838
+ kind: "parsed",
49839
+ parse: String,
49840
+ brief: "Destination path or directory (defaults to stored filenames in the cwd)",
49841
+ optional: true
49842
+ },
49843
+ host: {
49844
+ kind: "parsed",
49845
+ parse: String,
49846
+ brief: "Host to call (defaults to the active host)",
49847
+ optional: true
49848
+ },
49849
+ json: {
49850
+ kind: "boolean",
49851
+ brief: "Emit the download metadata as JSON",
49852
+ optional: true
49853
+ }
49854
+ }
49855
+ },
49856
+ docs: {
49857
+ brief: "Download RFI attachments, including response attachments (use --list to see them)"
49858
+ }
49859
+ });
49860
+
49861
+ // apps/cli/src/commands/specs/download.ts
49862
+ var SPEC_ASSETS = ["section", "book"];
49863
+ function parseAsset(value2) {
49864
+ if (SPEC_ASSETS.includes(value2)) {
49865
+ return value2;
49866
+ }
49867
+ throw new Error(`Invalid asset "${value2}" (expected ${SPEC_ASSETS.join("|")})`);
49868
+ }
49869
+ async function specsDownloadCommand(flags, ref) {
49870
+ const cli = await resolveDownloadCli(this.config, flags.host);
49871
+ if (cli instanceof Error) {
49872
+ return cli;
49873
+ }
49874
+ const outcome = await downloadSpecSectionAsset(
49875
+ { ...cli, cwd: process.cwd(), out: flags.out },
49876
+ {
49877
+ ref,
49878
+ projectId: flags.project ? normalizeProjectId(flags.project) : void 0,
49879
+ asset: flags.asset
49880
+ }
49881
+ );
49882
+ if (outcome instanceof Error) {
49883
+ return outcome;
49884
+ }
49885
+ printOutcome(this.process, flags.json ?? false, outcome, process.cwd());
49886
+ }
49887
+ var specsDownload = buildCommand({
49888
+ func: specsDownloadCommand,
49889
+ parameters: {
49890
+ positional: {
49891
+ kind: "tuple",
49892
+ parameters: [
49893
+ {
49894
+ brief: 'Spec section reference: sb://spec/<uuid> citation, bare UUID, or section number like "23 31 19" (with --project)',
49895
+ parse: String,
49896
+ placeholder: "ref"
49897
+ }
49898
+ ]
49899
+ },
49900
+ flags: {
49901
+ project: {
49902
+ kind: "parsed",
49903
+ parse: String,
49904
+ brief: "Project scope, required for section-number refs (UUID or sb://project/ URL)",
49905
+ optional: true
49906
+ },
49907
+ asset: {
49908
+ kind: "parsed",
49909
+ parse: parseAsset,
49910
+ brief: "Asset to download: section (per-section PDF slice) or book (the whole source spec file)",
49911
+ default: "section"
49912
+ },
49913
+ out: {
49914
+ kind: "parsed",
49915
+ parse: String,
49916
+ brief: "Destination path or directory (defaults to a derived filename in the cwd)",
49917
+ optional: true
49918
+ },
49919
+ host: {
49920
+ kind: "parsed",
49921
+ parse: String,
49922
+ brief: "Host to call (defaults to the active host)",
49923
+ optional: true
49924
+ },
49925
+ json: {
49926
+ kind: "boolean",
49927
+ brief: "Emit the download metadata as JSON",
49928
+ optional: true
49929
+ }
49930
+ }
49931
+ },
49932
+ docs: {
49933
+ brief: "Download a spec section PDF (or its whole source spec file)"
49934
+ }
49935
+ });
49936
+
49937
+ // apps/cli/src/commands/submittals/download.ts
49938
+ var SUBMITTAL_ASSETS = ["compiled", "cover", "attachment"];
49939
+ function parseAsset2(value2) {
49940
+ if (SUBMITTAL_ASSETS.includes(value2)) {
49941
+ return value2;
49942
+ }
49943
+ throw new Error(
49944
+ `Invalid asset "${value2}" (expected ${SUBMITTAL_ASSETS.join("|")})`
49945
+ );
49946
+ }
49947
+ async function submittalsDownloadCommand(flags, ref) {
49948
+ const cli = await resolveDownloadCli(this.config, flags.host);
49949
+ if (cli instanceof Error) {
49950
+ return cli;
49951
+ }
49952
+ const outcome = await downloadSubmittalAsset(
49953
+ { ...cli, cwd: process.cwd(), out: flags.out },
49954
+ {
49955
+ ref,
49956
+ asset: flags.asset,
49957
+ index: flags.index,
49958
+ all: flags.all,
49959
+ list: flags.list
49960
+ }
49961
+ );
49962
+ if (outcome instanceof Error) {
49963
+ return outcome;
49964
+ }
49965
+ printOutcome(this.process, flags.json ?? false, outcome, process.cwd());
49966
+ }
49967
+ var submittalsDownload = buildCommand({
49968
+ func: submittalsDownloadCommand,
49969
+ parameters: {
49970
+ positional: {
49971
+ kind: "tuple",
49972
+ parameters: [
49973
+ {
49974
+ brief: "Submittal reference: sb://sub/<uuid> citation or bare UUID",
49975
+ parse: String,
49976
+ placeholder: "ref"
49977
+ }
49978
+ ]
49979
+ },
49980
+ flags: {
49981
+ asset: {
49982
+ kind: "parsed",
49983
+ parse: parseAsset2,
49984
+ brief: "Asset to download: compiled (full package, the default when present), cover, or attachment (with --index/--all)",
49985
+ optional: true
49986
+ },
49987
+ index: {
49988
+ kind: "parsed",
49989
+ parse: numberParser,
49990
+ brief: "Attachment number from --list (1-based)",
49991
+ optional: true
49992
+ },
49993
+ all: {
49994
+ kind: "boolean",
49995
+ brief: "Download every attachment (--out names a directory)",
49996
+ optional: true
49997
+ },
49998
+ list: {
49999
+ kind: "boolean",
50000
+ brief: "List available assets instead of downloading",
50001
+ optional: true
50002
+ },
50003
+ out: {
50004
+ kind: "parsed",
50005
+ parse: String,
50006
+ brief: "Destination path or directory (defaults to stored filenames in the cwd)",
50007
+ optional: true
50008
+ },
50009
+ host: {
50010
+ kind: "parsed",
50011
+ parse: String,
50012
+ brief: "Host to call (defaults to the active host)",
50013
+ optional: true
50014
+ },
50015
+ json: {
50016
+ kind: "boolean",
50017
+ brief: "Emit the download metadata as JSON",
50018
+ optional: true
50019
+ }
50020
+ }
50021
+ },
50022
+ docs: {
50023
+ brief: "Download a submittal package, cover sheet, or attachments (use --list to see assets)"
50024
+ }
50025
+ });
50026
+
48691
50027
  // apps/cli/src/commands/skill/install.ts
48692
- import fs2 from "node:fs/promises";
50028
+ import fs3 from "node:fs/promises";
48693
50029
  import os2 from "node:os";
48694
- import path5 from "node:path";
50030
+ import path9 from "node:path";
48695
50031
 
48696
50032
  // apps/cli/src/skillAsset.ts
48697
50033
  import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync2 } from "node:fs";
@@ -48728,11 +50064,11 @@ function isSkillInstallTarget(value2) {
48728
50064
  return Object.hasOwn(SKILL_TARGET_PATHS, value2);
48729
50065
  }
48730
50066
  function defaultSkillsDir(target, homeDir = os2.homedir()) {
48731
- return path5.join(homeDir, ...SKILL_TARGET_PATHS[target]);
50067
+ return path9.join(homeDir, ...SKILL_TARGET_PATHS[target]);
48732
50068
  }
48733
50069
  async function readOptionalText(file) {
48734
50070
  try {
48735
- return await fs2.readFile(file, "utf8");
50071
+ return await fs3.readFile(file, "utf8");
48736
50072
  } catch (err) {
48737
50073
  if (err.code === "ENOENT") {
48738
50074
  return null;
@@ -48741,9 +50077,9 @@ async function readOptionalText(file) {
48741
50077
  }
48742
50078
  }
48743
50079
  async function installOne(skillsDir, name2, version2) {
48744
- const destDir = path5.join(skillsDir, name2);
48745
- const destFile = path5.join(destDir, "SKILL.md");
48746
- const versionFile = path5.join(destDir, SKILL_VERSION_FILENAME);
50080
+ const destDir = path9.join(skillsDir, name2);
50081
+ const destFile = path9.join(destDir, "SKILL.md");
50082
+ const versionFile = path9.join(destDir, SKILL_VERSION_FILENAME);
48747
50083
  const desired = readPackagedSkill(name2);
48748
50084
  const [existing, recordedVersion] = await Promise.all([
48749
50085
  readOptionalText(destFile),
@@ -48753,10 +50089,10 @@ async function installOne(skillsDir, name2, version2) {
48753
50089
  if (existing === desired && previousVersion === version2) {
48754
50090
  return { name: name2, path: destFile, action: "current", previousVersion: null };
48755
50091
  }
48756
- await fs2.mkdir(destDir, { recursive: true });
50092
+ await fs3.mkdir(destDir, { recursive: true });
48757
50093
  await Promise.all([
48758
- fs2.writeFile(destFile, desired),
48759
- fs2.writeFile(versionFile, `${version2}
50094
+ fs3.writeFile(destFile, desired),
50095
+ fs3.writeFile(versionFile, `${version2}
48760
50096
  `)
48761
50097
  ]);
48762
50098
  return {
@@ -48769,7 +50105,7 @@ async function installOne(skillsDir, name2, version2) {
48769
50105
  async function findOrphanedSkills(skillsDir, packagedNames) {
48770
50106
  let entries;
48771
50107
  try {
48772
- entries = await fs2.readdir(skillsDir, { withFileTypes: true });
50108
+ entries = await fs3.readdir(skillsDir, { withFileTypes: true });
48773
50109
  } catch {
48774
50110
  return [];
48775
50111
  }
@@ -48784,18 +50120,18 @@ async function findOrphanedSkills(skillsDir, packagedNames) {
48784
50120
  }
48785
50121
  try {
48786
50122
  const recordedVersion = await readOptionalText(
48787
- path5.join(skillsDir, entry.name, SKILL_VERSION_FILENAME)
50123
+ path9.join(skillsDir, entry.name, SKILL_VERSION_FILENAME)
48788
50124
  );
48789
50125
  if (recordedVersion?.trim()) {
48790
- orphans.push(path5.join(skillsDir, entry.name));
50126
+ orphans.push(path9.join(skillsDir, entry.name));
48791
50127
  continue;
48792
50128
  }
48793
- const content = await fs2.readFile(
48794
- path5.join(skillsDir, entry.name, "SKILL.md"),
50129
+ const content = await fs3.readFile(
50130
+ path9.join(skillsDir, entry.name, "SKILL.md"),
48795
50131
  "utf8"
48796
50132
  );
48797
50133
  if (extractSkillVersion(content) !== null) {
48798
- orphans.push(path5.join(skillsDir, entry.name));
50134
+ orphans.push(path9.join(skillsDir, entry.name));
48799
50135
  }
48800
50136
  } catch {
48801
50137
  }
@@ -49226,6 +50562,54 @@ var toolsRoutes = buildRouteMap({
49226
50562
  brief: "List and run Specset agent tools (search specs, drawings, and more)"
49227
50563
  }
49228
50564
  });
50565
+ var drawingsRoutes = buildRouteMap({
50566
+ routes: {
50567
+ download: drawingsDownload
50568
+ },
50569
+ docs: {
50570
+ brief: "Fetch drawing sheet assets (rendered images, sheet PDFs)"
50571
+ }
50572
+ });
50573
+ var docsRoutes = buildRouteMap({
50574
+ routes: {
50575
+ download: docsDownload
50576
+ },
50577
+ docs: {
50578
+ brief: "Fetch project documents (also RFI attachments, closeout documents)"
50579
+ }
50580
+ });
50581
+ var specsRoutes = buildRouteMap({
50582
+ routes: {
50583
+ download: specsDownload
50584
+ },
50585
+ docs: {
50586
+ brief: "Fetch spec section PDFs (or whole spec files)"
50587
+ }
50588
+ });
50589
+ var submittalsRoutes = buildRouteMap({
50590
+ routes: {
50591
+ download: submittalsDownload
50592
+ },
50593
+ docs: {
50594
+ brief: "Fetch submittal packages, cover sheets, and attachments"
50595
+ }
50596
+ });
50597
+ var rfisRoutes = buildRouteMap({
50598
+ routes: {
50599
+ download: rfisDownload
50600
+ },
50601
+ docs: {
50602
+ brief: "Fetch RFI attachments"
50603
+ }
50604
+ });
50605
+ var filesRoutes = buildRouteMap({
50606
+ routes: {
50607
+ download: filesDownload
50608
+ },
50609
+ docs: {
50610
+ brief: "Fetch raw file resources by id"
50611
+ }
50612
+ });
49229
50613
  var root = buildRouteMap({
49230
50614
  routes: {
49231
50615
  login,
@@ -49237,6 +50621,12 @@ var root = buildRouteMap({
49237
50621
  agent: agentRoutes,
49238
50622
  skill: skillRoutes,
49239
50623
  tools: toolsRoutes,
50624
+ drawings: drawingsRoutes,
50625
+ docs: docsRoutes,
50626
+ specs: specsRoutes,
50627
+ submittals: submittalsRoutes,
50628
+ rfis: rfisRoutes,
50629
+ files: filesRoutes,
49240
50630
  mcp
49241
50631
  },
49242
50632
  docs: {