@vectorize-io/hindsight-coding-agents 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -13
- package/dist/antigravity-hook.js +711 -55
- package/dist/antigravity-statusline.js +68 -7
- package/dist/antigravity-stop-hook.js +771 -57
- package/dist/claude-hook.js +711 -55
- package/dist/claude-sessionstart-hook.js +789 -68
- package/dist/claude-stop-hook.js +771 -57
- package/dist/cline.js +295 -75
- package/dist/codex-hook.js +711 -55
- package/dist/codex-sessionstart-hook.js +789 -68
- package/dist/codex-stop-hook.js +771 -57
- package/dist/copilot-hook.js +711 -55
- package/dist/copilot-sessionstart-hook.js +789 -68
- package/dist/copilot-stop-hook.js +771 -57
- package/dist/cursor-hook.js +711 -55
- package/dist/cursor-sessionstart-hook.js +789 -68
- package/dist/cursor-stop-hook.js +771 -57
- package/dist/daemon-start.js +38 -1
- package/dist/dcode-hook.js +711 -55
- package/dist/dcode-sessionstart-hook.js +789 -68
- package/dist/dcode-stop-hook.js +771 -57
- package/dist/deepen.js +236 -61
- package/dist/devin-hook.js +711 -55
- package/dist/devin-sessionstart-hook.js +789 -68
- package/dist/devin-stop-hook.js +771 -57
- package/dist/droid-hook.js +711 -55
- package/dist/droid-sessionstart-hook.js +789 -68
- package/dist/droid-stop-hook.js +771 -57
- package/dist/dsh.js +296 -76
- package/dist/grok-hook.js +711 -55
- package/dist/grok-sessionstart-hook.js +789 -68
- package/dist/grok-stop-hook.js +771 -57
- package/dist/hindsight-seed.js +41 -4
- package/dist/index.js +295 -75
- package/dist/installer.js +1148 -303
- package/dist/kilo.js +295 -75
- package/dist/kimi-hook.js +3909 -0
- package/dist/kimi-sessionstart-hook.js +4650 -0
- package/dist/kimi-stop-hook.js +4218 -0
- package/dist/mcp-server.js +162 -33
- package/dist/opencode2.js +298 -76
- package/dist/pi.js +299 -75
- package/dist/prime-agent.js +299 -75
- package/dist/qwen-hook.js +711 -55
- package/dist/qwen-sessionstart-hook.js +789 -68
- package/dist/qwen-stop-hook.js +771 -57
- package/dist/status.js +132 -14
- package/dist/traecode-hook.js +3909 -0
- package/dist/traecode-sessionstart-hook.js +4650 -0
- package/dist/traecode-stop-hook.js +4218 -0
- package/dist/zcode-hook.js +711 -55
- package/dist/zcode-sessionstart-hook.js +789 -68
- package/dist/zcode-stop-hook.js +771 -57
- package/package.json +15 -11
- package/plugin.json +1 -1
- package/skill/SKILL.md +70 -11
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 execFileSync7 } 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
|
-
readFileSync as
|
|
11
|
+
readFileSync as readFileSync16,
|
|
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 dirname12, join as join23 } 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) {
|
|
@@ -2106,6 +2106,15 @@ var PAGE_NAMES = PAGE_TAXONOMY.map((page) => page.name);
|
|
|
2106
2106
|
// src/core/util.ts
|
|
2107
2107
|
import { accessSync, constants } from "fs";
|
|
2108
2108
|
import { delimiter, join as join6 } from "path";
|
|
2109
|
+
function isOurMcpEntry(entry) {
|
|
2110
|
+
if (!entry || typeof entry !== "object") return false;
|
|
2111
|
+
const candidate = entry;
|
|
2112
|
+
if (candidate.command !== "node" || !Array.isArray(candidate.args)) return false;
|
|
2113
|
+
const script = candidate.args[0];
|
|
2114
|
+
if (typeof script !== "string") return false;
|
|
2115
|
+
const parts = script.replaceAll("\\", "/").split("/").filter(Boolean);
|
|
2116
|
+
return parts.at(-1) === "mcp-server.js" && parts.at(-2) === "dist" && (parts.at(-3) === "coding-agents" || parts.at(-3) === "hindsight-coding-agents");
|
|
2117
|
+
}
|
|
2109
2118
|
|
|
2110
2119
|
// src/core/hindsight.ts
|
|
2111
2120
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
@@ -2475,12 +2484,14 @@ var NPM_VIEW_HARD_DEADLINE_MS = NPM_VIEW_TIMEOUT_MS + 1e3;
|
|
|
2475
2484
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
2476
2485
|
|
|
2477
2486
|
// src/core/skill-sync.ts
|
|
2478
|
-
import { cpSync, existsSync as
|
|
2487
|
+
import { cpSync, existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
|
|
2479
2488
|
import { homedir as homedir6 } from "os";
|
|
2480
|
-
import { dirname as dirname10, join as
|
|
2489
|
+
import { dirname as dirname10, join as join16 } from "path";
|
|
2481
2490
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
2482
2491
|
|
|
2483
2492
|
// src/core/skill-dirs.ts
|
|
2493
|
+
import { existsSync as existsSync5 } from "fs";
|
|
2494
|
+
import { join as join15 } from "path";
|
|
2484
2495
|
var SKILL_DIRS = {
|
|
2485
2496
|
"claude-code": [".claude", "skills"],
|
|
2486
2497
|
// Codex and dsh share the agentskills-standard root; uninstalling either removes the one copy.
|
|
@@ -2493,6 +2504,8 @@ var SKILL_DIRS = {
|
|
|
2493
2504
|
"cline-cli": [".cline", "data", "settings", "skills"],
|
|
2494
2505
|
"qwen-code": [".qwen", "skills"],
|
|
2495
2506
|
// Qwen's user-level skills root (Storage.getUserSkillsDirs)
|
|
2507
|
+
// Kimi Code's user-level skills root, alongside its config.toml and mcp.json.
|
|
2508
|
+
"kimi-code": [".kimi-code", "skills"],
|
|
2496
2509
|
"factory-droid": [".factory", "skills"],
|
|
2497
2510
|
// Droid's user-level skills root
|
|
2498
2511
|
// ZCode scans TWO user roots by default (its resolveDefaultSkillRoots): `~/.zcode/skills` and the
|
|
@@ -2500,23 +2513,40 @@ var SKILL_DIRS = {
|
|
|
2500
2513
|
// skill removal is by fixed directory name, so installing into the shared root would make
|
|
2501
2514
|
// `uninstall zcode` take Codex's and dsh's copy with it.
|
|
2502
2515
|
zcode: [".zcode", "skills"],
|
|
2516
|
+
// TraeCode's user-level skills root, resolved per edition by traecodeDotDir below — like ZCode's
|
|
2517
|
+
// its own, never the shared agentskills root other hosts install into.
|
|
2518
|
+
traecode: [".trae-cn", "skills"],
|
|
2503
2519
|
// The pi family reads the shared ~/.agents/skills too, but writes its OWN root: skill removal is
|
|
2504
2520
|
// by fixed directory name, so installing to the shared one would make `uninstall pi` take Codex's
|
|
2505
2521
|
// and dsh's copy with it.
|
|
2506
2522
|
pi: [".pi", "agent", "skills"],
|
|
2507
2523
|
"prime-agent": [".prime", "agent", "skills"]
|
|
2508
2524
|
};
|
|
2525
|
+
var TRAE_DOT_DIRS = [".trae-cn", ".trae"];
|
|
2526
|
+
var traecodeDotDirName = (home, exists = existsSync5) => {
|
|
2527
|
+
for (const dir of TRAE_DOT_DIRS) {
|
|
2528
|
+
if (exists(join15(home, dir))) return dir;
|
|
2529
|
+
}
|
|
2530
|
+
return ".trae-cn";
|
|
2531
|
+
};
|
|
2532
|
+
var resolveSkillDirs = (harness, home) => {
|
|
2533
|
+
const parts = SKILL_DIRS[harness];
|
|
2534
|
+
if (harness === "traecode" && parts) {
|
|
2535
|
+
return [traecodeDotDirName(home), ...parts.slice(1)];
|
|
2536
|
+
}
|
|
2537
|
+
return parts;
|
|
2538
|
+
};
|
|
2509
2539
|
|
|
2510
2540
|
// src/core/legacy.ts
|
|
2511
|
-
import { existsSync as
|
|
2541
|
+
import { existsSync as existsSync7, readFileSync as readFileSync10 } from "fs";
|
|
2512
2542
|
import { homedir as homedir7 } from "os";
|
|
2513
|
-
import { join as
|
|
2543
|
+
import { join as join17, relative, isAbsolute as isAbsolute2 } from "path";
|
|
2514
2544
|
var LEGACY_CONFIG_FILES = {
|
|
2515
2545
|
"claude-code": "claude-code.json",
|
|
2516
2546
|
codex: "codex.json"
|
|
2517
2547
|
};
|
|
2518
2548
|
function legacyConfigPath(harness, home = homedir7()) {
|
|
2519
|
-
return
|
|
2549
|
+
return join17(home, ".hindsight", LEGACY_CONFIG_FILES[harness] ?? `${harness}.json`);
|
|
2520
2550
|
}
|
|
2521
2551
|
var CLOUD_URL = "https://api.hindsight.vectorize.io";
|
|
2522
2552
|
function readLegacyEndpoint(home = homedir7(), prefer = []) {
|
|
@@ -2531,7 +2561,7 @@ function readLegacyEndpoint(home = homedir7(), prefer = []) {
|
|
|
2531
2561
|
}
|
|
2532
2562
|
function readOne(harness, home) {
|
|
2533
2563
|
const source = legacyConfigPath(harness, home);
|
|
2534
|
-
if (!
|
|
2564
|
+
if (!existsSync7(source)) return void 0;
|
|
2535
2565
|
let raw;
|
|
2536
2566
|
try {
|
|
2537
2567
|
raw = JSON.parse(readFileSync10(source, "utf8"));
|
|
@@ -2560,6 +2590,311 @@ function readOne(harness, home) {
|
|
|
2560
2590
|
};
|
|
2561
2591
|
}
|
|
2562
2592
|
|
|
2593
|
+
// src/core/traecode-mcp.ts
|
|
2594
|
+
import { execFileSync as execFileSync4 } from "child_process";
|
|
2595
|
+
import { existsSync as existsSync8, mkdirSync as mkdirSync6, readFileSync as readFileSync12, readdirSync as readdirSync2, rmSync as rmSync3, writeFileSync as writeFileSync4 } from "fs";
|
|
2596
|
+
import { homedir as homedir8 } from "os";
|
|
2597
|
+
import { dirname as dirname11, isAbsolute as isAbsolute3, join as join18 } from "path";
|
|
2598
|
+
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
2599
|
+
var MCP_SERVER_NAME = "hindsight";
|
|
2600
|
+
var MCP_FILE_REL = join18(".trae", "mcp.json");
|
|
2601
|
+
function bundledDistDir() {
|
|
2602
|
+
const here = dirname11(fileURLToPath6(import.meta.url));
|
|
2603
|
+
return existsSync8(join18(here, "mcp-server.js")) ? here : join18(here, "..", "..", "dist");
|
|
2604
|
+
}
|
|
2605
|
+
function canon(value) {
|
|
2606
|
+
if (Array.isArray(value)) return `[${value.map(canon).join(",")}]`;
|
|
2607
|
+
if (value && typeof value === "object") {
|
|
2608
|
+
const entries = Object.entries(value).sort(
|
|
2609
|
+
([a], [b]) => a < b ? -1 : a > b ? 1 : 0
|
|
2610
|
+
);
|
|
2611
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canon(v)}`).join(",")}}`;
|
|
2612
|
+
}
|
|
2613
|
+
return JSON.stringify(value);
|
|
2614
|
+
}
|
|
2615
|
+
var WORKSPACE_MCP_KEY = "trae.mcp.enableWorkspaceMcp";
|
|
2616
|
+
var HINT_MIN_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
2617
|
+
function traecodeUserDataDir(home) {
|
|
2618
|
+
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");
|
|
2619
|
+
for (const brand of ["Trae CN", "Trae"]) {
|
|
2620
|
+
const dir = join18(root, brand);
|
|
2621
|
+
if (existsSync8(dir)) return dir;
|
|
2622
|
+
}
|
|
2623
|
+
return join18(root, "Trae CN");
|
|
2624
|
+
}
|
|
2625
|
+
var traecodeUserSettingsPath = (home) => join18(traecodeUserDataDir(home), "User", "settings.json");
|
|
2626
|
+
var gateStateFileFor = (dist) => join18(dirname11(dist), ".workspace-mcp.json");
|
|
2627
|
+
function gateStateFile() {
|
|
2628
|
+
return gateStateFileFor(bundledDistDir());
|
|
2629
|
+
}
|
|
2630
|
+
function readGateState(opts = {}) {
|
|
2631
|
+
try {
|
|
2632
|
+
return JSON.parse(readFileSync12(opts.stateFile ?? gateStateFile(), "utf8"));
|
|
2633
|
+
} catch {
|
|
2634
|
+
return {};
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
function workspaceMcpGateState(settingsPath) {
|
|
2638
|
+
let raw;
|
|
2639
|
+
try {
|
|
2640
|
+
raw = readFileSync12(settingsPath, "utf8");
|
|
2641
|
+
} catch {
|
|
2642
|
+
return "unknown";
|
|
2643
|
+
}
|
|
2644
|
+
try {
|
|
2645
|
+
const doc = JSON.parse(raw);
|
|
2646
|
+
return doc[WORKSPACE_MCP_KEY] === true ? "on" : "off";
|
|
2647
|
+
} catch {
|
|
2648
|
+
const hit = raw.match(new RegExp(`"${WORKSPACE_MCP_KEY}"\\s*:\\s*(true|false)`));
|
|
2649
|
+
return hit ? hit[1] === "true" ? "on" : "off" : "unknown";
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
function enableWorkspaceMcpSetting(settingsPath) {
|
|
2653
|
+
try {
|
|
2654
|
+
let doc = {};
|
|
2655
|
+
try {
|
|
2656
|
+
doc = JSON.parse(readFileSync12(settingsPath, "utf8"));
|
|
2657
|
+
} catch {
|
|
2658
|
+
if (existsSync8(settingsPath)) return false;
|
|
2659
|
+
}
|
|
2660
|
+
doc[WORKSPACE_MCP_KEY] = true;
|
|
2661
|
+
mkdirSync6(dirname11(settingsPath), { recursive: true });
|
|
2662
|
+
writeFileSync4(settingsPath, JSON.stringify(doc, null, 2) + "\n");
|
|
2663
|
+
return true;
|
|
2664
|
+
} catch {
|
|
2665
|
+
return false;
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
function markWorkspaceMcpEnabled(opts = {}) {
|
|
2669
|
+
try {
|
|
2670
|
+
writeFileSync4(
|
|
2671
|
+
opts.stateFile ?? gateStateFile(),
|
|
2672
|
+
JSON.stringify({ ...readGateState(opts), workspaceMcpEnabled: true }, null, 2) + "\n"
|
|
2673
|
+
);
|
|
2674
|
+
} catch {
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
function workspaceMcpHint(opts = {}) {
|
|
2678
|
+
try {
|
|
2679
|
+
const settingsPath = traecodeUserSettingsPath(opts.home ?? homedir8());
|
|
2680
|
+
if (workspaceMcpGateState(settingsPath) === "on") return void 0;
|
|
2681
|
+
const now = opts.now ?? Date.now();
|
|
2682
|
+
const state = readGateState(opts);
|
|
2683
|
+
if (state.workspaceMcpEnabled) return void 0;
|
|
2684
|
+
if (typeof state.lastHint === "number" && now - state.lastHint < HINT_MIN_INTERVAL_MS) {
|
|
2685
|
+
return void 0;
|
|
2686
|
+
}
|
|
2687
|
+
writeFileSync4(
|
|
2688
|
+
opts.stateFile ?? gateStateFile(),
|
|
2689
|
+
JSON.stringify({ ...state, lastHint: now }, null, 2) + "\n"
|
|
2690
|
+
);
|
|
2691
|
+
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.';
|
|
2692
|
+
} catch {
|
|
2693
|
+
return void 0;
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
function gitignoreCovers(lines) {
|
|
2697
|
+
return lines.some((l) => {
|
|
2698
|
+
const t = l.trim();
|
|
2699
|
+
return t.includes(".trae");
|
|
2700
|
+
});
|
|
2701
|
+
}
|
|
2702
|
+
function ensureGitignored(repo) {
|
|
2703
|
+
const gitignore = join18(repo, ".gitignore");
|
|
2704
|
+
if (!existsSync8(gitignore)) return;
|
|
2705
|
+
const current2 = readFileSync12(gitignore, "utf8");
|
|
2706
|
+
if (gitignoreCovers(current2.split("\n"))) return;
|
|
2707
|
+
const addition = (current2.endsWith("\n") || current2 === "" ? "" : "\n") + "# hindsight MCP registration (machine-specific)\n.trae/mcp.json\n";
|
|
2708
|
+
writeFileSync4(gitignore, current2 + addition);
|
|
2709
|
+
}
|
|
2710
|
+
function ensureTraecodeWorkspaceMcp(cwd, opts = {}) {
|
|
2711
|
+
registerTraecodeWorkspaceMcp(cwd, opts);
|
|
2712
|
+
const seeded = ensureWorkspaceMcpEnabled(cwd, opts);
|
|
2713
|
+
return workspaceMcpHint(opts) ?? (seeded === "failed" ? workspaceEnableHint(opts) : void 0);
|
|
2714
|
+
}
|
|
2715
|
+
function registerTraecodeWorkspaceMcp(cwd, opts = {}) {
|
|
2716
|
+
try {
|
|
2717
|
+
const home = opts.home ?? homedir8();
|
|
2718
|
+
if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return "skipped";
|
|
2719
|
+
const dist = opts.dist ?? bundledDistDir();
|
|
2720
|
+
const script = join18(dist, "mcp-server.js");
|
|
2721
|
+
if (!existsSync8(script)) return "skipped";
|
|
2722
|
+
const file = join18(cwd, MCP_FILE_REL);
|
|
2723
|
+
let doc = {};
|
|
2724
|
+
let exists = false;
|
|
2725
|
+
try {
|
|
2726
|
+
doc = JSON.parse(readFileSync12(file, "utf8"));
|
|
2727
|
+
exists = true;
|
|
2728
|
+
} catch {
|
|
2729
|
+
if (existsSync8(file)) return "skipped";
|
|
2730
|
+
}
|
|
2731
|
+
const servers = doc.mcpServers && typeof doc.mcpServers === "object" && !Array.isArray(doc.mcpServers) ? doc.mcpServers : doc.mcpServers = {};
|
|
2732
|
+
const entry = {
|
|
2733
|
+
command: "node",
|
|
2734
|
+
args: [script],
|
|
2735
|
+
env: { HINDSIGHT_MCP_HARNESS: "traecode", HINDSIGHT_MCP_PROJECT_CWD: cwd }
|
|
2736
|
+
};
|
|
2737
|
+
const existing = servers[MCP_SERVER_NAME];
|
|
2738
|
+
let merged;
|
|
2739
|
+
if (existing === void 0) {
|
|
2740
|
+
merged = entry;
|
|
2741
|
+
} else if (isOurMcpEntry(existing)) {
|
|
2742
|
+
const env = existing.env;
|
|
2743
|
+
merged = {
|
|
2744
|
+
...existing,
|
|
2745
|
+
command: entry.command,
|
|
2746
|
+
args: entry.args,
|
|
2747
|
+
env: { ...env ?? {}, ...entry.env }
|
|
2748
|
+
};
|
|
2749
|
+
} else {
|
|
2750
|
+
diag("traecode", "workspace_mcp_foreign_entry", { cwd, file });
|
|
2751
|
+
return "skipped";
|
|
2752
|
+
}
|
|
2753
|
+
if (existing !== void 0 && canon(merged) === canon(existing)) return "current";
|
|
2754
|
+
servers[MCP_SERVER_NAME] = merged;
|
|
2755
|
+
mkdirSync6(dirname11(file), { recursive: true });
|
|
2756
|
+
writeFileSync4(file, JSON.stringify(doc, null, 2) + "\n");
|
|
2757
|
+
if (!exists) ensureGitignored(cwd);
|
|
2758
|
+
diag("traecode", "workspace_mcp_registered", { cwd, file });
|
|
2759
|
+
return "registered";
|
|
2760
|
+
} catch (e) {
|
|
2761
|
+
diag("traecode", "workspace_mcp_register_failed", {
|
|
2762
|
+
cwd,
|
|
2763
|
+
error: e instanceof Error ? e.message : String(e)
|
|
2764
|
+
});
|
|
2765
|
+
return "failed";
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
function removeTraecodeWorkspaceMcpEntry(cwd, opts = {}) {
|
|
2769
|
+
try {
|
|
2770
|
+
const home = opts.home ?? homedir8();
|
|
2771
|
+
if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return false;
|
|
2772
|
+
const file = join18(cwd, MCP_FILE_REL);
|
|
2773
|
+
let doc;
|
|
2774
|
+
try {
|
|
2775
|
+
doc = JSON.parse(readFileSync12(file, "utf8"));
|
|
2776
|
+
} catch {
|
|
2777
|
+
return false;
|
|
2778
|
+
}
|
|
2779
|
+
const servers = doc.mcpServers;
|
|
2780
|
+
if (!servers || typeof servers !== "object" || Array.isArray(servers)) return false;
|
|
2781
|
+
const record = servers;
|
|
2782
|
+
if (!isOurMcpEntry(record[MCP_SERVER_NAME])) return false;
|
|
2783
|
+
delete record[MCP_SERVER_NAME];
|
|
2784
|
+
if (Object.keys(record).length === 0) delete doc.mcpServers;
|
|
2785
|
+
if (Object.keys(doc).length === 0) rmSync3(file);
|
|
2786
|
+
else writeFileSync4(file, JSON.stringify(doc, null, 2) + "\n");
|
|
2787
|
+
return true;
|
|
2788
|
+
} catch {
|
|
2789
|
+
return false;
|
|
2790
|
+
}
|
|
2791
|
+
}
|
|
2792
|
+
var WORKSPACE_STORAGE_REL = join18("User", "workspaceStorage");
|
|
2793
|
+
var ENABLED_KEY_PREFIX = "icubeAgentExtension.enabled.mcp.config.ws0.";
|
|
2794
|
+
var SQLITE_TIMEOUT_MS = 5e3;
|
|
2795
|
+
var TRAECODE_WORKSPACE_ENABLED_KEY = ENABLED_KEY_PREFIX + MCP_SERVER_NAME;
|
|
2796
|
+
var traecodeWorkspaceStorageDir = (home) => join18(traecodeUserDataDir(home), WORKSPACE_STORAGE_REL);
|
|
2797
|
+
function removeWorkspaceMcpEnabledKeys(home) {
|
|
2798
|
+
const storage = traecodeWorkspaceStorageDir(home);
|
|
2799
|
+
let entries;
|
|
2800
|
+
try {
|
|
2801
|
+
entries = readdirSync2(storage);
|
|
2802
|
+
} catch {
|
|
2803
|
+
return;
|
|
2804
|
+
}
|
|
2805
|
+
for (const name of entries) {
|
|
2806
|
+
const db = join18(storage, name, "state.vscdb");
|
|
2807
|
+
if (!existsSync8(db)) continue;
|
|
2808
|
+
try {
|
|
2809
|
+
execFileSync4(
|
|
2810
|
+
"sqlite3",
|
|
2811
|
+
[
|
|
2812
|
+
db,
|
|
2813
|
+
".timeout 3000",
|
|
2814
|
+
`DELETE FROM ItemTable WHERE key='${TRAECODE_WORKSPACE_ENABLED_KEY}';`
|
|
2815
|
+
],
|
|
2816
|
+
{
|
|
2817
|
+
timeout: SQLITE_TIMEOUT_MS,
|
|
2818
|
+
windowsHide: true,
|
|
2819
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2820
|
+
}
|
|
2821
|
+
);
|
|
2822
|
+
} catch {
|
|
2823
|
+
}
|
|
2824
|
+
}
|
|
2825
|
+
}
|
|
2826
|
+
function findWorkspaceStorageDir(storage, repo) {
|
|
2827
|
+
let entries;
|
|
2828
|
+
try {
|
|
2829
|
+
entries = readdirSync2(storage);
|
|
2830
|
+
} catch {
|
|
2831
|
+
return void 0;
|
|
2832
|
+
}
|
|
2833
|
+
for (const name of entries) {
|
|
2834
|
+
try {
|
|
2835
|
+
const doc = JSON.parse(readFileSync12(join18(storage, name, "workspace.json"), "utf8"));
|
|
2836
|
+
if (typeof doc.folder !== "string") continue;
|
|
2837
|
+
let folder;
|
|
2838
|
+
try {
|
|
2839
|
+
folder = fileURLToPath6(doc.folder);
|
|
2840
|
+
} catch {
|
|
2841
|
+
folder = doc.folder;
|
|
2842
|
+
}
|
|
2843
|
+
if (folder === repo) return join18(storage, name);
|
|
2844
|
+
} catch {
|
|
2845
|
+
continue;
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
return void 0;
|
|
2849
|
+
}
|
|
2850
|
+
function ensureWorkspaceMcpEnabled(cwd, opts = {}) {
|
|
2851
|
+
try {
|
|
2852
|
+
const home = opts.home ?? homedir8();
|
|
2853
|
+
if (!cwd || !isAbsolute3(cwd) || dirname11(cwd) === cwd || cwd === home) return "failed";
|
|
2854
|
+
const dir = findWorkspaceStorageDir(traecodeWorkspaceStorageDir(home), cwd);
|
|
2855
|
+
if (!dir) return "failed";
|
|
2856
|
+
const db = join18(dir, "state.vscdb");
|
|
2857
|
+
if (!existsSync8(db)) return "failed";
|
|
2858
|
+
const sqlite = opts.sqlite ?? execFileSync4;
|
|
2859
|
+
const run2 = (sql) => sqlite("sqlite3", [db, ".timeout 3000", sql], {
|
|
2860
|
+
encoding: "utf8",
|
|
2861
|
+
timeout: SQLITE_TIMEOUT_MS,
|
|
2862
|
+
windowsHide: true,
|
|
2863
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2864
|
+
}).trim();
|
|
2865
|
+
if (run2(`SELECT value FROM ItemTable WHERE key='${TRAECODE_WORKSPACE_ENABLED_KEY}';`) === "true") {
|
|
2866
|
+
return "on";
|
|
2867
|
+
}
|
|
2868
|
+
run2(
|
|
2869
|
+
`INSERT OR REPLACE INTO ItemTable (key, value) VALUES ('${TRAECODE_WORKSPACE_ENABLED_KEY}', 'true');`
|
|
2870
|
+
);
|
|
2871
|
+
diag("traecode", "workspace_mcp_enabled_seeded", { cwd, db });
|
|
2872
|
+
return "seeded";
|
|
2873
|
+
} catch (e) {
|
|
2874
|
+
diag("traecode", "workspace_mcp_enabled_seed_failed", {
|
|
2875
|
+
cwd,
|
|
2876
|
+
error: e instanceof Error ? e.message : String(e)
|
|
2877
|
+
});
|
|
2878
|
+
return "failed";
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
function workspaceEnableHint(opts = {}) {
|
|
2882
|
+
try {
|
|
2883
|
+
const now = opts.now ?? Date.now();
|
|
2884
|
+
const state = readGateState(opts);
|
|
2885
|
+
if (typeof state.lastEnableHint === "number" && now - state.lastEnableHint < HINT_MIN_INTERVAL_MS) {
|
|
2886
|
+
return void 0;
|
|
2887
|
+
}
|
|
2888
|
+
writeFileSync4(
|
|
2889
|
+
opts.stateFile ?? gateStateFile(),
|
|
2890
|
+
JSON.stringify({ ...state, lastEnableHint: now }, null, 2) + "\n"
|
|
2891
|
+
);
|
|
2892
|
+
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.";
|
|
2893
|
+
} catch {
|
|
2894
|
+
return void 0;
|
|
2895
|
+
}
|
|
2896
|
+
}
|
|
2897
|
+
|
|
2563
2898
|
// src/core/transcript-codex.ts
|
|
2564
2899
|
function stampOf(line) {
|
|
2565
2900
|
return typeof line.timestamp === "string" && line.timestamp ? { timestamp: line.timestamp } : {};
|
|
@@ -2569,11 +2904,56 @@ function isSyntheticUserText(text) {
|
|
|
2569
2904
|
return s.startsWith("# AGENTS.md instructions for ") || s.startsWith("<environment_context>");
|
|
2570
2905
|
}
|
|
2571
2906
|
function contentText(content) {
|
|
2572
|
-
return (content
|
|
2907
|
+
return (Array.isArray(content) ? content : []).filter((c) => c && typeof c.text === "string").map((c) => c.text).join("\n");
|
|
2908
|
+
}
|
|
2909
|
+
var startupKinds = /* @__PURE__ */ new Set([
|
|
2910
|
+
"agents_md.instructions",
|
|
2911
|
+
"environments.instructions",
|
|
2912
|
+
"environments.environment_context",
|
|
2913
|
+
"plugins.recommendations",
|
|
2914
|
+
"plugins.usage_instructions"
|
|
2915
|
+
]);
|
|
2916
|
+
function fallbackUserText(payload) {
|
|
2917
|
+
const content = payload.content;
|
|
2918
|
+
const kinds = payload.internal_chat_message_metadata_passthrough?.content_item_kinds;
|
|
2919
|
+
if (Array.isArray(content) && Array.isArray(kinds) && kinds.length === content.length && kinds.every((kind) => typeof kind === "string" && kind.length > 0)) {
|
|
2920
|
+
return contentText(content.filter((_, index) => !startupKinds.has(kinds[index])));
|
|
2921
|
+
}
|
|
2922
|
+
const text = contentText(content);
|
|
2923
|
+
return isSyntheticUserText(stripInjectedMemory(text)) ? "" : text;
|
|
2573
2924
|
}
|
|
2574
2925
|
function isUserMessageEvent(line) {
|
|
2575
2926
|
return line.type === "event_msg" && line.payload?.type === "item_completed" && line.payload.item?.type === "UserMessage";
|
|
2576
2927
|
}
|
|
2928
|
+
var TOOL_ITEM_TYPES = /* @__PURE__ */ new Set(["McpToolCall", "CommandExecution"]);
|
|
2929
|
+
function isToolItemEvent(line) {
|
|
2930
|
+
return line.type === "event_msg" && line.payload?.type === "item_completed" && TOOL_ITEM_TYPES.has(line.payload.item?.type ?? "");
|
|
2931
|
+
}
|
|
2932
|
+
function parseArgs(raw) {
|
|
2933
|
+
if (typeof raw !== "string") return raw;
|
|
2934
|
+
try {
|
|
2935
|
+
return JSON.parse(raw);
|
|
2936
|
+
} catch {
|
|
2937
|
+
return void 0;
|
|
2938
|
+
}
|
|
2939
|
+
}
|
|
2940
|
+
var SHELL_RE = /(?:^|\/)(?:sh|bash|zsh|dash|ksh|fish)$/;
|
|
2941
|
+
function commandText(command) {
|
|
2942
|
+
if (typeof command === "string") return command;
|
|
2943
|
+
if (!Array.isArray(command) || !command.every((c) => typeof c === "string")) return "";
|
|
2944
|
+
const argv = command;
|
|
2945
|
+
if (argv.length === 3 && SHELL_RE.test(argv[0]) && /^-[a-z]*c$/.test(argv[1])) return argv[2];
|
|
2946
|
+
return argv.join(" ");
|
|
2947
|
+
}
|
|
2948
|
+
function toolItemAction(item) {
|
|
2949
|
+
if (item.type === "McpToolCall") {
|
|
2950
|
+
if (typeof item.tool !== "string" || !item.tool) return void 0;
|
|
2951
|
+
const name = typeof item.server === "string" && item.server ? `mcp__${item.server}__${item.tool}` : item.tool;
|
|
2952
|
+
return actionLine(name, parseArgs(item.arguments));
|
|
2953
|
+
}
|
|
2954
|
+
const command = commandText(item.command).trim();
|
|
2955
|
+
return command ? actionLine("exec_command", { command }) : void 0;
|
|
2956
|
+
}
|
|
2577
2957
|
function readCodexTranscript(path) {
|
|
2578
2958
|
const lines = [];
|
|
2579
2959
|
for (const rawLine of readJsonl(path)) {
|
|
@@ -2587,6 +2967,7 @@ function readCodexTranscript(path) {
|
|
|
2587
2967
|
}
|
|
2588
2968
|
}
|
|
2589
2969
|
const userFromEvents = lines.some(isUserMessageEvent);
|
|
2970
|
+
const actionsFromEvents = lines.some(isToolItemEvent);
|
|
2590
2971
|
const turns = [];
|
|
2591
2972
|
const push = (role, raw, stamp = {}) => {
|
|
2592
2973
|
const text = stripInjectedMemory(raw).trim();
|
|
@@ -2597,16 +2978,24 @@ function readCodexTranscript(path) {
|
|
|
2597
2978
|
push("user", contentText(line.payload?.item?.content), stampOf(line));
|
|
2598
2979
|
continue;
|
|
2599
2980
|
}
|
|
2981
|
+
if (isToolItemEvent(line)) {
|
|
2982
|
+
const action = toolItemAction(line.payload?.item ?? {});
|
|
2983
|
+
if (action) turns.push({ role: "action", content: action, ...stampOf(line) });
|
|
2984
|
+
continue;
|
|
2985
|
+
}
|
|
2600
2986
|
if (line.type !== "response_item") continue;
|
|
2601
2987
|
const p = line.payload;
|
|
2602
2988
|
if (!p || typeof p !== "object") continue;
|
|
2603
2989
|
if (p.type === "message") {
|
|
2604
|
-
if (p.role === "assistant")
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2990
|
+
if (p.role === "assistant") {
|
|
2991
|
+
if (p.channel === "analysis" || p.channel === "reasoning" || p.phase === "analysis" || p.phase === "reasoning")
|
|
2992
|
+
continue;
|
|
2993
|
+
push("assistant", contentText(p.content), stampOf(line));
|
|
2994
|
+
} else if (p.role === "user" && !userFromEvents) {
|
|
2995
|
+
push("user", fallbackUserText(p), stampOf(line));
|
|
2608
2996
|
}
|
|
2609
2997
|
} else if ((p.type === "function_call" || p.type === "custom_tool_call") && typeof p.name === "string") {
|
|
2998
|
+
if (actionsFromEvents && p.type === "custom_tool_call" && p.name === "exec") continue;
|
|
2610
2999
|
const rawInput = p.type === "function_call" ? p.arguments : p.input;
|
|
2611
3000
|
let input;
|
|
2612
3001
|
try {
|
|
@@ -2707,19 +3096,19 @@ function readCopilotTranscript(path) {
|
|
|
2707
3096
|
}
|
|
2708
3097
|
|
|
2709
3098
|
// src/core/transcript-grok.ts
|
|
2710
|
-
import { existsSync as
|
|
2711
|
-
import { homedir as
|
|
2712
|
-
import { join as
|
|
3099
|
+
import { existsSync as existsSync9, readFileSync as readFileSync13, readdirSync as readdirSync3 } from "fs";
|
|
3100
|
+
import { homedir as homedir9 } from "os";
|
|
3101
|
+
import { join as join19 } from "path";
|
|
2713
3102
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
2714
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
2715
|
-
const sessionsDir =
|
|
2716
|
-
const direct =
|
|
2717
|
-
if (
|
|
3103
|
+
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join19(homedir9(), ".grok")) {
|
|
3104
|
+
const sessionsDir = join19(grokHome, "sessions");
|
|
3105
|
+
const direct = join19(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
|
|
3106
|
+
if (existsSync9(direct)) return direct;
|
|
2718
3107
|
try {
|
|
2719
|
-
for (const candidate of
|
|
2720
|
-
const directory =
|
|
2721
|
-
if (
|
|
2722
|
-
return
|
|
3108
|
+
for (const candidate of readdirSync3(sessionsDir)) {
|
|
3109
|
+
const directory = join19(sessionsDir, candidate);
|
|
3110
|
+
if (readFileSync13(join19(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
3111
|
+
return join19(directory, sessionId, CHAT_HISTORY);
|
|
2723
3112
|
}
|
|
2724
3113
|
}
|
|
2725
3114
|
} catch {
|
|
@@ -2754,12 +3143,12 @@ function readGrokTranscript(path) {
|
|
|
2754
3143
|
}
|
|
2755
3144
|
|
|
2756
3145
|
// src/core/transcript-devin.ts
|
|
2757
|
-
import { existsSync as
|
|
3146
|
+
import { existsSync as existsSync10 } from "fs";
|
|
2758
3147
|
import { createRequire } from "module";
|
|
2759
|
-
import { homedir as
|
|
2760
|
-
import { join as
|
|
2761
|
-
function devinSessionDb(home =
|
|
2762
|
-
return
|
|
3148
|
+
import { homedir as homedir10 } from "os";
|
|
3149
|
+
import { join as join20 } from "path";
|
|
3150
|
+
function devinSessionDb(home = homedir10()) {
|
|
3151
|
+
return join20(home, ".local", "share", "devin", "cli", "sessions.db");
|
|
2763
3152
|
}
|
|
2764
3153
|
function parseDevinMessages(nodes) {
|
|
2765
3154
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -2796,7 +3185,7 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
|
|
|
2796
3185
|
diag("devin-cli", "sqlite_unavailable", { node: process.version, dbPath });
|
|
2797
3186
|
return [];
|
|
2798
3187
|
}
|
|
2799
|
-
if (!
|
|
3188
|
+
if (!existsSync10(dbPath)) {
|
|
2800
3189
|
diag("devin-cli", "session_db_missing", { dbPath });
|
|
2801
3190
|
return [];
|
|
2802
3191
|
}
|
|
@@ -3069,7 +3458,7 @@ function readDroidTranscript(path) {
|
|
|
3069
3458
|
}
|
|
3070
3459
|
|
|
3071
3460
|
// src/core/transcript-zcode.ts
|
|
3072
|
-
import { readFileSync as
|
|
3461
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
3073
3462
|
function messageText(content) {
|
|
3074
3463
|
if (typeof content === "string") return content.trim();
|
|
3075
3464
|
if (!Array.isArray(content)) return "";
|
|
@@ -3079,7 +3468,7 @@ function readZcodeTranscript(path) {
|
|
|
3079
3468
|
if (!path) return [];
|
|
3080
3469
|
let body;
|
|
3081
3470
|
try {
|
|
3082
|
-
body =
|
|
3471
|
+
body = readFileSync14(path, "utf8");
|
|
3083
3472
|
} catch {
|
|
3084
3473
|
return [];
|
|
3085
3474
|
}
|
|
@@ -3113,6 +3502,131 @@ function zcodeAssistantText(path) {
|
|
|
3113
3502
|
return readZcodeTranscript(path).filter((turn) => turn.role === "assistant").at(-1)?.content ?? "";
|
|
3114
3503
|
}
|
|
3115
3504
|
|
|
3505
|
+
// src/core/transcript-kimi.ts
|
|
3506
|
+
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
3507
|
+
import { homedir as homedir11 } from "os";
|
|
3508
|
+
import { join as join21 } from "path";
|
|
3509
|
+
var HARNESS = "kimi-code";
|
|
3510
|
+
var SESSIONS_DIR = "sessions";
|
|
3511
|
+
var AGENTS_DIR = "agents";
|
|
3512
|
+
var WIRE_LOG = "wire.jsonl";
|
|
3513
|
+
var SESSION_PREFIX = "session_";
|
|
3514
|
+
var MAIN_AGENT = "main";
|
|
3515
|
+
var MAX_SESSION_CHARS = 32 * 1024 * 1024;
|
|
3516
|
+
function kimiSessionDir(sessionId, kimiHome2 = process.env.KIMI_CODE_HOME || join21(homedir11(), ".kimi-code")) {
|
|
3517
|
+
const name = sessionId.startsWith(SESSION_PREFIX) ? sessionId : `${SESSION_PREFIX}${sessionId}`;
|
|
3518
|
+
const sessions = join21(kimiHome2, SESSIONS_DIR);
|
|
3519
|
+
try {
|
|
3520
|
+
for (const workspace of readdirSync4(sessions, { withFileTypes: true })) {
|
|
3521
|
+
if (!workspace.isDirectory()) continue;
|
|
3522
|
+
const candidate = join21(sessions, workspace.name, name);
|
|
3523
|
+
if (existsSync11(join21(candidate, AGENTS_DIR))) return candidate;
|
|
3524
|
+
}
|
|
3525
|
+
} catch {
|
|
3526
|
+
}
|
|
3527
|
+
diag(HARNESS, "session_dir_missing", { sessions, session: name });
|
|
3528
|
+
return void 0;
|
|
3529
|
+
}
|
|
3530
|
+
function stampOf2(event) {
|
|
3531
|
+
if (typeof event.time !== "number") return {};
|
|
3532
|
+
const at = new Date(event.time);
|
|
3533
|
+
return Number.isNaN(at.getTime()) ? {} : { timestamp: at.toISOString() };
|
|
3534
|
+
}
|
|
3535
|
+
function kimiPromptText(input) {
|
|
3536
|
+
if (!Array.isArray(input)) return "";
|
|
3537
|
+
return input.filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n");
|
|
3538
|
+
}
|
|
3539
|
+
function readKimiWire(events) {
|
|
3540
|
+
const turns = [];
|
|
3541
|
+
let step;
|
|
3542
|
+
const flushStep = () => {
|
|
3543
|
+
if (!step) return;
|
|
3544
|
+
const content = stripInjectedMemory(step.texts.join("\n")).trim();
|
|
3545
|
+
if (content) turns.push({ role: "assistant", content, ...step.stamp });
|
|
3546
|
+
step = void 0;
|
|
3547
|
+
};
|
|
3548
|
+
for (const event of events || []) {
|
|
3549
|
+
if (!event || typeof event !== "object") continue;
|
|
3550
|
+
const stamp = stampOf2(event);
|
|
3551
|
+
if (event.type === "turn.prompt") {
|
|
3552
|
+
flushStep();
|
|
3553
|
+
if (event.origin?.kind !== "user") continue;
|
|
3554
|
+
const content = stripInjectedMemory(kimiPromptText(event.input)).trim();
|
|
3555
|
+
if (content) turns.push({ role: "user", content, ...stamp });
|
|
3556
|
+
continue;
|
|
3557
|
+
}
|
|
3558
|
+
if (event.type !== "context.append_loop_event") continue;
|
|
3559
|
+
const loop = event.event;
|
|
3560
|
+
if (!loop || typeof loop !== "object") continue;
|
|
3561
|
+
if (loop.type === "content.part") {
|
|
3562
|
+
if (loop.part?.type !== "text" || typeof loop.part.text !== "string") continue;
|
|
3563
|
+
const uuid = typeof loop.stepUuid === "string" ? loop.stepUuid : "";
|
|
3564
|
+
if (step && step.uuid !== uuid) flushStep();
|
|
3565
|
+
if (!step) step = { uuid, texts: [], stamp };
|
|
3566
|
+
step.texts.push(loop.part.text);
|
|
3567
|
+
} else if (loop.type === "tool.call") {
|
|
3568
|
+
flushStep();
|
|
3569
|
+
if (typeof loop.name !== "string" || !loop.name) continue;
|
|
3570
|
+
turns.push({ role: "action", content: actionLine(loop.name, loop.args), ...stamp });
|
|
3571
|
+
}
|
|
3572
|
+
}
|
|
3573
|
+
flushStep();
|
|
3574
|
+
return turns;
|
|
3575
|
+
}
|
|
3576
|
+
function agentIds(sessionDir) {
|
|
3577
|
+
try {
|
|
3578
|
+
return readdirSync4(join21(sessionDir, AGENTS_DIR), { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort(byAgentId);
|
|
3579
|
+
} catch {
|
|
3580
|
+
return [];
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
function byAgentId(a, b) {
|
|
3584
|
+
if (a === b) return 0;
|
|
3585
|
+
if (a === MAIN_AGENT) return -1;
|
|
3586
|
+
if (b === MAIN_AGENT) return 1;
|
|
3587
|
+
const indexA = agentIndex(a);
|
|
3588
|
+
const indexB = agentIndex(b);
|
|
3589
|
+
return indexA === indexB ? a.localeCompare(b) : indexA - indexB;
|
|
3590
|
+
}
|
|
3591
|
+
function agentIndex(id) {
|
|
3592
|
+
const suffix = Number(id.slice(id.lastIndexOf("-") + 1));
|
|
3593
|
+
return Number.isFinite(suffix) ? suffix : Number.MAX_SAFE_INTEGER;
|
|
3594
|
+
}
|
|
3595
|
+
function parseEvent(rawLine) {
|
|
3596
|
+
const trimmed = rawLine.trim();
|
|
3597
|
+
if (!trimmed) return void 0;
|
|
3598
|
+
let parsed;
|
|
3599
|
+
try {
|
|
3600
|
+
parsed = JSON.parse(trimmed);
|
|
3601
|
+
} catch {
|
|
3602
|
+
return void 0;
|
|
3603
|
+
}
|
|
3604
|
+
return typeof parsed === "object" && parsed !== null ? parsed : void 0;
|
|
3605
|
+
}
|
|
3606
|
+
function readKimiTranscript(path) {
|
|
3607
|
+
const turns = [];
|
|
3608
|
+
let remaining = MAX_SESSION_CHARS;
|
|
3609
|
+
for (const agentId of agentIds(path)) {
|
|
3610
|
+
const wire = join21(path, AGENTS_DIR, agentId, WIRE_LOG);
|
|
3611
|
+
const events = [];
|
|
3612
|
+
for (const rawLine of readJsonl(wire)) {
|
|
3613
|
+
remaining -= rawLine.length;
|
|
3614
|
+
if (remaining < 0) break;
|
|
3615
|
+
const event = parseEvent(rawLine);
|
|
3616
|
+
if (event) events.push(event);
|
|
3617
|
+
}
|
|
3618
|
+
for (const turn of readKimiWire(events)) turns.push(turn);
|
|
3619
|
+
if (remaining < 0) {
|
|
3620
|
+
log.warn(HARNESS, "session exceeds the wire-log budget \u2014 later agents were not read", {
|
|
3621
|
+
sessionDir: path,
|
|
3622
|
+
stoppedAt: wire
|
|
3623
|
+
});
|
|
3624
|
+
break;
|
|
3625
|
+
}
|
|
3626
|
+
}
|
|
3627
|
+
return turns;
|
|
3628
|
+
}
|
|
3629
|
+
|
|
3116
3630
|
// src/harness/hook-lifecycle.ts
|
|
3117
3631
|
var cursorCwd = (ev) => ev.cwd ?? ev.workspace_root ?? (Array.isArray(ev.workspace_roots) ? ev.workspace_roots[0] : void 0);
|
|
3118
3632
|
var claudePrompt = {
|
|
@@ -3191,7 +3705,7 @@ var copilotPrompt = {
|
|
|
3191
3705
|
${context}`.trim()
|
|
3192
3706
|
})
|
|
3193
3707
|
};
|
|
3194
|
-
var devinCwd = () => process.env.DEVIN_PROJECT_DIR;
|
|
3708
|
+
var devinCwd = () => process.env.DEVIN_PROJECT_DIR || process.cwd();
|
|
3195
3709
|
var devinPrompt = {
|
|
3196
3710
|
harness: "devin-cli",
|
|
3197
3711
|
requireCwd: true,
|
|
@@ -3218,6 +3732,7 @@ var standardSessionStart = (harness) => ({
|
|
|
3218
3732
|
}
|
|
3219
3733
|
})
|
|
3220
3734
|
});
|
|
3735
|
+
var notGrokHosted = () => !process.env.GROK_HOOK_EVENT;
|
|
3221
3736
|
var HOOK_HARNESSES = {
|
|
3222
3737
|
"claude-code": {
|
|
3223
3738
|
configStyle: "nested",
|
|
@@ -3226,11 +3741,12 @@ var HOOK_HARNESSES = {
|
|
|
3226
3741
|
prompt: { event: "UserPromptSubmit", entry: "claude-hook.js", timeout: 30 },
|
|
3227
3742
|
stop: { event: "Stop", entry: "claude-stop-hook.js", timeout: 60 }
|
|
3228
3743
|
},
|
|
3229
|
-
sessionStart: standardSessionStart("claude-code"),
|
|
3230
|
-
prompt: claudePrompt,
|
|
3744
|
+
sessionStart: { ...standardSessionStart("claude-code"), accept: notGrokHosted },
|
|
3745
|
+
prompt: { ...claudePrompt, accept: notGrokHosted },
|
|
3231
3746
|
retain: {
|
|
3232
3747
|
hostTimeoutSec: 60,
|
|
3233
3748
|
harness: "claude-code",
|
|
3749
|
+
accept: notGrokHosted,
|
|
3234
3750
|
parse: (ev) => ({
|
|
3235
3751
|
sessionId: ev.session_id,
|
|
3236
3752
|
transcriptPath: ev.transcript_path,
|
|
@@ -3546,37 +4062,148 @@ var HOOK_HARNESSES = {
|
|
|
3546
4062
|
assistantText: (ev) => (ev.responseText || zcodeAssistantText(ev.transcript_path) || ev.responsePreview || "").trim()
|
|
3547
4063
|
}
|
|
3548
4064
|
}
|
|
4065
|
+
},
|
|
4066
|
+
/**
|
|
4067
|
+
* TraeCode (TRAE CN's agent) also speaks Claude Code's hook protocol — `prompt`/`cwd`/`session_id`
|
|
4068
|
+
* in, `hookSpecificOutput.additionalContext` + `systemMessage` out — with registrations nested
|
|
4069
|
+
* under the top-level `hooks` key of `~/.trae-cn/hooks.json` (unlike Factory Droid, whose event
|
|
4070
|
+
* map IS the file) and a `version` field the host writes and expects.
|
|
4071
|
+
*
|
|
4072
|
+
* Like ZCode, what it does not have is a TRANSCRIPT: sessions live in an encrypted local DB or
|
|
4073
|
+
* the cloud and no `transcript_path` is ever supplied, so this is the second harness that retains
|
|
4074
|
+
* from the plugin's own journal (core/turn-journal.ts) — the prompt hook appends the user turn,
|
|
4075
|
+
* and Stop's `last_assistant_message` (the full reply) plays the role ZCode's `responseText`
|
|
4076
|
+
* plays: `journal.assistantText` closes the turn with it.
|
|
4077
|
+
*/
|
|
4078
|
+
traecode: {
|
|
4079
|
+
configStyle: "nested",
|
|
4080
|
+
install: {
|
|
4081
|
+
sessionStart: { event: "SessionStart", entry: "traecode-sessionstart-hook.js", timeout: 30 },
|
|
4082
|
+
prompt: { event: "UserPromptSubmit", entry: "traecode-hook.js", timeout: 30 },
|
|
4083
|
+
stop: { event: "Stop", entry: "traecode-stop-hook.js", timeout: 60 }
|
|
4084
|
+
},
|
|
4085
|
+
sessionStart: {
|
|
4086
|
+
...standardSessionStart("traecode"),
|
|
4087
|
+
// Trae launches USER-level MCP servers from the Electron process's cwd (home), where an
|
|
4088
|
+
// optInOnly config self-disables and the tools vanish. Each repo's own workspace file fixes
|
|
4089
|
+
// it — kept current here, once memory is confirmed live for the repo, along with the
|
|
4090
|
+
// workspace's per-server enable switch (seeded into Trae's storage DB,
|
|
4091
|
+
// core/traecode-mcp.ts). The returned hint (global gate off, or an unseedable switch)
|
|
4092
|
+
// rides the session banner.
|
|
4093
|
+
ensureMcpRegistration: (cwd) => ensureTraecodeWorkspaceMcp(cwd)
|
|
4094
|
+
},
|
|
4095
|
+
prompt: {
|
|
4096
|
+
...claudePrompt,
|
|
4097
|
+
harness: "traecode",
|
|
4098
|
+
journalPrompt: true,
|
|
4099
|
+
// TraeCode's UserPromptSubmit payload carries `prompt` exactly like Claude Code's.
|
|
4100
|
+
parse: (ev) => ({
|
|
4101
|
+
prompt: ev.prompt,
|
|
4102
|
+
cwd: ev.cwd,
|
|
4103
|
+
sessionId: ev.session_id
|
|
4104
|
+
})
|
|
4105
|
+
},
|
|
4106
|
+
retain: {
|
|
4107
|
+
hostTimeoutSec: 60,
|
|
4108
|
+
harness: "traecode",
|
|
4109
|
+
// No transcriptPath: the journal supplies it (see `journal` below).
|
|
4110
|
+
parse: (ev) => ({
|
|
4111
|
+
sessionId: ev.session_id,
|
|
4112
|
+
cwd: ev.cwd
|
|
4113
|
+
}),
|
|
4114
|
+
journal: {
|
|
4115
|
+
// `last_assistant_message` is the full reply — TraeCode's `responseText`.
|
|
4116
|
+
assistantText: (ev) => (ev.last_assistant_message ?? "").trim()
|
|
4117
|
+
}
|
|
4118
|
+
}
|
|
4119
|
+
},
|
|
4120
|
+
"kimi-code": {
|
|
4121
|
+
// Kimi's ~/.kimi-code/config.toml takes a FLAT [[hooks]] array whose entries are validated by a
|
|
4122
|
+
// strict 4-key schema (event/matcher/command/timeout). Neither JSON style can express it, and a
|
|
4123
|
+
// fifth key drops EVERY hook in the file at warning severity, so its installer writes the block
|
|
4124
|
+
// itself (the grok-build pattern) rather than going through mergeHarnessHooks.
|
|
4125
|
+
configStyle: "toml-array",
|
|
4126
|
+
install: {
|
|
4127
|
+
// Timeouts are SECONDS here (integer 1-600, default 30) — the same unit as every other
|
|
4128
|
+
// supported host, and the opposite of qwen-code's identically named field.
|
|
4129
|
+
sessionStart: { event: "SessionStart", entry: "kimi-sessionstart-hook.js", timeout: 30 },
|
|
4130
|
+
prompt: { event: "UserPromptSubmit", entry: "kimi-hook.js", timeout: 30 },
|
|
4131
|
+
stop: { event: "Stop", entry: "kimi-stop-hook.js", timeout: 60 }
|
|
4132
|
+
},
|
|
4133
|
+
sessionStart: {
|
|
4134
|
+
harness: "kimi-code",
|
|
4135
|
+
parse: (ev) => ({
|
|
4136
|
+
cwd: ev.cwd,
|
|
4137
|
+
sessionId: ev.session_id
|
|
4138
|
+
}),
|
|
4139
|
+
// Kimi runs SessionStart hooks for their side effects only: it awaits the trigger and drops
|
|
4140
|
+
// the result, so nothing emitted here can reach the model or the terminal. Installed for the
|
|
4141
|
+
// seed/daemon/session-root work runSessionStartHook does, and silent like antigravity-cli's.
|
|
4142
|
+
emit: () => ({})
|
|
4143
|
+
},
|
|
4144
|
+
prompt: {
|
|
4145
|
+
harness: "kimi-code",
|
|
4146
|
+
parse: (ev) => ({
|
|
4147
|
+
// A block array, not a string — the same shape as the wire log's `turn.prompt.input`.
|
|
4148
|
+
prompt: kimiPromptText(ev.prompt),
|
|
4149
|
+
cwd: ev.cwd,
|
|
4150
|
+
sessionId: ev.session_id
|
|
4151
|
+
}),
|
|
4152
|
+
// Kimi has no additionalContext: a top-level `message` is the injection channel, which the
|
|
4153
|
+
// CLI wraps as <hook_result hook_event="UserPromptSubmit"> and appends to the conversation.
|
|
4154
|
+
// `notice` has no banner channel to reach (the copilot-cli precedent), but it cannot simply
|
|
4155
|
+
// be dropped: when a hook's stdout parses to JSON carrying no message, Kimi falls back to
|
|
4156
|
+
// injecting the RAW STDOUT, so an empty `{}` would put a literal "{}" in front of the model.
|
|
4157
|
+
// Emitting the notice on the notice-only turn is what keeps that from ever happening.
|
|
4158
|
+
emit: (context, notice) => ({ message: context || notice })
|
|
4159
|
+
},
|
|
4160
|
+
retain: {
|
|
4161
|
+
hostTimeoutSec: 60,
|
|
4162
|
+
harness: "kimi-code",
|
|
4163
|
+
parse: (ev) => {
|
|
4164
|
+
const sessionId = ev.session_id;
|
|
4165
|
+
return {
|
|
4166
|
+
sessionId,
|
|
4167
|
+
// Kimi's Stop payload carries no transcript path — its hook feature has no such field at
|
|
4168
|
+
// all — so resolve the session's own directory from the id, as grok-build does. The
|
|
4169
|
+
// reader takes that DIRECTORY and reads every agent's wire.jsonl beneath it.
|
|
4170
|
+
transcriptPath: sessionId ? kimiSessionDir(sessionId) : void 0,
|
|
4171
|
+
cwd: ev.cwd
|
|
4172
|
+
};
|
|
4173
|
+
},
|
|
4174
|
+
readTranscript: readKimiTranscript
|
|
4175
|
+
}
|
|
3549
4176
|
}
|
|
3550
4177
|
};
|
|
3551
4178
|
|
|
3552
4179
|
// src/core/history.ts
|
|
3553
|
-
import { execFileSync as
|
|
4180
|
+
import { execFileSync as execFileSync5 } from "child_process";
|
|
3554
4181
|
import {
|
|
3555
4182
|
closeSync as closeSync2,
|
|
3556
|
-
existsSync as
|
|
4183
|
+
existsSync as existsSync12,
|
|
3557
4184
|
openSync as openSync2,
|
|
3558
|
-
readdirSync as
|
|
3559
|
-
readFileSync as
|
|
4185
|
+
readdirSync as readdirSync5,
|
|
4186
|
+
readFileSync as readFileSync15,
|
|
3560
4187
|
readSync as readSync2,
|
|
3561
4188
|
statSync as statSync4
|
|
3562
4189
|
} from "fs";
|
|
3563
4190
|
import { createHash as createHash5 } from "crypto";
|
|
3564
|
-
import { homedir as
|
|
3565
|
-
import { join as
|
|
4191
|
+
import { homedir as homedir12 } from "os";
|
|
4192
|
+
import { join as join22 } from "path";
|
|
3566
4193
|
import * as zlib2 from "zlib";
|
|
3567
4194
|
|
|
3568
4195
|
// src/core/transcript-dsh.ts
|
|
3569
4196
|
function textOf(message) {
|
|
3570
4197
|
return (message.content || []).filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n").trim();
|
|
3571
4198
|
}
|
|
3572
|
-
function
|
|
4199
|
+
function stampOf3(event) {
|
|
3573
4200
|
return typeof event.time === "number" ? { timestamp: new Date(event.time).toISOString() } : {};
|
|
3574
4201
|
}
|
|
3575
4202
|
function readDshEvents(events) {
|
|
3576
4203
|
const turns = [];
|
|
3577
4204
|
for (const event of events || []) {
|
|
3578
4205
|
if (!event || typeof event !== "object") continue;
|
|
3579
|
-
const stamp =
|
|
4206
|
+
const stamp = stampOf3(event);
|
|
3580
4207
|
if (event.type === "user/message") {
|
|
3581
4208
|
const message = event.data;
|
|
3582
4209
|
if (!message || message.source?.kind !== "user") continue;
|
|
@@ -3592,14 +4219,14 @@ function readDshEvents(events) {
|
|
|
3592
4219
|
if (!call?.name) continue;
|
|
3593
4220
|
turns.push({
|
|
3594
4221
|
role: "action",
|
|
3595
|
-
content: actionLine(call.name,
|
|
4222
|
+
content: actionLine(call.name, parseArgs2(call.arguments)),
|
|
3596
4223
|
...stamp
|
|
3597
4224
|
});
|
|
3598
4225
|
}
|
|
3599
4226
|
}
|
|
3600
4227
|
return turns;
|
|
3601
4228
|
}
|
|
3602
|
-
function
|
|
4229
|
+
function parseArgs2(raw) {
|
|
3603
4230
|
if (!raw) return void 0;
|
|
3604
4231
|
try {
|
|
3605
4232
|
return JSON.parse(raw);
|
|
@@ -3706,8 +4333,8 @@ function zstdDecompressFrames(buffer) {
|
|
|
3706
4333
|
}
|
|
3707
4334
|
|
|
3708
4335
|
// src/core/history.ts
|
|
3709
|
-
function claudeProjectDir(repoDir, home =
|
|
3710
|
-
return
|
|
4336
|
+
function claudeProjectDir(repoDir, home = homedir12()) {
|
|
4337
|
+
return join22(home, ".claude", "projects", repoDir.replace(/[^a-zA-Z0-9]/g, "-"));
|
|
3711
4338
|
}
|
|
3712
4339
|
function piSessionDir(repoDir) {
|
|
3713
4340
|
return `--${repoDir.replace(/^[/\\]/, "").replace(/[/\\:]/g, "-")}--`;
|
|
@@ -3717,7 +4344,7 @@ function withinRepo(dir, repoDir) {
|
|
|
3717
4344
|
}
|
|
3718
4345
|
function claudeSessionCwd(file) {
|
|
3719
4346
|
try {
|
|
3720
|
-
for (const line of
|
|
4347
|
+
for (const line of readFileSync15(file, "utf8").split("\n", 400)) {
|
|
3721
4348
|
if (!line.includes('"cwd"')) continue;
|
|
3722
4349
|
const cwd = JSON.parse(line).cwd;
|
|
3723
4350
|
if (cwd) return cwd;
|
|
@@ -3753,19 +4380,19 @@ function firstLine(path, cap = 1e6) {
|
|
|
3753
4380
|
}
|
|
3754
4381
|
function listDir(dir) {
|
|
3755
4382
|
try {
|
|
3756
|
-
return
|
|
4383
|
+
return readdirSync5(dir);
|
|
3757
4384
|
} catch {
|
|
3758
4385
|
return [];
|
|
3759
4386
|
}
|
|
3760
4387
|
}
|
|
3761
4388
|
function jsonlFiles(dir) {
|
|
3762
|
-
return listDir(dir).filter((f) => f.endsWith(".jsonl")).map((f) =>
|
|
4389
|
+
return listDir(dir).filter((f) => f.endsWith(".jsonl")).map((f) => join22(dir, f));
|
|
3763
4390
|
}
|
|
3764
4391
|
function claudeHistory(repoDir, home) {
|
|
3765
|
-
const root =
|
|
4392
|
+
const root = join22(home, ".claude", "projects");
|
|
3766
4393
|
const exact = claudeProjectDir(repoDir, home);
|
|
3767
4394
|
const prefix = exact + "-";
|
|
3768
|
-
const dirs = listDir(root).map((d) =>
|
|
4395
|
+
const dirs = listDir(root).map((d) => join22(root, d)).filter((d) => d === exact || d.startsWith(prefix));
|
|
3769
4396
|
const sessions = [];
|
|
3770
4397
|
let unattributed = 0;
|
|
3771
4398
|
for (const file of dirs.flatMap(jsonlFiles)) {
|
|
@@ -3785,12 +4412,12 @@ function claudeHistory(repoDir, home) {
|
|
|
3785
4412
|
return { supported: true, sessions, unattributed };
|
|
3786
4413
|
}
|
|
3787
4414
|
function codexHistory(repoDir, home) {
|
|
3788
|
-
const root =
|
|
3789
|
-
if (!
|
|
4415
|
+
const root = join22(home, ".codex", "sessions");
|
|
4416
|
+
if (!existsSync12(root)) return { supported: true, sessions: [] };
|
|
3790
4417
|
const files = [];
|
|
3791
4418
|
const walk = (dir) => {
|
|
3792
|
-
for (const entry of
|
|
3793
|
-
const p =
|
|
4419
|
+
for (const entry of readdirSync5(dir)) {
|
|
4420
|
+
const p = join22(dir, entry);
|
|
3794
4421
|
if (statSync4(p).isDirectory()) walk(p);
|
|
3795
4422
|
else if (entry.endsWith(".jsonl")) files.push(p);
|
|
3796
4423
|
}
|
|
@@ -3819,15 +4446,15 @@ function dcodeTranscriptPath(root, threadId) {
|
|
|
3819
4446
|
const digest = createHash5("sha256").update(threadId, "utf8").digest("hex");
|
|
3820
4447
|
const suffix = `--${digest}.jsonl`;
|
|
3821
4448
|
try {
|
|
3822
|
-
const match =
|
|
3823
|
-
return match ?
|
|
4449
|
+
const match = readdirSync5(root).find((entry) => entry.endsWith(suffix));
|
|
4450
|
+
return match ? join22(root, match) : void 0;
|
|
3824
4451
|
} catch {
|
|
3825
4452
|
return void 0;
|
|
3826
4453
|
}
|
|
3827
4454
|
}
|
|
3828
4455
|
function dcodeHistory(repoDir, home, runCli) {
|
|
3829
|
-
const root =
|
|
3830
|
-
if (!
|
|
4456
|
+
const root = join22(process.env.DEEPAGENTS_HOME || join22(home, ".deepagents"), "transcripts");
|
|
4457
|
+
if (!existsSync12(root)) return { supported: true, sessions: [] };
|
|
3831
4458
|
let listed;
|
|
3832
4459
|
try {
|
|
3833
4460
|
listed = JSON.parse(runCli(["threads", "list", "--json"]));
|
|
@@ -3867,8 +4494,8 @@ function dcodeHistory(repoDir, home, runCli) {
|
|
|
3867
4494
|
return { supported: true, sessions, ...unattributed ? { unattributed } : {} };
|
|
3868
4495
|
}
|
|
3869
4496
|
function dshHistory(repoDir, home) {
|
|
3870
|
-
const root = process.env.DSH_HOME ?
|
|
3871
|
-
if (!
|
|
4497
|
+
const root = process.env.DSH_HOME ? join22(process.env.DSH_HOME, "sessions") : join22(home, ".dsh", "sessions");
|
|
4498
|
+
if (!existsSync12(root)) return { supported: true, sessions: [] };
|
|
3872
4499
|
if (typeof zlib2.zstdDecompressSync !== "function") {
|
|
3873
4500
|
return {
|
|
3874
4501
|
supported: false,
|
|
@@ -3878,15 +4505,15 @@ function dshHistory(repoDir, home) {
|
|
|
3878
4505
|
}
|
|
3879
4506
|
const sessions = [];
|
|
3880
4507
|
let unattributed = 0;
|
|
3881
|
-
for (const dir of
|
|
4508
|
+
for (const dir of readdirSync5(root).map((project) => join22(root, project))) {
|
|
3882
4509
|
let sessionDirs;
|
|
3883
4510
|
try {
|
|
3884
|
-
sessionDirs =
|
|
4511
|
+
sessionDirs = readdirSync5(dir).map((id) => join22(dir, id));
|
|
3885
4512
|
} catch {
|
|
3886
4513
|
continue;
|
|
3887
4514
|
}
|
|
3888
4515
|
for (const sessionDir of sessionDirs) {
|
|
3889
|
-
const file = ["session.jsonl.zstd", "session.jsonl"].map((name) =>
|
|
4516
|
+
const file = ["session.jsonl.zstd", "session.jsonl"].map((name) => join22(sessionDir, name)).find((candidate) => existsSync12(candidate));
|
|
3890
4517
|
if (!file) continue;
|
|
3891
4518
|
try {
|
|
3892
4519
|
const lines = readDshLog(file);
|
|
@@ -3912,7 +4539,7 @@ function dshHistory(repoDir, home) {
|
|
|
3912
4539
|
return { supported: true, sessions, unattributed };
|
|
3913
4540
|
}
|
|
3914
4541
|
function readDshLog(file) {
|
|
3915
|
-
const bytes =
|
|
4542
|
+
const bytes = readFileSync15(file);
|
|
3916
4543
|
const text = file.endsWith(".zstd") ? zstdDecompressFrames(bytes) : bytes.toString("utf8");
|
|
3917
4544
|
return text.split("\n").filter((line) => line.trim());
|
|
3918
4545
|
}
|
|
@@ -3938,23 +4565,23 @@ function piFamilySessions(files, repoDir) {
|
|
|
3938
4565
|
return { supported: true, sessions, unattributed };
|
|
3939
4566
|
}
|
|
3940
4567
|
function piHistory(repoDir, home) {
|
|
3941
|
-
const root =
|
|
3942
|
-
if (!
|
|
4568
|
+
const root = join22(home, ".pi", "agent", "sessions");
|
|
4569
|
+
if (!existsSync12(root)) return { supported: true, sessions: [] };
|
|
3943
4570
|
const exact = piSessionDir(repoDir);
|
|
3944
4571
|
const nested = `${exact.slice(0, -2)}-`;
|
|
3945
4572
|
const files = [];
|
|
3946
4573
|
for (const dir of listDir(root).filter((d) => d === exact || d.startsWith(nested))) {
|
|
3947
|
-
files.push(...jsonlFiles(
|
|
4574
|
+
files.push(...jsonlFiles(join22(root, dir)));
|
|
3948
4575
|
}
|
|
3949
4576
|
return piFamilySessions(files, repoDir);
|
|
3950
4577
|
}
|
|
3951
4578
|
function primeAgentHistory(repoDir, home) {
|
|
3952
|
-
const root =
|
|
3953
|
-
if (!
|
|
4579
|
+
const root = join22(home, ".prime", "agent", "sessions");
|
|
4580
|
+
if (!existsSync12(root)) return { supported: true, sessions: [] };
|
|
3954
4581
|
return piFamilySessions(jsonlFiles(root), repoDir);
|
|
3955
4582
|
}
|
|
3956
4583
|
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 =
|
|
4584
|
+
function importLocalHistory(harness, repoDir, home = homedir12(), runDcodeCli) {
|
|
3958
4585
|
switch (harness) {
|
|
3959
4586
|
case "claude-code":
|
|
3960
4587
|
return claudeHistory(repoDir, home);
|
|
@@ -3964,7 +4591,7 @@ function importLocalHistory(harness, repoDir, home = homedir10(), runDcodeCli) {
|
|
|
3964
4591
|
return dcodeHistory(
|
|
3965
4592
|
repoDir,
|
|
3966
4593
|
home,
|
|
3967
|
-
runDcodeCli ?? ((args) =>
|
|
4594
|
+
runDcodeCli ?? ((args) => execFileSync5("dcode", args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }))
|
|
3968
4595
|
);
|
|
3969
4596
|
case "dsh":
|
|
3970
4597
|
return dshHistory(repoDir, home);
|
|
@@ -3981,10 +4608,14 @@ function importLocalHistory(harness, repoDir, home = homedir10(), runDcodeCli) {
|
|
|
3981
4608
|
case "copilot-cli":
|
|
3982
4609
|
case "devin-cli":
|
|
3983
4610
|
return { supported: false, reason: `${harness} ${SQLITE_HISTORY}`, sessions: [] };
|
|
4611
|
+
// TraeCode has no reader for the same reason as ZCode below: no session files on disk at all
|
|
4612
|
+
// (sessions live in an encrypted local DB / the cloud), which is why the plugin journals live
|
|
4613
|
+
// sessions itself (core/turn-journal.ts) — and why there is no past history to backfill from.
|
|
4614
|
+
case "traecode":
|
|
3984
4615
|
case "zcode":
|
|
3985
4616
|
return {
|
|
3986
4617
|
supported: false,
|
|
3987
|
-
reason:
|
|
4618
|
+
reason: `${harness} keeps no session transcripts on disk to import`,
|
|
3988
4619
|
sessions: []
|
|
3989
4620
|
};
|
|
3990
4621
|
default:
|
|
@@ -3993,7 +4624,7 @@ function importLocalHistory(harness, repoDir, home = homedir10(), runDcodeCli) {
|
|
|
3993
4624
|
}
|
|
3994
4625
|
|
|
3995
4626
|
// src/install-ui.ts
|
|
3996
|
-
import { execFileSync as
|
|
4627
|
+
import { execFileSync as execFileSync6 } from "child_process";
|
|
3997
4628
|
import { readSync as readSync3 } from "fs";
|
|
3998
4629
|
function fitSelectRow(label, hint, width) {
|
|
3999
4630
|
const room = Math.max(10, width - 6);
|
|
@@ -4088,7 +4719,7 @@ function createInstallerUi(o) {
|
|
|
4088
4719
|
return `${bar} ${question}`;
|
|
4089
4720
|
},
|
|
4090
4721
|
select(question, options, defaultIndex) {
|
|
4091
|
-
const stty = (args) =>
|
|
4722
|
+
const stty = (args) => execFileSync6("stty", args, { stdio: ["inherit", "pipe", "pipe"], encoding: "utf8" }).trim();
|
|
4092
4723
|
let savedTty;
|
|
4093
4724
|
try {
|
|
4094
4725
|
savedTty = stty(["-g"]);
|
|
@@ -4197,10 +4828,14 @@ function createInstallerUi(o) {
|
|
|
4197
4828
|
// src/installer.ts
|
|
4198
4829
|
var MARKER = "coding-agents";
|
|
4199
4830
|
var ZCODE_MAX_OUTPUT_BYTES = 32768;
|
|
4200
|
-
var zcodeConfigPath = (c) =>
|
|
4831
|
+
var zcodeConfigPath = (c) => join23(c.home, ".zcode", "cli", "config.json");
|
|
4832
|
+
function isPlainObject(value) {
|
|
4833
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
4834
|
+
}
|
|
4201
4835
|
function readJson(path) {
|
|
4202
4836
|
try {
|
|
4203
|
-
|
|
4837
|
+
const parsed = JSON.parse(readFileSync16(path, "utf8"));
|
|
4838
|
+
return isPlainObject(parsed) ? parsed : {};
|
|
4204
4839
|
} catch {
|
|
4205
4840
|
return {};
|
|
4206
4841
|
}
|
|
@@ -4215,17 +4850,17 @@ function parseJsonc(text) {
|
|
|
4215
4850
|
}
|
|
4216
4851
|
}
|
|
4217
4852
|
function writeJson(path, value) {
|
|
4218
|
-
|
|
4853
|
+
mkdirSync7(dirname12(path), { recursive: true });
|
|
4219
4854
|
backupOnce(path);
|
|
4220
|
-
|
|
4855
|
+
writeFileSync5(path, JSON.stringify(value, null, 2) + "\n");
|
|
4221
4856
|
}
|
|
4222
4857
|
function backupOnce(path) {
|
|
4223
|
-
if (
|
|
4858
|
+
if (existsSync13(path) && !existsSync13(`${path}.hindsight-backup`)) {
|
|
4224
4859
|
copyFileSync(path, `${path}.hindsight-backup`);
|
|
4225
4860
|
}
|
|
4226
4861
|
}
|
|
4227
4862
|
function writeJsonc(path, key, value) {
|
|
4228
|
-
const text =
|
|
4863
|
+
const text = existsSync13(path) ? readFileSync16(path, "utf8") : "";
|
|
4229
4864
|
const edits = modify(text, [key], value, {
|
|
4230
4865
|
formattingOptions: {
|
|
4231
4866
|
tabSize: 2,
|
|
@@ -4236,9 +4871,9 @@ function writeJsonc(path, key, value) {
|
|
|
4236
4871
|
}
|
|
4237
4872
|
});
|
|
4238
4873
|
const next = applyEdits(text, edits);
|
|
4239
|
-
|
|
4874
|
+
mkdirSync7(dirname12(path), { recursive: true });
|
|
4240
4875
|
backupOnce(path);
|
|
4241
|
-
|
|
4876
|
+
writeFileSync5(path, next.endsWith("\n") ? next : `${next}
|
|
4242
4877
|
`);
|
|
4243
4878
|
}
|
|
4244
4879
|
function mergeHookEvent(existing, entry) {
|
|
@@ -4253,33 +4888,26 @@ function setOrDelete(obj, key, arr) {
|
|
|
4253
4888
|
else delete obj[key];
|
|
4254
4889
|
}
|
|
4255
4890
|
var cmdHook = (dist, file, timeout) => ({
|
|
4256
|
-
hooks: [{ type: "command", command: `node "${
|
|
4891
|
+
hooks: [{ type: "command", command: `node "${join23(dist, file)}"`, timeout }]
|
|
4257
4892
|
});
|
|
4258
4893
|
var processHook = (dist, file, timeoutMs) => ({
|
|
4259
|
-
hooks: [{ type: "process", command: "node", args: [
|
|
4894
|
+
hooks: [{ type: "process", command: "node", args: [join23(dist, file)], timeoutMs }]
|
|
4260
4895
|
});
|
|
4261
|
-
var mcpServerEntry = (dist, harness) => ({
|
|
4896
|
+
var mcpServerEntry = (dist, harness, extraArgs = []) => ({
|
|
4262
4897
|
command: "node",
|
|
4263
|
-
args: [
|
|
4898
|
+
args: [join23(dist, "mcp-server.js"), ...extraArgs],
|
|
4264
4899
|
env: { HINDSIGHT_MCP_HARNESS: harness }
|
|
4265
4900
|
});
|
|
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
4901
|
function mergeHarnessHooks(hooks, harness, dist) {
|
|
4276
4902
|
const spec = HOOK_HARNESSES[harness];
|
|
4903
|
+
if (spec.configStyle === "toml-array")
|
|
4904
|
+
throw new Error(`${harness} writes its own TOML hook block; mergeHarnessHooks cannot emit it`);
|
|
4277
4905
|
const installedEvents = /* @__PURE__ */ new Set();
|
|
4278
4906
|
for (const hook of [...Object.values(spec.install), ...spec.additionalHooks ?? []]) {
|
|
4279
4907
|
if (installedEvents.has(hook.event)) continue;
|
|
4280
4908
|
installedEvents.add(hook.event);
|
|
4281
4909
|
const entry = spec.configStyle === "nested" ? cmdHook(dist, hook.entry, hook.timeout) : spec.configStyle === "process" ? processHook(dist, hook.entry, hook.timeout) : {
|
|
4282
|
-
command: `node "${
|
|
4910
|
+
command: `node "${join23(dist, hook.entry)}"`,
|
|
4283
4911
|
...hook.timeout ? { timeout: hook.timeout } : {}
|
|
4284
4912
|
};
|
|
4285
4913
|
hooks[hook.event] = mergeHookEvent(hooks[hook.event], entry);
|
|
@@ -4295,28 +4923,28 @@ function stripHarnessHooks(hooks, harness) {
|
|
|
4295
4923
|
}
|
|
4296
4924
|
}
|
|
4297
4925
|
function skillsBaseFor(c, harness) {
|
|
4298
|
-
const parts =
|
|
4926
|
+
const parts = resolveSkillDirs(harness, c.home);
|
|
4299
4927
|
if (!parts) throw new Error(`${harness} installs a skill but names no directory in SKILL_DIRS`);
|
|
4300
|
-
return
|
|
4928
|
+
return join23(c.home, ...parts);
|
|
4301
4929
|
}
|
|
4302
4930
|
function installSkill(c, harness) {
|
|
4303
|
-
const src =
|
|
4304
|
-
if (!
|
|
4931
|
+
const src = join23(c.pkgRoot, "skill");
|
|
4932
|
+
if (!existsSync13(join23(src, "SKILL.md"))) return;
|
|
4305
4933
|
const skillsBase = skillsBaseFor(c, harness);
|
|
4306
|
-
const dst =
|
|
4307
|
-
|
|
4934
|
+
const dst = join23(skillsBase, "hindsight-coding-agent");
|
|
4935
|
+
mkdirSync7(skillsBase, { recursive: true });
|
|
4308
4936
|
cpSync2(src, dst, { recursive: true });
|
|
4309
4937
|
c.log?.(`${harness}: skill installed at ${dst}`);
|
|
4310
4938
|
}
|
|
4311
4939
|
function uninstallSkill(c, harness) {
|
|
4312
|
-
|
|
4940
|
+
rmSync4(join23(skillsBaseFor(c, harness), "hindsight-coding-agent"), {
|
|
4313
4941
|
recursive: true,
|
|
4314
4942
|
force: true
|
|
4315
4943
|
});
|
|
4316
4944
|
}
|
|
4317
4945
|
function onPath2(bin) {
|
|
4318
4946
|
try {
|
|
4319
|
-
|
|
4947
|
+
execFileSync7("which", [bin], { stdio: "pipe" });
|
|
4320
4948
|
return true;
|
|
4321
4949
|
} catch {
|
|
4322
4950
|
return false;
|
|
@@ -4324,7 +4952,7 @@ function onPath2(bin) {
|
|
|
4324
4952
|
}
|
|
4325
4953
|
function runClinePlugin(args) {
|
|
4326
4954
|
try {
|
|
4327
|
-
|
|
4955
|
+
execFileSync7("cline", args, { stdio: "pipe" });
|
|
4328
4956
|
return true;
|
|
4329
4957
|
} catch {
|
|
4330
4958
|
return false;
|
|
@@ -4332,13 +4960,13 @@ function runClinePlugin(args) {
|
|
|
4332
4960
|
}
|
|
4333
4961
|
var OPENCODE_CONFIG_CANDIDATES = ["opencode.jsonc", "opencode.json"];
|
|
4334
4962
|
function opencodeConfigPath(c) {
|
|
4335
|
-
const dir =
|
|
4336
|
-
const existing = OPENCODE_CONFIG_CANDIDATES.map((f) =>
|
|
4337
|
-
return existing ??
|
|
4963
|
+
const dir = join23(c.home, ".config", "opencode");
|
|
4964
|
+
const existing = OPENCODE_CONFIG_CANDIDATES.map((f) => join23(dir, f)).find((p) => existsSync13(p));
|
|
4965
|
+
return existing ?? join23(dir, "opencode.json");
|
|
4338
4966
|
}
|
|
4339
4967
|
function runDcodePlugin(args) {
|
|
4340
4968
|
try {
|
|
4341
|
-
|
|
4969
|
+
execFileSync7("dcode", args, { stdio: "pipe" });
|
|
4342
4970
|
return true;
|
|
4343
4971
|
} catch {
|
|
4344
4972
|
return false;
|
|
@@ -4347,8 +4975,8 @@ function runDcodePlugin(args) {
|
|
|
4347
4975
|
function registerOpencodePlugin(c, name) {
|
|
4348
4976
|
const path = opencodeConfigPath(c);
|
|
4349
4977
|
let cfg = {};
|
|
4350
|
-
if (
|
|
4351
|
-
const parsed = parseJsonc(
|
|
4978
|
+
if (existsSync13(path)) {
|
|
4979
|
+
const parsed = parseJsonc(readFileSync16(path, "utf8"));
|
|
4352
4980
|
if (!parsed) {
|
|
4353
4981
|
c.log?.(`${name}: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
|
|
4354
4982
|
return;
|
|
@@ -4361,8 +4989,8 @@ function registerOpencodePlugin(c, name) {
|
|
|
4361
4989
|
}
|
|
4362
4990
|
function unregisterOpencodePlugin(c, name) {
|
|
4363
4991
|
const path = opencodeConfigPath(c);
|
|
4364
|
-
if (!
|
|
4365
|
-
const cfg = parseJsonc(
|
|
4992
|
+
if (!existsSync13(path)) return;
|
|
4993
|
+
const cfg = parseJsonc(readFileSync16(path, "utf8"));
|
|
4366
4994
|
if (!cfg || !Array.isArray(cfg.plugin)) return;
|
|
4367
4995
|
const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
|
|
4368
4996
|
writeJsonc(path, "plugin", kept.length ? kept : void 0);
|
|
@@ -4370,7 +4998,7 @@ function unregisterOpencodePlugin(c, name) {
|
|
|
4370
4998
|
}
|
|
4371
4999
|
var opencode = {
|
|
4372
5000
|
name: "opencode",
|
|
4373
|
-
detect: (c) => onPath2("opencode") ||
|
|
5001
|
+
detect: (c) => onPath2("opencode") || existsSync13(join23(c.home, ".config", "opencode")),
|
|
4374
5002
|
install: (c) => registerOpencodePlugin(c, "opencode"),
|
|
4375
5003
|
uninstall: (c) => unregisterOpencodePlugin(c, "opencode")
|
|
4376
5004
|
};
|
|
@@ -4381,16 +5009,16 @@ var opencode2 = {
|
|
|
4381
5009
|
uninstall: (c) => unregisterOpencodePlugin(c, "opencode2")
|
|
4382
5010
|
};
|
|
4383
5011
|
function piFamilyInstaller(harness, configDir) {
|
|
4384
|
-
const settings = (c) =>
|
|
5012
|
+
const settings = (c) => join23(c.home, ...configDir, "settings.json");
|
|
4385
5013
|
return {
|
|
4386
5014
|
name: harness,
|
|
4387
5015
|
// Both hosts name their executable exactly as we name the harness, so the harness id doubles
|
|
4388
5016
|
// as the PATH probe here — unlike, say, antigravity-cli, whose binary is `agy`.
|
|
4389
|
-
detect: (c) => onPath2(harness) ||
|
|
5017
|
+
detect: (c) => onPath2(harness) || existsSync13(join23(c.home, ...configDir)),
|
|
4390
5018
|
install(c) {
|
|
4391
5019
|
const path = settings(c);
|
|
4392
5020
|
const cfg = readJson(path);
|
|
4393
|
-
const entry =
|
|
5021
|
+
const entry = join23(c.pkgRoot, "dist", `${harness}.js`);
|
|
4394
5022
|
const exts = Array.isArray(cfg.extensions) ? cfg.extensions : [];
|
|
4395
5023
|
cfg.extensions = [...exts.filter((p) => !String(p).includes(MARKER)), entry];
|
|
4396
5024
|
writeJson(path, cfg);
|
|
@@ -4400,7 +5028,7 @@ function piFamilyInstaller(harness, configDir) {
|
|
|
4400
5028
|
uninstall(c) {
|
|
4401
5029
|
uninstallSkill(c, harness);
|
|
4402
5030
|
const path = settings(c);
|
|
4403
|
-
if (!
|
|
5031
|
+
if (!existsSync13(path)) return;
|
|
4404
5032
|
const cfg = readJson(path);
|
|
4405
5033
|
if (Array.isArray(cfg.extensions)) {
|
|
4406
5034
|
cfg.extensions = cfg.extensions.filter((p) => !String(p).includes(MARKER));
|
|
@@ -4415,33 +5043,33 @@ var pi = piFamilyInstaller("pi", [".pi", "agent"]);
|
|
|
4415
5043
|
var primeAgent = piFamilyInstaller("prime-agent", [".prime", "agent"]);
|
|
4416
5044
|
var KILO_CONFIG_CANDIDATES = ["kilo.jsonc", "kilo.json", "opencode.json"];
|
|
4417
5045
|
function kiloConfigPath(c) {
|
|
4418
|
-
const dir =
|
|
4419
|
-
const existing = KILO_CONFIG_CANDIDATES.map((f) =>
|
|
4420
|
-
return existing ??
|
|
5046
|
+
const dir = join23(c.home, ".config", "kilo");
|
|
5047
|
+
const existing = KILO_CONFIG_CANDIDATES.map((f) => join23(dir, f)).find((p) => existsSync13(p));
|
|
5048
|
+
return existing ?? join23(dir, "kilo.json");
|
|
4421
5049
|
}
|
|
4422
5050
|
var kilo = {
|
|
4423
5051
|
name: "kilo",
|
|
4424
|
-
detect: (c) => onPath2("kilo") ||
|
|
5052
|
+
detect: (c) => onPath2("kilo") || existsSync13(join23(c.home, ".config", "kilo")),
|
|
4425
5053
|
install(c) {
|
|
4426
5054
|
const path = kiloConfigPath(c);
|
|
4427
5055
|
let cfg = {};
|
|
4428
|
-
if (
|
|
4429
|
-
const parsed = parseJsonc(
|
|
5056
|
+
if (existsSync13(path)) {
|
|
5057
|
+
const parsed = parseJsonc(readFileSync16(path, "utf8"));
|
|
4430
5058
|
if (!parsed) {
|
|
4431
5059
|
c.log?.(`kilo: SKIPPED \u2014 could not parse ${path}; add the plugin entry manually`);
|
|
4432
5060
|
return;
|
|
4433
5061
|
}
|
|
4434
5062
|
cfg = parsed;
|
|
4435
5063
|
}
|
|
4436
|
-
const entry = pathToFileURL(
|
|
5064
|
+
const entry = pathToFileURL(join23(c.dist, "kilo.js")).href;
|
|
4437
5065
|
const plugins = Array.isArray(cfg.plugin) ? cfg.plugin : [];
|
|
4438
5066
|
writeJsonc(path, "plugin", [...plugins.filter((p) => !String(p).includes(MARKER)), entry]);
|
|
4439
5067
|
c.log?.(`kilo: plugin registered in ${path}`);
|
|
4440
5068
|
},
|
|
4441
5069
|
uninstall(c) {
|
|
4442
5070
|
const path = kiloConfigPath(c);
|
|
4443
|
-
if (!
|
|
4444
|
-
const cfg = parseJsonc(
|
|
5071
|
+
if (!existsSync13(path)) return;
|
|
5072
|
+
const cfg = parseJsonc(readFileSync16(path, "utf8"));
|
|
4445
5073
|
if (!cfg || !Array.isArray(cfg.plugin)) return;
|
|
4446
5074
|
const kept = cfg.plugin.filter((p) => !String(p).includes(MARKER));
|
|
4447
5075
|
writeJsonc(path, "plugin", kept.length ? kept : void 0);
|
|
@@ -4450,9 +5078,9 @@ var kilo = {
|
|
|
4450
5078
|
};
|
|
4451
5079
|
var claudeCode = {
|
|
4452
5080
|
name: "claude-code",
|
|
4453
|
-
detect: (c) => onPath2("claude") ||
|
|
5081
|
+
detect: (c) => onPath2("claude") || existsSync13(join23(c.home, ".claude")),
|
|
4454
5082
|
install(c) {
|
|
4455
|
-
const path =
|
|
5083
|
+
const path = join23(c.home, ".claude", "settings.json");
|
|
4456
5084
|
const settings = readJson(path);
|
|
4457
5085
|
settings.hooks = settings.hooks ?? {};
|
|
4458
5086
|
mergeHarnessHooks(settings.hooks, "claude-code", c.dist);
|
|
@@ -4471,19 +5099,19 @@ var claudeCode = {
|
|
|
4471
5099
|
"HINDSIGHT_MCP_HARNESS=claude-code",
|
|
4472
5100
|
"--",
|
|
4473
5101
|
"node",
|
|
4474
|
-
|
|
5102
|
+
join23(c.dist, "mcp-server.js")
|
|
4475
5103
|
])) {
|
|
4476
5104
|
c.log?.("claude-code: MCP server registered (claude mcp add, user scope)");
|
|
4477
5105
|
} else {
|
|
4478
5106
|
c.log?.(
|
|
4479
5107
|
`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 "${
|
|
5108
|
+
claude mcp add --scope user hindsight --env HINDSIGHT_MCP_HARNESS=claude-code -- node "${join23(c.dist, "mcp-server.js")}"`
|
|
4481
5109
|
);
|
|
4482
5110
|
}
|
|
4483
5111
|
},
|
|
4484
5112
|
uninstall(c) {
|
|
4485
|
-
const path =
|
|
4486
|
-
if (
|
|
5113
|
+
const path = join23(c.home, ".claude", "settings.json");
|
|
5114
|
+
if (existsSync13(path)) {
|
|
4487
5115
|
const settings = readJson(path);
|
|
4488
5116
|
if (settings.hooks) {
|
|
4489
5117
|
stripHarnessHooks(settings.hooks, "claude-code");
|
|
@@ -4499,7 +5127,7 @@ var claudeCode = {
|
|
|
4499
5127
|
};
|
|
4500
5128
|
function defaultClaudeMcp(args) {
|
|
4501
5129
|
try {
|
|
4502
|
-
|
|
5130
|
+
execFileSync7("claude", args, { stdio: "pipe" });
|
|
4503
5131
|
return true;
|
|
4504
5132
|
} catch {
|
|
4505
5133
|
return false;
|
|
@@ -4508,20 +5136,20 @@ function defaultClaudeMcp(args) {
|
|
|
4508
5136
|
var CODEX_MCP_BLOCK_RE = /^\[mcp_servers\.hindsight(?:\.[^\]]+)?\][^\n]*\n(?:(?!\[)[^\n]*\n?)*/gm;
|
|
4509
5137
|
var codexMcpBlock = (dist) => `[mcp_servers.hindsight]
|
|
4510
5138
|
command = "node"
|
|
4511
|
-
args = [${JSON.stringify(
|
|
5139
|
+
args = [${JSON.stringify(join23(dist, "mcp-server.js"))}]
|
|
4512
5140
|
env = { HINDSIGHT_MCP_HARNESS = "codex" }`;
|
|
4513
5141
|
var codex = {
|
|
4514
5142
|
name: "codex",
|
|
4515
|
-
detect: (c) => onPath2("codex") ||
|
|
5143
|
+
detect: (c) => onPath2("codex") || existsSync13(join23(c.home, ".codex")),
|
|
4516
5144
|
install(c) {
|
|
4517
|
-
const hooksPath =
|
|
5145
|
+
const hooksPath = join23(c.home, ".codex", "hooks.json");
|
|
4518
5146
|
const cfg = readJson(hooksPath);
|
|
4519
5147
|
cfg.hooks = cfg.hooks ?? {};
|
|
4520
5148
|
mergeHarnessHooks(cfg.hooks, "codex", c.dist);
|
|
4521
5149
|
writeJson(hooksPath, cfg);
|
|
4522
5150
|
c.log?.(`codex: hooks merged into ${hooksPath}`);
|
|
4523
|
-
const tomlPath =
|
|
4524
|
-
const existing =
|
|
5151
|
+
const tomlPath = join23(c.home, ".codex", "config.toml");
|
|
5152
|
+
const existing = existsSync13(tomlPath) ? readFileSync16(tomlPath, "utf8") : "";
|
|
4525
5153
|
const toml = existing.replace(CODEX_MCP_BLOCK_RE, "");
|
|
4526
5154
|
const additions = [];
|
|
4527
5155
|
if (!/^\s*(codex_hooks|hooks)\s*=/m.test(toml)) {
|
|
@@ -4537,18 +5165,18 @@ var codex = {
|
|
|
4537
5165
|
const next = `${toml.replace(/\n*$/, "\n\n")}${additions.join("\n\n")}
|
|
4538
5166
|
`;
|
|
4539
5167
|
if (next !== existing) {
|
|
4540
|
-
if (
|
|
5168
|
+
if (existsSync13(tomlPath) && !existsSync13(`${tomlPath}.hindsight-backup`)) {
|
|
4541
5169
|
copyFileSync(tomlPath, `${tomlPath}.hindsight-backup`);
|
|
4542
5170
|
}
|
|
4543
|
-
|
|
4544
|
-
|
|
5171
|
+
mkdirSync7(dirname12(tomlPath), { recursive: true });
|
|
5172
|
+
writeFileSync5(tomlPath, next);
|
|
4545
5173
|
c.log?.(`codex: wrote ${additions.length} section(s) to ${tomlPath}`);
|
|
4546
5174
|
}
|
|
4547
5175
|
installSkill(c, "codex");
|
|
4548
5176
|
},
|
|
4549
5177
|
uninstall(c) {
|
|
4550
|
-
const hooksPath =
|
|
4551
|
-
if (
|
|
5178
|
+
const hooksPath = join23(c.home, ".codex", "hooks.json");
|
|
5179
|
+
if (existsSync13(hooksPath)) {
|
|
4552
5180
|
const cfg = readJson(hooksPath);
|
|
4553
5181
|
if (cfg.hooks) {
|
|
4554
5182
|
stripHarnessHooks(cfg.hooks, "codex");
|
|
@@ -4556,11 +5184,11 @@ var codex = {
|
|
|
4556
5184
|
}
|
|
4557
5185
|
}
|
|
4558
5186
|
uninstallSkill(c, "codex");
|
|
4559
|
-
const tomlPath =
|
|
4560
|
-
if (
|
|
4561
|
-
const toml =
|
|
5187
|
+
const tomlPath = join23(c.home, ".codex", "config.toml");
|
|
5188
|
+
if (existsSync13(tomlPath)) {
|
|
5189
|
+
const toml = readFileSync16(tomlPath, "utf8");
|
|
4562
5190
|
const cleaned = toml.replace(CODEX_MCP_BLOCK_RE, "");
|
|
4563
|
-
if (cleaned !== toml)
|
|
5191
|
+
if (cleaned !== toml) writeFileSync5(tomlPath, cleaned);
|
|
4564
5192
|
}
|
|
4565
5193
|
c.log?.(
|
|
4566
5194
|
"codex: hooks + MCP section + skill removed ([features] hooks flag left as-is \u2014 other hooks may use it)"
|
|
@@ -4574,7 +5202,7 @@ var antigravity = {
|
|
|
4574
5202
|
// can consume this integration.
|
|
4575
5203
|
detect: (c) => onPath2("agy"),
|
|
4576
5204
|
install(c) {
|
|
4577
|
-
const hooksPath =
|
|
5205
|
+
const hooksPath = join23(c.home, ".gemini", "config", "hooks.json");
|
|
4578
5206
|
const hooks = readJson(hooksPath);
|
|
4579
5207
|
for (const key of Object.keys(hooks)) {
|
|
4580
5208
|
if (key !== MARKER && key.includes(MARKER)) delete hooks[key];
|
|
@@ -4585,26 +5213,26 @@ var antigravity = {
|
|
|
4585
5213
|
setOrDelete(hooks, event, stripOurs(hooks[event]));
|
|
4586
5214
|
}
|
|
4587
5215
|
writeJson(hooksPath, hooks);
|
|
4588
|
-
const mcpPath =
|
|
5216
|
+
const mcpPath = join23(c.home, ".gemini", "config", "mcp_config.json");
|
|
4589
5217
|
const mcp = readJson(mcpPath);
|
|
4590
5218
|
mcp.mcpServers = {
|
|
4591
5219
|
...mcp.mcpServers ?? {},
|
|
4592
5220
|
hindsight: mcpServerEntry(c.dist, "antigravity-cli")
|
|
4593
5221
|
};
|
|
4594
5222
|
writeJson(mcpPath, mcp);
|
|
4595
|
-
const settingsPath =
|
|
5223
|
+
const settingsPath = join23(c.home, ".gemini", "antigravity-cli", "settings.json");
|
|
4596
5224
|
const settings = readJson(settingsPath);
|
|
4597
5225
|
if (!settings.statusLine) {
|
|
4598
5226
|
settings.statusLine = {
|
|
4599
5227
|
type: "command",
|
|
4600
|
-
command: `node "${
|
|
5228
|
+
command: `node "${join23(c.dist, "antigravity-statusline.js")}"`
|
|
4601
5229
|
};
|
|
4602
5230
|
writeJson(settingsPath, settings);
|
|
4603
5231
|
c.log?.(`antigravity-cli: Hindsight status line enabled in ${settingsPath}`);
|
|
4604
5232
|
} else if (JSON.stringify(settings.statusLine).includes(MARKER)) {
|
|
4605
5233
|
settings.statusLine = {
|
|
4606
5234
|
type: "command",
|
|
4607
|
-
command: `node "${
|
|
5235
|
+
command: `node "${join23(c.dist, "antigravity-statusline.js")}"`
|
|
4608
5236
|
};
|
|
4609
5237
|
writeJson(settingsPath, settings);
|
|
4610
5238
|
} else {
|
|
@@ -4616,8 +5244,8 @@ var antigravity = {
|
|
|
4616
5244
|
installSkill(c, "antigravity-cli");
|
|
4617
5245
|
},
|
|
4618
5246
|
uninstall(c) {
|
|
4619
|
-
const hooksPath =
|
|
4620
|
-
if (
|
|
5247
|
+
const hooksPath = join23(c.home, ".gemini", "config", "hooks.json");
|
|
5248
|
+
if (existsSync13(hooksPath)) {
|
|
4621
5249
|
const hooks = readJson(hooksPath);
|
|
4622
5250
|
if (hooks[MARKER]) {
|
|
4623
5251
|
stripHarnessHooks(hooks[MARKER], "antigravity-cli");
|
|
@@ -4628,16 +5256,16 @@ var antigravity = {
|
|
|
4628
5256
|
}
|
|
4629
5257
|
writeJson(hooksPath, hooks);
|
|
4630
5258
|
}
|
|
4631
|
-
const mcpPath =
|
|
4632
|
-
if (
|
|
5259
|
+
const mcpPath = join23(c.home, ".gemini", "config", "mcp_config.json");
|
|
5260
|
+
if (existsSync13(mcpPath)) {
|
|
4633
5261
|
const mcp = readJson(mcpPath);
|
|
4634
5262
|
if (mcp.mcpServers?.hindsight) {
|
|
4635
5263
|
delete mcp.mcpServers.hindsight;
|
|
4636
5264
|
writeJson(mcpPath, mcp);
|
|
4637
5265
|
}
|
|
4638
5266
|
}
|
|
4639
|
-
const settingsPath =
|
|
4640
|
-
if (
|
|
5267
|
+
const settingsPath = join23(c.home, ".gemini", "antigravity-cli", "settings.json");
|
|
5268
|
+
if (existsSync13(settingsPath)) {
|
|
4641
5269
|
const settings = readJson(settingsPath);
|
|
4642
5270
|
if (JSON.stringify(settings.statusLine ?? {}).includes(MARKER)) {
|
|
4643
5271
|
delete settings.statusLine;
|
|
@@ -4650,7 +5278,7 @@ var antigravity = {
|
|
|
4650
5278
|
};
|
|
4651
5279
|
function pathNodeHasSqlite() {
|
|
4652
5280
|
try {
|
|
4653
|
-
|
|
5281
|
+
execFileSync7("node", ["-e", "require('node:sqlite')"], { stdio: "pipe", timeout: 1e4 });
|
|
4654
5282
|
return true;
|
|
4655
5283
|
} catch {
|
|
4656
5284
|
return false;
|
|
@@ -4658,13 +5286,13 @@ function pathNodeHasSqlite() {
|
|
|
4658
5286
|
}
|
|
4659
5287
|
function pathNodeVersion() {
|
|
4660
5288
|
try {
|
|
4661
|
-
return
|
|
5289
|
+
return execFileSync7("node", ["-v"], { encoding: "utf8", stdio: "pipe" }).trim();
|
|
4662
5290
|
} catch {
|
|
4663
5291
|
return "not found";
|
|
4664
5292
|
}
|
|
4665
5293
|
}
|
|
4666
5294
|
function runtimeDir(home) {
|
|
4667
|
-
return
|
|
5295
|
+
return join23(home, ".hindsight", "coding-agents");
|
|
4668
5296
|
}
|
|
4669
5297
|
var ORIGIN_FILE = ".install-origin.json";
|
|
4670
5298
|
function stageRuntime(c) {
|
|
@@ -4677,25 +5305,25 @@ function stageRuntime(c) {
|
|
|
4677
5305
|
}
|
|
4678
5306
|
};
|
|
4679
5307
|
if (same(c.pkgRoot, target)) return c;
|
|
4680
|
-
if (!
|
|
5308
|
+
if (!existsSync13(join23(c.dist, "installer.js"))) return c;
|
|
4681
5309
|
try {
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
cpSync2(c.dist,
|
|
4685
|
-
const skill =
|
|
4686
|
-
if (
|
|
4687
|
-
const pkgJson =
|
|
4688
|
-
if (
|
|
5310
|
+
rmSync4(join23(target, "dist"), { recursive: true, force: true });
|
|
5311
|
+
mkdirSync7(target, { recursive: true });
|
|
5312
|
+
cpSync2(c.dist, join23(target, "dist"), { recursive: true });
|
|
5313
|
+
const skill = join23(c.pkgRoot, "skill");
|
|
5314
|
+
if (existsSync13(skill)) cpSync2(skill, join23(target, "skill"), { recursive: true });
|
|
5315
|
+
const pkgJson = join23(c.pkgRoot, "package.json");
|
|
5316
|
+
if (existsSync13(pkgJson)) copyFileSync(pkgJson, join23(target, "package.json"));
|
|
4689
5317
|
for (const resource of ["plugin.json", "hooks", "index.js"]) {
|
|
4690
|
-
const source =
|
|
4691
|
-
if (
|
|
5318
|
+
const source = join23(c.pkgRoot, resource);
|
|
5319
|
+
if (existsSync13(source)) cpSync2(source, join23(target, resource), { recursive: true });
|
|
4692
5320
|
}
|
|
4693
|
-
|
|
4694
|
-
|
|
5321
|
+
writeFileSync5(
|
|
5322
|
+
join23(target, ORIGIN_FILE),
|
|
4695
5323
|
JSON.stringify({ source: c.pkgRoot, stagedAt: (/* @__PURE__ */ new Date()).toISOString() })
|
|
4696
5324
|
);
|
|
4697
5325
|
c.log?.(`runtime staged at ${target}`);
|
|
4698
|
-
return { ...c, pkgRoot: target, dist:
|
|
5326
|
+
return { ...c, pkgRoot: target, dist: join23(target, "dist") };
|
|
4699
5327
|
} catch (error) {
|
|
4700
5328
|
c.log?.(`could not stage the runtime at ${target}: ${String(error)}`);
|
|
4701
5329
|
return c;
|
|
@@ -4717,6 +5345,7 @@ function flagValueArgs(args, names) {
|
|
|
4717
5345
|
return taken;
|
|
4718
5346
|
}
|
|
4719
5347
|
var CONFIG_RELATIVE = [".hindsight", "coding-agent.json"];
|
|
5348
|
+
var hindsightConfigPath = (c) => process.env.HINDSIGHT_CONFIG || join23(c.home, ...CONFIG_RELATIVE);
|
|
4720
5349
|
var SERVER_CHOICES = [
|
|
4721
5350
|
{ mode: "cloud", label: "Hindsight Cloud", hint: "hosted, needs an API token" },
|
|
4722
5351
|
{ mode: "self-hosted", label: "Self-hosted server", hint: "a Hindsight server you already run" },
|
|
@@ -4773,7 +5402,7 @@ function configureServer(c, args, installing) {
|
|
|
4773
5402
|
c.log?.(`unknown --server "${explicit}" \u2014 expected one of: ${SERVER_MODES.join(", ")}`);
|
|
4774
5403
|
return false;
|
|
4775
5404
|
}
|
|
4776
|
-
const configPath =
|
|
5405
|
+
const configPath = hindsightConfigPath(c);
|
|
4777
5406
|
const existing = readJson(configPath);
|
|
4778
5407
|
const alreadyConfigured = !!(existing.serverMode || existing.apiUrl);
|
|
4779
5408
|
let mode = explicit;
|
|
@@ -4869,7 +5498,7 @@ function reportDaemonPrereqs(c) {
|
|
|
4869
5498
|
}
|
|
4870
5499
|
var devin = {
|
|
4871
5500
|
name: "devin-cli",
|
|
4872
|
-
detect: (c) => onPath2("devin") ||
|
|
5501
|
+
detect: (c) => onPath2("devin") || existsSync13(join23(c.home, ".config", "devin")),
|
|
4873
5502
|
// Devin is the ONLY harness whose hooks never hand over a transcript: they carry a session id and
|
|
4874
5503
|
// nothing else, so retain can only work by reading the CLI's own sessions.db. That makes SQLite
|
|
4875
5504
|
// support a hard prerequisite here — and one worth checking now, because the alternative is an
|
|
@@ -4882,12 +5511,12 @@ var devin = {
|
|
|
4882
5511
|
Upgrade to Node 22.5 or newer (24 LTS recommended) and re-run this command.`;
|
|
4883
5512
|
},
|
|
4884
5513
|
install(c) {
|
|
4885
|
-
const configPath =
|
|
5514
|
+
const configPath = join23(c.home, ".config", "devin", "config.json");
|
|
4886
5515
|
const config = readJson(configPath);
|
|
4887
5516
|
config.hooks = config.hooks ?? {};
|
|
4888
5517
|
mergeHarnessHooks(config.hooks, "devin-cli", c.dist);
|
|
4889
5518
|
writeJson(configPath, config);
|
|
4890
|
-
const mcpPath =
|
|
5519
|
+
const mcpPath = join23(c.home, ".config", "devin", "mcp_config.json");
|
|
4891
5520
|
const mcp = readJson(mcpPath);
|
|
4892
5521
|
mcp.mcpServers = {
|
|
4893
5522
|
...mcp.mcpServers ?? {},
|
|
@@ -4897,8 +5526,8 @@ var devin = {
|
|
|
4897
5526
|
c.log?.(`devin-cli: hooks merged into ${configPath}, MCP into ${mcpPath}`);
|
|
4898
5527
|
},
|
|
4899
5528
|
uninstall(c) {
|
|
4900
|
-
const configPath =
|
|
4901
|
-
if (
|
|
5529
|
+
const configPath = join23(c.home, ".config", "devin", "config.json");
|
|
5530
|
+
if (existsSync13(configPath)) {
|
|
4902
5531
|
const config = readJson(configPath);
|
|
4903
5532
|
if (config.hooks) {
|
|
4904
5533
|
stripHarnessHooks(config.hooks, "devin-cli");
|
|
@@ -4906,8 +5535,8 @@ var devin = {
|
|
|
4906
5535
|
writeJson(configPath, config);
|
|
4907
5536
|
}
|
|
4908
5537
|
}
|
|
4909
|
-
const mcpPath =
|
|
4910
|
-
if (
|
|
5538
|
+
const mcpPath = join23(c.home, ".config", "devin", "mcp_config.json");
|
|
5539
|
+
if (existsSync13(mcpPath)) {
|
|
4911
5540
|
const mcp = readJson(mcpPath);
|
|
4912
5541
|
if (mcp.mcpServers?.hindsight) {
|
|
4913
5542
|
delete mcp.mcpServers.hindsight;
|
|
@@ -4919,26 +5548,27 @@ var devin = {
|
|
|
4919
5548
|
};
|
|
4920
5549
|
var cursor = {
|
|
4921
5550
|
name: "cursor-cli",
|
|
4922
|
-
detect: (c) => onPath2("cursor-agent") ||
|
|
5551
|
+
detect: (c) => onPath2("cursor-agent") || existsSync13(join23(c.home, ".cursor")),
|
|
4923
5552
|
install(c) {
|
|
4924
|
-
const hooksPath =
|
|
5553
|
+
const hooksPath = join23(c.home, ".cursor", "hooks.json");
|
|
4925
5554
|
const cfg = readJson(hooksPath);
|
|
5555
|
+
cfg.version ??= 1;
|
|
4926
5556
|
cfg.hooks = cfg.hooks ?? {};
|
|
4927
5557
|
mergeHarnessHooks(cfg.hooks, "cursor-cli", c.dist);
|
|
4928
5558
|
writeJson(hooksPath, cfg);
|
|
4929
|
-
const mcpPath =
|
|
5559
|
+
const mcpPath = join23(c.home, ".cursor", "mcp.json");
|
|
4930
5560
|
const mcp = readJson(mcpPath);
|
|
4931
5561
|
mcp.mcpServers = {
|
|
4932
5562
|
...mcp.mcpServers ?? {},
|
|
4933
|
-
hindsight: mcpServerEntry(c.dist, "cursor-cli")
|
|
5563
|
+
hindsight: mcpServerEntry(c.dist, "cursor-cli", ["${workspaceFolder}"])
|
|
4934
5564
|
};
|
|
4935
5565
|
writeJson(mcpPath, mcp);
|
|
4936
5566
|
c.log?.(`cursor-cli: hooks merged into ${hooksPath}, MCP into ${mcpPath}`);
|
|
4937
5567
|
installSkill(c, "cursor-cli");
|
|
4938
5568
|
},
|
|
4939
5569
|
uninstall(c) {
|
|
4940
|
-
const hooksPath =
|
|
4941
|
-
if (
|
|
5570
|
+
const hooksPath = join23(c.home, ".cursor", "hooks.json");
|
|
5571
|
+
if (existsSync13(hooksPath)) {
|
|
4942
5572
|
const cfg = readJson(hooksPath);
|
|
4943
5573
|
if (cfg.hooks) {
|
|
4944
5574
|
stripHarnessHooks(cfg.hooks, "cursor-cli");
|
|
@@ -4946,8 +5576,8 @@ var cursor = {
|
|
|
4946
5576
|
writeJson(hooksPath, cfg);
|
|
4947
5577
|
}
|
|
4948
5578
|
}
|
|
4949
|
-
const mcpPath =
|
|
4950
|
-
if (
|
|
5579
|
+
const mcpPath = join23(c.home, ".cursor", "mcp.json");
|
|
5580
|
+
if (existsSync13(mcpPath)) {
|
|
4951
5581
|
const mcp = readJson(mcpPath);
|
|
4952
5582
|
if (mcp.mcpServers?.hindsight) {
|
|
4953
5583
|
delete mcp.mcpServers.hindsight;
|
|
@@ -4960,13 +5590,13 @@ var cursor = {
|
|
|
4960
5590
|
};
|
|
4961
5591
|
var copilot = {
|
|
4962
5592
|
name: "copilot-cli",
|
|
4963
|
-
detect: (c) => onPath2("copilot") ||
|
|
5593
|
+
detect: (c) => onPath2("copilot") || existsSync13(join23(c.home, ".copilot")),
|
|
4964
5594
|
install(c) {
|
|
4965
|
-
const hooksPath =
|
|
5595
|
+
const hooksPath = join23(c.home, ".copilot", "hooks", "hindsight-coding-agents.json");
|
|
4966
5596
|
const hooks = {};
|
|
4967
5597
|
mergeHarnessHooks(hooks, "copilot-cli", c.dist);
|
|
4968
5598
|
writeJson(hooksPath, { version: 1, hooks });
|
|
4969
|
-
const mcpPath =
|
|
5599
|
+
const mcpPath = join23(c.home, ".copilot", "mcp-config.json");
|
|
4970
5600
|
const mcp = readJson(mcpPath);
|
|
4971
5601
|
mcp.mcpServers = {
|
|
4972
5602
|
...mcp.mcpServers ?? {},
|
|
@@ -4977,11 +5607,11 @@ var copilot = {
|
|
|
4977
5607
|
c.log?.(`copilot-cli: hooks installed at ${hooksPath}, MCP into ${mcpPath}`);
|
|
4978
5608
|
},
|
|
4979
5609
|
uninstall(c) {
|
|
4980
|
-
|
|
5610
|
+
rmSync4(join23(c.home, ".copilot", "hooks", "hindsight-coding-agents.json"), {
|
|
4981
5611
|
force: true
|
|
4982
5612
|
});
|
|
4983
|
-
const mcpPath =
|
|
4984
|
-
if (
|
|
5613
|
+
const mcpPath = join23(c.home, ".copilot", "mcp-config.json");
|
|
5614
|
+
if (existsSync13(mcpPath)) {
|
|
4985
5615
|
const mcp = readJson(mcpPath);
|
|
4986
5616
|
if (mcp.mcpServers?.hindsight) {
|
|
4987
5617
|
delete mcp.mcpServers.hindsight;
|
|
@@ -5045,39 +5675,21 @@ function stripUnmarkedGrokEntries(toml) {
|
|
|
5045
5675
|
if (!drop.some(Boolean)) return toml;
|
|
5046
5676
|
return sections.filter((_, i) => !drop[i]).map((s) => s.lines.join("\n")).join("\n").replace(/\n{3,}/g, "\n\n");
|
|
5047
5677
|
}
|
|
5678
|
+
var grokHooksPath = (c) => join23(c.home, ".grok", "hooks", "hindsight.json");
|
|
5048
5679
|
var grok = {
|
|
5049
5680
|
name: "grok-build",
|
|
5050
|
-
detect: (c) => onPath2("grok") ||
|
|
5681
|
+
detect: (c) => onPath2("grok") || existsSync13(join23(c.home, ".grok")),
|
|
5051
5682
|
install(c) {
|
|
5052
|
-
const path =
|
|
5053
|
-
const existing =
|
|
5683
|
+
const path = join23(c.home, ".grok", "config.toml");
|
|
5684
|
+
const existing = existsSync13(path) ? readFileSync16(path, "utf8") : "";
|
|
5054
5685
|
const stripped = existing.replace(GROK_BLOCK_RE, "\n");
|
|
5055
5686
|
const withoutOurs = hasUnmarkedGrokEntries(stripped) ? stripUnmarkedGrokEntries(stripped) : stripped;
|
|
5056
|
-
const command = (entry) => JSON.stringify(`node "${join20(c.dist, entry)}"`);
|
|
5057
5687
|
const tomlString = (value) => JSON.stringify(value);
|
|
5058
5688
|
const block = `
|
|
5059
5689
|
${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
5690
|
[mcp_servers.hindsight]
|
|
5079
5691
|
command = "node"
|
|
5080
|
-
args = [${tomlString(
|
|
5692
|
+
args = [${tomlString(join23(c.dist, "mcp-server.js"))}]
|
|
5081
5693
|
env = { HINDSIGHT_MCP_HARNESS = "grok-build" }
|
|
5082
5694
|
${GROK_MARKER_END}
|
|
5083
5695
|
`;
|
|
@@ -5088,41 +5700,111 @@ ${GROK_MARKER_END}
|
|
|
5088
5700
|
);
|
|
5089
5701
|
return false;
|
|
5090
5702
|
}
|
|
5091
|
-
if (
|
|
5703
|
+
if (existsSync13(path) && !existsSync13(`${path}.hindsight-backup`))
|
|
5092
5704
|
copyFileSync(path, `${path}.hindsight-backup`);
|
|
5093
|
-
|
|
5094
|
-
|
|
5705
|
+
mkdirSync7(dirname12(path), { recursive: true });
|
|
5706
|
+
writeFileSync5(path, next);
|
|
5707
|
+
const hooksPath = grokHooksPath(c);
|
|
5708
|
+
const file = readJson(hooksPath);
|
|
5709
|
+
const hooks = isPlainObject(file.hooks) ? file.hooks : {};
|
|
5710
|
+
mergeHarnessHooks(hooks, "grok-build", c.dist);
|
|
5711
|
+
writeJson(hooksPath, { ...file, hooks });
|
|
5095
5712
|
installSkill(c, "grok-build");
|
|
5096
|
-
c.log?.(`grok-build:
|
|
5713
|
+
c.log?.(`grok-build: hooks installed in ${hooksPath}, MCP in ${path}`);
|
|
5097
5714
|
},
|
|
5098
5715
|
uninstall(c) {
|
|
5099
|
-
const path =
|
|
5100
|
-
if (
|
|
5101
|
-
const existing =
|
|
5716
|
+
const path = join23(c.home, ".grok", "config.toml");
|
|
5717
|
+
if (existsSync13(path)) {
|
|
5718
|
+
const existing = readFileSync16(path, "utf8");
|
|
5102
5719
|
const stripped = existing.replace(GROK_BLOCK_RE, "\n");
|
|
5103
5720
|
const cleaned = hasUnmarkedGrokEntries(stripped) ? stripUnmarkedGrokEntries(stripped) : stripped;
|
|
5104
5721
|
const safe = parseGrokToml(cleaned) !== null || parseGrokToml(existing) === null;
|
|
5105
|
-
if (cleaned !== existing && safe)
|
|
5722
|
+
if (cleaned !== existing && safe) writeFileSync5(path, cleaned);
|
|
5723
|
+
}
|
|
5724
|
+
const hooksPath = grokHooksPath(c);
|
|
5725
|
+
if (existsSync13(hooksPath)) {
|
|
5726
|
+
const file = readJson(hooksPath);
|
|
5727
|
+
if (isPlainObject(file.hooks)) {
|
|
5728
|
+
stripHarnessHooks(file.hooks, "grok-build");
|
|
5729
|
+
if (!Object.keys(file.hooks).length) delete file.hooks;
|
|
5730
|
+
}
|
|
5731
|
+
if (Object.keys(file).length) writeJson(hooksPath, file);
|
|
5732
|
+
else rmSync4(hooksPath);
|
|
5106
5733
|
}
|
|
5107
5734
|
uninstallSkill(c, "grok-build");
|
|
5108
5735
|
c.log?.("grok-build: native hooks + MCP + skill removed");
|
|
5109
5736
|
}
|
|
5110
5737
|
};
|
|
5738
|
+
var KIMI_MARKER_START = "# HINDSIGHT_CODING_AGENTS_KIMI_START";
|
|
5739
|
+
var KIMI_MARKER_END = "# HINDSIGHT_CODING_AGENTS_KIMI_END";
|
|
5740
|
+
var KIMI_BLOCK_RE = new RegExp(`\\n?${KIMI_MARKER_START}[\\s\\S]*?${KIMI_MARKER_END}\\n?`);
|
|
5741
|
+
function kimiHome(c) {
|
|
5742
|
+
return process.env.KIMI_CODE_HOME || join23(c.home, ".kimi-code");
|
|
5743
|
+
}
|
|
5744
|
+
var kimi = {
|
|
5745
|
+
name: "kimi-code",
|
|
5746
|
+
detect: (c) => onPath2("kimi") || existsSync13(kimiHome(c)),
|
|
5747
|
+
install(c) {
|
|
5748
|
+
const path = join23(kimiHome(c), "config.toml");
|
|
5749
|
+
const existing = existsSync13(path) ? readFileSync16(path, "utf8") : "";
|
|
5750
|
+
const withoutOurs = existing.replace(KIMI_BLOCK_RE, "\n");
|
|
5751
|
+
const spec = HOOK_HARNESSES["kimi-code"];
|
|
5752
|
+
const entries = Object.values(spec.install).map(
|
|
5753
|
+
(h) => `[[hooks]]
|
|
5754
|
+
event = ${JSON.stringify(h.event)}
|
|
5755
|
+
command = ${JSON.stringify(`node "${join23(c.dist, h.entry)}"`)}
|
|
5756
|
+
timeout = ${h.timeout}
|
|
5757
|
+
`
|
|
5758
|
+
).join("\n");
|
|
5759
|
+
const block = `
|
|
5760
|
+
${KIMI_MARKER_START}
|
|
5761
|
+
${entries}${KIMI_MARKER_END}
|
|
5762
|
+
`;
|
|
5763
|
+
if (existsSync13(path) && !existsSync13(`${path}.hindsight-backup`))
|
|
5764
|
+
copyFileSync(path, `${path}.hindsight-backup`);
|
|
5765
|
+
mkdirSync7(dirname12(path), { recursive: true });
|
|
5766
|
+
writeFileSync5(path, `${withoutOurs.replace(/\n*$/, "\n")}${block}`);
|
|
5767
|
+
const mcpPath = join23(kimiHome(c), "mcp.json");
|
|
5768
|
+
const mcp = readJson(mcpPath);
|
|
5769
|
+
mcp.mcpServers = { ...mcp.mcpServers ?? {}, hindsight: mcpServerEntry(c.dist, "kimi-code") };
|
|
5770
|
+
writeJson(mcpPath, mcp);
|
|
5771
|
+
installSkill(c, "kimi-code");
|
|
5772
|
+
c.log?.(`kimi-code: native hooks installed in ${path}, MCP in ${mcpPath}`);
|
|
5773
|
+
},
|
|
5774
|
+
uninstall(c) {
|
|
5775
|
+
const path = join23(kimiHome(c), "config.toml");
|
|
5776
|
+
if (existsSync13(path)) {
|
|
5777
|
+
const existing = readFileSync16(path, "utf8");
|
|
5778
|
+
const cleaned = existing.replace(KIMI_BLOCK_RE, "\n");
|
|
5779
|
+
if (cleaned !== existing) writeFileSync5(path, cleaned);
|
|
5780
|
+
}
|
|
5781
|
+
const mcpPath = join23(kimiHome(c), "mcp.json");
|
|
5782
|
+
if (existsSync13(mcpPath)) {
|
|
5783
|
+
const mcp = readJson(mcpPath);
|
|
5784
|
+
if (mcp.mcpServers?.hindsight) {
|
|
5785
|
+
delete mcp.mcpServers.hindsight;
|
|
5786
|
+
writeJson(mcpPath, mcp);
|
|
5787
|
+
}
|
|
5788
|
+
}
|
|
5789
|
+
uninstallSkill(c, "kimi-code");
|
|
5790
|
+
c.log?.("kimi-code: native hooks + MCP + skill removed");
|
|
5791
|
+
}
|
|
5792
|
+
};
|
|
5111
5793
|
var CLINE_HOOK_MARKER = "HINDSIGHT_CODING_AGENTS_CLINE";
|
|
5112
5794
|
var CLINE_OLD_HOOK_EVENTS = ["TaskStart", "UserPromptSubmit", "TaskComplete"];
|
|
5113
5795
|
var CLINE_PLUGIN_NAME = "@vectorize-io/hindsight-coding-agents";
|
|
5114
5796
|
function removeLegacyClineHooks(c) {
|
|
5115
|
-
const hooksDir =
|
|
5797
|
+
const hooksDir = join23(c.home, "Documents", "Cline", "Hooks");
|
|
5116
5798
|
for (const event of CLINE_OLD_HOOK_EVENTS) {
|
|
5117
|
-
const path =
|
|
5118
|
-
if (
|
|
5119
|
-
|
|
5799
|
+
const path = join23(hooksDir, event);
|
|
5800
|
+
if (existsSync13(path) && readFileSync16(path, "utf8").includes(CLINE_HOOK_MARKER)) {
|
|
5801
|
+
rmSync4(path, { force: true });
|
|
5120
5802
|
}
|
|
5121
5803
|
}
|
|
5122
5804
|
}
|
|
5123
5805
|
var cline = {
|
|
5124
5806
|
name: "cline-cli",
|
|
5125
|
-
detect: (c) => onPath2("cline") ||
|
|
5807
|
+
detect: (c) => onPath2("cline") || existsSync13(join23(c.home, ".cline")),
|
|
5126
5808
|
install(c) {
|
|
5127
5809
|
removeLegacyClineHooks(c);
|
|
5128
5810
|
const installed = (c.clinePlugin ?? runClinePlugin)([
|
|
@@ -5131,7 +5813,7 @@ var cline = {
|
|
|
5131
5813
|
"--force",
|
|
5132
5814
|
c.pkgRoot
|
|
5133
5815
|
]);
|
|
5134
|
-
const mcpPath =
|
|
5816
|
+
const mcpPath = join23(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
|
|
5135
5817
|
const mcp = readJson(mcpPath);
|
|
5136
5818
|
mcp.mcpServers = {
|
|
5137
5819
|
...mcp.mcpServers ?? {},
|
|
@@ -5146,8 +5828,8 @@ var cline = {
|
|
|
5146
5828
|
uninstall(c) {
|
|
5147
5829
|
removeLegacyClineHooks(c);
|
|
5148
5830
|
(c.clinePlugin ?? runClinePlugin)(["plugin", "uninstall", CLINE_PLUGIN_NAME]);
|
|
5149
|
-
const mcpPath =
|
|
5150
|
-
if (
|
|
5831
|
+
const mcpPath = join23(c.home, ".cline", "data", "settings", "cline_mcp_settings.json");
|
|
5832
|
+
if (existsSync13(mcpPath)) {
|
|
5151
5833
|
const mcp = readJson(mcpPath);
|
|
5152
5834
|
if (mcp.mcpServers?.hindsight) {
|
|
5153
5835
|
delete mcp.mcpServers.hindsight;
|
|
@@ -5160,31 +5842,31 @@ var cline = {
|
|
|
5160
5842
|
};
|
|
5161
5843
|
var DCODE_MARKETPLACE = "hindsight-coding-agents";
|
|
5162
5844
|
var DCODE_PLUGIN_ID = "hindsight-coding-agents@hindsight-coding-agents";
|
|
5163
|
-
var DCODE_MARKETPLACE_RELATIVE_PATH =
|
|
5845
|
+
var DCODE_MARKETPLACE_RELATIVE_PATH = join23(".agents", "plugins", "marketplace.json");
|
|
5164
5846
|
var DCODE_FALLBACK_MARKETPLACE = "hindsight-coding-agents-marketplace.json";
|
|
5165
5847
|
function prepareDcodeMarketplace(c) {
|
|
5166
|
-
const root =
|
|
5167
|
-
const conventionalPath =
|
|
5848
|
+
const root = join23(c.home, ".hindsight");
|
|
5849
|
+
const conventionalPath = join23(root, DCODE_MARKETPLACE_RELATIVE_PATH);
|
|
5168
5850
|
let path = conventionalPath;
|
|
5169
5851
|
let registrationSource = root;
|
|
5170
5852
|
let marketplace = { plugins: [] };
|
|
5171
|
-
if (
|
|
5853
|
+
if (existsSync13(conventionalPath)) {
|
|
5172
5854
|
try {
|
|
5173
|
-
const parsed = JSON.parse(
|
|
5855
|
+
const parsed = JSON.parse(readFileSync16(conventionalPath, "utf8"));
|
|
5174
5856
|
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins)) {
|
|
5175
|
-
path =
|
|
5857
|
+
path = join23(root, DCODE_FALLBACK_MARKETPLACE);
|
|
5176
5858
|
} else if (typeof parsed.name === "string" && parsed.name !== DCODE_MARKETPLACE) {
|
|
5177
|
-
path =
|
|
5859
|
+
path = join23(root, DCODE_FALLBACK_MARKETPLACE);
|
|
5178
5860
|
} else {
|
|
5179
5861
|
marketplace = parsed;
|
|
5180
5862
|
}
|
|
5181
5863
|
} catch {
|
|
5182
|
-
path =
|
|
5864
|
+
path = join23(root, DCODE_FALLBACK_MARKETPLACE);
|
|
5183
5865
|
}
|
|
5184
5866
|
}
|
|
5185
|
-
if (path !== conventionalPath &&
|
|
5867
|
+
if (path !== conventionalPath && existsSync13(path)) {
|
|
5186
5868
|
try {
|
|
5187
|
-
const parsed = JSON.parse(
|
|
5869
|
+
const parsed = JSON.parse(readFileSync16(path, "utf8"));
|
|
5188
5870
|
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.plugins) || parsed.name !== DCODE_MARKETPLACE) {
|
|
5189
5871
|
c.log?.(`dcode: refusing to replace malformed marketplace file ${path}`);
|
|
5190
5872
|
return false;
|
|
@@ -5212,7 +5894,7 @@ function prepareDcodeMarketplace(c) {
|
|
|
5212
5894
|
}
|
|
5213
5895
|
var dcode = {
|
|
5214
5896
|
name: "dcode",
|
|
5215
|
-
detect: (c) => onPath2("dcode") ||
|
|
5897
|
+
detect: (c) => onPath2("dcode") || existsSync13(join23(c.home, ".deepagents")),
|
|
5216
5898
|
preflight: (c) => c.dcodePlugin || onPath2("dcode") ? void 0 : "the `dcode` CLI is not on PATH",
|
|
5217
5899
|
install(c) {
|
|
5218
5900
|
const plugin = c.dcodePlugin ?? runDcodePlugin;
|
|
@@ -5221,7 +5903,7 @@ var dcode = {
|
|
|
5221
5903
|
if (installed) {
|
|
5222
5904
|
c.log?.(`dcode: native Agent Plugin installed (${DCODE_PLUGIN_ID})`);
|
|
5223
5905
|
} else {
|
|
5224
|
-
const source = marketplacePath === false ?
|
|
5906
|
+
const source = marketplacePath === false ? join23(c.home, ".hindsight") : marketplacePath;
|
|
5225
5907
|
c.log?.(
|
|
5226
5908
|
`dcode: could not install the native plugin \u2014 run dcode plugin marketplace add "${source}" && dcode plugin install ${DCODE_PLUGIN_ID}`
|
|
5227
5909
|
);
|
|
@@ -5248,27 +5930,32 @@ var dcode = {
|
|
|
5248
5930
|
var DSH_MARKER_START = "# HINDSIGHT_CODING_AGENTS_DSH_START";
|
|
5249
5931
|
var DSH_MARKER_END = "# HINDSIGHT_CODING_AGENTS_DSH_END";
|
|
5250
5932
|
var DSH_BLOCK_RE = new RegExp(`\\n?${DSH_MARKER_START}[\\s\\S]*?${DSH_MARKER_END}\\n?`);
|
|
5933
|
+
var DSH_EMPTY_LIST = "[]";
|
|
5934
|
+
function dshUserPatches(existing) {
|
|
5935
|
+
const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
|
|
5936
|
+
return others === DSH_EMPTY_LIST ? "" : others;
|
|
5937
|
+
}
|
|
5251
5938
|
function dshHome(c) {
|
|
5252
|
-
return process.env.DSH_HOME ||
|
|
5939
|
+
return process.env.DSH_HOME || join23(c.home, ".dsh");
|
|
5253
5940
|
}
|
|
5254
5941
|
var dsh = {
|
|
5255
5942
|
name: "dsh",
|
|
5256
|
-
detect: (c) => onPath2("dsh") ||
|
|
5943
|
+
detect: (c) => onPath2("dsh") || existsSync13(dshHome(c)),
|
|
5257
5944
|
install(c) {
|
|
5258
|
-
const path =
|
|
5259
|
-
const existing =
|
|
5260
|
-
const others = existing
|
|
5261
|
-
const entry = pathToFileURL(
|
|
5945
|
+
const path = join23(dshHome(c), "cordis.patch.yml");
|
|
5946
|
+
const existing = existsSync13(path) ? readFileSync16(path, "utf8") : "";
|
|
5947
|
+
const others = dshUserPatches(existing);
|
|
5948
|
+
const entry = pathToFileURL(join23(c.dist, "dsh.js")).href;
|
|
5262
5949
|
const block = `${DSH_MARKER_START}
|
|
5263
5950
|
- insert:
|
|
5264
5951
|
- id: hindsight
|
|
5265
5952
|
name: ${JSON.stringify(entry)}
|
|
5266
5953
|
${DSH_MARKER_END}
|
|
5267
5954
|
`;
|
|
5268
|
-
if (
|
|
5955
|
+
if (existsSync13(path) && !existsSync13(`${path}.hindsight-backup`))
|
|
5269
5956
|
copyFileSync(path, `${path}.hindsight-backup`);
|
|
5270
|
-
|
|
5271
|
-
|
|
5957
|
+
mkdirSync7(dirname12(path), { recursive: true });
|
|
5958
|
+
writeFileSync5(path, others ? `${others}
|
|
5272
5959
|
|
|
5273
5960
|
${block}` : block);
|
|
5274
5961
|
installSkill(c, "dsh");
|
|
@@ -5277,12 +5964,14 @@ ${block}` : block);
|
|
|
5277
5964
|
);
|
|
5278
5965
|
},
|
|
5279
5966
|
uninstall(c) {
|
|
5280
|
-
const path =
|
|
5281
|
-
if (
|
|
5282
|
-
const existing =
|
|
5967
|
+
const path = join23(dshHome(c), "cordis.patch.yml");
|
|
5968
|
+
if (existsSync13(path)) {
|
|
5969
|
+
const existing = readFileSync16(path, "utf8");
|
|
5283
5970
|
const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
|
|
5284
|
-
if (others !== existing.trim())
|
|
5285
|
-
|
|
5971
|
+
if (others !== existing.trim())
|
|
5972
|
+
writeFileSync5(path, others ? `${others}
|
|
5973
|
+
` : `${DSH_EMPTY_LIST}
|
|
5974
|
+
`);
|
|
5286
5975
|
}
|
|
5287
5976
|
uninstallSkill(c, "dsh");
|
|
5288
5977
|
c.log?.("dsh: plugin entry + skill removed");
|
|
@@ -5290,9 +5979,9 @@ ${block}` : block);
|
|
|
5290
5979
|
};
|
|
5291
5980
|
var qwen = {
|
|
5292
5981
|
name: "qwen-code",
|
|
5293
|
-
detect: (c) => onPath2("qwen") ||
|
|
5982
|
+
detect: (c) => onPath2("qwen") || existsSync13(join23(c.home, ".qwen")),
|
|
5294
5983
|
install(c) {
|
|
5295
|
-
const path =
|
|
5984
|
+
const path = join23(c.home, ".qwen", "settings.json");
|
|
5296
5985
|
const settings = readJson(path);
|
|
5297
5986
|
settings.hooks = settings.hooks ?? {};
|
|
5298
5987
|
mergeHarnessHooks(settings.hooks, "qwen-code", c.dist);
|
|
@@ -5310,19 +5999,19 @@ var qwen = {
|
|
|
5310
5999
|
"HINDSIGHT_MCP_HARNESS=qwen-code",
|
|
5311
6000
|
"hindsight",
|
|
5312
6001
|
"node",
|
|
5313
|
-
|
|
6002
|
+
join23(c.dist, "mcp-server.js")
|
|
5314
6003
|
])) {
|
|
5315
6004
|
c.log?.("qwen-code: MCP server registered (qwen mcp add, user scope)");
|
|
5316
6005
|
} else {
|
|
5317
6006
|
c.log?.(
|
|
5318
6007
|
`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 "${
|
|
6008
|
+
qwen mcp add -s user -e HINDSIGHT_MCP_HARNESS=qwen-code hindsight node "${join23(c.dist, "mcp-server.js")}"`
|
|
5320
6009
|
);
|
|
5321
6010
|
}
|
|
5322
6011
|
},
|
|
5323
6012
|
uninstall(c) {
|
|
5324
|
-
const path =
|
|
5325
|
-
if (
|
|
6013
|
+
const path = join23(c.home, ".qwen", "settings.json");
|
|
6014
|
+
if (existsSync13(path)) {
|
|
5326
6015
|
const settings = readJson(path);
|
|
5327
6016
|
if (settings.hooks) {
|
|
5328
6017
|
stripHarnessHooks(settings.hooks, "qwen-code");
|
|
@@ -5338,7 +6027,7 @@ var qwen = {
|
|
|
5338
6027
|
};
|
|
5339
6028
|
function defaultQwenMcp(args) {
|
|
5340
6029
|
try {
|
|
5341
|
-
|
|
6030
|
+
execFileSync7("qwen", args, { stdio: "pipe" });
|
|
5342
6031
|
return true;
|
|
5343
6032
|
} catch {
|
|
5344
6033
|
return false;
|
|
@@ -5346,19 +6035,19 @@ function defaultQwenMcp(args) {
|
|
|
5346
6035
|
}
|
|
5347
6036
|
var factoryDroid = {
|
|
5348
6037
|
name: "factory-droid",
|
|
5349
|
-
detect: (c) => onPath2("droid") ||
|
|
6038
|
+
detect: (c) => onPath2("droid") || existsSync13(join23(c.home, ".factory")),
|
|
5350
6039
|
preflight(c) {
|
|
5351
|
-
const mcpPath =
|
|
6040
|
+
const mcpPath = join23(c.home, ".factory", "mcp.json");
|
|
5352
6041
|
const existing = readJson(mcpPath).mcpServers?.hindsight;
|
|
5353
6042
|
if (existing && !isOurMcpEntry(existing)) {
|
|
5354
6043
|
return `${mcpPath} already contains a user-managed MCP server named "hindsight". Rename or remove that entry, then re-run install.`;
|
|
5355
6044
|
}
|
|
5356
6045
|
},
|
|
5357
6046
|
install(c) {
|
|
5358
|
-
const hooksPath =
|
|
6047
|
+
const hooksPath = join23(c.home, ".factory", "hooks.json");
|
|
5359
6048
|
const hooks = readJson(hooksPath);
|
|
5360
|
-
if (!
|
|
5361
|
-
const fallback = readJson(
|
|
6049
|
+
if (!existsSync13(hooksPath)) {
|
|
6050
|
+
const fallback = readJson(join23(c.home, ".factory", "settings.json")).hooks;
|
|
5362
6051
|
if (fallback && typeof fallback === "object" && !Array.isArray(fallback)) {
|
|
5363
6052
|
Object.assign(hooks, fallback);
|
|
5364
6053
|
}
|
|
@@ -5367,7 +6056,7 @@ var factoryDroid = {
|
|
|
5367
6056
|
writeJson(hooksPath, hooks);
|
|
5368
6057
|
c.log?.(`factory-droid: hooks merged into ${hooksPath}`);
|
|
5369
6058
|
installSkill(c, "factory-droid");
|
|
5370
|
-
const mcpPath =
|
|
6059
|
+
const mcpPath = join23(c.home, ".factory", "mcp.json");
|
|
5371
6060
|
const mcp = readJson(mcpPath);
|
|
5372
6061
|
mcp.mcpServers = mcp.mcpServers ?? {};
|
|
5373
6062
|
mcp.mcpServers.hindsight = mcpServerEntry(c.dist, "factory-droid");
|
|
@@ -5375,20 +6064,20 @@ var factoryDroid = {
|
|
|
5375
6064
|
c.log?.(`factory-droid: MCP server registered in ${mcpPath}`);
|
|
5376
6065
|
},
|
|
5377
6066
|
uninstall(c) {
|
|
5378
|
-
const hooksPath =
|
|
5379
|
-
if (
|
|
6067
|
+
const hooksPath = join23(c.home, ".factory", "hooks.json");
|
|
6068
|
+
if (existsSync13(hooksPath)) {
|
|
5380
6069
|
const hooks = readJson(hooksPath);
|
|
5381
6070
|
stripHarnessHooks(hooks, "factory-droid");
|
|
5382
6071
|
if (Object.keys(hooks).length) writeJson(hooksPath, hooks);
|
|
5383
|
-
else
|
|
6072
|
+
else rmSync4(hooksPath);
|
|
5384
6073
|
}
|
|
5385
|
-
const mcpPath =
|
|
5386
|
-
if (
|
|
6074
|
+
const mcpPath = join23(c.home, ".factory", "mcp.json");
|
|
6075
|
+
if (existsSync13(mcpPath)) {
|
|
5387
6076
|
const mcp = readJson(mcpPath);
|
|
5388
6077
|
if (isOurMcpEntry(mcp.mcpServers?.hindsight)) {
|
|
5389
6078
|
delete mcp.mcpServers.hindsight;
|
|
5390
6079
|
if (Object.keys(mcp.mcpServers).length) writeJson(mcpPath, mcp);
|
|
5391
|
-
else
|
|
6080
|
+
else rmSync4(mcpPath);
|
|
5392
6081
|
}
|
|
5393
6082
|
}
|
|
5394
6083
|
uninstallSkill(c, "factory-droid");
|
|
@@ -5397,7 +6086,7 @@ var factoryDroid = {
|
|
|
5397
6086
|
};
|
|
5398
6087
|
var zcode = {
|
|
5399
6088
|
name: "zcode",
|
|
5400
|
-
detect: (c) => onPath2("zcode") ||
|
|
6089
|
+
detect: (c) => onPath2("zcode") || existsSync13(join23(c.home, ".zcode")),
|
|
5401
6090
|
preflight(c) {
|
|
5402
6091
|
const configPath = zcodeConfigPath(c);
|
|
5403
6092
|
const existing = readJson(configPath).mcp?.servers?.hindsight;
|
|
@@ -5422,7 +6111,7 @@ var zcode = {
|
|
|
5422
6111
|
},
|
|
5423
6112
|
uninstall(c) {
|
|
5424
6113
|
const configPath = zcodeConfigPath(c);
|
|
5425
|
-
if (
|
|
6114
|
+
if (existsSync13(configPath)) {
|
|
5426
6115
|
const config = readJson(configPath);
|
|
5427
6116
|
if (isOurMcpEntry(config.mcp?.servers?.hindsight)) {
|
|
5428
6117
|
delete config.mcp.servers.hindsight;
|
|
@@ -5439,6 +6128,159 @@ var zcode = {
|
|
|
5439
6128
|
c.log?.(`zcode: hooks + MCP registration + skill removed`);
|
|
5440
6129
|
}
|
|
5441
6130
|
};
|
|
6131
|
+
var traecodeMcpPath = (c) => join23(traecodeUserDataDir(c.home), "User", "mcp.json");
|
|
6132
|
+
function removeTraecodeUserMcpEntry(c) {
|
|
6133
|
+
try {
|
|
6134
|
+
const mcpPath = traecodeMcpPath(c);
|
|
6135
|
+
if (!existsSync13(mcpPath)) return false;
|
|
6136
|
+
const mcp = readJson(mcpPath);
|
|
6137
|
+
if (!isOurMcpEntry(mcp.mcpServers?.hindsight)) return false;
|
|
6138
|
+
delete mcp.mcpServers.hindsight;
|
|
6139
|
+
if (Object.keys(mcp.mcpServers).length) writeJson(mcpPath, mcp);
|
|
6140
|
+
else rmSync4(mcpPath);
|
|
6141
|
+
return true;
|
|
6142
|
+
} catch {
|
|
6143
|
+
return false;
|
|
6144
|
+
}
|
|
6145
|
+
}
|
|
6146
|
+
function ensureTraecodeWorkspaceMcpGate(c) {
|
|
6147
|
+
const settingsPath = traecodeUserSettingsPath(c.home);
|
|
6148
|
+
if (workspaceMcpGateState(settingsPath) === "on") return;
|
|
6149
|
+
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";
|
|
6150
|
+
const skipNote = ' Skipped. Enable later in Trae settings (search "enableWorkspaceMcp") or re-run with\n --enable-workspace-mcp.';
|
|
6151
|
+
if (!(c.args ?? []).includes("--enable-workspace-mcp")) {
|
|
6152
|
+
if (c.interactive !== true) {
|
|
6153
|
+
c.log?.(`${ask} ${skipNote}`);
|
|
6154
|
+
return;
|
|
6155
|
+
}
|
|
6156
|
+
const answer = readLineSync(c, `${ask} Enable workspace MCP? [Y/n]: `).trim().toLowerCase();
|
|
6157
|
+
if (answer === "n" || answer === "no") {
|
|
6158
|
+
c.log?.(skipNote);
|
|
6159
|
+
return;
|
|
6160
|
+
}
|
|
6161
|
+
}
|
|
6162
|
+
if (enableWorkspaceMcpSetting(settingsPath)) {
|
|
6163
|
+
markWorkspaceMcpEnabled({ stateFile: gateStateFileFor(c.dist) });
|
|
6164
|
+
c.log?.(
|
|
6165
|
+
`traecode: workspace MCP enabled in ${settingsPath} \u2014 restart Trae windows to pick it up`
|
|
6166
|
+
);
|
|
6167
|
+
} else {
|
|
6168
|
+
c.log?.(
|
|
6169
|
+
`traecode: could not update ${settingsPath} (comments or unreadable JSON) \u2014 set
|
|
6170
|
+
"trae.mcp.enableWorkspaceMcp": true in Trae settings instead.`
|
|
6171
|
+
);
|
|
6172
|
+
}
|
|
6173
|
+
}
|
|
6174
|
+
var traecode = {
|
|
6175
|
+
name: "traecode",
|
|
6176
|
+
detect: (c) => existsSync13(join23(c.home, traecodeDotDirName(c.home))) || onPath2("trae"),
|
|
6177
|
+
install(c) {
|
|
6178
|
+
const hooksPath = join23(c.home, traecodeDotDirName(c.home), "hooks.json");
|
|
6179
|
+
const doc = readJson(hooksPath);
|
|
6180
|
+
doc.version = doc.version ?? 1;
|
|
6181
|
+
const hooks = doc.hooks = doc.hooks ?? {};
|
|
6182
|
+
mergeHarnessHooks(hooks, "traecode", c.dist);
|
|
6183
|
+
writeJson(hooksPath, doc);
|
|
6184
|
+
c.log?.(`traecode: hooks merged into ${hooksPath}`);
|
|
6185
|
+
installSkill(c, "traecode");
|
|
6186
|
+
if (removeTraecodeUserMcpEntry(c)) {
|
|
6187
|
+
c.log?.(
|
|
6188
|
+
`traecode: stale user-level MCP entry removed from ${traecodeMcpPath(c)} \u2014 per-repo
|
|
6189
|
+
.trae/mcp.json files register the server instead`
|
|
6190
|
+
);
|
|
6191
|
+
}
|
|
6192
|
+
const sandboxPath = join23(c.home, traecodeDotDirName(c.home), "sandbox.json");
|
|
6193
|
+
const sandbox = readJson(sandboxPath);
|
|
6194
|
+
const fsRules = sandbox.filesystem = sandbox.filesystem ?? {};
|
|
6195
|
+
const readWrite = fsRules.readWrite = fsRules.readWrite ?? [];
|
|
6196
|
+
const needed = [join23(c.home, ".hindsight"), traecodeWorkspaceStorageDir(c.home)];
|
|
6197
|
+
let sandboxChanged = false;
|
|
6198
|
+
for (const dir of needed) {
|
|
6199
|
+
if (!readWrite.includes(dir)) {
|
|
6200
|
+
readWrite.push(dir);
|
|
6201
|
+
sandboxChanged = true;
|
|
6202
|
+
}
|
|
6203
|
+
}
|
|
6204
|
+
if (sandboxChanged) {
|
|
6205
|
+
writeJson(sandboxPath, sandbox);
|
|
6206
|
+
c.log?.(`traecode: sandbox readWrite rules added (${needed.join(", ")})`);
|
|
6207
|
+
}
|
|
6208
|
+
const config = readJson(hindsightConfigPath(c));
|
|
6209
|
+
const repos = Object.keys(config.mapPathToBank ?? {}).sort();
|
|
6210
|
+
if (repos.length) {
|
|
6211
|
+
const written = [];
|
|
6212
|
+
const current2 = [];
|
|
6213
|
+
const skipped = [];
|
|
6214
|
+
let seeded = 0;
|
|
6215
|
+
for (const repo of repos) {
|
|
6216
|
+
if (!existsSync13(repo)) {
|
|
6217
|
+
skipped.push(repo);
|
|
6218
|
+
continue;
|
|
6219
|
+
}
|
|
6220
|
+
const outcome = registerTraecodeWorkspaceMcp(repo, { home: c.home, dist: c.dist });
|
|
6221
|
+
if (outcome === "registered") written.push(repo);
|
|
6222
|
+
else if (outcome === "current") current2.push(repo);
|
|
6223
|
+
else skipped.push(repo);
|
|
6224
|
+
if (ensureWorkspaceMcpEnabled(repo, { home: c.home }) !== "failed") seeded++;
|
|
6225
|
+
}
|
|
6226
|
+
c.log?.(
|
|
6227
|
+
`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}`
|
|
6228
|
+
);
|
|
6229
|
+
if (written.length) c.log?.(` registered: ${written.join(", ")}`);
|
|
6230
|
+
if (skipped.length) {
|
|
6231
|
+
c.log?.(
|
|
6232
|
+
` skipped (missing repo, no dist build, or a foreign hindsight entry): ` + skipped.join(", ")
|
|
6233
|
+
);
|
|
6234
|
+
}
|
|
6235
|
+
if (written.length) {
|
|
6236
|
+
c.log?.(
|
|
6237
|
+
" 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"
|
|
6238
|
+
);
|
|
6239
|
+
}
|
|
6240
|
+
}
|
|
6241
|
+
ensureTraecodeWorkspaceMcpGate(c);
|
|
6242
|
+
},
|
|
6243
|
+
uninstall(c) {
|
|
6244
|
+
const hooksPath = join23(c.home, traecodeDotDirName(c.home), "hooks.json");
|
|
6245
|
+
if (existsSync13(hooksPath)) {
|
|
6246
|
+
const doc = readJson(hooksPath);
|
|
6247
|
+
if (doc.hooks) {
|
|
6248
|
+
stripHarnessHooks(doc.hooks, "traecode");
|
|
6249
|
+
if (!Object.keys(doc.hooks).length) delete doc.hooks;
|
|
6250
|
+
}
|
|
6251
|
+
if (Object.keys(doc).length > 1) writeJson(hooksPath, doc);
|
|
6252
|
+
else rmSync4(hooksPath);
|
|
6253
|
+
}
|
|
6254
|
+
if (removeTraecodeUserMcpEntry(c)) {
|
|
6255
|
+
c.log?.(`traecode: MCP entry removed from ${traecodeMcpPath(c)}`);
|
|
6256
|
+
}
|
|
6257
|
+
const config = readJson(hindsightConfigPath(c));
|
|
6258
|
+
const repoEntries = Object.keys(config.mapPathToBank ?? {}).sort();
|
|
6259
|
+
const cleaned = repoEntries.filter(
|
|
6260
|
+
(repo) => removeTraecodeWorkspaceMcpEntry(repo, { home: c.home })
|
|
6261
|
+
);
|
|
6262
|
+
if (cleaned.length) {
|
|
6263
|
+
c.log?.(`traecode: per-repo MCP registration removed from:
|
|
6264
|
+
${cleaned.join("\n ")}`);
|
|
6265
|
+
}
|
|
6266
|
+
const sandboxPath = join23(c.home, traecodeDotDirName(c.home), "sandbox.json");
|
|
6267
|
+
if (existsSync13(sandboxPath)) {
|
|
6268
|
+
const sandbox = readJson(sandboxPath);
|
|
6269
|
+
const readWrite = sandbox.filesystem?.readWrite;
|
|
6270
|
+
if (Array.isArray(readWrite)) {
|
|
6271
|
+
const ours = [join23(c.home, ".hindsight"), traecodeWorkspaceStorageDir(c.home)];
|
|
6272
|
+
const filtered = readWrite.filter((p) => !ours.includes(p));
|
|
6273
|
+
if (filtered.length !== readWrite.length) {
|
|
6274
|
+
sandbox.filesystem.readWrite = filtered;
|
|
6275
|
+
writeJson(sandboxPath, sandbox);
|
|
6276
|
+
}
|
|
6277
|
+
}
|
|
6278
|
+
}
|
|
6279
|
+
removeWorkspaceMcpEnabledKeys(c.home);
|
|
6280
|
+
uninstallSkill(c, "traecode");
|
|
6281
|
+
c.log?.(`traecode: hooks + MCP registration + skill removed`);
|
|
6282
|
+
}
|
|
6283
|
+
};
|
|
5442
6284
|
var INSTALLERS = [
|
|
5443
6285
|
opencode,
|
|
5444
6286
|
opencode2,
|
|
@@ -5453,11 +6295,13 @@ var INSTALLERS = [
|
|
|
5453
6295
|
copilot,
|
|
5454
6296
|
grok,
|
|
5455
6297
|
qwen,
|
|
6298
|
+
kimi,
|
|
5456
6299
|
cline,
|
|
5457
6300
|
dcode,
|
|
5458
6301
|
dsh,
|
|
5459
6302
|
factoryDroid,
|
|
5460
|
-
zcode
|
|
6303
|
+
zcode,
|
|
6304
|
+
traecode
|
|
5461
6305
|
];
|
|
5462
6306
|
var HARNESS_ALIASES = { agy: "antigravity-cli" };
|
|
5463
6307
|
function importConversations(harness, ctx) {
|
|
@@ -5477,23 +6321,24 @@ function importConversations(harness, ctx) {
|
|
|
5477
6321
|
return;
|
|
5478
6322
|
}
|
|
5479
6323
|
const turns = found.sessions.reduce((n, s) => n + s.turns.length, 0);
|
|
5480
|
-
const file =
|
|
5481
|
-
|
|
6324
|
+
const file = join23(mkdtempSync2(join23(tmpdir5(), "hindsight-import-")), "conversations.json");
|
|
6325
|
+
writeFileSync5(file, JSON.stringify(found.sessions));
|
|
5482
6326
|
ctx.log?.(
|
|
5483
6327
|
`${harness}: importing ${found.sessions.length} past sessions (${turns} turns) from ${repo} \u2014 this runs extraction and may take a while`
|
|
5484
6328
|
);
|
|
5485
6329
|
try {
|
|
5486
|
-
|
|
6330
|
+
execFileSync7("node", [join23(ctx.dist, "deepen.js"), "--repo", repo, "--conversations", file], {
|
|
5487
6331
|
stdio: "inherit"
|
|
5488
6332
|
});
|
|
5489
6333
|
} catch {
|
|
5490
6334
|
ctx.log?.(`${harness}: conversation import did not finish \u2014 re-run it any time with:`);
|
|
5491
|
-
ctx.log?.(` node "${
|
|
6335
|
+
ctx.log?.(` node "${join23(ctx.dist, "deepen.js")}" --repo "${repo}" --conversations "${file}"`);
|
|
5492
6336
|
}
|
|
5493
6337
|
}
|
|
5494
6338
|
function run(argv, ctxIn) {
|
|
5495
6339
|
let ctx = ctxIn;
|
|
5496
6340
|
const [command, ...rawArgs] = argv;
|
|
6341
|
+
ctx = { ...ctx, args: rawArgs };
|
|
5497
6342
|
const importHistory = rawArgs.includes("--import-conversations");
|
|
5498
6343
|
const valueArgs = flagValueArgs(rawArgs, ["server", "api-url", "api-token"]);
|
|
5499
6344
|
const names = rawArgs.filter((a) => !a.startsWith("--") && !valueArgs.has(a));
|
|
@@ -5514,7 +6359,7 @@ function run(argv, ctxIn) {
|
|
|
5514
6359
|
hindsight-coding-agents update
|
|
5515
6360
|
hindsight-coding-agents stats
|
|
5516
6361
|
[--server cloud|self-hosted|daemon] [--api-url <url>] [--api-token <token>]
|
|
5517
|
-
[--import-conversations]
|
|
6362
|
+
[--import-conversations] [--enable-workspace-mcp]
|
|
5518
6363
|
all every agent detected on this machine
|
|
5519
6364
|
harness ${INSTALLERS.map((i) => i.name).join(", ")} (agy aliases antigravity-cli)
|
|
5520
6365
|
update re-stage the runtime only, leaving every host config untouched
|
|
@@ -5592,16 +6437,16 @@ var mainPath = process.argv[1] ? (() => {
|
|
|
5592
6437
|
})() : void 0;
|
|
5593
6438
|
var isMain = mainPath && import.meta.url === pathToFileURL(mainPath).href;
|
|
5594
6439
|
if (isMain || mainPath?.endsWith("installer.js")) {
|
|
5595
|
-
const dist =
|
|
5596
|
-
const pkgRoot =
|
|
6440
|
+
const dist = dirname12(fileURLToPath7(import.meta.url));
|
|
6441
|
+
const pkgRoot = dirname12(dist);
|
|
5597
6442
|
let version;
|
|
5598
6443
|
try {
|
|
5599
|
-
version = JSON.parse(
|
|
6444
|
+
version = JSON.parse(readFileSync16(join23(pkgRoot, "package.json"), "utf8")).version;
|
|
5600
6445
|
} catch {
|
|
5601
6446
|
version = void 0;
|
|
5602
6447
|
}
|
|
5603
6448
|
const ui = createInstallerUi({
|
|
5604
|
-
home:
|
|
6449
|
+
home: homedir13(),
|
|
5605
6450
|
command: process.argv[2],
|
|
5606
6451
|
version,
|
|
5607
6452
|
harnessNames: INSTALLERS.map((i) => i.name),
|
|
@@ -5611,7 +6456,7 @@ if (isMain || mainPath?.endsWith("installer.js")) {
|
|
|
5611
6456
|
});
|
|
5612
6457
|
ui.intro();
|
|
5613
6458
|
const code = run(process.argv.slice(2), {
|
|
5614
|
-
home:
|
|
6459
|
+
home: homedir13(),
|
|
5615
6460
|
pkgRoot,
|
|
5616
6461
|
dist,
|
|
5617
6462
|
// Only a real terminal gets prompted; piped/CI installs take the documented default.
|