@vectorize-io/hindsight-coding-agents 0.4.3 → 0.5.1
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 +202 -52
- package/dist/antigravity-hook.js +637 -199
- package/dist/antigravity-statusline.js +219 -84
- package/dist/antigravity-stop-hook.js +654 -205
- package/dist/claude-hook.js +637 -199
- package/dist/claude-sessionstart-hook.js +862 -236
- package/dist/claude-stop-hook.js +654 -205
- package/dist/cline.js +588 -234
- package/dist/codex-hook.js +637 -199
- package/dist/codex-sessionstart-hook.js +862 -236
- package/dist/codex-stop-hook.js +654 -205
- package/dist/copilot-hook.js +637 -199
- package/dist/copilot-sessionstart-hook.js +862 -236
- package/dist/copilot-stop-hook.js +654 -205
- package/dist/cursor-hook.js +637 -199
- package/dist/cursor-sessionstart-hook.js +862 -236
- package/dist/cursor-stop-hook.js +654 -205
- package/dist/daemon-start.js +62 -43
- package/dist/dcode-hook.js +2577 -0
- package/dist/dcode-sessionstart-hook.js +3193 -0
- package/dist/dcode-stop-hook.js +2807 -0
- package/dist/deepen.js +361 -204
- package/dist/devin-hook.js +637 -199
- package/dist/devin-sessionstart-hook.js +862 -236
- package/dist/devin-stop-hook.js +654 -205
- package/dist/dsh.js +591 -235
- package/dist/grok-hook.js +637 -199
- package/dist/grok-sessionstart-hook.js +862 -236
- package/dist/grok-stop-hook.js +654 -205
- package/dist/hindsight-seed.js +222 -83
- package/dist/index.js +588 -234
- package/dist/installer.js +2331 -299
- package/dist/kilo.js +588 -234
- package/dist/mcp-server.js +363 -169
- package/dist/opencode2.js +30091 -0
- package/dist/pi.js +17649 -0
- package/dist/prime-agent.js +624 -260
- package/dist/qwen-hook.js +2577 -0
- package/dist/qwen-sessionstart-hook.js +3193 -0
- package/dist/qwen-stop-hook.js +2807 -0
- package/dist/status.js +300 -136
- package/hooks/hooks.json +37 -0
- package/index.js +10 -0
- package/package.json +15 -8
- package/plugin.json +16 -0
- package/skill/SKILL.md +114 -43
package/dist/index.js
CHANGED
|
@@ -8,9 +8,9 @@ var __export = (target, all) => {
|
|
|
8
8
|
import { posix, win32 } from "path";
|
|
9
9
|
|
|
10
10
|
// src/core/config.ts
|
|
11
|
-
import { readFileSync } from "fs";
|
|
11
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
12
12
|
import { homedir as homedir2 } from "os";
|
|
13
|
-
import { join as
|
|
13
|
+
import { join as join6 } from "path";
|
|
14
14
|
|
|
15
15
|
// src/core/seed.ts
|
|
16
16
|
import { spawn as realSpawn } from "child_process";
|
|
@@ -46,64 +46,207 @@ function startBackgroundSeed(repoDir, opts = {}) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// src/core/bank.ts
|
|
49
|
-
import { execFileSync } from "child_process";
|
|
50
49
|
import { existsSync } from "fs";
|
|
51
50
|
import { homedir } from "os";
|
|
52
|
-
import { basename, dirname as
|
|
51
|
+
import { basename, dirname as dirname4, join as join4, normalize, sep } from "path";
|
|
52
|
+
|
|
53
|
+
// src/core/diag.ts
|
|
54
|
+
import { appendFileSync as appendFileSync2 } from "fs";
|
|
55
|
+
|
|
56
|
+
// src/core/log.ts
|
|
57
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
58
|
+
import { tmpdir } from "os";
|
|
59
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
60
|
+
var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
61
|
+
var current = ["debug", "info", "warn", "error"].find(
|
|
62
|
+
(l) => l === process.env.HINDSIGHT_LOG_LEVEL
|
|
63
|
+
) ?? "info";
|
|
64
|
+
function setLogLevel(level) {
|
|
65
|
+
if (!process.env.HINDSIGHT_LOG_LEVEL) current = level;
|
|
66
|
+
}
|
|
67
|
+
function logFilePath() {
|
|
68
|
+
return process.env.HINDSIGHT_LOG_FILE || join2(tmpdir(), "hindsight-coding-agent", "plugin.log");
|
|
69
|
+
}
|
|
70
|
+
function write(level, scope, msg, extra) {
|
|
71
|
+
if (WEIGHT[level] < WEIGHT[current]) return;
|
|
72
|
+
try {
|
|
73
|
+
const file3 = logFilePath();
|
|
74
|
+
mkdirSync(dirname2(file3), { recursive: true });
|
|
75
|
+
appendFileSync(
|
|
76
|
+
file3,
|
|
77
|
+
`${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
|
|
78
|
+
);
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
var log = {
|
|
83
|
+
debug: (scope, msg, extra) => write("debug", scope, msg, extra),
|
|
84
|
+
info: (scope, msg, extra) => write("info", scope, msg, extra),
|
|
85
|
+
warn: (scope, msg, extra) => write("warn", scope, msg, extra),
|
|
86
|
+
error: (scope, msg, extra) => write("error", scope, msg, extra)
|
|
87
|
+
};
|
|
88
|
+
function describeError(value, maxChars = 200) {
|
|
89
|
+
const parts = [];
|
|
90
|
+
const seen = /* @__PURE__ */ new Set();
|
|
91
|
+
let current2 = value;
|
|
92
|
+
while (current2 && !seen.has(current2)) {
|
|
93
|
+
seen.add(current2);
|
|
94
|
+
const error95 = current2;
|
|
95
|
+
const text = typeof error95.message === "string" ? error95.message : String(current2);
|
|
96
|
+
const withCode = error95.code ? `${text} (${String(error95.code)})` : text;
|
|
97
|
+
if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
|
|
98
|
+
current2 = error95.cause;
|
|
99
|
+
}
|
|
100
|
+
return (parts.join(": ") || String(value)).slice(0, maxChars);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/core/diag.ts
|
|
104
|
+
function diagFilePath() {
|
|
105
|
+
return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
|
|
106
|
+
}
|
|
107
|
+
function diag(harness, event, extra = {}) {
|
|
108
|
+
log.debug(harness, `diag:${event}`, extra);
|
|
109
|
+
try {
|
|
110
|
+
appendFileSync2(
|
|
111
|
+
diagFilePath(),
|
|
112
|
+
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
113
|
+
);
|
|
114
|
+
} catch {
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/core/git-layout.ts
|
|
119
|
+
import { lstatSync, readFileSync, realpathSync } from "fs";
|
|
120
|
+
import { dirname as dirname3, isAbsolute, join as join3, resolve } from "path";
|
|
121
|
+
var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
|
|
122
|
+
var ATTEMPTS = 3;
|
|
123
|
+
var BACKOFF_MS = 20;
|
|
124
|
+
function errorCode(error95) {
|
|
125
|
+
return error95?.code ?? "";
|
|
126
|
+
}
|
|
127
|
+
function sleepSync(ms) {
|
|
128
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
129
|
+
}
|
|
130
|
+
var TransientProbeError = class extends Error {
|
|
131
|
+
};
|
|
132
|
+
function entryKind(path) {
|
|
133
|
+
try {
|
|
134
|
+
const st = lstatSync(path);
|
|
135
|
+
return st.isDirectory() ? "dir" : "file";
|
|
136
|
+
} catch (error95) {
|
|
137
|
+
if (TRANSIENT.has(errorCode(error95))) throw new TransientProbeError(errorCode(error95));
|
|
138
|
+
return "none";
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function readTextOrNull(path) {
|
|
142
|
+
try {
|
|
143
|
+
return readFileSync(path, "utf8");
|
|
144
|
+
} catch (error95) {
|
|
145
|
+
if (TRANSIENT.has(errorCode(error95))) throw new TransientProbeError(errorCode(error95));
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
function gitDirFromPointer(text, holder) {
|
|
150
|
+
const match = /^\s*gitdir:\s*(.+?)\s*$/m.exec(text);
|
|
151
|
+
if (!match) return null;
|
|
152
|
+
const target = match[1];
|
|
153
|
+
return isAbsolute(target) ? target : resolve(holder, target);
|
|
154
|
+
}
|
|
155
|
+
function commonDirOf(gitDir) {
|
|
156
|
+
const pointer = entryKind(join3(gitDir, "commondir")) === "file" ? readTextOrNull(join3(gitDir, "commondir"))?.trim() : null;
|
|
157
|
+
if (!pointer) return gitDir;
|
|
158
|
+
return isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
|
|
159
|
+
}
|
|
160
|
+
function isBare(commonDir) {
|
|
161
|
+
const config3 = readTextOrNull(join3(commonDir, "config"));
|
|
162
|
+
return config3 !== null && /^\s*bare\s*=\s*true\s*$/im.test(config3);
|
|
163
|
+
}
|
|
164
|
+
function looksLikeBareRepository(directory) {
|
|
165
|
+
return entryKind(join3(directory, "HEAD")) === "file" && entryKind(join3(directory, "objects")) === "dir" && entryKind(join3(directory, "refs")) === "dir";
|
|
166
|
+
}
|
|
167
|
+
function canonical(path) {
|
|
168
|
+
try {
|
|
169
|
+
return realpathSync(path);
|
|
170
|
+
} catch {
|
|
171
|
+
return path;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function resolved(commonDir) {
|
|
175
|
+
if (entryKind(commonDir) !== "dir") return null;
|
|
176
|
+
const canonicalDir = canonical(commonDir);
|
|
177
|
+
return { status: "resolved", commonDir: canonicalDir, bare: isBare(canonicalDir) };
|
|
178
|
+
}
|
|
179
|
+
function probeOnce(directory) {
|
|
180
|
+
let current2 = resolve(directory);
|
|
181
|
+
for (; ; ) {
|
|
182
|
+
const dotGit = join3(current2, ".git");
|
|
183
|
+
const kind = entryKind(dotGit);
|
|
184
|
+
if (kind === "dir") {
|
|
185
|
+
const layout = resolved(commonDirOf(dotGit));
|
|
186
|
+
if (layout) return layout;
|
|
187
|
+
} else if (kind === "file") {
|
|
188
|
+
const text = readTextOrNull(dotGit);
|
|
189
|
+
const gitDir = text ? gitDirFromPointer(text, current2) : null;
|
|
190
|
+
const layout = gitDir ? resolved(commonDirOf(gitDir)) : null;
|
|
191
|
+
if (layout) return layout;
|
|
192
|
+
}
|
|
193
|
+
if (looksLikeBareRepository(current2)) {
|
|
194
|
+
const layout = resolved(current2);
|
|
195
|
+
if (layout) return layout;
|
|
196
|
+
}
|
|
197
|
+
const parent = dirname3(current2);
|
|
198
|
+
if (parent === current2) return { status: "absent" };
|
|
199
|
+
current2 = parent;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function probeGitLayout(directory) {
|
|
203
|
+
if (!directory) return { status: "absent" };
|
|
204
|
+
let last = "";
|
|
205
|
+
for (let attempt = 0; attempt < ATTEMPTS; attempt++) {
|
|
206
|
+
if (attempt) sleepSync(BACKOFF_MS * attempt);
|
|
207
|
+
try {
|
|
208
|
+
return probeOnce(directory);
|
|
209
|
+
} catch (error95) {
|
|
210
|
+
last = error95 instanceof TransientProbeError ? error95.message : errorCode(error95) || "unknown";
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return { status: "failed", reason: last };
|
|
214
|
+
}
|
|
53
215
|
|
|
54
216
|
// src/core/template.ts
|
|
55
217
|
var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
|
|
56
218
|
function applyTemplate(template, resolvers, what) {
|
|
57
219
|
return template.replace(PLACEHOLDER, (_, name) => {
|
|
58
|
-
const
|
|
59
|
-
if (!
|
|
220
|
+
const resolve3 = resolvers[name];
|
|
221
|
+
if (!resolve3) {
|
|
60
222
|
console.error(
|
|
61
223
|
`hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
|
|
62
224
|
);
|
|
63
225
|
return "unknown";
|
|
64
226
|
}
|
|
65
|
-
return
|
|
227
|
+
return resolve3();
|
|
66
228
|
});
|
|
67
229
|
}
|
|
68
230
|
|
|
69
231
|
// src/core/bank.ts
|
|
70
232
|
var DEFAULT_BANK_NAME = "coding";
|
|
71
233
|
var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"git",
|
|
77
|
-
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
78
|
-
{
|
|
79
|
-
cwd: directory,
|
|
80
|
-
encoding: "utf-8",
|
|
81
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
82
|
-
timeout: 1e3,
|
|
83
|
-
windowsHide: true
|
|
84
|
-
}
|
|
85
|
-
).trim();
|
|
86
|
-
if (!commonDir) return null;
|
|
87
|
-
if (basename(commonDir) === ".git") return dirname2(commonDir);
|
|
88
|
-
if (basename(commonDir).startsWith(".") && isBareRepository(commonDir)) {
|
|
89
|
-
return dirname2(commonDir);
|
|
90
|
-
}
|
|
91
|
-
return commonDir;
|
|
92
|
-
} catch {
|
|
93
|
-
return null;
|
|
234
|
+
var BankResolutionError = class extends Error {
|
|
235
|
+
constructor(message) {
|
|
236
|
+
super(message);
|
|
237
|
+
this.name = "BankResolutionError";
|
|
94
238
|
}
|
|
95
|
-
}
|
|
96
|
-
function
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
} catch {
|
|
105
|
-
return false;
|
|
239
|
+
};
|
|
240
|
+
function resolveProjectRoot(directory) {
|
|
241
|
+
if (!directory) return { status: "absent" };
|
|
242
|
+
const layout = probeGitLayout(directory);
|
|
243
|
+
if (layout.status !== "resolved") return layout;
|
|
244
|
+
const commonDir = layout.commonDir;
|
|
245
|
+
if (basename(commonDir) === ".git") return { status: "resolved", root: dirname4(commonDir) };
|
|
246
|
+
if (basename(commonDir).startsWith(".") && layout.bare) {
|
|
247
|
+
return { status: "resolved", root: dirname4(commonDir) };
|
|
106
248
|
}
|
|
249
|
+
return { status: "resolved", root: commonDir };
|
|
107
250
|
}
|
|
108
251
|
function projectNameOf(directory, sessionRoot) {
|
|
109
252
|
return gitProjectName(directory, true, sessionRoot);
|
|
@@ -113,7 +256,7 @@ function nearestExistingDir(directory) {
|
|
|
113
256
|
let current2 = directory;
|
|
114
257
|
while (current2) {
|
|
115
258
|
if (existsSync(current2)) return current2;
|
|
116
|
-
const parent =
|
|
259
|
+
const parent = dirname4(current2);
|
|
117
260
|
if (parent === current2) return "";
|
|
118
261
|
current2 = parent;
|
|
119
262
|
}
|
|
@@ -128,21 +271,29 @@ function mainWorktreeRoot(directory, sessionRoot = "") {
|
|
|
128
271
|
sessionRoot,
|
|
129
272
|
...PROJECT_ROOT_ENV.map((v) => process.env[v] || "")
|
|
130
273
|
];
|
|
274
|
+
let failure = null;
|
|
131
275
|
for (const candidate of candidates) {
|
|
132
|
-
|
|
133
|
-
|
|
276
|
+
if (!candidate) continue;
|
|
277
|
+
const projectRoot = resolveProjectRoot(candidate);
|
|
278
|
+
if (projectRoot.status === "resolved") return projectRoot;
|
|
279
|
+
if (projectRoot.status === "failed") failure = projectRoot;
|
|
134
280
|
}
|
|
135
|
-
return
|
|
281
|
+
return failure ?? { status: "absent" };
|
|
136
282
|
}
|
|
137
283
|
function gitProjectName(directory, resolveWorktrees, sessionRoot = "") {
|
|
138
284
|
if (resolveWorktrees) {
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
285
|
+
const projectRoot = mainWorktreeRoot(directory, sessionRoot);
|
|
286
|
+
if (projectRoot.status === "resolved") return basename(projectRoot.root);
|
|
287
|
+
if (projectRoot.status === "failed") {
|
|
288
|
+
throw new BankResolutionError(
|
|
289
|
+
`git probe failed for ${directory} (${projectRoot.reason}) \u2014 refusing to guess a bank id`
|
|
290
|
+
);
|
|
291
|
+
}
|
|
141
292
|
}
|
|
142
293
|
return dirName(sessionRoot || directory);
|
|
143
294
|
}
|
|
144
295
|
function configuredDir(dir) {
|
|
145
|
-
const expanded = dir === "~" || dir.startsWith("~/") ?
|
|
296
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join4(homedir(), dir.slice(1)) : dir;
|
|
146
297
|
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
147
298
|
}
|
|
148
299
|
function isWithin(directory, configured) {
|
|
@@ -162,8 +313,8 @@ function mapLookup(map3, directory) {
|
|
|
162
313
|
function lookupDirectories(config3, directory, sessionRoot = "") {
|
|
163
314
|
const directories = [normalize(directory)];
|
|
164
315
|
if (config3.resolveWorktrees ?? true) {
|
|
165
|
-
const
|
|
166
|
-
const normalizedRoot =
|
|
316
|
+
const projectRoot = mainWorktreeRoot(directory, sessionRoot);
|
|
317
|
+
const normalizedRoot = projectRoot.status === "resolved" ? normalize(projectRoot.root) : "";
|
|
167
318
|
if (normalizedRoot && normalizedRoot !== directories[0]) directories.push(normalizedRoot);
|
|
168
319
|
}
|
|
169
320
|
return directories;
|
|
@@ -196,52 +347,18 @@ function deriveBankId(config3, directory, harness = "coding", sessionRoot) {
|
|
|
196
347
|
};
|
|
197
348
|
return applyTemplate(config3.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
|
|
198
349
|
}
|
|
199
|
-
|
|
200
|
-
// src/core/log.ts
|
|
201
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
202
|
-
import { tmpdir } from "os";
|
|
203
|
-
import { dirname as dirname3, join as join3 } from "path";
|
|
204
|
-
var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
205
|
-
var current = ["debug", "info", "warn", "error"].find(
|
|
206
|
-
(l) => l === process.env.HINDSIGHT_LOG_LEVEL
|
|
207
|
-
) ?? "info";
|
|
208
|
-
function setLogLevel(level) {
|
|
209
|
-
if (!process.env.HINDSIGHT_LOG_LEVEL) current = level;
|
|
210
|
-
}
|
|
211
|
-
function logFilePath() {
|
|
212
|
-
return process.env.HINDSIGHT_LOG_FILE || join3(tmpdir(), "hindsight-coding-agent", "plugin.log");
|
|
213
|
-
}
|
|
214
|
-
function write(level, scope, msg, extra) {
|
|
215
|
-
if (WEIGHT[level] < WEIGHT[current]) return;
|
|
350
|
+
function deriveBankIdOrSkip(config3, directory, harness = "coding", sessionRoot) {
|
|
216
351
|
try {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
var log = {
|
|
227
|
-
debug: (scope, msg, extra) => write("debug", scope, msg, extra),
|
|
228
|
-
info: (scope, msg, extra) => write("info", scope, msg, extra),
|
|
229
|
-
warn: (scope, msg, extra) => write("warn", scope, msg, extra),
|
|
230
|
-
error: (scope, msg, extra) => write("error", scope, msg, extra)
|
|
231
|
-
};
|
|
232
|
-
function describeError(value, maxChars = 200) {
|
|
233
|
-
const parts = [];
|
|
234
|
-
const seen = /* @__PURE__ */ new Set();
|
|
235
|
-
let current2 = value;
|
|
236
|
-
while (current2 && !seen.has(current2)) {
|
|
237
|
-
seen.add(current2);
|
|
238
|
-
const error95 = current2;
|
|
239
|
-
const text = typeof error95.message === "string" ? error95.message : String(current2);
|
|
240
|
-
const withCode = error95.code ? `${text} (${String(error95.code)})` : text;
|
|
241
|
-
if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
|
|
242
|
-
current2 = error95.cause;
|
|
352
|
+
return deriveBankId(config3, directory, harness, sessionRoot);
|
|
353
|
+
} catch (error95) {
|
|
354
|
+
if (!(error95 instanceof BankResolutionError)) throw error95;
|
|
355
|
+
log.warn(harness, "bank unresolved: skipping (repository could not be identified)", {
|
|
356
|
+
directory,
|
|
357
|
+
error: error95.message
|
|
358
|
+
});
|
|
359
|
+
diag(harness, "bank_unresolved", { directory, error: error95.message });
|
|
360
|
+
return null;
|
|
243
361
|
}
|
|
244
|
-
return (parts.join(": ") || String(value)).slice(0, maxChars);
|
|
245
362
|
}
|
|
246
363
|
|
|
247
364
|
// src/core/missions.ts
|
|
@@ -381,15 +498,60 @@ var CODING_BANK_TEMPLATE = {
|
|
|
381
498
|
entities_allow_free_form: true
|
|
382
499
|
}
|
|
383
500
|
};
|
|
384
|
-
var
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
501
|
+
var MISSION_FIELDS = ["reflect_mission", "retain_mission", "observations_mission"];
|
|
502
|
+
function isSet(v) {
|
|
503
|
+
if (v === null || v === void 0) return false;
|
|
504
|
+
if (typeof v === "string") return v.trim() !== "";
|
|
505
|
+
return true;
|
|
506
|
+
}
|
|
507
|
+
function codingBankManifest(overrides) {
|
|
508
|
+
const current2 = overrides ?? {};
|
|
509
|
+
const template = CODING_BANK_TEMPLATE.bank;
|
|
510
|
+
const bank = {};
|
|
511
|
+
if (!MISSION_FIELDS.some((f) => isSet(current2[f]))) {
|
|
512
|
+
bank.reflect_mission = template.reflect_mission;
|
|
513
|
+
bank.enable_observations = template.enable_observations;
|
|
514
|
+
bank.observations_mission = template.observations_mission;
|
|
515
|
+
bank.retain_mission = template.retain_mission;
|
|
516
|
+
bank.retain_extraction_mode = template.retain_extraction_mode;
|
|
517
|
+
}
|
|
518
|
+
if (!isSet(current2.retain_default_strategy))
|
|
519
|
+
bank.retain_default_strategy = template.retain_default_strategy;
|
|
520
|
+
if (!isSet(current2.entities_allow_free_form))
|
|
521
|
+
bank.entities_allow_free_form = template.entities_allow_free_form;
|
|
522
|
+
const strategies = current2.retain_strategies && typeof current2.retain_strategies === "object" ? current2.retain_strategies : {};
|
|
523
|
+
const missing = Object.entries(template.retain_strategies).filter(([n]) => !(n in strategies));
|
|
524
|
+
if (missing.length > 0)
|
|
525
|
+
bank.retain_strategies = { ...strategies, ...Object.fromEntries(missing) };
|
|
526
|
+
const labels = Array.isArray(current2.entity_labels) ? current2.entity_labels : [];
|
|
527
|
+
const [knowledgeGroup] = template.entity_labels;
|
|
528
|
+
if (!labels.some((g) => g?.key === knowledgeGroup.key))
|
|
529
|
+
bank.entity_labels = [...labels, knowledgeGroup];
|
|
530
|
+
return Object.keys(bank).length > 0 ? { version: "1", bank } : void 0;
|
|
531
|
+
}
|
|
391
532
|
|
|
392
533
|
// src/core/util.ts
|
|
534
|
+
import { accessSync, constants } from "fs";
|
|
535
|
+
import { delimiter, join as join5 } from "path";
|
|
536
|
+
function binOnPath(bin) {
|
|
537
|
+
try {
|
|
538
|
+
if (bin.includes("/")) {
|
|
539
|
+
accessSync(bin, constants.X_OK);
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
for (const dir of (process.env.PATH || "").split(delimiter)) {
|
|
543
|
+
if (!dir) continue;
|
|
544
|
+
try {
|
|
545
|
+
accessSync(join5(dir, bin), constants.X_OK);
|
|
546
|
+
return true;
|
|
547
|
+
} catch {
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return false;
|
|
551
|
+
} catch {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
393
555
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
394
556
|
function semverGte(version3, min) {
|
|
395
557
|
const parts = (v) => {
|
|
@@ -421,6 +583,11 @@ async function pool(items, n, fn, onError, onProgress) {
|
|
|
421
583
|
}
|
|
422
584
|
|
|
423
585
|
// src/core/hindsight.ts
|
|
586
|
+
function resolveRetainScopes(tags, configured) {
|
|
587
|
+
if (configured !== "per_source") return configured;
|
|
588
|
+
const sources = [...new Set((tags ?? []).filter((t) => t.startsWith("source:")))].sort();
|
|
589
|
+
return [[], ...sources.map((s) => [s])];
|
|
590
|
+
}
|
|
424
591
|
var DEFAULT_OBSERVATION_SCOPES = "shared";
|
|
425
592
|
var MIN_IDEMPOTENT_RETAIN_VERSION = "0.8.6";
|
|
426
593
|
var RateLimitedError = class extends Error {
|
|
@@ -451,7 +618,6 @@ var DEFAULT_MAX_PARALLEL_RETAINS = 10;
|
|
|
451
618
|
var POLL_CYCLE_MS = 5e3;
|
|
452
619
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
453
620
|
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
454
|
-
var MISSION_FIELDS = ["reflect_mission", "retain_mission", "observations_mission"];
|
|
455
621
|
var HindsightClient = class {
|
|
456
622
|
apiUrl;
|
|
457
623
|
/** The credential the NEXT request will sign with — NOT the one the config file holds. The two
|
|
@@ -557,7 +723,7 @@ var HindsightClient = class {
|
|
|
557
723
|
// Sent on EVERY retain, including the server default `combined`, so the scoping a bank's
|
|
558
724
|
// observations were built under is a property of the write rather than of whichever server
|
|
559
725
|
// version happened to process it. Servers older than 0.4.15 ignore the field.
|
|
560
|
-
observation_scopes: this.observationScopes
|
|
726
|
+
observation_scopes: resolveRetainScopes(tags, this.observationScopes)
|
|
561
727
|
};
|
|
562
728
|
if (opts.timestamp) item.timestamp = opts.timestamp;
|
|
563
729
|
if (opts.metadata) item.metadata = opts.metadata;
|
|
@@ -598,11 +764,11 @@ var HindsightClient = class {
|
|
|
598
764
|
* Set. Powers the incremental git-sync's "what's already ingested?" check — since git commits are stored
|
|
599
765
|
* with document_id `git:<sha>`, the returned Set lets a caller diff a ref's commits against memory.
|
|
600
766
|
*/
|
|
601
|
-
async listDocumentIds(tag) {
|
|
767
|
+
async listDocumentIds(tag, tagsMatch = "all") {
|
|
602
768
|
const ids = /* @__PURE__ */ new Set();
|
|
603
769
|
const limit = 500;
|
|
604
770
|
for (let offset = 0; ; offset += limit) {
|
|
605
|
-
const q = `?tags=${encodeURIComponent(tag)}&tags_match
|
|
771
|
+
const q = `?tags=${encodeURIComponent(tag)}&tags_match=${tagsMatch}&limit=${limit}&offset=${offset}`;
|
|
606
772
|
const r = await this.req("GET", this.bankUrl(`/documents${q}`));
|
|
607
773
|
let items = [];
|
|
608
774
|
let total = 0;
|
|
@@ -618,49 +784,54 @@ var HindsightClient = class {
|
|
|
618
784
|
}
|
|
619
785
|
return ids;
|
|
620
786
|
}
|
|
621
|
-
/** Configure the bank: POST the coding bank
|
|
622
|
-
*
|
|
623
|
-
*
|
|
624
|
-
*
|
|
787
|
+
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
788
|
+
* entity labels), then seed knowledge pages when the server supports them. Both halves are
|
|
789
|
+
* idempotent and strictly ADDITIVE — nothing the bank already says is overwritten (#3927) — so
|
|
790
|
+
* the deepen engine can re-run this every pass. Creates the bank if missing; legacy servers
|
|
791
|
+
* continue with the template-only path.
|
|
792
|
+
*
|
|
793
|
+
* `manage: false` skips the config half entirely, for a bank whose owner shapes it themselves.
|
|
794
|
+
* That bank should then define the strategies this plugin writes under (`git`, `gitlog`,
|
|
795
|
+
* `conversation`, `document`, `survey`): an unknown strategy name is not an error server-side,
|
|
796
|
+
* it just falls back to the bank's own config, so the miss is silent. */
|
|
625
797
|
async configureBank(opts = {}) {
|
|
626
798
|
if (opts.reset) {
|
|
627
799
|
await this.req("DELETE", this.bankUrl());
|
|
628
800
|
this.log(`[bank] reset ${this.bank}`);
|
|
629
801
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
this.
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
802
|
+
if (opts.manage === false) {
|
|
803
|
+
this.log(`[bank] manageBankConfig: false \u2014 leaving ${this.bank}'s configuration alone`);
|
|
804
|
+
} else {
|
|
805
|
+
const manifest = codingBankManifest(opts.reset ? void 0 : await this.readBankOverrides());
|
|
806
|
+
if (!manifest) {
|
|
807
|
+
this.log(`[bank] ${this.bank} already carries the coding structure \u2014 nothing to apply`);
|
|
808
|
+
} else {
|
|
809
|
+
await this.req("POST", this.bankUrl("/import"), manifest);
|
|
810
|
+
this.log(`[bank] applied to ${this.bank}: ${Object.keys(manifest.bank).sort().join(", ")}`);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
639
813
|
await this.seedPages(opts.pageTrigger);
|
|
640
814
|
}
|
|
641
815
|
/**
|
|
642
|
-
*
|
|
643
|
-
* the user's own edit. Either way they are not ours to overwrite.
|
|
816
|
+
* This bank's own config OVERRIDES, or undefined when there are none to read.
|
|
644
817
|
*
|
|
645
|
-
*
|
|
646
|
-
*
|
|
647
|
-
*
|
|
648
|
-
*
|
|
818
|
+
* Deliberately the overrides and not the resolved config: an inherited global default is not
|
|
819
|
+
* something this bank's owner chose, so it must not read as "already set". `undefined` means the
|
|
820
|
+
* bank does not exist yet, or the deployment has the bank-config API switched off — in neither
|
|
821
|
+
* case can anything have been customised, so the caller seeds the full template.
|
|
649
822
|
*/
|
|
650
|
-
async
|
|
823
|
+
async readBankOverrides() {
|
|
651
824
|
try {
|
|
652
825
|
const r = await this.req("GET", this.bankUrl("/config"));
|
|
653
|
-
if (!r.ok) return
|
|
826
|
+
if (!r.ok) return void 0;
|
|
654
827
|
const j = await r.json();
|
|
655
|
-
return
|
|
656
|
-
const v = j.overrides?.[f];
|
|
657
|
-
return typeof v === "string" && v.trim() !== "";
|
|
658
|
-
});
|
|
828
|
+
return j.overrides ?? {};
|
|
659
829
|
} catch {
|
|
660
|
-
return
|
|
830
|
+
return void 0;
|
|
661
831
|
}
|
|
662
832
|
}
|
|
663
|
-
/**
|
|
833
|
+
/** Explicitly delete one document (and its cascaded memory units/links). Background sync must
|
|
834
|
+
* never use this as a cleanup primitive: a document id alone does not prove repository ownership. */
|
|
664
835
|
async deleteDocument(documentId) {
|
|
665
836
|
await this.req("DELETE", this.bankUrl(`/documents/${encodeURIComponent(documentId)}`));
|
|
666
837
|
}
|
|
@@ -961,7 +1132,7 @@ var HindsightClient = class {
|
|
|
961
1132
|
};
|
|
962
1133
|
|
|
963
1134
|
// src/core/config.ts
|
|
964
|
-
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG ||
|
|
1135
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
|
|
965
1136
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
966
1137
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
967
1138
|
function resolvePageTriggerType(raw) {
|
|
@@ -985,7 +1156,13 @@ function resolveReflectBudget(raw) {
|
|
|
985
1156
|
log.warn("config", `ignoring reflectBudget=${JSON.stringify(value)} \u2014 expected low|mid|high`);
|
|
986
1157
|
return "high";
|
|
987
1158
|
}
|
|
988
|
-
var OBSERVATION_SCOPE_MODES = [
|
|
1159
|
+
var OBSERVATION_SCOPE_MODES = [
|
|
1160
|
+
"shared",
|
|
1161
|
+
"combined",
|
|
1162
|
+
"per_tag",
|
|
1163
|
+
"all_combinations",
|
|
1164
|
+
"per_source"
|
|
1165
|
+
];
|
|
989
1166
|
function resolveObservationScopes(raw) {
|
|
990
1167
|
const value = raw;
|
|
991
1168
|
if (typeof value === "string")
|
|
@@ -1023,6 +1200,7 @@ function resolveConfig(raw = {}) {
|
|
|
1023
1200
|
disabled: raw.disabled ?? false,
|
|
1024
1201
|
retainSessions: raw.retainSessions ?? true,
|
|
1025
1202
|
// write sessions back by default, every harness
|
|
1203
|
+
manageBankConfig: raw.manageBankConfig ?? true,
|
|
1026
1204
|
maxParallelRetains: raw.maxParallelRetains || 10,
|
|
1027
1205
|
reflectTimeoutMs: raw.reflectTimeoutMs || 12e4,
|
|
1028
1206
|
// Inherit an explicitly-raised reflectTimeoutMs (that is what users reaching for a longer
|
|
@@ -1049,12 +1227,13 @@ function resolveConfig(raw = {}) {
|
|
|
1049
1227
|
) : {},
|
|
1050
1228
|
observationScopes: resolveObservationScopes(raw.observationScopes),
|
|
1051
1229
|
banks: raw.banks && typeof raw.banks === "object" ? raw.banks : {},
|
|
1052
|
-
logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info"
|
|
1230
|
+
logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info",
|
|
1231
|
+
autoUpdate: raw.autoUpdate ?? true
|
|
1053
1232
|
};
|
|
1054
1233
|
}
|
|
1055
1234
|
function readRaw(path) {
|
|
1056
1235
|
try {
|
|
1057
|
-
return JSON.parse(
|
|
1236
|
+
return JSON.parse(readFileSync2(path, "utf8"));
|
|
1058
1237
|
} catch (e) {
|
|
1059
1238
|
if (e?.code !== "ENOENT") {
|
|
1060
1239
|
console.error(`hindsight: ignoring invalid config at ${path}: ${e?.message || e}`);
|
|
@@ -1107,13 +1286,15 @@ var ENV_KEYS = {
|
|
|
1107
1286
|
surveyBudgetUsd: "HINDSIGHT_SURVEY_BUDGET_USD",
|
|
1108
1287
|
surveyRefreshCommits: "HINDSIGHT_SURVEY_REFRESH_COMMITS",
|
|
1109
1288
|
logLevel: "HINDSIGHT_LOG_LEVEL",
|
|
1289
|
+
autoUpdate: "HINDSIGHT_AUTO_UPDATE",
|
|
1110
1290
|
gitIngest: "HINDSIGHT_GIT_INGEST",
|
|
1111
1291
|
// Scalar modes only ("shared", "combined", "per_tag", "all_combinations"). An explicit scope
|
|
1112
1292
|
// list is a list OF lists, which does not survive flattening into one variable — file-only.
|
|
1113
1293
|
observationScopes: "HINDSIGHT_OBSERVATION_SCOPES",
|
|
1114
1294
|
// Comma-separated, e.g. HINDSIGHT_RETAIN_TAGS="project:{gitProject},env:work". A LIST rather than
|
|
1115
1295
|
// a map, so it flattens cleanly; its sibling retainMetadata stays file-only for the reason above.
|
|
1116
|
-
retainTags: "HINDSIGHT_RETAIN_TAGS"
|
|
1296
|
+
retainTags: "HINDSIGHT_RETAIN_TAGS",
|
|
1297
|
+
manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG"
|
|
1117
1298
|
};
|
|
1118
1299
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
1119
1300
|
"dynamicBankId",
|
|
@@ -1123,7 +1304,9 @@ var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
|
1123
1304
|
"retainSessions",
|
|
1124
1305
|
"autoReflect",
|
|
1125
1306
|
"autoSeed",
|
|
1126
|
-
"codebaseSurvey"
|
|
1307
|
+
"codebaseSurvey",
|
|
1308
|
+
"autoUpdate",
|
|
1309
|
+
"manageBankConfig"
|
|
1127
1310
|
]);
|
|
1128
1311
|
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
1129
1312
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
@@ -1202,7 +1385,9 @@ function resolvePartial(cfg, patch) {
|
|
|
1202
1385
|
function resolveHostConfig(harness, directory) {
|
|
1203
1386
|
const cfg0 = loadConfig({ harness });
|
|
1204
1387
|
if (cfg0.disabled) return { cfg: cfg0, bankId: "" };
|
|
1205
|
-
|
|
1388
|
+
const bankId = deriveBankIdOrSkip(cfg0, directory, harness);
|
|
1389
|
+
if (bankId === null) return { cfg: { ...cfg0, disabled: true }, bankId: "" };
|
|
1390
|
+
return applyBankConfig(cfg0, bankId, directory);
|
|
1206
1391
|
}
|
|
1207
1392
|
function resolveHostMemory(harness, directory) {
|
|
1208
1393
|
const { cfg, bankId } = resolveHostConfig(harness, directory);
|
|
@@ -1224,28 +1409,202 @@ function resolveHostMemory(harness, directory) {
|
|
|
1224
1409
|
};
|
|
1225
1410
|
}
|
|
1226
1411
|
|
|
1227
|
-
// src/core/
|
|
1228
|
-
import {
|
|
1229
|
-
import {
|
|
1412
|
+
// src/core/auto-update.ts
|
|
1413
|
+
import { spawn as realSpawn2 } from "child_process";
|
|
1414
|
+
import {
|
|
1415
|
+
existsSync as existsSync2,
|
|
1416
|
+
mkdirSync as mkdirSync2,
|
|
1417
|
+
readFileSync as readFileSync3,
|
|
1418
|
+
realpathSync as realpathSync2,
|
|
1419
|
+
unlinkSync,
|
|
1420
|
+
writeFileSync
|
|
1421
|
+
} from "fs";
|
|
1422
|
+
import { homedir as homedir3, tmpdir as tmpdir2 } from "os";
|
|
1423
|
+
import { dirname as dirname5, join as join7 } from "path";
|
|
1230
1424
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
function
|
|
1235
|
-
return
|
|
1425
|
+
var PACKAGE_NAME = "@vectorize-io/hindsight-coding-agents";
|
|
1426
|
+
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
1427
|
+
var FETCH_TIMEOUT_MS = 5e3;
|
|
1428
|
+
function stateFile(runtimeDir) {
|
|
1429
|
+
return join7(runtimeDir, ".update-check.json");
|
|
1236
1430
|
}
|
|
1237
|
-
function
|
|
1238
|
-
|
|
1431
|
+
function packageRoot() {
|
|
1432
|
+
return join7(dirname5(fileURLToPath2(import.meta.url)), "..");
|
|
1433
|
+
}
|
|
1434
|
+
function stagedRuntimeDir() {
|
|
1435
|
+
return join7(homedir3(), ".hindsight", "coding-agents");
|
|
1436
|
+
}
|
|
1437
|
+
function sameDir(a, b) {
|
|
1239
1438
|
try {
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1439
|
+
return realpathSync2(a) === realpathSync2(b);
|
|
1440
|
+
} catch {
|
|
1441
|
+
return a === b;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
function stagedVersion(pkgRoot) {
|
|
1445
|
+
try {
|
|
1446
|
+
const pkg = JSON.parse(readFileSync3(join7(pkgRoot, "package.json"), "utf8"));
|
|
1447
|
+
return typeof pkg.version === "string" ? pkg.version : "";
|
|
1448
|
+
} catch {
|
|
1449
|
+
return "";
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
function isNewer(candidate, current2) {
|
|
1453
|
+
const parse5 = (v) => {
|
|
1454
|
+
const [core = "", ...rest] = v.trim().split("-");
|
|
1455
|
+
return {
|
|
1456
|
+
nums: core.split(".").map((n) => Number.parseInt(n, 10)),
|
|
1457
|
+
pre: rest.length > 0
|
|
1458
|
+
};
|
|
1459
|
+
};
|
|
1460
|
+
const a = parse5(candidate);
|
|
1461
|
+
const b = parse5(current2);
|
|
1462
|
+
if (a.nums.length !== 3 || b.nums.length !== 3) return false;
|
|
1463
|
+
if (a.nums.some(Number.isNaN) || b.nums.some(Number.isNaN)) return false;
|
|
1464
|
+
for (let i = 0; i < 3; i++) {
|
|
1465
|
+
if (a.nums[i] !== b.nums[i]) return a.nums[i] > b.nums[i];
|
|
1466
|
+
}
|
|
1467
|
+
return b.pre && !a.pre;
|
|
1468
|
+
}
|
|
1469
|
+
function dueForCheck(file3, now) {
|
|
1470
|
+
try {
|
|
1471
|
+
const state = JSON.parse(readFileSync3(file3, "utf8"));
|
|
1472
|
+
return typeof state.lastCheck !== "number" || now - state.lastCheck >= CHECK_INTERVAL_MS;
|
|
1473
|
+
} catch {
|
|
1474
|
+
return true;
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
var ORIGIN_FILE = ".install-origin.json";
|
|
1478
|
+
function selfUpdatable(runtimeDir) {
|
|
1479
|
+
try {
|
|
1480
|
+
const origin = JSON.parse(readFileSync3(join7(runtimeDir, ORIGIN_FILE), "utf8"));
|
|
1481
|
+
if (typeof origin.source !== "string" || !origin.source) return false;
|
|
1482
|
+
return origin.source.split(/[\\/]/).includes("_npx");
|
|
1483
|
+
} catch {
|
|
1484
|
+
return false;
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
1488
|
+
function lockFile() {
|
|
1489
|
+
return join7(tmpdir2(), "hindsight-coding-agent", "auto-update.lock");
|
|
1490
|
+
}
|
|
1491
|
+
function acquireUpdateLock(file3, now) {
|
|
1492
|
+
try {
|
|
1493
|
+
const held = JSON.parse(readFileSync3(file3, "utf8"));
|
|
1494
|
+
if (held.ts && now - held.ts < LOCK_STALE_MS) {
|
|
1495
|
+
let holderAlive = false;
|
|
1496
|
+
if (held.pid) {
|
|
1497
|
+
try {
|
|
1498
|
+
process.kill(held.pid, 0);
|
|
1499
|
+
holderAlive = true;
|
|
1500
|
+
} catch {
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
if (holderAlive) return false;
|
|
1504
|
+
}
|
|
1505
|
+
} catch {
|
|
1506
|
+
}
|
|
1507
|
+
try {
|
|
1508
|
+
mkdirSync2(dirname5(file3), { recursive: true });
|
|
1509
|
+
writeFileSync(file3, JSON.stringify({ pid: process.pid, ts: now }));
|
|
1510
|
+
return true;
|
|
1511
|
+
} catch {
|
|
1512
|
+
return false;
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
function holdLockFor(file3, pid, now) {
|
|
1516
|
+
try {
|
|
1517
|
+
if (pid === void 0) return releaseUpdateLock(file3);
|
|
1518
|
+
writeFileSync(file3, JSON.stringify({ pid, ts: now }));
|
|
1519
|
+
} catch {
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
function releaseUpdateLock(file3) {
|
|
1523
|
+
try {
|
|
1524
|
+
unlinkSync(file3);
|
|
1525
|
+
} catch {
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
function stampCheck(file3, now, latest) {
|
|
1529
|
+
try {
|
|
1530
|
+
writeFileSync(file3, JSON.stringify({ lastCheck: now, latest }));
|
|
1531
|
+
} catch {
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
async function latestVersion(fetchImpl) {
|
|
1535
|
+
try {
|
|
1536
|
+
const r = await fetchImpl(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {
|
|
1537
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS)
|
|
1538
|
+
});
|
|
1539
|
+
if (!r.ok) return "";
|
|
1540
|
+
const body = await r.json();
|
|
1541
|
+
return typeof body.version === "string" ? body.version : "";
|
|
1244
1542
|
} catch {
|
|
1543
|
+
return "";
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
async function maybeAutoUpdate(cfg, opts = {}) {
|
|
1547
|
+
try {
|
|
1548
|
+
if (!cfg.autoUpdate) return "";
|
|
1549
|
+
if (process.env.HINDSIGHT_DISABLE_HOOKS) return "";
|
|
1550
|
+
const pkgRoot = opts.pkgRoot ?? packageRoot();
|
|
1551
|
+
const runtime = opts.runtimeDir ?? stagedRuntimeDir();
|
|
1552
|
+
if (!existsSync2(runtime)) return "";
|
|
1553
|
+
if (!sameDir(pkgRoot, runtime)) return "";
|
|
1554
|
+
const now = opts.now ?? Date.now();
|
|
1555
|
+
const file3 = stateFile(runtime);
|
|
1556
|
+
if (!dueForCheck(file3, now)) return "";
|
|
1557
|
+
const current2 = stagedVersion(pkgRoot);
|
|
1558
|
+
if (!current2) return "";
|
|
1559
|
+
if (!(opts.selfUpdatable ?? selfUpdatable)(runtime)) {
|
|
1560
|
+
log.info("auto-update", "runtime is managed outside npx \u2014 leaving its version alone");
|
|
1561
|
+
stampCheck(file3, now, "");
|
|
1562
|
+
return "";
|
|
1563
|
+
}
|
|
1564
|
+
if (!(opts.binOnPath ?? binOnPath)("npx")) {
|
|
1565
|
+
log.info("auto-update", "npx is not on PATH \u2014 skipping the update check");
|
|
1566
|
+
stampCheck(file3, now, "");
|
|
1567
|
+
return "";
|
|
1568
|
+
}
|
|
1569
|
+
const lock = opts.lockFile ?? lockFile();
|
|
1570
|
+
if (!acquireUpdateLock(lock, now)) return "";
|
|
1571
|
+
try {
|
|
1572
|
+
const latest = await latestVersion(opts.fetch ?? fetch);
|
|
1573
|
+
stampCheck(file3, now, latest);
|
|
1574
|
+
if (!latest || !isNewer(latest, current2)) {
|
|
1575
|
+
releaseUpdateLock(lock);
|
|
1576
|
+
return "";
|
|
1577
|
+
}
|
|
1578
|
+
log.info("auto-update", `updating the Hindsight runtime ${current2} -> ${latest}`);
|
|
1579
|
+
const child = (opts.spawn ?? realSpawn2)(
|
|
1580
|
+
"npx",
|
|
1581
|
+
["-y", `${PACKAGE_NAME}@${latest}`, "update"],
|
|
1582
|
+
{
|
|
1583
|
+
detached: true,
|
|
1584
|
+
stdio: "ignore",
|
|
1585
|
+
windowsHide: true
|
|
1586
|
+
}
|
|
1587
|
+
);
|
|
1588
|
+
child.on("error", (e) => {
|
|
1589
|
+
log.warn("auto-update", `update spawn failed: ${e.message}`);
|
|
1590
|
+
releaseUpdateLock(lock);
|
|
1591
|
+
});
|
|
1592
|
+
child.unref();
|
|
1593
|
+
holdLockFor(lock, child.pid, now);
|
|
1594
|
+
return latest;
|
|
1595
|
+
} catch (e) {
|
|
1596
|
+
releaseUpdateLock(lock);
|
|
1597
|
+
throw e;
|
|
1598
|
+
}
|
|
1599
|
+
} catch {
|
|
1600
|
+
return "";
|
|
1245
1601
|
}
|
|
1246
1602
|
}
|
|
1247
1603
|
|
|
1248
1604
|
// src/core/daemon.ts
|
|
1605
|
+
import { execFileSync, spawn as realSpawn3 } from "child_process";
|
|
1606
|
+
import { dirname as dirname6, join as join8 } from "path";
|
|
1607
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1249
1608
|
var DAEMON_WAIT_SESSION_START_MS = 12e3;
|
|
1250
1609
|
var DAEMON_WAIT_RETAIN_MS = 4e4;
|
|
1251
1610
|
async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
|
|
@@ -1259,7 +1618,7 @@ async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
|
|
|
1259
1618
|
function hasRustToolchain() {
|
|
1260
1619
|
if (process.platform !== "darwin") return true;
|
|
1261
1620
|
try {
|
|
1262
|
-
|
|
1621
|
+
execFileSync("cargo", ["--version"], {
|
|
1263
1622
|
stdio: "pipe",
|
|
1264
1623
|
timeout: 1e4,
|
|
1265
1624
|
windowsHide: true
|
|
@@ -1271,7 +1630,7 @@ function hasRustToolchain() {
|
|
|
1271
1630
|
}
|
|
1272
1631
|
function hasUvx() {
|
|
1273
1632
|
try {
|
|
1274
|
-
|
|
1633
|
+
execFileSync("uvx", ["--version"], {
|
|
1275
1634
|
stdio: "pipe",
|
|
1276
1635
|
timeout: 1e4,
|
|
1277
1636
|
windowsHide: true
|
|
@@ -1307,7 +1666,7 @@ function detectLlm(env = process.env) {
|
|
|
1307
1666
|
}
|
|
1308
1667
|
function onPath(bin) {
|
|
1309
1668
|
try {
|
|
1310
|
-
|
|
1669
|
+
execFileSync("which", [bin], {
|
|
1311
1670
|
stdio: "pipe",
|
|
1312
1671
|
timeout: 5e3,
|
|
1313
1672
|
windowsHide: true
|
|
@@ -1317,9 +1676,9 @@ function onPath(bin) {
|
|
|
1317
1676
|
return false;
|
|
1318
1677
|
}
|
|
1319
1678
|
}
|
|
1320
|
-
function startDaemonDetached(cfg, harness, spawnFn =
|
|
1679
|
+
function startDaemonDetached(cfg, harness, spawnFn = realSpawn3) {
|
|
1321
1680
|
try {
|
|
1322
|
-
const starter =
|
|
1681
|
+
const starter = join8(dirname6(fileURLToPath3(import.meta.url)), "daemon-start.js");
|
|
1323
1682
|
const child = spawnFn("node", [starter, "--harness", harness], {
|
|
1324
1683
|
detached: true,
|
|
1325
1684
|
stdio: "ignore",
|
|
@@ -15519,8 +15878,8 @@ function convertBaseSchema(schema, ctx) {
|
|
|
15519
15878
|
});
|
|
15520
15879
|
}
|
|
15521
15880
|
ctx.processing.add(refPath);
|
|
15522
|
-
const
|
|
15523
|
-
const zodSchema2 = convertSchema(
|
|
15881
|
+
const resolved2 = resolveRef(refPath, ctx);
|
|
15882
|
+
const zodSchema2 = convertSchema(resolved2, ctx);
|
|
15524
15883
|
ctx.refs.set(refPath, zodSchema2);
|
|
15525
15884
|
ctx.processing.delete(refPath);
|
|
15526
15885
|
return zodSchema2;
|
|
@@ -15887,25 +16246,25 @@ function date4(params) {
|
|
|
15887
16246
|
config(en_default());
|
|
15888
16247
|
|
|
15889
16248
|
// src/core/knowledge-tools.ts
|
|
15890
|
-
import { existsSync as
|
|
15891
|
-
import { homedir as
|
|
15892
|
-
import { join as
|
|
16249
|
+
import { existsSync as existsSync4 } from "fs";
|
|
16250
|
+
import { homedir as homedir5 } from "os";
|
|
16251
|
+
import { join as join10 } from "path";
|
|
15893
16252
|
|
|
15894
16253
|
// src/core/status.ts
|
|
15895
|
-
import { execFileSync as
|
|
16254
|
+
import { execFileSync as execFileSync3 } from "child_process";
|
|
15896
16255
|
|
|
15897
16256
|
// src/core/git.ts
|
|
15898
|
-
import { execFileSync as
|
|
15899
|
-
import { resolve } from "path";
|
|
16257
|
+
import { execFileSync as execFileSync2 } from "child_process";
|
|
16258
|
+
import { resolve as resolve2 } from "path";
|
|
15900
16259
|
function git(repo, ...args) {
|
|
15901
|
-
return
|
|
16260
|
+
return execFileSync2("git", ["-C", repo, ...args], {
|
|
15902
16261
|
encoding: "utf8",
|
|
15903
16262
|
maxBuffer: 1 << 28,
|
|
15904
16263
|
windowsHide: true
|
|
15905
16264
|
});
|
|
15906
16265
|
}
|
|
15907
16266
|
function repoNameOf(repo) {
|
|
15908
|
-
return projectNameOf(
|
|
16267
|
+
return projectNameOf(resolve2(repo));
|
|
15909
16268
|
}
|
|
15910
16269
|
function gitHeadSha(dir) {
|
|
15911
16270
|
try {
|
|
@@ -15975,11 +16334,11 @@ ${toolGuide(opts)}
|
|
|
15975
16334
|
}
|
|
15976
16335
|
|
|
15977
16336
|
// src/core/survey.ts
|
|
15978
|
-
import { spawn as
|
|
15979
|
-
import {
|
|
15980
|
-
import { homedir as
|
|
15981
|
-
import {
|
|
15982
|
-
import { fileURLToPath as
|
|
16337
|
+
import { spawn as realSpawn4 } from "child_process";
|
|
16338
|
+
import { existsSync as existsSync3 } from "fs";
|
|
16339
|
+
import { homedir as homedir4 } from "os";
|
|
16340
|
+
import { dirname as dirname7, join as join9 } from "path";
|
|
16341
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
15983
16342
|
var SURVEY_DOC_IDS = [
|
|
15984
16343
|
"repository-component-map",
|
|
15985
16344
|
"repository-core-concepts",
|
|
@@ -15989,9 +16348,9 @@ var SURVEY_DOC_IDS = [
|
|
|
15989
16348
|
function resolveClaudeBin(explicit) {
|
|
15990
16349
|
if (explicit) return explicit;
|
|
15991
16350
|
if (process.env.HINDSIGHT_CLAUDE_BIN) return process.env.HINDSIGHT_CLAUDE_BIN;
|
|
15992
|
-
const nativeInstallPath =
|
|
16351
|
+
const nativeInstallPath = join9(homedir4(), ".claude", "local", "claude");
|
|
15993
16352
|
try {
|
|
15994
|
-
if (
|
|
16353
|
+
if (existsSync3(nativeInstallPath)) return nativeInstallPath;
|
|
15995
16354
|
} catch {
|
|
15996
16355
|
}
|
|
15997
16356
|
return "claude";
|
|
@@ -16020,33 +16379,7 @@ function resolveAgentBin(harness, claudeBin) {
|
|
|
16020
16379
|
return process.env.HINDSIGHT_OPENCODE_BIN || "opencode";
|
|
16021
16380
|
}
|
|
16022
16381
|
}
|
|
16023
|
-
|
|
16024
|
-
try {
|
|
16025
|
-
if (bin.includes("/")) {
|
|
16026
|
-
accessSync(bin, constants.X_OK);
|
|
16027
|
-
return true;
|
|
16028
|
-
}
|
|
16029
|
-
for (const dir of (process.env.PATH || "").split(delimiter)) {
|
|
16030
|
-
if (!dir) continue;
|
|
16031
|
-
try {
|
|
16032
|
-
accessSync(join6(dir, bin), constants.X_OK);
|
|
16033
|
-
return true;
|
|
16034
|
-
} catch {
|
|
16035
|
-
}
|
|
16036
|
-
}
|
|
16037
|
-
return false;
|
|
16038
|
-
} catch {
|
|
16039
|
-
return false;
|
|
16040
|
-
}
|
|
16041
|
-
}
|
|
16042
|
-
var SURVEY_PROMPT = `You are performing a one-time structural survey of THIS repository to seed its Hindsight memory. Work efficiently \u2014 DO NOT read every file; sample enough to understand the architecture: the directory layout, entry points, package manifests (package.json / pyproject.toml / Cargo.toml / go.mod), the README, and a few representative source files per major area.
|
|
16043
|
-
IMPORTANT \u2014 DO NOT read, quote, summarize, or ingest agent-instruction files: CLAUDE.md, AGENTS.md, GEMINI.md, .cursorrules, .cursor/rules/*, or .github/copilot-instructions.md. These are live, user-controlled instructions (not repository knowledge); capturing them as memory would let a stale copy override the user's current instructions. Exclude them entirely from your survey and from every ingested document.
|
|
16044
|
-
Then use the hindsight_ingest_document tool to save what you learned as separate documents (one call each), with these titles and factual, developer-oriented content grounded in what you actually saw:
|
|
16045
|
-
- "Repository component map": the top-level modules/directories, each one's responsibility, and how they connect (data flow / dependencies).
|
|
16046
|
-
- "Repository core concepts": the domain model and key abstractions a new contributor must understand.
|
|
16047
|
-
- "Repository conventions and patterns": naming, file/module organization, testing approach, error handling, and other recurring patterns.
|
|
16048
|
-
- "Repository tech stack and features": languages, frameworks, build/test tooling, and the notable features the project provides.
|
|
16049
|
-
Keep each a few hundred words. When done, stop.`;
|
|
16382
|
+
var SURVEY_PROMPT = 'You are performing a one-time structural survey of THIS repository to seed its Hindsight memory. Work efficiently \u2014 DO NOT read every file; sample enough to understand the architecture: the directory layout, entry points, package manifests (package.json / pyproject.toml / Cargo.toml / go.mod), the README, and a few representative source files per major area. Use Glob (e.g. `**/*`) to see the directory layout \u2014 Read takes a FILE path only and errors on a directory; never call Read on a bare directory path.\nIMPORTANT \u2014 DO NOT read, quote, summarize, or ingest agent-instruction files: CLAUDE.md, AGENTS.md, GEMINI.md, .cursorrules, .cursor/rules/*, or .github/copilot-instructions.md. These are live, user-controlled instructions (not repository knowledge); capturing them as memory would let a stale copy override the user\'s current instructions. Exclude them entirely from your survey and from every ingested document.\nThen use the hindsight_ingest_document tool to save what you learned as separate documents (one call each), with these titles and factual, developer-oriented content grounded in what you actually saw:\n- "Repository component map": the top-level modules/directories, each one\'s responsibility, and how they connect (data flow / dependencies).\n- "Repository core concepts": the domain model and key abstractions a new contributor must understand.\n- "Repository conventions and patterns": naming, file/module organization, testing approach, error handling, and other recurring patterns.\n- "Repository tech stack and features": languages, frameworks, build/test tooling, and the notable features the project provides.\nKeep each a few hundred words. When done, stop.';
|
|
16050
16383
|
var SURVEY_DISALLOWED_TOOLS = [
|
|
16051
16384
|
"Bash",
|
|
16052
16385
|
"Write",
|
|
@@ -16142,9 +16475,9 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
16142
16475
|
}
|
|
16143
16476
|
function startCodebaseSurvey(repoDir, opts = {}) {
|
|
16144
16477
|
try {
|
|
16145
|
-
const spawnFn = opts.spawn ??
|
|
16146
|
-
const exists = opts.exists ??
|
|
16147
|
-
const mcpServerPath = opts.mcpServerPath ??
|
|
16478
|
+
const spawnFn = opts.spawn ?? realSpawn4;
|
|
16479
|
+
const exists = opts.exists ?? binOnPath;
|
|
16480
|
+
const mcpServerPath = opts.mcpServerPath ?? join9(dirname7(fileURLToPath4(import.meta.url)), "mcp-server.js");
|
|
16148
16481
|
const preferred = opts.harness ?? "claude-code";
|
|
16149
16482
|
const order = [
|
|
16150
16483
|
preferred,
|
|
@@ -16184,7 +16517,7 @@ function startCodebaseSurvey(repoDir, opts = {}) {
|
|
|
16184
16517
|
var DEEPEN_DIFF_TARGET = 300;
|
|
16185
16518
|
function commitCount(repoDir) {
|
|
16186
16519
|
try {
|
|
16187
|
-
const out =
|
|
16520
|
+
const out = execFileSync3("git", ["-C", repoDir, "rev-list", "--count", "HEAD"], {
|
|
16188
16521
|
encoding: "utf8",
|
|
16189
16522
|
windowsHide: true
|
|
16190
16523
|
});
|
|
@@ -16194,17 +16527,17 @@ function commitCount(repoDir) {
|
|
|
16194
16527
|
}
|
|
16195
16528
|
}
|
|
16196
16529
|
async function syncStatus(client, bank, repoDir) {
|
|
16197
|
-
const gitIds = await client.listDocumentIds("source:git");
|
|
16198
|
-
const chatIds = await client.listDocumentIds("source:chat").catch(() => /* @__PURE__ */ new Set());
|
|
16530
|
+
const gitIds = await client.listDocumentIds("source:git", "all_strict");
|
|
16531
|
+
const chatIds = await client.listDocumentIds("source:chat", "all_strict").catch(() => /* @__PURE__ */ new Set());
|
|
16199
16532
|
const pages = parsePageList(await client.listPages().catch(() => null));
|
|
16200
16533
|
const activeOps = await client.activeOperations().catch(() => null);
|
|
16201
|
-
const uploads = await client.listDocumentIds("source:upload").catch(() => /* @__PURE__ */ new Set());
|
|
16534
|
+
const uploads = await client.listDocumentIds("source:upload", "all_strict").catch(() => /* @__PURE__ */ new Set());
|
|
16202
16535
|
const surveyDocs = SURVEY_DOC_IDS.filter((id) => uploads.has(id)).length;
|
|
16203
16536
|
let surveyBaseline = null;
|
|
16204
16537
|
let surveyCommitsBehind = null;
|
|
16205
16538
|
if (repoDir) {
|
|
16206
16539
|
try {
|
|
16207
|
-
const markers = await client.listDocumentIds("source:survey-baseline");
|
|
16540
|
+
const markers = await client.listDocumentIds("source:survey-baseline", "all_strict");
|
|
16208
16541
|
let best;
|
|
16209
16542
|
for (const id of markers) {
|
|
16210
16543
|
const sha = id.replace(/^survey-baseline:/, "");
|
|
@@ -16241,6 +16574,18 @@ async function syncStatus(client, bank, repoDir) {
|
|
|
16241
16574
|
}
|
|
16242
16575
|
|
|
16243
16576
|
// src/core/knowledge-tools.ts
|
|
16577
|
+
var READ_ONLY_ANNOTATIONS = {
|
|
16578
|
+
readOnlyHint: true,
|
|
16579
|
+
destructiveHint: false,
|
|
16580
|
+
idempotentHint: true,
|
|
16581
|
+
openWorldHint: false
|
|
16582
|
+
};
|
|
16583
|
+
var NON_DESTRUCTIVE_WRITE_ANNOTATIONS = {
|
|
16584
|
+
readOnlyHint: false,
|
|
16585
|
+
destructiveHint: false,
|
|
16586
|
+
idempotentHint: false,
|
|
16587
|
+
openWorldHint: false
|
|
16588
|
+
};
|
|
16244
16589
|
function ok(value) {
|
|
16245
16590
|
return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
|
|
16246
16591
|
}
|
|
@@ -16263,6 +16608,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16263
16608
|
name: "hindsight_sync_status",
|
|
16264
16609
|
description: "Report whether this repo's memory bank is in sync: gitlog seed present, how much recent history has been deepened with full diffs, conversations ingested, knowledge pages created, and extractions still running. `synced: true` means the seeded memory is fully queryable. Ingestion is automatic and background \u2014 if not synced, it is in progress; nothing to run.",
|
|
16265
16610
|
inputSchema: {},
|
|
16611
|
+
annotations: READ_ONLY_ANNOTATIONS,
|
|
16266
16612
|
handler: async () => {
|
|
16267
16613
|
try {
|
|
16268
16614
|
return ok(await syncStatus(client, bankId, opts.repoDir ?? process.cwd()));
|
|
@@ -16275,8 +16621,9 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16275
16621
|
name: "hindsight_diagnose",
|
|
16276
16622
|
description: "Report safe Hindsight runtime diagnostics for this coding-agent session: resolved bank, workspace, harness, config location, API endpoint, and non-secret environment overrides. Use this when memory, hooks, MCP tools, or configuration appear not to work. Tokens and other secret values are never returned.",
|
|
16277
16623
|
inputSchema: {},
|
|
16624
|
+
annotations: READ_ONLY_ANNOTATIONS,
|
|
16278
16625
|
handler: async (_args) => {
|
|
16279
|
-
const configPath = process.env.HINDSIGHT_CONFIG ||
|
|
16626
|
+
const configPath = process.env.HINDSIGHT_CONFIG || join10(homedir5(), ".hindsight", "coding-agent.json");
|
|
16280
16627
|
const harness = opts.harness ?? "unknown";
|
|
16281
16628
|
const cfg = applyBankConfig(
|
|
16282
16629
|
loadConfig({ harness: opts.harness }),
|
|
@@ -16289,7 +16636,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16289
16636
|
workspace: opts.repoDir ?? process.cwd(),
|
|
16290
16637
|
config: {
|
|
16291
16638
|
path: configPath,
|
|
16292
|
-
exists:
|
|
16639
|
+
exists: existsSync4(configPath),
|
|
16293
16640
|
api_url: cfg.apiUrl,
|
|
16294
16641
|
api_token_configured: Boolean(cfg.apiToken),
|
|
16295
16642
|
disabled: cfg.disabled
|
|
@@ -16317,6 +16664,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16317
16664
|
name: "hindsight_search_knowledge_pages",
|
|
16318
16665
|
description: `Search this repository's Hindsight knowledge pages for content relevant to a query \u2014 hybrid full-text + semantic search, server-side. Call this when the user's question may be answered by the project's accumulated knowledge (architecture, conventions, decisions, initiatives) rather than by reading code. Returns ranked pages with a relevance snippet; read a full page with hindsight_read_knowledge_page. When a result informs your answer, credit it visibly: start that part with a markdown blockquote header "> \u{1F9E0} **From Hindsight memory (<page name>)** \u2014 <the facts you drew on>".`,
|
|
16319
16666
|
inputSchema: { query: external_exports.string().describe("what to look for") },
|
|
16667
|
+
annotations: READ_ONLY_ANNOTATIONS,
|
|
16320
16668
|
handler: async (args) => {
|
|
16321
16669
|
try {
|
|
16322
16670
|
const hits = await client.searchKnowledgePages(args.query, 3);
|
|
@@ -16337,18 +16685,21 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16337
16685
|
name: "hindsight_list_knowledge_pages",
|
|
16338
16686
|
description: "List this repository's Hindsight knowledge pages \u2014 curated, continuously-updated summaries of the project's durable knowledge (architecture, components, conventions, key decisions, and in-flight initiatives). Returns each page's id, title, and a one-line description of what it covers. Call this at the start of any non-trivial task, and again periodically in long sessions, to see what the project already knows before you read code or ask the user. The list changes as work is captured, so re-check it occasionally.",
|
|
16339
16687
|
inputSchema: {},
|
|
16688
|
+
annotations: READ_ONLY_ANNOTATIONS,
|
|
16340
16689
|
handler: guarded(async () => client.listPages())
|
|
16341
16690
|
},
|
|
16342
16691
|
{
|
|
16343
16692
|
name: "hindsight_read_knowledge_page",
|
|
16344
16693
|
description: "Read the full content of one knowledge page by its id (from hindsight_list_knowledge_pages). Call this whenever a listed page is relevant to what you're about to do \u2014 e.g. read Conventions before writing new code, Component map before changing a subsystem, or an initiative's page before continuing that feature. A page may contain [[page:<id>]] links to related pages; follow one by calling this tool again with that id. Prefer reading a page over re-deriving the same understanding from source.",
|
|
16345
16694
|
inputSchema: { page_id: external_exports.string() },
|
|
16695
|
+
annotations: READ_ONLY_ANNOTATIONS,
|
|
16346
16696
|
handler: guarded(async ({ page_id }) => client.getPage(page_id))
|
|
16347
16697
|
},
|
|
16348
16698
|
{
|
|
16349
16699
|
name: "hindsight_reflect",
|
|
16350
16700
|
description: `Deep memory reasoning: an agentic synthesis over this repository's FULL memory (git decisions, past sessions, ingested knowledge) that answers WHY questions \u2014 the past decision and exact rule/values that explain a behavior, bug, or convention. Slower than hindsight_search_knowledge_pages (several seconds): reach for it when pages are too shallow and you need the root cause or the decided literals. When the answer informs your reply, credit it visibly with a blockquote header: "> \u{1F9E0} **From Hindsight memory** \u2014 <summary>".`,
|
|
16351
16701
|
inputSchema: { query: external_exports.string().describe("the question to reason over memory about") },
|
|
16702
|
+
annotations: READ_ONLY_ANNOTATIONS,
|
|
16352
16703
|
handler: guarded(
|
|
16353
16704
|
async ({ query }) => client.reflect(query, {
|
|
16354
16705
|
budget: opts.reflectBudget ?? "high",
|
|
@@ -16364,6 +16715,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16364
16715
|
summary: external_exports.string(),
|
|
16365
16716
|
relates_to_page_id: external_exports.string().optional()
|
|
16366
16717
|
},
|
|
16718
|
+
annotations: NON_DESTRUCTIVE_WRITE_ANNOTATIONS,
|
|
16367
16719
|
handler: guarded(
|
|
16368
16720
|
async ({ title, summary, relates_to_page_id }) => client.captureInitiative({
|
|
16369
16721
|
title,
|
|
@@ -16378,6 +16730,7 @@ function buildKnowledgeTools(client, bankId, opts = {}) {
|
|
|
16378
16730
|
name: "hindsight_ingest_document",
|
|
16379
16731
|
description: "Save an external document or a block of durable notes/findings into this repository's memory so it informs future recall and pages. Use for design notes, research, or reference material you want remembered \u2014 not for the conversation you're already in (that's captured automatically at session end). This is ALSO the correction mechanism: when you verify that a retrieved memory is wrong or outdated, ingest a document titled 'Correction: <topic>' stating what memory claimed, what is actually true, and the evidence \u2014 the newer fact supersedes the stale one in future retrieval.",
|
|
16380
16732
|
inputSchema: { title: external_exports.string(), content: external_exports.string() },
|
|
16733
|
+
annotations: NON_DESTRUCTIVE_WRITE_ANNOTATIONS,
|
|
16381
16734
|
handler: guarded(async ({ title, content }) => {
|
|
16382
16735
|
const docId = title.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "doc";
|
|
16383
16736
|
const stamp = opts.stampFor?.();
|
|
@@ -16594,12 +16947,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
16594
16947
|
const base = resolversFor(ctx);
|
|
16595
16948
|
const cache = /* @__PURE__ */ new Map();
|
|
16596
16949
|
const resolvers = Object.fromEntries(
|
|
16597
|
-
Object.entries(base).map(([name,
|
|
16950
|
+
Object.entries(base).map(([name, resolve3]) => [
|
|
16598
16951
|
name,
|
|
16599
16952
|
() => {
|
|
16600
16953
|
const hit = cache.get(name);
|
|
16601
16954
|
if (hit !== void 0) return hit;
|
|
16602
|
-
const value =
|
|
16955
|
+
const value = resolve3();
|
|
16603
16956
|
cache.set(name, value);
|
|
16604
16957
|
return value;
|
|
16605
16958
|
}
|
|
@@ -16618,13 +16971,13 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
16618
16971
|
}
|
|
16619
16972
|
|
|
16620
16973
|
// src/core/session-start.ts
|
|
16621
|
-
import { readFileSync as
|
|
16974
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
16622
16975
|
|
|
16623
16976
|
// src/core/skill-sync.ts
|
|
16624
|
-
import { cpSync, existsSync as
|
|
16625
|
-
import { homedir as
|
|
16626
|
-
import { dirname as
|
|
16627
|
-
import { fileURLToPath as
|
|
16977
|
+
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync4 } from "fs";
|
|
16978
|
+
import { homedir as homedir6 } from "os";
|
|
16979
|
+
import { dirname as dirname8, join as join11 } from "path";
|
|
16980
|
+
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
16628
16981
|
|
|
16629
16982
|
// src/core/brand.ts
|
|
16630
16983
|
function brandWord() {
|
|
@@ -16641,24 +16994,24 @@ function brandWord() {
|
|
|
16641
16994
|
}
|
|
16642
16995
|
|
|
16643
16996
|
// src/core/session-cache.ts
|
|
16644
|
-
import { mkdirSync as
|
|
16645
|
-
import { tmpdir as
|
|
16646
|
-
import { dirname as
|
|
16997
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync5, renameSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
16998
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
16999
|
+
import { dirname as dirname9, join as join12 } from "path";
|
|
16647
17000
|
function sessionCacheFile(harness, sessionId) {
|
|
16648
|
-
return
|
|
17001
|
+
return join12(tmpdir3(), `hindsight-${harness}`, `${sessionId}.json`);
|
|
16649
17002
|
}
|
|
16650
17003
|
function readSessionCache(cacheFile) {
|
|
16651
17004
|
try {
|
|
16652
|
-
return JSON.parse(
|
|
17005
|
+
return JSON.parse(readFileSync5(cacheFile, "utf8"));
|
|
16653
17006
|
} catch {
|
|
16654
17007
|
return {};
|
|
16655
17008
|
}
|
|
16656
17009
|
}
|
|
16657
17010
|
function writeFileAtomic(path, body) {
|
|
16658
|
-
|
|
17011
|
+
mkdirSync3(dirname9(path), { recursive: true });
|
|
16659
17012
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
16660
17013
|
try {
|
|
16661
|
-
|
|
17014
|
+
writeFileSync2(tmp, body);
|
|
16662
17015
|
renameSync(tmp, path);
|
|
16663
17016
|
} catch (e) {
|
|
16664
17017
|
try {
|
|
@@ -16687,15 +17040,15 @@ async function gitSyncNote(args) {
|
|
|
16687
17040
|
if (mode === "none" || cold) return void 0;
|
|
16688
17041
|
const head = gitHeadSha(cwd);
|
|
16689
17042
|
if (!head) return void 0;
|
|
16690
|
-
const gitlogCurrent = await client.listDocumentIds(`gitlog-head:${head}
|
|
17043
|
+
const gitlogCurrent = await client.listDocumentIds(`gitlog-head:${head}`, "all_strict").then((s) => s.has(`gitlog:${repoNameOf(cwd)}`)).catch(() => void 0);
|
|
16691
17044
|
if (gitlogCurrent === void 0) return void 0;
|
|
16692
17045
|
if (mode === "message") return gitlogCurrent ? "git in sync" : "catching up on new commits";
|
|
16693
17046
|
const deepened = [...gitIds].filter((id) => id.startsWith("git:")).length;
|
|
16694
17047
|
let target = DEEPEN_DIFF_TARGET;
|
|
16695
17048
|
try {
|
|
16696
|
-
const { execFileSync:
|
|
17049
|
+
const { execFileSync: execFileSync4 } = await import("child_process");
|
|
16697
17050
|
const n = Number(
|
|
16698
|
-
|
|
17051
|
+
execFileSync4("git", ["-C", cwd, "rev-list", "--count", "HEAD"], {
|
|
16699
17052
|
encoding: "utf8",
|
|
16700
17053
|
windowsHide: true
|
|
16701
17054
|
}).trim()
|
|
@@ -16745,7 +17098,7 @@ async function buildSessionStartContext(args) {
|
|
|
16745
17098
|
{
|
|
16746
17099
|
let docIds;
|
|
16747
17100
|
try {
|
|
16748
|
-
docIds = await client.listDocumentIds("source:git");
|
|
17101
|
+
docIds = await client.listDocumentIds("source:git", "all_strict");
|
|
16749
17102
|
} catch {
|
|
16750
17103
|
docIds = void 0;
|
|
16751
17104
|
}
|
|
@@ -16767,7 +17120,7 @@ async function buildSessionStartContext(args) {
|
|
|
16767
17120
|
} else if (cfg.codebaseSurvey !== false && cfg.surveyRefreshCommits > 0) {
|
|
16768
17121
|
const sha = resolveHeadSha(cwd);
|
|
16769
17122
|
if (sha) {
|
|
16770
|
-
const markers = await client.listDocumentIds(SURVEY_BASELINE_TAG).catch(() => /* @__PURE__ */ new Set());
|
|
17123
|
+
const markers = await client.listDocumentIds(SURVEY_BASELINE_TAG, "all_strict").catch(() => /* @__PURE__ */ new Set());
|
|
16771
17124
|
const counts = [];
|
|
16772
17125
|
for (const id of markers) {
|
|
16773
17126
|
if (!id.startsWith(SURVEY_BASELINE_PREFIX)) continue;
|
|
@@ -16775,7 +17128,7 @@ async function buildSessionStartContext(args) {
|
|
|
16775
17128
|
if (n !== null) counts.push(n);
|
|
16776
17129
|
}
|
|
16777
17130
|
const sinceLast = counts.length ? Math.min(...counts) : null;
|
|
16778
|
-
const uploads = await client.listDocumentIds("source:upload").catch(() => /* @__PURE__ */ new Set());
|
|
17131
|
+
const uploads = await client.listDocumentIds("source:upload", "all_strict").catch(() => /* @__PURE__ */ new Set());
|
|
16779
17132
|
const findingsAbsent = counts.length > 0 && !SURVEY_DOC_IDS.some((id) => uploads.has(id));
|
|
16780
17133
|
if (sinceLast !== null && sinceLast >= cfg.surveyRefreshCommits || findingsAbsent) {
|
|
16781
17134
|
startSurvey(cwd, {
|
|
@@ -16826,7 +17179,7 @@ async function buildSessionStartContext(args) {
|
|
|
16826
17179
|
}
|
|
16827
17180
|
|
|
16828
17181
|
// src/core/hook.ts
|
|
16829
|
-
import { existsSync as
|
|
17182
|
+
import { existsSync as existsSync6, readFileSync as readFileSync7 } from "fs";
|
|
16830
17183
|
|
|
16831
17184
|
// src/core/inject.ts
|
|
16832
17185
|
function buildReflectQuery(prompt) {
|
|
@@ -17014,6 +17367,7 @@ var RuntimeCore = class {
|
|
|
17014
17367
|
async seedIfCold(repoPath) {
|
|
17015
17368
|
if (process.env.HINDSIGHT_DISABLE_HOOKS) return;
|
|
17016
17369
|
await ensureDaemon(this.cfg, this.harness, { waitMs: DAEMON_WAIT_SESSION_START_MS });
|
|
17370
|
+
void maybeAutoUpdate(this.cfg);
|
|
17017
17371
|
try {
|
|
17018
17372
|
const out = await buildSessionStartContext({
|
|
17019
17373
|
cwd: repoPath || process.cwd(),
|
|
@@ -29653,12 +30007,12 @@ function tool(input) {
|
|
|
29653
30007
|
tool.schema = external_exports2;
|
|
29654
30008
|
|
|
29655
30009
|
// src/harness/registry.ts
|
|
29656
|
-
import { readFileSync as
|
|
30010
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
29657
30011
|
var jsonChatReader = (harness) => ({
|
|
29658
30012
|
describe: `${harness} sessions via a normalized JSON export (--conversations file: [{ id, turns:[{role,text,timestamp?}] }])`,
|
|
29659
30013
|
async read(opts) {
|
|
29660
30014
|
if (!opts.conversations) return [];
|
|
29661
|
-
return JSON.parse(
|
|
30015
|
+
return JSON.parse(readFileSync8(opts.conversations, "utf8"));
|
|
29662
30016
|
}
|
|
29663
30017
|
});
|
|
29664
30018
|
|