@vectorize-io/hindsight-coding-agents 0.4.2 → 0.5.0
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 -51
- 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 +863 -236
- package/dist/claude-stop-hook.js +654 -205
- package/dist/cline.js +589 -234
- package/dist/codex-hook.js +637 -199
- package/dist/codex-sessionstart-hook.js +863 -236
- package/dist/codex-stop-hook.js +654 -205
- package/dist/copilot-hook.js +637 -199
- package/dist/copilot-sessionstart-hook.js +863 -236
- package/dist/copilot-stop-hook.js +654 -205
- package/dist/cursor-hook.js +637 -199
- package/dist/cursor-sessionstart-hook.js +863 -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 +3194 -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 +863 -236
- package/dist/devin-stop-hook.js +654 -205
- package/dist/dsh.js +592 -235
- package/dist/grok-hook.js +637 -199
- package/dist/grok-sessionstart-hook.js +863 -236
- package/dist/grok-stop-hook.js +654 -205
- package/dist/hindsight-seed.js +222 -83
- package/dist/index.js +589 -234
- package/dist/installer.js +2343 -302
- package/dist/kilo.js +589 -234
- package/dist/mcp-server.js +363 -169
- package/dist/opencode2.js +30092 -0
- package/dist/pi.js +17650 -0
- package/dist/prime-agent.js +625 -260
- package/dist/qwen-hook.js +2577 -0
- package/dist/qwen-sessionstart-hook.js +3194 -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
|
@@ -1,67 +1,210 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/core/hook.ts
|
|
4
|
-
import { existsSync as existsSync2, readFileSync as
|
|
4
|
+
import { existsSync as existsSync2, readFileSync as readFileSync4 } from "fs";
|
|
5
5
|
|
|
6
6
|
// src/core/bank.ts
|
|
7
|
-
import { execFileSync } from "child_process";
|
|
8
7
|
import { existsSync } from "fs";
|
|
9
8
|
import { homedir } from "os";
|
|
10
|
-
import { basename, dirname, join, normalize, sep } from "path";
|
|
9
|
+
import { basename, dirname as dirname3, join as join3, normalize, sep } from "path";
|
|
10
|
+
|
|
11
|
+
// src/core/diag.ts
|
|
12
|
+
import { appendFileSync as appendFileSync2 } from "fs";
|
|
13
|
+
|
|
14
|
+
// src/core/log.ts
|
|
15
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
16
|
+
import { tmpdir } from "os";
|
|
17
|
+
import { dirname, join } from "path";
|
|
18
|
+
var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
19
|
+
var current = ["debug", "info", "warn", "error"].find(
|
|
20
|
+
(l) => l === process.env.HINDSIGHT_LOG_LEVEL
|
|
21
|
+
) ?? "info";
|
|
22
|
+
function setLogLevel(level) {
|
|
23
|
+
if (!process.env.HINDSIGHT_LOG_LEVEL) current = level;
|
|
24
|
+
}
|
|
25
|
+
function logFilePath() {
|
|
26
|
+
return process.env.HINDSIGHT_LOG_FILE || join(tmpdir(), "hindsight-coding-agent", "plugin.log");
|
|
27
|
+
}
|
|
28
|
+
function write(level, scope, msg, extra) {
|
|
29
|
+
if (WEIGHT[level] < WEIGHT[current]) return;
|
|
30
|
+
try {
|
|
31
|
+
const file = logFilePath();
|
|
32
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
33
|
+
appendFileSync(
|
|
34
|
+
file,
|
|
35
|
+
`${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
|
|
36
|
+
);
|
|
37
|
+
} catch {
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
var log = {
|
|
41
|
+
debug: (scope, msg, extra) => write("debug", scope, msg, extra),
|
|
42
|
+
info: (scope, msg, extra) => write("info", scope, msg, extra),
|
|
43
|
+
warn: (scope, msg, extra) => write("warn", scope, msg, extra),
|
|
44
|
+
error: (scope, msg, extra) => write("error", scope, msg, extra)
|
|
45
|
+
};
|
|
46
|
+
function describeError(value, maxChars = 200) {
|
|
47
|
+
const parts = [];
|
|
48
|
+
const seen = /* @__PURE__ */ new Set();
|
|
49
|
+
let current2 = value;
|
|
50
|
+
while (current2 && !seen.has(current2)) {
|
|
51
|
+
seen.add(current2);
|
|
52
|
+
const error = current2;
|
|
53
|
+
const text = typeof error.message === "string" ? error.message : String(current2);
|
|
54
|
+
const withCode = error.code ? `${text} (${String(error.code)})` : text;
|
|
55
|
+
if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
|
|
56
|
+
current2 = error.cause;
|
|
57
|
+
}
|
|
58
|
+
return (parts.join(": ") || String(value)).slice(0, maxChars);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/core/diag.ts
|
|
62
|
+
function diagFilePath() {
|
|
63
|
+
return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
|
|
64
|
+
}
|
|
65
|
+
function diag(harness, event, extra = {}) {
|
|
66
|
+
log.debug(harness, `diag:${event}`, extra);
|
|
67
|
+
try {
|
|
68
|
+
appendFileSync2(
|
|
69
|
+
diagFilePath(),
|
|
70
|
+
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
71
|
+
);
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/core/git-layout.ts
|
|
77
|
+
import { lstatSync, readFileSync, realpathSync } from "fs";
|
|
78
|
+
import { dirname as dirname2, isAbsolute, join as join2, resolve } from "path";
|
|
79
|
+
var TRANSIENT = /* @__PURE__ */ new Set(["EAGAIN", "EMFILE", "ENFILE", "EBUSY", "EINTR", "EIO", "ETIMEDOUT"]);
|
|
80
|
+
var ATTEMPTS = 3;
|
|
81
|
+
var BACKOFF_MS = 20;
|
|
82
|
+
function errorCode(error) {
|
|
83
|
+
return error?.code ?? "";
|
|
84
|
+
}
|
|
85
|
+
function sleepSync(ms) {
|
|
86
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
87
|
+
}
|
|
88
|
+
var TransientProbeError = class extends Error {
|
|
89
|
+
};
|
|
90
|
+
function entryKind(path) {
|
|
91
|
+
try {
|
|
92
|
+
const st = lstatSync(path);
|
|
93
|
+
return st.isDirectory() ? "dir" : "file";
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (TRANSIENT.has(errorCode(error))) throw new TransientProbeError(errorCode(error));
|
|
96
|
+
return "none";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
function readTextOrNull(path) {
|
|
100
|
+
try {
|
|
101
|
+
return readFileSync(path, "utf8");
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (TRANSIENT.has(errorCode(error))) throw new TransientProbeError(errorCode(error));
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function gitDirFromPointer(text, holder) {
|
|
108
|
+
const match = /^\s*gitdir:\s*(.+?)\s*$/m.exec(text);
|
|
109
|
+
if (!match) return null;
|
|
110
|
+
const target = match[1];
|
|
111
|
+
return isAbsolute(target) ? target : resolve(holder, target);
|
|
112
|
+
}
|
|
113
|
+
function commonDirOf(gitDir) {
|
|
114
|
+
const pointer = entryKind(join2(gitDir, "commondir")) === "file" ? readTextOrNull(join2(gitDir, "commondir"))?.trim() : null;
|
|
115
|
+
if (!pointer) return gitDir;
|
|
116
|
+
return isAbsolute(pointer) ? pointer : resolve(gitDir, pointer);
|
|
117
|
+
}
|
|
118
|
+
function isBare(commonDir) {
|
|
119
|
+
const config = readTextOrNull(join2(commonDir, "config"));
|
|
120
|
+
return config !== null && /^\s*bare\s*=\s*true\s*$/im.test(config);
|
|
121
|
+
}
|
|
122
|
+
function looksLikeBareRepository(directory) {
|
|
123
|
+
return entryKind(join2(directory, "HEAD")) === "file" && entryKind(join2(directory, "objects")) === "dir" && entryKind(join2(directory, "refs")) === "dir";
|
|
124
|
+
}
|
|
125
|
+
function canonical(path) {
|
|
126
|
+
try {
|
|
127
|
+
return realpathSync(path);
|
|
128
|
+
} catch {
|
|
129
|
+
return path;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function resolved(commonDir) {
|
|
133
|
+
if (entryKind(commonDir) !== "dir") return null;
|
|
134
|
+
const canonicalDir = canonical(commonDir);
|
|
135
|
+
return { status: "resolved", commonDir: canonicalDir, bare: isBare(canonicalDir) };
|
|
136
|
+
}
|
|
137
|
+
function probeOnce(directory) {
|
|
138
|
+
let current2 = resolve(directory);
|
|
139
|
+
for (; ; ) {
|
|
140
|
+
const dotGit = join2(current2, ".git");
|
|
141
|
+
const kind = entryKind(dotGit);
|
|
142
|
+
if (kind === "dir") {
|
|
143
|
+
const layout = resolved(commonDirOf(dotGit));
|
|
144
|
+
if (layout) return layout;
|
|
145
|
+
} else if (kind === "file") {
|
|
146
|
+
const text = readTextOrNull(dotGit);
|
|
147
|
+
const gitDir = text ? gitDirFromPointer(text, current2) : null;
|
|
148
|
+
const layout = gitDir ? resolved(commonDirOf(gitDir)) : null;
|
|
149
|
+
if (layout) return layout;
|
|
150
|
+
}
|
|
151
|
+
if (looksLikeBareRepository(current2)) {
|
|
152
|
+
const layout = resolved(current2);
|
|
153
|
+
if (layout) return layout;
|
|
154
|
+
}
|
|
155
|
+
const parent = dirname2(current2);
|
|
156
|
+
if (parent === current2) return { status: "absent" };
|
|
157
|
+
current2 = parent;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function probeGitLayout(directory) {
|
|
161
|
+
if (!directory) return { status: "absent" };
|
|
162
|
+
let last = "";
|
|
163
|
+
for (let attempt = 0; attempt < ATTEMPTS; attempt++) {
|
|
164
|
+
if (attempt) sleepSync(BACKOFF_MS * attempt);
|
|
165
|
+
try {
|
|
166
|
+
return probeOnce(directory);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
last = error instanceof TransientProbeError ? error.message : errorCode(error) || "unknown";
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return { status: "failed", reason: last };
|
|
172
|
+
}
|
|
11
173
|
|
|
12
174
|
// src/core/template.ts
|
|
13
175
|
var PLACEHOLDER = /\{([a-zA-Z_]+)\}/g;
|
|
14
176
|
function applyTemplate(template, resolvers, what) {
|
|
15
177
|
return template.replace(PLACEHOLDER, (_, name) => {
|
|
16
|
-
const
|
|
17
|
-
if (!
|
|
178
|
+
const resolve3 = resolvers[name];
|
|
179
|
+
if (!resolve3) {
|
|
18
180
|
console.error(
|
|
19
181
|
`hindsight: unknown ${what} placeholder "{${name}}" \u2014 valid: ` + Object.keys(resolvers).sort().map((k) => `{${k}}`).join(", ")
|
|
20
182
|
);
|
|
21
183
|
return "unknown";
|
|
22
184
|
}
|
|
23
|
-
return
|
|
185
|
+
return resolve3();
|
|
24
186
|
});
|
|
25
187
|
}
|
|
26
188
|
|
|
27
189
|
// src/core/bank.ts
|
|
28
190
|
var DEFAULT_BANK_NAME = "coding";
|
|
29
191
|
var DEFAULT_TEMPLATE = "coding-agent::{gitProject}";
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"git",
|
|
35
|
-
["rev-parse", "--path-format=absolute", "--git-common-dir"],
|
|
36
|
-
{
|
|
37
|
-
cwd: directory,
|
|
38
|
-
encoding: "utf-8",
|
|
39
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
40
|
-
timeout: 1e3,
|
|
41
|
-
windowsHide: true
|
|
42
|
-
}
|
|
43
|
-
).trim();
|
|
44
|
-
if (!commonDir) return null;
|
|
45
|
-
if (basename(commonDir) === ".git") return dirname(commonDir);
|
|
46
|
-
if (basename(commonDir).startsWith(".") && isBareRepository(commonDir)) {
|
|
47
|
-
return dirname(commonDir);
|
|
48
|
-
}
|
|
49
|
-
return commonDir;
|
|
50
|
-
} catch {
|
|
51
|
-
return null;
|
|
192
|
+
var BankResolutionError = class extends Error {
|
|
193
|
+
constructor(message) {
|
|
194
|
+
super(message);
|
|
195
|
+
this.name = "BankResolutionError";
|
|
52
196
|
}
|
|
53
|
-
}
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
} catch {
|
|
63
|
-
return false;
|
|
197
|
+
};
|
|
198
|
+
function resolveProjectRoot(directory) {
|
|
199
|
+
if (!directory) return { status: "absent" };
|
|
200
|
+
const layout = probeGitLayout(directory);
|
|
201
|
+
if (layout.status !== "resolved") return layout;
|
|
202
|
+
const commonDir = layout.commonDir;
|
|
203
|
+
if (basename(commonDir) === ".git") return { status: "resolved", root: dirname3(commonDir) };
|
|
204
|
+
if (basename(commonDir).startsWith(".") && layout.bare) {
|
|
205
|
+
return { status: "resolved", root: dirname3(commonDir) };
|
|
64
206
|
}
|
|
207
|
+
return { status: "resolved", root: commonDir };
|
|
65
208
|
}
|
|
66
209
|
function projectNameOf(directory, sessionRoot) {
|
|
67
210
|
return gitProjectName(directory, true, sessionRoot);
|
|
@@ -71,7 +214,7 @@ function nearestExistingDir(directory) {
|
|
|
71
214
|
let current2 = directory;
|
|
72
215
|
while (current2) {
|
|
73
216
|
if (existsSync(current2)) return current2;
|
|
74
|
-
const parent =
|
|
217
|
+
const parent = dirname3(current2);
|
|
75
218
|
if (parent === current2) return "";
|
|
76
219
|
current2 = parent;
|
|
77
220
|
}
|
|
@@ -86,21 +229,29 @@ function mainWorktreeRoot(directory, sessionRoot = "") {
|
|
|
86
229
|
sessionRoot,
|
|
87
230
|
...PROJECT_ROOT_ENV.map((v) => process.env[v] || "")
|
|
88
231
|
];
|
|
232
|
+
let failure = null;
|
|
89
233
|
for (const candidate of candidates) {
|
|
90
|
-
|
|
91
|
-
|
|
234
|
+
if (!candidate) continue;
|
|
235
|
+
const projectRoot = resolveProjectRoot(candidate);
|
|
236
|
+
if (projectRoot.status === "resolved") return projectRoot;
|
|
237
|
+
if (projectRoot.status === "failed") failure = projectRoot;
|
|
92
238
|
}
|
|
93
|
-
return
|
|
239
|
+
return failure ?? { status: "absent" };
|
|
94
240
|
}
|
|
95
241
|
function gitProjectName(directory, resolveWorktrees, sessionRoot = "") {
|
|
96
242
|
if (resolveWorktrees) {
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
243
|
+
const projectRoot = mainWorktreeRoot(directory, sessionRoot);
|
|
244
|
+
if (projectRoot.status === "resolved") return basename(projectRoot.root);
|
|
245
|
+
if (projectRoot.status === "failed") {
|
|
246
|
+
throw new BankResolutionError(
|
|
247
|
+
`git probe failed for ${directory} (${projectRoot.reason}) \u2014 refusing to guess a bank id`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
99
250
|
}
|
|
100
251
|
return dirName(sessionRoot || directory);
|
|
101
252
|
}
|
|
102
253
|
function configuredDir(dir) {
|
|
103
|
-
const expanded = dir === "~" || dir.startsWith("~/") ?
|
|
254
|
+
const expanded = dir === "~" || dir.startsWith("~/") ? join3(homedir(), dir.slice(1)) : dir;
|
|
104
255
|
return normalize(expanded).replace(new RegExp(`\\${sep}+$`), "");
|
|
105
256
|
}
|
|
106
257
|
function isWithin(directory, configured) {
|
|
@@ -120,8 +271,8 @@ function mapLookup(map, directory) {
|
|
|
120
271
|
function lookupDirectories(config, directory, sessionRoot = "") {
|
|
121
272
|
const directories = [normalize(directory)];
|
|
122
273
|
if (config.resolveWorktrees ?? true) {
|
|
123
|
-
const
|
|
124
|
-
const normalizedRoot =
|
|
274
|
+
const projectRoot = mainWorktreeRoot(directory, sessionRoot);
|
|
275
|
+
const normalizedRoot = projectRoot.status === "resolved" ? normalize(projectRoot.root) : "";
|
|
125
276
|
if (normalizedRoot && normalizedRoot !== directories[0]) directories.push(normalizedRoot);
|
|
126
277
|
}
|
|
127
278
|
return directories;
|
|
@@ -154,65 +305,31 @@ function deriveBankId(config, directory, harness = "coding", sessionRoot) {
|
|
|
154
305
|
};
|
|
155
306
|
return applyTemplate(config.bankIdTemplate || DEFAULT_TEMPLATE, resolvers, "bankIdTemplate");
|
|
156
307
|
}
|
|
308
|
+
function deriveBankIdOrSkip(config, directory, harness = "coding", sessionRoot) {
|
|
309
|
+
try {
|
|
310
|
+
return deriveBankId(config, directory, harness, sessionRoot);
|
|
311
|
+
} catch (error) {
|
|
312
|
+
if (!(error instanceof BankResolutionError)) throw error;
|
|
313
|
+
log.warn(harness, "bank unresolved: skipping (repository could not be identified)", {
|
|
314
|
+
directory,
|
|
315
|
+
error: error.message
|
|
316
|
+
});
|
|
317
|
+
diag(harness, "bank_unresolved", { directory, error: error.message });
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
157
321
|
|
|
158
322
|
// src/core/config.ts
|
|
159
|
-
import { readFileSync } from "fs";
|
|
323
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
160
324
|
import { homedir as homedir2 } from "os";
|
|
161
|
-
import { join as
|
|
325
|
+
import { join as join6 } from "path";
|
|
162
326
|
|
|
163
327
|
// src/core/seed.ts
|
|
164
328
|
import { spawn as realSpawn } from "child_process";
|
|
165
|
-
import { dirname as
|
|
329
|
+
import { dirname as dirname4, join as join4 } from "path";
|
|
166
330
|
import { fileURLToPath } from "url";
|
|
167
331
|
var DEFAULT_SEED_LIMIT = 300;
|
|
168
332
|
|
|
169
|
-
// src/core/log.ts
|
|
170
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
171
|
-
import { tmpdir } from "os";
|
|
172
|
-
import { dirname as dirname3, join as join3 } from "path";
|
|
173
|
-
var WEIGHT = { debug: 10, info: 20, warn: 30, error: 40 };
|
|
174
|
-
var current = ["debug", "info", "warn", "error"].find(
|
|
175
|
-
(l) => l === process.env.HINDSIGHT_LOG_LEVEL
|
|
176
|
-
) ?? "info";
|
|
177
|
-
function setLogLevel(level) {
|
|
178
|
-
if (!process.env.HINDSIGHT_LOG_LEVEL) current = level;
|
|
179
|
-
}
|
|
180
|
-
function logFilePath() {
|
|
181
|
-
return process.env.HINDSIGHT_LOG_FILE || join3(tmpdir(), "hindsight-coding-agent", "plugin.log");
|
|
182
|
-
}
|
|
183
|
-
function write(level, scope, msg, extra) {
|
|
184
|
-
if (WEIGHT[level] < WEIGHT[current]) return;
|
|
185
|
-
try {
|
|
186
|
-
const file = logFilePath();
|
|
187
|
-
mkdirSync(dirname3(file), { recursive: true });
|
|
188
|
-
appendFileSync(
|
|
189
|
-
file,
|
|
190
|
-
`${(/* @__PURE__ */ new Date()).toISOString()} ${level.toUpperCase().padEnd(5)} [${scope}] ${msg}` + (extra && Object.keys(extra).length ? ` ${JSON.stringify(extra)}` : "") + "\n"
|
|
191
|
-
);
|
|
192
|
-
} catch {
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
var log = {
|
|
196
|
-
debug: (scope, msg, extra) => write("debug", scope, msg, extra),
|
|
197
|
-
info: (scope, msg, extra) => write("info", scope, msg, extra),
|
|
198
|
-
warn: (scope, msg, extra) => write("warn", scope, msg, extra),
|
|
199
|
-
error: (scope, msg, extra) => write("error", scope, msg, extra)
|
|
200
|
-
};
|
|
201
|
-
function describeError(value, maxChars = 200) {
|
|
202
|
-
const parts = [];
|
|
203
|
-
const seen = /* @__PURE__ */ new Set();
|
|
204
|
-
let current2 = value;
|
|
205
|
-
while (current2 && !seen.has(current2)) {
|
|
206
|
-
seen.add(current2);
|
|
207
|
-
const error = current2;
|
|
208
|
-
const text = typeof error.message === "string" ? error.message : String(current2);
|
|
209
|
-
const withCode = error.code ? `${text} (${String(error.code)})` : text;
|
|
210
|
-
if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
|
|
211
|
-
current2 = error.cause;
|
|
212
|
-
}
|
|
213
|
-
return (parts.join(": ") || String(value)).slice(0, maxChars);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
333
|
// src/core/missions.ts
|
|
217
334
|
var GIT_MISSION = "You are ingesting a single git commit: its message and its full diff. Extract the concrete technical DECISION and the CAUSE/INVARIANT it encodes, bound to the specific code entities (functions, methods, files) and behaviors it changes. Preserve exact identifiers, paths, and literal values verbatim. Preserve the 'REF-ID: <token>' marker verbatim in every fact. Capture both WHAT changed and WHY. Issue/PR references (#123, GH-123, PROJ-123) are load-bearing: keep them VERBATIM in the fact text and emit each as an ENTITY, so a later question about that issue or PR retrieves this decision.";
|
|
218
335
|
var GITLOG_MISSION = "You are ingesting an aggregated block of git commit MESSAGES ONLY (no diffs) \u2014 the project's recent commit-message history, newest first. Extract the project's INITIATIVES, FEATURES, ENHANCEMENTS, and notable changes or THEMES over time \u2014 what the project has been working on and how it has evolved. Do NOT extract per-line code detail (there is no diff to draw it from). Group related commits into a coherent initiative/theme where the messages make that clear; preserve exact identifiers and literal values verbatim when quoting a subject line. Keep issue/PR references (#123, GH-123) VERBATIM and emit each as an ENTITY \u2014 they are how future sessions will ask about this work.";
|
|
@@ -350,15 +467,41 @@ var CODING_BANK_TEMPLATE = {
|
|
|
350
467
|
entities_allow_free_form: true
|
|
351
468
|
}
|
|
352
469
|
};
|
|
353
|
-
var
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
470
|
+
var MISSION_FIELDS = ["reflect_mission", "retain_mission", "observations_mission"];
|
|
471
|
+
function isSet(v) {
|
|
472
|
+
if (v === null || v === void 0) return false;
|
|
473
|
+
if (typeof v === "string") return v.trim() !== "";
|
|
474
|
+
return true;
|
|
475
|
+
}
|
|
476
|
+
function codingBankManifest(overrides) {
|
|
477
|
+
const current2 = overrides ?? {};
|
|
478
|
+
const template = CODING_BANK_TEMPLATE.bank;
|
|
479
|
+
const bank = {};
|
|
480
|
+
if (!MISSION_FIELDS.some((f) => isSet(current2[f]))) {
|
|
481
|
+
bank.reflect_mission = template.reflect_mission;
|
|
482
|
+
bank.enable_observations = template.enable_observations;
|
|
483
|
+
bank.observations_mission = template.observations_mission;
|
|
484
|
+
bank.retain_mission = template.retain_mission;
|
|
485
|
+
bank.retain_extraction_mode = template.retain_extraction_mode;
|
|
486
|
+
}
|
|
487
|
+
if (!isSet(current2.retain_default_strategy))
|
|
488
|
+
bank.retain_default_strategy = template.retain_default_strategy;
|
|
489
|
+
if (!isSet(current2.entities_allow_free_form))
|
|
490
|
+
bank.entities_allow_free_form = template.entities_allow_free_form;
|
|
491
|
+
const strategies = current2.retain_strategies && typeof current2.retain_strategies === "object" ? current2.retain_strategies : {};
|
|
492
|
+
const missing = Object.entries(template.retain_strategies).filter(([n]) => !(n in strategies));
|
|
493
|
+
if (missing.length > 0)
|
|
494
|
+
bank.retain_strategies = { ...strategies, ...Object.fromEntries(missing) };
|
|
495
|
+
const labels = Array.isArray(current2.entity_labels) ? current2.entity_labels : [];
|
|
496
|
+
const [knowledgeGroup] = template.entity_labels;
|
|
497
|
+
if (!labels.some((g) => g?.key === knowledgeGroup.key))
|
|
498
|
+
bank.entity_labels = [...labels, knowledgeGroup];
|
|
499
|
+
return Object.keys(bank).length > 0 ? { version: "1", bank } : void 0;
|
|
500
|
+
}
|
|
360
501
|
|
|
361
502
|
// src/core/util.ts
|
|
503
|
+
import { accessSync, constants } from "fs";
|
|
504
|
+
import { delimiter, join as join5 } from "path";
|
|
362
505
|
var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
363
506
|
function semverGte(version, min) {
|
|
364
507
|
const parts = (v) => {
|
|
@@ -390,6 +533,11 @@ async function pool(items, n, fn, onError, onProgress) {
|
|
|
390
533
|
}
|
|
391
534
|
|
|
392
535
|
// src/core/hindsight.ts
|
|
536
|
+
function resolveRetainScopes(tags, configured) {
|
|
537
|
+
if (configured !== "per_source") return configured;
|
|
538
|
+
const sources = [...new Set((tags ?? []).filter((t) => t.startsWith("source:")))].sort();
|
|
539
|
+
return [[], ...sources.map((s) => [s])];
|
|
540
|
+
}
|
|
393
541
|
var DEFAULT_OBSERVATION_SCOPES = "shared";
|
|
394
542
|
var MIN_IDEMPOTENT_RETAIN_VERSION = "0.8.6";
|
|
395
543
|
var RateLimitedError = class extends Error {
|
|
@@ -420,7 +568,6 @@ var DEFAULT_MAX_PARALLEL_RETAINS = 10;
|
|
|
420
568
|
var POLL_CYCLE_MS = 5e3;
|
|
421
569
|
var RETRY_AFTER_FLOOR_MS = 10 * 1e3;
|
|
422
570
|
var RETRY_AFTER_CEILING_MS = 60 * 1e3;
|
|
423
|
-
var MISSION_FIELDS = ["reflect_mission", "retain_mission", "observations_mission"];
|
|
424
571
|
var HindsightClient = class {
|
|
425
572
|
apiUrl;
|
|
426
573
|
/** The credential the NEXT request will sign with — NOT the one the config file holds. The two
|
|
@@ -526,7 +673,7 @@ var HindsightClient = class {
|
|
|
526
673
|
// Sent on EVERY retain, including the server default `combined`, so the scoping a bank's
|
|
527
674
|
// observations were built under is a property of the write rather than of whichever server
|
|
528
675
|
// version happened to process it. Servers older than 0.4.15 ignore the field.
|
|
529
|
-
observation_scopes: this.observationScopes
|
|
676
|
+
observation_scopes: resolveRetainScopes(tags, this.observationScopes)
|
|
530
677
|
};
|
|
531
678
|
if (opts.timestamp) item.timestamp = opts.timestamp;
|
|
532
679
|
if (opts.metadata) item.metadata = opts.metadata;
|
|
@@ -567,11 +714,11 @@ var HindsightClient = class {
|
|
|
567
714
|
* Set. Powers the incremental git-sync's "what's already ingested?" check — since git commits are stored
|
|
568
715
|
* with document_id `git:<sha>`, the returned Set lets a caller diff a ref's commits against memory.
|
|
569
716
|
*/
|
|
570
|
-
async listDocumentIds(tag) {
|
|
717
|
+
async listDocumentIds(tag, tagsMatch = "all") {
|
|
571
718
|
const ids = /* @__PURE__ */ new Set();
|
|
572
719
|
const limit = 500;
|
|
573
720
|
for (let offset = 0; ; offset += limit) {
|
|
574
|
-
const q = `?tags=${encodeURIComponent(tag)}&tags_match
|
|
721
|
+
const q = `?tags=${encodeURIComponent(tag)}&tags_match=${tagsMatch}&limit=${limit}&offset=${offset}`;
|
|
575
722
|
const r = await this.req("GET", this.bankUrl(`/documents${q}`));
|
|
576
723
|
let items = [];
|
|
577
724
|
let total = 0;
|
|
@@ -587,49 +734,54 @@ var HindsightClient = class {
|
|
|
587
734
|
}
|
|
588
735
|
return ids;
|
|
589
736
|
}
|
|
590
|
-
/** Configure the bank: POST the coding bank
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
*
|
|
737
|
+
/** Configure the bank: POST the coding bank manifest to /import (missions, retain strategies,
|
|
738
|
+
* entity labels), then seed knowledge pages when the server supports them. Both halves are
|
|
739
|
+
* idempotent and strictly ADDITIVE — nothing the bank already says is overwritten (#3927) — so
|
|
740
|
+
* the deepen engine can re-run this every pass. Creates the bank if missing; legacy servers
|
|
741
|
+
* continue with the template-only path.
|
|
742
|
+
*
|
|
743
|
+
* `manage: false` skips the config half entirely, for a bank whose owner shapes it themselves.
|
|
744
|
+
* That bank should then define the strategies this plugin writes under (`git`, `gitlog`,
|
|
745
|
+
* `conversation`, `document`, `survey`): an unknown strategy name is not an error server-side,
|
|
746
|
+
* it just falls back to the bank's own config, so the miss is silent. */
|
|
594
747
|
async configureBank(opts = {}) {
|
|
595
748
|
if (opts.reset) {
|
|
596
749
|
await this.req("DELETE", this.bankUrl());
|
|
597
750
|
this.log(`[bank] reset ${this.bank}`);
|
|
598
751
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
this.
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
752
|
+
if (opts.manage === false) {
|
|
753
|
+
this.log(`[bank] manageBankConfig: false \u2014 leaving ${this.bank}'s configuration alone`);
|
|
754
|
+
} else {
|
|
755
|
+
const manifest = codingBankManifest(opts.reset ? void 0 : await this.readBankOverrides());
|
|
756
|
+
if (!manifest) {
|
|
757
|
+
this.log(`[bank] ${this.bank} already carries the coding structure \u2014 nothing to apply`);
|
|
758
|
+
} else {
|
|
759
|
+
await this.req("POST", this.bankUrl("/import"), manifest);
|
|
760
|
+
this.log(`[bank] applied to ${this.bank}: ${Object.keys(manifest.bank).sort().join(", ")}`);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
608
763
|
await this.seedPages(opts.pageTrigger);
|
|
609
764
|
}
|
|
610
765
|
/**
|
|
611
|
-
*
|
|
612
|
-
* the user's own edit. Either way they are not ours to overwrite.
|
|
766
|
+
* This bank's own config OVERRIDES, or undefined when there are none to read.
|
|
613
767
|
*
|
|
614
|
-
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
617
|
-
*
|
|
768
|
+
* Deliberately the overrides and not the resolved config: an inherited global default is not
|
|
769
|
+
* something this bank's owner chose, so it must not read as "already set". `undefined` means the
|
|
770
|
+
* bank does not exist yet, or the deployment has the bank-config API switched off — in neither
|
|
771
|
+
* case can anything have been customised, so the caller seeds the full template.
|
|
618
772
|
*/
|
|
619
|
-
async
|
|
773
|
+
async readBankOverrides() {
|
|
620
774
|
try {
|
|
621
775
|
const r = await this.req("GET", this.bankUrl("/config"));
|
|
622
|
-
if (!r.ok) return
|
|
776
|
+
if (!r.ok) return void 0;
|
|
623
777
|
const j = await r.json();
|
|
624
|
-
return
|
|
625
|
-
const v = j.overrides?.[f];
|
|
626
|
-
return typeof v === "string" && v.trim() !== "";
|
|
627
|
-
});
|
|
778
|
+
return j.overrides ?? {};
|
|
628
779
|
} catch {
|
|
629
|
-
return
|
|
780
|
+
return void 0;
|
|
630
781
|
}
|
|
631
782
|
}
|
|
632
|
-
/**
|
|
783
|
+
/** Explicitly delete one document (and its cascaded memory units/links). Background sync must
|
|
784
|
+
* never use this as a cleanup primitive: a document id alone does not prove repository ownership. */
|
|
633
785
|
async deleteDocument(documentId) {
|
|
634
786
|
await this.req("DELETE", this.bankUrl(`/documents/${encodeURIComponent(documentId)}`));
|
|
635
787
|
}
|
|
@@ -930,7 +1082,7 @@ var HindsightClient = class {
|
|
|
930
1082
|
};
|
|
931
1083
|
|
|
932
1084
|
// src/core/config.ts
|
|
933
|
-
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG ||
|
|
1085
|
+
var CONFIG_PATH = process.env.HINDSIGHT_CONFIG || join6(homedir2(), ".hindsight", "coding-agent.json");
|
|
934
1086
|
var DEFAULT_DAEMON_PORT = 9077;
|
|
935
1087
|
var DEFAULT_DAEMON_PROFILE = "coding-agent";
|
|
936
1088
|
function resolvePageTriggerType(raw) {
|
|
@@ -954,7 +1106,13 @@ function resolveReflectBudget(raw) {
|
|
|
954
1106
|
log.warn("config", `ignoring reflectBudget=${JSON.stringify(value)} \u2014 expected low|mid|high`);
|
|
955
1107
|
return "high";
|
|
956
1108
|
}
|
|
957
|
-
var OBSERVATION_SCOPE_MODES = [
|
|
1109
|
+
var OBSERVATION_SCOPE_MODES = [
|
|
1110
|
+
"shared",
|
|
1111
|
+
"combined",
|
|
1112
|
+
"per_tag",
|
|
1113
|
+
"all_combinations",
|
|
1114
|
+
"per_source"
|
|
1115
|
+
];
|
|
958
1116
|
function resolveObservationScopes(raw) {
|
|
959
1117
|
const value = raw;
|
|
960
1118
|
if (typeof value === "string")
|
|
@@ -992,6 +1150,7 @@ function resolveConfig(raw = {}) {
|
|
|
992
1150
|
disabled: raw.disabled ?? false,
|
|
993
1151
|
retainSessions: raw.retainSessions ?? true,
|
|
994
1152
|
// write sessions back by default, every harness
|
|
1153
|
+
manageBankConfig: raw.manageBankConfig ?? true,
|
|
995
1154
|
maxParallelRetains: raw.maxParallelRetains || 10,
|
|
996
1155
|
reflectTimeoutMs: raw.reflectTimeoutMs || 12e4,
|
|
997
1156
|
// Inherit an explicitly-raised reflectTimeoutMs (that is what users reaching for a longer
|
|
@@ -1018,12 +1177,13 @@ function resolveConfig(raw = {}) {
|
|
|
1018
1177
|
) : {},
|
|
1019
1178
|
observationScopes: resolveObservationScopes(raw.observationScopes),
|
|
1020
1179
|
banks: raw.banks && typeof raw.banks === "object" ? raw.banks : {},
|
|
1021
|
-
logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info"
|
|
1180
|
+
logLevel: ["debug", "info", "warn", "error"].includes(raw.logLevel) ? raw.logLevel : "info",
|
|
1181
|
+
autoUpdate: raw.autoUpdate ?? true
|
|
1022
1182
|
};
|
|
1023
1183
|
}
|
|
1024
1184
|
function readRaw(path) {
|
|
1025
1185
|
try {
|
|
1026
|
-
return JSON.parse(
|
|
1186
|
+
return JSON.parse(readFileSync2(path, "utf8"));
|
|
1027
1187
|
} catch (e) {
|
|
1028
1188
|
if (e?.code !== "ENOENT") {
|
|
1029
1189
|
console.error(`hindsight: ignoring invalid config at ${path}: ${e?.message || e}`);
|
|
@@ -1076,13 +1236,15 @@ var ENV_KEYS = {
|
|
|
1076
1236
|
surveyBudgetUsd: "HINDSIGHT_SURVEY_BUDGET_USD",
|
|
1077
1237
|
surveyRefreshCommits: "HINDSIGHT_SURVEY_REFRESH_COMMITS",
|
|
1078
1238
|
logLevel: "HINDSIGHT_LOG_LEVEL",
|
|
1239
|
+
autoUpdate: "HINDSIGHT_AUTO_UPDATE",
|
|
1079
1240
|
gitIngest: "HINDSIGHT_GIT_INGEST",
|
|
1080
1241
|
// Scalar modes only ("shared", "combined", "per_tag", "all_combinations"). An explicit scope
|
|
1081
1242
|
// list is a list OF lists, which does not survive flattening into one variable — file-only.
|
|
1082
1243
|
observationScopes: "HINDSIGHT_OBSERVATION_SCOPES",
|
|
1083
1244
|
// Comma-separated, e.g. HINDSIGHT_RETAIN_TAGS="project:{gitProject},env:work". A LIST rather than
|
|
1084
1245
|
// a map, so it flattens cleanly; its sibling retainMetadata stays file-only for the reason above.
|
|
1085
|
-
retainTags: "HINDSIGHT_RETAIN_TAGS"
|
|
1246
|
+
retainTags: "HINDSIGHT_RETAIN_TAGS",
|
|
1247
|
+
manageBankConfig: "HINDSIGHT_MANAGE_BANK_CONFIG"
|
|
1086
1248
|
};
|
|
1087
1249
|
var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
1088
1250
|
"dynamicBankId",
|
|
@@ -1092,7 +1254,9 @@ var ENV_BOOLEANS = /* @__PURE__ */ new Set([
|
|
|
1092
1254
|
"retainSessions",
|
|
1093
1255
|
"autoReflect",
|
|
1094
1256
|
"autoSeed",
|
|
1095
|
-
"codebaseSurvey"
|
|
1257
|
+
"codebaseSurvey",
|
|
1258
|
+
"autoUpdate",
|
|
1259
|
+
"manageBankConfig"
|
|
1096
1260
|
]);
|
|
1097
1261
|
var ENV_LISTS = /* @__PURE__ */ new Set(["retainTags", "optInPaths"]);
|
|
1098
1262
|
var ENV_NUMBERS = /* @__PURE__ */ new Set([
|
|
@@ -1167,28 +1331,12 @@ function resolvePartial(cfg, patch) {
|
|
|
1167
1331
|
return out;
|
|
1168
1332
|
}
|
|
1169
1333
|
|
|
1170
|
-
// src/core/diag.ts
|
|
1171
|
-
import { appendFileSync as appendFileSync2 } from "fs";
|
|
1172
|
-
function diagFilePath() {
|
|
1173
|
-
return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
|
|
1174
|
-
}
|
|
1175
|
-
function diag(harness, event, extra = {}) {
|
|
1176
|
-
log.debug(harness, `diag:${event}`, extra);
|
|
1177
|
-
try {
|
|
1178
|
-
appendFileSync2(
|
|
1179
|
-
diagFilePath(),
|
|
1180
|
-
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
1181
|
-
);
|
|
1182
|
-
} catch {
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
|
|
1186
1334
|
// src/core/session-cache.ts
|
|
1187
|
-
import { mkdirSync as mkdirSync2, readFileSync as
|
|
1335
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync, rmSync, writeFileSync } from "fs";
|
|
1188
1336
|
import { tmpdir as tmpdir2 } from "os";
|
|
1189
|
-
import { dirname as
|
|
1337
|
+
import { dirname as dirname5, join as join7 } from "path";
|
|
1190
1338
|
function writeFileAtomic(path, body) {
|
|
1191
|
-
mkdirSync2(
|
|
1339
|
+
mkdirSync2(dirname5(path), { recursive: true });
|
|
1192
1340
|
const tmp = `${path}.${process.pid}.tmp`;
|
|
1193
1341
|
try {
|
|
1194
1342
|
writeFileSync(tmp, body);
|
|
@@ -1202,13 +1350,13 @@ function writeFileAtomic(path, body) {
|
|
|
1202
1350
|
}
|
|
1203
1351
|
}
|
|
1204
1352
|
function sessionRootFile(harness, sessionId) {
|
|
1205
|
-
return
|
|
1353
|
+
return join7(tmpdir2(), `hindsight-${harness}`, `${sessionId}.root`);
|
|
1206
1354
|
}
|
|
1207
1355
|
function sessionRootDir(harness, sessionId, cwd) {
|
|
1208
1356
|
if (!sessionId || !cwd) return cwd;
|
|
1209
1357
|
const file = sessionRootFile(harness, sessionId);
|
|
1210
1358
|
try {
|
|
1211
|
-
const recorded =
|
|
1359
|
+
const recorded = readFileSync3(file, "utf8").trim();
|
|
1212
1360
|
if (recorded) return recorded;
|
|
1213
1361
|
} catch {
|
|
1214
1362
|
}
|
|
@@ -1219,13 +1367,13 @@ function sessionRootDir(harness, sessionId, cwd) {
|
|
|
1219
1367
|
return cwd;
|
|
1220
1368
|
}
|
|
1221
1369
|
function cursorFile(harness, sessionId) {
|
|
1222
|
-
return
|
|
1370
|
+
return join7(tmpdir2(), `hindsight-${harness}`, `${sessionId}.retain.json`);
|
|
1223
1371
|
}
|
|
1224
1372
|
function fileCursorStore(harness) {
|
|
1225
1373
|
return {
|
|
1226
1374
|
read: (sessionId) => {
|
|
1227
1375
|
try {
|
|
1228
|
-
return JSON.parse(
|
|
1376
|
+
return JSON.parse(readFileSync3(cursorFile(harness, sessionId), "utf8"));
|
|
1229
1377
|
} catch {
|
|
1230
1378
|
return void 0;
|
|
1231
1379
|
}
|
|
@@ -1240,7 +1388,7 @@ function fileCursorStore(harness) {
|
|
|
1240
1388
|
}
|
|
1241
1389
|
|
|
1242
1390
|
// src/core/retain-hook.ts
|
|
1243
|
-
import { readFileSync as
|
|
1391
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
1244
1392
|
|
|
1245
1393
|
// src/core/retain-cursor.ts
|
|
1246
1394
|
import { createHash } from "crypto";
|
|
@@ -1401,8 +1549,8 @@ ${content}`),
|
|
|
1401
1549
|
}
|
|
1402
1550
|
|
|
1403
1551
|
// src/core/daemon.ts
|
|
1404
|
-
import { execFileSync
|
|
1405
|
-
import { dirname as
|
|
1552
|
+
import { execFileSync, spawn as realSpawn2 } from "child_process";
|
|
1553
|
+
import { dirname as dirname6, join as join8 } from "path";
|
|
1406
1554
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
1407
1555
|
var DAEMON_WAIT_RETAIN_MS = 4e4;
|
|
1408
1556
|
async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
|
|
@@ -1416,7 +1564,7 @@ async function isServerHealthy(baseUrl, timeoutMs = 2e3) {
|
|
|
1416
1564
|
function hasRustToolchain() {
|
|
1417
1565
|
if (process.platform !== "darwin") return true;
|
|
1418
1566
|
try {
|
|
1419
|
-
|
|
1567
|
+
execFileSync("cargo", ["--version"], {
|
|
1420
1568
|
stdio: "pipe",
|
|
1421
1569
|
timeout: 1e4,
|
|
1422
1570
|
windowsHide: true
|
|
@@ -1428,7 +1576,7 @@ function hasRustToolchain() {
|
|
|
1428
1576
|
}
|
|
1429
1577
|
function hasUvx() {
|
|
1430
1578
|
try {
|
|
1431
|
-
|
|
1579
|
+
execFileSync("uvx", ["--version"], {
|
|
1432
1580
|
stdio: "pipe",
|
|
1433
1581
|
timeout: 1e4,
|
|
1434
1582
|
windowsHide: true
|
|
@@ -1464,7 +1612,7 @@ function detectLlm(env = process.env) {
|
|
|
1464
1612
|
}
|
|
1465
1613
|
function onPath(bin) {
|
|
1466
1614
|
try {
|
|
1467
|
-
|
|
1615
|
+
execFileSync("which", [bin], {
|
|
1468
1616
|
stdio: "pipe",
|
|
1469
1617
|
timeout: 5e3,
|
|
1470
1618
|
windowsHide: true
|
|
@@ -1476,7 +1624,7 @@ function onPath(bin) {
|
|
|
1476
1624
|
}
|
|
1477
1625
|
function startDaemonDetached(cfg, harness, spawnFn = realSpawn2) {
|
|
1478
1626
|
try {
|
|
1479
|
-
const starter =
|
|
1627
|
+
const starter = join8(dirname6(fileURLToPath2(import.meta.url)), "daemon-start.js");
|
|
1480
1628
|
const child = spawnFn("node", [starter, "--harness", harness], {
|
|
1481
1629
|
detached: true,
|
|
1482
1630
|
stdio: "ignore",
|
|
@@ -1553,12 +1701,12 @@ function buildRetainStamp(cfg, ctx) {
|
|
|
1553
1701
|
const base = resolversFor(ctx);
|
|
1554
1702
|
const cache = /* @__PURE__ */ new Map();
|
|
1555
1703
|
const resolvers = Object.fromEntries(
|
|
1556
|
-
Object.entries(base).map(([name,
|
|
1704
|
+
Object.entries(base).map(([name, resolve3]) => [
|
|
1557
1705
|
name,
|
|
1558
1706
|
() => {
|
|
1559
1707
|
const hit = cache.get(name);
|
|
1560
1708
|
if (hit !== void 0) return hit;
|
|
1561
|
-
const value =
|
|
1709
|
+
const value = resolve3();
|
|
1562
1710
|
cache.set(name, value);
|
|
1563
1711
|
return value;
|
|
1564
1712
|
}
|
|
@@ -1729,6 +1877,15 @@ async function buildRetain(args) {
|
|
|
1729
1877
|
const { harness, sessionId, transcriptPath, client } = args;
|
|
1730
1878
|
const readTranscript = args.readTranscript ?? readClaudeTranscript;
|
|
1731
1879
|
const turns = readTranscript(transcriptPath);
|
|
1880
|
+
const decoded = args.lastAssistantMessage ? (args.readLastMessage ?? ((raw) => raw))(args.lastAssistantMessage) : "";
|
|
1881
|
+
const lastAssistantMessage = stripInjectedMemory(decoded).trim();
|
|
1882
|
+
if (lastAssistantMessage && turns.at(-1)?.content !== lastAssistantMessage) {
|
|
1883
|
+
turns.push({
|
|
1884
|
+
role: "assistant",
|
|
1885
|
+
content: lastAssistantMessage,
|
|
1886
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1887
|
+
});
|
|
1888
|
+
}
|
|
1732
1889
|
if (turns.length === 0) return;
|
|
1733
1890
|
const startTs = turns[0]?.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
1734
1891
|
const t0 = Date.now();
|
|
@@ -1755,20 +1912,22 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1755
1912
|
const hostDeadline = Date.now() + spec.hostTimeoutSec * 1e3 - HOST_DEADLINE_MARGIN_MS;
|
|
1756
1913
|
let ev = {};
|
|
1757
1914
|
try {
|
|
1758
|
-
ev = JSON.parse(
|
|
1915
|
+
ev = JSON.parse(readFileSync5(0, "utf8"));
|
|
1759
1916
|
} catch {
|
|
1760
1917
|
return;
|
|
1761
1918
|
}
|
|
1762
|
-
const { sessionId, transcriptPath, cwd: rawCwd } = spec.parse(ev);
|
|
1919
|
+
const { sessionId, transcriptPath, cwd: rawCwd, lastAssistantMessage } = spec.parse(ev);
|
|
1763
1920
|
const cwd = rawCwd || process.cwd();
|
|
1764
1921
|
let cfg = loadConfig({ harness: spec.harness });
|
|
1765
1922
|
setLogLevel(cfg.logLevel);
|
|
1766
1923
|
if (cfg.disabled) return;
|
|
1767
1924
|
if (!transcriptPath) return;
|
|
1768
1925
|
const sessionRoot = sessionRootDir(spec.harness, sessionId, cwd);
|
|
1769
|
-
const
|
|
1770
|
-
|
|
1771
|
-
const
|
|
1926
|
+
const derived = deriveBankIdOrSkip(cfg, cwd, spec.harness, sessionRoot);
|
|
1927
|
+
if (derived === null) return;
|
|
1928
|
+
const resolved2 = applyBankConfig(cfg, derived, cwd);
|
|
1929
|
+
cfg = resolved2.cfg;
|
|
1930
|
+
const bankId = resolved2.bankId;
|
|
1772
1931
|
if (cfg.disabled) return;
|
|
1773
1932
|
if (!cfg.retainSessions) {
|
|
1774
1933
|
diag(spec.harness, "retain_disabled", { bank: bankId, session: sessionId });
|
|
@@ -1788,6 +1947,8 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1788
1947
|
transcriptPath,
|
|
1789
1948
|
client,
|
|
1790
1949
|
readTranscript: spec.readTranscript,
|
|
1950
|
+
lastAssistantMessage,
|
|
1951
|
+
readLastMessage: spec.readLastMessage,
|
|
1791
1952
|
retryUntil: hostDeadline,
|
|
1792
1953
|
stamp: buildRetainStamp(cfg, {
|
|
1793
1954
|
directory: cwd,
|
|
@@ -1800,27 +1961,43 @@ async function runRetainHook(spec, makeClient = (o) => new HindsightClient(o)) {
|
|
|
1800
1961
|
}
|
|
1801
1962
|
|
|
1802
1963
|
// src/core/session-start.ts
|
|
1803
|
-
import { readFileSync as
|
|
1964
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
1804
1965
|
|
|
1805
1966
|
// src/core/git.ts
|
|
1806
|
-
import { execFileSync as
|
|
1807
|
-
import { resolve } from "path";
|
|
1967
|
+
import { execFileSync as execFileSync2 } from "child_process";
|
|
1968
|
+
import { resolve as resolve2 } from "path";
|
|
1808
1969
|
|
|
1809
1970
|
// src/core/status.ts
|
|
1810
|
-
import { execFileSync as
|
|
1971
|
+
import { execFileSync as execFileSync3 } from "child_process";
|
|
1811
1972
|
|
|
1812
1973
|
// src/core/survey.ts
|
|
1813
1974
|
import { spawn as realSpawn3 } from "child_process";
|
|
1814
|
-
import {
|
|
1975
|
+
import { existsSync as existsSync3 } from "fs";
|
|
1815
1976
|
import { homedir as homedir3 } from "os";
|
|
1816
|
-
import {
|
|
1977
|
+
import { dirname as dirname7, join as join9 } from "path";
|
|
1817
1978
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1818
1979
|
|
|
1819
|
-
// src/core/
|
|
1820
|
-
import {
|
|
1821
|
-
import {
|
|
1822
|
-
|
|
1980
|
+
// src/core/auto-update.ts
|
|
1981
|
+
import { spawn as realSpawn4 } from "child_process";
|
|
1982
|
+
import {
|
|
1983
|
+
existsSync as existsSync4,
|
|
1984
|
+
mkdirSync as mkdirSync3,
|
|
1985
|
+
readFileSync as readFileSync6,
|
|
1986
|
+
realpathSync as realpathSync2,
|
|
1987
|
+
unlinkSync,
|
|
1988
|
+
writeFileSync as writeFileSync2
|
|
1989
|
+
} from "fs";
|
|
1990
|
+
import { homedir as homedir4, tmpdir as tmpdir3 } from "os";
|
|
1991
|
+
import { dirname as dirname8, join as join10 } from "path";
|
|
1823
1992
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
1993
|
+
var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
1994
|
+
var LOCK_STALE_MS = 10 * 60 * 1e3;
|
|
1995
|
+
|
|
1996
|
+
// src/core/skill-sync.ts
|
|
1997
|
+
import { cpSync, existsSync as existsSync5, readFileSync as readFileSync7 } from "fs";
|
|
1998
|
+
import { homedir as homedir5 } from "os";
|
|
1999
|
+
import { dirname as dirname9, join as join11 } from "path";
|
|
2000
|
+
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
1824
2001
|
|
|
1825
2002
|
// src/core/transcript-codex.ts
|
|
1826
2003
|
function isSyntheticUserText(text) {
|
|
@@ -1952,19 +2129,19 @@ function readCopilotTranscript(path) {
|
|
|
1952
2129
|
}
|
|
1953
2130
|
|
|
1954
2131
|
// src/core/transcript-grok.ts
|
|
1955
|
-
import { existsSync as
|
|
1956
|
-
import { homedir as
|
|
1957
|
-
import { join as
|
|
2132
|
+
import { existsSync as existsSync6, readFileSync as readFileSync9, readdirSync } from "fs";
|
|
2133
|
+
import { homedir as homedir6 } from "os";
|
|
2134
|
+
import { join as join12 } from "path";
|
|
1958
2135
|
var CHAT_HISTORY = "chat_history.jsonl";
|
|
1959
|
-
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME ||
|
|
1960
|
-
const sessionsDir =
|
|
1961
|
-
const direct =
|
|
1962
|
-
if (
|
|
2136
|
+
function grokTranscriptPath(cwd, sessionId, grokHome = process.env.GROK_HOME || join12(homedir6(), ".grok")) {
|
|
2137
|
+
const sessionsDir = join12(grokHome, "sessions");
|
|
2138
|
+
const direct = join12(sessionsDir, encodeURIComponent(cwd), sessionId, CHAT_HISTORY);
|
|
2139
|
+
if (existsSync6(direct)) return direct;
|
|
1963
2140
|
try {
|
|
1964
2141
|
for (const candidate of readdirSync(sessionsDir)) {
|
|
1965
|
-
const directory =
|
|
1966
|
-
if (
|
|
1967
|
-
return
|
|
2142
|
+
const directory = join12(sessionsDir, candidate);
|
|
2143
|
+
if (readFileSync9(join12(directory, ".cwd"), "utf8").trim() === cwd) {
|
|
2144
|
+
return join12(directory, sessionId, CHAT_HISTORY);
|
|
1968
2145
|
}
|
|
1969
2146
|
}
|
|
1970
2147
|
} catch {
|
|
@@ -1999,12 +2176,12 @@ function readGrokTranscript(path) {
|
|
|
1999
2176
|
}
|
|
2000
2177
|
|
|
2001
2178
|
// src/core/transcript-devin.ts
|
|
2002
|
-
import { existsSync as
|
|
2179
|
+
import { existsSync as existsSync7 } from "fs";
|
|
2003
2180
|
import { createRequire } from "module";
|
|
2004
|
-
import { homedir as
|
|
2005
|
-
import { join as
|
|
2006
|
-
function devinSessionDb(home =
|
|
2007
|
-
return
|
|
2181
|
+
import { homedir as homedir7 } from "os";
|
|
2182
|
+
import { join as join13 } from "path";
|
|
2183
|
+
function devinSessionDb(home = homedir7()) {
|
|
2184
|
+
return join13(home, ".local", "share", "devin", "cli", "sessions.db");
|
|
2008
2185
|
}
|
|
2009
2186
|
function parseDevinMessages(nodes) {
|
|
2010
2187
|
const messages = /* @__PURE__ */ new Map();
|
|
@@ -2041,7 +2218,7 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
|
|
|
2041
2218
|
diag("devin-cli", "sqlite_unavailable", { node: process.version, dbPath });
|
|
2042
2219
|
return [];
|
|
2043
2220
|
}
|
|
2044
|
-
if (!
|
|
2221
|
+
if (!existsSync7(dbPath)) {
|
|
2045
2222
|
diag("devin-cli", "session_db_missing", { dbPath });
|
|
2046
2223
|
return [];
|
|
2047
2224
|
}
|
|
@@ -2063,6 +2240,212 @@ function readDevinTranscript(sessionId, dbPath = devinSessionDb()) {
|
|
|
2063
2240
|
}
|
|
2064
2241
|
}
|
|
2065
2242
|
|
|
2243
|
+
// src/core/transcript-dcode.ts
|
|
2244
|
+
var BLOCK_JOIN = "\n";
|
|
2245
|
+
function contentText(content) {
|
|
2246
|
+
if (typeof content === "string") return content;
|
|
2247
|
+
if (!Array.isArray(content)) return "";
|
|
2248
|
+
return content.flatMap((block) => {
|
|
2249
|
+
if (typeof block === "string") return [block];
|
|
2250
|
+
if (!block || typeof block !== "object") return [];
|
|
2251
|
+
const text = block.text;
|
|
2252
|
+
return typeof text === "string" ? [text] : [];
|
|
2253
|
+
}).join(BLOCK_JOIN);
|
|
2254
|
+
}
|
|
2255
|
+
function readPyValue(s, i) {
|
|
2256
|
+
const skip = (j) => {
|
|
2257
|
+
while (j < s.length && /\s/.test(s[j])) j++;
|
|
2258
|
+
return j;
|
|
2259
|
+
};
|
|
2260
|
+
i = skip(i);
|
|
2261
|
+
if (i >= s.length) return null;
|
|
2262
|
+
const c = s[i];
|
|
2263
|
+
if (c === "'" || c === '"') {
|
|
2264
|
+
let out = "";
|
|
2265
|
+
let j = i + 1;
|
|
2266
|
+
while (j < s.length) {
|
|
2267
|
+
const ch = s[j];
|
|
2268
|
+
if (ch === "\\") {
|
|
2269
|
+
const esc = s[j + 1];
|
|
2270
|
+
if (esc === void 0) return null;
|
|
2271
|
+
if (esc === "n") out += "\n";
|
|
2272
|
+
else if (esc === "t") out += " ";
|
|
2273
|
+
else if (esc === "r") out += "\r";
|
|
2274
|
+
else if (esc === "x") {
|
|
2275
|
+
const hex = s.slice(j + 2, j + 4);
|
|
2276
|
+
if (!/^[0-9a-fA-F]{2}$/.test(hex)) return null;
|
|
2277
|
+
out += String.fromCharCode(parseInt(hex, 16));
|
|
2278
|
+
j += 4;
|
|
2279
|
+
continue;
|
|
2280
|
+
} else if (esc === "u") {
|
|
2281
|
+
const hex = s.slice(j + 2, j + 6);
|
|
2282
|
+
if (!/^[0-9a-fA-F]{4}$/.test(hex)) return null;
|
|
2283
|
+
out += String.fromCharCode(parseInt(hex, 16));
|
|
2284
|
+
j += 6;
|
|
2285
|
+
continue;
|
|
2286
|
+
} else out += esc;
|
|
2287
|
+
j += 2;
|
|
2288
|
+
continue;
|
|
2289
|
+
}
|
|
2290
|
+
if (ch === c) return { value: out, end: j + 1 };
|
|
2291
|
+
out += ch;
|
|
2292
|
+
j++;
|
|
2293
|
+
}
|
|
2294
|
+
return null;
|
|
2295
|
+
}
|
|
2296
|
+
if (s.startsWith("True", i)) return { value: true, end: i + 4 };
|
|
2297
|
+
if (s.startsWith("False", i)) return { value: false, end: i + 5 };
|
|
2298
|
+
if (s.startsWith("None", i)) return { value: null, end: i + 4 };
|
|
2299
|
+
if (c === "[" || c === "{") {
|
|
2300
|
+
const isList = c === "[";
|
|
2301
|
+
const close = isList ? "]" : "}";
|
|
2302
|
+
const list = [];
|
|
2303
|
+
const obj = {};
|
|
2304
|
+
let j = skip(i + 1);
|
|
2305
|
+
if (s[j] === close) return { value: isList ? list : obj, end: j + 1 };
|
|
2306
|
+
for (; ; ) {
|
|
2307
|
+
const key = readPyValue(s, j);
|
|
2308
|
+
if (!key) return null;
|
|
2309
|
+
j = skip(key.end);
|
|
2310
|
+
if (isList) {
|
|
2311
|
+
list.push(key.value);
|
|
2312
|
+
} else {
|
|
2313
|
+
if (s[j] !== ":" || typeof key.value !== "string") return null;
|
|
2314
|
+
const val = readPyValue(s, j + 1);
|
|
2315
|
+
if (!val) return null;
|
|
2316
|
+
obj[key.value] = val.value;
|
|
2317
|
+
j = skip(val.end);
|
|
2318
|
+
}
|
|
2319
|
+
if (s[j] === ",") {
|
|
2320
|
+
j = skip(j + 1);
|
|
2321
|
+
if (s[j] === close) return { value: isList ? list : obj, end: j + 1 };
|
|
2322
|
+
continue;
|
|
2323
|
+
}
|
|
2324
|
+
if (s[j] === close) return { value: isList ? list : obj, end: j + 1 };
|
|
2325
|
+
return null;
|
|
2326
|
+
}
|
|
2327
|
+
}
|
|
2328
|
+
const num = /^-?\d+(\.\d+)?([eE][-+]?\d+)?/.exec(s.slice(i));
|
|
2329
|
+
if (num) return { value: Number(num[0]), end: i + num[0].length };
|
|
2330
|
+
return null;
|
|
2331
|
+
}
|
|
2332
|
+
function dcodeAssistantText(raw) {
|
|
2333
|
+
const trimmed = raw.trim();
|
|
2334
|
+
if (!trimmed.startsWith("[{") && !trimmed.startsWith("[ {")) return raw;
|
|
2335
|
+
const parsed = readPyValue(trimmed, 0);
|
|
2336
|
+
if (!parsed || readPyValue(trimmed, parsed.end) !== null) return "";
|
|
2337
|
+
if (!Array.isArray(parsed.value)) return "";
|
|
2338
|
+
return contentText(parsed.value);
|
|
2339
|
+
}
|
|
2340
|
+
function readDcodeTranscript(path) {
|
|
2341
|
+
const turns = [];
|
|
2342
|
+
for (const rawLine of readJsonlTail(path, { scope: "dcode" }).lines) {
|
|
2343
|
+
if (!rawLine.trim()) continue;
|
|
2344
|
+
let parsed;
|
|
2345
|
+
try {
|
|
2346
|
+
parsed = JSON.parse(rawLine);
|
|
2347
|
+
} catch {
|
|
2348
|
+
continue;
|
|
2349
|
+
}
|
|
2350
|
+
if (!parsed || typeof parsed !== "object") continue;
|
|
2351
|
+
const record = parsed;
|
|
2352
|
+
if (record.schema_version !== 1) continue;
|
|
2353
|
+
const role = record.role;
|
|
2354
|
+
const stamp = typeof record.timestamp === "string" && record.timestamp ? { timestamp: record.timestamp } : {};
|
|
2355
|
+
if (role === "user" || role === "assistant") {
|
|
2356
|
+
const text = stripInjectedMemory(contentText(record.content)).trim();
|
|
2357
|
+
if (text) turns.push({ role, content: text, ...stamp });
|
|
2358
|
+
} else if (role === "tool" && typeof record.name === "string" && record.name.trim()) {
|
|
2359
|
+
turns.push({ role: "action", content: actionLine(record.name, record.content), ...stamp });
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
return turns;
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
// src/core/transcript-qwen.ts
|
|
2366
|
+
var HOOK_CONTEXT_PART_RE = /^\s*<qwen:user-prompt-submit-context>[\s\S]*<\/qwen:user-prompt-submit-context>\s*$/;
|
|
2367
|
+
function isWholeHookContextPart(part) {
|
|
2368
|
+
return typeof part.text === "string" && HOOK_CONTEXT_PART_RE.test(part.text);
|
|
2369
|
+
}
|
|
2370
|
+
function isRealUser(line) {
|
|
2371
|
+
if (typeof line.provenance === "string") return line.provenance === "real_user";
|
|
2372
|
+
if (line.provenance !== void 0) return false;
|
|
2373
|
+
const isSubagentEnvelope = line.agentId !== void 0 || line.isSidechain !== void 0;
|
|
2374
|
+
if (!isSubagentEnvelope) return false;
|
|
2375
|
+
return line.subtype === void 0 || line.subtype === "mid_turn_user_message";
|
|
2376
|
+
}
|
|
2377
|
+
function renderLine2(parts, type) {
|
|
2378
|
+
if (!Array.isArray(parts)) return [];
|
|
2379
|
+
const last = parts.length > 1 ? parts[parts.length - 1] : void 0;
|
|
2380
|
+
const dropLast = !!last && typeof last === "object" && isWholeHookContextPart(last) ? parts.length - 1 : -1;
|
|
2381
|
+
const texts = [];
|
|
2382
|
+
const actions = [];
|
|
2383
|
+
for (const [i, part] of parts.entries()) {
|
|
2384
|
+
if (!part || typeof part !== "object") continue;
|
|
2385
|
+
if (i === dropLast) continue;
|
|
2386
|
+
if (part.thought === true) continue;
|
|
2387
|
+
if (typeof part.text === "string") {
|
|
2388
|
+
const text = stripInjectedMemory(part.text).trim();
|
|
2389
|
+
if (text) texts.push(text);
|
|
2390
|
+
} else if (part.functionCall && typeof part.functionCall.name === "string") {
|
|
2391
|
+
actions.push({
|
|
2392
|
+
role: "action",
|
|
2393
|
+
content: actionLine(part.functionCall.name, part.functionCall.args)
|
|
2394
|
+
});
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
const out = [];
|
|
2398
|
+
const joined = texts.join("\n").trim();
|
|
2399
|
+
if (joined) out.push({ role: type, content: joined });
|
|
2400
|
+
out.push(...actions);
|
|
2401
|
+
return out;
|
|
2402
|
+
}
|
|
2403
|
+
function readQwenTranscript(path) {
|
|
2404
|
+
const turns = [];
|
|
2405
|
+
try {
|
|
2406
|
+
collectQwenTurns(path, turns);
|
|
2407
|
+
} catch (err) {
|
|
2408
|
+
log.warn("qwen-code", "transcript read failed \u2014 retaining what was parsed", {
|
|
2409
|
+
path,
|
|
2410
|
+
turns: turns.length,
|
|
2411
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2412
|
+
});
|
|
2413
|
+
}
|
|
2414
|
+
return turns;
|
|
2415
|
+
}
|
|
2416
|
+
function collectQwenTurns(path, turns) {
|
|
2417
|
+
for (const rawLine of readJsonlTail(path, { scope: "qwen-code" }).lines) {
|
|
2418
|
+
const trimmed = rawLine.trim();
|
|
2419
|
+
if (!trimmed) continue;
|
|
2420
|
+
let parsed;
|
|
2421
|
+
try {
|
|
2422
|
+
parsed = JSON.parse(trimmed);
|
|
2423
|
+
} catch {
|
|
2424
|
+
continue;
|
|
2425
|
+
}
|
|
2426
|
+
if (typeof parsed !== "object" || parsed === null) continue;
|
|
2427
|
+
const line = parsed;
|
|
2428
|
+
if (line.type !== "user" && line.type !== "assistant") continue;
|
|
2429
|
+
if (line.type === "user" && !isRealUser(line)) continue;
|
|
2430
|
+
if (typeof line.message !== "object" || line.message === null) continue;
|
|
2431
|
+
const sp = line.systemPayload;
|
|
2432
|
+
if (line.type === "user" && sp && typeof sp === "object" && typeof sp.hookContext === "string" && typeof sp.displayText === "string") {
|
|
2433
|
+
const content = stripInjectedMemory(sp.displayText).trim();
|
|
2434
|
+
if (content) {
|
|
2435
|
+
const turn = { role: "user", content };
|
|
2436
|
+
if (typeof line.timestamp === "string") turn.timestamp = line.timestamp;
|
|
2437
|
+
turns.push(turn);
|
|
2438
|
+
}
|
|
2439
|
+
continue;
|
|
2440
|
+
}
|
|
2441
|
+
for (const rendered of renderLine2(line.message.parts, line.type)) {
|
|
2442
|
+
const turn = { role: rendered.role, content: rendered.content };
|
|
2443
|
+
if (typeof line.timestamp === "string") turn.timestamp = line.timestamp;
|
|
2444
|
+
turns.push(turn);
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2447
|
+
}
|
|
2448
|
+
|
|
2066
2449
|
// src/harness/hook-lifecycle.ts
|
|
2067
2450
|
var cursorCwd = (ev) => ev.cwd ?? ev.workspace_root ?? (Array.isArray(ev.workspace_roots) ? ev.workspace_roots[0] : void 0);
|
|
2068
2451
|
var claudePrompt = {
|
|
@@ -2086,6 +2469,19 @@ var codexPrompt = {
|
|
|
2086
2469
|
sessionId: ev.session_id
|
|
2087
2470
|
})
|
|
2088
2471
|
};
|
|
2472
|
+
var dcodePrompt = {
|
|
2473
|
+
...claudePrompt,
|
|
2474
|
+
harness: "dcode"
|
|
2475
|
+
};
|
|
2476
|
+
var qwenPrompt = {
|
|
2477
|
+
...claudePrompt,
|
|
2478
|
+
harness: "qwen-code",
|
|
2479
|
+
parse: (ev) => ({
|
|
2480
|
+
prompt: ev.submitted_prompt,
|
|
2481
|
+
cwd: ev.cwd,
|
|
2482
|
+
sessionId: ev.session_id
|
|
2483
|
+
})
|
|
2484
|
+
};
|
|
2089
2485
|
var antigravityCwd = (ev) => Array.isArray(ev.workspacePaths) ? ev.workspacePaths[0] : void 0;
|
|
2090
2486
|
var antigravityPrompt = {
|
|
2091
2487
|
harness: "antigravity-cli",
|
|
@@ -2190,6 +2586,28 @@ var HOOK_HARNESSES = {
|
|
|
2190
2586
|
readTranscript: readCodexTranscript
|
|
2191
2587
|
}
|
|
2192
2588
|
},
|
|
2589
|
+
dcode: {
|
|
2590
|
+
configStyle: "nested",
|
|
2591
|
+
install: {
|
|
2592
|
+
sessionStart: { event: "SessionStart", entry: "dcode-sessionstart-hook.js", timeout: 30 },
|
|
2593
|
+
prompt: { event: "UserPromptSubmit", entry: "dcode-hook.js", timeout: 30 },
|
|
2594
|
+
stop: { event: "Stop", entry: "dcode-stop-hook.js", timeout: 60 }
|
|
2595
|
+
},
|
|
2596
|
+
sessionStart: standardSessionStart("dcode"),
|
|
2597
|
+
prompt: dcodePrompt,
|
|
2598
|
+
retain: {
|
|
2599
|
+
hostTimeoutSec: 60,
|
|
2600
|
+
harness: "dcode",
|
|
2601
|
+
parse: (ev) => ({
|
|
2602
|
+
sessionId: ev.session_id,
|
|
2603
|
+
transcriptPath: ev.transcript_path,
|
|
2604
|
+
cwd: ev.cwd,
|
|
2605
|
+
lastAssistantMessage: ev.last_assistant_message
|
|
2606
|
+
}),
|
|
2607
|
+
readTranscript: readDcodeTranscript,
|
|
2608
|
+
readLastMessage: dcodeAssistantText
|
|
2609
|
+
}
|
|
2610
|
+
},
|
|
2193
2611
|
"antigravity-cli": {
|
|
2194
2612
|
configStyle: "flat",
|
|
2195
2613
|
install: {
|
|
@@ -2350,6 +2768,37 @@ var HOOK_HARNESSES = {
|
|
|
2350
2768
|
}),
|
|
2351
2769
|
readTranscript: readGrokTranscript
|
|
2352
2770
|
}
|
|
2771
|
+
},
|
|
2772
|
+
"qwen-code": {
|
|
2773
|
+
configStyle: "nested",
|
|
2774
|
+
timeoutUnit: "milliseconds",
|
|
2775
|
+
// TIMEOUTS ARE MILLISECONDS HERE, not seconds like every other harness in this table: Qwen's
|
|
2776
|
+
// hookRunner does `setTimeout(..., hookConfig.timeout ?? DEFAULT_HOOK_TIMEOUT)` with
|
|
2777
|
+
// DEFAULT_HOOK_TIMEOUT = 60_000 ("Timeout in milliseconds, default 60000"). Writing 30/60
|
|
2778
|
+
// registers 30ms/60ms hooks, which die before a Node process starts — and Qwen spawns hooks
|
|
2779
|
+
// `detached` and terminates the whole process TREE on timeout, so the retain is genuinely lost
|
|
2780
|
+
// rather than merely orphaned. `retain.hostTimeoutSec` below stays SECONDS, as its name says;
|
|
2781
|
+
// these two numbers are the same budget in different units for this harness alone.
|
|
2782
|
+
// The prompt timeout must also stay above core/hook.ts's HOOK_REFLECT_CAP_MS (25_000).
|
|
2783
|
+
install: {
|
|
2784
|
+
sessionStart: { event: "SessionStart", entry: "qwen-sessionstart-hook.js", timeout: 3e4 },
|
|
2785
|
+
prompt: { event: "UserPromptSubmit", entry: "qwen-hook.js", timeout: 3e4 },
|
|
2786
|
+
stop: { event: "Stop", entry: "qwen-stop-hook.js", timeout: 6e4 }
|
|
2787
|
+
},
|
|
2788
|
+
sessionStart: standardSessionStart("qwen-code"),
|
|
2789
|
+
prompt: qwenPrompt,
|
|
2790
|
+
retain: {
|
|
2791
|
+
hostTimeoutSec: 60,
|
|
2792
|
+
harness: "qwen-code",
|
|
2793
|
+
parse: (ev) => ({
|
|
2794
|
+
sessionId: ev.session_id,
|
|
2795
|
+
// Qwen supplies the path, but as the EMPTY STRING (not null, not absent) when chat
|
|
2796
|
+
// recording is off — runRetainHook's `if (!transcriptPath) return` already covers that.
|
|
2797
|
+
transcriptPath: ev.transcript_path,
|
|
2798
|
+
cwd: ev.cwd
|
|
2799
|
+
}),
|
|
2800
|
+
readTranscript: readQwenTranscript
|
|
2801
|
+
}
|
|
2353
2802
|
}
|
|
2354
2803
|
};
|
|
2355
2804
|
var runHarnessRetain = (harness) => runRetainHook(HOOK_HARNESSES[harness].retain);
|