@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.
Files changed (64) hide show
  1. package/README.md +13 -3
  2. package/dist/antigravity-hook.js +95 -42
  3. package/dist/antigravity-statusline.js +6 -6
  4. package/dist/antigravity-stop-hook.js +132 -51
  5. package/dist/claude-hook.js +95 -42
  6. package/dist/claude-sessionstart-hook.js +383 -99
  7. package/dist/claude-stop-hook.js +132 -51
  8. package/dist/cline.js +401 -91
  9. package/dist/codebuddy-hook.js +95 -42
  10. package/dist/codebuddy-sessionstart-hook.js +383 -99
  11. package/dist/codebuddy-stop-hook.js +132 -51
  12. package/dist/codex-hook.js +95 -42
  13. package/dist/codex-sessionstart-hook.js +383 -99
  14. package/dist/codex-stop-hook.js +132 -51
  15. package/dist/copilot-hook.js +95 -42
  16. package/dist/copilot-sessionstart-hook.js +383 -99
  17. package/dist/copilot-stop-hook.js +132 -51
  18. package/dist/cursor-hook.js +95 -42
  19. package/dist/cursor-sessionstart-hook.js +383 -99
  20. package/dist/cursor-stop-hook.js +132 -51
  21. package/dist/daemon-start.js +10 -10
  22. package/dist/dcode-hook.js +95 -42
  23. package/dist/dcode-sessionstart-hook.js +383 -99
  24. package/dist/dcode-stop-hook.js +132 -51
  25. package/dist/deepen.js +82 -23
  26. package/dist/devin-hook.js +95 -42
  27. package/dist/devin-sessionstart-hook.js +383 -99
  28. package/dist/devin-stop-hook.js +132 -51
  29. package/dist/droid-hook.js +95 -42
  30. package/dist/droid-sessionstart-hook.js +383 -99
  31. package/dist/droid-stop-hook.js +132 -51
  32. package/dist/dsh.js +420 -98
  33. package/dist/grok-hook.js +95 -42
  34. package/dist/grok-sessionstart-hook.js +383 -99
  35. package/dist/grok-stop-hook.js +132 -51
  36. package/dist/hindsight-seed.js +6 -6
  37. package/dist/index.js +425 -110
  38. package/dist/installer.js +89 -80
  39. package/dist/kilo.js +425 -110
  40. package/dist/kimi-hook.js +95 -42
  41. package/dist/kimi-sessionstart-hook.js +383 -99
  42. package/dist/kimi-stop-hook.js +132 -51
  43. package/dist/mcp-server.js +169 -62
  44. package/dist/opencode2.js +581 -104
  45. package/dist/pi.js +401 -98
  46. package/dist/prime-agent.js +401 -98
  47. package/dist/qwen-hook.js +95 -42
  48. package/dist/qwen-sessionstart-hook.js +383 -99
  49. package/dist/qwen-stop-hook.js +132 -51
  50. package/dist/status.js +67 -17
  51. package/dist/survey-supervisor.js +73 -9
  52. package/dist/traecode-hook.js +95 -42
  53. package/dist/traecode-sessionstart-hook.js +383 -99
  54. package/dist/traecode-stop-hook.js +132 -51
  55. package/dist/workbuddy-hook.js +95 -42
  56. package/dist/workbuddy-sessionstart-hook.js +383 -99
  57. package/dist/workbuddy-stop-hook.js +132 -51
  58. package/dist/zcode-hook.js +95 -42
  59. package/dist/zcode-sessionstart-hook.js +383 -99
  60. package/dist/zcode-stop-hook.js +132 -51
  61. package/index.js +4 -1
  62. package/package.json +6 -4
  63. package/plugin.json +1 -1
  64. package/skill/SKILL.md +10 -2
package/dist/index.js CHANGED
@@ -228,14 +228,14 @@ function probeGitLayout(directory) {
228
228
  var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
229
229
  function applyTemplate(template, resolvers, what) {
230
230
  return template.replace(PLACEHOLDER, (_, name) => {
231
- const resolve3 = resolvers[name];
232
- if (!resolve3) {
231
+ const resolve4 = resolvers[name];
232
+ if (!resolve4) {
233
233
  console.error(
234
234
  `hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
235
235
  );
236
236
  return "unknown";
237
237
  }
238
- return resolve3();
238
+ return resolve4();
239
239
  });
240
240
  }
241
241
 
@@ -656,29 +656,33 @@ function codingBankManifest(overrides, mode = DEFAULT_RETAIN_EXTRACTION_MODE, de
656
656
  }
657
657
 
658
658
  // package.json
659
- var version = "0.8.2";
659
+ var version = "0.8.3";
660
660
 
661
661
  // src/core/util.ts
662
- import { accessSync, constants } from "fs";
663
- import { delimiter, join as join6 } from "path";
664
- function binOnPath(bin) {
665
- try {
666
- if (bin.includes("/")) {
667
- accessSync(bin, constants.X_OK);
662
+ import { accessSync, constants, statSync as statSync2 } from "fs";
663
+ import { delimiter, extname, isAbsolute as isAbsolute2, join as join6, resolve as resolve2 } from "path";
664
+ function binOnPath(bin, opts = {}) {
665
+ const platform = opts.platform ?? process.platform;
666
+ const env = opts.env ?? process.env;
667
+ const runnable = (file3) => {
668
+ try {
669
+ if (!statSync2(file3).isFile()) return false;
670
+ if (platform !== "win32") accessSync(file3, constants.X_OK);
668
671
  return true;
672
+ } catch {
673
+ return false;
669
674
  }
670
- for (const dir of (process.env.PATH || "").split(delimiter)) {
671
- if (!dir) continue;
672
- try {
673
- accessSync(join6(dir, bin), constants.X_OK);
674
- return true;
675
- } catch {
676
- }
675
+ };
676
+ if (isAbsolute2(bin) || /[\\/]/.test(bin)) return runnable(bin) ? resolve2(bin) : void 0;
677
+ const names = platform !== "win32" || extname(bin) ? [bin] : (opts.exts ?? (env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";")).filter(Boolean).map((ext) => bin + ext.toLowerCase());
678
+ for (const dir of (env.PATH || "").split(delimiter)) {
679
+ if (!dir) continue;
680
+ for (const name of names) {
681
+ const file3 = join6(dir, name);
682
+ if (runnable(file3)) return resolve2(file3);
677
683
  }
678
- return false;
679
- } catch {
680
- return false;
681
684
  }
685
+ return void 0;
682
686
  }
683
687
  var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
684
688
  function semverGte(version4, min) {
@@ -948,15 +952,19 @@ var HindsightClient = class {
948
952
  }
949
953
  /**
950
954
  * Whether this server honours `operation_id` on an async retain, and can therefore be appended to
951
- * safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed once per client via the version endpoint; anything
955
+ * safely (see MIN_IDEMPOTENT_RETAIN_VERSION). Probed via the version endpoint; anything
952
956
  * unreachable, unparseable or older answers "no", which costs efficiency, never correctness.
957
+ * Only a "yes" is cached: a long-lived plugin client would otherwise keep replacing for the rest
958
+ * of the process after one probe that hit a restarting server (#5735).
953
959
  */
954
960
  async supportsIdempotentRetain() {
955
- if (this.idempotentRetain === void 0) {
956
- this.idempotentRetain = await this.probeIdempotentRetain();
957
- this.log(`server retain idempotency: ${this.idempotentRetain ? "supported" : "unavailable"}`);
961
+ if (this.idempotentRetain) return true;
962
+ const supported = await this.probeIdempotentRetain();
963
+ if (supported || this.idempotentRetain === void 0) {
964
+ this.log(`server retain idempotency: ${supported ? "supported" : "unavailable"}`);
958
965
  }
959
- return this.idempotentRetain;
966
+ this.idempotentRetain = supported;
967
+ return supported;
960
968
  }
961
969
  /** `/v1/version` first: an ingress that routes only `/v1` to the API (the Helm chart's default)
962
970
  * hands a bare `/version` to the control plane, whose HTML 404 or login redirect read as "no",
@@ -1990,15 +1998,15 @@ function stagedVersion(pkgRoot) {
1990
1998
  }
1991
1999
  }
1992
2000
  function isNewer(candidate, current2) {
1993
- const parse5 = (v) => {
2001
+ const parse6 = (v) => {
1994
2002
  const [core = "", ...rest] = v.trim().split("-");
1995
2003
  return {
1996
2004
  nums: core.split(".").map((n) => Number.parseInt(n, 10)),
1997
2005
  pre: rest.length > 0
1998
2006
  };
1999
2007
  };
2000
- const a = parse5(candidate);
2001
- const b = parse5(current2);
2008
+ const a = parse6(candidate);
2009
+ const b = parse6(current2);
2002
2010
  if (a.nums.length !== 3 || b.nums.length !== 3) return false;
2003
2011
  if (a.nums.some(Number.isNaN) || b.nums.some(Number.isNaN)) return false;
2004
2012
  for (let i = 0; i < 3; i++) {
@@ -2075,7 +2083,7 @@ function spawnNpm(spawnImpl, bin, args, opts) {
2075
2083
  return process.platform === "win32" ? spawnImpl([bin, ...args].join(" "), { ...opts, shell: true }) : spawnImpl(bin, args, opts);
2076
2084
  }
2077
2085
  async function npmViewVersion(pkg, spawnImpl = realSpawn2) {
2078
- return new Promise((resolve3) => {
2086
+ return new Promise((resolve4) => {
2079
2087
  let out = "";
2080
2088
  let settled = false;
2081
2089
  let deadline;
@@ -2084,7 +2092,7 @@ async function npmViewVersion(pkg, spawnImpl = realSpawn2) {
2084
2092
  settled = true;
2085
2093
  if (deadline) clearTimeout(deadline);
2086
2094
  if (reason) log.info("auto-update", `version check failed: ${reason}`);
2087
- resolve3(v);
2095
+ resolve4(v);
2088
2096
  };
2089
2097
  try {
2090
2098
  const child = spawnNpm(spawnImpl, "npm", ["view", pkg, "version", "--json"], {
@@ -2281,8 +2289,8 @@ async function waitBounded(p, ms) {
2281
2289
  try {
2282
2290
  await Promise.race([
2283
2291
  p,
2284
- new Promise((resolve3) => {
2285
- timer = setTimeout(resolve3, Math.max(ms, 0));
2292
+ new Promise((resolve4) => {
2293
+ timer = setTimeout(resolve4, Math.max(ms, 0));
2286
2294
  })
2287
2295
  ]);
2288
2296
  } finally {
@@ -16927,7 +16935,7 @@ import { execFileSync as execFileSync4 } from "child_process";
16927
16935
 
16928
16936
  // src/core/git.ts
16929
16937
  import { execFileSync as execFileSync2 } from "child_process";
16930
- import { resolve as resolve2 } from "path";
16938
+ import { resolve as resolve3 } from "path";
16931
16939
 
16932
16940
  // src/core/uuid.ts
16933
16941
  import { createHash as createHash2 } from "crypto";
@@ -16955,18 +16963,25 @@ var US = "";
16955
16963
  var RS = "";
16956
16964
  var GITLOG_HEAD = "gitlog-head:";
16957
16965
  var GITLOG_FORMAT = `--format=%h${US}%ad${US}%an${US}%s${US}%b${RS}`;
16958
- function git(repo, ...args) {
16966
+ function runGit(repo, args, env) {
16959
16967
  return execFileSync2("git", ["-C", repo, "-c", "log.showSignature=false", ...args], {
16960
16968
  encoding: "utf8",
16961
16969
  maxBuffer: 1 << 28,
16962
16970
  windowsHide: true,
16971
+ env,
16963
16972
  // execFileSync otherwise forwards failed git stderr into the host's TUI,
16964
16973
  // even when callers catch the error. Keep diagnostics on the error instead.
16965
16974
  stdio: ["ignore", "pipe", "pipe"]
16966
16975
  });
16967
16976
  }
16977
+ function git(repo, ...args) {
16978
+ return runGit(repo, args);
16979
+ }
16980
+ function gitLocal(repo, ...args) {
16981
+ return runGit(repo, args, { ...process.env, GIT_NO_LAZY_FETCH: "1" });
16982
+ }
16968
16983
  function repoNameOf(repo) {
16969
- return projectNameOf(resolve2(repo));
16984
+ return projectNameOf(resolve3(repo));
16970
16985
  }
16971
16986
  function gitHeadSha(dir) {
16972
16987
  try {
@@ -16978,7 +16993,7 @@ function gitHeadSha(dir) {
16978
16993
  function commitsSince(dir, sinceSha) {
16979
16994
  if (!/^[0-9a-f]{40}(?:[0-9a-f]{24})?$/.test(sinceSha)) return null;
16980
16995
  try {
16981
- const n = Number.parseInt(git(dir, "rev-list", "--count", `${sinceSha}..HEAD`).trim(), 10);
16996
+ const n = Number.parseInt(gitLocal(dir, "rev-list", "--count", `${sinceSha}..HEAD`).trim(), 10);
16982
16997
  return Number.isFinite(n) ? n : null;
16983
16998
  } catch {
16984
16999
  return null;
@@ -17004,11 +17019,197 @@ async function gitLogIsCurrent(client, repo, head) {
17004
17019
  // src/core/survey.ts
17005
17020
  import { execFileSync as execFileSync3, spawn as realSpawn5 } from "child_process";
17006
17021
  import { createHash as createHash3 } from "crypto";
17007
- import { existsSync as existsSync3 } from "fs";
17022
+ import { existsSync as existsSync3, readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
17008
17023
  import { homedir as homedir5, tmpdir as tmpdir2 } from "os";
17009
17024
  import { dirname as dirname7, join as join11 } from "path";
17010
17025
  import { fileURLToPath as fileURLToPath4 } from "url";
17011
17026
 
17027
+ // node_modules/smol-toml/dist/stringify.js
17028
+ var BARE_KEY = /^[a-z0-9-_]+$/i;
17029
+ var HAS_WELLFORMED = !!"".isWellFormed;
17030
+ function extendedTypeOf(obj) {
17031
+ let type = typeof obj;
17032
+ if (type === "object") {
17033
+ if (Array.isArray(obj))
17034
+ return "array";
17035
+ if (typeof obj.getUTCDate === "function" && obj instanceof Date)
17036
+ return "date";
17037
+ if (globalThis.Temporal) {
17038
+ if (obj.until) {
17039
+ if (obj instanceof Temporal.ZonedDateTime)
17040
+ return "temporal/tz+uc";
17041
+ if (obj instanceof Temporal.PlainDateTime || obj instanceof Temporal.PlainDate)
17042
+ return "temporal/uc";
17043
+ if (obj instanceof Temporal.PlainTime || obj instanceof Temporal.Instant)
17044
+ return "temporal";
17045
+ if (obj instanceof Temporal.PlainYearMonth)
17046
+ return "temporal/x";
17047
+ } else if (obj.toPlainDate && obj instanceof Temporal.PlainMonthDay || obj.negated && obj instanceof Temporal.Duration) {
17048
+ return "temporal/x";
17049
+ }
17050
+ }
17051
+ }
17052
+ return type;
17053
+ }
17054
+ function isArrayOfTables(obj) {
17055
+ for (let i = 0; i < obj.length; i++) {
17056
+ if (extendedTypeOf(obj[i]) !== "object")
17057
+ return false;
17058
+ }
17059
+ return obj.length != 0;
17060
+ }
17061
+ function formatWellFormedStringUnchecked(s) {
17062
+ return JSON.stringify(s).replaceAll("\x7F", "\\u007f");
17063
+ }
17064
+ function formatString(s) {
17065
+ return formatWellFormedStringUnchecked(HAS_WELLFORMED ? s.toWellFormed() : s);
17066
+ }
17067
+ function formatKey(s) {
17068
+ if (BARE_KEY.test(s))
17069
+ return s;
17070
+ if (HAS_WELLFORMED && !s.isWellFormed())
17071
+ throw new RangeError("key contains illegal lone surrogates");
17072
+ return formatWellFormedStringUnchecked(s);
17073
+ }
17074
+ function stringifyValue(val, type, depth, numberAsFloat, strictTemporal) {
17075
+ if (depth === 0) {
17076
+ throw new Error("Could not stringify the object: maximum object depth exceeded");
17077
+ }
17078
+ switch (type) {
17079
+ // @ts-expect-error -- intentional fallthrough case
17080
+ case "number":
17081
+ if (isNaN(val))
17082
+ return "nan";
17083
+ if (val === Infinity)
17084
+ return "inf";
17085
+ if (val === -Infinity)
17086
+ return "-inf";
17087
+ if (Number.isInteger(val) && (numberAsFloat || !Number.isSafeInteger(val)))
17088
+ return val.toFixed(1);
17089
+ case "bigint":
17090
+ case "boolean":
17091
+ case "temporal":
17092
+ return val.toString();
17093
+ case "string":
17094
+ return formatString(val);
17095
+ case "date":
17096
+ if (isNaN(val.getTime()))
17097
+ throw new TypeError("cannot serialize invalid date");
17098
+ return val.toISOString();
17099
+ case "object":
17100
+ return stringifyInlineTable(val, depth, numberAsFloat, strictTemporal);
17101
+ case "array":
17102
+ return stringifyArray(val, depth, numberAsFloat, strictTemporal);
17103
+ // @ts-expect-error -- intentional fallthrough case
17104
+ case "temporal/tz+uc":
17105
+ if (strictTemporal) {
17106
+ let tz = val.timeZoneId;
17107
+ let tzc = tz.charCodeAt(0);
17108
+ if (
17109
+ // Classic offset
17110
+ tzc !== 43 && tzc !== 45 && // Fast pre-check pass; see below for the actually accepted values
17111
+ (tzc !== 85 && tzc !== 71 && tzc !== 90 && tzc !== 69 || // UTC and its aliases; Temporal implementations don't all canonicalise unfortunately
17112
+ tz !== "UTC" && tz !== "UCT" && tz !== "Universal" && tz !== "Zulu" && // GMT is a TZ but it's for all intents and purposes equivalent to UTC. Safe to downgrade.
17113
+ !tz.startsWith("GMT") && tz !== "Greenwich" && // Etc/* are all safe to downgrade to offset (either UTC, GMT, or offset)
17114
+ !tz.startsWith("Etc/"))
17115
+ ) {
17116
+ throw new TypeError("Temporal objects with an IANA timezone are not allowed in Temporal strict mode");
17117
+ }
17118
+ }
17119
+ case "temporal/uc":
17120
+ if (strictTemporal && val.calendarId !== "iso8601")
17121
+ throw new TypeError("Temporal objects with a non-default calendar are not allowed in Temporal strict mode");
17122
+ return val.toString({
17123
+ calendarName: "never",
17124
+ timeZoneName: "never"
17125
+ });
17126
+ case "temporal/x":
17127
+ throw new TypeError("Unsupported " + val[Symbol.toStringTag]);
17128
+ }
17129
+ }
17130
+ function stringifyInlineTable(obj, depth, numberAsFloat, strictTemporal) {
17131
+ let keys = Object.keys(obj);
17132
+ if (keys.length === 0)
17133
+ return "{}";
17134
+ let res = "{ ";
17135
+ for (let i = 0; i < keys.length; i++) {
17136
+ let k = keys[i];
17137
+ if (i)
17138
+ res += ", ";
17139
+ res += formatKey(k) + " = " + stringifyValue(obj[k], extendedTypeOf(obj[k]), depth - 1, numberAsFloat, strictTemporal);
17140
+ }
17141
+ return res + " }";
17142
+ }
17143
+ function stringifyArray(array3, depth, numberAsFloat, strictTemporal) {
17144
+ if (array3.length === 0)
17145
+ return "[]";
17146
+ let res = "[ ";
17147
+ for (let i = 0; i < array3.length; i++) {
17148
+ if (i)
17149
+ res += ", ";
17150
+ if (array3[i] === null || array3[i] === void 0) {
17151
+ throw new TypeError("arrays cannot contain null or undefined values");
17152
+ }
17153
+ res += stringifyValue(array3[i], extendedTypeOf(array3[i]), depth - 1, numberAsFloat, strictTemporal);
17154
+ }
17155
+ return res + " ]";
17156
+ }
17157
+ function stringifyArrayTable(array3, key, depth, numberAsFloat, strictTemporal) {
17158
+ if (depth === 0) {
17159
+ throw new Error("Could not stringify the object: maximum object depth exceeded");
17160
+ }
17161
+ let res = "";
17162
+ for (let i = 0; i < array3.length; i++) {
17163
+ res += `${res && "\n"}[[${key}]]
17164
+ `;
17165
+ res += stringifyTable(0, array3[i], key, depth, numberAsFloat, strictTemporal);
17166
+ }
17167
+ return res;
17168
+ }
17169
+ function stringifyTable(tableKey, obj, prefix, depth, numberAsFloat, strictTemporal) {
17170
+ if (depth === 0) {
17171
+ throw new Error("Could not stringify the object: maximum object depth exceeded");
17172
+ }
17173
+ let preamble = "";
17174
+ let tables = "";
17175
+ let keys = Object.keys(obj);
17176
+ for (let i = 0; i < keys.length; i++) {
17177
+ let k = keys[i];
17178
+ if (obj[k] !== null && obj[k] !== void 0) {
17179
+ let type = extendedTypeOf(obj[k]);
17180
+ if (type === "symbol" || type === "function") {
17181
+ throw new TypeError(`cannot serialize values of type '${type}'`);
17182
+ }
17183
+ let key = formatKey(k);
17184
+ if (type === "array" && isArrayOfTables(obj[k])) {
17185
+ tables += (tables && "\n") + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat, strictTemporal);
17186
+ } else if (type === "object") {
17187
+ let tblKey = prefix ? `${prefix}.${key}` : key;
17188
+ tables += (tables && "\n") + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat, strictTemporal);
17189
+ } else {
17190
+ preamble += key;
17191
+ preamble += " = ";
17192
+ preamble += stringifyValue(obj[k], type, depth, numberAsFloat, strictTemporal);
17193
+ preamble += "\n";
17194
+ }
17195
+ }
17196
+ }
17197
+ if (tableKey && (preamble || !tables))
17198
+ preamble = preamble ? `[${tableKey}]
17199
+ ${preamble}` : `[${tableKey}]`;
17200
+ return preamble && tables ? `${preamble}
17201
+ ${tables}` : preamble || tables;
17202
+ }
17203
+ function stringify(obj, { maxDepth = 1e3, numbersAsFloat = false, strictTemporal = false } = {}) {
17204
+ if (extendedTypeOf(obj) !== "object") {
17205
+ throw new TypeError("stringify can only be called with an object");
17206
+ }
17207
+ let str = stringifyTable(0, obj, "", maxDepth, numbersAsFloat, strictTemporal);
17208
+ if (str[str.length - 1] !== "\n")
17209
+ return str + "\n";
17210
+ return str;
17211
+ }
17212
+
17012
17213
  // src/core/survey-lease.ts
17013
17214
  import { spawn as realSpawn4 } from "child_process";
17014
17215
  import { randomUUID } from "crypto";
@@ -17019,7 +17220,7 @@ import {
17019
17220
  renameSync as renameSync2,
17020
17221
  rmdirSync,
17021
17222
  rmSync,
17022
- statSync as statSync2,
17223
+ statSync as statSync3,
17023
17224
  unlinkSync as unlinkSync2,
17024
17225
  utimesSync,
17025
17226
  writeFileSync as writeFileSync2
@@ -17056,7 +17257,7 @@ function reclaimIfStale(directory, staleMs) {
17056
17257
  return true;
17057
17258
  }
17058
17259
  if (owners.length !== 1) return false;
17059
- const age = Date.now() - statSync2(join10(directory, owners[0])).mtimeMs;
17260
+ const age = Date.now() - statSync3(join10(directory, owners[0])).mtimeMs;
17060
17261
  if (Math.abs(age) <= staleMs) return false;
17061
17262
  releaseLease({ directory, owner: owners[0] });
17062
17263
  return true;
@@ -17130,7 +17331,7 @@ function opencodeCanDefineSurveyAgent(bin) {
17130
17331
  windowsHide: true,
17131
17332
  stdio: ["ignore", "pipe", "ignore"]
17132
17333
  });
17133
- return Number(/(\d+)\./.exec(out)?.[1] ?? 0) >= 1;
17334
+ return Number(/(\d+)\./.exec(out)?.[1] ?? 0) === 1;
17134
17335
  } catch {
17135
17336
  return false;
17136
17337
  }
@@ -17145,6 +17346,7 @@ var SURVEY_DISALLOWED_TOOLS = [
17145
17346
  "WebSearch",
17146
17347
  "Task"
17147
17348
  ];
17349
+ var tomlValue = (value) => stringify({ v: value }).slice("v = ".length).trim();
17148
17350
  function buildSurveyPlan(harness, bin, repoDir, opts) {
17149
17351
  const env = {
17150
17352
  ...process.env,
@@ -17203,9 +17405,9 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
17203
17405
  "-c",
17204
17406
  `mcp_servers.hindsight.command="node"`,
17205
17407
  "-c",
17206
- `mcp_servers.hindsight.args=["${opts.mcpServerPath}"]`,
17408
+ `mcp_servers.hindsight.args=${tomlValue([opts.mcpServerPath])}`,
17207
17409
  "-c",
17208
- `mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD="${repoDir}"`,
17410
+ `mcp_servers.hindsight.env.HINDSIGHT_MCP_PROJECT_CWD=${tomlValue(repoDir)}`,
17209
17411
  "-c",
17210
17412
  `mcp_servers.hindsight.env.HINDSIGHT_MCP_HARNESS="codex"`,
17211
17413
  SURVEY_PROMPT
@@ -17229,10 +17431,19 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
17229
17431
  }
17230
17432
  }
17231
17433
  }
17434
+ var SURVEY_MAX_ATTEMPTS = 3;
17435
+ function surveyAttempts(file3, sha) {
17436
+ try {
17437
+ const state = JSON.parse(readFileSync5(file3, "utf8"));
17438
+ return state.sha === sha && typeof state.attempts === "number" ? state.attempts : 0;
17439
+ } catch {
17440
+ return 0;
17441
+ }
17442
+ }
17232
17443
  async function startCodebaseSurvey(repoDir, opts = {}) {
17233
17444
  try {
17234
17445
  const spawnFn = opts.spawn ?? realSpawn5;
17235
- const exists = opts.exists ?? binOnPath;
17446
+ const resolveBin = opts.resolveBin ?? ((bin) => binOnPath(bin, { exts: [".exe"] }));
17236
17447
  const mcpServerPath = opts.mcpServerPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
17237
17448
  const preferred = opts.harness ?? "claude-code";
17238
17449
  const order = [
@@ -17246,10 +17457,16 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
17246
17457
  for (const harness of order) {
17247
17458
  if (seen.has(harness)) continue;
17248
17459
  seen.add(harness);
17249
- const bin = resolveAgentBin(harness, opts.claudeBin);
17250
- if (!exists(bin)) continue;
17251
- if (harness === "opencode" && !(opts.opencodeDefinesAgent ?? opencodeCanDefineSurveyAgent)(bin))
17460
+ const name = resolveAgentBin(harness, opts.claudeBin);
17461
+ const bin = resolveBin(name);
17462
+ if (!bin) {
17463
+ log.info("survey", `${harness}: ${name} not found, trying the next agent`);
17252
17464
  continue;
17465
+ }
17466
+ if (harness === "opencode" && !(opts.opencodeDefinesAgent ?? opencodeCanDefineSurveyAgent)(bin)) {
17467
+ log.info("survey", `${harness}: ${bin} cannot define the survey agent, trying the next`);
17468
+ continue;
17469
+ }
17253
17470
  const plan = buildSurveyPlan(harness, bin, repoDir, {
17254
17471
  model: opts.model,
17255
17472
  budgetUsd: opts.budgetUsd,
@@ -17258,12 +17475,19 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
17258
17475
  const { cfg, bankId } = resolveHostConfig(harness, repoDir);
17259
17476
  if (cfg.disabled) return false;
17260
17477
  const key = createHash3("sha256").update(JSON.stringify([cfg.apiUrl.replace(/\/+$/, ""), cfg.apiToken ?? "", bankId])).digest("hex");
17261
- const lease = acquireLease(
17262
- opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys"),
17263
- key,
17264
- opts.lease?.staleMs ?? LEASE_STALE_MS
17265
- );
17478
+ const leaseDir = opts.lease?.dir ?? join11(tmpdir2(), "hindsight-coding-agent", "surveys");
17479
+ const lease = acquireLease(leaseDir, key, opts.lease?.staleMs ?? LEASE_STALE_MS);
17266
17480
  if (!lease) return false;
17481
+ const attemptsFile = join11(
17482
+ leaseDir,
17483
+ `attempts-${createHash3("sha256").update(JSON.stringify([key, repoDir])).digest("hex")}.json`
17484
+ );
17485
+ const attempts = opts.sha ? surveyAttempts(attemptsFile, opts.sha) : 0;
17486
+ if (attempts >= SURVEY_MAX_ATTEMPTS) {
17487
+ log.info("survey", `${attempts} surveys already launched at ${opts.sha}, skipping`);
17488
+ releaseLease(lease);
17489
+ return false;
17490
+ }
17267
17491
  const spec = {
17268
17492
  lease,
17269
17493
  bin: plan.bin,
@@ -17271,7 +17495,7 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
17271
17495
  ...opts.lease?.heartbeatMs ? { heartbeatMs: opts.lease.heartbeatMs } : {}
17272
17496
  };
17273
17497
  const supervisorPath = opts.supervisorPath ?? join11(dirname7(fileURLToPath4(import.meta.url)), "survey-supervisor.js");
17274
- return await new Promise((resolve3) => {
17498
+ return await new Promise((resolve4) => {
17275
17499
  try {
17276
17500
  const child = spawnFn("node", [supervisorPath], {
17277
17501
  cwd: repoDir,
@@ -17281,19 +17505,31 @@ async function startCodebaseSurvey(repoDir, opts = {}) {
17281
17505
  env: { ...plan.env, [SURVEY_SPEC_ENV]: JSON.stringify(spec) }
17282
17506
  });
17283
17507
  let spawned = false;
17284
- child.on("error", () => {
17508
+ child.on("error", (e) => {
17285
17509
  if (spawned) return;
17510
+ log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
17286
17511
  releaseLease(lease);
17287
- resolve3(false);
17512
+ resolve4(false);
17288
17513
  });
17289
17514
  child.once("spawn", () => {
17290
17515
  spawned = true;
17291
17516
  child.unref();
17292
- resolve3(true);
17517
+ if (opts.sha) {
17518
+ try {
17519
+ writeFileSync3(
17520
+ attemptsFile,
17521
+ JSON.stringify({ sha: opts.sha, attempts: attempts + 1 }),
17522
+ { mode: 384 }
17523
+ );
17524
+ } catch {
17525
+ }
17526
+ }
17527
+ resolve4(true);
17293
17528
  });
17294
- } catch {
17529
+ } catch (e) {
17530
+ log.warn("survey", `survey supervisor failed to launch: ${describeError(e)}`);
17295
17531
  releaseLease(lease);
17296
- resolve3(false);
17532
+ resolve4(false);
17297
17533
  }
17298
17534
  });
17299
17535
  }
@@ -17571,6 +17807,18 @@ function pendingReplayable(cursor, now) {
17571
17807
  if (pending.some((p) => now - p.at > PENDING_MAX_AGE_MS)) return false;
17572
17808
  return pending.reduce((n, p) => n + p.content.length, 0) <= PENDING_MAX_BYTES;
17573
17809
  }
17810
+ function advanceSegments(cursor, bank) {
17811
+ if (!cursor || cursor.bank === bank) return cursor?.segments;
17812
+ return [...cursor.segments ?? [{ bank: cursor.bank, from: 0 }], { bank, from: cursor.turns }];
17813
+ }
17814
+ function bankTurns(turns, segments, bank) {
17815
+ if (!segments) return turns;
17816
+ return turns.filter((_, i) => {
17817
+ let owner;
17818
+ for (const s of segments) if (s.from <= i) owner = s.bank;
17819
+ return owner === bank;
17820
+ });
17821
+ }
17574
17822
  var MAX_CURSOR_OPS = 8;
17575
17823
  function fingerprintTurns(turns, count) {
17576
17824
  const h = createHash5("sha1").update(String(count));
@@ -17581,7 +17829,8 @@ function planRetain(turns, cursor, opts) {
17581
17829
  if (!turns.length) return { mode: "skip" };
17582
17830
  if (!opts.appendSupported || !cursor || cursor.dirty) return { mode: "replace" };
17583
17831
  if (!pendingReplayable(cursor, opts.now ?? Date.now())) return { mode: "replace" };
17584
- if (cursor.bank !== opts.bank) return { mode: "replace" };
17832
+ if (cursor.bank !== opts.bank && !cursor.segments?.some((s) => s.bank === opts.bank))
17833
+ return { mode: "replace" };
17585
17834
  const seen = cursor.paths ?? [];
17586
17835
  const newFile = Boolean(opts.path && seen.length && !seen.includes(opts.path));
17587
17836
  const continues = cursor.turns <= turns.length && fingerprintTurns(turns, cursor.turns) === cursor.fingerprint;
@@ -17702,8 +17951,17 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
17702
17951
  let cursor = cursors?.read(sessionId);
17703
17952
  const probed = Boolean(cursors) && cursor?.appendSupported !== true;
17704
17953
  const appendSupported = Boolean(cursors) && (cursor?.appendSupported === true || await supportsAppend(client));
17954
+ const moved = Boolean(cursor && cursor.bank !== client.bank);
17955
+ if (moved)
17956
+ log.warn(harness ?? "", "session moved to another bank mid-session", {
17957
+ session: sessionId,
17958
+ from: cursor?.bank,
17959
+ to: client.bank,
17960
+ atTurn: cursor?.turns
17961
+ });
17962
+ const segments = advanceSegments(cursor, client.bank);
17705
17963
  let ops = [];
17706
- if (appendSupported && cursor?.ops?.length && !cursor.dirty)
17964
+ if (appendSupported && cursor?.ops?.length && !cursor.dirty && !moved)
17707
17965
  ({ cursor, ops } = await settleOps(client, cursor));
17708
17966
  const plan = planRetain(turns, cursor, {
17709
17967
  appendSupported,
@@ -17712,7 +17970,7 @@ async function writeSession(client, sessionId, turns, startTs, harness, stamp, c
17712
17970
  });
17713
17971
  if (probed) diag(harness ?? "", "retain_mode", { mode: plan.mode, appendSupported });
17714
17972
  const paths = plan.mode === "replace" ? transcriptPath ? [transcriptPath] : void 0 : advancePaths(cursor?.paths, transcriptPath);
17715
- const outbox = plan.mode === "replace" ? [] : cursor?.pending ?? [];
17973
+ const outbox = plan.mode === "replace" || moved ? [] : cursor?.pending ?? [];
17716
17974
  if (plan.mode === "skip" && !outbox.length) return;
17717
17975
  const opId = (mode, content) => uuidV5(`${client.bank}
17718
17976
  ${refId}
@@ -17754,6 +18012,7 @@ ${content}`);
17754
18012
  fingerprint: fingerprintTurns(turns, turns.length),
17755
18013
  bank: client.bank,
17756
18014
  ...paths ? { paths } : {},
18015
+ ...segments ? { segments } : {},
17757
18016
  ...appendSupported ? { appendSupported: true } : {}
17758
18017
  };
17759
18018
  const accepted = (id) => {
@@ -17766,9 +18025,14 @@ ${content}`);
17766
18025
  return now?.turns === next.turns && now?.fingerprint === next.fingerprint;
17767
18026
  };
17768
18027
  if (plan.mode === "replace") {
17769
- const content = renderSessionJsonl(refId, turns, startTs);
18028
+ const share = bankTurns(turns, segments, client.bank);
18029
+ if (!share.length) return;
18030
+ const content = renderSessionJsonl(refId, share, startTs);
18031
+ const base = cursor ? `${cursor.turns}
18032
+ ${cursor.fingerprint}` : "";
17770
18033
  cursors?.write(sessionId, { ...next, dirty: true });
17771
- const operationId = opId("replace", content);
18034
+ const operationId = opId("replace", `${base}
18035
+ ${content}`);
17772
18036
  await submitWithRetry(() => submit(content, operationId, false), stillOurs, retryUntil);
17773
18037
  ops = [];
17774
18038
  cursors?.write(sessionId, accepted(operationId));
@@ -17795,7 +18059,7 @@ ${content}`);
17795
18059
  }
17796
18060
 
17797
18061
  // src/core/usage.ts
17798
- import { readFileSync as readFileSync5 } from "fs";
18062
+ import { readFileSync as readFileSync6 } from "fs";
17799
18063
  import { join as join13 } from "path";
17800
18064
  function usageFilePath() {
17801
18065
  return process.env.HINDSIGHT_USAGE_FILE || join13(logsDir(), "usage.jsonl");
@@ -17878,12 +18142,12 @@ function buildRetainStamp(cfg, ctx) {
17878
18142
  const base = resolversFor(ctx);
17879
18143
  const cache = /* @__PURE__ */ new Map();
17880
18144
  const resolvers = Object.fromEntries(
17881
- Object.entries(base).map(([name, resolve3]) => [
18145
+ Object.entries(base).map(([name, resolve4]) => [
17882
18146
  name,
17883
18147
  () => {
17884
18148
  const hit = cache.get(name);
17885
18149
  if (hit !== void 0) return hit;
17886
- const value = resolve3();
18150
+ const value = resolve4();
17887
18151
  cache.set(name, value);
17888
18152
  return value;
17889
18153
  }
@@ -17903,7 +18167,7 @@ function buildRetainStamp(cfg, ctx) {
17903
18167
  }
17904
18168
 
17905
18169
  // src/core/skill-sync.ts
17906
- import { cpSync, existsSync as existsSync6, readFileSync as readFileSync6 } from "fs";
18170
+ import { cpSync, existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
17907
18171
  import { homedir as homedir7 } from "os";
17908
18172
  import { dirname as dirname8, join as join15 } from "path";
17909
18173
  import { fileURLToPath as fileURLToPath5 } from "url";
@@ -17978,7 +18242,7 @@ function syncCompanionSkill(harness, opts = {}) {
17978
18242
  const dstMd = join15(dst, "SKILL.md");
17979
18243
  const installed = existsSync6(dstMd);
17980
18244
  if (!installed && !opts.install) return;
17981
- if (!installed || readFileSync6(srcMd, "utf8") !== readFileSync6(dstMd, "utf8")) {
18245
+ if (!installed || readFileSync7(srcMd, "utf8") !== readFileSync7(dstMd, "utf8")) {
17982
18246
  cpSync(src, dst, { recursive: true });
17983
18247
  }
17984
18248
  } catch {
@@ -18000,9 +18264,9 @@ function brandWord() {
18000
18264
  }
18001
18265
 
18002
18266
  // src/core/legacy.ts
18003
- import { existsSync as existsSync7, readFileSync as readFileSync7 } from "fs";
18267
+ import { existsSync as existsSync7, readFileSync as readFileSync8 } from "fs";
18004
18268
  import { homedir as homedir8 } from "os";
18005
- import { join as join16, relative, isAbsolute as isAbsolute2 } from "path";
18269
+ import { join as join16, relative, isAbsolute as isAbsolute3 } from "path";
18006
18270
  var LEGACY_CLAUDE_PLUGIN = "hindsight-memory";
18007
18271
  function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")) {
18008
18272
  const registry3 = readJson(join16(claudeDir, "plugins", "installed_plugins.json"));
@@ -18017,7 +18281,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
18017
18281
  if (!i || typeof i !== "object") return false;
18018
18282
  if (typeof i.projectPath !== "string") return true;
18019
18283
  const rel = relative(i.projectPath, cwd);
18020
- return rel === "" || !rel.startsWith("..") && !isAbsolute2(rel);
18284
+ return rel === "" || !rel.startsWith("..") && !isAbsolute3(rel);
18021
18285
  });
18022
18286
  if (active) return key;
18023
18287
  }
@@ -18025,7 +18289,7 @@ function detectLegacyClaudePlugin(cwd, claudeDir = join16(homedir8(), ".claude")
18025
18289
  }
18026
18290
  function readJson(path) {
18027
18291
  try {
18028
- const parsed = JSON.parse(readFileSync7(path, "utf8"));
18292
+ const parsed = JSON.parse(readFileSync8(path, "utf8"));
18029
18293
  return parsed && typeof parsed === "object" ? parsed : void 0;
18030
18294
  } catch {
18031
18295
  return void 0;
@@ -18037,7 +18301,7 @@ function legacyClaudePluginWarning(key) {
18037
18301
  }
18038
18302
 
18039
18303
  // src/core/session-cache.ts
18040
- import { mkdirSync as mkdirSync4, readFileSync as readFileSync8, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "fs";
18304
+ import { mkdirSync as mkdirSync4, readFileSync as readFileSync9, renameSync as renameSync3, rmSync as rmSync2, writeFileSync as writeFileSync4 } from "fs";
18041
18305
  import { tmpdir as tmpdir3 } from "os";
18042
18306
  import { dirname as dirname9, join as join17 } from "path";
18043
18307
  function sessionCacheFile(harness, sessionId) {
@@ -18045,7 +18309,7 @@ function sessionCacheFile(harness, sessionId) {
18045
18309
  }
18046
18310
  function readSessionCache(cacheFile) {
18047
18311
  try {
18048
- return JSON.parse(readFileSync8(cacheFile, "utf8"));
18312
+ return JSON.parse(readFileSync9(cacheFile, "utf8"));
18049
18313
  } catch {
18050
18314
  return {};
18051
18315
  }
@@ -18054,7 +18318,7 @@ function writeFileAtomic(path, body) {
18054
18318
  mkdirSync4(dirname9(path), { recursive: true });
18055
18319
  const tmp = `${path}.${process.pid}.tmp`;
18056
18320
  try {
18057
- writeFileSync3(tmp, body);
18321
+ writeFileSync4(tmp, body);
18058
18322
  renameSync3(tmp, path);
18059
18323
  } catch (e) {
18060
18324
  try {
@@ -18164,12 +18428,13 @@ async function buildSessionStartContext(args) {
18164
18428
  startSeed(cwd, { limit: cfg.seedLimit, harness });
18165
18429
  if (cold) {
18166
18430
  if (cfg.codebaseSurvey !== false) {
18431
+ const sha = resolveHeadSha(cwd);
18167
18432
  const started = await startSurvey(cwd, {
18168
18433
  harness,
18169
18434
  model: cfg.surveyModel,
18170
- budgetUsd: cfg.surveyBudgetUsd
18435
+ budgetUsd: cfg.surveyBudgetUsd,
18436
+ sha: sha ?? void 0
18171
18437
  });
18172
- const sha = resolveHeadSha(cwd);
18173
18438
  if (started && sha) recordSurveyBaseline(sha);
18174
18439
  }
18175
18440
  diag(harness, "seed_started", { bank: bankId });
@@ -18190,7 +18455,8 @@ async function buildSessionStartContext(args) {
18190
18455
  const started = await startSurvey(cwd, {
18191
18456
  harness,
18192
18457
  model: cfg.surveyModel,
18193
- budgetUsd: cfg.surveyBudgetUsd
18458
+ budgetUsd: cfg.surveyBudgetUsd,
18459
+ sha
18194
18460
  });
18195
18461
  if (started) {
18196
18462
  recordSurveyBaseline(sha);
@@ -18292,7 +18558,7 @@ If you VERIFY this memory is wrong or outdated (the code or facts contradict it)
18292
18558
  }
18293
18559
 
18294
18560
  // src/core/turn-journal.ts
18295
- import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync9, statSync as statSync3 } from "fs";
18561
+ import { appendFileSync as appendFileSync2, mkdirSync as mkdirSync5, readFileSync as readFileSync10, statSync as statSync4 } from "fs";
18296
18562
  import { tmpdir as tmpdir4 } from "os";
18297
18563
  import { dirname as dirname10, join as join18 } from "path";
18298
18564
 
@@ -18543,8 +18809,6 @@ var RuntimeCore = class {
18543
18809
  fetchTranscript;
18544
18810
  /** Write-backs started and not yet settled — what `flush` waits for. */
18545
18811
  inFlight = /* @__PURE__ */ new Set();
18546
- lastInjection = "";
18547
- // most recent turn's injection block, keyed by nothing (see getInjection)
18548
18812
  deferInitialReflect = false;
18549
18813
  /** Host-notice channel (opencode/Kilo: client.tui.showToast via the adapter). Optional, fail-open. */
18550
18814
  notify;
@@ -18616,7 +18880,11 @@ var RuntimeCore = class {
18616
18880
  */
18617
18881
  async onPrompt(sessionId, prompt) {
18618
18882
  if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
18619
- if (!sessionId || !prompt.trim()) return;
18883
+ if (!sessionId) return;
18884
+ if (!prompt.trim()) {
18885
+ this.injection.delete(sessionId);
18886
+ return;
18887
+ }
18620
18888
  const turns = (this.turnCount.get(sessionId) ?? 0) + 1;
18621
18889
  this.turnCount.set(sessionId, turns);
18622
18890
  const cacheFile = sessionCacheFile(this.harness, sessionId);
@@ -18648,18 +18916,21 @@ var RuntimeCore = class {
18648
18916
  }
18649
18917
  const block = blocks.filter(Boolean).join("\n\n");
18650
18918
  this.injection.set(sessionId, block);
18651
- this.lastInjection = block;
18652
18919
  }
18653
18920
  /**
18654
- * The system-prompt text to inject this turn (built by the preceding onPrompt), or undefined.
18655
- * opencode's `experimental.chat.system.transform` hook fires with NO sessionId (input is just
18656
- * `{model}`), so a session-keyed lookup returns nothing there — fall back to the most recent
18657
- * turn's block (`lastInjection`). The completion's system.transform fires right after that
18658
- * session's `chat.message`/onPrompt, so `lastInjection` is this turn's block.
18921
+ * The text to inject into this turn's user message (built by the preceding onPrompt), or
18922
+ * undefined.
18923
+ *
18924
+ * It goes into the USER turn on every host, never the system prompt (#5914). The block changes
18925
+ * from turn to turn — the recall runs once, the roster refresh on a cadence — so a system prompt
18926
+ * carrying it differed between requests and broke the provider's prefix cache from that point
18927
+ * on. Persisted in the turn it belongs to, it leaves the system prompt and the earlier history
18928
+ * byte-identical. That used to need a fallback to the most recent block for opencode's
18929
+ * `experimental.chat.system.transform`, which fired with no session id; nothing reads it that
18930
+ * way any more.
18659
18931
  */
18660
18932
  getInjection(sessionId) {
18661
- const keyed = sessionId ? this.injection.get(sessionId) : void 0;
18662
- return keyed ?? this.lastInjection ?? void 0;
18933
+ return this.injection.get(sessionId) || void 0;
18663
18934
  }
18664
18935
  /**
18665
18936
  * Full normalized transcript (rich: user/assistant text + tool calls/outputs): upsert every turn
@@ -18988,7 +19259,7 @@ __export(external_exports2, {
18988
19259
  object: () => object2,
18989
19260
  optional: () => optional2,
18990
19261
  overwrite: () => _overwrite2,
18991
- parse: () => parse4,
19262
+ parse: () => parse5,
18992
19263
  parseAsync: () => parseAsync4,
18993
19264
  partialRecord: () => partialRecord2,
18994
19265
  pipe: () => pipe2,
@@ -19292,7 +19563,7 @@ __export(core_exports4, {
19292
19563
  isValidBase64URL: () => isValidBase64URL2,
19293
19564
  isValidJWT: () => isValidJWT2,
19294
19565
  locales: () => locales_exports2,
19295
- parse: () => parse3,
19566
+ parse: () => parse4,
19296
19567
  parseAsync: () => parseAsync3,
19297
19568
  prettifyError: () => prettifyError2,
19298
19569
  regexes: () => regexes_exports2,
@@ -20166,7 +20437,7 @@ var _parse2 = (_Err) => (schema, value, _ctx, _params) => {
20166
20437
  }
20167
20438
  return result.value;
20168
20439
  };
20169
- var parse3 = /* @__PURE__ */ _parse2($ZodRealError2);
20440
+ var parse4 = /* @__PURE__ */ _parse2($ZodRealError2);
20170
20441
  var _parseAsync2 = (_Err) => async (schema, value, _ctx, params) => {
20171
20442
  const ctx = _ctx ? Object.assign(_ctx, { async: true }) : { async: true };
20172
20443
  let result = schema._zod.run({ value, issues: [] }, ctx);
@@ -22689,10 +22960,10 @@ var $ZodFunction2 = /* @__PURE__ */ $constructor2("$ZodFunction", (inst, def) =>
22689
22960
  throw new Error("implement() must be called with a function");
22690
22961
  }
22691
22962
  return function(...args) {
22692
- const parsedArgs = inst._def.input ? parse3(inst._def.input, args) : args;
22963
+ const parsedArgs = inst._def.input ? parse4(inst._def.input, args) : args;
22693
22964
  const result = Reflect.apply(func, this, parsedArgs);
22694
22965
  if (inst._def.output) {
22695
- return parse3(inst._def.output, result);
22966
+ return parse4(inst._def.output, result);
22696
22967
  }
22697
22968
  return result;
22698
22969
  };
@@ -30184,7 +30455,7 @@ var ZodRealError2 = $constructor2("ZodError", initializer4, {
30184
30455
  });
30185
30456
 
30186
30457
  // node_modules/@opencode-ai/plugin/node_modules/zod/v4/classic/parse.js
30187
- var parse4 = /* @__PURE__ */ _parse2(ZodRealError2);
30458
+ var parse5 = /* @__PURE__ */ _parse2(ZodRealError2);
30188
30459
  var parseAsync4 = /* @__PURE__ */ _parseAsync2(ZodRealError2);
30189
30460
  var safeParse4 = /* @__PURE__ */ _safeParse2(ZodRealError2);
30190
30461
  var safeParseAsync4 = /* @__PURE__ */ _safeParseAsync2(ZodRealError2);
@@ -30221,7 +30492,7 @@ var ZodType2 = /* @__PURE__ */ $constructor2("ZodType", (inst, def) => {
30221
30492
  reg.add(inst, meta3);
30222
30493
  return inst;
30223
30494
  });
30224
- inst.parse = (data, params) => parse4(inst, data, params, { callee: inst.parse });
30495
+ inst.parse = (data, params) => parse5(inst, data, params, { callee: inst.parse });
30225
30496
  inst.safeParse = (data, params) => safeParse4(inst, data, params);
30226
30497
  inst.parseAsync = async (data, params) => parseAsync4(inst, data, params, { callee: inst.parseAsync });
30227
30498
  inst.safeParseAsync = async (data, params) => safeParseAsync4(inst, data, params);
@@ -31239,12 +31510,12 @@ function tool(input) {
31239
31510
  tool.schema = external_exports2;
31240
31511
 
31241
31512
  // src/harness/registry.ts
31242
- import { readFileSync as readFileSync10 } from "fs";
31513
+ import { readFileSync as readFileSync11 } from "fs";
31243
31514
  var jsonChatReader = (harness) => ({
31244
31515
  describe: `${harness} sessions via a normalized JSON export (--conversations file: [{ id, turns:[{role,text,timestamp?}] }])`,
31245
31516
  async read(opts) {
31246
31517
  if (!opts.conversations) return [];
31247
- return JSON.parse(readFileSync10(opts.conversations, "utf8"));
31518
+ return JSON.parse(readFileSync11(opts.conversations, "utf8"));
31248
31519
  }
31249
31520
  });
31250
31521
 
@@ -31277,21 +31548,26 @@ function createRuntime(core) {
31277
31548
  return {
31278
31549
  ...surveyAgentHook,
31279
31550
  tool: tools,
31280
- // Each user turn: recall on the prompt; the injection it builds is pushed by system.transform.
31551
+ // Each user turn: recall on the prompt, then add this turn's injection (recalled memories +
31552
+ // attribution/user-feedback framing, plus the knowledge preamble on turn 1 and the roster
31553
+ // refresh on cadence) to the user message as a synthetic text part. The host saves the parts
31554
+ // this hook leaves behind, so the block stays in the turn it was made for and every later
31555
+ // request repeats it byte for byte. It used to be pushed into the system prompt through
31556
+ // `experimental.chat.system.transform`, which made the system prompt change between turns
31557
+ // and broke the provider's prefix cache (#5914).
31281
31558
  "chat.message": async (input, output) => {
31282
31559
  await core.onPrompt(input.sessionID, textOf(output.parts));
31283
- },
31284
- // Push this turn's injection (recalled memories + attribution/user-feedback framing, plus the
31285
- // knowledge preamble on turn 1 and the roster refresh on cadence) into the system prompt every
31286
- // turn. opencode fires this hook with NO sessionId (input is just `{model}`), so getInjection
31287
- // falls back to the most recent turn's block (see RuntimeCore.getInjection).
31288
- "experimental.chat.system.transform": async (input, output) => {
31289
31560
  const inj = core.getInjection(input.sessionID);
31290
- if (inj) output.system.push(inj);
31291
- diag(core.harness, inj ? "inject_ok" : "inject_empty", {
31292
- chars: inj?.length ?? 0,
31293
- hasSession: !!input.sessionID
31294
- });
31561
+ if (inj)
31562
+ output.parts.unshift({
31563
+ id: `prt-hindsight-${output.message.id}`,
31564
+ sessionID: input.sessionID,
31565
+ messageID: output.message.id,
31566
+ type: "text",
31567
+ text: inj,
31568
+ synthetic: true
31569
+ });
31570
+ diag(core.harness, inj ? "inject_ok" : "inject_empty", { chars: inj?.length ?? 0 });
31295
31571
  },
31296
31572
  // Write-back (on by default): normalize the live transcript to rich turns (text + tool calls +
31297
31573
  // their inline output) and hand it to core, which upserts every N user turns.
@@ -31374,3 +31650,42 @@ export {
31374
31650
  HindsightCodingAgentsPlugin,
31375
31651
  src_default as default
31376
31652
  };
31653
+ /*! Bundled license information:
31654
+
31655
+ smol-toml/dist/error.js:
31656
+ smol-toml/dist/primitive.js:
31657
+ smol-toml/dist/date.js:
31658
+ smol-toml/dist/extract.js:
31659
+ smol-toml/dist/util.js:
31660
+ smol-toml/dist/struct.js:
31661
+ smol-toml/dist/parse.js:
31662
+ smol-toml/dist/stringify.js:
31663
+ smol-toml/dist/index.js:
31664
+ (*!
31665
+ * Copyright (c) Squirrel Chat et al., All rights reserved.
31666
+ * SPDX-License-Identifier: BSD-3-Clause
31667
+ *
31668
+ * Redistribution and use in source and binary forms, with or without
31669
+ * modification, are permitted provided that the following conditions are met:
31670
+ *
31671
+ * 1. Redistributions of source code must retain the above copyright notice, this
31672
+ * list of conditions and the following disclaimer.
31673
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
31674
+ * this list of conditions and the following disclaimer in the
31675
+ * documentation and/or other materials provided with the distribution.
31676
+ * 3. Neither the name of the copyright holder nor the names of its contributors
31677
+ * may be used to endorse or promote products derived from this software without
31678
+ * specific prior written permission.
31679
+ *
31680
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
31681
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31682
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31683
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31684
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31685
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31686
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31687
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31688
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31689
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31690
+ *)
31691
+ */