@vectorize-io/hindsight-coding-agents 0.8.2 → 0.8.3
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 +383 -99
- package/dist/claude-stop-hook.js +132 -51
- package/dist/cline.js +401 -91
- package/dist/codebuddy-hook.js +95 -42
- package/dist/codebuddy-sessionstart-hook.js +383 -99
- package/dist/codebuddy-stop-hook.js +132 -51
- package/dist/codex-hook.js +95 -42
- package/dist/codex-sessionstart-hook.js +383 -99
- package/dist/codex-stop-hook.js +132 -51
- package/dist/copilot-hook.js +95 -42
- package/dist/copilot-sessionstart-hook.js +383 -99
- package/dist/copilot-stop-hook.js +132 -51
- package/dist/cursor-hook.js +95 -42
- package/dist/cursor-sessionstart-hook.js +383 -99
- 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 +383 -99
- 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 +383 -99
- package/dist/devin-stop-hook.js +132 -51
- package/dist/droid-hook.js +95 -42
- package/dist/droid-sessionstart-hook.js +383 -99
- package/dist/droid-stop-hook.js +132 -51
- package/dist/dsh.js +420 -98
- package/dist/grok-hook.js +95 -42
- package/dist/grok-sessionstart-hook.js +383 -99
- package/dist/grok-stop-hook.js +132 -51
- package/dist/hindsight-seed.js +6 -6
- package/dist/index.js +425 -110
- package/dist/installer.js +89 -80
- package/dist/kilo.js +425 -110
- package/dist/kimi-hook.js +95 -42
- package/dist/kimi-sessionstart-hook.js +383 -99
- package/dist/kimi-stop-hook.js +132 -51
- package/dist/mcp-server.js +169 -62
- package/dist/opencode2.js +581 -104
- package/dist/pi.js +401 -98
- package/dist/prime-agent.js +401 -98
- package/dist/qwen-hook.js +95 -42
- package/dist/qwen-sessionstart-hook.js +383 -99
- 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 +383 -99
- package/dist/traecode-stop-hook.js +132 -51
- package/dist/workbuddy-hook.js +95 -42
- package/dist/workbuddy-sessionstart-hook.js +383 -99
- package/dist/workbuddy-stop-hook.js +132 -51
- package/dist/zcode-hook.js +95 -42
- package/dist/zcode-sessionstart-hook.js +383 -99
- package/dist/zcode-stop-hook.js +132 -51
- package/index.js +4 -1
- package/package.json +6 -4
- package/plugin.json +1 -1
- package/skill/SKILL.md +10 -2
package/dist/dsh.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, (_, name2) => {
|
|
231
|
-
const
|
|
232
|
-
if (!
|
|
231
|
+
const resolve4 = resolvers[name2];
|
|
232
|
+
if (!resolve4) {
|
|
233
233
|
console.error(
|
|
234
234
|
`hindsight: unknown ${what} placeholder "{${name2}}" \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.3";
|
|
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 = (file2) => {
|
|
668
|
+
try {
|
|
669
|
+
if (!statSync2(file2).isFile()) return false;
|
|
670
|
+
if (platform !== "win32") accessSync(file2, 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 name2 of names) {
|
|
681
|
+
const file2 = join6(dir, name2);
|
|
682
|
+
if (runnable(file2)) return resolve2(file2);
|
|
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(version3, 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 parse4 = (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 = parse4(candidate);
|
|
2009
|
+
const b = parse4(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"], {
|
|
@@ -2281,8 +2289,8 @@ async function waitBounded(p, ms) {
|
|
|
2281
2289
|
try {
|
|
2282
2290
|
await Promise.race([
|
|
2283
2291
|
p,
|
|
2284
|
-
new Promise((
|
|
2285
|
-
timer = setTimeout(
|
|
2292
|
+
new Promise((resolve4) => {
|
|
2293
|
+
timer = setTimeout(resolve4, Math.max(ms, 0));
|
|
2286
2294
|
})
|
|
2287
2295
|
]);
|
|
2288
2296
|
} finally {
|
|
@@ -16927,7 +16935,7 @@ import { execFileSync as execFileSync4 } from "child_process";
|
|
|
16927
16935
|
|
|
16928
16936
|
// src/core/git.ts
|
|
16929
16937
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
16930
|
-
import { resolve as
|
|
16938
|
+
import { resolve as resolve3 } from "path";
|
|
16931
16939
|
|
|
16932
16940
|
// src/core/uuid.ts
|
|
16933
16941
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -16955,18 +16963,25 @@ var US = "";
|
|
|
16955
16963
|
var RS = "";
|
|
16956
16964
|
var GITLOG_HEAD = "gitlog-head:";
|
|
16957
16965
|
var GITLOG_FORMAT = `--format=%h${US}%ad${US}%an${US}%s${US}%b${RS}`;
|
|
16958
|
-
function
|
|
16966
|
+
function runGit(repo, args, env) {
|
|
16959
16967
|
return execFileSync2("git", ["-C", repo, "-c", "log.showSignature=false", ...args], {
|
|
16960
16968
|
encoding: "utf8",
|
|
16961
16969
|
maxBuffer: 1 << 28,
|
|
16962
16970
|
windowsHide: true,
|
|
16971
|
+
env,
|
|
16963
16972
|
// execFileSync otherwise forwards failed git stderr into the host's TUI,
|
|
16964
16973
|
// even when callers catch the error. Keep diagnostics on the error instead.
|
|
16965
16974
|
stdio: ["ignore", "pipe", "pipe"]
|
|
16966
16975
|
});
|
|
16967
16976
|
}
|
|
16977
|
+
function git(repo, ...args) {
|
|
16978
|
+
return runGit(repo, args);
|
|
16979
|
+
}
|
|
16980
|
+
function gitLocal(repo, ...args) {
|
|
16981
|
+
return runGit(repo, args, { ...process.env, GIT_NO_LAZY_FETCH: "1" });
|
|
16982
|
+
}
|
|
16968
16983
|
function repoNameOf(repo) {
|
|
16969
|
-
return projectNameOf(
|
|
16984
|
+
return projectNameOf(resolve3(repo));
|
|
16970
16985
|
}
|
|
16971
16986
|
function gitHeadSha(dir) {
|
|
16972
16987
|
try {
|
|
@@ -16978,7 +16993,7 @@ function gitHeadSha(dir) {
|
|
|
16978
16993
|
function commitsSince(dir, sinceSha) {
|
|
16979
16994
|
if (!/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(sinceSha)) return null;
|
|
16980
16995
|
try {
|
|
16981
|
-
const n = Number.parseInt(
|
|
16996
|
+
const n = Number.parseInt(gitLocal(dir, "rev-list", "--count", `${sinceSha}..HEAD`).trim(), 10);
|
|
16982
16997
|
return Number.isFinite(n) ? n : null;
|
|
16983
16998
|
} catch {
|
|
16984
16999
|
return null;
|
|
@@ -17004,11 +17019,197 @@ async function gitLogIsCurrent(client, repo, head) {
|
|
|
17004
17019
|
// src/core/survey.ts
|
|
17005
17020
|
import { execFileSync as execFileSync3, spawn as realSpawn5 } from "child_process";
|
|
17006
17021
|
import { createHash as createHash3 } from "crypto";
|
|
17007
|
-
import { existsSync as existsSync3 } from "fs";
|
|
17022
|
+
import { existsSync as existsSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
17008
17023
|
import { homedir as homedir5, tmpdir as tmpdir2 } from "os";
|
|
17009
17024
|
import { dirname as dirname7, join as join11 } from "path";
|
|
17010
17025
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
17011
17026
|
|
|
17027
|
+
// node_modules/smol-toml/dist/stringify.js
|
|
17028
|
+
var BARE_KEY = /^[a-z0-9-_]+$/i;
|
|
17029
|
+
var HAS_WELLFORMED = !!"".isWellFormed;
|
|
17030
|
+
function extendedTypeOf(obj) {
|
|
17031
|
+
let type = typeof obj;
|
|
17032
|
+
if (type === "object") {
|
|
17033
|
+
if (Array.isArray(obj))
|
|
17034
|
+
return "array";
|
|
17035
|
+
if (typeof obj.getUTCDate === "function" && obj instanceof Date)
|
|
17036
|
+
return "date";
|
|
17037
|
+
if (globalThis.Temporal) {
|
|
17038
|
+
if (obj.until) {
|
|
17039
|
+
if (obj instanceof Temporal.ZonedDateTime)
|
|
17040
|
+
return "temporal/tz+uc";
|
|
17041
|
+
if (obj instanceof Temporal.PlainDateTime || obj instanceof Temporal.PlainDate)
|
|
17042
|
+
return "temporal/uc";
|
|
17043
|
+
if (obj instanceof Temporal.PlainTime || obj instanceof Temporal.Instant)
|
|
17044
|
+
return "temporal";
|
|
17045
|
+
if (obj instanceof Temporal.PlainYearMonth)
|
|
17046
|
+
return "temporal/x";
|
|
17047
|
+
} else if (obj.toPlainDate && obj instanceof Temporal.PlainMonthDay || obj.negated && obj instanceof Temporal.Duration) {
|
|
17048
|
+
return "temporal/x";
|
|
17049
|
+
}
|
|
17050
|
+
}
|
|
17051
|
+
}
|
|
17052
|
+
return type;
|
|
17053
|
+
}
|
|
17054
|
+
function isArrayOfTables(obj) {
|
|
17055
|
+
for (let i = 0; i < obj.length; i++) {
|
|
17056
|
+
if (extendedTypeOf(obj[i]) !== "object")
|
|
17057
|
+
return false;
|
|
17058
|
+
}
|
|
17059
|
+
return obj.length != 0;
|
|
17060
|
+
}
|
|
17061
|
+
function formatWellFormedStringUnchecked(s) {
|
|
17062
|
+
return JSON.stringify(s).replaceAll("\x7F", "\\u007f");
|
|
17063
|
+
}
|
|
17064
|
+
function formatString(s) {
|
|
17065
|
+
return formatWellFormedStringUnchecked(HAS_WELLFORMED ? s.toWellFormed() : s);
|
|
17066
|
+
}
|
|
17067
|
+
function formatKey(s) {
|
|
17068
|
+
if (BARE_KEY.test(s))
|
|
17069
|
+
return s;
|
|
17070
|
+
if (HAS_WELLFORMED && !s.isWellFormed())
|
|
17071
|
+
throw new RangeError("key contains illegal lone surrogates");
|
|
17072
|
+
return formatWellFormedStringUnchecked(s);
|
|
17073
|
+
}
|
|
17074
|
+
function stringifyValue(val, type, depth, numberAsFloat, strictTemporal) {
|
|
17075
|
+
if (depth === 0) {
|
|
17076
|
+
throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
17077
|
+
}
|
|
17078
|
+
switch (type) {
|
|
17079
|
+
// @ts-expect-error -- intentional fallthrough case
|
|
17080
|
+
case "number":
|
|
17081
|
+
if (isNaN(val))
|
|
17082
|
+
return "nan";
|
|
17083
|
+
if (val === Infinity)
|
|
17084
|
+
return "inf";
|
|
17085
|
+
if (val === -Infinity)
|
|
17086
|
+
return "-inf";
|
|
17087
|
+
if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val)))
|
|
17088
|
+
return val.toFixed(1);
|
|
17089
|
+
case "bigint":
|
|
17090
|
+
case "boolean":
|
|
17091
|
+
case "temporal":
|
|
17092
|
+
return val.toString();
|
|
17093
|
+
case "string":
|
|
17094
|
+
return formatString(val);
|
|
17095
|
+
case "date":
|
|
17096
|
+
if (isNaN(val.getTime()))
|
|
17097
|
+
throw new TypeError("cannot serialize invalid date");
|
|
17098
|
+
return val.toISOString();
|
|
17099
|
+
case "object":
|
|
17100
|
+
return stringifyInlineTable(val, depth, numberAsFloat, strictTemporal);
|
|
17101
|
+
case "array":
|
|
17102
|
+
return stringifyArray(val, depth, numberAsFloat, strictTemporal);
|
|
17103
|
+
// @ts-expect-error -- intentional fallthrough case
|
|
17104
|
+
case "temporal/tz+uc":
|
|
17105
|
+
if (strictTemporal) {
|
|
17106
|
+
let tz = val.timeZoneId;
|
|
17107
|
+
let tzc = tz.charCodeAt(0);
|
|
17108
|
+
if (
|
|
17109
|
+
// Classic offset
|
|
17110
|
+
tzc !== 43 && tzc !== 45 && // Fast pre-check pass; see below for the actually accepted values
|
|
17111
|
+
(tzc !== 85 && tzc !== 71 && tzc !== 90 && tzc !== 69 || // UTC and its aliases; Temporal implementations don't all canonicalise unfortunately
|
|
17112
|
+
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.
|
|
17113
|
+
!tz.startsWith("GMT") && tz !== "Greenwich" && // Etc/* are all safe to downgrade to offset (either UTC, GMT, or offset)
|
|
17114
|
+
!tz.startsWith("Etc/"))
|
|
17115
|
+
) {
|
|
17116
|
+
throw new TypeError("Temporal objects with an IANA timezone are not allowed in Temporal strict mode");
|
|
17117
|
+
}
|
|
17118
|
+
}
|
|
17119
|
+
case "temporal/uc":
|
|
17120
|
+
if (strictTemporal && val.calendarId !== "iso8601")
|
|
17121
|
+
throw new TypeError("Temporal objects with a non-default calendar are not allowed in Temporal strict mode");
|
|
17122
|
+
return val.toString({
|
|
17123
|
+
calendarName: "never",
|
|
17124
|
+
timeZoneName: "never"
|
|
17125
|
+
});
|
|
17126
|
+
case "temporal/x":
|
|
17127
|
+
throw new TypeError("Unsupported " + val[Symbol.toStringTag]);
|
|
17128
|
+
}
|
|
17129
|
+
}
|
|
17130
|
+
function stringifyInlineTable(obj, depth, numberAsFloat, strictTemporal) {
|
|
17131
|
+
let keys = Object.keys(obj);
|
|
17132
|
+
if (keys.length === 0)
|
|
17133
|
+
return "{}";
|
|
17134
|
+
let res = "{ ";
|
|
17135
|
+
for (let i = 0; i < keys.length; i++) {
|
|
17136
|
+
let k = keys[i];
|
|
17137
|
+
if (i)
|
|
17138
|
+
res += ", ";
|
|
17139
|
+
res += formatKey(k) + " = " + stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat, strictTemporal);
|
|
17140
|
+
}
|
|
17141
|
+
return res + " }";
|
|
17142
|
+
}
|
|
17143
|
+
function stringifyArray(array2, depth, numberAsFloat, strictTemporal) {
|
|
17144
|
+
if (array2.length === 0)
|
|
17145
|
+
return "[]";
|
|
17146
|
+
let res = "[ ";
|
|
17147
|
+
for (let i = 0; i < array2.length; i++) {
|
|
17148
|
+
if (i)
|
|
17149
|
+
res += ", ";
|
|
17150
|
+
if (array2[i] === null || array2[i] === void 0) {
|
|
17151
|
+
throw new TypeError("arrays cannot contain null or undefined values");
|
|
17152
|
+
}
|
|
17153
|
+
res += stringifyValue(array2[i], extendedTypeOf(array2[i]), depth - 1, numberAsFloat, strictTemporal);
|
|
17154
|
+
}
|
|
17155
|
+
return res + " ]";
|
|
17156
|
+
}
|
|
17157
|
+
function stringifyArrayTable(array2, key, depth, numberAsFloat, strictTemporal) {
|
|
17158
|
+
if (depth === 0) {
|
|
17159
|
+
throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
17160
|
+
}
|
|
17161
|
+
let res = "";
|
|
17162
|
+
for (let i = 0; i < array2.length; i++) {
|
|
17163
|
+
res += `${res && "\n"}[[${key}]]
|
|
17164
|
+
`;
|
|
17165
|
+
res += stringifyTable(0, array2[i], key, depth, numberAsFloat, strictTemporal);
|
|
17166
|
+
}
|
|
17167
|
+
return res;
|
|
17168
|
+
}
|
|
17169
|
+
function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat, strictTemporal) {
|
|
17170
|
+
if (depth === 0) {
|
|
17171
|
+
throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
17172
|
+
}
|
|
17173
|
+
let preamble = "";
|
|
17174
|
+
let tables = "";
|
|
17175
|
+
let keys = Object.keys(obj);
|
|
17176
|
+
for (let i = 0; i < keys.length; i++) {
|
|
17177
|
+
let k = keys[i];
|
|
17178
|
+
if (obj[k] !== null && obj[k] !== void 0) {
|
|
17179
|
+
let type = extendedTypeOf(obj[k]);
|
|
17180
|
+
if (type === "symbol" || type === "function") {
|
|
17181
|
+
throw new TypeError(`cannot serialize values of type '${type}'`);
|
|
17182
|
+
}
|
|
17183
|
+
let key = formatKey(k);
|
|
17184
|
+
if (type === "array" && isArrayOfTables(obj[k])) {
|
|
17185
|
+
tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat, strictTemporal);
|
|
17186
|
+
} else if (type === "object") {
|
|
17187
|
+
let tblKey = prefix ? `${prefix}.${key}` : key;
|
|
17188
|
+
tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat, strictTemporal);
|
|
17189
|
+
} else {
|
|
17190
|
+
preamble += key;
|
|
17191
|
+
preamble += " = ";
|
|
17192
|
+
preamble += stringifyValue(obj[k], type, depth, numberAsFloat, strictTemporal);
|
|
17193
|
+
preamble += "\n";
|
|
17194
|
+
}
|
|
17195
|
+
}
|
|
17196
|
+
}
|
|
17197
|
+
if (tableKey && (preamble || !tables))
|
|
17198
|
+
preamble = preamble ? `[${tableKey}]
|
|
17199
|
+
${preamble}` : `[${tableKey}]`;
|
|
17200
|
+
return preamble && tables ? `${preamble}
|
|
17201
|
+
${tables}` : preamble || tables;
|
|
17202
|
+
}
|
|
17203
|
+
function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false, strictTemporal = false } = {}) {
|
|
17204
|
+
if (extendedTypeOf(obj) !== "object") {
|
|
17205
|
+
throw new TypeError("stringify can only be called with an object");
|
|
17206
|
+
}
|
|
17207
|
+
let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat, strictTemporal);
|
|
17208
|
+
if (str[str.length - 1] !== "\n")
|
|
17209
|
+
return str + "\n";
|
|
17210
|
+
return str;
|
|
17211
|
+
}
|
|
17212
|
+
|
|
17012
17213
|
// src/core/survey-lease.ts
|
|
17013
17214
|
import { spawn as realSpawn4 } from "child_process";
|
|
17014
17215
|
import { randomUUID } from "crypto";
|
|
@@ -17019,7 +17220,7 @@ import {
|
|
|
17019
17220
|
renameSync as renameSync2,
|
|
17020
17221
|
rmdirSync,
|
|
17021
17222
|
rmSync,
|
|
17022
|
-
statSync as
|
|
17223
|
+
statSync as statSync3,
|
|
17023
17224
|
unlinkSync as unlinkSync2,
|
|
17024
17225
|
utimesSync,
|
|
17025
17226
|
writeFileSync as writeFileSync2
|
|
@@ -17056,7 +17257,7 @@ function reclaimIfStale(directory, staleMs) {
|
|
|
17056
17257
|
return true;
|
|
17057
17258
|
}
|
|
17058
17259
|
if (owners.length !== 1) return false;
|
|
17059
|
-
const age = Date.now() -
|
|
17260
|
+
const age = Date.now() - statSync3(join10(directory, owners[0])).mtimeMs;
|
|
17060
17261
|
if (Math.abs(age) <= staleMs) return false;
|
|
17061
17262
|
releaseLease({ directory, owner: owners[0] });
|
|
17062
17263
|
return true;
|
|
@@ -17119,7 +17320,7 @@ function opencodeCanDefineSurveyAgent(bin) {
|
|
|
17119
17320
|
windowsHide: true,
|
|
17120
17321
|
stdio: ["ignore", "pipe", "ignore"]
|
|
17121
17322
|
});
|
|
17122
|
-
return Number(/(\d+)\./.exec(out)?.[1] ?? 0)
|
|
17323
|
+
return Number(/(\d+)\./.exec(out)?.[1] ?? 0) === 1;
|
|
17123
17324
|
} catch {
|
|
17124
17325
|
return false;
|
|
17125
17326
|
}
|
|
@@ -17134,6 +17335,7 @@ var SURVEY_DISALLOWED_TOOLS = [
|
|
|
17134
17335
|
"WebSearch",
|
|
17135
17336
|
"Task"
|
|
17136
17337
|
];
|
|
17338
|
+
var tomlValue = (value) => stringify({ v: value }).slice("v = ".length).trim();
|
|
17137
17339
|
function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
17138
17340
|
const env = {
|
|
17139
17341
|
...process.env,
|
|
@@ -17192,9 +17394,9 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
17192
17394
|
"-c",
|
|
17193
17395
|
`mcp_servers.hindsight.command="node"`,
|
|
17194
17396
|
"-c",
|
|
17195
|
-
`mcp_servers.hindsight.args
|
|
17397
|
+
`mcp_servers.hindsight.args=${tomlValue([opts.mcpServerPath])}`,
|
|
17196
17398
|
"-c",
|
|
17197
|
-
`mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD
|
|
17399
|
+
`mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD=${tomlValue(repoDir)}`,
|
|
17198
17400
|
"-c",
|
|
17199
17401
|
`mcp_servers.hindsight.env.HINDSIGHT_MCP_HARNESS="codex"`,
|
|
17200
17402
|
SURVEY_PROMPT
|
|
@@ -17218,10 +17420,19 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
17218
17420
|
}
|
|
17219
17421
|
}
|
|
17220
17422
|
}
|
|
17423
|
+
var SURVEY_MAX_ATTEMPTS = 3;
|
|
17424
|
+
function surveyAttempts(file2, sha) {
|
|
17425
|
+
try {
|
|
17426
|
+
const state = JSON.parse(readFileSync5(file2, "utf8"));
|
|
17427
|
+
return state.sha === sha && typeof state.attempts === "number" ? state.attempts : 0;
|
|
17428
|
+
} catch {
|
|
17429
|
+
return 0;
|
|
17430
|
+
}
|
|
17431
|
+
}
|
|
17221
17432
|
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
17222
17433
|
try {
|
|
17223
17434
|
const spawnFn = opts.spawn ?? realSpawn5;
|
|
17224
|
-
const
|
|
17435
|
+
const resolveBin = opts.resolveBin ?? ((bin) => binOnPath(bin, { exts: [".exe"] }));
|
|
17225
17436
|
const mcpServerPath = opts.mcpServerPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
17226
17437
|
const preferred = opts.harness ?? "claude-code";
|
|
17227
17438
|
const order = [
|
|
@@ -17235,10 +17446,16 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17235
17446
|
for (const harness of order) {
|
|
17236
17447
|
if (seen.has(harness)) continue;
|
|
17237
17448
|
seen.add(harness);
|
|
17238
|
-
const
|
|
17239
|
-
|
|
17240
|
-
if (
|
|
17449
|
+
const name2 = resolveAgentBin(harness, opts.claudeBin);
|
|
17450
|
+
const bin = resolveBin(name2);
|
|
17451
|
+
if (!bin) {
|
|
17452
|
+
log.info("survey", `${harness}: ${name2} not found, trying the next agent`);
|
|
17453
|
+
continue;
|
|
17454
|
+
}
|
|
17455
|
+
if (harness === "opencode" && !(opts.opencodeDefinesAgent ?? opencodeCanDefineSurveyAgent)(bin)) {
|
|
17456
|
+
log.info("survey", `${harness}: ${bin} cannot define the survey agent, trying the next`);
|
|
17241
17457
|
continue;
|
|
17458
|
+
}
|
|
17242
17459
|
const plan = buildSurveyPlan(harness, bin, repoDir, {
|
|
17243
17460
|
model: opts.model,
|
|
17244
17461
|
budgetUsd: opts.budgetUsd,
|
|
@@ -17247,12 +17464,19 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17247
17464
|
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
17248
17465
|
if (cfg.disabled) return false;
|
|
17249
17466
|
const key = createHash3("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
17250
|
-
const
|
|
17251
|
-
|
|
17252
|
-
key,
|
|
17253
|
-
opts.lease?.staleMs ?? LEASE_STALE_MS
|
|
17254
|
-
);
|
|
17467
|
+
const leaseDir = opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys");
|
|
17468
|
+
const lease = acquireLease(leaseDir, key, opts.lease?.staleMs ?? LEASE_STALE_MS);
|
|
17255
17469
|
if (!lease) return false;
|
|
17470
|
+
const attemptsFile = join11(
|
|
17471
|
+
leaseDir,
|
|
17472
|
+
`attempts-${createHash3("sha256").update(JSON.stringify([key, repoDir])).digest("hex")}.json`
|
|
17473
|
+
);
|
|
17474
|
+
const attempts = opts.sha ? surveyAttempts(attemptsFile, opts.sha) : 0;
|
|
17475
|
+
if (attempts >= SURVEY_MAX_ATTEMPTS) {
|
|
17476
|
+
log.info("survey", `${attempts} surveys already launched at ${opts.sha}, skipping`);
|
|
17477
|
+
releaseLease(lease);
|
|
17478
|
+
return false;
|
|
17479
|
+
}
|
|
17256
17480
|
const spec = {
|
|
17257
17481
|
lease,
|
|
17258
17482
|
bin: plan.bin,
|
|
@@ -17260,7 +17484,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17260
17484
|
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
17261
17485
|
};
|
|
17262
17486
|
const supervisorPath = opts.supervisorPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
17263
|
-
return await new Promise((
|
|
17487
|
+
return await new Promise((resolve4) => {
|
|
17264
17488
|
try {
|
|
17265
17489
|
const child = spawnFn("node", [supervisorPath], {
|
|
17266
17490
|
cwd: repoDir,
|
|
@@ -17270,19 +17494,31 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17270
17494
|
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
17271
17495
|
});
|
|
17272
17496
|
let spawned = false;
|
|
17273
|
-
child.on("error", () => {
|
|
17497
|
+
child.on("error", (e) => {
|
|
17274
17498
|
if (spawned) return;
|
|
17499
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17275
17500
|
releaseLease(lease);
|
|
17276
|
-
|
|
17501
|
+
resolve4(false);
|
|
17277
17502
|
});
|
|
17278
17503
|
child.once("spawn", () => {
|
|
17279
17504
|
spawned = true;
|
|
17280
17505
|
child.unref();
|
|
17281
|
-
|
|
17506
|
+
if (opts.sha) {
|
|
17507
|
+
try {
|
|
17508
|
+
writeFileSync3(
|
|
17509
|
+
attemptsFile,
|
|
17510
|
+
JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
|
|
17511
|
+
{ mode: 384 }
|
|
17512
|
+
);
|
|
17513
|
+
} catch {
|
|
17514
|
+
}
|
|
17515
|
+
}
|
|
17516
|
+
resolve4(true);
|
|
17282
17517
|
});
|
|
17283
|
-
} catch {
|
|
17518
|
+
} catch (e) {
|
|
17519
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17284
17520
|
releaseLease(lease);
|
|
17285
|
-
|
|
17521
|
+
resolve4(false);
|
|
17286
17522
|
}
|
|
17287
17523
|
});
|
|
17288
17524
|
}
|
|
@@ -17560,6 +17796,18 @@ function pendingReplayable(cursor, now) {
|
|
|
17560
17796
|
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
17561
17797
|
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
17562
17798
|
}
|
|
17799
|
+
function advanceSegments(cursor, bank) {
|
|
17800
|
+
if (!cursor || cursor.bank === bank) return cursor?.segments;
|
|
17801
|
+
return [...cursor.segments ?? [{ bank: cursor.bank, from: 0 }], { bank, from: cursor.turns }];
|
|
17802
|
+
}
|
|
17803
|
+
function bankTurns(turns, segments, bank) {
|
|
17804
|
+
if (!segments) return turns;
|
|
17805
|
+
return turns.filter((_, i) => {
|
|
17806
|
+
let owner;
|
|
17807
|
+
for (const s of segments) if (s.from <= i) owner = s.bank;
|
|
17808
|
+
return owner === bank;
|
|
17809
|
+
});
|
|
17810
|
+
}
|
|
17563
17811
|
var MAX_CURSOR_OPS = 8;
|
|
17564
17812
|
function fingerprintTurns(turns, count) {
|
|
17565
17813
|
const h = createHash5("sha1").update(String(count));
|
|
@@ -17570,7 +17818,8 @@ function planRetain(turns, cursor, opts) {
|
|
|
17570
17818
|
if (!turns.length) return { mode: "skip" };
|
|
17571
17819
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
17572
17820
|
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
17573
|
-
if (cursor.bank !== opts.bank)
|
|
17821
|
+
if (cursor.bank !== opts.bank && !cursor.segments?.some((s) => s.bank === opts.bank))
|
|
17822
|
+
return { mode: "replace" };
|
|
17574
17823
|
const seen = cursor.paths ?? [];
|
|
17575
17824
|
const newFile = Boolean(opts.path && seen.length && !seen.includes(opts.path));
|
|
17576
17825
|
const continues = cursor.turns <= turns.length && fingerprintTurns(turns, cursor.turns) === cursor.fingerprint;
|
|
@@ -17691,8 +17940,17 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
|
|
|
17691
17940
|
let cursor = cursors?.read(sessionId);
|
|
17692
17941
|
const probed = Boolean(cursors) && cursor?.appendSupported !== true;
|
|
17693
17942
|
const appendSupported = Boolean(cursors) && (cursor?.appendSupported === true || await supportsAppend(client));
|
|
17943
|
+
const moved = Boolean(cursor && cursor.bank !== client.bank);
|
|
17944
|
+
if (moved)
|
|
17945
|
+
log.warn(harness ?? "", "session moved to another bank mid-session", {
|
|
17946
|
+
session: sessionId,
|
|
17947
|
+
from: cursor?.bank,
|
|
17948
|
+
to: client.bank,
|
|
17949
|
+
atTurn: cursor?.turns
|
|
17950
|
+
});
|
|
17951
|
+
const segments = advanceSegments(cursor, client.bank);
|
|
17694
17952
|
let ops = [];
|
|
17695
|
-
if (appendSupported && cursor?.ops?.length && !cursor.dirty)
|
|
17953
|
+
if (appendSupported && cursor?.ops?.length && !cursor.dirty && !moved)
|
|
17696
17954
|
({ cursor, ops } = await settleOps(client, cursor));
|
|
17697
17955
|
const plan = planRetain(turns, cursor, {
|
|
17698
17956
|
appendSupported,
|
|
@@ -17701,7 +17959,7 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
|
|
|
17701
17959
|
});
|
|
17702
17960
|
if (probed) diag(harness ?? "", "retain_mode", { mode: plan.mode, appendSupported });
|
|
17703
17961
|
const paths = plan.mode === "replace" ? transcriptPath ? [transcriptPath] : void 0 : advancePaths(cursor?.paths, transcriptPath);
|
|
17704
|
-
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
17962
|
+
const outbox = plan.mode === "replace" || moved ? [] : cursor?.pending ?? [];
|
|
17705
17963
|
if (plan.mode === "skip" && !outbox.length) return;
|
|
17706
17964
|
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
17707
17965
|
${refId}
|
|
@@ -17743,6 +18001,7 @@ ${content}`);
|
|
|
17743
18001
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
17744
18002
|
bank: client.bank,
|
|
17745
18003
|
...paths ? { paths } : {},
|
|
18004
|
+
...segments ? { segments } : {},
|
|
17746
18005
|
...appendSupported ? { appendSupported: true } : {}
|
|
17747
18006
|
};
|
|
17748
18007
|
const accepted = (id) => {
|
|
@@ -17755,9 +18014,14 @@ ${content}`);
|
|
|
17755
18014
|
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
17756
18015
|
};
|
|
17757
18016
|
if (plan.mode === "replace") {
|
|
17758
|
-
const
|
|
18017
|
+
const share = bankTurns(turns, segments, client.bank);
|
|
18018
|
+
if (!share.length) return;
|
|
18019
|
+
const content = renderSessionJsonl(refId, share, startTs);
|
|
18020
|
+
const base = cursor ? `${cursor.turns}
|
|
18021
|
+
${cursor.fingerprint}` : "";
|
|
17759
18022
|
cursors?.write(sessionId, { ...next, dirty: true });
|
|
17760
|
-
const operationId = opId("replace",
|
|
18023
|
+
const operationId = opId("replace", `${base}
|
|
18024
|
+
${content}`);
|
|
17761
18025
|
await submitWithRetry(() => submit(content, operationId, false), stillOurs, retryUntil);
|
|
17762
18026
|
ops = [];
|
|
17763
18027
|
cursors?.write(sessionId, accepted(operationId));
|
|
@@ -17784,7 +18048,7 @@ ${content}`);
|
|
|
17784
18048
|
}
|
|
17785
18049
|
|
|
17786
18050
|
// src/core/usage.ts
|
|
17787
|
-
import { readFileSync as
|
|
18051
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
17788
18052
|
import { join as join13 } from "path";
|
|
17789
18053
|
function usageFilePath() {
|
|
17790
18054
|
return process.env.HINDSIGHT_USAGE_FILE || join13(logsDir(), "usage.jsonl");
|
|
@@ -17867,12 +18131,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17867
18131
|
const base = resolversFor(ctx);
|
|
17868
18132
|
const cache = /* @__PURE__ */ new Map();
|
|
17869
18133
|
const resolvers = Object.fromEntries(
|
|
17870
|
-
Object.entries(base).map(([name2,
|
|
18134
|
+
Object.entries(base).map(([name2, resolve4]) => [
|
|
17871
18135
|
name2,
|
|
17872
18136
|
() => {
|
|
17873
18137
|
const hit = cache.get(name2);
|
|
17874
18138
|
if (hit !== void 0) return hit;
|
|
17875
|
-
const value =
|
|
18139
|
+
const value = resolve4();
|
|
17876
18140
|
cache.set(name2, value);
|
|
17877
18141
|
return value;
|
|
17878
18142
|
}
|
|
@@ -17892,7 +18156,7 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17892
18156
|
}
|
|
17893
18157
|
|
|
17894
18158
|
// src/core/skill-sync.ts
|
|
17895
|
-
import { cpSync, existsSync as existsSync6, readFileSync as
|
|
18159
|
+
import { cpSync, existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
17896
18160
|
import { homedir as homedir7 } from "os";
|
|
17897
18161
|
import { dirname as dirname8, join as join15 } from "path";
|
|
17898
18162
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
@@ -17967,7 +18231,7 @@ function syncCompanionSkill(harness, opts = {}) {
|
|
|
17967
18231
|
const dstMd = join15(dst, "SKILL.md");
|
|
17968
18232
|
const installed = existsSync6(dstMd);
|
|
17969
18233
|
if (!installed && !opts.install) return;
|
|
17970
|
-
if (!installed ||
|
|
18234
|
+
if (!installed || readFileSync7(srcMd, "utf8") !== readFileSync7(dstMd, "utf8")) {
|
|
17971
18235
|
cpSync(src, dst, { recursive: true });
|
|
17972
18236
|
}
|
|
17973
18237
|
} catch {
|
|
@@ -17989,9 +18253,9 @@ function brandWord() {
|
|
|
17989
18253
|
}
|
|
17990
18254
|
|
|
17991
18255
|
// src/core/legacy.ts
|
|
17992
|
-
import { existsSync as existsSync7, readFileSync as
|
|
18256
|
+
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "fs";
|
|
17993
18257
|
import { homedir as homedir8 } from "os";
|
|
17994
|
-
import { join as join16, relative, isAbsolute as
|
|
18258
|
+
import { join as join16, relative, isAbsolute as isAbsolute3 } from "path";
|
|
17995
18259
|
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
17996
18260
|
function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")) {
|
|
17997
18261
|
const registry2 = readJson(join16(claudeDir, "plugins", "installed_plugins.json"));
|
|
@@ -18006,7 +18270,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
|
|
|
18006
18270
|
if (!i || typeof i !== "object") return false;
|
|
18007
18271
|
if (typeof i.projectPath !== "string") return true;
|
|
18008
18272
|
const rel = relative(i.projectPath, cwd);
|
|
18009
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
18273
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
18010
18274
|
});
|
|
18011
18275
|
if (active) return key;
|
|
18012
18276
|
}
|
|
@@ -18014,7 +18278,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
|
|
|
18014
18278
|
}
|
|
18015
18279
|
function readJson(path) {
|
|
18016
18280
|
try {
|
|
18017
|
-
const parsed = JSON.parse(
|
|
18281
|
+
const parsed = JSON.parse(readFileSync8(path, "utf8"));
|
|
18018
18282
|
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
18019
18283
|
} catch {
|
|
18020
18284
|
return void 0;
|
|
@@ -18026,7 +18290,7 @@ function legacyClaudePluginWarning(key) {
|
|
|
18026
18290
|
}
|
|
18027
18291
|
|
|
18028
18292
|
// src/core/session-cache.ts
|
|
18029
|
-
import { mkdirSync as mkdirSync4, readFileSync as
|
|
18293
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
18030
18294
|
import { tmpdir as tmpdir3 } from "os";
|
|
18031
18295
|
import { dirname as dirname9, join as join17 } from "path";
|
|
18032
18296
|
function sessionCacheFile(harness, sessionId) {
|
|
@@ -18034,7 +18298,7 @@ function sessionCacheFile(harness, sessionId) {
|
|
|
18034
18298
|
}
|
|
18035
18299
|
function readSessionCache(cacheFile) {
|
|
18036
18300
|
try {
|
|
18037
|
-
return JSON.parse(
|
|
18301
|
+
return JSON.parse(readFileSync9(cacheFile, "utf8"));
|
|
18038
18302
|
} catch {
|
|
18039
18303
|
return {};
|
|
18040
18304
|
}
|
|
@@ -18043,7 +18307,7 @@ function writeFileAtomic(path, body) {
|
|
|
18043
18307
|
mkdirSync4(dirname9(path), { recursive: true });
|
|
18044
18308
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
18045
18309
|
try {
|
|
18046
|
-
|
|
18310
|
+
writeFileSync4(tmp, body);
|
|
18047
18311
|
renameSync3(tmp, path);
|
|
18048
18312
|
} catch (e) {
|
|
18049
18313
|
try {
|
|
@@ -18153,12 +18417,13 @@ async function buildSessionStartContext(args) {
|
|
|
18153
18417
|
startSeed(cwd, { limit: cfg.seedLimit, harness });
|
|
18154
18418
|
if (cold) {
|
|
18155
18419
|
if (cfg.codebaseSurvey !== false) {
|
|
18420
|
+
const sha = resolveHeadSha(cwd);
|
|
18156
18421
|
const started = await startSurvey(cwd, {
|
|
18157
18422
|
harness,
|
|
18158
18423
|
model: cfg.surveyModel,
|
|
18159
|
-
budgetUsd: cfg.surveyBudgetUsd
|
|
18424
|
+
budgetUsd: cfg.surveyBudgetUsd,
|
|
18425
|
+
sha: sha ?? void 0
|
|
18160
18426
|
});
|
|
18161
|
-
const sha = resolveHeadSha(cwd);
|
|
18162
18427
|
if (started && sha) recordSurveyBaseline(sha);
|
|
18163
18428
|
}
|
|
18164
18429
|
diag(harness, "seed_started", { bank: bankId });
|
|
@@ -18179,7 +18444,8 @@ async function buildSessionStartContext(args) {
|
|
|
18179
18444
|
const started = await startSurvey(cwd, {
|
|
18180
18445
|
harness,
|
|
18181
18446
|
model: cfg.surveyModel,
|
|
18182
|
-
budgetUsd: cfg.surveyBudgetUsd
|
|
18447
|
+
budgetUsd: cfg.surveyBudgetUsd,
|
|
18448
|
+
sha
|
|
18183
18449
|
});
|
|
18184
18450
|
if (started) {
|
|
18185
18451
|
recordSurveyBaseline(sha);
|
|
@@ -18281,7 +18547,7 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
18281
18547
|
}
|
|
18282
18548
|
|
|
18283
18549
|
// src/core/turn-journal.ts
|
|
18284
|
-
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as
|
|
18550
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync10, statSync as statSync4 } from "fs";
|
|
18285
18551
|
import { tmpdir as tmpdir4 } from "os";
|
|
18286
18552
|
import { dirname as dirname10, join as join18 } from "path";
|
|
18287
18553
|
|
|
@@ -18532,8 +18798,6 @@ var RuntimeCore = class {
|
|
|
18532
18798
|
fetchTranscript;
|
|
18533
18799
|
/** Write-backs started and not yet settled — what `flush` waits for. */
|
|
18534
18800
|
inFlight = /* @__PURE__ */ new Set();
|
|
18535
|
-
lastInjection = "";
|
|
18536
|
-
// most recent turn's injection block, keyed by nothing (see getInjection)
|
|
18537
18801
|
deferInitialReflect = false;
|
|
18538
18802
|
/** Host-notice channel (opencode/Kilo: client.tui.showToast via the adapter). Optional, fail-open. */
|
|
18539
18803
|
notify;
|
|
@@ -18605,7 +18869,11 @@ var RuntimeCore = class {
|
|
|
18605
18869
|
*/
|
|
18606
18870
|
async onPrompt(sessionId, prompt) {
|
|
18607
18871
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
18608
|
-
if (!sessionId
|
|
18872
|
+
if (!sessionId) return;
|
|
18873
|
+
if (!prompt.trim()) {
|
|
18874
|
+
this.injection.delete(sessionId);
|
|
18875
|
+
return;
|
|
18876
|
+
}
|
|
18609
18877
|
const turns = (this.turnCount.get(sessionId) ?? 0) + 1;
|
|
18610
18878
|
this.turnCount.set(sessionId, turns);
|
|
18611
18879
|
const cacheFile = sessionCacheFile(this.harness, sessionId);
|
|
@@ -18637,18 +18905,21 @@ var RuntimeCore = class {
|
|
|
18637
18905
|
}
|
|
18638
18906
|
const block = blocks.filter(Boolean).join("\n\n");
|
|
18639
18907
|
this.injection.set(sessionId, block);
|
|
18640
|
-
this.lastInjection = block;
|
|
18641
18908
|
}
|
|
18642
18909
|
/**
|
|
18643
|
-
* The
|
|
18644
|
-
*
|
|
18645
|
-
*
|
|
18646
|
-
* turn
|
|
18647
|
-
*
|
|
18910
|
+
* The text to inject into this turn's user message (built by the preceding onPrompt), or
|
|
18911
|
+
* undefined.
|
|
18912
|
+
*
|
|
18913
|
+
* It goes into the USER turn on every host, never the system prompt (#5914). The block changes
|
|
18914
|
+
* from turn to turn — the recall runs once, the roster refresh on a cadence — so a system prompt
|
|
18915
|
+
* carrying it differed between requests and broke the provider's prefix cache from that point
|
|
18916
|
+
* on. Persisted in the turn it belongs to, it leaves the system prompt and the earlier history
|
|
18917
|
+
* byte-identical. That used to need a fallback to the most recent block for opencode's
|
|
18918
|
+
* `experimental.chat.system.transform`, which fired with no session id; nothing reads it that
|
|
18919
|
+
* way any more.
|
|
18648
18920
|
*/
|
|
18649
18921
|
getInjection(sessionId) {
|
|
18650
|
-
|
|
18651
|
-
return keyed ?? this.lastInjection ?? void 0;
|
|
18922
|
+
return this.injection.get(sessionId) || void 0;
|
|
18652
18923
|
}
|
|
18653
18924
|
/**
|
|
18654
18925
|
* Full normalized transcript (rich: user/assistant text + tool calls/outputs): upsert every turn
|
|
@@ -18828,6 +19099,9 @@ var liveAgents = /* @__PURE__ */ new Map();
|
|
|
18828
19099
|
function dshSessionEvents(session) {
|
|
18829
19100
|
return session.snapshotEvents?.() ?? session.events ?? [];
|
|
18830
19101
|
}
|
|
19102
|
+
function ownEvents(session) {
|
|
19103
|
+
return dshSessionEvents(session).slice(session.inheritedEventCount ?? 0);
|
|
19104
|
+
}
|
|
18831
19105
|
function workspaceRoot(agent) {
|
|
18832
19106
|
return agent.session.header.cwd || process.cwd();
|
|
18833
19107
|
}
|
|
@@ -18842,7 +19116,7 @@ function workspaceFor(root) {
|
|
|
18842
19116
|
const core = new RuntimeCore(client, bankId, cfg, HARNESS2, root);
|
|
18843
19117
|
core.setTranscriptSource(async (sessionId) => {
|
|
18844
19118
|
const agent = liveAgents.get(sessionId);
|
|
18845
|
-
return agent ? readDshEvents(
|
|
19119
|
+
return agent ? readDshEvents(ownEvents(agent.session)) : [];
|
|
18846
19120
|
});
|
|
18847
19121
|
const workspace = { core, root };
|
|
18848
19122
|
workspaces.set(root, workspace);
|
|
@@ -18866,11 +19140,20 @@ function injectionMessage(text) {
|
|
|
18866
19140
|
source: { kind: `plugin:${HINDSIGHT_PLUGIN}`, form: "recall" }
|
|
18867
19141
|
};
|
|
18868
19142
|
}
|
|
18869
|
-
function
|
|
18870
|
-
|
|
19143
|
+
function lastInjectedText(events) {
|
|
19144
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
19145
|
+
const event = events[i];
|
|
19146
|
+
if (event?.type !== "user/message") continue;
|
|
19147
|
+
const message = event.data;
|
|
19148
|
+
if (message?.source?.kind !== `plugin:${HINDSIGHT_PLUGIN}`) continue;
|
|
19149
|
+
return (message.content ?? []).map((block) => block.text ?? "").join("\n");
|
|
19150
|
+
}
|
|
19151
|
+
return void 0;
|
|
19152
|
+
}
|
|
19153
|
+
function createDshHooks(resolve4) {
|
|
18871
19154
|
return {
|
|
18872
19155
|
sessionStart({ agent }) {
|
|
18873
|
-
const workspace =
|
|
19156
|
+
const workspace = resolve4(agent);
|
|
18874
19157
|
if (!workspace) return;
|
|
18875
19158
|
liveAgents.set(agent.session.header.id, agent);
|
|
18876
19159
|
ensureSeeded(workspace);
|
|
@@ -18878,7 +19161,7 @@ function createDshHooks(resolve3) {
|
|
|
18878
19161
|
async preStep({ agent, signal }, next) {
|
|
18879
19162
|
const decision = await next();
|
|
18880
19163
|
if (decision.kind !== "enter" || signal.aborted) return decision;
|
|
18881
|
-
const workspace =
|
|
19164
|
+
const workspace = resolve4(agent);
|
|
18882
19165
|
if (!workspace) return decision;
|
|
18883
19166
|
const sessionId = agent.session.header.id;
|
|
18884
19167
|
liveAgents.set(sessionId, agent);
|
|
@@ -18891,16 +19174,15 @@ function createDshHooks(resolve3) {
|
|
|
18891
19174
|
diag(HARNESS2, "inject_empty", { session: sessionId });
|
|
18892
19175
|
return decision;
|
|
18893
19176
|
}
|
|
18894
|
-
if (injection ===
|
|
19177
|
+
if (injection === lastInjectedText(dshSessionEvents(agent.session))) {
|
|
18895
19178
|
diag(HARNESS2, "inject_unchanged", { session: sessionId });
|
|
18896
19179
|
return decision;
|
|
18897
19180
|
}
|
|
18898
|
-
lastInjected.set(sessionId, injection);
|
|
18899
19181
|
diag(HARNESS2, "inject_ok", { session: sessionId, chars: injection.length });
|
|
18900
19182
|
return { kind: "enter", messages: [...decision.messages, injectionMessage(injection)] };
|
|
18901
19183
|
},
|
|
18902
19184
|
async turnStopping({ agent }) {
|
|
18903
|
-
const workspace =
|
|
19185
|
+
const workspace = resolve4(agent);
|
|
18904
19186
|
if (!workspace) return;
|
|
18905
19187
|
const sessionId = agent.session.header.id;
|
|
18906
19188
|
liveAgents.set(sessionId, agent);
|
|
@@ -18908,7 +19190,6 @@ function createDshHooks(resolve3) {
|
|
|
18908
19190
|
},
|
|
18909
19191
|
disposed({ agent }) {
|
|
18910
19192
|
liveAgents.delete(agent.session.header.id);
|
|
18911
|
-
lastInjected.delete(agent.session.header.id);
|
|
18912
19193
|
}
|
|
18913
19194
|
};
|
|
18914
19195
|
}
|
|
@@ -18986,6 +19267,47 @@ export {
|
|
|
18986
19267
|
dsh_default as default,
|
|
18987
19268
|
dshSessionEvents,
|
|
18988
19269
|
inject,
|
|
19270
|
+
lastInjectedText,
|
|
18989
19271
|
name,
|
|
19272
|
+
ownEvents,
|
|
18990
19273
|
toDshParameters
|
|
18991
19274
|
};
|
|
19275
|
+
/*! Bundled license information:
|
|
19276
|
+
|
|
19277
|
+
smol-toml/dist/error.js:
|
|
19278
|
+
smol-toml/dist/primitive.js:
|
|
19279
|
+
smol-toml/dist/date.js:
|
|
19280
|
+
smol-toml/dist/extract.js:
|
|
19281
|
+
smol-toml/dist/util.js:
|
|
19282
|
+
smol-toml/dist/struct.js:
|
|
19283
|
+
smol-toml/dist/parse.js:
|
|
19284
|
+
smol-toml/dist/stringify.js:
|
|
19285
|
+
smol-toml/dist/index.js:
|
|
19286
|
+
(*!
|
|
19287
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
19288
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
19289
|
+
*
|
|
19290
|
+
* Redistribution and use in source and binary forms, with or without
|
|
19291
|
+
* modification, are permitted provided that the following conditions are met:
|
|
19292
|
+
*
|
|
19293
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
19294
|
+
* list of conditions and the following disclaimer.
|
|
19295
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
19296
|
+
* this list of conditions and the following disclaimer in the
|
|
19297
|
+
* documentation and/or other materials provided with the distribution.
|
|
19298
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
19299
|
+
* may be used to endorse or promote products derived from this software without
|
|
19300
|
+
* specific prior written permission.
|
|
19301
|
+
*
|
|
19302
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
19303
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19304
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
19305
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
19306
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
19307
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
19308
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
19309
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
19310
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
19311
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
19312
|
+
*)
|
|
19313
|
+
*/
|