Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Fixed

- Bound loaded daily summaries to the configured history recap character budget.
- Prevent mixed reaction replies from narrating the bot's internal choice to react while preserving natural reaction-plus-text responses.
- Run Discord-initiated Claude login in a pseudo-terminal so the CLI accepts submitted OAuth codes.
- Isolate saved history and summaries by Discord channel ID in dedicated storage namespaces so same-named channels do not share automatic context.
Expand Down
10 changes: 7 additions & 3 deletions src/storage/summaries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from "fs";
import {
CLAUDE_WORKLOAD_CONFIG,
HISTORY_RECAP_MAX_CHARS,
HISTORY_V2_DIR,
SUMMARIES_V2_DIR,
} from "../config.js";
Expand Down Expand Up @@ -32,10 +33,13 @@ export function loadRecentSummaries(
const date = new Date(Date.now() - i * 86400000);
const summaryPath = getSummaryPath(channelId, date, channelName);
if (fs.existsSync(summaryPath)) {
const summary = fs
.readFileSync(summaryPath, "utf-8")
.trim()
.slice(0, HISTORY_RECAP_MAX_CHARS);
if (!summary) continue;
const dateStr = date.toISOString().split("T")[0];
summaries.push(
`[${dateStr}] ${fs.readFileSync(summaryPath, "utf-8").trim()}`,
);
summaries.push(`[${dateStr}] ${summary}`);
}
}
return summaries.reverse().join("\n\n");
Expand Down
31 changes: 31 additions & 0 deletions tests/summaryContext.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import test from "node:test";

const messagesDir = fs.mkdtempSync(
path.join(os.tmpdir(), "claudify-summary-context-"),
);
process.env.MESSAGES_DIR = messagesDir;
process.env.HISTORY_RECAP_MAX_CHARS = "80";

const { loadRecentHistory } = await import("../build/storage/history.js");
const { getSummaryPath } = await import("../build/storage/summaries.js");

test.after(() => fs.rmSync(messagesDir, { recursive: true, force: true }));

test("loaded daily summaries stay within the configured recap character budget", () => {
const date = new Date(Date.now() - 86400000);
const summary = `important opening context ${"x".repeat(200)} trailing data`;
fs.writeFileSync(
getSummaryPath("summary-channel", date, "general"),
summary,
"utf8",
);

const history = loadRecentHistory("summary-channel", "ordinary question", "general");

assert.match(history, /important opening context/);
assert.doesNotMatch(history, /trailing data/);
});