@kafbit/irsim-connectors 0.0.0-stage → 0.5.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.
@@ -0,0 +1,197 @@
1
+ /**
2
+ * irsim connector for Command Code.
3
+ *
4
+ * Place at ~/.commandcode/mods/irsim.ts (personal) or <project>/.commandcode/mods/irsim.ts.
5
+ * It registers /irsim, /irsim-stop, /irsim-comments and the design_canvas tool, and polls the
6
+ * canvas for comments while the session listens. Every canvas call goes through
7
+ * `irsim bridge`, so this file holds no HTTP or port logic of its own.
8
+ */
9
+
10
+ import { randomUUID } from 'node:crypto'
11
+ import { existsSync } from 'node:fs'
12
+ import { fileURLToPath } from 'node:url'
13
+ import type { ModApi } from '@commandcode/harness'
14
+
15
+ const POLL_MS = 2000
16
+
17
+ type Disposable = { dispose(): void }
18
+
19
+ const bridgeBin = (): string => {
20
+ const value = process.env.IRSIM_BIN
21
+ return typeof value === 'string' && value.trim() !== '' ? value.trim() : 'irsim'
22
+ }
23
+
24
+ const flag = (args: string[], name: string, value: unknown): void => {
25
+ if (typeof value === 'string' && value !== '') args.push(`--${name}`, value)
26
+ }
27
+
28
+ export default function (cmd: ModApi): void {
29
+ let sessionId = `command-code-${randomUUID()}`
30
+ let cwd = process.cwd()
31
+ let polling: Disposable | null = null
32
+
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 */
40
+ }
41
+
42
+ cmd.on('run_start', (event) => {
43
+ if (event.type === 'run_start' && typeof event.sessionId === 'string' && event.sessionId) {
44
+ sessionId = event.sessionId
45
+ }
46
+ })
47
+
48
+ const runBridge = async (
49
+ args: string[],
50
+ directory = cwd,
51
+ ): Promise<{ ok: boolean; text: string }> => {
52
+ try {
53
+ const result = await cmd.exec({ command: bridgeBin(), args: ['bridge', ...args], cwd: directory })
54
+ return result.code === 0
55
+ ? { ok: true, text: String(result.stdout).trim() }
56
+ : { ok: false, text: String(result.stderr || result.stdout).trim() }
57
+ } catch (error) {
58
+ return { ok: false, text: error instanceof Error ? error.message : String(error) }
59
+ }
60
+ }
61
+
62
+ const stopPolling = (): void => {
63
+ polling?.dispose()
64
+ polling = null
65
+ }
66
+
67
+ const startPolling = (): void => {
68
+ stopPolling()
69
+ polling = cmd.clock.every(POLL_MS, async () => {
70
+ const claimed = await runBridge(['claim', '--session', sessionId, '--cwd', cwd, '--json'])
71
+ if (!claimed.ok || claimed.text === '') return
72
+ let count = 0
73
+ let text = ''
74
+ try {
75
+ ;({ count, text } = JSON.parse(claimed.text) as { count: number; text: string })
76
+ } catch {
77
+ return
78
+ }
79
+ if (!(count > 0 && text)) return
80
+ try {
81
+ await cmd.sendUserMessage(text)
82
+ } catch {
83
+ await runBridge(['release', '--session', sessionId, '--cwd', cwd, '--claim', claimed.text])
84
+ }
85
+ })
86
+ }
87
+
88
+ const listen = async (directory: string): Promise<string> => {
89
+ cwd = directory
90
+ const registered = await runBridge(
91
+ ['register', '--agent', 'command-code', '--session', sessionId, '--cwd', cwd],
92
+ cwd,
93
+ )
94
+ if (!registered.ok) return registered.text
95
+ startPolling()
96
+ return `Listening for irsim comments in ${sessionId}.`
97
+ }
98
+
99
+ cmd.addTool({
100
+ schema: {
101
+ name: 'design_canvas',
102
+ 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.',
104
+ input_schema: {
105
+ type: 'object',
106
+ properties: {
107
+ action: {
108
+ type: 'string',
109
+ enum: ['open', 'page', 'comments', 'reply', 'resolve', 'check', 'doctor'],
110
+ },
111
+ page: { type: 'string', description: 'Page id, for open, page, comments and check.' },
112
+ board: { type: 'string', description: 'Board name, for open and check.' },
113
+ status: {
114
+ type: 'string',
115
+ enum: ['draft', 'queued', 'delivered', 'resolved'],
116
+ description: 'Filter for comments.',
117
+ },
118
+ id: { type: 'string', description: 'Comment id, for reply and resolve.' },
119
+ body: {
120
+ type: 'string',
121
+ description:
122
+ 'Reply text, for reply and resolve. Reply in at most three short sentences. Put long detail in the board or a file and link to it, not in the reply.',
123
+ },
124
+ },
125
+ required: ['action'],
126
+ },
127
+ },
128
+ run: async ({ input }) => {
129
+ const args = ['tool', '--action', String(input.action ?? ''), '--cwd', cwd]
130
+ flag(args, 'page', input.page)
131
+ flag(args, 'board', input.board)
132
+ flag(args, 'status', input.status)
133
+ flag(args, 'id', input.id)
134
+ flag(args, 'body', input.body)
135
+ flag(args, 'session', sessionId)
136
+ const result = await runBridge(args)
137
+ if (!result.ok) return { ok: false, error: `irsim: ${result.text}` }
138
+ return { ok: true, content: [{ type: 'text', text: result.text }] }
139
+ },
140
+ })
141
+
142
+ cmd.addCommand({
143
+ name: 'irsim',
144
+ description: 'Open irsim and listen for its comments',
145
+ argumentHint: '[page or board]',
146
+ handler: async (context) => {
147
+ cwd = context.cwd ?? process.cwd()
148
+ const opened = await runBridge(
149
+ [
150
+ 'tool',
151
+ '--action',
152
+ 'open',
153
+ '--agent',
154
+ 'command-code',
155
+ '--session',
156
+ sessionId,
157
+ '--cwd',
158
+ cwd,
159
+ ...(context.args?.trim() ? ['--target', context.args.trim()] : []),
160
+ ],
161
+ )
162
+ const started = await listen(cwd)
163
+ return { message: opened.ok ? `${opened.text} ${started}` : `irsim: ${opened.text}` }
164
+ },
165
+ })
166
+
167
+ cmd.addCommand({
168
+ name: 'irsim-stop',
169
+ description: 'Stop listening for irsim comments',
170
+ handler: async () => {
171
+ stopPolling()
172
+ await runBridge(['leave', '--session', sessionId, '--cwd', cwd])
173
+ return { message: 'Stopped listening for irsim comments.' }
174
+ },
175
+ })
176
+
177
+ cmd.addCommand({
178
+ name: 'irsim-comments',
179
+ description: 'Count the open irsim comments per page',
180
+ handler: async (context) => {
181
+ const args = ['tool', '--action', 'comments', '--cwd', cwd]
182
+ if (context.args?.trim()) args.push('--page', context.args.trim())
183
+ const listed = await runBridge(args)
184
+ return { message: listed.ok ? listed.text : `irsim: ${listed.text}` }
185
+ },
186
+ })
187
+
188
+ cmd.hooks({
189
+ onSessionStart: () => {
190
+ cwd = process.cwd()
191
+ },
192
+ onSessionEnd: () => {
193
+ stopPolling()
194
+ void runBridge(['leave', '--session', sessionId, '--cwd', cwd])
195
+ },
196
+ })
197
+ }
@@ -0,0 +1,223 @@
1
+ // irsim connector for OpenCode v2.
2
+ //
3
+ // Loads from ~/.config/opencode/plugins/irsim.js (or .opencode/plugins/). It registers
4
+ // /irsim, /irsim-stop, /irsim-comments and the design_canvas tool, and polls the canvas
5
+ // for comments while a session listens. Every canvas call goes through `irsim bridge`,
6
+ // so this file stays small and holds no HTTP or port logic of its own.
7
+
8
+ import { execFile } from 'node:child_process'
9
+
10
+ const BRIDGE_MS = 15000
11
+ const POLL_MS = 2000
12
+
13
+ const bridgeBin = () => {
14
+ const value = process.env.IRSIM_BIN
15
+ return typeof value === 'string' && value.trim() !== '' ? value.trim() : 'irsim'
16
+ }
17
+
18
+ const bridge = (args, cwd, signal) =>
19
+ new Promise((resolve) => {
20
+ const child = execFile(
21
+ bridgeBin(),
22
+ ['bridge', ...args],
23
+ { cwd, timeout: BRIDGE_MS, maxBuffer: 4 * 1024 * 1024, encoding: 'utf8', signal },
24
+ (error, stdout, stderr) => {
25
+ resolve(
26
+ error
27
+ ? { ok: false, text: String(stderr || error.message).trim() }
28
+ : { ok: true, text: String(stdout).trim() },
29
+ )
30
+ },
31
+ )
32
+ child.on('error', () => undefined)
33
+ })
34
+
35
+ const flag = (args, name, value) => {
36
+ if (typeof value === 'string' && value !== '') args.push(`--${name}`, value)
37
+ }
38
+
39
+ const toolArgs = (input, cwd) => {
40
+ const args = ['tool', '--action', String(input.action ?? ''), '--cwd', cwd]
41
+ flag(args, 'page', input.page)
42
+ flag(args, 'board', input.board)
43
+ flag(args, 'status', input.status)
44
+ flag(args, 'id', input.id)
45
+ flag(args, 'body', input.body)
46
+ return args
47
+ }
48
+
49
+ export default {
50
+ id: 'irsim',
51
+ async setup(ctx) {
52
+ const directory = ctx.location?.directory ?? process.cwd()
53
+ const timers = new Map()
54
+ const polling = new Set()
55
+ let disposed = false
56
+
57
+ const start = async (sessionID) => {
58
+ if (!sessionID) return 'No OpenCode session to register.'
59
+ const registered = await bridge(
60
+ ['register', '--agent', 'opencode', '--session', sessionID, '--cwd', directory],
61
+ directory,
62
+ )
63
+ if (!registered.ok) return registered.text
64
+ if (!timers.has(sessionID)) {
65
+ const poll = async () => {
66
+ const claimed = await bridge(
67
+ ['claim', '--session', sessionID, '--cwd', directory, '--json'],
68
+ directory,
69
+ )
70
+ if (!claimed.ok || claimed.text === '') return
71
+ let count = 0
72
+ let text = ''
73
+ try {
74
+ ;({ count, text } = JSON.parse(claimed.text))
75
+ } catch {
76
+ return
77
+ }
78
+ if (!(count > 0 && text)) return
79
+ const delivered = await ctx.session
80
+ .prompt({ sessionID, text })
81
+ .then(() => true)
82
+ .catch(() => false)
83
+ if (!delivered)
84
+ await bridge(
85
+ ['release', '--session', sessionID, '--cwd', directory, '--claim', claimed.text],
86
+ directory,
87
+ )
88
+ }
89
+ const timer = setInterval(async () => {
90
+ if (disposed || polling.has(sessionID)) return
91
+ polling.add(sessionID)
92
+ try {
93
+ await poll()
94
+ } finally {
95
+ polling.delete(sessionID)
96
+ }
97
+ }, POLL_MS)
98
+ timer.unref?.()
99
+ timers.set(sessionID, timer)
100
+ }
101
+ return `Listening for irsim comments in ${sessionID}.`
102
+ }
103
+
104
+ const stop = async (sessionID) => {
105
+ const timer = timers.get(sessionID)
106
+ if (timer) clearInterval(timer)
107
+ timers.delete(sessionID)
108
+ await bridge(['leave', '--session', sessionID, '--cwd', directory], directory)
109
+ return `Stopped listening for irsim comments in ${sessionID}.`
110
+ }
111
+
112
+ try {
113
+ await ctx.command.transform((editor) => {
114
+ editor.add({
115
+ name: 'irsim',
116
+ description: 'Open irsim and listen for its comments',
117
+ execute: async ({ sessionID, prompt }) => {
118
+ const opened = await bridge(
119
+ [
120
+ 'tool',
121
+ '--action',
122
+ 'open',
123
+ '--agent',
124
+ 'opencode',
125
+ '--session',
126
+ sessionID,
127
+ '--cwd',
128
+ directory,
129
+ ...(prompt?.text?.trim() ? ['--target', prompt.text.trim()] : []),
130
+ ],
131
+ directory,
132
+ )
133
+ const listening = await start(sessionID)
134
+ const text = opened.ok ? opened.text : `irsim: ${opened.text}`
135
+ await ctx.session.synthetic({ sessionID, text: `${text}\n${listening}` }).catch(() => undefined)
136
+ },
137
+ })
138
+ editor.add({
139
+ name: 'irsim-stop',
140
+ description: 'Stop listening for irsim comments',
141
+ execute: async ({ sessionID }) => {
142
+ await stop(sessionID)
143
+ },
144
+ })
145
+ editor.add({
146
+ name: 'irsim-comments',
147
+ description: 'Count the open irsim comments per page',
148
+ execute: async ({ sessionID, prompt }) => {
149
+ const args = ['tool', '--action', 'comments', '--cwd', directory]
150
+ flag(args, 'page', prompt?.text?.trim())
151
+ const listed = await bridge(args, directory)
152
+ await ctx.session
153
+ .synthetic({ sessionID, text: listed.ok ? listed.text : `irsim: ${listed.text}` })
154
+ .catch(() => undefined)
155
+ },
156
+ })
157
+ })
158
+ } catch {
159
+ /* a host without command transforms keeps the tools */
160
+ }
161
+
162
+ try {
163
+ await ctx.tool.transform((editor) => {
164
+ editor.add({
165
+ name: 'design_canvas',
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.',
168
+ input: {
169
+ type: 'object',
170
+ properties: {
171
+ action: {
172
+ type: 'string',
173
+ enum: ['open', 'page', 'comments', 'reply', 'resolve', 'check', 'doctor'],
174
+ },
175
+ page: { type: 'string', description: 'Page id, for open, page, comments and check.' },
176
+ board: { type: 'string', description: 'Board name, for open and check.' },
177
+ status: {
178
+ type: 'string',
179
+ enum: ['draft', 'queued', 'delivered', 'resolved'],
180
+ description: 'Filter for comments.',
181
+ },
182
+ id: { type: 'string', description: 'Comment id, for reply and resolve.' },
183
+ body: {
184
+ type: 'string',
185
+ description:
186
+ 'Reply text, for reply and resolve. Reply in at most three short sentences. Put long detail in the board or a file and link to it, not in the reply.',
187
+ },
188
+ session: { type: 'string', description: 'OpenCode session for a reply.' },
189
+ },
190
+ required: ['action'],
191
+ },
192
+ execute: async (input, context) => {
193
+ const args = toolArgs(input, directory)
194
+ flag(args, 'session', input.session ?? context?.sessionID)
195
+ const result = await bridge(args, directory, context?.signal)
196
+ return { content: result.ok ? result.text : `irsim: ${result.text}` }
197
+ },
198
+ })
199
+ })
200
+ } catch {
201
+ /* a host without tool transforms keeps the commands */
202
+ }
203
+
204
+ // Keep the registered session fresh while the plugin is idle, so it stays in the canvas picker.
205
+ const heartbeat = setInterval(async () => {
206
+ if (disposed) return
207
+ for (const sessionID of timers.keys()) {
208
+ await bridge(
209
+ ['register', '--agent', 'opencode', '--session', sessionID, '--cwd', directory],
210
+ directory,
211
+ )
212
+ }
213
+ }, 20_000)
214
+ heartbeat.unref?.()
215
+
216
+ return () => {
217
+ disposed = true
218
+ clearInterval(heartbeat)
219
+ for (const timer of timers.values()) clearInterval(timer)
220
+ timers.clear()
221
+ }
222
+ },
223
+ }
@@ -0,0 +1,197 @@
1
+ /**
2
+ * irsim connector for pi.
3
+ *
4
+ * Place at ~/.pi/agent/extensions/irsim.ts (or load with `pi --extension ./irsim.ts`).
5
+ * It registers /irsim, /irsim-stop, /irsim-comments and the design_canvas tool, and polls the
6
+ * canvas for comments while the session listens. Every canvas call goes through
7
+ * `irsim bridge`, so this file holds no HTTP or port logic of its own.
8
+ */
9
+
10
+ import { execFile } from 'node:child_process'
11
+ import { StringEnum, Type } from '@earendil-works/pi-ai'
12
+ import type { ExtensionAPI, ExtensionCommandContext } from '@earendil-works/pi-coding-agent'
13
+
14
+ const BRIDGE_MS = 15000
15
+ const POLL_MS = 2000
16
+
17
+ const bridgeBin = (): string => {
18
+ const value = process.env.IRSIM_BIN
19
+ return typeof value === 'string' && value.trim() !== '' ? value.trim() : 'irsim'
20
+ }
21
+
22
+ type BridgeResult = { ok: boolean; text: string }
23
+
24
+ const bridge = (args: string[], cwd: string, signal?: AbortSignal): Promise<BridgeResult> =>
25
+ new Promise((resolve) => {
26
+ execFile(
27
+ bridgeBin(),
28
+ ['bridge', ...args],
29
+ { cwd, timeout: BRIDGE_MS, maxBuffer: 4 * 1024 * 1024, encoding: 'utf8', signal },
30
+ (error, stdout, stderr) => {
31
+ resolve(
32
+ error
33
+ ? { ok: false, text: String(stderr || error.message).trim() }
34
+ : { ok: true, text: String(stdout).trim() },
35
+ )
36
+ },
37
+ )
38
+ })
39
+
40
+ const flag = (args: string[], name: string, value: unknown): void => {
41
+ if (typeof value === 'string' && value !== '') args.push(`--${name}`, value)
42
+ }
43
+
44
+ const toolArgs = (params: Record<string, unknown>, cwd: string): string[] => {
45
+ const args = ['tool', '--action', String(params.action ?? ''), '--cwd', cwd]
46
+ flag(args, 'page', params.page)
47
+ flag(args, 'board', params.board)
48
+ flag(args, 'status', params.status)
49
+ flag(args, 'id', params.id)
50
+ flag(args, 'body', params.body)
51
+ flag(args, 'session', params.session)
52
+ return args
53
+ }
54
+
55
+ export default function (pi: ExtensionAPI): void {
56
+ const timers = new Map<string, ReturnType<typeof setInterval>>()
57
+ const contexts = new Map<string, ExtensionCommandContext>()
58
+ let listening: string | null = null
59
+
60
+ const clear = (sessionId: string | null): void => {
61
+ if (!sessionId) return
62
+ const timer = timers.get(sessionId)
63
+ if (timer) clearInterval(timer)
64
+ timers.delete(sessionId)
65
+ contexts.delete(sessionId)
66
+ }
67
+
68
+ const listen = async (ctx: ExtensionCommandContext): Promise<string> => {
69
+ const sessionId = ctx.sessionManager.getSessionId()
70
+ const registered = await bridge(
71
+ ['register', '--agent', 'pi', '--session', sessionId, '--cwd', ctx.cwd],
72
+ ctx.cwd,
73
+ )
74
+ if (!registered.ok) return registered.text
75
+ contexts.set(sessionId, ctx)
76
+ listening = sessionId
77
+ if (!timers.has(sessionId)) {
78
+ const timer = setInterval(async () => {
79
+ const current = contexts.get(sessionId)
80
+ if (!current) return
81
+ const claimed = await bridge(
82
+ ['claim', '--session', sessionId, '--cwd', current.cwd, '--json'],
83
+ current.cwd,
84
+ )
85
+ if (!claimed.ok || claimed.text === '') return
86
+ let count = 0
87
+ let text = ''
88
+ try {
89
+ ;({ count, text } = JSON.parse(claimed.text) as { count: number; text: string })
90
+ } catch {
91
+ return
92
+ }
93
+ if (!(count > 0 && text)) return
94
+ let delivered = true
95
+ try {
96
+ if (current.isIdle()) pi.sendUserMessage(text)
97
+ else pi.sendUserMessage(text, { deliverAs: 'followUp' })
98
+ } catch {
99
+ delivered = false
100
+ }
101
+ if (!delivered)
102
+ await bridge(
103
+ ['release', '--session', sessionId, '--cwd', current.cwd, '--claim', claimed.text],
104
+ current.cwd,
105
+ )
106
+ }, POLL_MS)
107
+ timer.unref?.()
108
+ timers.set(sessionId, timer)
109
+ }
110
+ return `Listening for irsim comments in ${sessionId}.`
111
+ }
112
+
113
+ pi.registerTool({
114
+ name: 'design_canvas',
115
+ label: 'Design canvas',
116
+ 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.',
118
+ parameters: Type.Object({
119
+ action: StringEnum(['open', 'page', 'comments', 'reply', 'resolve', 'check', 'doctor'] as const),
120
+ page: Type.Optional(Type.String({ description: 'Page id, for open, page, comments and check.' })),
121
+ board: Type.Optional(Type.String({ description: 'Board name, for open and check.' })),
122
+ status: Type.Optional(
123
+ StringEnum(['draft', 'queued', 'delivered', 'resolved'] as const),
124
+ ),
125
+ id: Type.Optional(Type.String({ description: 'Comment id, for reply and resolve.' })),
126
+ body: Type.Optional(
127
+ Type.String({
128
+ description:
129
+ 'Reply text, for reply and resolve. Reply in at most three short sentences. Put long detail in the board or a file and link to it, not in the reply.',
130
+ }),
131
+ ),
132
+ session: Type.Optional(Type.String({ description: 'Pi session for a reply.' })),
133
+ }),
134
+ async execute(_toolCallId, params, signal, _onUpdate, ctx) {
135
+ const args = toolArgs(params, ctx.cwd)
136
+ if (!args.includes('--session')) {
137
+ args.push('--session', ctx.sessionManager.getSessionId())
138
+ }
139
+ const result = await bridge(args, ctx.cwd, signal)
140
+ return {
141
+ content: [{ type: 'text', text: result.ok ? result.text : `irsim: ${result.text}` }],
142
+ details: { action: params.action, ok: result.ok },
143
+ }
144
+ },
145
+ })
146
+
147
+ pi.registerCommand('irsim', {
148
+ description: 'Open irsim and listen for its comments',
149
+ handler: async (args, ctx) => {
150
+ const opened = await bridge(
151
+ [
152
+ 'tool',
153
+ '--action',
154
+ 'open',
155
+ '--agent',
156
+ 'pi',
157
+ '--session',
158
+ ctx.sessionManager.getSessionId(),
159
+ '--cwd',
160
+ ctx.cwd,
161
+ ...(args.trim() ? ['--target', args.trim()] : []),
162
+ ],
163
+ ctx.cwd,
164
+ )
165
+ const started = await listen(ctx)
166
+ ctx.ui.notify(opened.ok ? `${opened.text} ${started}` : `irsim: ${opened.text}`, opened.ok ? 'info' : 'error')
167
+ },
168
+ })
169
+
170
+ pi.registerCommand('irsim-stop', {
171
+ description: 'Stop listening for irsim comments',
172
+ handler: async (_args, ctx) => {
173
+ const sessionId = ctx.sessionManager.getSessionId()
174
+ clear(sessionId)
175
+ if (listening === sessionId) listening = null
176
+ await bridge(['leave', '--session', sessionId, '--cwd', ctx.cwd], ctx.cwd)
177
+ ctx.ui.notify('Stopped listening for irsim comments.', 'info')
178
+ },
179
+ })
180
+
181
+ pi.registerCommand('irsim-comments', {
182
+ description: 'Count the open irsim comments per page',
183
+ handler: async (args, ctx) => {
184
+ const tool = ['tool', '--action', 'comments', '--cwd', ctx.cwd]
185
+ if (args.trim()) tool.push('--page', args.trim())
186
+ const listed = await bridge(tool, ctx.cwd)
187
+ ctx.ui.notify(listed.ok ? listed.text : `irsim: ${listed.text}`, listed.ok ? 'info' : 'error')
188
+ },
189
+ })
190
+
191
+ pi.on('session_shutdown', async () => {
192
+ for (const sessionId of [...timers.keys()]) {
193
+ clear(sessionId)
194
+ await bridge(['leave', '--session', sessionId], process.cwd()).catch(() => undefined)
195
+ }
196
+ })
197
+ }
package/package.json CHANGED
@@ -1,6 +1,17 @@
1
1
  {
2
2
  "name": "@kafbit/irsim-connectors",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
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.",
5
+ "license": "AGPL-3.0-only",
6
+ "homepage": "https://github.com/kafbit/irsim",
7
+ "repository": { "type": "git", "url": "git+https://github.com/kafbit/irsim.git", "directory": "plugin" },
8
+ "bugs": "https://github.com/kafbit/irsim/issues",
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"],
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"] },
14
+ "peerDependencies": { "@earendil-works/pi-ai": "*", "@earendil-works/pi-coding-agent": "*" },
15
+ "peerDependenciesMeta": { "@earendil-works/pi-ai": { "optional": true }, "@earendil-works/pi-coding-agent": { "optional": true } },
16
+ "publishConfig": { "access": "public", "provenance": true }
17
+ }
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: irsim-workflow
3
+ description: The design-first process for any project that keeps its screens as boards in irsim. Use before planning or changing anything a person sees (a screen, popup, state, layout or shared component), when the user pastes a screenshot or asks to move, add, remove or restyle UI, and when implementing from a board. The board changes first, the user confirms it, then the code follows, and the board stays in step with the app.
4
+ ---
5
+
6
+ # irsim workflow
7
+
8
+ The boards in the design folder are the design. The app must match them, and they must match the app.
9
+
10
+ ## When this applies
11
+
12
+ Any change to what a screen shows or lets the user do: moving, adding, removing, resizing or restyling anything visible, including a one-control move or a layout that differs at one breakpoint.
13
+
14
+ It does not apply to a change that alters nothing a person sees (a refactor, a server-only fix with no visible effect).
15
+
16
+ ## The order
17
+
18
+ 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).
20
+ 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
+ 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
+ 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.
23
+ 6. Compare by looking. Screenshot the board in irsim and the running screen at the same width with Playwright, list every difference (layout, spacing, alignment, icons, cell content, header, footer), fix them, and screenshot again. Reading the markup or the component code is not a comparison.
24
+ 7. Keep them in step. Any later change to a screen in the app updates its board in the same change. Add, rename or remove a board and update the project's board index.
25
+
26
+ ## Sections
27
+
28
+ - `design/canvas.json` groups a page's boards in sections: `"sections": [{ "id": "leads", "title": "Leads" }, { "id": "leads-incoming", "title": "Incoming", "parent": "leads", "color": "red" }]`. A board joins one with `"section": "leads-incoming"`.
29
+ - Put one screen in one section, and each group of its states in a sub-section. Sections nest at most 3 levels.
30
+ - `color` is one of `gray` (the default), `blue`, `green`, `amber`, `purple` and `red`. Use it to tell groups apart, for example `red` for error states.
31
+ - A page in `design/canvas.json` has an optional `"icon"`, a Lucide icon name in kebab-case. Give every new page an icon that fits its subject, and change it when the user asks.
32
+ - Place boards 80 units apart so frame titles and section labels have room.
33
+ - A new board without x and y is placed under all existing boards of its page, and a move that overlaps another board pushes that board apart, so do not place boards by hand.
34
+
35
+ ## Rules
36
+
37
+ - A board that shrinks by more than 30% in `git diff --stat` needs the user's yes in chat before you keep it.
38
+ - Shared boards (table, sidebar, topbar, menu, nav) move many screens at once. Say which screens a change touches.
39
+ - Use only the project's design system values. Never pick a close enough color or radius. If a value is missing, ask.
40
+ - Read only the boards you change, with `rg` or `sed -n`, never a whole large board.
41
+ - A pull request that changes UI source without a board change is incomplete, unless the change alters nothing visible and says so.
42
+ - Replies to canvas comments: Reply in at most three short sentences. Put long detail in the board or a file and link to it, not in the reply.
43
+ - Styles that many boards share go in `design/shared/*.css`, helpers in `design/shared/*.js` (the exports reach a board script as `shared.<name>`, for example `design/shared/table-sort.js` as `shared.tableSort`), and images and fonts in `design/shared/`, referenced as `./shared/<path>`. Keep components as `dc-import` boards.
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.