@vectorize-io/hindsight-coding-agents 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -3
- package/dist/antigravity-hook.js +95 -42
- package/dist/antigravity-statusline.js +6 -6
- package/dist/antigravity-stop-hook.js +132 -51
- package/dist/claude-hook.js +95 -42
- package/dist/claude-sessionstart-hook.js +385 -100
- package/dist/claude-stop-hook.js +132 -51
- package/dist/cline.js +403 -92
- package/dist/codebuddy-hook.js +95 -42
- package/dist/codebuddy-sessionstart-hook.js +385 -100
- package/dist/codebuddy-stop-hook.js +132 -51
- package/dist/codex-hook.js +95 -42
- package/dist/codex-sessionstart-hook.js +385 -100
- package/dist/codex-stop-hook.js +132 -51
- package/dist/copilot-hook.js +95 -42
- package/dist/copilot-sessionstart-hook.js +385 -100
- package/dist/copilot-stop-hook.js +132 -51
- package/dist/cursor-hook.js +95 -42
- package/dist/cursor-sessionstart-hook.js +385 -100
- package/dist/cursor-stop-hook.js +132 -51
- package/dist/daemon-start.js +10 -10
- package/dist/dcode-hook.js +95 -42
- package/dist/dcode-sessionstart-hook.js +385 -100
- package/dist/dcode-stop-hook.js +132 -51
- package/dist/deepen.js +82 -23
- package/dist/devin-hook.js +95 -42
- package/dist/devin-sessionstart-hook.js +385 -100
- package/dist/devin-stop-hook.js +132 -51
- package/dist/droid-hook.js +95 -42
- package/dist/droid-sessionstart-hook.js +385 -100
- package/dist/droid-stop-hook.js +132 -51
- package/dist/dsh.js +422 -99
- package/dist/grok-hook.js +95 -42
- package/dist/grok-sessionstart-hook.js +385 -100
- package/dist/grok-stop-hook.js +132 -51
- package/dist/hindsight-seed.js +6 -6
- package/dist/index.js +427 -111
- package/dist/installer.js +89 -80
- package/dist/kilo.js +427 -111
- package/dist/kimi-hook.js +95 -42
- package/dist/kimi-sessionstart-hook.js +385 -100
- package/dist/kimi-stop-hook.js +132 -51
- package/dist/mcp-server.js +169 -62
- package/dist/opencode2.js +583 -105
- package/dist/pi.js +403 -99
- package/dist/prime-agent.js +403 -99
- package/dist/qwen-hook.js +95 -42
- package/dist/qwen-sessionstart-hook.js +385 -100
- package/dist/qwen-stop-hook.js +132 -51
- package/dist/status.js +67 -17
- package/dist/survey-supervisor.js +73 -9
- package/dist/traecode-hook.js +95 -42
- package/dist/traecode-sessionstart-hook.js +385 -100
- package/dist/traecode-stop-hook.js +132 -51
- package/dist/workbuddy-hook.js +95 -42
- package/dist/workbuddy-sessionstart-hook.js +385 -100
- package/dist/workbuddy-stop-hook.js +132 -51
- package/dist/zcode-hook.js +95 -42
- package/dist/zcode-sessionstart-hook.js +385 -100
- package/dist/zcode-stop-hook.js +132 -51
- package/index.js +4 -1
- package/package.json +7 -4
- package/plugin.json +1 -1
- package/skill/SKILL.md +10 -2
package/dist/pi.js
CHANGED
|
@@ -14739,14 +14739,14 @@ function probeGitLayout(directory) {
|
|
|
14739
14739
|
var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
|
|
14740
14740
|
function applyTemplate(template, resolvers, what) {
|
|
14741
14741
|
return template.replace(PLACEHOLDER, (_, name) => {
|
|
14742
|
-
const
|
|
14743
|
-
if (!
|
|
14742
|
+
const resolve4 = resolvers[name];
|
|
14743
|
+
if (!resolve4) {
|
|
14744
14744
|
console.error(
|
|
14745
14745
|
`hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
|
|
14746
14746
|
);
|
|
14747
14747
|
return "unknown";
|
|
14748
14748
|
}
|
|
14749
|
-
return
|
|
14749
|
+
return resolve4();
|
|
14750
14750
|
});
|
|
14751
14751
|
}
|
|
14752
14752
|
|
|
@@ -15167,29 +15167,33 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
|
|
|
15167
15167
|
}
|
|
15168
15168
|
|
|
15169
15169
|
// package.json
|
|
15170
|
-
var version2 = "0.8.
|
|
15170
|
+
var version2 = "0.8.4";
|
|
15171
15171
|
|
|
15172
15172
|
// src/core/util.ts
|
|
15173
|
-
import { accessSync, constants } from "fs";
|
|
15174
|
-
import { delimiter, join as join6 } from "path";
|
|
15175
|
-
function binOnPath(bin) {
|
|
15176
|
-
|
|
15177
|
-
|
|
15178
|
-
|
|
15173
|
+
import { accessSync, constants, statSync as statSync2 } from "fs";
|
|
15174
|
+
import { delimiter, extname, isAbsolute as isAbsolute2, join as join6, resolve as resolve2 } from "path";
|
|
15175
|
+
function binOnPath(bin, opts = {}) {
|
|
15176
|
+
const platform = opts.platform ?? process.platform;
|
|
15177
|
+
const env = opts.env ?? process.env;
|
|
15178
|
+
const runnable = (file2) => {
|
|
15179
|
+
try {
|
|
15180
|
+
if (!statSync2(file2).isFile()) return false;
|
|
15181
|
+
if (platform !== "win32") accessSync(file2, constants.X_OK);
|
|
15179
15182
|
return true;
|
|
15183
|
+
} catch {
|
|
15184
|
+
return false;
|
|
15180
15185
|
}
|
|
15181
|
-
|
|
15182
|
-
|
|
15183
|
-
|
|
15184
|
-
|
|
15185
|
-
|
|
15186
|
-
|
|
15187
|
-
|
|
15186
|
+
};
|
|
15187
|
+
if (isAbsolute2(bin) || /[\\/]/.test(bin)) return runnable(bin) ? resolve2(bin) : void 0;
|
|
15188
|
+
const names = platform !== "win32" || extname(bin) ? [bin] : (opts.exts ?? (env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";")).filter(Boolean).map((ext) => bin + ext.toLowerCase());
|
|
15189
|
+
for (const dir of (env.PATH || "").split(delimiter)) {
|
|
15190
|
+
if (!dir) continue;
|
|
15191
|
+
for (const name of names) {
|
|
15192
|
+
const file2 = join6(dir, name);
|
|
15193
|
+
if (runnable(file2)) return resolve2(file2);
|
|
15188
15194
|
}
|
|
15189
|
-
return false;
|
|
15190
|
-
} catch {
|
|
15191
|
-
return false;
|
|
15192
15195
|
}
|
|
15196
|
+
return void 0;
|
|
15193
15197
|
}
|
|
15194
15198
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
15195
15199
|
function semverGte(version3, min) {
|
|
@@ -15459,15 +15463,19 @@ var HindsightClient = class {
|
|
|
15459
15463
|
}
|
|
15460
15464
|
/**
|
|
15461
15465
|
* Whether this server honours `operation_id` on an async retain, and can therefore be appended to
|
|
15462
|
-
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed
|
|
15466
|
+
* safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed via the version endpoint; anything
|
|
15463
15467
|
* unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
|
|
15468
|
+
* Only a "yes" is cached: a long-lived plugin client would otherwise keep replacing for the rest
|
|
15469
|
+
* of the process after one probe that hit a restarting server (#5735).
|
|
15464
15470
|
*/
|
|
15465
15471
|
async supportsIdempotentRetain() {
|
|
15466
|
-
if (this.idempotentRetain
|
|
15467
|
-
|
|
15468
|
-
|
|
15472
|
+
if (this.idempotentRetain) return true;
|
|
15473
|
+
const supported = await this.probeIdempotentRetain();
|
|
15474
|
+
if (supported || this.idempotentRetain === void 0) {
|
|
15475
|
+
this.log(`server retain idempotency: ${supported ? "supported" : "unavailable"}`);
|
|
15469
15476
|
}
|
|
15470
|
-
|
|
15477
|
+
this.idempotentRetain = supported;
|
|
15478
|
+
return supported;
|
|
15471
15479
|
}
|
|
15472
15480
|
/** `/v1/version` first: an ingress that routes only `/v1` to the API (the Helm chart's default)
|
|
15473
15481
|
* hands a bare `/version` to the control plane, whose HTML 404 or login redirect read as "no",
|
|
@@ -16501,15 +16509,15 @@ function stagedVersion(pkgRoot) {
|
|
|
16501
16509
|
}
|
|
16502
16510
|
}
|
|
16503
16511
|
function isNewer(candidate, current2) {
|
|
16504
|
-
const
|
|
16512
|
+
const parse4 = (v) => {
|
|
16505
16513
|
const [core = "", ...rest] = v.trim().split("-");
|
|
16506
16514
|
return {
|
|
16507
16515
|
nums: core.split(".").map((n) => Number.parseInt(n, 10)),
|
|
16508
16516
|
pre: rest.length > 0
|
|
16509
16517
|
};
|
|
16510
16518
|
};
|
|
16511
|
-
const a =
|
|
16512
|
-
const b =
|
|
16519
|
+
const a = parse4(candidate);
|
|
16520
|
+
const b = parse4(current2);
|
|
16513
16521
|
if (a.nums.length !== 3 || b.nums.length !== 3) return false;
|
|
16514
16522
|
if (a.nums.some(Number.isNaN) || b.nums.some(Number.isNaN)) return false;
|
|
16515
16523
|
for (let i = 0; i < 3; i++) {
|
|
@@ -16586,7 +16594,7 @@ function spawnNpm(spawnImpl, bin, args, opts) {
|
|
|
16586
16594
|
return process.platform === "win32" ? spawnImpl([bin, ...args].join(" "), { ...opts, shell: true }) : spawnImpl(bin, args, opts);
|
|
16587
16595
|
}
|
|
16588
16596
|
async function npmViewVersion(pkg, spawnImpl = realSpawn2) {
|
|
16589
|
-
return new Promise((
|
|
16597
|
+
return new Promise((resolve4) => {
|
|
16590
16598
|
let out = "";
|
|
16591
16599
|
let settled = false;
|
|
16592
16600
|
let deadline;
|
|
@@ -16595,7 +16603,7 @@ async function npmViewVersion(pkg, spawnImpl = realSpawn2) {
|
|
|
16595
16603
|
settled = true;
|
|
16596
16604
|
if (deadline) clearTimeout(deadline);
|
|
16597
16605
|
if (reason) log.info("auto-update", `version check failed: ${reason}`);
|
|
16598
|
-
|
|
16606
|
+
resolve4(v);
|
|
16599
16607
|
};
|
|
16600
16608
|
try {
|
|
16601
16609
|
const child = spawnNpm(spawnImpl, "npm", ["view", pkg, "version", "--json"], {
|
|
@@ -16612,7 +16620,8 @@ async function npmViewVersion(pkg, spawnImpl = realSpawn2) {
|
|
|
16612
16620
|
child.on("close", (code, signal) => {
|
|
16613
16621
|
if (code !== 0) return done("", `npm view exited ${code ?? signal}`);
|
|
16614
16622
|
try {
|
|
16615
|
-
const
|
|
16623
|
+
const parsed = JSON.parse(out.trim());
|
|
16624
|
+
const v = Array.isArray(parsed) && parsed.length === 1 ? parsed[0] : parsed;
|
|
16616
16625
|
if (typeof v !== "string")
|
|
16617
16626
|
return done("", `unparsable npm output: ${out.trim().slice(0, 80)}`);
|
|
16618
16627
|
if (!RELEASE_RE.test(v)) return done("", `not a release: ${v.slice(0, 40)}`);
|
|
@@ -16792,8 +16801,8 @@ async function waitBounded(p, ms) {
|
|
|
16792
16801
|
try {
|
|
16793
16802
|
await Promise.race([
|
|
16794
16803
|
p,
|
|
16795
|
-
new Promise((
|
|
16796
|
-
timer = setTimeout(
|
|
16804
|
+
new Promise((resolve4) => {
|
|
16805
|
+
timer = setTimeout(resolve4, Math.max(ms, 0));
|
|
16797
16806
|
})
|
|
16798
16807
|
]);
|
|
16799
16808
|
} finally {
|
|
@@ -16924,7 +16933,7 @@ import { execFileSync as execFileSync4 } from "child_process";
|
|
|
16924
16933
|
|
|
16925
16934
|
// src/core/git.ts
|
|
16926
16935
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
16927
|
-
import { resolve as
|
|
16936
|
+
import { resolve as resolve3 } from "path";
|
|
16928
16937
|
|
|
16929
16938
|
// src/core/uuid.ts
|
|
16930
16939
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -16952,18 +16961,25 @@ var US = "";
|
|
|
16952
16961
|
var RS = "";
|
|
16953
16962
|
var GITLOG_HEAD = "gitlog-head:";
|
|
16954
16963
|
var GITLOG_FORMAT = `--format=%h${US}%ad${US}%an${US}%s${US}%b${RS}`;
|
|
16955
|
-
function
|
|
16964
|
+
function runGit(repo, args, env) {
|
|
16956
16965
|
return execFileSync2("git", ["-C", repo, "-c", "log.showSignature=false", ...args], {
|
|
16957
16966
|
encoding: "utf8",
|
|
16958
16967
|
maxBuffer: 1 << 28,
|
|
16959
16968
|
windowsHide: true,
|
|
16969
|
+
env,
|
|
16960
16970
|
// execFileSync otherwise forwards failed git stderr into the host's TUI,
|
|
16961
16971
|
// even when callers catch the error. Keep diagnostics on the error instead.
|
|
16962
16972
|
stdio: ["ignore", "pipe", "pipe"]
|
|
16963
16973
|
});
|
|
16964
16974
|
}
|
|
16975
|
+
function git(repo, ...args) {
|
|
16976
|
+
return runGit(repo, args);
|
|
16977
|
+
}
|
|
16978
|
+
function gitLocal(repo, ...args) {
|
|
16979
|
+
return runGit(repo, args, { ...process.env, GIT_NO_LAZY_FETCH: "1" });
|
|
16980
|
+
}
|
|
16965
16981
|
function repoNameOf(repo) {
|
|
16966
|
-
return projectNameOf(
|
|
16982
|
+
return projectNameOf(resolve3(repo));
|
|
16967
16983
|
}
|
|
16968
16984
|
function gitHeadSha(dir) {
|
|
16969
16985
|
try {
|
|
@@ -16975,7 +16991,7 @@ function gitHeadSha(dir) {
|
|
|
16975
16991
|
function commitsSince(dir, sinceSha) {
|
|
16976
16992
|
if (!/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(sinceSha)) return null;
|
|
16977
16993
|
try {
|
|
16978
|
-
const n = Number.parseInt(
|
|
16994
|
+
const n = Number.parseInt(gitLocal(dir, "rev-list", "--count", `${sinceSha}..HEAD`).trim(), 10);
|
|
16979
16995
|
return Number.isFinite(n) ? n : null;
|
|
16980
16996
|
} catch {
|
|
16981
16997
|
return null;
|
|
@@ -17001,11 +17017,197 @@ async function gitLogIsCurrent(client, repo, head) {
|
|
|
17001
17017
|
// src/core/survey.ts
|
|
17002
17018
|
import { execFileSync as execFileSync3, spawn as realSpawn5 } from "child_process";
|
|
17003
17019
|
import { createHash as createHash3 } from "crypto";
|
|
17004
|
-
import { existsSync as existsSync3 } from "fs";
|
|
17020
|
+
import { existsSync as existsSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
17005
17021
|
import { homedir as homedir5, tmpdir as tmpdir2 } from "os";
|
|
17006
17022
|
import { dirname as dirname7, join as join11 } from "path";
|
|
17007
17023
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
17008
17024
|
|
|
17025
|
+
// node_modules/smol-toml/dist/stringify.js
|
|
17026
|
+
var BARE_KEY = /^[a-z0-9-_]+$/i;
|
|
17027
|
+
var HAS_WELLFORMED = !!"".isWellFormed;
|
|
17028
|
+
function extendedTypeOf(obj) {
|
|
17029
|
+
let type = typeof obj;
|
|
17030
|
+
if (type === "object") {
|
|
17031
|
+
if (Array.isArray(obj))
|
|
17032
|
+
return "array";
|
|
17033
|
+
if (typeof obj.getUTCDate === "function" && obj instanceof Date)
|
|
17034
|
+
return "date";
|
|
17035
|
+
if (globalThis.Temporal) {
|
|
17036
|
+
if (obj.until) {
|
|
17037
|
+
if (obj instanceof Temporal.ZonedDateTime)
|
|
17038
|
+
return "temporal/tz+uc";
|
|
17039
|
+
if (obj instanceof Temporal.PlainDateTime || obj instanceof Temporal.PlainDate)
|
|
17040
|
+
return "temporal/uc";
|
|
17041
|
+
if (obj instanceof Temporal.PlainTime || obj instanceof Temporal.Instant)
|
|
17042
|
+
return "temporal";
|
|
17043
|
+
if (obj instanceof Temporal.PlainYearMonth)
|
|
17044
|
+
return "temporal/x";
|
|
17045
|
+
} else if (obj.toPlainDate && obj instanceof Temporal.PlainMonthDay || obj.negated && obj instanceof Temporal.Duration) {
|
|
17046
|
+
return "temporal/x";
|
|
17047
|
+
}
|
|
17048
|
+
}
|
|
17049
|
+
}
|
|
17050
|
+
return type;
|
|
17051
|
+
}
|
|
17052
|
+
function isArrayOfTables(obj) {
|
|
17053
|
+
for (let i = 0; i < obj.length; i++) {
|
|
17054
|
+
if (extendedTypeOf(obj[i]) !== "object")
|
|
17055
|
+
return false;
|
|
17056
|
+
}
|
|
17057
|
+
return obj.length != 0;
|
|
17058
|
+
}
|
|
17059
|
+
function formatWellFormedStringUnchecked(s) {
|
|
17060
|
+
return JSON.stringify(s).replaceAll("\x7F", "\\u007f");
|
|
17061
|
+
}
|
|
17062
|
+
function formatString(s) {
|
|
17063
|
+
return formatWellFormedStringUnchecked(HAS_WELLFORMED ? s.toWellFormed() : s);
|
|
17064
|
+
}
|
|
17065
|
+
function formatKey(s) {
|
|
17066
|
+
if (BARE_KEY.test(s))
|
|
17067
|
+
return s;
|
|
17068
|
+
if (HAS_WELLFORMED && !s.isWellFormed())
|
|
17069
|
+
throw new RangeError("key contains illegal lone surrogates");
|
|
17070
|
+
return formatWellFormedStringUnchecked(s);
|
|
17071
|
+
}
|
|
17072
|
+
function stringifyValue(val, type, depth, numberAsFloat, strictTemporal) {
|
|
17073
|
+
if (depth === 0) {
|
|
17074
|
+
throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
17075
|
+
}
|
|
17076
|
+
switch (type) {
|
|
17077
|
+
// @ts-expect-error -- intentional fallthrough case
|
|
17078
|
+
case "number":
|
|
17079
|
+
if (isNaN(val))
|
|
17080
|
+
return "nan";
|
|
17081
|
+
if (val === Infinity)
|
|
17082
|
+
return "inf";
|
|
17083
|
+
if (val === -Infinity)
|
|
17084
|
+
return "-inf";
|
|
17085
|
+
if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val)))
|
|
17086
|
+
return val.toFixed(1);
|
|
17087
|
+
case "bigint":
|
|
17088
|
+
case "boolean":
|
|
17089
|
+
case "temporal":
|
|
17090
|
+
return val.toString();
|
|
17091
|
+
case "string":
|
|
17092
|
+
return formatString(val);
|
|
17093
|
+
case "date":
|
|
17094
|
+
if (isNaN(val.getTime()))
|
|
17095
|
+
throw new TypeError("cannot serialize invalid date");
|
|
17096
|
+
return val.toISOString();
|
|
17097
|
+
case "object":
|
|
17098
|
+
return stringifyInlineTable(val, depth, numberAsFloat, strictTemporal);
|
|
17099
|
+
case "array":
|
|
17100
|
+
return stringifyArray(val, depth, numberAsFloat, strictTemporal);
|
|
17101
|
+
// @ts-expect-error -- intentional fallthrough case
|
|
17102
|
+
case "temporal/tz+uc":
|
|
17103
|
+
if (strictTemporal) {
|
|
17104
|
+
let tz = val.timeZoneId;
|
|
17105
|
+
let tzc = tz.charCodeAt(0);
|
|
17106
|
+
if (
|
|
17107
|
+
// Classic offset
|
|
17108
|
+
tzc !== 43 && tzc !== 45 && // Fast pre-check pass; see below for the actually accepted values
|
|
17109
|
+
(tzc !== 85 && tzc !== 71 && tzc !== 90 && tzc !== 69 || // UTC and its aliases; Temporal implementations don't all canonicalise unfortunately
|
|
17110
|
+
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.
|
|
17111
|
+
!tz.startsWith("GMT") && tz !== "Greenwich" && // Etc/* are all safe to downgrade to offset (either UTC, GMT, or offset)
|
|
17112
|
+
!tz.startsWith("Etc/"))
|
|
17113
|
+
) {
|
|
17114
|
+
throw new TypeError("Temporal objects with an IANA timezone are not allowed in Temporal strict mode");
|
|
17115
|
+
}
|
|
17116
|
+
}
|
|
17117
|
+
case "temporal/uc":
|
|
17118
|
+
if (strictTemporal && val.calendarId !== "iso8601")
|
|
17119
|
+
throw new TypeError("Temporal objects with a non-default calendar are not allowed in Temporal strict mode");
|
|
17120
|
+
return val.toString({
|
|
17121
|
+
calendarName: "never",
|
|
17122
|
+
timeZoneName: "never"
|
|
17123
|
+
});
|
|
17124
|
+
case "temporal/x":
|
|
17125
|
+
throw new TypeError("Unsupported " + val[Symbol.toStringTag]);
|
|
17126
|
+
}
|
|
17127
|
+
}
|
|
17128
|
+
function stringifyInlineTable(obj, depth, numberAsFloat, strictTemporal) {
|
|
17129
|
+
let keys = Object.keys(obj);
|
|
17130
|
+
if (keys.length === 0)
|
|
17131
|
+
return "{}";
|
|
17132
|
+
let res = "{ ";
|
|
17133
|
+
for (let i = 0; i < keys.length; i++) {
|
|
17134
|
+
let k = keys[i];
|
|
17135
|
+
if (i)
|
|
17136
|
+
res += ", ";
|
|
17137
|
+
res += formatKey(k) + " = " + stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat, strictTemporal);
|
|
17138
|
+
}
|
|
17139
|
+
return res + " }";
|
|
17140
|
+
}
|
|
17141
|
+
function stringifyArray(array2, depth, numberAsFloat, strictTemporal) {
|
|
17142
|
+
if (array2.length === 0)
|
|
17143
|
+
return "[]";
|
|
17144
|
+
let res = "[ ";
|
|
17145
|
+
for (let i = 0; i < array2.length; i++) {
|
|
17146
|
+
if (i)
|
|
17147
|
+
res += ", ";
|
|
17148
|
+
if (array2[i] === null || array2[i] === void 0) {
|
|
17149
|
+
throw new TypeError("arrays cannot contain null or undefined values");
|
|
17150
|
+
}
|
|
17151
|
+
res += stringifyValue(array2[i], extendedTypeOf(array2[i]), depth - 1, numberAsFloat, strictTemporal);
|
|
17152
|
+
}
|
|
17153
|
+
return res + " ]";
|
|
17154
|
+
}
|
|
17155
|
+
function stringifyArrayTable(array2, key, depth, numberAsFloat, strictTemporal) {
|
|
17156
|
+
if (depth === 0) {
|
|
17157
|
+
throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
17158
|
+
}
|
|
17159
|
+
let res = "";
|
|
17160
|
+
for (let i = 0; i < array2.length; i++) {
|
|
17161
|
+
res += `${res && "\n"}[[${key}]]
|
|
17162
|
+
`;
|
|
17163
|
+
res += stringifyTable(0, array2[i], key, depth, numberAsFloat, strictTemporal);
|
|
17164
|
+
}
|
|
17165
|
+
return res;
|
|
17166
|
+
}
|
|
17167
|
+
function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat, strictTemporal) {
|
|
17168
|
+
if (depth === 0) {
|
|
17169
|
+
throw new Error("Could not stringify the object: maximum object depth exceeded");
|
|
17170
|
+
}
|
|
17171
|
+
let preamble = "";
|
|
17172
|
+
let tables = "";
|
|
17173
|
+
let keys = Object.keys(obj);
|
|
17174
|
+
for (let i = 0; i < keys.length; i++) {
|
|
17175
|
+
let k = keys[i];
|
|
17176
|
+
if (obj[k] !== null && obj[k] !== void 0) {
|
|
17177
|
+
let type = extendedTypeOf(obj[k]);
|
|
17178
|
+
if (type === "symbol" || type === "function") {
|
|
17179
|
+
throw new TypeError(`cannot serialize values of type '${type}'`);
|
|
17180
|
+
}
|
|
17181
|
+
let key = formatKey(k);
|
|
17182
|
+
if (type === "array" && isArrayOfTables(obj[k])) {
|
|
17183
|
+
tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat, strictTemporal);
|
|
17184
|
+
} else if (type === "object") {
|
|
17185
|
+
let tblKey = prefix ? `${prefix}.${key}` : key;
|
|
17186
|
+
tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat, strictTemporal);
|
|
17187
|
+
} else {
|
|
17188
|
+
preamble += key;
|
|
17189
|
+
preamble += " = ";
|
|
17190
|
+
preamble += stringifyValue(obj[k], type, depth, numberAsFloat, strictTemporal);
|
|
17191
|
+
preamble += "\n";
|
|
17192
|
+
}
|
|
17193
|
+
}
|
|
17194
|
+
}
|
|
17195
|
+
if (tableKey && (preamble || !tables))
|
|
17196
|
+
preamble = preamble ? `[${tableKey}]
|
|
17197
|
+
${preamble}` : `[${tableKey}]`;
|
|
17198
|
+
return preamble && tables ? `${preamble}
|
|
17199
|
+
${tables}` : preamble || tables;
|
|
17200
|
+
}
|
|
17201
|
+
function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false, strictTemporal = false } = {}) {
|
|
17202
|
+
if (extendedTypeOf(obj) !== "object") {
|
|
17203
|
+
throw new TypeError("stringify can only be called with an object");
|
|
17204
|
+
}
|
|
17205
|
+
let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat, strictTemporal);
|
|
17206
|
+
if (str[str.length - 1] !== "\n")
|
|
17207
|
+
return str + "\n";
|
|
17208
|
+
return str;
|
|
17209
|
+
}
|
|
17210
|
+
|
|
17009
17211
|
// src/core/survey-lease.ts
|
|
17010
17212
|
import { spawn as realSpawn4 } from "child_process";
|
|
17011
17213
|
import { randomUUID } from "crypto";
|
|
@@ -17016,7 +17218,7 @@ import {
|
|
|
17016
17218
|
renameSync as renameSync2,
|
|
17017
17219
|
rmdirSync,
|
|
17018
17220
|
rmSync,
|
|
17019
|
-
statSync as
|
|
17221
|
+
statSync as statSync3,
|
|
17020
17222
|
unlinkSync as unlinkSync2,
|
|
17021
17223
|
utimesSync,
|
|
17022
17224
|
writeFileSync as writeFileSync2
|
|
@@ -17053,7 +17255,7 @@ function reclaimIfStale(directory, staleMs) {
|
|
|
17053
17255
|
return true;
|
|
17054
17256
|
}
|
|
17055
17257
|
if (owners.length !== 1) return false;
|
|
17056
|
-
const age = Date.now() -
|
|
17258
|
+
const age = Date.now() - statSync3(join10(directory, owners[0])).mtimeMs;
|
|
17057
17259
|
if (Math.abs(age) <= staleMs) return false;
|
|
17058
17260
|
releaseLease({ directory, owner: owners[0] });
|
|
17059
17261
|
return true;
|
|
@@ -17116,7 +17318,7 @@ function opencodeCanDefineSurveyAgent(bin) {
|
|
|
17116
17318
|
windowsHide: true,
|
|
17117
17319
|
stdio: ["ignore", "pipe", "ignore"]
|
|
17118
17320
|
});
|
|
17119
|
-
return Number(/(\d+)\./.exec(out)?.[1] ?? 0)
|
|
17321
|
+
return Number(/(\d+)\./.exec(out)?.[1] ?? 0) === 1;
|
|
17120
17322
|
} catch {
|
|
17121
17323
|
return false;
|
|
17122
17324
|
}
|
|
@@ -17131,6 +17333,7 @@ var SURVEY_DISALLOWED_TOOLS = [
|
|
|
17131
17333
|
"WebSearch",
|
|
17132
17334
|
"Task"
|
|
17133
17335
|
];
|
|
17336
|
+
var tomlValue = (value) => stringify({ v: value }).slice("v = ".length).trim();
|
|
17134
17337
|
function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
17135
17338
|
const env = {
|
|
17136
17339
|
...process.env,
|
|
@@ -17189,9 +17392,9 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
17189
17392
|
"-c",
|
|
17190
17393
|
`mcp_servers.hindsight.command="node"`,
|
|
17191
17394
|
"-c",
|
|
17192
|
-
`mcp_servers.hindsight.args
|
|
17395
|
+
`mcp_servers.hindsight.args=${tomlValue([opts.mcpServerPath])}`,
|
|
17193
17396
|
"-c",
|
|
17194
|
-
`mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD
|
|
17397
|
+
`mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD=${tomlValue(repoDir)}`,
|
|
17195
17398
|
"-c",
|
|
17196
17399
|
`mcp_servers.hindsight.env.HINDSIGHT_MCP_HARNESS="codex"`,
|
|
17197
17400
|
SURVEY_PROMPT
|
|
@@ -17215,10 +17418,19 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
17215
17418
|
}
|
|
17216
17419
|
}
|
|
17217
17420
|
}
|
|
17421
|
+
var SURVEY_MAX_ATTEMPTS = 3;
|
|
17422
|
+
function surveyAttempts(file2, sha) {
|
|
17423
|
+
try {
|
|
17424
|
+
const state = JSON.parse(readFileSync5(file2, "utf8"));
|
|
17425
|
+
return state.sha === sha && typeof state.attempts === "number" ? state.attempts : 0;
|
|
17426
|
+
} catch {
|
|
17427
|
+
return 0;
|
|
17428
|
+
}
|
|
17429
|
+
}
|
|
17218
17430
|
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
17219
17431
|
try {
|
|
17220
17432
|
const spawnFn = opts.spawn ?? realSpawn5;
|
|
17221
|
-
const
|
|
17433
|
+
const resolveBin = opts.resolveBin ?? ((bin) => binOnPath(bin, { exts: [".exe"] }));
|
|
17222
17434
|
const mcpServerPath = opts.mcpServerPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
17223
17435
|
const preferred = opts.harness ?? "claude-code";
|
|
17224
17436
|
const order = [
|
|
@@ -17232,10 +17444,16 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17232
17444
|
for (const harness of order) {
|
|
17233
17445
|
if (seen.has(harness)) continue;
|
|
17234
17446
|
seen.add(harness);
|
|
17235
|
-
const
|
|
17236
|
-
|
|
17237
|
-
if (
|
|
17447
|
+
const name = resolveAgentBin(harness, opts.claudeBin);
|
|
17448
|
+
const bin = resolveBin(name);
|
|
17449
|
+
if (!bin) {
|
|
17450
|
+
log.info("survey", `${harness}: ${name} not found, trying the next agent`);
|
|
17238
17451
|
continue;
|
|
17452
|
+
}
|
|
17453
|
+
if (harness === "opencode" && !(opts.opencodeDefinesAgent ?? opencodeCanDefineSurveyAgent)(bin)) {
|
|
17454
|
+
log.info("survey", `${harness}: ${bin} cannot define the survey agent, trying the next`);
|
|
17455
|
+
continue;
|
|
17456
|
+
}
|
|
17239
17457
|
const plan = buildSurveyPlan(harness, bin, repoDir, {
|
|
17240
17458
|
model: opts.model,
|
|
17241
17459
|
budgetUsd: opts.budgetUsd,
|
|
@@ -17244,12 +17462,19 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17244
17462
|
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
17245
17463
|
if (cfg.disabled) return false;
|
|
17246
17464
|
const key = createHash3("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
|
|
17247
|
-
const
|
|
17248
|
-
|
|
17249
|
-
key,
|
|
17250
|
-
opts.lease?.staleMs ?? LEASE_STALE_MS
|
|
17251
|
-
);
|
|
17465
|
+
const leaseDir = opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys");
|
|
17466
|
+
const lease = acquireLease(leaseDir, key, opts.lease?.staleMs ?? LEASE_STALE_MS);
|
|
17252
17467
|
if (!lease) return false;
|
|
17468
|
+
const attemptsFile = join11(
|
|
17469
|
+
leaseDir,
|
|
17470
|
+
`attempts-${createHash3("sha256").update(JSON.stringify([key, repoDir])).digest("hex")}.json`
|
|
17471
|
+
);
|
|
17472
|
+
const attempts = opts.sha ? surveyAttempts(attemptsFile, opts.sha) : 0;
|
|
17473
|
+
if (attempts >= SURVEY_MAX_ATTEMPTS) {
|
|
17474
|
+
log.info("survey", `${attempts} surveys already launched at ${opts.sha}, skipping`);
|
|
17475
|
+
releaseLease(lease);
|
|
17476
|
+
return false;
|
|
17477
|
+
}
|
|
17253
17478
|
const spec = {
|
|
17254
17479
|
lease,
|
|
17255
17480
|
bin: plan.bin,
|
|
@@ -17257,7 +17482,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17257
17482
|
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
17258
17483
|
};
|
|
17259
17484
|
const supervisorPath = opts.supervisorPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
17260
|
-
return await new Promise((
|
|
17485
|
+
return await new Promise((resolve4) => {
|
|
17261
17486
|
try {
|
|
17262
17487
|
const child = spawnFn("node", [supervisorPath], {
|
|
17263
17488
|
cwd: repoDir,
|
|
@@ -17267,19 +17492,31 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17267
17492
|
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
17268
17493
|
});
|
|
17269
17494
|
let spawned = false;
|
|
17270
|
-
child.on("error", () => {
|
|
17495
|
+
child.on("error", (e) => {
|
|
17271
17496
|
if (spawned) return;
|
|
17497
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17272
17498
|
releaseLease(lease);
|
|
17273
|
-
|
|
17499
|
+
resolve4(false);
|
|
17274
17500
|
});
|
|
17275
17501
|
child.once("spawn", () => {
|
|
17276
17502
|
spawned = true;
|
|
17277
17503
|
child.unref();
|
|
17278
|
-
|
|
17504
|
+
if (opts.sha) {
|
|
17505
|
+
try {
|
|
17506
|
+
writeFileSync3(
|
|
17507
|
+
attemptsFile,
|
|
17508
|
+
JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
|
|
17509
|
+
{ mode: 384 }
|
|
17510
|
+
);
|
|
17511
|
+
} catch {
|
|
17512
|
+
}
|
|
17513
|
+
}
|
|
17514
|
+
resolve4(true);
|
|
17279
17515
|
});
|
|
17280
|
-
} catch {
|
|
17516
|
+
} catch (e) {
|
|
17517
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17281
17518
|
releaseLease(lease);
|
|
17282
|
-
|
|
17519
|
+
resolve4(false);
|
|
17283
17520
|
}
|
|
17284
17521
|
});
|
|
17285
17522
|
}
|
|
@@ -17557,6 +17794,18 @@ function pendingReplayable(cursor, now) {
|
|
|
17557
17794
|
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
17558
17795
|
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
17559
17796
|
}
|
|
17797
|
+
function advanceSegments(cursor, bank) {
|
|
17798
|
+
if (!cursor || cursor.bank === bank) return cursor?.segments;
|
|
17799
|
+
return [...cursor.segments ?? [{ bank: cursor.bank, from: 0 }], { bank, from: cursor.turns }];
|
|
17800
|
+
}
|
|
17801
|
+
function bankTurns(turns, segments, bank) {
|
|
17802
|
+
if (!segments) return turns;
|
|
17803
|
+
return turns.filter((_, i) => {
|
|
17804
|
+
let owner;
|
|
17805
|
+
for (const s of segments) if (s.from <= i) owner = s.bank;
|
|
17806
|
+
return owner === bank;
|
|
17807
|
+
});
|
|
17808
|
+
}
|
|
17560
17809
|
var MAX_CURSOR_OPS = 8;
|
|
17561
17810
|
function fingerprintTurns(turns, count) {
|
|
17562
17811
|
const h = createHash5("sha1").update(String(count));
|
|
@@ -17567,7 +17816,8 @@ function planRetain(turns, cursor, opts) {
|
|
|
17567
17816
|
if (!turns.length) return { mode: "skip" };
|
|
17568
17817
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
17569
17818
|
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
17570
|
-
if (cursor.bank !== opts.bank)
|
|
17819
|
+
if (cursor.bank !== opts.bank && !cursor.segments?.some((s) => s.bank === opts.bank))
|
|
17820
|
+
return { mode: "replace" };
|
|
17571
17821
|
const seen = cursor.paths ?? [];
|
|
17572
17822
|
const newFile = Boolean(opts.path && seen.length && !seen.includes(opts.path));
|
|
17573
17823
|
const continues = cursor.turns <= turns.length && fingerprintTurns(turns, cursor.turns) === cursor.fingerprint;
|
|
@@ -17688,8 +17938,17 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
|
|
|
17688
17938
|
let cursor = cursors?.read(sessionId);
|
|
17689
17939
|
const probed = Boolean(cursors) && cursor?.appendSupported !== true;
|
|
17690
17940
|
const appendSupported = Boolean(cursors) && (cursor?.appendSupported === true || await supportsAppend(client));
|
|
17941
|
+
const moved = Boolean(cursor && cursor.bank !== client.bank);
|
|
17942
|
+
if (moved)
|
|
17943
|
+
log.warn(harness ?? "", "session moved to another bank mid-session", {
|
|
17944
|
+
session: sessionId,
|
|
17945
|
+
from: cursor?.bank,
|
|
17946
|
+
to: client.bank,
|
|
17947
|
+
atTurn: cursor?.turns
|
|
17948
|
+
});
|
|
17949
|
+
const segments = advanceSegments(cursor, client.bank);
|
|
17691
17950
|
let ops = [];
|
|
17692
|
-
if (appendSupported && cursor?.ops?.length && !cursor.dirty)
|
|
17951
|
+
if (appendSupported && cursor?.ops?.length && !cursor.dirty && !moved)
|
|
17693
17952
|
({ cursor, ops } = await settleOps(client, cursor));
|
|
17694
17953
|
const plan = planRetain(turns, cursor, {
|
|
17695
17954
|
appendSupported,
|
|
@@ -17698,7 +17957,7 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
|
|
|
17698
17957
|
});
|
|
17699
17958
|
if (probed) diag(harness ?? "", "retain_mode", { mode: plan.mode, appendSupported });
|
|
17700
17959
|
const paths = plan.mode === "replace" ? transcriptPath ? [transcriptPath] : void 0 : advancePaths(cursor?.paths, transcriptPath);
|
|
17701
|
-
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
17960
|
+
const outbox = plan.mode === "replace" || moved ? [] : cursor?.pending ?? [];
|
|
17702
17961
|
if (plan.mode === "skip" && !outbox.length) return;
|
|
17703
17962
|
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
17704
17963
|
${refId}
|
|
@@ -17740,6 +17999,7 @@ ${content}`);
|
|
|
17740
17999
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
17741
18000
|
bank: client.bank,
|
|
17742
18001
|
...paths ? { paths } : {},
|
|
18002
|
+
...segments ? { segments } : {},
|
|
17743
18003
|
...appendSupported ? { appendSupported: true } : {}
|
|
17744
18004
|
};
|
|
17745
18005
|
const accepted = (id) => {
|
|
@@ -17752,9 +18012,14 @@ ${content}`);
|
|
|
17752
18012
|
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
17753
18013
|
};
|
|
17754
18014
|
if (plan.mode === "replace") {
|
|
17755
|
-
const
|
|
18015
|
+
const share = bankTurns(turns, segments, client.bank);
|
|
18016
|
+
if (!share.length) return;
|
|
18017
|
+
const content = renderSessionJsonl(refId, share, startTs);
|
|
18018
|
+
const base = cursor ? `${cursor.turns}
|
|
18019
|
+
${cursor.fingerprint}` : "";
|
|
17756
18020
|
cursors?.write(sessionId, { ...next, dirty: true });
|
|
17757
|
-
const operationId = opId("replace",
|
|
18021
|
+
const operationId = opId("replace", `${base}
|
|
18022
|
+
${content}`);
|
|
17758
18023
|
await submitWithRetry(() => submit(content, operationId, false), stillOurs, retryUntil);
|
|
17759
18024
|
ops = [];
|
|
17760
18025
|
cursors?.write(sessionId, accepted(operationId));
|
|
@@ -17781,7 +18046,7 @@ ${content}`);
|
|
|
17781
18046
|
}
|
|
17782
18047
|
|
|
17783
18048
|
// src/core/usage.ts
|
|
17784
|
-
import { readFileSync as
|
|
18049
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
17785
18050
|
import { join as join13 } from "path";
|
|
17786
18051
|
function usageFilePath() {
|
|
17787
18052
|
return process.env.HINDSIGHT_USAGE_FILE || join13(logsDir(), "usage.jsonl");
|
|
@@ -17864,12 +18129,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17864
18129
|
const base = resolversFor(ctx);
|
|
17865
18130
|
const cache = /* @__PURE__ */ new Map();
|
|
17866
18131
|
const resolvers = Object.fromEntries(
|
|
17867
|
-
Object.entries(base).map(([name,
|
|
18132
|
+
Object.entries(base).map(([name, resolve4]) => [
|
|
17868
18133
|
name,
|
|
17869
18134
|
() => {
|
|
17870
18135
|
const hit = cache.get(name);
|
|
17871
18136
|
if (hit !== void 0) return hit;
|
|
17872
|
-
const value =
|
|
18137
|
+
const value = resolve4();
|
|
17873
18138
|
cache.set(name, value);
|
|
17874
18139
|
return value;
|
|
17875
18140
|
}
|
|
@@ -17889,7 +18154,7 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17889
18154
|
}
|
|
17890
18155
|
|
|
17891
18156
|
// src/core/skill-sync.ts
|
|
17892
|
-
import { cpSync, existsSync as existsSync6, readFileSync as
|
|
18157
|
+
import { cpSync, existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
17893
18158
|
import { homedir as homedir7 } from "os";
|
|
17894
18159
|
import { dirname as dirname8, join as join15 } from "path";
|
|
17895
18160
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
@@ -17964,7 +18229,7 @@ function syncCompanionSkill(harness, opts = {}) {
|
|
|
17964
18229
|
const dstMd = join15(dst, "SKILL.md");
|
|
17965
18230
|
const installed = existsSync6(dstMd);
|
|
17966
18231
|
if (!installed && !opts.install) return;
|
|
17967
|
-
if (!installed ||
|
|
18232
|
+
if (!installed || readFileSync7(srcMd, "utf8") !== readFileSync7(dstMd, "utf8")) {
|
|
17968
18233
|
cpSync(src, dst, { recursive: true });
|
|
17969
18234
|
}
|
|
17970
18235
|
} catch {
|
|
@@ -17986,9 +18251,9 @@ function brandWord() {
|
|
|
17986
18251
|
}
|
|
17987
18252
|
|
|
17988
18253
|
// src/core/legacy.ts
|
|
17989
|
-
import { existsSync as existsSync7, readFileSync as
|
|
18254
|
+
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "fs";
|
|
17990
18255
|
import { homedir as homedir8 } from "os";
|
|
17991
|
-
import { join as join16, relative, isAbsolute as
|
|
18256
|
+
import { join as join16, relative, isAbsolute as isAbsolute3 } from "path";
|
|
17992
18257
|
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
17993
18258
|
function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")) {
|
|
17994
18259
|
const registry2 = readJson(join16(claudeDir, "plugins", "installed_plugins.json"));
|
|
@@ -18003,7 +18268,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
|
|
|
18003
18268
|
if (!i || typeof i !== "object") return false;
|
|
18004
18269
|
if (typeof i.projectPath !== "string") return true;
|
|
18005
18270
|
const rel = relative(i.projectPath, cwd);
|
|
18006
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
18271
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
18007
18272
|
});
|
|
18008
18273
|
if (active) return key;
|
|
18009
18274
|
}
|
|
@@ -18011,7 +18276,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
|
|
|
18011
18276
|
}
|
|
18012
18277
|
function readJson(path) {
|
|
18013
18278
|
try {
|
|
18014
|
-
const parsed = JSON.parse(
|
|
18279
|
+
const parsed = JSON.parse(readFileSync8(path, "utf8"));
|
|
18015
18280
|
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
18016
18281
|
} catch {
|
|
18017
18282
|
return void 0;
|
|
@@ -18023,7 +18288,7 @@ function legacyClaudePluginWarning(key) {
|
|
|
18023
18288
|
}
|
|
18024
18289
|
|
|
18025
18290
|
// src/core/session-cache.ts
|
|
18026
|
-
import { mkdirSync as mkdirSync4, readFileSync as
|
|
18291
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
18027
18292
|
import { tmpdir as tmpdir3 } from "os";
|
|
18028
18293
|
import { dirname as dirname9, join as join17 } from "path";
|
|
18029
18294
|
function sessionCacheFile(harness, sessionId) {
|
|
@@ -18031,7 +18296,7 @@ function sessionCacheFile(harness, sessionId) {
|
|
|
18031
18296
|
}
|
|
18032
18297
|
function readSessionCache(cacheFile) {
|
|
18033
18298
|
try {
|
|
18034
|
-
return JSON.parse(
|
|
18299
|
+
return JSON.parse(readFileSync9(cacheFile, "utf8"));
|
|
18035
18300
|
} catch {
|
|
18036
18301
|
return {};
|
|
18037
18302
|
}
|
|
@@ -18040,7 +18305,7 @@ function writeFileAtomic(path, body) {
|
|
|
18040
18305
|
mkdirSync4(dirname9(path), { recursive: true });
|
|
18041
18306
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
18042
18307
|
try {
|
|
18043
|
-
|
|
18308
|
+
writeFileSync4(tmp, body);
|
|
18044
18309
|
renameSync3(tmp, path);
|
|
18045
18310
|
} catch (e) {
|
|
18046
18311
|
try {
|
|
@@ -18150,12 +18415,13 @@ async function buildSessionStartContext(args) {
|
|
|
18150
18415
|
startSeed(cwd, { limit: cfg.seedLimit, harness });
|
|
18151
18416
|
if (cold) {
|
|
18152
18417
|
if (cfg.codebaseSurvey !== false) {
|
|
18418
|
+
const sha = resolveHeadSha(cwd);
|
|
18153
18419
|
const started = await startSurvey(cwd, {
|
|
18154
18420
|
harness,
|
|
18155
18421
|
model: cfg.surveyModel,
|
|
18156
|
-
budgetUsd: cfg.surveyBudgetUsd
|
|
18422
|
+
budgetUsd: cfg.surveyBudgetUsd,
|
|
18423
|
+
sha: sha ?? void 0
|
|
18157
18424
|
});
|
|
18158
|
-
const sha = resolveHeadSha(cwd);
|
|
18159
18425
|
if (started && sha) recordSurveyBaseline(sha);
|
|
18160
18426
|
}
|
|
18161
18427
|
diag(harness, "seed_started", { bank: bankId });
|
|
@@ -18176,7 +18442,8 @@ async function buildSessionStartContext(args) {
|
|
|
18176
18442
|
const started = await startSurvey(cwd, {
|
|
18177
18443
|
harness,
|
|
18178
18444
|
model: cfg.surveyModel,
|
|
18179
|
-
budgetUsd: cfg.surveyBudgetUsd
|
|
18445
|
+
budgetUsd: cfg.surveyBudgetUsd,
|
|
18446
|
+
sha
|
|
18180
18447
|
});
|
|
18181
18448
|
if (started) {
|
|
18182
18449
|
recordSurveyBaseline(sha);
|
|
@@ -18278,7 +18545,7 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
18278
18545
|
}
|
|
18279
18546
|
|
|
18280
18547
|
// src/core/turn-journal.ts
|
|
18281
|
-
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as
|
|
18548
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync10, statSync as statSync4 } from "fs";
|
|
18282
18549
|
import { tmpdir as tmpdir4 } from "os";
|
|
18283
18550
|
import { dirname as dirname10, join as join18 } from "path";
|
|
18284
18551
|
|
|
@@ -18529,8 +18796,6 @@ var RuntimeCore = class {
|
|
|
18529
18796
|
fetchTranscript;
|
|
18530
18797
|
/** Write-backs started and not yet settled — what `flush` waits for. */
|
|
18531
18798
|
inFlight = /* @__PURE__ */ new Set();
|
|
18532
|
-
lastInjection = "";
|
|
18533
|
-
// most recent turn's injection block, keyed by nothing (see getInjection)
|
|
18534
18799
|
deferInitialReflect = false;
|
|
18535
18800
|
/** Host-notice channel (opencode/Kilo: client.tui.showToast via the adapter). Optional, fail-open. */
|
|
18536
18801
|
notify;
|
|
@@ -18602,7 +18867,11 @@ var RuntimeCore = class {
|
|
|
18602
18867
|
*/
|
|
18603
18868
|
async onPrompt(sessionId, prompt) {
|
|
18604
18869
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
18605
|
-
if (!sessionId
|
|
18870
|
+
if (!sessionId) return;
|
|
18871
|
+
if (!prompt.trim()) {
|
|
18872
|
+
this.injection.delete(sessionId);
|
|
18873
|
+
return;
|
|
18874
|
+
}
|
|
18606
18875
|
const turns = (this.turnCount.get(sessionId) ?? 0) + 1;
|
|
18607
18876
|
this.turnCount.set(sessionId, turns);
|
|
18608
18877
|
const cacheFile = sessionCacheFile(this.harness, sessionId);
|
|
@@ -18634,18 +18903,21 @@ var RuntimeCore = class {
|
|
|
18634
18903
|
}
|
|
18635
18904
|
const block = blocks.filter(Boolean).join("\n\n");
|
|
18636
18905
|
this.injection.set(sessionId, block);
|
|
18637
|
-
this.lastInjection = block;
|
|
18638
18906
|
}
|
|
18639
18907
|
/**
|
|
18640
|
-
* The
|
|
18641
|
-
*
|
|
18642
|
-
*
|
|
18643
|
-
* turn
|
|
18644
|
-
*
|
|
18908
|
+
* The text to inject into this turn's user message (built by the preceding onPrompt), or
|
|
18909
|
+
* undefined.
|
|
18910
|
+
*
|
|
18911
|
+
* It goes into the USER turn on every host, never the system prompt (#5914). The block changes
|
|
18912
|
+
* from turn to turn — the recall runs once, the roster refresh on a cadence — so a system prompt
|
|
18913
|
+
* carrying it differed between requests and broke the provider's prefix cache from that point
|
|
18914
|
+
* on. Persisted in the turn it belongs to, it leaves the system prompt and the earlier history
|
|
18915
|
+
* byte-identical. That used to need a fallback to the most recent block for opencode's
|
|
18916
|
+
* `experimental.chat.system.transform`, which fired with no session id; nothing reads it that
|
|
18917
|
+
* way any more.
|
|
18645
18918
|
*/
|
|
18646
18919
|
getInjection(sessionId) {
|
|
18647
|
-
|
|
18648
|
-
return keyed ?? this.lastInjection ?? void 0;
|
|
18920
|
+
return this.injection.get(sessionId) || void 0;
|
|
18649
18921
|
}
|
|
18650
18922
|
/**
|
|
18651
18923
|
* Full normalized transcript (rich: user/assistant text + tool calls/outputs): upsert every turn
|
|
@@ -18847,21 +19119,14 @@ function createPiHooks(core, harness, sessionStart) {
|
|
|
18847
19119
|
sessionStartAwaited = true;
|
|
18848
19120
|
await sessionStart;
|
|
18849
19121
|
}
|
|
18850
|
-
|
|
18851
|
-
if (prompt) await core.onPrompt(sessionId, prompt);
|
|
19122
|
+
await core.onPrompt(sessionId, typeof event.prompt === "string" ? event.prompt.trim() : "");
|
|
18852
19123
|
const injection = core.getInjection(sessionId);
|
|
18853
19124
|
if (!injection) {
|
|
18854
19125
|
diag(harness, "inject_empty", { session: sessionId });
|
|
18855
19126
|
return void 0;
|
|
18856
19127
|
}
|
|
18857
19128
|
diag(harness, "inject_ok", { session: sessionId, chars: injection.length });
|
|
18858
|
-
|
|
18859
|
-
event.systemPromptOptions.sections.hindsight = injection;
|
|
18860
|
-
return void 0;
|
|
18861
|
-
}
|
|
18862
|
-
return { systemPrompt: `${event.systemPrompt}
|
|
18863
|
-
|
|
18864
|
-
${injection}` };
|
|
19129
|
+
return { message: { customType: "hindsight", content: injection, display: false } };
|
|
18865
19130
|
},
|
|
18866
19131
|
/** `branch` is the session's entries (`sessionManager.getBranch()`): the event alone holds only
|
|
18867
19132
|
* the latest run, and writing that back replaced the session's earlier runs (#4963). */
|
|
@@ -18932,3 +19197,42 @@ export {
|
|
|
18932
19197
|
pi_default as default,
|
|
18933
19198
|
extension
|
|
18934
19199
|
};
|
|
19200
|
+
/*! Bundled license information:
|
|
19201
|
+
|
|
19202
|
+
smol-toml/dist/error.js:
|
|
19203
|
+
smol-toml/dist/primitive.js:
|
|
19204
|
+
smol-toml/dist/date.js:
|
|
19205
|
+
smol-toml/dist/extract.js:
|
|
19206
|
+
smol-toml/dist/util.js:
|
|
19207
|
+
smol-toml/dist/struct.js:
|
|
19208
|
+
smol-toml/dist/parse.js:
|
|
19209
|
+
smol-toml/dist/stringify.js:
|
|
19210
|
+
smol-toml/dist/index.js:
|
|
19211
|
+
(*!
|
|
19212
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
19213
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
19214
|
+
*
|
|
19215
|
+
* Redistribution and use in source and binary forms, with or without
|
|
19216
|
+
* modification, are permitted provided that the following conditions are met:
|
|
19217
|
+
*
|
|
19218
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
19219
|
+
* list of conditions and the following disclaimer.
|
|
19220
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
19221
|
+
* this list of conditions and the following disclaimer in the
|
|
19222
|
+
* documentation and/or other materials provided with the distribution.
|
|
19223
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
19224
|
+
* may be used to endorse or promote products derived from this software without
|
|
19225
|
+
* specific prior written permission.
|
|
19226
|
+
*
|
|
19227
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
19228
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19229
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
19230
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
19231
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
19232
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
19233
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
19234
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
19235
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
19236
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
19237
|
+
*)
|
|
19238
|
+
*/
|