Skip to content
Closed
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
268 changes: 134 additions & 134 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/backend/claude-sdk/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,11 @@ export async function handleMessage(
if (onToolUse) {
try {
onToolUse(tool.name, tool.input);
} catch {
/* non-fatal */
} catch (err) {
logWarn(
"agent",
`onToolUse callback threw for ${tool.name}: ${err instanceof Error ? err.message : err}`,
);
}
}
}
Expand Down
41 changes: 6 additions & 35 deletions src/backend/claude-sdk/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,38 +256,9 @@ export function processResultMessage(
}

// ── Trailing-text fallback dedup ────────────────────────────────────────────

/**
* Normalize text for fuzzy comparison — trim, lowercase, collapse whitespace,
* strip emoji. Used to detect whether trailing prose duplicates content
* already delivered via `end_turn` / `send(type="text")`.
*/
export function normalizeForDedupe(text: string): string {
return text
.trim()
.toLowerCase()
.replace(/\p{Emoji_Presentation}|\p{Extended_Pictographic}/gu, "")
.replace(/\s+/g, " ")
.trim();
}

const MIN_DEDUP_LENGTH = 10;

/**
* Returns true if `candidate` is substantively the same as any text in
* `deliveredNorms`. "Substantively" = one is a substring of the other after
* normalization; both must be at least MIN_DEDUP_LENGTH chars to avoid
* dropping short legitimate replies.
*/
export function isDuplicateOfDelivered(
candidate: string,
deliveredNorms: string[],
): boolean {
if (deliveredNorms.length === 0) return false;
const norm = normalizeForDedupe(candidate);
if (norm.length < MIN_DEDUP_LENGTH) return false;
return deliveredNorms.some(
(d) =>
d.length >= MIN_DEDUP_LENGTH && (norm.includes(d) || d.includes(norm)),
);
}
// Re-exported from the shared module so that consumers importing from
// stream.ts continue to work without maintaining a separate implementation.
export {
normalizeForDedupe,
isDuplicateOfDelivered,
} from "../shared/delivered-text.js";
5 changes: 5 additions & 0 deletions src/frontend/terminal/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ export function createInput(promptStr: string): InputHandler {
paused = false;
},
close() {
if (pendingResolve) {
const resolve = pendingResolve;
pendingResolve = null;
resolve("");
}
process.stdout.write("\x1b[?2004l");
if (process.stdin.isTTY) process.stdin.setRawMode(false);
process.stdin.pause();
Expand Down
3 changes: 2 additions & 1 deletion src/storage/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ export function getSession(chatId: string): SessionState {
session.usage.lastResponseMs = 0;
if (
session.usage.fastestResponseMs === undefined ||
session.usage.fastestResponseMs === 0
session.usage.fastestResponseMs === 0 ||
session.usage.fastestResponseMs === null
)
session.usage.fastestResponseMs = Infinity;
// Migrate sessions from before context tracking was added
Expand Down
Loading