aicommunicator 0.0.0-stage → 0.2.0
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/LICENSE +55 -0
- package/README.md +93 -2
- package/bin/aic.js +20427 -0
- package/host-ui/host.js +5151 -0
- package/host-ui/index.html +483 -0
- package/host-ui/lang-en.js +631 -0
- package/package.json +30 -4
- package/plugin-guide.md +997 -0
- package/plugins/plugin-animation/LICENSE +55 -0
- package/plugins/plugin-animation/dist/logic.js +2225 -0
- package/plugins/plugin-animation/docs/manual.md +217 -0
- package/plugins/plugin-animation/manifest.json +31 -0
- package/plugins/plugin-animation/ui/icon.svg +6 -0
- package/plugins/plugin-animation/ui/index.html +2266 -0
- package/plugins/plugin-html-design/LICENSE +55 -0
- package/plugins/plugin-html-design/dist/logic.js +972 -0
- package/plugins/plugin-html-design/docs/manual.md +100 -0
- package/plugins/plugin-html-design/manifest.json +39 -0
- package/plugins/plugin-html-design/samples/exhibition-page.json +570 -0
- package/plugins/plugin-html-design/ui/icon.svg +5 -0
- package/plugins/plugin-html-design/ui/index.html +1241 -0
- package/plugins/plugin-html-slides/LICENSE +55 -0
- package/plugins/plugin-html-slides/dist/logic.js +1323 -0
- package/plugins/plugin-html-slides/docs/manual.md +121 -0
- package/plugins/plugin-html-slides/manifest.json +39 -0
- package/plugins/plugin-html-slides/samples/first-week-lecture.json +1129 -0
- package/plugins/plugin-html-slides/ui/icon.svg +5 -0
- package/plugins/plugin-html-slides/ui/index.html +1349 -0
- package/plugins/plugin-mindmap/LICENSE +55 -0
- package/plugins/plugin-mindmap/dist/logic.js +966 -0
- package/plugins/plugin-mindmap/docs/manual.md +145 -0
- package/plugins/plugin-mindmap/manifest.json +39 -0
- package/plugins/plugin-mindmap/samples/book-club.json +480 -0
- package/plugins/plugin-mindmap/ui/icon.svg +5 -0
- package/plugins/plugin-mindmap/ui/index.html +1774 -0
- package/plugins/plugin-plan/LICENSE +55 -0
- package/plugins/plugin-plan/dist/logic.js +1029 -0
- package/plugins/plugin-plan/docs/manual.md +261 -0
- package/plugins/plugin-plan/manifest.json +51 -0
- package/plugins/plugin-plan/samples/kimchi-day.json +1514 -0
- package/plugins/plugin-plan/samples/meeting-outline.json +653 -0
- package/plugins/plugin-plan/samples/reading-class.json +1577 -0
- package/plugins/plugin-plan/ui/icon.svg +7 -0
- package/plugins/plugin-plan/ui/index.html +1523 -0
- package/plugins/plugin-png/LICENSE +55 -0
- package/plugins/plugin-png/dist/logic.js +1758 -0
- package/plugins/plugin-png/docs/manual.md +344 -0
- package/plugins/plugin-png/manifest.json +35 -0
- package/plugins/plugin-png/ui/icon.svg +5 -0
- package/plugins/plugin-png/ui/index.html +2885 -0
- package/plugins/plugin-process-log/LICENSE +55 -0
- package/plugins/plugin-process-log/dist/logic.js +406 -0
- package/plugins/plugin-process-log/docs/manual.md +131 -0
- package/plugins/plugin-process-log/manifest.json +43 -0
- package/plugins/plugin-process-log/samples/design-decisions.json +241 -0
- package/plugins/plugin-process-log/ui/icon.svg +7 -0
- package/plugins/plugin-process-log/ui/index.html +721 -0
- package/plugins/plugin-story/LICENSE +55 -0
- package/plugins/plugin-story/dist/logic.js +2201 -0
- package/plugins/plugin-story/docs/manual.md +428 -0
- package/plugins/plugin-story/manifest.json +49 -0
- package/plugins/plugin-story/samples/scene-body.json +758 -0
- package/plugins/plugin-story/samples/time-and-groups.json +989 -0
- package/plugins/plugin-story/ui/icon.svg +4 -0
- package/plugins/plugin-story/ui/index.html +2783 -0
- package/plugins/plugin-svg/LICENSE +55 -0
- package/plugins/plugin-svg/dist/logic.js +2150 -0
- package/plugins/plugin-svg/docs/manual.md +314 -0
- package/plugins/plugin-svg/manifest.json +45 -0
- package/plugins/plugin-svg/samples/rocket-icon.json +1305 -0
- package/plugins/plugin-svg/samples/yard-cat.json +7796 -0
- package/plugins/plugin-svg/ui/icon.svg +4 -0
- package/plugins/plugin-svg/ui/index.html +2017 -0
- package/plugins/plugin-tree/LICENSE +55 -0
- package/plugins/plugin-tree/dist/logic.js +505 -0
- package/plugins/plugin-tree/docs/manual.md +140 -0
- package/plugins/plugin-tree/manifest.json +45 -0
- package/plugins/plugin-tree/samples/book-club.json +473 -0
- package/plugins/plugin-tree/samples/sort-memos.json +604 -0
- package/plugins/plugin-tree/ui/icon.svg +7 -0
- package/plugins/plugin-tree/ui/index.html +1305 -0
- package/schema/aic_describe.input.json +11 -0
- package/schema/aic_describe.output.json +67 -0
- package/schema/aic_observe.input.json +14 -0
- package/schema/aic_observe.output.json +47 -0
- package/schema/aic_send.input.json +15 -0
- package/schema/aic_send.output.json +38 -0
- package/schema/aic_update.input.json +19 -0
- package/schema/aic_update.output.json +39 -0
- package/schema/common.json +127 -0
- package/template/plugin/LICENSE +55 -0
- package/template/plugin/README.md +27 -0
- package/template/plugin/docs/manual.md +31 -0
- package/template/plugin/logic.js +337 -0
- package/template/plugin/manifest.json +27 -0
- package/template/plugin/ui/icon.svg +4 -0
- package/template/plugin/ui/index.html +269 -0
package/plugin-guide.md
ADDED
|
@@ -0,0 +1,997 @@
|
|
|
1
|
+
# Guide to making an AIC plugin
|
|
2
|
+
|
|
3
|
+
> **This contract is experimental version 0.1 and may change.** The core's plugin protocol version is now `"0.1"`. While the version starts with 0, a change in the middle number is an incompatible change. When the contract changes, check the manifest's `protocol` again against the new version.
|
|
4
|
+
|
|
5
|
+
This guide is for a person who installed AIC with npm and for that person's coding AI. It is written so that you can make a plugin, test it, and publish it to the registry site with this guide alone, without the AIC source. You can print the guide again at any time with `aic plugin guide`.
|
|
6
|
+
|
|
7
|
+
When an AI reads this guide and works from it, the order is as follows.
|
|
8
|
+
|
|
9
|
+
1. Ask the person what screen they need, and use section 1 to check whether the job fits a plugin.
|
|
10
|
+
2. Make a starter template with `aic plugin new <id> [folder]` (section 7).
|
|
11
|
+
3. Edit `manifest.json`, the logic file and the screen file to follow the contracts in sections 2 to 4.
|
|
12
|
+
4. Check and install with `aic plugin pack` and `aic plugin install <folder>`, then restart the core and try the plugin (section 7).
|
|
13
|
+
5. If the person wants, publish it to the registry site (sections 8 and 9).
|
|
14
|
+
|
|
15
|
+
## 1. What a plugin is
|
|
16
|
+
|
|
17
|
+
In AIC, the person and the AI work while looking at the same "concept screen". A plugin defines one concept screen. The person sees and edits that screen in a browser. The AI reads the same content as text through MCP tools and edits it by sending operations. Both see and edit the same records.
|
|
18
|
+
|
|
19
|
+
A plugin has two parts.
|
|
20
|
+
|
|
21
|
+
- **Logic**: JavaScript functions that define how records change (operations), whether the state is correct (checks), and what to show to the AI and the screen (reads). The core calls them inside an isolated runner.
|
|
22
|
+
- **Screen**: one HTML file that runs inside an iframe in the browser. It talks to the host (the AIC browser screen) only through messages.
|
|
23
|
+
|
|
24
|
+
The core handles storage, history, merging changes from other participants, conflicts, the memo box, work intent and permissions. A plugin does not build any of these itself.
|
|
25
|
+
|
|
26
|
+
### 1.1 What a plugin can and cannot do
|
|
27
|
+
|
|
28
|
+
A plugin can do the following.
|
|
29
|
+
|
|
30
|
+
- Define the kinds (type) of its records and the shape of their content. The content can be any value that JSON can express.
|
|
31
|
+
- Define the operations that the person and the AI use (names like `item.add`) and their input.
|
|
32
|
+
- Define the text the AI reads and the JSON the screen draws.
|
|
33
|
+
- Send what the person edited on the screen as the same operations.
|
|
34
|
+
- Point to a memo in the core's memo box by its id (for example `memo3`).
|
|
35
|
+
|
|
36
|
+
A plugin cannot do the following.
|
|
37
|
+
|
|
38
|
+
- **Logic cannot reach files or the network.** The isolated runner has no files, network, time (`Date`), random numbers (`Math.random`), timers or module loading (`import`, `require`).
|
|
39
|
+
- **The screen cannot reach outside either.** The CSP that the core adds blocks all outside connections, outside images and outside scripts (section 4.1).
|
|
40
|
+
- **A plugin cannot connect to outside services.** Talking to outside tools is the job of the core's external connection feature, and it is not part of the plugin contract.
|
|
41
|
+
- A plugin cannot read or change the records of other instances or the core's records (memos, work intent).
|
|
42
|
+
- A plugin cannot load and use another plugin's code. `dependencies` only guarantees that the other plugin is installed too.
|
|
43
|
+
|
|
44
|
+
One work can have several instances. One instance is one screen of one plugin, and the core sets its id, like `p1` or `p2`. If one work has two instances of the same plugin, their records are separate too.
|
|
45
|
+
|
|
46
|
+
## 2. Folder and files
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
yourname-checklist/
|
|
50
|
+
manifest.json required
|
|
51
|
+
logic.js the logic file that the manifest's logic points to
|
|
52
|
+
ui/index.html the screen file
|
|
53
|
+
ui/icon.svg the icon that the manifest's icon points to. Optional, but recommended (section 2.2)
|
|
54
|
+
docs/manual.md the detailed manual that the manifest's manual points to. Optional, but recommended (section 7.8)
|
|
55
|
+
samples/*.json sample files that the manifest's samples point to. Optional (section 7.8)
|
|
56
|
+
LICENSE required to publish to the site
|
|
57
|
+
README.md optional. Shown on the site's detail page
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- The bundle (`.tgz`) contains only the files above. For the manual and samples, only the files that the manifest's `manual` and `samples` point to go in, so you can name their folders as you like. `aic plugin pack` leaves out all other files (sources, `node_modules`, test files). So you can use TypeScript or a build tool. Point `logic` to the one built output file (section 3.1).
|
|
61
|
+
- Do not put folders inside `ui/`. Use only English letters, digits, `_`, `.` and `-` in file names.
|
|
62
|
+
- The host always opens `ui/index.html`. So keep the screen file as `ui/index.html` and write `"ui/index.html"` in the manifest's `ui` too.
|
|
63
|
+
- Write the screen's scripts and styles directly inside `index.html`. The CSP blocks loading other files with `<script src>` and `<link rel="stylesheet">` (section 4.1).
|
|
64
|
+
|
|
65
|
+
### 2.1 manifest.json
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"id": "yourname.checklist",
|
|
70
|
+
"version": "0.1.0",
|
|
71
|
+
"dataVersion": 1,
|
|
72
|
+
"protocol": "0.1",
|
|
73
|
+
"title": "Checklist",
|
|
74
|
+
"license": "Apache-2.0",
|
|
75
|
+
"logic": "logic.js",
|
|
76
|
+
"ui": "ui/index.html",
|
|
77
|
+
"icon": "ui/icon.svg",
|
|
78
|
+
"about": "A list where you write things to do, one per line, and mark the finished ones.",
|
|
79
|
+
"examples": [
|
|
80
|
+
{ "ask": "I want to write down today's tasks and check them off one by one", "does": "The AI writes each task as an item, and you click the items that are done." }
|
|
81
|
+
],
|
|
82
|
+
"requires": { "os": "any", "external": [] }
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
| Field | Required? | Shape and limit | Meaning |
|
|
87
|
+
| --- | --- | --- | --- |
|
|
88
|
+
| `id` | required | `accountname.pluginname`. Both parts use lowercase English letters, digits and `-`, from 2 to 40 characters | The plugin name. The first part is your account name on the registry site. `aic.link` cannot be used, and names that start with `aic.` are reserved for official plugins |
|
|
89
|
+
| `version` | required | semver. `number.number.number`, optionally followed by a prerelease name like `-beta.1`. A `+` suffix is not accepted. Up to 64 characters | The plugin version (section 5) |
|
|
90
|
+
| `dataVersion` | required | An integer of 1 or more | The version of the shape of record content. If you change it, works made before will not open (section 5) |
|
|
91
|
+
| `logic` | required | A relative path inside the folder. Split by `/`, and each piece uses English letters, digits, `_`, `.` and `-`. `..`, absolute paths and `\` are not accepted. Up to 200 characters | The logic file |
|
|
92
|
+
| `ui` | optional | One file directly under `ui/` | The screen file. Set it to `"ui/index.html"` |
|
|
93
|
+
| `icon` | optional (recommended) | An SVG file (`.svg`) directly under `ui/`. The file can be up to 32,768 bytes | The icon (section 2.2). It is shown when a plugin is chosen on the screen that makes a new work and on the registry site. If it is missing, the first letter of the name is shown, and `aic plugin pack` and the site only give a notice |
|
|
94
|
+
| `title` | required to publish | Non-empty text, up to 100 characters | The name the person sees. Write it **in English** (section 3.7) |
|
|
95
|
+
| `license` | required to publish | Non-empty text, up to 100 characters | The license name. The bundle must also have a `LICENSE` file |
|
|
96
|
+
| `about` | required to publish | Non-empty text, up to 1,000 characters | What you can do on this screen. Write it in human words, **in English** (see "Write the introduction in English" below). Do not write operation names or id shapes (that is the job of `aiGuide`) |
|
|
97
|
+
| `protocol` | required to publish | The shape `"0.<number>"`. Now `"0.1"` | The core protocol version this plugin follows. If it differs from the core's protocol version, the core does not load this plugin. If it is missing, it is not checked |
|
|
98
|
+
| `examples` | optional | A list of `{ ask, does }`, up to five. Each text up to 300 characters | `ask` is what the person wants to do, and `does` is how to do it on this screen. The AI uses them to compare a job in the conversation with this plugin. Write them **in English** |
|
|
99
|
+
| `requires` | optional | `{ os, external }`. If missing, `{ "os": "any", "external": [] }` | The runtime environment. See the table below |
|
|
100
|
+
| `dependencies` | optional | `{ "<id>": "<version range>" }`, up to twenty | Other plugins that must be installed too (section 6) |
|
|
101
|
+
| `manual` | optional (recommended) | A relative path to a Markdown file (`.md`) inside the folder. The file can be up to 50,000 characters | The detailed manual (section 7.8). If it is missing, `aic plugin pack` and the site only give a notice |
|
|
102
|
+
| `samples` | optional | A list of `{ id, title, about, file }`, up to five. `id` uses lowercase English letters, digits and `-`, up to 40 characters. `title` is up to 100 characters and `about` up to 300. `file` is a relative path to a `.json` file inside the folder, and the file can be up to 200,000 characters | Usage samples (section 7.8). Each is a real work exported with `aic export-sample` |
|
|
103
|
+
|
|
104
|
+
The fields of `requires` are as follows.
|
|
105
|
+
|
|
106
|
+
| Field | Shape | Meaning |
|
|
107
|
+
| --- | --- | --- |
|
|
108
|
+
| `os` | `"any"`, or a list of `"windows"`, `"macos"`, `"linux"` | The operating systems it runs on. Logic and screens run on any operating system, so this is usually `"any"` |
|
|
109
|
+
| `external` | A list, up to ten | Outside tools. If none, an empty list |
|
|
110
|
+
| `external[].name` | Text, up to 100 characters | The tool name |
|
|
111
|
+
| `external[].kind` | `"program"`, `"web"`, `"mcp"` | A program to install, a web service, or the vendor's MCP server |
|
|
112
|
+
| `external[].account` | `"none"`, `"free"`, `"paid"` | No sign-up needed, free sign-up, or paid sign-up |
|
|
113
|
+
| `external[].install` | true or false | Whether the person must install it themselves |
|
|
114
|
+
| `external[].note` | Text, up to 200 characters (optional) | What it is used for and what to prepare |
|
|
115
|
+
|
|
116
|
+
- Text length is measured in characters (code points). If a value is over the limit or has the wrong shape, the core, `aic plugin pack` and the site all reject it for the same reason. They do not cut it silently.
|
|
117
|
+
- Unknown fields inside `requires`, `examples` and `requires.external[]` are rejected. Unknown fields at the top level are not rejected.
|
|
118
|
+
- The core does not block a plugin because of `requires`. If `os` leaves out the current operating system, the core only adds "이 컴퓨터의 운영체제에서는 돌지 않음" (Does not run on this computer's operating system) to the plugin list.
|
|
119
|
+
|
|
120
|
+
### 2.2 Icon
|
|
121
|
+
|
|
122
|
+
The icon is a small picture shown next to the name on screens where a plugin is chosen (making a new work, the registry site). Keep it as `ui/icon.svg` and write `"icon": "ui/icon.svg"` in the manifest.
|
|
123
|
+
|
|
124
|
+
```xml
|
|
125
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
|
|
126
|
+
<rect x="2" y="2" width="20" height="20" rx="5" fill="#3b6fd4"/>
|
|
127
|
+
<path d="M7 8h10M7 12h10M7 16h6" fill="none" stroke="#ffffff" stroke-width="2" stroke-linecap="round"/>
|
|
128
|
+
</svg>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**Shape**
|
|
132
|
+
|
|
133
|
+
- Draw it as a square. Set `viewBox` to a square, like `0 0 24 24`. Screens show it at 16 to 48 pixels.
|
|
134
|
+
- Draw it simply so it can be recognized even when small. Show what this screen handles (a list, a tree, a picture, a scene) with one shape. Do not put in letters or thin lines.
|
|
135
|
+
- Write colors directly in the file. The icon is shown only as an image, so `currentColor` and the screen's CSS variables do not reach it. To make it visible on both light and dark screens, a safe way is to fill the background with a color and put a light shape on top.
|
|
136
|
+
|
|
137
|
+
**File rules.** If a rule is broken, `aic plugin pack` and the site reject the icon with the reason. For a folder placed by hand, the core treats the plugin as having no icon.
|
|
138
|
+
|
|
139
|
+
| Rule | Value |
|
|
140
|
+
| --- | --- |
|
|
141
|
+
| Location and format | One `.svg` file directly under `ui/`. It is UTF-8 text that starts with `<svg` and ends with `</svg>` |
|
|
142
|
+
| Size | Up to 32,768 bytes |
|
|
143
|
+
| Elements not allowed | `script`, `style`, `foreignObject`, `iframe`, `object`, `embed`, `audio`, `video`, `link`, `meta`, and the animation elements `animate`, `animateTransform`, `animateMotion`, `set` |
|
|
144
|
+
| Other things not allowed | Event attributes (`on...` such as `onclick`), `javascript:` addresses, `@import`, `DOCTYPE`, `ENTITY` |
|
|
145
|
+
| Addresses | `href`, `xlink:href`, `src` and `url()` may point only to a `#id` inside the document. Outside addresses and `data:` addresses are not accepted. Gradients and `use` are allowed |
|
|
146
|
+
|
|
147
|
+
- Write colors and lines with attributes such as `fill` and `stroke`. `<style>` is not accepted.
|
|
148
|
+
- A file exported from a drawing editor may contain `<style>`, addresses inside `<metadata>`, or embedded images (`data:`). After exporting, check it with `aic plugin pack`.
|
|
149
|
+
- Adding or changing the icon changes the bundle. So for a plugin already published to the site, raise `version` and publish it again (section 5).
|
|
150
|
+
|
|
151
|
+
## 3. Logic contract
|
|
152
|
+
|
|
153
|
+
### 3.1 Shape of the logic file
|
|
154
|
+
|
|
155
|
+
The logic file is **a single script file**. It is not a module, so do not use `import`, `export` or `require`. At the end of the file, put an object that holds the functions into `globalThis.__aicPlugin`.
|
|
156
|
+
|
|
157
|
+
```js
|
|
158
|
+
(() => {
|
|
159
|
+
// helper functions and the operation table
|
|
160
|
+
globalThis.__aicPlugin = {
|
|
161
|
+
describe() { /* ... */ },
|
|
162
|
+
initialize(input, ctx) { /* ... */ },
|
|
163
|
+
plan(state, step, ctx) { /* ... */ },
|
|
164
|
+
validate(candidate, changed) { /* ... */ },
|
|
165
|
+
project(state, scope, mine) { /* ... */ },
|
|
166
|
+
extractRefs(record) { /* ... */ },
|
|
167
|
+
resolveTarget(state, target) { /* ... */ },
|
|
168
|
+
prepareGeneration(state, scope, medium) { /* ... */ },
|
|
169
|
+
interpretSelection(state, selection) { /* ... */ },
|
|
170
|
+
};
|
|
171
|
+
})();
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
- You may skip the wrapping function above and list `const` values and functions at the top level. Each call runs in a new context, so names do not mix with other plugins. The starter template's `logic.js` is not wrapped. It starts with `'use strict';` and ends with `globalThis.__aicPlugin = logic;`.
|
|
175
|
+
- You can use syntax up to ES2022 (arrow functions, `const`, spread, `??`, `?.`, `Object.values`, `Set`, `Map`).
|
|
176
|
+
- To write in TypeScript or in several files, bundle them into one IIFE file. For example, build with `esbuild src/logic.ts --bundle --format=iife --target=es2022 --platform=neutral --outfile=dist/logic.js` and set the manifest's `logic` to `"dist/logic.js"`.
|
|
177
|
+
- Arguments and return values travel as JSON. Functions, `undefined` fields, `Map` and `Set` are dropped or changed in return values. Usually build return values from objects and arrays.
|
|
178
|
+
|
|
179
|
+
### 3.2 Runtime environment and limits
|
|
180
|
+
|
|
181
|
+
| What | Value | If exceeded |
|
|
182
|
+
| --- | --- | --- |
|
|
183
|
+
| Time for one call | 2 seconds | `RESOURCE_LIMIT` |
|
|
184
|
+
| Memory for one call | 64MB | `RESOURCE_LIMIT` |
|
|
185
|
+
| Stack | 1MB | `RESOURCE_LIMIT` |
|
|
186
|
+
| Return value (JSON text) | 8MB | `RESOURCE_LIMIT` |
|
|
187
|
+
| All operation handling for one request | 10 seconds | `RESOURCE_LIMIT` |
|
|
188
|
+
| Output text passed to an operation | 1MB (UTF-8) | The core rejects it before calling |
|
|
189
|
+
|
|
190
|
+
- **Each call is a new execution context.** Every time the core calls a function, it runs the logic file fresh and throws it away when done. Values put in global variables do not survive to the next call. Do not keep caches or counters in globals. Keep all needed state in records.
|
|
191
|
+
- `Date` is removed and `Math.random()` throws an error. If you use them, that call fails with `PLUGIN_FAILURE`. `fetch`, `require` and `setTimeout` do not exist either.
|
|
192
|
+
- If a function throws an error, the core rejects the request with `PLUGIN_FAILURE`. Do not throw expected rejections. Return them in the failure shape from section 3.5.
|
|
193
|
+
- The core uses the sha256 of the logic file as its fingerprint. If you edit the logic file without changing the version, a notice appears (section 5).
|
|
194
|
+
|
|
195
|
+
### 3.3 Records and state
|
|
196
|
+
|
|
197
|
+
```ts
|
|
198
|
+
interface RecordValue {
|
|
199
|
+
id: string; // set by the core. Example: "it3"
|
|
200
|
+
type: string; // set by the plugin. Example: "item". "instance" cannot be used
|
|
201
|
+
owner: string | null; // the instance id of the record (p1). Filled in by the core
|
|
202
|
+
content: unknown; // a JSON value defined by the plugin
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
interface StateSnapshot {
|
|
206
|
+
records: Record<string, RecordValue>; // the key is the record id
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
- The `state` a function receives holds **only the records of that instance**. Memos, work intent and records of other instances are not in it.
|
|
211
|
+
- In `plan`, records made by earlier operations in the same request are in `state.records` with a temporary name (such as `$a`) as their id. So you can point to something an earlier operation made, as in `{ op: "item.check", input: { item: "$a" } }`.
|
|
212
|
+
- The core sets the real id of a new record by adding a number after the `prefix` (`it1`, `it2`). Numbers run separately for each work and each prefix.
|
|
213
|
+
|
|
214
|
+
### 3.4 Change
|
|
215
|
+
|
|
216
|
+
`initialize` and `plan` return a list of changes.
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
interface Change {
|
|
220
|
+
id: string; // the id of an existing record, or the temporary name of a new record (starts with $)
|
|
221
|
+
type: string; // the record type
|
|
222
|
+
after: unknown | null;// the whole content after the change. null deletes the record
|
|
223
|
+
prefix?: string; // the id prefix of a new record. Required for a new record
|
|
224
|
+
refs?: Record<string, string>; // position references. Example: { after: "it2" } means "placed after it2"
|
|
225
|
+
moved?: boolean; // true if this change moved the record
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
The core checks the following rules. If any is broken, the whole request is rejected with `PLUGIN_FAILURE`.
|
|
230
|
+
|
|
231
|
+
- `id` and `type` must be text. `type` must not be `"instance"`.
|
|
232
|
+
- Change only the records of your own instance. You cannot change records of other instances or core records (`memo3`, `intent1`).
|
|
233
|
+
- An id that does not start with `$` must be an existing record.
|
|
234
|
+
- A new record (temporary name) must have a `prefix`. Make the `prefix` a few lowercase English letters, and do not end it with a digit. `memo` and `intent` are used by the core, so they are not accepted. Also avoid `p` and `h`, which instances and revisions use.
|
|
235
|
+
- `after` is the whole content. Even when you change only some fields, write the whole content again, as in `{ ...r.content, done: true }`.
|
|
236
|
+
- If one request changes the same record several times, the core merges them into one.
|
|
237
|
+
|
|
238
|
+
**Replacing temporary names.** When saving, the core replaces every text value inside the content that is **exactly equal to a temporary name of this request** with the real id. Inside summary text, it replaces even a part of the text. So if ordinary text written by the person is exactly equal to a temporary name, it gets replaced by mistake. Reject input text that is in `ctx.tempNames`. On the other hand, you can use this behavior: if you write a temporary name in a summary, the saved summary keeps the real id.
|
|
239
|
+
|
|
240
|
+
**Naming the temporary name of a new record.** If the AI gave `step.as`, use that name for the new record. If not, the plugin makes a name that starts with `$~`, like `$~<stepIndex>` (the starter template uses `` op.as || `$~${ctx.stepIndex}` ``). If one operation makes several records, add a number, like `$~<stepIndex>.<number>` (for example `$~0.1`), so the names do not overlap. An `as` given by the AI cannot start with `$~`, so it never overlaps with a name the plugin made.
|
|
241
|
+
|
|
242
|
+
### 3.5 Reporting failure
|
|
243
|
+
|
|
244
|
+
Return an expected rejection as an object.
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
interface Fail { error: ErrorCode; summary: string }
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
`summary` is a sentence that the AI and the person read as it is. Write what was wrong and how to fix it. The codes plugins mostly use are as follows.
|
|
251
|
+
|
|
252
|
+
| Code | When to use |
|
|
253
|
+
| --- | --- |
|
|
254
|
+
| `INVALID_INPUT` | An unknown operation, or missing or wrong input |
|
|
255
|
+
| `TARGET_NOT_FOUND` | The record or scope id that was pointed to does not exist |
|
|
256
|
+
| `INVALID_STATE` | An operation that cannot be done in the current state |
|
|
257
|
+
| `UNSUPPORTED_CAPABILITY` | Something this plugin does not do (for example `prepareGeneration` in a plugin that makes no output) |
|
|
258
|
+
|
|
259
|
+
Codes used by the core also appear in responses. They are `STALE_BASE` (the record changed after the base revision), `CONFLICT`, `INCOMPATIBLE_VERSION`, `PERMISSION_DENIED`, `RESOURCE_LIMIT`, `PLUGIN_FAILURE`, `REQUEST_ID_REUSED` and `STORE_BUSY`.
|
|
260
|
+
|
|
261
|
+
### 3.6 Each function
|
|
262
|
+
|
|
263
|
+
Every function must return the same result for the same input (section 3.8).
|
|
264
|
+
|
|
265
|
+
**`describe(): Description`**
|
|
266
|
+
|
|
267
|
+
- When it is called: once for every plugin when the core starts, when the AI calls `describe_document`, when the AI adds this plugin with `add_instance`, and when `aic plugin pack` checks the plugin.
|
|
268
|
+
- What it returns: the `Description` below. Keep `id` and `version` the same as in the manifest. The core checks versions with the values in the manifest.
|
|
269
|
+
- Caution: **If `describe` throws an error or returns an operation name that starts with `core.`, the core does not start.** Always check with `aic plugin pack` before you install.
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
interface Description {
|
|
273
|
+
id: string;
|
|
274
|
+
version: string;
|
|
275
|
+
title: string;
|
|
276
|
+
operations: OperationDescription[];
|
|
277
|
+
markGuide: string; // How to use marks in text. If you do not use them, write "Plain text."
|
|
278
|
+
aiGuide: string; // What to write where on this screen. Sent to the AI as guides in describe_document, in works that have an instance of this plugin
|
|
279
|
+
views?: ViewDescription[]; // Views the AI can pass when it reads the image. Leave this out if you do not accept them (see renderOutput below)
|
|
280
|
+
}
|
|
281
|
+
interface ViewDescription {
|
|
282
|
+
summary: string; // One sentence on what this view shows. Example: "Shows one piece up close."
|
|
283
|
+
input: Record<string, string>; // A description for each field name. Example: { piece: "Piece id. q is the whole, q.2.3 is a piece under it." }
|
|
284
|
+
example?: Record<string, unknown>; // A view that can be sent as is. Example: { piece: "q.2" }
|
|
285
|
+
}
|
|
286
|
+
interface OperationDescription {
|
|
287
|
+
op: string; // Example: "item.add". Must not start with "core."
|
|
288
|
+
input: Record<string, string>; // A description for each input field
|
|
289
|
+
summary: string; // One sentence on what this operation does
|
|
290
|
+
example?: unknown; // Usually a list of operations (steps)
|
|
291
|
+
usesArtifact?: boolean; // true if the operation uses the output passed with the request (ctx.artifact)
|
|
292
|
+
}
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
**`initialize(input, ctx): Change[]`**
|
|
296
|
+
|
|
297
|
+
- When it is called: when a work is created with this plugin (`create_document`) and when an instance is added to a work (`add_instance`). `input` is `{}` and `ctx` is `{ tempNames: [], stepIndex: 0 }`.
|
|
298
|
+
- What it returns: the list of changes for records that must exist from the start. If the screen starts empty, it is `[]`. Every `id` must be a temporary name (starting with `$`), and each change must have a `prefix`.
|
|
299
|
+
|
|
300
|
+
**`plan(state, step, ctx): PlanResult`**
|
|
301
|
+
|
|
302
|
+
- When it is called: once for each operation sent by the AI's `apply_operation` or the screen's `applyOperation` that does not start with `core.`. Operations go only to the editing instance.
|
|
303
|
+
- What it receives: `state` is the current state of this instance with the earlier operations of the same request applied on top. `step` is `{ op, as?, input? }`, and `input` is an object. The core does not check its shape, so check each field yourself. `ctx` is shown below.
|
|
304
|
+
- What it returns: `{ changes, summary }`, or a failure from section 3.5. Keep `summary` to one sentence. The core joins the summaries of one request with periods.
|
|
305
|
+
- All operations in one request are saved together or rejected together. If even one fails, nothing is kept.
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
interface CallContext {
|
|
309
|
+
tempNames: string[]; // All as names in this request
|
|
310
|
+
stepIndex: number; // The position of this operation in the request (from 0)
|
|
311
|
+
artifact?: { id: string; unconfirmed: boolean; sections: Array<{ key: string; label: string; text: string }> };
|
|
312
|
+
}
|
|
313
|
+
type PlanResult = { changes: Change[]; summary: string } | { error: ErrorCode; summary: string };
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
**`validate(candidate, changed): Violation[]`**
|
|
317
|
+
|
|
318
|
+
- When it is called: after all `plan` calls of a request finish and before saving, and also when undo or conflict resolution changes records of this instance.
|
|
319
|
+
- What it receives: `candidate` is the state of this instance after the changes, and `changed` is the list of real ids of the changed records. A removed record is in `changed` but not in `candidate`.
|
|
320
|
+
- What it returns: the list of violations. If there are none, `[]`.
|
|
321
|
+
- If there is even one `level: "error"`, the whole request is rejected with `INVALID_STATE`, and the `message` of each error appears in the response's `summary`, one after another. `reason` is the `code` of the first error.
|
|
322
|
+
- An item with a `notice` field does not reject the request. Its notice goes into the response's `notices`. An item with `level: "notice"` and no `notice` field does not appear anywhere.
|
|
323
|
+
- Check here, not in `plan`, the rules that only hold after several operations (for example "there is one root" or "there are no cycles").
|
|
324
|
+
|
|
325
|
+
```ts
|
|
326
|
+
interface Violation {
|
|
327
|
+
level: 'error' | 'notice';
|
|
328
|
+
code: string; // A short name in English. Example: "second_root"
|
|
329
|
+
record: string;
|
|
330
|
+
message: string; // A sentence that the person and the AI read
|
|
331
|
+
notice?: { kind: 'position_moved' | 'position_removed' | 'ref_changed' | 'display_text_differs' | 'ref_target_removed'; record: string; message?: string };
|
|
332
|
+
}
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
**`project(state, scope, mine): ProjectResult | Fail`**
|
|
336
|
+
|
|
337
|
+
- When it is called: when the AI calls `read_concept` and when the screen calls `readConcept`. If the screen has changes from other participants that are not yet in the shared history, the core calls it once more with those changes applied on top.
|
|
338
|
+
- What it receives: `scope` is `null` (the whole), `{ target }` or `{ targets }`. The plugin decides what the ids refer to and writes this in `aiGuide`. If an id is unknown, return `TARGET_NOT_FOUND`. `mine` is the part of this instance among the reading participant's changes that are not yet in the shared history. Use it to add a mark such as `*` to the text.
|
|
339
|
+
|
|
340
|
+
```ts
|
|
341
|
+
interface ProjectResult {
|
|
342
|
+
text: string; // The text the AI reads through read_concept
|
|
343
|
+
json: unknown; // The data the screen draws (body, withOthers)
|
|
344
|
+
scopeLabel: string; // One line on what was read. Example: "Read everything"
|
|
345
|
+
records?: string[]; // When there is a scope, the record ids that the scope showed. The core uses them to pick the memos that touch the scope
|
|
346
|
+
}
|
|
347
|
+
interface PendingChange {
|
|
348
|
+
revision: string; participant: string; summary: string;
|
|
349
|
+
changes: Array<{ record: string; type: string; owner: string | null; action: 'add' | 'update' | 'remove' | 'move'; before: unknown | null; after: unknown | null }>;
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
- Write `text` so that the AI can send operations after reading only this. Write each record's id in parentheses next to it (for example `- (it1) [x] Choose a cover`). If it is empty, write one sentence on what to do first.
|
|
354
|
+
|
|
355
|
+
**`extractRefs(record): ContentRef[]`**
|
|
356
|
+
|
|
357
|
+
- When it is called: every time a record changes and is saved, and when the core rebuilds its reference index.
|
|
358
|
+
- What it returns: the list of other records that the record's content points to. If it points to no other record, it is `[]`.
|
|
359
|
+
|
|
360
|
+
```ts
|
|
361
|
+
interface ContentRef { from: string; to: string; kind: string; soft?: boolean }
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
- `kind` is a name the plugin chooses (for example `"parent"`). Do not use `"owner"`, because the core uses it.
|
|
365
|
+
- `soft: true` marks a soft reference. If the target is removed, it becomes a notice, not a conflict or a rejection. Keep references to memos soft.
|
|
366
|
+
- The core uses this list to find records that point to memos (stickers) and to report that a target was removed. If a memo being pointed to does not exist, the core rejects the request with `TARGET_NOT_FOUND`. `validate` checks whether references to plugin records are correct.
|
|
367
|
+
|
|
368
|
+
**`resolveTarget(state, target): { found: boolean; label?: string }`**
|
|
369
|
+
|
|
370
|
+
- When it is called: when a mark in the text of a core memo points to a record of this instance, to get that record's name.
|
|
371
|
+
- What it returns: `{ found: true, label: "Item it1: Choose a cover" }` if it exists, `{ found: false }` if not.
|
|
372
|
+
|
|
373
|
+
**`prepareGeneration(state, scope, medium)` and `interpretSelection(state, selection)`**
|
|
374
|
+
|
|
375
|
+
- These functions are for plugins that make text output from the concept (such as the body text of a novel). They are called when the AI calls `begin_generation` or when the person selects something in the output text.
|
|
376
|
+
- A plugin that makes no output returns `{ error: "UNSUPPORTED_CAPABILITY", summary: "..." }` from `prepareGeneration` and `{ candidates: [] }` from `interpretSelection`. If the functions are missing, calling them gives `PLUGIN_FAILURE`, so keep at least these.
|
|
377
|
+
|
|
378
|
+
```ts
|
|
379
|
+
interface GenerationPrep {
|
|
380
|
+
material: string; // The source text the AI reads when it writes the output
|
|
381
|
+
sections: Array<{ key: string; label: string; content: string }>; // The sections of the output. key is usually a record id
|
|
382
|
+
records: string[];
|
|
383
|
+
}
|
|
384
|
+
interface SelectionCandidates { candidates: Array<{ id: string; label: string; why: string }> }
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
**Optional functions `describeSelection` and `renderOutput`**
|
|
388
|
+
|
|
389
|
+
They are optional. The core checks whether they exist before calling them.
|
|
390
|
+
|
|
391
|
+
- `describeSelection(state, { selection, redrawn, current })`: turns the place the screen pointed to with `shareSelection` (`payload`) into text for the AI to read. It returns `{ text, targets, gone }`. A selection that the screen only reported with `setPick` (section 4.4) is described by the same function (`redrawn` is `null`). Without it, the AI sees only the list of records the core pointed to and the person's words.
|
|
392
|
+
- `renderOutput(state, { format, revision })`: turns the state of the work into one file. The formats are `"html"` and `"svg"`. If the plugin does not produce a format, it rejects it with `UNSUPPORTED_CAPABILITY`. Check the format first and reject before anything else, because the core learns whether you produce svg by asking once for svg with an empty state. It returns `{ ok: true, mediaType, fileName, content }`. If it exists, the screen's `capabilities().output` shows `["html", "svg"]` and `saveOutput` can be used.
|
|
393
|
+
- **View (`view`).** The AI passes a `view` (a JSON object) to `read_image` to see something less than the whole. That can be one part, one moment, one branch and so on, and the plugin decides what the fields mean. The core passes the object as is to `renderOutput(state, { format, revision, view })`. Without `view`, the plugin produces the whole, as before.
|
|
394
|
+
- To accept views, declare them in `views` of `describe()`. If you do not declare them, the core rejects `view` and does not pass it to the plugin. The AI reads this list from `describe_document` and uses it, so write `summary`, the `input` descriptions and `example` so that the AI can copy them as they are.
|
|
395
|
+
- Produce the SVG of that view. For one part, set `viewBox`, `width` and `height` to that part. The core draws the image at `size` (the longest side), so the part shows in more detail.
|
|
396
|
+
- What the core filters first: anything that is not an object, anything over 4,096 bytes, and field names that are not in `input` of `views` (it rejects them and suggests a close name). So every field that reaches the plugin has a declared name.
|
|
397
|
+
- What the plugin filters: the values. For a target that does not exist, return `{ error: "TARGET_NOT_FOUND", summary }`. For a wrong kind or range, return `{ error: "INVALID_INPUT", summary }`. Also reject combinations of fields that cannot be used together. In `summary`, write what was wrong and which values would work. **Do not ignore an unknown value and produce the whole image.** The AI would then believe it saw a part.
|
|
398
|
+
- The plugin chooses field names, but use the same name for the same meaning: `piece` (a piece id from splitting into four), `region` (`{ x, y, w, h }`), `time` (seconds), `node` (record id), `depth` (number of levels).
|
|
399
|
+
- If you produce svg, the plugin does not have to make PNG. The core draws the svg and saves it as PNG (`capabilities().output` then also shows `"png"`), and the AI gets the same picture as image content through `read_image`. Put outside images inside the picture as `data:` addresses. If there is an `<image>` that points to a file path or an internet address, the core does not make the PNG. If you do not paint a background, the empty areas of the PNG are transparent.
|
|
400
|
+
|
|
401
|
+
### 3.7 How the AI reads a plugin
|
|
402
|
+
|
|
403
|
+
The AI cannot see the plugin's code. What the AI knows about a plugin is only what is listed below. The description comes in two levels. Level 1 is a summary of the installed plugins, and level 2 is the detailed manual and samples of each plugin. Neither is always included in the MCP instructions. This keeps the instructions the same length as more plugins are added.
|
|
404
|
+
|
|
405
|
+
1. **`list_plugins` (level 1 summary).** For each installed plugin it shows `title`, `about`, all of `examples` and `requires`, plus `manual: true` if there is a manual and `samples` (id and title) if there are samples. The AI reads this when it creates a new work, and during work when another screen seems needed, and then suggests suitable plugins and combinations to the person. So write `about` and `examples` in the words a person would use.
|
|
406
|
+
2. **`describe_document`.** The AI calls it when it first opens a work. `guides` shows the `aiGuide` once for each plugin that has an instance in the work, and the `operations` and `markGuide` of the editing instance appear together with descriptions of the core operations (`core.memo.add`, `core.memo.update`, `core.memo.remove`, `core.intent.set`). When a plugin is added with `add_instance`, the AI also gets its `aiGuide` in that response. In `aiGuide`, write short and clear text on what to write where on this screen and what to ask the person first. The AI reads the operation names, input fields and examples, and builds the `steps` of `apply_operation`. In the `input` descriptions, write the shape of each field (whether it is an id or text, and what happens if it is left out), and in `example`, put a list of operations that can be sent as is.
|
|
407
|
+
3. **`read_plugin_manual` (level 2).** The manual text that the manifest's `manual` points to, and the samples in `samples` (section 7.8). When the person asks "How do I use this plugin?", the AI reads this, sums it up and answers. The person sees the same text with [설명서] (Manual) in the plugin window of the host screen.
|
|
408
|
+
4. **`read_concept`.** This is the `text` of `project`. The AI reads ids from this text and uses them in the next operation.
|
|
409
|
+
5. **The `summary` of a response and the `summary` of a failure.** The AI reads the failure sentence and sends again. Include how to fix it.
|
|
410
|
+
|
|
411
|
+
Put the name people see (`title`), the introduction (`about`, `examples`) and the manual and samples (`manual`, `samples`) in the manifest and the package files. Put how to use the plugin (`aiGuide`, `operations`) in `describe()`. This is because the registry site and the core do not run code. They read only the manifest and the files to show lists and manuals.
|
|
412
|
+
|
|
413
|
+
**Write the introduction in English (rawdev 2026-11-25).** Write `about` and the `ask` and `does` of `examples` in English. The registry site's list shows this text as is, and the site's text is in English. Use easy words and short sentences. Address the person using the screen as "you", and write `ask` as what that person wants to do, like "I want ...".
|
|
414
|
+
|
|
415
|
+
**Write all guidance text in English (rawdev 2026-11-25 "Set the rule that all guidance text for plugin making must be in English. I will run the sharing site in English.").** This covers not only the introduction but all of the text below.
|
|
416
|
+
|
|
417
|
+
- The name in the manifest (`title`). rawdev 2026-11-25: "Write the title in English too."
|
|
418
|
+
- The introduction in the manifest (`about`, `examples`)
|
|
419
|
+
- The manual (the file that `manual` points to)
|
|
420
|
+
- The names and descriptions of samples (`title` and `about` of `samples`)
|
|
421
|
+
- The AI instructions (`aiGuide` and `markGuide` of `describe()`, and the `summary` and input descriptions of operations)
|
|
422
|
+
- The text on the plugin screen (buttons, guidance sentences, error sentences). English is the base text. On top of it, a screen may show another language that the person chose for the AIC screen (section 4.4, `capabilities().language`).
|
|
423
|
+
|
|
424
|
+
`aic plugin pack` and the site do not check the language of the text, so the plugin maker must keep this rule. The starter template of `aic plugin new` and the official plugins are written in English throughout.
|
|
425
|
+
|
|
426
|
+
### 3.8 Rules you must follow
|
|
427
|
+
|
|
428
|
+
- **Determinism.** Return the same result for the same input. Do not depend on the time, random numbers or global state. Sort lists by id or by a fixed order value, and build objects so that their key order does not change. The core calls the same function many times and trusts that the results are the same.
|
|
429
|
+
- **Do not keep state in globals.** Each call gets a new context (section 3.2).
|
|
430
|
+
- **Reserved names.** Operation names do not start with `core.`. Do not use `memo` or `intent` as a `prefix`. Do not use `aic.link` as a plugin id.
|
|
431
|
+
- **Finish within the limits.** Do not go over 2 seconds per call or 8MB per return value. If a screen may get very many records, make the `text` of `project` readable in a narrowed form with a scope (`scope`).
|
|
432
|
+
- **Do not trust input.** The AI may send wrong fields in `step.input`. Check the shape of each field, and reject with a message that says how to fix it.
|
|
433
|
+
- **Reject text in content that is the same as a temporary name** (section 3.4).
|
|
434
|
+
- **Return failures. Do not throw them.** A thrown error becomes `PLUGIN_FAILURE`, and the AI cannot tell what to fix.
|
|
435
|
+
|
|
436
|
+
## 4. Screen contract
|
|
437
|
+
|
|
438
|
+
### 4.1 iframe limits
|
|
439
|
+
|
|
440
|
+
The screen runs inside an iframe with `sandbox="allow-scripts"`, and the core adds the following CSP to the screen file.
|
|
441
|
+
|
|
442
|
+
```text
|
|
443
|
+
default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data:; font-src data:; connect-src 'none'; form-action 'none'; base-uri 'none'; frame-ancestors 'self'
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
So build the screen as follows.
|
|
447
|
+
|
|
448
|
+
- Write scripts and styles inside `index.html` with `<script>` and `<style>`. Scripts, styles and fonts from other files and CDNs do not load.
|
|
449
|
+
- Put images and fonts in only as `data:` addresses.
|
|
450
|
+
- `fetch`, `XMLHttpRequest` and `WebSocket` are blocked. Ask the host for all data with messages.
|
|
451
|
+
- `<form>` submission does not happen. Take input with a button's `click` or with `keydown`.
|
|
452
|
+
- The sandbox has no `allow-same-origin`, so do not depend on `localStorage` or cookies. Keep screen state, such as what is expanded, in variables, and keep anything that must last in records.
|
|
453
|
+
- Do not use file downloads, new windows, or dialogs such as `alert`. To export to a file, use `renderOutput` and `saveOutput`.
|
|
454
|
+
- Make the screen readable in both the light and dark modes of the host (use `prefers-color-scheme`).
|
|
455
|
+
|
|
456
|
+
### 4.2 Message shapes
|
|
457
|
+
|
|
458
|
+
All messages are sent with `window.postMessage` and carry `aic: 1`. The screen accepts only messages where `e.source === parent` and `e.data.aic === 1`.
|
|
459
|
+
|
|
460
|
+
| Direction | Shape | Meaning |
|
|
461
|
+
| --- | --- | --- |
|
|
462
|
+
| Screen to host | `{ aic: 1, event: "ready", rendered: true }` | The screen has loaded. `rendered: true` is a promise to send `rendered` after drawing |
|
|
463
|
+
| Screen to host | `{ aic: 1, event: "rendered", token }` | The screen finished drawing the `renderToken` of a `readConcept` response |
|
|
464
|
+
| Screen to host | `{ aic: 1, id, method, params }` | A call. `id` is a number the screen chooses, and `method` is a name from section 4.4 |
|
|
465
|
+
| Host to screen | `{ aic: 1, id, result }` | The answer to a call |
|
|
466
|
+
| Host to screen | `{ aic: 1, id, error }` | A failed call. `error` is text for people |
|
|
467
|
+
| Host to screen | `{ aic: 1, event: "change", rev }` | A notice to read again. `rev` is the new revision id or `null` |
|
|
468
|
+
| Host to screen | `{ aic: 1, event: "focus", targets }` | The person clicked a section in the output text. `targets` is the list of keys of that section, and a key is usually a record id set by `prepareGeneration`. The screen makes those records stand out |
|
|
469
|
+
|
|
470
|
+
A rejection answered by the core (`{ ok: false, ... }`) comes as `result`, not `error`. `error` means the host could not handle the call.
|
|
471
|
+
|
|
472
|
+
### 4.3 Order
|
|
473
|
+
|
|
474
|
+
1. At its end, the screen script sends `{ aic: 1, event: "ready", rendered: true }`. If it does not arrive within 5 seconds, the host shows "화면을 올리지 못했습니다" (The screen could not be loaded).
|
|
475
|
+
2. The host sends `{ event: "change", rev }`.
|
|
476
|
+
3. The screen calls `readConcept` and draws with the `body` or `withOthers` it receives.
|
|
477
|
+
4. After drawing, if the response has a `renderToken`, the screen sends it back with `{ event: "rendered", token }`. This tells the host what the person saw. This value is the basis for the person's agreement on the screen (moving instances) and for `shareSelection`, `setPick` and `saveOutput`.
|
|
478
|
+
5. After that, a `change` comes every time a new revision is made. A fix by the person, a fix by the AI, and a reconnection all give the same notice.
|
|
479
|
+
|
|
480
|
+
If several `change` notices come in a short time, collect the ones that arrive while reading, and read again only once after the reading ends.
|
|
481
|
+
|
|
482
|
+
### 4.4 Calls the host accepts
|
|
483
|
+
|
|
484
|
+
| method | params | result |
|
|
485
|
+
| --- | --- | --- |
|
|
486
|
+
| `readConcept` | none, `{ target }` or `{ targets }` | Reading the concept as in section 4.5. On failure, `error` |
|
|
487
|
+
| `readMemos` | `{ ids? }`. Leave it out for the whole memo box | `{ base, intent, memos }`. Each memo has `id`, `deleted`, `text`, `display`, `targets`, `stickers` |
|
|
488
|
+
| `readChanges` | `{ since? }` (revision id) | `{ latest, since, newChanges, myEarlierPending, notices, conflicts, editing, text }` |
|
|
489
|
+
| `readArtifacts` | none, or `{ artifact }` | The output list `{ ok, artifacts }`, or one output as `{ ok, id, sections, missing, ... }` |
|
|
490
|
+
| `applyOperation` | `{ base, steps, resolves?, take?, artifact? }` | The operation response (section 4.6) |
|
|
491
|
+
| `capabilities` | `{}` | `{ edit, selection, conceptSelection?, conceptPick?, output?, language? }` |
|
|
492
|
+
| `shareSelection` | `{ base, role, said?, payload, records }` | `{ ok, selection }`. `role` is `"change"` (a place to change) or `"reference"` (a place to refer to). `base` must be the revision this screen reported with `rendered` |
|
|
493
|
+
| `setPick` | `{ base, payload, records }` or `null` | `{ ok }`. Something the person only selected and has not sent yet. The shape is `shareSelection` without `role` and `said`. `null` clears it |
|
|
494
|
+
| `reportMeasurement` | `{ selection, payload }` | `{ ok }`. `payload.rev` is the revision this screen reported as drawn |
|
|
495
|
+
| `saveOutput` | `{ base, format, scale?, size? }` | `{ ok, output, artifact, fileName, width?, height? }`. The host window downloads the file. Give one of `scale` (1, 2, 4, 8) and `size` (pixels of the longest side, 16 to 4096) only for `format: "png"`. Leave them out for the original size of the SVG |
|
|
496
|
+
|
|
497
|
+
- If `capabilities().edit` is `false`, the screen is a read-only "view" screen (when the person views another instance in the right pane). Hide the buttons that make changes. In this case `applyOperation` is rejected and `rendered` is ignored. Call it once at the start to check.
|
|
498
|
+
- Use `shareSelection` and `reportMeasurement` only when `capabilities().conceptSelection` is true, `setPick` only when `capabilities().conceptPick` is true, and `saveOutput` only when `capabilities().output` has that format. An old host without `conceptPick` does not accept `setPick`, so no answer comes back.
|
|
499
|
+
- **How to use `setPick`.** Call it every time what the person selected on the screen changes (a click, a multiple selection, a deselection), and call it with `null` when nothing is selected any more. You do not have to wait for the answer. The core keeps it only in memory, makes no selection id and does not wake the AI. When the person says "this" or "the selected one" in the conversation, the AI calls `read_selection` and reads it as "화면에서 지금 고른 것(보내지 않음)" (What is selected on the screen now, not sent), and `describeSelection` writes that description. If the same screen sends with `shareSelection`, the core clears the selection, and if the screen changes or the window closes, the host clears it. Selecting does not wake the AI, so for the person to give the AI a task, they press the send button (`shareSelection`) as they do now.
|
|
500
|
+
- **The language of the AIC screen (`capabilities().language`).** The person chooses the language of the AIC screen, and the host passes it to the plugin screen as `"ko"` or `"en"`. The field is optional: an old host does not send it. English stays the required base text of a plugin (section 3.7). If you want, add screen text in other languages and show it when `language` matches. For any other value, or when the field is missing, show English. Only the text of the screen (`ui/index.html`) may follow the language. The manifest, the manual, the AI guidance and the text the logic returns (summaries, reject messages) stay in English, because the AI reads them and the logic does not know the language. When the person changes the language the page is loaded again, so read the value once at the start.
|
|
501
|
+
- **Recommended: show a box to tell the AI as soon as something is selected.** When the person selects something on the screen that `shareSelection` can send (a node, a line, a piece, an area, a part, an element, a range), show a small text box and a [Send] button right then, without the person opening a side panel or clicking an icon first. Put it at the top of the work area, where the eye lands first, for example just under the top row of icons. A box at the bottom of the screen is easy to miss. Hide it when nothing is selected, during another action (dragging, drawing a line), on a read-only screen, and when `capabilities().conceptSelection` is not true. Enter (not while composing Korean or other IME text) or [Send] sends the selection and the words with `shareSelection`. If a side panel has the same box with more choices (a place to change or a place to refer to), both boxes hold the same text and both are cleared after sending. Keep calling `setPick` as before; this box is for sending right now with words. Keep the box small so the work content stays wide.
|
|
502
|
+
|
|
503
|
+
### 4.5 The readConcept response
|
|
504
|
+
|
|
505
|
+
```ts
|
|
506
|
+
interface ScreenConcept {
|
|
507
|
+
ok: true;
|
|
508
|
+
base: string; // The base revision of this response. Use it as base in the next applyOperation
|
|
509
|
+
renderToken?: string; // Send it back with rendered after drawing
|
|
510
|
+
body: unknown; // project().json. My state
|
|
511
|
+
withOthers: unknown; // project().json with other participants' changes that are not yet in the shared history applied on top. The screen usually draws this
|
|
512
|
+
scope: string; // project().scopeLabel
|
|
513
|
+
instance: string; // The instance id of this screen
|
|
514
|
+
editing: { id: string; title: string; kind: 'concept' | 'link' }; // The current editing instance
|
|
515
|
+
myPending: PendingChange[];
|
|
516
|
+
othersPending: PendingChange[];
|
|
517
|
+
notices: Array<{ kind: string; record: string; message?: string }>;
|
|
518
|
+
conflicts: Array<{ id: string; record: string; reason: 'same_record' | 'ref_deleted'; sides: unknown[] }>;
|
|
519
|
+
incomplete?: 'older_plugin'; // This was read with a plugin older than the version that wrote this work
|
|
520
|
+
}
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
- If `editing.id` is different from `instance`, this screen is not the screen being edited now. Operations are rejected, so hide or block the buttons that make changes.
|
|
524
|
+
- The memo text is not in this response. To show memos, call `readMemos`. Draw responses with the same `base` together so they match.
|
|
525
|
+
|
|
526
|
+
### 4.6 How to send what the person changed
|
|
527
|
+
|
|
528
|
+
The person's operations are saved under the same contract as the AI's operations. The screen sends the operations that `plan` receives as they are.
|
|
529
|
+
|
|
530
|
+
```js
|
|
531
|
+
const res = await call('applyOperation', {
|
|
532
|
+
base: concept.base,
|
|
533
|
+
steps: [{ op: 'item.check', input: { item: 'it1', done: true } }],
|
|
534
|
+
});
|
|
535
|
+
if (!res.ok) showError(res.summary ?? res.error);
|
|
536
|
+
await refresh();
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
- The host adds the `requestId` and the instance, and if the response is lost, it sends once more.
|
|
540
|
+
- `base` is the last `base` you read. If the `revision` of the response to what you just wrote is later, use that. If you send a `base` earlier than the end of your own history, it is rejected with `STALE_BASE`.
|
|
541
|
+
- A success response is `{ ok: true, revision, ids, created, summary, notices, conflicts, ... }` and a failure is `{ ok: false, error, summary, reason? }`. On failure, show `summary` to the person and read again.
|
|
542
|
+
- If you put several operations in one request, they are saved together or rejected together. To point to something newly made in the same request, give `as: "$name"`.
|
|
543
|
+
- **Resolving conflicts.** If two participants change the same record in different ways, a conflict appears in `conflicts` of the response and of `readConcept`. To let the person choose, send `{ base, steps: [], resolves: [conflict ids], take: "mine" }` or `take: "theirs"`. The revision of the side not chosen is withdrawn as a whole. Conflicts tied to the same revision must be resolved together, so put all their ids in `resolves`.
|
|
544
|
+
|
|
545
|
+
### 4.7 When to redraw
|
|
546
|
+
|
|
547
|
+
- Every time you receive `change`, call `readConcept` again and draw. A `change` also comes after an operation you sent succeeds, but you may also read again right after you get the response.
|
|
548
|
+
- If there is a field where the person is typing, keep that field's text and cursor when you redraw. If input disappears during a redraw, the person feels the screen is broken.
|
|
549
|
+
- While something is being dragged, hold off redrawing and draw when the drag ends.
|
|
550
|
+
|
|
551
|
+
## 5. Versions
|
|
552
|
+
|
|
553
|
+
| What | When to change it | What happens when you change it |
|
|
554
|
+
| --- | --- | --- |
|
|
555
|
+
| `version` | Raise it every time you release fixed code | The moment a higher version first writes to a work, the new version is recorded on that instance of the work |
|
|
556
|
+
| `dataVersion` | Only when you change the shape of record content so that earlier code cannot read it | That instance in works made with the earlier `dataVersion` **does not open** |
|
|
557
|
+
| `protocol` | When the core's protocol version changes | If it differs from the core's protocol version, the core does not load the plugin |
|
|
558
|
+
|
|
559
|
+
**`version`.** Each instance of a work records the version of the plugin that last wrote to it and the fingerprint of the logic file.
|
|
560
|
+
|
|
561
|
+
- When you write with a higher version of the plugin, the core rewrites the instance's version and fingerprint with the new ones. So a new version must be able to read and change records made by earlier versions. When you add a field, set a default value for when the field is missing.
|
|
562
|
+
- A lower version of the plugin can only read. Writes and creation are rejected with `INCOMPATIBLE_VERSION`, and read responses carry `incomplete: "older_plugin"`.
|
|
563
|
+
|
|
564
|
+
**Why you cannot go back to a lower version.** Because of the rule above, if you switch a plugin to a lower version, you can no longer change works written with the higher version. So `aic plugin install` and `update` do not switch to a lower version. If you must, give `--force`. Do not roll back a version you released by mistake. Release the fixed code as a higher version.
|
|
565
|
+
|
|
566
|
+
**If you change the code under the same version.** When the fingerprint recorded on the instance differs from the fingerprint of the current logic file, the core does not reject. It gives the notice "같은 버전인데 코드가 바뀌었다" (same version, but the code changed). The notice is attached to the instance list of the AI's `describe_document` and to the instance display on the host screen, and it stays until you raise the version. The fingerprint is the sha256 of the logic file alone, so changing only the screen file does not create the notice. During development this notice is normal. When you release, raise the version.
|
|
567
|
+
|
|
568
|
+
**`dataVersion`.** There is no feature yet to move a work to a new shape. If you change `dataVersion`, that screen in works made earlier does not open, and on start the core reports each "열리지 않는 작업" (work that cannot be opened) on its own line. So avoid changing it. For something like adding a field, raise only `version` and make the new code read the old shape too.
|
|
569
|
+
|
|
570
|
+
**`protocol`.** It is `"0.1"` now. While it is an experimental version, the core accepts a plugin only if the numbers match up to the middle one. When the core raises its protocol version, that core skips `"0.1"` plugins and reports the reason in one line on start. If you leave `protocol` out, it is not checked, but you cannot publish to the site.
|
|
571
|
+
|
|
572
|
+
## 6. Dependencies (dependencies)
|
|
573
|
+
|
|
574
|
+
```json
|
|
575
|
+
{ "dependencies": { "yourname.calendar": "^0.2.0" } }
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
- Only four kinds of version range are accepted: `1.2.3` (exactly that version), `^1.2.3`, `~1.2.3`, `>=1.2.3`. The meaning is the same as in npm. `^1.2.3` goes up to below 2.0.0, `^0.2.3` up to below 0.3.0, `^0.0.3` up to below 0.0.4, and `~1.2.3` up to below 1.3.0. A prerelease version matches only when the range's version is a prerelease of the same three numbers.
|
|
579
|
+
- If a plugin it depends on is not installed or does not match the range, the core does not load this plugin.
|
|
580
|
+
- A dependency only guarantees "it is installed alongside". There is no way to share code. Use it to declare a companion plugin made to be used together, switching between two screens in one work.
|
|
581
|
+
- Do not list the plugin itself or `aic.link`.
|
|
582
|
+
|
|
583
|
+
## 7. Steps to make and test
|
|
584
|
+
|
|
585
|
+
### 7.1 Make a starter template
|
|
586
|
+
|
|
587
|
+
```bash
|
|
588
|
+
aic plugin new yourname.checklist yourname-checklist
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
`aic plugin new <id> [folder] [--title <name>]` makes a starter template. If you leave out the folder, it is `./plugin-<last part of the id>`. The template contains `manifest.json`, a plain JavaScript logic file `logic.js` used without a build, the screen `ui/index.html`, the manual `docs/manual.md`, `LICENSE` (the Apache-2.0 text) and `README.md`. Choose the first part of the id as your account name on the registry site. Even a plugin you will not publish to the site must have the same shape.
|
|
592
|
+
|
|
593
|
+
The starter template is a "list" plugin that runs if you install it as it is. It handles named lines (type and `prefix` are `item`, content is `{ title, order }`), and it has four operations: `item.add`, `item.update`, `item.move`, `item.remove`. The screen has buttons to add, edit, move up and down, and remove, plus buttons to choose a side in a conflict. Change this template into the screen you want. The command puts the id into the manifest's `id`, `PLUGIN_ID` in `logic.js`, the screen's `<title>`, and the first line of `README.md` and the manual. It puts the name (`title`) from `--title`, or the last part of the id if you do not give it. It writes the manifest's `protocol` as the core protocol version that the command matches. To change the name, change the manifest's `title` and `TITLE` in `logic.js` together. Also raise `VERSION` at the top of `logic.js` together with the manifest's `version`. If the folder already exists and is not empty, the command refuses.
|
|
594
|
+
|
|
595
|
+
### 7.2 Change it
|
|
596
|
+
|
|
597
|
+
1. Write the `title`, `about` and `examples` in `manifest.json` to fit the screen the person wants.
|
|
598
|
+
2. In the logic file, decide the record types and the shape of their content. Put everything needed to redraw the record in its content.
|
|
599
|
+
3. Decide the operations. Names shaped like `type.verb` (`item.add`, `item.move`) are easy to read. Make what the person does on the screen and what the AI does use the same operations.
|
|
600
|
+
4. In the `operations` of `describe()`, write descriptions of the input fields and examples that can be sent as they are. In `aiGuide`, write what goes where and what to ask the person first.
|
|
601
|
+
5. Make the `text` (what the AI reads) and the `json` (data the screen draws) of `project`.
|
|
602
|
+
6. Write the rules for the whole state in `validate`.
|
|
603
|
+
7. Make the screen as described in section 4.
|
|
604
|
+
8. Write the manual in `docs/manual.md`, and export a work you have tried as a sample (section 7.8).
|
|
605
|
+
|
|
606
|
+
### 7.3 Check and install
|
|
607
|
+
|
|
608
|
+
```bash
|
|
609
|
+
aic plugin pack yourname-checklist
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
`aic plugin pack [folder]` runs the same checks as the site and makes a bundle file (`<id>-<version>.tgz`). It also loads the logic into the isolated runner to see whether `describe()` answers and whether it gives no reserved operation names. If something still needs fixing before you can publish to the site, it also prints "사이트에 올리기 전에 고친다" (fix before publishing to the site).
|
|
613
|
+
|
|
614
|
+
```bash
|
|
615
|
+
aic plugin install yourname-checklist
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
`aic plugin install <folder>` bundles the folder and installs it right away. The install location is `plugins/plugin-<id>/` in the data folder (the data folder is `%LOCALAPPDATA%\aic` on Windows and `~/.aic` elsewhere, and you change it with `AIC_HOME` or `--data`). It installs only what passes the same checks as `pack`. If fields needed only to publish to the site are missing, it only gives a notice. Installing the same version again overwrites it. If the version is lower than the one already installed, it does not install.
|
|
619
|
+
|
|
620
|
+
### 7.4 Restart the core
|
|
621
|
+
|
|
622
|
+
The core reads plugins only when it starts. If the core is running, the install command asks whether to restart it. Give `--restart` to restart without asking. To do it yourself, do the following.
|
|
623
|
+
|
|
624
|
+
```bash
|
|
625
|
+
aic stop
|
|
626
|
+
aic start --background
|
|
627
|
+
aic status
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
The plugin list of `aic status` must show `yourname.checklist 0.1.0 (Checklist) [설치함]` (`[설치함]` means installed). If it does not, start the core in the foreground (`aic start`) and read the "플러그인 ... 을 건너뜀" (skipping plugin ...) line printed on start. Manifest check, `protocol` and dependency problems appear in that line. If the AI chat window does not respond after the restart, reconnect the MCP server `aic` in the chat window.
|
|
631
|
+
|
|
632
|
+
### 7.5 Make a work and try it
|
|
633
|
+
|
|
634
|
+
1. Open the screen with `aic open`.
|
|
635
|
+
2. In the AI chat window, say "Make a new work with yourname.checklist". The AI makes it by giving `plugin: "yourname.checklist"` to `create_document`. To add to an existing work, give `package` to `add_instance`.
|
|
636
|
+
3. In the browser screen, try every operation the person does (add, edit, remove), and see whether the screen redraws and whether error text appears.
|
|
637
|
+
4. Check the case where another participant changes the same thing. While the person edits on the screen, have the AI change the same record.
|
|
638
|
+
|
|
639
|
+
### 7.6 Have the AI work with the plugin
|
|
640
|
+
|
|
641
|
+
The goal of this test is to see whether the AI can work from the guidance alone, without seeing the code.
|
|
642
|
+
|
|
643
|
+
1. Have the AI call `describe_document`, and see whether the operation list and examples are in a shape that can be used as they are.
|
|
644
|
+
2. The person gives a task in their usual way of speaking ("Write down five tasks for this week"). See whether the AI sends `apply_operation` correctly in one go.
|
|
645
|
+
3. If the AI got a rejection, see whether it could fix and resend by reading only the `summary`. If it could not, fix the rejection text, the descriptions in `operations`, and the `aiGuide`.
|
|
646
|
+
4. See whether the AI describes the state of the screen correctly by reading only the text of `read_concept`.
|
|
647
|
+
|
|
648
|
+
After a fix, repeat `aic plugin install <folder>` and the core restart. If you reinstall with the same version, works you already made get the notice "같은 버전인데 코드가 바뀌었다" (same version, but the code changed) (section 5). During development you can leave it.
|
|
649
|
+
|
|
650
|
+
### 7.7 Common failures
|
|
651
|
+
|
|
652
|
+
| What you see | Cause and how to fix it |
|
|
653
|
+
| --- | --- |
|
|
654
|
+
| `PLUGIN_FAILURE` such as `plugin has no plan` | That function is not in `globalThis.__aicPlugin`. Check that you put the object there at the end of the file and that you did not use `export` |
|
|
655
|
+
| `random is not available`, or an error that `Date` is not defined | You cannot use time or random numbers (section 3.2) |
|
|
656
|
+
| `플러그인이 한도를 넘었다` (the plugin went over a limit) | It went over one of 2 seconds, 64MB, or 1MB of stack. Look for an endless loop or deep recursion |
|
|
657
|
+
| `새 record $x 에 id 앞 글자가 없다` (new record $x has no id prefix) | Write a `prefix` in the change for the new record |
|
|
658
|
+
| `플러그인이 없는 record ... 을 바꾸려 했다` (the plugin tried to change a record that does not exist) | If it is not an existing id, use a temporary name that starts with `$` |
|
|
659
|
+
| `새 record 의 id ... 이 이미 쓰인 id 와 겹친다` (the id of the new record clashes with an id already in use) | The `prefix` runs into another `prefix` followed by a number. Change it to a name that does not end in a number |
|
|
660
|
+
| The core does not start | `describe()` throws or gives a `core.` operation name. Check with `aic plugin pack` |
|
|
661
|
+
| The screen is empty with "화면을 올리지 못했습니다" (could not load the screen) | You did not send `ready`, or the script was blocked by the CSP. Look at the console in the browser developer tools |
|
|
662
|
+
| A button on the screen does nothing | It relied on `<form>` submission. Handle it with `click` |
|
|
663
|
+
|
|
664
|
+
### 7.8 Make the manual and samples
|
|
665
|
+
|
|
666
|
+
The manual and samples are the second level of explanation (section 3.7). The AI reads them with `read_plugin_manual`, and the person reads them with [설명서] (Manual) in the plugin window. The plugin runs and can be published to the site without either of them, but without a manual `aic plugin pack` and `publish` print a one-line notice. If the screen has hard operations, include samples too.
|
|
667
|
+
|
|
668
|
+
**Manual.** Write the path of a Markdown file (`docs/manual.md` in the starter template) in the manifest's `manual`, and write in that file. It is text the person and the AI read together.
|
|
669
|
+
|
|
670
|
+
- Describe every feature of the screen. It is easy to read if, for each feature, you write what the person does on the screen side by side with the operation the AI does (like the table in the starter template).
|
|
671
|
+
- Write the order of working together, what to ask the person first, and where people often get stuck.
|
|
672
|
+
- The screen draws only headings, lists, tables, code, bold text and inline code. HTML shows as plain text, an image shows only as the text `[그림: description]` ("그림" means image), and a link only as "text (address)". Images at outside addresses are not loaded, so write explanations as text.
|
|
673
|
+
- Up to 50,000 characters. If it is longer, `aic plugin pack` and the site reject it.
|
|
674
|
+
|
|
675
|
+
**Samples.** A sample is not a story written by hand. It is the record of a work actually done in AIC. Only a record of an actual run lets the AI and the person trust it and follow it.
|
|
676
|
+
|
|
677
|
+
1. Install the plugin, make a work, and have the person and the AI actually use it together. It may be an example of using it with other plugins. The AI copies what the person says into `human_words`, so it stays in the sample.
|
|
678
|
+
2. Find the work id (after checking with `aic status` that the core is running, from the AI's `list_documents` or from the screen) and export it.
|
|
679
|
+
|
|
680
|
+
```bash
|
|
681
|
+
aic export-sample doc-3 --out yourname-checklist/samples/first.json
|
|
682
|
+
```
|
|
683
|
+
|
|
684
|
+
It takes the history of that work from the running core with the human key, as an `aic-sample/1` file. The real names of participants are replaced with "사람" (person) and "AI" ("사람 2" (person 2) when there are several of the same kind). For external connections it puts only the connection name, and leaves out connection definitions, authentication values, secret values, and the values of connection settings the person chose. Run records of external connections keep only the kind and the status. It also leaves out the name of the AI program, times, and request ids.
|
|
685
|
+
3. The text written in the work goes in as it is. Open the file and check that there is no personal information or text that must not be published. If there is, do not edit that work. Do it again without such text and export again. If you edit the file by hand, it may fail the shape check.
|
|
686
|
+
4. List it in the manifest's `samples`.
|
|
687
|
+
|
|
688
|
+
```json
|
|
689
|
+
"samples": [
|
|
690
|
+
{ "id": "first", "title": "Write five tasks", "about": "The AI writes down the tasks you name, and you change their order", "file": "samples/first.json" }
|
|
691
|
+
]
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
5. Check with `aic plugin pack`. A sample file can be up to 200,000 characters, and there can be up to five. It must have the `aic-sample/1` shape, and this plugin must be in its list of plugins used.
|
|
695
|
+
|
|
696
|
+
The AI reads a sample with `read_plugin_manual({ package, sample })` as turn-by-turn text, one revision at a time, in the lines "사람: (what was said)" (person), "AI: (summary of what it did)" and "화면 변화" (screen changes). It gets the original operations only with `form: "json"`. On a computer where another plugin the sample used is not installed, "이 예제는 X 도 씁니다(설치되지 않음)" (this sample also uses X (not installed)) appears with it.
|
|
697
|
+
|
|
698
|
+
## 8. Publishing to the registry site
|
|
699
|
+
|
|
700
|
+
### 8.1 Log in and publish
|
|
701
|
+
|
|
702
|
+
```bash
|
|
703
|
+
aic login
|
|
704
|
+
aic plugin publish yourname-checklist
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
- `aic login` uses GitHub login. When the command shows a short code, the person enters that code in the browser, and the command receives the site's key and stores it in `registry.json` in the data folder. To remove the key, use `aic logout`.
|
|
708
|
+
- The site address is looked up in this order: `--registry <address>`, the environment variable `AIC_REGISTRY`, then `registry.json`. If none of the three is set, it uses the default address written in the package. The default address is the public site `https://aic.aiakiv.net` (rawdev 2026-11-18). To use a test site started on this computer, give it like `--registry http://127.0.0.1:4330`.
|
|
709
|
+
- `aic plugin publish [folder]` runs the same checks as `pack`, makes the bundle, and publishes it. The person does the login and the choice of account. The AI tells the person the command and lets the person run it.
|
|
710
|
+
|
|
711
|
+
### 8.2 Site rules
|
|
712
|
+
|
|
713
|
+
- **The first part of the id is your account name.** You choose the account name when you first sign up, and you cannot change it. You cannot publish an id that starts with another account name. Only official plugins use `aic.`.
|
|
714
|
+
- **A version once published cannot be changed or deleted.** Works made with that version must open again. To fix something, raise the version and publish it new. The same version of the same id is not published twice.
|
|
715
|
+
- Put a "do not use" mark on a version published by mistake on the site (the site's `POST /api/plugins/<id>/<version>/deprecate`. The `aic` command does not have this yet). A marked version is not chosen for new installs, but you can still get it if you ask for that version by number.
|
|
716
|
+
- Publishing is limited to 30 times per hour per account.
|
|
717
|
+
- The site does not run plugin code. The list, search and the AI's recommendations are made from the manifest's `title`, `about`, `examples` and `requires`.
|
|
718
|
+
|
|
719
|
+
### 8.3 Bundle rules
|
|
720
|
+
|
|
721
|
+
| Rule | Value |
|
|
722
|
+
| --- | --- |
|
|
723
|
+
| Format | tar compressed with gzip (`.tgz`). The file name is `<id>-<version>.tgz` |
|
|
724
|
+
| Size | Bundle file up to 5MB, and the total size of the unpacked files also up to 5MB |
|
|
725
|
+
| Number of files | Up to 200 |
|
|
726
|
+
| Files that can go in | `manifest.json`, the manifest's `logic` file, files directly under `ui/` (including the icon), `LICENSE`, `README.md`, and the files the manifest's `manual` and `samples` point to |
|
|
727
|
+
| Icon | The file the manifest's `icon` points to must exist and pass the rules in section 2.2. If there is no icon, it only gives a notice and does not reject |
|
|
728
|
+
| Manual and samples | Manual 50,000 characters, one sample 200,000 characters, up to five samples. If there is no manual, it only gives a notice and does not reject |
|
|
729
|
+
| More things needed to publish to the site | The manifest's `protocol`, `license`, `title`, `about`, and the `LICENSE` file |
|
|
730
|
+
| Dependencies | The plugins in `dependencies` must be on the site, with at least one version that matches the range |
|
|
731
|
+
|
|
732
|
+
- `aic plugin pack` makes the bundle. A hand-made bundle is rejected if it has links, paths that point outside the folder, or two identical paths.
|
|
733
|
+
- Other people get it with `aic plugin install yourname.checklist` or `aic plugin install yourname.checklist@0.1.0`. Dependencies are fetched too.
|
|
734
|
+
|
|
735
|
+
## 9. Checklist before publishing
|
|
736
|
+
|
|
737
|
+
**manifest**
|
|
738
|
+
|
|
739
|
+
- [ ] The first part of `id` is your account name.
|
|
740
|
+
- [ ] `version` is higher than the versions already published.
|
|
741
|
+
- [ ] You did not change `dataVersion`. If you did, the person knows that earlier works will not open and agreed.
|
|
742
|
+
- [ ] `protocol` is `"0.1"`.
|
|
743
|
+
- [ ] `title`, `license` and `about` are present, and `examples` are written as what a person would actually say. `title`, `about` and `examples` are in English.
|
|
744
|
+
- [ ] The manual, the sample names and descriptions, the AI guidance text, and the screen text are in English (section 3.7, "Write all guidance text in English").
|
|
745
|
+
- [ ] `requires` matches the actual runtime environment.
|
|
746
|
+
- [ ] `ui` is `"ui/index.html"`.
|
|
747
|
+
- [ ] `icon` is `"ui/icon.svg"`, the icon shows what this screen is even when small, and it is visible on both light and dark screens.
|
|
748
|
+
- [ ] There is a `LICENSE` file.
|
|
749
|
+
|
|
750
|
+
**Manual and samples**
|
|
751
|
+
|
|
752
|
+
- [ ] The manual in `manual` covers every feature of the screen, the operations the person and the AI do, and where people often get stuck.
|
|
753
|
+
- [ ] If there are hard operations, a sample exported with `aic export-sample` is in `samples`.
|
|
754
|
+
- [ ] Sample files have no personal information or text that must not be published.
|
|
755
|
+
|
|
756
|
+
**Logic**
|
|
757
|
+
|
|
758
|
+
- [ ] The `id` and `version` of `describe()` match the manifest.
|
|
759
|
+
- [ ] Operation names do not start with `core.`, and `prefix` is not `memo` or `intent` and does not end in a number.
|
|
760
|
+
- [ ] It does not use `Date`, `Math.random` or global state.
|
|
761
|
+
- [ ] All functions are present. If it makes no output, `prepareGeneration` returns `UNSUPPORTED_CAPABILITY` and `interpretSelection` returns empty candidates.
|
|
762
|
+
- [ ] Expected rejections are returned as `{ error, summary }` instead of thrown, and `summary` says how to fix it.
|
|
763
|
+
- [ ] It rejects input text that equals a temporary name of this request.
|
|
764
|
+
- [ ] It also reads records made by earlier versions.
|
|
765
|
+
|
|
766
|
+
**AI guidance**
|
|
767
|
+
|
|
768
|
+
- [ ] Reading only `aiGuide`, the AI knows what to write where.
|
|
769
|
+
- [ ] Sending the `example` of `operations` as it is succeeds.
|
|
770
|
+
- [ ] The `text` of `project` has an id for every record.
|
|
771
|
+
|
|
772
|
+
**Screen**
|
|
773
|
+
|
|
774
|
+
- [ ] Scripts and styles are inside `index.html`, and it does not load outside files.
|
|
775
|
+
- [ ] It sends `ready` and `rendered`.
|
|
776
|
+
- [ ] If `capabilities().edit` is false or it is not the editing instance, it hides the editing buttons.
|
|
777
|
+
- [ ] It shows rejection text to the person.
|
|
778
|
+
- [ ] Recommended: when the person selects something that can be sent, a box to tell the AI appears at the top of the work area right away (section 4.4).
|
|
779
|
+
- [ ] It is readable on both light and dark screens.
|
|
780
|
+
|
|
781
|
+
**Tests**
|
|
782
|
+
|
|
783
|
+
- [ ] `aic plugin pack` finishes without "사이트에 올리기 전에 고친다" (fix before publishing to the site).
|
|
784
|
+
- [ ] After `aic plugin install <folder>` and a core restart, it shows in `aic status`.
|
|
785
|
+
- [ ] The person on the screen and the AI in the chat window have both changed the same work.
|
|
786
|
+
- [ ] The bundle contains no personal work data or secret values.
|
|
787
|
+
|
|
788
|
+
## Appendix. A small example: Checklist
|
|
789
|
+
|
|
790
|
+
The logic file and screen below were checked by running them in the real core and a browser. They add to-do items (`item`), mark them as done, and remove them.
|
|
791
|
+
|
|
792
|
+
```js
|
|
793
|
+
// Logic of the checklist. It is one script file and does not use import, export or require.
|
|
794
|
+
(() => {
|
|
795
|
+
const fail = (error, summary) => ({ error, summary });
|
|
796
|
+
const items = (state) =>
|
|
797
|
+
Object.values(state.records)
|
|
798
|
+
.filter((r) => r.type === 'item')
|
|
799
|
+
.sort((a, b) => a.content.pos - b.content.pos || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
800
|
+
const textOf = (input, ctx) => {
|
|
801
|
+
const t = typeof input.text === 'string' ? input.text.trim() : '';
|
|
802
|
+
return t === '' || ctx.tempNames.includes(t) ? null : t;
|
|
803
|
+
};
|
|
804
|
+
const need = (state, id) => {
|
|
805
|
+
const r = typeof id === 'string' ? state.records[id] : undefined;
|
|
806
|
+
return r && r.type === 'item' ? r : null;
|
|
807
|
+
};
|
|
808
|
+
|
|
809
|
+
const OPS = {
|
|
810
|
+
'item.add'(state, step, ctx) {
|
|
811
|
+
const text = textOf(step.input ?? {}, ctx);
|
|
812
|
+
if (text === null) return fail('INVALID_INPUT', 'text is empty or equals a temporary name of this request');
|
|
813
|
+
const list = items(state);
|
|
814
|
+
const pos = list.length ? list[list.length - 1].content.pos + 1 : 1;
|
|
815
|
+
const id = step.as ?? `$~${ctx.stepIndex}.0`;
|
|
816
|
+
return { changes: [{ id, type: 'item', prefix: 'it', after: { text, done: false, pos } }], summary: `Added item (${id}): ${text}.` };
|
|
817
|
+
},
|
|
818
|
+
'item.check'(state, step) {
|
|
819
|
+
const r = need(state, step.input?.item);
|
|
820
|
+
if (!r) return fail('TARGET_NOT_FOUND', `Cannot find item ${String(step.input?.item)}`);
|
|
821
|
+
const done = step.input?.done !== false;
|
|
822
|
+
return { changes: [{ id: r.id, type: 'item', after: { ...r.content, done } }], summary: `${r.id} ${done ? 'done' : 'reopened'}.` };
|
|
823
|
+
},
|
|
824
|
+
'item.remove'(state, step) {
|
|
825
|
+
const r = need(state, step.input?.item);
|
|
826
|
+
if (!r) return fail('TARGET_NOT_FOUND', `Cannot find item ${String(step.input?.item)}`);
|
|
827
|
+
return { changes: [{ id: r.id, type: 'item', after: null }], summary: `Removed ${r.id}: ${r.content.text}.` };
|
|
828
|
+
},
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
globalThis.__aicPlugin = {
|
|
832
|
+
describe: () => ({
|
|
833
|
+
id: 'yourname.checklist',
|
|
834
|
+
version: '0.1.0',
|
|
835
|
+
title: 'Checklist',
|
|
836
|
+
aiGuide: 'This screen is a checklist where to-dos are written one per line. Write the to-dos the person mentions with item.add, and mark finished ones with item.check. Ask the person before removing anything.',
|
|
837
|
+
markGuide: 'Item text is plain text. Marks in text are not used.',
|
|
838
|
+
operations: [
|
|
839
|
+
{ op: 'item.add', input: { text: 'one line of to-do text' }, summary: 'Adds an item at the end', example: [{ op: 'item.add', as: '$a', input: { text: 'Choose a cover' } }] },
|
|
840
|
+
{ op: 'item.check', input: { item: 'item id', done: 'true if finished, false to reopen. true if left out' }, summary: 'Marks whether it is finished' },
|
|
841
|
+
{ op: 'item.remove', input: { item: 'item id' }, summary: 'Removes the item' },
|
|
842
|
+
],
|
|
843
|
+
}),
|
|
844
|
+
initialize: () => [],
|
|
845
|
+
plan(state, step, ctx) {
|
|
846
|
+
const run = OPS[step.op];
|
|
847
|
+
return run ? run(state, step, ctx) : fail('INVALID_INPUT', `Unknown operation ${step.op}. See the operation list in describe_document`);
|
|
848
|
+
},
|
|
849
|
+
validate(candidate, changed) {
|
|
850
|
+
const out = [];
|
|
851
|
+
for (const id of changed) {
|
|
852
|
+
const r = candidate.records[id];
|
|
853
|
+
if (r && r.type === 'item' && typeof r.content.text !== 'string') out.push({ level: 'error', code: 'bad_item', record: id, message: `${id} has no text` });
|
|
854
|
+
}
|
|
855
|
+
return out;
|
|
856
|
+
},
|
|
857
|
+
project(state, scope, mine) {
|
|
858
|
+
const list = items(state);
|
|
859
|
+
const starred = new Set(mine.flatMap((p) => p.changes.map((c) => c.record)));
|
|
860
|
+
const lines = list.map((r) => `- (${r.id})${starred.has(r.id) ? ' *' : ''} [${r.content.done ? 'x' : ' '}] ${r.content.text}`);
|
|
861
|
+
return {
|
|
862
|
+
text: lines.length ? lines.join('\n') : 'The list is empty. Write the to-dos the person mentions with item.add.',
|
|
863
|
+
json: { items: list.map((r) => ({ id: r.id, ...r.content })) },
|
|
864
|
+
scopeLabel: 'Read everything',
|
|
865
|
+
};
|
|
866
|
+
},
|
|
867
|
+
extractRefs: () => [],
|
|
868
|
+
resolveTarget(state, target) {
|
|
869
|
+
const r = need(state, target.id);
|
|
870
|
+
return r ? { found: true, label: `Item ${r.id}: ${r.content.text}` } : { found: false };
|
|
871
|
+
},
|
|
872
|
+
prepareGeneration: () => fail('UNSUPPORTED_CAPABILITY', 'The checklist does not make output'),
|
|
873
|
+
interpretSelection: () => ({ candidates: [] }),
|
|
874
|
+
};
|
|
875
|
+
})();
|
|
876
|
+
```
|
|
877
|
+
|
|
878
|
+
If you send `[{ op: "item.add", as: "$a", input: { text: "Choose a cover" } }, { op: "item.add", input: { text: "Write the table of contents" } }, { op: "item.check", input: { item: "$a" } }]` to this logic, the response's `ids` is `{ "$a": "it1" }`, `created` is `["it1", "it2"]`, and the summary is "Added item (it1): Choose a cover. Added item (it2): Write the table of contents. it1 done.", and `read_concept` shows the following text.
|
|
879
|
+
|
|
880
|
+
```text
|
|
881
|
+
- (it1) * [x] Choose a cover
|
|
882
|
+
- (it2) * [ ] Write the table of contents
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
The skeleton of the screen is as follows. It reads with `readConcept` and draws, sends what the person changed with `applyOperation`, and reads again when a `change` arrives.
|
|
886
|
+
|
|
887
|
+
```html
|
|
888
|
+
<!doctype html>
|
|
889
|
+
<html lang="en">
|
|
890
|
+
<head>
|
|
891
|
+
<meta charset="utf-8">
|
|
892
|
+
<style>
|
|
893
|
+
body { font: 14px sans-serif; margin: 12px; }
|
|
894
|
+
.done { text-decoration: line-through; color: #777; }
|
|
895
|
+
#error { color: #b00020; }
|
|
896
|
+
</style>
|
|
897
|
+
</head>
|
|
898
|
+
<body>
|
|
899
|
+
<p id="error" hidden></p>
|
|
900
|
+
<ul id="list"></ul>
|
|
901
|
+
<div id="add"><input id="text" placeholder="To-do"> <button id="addButton">Add</button></div>
|
|
902
|
+
<script>
|
|
903
|
+
let nextId = 1;
|
|
904
|
+
const waiting = new Map();
|
|
905
|
+
let concept = null;
|
|
906
|
+
let canEdit = true;
|
|
907
|
+
|
|
908
|
+
// Send a call to the host and wait for the answer.
|
|
909
|
+
function call(method, params) {
|
|
910
|
+
return new Promise((resolve, reject) => {
|
|
911
|
+
const id = nextId++;
|
|
912
|
+
waiting.set(id, { resolve, reject });
|
|
913
|
+
parent.postMessage({ aic: 1, id, method, params }, '*');
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
window.addEventListener('message', (e) => {
|
|
918
|
+
if (e.source !== parent) return;
|
|
919
|
+
const d = e.data;
|
|
920
|
+
if (typeof d !== 'object' || d === null || d.aic !== 1) return;
|
|
921
|
+
if (d.event === 'change') return refresh();
|
|
922
|
+
if (d.event === 'focus') return;
|
|
923
|
+
const w = waiting.get(d.id);
|
|
924
|
+
if (!w) return;
|
|
925
|
+
waiting.delete(d.id);
|
|
926
|
+
if (d.error) w.reject(new Error(d.error));
|
|
927
|
+
else w.resolve(d.result);
|
|
928
|
+
});
|
|
929
|
+
|
|
930
|
+
async function refresh() {
|
|
931
|
+
try {
|
|
932
|
+
concept = await call('readConcept');
|
|
933
|
+
render();
|
|
934
|
+
if (typeof concept.renderToken === 'string') parent.postMessage({ aic: 1, event: 'rendered', token: concept.renderToken }, '*');
|
|
935
|
+
} catch (err) {
|
|
936
|
+
showError(err.message);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
async function send(steps) {
|
|
941
|
+
const res = await call('applyOperation', { base: concept.base, steps }).catch((err) => ({ ok: false, summary: err.message }));
|
|
942
|
+
if (!res.ok) showError(res.summary ?? res.error);
|
|
943
|
+
await refresh();
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
function showError(text) {
|
|
947
|
+
const el = document.getElementById('error');
|
|
948
|
+
el.textContent = text;
|
|
949
|
+
el.hidden = false;
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
function render() {
|
|
953
|
+
document.getElementById('error').hidden = true;
|
|
954
|
+
const view = concept.withOthers ?? concept.body;
|
|
955
|
+
const readOnly = !canEdit || (concept.editing && concept.editing.id !== concept.instance);
|
|
956
|
+
const list = document.getElementById('list');
|
|
957
|
+
list.replaceChildren(...view.items.map((it) => {
|
|
958
|
+
const li = document.createElement('li');
|
|
959
|
+
const box = document.createElement('input');
|
|
960
|
+
box.type = 'checkbox';
|
|
961
|
+
box.checked = it.done;
|
|
962
|
+
box.disabled = readOnly;
|
|
963
|
+
box.addEventListener('change', () => send([{ op: 'item.check', input: { item: it.id, done: box.checked } }]));
|
|
964
|
+
const label = document.createElement('span');
|
|
965
|
+
label.textContent = it.text;
|
|
966
|
+
if (it.done) label.className = 'done';
|
|
967
|
+
li.append(box, ' ', label);
|
|
968
|
+
return li;
|
|
969
|
+
}));
|
|
970
|
+
document.getElementById('add').hidden = readOnly;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
function addItem() {
|
|
974
|
+
const input = document.getElementById('text');
|
|
975
|
+
const text = input.value.trim();
|
|
976
|
+
if (!text) return;
|
|
977
|
+
input.value = '';
|
|
978
|
+
send([{ op: 'item.add', input: { text } }]);
|
|
979
|
+
}
|
|
980
|
+
document.getElementById('addButton').addEventListener('click', addItem);
|
|
981
|
+
document.getElementById('text').addEventListener('keydown', (ev) => {
|
|
982
|
+
if (ev.key === 'Enter' && !ev.isComposing) addItem();
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
parent.postMessage({ aic: 1, event: 'ready', rendered: true }, '*');
|
|
986
|
+
call('capabilities', {}).then((cap) => {
|
|
987
|
+
if (cap && cap.edit === false) {
|
|
988
|
+
canEdit = false;
|
|
989
|
+
if (concept) render();
|
|
990
|
+
}
|
|
991
|
+
}).catch(() => {});
|
|
992
|
+
</script>
|
|
993
|
+
</body>
|
|
994
|
+
</html>
|
|
995
|
+
```
|
|
996
|
+
|
|
997
|
+
This skeleton is cut down to keep it short. A real screen collects the `change` notices that arrive during a read and reads again only once, following the order in section 4.3, and keeps the text of the field being typed in, as described in section 4.7.
|