@coda-console/plugin-check 0.5.9 → 0.5.11
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/check/coda/builtin.json +4 -4
- package/check/coda/components/plugins/agent-plugins.mjs +19 -70
- package/check/coda/components/plugins/plugin-extensions.mjs +1 -70
- package/check/coda/components/plugins/plugin-rules.mjs +120 -513
- package/check/coda/components/plugins/plugin-schema.mjs +177 -0
- package/check/coda/components/plugins/plugin-source-rules.mjs +3 -1
- package/check/coda/components/plugins/schemas/agents.json +50 -0
- package/check/coda/components/plugins/schemas/capabilities.json +16 -0
- package/check/coda/components/plugins/schemas/commands.json +21 -0
- package/check/coda/components/plugins/schemas/common.json +25 -0
- package/check/coda/components/plugins/schemas/composer-modes.json +79 -0
- package/check/coda/components/plugins/schemas/configuration.json +23 -0
- package/check/coda/components/plugins/schemas/endpoints.json +19 -0
- package/check/coda/components/plugins/schemas/environment.json +22 -0
- package/check/coda/components/plugins/schemas/events.json +23 -0
- package/check/coda/components/plugins/schemas/executors.json +26 -0
- package/check/coda/components/plugins/schemas/extension-points.json +57 -0
- package/check/coda/components/plugins/schemas/extensions.json +13 -0
- package/check/coda/components/plugins/schemas/git-credentials.json +17 -0
- package/check/coda/components/plugins/schemas/groups.json +21 -0
- package/check/coda/components/plugins/schemas/instructions.json +9 -0
- package/check/coda/components/plugins/schemas/mcp-servers.json +29 -0
- package/check/coda/components/plugins/schemas/model-providers.json +39 -0
- package/check/coda/components/plugins/schemas/path.json +16 -0
- package/check/coda/components/plugins/schemas/plugin.json +46 -0
- package/check/coda/components/plugins/schemas/repositories.json +7 -0
- package/check/coda/components/plugins/schemas/services.json +9 -0
- package/check/coda/components/plugins/schemas/setting.json +242 -0
- package/check/coda/components/plugins/schemas/setup.json +7 -0
- package/check/coda/components/plugins/schemas/skills.json +15 -0
- package/check/coda/components/plugins/schemas/views.json +30 -0
- package/check/coda/components/session-config/commands.mjs +17 -2
- package/check/coda/contract.json +36 -10
- package/check/coda/domain/errors.mjs +3 -0
- package/package.json +2 -1
- package/check/coda/components/plugins/model-protocols.mjs +0 -39
|
@@ -1,278 +1,109 @@
|
|
|
1
1
|
// Plugins (docs/plugins.md): what Coda installs once for every project, the way VS Code installs an extension. A plugin
|
|
2
|
-
// is a directory with a VS Code style `package.json
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// (
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// Nothing here is Coda's own invention but a few string formats: `coda-agent`, what a new session is started with
|
|
15
|
-
// (agent, model, effort, fast mode, approval mode), `coda-agent-match`, which sessions a row applies to, and `coda-repo`
|
|
16
|
-
// and `coda-directory`, a repository and a directory of the machine, which clients fill in with the same chooser a project
|
|
17
|
-
// is added with. JSON Schema's own `format: duration` (an ISO 8601 duration) is checked as such, and its `writeOnly` marks a
|
|
18
|
-
// secret: a text written and never read back, kept in a file beside the database and given to the plugin's processes as
|
|
19
|
-
// that file's path (`CODA_PLUGIN_SECRETS`).
|
|
20
|
-
import { readFileSync, readdirSync, existsSync, statSync } from 'node:fs';
|
|
21
|
-
import { basename, join, normalize, posix } from 'node:path';
|
|
2
|
+
// is a directory with a VS Code style `package.json`, and the workflows it brings in `.coda/workflows/`. What it may write
|
|
3
|
+
// there is the schemas' to say (plugin-schema.mjs, schemas/): each key of `contributes` is a type with a JSON Schema of its
|
|
4
|
+
// own, and a manifest is right when it is of the types it names. This module reads one that is into what Coda keeps of it:
|
|
5
|
+
// its settings (`contributes.configuration`, declared in JSON Schema), with a value for every project (the plugin's
|
|
6
|
+
// settings) that a project may override, as user and workspace settings do in VS Code, which workflows read as `vars`
|
|
7
|
+
// (`=vars.…`); and what else it brings, each as its schema has it. Besides the schemas only two things are said here,
|
|
8
|
+
// both of the plugin's identity: the ID it has (its manifest's `id`, else its package name, else the one its npm name
|
|
9
|
+
// gives), and that its settings are named under it.
|
|
10
|
+
// A secret (`writeOnly`) is a text written and never read back, kept in a file beside the database and given to the
|
|
11
|
+
// plugin's processes as that file's path (`CODA_PLUGIN_SECRETS`).
|
|
12
|
+
import { readFileSync, readdirSync, existsSync } from 'node:fs';
|
|
13
|
+
import { join, normalize, posix } from 'node:path';
|
|
22
14
|
import { fileURLToPath } from 'node:url';
|
|
23
15
|
import { settings as agentSettings } from '../session-config/commands.mjs';
|
|
24
16
|
import { requireCondition as check, ContractError } from '../../domain/errors.mjs';
|
|
25
17
|
import { isDuration } from '../../domain/duration.mjs';
|
|
26
|
-
import { MODEL_APIS, isModelApi } from './model-protocols.mjs';
|
|
27
18
|
import { AGENT_ID } from '../../domain/values.mjs';
|
|
28
19
|
import { agentDeclarations } from './agent-plugins.mjs';
|
|
29
|
-
import { checkCatalog,
|
|
20
|
+
import { checkCatalog, extensionsFor } from './plugin-extensions.mjs';
|
|
21
|
+
import { manifestProblem, TYPES, valueProblem } from './plugin-schema.mjs';
|
|
30
22
|
import { claims, COMMIT, INTEGRITY, NPM_VERSION, npmPluginId, repoAddress, sourcePath } from './plugin-source-rules.mjs';
|
|
31
23
|
import { readSkillDocument } from './skill-document.mjs';
|
|
32
24
|
import { executorLabels } from '../workflows/executor-labels.mjs';
|
|
33
25
|
|
|
34
|
-
// A setting's name: the plugin's id, then letters and digits after each dot.
|
|
35
|
-
const KEY = /^[a-z][a-z0-9-]*(\.[a-z][A-Za-z0-9]*)+$/;
|
|
36
26
|
const ID = /^[a-z][a-z0-9-]{0,39}$/;
|
|
37
|
-
|
|
38
|
-
// An event's name, `<域>.<名>` as Coda's own are (session.facts); the domains of Coda's own no plugin publishes in.
|
|
39
|
-
const EVENT = /^(?=.{3,100}$)[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/;
|
|
40
|
-
// The domains of the events Coda publishes itself; a plugin's are of a domain of its own.
|
|
27
|
+
// The domains of the events Coda publishes itself; a plugin's are of a domain of its own (schemas/events.json).
|
|
41
28
|
export const CODA_EVENT_DOMAINS = ['workflow', 'session', 'user'];
|
|
42
|
-
// What a plugin tells every agent of a project that has it, kept short: it is in every session's instructions.
|
|
43
|
-
export const INSTRUCTIONS_LIMIT = 200;
|
|
44
|
-
// An environment variable's name, as a plugin gives one (`contributes.environment`).
|
|
45
|
-
export const VARIABLE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
46
29
|
// Plugins that ship with Coda, as VS Code's built-in extensions ship with it: updated with Coda itself.
|
|
47
30
|
export const BUILTIN_DIR = fileURLToPath(new URL('../../resources/plugins/', import.meta.url));
|
|
48
31
|
// The package the backend runs from (the runtime clone's, or the release's), whose npm dependencies may be built-in plugins
|
|
49
32
|
// too (dependencyPlugins).
|
|
50
33
|
const PACKAGE_ROOT = fileURLToPath(new URL('../../../', import.meta.url));
|
|
51
|
-
// What a plugin may contribute to Coda itself; anything else in `contributes` is for
|
|
52
|
-
// take it (the resources plugin's `panels`), refused when none does
|
|
53
|
-
export const CONTRIBUTES =
|
|
54
|
-
'repositories', 'services', 'setup', 'skills', 'environment', 'path', 'endpoints', 'mcpServers', 'views', 'modelProviders', 'executors', 'composerModes'];
|
|
55
|
-
// The string formats a setting may have, beside `coda-agent` (an object) and `coda-agent-match` (a table's row names):
|
|
56
|
-
// `coda-model-provider` names a model service another plugin provides (docs/plugins.md「模型服务」); `coda-model-url` is the
|
|
57
|
-
// address of one, its Key and API in fields beside it (`modelKey`, `modelApi`), which Coda checks (「检查可用模型」).
|
|
58
|
-
const STRING_FORMATS = ['duration', 'coda-repo', 'coda-directory', 'coda-model-provider', 'coda-model-url'];
|
|
34
|
+
// What a plugin may contribute to Coda itself, the types schemas/plugin.json names; anything else in `contributes` is for
|
|
35
|
+
// a point another plugin declares to take it (the resources plugin's `panels`), refused when none does.
|
|
36
|
+
export const CONTRIBUTES = TYPES;
|
|
59
37
|
export const MODEL_PROVIDER = /^[a-z][a-z0-9-]{0,39}\/[a-z][a-z0-9-]{0,39}$/;
|
|
60
38
|
// How many model services a setting of several may name.
|
|
61
39
|
const MODEL_PROVIDERS_AT_MOST = 20;
|
|
62
|
-
// A command's name, as a shell finds it on the PATH; Coda's own come first and are no plugin's.
|
|
63
|
-
const COMMAND = /^[a-z][a-z0-9-]{0,39}$/, CODA_COMMANDS = ['coda-run', 'coda-event', 'coda-resources'];
|
|
64
|
-
// Where in the clients a view may stay (docs/plugins.md「视图」): beside a session.
|
|
65
|
-
export const VIEW_PLACES = ['side', 'page'];
|
|
66
|
-
// What a view's entry in the clients can show (docs/plugins.md「视图」): a count the clients keep themselves, not one the
|
|
67
|
-
// plugin reports. A page's beside its title — `workflow-runs`: the runs going on, or waiting on the user; `machines`: the
|
|
68
|
-
// view's machines and which answer —, a view beside sessions' above the composer — `changes`: what the session changed
|
|
69
|
-
// in its worktree.
|
|
70
|
-
export const VIEW_READOUTS = ['workflow-runs', 'machines', 'changes'];
|
|
71
|
-
// Which sessions a view beside sessions is for, by where they work (docs/plugins.md「视图」): `worktree`, only those in a
|
|
72
|
-
// worktree of their own.
|
|
73
|
-
export const VIEW_CHECKOUTS = ['worktree'];
|
|
74
|
-
// When else than its views' opening the plugin host loads a plugin's module (docs/plugins.md「插件宿主」).
|
|
75
|
-
const ACTIVATION_EVENTS = ['onStartupFinished'];
|
|
76
|
-
// What a view may take over opening (`handles`): the kind of a Coda reference, as `coda://<kind>/…` names it.
|
|
77
|
-
export const REFERENCE_KIND = /^[a-z][a-z0-9-]{0,39}$/;
|
|
78
|
-
// An SF Symbol's name, as a view's icon is given.
|
|
79
|
-
const SYMBOL = /^[a-z0-9]+(\.[a-z0-9]+)*$/;
|
|
80
|
-
|
|
81
|
-
// ---- Declarations ----
|
|
82
|
-
// The JSON Schema Coda reads: a scalar, a choice of several among fixed options (an array of `items.anyOf` constants, as a
|
|
83
|
-
// form's multi-select), several model services (an array of `items` of format `coda-model-provider`, which the
|
|
84
|
-
// machine's model services are offered for), a list of rows (an array of `items` an object of named columns), or an object
|
|
85
|
-
// whose entries all share one schema (VS Code shows such a setting as a table): a single value, an Agent combination, or a
|
|
86
|
-
// row of named columns, each a single value or an Agent combination, secrets among them (docs/plugins.md「类型」). Anything
|
|
87
|
-
// else is refused when the plugin is read, not ignored. `level`: what is read, a setting, a table's entry, or a column of its rows.
|
|
88
|
-
const COLUMN = /^[a-z][A-Za-z0-9]{0,39}$/, OPTION = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
89
40
|
// How many rows a list of them holds.
|
|
90
41
|
const ROWS_AT_MOST = 50;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const extra = Object.keys(value).filter(k => !known.includes(k));
|
|
101
|
-
check(!extra.length, 'invalid_plugin', `${where} 里有 Coda 不支持的键:${extra.join('、')}`);
|
|
102
|
-
check((value.properties === undefined && value.required === undefined) || (value.type === 'object' && value.format === undefined), 'invalid_plugin',
|
|
103
|
-
`${where}:只有一行几列时才写 properties 与 required`);
|
|
104
|
-
// A secret is a text of its own, with nothing to fall back on: what it is cannot be shown, so neither offered nor defaulted.
|
|
105
|
-
check(value.writeOnly === undefined || typeof value.writeOnly === 'boolean', 'invalid_plugin', `${where} 的 writeOnly 须为开或关`);
|
|
106
|
-
check(!value.writeOnly || (value.type === 'string' && value.format === undefined && value.enum === undefined && value.default === undefined),
|
|
107
|
-
'invalid_plugin', `${where}:密文设置(writeOnly)只能是没有 format、enum 与默认值的文本`);
|
|
108
|
-
const agent = value.format === 'coda-agent';
|
|
109
|
-
check(['boolean', 'integer', 'number', 'string', 'object', 'array'].includes(value.type), 'invalid_plugin', `${where} 的 type 不受支持:${value.type}`);
|
|
110
|
-
check((value.items === undefined && value.uniqueItems === undefined) || value.type === 'array', 'invalid_plugin', `${where}:只有多选与一列行(type: array)才写 items 与 uniqueItems`);
|
|
111
|
-
check(value.format === undefined || agent || value.format === 'coda-agent-match' || STRING_FORMATS.includes(value.format), 'invalid_plugin', `${where} 的 format 不受支持:${value.format}`);
|
|
112
|
-
check(!agent || value.type === 'object', 'invalid_plugin', `${where}:coda-agent 是对象`);
|
|
113
|
-
check(!STRING_FORMATS.includes(value.format) || value.type === 'string', 'invalid_plugin', `${where}:${value.format} 是文本`);
|
|
114
|
-
check(value.enum === undefined || (Array.isArray(value.enum) && value.enum.length && ['string', 'integer', 'number'].includes(value.type)), 'invalid_plugin', `${where} 的 enum 无效`);
|
|
115
|
-
// What each option is shown as, as VS Code's settings say it.
|
|
116
|
-
check(value.enumItemLabels === undefined || (Array.isArray(value.enum) && Array.isArray(value.enumItemLabels) && value.enumItemLabels.length === value.enum.length
|
|
117
|
-
&& value.enumItemLabels.every(label => typeof label === 'string' && label.length <= 100)), 'invalid_plugin', `${where} 的 enumItemLabels 须与 enum 一一对应`);
|
|
118
|
-
check((value.modelKey === undefined && value.modelApi === undefined) || value.format === 'coda-model-url', 'invalid_plugin',
|
|
119
|
-
`${where}:modelKey 与 modelApi 只写在 coda-model-url 的地址上`);
|
|
42
|
+
|
|
43
|
+
// ---- Declarations ----
|
|
44
|
+
// A setting as Coda reads its declaration (schemas/setting.json): a scalar, a choice of several among fixed options
|
|
45
|
+
// (`options`), several model services (`format: coda-model-provider`, with the interfaces it takes), a list of rows
|
|
46
|
+
// (`rows`), a row of named columns (`columns`), or a table whose entries all share one declaration (`entries`, its row
|
|
47
|
+
// names `coda-agent-match` when `keys` says so). Option labels and descriptions are kept when there is one for each option.
|
|
48
|
+
// Its default is a value of it, checked as any value is (checkValue).
|
|
49
|
+
function setting(value, where) {
|
|
50
|
+
const labels = list => Array.isArray(list) && value.enum && list.length === value.enum.length && list.every(d => typeof d === 'string');
|
|
120
51
|
const out = { type: value.type, ...(value.format ? { format: value.format } : {}), ...(value.enum ? { enum: value.enum } : {}),
|
|
121
|
-
...(value.enumItemLabels ? { enumItemLabels: value.enumItemLabels } : {}),
|
|
122
|
-
...(Array.isArray(value.enumDescriptions) && value.enum && value.enumDescriptions.length === value.enum.length && value.enumDescriptions.every(d => typeof d === 'string')
|
|
123
|
-
? { enumDescriptions: value.enumDescriptions } : {}),
|
|
52
|
+
...(labels(value.enumItemLabels) ? { enumItemLabels: value.enumItemLabels } : {}), ...(labels(value.enumDescriptions) ? { enumDescriptions: value.enumDescriptions } : {}),
|
|
124
53
|
...(value.minimum !== undefined ? { minimum: value.minimum } : {}), ...(value.maximum !== undefined ? { maximum: value.maximum } : {}),
|
|
125
|
-
...(
|
|
126
|
-
...(
|
|
54
|
+
...(value.description !== undefined ? { description: value.description } : value.markdownDescription !== undefined ? { description: value.markdownDescription } : {}),
|
|
55
|
+
...(value.title !== undefined ? { title: value.title } : {}), ...(value.order !== undefined ? { order: value.order } : {}),
|
|
127
56
|
...(value.writeOnly ? { writeOnly: true } : {}),
|
|
128
57
|
...(value.modelKey !== undefined ? { modelKey: value.modelKey } : {}), ...(value.modelApi !== undefined ? { modelApi: value.modelApi } : {}) };
|
|
129
|
-
if (value.type === 'array' && value.items
|
|
130
|
-
// Several model services (docs/plugins.md「类型」): each `<plugin>/<id>`, chosen among those the machine offers;
|
|
131
|
-
// `modelApis` the interfaces its plugin takes, the only ones offered for it.
|
|
132
|
-
const items = value.items;
|
|
133
|
-
check(value.format === undefined && value.minimum === undefined && value.maximum === undefined, 'invalid_plugin', `${where}:多个模型服务不写 format、minimum 与 maximum`);
|
|
134
|
-
check(value.uniqueItems === undefined || value.uniqueItems === true, 'invalid_plugin', `${where}:多个模型服务的 uniqueItems 只能是 true`);
|
|
135
|
-
check(Object.keys(items).every(k => ['type', 'format', 'modelApis'].includes(k)) && items.type === 'string', 'invalid_plugin',
|
|
136
|
-
`${where}:多个模型服务写 items: { type: string, format: coda-model-provider, modelApis }`);
|
|
137
|
-
check(items.modelApis === undefined || (Array.isArray(items.modelApis) && items.modelApis.length >= 1 && items.modelApis.length <= 10
|
|
138
|
-
&& items.modelApis.every(isModelApi)), 'invalid_plugin', `${where}.items.modelApis 须为 1–10 个接口名,取 ${MODEL_APIS.join('、')}`);
|
|
58
|
+
if (value.type === 'array' && value.items.format === 'coda-model-provider') {
|
|
139
59
|
out.format = 'coda-model-provider';
|
|
140
|
-
if (items.modelApis) out.modelApis = [...new Set(items.modelApis)];
|
|
141
|
-
} else if (value.type === 'array' && value.items
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
out.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
// A choice of several: each option a constant of its own, with what the client shows for it; chosen ones kept in this order.
|
|
151
|
-
check(value.format === undefined && value.minimum === undefined && value.maximum === undefined, 'invalid_plugin', `${where}:多选不写 format、minimum 与 maximum`);
|
|
152
|
-
check(value.uniqueItems === undefined || value.uniqueItems === true, 'invalid_plugin', `${where}:多选的 uniqueItems 只能是 true(每项至多选一次)`);
|
|
153
|
-
const items = value.items, options = items?.anyOf;
|
|
154
|
-
check(items && typeof items === 'object' && !Array.isArray(items) && Object.keys(items).every(k => k === 'anyOf') && Array.isArray(options)
|
|
155
|
-
&& options.length >= 1 && options.length <= 50, 'invalid_plugin', `${where}:多选写 items: { anyOf: [{ const, title, description }] },1–50 项`);
|
|
156
|
-
out.options = options.map((option, i) => {
|
|
157
|
-
check(option && typeof option === 'object' && !Array.isArray(option) && Object.keys(option).every(k => ['const', 'title', 'description'].includes(k))
|
|
158
|
-
&& typeof option.const === 'string' && OPTION.test(option.const), 'invalid_plugin',
|
|
159
|
-
`${where}.items.anyOf[${i}] 须为 { const, title, description },const 只用字母、数字和「._-」`);
|
|
160
|
-
check(['title', 'description'].every(k => option[k] === undefined || (typeof option[k] === 'string' && option[k].length <= 400)), 'invalid_plugin',
|
|
161
|
-
`${where}.items.anyOf[${i}] 的 title 与 description 须为不超过 400 字的文字`);
|
|
162
|
-
return { value: option.const, ...(option.title ? { title: option.title } : {}), ...(option.description ? { description: option.description } : {}) };
|
|
163
|
-
});
|
|
164
|
-
check(new Set(out.options.map(o => o.value)).size === out.options.length, 'invalid_plugin', `${where}:多选的 const 不能重复`);
|
|
165
|
-
} else if (value.type === 'object' && !agent && level === 'entry') {
|
|
166
|
-
// A row of columns: each a single value, the row's `required` ones always there (given, or by their default).
|
|
167
|
-
const columns = value.properties;
|
|
168
|
-
check(columns && typeof columns === 'object' && !Array.isArray(columns) && Object.keys(columns).length >= 1 && Object.keys(columns).length <= 20,
|
|
169
|
-
'invalid_plugin', `${where}:表格的每一项只能是单个值、Agent 组合,或 properties 写明的 1–20 列`);
|
|
170
|
-
out.columns = Object.fromEntries(Object.entries(columns).map(([name, column]) => {
|
|
171
|
-
check(COLUMN.test(name), 'invalid_plugin', `${where} 的列名只用字母和数字,以小写字母开头:${name}`);
|
|
172
|
-
return [name, schema(column, `${where}.properties.${name}`, 'column')];
|
|
173
|
-
}));
|
|
174
|
-
const required = value.required ?? [];
|
|
175
|
-
check(Array.isArray(required) && required.every(name => typeof name === 'string' && Object.hasOwn(out.columns, name)) && new Set(required).size === required.length,
|
|
176
|
-
'invalid_plugin', `${where}.required 须为本行的列名,不重复`);
|
|
177
|
-
modelFields(out.columns, `${where} 的列`);
|
|
178
|
-
if (required.length) out.required = [...required];
|
|
179
|
-
} else if (value.type === 'object' && !agent) {
|
|
180
|
-
out.entries = schema(value.additionalProperties ?? invalidPlugin(`${where} 需要 additionalProperties`), `${where}.additionalProperties`, 'entry');
|
|
181
|
-
if (value.propertyNames !== undefined) {
|
|
182
|
-
check(value.propertyNames && Object.keys(value.propertyNames).every(k => k === 'format') && value.propertyNames.format === 'coda-agent-match',
|
|
183
|
-
'invalid_plugin', `${where}.propertyNames 只支持 format: coda-agent-match`);
|
|
184
|
-
out.keys = 'coda-agent-match';
|
|
185
|
-
}
|
|
60
|
+
if (value.items.modelApis) out.modelApis = [...new Set(value.items.modelApis)];
|
|
61
|
+
} else if (value.type === 'array' && value.items.type === 'object') out.rows = setting(value.items, `${where}.items`);
|
|
62
|
+
else if (value.type === 'array') out.options = value.items.anyOf.map(option => ({ value: option.const,
|
|
63
|
+
...(option.title ? { title: option.title } : {}), ...(option.description ? { description: option.description } : {}) }));
|
|
64
|
+
else if (value.type === 'object' && value.properties) {
|
|
65
|
+
out.columns = Object.fromEntries(Object.entries(value.properties).map(([name, column]) => [name, setting(column, `${where}.properties.${name}`)]));
|
|
66
|
+
if (value.required?.length) out.required = [...value.required];
|
|
67
|
+
} else if (value.type === 'object' && value.format !== 'coda-agent') {
|
|
68
|
+
out.entries = setting(value.additionalProperties, `${where}.additionalProperties`);
|
|
69
|
+
if (value.propertyNames) out.keys = 'coda-agent-match';
|
|
186
70
|
}
|
|
187
71
|
if (value.default !== undefined) out.default = checkValue(out, value.default, `${where} 的默认值`, 'invalid_plugin');
|
|
188
72
|
return out;
|
|
189
73
|
}
|
|
190
|
-
const invalidPlugin = message => { throw new ContractError('invalid_plugin', message); };
|
|
191
|
-
// A group of fields (a row's columns, or a plugin's single settings) has at most one model address (docs/plugins.md
|
|
192
|
-
// 「检查可用模型」), its Key a secret field of the group and its API a text field of it.
|
|
193
|
-
function modelFields(fields, where) {
|
|
194
|
-
const urls = Object.entries(fields).filter(([, field]) => field.format === 'coda-model-url');
|
|
195
|
-
check(urls.length <= 1, 'invalid_plugin', `${where}里至多一个 coda-model-url`);
|
|
196
|
-
for (const [name, field] of urls) {
|
|
197
|
-
check(field.modelKey === undefined || (typeof field.modelKey === 'string' && Object.hasOwn(fields, field.modelKey) && fields[field.modelKey].writeOnly),
|
|
198
|
-
'invalid_plugin', `${where}「${name}」的 modelKey 须为同组的密文`);
|
|
199
|
-
check(field.modelApi === undefined || (typeof field.modelApi === 'string' && Object.hasOwn(fields, field.modelApi) && fields[field.modelApi].type === 'string'
|
|
200
|
-
&& !fields[field.modelApi].writeOnly), 'invalid_plugin', `${where}「${name}」的 modelApi 须为同组的文本`);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
74
|
|
|
204
|
-
// The modes a composer can be put in (docs/plugins.md「输入框模式」): what it shows then — an icon and a title, a line on
|
|
205
|
-
// what sending does, its placeholder and send button —, whom what is sent is for (`agent`: the session's agent, `own` one
|
|
206
|
-
// chosen for it, which a new session runs, `off` none shown), and its parameters, written as settings are. One entered by a
|
|
207
|
-
// character typed first (`trigger`, as `!`) is the text's: it has no parameters, and what is sent in it is the session's.
|
|
208
|
-
// Which composers offer it (`in`) is its own to say: a session's (`session`), and the one of a session not started yet
|
|
209
|
-
// (`new`, the new task's), where what is sent starts that session in it; one whose messages a new session takes is sent
|
|
210
|
-
// from a session, so only a session's.
|
|
211
|
-
export const MODE_AGENTS = ['session', 'own', 'off'];
|
|
212
75
|
// What a plugin tells a session's agent at once (docs/session-contracts.md「顺带告诉」): a text, at most this long.
|
|
213
76
|
const TELL_LIMIT = 4000;
|
|
214
77
|
export const checkTold = text => check(typeof text === 'string' && text.trim() && text.length <= TELL_LIMIT && !text.includes('\0'), 'invalid_input',
|
|
215
78
|
`要告诉的话须为不超过 ${TELL_LIMIT} 字的文字`);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
`${where}.trigger 是一个标点:!#$%&*+:;=?^|~ 之一`);
|
|
235
|
-
check(m.trigger === undefined || (m.parameters === undefined && m.agent !== 'own'), 'invalid_plugin', `${where}:打字进入的模式(trigger)没有参数,也不另选 Agent`);
|
|
236
|
-
check(m.in === undefined || (Array.isArray(m.in) && m.in.length && m.in.every(place => MODE_PLACES.includes(place)) && new Set(m.in).size === m.in.length),
|
|
237
|
-
'invalid_plugin', `${where}.in 是它出现的输入框,取 ${MODE_PLACES.join('、')},不重复`);
|
|
238
|
-
check(m.agent !== 'own' || !m.in?.includes('new'), 'invalid_plugin', `${where}:开新会话的模式(agent: own)要从会话里发出,不能在 new 里`);
|
|
239
|
-
return { id: m.id, title: m.title.trim(), icon: m.icon, ...(m.hint ? { hint: m.hint.trim() } : {}), ...(m.placeholder ? { placeholder: m.placeholder.trim() } : {}),
|
|
240
|
-
...(m.sendLabel ? { sendLabel: m.sendLabel.trim() } : {}), agent: m.agent ?? 'session', ...(m.trigger ? { trigger: m.trigger } : {}),
|
|
241
|
-
in: m.in ? MODE_PLACES.filter(place => m.in.includes(place)) : ['session'],
|
|
242
|
-
// As read, which the clients show; as written (JSON Schema), which its hooks are given (components/composer-modes).
|
|
243
|
-
...(m.parameters !== undefined ? { parameters: modeParameters(m.parameters, `${where}.parameters`), schema: structuredClone(m.parameters) } : {}) };
|
|
244
|
-
});
|
|
245
|
-
check(new Set(out.map(m => m.id)).size === out.length, 'invalid_plugin', 'contributes.composerModes 的 id 不能重复');
|
|
246
|
-
const triggers = out.filter(m => m.trigger).map(m => m.trigger);
|
|
247
|
-
check(new Set(triggers).size === triggers.length, 'invalid_plugin', 'contributes.composerModes 的 trigger 不能重复');
|
|
248
|
-
return out;
|
|
79
|
+
// The modes a composer can be put in (docs/plugins.md「输入框模式」, schemas/composer-modes.json), each with the composers
|
|
80
|
+
// that offer it (`in`, a session's by default) and whom what is sent is for (`agent`, the session's by default); its
|
|
81
|
+
// parameters read as settings are, and as written (JSON Schema), which its hooks are given (components/composer-modes).
|
|
82
|
+
const MODE_PLACES = ['session', 'new'];
|
|
83
|
+
const composerModes = (modes = []) => modes.map((m, i) => ({ id: m.id, title: m.title.trim(), icon: m.icon,
|
|
84
|
+
...(m.hint ? { hint: m.hint.trim() } : {}), ...(m.placeholder ? { placeholder: m.placeholder.trim() } : {}),
|
|
85
|
+
...(m.sendLabel ? { sendLabel: m.sendLabel.trim() } : {}), agent: m.agent ?? 'session', ...(m.trigger ? { trigger: m.trigger } : {}),
|
|
86
|
+
in: m.in ? MODE_PLACES.filter(place => m.in.includes(place)) : ['session'],
|
|
87
|
+
...(m.parameters !== undefined ? { parameters: parametersOf(m.parameters, `contributes.composerModes[${i}].parameters`), schema: structuredClone(m.parameters) } : {}) }));
|
|
88
|
+
// A mode's parameters as read: each a setting, in the order written, which the clients show them in (JSON's objects keep
|
|
89
|
+
// none of their own there); what it cannot go without, `required`.
|
|
90
|
+
function parametersOf(value, where) {
|
|
91
|
+
const ordered = fields => Object.fromEntries(Object.entries(fields).map(([name, spec], i) => [name, { ...spec, order: spec.order ?? i }]));
|
|
92
|
+
const properties = Object.fromEntries(Object.entries(value.properties).map(([name, p], i) => {
|
|
93
|
+
const read = setting(p, `${where}.properties.${name}`);
|
|
94
|
+
return [name, { ...read, ...(read.rows ? { rows: { ...read.rows, columns: ordered(read.rows.columns) } } : {}), order: read.order ?? i }];
|
|
95
|
+
}));
|
|
96
|
+
return { properties, ...(value.required?.length ? { required: [...value.required] } : {}) };
|
|
249
97
|
}
|
|
250
|
-
//
|
|
98
|
+
// Parameters a mode's hook gives while it runs, checked against the same schema a manifest's are.
|
|
251
99
|
export function modeParameters(value, where) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
check(properties && typeof properties === 'object' && !Array.isArray(properties) && Object.keys(properties).length >= 1 && Object.keys(properties).length <= 20,
|
|
256
|
-
'invalid_plugin', `${where}.properties 须为 1–20 个参数`);
|
|
257
|
-
// In the order written, which the clients show them in: JSON's objects keep none of their own there.
|
|
258
|
-
const ordered = (fields, at) => Object.fromEntries(Object.entries(fields).map(([name, spec], i) => [name, { ...spec, order: spec.order ?? at + i }]));
|
|
259
|
-
const out = Object.fromEntries(Object.entries(properties).map(([name, p], i) => {
|
|
260
|
-
check(COLUMN.test(name), 'invalid_plugin', `${where} 的参数名只用字母和数字,以小写字母开头:${name}`);
|
|
261
|
-
const read = schema(p, `${where}.properties.${name}`);
|
|
262
|
-
const rows = read.rows ? { rows: { ...read.rows, columns: ordered(read.rows.columns, 0) } } : {};
|
|
263
|
-
const spec = { ...read, ...rows, order: read.order ?? i };
|
|
264
|
-
const secret = s => s.writeOnly || Object.values(s.columns ?? s.rows?.columns ?? s.entries?.columns ?? {}).some(c => c.writeOnly);
|
|
265
|
-
check(!secret(spec), 'invalid_plugin', `${where}.properties.${name}:参数不能是密文`);
|
|
266
|
-
return [name, spec];
|
|
267
|
-
}));
|
|
268
|
-
const required = value.required ?? [];
|
|
269
|
-
check(Array.isArray(required) && required.every(name => typeof name === 'string' && Object.hasOwn(out, name)) && new Set(required).size === required.length,
|
|
270
|
-
'invalid_plugin', `${where}.required 须为本模式的参数名,不重复`);
|
|
271
|
-
return { properties: out, ...(required.length ? { required: [...required] } : {}) };
|
|
100
|
+
const problem = valueProblem('composer-modes.json#/$defs/parameters', value, where);
|
|
101
|
+
check(!problem, 'invalid_plugin', problem);
|
|
102
|
+
return parametersOf(value, where);
|
|
272
103
|
}
|
|
273
104
|
|
|
274
105
|
// The category it is listed under (docs/plugins.md「商店」): the first of its manifest's `categories`, as VS Code's are
|
|
275
|
-
// written; empty when it names none.
|
|
106
|
+
// written; empty when it names none.
|
|
276
107
|
export const manifestCategory = manifest => Array.isArray(manifest?.categories) && typeof manifest.categories[0] === 'string' ? manifest.categories[0].trim().slice(0, 32) : '';
|
|
277
108
|
// A plugin as its directory declares it. `id` is the one its manifest says (for a package whose name cannot be one: a scoped
|
|
278
109
|
// package's, docs/plugins.md「插件的内容」), else its package name; a package from npm's without one, whatever npm calls it,
|
|
@@ -281,259 +112,64 @@ export function readPlugin(dir, source) {
|
|
|
281
112
|
let manifest;
|
|
282
113
|
try { manifest = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')); }
|
|
283
114
|
catch (e) { throw new ContractError('invalid_plugin', `${dir} 没有可读的 package.json:${e.message}`); }
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
check(properties && typeof properties === 'object', 'invalid_plugin', 'contributes.configuration.properties 须为对象');
|
|
296
|
-
const declared = Object.fromEntries(Object.entries(properties).map(([key, value]) => {
|
|
297
|
-
check(KEY.test(key) && key.split('.')[0] === manifest.name, 'invalid_plugin', `设置名须以「${manifest.name}.」开头,只用字母和数字:${key}`);
|
|
298
|
-
return [key, schema(value, key)];
|
|
115
|
+
check(manifest && typeof manifest === 'object' && !Array.isArray(manifest), 'invalid_plugin', 'package.json 须为对象');
|
|
116
|
+
const problem = manifestProblem(manifest, dir);
|
|
117
|
+
check(!problem, 'invalid_plugin', problem);
|
|
118
|
+
const named = manifest.id !== undefined;
|
|
119
|
+
let id = named ? manifest.id : manifest.name;
|
|
120
|
+
if (!named && source?.package && typeof manifest.name === 'string') try { id = npmPluginId(manifest.name); } catch {}
|
|
121
|
+
check(typeof id === 'string' && ID.test(id), 'invalid_plugin', `package.json 的 ${named ? 'id' : 'name'} 只能用小写字母、数字和「-」`);
|
|
122
|
+
const contributes = manifest.contributes ?? {}, configuration = contributes.configuration ?? {};
|
|
123
|
+
const properties = Object.fromEntries(Object.entries(configuration.properties ?? {}).map(([key, value]) => {
|
|
124
|
+
check(key.split('.')[0] === id, 'invalid_plugin', `设置名须以「${id}.」开头:${key}`);
|
|
125
|
+
return [key, setting(value, key)];
|
|
299
126
|
}));
|
|
300
|
-
modelFields(Object.fromEntries(Object.entries(declared).filter(([, spec]) => spec.type !== 'object')), '单值设置');
|
|
301
|
-
// The settings it cannot work without (docs/plugins.md「必填」), as JSON Schema says it: their names, beside `properties`.
|
|
302
|
-
const required = configuration.required ?? [];
|
|
303
|
-
check(Array.isArray(required) && required.every(key => typeof key === 'string' && Object.hasOwn(declared, key)) && new Set(required).size === required.length,
|
|
304
|
-
'invalid_plugin', 'contributes.configuration.required 须为本插件声明过的设置名的数组,不重复');
|
|
305
127
|
const files = sub => existsSync(join(dir, sub)) ? [...new Set(readdirSync(join(dir, sub)).map(f => /^(.+)\.bpmn$/.exec(f)?.[1]).filter(Boolean))].sort() : [];
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
// When the host loads that module, as VS Code's `activationEvents`: the first time one of its views opens, as by default,
|
|
321
|
-
// or as soon as the backend has started (`onStartupFinished`), for one that works with no view open.
|
|
322
|
-
const activation = manifest.activationEvents ?? [];
|
|
323
|
-
check(Array.isArray(activation) && activation.every(e => ACTIVATION_EVENTS.includes(e)) && new Set(activation).size === activation.length
|
|
324
|
-
&& (!activation.length || main), 'invalid_plugin', `activationEvents 须为 ${ACTIVATION_EVENTS.join('、')} 组成的数组,不重复,且插件须有 main`);
|
|
325
|
-
const instructions = manifest.contributes?.instructions;
|
|
326
|
-
check(instructions === undefined || (typeof instructions === 'string' && instructions.trim() && [...instructions].length <= INSTRUCTIONS_LIMIT), 'invalid_plugin',
|
|
327
|
-
`contributes.instructions 须为不超过 ${INSTRUCTIONS_LIMIT} 字的说明`);
|
|
328
|
-
// The concurrency groups it brings (docs/plugins.md「并发组」): a name any process may take, and the setting of its own that
|
|
329
|
-
// says how many the group lets in at once (an integer).
|
|
330
|
-
const groups = manifest.contributes?.groups ?? [];
|
|
331
|
-
check(Array.isArray(groups) && groups.every(g => g && typeof g === 'object' && Object.keys(g).every(k => ['name', 'capacity'].includes(k))
|
|
332
|
-
&& typeof g.name === 'string' && /^\S{1,100}$/.test(g.name) && declared[g.capacity]?.type === 'integer')
|
|
333
|
-
&& new Set(groups.map(g => g.name)).size === groups.length, 'invalid_plugin',
|
|
334
|
-
'contributes.groups 须为 { name, capacity } 的数组:name 为 1–100 个非空白字符、不重复,capacity 是本插件声明的整数设置');
|
|
335
|
-
// The events it publishes (docs/plugins.md「事件」): a name a workflow subscribes to, whether one starts the workflows
|
|
336
|
-
// subscribed to it (`starts`, as by default) or only reaches the runs going for its subject, and whether it ends its subject
|
|
337
|
-
// (`ends`: a pull request closed), which a run re-run after it is told again.
|
|
338
|
-
const events = manifest.contributes?.events ?? [];
|
|
339
|
-
check(Array.isArray(events) && events.length <= 50 && events.every(e => e && typeof e === 'object' && Object.keys(e).every(k => ['name', 'starts', 'ends'].includes(k))
|
|
340
|
-
&& typeof e.name === 'string' && EVENT.test(e.name) && !CODA_EVENT_DOMAINS.includes(e.name.split('.')[0])
|
|
341
|
-
&& ['starts', 'ends'].every(k => e[k] === undefined || typeof e[k] === 'boolean'))
|
|
342
|
-
&& new Set(events.map(e => e.name)).size === events.length, 'invalid_plugin',
|
|
343
|
-
`contributes.events 须为 { name, starts?, ends? } 的数组,至多 50 个:name 是「<域>.<名>」(小写字母、数字和「_」,以字母开头,不超过 100 个字符,不重复,域不能是 Coda 自己的 ${CODA_EVENT_DOMAINS.join('、')}),starts、ends 是真假值`);
|
|
344
|
-
// The commands it puts on the PATH of what starts in a project it applies to (docs/plugins.md「命令」): a name, and what
|
|
345
|
-
// runs for it (by `sh`, given the arguments; adapters/launch.mjs writeCommands).
|
|
346
|
-
const commands = manifest.contributes?.commands ?? [];
|
|
347
|
-
check(Array.isArray(commands) && commands.every(c => c && typeof c === 'object' && Object.keys(c).every(k => ['name', 'command'].includes(k))
|
|
348
|
-
&& typeof c.name === 'string' && COMMAND.test(c.name) && !CODA_COMMANDS.includes(c.name)
|
|
349
|
-
&& typeof c.command === 'string' && c.command.trim() && c.command.length <= 4000 && !/[\0\r\n]/.test(c.command))
|
|
350
|
-
&& new Set(commands.map(c => c.name)).size === commands.length, 'invalid_plugin',
|
|
351
|
-
`contributes.commands 须为 { name, command } 的数组:name 是命令名(小写字母、数字和「-」,以字母开头,不重复,不能是 Coda 自己的 ${CODA_COMMANDS.join('、')}),command 是一行命令`);
|
|
352
|
-
// The requests clients may send it (docs/plugins.md「端点」): an id, and what answers one (by `sh`, the request on its
|
|
353
|
-
// standard input; components/plugins/endpoints.mjs); one may say which of its settings it checks (`checks`), beside which
|
|
354
|
-
// clients offer to check what is filled in (docs/plugins.md「设置的检查」), one endpoint a setting.
|
|
355
|
-
const endpoints = manifest.contributes?.endpoints ?? [];
|
|
356
|
-
check(Array.isArray(endpoints) && endpoints.length <= 20 && endpoints.every(e => e && typeof e === 'object' && Object.keys(e).every(k => ['id', 'command', 'checks'].includes(k))
|
|
357
|
-
&& typeof e.id === 'string' && COMMAND.test(e.id)
|
|
358
|
-
&& typeof e.command === 'string' && e.command.trim() && e.command.length <= 4000 && !/[\0\r\n]/.test(e.command)
|
|
359
|
-
&& (e.checks === undefined || (typeof e.checks === 'string' && Object.hasOwn(declared, e.checks))))
|
|
360
|
-
&& new Set(endpoints.map(e => e.id)).size === endpoints.length
|
|
361
|
-
&& new Set(endpoints.filter(e => e.checks).map(e => e.checks)).size === endpoints.filter(e => e.checks).length, 'invalid_plugin',
|
|
362
|
-
'contributes.endpoints 须为 { id, command, checks? } 的数组,至多 20 个:id 是小写字母、数字和「-」,以字母开头,不重复;command 是一行命令;checks 是本插件声明的设置名,一个设置至多一个端点检查');
|
|
363
|
-
// The pages the clients open for it (docs/plugins.md「视图」): an id, what the window or page is called, the HTML file
|
|
364
|
-
// in its directory the client starts it from, in a sandbox, where in the clients it stays, with its icon there, and the
|
|
365
|
-
// references it opens in place of the client (`handles`, as a VS Code custom editor takes the files of its type).
|
|
366
|
-
const views = manifest.contributes?.views ?? [];
|
|
367
|
-
check(Array.isArray(views) && views.length <= 10 && views.every(v => v && typeof v === 'object' && Object.keys(v).every(k => ['id', 'title', 'entry', 'in', 'icon', 'handles', 'readout', 'checkout'].includes(k))
|
|
368
|
-
&& typeof v.id === 'string' && COMMAND.test(v.id)
|
|
369
|
-
&& typeof v.title === 'string' && v.title.trim() && [...v.title].length <= 40 && !/[\0\r\n]/.test(v.title)
|
|
370
|
-
&& typeof v.entry === 'string' && /\.html$/.test(v.entry) && !v.entry.startsWith('/') && !normalize(v.entry).split('/').includes('..')
|
|
371
|
-
&& (v.in === undefined || (Array.isArray(v.in) && v.in.every(place => VIEW_PLACES.includes(place)) && new Set(v.in).size === v.in.length))
|
|
372
|
-
&& (v.icon === undefined || (typeof v.icon === 'string' && v.icon.length <= 100 && SYMBOL.test(v.icon)))
|
|
373
|
-
&& (v.handles === undefined || (Array.isArray(v.handles) && v.handles.length <= 8 && v.handles.every(k => typeof k === 'string' && REFERENCE_KIND.test(k))
|
|
374
|
-
&& new Set(v.handles).size === v.handles.length))
|
|
375
|
-
&& (v.readout === undefined || VIEW_READOUTS.includes(v.readout)) && (v.checkout === undefined || VIEW_CHECKOUTS.includes(v.checkout)))
|
|
376
|
-
&& new Set(views.map(v => v.id)).size === views.length, 'invalid_plugin',
|
|
377
|
-
`contributes.views 须为 { id, title, entry, in?, icon?, handles? } 的数组,至多 10 个:id 是小写字母、数字和「-」,以字母开头,不重复;title 是不超过 40 字的一行;entry 是插件目录里的 .html 文件;in 是它常驻的位置(${VIEW_PLACES.join('、')}),不重复;icon 是 SF Symbol 的名字;handles 是它接管打开的引用种类(如 workflow-runs),至多 8 个,不重复;readout 是它的读数(${VIEW_READOUTS.join('、')});checkout 是它只给哪种工作位置的会话(${VIEW_CHECKOUTS.join('、')})`);
|
|
378
|
-
const composerModes = composerModeDeclarations(manifest.contributes?.composerModes);
|
|
379
|
-
const handled = views.flatMap(v => v.handles ?? []);
|
|
380
|
-
check(new Set(handled).size === handled.length, 'invalid_plugin', 'contributes.views:同一种引用只能由一个视图接管');
|
|
381
|
-
for (const v of views) {
|
|
382
|
-
const at = join(dir, v.entry);
|
|
383
|
-
check(existsSync(at) && statSync(at).isFile(), 'invalid_plugin', `视图 ${v.id} 的 ${v.entry} 不存在`);
|
|
384
|
-
}
|
|
385
|
-
// The addresses it gives Git's credentials for (docs/plugins.md「Git 凭据」): an `https://` host, and what runs as Git's
|
|
386
|
-
// credential helper for it (by `sh`, given Git's arguments; adapters/launch.mjs writeCredentialHelpers).
|
|
387
|
-
const gitCredentials = manifest.contributes?.gitCredentials ?? [];
|
|
388
|
-
check(Array.isArray(gitCredentials) && gitCredentials.every(c => c && typeof c === 'object' && Object.keys(c).every(k => ['url', 'command'].includes(k))
|
|
389
|
-
&& typeof c.url === 'string' && /^https:\/\/[a-z0-9.-]+(:\d+)?$/.test(c.url)
|
|
390
|
-
&& typeof c.command === 'string' && c.command.trim() && c.command.length <= 4000 && !/[\0\r\n]/.test(c.command))
|
|
391
|
-
&& new Set(gitCredentials.map(c => c.url)).size === gitCredentials.length, 'invalid_plugin',
|
|
392
|
-
'contributes.gitCredentials 须为 { url, command } 的数组:url 是 https:// 加小写主机名(可带端口,不带路径),不重复;command 是一行命令');
|
|
393
|
-
// The bundled services it turns on (docs/supervisor.md「独立服务进程」): one no installed plugin names does not run.
|
|
394
|
-
const services = manifest.contributes?.services ?? [];
|
|
395
|
-
check(Array.isArray(services) && services.every(id => typeof id === 'string' && NAME.test(id)) && new Set(services).size === services.length,
|
|
396
|
-
'invalid_plugin', 'contributes.services 须为服务 ID 的数组,不重复');
|
|
397
|
-
// The repositories it can list for a client choosing one (docs/plugins.md「仓库来源」): one command, run by `sh` as a
|
|
398
|
-
// panel's is, printing them (components/plugins/repositories.mjs).
|
|
399
|
-
const repositories = manifest.contributes?.repositories;
|
|
400
|
-
check(repositories === undefined || (repositories && typeof repositories === 'object' && !Array.isArray(repositories) && Object.keys(repositories).every(k => k === 'command')
|
|
401
|
-
&& typeof repositories.command === 'string' && repositories.command.trim() && repositories.command.length <= 4000 && !/[\0\r\n]/.test(repositories.command)),
|
|
402
|
-
'invalid_plugin', 'contributes.repositories 须为 { command }:command 是一行命令');
|
|
403
|
-
// What makes this machine ready for it (docs/plugins.md「准备运行环境」): one command, run by `sh` as a panel's is
|
|
404
|
-
// (components/plugins/plugin-setup.mjs) when the user installs or updates it.
|
|
405
|
-
const setup = manifest.contributes?.setup;
|
|
406
|
-
check(setup === undefined || (setup && typeof setup === 'object' && !Array.isArray(setup) && Object.keys(setup).every(k => k === 'command')
|
|
407
|
-
&& typeof setup.command === 'string' && setup.command.trim() && setup.command.length <= 4000 && !/[\0\r\n]/.test(setup.command)),
|
|
408
|
-
'invalid_plugin', 'contributes.setup 须为 { command }:command 是一行命令');
|
|
409
|
-
const skills = skillDeclarations(manifest.contributes?.skills, dir);
|
|
410
|
-
const environment = environmentDeclarations(manifest.contributes?.environment, declared), path = pathDeclarations(manifest.contributes?.path, dir);
|
|
411
|
-
const modelProviders = modelProviderDeclarations(manifest.contributes?.modelProviders, declared);
|
|
412
|
-
const executors = executorDeclarations(manifest.contributes?.executors);
|
|
413
|
-
const mcpServers = mcpDeclarations(manifest.contributes?.mcpServers, declared);
|
|
414
|
-
const dependencies = dependencyDeclarations(manifest.extensionDependencies, manifest.name);
|
|
415
|
-
return { id: manifest.name, displayName: typeof manifest.displayName === 'string' ? manifest.displayName : manifest.name,
|
|
416
|
-
description: typeof manifest.description === 'string' ? manifest.description : '', version: String(manifest.version ?? ''), category: manifestCategory(manifest),
|
|
417
|
-
source, dir, title: typeof configuration.title === 'string' ? configuration.title : manifest.displayName ?? manifest.name, properties: declared,
|
|
418
|
-
...(main ? { main: posix.normalize(main) } : {}), ...(activation.includes('onStartupFinished') ? { startup: true } : {}),
|
|
419
|
-
...(required.length ? { required: [...required] } : {}), workflows,
|
|
420
|
-
capabilities, services: [...services], groups: groups.map(g => ({ name: g.name, capacity: g.capacity })), commands: commands.map(c => ({ name: c.name, command: c.command })),
|
|
421
|
-
...(events.length ? { events: events.map(e => ({ name: e.name, starts: e.starts !== false, ...(e.ends ? { ends: true } : {}) })) } : {}),
|
|
422
|
-
gitCredentials: gitCredentials.map(c => ({ url: c.url, command: c.command })),
|
|
423
|
-
endpoints: endpoints.map(e => ({ id: e.id, command: e.command, ...(e.checks ? { checks: e.checks } : {}) })),
|
|
128
|
+
const required = configuration.required ?? [], activation = manifest.activationEvents ?? [], dependencies = manifest.extensionDependencies ?? [];
|
|
129
|
+
const displayName = typeof manifest.displayName === 'string' ? manifest.displayName : id;
|
|
130
|
+
// What it writes under keys of `contributes` that are none of Coda's: for the points other plugins declare (checkCatalog).
|
|
131
|
+
const offers = Object.fromEntries(Object.entries(contributes).filter(([key]) => !TYPES.includes(key)));
|
|
132
|
+
return { id, displayName, description: typeof manifest.description === 'string' ? manifest.description : '', version: String(manifest.version ?? ''),
|
|
133
|
+
category: manifestCategory(manifest), source, dir, title: typeof configuration.title === 'string' ? configuration.title : displayName, properties,
|
|
134
|
+
...(manifest.main ? { main: posix.normalize(manifest.main) } : {}), ...(activation.includes('onStartupFinished') ? { startup: true } : {}),
|
|
135
|
+
...(required.length ? { required: [...required] } : {}), workflows: files('.coda/workflows'),
|
|
136
|
+
capabilities: [...(contributes.capabilities ?? [])].sort(), services: [...(contributes.services ?? [])],
|
|
137
|
+
groups: (contributes.groups ?? []).map(g => ({ name: g.name, capacity: g.capacity })),
|
|
138
|
+
commands: (contributes.commands ?? []).map(c => ({ name: c.name, command: c.command })),
|
|
139
|
+
...(contributes.events?.length ? { events: contributes.events.map(e => ({ name: e.name, starts: e.starts !== false, ...(e.ends ? { ends: true } : {}) })) } : {}),
|
|
140
|
+
gitCredentials: (contributes.gitCredentials ?? []).map(c => ({ url: c.url, command: c.command })),
|
|
141
|
+
endpoints: (contributes.endpoints ?? []).map(e => ({ id: e.id, command: e.command, ...(e.checks ? { checks: e.checks } : {}) })),
|
|
424
142
|
// The entry as one path in its directory (`./view/a.html`, `view//a.html` are `view/a.html`): the clients load it by that.
|
|
425
|
-
views: views.map(v => ({ id: v.id, title: v.title, entry: posix.normalize(v.entry), ...(v.in?.length ? { in: [...v.in] } : {}),
|
|
426
|
-
...(v.handles?.length ? { handles: [...v.handles] } : {}), ...(v.readout ? { readout: v.readout } : {}),
|
|
143
|
+
views: (contributes.views ?? []).map(v => ({ id: v.id, title: v.title, entry: posix.normalize(v.entry), ...(v.in?.length ? { in: [...v.in] } : {}),
|
|
144
|
+
...(v.icon ? { icon: v.icon } : {}), ...(v.handles?.length ? { handles: [...v.handles] } : {}), ...(v.readout ? { readout: v.readout } : {}),
|
|
427
145
|
...(v.checkout ? { checkout: v.checkout } : {}) })),
|
|
428
|
-
...(composerModes
|
|
429
|
-
// What it writes for another plugin's points, as written (components/plugins/plugin-extensions.mjs offerDeclarations).
|
|
146
|
+
...(contributes.composerModes?.length ? { composerModes: composerModes(contributes.composerModes) } : {}),
|
|
430
147
|
...(Object.keys(offers).length ? { offers } : {}),
|
|
431
|
-
agents: agentDeclarations(
|
|
432
|
-
dependencies, extensionPoints:
|
|
433
|
-
extensions:
|
|
434
|
-
...(instructions ? { instructions: instructions.trim() } : {}), ...(setup ? { setup: { command: setup.command } } : {}),
|
|
435
|
-
...(
|
|
436
|
-
...(
|
|
437
|
-
...(
|
|
148
|
+
agents: agentDeclarations(contributes.agents, dir),
|
|
149
|
+
dependencies: [...dependencies], extensionPoints: extensionPoints(contributes.extensionPoints),
|
|
150
|
+
extensions: Object.entries(contributes.extensions ?? {}).map(([key, value]) => { const [plugin, point] = key.split('/'); return { plugin, point, command: value.command }; }),
|
|
151
|
+
...(contributes.instructions ? { instructions: contributes.instructions.trim() } : {}), ...(contributes.setup ? { setup: { command: contributes.setup.command } } : {}),
|
|
152
|
+
...(contributes.skills?.length ? { skills: skills(contributes.skills, dir) } : {}),
|
|
153
|
+
...(Object.keys(contributes.environment ?? {}).length ? { environment: Object.entries(contributes.environment).map(([name, value]) => ({ name, value })) } : {}),
|
|
154
|
+
...(contributes.path?.length ? { path: contributes.path.map(entry => pathEntry(entry)) } : {}),
|
|
155
|
+
...(contributes.mcpServers && Object.keys(contributes.mcpServers).length ? { mcpServers: Object.entries(contributes.mcpServers).map(([name, server]) => ({ name,
|
|
156
|
+
command: server.command, args: [...(server.args ?? [])], env: Object.entries(server.env ?? {}).map(([variable, value]) => ({ name: variable, value })) })) } : {}),
|
|
157
|
+
...(contributes.modelProviders?.length ? { modelProviders: contributes.modelProviders.map(p => ({ id: p.id, title: p.title.trim(), api: p.api, url: p.url,
|
|
158
|
+
...(p.key ? { key: /^\$\{config:([^}]+)\}$/.exec(p.key)[1] } : {}) })) } : {}),
|
|
159
|
+
...(contributes.executors?.length ? { executors: contributes.executors.map(e => ({ id: e.id, title: e.title.trim(),
|
|
160
|
+
labels: executorLabels(e.labels, `执行环境 ${e.id} 的 labels`, 'invalid_plugin'), command: e.command })) } : {}),
|
|
161
|
+
...(contributes.repositories ? { repositories: { command: contributes.repositories.command } } : {}) };
|
|
438
162
|
}
|
|
439
|
-
//
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
//
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
const
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
check(raw && typeof raw === 'object' && !Array.isArray(raw) && Object.keys(raw).length <= 100, 'invalid_plugin',
|
|
450
|
-
`${where} 须为「变量名 → 值」的对象,不超过 100 个`);
|
|
451
|
-
return Object.entries(raw).map(([name, value]) => {
|
|
452
|
-
check(VARIABLE.test(name) && !RESERVED_VARIABLE.test(name), 'invalid_plugin',
|
|
453
|
-
`${where} 的变量名只用字母、数字和「_」,不以数字开头,也不能是 PATH、ZDOTDIR、BASH_ENV 或 CODA_ 开头的:${name}`);
|
|
454
|
-
check(typeof value === 'string' && value.length <= 4096 && !value.includes('\0'), 'invalid_plugin', `${where} 的 ${name} 须为不超过 4096 字的文字`);
|
|
455
|
-
for (const [, place] of value.matchAll(PLACE)) {
|
|
456
|
-
const setting = /^config:(.+)$/.exec(place)?.[1];
|
|
457
|
-
check(PLUGIN_PLACES.includes(place) || (setting && ['string', 'number', 'integer', 'boolean'].includes(declared[setting]?.type)), 'invalid_plugin',
|
|
458
|
-
`${where} 的 ${name} 引用了 \${${place}}:只能是 config:<本插件的单值设置>、CODA_PLUGIN_PATH 或 CODA_PLUGIN_STATE`);
|
|
459
|
-
// A variable is seen by all that starts there and by whatever prints the environment: a secret is read from its file.
|
|
460
|
-
check(!declared[setting]?.writeOnly, 'invalid_plugin', `${where} 的 ${name} 引用了密文设置 ${setting}:密文不进环境变量,插件的进程从 CODA_PLUGIN_SECRETS 给的文件读`);
|
|
461
|
-
}
|
|
462
|
-
return { name, value };
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
// The MCP servers it gives the agents of a project it applies to (docs/plugins.md「MCP 服务器」), by name, as Claude Code's
|
|
466
|
-
// `.mcp.json` has them: a program the agent starts and talks to on its standard input and output (`command` and its
|
|
467
|
-
// `args`, not run by a shell), given the variables `env` names, written as `contributes.environment`'s. What it runs may name
|
|
468
|
-
// the plugin's directory, its state on the backend and the backend's own Node; a server's settings reach it through `env`.
|
|
469
|
-
const MCP_PLACES = ['CODA_PLUGIN_PATH', 'CODA_PLUGIN_STATE', 'CODA_NODE'];
|
|
470
|
-
function mcpDeclarations(raw, declared) {
|
|
471
|
-
if (raw === undefined) return [];
|
|
472
|
-
check(raw && typeof raw === 'object' && !Array.isArray(raw) && Object.keys(raw).length <= 20, 'invalid_plugin',
|
|
473
|
-
'contributes.mcpServers 须为「服务器名 → { command, args, env }」的对象,不超过 20 个');
|
|
474
|
-
return Object.entries(raw).map(([name, server]) => {
|
|
475
|
-
const where = `contributes.mcpServers 的 ${name}`;
|
|
476
|
-
check(NAME.test(name) && name.length <= 40 && name !== 'coda', 'invalid_plugin',
|
|
477
|
-
`contributes.mcpServers 的服务器名只用小写字母、数字和「-」,以字母开头,至多 40 个字符,不能是 Coda 自己的 coda:${name}`);
|
|
478
|
-
check(server && typeof server === 'object' && !Array.isArray(server) && Object.keys(server).every(k => ['type', 'command', 'args', 'env'].includes(k))
|
|
479
|
-
&& (server.type === undefined || server.type === 'stdio'), 'invalid_plugin', `${where} 须为 { command, args, env }:现在只支持由 Agent 在本机启动的服务器(stdio)`);
|
|
480
|
-
const word = (value, label) => {
|
|
481
|
-
check(typeof value === 'string' && value && value.length <= 4096 && !/[\0\r\n]/.test(value), 'invalid_plugin', `${where} 的 ${label} 须为一行不超过 4096 字的文字`);
|
|
482
|
-
for (const [, place] of value.matchAll(PLACE)) check(MCP_PLACES.includes(place), 'invalid_plugin',
|
|
483
|
-
`${where} 的 ${label} 引用了 \${${place}}:只能是 CODA_PLUGIN_PATH、CODA_PLUGIN_STATE 或 CODA_NODE,设置经 env 交给它`);
|
|
484
|
-
return value;
|
|
485
|
-
};
|
|
486
|
-
const args = server.args ?? [];
|
|
487
|
-
check(Array.isArray(args) && args.length <= 100, 'invalid_plugin', `${where} 的 args 须为不超过 100 项的数组`);
|
|
488
|
-
return { name, command: word(server.command, 'command'), args: args.map((arg, i) => word(arg, `args[${i}]`)),
|
|
489
|
-
env: environmentDeclarations(server.env, declared, `${where} 的 env`) };
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
// The model services it provides (docs/plugins.md「模型服务」), for another plugin to choose by `<plugin>/<id>` with a setting of
|
|
493
|
-
// format `coda-model-provider`, neither needing the other: what it is called, the API it speaks, and where it is — an address
|
|
494
|
-
// written out that may name its own settings of a single value (`${config:…}`), and its key, one of its own secrets.
|
|
495
|
-
function modelProviderDeclarations(raw, declared) {
|
|
496
|
-
if (raw === undefined) return [];
|
|
497
|
-
check(Array.isArray(raw) && raw.length <= 10, 'invalid_plugin', 'contributes.modelProviders 须为不超过 10 项的数组');
|
|
498
|
-
const providers = raw.map((p, i) => {
|
|
499
|
-
const where = `contributes.modelProviders[${i}]`;
|
|
500
|
-
check(p && typeof p === 'object' && !Array.isArray(p) && Object.keys(p).every(k => ['id', 'title', 'api', 'url', 'key'].includes(k)), 'invalid_plugin',
|
|
501
|
-
`${where} 须为 { id, title, api, url, key? }`);
|
|
502
|
-
check(typeof p.id === 'string' && COMMAND.test(p.id), 'invalid_plugin', `${where} 的 id 只用小写字母、数字和「-」,以字母开头`);
|
|
503
|
-
check(typeof p.title === 'string' && p.title.trim() && [...p.title].length <= 40 && !/[\0\r\n]/.test(p.title), 'invalid_plugin', `${where} 的 title 须为不超过 40 字的一行`);
|
|
504
|
-
check(isModelApi(p.api), 'invalid_plugin', `${where} 的 api 须为 Coda 认得的接口:${MODEL_APIS.join('、')}`);
|
|
505
|
-
check(typeof p.url === 'string' && p.url && p.url.length <= 4096 && !/[\0\r\n]/.test(p.url), 'invalid_plugin', `${where} 的 url 须为一行地址`);
|
|
506
|
-
for (const [, place] of p.url.matchAll(PLACE)) {
|
|
507
|
-
const setting = /^config:(.+)$/.exec(place)?.[1];
|
|
508
|
-
check(setting && ['string', 'number', 'integer'].includes(declared[setting]?.type) && !declared[setting].writeOnly, 'invalid_plugin',
|
|
509
|
-
`${where} 的 url 只能引用本插件的单值设置(\${config:<设置名>},不能是密文)`);
|
|
510
|
-
}
|
|
511
|
-
const key = p.key === undefined ? null : /^\$\{config:([^}]+)\}$/.exec(p.key)?.[1];
|
|
512
|
-
check(p.key === undefined || (key && declared[key]?.writeOnly), 'invalid_plugin', `${where} 的 key 须为 \${config:<本插件的密文设置>}`);
|
|
513
|
-
return { id: p.id, title: p.title.trim(), api: p.api, url: p.url, ...(key ? { key } : {}) };
|
|
514
|
-
});
|
|
515
|
-
check(new Set(providers.map(p => p.id)).size === providers.length, 'invalid_plugin', 'contributes.modelProviders 的 id 不能重复');
|
|
516
|
-
return providers;
|
|
517
|
-
}
|
|
518
|
-
// The executors it offers this machine's script steps (docs/plugins.md「执行环境」): what each is called, the labels it has
|
|
519
|
-
// (as `coda:runsOn` writes them), and its hook — one command, run by `sh` as a panel's is, that the step's runner calls for
|
|
520
|
-
// each part of the job (resources/workflow-executor.mjs).
|
|
521
|
-
function executorDeclarations(raw) {
|
|
522
|
-
if (raw === undefined) return [];
|
|
523
|
-
check(Array.isArray(raw) && raw.length <= 10, 'invalid_plugin', 'contributes.executors 须为不超过 10 项的数组');
|
|
524
|
-
const executors = raw.map((e, i) => {
|
|
525
|
-
const where = `contributes.executors[${i}]`;
|
|
526
|
-
check(e && typeof e === 'object' && !Array.isArray(e) && Object.keys(e).every(k => ['id', 'title', 'labels', 'command'].includes(k)), 'invalid_plugin',
|
|
527
|
-
`${where} 须为 { id, title, labels, command }`);
|
|
528
|
-
check(typeof e.id === 'string' && COMMAND.test(e.id), 'invalid_plugin', `${where} 的 id 只用小写字母、数字和「-」,以字母开头`);
|
|
529
|
-
check(typeof e.title === 'string' && e.title.trim() && [...e.title].length <= 40 && !/[\0\r\n]/.test(e.title), 'invalid_plugin', `${where} 的 title 须为不超过 40 字的一行`);
|
|
530
|
-
const labels = executorLabels(e.labels, `${where} 的 labels`, 'invalid_plugin');
|
|
531
|
-
check(labels.length, 'invalid_plugin', `${where} 的 labels 至少要有一个标签`);
|
|
532
|
-
check(typeof e.command === 'string' && e.command.trim() && e.command.length <= 4000 && !/[\0\r\n]/.test(e.command), 'invalid_plugin', `${where} 的 command 须为一行命令`);
|
|
533
|
-
return { id: e.id, title: e.title.trim(), labels, command: e.command };
|
|
534
|
-
});
|
|
535
|
-
check(new Set(executors.map(e => e.id)).size === executors.length, 'invalid_plugin', 'contributes.executors 的 id 不能重复');
|
|
536
|
-
return executors;
|
|
163
|
+
// Its extension points (schemas/extension-points.json), each with what it says of itself.
|
|
164
|
+
const extensionPoints = (raw = {}) => Object.fromEntries(Object.entries(raw).map(([name, value]) => [name, value.contributes === undefined
|
|
165
|
+
? { description: value.description } : { description: value.description, contributes: value.contributes, title: value.title, commands: { ...(value.commands ?? {}) } }]));
|
|
166
|
+
// The directories it puts on the PATH of what starts in a project it applies to: one of its own (relative, as a Skill's),
|
|
167
|
+
// or one in its state on the backend (`${CODA_PLUGIN_STATE}/…`), which its setup may make.
|
|
168
|
+
function pathEntry(entry) {
|
|
169
|
+
const state = /^\$\{CODA_PLUGIN_STATE\}(\/.*)?$/.exec(entry);
|
|
170
|
+
const relative = normalize(state ? `.${state[1] ?? ''}` : entry).replace(/\/$/, '');
|
|
171
|
+
if (state) return relative === '.' ? '${CODA_PLUGIN_STATE}' : `\${CODA_PLUGIN_STATE}/${relative}`;
|
|
172
|
+
return relative;
|
|
537
173
|
}
|
|
538
174
|
// Whether a plugin chooses model services (a setting, or a column of a table's rows, of format `coda-model-provider`): its
|
|
539
175
|
// processes are told those of this machine (CODA_MODEL_PROVIDERS).
|
|
@@ -545,27 +181,10 @@ export function modelProviderAddress(provider, values) {
|
|
|
545
181
|
const url = filler({}, values)(provider.url);
|
|
546
182
|
return url && url.trim() ? url.trim() : null;
|
|
547
183
|
}
|
|
548
|
-
// The directories it puts on the PATH of what starts in a project it applies to: one of its own (relative, as a Skill's),
|
|
549
|
-
// or one in its state on the backend (`${CODA_PLUGIN_STATE}/…`), which its setup may make.
|
|
550
|
-
function pathDeclarations(raw, dir) {
|
|
551
|
-
if (raw === undefined) return [];
|
|
552
|
-
check(Array.isArray(raw) && raw.length <= 20, 'invalid_plugin', 'contributes.path 须为不超过 20 项的目录数组');
|
|
553
|
-
return raw.map(entry => {
|
|
554
|
-
check(typeof entry === 'string' && entry && !/[\0:\n]/.test(entry), 'invalid_plugin', `contributes.path 的每项须为一个目录:${entry}`);
|
|
555
|
-
const state = /^\$\{CODA_PLUGIN_STATE\}(\/.*)?$/.exec(entry);
|
|
556
|
-
const relative = normalize(state ? `.${state[1] ?? ''}` : entry).replace(/\/$/, '');
|
|
557
|
-
check(!relative.startsWith('/') && !relative.split('/').includes('..') && !entry.includes('${', state ? 2 : 0), 'invalid_plugin',
|
|
558
|
-
`contributes.path 的每项须为插件目录里的相对路径,或 \${CODA_PLUGIN_STATE} 下的目录:${entry}`);
|
|
559
|
-
if (state) return relative === '.' ? '${CODA_PLUGIN_STATE}' : `\${CODA_PLUGIN_STATE}/${relative}`;
|
|
560
|
-
let found;
|
|
561
|
-
try { found = statSync(join(dir, relative)); } catch { found = null; }
|
|
562
|
-
check(relative !== '.' && found?.isDirectory(), 'invalid_plugin', `contributes.path 的目录不在插件里:${entry}`);
|
|
563
|
-
return relative;
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
184
|
// A plugin's environment variables and PATH as they are for one project: its settings there (`settings`), its directory and
|
|
567
185
|
// its state on this backend (`state`, null without one). A value naming a setting with none, or its state without one, is
|
|
568
186
|
// not given; nor is a directory in a state there is not.
|
|
187
|
+
const PLACE = /\$\{([^}]*)\}/g;
|
|
569
188
|
// A value with what it names filled in, or null when one of them has none.
|
|
570
189
|
const filler = (places, settings) => value => {
|
|
571
190
|
let missing = false;
|
|
@@ -597,26 +216,14 @@ export function mcpValues(plugin, settings, state, base) {
|
|
|
597
216
|
// The Agent Skills it brings (docs/plugins.md「Skills」): directories of its own, each with its SKILL.md, named after the
|
|
598
217
|
// directory as the agents find them. They are laid into the working copy of each project it applies to.
|
|
599
218
|
export const SKILL = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
600
|
-
function
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
const found = raw.map(path => {
|
|
604
|
-
const relative = typeof path === 'string' ? normalize(path).replace(/\/$/, '') : '';
|
|
605
|
-
check(relative && !relative.startsWith('/') && !relative.split('/').includes('..') && relative !== '.', 'invalid_plugin',
|
|
606
|
-
`contributes.skills 的每项须为插件目录里的相对路径:${path}`);
|
|
607
|
-
const name = basename(relative);
|
|
608
|
-
check(SKILL.test(name), 'invalid_plugin', `Skill 目录名只能用字母、数字、「.」「_」「-」:${path}`);
|
|
609
|
-
let file;
|
|
610
|
-
try { file = statSync(join(dir, relative, 'SKILL.md')); } catch { file = null; }
|
|
611
|
-
check(file?.isFile(), 'invalid_plugin', `Skill 目录里没有 SKILL.md:${path}`);
|
|
219
|
+
function skills(raw, dir) {
|
|
220
|
+
return raw.map(path => {
|
|
221
|
+
const relative = normalize(path).replace(/\/+$/, ''), name = relative.split('/').at(-1);
|
|
612
222
|
const skill = { name, path: join(dir, relative) };
|
|
613
223
|
// Descriptions are for browsing only; a missing or unreadable document is explained when opened.
|
|
614
224
|
try { skill.description = readSkillDocument({ dir, skills: [skill] }, name).description; } catch { /* Keep the declaration. */ }
|
|
615
225
|
return skill;
|
|
616
226
|
});
|
|
617
|
-
const names = found.map(skill => skill.name);
|
|
618
|
-
check(new Set(names).size === names.length, 'invalid_plugin', `contributes.skills 里有同名的 Skill:${names.filter((n, i) => names.indexOf(n) !== i).join('、')}`);
|
|
619
|
-
return found;
|
|
620
227
|
}
|
|
621
228
|
// The plugins Coda ships: those in `dir`, which come from nowhere else, and its npm dependencies that are plugins
|
|
622
229
|
// (`dependencies`), each with where it comes from, which a version from that same place may stand in for (docs/plugins.md
|