@coda-console/plugin-check 0.8.24 → 0.8.26
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 +349 -0
- package/check/coda/application/host-protocols.mjs +3 -1
- package/check/coda/components/plugins/plugin-extensions.mjs +1 -1
- package/check/coda/components/protocols/record-rules.mjs +2 -2
- package/check/coda/contract.json +16 -9
- package/check/coda/domain/accord.mjs +144 -0
- package/check/coda/domain/jcs.mjs +58 -0
- package/check/coda/domain/usage.mjs +56 -0
- package/check/coda/kernel/accord-protocol.mjs +168 -0
- package/check/coda/kernel/usage-protocol.mjs +97 -0
- 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
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "notes",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"lockfileVersion": 3,
|
|
5
|
+
"requires": true,
|
|
6
|
+
"packages": {
|
|
7
|
+
"": {
|
|
8
|
+
"name": "notes",
|
|
9
|
+
"version": "1.0.0",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@coda-console/plugin-check": "0.8.25"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"coda": 3
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"node_modules/@0dep/piso": {
|
|
18
|
+
"version": "5.2.0",
|
|
19
|
+
"resolved": "https://registry.npmjs.org/@0dep/piso/-/piso-5.2.0.tgz",
|
|
20
|
+
"integrity": "sha512-2XQye5870MQZsUvJ5M5p+WtqN6q7jp+e0OeHrXORNm5HJmsmKTSYgkao5RNnWS6tFmsBbIx5hgbxJPEuaQZneg==",
|
|
21
|
+
"dev": true,
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"workspaces": [
|
|
24
|
+
"bench"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=14"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"node_modules/@agentclientprotocol/sdk": {
|
|
31
|
+
"version": "2.6.0",
|
|
32
|
+
"resolved": "https://registry.npmjs.org/@agentclientprotocol/sdk/-/sdk-2.6.0.tgz",
|
|
33
|
+
"integrity": "sha512-3FtL6MkAV5F9qxg0FQV8wmBszIm2xuVPoDWOILIFSDQ+Vq3Twdh7Cw6Hk2GOPUbevgrTUpUAqZXQy7Geaj79mw==",
|
|
34
|
+
"dev": true,
|
|
35
|
+
"license": "Apache-2.0",
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"@modelcontextprotocol/server": "^2.4.0",
|
|
38
|
+
"zod": "^3.25.76 || ^4.0.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"@modelcontextprotocol/server": {
|
|
42
|
+
"optional": true
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"node_modules/@coda-console/plugin-check": {
|
|
47
|
+
"version": "0.8.25",
|
|
48
|
+
"resolved": "https://registry.npmjs.org/@coda-console/plugin-check/-/plugin-check-0.8.25.tgz",
|
|
49
|
+
"dev": true,
|
|
50
|
+
"license": "MIT",
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@0dep/piso": "5.2.0",
|
|
53
|
+
"@agentclientprotocol/sdk": "2.6.0",
|
|
54
|
+
"@coda-console/protocol": "6.15.0",
|
|
55
|
+
"ajv": "8.20.0",
|
|
56
|
+
"yaml": "2.9.1"
|
|
57
|
+
},
|
|
58
|
+
"bin": {
|
|
59
|
+
"coda-plugin-check": "bin/check.mjs"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=24"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"node_modules/@coda-console/protocol": {
|
|
66
|
+
"version": "6.15.0",
|
|
67
|
+
"resolved": "https://registry.npmjs.org/@coda-console/protocol/-/protocol-6.15.0.tgz",
|
|
68
|
+
"integrity": "sha512-xTcQdwb1QX0dNiAIh5Qz966dWoB5kqpkpZja51nJg/86+ABhIoqG4FsdlaizMYMUnyEBvdfxq1Lf89HSix1FnA==",
|
|
69
|
+
"dev": true,
|
|
70
|
+
"license": "MIT",
|
|
71
|
+
"dependencies": {
|
|
72
|
+
"@0dep/piso": "5.2.0",
|
|
73
|
+
"ajv": "8.20.0",
|
|
74
|
+
"bpmn-moddle": "10.3.1",
|
|
75
|
+
"feelin": "8.2.0"
|
|
76
|
+
},
|
|
77
|
+
"engines": {
|
|
78
|
+
"node": ">=24"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"node_modules/@lezer/common": {
|
|
82
|
+
"version": "1.5.5",
|
|
83
|
+
"resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.5.tgz",
|
|
84
|
+
"integrity": "sha512-Pw7PVCndruF1pb3ebCxpSVpkMHSDjwRCLcTRw+RizUKco5QbWylwq2g4lnG/RYN7yTTQDXE9F77MwtkAyphrjg==",
|
|
85
|
+
"dev": true,
|
|
86
|
+
"license": "MIT"
|
|
87
|
+
},
|
|
88
|
+
"node_modules/@lezer/highlight": {
|
|
89
|
+
"version": "1.2.5",
|
|
90
|
+
"resolved": "https://registry.npmjs.org/@lezer/highlight/-/highlight-1.2.5.tgz",
|
|
91
|
+
"integrity": "sha512-O1GMVKgtf5YspFaRzpmqkVgMtIk2HG9uMAbH6wdAIdNh3TVzCsch/+cRi+6l2//UGDKe6NB9BW3cvuR5ezMQ0w==",
|
|
92
|
+
"dev": true,
|
|
93
|
+
"license": "MIT",
|
|
94
|
+
"dependencies": {
|
|
95
|
+
"@lezer/common": "^1.3.0"
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"node_modules/@lezer/lr": {
|
|
99
|
+
"version": "1.4.12",
|
|
100
|
+
"resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.12.tgz",
|
|
101
|
+
"integrity": "sha512-On9HU4oMMiHPMkQDgoTnGahjgG5n/MkN38CgG77sMraKLL+3JBbeQNi1FcCXV9QRqwF9/BUXP3caHyJC1fBOTQ==",
|
|
102
|
+
"dev": true,
|
|
103
|
+
"license": "MIT",
|
|
104
|
+
"dependencies": {
|
|
105
|
+
"@lezer/common": "^1.0.0"
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
"node_modules/ajv": {
|
|
109
|
+
"version": "8.20.0",
|
|
110
|
+
"resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz",
|
|
111
|
+
"integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==",
|
|
112
|
+
"dev": true,
|
|
113
|
+
"license": "MIT",
|
|
114
|
+
"dependencies": {
|
|
115
|
+
"fast-deep-equal": "^3.1.3",
|
|
116
|
+
"fast-uri": "^3.0.1",
|
|
117
|
+
"json-schema-traverse": "^1.0.0",
|
|
118
|
+
"require-from-string": "^2.0.2"
|
|
119
|
+
},
|
|
120
|
+
"funding": {
|
|
121
|
+
"type": "github",
|
|
122
|
+
"url": "https://github.com/sponsors/epoberezkin"
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"node_modules/bpmn-moddle": {
|
|
126
|
+
"version": "10.3.1",
|
|
127
|
+
"resolved": "https://registry.npmjs.org/bpmn-moddle/-/bpmn-moddle-10.3.1.tgz",
|
|
128
|
+
"integrity": "sha512-xjJ8GzseRkjjM0MX/rODVB6iv+rhGLt8FCHJIovLAjJsDEAUjITfyiJZYczJ4pp3wmesbY3sQR7eRT+q5uroVA==",
|
|
129
|
+
"dev": true,
|
|
130
|
+
"license": "MIT",
|
|
131
|
+
"dependencies": {
|
|
132
|
+
"min-dash": "^5.1.0",
|
|
133
|
+
"moddle": "^8.2.1",
|
|
134
|
+
"moddle-xml": "^12.3.1"
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
"node_modules/fast-deep-equal": {
|
|
138
|
+
"version": "3.1.3",
|
|
139
|
+
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
|
|
140
|
+
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
|
|
141
|
+
"dev": true,
|
|
142
|
+
"license": "MIT"
|
|
143
|
+
},
|
|
144
|
+
"node_modules/fast-uri": {
|
|
145
|
+
"version": "3.1.9",
|
|
146
|
+
"resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.9.tgz",
|
|
147
|
+
"integrity": "sha512-hS/0Wt3Ya043oKXs0sIxrMpKQITXhMLIrVAKKXi4gozGC9v7YRWVnXIZzjNPTO02M9BdxLCWqK1yRXgNziVyJQ==",
|
|
148
|
+
"dev": true,
|
|
149
|
+
"funding": [
|
|
150
|
+
{
|
|
151
|
+
"type": "github",
|
|
152
|
+
"url": "https://github.com/sponsors/fastify"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"type": "opencollective",
|
|
156
|
+
"url": "https://opencollective.com/fastify"
|
|
157
|
+
}
|
|
158
|
+
],
|
|
159
|
+
"license": "BSD-3-Clause"
|
|
160
|
+
},
|
|
161
|
+
"node_modules/feelin": {
|
|
162
|
+
"version": "8.2.0",
|
|
163
|
+
"resolved": "https://registry.npmjs.org/feelin/-/feelin-8.2.0.tgz",
|
|
164
|
+
"integrity": "sha512-o/oUBp7hzcsupV3Pf+Kn+43y+gul/sSVqYYkJq9+hkYuFuBfk0rocy//H2goKlWJJbuONnE59Iqb4U34VyZpjA==",
|
|
165
|
+
"dev": true,
|
|
166
|
+
"license": "MIT",
|
|
167
|
+
"dependencies": {
|
|
168
|
+
"@lezer/common": "^1.5.2",
|
|
169
|
+
"lezer-feel": "^3.0.1",
|
|
170
|
+
"min-dash": "^5.1.0",
|
|
171
|
+
"temporal-polyfill": "^1.0.4"
|
|
172
|
+
},
|
|
173
|
+
"engines": {
|
|
174
|
+
"node": ">= 20.12.0"
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
"node_modules/json-schema-traverse": {
|
|
178
|
+
"version": "1.0.0",
|
|
179
|
+
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
|
|
180
|
+
"integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
|
|
181
|
+
"dev": true,
|
|
182
|
+
"license": "MIT"
|
|
183
|
+
},
|
|
184
|
+
"node_modules/lezer-feel": {
|
|
185
|
+
"version": "3.0.1",
|
|
186
|
+
"resolved": "https://registry.npmjs.org/lezer-feel/-/lezer-feel-3.0.1.tgz",
|
|
187
|
+
"integrity": "sha512-tTOBq2ZOwfekNXg7eflg9WK/jl4LW4pryR3wiGRp1/ODXBG3ngo2mqXcriULylTjdxCnz42ByMMFEgbOK0L7kg==",
|
|
188
|
+
"dev": true,
|
|
189
|
+
"license": "MIT",
|
|
190
|
+
"dependencies": {
|
|
191
|
+
"@lezer/highlight": "^1.2.3",
|
|
192
|
+
"@lezer/lr": "^1.4.10",
|
|
193
|
+
"min-dash": "^5.0.0"
|
|
194
|
+
},
|
|
195
|
+
"engines": {
|
|
196
|
+
"node": ">= 20.12.0"
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
"node_modules/min-dash": {
|
|
200
|
+
"version": "5.1.0",
|
|
201
|
+
"resolved": "https://registry.npmjs.org/min-dash/-/min-dash-5.1.0.tgz",
|
|
202
|
+
"integrity": "sha512-HAvN6XzmCQj+js43G9sJRRw8kj/7DvoxN7qhoIN9Xo5ZN1NMljtpyKs/NunXmw0QSWwlgZzNv6tLeEa4xaZ0tg==",
|
|
203
|
+
"dev": true,
|
|
204
|
+
"license": "MIT"
|
|
205
|
+
},
|
|
206
|
+
"node_modules/moddle": {
|
|
207
|
+
"version": "8.2.1",
|
|
208
|
+
"resolved": "https://registry.npmjs.org/moddle/-/moddle-8.2.1.tgz",
|
|
209
|
+
"integrity": "sha512-20qzO/ZpMGO9j9gdQgXk9bfGxb9wA3JKnGth/21YZKODLrZE4RW/uVMIL5pTskYm34Z61DucBEPkq93qByNsBQ==",
|
|
210
|
+
"dev": true,
|
|
211
|
+
"license": "MIT",
|
|
212
|
+
"dependencies": {
|
|
213
|
+
"min-dash": "^5.1.0"
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
"node_modules/moddle-xml": {
|
|
217
|
+
"version": "12.3.2",
|
|
218
|
+
"resolved": "https://registry.npmjs.org/moddle-xml/-/moddle-xml-12.3.2.tgz",
|
|
219
|
+
"integrity": "sha512-fo6DSZdLr7Lr4ydgpHbEQEXu63QxxRPNmu5k2n3B/+oRTT9ybBLrcxo/hIK6Bo16ORVtw8FoZbwRCwZRr5l19g==",
|
|
220
|
+
"dev": true,
|
|
221
|
+
"license": "MIT",
|
|
222
|
+
"dependencies": {
|
|
223
|
+
"min-dash": "^5.1.0",
|
|
224
|
+
"saxen": "^11.2.0"
|
|
225
|
+
},
|
|
226
|
+
"engines": {
|
|
227
|
+
"node": ">= 18"
|
|
228
|
+
},
|
|
229
|
+
"peerDependencies": {
|
|
230
|
+
"moddle": ">= 6.2.0"
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
"node_modules/require-from-string": {
|
|
234
|
+
"version": "2.0.2",
|
|
235
|
+
"resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
|
|
236
|
+
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
|
|
237
|
+
"dev": true,
|
|
238
|
+
"license": "MIT",
|
|
239
|
+
"engines": {
|
|
240
|
+
"node": ">=0.10.0"
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
"node_modules/saxen": {
|
|
244
|
+
"version": "11.2.0",
|
|
245
|
+
"resolved": "https://registry.npmjs.org/saxen/-/saxen-11.2.0.tgz",
|
|
246
|
+
"integrity": "sha512-2bG564AAJcm/3vyZC0Uhs/mACrH+4AHMaKHKAB2M5xMqomUZa27FQ7MYaQGFKVcJk/MVzSEQ34A8QZWW+eiWEw==",
|
|
247
|
+
"dev": true,
|
|
248
|
+
"license": "MIT",
|
|
249
|
+
"engines": {
|
|
250
|
+
"node": ">= 20.12"
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
"node_modules/temporal-polyfill": {
|
|
254
|
+
"version": "1.0.8",
|
|
255
|
+
"resolved": "https://registry.npmjs.org/temporal-polyfill/-/temporal-polyfill-1.0.8.tgz",
|
|
256
|
+
"integrity": "sha512-RCCGa0GddT099XG49ijdD0tDf86L8vfuZun1+JyJiO4Y2NP9PACQsG0OnvNPXwVLisdvhr/zqL2nhKQmXXx08A==",
|
|
257
|
+
"dev": true,
|
|
258
|
+
"license": "MIT",
|
|
259
|
+
"dependencies": {
|
|
260
|
+
"temporal-spec": "1.0.1",
|
|
261
|
+
"temporal-utils": "1.0.4"
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
"node_modules/temporal-spec": {
|
|
265
|
+
"version": "1.0.1",
|
|
266
|
+
"resolved": "https://registry.npmjs.org/temporal-spec/-/temporal-spec-1.0.1.tgz",
|
|
267
|
+
"integrity": "sha512-wxVoanmDeavXie1vu2JaQ3WIc3JZnWAOYFBsJyATaVsXsycKYUflGsyBmrRSnoCpZJpwPyr38VpgSUlQ8CbFxg==",
|
|
268
|
+
"dev": true,
|
|
269
|
+
"license": "Apache-2.0"
|
|
270
|
+
},
|
|
271
|
+
"node_modules/temporal-utils": {
|
|
272
|
+
"version": "1.0.4",
|
|
273
|
+
"resolved": "https://registry.npmjs.org/temporal-utils/-/temporal-utils-1.0.4.tgz",
|
|
274
|
+
"integrity": "sha512-4mAcgbWlaxe+gn23gk8g0iHxCVGVOhKzSCfF5HM3lfvH8BdT+/pBmH/R/E4CrIse+koUgs8ThkPzCLnui6Fi8w==",
|
|
275
|
+
"dev": true,
|
|
276
|
+
"license": "MIT"
|
|
277
|
+
},
|
|
278
|
+
"node_modules/yaml": {
|
|
279
|
+
"version": "2.9.1",
|
|
280
|
+
"resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.1.tgz",
|
|
281
|
+
"integrity": "sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==",
|
|
282
|
+
"dev": true,
|
|
283
|
+
"license": "ISC",
|
|
284
|
+
"bin": {
|
|
285
|
+
"yaml": "bin.mjs"
|
|
286
|
+
},
|
|
287
|
+
"engines": {
|
|
288
|
+
"node": ">= 14.6"
|
|
289
|
+
},
|
|
290
|
+
"funding": {
|
|
291
|
+
"url": "https://github.com/sponsors/eemeli"
|
|
292
|
+
}
|
|
293
|
+
},
|
|
294
|
+
"node_modules/zod": {
|
|
295
|
+
"version": "4.6.7",
|
|
296
|
+
"resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz",
|
|
297
|
+
"integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==",
|
|
298
|
+
"dev": true,
|
|
299
|
+
"license": "MIT",
|
|
300
|
+
"peer": true,
|
|
301
|
+
"funding": {
|
|
302
|
+
"url": "https://github.com/sponsors/colinhacks"
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "notes",
|
|
3
|
+
"displayName": "便条(模板)",
|
|
4
|
+
"description": "带模块的插件模板:自己的协议 notes/note@1(一个查询、一个做事的操作、一个事件),模块登记操作、写记录、发布并订阅事件,附测试。",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"categories": ["工作流程"],
|
|
7
|
+
"main": "main.mjs",
|
|
8
|
+
"engines": { "coda": 3 },
|
|
9
|
+
"uses": { "notes/note@1": ["watch"] },
|
|
10
|
+
"scripts": { "test": "node --test" },
|
|
11
|
+
"devDependencies": { "@coda-console/plugin-check": "0.8.25" },
|
|
12
|
+
"contributes": {
|
|
13
|
+
"protocols": [
|
|
14
|
+
{
|
|
15
|
+
"name": "notes/note@1",
|
|
16
|
+
"title": "便条",
|
|
17
|
+
"description": "一条便条:标题与正文。",
|
|
18
|
+
"spec": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"properties": { "title": { "type": "string", "minLength": 1, "maxLength": 100 }, "body": { "type": "string", "maxLength": 10000 } },
|
|
21
|
+
"required": ["title", "body"],
|
|
22
|
+
"additionalProperties": false
|
|
23
|
+
},
|
|
24
|
+
"status": { "type": "object", "properties": {}, "additionalProperties": false },
|
|
25
|
+
"operations": {
|
|
26
|
+
"find": {
|
|
27
|
+
"safe": true,
|
|
28
|
+
"description": "按标题里含的字查便条,不写就是全部;seen 是模块这次启动以来收到的 note_notes.added 事件数。",
|
|
29
|
+
"input": { "type": "object", "properties": { "query": { "type": "string" } }, "additionalProperties": false },
|
|
30
|
+
"result": {
|
|
31
|
+
"type": "object",
|
|
32
|
+
"properties": {
|
|
33
|
+
"seen": { "type": "integer", "minimum": 0 },
|
|
34
|
+
"notes": {
|
|
35
|
+
"type": "array",
|
|
36
|
+
"items": {
|
|
37
|
+
"type": "object",
|
|
38
|
+
"properties": { "key": { "type": "string" }, "title": { "type": "string" } },
|
|
39
|
+
"required": ["key", "title"],
|
|
40
|
+
"additionalProperties": false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"required": ["notes", "seen"],
|
|
45
|
+
"additionalProperties": false
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"add": {
|
|
49
|
+
"description": "记一条便条(同标题是同一条),先写入,写入成功后才发布 note_notes.added;每次调用都发一条事件,同标题再记也发。发布失败时调用不失败(便条已存下):结果里 notified 为 false,reason 写原因。标题与正文的长度在输入里限住,超了在写入前就拒绝;project 是事件发布在哪个项目。",
|
|
50
|
+
"input": {
|
|
51
|
+
"type": "object",
|
|
52
|
+
"properties": { "title": { "type": "string", "minLength": 1, "maxLength": 100 }, "body": { "type": "string", "maxLength": 10000 }, "project": { "type": "string", "minLength": 1 } },
|
|
53
|
+
"required": ["title", "body", "project"],
|
|
54
|
+
"additionalProperties": false
|
|
55
|
+
},
|
|
56
|
+
"result": {
|
|
57
|
+
"type": "object",
|
|
58
|
+
"properties": { "key": { "type": "string" }, "notified": { "type": "boolean" }, "reason": { "type": "string" } },
|
|
59
|
+
"required": ["key", "notified"],
|
|
60
|
+
"additionalProperties": false
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"events": {
|
|
65
|
+
"note_notes.added": {
|
|
66
|
+
"description": "记了一条便条。",
|
|
67
|
+
"payload": {
|
|
68
|
+
"type": "object",
|
|
69
|
+
"properties": { "key": { "type": "string" }, "title": { "type": "string" }, "body": { "type": "string" } },
|
|
70
|
+
"required": ["key", "title", "body"],
|
|
71
|
+
"additionalProperties": false
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
"permissions": { "watch": { "title": "订阅便条事件", "events": ["note_notes.added"] } }
|
|
76
|
+
}
|
|
77
|
+
],
|
|
78
|
+
"protocolImplementations": ["notes/note@1"]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { test } from 'node:test';
|
|
4
|
+
import { createTestHost } from '@coda-console/plugin-check/test-host';
|
|
5
|
+
import { activate } from '../main.mjs';
|
|
6
|
+
|
|
7
|
+
const { contributes, uses } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
8
|
+
const NOTE = 'notes/note@1';
|
|
9
|
+
|
|
10
|
+
async function started() {
|
|
11
|
+
const host = createTestHost({ plugin: { protocols: contributes.protocols, protocolImplementations: contributes.protocolImplementations, uses } });
|
|
12
|
+
await activate(host.coda);
|
|
13
|
+
return host;
|
|
14
|
+
}
|
|
15
|
+
const note = { kind: NOTE, id: 'any' };
|
|
16
|
+
|
|
17
|
+
test('find lists the welcome note the module wrote on activation', async () => {
|
|
18
|
+
const host = await started();
|
|
19
|
+
assert.deepEqual(await host.call(note, 'find'), { seen: 0, notes: [{ key: '欢迎', title: '欢迎' }] });
|
|
20
|
+
assert.deepEqual(await host.call(note, 'find', { query: '没有' }), { seen: 0, notes: [] });
|
|
21
|
+
await host.close();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('activating over notes already there leaves them as they are', async () => {
|
|
25
|
+
const host = createTestHost({ plugin: { protocols: contributes.protocols, protocolImplementations: contributes.protocolImplementations, uses } });
|
|
26
|
+
await host.coda.put({ kind: NOTE, key: '旧的' }, { spec: { title: '旧的', body: '先前记的' } });
|
|
27
|
+
await activate(host.coda);
|
|
28
|
+
assert.deepEqual((await host.call(note, 'find')).notes, [{ key: '旧的', title: '旧的' }]);
|
|
29
|
+
await host.close();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('add makes the note and publishes note_notes.added each time; the module counts the events it is given', async () => {
|
|
33
|
+
const host = await started();
|
|
34
|
+
const input = { title: '买牛奶', body: '两盒', project: 'p1' };
|
|
35
|
+
assert.deepEqual(await host.call(note, 'add', input), { key: '买牛奶', notified: true });
|
|
36
|
+
await host.call(note, 'add', input);
|
|
37
|
+
assert.equal(host.emitted.length, 2);
|
|
38
|
+
const [event] = host.emitted;
|
|
39
|
+
assert.equal(event.name, 'note_notes.added');
|
|
40
|
+
assert.equal(event.kind, NOTE);
|
|
41
|
+
assert.deepEqual(event.data, { key: '买牛奶', title: '买牛奶', body: '两盒' });
|
|
42
|
+
assert.deepEqual((await host.call(note, 'find', { query: '牛奶' })).notes, [{ key: '买牛奶', title: '买牛奶' }]);
|
|
43
|
+
await host.emit({ ...event, publisher: 'notes' });
|
|
44
|
+
assert.equal((await host.call(note, 'find')).seen, 1);
|
|
45
|
+
await host.close();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('an input over the limits is refused before anything is written or published', async () => {
|
|
49
|
+
const host = await started();
|
|
50
|
+
await assert.rejects(host.call(note, 'add', { title: '长', body: 'x'.repeat(10001), project: 'p1' }), { code: 'invalid_input' });
|
|
51
|
+
assert.deepEqual((await host.call(note, 'find')).notes.map(entry => entry.key), ['欢迎']);
|
|
52
|
+
assert.deepEqual(host.emitted, []);
|
|
53
|
+
await host.close();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('add that cannot publish still saves the note, and says it did not tell anyone', async () => {
|
|
57
|
+
const host = createTestHost({ plugin: { protocols: contributes.protocols, protocolImplementations: contributes.protocolImplementations, uses } });
|
|
58
|
+
const coda = { ...host.coda, emit: async () => { throw host.coda.error('invalid_input', '项目 nope 不存在'); } };
|
|
59
|
+
await activate(coda);
|
|
60
|
+
const added = await host.call(note, 'add', { title: '买牛奶', body: '两盒', project: 'nope' });
|
|
61
|
+
assert.deepEqual(added, { key: '买牛奶', notified: false, reason: added.reason });
|
|
62
|
+
assert.match(String(added.reason), /项目 nope 不存在/);
|
|
63
|
+
assert.deepEqual((await host.call(note, 'find')).notes.map(entry => entry.key).sort(), ['买牛奶', '欢迎']);
|
|
64
|
+
await host.close();
|
|
65
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "uptime",
|
|
3
|
+
"displayName": "运行时间(模板)",
|
|
4
|
+
"description": "最小的资源插件模板",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"contributes": {
|
|
7
|
+
"resources": [
|
|
8
|
+
{
|
|
9
|
+
"id": "uptime",
|
|
10
|
+
"title": "运行时间",
|
|
11
|
+
"command": "node \"$CODA_PLUGIN_PATH/scripts/resources.mjs\"",
|
|
12
|
+
"maxAge": "PT1M",
|
|
13
|
+
"actions": {
|
|
14
|
+
"mark": {
|
|
15
|
+
"command": "node \"$CODA_PLUGIN_PATH/scripts/mark.mjs\"",
|
|
16
|
+
"confirm": "记下此刻?\n之后显示距这次记下过了多久。"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// 「记下此刻」按钮的动作:Coda 在点按钮(并确认)后运行它,退出码 0 就算成功,随后重读这个类型。
|
|
2
|
+
// 按钮带的 args 在 CODA_PANEL_ARGS 里(JSON),这个按钮没带。
|
|
3
|
+
import { writeFileSync } from 'node:fs';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
|
|
6
|
+
writeFileSync(join(process.env.CODA_PLUGIN_STATE, 'mark.json'), JSON.stringify({ at: new Date().toISOString() }));
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// 「运行时间」资源类型的取数命令:Coda 在打开资源页或点「刷新」时用 `sh -c` 运行它,标准输出就是资源的 JSON
|
|
2
|
+
// (docs/plugins.md「资源」)。`node` 是 Coda 后端自己的 Node;只用 Node 自带的模块。
|
|
3
|
+
// 读不懂的键会让这次读取失败;格式里没有说明性的字段,每个资源只有名字、读数、一行错误和按钮。
|
|
4
|
+
import { execFileSync } from 'node:child_process';
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { cpus, loadavg, uptime } from 'node:os';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
|
|
9
|
+
// `uptime` 的负载在 macOS 写作「load averages: 1.2 1.3 1.4」,在 Linux 写作「load average: 1.2, 1.3, 1.4」;读不到就用 Node 的。
|
|
10
|
+
function loads() {
|
|
11
|
+
try {
|
|
12
|
+
const line = execFileSync('uptime', { encoding: 'utf8', timeout: 5000 });
|
|
13
|
+
const found = /load averages?:\s*([\d.]+),?\s+([\d.]+),?\s+([\d.]+)/.exec(line);
|
|
14
|
+
if (found) return found.slice(1, 4).map(Number);
|
|
15
|
+
} catch {}
|
|
16
|
+
return loadavg();
|
|
17
|
+
}
|
|
18
|
+
const since = seconds => {
|
|
19
|
+
const days = Math.floor(seconds / 86400), hours = Math.floor(seconds % 86400 / 3600), minutes = Math.floor(seconds % 3600 / 60);
|
|
20
|
+
return days ? `${days} 天 ${hours} 小时` : hours ? `${hours} 小时 ${minutes} 分钟` : `${minutes} 分钟`;
|
|
21
|
+
};
|
|
22
|
+
// 按钮动作记下的时刻,存在插件的状态目录里(CODA_PLUGIN_STATE,跨读取、跨版本保留)。
|
|
23
|
+
function marked() {
|
|
24
|
+
try { return JSON.parse(readFileSync(join(process.env.CODA_PLUGIN_STATE, 'mark.json'), 'utf8')).at; } catch { return null; }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const [one] = loads(), cores = cpus().length, up = uptime(), mark = marked();
|
|
28
|
+
// 这台机器的东西只有一个资源,不写名字,也不写身份(identity 留给账号这类在几台机器上是同一个的)。
|
|
29
|
+
// 条一律画「还剩多少」:这里是 CPU 按 1 分钟负载算的余量;不知道比例时不写 fraction。读数带的时刻(time)写在数值后面。
|
|
30
|
+
const values = [
|
|
31
|
+
{ label: 'CPU 余量', value: `${one.toFixed(2)} / ${cores} 核`, fraction: Math.round(Math.max(0, Math.min(1, 1 - one / cores)) * 1000) / 1000 },
|
|
32
|
+
{ label: '已开机', value: since(up), time: new Date(Date.now() - up * 1000).toISOString() },
|
|
33
|
+
...(mark ? [{ label: '距上次记下', value: since((Date.now() - Date.parse(mark)) / 1000) }] : []),
|
|
34
|
+
];
|
|
35
|
+
process.stdout.write(JSON.stringify({ resources: [{ values, actions: [{ label: '记下此刻', action: 'mark' }] }] }));
|