@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/opencode2.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 = (file3) => {
|
|
15179
|
+
try {
|
|
15180
|
+
if (!statSync2(file3).isFile()) return false;
|
|
15181
|
+
if (platform !== "win32") accessSync(file3, 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 file3 = join6(dir, name);
|
|
15193
|
+
if (runnable(file3)) return resolve2(file3);
|
|
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(version4, 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 parse6 = (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 = parse6(candidate);
|
|
16520
|
+
const b = parse6(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(array3, depth, numberAsFloat, strictTemporal) {
|
|
17141
|
+
if (array3.length === 0)
|
|
17142
|
+
return "[]";
|
|
17143
|
+
let res = "[ ";
|
|
17144
|
+
for (let i = 0; i < array3.length; i++) {
|
|
17145
|
+
if (i)
|
|
17146
|
+
res += ", ";
|
|
17147
|
+
if (array3[i] === null || array3[i] === void 0) {
|
|
17148
|
+
throw new TypeError("arrays cannot contain null or undefined values");
|
|
17149
|
+
}
|
|
17150
|
+
res += stringifyValue(array3[i], extendedTypeOf(array3[i]), depth - 1, numberAsFloat, strictTemporal);
|
|
17151
|
+
}
|
|
17152
|
+
return res + " ]";
|
|
17153
|
+
}
|
|
17154
|
+
function stringifyArrayTable(array3, 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 < array3.length; i++) {
|
|
17160
|
+
res += `${res && "\n"}[[${key}]]
|
|
17161
|
+
`;
|
|
17162
|
+
res += stringifyTable(0, array3[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;
|
|
@@ -17096,6 +17297,17 @@ function resolveClaudeBin(explicit) {
|
|
|
17096
17297
|
return "claude";
|
|
17097
17298
|
}
|
|
17098
17299
|
var SURVEY_AGENT = "hindsight-survey";
|
|
17300
|
+
var SURVEY_AGENT_CONFIG = {
|
|
17301
|
+
description: "One-time read-only structural survey that seeds this repository's Hindsight memory.",
|
|
17302
|
+
mode: "primary",
|
|
17303
|
+
permission: {
|
|
17304
|
+
"*": "deny",
|
|
17305
|
+
read: "allow",
|
|
17306
|
+
grep: "allow",
|
|
17307
|
+
glob: "allow",
|
|
17308
|
+
hindsight_ingest_document: "allow"
|
|
17309
|
+
}
|
|
17310
|
+
};
|
|
17099
17311
|
function resolveAgentBin(harness, claudeBin) {
|
|
17100
17312
|
switch (harness) {
|
|
17101
17313
|
case "claude-code":
|
|
@@ -17116,7 +17328,7 @@ function opencodeCanDefineSurveyAgent(bin) {
|
|
|
17116
17328
|
windowsHide: true,
|
|
17117
17329
|
stdio: ["ignore", "pipe", "ignore"]
|
|
17118
17330
|
});
|
|
17119
|
-
return Number(/(\d+)\./.exec(out)?.[1] ?? 0)
|
|
17331
|
+
return Number(/(\d+)\./.exec(out)?.[1] ?? 0) === 1;
|
|
17120
17332
|
} catch {
|
|
17121
17333
|
return false;
|
|
17122
17334
|
}
|
|
@@ -17131,6 +17343,7 @@ var SURVEY_DISALLOWED_TOOLS = [
|
|
|
17131
17343
|
"WebSearch",
|
|
17132
17344
|
"Task"
|
|
17133
17345
|
];
|
|
17346
|
+
var tomlValue = (value) => stringify({ v: value }).slice("v = ".length).trim();
|
|
17134
17347
|
function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
17135
17348
|
const env = {
|
|
17136
17349
|
...process.env,
|
|
@@ -17189,9 +17402,9 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
17189
17402
|
"-c",
|
|
17190
17403
|
`mcp_servers.hindsight.command="node"`,
|
|
17191
17404
|
"-c",
|
|
17192
|
-
`mcp_servers.hindsight.args
|
|
17405
|
+
`mcp_servers.hindsight.args=${tomlValue([opts.mcpServerPath])}`,
|
|
17193
17406
|
"-c",
|
|
17194
|
-
`mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD
|
|
17407
|
+
`mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD=${tomlValue(repoDir)}`,
|
|
17195
17408
|
"-c",
|
|
17196
17409
|
`mcp_servers.hindsight.env.HINDSIGHT_MCP_HARNESS="codex"`,
|
|
17197
17410
|
SURVEY_PROMPT
|
|
@@ -17215,10 +17428,19 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
17215
17428
|
}
|
|
17216
17429
|
}
|
|
17217
17430
|
}
|
|
17431
|
+
var SURVEY_MAX_ATTEMPTS = 3;
|
|
17432
|
+
function surveyAttempts(file3, sha) {
|
|
17433
|
+
try {
|
|
17434
|
+
const state = JSON.parse(readFileSync5(file3, "utf8"));
|
|
17435
|
+
return state.sha === sha && typeof state.attempts === "number" ? state.attempts : 0;
|
|
17436
|
+
} catch {
|
|
17437
|
+
return 0;
|
|
17438
|
+
}
|
|
17439
|
+
}
|
|
17218
17440
|
async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
17219
17441
|
try {
|
|
17220
17442
|
const spawnFn = opts.spawn ?? realSpawn5;
|
|
17221
|
-
const
|
|
17443
|
+
const resolveBin = opts.resolveBin ?? ((bin) => binOnPath(bin, { exts: [".exe"] }));
|
|
17222
17444
|
const mcpServerPath = opts.mcpServerPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
17223
17445
|
const preferred = opts.harness ?? "claude-code";
|
|
17224
17446
|
const order = [
|
|
@@ -17232,10 +17454,16 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17232
17454
|
for (const harness of order) {
|
|
17233
17455
|
if (seen.has(harness)) continue;
|
|
17234
17456
|
seen.add(harness);
|
|
17235
|
-
const
|
|
17236
|
-
|
|
17237
|
-
if (
|
|
17457
|
+
const name = resolveAgentBin(harness, opts.claudeBin);
|
|
17458
|
+
const bin = resolveBin(name);
|
|
17459
|
+
if (!bin) {
|
|
17460
|
+
log.info("survey", `${harness}: ${name} not found, trying the next agent`);
|
|
17238
17461
|
continue;
|
|
17462
|
+
}
|
|
17463
|
+
if (harness === "opencode" && !(opts.opencodeDefinesAgent ?? opencodeCanDefineSurveyAgent)(bin)) {
|
|
17464
|
+
log.info("survey", `${harness}: ${bin} cannot define the survey agent, trying the next`);
|
|
17465
|
+
continue;
|
|
17466
|
+
}
|
|
17239
17467
|
const plan = buildSurveyPlan(harness, bin, repoDir, {
|
|
17240
17468
|
model: opts.model,
|
|
17241
17469
|
budgetUsd: opts.budgetUsd,
|
|
@@ -17244,12 +17472,19 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17244
17472
|
const { cfg, bankId } = resolveHostConfig(harness, repoDir);
|
|
17245
17473
|
if (cfg.disabled) return false;
|
|
17246
17474
|
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
|
-
);
|
|
17475
|
+
const leaseDir = opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys");
|
|
17476
|
+
const lease = acquireLease(leaseDir, key, opts.lease?.staleMs ?? LEASE_STALE_MS);
|
|
17252
17477
|
if (!lease) return false;
|
|
17478
|
+
const attemptsFile = join11(
|
|
17479
|
+
leaseDir,
|
|
17480
|
+
`attempts-${createHash3("sha256").update(JSON.stringify([key, repoDir])).digest("hex")}.json`
|
|
17481
|
+
);
|
|
17482
|
+
const attempts = opts.sha ? surveyAttempts(attemptsFile, opts.sha) : 0;
|
|
17483
|
+
if (attempts >= SURVEY_MAX_ATTEMPTS) {
|
|
17484
|
+
log.info("survey", `${attempts} surveys already launched at ${opts.sha}, skipping`);
|
|
17485
|
+
releaseLease(lease);
|
|
17486
|
+
return false;
|
|
17487
|
+
}
|
|
17253
17488
|
const spec = {
|
|
17254
17489
|
lease,
|
|
17255
17490
|
bin: plan.bin,
|
|
@@ -17257,7 +17492,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17257
17492
|
...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
|
|
17258
17493
|
};
|
|
17259
17494
|
const supervisorPath = opts.supervisorPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
|
|
17260
|
-
return await new Promise((
|
|
17495
|
+
return await new Promise((resolve4) => {
|
|
17261
17496
|
try {
|
|
17262
17497
|
const child = spawnFn("node", [supervisorPath], {
|
|
17263
17498
|
cwd: repoDir,
|
|
@@ -17267,19 +17502,31 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
17267
17502
|
env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
|
|
17268
17503
|
});
|
|
17269
17504
|
let spawned = false;
|
|
17270
|
-
child.on("error", () => {
|
|
17505
|
+
child.on("error", (e) => {
|
|
17271
17506
|
if (spawned) return;
|
|
17507
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17272
17508
|
releaseLease(lease);
|
|
17273
|
-
|
|
17509
|
+
resolve4(false);
|
|
17274
17510
|
});
|
|
17275
17511
|
child.once("spawn", () => {
|
|
17276
17512
|
spawned = true;
|
|
17277
17513
|
child.unref();
|
|
17278
|
-
|
|
17514
|
+
if (opts.sha) {
|
|
17515
|
+
try {
|
|
17516
|
+
writeFileSync3(
|
|
17517
|
+
attemptsFile,
|
|
17518
|
+
JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
|
|
17519
|
+
{ mode: 384 }
|
|
17520
|
+
);
|
|
17521
|
+
} catch {
|
|
17522
|
+
}
|
|
17523
|
+
}
|
|
17524
|
+
resolve4(true);
|
|
17279
17525
|
});
|
|
17280
|
-
} catch {
|
|
17526
|
+
} catch (e) {
|
|
17527
|
+
log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
|
|
17281
17528
|
releaseLease(lease);
|
|
17282
|
-
|
|
17529
|
+
resolve4(false);
|
|
17283
17530
|
}
|
|
17284
17531
|
});
|
|
17285
17532
|
}
|
|
@@ -17557,6 +17804,18 @@ function pendingReplayable(cursor, now) {
|
|
|
17557
17804
|
if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
|
|
17558
17805
|
return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
|
|
17559
17806
|
}
|
|
17807
|
+
function advanceSegments(cursor, bank) {
|
|
17808
|
+
if (!cursor || cursor.bank === bank) return cursor?.segments;
|
|
17809
|
+
return [...cursor.segments ?? [{ bank: cursor.bank, from: 0 }], { bank, from: cursor.turns }];
|
|
17810
|
+
}
|
|
17811
|
+
function bankTurns(turns, segments, bank) {
|
|
17812
|
+
if (!segments) return turns;
|
|
17813
|
+
return turns.filter((_, i) => {
|
|
17814
|
+
let owner;
|
|
17815
|
+
for (const s of segments) if (s.from <= i) owner = s.bank;
|
|
17816
|
+
return owner === bank;
|
|
17817
|
+
});
|
|
17818
|
+
}
|
|
17560
17819
|
var MAX_CURSOR_OPS = 8;
|
|
17561
17820
|
function fingerprintTurns(turns, count) {
|
|
17562
17821
|
const h = createHash5("sha1").update(String(count));
|
|
@@ -17567,7 +17826,8 @@ function planRetain(turns, cursor, opts) {
|
|
|
17567
17826
|
if (!turns.length) return { mode: "skip" };
|
|
17568
17827
|
if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
|
|
17569
17828
|
if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
|
|
17570
|
-
if (cursor.bank !== opts.bank)
|
|
17829
|
+
if (cursor.bank !== opts.bank && !cursor.segments?.some((s) => s.bank === opts.bank))
|
|
17830
|
+
return { mode: "replace" };
|
|
17571
17831
|
const seen = cursor.paths ?? [];
|
|
17572
17832
|
const newFile = Boolean(opts.path && seen.length && !seen.includes(opts.path));
|
|
17573
17833
|
const continues = cursor.turns <= turns.length && fingerprintTurns(turns, cursor.turns) === cursor.fingerprint;
|
|
@@ -17688,8 +17948,17 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
|
|
|
17688
17948
|
let cursor = cursors?.read(sessionId);
|
|
17689
17949
|
const probed = Boolean(cursors) && cursor?.appendSupported !== true;
|
|
17690
17950
|
const appendSupported = Boolean(cursors) && (cursor?.appendSupported === true || await supportsAppend(client));
|
|
17951
|
+
const moved = Boolean(cursor && cursor.bank !== client.bank);
|
|
17952
|
+
if (moved)
|
|
17953
|
+
log.warn(harness ?? "", "session moved to another bank mid-session", {
|
|
17954
|
+
session: sessionId,
|
|
17955
|
+
from: cursor?.bank,
|
|
17956
|
+
to: client.bank,
|
|
17957
|
+
atTurn: cursor?.turns
|
|
17958
|
+
});
|
|
17959
|
+
const segments = advanceSegments(cursor, client.bank);
|
|
17691
17960
|
let ops = [];
|
|
17692
|
-
if (appendSupported && cursor?.ops?.length && !cursor.dirty)
|
|
17961
|
+
if (appendSupported && cursor?.ops?.length && !cursor.dirty && !moved)
|
|
17693
17962
|
({ cursor, ops } = await settleOps(client, cursor));
|
|
17694
17963
|
const plan = planRetain(turns, cursor, {
|
|
17695
17964
|
appendSupported,
|
|
@@ -17698,7 +17967,7 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
|
|
|
17698
17967
|
});
|
|
17699
17968
|
if (probed) diag(harness ?? "", "retain_mode", { mode: plan.mode, appendSupported });
|
|
17700
17969
|
const paths = plan.mode === "replace" ? transcriptPath ? [transcriptPath] : void 0 : advancePaths(cursor?.paths, transcriptPath);
|
|
17701
|
-
const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
|
|
17970
|
+
const outbox = plan.mode === "replace" || moved ? [] : cursor?.pending ?? [];
|
|
17702
17971
|
if (plan.mode === "skip" && !outbox.length) return;
|
|
17703
17972
|
const opId = (mode, content) => uuidV5(`${client.bank}
|
|
17704
17973
|
${refId}
|
|
@@ -17740,6 +18009,7 @@ ${content}`);
|
|
|
17740
18009
|
fingerprint: fingerprintTurns(turns, turns.length),
|
|
17741
18010
|
bank: client.bank,
|
|
17742
18011
|
...paths ? { paths } : {},
|
|
18012
|
+
...segments ? { segments } : {},
|
|
17743
18013
|
...appendSupported ? { appendSupported: true } : {}
|
|
17744
18014
|
};
|
|
17745
18015
|
const accepted = (id) => {
|
|
@@ -17752,9 +18022,14 @@ ${content}`);
|
|
|
17752
18022
|
return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
|
|
17753
18023
|
};
|
|
17754
18024
|
if (plan.mode === "replace") {
|
|
17755
|
-
const
|
|
18025
|
+
const share = bankTurns(turns, segments, client.bank);
|
|
18026
|
+
if (!share.length) return;
|
|
18027
|
+
const content = renderSessionJsonl(refId, share, startTs);
|
|
18028
|
+
const base = cursor ? `${cursor.turns}
|
|
18029
|
+
${cursor.fingerprint}` : "";
|
|
17756
18030
|
cursors?.write(sessionId, { ...next, dirty: true });
|
|
17757
|
-
const operationId = opId("replace",
|
|
18031
|
+
const operationId = opId("replace", `${base}
|
|
18032
|
+
${content}`);
|
|
17758
18033
|
await submitWithRetry(() => submit(content, operationId, false), stillOurs, retryUntil);
|
|
17759
18034
|
ops = [];
|
|
17760
18035
|
cursors?.write(sessionId, accepted(operationId));
|
|
@@ -17781,7 +18056,7 @@ ${content}`);
|
|
|
17781
18056
|
}
|
|
17782
18057
|
|
|
17783
18058
|
// src/core/usage.ts
|
|
17784
|
-
import { readFileSync as
|
|
18059
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
17785
18060
|
import { join as join13 } from "path";
|
|
17786
18061
|
function usageFilePath() {
|
|
17787
18062
|
return process.env.HINDSIGHT_USAGE_FILE || join13(logsDir(), "usage.jsonl");
|
|
@@ -17864,12 +18139,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17864
18139
|
const base = resolversFor(ctx);
|
|
17865
18140
|
const cache = /* @__PURE__ */ new Map();
|
|
17866
18141
|
const resolvers = Object.fromEntries(
|
|
17867
|
-
Object.entries(base).map(([name,
|
|
18142
|
+
Object.entries(base).map(([name, resolve4]) => [
|
|
17868
18143
|
name,
|
|
17869
18144
|
() => {
|
|
17870
18145
|
const hit = cache.get(name);
|
|
17871
18146
|
if (hit !== void 0) return hit;
|
|
17872
|
-
const value =
|
|
18147
|
+
const value = resolve4();
|
|
17873
18148
|
cache.set(name, value);
|
|
17874
18149
|
return value;
|
|
17875
18150
|
}
|
|
@@ -17889,7 +18164,7 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
17889
18164
|
}
|
|
17890
18165
|
|
|
17891
18166
|
// src/core/skill-sync.ts
|
|
17892
|
-
import { cpSync, existsSync as existsSync6, readFileSync as
|
|
18167
|
+
import { cpSync, existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
17893
18168
|
import { homedir as homedir7 } from "os";
|
|
17894
18169
|
import { dirname as dirname8, join as join15 } from "path";
|
|
17895
18170
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
@@ -17964,7 +18239,7 @@ function syncCompanionSkill(harness, opts = {}) {
|
|
|
17964
18239
|
const dstMd = join15(dst, "SKILL.md");
|
|
17965
18240
|
const installed = existsSync6(dstMd);
|
|
17966
18241
|
if (!installed && !opts.install) return;
|
|
17967
|
-
if (!installed ||
|
|
18242
|
+
if (!installed || readFileSync7(srcMd, "utf8") !== readFileSync7(dstMd, "utf8")) {
|
|
17968
18243
|
cpSync(src, dst, { recursive: true });
|
|
17969
18244
|
}
|
|
17970
18245
|
} catch {
|
|
@@ -17973,7 +18248,7 @@ function syncCompanionSkill(harness, opts = {}) {
|
|
|
17973
18248
|
function readPackagedSkill(srcDir = packagedSkillDir()) {
|
|
17974
18249
|
try {
|
|
17975
18250
|
const path = join15(srcDir, "SKILL.md");
|
|
17976
|
-
const raw =
|
|
18251
|
+
const raw = readFileSync7(path, "utf8");
|
|
17977
18252
|
const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(raw);
|
|
17978
18253
|
return {
|
|
17979
18254
|
location: srcDir,
|
|
@@ -18001,9 +18276,9 @@ function brandWord() {
|
|
|
18001
18276
|
}
|
|
18002
18277
|
|
|
18003
18278
|
// src/core/legacy.ts
|
|
18004
|
-
import { existsSync as existsSync7, readFileSync as
|
|
18279
|
+
import { existsSync as existsSync7, readFileSync as readFileSync8 } from "fs";
|
|
18005
18280
|
import { homedir as homedir8 } from "os";
|
|
18006
|
-
import { join as join16, relative, isAbsolute as
|
|
18281
|
+
import { join as join16, relative, isAbsolute as isAbsolute3 } from "path";
|
|
18007
18282
|
var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
|
|
18008
18283
|
function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")) {
|
|
18009
18284
|
const registry3 = readJson(join16(claudeDir, "plugins", "installed_plugins.json"));
|
|
@@ -18018,7 +18293,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
|
|
|
18018
18293
|
if (!i || typeof i !== "object") return false;
|
|
18019
18294
|
if (typeof i.projectPath !== "string") return true;
|
|
18020
18295
|
const rel = relative(i.projectPath, cwd);
|
|
18021
|
-
return rel === "" || !rel.startsWith("..") && !
|
|
18296
|
+
return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
|
|
18022
18297
|
});
|
|
18023
18298
|
if (active) return key;
|
|
18024
18299
|
}
|
|
@@ -18026,7 +18301,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
|
|
|
18026
18301
|
}
|
|
18027
18302
|
function readJson(path) {
|
|
18028
18303
|
try {
|
|
18029
|
-
const parsed = JSON.parse(
|
|
18304
|
+
const parsed = JSON.parse(readFileSync8(path, "utf8"));
|
|
18030
18305
|
return parsed && typeof parsed === "object" ? parsed : void 0;
|
|
18031
18306
|
} catch {
|
|
18032
18307
|
return void 0;
|
|
@@ -18038,7 +18313,7 @@ function legacyClaudePluginWarning(key) {
|
|
|
18038
18313
|
}
|
|
18039
18314
|
|
|
18040
18315
|
// src/core/session-cache.ts
|
|
18041
|
-
import { mkdirSync as mkdirSync4, readFileSync as
|
|
18316
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "fs";
|
|
18042
18317
|
import { tmpdir as tmpdir3 } from "os";
|
|
18043
18318
|
import { dirname as dirname9, join as join17 } from "path";
|
|
18044
18319
|
function sessionCacheFile(harness, sessionId) {
|
|
@@ -18046,7 +18321,7 @@ function sessionCacheFile(harness, sessionId) {
|
|
|
18046
18321
|
}
|
|
18047
18322
|
function readSessionCache(cacheFile) {
|
|
18048
18323
|
try {
|
|
18049
|
-
return JSON.parse(
|
|
18324
|
+
return JSON.parse(readFileSync9(cacheFile, "utf8"));
|
|
18050
18325
|
} catch {
|
|
18051
18326
|
return {};
|
|
18052
18327
|
}
|
|
@@ -18055,7 +18330,7 @@ function writeFileAtomic(path, body) {
|
|
|
18055
18330
|
mkdirSync4(dirname9(path), { recursive: true });
|
|
18056
18331
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
18057
18332
|
try {
|
|
18058
|
-
|
|
18333
|
+
writeFileSync4(tmp, body);
|
|
18059
18334
|
renameSync3(tmp, path);
|
|
18060
18335
|
} catch (e) {
|
|
18061
18336
|
try {
|
|
@@ -18165,12 +18440,13 @@ async function buildSessionStartContext(args) {
|
|
|
18165
18440
|
startSeed(cwd, { limit: cfg.seedLimit, harness });
|
|
18166
18441
|
if (cold) {
|
|
18167
18442
|
if (cfg.codebaseSurvey !== false) {
|
|
18443
|
+
const sha = resolveHeadSha(cwd);
|
|
18168
18444
|
const started = await startSurvey(cwd, {
|
|
18169
18445
|
harness,
|
|
18170
18446
|
model: cfg.surveyModel,
|
|
18171
|
-
budgetUsd: cfg.surveyBudgetUsd
|
|
18447
|
+
budgetUsd: cfg.surveyBudgetUsd,
|
|
18448
|
+
sha: sha ?? void 0
|
|
18172
18449
|
});
|
|
18173
|
-
const sha = resolveHeadSha(cwd);
|
|
18174
18450
|
if (started && sha) recordSurveyBaseline(sha);
|
|
18175
18451
|
}
|
|
18176
18452
|
diag(harness, "seed_started", { bank: bankId });
|
|
@@ -18191,7 +18467,8 @@ async function buildSessionStartContext(args) {
|
|
|
18191
18467
|
const started = await startSurvey(cwd, {
|
|
18192
18468
|
harness,
|
|
18193
18469
|
model: cfg.surveyModel,
|
|
18194
|
-
budgetUsd: cfg.surveyBudgetUsd
|
|
18470
|
+
budgetUsd: cfg.surveyBudgetUsd,
|
|
18471
|
+
sha
|
|
18195
18472
|
});
|
|
18196
18473
|
if (started) {
|
|
18197
18474
|
recordSurveyBaseline(sha);
|
|
@@ -18293,7 +18570,7 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
|
|
|
18293
18570
|
}
|
|
18294
18571
|
|
|
18295
18572
|
// src/core/turn-journal.ts
|
|
18296
|
-
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as
|
|
18573
|
+
import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync10, statSync as statSync4 } from "fs";
|
|
18297
18574
|
import { tmpdir as tmpdir4 } from "os";
|
|
18298
18575
|
import { dirname as dirname10, join as join18 } from "path";
|
|
18299
18576
|
|
|
@@ -18544,8 +18821,6 @@ var RuntimeCore = class {
|
|
|
18544
18821
|
fetchTranscript;
|
|
18545
18822
|
/** Write-backs started and not yet settled — what `flush` waits for. */
|
|
18546
18823
|
inFlight = /* @__PURE__ */ new Set();
|
|
18547
|
-
lastInjection = "";
|
|
18548
|
-
// most recent turn's injection block, keyed by nothing (see getInjection)
|
|
18549
18824
|
deferInitialReflect = false;
|
|
18550
18825
|
/** Host-notice channel (opencode/Kilo: client.tui.showToast via the adapter). Optional, fail-open. */
|
|
18551
18826
|
notify;
|
|
@@ -18617,7 +18892,11 @@ var RuntimeCore = class {
|
|
|
18617
18892
|
*/
|
|
18618
18893
|
async onPrompt(sessionId, prompt) {
|
|
18619
18894
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
18620
|
-
if (!sessionId
|
|
18895
|
+
if (!sessionId) return;
|
|
18896
|
+
if (!prompt.trim()) {
|
|
18897
|
+
this.injection.delete(sessionId);
|
|
18898
|
+
return;
|
|
18899
|
+
}
|
|
18621
18900
|
const turns = (this.turnCount.get(sessionId) ?? 0) + 1;
|
|
18622
18901
|
this.turnCount.set(sessionId, turns);
|
|
18623
18902
|
const cacheFile = sessionCacheFile(this.harness, sessionId);
|
|
@@ -18649,18 +18928,21 @@ var RuntimeCore = class {
|
|
|
18649
18928
|
}
|
|
18650
18929
|
const block = blocks.filter(Boolean).join("\n\n");
|
|
18651
18930
|
this.injection.set(sessionId, block);
|
|
18652
|
-
this.lastInjection = block;
|
|
18653
18931
|
}
|
|
18654
18932
|
/**
|
|
18655
|
-
* The
|
|
18656
|
-
*
|
|
18657
|
-
*
|
|
18658
|
-
* turn
|
|
18659
|
-
*
|
|
18933
|
+
* The text to inject into this turn's user message (built by the preceding onPrompt), or
|
|
18934
|
+
* undefined.
|
|
18935
|
+
*
|
|
18936
|
+
* It goes into the USER turn on every host, never the system prompt (#5914). The block changes
|
|
18937
|
+
* from turn to turn — the recall runs once, the roster refresh on a cadence — so a system prompt
|
|
18938
|
+
* carrying it differed between requests and broke the provider's prefix cache from that point
|
|
18939
|
+
* on. Persisted in the turn it belongs to, it leaves the system prompt and the earlier history
|
|
18940
|
+
* byte-identical. That used to need a fallback to the most recent block for opencode's
|
|
18941
|
+
* `experimental.chat.system.transform`, which fired with no session id; nothing reads it that
|
|
18942
|
+
* way any more.
|
|
18660
18943
|
*/
|
|
18661
18944
|
getInjection(sessionId) {
|
|
18662
|
-
|
|
18663
|
-
return keyed ?? this.lastInjection ?? void 0;
|
|
18945
|
+
return this.injection.get(sessionId) || void 0;
|
|
18664
18946
|
}
|
|
18665
18947
|
/**
|
|
18666
18948
|
* Full normalized transcript (rich: user/assistant text + tool calls/outputs): upsert every turn
|
|
@@ -18815,6 +19097,36 @@ function readOpencode2Messages(messages) {
|
|
|
18815
19097
|
// src/harness/plugin-entry.ts
|
|
18816
19098
|
import { posix, win32 } from "path";
|
|
18817
19099
|
|
|
19100
|
+
// src/core/transcript-opencode.ts
|
|
19101
|
+
function renderMessage2(m) {
|
|
19102
|
+
const role = m.info?.role;
|
|
19103
|
+
if (role !== "user" && role !== "assistant") return [];
|
|
19104
|
+
const created = m.info?.time?.created;
|
|
19105
|
+
const ts = created ? { timestamp: new Date(created).toISOString() } : {};
|
|
19106
|
+
const texts = [];
|
|
19107
|
+
const actions = [];
|
|
19108
|
+
for (const p of m.parts || []) {
|
|
19109
|
+
if (!p || typeof p !== "object") continue;
|
|
19110
|
+
if (p.type === "text" && typeof p.text === "string") {
|
|
19111
|
+
const t = stripInjectedMemory(p.text).trim();
|
|
19112
|
+
if (t) texts.push(t);
|
|
19113
|
+
} else if (p.type === "tool" && typeof p.tool === "string") {
|
|
19114
|
+
actions.push({ role: "action", content: actionLine(p.tool, p.state?.input), ...ts });
|
|
19115
|
+
}
|
|
19116
|
+
}
|
|
19117
|
+
const out = [];
|
|
19118
|
+
const joined = texts.join("\n").trim();
|
|
19119
|
+
if (joined) out.push({ role, content: joined, ...ts });
|
|
19120
|
+
out.push(...actions);
|
|
19121
|
+
return out;
|
|
19122
|
+
}
|
|
19123
|
+
function readOpencodeMessages(messages) {
|
|
19124
|
+
return (messages || []).flatMap((m) => renderMessage2(m));
|
|
19125
|
+
}
|
|
19126
|
+
function opencodeSessionId(messages) {
|
|
19127
|
+
return [...messages || []].reverse().find((m) => m.info?.sessionID)?.info?.sessionID;
|
|
19128
|
+
}
|
|
19129
|
+
|
|
18818
19130
|
// node_modules/@opencode-ai/plugin/node_modules/zod/v4/classic/external.js
|
|
18819
19131
|
var external_exports2 = {};
|
|
18820
19132
|
__export(external_exports2, {
|
|
@@ -18987,7 +19299,7 @@ __export(external_exports2, {
|
|
|
18987
19299
|
object: () => object2,
|
|
18988
19300
|
optional: () => optional2,
|
|
18989
19301
|
overwrite: () => _overwrite2,
|
|
18990
|
-
parse: () =>
|
|
19302
|
+
parse: () => parse5,
|
|
18991
19303
|
parseAsync: () => parseAsync4,
|
|
18992
19304
|
partialRecord: () => partialRecord2,
|
|
18993
19305
|
pipe: () => pipe2,
|
|
@@ -19291,7 +19603,7 @@ __export(core_exports4, {
|
|
|
19291
19603
|
isValidBase64URL: () => isValidBase64URL2,
|
|
19292
19604
|
isValidJWT: () => isValidJWT2,
|
|
19293
19605
|
locales: () => locales_exports2,
|
|
19294
|
-
parse: () =>
|
|
19606
|
+
parse: () => parse4,
|
|
19295
19607
|
parseAsync: () => parseAsync3,
|
|
19296
19608
|
prettifyError: () => prettifyError2,
|
|
19297
19609
|
regexes: () => regexes_exports2,
|
|
@@ -20165,7 +20477,7 @@ var _parse2 = (_Err) => (schema, value, _ctx, _params) => {
|
|
|
20165
20477
|
}
|
|
20166
20478
|
return result.value;
|
|
20167
20479
|
};
|
|
20168
|
-
var
|
|
20480
|
+
var parse4 = /* @__PURE__ */ _parse2($ZodRealError2);
|
|
20169
20481
|
var _parseAsync2 = (_Err) => async (schema, value, _ctx, params) => {
|
|
20170
20482
|
const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
|
|
20171
20483
|
let result = schema._zod.run({ value, issues: [] }, ctx);
|
|
@@ -22688,10 +23000,10 @@ var $ZodFunction2 = /* @__PURE__ */ $constructor2("$ZodFunction", (inst, def) =>
|
|
|
22688
23000
|
throw new Error("implement() must be called with a function");
|
|
22689
23001
|
}
|
|
22690
23002
|
return function(...args) {
|
|
22691
|
-
const parsedArgs = inst._def.input ?
|
|
23003
|
+
const parsedArgs = inst._def.input ? parse4(inst._def.input, args) : args;
|
|
22692
23004
|
const result = Reflect.apply(func, this, parsedArgs);
|
|
22693
23005
|
if (inst._def.output) {
|
|
22694
|
-
return
|
|
23006
|
+
return parse4(inst._def.output, result);
|
|
22695
23007
|
}
|
|
22696
23008
|
return result;
|
|
22697
23009
|
};
|
|
@@ -30183,7 +30495,7 @@ var ZodRealError2 = $constructor2("ZodError", initializer4, {
|
|
|
30183
30495
|
});
|
|
30184
30496
|
|
|
30185
30497
|
// node_modules/@opencode-ai/plugin/node_modules/zod/v4/classic/parse.js
|
|
30186
|
-
var
|
|
30498
|
+
var parse5 = /* @__PURE__ */ _parse2(ZodRealError2);
|
|
30187
30499
|
var parseAsync4 = /* @__PURE__ */ _parseAsync2(ZodRealError2);
|
|
30188
30500
|
var safeParse4 = /* @__PURE__ */ _safeParse2(ZodRealError2);
|
|
30189
30501
|
var safeParseAsync4 = /* @__PURE__ */ _safeParseAsync2(ZodRealError2);
|
|
@@ -30220,7 +30532,7 @@ var ZodType2 = /* @__PURE__ */ $constructor2("ZodType", (inst, def) => {
|
|
|
30220
30532
|
reg.add(inst, meta3);
|
|
30221
30533
|
return inst;
|
|
30222
30534
|
});
|
|
30223
|
-
inst.parse = (data, params) =>
|
|
30535
|
+
inst.parse = (data, params) => parse5(inst, data, params, { callee: inst.parse });
|
|
30224
30536
|
inst.safeParse = (data, params) => safeParse4(inst, data, params);
|
|
30225
30537
|
inst.parseAsync = async (data, params) => parseAsync4(inst, data, params, { callee: inst.parseAsync });
|
|
30226
30538
|
inst.safeParseAsync = async (data, params) => safeParseAsync4(inst, data, params);
|
|
@@ -31238,19 +31550,93 @@ function tool(input) {
|
|
|
31238
31550
|
tool.schema = external_exports2;
|
|
31239
31551
|
|
|
31240
31552
|
// src/harness/registry.ts
|
|
31241
|
-
import { readFileSync as
|
|
31553
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
31242
31554
|
var jsonChatReader = (harness) => ({
|
|
31243
31555
|
describe: `${harness} sessions via a normalized JSON export (--conversations file: [{ id, turns:[{role,text,timestamp?}] }])`,
|
|
31244
31556
|
async read(opts) {
|
|
31245
31557
|
if (!opts.conversations) return [];
|
|
31246
|
-
return JSON.parse(
|
|
31558
|
+
return JSON.parse(readFileSync11(opts.conversations, "utf8"));
|
|
31247
31559
|
}
|
|
31248
31560
|
});
|
|
31249
31561
|
|
|
31250
31562
|
// src/harness/opencode.ts
|
|
31563
|
+
var surveyAgentHook = {
|
|
31564
|
+
config: async (cfg) => {
|
|
31565
|
+
cfg.agent ??= {};
|
|
31566
|
+
cfg.agent[SURVEY_AGENT] ??= SURVEY_AGENT_CONFIG;
|
|
31567
|
+
}
|
|
31568
|
+
};
|
|
31569
|
+
var textOf = (parts) => (parts || []).filter((p) => p?.type === "text" && p.text).map((p) => p.text).join("\n").trim();
|
|
31251
31570
|
var chatReader = jsonChatReader("opencode");
|
|
31571
|
+
function toOpencodeTool(spec) {
|
|
31572
|
+
return tool({
|
|
31573
|
+
description: spec.description,
|
|
31574
|
+
// @opencode-ai/plugin bundles its own zod (v4.1.x); the project uses zod v4.4.x. The two are
|
|
31575
|
+
// runtime-compatible (same major), but their $ZodType brands differ, so TS rejects the
|
|
31576
|
+
// cross-instance assignment. Cast the raw shape to the plugin's expected `args` type — opencode
|
|
31577
|
+
// validates the args with its own zod at call time regardless.
|
|
31578
|
+
args: spec.inputSchema,
|
|
31579
|
+
async execute(args) {
|
|
31580
|
+
const r = await spec.handler(args);
|
|
31581
|
+
return r.content?.map((c) => c.text).join("\n") || "";
|
|
31582
|
+
}
|
|
31583
|
+
});
|
|
31584
|
+
}
|
|
31585
|
+
function createRuntime(core) {
|
|
31586
|
+
const tools = {};
|
|
31587
|
+
for (const spec of core.toolSpecs()) tools[spec.name] = toOpencodeTool(spec);
|
|
31588
|
+
return {
|
|
31589
|
+
...surveyAgentHook,
|
|
31590
|
+
tool: tools,
|
|
31591
|
+
// Each user turn: recall on the prompt, then add this turn's injection (recalled memories +
|
|
31592
|
+
// attribution/user-feedback framing, plus the knowledge preamble on turn 1 and the roster
|
|
31593
|
+
// refresh on cadence) to the user message as a synthetic text part. The host saves the parts
|
|
31594
|
+
// this hook leaves behind, so the block stays in the turn it was made for and every later
|
|
31595
|
+
// request repeats it byte for byte. It used to be pushed into the system prompt through
|
|
31596
|
+
// `experimental.chat.system.transform`, which made the system prompt change between turns
|
|
31597
|
+
// and broke the provider's prefix cache (#5914).
|
|
31598
|
+
"chat.message": async (input, output) => {
|
|
31599
|
+
await core.onPrompt(input.sessionID, textOf(output.parts));
|
|
31600
|
+
const inj = core.getInjection(input.sessionID);
|
|
31601
|
+
if (inj)
|
|
31602
|
+
output.parts.unshift({
|
|
31603
|
+
id: `prt-hindsight-${output.message.id}`,
|
|
31604
|
+
sessionID: input.sessionID,
|
|
31605
|
+
messageID: output.message.id,
|
|
31606
|
+
type: "text",
|
|
31607
|
+
text: inj,
|
|
31608
|
+
synthetic: true
|
|
31609
|
+
});
|
|
31610
|
+
diag(core.harness, inj ? "inject_ok" : "inject_empty", { chars: inj?.length ?? 0 });
|
|
31611
|
+
},
|
|
31612
|
+
// Write-back (on by default): normalize the live transcript to rich turns (text + tool calls +
|
|
31613
|
+
// their inline output) and hand it to core, which upserts every N user turns.
|
|
31614
|
+
//
|
|
31615
|
+
// NOTE this fires while the host BUILDS a request, so `messages` never includes the reply that
|
|
31616
|
+
// request is about to produce — on its own it always lags a turn. `session.idle` below closes
|
|
31617
|
+
// that gap; this stays as the mid-session cadence path.
|
|
31618
|
+
"experimental.chat.messages.transform": async (_input, output) => {
|
|
31619
|
+
if (!core.writeBackEnabled) return;
|
|
31620
|
+
const msgs = output.messages || [];
|
|
31621
|
+
const sid = opencodeSessionId(msgs);
|
|
31622
|
+
if (!sid) return;
|
|
31623
|
+
await core.onTranscript(sid, readOpencodeMessages(msgs), false);
|
|
31624
|
+
},
|
|
31625
|
+
// The Stop-equivalent these hosts otherwise lack: `session.idle` fires once the assistant has
|
|
31626
|
+
// finished, which is the only moment the completed exchange is readable. Without it a session's
|
|
31627
|
+
// last turn — usually its conclusion — was never retained at all.
|
|
31628
|
+
event: async (input) => {
|
|
31629
|
+
if (input?.event?.type !== "session.idle") return;
|
|
31630
|
+
const sid = input.event.properties?.sessionID;
|
|
31631
|
+
if (!sid) return;
|
|
31632
|
+
await core.onSessionIdle(sid);
|
|
31633
|
+
}
|
|
31634
|
+
};
|
|
31635
|
+
}
|
|
31636
|
+
var opencodeAdapter = { name: "opencode", chatReader, createRuntime };
|
|
31252
31637
|
|
|
31253
31638
|
// src/harness/plugin-entry.ts
|
|
31639
|
+
var TOAST_MOUNT_GRACE_MS = 3e3;
|
|
31254
31640
|
function isFilesystemRoot(path) {
|
|
31255
31641
|
return posix.parse(path).root === path || win32.parse(path).root === path;
|
|
31256
31642
|
}
|
|
@@ -31258,6 +31644,44 @@ function resolveProjectDirectory(input) {
|
|
|
31258
31644
|
const worktree = input?.worktree;
|
|
31259
31645
|
return worktree && !isFilesystemRoot(worktree) ? worktree : input?.directory;
|
|
31260
31646
|
}
|
|
31647
|
+
function createPluginEntry(harness) {
|
|
31648
|
+
return async (input) => {
|
|
31649
|
+
const projectDir = resolveProjectDirectory(input);
|
|
31650
|
+
const dir = projectDir || process.cwd();
|
|
31651
|
+
const { cfg, bankId, client } = resolveHostMemory(harness, dir);
|
|
31652
|
+
if (cfg.disabled) return {};
|
|
31653
|
+
const core = new RuntimeCore(client, bankId, cfg, harness, dir);
|
|
31654
|
+
const oc = input?.client;
|
|
31655
|
+
log.debug(harness, "toast channel", { wired: Boolean(oc?.tui?.showToast) });
|
|
31656
|
+
if (oc?.tui?.showToast) {
|
|
31657
|
+
const initAt = Date.now();
|
|
31658
|
+
core.setNotifier((title, message) => {
|
|
31659
|
+
const wait = Math.max(0, TOAST_MOUNT_GRACE_MS - (Date.now() - initAt));
|
|
31660
|
+
setTimeout(() => {
|
|
31661
|
+
void oc.tui.showToast({ body: { title, message, variant: "info", duration: 6e3 } }).then((r) => {
|
|
31662
|
+
const err2 = r?.error;
|
|
31663
|
+
if (err2)
|
|
31664
|
+
log.debug(harness, "toast rejected", { error: JSON.stringify(err2).slice(0, 200) });
|
|
31665
|
+
}).catch(
|
|
31666
|
+
(e) => log.debug(harness, "toast failed", { error: String(e).slice(0, 120) })
|
|
31667
|
+
);
|
|
31668
|
+
}, wait).unref?.();
|
|
31669
|
+
});
|
|
31670
|
+
}
|
|
31671
|
+
const sessionApi = oc?.session;
|
|
31672
|
+
if (sessionApi?.messages) {
|
|
31673
|
+
core.setTranscriptSource(async (sessionId) => {
|
|
31674
|
+
const r = await sessionApi.messages({ path: { id: sessionId } });
|
|
31675
|
+
if (r?.error) throw new Error(JSON.stringify(r.error).slice(0, 200));
|
|
31676
|
+
return readOpencodeMessages(r?.data ?? []);
|
|
31677
|
+
});
|
|
31678
|
+
}
|
|
31679
|
+
log.debug(harness, "transcript source", { wired: Boolean(sessionApi?.messages) });
|
|
31680
|
+
const runtime = opencodeAdapter.createRuntime(core);
|
|
31681
|
+
void core.seedIfCold(projectDir);
|
|
31682
|
+
return runtime;
|
|
31683
|
+
};
|
|
31684
|
+
}
|
|
31261
31685
|
|
|
31262
31686
|
// src/harness/opencode2.ts
|
|
31263
31687
|
var IDLE_EVENTS = /* @__PURE__ */ new Set([
|
|
@@ -31304,11 +31728,22 @@ async function wireOpencode2Runtime(core, ctx) {
|
|
|
31304
31728
|
await ctx.session.hook("prompt", async (input) => {
|
|
31305
31729
|
ownSessions.add(input.sessionID);
|
|
31306
31730
|
await core.onPrompt(input.sessionID, input.prompt?.text ?? "");
|
|
31307
|
-
});
|
|
31308
|
-
await ctx.session.hook("context", (input) => {
|
|
31309
31731
|
const inj = core.getInjection(input.sessionID);
|
|
31310
|
-
if (inj)
|
|
31311
|
-
|
|
31732
|
+
if (!inj) {
|
|
31733
|
+
diag(harness, "inject_empty", { chars: 0 });
|
|
31734
|
+
return;
|
|
31735
|
+
}
|
|
31736
|
+
try {
|
|
31737
|
+
await ctx.session.synthetic({
|
|
31738
|
+
sessionID: input.sessionID,
|
|
31739
|
+
text: inj,
|
|
31740
|
+
description: "Hindsight memory",
|
|
31741
|
+
resume: false
|
|
31742
|
+
});
|
|
31743
|
+
diag(harness, "inject_ok", { chars: inj.length });
|
|
31744
|
+
} catch (e) {
|
|
31745
|
+
diag(harness, "inject_failed", { error: describeError(e) });
|
|
31746
|
+
}
|
|
31312
31747
|
});
|
|
31313
31748
|
const events = new AbortController();
|
|
31314
31749
|
void (async () => {
|
|
@@ -31344,9 +31779,51 @@ function createOpencode2PluginEntry(harness) {
|
|
|
31344
31779
|
}
|
|
31345
31780
|
|
|
31346
31781
|
// src/opencode2.ts
|
|
31347
|
-
var HindsightOpencode2Plugin =
|
|
31782
|
+
var HindsightOpencode2Plugin = {
|
|
31783
|
+
...createOpencode2PluginEntry("opencode2"),
|
|
31784
|
+
server: createPluginEntry("opencode")
|
|
31785
|
+
};
|
|
31348
31786
|
var opencode2_default = HindsightOpencode2Plugin;
|
|
31349
31787
|
export {
|
|
31350
31788
|
HindsightOpencode2Plugin,
|
|
31351
31789
|
opencode2_default as default
|
|
31352
31790
|
};
|
|
31791
|
+
/*! Bundled license information:
|
|
31792
|
+
|
|
31793
|
+
smol-toml/dist/error.js:
|
|
31794
|
+
smol-toml/dist/primitive.js:
|
|
31795
|
+
smol-toml/dist/date.js:
|
|
31796
|
+
smol-toml/dist/extract.js:
|
|
31797
|
+
smol-toml/dist/util.js:
|
|
31798
|
+
smol-toml/dist/struct.js:
|
|
31799
|
+
smol-toml/dist/parse.js:
|
|
31800
|
+
smol-toml/dist/stringify.js:
|
|
31801
|
+
smol-toml/dist/index.js:
|
|
31802
|
+
(*!
|
|
31803
|
+
* Copyright (c) Squirrel Chat et al., All rights reserved.
|
|
31804
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
31805
|
+
*
|
|
31806
|
+
* Redistribution and use in source and binary forms, with or without
|
|
31807
|
+
* modification, are permitted provided that the following conditions are met:
|
|
31808
|
+
*
|
|
31809
|
+
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
31810
|
+
* list of conditions and the following disclaimer.
|
|
31811
|
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
31812
|
+
* this list of conditions and the following disclaimer in the
|
|
31813
|
+
* documentation and/or other materials provided with the distribution.
|
|
31814
|
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
|
31815
|
+
* may be used to endorse or promote products derived from this software without
|
|
31816
|
+
* specific prior written permission.
|
|
31817
|
+
*
|
|
31818
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
31819
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
31820
|
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
31821
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
31822
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
31823
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
31824
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
31825
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
31826
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
31827
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31828
|
+
*)
|
|
31829
|
+
*/
|