@fabrika/canvas-kernel 0.1.45 → 0.3.1

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 (70) hide show
  1. package/README.md +33 -67
  2. package/index.ts +20 -83
  3. package/package.json +69 -72
  4. package/src/client/AnnotationProvider.tsx +218 -255
  5. package/src/client/AnnotationSidebar.tsx +393 -338
  6. package/src/client/FileIcon.tsx +105 -66
  7. package/src/client/PlanRenderer.tsx +607 -551
  8. package/src/client/RenderErrorContext.ts +7 -7
  9. package/src/client/ResponsePreview.tsx +192 -173
  10. package/src/client/annotationDom.ts +43 -97
  11. package/src/client/annotationDraft.ts +106 -96
  12. package/src/client/appContext.tsx +40 -40
  13. package/src/client/components/Callout.tsx +20 -20
  14. package/src/client/components/Checklist.tsx +27 -29
  15. package/src/client/components/Choice.tsx +178 -159
  16. package/src/client/components/CodeBlock.tsx +27 -26
  17. package/src/client/components/Diff.tsx +16 -17
  18. package/src/client/components/FilePreview.tsx +102 -74
  19. package/src/client/components/Image.tsx +41 -39
  20. package/src/client/components/Markdown.tsx +33 -32
  21. package/src/client/components/Mermaid.tsx +593 -542
  22. package/src/client/components/Note.tsx +8 -8
  23. package/src/client/components/Priority.tsx +10 -12
  24. package/src/client/components/ResponseNote.tsx +16 -15
  25. package/src/client/components/Section.tsx +28 -26
  26. package/src/client/components/Table.tsx +33 -30
  27. package/src/client/components/Task.tsx +58 -60
  28. package/src/client/components/UserInput.tsx +169 -152
  29. package/src/client/components/index.ts +16 -16
  30. package/src/client/components/renderMarkdownChildren.tsx +86 -68
  31. package/src/client/diffLines.ts +51 -39
  32. package/src/client/generateMarkdown.ts +197 -191
  33. package/src/client/hostContext.tsx +39 -34
  34. package/src/client/index.ts +44 -125
  35. package/src/client/pageGlobals.ts +25 -0
  36. package/src/client/persistenceSchemas.ts +41 -0
  37. package/src/client/preact-all.ts +4 -4
  38. package/src/client/runtime.ts +58 -111
  39. package/src/client/styles.css +1 -74
  40. package/src/engine/compiler.ts +411 -323
  41. package/src/engine/file-admission.ts +25 -0
  42. package/src/engine/paths.ts +44 -44
  43. package/src/engine/session.ts +515 -626
  44. package/src/engine/sessionSchemas.ts +71 -0
  45. package/src/engine/watcher.ts +70 -60
  46. package/src/engine/websocket.ts +134 -132
  47. package/annotate.ts +0 -94
  48. package/daemon.ts +0 -46
  49. package/src/client/AnnotationDraftFooter.tsx +0 -76
  50. package/src/client/AnnotationEditor.tsx +0 -320
  51. package/src/client/AnnotationList.tsx +0 -190
  52. package/src/client/Popover.tsx +0 -361
  53. package/src/client/SessionContext.tsx +0 -3
  54. package/src/client/annotationContext.ts +0 -130
  55. package/src/client/annotationMarkdown.ts +0 -102
  56. package/src/client/annotationTarget.ts +0 -73
  57. package/src/client/blockTarget.ts +0 -127
  58. package/src/client/highlightRange.ts +0 -262
  59. package/src/client/popoverPosition.ts +0 -46
  60. package/src/client/regionTarget.ts +0 -180
  61. package/src/client/testing/dom.ts +0 -74
  62. package/src/client/textTarget.ts +0 -31
  63. package/src/client/useRegionAnnotation.tsx +0 -188
  64. package/src/client/useTextAnnotation.tsx +0 -194
  65. package/src/client/utils.ts +0 -33
  66. package/src/engine/channel.ts +0 -278
  67. package/src/engine/http-utils.ts +0 -14
  68. package/src/engine/lifecycle.ts +0 -302
  69. package/src/engine/router.ts +0 -16
  70. package/src/engine/waiter.ts +0 -188
@@ -0,0 +1,25 @@
1
+ import { readFileSync, realpathSync } from 'node:fs'
2
+ import { resolve } from 'node:path'
3
+
4
+ export type AssertReadable = (path: string) => void
5
+
6
+ export class CanvasFileAdmissionError extends Error {
7
+ constructor() {
8
+ super('Canvas file access refused')
9
+ }
10
+ }
11
+
12
+ export function assertCanvasFileReadable(path: string, assertReadable?: AssertReadable): void {
13
+ if (!assertReadable) return
14
+ try {
15
+ assertReadable(resolve(path))
16
+ assertReadable(realpathSync(path))
17
+ } catch {
18
+ throw new CanvasFileAdmissionError()
19
+ }
20
+ }
21
+
22
+ export function readCanvasFile(path: string, assertReadable?: AssertReadable): string {
23
+ assertCanvasFileReadable(path, assertReadable)
24
+ return readFileSync(path, 'utf-8')
25
+ }
@@ -1,6 +1,6 @@
1
- import { join } from "path";
2
- import { tmpdir, homedir } from "os";
3
- import { mkdirSync } from "fs";
1
+ import { mkdirSync } from 'fs'
2
+ import { homedir, tmpdir } from 'os'
3
+ import { join } from 'path'
4
4
 
5
5
  /**
6
6
  * On-disk layout for one canvas host (agent-canvas, fabrika, …).
@@ -10,54 +10,54 @@ import { mkdirSync } from "fs";
10
10
  * coexist in one process (tests rely on this).
11
11
  */
12
12
  export interface CanvasPaths {
13
- /** Persistent root — survives reboots. */
14
- dataDir: string;
15
- /** Session + revision store. */
16
- sessionsDir: string;
17
- /** Ephemeral root — may be lost on reboot. */
18
- tempDir: string;
19
- /** Daemon PID file. */
20
- pidFile: string;
21
- /** Scratch space for JSX compilation. */
22
- compileTempDir: string;
23
- /** Uploaded annotation images. */
24
- uploadsDir: string;
13
+ /** Persistent root — survives reboots. */
14
+ dataDir: string
15
+ /** Session + revision store. */
16
+ sessionsDir: string
17
+ /** Ephemeral root — may be lost on reboot. */
18
+ tempDir: string
19
+ /** Daemon PID file. */
20
+ pidFile: string
21
+ /** Scratch space for JSX compilation. */
22
+ compileTempDir: string
23
+ /** Uploaded annotation images. */
24
+ uploadsDir: string
25
25
  }
26
26
 
27
27
  export interface CanvasPathsConfig {
28
- /** Namespace for on-disk locations, e.g. `"agent-canvas"` or `"fabrika"`. */
29
- appName: string;
30
- /**
31
- * Persistent root. Defaults to `~/.claude/<appName>`. Hosts that keep data
32
- * elsewhere — or that migrate from a legacy location — resolve it themselves
33
- * and pass the result; the kernel holds no migration policy.
34
- */
35
- dataDir?: string;
36
- /** Ephemeral root. Defaults to `<tmpdir>/<appName>`. */
37
- tempDir?: string;
38
- /** Create the directories. Pass `false` when only the strings are needed. */
39
- ensure?: boolean;
28
+ /** Namespace for on-disk locations, e.g. `"agent-canvas"` or `"fabrika"`. */
29
+ appName: string
30
+ /**
31
+ * Persistent root. Defaults to `~/.claude/<appName>`. Hosts that keep data
32
+ * elsewhere — or that migrate from a legacy location — resolve it themselves
33
+ * and pass the result; the kernel holds no migration policy.
34
+ */
35
+ dataDir?: string
36
+ /** Ephemeral root. Defaults to `<tmpdir>/<appName>`. */
37
+ tempDir?: string
38
+ /** Create the directories. Pass `false` when only the strings are needed. */
39
+ ensure?: boolean
40
40
  }
41
41
 
42
42
  export function createCanvasPaths(config: CanvasPathsConfig): CanvasPaths {
43
- const { appName, ensure = true } = config;
44
- const dataDir = config.dataDir ?? join(homedir(), ".claude", appName);
45
- const tempDir = config.tempDir ?? join(tmpdir(), appName);
43
+ const { appName, ensure = true } = config
44
+ const dataDir = config.dataDir ?? join(homedir(), '.claude', appName)
45
+ const tempDir = config.tempDir ?? join(tmpdir(), appName)
46
46
 
47
- const paths: CanvasPaths = {
48
- dataDir,
49
- sessionsDir: join(dataDir, "sessions"),
50
- tempDir,
51
- pidFile: join(tempDir, "daemon.pid"),
52
- compileTempDir: join(tempDir, "compile"),
53
- uploadsDir: join(tempDir, "uploads"),
54
- };
47
+ const paths: CanvasPaths = {
48
+ dataDir,
49
+ sessionsDir: join(dataDir, 'sessions'),
50
+ tempDir,
51
+ pidFile: join(tempDir, 'daemon.pid'),
52
+ compileTempDir: join(tempDir, 'compile'),
53
+ uploadsDir: join(tempDir, 'uploads'),
54
+ }
55
55
 
56
- if (ensure) {
57
- mkdirSync(paths.sessionsDir, { recursive: true });
58
- mkdirSync(paths.compileTempDir, { recursive: true });
59
- mkdirSync(paths.uploadsDir, { recursive: true });
60
- }
56
+ if (ensure) {
57
+ mkdirSync(paths.sessionsDir, { recursive: true })
58
+ mkdirSync(paths.compileTempDir, { recursive: true })
59
+ mkdirSync(paths.uploadsDir, { recursive: true })
60
+ }
61
61
 
62
- return paths;
62
+ return paths
63
63
  }