@divergeai/cli 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/dist/diverge.mjs +142 -80
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -152,6 +152,11 @@ on the binding when the endpoint is a tailnet or LAN address.
|
|
|
152
152
|
## Updating
|
|
153
153
|
|
|
154
154
|
`diverge update` installs the latest release with the npm that installed it.
|
|
155
|
+
Once a day, after a command finishes, the CLI asks the registry for the latest
|
|
156
|
+
version in the background and caches the answer under `$DIVERGE_HOME`; the
|
|
157
|
+
next command prints one line on stderr when a newer release exists. Nothing
|
|
158
|
+
waits on the network for it, and it stays quiet in the bridge, in
|
|
159
|
+
non-interactive shells, under `CI`, and with `DIVERGE_NO_UPDATE_CHECK=1`.
|
|
155
160
|
|
|
156
161
|
## Environment
|
|
157
162
|
|
|
@@ -162,6 +167,7 @@ on the binding when the endpoint is a tailnet or LAN address.
|
|
|
162
167
|
| `DIVERGENT_ORG_ID`, `DIVERGENT_PROJECT_ID` | tool scope when the flags are omitted; without either, the login's organization |
|
|
163
168
|
| `DIVERGENT_CLIENT_ID`, `DIVERGENT_CLIENT_SECRET`, `DIVERGENT_USER_ID` | unattended tool execution with service credentials, delegated to that person |
|
|
164
169
|
| `DSH_HOME` | where dsh keeps its files, default `~/.dsh` |
|
|
170
|
+
| `DIVERGE_NO_UPDATE_CHECK` | set to skip the once-a-day check for a newer release |
|
|
165
171
|
|
|
166
172
|
## Security
|
|
167
173
|
|
package/dist/diverge.mjs
CHANGED
|
@@ -114,17 +114,17 @@ var require_visit = __commonJS({
|
|
|
114
114
|
visit.BREAK = BREAK;
|
|
115
115
|
visit.SKIP = SKIP;
|
|
116
116
|
visit.REMOVE = REMOVE;
|
|
117
|
-
function visit_(key, node, visitor,
|
|
118
|
-
const ctrl = callVisitor(key, node, visitor,
|
|
117
|
+
function visit_(key, node, visitor, path12) {
|
|
118
|
+
const ctrl = callVisitor(key, node, visitor, path12);
|
|
119
119
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
120
|
-
replaceNode(key,
|
|
121
|
-
return visit_(key, ctrl, visitor,
|
|
120
|
+
replaceNode(key, path12, ctrl);
|
|
121
|
+
return visit_(key, ctrl, visitor, path12);
|
|
122
122
|
}
|
|
123
123
|
if (typeof ctrl !== "symbol") {
|
|
124
124
|
if (identity.isCollection(node)) {
|
|
125
|
-
|
|
125
|
+
path12 = Object.freeze(path12.concat(node));
|
|
126
126
|
for (let i = 0; i < node.items.length; ++i) {
|
|
127
|
-
const ci = visit_(i, node.items[i], visitor,
|
|
127
|
+
const ci = visit_(i, node.items[i], visitor, path12);
|
|
128
128
|
if (typeof ci === "number")
|
|
129
129
|
i = ci - 1;
|
|
130
130
|
else if (ci === BREAK)
|
|
@@ -135,13 +135,13 @@ var require_visit = __commonJS({
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
} else if (identity.isPair(node)) {
|
|
138
|
-
|
|
139
|
-
const ck = visit_("key", node.key, visitor,
|
|
138
|
+
path12 = Object.freeze(path12.concat(node));
|
|
139
|
+
const ck = visit_("key", node.key, visitor, path12);
|
|
140
140
|
if (ck === BREAK)
|
|
141
141
|
return BREAK;
|
|
142
142
|
else if (ck === REMOVE)
|
|
143
143
|
node.key = null;
|
|
144
|
-
const cv = visit_("value", node.value, visitor,
|
|
144
|
+
const cv = visit_("value", node.value, visitor, path12);
|
|
145
145
|
if (cv === BREAK)
|
|
146
146
|
return BREAK;
|
|
147
147
|
else if (cv === REMOVE)
|
|
@@ -162,17 +162,17 @@ var require_visit = __commonJS({
|
|
|
162
162
|
visitAsync.BREAK = BREAK;
|
|
163
163
|
visitAsync.SKIP = SKIP;
|
|
164
164
|
visitAsync.REMOVE = REMOVE;
|
|
165
|
-
async function visitAsync_(key, node, visitor,
|
|
166
|
-
const ctrl = await callVisitor(key, node, visitor,
|
|
165
|
+
async function visitAsync_(key, node, visitor, path12) {
|
|
166
|
+
const ctrl = await callVisitor(key, node, visitor, path12);
|
|
167
167
|
if (identity.isNode(ctrl) || identity.isPair(ctrl)) {
|
|
168
|
-
replaceNode(key,
|
|
169
|
-
return visitAsync_(key, ctrl, visitor,
|
|
168
|
+
replaceNode(key, path12, ctrl);
|
|
169
|
+
return visitAsync_(key, ctrl, visitor, path12);
|
|
170
170
|
}
|
|
171
171
|
if (typeof ctrl !== "symbol") {
|
|
172
172
|
if (identity.isCollection(node)) {
|
|
173
|
-
|
|
173
|
+
path12 = Object.freeze(path12.concat(node));
|
|
174
174
|
for (let i = 0; i < node.items.length; ++i) {
|
|
175
|
-
const ci = await visitAsync_(i, node.items[i], visitor,
|
|
175
|
+
const ci = await visitAsync_(i, node.items[i], visitor, path12);
|
|
176
176
|
if (typeof ci === "number")
|
|
177
177
|
i = ci - 1;
|
|
178
178
|
else if (ci === BREAK)
|
|
@@ -183,13 +183,13 @@ var require_visit = __commonJS({
|
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
} else if (identity.isPair(node)) {
|
|
186
|
-
|
|
187
|
-
const ck = await visitAsync_("key", node.key, visitor,
|
|
186
|
+
path12 = Object.freeze(path12.concat(node));
|
|
187
|
+
const ck = await visitAsync_("key", node.key, visitor, path12);
|
|
188
188
|
if (ck === BREAK)
|
|
189
189
|
return BREAK;
|
|
190
190
|
else if (ck === REMOVE)
|
|
191
191
|
node.key = null;
|
|
192
|
-
const cv = await visitAsync_("value", node.value, visitor,
|
|
192
|
+
const cv = await visitAsync_("value", node.value, visitor, path12);
|
|
193
193
|
if (cv === BREAK)
|
|
194
194
|
return BREAK;
|
|
195
195
|
else if (cv === REMOVE)
|
|
@@ -216,23 +216,23 @@ var require_visit = __commonJS({
|
|
|
216
216
|
}
|
|
217
217
|
return visitor;
|
|
218
218
|
}
|
|
219
|
-
function callVisitor(key, node, visitor,
|
|
219
|
+
function callVisitor(key, node, visitor, path12) {
|
|
220
220
|
if (typeof visitor === "function")
|
|
221
|
-
return visitor(key, node,
|
|
221
|
+
return visitor(key, node, path12);
|
|
222
222
|
if (identity.isMap(node))
|
|
223
|
-
return visitor.Map?.(key, node,
|
|
223
|
+
return visitor.Map?.(key, node, path12);
|
|
224
224
|
if (identity.isSeq(node))
|
|
225
|
-
return visitor.Seq?.(key, node,
|
|
225
|
+
return visitor.Seq?.(key, node, path12);
|
|
226
226
|
if (identity.isPair(node))
|
|
227
|
-
return visitor.Pair?.(key, node,
|
|
227
|
+
return visitor.Pair?.(key, node, path12);
|
|
228
228
|
if (identity.isScalar(node))
|
|
229
|
-
return visitor.Scalar?.(key, node,
|
|
229
|
+
return visitor.Scalar?.(key, node, path12);
|
|
230
230
|
if (identity.isAlias(node))
|
|
231
|
-
return visitor.Alias?.(key, node,
|
|
231
|
+
return visitor.Alias?.(key, node, path12);
|
|
232
232
|
return void 0;
|
|
233
233
|
}
|
|
234
|
-
function replaceNode(key,
|
|
235
|
-
const parent =
|
|
234
|
+
function replaceNode(key, path12, node) {
|
|
235
|
+
const parent = path12[path12.length - 1];
|
|
236
236
|
if (identity.isCollection(parent)) {
|
|
237
237
|
parent.items[key] = node;
|
|
238
238
|
} else if (identity.isPair(parent)) {
|
|
@@ -842,10 +842,10 @@ var require_Collection = __commonJS({
|
|
|
842
842
|
var createNode = require_createNode();
|
|
843
843
|
var identity = require_identity();
|
|
844
844
|
var Node = require_Node();
|
|
845
|
-
function collectionFromPath(schema,
|
|
845
|
+
function collectionFromPath(schema, path12, value) {
|
|
846
846
|
let v = value;
|
|
847
|
-
for (let i =
|
|
848
|
-
const k =
|
|
847
|
+
for (let i = path12.length - 1; i >= 0; --i) {
|
|
848
|
+
const k = path12[i];
|
|
849
849
|
if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
|
|
850
850
|
const a = [];
|
|
851
851
|
a[k] = v;
|
|
@@ -864,7 +864,7 @@ var require_Collection = __commonJS({
|
|
|
864
864
|
sourceObjects: /* @__PURE__ */ new Map()
|
|
865
865
|
});
|
|
866
866
|
}
|
|
867
|
-
var isEmptyPath = (
|
|
867
|
+
var isEmptyPath = (path12) => path12 == null || typeof path12 === "object" && !!path12[Symbol.iterator]().next().done;
|
|
868
868
|
var Collection = class extends Node.NodeBase {
|
|
869
869
|
constructor(type, schema) {
|
|
870
870
|
super(type);
|
|
@@ -894,11 +894,11 @@ var require_Collection = __commonJS({
|
|
|
894
894
|
* be a Pair instance or a `{ key, value }` object, which may not have a key
|
|
895
895
|
* that already exists in the map.
|
|
896
896
|
*/
|
|
897
|
-
addIn(
|
|
898
|
-
if (isEmptyPath(
|
|
897
|
+
addIn(path12, value) {
|
|
898
|
+
if (isEmptyPath(path12))
|
|
899
899
|
this.add(value);
|
|
900
900
|
else {
|
|
901
|
-
const [key, ...rest] =
|
|
901
|
+
const [key, ...rest] = path12;
|
|
902
902
|
const node = this.get(key, true);
|
|
903
903
|
if (identity.isCollection(node))
|
|
904
904
|
node.addIn(rest, value);
|
|
@@ -912,8 +912,8 @@ var require_Collection = __commonJS({
|
|
|
912
912
|
* Removes a value from the collection.
|
|
913
913
|
* @returns `true` if the item was found and removed.
|
|
914
914
|
*/
|
|
915
|
-
deleteIn(
|
|
916
|
-
const [key, ...rest] =
|
|
915
|
+
deleteIn(path12) {
|
|
916
|
+
const [key, ...rest] = path12;
|
|
917
917
|
if (rest.length === 0)
|
|
918
918
|
return this.delete(key);
|
|
919
919
|
const node = this.get(key, true);
|
|
@@ -927,8 +927,8 @@ var require_Collection = __commonJS({
|
|
|
927
927
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
928
928
|
* `true` (collections are always returned intact).
|
|
929
929
|
*/
|
|
930
|
-
getIn(
|
|
931
|
-
const [key, ...rest] =
|
|
930
|
+
getIn(path12, keepScalar) {
|
|
931
|
+
const [key, ...rest] = path12;
|
|
932
932
|
const node = this.get(key, true);
|
|
933
933
|
if (rest.length === 0)
|
|
934
934
|
return !keepScalar && identity.isScalar(node) ? node.value : node;
|
|
@@ -946,8 +946,8 @@ var require_Collection = __commonJS({
|
|
|
946
946
|
/**
|
|
947
947
|
* Checks if the collection includes a value with the key `key`.
|
|
948
948
|
*/
|
|
949
|
-
hasIn(
|
|
950
|
-
const [key, ...rest] =
|
|
949
|
+
hasIn(path12) {
|
|
950
|
+
const [key, ...rest] = path12;
|
|
951
951
|
if (rest.length === 0)
|
|
952
952
|
return this.has(key);
|
|
953
953
|
const node = this.get(key, true);
|
|
@@ -957,8 +957,8 @@ var require_Collection = __commonJS({
|
|
|
957
957
|
* Sets a value in this collection. For `!!set`, `value` needs to be a
|
|
958
958
|
* boolean to add/remove the item from the set.
|
|
959
959
|
*/
|
|
960
|
-
setIn(
|
|
961
|
-
const [key, ...rest] =
|
|
960
|
+
setIn(path12, value) {
|
|
961
|
+
const [key, ...rest] = path12;
|
|
962
962
|
if (rest.length === 0) {
|
|
963
963
|
this.set(key, value);
|
|
964
964
|
} else {
|
|
@@ -3473,9 +3473,9 @@ var require_Document = __commonJS({
|
|
|
3473
3473
|
this.contents.add(value);
|
|
3474
3474
|
}
|
|
3475
3475
|
/** Adds a value to the document. */
|
|
3476
|
-
addIn(
|
|
3476
|
+
addIn(path12, value) {
|
|
3477
3477
|
if (assertCollection(this.contents))
|
|
3478
|
-
this.contents.addIn(
|
|
3478
|
+
this.contents.addIn(path12, value);
|
|
3479
3479
|
}
|
|
3480
3480
|
/**
|
|
3481
3481
|
* Create a new `Alias` node, ensuring that the target `node` has the required anchor.
|
|
@@ -3550,14 +3550,14 @@ var require_Document = __commonJS({
|
|
|
3550
3550
|
* Removes a value from the document.
|
|
3551
3551
|
* @returns `true` if the item was found and removed.
|
|
3552
3552
|
*/
|
|
3553
|
-
deleteIn(
|
|
3554
|
-
if (Collection.isEmptyPath(
|
|
3553
|
+
deleteIn(path12) {
|
|
3554
|
+
if (Collection.isEmptyPath(path12)) {
|
|
3555
3555
|
if (this.contents == null)
|
|
3556
3556
|
return false;
|
|
3557
3557
|
this.contents = null;
|
|
3558
3558
|
return true;
|
|
3559
3559
|
}
|
|
3560
|
-
return assertCollection(this.contents) ? this.contents.deleteIn(
|
|
3560
|
+
return assertCollection(this.contents) ? this.contents.deleteIn(path12) : false;
|
|
3561
3561
|
}
|
|
3562
3562
|
/**
|
|
3563
3563
|
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
@@ -3572,10 +3572,10 @@ var require_Document = __commonJS({
|
|
|
3572
3572
|
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
3573
3573
|
* `true` (collections are always returned intact).
|
|
3574
3574
|
*/
|
|
3575
|
-
getIn(
|
|
3576
|
-
if (Collection.isEmptyPath(
|
|
3575
|
+
getIn(path12, keepScalar) {
|
|
3576
|
+
if (Collection.isEmptyPath(path12))
|
|
3577
3577
|
return !keepScalar && identity.isScalar(this.contents) ? this.contents.value : this.contents;
|
|
3578
|
-
return identity.isCollection(this.contents) ? this.contents.getIn(
|
|
3578
|
+
return identity.isCollection(this.contents) ? this.contents.getIn(path12, keepScalar) : void 0;
|
|
3579
3579
|
}
|
|
3580
3580
|
/**
|
|
3581
3581
|
* Checks if the document includes a value with the key `key`.
|
|
@@ -3586,10 +3586,10 @@ var require_Document = __commonJS({
|
|
|
3586
3586
|
/**
|
|
3587
3587
|
* Checks if the document includes a value at `path`.
|
|
3588
3588
|
*/
|
|
3589
|
-
hasIn(
|
|
3590
|
-
if (Collection.isEmptyPath(
|
|
3589
|
+
hasIn(path12) {
|
|
3590
|
+
if (Collection.isEmptyPath(path12))
|
|
3591
3591
|
return this.contents !== void 0;
|
|
3592
|
-
return identity.isCollection(this.contents) ? this.contents.hasIn(
|
|
3592
|
+
return identity.isCollection(this.contents) ? this.contents.hasIn(path12) : false;
|
|
3593
3593
|
}
|
|
3594
3594
|
/**
|
|
3595
3595
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
@@ -3606,13 +3606,13 @@ var require_Document = __commonJS({
|
|
|
3606
3606
|
* Sets a value in this document. For `!!set`, `value` needs to be a
|
|
3607
3607
|
* boolean to add/remove the item from the set.
|
|
3608
3608
|
*/
|
|
3609
|
-
setIn(
|
|
3610
|
-
if (Collection.isEmptyPath(
|
|
3609
|
+
setIn(path12, value) {
|
|
3610
|
+
if (Collection.isEmptyPath(path12)) {
|
|
3611
3611
|
this.contents = value;
|
|
3612
3612
|
} else if (this.contents == null) {
|
|
3613
|
-
this.contents = Collection.collectionFromPath(this.schema, Array.from(
|
|
3613
|
+
this.contents = Collection.collectionFromPath(this.schema, Array.from(path12), value);
|
|
3614
3614
|
} else if (assertCollection(this.contents)) {
|
|
3615
|
-
this.contents.setIn(
|
|
3615
|
+
this.contents.setIn(path12, value);
|
|
3616
3616
|
}
|
|
3617
3617
|
}
|
|
3618
3618
|
/**
|
|
@@ -5572,9 +5572,9 @@ var require_cst_visit = __commonJS({
|
|
|
5572
5572
|
visit.BREAK = BREAK;
|
|
5573
5573
|
visit.SKIP = SKIP;
|
|
5574
5574
|
visit.REMOVE = REMOVE;
|
|
5575
|
-
visit.itemAtPath = (cst,
|
|
5575
|
+
visit.itemAtPath = (cst, path12) => {
|
|
5576
5576
|
let item = cst;
|
|
5577
|
-
for (const [field, index] of
|
|
5577
|
+
for (const [field, index] of path12) {
|
|
5578
5578
|
const tok = item?.[field];
|
|
5579
5579
|
if (tok && "items" in tok) {
|
|
5580
5580
|
item = tok.items[index];
|
|
@@ -5583,23 +5583,23 @@ var require_cst_visit = __commonJS({
|
|
|
5583
5583
|
}
|
|
5584
5584
|
return item;
|
|
5585
5585
|
};
|
|
5586
|
-
visit.parentCollection = (cst,
|
|
5587
|
-
const parent = visit.itemAtPath(cst,
|
|
5588
|
-
const field =
|
|
5586
|
+
visit.parentCollection = (cst, path12) => {
|
|
5587
|
+
const parent = visit.itemAtPath(cst, path12.slice(0, -1));
|
|
5588
|
+
const field = path12[path12.length - 1][0];
|
|
5589
5589
|
const coll = parent?.[field];
|
|
5590
5590
|
if (coll && "items" in coll)
|
|
5591
5591
|
return coll;
|
|
5592
5592
|
throw new Error("Parent collection not found");
|
|
5593
5593
|
};
|
|
5594
|
-
function _visit(
|
|
5595
|
-
let ctrl = visitor(item,
|
|
5594
|
+
function _visit(path12, item, visitor) {
|
|
5595
|
+
let ctrl = visitor(item, path12);
|
|
5596
5596
|
if (typeof ctrl === "symbol")
|
|
5597
5597
|
return ctrl;
|
|
5598
5598
|
for (const field of ["key", "value"]) {
|
|
5599
5599
|
const token = item[field];
|
|
5600
5600
|
if (token && "items" in token) {
|
|
5601
5601
|
for (let i = 0; i < token.items.length; ++i) {
|
|
5602
|
-
const ci = _visit(Object.freeze(
|
|
5602
|
+
const ci = _visit(Object.freeze(path12.concat([[field, i]])), token.items[i], visitor);
|
|
5603
5603
|
if (typeof ci === "number")
|
|
5604
5604
|
i = ci - 1;
|
|
5605
5605
|
else if (ci === BREAK)
|
|
@@ -5610,10 +5610,10 @@ var require_cst_visit = __commonJS({
|
|
|
5610
5610
|
}
|
|
5611
5611
|
}
|
|
5612
5612
|
if (typeof ctrl === "function" && field === "key")
|
|
5613
|
-
ctrl = ctrl(item,
|
|
5613
|
+
ctrl = ctrl(item, path12);
|
|
5614
5614
|
}
|
|
5615
5615
|
}
|
|
5616
|
-
return typeof ctrl === "function" ? ctrl(item,
|
|
5616
|
+
return typeof ctrl === "function" ? ctrl(item, path12) : ctrl;
|
|
5617
5617
|
}
|
|
5618
5618
|
exports.visit = visit;
|
|
5619
5619
|
}
|
|
@@ -6915,14 +6915,14 @@ var require_parser = __commonJS({
|
|
|
6915
6915
|
case "scalar":
|
|
6916
6916
|
case "single-quoted-scalar":
|
|
6917
6917
|
case "double-quoted-scalar": {
|
|
6918
|
-
const
|
|
6918
|
+
const fs10 = this.flowScalar(this.type);
|
|
6919
6919
|
if (atNextItem || it.value) {
|
|
6920
|
-
map.items.push({ start, key:
|
|
6920
|
+
map.items.push({ start, key: fs10, sep: [] });
|
|
6921
6921
|
this.onKeyLine = true;
|
|
6922
6922
|
} else if (it.sep) {
|
|
6923
|
-
this.stack.push(
|
|
6923
|
+
this.stack.push(fs10);
|
|
6924
6924
|
} else {
|
|
6925
|
-
Object.assign(it, { key:
|
|
6925
|
+
Object.assign(it, { key: fs10, sep: [] });
|
|
6926
6926
|
this.onKeyLine = true;
|
|
6927
6927
|
}
|
|
6928
6928
|
return;
|
|
@@ -7050,13 +7050,13 @@ var require_parser = __commonJS({
|
|
|
7050
7050
|
case "scalar":
|
|
7051
7051
|
case "single-quoted-scalar":
|
|
7052
7052
|
case "double-quoted-scalar": {
|
|
7053
|
-
const
|
|
7053
|
+
const fs10 = this.flowScalar(this.type);
|
|
7054
7054
|
if (!it || it.value)
|
|
7055
|
-
fc.items.push({ start: [], key:
|
|
7055
|
+
fc.items.push({ start: [], key: fs10, sep: [] });
|
|
7056
7056
|
else if (it.sep)
|
|
7057
|
-
this.stack.push(
|
|
7057
|
+
this.stack.push(fs10);
|
|
7058
7058
|
else
|
|
7059
|
-
Object.assign(it, { key:
|
|
7059
|
+
Object.assign(it, { key: fs10, sep: [] });
|
|
7060
7060
|
return;
|
|
7061
7061
|
}
|
|
7062
7062
|
case "flow-map-end":
|
|
@@ -7387,7 +7387,7 @@ import path10 from "node:path";
|
|
|
7387
7387
|
import { parseArgs } from "node:util";
|
|
7388
7388
|
|
|
7389
7389
|
// src/version.ts
|
|
7390
|
-
var VERSION = true ? "0.1.
|
|
7390
|
+
var VERSION = true ? "0.1.11" : "dev";
|
|
7391
7391
|
var USER_AGENT = `diverge/${VERSION}`;
|
|
7392
7392
|
|
|
7393
7393
|
// src/http.ts
|
|
@@ -8891,10 +8891,10 @@ var ToolsClient = class {
|
|
|
8891
8891
|
if (this.settings.mode === "service") headers["x-divergent-user-id"] = this.settings.delegatedUserId;
|
|
8892
8892
|
return headers;
|
|
8893
8893
|
}
|
|
8894
|
-
scoped(
|
|
8894
|
+
scoped(path12) {
|
|
8895
8895
|
const query = new URLSearchParams({ organizationId: this.settings.organizationId });
|
|
8896
8896
|
if (this.settings.projectId) query.set("projectId", this.settings.projectId);
|
|
8897
|
-
return `${this.settings.apiUrl}${
|
|
8897
|
+
return `${this.settings.apiUrl}${path12}?${query.toString()}`;
|
|
8898
8898
|
}
|
|
8899
8899
|
async send(method, url, body) {
|
|
8900
8900
|
return this.request(method, url, body, void 0);
|
|
@@ -9501,7 +9501,57 @@ ${pluginsUsage}`);
|
|
|
9501
9501
|
}
|
|
9502
9502
|
|
|
9503
9503
|
// src/commands/update.ts
|
|
9504
|
+
import { spawn as spawn4 } from "node:child_process";
|
|
9505
|
+
|
|
9506
|
+
// src/update-notice.ts
|
|
9504
9507
|
import { spawn as spawn3 } from "node:child_process";
|
|
9508
|
+
import fs9 from "node:fs";
|
|
9509
|
+
import path11 from "node:path";
|
|
9510
|
+
var UPDATE_CHECK_FILE = "update-check.json";
|
|
9511
|
+
var UPDATE_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
9512
|
+
function updateCheckFile(env) {
|
|
9513
|
+
return path11.join(configDir(env), UPDATE_CHECK_FILE);
|
|
9514
|
+
}
|
|
9515
|
+
function readUpdateCheck(env) {
|
|
9516
|
+
try {
|
|
9517
|
+
const parsed = JSON.parse(fs9.readFileSync(updateCheckFile(env), "utf8"));
|
|
9518
|
+
if (parsed && typeof parsed === "object" && typeof parsed.checkedAt === "number" && typeof parsed.latest === "string") return parsed;
|
|
9519
|
+
} catch {
|
|
9520
|
+
}
|
|
9521
|
+
return null;
|
|
9522
|
+
}
|
|
9523
|
+
function writeUpdateCheck(env, check) {
|
|
9524
|
+
writeJsonAtomic(updateCheckFile(env), check);
|
|
9525
|
+
}
|
|
9526
|
+
function noticeFor(check, version = VERSION) {
|
|
9527
|
+
if (!check || !isNewer(check.latest, version)) return null;
|
|
9528
|
+
return `diverge ${check.latest} is available (this is ${version}). Update with: diverge update (or run npx @divergeai/cli@latest)`;
|
|
9529
|
+
}
|
|
9530
|
+
function noticeApplies(argv, io, version = VERSION) {
|
|
9531
|
+
if (version === "dev" || !io.interactive) return false;
|
|
9532
|
+
if (io.env.DIVERGE_NO_UPDATE_CHECK?.trim() || io.env.CI?.trim()) return false;
|
|
9533
|
+
if (argv[0] === "update") return false;
|
|
9534
|
+
if (argv[0] === "tools" && argv[1] === "bridge") return false;
|
|
9535
|
+
return true;
|
|
9536
|
+
}
|
|
9537
|
+
function scheduleUpdateCheck(spawnImpl = spawn3) {
|
|
9538
|
+
try {
|
|
9539
|
+
const child = spawnImpl(process.execPath, [process.argv[1], "update", "--record"], { detached: true, stdio: "ignore" });
|
|
9540
|
+
child.on("error", () => {
|
|
9541
|
+
});
|
|
9542
|
+
child.unref();
|
|
9543
|
+
} catch {
|
|
9544
|
+
}
|
|
9545
|
+
}
|
|
9546
|
+
function updateNotice(argv, io, deps = { now: Date.now, schedule: scheduleUpdateCheck, read: readUpdateCheck, version: VERSION }) {
|
|
9547
|
+
if (!noticeApplies(argv, io, deps.version)) return;
|
|
9548
|
+
const check = deps.read(io.env);
|
|
9549
|
+
const notice = noticeFor(check, deps.version);
|
|
9550
|
+
if (notice) io.stderr(notice);
|
|
9551
|
+
if (!check || deps.now() - check.checkedAt > UPDATE_CHECK_INTERVAL_MS) deps.schedule();
|
|
9552
|
+
}
|
|
9553
|
+
|
|
9554
|
+
// src/commands/update.ts
|
|
9505
9555
|
var PACKAGE_NAME = "@divergeai/cli";
|
|
9506
9556
|
var updateUsage = "diverge update\n\nInstall the latest release with the npm that installed this one.";
|
|
9507
9557
|
async function latestVersion(registry = "https://registry.npmjs.org") {
|
|
@@ -9526,7 +9576,14 @@ function isNewer(a, b) {
|
|
|
9526
9576
|
if (!y.pre) return false;
|
|
9527
9577
|
return x.pre > y.pre;
|
|
9528
9578
|
}
|
|
9529
|
-
async function runUpdate(
|
|
9579
|
+
async function runUpdate(args, io, deps = { latestVersion, install: installLatest, record: writeUpdateCheck, now: Date.now }) {
|
|
9580
|
+
if (args[0] === "--record") {
|
|
9581
|
+
try {
|
|
9582
|
+
deps.record(io.env, { checkedAt: deps.now(), latest: await deps.latestVersion() });
|
|
9583
|
+
} catch {
|
|
9584
|
+
}
|
|
9585
|
+
return ExitCode.Ok;
|
|
9586
|
+
}
|
|
9530
9587
|
if (VERSION === "dev") throw new CliError("This is a source checkout, not an installed release; pull the repository instead.");
|
|
9531
9588
|
const latest = await deps.latestVersion();
|
|
9532
9589
|
if (!isNewer(latest, VERSION)) {
|
|
@@ -9542,7 +9599,7 @@ async function runUpdate(_args, io, deps = { latestVersion, install: installLate
|
|
|
9542
9599
|
function installLatest(version) {
|
|
9543
9600
|
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
9544
9601
|
return new Promise((resolve, reject) => {
|
|
9545
|
-
const child =
|
|
9602
|
+
const child = spawn4(npm, ["install", "-g", `${PACKAGE_NAME}@${version}`], { stdio: "inherit" });
|
|
9546
9603
|
child.on("error", reject);
|
|
9547
9604
|
child.on("exit", (code2) => resolve(code2 ?? 1));
|
|
9548
9605
|
});
|
|
@@ -9597,6 +9654,11 @@ ${usage()}`);
|
|
|
9597
9654
|
io.stdout(command.usage);
|
|
9598
9655
|
return ExitCode.Ok;
|
|
9599
9656
|
}
|
|
9657
|
+
const code2 = await runCommand(command, rest, io);
|
|
9658
|
+
updateNotice(argv, io);
|
|
9659
|
+
return code2;
|
|
9660
|
+
}
|
|
9661
|
+
async function runCommand(command, rest, io) {
|
|
9600
9662
|
try {
|
|
9601
9663
|
return await command.run(rest, io);
|
|
9602
9664
|
} catch (error) {
|
package/package.json
CHANGED