@vectorize-io/hindsight-coding-agents 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +201 -16
- package/dist/antigravity-hook.js +1132 -115
- package/dist/antigravity-statusline.js +77 -11
- package/dist/antigravity-stop-hook.js +1193 -133
- package/dist/claude-hook.js +1132 -115
- package/dist/claude-sessionstart-hook.js +1241 -140
- package/dist/claude-stop-hook.js +1193 -133
- package/dist/cline.js +578 -163
- package/dist/codebuddy-hook.js +4270 -0
- package/dist/codebuddy-sessionstart-hook.js +5030 -0
- package/dist/codebuddy-stop-hook.js +4564 -0
- package/dist/codex-hook.js +1132 -115
- package/dist/codex-sessionstart-hook.js +1241 -140
- package/dist/codex-stop-hook.js +1193 -133
- package/dist/copilot-hook.js +1132 -115
- package/dist/copilot-sessionstart-hook.js +1241 -140
- package/dist/copilot-stop-hook.js +1193 -133
- package/dist/cursor-hook.js +1132 -115
- package/dist/cursor-sessionstart-hook.js +1241 -140
- package/dist/cursor-stop-hook.js +1193 -133
- package/dist/daemon-start.js +54 -9
- package/dist/dcode-hook.js +1132 -115
- package/dist/dcode-sessionstart-hook.js +1241 -140
- package/dist/dcode-stop-hook.js +1193 -133
- package/dist/deepen.js +370 -104
- package/dist/devin-hook.js +1132 -115
- package/dist/devin-sessionstart-hook.js +1241 -140
- package/dist/devin-stop-hook.js +1193 -133
- package/dist/droid-hook.js +1132 -115
- package/dist/droid-sessionstart-hook.js +1241 -140
- package/dist/droid-stop-hook.js +1193 -133
- package/dist/dsh.js +586 -164
- package/dist/grok-hook.js +1132 -115
- package/dist/grok-sessionstart-hook.js +1241 -140
- package/dist/grok-stop-hook.js +1193 -133
- package/dist/hindsight-seed.js +50 -8
- package/dist/index.js +587 -172
- package/dist/installer.js +2010 -769
- package/dist/kilo.js +587 -172
- package/dist/kimi-hook.js +4270 -0
- package/dist/kimi-sessionstart-hook.js +5030 -0
- package/dist/kimi-stop-hook.js +4564 -0
- package/dist/mcp-server.js +419 -115
- package/dist/opencode2.js +586 -169
- package/dist/pi.js +644 -175
- package/dist/prime-agent.js +644 -175
- package/dist/qwen-hook.js +1132 -115
- package/dist/qwen-sessionstart-hook.js +1241 -140
- package/dist/qwen-stop-hook.js +1193 -133
- package/dist/status.js +243 -52
- package/dist/traecode-hook.js +4270 -0
- package/dist/traecode-sessionstart-hook.js +5030 -0
- package/dist/traecode-stop-hook.js +4564 -0
- package/dist/workbuddy-hook.js +4270 -0
- package/dist/workbuddy-sessionstart-hook.js +5030 -0
- package/dist/workbuddy-stop-hook.js +4564 -0
- package/dist/zcode-hook.js +1132 -115
- package/dist/zcode-sessionstart-hook.js +1241 -140
- package/dist/zcode-stop-hook.js +1193 -133
- package/package.json +22 -12
- package/plugin.json +1 -1
- package/skill/SKILL.md +73 -14
package/dist/installer.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/installer.ts
|
|
4
|
-
import { execFileSync as
|
|
4
|
+
import { execFileSync as execFileSync8 } from "child_process";
|
|
5
5
|
import {
|
|
6
6
|
copyFileSync,
|
|
7
7
|
cpSync as cpSync2,
|
|
8
|
-
existsSync as
|
|
9
|
-
mkdirSync as
|
|
8
|
+
existsSync as existsSync13,
|
|
9
|
+
mkdirSync as mkdirSync7,
|
|
10
10
|
mkdtempSync as mkdtempSync2,
|
|
11
11
|
readFileSync as readFileSync15,
|
|
12
12
|
readSync as readSync4,
|
|
13
13
|
realpathSync as realpathSync3,
|
|
14
|
-
rmSync as
|
|
15
|
-
writeFileSync as
|
|
14
|
+
rmSync as rmSync4,
|
|
15
|
+
writeFileSync as writeFileSync5
|
|
16
16
|
} from "fs";
|
|
17
|
-
import { homedir as
|
|
17
|
+
import { homedir as homedir13, tmpdir as tmpdir5 } from "os";
|
|
18
18
|
import { isatty } from "tty";
|
|
19
|
-
import { dirname as
|
|
20
|
-
import { fileURLToPath as
|
|
19
|
+
import { dirname as dirname13, join as join24 } from "path";
|
|
20
|
+
import { fileURLToPath as fileURLToPath7, pathToFileURL } from "url";
|
|
21
21
|
|
|
22
22
|
// node_modules/jsonc-parser/lib/esm/impl/scanner.js
|
|
23
23
|
function createScanner(text, ignoreTrivia = false) {
|
|
@@ -910,15 +910,15 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
|
910
910
|
}
|
|
911
911
|
}
|
|
912
912
|
}
|
|
913
|
-
function handleError(error, skipUntilAfter = [],
|
|
913
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
914
914
|
onError(error);
|
|
915
|
-
if (skipUntilAfter.length +
|
|
915
|
+
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
916
916
|
let token = _scanner.getToken();
|
|
917
917
|
while (token !== 17) {
|
|
918
918
|
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
919
919
|
scanNext();
|
|
920
920
|
break;
|
|
921
|
-
} else if (
|
|
921
|
+
} else if (skipUntil.indexOf(token) !== -1) {
|
|
922
922
|
break;
|
|
923
923
|
}
|
|
924
924
|
token = scanNext();
|
|
@@ -978,7 +978,7 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
|
978
978
|
if (_scanner.getToken() === 6) {
|
|
979
979
|
onSeparator(":");
|
|
980
980
|
scanNext();
|
|
981
|
-
if (!
|
|
981
|
+
if (!parseValue()) {
|
|
982
982
|
handleError(4, [], [
|
|
983
983
|
2,
|
|
984
984
|
5
|
|
@@ -1056,7 +1056,7 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
|
1056
1056
|
} else {
|
|
1057
1057
|
_jsonPath[_jsonPath.length - 1]++;
|
|
1058
1058
|
}
|
|
1059
|
-
if (!
|
|
1059
|
+
if (!parseValue()) {
|
|
1060
1060
|
handleError(4, [], [
|
|
1061
1061
|
4,
|
|
1062
1062
|
5
|
|
@@ -1079,7 +1079,7 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
|
1079
1079
|
}
|
|
1080
1080
|
return true;
|
|
1081
1081
|
}
|
|
1082
|
-
function
|
|
1082
|
+
function parseValue() {
|
|
1083
1083
|
switch (_scanner.getToken()) {
|
|
1084
1084
|
case 3:
|
|
1085
1085
|
return parseArray2();
|
|
@@ -1099,7 +1099,7 @@ function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
|
1099
1099
|
handleError(4, [], []);
|
|
1100
1100
|
return false;
|
|
1101
1101
|
}
|
|
1102
|
-
if (!
|
|
1102
|
+
if (!parseValue()) {
|
|
1103
1103
|
handleError(4, [], []);
|
|
1104
1104
|
return false;
|
|
1105
1105
|
}
|
|
@@ -1347,105 +1347,13 @@ function applyEdits(text, edits) {
|
|
|
1347
1347
|
return text;
|
|
1348
1348
|
}
|
|
1349
1349
|
|
|
1350
|
-
// node_modules/smol-toml/dist/date.js
|
|
1351
|
-
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;
|
|
1352
|
-
var TomlDate = class _TomlDate extends Date {
|
|
1353
|
-
#hasDate = false;
|
|
1354
|
-
#hasTime = false;
|
|
1355
|
-
#offset = null;
|
|
1356
|
-
constructor(date) {
|
|
1357
|
-
let hasDate = true;
|
|
1358
|
-
let hasTime = true;
|
|
1359
|
-
let offset = "Z";
|
|
1360
|
-
if (typeof date === "string") {
|
|
1361
|
-
let match = date.match(DATE_TIME_RE);
|
|
1362
|
-
if (match) {
|
|
1363
|
-
if (!match[1]) {
|
|
1364
|
-
hasDate = false;
|
|
1365
|
-
date = `0000-01-01T${date}`;
|
|
1366
|
-
}
|
|
1367
|
-
hasTime = !!match[2];
|
|
1368
|
-
hasTime && date[10] === " " && (date = date.replace(" ", "T"));
|
|
1369
|
-
if (match[2] && +match[2] > 23) {
|
|
1370
|
-
date = "";
|
|
1371
|
-
} else {
|
|
1372
|
-
offset = match[3] || null;
|
|
1373
|
-
date = date.toUpperCase();
|
|
1374
|
-
if (!offset && hasTime)
|
|
1375
|
-
date += "Z";
|
|
1376
|
-
}
|
|
1377
|
-
} else {
|
|
1378
|
-
date = "";
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
|
-
super(date);
|
|
1382
|
-
if (!isNaN(this.getTime())) {
|
|
1383
|
-
this.#hasDate = hasDate;
|
|
1384
|
-
this.#hasTime = hasTime;
|
|
1385
|
-
this.#offset = offset;
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
isDateTime() {
|
|
1389
|
-
return this.#hasDate && this.#hasTime;
|
|
1390
|
-
}
|
|
1391
|
-
isLocal() {
|
|
1392
|
-
return !this.#hasDate || !this.#hasTime || !this.#offset;
|
|
1393
|
-
}
|
|
1394
|
-
isDate() {
|
|
1395
|
-
return this.#hasDate && !this.#hasTime;
|
|
1396
|
-
}
|
|
1397
|
-
isTime() {
|
|
1398
|
-
return this.#hasTime && !this.#hasDate;
|
|
1399
|
-
}
|
|
1400
|
-
isValid() {
|
|
1401
|
-
return this.#hasDate || this.#hasTime;
|
|
1402
|
-
}
|
|
1403
|
-
toISOString() {
|
|
1404
|
-
let iso = super.toISOString();
|
|
1405
|
-
if (this.isDate())
|
|
1406
|
-
return iso.slice(0, 10);
|
|
1407
|
-
if (this.isTime())
|
|
1408
|
-
return iso.slice(11, 23);
|
|
1409
|
-
if (this.#offset === null)
|
|
1410
|
-
return iso.slice(0, -1);
|
|
1411
|
-
if (this.#offset === "Z")
|
|
1412
|
-
return iso;
|
|
1413
|
-
let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
|
|
1414
|
-
offset = this.#offset[0] === "-" ? offset : -offset;
|
|
1415
|
-
let offsetDate = new Date(this.getTime() - offset * 6e4);
|
|
1416
|
-
return offsetDate.toISOString().slice(0, -1) + this.#offset;
|
|
1417
|
-
}
|
|
1418
|
-
static wrapAsOffsetDateTime(jsDate, offset = "Z") {
|
|
1419
|
-
let date = new _TomlDate(jsDate);
|
|
1420
|
-
date.#offset = offset;
|
|
1421
|
-
return date;
|
|
1422
|
-
}
|
|
1423
|
-
static wrapAsLocalDateTime(jsDate) {
|
|
1424
|
-
let date = new _TomlDate(jsDate);
|
|
1425
|
-
date.#offset = null;
|
|
1426
|
-
return date;
|
|
1427
|
-
}
|
|
1428
|
-
static wrapAsLocalDate(jsDate) {
|
|
1429
|
-
let date = new _TomlDate(jsDate);
|
|
1430
|
-
date.#hasTime = false;
|
|
1431
|
-
date.#offset = null;
|
|
1432
|
-
return date;
|
|
1433
|
-
}
|
|
1434
|
-
static wrapAsLocalTime(jsDate) {
|
|
1435
|
-
let date = new _TomlDate(jsDate);
|
|
1436
|
-
date.#hasDate = false;
|
|
1437
|
-
date.#offset = null;
|
|
1438
|
-
return date;
|
|
1439
|
-
}
|
|
1440
|
-
};
|
|
1441
|
-
|
|
1442
1350
|
// node_modules/smol-toml/dist/error.js
|
|
1443
1351
|
function getLineColFromPtr(string, ptr) {
|
|
1444
|
-
let lines = string.slice(0, ptr).split(/\r
|
|
1352
|
+
let lines = string.slice(0, ptr).split(/\r?\n/);
|
|
1445
1353
|
return [lines.length, lines.pop().length + 1];
|
|
1446
1354
|
}
|
|
1447
1355
|
function makeCodeBlock(string, line, column) {
|
|
1448
|
-
let lines = string.split(/\r
|
|
1356
|
+
let lines = string.split(/\r?\n/);
|
|
1449
1357
|
let codeblock = "";
|
|
1450
1358
|
let numberLen = (Math.log10(line + 1) | 0) + 1;
|
|
1451
1359
|
for (let i = line - 1; i <= line + 1; i++) {
|
|
@@ -1463,7 +1371,7 @@ function makeCodeBlock(string, line, column) {
|
|
|
1463
1371
|
}
|
|
1464
1372
|
return codeblock;
|
|
1465
1373
|
}
|
|
1466
|
-
var TomlError = class extends Error {
|
|
1374
|
+
var TomlError = class _TomlError extends Error {
|
|
1467
1375
|
line;
|
|
1468
1376
|
column;
|
|
1469
1377
|
codeblock;
|
|
@@ -1477,69 +1385,15 @@ ${codeblock}`, options);
|
|
|
1477
1385
|
this.column = column;
|
|
1478
1386
|
this.codeblock = codeblock;
|
|
1479
1387
|
}
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
function indexOfNewline(str, start = 0) {
|
|
1484
|
-
let idx = str.indexOf("\n", start);
|
|
1485
|
-
if (str.charCodeAt(idx - 1) === 13)
|
|
1486
|
-
idx--;
|
|
1487
|
-
return idx;
|
|
1488
|
-
}
|
|
1489
|
-
function skipComment(ctx) {
|
|
1490
|
-
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
1491
|
-
let c = ctx.s.charCodeAt(ctx.p);
|
|
1492
|
-
if (c === 10)
|
|
1493
|
-
break;
|
|
1494
|
-
if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
|
|
1495
|
-
ctx.p++;
|
|
1496
|
-
break;
|
|
1497
|
-
}
|
|
1498
|
-
if (c < 32 && c !== 9 || c === 127) {
|
|
1499
|
-
throw new TomlError("control characters are not allowed in comments", {
|
|
1500
|
-
toml: ctx.s,
|
|
1501
|
-
ptr: ctx.p
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
function skipVoid(ctx, banNewLines, banComments) {
|
|
1507
|
-
let c;
|
|
1508
|
-
while (1) {
|
|
1509
|
-
while ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10))
|
|
1510
|
-
ctx.p++;
|
|
1511
|
-
if (banComments || c !== 35)
|
|
1512
|
-
break;
|
|
1513
|
-
skipComment(ctx);
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
function skipUntil(ctx, sep2, end) {
|
|
1517
|
-
let ptr = ctx.p;
|
|
1518
|
-
if (!end) {
|
|
1519
|
-
ptr = indexOfNewline(ctx.s, ptr);
|
|
1520
|
-
ctx.p = ptr < 0 ? ctx.s.length : ptr;
|
|
1521
|
-
return;
|
|
1522
|
-
}
|
|
1523
|
-
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
1524
|
-
let c = ctx.s.charCodeAt(ctx.p);
|
|
1525
|
-
if (c === 35) {
|
|
1526
|
-
skipComment(ctx);
|
|
1527
|
-
} else if (c === end || c === sep2) {
|
|
1528
|
-
return;
|
|
1529
|
-
}
|
|
1388
|
+
/** @internal */
|
|
1389
|
+
static x(message, ctx, ptr) {
|
|
1390
|
+
throw new _TomlError(message, { toml: ctx.s, ptr: ptr ?? ctx.p });
|
|
1530
1391
|
}
|
|
1531
|
-
|
|
1532
|
-
toml: ctx.s,
|
|
1533
|
-
ptr
|
|
1534
|
-
});
|
|
1535
|
-
}
|
|
1392
|
+
};
|
|
1536
1393
|
|
|
1537
1394
|
// node_modules/smol-toml/dist/primitive.js
|
|
1538
|
-
var INT_REGEX = /^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/;
|
|
1539
|
-
var FLOAT_REGEX = /^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/;
|
|
1540
|
-
var LEADING_ZERO = /^[+-]?0[0-9_]/;
|
|
1541
1395
|
function parseString(ctx) {
|
|
1542
|
-
let
|
|
1396
|
+
let startPtr = ctx.p;
|
|
1543
1397
|
let c = ctx.s.charCodeAt(ctx.p++);
|
|
1544
1398
|
let first = c;
|
|
1545
1399
|
let isLiteral = c === 39;
|
|
@@ -1558,10 +1412,7 @@ function parseString(ctx) {
|
|
|
1558
1412
|
if (isMultiline && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)) {
|
|
1559
1413
|
state = state && 3;
|
|
1560
1414
|
} else if (c < 32 && c !== 9 || c === 127) {
|
|
1561
|
-
|
|
1562
|
-
toml: ctx.s,
|
|
1563
|
-
ptr: ctx.p
|
|
1564
|
-
});
|
|
1415
|
+
TomlError.x("control characters are not allowed in strings", ctx);
|
|
1565
1416
|
} else if ((!state || state === 3) && c === first && (!isMultiline || ctx.s.charCodeAt(ctx.p + 1) === first && ctx.s.charCodeAt(ctx.p + 2) === first)) {
|
|
1566
1417
|
if (isMultiline) {
|
|
1567
1418
|
if (ctx.s.charCodeAt(ctx.p + 3) === first)
|
|
@@ -1569,8 +1420,10 @@ function parseString(ctx) {
|
|
|
1569
1420
|
if (ctx.s.charCodeAt(ctx.p + 3) === first)
|
|
1570
1421
|
ctx.p++;
|
|
1571
1422
|
}
|
|
1572
|
-
if (!state)
|
|
1573
|
-
|
|
1423
|
+
if (!state) {
|
|
1424
|
+
let s = ctx.s.slice(sliceStart, ctx.p);
|
|
1425
|
+
parsed = parsed ? parsed + s : s;
|
|
1426
|
+
}
|
|
1574
1427
|
ctx.p += isMultiline ? 3 : 1;
|
|
1575
1428
|
return parsed;
|
|
1576
1429
|
} else if (!state) {
|
|
@@ -1580,10 +1433,11 @@ function parseString(ctx) {
|
|
|
1580
1433
|
}
|
|
1581
1434
|
} else if (state === 1) {
|
|
1582
1435
|
if (c === 120 || c === 117 || c === 85) {
|
|
1436
|
+
let errPtr = ctx.p++ - 1;
|
|
1583
1437
|
let value = 0;
|
|
1584
1438
|
let len = c === 120 ? 2 : c === 117 ? 4 : 8;
|
|
1585
1439
|
for (let j = 0; j < len; j++, ctx.p++) {
|
|
1586
|
-
let hex = ctx.s.charCodeAt(ctx.p
|
|
1440
|
+
let hex = ctx.s.charCodeAt(ctx.p);
|
|
1587
1441
|
let digit = (
|
|
1588
1442
|
/* 0-9 */
|
|
1589
1443
|
hex >= 48 && hex <= 57 ? hex - 48 : (
|
|
@@ -1595,16 +1449,16 @@ function parseString(ctx) {
|
|
|
1595
1449
|
)
|
|
1596
1450
|
);
|
|
1597
1451
|
if (digit < 0)
|
|
1598
|
-
|
|
1452
|
+
TomlError.x("invalid non-hex character in unicode escape", ctx);
|
|
1599
1453
|
value = value << 4 | digit;
|
|
1600
1454
|
}
|
|
1601
1455
|
if (value < 0 || value > 1114111 || value >= 55296 && value <= 57343) {
|
|
1602
|
-
|
|
1456
|
+
TomlError.x("invalid unicode escape", ctx, errPtr);
|
|
1603
1457
|
}
|
|
1604
1458
|
parsed += String.fromCodePoint(value);
|
|
1605
|
-
sliceStart = ctx.p
|
|
1459
|
+
sliceStart = ctx.p--;
|
|
1606
1460
|
state = 0;
|
|
1607
|
-
} else if (c === 32 || c === 9) {
|
|
1461
|
+
} else if (isMultiline && (c === 32 || c === 9)) {
|
|
1608
1462
|
state = 2;
|
|
1609
1463
|
} else {
|
|
1610
1464
|
if (c === 98)
|
|
@@ -1624,84 +1478,150 @@ function parseString(ctx) {
|
|
|
1624
1478
|
else if (c === 92)
|
|
1625
1479
|
parsed += "\\";
|
|
1626
1480
|
else
|
|
1627
|
-
|
|
1481
|
+
TomlError.x("unrecognised escape sequence", ctx);
|
|
1628
1482
|
sliceStart = ctx.p + 1;
|
|
1629
1483
|
state = 0;
|
|
1630
1484
|
}
|
|
1631
1485
|
} else if (c !== 32 && c !== 9) {
|
|
1632
|
-
if (state === 2)
|
|
1633
|
-
|
|
1634
|
-
toml: ctx.s,
|
|
1635
|
-
ptr: sliceStart
|
|
1636
|
-
});
|
|
1637
|
-
}
|
|
1486
|
+
if (state === 2)
|
|
1487
|
+
TomlError.x("invalid escape: only line-ending whitespace may be escaped", ctx, sliceStart);
|
|
1638
1488
|
state = !isLiteral && c === 92 ? 1 : 0;
|
|
1639
1489
|
sliceStart = ctx.p;
|
|
1640
1490
|
}
|
|
1641
1491
|
}
|
|
1642
|
-
|
|
1643
|
-
}
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1492
|
+
TomlError.x("unfinished string", ctx, startPtr);
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
// node_modules/smol-toml/dist/date.js
|
|
1496
|
+
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
|
|
1497
|
+
var TomlDate = class _TomlDate extends Date {
|
|
1498
|
+
#hasDate = false;
|
|
1499
|
+
#hasTime = false;
|
|
1500
|
+
#offset = null;
|
|
1501
|
+
constructor(date, fasttype, unsafeDelim) {
|
|
1502
|
+
let hasDate = true;
|
|
1503
|
+
let hasTime = true;
|
|
1504
|
+
let offset = "Z";
|
|
1505
|
+
let c;
|
|
1506
|
+
if (typeof date === "string") {
|
|
1507
|
+
if (fasttype)
|
|
1508
|
+
prep: {
|
|
1509
|
+
if (fasttype < 3) {
|
|
1510
|
+
if (+date.slice(11, 13) > 23) {
|
|
1511
|
+
date = "";
|
|
1512
|
+
break prep;
|
|
1513
|
+
}
|
|
1514
|
+
if (fasttype === 2) {
|
|
1515
|
+
offset = null;
|
|
1516
|
+
date += "Z";
|
|
1517
|
+
} else if ((c = date.charCodeAt(date.length - 1)) !== 90 && c !== 122) {
|
|
1518
|
+
offset = date.slice(date.length - 6);
|
|
1519
|
+
}
|
|
1520
|
+
if (unsafeDelim)
|
|
1521
|
+
date = date.slice(0, 10) + "T" + date.slice(11);
|
|
1522
|
+
} else if (fasttype === 4) {
|
|
1523
|
+
date = +date.slice(0, 2) > 23 ? "" : `0000-01-01T${date}Z`;
|
|
1524
|
+
}
|
|
1525
|
+
hasDate = fasttype !== 4;
|
|
1526
|
+
hasTime = fasttype !== 3;
|
|
1527
|
+
}
|
|
1528
|
+
else {
|
|
1529
|
+
let match = date.match(DATE_TIME_RE);
|
|
1530
|
+
if (match) {
|
|
1531
|
+
if (!match[1]) {
|
|
1532
|
+
hasDate = false;
|
|
1533
|
+
date = `0000-01-01T${date}`;
|
|
1534
|
+
}
|
|
1535
|
+
hasTime = !!match[2];
|
|
1536
|
+
hasTime && date[10] === " " && (date = date.replace(" ", "T"));
|
|
1537
|
+
if (match[2] && +match[2] > 23) {
|
|
1538
|
+
date = "";
|
|
1539
|
+
} else {
|
|
1540
|
+
offset = match[3] || null;
|
|
1541
|
+
if (!offset && hasTime)
|
|
1542
|
+
date += "Z";
|
|
1543
|
+
}
|
|
1544
|
+
} else {
|
|
1545
|
+
date = "";
|
|
1546
|
+
}
|
|
1681
1547
|
}
|
|
1682
|
-
if (isInt || integersAsBigInt === true)
|
|
1683
|
-
numeric = BigInt(value);
|
|
1684
1548
|
}
|
|
1685
|
-
|
|
1549
|
+
super(date);
|
|
1550
|
+
if (!isNaN(this.getTime())) {
|
|
1551
|
+
this.#hasDate = hasDate;
|
|
1552
|
+
this.#hasTime = hasTime;
|
|
1553
|
+
this.#offset = offset;
|
|
1554
|
+
}
|
|
1686
1555
|
}
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1556
|
+
isDateTime() {
|
|
1557
|
+
return this.#hasDate && this.#hasTime;
|
|
1558
|
+
}
|
|
1559
|
+
isLocal() {
|
|
1560
|
+
return !this.#hasDate || !this.#hasTime || !this.#offset;
|
|
1561
|
+
}
|
|
1562
|
+
isDate() {
|
|
1563
|
+
return this.#hasDate && !this.#hasTime;
|
|
1564
|
+
}
|
|
1565
|
+
isTime() {
|
|
1566
|
+
return this.#hasTime && !this.#hasDate;
|
|
1567
|
+
}
|
|
1568
|
+
isValid() {
|
|
1569
|
+
return this.#hasDate || this.#hasTime;
|
|
1570
|
+
}
|
|
1571
|
+
toISOString() {
|
|
1572
|
+
let iso = super.toISOString();
|
|
1573
|
+
if (this.isDate())
|
|
1574
|
+
return iso.slice(0, 10);
|
|
1575
|
+
if (this.isTime())
|
|
1576
|
+
return iso.slice(11, 23);
|
|
1577
|
+
if (this.#offset === null)
|
|
1578
|
+
return iso.slice(0, -1);
|
|
1579
|
+
if (this.#offset === "Z" || this.#offset === "z")
|
|
1580
|
+
return iso;
|
|
1581
|
+
let offset = +this.#offset.slice(1, 3) * 60 + +this.#offset.slice(4, 6);
|
|
1582
|
+
offset = this.#offset[0] === "-" ? offset : -offset;
|
|
1583
|
+
let offsetDate = new Date(this.getTime() - offset * 6e4);
|
|
1584
|
+
return offsetDate.toISOString().slice(0, -1) + this.#offset;
|
|
1585
|
+
}
|
|
1586
|
+
static wrapAsOffsetDateTime(jsDate, offset = "Z") {
|
|
1587
|
+
let date = new _TomlDate(jsDate);
|
|
1588
|
+
date.#offset = offset;
|
|
1589
|
+
return date;
|
|
1590
|
+
}
|
|
1591
|
+
static wrapAsLocalDateTime(jsDate) {
|
|
1592
|
+
let date = new _TomlDate(jsDate);
|
|
1593
|
+
date.#offset = null;
|
|
1594
|
+
return date;
|
|
1595
|
+
}
|
|
1596
|
+
static wrapAsLocalDate(jsDate) {
|
|
1597
|
+
let date = new _TomlDate(jsDate);
|
|
1598
|
+
date.#hasTime = false;
|
|
1599
|
+
date.#offset = null;
|
|
1600
|
+
return date;
|
|
1601
|
+
}
|
|
1602
|
+
static wrapAsLocalTime(jsDate) {
|
|
1603
|
+
let date = new _TomlDate(jsDate);
|
|
1604
|
+
date.#hasDate = false;
|
|
1605
|
+
date.#offset = null;
|
|
1606
|
+
return date;
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1692
1609
|
|
|
1693
1610
|
// node_modules/smol-toml/dist/extract.js
|
|
1694
|
-
function
|
|
1695
|
-
|
|
1696
|
-
|
|
1611
|
+
function isDigit2(char, base = 10) {
|
|
1612
|
+
return base === 16 ? char > 47 && char < 58 || char > 64 && char < 71 || char > 96 && char < 103 : char > 47 && char < 48 + base;
|
|
1613
|
+
}
|
|
1614
|
+
function isEndOfValue(char, delim) {
|
|
1615
|
+
return char === 32 || char === 9 || char === 10 || char === 13 || // Structure end or next value delimiter
|
|
1616
|
+
delim && (char === delim || char === 44) || // Comment
|
|
1617
|
+
char === 35;
|
|
1618
|
+
}
|
|
1619
|
+
function extractValue(ctx, end) {
|
|
1620
|
+
let errPtr = ctx.p;
|
|
1621
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
1697
1622
|
if (c === 91 || c === 123) {
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
toml: ctx.s,
|
|
1701
|
-
ptr
|
|
1702
|
-
});
|
|
1703
|
-
}
|
|
1704
|
-
let value = c === 91 ? parseArray(ctx, integersAsBigInt) : parseInlineTable(ctx, integersAsBigInt);
|
|
1623
|
+
ctx.d-- || TomlError.x("document contains excessively nested structures. aborting.", ctx);
|
|
1624
|
+
let value = c === 91 ? parseArray(ctx) : parseInlineTable(ctx);
|
|
1705
1625
|
ctx.d++;
|
|
1706
1626
|
return value;
|
|
1707
1627
|
}
|
|
@@ -1710,163 +1630,336 @@ function extractValue(ctx, end, integersAsBigInt) {
|
|
|
1710
1630
|
}
|
|
1711
1631
|
if (c === 116) {
|
|
1712
1632
|
if (ctx.s.charCodeAt(++ctx.p) !== 114 || ctx.s.charCodeAt(++ctx.p) !== 117 || ctx.s.charCodeAt(++ctx.p) !== 101)
|
|
1713
|
-
|
|
1714
|
-
ctx.p
|
|
1715
|
-
return true;
|
|
1633
|
+
TomlError.x("invalid value", ctx, errPtr);
|
|
1634
|
+
return ctx.p++, true;
|
|
1716
1635
|
}
|
|
1717
1636
|
if (c === 102) {
|
|
1718
1637
|
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 108 || ctx.s.charCodeAt(++ctx.p) !== 115 || ctx.s.charCodeAt(++ctx.p) !== 101)
|
|
1719
|
-
|
|
1720
|
-
ctx.p
|
|
1721
|
-
|
|
1638
|
+
TomlError.x("invalid value", ctx, errPtr);
|
|
1639
|
+
return ctx.p++, false;
|
|
1640
|
+
}
|
|
1641
|
+
if (c === 43 || c === 45) {
|
|
1642
|
+
return parseNumber(ctx, ctx.p, ctx.s.charCodeAt(++ctx.p), 44 - c, end);
|
|
1722
1643
|
}
|
|
1723
|
-
|
|
1644
|
+
if (ctx.s.charCodeAt(ctx.p + 4) === 45 && ctx.s.charCodeAt(ctx.p + 7) === 45) {
|
|
1645
|
+
return parseDate(ctx, c, end);
|
|
1646
|
+
}
|
|
1647
|
+
if (ctx.s.charCodeAt(ctx.p + 2) === 58) {
|
|
1648
|
+
return parseTime(ctx, c, end);
|
|
1649
|
+
}
|
|
1650
|
+
return parseNumber(ctx, ctx.p, c, 0, end);
|
|
1724
1651
|
}
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1652
|
+
function parseNumber(ctx, startPtr, startChr, sign, endChr) {
|
|
1653
|
+
let c = startChr;
|
|
1654
|
+
let state = 0;
|
|
1655
|
+
let hasUnderscores = false;
|
|
1656
|
+
if (c === 105) {
|
|
1657
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 110 || ctx.s.charCodeAt(++ctx.p) !== 102)
|
|
1658
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
1659
|
+
return ctx.p++, (sign || 1) / 0;
|
|
1660
|
+
}
|
|
1661
|
+
if (c === 110) {
|
|
1662
|
+
if (ctx.s.charCodeAt(++ctx.p) !== 97 || ctx.s.charCodeAt(++ctx.p) !== 110)
|
|
1663
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
1664
|
+
return ctx.p++, NaN;
|
|
1665
|
+
}
|
|
1666
|
+
if (c === 48) {
|
|
1667
|
+
if (++ctx.p >= ctx.s.length || isEndOfValue(c = ctx.s.charCodeAt(ctx.p), endChr))
|
|
1668
|
+
return ctx.bi === true ? 0n : 0;
|
|
1669
|
+
if (!sign) {
|
|
1670
|
+
if (c === 120)
|
|
1671
|
+
return parseIntegerBaseN(ctx, startPtr, 16, endChr);
|
|
1672
|
+
else if (c === 98)
|
|
1673
|
+
return parseIntegerBaseN(ctx, startPtr, 2, endChr);
|
|
1674
|
+
else if (c === 111)
|
|
1675
|
+
return parseIntegerBaseN(ctx, startPtr, 8, endChr);
|
|
1676
|
+
}
|
|
1677
|
+
if (c === 46)
|
|
1678
|
+
state = 2;
|
|
1679
|
+
else if (c === 101 || c === 69)
|
|
1680
|
+
state = 4;
|
|
1681
|
+
else
|
|
1682
|
+
TomlError.x("illegal leading zero", ctx, startPtr);
|
|
1683
|
+
} else if (!isDigit2(c))
|
|
1684
|
+
TomlError.x("invalid value", ctx, startPtr);
|
|
1685
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
1686
|
+
if (!state)
|
|
1687
|
+
state = 1;
|
|
1688
|
+
if (c === 95) {
|
|
1689
|
+
if (!(state & 1))
|
|
1690
|
+
TomlError.x("illegal underscore", ctx);
|
|
1691
|
+
state += 11;
|
|
1692
|
+
hasUnderscores = true;
|
|
1693
|
+
} else if (state === 1 && c === 46)
|
|
1694
|
+
state = 2;
|
|
1695
|
+
else if ((state === 1 || state === 3) && (c === 101 || c === 69))
|
|
1696
|
+
state = 4;
|
|
1697
|
+
else if (state === 4 && (c === 43 || c === 45)) {
|
|
1698
|
+
} else if (!isDigit2(c))
|
|
1699
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
1700
|
+
else if (state > 9)
|
|
1701
|
+
state -= 11;
|
|
1702
|
+
else if (!(state & 1))
|
|
1703
|
+
state++;
|
|
1704
|
+
}
|
|
1705
|
+
if (!state) {
|
|
1706
|
+
let val = (startChr - 48) * (sign || 1);
|
|
1707
|
+
return ctx.bi === true ? BigInt(val) : val;
|
|
1708
|
+
}
|
|
1709
|
+
if (!(state & 1))
|
|
1710
|
+
TomlError.x("unfinished numeric value", ctx, startPtr);
|
|
1711
|
+
let str = ctx.s.slice(startPtr, ctx.p);
|
|
1712
|
+
if (hasUnderscores)
|
|
1713
|
+
str = str.replaceAll("_", "");
|
|
1714
|
+
return state > 1 ? parseFloat(str) : parseInteger(ctx, str, 10, startPtr);
|
|
1715
|
+
}
|
|
1716
|
+
function parseIntegerBaseN(ctx, startPtr, base, endChr) {
|
|
1717
|
+
let c, underscore = 1;
|
|
1718
|
+
while (++ctx.p < ctx.s.length && (c = ctx.s.charCodeAt(ctx.p), !isEndOfValue(c, endChr))) {
|
|
1719
|
+
if (c === 95) {
|
|
1720
|
+
if (underscore & 1)
|
|
1721
|
+
TomlError.x("illegal underscore", ctx);
|
|
1722
|
+
underscore = 3;
|
|
1723
|
+
} else if (!isDigit2(c, base))
|
|
1724
|
+
TomlError.x(`illegal character in numeric literal`, ctx);
|
|
1725
|
+
else if (underscore & 1)
|
|
1726
|
+
underscore--;
|
|
1727
|
+
}
|
|
1728
|
+
if (underscore & 1)
|
|
1729
|
+
TomlError.x("unfinished numeric value", ctx);
|
|
1730
|
+
let str = ctx.s.slice(startPtr + 2, ctx.p);
|
|
1731
|
+
if (underscore)
|
|
1732
|
+
str = str.replaceAll("_", "");
|
|
1733
|
+
return parseInteger(ctx, str, base, startPtr);
|
|
1734
|
+
}
|
|
1735
|
+
function parseInteger(ctx, str, base, startPtr) {
|
|
1736
|
+
if (ctx.bi !== true)
|
|
1737
|
+
int: {
|
|
1738
|
+
let val = parseInt(str, base);
|
|
1739
|
+
if (!Number.isSafeInteger(val)) {
|
|
1740
|
+
if (ctx.bi)
|
|
1741
|
+
break int;
|
|
1742
|
+
TomlError.x("integer value cannot be represented losslessly", ctx, startPtr);
|
|
1743
|
+
}
|
|
1744
|
+
return val;
|
|
1745
|
+
}
|
|
1746
|
+
return base === 10 ? BigInt(str) : BigInt((base === 2 ? "0b" : base === 8 ? "0o" : "0x") + str);
|
|
1747
|
+
}
|
|
1748
|
+
function parseDate(ctx, c, endChr) {
|
|
1749
|
+
let startPtr = ctx.p++, unsafeSeparator;
|
|
1750
|
+
if (!isDigit2(c) || !isDigit2(ctx.s.charCodeAt(ctx.p++)) || !isDigit2(ctx.s.charCodeAt(ctx.p++)) || !isDigit2(ctx.s.charCodeAt(ctx.p++))) {
|
|
1751
|
+
return parseNumber(ctx, ctx.p = startPtr, c, 0, endChr);
|
|
1752
|
+
}
|
|
1753
|
+
ctx.p += 5;
|
|
1754
|
+
if (!isDigit2(ctx.s.charCodeAt(ctx.p++)))
|
|
1755
|
+
TomlError.x("invalid date-time: date part is malformed", ctx, startPtr);
|
|
1756
|
+
if (ctx.p >= ctx.s.length || ((c = ctx.s.charCodeAt(ctx.p)) !== 32 || (unsafeSeparator = true, !isDigit2(ctx.s.charCodeAt(ctx.p + 1)))) && c !== 84 && c !== 116) {
|
|
1757
|
+
let t2 = ctx.s.slice(startPtr, ctx.p);
|
|
1758
|
+
return readDate(ctx, t2, 3, false, startPtr);
|
|
1759
|
+
}
|
|
1760
|
+
if (ctx.s.charCodeAt(ctx.p += 3) !== 58)
|
|
1761
|
+
TomlError.x("invalid date-time: time part is malformed", ctx, startPtr);
|
|
1762
|
+
if (ctx.s.charCodeAt(ctx.p += 3) === 58)
|
|
1763
|
+
ctx.p += 3;
|
|
1764
|
+
if (ctx.s.charCodeAt(ctx.p) === 46)
|
|
1765
|
+
while (isDigit2(ctx.s.charCodeAt(++ctx.p)))
|
|
1766
|
+
;
|
|
1767
|
+
if (c = ctx.s.charCodeAt(ctx.p)) {
|
|
1768
|
+
if (c === 90 || c === 122) {
|
|
1769
|
+
let t2 = ctx.s.slice(startPtr, ++ctx.p);
|
|
1770
|
+
return readDate(ctx, t2, 1, unsafeSeparator, startPtr, "[+00:00]");
|
|
1771
|
+
}
|
|
1772
|
+
if (c === 43 || c === 45) {
|
|
1773
|
+
let t2 = ctx.s.slice(startPtr, ctx.p += 6);
|
|
1774
|
+
return readDate(ctx, t2, 1, unsafeSeparator, startPtr, !ctx.ld && "[" + ctx.s.slice(ctx.p - 6, ctx.p) + "]");
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
let t = ctx.s.slice(startPtr, ctx.p);
|
|
1778
|
+
return readDate(ctx, t, 2, unsafeSeparator, startPtr);
|
|
1779
|
+
}
|
|
1780
|
+
function parseTime(ctx, c, endChr) {
|
|
1729
1781
|
let start = ctx.p;
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
let endPtr = ctx.s.indexOf(end, start);
|
|
1733
|
-
if (endPtr < 0) {
|
|
1734
|
-
throw new TomlError("incomplete key-value: cannot find end of key", {
|
|
1735
|
-
toml: ctx.s,
|
|
1736
|
-
ptr: start
|
|
1737
|
-
});
|
|
1782
|
+
if (!isDigit2(c) || !isDigit2(ctx.s.charCodeAt(++ctx.p))) {
|
|
1783
|
+
return parseNumber(ctx, --ctx.p, c, 0, endChr);
|
|
1738
1784
|
}
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
endPtr = ctx.s.indexOf(end, ctx.p);
|
|
1767
|
-
if (endPtr < 0) {
|
|
1768
|
-
throw new TomlError("incomplete key-value: cannot find end of key", {
|
|
1769
|
-
toml: ctx.s,
|
|
1770
|
-
ptr: start
|
|
1771
|
-
});
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
parsed.push(part);
|
|
1775
|
-
} else {
|
|
1776
|
-
dot = ctx.s.indexOf(".", ctx.p);
|
|
1777
|
-
let part = ctx.s.slice(ctx.p, dot < 0 || dot > endPtr ? endPtr : dot);
|
|
1778
|
-
if (!KEY_PART_RE.test(part)) {
|
|
1779
|
-
throw new TomlError("only letter, numbers, dashes and underscores are allowed in keys", {
|
|
1780
|
-
toml: ctx.s,
|
|
1781
|
-
ptr: ctx.p
|
|
1782
|
-
});
|
|
1783
|
-
}
|
|
1784
|
-
parsed.push(part.trimEnd());
|
|
1785
|
-
}
|
|
1785
|
+
if (ctx.s.charCodeAt(ctx.p += 4) === 58)
|
|
1786
|
+
ctx.p += 3;
|
|
1787
|
+
if (ctx.s.charCodeAt(ctx.p) === 46)
|
|
1788
|
+
while (isDigit2(ctx.s.charCodeAt(++ctx.p)))
|
|
1789
|
+
;
|
|
1790
|
+
let t = ctx.s.slice(start, ctx.p);
|
|
1791
|
+
return readDate(ctx, t, 4, false, start);
|
|
1792
|
+
}
|
|
1793
|
+
function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
|
|
1794
|
+
if (ctx.ld) {
|
|
1795
|
+
let date = new TomlDate(str, type, unsafeDelim);
|
|
1796
|
+
if (!date.isValid())
|
|
1797
|
+
TomlError.x("invalid date", ctx, errPtr);
|
|
1798
|
+
return date;
|
|
1799
|
+
}
|
|
1800
|
+
try {
|
|
1801
|
+
if (temporalSuffix)
|
|
1802
|
+
str += temporalSuffix;
|
|
1803
|
+
switch (type) {
|
|
1804
|
+
case 1:
|
|
1805
|
+
return Temporal.ZonedDateTime.from(str);
|
|
1806
|
+
case 2:
|
|
1807
|
+
return Temporal.PlainDateTime.from(str);
|
|
1808
|
+
case 3:
|
|
1809
|
+
return Temporal.PlainDate.from(str);
|
|
1810
|
+
case 4:
|
|
1811
|
+
return Temporal.PlainTime.from(str);
|
|
1786
1812
|
}
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
return parsed;
|
|
1813
|
+
} catch (e) {
|
|
1814
|
+
TomlError.x(e instanceof Error ? e.message : "" + e, ctx, errPtr);
|
|
1815
|
+
}
|
|
1791
1816
|
}
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1817
|
+
|
|
1818
|
+
// node_modules/smol-toml/dist/util.js
|
|
1819
|
+
function skipComment(ctx) {
|
|
1820
|
+
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
1821
|
+
let c = ctx.s.charCodeAt(ctx.p);
|
|
1822
|
+
if (c === 10)
|
|
1823
|
+
break;
|
|
1824
|
+
if (c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10) {
|
|
1825
|
+
ctx.p++;
|
|
1826
|
+
break;
|
|
1827
|
+
}
|
|
1828
|
+
if (c < 32 && c !== 9 || c === 127) {
|
|
1829
|
+
TomlError.x("control characters are not allowed in comments", ctx);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
function skipVoid(ctx, banNewLines, banComments) {
|
|
1795
1834
|
let c;
|
|
1796
|
-
ctx.p++;
|
|
1797
1835
|
while (ctx.p < ctx.s.length) {
|
|
1798
|
-
|
|
1799
|
-
|
|
1836
|
+
while (ctx.p < ctx.s.length && ((c = ctx.s.charCodeAt(ctx.p)) === 32 || c === 9 || !banNewLines && (c === 10 || c === 13 && ctx.s.charCodeAt(ctx.p + 1) === 10)))
|
|
1837
|
+
ctx.p++;
|
|
1838
|
+
if (banComments || c !== 35)
|
|
1839
|
+
break;
|
|
1840
|
+
skipComment(ctx);
|
|
1841
|
+
}
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
// node_modules/smol-toml/dist/struct.js
|
|
1845
|
+
function parseKey(ctx, end = 61) {
|
|
1846
|
+
let startPtr;
|
|
1847
|
+
let state = 0;
|
|
1848
|
+
let parsed = [];
|
|
1849
|
+
let sliceStart;
|
|
1850
|
+
let c = ctx.s.charCodeAt(startPtr = ctx.p);
|
|
1851
|
+
do {
|
|
1852
|
+
if (c === end) {
|
|
1853
|
+
if (!state)
|
|
1854
|
+
TomlError.x("unexpected end of key", ctx);
|
|
1855
|
+
if (state === 1)
|
|
1856
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
1857
|
+
return ctx.p++, parsed;
|
|
1858
|
+
} else if (c === 46) {
|
|
1859
|
+
if (!state)
|
|
1860
|
+
TomlError.x("illegal empty bare key", ctx);
|
|
1861
|
+
if (state === 1)
|
|
1862
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
1863
|
+
state = 0;
|
|
1864
|
+
} else if (!state && (c === 34 || c === 39)) {
|
|
1865
|
+
if (c === ctx.s.charCodeAt(ctx.p + 1) && c === ctx.s.charCodeAt(ctx.p + 2))
|
|
1866
|
+
TomlError.x("illegal quoted key: multiline strings are not allowed", ctx);
|
|
1867
|
+
parsed.push(parseString(ctx));
|
|
1868
|
+
state = 2;
|
|
1869
|
+
ctx.p--;
|
|
1870
|
+
} else if (c === 32 || c === 9) {
|
|
1871
|
+
if (state === 1) {
|
|
1872
|
+
parsed.push(ctx.s.slice(sliceStart, ctx.p));
|
|
1873
|
+
state = 2;
|
|
1874
|
+
}
|
|
1875
|
+
} else if (state === 2 || c < 48 && c !== 45 || c > 57 && c < 65 || c > 90 && c < 97 && c !== 95 || c > 122) {
|
|
1876
|
+
TomlError.x("illegal character in key", ctx);
|
|
1877
|
+
} else if (!state) {
|
|
1878
|
+
state = 1;
|
|
1879
|
+
sliceStart = ctx.p;
|
|
1880
|
+
}
|
|
1881
|
+
} while (c = ctx.s.charCodeAt(++ctx.p));
|
|
1882
|
+
TomlError.x("incomplete key-value: cannot find end of key", ctx, startPtr);
|
|
1883
|
+
}
|
|
1884
|
+
function parseInlineTable(ctx) {
|
|
1885
|
+
let startPtr = ctx.p++;
|
|
1886
|
+
let res = /* @__PURE__ */ Object.create(null);
|
|
1887
|
+
let seen = /* @__PURE__ */ new Set();
|
|
1888
|
+
let c;
|
|
1889
|
+
while (ctx.p < ctx.s.length) {
|
|
1890
|
+
skipVoid(ctx);
|
|
1891
|
+
if ((c = ctx.s.charCodeAt(ctx.p)) === 125) {
|
|
1800
1892
|
ctx.p++;
|
|
1801
1893
|
return res;
|
|
1802
1894
|
}
|
|
1803
1895
|
let k;
|
|
1804
1896
|
let t = res;
|
|
1805
1897
|
let hasOwn = false;
|
|
1806
|
-
let
|
|
1898
|
+
let errPtr = ctx.p;
|
|
1807
1899
|
let key = parseKey(ctx);
|
|
1808
1900
|
for (let i = 0; i < key.length; i++) {
|
|
1809
1901
|
if (i)
|
|
1810
|
-
t = hasOwn ? t[k] : t[k] =
|
|
1902
|
+
t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
|
|
1811
1903
|
k = key[i];
|
|
1812
1904
|
if ((hasOwn = Object.hasOwn(t, k)) && (typeof t[k] !== "object" || seen.has(t[k]))) {
|
|
1813
|
-
|
|
1814
|
-
toml: ctx.s,
|
|
1815
|
-
ptr: p
|
|
1816
|
-
});
|
|
1905
|
+
TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
1817
1906
|
}
|
|
1818
|
-
|
|
1907
|
+
let unsafe = k === "__proto__";
|
|
1908
|
+
if (ctx.uk && (unsafe || k === "constructor")) {
|
|
1909
|
+
t = ctx.uk !== 1 && TomlError.x("document contains an unsafe property", ctx, errPtr);
|
|
1910
|
+
break;
|
|
1911
|
+
}
|
|
1912
|
+
if (!hasOwn && unsafe) {
|
|
1819
1913
|
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
|
|
1820
1914
|
}
|
|
1821
1915
|
}
|
|
1822
1916
|
if (hasOwn) {
|
|
1823
|
-
|
|
1824
|
-
toml: ctx.s,
|
|
1825
|
-
ptr: ctx.p
|
|
1826
|
-
});
|
|
1917
|
+
TomlError.x("trying to redefine an already defined value", ctx, errPtr);
|
|
1827
1918
|
}
|
|
1828
|
-
|
|
1829
|
-
|
|
1919
|
+
skipVoid(ctx, true, true);
|
|
1920
|
+
let value = extractValue(
|
|
1921
|
+
ctx,
|
|
1922
|
+
125
|
|
1923
|
+
/* } */
|
|
1924
|
+
);
|
|
1925
|
+
if (t && typeof (t[k] = value) === "object")
|
|
1926
|
+
seen.add(value);
|
|
1830
1927
|
skipVoid(ctx);
|
|
1831
1928
|
if ((c = ctx.s.charCodeAt(ctx.p++)) === 125) {
|
|
1832
1929
|
return res;
|
|
1833
1930
|
}
|
|
1834
|
-
if (c !== 44)
|
|
1835
|
-
|
|
1836
|
-
}
|
|
1931
|
+
if (c !== 44)
|
|
1932
|
+
TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
1837
1933
|
}
|
|
1838
|
-
|
|
1839
|
-
toml: ctx.s,
|
|
1840
|
-
ptr: ctx.p
|
|
1841
|
-
});
|
|
1934
|
+
TomlError.x("unfinished table", ctx, startPtr);
|
|
1842
1935
|
}
|
|
1843
|
-
function parseArray(ctx
|
|
1936
|
+
function parseArray(ctx) {
|
|
1937
|
+
let startPtr = ctx.p++;
|
|
1844
1938
|
let res = [];
|
|
1845
1939
|
let c;
|
|
1846
|
-
ctx.p++;
|
|
1847
1940
|
while (ctx.p < ctx.s.length) {
|
|
1848
1941
|
skipVoid(ctx);
|
|
1849
1942
|
if ((c = ctx.s.charCodeAt(ctx.p)) === 93) {
|
|
1850
1943
|
ctx.p++;
|
|
1851
1944
|
return res;
|
|
1852
1945
|
}
|
|
1853
|
-
res.push(extractValue(
|
|
1946
|
+
res.push(extractValue(
|
|
1947
|
+
ctx,
|
|
1948
|
+
93
|
|
1949
|
+
/* ] */
|
|
1950
|
+
));
|
|
1854
1951
|
skipVoid(ctx);
|
|
1855
1952
|
if ((c = ctx.s.charCodeAt(ctx.p++)) === 93) {
|
|
1856
1953
|
return res;
|
|
1857
1954
|
}
|
|
1858
|
-
if (c !== 44)
|
|
1859
|
-
|
|
1860
|
-
}
|
|
1955
|
+
if (c !== 44)
|
|
1956
|
+
TomlError.x("expected comma or end of structure", ctx, ctx.p - 1);
|
|
1861
1957
|
}
|
|
1862
|
-
|
|
1863
|
-
toml: ctx.s,
|
|
1864
|
-
ptr: ctx.p
|
|
1865
|
-
});
|
|
1958
|
+
TomlError.x("unfinished array", ctx, startPtr);
|
|
1866
1959
|
}
|
|
1867
1960
|
|
|
1868
1961
|
// node_modules/smol-toml/dist/parse.js
|
|
1869
|
-
function peekTable(key, table, meta, type) {
|
|
1962
|
+
function peekTable(ctx, key, table, meta, type) {
|
|
1870
1963
|
let t = table;
|
|
1871
1964
|
let m = meta;
|
|
1872
1965
|
let k;
|
|
@@ -1874,7 +1967,7 @@ function peekTable(key, table, meta, type) {
|
|
|
1874
1967
|
let state;
|
|
1875
1968
|
for (let i = 0; i < key.length; i++) {
|
|
1876
1969
|
if (i) {
|
|
1877
|
-
t = hasOwn ? t[k] : t[k] =
|
|
1970
|
+
t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
|
|
1878
1971
|
m = (state = m[k]).c;
|
|
1879
1972
|
if (type === 0 && (state.t === 1 || state.t === 2)) {
|
|
1880
1973
|
return null;
|
|
@@ -1890,7 +1983,10 @@ function peekTable(key, table, meta, type) {
|
|
|
1890
1983
|
return null;
|
|
1891
1984
|
}
|
|
1892
1985
|
if (!hasOwn) {
|
|
1893
|
-
|
|
1986
|
+
let unsafe = k === "__proto__";
|
|
1987
|
+
if (ctx.uk && (unsafe || k === "constructor"))
|
|
1988
|
+
return false;
|
|
1989
|
+
if (unsafe) {
|
|
1894
1990
|
Object.defineProperty(t, k, { enumerable: true, configurable: true, writable: true });
|
|
1895
1991
|
Object.defineProperty(m, k, { enumerable: true, configurable: true, writable: true });
|
|
1896
1992
|
}
|
|
@@ -1898,7 +1994,7 @@ function peekTable(key, table, meta, type) {
|
|
|
1898
1994
|
t: i < key.length - 1 && type === 2 ? 3 : type,
|
|
1899
1995
|
d: false,
|
|
1900
1996
|
i: 0,
|
|
1901
|
-
c:
|
|
1997
|
+
c: /* @__PURE__ */ Object.create(null)
|
|
1902
1998
|
};
|
|
1903
1999
|
}
|
|
1904
2000
|
}
|
|
@@ -1911,43 +2007,60 @@ function peekTable(key, table, meta, type) {
|
|
|
1911
2007
|
state.d = true;
|
|
1912
2008
|
t[k] = [];
|
|
1913
2009
|
}
|
|
1914
|
-
t[k].push(t =
|
|
1915
|
-
state.c[state.i++] = state = { t: 1, d: false, i: 0, c:
|
|
2010
|
+
t[k].push(t = /* @__PURE__ */ Object.create(null));
|
|
2011
|
+
state.c[state.i++] = state = { t: 1, d: false, i: 0, c: /* @__PURE__ */ Object.create(null) };
|
|
1916
2012
|
}
|
|
1917
2013
|
if (state.d) {
|
|
1918
2014
|
return null;
|
|
1919
2015
|
}
|
|
1920
2016
|
state.d = true;
|
|
1921
2017
|
if (type === 1) {
|
|
1922
|
-
t = hasOwn ? t[k] : t[k] =
|
|
2018
|
+
t = hasOwn ? t[k] : t[k] = /* @__PURE__ */ Object.create(null);
|
|
1923
2019
|
} else if (type === 0 && hasOwn) {
|
|
1924
2020
|
return null;
|
|
1925
2021
|
}
|
|
1926
2022
|
return [k, t, state.c];
|
|
1927
2023
|
}
|
|
1928
|
-
function
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
2024
|
+
function validateTablePeek(ctx, peek, ptr) {
|
|
2025
|
+
if (peek === null || ctx.uk === 2)
|
|
2026
|
+
TomlError.x(peek === null ? "trying to redefine an already defined table or value" : "document contains an unsafe property", ctx, ptr);
|
|
2027
|
+
}
|
|
2028
|
+
function parse2(toml, options = {}) {
|
|
2029
|
+
let ctx = {
|
|
2030
|
+
s: toml,
|
|
2031
|
+
p: 0,
|
|
2032
|
+
d: options.maxDepth ?? 1e3,
|
|
2033
|
+
bi: options.integersAsBigInt ?? false,
|
|
2034
|
+
ld: options.useLegacyDate ?? true,
|
|
2035
|
+
uk: options.unsafeKeyBehaviour === "throw" ? 2 : options.unsafeKeyBehaviour === "drop" ? 1 : 0
|
|
2036
|
+
};
|
|
2037
|
+
let res = /* @__PURE__ */ Object.create(null);
|
|
2038
|
+
let meta = /* @__PURE__ */ Object.create(null);
|
|
1932
2039
|
let tmp;
|
|
2040
|
+
let skipping = false;
|
|
1933
2041
|
let tbl = res;
|
|
1934
2042
|
let m = meta;
|
|
2043
|
+
if (toml.charCodeAt(0) === 65279)
|
|
2044
|
+
ctx.p++;
|
|
1935
2045
|
skipVoid(ctx);
|
|
1936
2046
|
while (ctx.p < toml.length) {
|
|
1937
2047
|
if (toml.charCodeAt(ctx.p) === 91) {
|
|
1938
2048
|
let isTableArray = toml.charCodeAt(++ctx.p) === 91;
|
|
1939
2049
|
tmp = ctx.p += +isTableArray;
|
|
1940
|
-
|
|
2050
|
+
skipping = false;
|
|
2051
|
+
let k = parseKey(
|
|
2052
|
+
ctx,
|
|
2053
|
+
93
|
|
2054
|
+
/* ] */
|
|
2055
|
+
);
|
|
1941
2056
|
if (isTableArray) {
|
|
1942
|
-
if (toml.charCodeAt(ctx.p
|
|
1943
|
-
|
|
1944
|
-
toml,
|
|
1945
|
-
ptr: ctx.p - 1
|
|
1946
|
-
});
|
|
2057
|
+
if (toml.charCodeAt(ctx.p) !== 93) {
|
|
2058
|
+
TomlError.x("expected end of table array declaration", ctx);
|
|
1947
2059
|
}
|
|
1948
2060
|
ctx.p++;
|
|
1949
2061
|
}
|
|
1950
2062
|
let p = peekTable(
|
|
2063
|
+
ctx,
|
|
1951
2064
|
k,
|
|
1952
2065
|
res,
|
|
1953
2066
|
meta,
|
|
@@ -1955,45 +2068,44 @@ function parse2(toml, { maxDepth = 1e3, integersAsBigInt } = {}) {
|
|
|
1955
2068
|
/* Type.EXPLICIT */
|
|
1956
2069
|
);
|
|
1957
2070
|
if (!p) {
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
2071
|
+
validateTablePeek(ctx, p, tmp);
|
|
2072
|
+
skipping = true;
|
|
2073
|
+
} else {
|
|
2074
|
+
m = p[2];
|
|
2075
|
+
tbl = p[1];
|
|
1962
2076
|
}
|
|
1963
|
-
m = p[2];
|
|
1964
|
-
tbl = p[1];
|
|
1965
2077
|
} else {
|
|
1966
2078
|
tmp = ctx.p;
|
|
1967
2079
|
let k = parseKey(ctx);
|
|
1968
2080
|
let p = peekTable(
|
|
2081
|
+
ctx,
|
|
1969
2082
|
k,
|
|
1970
2083
|
tbl,
|
|
1971
2084
|
m,
|
|
1972
2085
|
0
|
|
1973
2086
|
/* Type.DOTTED */
|
|
1974
2087
|
);
|
|
1975
|
-
if (!p)
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
p[1][p[0]] = extractValue(ctx, void 0, integersAsBigInt);
|
|
2088
|
+
if (!p && !skipping)
|
|
2089
|
+
validateTablePeek(ctx, p, tmp);
|
|
2090
|
+
skipVoid(ctx, true, true);
|
|
2091
|
+
let v = extractValue(ctx, void 0);
|
|
2092
|
+
if (p && !skipping)
|
|
2093
|
+
p[1][p[0]] = v;
|
|
1982
2094
|
}
|
|
1983
2095
|
skipVoid(ctx, true);
|
|
1984
|
-
if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && tmp !== 13) {
|
|
1985
|
-
|
|
1986
|
-
toml,
|
|
1987
|
-
ptr: ctx.p
|
|
1988
|
-
});
|
|
2096
|
+
if (ctx.p < toml.length && (tmp = toml.charCodeAt(ctx.p)) !== 10 && (tmp !== 13 || toml.charCodeAt(ctx.p + 1) !== 10)) {
|
|
2097
|
+
TomlError.x("each key-value declaration must be followed by an end-of-line", ctx);
|
|
1989
2098
|
}
|
|
1990
2099
|
skipVoid(ctx);
|
|
1991
2100
|
}
|
|
1992
2101
|
return res;
|
|
1993
2102
|
}
|
|
1994
2103
|
|
|
2104
|
+
// node_modules/smol-toml/dist/stringify.js
|
|
2105
|
+
var HAS_WELLFORMED = !!"".isWellFormed;
|
|
2106
|
+
|
|
1995
2107
|
// src/core/hook.ts
|
|
1996
|
-
import { existsSync as existsSync2
|
|
2108
|
+
import { existsSync as existsSync2 } from "fs";
|
|
1997
2109
|
|
|
1998
2110
|
// src/core/bank.ts
|
|
1999
2111
|
import { existsSync } from "fs";
|
|
@@ -2001,6 +2113,7 @@ import { homedir as homedir2 } from "os";
|
|
|
2001
2113
|
import { basename, dirname as dirname3, join as join4, normalize, sep } from "path";
|
|
2002
2114
|
|
|
2003
2115
|
// src/core/diag.ts
|
|
2116
|
+
import { readFileSync } from "fs";
|
|
2004
2117
|
import { join as join2 } from "path";
|
|
2005
2118
|
|
|
2006
2119
|
// src/core/log.ts
|
|
@@ -2059,11 +2172,11 @@ function diag(harness, event, extra = {}) {
|
|
|
2059
2172
|
}
|
|
2060
2173
|
|
|
2061
2174
|
// src/core/git-layout.ts
|
|
2062
|
-
import { lstatSync, readFileSync, realpathSync } from "fs";
|
|
2175
|
+
import { lstatSync, readFileSync as readFileSync2, realpathSync } from "fs";
|
|
2063
2176
|
import { dirname as dirname2, isAbsolute, join as join3, resolve } from "path";
|
|
2064
2177
|
|
|
2065
2178
|
// src/core/config.ts
|
|
2066
|
-
import { readFileSync as
|
|
2179
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
2067
2180
|
import { homedir as homedir3 } from "os";
|
|
2068
2181
|
import { join as join7 } from "path";
|
|
2069
2182
|
|
|
@@ -2103,11 +2216,24 @@ var PAGE_TAXONOMY = [
|
|
|
2103
2216
|
];
|
|
2104
2217
|
var PAGE_NAMES = PAGE_TAXONOMY.map((page) => page.name);
|
|
2105
2218
|
|
|
2219
|
+
// package.json
|
|
2220
|
+
var version = "0.8.1";
|
|
2221
|
+
|
|
2106
2222
|
// src/core/util.ts
|
|
2107
2223
|
import { accessSync, constants } from "fs";
|
|
2108
2224
|
import { delimiter, join as join6 } from "path";
|
|
2225
|
+
function isOurMcpEntry(entry) {
|
|
2226
|
+
if (!entry || typeof entry !== "object") return false;
|
|
2227
|
+
const candidate = entry;
|
|
2228
|
+
if (candidate.command !== "node" || !Array.isArray(candidate.args)) return false;
|
|
2229
|
+
const script = candidate.args[0];
|
|
2230
|
+
if (typeof script !== "string") return false;
|
|
2231
|
+
const parts = script.replaceAll("\\", "/").split("/").filter(Boolean);
|
|
2232
|
+
return parts.at(-1) === "mcp-server.js" && parts.at(-2) === "dist" && (parts.at(-3) === "coding-agents" || parts.at(-3) === "hindsight-coding-agents");
|
|
2233
|
+
}
|
|
2109
2234
|
|
|
2110
2235
|
// src/core/hindsight.ts
|
|
2236
|
+
var USER_AGENT = `hindsight-coding-agents/${version}`;
|
|
2111
2237
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
2112
2238
|
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
2113
2239
|
|
|
@@ -2130,12 +2256,12 @@ function brandWord() {
|
|
|
2130
2256
|
}
|
|
2131
2257
|
|
|
2132
2258
|
// src/core/session-cache.ts
|
|
2133
|
-
import { mkdirSync as mkdirSync2, readFileSync as
|
|
2259
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync4, renameSync as renameSync2, rmSync, writeFileSync } from "fs";
|
|
2134
2260
|
import { tmpdir } from "os";
|
|
2135
2261
|
import { dirname as dirname5, join as join8 } from "path";
|
|
2136
2262
|
|
|
2137
2263
|
// src/core/turn-journal.ts
|
|
2138
|
-
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as
|
|
2264
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync5, statSync as statSync2 } from "fs";
|
|
2139
2265
|
import { tmpdir as tmpdir2 } from "os";
|
|
2140
2266
|
import { dirname as dirname6, join as join9 } from "path";
|
|
2141
2267
|
|
|
@@ -2177,9 +2303,6 @@ function actionLine(tool, input) {
|
|
|
2177
2303
|
// src/core/turn-journal.ts
|
|
2178
2304
|
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
2179
2305
|
|
|
2180
|
-
// src/core/retain-hook.ts
|
|
2181
|
-
import { readFileSync as readFileSync7 } from "fs";
|
|
2182
|
-
|
|
2183
2306
|
// src/core/retain-cursor.ts
|
|
2184
2307
|
import { createHash as createHash2 } from "crypto";
|
|
2185
2308
|
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
@@ -2421,18 +2544,15 @@ function formatUsageReport(usage, path = usageFilePath()) {
|
|
|
2421
2544
|
return out.join("\n");
|
|
2422
2545
|
}
|
|
2423
2546
|
|
|
2424
|
-
// src/core/session-start.ts
|
|
2425
|
-
import { readFileSync as readFileSync11 } from "fs";
|
|
2426
|
-
|
|
2427
2547
|
// src/core/git.ts
|
|
2428
2548
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
2429
2549
|
import { resolve as resolve2 } from "path";
|
|
2430
2550
|
|
|
2431
2551
|
// src/core/status.ts
|
|
2432
|
-
import { execFileSync as
|
|
2552
|
+
import { execFileSync as execFileSync4 } from "child_process";
|
|
2433
2553
|
|
|
2434
2554
|
// src/core/survey.ts
|
|
2435
|
-
import { spawn as realSpawn4 } from "child_process";
|
|
2555
|
+
import { execFileSync as execFileSync3, spawn as realSpawn4 } from "child_process";
|
|
2436
2556
|
import { createHash as createHash4 } from "crypto";
|
|
2437
2557
|
import { existsSync as existsSync3 } from "fs";
|
|
2438
2558
|
import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
|
|
@@ -2461,7 +2581,7 @@ import { spawn as realSpawn5 } from "child_process";
|
|
|
2461
2581
|
import {
|
|
2462
2582
|
existsSync as existsSync4,
|
|
2463
2583
|
mkdirSync as mkdirSync5,
|
|
2464
|
-
readFileSync as
|
|
2584
|
+
readFileSync as readFileSync7,
|
|
2465
2585
|
realpathSync as realpathSync2,
|
|
2466
2586
|
unlinkSync as unlinkSync2,
|
|
2467
2587
|
writeFileSync as writeFileSync3
|
|
@@ -2475,12 +2595,14 @@ var NPM_VIEW_HARD_DEADLINE_MS = NPM_VIEW_TIMEOUT_MS + 1e3;
|
|
|
2475
2595
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
2476
2596
|
|
|
2477
2597
|
// src/core/skill-sync.ts
|
|
2478
|
-
import { cpSync, existsSync as
|
|
2598
|
+
import { cpSync, existsSync as existsSync6, readFileSync as readFileSync8 } from "fs";
|
|
2479
2599
|
import { homedir as homedir6 } from "os";
|
|
2480
|
-
import { dirname as dirname10, join as
|
|
2600
|
+
import { dirname as dirname10, join as join16 } from "path";
|
|
2481
2601
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
2482
2602
|
|
|
2483
2603
|
// src/core/skill-dirs.ts
|
|
2604
|
+
import { existsSync as existsSync5 } from "fs";
|
|
2605
|
+
import { join as join15 } from "path";
|
|
2484
2606
|
var SKILL_DIRS = {
|
|
2485
2607
|
"claude-code": [".claude", "skills"],
|
|
2486
2608
|
// Codex and dsh share the agentskills-standard root; uninstalling either removes the one copy.
|
|
@@ -2493,6 +2615,8 @@ var SKILL_DIRS = {
|
|
|
2493
2615
|
"cline-cli": [".cline", "data", "settings", "skills"],
|
|
2494
2616
|
"qwen-code": [".qwen", "skills"],
|
|
2495
2617
|
// Qwen's user-level skills root (Storage.getUserSkillsDirs)
|
|
2618
|
+
// Kimi Code's user-level skills root, alongside its config.toml and mcp.json.
|
|
2619
|
+
"kimi-code": [".kimi-code", "skills"],
|
|
2496
2620
|
"factory-droid": [".factory", "skills"],
|
|
2497
2621
|
// Droid's user-level skills root
|
|
2498
2622
|
// ZCode scans TWO user roots by default (its resolveDefaultSkillRoots): `~/.zcode/skills` and the
|
|
@@ -2500,23 +2624,45 @@ var SKILL_DIRS = {
|
|
|
2500
2624
|
// skill removal is by fixed directory name, so installing into the shared root would make
|
|
2501
2625
|
// `uninstall zcode` take Codex's and dsh's copy with it.
|
|
2502
2626
|
zcode: [".zcode", "skills"],
|
|
2627
|
+
// TraeCode's user-level skills root, resolved per edition by traecodeDotDir below — like ZCode's
|
|
2628
|
+
// its own, never the shared agentskills root other hosts install into.
|
|
2629
|
+
traecode: [".trae-cn", "skills"],
|
|
2503
2630
|
// The pi family reads the shared ~/.agents/skills too, but writes its OWN root: skill removal is
|
|
2504
2631
|
// by fixed directory name, so installing to the shared one would make `uninstall pi` take Codex's
|
|
2505
2632
|
// and dsh's copy with it.
|
|
2506
2633
|
pi: [".pi", "agent", "skills"],
|
|
2507
|
-
"prime-agent": [".prime", "agent", "skills"]
|
|
2634
|
+
"prime-agent": [".prime", "agent", "skills"],
|
|
2635
|
+
// WorkBuddy's own user-level skills root (the @genie/agent-cli engine reads ~/.workbuddy).
|
|
2636
|
+
workbuddy: [".workbuddy", "skills"],
|
|
2637
|
+
// CodeBuddy Code reads that SAME engine's default root, ~/.codebuddy — WorkBuddy only overrides
|
|
2638
|
+
// its home folder (product config `dataLayout.configDir.userDirName`), so the two differ by config.
|
|
2639
|
+
codebuddy: [".codebuddy", "skills"]
|
|
2640
|
+
};
|
|
2641
|
+
var TRAE_DOT_DIRS = [".trae-cn", ".trae"];
|
|
2642
|
+
var traecodeDotDirName = (home, exists = existsSync5) => {
|
|
2643
|
+
for (const dir of TRAE_DOT_DIRS) {
|
|
2644
|
+
if (exists(join15(home, dir))) return dir;
|
|
2645
|
+
}
|
|
2646
|
+
return ".trae-cn";
|
|
2647
|
+
};
|
|
2648
|
+
var resolveSkillDirs = (harness, home) => {
|
|
2649
|
+
const parts = SKILL_DIRS[harness];
|
|
2650
|
+
if (harness === "traecode" && parts) {
|
|
2651
|
+
return [traecodeDotDirName(home), ...parts.slice(1)];
|
|
2652
|
+
}
|
|
2653
|
+
return parts;
|
|
2508
2654
|
};
|
|
2509
2655
|
|
|
2510
2656
|
// src/core/legacy.ts
|
|
2511
|
-
import { existsSync as
|
|
2657
|
+
import { existsSync as existsSync7, readFileSync as readFileSync9 } from "fs";
|
|
2512
2658
|
import { homedir as homedir7 } from "os";
|
|
2513
|
-
import { join as
|
|
2659
|
+
import { join as join17, relative, isAbsolute as isAbsolute2 } from "path";
|
|
2514
2660
|
var LEGACY_CONFIG_FILES = {
|
|
2515
2661
|
"claude-code": "claude-code.json",
|
|
2516
2662
|
codex: "codex.json"
|
|
2517
2663
|
};
|
|
2518
2664
|
function legacyConfigPath(harness, home = homedir7()) {
|
|
2519
|
-
return
|
|
2665
|
+
return join17(home, ".hindsight", LEGACY_CONFIG_FILES[harness] ?? `${harness}.json`);
|
|
2520
2666
|
}
|
|
2521
2667
|
var CLOUD_URL = "https://api.hindsight.vectorize.io";
|
|
2522
2668
|
function readLegacyEndpoint(home = homedir7(), prefer = []) {
|
|
@@ -2531,10 +2677,10 @@ function readLegacyEndpoint(home = homedir7(), prefer = []) {
|
|
|
2531
2677
|
}
|
|
2532
2678
|
function readOne(harness, home) {
|
|
2533
2679
|
const source = legacyConfigPath(harness, home);
|
|
2534
|
-
if (!
|
|
2680
|
+
if (!existsSync7(source)) return void 0;
|
|
2535
2681
|
let raw;
|
|
2536
2682
|
try {
|
|
2537
|
-
raw = JSON.parse(
|
|
2683
|
+
raw = JSON.parse(readFileSync9(source, "utf8"));
|
|
2538
2684
|
} catch {
|
|
2539
2685
|
return void 0;
|
|
2540
2686
|
}
|
|
@@ -2560,6 +2706,311 @@ function readOne(harness, home) {
|
|
|
2560
2706
|
};
|
|
2561
2707
|
}
|
|
2562
2708
|
|
|
2709
|
+
// src/core/traecode-mcp.ts
|
|
2710
|
+
import { execFileSync as execFileSync5 } from "child_process";
|
|
2711
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync10, readdirSync as readdirSync2, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "fs";
|
|
2712
|
+
import { homedir as homedir8 } from "os";
|
|
2713
|
+
import { dirname as dirname11, isAbsolute as isAbsolute3, join as join18 } from "path";
|
|
2714
|
+
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
2715
|
+
var MCP_SERVER_NAME = "hindsight";
|
|
2716
|
+
var MCP_FILE_REL = join18(".trae", "mcp.json");
|
|
2717
|
+
function bundledDistDir() {
|
|
2718
|
+
const here = dirname11(fileURLToPath6(import.meta.url));
|
|
2719
|
+
return existsSync8(join18(here, "mcp-server.js")) ? here : join18(here, "..", "..", "dist");
|
|
2720
|
+
}
|
|
2721
|
+
function canon(value) {
|
|
2722
|
+
if (Array.isArray(value)) return `[${value.map(canon).join(",")}]`;
|
|
2723
|
+
if (value && typeof value === "object") {
|
|
2724
|
+
const entries = Object.entries(value).sort(
|
|
2725
|
+
([a], [b]) => a < b ? -1 : a > b ? 1 : 0
|
|
2726
|
+
);
|
|
2727
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canon(v)}`).join(",")}}`;
|
|
2728
|
+
}
|
|
2729
|
+
return JSON.stringify(value);
|
|
2730
|
+
}
|
|
2731
|
+
var WORKSPACE_MCP_KEY = "trae.mcp.enableWorkspaceMcp";
|
|
2732
|
+
var HINT_MIN_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
2733
|
+
function traecodeUserDataDir(home) {
|
|
2734
|
+
const root = process.platform === "darwin" ? join18(home, "Library", "Application Support") : process.platform === "win32" ? process.env.APPDATA ?? join18(home, "AppData", "Roaming") : process.env.XDG_CONFIG_HOME ?? join18(home, ".config");
|
|
2735
|
+
for (const brand of ["Trae CN", "Trae"]) {
|
|
2736
|
+
const dir = join18(root, brand);
|
|
2737
|
+
if (existsSync8(dir)) return dir;
|
|
2738
|
+
}
|
|
2739
|
+
return join18(root, "Trae CN");
|
|
2740
|
+
}
|
|
2741
|
+
var traecodeUserSettingsPath = (home) => join18(traecodeUserDataDir(home), "User", "settings.json");
|
|
2742
|
+
var gateStateFileFor = (dist) => join18(dirname11(dist), ".workspace-mcp.json");
|
|
2743
|
+
function gateStateFile() {
|
|
2744
|
+
return gateStateFileFor(bundledDistDir());
|
|
2745
|
+
}
|
|
2746
|
+
function readGateState(opts = {}) {
|
|
2747
|
+
try {
|
|
2748
|
+
return JSON.parse(readFileSync10(opts.stateFile ?? gateStateFile(), "utf8"));
|
|
2749
|
+
} catch {
|
|
2750
|
+
return {};
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
function workspaceMcpGateState(settingsPath) {
|
|
2754
|
+
let raw;
|
|
2755
|
+
try {
|
|
2756
|
+
raw = readFileSync10(settingsPath, "utf8");
|
|
2757
|
+
} catch {
|
|
2758
|
+
return "unknown";
|
|
2759
|
+
}
|
|
2760
|
+
try {
|
|
2761
|
+
const doc = JSON.parse(raw);
|
|
2762
|
+
return doc[WORKSPACE_MCP_KEY] === true ? "on" : "off";
|
|
2763
|
+
} catch {
|
|
2764
|
+
const hit = raw.match(new RegExp(`"${WORKSPACE_MCP_KEY}"\\s*:\\s*(true|false)`));
|
|
2765
|
+
return hit ? hit[1] === "true" ? "on" : "off" : "unknown";
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
function enableWorkspaceMcpSetting(settingsPath) {
|
|
2769
|
+
try {
|
|
2770
|
+
let doc = {};
|
|
2771
|
+
try {
|
|
2772
|
+
doc = JSON.parse(readFileSync10(settingsPath, "utf8"));
|
|
2773
|
+
} catch {
|
|
2774
|
+
if (existsSync8(settingsPath)) return false;
|
|
2775
|
+
}
|
|
2776
|
+
doc[WORKSPACE_MCP_KEY] = true;
|
|
2777
|
+
mkdirSync6(dirname11(settingsPath), { recursive: true });
|
|
2778
|
+
writeFileSync4(settingsPath, JSON.stringify(doc, null, 2) + "\n");
|
|
2779
|
+
return true;
|
|
2780
|
+
} catch {
|
|
2781
|
+
return false;
|
|
2782
|
+
}
|
|
2783
|
+
}
|
|
2784
|
+
function markWorkspaceMcpEnabled(opts = {}) {
|
|
2785
|
+
try {
|
|
2786
|
+
writeFileSync4(
|
|
2787
|
+
opts.stateFile ?? gateStateFile(),
|
|
2788
|
+
JSON.stringify({ ...readGateState(opts), workspaceMcpEnabled: true }, null, 2) + "\n"
|
|
2789
|
+
);
|
|
2790
|
+
} catch {
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
function workspaceMcpHint(opts = {}) {
|
|
2794
|
+
try {
|
|
2795
|
+
const settingsPath = traecodeUserSettingsPath(opts.home ?? homedir8());
|
|
2796
|
+
if (workspaceMcpGateState(settingsPath) === "on") return void 0;
|
|
2797
|
+
const now = opts.now ?? Date.now();
|
|
2798
|
+
const state = readGateState(opts);
|
|
2799
|
+
if (state.workspaceMcpEnabled) return void 0;
|
|
2800
|
+
if (typeof state.lastHint === "number" && now - state.lastHint < HINT_MIN_INTERVAL_MS) {
|
|
2801
|
+
return void 0;
|
|
2802
|
+
}
|
|
2803
|
+
writeFileSync4(
|
|
2804
|
+
opts.stateFile ?? gateStateFile(),
|
|
2805
|
+
JSON.stringify({ ...state, lastHint: now }, null, 2) + "\n"
|
|
2806
|
+
);
|
|
2807
|
+
return 'Hindsight MCP tools are hidden: TraeCode does not read per-repo MCP configs until workspace MCP is enabled. Turn it on once in Trae settings (search "enableWorkspaceMcp") or re-run `hindsight-coding-agents install traecode` \u2014 then reload this window.';
|
|
2808
|
+
} catch {
|
|
2809
|
+
return void 0;
|
|
2810
|
+
}
|
|
2811
|
+
}
|
|
2812
|
+
function gitignoreCovers(lines) {
|
|
2813
|
+
return lines.some((l) => {
|
|
2814
|
+
const t = l.trim();
|
|
2815
|
+
return t.includes(".trae");
|
|
2816
|
+
});
|
|
2817
|
+
}
|
|
2818
|
+
function ensureGitignored(repo) {
|
|
2819
|
+
const gitignore = join18(repo, ".gitignore");
|
|
2820
|
+
if (!existsSync8(gitignore)) return;
|
|
2821
|
+
const current2 = readFileSync10(gitignore, "utf8");
|
|
2822
|
+
if (gitignoreCovers(current2.split("\n"))) return;
|
|
2823
|
+
const addition = (current2.endsWith("\n") || current2 === "" ? "" : "\n") + "# hindsight MCP registration (machine-specific)\n.trae/mcp.json\n";
|
|
2824
|
+
writeFileSync4(gitignore, current2 + addition);
|
|
2825
|
+
}
|
|
2826
|
+
function ensureTraecodeWorkspaceMcp(cwd, opts = {}) {
|
|
2827
|
+
registerTraecodeWorkspaceMcp(cwd, opts);
|
|
2828
|
+
const seeded = ensureWorkspaceMcpEnabled(cwd, opts);
|
|
2829
|
+
return workspaceMcpHint(opts) ?? (seeded === "failed" ? workspaceEnableHint(opts) : void 0);
|
|
2830
|
+
}
|
|
2831
|
+
function registerTraecodeWorkspaceMcp(cwd, opts = {}) {
|
|
2832
|
+
try {
|
|
2833
|
+
const home = opts.home ?? homedir8();
|
|
2834
|
+
if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return "skipped";
|
|
2835
|
+
const dist = opts.dist ?? bundledDistDir();
|
|
2836
|
+
const script = join18(dist, "mcp-server.js");
|
|
2837
|
+
if (!existsSync8(script)) return "skipped";
|
|
2838
|
+
const file = join18(cwd, MCP_FILE_REL);
|
|
2839
|
+
let doc = {};
|
|
2840
|
+
let exists = false;
|
|
2841
|
+
try {
|
|
2842
|
+
doc = JSON.parse(readFileSync10(file, "utf8"));
|
|
2843
|
+
exists = true;
|
|
2844
|
+
} catch {
|
|
2845
|
+
if (existsSync8(file)) return "skipped";
|
|
2846
|
+
}
|
|
2847
|
+
const servers = doc.mcpServers && typeof doc.mcpServers === "object" && !Array.isArray(doc.mcpServers) ? doc.mcpServers : doc.mcpServers = {};
|
|
2848
|
+
const entry = {
|
|
2849
|
+
command: "node",
|
|
2850
|
+
args: [script],
|
|
2851
|
+
env: { HINDSIGHT_MCP_HARNESS: "traecode", HINDSIGHT_MCP_PROJECT_CWD: cwd }
|
|
2852
|
+
};
|
|
2853
|
+
const existing = servers[MCP_SERVER_NAME];
|
|
2854
|
+
let merged;
|
|
2855
|
+
if (existing === void 0) {
|
|
2856
|
+
merged = entry;
|
|
2857
|
+
} else if (isOurMcpEntry(existing)) {
|
|
2858
|
+
const env = existing.env;
|
|
2859
|
+
merged = {
|
|
2860
|
+
...existing,
|
|
2861
|
+
command: entry.command,
|
|
2862
|
+
args: entry.args,
|
|
2863
|
+
env: { ...env ?? {}, ...entry.env }
|
|
2864
|
+
};
|
|
2865
|
+
} else {
|
|
2866
|
+
diag("traecode", "workspace_mcp_foreign_entry", { cwd, file });
|
|
2867
|
+
return "skipped";
|
|
2868
|
+
}
|
|
2869
|
+
if (existing !== void 0 && canon(merged) === canon(existing)) return "current";
|
|
2870
|
+
servers[MCP_SERVER_NAME] = merged;
|
|
2871
|
+
mkdirSync6(dirname11(file), { recursive: true });
|
|
2872
|
+
writeFileSync4(file, JSON.stringify(doc, null, 2) + "\n");
|
|
2873
|
+
if (!exists) ensureGitignored(cwd);
|
|
2874
|
+
diag("traecode", "workspace_mcp_registered", { cwd, file });
|
|
2875
|
+
return "registered";
|
|
2876
|
+
} catch (e) {
|
|
2877
|
+
diag("traecode", "workspace_mcp_register_failed", {
|
|
2878
|
+
cwd,
|
|
2879
|
+
error: e instanceof Error ? e.message : String(e)
|
|
2880
|
+
});
|
|
2881
|
+
return "failed";
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
function removeTraecodeWorkspaceMcpEntry(cwd, opts = {}) {
|
|
2885
|
+
try {
|
|
2886
|
+
const home = opts.home ?? homedir8();
|
|
2887
|
+
if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return false;
|
|
2888
|
+
const file = join18(cwd, MCP_FILE_REL);
|
|
2889
|
+
let doc;
|
|
2890
|
+
try {
|
|
2891
|
+
doc = JSON.parse(readFileSync10(file, "utf8"));
|
|
2892
|
+
} catch {
|
|
2893
|
+
return false;
|
|
2894
|
+
}
|
|
2895
|
+
const servers = doc.mcpServers;
|
|
2896
|
+
if (!servers || typeof servers !== "object" || Array.isArray(servers)) return false;
|
|
2897
|
+
const record = servers;
|
|
2898
|
+
if (!isOurMcpEntry(record[MCP_SERVER_NAME])) return false;
|
|
2899
|
+
delete record[MCP_SERVER_NAME];
|
|
2900
|
+
if (Object.keys(record).length === 0) delete doc.mcpServers;
|
|
2901
|
+
if (Object.keys(doc).length === 0) rmSync3(file);
|
|
2902
|
+
else writeFileSync4(file, JSON.stringify(doc, null, 2) + "\n");
|
|
2903
|
+
return true;
|
|
2904
|
+
} catch {
|
|
2905
|
+
return false;
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
var WORKSPACE_STORAGE_REL = join18("User", "workspaceStorage");
|
|
2909
|
+
var ENABLED_KEY_PREFIX = "icubeAgentExtension.enabled.mcp.config.ws0.";
|
|
2910
|
+
var SQLITE_TIMEOUT_MS = 5e3;
|
|
2911
|
+
var TRAECODE_WORKSPACE_ENABLED_KEY = ENABLED_KEY_PREFIX + MCP_SERVER_NAME;
|
|
2912
|
+
var traecodeWorkspaceStorageDir = (home) => join18(traecodeUserDataDir(home), WORKSPACE_STORAGE_REL);
|
|
2913
|
+
function removeWorkspaceMcpEnabledKeys(home) {
|
|
2914
|
+
const storage = traecodeWorkspaceStorageDir(home);
|
|
2915
|
+
let entries;
|
|
2916
|
+
try {
|
|
2917
|
+
entries = readdirSync2(storage);
|
|
2918
|
+
} catch {
|
|
2919
|
+
return;
|
|
2920
|
+
}
|
|
2921
|
+
for (const name of entries) {
|
|
2922
|
+
const db = join18(storage, name, "state.vscdb");
|
|
2923
|
+
if (!existsSync8(db)) continue;
|
|
2924
|
+
try {
|
|
2925
|
+
execFileSync5(
|
|
2926
|
+
"sqlite3",
|
|
2927
|
+
[
|
|
2928
|
+
db,
|
|
2929
|
+
".timeout 3000",
|
|
2930
|
+
`DELETE FROM ItemTable WHERE key='${TRAECODE_WORKSPACE_ENABLED_KEY}';`
|
|
2931
|
+
],
|
|
2932
|
+
{
|
|
2933
|
+
timeout: SQLITE_TIMEOUT_MS,
|
|
2934
|
+
windowsHide: true,
|
|
2935
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2936
|
+
}
|
|
2937
|
+
);
|
|
2938
|
+
} catch {
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2942
|
+
function findWorkspaceStorageDir(storage, repo) {
|
|
2943
|
+
let entries;
|
|
2944
|
+
try {
|
|
2945
|
+
entries = readdirSync2(storage);
|
|
2946
|
+
} catch {
|
|
2947
|
+
return void 0;
|
|
2948
|
+
}
|
|
2949
|
+
for (const name of entries) {
|
|
2950
|
+
try {
|
|
2951
|
+
const doc = JSON.parse(readFileSync10(join18(storage, name, "workspace.json"), "utf8"));
|
|
2952
|
+
if (typeof doc.folder !== "string") continue;
|
|
2953
|
+
let folder;
|
|
2954
|
+
try {
|
|
2955
|
+
folder = fileURLToPath6(doc.folder);
|
|
2956
|
+
} catch {
|
|
2957
|
+
folder = doc.folder;
|
|
2958
|
+
}
|
|
2959
|
+
if (folder === repo) return join18(storage, name);
|
|
2960
|
+
} catch {
|
|
2961
|
+
continue;
|
|
2962
|
+
}
|
|
2963
|
+
}
|
|
2964
|
+
return void 0;
|
|
2965
|
+
}
|
|
2966
|
+
function ensureWorkspaceMcpEnabled(cwd, opts = {}) {
|
|
2967
|
+
try {
|
|
2968
|
+
const home = opts.home ?? homedir8();
|
|
2969
|
+
if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return "failed";
|
|
2970
|
+
const dir = findWorkspaceStorageDir(traecodeWorkspaceStorageDir(home), cwd);
|
|
2971
|
+
if (!dir) return "failed";
|
|
2972
|
+
const db = join18(dir, "state.vscdb");
|
|
2973
|
+
if (!existsSync8(db)) return "failed";
|
|
2974
|
+
const sqlite = opts.sqlite ?? execFileSync5;
|
|
2975
|
+
const run2 = (sql) => sqlite("sqlite3", [db, ".timeout 3000", sql], {
|
|
2976
|
+
encoding: "utf8",
|
|
2977
|
+
timeout: SQLITE_TIMEOUT_MS,
|
|
2978
|
+
windowsHide: true,
|
|
2979
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2980
|
+
}).trim();
|
|
2981
|
+
if (run2(`SELECT value FROM ItemTable WHERE key='${TRAECODE_WORKSPACE_ENABLED_KEY}';`) === "true") {
|
|
2982
|
+
return "on";
|
|
2983
|
+
}
|
|
2984
|
+
run2(
|
|
2985
|
+
`INSERT OR REPLACE INTO ItemTable (key, value) VALUES ('${TRAECODE_WORKSPACE_ENABLED_KEY}', 'true');`
|
|
2986
|
+
);
|
|
2987
|
+
diag("traecode", "workspace_mcp_enabled_seeded", { cwd, db });
|
|
2988
|
+
return "seeded";
|
|
2989
|
+
} catch (e) {
|
|
2990
|
+
diag("traecode", "workspace_mcp_enabled_seed_failed", {
|
|
2991
|
+
cwd,
|
|
2992
|
+
error: e instanceof Error ? e.message : String(e)
|
|
2993
|
+
});
|
|
2994
|
+
return "failed";
|
|
2995
|
+
}
|
|
2996
|
+
}
|
|
2997
|
+
function workspaceEnableHint(opts = {}) {
|
|
2998
|
+
try {
|
|
2999
|
+
const now = opts.now ?? Date.now();
|
|
3000
|
+
const state = readGateState(opts);
|
|
3001
|
+
if (typeof state.lastEnableHint === "number" && now - state.lastEnableHint < HINT_MIN_INTERVAL_MS) {
|
|
3002
|
+
return void 0;
|
|
3003
|
+
}
|
|
3004
|
+
writeFileSync4(
|
|
3005
|
+
opts.stateFile ?? gateStateFile(),
|
|
3006
|
+
JSON.stringify({ ...state, lastEnableHint: now }, null, 2) + "\n"
|
|
3007
|
+
);
|
|
3008
|
+
return "Hindsight's MCP server stays disabled in this window: auto-enabling it failed here. Switch hindsight on for this workspace in Trae's MCP panel, then reload the window.";
|
|
3009
|
+
} catch {
|
|
3010
|
+
return void 0;
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
|
|
2563
3014
|
// src/core/transcript-codex.ts
|
|
2564
3015
|
function stampOf(line) {
|
|
2565
3016
|
return typeof line.timestamp === "string" && line.timestamp ? { timestamp: line.timestamp } : {};
|
|
@@ -2568,12 +3019,68 @@ function isSyntheticUserText(text) {
|
|
|
2568
3019
|
const s = text.trimStart();
|
|
2569
3020
|
return s.startsWith("# AGENTS.md instructions for ") || s.startsWith("<environment_context>");
|
|
2570
3021
|
}
|
|
3022
|
+
var AGENTS_BLOCK_HEADER = /^# AGENTS\.md instructions(?: for [^\n]*)?\n/;
|
|
3023
|
+
var STARTUP_TAG_BLOCK = /^<(recommended_plugins|environment_context)>(?:(?!<\1>)[\s\S])*<\/\1>$/;
|
|
3024
|
+
function isStartupItem(text) {
|
|
3025
|
+
const s = text.trim();
|
|
3026
|
+
if (AGENTS_BLOCK_HEADER.test(s))
|
|
3027
|
+
return s.includes("<INSTRUCTIONS>") && s.includes("</INSTRUCTIONS>");
|
|
3028
|
+
return STARTUP_TAG_BLOCK.test(s);
|
|
3029
|
+
}
|
|
2571
3030
|
function contentText(content) {
|
|
2572
|
-
return (content
|
|
3031
|
+
return (Array.isArray(content) ? content : []).filter((c) => c && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
3032
|
+
}
|
|
3033
|
+
var startupKinds = /* @__PURE__ */ new Set([
|
|
3034
|
+
"agents_md.instructions",
|
|
3035
|
+
"environments.instructions",
|
|
3036
|
+
"environments.environment_context",
|
|
3037
|
+
"plugins.recommendations",
|
|
3038
|
+
"plugins.usage_instructions"
|
|
3039
|
+
]);
|
|
3040
|
+
function fallbackUserText(payload) {
|
|
3041
|
+
const content = payload.content;
|
|
3042
|
+
const kinds = payload.internal_chat_message_metadata_passthrough?.content_item_kinds;
|
|
3043
|
+
if (Array.isArray(content) && Array.isArray(kinds) && kinds.length === content.length && kinds.every((kind) => typeof kind === "string" && kind.length > 0)) {
|
|
3044
|
+
return contentText(content.filter((_, index) => !startupKinds.has(kinds[index])));
|
|
3045
|
+
}
|
|
3046
|
+
const items = (Array.isArray(content) ? content : []).filter(
|
|
3047
|
+
(c) => !(c && typeof c.text === "string" && isStartupItem(stripInjectedMemory(c.text)))
|
|
3048
|
+
);
|
|
3049
|
+
const text = contentText(items);
|
|
3050
|
+
return isSyntheticUserText(stripInjectedMemory(text)) ? "" : text;
|
|
2573
3051
|
}
|
|
2574
3052
|
function isUserMessageEvent(line) {
|
|
2575
3053
|
return line.type === "event_msg" && line.payload?.type === "item_completed" && line.payload.item?.type === "UserMessage";
|
|
2576
3054
|
}
|
|
3055
|
+
var TOOL_ITEM_TYPES = /* @__PURE__ */ new Set(["McpToolCall", "CommandExecution"]);
|
|
3056
|
+
function isToolItemEvent(line) {
|
|
3057
|
+
return line.type === "event_msg" && line.payload?.type === "item_completed" && TOOL_ITEM_TYPES.has(line.payload.item?.type ?? "");
|
|
3058
|
+
}
|
|
3059
|
+
function parseArgs(raw) {
|
|
3060
|
+
if (typeof raw !== "string") return raw;
|
|
3061
|
+
try {
|
|
3062
|
+
return JSON.parse(raw);
|
|
3063
|
+
} catch {
|
|
3064
|
+
return void 0;
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
var SHELL_RE = /(?:^|\/)(?:sh|bash|zsh|dash|ksh|fish)$/;
|
|
3068
|
+
function commandText(command) {
|
|
3069
|
+
if (typeof command === "string") return command;
|
|
3070
|
+
if (!Array.isArray(command) || !command.every((c) => typeof c === "string")) return "";
|
|
3071
|
+
const argv = command;
|
|
3072
|
+
if (argv.length === 3 && SHELL_RE.test(argv[0]) && /^-[a-z]*c$/.test(argv[1])) return argv[2];
|
|
3073
|
+
return argv.join(" ");
|
|
3074
|
+
}
|
|
3075
|
+
function toolItemAction(item) {
|
|
3076
|
+
if (item.type === "McpToolCall") {
|
|
3077
|
+
if (typeof item.tool !== "string" || !item.tool) return void 0;
|
|
3078
|
+
const name = typeof item.server === "string" && item.server ? `mcp__${item.server}__${item.tool}` : item.tool;
|
|
3079
|
+
return actionLine(name, parseArgs(item.arguments));
|
|
3080
|
+
}
|
|
3081
|
+
const command = commandText(item.command).trim();
|
|
3082
|
+
return command ? actionLine("exec_command", { command }) : void 0;
|
|
3083
|
+
}
|
|
2577
3084
|
function readCodexTranscript(path) {
|
|
2578
3085
|
const lines = [];
|
|
2579
3086
|
for (const rawLine of readJsonl(path)) {
|
|
@@ -2587,6 +3094,7 @@ function readCodexTranscript(path) {
|
|
|
2587
3094
|
}
|
|
2588
3095
|
}
|
|
2589
3096
|
const userFromEvents = lines.some(isUserMessageEvent);
|
|
3097
|
+
const actionsFromEvents = lines.some(isToolItemEvent);
|
|
2590
3098
|
const turns = [];
|
|
2591
3099
|
const push = (role, raw, stamp = {}) => {
|
|
2592
3100
|
const text = stripInjectedMemory(raw).trim();
|
|
@@ -2597,16 +3105,24 @@ function readCodexTranscript(path) {
|
|
|
2597
3105
|
push("user", contentText(line.payload?.item?.content), stampOf(line));
|
|
2598
3106
|
continue;
|
|
2599
3107
|
}
|
|
3108
|
+
if (isToolItemEvent(line)) {
|
|
3109
|
+
const action = toolItemAction(line.payload?.item ?? {});
|
|
3110
|
+
if (action) turns.push({ role: "action", content: action, ...stampOf(line) });
|
|
3111
|
+
continue;
|
|
3112
|
+
}
|
|
2600
3113
|
if (line.type !== "response_item") continue;
|
|
2601
3114
|
const p = line.payload;
|
|
2602
3115
|
if (!p || typeof p !== "object") continue;
|
|
2603
3116
|
if (p.type === "message") {
|
|
2604
|
-
if (p.role === "assistant")
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
3117
|
+
if (p.role === "assistant") {
|
|
3118
|
+
if (p.channel === "analysis" || p.channel === "reasoning" || p.phase === "analysis" || p.phase === "reasoning")
|
|
3119
|
+
continue;
|
|
3120
|
+
push("assistant", contentText(p.content), stampOf(line));
|
|
3121
|
+
} else if (p.role === "user" && !userFromEvents) {
|
|
3122
|
+
push("user", fallbackUserText(p), stampOf(line));
|
|
2608
3123
|
}
|
|
2609
3124
|
} else if ((p.type === "function_call" || p.type === "custom_tool_call") && typeof p.name === "string") {
|
|
3125
|
+
if (actionsFromEvents && p.type === "custom_tool_call" && p.name === "exec") continue;
|
|
2610
3126
|
const rawInput = p.type === "function_call" ? p.arguments : p.input;
|
|
2611
3127
|
let input;
|
|
2612
3128
|
try {
|
|
@@ -2707,19 +3223,19 @@ function readCopilotTranscript(path) {
|
|
|
2707
3223
|
}
|
|
2708
3224
|
|
|
2709
3225
|
// src/core/transcript-grok.ts
|
|
2710
|
-
import { existsSync as
|
|
2711
|
-
import { homedir as
|
|
2712
|
-
import { join as
|
|
3226
|
+
import { existsSync as existsSync9, readFileSync as readFileSync11, readdirSync as readdirSync3 } from "fs";
|
|
3227
|
+
import { homedir as homedir9 } from "os";
|
|
3228
|
+
import { join as join19 } from "path";
|
|
2713
3229
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
2714
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
2715
|
-
const sessionsDir =
|
|
2716
|
-
const direct =
|
|
2717
|
-
if (
|
|
3230
|
+
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join19(homedir9(), ".grok")) {
|
|
3231
|
+
const sessionsDir = join19(grokHome, "sessions");
|
|
3232
|
+
const direct = join19(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
|
|
3233
|
+
if (existsSync9(direct)) return direct;
|
|
2718
3234
|
try {
|
|
2719
|
-
for (const candidate of
|
|
2720
|
-
const directory =
|
|
2721
|
-
if (
|
|
2722
|
-
return
|
|
3235
|
+
for (const candidate of readdirSync3(sessionsDir)) {
|
|
3236
|
+
const directory = join19(sessionsDir, candidate);
|
|
3237
|
+
if (readFileSync11(join19(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
3238
|
+
return join19(directory, sessionId, CHAT_HISTORY);
|
|
2723
3239
|
}
|
|
2724
3240
|
}
|
|
2725
3241
|
} catch {
|
|
@@ -2754,12 +3270,12 @@ function readGrokTranscript(path) {
|
|
|
2754
3270
|
}
|
|
2755
3271
|
|
|
2756
3272
|
// src/core/transcript-devin.ts
|
|
2757
|
-
import { existsSync as
|
|
3273
|
+
import { existsSync as existsSync10 } from "fs";
|
|
2758
3274
|
import { createRequire } from "module";
|
|
2759
|
-
import { homedir as
|
|
2760
|
-
import { join as
|
|
2761
|
-
function devinSessionDb(home =
|
|
2762
|
-
return
|
|
3275
|
+
import { homedir as homedir10 } from "os";
|
|
3276
|
+
import { join as join20 } from "path";
|
|
3277
|
+
function devinSessionDb(home = homedir10()) {
|
|
3278
|
+
return join20(home, ".local", "share", "devin", "cli", "sessions.db");
|
|
2763
3279
|
}
|
|
2764
3280
|
function parseDevinMessages(nodes) {
|
|
2765
3281
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -2796,7 +3312,7 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
|
|
|
2796
3312
|
diag("devin-cli", "sqlite_unavailable", { node: process.version, dbPath });
|
|
2797
3313
|
return [];
|
|
2798
3314
|
}
|
|
2799
|
-
if (!
|
|
3315
|
+
if (!existsSync10(dbPath)) {
|
|
2800
3316
|
diag("devin-cli", "session_db_missing", { dbPath });
|
|
2801
3317
|
return [];
|
|
2802
3318
|
}
|
|
@@ -3045,72 +3561,326 @@ function renderContent(content, role) {
|
|
|
3045
3561
|
out.push(...actions);
|
|
3046
3562
|
return out;
|
|
3047
3563
|
}
|
|
3048
|
-
function readDroidTranscript(path) {
|
|
3564
|
+
function readDroidTranscript(path) {
|
|
3565
|
+
const turns = [];
|
|
3566
|
+
for (const rawLine of readJsonl(path)) {
|
|
3567
|
+
if (!rawLine.trim()) continue;
|
|
3568
|
+
let parsed;
|
|
3569
|
+
try {
|
|
3570
|
+
parsed = JSON.parse(rawLine);
|
|
3571
|
+
} catch {
|
|
3572
|
+
continue;
|
|
3573
|
+
}
|
|
3574
|
+
if (!parsed || typeof parsed !== "object") continue;
|
|
3575
|
+
const line = parsed;
|
|
3576
|
+
if (line.type !== "message" || !line.message || typeof line.message !== "object") continue;
|
|
3577
|
+
const message = line.message;
|
|
3578
|
+
const role = message.role;
|
|
3579
|
+
if (role !== "user" && role !== "assistant") continue;
|
|
3580
|
+
if (message.visibility === "user_only" || message.visibility === "llm_only") continue;
|
|
3581
|
+
const stamp = typeof line.timestamp === "string" && line.timestamp ? { timestamp: line.timestamp } : {};
|
|
3582
|
+
turns.push(...renderContent(message.content, role).map((turn) => ({ ...turn, ...stamp })));
|
|
3583
|
+
}
|
|
3584
|
+
return turns;
|
|
3585
|
+
}
|
|
3586
|
+
|
|
3587
|
+
// src/core/transcript-zcode.ts
|
|
3588
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
3589
|
+
function messageText(content) {
|
|
3590
|
+
if (typeof content === "string") return content.trim();
|
|
3591
|
+
if (!Array.isArray(content)) return "";
|
|
3592
|
+
return content.filter((block) => block && typeof block === "object" && typeof block.text === "string").map((block) => block.text.trim()).filter(Boolean).join("\n").trim();
|
|
3593
|
+
}
|
|
3594
|
+
function readZcodeTranscript(path) {
|
|
3595
|
+
if (!path) return [];
|
|
3596
|
+
let body;
|
|
3597
|
+
try {
|
|
3598
|
+
body = readFileSync12(path, "utf8");
|
|
3599
|
+
} catch {
|
|
3600
|
+
return [];
|
|
3601
|
+
}
|
|
3602
|
+
const turns = [];
|
|
3603
|
+
for (const line of body.split("\n")) {
|
|
3604
|
+
const trimmed = line.trim();
|
|
3605
|
+
if (!trimmed) continue;
|
|
3606
|
+
let parsed;
|
|
3607
|
+
try {
|
|
3608
|
+
parsed = JSON.parse(trimmed);
|
|
3609
|
+
} catch {
|
|
3610
|
+
continue;
|
|
3611
|
+
}
|
|
3612
|
+
if (typeof parsed !== "object" || parsed === null) continue;
|
|
3613
|
+
const record = parsed;
|
|
3614
|
+
const message = typeof record.message === "object" && record.message !== null ? record.message : void 0;
|
|
3615
|
+
const role = typeof message?.role === "string" ? message.role : record.type;
|
|
3616
|
+
if (role !== "user" && role !== "assistant") continue;
|
|
3617
|
+
const content = stripInjectedMemory(messageText(message?.content)).trim();
|
|
3618
|
+
if (!content) continue;
|
|
3619
|
+
turns.push({
|
|
3620
|
+
role,
|
|
3621
|
+
content,
|
|
3622
|
+
...typeof record.timestamp === "string" ? { timestamp: record.timestamp } : {}
|
|
3623
|
+
});
|
|
3624
|
+
}
|
|
3625
|
+
return turns;
|
|
3626
|
+
}
|
|
3627
|
+
function zcodeAssistantText(path) {
|
|
3628
|
+
if (!path) return "";
|
|
3629
|
+
return readZcodeTranscript(path).filter((turn) => turn.role === "assistant").at(-1)?.content ?? "";
|
|
3630
|
+
}
|
|
3631
|
+
|
|
3632
|
+
// src/core/transcript-kimi.ts
|
|
3633
|
+
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
3634
|
+
import { homedir as homedir11 } from "os";
|
|
3635
|
+
import { join as join21 } from "path";
|
|
3636
|
+
var HARNESS = "kimi-code";
|
|
3637
|
+
var SESSIONS_DIR = "sessions";
|
|
3638
|
+
var AGENTS_DIR = "agents";
|
|
3639
|
+
var WIRE_LOG = "wire.jsonl";
|
|
3640
|
+
var SESSION_PREFIX = "session_";
|
|
3641
|
+
var MAIN_AGENT = "main";
|
|
3642
|
+
var MAX_SESSION_CHARS = 32 * 1024 * 1024;
|
|
3643
|
+
function kimiSessionDir(sessionId, kimiHome2 = process.env.KIMI_CODE_HOME || join21(homedir11(), ".kimi-code")) {
|
|
3644
|
+
const name = sessionId.startsWith(SESSION_PREFIX) ? sessionId : `${SESSION_PREFIX}${sessionId}`;
|
|
3645
|
+
const sessions = join21(kimiHome2, SESSIONS_DIR);
|
|
3646
|
+
try {
|
|
3647
|
+
for (const workspace of readdirSync4(sessions, { withFileTypes: true })) {
|
|
3648
|
+
if (!workspace.isDirectory()) continue;
|
|
3649
|
+
const candidate = join21(sessions, workspace.name, name);
|
|
3650
|
+
if (existsSync11(join21(candidate, AGENTS_DIR))) return candidate;
|
|
3651
|
+
}
|
|
3652
|
+
} catch {
|
|
3653
|
+
}
|
|
3654
|
+
diag(HARNESS, "session_dir_missing", { sessions, session: name });
|
|
3655
|
+
return void 0;
|
|
3656
|
+
}
|
|
3657
|
+
function stampOf2(event) {
|
|
3658
|
+
if (typeof event.time !== "number") return {};
|
|
3659
|
+
const at = new Date(event.time);
|
|
3660
|
+
return Number.isNaN(at.getTime()) ? {} : { timestamp: at.toISOString() };
|
|
3661
|
+
}
|
|
3662
|
+
function kimiPromptText(input) {
|
|
3663
|
+
if (!Array.isArray(input)) return "";
|
|
3664
|
+
return input.filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n");
|
|
3665
|
+
}
|
|
3666
|
+
function readKimiWire(events) {
|
|
3667
|
+
const turns = [];
|
|
3668
|
+
let step;
|
|
3669
|
+
const flushStep = () => {
|
|
3670
|
+
if (!step) return;
|
|
3671
|
+
const content = stripInjectedMemory(step.texts.join("\n")).trim();
|
|
3672
|
+
if (content) turns.push({ role: "assistant", content, ...step.stamp });
|
|
3673
|
+
step = void 0;
|
|
3674
|
+
};
|
|
3675
|
+
for (const event of events || []) {
|
|
3676
|
+
if (!event || typeof event !== "object") continue;
|
|
3677
|
+
const stamp = stampOf2(event);
|
|
3678
|
+
if (event.type === "turn.prompt") {
|
|
3679
|
+
flushStep();
|
|
3680
|
+
if (event.origin?.kind !== "user") continue;
|
|
3681
|
+
const content = stripInjectedMemory(kimiPromptText(event.input)).trim();
|
|
3682
|
+
if (content) turns.push({ role: "user", content, ...stamp });
|
|
3683
|
+
continue;
|
|
3684
|
+
}
|
|
3685
|
+
if (event.type !== "context.append_loop_event") continue;
|
|
3686
|
+
const loop = event.event;
|
|
3687
|
+
if (!loop || typeof loop !== "object") continue;
|
|
3688
|
+
if (loop.type === "content.part") {
|
|
3689
|
+
if (loop.part?.type !== "text" || typeof loop.part.text !== "string") continue;
|
|
3690
|
+
const uuid = typeof loop.stepUuid === "string" ? loop.stepUuid : "";
|
|
3691
|
+
if (step && step.uuid !== uuid) flushStep();
|
|
3692
|
+
if (!step) step = { uuid, texts: [], stamp };
|
|
3693
|
+
step.texts.push(loop.part.text);
|
|
3694
|
+
} else if (loop.type === "tool.call") {
|
|
3695
|
+
flushStep();
|
|
3696
|
+
if (typeof loop.name !== "string" || !loop.name) continue;
|
|
3697
|
+
turns.push({ role: "action", content: actionLine(loop.name, loop.args), ...stamp });
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
flushStep();
|
|
3701
|
+
return turns;
|
|
3702
|
+
}
|
|
3703
|
+
function agentIds(sessionDir) {
|
|
3704
|
+
try {
|
|
3705
|
+
return readdirSync4(join21(sessionDir, AGENTS_DIR), { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort(byAgentId);
|
|
3706
|
+
} catch {
|
|
3707
|
+
return [];
|
|
3708
|
+
}
|
|
3709
|
+
}
|
|
3710
|
+
function byAgentId(a, b) {
|
|
3711
|
+
if (a === b) return 0;
|
|
3712
|
+
if (a === MAIN_AGENT) return -1;
|
|
3713
|
+
if (b === MAIN_AGENT) return 1;
|
|
3714
|
+
const indexA = agentIndex(a);
|
|
3715
|
+
const indexB = agentIndex(b);
|
|
3716
|
+
return indexA === indexB ? a.localeCompare(b) : indexA - indexB;
|
|
3717
|
+
}
|
|
3718
|
+
function agentIndex(id) {
|
|
3719
|
+
const suffix = Number(id.slice(id.lastIndexOf("-") + 1));
|
|
3720
|
+
return Number.isFinite(suffix) ? suffix : Number.MAX_SAFE_INTEGER;
|
|
3721
|
+
}
|
|
3722
|
+
function parseEvent(rawLine) {
|
|
3723
|
+
const trimmed = rawLine.trim();
|
|
3724
|
+
if (!trimmed) return void 0;
|
|
3725
|
+
let parsed;
|
|
3726
|
+
try {
|
|
3727
|
+
parsed = JSON.parse(trimmed);
|
|
3728
|
+
} catch {
|
|
3729
|
+
return void 0;
|
|
3730
|
+
}
|
|
3731
|
+
return typeof parsed === "object" && parsed !== null ? parsed : void 0;
|
|
3732
|
+
}
|
|
3733
|
+
function readKimiTranscript(path) {
|
|
3734
|
+
const turns = [];
|
|
3735
|
+
let remaining = MAX_SESSION_CHARS;
|
|
3736
|
+
for (const agentId of agentIds(path)) {
|
|
3737
|
+
const wire = join21(path, AGENTS_DIR, agentId, WIRE_LOG);
|
|
3738
|
+
const events = [];
|
|
3739
|
+
for (const rawLine of readJsonl(wire)) {
|
|
3740
|
+
remaining -= rawLine.length;
|
|
3741
|
+
if (remaining < 0) break;
|
|
3742
|
+
const event = parseEvent(rawLine);
|
|
3743
|
+
if (event) events.push(event);
|
|
3744
|
+
}
|
|
3745
|
+
for (const turn of readKimiWire(events)) turns.push(turn);
|
|
3746
|
+
if (remaining < 0) {
|
|
3747
|
+
log.warn(HARNESS, "session exceeds the wire-log budget \u2014 later agents were not read", {
|
|
3748
|
+
sessionDir: path,
|
|
3749
|
+
stoppedAt: wire
|
|
3750
|
+
});
|
|
3751
|
+
break;
|
|
3752
|
+
}
|
|
3753
|
+
}
|
|
3754
|
+
return turns;
|
|
3755
|
+
}
|
|
3756
|
+
|
|
3757
|
+
// src/core/transcript-workbuddy.ts
|
|
3758
|
+
function messageText2(content) {
|
|
3759
|
+
if (typeof content === "string") return content;
|
|
3760
|
+
if (!Array.isArray(content)) return "";
|
|
3761
|
+
return content.filter((b) => b && typeof b.text === "string").map((b) => b.text).join("\n");
|
|
3762
|
+
}
|
|
3763
|
+
var USER_QUERY_RE = /^\s*<user_query>([\s\S]*?)<\/user_query>\s*(?:<image_local_path>[\s\S]*?<\/image_local_path>\s*)?$/;
|
|
3764
|
+
function unwrapUserQuery(text) {
|
|
3765
|
+
const match = USER_QUERY_RE.exec(text);
|
|
3766
|
+
return (match ? match[1] : text).trim();
|
|
3767
|
+
}
|
|
3768
|
+
function isSyntheticUserText2(text) {
|
|
3769
|
+
const s = text.trimStart();
|
|
3770
|
+
return s.startsWith("<cb_summary>") || s.startsWith("<conversation_history_summary>") || s.startsWith("Use the TaskOutput tool ");
|
|
3771
|
+
}
|
|
3772
|
+
function parseArgs2(raw) {
|
|
3773
|
+
if (!raw) return void 0;
|
|
3774
|
+
try {
|
|
3775
|
+
return JSON.parse(raw);
|
|
3776
|
+
} catch {
|
|
3777
|
+
return raw;
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
function stampOf3(line) {
|
|
3781
|
+
return typeof line.timestamp === "number" ? { timestamp: new Date(line.timestamp).toISOString() } : {};
|
|
3782
|
+
}
|
|
3783
|
+
function readWorkbuddyTranscript(path) {
|
|
3049
3784
|
const turns = [];
|
|
3050
3785
|
for (const rawLine of readJsonl(path)) {
|
|
3051
|
-
|
|
3786
|
+
const trimmed = rawLine.trim();
|
|
3787
|
+
if (!trimmed) continue;
|
|
3052
3788
|
let parsed;
|
|
3053
3789
|
try {
|
|
3054
|
-
parsed = JSON.parse(
|
|
3790
|
+
parsed = JSON.parse(trimmed);
|
|
3055
3791
|
} catch {
|
|
3056
3792
|
continue;
|
|
3057
3793
|
}
|
|
3058
|
-
if (
|
|
3794
|
+
if (typeof parsed !== "object" || parsed === null) continue;
|
|
3059
3795
|
const line = parsed;
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3796
|
+
const stamp = stampOf3(line);
|
|
3797
|
+
if (line.type === "message") {
|
|
3798
|
+
if (line.role !== "user" && line.role !== "assistant") continue;
|
|
3799
|
+
let text = stripInjectedMemory(messageText2(line.content)).trim();
|
|
3800
|
+
if (!text) continue;
|
|
3801
|
+
if (line.role === "user") {
|
|
3802
|
+
if (isSyntheticUserText2(text)) continue;
|
|
3803
|
+
text = unwrapUserQuery(text);
|
|
3804
|
+
if (!text) continue;
|
|
3805
|
+
}
|
|
3806
|
+
turns.push({ role: line.role, content: text, ...stamp });
|
|
3807
|
+
} else if (line.type === "function_call" && typeof line.name === "string") {
|
|
3808
|
+
turns.push({
|
|
3809
|
+
role: "action",
|
|
3810
|
+
content: actionLine(line.name, parseArgs2(line.arguments)),
|
|
3811
|
+
...stamp
|
|
3812
|
+
});
|
|
3813
|
+
}
|
|
3067
3814
|
}
|
|
3068
3815
|
return turns;
|
|
3069
3816
|
}
|
|
3070
3817
|
|
|
3071
|
-
// src/core/transcript-
|
|
3818
|
+
// src/core/transcript-codebuddy-ide.ts
|
|
3072
3819
|
import { readFileSync as readFileSync13 } from "fs";
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
return content.filter((block) => block && typeof block === "object" && typeof block.text === "string").map((block) => block.text.trim()).filter(Boolean).join("\n").trim();
|
|
3077
|
-
}
|
|
3078
|
-
function readZcodeTranscript(path) {
|
|
3079
|
-
if (!path) return [];
|
|
3080
|
-
let body;
|
|
3820
|
+
import { basename as basename3, dirname as dirname12, join as join22 } from "path";
|
|
3821
|
+
var IDE_CONTEXT_RE = /<(user_info|git_status|additional_data|system_reminder)\b[\s\S]*?<\/\1>/g;
|
|
3822
|
+
function readJson(path) {
|
|
3081
3823
|
try {
|
|
3082
|
-
|
|
3824
|
+
return JSON.parse(readFileSync13(path, "utf8"));
|
|
3083
3825
|
} catch {
|
|
3084
|
-
return
|
|
3826
|
+
return void 0;
|
|
3085
3827
|
}
|
|
3828
|
+
}
|
|
3829
|
+
function ideUserText(raw) {
|
|
3830
|
+
let text = stripInjectedMemory(raw).replace(IDE_CONTEXT_RE, "").trim();
|
|
3831
|
+
if (!text || isSyntheticUserText2(text)) return "";
|
|
3832
|
+
return unwrapUserQuery(text).trim();
|
|
3833
|
+
}
|
|
3834
|
+
function readCodebuddyIdeTranscript(indexPath) {
|
|
3835
|
+
const index = readJson(indexPath);
|
|
3836
|
+
const entries = index?.messages;
|
|
3837
|
+
if (!Array.isArray(entries)) return [];
|
|
3838
|
+
const messagesDir = join22(dirname12(indexPath), "messages");
|
|
3086
3839
|
const turns = [];
|
|
3087
|
-
for (const
|
|
3088
|
-
const
|
|
3089
|
-
if (
|
|
3090
|
-
|
|
3840
|
+
for (const entry of entries) {
|
|
3841
|
+
const id = entry?.id;
|
|
3842
|
+
if (typeof id !== "string") continue;
|
|
3843
|
+
const file = readJson(join22(messagesDir, `${id}.json`));
|
|
3844
|
+
const encoded = file?.message;
|
|
3845
|
+
if (typeof encoded !== "string") continue;
|
|
3846
|
+
let inner;
|
|
3091
3847
|
try {
|
|
3092
|
-
|
|
3848
|
+
inner = JSON.parse(encoded);
|
|
3093
3849
|
} catch {
|
|
3094
3850
|
continue;
|
|
3095
3851
|
}
|
|
3096
|
-
|
|
3097
|
-
const
|
|
3098
|
-
const
|
|
3099
|
-
const
|
|
3100
|
-
|
|
3101
|
-
const
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3852
|
+
const role = typeof inner.role === "string" ? inner.role : file?.role;
|
|
3853
|
+
const isUser = role === "user";
|
|
3854
|
+
const isAssistant = role === "assistant";
|
|
3855
|
+
const stamp = typeof file?.createdAt === "string" ? { timestamp: file.createdAt } : {};
|
|
3856
|
+
const blocks = Array.isArray(inner.content) ? inner.content : [];
|
|
3857
|
+
const texts = [];
|
|
3858
|
+
const calls = [];
|
|
3859
|
+
for (const block of blocks) {
|
|
3860
|
+
if (!block || typeof block !== "object") continue;
|
|
3861
|
+
const { type, text, toolName, args } = block;
|
|
3862
|
+
if (type === "text" && typeof text === "string") texts.push(text);
|
|
3863
|
+
else if (type === "tool-call" && typeof toolName === "string")
|
|
3864
|
+
calls.push({ name: toolName, args });
|
|
3865
|
+
}
|
|
3866
|
+
if (texts.length) {
|
|
3867
|
+
const raw = texts.join("\n");
|
|
3868
|
+
if (isUser) {
|
|
3869
|
+
const text = ideUserText(raw);
|
|
3870
|
+
if (text) turns.push({ role: "user", content: text, ...stamp });
|
|
3871
|
+
} else if (isAssistant) {
|
|
3872
|
+
const text = stripInjectedMemory(raw).trim();
|
|
3873
|
+
if (text) turns.push({ role: "assistant", content: text, ...stamp });
|
|
3874
|
+
}
|
|
3875
|
+
}
|
|
3876
|
+
for (const call of calls) {
|
|
3877
|
+
turns.push({ role: "action", content: actionLine(call.name, call.args), ...stamp });
|
|
3878
|
+
}
|
|
3108
3879
|
}
|
|
3109
3880
|
return turns;
|
|
3110
3881
|
}
|
|
3111
|
-
function
|
|
3112
|
-
|
|
3113
|
-
return readZcodeTranscript(path).filter((turn) => turn.role === "assistant").at(-1)?.content ?? "";
|
|
3882
|
+
function readCodebuddyTranscript(path) {
|
|
3883
|
+
return basename3(path) === "index.json" ? readCodebuddyIdeTranscript(path) : readWorkbuddyTranscript(path);
|
|
3114
3884
|
}
|
|
3115
3885
|
|
|
3116
3886
|
// src/harness/hook-lifecycle.ts
|
|
@@ -3191,7 +3961,7 @@ var copilotPrompt = {
|
|
|
3191
3961
|
${context}`.trim()
|
|
3192
3962
|
})
|
|
3193
3963
|
};
|
|
3194
|
-
var devinCwd = () => process.env.DEVIN_PROJECT_DIR;
|
|
3964
|
+
var devinCwd = () => process.env.DEVIN_PROJECT_DIR || process.cwd();
|
|
3195
3965
|
var devinPrompt = {
|
|
3196
3966
|
harness: "devin-cli",
|
|
3197
3967
|
requireCwd: true,
|
|
@@ -3218,6 +3988,36 @@ var standardSessionStart = (harness) => ({
|
|
|
3218
3988
|
}
|
|
3219
3989
|
})
|
|
3220
3990
|
});
|
|
3991
|
+
var genieSessionStart = (harness) => {
|
|
3992
|
+
const base = standardSessionStart(harness);
|
|
3993
|
+
return {
|
|
3994
|
+
...base,
|
|
3995
|
+
parse: (ev) => ({
|
|
3996
|
+
cwd: ev.cwd || process.env.CODEBUDDY_PROJECT_DIR,
|
|
3997
|
+
sessionId: ev.session_id
|
|
3998
|
+
}),
|
|
3999
|
+
emit: (out) => ({ ...base.emit(out), suppressOutput: true })
|
|
4000
|
+
};
|
|
4001
|
+
};
|
|
4002
|
+
var geniePrompt = (harness) => ({
|
|
4003
|
+
...claudePrompt,
|
|
4004
|
+
harness,
|
|
4005
|
+
emit: (context, notice, ev) => ({
|
|
4006
|
+
...claudePrompt.emit(context, notice, ev),
|
|
4007
|
+
suppressOutput: true
|
|
4008
|
+
})
|
|
4009
|
+
});
|
|
4010
|
+
var genieRetain = (harness, readTranscript) => ({
|
|
4011
|
+
hostTimeoutSec: 60,
|
|
4012
|
+
harness,
|
|
4013
|
+
parse: (ev) => ({
|
|
4014
|
+
sessionId: ev.session_id,
|
|
4015
|
+
transcriptPath: ev.transcript_path,
|
|
4016
|
+
cwd: ev.cwd
|
|
4017
|
+
}),
|
|
4018
|
+
readTranscript
|
|
4019
|
+
});
|
|
4020
|
+
var notGrokHosted = () => !process.env.GROK_HOOK_EVENT;
|
|
3221
4021
|
var HOOK_HARNESSES = {
|
|
3222
4022
|
"claude-code": {
|
|
3223
4023
|
configStyle: "nested",
|
|
@@ -3226,11 +4026,12 @@ var HOOK_HARNESSES = {
|
|
|
3226
4026
|
prompt: { event: "UserPromptSubmit", entry: "claude-hook.js", timeout: 30 },
|
|
3227
4027
|
stop: { event: "Stop", entry: "claude-stop-hook.js", timeout: 60 }
|
|
3228
4028
|
},
|
|
3229
|
-
sessionStart: standardSessionStart("claude-code"),
|
|
3230
|
-
prompt: claudePrompt,
|
|
4029
|
+
sessionStart: { ...standardSessionStart("claude-code"), accept: notGrokHosted },
|
|
4030
|
+
prompt: { ...claudePrompt, accept: notGrokHosted },
|
|
3231
4031
|
retain: {
|
|
3232
4032
|
hostTimeoutSec: 60,
|
|
3233
4033
|
harness: "claude-code",
|
|
4034
|
+
accept: notGrokHosted,
|
|
3234
4035
|
parse: (ev) => ({
|
|
3235
4036
|
sessionId: ev.session_id,
|
|
3236
4037
|
transcriptPath: ev.transcript_path,
|
|
@@ -3413,17 +4214,29 @@ var HOOK_HARNESSES = {
|
|
|
3413
4214
|
prompt: { event: "UserPromptSubmit", entry: "grok-hook.js", timeout: 30 },
|
|
3414
4215
|
stop: { event: "Stop", entry: "grok-stop-hook.js", timeout: 60 }
|
|
3415
4216
|
},
|
|
4217
|
+
// Grok hands the model `additionalContext` from TOOL hooks only: SessionStart is observe-only
|
|
4218
|
+
// and UserPromptSubmit can only block (#5467). Both stash their context instead, and the
|
|
4219
|
+
// prompt entry, also registered on PostToolUse, delivers it beside the next tool result.
|
|
4220
|
+
additionalHooks: [{ event: "PostToolUse", entry: "grok-hook.js", timeout: 30 }],
|
|
3416
4221
|
sessionStart: {
|
|
3417
4222
|
...standardSessionStart("grok-build"),
|
|
3418
4223
|
// Grok's wire envelope is camelCase, unlike Claude's similarly named hook events.
|
|
3419
4224
|
parse: (ev) => ({
|
|
3420
4225
|
cwd: ev.cwd,
|
|
3421
4226
|
sessionId: ev.sessionId
|
|
3422
|
-
})
|
|
4227
|
+
}),
|
|
4228
|
+
deferContextToToolHook: true
|
|
3423
4229
|
},
|
|
3424
4230
|
prompt: {
|
|
3425
4231
|
...claudePrompt,
|
|
3426
4232
|
harness: "grok-build",
|
|
4233
|
+
toolHook: {
|
|
4234
|
+
// Grok names the event twice: snake_case `hookEventName`, plus a Claude-named alias.
|
|
4235
|
+
accept: (ev) => ev.hookEventName === "post_tool_use" || ev.hook_event_name === "PostToolUse",
|
|
4236
|
+
emit: (context) => ({
|
|
4237
|
+
hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: context }
|
|
4238
|
+
})
|
|
4239
|
+
},
|
|
3427
4240
|
parse: (ev) => ({
|
|
3428
4241
|
prompt: ev.prompt,
|
|
3429
4242
|
cwd: ev.cwd,
|
|
@@ -3546,37 +4359,190 @@ var HOOK_HARNESSES = {
|
|
|
3546
4359
|
assistantText: (ev) => (ev.responseText || zcodeAssistantText(ev.transcript_path) || ev.responsePreview || "").trim()
|
|
3547
4360
|
}
|
|
3548
4361
|
}
|
|
4362
|
+
},
|
|
4363
|
+
/**
|
|
4364
|
+
* TraeCode (TRAE CN's agent) also speaks Claude Code's hook protocol — `prompt`/`cwd`/`session_id`
|
|
4365
|
+
* in, `hookSpecificOutput.additionalContext` + `systemMessage` out — with registrations nested
|
|
4366
|
+
* under the top-level `hooks` key of `~/.trae-cn/hooks.json` (unlike Factory Droid, whose event
|
|
4367
|
+
* map IS the file) and a `version` field the host writes and expects.
|
|
4368
|
+
*
|
|
4369
|
+
* Like ZCode, what it does not have is a TRANSCRIPT: sessions live in an encrypted local DB or
|
|
4370
|
+
* the cloud and no `transcript_path` is ever supplied, so this is the second harness that retains
|
|
4371
|
+
* from the plugin's own journal (core/turn-journal.ts) — the prompt hook appends the user turn,
|
|
4372
|
+
* and Stop's `last_assistant_message` (the full reply) plays the role ZCode's `responseText`
|
|
4373
|
+
* plays: `journal.assistantText` closes the turn with it.
|
|
4374
|
+
*/
|
|
4375
|
+
traecode: {
|
|
4376
|
+
configStyle: "nested",
|
|
4377
|
+
install: {
|
|
4378
|
+
sessionStart: { event: "SessionStart", entry: "traecode-sessionstart-hook.js", timeout: 30 },
|
|
4379
|
+
prompt: { event: "UserPromptSubmit", entry: "traecode-hook.js", timeout: 30 },
|
|
4380
|
+
stop: { event: "Stop", entry: "traecode-stop-hook.js", timeout: 60 }
|
|
4381
|
+
},
|
|
4382
|
+
sessionStart: {
|
|
4383
|
+
...standardSessionStart("traecode"),
|
|
4384
|
+
// Trae launches USER-level MCP servers from the Electron process's cwd (home), where an
|
|
4385
|
+
// optInOnly config self-disables and the tools vanish. Each repo's own workspace file fixes
|
|
4386
|
+
// it — kept current here, once memory is confirmed live for the repo, along with the
|
|
4387
|
+
// workspace's per-server enable switch (seeded into Trae's storage DB,
|
|
4388
|
+
// core/traecode-mcp.ts). The returned hint (global gate off, or an unseedable switch)
|
|
4389
|
+
// rides the session banner.
|
|
4390
|
+
ensureMcpRegistration: (cwd) => ensureTraecodeWorkspaceMcp(cwd)
|
|
4391
|
+
},
|
|
4392
|
+
prompt: {
|
|
4393
|
+
...claudePrompt,
|
|
4394
|
+
harness: "traecode",
|
|
4395
|
+
journalPrompt: true,
|
|
4396
|
+
// TraeCode's UserPromptSubmit payload carries `prompt` exactly like Claude Code's.
|
|
4397
|
+
parse: (ev) => ({
|
|
4398
|
+
prompt: ev.prompt,
|
|
4399
|
+
cwd: ev.cwd,
|
|
4400
|
+
sessionId: ev.session_id
|
|
4401
|
+
})
|
|
4402
|
+
},
|
|
4403
|
+
retain: {
|
|
4404
|
+
hostTimeoutSec: 60,
|
|
4405
|
+
harness: "traecode",
|
|
4406
|
+
// No transcriptPath: the journal supplies it (see `journal` below).
|
|
4407
|
+
parse: (ev) => ({
|
|
4408
|
+
sessionId: ev.session_id,
|
|
4409
|
+
cwd: ev.cwd
|
|
4410
|
+
}),
|
|
4411
|
+
journal: {
|
|
4412
|
+
// `last_assistant_message` is the full reply — TraeCode's `responseText`.
|
|
4413
|
+
assistantText: (ev) => (ev.last_assistant_message ?? "").trim()
|
|
4414
|
+
}
|
|
4415
|
+
}
|
|
4416
|
+
},
|
|
4417
|
+
"kimi-code": {
|
|
4418
|
+
// Kimi's ~/.kimi-code/config.toml takes a FLAT [[hooks]] array whose entries are validated by a
|
|
4419
|
+
// strict 4-key schema (event/matcher/command/timeout). Neither JSON style can express it, and a
|
|
4420
|
+
// fifth key drops EVERY hook in the file at warning severity, so its installer writes the block
|
|
4421
|
+
// itself (the grok-build pattern) rather than going through mergeHarnessHooks.
|
|
4422
|
+
configStyle: "toml-array",
|
|
4423
|
+
install: {
|
|
4424
|
+
// Timeouts are SECONDS here (integer 1-600, default 30) — the same unit as every other
|
|
4425
|
+
// supported host, and the opposite of qwen-code's identically named field.
|
|
4426
|
+
sessionStart: { event: "SessionStart", entry: "kimi-sessionstart-hook.js", timeout: 30 },
|
|
4427
|
+
prompt: { event: "UserPromptSubmit", entry: "kimi-hook.js", timeout: 30 },
|
|
4428
|
+
stop: { event: "Stop", entry: "kimi-stop-hook.js", timeout: 60 }
|
|
4429
|
+
},
|
|
4430
|
+
sessionStart: {
|
|
4431
|
+
harness: "kimi-code",
|
|
4432
|
+
parse: (ev) => ({
|
|
4433
|
+
cwd: ev.cwd,
|
|
4434
|
+
sessionId: ev.session_id
|
|
4435
|
+
}),
|
|
4436
|
+
// Kimi runs SessionStart hooks for their side effects only: it awaits the trigger and drops
|
|
4437
|
+
// the result, so nothing emitted here can reach the model or the terminal. Installed for the
|
|
4438
|
+
// seed/daemon/session-root work runSessionStartHook does, and silent like antigravity-cli's.
|
|
4439
|
+
emit: () => ({})
|
|
4440
|
+
},
|
|
4441
|
+
prompt: {
|
|
4442
|
+
harness: "kimi-code",
|
|
4443
|
+
parse: (ev) => ({
|
|
4444
|
+
// A block array, not a string — the same shape as the wire log's `turn.prompt.input`.
|
|
4445
|
+
prompt: kimiPromptText(ev.prompt),
|
|
4446
|
+
cwd: ev.cwd,
|
|
4447
|
+
sessionId: ev.session_id
|
|
4448
|
+
}),
|
|
4449
|
+
// Kimi has no additionalContext: a top-level `message` is the injection channel, which the
|
|
4450
|
+
// CLI wraps as <hook_result hook_event="UserPromptSubmit"> and appends to the conversation.
|
|
4451
|
+
// `notice` has no banner channel to reach (the copilot-cli precedent), but it cannot simply
|
|
4452
|
+
// be dropped: when a hook's stdout parses to JSON carrying no message, Kimi falls back to
|
|
4453
|
+
// injecting the RAW STDOUT, so an empty `{}` would put a literal "{}" in front of the model.
|
|
4454
|
+
// Emitting the notice on the notice-only turn is what keeps that from ever happening.
|
|
4455
|
+
emit: (context, notice) => ({ message: context || notice })
|
|
4456
|
+
},
|
|
4457
|
+
retain: {
|
|
4458
|
+
hostTimeoutSec: 60,
|
|
4459
|
+
harness: "kimi-code",
|
|
4460
|
+
parse: (ev) => {
|
|
4461
|
+
const sessionId = ev.session_id;
|
|
4462
|
+
return {
|
|
4463
|
+
sessionId,
|
|
4464
|
+
// Kimi's Stop payload carries no transcript path — its hook feature has no such field at
|
|
4465
|
+
// all — so resolve the session's own directory from the id, as grok-build does. The
|
|
4466
|
+
// reader takes that DIRECTORY and reads every agent's wire.jsonl beneath it.
|
|
4467
|
+
transcriptPath: sessionId ? kimiSessionDir(sessionId) : void 0,
|
|
4468
|
+
cwd: ev.cwd
|
|
4469
|
+
};
|
|
4470
|
+
},
|
|
4471
|
+
readTranscript: readKimiTranscript
|
|
4472
|
+
}
|
|
4473
|
+
},
|
|
4474
|
+
/**
|
|
4475
|
+
* WorkBuddy (Tencent's AI workbench) keeps a durable transcript at
|
|
4476
|
+
* ~/.workbuddy/projects/<cwd-encoded>/<uuid>.jsonl and speaks Claude's hook protocol —
|
|
4477
|
+
* `session_id` / `transcript_path` / `cwd` in, hookSpecificOutput + systemMessage out — apart
|
|
4478
|
+
* from the two quirks genieSessionStart/geniePrompt handle. The other host-specific piece is the
|
|
4479
|
+
* transcript SCHEMA: `type:"message"` records carrying top-level `role`/`content`, which
|
|
4480
|
+
* core/transcript-workbuddy.ts normalizes. Its Stop payload fills `transcript_path` for real (the
|
|
4481
|
+
* engine's own getHookTranscriptPath), so it retains through `readTranscript` like every other
|
|
4482
|
+
* file-backed host rather than the journal ZCode needs.
|
|
4483
|
+
* CodeBuddy Code ships the same @genie/agent-cli engine and reuses this reader (see `codebuddy`).
|
|
4484
|
+
*/
|
|
4485
|
+
workbuddy: {
|
|
4486
|
+
configStyle: "nested",
|
|
4487
|
+
install: {
|
|
4488
|
+
sessionStart: { event: "SessionStart", entry: "workbuddy-sessionstart-hook.js", timeout: 30 },
|
|
4489
|
+
prompt: { event: "UserPromptSubmit", entry: "workbuddy-hook.js", timeout: 30 },
|
|
4490
|
+
stop: { event: "Stop", entry: "workbuddy-stop-hook.js", timeout: 60 }
|
|
4491
|
+
},
|
|
4492
|
+
sessionStart: genieSessionStart("workbuddy"),
|
|
4493
|
+
prompt: geniePrompt("workbuddy"),
|
|
4494
|
+
retain: genieRetain("workbuddy", readWorkbuddyTranscript)
|
|
4495
|
+
},
|
|
4496
|
+
/**
|
|
4497
|
+
* CodeBuddy — the same `@genie/agent-cli` engine WorkBuddy ships, running under its own product
|
|
4498
|
+
* config (`~/.codebuddy`; WorkBuddy only renames the home folder). Hook names and payload shape
|
|
4499
|
+
* are identical, so this spec differs from `workbuddy` in the files the installer writes, the
|
|
4500
|
+
* harness name stamped on what it retains — and ONE thing more: CodeBuddy ships in two hosts whose
|
|
4501
|
+
* transcripts do NOT look alike. CodeBuddy Code (the CLI) writes the WorkBuddy JSONL, while the
|
|
4502
|
+
* IDE hands the Stop hook its own `<conversation>/index.json` directory layout. So the reader is
|
|
4503
|
+
* a dispatcher on the shape it was handed (core/transcript-codebuddy-ide.ts).
|
|
4504
|
+
*/
|
|
4505
|
+
codebuddy: {
|
|
4506
|
+
configStyle: "nested",
|
|
4507
|
+
install: {
|
|
4508
|
+
sessionStart: { event: "SessionStart", entry: "codebuddy-sessionstart-hook.js", timeout: 30 },
|
|
4509
|
+
prompt: { event: "UserPromptSubmit", entry: "codebuddy-hook.js", timeout: 30 },
|
|
4510
|
+
stop: { event: "Stop", entry: "codebuddy-stop-hook.js", timeout: 60 }
|
|
4511
|
+
},
|
|
4512
|
+
sessionStart: genieSessionStart("codebuddy"),
|
|
4513
|
+
prompt: geniePrompt("codebuddy"),
|
|
4514
|
+
retain: genieRetain("codebuddy", readCodebuddyTranscript)
|
|
3549
4515
|
}
|
|
3550
4516
|
};
|
|
3551
4517
|
|
|
3552
4518
|
// src/core/history.ts
|
|
3553
|
-
import { execFileSync as
|
|
4519
|
+
import { execFileSync as execFileSync6 } from "child_process";
|
|
3554
4520
|
import {
|
|
3555
4521
|
closeSync as closeSync2,
|
|
3556
|
-
existsSync as
|
|
4522
|
+
existsSync as existsSync12,
|
|
3557
4523
|
openSync as openSync2,
|
|
3558
|
-
readdirSync as
|
|
4524
|
+
readdirSync as readdirSync5,
|
|
3559
4525
|
readFileSync as readFileSync14,
|
|
3560
4526
|
readSync as readSync2,
|
|
3561
4527
|
statSync as statSync4
|
|
3562
4528
|
} from "fs";
|
|
3563
4529
|
import { createHash as createHash5 } from "crypto";
|
|
3564
|
-
import { homedir as
|
|
3565
|
-
import { join as
|
|
4530
|
+
import { homedir as homedir12 } from "os";
|
|
4531
|
+
import { join as join23 } from "path";
|
|
3566
4532
|
import * as zlib2 from "zlib";
|
|
3567
4533
|
|
|
3568
4534
|
// src/core/transcript-dsh.ts
|
|
3569
4535
|
function textOf(message) {
|
|
3570
4536
|
return (message.content || []).filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n").trim();
|
|
3571
4537
|
}
|
|
3572
|
-
function
|
|
4538
|
+
function stampOf4(event) {
|
|
3573
4539
|
return typeof event.time === "number" ? { timestamp: new Date(event.time).toISOString() } : {};
|
|
3574
4540
|
}
|
|
3575
4541
|
function readDshEvents(events) {
|
|
3576
4542
|
const turns = [];
|
|
3577
4543
|
for (const event of events || []) {
|
|
3578
4544
|
if (!event || typeof event !== "object") continue;
|
|
3579
|
-
const stamp =
|
|
4545
|
+
const stamp = stampOf4(event);
|
|
3580
4546
|
if (event.type === "user/message") {
|
|
3581
4547
|
const message = event.data;
|
|
3582
4548
|
if (!message || message.source?.kind !== "user") continue;
|
|
@@ -3592,14 +4558,14 @@ function readDshEvents(events) {
|
|
|
3592
4558
|
if (!call?.name) continue;
|
|
3593
4559
|
turns.push({
|
|
3594
4560
|
role: "action",
|
|
3595
|
-
content: actionLine(call.name,
|
|
4561
|
+
content: actionLine(call.name, parseArgs3(call.arguments)),
|
|
3596
4562
|
...stamp
|
|
3597
4563
|
});
|
|
3598
4564
|
}
|
|
3599
4565
|
}
|
|
3600
4566
|
return turns;
|
|
3601
4567
|
}
|
|
3602
|
-
function
|
|
4568
|
+
function parseArgs3(raw) {
|
|
3603
4569
|
if (!raw) return void 0;
|
|
3604
4570
|
try {
|
|
3605
4571
|
return JSON.parse(raw);
|
|
@@ -3637,7 +4603,7 @@ function renderMessage(m) {
|
|
|
3637
4603
|
return out;
|
|
3638
4604
|
}
|
|
3639
4605
|
function readPiTranscript(path) {
|
|
3640
|
-
const
|
|
4606
|
+
const entries = [];
|
|
3641
4607
|
for (const rawLine of readJsonl(path)) {
|
|
3642
4608
|
const trimmed = rawLine.trim();
|
|
3643
4609
|
if (!trimmed) continue;
|
|
@@ -3647,9 +4613,14 @@ function readPiTranscript(path) {
|
|
|
3647
4613
|
} catch {
|
|
3648
4614
|
continue;
|
|
3649
4615
|
}
|
|
3650
|
-
if (typeof parsed
|
|
3651
|
-
|
|
3652
|
-
|
|
4616
|
+
if (typeof parsed === "object" && parsed !== null) entries.push(parsed);
|
|
4617
|
+
}
|
|
4618
|
+
return readPiEntries(entries);
|
|
4619
|
+
}
|
|
4620
|
+
function readPiEntries(entries) {
|
|
4621
|
+
const turns = [];
|
|
4622
|
+
for (const entry of entries) {
|
|
4623
|
+
if (!entry || entry.type !== "message" || !entry.message) continue;
|
|
3653
4624
|
for (const turn of renderMessage(entry.message)) {
|
|
3654
4625
|
turns.push(entry.timestamp ? { ...turn, timestamp: entry.timestamp } : turn);
|
|
3655
4626
|
}
|
|
@@ -3706,8 +4677,8 @@ function zstdDecompressFrames(buffer) {
|
|
|
3706
4677
|
}
|
|
3707
4678
|
|
|
3708
4679
|
// src/core/history.ts
|
|
3709
|
-
function claudeProjectDir(repoDir, home =
|
|
3710
|
-
return
|
|
4680
|
+
function claudeProjectDir(repoDir, home = homedir12()) {
|
|
4681
|
+
return join23(home, ".claude", "projects", repoDir.replace(/[^a-zA-Z0-9]/g, "-"));
|
|
3711
4682
|
}
|
|
3712
4683
|
function piSessionDir(repoDir) {
|
|
3713
4684
|
return `--${repoDir.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
|
|
@@ -3753,19 +4724,19 @@ function firstLine(path, cap = 1e6) {
|
|
|
3753
4724
|
}
|
|
3754
4725
|
function listDir(dir) {
|
|
3755
4726
|
try {
|
|
3756
|
-
return
|
|
4727
|
+
return readdirSync5(dir);
|
|
3757
4728
|
} catch {
|
|
3758
4729
|
return [];
|
|
3759
4730
|
}
|
|
3760
4731
|
}
|
|
3761
4732
|
function jsonlFiles(dir) {
|
|
3762
|
-
return listDir(dir).filter((f) => f.endsWith(".jsonl")).map((f) =>
|
|
4733
|
+
return listDir(dir).filter((f) => f.endsWith(".jsonl")).map((f) => join23(dir, f));
|
|
3763
4734
|
}
|
|
3764
4735
|
function claudeHistory(repoDir, home) {
|
|
3765
|
-
const root =
|
|
4736
|
+
const root = join23(home, ".claude", "projects");
|
|
3766
4737
|
const exact = claudeProjectDir(repoDir, home);
|
|
3767
4738
|
const prefix = exact + "-";
|
|
3768
|
-
const dirs = listDir(root).map((d) =>
|
|
4739
|
+
const dirs = listDir(root).map((d) => join23(root, d)).filter((d) => d === exact || d.startsWith(prefix));
|
|
3769
4740
|
const sessions = [];
|
|
3770
4741
|
let unattributed = 0;
|
|
3771
4742
|
for (const file of dirs.flatMap(jsonlFiles)) {
|
|
@@ -3785,12 +4756,12 @@ function claudeHistory(repoDir, home) {
|
|
|
3785
4756
|
return { supported: true, sessions, unattributed };
|
|
3786
4757
|
}
|
|
3787
4758
|
function codexHistory(repoDir, home) {
|
|
3788
|
-
const root =
|
|
3789
|
-
if (!
|
|
4759
|
+
const root = join23(home, ".codex", "sessions");
|
|
4760
|
+
if (!existsSync12(root)) return { supported: true, sessions: [] };
|
|
3790
4761
|
const files = [];
|
|
3791
4762
|
const walk = (dir) => {
|
|
3792
|
-
for (const entry of
|
|
3793
|
-
const p =
|
|
4763
|
+
for (const entry of readdirSync5(dir)) {
|
|
4764
|
+
const p = join23(dir, entry);
|
|
3794
4765
|
if (statSync4(p).isDirectory()) walk(p);
|
|
3795
4766
|
else if (entry.endsWith(".jsonl")) files.push(p);
|
|
3796
4767
|
}
|
|
@@ -3819,15 +4790,15 @@ function dcodeTranscriptPath(root, threadId) {
|
|
|
3819
4790
|
const digest = createHash5("sha256").update(threadId, "utf8").digest("hex");
|
|
3820
4791
|
const suffix = `--${digest}.jsonl`;
|
|
3821
4792
|
try {
|
|
3822
|
-
const match =
|
|
3823
|
-
return match ?
|
|
4793
|
+
const match = readdirSync5(root).find((entry) => entry.endsWith(suffix));
|
|
4794
|
+
return match ? join23(root, match) : void 0;
|
|
3824
4795
|
} catch {
|
|
3825
4796
|
return void 0;
|
|
3826
4797
|
}
|
|
3827
4798
|
}
|
|
3828
4799
|
function dcodeHistory(repoDir, home, runCli) {
|
|
3829
|
-
const root =
|
|
3830
|
-
if (!
|
|
4800
|
+
const root = join23(process.env.DEEPAGENTS_HOME || join23(home, ".deepagents"), "transcripts");
|
|
4801
|
+
if (!existsSync12(root)) return { supported: true, sessions: [] };
|
|
3831
4802
|
let listed;
|
|
3832
4803
|
try {
|
|
3833
4804
|
listed = JSON.parse(runCli(["threads", "list", "--json"]));
|
|
@@ -3867,8 +4838,8 @@ function dcodeHistory(repoDir, home, runCli) {
|
|
|
3867
4838
|
return { supported: true, sessions, ...unattributed ? { unattributed } : {} };
|
|
3868
4839
|
}
|
|
3869
4840
|
function dshHistory(repoDir, home) {
|
|
3870
|
-
const root = process.env.DSH_HOME ?
|
|
3871
|
-
if (!
|
|
4841
|
+
const root = process.env.DSH_HOME ? join23(process.env.DSH_HOME, "sessions") : join23(home, ".dsh", "sessions");
|
|
4842
|
+
if (!existsSync12(root)) return { supported: true, sessions: [] };
|
|
3872
4843
|
if (typeof zlib2.zstdDecompressSync !== "function") {
|
|
3873
4844
|
return {
|
|
3874
4845
|
supported: false,
|
|
@@ -3878,15 +4849,15 @@ function dshHistory(repoDir, home) {
|
|
|
3878
4849
|
}
|
|
3879
4850
|
const sessions = [];
|
|
3880
4851
|
let unattributed = 0;
|
|
3881
|
-
for (const dir of
|
|
4852
|
+
for (const dir of readdirSync5(root).map((project) => join23(root, project))) {
|
|
3882
4853
|
let sessionDirs;
|
|
3883
4854
|
try {
|
|
3884
|
-
sessionDirs =
|
|
4855
|
+
sessionDirs = readdirSync5(dir).map((id) => join23(dir, id));
|
|
3885
4856
|
} catch {
|
|
3886
4857
|
continue;
|
|
3887
4858
|
}
|
|
3888
4859
|
for (const sessionDir of sessionDirs) {
|
|
3889
|
-
const file = ["session.jsonl.zstd", "session.jsonl"].map((name) =>
|
|
4860
|
+
const file = ["session.jsonl.zstd", "session.jsonl"].map((name) => join23(sessionDir, name)).find((candidate) => existsSync12(candidate));
|
|
3890
4861
|
if (!file) continue;
|
|
3891
4862
|
try {
|
|
3892
4863
|
const lines = readDshLog(file);
|
|
@@ -3938,23 +4909,23 @@ function piFamilySessions(files, repoDir) {
|
|
|
3938
4909
|
return { supported: true, sessions, unattributed };
|
|
3939
4910
|
}
|
|
3940
4911
|
function piHistory(repoDir, home) {
|
|
3941
|
-
const root =
|
|
3942
|
-
if (!
|
|
4912
|
+
const root = join23(home, ".pi", "agent", "sessions");
|
|
4913
|
+
if (!existsSync12(root)) return { supported: true, sessions: [] };
|
|
3943
4914
|
const exact = piSessionDir(repoDir);
|
|
3944
4915
|
const nested = `${exact.slice(0, -2)}-`;
|
|
3945
4916
|
const files = [];
|
|
3946
4917
|
for (const dir of listDir(root).filter((d) => d === exact || d.startsWith(nested))) {
|
|
3947
|
-
files.push(...jsonlFiles(
|
|
4918
|
+
files.push(...jsonlFiles(join23(root, dir)));
|
|
3948
4919
|
}
|
|
3949
4920
|
return piFamilySessions(files, repoDir);
|
|
3950
4921
|
}
|
|
3951
4922
|
function primeAgentHistory(repoDir, home) {
|
|
3952
|
-
const root =
|
|
3953
|
-
if (!
|
|
4923
|
+
const root = join23(home, ".prime", "agent", "sessions");
|
|
4924
|
+
if (!existsSync12(root)) return { supported: true, sessions: [] };
|
|
3954
4925
|
return piFamilySessions(jsonlFiles(root), repoDir);
|
|
3955
4926
|
}
|
|
3956
4927
|
var SQLITE_HISTORY = "keeps session history in an internal SQLite database, whose schema is unversioned and would break on any upstream change";
|
|
3957
|
-
function importLocalHistory(harness, repoDir, home =
|
|
4928
|
+
function importLocalHistory(harness, repoDir, home = homedir12(), runDcodeCli) {
|
|
3958
4929
|
switch (harness) {
|
|
3959
4930
|
case "claude-code":
|
|
3960
4931
|
return claudeHistory(repoDir, home);
|
|
@@ -3964,7 +4935,7 @@ function importLocalHistory(harness, repoDir, home = homedir10(), runDcodeCli) {
|
|
|
3964
4935
|
return dcodeHistory(
|
|
3965
4936
|
repoDir,
|
|
3966
4937
|
home,
|
|
3967
|
-
runDcodeCli ?? ((args) =>
|
|
4938
|
+
runDcodeCli ?? ((args) => execFileSync6("dcode", args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }))
|
|
3968
4939
|
);
|
|
3969
4940
|
case "dsh":
|
|
3970
4941
|
return dshHistory(repoDir, home);
|
|
@@ -3981,10 +4952,14 @@ function importLocalHistory(harness, repoDir, home = homedir10(), runDcodeCli) {
|
|
|
3981
4952
|
case "copilot-cli":
|
|
3982
4953
|
case "devin-cli":
|
|
3983
4954
|
return { supported: false, reason: `${harness} ${SQLITE_HISTORY}`, sessions: [] };
|
|
4955
|
+
// TraeCode has no reader for the same reason as ZCode below: no session files on disk at all
|
|
4956
|
+
// (sessions live in an encrypted local DB / the cloud), which is why the plugin journals live
|
|
4957
|
+
// sessions itself (core/turn-journal.ts) — and why there is no past history to backfill from.
|
|
4958
|
+
case "traecode":
|
|
3984
4959
|
case "zcode":
|
|
3985
4960
|
return {
|
|
3986
4961
|
supported: false,
|
|
3987
|
-
reason:
|
|
4962
|
+
reason: `${harness} keeps no session transcripts on disk to import`,
|
|
3988
4963
|
sessions: []
|
|
3989
4964
|
};
|
|
3990
4965
|
default:
|
|
@@ -3993,7 +4968,7 @@ function importLocalHistory(harness, repoDir, home = homedir10(), runDcodeCli) {
|
|
|
3993
4968
|
}
|
|
3994
4969
|
|
|
3995
4970
|
// src/install-ui.ts
|
|
3996
|
-
import { execFileSync as
|
|
4971
|
+
import { execFileSync as execFileSync7 } from "child_process";
|
|
3997
4972
|
import { readSync as readSync3 } from "fs";
|
|
3998
4973
|
function fitSelectRow(label, hint, width) {
|
|
3999
4974
|
const room = Math.max(10, width - 6);
|
|
@@ -4088,7 +5063,7 @@ function createInstallerUi(o) {
|
|
|
4088
5063
|
return `${bar} ${question}`;
|
|
4089
5064
|
},
|
|
4090
5065
|
select(question, options, defaultIndex) {
|
|
4091
|
-
const stty = (args) =>
|
|
5066
|
+
const stty = (args) => execFileSync7("stty", args, { stdio: ["inherit", "pipe", "pipe"], encoding: "utf8" }).trim();
|
|
4092
5067
|
let savedTty;
|
|
4093
5068
|
try {
|
|
4094
5069
|
savedTty = stty(["-g"]);
|
|
@@ -4197,10 +5172,14 @@ function createInstallerUi(o) {
|
|
|
4197
5172
|
// src/installer.ts
|
|
4198
5173
|
var MARKER = "coding-agents";
|
|
4199
5174
|
var ZCODE_MAX_OUTPUT_BYTES = 32768;
|
|
4200
|
-
var zcodeConfigPath = (c) =>
|
|
4201
|
-
function
|
|
5175
|
+
var zcodeConfigPath = (c) => join24(c.home, ".zcode", "cli", "config.json");
|
|
5176
|
+
function isPlainObject(value) {
|
|
5177
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5178
|
+
}
|
|
5179
|
+
function readJson2(path) {
|
|
4202
5180
|
try {
|
|
4203
|
-
|
|
5181
|
+
const parsed = JSON.parse(readFileSync15(path, "utf8"));
|
|
5182
|
+
return isPlainObject(parsed) ? parsed : {};
|
|
4204
5183
|
} catch {
|
|
4205
5184
|
return {};
|
|
4206
5185
|
}
|
|
@@ -4215,17 +5194,17 @@ function parseJsonc(text) {
|
|
|
4215
5194
|
}
|
|
4216
5195
|
}
|
|
4217
5196
|
function writeJson(path, value) {
|
|
4218
|
-
|
|
5197
|
+
mkdirSync7(dirname13(path), { recursive: true });
|
|
4219
5198
|
backupOnce(path);
|
|
4220
|
-
|
|
5199
|
+
writeFileSync5(path, JSON.stringify(value, null, 2) + "\n");
|
|
4221
5200
|
}
|
|
4222
5201
|
function backupOnce(path) {
|
|
4223
|
-
if (
|
|
5202
|
+
if (existsSync13(path) && !existsSync13(`${path}.hindsight-backup`)) {
|
|
4224
5203
|
copyFileSync(path, `${path}.hindsight-backup`);
|
|
4225
5204
|
}
|
|
4226
5205
|
}
|
|
4227
5206
|
function writeJsonc(path, key, value) {
|
|
4228
|
-
const text =
|
|
5207
|
+
const text = existsSync13(path) ? readFileSync15(path, "utf8") : "";
|
|
4229
5208
|
const edits = modify(text, [key], value, {
|
|
4230
5209
|
formattingOptions: {
|
|
4231
5210
|
tabSize: 2,
|
|
@@ -4236,9 +5215,9 @@ function writeJsonc(path, key, value) {
|
|
|
4236
5215
|
}
|
|
4237
5216
|
});
|
|
4238
5217
|
const next = applyEdits(text, edits);
|
|
4239
|
-
|
|
5218
|
+
mkdirSync7(dirname13(path), { recursive: true });
|
|
4240
5219
|
backupOnce(path);
|
|
4241
|
-
|
|
5220
|
+
writeFileSync5(path, next.endsWith("\n") ? next : `${next}
|
|
4242
5221
|
`);
|
|
4243
5222
|
}
|
|
4244
5223
|
function mergeHookEvent(existing, entry) {
|
|
@@ -4253,33 +5232,26 @@ function setOrDelete(obj, key, arr) {
|
|
|
4253
5232
|
else delete obj[key];
|
|
4254
5233
|
}
|
|
4255
5234
|
var cmdHook = (dist, file, timeout) => ({
|
|
4256
|
-
hooks: [{ type: "command", command: `node "${
|
|
5235
|
+
hooks: [{ type: "command", command: `node "${join24(dist, file)}"`, timeout }]
|
|
4257
5236
|
});
|
|
4258
5237
|
var processHook = (dist, file, timeoutMs) => ({
|
|
4259
|
-
hooks: [{ type: "process", command: "node", args: [
|
|
5238
|
+
hooks: [{ type: "process", command: "node", args: [join24(dist, file)], timeoutMs }]
|
|
4260
5239
|
});
|
|
4261
|
-
var mcpServerEntry = (dist, harness) => ({
|
|
5240
|
+
var mcpServerEntry = (dist, harness, extraArgs = []) => ({
|
|
4262
5241
|
command: "node",
|
|
4263
|
-
args: [
|
|
5242
|
+
args: [join24(dist, "mcp-server.js"), ...extraArgs],
|
|
4264
5243
|
env: { HINDSIGHT_MCP_HARNESS: harness }
|
|
4265
5244
|
});
|
|
4266
|
-
function isOurMcpEntry(entry) {
|
|
4267
|
-
if (!entry || typeof entry !== "object") return false;
|
|
4268
|
-
const candidate = entry;
|
|
4269
|
-
if (candidate.command !== "node" || !Array.isArray(candidate.args)) return false;
|
|
4270
|
-
const script = candidate.args[0];
|
|
4271
|
-
if (typeof script !== "string") return false;
|
|
4272
|
-
const parts = script.replaceAll("\\", "/").split("/").filter(Boolean);
|
|
4273
|
-
return parts.at(-1) === "mcp-server.js" && parts.at(-2) === "dist" && (parts.at(-3) === "coding-agents" || parts.at(-3) === "hindsight-coding-agents");
|
|
4274
|
-
}
|
|
4275
5245
|
function mergeHarnessHooks(hooks, harness, dist) {
|
|
4276
5246
|
const spec = HOOK_HARNESSES[harness];
|
|
5247
|
+
if (spec.configStyle === "toml-array")
|
|
5248
|
+
throw new Error(`${harness} writes its own TOML hook block; mergeHarnessHooks cannot emit it`);
|
|
4277
5249
|
const installedEvents = /* @__PURE__ */ new Set();
|
|
4278
5250
|
for (const hook of [...Object.values(spec.install), ...spec.additionalHooks ?? []]) {
|
|
4279
5251
|
if (installedEvents.has(hook.event)) continue;
|
|
4280
5252
|
installedEvents.add(hook.event);
|
|
4281
5253
|
const entry = spec.configStyle === "nested" ? cmdHook(dist, hook.entry, hook.timeout) : spec.configStyle === "process" ? processHook(dist, hook.entry, hook.timeout) : {
|
|
4282
|
-
command: `node "${
|
|
5254
|
+
command: `node "${join24(dist, hook.entry)}"`,
|
|
4283
5255
|
...hook.timeout ? { timeout: hook.timeout } : {}
|
|
4284
5256
|
};
|
|
4285
5257
|
hooks[hook.event] = mergeHookEvent(hooks[hook.event], entry);
|
|
@@ -4295,28 +5267,28 @@ function stripHarnessHooks(hooks, harness) {
|
|
|
4295
5267
|
}
|
|
4296
5268
|
}
|
|
4297
5269
|
function skillsBaseFor(c, harness) {
|
|
4298
|
-
const parts =
|
|
5270
|
+
const parts = resolveSkillDirs(harness, c.home);
|
|
4299
5271
|
if (!parts) throw new Error(`${harness} installs a skill but names no directory in SKILL_DIRS`);
|
|
4300
|
-
return
|
|
5272
|
+
return join24(c.home, ...parts);
|
|
4301
5273
|
}
|
|
4302
5274
|
function installSkill(c, harness) {
|
|
4303
|
-
const src =
|
|
4304
|
-
if (!
|
|
5275
|
+
const src = join24(c.pkgRoot, "skill");
|
|
5276
|
+
if (!existsSync13(join24(src, "SKILL.md"))) return;
|
|
4305
5277
|
const skillsBase = skillsBaseFor(c, harness);
|
|
4306
|
-
const dst =
|
|
4307
|
-
|
|
5278
|
+
const dst = join24(skillsBase, "hindsight-coding-agent");
|
|
5279
|
+
mkdirSync7(skillsBase, { recursive: true });
|
|
4308
5280
|
cpSync2(src, dst, { recursive: true });
|
|
4309
5281
|
c.log?.(`${harness}: skill installed at ${dst}`);
|
|
4310
5282
|
}
|
|
4311
5283
|
function uninstallSkill(c, harness) {
|
|
4312
|
-
|
|
5284
|
+
rmSync4(join24(skillsBaseFor(c, harness), "hindsight-coding-agent"), {
|
|
4313
5285
|
recursive: true,
|
|
4314
5286
|
force: true
|
|
4315
5287
|
});
|
|
4316
5288
|
}
|
|
4317
5289
|
function onPath2(bin) {
|
|
4318
5290
|
try {
|
|
4319
|
-
|
|
5291
|
+
execFileSync8("which", [bin], { stdio: "pipe" });
|
|
4320
5292
|
return true;
|
|
4321
5293
|
} catch {
|
|
4322
5294
|
return false;
|
|
@@ -4324,7 +5296,7 @@ function onPath2(bin) {
|
|
|
4324
5296
|
}
|
|
4325
5297
|
function runClinePlugin(args) {
|
|
4326
5298
|
try {
|
|
4327
|
-
|
|
5299
|
+
execFileSync8("cline", args, { stdio: "pipe" });
|
|
4328
5300
|
return true;
|
|
4329
5301
|
} catch {
|
|
4330
5302
|
return false;
|
|
@@ -4332,13 +5304,13 @@ function runClinePlugin(args) {
|
|
|
4332
5304
|
}
|
|
4333
5305
|
var OPENCODE_CONFIG_CANDIDATES = ["opencode.jsonc", "opencode.json"];
|
|
4334
5306
|
function opencodeConfigPath(c) {
|
|
4335
|
-
const dir =
|
|
4336
|
-
const existing = OPENCODE_CONFIG_CANDIDATES.map((f) =>
|
|
4337
|
-
return existing ??
|
|
5307
|
+
const dir = join24(c.home, ".config", "opencode");
|
|
5308
|
+
const existing = OPENCODE_CONFIG_CANDIDATES.map((f) => join24(dir, f)).find((p) => existsSync13(p));
|
|
5309
|
+
return existing ?? join24(dir, "opencode.json");
|
|
4338
5310
|
}
|
|
4339
5311
|
function runDcodePlugin(args) {
|
|
4340
5312
|
try {
|
|
4341
|
-
|
|
5313
|
+
execFileSync8("dcode", args, { stdio: "pipe" });
|
|
4342
5314
|
return true;
|
|
4343
5315
|
} catch {
|
|
4344
5316
|
return false;
|
|
@@ -4347,7 +5319,7 @@ function runDcodePlugin(args) {
|
|
|
4347
5319
|
function registerOpencodePlugin(c, name) {
|
|
4348
5320
|
const path = opencodeConfigPath(c);
|
|
4349
5321
|
let cfg = {};
|
|
4350
|
-
if (
|
|
5322
|
+
if (existsSync13(path)) {
|
|
4351
5323
|
const parsed = parseJsonc(readFileSync15(path, "utf8"));
|
|
4352
5324
|
if (!parsed) {
|
|
4353
5325
|
c.log?.(`${name}: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
|
|
@@ -4361,7 +5333,7 @@ function registerOpencodePlugin(c, name) {
|
|
|
4361
5333
|
}
|
|
4362
5334
|
function unregisterOpencodePlugin(c, name) {
|
|
4363
5335
|
const path = opencodeConfigPath(c);
|
|
4364
|
-
if (!
|
|
5336
|
+
if (!existsSync13(path)) return;
|
|
4365
5337
|
const cfg = parseJsonc(readFileSync15(path, "utf8"));
|
|
4366
5338
|
if (!cfg || !Array.isArray(cfg.plugin)) return;
|
|
4367
5339
|
const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
|
|
@@ -4370,7 +5342,7 @@ function unregisterOpencodePlugin(c, name) {
|
|
|
4370
5342
|
}
|
|
4371
5343
|
var opencode = {
|
|
4372
5344
|
name: "opencode",
|
|
4373
|
-
detect: (c) => onPath2("opencode") ||
|
|
5345
|
+
detect: (c) => onPath2("opencode") || existsSync13(join24(c.home, ".config", "opencode")),
|
|
4374
5346
|
install: (c) => registerOpencodePlugin(c, "opencode"),
|
|
4375
5347
|
uninstall: (c) => unregisterOpencodePlugin(c, "opencode")
|
|
4376
5348
|
};
|
|
@@ -4381,16 +5353,16 @@ var opencode2 = {
|
|
|
4381
5353
|
uninstall: (c) => unregisterOpencodePlugin(c, "opencode2")
|
|
4382
5354
|
};
|
|
4383
5355
|
function piFamilyInstaller(harness, configDir) {
|
|
4384
|
-
const settings = (c) =>
|
|
5356
|
+
const settings = (c) => join24(c.home, ...configDir, "settings.json");
|
|
4385
5357
|
return {
|
|
4386
5358
|
name: harness,
|
|
4387
5359
|
// Both hosts name their executable exactly as we name the harness, so the harness id doubles
|
|
4388
5360
|
// as the PATH probe here — unlike, say, antigravity-cli, whose binary is `agy`.
|
|
4389
|
-
detect: (c) => onPath2(harness) ||
|
|
5361
|
+
detect: (c) => onPath2(harness) || existsSync13(join24(c.home, ...configDir)),
|
|
4390
5362
|
install(c) {
|
|
4391
5363
|
const path = settings(c);
|
|
4392
|
-
const cfg =
|
|
4393
|
-
const entry =
|
|
5364
|
+
const cfg = readJson2(path);
|
|
5365
|
+
const entry = join24(c.pkgRoot, "dist", `${harness}.js`);
|
|
4394
5366
|
const exts = Array.isArray(cfg.extensions) ? cfg.extensions : [];
|
|
4395
5367
|
cfg.extensions = [...exts.filter((p) => !String(p).includes(MARKER)), entry];
|
|
4396
5368
|
writeJson(path, cfg);
|
|
@@ -4400,8 +5372,8 @@ function piFamilyInstaller(harness, configDir) {
|
|
|
4400
5372
|
uninstall(c) {
|
|
4401
5373
|
uninstallSkill(c, harness);
|
|
4402
5374
|
const path = settings(c);
|
|
4403
|
-
if (!
|
|
4404
|
-
const cfg =
|
|
5375
|
+
if (!existsSync13(path)) return;
|
|
5376
|
+
const cfg = readJson2(path);
|
|
4405
5377
|
if (Array.isArray(cfg.extensions)) {
|
|
4406
5378
|
cfg.extensions = cfg.extensions.filter((p) => !String(p).includes(MARKER));
|
|
4407
5379
|
if (!cfg.extensions.length) delete cfg.extensions;
|
|
@@ -4415,17 +5387,17 @@ var pi = piFamilyInstaller("pi", [".pi", "agent"]);
|
|
|
4415
5387
|
var primeAgent = piFamilyInstaller("prime-agent", [".prime", "agent"]);
|
|
4416
5388
|
var KILO_CONFIG_CANDIDATES = ["kilo.jsonc", "kilo.json", "opencode.json"];
|
|
4417
5389
|
function kiloConfigPath(c) {
|
|
4418
|
-
const dir =
|
|
4419
|
-
const existing = KILO_CONFIG_CANDIDATES.map((f) =>
|
|
4420
|
-
return existing ??
|
|
5390
|
+
const dir = join24(c.home, ".config", "kilo");
|
|
5391
|
+
const existing = KILO_CONFIG_CANDIDATES.map((f) => join24(dir, f)).find((p) => existsSync13(p));
|
|
5392
|
+
return existing ?? join24(dir, "kilo.json");
|
|
4421
5393
|
}
|
|
4422
5394
|
var kilo = {
|
|
4423
5395
|
name: "kilo",
|
|
4424
|
-
detect: (c) => onPath2("kilo") ||
|
|
5396
|
+
detect: (c) => onPath2("kilo") || existsSync13(join24(c.home, ".config", "kilo")),
|
|
4425
5397
|
install(c) {
|
|
4426
5398
|
const path = kiloConfigPath(c);
|
|
4427
5399
|
let cfg = {};
|
|
4428
|
-
if (
|
|
5400
|
+
if (existsSync13(path)) {
|
|
4429
5401
|
const parsed = parseJsonc(readFileSync15(path, "utf8"));
|
|
4430
5402
|
if (!parsed) {
|
|
4431
5403
|
c.log?.(`kilo: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
|
|
@@ -4433,14 +5405,14 @@ var kilo = {
|
|
|
4433
5405
|
}
|
|
4434
5406
|
cfg = parsed;
|
|
4435
5407
|
}
|
|
4436
|
-
const entry = pathToFileURL(
|
|
5408
|
+
const entry = pathToFileURL(join24(c.dist, "kilo.js")).href;
|
|
4437
5409
|
const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
|
|
4438
5410
|
writeJsonc(path, "plugin", [...plugins.filter((p) => !String(p).includes(MARKER)), entry]);
|
|
4439
5411
|
c.log?.(`kilo: plugin registered in ${path}`);
|
|
4440
5412
|
},
|
|
4441
5413
|
uninstall(c) {
|
|
4442
5414
|
const path = kiloConfigPath(c);
|
|
4443
|
-
if (!
|
|
5415
|
+
if (!existsSync13(path)) return;
|
|
4444
5416
|
const cfg = parseJsonc(readFileSync15(path, "utf8"));
|
|
4445
5417
|
if (!cfg || !Array.isArray(cfg.plugin)) return;
|
|
4446
5418
|
const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
|
|
@@ -4450,10 +5422,10 @@ var kilo = {
|
|
|
4450
5422
|
};
|
|
4451
5423
|
var claudeCode = {
|
|
4452
5424
|
name: "claude-code",
|
|
4453
|
-
detect: (c) => onPath2("claude") ||
|
|
5425
|
+
detect: (c) => onPath2("claude") || existsSync13(join24(c.home, ".claude")),
|
|
4454
5426
|
install(c) {
|
|
4455
|
-
const path =
|
|
4456
|
-
const settings =
|
|
5427
|
+
const path = join24(c.home, ".claude", "settings.json");
|
|
5428
|
+
const settings = readJson2(path);
|
|
4457
5429
|
settings.hooks = settings.hooks ?? {};
|
|
4458
5430
|
mergeHarnessHooks(settings.hooks, "claude-code", c.dist);
|
|
4459
5431
|
writeJson(path, settings);
|
|
@@ -4471,20 +5443,20 @@ var claudeCode = {
|
|
|
4471
5443
|
"HINDSIGHT_MCP_HARNESS=claude-code",
|
|
4472
5444
|
"--",
|
|
4473
5445
|
"node",
|
|
4474
|
-
|
|
5446
|
+
join24(c.dist, "mcp-server.js")
|
|
4475
5447
|
])) {
|
|
4476
5448
|
c.log?.("claude-code: MCP server registered (claude mcp add, user scope)");
|
|
4477
5449
|
} else {
|
|
4478
5450
|
c.log?.(
|
|
4479
5451
|
`claude-code: could not run \`claude mcp add\` \u2014 register the tools manually:
|
|
4480
|
-
claude mcp add --scope user hindsight --env HINDSIGHT_MCP_HARNESS=claude-code -- node "${
|
|
5452
|
+
claude mcp add --scope user hindsight --env HINDSIGHT_MCP_HARNESS=claude-code -- node "${join24(c.dist, "mcp-server.js")}"`
|
|
4481
5453
|
);
|
|
4482
5454
|
}
|
|
4483
5455
|
},
|
|
4484
5456
|
uninstall(c) {
|
|
4485
|
-
const path =
|
|
4486
|
-
if (
|
|
4487
|
-
const settings =
|
|
5457
|
+
const path = join24(c.home, ".claude", "settings.json");
|
|
5458
|
+
if (existsSync13(path)) {
|
|
5459
|
+
const settings = readJson2(path);
|
|
4488
5460
|
if (settings.hooks) {
|
|
4489
5461
|
stripHarnessHooks(settings.hooks, "claude-code");
|
|
4490
5462
|
if (!Object.keys(settings.hooks).length) delete settings.hooks;
|
|
@@ -4499,7 +5471,7 @@ var claudeCode = {
|
|
|
4499
5471
|
};
|
|
4500
5472
|
function defaultClaudeMcp(args) {
|
|
4501
5473
|
try {
|
|
4502
|
-
|
|
5474
|
+
execFileSync8("claude", args, { stdio: "pipe" });
|
|
4503
5475
|
return true;
|
|
4504
5476
|
} catch {
|
|
4505
5477
|
return false;
|
|
@@ -4508,20 +5480,20 @@ function defaultClaudeMcp(args) {
|
|
|
4508
5480
|
var CODEX_MCP_BLOCK_RE = /^\[mcp_servers\.hindsight(?:\.[^\]]+)?\][^\n]*\n(?:(?!\[)[^\n]*\n?)*/gm;
|
|
4509
5481
|
var codexMcpBlock = (dist) => `[mcp_servers.hindsight]
|
|
4510
5482
|
command = "node"
|
|
4511
|
-
args = [${JSON.stringify(
|
|
5483
|
+
args = [${JSON.stringify(join24(dist, "mcp-server.js"))}]
|
|
4512
5484
|
env = { HINDSIGHT_MCP_HARNESS = "codex" }`;
|
|
4513
5485
|
var codex = {
|
|
4514
5486
|
name: "codex",
|
|
4515
|
-
detect: (c) => onPath2("codex") ||
|
|
5487
|
+
detect: (c) => onPath2("codex") || existsSync13(join24(c.home, ".codex")),
|
|
4516
5488
|
install(c) {
|
|
4517
|
-
const hooksPath =
|
|
4518
|
-
const cfg =
|
|
5489
|
+
const hooksPath = join24(c.home, ".codex", "hooks.json");
|
|
5490
|
+
const cfg = readJson2(hooksPath);
|
|
4519
5491
|
cfg.hooks = cfg.hooks ?? {};
|
|
4520
5492
|
mergeHarnessHooks(cfg.hooks, "codex", c.dist);
|
|
4521
5493
|
writeJson(hooksPath, cfg);
|
|
4522
5494
|
c.log?.(`codex: hooks merged into ${hooksPath}`);
|
|
4523
|
-
const tomlPath =
|
|
4524
|
-
const existing =
|
|
5495
|
+
const tomlPath = join24(c.home, ".codex", "config.toml");
|
|
5496
|
+
const existing = existsSync13(tomlPath) ? readFileSync15(tomlPath, "utf8") : "";
|
|
4525
5497
|
const toml = existing.replace(CODEX_MCP_BLOCK_RE, "");
|
|
4526
5498
|
const additions = [];
|
|
4527
5499
|
if (!/^\s*(codex_hooks|hooks)\s*=/m.test(toml)) {
|
|
@@ -4537,30 +5509,30 @@ var codex = {
|
|
|
4537
5509
|
const next = `${toml.replace(/\n*$/, "\n\n")}${additions.join("\n\n")}
|
|
4538
5510
|
`;
|
|
4539
5511
|
if (next !== existing) {
|
|
4540
|
-
if (
|
|
5512
|
+
if (existsSync13(tomlPath) && !existsSync13(`${tomlPath}.hindsight-backup`)) {
|
|
4541
5513
|
copyFileSync(tomlPath, `${tomlPath}.hindsight-backup`);
|
|
4542
5514
|
}
|
|
4543
|
-
|
|
4544
|
-
|
|
5515
|
+
mkdirSync7(dirname13(tomlPath), { recursive: true });
|
|
5516
|
+
writeFileSync5(tomlPath, next);
|
|
4545
5517
|
c.log?.(`codex: wrote ${additions.length} section(s) to ${tomlPath}`);
|
|
4546
5518
|
}
|
|
4547
5519
|
installSkill(c, "codex");
|
|
4548
5520
|
},
|
|
4549
5521
|
uninstall(c) {
|
|
4550
|
-
const hooksPath =
|
|
4551
|
-
if (
|
|
4552
|
-
const cfg =
|
|
5522
|
+
const hooksPath = join24(c.home, ".codex", "hooks.json");
|
|
5523
|
+
if (existsSync13(hooksPath)) {
|
|
5524
|
+
const cfg = readJson2(hooksPath);
|
|
4553
5525
|
if (cfg.hooks) {
|
|
4554
5526
|
stripHarnessHooks(cfg.hooks, "codex");
|
|
4555
5527
|
writeJson(hooksPath, cfg);
|
|
4556
5528
|
}
|
|
4557
5529
|
}
|
|
4558
5530
|
uninstallSkill(c, "codex");
|
|
4559
|
-
const tomlPath =
|
|
4560
|
-
if (
|
|
5531
|
+
const tomlPath = join24(c.home, ".codex", "config.toml");
|
|
5532
|
+
if (existsSync13(tomlPath)) {
|
|
4561
5533
|
const toml = readFileSync15(tomlPath, "utf8");
|
|
4562
5534
|
const cleaned = toml.replace(CODEX_MCP_BLOCK_RE, "");
|
|
4563
|
-
if (cleaned !== toml)
|
|
5535
|
+
if (cleaned !== toml) writeFileSync5(tomlPath, cleaned);
|
|
4564
5536
|
}
|
|
4565
5537
|
c.log?.(
|
|
4566
5538
|
"codex: hooks + MCP section + skill removed ([features] hooks flag left as-is \u2014 other hooks may use it)"
|
|
@@ -4574,8 +5546,8 @@ var antigravity = {
|
|
|
4574
5546
|
// can consume this integration.
|
|
4575
5547
|
detect: (c) => onPath2("agy"),
|
|
4576
5548
|
install(c) {
|
|
4577
|
-
const hooksPath =
|
|
4578
|
-
const hooks =
|
|
5549
|
+
const hooksPath = join24(c.home, ".gemini", "config", "hooks.json");
|
|
5550
|
+
const hooks = readJson2(hooksPath);
|
|
4579
5551
|
for (const key of Object.keys(hooks)) {
|
|
4580
5552
|
if (key !== MARKER && key.includes(MARKER)) delete hooks[key];
|
|
4581
5553
|
}
|
|
@@ -4585,26 +5557,26 @@ var antigravity = {
|
|
|
4585
5557
|
setOrDelete(hooks, event, stripOurs(hooks[event]));
|
|
4586
5558
|
}
|
|
4587
5559
|
writeJson(hooksPath, hooks);
|
|
4588
|
-
const mcpPath =
|
|
4589
|
-
const mcp =
|
|
5560
|
+
const mcpPath = join24(c.home, ".gemini", "config", "mcp_config.json");
|
|
5561
|
+
const mcp = readJson2(mcpPath);
|
|
4590
5562
|
mcp.mcpServers = {
|
|
4591
5563
|
...mcp.mcpServers ?? {},
|
|
4592
5564
|
hindsight: mcpServerEntry(c.dist, "antigravity-cli")
|
|
4593
5565
|
};
|
|
4594
5566
|
writeJson(mcpPath, mcp);
|
|
4595
|
-
const settingsPath =
|
|
4596
|
-
const settings =
|
|
5567
|
+
const settingsPath = join24(c.home, ".gemini", "antigravity-cli", "settings.json");
|
|
5568
|
+
const settings = readJson2(settingsPath);
|
|
4597
5569
|
if (!settings.statusLine) {
|
|
4598
5570
|
settings.statusLine = {
|
|
4599
5571
|
type: "command",
|
|
4600
|
-
command: `node "${
|
|
5572
|
+
command: `node "${join24(c.dist, "antigravity-statusline.js")}"`
|
|
4601
5573
|
};
|
|
4602
5574
|
writeJson(settingsPath, settings);
|
|
4603
5575
|
c.log?.(`antigravity-cli: Hindsight status line enabled in ${settingsPath}`);
|
|
4604
5576
|
} else if (JSON.stringify(settings.statusLine).includes(MARKER)) {
|
|
4605
5577
|
settings.statusLine = {
|
|
4606
5578
|
type: "command",
|
|
4607
|
-
command: `node "${
|
|
5579
|
+
command: `node "${join24(c.dist, "antigravity-statusline.js")}"`
|
|
4608
5580
|
};
|
|
4609
5581
|
writeJson(settingsPath, settings);
|
|
4610
5582
|
} else {
|
|
@@ -4616,9 +5588,9 @@ var antigravity = {
|
|
|
4616
5588
|
installSkill(c, "antigravity-cli");
|
|
4617
5589
|
},
|
|
4618
5590
|
uninstall(c) {
|
|
4619
|
-
const hooksPath =
|
|
4620
|
-
if (
|
|
4621
|
-
const hooks =
|
|
5591
|
+
const hooksPath = join24(c.home, ".gemini", "config", "hooks.json");
|
|
5592
|
+
if (existsSync13(hooksPath)) {
|
|
5593
|
+
const hooks = readJson2(hooksPath);
|
|
4622
5594
|
if (hooks[MARKER]) {
|
|
4623
5595
|
stripHarnessHooks(hooks[MARKER], "antigravity-cli");
|
|
4624
5596
|
if (!Object.keys(hooks[MARKER]).length) delete hooks[MARKER];
|
|
@@ -4628,17 +5600,17 @@ var antigravity = {
|
|
|
4628
5600
|
}
|
|
4629
5601
|
writeJson(hooksPath, hooks);
|
|
4630
5602
|
}
|
|
4631
|
-
const mcpPath =
|
|
4632
|
-
if (
|
|
4633
|
-
const mcp =
|
|
5603
|
+
const mcpPath = join24(c.home, ".gemini", "config", "mcp_config.json");
|
|
5604
|
+
if (existsSync13(mcpPath)) {
|
|
5605
|
+
const mcp = readJson2(mcpPath);
|
|
4634
5606
|
if (mcp.mcpServers?.hindsight) {
|
|
4635
5607
|
delete mcp.mcpServers.hindsight;
|
|
4636
5608
|
writeJson(mcpPath, mcp);
|
|
4637
5609
|
}
|
|
4638
5610
|
}
|
|
4639
|
-
const settingsPath =
|
|
4640
|
-
if (
|
|
4641
|
-
const settings =
|
|
5611
|
+
const settingsPath = join24(c.home, ".gemini", "antigravity-cli", "settings.json");
|
|
5612
|
+
if (existsSync13(settingsPath)) {
|
|
5613
|
+
const settings = readJson2(settingsPath);
|
|
4642
5614
|
if (JSON.stringify(settings.statusLine ?? {}).includes(MARKER)) {
|
|
4643
5615
|
delete settings.statusLine;
|
|
4644
5616
|
writeJson(settingsPath, settings);
|
|
@@ -4650,7 +5622,7 @@ var antigravity = {
|
|
|
4650
5622
|
};
|
|
4651
5623
|
function pathNodeHasSqlite() {
|
|
4652
5624
|
try {
|
|
4653
|
-
|
|
5625
|
+
execFileSync8("node", ["-e", "require('node:sqlite')"], { stdio: "pipe", timeout: 1e4 });
|
|
4654
5626
|
return true;
|
|
4655
5627
|
} catch {
|
|
4656
5628
|
return false;
|
|
@@ -4658,13 +5630,13 @@ function pathNodeHasSqlite() {
|
|
|
4658
5630
|
}
|
|
4659
5631
|
function pathNodeVersion() {
|
|
4660
5632
|
try {
|
|
4661
|
-
return
|
|
5633
|
+
return execFileSync8("node", ["-v"], { encoding: "utf8", stdio: "pipe" }).trim();
|
|
4662
5634
|
} catch {
|
|
4663
5635
|
return "not found";
|
|
4664
5636
|
}
|
|
4665
5637
|
}
|
|
4666
5638
|
function runtimeDir(home) {
|
|
4667
|
-
return
|
|
5639
|
+
return join24(home, ".hindsight", "coding-agents");
|
|
4668
5640
|
}
|
|
4669
5641
|
var ORIGIN_FILE = ".install-origin.json";
|
|
4670
5642
|
function stageRuntime(c) {
|
|
@@ -4677,25 +5649,25 @@ function stageRuntime(c) {
|
|
|
4677
5649
|
}
|
|
4678
5650
|
};
|
|
4679
5651
|
if (same(c.pkgRoot, target)) return c;
|
|
4680
|
-
if (!
|
|
5652
|
+
if (!existsSync13(join24(c.dist, "installer.js"))) return c;
|
|
4681
5653
|
try {
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
cpSync2(c.dist,
|
|
4685
|
-
const skill =
|
|
4686
|
-
if (
|
|
4687
|
-
const pkgJson =
|
|
4688
|
-
if (
|
|
5654
|
+
rmSync4(join24(target, "dist"), { recursive: true, force: true });
|
|
5655
|
+
mkdirSync7(target, { recursive: true });
|
|
5656
|
+
cpSync2(c.dist, join24(target, "dist"), { recursive: true });
|
|
5657
|
+
const skill = join24(c.pkgRoot, "skill");
|
|
5658
|
+
if (existsSync13(skill)) cpSync2(skill, join24(target, "skill"), { recursive: true });
|
|
5659
|
+
const pkgJson = join24(c.pkgRoot, "package.json");
|
|
5660
|
+
if (existsSync13(pkgJson)) copyFileSync(pkgJson, join24(target, "package.json"));
|
|
4689
5661
|
for (const resource of ["plugin.json", "hooks", "index.js"]) {
|
|
4690
|
-
const source =
|
|
4691
|
-
if (
|
|
5662
|
+
const source = join24(c.pkgRoot, resource);
|
|
5663
|
+
if (existsSync13(source)) cpSync2(source, join24(target, resource), { recursive: true });
|
|
4692
5664
|
}
|
|
4693
|
-
|
|
4694
|
-
|
|
5665
|
+
writeFileSync5(
|
|
5666
|
+
join24(target, ORIGIN_FILE),
|
|
4695
5667
|
JSON.stringify({ source: c.pkgRoot, stagedAt: (/* @__PURE__ */ new Date()).toISOString() })
|
|
4696
5668
|
);
|
|
4697
5669
|
c.log?.(`runtime staged at ${target}`);
|
|
4698
|
-
return { ...c, pkgRoot: target, dist:
|
|
5670
|
+
return { ...c, pkgRoot: target, dist: join24(target, "dist") };
|
|
4699
5671
|
} catch (error) {
|
|
4700
5672
|
c.log?.(`could not stage the runtime at ${target}: ${String(error)}`);
|
|
4701
5673
|
return c;
|
|
@@ -4717,6 +5689,7 @@ function flagValueArgs(args, names) {
|
|
|
4717
5689
|
return taken;
|
|
4718
5690
|
}
|
|
4719
5691
|
var CONFIG_RELATIVE = [".hindsight", "coding-agent.json"];
|
|
5692
|
+
var hindsightConfigPath = (c) => process.env.HINDSIGHT_CONFIG || join24(c.home, ...CONFIG_RELATIVE);
|
|
4720
5693
|
var SERVER_CHOICES = [
|
|
4721
5694
|
{ mode: "cloud", label: "Hindsight Cloud", hint: "hosted, needs an API token" },
|
|
4722
5695
|
{ mode: "self-hosted", label: "Self-hosted server", hint: "a Hindsight server you already run" },
|
|
@@ -4773,8 +5746,8 @@ function configureServer(c, args, installing) {
|
|
|
4773
5746
|
c.log?.(`unknown --server "${explicit}" \u2014 expected one of: ${SERVER_MODES.join(", ")}`);
|
|
4774
5747
|
return false;
|
|
4775
5748
|
}
|
|
4776
|
-
const configPath =
|
|
4777
|
-
const existing =
|
|
5749
|
+
const configPath = hindsightConfigPath(c);
|
|
5750
|
+
const existing = readJson2(configPath);
|
|
4778
5751
|
const alreadyConfigured = !!(existing.serverMode || existing.apiUrl);
|
|
4779
5752
|
let mode = explicit;
|
|
4780
5753
|
if (!mode) {
|
|
@@ -4869,7 +5842,7 @@ function reportDaemonPrereqs(c) {
|
|
|
4869
5842
|
}
|
|
4870
5843
|
var devin = {
|
|
4871
5844
|
name: "devin-cli",
|
|
4872
|
-
detect: (c) => onPath2("devin") ||
|
|
5845
|
+
detect: (c) => onPath2("devin") || existsSync13(join24(c.home, ".config", "devin")),
|
|
4873
5846
|
// Devin is the ONLY harness whose hooks never hand over a transcript: they carry a session id and
|
|
4874
5847
|
// nothing else, so retain can only work by reading the CLI's own sessions.db. That makes SQLite
|
|
4875
5848
|
// support a hard prerequisite here — and one worth checking now, because the alternative is an
|
|
@@ -4882,13 +5855,13 @@ var devin = {
|
|
|
4882
5855
|
Upgrade to Node 22.5 or newer (24 LTS recommended) and re-run this command.`;
|
|
4883
5856
|
},
|
|
4884
5857
|
install(c) {
|
|
4885
|
-
const configPath =
|
|
4886
|
-
const config =
|
|
5858
|
+
const configPath = join24(c.home, ".config", "devin", "config.json");
|
|
5859
|
+
const config = readJson2(configPath);
|
|
4887
5860
|
config.hooks = config.hooks ?? {};
|
|
4888
5861
|
mergeHarnessHooks(config.hooks, "devin-cli", c.dist);
|
|
4889
5862
|
writeJson(configPath, config);
|
|
4890
|
-
const mcpPath =
|
|
4891
|
-
const mcp =
|
|
5863
|
+
const mcpPath = join24(c.home, ".config", "devin", "mcp_config.json");
|
|
5864
|
+
const mcp = readJson2(mcpPath);
|
|
4892
5865
|
mcp.mcpServers = {
|
|
4893
5866
|
...mcp.mcpServers ?? {},
|
|
4894
5867
|
hindsight: mcpServerEntry(c.dist, "devin-cli")
|
|
@@ -4897,18 +5870,18 @@ var devin = {
|
|
|
4897
5870
|
c.log?.(`devin-cli: hooks merged into ${configPath}, MCP into ${mcpPath}`);
|
|
4898
5871
|
},
|
|
4899
5872
|
uninstall(c) {
|
|
4900
|
-
const configPath =
|
|
4901
|
-
if (
|
|
4902
|
-
const config =
|
|
5873
|
+
const configPath = join24(c.home, ".config", "devin", "config.json");
|
|
5874
|
+
if (existsSync13(configPath)) {
|
|
5875
|
+
const config = readJson2(configPath);
|
|
4903
5876
|
if (config.hooks) {
|
|
4904
5877
|
stripHarnessHooks(config.hooks, "devin-cli");
|
|
4905
5878
|
if (!Object.keys(config.hooks).length) delete config.hooks;
|
|
4906
5879
|
writeJson(configPath, config);
|
|
4907
5880
|
}
|
|
4908
5881
|
}
|
|
4909
|
-
const mcpPath =
|
|
4910
|
-
if (
|
|
4911
|
-
const mcp =
|
|
5882
|
+
const mcpPath = join24(c.home, ".config", "devin", "mcp_config.json");
|
|
5883
|
+
if (existsSync13(mcpPath)) {
|
|
5884
|
+
const mcp = readJson2(mcpPath);
|
|
4912
5885
|
if (mcp.mcpServers?.hindsight) {
|
|
4913
5886
|
delete mcp.mcpServers.hindsight;
|
|
4914
5887
|
writeJson(mcpPath, mcp);
|
|
@@ -4919,36 +5892,37 @@ var devin = {
|
|
|
4919
5892
|
};
|
|
4920
5893
|
var cursor = {
|
|
4921
5894
|
name: "cursor-cli",
|
|
4922
|
-
detect: (c) => onPath2("cursor-agent") ||
|
|
5895
|
+
detect: (c) => onPath2("cursor-agent") || existsSync13(join24(c.home, ".cursor")),
|
|
4923
5896
|
install(c) {
|
|
4924
|
-
const hooksPath =
|
|
4925
|
-
const cfg =
|
|
5897
|
+
const hooksPath = join24(c.home, ".cursor", "hooks.json");
|
|
5898
|
+
const cfg = readJson2(hooksPath);
|
|
5899
|
+
cfg.version ??= 1;
|
|
4926
5900
|
cfg.hooks = cfg.hooks ?? {};
|
|
4927
5901
|
mergeHarnessHooks(cfg.hooks, "cursor-cli", c.dist);
|
|
4928
5902
|
writeJson(hooksPath, cfg);
|
|
4929
|
-
const mcpPath =
|
|
4930
|
-
const mcp =
|
|
5903
|
+
const mcpPath = join24(c.home, ".cursor", "mcp.json");
|
|
5904
|
+
const mcp = readJson2(mcpPath);
|
|
4931
5905
|
mcp.mcpServers = {
|
|
4932
5906
|
...mcp.mcpServers ?? {},
|
|
4933
|
-
hindsight: mcpServerEntry(c.dist, "cursor-cli")
|
|
5907
|
+
hindsight: mcpServerEntry(c.dist, "cursor-cli", ["${workspaceFolder}"])
|
|
4934
5908
|
};
|
|
4935
5909
|
writeJson(mcpPath, mcp);
|
|
4936
5910
|
c.log?.(`cursor-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
|
|
4937
5911
|
installSkill(c, "cursor-cli");
|
|
4938
5912
|
},
|
|
4939
5913
|
uninstall(c) {
|
|
4940
|
-
const hooksPath =
|
|
4941
|
-
if (
|
|
4942
|
-
const cfg =
|
|
5914
|
+
const hooksPath = join24(c.home, ".cursor", "hooks.json");
|
|
5915
|
+
if (existsSync13(hooksPath)) {
|
|
5916
|
+
const cfg = readJson2(hooksPath);
|
|
4943
5917
|
if (cfg.hooks) {
|
|
4944
5918
|
stripHarnessHooks(cfg.hooks, "cursor-cli");
|
|
4945
5919
|
if (!Object.keys(cfg.hooks).length) delete cfg.hooks;
|
|
4946
5920
|
writeJson(hooksPath, cfg);
|
|
4947
5921
|
}
|
|
4948
5922
|
}
|
|
4949
|
-
const mcpPath =
|
|
4950
|
-
if (
|
|
4951
|
-
const mcp =
|
|
5923
|
+
const mcpPath = join24(c.home, ".cursor", "mcp.json");
|
|
5924
|
+
if (existsSync13(mcpPath)) {
|
|
5925
|
+
const mcp = readJson2(mcpPath);
|
|
4952
5926
|
if (mcp.mcpServers?.hindsight) {
|
|
4953
5927
|
delete mcp.mcpServers.hindsight;
|
|
4954
5928
|
writeJson(mcpPath, mcp);
|
|
@@ -4960,14 +5934,14 @@ var cursor = {
|
|
|
4960
5934
|
};
|
|
4961
5935
|
var copilot = {
|
|
4962
5936
|
name: "copilot-cli",
|
|
4963
|
-
detect: (c) => onPath2("copilot") ||
|
|
5937
|
+
detect: (c) => onPath2("copilot") || existsSync13(join24(c.home, ".copilot")),
|
|
4964
5938
|
install(c) {
|
|
4965
|
-
const hooksPath =
|
|
5939
|
+
const hooksPath = join24(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
|
|
4966
5940
|
const hooks = {};
|
|
4967
5941
|
mergeHarnessHooks(hooks, "copilot-cli", c.dist);
|
|
4968
5942
|
writeJson(hooksPath, { version: 1, hooks });
|
|
4969
|
-
const mcpPath =
|
|
4970
|
-
const mcp =
|
|
5943
|
+
const mcpPath = join24(c.home, ".copilot", "mcp-config.json");
|
|
5944
|
+
const mcp = readJson2(mcpPath);
|
|
4971
5945
|
mcp.mcpServers = {
|
|
4972
5946
|
...mcp.mcpServers ?? {},
|
|
4973
5947
|
hindsight: mcpServerEntry(c.dist, "copilot-cli")
|
|
@@ -4977,12 +5951,12 @@ var copilot = {
|
|
|
4977
5951
|
c.log?.(`copilot-cli: hooks installed at ${hooksPath}, MCP into ${mcpPath}`);
|
|
4978
5952
|
},
|
|
4979
5953
|
uninstall(c) {
|
|
4980
|
-
|
|
5954
|
+
rmSync4(join24(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
|
|
4981
5955
|
force: true
|
|
4982
5956
|
});
|
|
4983
|
-
const mcpPath =
|
|
4984
|
-
if (
|
|
4985
|
-
const mcp =
|
|
5957
|
+
const mcpPath = join24(c.home, ".copilot", "mcp-config.json");
|
|
5958
|
+
if (existsSync13(mcpPath)) {
|
|
5959
|
+
const mcp = readJson2(mcpPath);
|
|
4986
5960
|
if (mcp.mcpServers?.hindsight) {
|
|
4987
5961
|
delete mcp.mcpServers.hindsight;
|
|
4988
5962
|
writeJson(mcpPath, mcp);
|
|
@@ -5045,39 +6019,21 @@ function stripUnmarkedGrokEntries(toml) {
|
|
|
5045
6019
|
if (!drop.some(Boolean)) return toml;
|
|
5046
6020
|
return sections.filter((_, i) => !drop[i]).map((s) => s.lines.join("\n")).join("\n").replace(/\n{3,}/g, "\n\n");
|
|
5047
6021
|
}
|
|
6022
|
+
var grokHooksPath = (c) => join24(c.home, ".grok", "hooks", "hindsight.json");
|
|
5048
6023
|
var grok = {
|
|
5049
6024
|
name: "grok-build",
|
|
5050
|
-
detect: (c) => onPath2("grok") ||
|
|
6025
|
+
detect: (c) => onPath2("grok") || existsSync13(join24(c.home, ".grok")),
|
|
5051
6026
|
install(c) {
|
|
5052
|
-
const path =
|
|
5053
|
-
const existing =
|
|
6027
|
+
const path = join24(c.home, ".grok", "config.toml");
|
|
6028
|
+
const existing = existsSync13(path) ? readFileSync15(path, "utf8") : "";
|
|
5054
6029
|
const stripped = existing.replace(GROK_BLOCK_RE, "\n");
|
|
5055
6030
|
const withoutOurs = hasUnmarkedGrokEntries(stripped) ? stripUnmarkedGrokEntries(stripped) : stripped;
|
|
5056
|
-
const command = (entry) => JSON.stringify(`node "${join20(c.dist, entry)}"`);
|
|
5057
6031
|
const tomlString = (value) => JSON.stringify(value);
|
|
5058
6032
|
const block = `
|
|
5059
6033
|
${GROK_MARKER_START}
|
|
5060
|
-
[[hooks.SessionStart]]
|
|
5061
|
-
[[hooks.SessionStart.hooks]]
|
|
5062
|
-
type = "command"
|
|
5063
|
-
command = ${command("grok-sessionstart-hook.js")}
|
|
5064
|
-
timeout = 30
|
|
5065
|
-
|
|
5066
|
-
[[hooks.UserPromptSubmit]]
|
|
5067
|
-
[[hooks.UserPromptSubmit.hooks]]
|
|
5068
|
-
type = "command"
|
|
5069
|
-
command = ${command("grok-hook.js")}
|
|
5070
|
-
timeout = 30
|
|
5071
|
-
|
|
5072
|
-
[[hooks.Stop]]
|
|
5073
|
-
[[hooks.Stop.hooks]]
|
|
5074
|
-
type = "command"
|
|
5075
|
-
command = ${command("grok-stop-hook.js")}
|
|
5076
|
-
timeout = 60
|
|
5077
|
-
|
|
5078
6034
|
[mcp_servers.hindsight]
|
|
5079
6035
|
command = "node"
|
|
5080
|
-
args = [${tomlString(
|
|
6036
|
+
args = [${tomlString(join24(c.dist, "mcp-server.js"))}]
|
|
5081
6037
|
env = { HINDSIGHT_MCP_HARNESS = "grok-build" }
|
|
5082
6038
|
${GROK_MARKER_END}
|
|
5083
6039
|
`;
|
|
@@ -5088,41 +6044,111 @@ ${GROK_MARKER_END}
|
|
|
5088
6044
|
);
|
|
5089
6045
|
return false;
|
|
5090
6046
|
}
|
|
5091
|
-
if (
|
|
6047
|
+
if (existsSync13(path) && !existsSync13(`${path}.hindsight-backup`))
|
|
5092
6048
|
copyFileSync(path, `${path}.hindsight-backup`);
|
|
5093
|
-
|
|
5094
|
-
|
|
6049
|
+
mkdirSync7(dirname13(path), { recursive: true });
|
|
6050
|
+
writeFileSync5(path, next);
|
|
6051
|
+
const hooksPath = grokHooksPath(c);
|
|
6052
|
+
const file = readJson2(hooksPath);
|
|
6053
|
+
const hooks = isPlainObject(file.hooks) ? file.hooks : {};
|
|
6054
|
+
mergeHarnessHooks(hooks, "grok-build", c.dist);
|
|
6055
|
+
writeJson(hooksPath, { ...file, hooks });
|
|
5095
6056
|
installSkill(c, "grok-build");
|
|
5096
|
-
c.log?.(`grok-build:
|
|
6057
|
+
c.log?.(`grok-build: hooks installed in ${hooksPath}, MCP in ${path}`);
|
|
5097
6058
|
},
|
|
5098
6059
|
uninstall(c) {
|
|
5099
|
-
const path =
|
|
5100
|
-
if (
|
|
6060
|
+
const path = join24(c.home, ".grok", "config.toml");
|
|
6061
|
+
if (existsSync13(path)) {
|
|
5101
6062
|
const existing = readFileSync15(path, "utf8");
|
|
5102
6063
|
const stripped = existing.replace(GROK_BLOCK_RE, "\n");
|
|
5103
6064
|
const cleaned = hasUnmarkedGrokEntries(stripped) ? stripUnmarkedGrokEntries(stripped) : stripped;
|
|
5104
6065
|
const safe = parseGrokToml(cleaned) !== null || parseGrokToml(existing) === null;
|
|
5105
|
-
if (cleaned !== existing && safe)
|
|
6066
|
+
if (cleaned !== existing && safe) writeFileSync5(path, cleaned);
|
|
6067
|
+
}
|
|
6068
|
+
const hooksPath = grokHooksPath(c);
|
|
6069
|
+
if (existsSync13(hooksPath)) {
|
|
6070
|
+
const file = readJson2(hooksPath);
|
|
6071
|
+
if (isPlainObject(file.hooks)) {
|
|
6072
|
+
stripHarnessHooks(file.hooks, "grok-build");
|
|
6073
|
+
if (!Object.keys(file.hooks).length) delete file.hooks;
|
|
6074
|
+
}
|
|
6075
|
+
if (Object.keys(file).length) writeJson(hooksPath, file);
|
|
6076
|
+
else rmSync4(hooksPath);
|
|
5106
6077
|
}
|
|
5107
6078
|
uninstallSkill(c, "grok-build");
|
|
5108
6079
|
c.log?.("grok-build: native hooks + MCP + skill removed");
|
|
5109
6080
|
}
|
|
5110
6081
|
};
|
|
6082
|
+
var KIMI_MARKER_START = "# HINDSIGHT_CODING_AGENTS_KIMI_START";
|
|
6083
|
+
var KIMI_MARKER_END = "# HINDSIGHT_CODING_AGENTS_KIMI_END";
|
|
6084
|
+
var KIMI_BLOCK_RE = new RegExp(`\\n?${KIMI_MARKER_START}[\\s\\S]*?${KIMI_MARKER_END}\\n?`);
|
|
6085
|
+
function kimiHome(c) {
|
|
6086
|
+
return process.env.KIMI_CODE_HOME || join24(c.home, ".kimi-code");
|
|
6087
|
+
}
|
|
6088
|
+
var kimi = {
|
|
6089
|
+
name: "kimi-code",
|
|
6090
|
+
detect: (c) => onPath2("kimi") || existsSync13(kimiHome(c)),
|
|
6091
|
+
install(c) {
|
|
6092
|
+
const path = join24(kimiHome(c), "config.toml");
|
|
6093
|
+
const existing = existsSync13(path) ? readFileSync15(path, "utf8") : "";
|
|
6094
|
+
const withoutOurs = existing.replace(KIMI_BLOCK_RE, "\n");
|
|
6095
|
+
const spec = HOOK_HARNESSES["kimi-code"];
|
|
6096
|
+
const entries = Object.values(spec.install).map(
|
|
6097
|
+
(h) => `[[hooks]]
|
|
6098
|
+
event = ${JSON.stringify(h.event)}
|
|
6099
|
+
command = ${JSON.stringify(`node "${join24(c.dist, h.entry)}"`)}
|
|
6100
|
+
timeout = ${h.timeout}
|
|
6101
|
+
`
|
|
6102
|
+
).join("\n");
|
|
6103
|
+
const block = `
|
|
6104
|
+
${KIMI_MARKER_START}
|
|
6105
|
+
${entries}${KIMI_MARKER_END}
|
|
6106
|
+
`;
|
|
6107
|
+
if (existsSync13(path) && !existsSync13(`${path}.hindsight-backup`))
|
|
6108
|
+
copyFileSync(path, `${path}.hindsight-backup`);
|
|
6109
|
+
mkdirSync7(dirname13(path), { recursive: true });
|
|
6110
|
+
writeFileSync5(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
|
|
6111
|
+
const mcpPath = join24(kimiHome(c), "mcp.json");
|
|
6112
|
+
const mcp = readJson2(mcpPath);
|
|
6113
|
+
mcp.mcpServers = { ...mcp.mcpServers ?? {}, hindsight: mcpServerEntry(c.dist, "kimi-code") };
|
|
6114
|
+
writeJson(mcpPath, mcp);
|
|
6115
|
+
installSkill(c, "kimi-code");
|
|
6116
|
+
c.log?.(`kimi-code: native hooks installed in ${path}, MCP in ${mcpPath}`);
|
|
6117
|
+
},
|
|
6118
|
+
uninstall(c) {
|
|
6119
|
+
const path = join24(kimiHome(c), "config.toml");
|
|
6120
|
+
if (existsSync13(path)) {
|
|
6121
|
+
const existing = readFileSync15(path, "utf8");
|
|
6122
|
+
const cleaned = existing.replace(KIMI_BLOCK_RE, "\n");
|
|
6123
|
+
if (cleaned !== existing) writeFileSync5(path, cleaned);
|
|
6124
|
+
}
|
|
6125
|
+
const mcpPath = join24(kimiHome(c), "mcp.json");
|
|
6126
|
+
if (existsSync13(mcpPath)) {
|
|
6127
|
+
const mcp = readJson2(mcpPath);
|
|
6128
|
+
if (mcp.mcpServers?.hindsight) {
|
|
6129
|
+
delete mcp.mcpServers.hindsight;
|
|
6130
|
+
writeJson(mcpPath, mcp);
|
|
6131
|
+
}
|
|
6132
|
+
}
|
|
6133
|
+
uninstallSkill(c, "kimi-code");
|
|
6134
|
+
c.log?.("kimi-code: native hooks + MCP + skill removed");
|
|
6135
|
+
}
|
|
6136
|
+
};
|
|
5111
6137
|
var CLINE_HOOK_MARKER = "HINDSIGHT_CODING_AGENTS_CLINE";
|
|
5112
6138
|
var CLINE_OLD_HOOK_EVENTS = ["TaskStart", "UserPromptSubmit", "TaskComplete"];
|
|
5113
6139
|
var CLINE_PLUGIN_NAME = "@vectorize-io/hindsight-coding-agents";
|
|
5114
6140
|
function removeLegacyClineHooks(c) {
|
|
5115
|
-
const hooksDir =
|
|
6141
|
+
const hooksDir = join24(c.home, "Documents", "Cline", "Hooks");
|
|
5116
6142
|
for (const event of CLINE_OLD_HOOK_EVENTS) {
|
|
5117
|
-
const path =
|
|
5118
|
-
if (
|
|
5119
|
-
|
|
6143
|
+
const path = join24(hooksDir, event);
|
|
6144
|
+
if (existsSync13(path) && readFileSync15(path, "utf8").includes(CLINE_HOOK_MARKER)) {
|
|
6145
|
+
rmSync4(path, { force: true });
|
|
5120
6146
|
}
|
|
5121
6147
|
}
|
|
5122
6148
|
}
|
|
5123
6149
|
var cline = {
|
|
5124
6150
|
name: "cline-cli",
|
|
5125
|
-
detect: (c) => onPath2("cline") ||
|
|
6151
|
+
detect: (c) => onPath2("cline") || existsSync13(join24(c.home, ".cline")),
|
|
5126
6152
|
install(c) {
|
|
5127
6153
|
removeLegacyClineHooks(c);
|
|
5128
6154
|
const installed = (c.clinePlugin ?? runClinePlugin)([
|
|
@@ -5131,8 +6157,8 @@ var cline = {
|
|
|
5131
6157
|
"--force",
|
|
5132
6158
|
c.pkgRoot
|
|
5133
6159
|
]);
|
|
5134
|
-
const mcpPath =
|
|
5135
|
-
const mcp =
|
|
6160
|
+
const mcpPath = join24(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
|
|
6161
|
+
const mcp = readJson2(mcpPath);
|
|
5136
6162
|
mcp.mcpServers = {
|
|
5137
6163
|
...mcp.mcpServers ?? {},
|
|
5138
6164
|
hindsight: mcpServerEntry(c.dist, "cline-cli")
|
|
@@ -5146,9 +6172,9 @@ var cline = {
|
|
|
5146
6172
|
uninstall(c) {
|
|
5147
6173
|
removeLegacyClineHooks(c);
|
|
5148
6174
|
(c.clinePlugin ?? runClinePlugin)(["plugin", "uninstall", CLINE_PLUGIN_NAME]);
|
|
5149
|
-
const mcpPath =
|
|
5150
|
-
if (
|
|
5151
|
-
const mcp =
|
|
6175
|
+
const mcpPath = join24(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
|
|
6176
|
+
if (existsSync13(mcpPath)) {
|
|
6177
|
+
const mcp = readJson2(mcpPath);
|
|
5152
6178
|
if (mcp.mcpServers?.hindsight) {
|
|
5153
6179
|
delete mcp.mcpServers.hindsight;
|
|
5154
6180
|
writeJson(mcpPath, mcp);
|
|
@@ -5160,29 +6186,29 @@ var cline = {
|
|
|
5160
6186
|
};
|
|
5161
6187
|
var DCODE_MARKETPLACE = "hindsight-coding-agents";
|
|
5162
6188
|
var DCODE_PLUGIN_ID = "hindsight-coding-agents@hindsight-coding-agents";
|
|
5163
|
-
var DCODE_MARKETPLACE_RELATIVE_PATH =
|
|
6189
|
+
var DCODE_MARKETPLACE_RELATIVE_PATH = join24(".agents", "plugins", "marketplace.json");
|
|
5164
6190
|
var DCODE_FALLBACK_MARKETPLACE = "hindsight-coding-agents-marketplace.json";
|
|
5165
6191
|
function prepareDcodeMarketplace(c) {
|
|
5166
|
-
const root =
|
|
5167
|
-
const conventionalPath =
|
|
6192
|
+
const root = join24(c.home, ".hindsight");
|
|
6193
|
+
const conventionalPath = join24(root, DCODE_MARKETPLACE_RELATIVE_PATH);
|
|
5168
6194
|
let path = conventionalPath;
|
|
5169
6195
|
let registrationSource = root;
|
|
5170
6196
|
let marketplace = { plugins: [] };
|
|
5171
|
-
if (
|
|
6197
|
+
if (existsSync13(conventionalPath)) {
|
|
5172
6198
|
try {
|
|
5173
6199
|
const parsed = JSON.parse(readFileSync15(conventionalPath, "utf8"));
|
|
5174
6200
|
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins)) {
|
|
5175
|
-
path =
|
|
6201
|
+
path = join24(root, DCODE_FALLBACK_MARKETPLACE);
|
|
5176
6202
|
} else if (typeof parsed.name === "string" && parsed.name !== DCODE_MARKETPLACE) {
|
|
5177
|
-
path =
|
|
6203
|
+
path = join24(root, DCODE_FALLBACK_MARKETPLACE);
|
|
5178
6204
|
} else {
|
|
5179
6205
|
marketplace = parsed;
|
|
5180
6206
|
}
|
|
5181
6207
|
} catch {
|
|
5182
|
-
path =
|
|
6208
|
+
path = join24(root, DCODE_FALLBACK_MARKETPLACE);
|
|
5183
6209
|
}
|
|
5184
6210
|
}
|
|
5185
|
-
if (path !== conventionalPath &&
|
|
6211
|
+
if (path !== conventionalPath && existsSync13(path)) {
|
|
5186
6212
|
try {
|
|
5187
6213
|
const parsed = JSON.parse(readFileSync15(path, "utf8"));
|
|
5188
6214
|
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins) || parsed.name !== DCODE_MARKETPLACE) {
|
|
@@ -5212,7 +6238,7 @@ function prepareDcodeMarketplace(c) {
|
|
|
5212
6238
|
}
|
|
5213
6239
|
var dcode = {
|
|
5214
6240
|
name: "dcode",
|
|
5215
|
-
detect: (c) => onPath2("dcode") ||
|
|
6241
|
+
detect: (c) => onPath2("dcode") || existsSync13(join24(c.home, ".deepagents")),
|
|
5216
6242
|
preflight: (c) => c.dcodePlugin || onPath2("dcode") ? void 0 : "the `dcode` CLI is not on PATH",
|
|
5217
6243
|
install(c) {
|
|
5218
6244
|
const plugin = c.dcodePlugin ?? runDcodePlugin;
|
|
@@ -5221,7 +6247,7 @@ var dcode = {
|
|
|
5221
6247
|
if (installed) {
|
|
5222
6248
|
c.log?.(`dcode: native Agent Plugin installed (${DCODE_PLUGIN_ID})`);
|
|
5223
6249
|
} else {
|
|
5224
|
-
const source = marketplacePath === false ?
|
|
6250
|
+
const source = marketplacePath === false ? join24(c.home, ".hindsight") : marketplacePath;
|
|
5225
6251
|
c.log?.(
|
|
5226
6252
|
`dcode: could not install the native plugin \u2014 run dcode plugin marketplace add "${source}" && dcode plugin install ${DCODE_PLUGIN_ID}`
|
|
5227
6253
|
);
|
|
@@ -5248,27 +6274,32 @@ var dcode = {
|
|
|
5248
6274
|
var DSH_MARKER_START = "# HINDSIGHT_CODING_AGENTS_DSH_START";
|
|
5249
6275
|
var DSH_MARKER_END = "# HINDSIGHT_CODING_AGENTS_DSH_END";
|
|
5250
6276
|
var DSH_BLOCK_RE = new RegExp(`\\n?${DSH_MARKER_START}[\\s\\S]*?${DSH_MARKER_END}\\n?`);
|
|
6277
|
+
var DSH_EMPTY_LIST = "[]";
|
|
6278
|
+
function dshUserPatches(existing) {
|
|
6279
|
+
const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
|
|
6280
|
+
return others === DSH_EMPTY_LIST ? "" : others;
|
|
6281
|
+
}
|
|
5251
6282
|
function dshHome(c) {
|
|
5252
|
-
return process.env.DSH_HOME ||
|
|
6283
|
+
return process.env.DSH_HOME || join24(c.home, ".dsh");
|
|
5253
6284
|
}
|
|
5254
6285
|
var dsh = {
|
|
5255
6286
|
name: "dsh",
|
|
5256
|
-
detect: (c) => onPath2("dsh") ||
|
|
6287
|
+
detect: (c) => onPath2("dsh") || existsSync13(dshHome(c)),
|
|
5257
6288
|
install(c) {
|
|
5258
|
-
const path =
|
|
5259
|
-
const existing =
|
|
5260
|
-
const others = existing
|
|
5261
|
-
const entry = pathToFileURL(
|
|
6289
|
+
const path = join24(dshHome(c), "cordis.patch.yml");
|
|
6290
|
+
const existing = existsSync13(path) ? readFileSync15(path, "utf8") : "";
|
|
6291
|
+
const others = dshUserPatches(existing);
|
|
6292
|
+
const entry = pathToFileURL(join24(c.dist, "dsh.js")).href;
|
|
5262
6293
|
const block = `${DSH_MARKER_START}
|
|
5263
6294
|
- insert:
|
|
5264
6295
|
- id: hindsight
|
|
5265
6296
|
name: ${JSON.stringify(entry)}
|
|
5266
6297
|
${DSH_MARKER_END}
|
|
5267
6298
|
`;
|
|
5268
|
-
if (
|
|
6299
|
+
if (existsSync13(path) && !existsSync13(`${path}.hindsight-backup`))
|
|
5269
6300
|
copyFileSync(path, `${path}.hindsight-backup`);
|
|
5270
|
-
|
|
5271
|
-
|
|
6301
|
+
mkdirSync7(dirname13(path), { recursive: true });
|
|
6302
|
+
writeFileSync5(path, others ? `${others}
|
|
5272
6303
|
|
|
5273
6304
|
${block}` : block);
|
|
5274
6305
|
installSkill(c, "dsh");
|
|
@@ -5277,12 +6308,14 @@ ${block}` : block);
|
|
|
5277
6308
|
);
|
|
5278
6309
|
},
|
|
5279
6310
|
uninstall(c) {
|
|
5280
|
-
const path =
|
|
5281
|
-
if (
|
|
6311
|
+
const path = join24(dshHome(c), "cordis.patch.yml");
|
|
6312
|
+
if (existsSync13(path)) {
|
|
5282
6313
|
const existing = readFileSync15(path, "utf8");
|
|
5283
6314
|
const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
|
|
5284
|
-
if (others !== existing.trim())
|
|
5285
|
-
|
|
6315
|
+
if (others !== existing.trim())
|
|
6316
|
+
writeFileSync5(path, others ? `${others}
|
|
6317
|
+
` : `${DSH_EMPTY_LIST}
|
|
6318
|
+
`);
|
|
5286
6319
|
}
|
|
5287
6320
|
uninstallSkill(c, "dsh");
|
|
5288
6321
|
c.log?.("dsh: plugin entry + skill removed");
|
|
@@ -5290,10 +6323,10 @@ ${block}` : block);
|
|
|
5290
6323
|
};
|
|
5291
6324
|
var qwen = {
|
|
5292
6325
|
name: "qwen-code",
|
|
5293
|
-
detect: (c) => onPath2("qwen") ||
|
|
6326
|
+
detect: (c) => onPath2("qwen") || existsSync13(join24(c.home, ".qwen")),
|
|
5294
6327
|
install(c) {
|
|
5295
|
-
const path =
|
|
5296
|
-
const settings =
|
|
6328
|
+
const path = join24(c.home, ".qwen", "settings.json");
|
|
6329
|
+
const settings = readJson2(path);
|
|
5297
6330
|
settings.hooks = settings.hooks ?? {};
|
|
5298
6331
|
mergeHarnessHooks(settings.hooks, "qwen-code", c.dist);
|
|
5299
6332
|
writeJson(path, settings);
|
|
@@ -5310,20 +6343,20 @@ var qwen = {
|
|
|
5310
6343
|
"HINDSIGHT_MCP_HARNESS=qwen-code",
|
|
5311
6344
|
"hindsight",
|
|
5312
6345
|
"node",
|
|
5313
|
-
|
|
6346
|
+
join24(c.dist, "mcp-server.js")
|
|
5314
6347
|
])) {
|
|
5315
6348
|
c.log?.("qwen-code: MCP server registered (qwen mcp add, user scope)");
|
|
5316
6349
|
} else {
|
|
5317
6350
|
c.log?.(
|
|
5318
6351
|
`qwen-code: could not run \`qwen mcp add\` \u2014 register the tools manually:
|
|
5319
|
-
qwen mcp add -s user -e HINDSIGHT_MCP_HARNESS=qwen-code hindsight node "${
|
|
6352
|
+
qwen mcp add -s user -e HINDSIGHT_MCP_HARNESS=qwen-code hindsight node "${join24(c.dist, "mcp-server.js")}"`
|
|
5320
6353
|
);
|
|
5321
6354
|
}
|
|
5322
6355
|
},
|
|
5323
6356
|
uninstall(c) {
|
|
5324
|
-
const path =
|
|
5325
|
-
if (
|
|
5326
|
-
const settings =
|
|
6357
|
+
const path = join24(c.home, ".qwen", "settings.json");
|
|
6358
|
+
if (existsSync13(path)) {
|
|
6359
|
+
const settings = readJson2(path);
|
|
5327
6360
|
if (settings.hooks) {
|
|
5328
6361
|
stripHarnessHooks(settings.hooks, "qwen-code");
|
|
5329
6362
|
if (!Object.keys(settings.hooks).length) delete settings.hooks;
|
|
@@ -5338,7 +6371,7 @@ var qwen = {
|
|
|
5338
6371
|
};
|
|
5339
6372
|
function defaultQwenMcp(args) {
|
|
5340
6373
|
try {
|
|
5341
|
-
|
|
6374
|
+
execFileSync8("qwen", args, { stdio: "pipe" });
|
|
5342
6375
|
return true;
|
|
5343
6376
|
} catch {
|
|
5344
6377
|
return false;
|
|
@@ -5346,19 +6379,19 @@ function defaultQwenMcp(args) {
|
|
|
5346
6379
|
}
|
|
5347
6380
|
var factoryDroid = {
|
|
5348
6381
|
name: "factory-droid",
|
|
5349
|
-
detect: (c) => onPath2("droid") ||
|
|
6382
|
+
detect: (c) => onPath2("droid") || existsSync13(join24(c.home, ".factory")),
|
|
5350
6383
|
preflight(c) {
|
|
5351
|
-
const mcpPath =
|
|
5352
|
-
const existing =
|
|
6384
|
+
const mcpPath = join24(c.home, ".factory", "mcp.json");
|
|
6385
|
+
const existing = readJson2(mcpPath).mcpServers?.hindsight;
|
|
5353
6386
|
if (existing && !isOurMcpEntry(existing)) {
|
|
5354
6387
|
return `${mcpPath} already contains a user-managed MCP server named "hindsight". Rename or remove that entry, then re-run install.`;
|
|
5355
6388
|
}
|
|
5356
6389
|
},
|
|
5357
6390
|
install(c) {
|
|
5358
|
-
const hooksPath =
|
|
5359
|
-
const hooks =
|
|
5360
|
-
if (!
|
|
5361
|
-
const fallback =
|
|
6391
|
+
const hooksPath = join24(c.home, ".factory", "hooks.json");
|
|
6392
|
+
const hooks = readJson2(hooksPath);
|
|
6393
|
+
if (!existsSync13(hooksPath)) {
|
|
6394
|
+
const fallback = readJson2(join24(c.home, ".factory", "settings.json")).hooks;
|
|
5362
6395
|
if (fallback && typeof fallback === "object" && !Array.isArray(fallback)) {
|
|
5363
6396
|
Object.assign(hooks, fallback);
|
|
5364
6397
|
}
|
|
@@ -5367,28 +6400,28 @@ var factoryDroid = {
|
|
|
5367
6400
|
writeJson(hooksPath, hooks);
|
|
5368
6401
|
c.log?.(`factory-droid: hooks merged into ${hooksPath}`);
|
|
5369
6402
|
installSkill(c, "factory-droid");
|
|
5370
|
-
const mcpPath =
|
|
5371
|
-
const mcp =
|
|
6403
|
+
const mcpPath = join24(c.home, ".factory", "mcp.json");
|
|
6404
|
+
const mcp = readJson2(mcpPath);
|
|
5372
6405
|
mcp.mcpServers = mcp.mcpServers ?? {};
|
|
5373
6406
|
mcp.mcpServers.hindsight = mcpServerEntry(c.dist, "factory-droid");
|
|
5374
6407
|
writeJson(mcpPath, mcp);
|
|
5375
6408
|
c.log?.(`factory-droid: MCP server registered in ${mcpPath}`);
|
|
5376
6409
|
},
|
|
5377
6410
|
uninstall(c) {
|
|
5378
|
-
const hooksPath =
|
|
5379
|
-
if (
|
|
5380
|
-
const hooks =
|
|
6411
|
+
const hooksPath = join24(c.home, ".factory", "hooks.json");
|
|
6412
|
+
if (existsSync13(hooksPath)) {
|
|
6413
|
+
const hooks = readJson2(hooksPath);
|
|
5381
6414
|
stripHarnessHooks(hooks, "factory-droid");
|
|
5382
6415
|
if (Object.keys(hooks).length) writeJson(hooksPath, hooks);
|
|
5383
|
-
else
|
|
6416
|
+
else rmSync4(hooksPath);
|
|
5384
6417
|
}
|
|
5385
|
-
const mcpPath =
|
|
5386
|
-
if (
|
|
5387
|
-
const mcp =
|
|
6418
|
+
const mcpPath = join24(c.home, ".factory", "mcp.json");
|
|
6419
|
+
if (existsSync13(mcpPath)) {
|
|
6420
|
+
const mcp = readJson2(mcpPath);
|
|
5388
6421
|
if (isOurMcpEntry(mcp.mcpServers?.hindsight)) {
|
|
5389
6422
|
delete mcp.mcpServers.hindsight;
|
|
5390
6423
|
if (Object.keys(mcp.mcpServers).length) writeJson(mcpPath, mcp);
|
|
5391
|
-
else
|
|
6424
|
+
else rmSync4(mcpPath);
|
|
5392
6425
|
}
|
|
5393
6426
|
}
|
|
5394
6427
|
uninstallSkill(c, "factory-droid");
|
|
@@ -5397,17 +6430,17 @@ var factoryDroid = {
|
|
|
5397
6430
|
};
|
|
5398
6431
|
var zcode = {
|
|
5399
6432
|
name: "zcode",
|
|
5400
|
-
detect: (c) => onPath2("zcode") ||
|
|
6433
|
+
detect: (c) => onPath2("zcode") || existsSync13(join24(c.home, ".zcode")),
|
|
5401
6434
|
preflight(c) {
|
|
5402
6435
|
const configPath = zcodeConfigPath(c);
|
|
5403
|
-
const existing =
|
|
6436
|
+
const existing = readJson2(configPath).mcp?.servers?.hindsight;
|
|
5404
6437
|
if (existing && !isOurMcpEntry(existing)) {
|
|
5405
6438
|
return `${configPath} already contains a user-managed MCP server named "hindsight". Rename or remove that entry, then re-run install.`;
|
|
5406
6439
|
}
|
|
5407
6440
|
},
|
|
5408
6441
|
install(c) {
|
|
5409
6442
|
const configPath = zcodeConfigPath(c);
|
|
5410
|
-
const config =
|
|
6443
|
+
const config = readJson2(configPath);
|
|
5411
6444
|
const hooks = config.hooks = config.hooks ?? {};
|
|
5412
6445
|
hooks.enabled = true;
|
|
5413
6446
|
hooks.maxOutputBytes = hooks.maxOutputBytes ?? ZCODE_MAX_OUTPUT_BYTES;
|
|
@@ -5422,8 +6455,8 @@ var zcode = {
|
|
|
5422
6455
|
},
|
|
5423
6456
|
uninstall(c) {
|
|
5424
6457
|
const configPath = zcodeConfigPath(c);
|
|
5425
|
-
if (
|
|
5426
|
-
const config =
|
|
6458
|
+
if (existsSync13(configPath)) {
|
|
6459
|
+
const config = readJson2(configPath);
|
|
5427
6460
|
if (isOurMcpEntry(config.mcp?.servers?.hindsight)) {
|
|
5428
6461
|
delete config.mcp.servers.hindsight;
|
|
5429
6462
|
if (!Object.keys(config.mcp.servers).length) delete config.mcp;
|
|
@@ -5439,6 +6472,209 @@ var zcode = {
|
|
|
5439
6472
|
c.log?.(`zcode: hooks + MCP registration + skill removed`);
|
|
5440
6473
|
}
|
|
5441
6474
|
};
|
|
6475
|
+
var traecodeMcpPath = (c) => join24(traecodeUserDataDir(c.home), "User", "mcp.json");
|
|
6476
|
+
function removeTraecodeUserMcpEntry(c) {
|
|
6477
|
+
try {
|
|
6478
|
+
const mcpPath = traecodeMcpPath(c);
|
|
6479
|
+
if (!existsSync13(mcpPath)) return false;
|
|
6480
|
+
const mcp = readJson2(mcpPath);
|
|
6481
|
+
if (!isOurMcpEntry(mcp.mcpServers?.hindsight)) return false;
|
|
6482
|
+
delete mcp.mcpServers.hindsight;
|
|
6483
|
+
if (Object.keys(mcp.mcpServers).length) writeJson(mcpPath, mcp);
|
|
6484
|
+
else rmSync4(mcpPath);
|
|
6485
|
+
return true;
|
|
6486
|
+
} catch {
|
|
6487
|
+
return false;
|
|
6488
|
+
}
|
|
6489
|
+
}
|
|
6490
|
+
function ensureTraecodeWorkspaceMcpGate(c) {
|
|
6491
|
+
const settingsPath = traecodeUserSettingsPath(c.home);
|
|
6492
|
+
if (workspaceMcpGateState(settingsPath) === "on") return;
|
|
6493
|
+
const ask = "\n Trae ignores per-repo MCP configs until workspace MCP is enabled, which keeps\n hindsight's MCP tools hidden. Enable it globally now? (one-time setting)\n";
|
|
6494
|
+
const skipNote = ' Skipped. Enable later in Trae settings (search "enableWorkspaceMcp") or re-run with\n --enable-workspace-mcp.';
|
|
6495
|
+
if (!(c.args ?? []).includes("--enable-workspace-mcp")) {
|
|
6496
|
+
if (c.interactive !== true) {
|
|
6497
|
+
c.log?.(`${ask} ${skipNote}`);
|
|
6498
|
+
return;
|
|
6499
|
+
}
|
|
6500
|
+
const answer = readLineSync(c, `${ask} Enable workspace MCP? [Y/n]: `).trim().toLowerCase();
|
|
6501
|
+
if (answer === "n" || answer === "no") {
|
|
6502
|
+
c.log?.(skipNote);
|
|
6503
|
+
return;
|
|
6504
|
+
}
|
|
6505
|
+
}
|
|
6506
|
+
if (enableWorkspaceMcpSetting(settingsPath)) {
|
|
6507
|
+
markWorkspaceMcpEnabled({ stateFile: gateStateFileFor(c.dist) });
|
|
6508
|
+
c.log?.(
|
|
6509
|
+
`traecode: workspace MCP enabled in ${settingsPath} \u2014 restart Trae windows to pick it up`
|
|
6510
|
+
);
|
|
6511
|
+
} else {
|
|
6512
|
+
c.log?.(
|
|
6513
|
+
`traecode: could not update ${settingsPath} (comments or unreadable JSON) \u2014 set
|
|
6514
|
+
"trae.mcp.enableWorkspaceMcp": true in Trae settings instead.`
|
|
6515
|
+
);
|
|
6516
|
+
}
|
|
6517
|
+
}
|
|
6518
|
+
var traecode = {
|
|
6519
|
+
name: "traecode",
|
|
6520
|
+
detect: (c) => existsSync13(join24(c.home, traecodeDotDirName(c.home))) || onPath2("trae"),
|
|
6521
|
+
install(c) {
|
|
6522
|
+
const hooksPath = join24(c.home, traecodeDotDirName(c.home), "hooks.json");
|
|
6523
|
+
const doc = readJson2(hooksPath);
|
|
6524
|
+
doc.version = doc.version ?? 1;
|
|
6525
|
+
const hooks = doc.hooks = doc.hooks ?? {};
|
|
6526
|
+
mergeHarnessHooks(hooks, "traecode", c.dist);
|
|
6527
|
+
writeJson(hooksPath, doc);
|
|
6528
|
+
c.log?.(`traecode: hooks merged into ${hooksPath}`);
|
|
6529
|
+
installSkill(c, "traecode");
|
|
6530
|
+
if (removeTraecodeUserMcpEntry(c)) {
|
|
6531
|
+
c.log?.(
|
|
6532
|
+
`traecode: stale user-level MCP entry removed from ${traecodeMcpPath(c)} \u2014 per-repo
|
|
6533
|
+
.trae/mcp.json files register the server instead`
|
|
6534
|
+
);
|
|
6535
|
+
}
|
|
6536
|
+
const sandboxPath = join24(c.home, traecodeDotDirName(c.home), "sandbox.json");
|
|
6537
|
+
const sandbox = readJson2(sandboxPath);
|
|
6538
|
+
const fsRules = sandbox.filesystem = sandbox.filesystem ?? {};
|
|
6539
|
+
const readWrite = fsRules.readWrite = fsRules.readWrite ?? [];
|
|
6540
|
+
const needed = [join24(c.home, ".hindsight"), traecodeWorkspaceStorageDir(c.home)];
|
|
6541
|
+
let sandboxChanged = false;
|
|
6542
|
+
for (const dir of needed) {
|
|
6543
|
+
if (!readWrite.includes(dir)) {
|
|
6544
|
+
readWrite.push(dir);
|
|
6545
|
+
sandboxChanged = true;
|
|
6546
|
+
}
|
|
6547
|
+
}
|
|
6548
|
+
if (sandboxChanged) {
|
|
6549
|
+
writeJson(sandboxPath, sandbox);
|
|
6550
|
+
c.log?.(`traecode: sandbox readWrite rules added (${needed.join(", ")})`);
|
|
6551
|
+
}
|
|
6552
|
+
const config = readJson2(hindsightConfigPath(c));
|
|
6553
|
+
const repos = Object.keys(config.mapPathToBank ?? {}).sort();
|
|
6554
|
+
if (repos.length) {
|
|
6555
|
+
const written = [];
|
|
6556
|
+
const current2 = [];
|
|
6557
|
+
const skipped = [];
|
|
6558
|
+
let seeded = 0;
|
|
6559
|
+
for (const repo of repos) {
|
|
6560
|
+
if (!existsSync13(repo)) {
|
|
6561
|
+
skipped.push(repo);
|
|
6562
|
+
continue;
|
|
6563
|
+
}
|
|
6564
|
+
const outcome = registerTraecodeWorkspaceMcp(repo, { home: c.home, dist: c.dist });
|
|
6565
|
+
if (outcome === "registered") written.push(repo);
|
|
6566
|
+
else if (outcome === "current") current2.push(repo);
|
|
6567
|
+
else skipped.push(repo);
|
|
6568
|
+
if (ensureWorkspaceMcpEnabled(repo, { home: c.home }) !== "failed") seeded++;
|
|
6569
|
+
}
|
|
6570
|
+
c.log?.(
|
|
6571
|
+
`traecode: per-repo MCP registration \u2014 ${written.length} written, ${current2.length} already current, ${skipped.length} skipped across ${repos.length} opted-in repo(s); enable switch on for ${seeded}`
|
|
6572
|
+
);
|
|
6573
|
+
if (written.length) c.log?.(` registered: ${written.join(", ")}`);
|
|
6574
|
+
if (skipped.length) {
|
|
6575
|
+
c.log?.(
|
|
6576
|
+
` skipped (missing repo, no dist build, or a foreign hindsight entry): ` + skipped.join(", ")
|
|
6577
|
+
);
|
|
6578
|
+
}
|
|
6579
|
+
if (written.length) {
|
|
6580
|
+
c.log?.(
|
|
6581
|
+
" new registrations appear in the next Trae window \u2014 if a repo's server still shows\n disabled in the MCP panel, flip it on once there"
|
|
6582
|
+
);
|
|
6583
|
+
}
|
|
6584
|
+
}
|
|
6585
|
+
ensureTraecodeWorkspaceMcpGate(c);
|
|
6586
|
+
},
|
|
6587
|
+
uninstall(c) {
|
|
6588
|
+
const hooksPath = join24(c.home, traecodeDotDirName(c.home), "hooks.json");
|
|
6589
|
+
if (existsSync13(hooksPath)) {
|
|
6590
|
+
const doc = readJson2(hooksPath);
|
|
6591
|
+
if (doc.hooks) {
|
|
6592
|
+
stripHarnessHooks(doc.hooks, "traecode");
|
|
6593
|
+
if (!Object.keys(doc.hooks).length) delete doc.hooks;
|
|
6594
|
+
}
|
|
6595
|
+
if (Object.keys(doc).length > 1) writeJson(hooksPath, doc);
|
|
6596
|
+
else rmSync4(hooksPath);
|
|
6597
|
+
}
|
|
6598
|
+
if (removeTraecodeUserMcpEntry(c)) {
|
|
6599
|
+
c.log?.(`traecode: MCP entry removed from ${traecodeMcpPath(c)}`);
|
|
6600
|
+
}
|
|
6601
|
+
const config = readJson2(hindsightConfigPath(c));
|
|
6602
|
+
const repoEntries = Object.keys(config.mapPathToBank ?? {}).sort();
|
|
6603
|
+
const cleaned = repoEntries.filter(
|
|
6604
|
+
(repo) => removeTraecodeWorkspaceMcpEntry(repo, { home: c.home })
|
|
6605
|
+
);
|
|
6606
|
+
if (cleaned.length) {
|
|
6607
|
+
c.log?.(`traecode: per-repo MCP registration removed from:
|
|
6608
|
+
${cleaned.join("\n ")}`);
|
|
6609
|
+
}
|
|
6610
|
+
const sandboxPath = join24(c.home, traecodeDotDirName(c.home), "sandbox.json");
|
|
6611
|
+
if (existsSync13(sandboxPath)) {
|
|
6612
|
+
const sandbox = readJson2(sandboxPath);
|
|
6613
|
+
const readWrite = sandbox.filesystem?.readWrite;
|
|
6614
|
+
if (Array.isArray(readWrite)) {
|
|
6615
|
+
const ours = [join24(c.home, ".hindsight"), traecodeWorkspaceStorageDir(c.home)];
|
|
6616
|
+
const filtered = readWrite.filter((p) => !ours.includes(p));
|
|
6617
|
+
if (filtered.length !== readWrite.length) {
|
|
6618
|
+
sandbox.filesystem.readWrite = filtered;
|
|
6619
|
+
writeJson(sandboxPath, sandbox);
|
|
6620
|
+
}
|
|
6621
|
+
}
|
|
6622
|
+
}
|
|
6623
|
+
removeWorkspaceMcpEnabledKeys(c.home);
|
|
6624
|
+
uninstallSkill(c, "traecode");
|
|
6625
|
+
c.log?.(`traecode: hooks + MCP registration + skill removed`);
|
|
6626
|
+
}
|
|
6627
|
+
};
|
|
6628
|
+
var genieInstaller = (name, homeDir, mcpPaths) => ({
|
|
6629
|
+
name,
|
|
6630
|
+
detect: (c) => existsSync13(join24(c.home, homeDir)),
|
|
6631
|
+
install(c) {
|
|
6632
|
+
const settingsPath = join24(c.home, homeDir, "settings.json");
|
|
6633
|
+
const settings = readJson2(settingsPath);
|
|
6634
|
+
settings.hooks = settings.hooks ?? {};
|
|
6635
|
+
mergeHarnessHooks(settings.hooks, name, c.dist);
|
|
6636
|
+
writeJson(settingsPath, settings);
|
|
6637
|
+
c.log?.(`${name}: hooks merged into ${settingsPath}`);
|
|
6638
|
+
const paths = mcpPaths(c.home);
|
|
6639
|
+
const mcpPath = paths.find((p) => existsSync13(p)) ?? paths[0];
|
|
6640
|
+
const mcp = readJson2(mcpPath);
|
|
6641
|
+
mcp.mcpServers = mcp.mcpServers ?? {};
|
|
6642
|
+
mcp.mcpServers.hindsight = mcpServerEntry(c.dist, name);
|
|
6643
|
+
writeJson(mcpPath, mcp);
|
|
6644
|
+
c.log?.(`${name}: MCP server registered in ${mcpPath}`);
|
|
6645
|
+
installSkill(c, name);
|
|
6646
|
+
},
|
|
6647
|
+
uninstall(c) {
|
|
6648
|
+
const settingsPath = join24(c.home, homeDir, "settings.json");
|
|
6649
|
+
if (existsSync13(settingsPath)) {
|
|
6650
|
+
const settings = readJson2(settingsPath);
|
|
6651
|
+
if (settings.hooks) {
|
|
6652
|
+
stripHarnessHooks(settings.hooks, name);
|
|
6653
|
+
if (!Object.keys(settings.hooks).length) delete settings.hooks;
|
|
6654
|
+
writeJson(settingsPath, settings);
|
|
6655
|
+
}
|
|
6656
|
+
}
|
|
6657
|
+
for (const mcpPath of mcpPaths(c.home)) {
|
|
6658
|
+
if (!existsSync13(mcpPath)) continue;
|
|
6659
|
+
const mcp = readJson2(mcpPath);
|
|
6660
|
+
if (isOurMcpEntry(mcp.mcpServers?.hindsight)) {
|
|
6661
|
+
delete mcp.mcpServers.hindsight;
|
|
6662
|
+
if (!Object.keys(mcp.mcpServers).length) delete mcp.mcpServers;
|
|
6663
|
+
writeJson(mcpPath, mcp);
|
|
6664
|
+
}
|
|
6665
|
+
}
|
|
6666
|
+
uninstallSkill(c, name);
|
|
6667
|
+
c.log?.(`${name}: hooks + MCP registration + skill removed`);
|
|
6668
|
+
}
|
|
6669
|
+
});
|
|
6670
|
+
var workbuddy = genieInstaller("workbuddy", ".workbuddy", (home) => [
|
|
6671
|
+
join24(home, ".workbuddy", "mcp.json")
|
|
6672
|
+
]);
|
|
6673
|
+
var codebuddy = genieInstaller("codebuddy", ".codebuddy", (home) => [
|
|
6674
|
+
join24(home, ".codebuddy", ".mcp.json"),
|
|
6675
|
+
join24(home, ".codebuddy", "mcp.json"),
|
|
6676
|
+
join24(home, ".codebuddy.json")
|
|
6677
|
+
]);
|
|
5442
6678
|
var INSTALLERS = [
|
|
5443
6679
|
opencode,
|
|
5444
6680
|
opencode2,
|
|
@@ -5453,11 +6689,15 @@ var INSTALLERS = [
|
|
|
5453
6689
|
copilot,
|
|
5454
6690
|
grok,
|
|
5455
6691
|
qwen,
|
|
6692
|
+
kimi,
|
|
5456
6693
|
cline,
|
|
5457
6694
|
dcode,
|
|
5458
6695
|
dsh,
|
|
5459
6696
|
factoryDroid,
|
|
5460
|
-
zcode
|
|
6697
|
+
zcode,
|
|
6698
|
+
traecode,
|
|
6699
|
+
workbuddy,
|
|
6700
|
+
codebuddy
|
|
5461
6701
|
];
|
|
5462
6702
|
var HARNESS_ALIASES = { agy: "antigravity-cli" };
|
|
5463
6703
|
function importConversations(harness, ctx) {
|
|
@@ -5477,23 +6717,24 @@ function importConversations(harness, ctx) {
|
|
|
5477
6717
|
return;
|
|
5478
6718
|
}
|
|
5479
6719
|
const turns = found.sessions.reduce((n, s) => n + s.turns.length, 0);
|
|
5480
|
-
const file =
|
|
5481
|
-
|
|
6720
|
+
const file = join24(mkdtempSync2(join24(tmpdir5(), "hindsight-import-")), "conversations.json");
|
|
6721
|
+
writeFileSync5(file, JSON.stringify(found.sessions));
|
|
5482
6722
|
ctx.log?.(
|
|
5483
6723
|
`${harness}: importing ${found.sessions.length} past sessions (${turns} turns) from ${repo} \u2014 this runs extraction and may take a while`
|
|
5484
6724
|
);
|
|
5485
6725
|
try {
|
|
5486
|
-
|
|
6726
|
+
execFileSync8("node", [join24(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
|
|
5487
6727
|
stdio: "inherit"
|
|
5488
6728
|
});
|
|
5489
6729
|
} catch {
|
|
5490
6730
|
ctx.log?.(`${harness}: conversation import did not finish \u2014 re-run it any time with:`);
|
|
5491
|
-
ctx.log?.(` node "${
|
|
6731
|
+
ctx.log?.(` node "${join24(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
|
|
5492
6732
|
}
|
|
5493
6733
|
}
|
|
5494
6734
|
function run(argv, ctxIn) {
|
|
5495
6735
|
let ctx = ctxIn;
|
|
5496
6736
|
const [command, ...rawArgs] = argv;
|
|
6737
|
+
ctx = { ...ctx, args: rawArgs };
|
|
5497
6738
|
const importHistory = rawArgs.includes("--import-conversations");
|
|
5498
6739
|
const valueArgs = flagValueArgs(rawArgs, ["server", "api-url", "api-token"]);
|
|
5499
6740
|
const names = rawArgs.filter((a) => !a.startsWith("--") && !valueArgs.has(a));
|
|
@@ -5514,7 +6755,7 @@ function run(argv, ctxIn) {
|
|
|
5514
6755
|
hindsight-coding-agents update
|
|
5515
6756
|
hindsight-coding-agents stats
|
|
5516
6757
|
[--server cloud|self-hosted|daemon] [--api-url <url>] [--api-token <token>]
|
|
5517
|
-
[--import-conversations]
|
|
6758
|
+
[--import-conversations] [--enable-workspace-mcp]
|
|
5518
6759
|
all every agent detected on this machine
|
|
5519
6760
|
harness ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-cli)
|
|
5520
6761
|
update re-stage the runtime only, leaving every host config untouched
|
|
@@ -5592,18 +6833,18 @@ var mainPath = process.argv[1] ? (() => {
|
|
|
5592
6833
|
})() : void 0;
|
|
5593
6834
|
var isMain = mainPath && import.meta.url === pathToFileURL(mainPath).href;
|
|
5594
6835
|
if (isMain || mainPath?.endsWith("installer.js")) {
|
|
5595
|
-
const dist =
|
|
5596
|
-
const pkgRoot =
|
|
5597
|
-
let
|
|
6836
|
+
const dist = dirname13(fileURLToPath7(import.meta.url));
|
|
6837
|
+
const pkgRoot = dirname13(dist);
|
|
6838
|
+
let version2;
|
|
5598
6839
|
try {
|
|
5599
|
-
|
|
6840
|
+
version2 = JSON.parse(readFileSync15(join24(pkgRoot, "package.json"), "utf8")).version;
|
|
5600
6841
|
} catch {
|
|
5601
|
-
|
|
6842
|
+
version2 = void 0;
|
|
5602
6843
|
}
|
|
5603
6844
|
const ui = createInstallerUi({
|
|
5604
|
-
home:
|
|
6845
|
+
home: homedir13(),
|
|
5605
6846
|
command: process.argv[2],
|
|
5606
|
-
version,
|
|
6847
|
+
version: version2,
|
|
5607
6848
|
harnessNames: INSTALLERS.map((i) => i.name),
|
|
5608
6849
|
// configureServer's messages render as their own "server" group, but don't count as an agent.
|
|
5609
6850
|
auxNames: ["server"],
|
|
@@ -5611,7 +6852,7 @@ if (isMain || mainPath?.endsWith("installer.js")) {
|
|
|
5611
6852
|
});
|
|
5612
6853
|
ui.intro();
|
|
5613
6854
|
const code = run(process.argv.slice(2), {
|
|
5614
|
-
home:
|
|
6855
|
+
home: homedir13(),
|
|
5615
6856
|
pkgRoot,
|
|
5616
6857
|
dist,
|
|
5617
6858
|
// Only a real terminal gets prompted; piped/CI installs take the documented default.
|
|
@@ -5639,11 +6880,11 @@ export {
|
|
|
5639
6880
|
};
|
|
5640
6881
|
/*! Bundled license information:
|
|
5641
6882
|
|
|
5642
|
-
smol-toml/dist/date.js:
|
|
5643
6883
|
smol-toml/dist/error.js:
|
|
5644
|
-
smol-toml/dist/util.js:
|
|
5645
6884
|
smol-toml/dist/primitive.js:
|
|
6885
|
+
smol-toml/dist/date.js:
|
|
5646
6886
|
smol-toml/dist/extract.js:
|
|
6887
|
+
smol-toml/dist/util.js:
|
|
5647
6888
|
smol-toml/dist/struct.js:
|
|
5648
6889
|
smol-toml/dist/parse.js:
|
|
5649
6890
|
smol-toml/dist/stringify.js:
|