@vectorize-io/hindsight-coding-agents 0.8.2 → 0.8.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/README.md +13 -3
- package/dist/antigravity-hook.js +95 -42
- package/dist/antigravity-statusline.js +6 -6
- package/dist/antigravity-stop-hook.js +132 -51
- package/dist/claude-hook.js +95 -42
- package/dist/claude-sessionstart-hook.js +385 -100
- package/dist/claude-stop-hook.js +132 -51
- package/dist/cline.js +403 -92
- package/dist/codebuddy-hook.js +95 -42
- package/dist/codebuddy-sessionstart-hook.js +385 -100
- package/dist/codebuddy-stop-hook.js +132 -51
- package/dist/codex-hook.js +95 -42
- package/dist/codex-sessionstart-hook.js +385 -100
- package/dist/codex-stop-hook.js +132 -51
- package/dist/copilot-hook.js +95 -42
- package/dist/copilot-sessionstart-hook.js +385 -100
- package/dist/copilot-stop-hook.js +132 -51
- package/dist/cursor-hook.js +95 -42
- package/dist/cursor-sessionstart-hook.js +385 -100
- package/dist/cursor-stop-hook.js +132 -51
- package/dist/daemon-start.js +10 -10
- package/dist/dcode-hook.js +95 -42
- package/dist/dcode-sessionstart-hook.js +385 -100
- package/dist/dcode-stop-hook.js +132 -51
- package/dist/deepen.js +82 -23
- package/dist/devin-hook.js +95 -42
- package/dist/devin-sessionstart-hook.js +385 -100
- package/dist/devin-stop-hook.js +132 -51
- package/dist/droid-hook.js +95 -42
- package/dist/droid-sessionstart-hook.js +385 -100
- package/dist/droid-stop-hook.js +132 -51
- package/dist/dsh.js +422 -99
- package/dist/grok-hook.js +95 -42
- package/dist/grok-sessionstart-hook.js +385 -100
- package/dist/grok-stop-hook.js +132 -51
- package/dist/hindsight-seed.js +6 -6
- package/dist/index.js +427 -111
- package/dist/installer.js +89 -80
- package/dist/kilo.js +427 -111
- package/dist/kimi-hook.js +95 -42
- package/dist/kimi-sessionstart-hook.js +385 -100
- package/dist/kimi-stop-hook.js +132 -51
- package/dist/mcp-server.js +169 -62
- package/dist/opencode2.js +583 -105
- package/dist/pi.js +403 -99
- package/dist/prime-agent.js +403 -99
- package/dist/qwen-hook.js +95 -42
- package/dist/qwen-sessionstart-hook.js +385 -100
- package/dist/qwen-stop-hook.js +132 -51
- package/dist/status.js +67 -17
- package/dist/survey-supervisor.js +73 -9
- package/dist/traecode-hook.js +95 -42
- package/dist/traecode-sessionstart-hook.js +385 -100
- package/dist/traecode-stop-hook.js +132 -51
- package/dist/workbuddy-hook.js +95 -42
- package/dist/workbuddy-sessionstart-hook.js +385 -100
- package/dist/workbuddy-stop-hook.js +132 -51
- package/dist/zcode-hook.js +95 -42
- package/dist/zcode-sessionstart-hook.js +385 -100
- package/dist/zcode-stop-hook.js +132 -51
- package/index.js +4 -1
- package/package.json +7 -4
- package/plugin.json +1 -1
- package/skill/SKILL.md +10 -2
package/dist/kilo.js
CHANGED
|
@@ -228,14 +228,14 @@ function probeGitLayout(directory) {
|
|
|
228
228
|
var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
|
|
229
229
|
function applyTemplate(template, resolvers, what) {
|
|
230
230
|
return template.replace(PLACEHOLDER, (_, name) => {
|
|
231
|
-
const
|
|
232
|
-
if (!
|
|
231
|
+
const resolve4 = resolvers[name];
|
|
232
|
+
if (!resolve4) {
|
|
233
233
|
console.error(
|
|
234
234
|
`hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
|
|
235
235
|
);
|
|
236
236
|
return "unknown";
|
|
237
237
|
}
|
|
238
|
-
return
|
|
238
|
+
return resolve4();
|
|
239
239
|
});
|
|
240
240
|
}
|
|
241
241
|
|
|
@@ -656,29 +656,33 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
|
|
|
656
656
|
}
|
|
657
657
|
|
|
658
658
|
// package.json
|
|
659
|
-
var version = "0.8.
|
|
659
|
+
var version = "0.8.4";
|
|
660
660
|
|
|
661
661
|
// src/core/util.ts
|
|
662
|
-
import { accessSync, constants } from "fs";
|
|
663
|
-
import { delimiter, join as join6 } from "path";
|
|
664
|
-
function binOnPath(bin) {
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
662
|
+
import { accessSync, constants, statSync as statSync2 } from "fs";
|
|
663
|
+
import { delimiter, extname, isAbsolute as isAbsolute2, join as join6, resolve as resolve2 } from "path";
|
|
664
|
+
function binOnPath(bin, opts = {}) {
|
|
665
|
+
const platform = opts.platform ?? process.platform;
|
|
666
|
+
const env = opts.env ?? process.env;
|
|
667
|
+
const runnable = (file3) => {
|
|
668
|
+
try {
|
|
669
|
+
if (!statSync2(file3).isFile()) return false;
|
|
670
|
+
if (platform !== "win32") accessSync(file3, constants.X_OK);
|
|
668
671
|
return true;
|
|
672
|
+
} catch {
|
|
673
|
+
return false;
|
|
669
674
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
675
|
+
};
|
|
676
|
+
if (isAbsolute2(bin) || /[\\/]/.test(bin)) return runnable(bin) ? resolve2(bin) : void 0;
|
|
677
|
+
const names = platform !== "win32" || extname(bin) ? [bin] : (opts.exts ?? (env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";")).filter(Boolean).map((ext) => bin + ext.toLowerCase());
|
|
678
|
+
for (const dir of (env.PATH || "").split(delimiter)) {
|
|
679
|
+
if (!dir) continue;
|
|
680
|
+
for (const name of names) {
|
|
681
|
+
const file3 = join6(dir, name);
|
|
682
|
+
if (runnable(file3)) return resolve2(file3);
|
|
677
683
|
}
|
|
678
|
-
return false;
|
|
679
|
-
} catch {
|
|
680
|
-
return false;
|
|
681
684
|
}
|
|
685
|
+
return void 0;
|
|
682
686
|
}
|
|
683
687
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
684
688
|
function semverGte(version4, min) {
|
|
@@ -948,15 +952,19 @@ var HindsightClient = class {
|
|
|
948
952
|
}
|
|
949
953
|
/**
|
|
950
954
|
* Whether this server honours `operation_id` on an async retain, and can therefore be appended to
|
|
951
|
-
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed
|
|
955
|
+
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed via the version endpoint; anything
|
|
952
956
|
* unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
|
|
957
|
+
* Only a "yes" is cached: a long-lived plugin client would otherwise keep replacing for the rest
|
|
958
|
+
* of the process after one probe that hit a restarting server (#5735).
|
|
953
959
|
*/
|
|
954
960
|
async supportsIdempotentRetain() {
|
|
955
|
-
if (this.idempotentRetain
|
|
956
|
-
|
|
957
|
-
|
|
961
|
+
if (this.idempotentRetain) return true;
|
|
962
|
+
const supported = await this.probeIdempotentRetain();
|
|
963
|
+
if (supported || this.idempotentRetain === void 0) {
|
|
964
|
+
this.log(`server retain idempotency: ${supported ? "supported" : "unavailable"}`);
|
|
958
965
|
}
|
|
959
|
-
|
|
966
|
+
this.idempotentRetain = supported;
|
|
967
|
+
return supported;
|
|
960
968
|
}
|
|
961
969
|
/** `/v1/version` first: an ingress that routes only `/v1` to the API (the Helm chart's default)
|
|
962
970
|
* hands a bare `/version` to the control plane, whose HTML 404 or login redirect read as "no",
|
|
@@ -1990,15 +1998,15 @@ function stagedVersion(pkgRoot) {
|
|
|
1990
1998
|
}
|
|
1991
1999
|
}
|
|
1992
2000
|
function isNewer(candidate, current2) {
|
|
1993
|
-
const
|
|
2001
|
+
const parse6 = (v) => {
|
|
1994
2002
|
const [core = "", ...rest] = v.trim().split("-");
|
|
1995
2003
|
return {
|
|
1996
2004
|
nums: core.split(".").map((n) => Number.parseInt(n, 10)),
|
|
1997
2005
|
pre: rest.length > 0
|
|
1998
2006
|
};
|
|
1999
2007
|
};
|
|
2000
|
-
const a =
|
|
2001
|
-
const b =
|
|
2008
|
+
const a = parse6(candidate);
|
|
2009
|
+
const b = parse6(current2);
|
|
2002
2010
|
if (a.nums.length !== 3 || b.nums.length !== 3) return false;
|
|
2003
2011
|
if (a.nums.some(Number.isNaN) || b.nums.some(Number.isNaN)) return false;
|
|
2004
2012
|
for (let i = 0; i < 3; i++) {
|
|
@@ -2075,7 +2083,7 @@ function spawnNpm(spawnImpl, bin, args, opts) {
|
|
|
2075
2083
|
return process.platform === "win32" ? spawnImpl([bin, ...args].join(" "), { ...opts, shell: true }) : spawnImpl(bin, args, opts);
|
|
2076
2084
|
}
|
|
2077
2085
|
async function npmViewVersion(pkg, spawnImpl = realSpawn2) {
|
|
2078
|
-
return new Promise((
|
|
2086
|
+
return new Promise((resolve4) => {
|
|
2079
2087
|
let out = "";
|
|
2080
2088
|
let settled = false;
|
|
2081
2089
|
let deadline;
|
|
@@ -2084,7 +2092,7 @@ async function npmViewVersion(pkg, spawnImpl = realSpawn2) {
|
|
|
2084
2092
|
settled = true;
|
|
2085
2093
|
if (deadline) clearTimeout(deadline);
|
|
2086
2094
|
if (reason) log.info("auto-update", `version check failed: ${reason}`);
|
|
2087
|
-
|
|
2095
|
+
resolve4(v);
|
|
2088
2096
|
};
|
|
2089
2097
|
try {
|
|
2090
2098
|
const child = spawnNpm(spawnImpl, "npm", ["view", pkg, "version", "--json"], {
|
|
@@ -2101,7 +2109,8 @@ async function npmViewVersion(pkg, spawnImpl = realSpawn2) {
|
|
|
2101
2109
|
child.on("close", (code, signal) => {
|
|
2102
2110
|
if (code !== 0) return done("", `npm view exited ${code ?? signal}`);
|
|
2103
2111
|
try {
|
|
2104
|
-
const
|
|
2112
|
+
const parsed = JSON.parse(out.trim());
|
|
2113
|
+
const v = Array.isArray(parsed) && parsed.length === 1 ? parsed[0] : parsed;
|
|
2105
2114
|
if (typeof v !== "string")
|
|
2106
2115
|
return done("", `unparsable npm output: ${out.trim().slice(0, 80)}`);
|
|
2107
2116
|
if (!RELEASE_RE.test(v)) return done("", `not a release: ${v.slice(0, 40)}`);
|
|
@@ -2281,8 +2290,8 @@ async function waitBounded(p, ms) {
|
|
|
2281
2290
|
try {
|
|
2282
2291
|
await Promise.race([
|
|
2283
2292
|
p,
|
|
2284
|
-
new Promise((
|
|
2285
|
-
timer = setTimeout(
|
|
2293
|
+
new Promise((resolve4) => {
|
|
2294
|
+
timer = setTimeout(resolve4, Math.max(ms, 0));
|
|
2286
2295
|
})
|
|
2287
2296
|
]);
|
|
2288
2297
|
} finally {
|
|
@@ -16927,7 +16936,7 @@ import { execFileSync as execFileSync4 } from "child_process";
|
|
|
16927
16936
|
|
|
16928
16937
|
// src/core/git.ts
|
|
16929
16938
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
16930
|
-
import { resolve as
|
|
16939
|
+
import { resolve as resolve3 } from "path";
|
|
16931
16940
|
|
|
16932
16941
|
// src/core/uuid.ts
|
|
16933
16942
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -16955,18 +16964,25 @@ var US = "";
|
|
|
16955
16964
|
var RS = "";
|
|
16956
16965
|
var GITLOG_HEAD = "gitlog-head:";
|
|
16957
16966
|
var GITLOG_FORMAT = `--format=%h${US}%ad${US}%an${US}%s${US}%b${RS}`;
|
|
16958
|
-
function
|
|
16967
|
+
function runGit(repo, args, env) {
|
|
16959
16968
|
return execFileSync2("git", ["-C", repo, "-c", "log.showSignature=false", ...args], {
|
|
16960
16969
|
encoding: "utf8",
|
|
16961
16970
|
maxBuffer: 1 << 28,
|
|
16962
16971
|
windowsHide: true,
|
|
16972
|
+
env,
|
|
16963
16973
|
// execFileSync otherwise forwards failed git stderr into the host's TUI,
|
|
16964
16974
|
// even when callers catch the error. Keep diagnostics on the error instead.
|
|
16965
16975
|
stdio: ["ignore", "pipe", "pipe"]
|
|
16966
16976
|
});
|
|
16967
16977
|
}
|
|
16978
|
+
function git(repo, ...args) {
|
|
16979
|
+
return runGit(repo, args);
|
|
16980
|
+
}
|
|
16981
|
+
function gitLocal(repo, ...args) {
|
|
16982
|
+
return runGit(repo, args, { ...process.env, GIT_NO_LAZY_FETCH: "1" });
|
|
16983
|
+
}
|
|
16968
16984
|
function repoNameOf(repo) {
|
|
16969
|
-
return projectNameOf(
|
|
16985
|
+
return projectNameOf(resolve3(repo));
|
|
16970
16986
|
}
|
|
16971
16987
|
function gitHeadSha(dir) {
|
|
16972
16988
|
try {
|
|
@@ -16978,7 +16994,7 @@ function gitHeadSha(dir) {
|
|
|
16978
16994
|
function commitsSince(dir, sinceSha) {
|
|
16979
16995
|
if (!/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(sinceSha)) return null;
|
|
16980
16996
|
try {
|
|
16981
|
-
const n = Number.parseInt(
|
|
16997
|
+
const n = Number.parseInt(gitLocal(dir, "rev-list", "--count", `${sinceSha}..HEAD`).trim(), 10);
|
|
16982
16998
|
return Number.isFinite(n) ? n : null;
|
|
16983
16999
|
} catch {
|
|
16984
17000
|
return null;
|
|
@@ -17004,11 +17020,197 @@ async function gitLogIsCurrent(client, repo, head) {
|
|
|
17004
17020
|
// src/core/survey.ts
|
|
17005
17021
|
import { execFileSync as execFileSync3, spawn as realSpawn5 } from "child_process";
|
|
17006
17022
|
import { createHash as createHash3 } from "crypto";
|
|
17007
|
-
import { existsSync as existsSync3 } from "fs";
|
|
17023
|
+
import { existsSync as existsSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
17008
17024
|
import { homedir as homedir5, tmpdir as tmpdir2 } from "os";
|
|
17009
17025
|
import { dirname as dirname7, join as join11 } from "path";
|
|
17010
17026
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
17011
17027
|
|
|
17028
|
+
// node_modules/smol-toml/dist/stringify.js
|
|
17029
|
+
var BARE_KEY = /^[a-z0-9-_]+$/i;
|
|
17030
|
+
var HAS_WELLFORMED = !!"".isWellFormed;
|
|
17031
|
+
function extendedTypeOf(obj) {
|
|
17032
|
+
let type = typeof obj;
|
|
17033
|
+
if (type === "object") {
|
|
17034
|
+
if (Array.isArray(obj))
|
|
17035
|
+
return "array";
|
|
17036
|
+
if (typeof obj.getUTCDate === "function" && obj instanceof Date)
|
|
17037
|
+
return "date";
|
|
17038
|
+
if (globalThis.Temporal) {
|
|
17039
|
+
if (obj.until) {
|
|
17040
|
+
if (obj instanceof Temporal.ZonedDateTime)
|
|
17041
|
+
return "temporal/tz+uc";
|
|
17042
|
+
if (obj instanceof Temporal.PlainDateTime || obj instanceof Temporal.PlainDate)
|
|
17043
|
+
return "temporal/uc";
|
|
17044
|
+
if (obj instanceof Temporal.PlainTime || obj instanceof Temporal.Instant)
|
|
17045
|
+
return "temporal";
|
|
17046
|
+
if (obj instanceof Temporal.PlainYearMonth)
|
|
17047
|
+
return "temporal/x";
|
|
17048
|
+
} else if (obj.toPlainDate && obj instanceof Temporal.PlainMonthDay || obj.negated && obj instanceof Temporal.Duration) {
|
|
17049
|
+
return "temporal/x";
|
|
17050
|
+
}
|
|
17051
|
+
}
|
|
17052
|
+
}
|
|
17053
|
+
return type;
|
|
17054
|
+
}
|
|
17055
|
+
function isArrayOfTables(obj) {
|
|
17056
|
+
for (let i = 0; i < obj.length; i++) {
|
|
17057
|
+
if (extendedTypeOf(obj[i]) !== "object")
|
|
17058
|
+
return false;
|
|
17059
|
+
}
|
|
17060
|
+
return obj.length != 0;
|
|
17061
|
+
}
|
|
17062
|
+
function formatWellFormedStringUnchecked(s) {
|
|
17063
|
+
return JSON.stringify(s).replaceAll("\x7F", "\\u007f");
|
|
17064
|
+
}
|
|
17065
|
+
function formatString(s) {
|
|
17066
|
+
return formatWellFormedStringUnchecked(HAS_WELLFORMED ? s.toWellFormed() : s);
|
|
17067
|
+
}
|
|
17068
|
+
function formatKey(s) {
|
|
17069
|
+
if (BARE_KEY.test(s))
|
|
17070
|
+
return s;
|
|
17071
|
+
if (HAS_WELLFORMED && !s.isWellFormed())
|
|
17072
|
+
throw new RangeError("key contains illegal lone surrogates");
|
|
17073
|
+
return formatWellFormedStringUnchecked(s);
|
|
17074
|
+
}
|
|
17075
|
+
function stringifyValue(val, type, depth, numberAsFloat, strictTemporal) {
|
|
17076
|
+
if (depth === 0) {
|
|
17077
|
+
throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
17078
|
+
}
|
|
17079
|
+
switch (type) {
|
|
17080
|
+
// @ts-expect-error -- intentional fallthrough case
|
|
17081
|
+
case "number":
|
|
17082
|
+
if (isNaN(val))
|
|
17083
|
+
return "nan";
|
|
17084
|
+
if (val === Infinity)
|
|
17085
|
+
return "inf";
|
|
17086
|
+
if (val === -Infinity)
|
|
17087
|
+
return "-inf";
|
|
17088
|
+
if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val)))
|
|
17089
|
+
return val.toFixed(1);
|
|
17090
|
+
case "bigint":
|
|
17091
|
+
case "boolean":
|
|
17092
|
+
case "temporal":
|
|
17093
|
+
return val.toString();
|
|
17094
|
+
case "string":
|
|
17095
|
+
return formatString(val);
|
|
17096
|
+
case "date":
|
|
17097
|
+
if (isNaN(val.getTime()))
|
|
17098
|
+
throw new TypeError("cannot serialize invalid date");
|
|
17099
|
+
return val.toISOString();
|
|
17100
|
+
case "object":
|
|
17101
|
+
return stringifyInlineTable(val, depth, numberAsFloat, strictTemporal);
|
|
17102
|
+
case "array":
|
|
17103
|
+
return stringifyArray(val, depth, numberAsFloat, strictTemporal);
|
|
17104
|
+
// @ts-expect-error -- intentional fallthrough case
|
|
17105
|
+
case "temporal/tz+uc":
|
|
17106
|
+
if (strictTemporal) {
|
|
17107
|
+
let tz = val.timeZoneId;
|
|
17108
|
+
let tzc = tz.charCodeAt(0);
|
|
17109
|
+
if (
|
|
17110
|
+
// Classic offset
|
|
17111
|
+
tzc !== 43 && tzc !== 45 && // Fast pre-check pass; see below for the actually accepted values
|
|
17112
|
+
(tzc !== 85 && tzc !== 71 && tzc !== 90 && tzc !== 69 || // UTC and its aliases; Temporal implementations don't all canonicalise unfortunately
|
|
17113
|
+
tz !== "UTC" && tz !== "UCT" && tz !== "Universal" && tz !== "Zulu" && // GMT is a TZ but it's for all intents and purposes equivalent to UTC. Safe to downgrade.
|
|
17114
|
+
!tz.startsWith("GMT") && tz !== "Greenwich" && // Etc/* are all safe to downgrade to offset (either UTC, GMT, or offset)
|
|
17115
|
+
!tz.startsWith("Etc/"))
|
|
17116
|
+
) {
|
|
17117
|
+
throw new TypeError("Temporal objects with an IANA timezone are not allowed in Temporal strict mode");
|
|
17118
|
+
}
|
|
17119
|
+
}
|
|
17120
|
+
case "temporal/uc":
|
|
17121
|
+
if (strictTemporal && val.calendarId !== "iso8601")
|
|
17122
|
+
throw new TypeError("Temporal objects with a non-default calendar are not allowed in Temporal strict mode");
|
|
17123
|
+
return val.toString({
|
|
17124
|
+
calendarName: "never",
|
|
17125
|
+
timeZoneName: "never"
|
|
17126
|
+
});
|
|
17127
|
+
case "temporal/x":
|
|
17128
|
+
throw new TypeError("Unsupported " + val[Symbol.toStringTag]);
|
|
17129
|
+
}
|
|
17130
|
+
}
|
|
17131
|
+
function stringifyInlineTable(obj, depth, numberAsFloat, strictTemporal) {
|
|
17132
|
+
let keys = Object.keys(obj);
|
|
17133
|
+
if (keys.length === 0)
|
|
17134
|
+
return "{}";
|
|
17135
|
+
let res = "{ ";
|
|
17136
|
+
for (let i = 0; i < keys.length; i++) {
|
|
17137
|
+
let k = keys[i];
|
|
17138
|
+
if (i)
|
|
17139
|
+
res += ", ";
|
|
17140
|
+
res += formatKey(k) + " = " + stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat, strictTemporal);
|
|
17141
|
+
}
|
|
17142
|
+
return res + " }";
|
|
17143
|
+
}
|
|
17144
|
+
function stringifyArray(array3, depth, numberAsFloat, strictTemporal) {
|
|
17145
|
+
if (array3.length === 0)
|
|
17146
|
+
return "[]";
|
|
17147
|
+
let res = "[ ";
|
|
17148
|
+
for (let i = 0; i < array3.length; i++) {
|
|
17149
|
+
if (i)
|
|
17150
|
+
res += ", ";
|
|
17151
|
+
if (array3[i] === null || array3[i] === void 0) {
|
|
17152
|
+
throw new TypeError("arrays cannot contain null or undefined values");
|
|
17153
|
+
}
|
|
17154
|
+
res += stringifyValue(array3[i], extendedTypeOf(array3[i]), depth - 1, numberAsFloat, strictTemporal);
|
|
17155
|
+
}
|
|
17156
|
+
return res + " ]";
|
|
17157
|
+
}
|
|
17158
|
+
function stringifyArrayTable(array3, key, depth, numberAsFloat, strictTemporal) {
|
|
17159
|
+
if (depth === 0) {
|
|
17160
|
+
throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
17161
|
+
}
|
|
17162
|
+
let res = "";
|
|
17163
|
+
for (let i = 0; i < array3.length; i++) {
|
|
17164
|
+
res += `${res && "\n"}[[${key}]]
|
|
17165
|
+
`;
|
|
17166
|
+
res += stringifyTable(0, array3[i], key, depth, numberAsFloat, strictTemporal);
|
|
17167
|
+
}
|
|
17168
|
+
return res;
|
|
17169
|
+
}
|
|
17170
|
+
function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat, strictTemporal) {
|
|
17171
|
+
if (depth === 0) {
|
|
17172
|
+
throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
17173
|
+
}
|
|
17174
|
+
let preamble = "";
|
|
17175
|
+
let tables = "";
|
|
17176
|
+
let keys = Object.keys(obj);
|
|
17177
|
+
for (let i = 0; i < keys.length; i++) {
|
|
17178
|
+
let k = keys[i];
|
|
17179
|
+
if (obj[k] !== null && obj[k] !== void 0) {
|
|
17180
|
+
let type = extendedTypeOf(obj[k]);
|
|
17181
|
+
if (type === "symbol" || type === "function") {
|
|
17182
|
+
throw new TypeError(`cannot serialize values of type '${type}'`);
|
|
17183
|
+
}
|
|
17184
|
+
let key = formatKey(k);
|
|
17185
|
+
if (type === "array" && isArrayOfTables(obj[k])) {
|
|
17186
|
+
tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat, strictTemporal);
|
|
17187
|
+
} else if (type === "object") {
|
|
17188
|
+
let tblKey = prefix ? `${prefix}.${key}` : key;
|
|
17189
|
+
tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat, strictTemporal);
|
|
17190
|
+
} else {
|
|
17191
|
+
preamble += key;
|
|
17192
|
+
preamble += " = ";
|
|
17193
|
+
preamble += stringifyValue(obj[k], type, depth, numberAsFloat, strictTemporal);
|
|
17194
|
+
preamble += "\n";
|
|
17195
|
+
}
|
|
17196
|
+
}
|
|
17197
|
+
}
|
|
17198
|
+
if (tableKey && (preamble || !tables))
|
|
17199
|
+
preamble = preamble ? `[${tableKey}]
|
|
17200
|
+
${preamble}` : `[${tableKey}]`;
|
|
17201
|
+
return preamble && tables ? `${preamble}
|
|
17202
|
+
${tables}` : preamble || tables;
|
|
17203
|
+
}
|
|
17204
|
+
function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false, strictTemporal = false } = {}) {
|
|
17205
|
+
if (extendedTypeOf(obj) !== "object") {
|
|
17206
|
+
throw new TypeError("stringify can only be called with an object");
|
|
17207
|
+
}
|
|
17208
|
+
let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat, strictTemporal);
|
|
17209
|
+
if (str[str.length - 1] !== "\n")
|
|
17210
|
+
return str + "\n";
|
|
17211
|
+
return str;
|
|
17212
|
+
}
|
|
17213
|
+
|
|
17012
17214
|
// src/core/survey-lease.ts
|
|
17013
17215
|
import { spawn as realSpawn4 } from "child_process";
|
|
17014
17216
|
import { randomUUID } from "crypto";
|
|
@@ -17019,7 +17221,7 @@ import {
|
|
|
17019
17221
|
renameSync as renameSync2,
|
|
17020
17222
|
rmdirSync,
|
|
17021
17223
|
rmSync,
|
|
17022
|
-
statSync as
|
|
17224
|
+
statSync as statSync3,
|
|
17023
17225
|
unlinkSync as unlinkSync2,
|
|
17024
17226
|
utimesSync,
|
|
17025
17227
|
writeFileSync as writeFileSync2
|
|
@@ -17056,7 +17258,7 @@ function reclaimIfStale(directory, staleMs) {
|
|
|
17056
17258
|
return true;
|
|
17057
17259
|
}
|
|
17058
17260
|
if (owners.length !== 1) return false;
|
|
17059
|
-
const age = Date.now() -
|
|
17261
|
+
const age = Date.now() - statSync3(join10(directory, owners[0])).mtimeMs;
|
|
17060
17262
|
if (Math.abs(age) <= staleMs) return false;
|
|
17061
17263
|
releaseLease({ directory, owner: owners[0] });
|
|
17062
17264
|
return true;
|
|
@@ -17130,7 +17332,7 @@ function opencodeCanDefineSurveyAgent(bin) {
|
|
|
17130
17332
|
windowsHide: true,
|
|
17131
17333
|
stdio: ["ignore", "pipe", "ignore"]
|
|
17132
17334
|
});
|
|
17133
|
-
return Number(/(\d+)\./.exec(out)?.[1] ?? 0)
|
|
17335
|
+
return Number(/(\d+)\./.exec(out)?.[1] ?? 0) === 1;
|
|
17134
17336
|
} catch {
|
|
17135
17337
|
return false;
|
|
17136
17338
|
}
|
|
@@ -17145,6 +17347,7 @@ var SURVEY_DISALLOWED_TOOLS = [
|
|
|
17145
17347
|
"WebSearch",
|
|
17146
17348
|
"Task"
|
|
17147
17349
|
];
|
|
17350
|
+
var tomlValue = (value) => stringify({ v: value }).slice("v = ".length).trim();
|
|
17148
17351
|
function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
17149
17352
|
const env = {
|
|
17150
17353
|
...process.env,
|
|
@@ -17203,9 +17406,9 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
17203
17406
|
"-c",
|
|
17204
17407
|
`mcp_servers.hindsight.command="node"`,
|
|
17205
17408
|
"-c",
|
|
17206
|
-
`mcp_servers.hindsight.args
|
|
17409
|
+
`mcp_servers.hindsight.args=${tomlValue([opts.mcpServerPath])}`,
|
|
17207
17410
|
"-c",
|
|
17208
|
-
`mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD
|
|
17411
|
+
`mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD=${tomlValue(repoDir)}`,
|
|
17209
17412
|
"-c",
|
|
17210
17413
|
`mcp_servers.hindsight.env.HINDSIGHT_MCP_HARNESS="codex"`,
|
|
17211
17414
|
SURVEY_PROMPT
|
|
@@ -17229,10 +17432,19 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
17229
17432
|
}
|
|
17230
17433
|
}
|
|
17231
17434
|
}
|
|
17435
|
+
var SURVEY_MAX_ATTEMPTS = 3;
|
|
17436
|
+
function surveyAttempts(file3, sha) {
|
|
17437
|
+
try {
|
|
17438
|
+
const state = JSON.parse(readFileSync5(file3, "utf8"));
|
|
17439
|
+
return state.sha === sha && typeof state.attempts === "number" ? state.attempts : 0;
|
|
17440
|
+
} catch {
|
|
17441
|
+
return 0;
|
|
17442
|
+
}
|
|
17443
|
+
}
|
|
17232
17444
|
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
17233
17445
|
try {
|
|
17234
17446
|
const spawnFn = opts.spawn ?? realSpawn5;
|
|
17235
|
-
const
|
|
17447
|
+
const resolveBin = opts.resolveBin ?? ((bin) => binOnPath(bin, { exts: [".exe"] }));
|
|
17236
17448
|
const mcpServerPath = opts.mcpServerPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
17237
17449
|
const preferred = opts.harness ?? "claude-code";
|
|
17238
17450
|
const order = [
|
|
@@ -17246,10 +17458,16 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17246
17458
|
for (const harness of order) {
|
|
17247
17459
|
if (seen.has(harness)) continue;
|
|
17248
17460
|
seen.add(harness);
|
|
17249
|
-
const
|
|
17250
|
-
|
|
17251
|
-
if (
|
|
17461
|
+
const name = resolveAgentBin(harness, opts.claudeBin);
|
|
17462
|
+
const bin = resolveBin(name);
|
|
17463
|
+
if (!bin) {
|
|
17464
|
+
log.info("survey", `${harness}: ${name} not found, trying the next agent`);
|
|
17252
17465
|
continue;
|
|
17466
|
+
}
|
|
17467
|
+
if (harness === "opencode" && !(opts.opencodeDefinesAgent ?? opencodeCanDefineSurveyAgent)(bin)) {
|
|
17468
|
+
log.info("survey", `${harness}: ${bin} cannot define the survey agent, trying the next`);
|
|
17469
|
+
continue;
|
|
17470
|
+
}
|
|
17253
17471
|
const plan = buildSurveyPlan(harness, bin, repoDir, {
|
|
17254
17472
|
model: opts.model,
|
|
17255
17473
|
budgetUsd: opts.budgetUsd,
|
|
@@ -17258,12 +17476,19 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17258
17476
|
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
17259
17477
|
if (cfg.disabled) return false;
|
|
17260
17478
|
const key = createHash3("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
17261
|
-
const
|
|
17262
|
-
|
|
17263
|
-
key,
|
|
17264
|
-
opts.lease?.staleMs ?? LEASE_STALE_MS
|
|
17265
|
-
);
|
|
17479
|
+
const leaseDir = opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys");
|
|
17480
|
+
const lease = acquireLease(leaseDir, key, opts.lease?.staleMs ?? LEASE_STALE_MS);
|
|
17266
17481
|
if (!lease) return false;
|
|
17482
|
+
const attemptsFile = join11(
|
|
17483
|
+
leaseDir,
|
|
17484
|
+
`attempts-${createHash3("sha256").update(JSON.stringify([key, repoDir])).digest("hex")}.json`
|
|
17485
|
+
);
|
|
17486
|
+
const attempts = opts.sha ? surveyAttempts(attemptsFile, opts.sha) : 0;
|
|
17487
|
+
if (attempts >= SURVEY_MAX_ATTEMPTS) {
|
|
17488
|
+
log.info("survey", `${attempts} surveys already launched at ${opts.sha}, skipping`);
|
|
17489
|
+
releaseLease(lease);
|
|
17490
|
+
return false;
|
|
17491
|
+
}
|
|
17267
17492
|
const spec = {
|
|
17268
17493
|
lease,
|
|
17269
17494
|
bin: plan.bin,
|
|
@@ -17271,7 +17496,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17271
17496
|
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
17272
17497
|
};
|
|
17273
17498
|
const supervisorPath = opts.supervisorPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
17274
|
-
return await new Promise((
|
|
17499
|
+
return await new Promise((resolve4) => {
|
|
17275
17500
|
try {
|
|
17276
17501
|
const child = spawnFn("node", [supervisorPath], {
|
|
17277
17502
|
cwd: repoDir,
|
|
@@ -17281,19 +17506,31 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17281
17506
|
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
17282
17507
|
});
|
|
17283
17508
|
let spawned = false;
|
|
17284
|
-
child.on("error", () => {
|
|
17509
|
+
child.on("error", (e) => {
|
|
17285
17510
|
if (spawned) return;
|
|
17511
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17286
17512
|
releaseLease(lease);
|
|
17287
|
-
|
|
17513
|
+
resolve4(false);
|
|
17288
17514
|
});
|
|
17289
17515
|
child.once("spawn", () => {
|
|
17290
17516
|
spawned = true;
|
|
17291
17517
|
child.unref();
|
|
17292
|
-
|
|
17518
|
+
if (opts.sha) {
|
|
17519
|
+
try {
|
|
17520
|
+
writeFileSync3(
|
|
17521
|
+
attemptsFile,
|
|
17522
|
+
JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
|
|
17523
|
+
{ mode: 384 }
|
|
17524
|
+
);
|
|
17525
|
+
} catch {
|
|
17526
|
+
}
|
|
17527
|
+
}
|
|
17528
|
+
resolve4(true);
|
|
17293
17529
|
});
|
|
17294
|
-
} catch {
|
|
17530
|
+
} catch (e) {
|
|
17531
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17295
17532
|
releaseLease(lease);
|
|
17296
|
-
|
|
17533
|
+
resolve4(false);
|
|
17297
17534
|
}
|
|
17298
17535
|
});
|
|
17299
17536
|
}
|
|
@@ -17571,6 +17808,18 @@ function pendingReplayable(cursor, now) {
|
|
|
17571
17808
|
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
17572
17809
|
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
17573
17810
|
}
|
|
17811
|
+
function advanceSegments(cursor, bank) {
|
|
17812
|
+
if (!cursor || cursor.bank === bank) return cursor?.segments;
|
|
17813
|
+
return [...cursor.segments ?? [{ bank: cursor.bank, from: 0 }], { bank, from: cursor.turns }];
|
|
17814
|
+
}
|
|
17815
|
+
function bankTurns(turns, segments, bank) {
|
|
17816
|
+
if (!segments) return turns;
|
|
17817
|
+
return turns.filter((_, i) => {
|
|
17818
|
+
let owner;
|
|
17819
|
+
for (const s of segments) if (s.from <= i) owner = s.bank;
|
|
17820
|
+
return owner === bank;
|
|
17821
|
+
});
|
|
17822
|
+
}
|
|
17574
17823
|
var MAX_CURSOR_OPS = 8;
|
|
17575
17824
|
function fingerprintTurns(turns, count) {
|
|
17576
17825
|
const h = createHash5("sha1").update(String(count));
|
|
@@ -17581,7 +17830,8 @@ function planRetain(turns, cursor, opts) {
|
|
|
17581
17830
|
if (!turns.length) return { mode: "skip" };
|
|
17582
17831
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
17583
17832
|
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
17584
|
-
if (cursor.bank !== opts.bank)
|
|
17833
|
+
if (cursor.bank !== opts.bank && !cursor.segments?.some((s) => s.bank === opts.bank))
|
|
17834
|
+
return { mode: "replace" };
|
|
17585
17835
|
const seen = cursor.paths ?? [];
|
|
17586
17836
|
const newFile = Boolean(opts.path && seen.length && !seen.includes(opts.path));
|
|
17587
17837
|
const continues = cursor.turns <= turns.length && fingerprintTurns(turns, cursor.turns) === cursor.fingerprint;
|
|
@@ -17702,8 +17952,17 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
|
|
|
17702
17952
|
let cursor = cursors?.read(sessionId);
|
|
17703
17953
|
const probed = Boolean(cursors) && cursor?.appendSupported !== true;
|
|
17704
17954
|
const appendSupported = Boolean(cursors) && (cursor?.appendSupported === true || await supportsAppend(client));
|
|
17955
|
+
const moved = Boolean(cursor && cursor.bank !== client.bank);
|
|
17956
|
+
if (moved)
|
|
17957
|
+
log.warn(harness ?? "", "session moved to another bank mid-session", {
|
|
17958
|
+
session: sessionId,
|
|
17959
|
+
from: cursor?.bank,
|
|
17960
|
+
to: client.bank,
|
|
17961
|
+
atTurn: cursor?.turns
|
|
17962
|
+
});
|
|
17963
|
+
const segments = advanceSegments(cursor, client.bank);
|
|
17705
17964
|
let ops = [];
|
|
17706
|
-
if (appendSupported && cursor?.ops?.length && !cursor.dirty)
|
|
17965
|
+
if (appendSupported && cursor?.ops?.length && !cursor.dirty && !moved)
|
|
17707
17966
|
({ cursor, ops } = await settleOps(client, cursor));
|
|
17708
17967
|
const plan = planRetain(turns, cursor, {
|
|
17709
17968
|
appendSupported,
|
|
@@ -17712,7 +17971,7 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
|
|
|
17712
17971
|
});
|
|
17713
17972
|
if (probed) diag(harness ?? "", "retain_mode", { mode: plan.mode, appendSupported });
|
|
17714
17973
|
const paths = plan.mode === "replace" ? transcriptPath ? [transcriptPath] : void 0 : advancePaths(cursor?.paths, transcriptPath);
|
|
17715
|
-
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
17974
|
+
const outbox = plan.mode === "replace" || moved ? [] : cursor?.pending ?? [];
|
|
17716
17975
|
if (plan.mode === "skip" && !outbox.length) return;
|
|
17717
17976
|
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
17718
17977
|
${refId}
|
|
@@ -17754,6 +18013,7 @@ ${content}`);
|
|
|
17754
18013
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
17755
18014
|
bank: client.bank,
|
|
17756
18015
|
...paths ? { paths } : {},
|
|
18016
|
+
...segments ? { segments } : {},
|
|
17757
18017
|
...appendSupported ? { appendSupported: true } : {}
|
|
17758
18018
|
};
|
|
17759
18019
|
const accepted = (id) => {
|
|
@@ -17766,9 +18026,14 @@ ${content}`);
|
|
|
17766
18026
|
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
17767
18027
|
};
|
|
17768
18028
|
if (plan.mode === "replace") {
|
|
17769
|
-
const
|
|
18029
|
+
const share = bankTurns(turns, segments, client.bank);
|
|
18030
|
+
if (!share.length) return;
|
|
18031
|
+
const content = renderSessionJsonl(refId, share, startTs);
|
|
18032
|
+
const base = cursor ? `${cursor.turns}
|
|
18033
|
+
${cursor.fingerprint}` : "";
|
|
17770
18034
|
cursors?.write(sessionId, { ...next, dirty: true });
|
|
17771
|
-
const operationId = opId("replace",
|
|
18035
|
+
const operationId = opId("replace", `${base}
|
|
18036
|
+
${content}`);
|
|
17772
18037
|
await submitWithRetry(() => submit(content, operationId, false), stillOurs, retryUntil);
|
|
17773
18038
|
ops = [];
|
|
17774
18039
|
cursors?.write(sessionId, accepted(operationId));
|
|
@@ -17795,7 +18060,7 @@ ${content}`);
|
|
|
17795
18060
|
}
|
|
17796
18061
|
|
|
17797
18062
|
// src/core/usage.ts
|
|
17798
|
-
import { readFileSync as
|
|
18063
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
17799
18064
|
import { join as join13 } from "path";
|
|
17800
18065
|
function usageFilePath() {
|
|
17801
18066
|
return process.env.HINDSIGHT_USAGE_FILE || join13(logsDir(), "usage.jsonl");
|
|
@@ -17878,12 +18143,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17878
18143
|
const base = resolversFor(ctx);
|
|
17879
18144
|
const cache = /* @__PURE__ */ new Map();
|
|
17880
18145
|
const resolvers = Object.fromEntries(
|
|
17881
|
-
Object.entries(base).map(([name,
|
|
18146
|
+
Object.entries(base).map(([name, resolve4]) => [
|
|
17882
18147
|
name,
|
|
17883
18148
|
() => {
|
|
17884
18149
|
const hit = cache.get(name);
|
|
17885
18150
|
if (hit !== void 0) return hit;
|
|
17886
|
-
const value =
|
|
18151
|
+
const value = resolve4();
|
|
17887
18152
|
cache.set(name, value);
|
|
17888
18153
|
return value;
|
|
17889
18154
|
}
|
|
@@ -17903,7 +18168,7 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17903
18168
|
}
|
|
17904
18169
|
|
|
17905
18170
|
// src/core/skill-sync.ts
|
|
17906
|
-
import { cpSync, existsSync as existsSync6, readFileSync as
|
|
18171
|
+
import { cpSync, existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
17907
18172
|
import { homedir as homedir7 } from "os";
|
|
17908
18173
|
import { dirname as dirname8, join as join15 } from "path";
|
|
17909
18174
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
@@ -17978,7 +18243,7 @@ function syncCompanionSkill(harness, opts = {}) {
|
|
|
17978
18243
|
const dstMd = join15(dst, "SKILL.md");
|
|
17979
18244
|
const installed = existsSync6(dstMd);
|
|
17980
18245
|
if (!installed && !opts.install) return;
|
|
17981
|
-
if (!installed ||
|
|
18246
|
+
if (!installed || readFileSync7(srcMd, "utf8") !== readFileSync7(dstMd, "utf8")) {
|
|
17982
18247
|
cpSync(src, dst, { recursive: true });
|
|
17983
18248
|
}
|
|
17984
18249
|
} catch {
|
|
@@ -18000,9 +18265,9 @@ function brandWord() {
|
|
|
18000
18265
|
}
|
|
18001
18266
|
|
|
18002
18267
|
// src/core/legacy.ts
|
|
18003
|
-
import { existsSync as existsSync7, readFileSync as
|
|
18268
|
+
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "fs";
|
|
18004
18269
|
import { homedir as homedir8 } from "os";
|
|
18005
|
-
import { join as join16, relative, isAbsolute as
|
|
18270
|
+
import { join as join16, relative, isAbsolute as isAbsolute3 } from "path";
|
|
18006
18271
|
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
18007
18272
|
function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")) {
|
|
18008
18273
|
const registry3 = readJson(join16(claudeDir, "plugins", "installed_plugins.json"));
|
|
@@ -18017,7 +18282,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
|
|
|
18017
18282
|
if (!i || typeof i !== "object") return false;
|
|
18018
18283
|
if (typeof i.projectPath !== "string") return true;
|
|
18019
18284
|
const rel = relative(i.projectPath, cwd);
|
|
18020
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
18285
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
18021
18286
|
});
|
|
18022
18287
|
if (active) return key;
|
|
18023
18288
|
}
|
|
@@ -18025,7 +18290,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
|
|
|
18025
18290
|
}
|
|
18026
18291
|
function readJson(path) {
|
|
18027
18292
|
try {
|
|
18028
|
-
const parsed = JSON.parse(
|
|
18293
|
+
const parsed = JSON.parse(readFileSync8(path, "utf8"));
|
|
18029
18294
|
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
18030
18295
|
} catch {
|
|
18031
18296
|
return void 0;
|
|
@@ -18037,7 +18302,7 @@ function legacyClaudePluginWarning(key) {
|
|
|
18037
18302
|
}
|
|
18038
18303
|
|
|
18039
18304
|
// src/core/session-cache.ts
|
|
18040
|
-
import { mkdirSync as mkdirSync4, readFileSync as
|
|
18305
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
18041
18306
|
import { tmpdir as tmpdir3 } from "os";
|
|
18042
18307
|
import { dirname as dirname9, join as join17 } from "path";
|
|
18043
18308
|
function sessionCacheFile(harness, sessionId) {
|
|
@@ -18045,7 +18310,7 @@ function sessionCacheFile(harness, sessionId) {
|
|
|
18045
18310
|
}
|
|
18046
18311
|
function readSessionCache(cacheFile) {
|
|
18047
18312
|
try {
|
|
18048
|
-
return JSON.parse(
|
|
18313
|
+
return JSON.parse(readFileSync9(cacheFile, "utf8"));
|
|
18049
18314
|
} catch {
|
|
18050
18315
|
return {};
|
|
18051
18316
|
}
|
|
@@ -18054,7 +18319,7 @@ function writeFileAtomic(path, body) {
|
|
|
18054
18319
|
mkdirSync4(dirname9(path), { recursive: true });
|
|
18055
18320
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
18056
18321
|
try {
|
|
18057
|
-
|
|
18322
|
+
writeFileSync4(tmp, body);
|
|
18058
18323
|
renameSync3(tmp, path);
|
|
18059
18324
|
} catch (e) {
|
|
18060
18325
|
try {
|
|
@@ -18164,12 +18429,13 @@ async function buildSessionStartContext(args) {
|
|
|
18164
18429
|
startSeed(cwd, { limit: cfg.seedLimit, harness });
|
|
18165
18430
|
if (cold) {
|
|
18166
18431
|
if (cfg.codebaseSurvey !== false) {
|
|
18432
|
+
const sha = resolveHeadSha(cwd);
|
|
18167
18433
|
const started = await startSurvey(cwd, {
|
|
18168
18434
|
harness,
|
|
18169
18435
|
model: cfg.surveyModel,
|
|
18170
|
-
budgetUsd: cfg.surveyBudgetUsd
|
|
18436
|
+
budgetUsd: cfg.surveyBudgetUsd,
|
|
18437
|
+
sha: sha ?? void 0
|
|
18171
18438
|
});
|
|
18172
|
-
const sha = resolveHeadSha(cwd);
|
|
18173
18439
|
if (started && sha) recordSurveyBaseline(sha);
|
|
18174
18440
|
}
|
|
18175
18441
|
diag(harness, "seed_started", { bank: bankId });
|
|
@@ -18190,7 +18456,8 @@ async function buildSessionStartContext(args) {
|
|
|
18190
18456
|
const started = await startSurvey(cwd, {
|
|
18191
18457
|
harness,
|
|
18192
18458
|
model: cfg.surveyModel,
|
|
18193
|
-
budgetUsd: cfg.surveyBudgetUsd
|
|
18459
|
+
budgetUsd: cfg.surveyBudgetUsd,
|
|
18460
|
+
sha
|
|
18194
18461
|
});
|
|
18195
18462
|
if (started) {
|
|
18196
18463
|
recordSurveyBaseline(sha);
|
|
@@ -18292,7 +18559,7 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
18292
18559
|
}
|
|
18293
18560
|
|
|
18294
18561
|
// src/core/turn-journal.ts
|
|
18295
|
-
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as
|
|
18562
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync10, statSync as statSync4 } from "fs";
|
|
18296
18563
|
import { tmpdir as tmpdir4 } from "os";
|
|
18297
18564
|
import { dirname as dirname10, join as join18 } from "path";
|
|
18298
18565
|
|
|
@@ -18543,8 +18810,6 @@ var RuntimeCore = class {
|
|
|
18543
18810
|
fetchTranscript;
|
|
18544
18811
|
/** Write-backs started and not yet settled — what `flush` waits for. */
|
|
18545
18812
|
inFlight = /* @__PURE__ */ new Set();
|
|
18546
|
-
lastInjection = "";
|
|
18547
|
-
// most recent turn's injection block, keyed by nothing (see getInjection)
|
|
18548
18813
|
deferInitialReflect = false;
|
|
18549
18814
|
/** Host-notice channel (opencode/Kilo: client.tui.showToast via the adapter). Optional, fail-open. */
|
|
18550
18815
|
notify;
|
|
@@ -18616,7 +18881,11 @@ var RuntimeCore = class {
|
|
|
18616
18881
|
*/
|
|
18617
18882
|
async onPrompt(sessionId, prompt) {
|
|
18618
18883
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
18619
|
-
if (!sessionId
|
|
18884
|
+
if (!sessionId) return;
|
|
18885
|
+
if (!prompt.trim()) {
|
|
18886
|
+
this.injection.delete(sessionId);
|
|
18887
|
+
return;
|
|
18888
|
+
}
|
|
18620
18889
|
const turns = (this.turnCount.get(sessionId) ?? 0) + 1;
|
|
18621
18890
|
this.turnCount.set(sessionId, turns);
|
|
18622
18891
|
const cacheFile = sessionCacheFile(this.harness, sessionId);
|
|
@@ -18648,18 +18917,21 @@ var RuntimeCore = class {
|
|
|
18648
18917
|
}
|
|
18649
18918
|
const block = blocks.filter(Boolean).join("\n\n");
|
|
18650
18919
|
this.injection.set(sessionId, block);
|
|
18651
|
-
this.lastInjection = block;
|
|
18652
18920
|
}
|
|
18653
18921
|
/**
|
|
18654
|
-
* The
|
|
18655
|
-
*
|
|
18656
|
-
*
|
|
18657
|
-
* turn
|
|
18658
|
-
*
|
|
18922
|
+
* The text to inject into this turn's user message (built by the preceding onPrompt), or
|
|
18923
|
+
* undefined.
|
|
18924
|
+
*
|
|
18925
|
+
* It goes into the USER turn on every host, never the system prompt (#5914). The block changes
|
|
18926
|
+
* from turn to turn — the recall runs once, the roster refresh on a cadence — so a system prompt
|
|
18927
|
+
* carrying it differed between requests and broke the provider's prefix cache from that point
|
|
18928
|
+
* on. Persisted in the turn it belongs to, it leaves the system prompt and the earlier history
|
|
18929
|
+
* byte-identical. That used to need a fallback to the most recent block for opencode's
|
|
18930
|
+
* `experimental.chat.system.transform`, which fired with no session id; nothing reads it that
|
|
18931
|
+
* way any more.
|
|
18659
18932
|
*/
|
|
18660
18933
|
getInjection(sessionId) {
|
|
18661
|
-
|
|
18662
|
-
return keyed ?? this.lastInjection ?? void 0;
|
|
18934
|
+
return this.injection.get(sessionId) || void 0;
|
|
18663
18935
|
}
|
|
18664
18936
|
/**
|
|
18665
18937
|
* Full normalized transcript (rich: user/assistant text + tool calls/outputs): upsert every turn
|
|
@@ -18988,7 +19260,7 @@ __export(external_exports2, {
|
|
|
18988
19260
|
object: () => object2,
|
|
18989
19261
|
optional: () => optional2,
|
|
18990
19262
|
overwrite: () => _overwrite2,
|
|
18991
|
-
parse: () =>
|
|
19263
|
+
parse: () => parse5,
|
|
18992
19264
|
parseAsync: () => parseAsync4,
|
|
18993
19265
|
partialRecord: () => partialRecord2,
|
|
18994
19266
|
pipe: () => pipe2,
|
|
@@ -19292,7 +19564,7 @@ __export(core_exports4, {
|
|
|
19292
19564
|
isValidBase64URL: () => isValidBase64URL2,
|
|
19293
19565
|
isValidJWT: () => isValidJWT2,
|
|
19294
19566
|
locales: () => locales_exports2,
|
|
19295
|
-
parse: () =>
|
|
19567
|
+
parse: () => parse4,
|
|
19296
19568
|
parseAsync: () => parseAsync3,
|
|
19297
19569
|
prettifyError: () => prettifyError2,
|
|
19298
19570
|
regexes: () => regexes_exports2,
|
|
@@ -20166,7 +20438,7 @@ var _parse2 = (_Err) => (schema, value, _ctx, _params) => {
|
|
|
20166
20438
|
}
|
|
20167
20439
|
return result.value;
|
|
20168
20440
|
};
|
|
20169
|
-
var
|
|
20441
|
+
var parse4 = /* @__PURE__ */ _parse2($ZodRealError2);
|
|
20170
20442
|
var _parseAsync2 = (_Err) => async (schema, value, _ctx, params) => {
|
|
20171
20443
|
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
20172
20444
|
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
@@ -22689,10 +22961,10 @@ var $ZodFunction2 = /* @__PURE__ */ $constructor2("$ZodFunction", (inst, def) =>
|
|
|
22689
22961
|
throw new Error("implement() must be called with a function");
|
|
22690
22962
|
}
|
|
22691
22963
|
return function(...args) {
|
|
22692
|
-
const parsedArgs = inst._def.input ?
|
|
22964
|
+
const parsedArgs = inst._def.input ? parse4(inst._def.input, args) : args;
|
|
22693
22965
|
const result = Reflect.apply(func, this, parsedArgs);
|
|
22694
22966
|
if (inst._def.output) {
|
|
22695
|
-
return
|
|
22967
|
+
return parse4(inst._def.output, result);
|
|
22696
22968
|
}
|
|
22697
22969
|
return result;
|
|
22698
22970
|
};
|
|
@@ -30184,7 +30456,7 @@ var ZodRealError2 = $constructor2("ZodError", initializer4, {
|
|
|
30184
30456
|
});
|
|
30185
30457
|
|
|
30186
30458
|
// node_modules/@opencode-ai/plugin/node_modules/zod/v4/classic/parse.js
|
|
30187
|
-
var
|
|
30459
|
+
var parse5 = /* @__PURE__ */ _parse2(ZodRealError2);
|
|
30188
30460
|
var parseAsync4 = /* @__PURE__ */ _parseAsync2(ZodRealError2);
|
|
30189
30461
|
var safeParse4 = /* @__PURE__ */ _safeParse2(ZodRealError2);
|
|
30190
30462
|
var safeParseAsync4 = /* @__PURE__ */ _safeParseAsync2(ZodRealError2);
|
|
@@ -30221,7 +30493,7 @@ var ZodType2 = /* @__PURE__ */ $constructor2("ZodType", (inst, def) => {
|
|
|
30221
30493
|
reg.add(inst, meta3);
|
|
30222
30494
|
return inst;
|
|
30223
30495
|
});
|
|
30224
|
-
inst.parse = (data, params) =>
|
|
30496
|
+
inst.parse = (data, params) => parse5(inst, data, params, { callee: inst.parse });
|
|
30225
30497
|
inst.safeParse = (data, params) => safeParse4(inst, data, params);
|
|
30226
30498
|
inst.parseAsync = async (data, params) => parseAsync4(inst, data, params, { callee: inst.parseAsync });
|
|
30227
30499
|
inst.safeParseAsync = async (data, params) => safeParseAsync4(inst, data, params);
|
|
@@ -31239,12 +31511,12 @@ function tool(input) {
|
|
|
31239
31511
|
tool.schema = external_exports2;
|
|
31240
31512
|
|
|
31241
31513
|
// src/harness/registry.ts
|
|
31242
|
-
import { readFileSync as
|
|
31514
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
31243
31515
|
var jsonChatReader = (harness) => ({
|
|
31244
31516
|
describe: `${harness} sessions via a normalized JSON export (--conversations file: [{ id, turns:[{role,text,timestamp?}] }])`,
|
|
31245
31517
|
async read(opts) {
|
|
31246
31518
|
if (!opts.conversations) return [];
|
|
31247
|
-
return JSON.parse(
|
|
31519
|
+
return JSON.parse(readFileSync11(opts.conversations, "utf8"));
|
|
31248
31520
|
}
|
|
31249
31521
|
});
|
|
31250
31522
|
|
|
@@ -31277,21 +31549,26 @@ function createRuntime(core) {
|
|
|
31277
31549
|
return {
|
|
31278
31550
|
...surveyAgentHook,
|
|
31279
31551
|
tool: tools,
|
|
31280
|
-
// Each user turn: recall on the prompt
|
|
31552
|
+
// Each user turn: recall on the prompt, then add this turn's injection (recalled memories +
|
|
31553
|
+
// attribution/user-feedback framing, plus the knowledge preamble on turn 1 and the roster
|
|
31554
|
+
// refresh on cadence) to the user message as a synthetic text part. The host saves the parts
|
|
31555
|
+
// this hook leaves behind, so the block stays in the turn it was made for and every later
|
|
31556
|
+
// request repeats it byte for byte. It used to be pushed into the system prompt through
|
|
31557
|
+
// `experimental.chat.system.transform`, which made the system prompt change between turns
|
|
31558
|
+
// and broke the provider's prefix cache (#5914).
|
|
31281
31559
|
"chat.message": async (input, output) => {
|
|
31282
31560
|
await core.onPrompt(input.sessionID, textOf(output.parts));
|
|
31283
|
-
},
|
|
31284
|
-
// Push this turn's injection (recalled memories + attribution/user-feedback framing, plus the
|
|
31285
|
-
// knowledge preamble on turn 1 and the roster refresh on cadence) into the system prompt every
|
|
31286
|
-
// turn. opencode fires this hook with NO sessionId (input is just `{model}`), so getInjection
|
|
31287
|
-
// falls back to the most recent turn's block (see RuntimeCore.getInjection).
|
|
31288
|
-
"experimental.chat.system.transform": async (input, output) => {
|
|
31289
31561
|
const inj = core.getInjection(input.sessionID);
|
|
31290
|
-
if (inj)
|
|
31291
|
-
|
|
31292
|
-
|
|
31293
|
-
|
|
31294
|
-
|
|
31562
|
+
if (inj)
|
|
31563
|
+
output.parts.unshift({
|
|
31564
|
+
id: `prt-hindsight-${output.message.id}`,
|
|
31565
|
+
sessionID: input.sessionID,
|
|
31566
|
+
messageID: output.message.id,
|
|
31567
|
+
type: "text",
|
|
31568
|
+
text: inj,
|
|
31569
|
+
synthetic: true
|
|
31570
|
+
});
|
|
31571
|
+
diag(core.harness, inj ? "inject_ok" : "inject_empty", { chars: inj?.length ?? 0 });
|
|
31295
31572
|
},
|
|
31296
31573
|
// Write-back (on by default): normalize the live transcript to rich turns (text + tool calls +
|
|
31297
31574
|
// their inline output) and hand it to core, which upserts every N user turns.
|
|
@@ -31374,3 +31651,42 @@ export {
|
|
|
31374
31651
|
HindsightKiloPlugin,
|
|
31375
31652
|
kilo_default as default
|
|
31376
31653
|
};
|
|
31654
|
+
/*! Bundled license information:
|
|
31655
|
+
|
|
31656
|
+
smol-toml/dist/error.js:
|
|
31657
|
+
smol-toml/dist/primitive.js:
|
|
31658
|
+
smol-toml/dist/date.js:
|
|
31659
|
+
smol-toml/dist/extract.js:
|
|
31660
|
+
smol-toml/dist/util.js:
|
|
31661
|
+
smol-toml/dist/struct.js:
|
|
31662
|
+
smol-toml/dist/parse.js:
|
|
31663
|
+
smol-toml/dist/stringify.js:
|
|
31664
|
+
smol-toml/dist/index.js:
|
|
31665
|
+
(*!
|
|
31666
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
31667
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
31668
|
+
*
|
|
31669
|
+
* Redistribution and use in source and binary forms, with or without
|
|
31670
|
+
* modification, are permitted provided that the following conditions are met:
|
|
31671
|
+
*
|
|
31672
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
31673
|
+
* list of conditions and the following disclaimer.
|
|
31674
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
31675
|
+
* this list of conditions and the following disclaimer in the
|
|
31676
|
+
* documentation and/or other materials provided with the distribution.
|
|
31677
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
31678
|
+
* may be used to endorse or promote products derived from this software without
|
|
31679
|
+
* specific prior written permission.
|
|
31680
|
+
*
|
|
31681
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
31682
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
31683
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
31684
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
31685
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
31686
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
31687
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
31688
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
31689
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
31690
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31691
|
+
*)
|
|
31692
|
+
*/
|