@emiyakatuz/crispasr-agent-transcriber 0.3.5 → 0.4.1
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 +11 -6
- package/package.json +1 -1
- package/src/cli.js +32 -5
- package/src/constants.js +127 -4
- package/src/installer.js +204 -7
- package/src/release.js +39 -1
package/README.md
CHANGED
|
@@ -13,14 +13,15 @@ checksum, installs Python/MCP dependencies with `uv`, installs the best
|
|
|
13
13
|
available CrispASR binary (CUDA, then Vulkan, then CPU), and registers the
|
|
14
14
|
plugin in the Codex Personal marketplace.
|
|
15
15
|
|
|
16
|
-
Models are never downloaded
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
Models are never downloaded during install/update. Run the explicit `models`
|
|
17
|
+
command to download the approved recommended bundle into the plugin's `models/`
|
|
18
|
+
directory.
|
|
19
19
|
|
|
20
20
|
## Commands
|
|
21
21
|
|
|
22
22
|
```powershell
|
|
23
23
|
npx @emiyakatuz/crispasr-agent-transcriber@latest install
|
|
24
|
+
npx @emiyakatuz/crispasr-agent-transcriber@latest models
|
|
24
25
|
npx @emiyakatuz/crispasr-agent-transcriber@latest update
|
|
25
26
|
npx @emiyakatuz/crispasr-agent-transcriber@latest doctor
|
|
26
27
|
npx @emiyakatuz/crispasr-agent-transcriber@latest --json doctor
|
|
@@ -30,12 +31,16 @@ npx @emiyakatuz/crispasr-agent-transcriber@latest uninstall
|
|
|
30
31
|
`uninstall` preserves local models, CrispASR binaries, and outputs. Add
|
|
31
32
|
`--purge-data` only when those files should also be removed.
|
|
32
33
|
|
|
34
|
+
Use `models --model-id english-q8` to choose a specific allowlisted quantization
|
|
35
|
+
instead of the default bundle. Use `models --dry-run --json` to inspect the
|
|
36
|
+
download plan without writing model files.
|
|
37
|
+
|
|
33
38
|
## Prerequisites
|
|
34
39
|
|
|
35
40
|
- Node.js 20 or newer
|
|
36
41
|
- [uv](https://docs.astral.sh/uv/)
|
|
37
42
|
- [ffmpeg](https://ffmpeg.org/)
|
|
38
43
|
|
|
39
|
-
Media remains local. This installer downloads code
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
Media remains local. This installer downloads code, CrispASR binaries, and only
|
|
45
|
+
explicitly requested allowlisted model files from the documented sources. It
|
|
46
|
+
never uploads media.
|
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { PACKAGE_NAME, PACKAGE_VERSION } from "./constants.js";
|
|
2
2
|
import { InstallerError } from "./errors.js";
|
|
3
|
-
import { doctor, installPlugin, uninstallPlugin } from "./installer.js";
|
|
3
|
+
import { doctor, downloadModels, installPlugin, uninstallPlugin } from "./installer.js";
|
|
4
4
|
|
|
5
5
|
const HELP = `CrispASR Agent Transcriber installer
|
|
6
6
|
|
|
7
7
|
Usage:
|
|
8
8
|
crispasr-agent-transcriber [install] [options]
|
|
9
9
|
crispasr-agent-transcriber update [options]
|
|
10
|
+
crispasr-agent-transcriber models [options]
|
|
10
11
|
crispasr-agent-transcriber doctor [options]
|
|
11
12
|
crispasr-agent-transcriber uninstall [options]
|
|
12
13
|
|
|
13
14
|
Commands:
|
|
14
15
|
install Install the Codex plugin, MCP dependencies, and CrispASR (default)
|
|
15
16
|
update Update plugin files and the GPU-preferred CrispASR binary
|
|
17
|
+
models Download approved local GGUF models into the plugin models directory
|
|
16
18
|
doctor Check prerequisites, plugin files, CrispASR, and local models
|
|
17
19
|
uninstall Remove managed plugin files and Codex registration
|
|
18
20
|
|
|
@@ -22,6 +24,8 @@ Options:
|
|
|
22
24
|
--release VERSION Install a matching GitHub Release version
|
|
23
25
|
--json Print stable JSON to stdout
|
|
24
26
|
--dry-run Show install/update actions without changing files
|
|
27
|
+
--model-id ID With models, download this model id; repeat for many
|
|
28
|
+
--overwrite-models With models, replace existing local model files
|
|
25
29
|
--skip-crispasr Do not install or update the CrispASR binary
|
|
26
30
|
--skip-deps Do not run uv sync
|
|
27
31
|
--no-marketplace Do not modify the Personal Codex marketplace
|
|
@@ -29,8 +33,8 @@ Options:
|
|
|
29
33
|
-v, --version Print installer version
|
|
30
34
|
-h, --help Show this help
|
|
31
35
|
|
|
32
|
-
Models are never downloaded
|
|
33
|
-
|
|
36
|
+
Models are never downloaded during install/update. Run the models command to
|
|
37
|
+
download the recommended local English, Chinese, and language-detection bundle.
|
|
34
38
|
`;
|
|
35
39
|
|
|
36
40
|
function parseArgs(argv) {
|
|
@@ -38,7 +42,7 @@ function parseArgs(argv) {
|
|
|
38
42
|
let command = null;
|
|
39
43
|
for (let index = 0; index < argv.length; index += 1) {
|
|
40
44
|
const value = argv[index];
|
|
41
|
-
if (["install", "update", "doctor", "uninstall"].includes(value) && !command) {
|
|
45
|
+
if (["install", "update", "models", "doctor", "uninstall"].includes(value) && !command) {
|
|
42
46
|
command = value;
|
|
43
47
|
continue;
|
|
44
48
|
}
|
|
@@ -48,9 +52,10 @@ function parseArgs(argv) {
|
|
|
48
52
|
else if (value === "--skip-deps") options.skipDependencies = true;
|
|
49
53
|
else if (value === "--no-marketplace") options.skipMarketplace = true;
|
|
50
54
|
else if (value === "--purge-data") options.purgeData = true;
|
|
55
|
+
else if (value === "--overwrite-models") options.overwrite = true;
|
|
51
56
|
else if (value === "--help" || value === "-h") options.help = true;
|
|
52
57
|
else if (value === "--version" || value === "-v") options.version = true;
|
|
53
|
-
else if (["--target-dir", "--marketplace-path", "--release"].includes(value)) {
|
|
58
|
+
else if (["--target-dir", "--marketplace-path", "--release", "--model-id"].includes(value)) {
|
|
54
59
|
const next = argv[index + 1];
|
|
55
60
|
if (!next || next.startsWith("--")) {
|
|
56
61
|
throw new InstallerError(`${value} requires a value.`, "invalid_arguments");
|
|
@@ -59,6 +64,10 @@ function parseArgs(argv) {
|
|
|
59
64
|
if (value === "--target-dir") options.targetDir = next;
|
|
60
65
|
if (value === "--marketplace-path") options.marketplacePath = next;
|
|
61
66
|
if (value === "--release") options.releaseVersion = next.replace(/^v/, "");
|
|
67
|
+
if (value === "--model-id") {
|
|
68
|
+
options.modelIds ||= [];
|
|
69
|
+
options.modelIds.push(next);
|
|
70
|
+
}
|
|
62
71
|
} else {
|
|
63
72
|
throw new InstallerError(`Unknown argument: ${value}`, "invalid_arguments");
|
|
64
73
|
}
|
|
@@ -79,6 +88,22 @@ function printHumanResult(result) {
|
|
|
79
88
|
}
|
|
80
89
|
return;
|
|
81
90
|
}
|
|
91
|
+
if (result.command === "models") {
|
|
92
|
+
process.stdout.write(`Models directory: ${result.modelsDir}\n`);
|
|
93
|
+
for (const item of result.results) {
|
|
94
|
+
process.stdout.write(
|
|
95
|
+
`${item.downloaded ? "[downloaded]" : "[skipped]"} ${item.id} -> ${item.path}\n`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
process.stdout.write(`Recommended bundle ready: ${result.ready ? "yes" : "no"}\n`);
|
|
99
|
+
if (!result.ready) {
|
|
100
|
+
process.stdout.write("Missing recommended models:\n");
|
|
101
|
+
for (const model of result.missingModels) {
|
|
102
|
+
process.stdout.write(`- ${model.id}: ${model.url}\n`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
82
107
|
if (result.command === "uninstall") {
|
|
83
108
|
process.stdout.write(
|
|
84
109
|
result.removed ? "Plugin registration and managed files removed.\n" : "Plugin was not installed.\n",
|
|
@@ -149,6 +174,8 @@ export async function main(argv = []) {
|
|
|
149
174
|
let result;
|
|
150
175
|
if (parsed.command === "doctor") {
|
|
151
176
|
result = doctor(parsed.options);
|
|
177
|
+
} else if (parsed.command === "models") {
|
|
178
|
+
result = await downloadModels(parsed.options);
|
|
152
179
|
} else if (parsed.command === "uninstall") {
|
|
153
180
|
result = uninstallPlugin(parsed.options);
|
|
154
181
|
} else {
|
package/src/constants.js
CHANGED
|
@@ -16,21 +16,144 @@ export const PACKAGE_VERSION = packageJson.version;
|
|
|
16
16
|
|
|
17
17
|
export const MODEL_SPECS = [
|
|
18
18
|
{
|
|
19
|
+
id: "english-q4",
|
|
20
|
+
role: "english",
|
|
21
|
+
purpose: "English transcription",
|
|
22
|
+
filename: "cohere-transcribe-q4_k.gguf",
|
|
23
|
+
quantization: "q4_k",
|
|
24
|
+
recommended: true,
|
|
25
|
+
repo: "cstr/cohere-transcribe-03-2026-GGUF",
|
|
26
|
+
description: "Default English model with lower disk and memory use.",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: "english-q5-0",
|
|
30
|
+
role: "english",
|
|
31
|
+
purpose: "English transcription",
|
|
32
|
+
filename: "cohere-transcribe-q5_0.gguf",
|
|
33
|
+
quantization: "q5_0",
|
|
34
|
+
recommended: false,
|
|
35
|
+
repo: "cstr/cohere-transcribe-03-2026-GGUF",
|
|
36
|
+
description: "Higher quality English option than q4_k.",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: "english-q5-1",
|
|
40
|
+
role: "english",
|
|
41
|
+
purpose: "English transcription",
|
|
42
|
+
filename: "cohere-transcribe-q5_1.gguf",
|
|
43
|
+
quantization: "q5_1",
|
|
44
|
+
recommended: false,
|
|
45
|
+
repo: "cstr/cohere-transcribe-03-2026-GGUF",
|
|
46
|
+
description: "Alternate q5 English quantization.",
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: "english-q6",
|
|
50
|
+
role: "english",
|
|
51
|
+
purpose: "English transcription",
|
|
52
|
+
filename: "cohere-transcribe-q6_k.gguf",
|
|
53
|
+
quantization: "q6_k",
|
|
54
|
+
recommended: false,
|
|
55
|
+
repo: "cstr/cohere-transcribe-03-2026-GGUF",
|
|
56
|
+
description: "Larger English model for quality-focused local use.",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
id: "english-q8",
|
|
60
|
+
role: "english",
|
|
61
|
+
purpose: "English transcription",
|
|
62
|
+
filename: "cohere-transcribe-q8_0.gguf",
|
|
63
|
+
quantization: "q8_0",
|
|
64
|
+
recommended: false,
|
|
65
|
+
repo: "cstr/cohere-transcribe-03-2026-GGUF",
|
|
66
|
+
description: "Large English model with less quantization.",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "english-f16",
|
|
70
|
+
role: "english",
|
|
19
71
|
purpose: "English transcription",
|
|
20
72
|
filename: "cohere-transcribe.gguf",
|
|
21
|
-
|
|
73
|
+
quantization: "f16",
|
|
74
|
+
recommended: false,
|
|
75
|
+
repo: "cstr/cohere-transcribe-03-2026-GGUF",
|
|
76
|
+
description: "Largest English option from the upstream GGUF repo.",
|
|
22
77
|
},
|
|
23
78
|
{
|
|
79
|
+
id: "chinese-q4",
|
|
80
|
+
role: "chinese",
|
|
24
81
|
purpose: "Chinese transcription",
|
|
25
82
|
filename: "qwen3-asr-1.7b-q4_k.gguf",
|
|
26
|
-
|
|
83
|
+
quantization: "q4_k",
|
|
84
|
+
recommended: true,
|
|
85
|
+
repo: "cstr/qwen3-asr-1.7b-GGUF",
|
|
86
|
+
description: "Default Chinese model with practical disk and memory use.",
|
|
27
87
|
},
|
|
28
88
|
{
|
|
89
|
+
id: "chinese-q8",
|
|
90
|
+
role: "chinese",
|
|
91
|
+
purpose: "Chinese transcription",
|
|
92
|
+
filename: "qwen3-asr-1.7b-q8_0.gguf",
|
|
93
|
+
quantization: "q8_0",
|
|
94
|
+
recommended: false,
|
|
95
|
+
repo: "cstr/qwen3-asr-1.7b-GGUF",
|
|
96
|
+
description: "Larger Chinese model with less quantization.",
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: "chinese-f16",
|
|
100
|
+
role: "chinese",
|
|
101
|
+
purpose: "Chinese transcription",
|
|
102
|
+
filename: "qwen3-asr-1.7b-f16.gguf",
|
|
103
|
+
quantization: "f16",
|
|
104
|
+
recommended: false,
|
|
105
|
+
repo: "cstr/qwen3-asr-1.7b-GGUF",
|
|
106
|
+
description: "Largest Chinese option from the upstream GGUF repo.",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: "lid-q2",
|
|
110
|
+
role: "lid",
|
|
29
111
|
purpose: "English/Chinese language detection",
|
|
30
112
|
filename: "firered-lid-q2_k.gguf",
|
|
31
|
-
|
|
113
|
+
quantization: "q2_k",
|
|
114
|
+
recommended: false,
|
|
115
|
+
repo: "cstr/firered-lid-GGUF",
|
|
116
|
+
description: "Smallest local language-detection option.",
|
|
32
117
|
},
|
|
33
|
-
|
|
118
|
+
{
|
|
119
|
+
id: "lid-q4",
|
|
120
|
+
role: "lid",
|
|
121
|
+
purpose: "English/Chinese language detection",
|
|
122
|
+
filename: "firered-lid-q4_k.gguf",
|
|
123
|
+
quantization: "q4_k",
|
|
124
|
+
recommended: true,
|
|
125
|
+
repo: "cstr/firered-lid-GGUF",
|
|
126
|
+
description: "Default local language-detection model.",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
id: "lid-q8",
|
|
130
|
+
role: "lid",
|
|
131
|
+
purpose: "English/Chinese language detection",
|
|
132
|
+
filename: "firered-lid-q8_0.gguf",
|
|
133
|
+
quantization: "q8_0",
|
|
134
|
+
recommended: false,
|
|
135
|
+
repo: "cstr/firered-lid-GGUF",
|
|
136
|
+
description: "Larger language-detection option with less quantization.",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "lid-f16",
|
|
140
|
+
role: "lid",
|
|
141
|
+
purpose: "English/Chinese language detection",
|
|
142
|
+
filename: "firered-lid-f16.gguf",
|
|
143
|
+
quantization: "f16",
|
|
144
|
+
recommended: false,
|
|
145
|
+
repo: "cstr/firered-lid-GGUF",
|
|
146
|
+
description: "Largest language-detection option from the upstream GGUF repo.",
|
|
147
|
+
},
|
|
148
|
+
].map((model) => ({
|
|
149
|
+
...model,
|
|
150
|
+
url: `https://huggingface.co/${model.repo}`,
|
|
151
|
+
downloadUrl: `https://huggingface.co/${model.repo}/resolve/main/${model.filename}`,
|
|
152
|
+
}));
|
|
153
|
+
|
|
154
|
+
export const RECOMMENDED_MODEL_IDS = MODEL_SPECS.filter((model) => model.recommended).map(
|
|
155
|
+
(model) => model.id,
|
|
156
|
+
);
|
|
34
157
|
|
|
35
158
|
export const MANAGED_ENTRIES = [
|
|
36
159
|
".codex-plugin",
|
package/src/installer.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
import { Readable } from "node:stream";
|
|
5
|
+
import { pipeline } from "node:stream/promises";
|
|
4
6
|
|
|
5
7
|
import {
|
|
6
8
|
MANAGED_ENTRIES,
|
|
7
9
|
MODEL_SPECS,
|
|
8
10
|
PACKAGE_VERSION,
|
|
9
11
|
PLUGIN_NAME,
|
|
12
|
+
RECOMMENDED_MODEL_IDS,
|
|
10
13
|
defaultMarketplacePath,
|
|
11
14
|
defaultReleaseBase,
|
|
12
15
|
defaultTargetDir,
|
|
@@ -17,10 +20,11 @@ import {
|
|
|
17
20
|
installMarketplaceEntry,
|
|
18
21
|
removeMarketplaceEntry,
|
|
19
22
|
} from "./marketplace.js";
|
|
20
|
-
import { extractZipSafely, fetchReleaseBundle } from "./release.js";
|
|
23
|
+
import { extractZipSafely, fetchReleaseBundle, normalizePluginPermissions } from "./release.js";
|
|
21
24
|
import { crispasrExecutableName, findCommand, runCommand } from "./system.js";
|
|
22
25
|
|
|
23
26
|
const MARKER_FILE = ".crispasr-installer.json";
|
|
27
|
+
const MODEL_MANIFEST = "model-manifest.json";
|
|
24
28
|
const RELEASE_VERSION_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
25
29
|
|
|
26
30
|
function resolvedPath(value) {
|
|
@@ -104,10 +108,14 @@ function removeManagedEntries(targetDir) {
|
|
|
104
108
|
function copyPluginFiles(sourceDir, targetDir) {
|
|
105
109
|
fs.mkdirSync(targetDir, { recursive: true });
|
|
106
110
|
for (const entry of fs.readdirSync(sourceDir)) {
|
|
107
|
-
|
|
111
|
+
const destination = path.join(targetDir, entry);
|
|
112
|
+
// Replace old managed entries rather than merging into previously writable directories.
|
|
113
|
+
fs.rmSync(destination, { recursive: true, force: true });
|
|
114
|
+
fs.cpSync(path.join(sourceDir, entry), destination, {
|
|
108
115
|
recursive: true,
|
|
109
116
|
force: true,
|
|
110
117
|
});
|
|
118
|
+
normalizePluginPermissions(destination);
|
|
111
119
|
}
|
|
112
120
|
}
|
|
113
121
|
|
|
@@ -121,8 +129,9 @@ function writeMarker(targetDir, version, installed = true) {
|
|
|
121
129
|
fs.writeFileSync(
|
|
122
130
|
path.join(targetDir, MARKER_FILE),
|
|
123
131
|
`${JSON.stringify(marker, null, 2)}\n`,
|
|
124
|
-
"utf8",
|
|
132
|
+
{ encoding: "utf8", mode: 0o644 },
|
|
125
133
|
);
|
|
134
|
+
fs.chmodSync(path.join(targetDir, MARKER_FILE), 0o644);
|
|
126
135
|
}
|
|
127
136
|
|
|
128
137
|
function locatePluginSource(extractDir, version) {
|
|
@@ -141,6 +150,15 @@ function locatePluginSource(extractDir, version) {
|
|
|
141
150
|
{ expected: version, actual: manifest.version },
|
|
142
151
|
);
|
|
143
152
|
}
|
|
153
|
+
for (const entry of fs.readdirSync(sourceDir)) {
|
|
154
|
+
if (!MANAGED_ENTRIES.includes(entry) || entry === ".venv") {
|
|
155
|
+
throw new InstallerError(
|
|
156
|
+
"The plugin archive contains an unexpected top-level entry.",
|
|
157
|
+
"invalid_release_bundle",
|
|
158
|
+
{ entry },
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
144
162
|
return sourceDir;
|
|
145
163
|
}
|
|
146
164
|
|
|
@@ -170,6 +188,170 @@ export function inspectModels(targetDir) {
|
|
|
170
188
|
}));
|
|
171
189
|
}
|
|
172
190
|
|
|
191
|
+
function recommendedModels(targetDir) {
|
|
192
|
+
return inspectModels(targetDir).filter((model) => RECOMMENDED_MODEL_IDS.includes(model.id));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function resolveModelPaths(targetDir) {
|
|
196
|
+
const recommended = recommendedModels(targetDir);
|
|
197
|
+
return {
|
|
198
|
+
targetDir,
|
|
199
|
+
modelsDir: path.join(targetDir, "models"),
|
|
200
|
+
ready: recommended.every((model) => model.installed),
|
|
201
|
+
recommendedModelIds: RECOMMENDED_MODEL_IDS,
|
|
202
|
+
englishModel: recommended.find((model) => model.role === "english")?.path || null,
|
|
203
|
+
chineseModel: recommended.find((model) => model.role === "chinese")?.path || null,
|
|
204
|
+
lidModel: recommended.find((model) => model.role === "lid")?.path || null,
|
|
205
|
+
missingModels: recommended.filter((model) => !model.installed),
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function findModelSpec(modelId) {
|
|
210
|
+
const normalized = modelId.toLowerCase();
|
|
211
|
+
const match = MODEL_SPECS.find(
|
|
212
|
+
(model) => model.id === normalized || model.filename.toLowerCase() === normalized,
|
|
213
|
+
);
|
|
214
|
+
if (!match) {
|
|
215
|
+
throw new InstallerError("Unknown CrispASR model id.", "unknown_model", {
|
|
216
|
+
modelId,
|
|
217
|
+
knownIds: MODEL_SPECS.map((model) => model.id),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return match;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
async function writeResponseBody(response, destination) {
|
|
224
|
+
if (response.body) {
|
|
225
|
+
await pipeline(Readable.fromWeb(response.body), fs.createWriteStream(destination));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (response.arrayBuffer) {
|
|
229
|
+
fs.writeFileSync(destination, Buffer.from(await response.arrayBuffer()));
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
throw new InstallerError("The model download response did not include a body.", "empty_model_download");
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function writeModelManifest(modelsDir, entries) {
|
|
236
|
+
const manifestPath = path.join(modelsDir, MODEL_MANIFEST);
|
|
237
|
+
let existing = { models: [] };
|
|
238
|
+
if (fs.existsSync(manifestPath)) {
|
|
239
|
+
try {
|
|
240
|
+
existing = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
241
|
+
} catch {
|
|
242
|
+
existing = { models: [] };
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const byId = new Map(
|
|
246
|
+
(existing.models || []).filter((item) => item.id).map((item) => [item.id, item]),
|
|
247
|
+
);
|
|
248
|
+
for (const entry of entries) byId.set(entry.id, entry);
|
|
249
|
+
const manifest = {
|
|
250
|
+
updatedAt: new Date().toISOString(),
|
|
251
|
+
models: [...byId.values()].sort((a, b) => a.id.localeCompare(b.id)),
|
|
252
|
+
};
|
|
253
|
+
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
|
|
254
|
+
return manifestPath;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function downloadOneModel(spec, modelsDir, options) {
|
|
258
|
+
const destination = path.join(modelsDir, spec.filename);
|
|
259
|
+
if (fs.existsSync(destination) && !options.overwrite) {
|
|
260
|
+
return {
|
|
261
|
+
id: spec.id,
|
|
262
|
+
filename: spec.filename,
|
|
263
|
+
path: destination,
|
|
264
|
+
downloaded: false,
|
|
265
|
+
skipped: true,
|
|
266
|
+
reason: "already_exists",
|
|
267
|
+
url: spec.url,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const fetchImpl = options.fetchImpl || globalThis.fetch;
|
|
272
|
+
if (!fetchImpl) {
|
|
273
|
+
throw new InstallerError("This Node.js runtime does not provide fetch.", "fetch_unavailable");
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const partial = `${destination}.part`;
|
|
277
|
+
try {
|
|
278
|
+
const response = await fetchImpl(spec.downloadUrl);
|
|
279
|
+
if (!response.ok) {
|
|
280
|
+
throw new InstallerError("Model download request failed.", "model_download_failed", {
|
|
281
|
+
modelId: spec.id,
|
|
282
|
+
status: response.status,
|
|
283
|
+
url: spec.downloadUrl,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
await writeResponseBody(response, partial);
|
|
287
|
+
if (options.overwrite) fs.rmSync(destination, { force: true });
|
|
288
|
+
fs.renameSync(partial, destination);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
fs.rmSync(partial, { force: true });
|
|
291
|
+
if (error instanceof InstallerError) throw error;
|
|
292
|
+
throw new InstallerError("Model download failed.", "model_download_failed", {
|
|
293
|
+
modelId: spec.id,
|
|
294
|
+
url: spec.downloadUrl,
|
|
295
|
+
message: error.message,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return {
|
|
300
|
+
id: spec.id,
|
|
301
|
+
role: spec.role,
|
|
302
|
+
filename: spec.filename,
|
|
303
|
+
path: destination,
|
|
304
|
+
downloaded: true,
|
|
305
|
+
skipped: false,
|
|
306
|
+
url: spec.url,
|
|
307
|
+
downloadUrl: spec.downloadUrl,
|
|
308
|
+
downloadedAt: new Date().toISOString(),
|
|
309
|
+
sizeBytes: fs.statSync(destination).size,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export async function downloadModels(options = {}) {
|
|
314
|
+
const homeDir = options.homeDir || os.homedir();
|
|
315
|
+
const targetDir = assertSafeTarget(options.targetDir || defaultTargetDir(homeDir), homeDir);
|
|
316
|
+
const modelsDir = path.join(targetDir, "models");
|
|
317
|
+
const requestedIds = options.modelIds?.length ? options.modelIds : RECOMMENDED_MODEL_IDS;
|
|
318
|
+
const specs = requestedIds.map((modelId) => findModelSpec(modelId));
|
|
319
|
+
|
|
320
|
+
if (options.dryRun) {
|
|
321
|
+
return {
|
|
322
|
+
command: "models",
|
|
323
|
+
dryRun: true,
|
|
324
|
+
targetDir,
|
|
325
|
+
plan: specs.map((spec) => `Download ${spec.id} (${spec.filename}) to ${modelsDir}`),
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
fs.mkdirSync(modelsDir, { recursive: true });
|
|
330
|
+
const results = [];
|
|
331
|
+
for (const spec of specs) {
|
|
332
|
+
results.push(await downloadOneModel(spec, modelsDir, options));
|
|
333
|
+
}
|
|
334
|
+
const downloaded = results.filter((item) => item.downloaded);
|
|
335
|
+
const manifestPath = downloaded.length > 0 ? writeModelManifest(modelsDir, downloaded) : null;
|
|
336
|
+
const paths = resolveModelPaths(targetDir);
|
|
337
|
+
return {
|
|
338
|
+
command: "models",
|
|
339
|
+
targetDir,
|
|
340
|
+
modelsDir,
|
|
341
|
+
modelIds: requestedIds,
|
|
342
|
+
results,
|
|
343
|
+
manifestPath,
|
|
344
|
+
ready: paths.ready,
|
|
345
|
+
recommendedModelIds: RECOMMENDED_MODEL_IDS,
|
|
346
|
+
recommendedPaths: {
|
|
347
|
+
englishModel: paths.englishModel,
|
|
348
|
+
chineseModel: paths.chineseModel,
|
|
349
|
+
lidModel: paths.lidModel,
|
|
350
|
+
},
|
|
351
|
+
missingModels: paths.missingModels,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
173
355
|
function installPlan({ targetDir, version, marketplacePath, update }) {
|
|
174
356
|
return [
|
|
175
357
|
`Download and verify GitHub Release v${version}`,
|
|
@@ -177,7 +359,7 @@ function installPlan({ targetDir, version, marketplacePath, update }) {
|
|
|
177
359
|
"Install Python and MCP dependencies with uv",
|
|
178
360
|
`${update ? "Update" : "Install"} the GPU-preferred CrispASR binary`,
|
|
179
361
|
`Register the Codex Personal marketplace entry in ${marketplacePath}`,
|
|
180
|
-
"Check for the three
|
|
362
|
+
"Check for the three recommended local model files",
|
|
181
363
|
];
|
|
182
364
|
}
|
|
183
365
|
|
|
@@ -197,7 +379,7 @@ export async function installPlugin(options = {}) {
|
|
|
197
379
|
|
|
198
380
|
if (!RELEASE_VERSION_RE.test(version)) {
|
|
199
381
|
throw new InstallerError(
|
|
200
|
-
"Release versions must use semantic version syntax such as 0.
|
|
382
|
+
"Release versions must use semantic version syntax such as 0.4.0.",
|
|
201
383
|
"invalid_release_version",
|
|
202
384
|
{ version },
|
|
203
385
|
);
|
|
@@ -233,6 +415,20 @@ export async function installPlugin(options = {}) {
|
|
|
233
415
|
const sourceDir = locatePluginSource(extractDir, version);
|
|
234
416
|
|
|
235
417
|
progress(`${update ? "Updating" : "Installing"} plugin files...`);
|
|
418
|
+
fs.mkdirSync(targetDir, { recursive: true, mode: 0o755 });
|
|
419
|
+
const targetStat = fs.lstatSync(targetDir);
|
|
420
|
+
if (!targetStat.isDirectory()) {
|
|
421
|
+
throw new InstallerError("The plugin target must be a directory.", "unsafe_target");
|
|
422
|
+
}
|
|
423
|
+
// Keep private roots private: remove shared write access without exposing user data.
|
|
424
|
+
const targetMode = (targetStat.mode & 0o755) | 0o700;
|
|
425
|
+
fs.chmodSync(targetDir, targetMode);
|
|
426
|
+
if (process.platform !== "win32" &&
|
|
427
|
+
(fs.lstatSync(targetDir).mode & 0o7777) !== targetMode) {
|
|
428
|
+
throw new InstallerError("Could not secure the plugin directory.", "unsafe_target", {
|
|
429
|
+
target: targetDir,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
236
432
|
if (readMarker(targetDir)) {
|
|
237
433
|
removeManagedEntries(targetDir);
|
|
238
434
|
}
|
|
@@ -277,7 +473,7 @@ export async function installPlugin(options = {}) {
|
|
|
277
473
|
}
|
|
278
474
|
|
|
279
475
|
const models = inspectModels(targetDir);
|
|
280
|
-
const missingModels = models.filter((model) => !model.installed);
|
|
476
|
+
const missingModels = models.filter((model) => model.recommended && !model.installed);
|
|
281
477
|
return {
|
|
282
478
|
command: update ? "update" : "install",
|
|
283
479
|
targetDir,
|
|
@@ -326,8 +522,9 @@ export function doctor(options = {}) {
|
|
|
326
522
|
path: marketplacePath,
|
|
327
523
|
},
|
|
328
524
|
models: {
|
|
329
|
-
ok: models.every((model) => model.installed),
|
|
525
|
+
ok: models.filter((model) => model.recommended).every((model) => model.installed),
|
|
330
526
|
items: models,
|
|
527
|
+
recommendedModelIds: RECOMMENDED_MODEL_IDS,
|
|
331
528
|
},
|
|
332
529
|
};
|
|
333
530
|
return {
|
package/src/release.js
CHANGED
|
@@ -80,10 +80,48 @@ export function extractZipSafely(archivePath, destination) {
|
|
|
80
80
|
const entries = archive.getEntries();
|
|
81
81
|
for (const entry of entries) {
|
|
82
82
|
assertSafeArchiveEntry(entry.entryName);
|
|
83
|
+
const type = (entry.attr >>> 16) & 0o170000;
|
|
84
|
+
const expectedType = entry.isDirectory ? 0o040000 : 0o100000;
|
|
85
|
+
if (type !== 0 && type !== expectedType) {
|
|
86
|
+
throw new InstallerError(
|
|
87
|
+
"Plugin archives must contain only regular files and directories.",
|
|
88
|
+
"unsafe_archive",
|
|
89
|
+
{ entry: entry.entryName },
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
// The plugin bundle invokes scripts through their interpreter (all files are 0644).
|
|
93
|
+
// Set our policy before adm-zip writes files, including children of directory entries.
|
|
94
|
+
entry.attr = ((expectedType | (entry.isDirectory ? 0o755 : 0o644)) << 16) >>> 0;
|
|
83
95
|
}
|
|
84
96
|
fs.mkdirSync(destination, { recursive: true });
|
|
85
97
|
for (const entry of entries) {
|
|
86
|
-
archive.extractEntryTo(entry, destination, true, true);
|
|
98
|
+
archive.extractEntryTo(entry, destination, true, true, true);
|
|
99
|
+
}
|
|
100
|
+
normalizePluginPermissions(destination);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function normalizePluginPermissions(target) {
|
|
104
|
+
const stat = fs.lstatSync(target);
|
|
105
|
+
if (!stat.isDirectory() && !stat.isFile()) {
|
|
106
|
+
throw new InstallerError(
|
|
107
|
+
"Plugin code must contain only regular files and directories.",
|
|
108
|
+
"unsafe_plugin_entry",
|
|
109
|
+
{ path: target },
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const mode = stat.isDirectory() ? 0o755 : 0o644;
|
|
113
|
+
fs.chmodSync(target, mode);
|
|
114
|
+
if (process.platform !== "win32" && (fs.lstatSync(target).mode & 0o7777) !== mode) {
|
|
115
|
+
throw new InstallerError(
|
|
116
|
+
"Could not establish safe plugin permissions.",
|
|
117
|
+
"unsafe_plugin_permissions",
|
|
118
|
+
{ path: target },
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
if (stat.isDirectory()) {
|
|
122
|
+
for (const entry of fs.readdirSync(target)) {
|
|
123
|
+
normalizePluginPermissions(path.join(target, entry));
|
|
124
|
+
}
|
|
87
125
|
}
|
|
88
126
|
}
|
|
89
127
|
|