@vectorize-io/hindsight-coding-agents 0.8.2 → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -3
- package/dist/antigravity-hook.js +95 -42
- package/dist/antigravity-statusline.js +6 -6
- package/dist/antigravity-stop-hook.js +132 -51
- package/dist/claude-hook.js +95 -42
- package/dist/claude-sessionstart-hook.js +383 -99
- package/dist/claude-stop-hook.js +132 -51
- package/dist/cline.js +401 -91
- package/dist/codebuddy-hook.js +95 -42
- package/dist/codebuddy-sessionstart-hook.js +383 -99
- package/dist/codebuddy-stop-hook.js +132 -51
- package/dist/codex-hook.js +95 -42
- package/dist/codex-sessionstart-hook.js +383 -99
- package/dist/codex-stop-hook.js +132 -51
- package/dist/copilot-hook.js +95 -42
- package/dist/copilot-sessionstart-hook.js +383 -99
- package/dist/copilot-stop-hook.js +132 -51
- package/dist/cursor-hook.js +95 -42
- package/dist/cursor-sessionstart-hook.js +383 -99
- package/dist/cursor-stop-hook.js +132 -51
- package/dist/daemon-start.js +10 -10
- package/dist/dcode-hook.js +95 -42
- package/dist/dcode-sessionstart-hook.js +383 -99
- package/dist/dcode-stop-hook.js +132 -51
- package/dist/deepen.js +82 -23
- package/dist/devin-hook.js +95 -42
- package/dist/devin-sessionstart-hook.js +383 -99
- package/dist/devin-stop-hook.js +132 -51
- package/dist/droid-hook.js +95 -42
- package/dist/droid-sessionstart-hook.js +383 -99
- package/dist/droid-stop-hook.js +132 -51
- package/dist/dsh.js +420 -98
- package/dist/grok-hook.js +95 -42
- package/dist/grok-sessionstart-hook.js +383 -99
- package/dist/grok-stop-hook.js +132 -51
- package/dist/hindsight-seed.js +6 -6
- package/dist/index.js +425 -110
- package/dist/installer.js +89 -80
- package/dist/kilo.js +425 -110
- package/dist/kimi-hook.js +95 -42
- package/dist/kimi-sessionstart-hook.js +383 -99
- package/dist/kimi-stop-hook.js +132 -51
- package/dist/mcp-server.js +169 -62
- package/dist/opencode2.js +581 -104
- package/dist/pi.js +401 -98
- package/dist/prime-agent.js +401 -98
- package/dist/qwen-hook.js +95 -42
- package/dist/qwen-sessionstart-hook.js +383 -99
- package/dist/qwen-stop-hook.js +132 -51
- package/dist/status.js +67 -17
- package/dist/survey-supervisor.js +73 -9
- package/dist/traecode-hook.js +95 -42
- package/dist/traecode-sessionstart-hook.js +383 -99
- package/dist/traecode-stop-hook.js +132 -51
- package/dist/workbuddy-hook.js +95 -42
- package/dist/workbuddy-sessionstart-hook.js +383 -99
- package/dist/workbuddy-stop-hook.js +132 -51
- package/dist/zcode-hook.js +95 -42
- package/dist/zcode-sessionstart-hook.js +383 -99
- package/dist/zcode-stop-hook.js +132 -51
- package/index.js +4 -1
- package/package.json +6 -4
- package/plugin.json +1 -1
- package/skill/SKILL.md +10 -2
package/dist/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.3";
|
|
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"], {
|
|
@@ -16792,8 +16800,8 @@ async function waitBounded(p, ms) {
|
|
|
16792
16800
|
try {
|
|
16793
16801
|
await Promise.race([
|
|
16794
16802
|
p,
|
|
16795
|
-
new Promise((
|
|
16796
|
-
timer = setTimeout(
|
|
16803
|
+
new Promise((resolve4) => {
|
|
16804
|
+
timer = setTimeout(resolve4, Math.max(ms, 0));
|
|
16797
16805
|
})
|
|
16798
16806
|
]);
|
|
16799
16807
|
} finally {
|
|
@@ -16924,7 +16932,7 @@ 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";
|
|
16928
16936
|
|
|
16929
16937
|
// src/core/uuid.ts
|
|
16930
16938
|
import { createHash as createHash2 } from "crypto";
|
|
@@ -16952,18 +16960,25 @@ var US = "";
|
|
|
16952
16960
|
var RS = "";
|
|
16953
16961
|
var GITLOG_HEAD = "gitlog-head:";
|
|
16954
16962
|
var GITLOG_FORMAT = `--format=%h${US}%ad${US}%an${US}%s${US}%b${RS}`;
|
|
16955
|
-
function
|
|
16963
|
+
function runGit(repo, args, env) {
|
|
16956
16964
|
return execFileSync2("git", ["-C", repo, "-c", "log.showSignature=false", ...args], {
|
|
16957
16965
|
encoding: "utf8",
|
|
16958
16966
|
maxBuffer: 1 << 28,
|
|
16959
16967
|
windowsHide: true,
|
|
16968
|
+
env,
|
|
16960
16969
|
// execFileSync otherwise forwards failed git stderr into the host's TUI,
|
|
16961
16970
|
// even when callers catch the error. Keep diagnostics on the error instead.
|
|
16962
16971
|
stdio: ["ignore", "pipe", "pipe"]
|
|
16963
16972
|
});
|
|
16964
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
|
+
}
|
|
16965
16980
|
function repoNameOf(repo) {
|
|
16966
|
-
return projectNameOf(
|
|
16981
|
+
return projectNameOf(resolve3(repo));
|
|
16967
16982
|
}
|
|
16968
16983
|
function gitHeadSha(dir) {
|
|
16969
16984
|
try {
|
|
@@ -16975,7 +16990,7 @@ function gitHeadSha(dir) {
|
|
|
16975
16990
|
function commitsSince(dir, sinceSha) {
|
|
16976
16991
|
if (!/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(sinceSha)) return null;
|
|
16977
16992
|
try {
|
|
16978
|
-
const n = Number.parseInt(
|
|
16993
|
+
const n = Number.parseInt(gitLocal(dir, "rev-list", "--count", `${sinceSha}..HEAD`).trim(), 10);
|
|
16979
16994
|
return Number.isFinite(n) ? n : null;
|
|
16980
16995
|
} catch {
|
|
16981
16996
|
return null;
|
|
@@ -17001,11 +17016,197 @@ async function gitLogIsCurrent(client, repo, head) {
|
|
|
17001
17016
|
// src/core/survey.ts
|
|
17002
17017
|
import { execFileSync as execFileSync3, spawn as realSpawn5 } from "child_process";
|
|
17003
17018
|
import { createHash as createHash3 } from "crypto";
|
|
17004
|
-
import { existsSync as existsSync3 } from "fs";
|
|
17019
|
+
import { existsSync as existsSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
17005
17020
|
import { homedir as homedir5, tmpdir as tmpdir2 } from "os";
|
|
17006
17021
|
import { dirname as dirname7, join as join11 } from "path";
|
|
17007
17022
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
17008
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
|
+
|
|
17009
17210
|
// src/core/survey-lease.ts
|
|
17010
17211
|
import { spawn as realSpawn4 } from "child_process";
|
|
17011
17212
|
import { randomUUID } from "crypto";
|
|
@@ -17016,7 +17217,7 @@ import {
|
|
|
17016
17217
|
renameSync as renameSync2,
|
|
17017
17218
|
rmdirSync,
|
|
17018
17219
|
rmSync,
|
|
17019
|
-
statSync as
|
|
17220
|
+
statSync as statSync3,
|
|
17020
17221
|
unlinkSync as unlinkSync2,
|
|
17021
17222
|
utimesSync,
|
|
17022
17223
|
writeFileSync as writeFileSync2
|
|
@@ -17053,7 +17254,7 @@ function reclaimIfStale(directory, staleMs) {
|
|
|
17053
17254
|
return true;
|
|
17054
17255
|
}
|
|
17055
17256
|
if (owners.length !== 1) return false;
|
|
17056
|
-
const age = Date.now() -
|
|
17257
|
+
const age = Date.now() - statSync3(join10(directory, owners[0])).mtimeMs;
|
|
17057
17258
|
if (Math.abs(age) <= staleMs) return false;
|
|
17058
17259
|
releaseLease({ directory, owner: owners[0] });
|
|
17059
17260
|
return true;
|
|
@@ -17116,7 +17317,7 @@ function opencodeCanDefineSurveyAgent(bin) {
|
|
|
17116
17317
|
windowsHide: true,
|
|
17117
17318
|
stdio: ["ignore", "pipe", "ignore"]
|
|
17118
17319
|
});
|
|
17119
|
-
return Number(/(\d+)\./.exec(out)?.[1] ?? 0)
|
|
17320
|
+
return Number(/(\d+)\./.exec(out)?.[1] ?? 0) === 1;
|
|
17120
17321
|
} catch {
|
|
17121
17322
|
return false;
|
|
17122
17323
|
}
|
|
@@ -17131,6 +17332,7 @@ var SURVEY_DISALLOWED_TOOLS = [
|
|
|
17131
17332
|
"WebSearch",
|
|
17132
17333
|
"Task"
|
|
17133
17334
|
];
|
|
17335
|
+
var tomlValue = (value) => stringify({ v: value }).slice("v = ".length).trim();
|
|
17134
17336
|
function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
17135
17337
|
const env = {
|
|
17136
17338
|
...process.env,
|
|
@@ -17189,9 +17391,9 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
17189
17391
|
"-c",
|
|
17190
17392
|
`mcp_servers.hindsight.command="node"`,
|
|
17191
17393
|
"-c",
|
|
17192
|
-
`mcp_servers.hindsight.args
|
|
17394
|
+
`mcp_servers.hindsight.args=${tomlValue([opts.mcpServerPath])}`,
|
|
17193
17395
|
"-c",
|
|
17194
|
-
`mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD
|
|
17396
|
+
`mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD=${tomlValue(repoDir)}`,
|
|
17195
17397
|
"-c",
|
|
17196
17398
|
`mcp_servers.hindsight.env.HINDSIGHT_MCP_HARNESS="codex"`,
|
|
17197
17399
|
SURVEY_PROMPT
|
|
@@ -17215,10 +17417,19 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
17215
17417
|
}
|
|
17216
17418
|
}
|
|
17217
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
|
+
}
|
|
17218
17429
|
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
17219
17430
|
try {
|
|
17220
17431
|
const spawnFn = opts.spawn ?? realSpawn5;
|
|
17221
|
-
const
|
|
17432
|
+
const resolveBin = opts.resolveBin ?? ((bin) => binOnPath(bin, { exts: [".exe"] }));
|
|
17222
17433
|
const mcpServerPath = opts.mcpServerPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
17223
17434
|
const preferred = opts.harness ?? "claude-code";
|
|
17224
17435
|
const order = [
|
|
@@ -17232,10 +17443,16 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17232
17443
|
for (const harness of order) {
|
|
17233
17444
|
if (seen.has(harness)) continue;
|
|
17234
17445
|
seen.add(harness);
|
|
17235
|
-
const
|
|
17236
|
-
|
|
17237
|
-
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`);
|
|
17238
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
|
+
}
|
|
17239
17456
|
const plan = buildSurveyPlan(harness, bin, repoDir, {
|
|
17240
17457
|
model: opts.model,
|
|
17241
17458
|
budgetUsd: opts.budgetUsd,
|
|
@@ -17244,12 +17461,19 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17244
17461
|
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
17245
17462
|
if (cfg.disabled) return false;
|
|
17246
17463
|
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
|
-
);
|
|
17464
|
+
const leaseDir = opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys");
|
|
17465
|
+
const lease = acquireLease(leaseDir, key, opts.lease?.staleMs ?? LEASE_STALE_MS);
|
|
17252
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
|
+
}
|
|
17253
17477
|
const spec = {
|
|
17254
17478
|
lease,
|
|
17255
17479
|
bin: plan.bin,
|
|
@@ -17257,7 +17481,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17257
17481
|
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
17258
17482
|
};
|
|
17259
17483
|
const supervisorPath = opts.supervisorPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
17260
|
-
return await new Promise((
|
|
17484
|
+
return await new Promise((resolve4) => {
|
|
17261
17485
|
try {
|
|
17262
17486
|
const child = spawnFn("node", [supervisorPath], {
|
|
17263
17487
|
cwd: repoDir,
|
|
@@ -17267,19 +17491,31 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17267
17491
|
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
17268
17492
|
});
|
|
17269
17493
|
let spawned = false;
|
|
17270
|
-
child.on("error", () => {
|
|
17494
|
+
child.on("error", (e) => {
|
|
17271
17495
|
if (spawned) return;
|
|
17496
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17272
17497
|
releaseLease(lease);
|
|
17273
|
-
|
|
17498
|
+
resolve4(false);
|
|
17274
17499
|
});
|
|
17275
17500
|
child.once("spawn", () => {
|
|
17276
17501
|
spawned = true;
|
|
17277
17502
|
child.unref();
|
|
17278
|
-
|
|
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);
|
|
17279
17514
|
});
|
|
17280
|
-
} catch {
|
|
17515
|
+
} catch (e) {
|
|
17516
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17281
17517
|
releaseLease(lease);
|
|
17282
|
-
|
|
17518
|
+
resolve4(false);
|
|
17283
17519
|
}
|
|
17284
17520
|
});
|
|
17285
17521
|
}
|
|
@@ -17557,6 +17793,18 @@ function pendingReplayable(cursor, now) {
|
|
|
17557
17793
|
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
17558
17794
|
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
17559
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
|
+
}
|
|
17560
17808
|
var MAX_CURSOR_OPS = 8;
|
|
17561
17809
|
function fingerprintTurns(turns, count) {
|
|
17562
17810
|
const h = createHash5("sha1").update(String(count));
|
|
@@ -17567,7 +17815,8 @@ function planRetain(turns, cursor, opts) {
|
|
|
17567
17815
|
if (!turns.length) return { mode: "skip" };
|
|
17568
17816
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
17569
17817
|
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
17570
|
-
if (cursor.bank !== opts.bank)
|
|
17818
|
+
if (cursor.bank !== opts.bank && !cursor.segments?.some((s) => s.bank === opts.bank))
|
|
17819
|
+
return { mode: "replace" };
|
|
17571
17820
|
const seen = cursor.paths ?? [];
|
|
17572
17821
|
const newFile = Boolean(opts.path && seen.length && !seen.includes(opts.path));
|
|
17573
17822
|
const continues = cursor.turns <= turns.length && fingerprintTurns(turns, cursor.turns) === cursor.fingerprint;
|
|
@@ -17688,8 +17937,17 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
|
|
|
17688
17937
|
let cursor = cursors?.read(sessionId);
|
|
17689
17938
|
const probed = Boolean(cursors) && cursor?.appendSupported !== true;
|
|
17690
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: sessionId,
|
|
17944
|
+
from: cursor?.bank,
|
|
17945
|
+
to: client.bank,
|
|
17946
|
+
atTurn: cursor?.turns
|
|
17947
|
+
});
|
|
17948
|
+
const segments = advanceSegments(cursor, client.bank);
|
|
17691
17949
|
let ops = [];
|
|
17692
|
-
if (appendSupported && cursor?.ops?.length && !cursor.dirty)
|
|
17950
|
+
if (appendSupported && cursor?.ops?.length && !cursor.dirty && !moved)
|
|
17693
17951
|
({ cursor, ops } = await settleOps(client, cursor));
|
|
17694
17952
|
const plan = planRetain(turns, cursor, {
|
|
17695
17953
|
appendSupported,
|
|
@@ -17698,7 +17956,7 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
|
|
|
17698
17956
|
});
|
|
17699
17957
|
if (probed) diag(harness ?? "", "retain_mode", { mode: plan.mode, appendSupported });
|
|
17700
17958
|
const paths = plan.mode === "replace" ? transcriptPath ? [transcriptPath] : void 0 : advancePaths(cursor?.paths, transcriptPath);
|
|
17701
|
-
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
17959
|
+
const outbox = plan.mode === "replace" || moved ? [] : cursor?.pending ?? [];
|
|
17702
17960
|
if (plan.mode === "skip" && !outbox.length) return;
|
|
17703
17961
|
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
17704
17962
|
${refId}
|
|
@@ -17740,6 +17998,7 @@ ${content}`);
|
|
|
17740
17998
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
17741
17999
|
bank: client.bank,
|
|
17742
18000
|
...paths ? { paths } : {},
|
|
18001
|
+
...segments ? { segments } : {},
|
|
17743
18002
|
...appendSupported ? { appendSupported: true } : {}
|
|
17744
18003
|
};
|
|
17745
18004
|
const accepted = (id) => {
|
|
@@ -17752,9 +18011,14 @@ ${content}`);
|
|
|
17752
18011
|
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
17753
18012
|
};
|
|
17754
18013
|
if (plan.mode === "replace") {
|
|
17755
|
-
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}` : "";
|
|
17756
18019
|
cursors?.write(sessionId, { ...next, dirty: true });
|
|
17757
|
-
const operationId = opId("replace",
|
|
18020
|
+
const operationId = opId("replace", `${base}
|
|
18021
|
+
${content}`);
|
|
17758
18022
|
await submitWithRetry(() => submit(content, operationId, false), stillOurs, retryUntil);
|
|
17759
18023
|
ops = [];
|
|
17760
18024
|
cursors?.write(sessionId, accepted(operationId));
|
|
@@ -17781,7 +18045,7 @@ ${content}`);
|
|
|
17781
18045
|
}
|
|
17782
18046
|
|
|
17783
18047
|
// src/core/usage.ts
|
|
17784
|
-
import { readFileSync as
|
|
18048
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
17785
18049
|
import { join as join13 } from "path";
|
|
17786
18050
|
function usageFilePath() {
|
|
17787
18051
|
return process.env.HINDSIGHT_USAGE_FILE || join13(logsDir(), "usage.jsonl");
|
|
@@ -17864,12 +18128,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17864
18128
|
const base = resolversFor(ctx);
|
|
17865
18129
|
const cache = /* @__PURE__ */ new Map();
|
|
17866
18130
|
const resolvers = Object.fromEntries(
|
|
17867
|
-
Object.entries(base).map(([name,
|
|
18131
|
+
Object.entries(base).map(([name, resolve4]) => [
|
|
17868
18132
|
name,
|
|
17869
18133
|
() => {
|
|
17870
18134
|
const hit = cache.get(name);
|
|
17871
18135
|
if (hit !== void 0) return hit;
|
|
17872
|
-
const value =
|
|
18136
|
+
const value = resolve4();
|
|
17873
18137
|
cache.set(name, value);
|
|
17874
18138
|
return value;
|
|
17875
18139
|
}
|
|
@@ -17889,7 +18153,7 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17889
18153
|
}
|
|
17890
18154
|
|
|
17891
18155
|
// src/core/skill-sync.ts
|
|
17892
|
-
import { cpSync, existsSync as existsSync6, readFileSync as
|
|
18156
|
+
import { cpSync, existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
17893
18157
|
import { homedir as homedir7 } from "os";
|
|
17894
18158
|
import { dirname as dirname8, join as join15 } from "path";
|
|
17895
18159
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
@@ -17964,7 +18228,7 @@ function syncCompanionSkill(harness, opts = {}) {
|
|
|
17964
18228
|
const dstMd = join15(dst, "SKILL.md");
|
|
17965
18229
|
const installed = existsSync6(dstMd);
|
|
17966
18230
|
if (!installed && !opts.install) return;
|
|
17967
|
-
if (!installed ||
|
|
18231
|
+
if (!installed || readFileSync7(srcMd, "utf8") !== readFileSync7(dstMd, "utf8")) {
|
|
17968
18232
|
cpSync(src, dst, { recursive: true });
|
|
17969
18233
|
}
|
|
17970
18234
|
} catch {
|
|
@@ -17986,9 +18250,9 @@ function brandWord() {
|
|
|
17986
18250
|
}
|
|
17987
18251
|
|
|
17988
18252
|
// src/core/legacy.ts
|
|
17989
|
-
import { existsSync as existsSync7, readFileSync as
|
|
18253
|
+
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "fs";
|
|
17990
18254
|
import { homedir as homedir8 } from "os";
|
|
17991
|
-
import { join as join16, relative, isAbsolute as
|
|
18255
|
+
import { join as join16, relative, isAbsolute as isAbsolute3 } from "path";
|
|
17992
18256
|
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
17993
18257
|
function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")) {
|
|
17994
18258
|
const registry2 = readJson(join16(claudeDir, "plugins", "installed_plugins.json"));
|
|
@@ -18003,7 +18267,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
|
|
|
18003
18267
|
if (!i || typeof i !== "object") return false;
|
|
18004
18268
|
if (typeof i.projectPath !== "string") return true;
|
|
18005
18269
|
const rel = relative(i.projectPath, cwd);
|
|
18006
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
18270
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
18007
18271
|
});
|
|
18008
18272
|
if (active) return key;
|
|
18009
18273
|
}
|
|
@@ -18011,7 +18275,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
|
|
|
18011
18275
|
}
|
|
18012
18276
|
function readJson(path) {
|
|
18013
18277
|
try {
|
|
18014
|
-
const parsed = JSON.parse(
|
|
18278
|
+
const parsed = JSON.parse(readFileSync8(path, "utf8"));
|
|
18015
18279
|
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
18016
18280
|
} catch {
|
|
18017
18281
|
return void 0;
|
|
@@ -18023,7 +18287,7 @@ function legacyClaudePluginWarning(key) {
|
|
|
18023
18287
|
}
|
|
18024
18288
|
|
|
18025
18289
|
// src/core/session-cache.ts
|
|
18026
|
-
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";
|
|
18027
18291
|
import { tmpdir as tmpdir3 } from "os";
|
|
18028
18292
|
import { dirname as dirname9, join as join17 } from "path";
|
|
18029
18293
|
function sessionCacheFile(harness, sessionId) {
|
|
@@ -18031,7 +18295,7 @@ function sessionCacheFile(harness, sessionId) {
|
|
|
18031
18295
|
}
|
|
18032
18296
|
function readSessionCache(cacheFile) {
|
|
18033
18297
|
try {
|
|
18034
|
-
return JSON.parse(
|
|
18298
|
+
return JSON.parse(readFileSync9(cacheFile, "utf8"));
|
|
18035
18299
|
} catch {
|
|
18036
18300
|
return {};
|
|
18037
18301
|
}
|
|
@@ -18040,7 +18304,7 @@ function writeFileAtomic(path, body) {
|
|
|
18040
18304
|
mkdirSync4(dirname9(path), { recursive: true });
|
|
18041
18305
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
18042
18306
|
try {
|
|
18043
|
-
|
|
18307
|
+
writeFileSync4(tmp, body);
|
|
18044
18308
|
renameSync3(tmp, path);
|
|
18045
18309
|
} catch (e) {
|
|
18046
18310
|
try {
|
|
@@ -18150,12 +18414,13 @@ async function buildSessionStartContext(args) {
|
|
|
18150
18414
|
startSeed(cwd, { limit: cfg.seedLimit, harness });
|
|
18151
18415
|
if (cold) {
|
|
18152
18416
|
if (cfg.codebaseSurvey !== false) {
|
|
18417
|
+
const sha = resolveHeadSha(cwd);
|
|
18153
18418
|
const started = await startSurvey(cwd, {
|
|
18154
18419
|
harness,
|
|
18155
18420
|
model: cfg.surveyModel,
|
|
18156
|
-
budgetUsd: cfg.surveyBudgetUsd
|
|
18421
|
+
budgetUsd: cfg.surveyBudgetUsd,
|
|
18422
|
+
sha: sha ?? void 0
|
|
18157
18423
|
});
|
|
18158
|
-
const sha = resolveHeadSha(cwd);
|
|
18159
18424
|
if (started && sha) recordSurveyBaseline(sha);
|
|
18160
18425
|
}
|
|
18161
18426
|
diag(harness, "seed_started", { bank: bankId });
|
|
@@ -18176,7 +18441,8 @@ async function buildSessionStartContext(args) {
|
|
|
18176
18441
|
const started = await startSurvey(cwd, {
|
|
18177
18442
|
harness,
|
|
18178
18443
|
model: cfg.surveyModel,
|
|
18179
|
-
budgetUsd: cfg.surveyBudgetUsd
|
|
18444
|
+
budgetUsd: cfg.surveyBudgetUsd,
|
|
18445
|
+
sha
|
|
18180
18446
|
});
|
|
18181
18447
|
if (started) {
|
|
18182
18448
|
recordSurveyBaseline(sha);
|
|
@@ -18278,7 +18544,7 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
18278
18544
|
}
|
|
18279
18545
|
|
|
18280
18546
|
// src/core/turn-journal.ts
|
|
18281
|
-
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";
|
|
18282
18548
|
import { tmpdir as tmpdir4 } from "os";
|
|
18283
18549
|
import { dirname as dirname10, join as join18 } from "path";
|
|
18284
18550
|
|
|
@@ -18529,8 +18795,6 @@ var RuntimeCore = class {
|
|
|
18529
18795
|
fetchTranscript;
|
|
18530
18796
|
/** Write-backs started and not yet settled — what `flush` waits for. */
|
|
18531
18797
|
inFlight = /* @__PURE__ */ new Set();
|
|
18532
|
-
lastInjection = "";
|
|
18533
|
-
// most recent turn's injection block, keyed by nothing (see getInjection)
|
|
18534
18798
|
deferInitialReflect = false;
|
|
18535
18799
|
/** Host-notice channel (opencode/Kilo: client.tui.showToast via the adapter). Optional, fail-open. */
|
|
18536
18800
|
notify;
|
|
@@ -18602,7 +18866,11 @@ var RuntimeCore = class {
|
|
|
18602
18866
|
*/
|
|
18603
18867
|
async onPrompt(sessionId, prompt) {
|
|
18604
18868
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
18605
|
-
if (!sessionId
|
|
18869
|
+
if (!sessionId) return;
|
|
18870
|
+
if (!prompt.trim()) {
|
|
18871
|
+
this.injection.delete(sessionId);
|
|
18872
|
+
return;
|
|
18873
|
+
}
|
|
18606
18874
|
const turns = (this.turnCount.get(sessionId) ?? 0) + 1;
|
|
18607
18875
|
this.turnCount.set(sessionId, turns);
|
|
18608
18876
|
const cacheFile = sessionCacheFile(this.harness, sessionId);
|
|
@@ -18634,18 +18902,21 @@ var RuntimeCore = class {
|
|
|
18634
18902
|
}
|
|
18635
18903
|
const block = blocks.filter(Boolean).join("\n\n");
|
|
18636
18904
|
this.injection.set(sessionId, block);
|
|
18637
|
-
this.lastInjection = block;
|
|
18638
18905
|
}
|
|
18639
18906
|
/**
|
|
18640
|
-
* The
|
|
18641
|
-
*
|
|
18642
|
-
*
|
|
18643
|
-
* turn
|
|
18644
|
-
*
|
|
18907
|
+
* The text to inject into this turn's user message (built by the preceding onPrompt), or
|
|
18908
|
+
* undefined.
|
|
18909
|
+
*
|
|
18910
|
+
* It goes into the USER turn on every host, never the system prompt (#5914). The block changes
|
|
18911
|
+
* from turn to turn — the recall runs once, the roster refresh on a cadence — so a system prompt
|
|
18912
|
+
* carrying it differed between requests and broke the provider's prefix cache from that point
|
|
18913
|
+
* on. Persisted in the turn it belongs to, it leaves the system prompt and the earlier history
|
|
18914
|
+
* byte-identical. That used to need a fallback to the most recent block for opencode's
|
|
18915
|
+
* `experimental.chat.system.transform`, which fired with no session id; nothing reads it that
|
|
18916
|
+
* way any more.
|
|
18645
18917
|
*/
|
|
18646
18918
|
getInjection(sessionId) {
|
|
18647
|
-
|
|
18648
|
-
return keyed ?? this.lastInjection ?? void 0;
|
|
18919
|
+
return this.injection.get(sessionId) || void 0;
|
|
18649
18920
|
}
|
|
18650
18921
|
/**
|
|
18651
18922
|
* Full normalized transcript (rich: user/assistant text + tool calls/outputs): upsert every turn
|
|
@@ -18847,21 +19118,14 @@ function createPiHooks(core, harness, sessionStart) {
|
|
|
18847
19118
|
sessionStartAwaited = true;
|
|
18848
19119
|
await sessionStart;
|
|
18849
19120
|
}
|
|
18850
|
-
|
|
18851
|
-
if (prompt) await core.onPrompt(sessionId, prompt);
|
|
19121
|
+
await core.onPrompt(sessionId, event.prompt.trim());
|
|
18852
19122
|
const injection = core.getInjection(sessionId);
|
|
18853
19123
|
if (!injection) {
|
|
18854
19124
|
diag(harness, "inject_empty", { session: sessionId });
|
|
18855
19125
|
return void 0;
|
|
18856
19126
|
}
|
|
18857
19127
|
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}` };
|
|
19128
|
+
return { message: { customType: "hindsight", content: injection, display: false } };
|
|
18865
19129
|
},
|
|
18866
19130
|
/** `branch` is the session's entries (`sessionManager.getBranch()`): the event alone holds only
|
|
18867
19131
|
* the latest run, and writing that back replaced the session's earlier runs (#4963). */
|
|
@@ -18932,3 +19196,42 @@ export {
|
|
|
18932
19196
|
pi_default as default,
|
|
18933
19197
|
extension
|
|
18934
19198
|
};
|
|
19199
|
+
/*! Bundled license information:
|
|
19200
|
+
|
|
19201
|
+
smol-toml/dist/error.js:
|
|
19202
|
+
smol-toml/dist/primitive.js:
|
|
19203
|
+
smol-toml/dist/date.js:
|
|
19204
|
+
smol-toml/dist/extract.js:
|
|
19205
|
+
smol-toml/dist/util.js:
|
|
19206
|
+
smol-toml/dist/struct.js:
|
|
19207
|
+
smol-toml/dist/parse.js:
|
|
19208
|
+
smol-toml/dist/stringify.js:
|
|
19209
|
+
smol-toml/dist/index.js:
|
|
19210
|
+
(*!
|
|
19211
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
19212
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
19213
|
+
*
|
|
19214
|
+
* Redistribution and use in source and binary forms, with or without
|
|
19215
|
+
* modification, are permitted provided that the following conditions are met:
|
|
19216
|
+
*
|
|
19217
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
19218
|
+
* list of conditions and the following disclaimer.
|
|
19219
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
19220
|
+
* this list of conditions and the following disclaimer in the
|
|
19221
|
+
* documentation and/or other materials provided with the distribution.
|
|
19222
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
19223
|
+
* may be used to endorse or promote products derived from this software without
|
|
19224
|
+
* specific prior written permission.
|
|
19225
|
+
*
|
|
19226
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
19227
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
19228
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
19229
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
19230
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
19231
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
19232
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
19233
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
19234
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
19235
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
19236
|
+
*)
|
|
19237
|
+
*/
|