Compare commits

...
Author SHA1 Message Date
copilot-swe-agent[bot]andCohee1207 5da9808a4d Revert unrelated package-lock.json changes
Agent-Logs-Url: https://github.com/SillyTavern/SillyTavern/sessions/24ce521f-29ee-4569-9930-65f75afe6800

Co-authored-by: Cohee1207 <18619528+Cohee1207@users.noreply.github.com>
2026-04-15 18:32:56 +00:00
copilot-swe-agent[bot]andCohee1207 c345b65853 Fix silent chat overwrite when file first line is unparseable
When a chat file exists but its first line cannot be parsed as JSON
(due to corruption, encoding issues like BOM, or truncation),
checkChatIntegrity() previously returned true, silently allowing the
file to be overwritten without user confirmation.

Now it returns false in this case, which triggers the existing
IntegrityMismatchError and shows the OVERWRITE confirmation dialog,
preventing silent data loss.

The legitimate upgrade path (old format files without integrity
metadata) is preserved: files with valid JSON but no integrity
field still pass the check.

Agent-Logs-Url: https://github.com/SillyTavern/SillyTavern/sessions/24ce521f-29ee-4569-9930-65f75afe6800

Co-authored-by: Cohee1207 <18619528+Cohee1207@users.noreply.github.com>
2026-04-15 18:32:26 +00:00
copilot-swe-agent[bot] ebbb8057c2 Initial plan 2026-04-15 18:22:32 +00:00
+15 -1
View File
@@ -321,10 +321,24 @@ async function checkChatIntegrity(filePath, integritySlug) {
// Parse the first line of the chat file as JSON
const firstLine = await readFirstLine(filePath);
// If the file is empty, allow the save
if (!firstLine) {
return true;
}
const jsonData = tryParse(firstLine);
// If the first line exists but can't be parsed, the file may be corrupted.
// Refuse the save to prevent silent data loss and let the user decide.
if (!jsonData) {
console.warn(`File "${filePath}" first line could not be parsed as JSON. Integrity check failed for slug "${integritySlug}".`);
return false;
}
const chatIntegrity = jsonData?.chat_metadata?.integrity;
// If the chat has no integrity metadata, assume it's intact
// If the chat has no integrity metadata, assume it's an old format file being upgraded
if (!chatIntegrity) {
console.debug(`File "${filePath}" does not have integrity metadata matching "${integritySlug}". The integrity validation has been skipped.`);
return true;