@vectorize-io/hindsight-coding-agents 0.8.1 → 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 +19 -5
- package/dist/antigravity-hook.js +98 -42
- package/dist/antigravity-statusline.js +6 -6
- package/dist/antigravity-stop-hook.js +135 -51
- package/dist/claude-hook.js +98 -42
- package/dist/claude-sessionstart-hook.js +386 -99
- package/dist/claude-stop-hook.js +135 -51
- package/dist/cline.js +433 -118
- package/dist/codebuddy-hook.js +98 -42
- package/dist/codebuddy-sessionstart-hook.js +386 -99
- package/dist/codebuddy-stop-hook.js +135 -51
- package/dist/codex-hook.js +98 -42
- package/dist/codex-sessionstart-hook.js +386 -99
- package/dist/codex-stop-hook.js +135 -51
- package/dist/copilot-hook.js +98 -42
- package/dist/copilot-sessionstart-hook.js +386 -99
- package/dist/copilot-stop-hook.js +135 -51
- package/dist/cursor-hook.js +98 -42
- package/dist/cursor-sessionstart-hook.js +386 -99
- package/dist/cursor-stop-hook.js +135 -51
- package/dist/daemon-start.js +10 -10
- package/dist/dcode-hook.js +98 -42
- package/dist/dcode-sessionstart-hook.js +386 -99
- package/dist/dcode-stop-hook.js +135 -51
- package/dist/deepen.js +193 -52
- package/dist/devin-hook.js +98 -42
- package/dist/devin-sessionstart-hook.js +386 -99
- package/dist/devin-stop-hook.js +135 -51
- package/dist/droid-hook.js +98 -42
- package/dist/droid-sessionstart-hook.js +386 -99
- package/dist/droid-stop-hook.js +135 -51
- package/dist/dsh.js +452 -125
- package/dist/grok-hook.js +98 -42
- package/dist/grok-sessionstart-hook.js +386 -99
- package/dist/grok-stop-hook.js +135 -51
- package/dist/hindsight-seed.js +6 -6
- package/dist/index.js +457 -137
- package/dist/installer.js +92 -80
- package/dist/kilo.js +457 -137
- package/dist/kimi-hook.js +98 -42
- package/dist/kimi-sessionstart-hook.js +386 -99
- package/dist/kimi-stop-hook.js +135 -51
- package/dist/mcp-server.js +180 -65
- package/dist/opencode2.js +613 -131
- package/dist/pi.js +433 -125
- package/dist/prime-agent.js +433 -125
- package/dist/qwen-hook.js +98 -42
- package/dist/qwen-sessionstart-hook.js +386 -99
- package/dist/qwen-stop-hook.js +135 -51
- package/dist/status.js +76 -18
- package/dist/survey-supervisor.js +73 -9
- package/dist/traecode-hook.js +98 -42
- package/dist/traecode-sessionstart-hook.js +386 -99
- package/dist/traecode-stop-hook.js +135 -51
- package/dist/workbuddy-hook.js +98 -42
- package/dist/workbuddy-sessionstart-hook.js +386 -99
- package/dist/workbuddy-stop-hook.js +135 -51
- package/dist/zcode-hook.js +98 -42
- package/dist/zcode-sessionstart-hook.js +386 -99
- package/dist/zcode-stop-hook.js +135 -51
- package/index.js +4 -1
- package/package.json +6 -4
- package/plugin.json +1 -1
- package/skill/SKILL.md +16 -4
package/dist/cline.js
CHANGED
|
@@ -225,14 +225,14 @@ function probeGitLayout(directory) {
|
|
|
225
225
|
var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
|
|
226
226
|
function applyTemplate(template, resolvers, what) {
|
|
227
227
|
return template.replace(PLACEHOLDER, (_, name) => {
|
|
228
|
-
const
|
|
229
|
-
if (!
|
|
228
|
+
const resolve4 = resolvers[name];
|
|
229
|
+
if (!resolve4) {
|
|
230
230
|
console.error(
|
|
231
231
|
`hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
|
|
232
232
|
);
|
|
233
233
|
return "unknown";
|
|
234
234
|
}
|
|
235
|
-
return
|
|
235
|
+
return resolve4();
|
|
236
236
|
});
|
|
237
237
|
}
|
|
238
238
|
|
|
@@ -653,29 +653,33 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
|
|
|
653
653
|
}
|
|
654
654
|
|
|
655
655
|
// package.json
|
|
656
|
-
var version = "0.8.
|
|
656
|
+
var version = "0.8.3";
|
|
657
657
|
|
|
658
658
|
// src/core/util.ts
|
|
659
|
-
import { accessSync, constants } from "fs";
|
|
660
|
-
import { delimiter, join as join6 } from "path";
|
|
661
|
-
function binOnPath(bin) {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
659
|
+
import { accessSync, constants, statSync as statSync2 } from "fs";
|
|
660
|
+
import { delimiter, extname, isAbsolute as isAbsolute2, join as join6, resolve as resolve2 } from "path";
|
|
661
|
+
function binOnPath(bin, opts = {}) {
|
|
662
|
+
const platform = opts.platform ?? process.platform;
|
|
663
|
+
const env = opts.env ?? process.env;
|
|
664
|
+
const runnable = (file2) => {
|
|
665
|
+
try {
|
|
666
|
+
if (!statSync2(file2).isFile()) return false;
|
|
667
|
+
if (platform !== "win32") accessSync(file2, constants.X_OK);
|
|
665
668
|
return true;
|
|
669
|
+
} catch {
|
|
670
|
+
return false;
|
|
666
671
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
672
|
+
};
|
|
673
|
+
if (isAbsolute2(bin) || /[\\/]/.test(bin)) return runnable(bin) ? resolve2(bin) : void 0;
|
|
674
|
+
const names = platform !== "win32" || extname(bin) ? [bin] : (opts.exts ?? (env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";")).filter(Boolean).map((ext) => bin + ext.toLowerCase());
|
|
675
|
+
for (const dir of (env.PATH || "").split(delimiter)) {
|
|
676
|
+
if (!dir) continue;
|
|
677
|
+
for (const name of names) {
|
|
678
|
+
const file2 = join6(dir, name);
|
|
679
|
+
if (runnable(file2)) return resolve2(file2);
|
|
674
680
|
}
|
|
675
|
-
return false;
|
|
676
|
-
} catch {
|
|
677
|
-
return false;
|
|
678
681
|
}
|
|
682
|
+
return void 0;
|
|
679
683
|
}
|
|
680
684
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
681
685
|
function semverGte(version3, min) {
|
|
@@ -945,15 +949,19 @@ var HindsightClient = class {
|
|
|
945
949
|
}
|
|
946
950
|
/**
|
|
947
951
|
* Whether this server honours `operation_id` on an async retain, and can therefore be appended to
|
|
948
|
-
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed
|
|
952
|
+
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed via the version endpoint; anything
|
|
949
953
|
* unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
|
|
954
|
+
* Only a "yes" is cached: a long-lived plugin client would otherwise keep replacing for the rest
|
|
955
|
+
* of the process after one probe that hit a restarting server (#5735).
|
|
950
956
|
*/
|
|
951
957
|
async supportsIdempotentRetain() {
|
|
952
|
-
if (this.idempotentRetain
|
|
953
|
-
|
|
954
|
-
|
|
958
|
+
if (this.idempotentRetain) return true;
|
|
959
|
+
const supported = await this.probeIdempotentRetain();
|
|
960
|
+
if (supported || this.idempotentRetain === void 0) {
|
|
961
|
+
this.log(`server retain idempotency: ${supported ? "supported" : "unavailable"}`);
|
|
955
962
|
}
|
|
956
|
-
|
|
963
|
+
this.idempotentRetain = supported;
|
|
964
|
+
return supported;
|
|
957
965
|
}
|
|
958
966
|
/** `/v1/version` first: an ingress that routes only `/v1` to the API (the Helm chart's default)
|
|
959
967
|
* hands a bare `/version` to the control plane, whose HTML 404 or login redirect read as "no",
|
|
@@ -1987,15 +1995,15 @@ function stagedVersion(pkgRoot) {
|
|
|
1987
1995
|
}
|
|
1988
1996
|
}
|
|
1989
1997
|
function isNewer(candidate, current2) {
|
|
1990
|
-
const
|
|
1998
|
+
const parse4 = (v) => {
|
|
1991
1999
|
const [core = "", ...rest] = v.trim().split("-");
|
|
1992
2000
|
return {
|
|
1993
2001
|
nums: core.split(".").map((n) => Number.parseInt(n, 10)),
|
|
1994
2002
|
pre: rest.length > 0
|
|
1995
2003
|
};
|
|
1996
2004
|
};
|
|
1997
|
-
const a =
|
|
1998
|
-
const b =
|
|
2005
|
+
const a = parse4(candidate);
|
|
2006
|
+
const b = parse4(current2);
|
|
1999
2007
|
if (a.nums.length !== 3 || b.nums.length !== 3) return false;
|
|
2000
2008
|
if (a.nums.some(Number.isNaN) || b.nums.some(Number.isNaN)) return false;
|
|
2001
2009
|
for (let i = 0; i < 3; i++) {
|
|
@@ -2072,7 +2080,7 @@ function spawnNpm(spawnImpl, bin, args, opts) {
|
|
|
2072
2080
|
return process.platform === "win32" ? spawnImpl([bin, ...args].join(" "), { ...opts, shell: true }) : spawnImpl(bin, args, opts);
|
|
2073
2081
|
}
|
|
2074
2082
|
async function npmViewVersion(pkg, spawnImpl = realSpawn2) {
|
|
2075
|
-
return new Promise((
|
|
2083
|
+
return new Promise((resolve4) => {
|
|
2076
2084
|
let out = "";
|
|
2077
2085
|
let settled = false;
|
|
2078
2086
|
let deadline;
|
|
@@ -2081,7 +2089,7 @@ async function npmViewVersion(pkg, spawnImpl = realSpawn2) {
|
|
|
2081
2089
|
settled = true;
|
|
2082
2090
|
if (deadline) clearTimeout(deadline);
|
|
2083
2091
|
if (reason) log.info("auto-update", `version check failed: ${reason}`);
|
|
2084
|
-
|
|
2092
|
+
resolve4(v);
|
|
2085
2093
|
};
|
|
2086
2094
|
try {
|
|
2087
2095
|
const child = spawnNpm(spawnImpl, "npm", ["view", pkg, "version", "--json"], {
|
|
@@ -2278,8 +2286,8 @@ async function waitBounded(p, ms) {
|
|
|
2278
2286
|
try {
|
|
2279
2287
|
await Promise.race([
|
|
2280
2288
|
p,
|
|
2281
|
-
new Promise((
|
|
2282
|
-
timer = setTimeout(
|
|
2289
|
+
new Promise((resolve4) => {
|
|
2290
|
+
timer = setTimeout(resolve4, Math.max(ms, 0));
|
|
2283
2291
|
})
|
|
2284
2292
|
]);
|
|
2285
2293
|
} finally {
|
|
@@ -16914,7 +16922,7 @@ function date4(params) {
|
|
|
16914
16922
|
config(en_default());
|
|
16915
16923
|
|
|
16916
16924
|
// src/core/knowledge-tools.ts
|
|
16917
|
-
import { createHash as
|
|
16925
|
+
import { createHash as createHash4 } from "crypto";
|
|
16918
16926
|
import { existsSync as existsSync4 } from "fs";
|
|
16919
16927
|
import { homedir as homedir6 } from "os";
|
|
16920
16928
|
import { join as join12 } from "path";
|
|
@@ -16924,20 +16932,53 @@ import { execFileSync as execFileSync4 } from "child_process";
|
|
|
16924
16932
|
|
|
16925
16933
|
// src/core/git.ts
|
|
16926
16934
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
16927
|
-
import { resolve as
|
|
16935
|
+
import { resolve as resolve3 } from "path";
|
|
16936
|
+
|
|
16937
|
+
// src/core/uuid.ts
|
|
16938
|
+
import { createHash as createHash2 } from "crypto";
|
|
16939
|
+
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
16940
|
+
function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
|
|
16941
|
+
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
16942
|
+
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
16943
|
+
const bytes = Buffer.from(
|
|
16944
|
+
createHash2("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
|
|
16945
|
+
);
|
|
16946
|
+
bytes[6] = bytes[6] & 15 | 80;
|
|
16947
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
16948
|
+
const hex3 = bytes.toString("hex");
|
|
16949
|
+
return [
|
|
16950
|
+
hex3.slice(0, 8),
|
|
16951
|
+
hex3.slice(8, 12),
|
|
16952
|
+
hex3.slice(12, 16),
|
|
16953
|
+
hex3.slice(16, 20),
|
|
16954
|
+
hex3.slice(20)
|
|
16955
|
+
].join("-");
|
|
16956
|
+
}
|
|
16957
|
+
|
|
16958
|
+
// src/core/git.ts
|
|
16959
|
+
var US = "";
|
|
16960
|
+
var RS = "";
|
|
16928
16961
|
var GITLOG_HEAD = "gitlog-head:";
|
|
16929
|
-
|
|
16962
|
+
var GITLOG_FORMAT = `--format=%h${US}%ad${US}%an${US}%s${US}%b${RS}`;
|
|
16963
|
+
function runGit(repo, args, env) {
|
|
16930
16964
|
return execFileSync2("git", ["-C", repo, "-c", "log.showSignature=false", ...args], {
|
|
16931
16965
|
encoding: "utf8",
|
|
16932
16966
|
maxBuffer: 1 << 28,
|
|
16933
16967
|
windowsHide: true,
|
|
16968
|
+
env,
|
|
16934
16969
|
// execFileSync otherwise forwards failed git stderr into the host's TUI,
|
|
16935
16970
|
// even when callers catch the error. Keep diagnostics on the error instead.
|
|
16936
16971
|
stdio: ["ignore", "pipe", "pipe"]
|
|
16937
16972
|
});
|
|
16938
16973
|
}
|
|
16974
|
+
function git(repo, ...args) {
|
|
16975
|
+
return runGit(repo, args);
|
|
16976
|
+
}
|
|
16977
|
+
function gitLocal(repo, ...args) {
|
|
16978
|
+
return runGit(repo, args, { ...process.env, GIT_NO_LAZY_FETCH: "1" });
|
|
16979
|
+
}
|
|
16939
16980
|
function repoNameOf(repo) {
|
|
16940
|
-
return projectNameOf(
|
|
16981
|
+
return projectNameOf(resolve3(repo));
|
|
16941
16982
|
}
|
|
16942
16983
|
function gitHeadSha(dir) {
|
|
16943
16984
|
try {
|
|
@@ -16949,7 +16990,7 @@ function gitHeadSha(dir) {
|
|
|
16949
16990
|
function commitsSince(dir, sinceSha) {
|
|
16950
16991
|
if (!/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(sinceSha)) return null;
|
|
16951
16992
|
try {
|
|
16952
|
-
const n = Number.parseInt(
|
|
16993
|
+
const n = Number.parseInt(gitLocal(dir, "rev-list", "--count", `${sinceSha}..HEAD`).trim(), 10);
|
|
16953
16994
|
return Number.isFinite(n) ? n : null;
|
|
16954
16995
|
} catch {
|
|
16955
16996
|
return null;
|
|
@@ -16974,12 +17015,198 @@ async function gitLogIsCurrent(client, repo, head) {
|
|
|
16974
17015
|
|
|
16975
17016
|
// src/core/survey.ts
|
|
16976
17017
|
import { execFileSync as execFileSync3, spawn as realSpawn5 } from "child_process";
|
|
16977
|
-
import { createHash as
|
|
16978
|
-
import { existsSync as existsSync3 } from "fs";
|
|
17018
|
+
import { createHash as createHash3 } from "crypto";
|
|
17019
|
+
import { existsSync as existsSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
16979
17020
|
import { homedir as homedir5, tmpdir as tmpdir2 } from "os";
|
|
16980
17021
|
import { dirname as dirname7, join as join11 } from "path";
|
|
16981
17022
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
16982
17023
|
|
|
17024
|
+
// node_modules/smol-toml/dist/stringify.js
|
|
17025
|
+
var BARE_KEY = /^[a-z0-9-_]+$/i;
|
|
17026
|
+
var HAS_WELLFORMED = !!"".isWellFormed;
|
|
17027
|
+
function extendedTypeOf(obj) {
|
|
17028
|
+
let type = typeof obj;
|
|
17029
|
+
if (type === "object") {
|
|
17030
|
+
if (Array.isArray(obj))
|
|
17031
|
+
return "array";
|
|
17032
|
+
if (typeof obj.getUTCDate === "function" && obj instanceof Date)
|
|
17033
|
+
return "date";
|
|
17034
|
+
if (globalThis.Temporal) {
|
|
17035
|
+
if (obj.until) {
|
|
17036
|
+
if (obj instanceof Temporal.ZonedDateTime)
|
|
17037
|
+
return "temporal/tz+uc";
|
|
17038
|
+
if (obj instanceof Temporal.PlainDateTime || obj instanceof Temporal.PlainDate)
|
|
17039
|
+
return "temporal/uc";
|
|
17040
|
+
if (obj instanceof Temporal.PlainTime || obj instanceof Temporal.Instant)
|
|
17041
|
+
return "temporal";
|
|
17042
|
+
if (obj instanceof Temporal.PlainYearMonth)
|
|
17043
|
+
return "temporal/x";
|
|
17044
|
+
} else if (obj.toPlainDate && obj instanceof Temporal.PlainMonthDay || obj.negated && obj instanceof Temporal.Duration) {
|
|
17045
|
+
return "temporal/x";
|
|
17046
|
+
}
|
|
17047
|
+
}
|
|
17048
|
+
}
|
|
17049
|
+
return type;
|
|
17050
|
+
}
|
|
17051
|
+
function isArrayOfTables(obj) {
|
|
17052
|
+
for (let i = 0; i < obj.length; i++) {
|
|
17053
|
+
if (extendedTypeOf(obj[i]) !== "object")
|
|
17054
|
+
return false;
|
|
17055
|
+
}
|
|
17056
|
+
return obj.length != 0;
|
|
17057
|
+
}
|
|
17058
|
+
function formatWellFormedStringUnchecked(s) {
|
|
17059
|
+
return JSON.stringify(s).replaceAll("\x7F", "\\u007f");
|
|
17060
|
+
}
|
|
17061
|
+
function formatString(s) {
|
|
17062
|
+
return formatWellFormedStringUnchecked(HAS_WELLFORMED ? s.toWellFormed() : s);
|
|
17063
|
+
}
|
|
17064
|
+
function formatKey(s) {
|
|
17065
|
+
if (BARE_KEY.test(s))
|
|
17066
|
+
return s;
|
|
17067
|
+
if (HAS_WELLFORMED && !s.isWellFormed())
|
|
17068
|
+
throw new RangeError("key contains illegal lone surrogates");
|
|
17069
|
+
return formatWellFormedStringUnchecked(s);
|
|
17070
|
+
}
|
|
17071
|
+
function stringifyValue(val, type, depth, numberAsFloat, strictTemporal) {
|
|
17072
|
+
if (depth === 0) {
|
|
17073
|
+
throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
17074
|
+
}
|
|
17075
|
+
switch (type) {
|
|
17076
|
+
// @ts-expect-error -- intentional fallthrough case
|
|
17077
|
+
case "number":
|
|
17078
|
+
if (isNaN(val))
|
|
17079
|
+
return "nan";
|
|
17080
|
+
if (val === Infinity)
|
|
17081
|
+
return "inf";
|
|
17082
|
+
if (val === -Infinity)
|
|
17083
|
+
return "-inf";
|
|
17084
|
+
if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val)))
|
|
17085
|
+
return val.toFixed(1);
|
|
17086
|
+
case "bigint":
|
|
17087
|
+
case "boolean":
|
|
17088
|
+
case "temporal":
|
|
17089
|
+
return val.toString();
|
|
17090
|
+
case "string":
|
|
17091
|
+
return formatString(val);
|
|
17092
|
+
case "date":
|
|
17093
|
+
if (isNaN(val.getTime()))
|
|
17094
|
+
throw new TypeError("cannot serialize invalid date");
|
|
17095
|
+
return val.toISOString();
|
|
17096
|
+
case "object":
|
|
17097
|
+
return stringifyInlineTable(val, depth, numberAsFloat, strictTemporal);
|
|
17098
|
+
case "array":
|
|
17099
|
+
return stringifyArray(val, depth, numberAsFloat, strictTemporal);
|
|
17100
|
+
// @ts-expect-error -- intentional fallthrough case
|
|
17101
|
+
case "temporal/tz+uc":
|
|
17102
|
+
if (strictTemporal) {
|
|
17103
|
+
let tz = val.timeZoneId;
|
|
17104
|
+
let tzc = tz.charCodeAt(0);
|
|
17105
|
+
if (
|
|
17106
|
+
// Classic offset
|
|
17107
|
+
tzc !== 43 && tzc !== 45 && // Fast pre-check pass; see below for the actually accepted values
|
|
17108
|
+
(tzc !== 85 && tzc !== 71 && tzc !== 90 && tzc !== 69 || // UTC and its aliases; Temporal implementations don't all canonicalise unfortunately
|
|
17109
|
+
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.
|
|
17110
|
+
!tz.startsWith("GMT") && tz !== "Greenwich" && // Etc/* are all safe to downgrade to offset (either UTC, GMT, or offset)
|
|
17111
|
+
!tz.startsWith("Etc/"))
|
|
17112
|
+
) {
|
|
17113
|
+
throw new TypeError("Temporal objects with an IANA timezone are not allowed in Temporal strict mode");
|
|
17114
|
+
}
|
|
17115
|
+
}
|
|
17116
|
+
case "temporal/uc":
|
|
17117
|
+
if (strictTemporal && val.calendarId !== "iso8601")
|
|
17118
|
+
throw new TypeError("Temporal objects with a non-default calendar are not allowed in Temporal strict mode");
|
|
17119
|
+
return val.toString({
|
|
17120
|
+
calendarName: "never",
|
|
17121
|
+
timeZoneName: "never"
|
|
17122
|
+
});
|
|
17123
|
+
case "temporal/x":
|
|
17124
|
+
throw new TypeError("Unsupported " + val[Symbol.toStringTag]);
|
|
17125
|
+
}
|
|
17126
|
+
}
|
|
17127
|
+
function stringifyInlineTable(obj, depth, numberAsFloat, strictTemporal) {
|
|
17128
|
+
let keys = Object.keys(obj);
|
|
17129
|
+
if (keys.length === 0)
|
|
17130
|
+
return "{}";
|
|
17131
|
+
let res = "{ ";
|
|
17132
|
+
for (let i = 0; i < keys.length; i++) {
|
|
17133
|
+
let k = keys[i];
|
|
17134
|
+
if (i)
|
|
17135
|
+
res += ", ";
|
|
17136
|
+
res += formatKey(k) + " = " + stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat, strictTemporal);
|
|
17137
|
+
}
|
|
17138
|
+
return res + " }";
|
|
17139
|
+
}
|
|
17140
|
+
function stringifyArray(array2, depth, numberAsFloat, strictTemporal) {
|
|
17141
|
+
if (array2.length === 0)
|
|
17142
|
+
return "[]";
|
|
17143
|
+
let res = "[ ";
|
|
17144
|
+
for (let i = 0; i < array2.length; i++) {
|
|
17145
|
+
if (i)
|
|
17146
|
+
res += ", ";
|
|
17147
|
+
if (array2[i] === null || array2[i] === void 0) {
|
|
17148
|
+
throw new TypeError("arrays cannot contain null or undefined values");
|
|
17149
|
+
}
|
|
17150
|
+
res += stringifyValue(array2[i], extendedTypeOf(array2[i]), depth - 1, numberAsFloat, strictTemporal);
|
|
17151
|
+
}
|
|
17152
|
+
return res + " ]";
|
|
17153
|
+
}
|
|
17154
|
+
function stringifyArrayTable(array2, key, depth, numberAsFloat, strictTemporal) {
|
|
17155
|
+
if (depth === 0) {
|
|
17156
|
+
throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
17157
|
+
}
|
|
17158
|
+
let res = "";
|
|
17159
|
+
for (let i = 0; i < array2.length; i++) {
|
|
17160
|
+
res += `${res && "\n"}[[${key}]]
|
|
17161
|
+
`;
|
|
17162
|
+
res += stringifyTable(0, array2[i], key, depth, numberAsFloat, strictTemporal);
|
|
17163
|
+
}
|
|
17164
|
+
return res;
|
|
17165
|
+
}
|
|
17166
|
+
function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat, strictTemporal) {
|
|
17167
|
+
if (depth === 0) {
|
|
17168
|
+
throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
17169
|
+
}
|
|
17170
|
+
let preamble = "";
|
|
17171
|
+
let tables = "";
|
|
17172
|
+
let keys = Object.keys(obj);
|
|
17173
|
+
for (let i = 0; i < keys.length; i++) {
|
|
17174
|
+
let k = keys[i];
|
|
17175
|
+
if (obj[k] !== null && obj[k] !== void 0) {
|
|
17176
|
+
let type = extendedTypeOf(obj[k]);
|
|
17177
|
+
if (type === "symbol" || type === "function") {
|
|
17178
|
+
throw new TypeError(`cannot serialize values of type '${type}'`);
|
|
17179
|
+
}
|
|
17180
|
+
let key = formatKey(k);
|
|
17181
|
+
if (type === "array" && isArrayOfTables(obj[k])) {
|
|
17182
|
+
tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat, strictTemporal);
|
|
17183
|
+
} else if (type === "object") {
|
|
17184
|
+
let tblKey = prefix ? `${prefix}.${key}` : key;
|
|
17185
|
+
tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat, strictTemporal);
|
|
17186
|
+
} else {
|
|
17187
|
+
preamble += key;
|
|
17188
|
+
preamble += " = ";
|
|
17189
|
+
preamble += stringifyValue(obj[k], type, depth, numberAsFloat, strictTemporal);
|
|
17190
|
+
preamble += "\n";
|
|
17191
|
+
}
|
|
17192
|
+
}
|
|
17193
|
+
}
|
|
17194
|
+
if (tableKey && (preamble || !tables))
|
|
17195
|
+
preamble = preamble ? `[${tableKey}]
|
|
17196
|
+
${preamble}` : `[${tableKey}]`;
|
|
17197
|
+
return preamble && tables ? `${preamble}
|
|
17198
|
+
${tables}` : preamble || tables;
|
|
17199
|
+
}
|
|
17200
|
+
function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false, strictTemporal = false } = {}) {
|
|
17201
|
+
if (extendedTypeOf(obj) !== "object") {
|
|
17202
|
+
throw new TypeError("stringify can only be called with an object");
|
|
17203
|
+
}
|
|
17204
|
+
let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat, strictTemporal);
|
|
17205
|
+
if (str[str.length - 1] !== "\n")
|
|
17206
|
+
return str + "\n";
|
|
17207
|
+
return str;
|
|
17208
|
+
}
|
|
17209
|
+
|
|
16983
17210
|
// src/core/survey-lease.ts
|
|
16984
17211
|
import { spawn as realSpawn4 } from "child_process";
|
|
16985
17212
|
import { randomUUID } from "crypto";
|
|
@@ -16990,7 +17217,7 @@ import {
|
|
|
16990
17217
|
renameSync as renameSync2,
|
|
16991
17218
|
rmdirSync,
|
|
16992
17219
|
rmSync,
|
|
16993
|
-
statSync as
|
|
17220
|
+
statSync as statSync3,
|
|
16994
17221
|
unlinkSync as unlinkSync2,
|
|
16995
17222
|
utimesSync,
|
|
16996
17223
|
writeFileSync as writeFileSync2
|
|
@@ -17027,7 +17254,7 @@ function reclaimIfStale(directory, staleMs) {
|
|
|
17027
17254
|
return true;
|
|
17028
17255
|
}
|
|
17029
17256
|
if (owners.length !== 1) return false;
|
|
17030
|
-
const age = Date.now() -
|
|
17257
|
+
const age = Date.now() - statSync3(join10(directory, owners[0])).mtimeMs;
|
|
17031
17258
|
if (Math.abs(age) <= staleMs) return false;
|
|
17032
17259
|
releaseLease({ directory, owner: owners[0] });
|
|
17033
17260
|
return true;
|
|
@@ -17090,7 +17317,7 @@ function opencodeCanDefineSurveyAgent(bin) {
|
|
|
17090
17317
|
windowsHide: true,
|
|
17091
17318
|
stdio: ["ignore", "pipe", "ignore"]
|
|
17092
17319
|
});
|
|
17093
|
-
return Number(/(\d+)\./.exec(out)?.[1] ?? 0)
|
|
17320
|
+
return Number(/(\d+)\./.exec(out)?.[1] ?? 0) === 1;
|
|
17094
17321
|
} catch {
|
|
17095
17322
|
return false;
|
|
17096
17323
|
}
|
|
@@ -17105,6 +17332,7 @@ var SURVEY_DISALLOWED_TOOLS = [
|
|
|
17105
17332
|
"WebSearch",
|
|
17106
17333
|
"Task"
|
|
17107
17334
|
];
|
|
17335
|
+
var tomlValue = (value) => stringify({ v: value }).slice("v = ".length).trim();
|
|
17108
17336
|
function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
17109
17337
|
const env = {
|
|
17110
17338
|
...process.env,
|
|
@@ -17163,9 +17391,9 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
17163
17391
|
"-c",
|
|
17164
17392
|
`mcp_servers.hindsight.command="node"`,
|
|
17165
17393
|
"-c",
|
|
17166
|
-
`mcp_servers.hindsight.args
|
|
17394
|
+
`mcp_servers.hindsight.args=${tomlValue([opts.mcpServerPath])}`,
|
|
17167
17395
|
"-c",
|
|
17168
|
-
`mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD
|
|
17396
|
+
`mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD=${tomlValue(repoDir)}`,
|
|
17169
17397
|
"-c",
|
|
17170
17398
|
`mcp_servers.hindsight.env.HINDSIGHT_MCP_HARNESS="codex"`,
|
|
17171
17399
|
SURVEY_PROMPT
|
|
@@ -17189,10 +17417,19 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
17189
17417
|
}
|
|
17190
17418
|
}
|
|
17191
17419
|
}
|
|
17420
|
+
var SURVEY_MAX_ATTEMPTS = 3;
|
|
17421
|
+
function surveyAttempts(file2, sha) {
|
|
17422
|
+
try {
|
|
17423
|
+
const state = JSON.parse(readFileSync5(file2, "utf8"));
|
|
17424
|
+
return state.sha === sha && typeof state.attempts === "number" ? state.attempts : 0;
|
|
17425
|
+
} catch {
|
|
17426
|
+
return 0;
|
|
17427
|
+
}
|
|
17428
|
+
}
|
|
17192
17429
|
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
17193
17430
|
try {
|
|
17194
17431
|
const spawnFn = opts.spawn ?? realSpawn5;
|
|
17195
|
-
const
|
|
17432
|
+
const resolveBin = opts.resolveBin ?? ((bin) => binOnPath(bin, { exts: [".exe"] }));
|
|
17196
17433
|
const mcpServerPath = opts.mcpServerPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
17197
17434
|
const preferred = opts.harness ?? "claude-code";
|
|
17198
17435
|
const order = [
|
|
@@ -17206,10 +17443,16 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17206
17443
|
for (const harness of order) {
|
|
17207
17444
|
if (seen.has(harness)) continue;
|
|
17208
17445
|
seen.add(harness);
|
|
17209
|
-
const
|
|
17210
|
-
|
|
17211
|
-
if (
|
|
17446
|
+
const name = resolveAgentBin(harness, opts.claudeBin);
|
|
17447
|
+
const bin = resolveBin(name);
|
|
17448
|
+
if (!bin) {
|
|
17449
|
+
log.info("survey", `${harness}: ${name} not found, trying the next agent`);
|
|
17212
17450
|
continue;
|
|
17451
|
+
}
|
|
17452
|
+
if (harness === "opencode" && !(opts.opencodeDefinesAgent ?? opencodeCanDefineSurveyAgent)(bin)) {
|
|
17453
|
+
log.info("survey", `${harness}: ${bin} cannot define the survey agent, trying the next`);
|
|
17454
|
+
continue;
|
|
17455
|
+
}
|
|
17213
17456
|
const plan = buildSurveyPlan(harness, bin, repoDir, {
|
|
17214
17457
|
model: opts.model,
|
|
17215
17458
|
budgetUsd: opts.budgetUsd,
|
|
@@ -17217,13 +17460,20 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17217
17460
|
});
|
|
17218
17461
|
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
17219
17462
|
if (cfg.disabled) return false;
|
|
17220
|
-
const key =
|
|
17221
|
-
const
|
|
17222
|
-
|
|
17223
|
-
key,
|
|
17224
|
-
opts.lease?.staleMs ?? LEASE_STALE_MS
|
|
17225
|
-
);
|
|
17463
|
+
const key = createHash3("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
17464
|
+
const leaseDir = opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys");
|
|
17465
|
+
const lease = acquireLease(leaseDir, key, opts.lease?.staleMs ?? LEASE_STALE_MS);
|
|
17226
17466
|
if (!lease) return false;
|
|
17467
|
+
const attemptsFile = join11(
|
|
17468
|
+
leaseDir,
|
|
17469
|
+
`attempts-${createHash3("sha256").update(JSON.stringify([key, repoDir])).digest("hex")}.json`
|
|
17470
|
+
);
|
|
17471
|
+
const attempts = opts.sha ? surveyAttempts(attemptsFile, opts.sha) : 0;
|
|
17472
|
+
if (attempts >= SURVEY_MAX_ATTEMPTS) {
|
|
17473
|
+
log.info("survey", `${attempts} surveys already launched at ${opts.sha}, skipping`);
|
|
17474
|
+
releaseLease(lease);
|
|
17475
|
+
return false;
|
|
17476
|
+
}
|
|
17227
17477
|
const spec = {
|
|
17228
17478
|
lease,
|
|
17229
17479
|
bin: plan.bin,
|
|
@@ -17231,7 +17481,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17231
17481
|
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
17232
17482
|
};
|
|
17233
17483
|
const supervisorPath = opts.supervisorPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
17234
|
-
return await new Promise((
|
|
17484
|
+
return await new Promise((resolve4) => {
|
|
17235
17485
|
try {
|
|
17236
17486
|
const child = spawnFn("node", [supervisorPath], {
|
|
17237
17487
|
cwd: repoDir,
|
|
@@ -17241,19 +17491,31 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17241
17491
|
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
17242
17492
|
});
|
|
17243
17493
|
let spawned = false;
|
|
17244
|
-
child.on("error", () => {
|
|
17494
|
+
child.on("error", (e) => {
|
|
17245
17495
|
if (spawned) return;
|
|
17496
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17246
17497
|
releaseLease(lease);
|
|
17247
|
-
|
|
17498
|
+
resolve4(false);
|
|
17248
17499
|
});
|
|
17249
17500
|
child.once("spawn", () => {
|
|
17250
17501
|
spawned = true;
|
|
17251
17502
|
child.unref();
|
|
17252
|
-
|
|
17503
|
+
if (opts.sha) {
|
|
17504
|
+
try {
|
|
17505
|
+
writeFileSync3(
|
|
17506
|
+
attemptsFile,
|
|
17507
|
+
JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
|
|
17508
|
+
{ mode: 384 }
|
|
17509
|
+
);
|
|
17510
|
+
} catch {
|
|
17511
|
+
}
|
|
17512
|
+
}
|
|
17513
|
+
resolve4(true);
|
|
17253
17514
|
});
|
|
17254
|
-
} catch {
|
|
17515
|
+
} catch (e) {
|
|
17516
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17255
17517
|
releaseLease(lease);
|
|
17256
|
-
|
|
17518
|
+
resolve4(false);
|
|
17257
17519
|
}
|
|
17258
17520
|
});
|
|
17259
17521
|
}
|
|
@@ -17490,7 +17752,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
17490
17752
|
annotations: NON_DESTRUCTIVE_WRITE_ANNOTATIONS,
|
|
17491
17753
|
handler: guarded(async ({ title, content }) => {
|
|
17492
17754
|
const slug = title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
17493
|
-
const docId = /[^\x00-\x7f]/.test(title) || !slug ? `${slug || "doc"}--${
|
|
17755
|
+
const docId = /[^\x00-\x7f]/.test(title) || !slug ? `${slug || "doc"}--${createHash4("sha256").update(title).digest("hex")}` : slug;
|
|
17494
17756
|
const stamp = opts.stampFor?.();
|
|
17495
17757
|
const metadata = {
|
|
17496
17758
|
...stamp?.metadata,
|
|
@@ -17517,7 +17779,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
17517
17779
|
}
|
|
17518
17780
|
|
|
17519
17781
|
// src/core/retain-cursor.ts
|
|
17520
|
-
import { createHash as
|
|
17782
|
+
import { createHash as createHash5 } from "crypto";
|
|
17521
17783
|
var PENDING_MAX_AGE_MS = 12 * 60 * 60 * 1e3;
|
|
17522
17784
|
var PENDING_MAX_BYTES = 256 * 1024;
|
|
17523
17785
|
var MAX_CURSOR_PATHS = 16;
|
|
@@ -17531,9 +17793,21 @@ function pendingReplayable(cursor, now) {
|
|
|
17531
17793
|
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
17532
17794
|
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
17533
17795
|
}
|
|
17796
|
+
function advanceSegments(cursor, bank) {
|
|
17797
|
+
if (!cursor || cursor.bank === bank) return cursor?.segments;
|
|
17798
|
+
return [...cursor.segments ?? [{ bank: cursor.bank, from: 0 }], { bank, from: cursor.turns }];
|
|
17799
|
+
}
|
|
17800
|
+
function bankTurns(turns, segments, bank) {
|
|
17801
|
+
if (!segments) return turns;
|
|
17802
|
+
return turns.filter((_, i) => {
|
|
17803
|
+
let owner;
|
|
17804
|
+
for (const s of segments) if (s.from <= i) owner = s.bank;
|
|
17805
|
+
return owner === bank;
|
|
17806
|
+
});
|
|
17807
|
+
}
|
|
17534
17808
|
var MAX_CURSOR_OPS = 8;
|
|
17535
17809
|
function fingerprintTurns(turns, count) {
|
|
17536
|
-
const h =
|
|
17810
|
+
const h = createHash5("sha1").update(String(count));
|
|
17537
17811
|
for (let i = 0; i < count; i++) h.update("\n" + JSON.stringify(turns[i]));
|
|
17538
17812
|
return h.digest("hex");
|
|
17539
17813
|
}
|
|
@@ -17541,7 +17815,8 @@ function planRetain(turns, cursor, opts) {
|
|
|
17541
17815
|
if (!turns.length) return { mode: "skip" };
|
|
17542
17816
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
17543
17817
|
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
17544
|
-
if (cursor.bank !== opts.bank)
|
|
17818
|
+
if (cursor.bank !== opts.bank && !cursor.segments?.some((s) => s.bank === opts.bank))
|
|
17819
|
+
return { mode: "replace" };
|
|
17545
17820
|
const seen = cursor.paths ?? [];
|
|
17546
17821
|
const newFile = Boolean(opts.path && seen.length && !seen.includes(opts.path));
|
|
17547
17822
|
const continues = cursor.turns <= turns.length && fingerprintTurns(turns, cursor.turns) === cursor.fingerprint;
|
|
@@ -17557,27 +17832,6 @@ function memoryCursorStore() {
|
|
|
17557
17832
|
};
|
|
17558
17833
|
}
|
|
17559
17834
|
|
|
17560
|
-
// src/core/uuid.ts
|
|
17561
|
-
import { createHash as createHash5 } from "crypto";
|
|
17562
|
-
var HINDSIGHT_NAMESPACE = "e75686a4-e923-4326-a0d1-358f1c6c3eb4";
|
|
17563
|
-
function uuidV5(name, namespace = HINDSIGHT_NAMESPACE) {
|
|
17564
|
-
const ns = Buffer.from(namespace.replace(/-/g, ""), "hex");
|
|
17565
|
-
if (ns.length !== 16) throw new Error(`invalid UUID namespace: ${namespace}`);
|
|
17566
|
-
const bytes = Buffer.from(
|
|
17567
|
-
createHash5("sha1").update(ns).update(Buffer.from(name, "utf8")).digest().subarray(0, 16)
|
|
17568
|
-
);
|
|
17569
|
-
bytes[6] = bytes[6] & 15 | 80;
|
|
17570
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
17571
|
-
const hex3 = bytes.toString("hex");
|
|
17572
|
-
return [
|
|
17573
|
-
hex3.slice(0, 8),
|
|
17574
|
-
hex3.slice(8, 12),
|
|
17575
|
-
hex3.slice(12, 16),
|
|
17576
|
-
hex3.slice(16, 20),
|
|
17577
|
-
hex3.slice(20)
|
|
17578
|
-
].join("-");
|
|
17579
|
-
}
|
|
17580
|
-
|
|
17581
17835
|
// src/core/chat.ts
|
|
17582
17836
|
function withRefId(refId, turns, baseTs) {
|
|
17583
17837
|
return [{ role: "system", content: `REF-ID: ${refId}`, timestamp: baseTs }, ...turns];
|
|
@@ -17683,8 +17937,17 @@ async function writeSession(client, sessionId2, turns, startTs, harness, stamp,
|
|
|
17683
17937
|
let cursor = cursors?.read(sessionId2);
|
|
17684
17938
|
const probed = Boolean(cursors) && cursor?.appendSupported !== true;
|
|
17685
17939
|
const appendSupported = Boolean(cursors) && (cursor?.appendSupported === true || await supportsAppend(client));
|
|
17940
|
+
const moved = Boolean(cursor && cursor.bank !== client.bank);
|
|
17941
|
+
if (moved)
|
|
17942
|
+
log.warn(harness ?? "", "session moved to another bank mid-session", {
|
|
17943
|
+
session: sessionId2,
|
|
17944
|
+
from: cursor?.bank,
|
|
17945
|
+
to: client.bank,
|
|
17946
|
+
atTurn: cursor?.turns
|
|
17947
|
+
});
|
|
17948
|
+
const segments = advanceSegments(cursor, client.bank);
|
|
17686
17949
|
let ops = [];
|
|
17687
|
-
if (appendSupported && cursor?.ops?.length && !cursor.dirty)
|
|
17950
|
+
if (appendSupported && cursor?.ops?.length && !cursor.dirty && !moved)
|
|
17688
17951
|
({ cursor, ops } = await settleOps(client, cursor));
|
|
17689
17952
|
const plan = planRetain(turns, cursor, {
|
|
17690
17953
|
appendSupported,
|
|
@@ -17693,7 +17956,7 @@ async function writeSession(client, sessionId2, turns, startTs, harness, stamp,
|
|
|
17693
17956
|
});
|
|
17694
17957
|
if (probed) diag(harness ?? "", "retain_mode", { mode: plan.mode, appendSupported });
|
|
17695
17958
|
const paths = plan.mode === "replace" ? transcriptPath ? [transcriptPath] : void 0 : advancePaths(cursor?.paths, transcriptPath);
|
|
17696
|
-
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
17959
|
+
const outbox = plan.mode === "replace" || moved ? [] : cursor?.pending ?? [];
|
|
17697
17960
|
if (plan.mode === "skip" && !outbox.length) return;
|
|
17698
17961
|
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
17699
17962
|
${refId}
|
|
@@ -17735,6 +17998,7 @@ ${content}`);
|
|
|
17735
17998
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
17736
17999
|
bank: client.bank,
|
|
17737
18000
|
...paths ? { paths } : {},
|
|
18001
|
+
...segments ? { segments } : {},
|
|
17738
18002
|
...appendSupported ? { appendSupported: true } : {}
|
|
17739
18003
|
};
|
|
17740
18004
|
const accepted = (id) => {
|
|
@@ -17747,9 +18011,14 @@ ${content}`);
|
|
|
17747
18011
|
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
17748
18012
|
};
|
|
17749
18013
|
if (plan.mode === "replace") {
|
|
17750
|
-
const
|
|
18014
|
+
const share = bankTurns(turns, segments, client.bank);
|
|
18015
|
+
if (!share.length) return;
|
|
18016
|
+
const content = renderSessionJsonl(refId, share, startTs);
|
|
18017
|
+
const base = cursor ? `${cursor.turns}
|
|
18018
|
+
${cursor.fingerprint}` : "";
|
|
17751
18019
|
cursors?.write(sessionId2, { ...next, dirty: true });
|
|
17752
|
-
const operationId = opId("replace",
|
|
18020
|
+
const operationId = opId("replace", `${base}
|
|
18021
|
+
${content}`);
|
|
17753
18022
|
await submitWithRetry(() => submit(content, operationId, false), stillOurs, retryUntil);
|
|
17754
18023
|
ops = [];
|
|
17755
18024
|
cursors?.write(sessionId2, accepted(operationId));
|
|
@@ -17776,7 +18045,7 @@ ${content}`);
|
|
|
17776
18045
|
}
|
|
17777
18046
|
|
|
17778
18047
|
// src/core/usage.ts
|
|
17779
|
-
import { readFileSync as
|
|
18048
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
17780
18049
|
import { join as join13 } from "path";
|
|
17781
18050
|
function usageFilePath() {
|
|
17782
18051
|
return process.env.HINDSIGHT_USAGE_FILE || join13(logsDir(), "usage.jsonl");
|
|
@@ -17859,12 +18128,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17859
18128
|
const base = resolversFor(ctx);
|
|
17860
18129
|
const cache = /* @__PURE__ */ new Map();
|
|
17861
18130
|
const resolvers = Object.fromEntries(
|
|
17862
|
-
Object.entries(base).map(([name,
|
|
18131
|
+
Object.entries(base).map(([name, resolve4]) => [
|
|
17863
18132
|
name,
|
|
17864
18133
|
() => {
|
|
17865
18134
|
const hit = cache.get(name);
|
|
17866
18135
|
if (hit !== void 0) return hit;
|
|
17867
|
-
const value =
|
|
18136
|
+
const value = resolve4();
|
|
17868
18137
|
cache.set(name, value);
|
|
17869
18138
|
return value;
|
|
17870
18139
|
}
|
|
@@ -17884,7 +18153,7 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17884
18153
|
}
|
|
17885
18154
|
|
|
17886
18155
|
// src/core/skill-sync.ts
|
|
17887
|
-
import { cpSync, existsSync as existsSync6, readFileSync as
|
|
18156
|
+
import { cpSync, existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
17888
18157
|
import { homedir as homedir7 } from "os";
|
|
17889
18158
|
import { dirname as dirname8, join as join15 } from "path";
|
|
17890
18159
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
@@ -17959,7 +18228,7 @@ function syncCompanionSkill(harness, opts = {}) {
|
|
|
17959
18228
|
const dstMd = join15(dst, "SKILL.md");
|
|
17960
18229
|
const installed = existsSync6(dstMd);
|
|
17961
18230
|
if (!installed && !opts.install) return;
|
|
17962
|
-
if (!installed ||
|
|
18231
|
+
if (!installed || readFileSync7(srcMd, "utf8") !== readFileSync7(dstMd, "utf8")) {
|
|
17963
18232
|
cpSync(src, dst, { recursive: true });
|
|
17964
18233
|
}
|
|
17965
18234
|
} catch {
|
|
@@ -17981,9 +18250,9 @@ function brandWord() {
|
|
|
17981
18250
|
}
|
|
17982
18251
|
|
|
17983
18252
|
// src/core/legacy.ts
|
|
17984
|
-
import { existsSync as existsSync7, readFileSync as
|
|
18253
|
+
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "fs";
|
|
17985
18254
|
import { homedir as homedir8 } from "os";
|
|
17986
|
-
import { join as join16, relative, isAbsolute as
|
|
18255
|
+
import { join as join16, relative, isAbsolute as isAbsolute3 } from "path";
|
|
17987
18256
|
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
17988
18257
|
function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")) {
|
|
17989
18258
|
const registry2 = readJson(join16(claudeDir, "plugins", "installed_plugins.json"));
|
|
@@ -17998,7 +18267,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
|
|
|
17998
18267
|
if (!i || typeof i !== "object") return false;
|
|
17999
18268
|
if (typeof i.projectPath !== "string") return true;
|
|
18000
18269
|
const rel = relative(i.projectPath, cwd);
|
|
18001
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
18270
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
18002
18271
|
});
|
|
18003
18272
|
if (active) return key;
|
|
18004
18273
|
}
|
|
@@ -18006,7 +18275,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
|
|
|
18006
18275
|
}
|
|
18007
18276
|
function readJson(path) {
|
|
18008
18277
|
try {
|
|
18009
|
-
const parsed = JSON.parse(
|
|
18278
|
+
const parsed = JSON.parse(readFileSync8(path, "utf8"));
|
|
18010
18279
|
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
18011
18280
|
} catch {
|
|
18012
18281
|
return void 0;
|
|
@@ -18018,7 +18287,7 @@ function legacyClaudePluginWarning(key) {
|
|
|
18018
18287
|
}
|
|
18019
18288
|
|
|
18020
18289
|
// src/core/session-cache.ts
|
|
18021
|
-
import { mkdirSync as mkdirSync4, readFileSync as
|
|
18290
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
18022
18291
|
import { tmpdir as tmpdir3 } from "os";
|
|
18023
18292
|
import { dirname as dirname9, join as join17 } from "path";
|
|
18024
18293
|
function sessionCacheFile(harness, sessionId2) {
|
|
@@ -18026,7 +18295,7 @@ function sessionCacheFile(harness, sessionId2) {
|
|
|
18026
18295
|
}
|
|
18027
18296
|
function readSessionCache(cacheFile) {
|
|
18028
18297
|
try {
|
|
18029
|
-
return JSON.parse(
|
|
18298
|
+
return JSON.parse(readFileSync9(cacheFile, "utf8"));
|
|
18030
18299
|
} catch {
|
|
18031
18300
|
return {};
|
|
18032
18301
|
}
|
|
@@ -18035,7 +18304,7 @@ function writeFileAtomic(path, body) {
|
|
|
18035
18304
|
mkdirSync4(dirname9(path), { recursive: true });
|
|
18036
18305
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
18037
18306
|
try {
|
|
18038
|
-
|
|
18307
|
+
writeFileSync4(tmp, body);
|
|
18039
18308
|
renameSync3(tmp, path);
|
|
18040
18309
|
} catch (e) {
|
|
18041
18310
|
try {
|
|
@@ -18145,12 +18414,13 @@ async function buildSessionStartContext(args) {
|
|
|
18145
18414
|
startSeed(cwd, { limit: cfg.seedLimit, harness });
|
|
18146
18415
|
if (cold) {
|
|
18147
18416
|
if (cfg.codebaseSurvey !== false) {
|
|
18417
|
+
const sha = resolveHeadSha(cwd);
|
|
18148
18418
|
const started = await startSurvey(cwd, {
|
|
18149
18419
|
harness,
|
|
18150
18420
|
model: cfg.surveyModel,
|
|
18151
|
-
budgetUsd: cfg.surveyBudgetUsd
|
|
18421
|
+
budgetUsd: cfg.surveyBudgetUsd,
|
|
18422
|
+
sha: sha ?? void 0
|
|
18152
18423
|
});
|
|
18153
|
-
const sha = resolveHeadSha(cwd);
|
|
18154
18424
|
if (started && sha) recordSurveyBaseline(sha);
|
|
18155
18425
|
}
|
|
18156
18426
|
diag(harness, "seed_started", { bank: bankId });
|
|
@@ -18171,7 +18441,8 @@ async function buildSessionStartContext(args) {
|
|
|
18171
18441
|
const started = await startSurvey(cwd, {
|
|
18172
18442
|
harness,
|
|
18173
18443
|
model: cfg.surveyModel,
|
|
18174
|
-
budgetUsd: cfg.surveyBudgetUsd
|
|
18444
|
+
budgetUsd: cfg.surveyBudgetUsd,
|
|
18445
|
+
sha
|
|
18175
18446
|
});
|
|
18176
18447
|
if (started) {
|
|
18177
18448
|
recordSurveyBaseline(sha);
|
|
@@ -18273,7 +18544,7 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
18273
18544
|
}
|
|
18274
18545
|
|
|
18275
18546
|
// src/core/turn-journal.ts
|
|
18276
|
-
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as
|
|
18547
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync10, statSync as statSync4 } from "fs";
|
|
18277
18548
|
import { tmpdir as tmpdir4 } from "os";
|
|
18278
18549
|
import { dirname as dirname10, join as join18 } from "path";
|
|
18279
18550
|
var JOURNAL_MAX_BYTES = 8 * 1024 * 1024;
|
|
@@ -18487,8 +18758,6 @@ var RuntimeCore = class {
|
|
|
18487
18758
|
fetchTranscript;
|
|
18488
18759
|
/** Write-backs started and not yet settled — what `flush` waits for. */
|
|
18489
18760
|
inFlight = /* @__PURE__ */ new Set();
|
|
18490
|
-
lastInjection = "";
|
|
18491
|
-
// most recent turn's injection block, keyed by nothing (see getInjection)
|
|
18492
18761
|
deferInitialReflect = false;
|
|
18493
18762
|
/** Host-notice channel (opencode/Kilo: client.tui.showToast via the adapter). Optional, fail-open. */
|
|
18494
18763
|
notify;
|
|
@@ -18560,7 +18829,11 @@ var RuntimeCore = class {
|
|
|
18560
18829
|
*/
|
|
18561
18830
|
async onPrompt(sessionId2, prompt) {
|
|
18562
18831
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
18563
|
-
if (!sessionId2
|
|
18832
|
+
if (!sessionId2) return;
|
|
18833
|
+
if (!prompt.trim()) {
|
|
18834
|
+
this.injection.delete(sessionId2);
|
|
18835
|
+
return;
|
|
18836
|
+
}
|
|
18564
18837
|
const turns = (this.turnCount.get(sessionId2) ?? 0) + 1;
|
|
18565
18838
|
this.turnCount.set(sessionId2, turns);
|
|
18566
18839
|
const cacheFile = sessionCacheFile(this.harness, sessionId2);
|
|
@@ -18592,18 +18865,21 @@ var RuntimeCore = class {
|
|
|
18592
18865
|
}
|
|
18593
18866
|
const block = blocks.filter(Boolean).join("\n\n");
|
|
18594
18867
|
this.injection.set(sessionId2, block);
|
|
18595
|
-
this.lastInjection = block;
|
|
18596
18868
|
}
|
|
18597
18869
|
/**
|
|
18598
|
-
* The
|
|
18599
|
-
*
|
|
18600
|
-
*
|
|
18601
|
-
* turn
|
|
18602
|
-
*
|
|
18870
|
+
* The text to inject into this turn's user message (built by the preceding onPrompt), or
|
|
18871
|
+
* undefined.
|
|
18872
|
+
*
|
|
18873
|
+
* It goes into the USER turn on every host, never the system prompt (#5914). The block changes
|
|
18874
|
+
* from turn to turn — the recall runs once, the roster refresh on a cadence — so a system prompt
|
|
18875
|
+
* carrying it differed between requests and broke the provider's prefix cache from that point
|
|
18876
|
+
* on. Persisted in the turn it belongs to, it leaves the system prompt and the earlier history
|
|
18877
|
+
* byte-identical. That used to need a fallback to the most recent block for opencode's
|
|
18878
|
+
* `experimental.chat.system.transform`, which fired with no session id; nothing reads it that
|
|
18879
|
+
* way any more.
|
|
18603
18880
|
*/
|
|
18604
18881
|
getInjection(sessionId2) {
|
|
18605
|
-
|
|
18606
|
-
return keyed ?? this.lastInjection ?? void 0;
|
|
18882
|
+
return this.injection.get(sessionId2) || void 0;
|
|
18607
18883
|
}
|
|
18608
18884
|
/**
|
|
18609
18885
|
* Full normalized transcript (rich: user/assistant text + tool calls/outputs): upsert every turn
|
|
@@ -18763,8 +19039,8 @@ async function settleWithinHookBudget(work) {
|
|
|
18763
19039
|
() => true
|
|
18764
19040
|
// RuntimeCore is fail-open; an adapter failure must be equally non-fatal.
|
|
18765
19041
|
),
|
|
18766
|
-
new Promise((
|
|
18767
|
-
timer = setTimeout(() =>
|
|
19042
|
+
new Promise((resolve4) => {
|
|
19043
|
+
timer = setTimeout(() => resolve4(false), CLINE_HOOK_BUDGET_MS);
|
|
18768
19044
|
})
|
|
18769
19045
|
]);
|
|
18770
19046
|
} finally {
|
|
@@ -18859,3 +19135,42 @@ export {
|
|
|
18859
19135
|
cline_default as default,
|
|
18860
19136
|
plugin
|
|
18861
19137
|
};
|
|
19138
|
+
/*! Bundled license information:
|
|
19139
|
+
|
|
19140
|
+
smol-toml/dist/error.js:
|
|
19141
|
+
smol-toml/dist/primitive.js:
|
|
19142
|
+
smol-toml/dist/date.js:
|
|
19143
|
+
smol-toml/dist/extract.js:
|
|
19144
|
+
smol-toml/dist/util.js:
|
|
19145
|
+
smol-toml/dist/struct.js:
|
|
19146
|
+
smol-toml/dist/parse.js:
|
|
19147
|
+
smol-toml/dist/stringify.js:
|
|
19148
|
+
smol-toml/dist/index.js:
|
|
19149
|
+
(*!
|
|
19150
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
19151
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
19152
|
+
*
|
|
19153
|
+
* Redistribution and use in source and binary forms, with or without
|
|
19154
|
+
* modification, are permitted provided that the following conditions are met:
|
|
19155
|
+
*
|
|
19156
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
19157
|
+
* list of conditions and the following disclaimer.
|
|
19158
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
19159
|
+
* this list of conditions and the following disclaimer in the
|
|
19160
|
+
* documentation and/or other materials provided with the distribution.
|
|
19161
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
19162
|
+
* may be used to endorse or promote products derived from this software without
|
|
19163
|
+
* specific prior written permission.
|
|
19164
|
+
*
|
|
19165
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
19166
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19167
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
19168
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
19169
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
19170
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
19171
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
19172
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
19173
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
19174
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
19175
|
+
*)
|
|
19176
|
+
*/
|