@vectorize-io/hindsight-coding-agents 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +202 -51
  2. package/dist/antigravity-hook.js +637 -199
  3. package/dist/antigravity-statusline.js +219 -84
  4. package/dist/antigravity-stop-hook.js +654 -205
  5. package/dist/claude-hook.js +637 -199
  6. package/dist/claude-sessionstart-hook.js +863 -236
  7. package/dist/claude-stop-hook.js +654 -205
  8. package/dist/cline.js +589 -234
  9. package/dist/codex-hook.js +637 -199
  10. package/dist/codex-sessionstart-hook.js +863 -236
  11. package/dist/codex-stop-hook.js +654 -205
  12. package/dist/copilot-hook.js +637 -199
  13. package/dist/copilot-sessionstart-hook.js +863 -236
  14. package/dist/copilot-stop-hook.js +654 -205
  15. package/dist/cursor-hook.js +637 -199
  16. package/dist/cursor-sessionstart-hook.js +863 -236
  17. package/dist/cursor-stop-hook.js +654 -205
  18. package/dist/daemon-start.js +62 -43
  19. package/dist/dcode-hook.js +2577 -0
  20. package/dist/dcode-sessionstart-hook.js +3194 -0
  21. package/dist/dcode-stop-hook.js +2807 -0
  22. package/dist/deepen.js +361 -204
  23. package/dist/devin-hook.js +637 -199
  24. package/dist/devin-sessionstart-hook.js +863 -236
  25. package/dist/devin-stop-hook.js +654 -205
  26. package/dist/dsh.js +592 -235
  27. package/dist/grok-hook.js +637 -199
  28. package/dist/grok-sessionstart-hook.js +863 -236
  29. package/dist/grok-stop-hook.js +654 -205
  30. package/dist/hindsight-seed.js +222 -83
  31. package/dist/index.js +589 -234
  32. package/dist/installer.js +2343 -302
  33. package/dist/kilo.js +589 -234
  34. package/dist/mcp-server.js +363 -169
  35. package/dist/opencode2.js +30092 -0
  36. package/dist/pi.js +17650 -0
  37. package/dist/prime-agent.js +625 -260
  38. package/dist/qwen-hook.js +2577 -0
  39. package/dist/qwen-sessionstart-hook.js +3194 -0
  40. package/dist/qwen-stop-hook.js +2807 -0
  41. package/dist/status.js +300 -136
  42. package/hooks/hooks.json +37 -0
  43. package/index.js +10 -0
  44. package/package.json +15 -8
  45. package/plugin.json +16 -0
  46. 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 existsSync9,
9
- mkdirSync as mkdirSync3,
8
+ existsSync as existsSync10,
9
+ mkdirSync as mkdirSync4,
10
10
  mkdtempSync,
11
- readFileSync as readFileSync10,
11
+ readFileSync as readFileSync12,
12
12
  readSync as readSync4,
13
- realpathSync,
13
+ realpathSync as realpathSync3,
14
14
  rmSync as rmSync2,
15
- writeFileSync as writeFileSync2
15
+ writeFileSync as writeFileSync3
16
16
  } from "fs";
17
- import { homedir as homedir9, tmpdir as tmpdir3 } from "os";
17
+ import { homedir as homedir10, tmpdir as tmpdir4 } from "os";
18
18
  import { isatty } from "tty";
19
- import { dirname as dirname8, join as join13 } from "path";
20
- import { fileURLToPath as fileURLToPath5, pathToFileURL } from "url";
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 readFileSync3 } from "fs";
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";
30
-
31
- // src/core/config.ts
32
- import { readFileSync } from "fs";
33
- import { homedir as homedir2 } from "os";
34
- import { join as join4 } from "path";
1356
+ import { basename, dirname as dirname3, join as join3, normalize, sep } from "path";
35
1357
 
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 as dirname3, join as join3 } from "path";
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 || join3(tmpdir(), "hindsight-coding-agent", "plugin.log");
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(dirname3(file), { recursive: true });
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 readFileSync2, renameSync, rmSync, writeFileSync } from "fs";
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 dirname4, join as join5 } from "path";
1449
+ import { dirname as dirname5, join as join7 } from "path";
113
1450
 
114
1451
  // src/core/retain-hook.ts
115
- import { readFileSync as readFileSync4 } from "fs";
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 as execFileSync2, spawn as realSpawn2 } from "child_process";
125
- import { dirname as dirname5, join as join6 } from "path";
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
- execFileSync2("cargo", ["--version"], {
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
- execFileSync2("uvx", ["--version"], {
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
- execFileSync2("which", [bin], {
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 readFileSync6 } from "fs";
1677
+ import { readFileSync as readFileSync8 } from "fs";
341
1678
 
342
1679
  // src/core/git.ts
343
- import { execFileSync as execFileSync3 } from "child_process";
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 execFileSync4 } from "child_process";
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 { accessSync, constants, existsSync as existsSync3 } from "fs";
1688
+ import { existsSync as existsSync3 } from "fs";
352
1689
  import { homedir as homedir3 } from "os";
353
- import { delimiter, dirname as dirname6, join as join7 } from "path";
1690
+ import { dirname as dirname7, join as join9 } from "path";
354
1691
  import { fileURLToPath as fileURLToPath3 } from "url";
355
1692
 
356
- // src/core/skill-sync.ts
357
- import { cpSync, existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
358
- import { homedir as homedir4 } from "os";
359
- import { dirname as dirname7, join as join8 } from "path";
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 existsSync5, readFileSync as readFileSync7, readdirSync } from "fs";
493
- import { homedir as homedir5 } from "os";
494
- import { join as join9 } from "path";
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 || join9(homedir5(), ".grok")) {
497
- const sessionsDir = join9(grokHome, "sessions");
498
- const direct = join9(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
499
- if (existsSync5(direct)) return direct;
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 = join9(sessionsDir, candidate);
503
- if (readFileSync7(join9(directory, ".cwd"), "utf8").trim() === cwd) {
504
- return join9(directory, sessionId, CHAT_HISTORY);
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 existsSync6 } from "fs";
1912
+ import { existsSync as existsSync7 } from "fs";
540
1913
  import { createRequire } from "module";
541
- import { homedir as homedir6 } from "os";
542
- import { join as join10 } from "path";
543
- function devinSessionDb(home = homedir6()) {
544
- return join10(home, ".local", "share", "devin", "cli", "sessions.db");
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 (!existsSync6(dbPath)) {
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
- db?.close();
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 existsSync7,
2542
+ existsSync as existsSync8,
897
2543
  openSync as openSync2,
898
2544
  readdirSync as readdirSync2,
899
- readFileSync as readFileSync8,
2545
+ readFileSync as readFileSync10,
900
2546
  readSync as readSync2,
901
2547
  statSync as statSync2
902
2548
  } from "fs";
903
- import { homedir as homedir7 } from "os";
904
- import { join as join11 } from "path";
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 = homedir7()) {
1000
- return join11(home, ".claude", "projects", repoDir.replace(/[^a-zA-Z0-9]/g, "-"));
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 readFileSync8(file, "utf8").split("\n", 400)) {
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;
@@ -1038,15 +2737,21 @@ function firstLine(path, cap = 1e6) {
1038
2737
  closeSync2(fd);
1039
2738
  }
1040
2739
  }
2740
+ function listDir(dir) {
2741
+ try {
2742
+ return readdirSync2(dir);
2743
+ } catch {
2744
+ return [];
2745
+ }
2746
+ }
1041
2747
  function jsonlFiles(dir) {
1042
- if (!existsSync7(dir)) return [];
1043
- return readdirSync2(dir).filter((f) => f.endsWith(".jsonl")).map((f) => join11(dir, f));
2748
+ return listDir(dir).filter((f) => f.endsWith(".jsonl")).map((f) => join14(dir, f));
1044
2749
  }
1045
2750
  function claudeHistory(repoDir, home) {
1046
- const root = join11(home, ".claude", "projects");
2751
+ const root = join14(home, ".claude", "projects");
1047
2752
  const exact = claudeProjectDir(repoDir, home);
1048
2753
  const prefix = exact + "-";
1049
- const dirs = existsSync7(root) ? readdirSync2(root).map((d) => join11(root, d)).filter((d) => d === exact || d.startsWith(prefix)) : [];
2754
+ const dirs = listDir(root).map((d) => join14(root, d)).filter((d) => d === exact || d.startsWith(prefix));
1050
2755
  const sessions = [];
1051
2756
  let unattributed = 0;
1052
2757
  for (const file of dirs.flatMap(jsonlFiles)) {
@@ -1066,12 +2771,12 @@ function claudeHistory(repoDir, home) {
1066
2771
  return { supported: true, sessions, unattributed };
1067
2772
  }
1068
2773
  function codexHistory(repoDir, home) {
1069
- const root = join11(home, ".codex", "sessions");
1070
- if (!existsSync7(root)) return { supported: true, sessions: [] };
2774
+ const root = join14(home, ".codex", "sessions");
2775
+ if (!existsSync8(root)) return { supported: true, sessions: [] };
1071
2776
  const files = [];
1072
2777
  const walk = (dir) => {
1073
2778
  for (const entry of readdirSync2(dir)) {
1074
- const p = join11(dir, entry);
2779
+ const p = join14(dir, entry);
1075
2780
  if (statSync2(p).isDirectory()) walk(p);
1076
2781
  else if (entry.endsWith(".jsonl")) files.push(p);
1077
2782
  }
@@ -1095,9 +2800,61 @@ function codexHistory(repoDir, home) {
1095
2800
  }
1096
2801
  return { supported: true, sessions };
1097
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
+ }
1098
2855
  function dshHistory(repoDir, home) {
1099
- const root = process.env.DSH_HOME ? join11(process.env.DSH_HOME, "sessions") : join11(home, ".dsh", "sessions");
1100
- if (!existsSync7(root)) return { supported: true, sessions: [] };
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: [] };
1101
2858
  if (typeof zlib2.zstdDecompressSync !== "function") {
1102
2859
  return {
1103
2860
  supported: false,
@@ -1107,15 +2864,15 @@ function dshHistory(repoDir, home) {
1107
2864
  }
1108
2865
  const sessions = [];
1109
2866
  let unattributed = 0;
1110
- for (const dir of readdirSync2(root).map((project) => join11(root, project))) {
2867
+ for (const dir of readdirSync2(root).map((project) => join14(root, project))) {
1111
2868
  let sessionDirs;
1112
2869
  try {
1113
- sessionDirs = readdirSync2(dir).map((id) => join11(dir, id));
2870
+ sessionDirs = readdirSync2(dir).map((id) => join14(dir, id));
1114
2871
  } catch {
1115
2872
  continue;
1116
2873
  }
1117
2874
  for (const sessionDir of sessionDirs) {
1118
- const file = ["session.jsonl.zstd", "session.jsonl"].map((name) => join11(sessionDir, name)).find((candidate) => existsSync7(candidate));
2875
+ const file = ["session.jsonl.zstd", "session.jsonl"].map((name) => join14(sessionDir, name)).find((candidate) => existsSync8(candidate));
1119
2876
  if (!file) continue;
1120
2877
  try {
1121
2878
  const lines = readDshLog(file);
@@ -1141,20 +2898,69 @@ function dshHistory(repoDir, home) {
1141
2898
  return { supported: true, sessions, unattributed };
1142
2899
  }
1143
2900
  function readDshLog(file) {
1144
- const bytes = readFileSync8(file);
2901
+ const bytes = readFileSync10(file);
1145
2902
  const text = file.endsWith(".zstd") ? zstdDecompressFrames(bytes) : bytes.toString("utf8");
1146
2903
  return text.split("\n").filter((line) => line.trim());
1147
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
+ }
1148
2942
  var SQLITE_HISTORY = "keeps session history in an internal SQLite database, whose schema is unversioned and would break on any upstream change";
1149
- function importLocalHistory(harness, repoDir, home = homedir7()) {
2943
+ function importLocalHistory(harness, repoDir, home = homedir8(), runDcodeCli) {
1150
2944
  switch (harness) {
1151
2945
  case "claude-code":
1152
2946
  return claudeHistory(repoDir, home);
1153
2947
  case "codex":
1154
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
+ );
1155
2955
  case "dsh":
1156
2956
  return dshHistory(repoDir, home);
2957
+ case "pi":
2958
+ return piHistory(repoDir, home);
2959
+ case "prime-agent":
2960
+ return primeAgentHistory(repoDir, home);
1157
2961
  case "opencode":
2962
+ // opencode v2 keeps sessions in the SAME `opencode.db` v1 does.
2963
+ case "opencode2":
1158
2964
  case "kilo":
1159
2965
  case "cursor-cli":
1160
2966
  case "cline-cli":
@@ -1167,18 +2973,18 @@ function importLocalHistory(harness, repoDir, home = homedir7()) {
1167
2973
  }
1168
2974
 
1169
2975
  // src/core/legacy.ts
1170
- import { existsSync as existsSync8, readFileSync as readFileSync9 } from "fs";
1171
- import { homedir as homedir8 } from "os";
1172
- import { join as join12 } from "path";
2976
+ import { existsSync as existsSync9, readFileSync as readFileSync11 } from "fs";
2977
+ import { homedir as homedir9 } from "os";
2978
+ import { join as join15 } from "path";
1173
2979
  var LEGACY_CONFIG_FILES = {
1174
2980
  "claude-code": "claude-code.json",
1175
2981
  codex: "codex.json"
1176
2982
  };
1177
- function legacyConfigPath(harness, home = homedir8()) {
1178
- return join12(home, ".hindsight", LEGACY_CONFIG_FILES[harness] ?? `${harness}.json`);
2983
+ function legacyConfigPath(harness, home = homedir9()) {
2984
+ return join15(home, ".hindsight", LEGACY_CONFIG_FILES[harness] ?? `${harness}.json`);
1179
2985
  }
1180
2986
  var CLOUD_URL = "https://api.hindsight.vectorize.io";
1181
- function readLegacyEndpoint(home = homedir8(), prefer = []) {
2987
+ function readLegacyEndpoint(home = homedir9(), prefer = []) {
1182
2988
  const order = [...prefer, ...Object.keys(LEGACY_CONFIG_FILES)].filter(
1183
2989
  (h, i, all) => h in LEGACY_CONFIG_FILES && all.indexOf(h) === i
1184
2990
  );
@@ -1190,10 +2996,10 @@ function readLegacyEndpoint(home = homedir8(), prefer = []) {
1190
2996
  }
1191
2997
  function readOne(harness, home) {
1192
2998
  const source = legacyConfigPath(harness, home);
1193
- if (!existsSync8(source)) return void 0;
2999
+ if (!existsSync9(source)) return void 0;
1194
3000
  let raw;
1195
3001
  try {
1196
- raw = JSON.parse(readFileSync9(source, "utf8"));
3002
+ raw = JSON.parse(readFileSync11(source, "utf8"));
1197
3003
  } catch {
1198
3004
  return void 0;
1199
3005
  }
@@ -1409,6 +3215,10 @@ function createInstallerUi(o) {
1409
3215
  `${dim("\u2514")} ${green("\u2713")} Uninstalled ${agents} in ${secs}s \u2014 Hindsight entries removed, *.hindsight-backup files left in place.`
1410
3216
  );
1411
3217
  }
3218
+ } else if (o.command === "update") {
3219
+ write2(
3220
+ `${dim("\u2514")} ${green("\u2713")} Runtime up to date${o.version ? ` (v${o.version})` : ""}`
3221
+ );
1412
3222
  } else {
1413
3223
  write2(dim("\u2514"));
1414
3224
  }
@@ -1421,7 +3231,7 @@ function createInstallerUi(o) {
1421
3231
  var MARKER = "coding-agents";
1422
3232
  function readJson(path) {
1423
3233
  try {
1424
- return JSON.parse(readFileSync10(path, "utf8"));
3234
+ return JSON.parse(readFileSync12(path, "utf8"));
1425
3235
  } catch {
1426
3236
  return {};
1427
3237
  }
@@ -1436,11 +3246,31 @@ function parseJsonc(text) {
1436
3246
  }
1437
3247
  }
1438
3248
  function writeJson(path, value) {
1439
- mkdirSync3(dirname8(path), { recursive: true });
1440
- if (existsSync9(path) && !existsSync9(`${path}.hindsight-backup`)) {
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`)) {
1441
3255
  copyFileSync(path, `${path}.hindsight-backup`);
1442
3256
  }
1443
- writeFileSync2(path, JSON.stringify(value, null, 2) + "\n");
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
+ `);
1444
3274
  }
1445
3275
  function mergeHookEvent(existing, entry) {
1446
3276
  const kept = (existing ?? []).filter((e) => !JSON.stringify(e).includes(MARKER));
@@ -1454,11 +3284,11 @@ function setOrDelete(obj, key, arr) {
1454
3284
  else delete obj[key];
1455
3285
  }
1456
3286
  var cmdHook = (dist, file, timeout) => ({
1457
- hooks: [{ type: "command", command: `node "${join13(dist, file)}"`, timeout }]
3287
+ hooks: [{ type: "command", command: `node "${join16(dist, file)}"`, timeout }]
1458
3288
  });
1459
3289
  var mcpServerEntry = (dist, harness) => ({
1460
3290
  command: "node",
1461
- args: [join13(dist, "mcp-server.js")],
3291
+ args: [join16(dist, "mcp-server.js")],
1462
3292
  env: { HINDSIGHT_MCP_HARNESS: harness }
1463
3293
  });
1464
3294
  function mergeHarnessHooks(hooks, harness, dist) {
@@ -1468,7 +3298,7 @@ function mergeHarnessHooks(hooks, harness, dist) {
1468
3298
  if (installedEvents.has(hook.event)) continue;
1469
3299
  installedEvents.add(hook.event);
1470
3300
  const entry = spec.configStyle === "nested" ? cmdHook(dist, hook.entry, hook.timeout) : {
1471
- command: `node "${join13(dist, hook.entry)}"`,
3301
+ command: `node "${join16(dist, hook.entry)}"`,
1472
3302
  ...hook.timeout ? { timeout: hook.timeout } : {}
1473
3303
  };
1474
3304
  hooks[hook.event] = mergeHookEvent(hooks[hook.event], entry);
@@ -1482,16 +3312,25 @@ function stripHarnessHooks(hooks, harness) {
1482
3312
  setOrDelete(hooks, hook.event, stripOurs(hooks[hook.event]));
1483
3313
  }
1484
3314
  }
1485
- function installSkill(c, harness, skillsBase) {
1486
- const src = join13(c.pkgRoot, "skill");
1487
- if (!existsSync9(join13(src, "SKILL.md"))) return;
1488
- const dst = join13(skillsBase, "hindsight-coding-agent");
1489
- mkdirSync3(skillsBase, { recursive: true });
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 });
1490
3326
  cpSync2(src, dst, { recursive: true });
1491
3327
  c.log?.(`${harness}: skill installed at ${dst}`);
1492
3328
  }
1493
- function uninstallSkill(c, skillsBase) {
1494
- rmSync2(join13(skillsBase, "hindsight-coding-agent"), { recursive: true, force: true });
3329
+ function uninstallSkill(c, harness) {
3330
+ rmSync2(join16(skillsBaseFor(c, harness), "hindsight-coding-agent"), {
3331
+ recursive: true,
3332
+ force: true
3333
+ });
1495
3334
  }
1496
3335
  function onPath2(bin) {
1497
3336
  try {
@@ -1509,101 +3348,135 @@ function runClinePlugin(args) {
1509
3348
  return false;
1510
3349
  }
1511
3350
  }
1512
- var opencode = {
1513
- name: "opencode",
1514
- detect: (c) => onPath2("opencode") || existsSync9(join13(c.home, ".config", "opencode")),
1515
- install(c) {
1516
- const path = join13(c.home, ".config", "opencode", "opencode.json");
1517
- const cfg = readJson(path);
1518
- const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
1519
- cfg.plugin = [...plugins.filter((p) => !String(p).includes(MARKER)), c.pkgRoot];
1520
- writeJson(path, cfg);
1521
- c.log?.(`opencode: plugin registered in ${path}`);
1522
- },
1523
- uninstall(c) {
1524
- const path = join13(c.home, ".config", "opencode", "opencode.json");
1525
- if (!existsSync9(path)) return;
1526
- const cfg = readJson(path);
1527
- if (Array.isArray(cfg.plugin)) {
1528
- cfg.plugin = cfg.plugin.filter((p) => !String(p).includes(MARKER));
1529
- if (!cfg.plugin.length) delete cfg.plugin;
1530
- writeJson(path, cfg);
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;
1531
3373
  }
1532
- c.log?.("opencode: plugin entry removed");
3374
+ cfg = parsed;
1533
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")
1534
3394
  };
1535
- var primeAgent = {
1536
- name: "prime-agent",
1537
- detect: (c) => onPath2("prime-agent") || existsSync9(join13(c.home, ".prime", "agent")),
1538
- install(c) {
1539
- const path = join13(c.home, ".prime", "agent", "settings.json");
1540
- const cfg = readJson(path);
1541
- const entry = join13(c.pkgRoot, "dist", "prime-agent.js");
1542
- const exts = Array.isArray(cfg.extensions) ? cfg.extensions : [];
1543
- cfg.extensions = [...exts.filter((p) => !String(p).includes(MARKER)), entry];
1544
- writeJson(path, cfg);
1545
- c.log?.(`prime-agent: extension registered in ${path}`);
1546
- },
1547
- uninstall(c) {
1548
- const path = join13(c.home, ".prime", "agent", "settings.json");
1549
- if (!existsSync9(path)) return;
1550
- const cfg = readJson(path);
1551
- if (Array.isArray(cfg.extensions)) {
1552
- cfg.extensions = cfg.extensions.filter((p) => !String(p).includes(MARKER));
1553
- if (!cfg.extensions.length) delete cfg.extensions;
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];
1554
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;
3422
+ const cfg = readJson(path);
3423
+ if (Array.isArray(cfg.extensions)) {
3424
+ cfg.extensions = cfg.extensions.filter((p) => !String(p).includes(MARKER));
3425
+ if (!cfg.extensions.length) delete cfg.extensions;
3426
+ writeJson(path, cfg);
3427
+ }
3428
+ c.log?.(`${harness}: extension entry + skill removed`);
1555
3429
  }
1556
- c.log?.("prime-agent: extension entry removed");
1557
- }
1558
- };
3430
+ };
3431
+ }
3432
+ var pi = piFamilyInstaller("pi", [".pi", "agent"]);
3433
+ var primeAgent = piFamilyInstaller("prime-agent", [".prime", "agent"]);
1559
3434
  var KILO_CONFIG_CANDIDATES = ["kilo.jsonc", "kilo.json", "opencode.json"];
1560
3435
  function kiloConfigPath(c) {
1561
- const dir = join13(c.home, ".config", "kilo");
1562
- const existing = KILO_CONFIG_CANDIDATES.map((f) => join13(dir, f)).find((p) => existsSync9(p));
1563
- return existing ?? join13(dir, "kilo.json");
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");
1564
3439
  }
1565
3440
  var kilo = {
1566
3441
  name: "kilo",
1567
- detect: (c) => onPath2("kilo") || existsSync9(join13(c.home, ".config", "kilo")),
3442
+ detect: (c) => onPath2("kilo") || existsSync10(join16(c.home, ".config", "kilo")),
1568
3443
  install(c) {
1569
3444
  const path = kiloConfigPath(c);
1570
3445
  let cfg = {};
1571
- if (existsSync9(path)) {
1572
- const parsed = parseJsonc(readFileSync10(path, "utf8"));
3446
+ if (existsSync10(path)) {
3447
+ const parsed = parseJsonc(readFileSync12(path, "utf8"));
1573
3448
  if (!parsed) {
1574
3449
  c.log?.(`kilo: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
1575
3450
  return;
1576
3451
  }
1577
3452
  cfg = parsed;
1578
3453
  }
1579
- const entry = pathToFileURL(join13(c.dist, "kilo.js")).href;
3454
+ const entry = pathToFileURL(join16(c.dist, "kilo.js")).href;
1580
3455
  const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
1581
- cfg.plugin = [...plugins.filter((p) => !String(p).includes(MARKER)), entry];
1582
- writeJson(path, cfg);
3456
+ writeJsonc(path, "plugin", [...plugins.filter((p) => !String(p).includes(MARKER)), entry]);
1583
3457
  c.log?.(`kilo: plugin registered in ${path}`);
1584
3458
  },
1585
3459
  uninstall(c) {
1586
3460
  const path = kiloConfigPath(c);
1587
- if (!existsSync9(path)) return;
1588
- const cfg = parseJsonc(readFileSync10(path, "utf8"));
3461
+ if (!existsSync10(path)) return;
3462
+ const cfg = parseJsonc(readFileSync12(path, "utf8"));
1589
3463
  if (!cfg || !Array.isArray(cfg.plugin)) return;
1590
- cfg.plugin = cfg.plugin.filter((p) => !String(p).includes(MARKER));
1591
- if (!cfg.plugin.length) delete cfg.plugin;
1592
- writeJson(path, cfg);
3464
+ const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
3465
+ writeJsonc(path, "plugin", kept.length ? kept : void 0);
1593
3466
  c.log?.("kilo: plugin entry removed");
1594
3467
  }
1595
3468
  };
1596
3469
  var claudeCode = {
1597
3470
  name: "claude-code",
1598
- detect: (c) => onPath2("claude") || existsSync9(join13(c.home, ".claude")),
3471
+ detect: (c) => onPath2("claude") || existsSync10(join16(c.home, ".claude")),
1599
3472
  install(c) {
1600
- const path = join13(c.home, ".claude", "settings.json");
3473
+ const path = join16(c.home, ".claude", "settings.json");
1601
3474
  const settings = readJson(path);
1602
3475
  settings.hooks = settings.hooks ?? {};
1603
3476
  mergeHarnessHooks(settings.hooks, "claude-code", c.dist);
1604
3477
  writeJson(path, settings);
1605
3478
  c.log?.(`claude-code: hooks merged into ${path}`);
1606
- installSkill(c, "claude-code", join13(c.home, ".claude", "skills"));
3479
+ installSkill(c, "claude-code");
1607
3480
  const mcp = c.claudeMcp ?? defaultClaudeMcp;
1608
3481
  mcp(["mcp", "remove", "--scope", "user", "hindsight"]);
1609
3482
  if (mcp([
@@ -1616,19 +3489,19 @@ var claudeCode = {
1616
3489
  "HINDSIGHT_MCP_HARNESS=claude-code",
1617
3490
  "--",
1618
3491
  "node",
1619
- join13(c.dist, "mcp-server.js")
3492
+ join16(c.dist, "mcp-server.js")
1620
3493
  ])) {
1621
3494
  c.log?.("claude-code: MCP server registered (claude mcp add, user scope)");
1622
3495
  } else {
1623
3496
  c.log?.(
1624
3497
  `claude-code: could not run \`claude mcp add\` \u2014 register the tools manually:
1625
- claude mcp add --scope user hindsight --env HINDSIGHT_MCP_HARNESS=claude-code -- node "${join13(c.dist, "mcp-server.js")}"`
3498
+ claude mcp add --scope user hindsight --env HINDSIGHT_MCP_HARNESS=claude-code -- node "${join16(c.dist, "mcp-server.js")}"`
1626
3499
  );
1627
3500
  }
1628
3501
  },
1629
3502
  uninstall(c) {
1630
- const path = join13(c.home, ".claude", "settings.json");
1631
- if (existsSync9(path)) {
3503
+ const path = join16(c.home, ".claude", "settings.json");
3504
+ if (existsSync10(path)) {
1632
3505
  const settings = readJson(path);
1633
3506
  if (settings.hooks) {
1634
3507
  stripHarnessHooks(settings.hooks, "claude-code");
@@ -1638,7 +3511,7 @@ var claudeCode = {
1638
3511
  }
1639
3512
  const mcp = c.claudeMcp ?? defaultClaudeMcp;
1640
3513
  mcp(["mcp", "remove", "--scope", "user", "hindsight"]);
1641
- uninstallSkill(c, join13(c.home, ".claude", "skills"));
3514
+ uninstallSkill(c, "claude-code");
1642
3515
  c.log?.("claude-code: hooks + MCP registration + skill removed");
1643
3516
  }
1644
3517
  };
@@ -1653,20 +3526,20 @@ function defaultClaudeMcp(args) {
1653
3526
  var CODEX_MCP_BLOCK_RE = /^\[mcp_servers\.hindsight(?:\.[^\]]+)?\][^\n]*\n(?:(?!\[)[^\n]*\n?)*/gm;
1654
3527
  var codexMcpBlock = (dist) => `[mcp_servers.hindsight]
1655
3528
  command = "node"
1656
- args = [${JSON.stringify(join13(dist, "mcp-server.js"))}]
3529
+ args = [${JSON.stringify(join16(dist, "mcp-server.js"))}]
1657
3530
  env = { HINDSIGHT_MCP_HARNESS = "codex" }`;
1658
3531
  var codex = {
1659
3532
  name: "codex",
1660
- detect: (c) => onPath2("codex") || existsSync9(join13(c.home, ".codex")),
3533
+ detect: (c) => onPath2("codex") || existsSync10(join16(c.home, ".codex")),
1661
3534
  install(c) {
1662
- const hooksPath = join13(c.home, ".codex", "hooks.json");
3535
+ const hooksPath = join16(c.home, ".codex", "hooks.json");
1663
3536
  const cfg = readJson(hooksPath);
1664
3537
  cfg.hooks = cfg.hooks ?? {};
1665
3538
  mergeHarnessHooks(cfg.hooks, "codex", c.dist);
1666
3539
  writeJson(hooksPath, cfg);
1667
3540
  c.log?.(`codex: hooks merged into ${hooksPath}`);
1668
- const tomlPath = join13(c.home, ".codex", "config.toml");
1669
- const existing = existsSync9(tomlPath) ? readFileSync10(tomlPath, "utf8") : "";
3541
+ const tomlPath = join16(c.home, ".codex", "config.toml");
3542
+ const existing = existsSync10(tomlPath) ? readFileSync12(tomlPath, "utf8") : "";
1670
3543
  const toml = existing.replace(CODEX_MCP_BLOCK_RE, "");
1671
3544
  const additions = [];
1672
3545
  if (!/^\s*(codex_hooks|hooks)\s*=/m.test(toml)) {
@@ -1682,30 +3555,30 @@ var codex = {
1682
3555
  const next = `${toml.replace(/\n*$/, "\n\n")}${additions.join("\n\n")}
1683
3556
  `;
1684
3557
  if (next !== existing) {
1685
- if (existsSync9(tomlPath) && !existsSync9(`${tomlPath}.hindsight-backup`)) {
3558
+ if (existsSync10(tomlPath) && !existsSync10(`${tomlPath}.hindsight-backup`)) {
1686
3559
  copyFileSync(tomlPath, `${tomlPath}.hindsight-backup`);
1687
3560
  }
1688
- mkdirSync3(dirname8(tomlPath), { recursive: true });
1689
- writeFileSync2(tomlPath, next);
3561
+ mkdirSync4(dirname10(tomlPath), { recursive: true });
3562
+ writeFileSync3(tomlPath, next);
1690
3563
  c.log?.(`codex: wrote ${additions.length} section(s) to ${tomlPath}`);
1691
3564
  }
1692
- installSkill(c, "codex", join13(c.home, ".agents", "skills"));
3565
+ installSkill(c, "codex");
1693
3566
  },
1694
3567
  uninstall(c) {
1695
- const hooksPath = join13(c.home, ".codex", "hooks.json");
1696
- if (existsSync9(hooksPath)) {
3568
+ const hooksPath = join16(c.home, ".codex", "hooks.json");
3569
+ if (existsSync10(hooksPath)) {
1697
3570
  const cfg = readJson(hooksPath);
1698
3571
  if (cfg.hooks) {
1699
3572
  stripHarnessHooks(cfg.hooks, "codex");
1700
3573
  writeJson(hooksPath, cfg);
1701
3574
  }
1702
3575
  }
1703
- uninstallSkill(c, join13(c.home, ".agents", "skills"));
1704
- const tomlPath = join13(c.home, ".codex", "config.toml");
1705
- if (existsSync9(tomlPath)) {
1706
- const toml = readFileSync10(tomlPath, "utf8");
3576
+ uninstallSkill(c, "codex");
3577
+ const tomlPath = join16(c.home, ".codex", "config.toml");
3578
+ if (existsSync10(tomlPath)) {
3579
+ const toml = readFileSync12(tomlPath, "utf8");
1707
3580
  const cleaned = toml.replace(CODEX_MCP_BLOCK_RE, "");
1708
- if (cleaned !== toml) writeFileSync2(tomlPath, cleaned);
3581
+ if (cleaned !== toml) writeFileSync3(tomlPath, cleaned);
1709
3582
  }
1710
3583
  c.log?.(
1711
3584
  "codex: hooks + MCP section + skill removed ([features] hooks flag left as-is \u2014 other hooks may use it)"
@@ -1719,7 +3592,7 @@ var antigravity = {
1719
3592
  // can consume this integration.
1720
3593
  detect: (c) => onPath2("agy"),
1721
3594
  install(c) {
1722
- const hooksPath = join13(c.home, ".gemini", "config", "hooks.json");
3595
+ const hooksPath = join16(c.home, ".gemini", "config", "hooks.json");
1723
3596
  const hooks = readJson(hooksPath);
1724
3597
  for (const key of Object.keys(hooks)) {
1725
3598
  if (key !== MARKER && key.includes(MARKER)) delete hooks[key];
@@ -1730,26 +3603,26 @@ var antigravity = {
1730
3603
  setOrDelete(hooks, event, stripOurs(hooks[event]));
1731
3604
  }
1732
3605
  writeJson(hooksPath, hooks);
1733
- const mcpPath = join13(c.home, ".gemini", "config", "mcp_config.json");
3606
+ const mcpPath = join16(c.home, ".gemini", "config", "mcp_config.json");
1734
3607
  const mcp = readJson(mcpPath);
1735
3608
  mcp.mcpServers = {
1736
3609
  ...mcp.mcpServers ?? {},
1737
3610
  hindsight: mcpServerEntry(c.dist, "antigravity-cli")
1738
3611
  };
1739
3612
  writeJson(mcpPath, mcp);
1740
- const settingsPath = join13(c.home, ".gemini", "antigravity-cli", "settings.json");
3613
+ const settingsPath = join16(c.home, ".gemini", "antigravity-cli", "settings.json");
1741
3614
  const settings = readJson(settingsPath);
1742
3615
  if (!settings.statusLine) {
1743
3616
  settings.statusLine = {
1744
3617
  type: "command",
1745
- command: `node "${join13(c.dist, "antigravity-statusline.js")}"`
3618
+ command: `node "${join16(c.dist, "antigravity-statusline.js")}"`
1746
3619
  };
1747
3620
  writeJson(settingsPath, settings);
1748
3621
  c.log?.(`antigravity-cli: Hindsight status line enabled in ${settingsPath}`);
1749
3622
  } else if (JSON.stringify(settings.statusLine).includes(MARKER)) {
1750
3623
  settings.statusLine = {
1751
3624
  type: "command",
1752
- command: `node "${join13(c.dist, "antigravity-statusline.js")}"`
3625
+ command: `node "${join16(c.dist, "antigravity-statusline.js")}"`
1753
3626
  };
1754
3627
  writeJson(settingsPath, settings);
1755
3628
  } else {
@@ -1758,11 +3631,11 @@ var antigravity = {
1758
3631
  );
1759
3632
  }
1760
3633
  c.log?.(`antigravity-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
1761
- installSkill(c, "antigravity-cli", join13(c.home, ".gemini", "config", "skills"));
3634
+ installSkill(c, "antigravity-cli");
1762
3635
  },
1763
3636
  uninstall(c) {
1764
- const hooksPath = join13(c.home, ".gemini", "config", "hooks.json");
1765
- if (existsSync9(hooksPath)) {
3637
+ const hooksPath = join16(c.home, ".gemini", "config", "hooks.json");
3638
+ if (existsSync10(hooksPath)) {
1766
3639
  const hooks = readJson(hooksPath);
1767
3640
  if (hooks[MARKER]) {
1768
3641
  stripHarnessHooks(hooks[MARKER], "antigravity-cli");
@@ -1773,23 +3646,23 @@ var antigravity = {
1773
3646
  }
1774
3647
  writeJson(hooksPath, hooks);
1775
3648
  }
1776
- const mcpPath = join13(c.home, ".gemini", "config", "mcp_config.json");
1777
- if (existsSync9(mcpPath)) {
3649
+ const mcpPath = join16(c.home, ".gemini", "config", "mcp_config.json");
3650
+ if (existsSync10(mcpPath)) {
1778
3651
  const mcp = readJson(mcpPath);
1779
3652
  if (mcp.mcpServers?.hindsight) {
1780
3653
  delete mcp.mcpServers.hindsight;
1781
3654
  writeJson(mcpPath, mcp);
1782
3655
  }
1783
3656
  }
1784
- const settingsPath = join13(c.home, ".gemini", "antigravity-cli", "settings.json");
1785
- if (existsSync9(settingsPath)) {
3657
+ const settingsPath = join16(c.home, ".gemini", "antigravity-cli", "settings.json");
3658
+ if (existsSync10(settingsPath)) {
1786
3659
  const settings = readJson(settingsPath);
1787
3660
  if (JSON.stringify(settings.statusLine ?? {}).includes(MARKER)) {
1788
3661
  delete settings.statusLine;
1789
3662
  writeJson(settingsPath, settings);
1790
3663
  }
1791
3664
  }
1792
- uninstallSkill(c, join13(c.home, ".gemini", "config", "skills"));
3665
+ uninstallSkill(c, "antigravity-cli");
1793
3666
  c.log?.("antigravity-cli: hooks + MCP entry + status line + skill removed");
1794
3667
  }
1795
3668
  };
@@ -1809,29 +3682,38 @@ function pathNodeVersion() {
1809
3682
  }
1810
3683
  }
1811
3684
  function runtimeDir(home) {
1812
- return join13(home, ".hindsight", "coding-agents");
3685
+ return join16(home, ".hindsight", "coding-agents");
1813
3686
  }
3687
+ var ORIGIN_FILE = ".install-origin.json";
1814
3688
  function stageRuntime(c) {
1815
3689
  const target = runtimeDir(c.home);
1816
3690
  const same = (a, b) => {
1817
3691
  try {
1818
- return realpathSync(a) === realpathSync(b);
3692
+ return realpathSync3(a) === realpathSync3(b);
1819
3693
  } catch {
1820
3694
  return a === b;
1821
3695
  }
1822
3696
  };
1823
3697
  if (same(c.pkgRoot, target)) return c;
1824
- if (!existsSync9(join13(c.dist, "installer.js"))) return c;
3698
+ if (!existsSync10(join16(c.dist, "installer.js"))) return c;
1825
3699
  try {
1826
- rmSync2(join13(target, "dist"), { recursive: true, force: true });
1827
- mkdirSync3(target, { recursive: true });
1828
- cpSync2(c.dist, join13(target, "dist"), { recursive: true });
1829
- const skill = join13(c.pkgRoot, "skill");
1830
- if (existsSync9(skill)) cpSync2(skill, join13(target, "skill"), { recursive: true });
1831
- const pkgJson = join13(c.pkgRoot, "package.json");
1832
- if (existsSync9(pkgJson)) copyFileSync(pkgJson, join13(target, "package.json"));
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
+ );
1833
3715
  c.log?.(`runtime staged at ${target}`);
1834
- return { ...c, pkgRoot: target, dist: join13(target, "dist") };
3716
+ return { ...c, pkgRoot: target, dist: join16(target, "dist") };
1835
3717
  } catch (error) {
1836
3718
  c.log?.(`could not stage the runtime at ${target}: ${String(error)}`);
1837
3719
  return c;
@@ -1909,7 +3791,7 @@ function configureServer(c, args, installing) {
1909
3791
  c.log?.(`unknown --server "${explicit}" \u2014 expected one of: ${SERVER_MODES.join(", ")}`);
1910
3792
  return false;
1911
3793
  }
1912
- const configPath = process.env.HINDSIGHT_CONFIG || join13(c.home, ...CONFIG_RELATIVE);
3794
+ const configPath = process.env.HINDSIGHT_CONFIG || join16(c.home, ...CONFIG_RELATIVE);
1913
3795
  const existing = readJson(configPath);
1914
3796
  const alreadyConfigured = !!(existing.serverMode || existing.apiUrl);
1915
3797
  let mode = explicit;
@@ -2005,7 +3887,7 @@ function reportDaemonPrereqs(c) {
2005
3887
  }
2006
3888
  var devin = {
2007
3889
  name: "devin-cli",
2008
- detect: (c) => onPath2("devin") || existsSync9(join13(c.home, ".config", "devin")),
3890
+ detect: (c) => onPath2("devin") || existsSync10(join16(c.home, ".config", "devin")),
2009
3891
  // Devin is the ONLY harness whose hooks never hand over a transcript: they carry a session id and
2010
3892
  // nothing else, so retain can only work by reading the CLI's own sessions.db. That makes SQLite
2011
3893
  // support a hard prerequisite here — and one worth checking now, because the alternative is an
@@ -2018,12 +3900,12 @@ var devin = {
2018
3900
  Upgrade to Node 22.5 or newer (24 LTS recommended) and re-run this command.`;
2019
3901
  },
2020
3902
  install(c) {
2021
- const configPath = join13(c.home, ".config", "devin", "config.json");
3903
+ const configPath = join16(c.home, ".config", "devin", "config.json");
2022
3904
  const config = readJson(configPath);
2023
3905
  config.hooks = config.hooks ?? {};
2024
3906
  mergeHarnessHooks(config.hooks, "devin-cli", c.dist);
2025
3907
  writeJson(configPath, config);
2026
- const mcpPath = join13(c.home, ".config", "devin", "mcp_config.json");
3908
+ const mcpPath = join16(c.home, ".config", "devin", "mcp_config.json");
2027
3909
  const mcp = readJson(mcpPath);
2028
3910
  mcp.mcpServers = {
2029
3911
  ...mcp.mcpServers ?? {},
@@ -2033,8 +3915,8 @@ var devin = {
2033
3915
  c.log?.(`devin-cli: hooks merged into ${configPath}, MCP into ${mcpPath}`);
2034
3916
  },
2035
3917
  uninstall(c) {
2036
- const configPath = join13(c.home, ".config", "devin", "config.json");
2037
- if (existsSync9(configPath)) {
3918
+ const configPath = join16(c.home, ".config", "devin", "config.json");
3919
+ if (existsSync10(configPath)) {
2038
3920
  const config = readJson(configPath);
2039
3921
  if (config.hooks) {
2040
3922
  stripHarnessHooks(config.hooks, "devin-cli");
@@ -2042,8 +3924,8 @@ var devin = {
2042
3924
  writeJson(configPath, config);
2043
3925
  }
2044
3926
  }
2045
- const mcpPath = join13(c.home, ".config", "devin", "mcp_config.json");
2046
- if (existsSync9(mcpPath)) {
3927
+ const mcpPath = join16(c.home, ".config", "devin", "mcp_config.json");
3928
+ if (existsSync10(mcpPath)) {
2047
3929
  const mcp = readJson(mcpPath);
2048
3930
  if (mcp.mcpServers?.hindsight) {
2049
3931
  delete mcp.mcpServers.hindsight;
@@ -2055,14 +3937,14 @@ var devin = {
2055
3937
  };
2056
3938
  var cursor = {
2057
3939
  name: "cursor-cli",
2058
- detect: (c) => onPath2("cursor-agent") || existsSync9(join13(c.home, ".cursor")),
3940
+ detect: (c) => onPath2("cursor-agent") || existsSync10(join16(c.home, ".cursor")),
2059
3941
  install(c) {
2060
- const hooksPath = join13(c.home, ".cursor", "hooks.json");
3942
+ const hooksPath = join16(c.home, ".cursor", "hooks.json");
2061
3943
  const cfg = readJson(hooksPath);
2062
3944
  cfg.hooks = cfg.hooks ?? {};
2063
3945
  mergeHarnessHooks(cfg.hooks, "cursor-cli", c.dist);
2064
3946
  writeJson(hooksPath, cfg);
2065
- const mcpPath = join13(c.home, ".cursor", "mcp.json");
3947
+ const mcpPath = join16(c.home, ".cursor", "mcp.json");
2066
3948
  const mcp = readJson(mcpPath);
2067
3949
  mcp.mcpServers = {
2068
3950
  ...mcp.mcpServers ?? {},
@@ -2070,11 +3952,11 @@ var cursor = {
2070
3952
  };
2071
3953
  writeJson(mcpPath, mcp);
2072
3954
  c.log?.(`cursor-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
2073
- installSkill(c, "cursor-cli", join13(c.home, ".cursor", "skills"));
3955
+ installSkill(c, "cursor-cli");
2074
3956
  },
2075
3957
  uninstall(c) {
2076
- const hooksPath = join13(c.home, ".cursor", "hooks.json");
2077
- if (existsSync9(hooksPath)) {
3958
+ const hooksPath = join16(c.home, ".cursor", "hooks.json");
3959
+ if (existsSync10(hooksPath)) {
2078
3960
  const cfg = readJson(hooksPath);
2079
3961
  if (cfg.hooks) {
2080
3962
  stripHarnessHooks(cfg.hooks, "cursor-cli");
@@ -2082,49 +3964,49 @@ var cursor = {
2082
3964
  writeJson(hooksPath, cfg);
2083
3965
  }
2084
3966
  }
2085
- const mcpPath = join13(c.home, ".cursor", "mcp.json");
2086
- if (existsSync9(mcpPath)) {
3967
+ const mcpPath = join16(c.home, ".cursor", "mcp.json");
3968
+ if (existsSync10(mcpPath)) {
2087
3969
  const mcp = readJson(mcpPath);
2088
3970
  if (mcp.mcpServers?.hindsight) {
2089
3971
  delete mcp.mcpServers.hindsight;
2090
3972
  writeJson(mcpPath, mcp);
2091
3973
  }
2092
3974
  }
2093
- uninstallSkill(c, join13(c.home, ".cursor", "skills"));
3975
+ uninstallSkill(c, "cursor-cli");
2094
3976
  c.log?.("cursor-cli: hooks + MCP entry + skill removed");
2095
3977
  }
2096
3978
  };
2097
3979
  var copilot = {
2098
3980
  name: "copilot-cli",
2099
- detect: (c) => onPath2("copilot") || existsSync9(join13(c.home, ".copilot")),
3981
+ detect: (c) => onPath2("copilot") || existsSync10(join16(c.home, ".copilot")),
2100
3982
  install(c) {
2101
- const hooksPath = join13(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
3983
+ const hooksPath = join16(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
2102
3984
  const hooks = {};
2103
3985
  mergeHarnessHooks(hooks, "copilot-cli", c.dist);
2104
3986
  writeJson(hooksPath, { version: 1, hooks });
2105
- const mcpPath = join13(c.home, ".copilot", "mcp-config.json");
3987
+ const mcpPath = join16(c.home, ".copilot", "mcp-config.json");
2106
3988
  const mcp = readJson(mcpPath);
2107
3989
  mcp.mcpServers = {
2108
3990
  ...mcp.mcpServers ?? {},
2109
3991
  hindsight: mcpServerEntry(c.dist, "copilot-cli")
2110
3992
  };
2111
3993
  writeJson(mcpPath, mcp);
2112
- installSkill(c, "copilot-cli", join13(c.home, ".copilot", "skills"));
3994
+ installSkill(c, "copilot-cli");
2113
3995
  c.log?.(`copilot-cli: hooks installed at ${hooksPath}, MCP into ${mcpPath}`);
2114
3996
  },
2115
3997
  uninstall(c) {
2116
- rmSync2(join13(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
3998
+ rmSync2(join16(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
2117
3999
  force: true
2118
4000
  });
2119
- const mcpPath = join13(c.home, ".copilot", "mcp-config.json");
2120
- if (existsSync9(mcpPath)) {
4001
+ const mcpPath = join16(c.home, ".copilot", "mcp-config.json");
4002
+ if (existsSync10(mcpPath)) {
2121
4003
  const mcp = readJson(mcpPath);
2122
4004
  if (mcp.mcpServers?.hindsight) {
2123
4005
  delete mcp.mcpServers.hindsight;
2124
4006
  writeJson(mcpPath, mcp);
2125
4007
  }
2126
4008
  }
2127
- uninstallSkill(c, join13(c.home, ".copilot", "skills"));
4009
+ uninstallSkill(c, "copilot-cli");
2128
4010
  c.log?.("copilot-cli: hooks + MCP entry + skill removed");
2129
4011
  }
2130
4012
  };
@@ -2133,12 +4015,12 @@ var GROK_MARKER_END = "# HINDSIGHT_CODING_AGENTS_GROK_END";
2133
4015
  var GROK_BLOCK_RE = new RegExp(`\\n?${GROK_MARKER_START}[\\s\\S]*?${GROK_MARKER_END}\\n?`);
2134
4016
  var grok = {
2135
4017
  name: "grok-build",
2136
- detect: (c) => onPath2("grok") || existsSync9(join13(c.home, ".grok")),
4018
+ detect: (c) => onPath2("grok") || existsSync10(join16(c.home, ".grok")),
2137
4019
  install(c) {
2138
- const path = join13(c.home, ".grok", "config.toml");
2139
- const existing = existsSync9(path) ? readFileSync10(path, "utf8") : "";
4020
+ const path = join16(c.home, ".grok", "config.toml");
4021
+ const existing = existsSync10(path) ? readFileSync12(path, "utf8") : "";
2140
4022
  const withoutOurs = existing.replace(GROK_BLOCK_RE, "\n");
2141
- const command = (entry) => JSON.stringify(`node "${join13(c.dist, entry)}"`);
4023
+ const command = (entry) => JSON.stringify(`node "${join16(c.dist, entry)}"`);
2142
4024
  const tomlString = (value) => JSON.stringify(value);
2143
4025
  const block = `
2144
4026
  ${GROK_MARKER_START}
@@ -2162,25 +4044,25 @@ ${GROK_MARKER_START}
2162
4044
 
2163
4045
  [mcp_servers.hindsight]
2164
4046
  command = "node"
2165
- args = [${tomlString(join13(c.dist, "mcp-server.js"))}]
4047
+ args = [${tomlString(join16(c.dist, "mcp-server.js"))}]
2166
4048
  env = { HINDSIGHT_MCP_HARNESS = "grok-build" }
2167
4049
  ${GROK_MARKER_END}
2168
4050
  `;
2169
- if (existsSync9(path) && !existsSync9(`${path}.hindsight-backup`))
4051
+ if (existsSync10(path) && !existsSync10(`${path}.hindsight-backup`))
2170
4052
  copyFileSync(path, `${path}.hindsight-backup`);
2171
- mkdirSync3(dirname8(path), { recursive: true });
2172
- writeFileSync2(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
2173
- installSkill(c, "grok-build", join13(c.home, ".grok", "skills"));
4053
+ mkdirSync4(dirname10(path), { recursive: true });
4054
+ writeFileSync3(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
4055
+ installSkill(c, "grok-build");
2174
4056
  c.log?.(`grok-build: native hooks + MCP installed in ${path}`);
2175
4057
  },
2176
4058
  uninstall(c) {
2177
- const path = join13(c.home, ".grok", "config.toml");
2178
- if (existsSync9(path)) {
2179
- const existing = readFileSync10(path, "utf8");
4059
+ const path = join16(c.home, ".grok", "config.toml");
4060
+ if (existsSync10(path)) {
4061
+ const existing = readFileSync12(path, "utf8");
2180
4062
  const cleaned = existing.replace(GROK_BLOCK_RE, "\n");
2181
- if (cleaned !== existing) writeFileSync2(path, cleaned);
4063
+ if (cleaned !== existing) writeFileSync3(path, cleaned);
2182
4064
  }
2183
- uninstallSkill(c, join13(c.home, ".grok", "skills"));
4065
+ uninstallSkill(c, "grok-build");
2184
4066
  c.log?.("grok-build: native hooks + MCP + skill removed");
2185
4067
  }
2186
4068
  };
@@ -2188,17 +4070,17 @@ var CLINE_HOOK_MARKER = "HINDSIGHT_CODING_AGENTS_CLINE";
2188
4070
  var CLINE_OLD_HOOK_EVENTS = ["TaskStart", "UserPromptSubmit", "TaskComplete"];
2189
4071
  var CLINE_PLUGIN_NAME = "@vectorize-io/hindsight-coding-agents";
2190
4072
  function removeLegacyClineHooks(c) {
2191
- const hooksDir = join13(c.home, "Documents", "Cline", "Hooks");
4073
+ const hooksDir = join16(c.home, "Documents", "Cline", "Hooks");
2192
4074
  for (const event of CLINE_OLD_HOOK_EVENTS) {
2193
- const path = join13(hooksDir, event);
2194
- if (existsSync9(path) && readFileSync10(path, "utf8").includes(CLINE_HOOK_MARKER)) {
4075
+ const path = join16(hooksDir, event);
4076
+ if (existsSync10(path) && readFileSync12(path, "utf8").includes(CLINE_HOOK_MARKER)) {
2195
4077
  rmSync2(path, { force: true });
2196
4078
  }
2197
4079
  }
2198
4080
  }
2199
4081
  var cline = {
2200
4082
  name: "cline-cli",
2201
- detect: (c) => onPath2("cline") || existsSync9(join13(c.home, ".cline")),
4083
+ detect: (c) => onPath2("cline") || existsSync10(join16(c.home, ".cline")),
2202
4084
  install(c) {
2203
4085
  removeLegacyClineHooks(c);
2204
4086
  const installed = (c.clinePlugin ?? runClinePlugin)([
@@ -2207,14 +4089,14 @@ var cline = {
2207
4089
  "--force",
2208
4090
  c.pkgRoot
2209
4091
  ]);
2210
- const mcpPath = join13(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
4092
+ const mcpPath = join16(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
2211
4093
  const mcp = readJson(mcpPath);
2212
4094
  mcp.mcpServers = {
2213
4095
  ...mcp.mcpServers ?? {},
2214
4096
  hindsight: mcpServerEntry(c.dist, "cline-cli")
2215
4097
  };
2216
4098
  writeJson(mcpPath, mcp);
2217
- installSkill(c, "cline-cli", join13(c.home, ".cline", "data", "settings", "skills"));
4099
+ installSkill(c, "cline-cli");
2218
4100
  c.log?.(
2219
4101
  installed ? "cline-cli: native plugin + MCP + skill installed" : `cline-cli: MCP + skill installed; run: cline plugin install --force "${c.pkgRoot}"`
2220
4102
  );
@@ -2222,62 +4104,207 @@ var cline = {
2222
4104
  uninstall(c) {
2223
4105
  removeLegacyClineHooks(c);
2224
4106
  (c.clinePlugin ?? runClinePlugin)(["plugin", "uninstall", CLINE_PLUGIN_NAME]);
2225
- const mcpPath = join13(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
2226
- if (existsSync9(mcpPath)) {
4107
+ const mcpPath = join16(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
4108
+ if (existsSync10(mcpPath)) {
2227
4109
  const mcp = readJson(mcpPath);
2228
4110
  if (mcp.mcpServers?.hindsight) {
2229
4111
  delete mcp.mcpServers.hindsight;
2230
4112
  writeJson(mcpPath, mcp);
2231
4113
  }
2232
4114
  }
2233
- uninstallSkill(c, join13(c.home, ".cline", "data", "settings", "skills"));
4115
+ uninstallSkill(c, "cline-cli");
2234
4116
  c.log?.("cline-cli: native plugin + MCP + skill removed");
2235
4117
  }
2236
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
+ };
2237
4206
  var DSH_MARKER_START = "# HINDSIGHT_CODING_AGENTS_DSH_START";
2238
4207
  var DSH_MARKER_END = "# HINDSIGHT_CODING_AGENTS_DSH_END";
2239
4208
  var DSH_BLOCK_RE = new RegExp(`\\n?${DSH_MARKER_START}[\\s\\S]*?${DSH_MARKER_END}\\n?`);
2240
4209
  function dshHome(c) {
2241
- return process.env.DSH_HOME || join13(c.home, ".dsh");
4210
+ return process.env.DSH_HOME || join16(c.home, ".dsh");
2242
4211
  }
2243
4212
  var dsh = {
2244
4213
  name: "dsh",
2245
- detect: (c) => onPath2("dsh") || existsSync9(dshHome(c)),
4214
+ detect: (c) => onPath2("dsh") || existsSync10(dshHome(c)),
2246
4215
  install(c) {
2247
- const path = join13(dshHome(c), "cordis.patch.yml");
2248
- const existing = existsSync9(path) ? readFileSync10(path, "utf8") : "";
4216
+ const path = join16(dshHome(c), "cordis.patch.yml");
4217
+ const existing = existsSync10(path) ? readFileSync12(path, "utf8") : "";
2249
4218
  const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
2250
- const entry = pathToFileURL(join13(c.dist, "dsh.js")).href;
4219
+ const entry = pathToFileURL(join16(c.dist, "dsh.js")).href;
2251
4220
  const block = `${DSH_MARKER_START}
2252
4221
  - insert:
2253
4222
  - id: hindsight
2254
4223
  name: ${JSON.stringify(entry)}
2255
4224
  ${DSH_MARKER_END}
2256
4225
  `;
2257
- if (existsSync9(path) && !existsSync9(`${path}.hindsight-backup`))
4226
+ if (existsSync10(path) && !existsSync10(`${path}.hindsight-backup`))
2258
4227
  copyFileSync(path, `${path}.hindsight-backup`);
2259
- mkdirSync3(dirname8(path), { recursive: true });
2260
- writeFileSync2(path, others ? `${others}
4228
+ mkdirSync4(dirname10(path), { recursive: true });
4229
+ writeFileSync3(path, others ? `${others}
2261
4230
 
2262
4231
  ${block}` : block);
2263
- installSkill(c, "dsh", join13(c.home, ".agents", "skills"));
4232
+ installSkill(c, "dsh");
2264
4233
  c.log?.(`dsh: plugin registered in ${path} (applies to every dsh profile)`);
2265
4234
  },
2266
4235
  uninstall(c) {
2267
- const path = join13(dshHome(c), "cordis.patch.yml");
2268
- if (existsSync9(path)) {
2269
- const existing = readFileSync10(path, "utf8");
4236
+ const path = join16(dshHome(c), "cordis.patch.yml");
4237
+ if (existsSync10(path)) {
4238
+ const existing = readFileSync12(path, "utf8");
2270
4239
  const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
2271
- if (others !== existing.trim()) writeFileSync2(path, others ? `${others}
4240
+ if (others !== existing.trim()) writeFileSync3(path, others ? `${others}
2272
4241
  ` : "[]\n");
2273
4242
  }
2274
- uninstallSkill(c, join13(c.home, ".agents", "skills"));
4243
+ uninstallSkill(c, "dsh");
2275
4244
  c.log?.("dsh: plugin entry + skill removed");
2276
4245
  }
2277
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
+ }
2278
4303
  var INSTALLERS = [
2279
4304
  opencode,
4305
+ opencode2,
2280
4306
  kilo,
4307
+ pi,
2281
4308
  primeAgent,
2282
4309
  claudeCode,
2283
4310
  codex,
@@ -2286,7 +4313,9 @@ var INSTALLERS = [
2286
4313
  cursor,
2287
4314
  copilot,
2288
4315
  grok,
4316
+ qwen,
2289
4317
  cline,
4318
+ dcode,
2290
4319
  dsh
2291
4320
  ];
2292
4321
  var HARNESS_ALIASES = { agy: "antigravity-cli" };
@@ -2307,18 +4336,18 @@ function importConversations(harness, ctx) {
2307
4336
  return;
2308
4337
  }
2309
4338
  const turns = found.sessions.reduce((n, s) => n + s.turns.length, 0);
2310
- const file = join13(mkdtempSync(join13(tmpdir3(), "hindsight-import-")), "conversations.json");
2311
- writeFileSync2(file, JSON.stringify(found.sessions));
4339
+ const file = join16(mkdtempSync(join16(tmpdir4(), "hindsight-import-")), "conversations.json");
4340
+ writeFileSync3(file, JSON.stringify(found.sessions));
2312
4341
  ctx.log?.(
2313
4342
  `${harness}: importing ${found.sessions.length} past sessions (${turns} turns) from ${repo} \u2014 this runs extraction and may take a while`
2314
4343
  );
2315
4344
  try {
2316
- execFileSync6("node", [join13(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
4345
+ execFileSync6("node", [join16(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
2317
4346
  stdio: "inherit"
2318
4347
  });
2319
4348
  } catch {
2320
4349
  ctx.log?.(`${harness}: conversation import did not finish \u2014 re-run it any time with:`);
2321
- ctx.log?.(` node "${join13(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
4350
+ ctx.log?.(` node "${join16(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
2322
4351
  }
2323
4352
  }
2324
4353
  function run(argv, ctxIn) {
@@ -2327,14 +4356,22 @@ function run(argv, ctxIn) {
2327
4356
  const importHistory = rawArgs.includes("--import-conversations");
2328
4357
  const valueArgs = flagValueArgs(rawArgs, ["server", "api-url", "api-token"]);
2329
4358
  const names = rawArgs.filter((a) => !a.startsWith("--") && !valueArgs.has(a));
2330
- 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
+ }
2331
4366
  if (command !== "install" && command !== "uninstall") {
2332
4367
  ctx.log?.(
2333
4368
  `usage: hindsight-coding-agents <install|uninstall> <all|harness...>
4369
+ hindsight-coding-agents update
2334
4370
  [--server cloud|self-hosted|daemon] [--api-url <url>] [--api-token <token>]
2335
4371
  [--import-conversations]
2336
4372
  all every agent detected on this machine
2337
4373
  harness ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-cli)
4374
+ update re-stage the runtime only, leaving every host config untouched
2338
4375
  agents/CI: without a TTY nothing ever prompts \u2014 pass --server (and --api-url/--api-token) to choose`
2339
4376
  );
2340
4377
  return command ? 1 : 0;
@@ -2385,38 +4422,40 @@ harnesses: ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-
2385
4422
  }
2386
4423
  }
2387
4424
  const runnable = targets.filter((t) => !blocked.has(t.name));
2388
- for (const t of runnable) t[command](ctx);
4425
+ const failed = [];
4426
+ for (const t of runnable) {
4427
+ if (t[command](ctx) === false) failed.push(t.name);
4428
+ }
2389
4429
  if (command === "install" && importHistory) {
2390
4430
  for (const t of runnable) importConversations(t.name, ctx);
2391
4431
  }
2392
- if (blocked.size) {
2393
- ctx.log?.(
2394
- `
2395
- \u274C not installed: ${[...blocked].join(", ")} \u2014 this machine can't run ${blocked.size > 1 ? "them" : "it"} (see above).`
2396
- );
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.`);
2397
4436
  return 1;
2398
4437
  }
2399
4438
  return 0;
2400
4439
  }
2401
4440
  var mainPath = process.argv[1] ? (() => {
2402
4441
  try {
2403
- return realpathSync(process.argv[1]);
4442
+ return realpathSync3(process.argv[1]);
2404
4443
  } catch {
2405
4444
  return process.argv[1];
2406
4445
  }
2407
4446
  })() : void 0;
2408
4447
  var isMain = mainPath && import.meta.url === pathToFileURL(mainPath).href;
2409
4448
  if (isMain || mainPath?.endsWith("installer.js")) {
2410
- const dist = dirname8(fileURLToPath5(import.meta.url));
2411
- const pkgRoot = dirname8(dist);
4449
+ const dist = dirname10(fileURLToPath6(import.meta.url));
4450
+ const pkgRoot = dirname10(dist);
2412
4451
  let version;
2413
4452
  try {
2414
- version = JSON.parse(readFileSync10(join13(pkgRoot, "package.json"), "utf8")).version;
4453
+ version = JSON.parse(readFileSync12(join16(pkgRoot, "package.json"), "utf8")).version;
2415
4454
  } catch {
2416
4455
  version = void 0;
2417
4456
  }
2418
4457
  const ui = createInstallerUi({
2419
- home: homedir9(),
4458
+ home: homedir10(),
2420
4459
  command: process.argv[2],
2421
4460
  version,
2422
4461
  harnessNames: INSTALLERS.map((i) => i.name),
@@ -2426,7 +4465,7 @@ if (isMain || mainPath?.endsWith("installer.js")) {
2426
4465
  });
2427
4466
  ui.intro();
2428
4467
  const code = run(process.argv.slice(2), {
2429
- home: homedir9(),
4468
+ home: homedir10(),
2430
4469
  pkgRoot,
2431
4470
  dist,
2432
4471
  // Only a real terminal gets prompted; piped/CI installs take the documented default.
@@ -2444,6 +4483,8 @@ export {
2444
4483
  INSTALLERS,
2445
4484
  KILO_CONFIG_CANDIDATES,
2446
4485
  MARKER,
4486
+ OPENCODE_CONFIG_CANDIDATES,
4487
+ ORIGIN_FILE,
2447
4488
  flagValue,
2448
4489
  flagValueArgs,
2449
4490
  parseJsonc,