agent-canvas 0.1.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.
Files changed (65) hide show
  1. package/bin/agent-canvas.js +14 -0
  2. package/bin/agent-canvas.ts +377 -0
  3. package/daemon/build.ts +185 -0
  4. package/daemon/client/AnnotationProvider.tsx +185 -0
  5. package/daemon/client/AnnotationSidebar.tsx +314 -0
  6. package/daemon/client/App.tsx +611 -0
  7. package/daemon/client/CompareView.tsx +333 -0
  8. package/daemon/client/FileBrowser.tsx +188 -0
  9. package/daemon/client/FileIcon.tsx +76 -0
  10. package/daemon/client/FileViewer.tsx +207 -0
  11. package/daemon/client/PlanRenderer.tsx +665 -0
  12. package/daemon/client/Popover.tsx +285 -0
  13. package/daemon/client/ResponsePreview.tsx +260 -0
  14. package/daemon/client/RevisionSelect.tsx +97 -0
  15. package/daemon/client/SessionContext.tsx +3 -0
  16. package/daemon/client/SessionSwitcher.tsx +72 -0
  17. package/daemon/client/annotationContext.ts +114 -0
  18. package/daemon/client/components/Callout.tsx +25 -0
  19. package/daemon/client/components/Checklist.tsx +37 -0
  20. package/daemon/client/components/Choice.tsx +164 -0
  21. package/daemon/client/components/CodeBlock.tsx +35 -0
  22. package/daemon/client/components/Diff.tsx +65 -0
  23. package/daemon/client/components/FilePreview.tsx +88 -0
  24. package/daemon/client/components/Image.tsx +45 -0
  25. package/daemon/client/components/Mermaid.tsx +277 -0
  26. package/daemon/client/components/Note.tsx +13 -0
  27. package/daemon/client/components/Priority.tsx +19 -0
  28. package/daemon/client/components/ResponseNote.tsx +24 -0
  29. package/daemon/client/components/Section.tsx +32 -0
  30. package/daemon/client/components/Table.tsx +35 -0
  31. package/daemon/client/components/Task.tsx +75 -0
  32. package/daemon/client/components/UserInput.tsx +180 -0
  33. package/daemon/client/components/index.ts +15 -0
  34. package/daemon/client/domDiff.ts +336 -0
  35. package/daemon/client/exportMarkdown.ts +267 -0
  36. package/daemon/client/generateMarkdown.ts +194 -0
  37. package/daemon/client/highlightRange.ts +233 -0
  38. package/daemon/client/index.html +26 -0
  39. package/daemon/client/lcs.ts +19 -0
  40. package/daemon/client/popoverPosition.ts +31 -0
  41. package/daemon/client/runtime.ts +89 -0
  42. package/daemon/client/styles.css +306 -0
  43. package/daemon/client/theme.css +66 -0
  44. package/daemon/client/unifiedDiff.ts +604 -0
  45. package/daemon/dist/client.css +2 -0
  46. package/daemon/dist/client.js +68 -0
  47. package/daemon/dist/components.js +5 -0
  48. package/daemon/dist/index.html +108 -0
  49. package/daemon/dist/jsx-dev-runtime-shim.js +17 -0
  50. package/daemon/dist/jsx-runtime-shim.js +17 -0
  51. package/daemon/dist/react-dom-client-shim.js +4 -0
  52. package/daemon/dist/react-dom-shim.js +4 -0
  53. package/daemon/dist/react-shim.js +4 -0
  54. package/daemon/dist/runtime.js +1 -0
  55. package/daemon/dist/theme.css +66 -0
  56. package/daemon/src/compiler.ts +92 -0
  57. package/daemon/src/paths.ts +22 -0
  58. package/daemon/src/server.ts +448 -0
  59. package/daemon/src/session.ts +274 -0
  60. package/daemon/src/watcher.ts +59 -0
  61. package/hooks/session-start.sh +11 -0
  62. package/package.json +39 -0
  63. package/skills/canvas/SKILL.md +174 -0
  64. package/skills/canvas/components.md +349 -0
  65. package/skills/canvas/flows.md +406 -0
@@ -0,0 +1,349 @@
1
+ # Component Reference
2
+
3
+ All components are available globally in canvas JSX — no imports needed.
4
+ For inline styling use `style={{ ... }}`. Tailwind classes are NOT available.
5
+
6
+ ---
7
+
8
+ ## Layout
9
+
10
+ ### `<Section title="string">`
11
+
12
+ Top-level grouping. Rendered as a serif heading with generous spacing.
13
+ Collapsible (chevron appears on hover). Children are the section body.
14
+
15
+ ```jsx
16
+ <Section title="Phase 1: Data Migration">
17
+ A brief description of this section.
18
+
19
+ {/* Items, callouts, code blocks, diagrams, etc. */}
20
+ </Section>
21
+ ```
22
+
23
+ **Props:**
24
+ - `title` (string, required) — section heading, rendered in Instrument Serif
25
+ - `collapsed` (boolean, default false) — start collapsed
26
+
27
+ ---
28
+
29
+ ### `<Item id="string" label="string">`
30
+
31
+ The primary content block. A flexible card-like row used for tasks, findings, requirements, observations, options — anything that has a title and details.
32
+
33
+ Previously called "Task" — Item is the generalized version. It's a labeled sub-section with an optional status dot, badge, and children for details.
34
+
35
+ ```jsx
36
+ {/* As a plan task */}
37
+ <Item id="migrate-db" label="Run database migration" badge="todo">
38
+ Execute the migration script against staging first.
39
+ <CodeBlock language="bash">npm run migrate:staging</CodeBlock>
40
+ </Item>
41
+
42
+ {/* As a review finding */}
43
+ <Item id="finding-1" label="Missing null check in auth handler" badge="critical" badgeVariant="danger">
44
+ The handler doesn't check for missing tokens.
45
+ <FilePreview path="src/auth.ts" lines={[42, 48]} />
46
+ </Item>
47
+
48
+ {/* As a requirement */}
49
+ <Item id="req-auth" label="JWT authentication" badge="must-have" badgeVariant="danger">
50
+ All API endpoints must require a valid JWT token.
51
+ </Item>
52
+
53
+ {/* As an architecture component */}
54
+ <Item label="API Gateway" badge="core" badgeVariant="info">
55
+ Routes requests to downstream services. Handles rate limiting.
56
+ </Item>
57
+ ```
58
+
59
+ **Props:**
60
+ - `id` (string) — unique ID. Required if the item should be individually addressable in feedback. Optional for informational items.
61
+ - `label` (string, required) — item title, rendered in Inter 600
62
+ - `badge` (string) — short label shown as a small tag. Freeform text.
63
+ - `badgeVariant` ("default" | "success" | "warning" | "danger" | "info") — badge color. Default is neutral gray.
64
+ - `status` ("todo" | "done" | "blocked" | "in-progress") — shows a colored dot. Alternative to badge for plan-style items.
65
+
66
+ **Badge vs Status**: Use `status` for things with a workflow state (tasks in a plan). Use `badge` for categorical labels (requirement priority, review severity, component type). You can use both on the same Item if needed.
67
+
68
+ **Children**: Any content — text, components, code blocks, file previews, nested items. Rendered indented under the label.
69
+
70
+ ---
71
+
72
+ ## Code & Files
73
+
74
+ ### `<FilePreview path="string">`
75
+
76
+ Shows a syntax-highlighted preview of a project file. The daemon serves the file content from the project root.
77
+
78
+ ```jsx
79
+ <FilePreview path="src/auth/middleware.ts" />
80
+ <FilePreview path="src/auth/middleware.ts" lines={[42, 87]} />
81
+ ```
82
+
83
+ **Props:**
84
+ - `path` (string, required) — relative to project root
85
+ - `lines` ([number, number]) — line range to show. Omit for full file.
86
+
87
+ ### `<CodeBlock language="string">`
88
+
89
+ Inline code block with syntax highlighting. For code that's part of the narrative, not from a file on disk.
90
+
91
+ ```jsx
92
+ <CodeBlock language="typescript">
93
+ interface User {
94
+ id: string;
95
+ email: string;
96
+ }
97
+ </CodeBlock>
98
+ ```
99
+
100
+ **Props:**
101
+ - `language` (string) — syntax highlighting language
102
+
103
+ ### `<Diff before="string" after="string">`
104
+
105
+ Shows a diff view between two code snippets.
106
+
107
+ ```jsx
108
+ <Diff language="typescript"
109
+ before={`function auth(req) {\n return true;\n}`}
110
+ after={`function auth(req) {\n const token = req.headers.authorization;\n if (!token) throw new Error('Unauthorized');\n return verify(token);\n}`}
111
+ />
112
+ ```
113
+
114
+ **Props:**
115
+ - `before` (string, required) — original code
116
+ - `after` (string, required) — modified code
117
+ - `language` (string) — syntax highlighting language
118
+
119
+ ---
120
+
121
+ ## Content
122
+
123
+ ### `<Callout type="string">`
124
+
125
+ Highlighted information block. Background-tinted, no border.
126
+
127
+ ```jsx
128
+ <Callout type="warning">
129
+ This will invalidate all existing sessions. Plan a maintenance window.
130
+ </Callout>
131
+ ```
132
+
133
+ **Props:**
134
+ - `type` ("info" | "warning" | "danger" | "tip") — determines color and icon
135
+
136
+ ### `<Note>`
137
+
138
+ Softer than Callout. For asides, context, non-critical info.
139
+
140
+ ```jsx
141
+ <Note>
142
+ This pattern is also used in the payment service — see src/payments/auth.ts.
143
+ </Note>
144
+ ```
145
+
146
+ ### `<Priority level="string" />`
147
+
148
+ Inline badge. Use inside Item labels or body text.
149
+
150
+ ```jsx
151
+ <Item label="Fix the race condition">
152
+ <Priority level="high" /> This causes data corruption under load.
153
+ </Item>
154
+ ```
155
+
156
+ **Props:**
157
+ - `level` ("high" | "medium" | "low")
158
+
159
+ ---
160
+
161
+ ## Data Display
162
+
163
+ ### `<Table headers={[...]} rows={[[...], ...]} />`
164
+
165
+ Simple data table.
166
+
167
+ ```jsx
168
+ <Table
169
+ headers={["Endpoint", "Method", "Auth"]}
170
+ rows={[
171
+ ["/users", "GET", "Required"],
172
+ ["/users/:id", "PUT", "Owner only"],
173
+ ["/health", "GET", "None"],
174
+ ]}
175
+ />
176
+ ```
177
+
178
+ ### `<Checklist items={[...]} />`
179
+
180
+ Visual checklist. Read-only display (feedback via annotations).
181
+
182
+ ```jsx
183
+ <Checklist items={[
184
+ { label: "Run migration on staging", checked: true },
185
+ { label: "Verify data integrity", checked: false },
186
+ { label: "Update API docs", checked: false },
187
+ ]} />
188
+ ```
189
+
190
+ ### `<Mermaid>`
191
+
192
+ Renders a Mermaid diagram. Supports flowchart, sequence, ER, gantt, pie, etc.
193
+ The daemon bundles mermaid.js with a custom dark theme matching Canvas colors.
194
+
195
+ ```jsx
196
+ <Mermaid>{`
197
+ graph TD
198
+ A[Client] -->|HTTP| B(API Gateway)
199
+ B --> C{Auth?}
200
+ C -->|Valid| D[Service]
201
+ C -->|Invalid| E[401 Response]
202
+ `}</Mermaid>
203
+ ```
204
+
205
+ For complex diagrams, prefer Mermaid over raw SVG. Use raw `<svg>` only when Mermaid can't express what you need (custom visual layouts, non-standard diagrams).
206
+
207
+ ---
208
+
209
+ ## Interactive (User Input)
210
+
211
+ Interactive components collect structured responses. They appear in feedback as `[component-id]: value`. Each has an optional "Add note" affordance for extra context.
212
+
213
+ ### `<Choice id="string" label="string" options={[...]} />`
214
+
215
+ Single-select radio group.
216
+
217
+ ```jsx
218
+ <Choice id="db-choice" label="Which database?" required
219
+ options={["PostgreSQL", "SQLite", "MongoDB"]} />
220
+ ```
221
+
222
+ ### `<MultiChoice id="string" label="string" options={[...]} />`
223
+
224
+ Multi-select checkboxes.
225
+
226
+ ```jsx
227
+ <MultiChoice id="affected-areas" label="Which areas need changes?" required
228
+ options={["Models", "API", "Frontend", "Tests"]} />
229
+ ```
230
+
231
+ ### `<UserInput id="string" label="string" />`
232
+
233
+ Free text input.
234
+
235
+ ```jsx
236
+ <UserInput id="constraints" label="Any constraints I should know about?"
237
+ placeholder="e.g. must work with existing Redis setup" required />
238
+ ```
239
+
240
+ ### `<RangeInput id="string" label="string" />`
241
+
242
+ Slider for numeric ranges or scales.
243
+
244
+ ```jsx
245
+ <RangeInput id="effort-tolerance" label="How much refactoring is acceptable?"
246
+ min={1} max={5} minLabel="Minimal changes" maxLabel="Full rewrite OK" required />
247
+ ```
248
+
249
+ **Common props for all interactive components:**
250
+ - `id` (string, required) — unique, used as key in feedback
251
+ - `label` (string, required) — question text
252
+ - `required` (boolean) — prevents submit until answered
253
+ - `placeholder` (string) — hint text (UserInput only)
254
+
255
+ ---
256
+
257
+ ## Programmatic Feedback — `useFeedback`
258
+
259
+ Hook for custom components to contribute computed/derived data to the feedback response. Use when built-in interactive components (`Choice`, `UserInput`, etc.) don't cover your needs.
260
+
261
+ ```jsx
262
+ useFeedback(id: string, markdown: string, options?: { label?: string; required?: boolean })
263
+ ```
264
+
265
+ **Props:**
266
+ - `id` (string, required) — unique feedback entry identifier
267
+ - `markdown` (string, required) — markdown included in feedback, re-evaluated each render
268
+ - `options.label` — display label in feedback preview
269
+ - `options.required` — blocks submit while markdown is empty
270
+
271
+ Registers on mount, updates on change, unregisters on unmount.
272
+
273
+ ```jsx
274
+ function ProConList() {
275
+ const [pros, setPros] = React.useState(["Fast builds"]);
276
+ const [cons, setCons] = React.useState(["New runtime"]);
277
+
278
+ useFeedback(
279
+ "pro-con",
280
+ `**Pros:** ${pros.join(", ")}\n**Cons:** ${cons.join(", ")}`,
281
+ { label: "Pro/Con Analysis" },
282
+ );
283
+
284
+ return <div>{/* UI for managing pros/cons */}</div>;
285
+ }
286
+ ```
287
+
288
+ ---
289
+
290
+ ## Custom Components
291
+
292
+ When you use the full module format (`export default function Canvas()`), you can define custom helper components:
293
+
294
+ ```jsx
295
+ function Metric({ label, value, trend }) {
296
+ const color = trend === 'up' ? '#4a9e6d' : trend === 'down' ? '#c45a5a' : '#a09a92';
297
+ return (
298
+ <div style={{ display: 'flex', gap: 12, alignItems: 'baseline' }}>
299
+ <span style={{ color: '#6b6560', fontSize: '0.75rem' }}>{label}</span>
300
+ <span style={{ color, fontSize: '1.25rem', fontWeight: 600 }}>{value}</span>
301
+ </div>
302
+ );
303
+ }
304
+
305
+ export default function Canvas() {
306
+ return (
307
+ <Section title="Performance Summary">
308
+ <Metric label="P95 Latency" value="42ms" trend="down" />
309
+ <Metric label="Error Rate" value="0.3%" trend="up" />
310
+ <Metric label="Throughput" value="1.2k rps" trend="up" />
311
+ </Section>
312
+ );
313
+ }
314
+ ```
315
+
316
+ Standard components remain available without import even in full module format.
317
+
318
+ ---
319
+
320
+ ## Diagrams with Raw SVG
321
+
322
+ For custom visuals that Mermaid can't express, write `<svg>` directly.
323
+ Use Canvas CSS variables for colors to match the theme:
324
+
325
+ ```jsx
326
+ <svg viewBox="0 0 400 200" style={{ width: '100%', maxWidth: 400 }}>
327
+ <rect x="10" y="10" width="120" height="50" rx="8"
328
+ fill="rgba(90, 142, 196, 0.12)" stroke="rgba(90, 142, 196, 0.3)" />
329
+ <text x="70" y="40" textAnchor="middle" fill="#e8e4df" fontSize="13"
330
+ fontFamily="Inter, sans-serif">API Gateway</text>
331
+
332
+ <line x1="130" y1="35" x2="180" y2="35" stroke="#6b6560" strokeWidth="1.5"
333
+ markerEnd="url(#arrow)" />
334
+
335
+ <rect x="180" y="10" width="120" height="50" rx="8"
336
+ fill="rgba(74, 158, 109, 0.12)" stroke="rgba(74, 158, 109, 0.3)" />
337
+ <text x="240" y="40" textAnchor="middle" fill="#e8e4df" fontSize="13"
338
+ fontFamily="Inter, sans-serif">Auth Service</text>
339
+
340
+ <defs>
341
+ <marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6"
342
+ orient="auto-start-reverse">
343
+ <path d="M 0 0 L 10 5 L 0 10 z" fill="#6b6560" />
344
+ </marker>
345
+ </defs>
346
+ </svg>
347
+ ```
348
+
349
+ Keep SVG diagrams simple. For anything with more than ~5 nodes, prefer Mermaid.