@kafbit/irsim-connectors 0.5.0 → 0.6.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.
@@ -9,6 +9,7 @@
9
9
 
10
10
  import { randomUUID } from 'node:crypto'
11
11
  import { existsSync } from 'node:fs'
12
+ import { dirname, join } from 'node:path'
12
13
  import { fileURLToPath } from 'node:url'
13
14
  import type { ModApi } from '@commandcode/harness'
14
15
 
@@ -21,6 +22,19 @@ const bridgeBin = (): string => {
21
22
  return typeof value === 'string' && value.trim() !== '' ? value.trim() : 'irsim'
22
23
  }
23
24
 
25
+ const SESSION_CONTEXT =
26
+ 'This project keeps its screens as irsim boards. Load the `irsim-design` skill before you create or edit a board file or design/canvas.json, and the `irsim-workflow` skill before you change what a screen shows. Run `irsim lint` and design_canvas check before you say you are done.'
27
+
28
+ const hasIrsimConfig = (from: string): boolean => {
29
+ let dir = from
30
+ for (;;) {
31
+ if (existsSync(join(dir, '.irsim.json'))) return true
32
+ const parent = dirname(dir)
33
+ if (parent === dir) return false
34
+ dir = parent
35
+ }
36
+ }
37
+
24
38
  const flag = (args: string[], name: string, value: unknown): void => {
25
39
  if (typeof value === 'string' && value !== '') args.push(`--${name}`, value)
26
40
  }
@@ -30,13 +44,15 @@ export default function (cmd: ModApi): void {
30
44
  let cwd = process.cwd()
31
45
  let polling: Disposable | null = null
32
46
 
33
- try {
34
- const skill = ['../../skills/irsim-workflow', '../../../plugin/skills/irsim-workflow']
35
- .map((path) => fileURLToPath(new URL(path, import.meta.url)))
36
- .find((path) => existsSync(path))
37
- if (skill) cmd.addSkillsPath(skill)
38
- } catch {
39
- /* the host may reject an extra skills path */
47
+ for (const name of ['irsim-workflow', 'irsim-design']) {
48
+ try {
49
+ const skill = [`../../skills/${name}`, `../../../plugin/skills/${name}`]
50
+ .map((path) => fileURLToPath(new URL(path, import.meta.url)))
51
+ .find((path) => existsSync(path))
52
+ if (skill) cmd.addSkillsPath(skill)
53
+ } catch {
54
+ /* the host may reject an extra skills path */
55
+ }
40
56
  }
41
57
 
42
58
  cmd.on('run_start', (event) => {
@@ -100,13 +116,13 @@ export default function (cmd: ModApi): void {
100
116
  schema: {
101
117
  name: 'design_canvas',
102
118
  description:
103
- 'Reads and answers design canvas comments, checks boards, and checks the project. Actions: open, page, comments, reply, resolve, check, doctor. check renders a board (or every board of a page) in headless Chromium and returns errors, warnings and a screenshot path to look at. doctor checks the project rules, git setup and config. Reply in at most three short sentences. Put long detail in the board or a file and link to it, not in the reply.',
119
+ 'Reads and answers design canvas comments, checks boards, lints the design folder, and checks the project. Actions: open, page, comments, reply, resolve, check, lint, doctor. check renders a board (or every board of a page) in headless Chromium and returns errors, warnings and a screenshot path to look at, after the format problems of the design folder. lint lists the format problems of the board files and design/canvas.json. doctor checks the project rules, git setup and config. Reply in at most three short sentences. Put long detail in the board or a file and link to it, not in the reply.',
104
120
  input_schema: {
105
121
  type: 'object',
106
122
  properties: {
107
123
  action: {
108
124
  type: 'string',
109
- enum: ['open', 'page', 'comments', 'reply', 'resolve', 'check', 'doctor'],
125
+ enum: ['open', 'page', 'comments', 'reply', 'resolve', 'check', 'lint', 'doctor'],
110
126
  },
111
127
  page: { type: 'string', description: 'Page id, for open, page, comments and check.' },
112
128
  board: { type: 'string', description: 'Board name, for open and check.' },
@@ -186,6 +202,7 @@ export default function (cmd: ModApi): void {
186
202
  })
187
203
 
188
204
  cmd.hooks({
205
+ appendSystemPrompt: () => (hasIrsimConfig(cwd) ? SESSION_CONTEXT : undefined),
189
206
  onSessionStart: () => {
190
207
  cwd = process.cwd()
191
208
  },
@@ -164,13 +164,13 @@ export default {
164
164
  editor.add({
165
165
  name: 'design_canvas',
166
166
  description:
167
- 'Reads and answers design canvas comments, checks boards, and checks the project. Actions: open, page, comments, reply, resolve, check, doctor. check renders a board (or every board of a page) in headless Chromium and returns errors, warnings and a screenshot path to look at. doctor checks the project rules, git setup and config. Reply in at most three short sentences. Put long detail in the board or a file and link to it, not in the reply.',
167
+ 'Reads and answers design canvas comments, checks boards, lints the design folder, and checks the project. Actions: open, page, comments, reply, resolve, check, lint, doctor. check renders a board (or every board of a page) in headless Chromium and returns errors, warnings and a screenshot path to look at, after the format problems of the design folder. lint lists the format problems of the board files and design/canvas.json. doctor checks the project rules, git setup and config. Reply in at most three short sentences. Put long detail in the board or a file and link to it, not in the reply.',
168
168
  input: {
169
169
  type: 'object',
170
170
  properties: {
171
171
  action: {
172
172
  type: 'string',
173
- enum: ['open', 'page', 'comments', 'reply', 'resolve', 'check', 'doctor'],
173
+ enum: ['open', 'page', 'comments', 'reply', 'resolve', 'check', 'lint', 'doctor'],
174
174
  },
175
175
  page: { type: 'string', description: 'Page id, for open, page, comments and check.' },
176
176
  board: { type: 'string', description: 'Board name, for open and check.' },
@@ -8,6 +8,8 @@
8
8
  */
9
9
 
10
10
  import { execFile } from 'node:child_process'
11
+ import { existsSync } from 'node:fs'
12
+ import { dirname, join } from 'node:path'
11
13
  import { StringEnum, Type } from '@earendil-works/pi-ai'
12
14
  import type { ExtensionAPI, ExtensionCommandContext } from '@earendil-works/pi-coding-agent'
13
15
 
@@ -37,6 +39,19 @@ const bridge = (args: string[], cwd: string, signal?: AbortSignal): Promise<Brid
37
39
  )
38
40
  })
39
41
 
42
+ const SESSION_CONTEXT =
43
+ 'This project keeps its screens as irsim boards. Load the `irsim-design` skill before you create or edit a board file or design/canvas.json, and the `irsim-workflow` skill before you change what a screen shows. Run `irsim lint` and design_canvas check before you say you are done.'
44
+
45
+ const hasIrsimConfig = (from: string): boolean => {
46
+ let dir = from
47
+ for (;;) {
48
+ if (existsSync(join(dir, '.irsim.json'))) return true
49
+ const parent = dirname(dir)
50
+ if (parent === dir) return false
51
+ dir = parent
52
+ }
53
+ }
54
+
40
55
  const flag = (args: string[], name: string, value: unknown): void => {
41
56
  if (typeof value === 'string' && value !== '') args.push(`--${name}`, value)
42
57
  }
@@ -110,13 +125,17 @@ export default function (pi: ExtensionAPI): void {
110
125
  return `Listening for irsim comments in ${sessionId}.`
111
126
  }
112
127
 
128
+ pi.on('before_agent_start', (event, ctx) =>
129
+ hasIrsimConfig(ctx.cwd) ? { systemPrompt: `${event.systemPrompt}\n\n${SESSION_CONTEXT}` } : undefined,
130
+ )
131
+
113
132
  pi.registerTool({
114
133
  name: 'design_canvas',
115
134
  label: 'Design canvas',
116
135
  description:
117
- 'Reads and answers design canvas comments, checks boards, and checks the project. Actions: open, page, comments, reply, resolve, check, doctor. check renders a board (or every board of a page) in headless Chromium and returns errors, warnings and a screenshot path to look at. doctor checks the project rules, git setup and config. Reply in at most three short sentences. Put long detail in the board or a file and link to it, not in the reply.',
136
+ 'Reads and answers design canvas comments, checks boards, lints the design folder, and checks the project. Actions: open, page, comments, reply, resolve, check, lint, doctor. check renders a board (or every board of a page) in headless Chromium and returns errors, warnings and a screenshot path to look at, after the format problems of the design folder. lint lists the format problems of the board files and design/canvas.json. doctor checks the project rules, git setup and config. Reply in at most three short sentences. Put long detail in the board or a file and link to it, not in the reply.',
118
137
  parameters: Type.Object({
119
- action: StringEnum(['open', 'page', 'comments', 'reply', 'resolve', 'check', 'doctor'] as const),
138
+ action: StringEnum(['open', 'page', 'comments', 'reply', 'resolve', 'check', 'lint', 'doctor'] as const),
120
139
  page: Type.Optional(Type.String({ description: 'Page id, for open, page, comments and check.' })),
121
140
  board: Type.Optional(Type.String({ description: 'Board name, for open and check.' })),
122
141
  status: Type.Optional(
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@kafbit/irsim-connectors",
3
- "version": "0.5.0",
4
- "description": "irsim connectors for Pi, OpenCode and Command Code: the design_canvas tool, canvas comments delivered to the session, and the irsim-workflow skill.",
3
+ "version": "0.6.0",
4
+ "description": "irsim connectors for Pi, OpenCode and Command Code: the design_canvas tool, canvas comments delivered to the session, and the irsim-workflow and irsim-design skills.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "homepage": "https://github.com/kafbit/irsim",
7
7
  "repository": { "type": "git", "url": "git+https://github.com/kafbit/irsim.git", "directory": "plugin" },
8
8
  "bugs": "https://github.com/kafbit/irsim/issues",
9
9
  "keywords": ["pi-package", "opencode", "opencode-plugin", "command-code", "irsim", "design", "canvas"],
10
- "files": ["harnesses/pi/irsim.ts", "harnesses/opencode/irsim.js", "harnesses/command-code/irsim.ts", "skills/irsim-workflow"],
10
+ "files": ["harnesses/pi/irsim.ts", "harnesses/opencode/irsim.js", "harnesses/command-code/irsim.ts", "skills/irsim-workflow", "skills/irsim-design"],
11
11
  "exports": { "./server": "./harnesses/opencode/irsim.js" },
12
- "pi": { "extensions": ["./harnesses/pi/irsim.ts"], "skills": ["./skills/irsim-workflow"] },
13
- "commandcode": { "mods": ["./harnesses/command-code/irsim.ts"], "skills": ["./skills/irsim-workflow"] },
12
+ "pi": { "extensions": ["./harnesses/pi/irsim.ts"], "skills": ["./skills/irsim-workflow", "./skills/irsim-design"] },
13
+ "commandcode": { "mods": ["./harnesses/command-code/irsim.ts"], "skills": ["./skills/irsim-workflow", "./skills/irsim-design"] },
14
14
  "peerDependencies": { "@earendil-works/pi-ai": "*", "@earendil-works/pi-coding-agent": "*" },
15
15
  "peerDependenciesMeta": { "@earendil-works/pi-ai": { "optional": true }, "@earendil-works/pi-coding-agent": { "optional": true } },
16
16
  "publishConfig": { "access": "public", "provenance": true }
@@ -0,0 +1,152 @@
1
+ ---
2
+ name: irsim-design
3
+ description: The file formats of an irsim design folder: board files and design/canvas.json. Load it before you create or edit a board file or design/canvas.json, or when a project has a design folder of boards.
4
+ ---
5
+
6
+ # irsim design files
7
+
8
+ Load this before you write a board file or `design/canvas.json`. For the order of work on a screen change (board first, user confirms, then code) follow the `irsim-workflow` skill.
9
+
10
+ ## Where things live
11
+
12
+ - `.irsim.json` at the project root names the design folder: `{ "designDir": "design" }`. The default is `design`.
13
+ - `<designDir>/<Name>.html` is one board.
14
+ - `<designDir>/canvas.json` places boards on pages and in sections.
15
+ - `<designDir>/shared/` holds `*.css` (injected into every board), `*.js` and `*.mjs` (modules, reached as `shared.<name>`), and images and fonts (referenced as `./shared/<path>`). Names that start with `.` are ignored.
16
+ - `.irsim/` holds generated files (checks, screenshots, port). Never edit or commit it.
17
+
18
+ ## A board file
19
+
20
+ - The file name is `<Name>.html`. `Name` matches `^[A-Za-z][A-Za-z0-9]*$`, for example `LeadsTable`.
21
+ - A legacy `<Name>.dc.html` is still read. Do not create new ones. When both exist, `<Name>.html` wins.
22
+ - A `.html` file is a board only when it contains `<x-dc>` or a `<script type="text/x-dc">`. Any other `.html` file in the folder is ignored.
23
+ - Parts of a board file:
24
+ - `<title>`: the board title shown on the canvas.
25
+ - `<script src="./support.js">` in the head. Leave it as written, the canvas serves the runtime under that name.
26
+ - `<x-dc>`: the template. Its children are rendered as written. `<helmet>` inside it holds the `<link>` and `<style>` elements that belong in the head.
27
+ - `<script type="text/x-dc" data-dc-script data-props='...'>`: the props as JSON in single quotes, then `class Component extends DCLogic` with `renderVals()` returning the values the template uses.
28
+ - `$preview` inside `data-props` is the board size `{ "width": n, "height": n }`. It is not a prop. Without it the size is 1440 by 900.
29
+ - A hole is `{{a.b.c}}`, a dotted lookup in what `renderVals()` returns. There are no operators or calls. `<sc-if value="{{x}}">` and `<sc-for list="{{xs}}" as="item">` are the only control tags.
30
+ - `<dc-import name="Other" prop="value" ...>` mounts the board `Other` of the same folder. Every other attribute is a prop of it. `hint-size` and `hint-placeholder-*` are dropped. Write it as a pair with no content.
31
+ - `data-props` entries are `{ "editor": "text", "enum" or "number", "default": ..., "options": [...] }`, or `{ "editor": null }` for a prop only a parent passes.
32
+
33
+ A complete minimal board:
34
+
35
+ ```html
36
+ <!doctype html>
37
+ <html lang="en" dir="ltr">
38
+ <head>
39
+ <meta charset="utf-8">
40
+ <title>Greeting: dark</title>
41
+ <script src="./support.js"></script>
42
+ </head>
43
+ <body>
44
+ <x-dc>
45
+ <helmet>
46
+ <style>body{margin:0}</style>
47
+ </helmet>
48
+ <dc-import name="Greeting" theme="{{theme}}" hint-size="480px,240px"></dc-import>
49
+ </x-dc>
50
+ <script type="text/x-dc" data-dc-script data-props='{"theme":{"editor":"enum","default":"dark","options":["light","dark"]},"$preview":{"width":480,"height":240}}'>
51
+ class Component extends DCLogic {
52
+ renderVals() {
53
+ return { theme: this.props.theme }
54
+ }
55
+ }
56
+ </script>
57
+ </body>
58
+ </html>
59
+ ```
60
+
61
+ ## Props and state boards
62
+
63
+ - The canvas has no prop switcher. Draw each state as its own board: a wrapper of the base board with fixed props, named `<Board><State>` (`GreetingDark`), with its own title, placed on a page.
64
+ - A wrapper is the example above: one `<dc-import>` with the fixed props, the `theme` prop passed down as `theme="{{theme}}"`, and the same `$preview` size as the base.
65
+ - Do not copy the base markup into a state board.
66
+ - Every board has a `theme` prop, `light` or `dark`, when the project has both themes.
67
+
68
+ ## Tokens
69
+
70
+ - Colors, radius and type come from the project's token files (this repo: `app/src/app/ui-tokens.css` and `globals.css`). Write `var(--token)` and never a close value. If a value is missing, ask.
71
+ - Put styles that many boards share in `<designDir>/shared/*.css`.
72
+ - English boards set `<html lang="en" dir="ltr">` and the same on the root element. A project in another language sets its own `lang` and `dir`.
73
+
74
+ ## design/canvas.json
75
+
76
+ Top level: `{ "version": 1, "pages": [...], "overrides": {...}, "bindings": {...} }`. `overrides` and `bindings` are required. The canvas writes them, so leave their content as it is. A new file starts with `"overrides": {"colors": {}, "radius": {}, "type": {}}` and `"bindings": {}`. `irsim lint` reports an error when either is missing or malformed.
77
+
78
+ Page:
79
+
80
+ | Field | Type | Required | Notes |
81
+ |---|---|---|---|
82
+ | `id` | string | yes | Used in the route `/p/<id>`. Lowercase kebab-case. |
83
+ | `title` | string | yes | Shown in the sidebar. At most 120 characters. |
84
+ | `icon` | string | no | A Lucide icon name in kebab-case. Give every page one. |
85
+ | `sections` | array | no | Section entries, below. |
86
+ | `boards` | array | yes | Board entries, below. |
87
+
88
+ Board entry:
89
+
90
+ | Field | Type | Required | Notes |
91
+ |---|---|---|---|
92
+ | `name` | string | yes | The board file name without `.html`. A name with no file is dropped. |
93
+ | `title` | string | filled | Read from `<title>`. Never write it by hand. |
94
+ | `width`, `height` | number | filled | Read from `$preview`. Never write them by hand. A size under 240 x 160 gets a lint warning and is fine for a small part. |
95
+ | `x`, `y` | number | filled | Canvas position. Leave out for a new board, it is placed below the others. Do not place by hand. |
96
+ | `section` | string | no | The `id` of the innermost section of the same page. |
97
+ | `interactive` | boolean | no | Overrides the guess whether the board is a prototype. |
98
+ | `expand` | string | no | `"fill"` makes it a web page in full screen play. |
99
+ | `variantOf`, `variantLabel` | string | no | Written by the Variants feature. Do not write them. |
100
+ | `baseHash` | string | no | Written by the canvas. Do not write it. |
101
+
102
+ Section entry:
103
+
104
+ | Field | Type | Required | Notes |
105
+ |---|---|---|---|
106
+ | `id` | string | yes | Unique on the page. |
107
+ | `title` | string | yes | Shown as the section label. |
108
+ | `parent` | string | no | The `id` of another section of the page. At most 3 levels, no cycle. |
109
+ | `color` | string | no | `gray` (default), `blue`, `green`, `amber`, `purple` or `red`. |
110
+ | `x`, `y`, `width`, `height` | number | no | A stored area. All four or none. Written by the canvas. |
111
+ | `layout` | object | no | `{ "mode": "wrap", "gap": 0 to 400 }`. Written by the canvas. |
112
+ | `variantOf`, `baseSection` | string | no | Written by the Variants feature. Do not write them. |
113
+
114
+ A complete 2-page example (the fields marked filled are left out on purpose):
115
+
116
+ ```json
117
+ {
118
+ "version": 1,
119
+ "pages": [
120
+ {
121
+ "id": "onboarding",
122
+ "title": "Onboarding",
123
+ "icon": "hand",
124
+ "sections": [
125
+ { "id": "greeting", "title": "Greeting" },
126
+ { "id": "greeting-states", "title": "States", "parent": "greeting", "color": "red" }
127
+ ],
128
+ "boards": [
129
+ { "name": "Greeting", "section": "greeting" },
130
+ { "name": "GreetingDark", "section": "greeting-states" }
131
+ ]
132
+ },
133
+ {
134
+ "id": "settings",
135
+ "title": "Settings",
136
+ "icon": "settings",
137
+ "boards": [{ "name": "SettingsForm" }]
138
+ }
139
+ ],
140
+ "overrides": { "colors": {}, "radius": {}, "type": {} },
141
+ "bindings": {}
142
+ }
143
+ ```
144
+
145
+ `irsim build` fills `title`, `width`, `height`, `x` and `y` from the board files, adds boards that no page lists to the `unsorted` page, and drops entries whose file is gone. A file that has no entry yet shows up on the `unsorted` page.
146
+
147
+ ## Finish
148
+
149
+ 1. Run `irsim lint`. Fix every error and read every warning. `design_canvas {action: "lint"}` returns the same list.
150
+ 2. Run `irsim build` to fill `canvas.json`. Never hand-write `title`, `width` or `height`. `irsim lint --fix` runs the build too and also renames legacy `.dc.html` files to `.html`.
151
+ 3. Run `design_canvas {action: "check", page: "<id>"}` and look at the screenshots. `check` also lists every lint error first, under `Format problems:`, and the warnings of the checked boards. It counts the other warnings, and `design_canvas {action: "lint"}` lists them.
152
+ 4. Report the board routes `/p/<page>?board=<Board>`.
@@ -5,6 +5,8 @@ description: The design-first process for any project that keeps its screens as
5
5
 
6
6
  # irsim workflow
7
7
 
8
+ Load the `irsim-design` skill before you create or edit a board file or `design/canvas.json`.
9
+
8
10
  The boards in the design folder are the design. The app must match them, and they must match the app.
9
11
 
10
12
  ## When this applies
@@ -16,7 +18,7 @@ It does not apply to a change that alters nothing a person sees (a refactor, a s
16
18
  ## The order
17
19
 
18
20
  1. Plan. Name the boards that change, what changes in each, and the app files that would follow. List open choices, do not decide them. Put the board change in the plan as its own step, before the implementation steps.
19
- 2. Change the board. Edit the `.dc.html` file. Draw the new states: disabled and locked controls, confirmation dialogs, empty, loading and error states, and every language and width the screen has. The canvas has no prop switcher: the user sees only the boards placed on a page. Draw each state, and each option of a choice the user must make, as its own state board: a `dc-import` wrapper of the base board with fixed props, named `<Board><State>`, with a title, placed on the page. Group the states of one screen in a section (see Sections).
21
+ 2. Change the board. Edit the board file, `<Name>.html` (`.dc.html` is a legacy form that is still read). Draw the new states: disabled and locked controls, confirmation dialogs, empty, loading and error states, and every language and width the screen has. The canvas has no prop switcher: the user sees only the boards placed on a page. Draw each state, and each option of a choice the user must make, as its own state board: a `dc-import` wrapper of the base board with fixed props, named `<Board><State>`, with a title, placed on the page. Group the states of one screen in a section (see Sections).
20
22
  3. Check the board. Run `design_canvas {action: "check", board: "<Board>"}` (or `page` for every board of a page). Fix every error and warning it lists, then open the screenshot it returns and look at it. Check again until it reports `ok`.
21
23
  4. Report and stop. Give the board name and its route (`/p/<page>?board=<Board>`), the plan and the open choices. Give the route of each state board. Never ask the user to set a prop value to see a state. Write no app code until the user confirms in a separate message. A request is not a confirmation: "implement", "make it", "move X" and a pasted screenshot all ask for the board change. The user can also confirm with the Approve button in irsim: a turn that starts with "Design canvas: the user approved board X" is the confirmation for that board. If that turn says the board changed after the approval, it is not a confirmation; ask again.
22
24
  5. Implement. Read the board file again first, because the user may have edited it. A board the user edited is the source of truth over your last copy and over the plan.