@vectorize-io/hindsight-coding-agents 0.3.2 → 0.3.4
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 +23 -5
- package/cordis.patch.yml +18 -0
- package/dist/antigravity-hook.js +25 -4
- package/dist/antigravity-stop-hook.js +20 -3
- package/dist/claude-hook.js +25 -4
- package/dist/claude-sessionstart-hook.js +6 -2
- package/dist/claude-stop-hook.js +20 -3
- package/dist/cline.js +30 -8
- package/dist/codex-hook.js +25 -4
- package/dist/codex-sessionstart-hook.js +6 -2
- package/dist/codex-stop-hook.js +20 -3
- package/dist/copilot-hook.js +25 -4
- package/dist/copilot-sessionstart-hook.js +6 -2
- package/dist/copilot-stop-hook.js +20 -3
- package/dist/cursor-hook.js +25 -4
- package/dist/cursor-sessionstart-hook.js +6 -2
- package/dist/cursor-stop-hook.js +20 -3
- package/dist/daemon-start.js +4 -1
- package/dist/deepen.js +31 -4
- package/dist/devin-hook.js +25 -4
- package/dist/devin-sessionstart-hook.js +6 -2
- package/dist/devin-stop-hook.js +20 -3
- package/dist/dsh.js +17042 -0
- package/dist/grok-hook.js +25 -4
- package/dist/grok-sessionstart-hook.js +6 -2
- package/dist/grok-stop-hook.js +20 -3
- package/dist/index.js +48 -8
- package/dist/installer.js +193 -2
- package/dist/kilo.js +48 -8
- package/dist/mcp-server.js +47 -33
- package/dist/prime-agent.js +30 -8
- package/package.json +18 -2
package/dist/grok-hook.js
CHANGED
|
@@ -372,13 +372,30 @@ var log = {
|
|
|
372
372
|
warn: (scope, msg, extra) => write("warn", scope, msg, extra),
|
|
373
373
|
error: (scope, msg, extra) => write("error", scope, msg, extra)
|
|
374
374
|
};
|
|
375
|
+
function describeError(value, maxChars = 200) {
|
|
376
|
+
const parts = [];
|
|
377
|
+
const seen = /* @__PURE__ */ new Set();
|
|
378
|
+
let current2 = value;
|
|
379
|
+
while (current2 && !seen.has(current2)) {
|
|
380
|
+
seen.add(current2);
|
|
381
|
+
const error = current2;
|
|
382
|
+
const text = typeof error.message === "string" ? error.message : String(current2);
|
|
383
|
+
const withCode = error.code ? `${text} (${String(error.code)})` : text;
|
|
384
|
+
if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
|
|
385
|
+
current2 = error.cause;
|
|
386
|
+
}
|
|
387
|
+
return (parts.join(": ") || String(value)).slice(0, maxChars);
|
|
388
|
+
}
|
|
375
389
|
|
|
376
390
|
// src/core/diag.ts
|
|
391
|
+
function diagFilePath() {
|
|
392
|
+
return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
|
|
393
|
+
}
|
|
377
394
|
function diag(harness, event, extra = {}) {
|
|
378
395
|
log.debug(harness, `diag:${event}`, extra);
|
|
379
396
|
try {
|
|
380
397
|
appendFileSync2(
|
|
381
|
-
|
|
398
|
+
diagFilePath(),
|
|
382
399
|
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
383
400
|
);
|
|
384
401
|
} catch {
|
|
@@ -1136,6 +1153,7 @@ async function buildHookOutput(args) {
|
|
|
1136
1153
|
const turns = (cached.turns ?? 0) + 1;
|
|
1137
1154
|
let reflectAnswer = cached.reflectAnswer;
|
|
1138
1155
|
let reflectRanThisTurn = false;
|
|
1156
|
+
let reflectFailed = false;
|
|
1139
1157
|
const deferInitialReflect = cached.deferInitialReflect === true;
|
|
1140
1158
|
if (deferInitialReflect) {
|
|
1141
1159
|
diag(harness, "reflect_deferred_new_bank", { query: prompt.slice(0, 80) });
|
|
@@ -1160,12 +1178,13 @@ async function buildHookOutput(args) {
|
|
|
1160
1178
|
});
|
|
1161
1179
|
} catch (e) {
|
|
1162
1180
|
reflectAnswer = "";
|
|
1181
|
+
reflectFailed = true;
|
|
1163
1182
|
log.warn(harness, "reflect failed \u2014 session runs without memory", {
|
|
1164
|
-
error:
|
|
1183
|
+
error: describeError(e)
|
|
1165
1184
|
});
|
|
1166
1185
|
diag(harness, "reflect_failed", {
|
|
1167
1186
|
ms: Date.now() - t0,
|
|
1168
|
-
error:
|
|
1187
|
+
error: describeError(e),
|
|
1169
1188
|
query: prompt.slice(0, 80)
|
|
1170
1189
|
});
|
|
1171
1190
|
}
|
|
@@ -1184,7 +1203,7 @@ async function buildHookOutput(args) {
|
|
|
1184
1203
|
client.knowledgePagesSupported === false ? "knowledge_pages_unavailable" : "pages_failed",
|
|
1185
1204
|
{
|
|
1186
1205
|
ms: Date.now() - t0,
|
|
1187
|
-
error:
|
|
1206
|
+
error: describeError(e)
|
|
1188
1207
|
}
|
|
1189
1208
|
);
|
|
1190
1209
|
}
|
|
@@ -1207,6 +1226,8 @@ async function buildHookOutput(args) {
|
|
|
1207
1226
|
const preview = reflectAnswer.replace(/\s+/g, " ").trim();
|
|
1208
1227
|
notice = `${brandWord()} \xB7 goal: recall this repo's past decisions about \u201C${excerpt}\u201D
|
|
1209
1228
|
\u21B3 ${preview.length > 140 ? `${preview.slice(0, 140)}\u2026` : preview}`;
|
|
1229
|
+
} else if (reflectFailed) {
|
|
1230
|
+
notice = `${brandWord()} \xB7 no memory this turn \u2014 see ${diagFilePath()}`;
|
|
1210
1231
|
}
|
|
1211
1232
|
return { context: kept.length ? kept.join("\n\n") : void 0, notice, pagesKnown: pages.length };
|
|
1212
1233
|
}
|
|
@@ -377,11 +377,14 @@ var log = {
|
|
|
377
377
|
};
|
|
378
378
|
|
|
379
379
|
// src/core/diag.ts
|
|
380
|
+
function diagFilePath() {
|
|
381
|
+
return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
|
|
382
|
+
}
|
|
380
383
|
function diag(harness, event, extra = {}) {
|
|
381
384
|
log.debug(harness, `diag:${event}`, extra);
|
|
382
385
|
try {
|
|
383
386
|
appendFileSync2(
|
|
384
|
-
|
|
387
|
+
diagFilePath(),
|
|
385
388
|
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
386
389
|
);
|
|
387
390
|
} catch {
|
|
@@ -1423,6 +1426,7 @@ function resolveClaudeBin(explicit) {
|
|
|
1423
1426
|
}
|
|
1424
1427
|
return "claude";
|
|
1425
1428
|
}
|
|
1429
|
+
var SURVEY_AGENT = "hindsight-survey";
|
|
1426
1430
|
function resolveAgentBin(harness, claudeBin) {
|
|
1427
1431
|
switch (harness) {
|
|
1428
1432
|
case "claude-code":
|
|
@@ -1543,7 +1547,7 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
1543
1547
|
case "opencode": {
|
|
1544
1548
|
return {
|
|
1545
1549
|
bin,
|
|
1546
|
-
args: ["run", "--agent",
|
|
1550
|
+
args: ["run", "--agent", SURVEY_AGENT, SURVEY_PROMPT],
|
|
1547
1551
|
env
|
|
1548
1552
|
};
|
|
1549
1553
|
}
|
package/dist/grok-stop-hook.js
CHANGED
|
@@ -349,13 +349,30 @@ var log = {
|
|
|
349
349
|
warn: (scope, msg, extra) => write("warn", scope, msg, extra),
|
|
350
350
|
error: (scope, msg, extra) => write("error", scope, msg, extra)
|
|
351
351
|
};
|
|
352
|
+
function describeError(value, maxChars = 200) {
|
|
353
|
+
const parts = [];
|
|
354
|
+
const seen = /* @__PURE__ */ new Set();
|
|
355
|
+
let current2 = value;
|
|
356
|
+
while (current2 && !seen.has(current2)) {
|
|
357
|
+
seen.add(current2);
|
|
358
|
+
const error = current2;
|
|
359
|
+
const text = typeof error.message === "string" ? error.message : String(current2);
|
|
360
|
+
const withCode = error.code ? `${text} (${String(error.code)})` : text;
|
|
361
|
+
if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
|
|
362
|
+
current2 = error.cause;
|
|
363
|
+
}
|
|
364
|
+
return (parts.join(": ") || String(value)).slice(0, maxChars);
|
|
365
|
+
}
|
|
352
366
|
|
|
353
367
|
// src/core/diag.ts
|
|
368
|
+
function diagFilePath() {
|
|
369
|
+
return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
|
|
370
|
+
}
|
|
354
371
|
function diag(harness, event, extra = {}) {
|
|
355
372
|
log.debug(harness, `diag:${event}`, extra);
|
|
356
373
|
try {
|
|
357
374
|
appendFileSync2(
|
|
358
|
-
|
|
375
|
+
diagFilePath(),
|
|
359
376
|
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
360
377
|
);
|
|
361
378
|
} catch {
|
|
@@ -1522,11 +1539,11 @@ async function buildRetain(args) {
|
|
|
1522
1539
|
diag(harness, "retain_ok", { ms: Date.now() - t0, turns: turns.length, session: sessionId });
|
|
1523
1540
|
} catch (e) {
|
|
1524
1541
|
log.warn(harness, "session write-back failed", {
|
|
1525
|
-
error:
|
|
1542
|
+
error: describeError(e)
|
|
1526
1543
|
});
|
|
1527
1544
|
diag(harness, "retain_failed", {
|
|
1528
1545
|
ms: Date.now() - t0,
|
|
1529
|
-
error:
|
|
1546
|
+
error: describeError(e),
|
|
1530
1547
|
session: sessionId
|
|
1531
1548
|
});
|
|
1532
1549
|
}
|
package/dist/index.js
CHANGED
|
@@ -376,6 +376,20 @@ var log = {
|
|
|
376
376
|
warn: (scope, msg, extra) => write("warn", scope, msg, extra),
|
|
377
377
|
error: (scope, msg, extra) => write("error", scope, msg, extra)
|
|
378
378
|
};
|
|
379
|
+
function describeError(value, maxChars = 200) {
|
|
380
|
+
const parts = [];
|
|
381
|
+
const seen = /* @__PURE__ */ new Set();
|
|
382
|
+
let current2 = value;
|
|
383
|
+
while (current2 && !seen.has(current2)) {
|
|
384
|
+
seen.add(current2);
|
|
385
|
+
const error95 = current2;
|
|
386
|
+
const text = typeof error95.message === "string" ? error95.message : String(current2);
|
|
387
|
+
const withCode = error95.code ? `${text} (${String(error95.code)})` : text;
|
|
388
|
+
if (withCode && parts.at(-1) !== withCode) parts.push(withCode);
|
|
389
|
+
current2 = error95.cause;
|
|
390
|
+
}
|
|
391
|
+
return (parts.join(": ") || String(value)).slice(0, maxChars);
|
|
392
|
+
}
|
|
379
393
|
|
|
380
394
|
// src/core/missions.ts
|
|
381
395
|
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.";
|
|
@@ -1011,11 +1025,14 @@ var HindsightClient = class {
|
|
|
1011
1025
|
|
|
1012
1026
|
// src/core/diag.ts
|
|
1013
1027
|
import { appendFileSync as appendFileSync2 } from "fs";
|
|
1028
|
+
function diagFilePath() {
|
|
1029
|
+
return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
|
|
1030
|
+
}
|
|
1014
1031
|
function diag(harness, event, extra = {}) {
|
|
1015
1032
|
log.debug(harness, `diag:${event}`, extra);
|
|
1016
1033
|
try {
|
|
1017
1034
|
appendFileSync2(
|
|
1018
|
-
|
|
1035
|
+
diagFilePath(),
|
|
1019
1036
|
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
1020
1037
|
);
|
|
1021
1038
|
} catch {
|
|
@@ -15642,6 +15659,18 @@ function resolveClaudeBin(explicit) {
|
|
|
15642
15659
|
}
|
|
15643
15660
|
return "claude";
|
|
15644
15661
|
}
|
|
15662
|
+
var SURVEY_AGENT = "hindsight-survey";
|
|
15663
|
+
var SURVEY_AGENT_CONFIG = {
|
|
15664
|
+
description: "One-time read-only structural survey that seeds this repository's Hindsight memory.",
|
|
15665
|
+
mode: "primary",
|
|
15666
|
+
permission: {
|
|
15667
|
+
"*": "deny",
|
|
15668
|
+
read: "allow",
|
|
15669
|
+
grep: "allow",
|
|
15670
|
+
glob: "allow",
|
|
15671
|
+
hindsight_ingest_document: "allow"
|
|
15672
|
+
}
|
|
15673
|
+
};
|
|
15645
15674
|
function resolveAgentBin(harness, claudeBin) {
|
|
15646
15675
|
switch (harness) {
|
|
15647
15676
|
case "claude-code":
|
|
@@ -15762,7 +15791,7 @@ function buildSurveyPlan(harness, bin, repoDir, opts) {
|
|
|
15762
15791
|
case "opencode": {
|
|
15763
15792
|
return {
|
|
15764
15793
|
bin,
|
|
15765
|
-
args: ["run", "--agent",
|
|
15794
|
+
args: ["run", "--agent", SURVEY_AGENT, SURVEY_PROMPT],
|
|
15766
15795
|
env
|
|
15767
15796
|
};
|
|
15768
15797
|
}
|
|
@@ -15871,7 +15900,7 @@ function ok(value) {
|
|
|
15871
15900
|
return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
|
|
15872
15901
|
}
|
|
15873
15902
|
function err(e) {
|
|
15874
|
-
const message =
|
|
15903
|
+
const message = describeError(e);
|
|
15875
15904
|
return { content: [{ type: "text", text: JSON.stringify({ error: message }) }], isError: true };
|
|
15876
15905
|
}
|
|
15877
15906
|
function guarded(fn) {
|
|
@@ -16477,6 +16506,7 @@ async function buildHookOutput(args) {
|
|
|
16477
16506
|
const turns = (cached3.turns ?? 0) + 1;
|
|
16478
16507
|
let reflectAnswer = cached3.reflectAnswer;
|
|
16479
16508
|
let reflectRanThisTurn = false;
|
|
16509
|
+
let reflectFailed = false;
|
|
16480
16510
|
const deferInitialReflect = cached3.deferInitialReflect === true;
|
|
16481
16511
|
if (deferInitialReflect) {
|
|
16482
16512
|
diag(harness, "reflect_deferred_new_bank", { query: prompt.slice(0, 80) });
|
|
@@ -16501,12 +16531,13 @@ async function buildHookOutput(args) {
|
|
|
16501
16531
|
});
|
|
16502
16532
|
} catch (e) {
|
|
16503
16533
|
reflectAnswer = "";
|
|
16534
|
+
reflectFailed = true;
|
|
16504
16535
|
log.warn(harness, "reflect failed \u2014 session runs without memory", {
|
|
16505
|
-
error:
|
|
16536
|
+
error: describeError(e)
|
|
16506
16537
|
});
|
|
16507
16538
|
diag(harness, "reflect_failed", {
|
|
16508
16539
|
ms: Date.now() - t0,
|
|
16509
|
-
error:
|
|
16540
|
+
error: describeError(e),
|
|
16510
16541
|
query: prompt.slice(0, 80)
|
|
16511
16542
|
});
|
|
16512
16543
|
}
|
|
@@ -16525,7 +16556,7 @@ async function buildHookOutput(args) {
|
|
|
16525
16556
|
client.knowledgePagesSupported === false ? "knowledge_pages_unavailable" : "pages_failed",
|
|
16526
16557
|
{
|
|
16527
16558
|
ms: Date.now() - t0,
|
|
16528
|
-
error:
|
|
16559
|
+
error: describeError(e)
|
|
16529
16560
|
}
|
|
16530
16561
|
);
|
|
16531
16562
|
}
|
|
@@ -16548,6 +16579,8 @@ async function buildHookOutput(args) {
|
|
|
16548
16579
|
const preview = reflectAnswer.replace(/\s+/g, " ").trim();
|
|
16549
16580
|
notice = `${brandWord()} \xB7 goal: recall this repo's past decisions about \u201C${excerpt}\u201D
|
|
16550
16581
|
\u21B3 ${preview.length > 140 ? `${preview.slice(0, 140)}\u2026` : preview}`;
|
|
16582
|
+
} else if (reflectFailed) {
|
|
16583
|
+
notice = `${brandWord()} \xB7 no memory this turn \u2014 see ${diagFilePath()}`;
|
|
16551
16584
|
}
|
|
16552
16585
|
return { context: kept.length ? kept.join("\n\n") : void 0, notice, pagesKnown: pages.length };
|
|
16553
16586
|
}
|
|
@@ -16719,7 +16752,7 @@ var RuntimeCore = class {
|
|
|
16719
16752
|
turns = await this.fetchTranscript(sessionId);
|
|
16720
16753
|
} catch (e) {
|
|
16721
16754
|
diag(this.harness, "idle_fetch_failed", {
|
|
16722
|
-
error:
|
|
16755
|
+
error: describeError(e),
|
|
16723
16756
|
session: sessionId
|
|
16724
16757
|
});
|
|
16725
16758
|
return;
|
|
@@ -16759,7 +16792,7 @@ var RuntimeCore = class {
|
|
|
16759
16792
|
).catch(
|
|
16760
16793
|
(e) => diag(this.harness, "retain_failed", {
|
|
16761
16794
|
ms: Date.now() - t0,
|
|
16762
|
-
error:
|
|
16795
|
+
error: describeError(e),
|
|
16763
16796
|
session: sessionId,
|
|
16764
16797
|
trigger
|
|
16765
16798
|
})
|
|
@@ -29265,6 +29298,12 @@ var jsonChatReader = (harness) => ({
|
|
|
29265
29298
|
});
|
|
29266
29299
|
|
|
29267
29300
|
// src/harness/opencode.ts
|
|
29301
|
+
var surveyAgentHook = {
|
|
29302
|
+
config: async (cfg) => {
|
|
29303
|
+
cfg.agent ??= {};
|
|
29304
|
+
cfg.agent[SURVEY_AGENT] ??= SURVEY_AGENT_CONFIG;
|
|
29305
|
+
}
|
|
29306
|
+
};
|
|
29268
29307
|
var textOf = (parts) => (parts || []).filter((p) => p?.type === "text" && p.text).map((p) => p.text).join("\n").trim();
|
|
29269
29308
|
var chatReader = jsonChatReader("opencode");
|
|
29270
29309
|
function toOpencodeTool(spec) {
|
|
@@ -29285,6 +29324,7 @@ function createRuntime(core) {
|
|
|
29285
29324
|
const tools = {};
|
|
29286
29325
|
for (const spec of core.toolSpecs()) tools[spec.name] = toOpencodeTool(spec);
|
|
29287
29326
|
return {
|
|
29327
|
+
...surveyAgentHook,
|
|
29288
29328
|
tool: tools,
|
|
29289
29329
|
// Each user turn: recall on the prompt; the injection it builds is pushed by system.transform.
|
|
29290
29330
|
"chat.message": async (input, output) => {
|
package/dist/installer.js
CHANGED
|
@@ -76,11 +76,14 @@ var log = {
|
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
// src/core/diag.ts
|
|
79
|
+
function diagFilePath() {
|
|
80
|
+
return process.env.HINDSIGHT_DIAG_FILE || "/tmp/hindsight-plugin.log";
|
|
81
|
+
}
|
|
79
82
|
function diag(harness, event, extra = {}) {
|
|
80
83
|
log.debug(harness, `diag:${event}`, extra);
|
|
81
84
|
try {
|
|
82
85
|
appendFileSync2(
|
|
83
|
-
|
|
86
|
+
diagFilePath(),
|
|
84
87
|
JSON.stringify({ ts: (/* @__PURE__ */ new Date()).toISOString(), harness, event, ...extra }) + "\n"
|
|
85
88
|
);
|
|
86
89
|
} catch {
|
|
@@ -889,6 +892,100 @@ import {
|
|
|
889
892
|
} from "fs";
|
|
890
893
|
import { homedir as homedir7 } from "os";
|
|
891
894
|
import { join as join11 } from "path";
|
|
895
|
+
import * as zlib2 from "zlib";
|
|
896
|
+
|
|
897
|
+
// src/core/transcript-dsh.ts
|
|
898
|
+
function textOf(message) {
|
|
899
|
+
return (message.content || []).filter((block) => block?.type === "text" && typeof block.text === "string").map((block) => block.text).join("\n").trim();
|
|
900
|
+
}
|
|
901
|
+
function stampOf(event) {
|
|
902
|
+
return typeof event.time === "number" ? { timestamp: new Date(event.time).toISOString() } : {};
|
|
903
|
+
}
|
|
904
|
+
function readDshEvents(events) {
|
|
905
|
+
const turns = [];
|
|
906
|
+
for (const event of events || []) {
|
|
907
|
+
if (!event || typeof event !== "object") continue;
|
|
908
|
+
const stamp = stampOf(event);
|
|
909
|
+
if (event.type === "user/message") {
|
|
910
|
+
const message = event.data;
|
|
911
|
+
if (!message || message.source?.kind !== "user") continue;
|
|
912
|
+
const text = stripInjectedMemory(textOf(message)).trim();
|
|
913
|
+
if (text) turns.push({ role: "user", content: text, ...stamp });
|
|
914
|
+
} else if (event.type === "assistant/message") {
|
|
915
|
+
const message = event.data?.message;
|
|
916
|
+
if (!message) continue;
|
|
917
|
+
const text = stripInjectedMemory(textOf(message)).trim();
|
|
918
|
+
if (text) turns.push({ role: "assistant", content: text, ...stamp });
|
|
919
|
+
} else if (event.type === "tool/call") {
|
|
920
|
+
const call = event.data;
|
|
921
|
+
if (!call?.name) continue;
|
|
922
|
+
turns.push({
|
|
923
|
+
role: "action",
|
|
924
|
+
content: actionLine(call.name, parseArgs(call.arguments)),
|
|
925
|
+
...stamp
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
return turns;
|
|
930
|
+
}
|
|
931
|
+
function parseArgs(raw) {
|
|
932
|
+
if (!raw) return void 0;
|
|
933
|
+
try {
|
|
934
|
+
return JSON.parse(raw);
|
|
935
|
+
} catch {
|
|
936
|
+
return raw;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
// src/core/zstd-frames.ts
|
|
941
|
+
import * as zlib from "zlib";
|
|
942
|
+
var ZSTD_MAGIC = 4247762216;
|
|
943
|
+
function scanZstdFrames(buffer) {
|
|
944
|
+
const frames = [];
|
|
945
|
+
let offset = 0;
|
|
946
|
+
while (offset < buffer.length) {
|
|
947
|
+
const start = offset;
|
|
948
|
+
if (buffer.length - offset < 5) return frames;
|
|
949
|
+
if (buffer.readUInt32LE(offset) !== ZSTD_MAGIC) return frames;
|
|
950
|
+
offset += 4;
|
|
951
|
+
const descriptor = buffer.readUInt8(offset);
|
|
952
|
+
offset += 1;
|
|
953
|
+
if ((descriptor & 24) !== 0) return frames;
|
|
954
|
+
const contentSizeFlag = descriptor >>> 6;
|
|
955
|
+
const singleSegment = (descriptor & 32) !== 0;
|
|
956
|
+
const hasChecksum = (descriptor & 4) !== 0;
|
|
957
|
+
const dictionaryFlag = descriptor & 3;
|
|
958
|
+
const dictionaryBytes = dictionaryFlag === 3 ? 4 : dictionaryFlag;
|
|
959
|
+
const contentSizeBytes = contentSizeFlag === 0 ? singleSegment ? 1 : 0 : 1 << contentSizeFlag;
|
|
960
|
+
offset += (singleSegment ? 0 : 1) + dictionaryBytes + contentSizeBytes;
|
|
961
|
+
if (offset > buffer.length) return frames;
|
|
962
|
+
for (; ; ) {
|
|
963
|
+
if (buffer.length - offset < 3) return frames;
|
|
964
|
+
const blockHeader = buffer.readUIntLE(offset, 3);
|
|
965
|
+
offset += 3;
|
|
966
|
+
const lastBlock = (blockHeader & 1) !== 0;
|
|
967
|
+
const blockType = blockHeader >>> 1 & 3;
|
|
968
|
+
if (blockType === 3) return frames;
|
|
969
|
+
const payloadBytes = blockType === 1 ? 1 : blockHeader >>> 3;
|
|
970
|
+
offset += payloadBytes;
|
|
971
|
+
if (offset > buffer.length) return frames;
|
|
972
|
+
if (lastBlock) break;
|
|
973
|
+
}
|
|
974
|
+
if (hasChecksum) {
|
|
975
|
+
if (buffer.length - offset < 4) return frames;
|
|
976
|
+
offset += 4;
|
|
977
|
+
}
|
|
978
|
+
frames.push({ start, end: offset });
|
|
979
|
+
}
|
|
980
|
+
return frames;
|
|
981
|
+
}
|
|
982
|
+
function zstdDecompressFrames(buffer) {
|
|
983
|
+
return scanZstdFrames(buffer).map(
|
|
984
|
+
(frame) => zlib.zstdDecompressSync(buffer.subarray(frame.start, frame.end)).toString("utf8")
|
|
985
|
+
).join("");
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
// src/core/history.ts
|
|
892
989
|
function claudeProjectDir(repoDir, home = homedir7()) {
|
|
893
990
|
return join11(home, ".claude", "projects", repoDir.replace(/[/.]/g, "-"));
|
|
894
991
|
}
|
|
@@ -988,6 +1085,56 @@ function codexHistory(repoDir, home) {
|
|
|
988
1085
|
}
|
|
989
1086
|
return { supported: true, sessions };
|
|
990
1087
|
}
|
|
1088
|
+
function dshHistory(repoDir, home) {
|
|
1089
|
+
const root = process.env.DSH_HOME ? join11(process.env.DSH_HOME, "sessions") : join11(home, ".dsh", "sessions");
|
|
1090
|
+
if (!existsSync7(root)) return { supported: true, sessions: [] };
|
|
1091
|
+
if (typeof zlib2.zstdDecompressSync !== "function") {
|
|
1092
|
+
return {
|
|
1093
|
+
supported: false,
|
|
1094
|
+
reason: `reading dsh session logs needs Node's built-in Zstandard support (Node 22.15+); this import is running on ${process.version}`,
|
|
1095
|
+
sessions: []
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
const sessions = [];
|
|
1099
|
+
let unattributed = 0;
|
|
1100
|
+
for (const dir of readdirSync2(root).map((project) => join11(root, project))) {
|
|
1101
|
+
let sessionDirs;
|
|
1102
|
+
try {
|
|
1103
|
+
sessionDirs = readdirSync2(dir).map((id) => join11(dir, id));
|
|
1104
|
+
} catch {
|
|
1105
|
+
continue;
|
|
1106
|
+
}
|
|
1107
|
+
for (const sessionDir of sessionDirs) {
|
|
1108
|
+
const file = ["session.jsonl.zstd", "session.jsonl"].map((name) => join11(sessionDir, name)).find((candidate) => existsSync7(candidate));
|
|
1109
|
+
if (!file) continue;
|
|
1110
|
+
try {
|
|
1111
|
+
const lines = readDshLog(file);
|
|
1112
|
+
const header = JSON.parse(lines[0] ?? "{}");
|
|
1113
|
+
if (!header.cwd) {
|
|
1114
|
+
unattributed++;
|
|
1115
|
+
continue;
|
|
1116
|
+
}
|
|
1117
|
+
if (!withinRepo(header.cwd, repoDir)) continue;
|
|
1118
|
+
const events = lines.slice(1).flatMap((line) => {
|
|
1119
|
+
try {
|
|
1120
|
+
return [JSON.parse(line)];
|
|
1121
|
+
} catch {
|
|
1122
|
+
return [];
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1125
|
+
const s = toSession(header.id ?? sessionDir, readDshEvents(events));
|
|
1126
|
+
if (s) sessions.push(s);
|
|
1127
|
+
} catch {
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
return { supported: true, sessions, unattributed };
|
|
1132
|
+
}
|
|
1133
|
+
function readDshLog(file) {
|
|
1134
|
+
const bytes = readFileSync8(file);
|
|
1135
|
+
const text = file.endsWith(".zstd") ? zstdDecompressFrames(bytes) : bytes.toString("utf8");
|
|
1136
|
+
return text.split("\n").filter((line) => line.trim());
|
|
1137
|
+
}
|
|
991
1138
|
var SQLITE_HISTORY = "keeps session history in an internal SQLite database, whose schema is unversioned and would break on any upstream change";
|
|
992
1139
|
function importLocalHistory(harness, repoDir, home = homedir7()) {
|
|
993
1140
|
switch (harness) {
|
|
@@ -995,6 +1142,8 @@ function importLocalHistory(harness, repoDir, home = homedir7()) {
|
|
|
995
1142
|
return claudeHistory(repoDir, home);
|
|
996
1143
|
case "codex":
|
|
997
1144
|
return codexHistory(repoDir, home);
|
|
1145
|
+
case "dsh":
|
|
1146
|
+
return dshHistory(repoDir, home);
|
|
998
1147
|
case "opencode":
|
|
999
1148
|
case "kilo":
|
|
1000
1149
|
case "cursor-cli":
|
|
@@ -2081,6 +2230,47 @@ var cline = {
|
|
|
2081
2230
|
c.log?.("cline-cli: native plugin + MCP + skill removed");
|
|
2082
2231
|
}
|
|
2083
2232
|
};
|
|
2233
|
+
var DSH_MARKER_START = "# HINDSIGHT_CODING_AGENTS_DSH_START";
|
|
2234
|
+
var DSH_MARKER_END = "# HINDSIGHT_CODING_AGENTS_DSH_END";
|
|
2235
|
+
var DSH_BLOCK_RE = new RegExp(`\\n?${DSH_MARKER_START}[\\s\\S]*?${DSH_MARKER_END}\\n?`);
|
|
2236
|
+
function dshHome(c) {
|
|
2237
|
+
return process.env.DSH_HOME || join13(c.home, ".dsh");
|
|
2238
|
+
}
|
|
2239
|
+
var dsh = {
|
|
2240
|
+
name: "dsh",
|
|
2241
|
+
detect: (c) => onPath2("dsh") || existsSync9(dshHome(c)),
|
|
2242
|
+
install(c) {
|
|
2243
|
+
const path = join13(dshHome(c), "cordis.patch.yml");
|
|
2244
|
+
const existing = existsSync9(path) ? readFileSync10(path, "utf8") : "";
|
|
2245
|
+
const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
|
|
2246
|
+
const entry = pathToFileURL(join13(c.dist, "dsh.js")).href;
|
|
2247
|
+
const block = `${DSH_MARKER_START}
|
|
2248
|
+
- insert:
|
|
2249
|
+
- id: hindsight
|
|
2250
|
+
name: ${JSON.stringify(entry)}
|
|
2251
|
+
${DSH_MARKER_END}
|
|
2252
|
+
`;
|
|
2253
|
+
if (existsSync9(path) && !existsSync9(`${path}.hindsight-backup`))
|
|
2254
|
+
copyFileSync(path, `${path}.hindsight-backup`);
|
|
2255
|
+
mkdirSync3(dirname8(path), { recursive: true });
|
|
2256
|
+
writeFileSync2(path, others ? `${others}
|
|
2257
|
+
|
|
2258
|
+
${block}` : block);
|
|
2259
|
+
installSkill(c, "dsh", join13(c.home, ".agents", "skills"));
|
|
2260
|
+
c.log?.(`dsh: plugin registered in ${path} (applies to every dsh profile)`);
|
|
2261
|
+
},
|
|
2262
|
+
uninstall(c) {
|
|
2263
|
+
const path = join13(dshHome(c), "cordis.patch.yml");
|
|
2264
|
+
if (existsSync9(path)) {
|
|
2265
|
+
const existing = readFileSync10(path, "utf8");
|
|
2266
|
+
const others = existing.replace(DSH_BLOCK_RE, "\n").trim();
|
|
2267
|
+
if (others !== existing.trim()) writeFileSync2(path, others ? `${others}
|
|
2268
|
+
` : "[]\n");
|
|
2269
|
+
}
|
|
2270
|
+
uninstallSkill(c, join13(c.home, ".agents", "skills"));
|
|
2271
|
+
c.log?.("dsh: plugin entry + skill removed");
|
|
2272
|
+
}
|
|
2273
|
+
};
|
|
2084
2274
|
var INSTALLERS = [
|
|
2085
2275
|
opencode,
|
|
2086
2276
|
kilo,
|
|
@@ -2092,7 +2282,8 @@ var INSTALLERS = [
|
|
|
2092
2282
|
cursor,
|
|
2093
2283
|
copilot,
|
|
2094
2284
|
grok,
|
|
2095
|
-
cline
|
|
2285
|
+
cline,
|
|
2286
|
+
dsh
|
|
2096
2287
|
];
|
|
2097
2288
|
var HARNESS_ALIASES = { agy: "antigravity-cli" };
|
|
2098
2289
|
function importConversations(harness, ctx) {
|