Jason-approved merge, rebased: git diff 813671596..6219c5c8c from
work/vikunja-19-307, stacked on 295. Business reviewer verdict 84c9c4be
approve on 6219c5c8c; Jason resolved merge decision 17bb9efc via the CLI.
Conflict resolution only. packages/harness/src/tools.mjs conflicted with
row 132 (0e947c216): both sides add a constant after TASK_PAGE_MAX. Kept
row 132's ORGANIZATION_KEYS, then 307's WEB_QUERY_MAX. Three other paths
that refactor also changed merged without conflict. For each, the +/-
lines on the new base equal the source commit's. The other nine paths are
the source blobs. Filbert reviews the rebased diff.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
74 lines
3.2 KiB
JavaScript
74 lines
3.2 KiB
JavaScript
// The plug-in kind registry (REQ-PLUG-1; the first two kinds are
|
|
// REQ-LIMIT-4's). A kind names the exports its modules must provide, the
|
|
// interface version they implement, and whether the organization file
|
|
// switches on one module or a list. Adding a kind, or changing one, is a
|
|
// core change: a reviewed edit to this file.
|
|
|
|
export const NAME = /^[a-z][a-z0-9-]*$/;
|
|
|
|
export const KINDS = Object.freeze({
|
|
// Reads one turn's usage for the limit checks (row 124 converts the first).
|
|
"usage-source": Object.freeze({
|
|
kind: "usage-source", interfaceVersion: 1, exports: Object.freeze(["readTurn"]), switch: "list",
|
|
}),
|
|
// Decides whether a launch may start and whether a running session must stop.
|
|
"limit-check": Object.freeze({
|
|
kind: "limit-check", interfaceVersion: 1, exports: Object.freeze(["mayLaunch", "mustStop"]), switch: "list",
|
|
}),
|
|
// Answers web_search for a role's web tool (REQ-HARN-2, REQ-PLUG-2). The organization file names
|
|
// one source, and the module's name is the choice: harness-builtin, searxng-bundled or
|
|
// searxng-url (technical decision 0b81b0c5). The broker calls `search` with the business's
|
|
// settings and an AbortSignal (`search(settings, query, deps, { signal })`); harness-builtin's `search` only refuses, since the harness serves web itself.
|
|
"search-source": Object.freeze({
|
|
kind: "search-source", interfaceVersion: 1, exports: Object.freeze(["search"]), switch: "one",
|
|
}),
|
|
});
|
|
|
|
export class PluginError extends Error {
|
|
constructor(code, message, name = null) {
|
|
super(message);
|
|
this.code = code;
|
|
this.name = "PluginError";
|
|
this.plugin = name;
|
|
}
|
|
}
|
|
|
|
const raise = (code, message, name) => {
|
|
throw new PluginError(code, message, name);
|
|
};
|
|
|
|
// The module names one kind's setting switches on, checked against the
|
|
// kind's cardinality and the name pattern. A list may be empty.
|
|
export function namesFor(spec, setting, where, fail = raise) {
|
|
if (spec.switch === "one") {
|
|
if (typeof setting !== "string") fail("bad-setting", `${where} must be one module name`);
|
|
} else if (!Array.isArray(setting)) {
|
|
fail("bad-setting", `${where} must be a list of module names`);
|
|
}
|
|
const names = spec.switch === "one" ? [setting] : setting;
|
|
const seen = new Set();
|
|
for (const name of names) {
|
|
if (typeof name !== "string" || !NAME.test(name)) {
|
|
fail("bad-name", `${where} names ${JSON.stringify(name)}, which doesn't match ${NAME}`,
|
|
typeof name === "string" ? name : null);
|
|
}
|
|
if (seen.has(name)) fail("bad-setting", `${where} names ${name} twice`, name);
|
|
seen.add(name);
|
|
}
|
|
return names;
|
|
}
|
|
|
|
// The organization file's `plugins` object: one key per kind, each a known kind.
|
|
export function checkPlugins(value, where, { kinds = KINDS, fail = raise } = {}) {
|
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
fail("bad-setting", `${where} must be an object with one key per kind`);
|
|
}
|
|
for (const [kind, setting] of Object.entries(value)) {
|
|
if (!Object.hasOwn(kinds, kind)) {
|
|
fail("unknown-kind", `${where} names unknown kind ${JSON.stringify(kind)}; adding a kind is a core change`);
|
|
}
|
|
namesFor(kinds[kind], setting, `${where}.${kind}`, fail);
|
|
}
|
|
return value;
|
|
}
|