@coda-console/plugin-check 0.8.24 → 0.8.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -3
- package/bin/check.mjs +18 -2
- package/check/coda/adapters/plugin-events.mjs +2 -0
- package/check/coda/adapters/plugin-modules.mjs +13 -4
- package/check/coda/adapters/plugin-test-host.d.mts +71 -3
- package/check/coda/adapters/plugin-test-host.mjs +6 -1
- package/check/coda/api-surface.txt +335 -0
- package/check/coda/components/plugins/plugin-extensions.mjs +1 -1
- package/check/coda/contract.json +9 -7
- package/check/index.mjs +6 -2
- package/check/init.mjs +33 -0
- package/check/level.mjs +70 -0
- package/check/manifest.mjs +5 -2
- package/check/module.mjs +133 -0
- package/check/report.mjs +2 -2
- package/package.json +7 -2
- package/templates/agent/agent/entry.mjs +128 -0
- package/templates/agent/icons/README.md +14 -0
- package/templates/agent/icons/echo.pdf +0 -0
- package/templates/agent/icons/echo.svg +8 -0
- package/templates/agent/package.json +20 -0
- package/templates/module/main.mjs +37 -0
- package/templates/module/package-lock.json +306 -0
- package/templates/module/package.json +80 -0
- package/templates/module/test/main.test.mjs +65 -0
- package/templates/resource/package.json +22 -0
- package/templates/resource/scripts/mark.mjs +6 -0
- package/templates/resource/scripts/resources.mjs +35 -0
package/check/coda/contract.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"commit": "
|
|
2
|
+
"commit": "46a06458a98d290d4cc69dfdfcf1880889d0bfcf",
|
|
3
|
+
"apiLevel": 3,
|
|
3
4
|
"packages": {
|
|
4
5
|
"@0dep/piso": "5.2.0",
|
|
5
6
|
"@agentclientprotocol/sdk": "2.6.0",
|
|
@@ -17,11 +18,11 @@
|
|
|
17
18
|
"check/coda/adapters/call-limit.mjs": "7e86d95ff7b0a88955015904ec91ae55e78fad816d06f710d6e62af53ccbdeab",
|
|
18
19
|
"check/coda/adapters/clock.mjs": "79733b9ac3807b3da147fe8b782318a1cb42d1d51b9c8b81a507c13c7a8025fd",
|
|
19
20
|
"check/coda/adapters/plugin-command.mjs": "47bd580f7142780933315f64d4562d23a61f996b3f411cfb583333261b590ee8",
|
|
20
|
-
"check/coda/adapters/plugin-events.mjs": "
|
|
21
|
-
"check/coda/adapters/plugin-modules.mjs": "
|
|
21
|
+
"check/coda/adapters/plugin-events.mjs": "5b6b98063a2a2f3d112908ad9fdc08119ec1bd577ca765811799ef6d1030dfe4",
|
|
22
|
+
"check/coda/adapters/plugin-modules.mjs": "dd916da2c3411087fc09ed20e2c1c5f10ce450ed096b9054db7d9c47000a2857",
|
|
22
23
|
"check/coda/adapters/plugin-stream-services.mjs": "1e92eb3dd9d844d4f2773a60bc2941aae3c9cda10d9e96e31de9f09f51e672e5",
|
|
23
|
-
"check/coda/adapters/plugin-test-host.d.mts": "
|
|
24
|
-
"check/coda/adapters/plugin-test-host.mjs": "
|
|
24
|
+
"check/coda/adapters/plugin-test-host.d.mts": "d0592b00e898da7abae8d48b0ee6f72cd807ac9b7a7e8d185148904082850575",
|
|
25
|
+
"check/coda/adapters/plugin-test-host.mjs": "7c8e5ee46792181bfd3b2f4d67d1ac6844c64c2af678655308cfdeb5ecf84c42",
|
|
25
26
|
"check/coda/adapters/process-relay.mjs": "5d379bd7ad07138d69c7accbe769d71294843399539bdf1fab8b6a1ddf13b9d8",
|
|
26
27
|
"check/coda/components/composers/contributions.mjs": "43d3e15fb1f63b7b5c20716030d9537613809ed5cc2fb466a3678bfa308f9f92",
|
|
27
28
|
"check/coda/components/concurrency-groups/schemas.mjs": "3c422044c637dee10565fb1b8bdc75b9c6a31e3b600ed223b7e5e345e1baf092",
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"check/coda/components/plugins/contribution-points.mjs": "2dade9fe4f3fa2b4e89f49a1ac4378ab2621e5ac542eb175967091f04568b45c",
|
|
30
31
|
"check/coda/components/plugins/git-contributions.mjs": "532917cd3ec45e12535e9e6c206ae14fa598bebc789ab0c8f15609d1699fa1cd",
|
|
31
32
|
"check/coda/components/plugins/model-contributions.mjs": "018a7157954b2326887ba1a780b37d3beb33338e41a28936b313562c2939d563",
|
|
32
|
-
"check/coda/components/plugins/plugin-extensions.mjs": "
|
|
33
|
+
"check/coda/components/plugins/plugin-extensions.mjs": "4b0f5379de25c464b044dbfc293e421f4f0c36b16bd4742d90ed82f5bd7d7162",
|
|
33
34
|
"check/coda/components/plugins/plugin-icons.mjs": "ec29cadce4948ecacabfe911a2ceb45414b96e28971358acbc4e952bedc78e1a",
|
|
34
35
|
"check/coda/components/plugins/plugin-rules.mjs": "32cf0a3956a646e0c18cea62da4c0969af9f4c6f60ab1a4970937163a13a878a",
|
|
35
36
|
"check/coda/components/plugins/plugin-source-rules.mjs": "d3bf278c4fb35e99f602ea81419dff0ad0c2753ee20e6e3b648d2fecf82da44f",
|
|
@@ -54,6 +55,7 @@
|
|
|
54
55
|
"check/coda/resources/plugins/resources/panels/panels.mjs": "37ffc6a4ede3e4612cd13cf1a973a90892f8ce7e8a0f055e7cfe86313aae5224",
|
|
55
56
|
"check/coda/resources/plugins/resources/panels/rules.mjs": "a433d4e84138937297ec31a8912aab7bd48bba4b66da3a10978edb1367613c96",
|
|
56
57
|
"check/coda/resources/plugins/resources/panels/sign-in.mjs": "6eb016ef9a7f8aa03e0f4b2fa35ce139b8b1ff0deb4ec6e6a34139aed4f2841a",
|
|
57
|
-
"check/coda/builtin.json": "0eb63a693c912f7e339cda0b76b85110f881784b92c7788c8ea6d0a1c7468ade"
|
|
58
|
+
"check/coda/builtin.json": "0eb63a693c912f7e339cda0b76b85110f881784b92c7788c8ea6d0a1c7468ade",
|
|
59
|
+
"check/coda/api-surface.txt": "7ce7dca260719ef0f756b0f73eceec447eacec6d966d9671b312e15c7ec4034a"
|
|
58
60
|
}
|
|
59
61
|
}
|
package/check/index.mjs
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
// The contract check of one plugin directory: the manifest and its workflows, then each agent's handshake (and with `live`, a
|
|
1
|
+
// The contract check of one plugin directory: the manifest and its workflows, its module if it has one, then each agent's handshake (and with `live`, a
|
|
2
2
|
// turn) and each resource type's (or panel's) reading. The manifest is checked against Coda's schemas of its types and its workflows against Coda's
|
|
3
3
|
// dialect of BPMN (both the protocol's), the rest by Coda's own code (check/coda/), run where a plugin is written.
|
|
4
4
|
import { resolve } from 'node:path';
|
|
5
5
|
import { checkAgent } from './agent.mjs';
|
|
6
|
+
import { checkLevel } from './level.mjs';
|
|
6
7
|
import { checkManifest } from './manifest.mjs';
|
|
8
|
+
import { checkModule } from './module.mjs';
|
|
7
9
|
import { checkPanel } from './panel.mjs';
|
|
8
10
|
import { checkWorkflows } from './workflows.mjs';
|
|
9
11
|
import { Report } from './report.mjs';
|
|
10
12
|
|
|
11
|
-
// `agent`: only this agent of the plugin; `manifestOnly`: nothing is run; `live`: one turn each with `prompt`.
|
|
13
|
+
// `agent`: only this agent of the plugin; `manifestOnly`: nothing is run (not its module either); `live`: one turn each with `prompt`.
|
|
12
14
|
export async function checkPlugin(dir, { agent: only = null, manifestOnly = false, live = false, prompt, limits } = {}) {
|
|
13
15
|
const pluginDir = resolve(dir), report = new Report();
|
|
14
16
|
const plugin = checkManifest(pluginDir, report.scope('manifest'));
|
|
15
17
|
if (!plugin) return { report, plugin };
|
|
16
18
|
await checkWorkflows(plugin, report.scope('manifest'));
|
|
19
|
+
checkLevel({ checked: plugin, say: report.scope('manifest'), note: report.scope('note') });
|
|
17
20
|
const agents = only ? plugin.agents.filter(a => a.id === only) : plugin.agents;
|
|
18
21
|
if (only && !agents.length) report.scope('manifest').fail('options.agent', `清单里没有能检查的 Agent ${only}`);
|
|
19
22
|
if (manifestOnly) {
|
|
20
23
|
if (agents.length || plugin.panels.length) report.scope('handshake').skip('options.manifest', '只查清单(--manifest):不启动 Agent、不读资源');
|
|
21
24
|
return { report, plugin };
|
|
22
25
|
}
|
|
26
|
+
if (plugin.plugin.main) await checkModule({ checked: plugin, say: report.scope('module'), note: report.scope('note'), limit: limits?.activate });
|
|
23
27
|
for (const agent of agents) await checkAgent({ agent, checked: plugin, live, prompt, limits, say: level => report.scope(level, `Agent ${agent.id}`) });
|
|
24
28
|
if (!only) for (const panel of plugin.panels) await checkPanel({ panel, checked: plugin, say: report.scope('handshake', `${panel.format === 'resources' ? '资源类型' : '面板'} ${panel.id}`) });
|
|
25
29
|
return { report, plugin };
|
package/check/init.mjs
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// `coda-plugin-check init <目录> [--template module|agent|resource]`: a template copied into a new directory, named after it.
|
|
2
|
+
import { cpSync, existsSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { basename, join, resolve } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
export const TEMPLATES = ['module', 'agent', 'resource'];
|
|
7
|
+
const ROOT = fileURLToPath(new URL('../templates', import.meta.url));
|
|
8
|
+
// A plugin ID: the directory's name is the plugin's.
|
|
9
|
+
const ID = /^[a-z][a-z0-9-]{0,39}$/;
|
|
10
|
+
|
|
11
|
+
// Copies `template` into `target` (absent or empty), and says the plugin's `name`, the protocol prefix of the module template's
|
|
12
|
+
// `<name>/note@1` and the domain of its event `note_<name>.added` (event names are one machine's: `_` for `-`), the directory's.
|
|
13
|
+
// Returns the plugin ID.
|
|
14
|
+
export function init(target, template) {
|
|
15
|
+
if (!TEMPLATES.includes(template)) throw new Error(`没有模板「${template}」,可选 ${TEMPLATES.join('、')}`);
|
|
16
|
+
const dir = resolve(target), id = basename(dir);
|
|
17
|
+
if (!ID.test(id)) throw new Error(`目录名「${id}」要作插件 ID:小写字母开头,只用小写字母、数字和 -,至多 40 个字符`);
|
|
18
|
+
if (existsSync(dir) && (!statSync(dir).isDirectory() || readdirSync(dir).length)) throw new Error(`${target} 不是空目录,不往里复制`);
|
|
19
|
+
const source = join(ROOT, template);
|
|
20
|
+
const was = JSON.parse(readFileSync(join(source, 'package.json'), 'utf8')).name;
|
|
21
|
+
cpSync(source, dir, { recursive: true, filter: path => basename(path) !== 'node_modules' });
|
|
22
|
+
for (const file of ['package.json', 'package-lock.json', 'main.mjs', 'test/main.test.mjs']) {
|
|
23
|
+
const path = join(dir, file);
|
|
24
|
+
if (!existsSync(path)) continue;
|
|
25
|
+
const text = readFileSync(path, 'utf8').replaceAll(`${was}/note@1`, `${id}/note@1`).replaceAll(`note_${was}.added`, `note_${id.replaceAll('-', '_')}.added`);
|
|
26
|
+
if (!file.endsWith('.json')) { writeFileSync(path, text); continue; }
|
|
27
|
+
const json = JSON.parse(text);
|
|
28
|
+
json.name = id;
|
|
29
|
+
if (json.packages?.['']) json.packages[''].name = id;
|
|
30
|
+
writeFileSync(path, `${JSON.stringify(json, null, 2)}\n`);
|
|
31
|
+
}
|
|
32
|
+
return id;
|
|
33
|
+
}
|
package/check/level.mjs
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// The API Level a plugin needs, reckoned from what it uses (check/coda/api-surface.txt: every item Coda offers plugins, with the
|
|
2
|
+
// Level it came in) against its `engines.coda`. What the manifest and its protocols name is certain; what is read from the text of
|
|
3
|
+
// its files (`coda.<member>`, `ctx.<member>`, `window.coda.<member>`) may be a misreading, and is only remarked on.
|
|
4
|
+
// Also lists the trial surface it uses: the permission groups and module interfaces that may change from one Coda to the next.
|
|
5
|
+
import { readdirSync, readFileSync } from 'node:fs';
|
|
6
|
+
import { extname, join } from 'node:path';
|
|
7
|
+
import { wantedLevel } from './coda/components/plugins/plugin-extensions.mjs';
|
|
8
|
+
|
|
9
|
+
// The lines of a surface (check/coda/api-surface.txt) as item → Level.
|
|
10
|
+
export const parseSurface = text => new Map(text.split('\n').flatMap(line => { const match = /^(\d+) (.+)$/.exec(line); return match ? [[match[2], Number(match[1])]] : []; }));
|
|
11
|
+
const SURFACE = parseSurface(readFileSync(new URL('./coda/api-surface.txt', import.meta.url), 'utf8'));
|
|
12
|
+
|
|
13
|
+
// The source files of a directory by their paths in it, but what npm installed and Git keeps.
|
|
14
|
+
function files(dir, prefix = '') {
|
|
15
|
+
return readdirSync(join(dir, prefix), { withFileTypes: true }).flatMap(entry => {
|
|
16
|
+
const path = join(prefix, entry.name);
|
|
17
|
+
if (entry.isDirectory()) return entry.name === 'node_modules' || entry.name === '.git' ? [] : files(dir, path);
|
|
18
|
+
return entry.isFile() ? [path] : [];
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
function scan(dir, views, surface) {
|
|
22
|
+
const items = new Set();
|
|
23
|
+
for (const path of files(dir)) {
|
|
24
|
+
const script = ['.mjs', '.js'].includes(extname(path));
|
|
25
|
+
if (!script && !views.has(path)) continue;
|
|
26
|
+
const text = readFileSync(join(dir, path), 'utf8');
|
|
27
|
+
for (const [, name] of text.matchAll(/\bwindow\.coda\.(\w+)/g)) if (surface.has(`bridge window.coda.${name}`)) items.add(`bridge window.coda.${name}`);
|
|
28
|
+
if (!script) continue;
|
|
29
|
+
// The deepest member of `coda` the surface has: `coda.settings.get`, else `coda.settings`.
|
|
30
|
+
for (const [, name, sub] of text.matchAll(/(?<!window\.)\bcoda\.(\w+)(?:\.(\w+))?/g))
|
|
31
|
+
for (const item of [`module coda.${name}.${sub}`, `module coda.${name}`]) if (surface.has(item)) { items.add(item); break; }
|
|
32
|
+
for (const [, name] of text.matchAll(/\bctx\.(\w+)/g)) if (surface.has(`module ctx.${name}`)) items.add(`module ctx.${name}`);
|
|
33
|
+
}
|
|
34
|
+
return items;
|
|
35
|
+
}
|
|
36
|
+
// What the manifest names: its keys, their keys under them, and what a protocol's `uses` and its own definitions are made of.
|
|
37
|
+
function named({ manifest, plugin }, surface) {
|
|
38
|
+
const items = new Set();
|
|
39
|
+
for (const [key, value] of Object.entries(manifest)) {
|
|
40
|
+
items.add(`manifest ${key}`);
|
|
41
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) for (const sub of Object.keys(value)) items.add(`manifest ${key}.${sub}`);
|
|
42
|
+
}
|
|
43
|
+
for (const [kind, groups] of Object.entries(plugin.uses ?? {})) { items.add(kind); for (const group of groups) items.add(`${kind} ${group}`); }
|
|
44
|
+
for (const definition of plugin.protocols ?? []) {
|
|
45
|
+
for (const key of Object.keys(definition)) items.add(`definition ${key}`);
|
|
46
|
+
for (const section of ['permissions', 'operations', 'events', 'streams'])
|
|
47
|
+
for (const entry of Object.values(definition[section] ?? {})) for (const key of Object.keys(entry)) items.add(`definition ${section}.${key}`);
|
|
48
|
+
}
|
|
49
|
+
return [...items].filter(item => surface.has(item));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// `checked`: the plugin as the manifest level read it. `say`: the manifest level's; `note`: the notes'. `surface`: the items and
|
|
53
|
+
// their Levels, as this Coda has them unless given.
|
|
54
|
+
export function checkLevel({ checked, say, note, surface = SURFACE }) {
|
|
55
|
+
const { plugin } = checked;
|
|
56
|
+
const certain = named(checked, surface), read = [...scan(plugin.dir, new Set(plugin.views.map(view => view.entry)), surface)];
|
|
57
|
+
const highest = items => items.reduce((top, item) => !top || surface.get(item) > surface.get(top) ? item : top, null);
|
|
58
|
+
const written = wantedLevel(plugin.engines) ?? undefined, top = highest([...certain, ...read]);
|
|
59
|
+
const need = top ? surface.get(top) : 0;
|
|
60
|
+
if (written === undefined) say.warn('manifest.level', `没写 engines.coda:用到的项最高 Level ${need}${top ? `(${top})` : ''},该写 "engines": { "coda": ${need} }`);
|
|
61
|
+
else {
|
|
62
|
+
const short = highest(certain.filter(item => surface.get(item) > written));
|
|
63
|
+
if (short) say.fail('manifest.level', `用到 ${short}(Level ${surface.get(short)}),engines.coda 至少写 ${surface.get(short)}(现写 ${written})`);
|
|
64
|
+
for (const item of read.filter(item => surface.get(item) > written)) say.warn('manifest.level-text', `文件里出现 ${item}(Level ${surface.get(item)}),engines.coda 写 ${written}:扫描文本得来,可能认错;没错的话至少写 ${surface.get(item)}`);
|
|
65
|
+
if (!short && !read.some(item => surface.get(item) > written)) say.pass('manifest.level', `engines.coda ${written},用到的项最高 Level ${need}`);
|
|
66
|
+
}
|
|
67
|
+
for (const [kind, groups] of Object.entries(plugin.uses ?? {}))
|
|
68
|
+
for (const group of groups) if (checked.definitionOf(kind)?.permissions?.[group]?.trial) note.info('note.trial', `用到试行面:${kind} 的权限组 ${group},随 Coda 版本可能变`);
|
|
69
|
+
for (const item of [...certain, ...read].filter(item => item.startsWith('module '))) note.info('note.trial', `用到试行面:模块接口 ${item.slice('module '.length)},随 Coda 版本可能变`);
|
|
70
|
+
}
|
package/check/manifest.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { inflateSync } from 'node:zlib';
|
|
|
11
11
|
import './coda/application/contributions.mjs';
|
|
12
12
|
import { HOST_PROTOCOLS } from './coda/application/host-protocols.mjs';
|
|
13
13
|
import shipped from './coda/builtin.json' with { type: 'json' };
|
|
14
|
+
import { CORE_PROTOCOLS } from '@coda-console/protocol/protocol';
|
|
14
15
|
import { manifestProblem } from '@coda-console/protocol/validate';
|
|
15
16
|
import { offerProblem, protocolDefinition, usesMissing } from './coda/components/plugins/plugin-extensions.mjs';
|
|
16
17
|
import { choosesModelProviders, pluginEnv, readPlugin, resolveSettings } from './coda/components/plugins/plugin-rules.mjs';
|
|
@@ -63,7 +64,8 @@ function pageSize(data) {
|
|
|
63
64
|
|
|
64
65
|
// Checks the manifest in `dir` and reports under `say` (report.mjs). Returns what the later levels need — the plugin as Coda
|
|
65
66
|
// reads it, its agents and the panels the resources plugin can read, its settings for every project, the directories of the
|
|
66
|
-
// plugins it depends on that are here,
|
|
67
|
+
// plugins it depends on that are here, `definitionOf(kind)`, a protocol's definition as far as it is here (its own, Coda's
|
|
68
|
+
// or a plugin's beside it; undefined if not), `definitions`, all of those that are here, and `env(stateDir)`, what Coda gives each of its processes —; null when it is no
|
|
67
69
|
// plugin, or not of the types it names.
|
|
68
70
|
export function checkManifest(dir, say) {
|
|
69
71
|
let manifest;
|
|
@@ -150,5 +152,6 @@ export function checkManifest(dir, say) {
|
|
|
150
152
|
// The model services of a machine with none, for one that chooses them; the PATH has no directories of Coda's own here.
|
|
151
153
|
const env = stateDir => pluginEnv({ catalog: given, installed, id: plugin.id, stateDir: id => id === plugin.id ? stateDir : null, settings,
|
|
152
154
|
providers: choosesModelProviders(plugin) ? {} : null, userPath: process.env.PATH ?? '' });
|
|
153
|
-
return { id: plugin.id, manifest, plugin, agents: plugin.agents, panels, settings, dependencies, env
|
|
155
|
+
return { id: plugin.id, manifest, plugin, agents: plugin.agents, panels, settings, dependencies, env, definitionOf: kind => protocolDefinition(kind, protocols, hosted),
|
|
156
|
+
definitions: [...Object.values(CORE_PROTOCOLS), ...HOST_PROTOCOLS, ...[...protocols.values()].flatMap(each => each.protocols ?? [])] };
|
|
154
157
|
}
|
package/check/module.mjs
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// The module level: the plugin's `main` loaded by Coda's own `coda` (the test host, check/coda/adapters/plugin-test-host.mjs),
|
|
2
|
+
// activated, and what it registered set against what the manifest says it implements. Runs between the manifest and the Agent
|
|
3
|
+
// handshake, for a plugin with a `main`.
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
6
|
+
import { protocolHasRecords } from '@coda-console/protocol/protocol';
|
|
7
|
+
import { usesRefusal } from './coda/components/plugins/plugin-extensions.mjs';
|
|
8
|
+
import { createTestHost } from './coda/adapters/plugin-test-host.mjs';
|
|
9
|
+
import { closing, temporary } from './leftovers.mjs';
|
|
10
|
+
|
|
11
|
+
// How long `activate` may take before the check gives up on it.
|
|
12
|
+
export const ACTIVATE_LIMIT = 10_000;
|
|
13
|
+
|
|
14
|
+
const firstLine = e => String(e?.stack ?? e).split('\n')[0];
|
|
15
|
+
|
|
16
|
+
// The members of `coda` the test host has no backend for, each with the failure the test host answers it with (the code, and the
|
|
17
|
+
// text): the same member failing otherwise is the module's own (an argument it gave, a handler it wrote).
|
|
18
|
+
export const NOT_PROVIDED = {
|
|
19
|
+
watch: { message: '测试宿主没有后端,不答 watch' },
|
|
20
|
+
'services.register': { message: '测试宿主没有后端,不答 serviceRegister' },
|
|
21
|
+
tell: { message: '测试宿主没有后端,不答 tell' },
|
|
22
|
+
api: { message: 'Coda 还在启动,稍后再试' },
|
|
23
|
+
environment: { message: '测试宿主没有后端,不答 environment' },
|
|
24
|
+
'protocols.resolve': { message: '测试宿主没有后端,不答 provider' },
|
|
25
|
+
'protocols.upload': { message: '测试宿主没有后端,不答 provider' },
|
|
26
|
+
'pluginSetup.retry': { code: 'unsupported', message: '测试宿主不提供 coda.pluginSetup' },
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// `coda` as the module is given it, each function noting which member each error it ends with came out of (the first, when it is
|
|
30
|
+
// passed on): the member that ended the module's `activate` tells a refusal of `coda.on` and a missing backend from the
|
|
31
|
+
// module's own failure.
|
|
32
|
+
function traced(coda, thrown) {
|
|
33
|
+
const wrap = (object, path) => Object.fromEntries(Object.entries(object).map(([key, value]) => {
|
|
34
|
+
const member = path ? `${path}.${key}` : key;
|
|
35
|
+
if (typeof value === 'function') return [key, (...args) => {
|
|
36
|
+
const fail = error => { if (!thrown.has(error)) thrown.set(error, member); throw error; };
|
|
37
|
+
try { const result = value.apply(object, args); return result instanceof Promise ? result.catch(fail) : result; } catch (error) { return fail(error); }
|
|
38
|
+
}];
|
|
39
|
+
return [key, value && typeof value === 'object' ? wrap(value, member) : value];
|
|
40
|
+
}));
|
|
41
|
+
return wrap(coda, '');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Gives `work` `limit` milliseconds, then fails with it.
|
|
45
|
+
function within(work, limit) {
|
|
46
|
+
let timer;
|
|
47
|
+
return Promise.race([work, new Promise((_, reject) => { timer = setTimeout(reject, limit, new Error(`${limit / 1000} 秒没完成`)); })]).finally(() => clearTimeout(timer));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// `checked`: the plugin as the manifest level read it (manifest.mjs checkManifest). `limit`: how long `activate` and `deactivate`
|
|
51
|
+
// may each take.
|
|
52
|
+
export async function checkModule({ checked, say, note, limit = ACTIVATE_LIMIT }) {
|
|
53
|
+
const { plugin } = checked, main = plugin.main;
|
|
54
|
+
const state = temporary('coda-plugin-check-state-');
|
|
55
|
+
// Others' definitions of the protocols it uses, for the event groups its `coda.on` may name. The test host takes them for
|
|
56
|
+
// those alone: its record types are Coda's, the plugin's own and its kinds that stay on this machine, so it cannot hand out a
|
|
57
|
+
// dependency's records (registering the definitions among the plugin's own protocols would let it publish their events too).
|
|
58
|
+
const used = Object.keys(plugin.uses ?? {}).filter(kind => !plugin.protocols?.some(one => one.name === kind));
|
|
59
|
+
const protocols = used.map(checked.definitionOf).filter(Boolean);
|
|
60
|
+
const absent = used.filter(kind => !checked.definitionOf(kind));
|
|
61
|
+
const host = createTestHost({ plugin: { id: plugin.id, path: plugin.dir, state: state.dir, protocols: plugin.protocols,
|
|
62
|
+
protocolImplementations: plugin.protocolImplementations, processes: plugin.processes, uses: plugin.uses }, settings: checked.settings, protocols });
|
|
63
|
+
const done = closing(() => host.close());
|
|
64
|
+
const thrown = new Map();
|
|
65
|
+
try {
|
|
66
|
+
let module;
|
|
67
|
+
try { module = await import(pathToFileURL(join(plugin.dir, main)).href); }
|
|
68
|
+
catch (e) { return say.fail('module.load', `main ${main} 加载不了:${firstLine(e)}`); }
|
|
69
|
+
if (typeof module.activate !== 'function') return say.fail('module.activate', `main ${main} 没有导出 activate(coda)`);
|
|
70
|
+
let activated = false;
|
|
71
|
+
try {
|
|
72
|
+
await within(module.activate(traced(host.coda, thrown)), limit);
|
|
73
|
+
activated = true;
|
|
74
|
+
} catch (e) {
|
|
75
|
+
const from = thrown.get(e), lacking = NOT_PROVIDED[from];
|
|
76
|
+
const unsettled = from === 'on' || from === 'get' || from === 'list' ? unfinished(checked, e, from, absent, used) : null;
|
|
77
|
+
if (unsettled?.fail) say.fail(...unsettled.fail);
|
|
78
|
+
else if (unsettled) say.warn('module.registered', `未完成核对:${unsettled.warn}`);
|
|
79
|
+
else if (lacking && e.code === lacking.code && e.message === lacking.message) {
|
|
80
|
+
note.info('note.host', `模块用到测试宿主不提供的能力 coda.${from},模块一级只验到这里`);
|
|
81
|
+
say.warn('module.registered', `未完成核对:模块用到测试宿主不提供的能力 coda.${from},登记的操作没有拿去与清单比对`);
|
|
82
|
+
} else say.fail('module.activate', `activate 失败:${firstLine(e)}`);
|
|
83
|
+
}
|
|
84
|
+
if (activated) {
|
|
85
|
+
say.pass('module.activate', `activate 完成:${main}`);
|
|
86
|
+
compare(checked, host.registered(), say);
|
|
87
|
+
}
|
|
88
|
+
// As Coda's host ends a module before it goes, once it has been activated: what it started ends with it. One that did not
|
|
89
|
+
// finish activating is not called; closing the test host ends what it started.
|
|
90
|
+
if (activated) try { await within(module.deactivate?.(), limit); } catch (e) { say.fail('module.deactivate', `deactivate 失败:${firstLine(e)}`); }
|
|
91
|
+
} finally { done(); await host.close(); state.remove(); }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// A `coda.on` the test host refused, or a `coda.get`/`coda.list` of a kind it does not have, judged by the definitions that are
|
|
95
|
+
// here: a failure when they settle it (`{ fail: [rule, message] }`), what the check could not tell when it depends on one that
|
|
96
|
+
// is not (`{ warn }`), null when it is neither (the module's own failure). `absent`: the protocols it uses whose definition is
|
|
97
|
+
// not here; `used`: those it uses that are not its own.
|
|
98
|
+
function unfinished({ plugin, definitions, definitionOf }, e, from, absent, used) {
|
|
99
|
+
if (from === 'on') {
|
|
100
|
+
if (e.code !== 'forbidden') return null;
|
|
101
|
+
const name = /没有订事件 (\S+):/.exec(e.message)?.[1];
|
|
102
|
+
// An event is one protocol's, as far as the definitions here say: its group is not among those used, whoever else is missing.
|
|
103
|
+
if (definitions.some(one => one.events && Object.hasOwn(one.events, name)) || !absent.length) return { fail: ['module.events', `coda.on 订了不在自己事件组里的事件:${e.message}`] };
|
|
104
|
+
return { warn: `协议 ${absent.join('、')} 的定义不在本地,coda.on 被拒可能只是不认识它的事件组` };
|
|
105
|
+
}
|
|
106
|
+
const kind = /^没有协议:(.+)$/.exec(e.message)?.[1];
|
|
107
|
+
if (e.code !== 'not_found' || kind === undefined) return null;
|
|
108
|
+
const definition = definitionOf(kind);
|
|
109
|
+
if (!definition) return used.includes(kind) ? { warn: `协议 ${kind} 的定义不在本地,查不了 coda.${from} 读它的记录是不是已获授权` } : null;
|
|
110
|
+
if (!protocolHasRecords(definition)) return null;
|
|
111
|
+
const refusal = usesRefusal(plugin, kind, 'read', definition);
|
|
112
|
+
return refusal ? { fail: ['module.activate', `activate 失败:${refusal}`] } : { warn: `测试宿主登记不了已获授权的记录类型 ${kind},coda.${from} 之后没有核对` };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// What the manifest says it implements against what the module registered, both ways: an operation not implemented by a command
|
|
116
|
+
// is the module's to register (but for those only Coda answers); one registered that the definition lacks is no operation of the
|
|
117
|
+
// protocol. (A protocol the manifest does not implement is refused by the test host as the module registers: it fails `activate`.)
|
|
118
|
+
function compare({ plugin, definitionOf }, { operations }, say) {
|
|
119
|
+
const registered = new Set(operations.map(({ kind, operation }) => `${kind} ${operation}`));
|
|
120
|
+
let problems = 0, incomplete = false;
|
|
121
|
+
for (const { kind, commands } of plugin.protocolImplementations ?? []) {
|
|
122
|
+
const definition = definitionOf(kind);
|
|
123
|
+
if (!definition) { incomplete = true; say.warn('module.registered', `未完成核对:协议 ${kind} 的定义不在本地,查不了模块登记了它的哪些操作`); continue; }
|
|
124
|
+
// `codaOnly`: Coda's own protocol's operation that Coda alone answers.
|
|
125
|
+
for (const [operation, { codaOnly }] of Object.entries(definition.operations ?? {}))
|
|
126
|
+
if (!codaOnly && !Object.hasOwn(commands, operation) && !registered.has(`${kind} ${operation}`)) { problems++; say.fail('module.unregistered', `清单写了实现 ${kind} 的操作 ${operation},模块没登记(coda.handle)`); }
|
|
127
|
+
}
|
|
128
|
+
for (const { kind, operation } of operations) {
|
|
129
|
+
const definition = definitionOf(kind);
|
|
130
|
+
if (definition && !Object.hasOwn(definition.operations ?? {}, operation)) { problems++; say.fail('module.unlisted', `模块登记了 ${kind} 的操作 ${operation},协议定义里没有这个操作`); }
|
|
131
|
+
}
|
|
132
|
+
if (!problems && !incomplete) say.pass('module.registered', `模块登记了 ${operations.length} 个操作,与清单一致`);
|
|
133
|
+
}
|
package/check/report.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// What a check found, in the order found: each line a level (清单, 握手,
|
|
1
|
+
// What a check found, in the order found: each line a level (清单, 模块, 握手, 一轮, 说明), what it is about (the plugin, an agent, a panel),
|
|
2
2
|
// whether it passed, failed, was skipped or is worth a look (warn, info), a rule ID the tests name, and a line of Chinese.
|
|
3
|
-
export const LEVELS = { manifest: '清单', handshake: '握手', live: '一轮' };
|
|
3
|
+
export const LEVELS = { manifest: '清单', module: '模块', handshake: '握手', live: '一轮', note: '说明' };
|
|
4
4
|
const MARKS = { pass: '✓', fail: '✗', warn: '!', skip: '-', info: '·' };
|
|
5
5
|
|
|
6
6
|
export class Report {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coda-console/plugin-check",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.25",
|
|
4
4
|
"description": "Coda 插件的契约检查:扮演 Coda 读清单、启动 Agent 讲 ACP 与 _coda/wait、读资源类型(与旧的面板)。",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -11,12 +11,17 @@
|
|
|
11
11
|
"engines": {
|
|
12
12
|
"node": ">=24"
|
|
13
13
|
},
|
|
14
|
+
"exports": {
|
|
15
|
+
"./types": "./check/coda/adapters/plugin-test-host.d.mts",
|
|
16
|
+
"./test-host": "./check/coda/adapters/plugin-test-host.mjs"
|
|
17
|
+
},
|
|
14
18
|
"bin": {
|
|
15
19
|
"coda-plugin-check": "bin/check.mjs"
|
|
16
20
|
},
|
|
17
21
|
"files": [
|
|
18
22
|
"bin",
|
|
19
|
-
"check"
|
|
23
|
+
"check",
|
|
24
|
+
"templates"
|
|
20
25
|
],
|
|
21
26
|
"scripts": {
|
|
22
27
|
"test": "node --test 'test/**/*.test.mjs'"
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// 回声 Agent:Coda Agent 插件的最小模板。
|
|
2
|
+
//
|
|
3
|
+
// Coda 用 `sh -c` 运行清单里的 command,经标准输入输出讲 ACP(一行一个 JSON-RPC 消息),外加 Coda 的等待项登记
|
|
4
|
+
// `_coda/wait`(见协议仓库 coda-console/coda-protocol 的 docs/agent-protocol.md)。这里全部手写,只用 Node 自带的模块:从仓库安装的插件没有 npm 依赖。
|
|
5
|
+
//
|
|
6
|
+
// - 每轮把提示词原样回显,几个字一段地流式发出,所以「停止」能落在一轮中间。
|
|
7
|
+
// - 会话指令(systemPrompt):Coda 要求声明。回声 Agent 没有原生的系统提示词,就照协议在这个会话第一次 session/prompt 时
|
|
8
|
+
// 把指令作为单独分隔的一段放在用户输入前面;它没有模型,「送入」就是把这一段也回显出来。
|
|
9
|
+
// - 插话(_session/steering):一轮进行中收到的加进这一轮,说完提示词接着说;一轮已经结束就回 promptRequired,不自己另开一轮。
|
|
10
|
+
// - 提示词以 wait 开头时登记一个后台任务(kind: task),两秒后在一轮之外报 handling:Coda 为它开一轮自主轮次,
|
|
11
|
+
// 这时说的话归这一项;说完报 done,自主轮次结束。
|
|
12
|
+
// - session/cancel:停止本轮;没有轮次在进行时,停止正在处理(handling)的等待项。
|
|
13
|
+
// - 日志只能写标准错误:标准输出里每一行都必须是 JSON-RPC 消息。
|
|
14
|
+
import { randomUUID } from 'node:crypto';
|
|
15
|
+
import { createInterface } from 'node:readline';
|
|
16
|
+
|
|
17
|
+
const send = message => process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', ...message })}\n`);
|
|
18
|
+
const reply = (id, result) => send({ id, result });
|
|
19
|
+
const refuse = (id, code, message) => send({ id, error: { code, message } });
|
|
20
|
+
const notify = (method, params) => send({ method, params });
|
|
21
|
+
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
|
|
22
|
+
// 把一段话作为回复发出,四个字一段;`stopped()` 为真时不再往下说。返回是否说完了。
|
|
23
|
+
async function speak(sessionId, text, stopped) {
|
|
24
|
+
for (const piece of text.match(/.{1,4}/gsu) ?? []) {
|
|
25
|
+
if (stopped()) return false;
|
|
26
|
+
notify('session/update', { sessionId, update: { sessionUpdate: 'agent_message_chunk', content: { type: 'text', text: piece } } });
|
|
27
|
+
await sleep(20);
|
|
28
|
+
}
|
|
29
|
+
return !stopped();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Coda 每轮开始前要知道会话用的是哪个模型:没有模型的 Agent 也报一个。
|
|
33
|
+
const MODEL = { id: 'model', name: '模型', category: 'model', type: 'select', currentValue: 'echo', options: [{ value: 'echo', name: '回声' }] };
|
|
34
|
+
// sessionId → { turn:进行中的一轮或 null,waits:waitId → { state, timer },count:取 waitId 用,
|
|
35
|
+
// instructions:会话指令还没送入时是它的正文,送入后为 null }
|
|
36
|
+
const sessions = new Map();
|
|
37
|
+
const session = sessionId => {
|
|
38
|
+
const found = sessions.get(sessionId);
|
|
39
|
+
if (!found) throw Object.assign(new Error(`没有会话 ${sessionId}`), { code: -32002 });
|
|
40
|
+
return found;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// ---- 等待项 ----
|
|
44
|
+
// 报告一项的新状态;结束(done、failed、cancelled)后这个 waitId 不再说话。
|
|
45
|
+
function report(sessionId, waitId, state, fields = {}) {
|
|
46
|
+
const s = sessions.get(sessionId), wait = s?.waits.get(waitId);
|
|
47
|
+
if (!wait) return;
|
|
48
|
+
wait.state = state;
|
|
49
|
+
if (['done', 'failed', 'cancelled'].includes(state)) { clearTimeout(wait.timer); s.waits.delete(waitId); }
|
|
50
|
+
notify('_coda/wait', { sessionId, waitId, state, ...fields });
|
|
51
|
+
}
|
|
52
|
+
function startWait(sessionId, text) {
|
|
53
|
+
const s = session(sessionId), waitId = `wait-${++s.count}`;
|
|
54
|
+
s.waits.set(waitId, { state: 'waiting', timer: setTimeout(() => handle(sessionId, waitId, text), 2000) });
|
|
55
|
+
report(sessionId, waitId, 'waiting', { kind: 'task', title: '两秒后回来', detail: text.slice(0, 4000), stoppable: true });
|
|
56
|
+
}
|
|
57
|
+
// 到点了:报 handling(一轮之外时 Coda 开一轮自主轮次),说完报 done。被停下就不再说。
|
|
58
|
+
async function handle(sessionId, waitId, text) {
|
|
59
|
+
report(sessionId, waitId, 'handling');
|
|
60
|
+
const wait = sessions.get(sessionId)?.waits.get(waitId);
|
|
61
|
+
if (await speak(sessionId, `两秒到了,接着说:${text}`, () => wait.state !== 'handling')) report(sessionId, waitId, 'done');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ---- 请求 ----
|
|
65
|
+
const methods = {
|
|
66
|
+
// 声明会话指令(sessionCapabilities.systemPrompt)、会登记等待项(_meta.coda.waits)与插话(顶层 _meta.steering);
|
|
67
|
+
// 不支持恢复会话,Coda 就不会发 session/load(支持的,恢复的会话已经送过指令,不再送)。
|
|
68
|
+
initialize: () => ({ protocolVersion: 1, agentCapabilities: { loadSession: false, sessionCapabilities: { systemPrompt: {} }, _meta: { coda: { waits: {} } } },
|
|
69
|
+
authMethods: [], _meta: { steering: { supported: true } } }),
|
|
70
|
+
'session/new': ({ systemPrompt }) => {
|
|
71
|
+
// Coda 只用 append 模式、一个文本块;应用不了的指令回错误,不建立会话。
|
|
72
|
+
if (systemPrompt && systemPrompt.mode !== 'append') throw Object.assign(new Error(`不支持 systemPrompt 模式 ${systemPrompt.mode}`), { code: -32602 });
|
|
73
|
+
const instructions = (systemPrompt?.content ?? []).filter(block => block.type === 'text').map(block => block.text).join('\n').trim() || null;
|
|
74
|
+
const sessionId = randomUUID();
|
|
75
|
+
sessions.set(sessionId, { turn: null, waits: new Map(), count: 0, instructions });
|
|
76
|
+
return { sessionId, configOptions: [MODEL] };
|
|
77
|
+
},
|
|
78
|
+
'session/set_config_option': ({ sessionId, configId, value }) => {
|
|
79
|
+
session(sessionId);
|
|
80
|
+
if (configId !== 'model' || value !== 'echo') throw Object.assign(new Error(`不支持 ${configId}=${value}`), { code: -32602 });
|
|
81
|
+
return { configOptions: [MODEL] };
|
|
82
|
+
},
|
|
83
|
+
'session/prompt': async ({ sessionId, prompt }) => {
|
|
84
|
+
const s = session(sessionId), turn = s.turn = { cancelled: false, steers: [] };
|
|
85
|
+
const text = (prompt ?? []).filter(block => block.type === 'text').map(block => block.text).join('\n').trim();
|
|
86
|
+
try {
|
|
87
|
+
if (/^wait\b/i.test(text)) startWait(sessionId, text);
|
|
88
|
+
// 第一轮:指令作为单独分隔的一段在用户输入前面,整段一次说出。
|
|
89
|
+
if (s.instructions) {
|
|
90
|
+
notify('session/update', { sessionId, update: { sessionUpdate: 'agent_message_chunk',
|
|
91
|
+
content: { type: 'text', text: `<coda-instructions>\n${s.instructions}\n</coda-instructions>\n\n` } } });
|
|
92
|
+
s.instructions = null;
|
|
93
|
+
}
|
|
94
|
+
let said = await speak(sessionId, `回声:${text}`, () => turn.cancelled);
|
|
95
|
+
while (said && turn.steers.length) said = await speak(sessionId, `\n插话:${turn.steers.shift()}`, () => turn.cancelled);
|
|
96
|
+
return { stopReason: turn.cancelled ? 'cancelled' : 'end_turn' };
|
|
97
|
+
} finally { if (s.turn === turn) s.turn = null; }
|
|
98
|
+
},
|
|
99
|
+
// 插话:一轮进行中就加进这一轮,之后的回复与结束都属于原来那次 session/prompt;没有轮次在进行时不收,等 Coda 作为下一轮发来。
|
|
100
|
+
'_session/steering': ({ sessionId, prompt }) => {
|
|
101
|
+
const s = session(sessionId);
|
|
102
|
+
if (!s.turn || s.turn.cancelled) return { outcome: 'promptRequired', reason: 'noRunningTurn' };
|
|
103
|
+
s.turn.steers.push((prompt ?? []).filter(block => block.type === 'text').map(block => block.text).join('\n').trim());
|
|
104
|
+
return { outcome: 'injected' };
|
|
105
|
+
},
|
|
106
|
+
// Coda 停一个声明了 stoppable 的等待项:回 {} 只表示收到,随后用 _coda/wait 报它结束。
|
|
107
|
+
'_coda/wait/stop': ({ sessionId, waitId }) => {
|
|
108
|
+
setImmediate(() => report(sessionId, waitId, 'cancelled'));
|
|
109
|
+
return {};
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
function cancel({ sessionId }) {
|
|
113
|
+
const s = sessions.get(sessionId);
|
|
114
|
+
if (!s) return;
|
|
115
|
+
if (s.turn) s.turn.cancelled = true;
|
|
116
|
+
for (const [waitId, wait] of s.waits) if (wait.state === 'handling') report(sessionId, waitId, 'cancelled');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
createInterface({ input: process.stdin }).on('line', async line => {
|
|
120
|
+
let message;
|
|
121
|
+
try { message = JSON.parse(line); } catch { return; }
|
|
122
|
+
if (typeof message?.method !== 'string') return;
|
|
123
|
+
if (!('id' in message)) { if (message.method === 'session/cancel') cancel(message.params ?? {}); return; }
|
|
124
|
+
const method = methods[message.method];
|
|
125
|
+
if (!method) { refuse(message.id, -32601, `Method not found: ${message.method}`); return; }
|
|
126
|
+
try { reply(message.id, await method(message.params ?? {})); }
|
|
127
|
+
catch (error) { refuse(message.id, error.code ?? -32603, error.message); }
|
|
128
|
+
}).on('close', () => process.exit(0));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# 回声图标
|
|
2
|
+
|
|
3
|
+
为这个模板画的单色图标(一个点和三道声波),随本仓库以 MIT 许可。清单里 `template: true`:只用黑色,客户端随文字颜色着色。
|
|
4
|
+
|
|
5
|
+
图标的规矩(Coda 读清单时核对):插件目录里的 PDF,不超过 32 KiB;可另给深色外观用的 `dark`。画布照 Coda 自带图标定为 256 px:
|
|
6
|
+
iOS 按 96 pt 光栅化 PDF 时只缩不放,页面太小会画成一个点。SVG 是可审阅的源文件,PDF 由 CairoSVG 转换(开发工具,不是运行依赖):
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
uv run --with cairosvg python - <<'PY'
|
|
10
|
+
import cairosvg
|
|
11
|
+
for name in ['echo']:
|
|
12
|
+
cairosvg.svg2pdf(url=f'{name}.svg', write_to=f'{name}.pdf')
|
|
13
|
+
PY
|
|
14
|
+
```
|
|
Binary file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" viewBox="0 0 256 256">
|
|
2
|
+
<circle cx="56" cy="128" r="24" fill="black"/>
|
|
3
|
+
<g fill="none" stroke="black" stroke-width="18" stroke-linecap="round">
|
|
4
|
+
<path d="M95.6 88.4A56 56 0 0 1 95.6 167.6"/>
|
|
5
|
+
<path d="M126.7 57.3A100 100 0 0 1 126.7 198.7"/>
|
|
6
|
+
<path d="M157.8 26.2A144 144 0 0 1 157.8 229.8"/>
|
|
7
|
+
</g>
|
|
8
|
+
</svg>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "echo",
|
|
3
|
+
"displayName": "回声(模板)",
|
|
4
|
+
"description": "最小的 Agent 插件模板:手写 ACP 的回声 Agent,没有依赖;提示词以 wait 开头时演示等待项登记与自主轮次。",
|
|
5
|
+
"version": "1.1.0",
|
|
6
|
+
"contributes": {
|
|
7
|
+
"agents": [
|
|
8
|
+
{
|
|
9
|
+
"id": "echo",
|
|
10
|
+
"displayName": "回声",
|
|
11
|
+
"icon": {
|
|
12
|
+
"light": "icons/echo.pdf",
|
|
13
|
+
"template": true
|
|
14
|
+
},
|
|
15
|
+
"command": "exec \"$CODA_NODE\" \"$CODA_PLUGIN_PATH/agent/entry.mjs\"",
|
|
16
|
+
"setupHint": "回声 Agent 不需要登录,也不联网;起不来时看运行机上 Coda 后端的 Node。"
|
|
17
|
+
}
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { Coda, Json } from '@coda-console/plugin-check/types' */
|
|
3
|
+
|
|
4
|
+
const NOTE = 'notes/note@1';
|
|
5
|
+
|
|
6
|
+
/** @param {Coda} coda */
|
|
7
|
+
export async function activate(coda) {
|
|
8
|
+
// A query: the notes this plugin holds, those whose title has `query` in it, and how many note_notes.added this module has been told of.
|
|
9
|
+
let seen = 0;
|
|
10
|
+
coda.handle(NOTE, 'find', async input => {
|
|
11
|
+
const { query = '' } = /** @type {{ query?: string }} */ (input);
|
|
12
|
+
const entries = await coda.list(NOTE, { scope: 'local' });
|
|
13
|
+
return { seen, notes: entries.filter(entry => String(entry.spec.title).includes(query)).map(entry => ({ key: String(entry.key), title: String(entry.spec.title) })) };
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// A doing call: the input's limits (the schema) refuse what cannot be written before anything is. Once the note is saved the call
|
|
17
|
+
// does not fail: if note_notes.added cannot be published, it says so (`notified`), for the note is there. Each call publishes one.
|
|
18
|
+
coda.handle(NOTE, 'add', async input => {
|
|
19
|
+
const { title, body, project } = /** @type {{ title: string, body: string, project: string }} */ (input);
|
|
20
|
+
const entry = await coda.put({ kind: NOTE, key: title }, { spec: { title, body } });
|
|
21
|
+
/** @type {Json} */
|
|
22
|
+
let result = { key: title, notified: true };
|
|
23
|
+
try {
|
|
24
|
+
await coda.emit('note_notes.added', { key: title, title, body }, { subject: `note:${entry.id}`, project });
|
|
25
|
+
} catch (e) {
|
|
26
|
+
result = { key: title, notified: false, reason: String(e) };
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// The welcome note, only while there are no notes: `replace` gives every record of the kind whole, so it would wipe the others.
|
|
32
|
+
if (!(await coda.list(NOTE, { scope: 'local' })).length)
|
|
33
|
+
await coda.replace(NOTE, [{ key: '欢迎', spec: { title: '欢迎', body: '这是模板自带的一条便条。' } }]);
|
|
34
|
+
|
|
35
|
+
// The event group `watch` of the protocol, in `uses`: it only reads the events.
|
|
36
|
+
coda.on('note_notes.added', () => { seen++; });
|
|
37
|
+
}
|