@vectorize-io/hindsight-coding-agents 0.5.3 → 0.5.5
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 +5 -2
- package/dist/antigravity-hook.js +185 -41
- package/dist/antigravity-stop-hook.js +114 -36
- package/dist/claude-hook.js +185 -41
- package/dist/claude-sessionstart-hook.js +292 -76
- package/dist/claude-stop-hook.js +114 -36
- package/dist/cline.js +331 -58
- package/dist/codex-hook.js +185 -41
- package/dist/codex-sessionstart-hook.js +292 -76
- package/dist/codex-stop-hook.js +114 -36
- package/dist/copilot-hook.js +185 -41
- package/dist/copilot-sessionstart-hook.js +292 -76
- package/dist/copilot-stop-hook.js +114 -36
- package/dist/cursor-hook.js +185 -41
- package/dist/cursor-sessionstart-hook.js +292 -76
- package/dist/cursor-stop-hook.js +114 -36
- package/dist/dcode-hook.js +185 -41
- package/dist/dcode-sessionstart-hook.js +292 -76
- package/dist/dcode-stop-hook.js +114 -36
- package/dist/deepen.js +93 -18
- package/dist/devin-hook.js +185 -41
- package/dist/devin-sessionstart-hook.js +292 -76
- package/dist/devin-stop-hook.js +114 -36
- package/dist/droid-hook.js +185 -41
- package/dist/droid-sessionstart-hook.js +292 -76
- package/dist/droid-stop-hook.js +114 -36
- package/dist/dsh.js +333 -60
- package/dist/grok-hook.js +185 -41
- package/dist/grok-sessionstart-hook.js +292 -76
- package/dist/grok-stop-hook.js +114 -36
- package/dist/index.js +333 -60
- package/dist/installer.js +1030 -268
- package/dist/kilo.js +333 -60
- package/dist/mcp-server.js +86 -11
- package/dist/opencode2.js +333 -60
- package/dist/pi.js +332 -59
- package/dist/prime-agent.js +332 -59
- package/dist/qwen-hook.js +185 -41
- package/dist/qwen-sessionstart-hook.js +292 -76
- package/dist/qwen-stop-hook.js +114 -36
- package/dist/status.js +84 -9
- package/dist/survey-supervisor.js +81 -0
- package/dist/zcode-hook.js +185 -41
- package/dist/zcode-sessionstart-hook.js +292 -76
- package/dist/zcode-stop-hook.js +114 -36
- package/package.json +2 -1
- package/plugin.json +1 -1
- package/skill/SKILL.md +5 -2
|
@@ -661,6 +661,22 @@ var KnowledgePagesUnavailableError = class extends Error {
|
|
|
661
661
|
}
|
|
662
662
|
};
|
|
663
663
|
var TERMINAL = /* @__PURE__ */ new Set(["completed", "failed", "cancelled", "error"]);
|
|
664
|
+
var ReflectError = class extends Error {
|
|
665
|
+
constructor(message, status, timedOut, options) {
|
|
666
|
+
super(message, options);
|
|
667
|
+
this.status = status;
|
|
668
|
+
this.timedOut = timedOut;
|
|
669
|
+
this.name = "ReflectError";
|
|
670
|
+
}
|
|
671
|
+
status;
|
|
672
|
+
timedOut;
|
|
673
|
+
/** A timeout or a 5xx means reflect's synthesis (the slow LLM path) broke, while the cheap
|
|
674
|
+
* retrieval endpoints may still answer — worth falling back. A 4xx will fail the same way on
|
|
675
|
+
* every endpoint (auth, missing bank), so it is not. */
|
|
676
|
+
get fallbackEligible() {
|
|
677
|
+
return this.timedOut || this.status !== void 0 && this.status >= 500;
|
|
678
|
+
}
|
|
679
|
+
};
|
|
664
680
|
var DEFAULT_MAX_PARALLEL_RETAINS = 10;
|
|
665
681
|
var POLL_CYCLE_MS = 5e3;
|
|
666
682
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
@@ -744,11 +760,11 @@ var HindsightClient = class {
|
|
|
744
760
|
return `${this.apiUrl}/v1/default/banks/${encodeURIComponent(this.bank)}${suffix}`;
|
|
745
761
|
}
|
|
746
762
|
/** `tolerate` adds statuses that are returned to the caller instead of thrown (404 always is). */
|
|
747
|
-
async req(method, url, body, tolerate = []) {
|
|
763
|
+
async req(method, url, body, tolerate = [], timeoutMs = 15e3) {
|
|
748
764
|
const r = await this.fetchWithAuth(url, {
|
|
749
765
|
method,
|
|
750
766
|
body: body ? JSON.stringify(body) : void 0,
|
|
751
|
-
signal: AbortSignal.timeout(
|
|
767
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
752
768
|
});
|
|
753
769
|
if (r.status === 429 && !tolerate.includes(429))
|
|
754
770
|
throw new RateLimitedError(retryAfterMs(r.headers.get("retry-after")));
|
|
@@ -941,7 +957,7 @@ var HindsightClient = class {
|
|
|
941
957
|
/**
|
|
942
958
|
* Reflect: synthesized, root-cause answer over the bank. Bounded so a slow server never hangs a
|
|
943
959
|
* caller — but `timeoutMs` is REQUIRED, deliberately: the right deadline differs by an order of
|
|
944
|
-
* magnitude between the automatic hook (
|
|
960
|
+
* magnitude between the automatic hook (20s, to fit the host's window) and the agent-invoked
|
|
945
961
|
* tool (minutes, on a populated bank). This used to default to 120s, which silently overrode the
|
|
946
962
|
* tool's configured window and aborted every high-budget synthesis mid-flight (#3590).
|
|
947
963
|
*/
|
|
@@ -954,13 +970,46 @@ var HindsightClient = class {
|
|
|
954
970
|
body: JSON.stringify({ query, budget: opts.budget ?? "high" }),
|
|
955
971
|
signal: ctrl.signal
|
|
956
972
|
});
|
|
957
|
-
if (!resp.ok)
|
|
973
|
+
if (!resp.ok)
|
|
974
|
+
throw new ReflectError(
|
|
975
|
+
`reflect ${resp.status} ${(await resp.text()).slice(0, 1e3)}${this.authHint(resp.status)}`,
|
|
976
|
+
resp.status,
|
|
977
|
+
false
|
|
978
|
+
);
|
|
958
979
|
const data = await resp.json();
|
|
959
980
|
return (data.text || "").trim();
|
|
981
|
+
} catch (e) {
|
|
982
|
+
if (ctrl.signal.aborted)
|
|
983
|
+
throw new ReflectError(`reflect timed out after ${opts.timeoutMs}ms`, void 0, true, {
|
|
984
|
+
cause: e
|
|
985
|
+
});
|
|
986
|
+
throw e;
|
|
960
987
|
} finally {
|
|
961
988
|
clearTimeout(timer);
|
|
962
989
|
}
|
|
963
990
|
}
|
|
991
|
+
/**
|
|
992
|
+
* Raw recall restricted to consolidated observations — no LLM in the loop, so it still answers
|
|
993
|
+
* when reflect's synthesis times out or 5xxs. Returns the observation texts in rank order.
|
|
994
|
+
*/
|
|
995
|
+
async recallObservations(query, opts) {
|
|
996
|
+
const r = await this.req(
|
|
997
|
+
"POST",
|
|
998
|
+
this.bankUrl("/memories/recall"),
|
|
999
|
+
{
|
|
1000
|
+
query,
|
|
1001
|
+
types: ["observation"],
|
|
1002
|
+
budget: "low",
|
|
1003
|
+
max_tokens: opts.maxTokens,
|
|
1004
|
+
include: { entities: null }
|
|
1005
|
+
},
|
|
1006
|
+
[],
|
|
1007
|
+
opts.timeoutMs
|
|
1008
|
+
);
|
|
1009
|
+
if (r.status === 404) return [];
|
|
1010
|
+
const j = await r.json();
|
|
1011
|
+
return (j.results ?? []).map((x) => (x.text ?? "").trim()).filter(Boolean);
|
|
1012
|
+
}
|
|
964
1013
|
/**
|
|
965
1014
|
* The bank's knowledge-base tree (folders + pages, nested). The tree carries names, source
|
|
966
1015
|
* queries and staleness but NOT synthesized content, so it is cheap enough to poll.
|
|
@@ -1025,10 +1074,16 @@ var HindsightClient = class {
|
|
|
1025
1074
|
/** Hybrid (BM25 + vector, RRF-fused) server-side search over the bank's knowledge pages.
|
|
1026
1075
|
* Returns page-level hits with a relevance snippet — the real search behind
|
|
1027
1076
|
* hindsight_search_knowledge_pages. */
|
|
1028
|
-
async searchKnowledgePages(query, limit = 3) {
|
|
1077
|
+
async searchKnowledgePages(query, limit = 3, timeoutMs) {
|
|
1029
1078
|
if (this.knowledgePagesSupported === false) throw new KnowledgePagesUnavailableError();
|
|
1030
1079
|
const q = `?q=${encodeURIComponent(query)}&limit=${limit}`;
|
|
1031
|
-
const r = await this.req(
|
|
1080
|
+
const r = await this.req(
|
|
1081
|
+
"GET",
|
|
1082
|
+
this.bankUrl(`/knowledge-base/search${q}`),
|
|
1083
|
+
void 0,
|
|
1084
|
+
[],
|
|
1085
|
+
timeoutMs
|
|
1086
|
+
);
|
|
1032
1087
|
const j = await r.json();
|
|
1033
1088
|
return (j.results ?? []).map((x) => ({
|
|
1034
1089
|
id: x.id,
|
|
@@ -1858,7 +1913,7 @@ function* streamLines(path, start) {
|
|
|
1858
1913
|
}
|
|
1859
1914
|
|
|
1860
1915
|
// src/core/session-start.ts
|
|
1861
|
-
import { readFileSync as
|
|
1916
|
+
import { readFileSync as readFileSync10 } from "fs";
|
|
1862
1917
|
|
|
1863
1918
|
// src/core/git.ts
|
|
1864
1919
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
@@ -1900,11 +1955,95 @@ function hasGitHistory(dir) {
|
|
|
1900
1955
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
1901
1956
|
|
|
1902
1957
|
// src/core/survey.ts
|
|
1903
|
-
import { spawn as
|
|
1958
|
+
import { spawn as realSpawn4 } from "child_process";
|
|
1959
|
+
import { createHash as createHash4 } from "crypto";
|
|
1904
1960
|
import { existsSync as existsSync3 } from "fs";
|
|
1905
|
-
import { homedir as homedir3 } from "os";
|
|
1906
|
-
import { dirname as dirname8, join as
|
|
1961
|
+
import { homedir as homedir3, tmpdir as tmpdir4 } from "os";
|
|
1962
|
+
import { dirname as dirname8, join as join11 } from "path";
|
|
1907
1963
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1964
|
+
|
|
1965
|
+
// src/core/host-client.ts
|
|
1966
|
+
function resolveHostConfig(harness, directory) {
|
|
1967
|
+
const cfg0 = loadConfig({ harness });
|
|
1968
|
+
if (cfg0.disabled) return { cfg: cfg0, bankId: "" };
|
|
1969
|
+
const bankId = deriveBankIdOrSkip(cfg0, directory, harness);
|
|
1970
|
+
if (bankId === null) return { cfg: { ...cfg0, disabled: true }, bankId: "" };
|
|
1971
|
+
return applyBankConfig(cfg0, bankId, directory);
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
// src/core/survey-lease.ts
|
|
1975
|
+
import { spawn as realSpawn3 } from "child_process";
|
|
1976
|
+
import { randomUUID } from "crypto";
|
|
1977
|
+
import {
|
|
1978
|
+
mkdirSync as mkdirSync4,
|
|
1979
|
+
mkdtempSync,
|
|
1980
|
+
readdirSync,
|
|
1981
|
+
renameSync as renameSync2,
|
|
1982
|
+
rmdirSync,
|
|
1983
|
+
rmSync as rmSync2,
|
|
1984
|
+
statSync as statSync3,
|
|
1985
|
+
unlinkSync,
|
|
1986
|
+
utimesSync,
|
|
1987
|
+
writeFileSync as writeFileSync2
|
|
1988
|
+
} from "fs";
|
|
1989
|
+
import { join as join10 } from "path";
|
|
1990
|
+
var LEASE_STALE_MS = 3e4;
|
|
1991
|
+
var SURVEY_SPEC_ENV = "HINDSIGHT_SURVEY_SPEC";
|
|
1992
|
+
function tryRename(from, to) {
|
|
1993
|
+
try {
|
|
1994
|
+
renameSync2(from, to);
|
|
1995
|
+
return true;
|
|
1996
|
+
} catch {
|
|
1997
|
+
return false;
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
function releaseLease(lease) {
|
|
2001
|
+
try {
|
|
2002
|
+
unlinkSync(join10(lease.directory, lease.owner));
|
|
2003
|
+
} catch {
|
|
2004
|
+
return;
|
|
2005
|
+
}
|
|
2006
|
+
try {
|
|
2007
|
+
rmdirSync(lease.directory);
|
|
2008
|
+
} catch {
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
function reclaimIfStale(directory, staleMs) {
|
|
2012
|
+
const owners = readdirSync(directory);
|
|
2013
|
+
if (owners.length === 0) {
|
|
2014
|
+
try {
|
|
2015
|
+
rmdirSync(directory);
|
|
2016
|
+
} catch {
|
|
2017
|
+
}
|
|
2018
|
+
return true;
|
|
2019
|
+
}
|
|
2020
|
+
if (owners.length !== 1) return false;
|
|
2021
|
+
const age = Date.now() - statSync3(join10(directory, owners[0])).mtimeMs;
|
|
2022
|
+
if (Math.abs(age) <= staleMs) return false;
|
|
2023
|
+
releaseLease({ directory, owner: owners[0] });
|
|
2024
|
+
return true;
|
|
2025
|
+
}
|
|
2026
|
+
function acquireLease(root, key, staleMs = LEASE_STALE_MS) {
|
|
2027
|
+
let staging;
|
|
2028
|
+
try {
|
|
2029
|
+
mkdirSync4(root, { recursive: true, mode: 448 });
|
|
2030
|
+
staging = mkdtempSync(join10(root, "claim-"));
|
|
2031
|
+
const owner = randomUUID();
|
|
2032
|
+
writeFileSync2(join10(staging, owner), "", { flag: "wx", mode: 384 });
|
|
2033
|
+
const directory = join10(root, `survey-${key}.lock`);
|
|
2034
|
+
if (!tryRename(staging, directory)) {
|
|
2035
|
+
if (!reclaimIfStale(directory, staleMs)) return void 0;
|
|
2036
|
+
if (!tryRename(staging, directory)) return void 0;
|
|
2037
|
+
}
|
|
2038
|
+
return { directory, owner };
|
|
2039
|
+
} catch {
|
|
2040
|
+
return void 0;
|
|
2041
|
+
} finally {
|
|
2042
|
+
if (staging) rmSync2(staging, { recursive: true, force: true });
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
// src/core/survey.ts
|
|
1908
2047
|
var SURVEY_DOC_IDS = [
|
|
1909
2048
|
"repository-component-map",
|
|
1910
2049
|
"repository-core-concepts",
|
|
@@ -1914,7 +2053,7 @@ var SURVEY_DOC_IDS = [
|
|
|
1914
2053
|
function resolveClaudeBin(explicit) {
|
|
1915
2054
|
if (explicit) return explicit;
|
|
1916
2055
|
if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
|
|
1917
|
-
const nativeInstallPath =
|
|
2056
|
+
const nativeInstallPath = join11(homedir3(), ".claude", "local", "claude");
|
|
1918
2057
|
try {
|
|
1919
2058
|
if (existsSync3(nativeInstallPath)) return nativeInstallPath;
|
|
1920
2059
|
} catch {
|
|
@@ -2028,11 +2167,11 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
2028
2167
|
}
|
|
2029
2168
|
}
|
|
2030
2169
|
}
|
|
2031
|
-
function startCodebaseSurvey(repoDir, opts = {}) {
|
|
2170
|
+
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
2032
2171
|
try {
|
|
2033
|
-
const spawnFn = opts.spawn ??
|
|
2172
|
+
const spawnFn = opts.spawn ?? realSpawn4;
|
|
2034
2173
|
const exists = opts.exists ?? binOnPath;
|
|
2035
|
-
const mcpServerPath = opts.mcpServerPath ??
|
|
2174
|
+
const mcpServerPath = opts.mcpServerPath ?? join11(dirname8(fileURLToPath3(import.meta.url)), "mcp-server.js");
|
|
2036
2175
|
const preferred = opts.harness ?? "claude-code";
|
|
2037
2176
|
const order = [
|
|
2038
2177
|
preferred,
|
|
@@ -2052,49 +2191,80 @@ function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
2052
2191
|
budgetUsd: opts.budgetUsd,
|
|
2053
2192
|
mcpServerPath
|
|
2054
2193
|
});
|
|
2055
|
-
const
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2194
|
+
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
2195
|
+
if (cfg.disabled) return false;
|
|
2196
|
+
const key = createHash4("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
2197
|
+
const lease = acquireLease(
|
|
2198
|
+
opts.lease?.dir ?? join11(tmpdir4(), "hindsight-coding-agent", "surveys"),
|
|
2199
|
+
key,
|
|
2200
|
+
opts.lease?.staleMs ?? LEASE_STALE_MS
|
|
2201
|
+
);
|
|
2202
|
+
if (!lease) return false;
|
|
2203
|
+
const spec = {
|
|
2204
|
+
lease,
|
|
2205
|
+
bin: plan.bin,
|
|
2206
|
+
args: plan.args,
|
|
2207
|
+
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
2208
|
+
};
|
|
2209
|
+
const supervisorPath = opts.supervisorPath ?? join11(dirname8(fileURLToPath3(import.meta.url)), "survey-supervisor.js");
|
|
2210
|
+
return await new Promise((resolve3) => {
|
|
2211
|
+
try {
|
|
2212
|
+
const child = spawnFn("node", [supervisorPath], {
|
|
2213
|
+
cwd: repoDir,
|
|
2214
|
+
detached: true,
|
|
2215
|
+
stdio: "ignore",
|
|
2216
|
+
windowsHide: true,
|
|
2217
|
+
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
2218
|
+
});
|
|
2219
|
+
let spawned = false;
|
|
2220
|
+
child.on("error", () => {
|
|
2221
|
+
if (spawned) return;
|
|
2222
|
+
releaseLease(lease);
|
|
2223
|
+
resolve3(false);
|
|
2224
|
+
});
|
|
2225
|
+
child.once("spawn", () => {
|
|
2226
|
+
spawned = true;
|
|
2227
|
+
child.unref();
|
|
2228
|
+
resolve3(true);
|
|
2229
|
+
});
|
|
2230
|
+
} catch {
|
|
2231
|
+
releaseLease(lease);
|
|
2232
|
+
resolve3(false);
|
|
2233
|
+
}
|
|
2063
2234
|
});
|
|
2064
|
-
child.unref();
|
|
2065
|
-
return;
|
|
2066
2235
|
}
|
|
2067
2236
|
} catch {
|
|
2068
2237
|
}
|
|
2238
|
+
return false;
|
|
2069
2239
|
}
|
|
2070
2240
|
|
|
2071
2241
|
// src/core/status.ts
|
|
2072
2242
|
var DEEPEN_DIFF_TARGET = 300;
|
|
2073
2243
|
|
|
2074
2244
|
// src/core/auto-update.ts
|
|
2075
|
-
import { spawn as
|
|
2245
|
+
import { spawn as realSpawn5 } from "child_process";
|
|
2076
2246
|
import {
|
|
2077
2247
|
existsSync as existsSync4,
|
|
2078
|
-
mkdirSync as
|
|
2248
|
+
mkdirSync as mkdirSync5,
|
|
2079
2249
|
readFileSync as readFileSync7,
|
|
2080
2250
|
realpathSync as realpathSync2,
|
|
2081
|
-
unlinkSync,
|
|
2082
|
-
writeFileSync as
|
|
2251
|
+
unlinkSync as unlinkSync2,
|
|
2252
|
+
writeFileSync as writeFileSync3
|
|
2083
2253
|
} from "fs";
|
|
2084
|
-
import { homedir as homedir4, tmpdir as
|
|
2085
|
-
import { dirname as dirname9, join as
|
|
2254
|
+
import { homedir as homedir4, tmpdir as tmpdir5 } from "os";
|
|
2255
|
+
import { dirname as dirname9, join as join12 } from "path";
|
|
2086
2256
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
2087
2257
|
var PACKAGE_NAME = "@vectorize-io/hindsight-coding-agents";
|
|
2088
2258
|
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
2089
2259
|
var FETCH_TIMEOUT_MS = 5e3;
|
|
2090
2260
|
function stateFile(runtimeDir) {
|
|
2091
|
-
return
|
|
2261
|
+
return join12(runtimeDir, ".update-check.json");
|
|
2092
2262
|
}
|
|
2093
2263
|
function packageRoot() {
|
|
2094
|
-
return
|
|
2264
|
+
return join12(dirname9(fileURLToPath4(import.meta.url)), "..");
|
|
2095
2265
|
}
|
|
2096
2266
|
function stagedRuntimeDir() {
|
|
2097
|
-
return
|
|
2267
|
+
return join12(homedir4(), ".hindsight", "coding-agents");
|
|
2098
2268
|
}
|
|
2099
2269
|
function sameDir(a, b) {
|
|
2100
2270
|
try {
|
|
@@ -2105,7 +2275,7 @@ function sameDir(a, b) {
|
|
|
2105
2275
|
}
|
|
2106
2276
|
function stagedVersion(pkgRoot) {
|
|
2107
2277
|
try {
|
|
2108
|
-
const pkg = JSON.parse(readFileSync7(
|
|
2278
|
+
const pkg = JSON.parse(readFileSync7(join12(pkgRoot, "package.json"), "utf8"));
|
|
2109
2279
|
return typeof pkg.version === "string" ? pkg.version : "";
|
|
2110
2280
|
} catch {
|
|
2111
2281
|
return "";
|
|
@@ -2139,7 +2309,7 @@ function dueForCheck(file, now) {
|
|
|
2139
2309
|
var ORIGIN_FILE = ".install-origin.json";
|
|
2140
2310
|
function selfUpdatable(runtimeDir) {
|
|
2141
2311
|
try {
|
|
2142
|
-
const origin = JSON.parse(readFileSync7(
|
|
2312
|
+
const origin = JSON.parse(readFileSync7(join12(runtimeDir, ORIGIN_FILE), "utf8"));
|
|
2143
2313
|
if (typeof origin.source !== "string" || !origin.source) return false;
|
|
2144
2314
|
return origin.source.split(/[\\/]/).includes("_npx");
|
|
2145
2315
|
} catch {
|
|
@@ -2148,7 +2318,7 @@ function selfUpdatable(runtimeDir) {
|
|
|
2148
2318
|
}
|
|
2149
2319
|
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
2150
2320
|
function lockFile() {
|
|
2151
|
-
return
|
|
2321
|
+
return join12(tmpdir5(), "hindsight-coding-agent", "auto-update.lock");
|
|
2152
2322
|
}
|
|
2153
2323
|
function acquireUpdateLock(file, now) {
|
|
2154
2324
|
try {
|
|
@@ -2167,8 +2337,8 @@ function acquireUpdateLock(file, now) {
|
|
|
2167
2337
|
} catch {
|
|
2168
2338
|
}
|
|
2169
2339
|
try {
|
|
2170
|
-
|
|
2171
|
-
|
|
2340
|
+
mkdirSync5(dirname9(file), { recursive: true });
|
|
2341
|
+
writeFileSync3(file, JSON.stringify({ pid: process.pid, ts: now }));
|
|
2172
2342
|
return true;
|
|
2173
2343
|
} catch {
|
|
2174
2344
|
return false;
|
|
@@ -2177,19 +2347,19 @@ function acquireUpdateLock(file, now) {
|
|
|
2177
2347
|
function holdLockFor(file, pid, now) {
|
|
2178
2348
|
try {
|
|
2179
2349
|
if (pid === void 0) return releaseUpdateLock(file);
|
|
2180
|
-
|
|
2350
|
+
writeFileSync3(file, JSON.stringify({ pid, ts: now }));
|
|
2181
2351
|
} catch {
|
|
2182
2352
|
}
|
|
2183
2353
|
}
|
|
2184
2354
|
function releaseUpdateLock(file) {
|
|
2185
2355
|
try {
|
|
2186
|
-
|
|
2356
|
+
unlinkSync2(file);
|
|
2187
2357
|
} catch {
|
|
2188
2358
|
}
|
|
2189
2359
|
}
|
|
2190
2360
|
function stampCheck(file, now, latest) {
|
|
2191
2361
|
try {
|
|
2192
|
-
|
|
2362
|
+
writeFileSync3(file, JSON.stringify({ lastCheck: now, latest }));
|
|
2193
2363
|
} catch {
|
|
2194
2364
|
}
|
|
2195
2365
|
}
|
|
@@ -2238,7 +2408,7 @@ async function maybeAutoUpdate(cfg, opts = {}) {
|
|
|
2238
2408
|
return "";
|
|
2239
2409
|
}
|
|
2240
2410
|
log.info("auto-update", `updating the Hindsight runtime ${current2} -> ${latest}`);
|
|
2241
|
-
const child = (opts.spawn ??
|
|
2411
|
+
const child = (opts.spawn ?? realSpawn5)(
|
|
2242
2412
|
"npx",
|
|
2243
2413
|
["-y", `${PACKAGE_NAME}@${latest}`, "update"],
|
|
2244
2414
|
{
|
|
@@ -2266,7 +2436,7 @@ async function maybeAutoUpdate(cfg, opts = {}) {
|
|
|
2266
2436
|
// src/core/skill-sync.ts
|
|
2267
2437
|
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync8 } from "fs";
|
|
2268
2438
|
import { homedir as homedir5 } from "os";
|
|
2269
|
-
import { dirname as dirname10, join as
|
|
2439
|
+
import { dirname as dirname10, join as join13 } from "path";
|
|
2270
2440
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
2271
2441
|
|
|
2272
2442
|
// src/core/skill-dirs.ts
|
|
@@ -2298,17 +2468,17 @@ var SKILL_DIRS = {
|
|
|
2298
2468
|
|
|
2299
2469
|
// src/core/skill-sync.ts
|
|
2300
2470
|
function packagedSkillDir() {
|
|
2301
|
-
return
|
|
2471
|
+
return join13(dirname10(fileURLToPath5(import.meta.url)), "..", "skill");
|
|
2302
2472
|
}
|
|
2303
2473
|
function syncCompanionSkill(harness, opts = {}) {
|
|
2304
2474
|
try {
|
|
2305
2475
|
const parts = SKILL_DIRS[harness];
|
|
2306
2476
|
if (!parts) return;
|
|
2307
2477
|
const src = opts.srcDir ?? packagedSkillDir();
|
|
2308
|
-
const srcMd =
|
|
2478
|
+
const srcMd = join13(src, "SKILL.md");
|
|
2309
2479
|
if (!existsSync5(srcMd)) return;
|
|
2310
|
-
const dst =
|
|
2311
|
-
const dstMd =
|
|
2480
|
+
const dst = join13(opts.home ?? homedir5(), ...parts, "hindsight-coding-agent");
|
|
2481
|
+
const dstMd = join13(dst, "SKILL.md");
|
|
2312
2482
|
if (!existsSync5(dstMd)) return;
|
|
2313
2483
|
if (readFileSync8(srcMd, "utf8") !== readFileSync8(dstMd, "utf8")) {
|
|
2314
2484
|
cpSync(src, dst, { recursive: true });
|
|
@@ -2317,6 +2487,43 @@ function syncCompanionSkill(harness, opts = {}) {
|
|
|
2317
2487
|
}
|
|
2318
2488
|
}
|
|
2319
2489
|
|
|
2490
|
+
// src/core/legacy.ts
|
|
2491
|
+
import { existsSync as existsSync6, readFileSync as readFileSync9 } from "fs";
|
|
2492
|
+
import { homedir as homedir6 } from "os";
|
|
2493
|
+
import { join as join14, relative, isAbsolute as isAbsolute2 } from "path";
|
|
2494
|
+
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
2495
|
+
function detectLegacyClaudePlugin(cwd, claudeDir = join14(homedir6(), ".claude")) {
|
|
2496
|
+
const registry = readJson(join14(claudeDir, "plugins", "installed_plugins.json"));
|
|
2497
|
+
const plugins = registry?.plugins;
|
|
2498
|
+
if (!plugins || typeof plugins !== "object") return void 0;
|
|
2499
|
+
const enabled = readJson(join14(claudeDir, "settings.json"))?.enabledPlugins;
|
|
2500
|
+
for (const [key, raw] of Object.entries(plugins)) {
|
|
2501
|
+
if (key.split("@")[0] !== LEGACY_CLAUDE_PLUGIN) continue;
|
|
2502
|
+
if (enabled && enabled[key] === false) continue;
|
|
2503
|
+
const installs = Array.isArray(raw) ? raw : [raw];
|
|
2504
|
+
const active = installs.some((i) => {
|
|
2505
|
+
if (!i || typeof i !== "object") return false;
|
|
2506
|
+
if (typeof i.projectPath !== "string") return true;
|
|
2507
|
+
const rel = relative(i.projectPath, cwd);
|
|
2508
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
|
|
2509
|
+
});
|
|
2510
|
+
if (active) return key;
|
|
2511
|
+
}
|
|
2512
|
+
return void 0;
|
|
2513
|
+
}
|
|
2514
|
+
function readJson(path) {
|
|
2515
|
+
try {
|
|
2516
|
+
const parsed = JSON.parse(readFileSync9(path, "utf8"));
|
|
2517
|
+
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
2518
|
+
} catch {
|
|
2519
|
+
return void 0;
|
|
2520
|
+
}
|
|
2521
|
+
}
|
|
2522
|
+
function legacyClaudePluginWarning(key) {
|
|
2523
|
+
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.
|
|
2524
|
+
\u21B3 remove it: claude plugin uninstall ${key}`;
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2320
2527
|
// src/core/session-start.ts
|
|
2321
2528
|
function buildSeedBanner(bankId, cold = true, gitNote) {
|
|
2322
2529
|
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 +2604,13 @@ async function buildSessionStartContext(args) {
|
|
|
2397
2604
|
startSeed(cwd, { limit: cfg.seedLimit, harness });
|
|
2398
2605
|
if (docIds.size === 0) {
|
|
2399
2606
|
if (cfg.codebaseSurvey !== false) {
|
|
2400
|
-
startSurvey(cwd, {
|
|
2607
|
+
const started = await startSurvey(cwd, {
|
|
2401
2608
|
harness,
|
|
2402
2609
|
model: cfg.surveyModel,
|
|
2403
2610
|
budgetUsd: cfg.surveyBudgetUsd
|
|
2404
2611
|
});
|
|
2405
2612
|
const sha = resolveHeadSha(cwd);
|
|
2406
|
-
if (sha) recordSurveyBaseline(sha);
|
|
2613
|
+
if (started && sha) recordSurveyBaseline(sha);
|
|
2407
2614
|
}
|
|
2408
2615
|
diag(harness, "seed_started", { bank: bankId });
|
|
2409
2616
|
} else if (cfg.codebaseSurvey !== false && cfg.surveyRefreshCommits > 0) {
|
|
@@ -2420,17 +2627,19 @@ async function buildSessionStartContext(args) {
|
|
|
2420
2627
|
const uploads = await client.listDocumentIds("source:upload", "all_strict").catch(() => /* @__PURE__ */ new Set());
|
|
2421
2628
|
const findingsAbsent = counts.length > 0 && !SURVEY_DOC_IDS.some((id) => uploads.has(id));
|
|
2422
2629
|
if (sinceLast !== null && sinceLast >= cfg.surveyRefreshCommits || findingsAbsent) {
|
|
2423
|
-
startSurvey(cwd, {
|
|
2630
|
+
const started = await startSurvey(cwd, {
|
|
2424
2631
|
harness,
|
|
2425
2632
|
model: cfg.surveyModel,
|
|
2426
2633
|
budgetUsd: cfg.surveyBudgetUsd
|
|
2427
2634
|
});
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2635
|
+
if (started) {
|
|
2636
|
+
recordSurveyBaseline(sha);
|
|
2637
|
+
diag(harness, "survey_refresh", {
|
|
2638
|
+
bank: bankId,
|
|
2639
|
+
commits: sinceLast,
|
|
2640
|
+
retry: findingsAbsent
|
|
2641
|
+
});
|
|
2642
|
+
}
|
|
2434
2643
|
} else if (sinceLast === null) {
|
|
2435
2644
|
recordSurveyBaseline(sha);
|
|
2436
2645
|
}
|
|
@@ -2463,6 +2672,13 @@ async function buildSessionStartContext(args) {
|
|
|
2463
2672
|
}).catch(() => void 0);
|
|
2464
2673
|
}
|
|
2465
2674
|
systemMessage = buildSeedBanner(bankId, cold === true, gitNote);
|
|
2675
|
+
const detectLegacy = args.detectLegacyPlugin ?? (harness === "claude-code" ? detectLegacyClaudePlugin : void 0);
|
|
2676
|
+
const legacyPlugin = detectLegacy?.(cwd);
|
|
2677
|
+
if (legacyPlugin) {
|
|
2678
|
+
systemMessage += `
|
|
2679
|
+
${legacyClaudePluginWarning(legacyPlugin)}`;
|
|
2680
|
+
diag(harness, "legacy_plugin_active", { plugin: legacyPlugin });
|
|
2681
|
+
}
|
|
2466
2682
|
diag(harness, "session_start", { bank: bankId, cold, pages: pages.length, ms: Date.now() - t0 });
|
|
2467
2683
|
return { systemMessage, additionalContext, deferInitialReflect };
|
|
2468
2684
|
}
|
|
@@ -2471,7 +2687,7 @@ async function runSessionStartHook(spec, makeClient = (o) => new HindsightClient
|
|
|
2471
2687
|
try {
|
|
2472
2688
|
let ev = {};
|
|
2473
2689
|
try {
|
|
2474
|
-
ev = JSON.parse(
|
|
2690
|
+
ev = JSON.parse(readFileSync10(0, "utf8"));
|
|
2475
2691
|
} catch {
|
|
2476
2692
|
return;
|
|
2477
2693
|
}
|
|
@@ -2640,19 +2856,19 @@ function readCopilotTranscript(path) {
|
|
|
2640
2856
|
}
|
|
2641
2857
|
|
|
2642
2858
|
// src/core/transcript-grok.ts
|
|
2643
|
-
import { existsSync as
|
|
2644
|
-
import { homedir as
|
|
2645
|
-
import { join as
|
|
2859
|
+
import { existsSync as existsSync7, readFileSync as readFileSync11, readdirSync as readdirSync2 } from "fs";
|
|
2860
|
+
import { homedir as homedir7 } from "os";
|
|
2861
|
+
import { join as join15 } from "path";
|
|
2646
2862
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
2647
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
2648
|
-
const sessionsDir =
|
|
2649
|
-
const direct =
|
|
2650
|
-
if (
|
|
2863
|
+
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join15(homedir7(), ".grok")) {
|
|
2864
|
+
const sessionsDir = join15(grokHome, "sessions");
|
|
2865
|
+
const direct = join15(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
|
|
2866
|
+
if (existsSync7(direct)) return direct;
|
|
2651
2867
|
try {
|
|
2652
|
-
for (const candidate of
|
|
2653
|
-
const directory =
|
|
2654
|
-
if (
|
|
2655
|
-
return
|
|
2868
|
+
for (const candidate of readdirSync2(sessionsDir)) {
|
|
2869
|
+
const directory = join15(sessionsDir, candidate);
|
|
2870
|
+
if (readFileSync11(join15(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
2871
|
+
return join15(directory, sessionId, CHAT_HISTORY);
|
|
2656
2872
|
}
|
|
2657
2873
|
}
|
|
2658
2874
|
} catch {
|
|
@@ -2687,12 +2903,12 @@ function readGrokTranscript(path) {
|
|
|
2687
2903
|
}
|
|
2688
2904
|
|
|
2689
2905
|
// src/core/transcript-devin.ts
|
|
2690
|
-
import { existsSync as
|
|
2906
|
+
import { existsSync as existsSync8 } from "fs";
|
|
2691
2907
|
import { createRequire } from "module";
|
|
2692
|
-
import { homedir as
|
|
2693
|
-
import { join as
|
|
2694
|
-
function devinSessionDb(home =
|
|
2695
|
-
return
|
|
2908
|
+
import { homedir as homedir8 } from "os";
|
|
2909
|
+
import { join as join16 } from "path";
|
|
2910
|
+
function devinSessionDb(home = homedir8()) {
|
|
2911
|
+
return join16(home, ".local", "share", "devin", "cli", "sessions.db");
|
|
2696
2912
|
}
|
|
2697
2913
|
function parseDevinMessages(nodes) {
|
|
2698
2914
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -2729,7 +2945,7 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
|
|
|
2729
2945
|
diag("devin-cli", "sqlite_unavailable", { node: process.version, dbPath });
|
|
2730
2946
|
return [];
|
|
2731
2947
|
}
|
|
2732
|
-
if (!
|
|
2948
|
+
if (!existsSync8(dbPath)) {
|
|
2733
2949
|
diag("devin-cli", "session_db_missing", { dbPath });
|
|
2734
2950
|
return [];
|
|
2735
2951
|
}
|
|
@@ -3002,7 +3218,7 @@ function readDroidTranscript(path) {
|
|
|
3002
3218
|
}
|
|
3003
3219
|
|
|
3004
3220
|
// src/core/transcript-zcode.ts
|
|
3005
|
-
import { readFileSync as
|
|
3221
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
3006
3222
|
function messageText2(content) {
|
|
3007
3223
|
if (typeof content === "string") return content.trim();
|
|
3008
3224
|
if (!Array.isArray(content)) return "";
|
|
@@ -3012,7 +3228,7 @@ function readZcodeTranscript(path) {
|
|
|
3012
3228
|
if (!path) return [];
|
|
3013
3229
|
let body;
|
|
3014
3230
|
try {
|
|
3015
|
-
body =
|
|
3231
|
+
body = readFileSync12(path, "utf8");
|
|
3016
3232
|
} catch {
|
|
3017
3233
|
return [];
|
|
3018
3234
|
}
|