@honcho-ai/claude-honcho 0.3.3 → 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/.claude-plugin/plugin.json +1 -1
- package/dist/hooks/post-tool-use.js +62 -43
- package/dist/hooks/post-tool-use.js.map +5 -5
- package/dist/hooks/pre-compact.js +70 -46
- package/dist/hooks/pre-compact.js.map +6 -6
- package/dist/hooks/pre-tool-honcho.js +17 -5
- package/dist/hooks/pre-tool-honcho.js.map +4 -4
- package/dist/hooks/save-user-message.js +39 -10
- package/dist/hooks/save-user-message.js.map +5 -5
- package/dist/hooks/session-end.js +18 -5
- package/dist/hooks/session-end.js.map +4 -4
- package/dist/hooks/session-start.js +65 -43
- package/dist/hooks/session-start.js.map +8 -8
- package/dist/hooks/stop.js +82 -36
- package/dist/hooks/stop.js.map +7 -6
- package/dist/hooks/user-prompt.js +122 -76
- package/dist/hooks/user-prompt.js.map +8 -8
- package/dist/mcp-server.js +119 -89
- package/dist/mcp-server.js.map +5 -5
- package/dist/skills/backfill-runner.js +24 -8
- package/dist/skills/backfill-runner.js.map +7 -6
- package/dist/skills/setup-runner.js +27 -9
- package/dist/skills/setup-runner.js.map +7 -6
- package/dist/skills/status-runner.js +14 -5
- package/dist/skills/status-runner.js.map +4 -4
- package/hooks/hooks.json +9 -9
- package/package.json +1 -1
- package/skills/status/SKILL.md +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
// @bun
|
|
3
2
|
var __create = Object.create;
|
|
4
3
|
var __getProtoOf = Object.getPrototypeOf;
|
|
5
4
|
var __defProp = Object.defineProperty;
|
|
@@ -15562,14 +15561,14 @@ var require_dist = __commonJS(function(exports) {
|
|
|
15562
15561
|
|
|
15563
15562
|
// src/hooks/user-prompt.ts
|
|
15564
15563
|
var import_sdk = __toESM(require_dist(), 1);
|
|
15565
|
-
import { readFileSync as readFileSync4, existsSync as
|
|
15564
|
+
import { readFileSync as readFileSync4, existsSync as existsSync7 } from "node:fs";
|
|
15566
15565
|
import { join as join7 } from "node:path";
|
|
15567
15566
|
|
|
15568
15567
|
// src/config.ts
|
|
15569
15568
|
import { homedir as homedir2 } from "os";
|
|
15570
15569
|
import { join as join3, basename, dirname, resolve, sep } from "path";
|
|
15571
15570
|
import { fileURLToPath } from "url";
|
|
15572
|
-
import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync2, statSync, writeFileSync as writeFileSync2 } from "fs";
|
|
15571
|
+
import { chmodSync, existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync2, statSync, writeFileSync as writeFileSync2 } from "fs";
|
|
15573
15572
|
|
|
15574
15573
|
// src/git.ts
|
|
15575
15574
|
import { execSync } from "child_process";
|
|
@@ -16110,6 +16109,9 @@ function mergeWithEnvVars(config) {
|
|
|
16110
16109
|
if (process.env.HONCHO_LOGGING === "false") {
|
|
16111
16110
|
config.logging = false;
|
|
16112
16111
|
}
|
|
16112
|
+
if (process.env.HONCHO_SAVE_MESSAGES === "false") {
|
|
16113
|
+
config.saveMessages = false;
|
|
16114
|
+
}
|
|
16113
16115
|
if (process.env.HONCHO_SAVE_TOOL_USE !== undefined) {
|
|
16114
16116
|
config.saveToolUse = process.env.HONCHO_SAVE_TOOL_USE === "true";
|
|
16115
16117
|
}
|
|
@@ -16118,6 +16120,11 @@ function mergeWithEnvVars(config) {
|
|
|
16118
16120
|
}
|
|
16119
16121
|
return config;
|
|
16120
16122
|
}
|
|
16123
|
+
function writeConfigFile(data) {
|
|
16124
|
+
if (existsSync3(CONFIG_FILE))
|
|
16125
|
+
chmodSync(CONFIG_FILE, 384);
|
|
16126
|
+
writeFileSync2(CONFIG_FILE, JSON.stringify(data, null, 2), { mode: 384 });
|
|
16127
|
+
}
|
|
16121
16128
|
function saveConfig(config) {
|
|
16122
16129
|
if (!existsSync3(CONFIG_DIR)) {
|
|
16123
16130
|
mkdirSync2(CONFIG_DIR, { recursive: true });
|
|
@@ -16148,9 +16155,10 @@ function saveConfig(config) {
|
|
|
16148
16155
|
setHostIfExplicit("aiPeer", config.aiPeer, existing.aiPeer ?? DEFAULT_AI_PEER[host]);
|
|
16149
16156
|
const enabledForSave = process.env.HONCHO_ENABLED === "false" && config.enabled === false ? existingHost.enabled : config.enabled;
|
|
16150
16157
|
const loggingForSave = process.env.HONCHO_LOGGING === "false" && config.logging === false ? existingHost.logging : config.logging;
|
|
16158
|
+
const saveMessagesForSave = process.env.HONCHO_SAVE_MESSAGES === "false" && config.saveMessages === false ? existingHost.saveMessages : config.saveMessages;
|
|
16151
16159
|
setHostIfExplicit("enabled", enabledForSave, existing.enabled);
|
|
16152
16160
|
setHostIfExplicit("logging", loggingForSave, existing.logging);
|
|
16153
|
-
setHostIfExplicit("saveMessages",
|
|
16161
|
+
setHostIfExplicit("saveMessages", saveMessagesForSave, existing.saveMessages);
|
|
16154
16162
|
setHostIfExplicit("sessionStrategy", config.sessionStrategy, existing.sessionStrategy);
|
|
16155
16163
|
setHostIfExplicit("sessionPeerPrefix", config.sessionPeerPrefix, existing.sessionPeerPrefix);
|
|
16156
16164
|
setHostIfExplicit("reasoningLevel", config.reasoningLevel, existing.reasoningLevel);
|
|
@@ -16165,7 +16173,7 @@ function saveConfig(config) {
|
|
|
16165
16173
|
hostEntry.apiKey = existingHost.apiKey;
|
|
16166
16174
|
}
|
|
16167
16175
|
existing.hosts[host] = hostEntry;
|
|
16168
|
-
|
|
16176
|
+
writeConfigFile(existing);
|
|
16169
16177
|
}
|
|
16170
16178
|
function saveRootField(field, value) {
|
|
16171
16179
|
if (!existsSync3(CONFIG_DIR)) {
|
|
@@ -16178,7 +16186,7 @@ function saveRootField(field, value) {
|
|
|
16178
16186
|
} catch {}
|
|
16179
16187
|
}
|
|
16180
16188
|
existing[field] = value;
|
|
16181
|
-
|
|
16189
|
+
writeConfigFile(existing);
|
|
16182
16190
|
}
|
|
16183
16191
|
function resolveWorktreeMainRoot(dir) {
|
|
16184
16192
|
try {
|
|
@@ -16343,6 +16351,9 @@ function getHonchoClientOptions(config) {
|
|
|
16343
16351
|
defaultHeaders: getTelemetryHeaders()
|
|
16344
16352
|
};
|
|
16345
16353
|
}
|
|
16354
|
+
function isProductionEndpoint(config) {
|
|
16355
|
+
return getHonchoBaseUrl(config) === HONCHO_BASE_URLS.production;
|
|
16356
|
+
}
|
|
16346
16357
|
function getEndpointInfo(config) {
|
|
16347
16358
|
if (config.endpoint?.baseUrl) {
|
|
16348
16359
|
return { type: "custom", url: config.endpoint.baseUrl };
|
|
@@ -16586,15 +16597,24 @@ function visSessionContextMessage(hookName, lines, tokenCount, showContents = fa
|
|
|
16586
16597
|
return body ? `${head}
|
|
16587
16598
|
${body}` : head;
|
|
16588
16599
|
}
|
|
16589
|
-
function visComposedInjection(hookName, labels) {
|
|
16590
|
-
const
|
|
16591
|
-
return formatLine("in", hookName,
|
|
16600
|
+
function visComposedInjection(hookName, labels, notes = []) {
|
|
16601
|
+
const head = labels.length ? `injected ${labels.join(" + ")}` : "nothing injected";
|
|
16602
|
+
return formatLine("in", hookName, [head, ...notes].join(" · "));
|
|
16603
|
+
}
|
|
16604
|
+
function visEmptyComponent(hookName, message, unavailable = false) {
|
|
16605
|
+
return formatLine(unavailable ? "warn" : "info", hookName, message);
|
|
16606
|
+
}
|
|
16607
|
+
function visAnchorSummary(hookName, items, elapsedMs) {
|
|
16608
|
+
const what = items.length ? items.join(" · ") : "session identity only";
|
|
16609
|
+
return formatLine("in", hookName, `anchored ${what} (${(elapsedMs / 1000).toFixed(1)}s)`);
|
|
16592
16610
|
}
|
|
16593
16611
|
function visCapture(summary) {
|
|
16594
16612
|
visMessage("out", "post-tool-use", `captured: ${summary}`);
|
|
16595
16613
|
}
|
|
16596
|
-
function visSkipMessage(hookName, reason) {
|
|
16597
|
-
|
|
16614
|
+
function visSkipMessage(hookName, reason, banner) {
|
|
16615
|
+
const line = formatLine("info", hookName, `skipped (${reason})`);
|
|
16616
|
+
console.log(JSON.stringify({ systemMessage: banner ? `${banner}
|
|
16617
|
+
${line}` : line }));
|
|
16598
16618
|
}
|
|
16599
16619
|
function visStopMessage(direction, message) {
|
|
16600
16620
|
visMessage(direction, "response", message);
|
|
@@ -16642,27 +16662,6 @@ function clearVerboseLog() {
|
|
|
16642
16662
|
ensureVerboseLog();
|
|
16643
16663
|
writeFileSync4(VERBOSE_LOG, "");
|
|
16644
16664
|
}
|
|
16645
|
-
function formatVerboseBlock(label, data) {
|
|
16646
|
-
if (!data)
|
|
16647
|
-
return "";
|
|
16648
|
-
const separator = "─".repeat(60);
|
|
16649
|
-
const content = data.length > 3000 ? data.slice(0, 3000) + `
|
|
16650
|
-
... (${data.length - 3000} more chars)` : data;
|
|
16651
|
-
return `
|
|
16652
|
-
[verbose] ${label}
|
|
16653
|
-
${separator}
|
|
16654
|
-
${content}
|
|
16655
|
-
${separator}`;
|
|
16656
|
-
}
|
|
16657
|
-
function formatVerboseList(label, items) {
|
|
16658
|
-
if (!items || items.length === 0)
|
|
16659
|
-
return "";
|
|
16660
|
-
const formatted = items.map((item) => ` • ${item}`).join(`
|
|
16661
|
-
`);
|
|
16662
|
-
return `
|
|
16663
|
-
[verbose] ${label} (${items.length} items)
|
|
16664
|
-
${formatted}`;
|
|
16665
|
-
}
|
|
16666
16665
|
|
|
16667
16666
|
// src/styles.ts
|
|
16668
16667
|
var symbols2 = {
|
|
@@ -16676,8 +16675,10 @@ var symbols2 = {
|
|
|
16676
16675
|
pipe: String.fromCodePoint(9474),
|
|
16677
16676
|
sparkle: String.fromCodePoint(10022)
|
|
16678
16677
|
};
|
|
16679
|
-
function honchoSessionUrl(
|
|
16680
|
-
|
|
16678
|
+
function honchoSessionUrl(config, sessionName) {
|
|
16679
|
+
if (!isProductionEndpoint(config))
|
|
16680
|
+
return null;
|
|
16681
|
+
return `https://app.honcho.dev/explore?workspace=${encodeURIComponent(config.workspace)}&view=sessions&session=${encodeURIComponent(sessionName)}`;
|
|
16681
16682
|
}
|
|
16682
16683
|
|
|
16683
16684
|
// src/state.ts
|
|
@@ -16712,12 +16713,14 @@ function clearSessionFiles(sessionId) {
|
|
|
16712
16713
|
}
|
|
16713
16714
|
|
|
16714
16715
|
// src/prompt-filters.ts
|
|
16716
|
+
import { existsSync as existsSync6 } from "fs";
|
|
16715
16717
|
var TRIVIAL_REPLY_PATTERN = /^(yes|no|ok|sure|thanks|y|n|yep|nope|yeah|nah|continue|go ahead|do it|proceed)$/i;
|
|
16716
16718
|
function isTerseReply(prompt) {
|
|
16717
16719
|
return TRIVIAL_REPLY_PATTERN.test(prompt.trim());
|
|
16718
16720
|
}
|
|
16719
16721
|
var HARNESS_INJECTED_PATTERNS = [
|
|
16720
16722
|
/^<task-notification>/,
|
|
16723
|
+
/^<cross-session-message\b/,
|
|
16721
16724
|
/^<local-command-stdout>/,
|
|
16722
16725
|
/^<command-name>/,
|
|
16723
16726
|
/^<command-message>/,
|
|
@@ -16725,16 +16728,27 @@ var HARNESS_INJECTED_PATTERNS = [
|
|
|
16725
16728
|
/^<bash-(stdout|stderr|input)>/,
|
|
16726
16729
|
/^<<[\w-]+>>$/
|
|
16727
16730
|
];
|
|
16731
|
+
var LEADING_REMINDERS = /^(?:\s*<system-reminder>[\s\S]*?<\/system-reminder>)+\s*/;
|
|
16732
|
+
function stripLeadingReminders(prompt) {
|
|
16733
|
+
return prompt.replace(LEADING_REMINDERS, "");
|
|
16734
|
+
}
|
|
16735
|
+
var SLASH_COMMAND_ENVELOPE = /^<command-(name|message)>/;
|
|
16728
16736
|
function isHarnessInjected(prompt) {
|
|
16729
|
-
const trimmed = prompt.trim();
|
|
16730
|
-
return HARNESS_INJECTED_PATTERNS.some((p) => p.test(trimmed));
|
|
16737
|
+
const trimmed = stripLeadingReminders(prompt).trim();
|
|
16738
|
+
return !trimmed || HARNESS_INJECTED_PATTERNS.some((p) => p.test(trimmed));
|
|
16739
|
+
}
|
|
16740
|
+
var SLASH_COMMAND = /^\/([\w:-]+)(?:\s|$)/;
|
|
16741
|
+
function isSlashCommand(prompt) {
|
|
16742
|
+
const trimmed = stripLeadingReminders(prompt).trim();
|
|
16743
|
+
if (SLASH_COMMAND_ENVELOPE.test(trimmed))
|
|
16744
|
+
return true;
|
|
16745
|
+
const name = SLASH_COMMAND.exec(trimmed)?.[1];
|
|
16746
|
+
if (!name)
|
|
16747
|
+
return false;
|
|
16748
|
+
return name.includes(":") || !existsSync6(`/${name}`);
|
|
16731
16749
|
}
|
|
16732
16750
|
|
|
16733
16751
|
// src/hooks/user-prompt.ts
|
|
16734
|
-
var SKIP_CONTEXT_PATTERNS = [
|
|
16735
|
-
TRIVIAL_REPLY_PATTERN,
|
|
16736
|
-
/^\//
|
|
16737
|
-
];
|
|
16738
16752
|
var FETCH_TIMEOUT_MS = 4000;
|
|
16739
16753
|
var DIALECTIC_TIMEOUT_MS = 120000;
|
|
16740
16754
|
function raceTimeout(p, ms) {
|
|
@@ -16760,8 +16774,14 @@ function extractTopics(prompt) {
|
|
|
16760
16774
|
const words = prompt.toLowerCase().match(/\b[a-z]{4,}\b/g) || [];
|
|
16761
16775
|
return { topics: [...new Set(words.filter((w) => !stopwords.has(w)))].slice(0, 10), precise: false };
|
|
16762
16776
|
}
|
|
16763
|
-
function
|
|
16764
|
-
|
|
16777
|
+
function skipReason(prompt) {
|
|
16778
|
+
if (isHarnessInjected(prompt))
|
|
16779
|
+
return "automated message";
|
|
16780
|
+
if (isSlashCommand(prompt))
|
|
16781
|
+
return "slash command";
|
|
16782
|
+
if (isTerseReply(stripLeadingReminders(prompt)))
|
|
16783
|
+
return "short reply";
|
|
16784
|
+
return null;
|
|
16765
16785
|
}
|
|
16766
16786
|
function formatSessionLink(sessionUrl) {
|
|
16767
16787
|
return `view your session in honcho GUI: ${sessionUrl}`;
|
|
@@ -16771,7 +16791,7 @@ function readVersionNag() {
|
|
|
16771
16791
|
if (!dataDir)
|
|
16772
16792
|
return;
|
|
16773
16793
|
const flag = join7(dataDir, ".version-stale");
|
|
16774
|
-
if (!
|
|
16794
|
+
if (!existsSync7(flag))
|
|
16775
16795
|
return;
|
|
16776
16796
|
try {
|
|
16777
16797
|
return readFileSync4(flag, "utf8").trim() || undefined;
|
|
@@ -16805,19 +16825,23 @@ async function handleUserPrompt() {
|
|
|
16805
16825
|
process.exit(0);
|
|
16806
16826
|
}
|
|
16807
16827
|
logHook("user-prompt", `Prompt received (${prompt.length} chars)`);
|
|
16808
|
-
|
|
16828
|
+
const sessionUrl = honchoSessionUrl(config, sessionName);
|
|
16829
|
+
setSessionLink(sessionUrl, sessionName, hookInput.session_id);
|
|
16809
16830
|
const messageCountBefore = getMessageCount();
|
|
16810
16831
|
incrementMessageCount();
|
|
16811
16832
|
if (messageCountBefore === 0) {
|
|
16812
16833
|
sessionToolHint = `Honcho memory tools are available — call honcho.search(query) or honcho.get_context to recall ` + `facts about ${config.peerName} across sessions, and honcho.chat(question) for dialectic/` + `psychological questions. Prefer querying over guessing when the user's history is relevant.`;
|
|
16813
16834
|
}
|
|
16814
16835
|
const nag = readVersionNag();
|
|
16815
|
-
const
|
|
16816
|
-
|
|
16817
|
-
|
|
16818
|
-
|
|
16836
|
+
const link = sessionUrl ? formatSessionLink(sessionUrl) : undefined;
|
|
16837
|
+
const banner = messageCountBefore === 0 ? nag ?? link : messageCountBefore === 1 && nag ? link : undefined;
|
|
16838
|
+
const skip = skipReason(prompt);
|
|
16839
|
+
if (skip) {
|
|
16840
|
+
logHook("user-prompt", `Skipping context (${skip})`);
|
|
16841
|
+
visSkipMessage("user-prompt", skip, banner);
|
|
16819
16842
|
process.exit(0);
|
|
16820
16843
|
}
|
|
16844
|
+
const userPrompt = stripLeadingReminders(prompt);
|
|
16821
16845
|
const injection = getInjectionConfig(config);
|
|
16822
16846
|
const wantUserContext = injection.perTurn.includes("userContext");
|
|
16823
16847
|
const wantAssistantContext = injection.perTurn.includes("assistantContext");
|
|
@@ -16825,54 +16849,80 @@ async function handleUserPrompt() {
|
|
|
16825
16849
|
const wantDialectic = injection.perTurn.includes("dialectic");
|
|
16826
16850
|
if (!wantUserContext && !wantAssistantContext && !wantSessionContext && !wantDialectic) {
|
|
16827
16851
|
logHook("user-prompt", "No per-turn injection components selected");
|
|
16828
|
-
visSkipMessage("user-prompt",
|
|
16852
|
+
visSkipMessage("user-prompt", "injection off", banner);
|
|
16829
16853
|
process.exit(0);
|
|
16830
16854
|
}
|
|
16831
16855
|
setMemoryState("recalling", undefined, hookInput.session_id);
|
|
16832
16856
|
const [userCtxResult, assistantCtxResult, sessionCtx, dialectic] = await Promise.all([
|
|
16833
|
-
wantUserContext ? raceTimeout(fetchUserContext(config,
|
|
16834
|
-
wantAssistantContext ? raceTimeout(fetchAssistantContext(config,
|
|
16857
|
+
wantUserContext ? raceTimeout(fetchUserContext(config, userPrompt, injection), FETCH_TIMEOUT_MS) : Promise.resolve(null),
|
|
16858
|
+
wantAssistantContext ? raceTimeout(fetchAssistantContext(config, userPrompt, injection), FETCH_TIMEOUT_MS) : Promise.resolve(null),
|
|
16835
16859
|
wantSessionContext ? raceTimeout(fetchSessionContext(config, sessionName, injection), FETCH_TIMEOUT_MS) : Promise.resolve(null),
|
|
16836
|
-
wantDialectic ? raceTimeout(fetchDialectic(config,
|
|
16860
|
+
wantDialectic ? raceTimeout(fetchDialectic(config, userPrompt, injection), DIALECTIC_TIMEOUT_MS) : Promise.resolve(null)
|
|
16837
16861
|
]);
|
|
16838
16862
|
const userCtx = userCtxResult?.context ? { context: userCtxResult.context, matched: userCtxResult.matched, queryLabel: userCtxResult.queryLabel } : null;
|
|
16839
|
-
emitPerTurn(config, injection, userCtx, assistantCtxResult?.context ?? null, sessionCtx, dialectic,
|
|
16863
|
+
emitPerTurn(config, injection, userCtx, assistantCtxResult?.context ?? null, sessionCtx, dialectic, banner);
|
|
16840
16864
|
process.exit(0);
|
|
16841
16865
|
}
|
|
16842
|
-
function emitPerTurn(config, injection, userCtx, assistantCtx, sessionCtx, dialectic,
|
|
16866
|
+
function emitPerTurn(config, injection, userCtx, assistantCtx, sessionCtx, dialectic, banner) {
|
|
16843
16867
|
const parts = [];
|
|
16844
16868
|
const visLines = [];
|
|
16845
16869
|
const show = (c) => injection.showContents?.includes(c) ?? false;
|
|
16846
|
-
|
|
16847
|
-
|
|
16848
|
-
|
|
16870
|
+
const want = (c) => injection.perTurn?.includes(c) ?? false;
|
|
16871
|
+
const unavailable = (what) => visLines.push(visEmptyComponent("user-prompt", `${what} unavailable`, true));
|
|
16872
|
+
const empty = (message) => visLines.push(visEmptyComponent("user-prompt", message));
|
|
16873
|
+
if (want("userContext")) {
|
|
16874
|
+
const conclusions = userCtx ? extractConclusions(userCtx.context) : [];
|
|
16875
|
+
if (!userCtx) {
|
|
16876
|
+
unavailable("user context");
|
|
16877
|
+
} else if (conclusions.length === 0) {
|
|
16878
|
+
empty("no conclusions matched");
|
|
16879
|
+
} else {
|
|
16849
16880
|
parts.push(`Relevant conclusions: ${conclusions.join("; ")}`);
|
|
16850
16881
|
visLines.push(visInjectionMessage("user-prompt", { conclusions, matched: userCtx.matched, queryLabel: userCtx.queryLabel, showContents: show("userContext") }));
|
|
16851
16882
|
}
|
|
16852
16883
|
}
|
|
16853
|
-
if (
|
|
16854
|
-
const conclusions = extractConclusions(assistantCtx);
|
|
16855
|
-
if (
|
|
16884
|
+
if (want("assistantContext")) {
|
|
16885
|
+
const conclusions = assistantCtx ? extractConclusions(assistantCtx) : [];
|
|
16886
|
+
if (!assistantCtx) {
|
|
16887
|
+
unavailable("assistant context");
|
|
16888
|
+
} else if (conclusions.length === 0) {
|
|
16889
|
+
empty(`no conclusions about ${config.aiPeer} matched`);
|
|
16890
|
+
} else {
|
|
16856
16891
|
parts.push(`Conclusions about the assistant (${config.aiPeer}): ${conclusions.join("; ")}`);
|
|
16857
16892
|
visLines.push(visInjectionMessage("user-prompt", { conclusions, queryLabel: `assistant ${config.aiPeer}`, showContents: show("assistantContext") }));
|
|
16858
16893
|
}
|
|
16859
16894
|
}
|
|
16860
|
-
if (
|
|
16861
|
-
|
|
16895
|
+
if (want("sessionContext")) {
|
|
16896
|
+
if (!sessionCtx) {
|
|
16897
|
+
unavailable("session context");
|
|
16898
|
+
} else if (sessionCtx.lines.length === 0) {
|
|
16899
|
+
empty("no session messages yet");
|
|
16900
|
+
} else {
|
|
16901
|
+
parts.push(`Recent Honcho session messages:
|
|
16862
16902
|
${sessionCtx.lines.join(`
|
|
16863
16903
|
`)}`);
|
|
16864
|
-
|
|
16904
|
+
visLines.push(visSessionContextMessage("user-prompt", sessionCtx.lines, sessionCtx.tokenCount, show("sessionContext")));
|
|
16905
|
+
}
|
|
16865
16906
|
}
|
|
16866
|
-
if (dialectic) {
|
|
16867
|
-
|
|
16868
|
-
|
|
16907
|
+
if (want("dialectic")) {
|
|
16908
|
+
if (!dialectic) {
|
|
16909
|
+
unavailable("dialectic");
|
|
16910
|
+
} else if (!dialectic.answer) {
|
|
16911
|
+
empty(`dialectic returned no answer (${dialectic.reasoning} · ${(dialectic.elapsedMs / 1000).toFixed(1)}s)`);
|
|
16912
|
+
} else {
|
|
16913
|
+
parts.push(`Dialectic recall: ${dialectic.answer}`);
|
|
16914
|
+
visLines.push(visDialecticMessage("user-prompt", dialectic.reasoning, dialectic.elapsedMs, dialectic.answer, show("dialectic")));
|
|
16915
|
+
}
|
|
16869
16916
|
}
|
|
16870
|
-
if (parts.length === 0)
|
|
16871
|
-
return;
|
|
16872
16917
|
const visMsg = visLines.join(`
|
|
16873
16918
|
`);
|
|
16874
|
-
|
|
16875
|
-
${visMsg}` : visMsg
|
|
16919
|
+
const systemMessage = banner ? `${banner}
|
|
16920
|
+
${visMsg}` : visMsg;
|
|
16921
|
+
if (parts.length === 0) {
|
|
16922
|
+
console.log(JSON.stringify({ systemMessage }));
|
|
16923
|
+
return;
|
|
16924
|
+
}
|
|
16925
|
+
outputContext(config.peerName, parts, systemMessage);
|
|
16876
16926
|
}
|
|
16877
16927
|
async function fetchDialectic(config, prompt, injection) {
|
|
16878
16928
|
const honcho = new import_sdk.Honcho(getHonchoClientOptions(config));
|
|
@@ -16889,9 +16939,7 @@ async function fetchDialectic(config, prompt, injection) {
|
|
|
16889
16939
|
});
|
|
16890
16940
|
const elapsedMs = Date.now() - startTime;
|
|
16891
16941
|
logApiCall("peer.chat (dialectic)", "POST", `${reasoning}: ${query.slice(0, 60)}`, elapsedMs, true);
|
|
16892
|
-
|
|
16893
|
-
return null;
|
|
16894
|
-
return { answer: answer.trim(), reasoning, elapsedMs };
|
|
16942
|
+
return { answer: typeof answer === "string" ? answer.trim() : "", reasoning, elapsedMs };
|
|
16895
16943
|
} catch (e) {
|
|
16896
16944
|
logHook("user-prompt", `Dialectic fetch failed: ${e}`);
|
|
16897
16945
|
return null;
|
|
@@ -16963,8 +17011,6 @@ async function fetchSessionContext(config, sessionName, injection) {
|
|
|
16963
17011
|
});
|
|
16964
17012
|
logApiCall("session.context", "GET", sessionName, Date.now() - startTime, true);
|
|
16965
17013
|
const messages = context?.messages ?? [];
|
|
16966
|
-
if (!messages.length)
|
|
16967
|
-
return null;
|
|
16968
17014
|
const lines = messages.map((m) => `${m.peerId}: ${m.content}`);
|
|
16969
17015
|
const tokenCount = messages.reduce((sum, m) => sum + (m.tokenCount ?? 0), 0);
|
|
16970
17016
|
verboseApiResult("session.context() -> messages", lines.join(`
|
|
@@ -17005,5 +17051,5 @@ async function main() {
|
|
|
17005
17051
|
// hooks/user-prompt.ts
|
|
17006
17052
|
await main();
|
|
17007
17053
|
|
|
17008
|
-
//# debugId=
|
|
17054
|
+
//# debugId=11850AB8BCC111EC64756E2164756E21
|
|
17009
17055
|
//# sourceMappingURL=user-prompt.js.map
|