From 12d6830424d24f5a2ed8056b53a12cc4b978ece2 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 16 Oct 2026 16:20:01 +0200 Subject: feat(assistant): tell a nameless file's kind from its content A script with no suffix staged as 'other' and was refused. A staged file the name says nothing about is now handed to file(1) once, and its mime type gives the kind, so a shell script is code and gets Explain and Review. The daemon makes its own call on the content. Co-Authored-By: Claude Opus 5.5 --- desktop/assistant/test_files.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'desktop/assistant/test_files.js') diff --git a/desktop/assistant/test_files.js b/desktop/assistant/test_files.js index 80a855d..f2a65ca 100644 --- a/desktop/assistant/test_files.js +++ b/desktop/assistant/test_files.js @@ -18,7 +18,7 @@ const assert = require("assert"); const src = fs.readFileSync(__dirname + "/Files.js", "utf8") .replace(/^\.pragma library$/m, ""); -const F = new Function(src + "\nreturn { kind, chats, fromUrl, file, name };")(); +const F = new Function(src + "\nreturn { kind, chats, fromUrl, file, name, fromMime };")(); const cases = { "/a/report.pdf": "pdf", "/a/Report.PDF": "pdf", "/a/x.png": "image", "/a/x.JPEG": "image", @@ -40,4 +40,14 @@ assert.strictEqual(F.fromUrl("file://otherhost/tmp/a.pdf"), ""); assert.strictEqual(F.fromUrl("file:///bad%E0%A4%A"), ""); // malformed escape assert.deepStrictEqual(F.file("/x/y/a b.pdf"), { path: "/x/y/a b.pdf", name: "a b.pdf", kind: "pdf" }); +// A file the name says nothing about is told by its mime type (file -b). +const mimes = { + "text/x-shellscript": "code", "text/x-script.python": "code", "text/x-c": "code", + "text/x-makefile": "code", "application/json": "code", "text/plain": "text", + "text/csv": "text", "text/markdown": "text", "image/png": "image", "application/pdf": "pdf", + "video/mp4": "video", "application/zip": "archive", "application/x-xz": "archive", + "application/octet-stream": "other", "application/x-executable": "other", "": "other", +}; +for (const [m, k] of Object.entries(mimes)) assert.strictEqual(F.fromMime(m), k, m); + console.log("ok"); -- cgit v1.2.3