@vectorize-io/hindsight-coding-agents 0.4.3 → 0.5.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/README.md +202 -52
- package/dist/antigravity-hook.js +637 -199
- package/dist/antigravity-statusline.js +219 -84
- package/dist/antigravity-stop-hook.js +654 -205
- package/dist/claude-hook.js +637 -199
- package/dist/claude-sessionstart-hook.js +862 -236
- package/dist/claude-stop-hook.js +654 -205
- package/dist/cline.js +588 -234
- package/dist/codex-hook.js +637 -199
- package/dist/codex-sessionstart-hook.js +862 -236
- package/dist/codex-stop-hook.js +654 -205
- package/dist/copilot-hook.js +637 -199
- package/dist/copilot-sessionstart-hook.js +862 -236
- package/dist/copilot-stop-hook.js +654 -205
- package/dist/cursor-hook.js +637 -199
- package/dist/cursor-sessionstart-hook.js +862 -236
- package/dist/cursor-stop-hook.js +654 -205
- package/dist/daemon-start.js +62 -43
- package/dist/dcode-hook.js +2577 -0
- package/dist/dcode-sessionstart-hook.js +3193 -0
- package/dist/dcode-stop-hook.js +2807 -0
- package/dist/deepen.js +361 -204
- package/dist/devin-hook.js +637 -199
- package/dist/devin-sessionstart-hook.js +862 -236
- package/dist/devin-stop-hook.js +654 -205
- package/dist/dsh.js +591 -235
- package/dist/grok-hook.js +637 -199
- package/dist/grok-sessionstart-hook.js +862 -236
- package/dist/grok-stop-hook.js +654 -205
- package/dist/hindsight-seed.js +222 -83
- package/dist/index.js +588 -234
- package/dist/installer.js +2331 -299
- package/dist/kilo.js +588 -234
- package/dist/mcp-server.js +363 -169
- package/dist/opencode2.js +30091 -0
- package/dist/pi.js +17649 -0
- package/dist/prime-agent.js +624 -260
- package/dist/qwen-hook.js +2577 -0
- package/dist/qwen-sessionstart-hook.js +3193 -0
- package/dist/qwen-stop-hook.js +2807 -0
- package/dist/status.js +300 -136
- package/hooks/hooks.json +37 -0
- package/index.js +10 -0
- package/package.json +15 -8
- package/plugin.json +16 -0
- package/skill/SKILL.md +114 -43
package/dist/installer.js
CHANGED
|
@@ -5,55 +5,1375 @@ import { execFileSync as execFileSync6 } from "child_process";
|
|
|
5
5
|
import {
|
|
6
6
|
copyFileSync,
|
|
7
7
|
cpSync as cpSync2,
|
|
8
|
-
existsSync as
|
|
9
|
-
mkdirSync as
|
|
8
|
+
existsSync as existsSync10,
|
|
9
|
+
mkdirSync as mkdirSync4,
|
|
10
10
|
mkdtempSync,
|
|
11
|
-
readFileSync as
|
|
11
|
+
readFileSync as readFileSync12,
|
|
12
12
|
readSync as readSync4,
|
|
13
|
-
realpathSync,
|
|
13
|
+
realpathSync as realpathSync3,
|
|
14
14
|
rmSync as rmSync2,
|
|
15
|
-
writeFileSync as
|
|
15
|
+
writeFileSync as writeFileSync3
|
|
16
16
|
} from "fs";
|
|
17
|
-
import { homedir as
|
|
17
|
+
import { homedir as homedir10, tmpdir as tmpdir4 } from "os";
|
|
18
18
|
import { isatty } from "tty";
|
|
19
|
-
import { dirname as
|
|
20
|
-
import { fileURLToPath as
|
|
19
|
+
import { dirname as dirname10, join as join16 } from "path";
|
|
20
|
+
import { fileURLToPath as fileURLToPath6, pathToFileURL } from "url";
|
|
21
|
+
|
|
22
|
+
// node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
23
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
24
|
+
const len = text.length;
|
|
25
|
+
let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
|
|
26
|
+
function scanHexDigits(count, exact) {
|
|
27
|
+
let digits = 0;
|
|
28
|
+
let value2 = 0;
|
|
29
|
+
while (digits < count || !exact) {
|
|
30
|
+
let ch = text.charCodeAt(pos);
|
|
31
|
+
if (ch >= 48 && ch <= 57) {
|
|
32
|
+
value2 = value2 * 16 + ch - 48;
|
|
33
|
+
} else if (ch >= 65 && ch <= 70) {
|
|
34
|
+
value2 = value2 * 16 + ch - 65 + 10;
|
|
35
|
+
} else if (ch >= 97 && ch <= 102) {
|
|
36
|
+
value2 = value2 * 16 + ch - 97 + 10;
|
|
37
|
+
} else {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
pos++;
|
|
41
|
+
digits++;
|
|
42
|
+
}
|
|
43
|
+
if (digits < count) {
|
|
44
|
+
value2 = -1;
|
|
45
|
+
}
|
|
46
|
+
return value2;
|
|
47
|
+
}
|
|
48
|
+
function setPosition(newPosition) {
|
|
49
|
+
pos = newPosition;
|
|
50
|
+
value = "";
|
|
51
|
+
tokenOffset = 0;
|
|
52
|
+
token = 16;
|
|
53
|
+
scanError = 0;
|
|
54
|
+
}
|
|
55
|
+
function scanNumber() {
|
|
56
|
+
let start = pos;
|
|
57
|
+
if (text.charCodeAt(pos) === 48) {
|
|
58
|
+
pos++;
|
|
59
|
+
} else {
|
|
60
|
+
pos++;
|
|
61
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
62
|
+
pos++;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (pos < text.length && text.charCodeAt(pos) === 46) {
|
|
66
|
+
pos++;
|
|
67
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
68
|
+
pos++;
|
|
69
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
70
|
+
pos++;
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
scanError = 3;
|
|
74
|
+
return text.substring(start, pos);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
let end = pos;
|
|
78
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 || text.charCodeAt(pos) === 101)) {
|
|
79
|
+
pos++;
|
|
80
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 || text.charCodeAt(pos) === 45) {
|
|
81
|
+
pos++;
|
|
82
|
+
}
|
|
83
|
+
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
84
|
+
pos++;
|
|
85
|
+
while (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
86
|
+
pos++;
|
|
87
|
+
}
|
|
88
|
+
end = pos;
|
|
89
|
+
} else {
|
|
90
|
+
scanError = 3;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return text.substring(start, end);
|
|
94
|
+
}
|
|
95
|
+
function scanString() {
|
|
96
|
+
let result = "", start = pos;
|
|
97
|
+
while (true) {
|
|
98
|
+
if (pos >= len) {
|
|
99
|
+
result += text.substring(start, pos);
|
|
100
|
+
scanError = 2;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
const ch = text.charCodeAt(pos);
|
|
104
|
+
if (ch === 34) {
|
|
105
|
+
result += text.substring(start, pos);
|
|
106
|
+
pos++;
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
if (ch === 92) {
|
|
110
|
+
result += text.substring(start, pos);
|
|
111
|
+
pos++;
|
|
112
|
+
if (pos >= len) {
|
|
113
|
+
scanError = 2;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
const ch2 = text.charCodeAt(pos++);
|
|
117
|
+
switch (ch2) {
|
|
118
|
+
case 34:
|
|
119
|
+
result += '"';
|
|
120
|
+
break;
|
|
121
|
+
case 92:
|
|
122
|
+
result += "\\";
|
|
123
|
+
break;
|
|
124
|
+
case 47:
|
|
125
|
+
result += "/";
|
|
126
|
+
break;
|
|
127
|
+
case 98:
|
|
128
|
+
result += "\b";
|
|
129
|
+
break;
|
|
130
|
+
case 102:
|
|
131
|
+
result += "\f";
|
|
132
|
+
break;
|
|
133
|
+
case 110:
|
|
134
|
+
result += "\n";
|
|
135
|
+
break;
|
|
136
|
+
case 114:
|
|
137
|
+
result += "\r";
|
|
138
|
+
break;
|
|
139
|
+
case 116:
|
|
140
|
+
result += " ";
|
|
141
|
+
break;
|
|
142
|
+
case 117:
|
|
143
|
+
const ch3 = scanHexDigits(4, true);
|
|
144
|
+
if (ch3 >= 0) {
|
|
145
|
+
result += String.fromCharCode(ch3);
|
|
146
|
+
} else {
|
|
147
|
+
scanError = 4;
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
default:
|
|
151
|
+
scanError = 5;
|
|
152
|
+
}
|
|
153
|
+
start = pos;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (ch >= 0 && ch <= 31) {
|
|
157
|
+
if (isLineBreak(ch)) {
|
|
158
|
+
result += text.substring(start, pos);
|
|
159
|
+
scanError = 2;
|
|
160
|
+
break;
|
|
161
|
+
} else {
|
|
162
|
+
scanError = 6;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
pos++;
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
function scanNext() {
|
|
170
|
+
value = "";
|
|
171
|
+
scanError = 0;
|
|
172
|
+
tokenOffset = pos;
|
|
173
|
+
lineStartOffset = lineNumber;
|
|
174
|
+
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
175
|
+
if (pos >= len) {
|
|
176
|
+
tokenOffset = len;
|
|
177
|
+
return token = 17;
|
|
178
|
+
}
|
|
179
|
+
let code = text.charCodeAt(pos);
|
|
180
|
+
if (isWhiteSpace(code)) {
|
|
181
|
+
do {
|
|
182
|
+
pos++;
|
|
183
|
+
value += String.fromCharCode(code);
|
|
184
|
+
code = text.charCodeAt(pos);
|
|
185
|
+
} while (isWhiteSpace(code));
|
|
186
|
+
return token = 15;
|
|
187
|
+
}
|
|
188
|
+
if (isLineBreak(code)) {
|
|
189
|
+
pos++;
|
|
190
|
+
value += String.fromCharCode(code);
|
|
191
|
+
if (code === 13 && text.charCodeAt(pos) === 10) {
|
|
192
|
+
pos++;
|
|
193
|
+
value += "\n";
|
|
194
|
+
}
|
|
195
|
+
lineNumber++;
|
|
196
|
+
tokenLineStartOffset = pos;
|
|
197
|
+
return token = 14;
|
|
198
|
+
}
|
|
199
|
+
switch (code) {
|
|
200
|
+
// tokens: []{}:,
|
|
201
|
+
case 123:
|
|
202
|
+
pos++;
|
|
203
|
+
return token = 1;
|
|
204
|
+
case 125:
|
|
205
|
+
pos++;
|
|
206
|
+
return token = 2;
|
|
207
|
+
case 91:
|
|
208
|
+
pos++;
|
|
209
|
+
return token = 3;
|
|
210
|
+
case 93:
|
|
211
|
+
pos++;
|
|
212
|
+
return token = 4;
|
|
213
|
+
case 58:
|
|
214
|
+
pos++;
|
|
215
|
+
return token = 6;
|
|
216
|
+
case 44:
|
|
217
|
+
pos++;
|
|
218
|
+
return token = 5;
|
|
219
|
+
// strings
|
|
220
|
+
case 34:
|
|
221
|
+
pos++;
|
|
222
|
+
value = scanString();
|
|
223
|
+
return token = 10;
|
|
224
|
+
// comments
|
|
225
|
+
case 47:
|
|
226
|
+
const start = pos - 1;
|
|
227
|
+
if (text.charCodeAt(pos + 1) === 47) {
|
|
228
|
+
pos += 2;
|
|
229
|
+
while (pos < len) {
|
|
230
|
+
if (isLineBreak(text.charCodeAt(pos))) {
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
pos++;
|
|
234
|
+
}
|
|
235
|
+
value = text.substring(start, pos);
|
|
236
|
+
return token = 12;
|
|
237
|
+
}
|
|
238
|
+
if (text.charCodeAt(pos + 1) === 42) {
|
|
239
|
+
pos += 2;
|
|
240
|
+
const safeLength = len - 1;
|
|
241
|
+
let commentClosed = false;
|
|
242
|
+
while (pos < safeLength) {
|
|
243
|
+
const ch = text.charCodeAt(pos);
|
|
244
|
+
if (ch === 42 && text.charCodeAt(pos + 1) === 47) {
|
|
245
|
+
pos += 2;
|
|
246
|
+
commentClosed = true;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
pos++;
|
|
250
|
+
if (isLineBreak(ch)) {
|
|
251
|
+
if (ch === 13 && text.charCodeAt(pos) === 10) {
|
|
252
|
+
pos++;
|
|
253
|
+
}
|
|
254
|
+
lineNumber++;
|
|
255
|
+
tokenLineStartOffset = pos;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (!commentClosed) {
|
|
259
|
+
pos++;
|
|
260
|
+
scanError = 1;
|
|
261
|
+
}
|
|
262
|
+
value = text.substring(start, pos);
|
|
263
|
+
return token = 13;
|
|
264
|
+
}
|
|
265
|
+
value += String.fromCharCode(code);
|
|
266
|
+
pos++;
|
|
267
|
+
return token = 16;
|
|
268
|
+
// numbers
|
|
269
|
+
case 45:
|
|
270
|
+
value += String.fromCharCode(code);
|
|
271
|
+
pos++;
|
|
272
|
+
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
273
|
+
return token = 16;
|
|
274
|
+
}
|
|
275
|
+
// found a minus, followed by a number so
|
|
276
|
+
// we fall through to proceed with scanning
|
|
277
|
+
// numbers
|
|
278
|
+
case 48:
|
|
279
|
+
case 49:
|
|
280
|
+
case 50:
|
|
281
|
+
case 51:
|
|
282
|
+
case 52:
|
|
283
|
+
case 53:
|
|
284
|
+
case 54:
|
|
285
|
+
case 55:
|
|
286
|
+
case 56:
|
|
287
|
+
case 57:
|
|
288
|
+
value += scanNumber();
|
|
289
|
+
return token = 11;
|
|
290
|
+
// literals and unknown symbols
|
|
291
|
+
default:
|
|
292
|
+
while (pos < len && isUnknownContentCharacter(code)) {
|
|
293
|
+
pos++;
|
|
294
|
+
code = text.charCodeAt(pos);
|
|
295
|
+
}
|
|
296
|
+
if (tokenOffset !== pos) {
|
|
297
|
+
value = text.substring(tokenOffset, pos);
|
|
298
|
+
switch (value) {
|
|
299
|
+
case "true":
|
|
300
|
+
return token = 8;
|
|
301
|
+
case "false":
|
|
302
|
+
return token = 9;
|
|
303
|
+
case "null":
|
|
304
|
+
return token = 7;
|
|
305
|
+
}
|
|
306
|
+
return token = 16;
|
|
307
|
+
}
|
|
308
|
+
value += String.fromCharCode(code);
|
|
309
|
+
pos++;
|
|
310
|
+
return token = 16;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function isUnknownContentCharacter(code) {
|
|
314
|
+
if (isWhiteSpace(code) || isLineBreak(code)) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
switch (code) {
|
|
318
|
+
case 125:
|
|
319
|
+
case 93:
|
|
320
|
+
case 123:
|
|
321
|
+
case 91:
|
|
322
|
+
case 34:
|
|
323
|
+
case 58:
|
|
324
|
+
case 44:
|
|
325
|
+
case 47:
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
function scanNextNonTrivia() {
|
|
331
|
+
let result;
|
|
332
|
+
do {
|
|
333
|
+
result = scanNext();
|
|
334
|
+
} while (result >= 12 && result <= 15);
|
|
335
|
+
return result;
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
setPosition,
|
|
339
|
+
getPosition: () => pos,
|
|
340
|
+
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
341
|
+
getToken: () => token,
|
|
342
|
+
getTokenValue: () => value,
|
|
343
|
+
getTokenOffset: () => tokenOffset,
|
|
344
|
+
getTokenLength: () => pos - tokenOffset,
|
|
345
|
+
getTokenStartLine: () => lineStartOffset,
|
|
346
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
347
|
+
getTokenError: () => scanError
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function isWhiteSpace(ch) {
|
|
351
|
+
return ch === 32 || ch === 9;
|
|
352
|
+
}
|
|
353
|
+
function isLineBreak(ch) {
|
|
354
|
+
return ch === 10 || ch === 13;
|
|
355
|
+
}
|
|
356
|
+
function isDigit(ch) {
|
|
357
|
+
return ch >= 48 && ch <= 57;
|
|
358
|
+
}
|
|
359
|
+
var CharacterCodes;
|
|
360
|
+
(function(CharacterCodes2) {
|
|
361
|
+
CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
|
|
362
|
+
CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
|
|
363
|
+
CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
|
|
364
|
+
CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
|
|
365
|
+
CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
|
|
366
|
+
CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
|
|
367
|
+
CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
|
|
368
|
+
CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
|
|
369
|
+
CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
|
|
370
|
+
CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
|
|
371
|
+
CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
|
|
372
|
+
CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
|
|
373
|
+
CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
|
|
374
|
+
CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
|
|
375
|
+
CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
|
|
376
|
+
CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
|
|
377
|
+
CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
|
|
378
|
+
CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
|
|
379
|
+
CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
|
|
380
|
+
CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
|
|
381
|
+
CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
|
|
382
|
+
CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
|
|
383
|
+
CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
|
|
384
|
+
CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
|
|
385
|
+
CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
|
|
386
|
+
CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
|
|
387
|
+
CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
|
|
388
|
+
CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
|
|
389
|
+
CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
|
|
390
|
+
CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
|
|
391
|
+
CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
|
|
392
|
+
CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
|
|
393
|
+
CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
|
|
394
|
+
CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
|
|
395
|
+
CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
|
|
396
|
+
CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
|
|
397
|
+
CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
|
|
398
|
+
CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
|
|
399
|
+
CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
|
|
400
|
+
CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
|
|
401
|
+
CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
|
|
402
|
+
CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
|
|
403
|
+
CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
|
|
404
|
+
CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
|
|
405
|
+
CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
|
|
406
|
+
CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
|
|
407
|
+
CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
|
|
408
|
+
CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
|
|
409
|
+
CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
|
|
410
|
+
CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
|
|
411
|
+
CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
|
|
412
|
+
CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
|
|
413
|
+
CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
|
|
414
|
+
CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
|
|
415
|
+
CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
|
|
416
|
+
CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
|
|
417
|
+
CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
|
|
418
|
+
CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
|
|
419
|
+
CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
|
|
420
|
+
CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
|
|
421
|
+
CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
|
|
422
|
+
CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
|
|
423
|
+
CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
|
|
424
|
+
CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
|
|
425
|
+
CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
|
|
426
|
+
CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
|
|
427
|
+
CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
|
|
428
|
+
CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
|
|
429
|
+
CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
|
|
430
|
+
CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
|
|
431
|
+
CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
|
|
432
|
+
CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
|
|
433
|
+
CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
|
|
434
|
+
CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
|
|
435
|
+
CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
|
|
436
|
+
CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
|
|
437
|
+
CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
|
|
438
|
+
CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
|
|
439
|
+
CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
|
|
440
|
+
CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
|
|
441
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
442
|
+
|
|
443
|
+
// node_modules/jsonc-parser/lib/esm/impl/string-intern.js
|
|
444
|
+
var cachedSpaces = new Array(20).fill(0).map((_, index) => {
|
|
445
|
+
return " ".repeat(index);
|
|
446
|
+
});
|
|
447
|
+
var maxCachedValues = 200;
|
|
448
|
+
var cachedBreakLinesWithSpaces = {
|
|
449
|
+
" ": {
|
|
450
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
451
|
+
return "\n" + " ".repeat(index);
|
|
452
|
+
}),
|
|
453
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
454
|
+
return "\r" + " ".repeat(index);
|
|
455
|
+
}),
|
|
456
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
457
|
+
return "\r\n" + " ".repeat(index);
|
|
458
|
+
})
|
|
459
|
+
},
|
|
460
|
+
" ": {
|
|
461
|
+
"\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
462
|
+
return "\n" + " ".repeat(index);
|
|
463
|
+
}),
|
|
464
|
+
"\r": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
465
|
+
return "\r" + " ".repeat(index);
|
|
466
|
+
}),
|
|
467
|
+
"\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
|
|
468
|
+
return "\r\n" + " ".repeat(index);
|
|
469
|
+
})
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
var supportedEols = ["\n", "\r", "\r\n"];
|
|
473
|
+
|
|
474
|
+
// node_modules/jsonc-parser/lib/esm/impl/format.js
|
|
475
|
+
function format(documentText, range, options) {
|
|
476
|
+
let initialIndentLevel;
|
|
477
|
+
let formatText;
|
|
478
|
+
let formatTextStart;
|
|
479
|
+
let rangeStart;
|
|
480
|
+
let rangeEnd;
|
|
481
|
+
if (range) {
|
|
482
|
+
rangeStart = range.offset;
|
|
483
|
+
rangeEnd = rangeStart + range.length;
|
|
484
|
+
formatTextStart = rangeStart;
|
|
485
|
+
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
|
|
486
|
+
formatTextStart--;
|
|
487
|
+
}
|
|
488
|
+
let endOffset = rangeEnd;
|
|
489
|
+
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
|
|
490
|
+
endOffset++;
|
|
491
|
+
}
|
|
492
|
+
formatText = documentText.substring(formatTextStart, endOffset);
|
|
493
|
+
initialIndentLevel = computeIndentLevel(formatText, options);
|
|
494
|
+
} else {
|
|
495
|
+
formatText = documentText;
|
|
496
|
+
initialIndentLevel = 0;
|
|
497
|
+
formatTextStart = 0;
|
|
498
|
+
rangeStart = 0;
|
|
499
|
+
rangeEnd = documentText.length;
|
|
500
|
+
}
|
|
501
|
+
const eol = getEOL(options, documentText);
|
|
502
|
+
const eolFastPathSupported = supportedEols.includes(eol);
|
|
503
|
+
let numberLineBreaks = 0;
|
|
504
|
+
let indentLevel = 0;
|
|
505
|
+
let indentValue;
|
|
506
|
+
if (options.insertSpaces) {
|
|
507
|
+
indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
|
|
508
|
+
} else {
|
|
509
|
+
indentValue = " ";
|
|
510
|
+
}
|
|
511
|
+
const indentType = indentValue === " " ? " " : " ";
|
|
512
|
+
let scanner = createScanner(formatText, false);
|
|
513
|
+
let hasError = false;
|
|
514
|
+
function newLinesAndIndent() {
|
|
515
|
+
if (numberLineBreaks > 1) {
|
|
516
|
+
return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
517
|
+
}
|
|
518
|
+
const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
|
|
519
|
+
if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
|
|
520
|
+
return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
521
|
+
}
|
|
522
|
+
if (amountOfSpaces <= 0) {
|
|
523
|
+
return eol;
|
|
524
|
+
}
|
|
525
|
+
return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
|
|
526
|
+
}
|
|
527
|
+
function scanNext() {
|
|
528
|
+
let token = scanner.scan();
|
|
529
|
+
numberLineBreaks = 0;
|
|
530
|
+
while (token === 15 || token === 14) {
|
|
531
|
+
if (token === 14 && options.keepLines) {
|
|
532
|
+
numberLineBreaks += 1;
|
|
533
|
+
} else if (token === 14) {
|
|
534
|
+
numberLineBreaks = 1;
|
|
535
|
+
}
|
|
536
|
+
token = scanner.scan();
|
|
537
|
+
}
|
|
538
|
+
hasError = token === 16 || scanner.getTokenError() !== 0;
|
|
539
|
+
return token;
|
|
540
|
+
}
|
|
541
|
+
const editOperations = [];
|
|
542
|
+
function addEdit(text, startOffset, endOffset) {
|
|
543
|
+
if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text) {
|
|
544
|
+
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
let firstToken = scanNext();
|
|
548
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
549
|
+
addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
550
|
+
}
|
|
551
|
+
if (firstToken !== 17) {
|
|
552
|
+
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
553
|
+
let initialIndent = indentValue.length * initialIndentLevel < 20 && options.insertSpaces ? cachedSpaces[indentValue.length * initialIndentLevel] : repeat(indentValue, initialIndentLevel);
|
|
554
|
+
addEdit(initialIndent, formatTextStart, firstTokenStart);
|
|
555
|
+
}
|
|
556
|
+
while (firstToken !== 17) {
|
|
557
|
+
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
558
|
+
let secondToken = scanNext();
|
|
559
|
+
let replaceContent = "";
|
|
560
|
+
let needsLineBreak = false;
|
|
561
|
+
while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
|
|
562
|
+
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
563
|
+
addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
|
|
564
|
+
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
565
|
+
needsLineBreak = secondToken === 12;
|
|
566
|
+
replaceContent = needsLineBreak ? newLinesAndIndent() : "";
|
|
567
|
+
secondToken = scanNext();
|
|
568
|
+
}
|
|
569
|
+
if (secondToken === 2) {
|
|
570
|
+
if (firstToken !== 1) {
|
|
571
|
+
indentLevel--;
|
|
572
|
+
}
|
|
573
|
+
;
|
|
574
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) {
|
|
575
|
+
replaceContent = newLinesAndIndent();
|
|
576
|
+
} else if (options.keepLines) {
|
|
577
|
+
replaceContent = cachedSpaces[1];
|
|
578
|
+
}
|
|
579
|
+
} else if (secondToken === 4) {
|
|
580
|
+
if (firstToken !== 3) {
|
|
581
|
+
indentLevel--;
|
|
582
|
+
}
|
|
583
|
+
;
|
|
584
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) {
|
|
585
|
+
replaceContent = newLinesAndIndent();
|
|
586
|
+
} else if (options.keepLines) {
|
|
587
|
+
replaceContent = cachedSpaces[1];
|
|
588
|
+
}
|
|
589
|
+
} else {
|
|
590
|
+
switch (firstToken) {
|
|
591
|
+
case 3:
|
|
592
|
+
case 1:
|
|
593
|
+
indentLevel++;
|
|
594
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
595
|
+
replaceContent = newLinesAndIndent();
|
|
596
|
+
} else {
|
|
597
|
+
replaceContent = cachedSpaces[1];
|
|
598
|
+
}
|
|
599
|
+
break;
|
|
600
|
+
case 5:
|
|
601
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
602
|
+
replaceContent = newLinesAndIndent();
|
|
603
|
+
} else {
|
|
604
|
+
replaceContent = cachedSpaces[1];
|
|
605
|
+
}
|
|
606
|
+
break;
|
|
607
|
+
case 12:
|
|
608
|
+
replaceContent = newLinesAndIndent();
|
|
609
|
+
break;
|
|
610
|
+
case 13:
|
|
611
|
+
if (numberLineBreaks > 0) {
|
|
612
|
+
replaceContent = newLinesAndIndent();
|
|
613
|
+
} else if (!needsLineBreak) {
|
|
614
|
+
replaceContent = cachedSpaces[1];
|
|
615
|
+
}
|
|
616
|
+
break;
|
|
617
|
+
case 6:
|
|
618
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
619
|
+
replaceContent = newLinesAndIndent();
|
|
620
|
+
} else if (!needsLineBreak) {
|
|
621
|
+
replaceContent = cachedSpaces[1];
|
|
622
|
+
}
|
|
623
|
+
break;
|
|
624
|
+
case 10:
|
|
625
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
626
|
+
replaceContent = newLinesAndIndent();
|
|
627
|
+
} else if (secondToken === 6 && !needsLineBreak) {
|
|
628
|
+
replaceContent = "";
|
|
629
|
+
}
|
|
630
|
+
break;
|
|
631
|
+
case 7:
|
|
632
|
+
case 8:
|
|
633
|
+
case 9:
|
|
634
|
+
case 11:
|
|
635
|
+
case 2:
|
|
636
|
+
case 4:
|
|
637
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
638
|
+
replaceContent = newLinesAndIndent();
|
|
639
|
+
} else {
|
|
640
|
+
if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) {
|
|
641
|
+
replaceContent = cachedSpaces[1];
|
|
642
|
+
} else if (secondToken !== 5 && secondToken !== 17) {
|
|
643
|
+
hasError = true;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
break;
|
|
647
|
+
case 16:
|
|
648
|
+
hasError = true;
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) {
|
|
652
|
+
replaceContent = newLinesAndIndent();
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
if (secondToken === 17) {
|
|
656
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
657
|
+
replaceContent = newLinesAndIndent();
|
|
658
|
+
} else {
|
|
659
|
+
replaceContent = options.insertFinalNewline ? eol : "";
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
663
|
+
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
664
|
+
firstToken = secondToken;
|
|
665
|
+
}
|
|
666
|
+
return editOperations;
|
|
667
|
+
}
|
|
668
|
+
function repeat(s, count) {
|
|
669
|
+
let result = "";
|
|
670
|
+
for (let i = 0; i < count; i++) {
|
|
671
|
+
result += s;
|
|
672
|
+
}
|
|
673
|
+
return result;
|
|
674
|
+
}
|
|
675
|
+
function computeIndentLevel(content, options) {
|
|
676
|
+
let i = 0;
|
|
677
|
+
let nChars = 0;
|
|
678
|
+
const tabSize = options.tabSize || 4;
|
|
679
|
+
while (i < content.length) {
|
|
680
|
+
let ch = content.charAt(i);
|
|
681
|
+
if (ch === cachedSpaces[1]) {
|
|
682
|
+
nChars++;
|
|
683
|
+
} else if (ch === " ") {
|
|
684
|
+
nChars += tabSize;
|
|
685
|
+
} else {
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
i++;
|
|
689
|
+
}
|
|
690
|
+
return Math.floor(nChars / tabSize);
|
|
691
|
+
}
|
|
692
|
+
function getEOL(options, text) {
|
|
693
|
+
for (let i = 0; i < text.length; i++) {
|
|
694
|
+
const ch = text.charAt(i);
|
|
695
|
+
if (ch === "\r") {
|
|
696
|
+
if (i + 1 < text.length && text.charAt(i + 1) === "\n") {
|
|
697
|
+
return "\r\n";
|
|
698
|
+
}
|
|
699
|
+
return "\r";
|
|
700
|
+
} else if (ch === "\n") {
|
|
701
|
+
return "\n";
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
return options && options.eol || "\n";
|
|
705
|
+
}
|
|
706
|
+
function isEOL(text, offset) {
|
|
707
|
+
return "\r\n".indexOf(text.charAt(offset)) !== -1;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
// node_modules/jsonc-parser/lib/esm/impl/parser.js
|
|
711
|
+
var ParseOptions;
|
|
712
|
+
(function(ParseOptions2) {
|
|
713
|
+
ParseOptions2.DEFAULT = {
|
|
714
|
+
allowTrailingComma: false
|
|
715
|
+
};
|
|
716
|
+
})(ParseOptions || (ParseOptions = {}));
|
|
717
|
+
function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
718
|
+
let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: void 0 };
|
|
719
|
+
function ensurePropertyComplete(endOffset) {
|
|
720
|
+
if (currentParent.type === "property") {
|
|
721
|
+
currentParent.length = endOffset - currentParent.offset;
|
|
722
|
+
currentParent = currentParent.parent;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
function onValue(valueNode) {
|
|
726
|
+
currentParent.children.push(valueNode);
|
|
727
|
+
return valueNode;
|
|
728
|
+
}
|
|
729
|
+
const visitor = {
|
|
730
|
+
onObjectBegin: (offset) => {
|
|
731
|
+
currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
|
|
732
|
+
},
|
|
733
|
+
onObjectProperty: (name, offset, length) => {
|
|
734
|
+
currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
|
|
735
|
+
currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
|
|
736
|
+
},
|
|
737
|
+
onObjectEnd: (offset, length) => {
|
|
738
|
+
ensurePropertyComplete(offset + length);
|
|
739
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
740
|
+
currentParent = currentParent.parent;
|
|
741
|
+
ensurePropertyComplete(offset + length);
|
|
742
|
+
},
|
|
743
|
+
onArrayBegin: (offset, length) => {
|
|
744
|
+
currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
|
|
745
|
+
},
|
|
746
|
+
onArrayEnd: (offset, length) => {
|
|
747
|
+
currentParent.length = offset + length - currentParent.offset;
|
|
748
|
+
currentParent = currentParent.parent;
|
|
749
|
+
ensurePropertyComplete(offset + length);
|
|
750
|
+
},
|
|
751
|
+
onLiteralValue: (value, offset, length) => {
|
|
752
|
+
onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
|
|
753
|
+
ensurePropertyComplete(offset + length);
|
|
754
|
+
},
|
|
755
|
+
onSeparator: (sep2, offset, length) => {
|
|
756
|
+
if (currentParent.type === "property") {
|
|
757
|
+
if (sep2 === ":") {
|
|
758
|
+
currentParent.colonOffset = offset;
|
|
759
|
+
} else if (sep2 === ",") {
|
|
760
|
+
ensurePropertyComplete(offset);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
},
|
|
764
|
+
onError: (error, offset, length) => {
|
|
765
|
+
errors.push({ error, offset, length });
|
|
766
|
+
}
|
|
767
|
+
};
|
|
768
|
+
visit(text, visitor, options);
|
|
769
|
+
const result = currentParent.children[0];
|
|
770
|
+
if (result) {
|
|
771
|
+
delete result.parent;
|
|
772
|
+
}
|
|
773
|
+
return result;
|
|
774
|
+
}
|
|
775
|
+
function findNodeAtLocation(root, path) {
|
|
776
|
+
if (!root) {
|
|
777
|
+
return void 0;
|
|
778
|
+
}
|
|
779
|
+
let node = root;
|
|
780
|
+
for (let segment of path) {
|
|
781
|
+
if (typeof segment === "string") {
|
|
782
|
+
if (node.type !== "object" || !Array.isArray(node.children)) {
|
|
783
|
+
return void 0;
|
|
784
|
+
}
|
|
785
|
+
let found = false;
|
|
786
|
+
for (const propertyNode of node.children) {
|
|
787
|
+
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
|
|
788
|
+
node = propertyNode.children[1];
|
|
789
|
+
found = true;
|
|
790
|
+
break;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
if (!found) {
|
|
794
|
+
return void 0;
|
|
795
|
+
}
|
|
796
|
+
} else {
|
|
797
|
+
const index = segment;
|
|
798
|
+
if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
|
|
799
|
+
return void 0;
|
|
800
|
+
}
|
|
801
|
+
node = node.children[index];
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
return node;
|
|
805
|
+
}
|
|
806
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
807
|
+
const _scanner = createScanner(text, false);
|
|
808
|
+
const _jsonPath = [];
|
|
809
|
+
let suppressedCallbacks = 0;
|
|
810
|
+
function toNoArgVisit(visitFunction) {
|
|
811
|
+
return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
812
|
+
}
|
|
813
|
+
function toOneArgVisit(visitFunction) {
|
|
814
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
815
|
+
}
|
|
816
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
817
|
+
return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
818
|
+
}
|
|
819
|
+
function toBeginVisit(visitFunction) {
|
|
820
|
+
return visitFunction ? () => {
|
|
821
|
+
if (suppressedCallbacks > 0) {
|
|
822
|
+
suppressedCallbacks++;
|
|
823
|
+
} else {
|
|
824
|
+
let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
|
|
825
|
+
if (cbReturn === false) {
|
|
826
|
+
suppressedCallbacks = 1;
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
} : () => true;
|
|
830
|
+
}
|
|
831
|
+
function toEndVisit(visitFunction) {
|
|
832
|
+
return visitFunction ? () => {
|
|
833
|
+
if (suppressedCallbacks > 0) {
|
|
834
|
+
suppressedCallbacks--;
|
|
835
|
+
}
|
|
836
|
+
if (suppressedCallbacks === 0) {
|
|
837
|
+
visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
|
|
838
|
+
}
|
|
839
|
+
} : () => true;
|
|
840
|
+
}
|
|
841
|
+
const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
842
|
+
const disallowComments = options && options.disallowComments;
|
|
843
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
844
|
+
function scanNext() {
|
|
845
|
+
while (true) {
|
|
846
|
+
const token = _scanner.scan();
|
|
847
|
+
switch (_scanner.getTokenError()) {
|
|
848
|
+
case 4:
|
|
849
|
+
handleError(
|
|
850
|
+
14
|
|
851
|
+
/* ParseErrorCode.InvalidUnicode */
|
|
852
|
+
);
|
|
853
|
+
break;
|
|
854
|
+
case 5:
|
|
855
|
+
handleError(
|
|
856
|
+
15
|
|
857
|
+
/* ParseErrorCode.InvalidEscapeCharacter */
|
|
858
|
+
);
|
|
859
|
+
break;
|
|
860
|
+
case 3:
|
|
861
|
+
handleError(
|
|
862
|
+
13
|
|
863
|
+
/* ParseErrorCode.UnexpectedEndOfNumber */
|
|
864
|
+
);
|
|
865
|
+
break;
|
|
866
|
+
case 1:
|
|
867
|
+
if (!disallowComments) {
|
|
868
|
+
handleError(
|
|
869
|
+
11
|
|
870
|
+
/* ParseErrorCode.UnexpectedEndOfComment */
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
break;
|
|
874
|
+
case 2:
|
|
875
|
+
handleError(
|
|
876
|
+
12
|
|
877
|
+
/* ParseErrorCode.UnexpectedEndOfString */
|
|
878
|
+
);
|
|
879
|
+
break;
|
|
880
|
+
case 6:
|
|
881
|
+
handleError(
|
|
882
|
+
16
|
|
883
|
+
/* ParseErrorCode.InvalidCharacter */
|
|
884
|
+
);
|
|
885
|
+
break;
|
|
886
|
+
}
|
|
887
|
+
switch (token) {
|
|
888
|
+
case 12:
|
|
889
|
+
case 13:
|
|
890
|
+
if (disallowComments) {
|
|
891
|
+
handleError(
|
|
892
|
+
10
|
|
893
|
+
/* ParseErrorCode.InvalidCommentToken */
|
|
894
|
+
);
|
|
895
|
+
} else {
|
|
896
|
+
onComment();
|
|
897
|
+
}
|
|
898
|
+
break;
|
|
899
|
+
case 16:
|
|
900
|
+
handleError(
|
|
901
|
+
1
|
|
902
|
+
/* ParseErrorCode.InvalidSymbol */
|
|
903
|
+
);
|
|
904
|
+
break;
|
|
905
|
+
case 15:
|
|
906
|
+
case 14:
|
|
907
|
+
break;
|
|
908
|
+
default:
|
|
909
|
+
return token;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
914
|
+
onError(error);
|
|
915
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
916
|
+
let token = _scanner.getToken();
|
|
917
|
+
while (token !== 17) {
|
|
918
|
+
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
919
|
+
scanNext();
|
|
920
|
+
break;
|
|
921
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
922
|
+
break;
|
|
923
|
+
}
|
|
924
|
+
token = scanNext();
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
function parseString(isValue) {
|
|
929
|
+
const value = _scanner.getTokenValue();
|
|
930
|
+
if (isValue) {
|
|
931
|
+
onLiteralValue(value);
|
|
932
|
+
} else {
|
|
933
|
+
onObjectProperty(value);
|
|
934
|
+
_jsonPath.push(value);
|
|
935
|
+
}
|
|
936
|
+
scanNext();
|
|
937
|
+
return true;
|
|
938
|
+
}
|
|
939
|
+
function parseLiteral() {
|
|
940
|
+
switch (_scanner.getToken()) {
|
|
941
|
+
case 11:
|
|
942
|
+
const tokenValue = _scanner.getTokenValue();
|
|
943
|
+
let value = Number(tokenValue);
|
|
944
|
+
if (isNaN(value)) {
|
|
945
|
+
handleError(
|
|
946
|
+
2
|
|
947
|
+
/* ParseErrorCode.InvalidNumberFormat */
|
|
948
|
+
);
|
|
949
|
+
value = 0;
|
|
950
|
+
}
|
|
951
|
+
onLiteralValue(value);
|
|
952
|
+
break;
|
|
953
|
+
case 7:
|
|
954
|
+
onLiteralValue(null);
|
|
955
|
+
break;
|
|
956
|
+
case 8:
|
|
957
|
+
onLiteralValue(true);
|
|
958
|
+
break;
|
|
959
|
+
case 9:
|
|
960
|
+
onLiteralValue(false);
|
|
961
|
+
break;
|
|
962
|
+
default:
|
|
963
|
+
return false;
|
|
964
|
+
}
|
|
965
|
+
scanNext();
|
|
966
|
+
return true;
|
|
967
|
+
}
|
|
968
|
+
function parseProperty() {
|
|
969
|
+
if (_scanner.getToken() !== 10) {
|
|
970
|
+
handleError(3, [], [
|
|
971
|
+
2,
|
|
972
|
+
5
|
|
973
|
+
/* SyntaxKind.CommaToken */
|
|
974
|
+
]);
|
|
975
|
+
return false;
|
|
976
|
+
}
|
|
977
|
+
parseString(false);
|
|
978
|
+
if (_scanner.getToken() === 6) {
|
|
979
|
+
onSeparator(":");
|
|
980
|
+
scanNext();
|
|
981
|
+
if (!parseValue()) {
|
|
982
|
+
handleError(4, [], [
|
|
983
|
+
2,
|
|
984
|
+
5
|
|
985
|
+
/* SyntaxKind.CommaToken */
|
|
986
|
+
]);
|
|
987
|
+
}
|
|
988
|
+
} else {
|
|
989
|
+
handleError(5, [], [
|
|
990
|
+
2,
|
|
991
|
+
5
|
|
992
|
+
/* SyntaxKind.CommaToken */
|
|
993
|
+
]);
|
|
994
|
+
}
|
|
995
|
+
_jsonPath.pop();
|
|
996
|
+
return true;
|
|
997
|
+
}
|
|
998
|
+
function parseObject() {
|
|
999
|
+
onObjectBegin();
|
|
1000
|
+
scanNext();
|
|
1001
|
+
let needsComma = false;
|
|
1002
|
+
while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
|
|
1003
|
+
if (_scanner.getToken() === 5) {
|
|
1004
|
+
if (!needsComma) {
|
|
1005
|
+
handleError(4, [], []);
|
|
1006
|
+
}
|
|
1007
|
+
onSeparator(",");
|
|
1008
|
+
scanNext();
|
|
1009
|
+
if (_scanner.getToken() === 2 && allowTrailingComma) {
|
|
1010
|
+
break;
|
|
1011
|
+
}
|
|
1012
|
+
} else if (needsComma) {
|
|
1013
|
+
handleError(6, [], []);
|
|
1014
|
+
}
|
|
1015
|
+
if (!parseProperty()) {
|
|
1016
|
+
handleError(4, [], [
|
|
1017
|
+
2,
|
|
1018
|
+
5
|
|
1019
|
+
/* SyntaxKind.CommaToken */
|
|
1020
|
+
]);
|
|
1021
|
+
}
|
|
1022
|
+
needsComma = true;
|
|
1023
|
+
}
|
|
1024
|
+
onObjectEnd();
|
|
1025
|
+
if (_scanner.getToken() !== 2) {
|
|
1026
|
+
handleError(7, [
|
|
1027
|
+
2
|
|
1028
|
+
/* SyntaxKind.CloseBraceToken */
|
|
1029
|
+
], []);
|
|
1030
|
+
} else {
|
|
1031
|
+
scanNext();
|
|
1032
|
+
}
|
|
1033
|
+
return true;
|
|
1034
|
+
}
|
|
1035
|
+
function parseArray() {
|
|
1036
|
+
onArrayBegin();
|
|
1037
|
+
scanNext();
|
|
1038
|
+
let isFirstElement = true;
|
|
1039
|
+
let needsComma = false;
|
|
1040
|
+
while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
|
|
1041
|
+
if (_scanner.getToken() === 5) {
|
|
1042
|
+
if (!needsComma) {
|
|
1043
|
+
handleError(4, [], []);
|
|
1044
|
+
}
|
|
1045
|
+
onSeparator(",");
|
|
1046
|
+
scanNext();
|
|
1047
|
+
if (_scanner.getToken() === 4 && allowTrailingComma) {
|
|
1048
|
+
break;
|
|
1049
|
+
}
|
|
1050
|
+
} else if (needsComma) {
|
|
1051
|
+
handleError(6, [], []);
|
|
1052
|
+
}
|
|
1053
|
+
if (isFirstElement) {
|
|
1054
|
+
_jsonPath.push(0);
|
|
1055
|
+
isFirstElement = false;
|
|
1056
|
+
} else {
|
|
1057
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
1058
|
+
}
|
|
1059
|
+
if (!parseValue()) {
|
|
1060
|
+
handleError(4, [], [
|
|
1061
|
+
4,
|
|
1062
|
+
5
|
|
1063
|
+
/* SyntaxKind.CommaToken */
|
|
1064
|
+
]);
|
|
1065
|
+
}
|
|
1066
|
+
needsComma = true;
|
|
1067
|
+
}
|
|
1068
|
+
onArrayEnd();
|
|
1069
|
+
if (!isFirstElement) {
|
|
1070
|
+
_jsonPath.pop();
|
|
1071
|
+
}
|
|
1072
|
+
if (_scanner.getToken() !== 4) {
|
|
1073
|
+
handleError(8, [
|
|
1074
|
+
4
|
|
1075
|
+
/* SyntaxKind.CloseBracketToken */
|
|
1076
|
+
], []);
|
|
1077
|
+
} else {
|
|
1078
|
+
scanNext();
|
|
1079
|
+
}
|
|
1080
|
+
return true;
|
|
1081
|
+
}
|
|
1082
|
+
function parseValue() {
|
|
1083
|
+
switch (_scanner.getToken()) {
|
|
1084
|
+
case 3:
|
|
1085
|
+
return parseArray();
|
|
1086
|
+
case 1:
|
|
1087
|
+
return parseObject();
|
|
1088
|
+
case 10:
|
|
1089
|
+
return parseString(true);
|
|
1090
|
+
default:
|
|
1091
|
+
return parseLiteral();
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
scanNext();
|
|
1095
|
+
if (_scanner.getToken() === 17) {
|
|
1096
|
+
if (options.allowEmptyContent) {
|
|
1097
|
+
return true;
|
|
1098
|
+
}
|
|
1099
|
+
handleError(4, [], []);
|
|
1100
|
+
return false;
|
|
1101
|
+
}
|
|
1102
|
+
if (!parseValue()) {
|
|
1103
|
+
handleError(4, [], []);
|
|
1104
|
+
return false;
|
|
1105
|
+
}
|
|
1106
|
+
if (_scanner.getToken() !== 17) {
|
|
1107
|
+
handleError(9, [], []);
|
|
1108
|
+
}
|
|
1109
|
+
return true;
|
|
1110
|
+
}
|
|
1111
|
+
function getNodeType(value) {
|
|
1112
|
+
switch (typeof value) {
|
|
1113
|
+
case "boolean":
|
|
1114
|
+
return "boolean";
|
|
1115
|
+
case "number":
|
|
1116
|
+
return "number";
|
|
1117
|
+
case "string":
|
|
1118
|
+
return "string";
|
|
1119
|
+
case "object": {
|
|
1120
|
+
if (!value) {
|
|
1121
|
+
return "null";
|
|
1122
|
+
} else if (Array.isArray(value)) {
|
|
1123
|
+
return "array";
|
|
1124
|
+
}
|
|
1125
|
+
return "object";
|
|
1126
|
+
}
|
|
1127
|
+
default:
|
|
1128
|
+
return "null";
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
|
|
1132
|
+
// node_modules/jsonc-parser/lib/esm/impl/edit.js
|
|
1133
|
+
function setProperty(text, originalPath, value, options) {
|
|
1134
|
+
const path = originalPath.slice();
|
|
1135
|
+
const errors = [];
|
|
1136
|
+
const root = parseTree(text, errors);
|
|
1137
|
+
let parent = void 0;
|
|
1138
|
+
let lastSegment = void 0;
|
|
1139
|
+
while (path.length > 0) {
|
|
1140
|
+
lastSegment = path.pop();
|
|
1141
|
+
parent = findNodeAtLocation(root, path);
|
|
1142
|
+
if (parent === void 0 && value !== void 0) {
|
|
1143
|
+
if (typeof lastSegment === "string") {
|
|
1144
|
+
value = { [lastSegment]: value };
|
|
1145
|
+
} else {
|
|
1146
|
+
value = [value];
|
|
1147
|
+
}
|
|
1148
|
+
} else {
|
|
1149
|
+
break;
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
if (!parent) {
|
|
1153
|
+
if (value === void 0) {
|
|
1154
|
+
throw new Error("Can not delete in empty document");
|
|
1155
|
+
}
|
|
1156
|
+
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
|
|
1157
|
+
} else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
|
|
1158
|
+
const existing = findNodeAtLocation(parent, [lastSegment]);
|
|
1159
|
+
if (existing !== void 0) {
|
|
1160
|
+
if (value === void 0) {
|
|
1161
|
+
if (!existing.parent) {
|
|
1162
|
+
throw new Error("Malformed AST");
|
|
1163
|
+
}
|
|
1164
|
+
const propertyIndex = parent.children.indexOf(existing.parent);
|
|
1165
|
+
let removeBegin;
|
|
1166
|
+
let removeEnd = existing.parent.offset + existing.parent.length;
|
|
1167
|
+
if (propertyIndex > 0) {
|
|
1168
|
+
let previous = parent.children[propertyIndex - 1];
|
|
1169
|
+
removeBegin = previous.offset + previous.length;
|
|
1170
|
+
} else {
|
|
1171
|
+
removeBegin = parent.offset + 1;
|
|
1172
|
+
if (parent.children.length > 1) {
|
|
1173
|
+
let next = parent.children[1];
|
|
1174
|
+
removeEnd = next.offset;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: "" }, options);
|
|
1178
|
+
} else {
|
|
1179
|
+
return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
|
|
1180
|
+
}
|
|
1181
|
+
} else {
|
|
1182
|
+
if (value === void 0) {
|
|
1183
|
+
return [];
|
|
1184
|
+
}
|
|
1185
|
+
const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
|
|
1186
|
+
const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
|
|
1187
|
+
let edit;
|
|
1188
|
+
if (index > 0) {
|
|
1189
|
+
let previous = parent.children[index - 1];
|
|
1190
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1191
|
+
} else if (parent.children.length === 0) {
|
|
1192
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1193
|
+
} else {
|
|
1194
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty + "," };
|
|
1195
|
+
}
|
|
1196
|
+
return withFormatting(text, edit, options);
|
|
1197
|
+
}
|
|
1198
|
+
} else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
|
|
1199
|
+
const insertIndex = lastSegment;
|
|
1200
|
+
if (insertIndex === -1) {
|
|
1201
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1202
|
+
let edit;
|
|
1203
|
+
if (parent.children.length === 0) {
|
|
1204
|
+
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
1205
|
+
} else {
|
|
1206
|
+
const previous = parent.children[parent.children.length - 1];
|
|
1207
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1208
|
+
}
|
|
1209
|
+
return withFormatting(text, edit, options);
|
|
1210
|
+
} else if (value === void 0 && parent.children.length >= 0) {
|
|
1211
|
+
const removalIndex = lastSegment;
|
|
1212
|
+
const toRemove = parent.children[removalIndex];
|
|
1213
|
+
let edit;
|
|
1214
|
+
if (parent.children.length === 1) {
|
|
1215
|
+
edit = { offset: parent.offset + 1, length: parent.length - 2, content: "" };
|
|
1216
|
+
} else if (parent.children.length - 1 === removalIndex) {
|
|
1217
|
+
let previous = parent.children[removalIndex - 1];
|
|
1218
|
+
let offset = previous.offset + previous.length;
|
|
1219
|
+
let parentEndOffset = parent.offset + parent.length;
|
|
1220
|
+
edit = { offset, length: parentEndOffset - 2 - offset, content: "" };
|
|
1221
|
+
} else {
|
|
1222
|
+
edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: "" };
|
|
1223
|
+
}
|
|
1224
|
+
return withFormatting(text, edit, options);
|
|
1225
|
+
} else if (value !== void 0) {
|
|
1226
|
+
let edit;
|
|
1227
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1228
|
+
if (!options.isArrayInsertion && parent.children.length > lastSegment) {
|
|
1229
|
+
const toModify = parent.children[lastSegment];
|
|
1230
|
+
edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
|
|
1231
|
+
} else if (parent.children.length === 0 || lastSegment === 0) {
|
|
1232
|
+
edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + "," };
|
|
1233
|
+
} else {
|
|
1234
|
+
const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
|
|
1235
|
+
const previous = parent.children[index - 1];
|
|
1236
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
|
|
1237
|
+
}
|
|
1238
|
+
return withFormatting(text, edit, options);
|
|
1239
|
+
} else {
|
|
1240
|
+
throw new Error(`Can not ${value === void 0 ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
|
|
1241
|
+
}
|
|
1242
|
+
} else {
|
|
1243
|
+
throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
function withFormatting(text, edit, options) {
|
|
1247
|
+
if (!options.formattingOptions) {
|
|
1248
|
+
return [edit];
|
|
1249
|
+
}
|
|
1250
|
+
let newText = applyEdit(text, edit);
|
|
1251
|
+
let begin = edit.offset;
|
|
1252
|
+
let end = edit.offset + edit.content.length;
|
|
1253
|
+
if (edit.length === 0 || edit.content.length === 0) {
|
|
1254
|
+
while (begin > 0 && !isEOL(newText, begin - 1)) {
|
|
1255
|
+
begin--;
|
|
1256
|
+
}
|
|
1257
|
+
while (end < newText.length && !isEOL(newText, end)) {
|
|
1258
|
+
end++;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
|
|
1262
|
+
for (let i = edits.length - 1; i >= 0; i--) {
|
|
1263
|
+
const edit2 = edits[i];
|
|
1264
|
+
newText = applyEdit(newText, edit2);
|
|
1265
|
+
begin = Math.min(begin, edit2.offset);
|
|
1266
|
+
end = Math.max(end, edit2.offset + edit2.length);
|
|
1267
|
+
end += edit2.content.length - edit2.length;
|
|
1268
|
+
}
|
|
1269
|
+
const editLength = text.length - (newText.length - end) - begin;
|
|
1270
|
+
return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
|
|
1271
|
+
}
|
|
1272
|
+
function applyEdit(text, edit) {
|
|
1273
|
+
return text.substring(0, edit.offset) + edit.content + text.substring(edit.offset + edit.length);
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
// node_modules/jsonc-parser/lib/esm/main.js
|
|
1277
|
+
var ScanError;
|
|
1278
|
+
(function(ScanError2) {
|
|
1279
|
+
ScanError2[ScanError2["None"] = 0] = "None";
|
|
1280
|
+
ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
1281
|
+
ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
1282
|
+
ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
1283
|
+
ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
1284
|
+
ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
1285
|
+
ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
1286
|
+
})(ScanError || (ScanError = {}));
|
|
1287
|
+
var SyntaxKind;
|
|
1288
|
+
(function(SyntaxKind2) {
|
|
1289
|
+
SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
1290
|
+
SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
1291
|
+
SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
1292
|
+
SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
1293
|
+
SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
|
|
1294
|
+
SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
|
|
1295
|
+
SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
|
|
1296
|
+
SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
|
|
1297
|
+
SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
|
|
1298
|
+
SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
|
|
1299
|
+
SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
|
|
1300
|
+
SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
1301
|
+
SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
1302
|
+
SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
1303
|
+
SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
|
|
1304
|
+
SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
|
|
1305
|
+
SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
|
|
1306
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
1307
|
+
var ParseErrorCode;
|
|
1308
|
+
(function(ParseErrorCode2) {
|
|
1309
|
+
ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
1310
|
+
ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
1311
|
+
ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
1312
|
+
ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
|
|
1313
|
+
ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
|
|
1314
|
+
ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
|
|
1315
|
+
ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
1316
|
+
ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
1317
|
+
ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
1318
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
1319
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
1320
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
1321
|
+
ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
1322
|
+
ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
1323
|
+
ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
1324
|
+
ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
1325
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
1326
|
+
function modify(text, path, value, options) {
|
|
1327
|
+
return setProperty(text, path, value, options);
|
|
1328
|
+
}
|
|
1329
|
+
function applyEdits(text, edits) {
|
|
1330
|
+
let sortedEdits = edits.slice(0).sort((a, b) => {
|
|
1331
|
+
const diff = a.offset - b.offset;
|
|
1332
|
+
if (diff === 0) {
|
|
1333
|
+
return a.length - b.length;
|
|
1334
|
+
}
|
|
1335
|
+
return diff;
|
|
1336
|
+
});
|
|
1337
|
+
let lastModifiedOffset = text.length;
|
|
1338
|
+
for (let i = sortedEdits.length - 1; i >= 0; i--) {
|
|
1339
|
+
let e = sortedEdits[i];
|
|
1340
|
+
if (e.offset + e.length <= lastModifiedOffset) {
|
|
1341
|
+
text = applyEdit(text, e);
|
|
1342
|
+
} else {
|
|
1343
|
+
throw new Error("Overlapping edit");
|
|
1344
|
+
}
|
|
1345
|
+
lastModifiedOffset = e.offset;
|
|
1346
|
+
}
|
|
1347
|
+
return text;
|
|
1348
|
+
}
|
|
21
1349
|
|
|
22
1350
|
// src/core/hook.ts
|
|
23
|
-
import { existsSync as existsSync2, readFileSync as
|
|
1351
|
+
import { existsSync as existsSync2, readFileSync as readFileSync4 } from "fs";
|
|
24
1352
|
|
|
25
1353
|
// src/core/bank.ts
|
|
26
|
-
import { execFileSync } from "child_process";
|
|
27
1354
|
import { existsSync } from "fs";
|
|
28
1355
|
import { homedir } from "os";
|
|
29
|
-
import { basename, dirname, join, normalize, sep } from "path";
|
|
1356
|
+
import { basename, dirname as dirname3, join as join3, normalize, sep } from "path";
|
|
30
1357
|
|
|
31
|
-
// src/core/
|
|
32
|
-
import {
|
|
33
|
-
import { homedir as homedir2 } from "os";
|
|
34
|
-
import { join as join4 } from "path";
|
|
35
|
-
|
|
36
|
-
// src/core/seed.ts
|
|
37
|
-
import { spawn as realSpawn } from "child_process";
|
|
38
|
-
import { dirname as dirname2, join as join2 } from "path";
|
|
39
|
-
import { fileURLToPath } from "url";
|
|
1358
|
+
// src/core/diag.ts
|
|
1359
|
+
import { appendFileSync as appendFileSync2 } from "fs";
|
|
40
1360
|
|
|
41
1361
|
// src/core/log.ts
|
|
42
1362
|
import { appendFileSync, mkdirSync } from "fs";
|
|
43
1363
|
import { tmpdir } from "os";
|
|
44
|
-
import { dirname
|
|
1364
|
+
import { dirname, join } from "path";
|
|
45
1365
|
var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
46
1366
|
var current = ["debug", "info", "warn", "error"].find(
|
|
47
1367
|
(l) => l === process.env.HINDSIGHT_LOG_LEVEL
|
|
48
1368
|
) ?? "info";
|
|
49
1369
|
function logFilePath() {
|
|
50
|
-
return process.env.HINDSIGHT_LOG_FILE ||
|
|
1370
|
+
return process.env.HINDSIGHT_LOG_FILE || join(tmpdir(), "hindsight-coding-agent", "plugin.log");
|
|
51
1371
|
}
|
|
52
1372
|
function write(level, scope, msg, extra) {
|
|
53
1373
|
if (WEIGHT[level] < WEIGHT[current]) return;
|
|
54
1374
|
try {
|
|
55
1375
|
const file = logFilePath();
|
|
56
|
-
mkdirSync(
|
|
1376
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
57
1377
|
appendFileSync(
|
|
58
1378
|
file,
|
|
59
1379
|
`${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
|
|
@@ -68,16 +1388,7 @@ var log = {
|
|
|
68
1388
|
error: (scope, msg, extra) => write("error", scope, msg, extra)
|
|
69
1389
|
};
|
|
70
1390
|
|
|
71
|
-
// src/core/hindsight.ts
|
|
72
|
-
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
73
|
-
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
74
|
-
|
|
75
|
-
// src/core/config.ts
|
|
76
|
-
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join4(homedir2(), ".hindsight", "coding-agent.json");
|
|
77
|
-
var DEFAULT_DAEMON_PORT = 9077;
|
|
78
|
-
|
|
79
1391
|
// src/core/diag.ts
|
|
80
|
-
import { appendFileSync as appendFileSync2 } from "fs";
|
|
81
1392
|
function diagFilePath() {
|
|
82
1393
|
return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
|
|
83
1394
|
}
|
|
@@ -92,6 +1403,32 @@ function diag(harness, event, extra = {}) {
|
|
|
92
1403
|
}
|
|
93
1404
|
}
|
|
94
1405
|
|
|
1406
|
+
// src/core/git-layout.ts
|
|
1407
|
+
import { lstatSync, readFileSync, realpathSync } from "fs";
|
|
1408
|
+
import { dirname as dirname2, isAbsolute, join as join2, resolve } from "path";
|
|
1409
|
+
|
|
1410
|
+
// src/core/config.ts
|
|
1411
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
1412
|
+
import { homedir as homedir2 } from "os";
|
|
1413
|
+
import { join as join6 } from "path";
|
|
1414
|
+
|
|
1415
|
+
// src/core/seed.ts
|
|
1416
|
+
import { spawn as realSpawn } from "child_process";
|
|
1417
|
+
import { dirname as dirname4, join as join4 } from "path";
|
|
1418
|
+
import { fileURLToPath } from "url";
|
|
1419
|
+
|
|
1420
|
+
// src/core/util.ts
|
|
1421
|
+
import { accessSync, constants } from "fs";
|
|
1422
|
+
import { delimiter, join as join5 } from "path";
|
|
1423
|
+
|
|
1424
|
+
// src/core/hindsight.ts
|
|
1425
|
+
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
1426
|
+
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
1427
|
+
|
|
1428
|
+
// src/core/config.ts
|
|
1429
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
|
|
1430
|
+
var DEFAULT_DAEMON_PORT = 9077;
|
|
1431
|
+
|
|
95
1432
|
// src/core/brand.ts
|
|
96
1433
|
function brandWord() {
|
|
97
1434
|
const start = [0, 116, 217];
|
|
@@ -107,12 +1444,12 @@ function brandWord() {
|
|
|
107
1444
|
}
|
|
108
1445
|
|
|
109
1446
|
// src/core/session-cache.ts
|
|
110
|
-
import { mkdirSync as mkdirSync2, readFileSync as
|
|
1447
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync, rmSync, writeFileSync } from "fs";
|
|
111
1448
|
import { tmpdir as tmpdir2 } from "os";
|
|
112
|
-
import { dirname as
|
|
1449
|
+
import { dirname as dirname5, join as join7 } from "path";
|
|
113
1450
|
|
|
114
1451
|
// src/core/retain-hook.ts
|
|
115
|
-
import { readFileSync as
|
|
1452
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
116
1453
|
|
|
117
1454
|
// src/core/retain-cursor.ts
|
|
118
1455
|
import { createHash } from "crypto";
|
|
@@ -121,13 +1458,13 @@ import { createHash } from "crypto";
|
|
|
121
1458
|
import { createHash as createHash2 } from "crypto";
|
|
122
1459
|
|
|
123
1460
|
// src/core/daemon.ts
|
|
124
|
-
import { execFileSync
|
|
125
|
-
import { dirname as
|
|
1461
|
+
import { execFileSync, spawn as realSpawn2 } from "child_process";
|
|
1462
|
+
import { dirname as dirname6, join as join8 } from "path";
|
|
126
1463
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
127
1464
|
function hasRustToolchain() {
|
|
128
1465
|
if (process.platform !== "darwin") return true;
|
|
129
1466
|
try {
|
|
130
|
-
|
|
1467
|
+
execFileSync("cargo", ["--version"], {
|
|
131
1468
|
stdio: "pipe",
|
|
132
1469
|
timeout: 1e4,
|
|
133
1470
|
windowsHide: true
|
|
@@ -139,7 +1476,7 @@ function hasRustToolchain() {
|
|
|
139
1476
|
}
|
|
140
1477
|
function hasUvx() {
|
|
141
1478
|
try {
|
|
142
|
-
|
|
1479
|
+
execFileSync("uvx", ["--version"], {
|
|
143
1480
|
stdio: "pipe",
|
|
144
1481
|
timeout: 1e4,
|
|
145
1482
|
windowsHide: true
|
|
@@ -175,7 +1512,7 @@ function detectLlm(env = process.env) {
|
|
|
175
1512
|
}
|
|
176
1513
|
function onPath(bin) {
|
|
177
1514
|
try {
|
|
178
|
-
|
|
1515
|
+
execFileSync("which", [bin], {
|
|
179
1516
|
stdio: "pipe",
|
|
180
1517
|
timeout: 5e3,
|
|
181
1518
|
windowsHide: true
|
|
@@ -337,27 +1674,63 @@ function readClaudeTranscript(path) {
|
|
|
337
1674
|
}
|
|
338
1675
|
|
|
339
1676
|
// src/core/session-start.ts
|
|
340
|
-
import { readFileSync as
|
|
1677
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
341
1678
|
|
|
342
1679
|
// src/core/git.ts
|
|
343
|
-
import { execFileSync as
|
|
344
|
-
import { resolve } from "path";
|
|
1680
|
+
import { execFileSync as execFileSync2 } from "child_process";
|
|
1681
|
+
import { resolve as resolve2 } from "path";
|
|
345
1682
|
|
|
346
1683
|
// src/core/status.ts
|
|
347
|
-
import { execFileSync as
|
|
1684
|
+
import { execFileSync as execFileSync3 } from "child_process";
|
|
348
1685
|
|
|
349
1686
|
// src/core/survey.ts
|
|
350
1687
|
import { spawn as realSpawn3 } from "child_process";
|
|
351
|
-
import {
|
|
1688
|
+
import { existsSync as existsSync3 } from "fs";
|
|
352
1689
|
import { homedir as homedir3 } from "os";
|
|
353
|
-
import {
|
|
1690
|
+
import { dirname as dirname7, join as join9 } from "path";
|
|
354
1691
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
355
1692
|
|
|
356
|
-
// src/core/
|
|
357
|
-
import {
|
|
358
|
-
import {
|
|
359
|
-
|
|
1693
|
+
// src/core/auto-update.ts
|
|
1694
|
+
import { spawn as realSpawn4 } from "child_process";
|
|
1695
|
+
import {
|
|
1696
|
+
existsSync as existsSync4,
|
|
1697
|
+
mkdirSync as mkdirSync3,
|
|
1698
|
+
readFileSync as readFileSync6,
|
|
1699
|
+
realpathSync as realpathSync2,
|
|
1700
|
+
unlinkSync,
|
|
1701
|
+
writeFileSync as writeFileSync2
|
|
1702
|
+
} from "fs";
|
|
1703
|
+
import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
|
|
1704
|
+
import { dirname as dirname8, join as join10 } from "path";
|
|
360
1705
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
1706
|
+
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
1707
|
+
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
1708
|
+
|
|
1709
|
+
// src/core/skill-sync.ts
|
|
1710
|
+
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync7 } from "fs";
|
|
1711
|
+
import { homedir as homedir5 } from "os";
|
|
1712
|
+
import { dirname as dirname9, join as join11 } from "path";
|
|
1713
|
+
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
1714
|
+
|
|
1715
|
+
// src/core/skill-dirs.ts
|
|
1716
|
+
var SKILL_DIRS = {
|
|
1717
|
+
"claude-code": [".claude", "skills"],
|
|
1718
|
+
// Codex and dsh share the agentskills-standard root; uninstalling either removes the one copy.
|
|
1719
|
+
codex: [".agents", "skills"],
|
|
1720
|
+
dsh: [".agents", "skills"],
|
|
1721
|
+
"antigravity-cli": [".gemini", "config", "skills"],
|
|
1722
|
+
"cursor-cli": [".cursor", "skills"],
|
|
1723
|
+
"copilot-cli": [".copilot", "skills"],
|
|
1724
|
+
"grok-build": [".grok", "skills"],
|
|
1725
|
+
"cline-cli": [".cline", "data", "settings", "skills"],
|
|
1726
|
+
"qwen-code": [".qwen", "skills"],
|
|
1727
|
+
// Qwen's user-level skills root (Storage.getUserSkillsDirs)
|
|
1728
|
+
// The pi family reads the shared ~/.agents/skills too, but writes its OWN root: skill removal is
|
|
1729
|
+
// by fixed directory name, so installing to the shared one would make `uninstall pi` take Codex's
|
|
1730
|
+
// and dsh's copy with it.
|
|
1731
|
+
pi: [".pi", "agent", "skills"],
|
|
1732
|
+
"prime-agent": [".prime", "agent", "skills"]
|
|
1733
|
+
};
|
|
361
1734
|
|
|
362
1735
|
// src/core/transcript-codex.ts
|
|
363
1736
|
function isSyntheticUserText(text) {
|
|
@@ -489,19 +1862,19 @@ function readCopilotTranscript(path) {
|
|
|
489
1862
|
}
|
|
490
1863
|
|
|
491
1864
|
// src/core/transcript-grok.ts
|
|
492
|
-
import { existsSync as
|
|
493
|
-
import { homedir as
|
|
494
|
-
import { join as
|
|
1865
|
+
import { existsSync as existsSync6, readFileSync as readFileSync9, readdirSync } from "fs";
|
|
1866
|
+
import { homedir as homedir6 } from "os";
|
|
1867
|
+
import { join as join12 } from "path";
|
|
495
1868
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
496
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
497
|
-
const sessionsDir =
|
|
498
|
-
const direct =
|
|
499
|
-
if (
|
|
1869
|
+
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join12(homedir6(), ".grok")) {
|
|
1870
|
+
const sessionsDir = join12(grokHome, "sessions");
|
|
1871
|
+
const direct = join12(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
|
|
1872
|
+
if (existsSync6(direct)) return direct;
|
|
500
1873
|
try {
|
|
501
1874
|
for (const candidate of readdirSync(sessionsDir)) {
|
|
502
|
-
const directory =
|
|
503
|
-
if (
|
|
504
|
-
return
|
|
1875
|
+
const directory = join12(sessionsDir, candidate);
|
|
1876
|
+
if (readFileSync9(join12(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
1877
|
+
return join12(directory, sessionId, CHAT_HISTORY);
|
|
505
1878
|
}
|
|
506
1879
|
}
|
|
507
1880
|
} catch {
|
|
@@ -536,12 +1909,12 @@ function readGrokTranscript(path) {
|
|
|
536
1909
|
}
|
|
537
1910
|
|
|
538
1911
|
// src/core/transcript-devin.ts
|
|
539
|
-
import { existsSync as
|
|
1912
|
+
import { existsSync as existsSync7 } from "fs";
|
|
540
1913
|
import { createRequire } from "module";
|
|
541
|
-
import { homedir as
|
|
542
|
-
import { join as
|
|
543
|
-
function devinSessionDb(home =
|
|
544
|
-
return
|
|
1914
|
+
import { homedir as homedir7 } from "os";
|
|
1915
|
+
import { join as join13 } from "path";
|
|
1916
|
+
function devinSessionDb(home = homedir7()) {
|
|
1917
|
+
return join13(home, ".local", "share", "devin", "cli", "sessions.db");
|
|
545
1918
|
}
|
|
546
1919
|
function parseDevinMessages(nodes) {
|
|
547
1920
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -578,24 +1951,230 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
|
|
|
578
1951
|
diag("devin-cli", "sqlite_unavailable", { node: process.version, dbPath });
|
|
579
1952
|
return [];
|
|
580
1953
|
}
|
|
581
|
-
if (!
|
|
1954
|
+
if (!existsSync7(dbPath)) {
|
|
582
1955
|
diag("devin-cli", "session_db_missing", { dbPath });
|
|
583
1956
|
return [];
|
|
584
1957
|
}
|
|
585
1958
|
let db;
|
|
586
1959
|
try {
|
|
587
|
-
db = new Database(dbPath, { readOnly: true });
|
|
588
|
-
const rows = db.prepare(
|
|
589
|
-
"SELECT node_id, chat_message FROM message_nodes WHERE session_id = ? ORDER BY node_id"
|
|
590
|
-
).all(sessionId);
|
|
591
|
-
return parseDevinMessages(rows);
|
|
592
|
-
} catch (error) {
|
|
593
|
-
diag("devin-cli", "session_db_read_failed", { dbPath, error: String(error) });
|
|
594
|
-
return [];
|
|
595
|
-
} finally {
|
|
1960
|
+
db = new Database(dbPath, { readOnly: true });
|
|
1961
|
+
const rows = db.prepare(
|
|
1962
|
+
"SELECT node_id, chat_message FROM message_nodes WHERE session_id = ? ORDER BY node_id"
|
|
1963
|
+
).all(sessionId);
|
|
1964
|
+
return parseDevinMessages(rows);
|
|
1965
|
+
} catch (error) {
|
|
1966
|
+
diag("devin-cli", "session_db_read_failed", { dbPath, error: String(error) });
|
|
1967
|
+
return [];
|
|
1968
|
+
} finally {
|
|
1969
|
+
try {
|
|
1970
|
+
db?.close();
|
|
1971
|
+
} catch {
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
// src/core/transcript-dcode.ts
|
|
1977
|
+
var BLOCK_JOIN = "\n";
|
|
1978
|
+
function contentText(content) {
|
|
1979
|
+
if (typeof content === "string") return content;
|
|
1980
|
+
if (!Array.isArray(content)) return "";
|
|
1981
|
+
return content.flatMap((block) => {
|
|
1982
|
+
if (typeof block === "string") return [block];
|
|
1983
|
+
if (!block || typeof block !== "object") return [];
|
|
1984
|
+
const text = block.text;
|
|
1985
|
+
return typeof text === "string" ? [text] : [];
|
|
1986
|
+
}).join(BLOCK_JOIN);
|
|
1987
|
+
}
|
|
1988
|
+
function readPyValue(s, i) {
|
|
1989
|
+
const skip = (j) => {
|
|
1990
|
+
while (j < s.length && /\s/.test(s[j])) j++;
|
|
1991
|
+
return j;
|
|
1992
|
+
};
|
|
1993
|
+
i = skip(i);
|
|
1994
|
+
if (i >= s.length) return null;
|
|
1995
|
+
const c = s[i];
|
|
1996
|
+
if (c === "'" || c === '"') {
|
|
1997
|
+
let out = "";
|
|
1998
|
+
let j = i + 1;
|
|
1999
|
+
while (j < s.length) {
|
|
2000
|
+
const ch = s[j];
|
|
2001
|
+
if (ch === "\\") {
|
|
2002
|
+
const esc = s[j + 1];
|
|
2003
|
+
if (esc === void 0) return null;
|
|
2004
|
+
if (esc === "n") out += "\n";
|
|
2005
|
+
else if (esc === "t") out += " ";
|
|
2006
|
+
else if (esc === "r") out += "\r";
|
|
2007
|
+
else if (esc === "x") {
|
|
2008
|
+
const hex = s.slice(j + 2, j + 4);
|
|
2009
|
+
if (!/^[0-9a-fA-F]{2}$/.test(hex)) return null;
|
|
2010
|
+
out += String.fromCharCode(parseInt(hex, 16));
|
|
2011
|
+
j += 4;
|
|
2012
|
+
continue;
|
|
2013
|
+
} else if (esc === "u") {
|
|
2014
|
+
const hex = s.slice(j + 2, j + 6);
|
|
2015
|
+
if (!/^[0-9a-fA-F]{4}$/.test(hex)) return null;
|
|
2016
|
+
out += String.fromCharCode(parseInt(hex, 16));
|
|
2017
|
+
j += 6;
|
|
2018
|
+
continue;
|
|
2019
|
+
} else out += esc;
|
|
2020
|
+
j += 2;
|
|
2021
|
+
continue;
|
|
2022
|
+
}
|
|
2023
|
+
if (ch === c) return { value: out, end: j + 1 };
|
|
2024
|
+
out += ch;
|
|
2025
|
+
j++;
|
|
2026
|
+
}
|
|
2027
|
+
return null;
|
|
2028
|
+
}
|
|
2029
|
+
if (s.startsWith("True", i)) return { value: true, end: i + 4 };
|
|
2030
|
+
if (s.startsWith("False", i)) return { value: false, end: i + 5 };
|
|
2031
|
+
if (s.startsWith("None", i)) return { value: null, end: i + 4 };
|
|
2032
|
+
if (c === "[" || c === "{") {
|
|
2033
|
+
const isList = c === "[";
|
|
2034
|
+
const close = isList ? "]" : "}";
|
|
2035
|
+
const list = [];
|
|
2036
|
+
const obj = {};
|
|
2037
|
+
let j = skip(i + 1);
|
|
2038
|
+
if (s[j] === close) return { value: isList ? list : obj, end: j + 1 };
|
|
2039
|
+
for (; ; ) {
|
|
2040
|
+
const key = readPyValue(s, j);
|
|
2041
|
+
if (!key) return null;
|
|
2042
|
+
j = skip(key.end);
|
|
2043
|
+
if (isList) {
|
|
2044
|
+
list.push(key.value);
|
|
2045
|
+
} else {
|
|
2046
|
+
if (s[j] !== ":" || typeof key.value !== "string") return null;
|
|
2047
|
+
const val = readPyValue(s, j + 1);
|
|
2048
|
+
if (!val) return null;
|
|
2049
|
+
obj[key.value] = val.value;
|
|
2050
|
+
j = skip(val.end);
|
|
2051
|
+
}
|
|
2052
|
+
if (s[j] === ",") {
|
|
2053
|
+
j = skip(j + 1);
|
|
2054
|
+
if (s[j] === close) return { value: isList ? list : obj, end: j + 1 };
|
|
2055
|
+
continue;
|
|
2056
|
+
}
|
|
2057
|
+
if (s[j] === close) return { value: isList ? list : obj, end: j + 1 };
|
|
2058
|
+
return null;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
const num = /^-?\d+(\.\d+)?([eE][-+]?\d+)?/.exec(s.slice(i));
|
|
2062
|
+
if (num) return { value: Number(num[0]), end: i + num[0].length };
|
|
2063
|
+
return null;
|
|
2064
|
+
}
|
|
2065
|
+
function dcodeAssistantText(raw) {
|
|
2066
|
+
const trimmed = raw.trim();
|
|
2067
|
+
if (!trimmed.startsWith("[{") && !trimmed.startsWith("[ {")) return raw;
|
|
2068
|
+
const parsed = readPyValue(trimmed, 0);
|
|
2069
|
+
if (!parsed || readPyValue(trimmed, parsed.end) !== null) return "";
|
|
2070
|
+
if (!Array.isArray(parsed.value)) return "";
|
|
2071
|
+
return contentText(parsed.value);
|
|
2072
|
+
}
|
|
2073
|
+
function readDcodeTranscript(path) {
|
|
2074
|
+
const turns = [];
|
|
2075
|
+
for (const rawLine of readJsonlTail(path, { scope: "dcode" }).lines) {
|
|
2076
|
+
if (!rawLine.trim()) continue;
|
|
2077
|
+
let parsed;
|
|
2078
|
+
try {
|
|
2079
|
+
parsed = JSON.parse(rawLine);
|
|
2080
|
+
} catch {
|
|
2081
|
+
continue;
|
|
2082
|
+
}
|
|
2083
|
+
if (!parsed || typeof parsed !== "object") continue;
|
|
2084
|
+
const record = parsed;
|
|
2085
|
+
if (record.schema_version !== 1) continue;
|
|
2086
|
+
const role = record.role;
|
|
2087
|
+
const stamp = typeof record.timestamp === "string" && record.timestamp ? { timestamp: record.timestamp } : {};
|
|
2088
|
+
if (role === "user" || role === "assistant") {
|
|
2089
|
+
const text = stripInjectedMemory(contentText(record.content)).trim();
|
|
2090
|
+
if (text) turns.push({ role, content: text, ...stamp });
|
|
2091
|
+
} else if (role === "tool" && typeof record.name === "string" && record.name.trim()) {
|
|
2092
|
+
turns.push({ role: "action", content: actionLine(record.name, record.content), ...stamp });
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
return turns;
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
// src/core/transcript-qwen.ts
|
|
2099
|
+
var HOOK_CONTEXT_PART_RE = /^\s*<qwen:user-prompt-submit-context>[\s\S]*<\/qwen:user-prompt-submit-context>\s*$/;
|
|
2100
|
+
function isWholeHookContextPart(part) {
|
|
2101
|
+
return typeof part.text === "string" && HOOK_CONTEXT_PART_RE.test(part.text);
|
|
2102
|
+
}
|
|
2103
|
+
function isRealUser(line) {
|
|
2104
|
+
if (typeof line.provenance === "string") return line.provenance === "real_user";
|
|
2105
|
+
if (line.provenance !== void 0) return false;
|
|
2106
|
+
const isSubagentEnvelope = line.agentId !== void 0 || line.isSidechain !== void 0;
|
|
2107
|
+
if (!isSubagentEnvelope) return false;
|
|
2108
|
+
return line.subtype === void 0 || line.subtype === "mid_turn_user_message";
|
|
2109
|
+
}
|
|
2110
|
+
function renderLine2(parts, type) {
|
|
2111
|
+
if (!Array.isArray(parts)) return [];
|
|
2112
|
+
const last = parts.length > 1 ? parts[parts.length - 1] : void 0;
|
|
2113
|
+
const dropLast = !!last && typeof last === "object" && isWholeHookContextPart(last) ? parts.length - 1 : -1;
|
|
2114
|
+
const texts = [];
|
|
2115
|
+
const actions = [];
|
|
2116
|
+
for (const [i, part] of parts.entries()) {
|
|
2117
|
+
if (!part || typeof part !== "object") continue;
|
|
2118
|
+
if (i === dropLast) continue;
|
|
2119
|
+
if (part.thought === true) continue;
|
|
2120
|
+
if (typeof part.text === "string") {
|
|
2121
|
+
const text = stripInjectedMemory(part.text).trim();
|
|
2122
|
+
if (text) texts.push(text);
|
|
2123
|
+
} else if (part.functionCall && typeof part.functionCall.name === "string") {
|
|
2124
|
+
actions.push({
|
|
2125
|
+
role: "action",
|
|
2126
|
+
content: actionLine(part.functionCall.name, part.functionCall.args)
|
|
2127
|
+
});
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
const out = [];
|
|
2131
|
+
const joined = texts.join("\n").trim();
|
|
2132
|
+
if (joined) out.push({ role: type, content: joined });
|
|
2133
|
+
out.push(...actions);
|
|
2134
|
+
return out;
|
|
2135
|
+
}
|
|
2136
|
+
function readQwenTranscript(path) {
|
|
2137
|
+
const turns = [];
|
|
2138
|
+
try {
|
|
2139
|
+
collectQwenTurns(path, turns);
|
|
2140
|
+
} catch (err) {
|
|
2141
|
+
log.warn("qwen-code", "transcript read failed \u2014 retaining what was parsed", {
|
|
2142
|
+
path,
|
|
2143
|
+
turns: turns.length,
|
|
2144
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2145
|
+
});
|
|
2146
|
+
}
|
|
2147
|
+
return turns;
|
|
2148
|
+
}
|
|
2149
|
+
function collectQwenTurns(path, turns) {
|
|
2150
|
+
for (const rawLine of readJsonlTail(path, { scope: "qwen-code" }).lines) {
|
|
2151
|
+
const trimmed = rawLine.trim();
|
|
2152
|
+
if (!trimmed) continue;
|
|
2153
|
+
let parsed;
|
|
596
2154
|
try {
|
|
597
|
-
|
|
2155
|
+
parsed = JSON.parse(trimmed);
|
|
598
2156
|
} catch {
|
|
2157
|
+
continue;
|
|
2158
|
+
}
|
|
2159
|
+
if (typeof parsed !== "object" || parsed === null) continue;
|
|
2160
|
+
const line = parsed;
|
|
2161
|
+
if (line.type !== "user" && line.type !== "assistant") continue;
|
|
2162
|
+
if (line.type === "user" && !isRealUser(line)) continue;
|
|
2163
|
+
if (typeof line.message !== "object" || line.message === null) continue;
|
|
2164
|
+
const sp = line.systemPayload;
|
|
2165
|
+
if (line.type === "user" && sp && typeof sp === "object" && typeof sp.hookContext === "string" && typeof sp.displayText === "string") {
|
|
2166
|
+
const content = stripInjectedMemory(sp.displayText).trim();
|
|
2167
|
+
if (content) {
|
|
2168
|
+
const turn = { role: "user", content };
|
|
2169
|
+
if (typeof line.timestamp === "string") turn.timestamp = line.timestamp;
|
|
2170
|
+
turns.push(turn);
|
|
2171
|
+
}
|
|
2172
|
+
continue;
|
|
2173
|
+
}
|
|
2174
|
+
for (const rendered of renderLine2(line.message.parts, line.type)) {
|
|
2175
|
+
const turn = { role: rendered.role, content: rendered.content };
|
|
2176
|
+
if (typeof line.timestamp === "string") turn.timestamp = line.timestamp;
|
|
2177
|
+
turns.push(turn);
|
|
599
2178
|
}
|
|
600
2179
|
}
|
|
601
2180
|
}
|
|
@@ -623,6 +2202,19 @@ var codexPrompt = {
|
|
|
623
2202
|
sessionId: ev.session_id
|
|
624
2203
|
})
|
|
625
2204
|
};
|
|
2205
|
+
var dcodePrompt = {
|
|
2206
|
+
...claudePrompt,
|
|
2207
|
+
harness: "dcode"
|
|
2208
|
+
};
|
|
2209
|
+
var qwenPrompt = {
|
|
2210
|
+
...claudePrompt,
|
|
2211
|
+
harness: "qwen-code",
|
|
2212
|
+
parse: (ev) => ({
|
|
2213
|
+
prompt: ev.submitted_prompt,
|
|
2214
|
+
cwd: ev.cwd,
|
|
2215
|
+
sessionId: ev.session_id
|
|
2216
|
+
})
|
|
2217
|
+
};
|
|
626
2218
|
var antigravityCwd = (ev) => Array.isArray(ev.workspacePaths) ? ev.workspacePaths[0] : void 0;
|
|
627
2219
|
var antigravityPrompt = {
|
|
628
2220
|
harness: "antigravity-cli",
|
|
@@ -727,6 +2319,28 @@ var HOOK_HARNESSES = {
|
|
|
727
2319
|
readTranscript: readCodexTranscript
|
|
728
2320
|
}
|
|
729
2321
|
},
|
|
2322
|
+
dcode: {
|
|
2323
|
+
configStyle: "nested",
|
|
2324
|
+
install: {
|
|
2325
|
+
sessionStart: { event: "SessionStart", entry: "dcode-sessionstart-hook.js", timeout: 30 },
|
|
2326
|
+
prompt: { event: "UserPromptSubmit", entry: "dcode-hook.js", timeout: 30 },
|
|
2327
|
+
stop: { event: "Stop", entry: "dcode-stop-hook.js", timeout: 60 }
|
|
2328
|
+
},
|
|
2329
|
+
sessionStart: standardSessionStart("dcode"),
|
|
2330
|
+
prompt: dcodePrompt,
|
|
2331
|
+
retain: {
|
|
2332
|
+
hostTimeoutSec: 60,
|
|
2333
|
+
harness: "dcode",
|
|
2334
|
+
parse: (ev) => ({
|
|
2335
|
+
sessionId: ev.session_id,
|
|
2336
|
+
transcriptPath: ev.transcript_path,
|
|
2337
|
+
cwd: ev.cwd,
|
|
2338
|
+
lastAssistantMessage: ev.last_assistant_message
|
|
2339
|
+
}),
|
|
2340
|
+
readTranscript: readDcodeTranscript,
|
|
2341
|
+
readLastMessage: dcodeAssistantText
|
|
2342
|
+
}
|
|
2343
|
+
},
|
|
730
2344
|
"antigravity-cli": {
|
|
731
2345
|
configStyle: "flat",
|
|
732
2346
|
install: {
|
|
@@ -887,21 +2501,54 @@ var HOOK_HARNESSES = {
|
|
|
887
2501
|
}),
|
|
888
2502
|
readTranscript: readGrokTranscript
|
|
889
2503
|
}
|
|
2504
|
+
},
|
|
2505
|
+
"qwen-code": {
|
|
2506
|
+
configStyle: "nested",
|
|
2507
|
+
timeoutUnit: "milliseconds",
|
|
2508
|
+
// TIMEOUTS ARE MILLISECONDS HERE, not seconds like every other harness in this table: Qwen's
|
|
2509
|
+
// hookRunner does `setTimeout(..., hookConfig.timeout ?? DEFAULT_HOOK_TIMEOUT)` with
|
|
2510
|
+
// DEFAULT_HOOK_TIMEOUT = 60_000 ("Timeout in milliseconds, default 60000"). Writing 30/60
|
|
2511
|
+
// registers 30ms/60ms hooks, which die before a Node process starts — and Qwen spawns hooks
|
|
2512
|
+
// `detached` and terminates the whole process TREE on timeout, so the retain is genuinely lost
|
|
2513
|
+
// rather than merely orphaned. `retain.hostTimeoutSec` below stays SECONDS, as its name says;
|
|
2514
|
+
// these two numbers are the same budget in different units for this harness alone.
|
|
2515
|
+
// The prompt timeout must also stay above core/hook.ts's HOOK_REFLECT_CAP_MS (25_000).
|
|
2516
|
+
install: {
|
|
2517
|
+
sessionStart: { event: "SessionStart", entry: "qwen-sessionstart-hook.js", timeout: 3e4 },
|
|
2518
|
+
prompt: { event: "UserPromptSubmit", entry: "qwen-hook.js", timeout: 3e4 },
|
|
2519
|
+
stop: { event: "Stop", entry: "qwen-stop-hook.js", timeout: 6e4 }
|
|
2520
|
+
},
|
|
2521
|
+
sessionStart: standardSessionStart("qwen-code"),
|
|
2522
|
+
prompt: qwenPrompt,
|
|
2523
|
+
retain: {
|
|
2524
|
+
hostTimeoutSec: 60,
|
|
2525
|
+
harness: "qwen-code",
|
|
2526
|
+
parse: (ev) => ({
|
|
2527
|
+
sessionId: ev.session_id,
|
|
2528
|
+
// Qwen supplies the path, but as the EMPTY STRING (not null, not absent) when chat
|
|
2529
|
+
// recording is off — runRetainHook's `if (!transcriptPath) return` already covers that.
|
|
2530
|
+
transcriptPath: ev.transcript_path,
|
|
2531
|
+
cwd: ev.cwd
|
|
2532
|
+
}),
|
|
2533
|
+
readTranscript: readQwenTranscript
|
|
2534
|
+
}
|
|
890
2535
|
}
|
|
891
2536
|
};
|
|
892
2537
|
|
|
893
2538
|
// src/core/history.ts
|
|
2539
|
+
import { execFileSync as execFileSync4 } from "child_process";
|
|
894
2540
|
import {
|
|
895
2541
|
closeSync as closeSync2,
|
|
896
|
-
existsSync as
|
|
2542
|
+
existsSync as existsSync8,
|
|
897
2543
|
openSync as openSync2,
|
|
898
2544
|
readdirSync as readdirSync2,
|
|
899
|
-
readFileSync as
|
|
2545
|
+
readFileSync as readFileSync10,
|
|
900
2546
|
readSync as readSync2,
|
|
901
2547
|
statSync as statSync2
|
|
902
2548
|
} from "fs";
|
|
903
|
-
import {
|
|
904
|
-
import {
|
|
2549
|
+
import { createHash as createHash3 } from "crypto";
|
|
2550
|
+
import { homedir as homedir8 } from "os";
|
|
2551
|
+
import { join as join14 } from "path";
|
|
905
2552
|
import * as zlib2 from "zlib";
|
|
906
2553
|
|
|
907
2554
|
// src/core/transcript-dsh.ts
|
|
@@ -947,6 +2594,55 @@ function parseArgs(raw) {
|
|
|
947
2594
|
}
|
|
948
2595
|
}
|
|
949
2596
|
|
|
2597
|
+
// src/core/transcript-pi.ts
|
|
2598
|
+
function renderMessage(m) {
|
|
2599
|
+
if (!m || typeof m !== "object") return [];
|
|
2600
|
+
const role = m.role;
|
|
2601
|
+
if (role !== "user" && role !== "assistant") return [];
|
|
2602
|
+
const texts = [];
|
|
2603
|
+
const actions = [];
|
|
2604
|
+
if (typeof m.content === "string") {
|
|
2605
|
+
const t = stripInjectedMemory(m.content).trim();
|
|
2606
|
+
if (t) texts.push(t);
|
|
2607
|
+
} else if (Array.isArray(m.content)) {
|
|
2608
|
+
for (const part of m.content) {
|
|
2609
|
+
if (!part || typeof part !== "object") continue;
|
|
2610
|
+
const block = part;
|
|
2611
|
+
if (block.type === "text" && typeof block.text === "string") {
|
|
2612
|
+
const t = stripInjectedMemory(block.text).trim();
|
|
2613
|
+
if (t) texts.push(t);
|
|
2614
|
+
} else if (block.type === "toolCall" && typeof block.name === "string") {
|
|
2615
|
+
actions.push({ role: "action", content: actionLine(block.name, block.arguments) });
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
}
|
|
2619
|
+
const out = [];
|
|
2620
|
+
const joined = texts.join("\n").trim();
|
|
2621
|
+
if (joined) out.push({ role, content: joined });
|
|
2622
|
+
out.push(...actions);
|
|
2623
|
+
return out;
|
|
2624
|
+
}
|
|
2625
|
+
function readPiTranscript(path) {
|
|
2626
|
+
const turns = [];
|
|
2627
|
+
for (const rawLine of readJsonlTail(path, { scope: "pi" }).lines) {
|
|
2628
|
+
const trimmed = rawLine.trim();
|
|
2629
|
+
if (!trimmed) continue;
|
|
2630
|
+
let parsed;
|
|
2631
|
+
try {
|
|
2632
|
+
parsed = JSON.parse(trimmed);
|
|
2633
|
+
} catch {
|
|
2634
|
+
continue;
|
|
2635
|
+
}
|
|
2636
|
+
if (typeof parsed !== "object" || parsed === null) continue;
|
|
2637
|
+
const entry = parsed;
|
|
2638
|
+
if (entry.type !== "message" || !entry.message) continue;
|
|
2639
|
+
for (const turn of renderMessage(entry.message)) {
|
|
2640
|
+
turns.push(entry.timestamp ? { ...turn, timestamp: entry.timestamp } : turn);
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
return turns;
|
|
2644
|
+
}
|
|
2645
|
+
|
|
950
2646
|
// src/core/zstd-frames.ts
|
|
951
2647
|
import * as zlib from "zlib";
|
|
952
2648
|
var ZSTD_MAGIC = 4247762216;
|
|
@@ -996,15 +2692,18 @@ function zstdDecompressFrames(buffer) {
|
|
|
996
2692
|
}
|
|
997
2693
|
|
|
998
2694
|
// src/core/history.ts
|
|
999
|
-
function claudeProjectDir(repoDir, home =
|
|
1000
|
-
return
|
|
2695
|
+
function claudeProjectDir(repoDir, home = homedir8()) {
|
|
2696
|
+
return join14(home, ".claude", "projects", repoDir.replace(/[^a-zA-Z0-9]/g, "-"));
|
|
2697
|
+
}
|
|
2698
|
+
function piSessionDir(repoDir) {
|
|
2699
|
+
return `--${repoDir.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
|
|
1001
2700
|
}
|
|
1002
2701
|
function withinRepo(dir, repoDir) {
|
|
1003
2702
|
return !!dir && (dir === repoDir || dir.startsWith(repoDir.endsWith("/") ? repoDir : repoDir + "/"));
|
|
1004
2703
|
}
|
|
1005
2704
|
function claudeSessionCwd(file) {
|
|
1006
2705
|
try {
|
|
1007
|
-
for (const line of
|
|
2706
|
+
for (const line of readFileSync10(file, "utf8").split("\n", 400)) {
|
|
1008
2707
|
if (!line.includes('"cwd"')) continue;
|
|
1009
2708
|
const cwd = JSON.parse(line).cwd;
|
|
1010
2709
|
if (cwd) return cwd;
|
|
@@ -1046,13 +2745,13 @@ function listDir(dir) {
|
|
|
1046
2745
|
}
|
|
1047
2746
|
}
|
|
1048
2747
|
function jsonlFiles(dir) {
|
|
1049
|
-
return listDir(dir).filter((f) => f.endsWith(".jsonl")).map((f) =>
|
|
2748
|
+
return listDir(dir).filter((f) => f.endsWith(".jsonl")).map((f) => join14(dir, f));
|
|
1050
2749
|
}
|
|
1051
2750
|
function claudeHistory(repoDir, home) {
|
|
1052
|
-
const root =
|
|
2751
|
+
const root = join14(home, ".claude", "projects");
|
|
1053
2752
|
const exact = claudeProjectDir(repoDir, home);
|
|
1054
2753
|
const prefix = exact + "-";
|
|
1055
|
-
const dirs = listDir(root).map((d) =>
|
|
2754
|
+
const dirs = listDir(root).map((d) => join14(root, d)).filter((d) => d === exact || d.startsWith(prefix));
|
|
1056
2755
|
const sessions = [];
|
|
1057
2756
|
let unattributed = 0;
|
|
1058
2757
|
for (const file of dirs.flatMap(jsonlFiles)) {
|
|
@@ -1072,12 +2771,12 @@ function claudeHistory(repoDir, home) {
|
|
|
1072
2771
|
return { supported: true, sessions, unattributed };
|
|
1073
2772
|
}
|
|
1074
2773
|
function codexHistory(repoDir, home) {
|
|
1075
|
-
const root =
|
|
1076
|
-
if (!
|
|
2774
|
+
const root = join14(home, ".codex", "sessions");
|
|
2775
|
+
if (!existsSync8(root)) return { supported: true, sessions: [] };
|
|
1077
2776
|
const files = [];
|
|
1078
2777
|
const walk = (dir) => {
|
|
1079
2778
|
for (const entry of readdirSync2(dir)) {
|
|
1080
|
-
const p =
|
|
2779
|
+
const p = join14(dir, entry);
|
|
1081
2780
|
if (statSync2(p).isDirectory()) walk(p);
|
|
1082
2781
|
else if (entry.endsWith(".jsonl")) files.push(p);
|
|
1083
2782
|
}
|
|
@@ -1101,9 +2800,61 @@ function codexHistory(repoDir, home) {
|
|
|
1101
2800
|
}
|
|
1102
2801
|
return { supported: true, sessions };
|
|
1103
2802
|
}
|
|
2803
|
+
var DCODE_THREADS_SCHEMA_VERSION = 1;
|
|
2804
|
+
function dcodeTranscriptPath(root, threadId) {
|
|
2805
|
+
const digest = createHash3("sha256").update(threadId, "utf8").digest("hex");
|
|
2806
|
+
const suffix = `--${digest}.jsonl`;
|
|
2807
|
+
try {
|
|
2808
|
+
const match = readdirSync2(root).find((entry) => entry.endsWith(suffix));
|
|
2809
|
+
return match ? join14(root, match) : void 0;
|
|
2810
|
+
} catch {
|
|
2811
|
+
return void 0;
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
function dcodeHistory(repoDir, home, runCli) {
|
|
2815
|
+
const root = join14(process.env.DEEPAGENTS_HOME || join14(home, ".deepagents"), "transcripts");
|
|
2816
|
+
if (!existsSync8(root)) return { supported: true, sessions: [] };
|
|
2817
|
+
let listed;
|
|
2818
|
+
try {
|
|
2819
|
+
listed = JSON.parse(runCli(["threads", "list", "--json"]));
|
|
2820
|
+
} catch {
|
|
2821
|
+
return {
|
|
2822
|
+
supported: false,
|
|
2823
|
+
reason: "dcode transcripts record no working directory, so `dcode threads list --json` is the only way to tell which sessions belong to this repo \u2014 and the dcode CLI is not runnable here",
|
|
2824
|
+
sessions: []
|
|
2825
|
+
};
|
|
2826
|
+
}
|
|
2827
|
+
const payload = listed;
|
|
2828
|
+
if (payload?.schema_version !== DCODE_THREADS_SCHEMA_VERSION || !Array.isArray(payload.data)) {
|
|
2829
|
+
return {
|
|
2830
|
+
supported: false,
|
|
2831
|
+
reason: `unrecognized \`dcode threads list --json\` schema (expected schema_version ${DCODE_THREADS_SCHEMA_VERSION})`,
|
|
2832
|
+
sessions: []
|
|
2833
|
+
};
|
|
2834
|
+
}
|
|
2835
|
+
const sessions = [];
|
|
2836
|
+
let unattributed = 0;
|
|
2837
|
+
for (const row of payload.data) {
|
|
2838
|
+
const threadId = typeof row?.thread_id === "string" ? row.thread_id : void 0;
|
|
2839
|
+
if (!threadId) continue;
|
|
2840
|
+
if (typeof row.cwd !== "string") {
|
|
2841
|
+
unattributed++;
|
|
2842
|
+
continue;
|
|
2843
|
+
}
|
|
2844
|
+
if (!withinRepo(row.cwd, repoDir)) continue;
|
|
2845
|
+
const file = dcodeTranscriptPath(root, threadId);
|
|
2846
|
+
if (!file) continue;
|
|
2847
|
+
try {
|
|
2848
|
+
const session = toSession(threadId, readDcodeTranscript(file));
|
|
2849
|
+
if (session) sessions.push(session);
|
|
2850
|
+
} catch {
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
return { supported: true, sessions, ...unattributed ? { unattributed } : {} };
|
|
2854
|
+
}
|
|
1104
2855
|
function dshHistory(repoDir, home) {
|
|
1105
|
-
const root = process.env.DSH_HOME ?
|
|
1106
|
-
if (!
|
|
2856
|
+
const root = process.env.DSH_HOME ? join14(process.env.DSH_HOME, "sessions") : join14(home, ".dsh", "sessions");
|
|
2857
|
+
if (!existsSync8(root)) return { supported: true, sessions: [] };
|
|
1107
2858
|
if (typeof zlib2.zstdDecompressSync !== "function") {
|
|
1108
2859
|
return {
|
|
1109
2860
|
supported: false,
|
|
@@ -1113,15 +2864,15 @@ function dshHistory(repoDir, home) {
|
|
|
1113
2864
|
}
|
|
1114
2865
|
const sessions = [];
|
|
1115
2866
|
let unattributed = 0;
|
|
1116
|
-
for (const dir of readdirSync2(root).map((project) =>
|
|
2867
|
+
for (const dir of readdirSync2(root).map((project) => join14(root, project))) {
|
|
1117
2868
|
let sessionDirs;
|
|
1118
2869
|
try {
|
|
1119
|
-
sessionDirs = readdirSync2(dir).map((id) =>
|
|
2870
|
+
sessionDirs = readdirSync2(dir).map((id) => join14(dir, id));
|
|
1120
2871
|
} catch {
|
|
1121
2872
|
continue;
|
|
1122
2873
|
}
|
|
1123
2874
|
for (const sessionDir of sessionDirs) {
|
|
1124
|
-
const file = ["session.jsonl.zstd", "session.jsonl"].map((name) =>
|
|
2875
|
+
const file = ["session.jsonl.zstd", "session.jsonl"].map((name) => join14(sessionDir, name)).find((candidate) => existsSync8(candidate));
|
|
1125
2876
|
if (!file) continue;
|
|
1126
2877
|
try {
|
|
1127
2878
|
const lines = readDshLog(file);
|
|
@@ -1147,20 +2898,69 @@ function dshHistory(repoDir, home) {
|
|
|
1147
2898
|
return { supported: true, sessions, unattributed };
|
|
1148
2899
|
}
|
|
1149
2900
|
function readDshLog(file) {
|
|
1150
|
-
const bytes =
|
|
2901
|
+
const bytes = readFileSync10(file);
|
|
1151
2902
|
const text = file.endsWith(".zstd") ? zstdDecompressFrames(bytes) : bytes.toString("utf8");
|
|
1152
2903
|
return text.split("\n").filter((line) => line.trim());
|
|
1153
2904
|
}
|
|
2905
|
+
function piFamilySessions(files, repoDir) {
|
|
2906
|
+
const sessions = [];
|
|
2907
|
+
let unattributed = 0;
|
|
2908
|
+
for (const file of files) {
|
|
2909
|
+
try {
|
|
2910
|
+
const head = firstLine(file);
|
|
2911
|
+
if (!head) continue;
|
|
2912
|
+
const meta = JSON.parse(head);
|
|
2913
|
+
if (meta?.type !== "session") continue;
|
|
2914
|
+
if (!meta.cwd) {
|
|
2915
|
+
unattributed++;
|
|
2916
|
+
continue;
|
|
2917
|
+
}
|
|
2918
|
+
if (!withinRepo(meta.cwd, repoDir)) continue;
|
|
2919
|
+
const s = toSession(meta.id ?? file, readPiTranscript(file));
|
|
2920
|
+
if (s) sessions.push(s);
|
|
2921
|
+
} catch {
|
|
2922
|
+
}
|
|
2923
|
+
}
|
|
2924
|
+
return { supported: true, sessions, unattributed };
|
|
2925
|
+
}
|
|
2926
|
+
function piHistory(repoDir, home) {
|
|
2927
|
+
const root = join14(home, ".pi", "agent", "sessions");
|
|
2928
|
+
if (!existsSync8(root)) return { supported: true, sessions: [] };
|
|
2929
|
+
const exact = piSessionDir(repoDir);
|
|
2930
|
+
const nested = `${exact.slice(0, -2)}-`;
|
|
2931
|
+
const files = [];
|
|
2932
|
+
for (const dir of listDir(root).filter((d) => d === exact || d.startsWith(nested))) {
|
|
2933
|
+
files.push(...jsonlFiles(join14(root, dir)));
|
|
2934
|
+
}
|
|
2935
|
+
return piFamilySessions(files, repoDir);
|
|
2936
|
+
}
|
|
2937
|
+
function primeAgentHistory(repoDir, home) {
|
|
2938
|
+
const root = join14(home, ".prime", "agent", "sessions");
|
|
2939
|
+
if (!existsSync8(root)) return { supported: true, sessions: [] };
|
|
2940
|
+
return piFamilySessions(jsonlFiles(root), repoDir);
|
|
2941
|
+
}
|
|
1154
2942
|
var SQLITE_HISTORY = "keeps session history in an internal SQLite database, whose schema is unversioned and would break on any upstream change";
|
|
1155
|
-
function importLocalHistory(harness, repoDir, home =
|
|
2943
|
+
function importLocalHistory(harness, repoDir, home = homedir8(), runDcodeCli) {
|
|
1156
2944
|
switch (harness) {
|
|
1157
2945
|
case "claude-code":
|
|
1158
2946
|
return claudeHistory(repoDir, home);
|
|
1159
2947
|
case "codex":
|
|
1160
2948
|
return codexHistory(repoDir, home);
|
|
2949
|
+
case "dcode":
|
|
2950
|
+
return dcodeHistory(
|
|
2951
|
+
repoDir,
|
|
2952
|
+
home,
|
|
2953
|
+
runDcodeCli ?? ((args) => execFileSync4("dcode", args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }))
|
|
2954
|
+
);
|
|
1161
2955
|
case "dsh":
|
|
1162
2956
|
return dshHistory(repoDir, home);
|
|
2957
|
+
case "pi":
|
|
2958
|
+
return piHistory(repoDir, home);
|
|
2959
|
+
case "prime-agent":
|
|
2960
|
+
return primeAgentHistory(repoDir, home);
|
|
1163
2961
|
case "opencode":
|
|
2962
|
+
// opencode v2 keeps sessions in the SAME `opencode.db` v1 does.
|
|
2963
|
+
case "opencode2":
|
|
1164
2964
|
case "kilo":
|
|
1165
2965
|
case "cursor-cli":
|
|
1166
2966
|
case "cline-cli":
|
|
@@ -1173,18 +2973,18 @@ function importLocalHistory(harness, repoDir, home = homedir7()) {
|
|
|
1173
2973
|
}
|
|
1174
2974
|
|
|
1175
2975
|
// src/core/legacy.ts
|
|
1176
|
-
import { existsSync as
|
|
1177
|
-
import { homedir as
|
|
1178
|
-
import { join as
|
|
2976
|
+
import { existsSync as existsSync9, readFileSync as readFileSync11 } from "fs";
|
|
2977
|
+
import { homedir as homedir9 } from "os";
|
|
2978
|
+
import { join as join15 } from "path";
|
|
1179
2979
|
var LEGACY_CONFIG_FILES = {
|
|
1180
2980
|
"claude-code": "claude-code.json",
|
|
1181
2981
|
codex: "codex.json"
|
|
1182
2982
|
};
|
|
1183
|
-
function legacyConfigPath(harness, home =
|
|
1184
|
-
return
|
|
2983
|
+
function legacyConfigPath(harness, home = homedir9()) {
|
|
2984
|
+
return join15(home, ".hindsight", LEGACY_CONFIG_FILES[harness] ?? `${harness}.json`);
|
|
1185
2985
|
}
|
|
1186
2986
|
var CLOUD_URL = "https://api.hindsight.vectorize.io";
|
|
1187
|
-
function readLegacyEndpoint(home =
|
|
2987
|
+
function readLegacyEndpoint(home = homedir9(), prefer = []) {
|
|
1188
2988
|
const order = [...prefer, ...Object.keys(LEGACY_CONFIG_FILES)].filter(
|
|
1189
2989
|
(h, i, all) => h in LEGACY_CONFIG_FILES && all.indexOf(h) === i
|
|
1190
2990
|
);
|
|
@@ -1196,10 +2996,10 @@ function readLegacyEndpoint(home = homedir8(), prefer = []) {
|
|
|
1196
2996
|
}
|
|
1197
2997
|
function readOne(harness, home) {
|
|
1198
2998
|
const source = legacyConfigPath(harness, home);
|
|
1199
|
-
if (!
|
|
2999
|
+
if (!existsSync9(source)) return void 0;
|
|
1200
3000
|
let raw;
|
|
1201
3001
|
try {
|
|
1202
|
-
raw = JSON.parse(
|
|
3002
|
+
raw = JSON.parse(readFileSync11(source, "utf8"));
|
|
1203
3003
|
} catch {
|
|
1204
3004
|
return void 0;
|
|
1205
3005
|
}
|
|
@@ -1415,6 +3215,10 @@ function createInstallerUi(o) {
|
|
|
1415
3215
|
`${dim("\u2514")} ${green("\u2713")} Uninstalled ${agents} in ${secs}s \u2014 Hindsight entries removed, *.hindsight-backup files left in place.`
|
|
1416
3216
|
);
|
|
1417
3217
|
}
|
|
3218
|
+
} else if (o.command === "update") {
|
|
3219
|
+
write2(
|
|
3220
|
+
`${dim("\u2514")} ${green("\u2713")} Runtime up to date${o.version ? ` (v${o.version})` : ""}`
|
|
3221
|
+
);
|
|
1418
3222
|
} else {
|
|
1419
3223
|
write2(dim("\u2514"));
|
|
1420
3224
|
}
|
|
@@ -1427,7 +3231,7 @@ function createInstallerUi(o) {
|
|
|
1427
3231
|
var MARKER = "coding-agents";
|
|
1428
3232
|
function readJson(path) {
|
|
1429
3233
|
try {
|
|
1430
|
-
return JSON.parse(
|
|
3234
|
+
return JSON.parse(readFileSync12(path, "utf8"));
|
|
1431
3235
|
} catch {
|
|
1432
3236
|
return {};
|
|
1433
3237
|
}
|
|
@@ -1442,11 +3246,31 @@ function parseJsonc(text) {
|
|
|
1442
3246
|
}
|
|
1443
3247
|
}
|
|
1444
3248
|
function writeJson(path, value) {
|
|
1445
|
-
|
|
1446
|
-
|
|
3249
|
+
mkdirSync4(dirname10(path), { recursive: true });
|
|
3250
|
+
backupOnce(path);
|
|
3251
|
+
writeFileSync3(path, JSON.stringify(value, null, 2) + "\n");
|
|
3252
|
+
}
|
|
3253
|
+
function backupOnce(path) {
|
|
3254
|
+
if (existsSync10(path) && !existsSync10(`${path}.hindsight-backup`)) {
|
|
1447
3255
|
copyFileSync(path, `${path}.hindsight-backup`);
|
|
1448
3256
|
}
|
|
1449
|
-
|
|
3257
|
+
}
|
|
3258
|
+
function writeJsonc(path, key, value) {
|
|
3259
|
+
const text = existsSync10(path) ? readFileSync12(path, "utf8") : "";
|
|
3260
|
+
const edits = modify(text, [key], value, {
|
|
3261
|
+
formattingOptions: {
|
|
3262
|
+
tabSize: 2,
|
|
3263
|
+
insertSpaces: true,
|
|
3264
|
+
// Keep a CRLF file CRLF: rewriting every line ending would turn a one-line change into a
|
|
3265
|
+
// whole-file diff for anyone on Windows.
|
|
3266
|
+
eol: text.includes("\r\n") ? "\r\n" : "\n"
|
|
3267
|
+
}
|
|
3268
|
+
});
|
|
3269
|
+
const next = applyEdits(text, edits);
|
|
3270
|
+
mkdirSync4(dirname10(path), { recursive: true });
|
|
3271
|
+
backupOnce(path);
|
|
3272
|
+
writeFileSync3(path, next.endsWith("\n") ? next : `${next}
|
|
3273
|
+
`);
|
|
1450
3274
|
}
|
|
1451
3275
|
function mergeHookEvent(existing, entry) {
|
|
1452
3276
|
const kept = (existing ?? []).filter((e) => !JSON.stringify(e).includes(MARKER));
|
|
@@ -1460,11 +3284,11 @@ function setOrDelete(obj, key, arr) {
|
|
|
1460
3284
|
else delete obj[key];
|
|
1461
3285
|
}
|
|
1462
3286
|
var cmdHook = (dist, file, timeout) => ({
|
|
1463
|
-
hooks: [{ type: "command", command: `node "${
|
|
3287
|
+
hooks: [{ type: "command", command: `node "${join16(dist, file)}"`, timeout }]
|
|
1464
3288
|
});
|
|
1465
3289
|
var mcpServerEntry = (dist, harness) => ({
|
|
1466
3290
|
command: "node",
|
|
1467
|
-
args: [
|
|
3291
|
+
args: [join16(dist, "mcp-server.js")],
|
|
1468
3292
|
env: { HINDSIGHT_MCP_HARNESS: harness }
|
|
1469
3293
|
});
|
|
1470
3294
|
function mergeHarnessHooks(hooks, harness, dist) {
|
|
@@ -1474,7 +3298,7 @@ function mergeHarnessHooks(hooks, harness, dist) {
|
|
|
1474
3298
|
if (installedEvents.has(hook.event)) continue;
|
|
1475
3299
|
installedEvents.add(hook.event);
|
|
1476
3300
|
const entry = spec.configStyle === "nested" ? cmdHook(dist, hook.entry, hook.timeout) : {
|
|
1477
|
-
command: `node "${
|
|
3301
|
+
command: `node "${join16(dist, hook.entry)}"`,
|
|
1478
3302
|
...hook.timeout ? { timeout: hook.timeout } : {}
|
|
1479
3303
|
};
|
|
1480
3304
|
hooks[hook.event] = mergeHookEvent(hooks[hook.event], entry);
|
|
@@ -1488,16 +3312,25 @@ function stripHarnessHooks(hooks, harness) {
|
|
|
1488
3312
|
setOrDelete(hooks, hook.event, stripOurs(hooks[hook.event]));
|
|
1489
3313
|
}
|
|
1490
3314
|
}
|
|
1491
|
-
function
|
|
1492
|
-
const
|
|
1493
|
-
if (!
|
|
1494
|
-
|
|
1495
|
-
|
|
3315
|
+
function skillsBaseFor(c, harness) {
|
|
3316
|
+
const parts = SKILL_DIRS[harness];
|
|
3317
|
+
if (!parts) throw new Error(`${harness} installs a skill but names no directory in SKILL_DIRS`);
|
|
3318
|
+
return join16(c.home, ...parts);
|
|
3319
|
+
}
|
|
3320
|
+
function installSkill(c, harness) {
|
|
3321
|
+
const src = join16(c.pkgRoot, "skill");
|
|
3322
|
+
if (!existsSync10(join16(src, "SKILL.md"))) return;
|
|
3323
|
+
const skillsBase = skillsBaseFor(c, harness);
|
|
3324
|
+
const dst = join16(skillsBase, "hindsight-coding-agent");
|
|
3325
|
+
mkdirSync4(skillsBase, { recursive: true });
|
|
1496
3326
|
cpSync2(src, dst, { recursive: true });
|
|
1497
3327
|
c.log?.(`${harness}: skill installed at ${dst}`);
|
|
1498
3328
|
}
|
|
1499
|
-
function uninstallSkill(c,
|
|
1500
|
-
rmSync2(
|
|
3329
|
+
function uninstallSkill(c, harness) {
|
|
3330
|
+
rmSync2(join16(skillsBaseFor(c, harness), "hindsight-coding-agent"), {
|
|
3331
|
+
recursive: true,
|
|
3332
|
+
force: true
|
|
3333
|
+
});
|
|
1501
3334
|
}
|
|
1502
3335
|
function onPath2(bin) {
|
|
1503
3336
|
try {
|
|
@@ -1515,104 +3348,135 @@ function runClinePlugin(args) {
|
|
|
1515
3348
|
return false;
|
|
1516
3349
|
}
|
|
1517
3350
|
}
|
|
1518
|
-
var
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
3351
|
+
var OPENCODE_CONFIG_CANDIDATES = ["opencode.jsonc", "opencode.json"];
|
|
3352
|
+
function opencodeConfigPath(c) {
|
|
3353
|
+
const dir = join16(c.home, ".config", "opencode");
|
|
3354
|
+
const existing = OPENCODE_CONFIG_CANDIDATES.map((f) => join16(dir, f)).find((p) => existsSync10(p));
|
|
3355
|
+
return existing ?? join16(dir, "opencode.json");
|
|
3356
|
+
}
|
|
3357
|
+
function runDcodePlugin(args) {
|
|
3358
|
+
try {
|
|
3359
|
+
execFileSync6("dcode", args, { stdio: "pipe" });
|
|
3360
|
+
return true;
|
|
3361
|
+
} catch {
|
|
3362
|
+
return false;
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
function registerOpencodePlugin(c, name) {
|
|
3366
|
+
const path = opencodeConfigPath(c);
|
|
3367
|
+
let cfg = {};
|
|
3368
|
+
if (existsSync10(path)) {
|
|
3369
|
+
const parsed = parseJsonc(readFileSync12(path, "utf8"));
|
|
3370
|
+
if (!parsed) {
|
|
3371
|
+
c.log?.(`${name}: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
|
|
3372
|
+
return;
|
|
1537
3373
|
}
|
|
1538
|
-
|
|
3374
|
+
cfg = parsed;
|
|
1539
3375
|
}
|
|
3376
|
+
const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
|
|
3377
|
+
writeJsonc(path, "plugin", [...plugins.filter((p) => !String(p).includes(MARKER)), c.pkgRoot]);
|
|
3378
|
+
c.log?.(`${name}: plugin registered in ${path}`);
|
|
3379
|
+
}
|
|
3380
|
+
function unregisterOpencodePlugin(c, name) {
|
|
3381
|
+
const path = opencodeConfigPath(c);
|
|
3382
|
+
if (!existsSync10(path)) return;
|
|
3383
|
+
const cfg = parseJsonc(readFileSync12(path, "utf8"));
|
|
3384
|
+
if (!cfg || !Array.isArray(cfg.plugin)) return;
|
|
3385
|
+
const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
|
|
3386
|
+
writeJsonc(path, "plugin", kept.length ? kept : void 0);
|
|
3387
|
+
c.log?.(`${name}: plugin entry removed`);
|
|
3388
|
+
}
|
|
3389
|
+
var opencode = {
|
|
3390
|
+
name: "opencode",
|
|
3391
|
+
detect: (c) => onPath2("opencode") || existsSync10(join16(c.home, ".config", "opencode")),
|
|
3392
|
+
install: (c) => registerOpencodePlugin(c, "opencode"),
|
|
3393
|
+
uninstall: (c) => unregisterOpencodePlugin(c, "opencode")
|
|
1540
3394
|
};
|
|
1541
|
-
var
|
|
1542
|
-
name: "
|
|
1543
|
-
detect: (
|
|
1544
|
-
install(c)
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
3395
|
+
var opencode2 = {
|
|
3396
|
+
name: "opencode2",
|
|
3397
|
+
detect: () => onPath2("opencode2"),
|
|
3398
|
+
install: (c) => registerOpencodePlugin(c, "opencode2"),
|
|
3399
|
+
uninstall: (c) => unregisterOpencodePlugin(c, "opencode2")
|
|
3400
|
+
};
|
|
3401
|
+
function piFamilyInstaller(harness, configDir) {
|
|
3402
|
+
const settings = (c) => join16(c.home, ...configDir, "settings.json");
|
|
3403
|
+
return {
|
|
3404
|
+
name: harness,
|
|
3405
|
+
// Both hosts name their executable exactly as we name the harness, so the harness id doubles
|
|
3406
|
+
// as the PATH probe here — unlike, say, antigravity-cli, whose binary is `agy`.
|
|
3407
|
+
detect: (c) => onPath2(harness) || existsSync10(join16(c.home, ...configDir)),
|
|
3408
|
+
install(c) {
|
|
3409
|
+
const path = settings(c);
|
|
3410
|
+
const cfg = readJson(path);
|
|
3411
|
+
const entry = join16(c.pkgRoot, "dist", `${harness}.js`);
|
|
3412
|
+
const exts = Array.isArray(cfg.extensions) ? cfg.extensions : [];
|
|
3413
|
+
cfg.extensions = [...exts.filter((p) => !String(p).includes(MARKER)), entry];
|
|
3414
|
+
writeJson(path, cfg);
|
|
3415
|
+
installSkill(c, harness);
|
|
3416
|
+
c.log?.(`${harness}: extension registered in ${path}`);
|
|
3417
|
+
},
|
|
3418
|
+
uninstall(c) {
|
|
3419
|
+
uninstallSkill(c, harness);
|
|
3420
|
+
const path = settings(c);
|
|
3421
|
+
if (!existsSync10(path)) return;
|
|
1557
3422
|
const cfg = readJson(path);
|
|
1558
3423
|
if (Array.isArray(cfg.extensions)) {
|
|
1559
3424
|
cfg.extensions = cfg.extensions.filter((p) => !String(p).includes(MARKER));
|
|
1560
3425
|
if (!cfg.extensions.length) delete cfg.extensions;
|
|
1561
3426
|
writeJson(path, cfg);
|
|
1562
3427
|
}
|
|
3428
|
+
c.log?.(`${harness}: extension entry + skill removed`);
|
|
1563
3429
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
3430
|
+
};
|
|
3431
|
+
}
|
|
3432
|
+
var pi = piFamilyInstaller("pi", [".pi", "agent"]);
|
|
3433
|
+
var primeAgent = piFamilyInstaller("prime-agent", [".prime", "agent"]);
|
|
1568
3434
|
var KILO_CONFIG_CANDIDATES = ["kilo.jsonc", "kilo.json", "opencode.json"];
|
|
1569
3435
|
function kiloConfigPath(c) {
|
|
1570
|
-
const dir =
|
|
1571
|
-
const existing = KILO_CONFIG_CANDIDATES.map((f) =>
|
|
1572
|
-
return existing ??
|
|
3436
|
+
const dir = join16(c.home, ".config", "kilo");
|
|
3437
|
+
const existing = KILO_CONFIG_CANDIDATES.map((f) => join16(dir, f)).find((p) => existsSync10(p));
|
|
3438
|
+
return existing ?? join16(dir, "kilo.json");
|
|
1573
3439
|
}
|
|
1574
3440
|
var kilo = {
|
|
1575
3441
|
name: "kilo",
|
|
1576
|
-
detect: (c) => onPath2("kilo") ||
|
|
3442
|
+
detect: (c) => onPath2("kilo") || existsSync10(join16(c.home, ".config", "kilo")),
|
|
1577
3443
|
install(c) {
|
|
1578
3444
|
const path = kiloConfigPath(c);
|
|
1579
3445
|
let cfg = {};
|
|
1580
|
-
if (
|
|
1581
|
-
const parsed = parseJsonc(
|
|
3446
|
+
if (existsSync10(path)) {
|
|
3447
|
+
const parsed = parseJsonc(readFileSync12(path, "utf8"));
|
|
1582
3448
|
if (!parsed) {
|
|
1583
3449
|
c.log?.(`kilo: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
|
|
1584
3450
|
return;
|
|
1585
3451
|
}
|
|
1586
3452
|
cfg = parsed;
|
|
1587
3453
|
}
|
|
1588
|
-
const entry = pathToFileURL(
|
|
3454
|
+
const entry = pathToFileURL(join16(c.dist, "kilo.js")).href;
|
|
1589
3455
|
const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
|
|
1590
|
-
|
|
1591
|
-
writeJson(path, cfg);
|
|
3456
|
+
writeJsonc(path, "plugin", [...plugins.filter((p) => !String(p).includes(MARKER)), entry]);
|
|
1592
3457
|
c.log?.(`kilo: plugin registered in ${path}`);
|
|
1593
3458
|
},
|
|
1594
3459
|
uninstall(c) {
|
|
1595
3460
|
const path = kiloConfigPath(c);
|
|
1596
|
-
if (!
|
|
1597
|
-
const cfg = parseJsonc(
|
|
3461
|
+
if (!existsSync10(path)) return;
|
|
3462
|
+
const cfg = parseJsonc(readFileSync12(path, "utf8"));
|
|
1598
3463
|
if (!cfg || !Array.isArray(cfg.plugin)) return;
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
writeJson(path, cfg);
|
|
3464
|
+
const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
|
|
3465
|
+
writeJsonc(path, "plugin", kept.length ? kept : void 0);
|
|
1602
3466
|
c.log?.("kilo: plugin entry removed");
|
|
1603
3467
|
}
|
|
1604
3468
|
};
|
|
1605
3469
|
var claudeCode = {
|
|
1606
3470
|
name: "claude-code",
|
|
1607
|
-
detect: (c) => onPath2("claude") ||
|
|
3471
|
+
detect: (c) => onPath2("claude") || existsSync10(join16(c.home, ".claude")),
|
|
1608
3472
|
install(c) {
|
|
1609
|
-
const path =
|
|
3473
|
+
const path = join16(c.home, ".claude", "settings.json");
|
|
1610
3474
|
const settings = readJson(path);
|
|
1611
3475
|
settings.hooks = settings.hooks ?? {};
|
|
1612
3476
|
mergeHarnessHooks(settings.hooks, "claude-code", c.dist);
|
|
1613
3477
|
writeJson(path, settings);
|
|
1614
3478
|
c.log?.(`claude-code: hooks merged into ${path}`);
|
|
1615
|
-
installSkill(c, "claude-code"
|
|
3479
|
+
installSkill(c, "claude-code");
|
|
1616
3480
|
const mcp = c.claudeMcp ?? defaultClaudeMcp;
|
|
1617
3481
|
mcp(["mcp", "remove", "--scope", "user", "hindsight"]);
|
|
1618
3482
|
if (mcp([
|
|
@@ -1625,19 +3489,19 @@ var claudeCode = {
|
|
|
1625
3489
|
"HINDSIGHT_MCP_HARNESS=claude-code",
|
|
1626
3490
|
"--",
|
|
1627
3491
|
"node",
|
|
1628
|
-
|
|
3492
|
+
join16(c.dist, "mcp-server.js")
|
|
1629
3493
|
])) {
|
|
1630
3494
|
c.log?.("claude-code: MCP server registered (claude mcp add, user scope)");
|
|
1631
3495
|
} else {
|
|
1632
3496
|
c.log?.(
|
|
1633
3497
|
`claude-code: could not run \`claude mcp add\` \u2014 register the tools manually:
|
|
1634
|
-
claude mcp add --scope user hindsight --env HINDSIGHT_MCP_HARNESS=claude-code -- node "${
|
|
3498
|
+
claude mcp add --scope user hindsight --env HINDSIGHT_MCP_HARNESS=claude-code -- node "${join16(c.dist, "mcp-server.js")}"`
|
|
1635
3499
|
);
|
|
1636
3500
|
}
|
|
1637
3501
|
},
|
|
1638
3502
|
uninstall(c) {
|
|
1639
|
-
const path =
|
|
1640
|
-
if (
|
|
3503
|
+
const path = join16(c.home, ".claude", "settings.json");
|
|
3504
|
+
if (existsSync10(path)) {
|
|
1641
3505
|
const settings = readJson(path);
|
|
1642
3506
|
if (settings.hooks) {
|
|
1643
3507
|
stripHarnessHooks(settings.hooks, "claude-code");
|
|
@@ -1647,7 +3511,7 @@ var claudeCode = {
|
|
|
1647
3511
|
}
|
|
1648
3512
|
const mcp = c.claudeMcp ?? defaultClaudeMcp;
|
|
1649
3513
|
mcp(["mcp", "remove", "--scope", "user", "hindsight"]);
|
|
1650
|
-
uninstallSkill(c,
|
|
3514
|
+
uninstallSkill(c, "claude-code");
|
|
1651
3515
|
c.log?.("claude-code: hooks + MCP registration + skill removed");
|
|
1652
3516
|
}
|
|
1653
3517
|
};
|
|
@@ -1662,20 +3526,20 @@ function defaultClaudeMcp(args) {
|
|
|
1662
3526
|
var CODEX_MCP_BLOCK_RE = /^\[mcp_servers\.hindsight(?:\.[^\]]+)?\][^\n]*\n(?:(?!\[)[^\n]*\n?)*/gm;
|
|
1663
3527
|
var codexMcpBlock = (dist) => `[mcp_servers.hindsight]
|
|
1664
3528
|
command = "node"
|
|
1665
|
-
args = [${JSON.stringify(
|
|
3529
|
+
args = [${JSON.stringify(join16(dist, "mcp-server.js"))}]
|
|
1666
3530
|
env = { HINDSIGHT_MCP_HARNESS = "codex" }`;
|
|
1667
3531
|
var codex = {
|
|
1668
3532
|
name: "codex",
|
|
1669
|
-
detect: (c) => onPath2("codex") ||
|
|
3533
|
+
detect: (c) => onPath2("codex") || existsSync10(join16(c.home, ".codex")),
|
|
1670
3534
|
install(c) {
|
|
1671
|
-
const hooksPath =
|
|
3535
|
+
const hooksPath = join16(c.home, ".codex", "hooks.json");
|
|
1672
3536
|
const cfg = readJson(hooksPath);
|
|
1673
3537
|
cfg.hooks = cfg.hooks ?? {};
|
|
1674
3538
|
mergeHarnessHooks(cfg.hooks, "codex", c.dist);
|
|
1675
3539
|
writeJson(hooksPath, cfg);
|
|
1676
3540
|
c.log?.(`codex: hooks merged into ${hooksPath}`);
|
|
1677
|
-
const tomlPath =
|
|
1678
|
-
const existing =
|
|
3541
|
+
const tomlPath = join16(c.home, ".codex", "config.toml");
|
|
3542
|
+
const existing = existsSync10(tomlPath) ? readFileSync12(tomlPath, "utf8") : "";
|
|
1679
3543
|
const toml = existing.replace(CODEX_MCP_BLOCK_RE, "");
|
|
1680
3544
|
const additions = [];
|
|
1681
3545
|
if (!/^\s*(codex_hooks|hooks)\s*=/m.test(toml)) {
|
|
@@ -1691,30 +3555,30 @@ var codex = {
|
|
|
1691
3555
|
const next = `${toml.replace(/\n*$/, "\n\n")}${additions.join("\n\n")}
|
|
1692
3556
|
`;
|
|
1693
3557
|
if (next !== existing) {
|
|
1694
|
-
if (
|
|
3558
|
+
if (existsSync10(tomlPath) && !existsSync10(`${tomlPath}.hindsight-backup`)) {
|
|
1695
3559
|
copyFileSync(tomlPath, `${tomlPath}.hindsight-backup`);
|
|
1696
3560
|
}
|
|
1697
|
-
|
|
1698
|
-
|
|
3561
|
+
mkdirSync4(dirname10(tomlPath), { recursive: true });
|
|
3562
|
+
writeFileSync3(tomlPath, next);
|
|
1699
3563
|
c.log?.(`codex: wrote ${additions.length} section(s) to ${tomlPath}`);
|
|
1700
3564
|
}
|
|
1701
|
-
installSkill(c, "codex"
|
|
3565
|
+
installSkill(c, "codex");
|
|
1702
3566
|
},
|
|
1703
3567
|
uninstall(c) {
|
|
1704
|
-
const hooksPath =
|
|
1705
|
-
if (
|
|
3568
|
+
const hooksPath = join16(c.home, ".codex", "hooks.json");
|
|
3569
|
+
if (existsSync10(hooksPath)) {
|
|
1706
3570
|
const cfg = readJson(hooksPath);
|
|
1707
3571
|
if (cfg.hooks) {
|
|
1708
3572
|
stripHarnessHooks(cfg.hooks, "codex");
|
|
1709
3573
|
writeJson(hooksPath, cfg);
|
|
1710
3574
|
}
|
|
1711
3575
|
}
|
|
1712
|
-
uninstallSkill(c,
|
|
1713
|
-
const tomlPath =
|
|
1714
|
-
if (
|
|
1715
|
-
const toml =
|
|
3576
|
+
uninstallSkill(c, "codex");
|
|
3577
|
+
const tomlPath = join16(c.home, ".codex", "config.toml");
|
|
3578
|
+
if (existsSync10(tomlPath)) {
|
|
3579
|
+
const toml = readFileSync12(tomlPath, "utf8");
|
|
1716
3580
|
const cleaned = toml.replace(CODEX_MCP_BLOCK_RE, "");
|
|
1717
|
-
if (cleaned !== toml)
|
|
3581
|
+
if (cleaned !== toml) writeFileSync3(tomlPath, cleaned);
|
|
1718
3582
|
}
|
|
1719
3583
|
c.log?.(
|
|
1720
3584
|
"codex: hooks + MCP section + skill removed ([features] hooks flag left as-is \u2014 other hooks may use it)"
|
|
@@ -1728,7 +3592,7 @@ var antigravity = {
|
|
|
1728
3592
|
// can consume this integration.
|
|
1729
3593
|
detect: (c) => onPath2("agy"),
|
|
1730
3594
|
install(c) {
|
|
1731
|
-
const hooksPath =
|
|
3595
|
+
const hooksPath = join16(c.home, ".gemini", "config", "hooks.json");
|
|
1732
3596
|
const hooks = readJson(hooksPath);
|
|
1733
3597
|
for (const key of Object.keys(hooks)) {
|
|
1734
3598
|
if (key !== MARKER && key.includes(MARKER)) delete hooks[key];
|
|
@@ -1739,26 +3603,26 @@ var antigravity = {
|
|
|
1739
3603
|
setOrDelete(hooks, event, stripOurs(hooks[event]));
|
|
1740
3604
|
}
|
|
1741
3605
|
writeJson(hooksPath, hooks);
|
|
1742
|
-
const mcpPath =
|
|
3606
|
+
const mcpPath = join16(c.home, ".gemini", "config", "mcp_config.json");
|
|
1743
3607
|
const mcp = readJson(mcpPath);
|
|
1744
3608
|
mcp.mcpServers = {
|
|
1745
3609
|
...mcp.mcpServers ?? {},
|
|
1746
3610
|
hindsight: mcpServerEntry(c.dist, "antigravity-cli")
|
|
1747
3611
|
};
|
|
1748
3612
|
writeJson(mcpPath, mcp);
|
|
1749
|
-
const settingsPath =
|
|
3613
|
+
const settingsPath = join16(c.home, ".gemini", "antigravity-cli", "settings.json");
|
|
1750
3614
|
const settings = readJson(settingsPath);
|
|
1751
3615
|
if (!settings.statusLine) {
|
|
1752
3616
|
settings.statusLine = {
|
|
1753
3617
|
type: "command",
|
|
1754
|
-
command: `node "${
|
|
3618
|
+
command: `node "${join16(c.dist, "antigravity-statusline.js")}"`
|
|
1755
3619
|
};
|
|
1756
3620
|
writeJson(settingsPath, settings);
|
|
1757
3621
|
c.log?.(`antigravity-cli: Hindsight status line enabled in ${settingsPath}`);
|
|
1758
3622
|
} else if (JSON.stringify(settings.statusLine).includes(MARKER)) {
|
|
1759
3623
|
settings.statusLine = {
|
|
1760
3624
|
type: "command",
|
|
1761
|
-
command: `node "${
|
|
3625
|
+
command: `node "${join16(c.dist, "antigravity-statusline.js")}"`
|
|
1762
3626
|
};
|
|
1763
3627
|
writeJson(settingsPath, settings);
|
|
1764
3628
|
} else {
|
|
@@ -1767,11 +3631,11 @@ var antigravity = {
|
|
|
1767
3631
|
);
|
|
1768
3632
|
}
|
|
1769
3633
|
c.log?.(`antigravity-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
|
|
1770
|
-
installSkill(c, "antigravity-cli"
|
|
3634
|
+
installSkill(c, "antigravity-cli");
|
|
1771
3635
|
},
|
|
1772
3636
|
uninstall(c) {
|
|
1773
|
-
const hooksPath =
|
|
1774
|
-
if (
|
|
3637
|
+
const hooksPath = join16(c.home, ".gemini", "config", "hooks.json");
|
|
3638
|
+
if (existsSync10(hooksPath)) {
|
|
1775
3639
|
const hooks = readJson(hooksPath);
|
|
1776
3640
|
if (hooks[MARKER]) {
|
|
1777
3641
|
stripHarnessHooks(hooks[MARKER], "antigravity-cli");
|
|
@@ -1782,23 +3646,23 @@ var antigravity = {
|
|
|
1782
3646
|
}
|
|
1783
3647
|
writeJson(hooksPath, hooks);
|
|
1784
3648
|
}
|
|
1785
|
-
const mcpPath =
|
|
1786
|
-
if (
|
|
3649
|
+
const mcpPath = join16(c.home, ".gemini", "config", "mcp_config.json");
|
|
3650
|
+
if (existsSync10(mcpPath)) {
|
|
1787
3651
|
const mcp = readJson(mcpPath);
|
|
1788
3652
|
if (mcp.mcpServers?.hindsight) {
|
|
1789
3653
|
delete mcp.mcpServers.hindsight;
|
|
1790
3654
|
writeJson(mcpPath, mcp);
|
|
1791
3655
|
}
|
|
1792
3656
|
}
|
|
1793
|
-
const settingsPath =
|
|
1794
|
-
if (
|
|
3657
|
+
const settingsPath = join16(c.home, ".gemini", "antigravity-cli", "settings.json");
|
|
3658
|
+
if (existsSync10(settingsPath)) {
|
|
1795
3659
|
const settings = readJson(settingsPath);
|
|
1796
3660
|
if (JSON.stringify(settings.statusLine ?? {}).includes(MARKER)) {
|
|
1797
3661
|
delete settings.statusLine;
|
|
1798
3662
|
writeJson(settingsPath, settings);
|
|
1799
3663
|
}
|
|
1800
3664
|
}
|
|
1801
|
-
uninstallSkill(c,
|
|
3665
|
+
uninstallSkill(c, "antigravity-cli");
|
|
1802
3666
|
c.log?.("antigravity-cli: hooks + MCP entry + status line + skill removed");
|
|
1803
3667
|
}
|
|
1804
3668
|
};
|
|
@@ -1818,29 +3682,38 @@ function pathNodeVersion() {
|
|
|
1818
3682
|
}
|
|
1819
3683
|
}
|
|
1820
3684
|
function runtimeDir(home) {
|
|
1821
|
-
return
|
|
3685
|
+
return join16(home, ".hindsight", "coding-agents");
|
|
1822
3686
|
}
|
|
3687
|
+
var ORIGIN_FILE = ".install-origin.json";
|
|
1823
3688
|
function stageRuntime(c) {
|
|
1824
3689
|
const target = runtimeDir(c.home);
|
|
1825
3690
|
const same = (a, b) => {
|
|
1826
3691
|
try {
|
|
1827
|
-
return
|
|
3692
|
+
return realpathSync3(a) === realpathSync3(b);
|
|
1828
3693
|
} catch {
|
|
1829
3694
|
return a === b;
|
|
1830
3695
|
}
|
|
1831
3696
|
};
|
|
1832
3697
|
if (same(c.pkgRoot, target)) return c;
|
|
1833
|
-
if (!
|
|
3698
|
+
if (!existsSync10(join16(c.dist, "installer.js"))) return c;
|
|
1834
3699
|
try {
|
|
1835
|
-
rmSync2(
|
|
1836
|
-
|
|
1837
|
-
cpSync2(c.dist,
|
|
1838
|
-
const skill =
|
|
1839
|
-
if (
|
|
1840
|
-
const pkgJson =
|
|
1841
|
-
if (
|
|
3700
|
+
rmSync2(join16(target, "dist"), { recursive: true, force: true });
|
|
3701
|
+
mkdirSync4(target, { recursive: true });
|
|
3702
|
+
cpSync2(c.dist, join16(target, "dist"), { recursive: true });
|
|
3703
|
+
const skill = join16(c.pkgRoot, "skill");
|
|
3704
|
+
if (existsSync10(skill)) cpSync2(skill, join16(target, "skill"), { recursive: true });
|
|
3705
|
+
const pkgJson = join16(c.pkgRoot, "package.json");
|
|
3706
|
+
if (existsSync10(pkgJson)) copyFileSync(pkgJson, join16(target, "package.json"));
|
|
3707
|
+
for (const resource of ["plugin.json", "hooks", "index.js"]) {
|
|
3708
|
+
const source = join16(c.pkgRoot, resource);
|
|
3709
|
+
if (existsSync10(source)) cpSync2(source, join16(target, resource), { recursive: true });
|
|
3710
|
+
}
|
|
3711
|
+
writeFileSync3(
|
|
3712
|
+
join16(target, ORIGIN_FILE),
|
|
3713
|
+
JSON.stringify({ source: c.pkgRoot, stagedAt: (/* @__PURE__ */ new Date()).toISOString() })
|
|
3714
|
+
);
|
|
1842
3715
|
c.log?.(`runtime staged at ${target}`);
|
|
1843
|
-
return { ...c, pkgRoot: target, dist:
|
|
3716
|
+
return { ...c, pkgRoot: target, dist: join16(target, "dist") };
|
|
1844
3717
|
} catch (error) {
|
|
1845
3718
|
c.log?.(`could not stage the runtime at ${target}: ${String(error)}`);
|
|
1846
3719
|
return c;
|
|
@@ -1918,7 +3791,7 @@ function configureServer(c, args, installing) {
|
|
|
1918
3791
|
c.log?.(`unknown --server "${explicit}" \u2014 expected one of: ${SERVER_MODES.join(", ")}`);
|
|
1919
3792
|
return false;
|
|
1920
3793
|
}
|
|
1921
|
-
const configPath = process.env.HINDSIGHT_CONFIG ||
|
|
3794
|
+
const configPath = process.env.HINDSIGHT_CONFIG || join16(c.home, ...CONFIG_RELATIVE);
|
|
1922
3795
|
const existing = readJson(configPath);
|
|
1923
3796
|
const alreadyConfigured = !!(existing.serverMode || existing.apiUrl);
|
|
1924
3797
|
let mode = explicit;
|
|
@@ -2014,7 +3887,7 @@ function reportDaemonPrereqs(c) {
|
|
|
2014
3887
|
}
|
|
2015
3888
|
var devin = {
|
|
2016
3889
|
name: "devin-cli",
|
|
2017
|
-
detect: (c) => onPath2("devin") ||
|
|
3890
|
+
detect: (c) => onPath2("devin") || existsSync10(join16(c.home, ".config", "devin")),
|
|
2018
3891
|
// Devin is the ONLY harness whose hooks never hand over a transcript: they carry a session id and
|
|
2019
3892
|
// nothing else, so retain can only work by reading the CLI's own sessions.db. That makes SQLite
|
|
2020
3893
|
// support a hard prerequisite here — and one worth checking now, because the alternative is an
|
|
@@ -2027,12 +3900,12 @@ var devin = {
|
|
|
2027
3900
|
Upgrade to Node 22.5 or newer (24 LTS recommended) and re-run this command.`;
|
|
2028
3901
|
},
|
|
2029
3902
|
install(c) {
|
|
2030
|
-
const configPath =
|
|
3903
|
+
const configPath = join16(c.home, ".config", "devin", "config.json");
|
|
2031
3904
|
const config = readJson(configPath);
|
|
2032
3905
|
config.hooks = config.hooks ?? {};
|
|
2033
3906
|
mergeHarnessHooks(config.hooks, "devin-cli", c.dist);
|
|
2034
3907
|
writeJson(configPath, config);
|
|
2035
|
-
const mcpPath =
|
|
3908
|
+
const mcpPath = join16(c.home, ".config", "devin", "mcp_config.json");
|
|
2036
3909
|
const mcp = readJson(mcpPath);
|
|
2037
3910
|
mcp.mcpServers = {
|
|
2038
3911
|
...mcp.mcpServers ?? {},
|
|
@@ -2042,8 +3915,8 @@ var devin = {
|
|
|
2042
3915
|
c.log?.(`devin-cli: hooks merged into ${configPath}, MCP into ${mcpPath}`);
|
|
2043
3916
|
},
|
|
2044
3917
|
uninstall(c) {
|
|
2045
|
-
const configPath =
|
|
2046
|
-
if (
|
|
3918
|
+
const configPath = join16(c.home, ".config", "devin", "config.json");
|
|
3919
|
+
if (existsSync10(configPath)) {
|
|
2047
3920
|
const config = readJson(configPath);
|
|
2048
3921
|
if (config.hooks) {
|
|
2049
3922
|
stripHarnessHooks(config.hooks, "devin-cli");
|
|
@@ -2051,8 +3924,8 @@ var devin = {
|
|
|
2051
3924
|
writeJson(configPath, config);
|
|
2052
3925
|
}
|
|
2053
3926
|
}
|
|
2054
|
-
const mcpPath =
|
|
2055
|
-
if (
|
|
3927
|
+
const mcpPath = join16(c.home, ".config", "devin", "mcp_config.json");
|
|
3928
|
+
if (existsSync10(mcpPath)) {
|
|
2056
3929
|
const mcp = readJson(mcpPath);
|
|
2057
3930
|
if (mcp.mcpServers?.hindsight) {
|
|
2058
3931
|
delete mcp.mcpServers.hindsight;
|
|
@@ -2064,14 +3937,14 @@ var devin = {
|
|
|
2064
3937
|
};
|
|
2065
3938
|
var cursor = {
|
|
2066
3939
|
name: "cursor-cli",
|
|
2067
|
-
detect: (c) => onPath2("cursor-agent") ||
|
|
3940
|
+
detect: (c) => onPath2("cursor-agent") || existsSync10(join16(c.home, ".cursor")),
|
|
2068
3941
|
install(c) {
|
|
2069
|
-
const hooksPath =
|
|
3942
|
+
const hooksPath = join16(c.home, ".cursor", "hooks.json");
|
|
2070
3943
|
const cfg = readJson(hooksPath);
|
|
2071
3944
|
cfg.hooks = cfg.hooks ?? {};
|
|
2072
3945
|
mergeHarnessHooks(cfg.hooks, "cursor-cli", c.dist);
|
|
2073
3946
|
writeJson(hooksPath, cfg);
|
|
2074
|
-
const mcpPath =
|
|
3947
|
+
const mcpPath = join16(c.home, ".cursor", "mcp.json");
|
|
2075
3948
|
const mcp = readJson(mcpPath);
|
|
2076
3949
|
mcp.mcpServers = {
|
|
2077
3950
|
...mcp.mcpServers ?? {},
|
|
@@ -2079,11 +3952,11 @@ var cursor = {
|
|
|
2079
3952
|
};
|
|
2080
3953
|
writeJson(mcpPath, mcp);
|
|
2081
3954
|
c.log?.(`cursor-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
|
|
2082
|
-
installSkill(c, "cursor-cli"
|
|
3955
|
+
installSkill(c, "cursor-cli");
|
|
2083
3956
|
},
|
|
2084
3957
|
uninstall(c) {
|
|
2085
|
-
const hooksPath =
|
|
2086
|
-
if (
|
|
3958
|
+
const hooksPath = join16(c.home, ".cursor", "hooks.json");
|
|
3959
|
+
if (existsSync10(hooksPath)) {
|
|
2087
3960
|
const cfg = readJson(hooksPath);
|
|
2088
3961
|
if (cfg.hooks) {
|
|
2089
3962
|
stripHarnessHooks(cfg.hooks, "cursor-cli");
|
|
@@ -2091,49 +3964,49 @@ var cursor = {
|
|
|
2091
3964
|
writeJson(hooksPath, cfg);
|
|
2092
3965
|
}
|
|
2093
3966
|
}
|
|
2094
|
-
const mcpPath =
|
|
2095
|
-
if (
|
|
3967
|
+
const mcpPath = join16(c.home, ".cursor", "mcp.json");
|
|
3968
|
+
if (existsSync10(mcpPath)) {
|
|
2096
3969
|
const mcp = readJson(mcpPath);
|
|
2097
3970
|
if (mcp.mcpServers?.hindsight) {
|
|
2098
3971
|
delete mcp.mcpServers.hindsight;
|
|
2099
3972
|
writeJson(mcpPath, mcp);
|
|
2100
3973
|
}
|
|
2101
3974
|
}
|
|
2102
|
-
uninstallSkill(c,
|
|
3975
|
+
uninstallSkill(c, "cursor-cli");
|
|
2103
3976
|
c.log?.("cursor-cli: hooks + MCP entry + skill removed");
|
|
2104
3977
|
}
|
|
2105
3978
|
};
|
|
2106
3979
|
var copilot = {
|
|
2107
3980
|
name: "copilot-cli",
|
|
2108
|
-
detect: (c) => onPath2("copilot") ||
|
|
3981
|
+
detect: (c) => onPath2("copilot") || existsSync10(join16(c.home, ".copilot")),
|
|
2109
3982
|
install(c) {
|
|
2110
|
-
const hooksPath =
|
|
3983
|
+
const hooksPath = join16(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
|
|
2111
3984
|
const hooks = {};
|
|
2112
3985
|
mergeHarnessHooks(hooks, "copilot-cli", c.dist);
|
|
2113
3986
|
writeJson(hooksPath, { version: 1, hooks });
|
|
2114
|
-
const mcpPath =
|
|
3987
|
+
const mcpPath = join16(c.home, ".copilot", "mcp-config.json");
|
|
2115
3988
|
const mcp = readJson(mcpPath);
|
|
2116
3989
|
mcp.mcpServers = {
|
|
2117
3990
|
...mcp.mcpServers ?? {},
|
|
2118
3991
|
hindsight: mcpServerEntry(c.dist, "copilot-cli")
|
|
2119
3992
|
};
|
|
2120
3993
|
writeJson(mcpPath, mcp);
|
|
2121
|
-
installSkill(c, "copilot-cli"
|
|
3994
|
+
installSkill(c, "copilot-cli");
|
|
2122
3995
|
c.log?.(`copilot-cli: hooks installed at ${hooksPath}, MCP into ${mcpPath}`);
|
|
2123
3996
|
},
|
|
2124
3997
|
uninstall(c) {
|
|
2125
|
-
rmSync2(
|
|
3998
|
+
rmSync2(join16(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
|
|
2126
3999
|
force: true
|
|
2127
4000
|
});
|
|
2128
|
-
const mcpPath =
|
|
2129
|
-
if (
|
|
4001
|
+
const mcpPath = join16(c.home, ".copilot", "mcp-config.json");
|
|
4002
|
+
if (existsSync10(mcpPath)) {
|
|
2130
4003
|
const mcp = readJson(mcpPath);
|
|
2131
4004
|
if (mcp.mcpServers?.hindsight) {
|
|
2132
4005
|
delete mcp.mcpServers.hindsight;
|
|
2133
4006
|
writeJson(mcpPath, mcp);
|
|
2134
4007
|
}
|
|
2135
4008
|
}
|
|
2136
|
-
uninstallSkill(c,
|
|
4009
|
+
uninstallSkill(c, "copilot-cli");
|
|
2137
4010
|
c.log?.("copilot-cli: hooks + MCP entry + skill removed");
|
|
2138
4011
|
}
|
|
2139
4012
|
};
|
|
@@ -2142,12 +4015,12 @@ var GROK_MARKER_END = "# HINDSIGHT_CODING_AGENTS_GROK_END";
|
|
|
2142
4015
|
var GROK_BLOCK_RE = new RegExp(`\\n?${GROK_MARKER_START}[\\s\\S]*?${GROK_MARKER_END}\\n?`);
|
|
2143
4016
|
var grok = {
|
|
2144
4017
|
name: "grok-build",
|
|
2145
|
-
detect: (c) => onPath2("grok") ||
|
|
4018
|
+
detect: (c) => onPath2("grok") || existsSync10(join16(c.home, ".grok")),
|
|
2146
4019
|
install(c) {
|
|
2147
|
-
const path =
|
|
2148
|
-
const existing =
|
|
4020
|
+
const path = join16(c.home, ".grok", "config.toml");
|
|
4021
|
+
const existing = existsSync10(path) ? readFileSync12(path, "utf8") : "";
|
|
2149
4022
|
const withoutOurs = existing.replace(GROK_BLOCK_RE, "\n");
|
|
2150
|
-
const command = (entry) => JSON.stringify(`node "${
|
|
4023
|
+
const command = (entry) => JSON.stringify(`node "${join16(c.dist, entry)}"`);
|
|
2151
4024
|
const tomlString = (value) => JSON.stringify(value);
|
|
2152
4025
|
const block = `
|
|
2153
4026
|
${GROK_MARKER_START}
|
|
@@ -2171,25 +4044,25 @@ ${GROK_MARKER_START}
|
|
|
2171
4044
|
|
|
2172
4045
|
[mcp_servers.hindsight]
|
|
2173
4046
|
command = "node"
|
|
2174
|
-
args = [${tomlString(
|
|
4047
|
+
args = [${tomlString(join16(c.dist, "mcp-server.js"))}]
|
|
2175
4048
|
env = { HINDSIGHT_MCP_HARNESS = "grok-build" }
|
|
2176
4049
|
${GROK_MARKER_END}
|
|
2177
4050
|
`;
|
|
2178
|
-
if (
|
|
4051
|
+
if (existsSync10(path) && !existsSync10(`${path}.hindsight-backup`))
|
|
2179
4052
|
copyFileSync(path, `${path}.hindsight-backup`);
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
installSkill(c, "grok-build"
|
|
4053
|
+
mkdirSync4(dirname10(path), { recursive: true });
|
|
4054
|
+
writeFileSync3(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
|
|
4055
|
+
installSkill(c, "grok-build");
|
|
2183
4056
|
c.log?.(`grok-build: native hooks + MCP installed in ${path}`);
|
|
2184
4057
|
},
|
|
2185
4058
|
uninstall(c) {
|
|
2186
|
-
const path =
|
|
2187
|
-
if (
|
|
2188
|
-
const existing =
|
|
4059
|
+
const path = join16(c.home, ".grok", "config.toml");
|
|
4060
|
+
if (existsSync10(path)) {
|
|
4061
|
+
const existing = readFileSync12(path, "utf8");
|
|
2189
4062
|
const cleaned = existing.replace(GROK_BLOCK_RE, "\n");
|
|
2190
|
-
if (cleaned !== existing)
|
|
4063
|
+
if (cleaned !== existing) writeFileSync3(path, cleaned);
|
|
2191
4064
|
}
|
|
2192
|
-
uninstallSkill(c,
|
|
4065
|
+
uninstallSkill(c, "grok-build");
|
|
2193
4066
|
c.log?.("grok-build: native hooks + MCP + skill removed");
|
|
2194
4067
|
}
|
|
2195
4068
|
};
|
|
@@ -2197,17 +4070,17 @@ var CLINE_HOOK_MARKER = "HINDSIGHT_CODING_AGENTS_CLINE";
|
|
|
2197
4070
|
var CLINE_OLD_HOOK_EVENTS = ["TaskStart", "UserPromptSubmit", "TaskComplete"];
|
|
2198
4071
|
var CLINE_PLUGIN_NAME = "@vectorize-io/hindsight-coding-agents";
|
|
2199
4072
|
function removeLegacyClineHooks(c) {
|
|
2200
|
-
const hooksDir =
|
|
4073
|
+
const hooksDir = join16(c.home, "Documents", "Cline", "Hooks");
|
|
2201
4074
|
for (const event of CLINE_OLD_HOOK_EVENTS) {
|
|
2202
|
-
const path =
|
|
2203
|
-
if (
|
|
4075
|
+
const path = join16(hooksDir, event);
|
|
4076
|
+
if (existsSync10(path) && readFileSync12(path, "utf8").includes(CLINE_HOOK_MARKER)) {
|
|
2204
4077
|
rmSync2(path, { force: true });
|
|
2205
4078
|
}
|
|
2206
4079
|
}
|
|
2207
4080
|
}
|
|
2208
4081
|
var cline = {
|
|
2209
4082
|
name: "cline-cli",
|
|
2210
|
-
detect: (c) => onPath2("cline") ||
|
|
4083
|
+
detect: (c) => onPath2("cline") || existsSync10(join16(c.home, ".cline")),
|
|
2211
4084
|
install(c) {
|
|
2212
4085
|
removeLegacyClineHooks(c);
|
|
2213
4086
|
const installed = (c.clinePlugin ?? runClinePlugin)([
|
|
@@ -2216,14 +4089,14 @@ var cline = {
|
|
|
2216
4089
|
"--force",
|
|
2217
4090
|
c.pkgRoot
|
|
2218
4091
|
]);
|
|
2219
|
-
const mcpPath =
|
|
4092
|
+
const mcpPath = join16(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
|
|
2220
4093
|
const mcp = readJson(mcpPath);
|
|
2221
4094
|
mcp.mcpServers = {
|
|
2222
4095
|
...mcp.mcpServers ?? {},
|
|
2223
4096
|
hindsight: mcpServerEntry(c.dist, "cline-cli")
|
|
2224
4097
|
};
|
|
2225
4098
|
writeJson(mcpPath, mcp);
|
|
2226
|
-
installSkill(c, "cline-cli"
|
|
4099
|
+
installSkill(c, "cline-cli");
|
|
2227
4100
|
c.log?.(
|
|
2228
4101
|
installed ? "cline-cli: native plugin + MCP + skill installed" : `cline-cli: MCP + skill installed; run: cline plugin install --force "${c.pkgRoot}"`
|
|
2229
4102
|
);
|
|
@@ -2231,62 +4104,207 @@ var cline = {
|
|
|
2231
4104
|
uninstall(c) {
|
|
2232
4105
|
removeLegacyClineHooks(c);
|
|
2233
4106
|
(c.clinePlugin ?? runClinePlugin)(["plugin", "uninstall", CLINE_PLUGIN_NAME]);
|
|
2234
|
-
const mcpPath =
|
|
2235
|
-
if (
|
|
4107
|
+
const mcpPath = join16(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
|
|
4108
|
+
if (existsSync10(mcpPath)) {
|
|
2236
4109
|
const mcp = readJson(mcpPath);
|
|
2237
4110
|
if (mcp.mcpServers?.hindsight) {
|
|
2238
4111
|
delete mcp.mcpServers.hindsight;
|
|
2239
4112
|
writeJson(mcpPath, mcp);
|
|
2240
4113
|
}
|
|
2241
4114
|
}
|
|
2242
|
-
uninstallSkill(c,
|
|
4115
|
+
uninstallSkill(c, "cline-cli");
|
|
2243
4116
|
c.log?.("cline-cli: native plugin + MCP + skill removed");
|
|
2244
4117
|
}
|
|
2245
4118
|
};
|
|
4119
|
+
var DCODE_MARKETPLACE = "hindsight-coding-agents";
|
|
4120
|
+
var DCODE_PLUGIN_ID = "hindsight-coding-agents@hindsight-coding-agents";
|
|
4121
|
+
var DCODE_MARKETPLACE_RELATIVE_PATH = join16(".agents", "plugins", "marketplace.json");
|
|
4122
|
+
var DCODE_FALLBACK_MARKETPLACE = "hindsight-coding-agents-marketplace.json";
|
|
4123
|
+
function prepareDcodeMarketplace(c) {
|
|
4124
|
+
const root = join16(c.home, ".hindsight");
|
|
4125
|
+
const conventionalPath = join16(root, DCODE_MARKETPLACE_RELATIVE_PATH);
|
|
4126
|
+
let path = conventionalPath;
|
|
4127
|
+
let registrationSource = root;
|
|
4128
|
+
let marketplace = { plugins: [] };
|
|
4129
|
+
if (existsSync10(conventionalPath)) {
|
|
4130
|
+
try {
|
|
4131
|
+
const parsed = JSON.parse(readFileSync12(conventionalPath, "utf8"));
|
|
4132
|
+
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins)) {
|
|
4133
|
+
path = join16(root, DCODE_FALLBACK_MARKETPLACE);
|
|
4134
|
+
} else if (typeof parsed.name === "string" && parsed.name !== DCODE_MARKETPLACE) {
|
|
4135
|
+
path = join16(root, DCODE_FALLBACK_MARKETPLACE);
|
|
4136
|
+
} else {
|
|
4137
|
+
marketplace = parsed;
|
|
4138
|
+
}
|
|
4139
|
+
} catch {
|
|
4140
|
+
path = join16(root, DCODE_FALLBACK_MARKETPLACE);
|
|
4141
|
+
}
|
|
4142
|
+
}
|
|
4143
|
+
if (path !== conventionalPath && existsSync10(path)) {
|
|
4144
|
+
try {
|
|
4145
|
+
const parsed = JSON.parse(readFileSync12(path, "utf8"));
|
|
4146
|
+
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins) || parsed.name !== DCODE_MARKETPLACE) {
|
|
4147
|
+
c.log?.(`dcode: refusing to replace malformed marketplace file ${path}`);
|
|
4148
|
+
return false;
|
|
4149
|
+
}
|
|
4150
|
+
marketplace = parsed;
|
|
4151
|
+
} catch {
|
|
4152
|
+
c.log?.(`dcode: refusing to replace unreadable marketplace file ${path}`);
|
|
4153
|
+
return false;
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
if (path !== conventionalPath) registrationSource = path;
|
|
4157
|
+
const foreign = marketplace.plugins.filter(
|
|
4158
|
+
(entry) => !entry || typeof entry !== "object" || entry.name !== "hindsight-coding-agents"
|
|
4159
|
+
);
|
|
4160
|
+
marketplace.name = DCODE_MARKETPLACE;
|
|
4161
|
+
marketplace.plugins = [
|
|
4162
|
+
...foreign,
|
|
4163
|
+
{
|
|
4164
|
+
name: "hindsight-coding-agents",
|
|
4165
|
+
source: { source: "local", path: "./coding-agents" }
|
|
4166
|
+
}
|
|
4167
|
+
];
|
|
4168
|
+
writeJson(path, marketplace);
|
|
4169
|
+
return registrationSource;
|
|
4170
|
+
}
|
|
4171
|
+
var dcode = {
|
|
4172
|
+
name: "dcode",
|
|
4173
|
+
detect: (c) => onPath2("dcode") || existsSync10(join16(c.home, ".deepagents")),
|
|
4174
|
+
preflight: (c) => c.dcodePlugin || onPath2("dcode") ? void 0 : "the `dcode` CLI is not on PATH",
|
|
4175
|
+
install(c) {
|
|
4176
|
+
const plugin = c.dcodePlugin ?? runDcodePlugin;
|
|
4177
|
+
const marketplacePath = prepareDcodeMarketplace(c);
|
|
4178
|
+
const installed = marketplacePath !== false && plugin(["plugin", "marketplace", "add", marketplacePath]) && plugin(["plugin", "install", DCODE_PLUGIN_ID]);
|
|
4179
|
+
if (installed) {
|
|
4180
|
+
c.log?.(`dcode: native Agent Plugin installed (${DCODE_PLUGIN_ID})`);
|
|
4181
|
+
} else {
|
|
4182
|
+
const source = marketplacePath === false ? join16(c.home, ".hindsight") : marketplacePath;
|
|
4183
|
+
c.log?.(
|
|
4184
|
+
`dcode: could not install the native plugin \u2014 run dcode plugin marketplace add "${source}" && dcode plugin install ${DCODE_PLUGIN_ID}`
|
|
4185
|
+
);
|
|
4186
|
+
}
|
|
4187
|
+
return installed;
|
|
4188
|
+
},
|
|
4189
|
+
uninstall(c) {
|
|
4190
|
+
const plugin = c.dcodePlugin ?? runDcodePlugin;
|
|
4191
|
+
const removed = plugin(["plugin", "uninstall", DCODE_PLUGIN_ID]);
|
|
4192
|
+
const marketplaceRemoved = plugin(["plugin", "marketplace", "remove", DCODE_MARKETPLACE]);
|
|
4193
|
+
if (removed) {
|
|
4194
|
+
c.log?.("dcode: native Agent Plugin removed (foreign ~/.deepagents state preserved)");
|
|
4195
|
+
if (!marketplaceRemoved) {
|
|
4196
|
+
c.log?.(
|
|
4197
|
+
`dcode: the ${DCODE_MARKETPLACE} marketplace is still registered \u2014 remove it with \`dcode plugin marketplace remove ${DCODE_MARKETPLACE}\``
|
|
4198
|
+
);
|
|
4199
|
+
}
|
|
4200
|
+
} else {
|
|
4201
|
+
c.log?.(`dcode: could not run native uninstall for ${DCODE_PLUGIN_ID}`);
|
|
4202
|
+
}
|
|
4203
|
+
return removed;
|
|
4204
|
+
}
|
|
4205
|
+
};
|
|
2246
4206
|
var DSH_MARKER_START = "# HINDSIGHT_CODING_AGENTS_DSH_START";
|
|
2247
4207
|
var DSH_MARKER_END = "# HINDSIGHT_CODING_AGENTS_DSH_END";
|
|
2248
4208
|
var DSH_BLOCK_RE = new RegExp(`\\n?${DSH_MARKER_START}[\\s\\S]*?${DSH_MARKER_END}\\n?`);
|
|
2249
4209
|
function dshHome(c) {
|
|
2250
|
-
return process.env.DSH_HOME ||
|
|
4210
|
+
return process.env.DSH_HOME || join16(c.home, ".dsh");
|
|
2251
4211
|
}
|
|
2252
4212
|
var dsh = {
|
|
2253
4213
|
name: "dsh",
|
|
2254
|
-
detect: (c) => onPath2("dsh") ||
|
|
4214
|
+
detect: (c) => onPath2("dsh") || existsSync10(dshHome(c)),
|
|
2255
4215
|
install(c) {
|
|
2256
|
-
const path =
|
|
2257
|
-
const existing =
|
|
4216
|
+
const path = join16(dshHome(c), "cordis.patch.yml");
|
|
4217
|
+
const existing = existsSync10(path) ? readFileSync12(path, "utf8") : "";
|
|
2258
4218
|
const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
|
|
2259
|
-
const entry = pathToFileURL(
|
|
4219
|
+
const entry = pathToFileURL(join16(c.dist, "dsh.js")).href;
|
|
2260
4220
|
const block = `${DSH_MARKER_START}
|
|
2261
4221
|
- insert:
|
|
2262
4222
|
- id: hindsight
|
|
2263
4223
|
name: ${JSON.stringify(entry)}
|
|
2264
4224
|
${DSH_MARKER_END}
|
|
2265
4225
|
`;
|
|
2266
|
-
if (
|
|
4226
|
+
if (existsSync10(path) && !existsSync10(`${path}.hindsight-backup`))
|
|
2267
4227
|
copyFileSync(path, `${path}.hindsight-backup`);
|
|
2268
|
-
|
|
2269
|
-
|
|
4228
|
+
mkdirSync4(dirname10(path), { recursive: true });
|
|
4229
|
+
writeFileSync3(path, others ? `${others}
|
|
2270
4230
|
|
|
2271
4231
|
${block}` : block);
|
|
2272
|
-
installSkill(c, "dsh"
|
|
4232
|
+
installSkill(c, "dsh");
|
|
2273
4233
|
c.log?.(`dsh: plugin registered in ${path} (applies to every dsh profile)`);
|
|
2274
4234
|
},
|
|
2275
4235
|
uninstall(c) {
|
|
2276
|
-
const path =
|
|
2277
|
-
if (
|
|
2278
|
-
const existing =
|
|
4236
|
+
const path = join16(dshHome(c), "cordis.patch.yml");
|
|
4237
|
+
if (existsSync10(path)) {
|
|
4238
|
+
const existing = readFileSync12(path, "utf8");
|
|
2279
4239
|
const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
|
|
2280
|
-
if (others !== existing.trim())
|
|
4240
|
+
if (others !== existing.trim()) writeFileSync3(path, others ? `${others}
|
|
2281
4241
|
` : "[]\n");
|
|
2282
4242
|
}
|
|
2283
|
-
uninstallSkill(c,
|
|
4243
|
+
uninstallSkill(c, "dsh");
|
|
2284
4244
|
c.log?.("dsh: plugin entry + skill removed");
|
|
2285
4245
|
}
|
|
2286
4246
|
};
|
|
4247
|
+
var qwen = {
|
|
4248
|
+
name: "qwen-code",
|
|
4249
|
+
detect: (c) => onPath2("qwen") || existsSync10(join16(c.home, ".qwen")),
|
|
4250
|
+
install(c) {
|
|
4251
|
+
const path = join16(c.home, ".qwen", "settings.json");
|
|
4252
|
+
const settings = readJson(path);
|
|
4253
|
+
settings.hooks = settings.hooks ?? {};
|
|
4254
|
+
mergeHarnessHooks(settings.hooks, "qwen-code", c.dist);
|
|
4255
|
+
writeJson(path, settings);
|
|
4256
|
+
c.log?.(`qwen-code: hooks merged into ${path}`);
|
|
4257
|
+
installSkill(c, "qwen-code");
|
|
4258
|
+
const mcp = c.qwenMcp ?? defaultQwenMcp;
|
|
4259
|
+
mcp(["mcp", "remove", "hindsight"]);
|
|
4260
|
+
if (mcp([
|
|
4261
|
+
"mcp",
|
|
4262
|
+
"add",
|
|
4263
|
+
"-s",
|
|
4264
|
+
"user",
|
|
4265
|
+
"-e",
|
|
4266
|
+
"HINDSIGHT_MCP_HARNESS=qwen-code",
|
|
4267
|
+
"hindsight",
|
|
4268
|
+
"node",
|
|
4269
|
+
join16(c.dist, "mcp-server.js")
|
|
4270
|
+
])) {
|
|
4271
|
+
c.log?.("qwen-code: MCP server registered (qwen mcp add, user scope)");
|
|
4272
|
+
} else {
|
|
4273
|
+
c.log?.(
|
|
4274
|
+
`qwen-code: could not run \`qwen mcp add\` \u2014 register the tools manually:
|
|
4275
|
+
qwen mcp add -s user -e HINDSIGHT_MCP_HARNESS=qwen-code hindsight node "${join16(c.dist, "mcp-server.js")}"`
|
|
4276
|
+
);
|
|
4277
|
+
}
|
|
4278
|
+
},
|
|
4279
|
+
uninstall(c) {
|
|
4280
|
+
const path = join16(c.home, ".qwen", "settings.json");
|
|
4281
|
+
if (existsSync10(path)) {
|
|
4282
|
+
const settings = readJson(path);
|
|
4283
|
+
if (settings.hooks) {
|
|
4284
|
+
stripHarnessHooks(settings.hooks, "qwen-code");
|
|
4285
|
+
if (!Object.keys(settings.hooks).length) delete settings.hooks;
|
|
4286
|
+
writeJson(path, settings);
|
|
4287
|
+
}
|
|
4288
|
+
}
|
|
4289
|
+
const mcp = c.qwenMcp ?? defaultQwenMcp;
|
|
4290
|
+
mcp(["mcp", "remove", "hindsight"]);
|
|
4291
|
+
uninstallSkill(c, "qwen-code");
|
|
4292
|
+
c.log?.("qwen-code: hooks + MCP registration + skill removed");
|
|
4293
|
+
}
|
|
4294
|
+
};
|
|
4295
|
+
function defaultQwenMcp(args) {
|
|
4296
|
+
try {
|
|
4297
|
+
execFileSync6("qwen", args, { stdio: "pipe" });
|
|
4298
|
+
return true;
|
|
4299
|
+
} catch {
|
|
4300
|
+
return false;
|
|
4301
|
+
}
|
|
4302
|
+
}
|
|
2287
4303
|
var INSTALLERS = [
|
|
2288
4304
|
opencode,
|
|
4305
|
+
opencode2,
|
|
2289
4306
|
kilo,
|
|
4307
|
+
pi,
|
|
2290
4308
|
primeAgent,
|
|
2291
4309
|
claudeCode,
|
|
2292
4310
|
codex,
|
|
@@ -2295,7 +4313,9 @@ var INSTALLERS = [
|
|
|
2295
4313
|
cursor,
|
|
2296
4314
|
copilot,
|
|
2297
4315
|
grok,
|
|
4316
|
+
qwen,
|
|
2298
4317
|
cline,
|
|
4318
|
+
dcode,
|
|
2299
4319
|
dsh
|
|
2300
4320
|
];
|
|
2301
4321
|
var HARNESS_ALIASES = { agy: "antigravity-cli" };
|
|
@@ -2316,18 +4336,18 @@ function importConversations(harness, ctx) {
|
|
|
2316
4336
|
return;
|
|
2317
4337
|
}
|
|
2318
4338
|
const turns = found.sessions.reduce((n, s) => n + s.turns.length, 0);
|
|
2319
|
-
const file =
|
|
2320
|
-
|
|
4339
|
+
const file = join16(mkdtempSync(join16(tmpdir4(), "hindsight-import-")), "conversations.json");
|
|
4340
|
+
writeFileSync3(file, JSON.stringify(found.sessions));
|
|
2321
4341
|
ctx.log?.(
|
|
2322
4342
|
`${harness}: importing ${found.sessions.length} past sessions (${turns} turns) from ${repo} \u2014 this runs extraction and may take a while`
|
|
2323
4343
|
);
|
|
2324
4344
|
try {
|
|
2325
|
-
execFileSync6("node", [
|
|
4345
|
+
execFileSync6("node", [join16(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
|
|
2326
4346
|
stdio: "inherit"
|
|
2327
4347
|
});
|
|
2328
4348
|
} catch {
|
|
2329
4349
|
ctx.log?.(`${harness}: conversation import did not finish \u2014 re-run it any time with:`);
|
|
2330
|
-
ctx.log?.(` node "${
|
|
4350
|
+
ctx.log?.(` node "${join16(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
|
|
2331
4351
|
}
|
|
2332
4352
|
}
|
|
2333
4353
|
function run(argv, ctxIn) {
|
|
@@ -2336,14 +4356,22 @@ function run(argv, ctxIn) {
|
|
|
2336
4356
|
const importHistory = rawArgs.includes("--import-conversations");
|
|
2337
4357
|
const valueArgs = flagValueArgs(rawArgs, ["server", "api-url", "api-token"]);
|
|
2338
4358
|
const names = rawArgs.filter((a) => !a.startsWith("--") && !valueArgs.has(a));
|
|
2339
|
-
if (command === "install") ctx = stageRuntime(ctx);
|
|
4359
|
+
if (command === "install" || command === "update") ctx = stageRuntime(ctx);
|
|
4360
|
+
if (command === "update") {
|
|
4361
|
+
ctx.log?.(
|
|
4362
|
+
ctx.pkgRoot === ctxIn.pkgRoot ? "runtime already up to date \u2014 nothing staged" : "runtime updated \u2014 every wired agent picks it up on its next session"
|
|
4363
|
+
);
|
|
4364
|
+
return 0;
|
|
4365
|
+
}
|
|
2340
4366
|
if (command !== "install" && command !== "uninstall") {
|
|
2341
4367
|
ctx.log?.(
|
|
2342
4368
|
`usage: hindsight-coding-agents <install|uninstall> <all|harness...>
|
|
4369
|
+
hindsight-coding-agents update
|
|
2343
4370
|
[--server cloud|self-hosted|daemon] [--api-url <url>] [--api-token <token>]
|
|
2344
4371
|
[--import-conversations]
|
|
2345
4372
|
all every agent detected on this machine
|
|
2346
4373
|
harness ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-cli)
|
|
4374
|
+
update re-stage the runtime only, leaving every host config untouched
|
|
2347
4375
|
agents/CI: without a TTY nothing ever prompts \u2014 pass --server (and --api-url/--api-token) to choose`
|
|
2348
4376
|
);
|
|
2349
4377
|
return command ? 1 : 0;
|
|
@@ -2394,38 +4422,40 @@ harnesses: ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-
|
|
|
2394
4422
|
}
|
|
2395
4423
|
}
|
|
2396
4424
|
const runnable = targets.filter((t) => !blocked.has(t.name));
|
|
2397
|
-
|
|
4425
|
+
const failed = [];
|
|
4426
|
+
for (const t of runnable) {
|
|
4427
|
+
if (t[command](ctx) === false) failed.push(t.name);
|
|
4428
|
+
}
|
|
2398
4429
|
if (command === "install" && importHistory) {
|
|
2399
4430
|
for (const t of runnable) importConversations(t.name, ctx);
|
|
2400
4431
|
}
|
|
2401
|
-
if (blocked.size) {
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
\u274C not installed: ${
|
|
2405
|
-
);
|
|
4432
|
+
if (blocked.size || failed.length) {
|
|
4433
|
+
const notInstalled = [...blocked, ...failed];
|
|
4434
|
+
ctx.log?.(`
|
|
4435
|
+
\u274C not installed: ${notInstalled.join(", ")} \u2014 see the messages above.`);
|
|
2406
4436
|
return 1;
|
|
2407
4437
|
}
|
|
2408
4438
|
return 0;
|
|
2409
4439
|
}
|
|
2410
4440
|
var mainPath = process.argv[1] ? (() => {
|
|
2411
4441
|
try {
|
|
2412
|
-
return
|
|
4442
|
+
return realpathSync3(process.argv[1]);
|
|
2413
4443
|
} catch {
|
|
2414
4444
|
return process.argv[1];
|
|
2415
4445
|
}
|
|
2416
4446
|
})() : void 0;
|
|
2417
4447
|
var isMain = mainPath && import.meta.url === pathToFileURL(mainPath).href;
|
|
2418
4448
|
if (isMain || mainPath?.endsWith("installer.js")) {
|
|
2419
|
-
const dist =
|
|
2420
|
-
const pkgRoot =
|
|
4449
|
+
const dist = dirname10(fileURLToPath6(import.meta.url));
|
|
4450
|
+
const pkgRoot = dirname10(dist);
|
|
2421
4451
|
let version;
|
|
2422
4452
|
try {
|
|
2423
|
-
version = JSON.parse(
|
|
4453
|
+
version = JSON.parse(readFileSync12(join16(pkgRoot, "package.json"), "utf8")).version;
|
|
2424
4454
|
} catch {
|
|
2425
4455
|
version = void 0;
|
|
2426
4456
|
}
|
|
2427
4457
|
const ui = createInstallerUi({
|
|
2428
|
-
home:
|
|
4458
|
+
home: homedir10(),
|
|
2429
4459
|
command: process.argv[2],
|
|
2430
4460
|
version,
|
|
2431
4461
|
harnessNames: INSTALLERS.map((i) => i.name),
|
|
@@ -2435,7 +4465,7 @@ if (isMain || mainPath?.endsWith("installer.js")) {
|
|
|
2435
4465
|
});
|
|
2436
4466
|
ui.intro();
|
|
2437
4467
|
const code = run(process.argv.slice(2), {
|
|
2438
|
-
home:
|
|
4468
|
+
home: homedir10(),
|
|
2439
4469
|
pkgRoot,
|
|
2440
4470
|
dist,
|
|
2441
4471
|
// Only a real terminal gets prompted; piped/CI installs take the documented default.
|
|
@@ -2453,6 +4483,8 @@ export {
|
|
|
2453
4483
|
INSTALLERS,
|
|
2454
4484
|
KILO_CONFIG_CANDIDATES,
|
|
2455
4485
|
MARKER,
|
|
4486
|
+
OPENCODE_CONFIG_CANDIDATES,
|
|
4487
|
+
ORIGIN_FILE,
|
|
2456
4488
|
flagValue,
|
|
2457
4489
|
flagValueArgs,
|
|
2458
4490
|
parseJsonc,
|