@vectorize-io/hindsight-coding-agents 0.5.3 → 0.5.4
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/dist/antigravity-hook.js +67 -33
- package/dist/antigravity-stop-hook.js +61 -31
- package/dist/claude-hook.js +67 -33
- package/dist/claude-sessionstart-hook.js +239 -71
- package/dist/claude-stop-hook.js +61 -31
- package/dist/cline.js +213 -50
- package/dist/codex-hook.js +67 -33
- package/dist/codex-sessionstart-hook.js +239 -71
- package/dist/codex-stop-hook.js +61 -31
- package/dist/copilot-hook.js +67 -33
- package/dist/copilot-sessionstart-hook.js +239 -71
- package/dist/copilot-stop-hook.js +61 -31
- package/dist/cursor-hook.js +67 -33
- package/dist/cursor-sessionstart-hook.js +239 -71
- package/dist/cursor-stop-hook.js +61 -31
- package/dist/dcode-hook.js +67 -33
- package/dist/dcode-sessionstart-hook.js +239 -71
- package/dist/dcode-stop-hook.js +61 -31
- package/dist/deepen.js +40 -13
- package/dist/devin-hook.js +67 -33
- package/dist/devin-sessionstart-hook.js +239 -71
- package/dist/devin-stop-hook.js +61 -31
- package/dist/droid-hook.js +67 -33
- package/dist/droid-sessionstart-hook.js +239 -71
- package/dist/droid-stop-hook.js +61 -31
- package/dist/dsh.js +215 -52
- package/dist/grok-hook.js +67 -33
- package/dist/grok-sessionstart-hook.js +239 -71
- package/dist/grok-stop-hook.js +61 -31
- package/dist/index.js +215 -52
- package/dist/installer.js +1030 -268
- package/dist/kilo.js +215 -52
- package/dist/mcp-server.js +33 -6
- package/dist/opencode2.js +215 -52
- package/dist/pi.js +214 -51
- package/dist/prime-agent.js +214 -51
- package/dist/qwen-hook.js +67 -33
- package/dist/qwen-sessionstart-hook.js +239 -71
- package/dist/qwen-stop-hook.js +61 -31
- package/dist/status.js +31 -4
- package/dist/survey-supervisor.js +81 -0
- package/dist/zcode-hook.js +67 -33
- package/dist/zcode-sessionstart-hook.js +239 -71
- package/dist/zcode-stop-hook.js +61 -31
- package/package.json +2 -1
- package/plugin.json +1 -1
|
@@ -954,9 +954,16 @@ var HindsightClient = class {
|
|
|
954
954
|
body: JSON.stringify({ query, budget: opts.budget ?? "high" }),
|
|
955
955
|
signal: ctrl.signal
|
|
956
956
|
});
|
|
957
|
-
if (!resp.ok)
|
|
957
|
+
if (!resp.ok)
|
|
958
|
+
throw new Error(
|
|
959
|
+
`reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`
|
|
960
|
+
);
|
|
958
961
|
const data = await resp.json();
|
|
959
962
|
return (data.text || "").trim();
|
|
963
|
+
} catch (e) {
|
|
964
|
+
if (ctrl.signal.aborted)
|
|
965
|
+
throw new Error(`reflect timed out after ${opts.timeoutMs}ms`, { cause: e });
|
|
966
|
+
throw e;
|
|
960
967
|
} finally {
|
|
961
968
|
clearTimeout(timer);
|
|
962
969
|
}
|
|
@@ -1858,7 +1865,7 @@ function* streamLines(path, start) {
|
|
|
1858
1865
|
}
|
|
1859
1866
|
|
|
1860
1867
|
// src/core/session-start.ts
|
|
1861
|
-
import { readFileSync as
|
|
1868
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
1862
1869
|
|
|
1863
1870
|
// src/core/git.ts
|
|
1864
1871
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
@@ -1900,11 +1907,95 @@ function hasGitHistory(dir) {
|
|
|
1900
1907
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
1901
1908
|
|
|
1902
1909
|
// src/core/survey.ts
|
|
1903
|
-
import { spawn as
|
|
1910
|
+
import { spawn as realSpawn4 } from "child_process";
|
|
1911
|
+
import { createHash as createHash4 } from "crypto";
|
|
1904
1912
|
import { existsSync as existsSync3 } from "fs";
|
|
1905
|
-
import { homedir as homedir3 } from "os";
|
|
1906
|
-
import { dirname as dirname8, join as
|
|
1913
|
+
import { homedir as homedir3, tmpdir as tmpdir4 } from "os";
|
|
1914
|
+
import { dirname as dirname8, join as join11 } from "path";
|
|
1907
1915
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1916
|
+
|
|
1917
|
+
// src/core/host-client.ts
|
|
1918
|
+
function resolveHostConfig(harness, directory) {
|
|
1919
|
+
const cfg0 = loadConfig({ harness });
|
|
1920
|
+
if (cfg0.disabled) return { cfg: cfg0, bankId: "" };
|
|
1921
|
+
const bankId = deriveBankIdOrSkip(cfg0, directory, harness);
|
|
1922
|
+
if (bankId === null) return { cfg: { ...cfg0, disabled: true }, bankId: "" };
|
|
1923
|
+
return applyBankConfig(cfg0, bankId, directory);
|
|
1924
|
+
}
|
|
1925
|
+
|
|
1926
|
+
// src/core/survey-lease.ts
|
|
1927
|
+
import { spawn as realSpawn3 } from "child_process";
|
|
1928
|
+
import { randomUUID } from "crypto";
|
|
1929
|
+
import {
|
|
1930
|
+
mkdirSync as mkdirSync4,
|
|
1931
|
+
mkdtempSync,
|
|
1932
|
+
readdirSync,
|
|
1933
|
+
renameSync as renameSync2,
|
|
1934
|
+
rmdirSync,
|
|
1935
|
+
rmSync as rmSync2,
|
|
1936
|
+
statSync as statSync3,
|
|
1937
|
+
unlinkSync,
|
|
1938
|
+
utimesSync,
|
|
1939
|
+
writeFileSync as writeFileSync2
|
|
1940
|
+
} from "fs";
|
|
1941
|
+
import { join as join10 } from "path";
|
|
1942
|
+
var LEASE_STALE_MS = 3e4;
|
|
1943
|
+
var SURVEY_SPEC_ENV = "HINDSIGHT_SURVEY_SPEC";
|
|
1944
|
+
function tryRename(from, to) {
|
|
1945
|
+
try {
|
|
1946
|
+
renameSync2(from, to);
|
|
1947
|
+
return true;
|
|
1948
|
+
} catch {
|
|
1949
|
+
return false;
|
|
1950
|
+
}
|
|
1951
|
+
}
|
|
1952
|
+
function releaseLease(lease) {
|
|
1953
|
+
try {
|
|
1954
|
+
unlinkSync(join10(lease.directory, lease.owner));
|
|
1955
|
+
} catch {
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
try {
|
|
1959
|
+
rmdirSync(lease.directory);
|
|
1960
|
+
} catch {
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
function reclaimIfStale(directory, staleMs) {
|
|
1964
|
+
const owners = readdirSync(directory);
|
|
1965
|
+
if (owners.length === 0) {
|
|
1966
|
+
try {
|
|
1967
|
+
rmdirSync(directory);
|
|
1968
|
+
} catch {
|
|
1969
|
+
}
|
|
1970
|
+
return true;
|
|
1971
|
+
}
|
|
1972
|
+
if (owners.length !== 1) return false;
|
|
1973
|
+
const age = Date.now() - statSync3(join10(directory, owners[0])).mtimeMs;
|
|
1974
|
+
if (Math.abs(age) <= staleMs) return false;
|
|
1975
|
+
releaseLease({ directory, owner: owners[0] });
|
|
1976
|
+
return true;
|
|
1977
|
+
}
|
|
1978
|
+
function acquireLease(root, key, staleMs = LEASE_STALE_MS) {
|
|
1979
|
+
let staging;
|
|
1980
|
+
try {
|
|
1981
|
+
mkdirSync4(root, { recursive: true, mode: 448 });
|
|
1982
|
+
staging = mkdtempSync(join10(root, "claim-"));
|
|
1983
|
+
const owner = randomUUID();
|
|
1984
|
+
writeFileSync2(join10(staging, owner), "", { flag: "wx", mode: 384 });
|
|
1985
|
+
const directory = join10(root, `survey-${key}.lock`);
|
|
1986
|
+
if (!tryRename(staging, directory)) {
|
|
1987
|
+
if (!reclaimIfStale(directory, staleMs)) return void 0;
|
|
1988
|
+
if (!tryRename(staging, directory)) return void 0;
|
|
1989
|
+
}
|
|
1990
|
+
return { directory, owner };
|
|
1991
|
+
} catch {
|
|
1992
|
+
return void 0;
|
|
1993
|
+
} finally {
|
|
1994
|
+
if (staging) rmSync2(staging, { recursive: true, force: true });
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
// src/core/survey.ts
|
|
1908
1999
|
var SURVEY_DOC_IDS = [
|
|
1909
2000
|
"repository-component-map",
|
|
1910
2001
|
"repository-core-concepts",
|
|
@@ -1914,7 +2005,7 @@ var SURVEY_DOC_IDS = [
|
|
|
1914
2005
|
function resolveClaudeBin(explicit) {
|
|
1915
2006
|
if (explicit) return explicit;
|
|
1916
2007
|
if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
|
|
1917
|
-
const nativeInstallPath =
|
|
2008
|
+
const nativeInstallPath = join11(homedir3(), ".claude", "local", "claude");
|
|
1918
2009
|
try {
|
|
1919
2010
|
if (existsSync3(nativeInstallPath)) return nativeInstallPath;
|
|
1920
2011
|
} catch {
|
|
@@ -2028,11 +2119,11 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
2028
2119
|
}
|
|
2029
2120
|
}
|
|
2030
2121
|
}
|
|
2031
|
-
function startCodebaseSurvey(repoDir, opts = {}) {
|
|
2122
|
+
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
2032
2123
|
try {
|
|
2033
|
-
const spawnFn = opts.spawn ??
|
|
2124
|
+
const spawnFn = opts.spawn ?? realSpawn4;
|
|
2034
2125
|
const exists = opts.exists ?? binOnPath;
|
|
2035
|
-
const mcpServerPath = opts.mcpServerPath ??
|
|
2126
|
+
const mcpServerPath = opts.mcpServerPath ?? join11(dirname8(fileURLToPath3(import.meta.url)), "mcp-server.js");
|
|
2036
2127
|
const preferred = opts.harness ?? "claude-code";
|
|
2037
2128
|
const order = [
|
|
2038
2129
|
preferred,
|
|
@@ -2052,49 +2143,80 @@ function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
2052
2143
|
budgetUsd: opts.budgetUsd,
|
|
2053
2144
|
mcpServerPath
|
|
2054
2145
|
});
|
|
2055
|
-
const
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2146
|
+
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
2147
|
+
if (cfg.disabled) return false;
|
|
2148
|
+
const key = createHash4("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
2149
|
+
const lease = acquireLease(
|
|
2150
|
+
opts.lease?.dir ?? join11(tmpdir4(), "hindsight-coding-agent", "surveys"),
|
|
2151
|
+
key,
|
|
2152
|
+
opts.lease?.staleMs ?? LEASE_STALE_MS
|
|
2153
|
+
);
|
|
2154
|
+
if (!lease) return false;
|
|
2155
|
+
const spec = {
|
|
2156
|
+
lease,
|
|
2157
|
+
bin: plan.bin,
|
|
2158
|
+
args: plan.args,
|
|
2159
|
+
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
2160
|
+
};
|
|
2161
|
+
const supervisorPath = opts.supervisorPath ?? join11(dirname8(fileURLToPath3(import.meta.url)), "survey-supervisor.js");
|
|
2162
|
+
return await new Promise((resolve3) => {
|
|
2163
|
+
try {
|
|
2164
|
+
const child = spawnFn("node", [supervisorPath], {
|
|
2165
|
+
cwd: repoDir,
|
|
2166
|
+
detached: true,
|
|
2167
|
+
stdio: "ignore",
|
|
2168
|
+
windowsHide: true,
|
|
2169
|
+
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
2170
|
+
});
|
|
2171
|
+
let spawned = false;
|
|
2172
|
+
child.on("error", () => {
|
|
2173
|
+
if (spawned) return;
|
|
2174
|
+
releaseLease(lease);
|
|
2175
|
+
resolve3(false);
|
|
2176
|
+
});
|
|
2177
|
+
child.once("spawn", () => {
|
|
2178
|
+
spawned = true;
|
|
2179
|
+
child.unref();
|
|
2180
|
+
resolve3(true);
|
|
2181
|
+
});
|
|
2182
|
+
} catch {
|
|
2183
|
+
releaseLease(lease);
|
|
2184
|
+
resolve3(false);
|
|
2185
|
+
}
|
|
2063
2186
|
});
|
|
2064
|
-
child.unref();
|
|
2065
|
-
return;
|
|
2066
2187
|
}
|
|
2067
2188
|
} catch {
|
|
2068
2189
|
}
|
|
2190
|
+
return false;
|
|
2069
2191
|
}
|
|
2070
2192
|
|
|
2071
2193
|
// src/core/status.ts
|
|
2072
2194
|
var DEEPEN_DIFF_TARGET = 300;
|
|
2073
2195
|
|
|
2074
2196
|
// src/core/auto-update.ts
|
|
2075
|
-
import { spawn as
|
|
2197
|
+
import { spawn as realSpawn5 } from "child_process";
|
|
2076
2198
|
import {
|
|
2077
2199
|
existsSync as existsSync4,
|
|
2078
|
-
mkdirSync as
|
|
2200
|
+
mkdirSync as mkdirSync5,
|
|
2079
2201
|
readFileSync as readFileSync7,
|
|
2080
2202
|
realpathSync as realpathSync2,
|
|
2081
|
-
unlinkSync,
|
|
2082
|
-
writeFileSync as
|
|
2203
|
+
unlinkSync as unlinkSync2,
|
|
2204
|
+
writeFileSync as writeFileSync3
|
|
2083
2205
|
} from "fs";
|
|
2084
|
-
import { homedir as homedir4, tmpdir as
|
|
2085
|
-
import { dirname as dirname9, join as
|
|
2206
|
+
import { homedir as homedir4, tmpdir as tmpdir5 } from "os";
|
|
2207
|
+
import { dirname as dirname9, join as join12 } from "path";
|
|
2086
2208
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2087
2209
|
var PACKAGE_NAME = "@vectorize-io/hindsight-coding-agents";
|
|
2088
2210
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
2089
2211
|
var FETCH_TIMEOUT_MS = 5e3;
|
|
2090
2212
|
function stateFile(runtimeDir) {
|
|
2091
|
-
return
|
|
2213
|
+
return join12(runtimeDir, ".update-check.json");
|
|
2092
2214
|
}
|
|
2093
2215
|
function packageRoot() {
|
|
2094
|
-
return
|
|
2216
|
+
return join12(dirname9(fileURLToPath4(import.meta.url)), "..");
|
|
2095
2217
|
}
|
|
2096
2218
|
function stagedRuntimeDir() {
|
|
2097
|
-
return
|
|
2219
|
+
return join12(homedir4(), ".hindsight", "coding-agents");
|
|
2098
2220
|
}
|
|
2099
2221
|
function sameDir(a, b) {
|
|
2100
2222
|
try {
|
|
@@ -2105,7 +2227,7 @@ function sameDir(a, b) {
|
|
|
2105
2227
|
}
|
|
2106
2228
|
function stagedVersion(pkgRoot) {
|
|
2107
2229
|
try {
|
|
2108
|
-
const pkg = JSON.parse(readFileSync7(
|
|
2230
|
+
const pkg = JSON.parse(readFileSync7(join12(pkgRoot, "package.json"), "utf8"));
|
|
2109
2231
|
return typeof pkg.version === "string" ? pkg.version : "";
|
|
2110
2232
|
} catch {
|
|
2111
2233
|
return "";
|
|
@@ -2139,7 +2261,7 @@ function dueForCheck(file, now) {
|
|
|
2139
2261
|
var ORIGIN_FILE = ".install-origin.json";
|
|
2140
2262
|
function selfUpdatable(runtimeDir) {
|
|
2141
2263
|
try {
|
|
2142
|
-
const origin = JSON.parse(readFileSync7(
|
|
2264
|
+
const origin = JSON.parse(readFileSync7(join12(runtimeDir, ORIGIN_FILE), "utf8"));
|
|
2143
2265
|
if (typeof origin.source !== "string" || !origin.source) return false;
|
|
2144
2266
|
return origin.source.split(/[\\/]/).includes("_npx");
|
|
2145
2267
|
} catch {
|
|
@@ -2148,7 +2270,7 @@ function selfUpdatable(runtimeDir) {
|
|
|
2148
2270
|
}
|
|
2149
2271
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
2150
2272
|
function lockFile() {
|
|
2151
|
-
return
|
|
2273
|
+
return join12(tmpdir5(), "hindsight-coding-agent", "auto-update.lock");
|
|
2152
2274
|
}
|
|
2153
2275
|
function acquireUpdateLock(file, now) {
|
|
2154
2276
|
try {
|
|
@@ -2167,8 +2289,8 @@ function acquireUpdateLock(file, now) {
|
|
|
2167
2289
|
} catch {
|
|
2168
2290
|
}
|
|
2169
2291
|
try {
|
|
2170
|
-
|
|
2171
|
-
|
|
2292
|
+
mkdirSync5(dirname9(file), { recursive: true });
|
|
2293
|
+
writeFileSync3(file, JSON.stringify({ pid: process.pid, ts: now }));
|
|
2172
2294
|
return true;
|
|
2173
2295
|
} catch {
|
|
2174
2296
|
return false;
|
|
@@ -2177,19 +2299,19 @@ function acquireUpdateLock(file, now) {
|
|
|
2177
2299
|
function holdLockFor(file, pid, now) {
|
|
2178
2300
|
try {
|
|
2179
2301
|
if (pid === void 0) return releaseUpdateLock(file);
|
|
2180
|
-
|
|
2302
|
+
writeFileSync3(file, JSON.stringify({ pid, ts: now }));
|
|
2181
2303
|
} catch {
|
|
2182
2304
|
}
|
|
2183
2305
|
}
|
|
2184
2306
|
function releaseUpdateLock(file) {
|
|
2185
2307
|
try {
|
|
2186
|
-
|
|
2308
|
+
unlinkSync2(file);
|
|
2187
2309
|
} catch {
|
|
2188
2310
|
}
|
|
2189
2311
|
}
|
|
2190
2312
|
function stampCheck(file, now, latest) {
|
|
2191
2313
|
try {
|
|
2192
|
-
|
|
2314
|
+
writeFileSync3(file, JSON.stringify({ lastCheck: now, latest }));
|
|
2193
2315
|
} catch {
|
|
2194
2316
|
}
|
|
2195
2317
|
}
|
|
@@ -2238,7 +2360,7 @@ async function maybeAutoUpdate(cfg, opts = {}) {
|
|
|
2238
2360
|
return "";
|
|
2239
2361
|
}
|
|
2240
2362
|
log.info("auto-update", `updating the Hindsight runtime ${current2} -> ${latest}`);
|
|
2241
|
-
const child = (opts.spawn ??
|
|
2363
|
+
const child = (opts.spawn ?? realSpawn5)(
|
|
2242
2364
|
"npx",
|
|
2243
2365
|
["-y", `${PACKAGE_NAME}@${latest}`, "update"],
|
|
2244
2366
|
{
|
|
@@ -2266,7 +2388,7 @@ async function maybeAutoUpdate(cfg, opts = {}) {
|
|
|
2266
2388
|
// src/core/skill-sync.ts
|
|
2267
2389
|
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
|
|
2268
2390
|
import { homedir as homedir5 } from "os";
|
|
2269
|
-
import { dirname as dirname10, join as
|
|
2391
|
+
import { dirname as dirname10, join as join13 } from "path";
|
|
2270
2392
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
2271
2393
|
|
|
2272
2394
|
// src/core/skill-dirs.ts
|
|
@@ -2298,17 +2420,17 @@ var SKILL_DIRS = {
|
|
|
2298
2420
|
|
|
2299
2421
|
// src/core/skill-sync.ts
|
|
2300
2422
|
function packagedSkillDir() {
|
|
2301
|
-
return
|
|
2423
|
+
return join13(dirname10(fileURLToPath5(import.meta.url)), "..", "skill");
|
|
2302
2424
|
}
|
|
2303
2425
|
function syncCompanionSkill(harness, opts = {}) {
|
|
2304
2426
|
try {
|
|
2305
2427
|
const parts = SKILL_DIRS[harness];
|
|
2306
2428
|
if (!parts) return;
|
|
2307
2429
|
const src = opts.srcDir ?? packagedSkillDir();
|
|
2308
|
-
const srcMd =
|
|
2430
|
+
const srcMd = join13(src, "SKILL.md");
|
|
2309
2431
|
if (!existsSync5(srcMd)) return;
|
|
2310
|
-
const dst =
|
|
2311
|
-
const dstMd =
|
|
2432
|
+
const dst = join13(opts.home ?? homedir5(), ...parts, "hindsight-coding-agent");
|
|
2433
|
+
const dstMd = join13(dst, "SKILL.md");
|
|
2312
2434
|
if (!existsSync5(dstMd)) return;
|
|
2313
2435
|
if (readFileSync8(srcMd, "utf8") !== readFileSync8(dstMd, "utf8")) {
|
|
2314
2436
|
cpSync(src, dst, { recursive: true });
|
|
@@ -2317,6 +2439,43 @@ function syncCompanionSkill(harness, opts = {}) {
|
|
|
2317
2439
|
}
|
|
2318
2440
|
}
|
|
2319
2441
|
|
|
2442
|
+
// src/core/legacy.ts
|
|
2443
|
+
import { existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
|
|
2444
|
+
import { homedir as homedir6 } from "os";
|
|
2445
|
+
import { join as join14, relative, isAbsolute as isAbsolute2 } from "path";
|
|
2446
|
+
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
2447
|
+
function detectLegacyClaudePlugin(cwd, claudeDir = join14(homedir6(), ".claude")) {
|
|
2448
|
+
const registry = readJson(join14(claudeDir, "plugins", "installed_plugins.json"));
|
|
2449
|
+
const plugins = registry?.plugins;
|
|
2450
|
+
if (!plugins || typeof plugins !== "object") return void 0;
|
|
2451
|
+
const enabled = readJson(join14(claudeDir, "settings.json"))?.enabledPlugins;
|
|
2452
|
+
for (const [key, raw] of Object.entries(plugins)) {
|
|
2453
|
+
if (key.split("@")[0] !== LEGACY_CLAUDE_PLUGIN) continue;
|
|
2454
|
+
if (enabled && enabled[key] === false) continue;
|
|
2455
|
+
const installs = Array.isArray(raw) ? raw : [raw];
|
|
2456
|
+
const active = installs.some((i) => {
|
|
2457
|
+
if (!i || typeof i !== "object") return false;
|
|
2458
|
+
if (typeof i.projectPath !== "string") return true;
|
|
2459
|
+
const rel = relative(i.projectPath, cwd);
|
|
2460
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
2461
|
+
});
|
|
2462
|
+
if (active) return key;
|
|
2463
|
+
}
|
|
2464
|
+
return void 0;
|
|
2465
|
+
}
|
|
2466
|
+
function readJson(path) {
|
|
2467
|
+
try {
|
|
2468
|
+
const parsed = JSON.parse(readFileSync9(path, "utf8"));
|
|
2469
|
+
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
2470
|
+
} catch {
|
|
2471
|
+
return void 0;
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
function legacyClaudePluginWarning(key) {
|
|
2475
|
+
return `\u26A0\uFE0F The old Hindsight Claude Code plugin (${key}) is still installed \u2014 it runs alongside this one, so memory is recalled and retained twice.
|
|
2476
|
+
\u21B3 remove it: claude plugin uninstall ${key}`;
|
|
2477
|
+
}
|
|
2478
|
+
|
|
2320
2479
|
// src/core/session-start.ts
|
|
2321
2480
|
function buildSeedBanner(bankId, cold = true, gitNote) {
|
|
2322
2481
|
const headline = cold ? `${brandWord()} is learning this repo \u2014 ingesting its decisions, conventions and history` : `${brandWord()} is tracking the decisions, conventions and history of this repo`;
|
|
@@ -2397,13 +2556,13 @@ async function buildSessionStartContext(args) {
|
|
|
2397
2556
|
startSeed(cwd, { limit: cfg.seedLimit, harness });
|
|
2398
2557
|
if (docIds.size === 0) {
|
|
2399
2558
|
if (cfg.codebaseSurvey !== false) {
|
|
2400
|
-
startSurvey(cwd, {
|
|
2559
|
+
const started = await startSurvey(cwd, {
|
|
2401
2560
|
harness,
|
|
2402
2561
|
model: cfg.surveyModel,
|
|
2403
2562
|
budgetUsd: cfg.surveyBudgetUsd
|
|
2404
2563
|
});
|
|
2405
2564
|
const sha = resolveHeadSha(cwd);
|
|
2406
|
-
if (sha) recordSurveyBaseline(sha);
|
|
2565
|
+
if (started && sha) recordSurveyBaseline(sha);
|
|
2407
2566
|
}
|
|
2408
2567
|
diag(harness, "seed_started", { bank: bankId });
|
|
2409
2568
|
} else if (cfg.codebaseSurvey !== false && cfg.surveyRefreshCommits > 0) {
|
|
@@ -2420,17 +2579,19 @@ async function buildSessionStartContext(args) {
|
|
|
2420
2579
|
const uploads = await client.listDocumentIds("source:upload", "all_strict").catch(() => /* @__PURE__ */ new Set());
|
|
2421
2580
|
const findingsAbsent = counts.length > 0 && !SURVEY_DOC_IDS.some((id) => uploads.has(id));
|
|
2422
2581
|
if (sinceLast !== null && sinceLast >= cfg.surveyRefreshCommits || findingsAbsent) {
|
|
2423
|
-
startSurvey(cwd, {
|
|
2582
|
+
const started = await startSurvey(cwd, {
|
|
2424
2583
|
harness,
|
|
2425
2584
|
model: cfg.surveyModel,
|
|
2426
2585
|
budgetUsd: cfg.surveyBudgetUsd
|
|
2427
2586
|
});
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2587
|
+
if (started) {
|
|
2588
|
+
recordSurveyBaseline(sha);
|
|
2589
|
+
diag(harness, "survey_refresh", {
|
|
2590
|
+
bank: bankId,
|
|
2591
|
+
commits: sinceLast,
|
|
2592
|
+
retry: findingsAbsent
|
|
2593
|
+
});
|
|
2594
|
+
}
|
|
2434
2595
|
} else if (sinceLast === null) {
|
|
2435
2596
|
recordSurveyBaseline(sha);
|
|
2436
2597
|
}
|
|
@@ -2463,6 +2624,13 @@ async function buildSessionStartContext(args) {
|
|
|
2463
2624
|
}).catch(() => void 0);
|
|
2464
2625
|
}
|
|
2465
2626
|
systemMessage = buildSeedBanner(bankId, cold === true, gitNote);
|
|
2627
|
+
const detectLegacy = args.detectLegacyPlugin ?? (harness === "claude-code" ? detectLegacyClaudePlugin : void 0);
|
|
2628
|
+
const legacyPlugin = detectLegacy?.(cwd);
|
|
2629
|
+
if (legacyPlugin) {
|
|
2630
|
+
systemMessage += `
|
|
2631
|
+
${legacyClaudePluginWarning(legacyPlugin)}`;
|
|
2632
|
+
diag(harness, "legacy_plugin_active", { plugin: legacyPlugin });
|
|
2633
|
+
}
|
|
2466
2634
|
diag(harness, "session_start", { bank: bankId, cold, pages: pages.length, ms: Date.now() - t0 });
|
|
2467
2635
|
return { systemMessage, additionalContext, deferInitialReflect };
|
|
2468
2636
|
}
|
|
@@ -2471,7 +2639,7 @@ async function runSessionStartHook(spec, makeClient = (o) => new HindsightClient
|
|
|
2471
2639
|
try {
|
|
2472
2640
|
let ev = {};
|
|
2473
2641
|
try {
|
|
2474
|
-
ev = JSON.parse(
|
|
2642
|
+
ev = JSON.parse(readFileSync10(0, "utf8"));
|
|
2475
2643
|
} catch {
|
|
2476
2644
|
return;
|
|
2477
2645
|
}
|
|
@@ -2640,19 +2808,19 @@ function readCopilotTranscript(path) {
|
|
|
2640
2808
|
}
|
|
2641
2809
|
|
|
2642
2810
|
// src/core/transcript-grok.ts
|
|
2643
|
-
import { existsSync as
|
|
2644
|
-
import { homedir as
|
|
2645
|
-
import { join as
|
|
2811
|
+
import { existsSync as existsSync7, readFileSync as readFileSync11, readdirSync as readdirSync2 } from "fs";
|
|
2812
|
+
import { homedir as homedir7 } from "os";
|
|
2813
|
+
import { join as join15 } from "path";
|
|
2646
2814
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
2647
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
2648
|
-
const sessionsDir =
|
|
2649
|
-
const direct =
|
|
2650
|
-
if (
|
|
2815
|
+
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join15(homedir7(), ".grok")) {
|
|
2816
|
+
const sessionsDir = join15(grokHome, "sessions");
|
|
2817
|
+
const direct = join15(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
|
|
2818
|
+
if (existsSync7(direct)) return direct;
|
|
2651
2819
|
try {
|
|
2652
|
-
for (const candidate of
|
|
2653
|
-
const directory =
|
|
2654
|
-
if (
|
|
2655
|
-
return
|
|
2820
|
+
for (const candidate of readdirSync2(sessionsDir)) {
|
|
2821
|
+
const directory = join15(sessionsDir, candidate);
|
|
2822
|
+
if (readFileSync11(join15(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
2823
|
+
return join15(directory, sessionId, CHAT_HISTORY);
|
|
2656
2824
|
}
|
|
2657
2825
|
}
|
|
2658
2826
|
} catch {
|
|
@@ -2687,12 +2855,12 @@ function readGrokTranscript(path) {
|
|
|
2687
2855
|
}
|
|
2688
2856
|
|
|
2689
2857
|
// src/core/transcript-devin.ts
|
|
2690
|
-
import { existsSync as
|
|
2858
|
+
import { existsSync as existsSync8 } from "fs";
|
|
2691
2859
|
import { createRequire } from "module";
|
|
2692
|
-
import { homedir as
|
|
2693
|
-
import { join as
|
|
2694
|
-
function devinSessionDb(home =
|
|
2695
|
-
return
|
|
2860
|
+
import { homedir as homedir8 } from "os";
|
|
2861
|
+
import { join as join16 } from "path";
|
|
2862
|
+
function devinSessionDb(home = homedir8()) {
|
|
2863
|
+
return join16(home, ".local", "share", "devin", "cli", "sessions.db");
|
|
2696
2864
|
}
|
|
2697
2865
|
function parseDevinMessages(nodes) {
|
|
2698
2866
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -2729,7 +2897,7 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
|
|
|
2729
2897
|
diag("devin-cli", "sqlite_unavailable", { node: process.version, dbPath });
|
|
2730
2898
|
return [];
|
|
2731
2899
|
}
|
|
2732
|
-
if (!
|
|
2900
|
+
if (!existsSync8(dbPath)) {
|
|
2733
2901
|
diag("devin-cli", "session_db_missing", { dbPath });
|
|
2734
2902
|
return [];
|
|
2735
2903
|
}
|
|
@@ -3002,7 +3170,7 @@ function readDroidTranscript(path) {
|
|
|
3002
3170
|
}
|
|
3003
3171
|
|
|
3004
3172
|
// src/core/transcript-zcode.ts
|
|
3005
|
-
import { readFileSync as
|
|
3173
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
3006
3174
|
function messageText2(content) {
|
|
3007
3175
|
if (typeof content === "string") return content.trim();
|
|
3008
3176
|
if (!Array.isArray(content)) return "";
|
|
@@ -3012,7 +3180,7 @@ function readZcodeTranscript(path) {
|
|
|
3012
3180
|
if (!path) return [];
|
|
3013
3181
|
let body;
|
|
3014
3182
|
try {
|
|
3015
|
-
body =
|
|
3183
|
+
body = readFileSync12(path, "utf8");
|
|
3016
3184
|
} catch {
|
|
3017
3185
|
return [];
|
|
3018
3186
|
}
|