@emiyakatuz/crispasr-agent-transcriber 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/package.json +3 -2
- package/src/cli.js +1 -1
- package/src/constants.js +40 -1
- package/src/installer.js +89 -27
- package/src/release-trust.js +5 -0
- package/src/release.js +60 -3
package/README.md
CHANGED
|
@@ -8,10 +8,11 @@ Codex plugin and MCP server.
|
|
|
8
8
|
npx @emiyakatuz/crispasr-agent-transcriber@latest install
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
The installer downloads the matching GitHub Release
|
|
12
|
-
checksum
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
The installer downloads the matching GitHub Release and verifies its SHA-256
|
|
12
|
+
checksum against a digest embedded in the provenance-enabled npm package. It
|
|
13
|
+
then installs Python/MCP dependencies with `uv`, installs the best available
|
|
14
|
+
CrispASR binary (CUDA, then Vulkan, then CPU), and registers the plugin in the
|
|
15
|
+
Codex Personal marketplace.
|
|
15
16
|
|
|
16
17
|
Models are never downloaded during install/update. Run the explicit `models`
|
|
17
18
|
command to download the approved recommended bundle into the plugin's `models/`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emiyakatuz/crispasr-agent-transcriber",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Installer and updater for the local-only CrispASR Codex plugin and MCP server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
15
|
"test": "node --test",
|
|
16
|
-
"pack:check": "npm pack --dry-run"
|
|
16
|
+
"pack:check": "npm pack --dry-run",
|
|
17
|
+
"prepublishOnly": "node scripts/pin-release-trust.js --verify"
|
|
17
18
|
},
|
|
18
19
|
"repository": {
|
|
19
20
|
"type": "git",
|
package/src/cli.js
CHANGED
|
@@ -21,7 +21,7 @@ Commands:
|
|
|
21
21
|
Options:
|
|
22
22
|
--target-dir PATH Plugin directory; use with --no-marketplace if custom
|
|
23
23
|
--marketplace-path PATH Personal Codex marketplace.json path
|
|
24
|
-
--release VERSION Install
|
|
24
|
+
--release VERSION Install the release matching this npm package version
|
|
25
25
|
--json Print stable JSON to stdout
|
|
26
26
|
--dry-run Show install/update actions without changing files
|
|
27
27
|
--model-id ID With models, download this model id; repeat for many
|
package/src/constants.js
CHANGED
|
@@ -20,6 +20,9 @@ export const MODEL_SPECS = [
|
|
|
20
20
|
role: "english",
|
|
21
21
|
purpose: "English transcription",
|
|
22
22
|
filename: "cohere-transcribe-q4_k.gguf",
|
|
23
|
+
revision: "4e98a8c31c95a92d651e60e3bfae4fe29fc6e026",
|
|
24
|
+
sha256: "116f4c4f7ff1b03997100d3a097e13fecd84350555b9979867b241cd6803e4f5",
|
|
25
|
+
sizeBytes: 1289178240,
|
|
23
26
|
quantization: "q4_k",
|
|
24
27
|
recommended: true,
|
|
25
28
|
repo: "cstr/cohere-transcribe-03-2026-GGUF",
|
|
@@ -30,6 +33,9 @@ export const MODEL_SPECS = [
|
|
|
30
33
|
role: "english",
|
|
31
34
|
purpose: "English transcription",
|
|
32
35
|
filename: "cohere-transcribe-q5_0.gguf",
|
|
36
|
+
revision: "4e98a8c31c95a92d651e60e3bfae4fe29fc6e026",
|
|
37
|
+
sha256: "0ee052d15d7f7cbc6831c8816d64880347bd99289600aaaac1e33abf21d9deb6",
|
|
38
|
+
sizeBytes: 1738723200,
|
|
33
39
|
quantization: "q5_0",
|
|
34
40
|
recommended: false,
|
|
35
41
|
repo: "cstr/cohere-transcribe-03-2026-GGUF",
|
|
@@ -40,6 +46,9 @@ export const MODEL_SPECS = [
|
|
|
40
46
|
role: "english",
|
|
41
47
|
purpose: "English transcription",
|
|
42
48
|
filename: "cohere-transcribe-q5_1.gguf",
|
|
49
|
+
revision: "4e98a8c31c95a92d651e60e3bfae4fe29fc6e026",
|
|
50
|
+
sha256: "8c16a55f62e65c47473b01affc965e7bcc7c9f33bbccced1a391b7d41e129753",
|
|
51
|
+
sizeBytes: 1852903296,
|
|
43
52
|
quantization: "q5_1",
|
|
44
53
|
recommended: false,
|
|
45
54
|
repo: "cstr/cohere-transcribe-03-2026-GGUF",
|
|
@@ -50,6 +59,9 @@ export const MODEL_SPECS = [
|
|
|
50
59
|
role: "english",
|
|
51
60
|
purpose: "English transcription",
|
|
52
61
|
filename: "cohere-transcribe-q6_k.gguf",
|
|
62
|
+
revision: "4e98a8c31c95a92d651e60e3bfae4fe29fc6e026",
|
|
63
|
+
sha256: "36ba543ce576587aae88817351cfe122d1ad9e9cfcb5e11d1509ce26095e939d",
|
|
64
|
+
sizeBytes: 1981355904,
|
|
53
65
|
quantization: "q6_k",
|
|
54
66
|
recommended: false,
|
|
55
67
|
repo: "cstr/cohere-transcribe-03-2026-GGUF",
|
|
@@ -60,6 +72,9 @@ export const MODEL_SPECS = [
|
|
|
60
72
|
role: "english",
|
|
61
73
|
purpose: "English transcription",
|
|
62
74
|
filename: "cohere-transcribe-q8_0.gguf",
|
|
75
|
+
revision: "4e98a8c31c95a92d651e60e3bfae4fe29fc6e026",
|
|
76
|
+
sha256: "e725a5ec9b5b9c0b7aba07b071753cae9b39ec3fbaf9f6a622c6810d5a11e3f4",
|
|
77
|
+
sizeBytes: 2423803776,
|
|
63
78
|
quantization: "q8_0",
|
|
64
79
|
recommended: false,
|
|
65
80
|
repo: "cstr/cohere-transcribe-03-2026-GGUF",
|
|
@@ -70,6 +85,9 @@ export const MODEL_SPECS = [
|
|
|
70
85
|
role: "english",
|
|
71
86
|
purpose: "English transcription",
|
|
72
87
|
filename: "cohere-transcribe.gguf",
|
|
88
|
+
revision: "4e98a8c31c95a92d651e60e3bfae4fe29fc6e026",
|
|
89
|
+
sha256: "f38225c97dd8185823167cd5107370cda4bf7f77e5042cae7e254f1e6dabced4",
|
|
90
|
+
sizeBytes: 4136505120,
|
|
73
91
|
quantization: "f16",
|
|
74
92
|
recommended: false,
|
|
75
93
|
repo: "cstr/cohere-transcribe-03-2026-GGUF",
|
|
@@ -80,6 +98,9 @@ export const MODEL_SPECS = [
|
|
|
80
98
|
role: "chinese",
|
|
81
99
|
purpose: "Chinese transcription",
|
|
82
100
|
filename: "qwen3-asr-1.7b-q4_k.gguf",
|
|
101
|
+
revision: "674df5d44b50a63e7102a18895ed20e3f91de301",
|
|
102
|
+
sha256: "ec197cef7ccc589fdcae1becc3f4a3de119d0a41e790b898b519b1a048dad8d4",
|
|
103
|
+
sizeBytes: 1490915200,
|
|
83
104
|
quantization: "q4_k",
|
|
84
105
|
recommended: true,
|
|
85
106
|
repo: "cstr/qwen3-asr-1.7b-GGUF",
|
|
@@ -90,6 +111,9 @@ export const MODEL_SPECS = [
|
|
|
90
111
|
role: "chinese",
|
|
91
112
|
purpose: "Chinese transcription",
|
|
92
113
|
filename: "qwen3-asr-1.7b-q8_0.gguf",
|
|
114
|
+
revision: "674df5d44b50a63e7102a18895ed20e3f91de301",
|
|
115
|
+
sha256: "9851ab996591a2d0cb0efb216002764b509c86bd40c95e613d7b65b8e69c8a6e",
|
|
116
|
+
sizeBytes: 2506723200,
|
|
93
117
|
quantization: "q8_0",
|
|
94
118
|
recommended: false,
|
|
95
119
|
repo: "cstr/qwen3-asr-1.7b-GGUF",
|
|
@@ -100,6 +124,9 @@ export const MODEL_SPECS = [
|
|
|
100
124
|
role: "chinese",
|
|
101
125
|
purpose: "Chinese transcription",
|
|
102
126
|
filename: "qwen3-asr-1.7b-f16.gguf",
|
|
127
|
+
revision: "674df5d44b50a63e7102a18895ed20e3f91de301",
|
|
128
|
+
sha256: "ac6c58f9cb0f2bb22290319cde01b0e25a2c1f1ee69aa2f1a9265f29a8bfc9d7",
|
|
129
|
+
sizeBytes: 4704800576,
|
|
103
130
|
quantization: "f16",
|
|
104
131
|
recommended: false,
|
|
105
132
|
repo: "cstr/qwen3-asr-1.7b-GGUF",
|
|
@@ -110,6 +137,9 @@ export const MODEL_SPECS = [
|
|
|
110
137
|
role: "lid",
|
|
111
138
|
purpose: "English/Chinese language detection",
|
|
112
139
|
filename: "firered-lid-q2_k.gguf",
|
|
140
|
+
revision: "417001762e0c60dc6b0fc5afcb6b28badb9a1b45",
|
|
141
|
+
sha256: "090274b59a2132450fe28a1ba725e4b1f4a099c4eca0ae1e73fcd51b9a4575d6",
|
|
142
|
+
sizeBytes: 366864704,
|
|
113
143
|
quantization: "q2_k",
|
|
114
144
|
recommended: false,
|
|
115
145
|
repo: "cstr/firered-lid-GGUF",
|
|
@@ -120,6 +150,9 @@ export const MODEL_SPECS = [
|
|
|
120
150
|
role: "lid",
|
|
121
151
|
purpose: "English/Chinese language detection",
|
|
122
152
|
filename: "firered-lid-q4_k.gguf",
|
|
153
|
+
revision: "417001762e0c60dc6b0fc5afcb6b28badb9a1b45",
|
|
154
|
+
sha256: "f83eee40c5c00c5de4cca52c91a60c3fcf8608851d44ef0e841fdb2e569770c2",
|
|
155
|
+
sizeBytes: 569688704,
|
|
123
156
|
quantization: "q4_k",
|
|
124
157
|
recommended: true,
|
|
125
158
|
repo: "cstr/firered-lid-GGUF",
|
|
@@ -130,6 +163,9 @@ export const MODEL_SPECS = [
|
|
|
130
163
|
role: "lid",
|
|
131
164
|
purpose: "English/Chinese language detection",
|
|
132
165
|
filename: "firered-lid-q8_0.gguf",
|
|
166
|
+
revision: "417001762e0c60dc6b0fc5afcb6b28badb9a1b45",
|
|
167
|
+
sha256: "416d3e431e6e20bd78e78e545ad6b91fe40d254ac66190d36a4d9127e66aebdb",
|
|
168
|
+
sizeBytes: 1002769024,
|
|
133
169
|
quantization: "q8_0",
|
|
134
170
|
recommended: false,
|
|
135
171
|
repo: "cstr/firered-lid-GGUF",
|
|
@@ -140,6 +176,9 @@ export const MODEL_SPECS = [
|
|
|
140
176
|
role: "lid",
|
|
141
177
|
purpose: "English/Chinese language detection",
|
|
142
178
|
filename: "firered-lid-f16.gguf",
|
|
179
|
+
revision: "417001762e0c60dc6b0fc5afcb6b28badb9a1b45",
|
|
180
|
+
sha256: "f441cf09eb8fa1dc0657ca81aee36572636656e6077375058ce807496566ca7f",
|
|
181
|
+
sizeBytes: 1814794560,
|
|
143
182
|
quantization: "f16",
|
|
144
183
|
recommended: false,
|
|
145
184
|
repo: "cstr/firered-lid-GGUF",
|
|
@@ -148,7 +187,7 @@ export const MODEL_SPECS = [
|
|
|
148
187
|
].map((model) => ({
|
|
149
188
|
...model,
|
|
150
189
|
url: `https://huggingface.co/${model.repo}`,
|
|
151
|
-
downloadUrl: `https://huggingface.co/${model.repo}/resolve
|
|
190
|
+
downloadUrl: `https://huggingface.co/${model.repo}/resolve/${model.revision}/${model.filename}`,
|
|
152
191
|
}));
|
|
153
192
|
|
|
154
193
|
export const RECOMMENDED_MODEL_IDS = MODEL_SPECS.filter((model) => model.recommended).map(
|
package/src/installer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import os from "node:os";
|
|
3
4
|
import path from "node:path";
|
|
4
|
-
import { Readable } from "node:stream";
|
|
5
5
|
import { pipeline } from "node:stream/promises";
|
|
6
6
|
|
|
7
7
|
import {
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
removeMarketplaceEntry,
|
|
22
22
|
} from "./marketplace.js";
|
|
23
23
|
import { extractZipSafely, fetchReleaseBundle, normalizePluginPermissions } from "./release.js";
|
|
24
|
+
import { RELEASE_TRUST } from "./release-trust.js";
|
|
24
25
|
import { crispasrExecutableName, findCommand, runCommand } from "./system.js";
|
|
25
26
|
|
|
26
27
|
const MARKER_FILE = ".crispasr-installer.json";
|
|
@@ -181,10 +182,12 @@ function resolvePrerequisites(options) {
|
|
|
181
182
|
|
|
182
183
|
export function inspectModels(targetDir) {
|
|
183
184
|
const modelsDir = path.join(targetDir, "models");
|
|
185
|
+
const directory = fs.lstatSync(modelsDir, { throwIfNoEntry: false });
|
|
184
186
|
return MODEL_SPECS.map((model) => ({
|
|
185
187
|
...model,
|
|
186
188
|
path: path.join(modelsDir, model.filename),
|
|
187
|
-
installed:
|
|
189
|
+
installed: Boolean(directory?.isDirectory() &&
|
|
190
|
+
fs.lstatSync(path.join(modelsDir, model.filename), { throwIfNoEntry: false })?.isFile()),
|
|
188
191
|
}));
|
|
189
192
|
}
|
|
190
193
|
|
|
@@ -220,22 +223,32 @@ function findModelSpec(modelId) {
|
|
|
220
223
|
return match;
|
|
221
224
|
}
|
|
222
225
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
226
|
+
function modelFileInfo(filename) {
|
|
227
|
+
const info = fs.lstatSync(filename, { throwIfNoEntry: false });
|
|
228
|
+
if (info && !info.isFile()) {
|
|
229
|
+
throw new InstallerError("Model storage requires regular files.", "unsafe_model_path");
|
|
227
230
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
+
return info;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function* verifiedModelBytes(stream, spec) {
|
|
235
|
+
let size = 0;
|
|
236
|
+
const digest = createHash("sha256");
|
|
237
|
+
for await (const chunk of stream) {
|
|
238
|
+
size += chunk.length;
|
|
239
|
+
if (size > spec.sizeBytes) break;
|
|
240
|
+
digest.update(chunk);
|
|
241
|
+
yield chunk;
|
|
242
|
+
}
|
|
243
|
+
if (size !== spec.sizeBytes || digest.digest("hex") !== spec.sha256) {
|
|
244
|
+
throw new InstallerError("Model size or SHA-256 differs from the catalog.", "model_integrity_error");
|
|
231
245
|
}
|
|
232
|
-
throw new InstallerError("The model download response did not include a body.", "empty_model_download");
|
|
233
246
|
}
|
|
234
247
|
|
|
235
248
|
function writeModelManifest(modelsDir, entries) {
|
|
236
249
|
const manifestPath = path.join(modelsDir, MODEL_MANIFEST);
|
|
237
250
|
let existing = { models: [] };
|
|
238
|
-
if (
|
|
251
|
+
if (modelFileInfo(manifestPath)) {
|
|
239
252
|
try {
|
|
240
253
|
existing = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
241
254
|
} catch {
|
|
@@ -245,25 +258,46 @@ function writeModelManifest(modelsDir, entries) {
|
|
|
245
258
|
const byId = new Map(
|
|
246
259
|
(existing.models || []).filter((item) => item.id).map((item) => [item.id, item]),
|
|
247
260
|
);
|
|
248
|
-
|
|
261
|
+
let changed = false;
|
|
262
|
+
for (const entry of entries) {
|
|
263
|
+
const previous = byId.get(entry.id);
|
|
264
|
+
if (previous?.sha256 === entry.sha256 && previous?.sizeBytes === entry.sizeBytes) continue;
|
|
265
|
+
byId.set(entry.id, entry);
|
|
266
|
+
changed = true;
|
|
267
|
+
}
|
|
268
|
+
if (!changed) return manifestPath;
|
|
249
269
|
const manifest = {
|
|
250
270
|
updatedAt: new Date().toISOString(),
|
|
251
271
|
models: [...byId.values()].sort((a, b) => a.id.localeCompare(b.id)),
|
|
252
272
|
};
|
|
253
|
-
|
|
273
|
+
const partial = path.join(modelsDir, `.${MODEL_MANIFEST}.${randomUUID()}.part`);
|
|
274
|
+
try {
|
|
275
|
+
fs.writeFileSync(partial, JSON.stringify(manifest, null, 2) + "\n", { flag: "wx", mode: 0o600 });
|
|
276
|
+
fs.renameSync(partial, manifestPath);
|
|
277
|
+
} finally {
|
|
278
|
+
fs.rmSync(partial, { force: true });
|
|
279
|
+
}
|
|
254
280
|
return manifestPath;
|
|
255
281
|
}
|
|
256
282
|
|
|
257
283
|
async function downloadOneModel(spec, modelsDir, options) {
|
|
258
284
|
const destination = path.join(modelsDir, spec.filename);
|
|
259
|
-
|
|
285
|
+
const publicPath = path.join(options.modelsDir, spec.filename);
|
|
286
|
+
if (modelFileInfo(destination) && !options.overwrite) {
|
|
287
|
+
for await (const _chunk of verifiedModelBytes(fs.createReadStream(destination), spec)) {
|
|
288
|
+
// Consume the local file before reporting a verified cache hit.
|
|
289
|
+
}
|
|
260
290
|
return {
|
|
261
291
|
id: spec.id,
|
|
262
292
|
filename: spec.filename,
|
|
263
|
-
path:
|
|
293
|
+
path: publicPath,
|
|
264
294
|
downloaded: false,
|
|
265
295
|
skipped: true,
|
|
266
296
|
reason: "already_exists",
|
|
297
|
+
role: spec.role,
|
|
298
|
+
sizeBytes: spec.sizeBytes,
|
|
299
|
+
sha256: spec.sha256,
|
|
300
|
+
downloadUrl: spec.downloadUrl,
|
|
267
301
|
url: spec.url,
|
|
268
302
|
};
|
|
269
303
|
}
|
|
@@ -273,7 +307,7 @@ async function downloadOneModel(spec, modelsDir, options) {
|
|
|
273
307
|
throw new InstallerError("This Node.js runtime does not provide fetch.", "fetch_unavailable");
|
|
274
308
|
}
|
|
275
309
|
|
|
276
|
-
const partial = `${destination}.part`;
|
|
310
|
+
const partial = `${destination}.${randomUUID()}.part`;
|
|
277
311
|
try {
|
|
278
312
|
const response = await fetchImpl(spec.downloadUrl);
|
|
279
313
|
if (!response.ok) {
|
|
@@ -283,10 +317,19 @@ async function downloadOneModel(spec, modelsDir, options) {
|
|
|
283
317
|
url: spec.downloadUrl,
|
|
284
318
|
});
|
|
285
319
|
}
|
|
286
|
-
|
|
287
|
-
if (
|
|
320
|
+
const final = new URL(response.url);
|
|
321
|
+
if (final.protocol !== "https:" || final.port || final.username || final.password ||
|
|
322
|
+
!/(^|\.)(huggingface\.co|hf\.co)$/.test(final.hostname)) {
|
|
323
|
+
throw new InstallerError("Untrusted model download origin.", "model_download_origin_invalid");
|
|
324
|
+
}
|
|
325
|
+
if (!response.body) throw new InstallerError("Missing model data.", "empty_model_download");
|
|
326
|
+
options.checkDirectory();
|
|
327
|
+
const fd = fs.openSync(partial, "wx", 0o600);
|
|
328
|
+
await pipeline(verifiedModelBytes(response.body, spec), fs.createWriteStream(partial, { fd }));
|
|
329
|
+
options.checkDirectory();
|
|
288
330
|
fs.renameSync(partial, destination);
|
|
289
331
|
} catch (error) {
|
|
332
|
+
options.checkDirectory();
|
|
290
333
|
fs.rmSync(partial, { force: true });
|
|
291
334
|
if (error instanceof InstallerError) throw error;
|
|
292
335
|
throw new InstallerError("Model download failed.", "model_download_failed", {
|
|
@@ -300,13 +343,14 @@ async function downloadOneModel(spec, modelsDir, options) {
|
|
|
300
343
|
id: spec.id,
|
|
301
344
|
role: spec.role,
|
|
302
345
|
filename: spec.filename,
|
|
303
|
-
path:
|
|
346
|
+
path: publicPath,
|
|
304
347
|
downloaded: true,
|
|
305
348
|
skipped: false,
|
|
306
349
|
url: spec.url,
|
|
307
350
|
downloadUrl: spec.downloadUrl,
|
|
308
351
|
downloadedAt: new Date().toISOString(),
|
|
309
|
-
sizeBytes:
|
|
352
|
+
sizeBytes: spec.sizeBytes,
|
|
353
|
+
sha256: spec.sha256,
|
|
310
354
|
};
|
|
311
355
|
}
|
|
312
356
|
|
|
@@ -327,12 +371,30 @@ export async function downloadModels(options = {}) {
|
|
|
327
371
|
}
|
|
328
372
|
|
|
329
373
|
fs.mkdirSync(modelsDir, { recursive: true });
|
|
374
|
+
const directory = fs.lstatSync(modelsDir, { bigint: true });
|
|
375
|
+
function checkDirectory() {
|
|
376
|
+
const current = fs.lstatSync(modelsDir, { bigint: true });
|
|
377
|
+
if (!current.isDirectory() || current.dev !== directory.dev || current.ino !== directory.ino) {
|
|
378
|
+
throw new InstallerError("Unsafe model directory.", "unsafe_model_path");
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
checkDirectory();
|
|
382
|
+
// Linux permits directory-relative I/O through an open descriptor in procfs.
|
|
383
|
+
const fd = process.platform === "linux"
|
|
384
|
+
? fs.openSync(modelsDir, fs.constants.O_DIRECTORY | fs.constants.O_NOFOLLOW) : null;
|
|
330
385
|
const results = [];
|
|
331
|
-
|
|
332
|
-
|
|
386
|
+
try {
|
|
387
|
+
const root = fd === null ? modelsDir : "/proc/self/fd/" + fd;
|
|
388
|
+
for (const spec of specs) {
|
|
389
|
+
checkDirectory();
|
|
390
|
+
results.push(await downloadOneModel(spec, root, { ...options, modelsDir, checkDirectory }));
|
|
391
|
+
}
|
|
392
|
+
checkDirectory();
|
|
393
|
+
writeModelManifest(root, results);
|
|
394
|
+
} finally {
|
|
395
|
+
if (fd !== null) fs.closeSync(fd);
|
|
333
396
|
}
|
|
334
|
-
const
|
|
335
|
-
const manifestPath = downloaded.length > 0 ? writeModelManifest(modelsDir, downloaded) : null;
|
|
397
|
+
const manifestPath = path.join(modelsDir, MODEL_MANIFEST);
|
|
336
398
|
const paths = resolveModelPaths(targetDir);
|
|
337
399
|
return {
|
|
338
400
|
command: "models",
|
|
@@ -408,6 +470,7 @@ export async function installPlugin(options = {}) {
|
|
|
408
470
|
version,
|
|
409
471
|
releaseBase,
|
|
410
472
|
destinationDir: temporaryDir,
|
|
473
|
+
releaseTrust: options.releaseTrust || RELEASE_TRUST,
|
|
411
474
|
fetchImpl: options.fetchImpl,
|
|
412
475
|
});
|
|
413
476
|
const extractDir = path.join(temporaryDir, "extracted");
|
|
@@ -458,9 +521,8 @@ export async function installPlugin(options = {}) {
|
|
|
458
521
|
[
|
|
459
522
|
"run",
|
|
460
523
|
"python",
|
|
461
|
-
"
|
|
462
|
-
|
|
463
|
-
"--crispasr-bin-dir",
|
|
524
|
+
"-c",
|
|
525
|
+
"from pathlib import Path; import sys; from crispasr_agent_transcriber.crispasr_manager import install_packaged_runtime; install_packaged_runtime(Path(sys.argv[1]))",
|
|
464
526
|
path.join(targetDir, "bin"),
|
|
465
527
|
],
|
|
466
528
|
{ cwd: targetDir, capture: Boolean(options.captureCommands) },
|
package/src/release.js
CHANGED
|
@@ -8,6 +8,12 @@ import AdmZip from "adm-zip";
|
|
|
8
8
|
|
|
9
9
|
import { InstallerError } from "./errors.js";
|
|
10
10
|
|
|
11
|
+
const SHA256_RE = /^[0-9a-f]{64}$/;
|
|
12
|
+
const GITHUB_RELEASE_REDIRECT_ORIGINS = new Set([
|
|
13
|
+
"https://release-assets.githubusercontent.com",
|
|
14
|
+
"https://objects.githubusercontent.com",
|
|
15
|
+
]);
|
|
16
|
+
|
|
11
17
|
export function assertSafeReleaseBase(releaseBase) {
|
|
12
18
|
let parsed;
|
|
13
19
|
try {
|
|
@@ -28,6 +34,35 @@ export function assertSafeReleaseBase(releaseBase) {
|
|
|
28
34
|
return parsed.toString().replace(/\/$/, "");
|
|
29
35
|
}
|
|
30
36
|
|
|
37
|
+
export function assertSafeDownloadRedirect(requestUrl, responseUrl) {
|
|
38
|
+
let requested;
|
|
39
|
+
let final;
|
|
40
|
+
try {
|
|
41
|
+
requested = new URL(requestUrl);
|
|
42
|
+
final = new URL(responseUrl);
|
|
43
|
+
} catch {
|
|
44
|
+
throw new InstallerError(
|
|
45
|
+
"The release download returned an invalid final URL.",
|
|
46
|
+
"unsafe_release_redirect",
|
|
47
|
+
{ url: requestUrl, finalUrl: responseUrl },
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const allowedOrigins = new Set([requested.origin]);
|
|
51
|
+
if (requested.origin === "https://github.com") {
|
|
52
|
+
for (const origin of GITHUB_RELEASE_REDIRECT_ORIGINS) {
|
|
53
|
+
allowedOrigins.add(origin);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (!allowedOrigins.has(final.origin)) {
|
|
57
|
+
throw new InstallerError(
|
|
58
|
+
"The release download redirected to an unapproved origin.",
|
|
59
|
+
"unsafe_release_redirect",
|
|
60
|
+
{ url: requestUrl, finalUrl: responseUrl },
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return final.toString();
|
|
64
|
+
}
|
|
65
|
+
|
|
31
66
|
export async function downloadFile(url, destination, fetchImpl = globalThis.fetch) {
|
|
32
67
|
const response = await fetchImpl(url, {
|
|
33
68
|
headers: { "User-Agent": "crispasr-agent-transcriber-installer" },
|
|
@@ -40,6 +75,7 @@ export async function downloadFile(url, destination, fetchImpl = globalThis.fetc
|
|
|
40
75
|
{ url, status: response.status },
|
|
41
76
|
);
|
|
42
77
|
}
|
|
78
|
+
assertSafeDownloadRedirect(url, response.url);
|
|
43
79
|
await pipeline(Readable.fromWeb(response.body), fs.createWriteStream(destination));
|
|
44
80
|
}
|
|
45
81
|
|
|
@@ -59,6 +95,18 @@ export function expectedChecksum(checksumText, filename) {
|
|
|
59
95
|
return null;
|
|
60
96
|
}
|
|
61
97
|
|
|
98
|
+
export function trustedPluginChecksum(version, releaseTrust) {
|
|
99
|
+
const expected = releaseTrust?.pluginSha256;
|
|
100
|
+
if (releaseTrust?.version !== version || !SHA256_RE.test(expected)) {
|
|
101
|
+
throw new InstallerError(
|
|
102
|
+
"This npm installer does not contain trust data for the requested plugin release.",
|
|
103
|
+
"untrusted_release",
|
|
104
|
+
{ version },
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return expected;
|
|
108
|
+
}
|
|
109
|
+
|
|
62
110
|
export function assertSafeArchiveEntry(entryName) {
|
|
63
111
|
const normalized = entryName.replaceAll("\\", "/");
|
|
64
112
|
const parts = normalized.split("/").filter(Boolean);
|
|
@@ -129,15 +177,16 @@ export async function fetchReleaseBundle({
|
|
|
129
177
|
version,
|
|
130
178
|
releaseBase,
|
|
131
179
|
destinationDir,
|
|
180
|
+
releaseTrust,
|
|
132
181
|
fetchImpl = globalThis.fetch,
|
|
133
182
|
}) {
|
|
183
|
+
const trustedExpected = trustedPluginChecksum(version, releaseTrust);
|
|
134
184
|
const filename = `crispasr-agent-transcriber-plugin-${version}.zip`;
|
|
135
185
|
const archivePath = path.join(destinationDir, filename);
|
|
136
186
|
const checksumPath = path.join(destinationDir, "SHA256SUMS");
|
|
137
187
|
const versionBase = `${assertSafeReleaseBase(releaseBase)}/v${version}`;
|
|
138
188
|
|
|
139
189
|
await downloadFile(`${versionBase}/SHA256SUMS`, checksumPath, fetchImpl);
|
|
140
|
-
await downloadFile(`${versionBase}/${filename}`, archivePath, fetchImpl);
|
|
141
190
|
|
|
142
191
|
const checksumText = fs.readFileSync(checksumPath, "utf8");
|
|
143
192
|
const expected = expectedChecksum(checksumText, filename);
|
|
@@ -148,12 +197,20 @@ export async function fetchReleaseBundle({
|
|
|
148
197
|
{ filename },
|
|
149
198
|
);
|
|
150
199
|
}
|
|
200
|
+
if (expected !== trustedExpected) {
|
|
201
|
+
throw new InstallerError(
|
|
202
|
+
"The release checksum does not match the digest embedded in the npm installer.",
|
|
203
|
+
"untrusted_release_checksum",
|
|
204
|
+
{ filename, expected, trustedExpected },
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
await downloadFile(`${versionBase}/${filename}`, archivePath, fetchImpl);
|
|
151
208
|
const actual = sha256File(archivePath);
|
|
152
|
-
if (actual !==
|
|
209
|
+
if (actual !== trustedExpected) {
|
|
153
210
|
throw new InstallerError(
|
|
154
211
|
"The downloaded plugin archive failed SHA-256 verification.",
|
|
155
212
|
"checksum_mismatch",
|
|
156
|
-
{ filename, expected, actual },
|
|
213
|
+
{ filename, expected: trustedExpected, actual },
|
|
157
214
|
);
|
|
158
215
|
}
|
|
159
216
|
return { archivePath, filename, sha256: actual };
|