aicommunicator-plugin-check 0.2.0 → 0.2.1
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 +35 -35
- package/dist/bundle.js +33 -33
- package/dist/icon.js +11 -11
- package/dist/manifest.js +38 -38
- package/dist/messages.js +33 -33
- package/dist/sample.d.ts +5 -2
- package/dist/sample.js +73 -64
- package/dist/state.js +7 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# aicommunicator-plugin-check
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Code that checks the rules for the manifest and the package file (`.tgz`) of AIC (aicommunicator) plugins. The AIC core, the `aic` command, and the plugin registry site all use this one npm package, so the three accept or reject the same plugin by the same rules.
|
|
4
4
|
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
5
|
+
- It depends on no other package and uses only built-in Node modules (`node:crypto`, `node:zlib`). It runs on Node 22.13 or later.
|
|
6
|
+
- It does not run plugin code. It only looks at the text of the manifest, the names and sizes of files in the package file, and the text of the manual and sample files.
|
|
7
|
+
- The design is in `doc/036_plugin_registry_design.md` of the aicommunicator repository, and the manual and samples are in `doc/037_plugin_manual_design.md`.
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
10
|
npm install aicommunicator-plugin-check
|
|
@@ -14,7 +14,7 @@ npm install aicommunicator-plugin-check
|
|
|
14
14
|
import { readBundle, checkBundleForRegistry, BundleError } from 'aicommunicator-plugin-check';
|
|
15
15
|
|
|
16
16
|
try {
|
|
17
|
-
const bundle = readBundle(buffer); // .tgz
|
|
17
|
+
const bundle = readBundle(buffer); // Buffer of the .tgz
|
|
18
18
|
const problem = checkBundleForRegistry(bundle);
|
|
19
19
|
if (problem) console.log(problem.code, problem.message);
|
|
20
20
|
} catch (e) {
|
|
@@ -22,37 +22,37 @@ try {
|
|
|
22
22
|
}
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
##
|
|
25
|
+
## Exports
|
|
26
26
|
|
|
27
|
-
|
|
|
27
|
+
| Name | What it does |
|
|
28
28
|
| --- | --- |
|
|
29
|
-
| `PROTOCOL_VERSION` |
|
|
30
|
-
| `checkManifest(manifest)` |
|
|
31
|
-
| `checkForRegistry(manifest)` | `checkManifest
|
|
32
|
-
| `checkBundleForRegistry(bundle)` | `checkForRegistry`
|
|
33
|
-
| `readBundle(buffer)` | `.tgz
|
|
34
|
-
| `BundleError` | `code`
|
|
35
|
-
| `packBundle(files)` |
|
|
36
|
-
| `compareVersions(a, b)` | semver
|
|
37
|
-
| `satisfies(version, range)` | `1.2.3`, `^1.2.3`, `~1.2.3`, `>=1.2.3
|
|
38
|
-
| `protocolAccepts(range, core?)` |
|
|
39
|
-
| `stateId(plugins)`, `canonicalState(plugins)`, `checkState(plugins)` |
|
|
40
|
-
| `isPluginId`, `idOwner`, `isVersion`, `isPrerelease`, `isRange`, `isProtocolRange`, `isStateId` |
|
|
41
|
-
| `bundleFileName`, `bundlePathAllowed`, `sha256Hex` |
|
|
42
|
-
| `BUNDLE_MAX_BYTES`, `BUNDLE_MAX_FILES`, `MAX_DEPENDENCIES`, `STATE_MAX_PLUGINS`, `RESERVED_IDS` |
|
|
43
|
-
| `checkMessageTable(data)` |
|
|
44
|
-
| `renderMessage(table, id, values)` |
|
|
45
|
-
| `isMessageId`, `MESSAGE_TABLE_FORMAT`, `MESSAGE_TABLE_MAX_BYTES`, `MESSAGE_TABLE_MAX_MESSAGES`, `MESSAGE_TEXT_MAX` |
|
|
46
|
-
| `docsProblem(manifest, files)` |
|
|
47
|
-
| `bundleNotices(manifest)` |
|
|
48
|
-
| `checkSample(value)`, `parseSample(data)`, `parseManual(data)` |
|
|
49
|
-
| `sampleNarrative(sample, { installed?, self? })`, `samplePluginLines`, `missingPlugins` |
|
|
50
|
-
| `SAMPLE_FORMAT`, `MANUAL_MAX_CHARS`, `SAMPLE_MAX_CHARS`, `MAX_SAMPLES`, `SAMPLE_WHO` |
|
|
51
|
-
|
|
52
|
-
##
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
##
|
|
29
|
+
| `PROTOCOL_VERSION` | The plugin contract version of the core. Now `"0.1"` |
|
|
30
|
+
| `checkManifest(manifest)` | The manifest check the core uses. Returns the reason as text when something is wrong, and `null` when it is fine |
|
|
31
|
+
| `checkForRegistry(manifest)` | On top of `checkManifest`, checks the fields needed to upload to the site (`protocol`, `license`, `title`, `about`) |
|
|
32
|
+
| `checkBundleForRegistry(bundle)` | Checks `checkForRegistry` and the `LICENSE` file. Returns `{ code, message }` (code is `bad_manifest` or `bad_bundle`) when there is a problem, and `null` when there is none |
|
|
33
|
+
| `readBundle(buffer)` | Unpacks a `.tgz`, checks the rules (allowed files, 5MB, 200 files, paths outside the package, links, manual and samples), and returns `{ manifest, files, sha256, size }`. Throws `BundleError` when something is wrong |
|
|
34
|
+
| `BundleError` | `code` is one of `too_large`, `bad_bundle`, `bad_manifest` |
|
|
35
|
+
| `packBundle(files)` | Makes a `.tgz` from a list of files. The same input gives the same bytes |
|
|
36
|
+
| `compareVersions(a, b)` | semver order. -1, 0, 1 |
|
|
37
|
+
| `satisfies(version, range)` | Four kinds of range: `1.2.3`, `^1.2.3`, `~1.2.3`, `>=1.2.3`. The meaning is the same as in npm |
|
|
38
|
+
| `protocolAccepts(range, core?)` | Whether the `protocol` of a manifest accepts the contract version of the core |
|
|
39
|
+
| `stateId(plugins)`, `canonicalState(plugins)`, `checkState(plugins)` | Computes the state id of a plugin setup and checks the shape of the list |
|
|
40
|
+
| `isPluginId`, `idOwner`, `isVersion`, `isPrerelease`, `isRange`, `isProtocolRange`, `isStateId` | Shape checks |
|
|
41
|
+
| `bundleFileName`, `bundlePathAllowed`, `sha256Hex` | The package file name, whether a path may go into a package, sha256 |
|
|
42
|
+
| `BUNDLE_MAX_BYTES`, `BUNDLE_MAX_FILES`, `MAX_DEPENDENCIES`, `STATE_MAX_PLUGINS`, `RESERVED_IDS` | Limits and ids that cannot be used |
|
|
43
|
+
| `checkMessageTable(data)` | Checks the bytes of a message table file (`aic-link-messages/1`) of an external connection. Returns `{ ok: true, table }` when it is fine, and `{ ok: false, problems }` when it is not |
|
|
44
|
+
| `renderMessage(table, id, values)` | Turns a message id registered in the table and its values into text. For an unregistered id, wrong values, or a malformed id, it makes no text and returns the reason (`unknown_id`, `bad_values`, `malformed_id`) |
|
|
45
|
+
| `isMessageId`, `MESSAGE_TABLE_FORMAT`, `MESSAGE_TABLE_MAX_BYTES`, `MESSAGE_TABLE_MAX_MESSAGES`, `MESSAGE_TEXT_MAX` | Shape check and limits of the message table |
|
|
46
|
+
| `docsProblem(manifest, files)` | Checks that the files that `manual` (the manual) and `samples` of the manifest point to exist, and that their limits and shapes are right. `readBundle` calls it too |
|
|
47
|
+
| `bundleNotices(manifest)` | Things it only reports without rejecting. Now one line each when there is no manual or no icon |
|
|
48
|
+
| `checkSample(value)`, `parseSample(data)`, `parseManual(data)` | Shape check of a sample file (`aic-sample/1`), and character limit and UTF-8 checks of sample and manual files |
|
|
49
|
+
| `sampleNarrative(sample, { installed?, self? })`, `samplePluginLines`, `missingPlugins` | Turns a sample into text in order, per revision: what the person said, what the AI did, and the screen changes. Reports plugins that are not installed |
|
|
50
|
+
| `SAMPLE_FORMAT`, `MANUAL_MAX_CHARS`, `SAMPLE_MAX_CHARS`, `MAX_SAMPLES`, `SAMPLE_WHO` | The name of the sample format, the manual limit of 50,000 characters, 200,000 characters per sample, five samples, and how participants are written in the file ("Person", "AI", "Core", with a number such as "Person 2" when there are several of the same kind; older files that wrote "사람" and "코어" are still accepted) |
|
|
51
|
+
|
|
52
|
+
## Versions
|
|
53
|
+
|
|
54
|
+
When the check rules change, the version of this package goes up, and the registry site follows that version. While the version starts with 0, a change in the middle number means the rules changed in an incompatible way.
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
57
|
|
|
58
58
|
Apache-2.0
|
package/dist/bundle.js
CHANGED
|
@@ -44,7 +44,7 @@ export function docsProblem(manifest, files) {
|
|
|
44
44
|
if (manifest.manual !== undefined) {
|
|
45
45
|
const data = files.get(manifest.manual);
|
|
46
46
|
if (!data)
|
|
47
|
-
return
|
|
47
|
+
return `The manual file ${manifest.manual} is missing`;
|
|
48
48
|
const read = parseManual(data);
|
|
49
49
|
if (!read.ok)
|
|
50
50
|
return `${manifest.manual}: ${read.problem}`;
|
|
@@ -52,12 +52,12 @@ export function docsProblem(manifest, files) {
|
|
|
52
52
|
for (const s of manifest.samples ?? []) {
|
|
53
53
|
const data = files.get(s.file);
|
|
54
54
|
if (!data)
|
|
55
|
-
return
|
|
55
|
+
return `The file ${s.file} of sample ${s.id} is missing`;
|
|
56
56
|
const read = parseSample(data);
|
|
57
57
|
if (!read.ok)
|
|
58
|
-
return
|
|
58
|
+
return `Sample ${s.id} (${s.file}): ${read.problem}`;
|
|
59
59
|
if (!read.sample.plugins.some((p) => p.package === manifest.id))
|
|
60
|
-
return
|
|
60
|
+
return `The plugins of sample ${s.id} (${s.file}) do not include this plugin ${manifest.id}. Export a work that uses this plugin`;
|
|
61
61
|
}
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
@@ -67,7 +67,7 @@ export function iconFileProblem(manifest, files) {
|
|
|
67
67
|
return null;
|
|
68
68
|
const data = files.get(manifest.icon);
|
|
69
69
|
if (!data)
|
|
70
|
-
return
|
|
70
|
+
return `The icon file ${manifest.icon} is missing`;
|
|
71
71
|
const problem = iconProblem(data);
|
|
72
72
|
return problem ? `${manifest.icon}: ${problem}` : null;
|
|
73
73
|
}
|
|
@@ -77,8 +77,8 @@ export function iconFileProblem(manifest, files) {
|
|
|
77
77
|
*/
|
|
78
78
|
export function bundleNotices(manifest) {
|
|
79
79
|
return [
|
|
80
|
-
...(manifest.manual === undefined ? ['
|
|
81
|
-
...(manifest.icon === undefined ? ['
|
|
80
|
+
...(manifest.manual === undefined ? ['There is no manual (manual in the manifest). The registry site recommends a manual. The plugin can be uploaded without one'] : []),
|
|
81
|
+
...(manifest.icon === undefined ? ['There is no icon (icon in the manifest). The screen for choosing plugins shows the first letter of the name instead. The plugin can be uploaded without one'] : []),
|
|
82
82
|
];
|
|
83
83
|
}
|
|
84
84
|
// ---- ustar ----
|
|
@@ -91,7 +91,7 @@ function octal(value, width) {
|
|
|
91
91
|
function writeString(buf, offset, width, s) {
|
|
92
92
|
const bytes = Buffer.from(s, 'utf8');
|
|
93
93
|
if (bytes.length > width)
|
|
94
|
-
throw new BundleError('bad_bundle',
|
|
94
|
+
throw new BundleError('bad_bundle', `A name in the package is too long: ${s}`);
|
|
95
95
|
bytes.copy(buf, offset);
|
|
96
96
|
}
|
|
97
97
|
/** 이름이 100바이트를 넘으면 ustar 의 prefix(155바이트)로 나눈다. */
|
|
@@ -104,7 +104,7 @@ function splitName(p) {
|
|
|
104
104
|
if (Buffer.byteLength(prefix) <= 155 && Buffer.byteLength(name) <= 100)
|
|
105
105
|
return { name, prefix };
|
|
106
106
|
}
|
|
107
|
-
throw new BundleError('bad_bundle',
|
|
107
|
+
throw new BundleError('bad_bundle', `A path in the package is too long: ${p}`);
|
|
108
108
|
}
|
|
109
109
|
function header(p, size) {
|
|
110
110
|
const h = Buffer.alloc(BLOCK);
|
|
@@ -137,9 +137,9 @@ export function packBundle(files) {
|
|
|
137
137
|
const seen = new Set();
|
|
138
138
|
for (const [p, data] of entries) {
|
|
139
139
|
if (!isPluginPath(p))
|
|
140
|
-
throw new BundleError('bad_bundle',
|
|
140
|
+
throw new BundleError('bad_bundle', `This path cannot go into a package: ${JSON.stringify(p)}`);
|
|
141
141
|
if (seen.has(p))
|
|
142
|
-
throw new BundleError('bad_bundle',
|
|
142
|
+
throw new BundleError('bad_bundle', `The same path appears twice: ${p}`);
|
|
143
143
|
seen.add(p);
|
|
144
144
|
parts.push(header(p, data.length), data);
|
|
145
145
|
const pad = (BLOCK - (data.length % BLOCK)) % BLOCK;
|
|
@@ -161,12 +161,12 @@ function readString(buf, offset, width) {
|
|
|
161
161
|
}
|
|
162
162
|
function readOctal(buf, offset, width, what) {
|
|
163
163
|
if (buf[offset] & 0x80)
|
|
164
|
-
throw new BundleError('bad_bundle',
|
|
164
|
+
throw new BundleError('bad_bundle', `Could not read the ${what} of the package (base-256 notation is not accepted)`);
|
|
165
165
|
const s = readString(buf, offset, width).trim();
|
|
166
166
|
if (s === '')
|
|
167
167
|
return 0;
|
|
168
168
|
if (!/^[0-7]+$/.test(s))
|
|
169
|
-
throw new BundleError('bad_bundle',
|
|
169
|
+
throw new BundleError('bad_bundle', `The ${what} of the package is not an octal number`);
|
|
170
170
|
return parseInt(s, 8);
|
|
171
171
|
}
|
|
172
172
|
/** pax 머리말의 "길이 key=value\n" 기록에서 path 를 꺼낸다. */
|
|
@@ -179,7 +179,7 @@ function paxPath(data) {
|
|
|
179
179
|
break;
|
|
180
180
|
const len = Number(data.subarray(i, space).toString('ascii'));
|
|
181
181
|
if (!Number.isInteger(len) || len <= 0 || i + len > data.length)
|
|
182
|
-
throw new BundleError('bad_bundle', '
|
|
182
|
+
throw new BundleError('bad_bundle', 'Could not read the pax header of the package');
|
|
183
183
|
const record = data.subarray(space + 1, i + len - 1).toString('utf8');
|
|
184
184
|
const eq = record.indexOf('=');
|
|
185
185
|
if (eq > 0 && record.slice(0, eq) === 'path')
|
|
@@ -198,7 +198,7 @@ function cleanPath(raw, dir) {
|
|
|
198
198
|
if (dir && (p === '' || p === '.'))
|
|
199
199
|
return '';
|
|
200
200
|
if (!isPluginPath(p))
|
|
201
|
-
throw new BundleError('bad_bundle',
|
|
201
|
+
throw new BundleError('bad_bundle', `A path in the package is not a relative path inside the plugin folder: ${JSON.stringify(raw)}`);
|
|
202
202
|
return p;
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
@@ -211,7 +211,7 @@ function cleanPath(raw, dir) {
|
|
|
211
211
|
export function readBundle(buffer) {
|
|
212
212
|
const buf = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
213
213
|
if (buf.length > BUNDLE_MAX_BYTES)
|
|
214
|
-
throw new BundleError('too_large',
|
|
214
|
+
throw new BundleError('too_large', `The package is over ${BUNDLE_MAX_BYTES} bytes (${buf.length} bytes)`);
|
|
215
215
|
// 파일 내용의 합은 BUNDLE_MAX_BYTES 까지이고, 머리말과 채움은 파일마다 1,024 바이트를 넘지 않는다
|
|
216
216
|
const maxTar = BUNDLE_MAX_BYTES + (BUNDLE_MAX_FILES + 8) * BLOCK * 2;
|
|
217
217
|
let tar;
|
|
@@ -220,9 +220,9 @@ export function readBundle(buffer) {
|
|
|
220
220
|
}
|
|
221
221
|
catch (e) {
|
|
222
222
|
if (e instanceof RangeError || e.code === 'ERR_BUFFER_TOO_LARGE') {
|
|
223
|
-
throw new BundleError('too_large',
|
|
223
|
+
throw new BundleError('too_large', `The unpacked package is over the limit (${BUNDLE_MAX_BYTES} bytes)`);
|
|
224
224
|
}
|
|
225
|
-
throw new BundleError('bad_bundle',
|
|
225
|
+
throw new BundleError('bad_bundle', `The package is not a gzip file (${e.message})`);
|
|
226
226
|
}
|
|
227
227
|
const files = new Map();
|
|
228
228
|
let total = 0;
|
|
@@ -238,14 +238,14 @@ export function readBundle(buffer) {
|
|
|
238
238
|
let sum = 0;
|
|
239
239
|
for (let i = 0; i < BLOCK; i += 1)
|
|
240
240
|
sum += i >= 148 && i < 156 ? 0x20 : h[i];
|
|
241
|
-
if (readOctal(h, 148, 8, '
|
|
242
|
-
throw new BundleError('bad_bundle', '
|
|
243
|
-
const size = readOctal(h, 124, 12, '
|
|
241
|
+
if (readOctal(h, 148, 8, 'checksum') !== sum)
|
|
242
|
+
throw new BundleError('bad_bundle', 'The header checksum of the package does not match');
|
|
243
|
+
const size = readOctal(h, 124, 12, 'file size');
|
|
244
244
|
const type = String.fromCharCode(h[156]);
|
|
245
245
|
const dataStart = offset + BLOCK;
|
|
246
246
|
const dataEnd = dataStart + size;
|
|
247
247
|
if (dataEnd > tar.length)
|
|
248
|
-
throw new BundleError('bad_bundle', '
|
|
248
|
+
throw new BundleError('bad_bundle', 'The package is cut off in the middle');
|
|
249
249
|
const data = tar.subarray(dataStart, dataEnd);
|
|
250
250
|
offset = dataStart + Math.ceil(size / BLOCK) * BLOCK;
|
|
251
251
|
if (type === 'x') {
|
|
@@ -266,40 +266,40 @@ export function readBundle(buffer) {
|
|
|
266
266
|
continue;
|
|
267
267
|
}
|
|
268
268
|
if (type !== '0' && type !== '\0')
|
|
269
|
-
throw new BundleError('bad_bundle',
|
|
269
|
+
throw new BundleError('bad_bundle', `The package has an entry that is not a regular file: ${rawName}`);
|
|
270
270
|
const p = cleanPath(rawName, false);
|
|
271
271
|
if (files.has(p))
|
|
272
|
-
throw new BundleError('bad_bundle',
|
|
272
|
+
throw new BundleError('bad_bundle', `The package has the same path twice: ${p}`);
|
|
273
273
|
if (files.size + 1 > BUNDLE_MAX_FILES)
|
|
274
|
-
throw new BundleError('too_large',
|
|
274
|
+
throw new BundleError('too_large', `The package has more than ${BUNDLE_MAX_FILES} files`);
|
|
275
275
|
total += size;
|
|
276
276
|
if (total > BUNDLE_MAX_BYTES)
|
|
277
|
-
throw new BundleError('too_large',
|
|
277
|
+
throw new BundleError('too_large', `The total file size in the package is over ${BUNDLE_MAX_BYTES} bytes`);
|
|
278
278
|
files.set(p, Buffer.from(data));
|
|
279
279
|
}
|
|
280
280
|
if (!ended)
|
|
281
|
-
throw new BundleError('bad_bundle', '
|
|
281
|
+
throw new BundleError('bad_bundle', 'The package has no end marker');
|
|
282
282
|
const manifestFile = files.get('manifest.json');
|
|
283
283
|
if (!manifestFile)
|
|
284
|
-
throw new BundleError('bad_bundle', '
|
|
284
|
+
throw new BundleError('bad_bundle', 'The package has no manifest.json');
|
|
285
285
|
let manifest;
|
|
286
286
|
try {
|
|
287
287
|
manifest = JSON.parse(manifestFile.toString('utf8'));
|
|
288
288
|
}
|
|
289
289
|
catch (e) {
|
|
290
|
-
throw new BundleError('bad_manifest', `manifest.json
|
|
290
|
+
throw new BundleError('bad_manifest', `manifest.json is not JSON (${e.message})`);
|
|
291
291
|
}
|
|
292
292
|
const problem = checkManifest(manifest);
|
|
293
293
|
if (problem)
|
|
294
294
|
throw new BundleError('bad_manifest', problem);
|
|
295
295
|
const m = manifest;
|
|
296
296
|
if (!files.has(m.logic))
|
|
297
|
-
throw new BundleError('bad_bundle',
|
|
297
|
+
throw new BundleError('bad_bundle', `The package has no logic file ${m.logic}`);
|
|
298
298
|
if (m.ui !== undefined && !files.has(m.ui))
|
|
299
|
-
throw new BundleError('bad_bundle',
|
|
299
|
+
throw new BundleError('bad_bundle', `The package has no screen file ${m.ui}`);
|
|
300
300
|
const extra = [...files.keys()].filter((p) => !bundlePathAllowed(p, m));
|
|
301
301
|
if (extra.length > 0) {
|
|
302
|
-
throw new BundleError('bad_bundle',
|
|
302
|
+
throw new BundleError('bad_bundle', `The package has files that cannot go into it: ${extra.join(', ')}. Only include manifest.json, the logic file, files in ui/, LICENSE, README.md, and the files that manual and samples in the manifest point to`);
|
|
303
303
|
}
|
|
304
304
|
const docs = docsProblem(m, files) ?? iconFileProblem(m, files);
|
|
305
305
|
if (docs)
|
|
@@ -314,5 +314,5 @@ export function checkBundleForRegistry(bundle) {
|
|
|
314
314
|
const problem = checkForRegistry(bundle.manifest);
|
|
315
315
|
if (problem)
|
|
316
316
|
return { code: 'bad_manifest', message: problem };
|
|
317
|
-
return bundle.files.has('LICENSE') ? null : { code: 'bad_bundle', message: '
|
|
317
|
+
return bundle.files.has('LICENSE') ? null : { code: 'bad_bundle', message: 'To upload to the site, the package needs a LICENSE file' };
|
|
318
318
|
}
|
package/dist/icon.js
CHANGED
|
@@ -24,38 +24,38 @@ function insideOnly(text, pattern) {
|
|
|
24
24
|
*/
|
|
25
25
|
export function iconProblem(data) {
|
|
26
26
|
if (data.length === 0)
|
|
27
|
-
return '
|
|
27
|
+
return 'The icon file is empty';
|
|
28
28
|
if (data.length > ICON_MAX_BYTES)
|
|
29
|
-
return
|
|
29
|
+
return `The icon file is over ${ICON_MAX_BYTES.toLocaleString('en-US')} bytes (${data.length.toLocaleString('en-US')} bytes)`;
|
|
30
30
|
let text;
|
|
31
31
|
try {
|
|
32
32
|
text = new TextDecoder('utf-8', { fatal: true }).decode(data);
|
|
33
33
|
}
|
|
34
34
|
catch {
|
|
35
|
-
return '
|
|
35
|
+
return 'The icon file is not UTF-8 text';
|
|
36
36
|
}
|
|
37
37
|
if (/<!DOCTYPE|<!ENTITY/i.test(text))
|
|
38
|
-
return '
|
|
38
|
+
return 'The icon must not contain DOCTYPE or ENTITY';
|
|
39
39
|
const body = text
|
|
40
40
|
.replace(new RegExp('^' + String.fromCharCode(0xfeff)), '')
|
|
41
41
|
.replace(/^\s*<\?xml[^>]*\?>/, '')
|
|
42
42
|
.replace(/<!--[\s\S]*?-->/g, '');
|
|
43
43
|
if (!/^\s*<svg[\s>]/i.test(body))
|
|
44
|
-
return '
|
|
44
|
+
return 'The icon file is not an SVG that starts with <svg';
|
|
45
45
|
if (!/<\/svg>\s*$/i.test(body))
|
|
46
|
-
return '
|
|
46
|
+
return 'The icon file does not end with </svg>';
|
|
47
47
|
const banned = /<\s*(script|foreignObject|iframe|object|embed|audio|video|link|meta|style|animate|animateTransform|animateMotion|set)\b/i.exec(body);
|
|
48
48
|
if (banned)
|
|
49
|
-
return
|
|
49
|
+
return `The icon must not contain a ${banned[1]} element`;
|
|
50
50
|
if (/[\s"'/]on[a-z]+\s*=/i.test(body))
|
|
51
|
-
return '
|
|
51
|
+
return 'The icon must not contain event attributes (on...)';
|
|
52
52
|
if (/javascript\s*:|@import/i.test(body))
|
|
53
|
-
return '
|
|
53
|
+
return 'The icon must not contain javascript: addresses or @import';
|
|
54
54
|
if (!insideOnly(body, /\b(xlink:href|href|src)\s*=\s*(?:"([^"]*)"|'([^']*)')/gi))
|
|
55
|
-
return '
|
|
55
|
+
return 'href and src in the icon may only point to a #id inside the document (outside addresses and data: addresses are not accepted)';
|
|
56
56
|
for (const m of body.matchAll(/url\(\s*(["']?)([^)"']*)\1\s*\)/gi)) {
|
|
57
57
|
if (!m[2].trim().startsWith('#'))
|
|
58
|
-
return '
|
|
58
|
+
return 'url() in the icon may only point to a #id inside the document';
|
|
59
59
|
}
|
|
60
60
|
return null;
|
|
61
61
|
}
|
package/dist/manifest.js
CHANGED
|
@@ -46,17 +46,17 @@ function chars(s) {
|
|
|
46
46
|
/** 비어 있지 않은 글이고 한도 안인가. 문제가 있으면 그 설명이다. */
|
|
47
47
|
function textProblem(where, value, max) {
|
|
48
48
|
if (typeof value !== 'string' || value.trim() === '')
|
|
49
|
-
return `${where}
|
|
49
|
+
return `${where} must be non-empty text`;
|
|
50
50
|
if (chars(value) > max)
|
|
51
|
-
return `${where}
|
|
51
|
+
return `${where} is over ${max.toLocaleString('en-US')} characters (${chars(value)} characters)`;
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
54
54
|
/** 칸을 모두 아는 객체인가. 칸 이름을 잘못 적으면 조용히 빠지므로 모르는 칸은 받지 않는다. */
|
|
55
55
|
function objectProblem(where, value, known) {
|
|
56
56
|
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
57
|
-
return `${where}
|
|
57
|
+
return `${where} must be an object`;
|
|
58
58
|
const extra = Object.keys(value).filter((k) => !known.includes(k));
|
|
59
|
-
return extra.length > 0 ? `${where}
|
|
59
|
+
return extra.length > 0 ? `${where} has unknown fields: ${extra.join(', ')}` : null;
|
|
60
60
|
}
|
|
61
61
|
function requiresProblem(value) {
|
|
62
62
|
const problem = objectProblem('requires', value, ['os', 'external']);
|
|
@@ -65,18 +65,18 @@ function requiresProblem(value) {
|
|
|
65
65
|
const r = value;
|
|
66
66
|
if (r.os !== undefined && r.os !== 'any') {
|
|
67
67
|
if (!Array.isArray(r.os) || r.os.length === 0)
|
|
68
|
-
return 'requires.os
|
|
68
|
+
return 'requires.os must be "any" or a list of windows, macos, linux';
|
|
69
69
|
const bad = r.os.filter((o) => typeof o !== 'string' || !OS_NAMES.includes(o));
|
|
70
70
|
if (bad.length > 0)
|
|
71
|
-
return `requires.os
|
|
71
|
+
return `requires.os has an unknown operating system: ${bad.map((o) => JSON.stringify(o)).join(', ')}`;
|
|
72
72
|
if (new Set(r.os).size !== r.os.length)
|
|
73
|
-
return 'requires.os
|
|
73
|
+
return 'requires.os repeats the same operating system';
|
|
74
74
|
}
|
|
75
75
|
if (r.external !== undefined) {
|
|
76
76
|
if (!Array.isArray(r.external))
|
|
77
|
-
return 'requires.external
|
|
77
|
+
return 'requires.external must be a list of external tools';
|
|
78
78
|
if (r.external.length > 10)
|
|
79
|
-
return `requires.external
|
|
79
|
+
return `requires.external can have up to 10 entries (${r.external.length} given)`;
|
|
80
80
|
for (const [i, t] of r.external.entries()) {
|
|
81
81
|
const where = `requires.external[${i}]`;
|
|
82
82
|
const shape = objectProblem(where, t, ['name', 'kind', 'account', 'install', 'note']);
|
|
@@ -87,11 +87,11 @@ function requiresProblem(value) {
|
|
|
87
87
|
if (name)
|
|
88
88
|
return name;
|
|
89
89
|
if (typeof tool.kind !== 'string' || !TOOL_KINDS.includes(tool.kind))
|
|
90
|
-
return `${where}.kind
|
|
90
|
+
return `${where}.kind must be one of program, web, mcp`;
|
|
91
91
|
if (typeof tool.account !== 'string' || !ACCOUNTS.includes(tool.account))
|
|
92
|
-
return `${where}.account
|
|
92
|
+
return `${where}.account must be one of none, free, paid`;
|
|
93
93
|
if (typeof tool.install !== 'boolean')
|
|
94
|
-
return `${where}.install
|
|
94
|
+
return `${where}.install must be true or false`;
|
|
95
95
|
if (tool.note !== undefined) {
|
|
96
96
|
const note = textProblem(`${where}.note`, tool.note, 200);
|
|
97
97
|
if (note)
|
|
@@ -107,14 +107,14 @@ function requiresProblem(value) {
|
|
|
107
107
|
*/
|
|
108
108
|
function manualProblem(m) {
|
|
109
109
|
if (m.manual !== undefined && (!isPluginPath(m.manual) || !m.manual.endsWith('.md'))) {
|
|
110
|
-
return `manual ${JSON.stringify(m.manual)}
|
|
110
|
+
return `manual ${JSON.stringify(m.manual)} must be a relative path to a Markdown file (.md) inside the plugin folder (for example docs/manual.md)`;
|
|
111
111
|
}
|
|
112
112
|
if (m.samples === undefined)
|
|
113
113
|
return null;
|
|
114
114
|
if (!Array.isArray(m.samples))
|
|
115
|
-
return 'samples
|
|
115
|
+
return 'samples must be a list of { id, title, about, file }';
|
|
116
116
|
if (m.samples.length > MAX_SAMPLES)
|
|
117
|
-
return `samples
|
|
117
|
+
return `samples can have up to 5 entries (${m.samples.length} given)`;
|
|
118
118
|
const ids = new Set();
|
|
119
119
|
const files = new Set();
|
|
120
120
|
for (const [i, s] of m.samples.entries()) {
|
|
@@ -124,16 +124,16 @@ function manualProblem(m) {
|
|
|
124
124
|
return shape;
|
|
125
125
|
const sample = s;
|
|
126
126
|
if (typeof sample.id !== 'string' || !SAMPLE_ID.test(sample.id))
|
|
127
|
-
return `${where}.id
|
|
127
|
+
return `${where}.id must be 1 to 40 characters of lowercase English letters, digits, and -`;
|
|
128
128
|
const text = textProblem(`${where}.title`, sample.title, 100) ?? textProblem(`${where}.about`, sample.about, 300);
|
|
129
129
|
if (text)
|
|
130
130
|
return text;
|
|
131
131
|
if (!isPluginPath(sample.file) || !sample.file.endsWith('.json'))
|
|
132
|
-
return `${where}.file ${JSON.stringify(sample.file)}
|
|
132
|
+
return `${where}.file ${JSON.stringify(sample.file)} must be a relative path to a sample file (.json) inside the plugin folder (for example samples/first.json)`;
|
|
133
133
|
if (ids.has(sample.id))
|
|
134
|
-
return `samples
|
|
134
|
+
return `samples has the id ${sample.id} twice`;
|
|
135
135
|
if (files.has(sample.file))
|
|
136
|
-
return `samples
|
|
136
|
+
return `samples has the file ${sample.file} twice`;
|
|
137
137
|
ids.add(sample.id);
|
|
138
138
|
files.add(sample.file);
|
|
139
139
|
}
|
|
@@ -141,19 +141,19 @@ function manualProblem(m) {
|
|
|
141
141
|
}
|
|
142
142
|
function dependenciesProblem(id, value) {
|
|
143
143
|
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
144
|
-
return 'dependencies
|
|
144
|
+
return 'dependencies must be an object { "<id>": "<version range>" }';
|
|
145
145
|
const entries = Object.entries(value);
|
|
146
146
|
if (entries.length > MAX_DEPENDENCIES)
|
|
147
|
-
return `dependencies
|
|
147
|
+
return `dependencies can have up to ${MAX_DEPENDENCIES} entries (${entries.length} given)`;
|
|
148
148
|
for (const [dep, range] of entries) {
|
|
149
149
|
if (!isPluginId(dep))
|
|
150
|
-
return
|
|
150
|
+
return `${JSON.stringify(dep)} in dependencies is not shaped like a plugin id`;
|
|
151
151
|
if (RESERVED_IDS.includes(dep))
|
|
152
|
-
return `
|
|
152
|
+
return `Do not list ${dep} in dependencies. It is a name built into the core`;
|
|
153
153
|
if (dep === id)
|
|
154
|
-
return '
|
|
154
|
+
return 'Do not list the plugin itself in dependencies';
|
|
155
155
|
if (!isRange(range))
|
|
156
|
-
return
|
|
156
|
+
return `${JSON.stringify(range)} in dependencies.${dep} must have one of the shapes 1.2.3, ^1.2.3, ~1.2.3, >=1.2.3`;
|
|
157
157
|
}
|
|
158
158
|
return null;
|
|
159
159
|
}
|
|
@@ -163,28 +163,28 @@ function dependenciesProblem(id, value) {
|
|
|
163
163
|
*/
|
|
164
164
|
export function checkManifest(manifest) {
|
|
165
165
|
if (typeof manifest !== 'object' || manifest === null || Array.isArray(manifest))
|
|
166
|
-
return 'manifest
|
|
166
|
+
return 'manifest must be an object';
|
|
167
167
|
const m = manifest;
|
|
168
168
|
for (const key of ['id', 'version', 'logic']) {
|
|
169
169
|
if (typeof m[key] !== 'string')
|
|
170
|
-
return `manifest
|
|
170
|
+
return `manifest has no ${key}`;
|
|
171
171
|
}
|
|
172
172
|
const id = m.id;
|
|
173
173
|
if (!isPluginId(id))
|
|
174
|
-
return `id ${JSON.stringify(id)}
|
|
174
|
+
return `id ${JSON.stringify(id)} must look like account.plugin-name. Each part is 2 to 40 characters of lowercase English letters, digits, and -`;
|
|
175
175
|
if (RESERVED_IDS.includes(id))
|
|
176
|
-
return `id ${id}
|
|
176
|
+
return `id ${id} is a name built into the core, so it cannot be used as a plugin id`;
|
|
177
177
|
if (!isVersion(m.version))
|
|
178
|
-
return `version ${JSON.stringify(m.version)}
|
|
178
|
+
return `version ${JSON.stringify(m.version)} must be semver (number.number.number, optionally followed by -prerelease-name)`;
|
|
179
179
|
if (typeof m.dataVersion !== 'number' || !Number.isInteger(m.dataVersion) || m.dataVersion < 1)
|
|
180
|
-
return 'dataVersion
|
|
180
|
+
return 'dataVersion must be an integer of 1 or more';
|
|
181
181
|
if (!isPluginPath(m.logic))
|
|
182
|
-
return `logic ${JSON.stringify(m.logic)}
|
|
182
|
+
return `logic ${JSON.stringify(m.logic)} must be a relative path inside the plugin folder (.. and absolute paths are not accepted)`;
|
|
183
183
|
if (m.ui !== undefined && !isUiPath(m.ui))
|
|
184
|
-
return `ui ${JSON.stringify(m.ui)}
|
|
184
|
+
return `ui ${JSON.stringify(m.ui)} must be a file directly under ui/ (for example ui/index.html)`;
|
|
185
185
|
// 아이콘은 코어가 내보내는 ui/ 의 파일이어야 화면이 읽는다. icon.ts 의 isIconPath 와 같은 모양이다(서로 불러오지 않게 여기에 적는다)
|
|
186
186
|
if (m.icon !== undefined && (!isUiPath(m.icon) || !m.icon.toLowerCase().endsWith('.svg'))) {
|
|
187
|
-
return `icon ${JSON.stringify(m.icon)}
|
|
187
|
+
return `icon ${JSON.stringify(m.icon)} must be an SVG file (.svg) directly under ui/ (for example ui/icon.svg)`;
|
|
188
188
|
}
|
|
189
189
|
if (m.title !== undefined) {
|
|
190
190
|
const problem = textProblem('title', m.title, 100);
|
|
@@ -203,9 +203,9 @@ export function checkManifest(manifest) {
|
|
|
203
203
|
}
|
|
204
204
|
if (m.examples !== undefined) {
|
|
205
205
|
if (!Array.isArray(m.examples))
|
|
206
|
-
return 'examples
|
|
206
|
+
return 'examples must be a list of { ask, does }';
|
|
207
207
|
if (m.examples.length > 5)
|
|
208
|
-
return `examples
|
|
208
|
+
return `examples can have up to 5 entries (${m.examples.length} given)`;
|
|
209
209
|
for (const [i, e] of m.examples.entries()) {
|
|
210
210
|
const where = `examples[${i}]`;
|
|
211
211
|
const problem = objectProblem(where, e, ['ask', 'does']) ??
|
|
@@ -221,7 +221,7 @@ export function checkManifest(manifest) {
|
|
|
221
221
|
return problem;
|
|
222
222
|
}
|
|
223
223
|
if (m.protocol !== undefined && !isProtocolRange(m.protocol)) {
|
|
224
|
-
return `protocol ${JSON.stringify(m.protocol)}
|
|
224
|
+
return `protocol ${JSON.stringify(m.protocol)} must look like 0.<number> (for example "0.1")`;
|
|
225
225
|
}
|
|
226
226
|
if (m.dependencies !== undefined) {
|
|
227
227
|
const problem = dependenciesProblem(id, m.dependencies);
|
|
@@ -240,5 +240,5 @@ export function checkForRegistry(manifest) {
|
|
|
240
240
|
return problem;
|
|
241
241
|
const m = manifest;
|
|
242
242
|
const missing = ['protocol', 'license', 'title', 'about'].filter((k) => m[k] === undefined);
|
|
243
|
-
return missing.length > 0 ?
|
|
243
|
+
return missing.length > 0 ? `To upload to the site, the manifest needs the field(s) ${missing.join(', ')}` : null;
|
|
244
244
|
}
|
package/dist/messages.js
CHANGED
|
@@ -55,7 +55,7 @@ function valueEdgeProblems(text) {
|
|
|
55
55
|
const beforeOk = before === null || VALUE_EDGE.test(before);
|
|
56
56
|
const afterOk = after === null || VALUE_EDGE.test(after) || (after === '.' && (end + 1 >= text.length || text[end + 1] === ' '));
|
|
57
57
|
if (!beforeOk || !afterOk) {
|
|
58
|
-
out.push(`{${m[1]}}
|
|
58
|
+
out.push(`The characters right before and after {${m[1]}} must be a space or punctuation (, ; ! ? ( ) ' "). A period may follow it only at the end of a sentence (followed by a space or the end of the text)`);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
return out;
|
|
@@ -67,33 +67,33 @@ function valueEdgeProblems(text) {
|
|
|
67
67
|
*/
|
|
68
68
|
function textProblems(text, names) {
|
|
69
69
|
if (typeof text !== 'string' || text === '')
|
|
70
|
-
return ['text
|
|
70
|
+
return ['text must be non-empty text'];
|
|
71
71
|
const out = [];
|
|
72
72
|
if (text.length > MESSAGE_TEXT_MAX)
|
|
73
|
-
out.push(
|
|
73
|
+
out.push(`The text is over ${MESSAGE_TEXT_MAX} characters (${text.length} characters)`);
|
|
74
74
|
if ([...text].some((c) => c.charCodeAt(0) < 0x20 || c.charCodeAt(0) > 0x7e))
|
|
75
|
-
out.push('
|
|
75
|
+
out.push('The text may only use visible ASCII (0x20 to 0x7E). Line breaks and non-English characters are not accepted');
|
|
76
76
|
if (!/[A-Za-z]/.test(text))
|
|
77
|
-
out.push('
|
|
77
|
+
out.push('The text must be an English sentence');
|
|
78
78
|
if (hasAddress(text))
|
|
79
|
-
out.push('
|
|
79
|
+
out.push('The text cannot contain addresses (://, www., a period between letters, and @ are not accepted)');
|
|
80
80
|
if (/[<>[\]`\\]/.test(text))
|
|
81
|
-
out.push('
|
|
81
|
+
out.push('The text must not use < > [ ] backticks or backslashes');
|
|
82
82
|
out.push(...valueEdgeProblems(text));
|
|
83
83
|
const used = new Set();
|
|
84
84
|
for (const m of text.matchAll(PLACEHOLDER)) {
|
|
85
85
|
const name = m[1];
|
|
86
86
|
if (!VALUE_NAME.test(name))
|
|
87
|
-
out.push(`{${name}}
|
|
87
|
+
out.push(`{${name}} is not shaped like a value name (starts with a lowercase English letter, up to 32 lowercase letters, digits, and _)`);
|
|
88
88
|
else if (!names.includes(name))
|
|
89
|
-
out.push(`{${name}}
|
|
89
|
+
out.push(`{${name}} is not in values`);
|
|
90
90
|
used.add(name);
|
|
91
91
|
}
|
|
92
92
|
if (/[{}]/.test(text.replace(PLACEHOLDER, '')))
|
|
93
|
-
out.push('
|
|
93
|
+
out.push('There is an unmatched { or }');
|
|
94
94
|
for (const n of names)
|
|
95
95
|
if (!used.has(n))
|
|
96
|
-
out.push(
|
|
96
|
+
out.push(`${n} in values does not appear in the text`);
|
|
97
97
|
return out;
|
|
98
98
|
}
|
|
99
99
|
/** values 의 까닭들. 이름마다 종류 하나이고, enum 은 낱말 목록을 함께 적는다. */
|
|
@@ -101,34 +101,34 @@ function valuesProblems(values) {
|
|
|
101
101
|
if (values === undefined)
|
|
102
102
|
return [];
|
|
103
103
|
if (!isPlainObject(values))
|
|
104
|
-
return ['values
|
|
104
|
+
return ['values must be an object that gives a type for each name'];
|
|
105
105
|
const out = [];
|
|
106
106
|
for (const [name, spec] of Object.entries(values)) {
|
|
107
|
-
const at =
|
|
107
|
+
const at = `value ${name}`;
|
|
108
108
|
if (!VALUE_NAME.test(name))
|
|
109
|
-
out.push(`${at}:
|
|
109
|
+
out.push(`${at}: the name starts with a lowercase English letter and has up to 32 lowercase letters, digits, and _`);
|
|
110
110
|
if (!isPlainObject(spec) || !MESSAGE_VALUE_TYPES.includes(spec.type)) {
|
|
111
|
-
out.push(`${at}: type
|
|
111
|
+
out.push(`${at}: type must be one of ${MESSAGE_VALUE_TYPES.join(', ')}. There is no free text value`);
|
|
112
112
|
continue;
|
|
113
113
|
}
|
|
114
114
|
const extra = Object.keys(spec).filter((k) => k !== 'type' && !(spec.type === 'enum' && k === 'values'));
|
|
115
115
|
if (extra.length)
|
|
116
|
-
out.push(`${at}:
|
|
116
|
+
out.push(`${at}: unknown fields ${extra.join(', ')}`);
|
|
117
117
|
if (spec.type !== 'enum')
|
|
118
118
|
continue;
|
|
119
119
|
const words = spec.values;
|
|
120
120
|
if (!Array.isArray(words) || words.length === 0 || words.length > MESSAGE_ENUM_MAX_VALUES) {
|
|
121
|
-
out.push(`${at}: enum
|
|
121
|
+
out.push(`${at}: the values of an enum must be a list of 1 to ${MESSAGE_ENUM_MAX_VALUES} words`);
|
|
122
122
|
continue;
|
|
123
123
|
}
|
|
124
124
|
for (const w of words) {
|
|
125
125
|
if (typeof w !== 'string' || w.length > MESSAGE_ENUM_WORD_MAX || !ENUM_WORD.test(w)) {
|
|
126
|
-
out.push(`${at}: enum
|
|
126
|
+
out.push(`${at}: an enum word has up to ${MESSAGE_ENUM_WORD_MAX} English letters, digits, spaces, and _-`);
|
|
127
127
|
break;
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
if (new Set(words).size !== words.length)
|
|
131
|
-
out.push(`${at}: enum
|
|
131
|
+
out.push(`${at}: enum words repeat`);
|
|
132
132
|
}
|
|
133
133
|
return out;
|
|
134
134
|
}
|
|
@@ -139,7 +139,7 @@ function valuesProblems(values) {
|
|
|
139
139
|
export function checkMessageTable(data) {
|
|
140
140
|
const bytes = typeof data === 'string' ? new TextEncoder().encode(data) : data;
|
|
141
141
|
if (bytes.byteLength > MESSAGE_TABLE_MAX_BYTES)
|
|
142
|
-
return { ok: false, problems: [
|
|
142
|
+
return { ok: false, problems: [`The table file is over ${MESSAGE_TABLE_MAX_BYTES} bytes (${bytes.byteLength} bytes)`] };
|
|
143
143
|
let raw;
|
|
144
144
|
try {
|
|
145
145
|
const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
@@ -147,38 +147,38 @@ export function checkMessageTable(data) {
|
|
|
147
147
|
}
|
|
148
148
|
catch {
|
|
149
149
|
// 해석기의 글은 파일의 일부를 옮겨 적을 수 있어 까닭은 적지 않는다.
|
|
150
|
-
return { ok: false, problems: ['
|
|
150
|
+
return { ok: false, problems: ['The table file is not UTF-8 JSON'] };
|
|
151
151
|
}
|
|
152
152
|
if (!isPlainObject(raw))
|
|
153
|
-
return { ok: false, problems: ['
|
|
153
|
+
return { ok: false, problems: ['The table must be an object with format, version, and messages'] };
|
|
154
154
|
const problems = [];
|
|
155
155
|
const extra = Object.keys(raw).filter((k) => !['format', 'version', 'messages'].includes(k));
|
|
156
156
|
if (extra.length)
|
|
157
|
-
problems.push(
|
|
157
|
+
problems.push(`Unknown fields: ${extra.join(', ')}`);
|
|
158
158
|
if (raw.format !== MESSAGE_TABLE_FORMAT)
|
|
159
|
-
problems.push(`format
|
|
159
|
+
problems.push(`format must be ${MESSAGE_TABLE_FORMAT}`);
|
|
160
160
|
if (!isVersion(raw.version))
|
|
161
|
-
problems.push('version
|
|
161
|
+
problems.push('version must be semver such as 1.0.0');
|
|
162
162
|
if (!isPlainObject(raw.messages)) {
|
|
163
|
-
problems.push('messages
|
|
163
|
+
problems.push('messages must be an object that gives text for each message id');
|
|
164
164
|
return { ok: false, problems };
|
|
165
165
|
}
|
|
166
166
|
const entries = Object.entries(raw.messages);
|
|
167
167
|
if (entries.length === 0)
|
|
168
|
-
problems.push('messages
|
|
168
|
+
problems.push('messages is empty');
|
|
169
169
|
if (entries.length > MESSAGE_TABLE_MAX_MESSAGES)
|
|
170
|
-
problems.push(
|
|
170
|
+
problems.push(`There are more than ${MESSAGE_TABLE_MAX_MESSAGES} messages (${entries.length})`);
|
|
171
171
|
for (const [id, def] of entries) {
|
|
172
|
-
const at =
|
|
172
|
+
const at = `message ${MESSAGE_ID.test(id) ? id : '(malformed id)'}`;
|
|
173
173
|
if (!MESSAGE_ID.test(id))
|
|
174
|
-
problems.push(`${at}: id
|
|
174
|
+
problems.push(`${at}: the id starts with a lowercase English letter and has up to 64 lowercase letters, digits, and _`);
|
|
175
175
|
if (!isPlainObject(def)) {
|
|
176
|
-
problems.push(`${at}:
|
|
176
|
+
problems.push(`${at}: must be an object with text and values`);
|
|
177
177
|
continue;
|
|
178
178
|
}
|
|
179
179
|
const unknown = Object.keys(def).filter((k) => k !== 'text' && k !== 'values');
|
|
180
180
|
if (unknown.length)
|
|
181
|
-
problems.push(`${at}:
|
|
181
|
+
problems.push(`${at}: unknown fields ${unknown.join(', ')}`);
|
|
182
182
|
const vp = valuesProblems(def.values);
|
|
183
183
|
for (const p of vp)
|
|
184
184
|
problems.push(`${at}: ${p}`);
|
|
@@ -189,7 +189,7 @@ export function checkMessageTable(data) {
|
|
|
189
189
|
if (problems.length > 0) {
|
|
190
190
|
const shown = problems.slice(0, MAX_PROBLEMS);
|
|
191
191
|
if (problems.length > MAX_PROBLEMS)
|
|
192
|
-
shown.push(
|
|
192
|
+
shown.push(`${problems.length - MAX_PROBLEMS} more`);
|
|
193
193
|
return { ok: false, problems: shown };
|
|
194
194
|
}
|
|
195
195
|
return { ok: true, table: raw };
|
package/dist/sample.d.ts
CHANGED
|
@@ -3,7 +3,10 @@ export declare const SAMPLE_FORMAT = "aic-sample/1";
|
|
|
3
3
|
export declare const MANUAL_MAX_CHARS = 50000;
|
|
4
4
|
/** 예제 파일 하나의 한도(글자, 037 7절 4번). */
|
|
5
5
|
export declare const SAMPLE_MAX_CHARS = 200000;
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* 예제를 쓴 참여자. 실제 이름 대신 "Person", "AI" 이고, 같은 종류가 여럿이면 "Person 2" 처럼 번호를 붙인다. 참여자가 없는 revision 은 "Core" 다.
|
|
8
|
+
* 새로 내보내는 파일은 영어로 쓰고, 옛 파일의 "사람", "코어" 도 읽는다(999 4.2절, rawdev 2026-11-30).
|
|
9
|
+
*/
|
|
7
10
|
export declare const SAMPLE_WHO: RegExp;
|
|
8
11
|
/** 예제가 쓴 플러그인 하나. version 은 그 작업에 적힌 가장 높은 버전이다. */
|
|
9
12
|
export interface SamplePlugin {
|
|
@@ -132,7 +135,7 @@ export declare function charCount(s: string): number;
|
|
|
132
135
|
/**
|
|
133
136
|
* 예제 파일(aic-sample/1)의 검사. 문제의 설명이고 없으면 null 이다. 맨 위 층과 revision 과 원인에 모르는 칸이 있으면 거절한다.
|
|
134
137
|
* 예제는 실제 작업을 내보낸 것이어야 하고(037 7절 2번), 내보낼 때 지운 것(참여자 이름, 도구, 시각, 연결 정의)이 다시 들어가지
|
|
135
|
-
* 않게 하려는 것이다. 참여자는 "
|
|
138
|
+
* 않게 하려는 것이다. 참여자는 "Person", "AI", "Core" 로만 적는다(옛 파일의 "사람", "코어" 도 받는다).
|
|
136
139
|
*/
|
|
137
140
|
export declare function checkSample(value: unknown): string | null;
|
|
138
141
|
/** 예제 파일의 글(바이트)을 풀고 검사한다. 맞으면 { ok: true, sample }, 틀리면 까닭이다. 글자 한도도 본다. */
|
package/dist/sample.js
CHANGED
|
@@ -7,8 +7,11 @@ export const SAMPLE_FORMAT = 'aic-sample/1';
|
|
|
7
7
|
export const MANUAL_MAX_CHARS = 50_000;
|
|
8
8
|
/** 예제 파일 하나의 한도(글자, 037 7절 4번). */
|
|
9
9
|
export const SAMPLE_MAX_CHARS = 200_000;
|
|
10
|
-
/**
|
|
11
|
-
|
|
10
|
+
/**
|
|
11
|
+
* 예제를 쓴 참여자. 실제 이름 대신 "Person", "AI" 이고, 같은 종류가 여럿이면 "Person 2" 처럼 번호를 붙인다. 참여자가 없는 revision 은 "Core" 다.
|
|
12
|
+
* 새로 내보내는 파일은 영어로 쓰고, 옛 파일의 "사람", "코어" 도 읽는다(999 4.2절, rawdev 2026-11-30).
|
|
13
|
+
*/
|
|
14
|
+
export const SAMPLE_WHO = /^(Person|AI|Core|사람|코어)( [2-9]| [1-9]\d)?$/;
|
|
12
15
|
/** 글자 수(코드 포인트). manifest 의 길이 한도와 같은 방법으로 잰다. */
|
|
13
16
|
export function charCount(s) {
|
|
14
17
|
let n = 0;
|
|
@@ -24,19 +27,19 @@ const REVISION_KEYS = ['revision', 'who', 'kind', 'cause', 'summary', 'operation
|
|
|
24
27
|
const TOP_KEYS = ['format', 'title', 'plugins', 'instances', 'revisions', 'generations', 'transmissions'];
|
|
25
28
|
function wordsProblem(where, w) {
|
|
26
29
|
if (!isObject(w) || !isText(w.text) || (w.source !== 'screen' && w.source !== 'relayed_by_ai'))
|
|
27
|
-
return `${where}
|
|
30
|
+
return `${where} must be { text, source: "screen" | "relayed_by_ai" }`;
|
|
28
31
|
const extra = extraKeys(w, ['text', 'source']);
|
|
29
|
-
return extra.length ? `${where}
|
|
32
|
+
return extra.length ? `${where} has unknown fields: ${extra.join(', ')}` : null;
|
|
30
33
|
}
|
|
31
34
|
function causeProblem(where, c) {
|
|
32
35
|
if (!isObject(c))
|
|
33
|
-
return `${where}
|
|
36
|
+
return `${where} must be an object`;
|
|
34
37
|
const extra = extraKeys(c, CAUSE_KEYS);
|
|
35
38
|
if (extra.length)
|
|
36
|
-
return `${where}
|
|
39
|
+
return `${where} has unknown fields: ${extra.join(', ')}. A sample must be a file exported with aic export-sample`;
|
|
37
40
|
if (c.humanWords !== undefined) {
|
|
38
41
|
if (!Array.isArray(c.humanWords))
|
|
39
|
-
return `${where}.humanWords
|
|
42
|
+
return `${where}.humanWords must be a list`;
|
|
40
43
|
for (const [i, w] of c.humanWords.entries()) {
|
|
41
44
|
const p = wordsProblem(`${where}.humanWords[${i}]`, w);
|
|
42
45
|
if (p)
|
|
@@ -49,95 +52,95 @@ function causeProblem(where, c) {
|
|
|
49
52
|
return p;
|
|
50
53
|
}
|
|
51
54
|
if (c.selection !== undefined && (!isObject(c.selection) || (c.selection.kind !== 'artifact' && c.selection.kind !== 'concept'))) {
|
|
52
|
-
return `${where}.selection
|
|
55
|
+
return `${where}.selection must be an object whose kind is artifact or concept`;
|
|
53
56
|
}
|
|
54
57
|
if (c.switch !== undefined && (!isObject(c.switch) || !isText(c.switch.from) || !isText(c.switch.to)))
|
|
55
|
-
return `${where}.switch
|
|
58
|
+
return `${where}.switch must be { from, to, mode }`;
|
|
56
59
|
return null;
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
59
62
|
* 예제 파일(aic-sample/1)의 검사. 문제의 설명이고 없으면 null 이다. 맨 위 층과 revision 과 원인에 모르는 칸이 있으면 거절한다.
|
|
60
63
|
* 예제는 실제 작업을 내보낸 것이어야 하고(037 7절 2번), 내보낼 때 지운 것(참여자 이름, 도구, 시각, 연결 정의)이 다시 들어가지
|
|
61
|
-
* 않게 하려는 것이다. 참여자는 "
|
|
64
|
+
* 않게 하려는 것이다. 참여자는 "Person", "AI", "Core" 로만 적는다(옛 파일의 "사람", "코어" 도 받는다).
|
|
62
65
|
*/
|
|
63
66
|
export function checkSample(value) {
|
|
64
67
|
if (!isObject(value))
|
|
65
|
-
return '
|
|
68
|
+
return 'The sample file must be a JSON object';
|
|
66
69
|
if (value.format !== SAMPLE_FORMAT)
|
|
67
|
-
return
|
|
70
|
+
return `The format of the sample file must be "${SAMPLE_FORMAT}". Use a file exported with aic export-sample`;
|
|
68
71
|
const extra = extraKeys(value, TOP_KEYS);
|
|
69
72
|
if (extra.length)
|
|
70
|
-
return
|
|
73
|
+
return `The sample file has unknown fields: ${extra.join(', ')}`;
|
|
71
74
|
if (!isText(value.title) || value.title.trim() === '' || charCount(value.title) > 200)
|
|
72
|
-
return '
|
|
75
|
+
return 'The title of the sample file must be non-empty text of up to 200 characters';
|
|
73
76
|
if (!Array.isArray(value.plugins) || value.plugins.length === 0 || value.plugins.length > 20)
|
|
74
|
-
return '
|
|
77
|
+
return 'The plugins of the sample file must be a list of 1 to 20 plugins';
|
|
75
78
|
const seen = new Set();
|
|
76
79
|
for (const [i, p] of value.plugins.entries()) {
|
|
77
80
|
if (!isObject(p) || !isPluginId(p.package) || !isVersion(p.version) || (p.title !== undefined && !isText(p.title)))
|
|
78
|
-
return
|
|
81
|
+
return `plugins[${i}] of the sample file must be { package, version, title? }, where package is a plugin id and version is semver`;
|
|
79
82
|
if (seen.has(p.package))
|
|
80
|
-
return
|
|
83
|
+
return `${p.package} appears twice in the plugins of the sample file`;
|
|
81
84
|
seen.add(p.package);
|
|
82
85
|
}
|
|
83
86
|
if (!Array.isArray(value.instances))
|
|
84
|
-
return '
|
|
87
|
+
return 'The instances of the sample file must be a list';
|
|
85
88
|
for (const [i, s] of value.instances.entries()) {
|
|
86
89
|
if (!isObject(s) || !isText(s.id) || !isText(s.package))
|
|
87
|
-
return
|
|
90
|
+
return `instances[${i}] of the sample file must be { id, package, title?, connection? }`;
|
|
88
91
|
const more = extraKeys(s, ['id', 'package', 'title', 'connection']);
|
|
89
92
|
if (more.length)
|
|
90
|
-
return
|
|
93
|
+
return `instances[${i}] of the sample file has unknown fields: ${more.join(', ')}`;
|
|
91
94
|
}
|
|
92
95
|
if (!Array.isArray(value.revisions) || value.revisions.length === 0)
|
|
93
|
-
return '
|
|
96
|
+
return 'The revisions of the sample file must be a list of one or more revisions';
|
|
94
97
|
for (const [i, r] of value.revisions.entries()) {
|
|
95
98
|
const where = `revisions[${i}]`;
|
|
96
99
|
if (!isObject(r))
|
|
97
|
-
return
|
|
100
|
+
return `${where} of the sample file must be an object`;
|
|
98
101
|
const more = extraKeys(r, REVISION_KEYS);
|
|
99
102
|
if (more.length)
|
|
100
|
-
return
|
|
103
|
+
return `${where} of the sample file has unknown fields: ${more.join(', ')}`;
|
|
101
104
|
if (!isText(r.revision) || !isText(r.kind) || !isText(r.summary))
|
|
102
|
-
return
|
|
105
|
+
return `${where} of the sample file must have revision, kind, and summary text`;
|
|
103
106
|
if (!isText(r.who) || !SAMPLE_WHO.test(r.who))
|
|
104
|
-
return
|
|
107
|
+
return `${where}.who of the sample file must be one of "Person", "AI", "Core", with a number such as "Person 2" when there are several of the same kind. Do not put real participant names`;
|
|
105
108
|
if (r.cause !== undefined) {
|
|
106
|
-
const p = causeProblem(
|
|
109
|
+
const p = causeProblem(`${where}.cause of the sample file`, r.cause);
|
|
107
110
|
if (p)
|
|
108
111
|
return p;
|
|
109
112
|
}
|
|
110
113
|
if (r.operations !== undefined && (!Array.isArray(r.operations) || r.operations.some((o) => !isObject(o) || !isText(o.op))))
|
|
111
|
-
return
|
|
114
|
+
return `${where}.operations of the sample file must be a list of { op, as?, input? }`;
|
|
112
115
|
if (!Array.isArray(r.changes) || r.changes.some((c) => !isObject(c) || !isText(c.record) || !isText(c.type)))
|
|
113
|
-
return
|
|
116
|
+
return `${where}.changes of the sample file must be a list of { record, type, owner, before, after }`;
|
|
114
117
|
}
|
|
115
118
|
if (value.generations !== undefined) {
|
|
116
119
|
if (!Array.isArray(value.generations))
|
|
117
|
-
return '
|
|
120
|
+
return 'The generations of the sample file must be a list';
|
|
118
121
|
const texts = (v) => Array.isArray(v) && v.every(isText);
|
|
119
122
|
for (const [i, g] of value.generations.entries()) {
|
|
120
|
-
const where =
|
|
123
|
+
const where = `generations[${i}] of the sample file`;
|
|
121
124
|
if (!isObject(g) || !isText(g.artifact) || !isText(g.who) || !isText(g.medium) || !isText(g.after) || !texts(g.sections))
|
|
122
|
-
return `${where}
|
|
125
|
+
return `${where} must be { artifact, who, medium, instance?, scope?, sections, missing?, after }`;
|
|
123
126
|
if (!SAMPLE_WHO.test(g.who))
|
|
124
|
-
return `${where}.who
|
|
127
|
+
return `${where}.who must be one of "Person", "AI", "Core", with a number when there are several of the same kind`;
|
|
125
128
|
if ((g.instance !== undefined && !isText(g.instance)) || (g.scope !== undefined && !texts(g.scope)) || (g.missing !== undefined && !texts(g.missing)))
|
|
126
|
-
return
|
|
129
|
+
return `instance, scope, or missing of ${where} has the wrong shape`;
|
|
127
130
|
const more = extraKeys(g, ['artifact', 'who', 'medium', 'instance', 'scope', 'sections', 'missing', 'after']);
|
|
128
131
|
if (more.length)
|
|
129
|
-
return `${where}
|
|
132
|
+
return `${where} has unknown fields: ${more.join(', ')}. Do not include artifact bodies or source text`;
|
|
130
133
|
}
|
|
131
134
|
}
|
|
132
135
|
if (value.transmissions !== undefined) {
|
|
133
136
|
if (!Array.isArray(value.transmissions))
|
|
134
|
-
return '
|
|
137
|
+
return 'The transmissions of the sample file must be a list';
|
|
135
138
|
for (const [i, t] of value.transmissions.entries()) {
|
|
136
139
|
if (!isObject(t) || !isText(t.instance) || (t.kind !== 'send' && t.kind !== 'update') || !isText(t.status))
|
|
137
|
-
return
|
|
140
|
+
return `transmissions[${i}] of the sample file must be { instance, kind, status, label? }`;
|
|
138
141
|
const more = extraKeys(t, ['instance', 'kind', 'status', 'label']);
|
|
139
142
|
if (more.length)
|
|
140
|
-
return
|
|
143
|
+
return `transmissions[${i}] of the sample file has unknown fields: ${more.join(', ')}. Run records hold only a summary`;
|
|
141
144
|
}
|
|
142
145
|
}
|
|
143
146
|
return null;
|
|
@@ -149,17 +152,17 @@ export function parseSample(data) {
|
|
|
149
152
|
text = typeof data === 'string' ? data : new TextDecoder('utf-8', { fatal: true }).decode(data);
|
|
150
153
|
}
|
|
151
154
|
catch {
|
|
152
|
-
return { ok: false, problem: '
|
|
155
|
+
return { ok: false, problem: 'The sample file is not UTF-8 text' };
|
|
153
156
|
}
|
|
154
157
|
const n = charCount(text);
|
|
155
158
|
if (n > SAMPLE_MAX_CHARS)
|
|
156
|
-
return { ok: false, problem:
|
|
159
|
+
return { ok: false, problem: `The sample file is over ${SAMPLE_MAX_CHARS.toLocaleString('en-US')} characters (${n.toLocaleString('en-US')} characters)` };
|
|
157
160
|
let value;
|
|
158
161
|
try {
|
|
159
162
|
value = JSON.parse(text.replace(/^/, ''));
|
|
160
163
|
}
|
|
161
164
|
catch (e) {
|
|
162
|
-
return { ok: false, problem:
|
|
165
|
+
return { ok: false, problem: `The sample file is not JSON (${e.message})` };
|
|
163
166
|
}
|
|
164
167
|
const problem = checkSample(value);
|
|
165
168
|
return problem ? { ok: false, problem } : { ok: true, sample: value };
|
|
@@ -171,12 +174,12 @@ export function parseManual(data) {
|
|
|
171
174
|
text = typeof data === 'string' ? data : new TextDecoder('utf-8', { fatal: true }).decode(data);
|
|
172
175
|
}
|
|
173
176
|
catch {
|
|
174
|
-
return { ok: false, problem: '
|
|
177
|
+
return { ok: false, problem: 'The manual is not UTF-8 text' };
|
|
175
178
|
}
|
|
176
179
|
text = text.replace(/^/, '');
|
|
177
180
|
const n = charCount(text);
|
|
178
181
|
if (n > MANUAL_MAX_CHARS)
|
|
179
|
-
return { ok: false, problem:
|
|
182
|
+
return { ok: false, problem: `The manual is over ${MANUAL_MAX_CHARS.toLocaleString('en-US')} characters (${n.toLocaleString('en-US')} characters)` };
|
|
180
183
|
return { ok: true, text };
|
|
181
184
|
}
|
|
182
185
|
/** 쓴 플러그인 하나의 글. 설치되지 않았거나 낮은 버전이면 괄호로 붙인다. */
|
|
@@ -186,8 +189,8 @@ function pluginWord(p, installed) {
|
|
|
186
189
|
return base;
|
|
187
190
|
const have = installed(p.package);
|
|
188
191
|
if (have === null)
|
|
189
|
-
return `${base}(
|
|
190
|
-
return have === p.version ? base : `${base}(
|
|
192
|
+
return `${base} (not installed)`;
|
|
193
|
+
return have === p.version ? base : `${base} (${have} on this computer)`;
|
|
191
194
|
}
|
|
192
195
|
/** 예제가 쓴 플러그인 가운데 이 컴퓨터에 설치되지 않은 것(037 5.2절). */
|
|
193
196
|
export function missingPlugins(sample, installed) {
|
|
@@ -195,11 +198,11 @@ export function missingPlugins(sample, installed) {
|
|
|
195
198
|
}
|
|
196
199
|
/** "쓰는 플러그인" 한 줄과, 설치되지 않은 것이 있으면 "이 예제는 X 도 씁니다(설치되지 않음)." 한 줄. */
|
|
197
200
|
export function samplePluginLines(sample, installed, self) {
|
|
198
|
-
const lines = [
|
|
201
|
+
const lines = [`Plugins used: ${sample.plugins.map((p) => pluginWord(p, installed)).join(', ')}`];
|
|
199
202
|
if (installed) {
|
|
200
203
|
const missing = missingPlugins(sample, installed).filter((p) => p !== self);
|
|
201
204
|
if (missing.length)
|
|
202
|
-
lines.push(
|
|
205
|
+
lines.push(`This sample also uses ${missing.join(', ')} (not installed).`);
|
|
203
206
|
}
|
|
204
207
|
return lines;
|
|
205
208
|
}
|
|
@@ -212,46 +215,52 @@ function clip(s, max) {
|
|
|
212
215
|
return all.length <= max ? s : `${all.slice(0, max).join('')} ...`;
|
|
213
216
|
}
|
|
214
217
|
const indentLines = (s, pad) => s.replace(/\r?\n/g, `\n${pad}`);
|
|
218
|
+
/** 파일의 참여자 표기("Person", "AI", "Core" 와 번호)를 읽기 글의 이름으로. 옛 파일의 "사람", "코어" 는 영어 이름으로 옮긴다. */
|
|
219
|
+
function whoWord(who) {
|
|
220
|
+
return who.replace(/^사람/, 'Person').replace(/^코어/, 'Core');
|
|
221
|
+
}
|
|
222
|
+
/** 그 표기가 사람인가. 옛 파일의 "사람" 도 사람이다. */
|
|
223
|
+
const isPersonWho = (who) => /^(Person|사람)/.test(who);
|
|
215
224
|
function changeWord(c) {
|
|
216
|
-
const action = c.before === null || c.before === undefined ? '
|
|
225
|
+
const action = c.before === null || c.before === undefined ? 'added' : c.after === null || c.after === undefined ? 'removed' : 'changed';
|
|
217
226
|
return `${c.record} ${c.type} ${action}`;
|
|
218
227
|
}
|
|
219
228
|
/** 사람의 말과 선택을 "사람: ..." 줄로. 말한 사람은 revision 을 만든 참여자가 아니라 사람이다. */
|
|
220
229
|
function causeLines(c, who) {
|
|
221
230
|
if (!c)
|
|
222
231
|
return [];
|
|
223
|
-
const person = who
|
|
232
|
+
const person = isPersonWho(who) ? whoWord(who) : 'Person';
|
|
224
233
|
const out = [];
|
|
225
234
|
for (const w of c.humanWords ?? [])
|
|
226
|
-
out.push(`${person}${w.source === 'relayed_by_ai' ? '(
|
|
235
|
+
out.push(`${person}${w.source === 'relayed_by_ai' ? ' (relayed by the AI)' : ''}: "${w.text}"`);
|
|
227
236
|
const s = c.selection;
|
|
228
237
|
if (s) {
|
|
229
238
|
const said = s.said ? `: "${s.said}"` : '';
|
|
230
239
|
if (s.kind === 'artifact')
|
|
231
|
-
out.push(`${person}:
|
|
240
|
+
out.push(`${person}: picked "${clip(s.text ?? '', 200)}" in artifact${s.artifact ? ` ${s.artifact}` : ''}${said}`);
|
|
232
241
|
else
|
|
233
|
-
out.push(`${person}:
|
|
242
|
+
out.push(`${person}: pointed at ${s.records?.length ? s.records.join(', ') : 'one place'} on screen${s.instance ? ` ${s.instance}` : ''}${s.role === 'reference' ? ' as a reference' : ''}${said}`);
|
|
234
243
|
}
|
|
235
244
|
if (c.choice)
|
|
236
|
-
out.push(`${person}(
|
|
245
|
+
out.push(`${person} (answer): "${c.choice.text}"`);
|
|
237
246
|
return out;
|
|
238
247
|
}
|
|
239
248
|
/** 생성 한 줄. 본문은 예제에 없으므로 범위와 구간 이름만 적는다. */
|
|
240
249
|
function generationLine(g, withBasis) {
|
|
241
|
-
const scope = g.scope?.length ?
|
|
242
|
-
const sections = g.sections.length ?
|
|
243
|
-
const missing = g.missing?.length ? `,
|
|
244
|
-
return `${g.who}: ${
|
|
250
|
+
const scope = g.scope?.length ? `scope ${g.scope.join(', ')}` : 'whole scope';
|
|
251
|
+
const sections = g.sections.length ? `sections ${clip(g.sections.join(', '), 300)}` : 'no sections';
|
|
252
|
+
const missing = g.missing?.length ? `, sections without a body ${g.missing.join(', ')}` : '';
|
|
253
|
+
return `${whoWord(g.who)}: made artifact ${g.artifact} (${g.medium}) ${withBasis ? `from the state up to ${g.after}` : 'from this state'} (${g.instance ? `screen ${g.instance}, ` : ''}${scope}, ${sections}${missing})`;
|
|
245
254
|
}
|
|
246
255
|
/**
|
|
247
256
|
* 예제를 읽기 좋은 글로 옮긴다(037 5.3절). revision 마다 "사람: (말)", "AI: (한 일의 요약)", "화면 변화" 를 차례로 적는다. 조작
|
|
248
257
|
* 원문과 변경의 내용은 넣지 않는다. 그것은 파일 자체(form: json)에 있다. installed 를 주면 설치되지 않은 플러그인을 알린다.
|
|
249
258
|
*/
|
|
250
259
|
export function sampleNarrative(sample, opts = {}) {
|
|
251
|
-
const lines = [
|
|
260
|
+
const lines = [`Sample work: ${sample.title}`, ...samplePluginLines(sample, opts.installed, opts.self)];
|
|
252
261
|
if (sample.instances.length) {
|
|
253
|
-
const screens = sample.instances.map((i) => `${i.id} ${i.title ?? i.package}(${i.connection !== undefined ?
|
|
254
|
-
lines.push(
|
|
262
|
+
const screens = sample.instances.map((i) => `${i.id} ${i.title ?? i.package}(${i.connection !== undefined ? `external connection ${i.connection}` : i.package})`);
|
|
263
|
+
lines.push(`Screens: ${screens.join(', ')}`);
|
|
255
264
|
}
|
|
256
265
|
lines.push('');
|
|
257
266
|
// 생성은 revision 이 아니므로 그 상태(after)의 revision 아래에 적는다. 그 revision 이 예제에 없으면 끝에 모은다.
|
|
@@ -262,10 +271,10 @@ export function sampleNarrative(sample, opts = {}) {
|
|
|
262
271
|
sample.revisions.forEach((r, i) => {
|
|
263
272
|
const head = `${i + 1}. (${r.revision}) `;
|
|
264
273
|
const pad = ' '.repeat(head.length);
|
|
265
|
-
const body = [...causeLines(r.cause, r.who), `${r.who}: ${indentLines(clip(r.summary, SUMMARY_SHOWN), pad)}`];
|
|
274
|
+
const body = [...causeLines(r.cause, r.who), `${whoWord(r.who)}: ${indentLines(clip(r.summary, SUMMARY_SHOWN), pad)}`];
|
|
266
275
|
if (r.changes.length) {
|
|
267
276
|
const shown = r.changes.slice(0, CHANGES_SHOWN).map(changeWord);
|
|
268
|
-
body.push(
|
|
277
|
+
body.push(`Screen changes: ${shown.join(', ')}${r.changes.length > shown.length ? ` and ${r.changes.length - shown.length} more` : ''}`);
|
|
269
278
|
}
|
|
270
279
|
for (const g of made.get(r.revision) ?? [])
|
|
271
280
|
body.push(generationLine(g, false));
|
|
@@ -273,14 +282,14 @@ export function sampleNarrative(sample, opts = {}) {
|
|
|
273
282
|
});
|
|
274
283
|
const loose = made.get('') ?? [];
|
|
275
284
|
if (loose.length) {
|
|
276
|
-
lines.push('', '
|
|
285
|
+
lines.push('', 'Artifacts made');
|
|
277
286
|
for (const g of loose)
|
|
278
287
|
lines.push(`- ${generationLine(g, true)}`);
|
|
279
288
|
}
|
|
280
289
|
if (sample.transmissions?.length) {
|
|
281
|
-
lines.push('', '
|
|
290
|
+
lines.push('', 'External connection runs (summary)');
|
|
282
291
|
for (const t of sample.transmissions)
|
|
283
|
-
lines.push(`- ${t.instance} ${t.kind === 'send' ? '
|
|
292
|
+
lines.push(`- ${t.instance} ${t.kind === 'send' ? 'send' : 'update'} ${t.status}${t.label ? `(${t.label})` : ''}`);
|
|
284
293
|
}
|
|
285
294
|
return lines.join('\n');
|
|
286
295
|
}
|
package/dist/state.js
CHANGED
|
@@ -12,22 +12,22 @@ export function isStateId(s) {
|
|
|
12
12
|
/** 상태 목록의 모양 검사. 문제의 설명이고 없으면 null 이다. 같은 id 가 둘이면 받지 않는다. 한 id 는 한 버전만 설치되기 때문이다. */
|
|
13
13
|
export function checkState(plugins) {
|
|
14
14
|
if (!Array.isArray(plugins))
|
|
15
|
-
return 'plugins
|
|
15
|
+
return 'plugins must be a list of { id, version, sha256 }';
|
|
16
16
|
if (plugins.length > STATE_MAX_PLUGINS)
|
|
17
|
-
return `plugins
|
|
17
|
+
return `plugins can have up to ${STATE_MAX_PLUGINS} entries (${plugins.length} given)`;
|
|
18
18
|
const seen = new Set();
|
|
19
19
|
for (const [i, e] of plugins.entries()) {
|
|
20
20
|
if (typeof e !== 'object' || e === null || Array.isArray(e))
|
|
21
|
-
return `plugins[${i}]
|
|
21
|
+
return `plugins[${i}] must be an object`;
|
|
22
22
|
const { id, version, sha256 } = e;
|
|
23
23
|
if (!isPluginId(id))
|
|
24
|
-
return `plugins[${i}].id
|
|
24
|
+
return `plugins[${i}].id is not shaped like a plugin id`;
|
|
25
25
|
if (!isVersion(version))
|
|
26
|
-
return `plugins[${i}].version
|
|
26
|
+
return `plugins[${i}].version is not semver`;
|
|
27
27
|
if (typeof sha256 !== 'string' || !SHA256.test(sha256))
|
|
28
|
-
return `plugins[${i}].sha256
|
|
28
|
+
return `plugins[${i}].sha256 must be 64 lowercase hexadecimal characters`;
|
|
29
29
|
if (seen.has(id))
|
|
30
|
-
return `plugins
|
|
30
|
+
return `plugins has the id ${id} twice`;
|
|
31
31
|
seen.add(id);
|
|
32
32
|
}
|
|
33
33
|
return null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aicommunicator-plugin-check",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "Checks the rules for the manifest and package file (.tgz) of AIC (aicommunicator) plugins. Shared by the AIC core, the aic command, and the plugin registry site",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": { "node": ">=22.13" },
|