aicommunicator-plugin-check 0.2.0 → 0.2.2

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 CHANGED
@@ -1,10 +1,10 @@
1
1
  # aicommunicator-plugin-check
2
2
 
3
- AIC(aicommunicator) 플러그인의 manifest 와 묶음 파일(`.tgz`)의 규칙을 확인하는 코드입니다. AIC 코어, `aic` 명령, 플러그인 등록 사이트가 이 패키지 하나를 함께 써서, 셋이 같은 플러그인을 같은 규칙으로 받아들이거나 거절합니다.
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
- - 다른 패키지에 기대지 않고 Node 내장 모듈(`node:crypto`, `node:zlib`)만 씁니다. Node 22.13 이상에서 돕니다.
6
- - 플러그인 코드를 실행하지 않습니다. manifest 의 글, 묶음 안의 파일 이름과 크기, 설명서와 예제 파일의 글만 봅니다.
7
- - 설계는 aicommunicator 저장소의 `doc/036_plugin_registry_design.md` 에 있고, 설명서와 예제는 `doc/037_plugin_manual_design.md` 에 있습니다.
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 의 Buffer
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` | 코어의 플러그인 계약 버전. 지금 `"0.1"` |
30
- | `checkManifest(manifest)` | 코어가 쓰는 manifest 검사. 틀리면 까닭의 글, 맞으면 `null` |
31
- | `checkForRegistry(manifest)` | `checkManifest` 에 더해 사이트에 올릴 때 필요한 칸(`protocol`, `license`, `title`, `about`)을 본다 |
32
- | `checkBundleForRegistry(bundle)` | `checkForRegistry` 와 `LICENSE` 파일을 본다. 문제가 있으면 `{ code, message }`(code 는 `bad_manifest` 나 `bad_bundle`), 없으면 `null` |
33
- | `readBundle(buffer)` | `.tgz` 를 풀어 규칙(들어갈 수 있는 파일, 5MB, 200개, 묶음 밖 경로, 링크, 설명서와 예제)을 확인하고 `{ manifest, files, sha256, size }` 를 돌려준다. 틀리면 `BundleError` 를 던진다 |
34
- | `BundleError` | `code` 가 `too_large`, `bad_bundle`, `bad_manifest` 가운데 하나다 |
35
- | `packBundle(files)` | 파일 목록으로 `.tgz` 를 만든다. 같은 입력이면 같은 바이트가 나온다 |
36
- | `compareVersions(a, b)` | semver 순서. -1, 0, 1 |
37
- | `satisfies(version, range)` | `1.2.3`, `^1.2.3`, `~1.2.3`, `>=1.2.3` 네 가지 범위. 뜻은 npm 과 같다 |
38
- | `protocolAccepts(range, core?)` | manifest 의 `protocol` 이 코어의 계약 버전을 받는지 |
39
- | `stateId(plugins)`, `canonicalState(plugins)`, `checkState(plugins)` | 플러그인 구성의 상태 id 계산과 목록의 모양 검사 |
40
- | `isPluginId`, `idOwner`, `isVersion`, `isPrerelease`, `isRange`, `isProtocolRange`, `isStateId` | 모양 확인 |
41
- | `bundleFileName`, `bundlePathAllowed`, `sha256Hex` | 묶음 파일 이름, 묶음에 들어갈 수 있는 경로인지, sha256 |
42
- | `BUNDLE_MAX_BYTES`, `BUNDLE_MAX_FILES`, `MAX_DEPENDENCIES`, `STATE_MAX_PLUGINS`, `RESERVED_IDS` | 한도와 쓰지 못하는 id |
43
- | `checkMessageTable(data)` | 외부 연결의 메시지 표(`aic-link-messages/1`) 파일의 바이트를 검사한다. 맞으면 `{ ok: true, table }`, 틀리면 `{ ok: false, problems }` |
44
- | `renderMessage(table, id, values)` | 표에 등록한 메시지 id 와 값을 글로 푼다. 등록하지 않은 id, 값이 틀린 것, 모양이 틀린 id 는 글을 만들지 않고 까닭(`unknown_id`, `bad_values`, `malformed_id`)을 돌려준다 |
45
- | `isMessageId`, `MESSAGE_TABLE_FORMAT`, `MESSAGE_TABLE_MAX_BYTES`, `MESSAGE_TABLE_MAX_MESSAGES`, `MESSAGE_TEXT_MAX` | 메시지 표의 모양 확인과 한도 |
46
- | `docsProblem(manifest, files)` | manifest 의 `manual`(설명서)과 `samples`(예제)가 가리키는 파일이 있는지, 한도와 모양이 맞는지 본다. `readBundle` 이 함께 부른다 |
47
- | `bundleNotices(manifest)` | 거절하지 않고 알리기만 하는 것. 지금은 설명서가 없을 때 한 줄이다 |
48
- | `checkSample(value)`, `parseSample(data)`, `parseManual(data)` | 예제 파일(`aic-sample/1`)의 모양 검사, 예제와 설명서 파일의 글자 한도와 UTF-8 검사 |
49
- | `sampleNarrative(sample, { installed?, self? })`, `samplePluginLines`, `missingPlugins` | 예제를 revision 마다 사람의 말, AI 가 한 일, 화면 변화의 차례 글로 옮기고, 설치되지 않은 플러그인을 알린다 |
50
- | `SAMPLE_FORMAT`, `MANUAL_MAX_CHARS`, `SAMPLE_MAX_CHARS`, `MAX_SAMPLES`, `SAMPLE_WHO` | 예제 형식의 이름, 설명서 50,000자, 예제 하나 200,000자, 예제 다섯 개, 참여자 표기("사람", "AI", "코어") |
51
-
52
- ## 버전
53
-
54
- 검사 규칙을 바꾸면 이 패키지의 버전을 올리고, 등록 사이트가 그 버전을 따라 올립니다. 0 으로 시작하는 동안은 가운데 숫자가 바뀌면 규칙이 호환되지 않게 바뀐 것입니다.
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
@@ -21,11 +21,18 @@ export declare class BundleError extends Error {
21
21
  /** 묶음 파일의 이름. 예: rawdev.novel-0.3.0.tgz */
22
22
  export declare function bundleFileName(id: string, version: string): string;
23
23
  export declare function sha256Hex(data: Uint8Array | string): string;
24
+ /** manifest 의 requires.external[].connect.messages 가 가리키는 메시지 표 파일들(032 44.2절). */
25
+ export declare function connectMessageFiles(manifest: Pick<Manifest, 'requires'>): string[];
24
26
  /**
25
27
  * 이 경로의 파일이 묶음에 들어갈 수 있는가(036 3절). manifest, 논리 파일, ui/ 의 파일, LICENSE, README.md, 그리고 manifest 가 가리키는
26
- * 설명서와 예제 파일(037 5.1절)뿐이다.
28
+ * 설명서와 예제 파일(037 5.1절), 외부 연결의 메시지 표(032 44.2절)뿐이다.
27
29
  */
28
- export declare function bundlePathAllowed(p: string, manifest: Pick<Manifest, 'logic' | 'manual' | 'samples'>): boolean;
30
+ export declare function bundlePathAllowed(p: string, manifest: Pick<Manifest, 'logic' | 'manual' | 'samples' | 'requires'>): boolean;
31
+ /**
32
+ * 외부 연결의 메시지 표 파일 검사(032 44.2절). connect.messages 가 가리키는 파일이 묶음에 있어야 하고 메시지 표의 검사(032 31.3절)를 지나야
33
+ * 한다. 코어도 연결을 쓴 뒤 읽을 때 다시 검사한다. 틀리면 까닭이고 없으면 null 이다.
34
+ */
35
+ export declare function connectFilesProblem(manifest: Pick<Manifest, 'requires'>, files: ReadonlyMap<string, Uint8Array>): string | null;
29
36
  /**
30
37
  * 설명서와 예제 파일의 검사(037 5절, 7절 4번). manifest 가 가리키는 파일이 묶음에 있어야 하고, 설명서는 50,000자, 예제는 하나에
31
38
  * 200,000자까지다. 예제는 aic-sample/1 모양이어야 하고 쓴 플러그인에 이 플러그인이 있어야 한다. 틀리면 까닭이고 없으면 null 이다.
@@ -46,7 +53,7 @@ export declare function packBundle(files: Map<string, Uint8Array | string> | Rec
46
53
  /**
47
54
  * `.tgz` 를 풀어 036 3절의 규칙을 확인한다. 묶음 크기, 풀린 크기, 파일 수, 묶음 밖 경로, 보통 파일이 아닌 항목(링크 같은 것),
48
55
  * 같은 경로 둘, 들어갈 수 없는 파일, manifest 검사, 논리 파일과 화면 파일이 있는지, 설명서와 예제 파일(docsProblem), 아이콘 파일
49
- * (iconFileProblem)을 본다. 틀리면
56
+ * (iconFileProblem), 외부 연결의 메시지 표(connectFilesProblem)를 본다. 틀리면
50
57
  * 까닭이 든 BundleError 를 던진다.
51
58
  * 풀린 크기는 gzip 을 풀면서 한도로 막으므로 아주 크게 부풀리는 묶음도 메모리에 다 풀지 않는다.
52
59
  */
package/dist/bundle.js CHANGED
@@ -4,6 +4,7 @@ import { createHash } from 'node:crypto';
4
4
  import zlib from 'node:zlib';
5
5
  import { checkForRegistry, checkManifest, isFileName, isPluginPath } from "./manifest.js";
6
6
  import { iconProblem } from "./icon.js";
7
+ import { checkMessageTable } from "./messages.js";
7
8
  import { parseManual, parseSample } from "./sample.js";
8
9
  /** 묶음 파일의 크기 한도와 풀린 파일 크기 합의 한도(036 12절 3번). */
9
10
  export const BUNDLE_MAX_BYTES = 5 * 1024 * 1024;
@@ -25,17 +26,38 @@ export function bundleFileName(id, version) {
25
26
  export function sha256Hex(data) {
26
27
  return createHash('sha256').update(data).digest('hex');
27
28
  }
29
+ /** manifest 의 requires.external[].connect.messages 가 가리키는 메시지 표 파일들(032 44.2절). */
30
+ export function connectMessageFiles(manifest) {
31
+ return (manifest.requires?.external ?? []).map((t) => t.connect?.messages).filter((p) => typeof p === 'string');
32
+ }
28
33
  /**
29
34
  * 이 경로의 파일이 묶음에 들어갈 수 있는가(036 3절). manifest, 논리 파일, ui/ 의 파일, LICENSE, README.md, 그리고 manifest 가 가리키는
30
- * 설명서와 예제 파일(037 5.1절)뿐이다.
35
+ * 설명서와 예제 파일(037 5.1절), 외부 연결의 메시지 표(032 44.2절)뿐이다.
31
36
  */
32
37
  export function bundlePathAllowed(p, manifest) {
33
38
  if (p === 'manifest.json' || p === 'LICENSE' || p === 'README.md' || p === manifest.logic)
34
39
  return true;
35
40
  if (p === manifest.manual || (manifest.samples ?? []).some((s) => s.file === p))
36
41
  return true;
42
+ if (connectMessageFiles(manifest).includes(p))
43
+ return true;
37
44
  return p.startsWith('ui/') && isFileName(p.slice(3));
38
45
  }
46
+ /**
47
+ * 외부 연결의 메시지 표 파일 검사(032 44.2절). connect.messages 가 가리키는 파일이 묶음에 있어야 하고 메시지 표의 검사(032 31.3절)를 지나야
48
+ * 한다. 코어도 연결을 쓴 뒤 읽을 때 다시 검사한다. 틀리면 까닭이고 없으면 null 이다.
49
+ */
50
+ export function connectFilesProblem(manifest, files) {
51
+ for (const p of connectMessageFiles(manifest)) {
52
+ const data = files.get(p);
53
+ if (!data)
54
+ return `The message table file ${p} is missing`;
55
+ const checked = checkMessageTable(data);
56
+ if (!checked.ok)
57
+ return `${p}: ${checked.problems.join('. ')}`;
58
+ }
59
+ return null;
60
+ }
39
61
  /**
40
62
  * 설명서와 예제 파일의 검사(037 5절, 7절 4번). manifest 가 가리키는 파일이 묶음에 있어야 하고, 설명서는 50,000자, 예제는 하나에
41
63
  * 200,000자까지다. 예제는 aic-sample/1 모양이어야 하고 쓴 플러그인에 이 플러그인이 있어야 한다. 틀리면 까닭이고 없으면 null 이다.
@@ -44,7 +66,7 @@ export function docsProblem(manifest, files) {
44
66
  if (manifest.manual !== undefined) {
45
67
  const data = files.get(manifest.manual);
46
68
  if (!data)
47
- return `설명서 파일 ${manifest.manual} 이 없다`;
69
+ return `The manual file ${manifest.manual} is missing`;
48
70
  const read = parseManual(data);
49
71
  if (!read.ok)
50
72
  return `${manifest.manual}: ${read.problem}`;
@@ -52,12 +74,12 @@ export function docsProblem(manifest, files) {
52
74
  for (const s of manifest.samples ?? []) {
53
75
  const data = files.get(s.file);
54
76
  if (!data)
55
- return `예제 ${s.id} 의 파일 ${s.file} 이 없다`;
77
+ return `The file ${s.file} of sample ${s.id} is missing`;
56
78
  const read = parseSample(data);
57
79
  if (!read.ok)
58
- return `예제 ${s.id}(${s.file}): ${read.problem}`;
80
+ return `Sample ${s.id} (${s.file}): ${read.problem}`;
59
81
  if (!read.sample.plugins.some((p) => p.package === manifest.id))
60
- return `예제 ${s.id}(${s.file}) 의 plugins 에 이 플러그인 ${manifest.id} 이 없다. 이 플러그인을 쓴 작업을 내보낸다`;
82
+ return `The plugins of sample ${s.id} (${s.file}) do not include this plugin ${manifest.id}. Export a work that uses this plugin`;
61
83
  }
62
84
  return null;
63
85
  }
@@ -67,7 +89,7 @@ export function iconFileProblem(manifest, files) {
67
89
  return null;
68
90
  const data = files.get(manifest.icon);
69
91
  if (!data)
70
- return `아이콘 파일 ${manifest.icon} 이 없다`;
92
+ return `The icon file ${manifest.icon} is missing`;
71
93
  const problem = iconProblem(data);
72
94
  return problem ? `${manifest.icon}: ${problem}` : null;
73
95
  }
@@ -77,8 +99,8 @@ export function iconFileProblem(manifest, files) {
77
99
  */
78
100
  export function bundleNotices(manifest) {
79
101
  return [
80
- ...(manifest.manual === undefined ? ['설명서(manifest 의 manual)가 없다. 등록 사이트는 설명서를 권한다. 없어도 올라간다'] : []),
81
- ...(manifest.icon === undefined ? ['대표 아이콘(manifest 의 icon)이 없다. 플러그인을 고르는 화면은 이름의 첫 글자를 보인다. 없어도 올라간다'] : []),
102
+ ...(manifest.manual === undefined ? ['There is no manual (manual in the manifest). The registry site recommends a manual. The plugin can be uploaded without one'] : []),
103
+ ...(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
104
  ];
83
105
  }
84
106
  // ---- ustar ----
@@ -91,7 +113,7 @@ function octal(value, width) {
91
113
  function writeString(buf, offset, width, s) {
92
114
  const bytes = Buffer.from(s, 'utf8');
93
115
  if (bytes.length > width)
94
- throw new BundleError('bad_bundle', `묶음 안의 이름이 너무 길다: ${s}`);
116
+ throw new BundleError('bad_bundle', `A name in the package is too long: ${s}`);
95
117
  bytes.copy(buf, offset);
96
118
  }
97
119
  /** 이름이 100바이트를 넘으면 ustar 의 prefix(155바이트)로 나눈다. */
@@ -104,7 +126,7 @@ function splitName(p) {
104
126
  if (Buffer.byteLength(prefix) <= 155 && Buffer.byteLength(name) <= 100)
105
127
  return { name, prefix };
106
128
  }
107
- throw new BundleError('bad_bundle', `묶음 안의 경로가 너무 길다: ${p}`);
129
+ throw new BundleError('bad_bundle', `A path in the package is too long: ${p}`);
108
130
  }
109
131
  function header(p, size) {
110
132
  const h = Buffer.alloc(BLOCK);
@@ -137,9 +159,9 @@ export function packBundle(files) {
137
159
  const seen = new Set();
138
160
  for (const [p, data] of entries) {
139
161
  if (!isPluginPath(p))
140
- throw new BundleError('bad_bundle', `묶음에 넣을 수 없는 경로다: ${JSON.stringify(p)}`);
162
+ throw new BundleError('bad_bundle', `This path cannot go into a package: ${JSON.stringify(p)}`);
141
163
  if (seen.has(p))
142
- throw new BundleError('bad_bundle', `같은 경로가 둘이다: ${p}`);
164
+ throw new BundleError('bad_bundle', `The same path appears twice: ${p}`);
143
165
  seen.add(p);
144
166
  parts.push(header(p, data.length), data);
145
167
  const pad = (BLOCK - (data.length % BLOCK)) % BLOCK;
@@ -161,12 +183,12 @@ function readString(buf, offset, width) {
161
183
  }
162
184
  function readOctal(buf, offset, width, what) {
163
185
  if (buf[offset] & 0x80)
164
- throw new BundleError('bad_bundle', `묶음의 ${what} 를 읽지 못했다(256진 표기는 받지 않는다)`);
186
+ throw new BundleError('bad_bundle', `Could not read the ${what} of the package (base-256 notation is not accepted)`);
165
187
  const s = readString(buf, offset, width).trim();
166
188
  if (s === '')
167
189
  return 0;
168
190
  if (!/^[0-7]+$/.test(s))
169
- throw new BundleError('bad_bundle', `묶음의 ${what} 가 8진 숫자가 아니다`);
191
+ throw new BundleError('bad_bundle', `The ${what} of the package is not an octal number`);
170
192
  return parseInt(s, 8);
171
193
  }
172
194
  /** pax 머리말의 "길이 key=value\n" 기록에서 path 를 꺼낸다. */
@@ -179,7 +201,7 @@ function paxPath(data) {
179
201
  break;
180
202
  const len = Number(data.subarray(i, space).toString('ascii'));
181
203
  if (!Number.isInteger(len) || len <= 0 || i + len > data.length)
182
- throw new BundleError('bad_bundle', '묶음의 pax 머리말을 읽지 못했다');
204
+ throw new BundleError('bad_bundle', 'Could not read the pax header of the package');
183
205
  const record = data.subarray(space + 1, i + len - 1).toString('utf8');
184
206
  const eq = record.indexOf('=');
185
207
  if (eq > 0 && record.slice(0, eq) === 'path')
@@ -198,20 +220,20 @@ function cleanPath(raw, dir) {
198
220
  if (dir && (p === '' || p === '.'))
199
221
  return '';
200
222
  if (!isPluginPath(p))
201
- throw new BundleError('bad_bundle', `묶음 안의 경로가 플러그인 폴더 안의 상대 경로가 아니다: ${JSON.stringify(raw)}`);
223
+ throw new BundleError('bad_bundle', `A path in the package is not a relative path inside the plugin folder: ${JSON.stringify(raw)}`);
202
224
  return p;
203
225
  }
204
226
  /**
205
227
  * `.tgz` 를 풀어 036 3절의 규칙을 확인한다. 묶음 크기, 풀린 크기, 파일 수, 묶음 밖 경로, 보통 파일이 아닌 항목(링크 같은 것),
206
228
  * 같은 경로 둘, 들어갈 수 없는 파일, manifest 검사, 논리 파일과 화면 파일이 있는지, 설명서와 예제 파일(docsProblem), 아이콘 파일
207
- * (iconFileProblem)을 본다. 틀리면
229
+ * (iconFileProblem), 외부 연결의 메시지 표(connectFilesProblem)를 본다. 틀리면
208
230
  * 까닭이 든 BundleError 를 던진다.
209
231
  * 풀린 크기는 gzip 을 풀면서 한도로 막으므로 아주 크게 부풀리는 묶음도 메모리에 다 풀지 않는다.
210
232
  */
211
233
  export function readBundle(buffer) {
212
234
  const buf = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
213
235
  if (buf.length > BUNDLE_MAX_BYTES)
214
- throw new BundleError('too_large', `묶음이 ${BUNDLE_MAX_BYTES} 바이트를 넘는다(${buf.length} 바이트)`);
236
+ throw new BundleError('too_large', `The package is over ${BUNDLE_MAX_BYTES} bytes (${buf.length} bytes)`);
215
237
  // 파일 내용의 합은 BUNDLE_MAX_BYTES 까지이고, 머리말과 채움은 파일마다 1,024 바이트를 넘지 않는다
216
238
  const maxTar = BUNDLE_MAX_BYTES + (BUNDLE_MAX_FILES + 8) * BLOCK * 2;
217
239
  let tar;
@@ -220,9 +242,9 @@ export function readBundle(buffer) {
220
242
  }
221
243
  catch (e) {
222
244
  if (e instanceof RangeError || e.code === 'ERR_BUFFER_TOO_LARGE') {
223
- throw new BundleError('too_large', `풀린 묶음이 한도(${BUNDLE_MAX_BYTES} 바이트)를 넘는다`);
245
+ throw new BundleError('too_large', `The unpacked package is over the limit (${BUNDLE_MAX_BYTES} bytes)`);
224
246
  }
225
- throw new BundleError('bad_bundle', `묶음이 gzip 파일이 아니다(${e.message})`);
247
+ throw new BundleError('bad_bundle', `The package is not a gzip file (${e.message})`);
226
248
  }
227
249
  const files = new Map();
228
250
  let total = 0;
@@ -238,14 +260,14 @@ export function readBundle(buffer) {
238
260
  let sum = 0;
239
261
  for (let i = 0; i < BLOCK; i += 1)
240
262
  sum += i >= 148 && i < 156 ? 0x20 : h[i];
241
- if (readOctal(h, 148, 8, '검사합') !== sum)
242
- throw new BundleError('bad_bundle', '묶음의 머리말 검사합이 맞지 않는다');
243
- const size = readOctal(h, 124, 12, '파일 크기');
263
+ if (readOctal(h, 148, 8, 'checksum') !== sum)
264
+ throw new BundleError('bad_bundle', 'The header checksum of the package does not match');
265
+ const size = readOctal(h, 124, 12, 'file size');
244
266
  const type = String.fromCharCode(h[156]);
245
267
  const dataStart = offset + BLOCK;
246
268
  const dataEnd = dataStart + size;
247
269
  if (dataEnd > tar.length)
248
- throw new BundleError('bad_bundle', '묶음이 중간에 끊겼다');
270
+ throw new BundleError('bad_bundle', 'The package is cut off in the middle');
249
271
  const data = tar.subarray(dataStart, dataEnd);
250
272
  offset = dataStart + Math.ceil(size / BLOCK) * BLOCK;
251
273
  if (type === 'x') {
@@ -266,42 +288,42 @@ export function readBundle(buffer) {
266
288
  continue;
267
289
  }
268
290
  if (type !== '0' && type !== '\0')
269
- throw new BundleError('bad_bundle', `묶음에 보통 파일이 아닌 항목이 있다: ${rawName}`);
291
+ throw new BundleError('bad_bundle', `The package has an entry that is not a regular file: ${rawName}`);
270
292
  const p = cleanPath(rawName, false);
271
293
  if (files.has(p))
272
- throw new BundleError('bad_bundle', `묶음에 같은 경로가 둘이다: ${p}`);
294
+ throw new BundleError('bad_bundle', `The package has the same path twice: ${p}`);
273
295
  if (files.size + 1 > BUNDLE_MAX_FILES)
274
- throw new BundleError('too_large', `묶음의 파일이 ${BUNDLE_MAX_FILES}개를 넘는다`);
296
+ throw new BundleError('too_large', `The package has more than ${BUNDLE_MAX_FILES} files`);
275
297
  total += size;
276
298
  if (total > BUNDLE_MAX_BYTES)
277
- throw new BundleError('too_large', `묶음의 파일 크기 합이 ${BUNDLE_MAX_BYTES} 바이트를 넘는다`);
299
+ throw new BundleError('too_large', `The total file size in the package is over ${BUNDLE_MAX_BYTES} bytes`);
278
300
  files.set(p, Buffer.from(data));
279
301
  }
280
302
  if (!ended)
281
- throw new BundleError('bad_bundle', '묶음의 끝 표시가 없다');
303
+ throw new BundleError('bad_bundle', 'The package has no end marker');
282
304
  const manifestFile = files.get('manifest.json');
283
305
  if (!manifestFile)
284
- throw new BundleError('bad_bundle', '묶음에 manifest.json 이 없다');
306
+ throw new BundleError('bad_bundle', 'The package has no manifest.json');
285
307
  let manifest;
286
308
  try {
287
309
  manifest = JSON.parse(manifestFile.toString('utf8'));
288
310
  }
289
311
  catch (e) {
290
- throw new BundleError('bad_manifest', `manifest.json 이 JSON 이 아니다(${e.message})`);
312
+ throw new BundleError('bad_manifest', `manifest.json is not JSON (${e.message})`);
291
313
  }
292
314
  const problem = checkManifest(manifest);
293
315
  if (problem)
294
316
  throw new BundleError('bad_manifest', problem);
295
317
  const m = manifest;
296
318
  if (!files.has(m.logic))
297
- throw new BundleError('bad_bundle', `묶음에 논리 파일 ${m.logic} 이 없다`);
319
+ throw new BundleError('bad_bundle', `The package has no logic file ${m.logic}`);
298
320
  if (m.ui !== undefined && !files.has(m.ui))
299
- throw new BundleError('bad_bundle', `묶음에 화면 파일 ${m.ui} 가 없다`);
321
+ throw new BundleError('bad_bundle', `The package has no screen file ${m.ui}`);
300
322
  const extra = [...files.keys()].filter((p) => !bundlePathAllowed(p, m));
301
323
  if (extra.length > 0) {
302
- throw new BundleError('bad_bundle', `묶음에 넣을 수 없는 파일이 있다: ${extra.join(', ')}. manifest.json, 논리 파일, ui/ 의 파일, LICENSE, README.md, manifest 의 manual 과 samples 가 가리키는 파일만 넣는다`);
324
+ 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, samples and connect.messages in the manifest point to`);
303
325
  }
304
- const docs = docsProblem(m, files) ?? iconFileProblem(m, files);
326
+ const docs = docsProblem(m, files) ?? iconFileProblem(m, files) ?? connectFilesProblem(m, files);
305
327
  if (docs)
306
328
  throw new BundleError('bad_bundle', docs);
307
329
  return { manifest: m, files, sha256: sha256Hex(buf), size: buf.length };
@@ -314,5 +336,5 @@ export function checkBundleForRegistry(bundle) {
314
336
  const problem = checkForRegistry(bundle.manifest);
315
337
  if (problem)
316
338
  return { code: 'bad_manifest', message: problem };
317
- return bundle.files.has('LICENSE') ? null : { code: 'bad_bundle', message: '사이트에 올리려면 묶음에 LICENSE 파일이 있어야 한다' };
339
+ return bundle.files.has('LICENSE') ? null : { code: 'bad_bundle', message: 'To upload to the site, the package needs a LICENSE file' };
318
340
  }
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 `아이콘 파일이 ${ICON_MAX_BYTES.toLocaleString('en-US')} 바이트를 넘는다(${data.length.toLocaleString('en-US')} 바이트)`;
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 '아이콘 파일이 UTF-8 글이 아니다';
35
+ return 'The icon file is not UTF-8 text';
36
36
  }
37
37
  if (/<!DOCTYPE|<!ENTITY/i.test(text))
38
- return '아이콘에 DOCTYPE 이나 ENTITY 를 넣지 않는다';
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 '아이콘 파일이 <svg 로 시작하는 SVG 가 아니다';
44
+ return 'The icon file is not an SVG that starts with <svg';
45
45
  if (!/<\/svg>\s*$/i.test(body))
46
- return '아이콘 파일이 </svg> 로 끝나지 않는다';
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 `아이콘에 ${banned[1]} 요소를 넣지 않는다`;
49
+ return `The icon must not contain a ${banned[1]} element`;
50
50
  if (/[\s"'/]on[a-z]+\s*=/i.test(body))
51
- return '아이콘에 이벤트 속성(on...)을 넣지 않는다';
51
+ return 'The icon must not contain event attributes (on...)';
52
52
  if (/javascript\s*:|@import/i.test(body))
53
- return '아이콘에 javascript: 주소나 @import 를 넣지 않는다';
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 '아이콘의 href 와 src 는 문서 안의 #id 만 가리킨다(바깥 주소와 data: 주소는 받지 않는다)';
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 '아이콘의 url() 은 문서 안의 #id 만 가리킨다';
58
+ return 'url() in the icon may only point to a #id inside the document';
59
59
  }
60
60
  return null;
61
61
  }
@@ -43,6 +43,18 @@ export interface ExternalTool {
43
43
  account: 'none' | 'free' | 'paid';
44
44
  install: boolean;
45
45
  note?: string;
46
+ /** 플러그인 화면에서 사람이 만들 수 있는 HTTP 연결(032 44.2절). kind 가 mcp 인 항목에만 있다. */
47
+ connect?: ExternalConnect;
48
+ }
49
+ /**
50
+ * 플러그인 화면에서 사람이 [연결] 을 눌러 만드는 HTTP 연결(032 44.2절). 코어는 이 manifest 의 주소만 쓰고 화면 코드가 주소를 넘기지 못한다.
51
+ * messages 는 플러그인 폴더 안의 메시지 표이고, 연결을 만들 때 코어가 연결 정의 파일의 폴더로 복사한다.
52
+ */
53
+ export interface ExternalConnect {
54
+ connection: string;
55
+ url: string;
56
+ title?: string;
57
+ messages?: string;
46
58
  }
47
59
  export interface PluginRequires {
48
60
  os: 'any' | OsName[];
@@ -54,6 +66,14 @@ export declare const RESERVED_IDS: readonly string[];
54
66
  export declare const MAX_DEPENDENCIES = 20;
55
67
  /** samples 의 항목 수 한도(037 7절 4번). */
56
68
  export declare const MAX_SAMPLES = 5;
69
+ /** connect.url 의 길이 한도(032 44.2절). */
70
+ export declare const CONNECT_URL_MAX = 500;
71
+ /**
72
+ * connect.url 의 모양(032 44.2절). https 이고, 시험을 위해 http://127.0.0.1 과 http://localhost 는 받는다(032 31.6절과 같다). 사용자 정보(user@)와
73
+ * # 뒤는 받지 않는다. 물음표 뒤는 공개 manifest 에 있으니 비밀이 아니라 받는다. 빈칸, 제어 글자, 역빗금은 URL 이 조용히 고쳐 읽으므로 받지
74
+ * 않는다. 문제가 있으면 "<칸> <까닭>" 의 까닭이고 없으면 null 이다. 코어도 연결을 쓰기 전에 이것으로 다시 본다.
75
+ */
76
+ export declare function connectUrlProblem(value: unknown): string | null;
57
77
  /** `계정이름.플러그인이름` 모양인가. 각 부분은 영어 소문자, 숫자, `-` 이고 2자에서 40자다(036 4절). */
58
78
  export declare function isPluginId(id: unknown): id is string;
59
79
  /** id 의 앞부분(계정 이름). */