@psnext/slingcli 2.5.20260723-1 → 2.5.20260724-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/sling.js +2 -0
- package/node_modules/@aws-sdk/credential-provider-http/node_modules/@smithy/node-http-handler/package.json +2 -2
- package/node_modules/@aws-sdk/nested-clients/node_modules/@smithy/node-http-handler/package.json +2 -2
- package/node_modules/@smithy/core/dist-cjs/submodules/cbor/index.js +1 -1
- package/node_modules/@smithy/core/dist-es/submodules/cbor/cbor-decode.js +1 -1
- package/node_modules/@smithy/core/package.json +1 -1
- package/node_modules/@smithy/credential-provider-imds/package.json +2 -2
- package/node_modules/@smithy/fetch-http-handler/package.json +2 -2
- package/node_modules/@smithy/signature-v4/package.json +2 -2
- package/node_modules/brace-expansion/README.md +12 -0
- package/node_modules/brace-expansion/dist/commonjs/index.d.ts +2 -0
- package/node_modules/brace-expansion/dist/commonjs/index.d.ts.map +1 -1
- package/node_modules/brace-expansion/dist/commonjs/index.js +138 -86
- package/node_modules/brace-expansion/dist/commonjs/index.js.map +1 -1
- package/node_modules/brace-expansion/dist/esm/index.d.ts +2 -0
- package/node_modules/brace-expansion/dist/esm/index.d.ts.map +1 -1
- package/node_modules/brace-expansion/dist/esm/index.js +137 -85
- package/node_modules/brace-expansion/dist/esm/index.js.map +1 -1
- package/node_modules/brace-expansion/package.json +2 -2
- package/package.json +2 -2
- package/slingshot/index.js +1 -1
package/bin/sling.js
CHANGED
|
@@ -50,6 +50,8 @@ function findSlingPkg() {
|
|
|
50
50
|
}
|
|
51
51
|
const { slingVersion: SLING_VERSION } = findSlingPkg();
|
|
52
52
|
process.env.SLING_VERSION = SLING_VERSION;
|
|
53
|
+
process.env.PI_SUBAGENT_PI_BINARY_ENV = "sling";
|
|
54
|
+
// if (IS_DEV) process.env.PI_SUBAGENT_PI_BINARY_ENV = "node " + process.argv[1];
|
|
53
55
|
const { main } = IS_DEV
|
|
54
56
|
? await import(path.resolve(__dirname, "packages/coding-agent/src/main.ts"))
|
|
55
57
|
: await import("@earendil-works/pi-coding-agent");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/node-http-handler",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.10",
|
|
4
4
|
"description": "Provides a way to make requests",
|
|
5
5
|
"homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/node-http-handler",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"test:watch": "yarn g:vitest watch"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@smithy/core": "^3.29.
|
|
46
|
+
"@smithy/core": "^3.29.8",
|
|
47
47
|
"@smithy/types": "^4.16.1",
|
|
48
48
|
"tslib": "^2.6.2"
|
|
49
49
|
},
|
package/node_modules/@aws-sdk/nested-clients/node_modules/@smithy/node-http-handler/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/node-http-handler",
|
|
3
|
-
"version": "4.9.
|
|
3
|
+
"version": "4.9.10",
|
|
4
4
|
"description": "Provides a way to make requests",
|
|
5
5
|
"homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/node-http-handler",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"test:watch": "yarn g:vitest watch"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@smithy/core": "^3.29.
|
|
46
|
+
"@smithy/core": "^3.29.8",
|
|
47
47
|
"@smithy/types": "^4.16.1",
|
|
48
48
|
"tslib": "^2.6.2"
|
|
49
49
|
},
|
|
@@ -169,7 +169,7 @@ function bytesToFloat16(a, b) {
|
|
|
169
169
|
}
|
|
170
170
|
function decodeMap(at, to) {
|
|
171
171
|
const mapDataLength = decodeCount(at, to);
|
|
172
|
-
if (mapDataLength <
|
|
172
|
+
if (mapDataLength < 25) {
|
|
173
173
|
return decodeMapSmall(at, to, mapDataLength);
|
|
174
174
|
}
|
|
175
175
|
return decodeMapLarge(at, to, mapDataLength);
|
|
@@ -141,7 +141,7 @@ export function bytesToFloat16(a, b) {
|
|
|
141
141
|
}
|
|
142
142
|
function decodeMap(at, to) {
|
|
143
143
|
const mapDataLength = decodeCount(at, to);
|
|
144
|
-
if (mapDataLength <
|
|
144
|
+
if (mapDataLength < 25) {
|
|
145
145
|
return decodeMapSmall(at, to, mapDataLength);
|
|
146
146
|
}
|
|
147
147
|
return decodeMapLarge(at, to, mapDataLength);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/credential-provider-imds",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.13",
|
|
4
4
|
"description": "AWS credential provider that sources credentials from the EC2 instance metadata service and ECS container metadata service",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aws",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"test:watch": "yarn g:vitest watch"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@smithy/core": "^3.29.
|
|
48
|
+
"@smithy/core": "^3.29.8",
|
|
49
49
|
"@smithy/types": "^4.16.1",
|
|
50
50
|
"tslib": "^2.6.2"
|
|
51
51
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/fetch-http-handler",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.10",
|
|
4
4
|
"description": "Provides a way to make requests",
|
|
5
5
|
"homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/fetch-http-handler",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"test:browser:watch": "yarn g:vitest watch -c vitest.config.browser.mts"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@smithy/core": "^3.29.
|
|
47
|
+
"@smithy/core": "^3.29.8",
|
|
48
48
|
"@smithy/types": "^4.16.1",
|
|
49
49
|
"tslib": "^2.6.2"
|
|
50
50
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/signature-v4",
|
|
3
|
-
"version": "5.6.
|
|
3
|
+
"version": "5.6.9",
|
|
4
4
|
"description": "A standalone implementation of the AWS Signature V4 request signing algorithm",
|
|
5
5
|
"homepage": "https://github.com/smithy-lang/smithy-typescript/tree/main/packages/signature-v4",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"test:watch": "yarn g:vitest watch"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@smithy/core": "^3.29.
|
|
45
|
+
"@smithy/core": "^3.29.8",
|
|
46
46
|
"@smithy/types": "^4.16.1",
|
|
47
47
|
"tslib": "^2.6.2"
|
|
48
48
|
},
|
|
@@ -64,6 +64,18 @@ const expansions = expand('{1..100}'.repeat(5), {
|
|
|
64
64
|
// expansions.length will be 100, not 100^5
|
|
65
65
|
```
|
|
66
66
|
|
|
67
|
+
The `options` object can also provide a `maxLength` value to cap the
|
|
68
|
+
total number of characters across all expansions. This is limited to
|
|
69
|
+
`4_000_000` by default, to prevent memory exhaustion from inputs whose
|
|
70
|
+
result count stays under `max` while each result grows very long.
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
const expansions = expand('{a,b}'.repeat(1500), {
|
|
74
|
+
maxLength: 100,
|
|
75
|
+
})
|
|
76
|
+
// the combined length of expansions will not exceed 100 characters
|
|
77
|
+
```
|
|
78
|
+
|
|
67
79
|
Valid expansions are:
|
|
68
80
|
|
|
69
81
|
```js
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const EXPANSION_MAX = 100000;
|
|
2
|
+
export declare const EXPANSION_MAX_LENGTH = 4000000;
|
|
2
3
|
export type BraceExpansionOptions = {
|
|
3
4
|
max?: number;
|
|
5
|
+
maxLength?: number;
|
|
4
6
|
};
|
|
5
7
|
export declare function expand(str: string, options?: BraceExpansionOptions): string[];
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,aAAa,SAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,aAAa,SAAU,CAAA;AAYpC,eAAO,MAAM,oBAAoB,UAAY,CAAA;AAwD7C,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,YAkBtE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EXPANSION_MAX = void 0;
|
|
3
|
+
exports.EXPANSION_MAX_LENGTH = exports.EXPANSION_MAX = void 0;
|
|
4
4
|
exports.expand = expand;
|
|
5
5
|
const balanced_match_1 = require("balanced-match");
|
|
6
6
|
const escSlash = '\0SLASH' + Math.random() + '\0';
|
|
@@ -19,6 +19,17 @@ const closePattern = /\\}/g;
|
|
|
19
19
|
const commaPattern = /\\,/g;
|
|
20
20
|
const periodPattern = /\\\./g;
|
|
21
21
|
exports.EXPANSION_MAX = 100_000;
|
|
22
|
+
// `EXPANSION_MAX` caps the *number* of expansions, but not their length. An
|
|
23
|
+
// input like `'{a,b}'.repeat(1500)` stays under that count - its output is
|
|
24
|
+
// truncated to 100k results - while making every result ~1500 characters
|
|
25
|
+
// long. The result set, and the intermediate arrays built while combining
|
|
26
|
+
// brace sets, then grow large enough to exhaust memory and crash the process
|
|
27
|
+
// (CVE-2026-14257). `EXPANSION_MAX_LENGTH` bounds the total number of
|
|
28
|
+
// characters the accumulator may hold at any point, so memory stays flat no
|
|
29
|
+
// matter how many brace groups are chained. The limit sits well above any
|
|
30
|
+
// realistic expansion (100k results hitting `EXPANSION_MAX` measure ~1M
|
|
31
|
+
// characters) so legitimate input is unaffected.
|
|
32
|
+
exports.EXPANSION_MAX_LENGTH = 4_000_000;
|
|
22
33
|
function numeric(str) {
|
|
23
34
|
return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
|
|
24
35
|
}
|
|
@@ -68,7 +79,7 @@ function expand(str, options = {}) {
|
|
|
68
79
|
if (!str) {
|
|
69
80
|
return [];
|
|
70
81
|
}
|
|
71
|
-
const { max = exports.EXPANSION_MAX } = options;
|
|
82
|
+
const { max = exports.EXPANSION_MAX, maxLength = exports.EXPANSION_MAX_LENGTH } = options;
|
|
72
83
|
// I don't know why Bash 4.3 does this, but it does.
|
|
73
84
|
// Anything starting with {} will have the first two bytes preserved
|
|
74
85
|
// but *only* at the top level, so {},a}b will not expand to anything,
|
|
@@ -78,7 +89,7 @@ function expand(str, options = {}) {
|
|
|
78
89
|
if (str.slice(0, 2) === '{}') {
|
|
79
90
|
str = '\\{\\}' + str.slice(2);
|
|
80
91
|
}
|
|
81
|
-
return expand_(escapeBraces(str), max, true).map(unescapeBraces);
|
|
92
|
+
return expand_(escapeBraces(str), max, maxLength, true).map(unescapeBraces);
|
|
82
93
|
}
|
|
83
94
|
function embrace(str) {
|
|
84
95
|
return '{' + str + '}';
|
|
@@ -92,25 +103,112 @@ function lte(i, y) {
|
|
|
92
103
|
function gte(i, y) {
|
|
93
104
|
return i >= y;
|
|
94
105
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
// Build `{ acc[a] + pre + values[v] }` for every combination, capping the
|
|
107
|
+
// number of results at `max` and the total number of characters at `maxLength`.
|
|
108
|
+
// This is the one place output grows, so bounding it here keeps the single
|
|
109
|
+
// accumulator - and therefore memory - flat regardless of how many brace groups
|
|
110
|
+
// are combined (CVE-2026-14257).
|
|
111
|
+
function combine(acc, pre, values, max, maxLength, dropEmpties) {
|
|
112
|
+
const out = [];
|
|
113
|
+
let length = 0;
|
|
114
|
+
for (let a = 0; a < acc.length; a++) {
|
|
115
|
+
for (let v = 0; v < values.length; v++) {
|
|
116
|
+
if (out.length >= max)
|
|
117
|
+
return out;
|
|
118
|
+
const expansion = acc[a] + pre + values[v];
|
|
119
|
+
// Bash drops empty results at the top level. Skip them before they count
|
|
120
|
+
// against `max`, so `max` bounds the number of *kept* results.
|
|
121
|
+
if (dropEmpties && !expansion)
|
|
122
|
+
continue;
|
|
123
|
+
if (length + expansion.length > maxLength)
|
|
124
|
+
return out;
|
|
125
|
+
out.push(expansion);
|
|
126
|
+
length += expansion.length;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return out;
|
|
130
|
+
}
|
|
131
|
+
// The expansion values of a single numeric (`1..5`) or alphabetic (`a..e..2`)
|
|
132
|
+
// sequence body.
|
|
133
|
+
function expandSequence(body, isAlphaSequence, max) {
|
|
134
|
+
const n = body.split(/\.\./);
|
|
135
|
+
const N = [];
|
|
136
|
+
// A sequence body always splits into two or three parts, but the compiler
|
|
137
|
+
// can't know that.
|
|
138
|
+
/* c8 ignore start */
|
|
139
|
+
if (n[0] === undefined || n[1] === undefined) {
|
|
140
|
+
return N;
|
|
141
|
+
}
|
|
142
|
+
/* c8 ignore stop */
|
|
143
|
+
const x = numeric(n[0]);
|
|
144
|
+
const y = numeric(n[1]);
|
|
145
|
+
const width = Math.max(n[0].length, n[1].length);
|
|
146
|
+
let incr = n.length === 3 && n[2] !== undefined ?
|
|
147
|
+
Math.max(Math.abs(numeric(n[2])), 1)
|
|
148
|
+
: 1;
|
|
149
|
+
let test = lte;
|
|
150
|
+
const reverse = y < x;
|
|
151
|
+
if (reverse) {
|
|
152
|
+
incr *= -1;
|
|
153
|
+
test = gte;
|
|
154
|
+
}
|
|
155
|
+
const pad = n.some(isPadded);
|
|
156
|
+
for (let i = x; test(i, y) && N.length < max; i += incr) {
|
|
157
|
+
let c;
|
|
158
|
+
if (isAlphaSequence) {
|
|
159
|
+
c = String.fromCharCode(i);
|
|
160
|
+
if (c === '\\') {
|
|
161
|
+
c = '';
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
c = String(i);
|
|
166
|
+
if (pad) {
|
|
167
|
+
const need = width - c.length;
|
|
168
|
+
if (need > 0) {
|
|
169
|
+
const z = new Array(need + 1).join('0');
|
|
170
|
+
if (i < 0) {
|
|
171
|
+
c = '-' + z + c.slice(1);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
c = z + c;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
N.push(c);
|
|
180
|
+
}
|
|
181
|
+
return N;
|
|
182
|
+
}
|
|
183
|
+
function expand_(str, max, maxLength, isTop) {
|
|
184
|
+
// Consume the string's top-level brace groups left to right, threading a
|
|
185
|
+
// running set of combined prefixes (`acc`). Expanding the tail iteratively -
|
|
186
|
+
// rather than recursing on `m.post` once per group - keeps the native stack
|
|
187
|
+
// depth constant, so deeply chained input (`'{a,b}'.repeat(3000)`) can no
|
|
188
|
+
// longer overflow the stack, and leaves a single accumulator whose size
|
|
189
|
+
// `maxLength` bounds directly (CVE-2026-14257).
|
|
190
|
+
let acc = [''];
|
|
191
|
+
// Bash drops empty results, but only when the *first* top-level group is a
|
|
192
|
+
// comma set - a sequence like `{a..\}` may legitimately yield ''. The drop
|
|
193
|
+
// is on the final strings, so it is applied to whichever `combine` produces
|
|
194
|
+
// them (the one with no brace set left in the tail).
|
|
195
|
+
let dropEmpties = false;
|
|
196
|
+
let firstGroup = true;
|
|
101
197
|
for (;;) {
|
|
102
198
|
const m = (0, balanced_match_1.balanced)('{', '}', str);
|
|
103
|
-
|
|
104
|
-
|
|
199
|
+
// No brace set left: the rest of the string is literal.
|
|
200
|
+
if (!m) {
|
|
201
|
+
return combine(acc, str, [''], max, maxLength, dropEmpties);
|
|
202
|
+
}
|
|
105
203
|
// no need to expand pre, since it is guaranteed to be free of brace-sets
|
|
106
204
|
const pre = m.pre;
|
|
107
|
-
if (/\$$/.test(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
205
|
+
if (/\$$/.test(pre)) {
|
|
206
|
+
acc = combine(acc, pre + '{' + m.body + '}', [''], max, maxLength, dropEmpties && !m.post.length);
|
|
207
|
+
firstGroup = false;
|
|
208
|
+
if (!m.post.length)
|
|
209
|
+
break;
|
|
210
|
+
str = m.post;
|
|
211
|
+
continue;
|
|
114
212
|
}
|
|
115
213
|
const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
116
214
|
const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
@@ -123,89 +221,43 @@ function expand_(str, max, isTop) {
|
|
|
123
221
|
isTop = true;
|
|
124
222
|
continue;
|
|
125
223
|
}
|
|
126
|
-
|
|
224
|
+
// Nothing here expands, so the whole remaining string is literal.
|
|
225
|
+
return combine(acc, pre + '{' + m.body + '}' + m.post, [''], max, maxLength, dropEmpties);
|
|
127
226
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
let n;
|
|
227
|
+
if (firstGroup) {
|
|
228
|
+
dropEmpties = isTop && !isSequence;
|
|
229
|
+
firstGroup = false;
|
|
230
|
+
}
|
|
231
|
+
let values;
|
|
134
232
|
if (isSequence) {
|
|
135
|
-
|
|
233
|
+
values = expandSequence(m.body, isAlphaSequence, max);
|
|
136
234
|
}
|
|
137
235
|
else {
|
|
138
|
-
n = parseCommaParts(m.body);
|
|
236
|
+
let n = parseCommaParts(m.body);
|
|
139
237
|
if (n.length === 1 && n[0] !== undefined) {
|
|
140
238
|
// x{{a,b}}y ==> x{a}y x{b}y
|
|
141
|
-
n = expand_(n[0], max, false).map(embrace);
|
|
239
|
+
n = expand_(n[0], max, maxLength, false).map(embrace);
|
|
142
240
|
//XXX is this necessary? Can't seem to hit it in tests.
|
|
143
241
|
/* c8 ignore start */
|
|
144
242
|
if (n.length === 1) {
|
|
145
|
-
|
|
243
|
+
acc = combine(acc, pre + n[0], [''], max, maxLength, dropEmpties && !m.post.length);
|
|
244
|
+
if (!m.post.length)
|
|
245
|
+
break;
|
|
246
|
+
str = m.post;
|
|
247
|
+
continue;
|
|
146
248
|
}
|
|
147
249
|
/* c8 ignore stop */
|
|
148
250
|
}
|
|
149
|
-
|
|
150
|
-
// at this point, n is the parts, and we know it's not a comma set
|
|
151
|
-
// with a single entry.
|
|
152
|
-
let N;
|
|
153
|
-
if (isSequence && n[0] !== undefined && n[1] !== undefined) {
|
|
154
|
-
const x = numeric(n[0]);
|
|
155
|
-
const y = numeric(n[1]);
|
|
156
|
-
const width = Math.max(n[0].length, n[1].length);
|
|
157
|
-
let incr = n.length === 3 && n[2] !== undefined ?
|
|
158
|
-
Math.max(Math.abs(numeric(n[2])), 1)
|
|
159
|
-
: 1;
|
|
160
|
-
let test = lte;
|
|
161
|
-
const reverse = y < x;
|
|
162
|
-
if (reverse) {
|
|
163
|
-
incr *= -1;
|
|
164
|
-
test = gte;
|
|
165
|
-
}
|
|
166
|
-
const pad = n.some(isPadded);
|
|
167
|
-
N = [];
|
|
168
|
-
for (let i = x; test(i, y) && N.length < max; i += incr) {
|
|
169
|
-
let c;
|
|
170
|
-
if (isAlphaSequence) {
|
|
171
|
-
c = String.fromCharCode(i);
|
|
172
|
-
if (c === '\\') {
|
|
173
|
-
c = '';
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
c = String(i);
|
|
178
|
-
if (pad) {
|
|
179
|
-
const need = width - c.length;
|
|
180
|
-
if (need > 0) {
|
|
181
|
-
const z = new Array(need + 1).join('0');
|
|
182
|
-
if (i < 0) {
|
|
183
|
-
c = '-' + z + c.slice(1);
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
c = z + c;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
N.push(c);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
else {
|
|
195
|
-
N = [];
|
|
251
|
+
values = [];
|
|
196
252
|
for (let j = 0; j < n.length; j++) {
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
for (let j = 0; j < N.length; j++) {
|
|
201
|
-
for (let k = 0; k < post.length && expansions.length < max; k++) {
|
|
202
|
-
const expansion = pre + N[j] + post[k];
|
|
203
|
-
if (!isTop || isSequence || expansion) {
|
|
204
|
-
expansions.push(expansion);
|
|
205
|
-
}
|
|
253
|
+
values.push.apply(values, expand_(n[j], max, maxLength, false));
|
|
206
254
|
}
|
|
207
255
|
}
|
|
208
|
-
|
|
256
|
+
acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length);
|
|
257
|
+
if (!m.post.length)
|
|
258
|
+
break;
|
|
259
|
+
str = m.post;
|
|
209
260
|
}
|
|
261
|
+
return acc;
|
|
210
262
|
}
|
|
211
263
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AA8EA,wBAkBC;AAhGD,mDAAyC;AAEzC,MAAM,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AACjD,MAAM,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AAC/C,MAAM,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM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,CAAC,CAAC,CAAA;gBACtC,IAAI,CAAC,KAAK,IAAI,UAAU,IAAI,SAAS,EAAE,CAAC;oBACtC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;gBAC5B,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { balanced } from 'balanced-match'\n\nconst escSlash = '\\0SLASH' + Math.random() + '\\0'\nconst escOpen = '\\0OPEN' + Math.random() + '\\0'\nconst escClose = '\\0CLOSE' + Math.random() + '\\0'\nconst escComma = '\\0COMMA' + Math.random() + '\\0'\nconst escPeriod = '\\0PERIOD' + Math.random() + '\\0'\nconst escSlashPattern = new RegExp(escSlash, 'g')\nconst escOpenPattern = new RegExp(escOpen, 'g')\nconst escClosePattern = new RegExp(escClose, 'g')\nconst escCommaPattern = new RegExp(escComma, 'g')\nconst escPeriodPattern = new RegExp(escPeriod, 'g')\nconst slashPattern = /\\\\\\\\/g\nconst openPattern = /\\\\{/g\nconst closePattern = /\\\\}/g\nconst commaPattern = /\\\\,/g\nconst periodPattern = /\\\\\\./g\n\nexport const EXPANSION_MAX = 100_000\n\nfunction numeric(str: string) {\n return !isNaN(str as any) ? parseInt(str, 10) : str.charCodeAt(0)\n}\n\nfunction escapeBraces(str: string) {\n return str\n .replace(slashPattern, escSlash)\n .replace(openPattern, escOpen)\n .replace(closePattern, escClose)\n .replace(commaPattern, escComma)\n .replace(periodPattern, escPeriod)\n}\n\nfunction unescapeBraces(str: string) {\n return str\n .replace(escSlashPattern, '\\\\')\n .replace(escOpenPattern, '{')\n .replace(escClosePattern, '}')\n .replace(escCommaPattern, ',')\n .replace(escPeriodPattern, '.')\n}\n\n/**\n * Basically just str.split(\",\"), but handling cases\n * where we have nested braced sections, which should be\n * treated as individual members, like {a,{b,c},d}\n */\nfunction parseCommaParts(str: string) {\n if (!str) {\n return ['']\n }\n\n const parts: string[] = []\n const m = balanced('{', '}', str)\n\n if (!m) {\n return str.split(',')\n }\n\n const { pre, body, post } = m\n const p = pre.split(',')\n\n p[p.length - 1] += '{' + body + '}'\n const postParts = parseCommaParts(post)\n if (post.length) {\n ;(p[p.length - 1] as string) += postParts.shift()\n p.push.apply(p, postParts)\n }\n\n parts.push.apply(parts, p)\n\n return parts\n}\n\nexport type BraceExpansionOptions = {\n max?: number\n}\n\nexport function expand(str: string, options: BraceExpansionOptions = {}) {\n if (!str) {\n return []\n }\n\n const { max = EXPANSION_MAX } = options\n\n // I don't know why Bash 4.3 does this, but it does.\n // Anything starting with {} will have the first two bytes preserved\n // but *only* at the top level, so {},a}b will not expand to anything,\n // but a{},b}c will be expanded to [a}c,abc].\n // One could argue that this is a bug in Bash, but since the goal of\n // this module is to match Bash's rules, we escape a leading {}\n if (str.slice(0, 2) === '{}') {\n str = '\\\\{\\\\}' + str.slice(2)\n }\n\n return expand_(escapeBraces(str), max, true).map(unescapeBraces)\n}\n\nfunction embrace(str: string) {\n return '{' + str + '}'\n}\n\nfunction isPadded(el: string) {\n return /^-?0\\d/.test(el)\n}\n\nfunction lte(i: number, y: number) {\n return i <= y\n}\n\nfunction gte(i: number, y: number) {\n return i >= y\n}\n\nfunction expand_(str: string, max: number, isTop: boolean): string[] {\n /** @type {string[]} */\n const expansions: string[] = []\n\n // The `{a},b}` rewrite below restarts expansion on a rewritten string with\n // the same `max` and `isTop = true`. Loop instead of recursing so a long run\n // of non-expanding `{}` groups can't exhaust the call stack.\n for (;;) {\n const m = balanced('{', '}', str)\n if (!m) return [str]\n\n // no need to expand pre, since it is guaranteed to be free of brace-sets\n const pre = m.pre\n\n if (/\\$$/.test(m.pre)) {\n const post: string[] =\n m.post.length ? expand_(m.post, max, false) : ['']\n for (let k = 0; k < post.length && k < max; k++) {\n const expansion = pre + '{' + m.body + '}' + post[k]\n expansions.push(expansion)\n }\n return expansions\n }\n\n const isNumericSequence = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(m.body)\n const isAlphaSequence = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(\n m.body,\n )\n const isSequence = isNumericSequence || isAlphaSequence\n const isOptions = m.body.indexOf(',') >= 0\n if (!isSequence && !isOptions) {\n // {a},b}\n if (m.post.match(/,(?!,).*\\}/)) {\n str = m.pre + '{' + m.body + escClose + m.post\n isTop = true\n continue\n }\n return [str]\n }\n\n // Only expand post once we know this brace set actually expands. Computing\n // it before the early returns above expanded post a second time on every\n // non-expanding `{}`, which is what made inputs like `a{},{},{}...` blow up\n // exponentially.\n const post: string[] =\n m.post.length ? expand_(m.post, max, false) : ['']\n\n let n: string[]\n if (isSequence) {\n n = m.body.split(/\\.\\./)\n } else {\n n = parseCommaParts(m.body)\n if (n.length === 1 && n[0] !== undefined) {\n // x{{a,b}}y ==> x{a}y x{b}y\n n = expand_(n[0], max, false).map(embrace)\n //XXX is this necessary? Can't seem to hit it in tests.\n /* c8 ignore start */\n if (n.length === 1) {\n return post.map(p => m.pre + n[0] + p)\n }\n /* c8 ignore stop */\n }\n }\n\n // at this point, n is the parts, and we know it's not a comma set\n // with a single entry.\n let N: string[]\n\n if (isSequence && n[0] !== undefined && n[1] !== undefined) {\n const x = numeric(n[0])\n const y = numeric(n[1])\n const width = Math.max(n[0].length, n[1].length)\n let incr =\n n.length === 3 && n[2] !== undefined ?\n Math.max(Math.abs(numeric(n[2])), 1)\n : 1\n let test = lte\n const reverse = y < x\n if (reverse) {\n incr *= -1\n test = gte\n }\n const pad = n.some(isPadded)\n\n N = []\n\n for (let i = x; test(i, y) && N.length < max; i += incr) {\n let c\n if (isAlphaSequence) {\n c = String.fromCharCode(i)\n if (c === '\\\\') {\n c = ''\n }\n } else {\n c = String(i)\n if (pad) {\n const need = width - c.length\n if (need > 0) {\n const z = new Array(need + 1).join('0')\n if (i < 0) {\n c = '-' + z + c.slice(1)\n } else {\n c = z + c\n }\n }\n }\n }\n N.push(c)\n }\n } else {\n N = []\n\n for (let j = 0; j < n.length; j++) {\n N.push.apply(N, expand_(n[j] as string, max, false))\n }\n }\n\n for (let j = 0; j < N.length; j++) {\n for (let k = 0; k < post.length && expansions.length < max; k++) {\n const expansion = pre + N[j] + post[k]\n if (!isTop || isSequence || expansion) {\n expansions.push(expansion)\n }\n }\n }\n\n return expansions\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AA2FA,wBAkBC;AA7GD,mDAAyC;AAEzC,MAAM,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AACjD,MAAM,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AAC/C,MAAM,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AACjD,MAAM,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AACjD,MAAM,SAAS,GAAG,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AACnD,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;AACjD,MAAM,cAAc,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;AAC/C,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;AACjD,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;AACjD,MAAM,gBAAgB,GAAG,IAAI,MAAM,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;AACnD,MAAM,YAAY,GAAG,OAAO,CAAA;AAC5B,MAAM,WAAW,GAAG,MAAM,CAAA;AAC1B,MAAM,YAAY,GAAG,MAAM,CAAA;AAC3B,MAAM,YAAY,GAAG,MAAM,CAAA;AAC3B,MAAM,aAAa,GAAG,O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CAAC,EAAE,CAAC;oBACnB,GAAG,GAAG,OAAO,CACX,GAAG,EACH,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,EACV,CAAC,EAAE,CAAC,EACJ,GAAG,EACH,SAAS,EACT,WAAW,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAC9B,CAAA;oBACD,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM;wBAAE,MAAK;oBACzB,GAAG,GAAG,CAAC,CAAC,IAAI,CAAA;oBACZ,SAAQ;gBACV,CAAC;gBACD,oBAAoB;YACtB,CAAC;YAED,MAAM,GAAG,EAAE,CAAA;YACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAClC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAW,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;YAC3E,CAAC;QACH,CAAC;QAED,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,WAAW,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC9E,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM;YAAE,MAAK;QACzB,GAAG,GAAG,CAAC,CAAC,IAAI,CAAA;IACd,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import { balanced } from 'balanced-match'\n\nconst escSlash = '\\0SLASH' + Math.random() + '\\0'\nconst escOpen = '\\0OPEN' + Math.random() + '\\0'\nconst escClose = '\\0CLOSE' + Math.random() + '\\0'\nconst escComma = '\\0COMMA' + Math.random() + '\\0'\nconst escPeriod = '\\0PERIOD' + Math.random() + '\\0'\nconst escSlashPattern = new RegExp(escSlash, 'g')\nconst escOpenPattern = new RegExp(escOpen, 'g')\nconst escClosePattern = new RegExp(escClose, 'g')\nconst escCommaPattern = new RegExp(escComma, 'g')\nconst escPeriodPattern = new RegExp(escPeriod, 'g')\nconst slashPattern = /\\\\\\\\/g\nconst openPattern = /\\\\{/g\nconst closePattern = /\\\\}/g\nconst commaPattern = /\\\\,/g\nconst periodPattern = /\\\\\\./g\n\nexport const EXPANSION_MAX = 100_000\n\n// `EXPANSION_MAX` caps the *number* of expansions, but not their length. An\n// input like `'{a,b}'.repeat(1500)` stays under that count - its output is\n// truncated to 100k results - while making every result ~1500 characters\n// long. The result set, and the intermediate arrays built while combining\n// brace sets, then grow large enough to exhaust memory and crash the process\n// (CVE-2026-14257). `EXPANSION_MAX_LENGTH` bounds the total number of\n// characters the accumulator may hold at any point, so memory stays flat no\n// matter how many brace groups are chained. The limit sits well above any\n// realistic expansion (100k results hitting `EXPANSION_MAX` measure ~1M\n// characters) so legitimate input is unaffected.\nexport const EXPANSION_MAX_LENGTH = 4_000_000\n\nfunction numeric(str: string) {\n return !isNaN(str as any) ? parseInt(str, 10) : str.charCodeAt(0)\n}\n\nfunction escapeBraces(str: string) {\n return str\n .replace(slashPattern, escSlash)\n .replace(openPattern, escOpen)\n .replace(closePattern, escClose)\n .replace(commaPattern, escComma)\n .replace(periodPattern, escPeriod)\n}\n\nfunction unescapeBraces(str: string) {\n return str\n .replace(escSlashPattern, '\\\\')\n .replace(escOpenPattern, '{')\n .replace(escClosePattern, '}')\n .replace(escCommaPattern, ',')\n .replace(escPeriodPattern, '.')\n}\n\n/**\n * Basically just str.split(\",\"), but handling cases\n * where we have nested braced sections, which should be\n * treated as individual members, like {a,{b,c},d}\n */\nfunction parseCommaParts(str: string) {\n if (!str) {\n return ['']\n }\n\n const parts: string[] = []\n const m = balanced('{', '}', str)\n\n if (!m) {\n return str.split(',')\n }\n\n const { pre, body, post } = m\n const p = pre.split(',')\n\n p[p.length - 1] += '{' + body + '}'\n const postParts = parseCommaParts(post)\n if (post.length) {\n ;(p[p.length - 1] as string) += postParts.shift()\n p.push.apply(p, postParts)\n }\n\n parts.push.apply(parts, p)\n\n return parts\n}\n\nexport type BraceExpansionOptions = {\n max?: number\n maxLength?: number\n}\n\nexport function expand(str: string, options: BraceExpansionOptions = {}) {\n if (!str) {\n return []\n }\n\n const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH } = options\n\n // I don't know why Bash 4.3 does this, but it does.\n // Anything starting with {} will have the first two bytes preserved\n // but *only* at the top level, so {},a}b will not expand to anything,\n // but a{},b}c will be expanded to [a}c,abc].\n // One could argue that this is a bug in Bash, but since the goal of\n // this module is to match Bash's rules, we escape a leading {}\n if (str.slice(0, 2) === '{}') {\n str = '\\\\{\\\\}' + str.slice(2)\n }\n\n return expand_(escapeBraces(str), max, maxLength, true).map(unescapeBraces)\n}\n\nfunction embrace(str: string) {\n return '{' + str + '}'\n}\n\nfunction isPadded(el: string) {\n return /^-?0\\d/.test(el)\n}\n\nfunction lte(i: number, y: number) {\n return i <= y\n}\n\nfunction gte(i: number, y: number) {\n return i >= y\n}\n\n// Build `{ acc[a] + pre + values[v] }` for every combination, capping the\n// number of results at `max` and the total number of characters at `maxLength`.\n// This is the one place output grows, so bounding it here keeps the single\n// accumulator - and therefore memory - flat regardless of how many brace groups\n// are combined (CVE-2026-14257).\nfunction combine(\n acc: string[],\n pre: string,\n values: string[],\n max: number,\n maxLength: number,\n dropEmpties: boolean,\n): string[] {\n const out: string[] = []\n let length = 0\n for (let a = 0; a < acc.length; a++) {\n for (let v = 0; v < values.length; v++) {\n if (out.length >= max) return out\n const expansion = (acc[a] as string) + pre + values[v]\n // Bash drops empty results at the top level. Skip them before they count\n // against `max`, so `max` bounds the number of *kept* results.\n if (dropEmpties && !expansion) continue\n if (length + expansion.length > maxLength) return out\n out.push(expansion)\n length += expansion.length\n }\n }\n return out\n}\n\n// The expansion values of a single numeric (`1..5`) or alphabetic (`a..e..2`)\n// sequence body.\nfunction expandSequence(\n body: string,\n isAlphaSequence: boolean,\n max: number,\n): string[] {\n const n = body.split(/\\.\\./)\n const N: string[] = []\n // A sequence body always splits into two or three parts, but the compiler\n // can't know that.\n /* c8 ignore start */\n if (n[0] === undefined || n[1] === undefined) {\n return N\n }\n /* c8 ignore stop */\n const x = numeric(n[0])\n const y = numeric(n[1])\n const width = Math.max(n[0].length, n[1].length)\n let incr =\n n.length === 3 && n[2] !== undefined ?\n Math.max(Math.abs(numeric(n[2])), 1)\n : 1\n let test = lte\n const reverse = y < x\n if (reverse) {\n incr *= -1\n test = gte\n }\n const pad = n.some(isPadded)\n\n for (let i = x; test(i, y) && N.length < max; i += incr) {\n let c\n if (isAlphaSequence) {\n c = String.fromCharCode(i)\n if (c === '\\\\') {\n c = ''\n }\n } else {\n c = String(i)\n if (pad) {\n const need = width - c.length\n if (need > 0) {\n const z = new Array(need + 1).join('0')\n if (i < 0) {\n c = '-' + z + c.slice(1)\n } else {\n c = z + c\n }\n }\n }\n }\n N.push(c)\n }\n return N\n}\n\nfunction expand_(\n str: string,\n max: number,\n maxLength: number,\n isTop: boolean,\n): string[] {\n // Consume the string's top-level brace groups left to right, threading a\n // running set of combined prefixes (`acc`). Expanding the tail iteratively -\n // rather than recursing on `m.post` once per group - keeps the native stack\n // depth constant, so deeply chained input (`'{a,b}'.repeat(3000)`) can no\n // longer overflow the stack, and leaves a single accumulator whose size\n // `maxLength` bounds directly (CVE-2026-14257).\n let acc: string[] = ['']\n\n // Bash drops empty results, but only when the *first* top-level group is a\n // comma set - a sequence like `{a..\\}` may legitimately yield ''. The drop\n // is on the final strings, so it is applied to whichever `combine` produces\n // them (the one with no brace set left in the tail).\n let dropEmpties = false\n let firstGroup = true\n\n for (;;) {\n const m = balanced('{', '}', str)\n\n // No brace set left: the rest of the string is literal.\n if (!m) {\n return combine(acc, str, [''], max, maxLength, dropEmpties)\n }\n\n // no need to expand pre, since it is guaranteed to be free of brace-sets\n const pre = m.pre\n\n if (/\\$$/.test(pre)) {\n acc = combine(\n acc,\n pre + '{' + m.body + '}',\n [''],\n max,\n maxLength,\n dropEmpties && !m.post.length,\n )\n firstGroup = false\n if (!m.post.length) break\n str = m.post\n continue\n }\n\n const isNumericSequence = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(m.body)\n const isAlphaSequence = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(\n m.body,\n )\n const isSequence = isNumericSequence || isAlphaSequence\n const isOptions = m.body.indexOf(',') >= 0\n if (!isSequence && !isOptions) {\n // {a},b}\n if (m.post.match(/,(?!,).*\\}/)) {\n str = m.pre + '{' + m.body + escClose + m.post\n isTop = true\n continue\n }\n // Nothing here expands, so the whole remaining string is literal.\n return combine(\n acc,\n pre + '{' + m.body + '}' + m.post,\n [''],\n max,\n maxLength,\n dropEmpties,\n )\n }\n\n if (firstGroup) {\n dropEmpties = isTop && !isSequence\n firstGroup = false\n }\n\n let values: string[]\n if (isSequence) {\n values = expandSequence(m.body, isAlphaSequence, max)\n } else {\n let n = parseCommaParts(m.body)\n if (n.length === 1 && n[0] !== undefined) {\n // x{{a,b}}y ==> x{a}y x{b}y\n n = expand_(n[0], max, maxLength, false).map(embrace)\n //XXX is this necessary? Can't seem to hit it in tests.\n /* c8 ignore start */\n if (n.length === 1) {\n acc = combine(\n acc,\n pre + n[0],\n [''],\n max,\n maxLength,\n dropEmpties && !m.post.length,\n )\n if (!m.post.length) break\n str = m.post\n continue\n }\n /* c8 ignore stop */\n }\n\n values = []\n for (let j = 0; j < n.length; j++) {\n values.push.apply(values, expand_(n[j] as string, max, maxLength, false))\n }\n }\n\n acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length)\n if (!m.post.length) break\n str = m.post\n }\n\n return acc\n}\n"]}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const EXPANSION_MAX = 100000;
|
|
2
|
+
export declare const EXPANSION_MAX_LENGTH = 4000000;
|
|
2
3
|
export type BraceExpansionOptions = {
|
|
3
4
|
max?: number;
|
|
5
|
+
maxLength?: number;
|
|
4
6
|
};
|
|
5
7
|
export declare function expand(str: string, options?: BraceExpansionOptions): string[];
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,aAAa,SAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,aAAa,SAAU,CAAA;AAYpC,eAAO,MAAM,oBAAoB,UAAY,CAAA;AAwD7C,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,qBAA0B,YAkBtE"}
|
|
@@ -15,6 +15,17 @@ const closePattern = /\\}/g;
|
|
|
15
15
|
const commaPattern = /\\,/g;
|
|
16
16
|
const periodPattern = /\\\./g;
|
|
17
17
|
export const EXPANSION_MAX = 100_000;
|
|
18
|
+
// `EXPANSION_MAX` caps the *number* of expansions, but not their length. An
|
|
19
|
+
// input like `'{a,b}'.repeat(1500)` stays under that count - its output is
|
|
20
|
+
// truncated to 100k results - while making every result ~1500 characters
|
|
21
|
+
// long. The result set, and the intermediate arrays built while combining
|
|
22
|
+
// brace sets, then grow large enough to exhaust memory and crash the process
|
|
23
|
+
// (CVE-2026-14257). `EXPANSION_MAX_LENGTH` bounds the total number of
|
|
24
|
+
// characters the accumulator may hold at any point, so memory stays flat no
|
|
25
|
+
// matter how many brace groups are chained. The limit sits well above any
|
|
26
|
+
// realistic expansion (100k results hitting `EXPANSION_MAX` measure ~1M
|
|
27
|
+
// characters) so legitimate input is unaffected.
|
|
28
|
+
export const EXPANSION_MAX_LENGTH = 4_000_000;
|
|
18
29
|
function numeric(str) {
|
|
19
30
|
return !isNaN(str) ? parseInt(str, 10) : str.charCodeAt(0);
|
|
20
31
|
}
|
|
@@ -64,7 +75,7 @@ export function expand(str, options = {}) {
|
|
|
64
75
|
if (!str) {
|
|
65
76
|
return [];
|
|
66
77
|
}
|
|
67
|
-
const { max = EXPANSION_MAX } = options;
|
|
78
|
+
const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH } = options;
|
|
68
79
|
// I don't know why Bash 4.3 does this, but it does.
|
|
69
80
|
// Anything starting with {} will have the first two bytes preserved
|
|
70
81
|
// but *only* at the top level, so {},a}b will not expand to anything,
|
|
@@ -74,7 +85,7 @@ export function expand(str, options = {}) {
|
|
|
74
85
|
if (str.slice(0, 2) === '{}') {
|
|
75
86
|
str = '\\{\\}' + str.slice(2);
|
|
76
87
|
}
|
|
77
|
-
return expand_(escapeBraces(str), max, true).map(unescapeBraces);
|
|
88
|
+
return expand_(escapeBraces(str), max, maxLength, true).map(unescapeBraces);
|
|
78
89
|
}
|
|
79
90
|
function embrace(str) {
|
|
80
91
|
return '{' + str + '}';
|
|
@@ -88,25 +99,112 @@ function lte(i, y) {
|
|
|
88
99
|
function gte(i, y) {
|
|
89
100
|
return i >= y;
|
|
90
101
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
// Build `{ acc[a] + pre + values[v] }` for every combination, capping the
|
|
103
|
+
// number of results at `max` and the total number of characters at `maxLength`.
|
|
104
|
+
// This is the one place output grows, so bounding it here keeps the single
|
|
105
|
+
// accumulator - and therefore memory - flat regardless of how many brace groups
|
|
106
|
+
// are combined (CVE-2026-14257).
|
|
107
|
+
function combine(acc, pre, values, max, maxLength, dropEmpties) {
|
|
108
|
+
const out = [];
|
|
109
|
+
let length = 0;
|
|
110
|
+
for (let a = 0; a < acc.length; a++) {
|
|
111
|
+
for (let v = 0; v < values.length; v++) {
|
|
112
|
+
if (out.length >= max)
|
|
113
|
+
return out;
|
|
114
|
+
const expansion = acc[a] + pre + values[v];
|
|
115
|
+
// Bash drops empty results at the top level. Skip them before they count
|
|
116
|
+
// against `max`, so `max` bounds the number of *kept* results.
|
|
117
|
+
if (dropEmpties && !expansion)
|
|
118
|
+
continue;
|
|
119
|
+
if (length + expansion.length > maxLength)
|
|
120
|
+
return out;
|
|
121
|
+
out.push(expansion);
|
|
122
|
+
length += expansion.length;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return out;
|
|
126
|
+
}
|
|
127
|
+
// The expansion values of a single numeric (`1..5`) or alphabetic (`a..e..2`)
|
|
128
|
+
// sequence body.
|
|
129
|
+
function expandSequence(body, isAlphaSequence, max) {
|
|
130
|
+
const n = body.split(/\.\./);
|
|
131
|
+
const N = [];
|
|
132
|
+
// A sequence body always splits into two or three parts, but the compiler
|
|
133
|
+
// can't know that.
|
|
134
|
+
/* c8 ignore start */
|
|
135
|
+
if (n[0] === undefined || n[1] === undefined) {
|
|
136
|
+
return N;
|
|
137
|
+
}
|
|
138
|
+
/* c8 ignore stop */
|
|
139
|
+
const x = numeric(n[0]);
|
|
140
|
+
const y = numeric(n[1]);
|
|
141
|
+
const width = Math.max(n[0].length, n[1].length);
|
|
142
|
+
let incr = n.length === 3 && n[2] !== undefined ?
|
|
143
|
+
Math.max(Math.abs(numeric(n[2])), 1)
|
|
144
|
+
: 1;
|
|
145
|
+
let test = lte;
|
|
146
|
+
const reverse = y < x;
|
|
147
|
+
if (reverse) {
|
|
148
|
+
incr *= -1;
|
|
149
|
+
test = gte;
|
|
150
|
+
}
|
|
151
|
+
const pad = n.some(isPadded);
|
|
152
|
+
for (let i = x; test(i, y) && N.length < max; i += incr) {
|
|
153
|
+
let c;
|
|
154
|
+
if (isAlphaSequence) {
|
|
155
|
+
c = String.fromCharCode(i);
|
|
156
|
+
if (c === '\\') {
|
|
157
|
+
c = '';
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
c = String(i);
|
|
162
|
+
if (pad) {
|
|
163
|
+
const need = width - c.length;
|
|
164
|
+
if (need > 0) {
|
|
165
|
+
const z = new Array(need + 1).join('0');
|
|
166
|
+
if (i < 0) {
|
|
167
|
+
c = '-' + z + c.slice(1);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
c = z + c;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
N.push(c);
|
|
176
|
+
}
|
|
177
|
+
return N;
|
|
178
|
+
}
|
|
179
|
+
function expand_(str, max, maxLength, isTop) {
|
|
180
|
+
// Consume the string's top-level brace groups left to right, threading a
|
|
181
|
+
// running set of combined prefixes (`acc`). Expanding the tail iteratively -
|
|
182
|
+
// rather than recursing on `m.post` once per group - keeps the native stack
|
|
183
|
+
// depth constant, so deeply chained input (`'{a,b}'.repeat(3000)`) can no
|
|
184
|
+
// longer overflow the stack, and leaves a single accumulator whose size
|
|
185
|
+
// `maxLength` bounds directly (CVE-2026-14257).
|
|
186
|
+
let acc = [''];
|
|
187
|
+
// Bash drops empty results, but only when the *first* top-level group is a
|
|
188
|
+
// comma set - a sequence like `{a..\}` may legitimately yield ''. The drop
|
|
189
|
+
// is on the final strings, so it is applied to whichever `combine` produces
|
|
190
|
+
// them (the one with no brace set left in the tail).
|
|
191
|
+
let dropEmpties = false;
|
|
192
|
+
let firstGroup = true;
|
|
97
193
|
for (;;) {
|
|
98
194
|
const m = balanced('{', '}', str);
|
|
99
|
-
|
|
100
|
-
|
|
195
|
+
// No brace set left: the rest of the string is literal.
|
|
196
|
+
if (!m) {
|
|
197
|
+
return combine(acc, str, [''], max, maxLength, dropEmpties);
|
|
198
|
+
}
|
|
101
199
|
// no need to expand pre, since it is guaranteed to be free of brace-sets
|
|
102
200
|
const pre = m.pre;
|
|
103
|
-
if (/\$$/.test(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
201
|
+
if (/\$$/.test(pre)) {
|
|
202
|
+
acc = combine(acc, pre + '{' + m.body + '}', [''], max, maxLength, dropEmpties && !m.post.length);
|
|
203
|
+
firstGroup = false;
|
|
204
|
+
if (!m.post.length)
|
|
205
|
+
break;
|
|
206
|
+
str = m.post;
|
|
207
|
+
continue;
|
|
110
208
|
}
|
|
111
209
|
const isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
|
112
210
|
const isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
|
@@ -119,89 +217,43 @@ function expand_(str, max, isTop) {
|
|
|
119
217
|
isTop = true;
|
|
120
218
|
continue;
|
|
121
219
|
}
|
|
122
|
-
|
|
220
|
+
// Nothing here expands, so the whole remaining string is literal.
|
|
221
|
+
return combine(acc, pre + '{' + m.body + '}' + m.post, [''], max, maxLength, dropEmpties);
|
|
123
222
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
let n;
|
|
223
|
+
if (firstGroup) {
|
|
224
|
+
dropEmpties = isTop && !isSequence;
|
|
225
|
+
firstGroup = false;
|
|
226
|
+
}
|
|
227
|
+
let values;
|
|
130
228
|
if (isSequence) {
|
|
131
|
-
|
|
229
|
+
values = expandSequence(m.body, isAlphaSequence, max);
|
|
132
230
|
}
|
|
133
231
|
else {
|
|
134
|
-
n = parseCommaParts(m.body);
|
|
232
|
+
let n = parseCommaParts(m.body);
|
|
135
233
|
if (n.length === 1 && n[0] !== undefined) {
|
|
136
234
|
// x{{a,b}}y ==> x{a}y x{b}y
|
|
137
|
-
n = expand_(n[0], max, false).map(embrace);
|
|
235
|
+
n = expand_(n[0], max, maxLength, false).map(embrace);
|
|
138
236
|
//XXX is this necessary? Can't seem to hit it in tests.
|
|
139
237
|
/* c8 ignore start */
|
|
140
238
|
if (n.length === 1) {
|
|
141
|
-
|
|
239
|
+
acc = combine(acc, pre + n[0], [''], max, maxLength, dropEmpties && !m.post.length);
|
|
240
|
+
if (!m.post.length)
|
|
241
|
+
break;
|
|
242
|
+
str = m.post;
|
|
243
|
+
continue;
|
|
142
244
|
}
|
|
143
245
|
/* c8 ignore stop */
|
|
144
246
|
}
|
|
145
|
-
|
|
146
|
-
// at this point, n is the parts, and we know it's not a comma set
|
|
147
|
-
// with a single entry.
|
|
148
|
-
let N;
|
|
149
|
-
if (isSequence && n[0] !== undefined && n[1] !== undefined) {
|
|
150
|
-
const x = numeric(n[0]);
|
|
151
|
-
const y = numeric(n[1]);
|
|
152
|
-
const width = Math.max(n[0].length, n[1].length);
|
|
153
|
-
let incr = n.length === 3 && n[2] !== undefined ?
|
|
154
|
-
Math.max(Math.abs(numeric(n[2])), 1)
|
|
155
|
-
: 1;
|
|
156
|
-
let test = lte;
|
|
157
|
-
const reverse = y < x;
|
|
158
|
-
if (reverse) {
|
|
159
|
-
incr *= -1;
|
|
160
|
-
test = gte;
|
|
161
|
-
}
|
|
162
|
-
const pad = n.some(isPadded);
|
|
163
|
-
N = [];
|
|
164
|
-
for (let i = x; test(i, y) && N.length < max; i += incr) {
|
|
165
|
-
let c;
|
|
166
|
-
if (isAlphaSequence) {
|
|
167
|
-
c = String.fromCharCode(i);
|
|
168
|
-
if (c === '\\') {
|
|
169
|
-
c = '';
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
c = String(i);
|
|
174
|
-
if (pad) {
|
|
175
|
-
const need = width - c.length;
|
|
176
|
-
if (need > 0) {
|
|
177
|
-
const z = new Array(need + 1).join('0');
|
|
178
|
-
if (i < 0) {
|
|
179
|
-
c = '-' + z + c.slice(1);
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
c = z + c;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
N.push(c);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
N = [];
|
|
247
|
+
values = [];
|
|
192
248
|
for (let j = 0; j < n.length; j++) {
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
for (let j = 0; j < N.length; j++) {
|
|
197
|
-
for (let k = 0; k < post.length && expansions.length < max; k++) {
|
|
198
|
-
const expansion = pre + N[j] + post[k];
|
|
199
|
-
if (!isTop || isSequence || expansion) {
|
|
200
|
-
expansions.push(expansion);
|
|
201
|
-
}
|
|
249
|
+
values.push.apply(values, expand_(n[j], max, maxLength, false));
|
|
202
250
|
}
|
|
203
251
|
}
|
|
204
|
-
|
|
252
|
+
acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length);
|
|
253
|
+
if (!m.post.length)
|
|
254
|
+
break;
|
|
255
|
+
str = m.post;
|
|
205
256
|
}
|
|
257
|
+
return acc;
|
|
206
258
|
}
|
|
207
259
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,MAAM,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AACjD,MAAM,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AAC/C,MAAM,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AACjD,MAAM,QAAQ,GAAG,SAAS,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AACjD,MAAM,SAAS,GAAG,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAA;AACnD,MAAM,eAAe,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;AACjD,MAAM,cAAc,GAAG,IAAI,MAAM,CAAC,OAAO,EAAE,GA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,CAAC,GAAG,CAAC,EAAE,CAAC;gCACV,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;4BAC1B,CAAC;iCAAM,CAAC;gCACN,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;4BACX,CAAC;wBACH,CAAC;oBACH,CAAC;gBACH,CAAC;gBACD,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACX,CAAC;QACH,CAAC;aAAM,CAAC;YACN,CAAC,GAAG,EAAE,CAAA;YAEN,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAClC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAW,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;YACtD,CAAC;QACH,CAAC;QAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,IAAI,UAAU,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;gBAChE,MAAM,SAAS,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;gBACtC,IAAI,CAAC,KAAK,IAAI,UAAU,IAAI,SAAS,EAAE,CAAC;oBACtC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;gBAC5B,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAA;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { balanced } from 'balanced-match'\n\nconst escSlash = '\\0SLASH' + Math.random() + '\\0'\nconst escOpen = '\\0OPEN' + Math.random() + '\\0'\nconst escClose = '\\0CLOSE' + Math.random() + '\\0'\nconst escComma = '\\0COMMA' + Math.random() + '\\0'\nconst escPeriod = '\\0PERIOD' + Math.random() + '\\0'\nconst escSlashPattern = new RegExp(escSlash, 'g')\nconst escOpenPattern = new RegExp(escOpen, 'g')\nconst escClosePattern = new RegExp(escClose, 'g')\nconst escCommaPattern = new RegExp(escComma, 'g')\nconst escPeriodPattern = new RegExp(escPeriod, 'g')\nconst slashPattern = /\\\\\\\\/g\nconst openPattern = /\\\\{/g\nconst closePattern = /\\\\}/g\nconst commaPattern = /\\\\,/g\nconst periodPattern = /\\\\\\./g\n\nexport const EXPANSION_MAX = 100_000\n\nfunction numeric(str: string) {\n return !isNaN(str as any) ? parseInt(str, 10) : str.charCodeAt(0)\n}\n\nfunction escapeBraces(str: string) {\n return str\n .replace(slashPattern, escSlash)\n .replace(openPattern, escOpen)\n .replace(closePattern, escClose)\n .replace(commaPattern, escComma)\n .replace(periodPattern, escPeriod)\n}\n\nfunction unescapeBraces(str: string) {\n return str\n .replace(escSlashPattern, '\\\\')\n .replace(escOpenPattern, '{')\n .replace(escClosePattern, '}')\n .replace(escCommaPattern, ',')\n .replace(escPeriodPattern, '.')\n}\n\n/**\n * Basically just str.split(\",\"), but handling cases\n * where we have nested braced sections, which should be\n * treated as individual members, like {a,{b,c},d}\n */\nfunction parseCommaParts(str: string) {\n if (!str) {\n return ['']\n }\n\n const parts: string[] = []\n const m = balanced('{', '}', str)\n\n if (!m) {\n return str.split(',')\n }\n\n const { pre, body, post } = m\n const p = pre.split(',')\n\n p[p.length - 1] += '{' + body + '}'\n const postParts = parseCommaParts(post)\n if (post.length) {\n ;(p[p.length - 1] as string) += postParts.shift()\n p.push.apply(p, postParts)\n }\n\n parts.push.apply(parts, p)\n\n return parts\n}\n\nexport type BraceExpansionOptions = {\n max?: number\n}\n\nexport function expand(str: string, options: BraceExpansionOptions = {}) {\n if (!str) {\n return []\n }\n\n const { max = EXPANSION_MAX } = options\n\n // I don't know why Bash 4.3 does this, but it does.\n // Anything starting with {} will have the first two bytes preserved\n // but *only* at the top level, so {},a}b will not expand to anything,\n // but a{},b}c will be expanded to [a}c,abc].\n // One could argue that this is a bug in Bash, but since the goal of\n // this module is to match Bash's rules, we escape a leading {}\n if (str.slice(0, 2) === '{}') {\n str = '\\\\{\\\\}' + str.slice(2)\n }\n\n return expand_(escapeBraces(str), max, true).map(unescapeBraces)\n}\n\nfunction embrace(str: string) {\n return '{' + str + '}'\n}\n\nfunction isPadded(el: string) {\n return /^-?0\\d/.test(el)\n}\n\nfunction lte(i: number, y: number) {\n return i <= y\n}\n\nfunction gte(i: number, y: number) {\n return i >= y\n}\n\nfunction expand_(str: string, max: number, isTop: boolean): string[] {\n /** @type {string[]} */\n const expansions: string[] = []\n\n // The `{a},b}` rewrite below restarts expansion on a rewritten string with\n // the same `max` and `isTop = true`. Loop instead of recursing so a long run\n // of non-expanding `{}` groups can't exhaust the call stack.\n for (;;) {\n const m = balanced('{', '}', str)\n if (!m) return [str]\n\n // no need to expand pre, since it is guaranteed to be free of brace-sets\n const pre = m.pre\n\n if (/\\$$/.test(m.pre)) {\n const post: string[] =\n m.post.length ? expand_(m.post, max, false) : ['']\n for (let k = 0; k < post.length && k < max; k++) {\n const expansion = pre + '{' + m.body + '}' + post[k]\n expansions.push(expansion)\n }\n return expansions\n }\n\n const isNumericSequence = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(m.body)\n const isAlphaSequence = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(\n m.body,\n )\n const isSequence = isNumericSequence || isAlphaSequence\n const isOptions = m.body.indexOf(',') >= 0\n if (!isSequence && !isOptions) {\n // {a},b}\n if (m.post.match(/,(?!,).*\\}/)) {\n str = m.pre + '{' + m.body + escClose + m.post\n isTop = true\n continue\n }\n return [str]\n }\n\n // Only expand post once we know this brace set actually expands. Computing\n // it before the early returns above expanded post a second time on every\n // non-expanding `{}`, which is what made inputs like `a{},{},{}...` blow up\n // exponentially.\n const post: string[] =\n m.post.length ? expand_(m.post, max, false) : ['']\n\n let n: string[]\n if (isSequence) {\n n = m.body.split(/\\.\\./)\n } else {\n n = parseCommaParts(m.body)\n if (n.length === 1 && n[0] !== undefined) {\n // x{{a,b}}y ==> x{a}y x{b}y\n n = expand_(n[0], max, false).map(embrace)\n //XXX is this necessary? Can't seem to hit it in tests.\n /* c8 ignore start */\n if (n.length === 1) {\n return post.map(p => m.pre + n[0] + p)\n }\n /* c8 ignore stop */\n }\n }\n\n // at this point, n is the parts, and we know it's not a comma set\n // with a single entry.\n let N: string[]\n\n if (isSequence && n[0] !== undefined && n[1] !== undefined) {\n const x = numeric(n[0])\n const y = numeric(n[1])\n const width = Math.max(n[0].length, n[1].length)\n let incr =\n n.length === 3 && n[2] !== undefined ?\n Math.max(Math.abs(numeric(n[2])), 1)\n : 1\n let test = lte\n const reverse = y < x\n if (reverse) {\n incr *= -1\n test = gte\n }\n const pad = n.some(isPadded)\n\n N = []\n\n for (let i = x; test(i, y) && N.length < max; i += incr) {\n let c\n if (isAlphaSequence) {\n c = String.fromCharCode(i)\n if (c === '\\\\') {\n c = ''\n }\n } else {\n c = String(i)\n if (pad) {\n const need = width - c.length\n if (need > 0) {\n const z = new Array(need + 1).join('0')\n if (i < 0) {\n c = '-' + z + c.slice(1)\n } else {\n c = z + c\n }\n }\n }\n }\n N.push(c)\n }\n } else {\n N = []\n\n for (let j = 0; j < n.length; j++) {\n N.push.apply(N, expand_(n[j] as string, max, false))\n }\n }\n\n for (let j = 0; j < N.length; j++) {\n for (let k = 0; k < post.length && expansions.length < max; k++) {\n const expansion = pre + N[j] + post[k]\n if (!isTop || isSequence || expansion) {\n expansions.push(expansion)\n }\n }\n }\n\n return expansions\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AA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,GAAG,CAAC,CAAC,IAAI,CAAA;oBACZ,SAAQ;gBACV,CAAC;gBACD,oBAAoB;YACtB,CAAC;YAED,MAAM,GAAG,EAAE,CAAA;YACX,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAClC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAW,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAA;YAC3E,CAAC;QACH,CAAC;QAED,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,WAAW,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAC9E,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM;YAAE,MAAK;QACzB,GAAG,GAAG,CAAC,CAAC,IAAI,CAAA;IACd,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC","sourcesContent":["import { balanced } from 'balanced-match'\n\nconst escSlash = '\\0SLASH' + Math.random() + '\\0'\nconst escOpen = '\\0OPEN' + Math.random() + '\\0'\nconst escClose = '\\0CLOSE' + Math.random() + '\\0'\nconst escComma = '\\0COMMA' + Math.random() + '\\0'\nconst escPeriod = '\\0PERIOD' + Math.random() + '\\0'\nconst escSlashPattern = new RegExp(escSlash, 'g')\nconst escOpenPattern = new RegExp(escOpen, 'g')\nconst escClosePattern = new RegExp(escClose, 'g')\nconst escCommaPattern = new RegExp(escComma, 'g')\nconst escPeriodPattern = new RegExp(escPeriod, 'g')\nconst slashPattern = /\\\\\\\\/g\nconst openPattern = /\\\\{/g\nconst closePattern = /\\\\}/g\nconst commaPattern = /\\\\,/g\nconst periodPattern = /\\\\\\./g\n\nexport const EXPANSION_MAX = 100_000\n\n// `EXPANSION_MAX` caps the *number* of expansions, but not their length. An\n// input like `'{a,b}'.repeat(1500)` stays under that count - its output is\n// truncated to 100k results - while making every result ~1500 characters\n// long. The result set, and the intermediate arrays built while combining\n// brace sets, then grow large enough to exhaust memory and crash the process\n// (CVE-2026-14257). `EXPANSION_MAX_LENGTH` bounds the total number of\n// characters the accumulator may hold at any point, so memory stays flat no\n// matter how many brace groups are chained. The limit sits well above any\n// realistic expansion (100k results hitting `EXPANSION_MAX` measure ~1M\n// characters) so legitimate input is unaffected.\nexport const EXPANSION_MAX_LENGTH = 4_000_000\n\nfunction numeric(str: string) {\n return !isNaN(str as any) ? parseInt(str, 10) : str.charCodeAt(0)\n}\n\nfunction escapeBraces(str: string) {\n return str\n .replace(slashPattern, escSlash)\n .replace(openPattern, escOpen)\n .replace(closePattern, escClose)\n .replace(commaPattern, escComma)\n .replace(periodPattern, escPeriod)\n}\n\nfunction unescapeBraces(str: string) {\n return str\n .replace(escSlashPattern, '\\\\')\n .replace(escOpenPattern, '{')\n .replace(escClosePattern, '}')\n .replace(escCommaPattern, ',')\n .replace(escPeriodPattern, '.')\n}\n\n/**\n * Basically just str.split(\",\"), but handling cases\n * where we have nested braced sections, which should be\n * treated as individual members, like {a,{b,c},d}\n */\nfunction parseCommaParts(str: string) {\n if (!str) {\n return ['']\n }\n\n const parts: string[] = []\n const m = balanced('{', '}', str)\n\n if (!m) {\n return str.split(',')\n }\n\n const { pre, body, post } = m\n const p = pre.split(',')\n\n p[p.length - 1] += '{' + body + '}'\n const postParts = parseCommaParts(post)\n if (post.length) {\n ;(p[p.length - 1] as string) += postParts.shift()\n p.push.apply(p, postParts)\n }\n\n parts.push.apply(parts, p)\n\n return parts\n}\n\nexport type BraceExpansionOptions = {\n max?: number\n maxLength?: number\n}\n\nexport function expand(str: string, options: BraceExpansionOptions = {}) {\n if (!str) {\n return []\n }\n\n const { max = EXPANSION_MAX, maxLength = EXPANSION_MAX_LENGTH } = options\n\n // I don't know why Bash 4.3 does this, but it does.\n // Anything starting with {} will have the first two bytes preserved\n // but *only* at the top level, so {},a}b will not expand to anything,\n // but a{},b}c will be expanded to [a}c,abc].\n // One could argue that this is a bug in Bash, but since the goal of\n // this module is to match Bash's rules, we escape a leading {}\n if (str.slice(0, 2) === '{}') {\n str = '\\\\{\\\\}' + str.slice(2)\n }\n\n return expand_(escapeBraces(str), max, maxLength, true).map(unescapeBraces)\n}\n\nfunction embrace(str: string) {\n return '{' + str + '}'\n}\n\nfunction isPadded(el: string) {\n return /^-?0\\d/.test(el)\n}\n\nfunction lte(i: number, y: number) {\n return i <= y\n}\n\nfunction gte(i: number, y: number) {\n return i >= y\n}\n\n// Build `{ acc[a] + pre + values[v] }` for every combination, capping the\n// number of results at `max` and the total number of characters at `maxLength`.\n// This is the one place output grows, so bounding it here keeps the single\n// accumulator - and therefore memory - flat regardless of how many brace groups\n// are combined (CVE-2026-14257).\nfunction combine(\n acc: string[],\n pre: string,\n values: string[],\n max: number,\n maxLength: number,\n dropEmpties: boolean,\n): string[] {\n const out: string[] = []\n let length = 0\n for (let a = 0; a < acc.length; a++) {\n for (let v = 0; v < values.length; v++) {\n if (out.length >= max) return out\n const expansion = (acc[a] as string) + pre + values[v]\n // Bash drops empty results at the top level. Skip them before they count\n // against `max`, so `max` bounds the number of *kept* results.\n if (dropEmpties && !expansion) continue\n if (length + expansion.length > maxLength) return out\n out.push(expansion)\n length += expansion.length\n }\n }\n return out\n}\n\n// The expansion values of a single numeric (`1..5`) or alphabetic (`a..e..2`)\n// sequence body.\nfunction expandSequence(\n body: string,\n isAlphaSequence: boolean,\n max: number,\n): string[] {\n const n = body.split(/\\.\\./)\n const N: string[] = []\n // A sequence body always splits into two or three parts, but the compiler\n // can't know that.\n /* c8 ignore start */\n if (n[0] === undefined || n[1] === undefined) {\n return N\n }\n /* c8 ignore stop */\n const x = numeric(n[0])\n const y = numeric(n[1])\n const width = Math.max(n[0].length, n[1].length)\n let incr =\n n.length === 3 && n[2] !== undefined ?\n Math.max(Math.abs(numeric(n[2])), 1)\n : 1\n let test = lte\n const reverse = y < x\n if (reverse) {\n incr *= -1\n test = gte\n }\n const pad = n.some(isPadded)\n\n for (let i = x; test(i, y) && N.length < max; i += incr) {\n let c\n if (isAlphaSequence) {\n c = String.fromCharCode(i)\n if (c === '\\\\') {\n c = ''\n }\n } else {\n c = String(i)\n if (pad) {\n const need = width - c.length\n if (need > 0) {\n const z = new Array(need + 1).join('0')\n if (i < 0) {\n c = '-' + z + c.slice(1)\n } else {\n c = z + c\n }\n }\n }\n }\n N.push(c)\n }\n return N\n}\n\nfunction expand_(\n str: string,\n max: number,\n maxLength: number,\n isTop: boolean,\n): string[] {\n // Consume the string's top-level brace groups left to right, threading a\n // running set of combined prefixes (`acc`). Expanding the tail iteratively -\n // rather than recursing on `m.post` once per group - keeps the native stack\n // depth constant, so deeply chained input (`'{a,b}'.repeat(3000)`) can no\n // longer overflow the stack, and leaves a single accumulator whose size\n // `maxLength` bounds directly (CVE-2026-14257).\n let acc: string[] = ['']\n\n // Bash drops empty results, but only when the *first* top-level group is a\n // comma set - a sequence like `{a..\\}` may legitimately yield ''. The drop\n // is on the final strings, so it is applied to whichever `combine` produces\n // them (the one with no brace set left in the tail).\n let dropEmpties = false\n let firstGroup = true\n\n for (;;) {\n const m = balanced('{', '}', str)\n\n // No brace set left: the rest of the string is literal.\n if (!m) {\n return combine(acc, str, [''], max, maxLength, dropEmpties)\n }\n\n // no need to expand pre, since it is guaranteed to be free of brace-sets\n const pre = m.pre\n\n if (/\\$$/.test(pre)) {\n acc = combine(\n acc,\n pre + '{' + m.body + '}',\n [''],\n max,\n maxLength,\n dropEmpties && !m.post.length,\n )\n firstGroup = false\n if (!m.post.length) break\n str = m.post\n continue\n }\n\n const isNumericSequence = /^-?\\d+\\.\\.-?\\d+(?:\\.\\.-?\\d+)?$/.test(m.body)\n const isAlphaSequence = /^[a-zA-Z]\\.\\.[a-zA-Z](?:\\.\\.-?\\d+)?$/.test(\n m.body,\n )\n const isSequence = isNumericSequence || isAlphaSequence\n const isOptions = m.body.indexOf(',') >= 0\n if (!isSequence && !isOptions) {\n // {a},b}\n if (m.post.match(/,(?!,).*\\}/)) {\n str = m.pre + '{' + m.body + escClose + m.post\n isTop = true\n continue\n }\n // Nothing here expands, so the whole remaining string is literal.\n return combine(\n acc,\n pre + '{' + m.body + '}' + m.post,\n [''],\n max,\n maxLength,\n dropEmpties,\n )\n }\n\n if (firstGroup) {\n dropEmpties = isTop && !isSequence\n firstGroup = false\n }\n\n let values: string[]\n if (isSequence) {\n values = expandSequence(m.body, isAlphaSequence, max)\n } else {\n let n = parseCommaParts(m.body)\n if (n.length === 1 && n[0] !== undefined) {\n // x{{a,b}}y ==> x{a}y x{b}y\n n = expand_(n[0], max, maxLength, false).map(embrace)\n //XXX is this necessary? Can't seem to hit it in tests.\n /* c8 ignore start */\n if (n.length === 1) {\n acc = combine(\n acc,\n pre + n[0],\n [''],\n max,\n maxLength,\n dropEmpties && !m.post.length,\n )\n if (!m.post.length) break\n str = m.post\n continue\n }\n /* c8 ignore stop */\n }\n\n values = []\n for (let j = 0; j < n.length; j++) {\n values.push.apply(values, expand_(n[j] as string, max, maxLength, false))\n }\n }\n\n acc = combine(acc, pre, values, max, maxLength, dropEmpties && !m.post.length)\n if (!m.post.length) break\n str = m.post\n }\n\n return acc\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brace-expansion",
|
|
3
3
|
"description": "Brace expansion as known from sh/bash",
|
|
4
|
-
"version": "5.0.
|
|
4
|
+
"version": "5.0.8",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
7
7
|
],
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"license": "MIT",
|
|
48
48
|
"engines": {
|
|
49
|
-
"node": "
|
|
49
|
+
"node": "20 || >=22"
|
|
50
50
|
},
|
|
51
51
|
"tshy": {
|
|
52
52
|
"exports": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@psnext/slingcli",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.20260724-1",
|
|
4
4
|
"description": "Connects Sling CLI to Publicis Sapient Slingshot enterprise LLM gateway. Bundles the pi coding-agent runtime.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"type": "git",
|
|
30
30
|
"url": "git+https://pscode.lioncloud.net/psaiproducts/slingcli.git"
|
|
31
31
|
},
|
|
32
|
-
"slingVersion": "2.5.
|
|
32
|
+
"slingVersion": "2.5.20260724-1",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@earendil-works/pi-tui": "file:../.sling-pack/earendil-works-pi-tui-0.81.1.tgz",
|
|
35
35
|
"@earendil-works/pi-ai": "file:../.sling-pack/earendil-works-pi-ai-0.81.1.tgz",
|
package/slingshot/index.js
CHANGED
|
@@ -384,7 +384,7 @@ Log file: ${po}
|
|
|
384
384
|
`;ir.appendFileSync(po,n)}catch{}}function ct(t,e){if(!(!po||!ir||!Au))try{let i=`[${new Date().toISOString()}] ${t}:
|
|
385
385
|
${JSON.stringify(e,null,2)}
|
|
386
386
|
|
|
387
|
-
`;ir.appendFileSync(po,i)}catch{}}var or=null;function EE(t){if(!t)return;let e=t.trim();if(e)return e.replace(/\/+$/,"")}var ke=class t{static{this.BASE_URL="base_url"}static{this.ANALYTICS_DOMAIN="analytics_domain"}static{this.CLIENT_ID="client_id"}static{this.PROJECT_ID="project_id"}static{this.WORKSPACE_ID="workspace_id"}static{this.defaultValues={[t.BASE_URL]:"https://sapientaiproducts.com",[t.ANALYTICS_DOMAIN]:"https://slingshot.sapientaiproducts.com",[t.CLIENT_ID]:"b97fbef7-cad9-4e56-9850-39e86c8fdf61",[t.PROJECT_ID]:"fa8121c4-e2fc-48f1-9478-8949c04e13cc",[t.WORKSPACE_ID]:"6e5756eb-d7e2-4d80-ad07-9d7a51600d85"}}static{this.LOGIN_PATH="/web/v1/studio-auth/login"}static{this.EXCHANGE_PATH="/api/v1/studio-auth/auth/desktop/exchange"}static{this.REFRESH_PATH="/api/v3/auth/refreshtoken"}static{this.REFRESH_CLIENT_NAME="machine"}static{this.API_BASE_PATH="/api/v1/llm"}static{this.SAGE_EVENTS_PATH="/api/v1/ai-portal/sage_events"}static{this.APP_TOKEN_PATH="/api/v3/auth/app-token"}static{this.CONFIG_SERVICE_PATH="/api/v2/configservice/client"}static{this.APP_TOKEN_REFRESH_BUFFER_MS=60*1e3}static{this.SLINGSHOT_APP_TOKEN_ENV="SLINGSHOT_APP_TOKEN_HEADER"}static{this.TOKEN_EXPIRY_BUFFER_MS=300*1e3}static{this.SAPI="/save/api/v1"}static{this.CLIENT_NAME="desktop"}static defaults(e){return this.defaultValues[e]}static getLocalSettingsPath(){return Vm.resolve(process.cwd(),".sling","sling.settings.json")}static getGlobalSettingsPath(){return Vm.resolve(_e(),"sling.settings.json")}static getSettingsPath(e){if(e==="local")return this.getLocalSettingsPath();if(e==="global")return this.getGlobalSettingsPath();let n=this.getLocalSettingsPath();return pi.existsSync(n)?n:this.getGlobalSettingsPath()}static getSettings(){if(!or){let i=this.getSettingsPath();try{if(pi.existsSync(i)){let o=pi.readFileSync(i,"utf-8"),r=JSON.parse(o)||{};or={...this.defaultValues,...r}}else{let o=Vm.dirname(i);pi.existsSync(o)||pi.mkdirSync(o,{recursive:!0}),pi.writeFileSync(i,JSON.stringify(this.defaultValues,null,2),"utf-8"),or={...this.defaultValues}}}catch(o){ct("Error reading/writing sling.settings.json: ",o),or={...this.defaultValues}}}let e=EE(process.env.SLINGSHOT_API_DOMAIN),n=EE(process.env.SLINGSHOT_ANALYTICS_DOMAIN);return{...or,[t.BASE_URL]:e||or[t.BASE_URL],[t.ANALYTICS_DOMAIN]:n||or[t.ANALYTICS_DOMAIN]}}static updateSettings(e,n){let i=n?.scope??"global",o=this.getSettingsPath(i);try{let r={};if(pi.existsSync(o)){let l=pi.readFileSync(o,"utf-8");r=JSON.parse(l)||{}}let s={...this.defaultValues,...r,...e},a=Vm.dirname(o);pi.existsSync(a)||pi.mkdirSync(a,{recursive:!0}),pi.writeFileSync(o,JSON.stringify(s,null,2),"utf-8"),or=null}catch(r){ct("Error updating sling.settings.json: ",r)}}static getLoginUrl(e){let n=this.getSettings(),i=new URLSearchParams({client:this.CLIENT_NAME,port:String(e.port),localState:e.localState});return e.clientId&&i.set("clientId",e.clientId),`${n[t.BASE_URL]}${this.LOGIN_PATH}?${i.toString()}`}static getExchangeUrl(){return`${this.getSettings()[t.BASE_URL]}${this.EXCHANGE_PATH}`}static getRefreshUrl(){let e=this.getSettings(),n=new URLSearchParams({client:this.REFRESH_CLIENT_NAME});return`${e[t.BASE_URL]}${this.REFRESH_PATH}?${n.toString()}`}static getApiBaseUrl(){return`${this.getSettings()[t.BASE_URL]}${this.API_BASE_PATH}`}static getSageEventsUrl(){return`${this.getSettings()[t.ANALYTICS_DOMAIN]}${this.SAGE_EVENTS_PATH}`}static getTokenExpiryBuffer(){return this.TOKEN_EXPIRY_BUFFER_MS}static getDefaultProjectId(){let e=this.getSettings();return process.env.SLINGSHOT_PROJECT_ID||e[t.PROJECT_ID]}static getDefaultWorkspaceId(){let e=this.getSettings();return process.env.SLINGSHOT_WORKSPACE_ID||e[t.WORKSPACE_ID]}static getDefaultClientId(){let e=this.getSettings();return process.env.CLIENT_ID||e[t.CLIENT_ID]}static getUserActivityUrl(){return`${this.getSettings()[t.BASE_URL]}${this.SAPI}/users/activity`}static getUserUrl(){return`${this.getSettings()[t.BASE_URL]}${this.SAPI}/users`}static getAppTokenUrl(){return`${this.getSettings()[t.BASE_URL]}${this.APP_TOKEN_PATH}`}static getConfigServiceUrl(e){let n=this.getSettings(),i=this.getDefaultClientId(),o=new URLSearchParams({keys:e});return`${n[t.BASE_URL]}${this.CONFIG_SERVICE_PATH}/${i}?${o.toString()}`}static getAppTokenRefreshBuffer(){return this.APP_TOKEN_REFRESH_BUFFER_MS}};function Ou(t){try{let e=t.split(".");if(e.length!==3)return 0;let n=JSON.parse(atob(e[1]));return n.exp?n.exp*1e3:0}catch{return 0}}function AE(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}var Tb="Xq7Wm2zR9pLkVbN4cD8fH3jT6yG1sA5",rz=BigInt(Tb.length);function sz(t){if(t.length===0)return"";let e=0n;for(let i of t){let o=Tb.indexOf(i);if(o===-1)throw new Error(`Cannot decode app_key: character "${i}" is not in the expected alphabet`);e=e*rz+BigInt(o)}let n=[];for(;e>0n;)n.unshift(Number(e&0xffn)),e>>=8n;for(let i of t)if(i===Tb[0])n.unshift(0);else break;return new TextDecoder().decode(new Uint8Array(n))}var Cb=new Map,Qm=new Map;async function az(t,e){let n=ke.getConfigServiceUrl(t);qe(`sling-config: fetching ${n}`);let i;try{i=await fetch(n,{method:"GET",headers:{Accept:"application/json",Authorization:`Bearer ${e}`}})}catch(s){let a=s instanceof Error?s.message:String(s);throw new Error(`Cannot reach config service: ${a}`)}if(!i.ok){let s=`${i.status} ${i.statusText}`;try{let a=await i.json();a.message?s=String(a.message):a.error&&(s=String(a.error))}catch{}throw new Error(`Config service request failed: ${s}`)}let r=(await i.json())?.data?.config;if(!r||typeof r!="object")throw new Error("Config service response missing data.config");return r}async function _E(t,e){let n=Cb.get(t);if(n)return n;let i=Qm.get(t);if(i)return i;if(!e)throw new Error("Cannot reach config service: no Slingshot user token provided");let o=az(t,e).then(r=>(Cb.set(t,r),r)).finally(()=>{Qm.delete(t)});return Qm.set(t,o),o}var Ol=class{static async getSlingcliConfig(e){let n=await _E("slingcli",e),i=n.slingcli;if(!i||typeof i.app_id!="string"||typeof i.app_key!="string"||!i.app_id||!i.app_key)throw ct("sling-config: missing slingcli block",n),new Error("Config service did not return slingcli.app_id / slingcli.app_key for this client");return{app_id:i.app_id,app_key:sz(i.app_key)}}static async getRemoteConfig(e,n){return _E(e,n)}static clearCache(){Cb.clear(),Qm=new Map}};import OE from"node:path";import rr from"node:fs";var lz="sling.app-creds.json";function Mb(){return OE.resolve(_e(),lz)}function LE(){let t=Mb();if(!rr.existsSync(t))return null;try{let e=rr.readFileSync(t,"utf-8"),n=JSON.parse(e);return typeof n.app_id!="string"||typeof n.app_key!="string"||!n.app_id||!n.app_key?(ct("app-creds-store: invalid creds file, ignoring",n),null):{app_id:n.app_id,app_key:n.app_key}}catch(e){return ct("app-creds-store: failed to read creds file",e),null}}function Rb(t){let e=Mb(),n=OE.dirname(e);try{rr.existsSync(n)||rr.mkdirSync(n,{recursive:!0});let i={...t,savedAt:Date.now()};rr.writeFileSync(e,JSON.stringify(i,null,2),{encoding:"utf-8",mode:384});try{rr.chmodSync(e,384)}catch{}qe(`app-creds-store: persisted to ${e}`)}catch(i){ct("app-creds-store: failed to persist creds",i)}}function WE(){let t=Mb();try{rr.existsSync(t)&&(rr.unlinkSync(t),qe(`app-creds-store: cleared ${t}`))}catch(e){ct("app-creds-store: failed to clear creds file",e)}}var Jm=class extends Error{constructor(n,i){super(i);this.status=n;this.name="AppTokenHttpError"}},Lu=null,Wu=null,Ym=null,Ll=null;function FE(t){process.env[ke.SLINGSHOT_APP_TOKEN_ENV]=`Bearer ${t}`}function cz(t){Ll&&(clearTimeout(Ll),Ll=null);let e=t.expiresAt-Date.now();e<=0||(Ll=setTimeout(()=>{Ll=null,Yn().catch(n=>{ct("app-token: scheduled refresh failed",n)})},e),Ll.unref?.())}async function DE(t){let e=Buffer.from(`${t.app_id}:${t.app_key}`).toString("base64"),n=ke.getAppTokenUrl();qe(`app-token: minting from ${n}`);let i;try{i=await fetch(n,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${e}`}})}catch(a){let l=a instanceof Error?a.message:String(a);throw new Error(`Cannot reach app-token service: ${l}`)}if(!i.ok){let a=`${i.status} ${i.statusText}`;try{let l=await i.text()||"";l&&(a=l)}catch{}throw new Jm(i.status,`App token request failed: ${a}`)}let o=await i.json();if(!o.app_token||typeof o.expires_in!="number")throw new Error("App token response missing app_token or expires_in");let r=ke.getAppTokenRefreshBuffer(),s=Date.now()+o.expires_in*1e3-r;return qe(`app-token: minted, expires at ${new Date(s).toISOString()}`),{token:o.app_token,expiresAt:s}}async function uz(){let t=LE();if(t)return{creds:t,fromDisk:!0};if(!Wu)throw new Error("Cannot mint app token: no on-disk app credentials and no Slingshot user token available (please /login slingshot first)");let e=await Ol.getSlingcliConfig(Wu);return Rb(e),{creds:e,fromDisk:!1}}async function dz(){let{creds:t,fromDisk:e}=await uz();try{return await DE(t)}catch(n){let i=n instanceof Jm&&(n.status===401||n.status===403);if(!e||!i)throw n;if(ct("app-token: disk creds rejected (likely rotated), refetching from config service",{status:n.status}),WE(),!Wu)throw new Error("Cannot rotate app credentials: on-disk creds rejected and no Slingshot user token available (please /login slingshot)");let o=await Ol.getSlingcliConfig(Wu);return Rb(o),await DE(o)}}async function Yn(t){if(t&&(Wu=t),Lu&&Lu.expiresAt>Date.now())return FE(Lu.token),Lu.token;if(Ym)return(await Ym).token;let e=dz().then(i=>(Lu=i,FE(i.token),cz(i),i)).finally(()=>{Ym=null});return Ym=e,(await e).token}var Fu=null,Pb=null;typeof process<"u"&&process.versions?.node&&(Pb=import("node:http").then(t=>{Fu=t.createServer}));async function pz(){if(Fu||(Pb&&await Pb,Fu))return Fu;throw new Error("Slingshot OAuth requires Node.js")}async function Ib(t){let e=await pz(),n,i,o,r=!1,s=new Promise((u,d)=>{i=u,o=d}),a=u=>{if(!r){r=!0;try{n.close()}catch{}u()}};n=e((u,d)=>{let p=new URL(u.url||"","http://127.0.0.1"),m=p.searchParams.get("code"),g=p.searchParams.get("state"),h=p.searchParams.get("clientId"),f=p.searchParams.get("error"),b=p.searchParams.get("error_description");if(f){d.writeHead(400,{"Content-Type":"text/html"}),d.end(`<html><body><h1>Login Failed</h1><p>${b||f}</p><p>You can close this window.</p></body></html>`),a(()=>o(new Error(`Login failed: ${b||f}`)));return}if(!m||!g){d.writeHead(400,{"Content-Type":"text/html"}),d.end("<html><body><h1>Login Failed</h1><p>Missing code or state in callback.</p><p>You can close this window.</p></body></html>"),a(()=>o(new Error("Missing code or state in callback")));return}d.writeHead(200,{"Content-Type":"text/html"}),d.end("<html><body><h1>Login Successful</h1><p>You can close this window and return to your terminal.</p><script>setTimeout(()=>window.close(),3000)</script></body></html>"),a(()=>i({code:m,state:g,clientId:h||""}))}),n.on("error",u=>{a(()=>o(u))});let l=setTimeout(()=>{a(()=>o(new Error("Login timeout - no callback received within 5 minutes")))},300*1e3);return n.on("close",()=>clearTimeout(l)),t&&t.addEventListener("abort",()=>{a(()=>o(new Error("Login cancelled")))}),{port:await new Promise((u,d)=>{n.once("error",d),n.listen(0,"127.0.0.1",()=>{let p=n.address();p&&typeof p=="object"?u(p.port):d(new Error("Failed to obtain loopback server port"))})}),result:s}}async function Eb(t,e){if(!t)throw new Error("Missing exchange code");if(!e)throw new Error("Missing clientId for exchange");let n=ke.getExchangeUrl(),i;try{i=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",accept:"application/json"},body:JSON.stringify({code:t,clientId:e})})}catch(r){let s=r instanceof Error?r.message:String(r);throw new Error(`Cannot reach Studio Auth: ${s}`)}if(!i.ok){let r,s=`${i.status} ${i.statusText}`;try{let a=await i.json();r=a.error?.code,a.error?.message?s=a.error.message:a.message?s=a.message:r&&(s=r)}catch{}throw r==="INVALID_CALLBACK"?new Error("Login failed: exchange code is expired, already used, or bound to a different tenant. Please log in again."):new Error(`Code exchange failed: ${s}`)}let o=await i.json();if(!o.accessToken||!o.refreshToken)throw new Error("Exchange response missing accessToken or refreshToken");return o}function hz(){return mz(16).toString("hex")}function gz(t){let e=new URL(t),n=e.searchParams.get("code"),i=e.searchParams.get("state"),o=e.searchParams.get("clientId");if(!n||!i)throw new Error("Pasted URL is missing code or state");return{code:n,state:i,clientId:o||""}}async function Ab(t){let e=process.env.SLINGSHOT_TOKEN;if(e){let u=Ou(e);return qe("Using Slingshot token from SLINGSHOT_TOKEN environment variable"),await Yn(e),{refresh:"",access:e,expires:u>0?u-ke.getTokenExpiryBuffer():Date.now()+10800*1e3,projectId:ke.getDefaultProjectId(),workspaceId:ke.getDefaultWorkspaceId()}}let{port:n,result:i}=await Ib(t.signal),o=hz(),r=ke.getDefaultClientId(),s=ke.getLoginUrl({port:n,localState:o,clientId:r||void 0});t.onAuth({url:s});let a;if(t.onManualCodeInput){let u=t.onManualCodeInput().then(gz);a=await Promise.race([i,u])}else a=await i;if(a.state!==o)throw new Error("CSRF check failed - state does not match localState");if(!a.clientId)throw new Error("Login callback did not include clientId");let l=await Eb(a.code,a.clientId),c=Ou(l.accessToken);return await Yn(l.accessToken),{refresh:l.refreshToken,access:l.accessToken,expires:c>0?c-ke.getTokenExpiryBuffer():Date.now()+10800*1e3,projectId:ke.getDefaultProjectId(),workspaceId:ke.getDefaultWorkspaceId()}}import{randomUUID as fz}from"node:crypto";async function Xm(t){if(!t.refresh)throw new Error("No refresh token available. Please login again.");let e;try{e=await Yn()}catch(a){throw ct("auth/refresh: app token unavailable for refresh call",a),new Error(`Cannot refresh Slingshot token: app token unavailable (${a instanceof Error?a.message:String(a)}). Please /login slingshot.`)}let n=fz(),i={accept:"application/json",rt:t.refresh,"trace-id":n,Authorization:`Bearer ${e}`},o;try{let a=ke.getRefreshUrl();o=await fetch(a,{headers:i})}catch(a){let l=a instanceof Error?a.message:String(a);throw new Error(`Cannot reach Slingshot server: ${l}`)}if(!o.ok){let a=`${o.status} ${o.statusText}`;try{let l=await o.json();l.message?a=String(l.message):l.error&&(a=String(l.error))}catch{}throw new Error(`Token refresh failed: ${a}`)}let r=await o.json();if(!r.accessToken)throw new Error("No access token in refresh response");let s=Ou(r.accessToken);try{await Yn(r.accessToken)}catch(a){throw ct("auth/refresh: app token refresh failed",a),a}return{refresh:r.refreshToken||t.refresh,access:r.accessToken,expires:s>0?s-ke.getTokenExpiryBuffer():Date.now()+10800*1e3,projectId:t.projectId,workspaceId:t.workspaceId}}var UE=[{id:"gpt-5.4-nano",name:"GPT-5.4 nano",baseUrl:"",reasoning:!0,thinkingLevelMap:{xhigh:"xhigh"},input:["text","image"],cost:{input:.2,output:1.25,cacheRead:.02,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,api:"openai-responses",provider:"slingshot"},{id:"gpt-4.1",name:"GPT-4.1",baseUrl:"",reasoning:!1,input:["text","image"],cost:{input:2,output:8,cacheRead:.5,cacheWrite:0},contextWindow:1047576,maxTokens:32768,provider:"slingshot",api:"openai-completions"},{id:"gpt-5",name:"GPT-5",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:1.25,output:10,cacheRead:.125,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"gpt-5-mini",name:"GPT-5 Mini",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:.25,output:2,cacheRead:.025,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"gpt-5-nano",name:"GPT-5 Nano",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:.05,output:.4,cacheRead:.005,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"gpt-5.1",name:"GPT-5.1",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:1.25,output:10,cacheRead:.13,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"gpt-5.2",name:"GPT-5.2",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:1.75,output:14,cacheRead:.175,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"gpt-5.4-mini",name:"GPT-5.4 mini",baseUrl:"",reasoning:!0,thinkingLevelMap:{xhigh:"xhigh"},input:["text","image"],cost:{input:.75,output:4.5,cacheRead:.075,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,api:"openai-responses",provider:"slingshot"},{id:"gpt-5.4",name:"GPT-5.4",baseUrl:"",reasoning:!0,thinkingLevelMap:{xhigh:"xhigh"},input:["text","image"],cost:{input:2.5,output:15,cacheRead:.25,cacheWrite:0},contextWindow:272e3,maxTokens:128e3,api:"openai-responses",provider:"slingshot"},{id:"gpt-5.5",name:"GPT-5.5",baseUrl:"",reasoning:!0,thinkingLevelMap:{xhigh:"xhigh"},input:["text","image"],cost:{input:5,output:30,cacheRead:.5,cacheWrite:0},contextWindow:272e3,maxTokens:128e3,api:"openai-responses",provider:"slingshot"},{id:"gpt-5.2-codex",name:"GPT-5.2 Codex",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:1.75,output:14,cacheRead:.175,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"gpt-5.3-codex",name:"GPT-5.3 Codex",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:1.75,output:14,cacheRead:.175,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"claude-opus-4@20250514",name:"Claude Opus 4",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75},contextWindow:2e5,maxTokens:32e3,provider:"slingshot",api:"openai-completions"},{id:"claude-sonnet-4@20250514",name:"Claude Sonnet 4",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},contextWindow:2e5,maxTokens:64e3,provider:"slingshot",api:"openai-completions"},{id:"claude-sonnet-4-5@20250929",name:"Claude Sonnet 4.5",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},contextWindow:2e5,maxTokens:64e3,provider:"slingshot",api:"openai-completions"},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},contextWindow:1e6,maxTokens:64e3,provider:"slingshot",api:"openai-completions"},{id:"claude-opus-4-6",name:"Claude Opus 4.6",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:5,output:25,cacheRead:.5,cacheWrite:6.25},contextWindow:1e6,maxTokens:128e3,provider:"slingshot",api:"openai-completions"},{id:"o3",name:"O3",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:2,output:8,cacheRead:.5,cacheWrite:0},contextWindow:2e5,maxTokens:1e5,provider:"slingshot",api:"openai-completions"},{id:"o3-mini",name:"o3-mini",baseUrl:"",reasoning:!0,input:["text"],cost:{input:1.1,output:4.4,cacheRead:.55,cacheWrite:0},contextWindow:2e5,maxTokens:1e5,provider:"slingshot",api:"openai-completions"},{id:"o4-mini",name:"o4-mini",baseUrl:"",reasoning:!0,input:["text"],cost:{input:1.1,output:4.4,cacheRead:.28,cacheWrite:0},contextWindow:2e5,maxTokens:1e5,provider:"slingshot",api:"openai-completions"},{id:"gemini-2.5-flash",name:"Gemini 2.5 Flash",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:.3,output:2.5,cacheRead:.075,cacheWrite:0},contextWindow:1048576,maxTokens:65536,provider:"slingshot",api:"openai-completions"}];var Zm={name:"slingshot.cli",private:!0,type:"module",workspaces:["packages/*","packages/web-ui/example","packages/coding-agent/examples/extensions/with-deps","packages/coding-agent/examples/extensions/custom-provider-anthropic","packages/coding-agent/examples/extensions/custom-provider-gitlab-duo"],scripts:{clean:"npm run clean --workspaces",build:"cd packages/tui && npm run build && cd ../ai && npm run build && cd ../agent && npm run build && cd ../storage/sqlite-node && npm run build && cd ../../coding-agent && npm run build && cd ../server && npm run build","build:offline":"cd packages/tui && npm run build && cd ../ai && npm run build:offline && cd ../agent && npm run build && cd ../storage/sqlite-node && npm run build && cd ../../coding-agent && npm run build && cd ../server && npm run build",dev:'concurrently --names "ai,agent,coding-agent,web-ui,tui" --prefix-colors "cyan,yellow,red,white,green,magenta" "cd packages/ai && npm run dev" "cd packages/agent && npm run dev" "cd packages/coding-agent && npm run dev" "cd packages/server && npm run dev" "cd packages/tui && npm run dev"',"dev:tsc":'concurrently --names "ai,web-ui" --prefix-colors "cyan,green" "cd packages/ai && npm run dev:tsc" "cd packages/web-ui && npm run dev:tsc"',check:"","check:browser-smoke":"","test:models":"node scripts/test-models.mjs","profile:tui":"node scripts/profile-coding-agent-node.mjs --mode tui","profile:rpc":"node scripts/profile-coding-agent-node.mjs --mode rpc",test:"npm run test --workspaces --if-present","version:patch":"npm version patch -ws --no-git-tag-version && node scripts/sync-versions.js && shx rm -rf node_modules packages/*/node_modules package-lock.json && npm install","version:minor":"npm version minor -ws --no-git-tag-version && node scripts/sync-versions.js && shx rm -rf node_modules packages/*/node_modules package-lock.json && npm install","version:major":"npm version major -ws --no-git-tag-version && node scripts/sync-versions.js && shx rm -rf node_modules packages/*/node_modules package-lock.json && npm install","version:set":"npm version -ws",prepublishOnly:"npm run clean && npm run build && npm run check",publish:"npm run prepublishOnly && npm publish -ws --access public","publish:dry":"npm run prepublishOnly && npm publish -ws --access public --dry-run","release:patch":"node scripts/release.mjs patch","release:minor":"node scripts/release.mjs minor","release:major":"node scripts/release.mjs major",prepare:"husky"},devDependencies:{"@anthropic-ai/sandbox-runtime":"0.0.57","@biomejs/biome":"2.3.15","@types/better-sqlite3":"^7.6.13","@types/lodash.mergewith":"^4.6.9","@types/node":"24.13.2","@types/turndown":"^5.0.6","@typescript/native-preview":"7.0.0-dev.20260120.1",concurrently:"^9.2.3",esbuild:"0.28.1","fast-xml-parser":"^5.9.3",husky:"9.1.7",jiti:"2.7.0",psadk:"^1.5.1",shx:"0.4.0",tsx:"4.22.4",turbo:"^2.9.18",typescript:"5.9.3",vitest:"^4.1.9"},engines:{node:">=20.0.0"},slingVersion:"2.5.20260723-1",overrides:{postcss:"8.5.14",next:{postcss:"8.5.14"},"ip-address":"^10.1.1","@modelcontextprotocol/sdk":"^1.29.0",ai:">=5.0.52","fast-xml-parser":"^5.9.3","@aws-sdk/xml-builder":{"fast-xml-parser":"^5.9.3"},"adaptivecards-templating":{"adaptive-expressions":{"fast-xml-parser":"^5.5.8"}},picomatch:"^4.0.4","path-to-regexp":"8.4.1",router:{"path-to-regexp":"8.4.1"},minimatch:"^10.2.3",tar:"7.5.11",react:"19.1.1","react-dom":"19.1.1","@types/react":"19","@types/react-dom":"19",tailwindcss:"4.1.12",lightningcss:"1.30.2",glob:{".":"11.1.0",minimatch:"10.2.3"},prismjs:"^1.30.0",qs:"^6.15.0","@hono/node-server":"1.19.14",protobufjs:"^8.2.0","@opentelemetry/otlp-transformer":{protobufjs:"^8.2.0"},langchain:{langsmith:">=0.7.0"},hono:"4.12.18",fsevents:"^2.3.3",swiper:"^12.1.2",lodash:"^4.18.0","lodash-es":"^4.18.1",axios:"^1.15.0","ibm-cloud-sdk-core":"^5.4.11",dompurify:">=3.4.0","react-markdown-mermaid":{mermaid:"10.9.6"}},dependencies:{"@modelcontextprotocol/sdk":"^1.29.0","@mozilla/readability":"^0.6.0","better-sqlite3":"^12.11.1","compound-engineering-pi":"^0.2.4","get-east-asian-width":"^1.4.0",linkedom:"^0.18.12",turndown:"^7.2.4",unpdf:"^1.6.2"}};import Du from"chalk";function $E(t,e){return{render(n){let i=` \u26AC _______. __ __ .__ __. _______
|
|
387
|
+
`;ir.appendFileSync(po,i)}catch{}}var or=null;function EE(t){if(!t)return;let e=t.trim();if(e)return e.replace(/\/+$/,"")}var ke=class t{static{this.BASE_URL="base_url"}static{this.ANALYTICS_DOMAIN="analytics_domain"}static{this.CLIENT_ID="client_id"}static{this.PROJECT_ID="project_id"}static{this.WORKSPACE_ID="workspace_id"}static{this.defaultValues={[t.BASE_URL]:"https://sapientaiproducts.com",[t.ANALYTICS_DOMAIN]:"https://slingshot.sapientaiproducts.com",[t.CLIENT_ID]:"b97fbef7-cad9-4e56-9850-39e86c8fdf61",[t.PROJECT_ID]:"fa8121c4-e2fc-48f1-9478-8949c04e13cc",[t.WORKSPACE_ID]:"6e5756eb-d7e2-4d80-ad07-9d7a51600d85"}}static{this.LOGIN_PATH="/web/v1/studio-auth/login"}static{this.EXCHANGE_PATH="/api/v1/studio-auth/auth/desktop/exchange"}static{this.REFRESH_PATH="/api/v3/auth/refreshtoken"}static{this.REFRESH_CLIENT_NAME="machine"}static{this.API_BASE_PATH="/api/v1/llm"}static{this.SAGE_EVENTS_PATH="/api/v1/ai-portal/sage_events"}static{this.APP_TOKEN_PATH="/api/v3/auth/app-token"}static{this.CONFIG_SERVICE_PATH="/api/v2/configservice/client"}static{this.APP_TOKEN_REFRESH_BUFFER_MS=60*1e3}static{this.SLINGSHOT_APP_TOKEN_ENV="SLINGSHOT_APP_TOKEN_HEADER"}static{this.TOKEN_EXPIRY_BUFFER_MS=300*1e3}static{this.SAPI="/save/api/v1"}static{this.CLIENT_NAME="desktop"}static defaults(e){return this.defaultValues[e]}static getLocalSettingsPath(){return Vm.resolve(process.cwd(),".sling","sling.settings.json")}static getGlobalSettingsPath(){return Vm.resolve(_e(),"sling.settings.json")}static getSettingsPath(e){if(e==="local")return this.getLocalSettingsPath();if(e==="global")return this.getGlobalSettingsPath();let n=this.getLocalSettingsPath();return pi.existsSync(n)?n:this.getGlobalSettingsPath()}static getSettings(){if(!or){let i=this.getSettingsPath();try{if(pi.existsSync(i)){let o=pi.readFileSync(i,"utf-8"),r=JSON.parse(o)||{};or={...this.defaultValues,...r}}else{let o=Vm.dirname(i);pi.existsSync(o)||pi.mkdirSync(o,{recursive:!0}),pi.writeFileSync(i,JSON.stringify(this.defaultValues,null,2),"utf-8"),or={...this.defaultValues}}}catch(o){ct("Error reading/writing sling.settings.json: ",o),or={...this.defaultValues}}}let e=EE(process.env.SLINGSHOT_API_DOMAIN),n=EE(process.env.SLINGSHOT_ANALYTICS_DOMAIN);return{...or,[t.BASE_URL]:e||or[t.BASE_URL],[t.ANALYTICS_DOMAIN]:n||or[t.ANALYTICS_DOMAIN]}}static updateSettings(e,n){let i=n?.scope??"global",o=this.getSettingsPath(i);try{let r={};if(pi.existsSync(o)){let l=pi.readFileSync(o,"utf-8");r=JSON.parse(l)||{}}let s={...this.defaultValues,...r,...e},a=Vm.dirname(o);pi.existsSync(a)||pi.mkdirSync(a,{recursive:!0}),pi.writeFileSync(o,JSON.stringify(s,null,2),"utf-8"),or=null}catch(r){ct("Error updating sling.settings.json: ",r)}}static getLoginUrl(e){let n=this.getSettings(),i=new URLSearchParams({client:this.CLIENT_NAME,port:String(e.port),localState:e.localState});return e.clientId&&i.set("clientId",e.clientId),`${n[t.BASE_URL]}${this.LOGIN_PATH}?${i.toString()}`}static getExchangeUrl(){return`${this.getSettings()[t.BASE_URL]}${this.EXCHANGE_PATH}`}static getRefreshUrl(){let e=this.getSettings(),n=new URLSearchParams({client:this.REFRESH_CLIENT_NAME});return`${e[t.BASE_URL]}${this.REFRESH_PATH}?${n.toString()}`}static getApiBaseUrl(){return`${this.getSettings()[t.BASE_URL]}${this.API_BASE_PATH}`}static getSageEventsUrl(){return`${this.getSettings()[t.ANALYTICS_DOMAIN]}${this.SAGE_EVENTS_PATH}`}static getTokenExpiryBuffer(){return this.TOKEN_EXPIRY_BUFFER_MS}static getDefaultProjectId(){let e=this.getSettings();return process.env.SLINGSHOT_PROJECT_ID||e[t.PROJECT_ID]}static getDefaultWorkspaceId(){let e=this.getSettings();return process.env.SLINGSHOT_WORKSPACE_ID||e[t.WORKSPACE_ID]}static getDefaultClientId(){let e=this.getSettings();return process.env.CLIENT_ID||e[t.CLIENT_ID]}static getUserActivityUrl(){return`${this.getSettings()[t.BASE_URL]}${this.SAPI}/users/activity`}static getUserUrl(){return`${this.getSettings()[t.BASE_URL]}${this.SAPI}/users`}static getAppTokenUrl(){return`${this.getSettings()[t.BASE_URL]}${this.APP_TOKEN_PATH}`}static getConfigServiceUrl(e){let n=this.getSettings(),i=this.getDefaultClientId(),o=new URLSearchParams({keys:e});return`${n[t.BASE_URL]}${this.CONFIG_SERVICE_PATH}/${i}?${o.toString()}`}static getAppTokenRefreshBuffer(){return this.APP_TOKEN_REFRESH_BUFFER_MS}};function Ou(t){try{let e=t.split(".");if(e.length!==3)return 0;let n=JSON.parse(atob(e[1]));return n.exp?n.exp*1e3:0}catch{return 0}}function AE(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}var Tb="Xq7Wm2zR9pLkVbN4cD8fH3jT6yG1sA5",rz=BigInt(Tb.length);function sz(t){if(t.length===0)return"";let e=0n;for(let i of t){let o=Tb.indexOf(i);if(o===-1)throw new Error(`Cannot decode app_key: character "${i}" is not in the expected alphabet`);e=e*rz+BigInt(o)}let n=[];for(;e>0n;)n.unshift(Number(e&0xffn)),e>>=8n;for(let i of t)if(i===Tb[0])n.unshift(0);else break;return new TextDecoder().decode(new Uint8Array(n))}var Cb=new Map,Qm=new Map;async function az(t,e){let n=ke.getConfigServiceUrl(t);qe(`sling-config: fetching ${n}`);let i;try{i=await fetch(n,{method:"GET",headers:{Accept:"application/json",Authorization:`Bearer ${e}`}})}catch(s){let a=s instanceof Error?s.message:String(s);throw new Error(`Cannot reach config service: ${a}`)}if(!i.ok){let s=`${i.status} ${i.statusText}`;try{let a=await i.json();a.message?s=String(a.message):a.error&&(s=String(a.error))}catch{}throw new Error(`Config service request failed: ${s}`)}let r=(await i.json())?.data?.config;if(!r||typeof r!="object")throw new Error("Config service response missing data.config");return r}async function _E(t,e){let n=Cb.get(t);if(n)return n;let i=Qm.get(t);if(i)return i;if(!e)throw new Error("Cannot reach config service: no Slingshot user token provided");let o=az(t,e).then(r=>(Cb.set(t,r),r)).finally(()=>{Qm.delete(t)});return Qm.set(t,o),o}var Ol=class{static async getSlingcliConfig(e){let n=await _E("slingcli",e),i=n.slingcli;if(!i||typeof i.app_id!="string"||typeof i.app_key!="string"||!i.app_id||!i.app_key)throw ct("sling-config: missing slingcli block",n),new Error("Config service did not return slingcli.app_id / slingcli.app_key for this client");return{app_id:i.app_id,app_key:sz(i.app_key)}}static async getRemoteConfig(e,n){return _E(e,n)}static clearCache(){Cb.clear(),Qm=new Map}};import OE from"node:path";import rr from"node:fs";var lz="sling.app-creds.json";function Mb(){return OE.resolve(_e(),lz)}function LE(){let t=Mb();if(!rr.existsSync(t))return null;try{let e=rr.readFileSync(t,"utf-8"),n=JSON.parse(e);return typeof n.app_id!="string"||typeof n.app_key!="string"||!n.app_id||!n.app_key?(ct("app-creds-store: invalid creds file, ignoring",n),null):{app_id:n.app_id,app_key:n.app_key}}catch(e){return ct("app-creds-store: failed to read creds file",e),null}}function Rb(t){let e=Mb(),n=OE.dirname(e);try{rr.existsSync(n)||rr.mkdirSync(n,{recursive:!0});let i={...t,savedAt:Date.now()};rr.writeFileSync(e,JSON.stringify(i,null,2),{encoding:"utf-8",mode:384});try{rr.chmodSync(e,384)}catch{}qe(`app-creds-store: persisted to ${e}`)}catch(i){ct("app-creds-store: failed to persist creds",i)}}function WE(){let t=Mb();try{rr.existsSync(t)&&(rr.unlinkSync(t),qe(`app-creds-store: cleared ${t}`))}catch(e){ct("app-creds-store: failed to clear creds file",e)}}var Jm=class extends Error{constructor(n,i){super(i);this.status=n;this.name="AppTokenHttpError"}},Lu=null,Wu=null,Ym=null,Ll=null;function FE(t){process.env[ke.SLINGSHOT_APP_TOKEN_ENV]=`Bearer ${t}`}function cz(t){Ll&&(clearTimeout(Ll),Ll=null);let e=t.expiresAt-Date.now();e<=0||(Ll=setTimeout(()=>{Ll=null,Yn().catch(n=>{ct("app-token: scheduled refresh failed",n)})},e),Ll.unref?.())}async function DE(t){let e=Buffer.from(`${t.app_id}:${t.app_key}`).toString("base64"),n=ke.getAppTokenUrl();qe(`app-token: minting from ${n}`);let i;try{i=await fetch(n,{method:"GET",headers:{Accept:"application/json",Authorization:`Basic ${e}`}})}catch(a){let l=a instanceof Error?a.message:String(a);throw new Error(`Cannot reach app-token service: ${l}`)}if(!i.ok){let a=`${i.status} ${i.statusText}`;try{let l=await i.text()||"";l&&(a=l)}catch{}throw new Jm(i.status,`App token request failed: ${a}`)}let o=await i.json();if(!o.app_token||typeof o.expires_in!="number")throw new Error("App token response missing app_token or expires_in");let r=ke.getAppTokenRefreshBuffer(),s=Date.now()+o.expires_in*1e3-r;return qe(`app-token: minted, expires at ${new Date(s).toISOString()}`),{token:o.app_token,expiresAt:s}}async function uz(){let t=LE();if(t)return{creds:t,fromDisk:!0};if(!Wu)throw new Error("Cannot mint app token: no on-disk app credentials and no Slingshot user token available (please /login slingshot first)");let e=await Ol.getSlingcliConfig(Wu);return Rb(e),{creds:e,fromDisk:!1}}async function dz(){let{creds:t,fromDisk:e}=await uz();try{return await DE(t)}catch(n){let i=n instanceof Jm&&(n.status===401||n.status===403);if(!e||!i)throw n;if(ct("app-token: disk creds rejected (likely rotated), refetching from config service",{status:n.status}),WE(),!Wu)throw new Error("Cannot rotate app credentials: on-disk creds rejected and no Slingshot user token available (please /login slingshot)");let o=await Ol.getSlingcliConfig(Wu);return Rb(o),await DE(o)}}async function Yn(t){if(t&&(Wu=t),Lu&&Lu.expiresAt>Date.now())return FE(Lu.token),Lu.token;if(Ym)return(await Ym).token;let e=dz().then(i=>(Lu=i,FE(i.token),cz(i),i)).finally(()=>{Ym=null});return Ym=e,(await e).token}var Fu=null,Pb=null;typeof process<"u"&&process.versions?.node&&(Pb=import("node:http").then(t=>{Fu=t.createServer}));async function pz(){if(Fu||(Pb&&await Pb,Fu))return Fu;throw new Error("Slingshot OAuth requires Node.js")}async function Ib(t){let e=await pz(),n,i,o,r=!1,s=new Promise((u,d)=>{i=u,o=d}),a=u=>{if(!r){r=!0;try{n.close()}catch{}u()}};n=e((u,d)=>{let p=new URL(u.url||"","http://127.0.0.1"),m=p.searchParams.get("code"),g=p.searchParams.get("state"),h=p.searchParams.get("clientId"),f=p.searchParams.get("error"),b=p.searchParams.get("error_description");if(f){d.writeHead(400,{"Content-Type":"text/html"}),d.end(`<html><body><h1>Login Failed</h1><p>${b||f}</p><p>You can close this window.</p></body></html>`),a(()=>o(new Error(`Login failed: ${b||f}`)));return}if(!m||!g){d.writeHead(400,{"Content-Type":"text/html"}),d.end("<html><body><h1>Login Failed</h1><p>Missing code or state in callback.</p><p>You can close this window.</p></body></html>"),a(()=>o(new Error("Missing code or state in callback")));return}d.writeHead(200,{"Content-Type":"text/html"}),d.end("<html><body><h1>Login Successful</h1><p>You can close this window and return to your terminal.</p><script>setTimeout(()=>window.close(),3000)</script></body></html>"),a(()=>i({code:m,state:g,clientId:h||""}))}),n.on("error",u=>{a(()=>o(u))});let l=setTimeout(()=>{a(()=>o(new Error("Login timeout - no callback received within 5 minutes")))},300*1e3);return n.on("close",()=>clearTimeout(l)),t&&t.addEventListener("abort",()=>{a(()=>o(new Error("Login cancelled")))}),{port:await new Promise((u,d)=>{n.once("error",d),n.listen(0,"127.0.0.1",()=>{let p=n.address();p&&typeof p=="object"?u(p.port):d(new Error("Failed to obtain loopback server port"))})}),result:s}}async function Eb(t,e){if(!t)throw new Error("Missing exchange code");if(!e)throw new Error("Missing clientId for exchange");let n=ke.getExchangeUrl(),i;try{i=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json",accept:"application/json"},body:JSON.stringify({code:t,clientId:e})})}catch(r){let s=r instanceof Error?r.message:String(r);throw new Error(`Cannot reach Studio Auth: ${s}`)}if(!i.ok){let r,s=`${i.status} ${i.statusText}`;try{let a=await i.json();r=a.error?.code,a.error?.message?s=a.error.message:a.message?s=a.message:r&&(s=r)}catch{}throw r==="INVALID_CALLBACK"?new Error("Login failed: exchange code is expired, already used, or bound to a different tenant. Please log in again."):new Error(`Code exchange failed: ${s}`)}let o=await i.json();if(!o.accessToken||!o.refreshToken)throw new Error("Exchange response missing accessToken or refreshToken");return o}function hz(){return mz(16).toString("hex")}function gz(t){let e=new URL(t),n=e.searchParams.get("code"),i=e.searchParams.get("state"),o=e.searchParams.get("clientId");if(!n||!i)throw new Error("Pasted URL is missing code or state");return{code:n,state:i,clientId:o||""}}async function Ab(t){let e=process.env.SLINGSHOT_TOKEN;if(e){let u=Ou(e);return qe("Using Slingshot token from SLINGSHOT_TOKEN environment variable"),await Yn(e),{refresh:"",access:e,expires:u>0?u-ke.getTokenExpiryBuffer():Date.now()+10800*1e3,projectId:ke.getDefaultProjectId(),workspaceId:ke.getDefaultWorkspaceId()}}let{port:n,result:i}=await Ib(t.signal),o=hz(),r=ke.getDefaultClientId(),s=ke.getLoginUrl({port:n,localState:o,clientId:r||void 0});t.onAuth({url:s});let a;if(t.onManualCodeInput){let u=t.onManualCodeInput().then(gz);a=await Promise.race([i,u])}else a=await i;if(a.state!==o)throw new Error("CSRF check failed - state does not match localState");if(!a.clientId)throw new Error("Login callback did not include clientId");let l=await Eb(a.code,a.clientId),c=Ou(l.accessToken);return await Yn(l.accessToken),{refresh:l.refreshToken,access:l.accessToken,expires:c>0?c-ke.getTokenExpiryBuffer():Date.now()+10800*1e3,projectId:ke.getDefaultProjectId(),workspaceId:ke.getDefaultWorkspaceId()}}import{randomUUID as fz}from"node:crypto";async function Xm(t){if(!t.refresh)throw new Error("No refresh token available. Please login again.");let e;try{e=await Yn()}catch(a){throw ct("auth/refresh: app token unavailable for refresh call",a),new Error(`Cannot refresh Slingshot token: app token unavailable (${a instanceof Error?a.message:String(a)}). Please /login slingshot.`)}let n=fz(),i={accept:"application/json",rt:t.refresh,"trace-id":n,Authorization:`Bearer ${e}`},o;try{let a=ke.getRefreshUrl();o=await fetch(a,{headers:i})}catch(a){let l=a instanceof Error?a.message:String(a);throw new Error(`Cannot reach Slingshot server: ${l}`)}if(!o.ok){let a=`${o.status} ${o.statusText}`;try{let l=await o.json();l.message?a=String(l.message):l.error&&(a=String(l.error))}catch{}throw new Error(`Token refresh failed: ${a}`)}let r=await o.json();if(!r.accessToken)throw new Error("No access token in refresh response");let s=Ou(r.accessToken);try{await Yn(r.accessToken)}catch(a){throw ct("auth/refresh: app token refresh failed",a),a}return{refresh:r.refreshToken||t.refresh,access:r.accessToken,expires:s>0?s-ke.getTokenExpiryBuffer():Date.now()+10800*1e3,projectId:t.projectId,workspaceId:t.workspaceId}}var UE=[{id:"gpt-5.4-nano",name:"GPT-5.4 nano",baseUrl:"",reasoning:!0,thinkingLevelMap:{xhigh:"xhigh"},input:["text","image"],cost:{input:.2,output:1.25,cacheRead:.02,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,api:"openai-responses",provider:"slingshot"},{id:"gpt-4.1",name:"GPT-4.1",baseUrl:"",reasoning:!1,input:["text","image"],cost:{input:2,output:8,cacheRead:.5,cacheWrite:0},contextWindow:1047576,maxTokens:32768,provider:"slingshot",api:"openai-completions"},{id:"gpt-5",name:"GPT-5",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:1.25,output:10,cacheRead:.125,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"gpt-5-mini",name:"GPT-5 Mini",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:.25,output:2,cacheRead:.025,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"gpt-5-nano",name:"GPT-5 Nano",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:.05,output:.4,cacheRead:.005,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"gpt-5.1",name:"GPT-5.1",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:1.25,output:10,cacheRead:.13,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"gpt-5.2",name:"GPT-5.2",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:1.75,output:14,cacheRead:.175,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"gpt-5.4-mini",name:"GPT-5.4 mini",baseUrl:"",reasoning:!0,thinkingLevelMap:{xhigh:"xhigh"},input:["text","image"],cost:{input:.75,output:4.5,cacheRead:.075,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,api:"openai-responses",provider:"slingshot"},{id:"gpt-5.4",name:"GPT-5.4",baseUrl:"",reasoning:!0,thinkingLevelMap:{xhigh:"xhigh"},input:["text","image"],cost:{input:2.5,output:15,cacheRead:.25,cacheWrite:0},contextWindow:272e3,maxTokens:128e3,api:"openai-responses",provider:"slingshot"},{id:"gpt-5.5",name:"GPT-5.5",baseUrl:"",reasoning:!0,thinkingLevelMap:{xhigh:"xhigh"},input:["text","image"],cost:{input:5,output:30,cacheRead:.5,cacheWrite:0},contextWindow:272e3,maxTokens:128e3,api:"openai-responses",provider:"slingshot"},{id:"gpt-5.2-codex",name:"GPT-5.2 Codex",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:1.75,output:14,cacheRead:.175,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"gpt-5.3-codex",name:"GPT-5.3 Codex",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:1.75,output:14,cacheRead:.175,cacheWrite:0},contextWindow:4e5,maxTokens:128e3,provider:"slingshot",api:"openai-responses"},{id:"claude-opus-4@20250514",name:"Claude Opus 4",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75},contextWindow:2e5,maxTokens:32e3,provider:"slingshot",api:"openai-completions"},{id:"claude-sonnet-4@20250514",name:"Claude Sonnet 4",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},contextWindow:2e5,maxTokens:64e3,provider:"slingshot",api:"openai-completions"},{id:"claude-sonnet-4-5@20250929",name:"Claude Sonnet 4.5",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},contextWindow:2e5,maxTokens:64e3,provider:"slingshot",api:"openai-completions"},{id:"claude-sonnet-4-6",name:"Claude Sonnet 4.6",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},contextWindow:1e6,maxTokens:64e3,provider:"slingshot",api:"openai-completions"},{id:"claude-opus-4-6",name:"Claude Opus 4.6",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:5,output:25,cacheRead:.5,cacheWrite:6.25},contextWindow:1e6,maxTokens:128e3,provider:"slingshot",api:"openai-completions"},{id:"o3",name:"O3",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:2,output:8,cacheRead:.5,cacheWrite:0},contextWindow:2e5,maxTokens:1e5,provider:"slingshot",api:"openai-completions"},{id:"o3-mini",name:"o3-mini",baseUrl:"",reasoning:!0,input:["text"],cost:{input:1.1,output:4.4,cacheRead:.55,cacheWrite:0},contextWindow:2e5,maxTokens:1e5,provider:"slingshot",api:"openai-completions"},{id:"o4-mini",name:"o4-mini",baseUrl:"",reasoning:!0,input:["text"],cost:{input:1.1,output:4.4,cacheRead:.28,cacheWrite:0},contextWindow:2e5,maxTokens:1e5,provider:"slingshot",api:"openai-completions"},{id:"gemini-2.5-flash",name:"Gemini 2.5 Flash",baseUrl:"",reasoning:!0,input:["text","image"],cost:{input:.3,output:2.5,cacheRead:.075,cacheWrite:0},contextWindow:1048576,maxTokens:65536,provider:"slingshot",api:"openai-completions"}];var Zm={name:"slingshot.cli",private:!0,type:"module",workspaces:["packages/*","packages/web-ui/example","packages/coding-agent/examples/extensions/with-deps","packages/coding-agent/examples/extensions/custom-provider-anthropic","packages/coding-agent/examples/extensions/custom-provider-gitlab-duo"],scripts:{clean:"npm run clean --workspaces",build:"cd packages/tui && npm run build && cd ../ai && npm run build && cd ../agent && npm run build && cd ../storage/sqlite-node && npm run build && cd ../../coding-agent && npm run build && cd ../server && npm run build","build:offline":"cd packages/tui && npm run build && cd ../ai && npm run build:offline && cd ../agent && npm run build && cd ../storage/sqlite-node && npm run build && cd ../../coding-agent && npm run build && cd ../server && npm run build",dev:'concurrently --names "ai,agent,coding-agent,web-ui,tui" --prefix-colors "cyan,yellow,red,white,green,magenta" "cd packages/ai && npm run dev" "cd packages/agent && npm run dev" "cd packages/coding-agent && npm run dev" "cd packages/server && npm run dev" "cd packages/tui && npm run dev"',"dev:tsc":'concurrently --names "ai,web-ui" --prefix-colors "cyan,green" "cd packages/ai && npm run dev:tsc" "cd packages/web-ui && npm run dev:tsc"',check:"","check:browser-smoke":"","test:models":"node scripts/test-models.mjs","profile:tui":"node scripts/profile-coding-agent-node.mjs --mode tui","profile:rpc":"node scripts/profile-coding-agent-node.mjs --mode rpc",test:"npm run test --workspaces --if-present","version:patch":"npm version patch -ws --no-git-tag-version && node scripts/sync-versions.js && shx rm -rf node_modules packages/*/node_modules package-lock.json && npm install","version:minor":"npm version minor -ws --no-git-tag-version && node scripts/sync-versions.js && shx rm -rf node_modules packages/*/node_modules package-lock.json && npm install","version:major":"npm version major -ws --no-git-tag-version && node scripts/sync-versions.js && shx rm -rf node_modules packages/*/node_modules package-lock.json && npm install","version:set":"npm version -ws",prepublishOnly:"npm run clean && npm run build && npm run check",publish:"npm run prepublishOnly && npm publish -ws --access public","publish:dry":"npm run prepublishOnly && npm publish -ws --access public --dry-run","release:patch":"node scripts/release.mjs patch","release:minor":"node scripts/release.mjs minor","release:major":"node scripts/release.mjs major",prepare:"husky"},devDependencies:{"@anthropic-ai/sandbox-runtime":"0.0.57","@biomejs/biome":"2.3.15","@types/better-sqlite3":"^7.6.13","@types/lodash.mergewith":"^4.6.9","@types/node":"24.13.2","@types/turndown":"^5.0.6","@typescript/native-preview":"7.0.0-dev.20260120.1",concurrently:"^9.2.3",esbuild:"0.28.1","fast-xml-parser":"^5.9.3",husky:"9.1.7",jiti:"2.7.0",psadk:"^1.5.1",shx:"0.4.0",tsx:"4.22.4",turbo:"^2.9.18",typescript:"5.9.3",vitest:"^4.1.9"},engines:{node:">=20.0.0"},slingVersion:"2.5.20260724-1",overrides:{postcss:"8.5.14",next:{postcss:"8.5.14"},"ip-address":"^10.1.1","@modelcontextprotocol/sdk":"^1.29.0",ai:">=5.0.52","fast-xml-parser":"^5.9.3","@aws-sdk/xml-builder":{"fast-xml-parser":"^5.9.3"},"adaptivecards-templating":{"adaptive-expressions":{"fast-xml-parser":"^5.5.8"}},picomatch:"^4.0.4","path-to-regexp":"8.4.1",router:{"path-to-regexp":"8.4.1"},minimatch:"^10.2.3",tar:"7.5.11",react:"19.1.1","react-dom":"19.1.1","@types/react":"19","@types/react-dom":"19",tailwindcss:"4.1.12",lightningcss:"1.30.2",glob:{".":"11.1.0",minimatch:"10.2.3"},prismjs:"^1.30.0",qs:"^6.15.0","@hono/node-server":"1.19.14",protobufjs:"^8.2.0","@opentelemetry/otlp-transformer":{protobufjs:"^8.2.0"},langchain:{langsmith:">=0.7.0"},hono:"4.12.18",fsevents:"^2.3.3",swiper:"^12.1.2",lodash:"^4.18.0","lodash-es":"^4.18.1",axios:"^1.15.0","ibm-cloud-sdk-core":"^5.4.11",dompurify:">=3.4.0","react-markdown-mermaid":{mermaid:"10.9.6"}},dependencies:{"@modelcontextprotocol/sdk":"^1.29.0","@mozilla/readability":"^0.6.0","better-sqlite3":"^12.11.1","compound-engineering-pi":"^0.2.4","get-east-asian-width":"^1.4.0",linkedom:"^0.18.12",turndown:"^7.2.4",unpdf:"^1.6.2"}};import Du from"chalk";function $E(t,e){return{render(n){let i=` \u26AC _______. __ __ .__ __. _______
|
|
388
388
|
\u274D \xB7 \u274D / || | | | | \\ | | / _____|
|
|
389
389
|
\u2726 \u26AC \u2726 | (----\`| | | | | \\| | | | __
|
|
390
390
|
\u26AC \xB7 \u26AC \u26AC \xB7 \u26AC \\ \\ | | | | | . \` | | | |_ |
|