fix: pass paths to PowerShell as Base64, validate files one by one

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 11:43:06 +01:00
1 parent 1ed04fe9be
commit 6360c75ff8
3 files changed
+128 -40

No files matched your search

+36 -27
View File
@@ -40,7 +40,7 @@ import { keyIntent } from "./keys.js";
import { decide, shouldDrain, shouldStartCountdown, sendNow as sendToTerminal } from "./delivery.js";
import { detect as detectTrigger, rank, merge, startsLine } from "./suggest.js";
import * as catalog from "./catalog.js";
import { LIMITS, validate, validateMany, mention, removeMention, kindOf } from "./attachments.js";
import { LIMITS, validate, mention, removeMention, kindOf } from "./attachments.js";
import {
clipboardScript,
parseClipboardResult,
@@ -1141,24 +1141,24 @@ export default class Composer extends View {
this.state = reduce(this.state, { type: "attachment_update", agent: key, id, patch: { state: "adding" } });
cx.notify();
cx.spawn(async (cx) => {
let current = file;
if (!Number.isFinite(file.bytes)) {
let bytes = file.bytes;
if (!Number.isFinite(bytes)) {
const measured = (await this.measure([file.path])).files[0];
const check = measured && Number.isFinite(measured.bytes) ? validate({ ...file, bytes: measured.bytes }) : null;
if (!check || !check.ok) {
this.state = reduce(this.state, {
type: "attachment_update",
agent: key,
id,
patch: { state: "error", error: check ? check.reason : SIZE_ERROR },
});
cx.notify();
return;
}
current = { ...file, bytes: measured.bytes };
this.state = reduce(this.state, { type: "attachment_update", agent: key, id, patch: { bytes: measured.bytes } });
bytes = measured && Number.isFinite(measured.bytes) ? measured.bytes : undefined;
}
await this.putAttachment(agent, current, cx);
const check = bytes === undefined ? null : validate({ ...file, bytes });
if (!check || !check.ok) {
this.state = reduce(this.state, {
type: "attachment_update",
agent: key,
id,
patch: { state: "error", error: check ? check.reason : SIZE_ERROR },
});
cx.notify();
return;
}
this.state = reduce(this.state, { type: "attachment_update", agent: key, id, patch: { bytes } });
await this.putAttachment(agent, { ...file, bytes }, cx);
});
}
@@ -1353,6 +1353,10 @@ export default class Composer extends View {
}
if (measured.dirs.length) this.notice(DIR_NOTICE, "error");
this.addFiles(measured.files, "drop", cx);
// A path that is not there any more is said, not skipped in silence.
if (measured.missing.length) {
this.notice(`Nie znaleziono pliku: ${measured.missing.map(nameOf).join(", ")}`, "error", cx);
}
});
}
@@ -1410,27 +1414,32 @@ export default class Composer extends View {
origin,
};
});
const known = files.filter((file) => file.bytes !== undefined);
const check = validateMany(known);
if (!check.ok) {
this.notice(check.reason, "error", cx);
return;
}
// The whole batch may be 100 files at most; every file is judged on its
// own - a file that is too big does not take the good ones with it.
if ((this.state.attachments[key] ?? []).length + files.length > LIMITS.filesPerAction) {
this.notice(`Za dużo plików (limit ${LIMITS.filesPerAction})`, "error", cx);
return;
}
const known = [];
let problem = "";
for (const file of files) {
const unknown = file.bytes === undefined;
let error = "";
if (file.bytes === undefined) {
error = SIZE_ERROR;
} else {
const check = validate(file);
if (!check.ok) error = check.reason;
}
if (error) problem = error;
else known.push(file);
this.state = reduce(this.state, {
type: "attach",
agent: key,
file: unknown ? { ...file, state: "error", error: SIZE_ERROR } : { ...file, state: "adding" },
file: error ? { ...file, state: "error", error } : { ...file, state: "adding" },
});
}
if (files.some((file) => file.bytes === undefined)) this.notice(SIZE_ERROR, "error");
if (problem) this.notice(problem, "error");
this.scheduleDraftSave(cx);
cx.notify();