broader-vids 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +114 -3
- package/bin/broader-vids.cjs +482 -0
- package/bin/plugin-install.cjs +99 -0
- package/bin/profile-data.cjs +327 -0
- package/bin/runtime-lock.cjs +151 -0
- package/docs/ARCHITECTURE.md +396 -0
- package/docs/REFERENCE.md +1144 -0
- package/docs/SCORING.md +501 -0
- package/docs/WORKFLOW.md +443 -0
- package/package.json +48 -6
- package/plugin.json +28 -0
- package/python/asr-requirements.txt +315 -0
- package/python/broader_vids-0.1.0-py3-none-any.whl +0 -0
- package/python/core-requirements.txt +4 -0
- package/python/evidence-requirements.txt +640 -0
- package/skills/broader-vids/SKILL.md +269 -0
- package/skills/broader-vids/agents/openai.yaml +4 -0
- package/skills/broader-vids-clean/SKILL.md +42 -0
- package/skills/broader-vids-clean/agents/openai.yaml +4 -0
- package/skills/broader-vids-dashboard/SKILL.md +69 -0
- package/skills/broader-vids-dashboard/agents/openai.yaml +4 -0
- package/skills/broader-vids-reset/SKILL.md +42 -0
- package/skills/broader-vids-reset/agents/openai.yaml +4 -0
- package/skills/broader-vids-setup/SKILL.md +193 -0
- package/skills/broader-vids-setup/agents/openai.yaml +4 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 antidemosthenes
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,114 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Broader Vids
|
|
2
|
+
|
|
3
|
+
Broader Vids provides an alternative recommendation algorithm for YouTube and Bilibili.
|
|
4
|
+
It combines your interests, exploration of unfamiliar topics, video quality, and feedback.
|
|
5
|
+
|
|
6
|
+
**The plugin learns from your dashboard ratings and calibrates its internal scoring model weights to your preferences.**
|
|
7
|
+
You can manually exclude creators and tags from future rounds.
|
|
8
|
+
Each complete round recommends ten videos per selected platform.
|
|
9
|
+
|
|
10
|
+
The plugin runs locally through Codex CLI or Codex in the ChatGPT desktop app.
|
|
11
|
+
Recommendations appear in chat. A local dashboard provides ratings, exclusions, and preferences.
|
|
12
|
+
|
|
13
|
+
## Install the plugin
|
|
14
|
+
|
|
15
|
+
Requirements: Windows, PowerShell, Node.js 20 or later with npm, UV, and Codex CLI authenticated with ChatGPT.
|
|
16
|
+
Installation and recommendations require internet access.
|
|
17
|
+
Choose one installation method. Neither method requires a checkout, build, or local folder selection.
|
|
18
|
+
|
|
19
|
+
### From GitHub in the ChatGPT desktop app
|
|
20
|
+
|
|
21
|
+
1. Open the plugin marketplace controls in Codex.
|
|
22
|
+
2. Select **Add marketplace** and its repository or Git URL option.
|
|
23
|
+
3. Enter `https://github.com/antidemosthenes/broader-vids`.
|
|
24
|
+
4. Add or sync the marketplace.
|
|
25
|
+
5. Select **Broader Vids** and install it.
|
|
26
|
+
6. Start a new conversation.
|
|
27
|
+
|
|
28
|
+
The GitHub repository supplies the catalog. Its plugin entry downloads the complete package from npm.
|
|
29
|
+
|
|
30
|
+
### From GitHub in Codex CLI
|
|
31
|
+
|
|
32
|
+
Run these commands in PowerShell:
|
|
33
|
+
|
|
34
|
+
```powershell
|
|
35
|
+
codex plugin marketplace add antidemosthenes/broader-vids --sparse .agents/plugins
|
|
36
|
+
codex plugin add broader-vids@broader-vids
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Start a new conversation after installation.
|
|
40
|
+
|
|
41
|
+
### From npm
|
|
42
|
+
|
|
43
|
+
Run this command in PowerShell:
|
|
44
|
+
|
|
45
|
+
```powershell
|
|
46
|
+
npx --yes broader-vids@0.1.0 plugin install
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
This command registers an npm-backed marketplace and installs the plugin through Codex.
|
|
50
|
+
It installs the skills and dashboard, not only the terminal launcher.
|
|
51
|
+
It does not require the GitHub catalog.
|
|
52
|
+
Restart the desktop app or start a new Codex CLI conversation after installation.
|
|
53
|
+
|
|
54
|
+
The app's Add marketplace field accepts repository URLs, not npm package names.
|
|
55
|
+
Use the npm command above for that installation route.
|
|
56
|
+
See the [official packaging guide](https://developers.openai.com/plugins/build/plugins) for supported plugin sources.
|
|
57
|
+
|
|
58
|
+
## Set up and request recommendations
|
|
59
|
+
|
|
60
|
+
Use this procedure for either platform or both:
|
|
61
|
+
|
|
62
|
+
1. Start a new conversation. Invoke the setup skill from the table below.
|
|
63
|
+
2. Choose YouTube, Bilibili, or both.
|
|
64
|
+
3. Choose calibrated starter preferences, enter your interests, or import a preference file.
|
|
65
|
+
4. Complete the dependency and access checks. Setup gives repair steps for required failures.
|
|
66
|
+
5. Invoke the recommendation skill. Review the links and summaries in chat.
|
|
67
|
+
6. Open the dashboard to mark watched videos and rate their topic, subject, depth, and quality.
|
|
68
|
+
7. Request another round when you want more recommendations.
|
|
69
|
+
|
|
70
|
+
Existing profiles can keep their saved preferences during setup.
|
|
71
|
+
Saving ratings updates the local preference and quality models.
|
|
72
|
+
Their learned weights affect screening and final ranking in later rounds.
|
|
73
|
+
Creator and tag exclusions apply to the next new round.
|
|
74
|
+
The dashboard **Preferences** page lets you edit interests and import or export preferences and learned weights.
|
|
75
|
+
Before a new round, incomplete feedback prompts you to open the dashboard or continue.
|
|
76
|
+
|
|
77
|
+
Both platforms support manual creator and tag exclusions.
|
|
78
|
+
YouTube tag rules match available creator-supplied keyword tags, which differ from visible hashtags.
|
|
79
|
+
Bilibili rules match its video tags.
|
|
80
|
+
Search queries use English for YouTube and Simplified Chinese for Bilibili.
|
|
81
|
+
|
|
82
|
+
| Action | Skill command | Purpose |
|
|
83
|
+
| --- | --- | --- |
|
|
84
|
+
| Setup | `$broader-vids-setup` | Choose platforms and preferences, install required tools, and check access. |
|
|
85
|
+
| Recommendations | `$broader-vids` | Request a round for your saved platforms. |
|
|
86
|
+
| Dashboard | `$broader-vids-dashboard` | Rate videos, manage exclusions, and edit preferences. |
|
|
87
|
+
| Reset | `$broader-vids-reset` | Preview removal of preferences, weights, ratings, and histories while keeping tools and sign-in. |
|
|
88
|
+
| Clean | `$broader-vids-clean` | Preview removal of all managed local data, including tools and sign-in. |
|
|
89
|
+
|
|
90
|
+
Use the command names shown by your host's skill menu.
|
|
91
|
+
Some hosts add the plugin namespace, such as `$broader-vids:broader-vids-dashboard`.
|
|
92
|
+
You can also ask: “Use Broader Vids to recommend videos” or “Use Broader Vids to open my dashboard.”
|
|
93
|
+
Reset and Clean require confirmation. Neither action uninstalls the plugin.
|
|
94
|
+
|
|
95
|
+
## Bilibili access and exclusions
|
|
96
|
+
|
|
97
|
+
Bilibili requires manual sign-in for full-video evidence.
|
|
98
|
+
Setup opens a separate browser window.
|
|
99
|
+
Keep that window open after sign-in and return to chat to report completion.
|
|
100
|
+
The plugin verifies the session and closes the window.
|
|
101
|
+
You can switch accounts later from the dashboard.
|
|
102
|
+
|
|
103
|
+
Bilibili imports your account blacklist after verified sign-in and before new rounds.
|
|
104
|
+
Imported creator exclusions combine with your manual exclusions.
|
|
105
|
+
A failed sync preserves the last complete copy.
|
|
106
|
+
Use **Sync blacklist** in the dashboard to retry.
|
|
107
|
+
|
|
108
|
+
The default 视频翻译 tag exclusion can be removed in the dashboard.
|
|
109
|
+
|
|
110
|
+
See the [workflow](docs/WORKFLOW.md) for recommendation steps and the [scoring guide](docs/SCORING.md) for ranking and learning.
|
|
111
|
+
The [reference](docs/REFERENCE.md) covers terminal commands, troubleshooting, local builds, and maintenance.
|
|
112
|
+
The [architecture](docs/ARCHITECTURE.md) describes the launcher, engine, and local storage.
|
|
113
|
+
|
|
114
|
+
License: [MIT](LICENSE).
|
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const os = require("node:os");
|
|
6
|
+
const path = require("node:path");
|
|
7
|
+
const { createHash, randomUUID } = require("node:crypto");
|
|
8
|
+
const {
|
|
9
|
+
withRuntimeUse,
|
|
10
|
+
withSetup,
|
|
11
|
+
setupInProgress,
|
|
12
|
+
} = require("./runtime-lock.cjs");
|
|
13
|
+
const { spawnSync } = require("node:child_process");
|
|
14
|
+
|
|
15
|
+
function defaultRoot(env = process.env, platform = process.platform) {
|
|
16
|
+
const fallback =
|
|
17
|
+
platform === "win32"
|
|
18
|
+
? path.join(env.USERPROFILE || os.homedir(), "AppData", "Local")
|
|
19
|
+
: path.join(os.homedir(), ".local", "share");
|
|
20
|
+
return path.join(env.LOCALAPPDATA || fallback, "broader-vids");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function dataRoot(args, env = process.env, selected) {
|
|
24
|
+
let override;
|
|
25
|
+
for (let index = 0; index < args.length; index += 1) {
|
|
26
|
+
if (args[index] === "--data-dir") override = args[++index];
|
|
27
|
+
else if (args[index].startsWith("--data-dir="))
|
|
28
|
+
override = args[index].slice("--data-dir=".length);
|
|
29
|
+
else continue;
|
|
30
|
+
if (!override || override.startsWith("--"))
|
|
31
|
+
throw new Error("--data-dir requires a path");
|
|
32
|
+
}
|
|
33
|
+
return path.resolve(
|
|
34
|
+
override || env.BROADER_VIDS_DATA_DIR || selected || defaultRoot(env),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function selectionFile(env = process.env) {
|
|
39
|
+
return path.join(defaultRoot(env), "launcher.json");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function selectedRoot(env = process.env) {
|
|
43
|
+
const file = selectionFile(env);
|
|
44
|
+
if (!fs.existsSync(file)) return undefined;
|
|
45
|
+
const value = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
46
|
+
if (
|
|
47
|
+
!value ||
|
|
48
|
+
typeof value !== "object" ||
|
|
49
|
+
value.version !== 1 ||
|
|
50
|
+
typeof value.data_directory !== "string" ||
|
|
51
|
+
!path.isAbsolute(value.data_directory)
|
|
52
|
+
)
|
|
53
|
+
throw new Error(
|
|
54
|
+
"Invalid saved data selection; use broader-vids data reset or choose a directory with data use.",
|
|
55
|
+
);
|
|
56
|
+
return value.data_directory;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function resolvedRoot(args) {
|
|
60
|
+
const explicit = args.some(
|
|
61
|
+
(value) => value === "--data-dir" || value.startsWith("--data-dir="),
|
|
62
|
+
);
|
|
63
|
+
return dataRoot(
|
|
64
|
+
args,
|
|
65
|
+
process.env,
|
|
66
|
+
explicit || process.env.BROADER_VIDS_DATA_DIR ? undefined : selectedRoot(),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function selectRoot(directory, env = process.env) {
|
|
71
|
+
if (!directory || directory.startsWith("--"))
|
|
72
|
+
throw new Error("data use requires a directory path.");
|
|
73
|
+
if (fs.existsSync(directory) && !fs.statSync(directory).isDirectory())
|
|
74
|
+
throw new Error("Choose a directory, not a file.");
|
|
75
|
+
const target = selectionFile(env);
|
|
76
|
+
const temporary = `${target}.${process.pid}.${Date.now()}.tmp`;
|
|
77
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
78
|
+
try {
|
|
79
|
+
fs.writeFileSync(
|
|
80
|
+
temporary,
|
|
81
|
+
JSON.stringify(
|
|
82
|
+
{ version: 1, data_directory: path.resolve(directory) },
|
|
83
|
+
null,
|
|
84
|
+
2,
|
|
85
|
+
),
|
|
86
|
+
{ flag: "wx", mode: 0o600 },
|
|
87
|
+
);
|
|
88
|
+
fs.renameSync(temporary, target);
|
|
89
|
+
} finally {
|
|
90
|
+
if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function commandIndex(args) {
|
|
95
|
+
let index = 0;
|
|
96
|
+
while (index < args.length) {
|
|
97
|
+
if (args[index] === "--data-dir") index += 2;
|
|
98
|
+
else if (args[index].startsWith("--data-dir=")) index += 1;
|
|
99
|
+
else return index;
|
|
100
|
+
}
|
|
101
|
+
return -1;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function invoke(command, args) {
|
|
105
|
+
const result = spawnSync(command, args, {
|
|
106
|
+
stdio: "inherit",
|
|
107
|
+
shell: false,
|
|
108
|
+
env: { ...process.env, BROADER_VIDS_LAUNCHER: __filename },
|
|
109
|
+
});
|
|
110
|
+
if (result.error)
|
|
111
|
+
throw new Error(
|
|
112
|
+
`Could not launch ${path.basename(command)} (${result.error.code || "unknown error"})`,
|
|
113
|
+
);
|
|
114
|
+
if (result.status !== 0) {
|
|
115
|
+
const error = new Error(
|
|
116
|
+
`${path.basename(command)} did not complete successfully.`,
|
|
117
|
+
);
|
|
118
|
+
error.exitCode = result.status ?? (result.signal === "SIGINT" ? 130 : 1);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function cacheWheel(source, root) {
|
|
124
|
+
const content = fs.readFileSync(source);
|
|
125
|
+
const digest = createHash("sha256").update(content).digest("hex");
|
|
126
|
+
const directory = path.join(root, "wheels", digest);
|
|
127
|
+
const destination = path.join(directory, path.basename(source));
|
|
128
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
129
|
+
if (
|
|
130
|
+
!fs.existsSync(destination) ||
|
|
131
|
+
!fs.readFileSync(destination).equals(content)
|
|
132
|
+
) {
|
|
133
|
+
const temporary = path.join(directory, `.${randomUUID()}.tmp`);
|
|
134
|
+
try {
|
|
135
|
+
fs.writeFileSync(temporary, content, { flag: "wx", mode: 0o600 });
|
|
136
|
+
fs.renameSync(temporary, destination);
|
|
137
|
+
} finally {
|
|
138
|
+
if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return destination;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function bundledWheel(packageRoot, version) {
|
|
145
|
+
const prefix = `broader_vids-${version.replace("-alpha.", "a")}-`;
|
|
146
|
+
const folder = path.join(packageRoot, "python");
|
|
147
|
+
const wheels = fs.existsSync(folder)
|
|
148
|
+
? fs
|
|
149
|
+
.readdirSync(folder)
|
|
150
|
+
.filter((name) => name.startsWith(prefix) && name.endsWith(".whl"))
|
|
151
|
+
: [];
|
|
152
|
+
if (wheels.length !== 1)
|
|
153
|
+
throw new Error(
|
|
154
|
+
"The package needs exactly one matching bundled wheel; in a checkout run: uv build --out-dir python",
|
|
155
|
+
);
|
|
156
|
+
return path.join(folder, wheels[0]);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function wheelDigest(wheel) {
|
|
160
|
+
return createHash("sha256").update(fs.readFileSync(wheel)).digest("hex");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function requirementDigests(packageRoot, groups) {
|
|
164
|
+
return Object.fromEntries(
|
|
165
|
+
groups.map((group) => [
|
|
166
|
+
group,
|
|
167
|
+
createHash("sha256")
|
|
168
|
+
.update(
|
|
169
|
+
fs.readFileSync(
|
|
170
|
+
path.join(packageRoot, "python", `${group}-requirements.txt`),
|
|
171
|
+
),
|
|
172
|
+
)
|
|
173
|
+
.digest("hex"),
|
|
174
|
+
]),
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function validGroups(groups) {
|
|
179
|
+
return (
|
|
180
|
+
Array.isArray(groups) &&
|
|
181
|
+
(JSON.stringify(groups) === JSON.stringify(["core"]) ||
|
|
182
|
+
JSON.stringify(groups) === JSON.stringify(["core", "evidence"]) ||
|
|
183
|
+
JSON.stringify(groups) === JSON.stringify(["core", "evidence", "asr"]))
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function runtimeBuildMatches(runtime, digest, packageRoot) {
|
|
188
|
+
const file = path.join(runtime, "broader-vids-build.json");
|
|
189
|
+
try {
|
|
190
|
+
if (fs.statSync(file).size > 4096) return false;
|
|
191
|
+
const receipt = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
192
|
+
if (
|
|
193
|
+
receipt?.version !== 2 ||
|
|
194
|
+
receipt.wheel_sha256 !== digest ||
|
|
195
|
+
!validGroups(receipt.groups)
|
|
196
|
+
)
|
|
197
|
+
return false;
|
|
198
|
+
const expected = requirementDigests(packageRoot, receipt.groups);
|
|
199
|
+
return (
|
|
200
|
+
JSON.stringify(receipt.requirements_sha256) === JSON.stringify(expected)
|
|
201
|
+
);
|
|
202
|
+
} catch {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function recordRuntimeBuild(runtime, digest, packageRoot, groups) {
|
|
208
|
+
const target = path.join(runtime, "broader-vids-build.json");
|
|
209
|
+
const temporary = path.join(runtime, `.build-${randomUUID()}.tmp`);
|
|
210
|
+
try {
|
|
211
|
+
fs.writeFileSync(
|
|
212
|
+
temporary,
|
|
213
|
+
JSON.stringify({
|
|
214
|
+
version: 2,
|
|
215
|
+
wheel_sha256: digest,
|
|
216
|
+
groups,
|
|
217
|
+
requirements_sha256: requirementDigests(packageRoot, groups),
|
|
218
|
+
}),
|
|
219
|
+
{ flag: "wx", mode: 0o600 },
|
|
220
|
+
);
|
|
221
|
+
fs.renameSync(temporary, target);
|
|
222
|
+
} finally {
|
|
223
|
+
if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function main(args = process.argv.slice(2)) {
|
|
228
|
+
const packageRoot = path.resolve(__dirname, "..");
|
|
229
|
+
const manifest = JSON.parse(
|
|
230
|
+
fs.readFileSync(path.join(packageRoot, "package.json"), "utf8"),
|
|
231
|
+
);
|
|
232
|
+
const index = commandIndex(args);
|
|
233
|
+
if (args[index] === "plugin") {
|
|
234
|
+
if (
|
|
235
|
+
index === 0 &&
|
|
236
|
+
args.length === 2 &&
|
|
237
|
+
["--help", "-h"].includes(args[1])
|
|
238
|
+
) {
|
|
239
|
+
console.log("Usage: broader-vids plugin install");
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (index !== 0 || args.length !== 2 || args[1] !== "install")
|
|
243
|
+
throw new Error(
|
|
244
|
+
"Use broader-vids plugin install without profile arguments.",
|
|
245
|
+
);
|
|
246
|
+
const result = require("./plugin-install.cjs").installPlugin(
|
|
247
|
+
manifest.version,
|
|
248
|
+
invoke,
|
|
249
|
+
);
|
|
250
|
+
console.log(JSON.stringify(result, null, 2));
|
|
251
|
+
console.log(
|
|
252
|
+
"Start a new Codex conversation and invoke the Broader Vids setup skill.",
|
|
253
|
+
);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (args[index] === "data") {
|
|
257
|
+
const operation = args[index + 1] || "show";
|
|
258
|
+
if (operation === "use" && args.length === index + 3)
|
|
259
|
+
selectRoot(args[index + 2]);
|
|
260
|
+
else if (operation === "reset" && args.length === index + 2) {
|
|
261
|
+
const file = selectionFile();
|
|
262
|
+
if (fs.existsSync(file)) fs.unlinkSync(file);
|
|
263
|
+
} else if (operation !== "show" || args.length > index + 2)
|
|
264
|
+
throw new Error("Use data show, data use PATH, or data reset.");
|
|
265
|
+
console.log(
|
|
266
|
+
JSON.stringify(
|
|
267
|
+
{ data_directory: resolvedRoot(args), selection_file: selectionFile() },
|
|
268
|
+
null,
|
|
269
|
+
2,
|
|
270
|
+
),
|
|
271
|
+
);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
const root = resolvedRoot(args);
|
|
275
|
+
const runtime = path.join(root, "runtimes", manifest.version);
|
|
276
|
+
const executable =
|
|
277
|
+
process.platform === "win32"
|
|
278
|
+
? path.join(runtime, "Scripts", "python.exe")
|
|
279
|
+
: path.join(runtime, "bin", "python");
|
|
280
|
+
if (["reset", "clean"].includes(args[index])) {
|
|
281
|
+
const operation = args[index];
|
|
282
|
+
const values = args.slice(index + 1);
|
|
283
|
+
if (values.length === 1 && ["--help", "-h"].includes(values[0])) {
|
|
284
|
+
console.log(
|
|
285
|
+
`Usage: broader-vids [--data-dir PATH] ${operation} [--apply --confirm-path ABSOLUTE_PATH]`,
|
|
286
|
+
);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
let applyChange = false,
|
|
290
|
+
confirmation;
|
|
291
|
+
for (let item = 0; item < values.length; item += 1) {
|
|
292
|
+
if (values[item] === "--apply") applyChange = true;
|
|
293
|
+
else if (values[item] === "--confirm-path") confirmation = values[++item];
|
|
294
|
+
else if (values[item].startsWith("--confirm-path="))
|
|
295
|
+
confirmation = values[item].slice("--confirm-path=".length);
|
|
296
|
+
else
|
|
297
|
+
throw new Error(
|
|
298
|
+
"Use reset or clean with optional --apply --confirm-path ABSOLUTE_PATH.",
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
const data = require("./profile-data.cjs");
|
|
302
|
+
const result = applyChange
|
|
303
|
+
? data.apply(root, operation, packageRoot, confirmation)
|
|
304
|
+
: data.preview(root, operation, packageRoot);
|
|
305
|
+
console.log(JSON.stringify(result, null, 2));
|
|
306
|
+
if (result.status === "partial") process.exitCode = 2;
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (args[commandIndex(args)] === "setup") {
|
|
310
|
+
const sourceWheel = bundledWheel(packageRoot, manifest.version);
|
|
311
|
+
const wheelRoot = path.dirname(sourceWheel);
|
|
312
|
+
return withSetup(root, () => {
|
|
313
|
+
require("./profile-data.cjs").ensureMarker(root);
|
|
314
|
+
const receipt = path.join(runtime, "broader-vids-build.json");
|
|
315
|
+
if (fs.existsSync(receipt)) fs.unlinkSync(receipt);
|
|
316
|
+
if (!fs.existsSync(executable))
|
|
317
|
+
invoke("uv", [
|
|
318
|
+
"venv",
|
|
319
|
+
"--allow-existing",
|
|
320
|
+
"--python",
|
|
321
|
+
">=3.12",
|
|
322
|
+
runtime,
|
|
323
|
+
]);
|
|
324
|
+
const wheel = cacheWheel(sourceWheel, root);
|
|
325
|
+
invoke("uv", [
|
|
326
|
+
"pip",
|
|
327
|
+
"install",
|
|
328
|
+
"--python",
|
|
329
|
+
executable,
|
|
330
|
+
"--reinstall",
|
|
331
|
+
"--no-index",
|
|
332
|
+
"--no-deps",
|
|
333
|
+
wheel,
|
|
334
|
+
]);
|
|
335
|
+
const extras = args.includes("--asr")
|
|
336
|
+
? ["evidence", "asr"]
|
|
337
|
+
: args.includes("--evidence")
|
|
338
|
+
? ["evidence"]
|
|
339
|
+
: [];
|
|
340
|
+
const groups = ["core", ...extras];
|
|
341
|
+
for (const extra of groups) {
|
|
342
|
+
invoke("uv", [
|
|
343
|
+
"pip",
|
|
344
|
+
"install",
|
|
345
|
+
"--python",
|
|
346
|
+
executable,
|
|
347
|
+
"--require-hashes",
|
|
348
|
+
"-r",
|
|
349
|
+
path.join(wheelRoot, `${extra}-requirements.txt`),
|
|
350
|
+
]);
|
|
351
|
+
}
|
|
352
|
+
recordRuntimeBuild(runtime, wheelDigest(wheel), packageRoot, groups);
|
|
353
|
+
console.log(
|
|
354
|
+
JSON.stringify(
|
|
355
|
+
{
|
|
356
|
+
status: "installed",
|
|
357
|
+
runtime,
|
|
358
|
+
data_directory: root,
|
|
359
|
+
next_action:
|
|
360
|
+
"Complete the setup skill and run onboarding complete to verify readiness.",
|
|
361
|
+
},
|
|
362
|
+
null,
|
|
363
|
+
2,
|
|
364
|
+
),
|
|
365
|
+
);
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
if (fs.existsSync(path.join(root, ".reset-pending")))
|
|
369
|
+
throw new Error(
|
|
370
|
+
"A reset is unfinished. Preview reset or clean, then complete that action before using this profile.",
|
|
371
|
+
);
|
|
372
|
+
if (setupInProgress(root)) {
|
|
373
|
+
const error = new Error(
|
|
374
|
+
"Runtime installation holds this profile. Wait for setup to finish. Check surviving child processes before repairing a stale installation lock.",
|
|
375
|
+
);
|
|
376
|
+
error.code = "RUNTIME_BUSY";
|
|
377
|
+
throw error;
|
|
378
|
+
}
|
|
379
|
+
if (!fs.existsSync(executable)) {
|
|
380
|
+
if (
|
|
381
|
+
["preflight", "recommend", "onboarding"].includes(
|
|
382
|
+
args[commandIndex(args)],
|
|
383
|
+
)
|
|
384
|
+
) {
|
|
385
|
+
console.log(
|
|
386
|
+
JSON.stringify(
|
|
387
|
+
{
|
|
388
|
+
status: "setup_required",
|
|
389
|
+
data_directory: root,
|
|
390
|
+
checks: {
|
|
391
|
+
runtime: {
|
|
392
|
+
status: "missing",
|
|
393
|
+
remedy:
|
|
394
|
+
"Run the setup skill, or setup --evidence with this same --data-dir.",
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
null,
|
|
399
|
+
2,
|
|
400
|
+
),
|
|
401
|
+
);
|
|
402
|
+
process.exitCode = 2;
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
throw new Error(
|
|
406
|
+
"Broader Vids runtime is missing; run broader-vids setup --evidence with the same --data-dir first.",
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
return withRuntimeUse(root, () => {
|
|
410
|
+
const stopDashboard =
|
|
411
|
+
args[index] === "dashboard" && args[index + 1] === "stop";
|
|
412
|
+
if (
|
|
413
|
+
!stopDashboard &&
|
|
414
|
+
!runtimeBuildMatches(
|
|
415
|
+
runtime,
|
|
416
|
+
wheelDigest(bundledWheel(packageRoot, manifest.version)),
|
|
417
|
+
packageRoot,
|
|
418
|
+
)
|
|
419
|
+
) {
|
|
420
|
+
const error = new Error(
|
|
421
|
+
"The installed Python engine does not match the bundled build, or its build receipt is missing. Stop the dashboard, then run setup --evidence with this same --data-dir to refresh it. Existing preferences and sign-in stay intact.",
|
|
422
|
+
);
|
|
423
|
+
error.code = "RUNTIME_BUILD_MISMATCH";
|
|
424
|
+
error.data_directory = root;
|
|
425
|
+
throw error;
|
|
426
|
+
}
|
|
427
|
+
return invoke(executable, [
|
|
428
|
+
"-m",
|
|
429
|
+
"broader_vids",
|
|
430
|
+
"--data-dir",
|
|
431
|
+
root,
|
|
432
|
+
...args,
|
|
433
|
+
]);
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
module.exports = {
|
|
438
|
+
defaultRoot,
|
|
439
|
+
dataRoot,
|
|
440
|
+
commandIndex,
|
|
441
|
+
cacheWheel,
|
|
442
|
+
selectedRoot,
|
|
443
|
+
selectRoot,
|
|
444
|
+
bundledWheel,
|
|
445
|
+
wheelDigest,
|
|
446
|
+
runtimeBuildMatches,
|
|
447
|
+
recordRuntimeBuild,
|
|
448
|
+
requirementDigests,
|
|
449
|
+
};
|
|
450
|
+
if (require.main === module) {
|
|
451
|
+
try {
|
|
452
|
+
main();
|
|
453
|
+
} catch (error) {
|
|
454
|
+
if (error.code === "RUNTIME_BUSY")
|
|
455
|
+
console.log(
|
|
456
|
+
JSON.stringify(
|
|
457
|
+
{
|
|
458
|
+
status: "blocked",
|
|
459
|
+
checks: { runtime: { status: "busy", remedy: error.message } },
|
|
460
|
+
},
|
|
461
|
+
null,
|
|
462
|
+
2,
|
|
463
|
+
),
|
|
464
|
+
);
|
|
465
|
+
else if (error.code === "RUNTIME_BUILD_MISMATCH")
|
|
466
|
+
console.log(
|
|
467
|
+
JSON.stringify(
|
|
468
|
+
{
|
|
469
|
+
status: "setup_required",
|
|
470
|
+
data_directory: error.data_directory,
|
|
471
|
+
checks: {
|
|
472
|
+
runtime: { status: "unverified", remedy: error.message },
|
|
473
|
+
},
|
|
474
|
+
},
|
|
475
|
+
null,
|
|
476
|
+
2,
|
|
477
|
+
),
|
|
478
|
+
);
|
|
479
|
+
else console.error(`broader-vids: ${error.message}`);
|
|
480
|
+
process.exitCode = error.exitCode || 2;
|
|
481
|
+
}
|
|
482
|
+
}
|