aicommunicator-plugin-check 0.1.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.d.ts +7 -4
- package/dist/bundle.js +50 -35
- package/dist/icon.d.ts +10 -0
- package/dist/icon.js +61 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/manifest.d.ts +2 -0
- package/dist/manifest.js +41 -37
- 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.d.ts
CHANGED
|
@@ -31,11 +31,13 @@ export declare function bundlePathAllowed(p: string, manifest: Pick<Manifest, 'l
|
|
|
31
31
|
* 200,000자까지다. 예제는 aic-sample/1 모양이어야 하고 쓴 플러그인에 이 플러그인이 있어야 한다. 틀리면 까닭이고 없으면 null 이다.
|
|
32
32
|
*/
|
|
33
33
|
export declare function docsProblem(manifest: Pick<Manifest, 'id' | 'manual' | 'samples'>, files: ReadonlyMap<string, Uint8Array>): string | null;
|
|
34
|
+
/** 아이콘 파일의 검사(036 16절). manifest 가 가리키는 파일이 묶음에 있어야 하고 iconProblem 을 지나야 한다. 틀리면 까닭이고 없으면 null 이다. */
|
|
35
|
+
export declare function iconFileProblem(manifest: Pick<Manifest, 'icon'>, files: ReadonlyMap<string, Uint8Array>): string | null;
|
|
34
36
|
/**
|
|
35
|
-
* 묶음에 대한 알림. 거절하지 않고 알리기만 한다.
|
|
36
|
-
*
|
|
37
|
+
* 묶음에 대한 알림. 거절하지 않고 알리기만 한다. 설명서가 없을 때 한 줄(037 7절 3번: 등록 사이트는 설명서를 권하되 요구하지 않는다)과
|
|
38
|
+
* 대표 아이콘이 없을 때 한 줄(036 16절)이다.
|
|
37
39
|
*/
|
|
38
|
-
export declare function bundleNotices(manifest: Pick<Manifest, 'manual'>): string[];
|
|
40
|
+
export declare function bundleNotices(manifest: Pick<Manifest, 'manual' | 'icon'>): string[];
|
|
39
41
|
/**
|
|
40
42
|
* 파일 목록으로 `.tgz` 를 만든다. 경로의 글자 순서(UTF-16 코드 단위)로 늘어놓고 시각, 권한, 소유자를 고정하므로 같은 node 에서
|
|
41
43
|
* 같은 입력이면 같은 바이트가 나온다. 경로가 플러그인 폴더 안의 상대 경로가 아니면 던진다. manifest 의 검사는 하지 않는다.
|
|
@@ -43,7 +45,8 @@ export declare function bundleNotices(manifest: Pick<Manifest, 'manual'>): strin
|
|
|
43
45
|
export declare function packBundle(files: Map<string, Uint8Array | string> | Record<string, Uint8Array | string>): Buffer;
|
|
44
46
|
/**
|
|
45
47
|
* `.tgz` 를 풀어 036 3절의 규칙을 확인한다. 묶음 크기, 풀린 크기, 파일 수, 묶음 밖 경로, 보통 파일이 아닌 항목(링크 같은 것),
|
|
46
|
-
* 같은 경로 둘, 들어갈 수 없는 파일, manifest 검사, 논리 파일과 화면 파일이 있는지, 설명서와 예제 파일(docsProblem)
|
|
48
|
+
* 같은 경로 둘, 들어갈 수 없는 파일, manifest 검사, 논리 파일과 화면 파일이 있는지, 설명서와 예제 파일(docsProblem), 아이콘 파일
|
|
49
|
+
* (iconFileProblem)을 본다. 틀리면
|
|
47
50
|
* 까닭이 든 BundleError 를 던진다.
|
|
48
51
|
* 풀린 크기는 gzip 을 풀면서 한도로 막으므로 아주 크게 부풀리는 묶음도 메모리에 다 풀지 않는다.
|
|
49
52
|
*/
|
package/dist/bundle.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
4
|
import zlib from 'node:zlib';
|
|
5
5
|
import { checkForRegistry, checkManifest, isFileName, isPluginPath } from "./manifest.js";
|
|
6
|
+
import { iconProblem } from "./icon.js";
|
|
6
7
|
import { parseManual, parseSample } from "./sample.js";
|
|
7
8
|
/** 묶음 파일의 크기 한도와 풀린 파일 크기 합의 한도(036 12절 3번). */
|
|
8
9
|
export const BUNDLE_MAX_BYTES = 5 * 1024 * 1024;
|
|
@@ -43,7 +44,7 @@ export function docsProblem(manifest, files) {
|
|
|
43
44
|
if (manifest.manual !== undefined) {
|
|
44
45
|
const data = files.get(manifest.manual);
|
|
45
46
|
if (!data)
|
|
46
|
-
return
|
|
47
|
+
return `The manual file ${manifest.manual} is missing`;
|
|
47
48
|
const read = parseManual(data);
|
|
48
49
|
if (!read.ok)
|
|
49
50
|
return `${manifest.manual}: ${read.problem}`;
|
|
@@ -51,21 +52,34 @@ export function docsProblem(manifest, files) {
|
|
|
51
52
|
for (const s of manifest.samples ?? []) {
|
|
52
53
|
const data = files.get(s.file);
|
|
53
54
|
if (!data)
|
|
54
|
-
return
|
|
55
|
+
return `The file ${s.file} of sample ${s.id} is missing`;
|
|
55
56
|
const read = parseSample(data);
|
|
56
57
|
if (!read.ok)
|
|
57
|
-
return
|
|
58
|
+
return `Sample ${s.id} (${s.file}): ${read.problem}`;
|
|
58
59
|
if (!read.sample.plugins.some((p) => p.package === manifest.id))
|
|
59
|
-
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`;
|
|
60
61
|
}
|
|
61
62
|
return null;
|
|
62
63
|
}
|
|
64
|
+
/** 아이콘 파일의 검사(036 16절). manifest 가 가리키는 파일이 묶음에 있어야 하고 iconProblem 을 지나야 한다. 틀리면 까닭이고 없으면 null 이다. */
|
|
65
|
+
export function iconFileProblem(manifest, files) {
|
|
66
|
+
if (manifest.icon === undefined)
|
|
67
|
+
return null;
|
|
68
|
+
const data = files.get(manifest.icon);
|
|
69
|
+
if (!data)
|
|
70
|
+
return `The icon file ${manifest.icon} is missing`;
|
|
71
|
+
const problem = iconProblem(data);
|
|
72
|
+
return problem ? `${manifest.icon}: ${problem}` : null;
|
|
73
|
+
}
|
|
63
74
|
/**
|
|
64
|
-
* 묶음에 대한 알림. 거절하지 않고 알리기만 한다.
|
|
65
|
-
*
|
|
75
|
+
* 묶음에 대한 알림. 거절하지 않고 알리기만 한다. 설명서가 없을 때 한 줄(037 7절 3번: 등록 사이트는 설명서를 권하되 요구하지 않는다)과
|
|
76
|
+
* 대표 아이콘이 없을 때 한 줄(036 16절)이다.
|
|
66
77
|
*/
|
|
67
78
|
export function bundleNotices(manifest) {
|
|
68
|
-
return
|
|
79
|
+
return [
|
|
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
|
+
];
|
|
69
83
|
}
|
|
70
84
|
// ---- ustar ----
|
|
71
85
|
const BLOCK = 512;
|
|
@@ -77,7 +91,7 @@ function octal(value, width) {
|
|
|
77
91
|
function writeString(buf, offset, width, s) {
|
|
78
92
|
const bytes = Buffer.from(s, 'utf8');
|
|
79
93
|
if (bytes.length > width)
|
|
80
|
-
throw new BundleError('bad_bundle',
|
|
94
|
+
throw new BundleError('bad_bundle', `A name in the package is too long: ${s}`);
|
|
81
95
|
bytes.copy(buf, offset);
|
|
82
96
|
}
|
|
83
97
|
/** 이름이 100바이트를 넘으면 ustar 의 prefix(155바이트)로 나눈다. */
|
|
@@ -90,7 +104,7 @@ function splitName(p) {
|
|
|
90
104
|
if (Buffer.byteLength(prefix) <= 155 && Buffer.byteLength(name) <= 100)
|
|
91
105
|
return { name, prefix };
|
|
92
106
|
}
|
|
93
|
-
throw new BundleError('bad_bundle',
|
|
107
|
+
throw new BundleError('bad_bundle', `A path in the package is too long: ${p}`);
|
|
94
108
|
}
|
|
95
109
|
function header(p, size) {
|
|
96
110
|
const h = Buffer.alloc(BLOCK);
|
|
@@ -123,9 +137,9 @@ export function packBundle(files) {
|
|
|
123
137
|
const seen = new Set();
|
|
124
138
|
for (const [p, data] of entries) {
|
|
125
139
|
if (!isPluginPath(p))
|
|
126
|
-
throw new BundleError('bad_bundle',
|
|
140
|
+
throw new BundleError('bad_bundle', `This path cannot go into a package: ${JSON.stringify(p)}`);
|
|
127
141
|
if (seen.has(p))
|
|
128
|
-
throw new BundleError('bad_bundle',
|
|
142
|
+
throw new BundleError('bad_bundle', `The same path appears twice: ${p}`);
|
|
129
143
|
seen.add(p);
|
|
130
144
|
parts.push(header(p, data.length), data);
|
|
131
145
|
const pad = (BLOCK - (data.length % BLOCK)) % BLOCK;
|
|
@@ -147,12 +161,12 @@ function readString(buf, offset, width) {
|
|
|
147
161
|
}
|
|
148
162
|
function readOctal(buf, offset, width, what) {
|
|
149
163
|
if (buf[offset] & 0x80)
|
|
150
|
-
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)`);
|
|
151
165
|
const s = readString(buf, offset, width).trim();
|
|
152
166
|
if (s === '')
|
|
153
167
|
return 0;
|
|
154
168
|
if (!/^[0-7]+$/.test(s))
|
|
155
|
-
throw new BundleError('bad_bundle',
|
|
169
|
+
throw new BundleError('bad_bundle', `The ${what} of the package is not an octal number`);
|
|
156
170
|
return parseInt(s, 8);
|
|
157
171
|
}
|
|
158
172
|
/** pax 머리말의 "길이 key=value\n" 기록에서 path 를 꺼낸다. */
|
|
@@ -165,7 +179,7 @@ function paxPath(data) {
|
|
|
165
179
|
break;
|
|
166
180
|
const len = Number(data.subarray(i, space).toString('ascii'));
|
|
167
181
|
if (!Number.isInteger(len) || len <= 0 || i + len > data.length)
|
|
168
|
-
throw new BundleError('bad_bundle', '
|
|
182
|
+
throw new BundleError('bad_bundle', 'Could not read the pax header of the package');
|
|
169
183
|
const record = data.subarray(space + 1, i + len - 1).toString('utf8');
|
|
170
184
|
const eq = record.indexOf('=');
|
|
171
185
|
if (eq > 0 && record.slice(0, eq) === 'path')
|
|
@@ -184,19 +198,20 @@ function cleanPath(raw, dir) {
|
|
|
184
198
|
if (dir && (p === '' || p === '.'))
|
|
185
199
|
return '';
|
|
186
200
|
if (!isPluginPath(p))
|
|
187
|
-
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)}`);
|
|
188
202
|
return p;
|
|
189
203
|
}
|
|
190
204
|
/**
|
|
191
205
|
* `.tgz` 를 풀어 036 3절의 규칙을 확인한다. 묶음 크기, 풀린 크기, 파일 수, 묶음 밖 경로, 보통 파일이 아닌 항목(링크 같은 것),
|
|
192
|
-
* 같은 경로 둘, 들어갈 수 없는 파일, manifest 검사, 논리 파일과 화면 파일이 있는지, 설명서와 예제 파일(docsProblem)
|
|
206
|
+
* 같은 경로 둘, 들어갈 수 없는 파일, manifest 검사, 논리 파일과 화면 파일이 있는지, 설명서와 예제 파일(docsProblem), 아이콘 파일
|
|
207
|
+
* (iconFileProblem)을 본다. 틀리면
|
|
193
208
|
* 까닭이 든 BundleError 를 던진다.
|
|
194
209
|
* 풀린 크기는 gzip 을 풀면서 한도로 막으므로 아주 크게 부풀리는 묶음도 메모리에 다 풀지 않는다.
|
|
195
210
|
*/
|
|
196
211
|
export function readBundle(buffer) {
|
|
197
212
|
const buf = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
198
213
|
if (buf.length > BUNDLE_MAX_BYTES)
|
|
199
|
-
throw new BundleError('too_large',
|
|
214
|
+
throw new BundleError('too_large', `The package is over ${BUNDLE_MAX_BYTES} bytes (${buf.length} bytes)`);
|
|
200
215
|
// 파일 내용의 합은 BUNDLE_MAX_BYTES 까지이고, 머리말과 채움은 파일마다 1,024 바이트를 넘지 않는다
|
|
201
216
|
const maxTar = BUNDLE_MAX_BYTES + (BUNDLE_MAX_FILES + 8) * BLOCK * 2;
|
|
202
217
|
let tar;
|
|
@@ -205,9 +220,9 @@ export function readBundle(buffer) {
|
|
|
205
220
|
}
|
|
206
221
|
catch (e) {
|
|
207
222
|
if (e instanceof RangeError || e.code === 'ERR_BUFFER_TOO_LARGE') {
|
|
208
|
-
throw new BundleError('too_large',
|
|
223
|
+
throw new BundleError('too_large', `The unpacked package is over the limit (${BUNDLE_MAX_BYTES} bytes)`);
|
|
209
224
|
}
|
|
210
|
-
throw new BundleError('bad_bundle',
|
|
225
|
+
throw new BundleError('bad_bundle', `The package is not a gzip file (${e.message})`);
|
|
211
226
|
}
|
|
212
227
|
const files = new Map();
|
|
213
228
|
let total = 0;
|
|
@@ -223,14 +238,14 @@ export function readBundle(buffer) {
|
|
|
223
238
|
let sum = 0;
|
|
224
239
|
for (let i = 0; i < BLOCK; i += 1)
|
|
225
240
|
sum += i >= 148 && i < 156 ? 0x20 : h[i];
|
|
226
|
-
if (readOctal(h, 148, 8, '
|
|
227
|
-
throw new BundleError('bad_bundle', '
|
|
228
|
-
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');
|
|
229
244
|
const type = String.fromCharCode(h[156]);
|
|
230
245
|
const dataStart = offset + BLOCK;
|
|
231
246
|
const dataEnd = dataStart + size;
|
|
232
247
|
if (dataEnd > tar.length)
|
|
233
|
-
throw new BundleError('bad_bundle', '
|
|
248
|
+
throw new BundleError('bad_bundle', 'The package is cut off in the middle');
|
|
234
249
|
const data = tar.subarray(dataStart, dataEnd);
|
|
235
250
|
offset = dataStart + Math.ceil(size / BLOCK) * BLOCK;
|
|
236
251
|
if (type === 'x') {
|
|
@@ -251,42 +266,42 @@ export function readBundle(buffer) {
|
|
|
251
266
|
continue;
|
|
252
267
|
}
|
|
253
268
|
if (type !== '0' && type !== '\0')
|
|
254
|
-
throw new BundleError('bad_bundle',
|
|
269
|
+
throw new BundleError('bad_bundle', `The package has an entry that is not a regular file: ${rawName}`);
|
|
255
270
|
const p = cleanPath(rawName, false);
|
|
256
271
|
if (files.has(p))
|
|
257
|
-
throw new BundleError('bad_bundle',
|
|
272
|
+
throw new BundleError('bad_bundle', `The package has the same path twice: ${p}`);
|
|
258
273
|
if (files.size + 1 > BUNDLE_MAX_FILES)
|
|
259
|
-
throw new BundleError('too_large',
|
|
274
|
+
throw new BundleError('too_large', `The package has more than ${BUNDLE_MAX_FILES} files`);
|
|
260
275
|
total += size;
|
|
261
276
|
if (total > BUNDLE_MAX_BYTES)
|
|
262
|
-
throw new BundleError('too_large',
|
|
277
|
+
throw new BundleError('too_large', `The total file size in the package is over ${BUNDLE_MAX_BYTES} bytes`);
|
|
263
278
|
files.set(p, Buffer.from(data));
|
|
264
279
|
}
|
|
265
280
|
if (!ended)
|
|
266
|
-
throw new BundleError('bad_bundle', '
|
|
281
|
+
throw new BundleError('bad_bundle', 'The package has no end marker');
|
|
267
282
|
const manifestFile = files.get('manifest.json');
|
|
268
283
|
if (!manifestFile)
|
|
269
|
-
throw new BundleError('bad_bundle', '
|
|
284
|
+
throw new BundleError('bad_bundle', 'The package has no manifest.json');
|
|
270
285
|
let manifest;
|
|
271
286
|
try {
|
|
272
287
|
manifest = JSON.parse(manifestFile.toString('utf8'));
|
|
273
288
|
}
|
|
274
289
|
catch (e) {
|
|
275
|
-
throw new BundleError('bad_manifest', `manifest.json
|
|
290
|
+
throw new BundleError('bad_manifest', `manifest.json is not JSON (${e.message})`);
|
|
276
291
|
}
|
|
277
292
|
const problem = checkManifest(manifest);
|
|
278
293
|
if (problem)
|
|
279
294
|
throw new BundleError('bad_manifest', problem);
|
|
280
295
|
const m = manifest;
|
|
281
296
|
if (!files.has(m.logic))
|
|
282
|
-
throw new BundleError('bad_bundle',
|
|
297
|
+
throw new BundleError('bad_bundle', `The package has no logic file ${m.logic}`);
|
|
283
298
|
if (m.ui !== undefined && !files.has(m.ui))
|
|
284
|
-
throw new BundleError('bad_bundle',
|
|
299
|
+
throw new BundleError('bad_bundle', `The package has no screen file ${m.ui}`);
|
|
285
300
|
const extra = [...files.keys()].filter((p) => !bundlePathAllowed(p, m));
|
|
286
301
|
if (extra.length > 0) {
|
|
287
|
-
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`);
|
|
288
303
|
}
|
|
289
|
-
const docs = docsProblem(m, files);
|
|
304
|
+
const docs = docsProblem(m, files) ?? iconFileProblem(m, files);
|
|
290
305
|
if (docs)
|
|
291
306
|
throw new BundleError('bad_bundle', docs);
|
|
292
307
|
return { manifest: m, files, sha256: sha256Hex(buf), size: buf.length };
|
|
@@ -299,5 +314,5 @@ export function checkBundleForRegistry(bundle) {
|
|
|
299
314
|
const problem = checkForRegistry(bundle.manifest);
|
|
300
315
|
if (problem)
|
|
301
316
|
return { code: 'bad_manifest', message: problem };
|
|
302
|
-
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' };
|
|
303
318
|
}
|
package/dist/icon.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** 아이콘 파일의 크기 한도. 작은 그림 하나에 넉넉하고 목록에 여러 개를 올려도 가볍다. */
|
|
2
|
+
export declare const ICON_MAX_BYTES: number;
|
|
3
|
+
/** 아이콘 경로인가. ui/ 바로 아래의 .svg 파일이다. 코어가 `/plugin/<id>/ui/<파일>` 로 내보내는 곳과 같다. */
|
|
4
|
+
export declare function isIconPath(p: unknown): p is string;
|
|
5
|
+
/**
|
|
6
|
+
* 아이콘 파일의 검사. 문제의 설명이고 없으면 null 이다. UTF-8 글이고 `<svg` 로 시작하는 SVG 여야 한다. 스크립트, 다른 문서를 넣는 요소,
|
|
7
|
+
* 움직임(animate, set), 이벤트 속성, 바깥 주소(href, src, url() 은 문서 안의 #id 만), DOCTYPE 과 ENTITY, @import 는 받지 않는다. 그림으로만 보일 때는 돌지 않는
|
|
8
|
+
* 것들이지만, 아이콘을 다른 방식으로 보이는 화면이 생겨도 안전하게 하려는 것이다.
|
|
9
|
+
*/
|
|
10
|
+
export declare function iconProblem(data: Uint8Array): string | null;
|
package/dist/icon.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// 플러그인의 대표 아이콘(036 16절, rawdev 2026-11-25). manifest 의 icon 은 ui/ 바로 아래의 SVG 파일 하나다. 새 작업 화면과 등록
|
|
2
|
+
// 사이트가 플러그인을 고르는 곳에 보인다. 올린 사람이 만든 파일이므로 그림으로만(img) 보이고, 그 전제에서도 스크립트, 바깥 주소,
|
|
3
|
+
// 다른 문서를 끌어오는 것은 파일에 들어 있지 못하게 검사한다. 코어, aic 명령, 등록 사이트가 같은 검사를 쓴다.
|
|
4
|
+
import { isUiPath } from "./manifest.js";
|
|
5
|
+
/** 아이콘 파일의 크기 한도. 작은 그림 하나에 넉넉하고 목록에 여러 개를 올려도 가볍다. */
|
|
6
|
+
export const ICON_MAX_BYTES = 32 * 1024;
|
|
7
|
+
/** 아이콘 경로인가. ui/ 바로 아래의 .svg 파일이다. 코어가 `/plugin/<id>/ui/<파일>` 로 내보내는 곳과 같다. */
|
|
8
|
+
export function isIconPath(p) {
|
|
9
|
+
return isUiPath(p) && p.toLowerCase().endsWith('.svg');
|
|
10
|
+
}
|
|
11
|
+
/** 주소를 받는 속성의 값이 문서 안의 것(#id)인가. */
|
|
12
|
+
function insideOnly(text, pattern) {
|
|
13
|
+
for (const m of text.matchAll(pattern)) {
|
|
14
|
+
const value = (m[2] ?? m[3] ?? '').trim();
|
|
15
|
+
if (!value.startsWith('#'))
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 아이콘 파일의 검사. 문제의 설명이고 없으면 null 이다. UTF-8 글이고 `<svg` 로 시작하는 SVG 여야 한다. 스크립트, 다른 문서를 넣는 요소,
|
|
22
|
+
* 움직임(animate, set), 이벤트 속성, 바깥 주소(href, src, url() 은 문서 안의 #id 만), DOCTYPE 과 ENTITY, @import 는 받지 않는다. 그림으로만 보일 때는 돌지 않는
|
|
23
|
+
* 것들이지만, 아이콘을 다른 방식으로 보이는 화면이 생겨도 안전하게 하려는 것이다.
|
|
24
|
+
*/
|
|
25
|
+
export function iconProblem(data) {
|
|
26
|
+
if (data.length === 0)
|
|
27
|
+
return 'The icon file is empty';
|
|
28
|
+
if (data.length > ICON_MAX_BYTES)
|
|
29
|
+
return `The icon file is over ${ICON_MAX_BYTES.toLocaleString('en-US')} bytes (${data.length.toLocaleString('en-US')} bytes)`;
|
|
30
|
+
let text;
|
|
31
|
+
try {
|
|
32
|
+
text = new TextDecoder('utf-8', { fatal: true }).decode(data);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return 'The icon file is not UTF-8 text';
|
|
36
|
+
}
|
|
37
|
+
if (/<!DOCTYPE|<!ENTITY/i.test(text))
|
|
38
|
+
return 'The icon must not contain DOCTYPE or ENTITY';
|
|
39
|
+
const body = text
|
|
40
|
+
.replace(new RegExp('^' + String.fromCharCode(0xfeff)), '')
|
|
41
|
+
.replace(/^\s*<\?xml[^>]*\?>/, '')
|
|
42
|
+
.replace(/<!--[\s\S]*?-->/g, '');
|
|
43
|
+
if (!/^\s*<svg[\s>]/i.test(body))
|
|
44
|
+
return 'The icon file is not an SVG that starts with <svg';
|
|
45
|
+
if (!/<\/svg>\s*$/i.test(body))
|
|
46
|
+
return 'The icon file does not end with </svg>';
|
|
47
|
+
const banned = /<\s*(script|foreignObject|iframe|object|embed|audio|video|link|meta|style|animate|animateTransform|animateMotion|set)\b/i.exec(body);
|
|
48
|
+
if (banned)
|
|
49
|
+
return `The icon must not contain a ${banned[1]} element`;
|
|
50
|
+
if (/[\s"'/]on[a-z]+\s*=/i.test(body))
|
|
51
|
+
return 'The icon must not contain event attributes (on...)';
|
|
52
|
+
if (/javascript\s*:|@import/i.test(body))
|
|
53
|
+
return 'The icon must not contain javascript: addresses or @import';
|
|
54
|
+
if (!insideOnly(body, /\b(xlink:href|href|src)\s*=\s*(?:"([^"]*)"|'([^']*)')/gi))
|
|
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
|
+
for (const m of body.matchAll(/url\(\s*(["']?)([^)"']*)\1\s*\)/gi)) {
|
|
57
|
+
if (!m[2].trim().startsWith('#'))
|
|
58
|
+
return 'url() in the icon may only point to a #id inside the document';
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/manifest.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ export interface Manifest {
|
|
|
20
20
|
manual?: string;
|
|
21
21
|
/** 사용 예제(037 5.1절). 다섯 개까지. file 은 패키지 안의 aic-sample/1 파일이다. */
|
|
22
22
|
samples?: PluginSample[];
|
|
23
|
+
/** 대표 아이콘(036 16절). ui/ 바로 아래의 SVG 파일 경로. 예: ui/icon.svg. 없어도 된다. 파일의 검사는 icon.ts 의 iconProblem 이다. */
|
|
24
|
+
icon?: string;
|
|
23
25
|
}
|
|
24
26
|
/** manifest 의 samples 항목(037 5.1절). */
|
|
25
27
|
export interface PluginSample {
|