@fabrika/canvas-kernel 0.9.0-dev.21 → 0.9.0-dev.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/canvas-kernel",
3
- "version": "0.9.0-dev.21",
3
+ "version": "0.9.0-dev.23",
4
4
  "type": "module",
5
5
  "description": "Canvas JSX compiler, session/revision store, renderer and interactive component library.",
6
6
  "license": "MIT",
@@ -64,8 +64,8 @@
64
64
  },
65
65
  "dependencies": {
66
66
  "zod": "^3.25.76",
67
- "@fabrika/annotations": "0.9.0-dev.21",
68
- "@fabrika/daemon-kit": "0.9.0-dev.21",
67
+ "@fabrika/annotations": "0.9.0-dev.23",
68
+ "@fabrika/daemon-kit": "0.9.0-dev.23",
69
69
  "marked": "^17.0.4",
70
70
  "mermaid-parser-bundle": "^0.1.2",
71
71
  "preact": "^10.25.0",
@@ -194,7 +194,8 @@ export function ResponsePreview({ open, onClose, onSubmit, includedRemoteIds, on
194
194
  )
195
195
  }
196
196
 
197
- const UPLOADS_PATH_RE = /!\[([^\]]*)\]\((\/tmp\/agent-canvas\/uploads\/([^)]+))\)/g
197
+ // An upload's absolute path: under agent-canvas's runtime directory, `$XDG_RUNTIME_DIR/agent-canvas` or `<tmpdir>/agent-canvas-<uid>`.
198
+ const UPLOADS_PATH_RE = /!\[([^\]]*)\]\((\/[^)\s]*\/agent-canvas(?:-\d+)?\/uploads\/([^/)]+))\)/g
198
199
 
199
200
  function rewriteUploadPaths(md: string): string {
200
201
  return md.replace(UPLOADS_PATH_RE, (_match, alt, _fullPath, filename) => `![${alt}](/api/uploads/${filename})`)
@@ -1,7 +1,7 @@
1
+ import { ensureRuntimeDir, userRuntimeDir } from '@fabrika/daemon-kit'
1
2
  import { randomUUID } from 'crypto'
2
3
  import { mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'fs'
3
4
  import { parse as parseMermaid } from 'mermaid-parser-bundle'
4
- import { tmpdir } from 'os'
5
5
  import { join, resolve } from 'path'
6
6
  import { type ComponentChildren, type ComponentType, Fragment, h, isValidElement, type Key } from 'preact'
7
7
  import renderToString from 'preact-render-to-string'
@@ -69,9 +69,6 @@ export interface CompileOptions {
69
69
  components?: CanvasComponents
70
70
  }
71
71
 
72
- /** Fallback scratch dir for hosts that compile without wiring CanvasPaths. */
73
- const FALLBACK_COMPILE_DIR = join(tmpdir(), 'canvas-kernel', 'compile')
74
-
75
72
  function componentImports(components: CanvasComponents): string {
76
73
  return `import React from 'react';
77
74
  import * as C from '#canvas/components';
@@ -338,7 +335,8 @@ export async function compileJsx(jsx: string, options: CompileOptions = {}): Pro
338
335
  return { ok: false, error: formatBuildError(syntaxError, lineOffset) }
339
336
  }
340
337
 
341
- const compileDir = options.tempDir ?? FALLBACK_COMPILE_DIR
338
+ // The fallback for hosts that compile without wiring CanvasPaths.
339
+ const compileDir = options.tempDir ?? join(ensureRuntimeDir(userRuntimeDir('canvas-kernel')), 'compile')
342
340
  mkdirSync(compileDir, { recursive: true })
343
341
  const tmpFile = join(compileDir, `plan-${randomUUID()}.jsx`)
344
342
  const configFile = `${tmpFile}.json`
@@ -1,5 +1,6 @@
1
+ import { ensureRuntimeDir, userRuntimeDir } from '@fabrika/daemon-kit'
1
2
  import { mkdirSync } from 'fs'
2
- import { homedir, tmpdir } from 'os'
3
+ import { homedir } from 'os'
3
4
  import { join } from 'path'
4
5
 
5
6
  /**
@@ -14,7 +15,7 @@ export interface CanvasPaths {
14
15
  dataDir: string
15
16
  /** Session + revision store. */
16
17
  sessionsDir: string
17
- /** Ephemeral root — may be lost on reboot. */
18
+ /** Ephemeral root, private to the user — may be lost on reboot. */
18
19
  tempDir: string
19
20
  /** Daemon PID file. */
20
21
  pidFile: string
@@ -33,7 +34,7 @@ export interface CanvasPathsConfig {
33
34
  * and pass the result; the kernel holds no migration policy.
34
35
  */
35
36
  dataDir?: string
36
- /** Ephemeral root. Defaults to `<tmpdir>/<appName>`. */
37
+ /** Ephemeral root. Defaults to the per-user runtime directory, `userRuntimeDir(appName)`. */
37
38
  tempDir?: string
38
39
  /** Create the directories. Pass `false` when only the strings are needed. */
39
40
  ensure?: boolean
@@ -42,7 +43,7 @@ export interface CanvasPathsConfig {
42
43
  export function createCanvasPaths(config: CanvasPathsConfig): CanvasPaths {
43
44
  const { appName, ensure = true } = config
44
45
  const dataDir = config.dataDir ?? join(homedir(), '.claude', appName)
45
- const tempDir = config.tempDir ?? join(tmpdir(), appName)
46
+ const tempDir = config.tempDir ?? userRuntimeDir(appName)
46
47
 
47
48
  const paths: CanvasPaths = {
48
49
  dataDir,
@@ -54,6 +55,7 @@ export function createCanvasPaths(config: CanvasPathsConfig): CanvasPaths {
54
55
  }
55
56
 
56
57
  if (ensure) {
58
+ ensureRuntimeDir(tempDir)
57
59
  mkdirSync(paths.sessionsDir, { recursive: true })
58
60
  mkdirSync(paths.compileTempDir, { recursive: true })
59
61
  mkdirSync(paths.uploadsDir, { recursive: true })
@@ -25,9 +25,9 @@ export declare const planResponseSchema: z.ZodEffects<z.ZodObject<{
25
25
  note: z.ZodOptional<z.ZodString>;
26
26
  }, z.ZodTypeAny, "passthrough">>, {
27
27
  value: unknown;
28
+ type: "select" | "text" | "checkbox" | "radio" | "range";
28
29
  id: string;
29
30
  label: string;
30
- type: "select" | "text" | "checkbox" | "radio" | "range";
31
31
  options?: string[] | undefined;
32
32
  note?: string | undefined;
33
33
  required?: boolean | undefined;
@@ -278,9 +278,9 @@ export declare const persistedStateSchema: z.ZodObject<{
278
278
  note: z.ZodOptional<z.ZodString>;
279
279
  }, z.ZodTypeAny, "passthrough">>, {
280
280
  value: unknown;
281
+ type: "select" | "text" | "checkbox" | "radio" | "range";
281
282
  id: string;
282
283
  label: string;
283
- type: "select" | "text" | "checkbox" | "radio" | "range";
284
284
  options?: string[] | undefined;
285
285
  note?: string | undefined;
286
286
  required?: boolean | undefined;
@@ -294,9 +294,9 @@ export declare const persistedStateSchema: z.ZodObject<{
294
294
  note: z.ZodOptional<z.ZodString>;
295
295
  }, z.ZodTypeAny, "passthrough">>], null>>>, "many">, [string, {
296
296
  value: unknown;
297
+ type: "select" | "text" | "checkbox" | "radio" | "range";
297
298
  id: string;
298
299
  label: string;
299
- type: "select" | "text" | "checkbox" | "radio" | "range";
300
300
  options?: string[] | undefined;
301
301
  note?: string | undefined;
302
302
  required?: boolean | undefined;
@@ -544,9 +544,9 @@ export declare const persistedStateSchema: z.ZodObject<{
544
544
  note: z.ZodOptional<z.ZodString>;
545
545
  }, z.ZodTypeAny, "passthrough">>, {
546
546
  value: unknown;
547
+ type: "select" | "text" | "checkbox" | "radio" | "range";
547
548
  id: string;
548
549
  label: string;
549
- type: "select" | "text" | "checkbox" | "radio" | "range";
550
550
  options?: string[] | undefined;
551
551
  note?: string | undefined;
552
552
  required?: boolean | undefined;
@@ -560,9 +560,9 @@ export declare const persistedStateSchema: z.ZodObject<{
560
560
  note: z.ZodOptional<z.ZodString>;
561
561
  }, z.ZodTypeAny, "passthrough">>], null>>>, "many">, [string, {
562
562
  value: unknown;
563
+ type: "select" | "text" | "checkbox" | "radio" | "range";
563
564
  id: string;
564
565
  label: string;
565
- type: "select" | "text" | "checkbox" | "radio" | "range";
566
566
  options?: string[] | undefined;
567
567
  note?: string | undefined;
568
568
  required?: boolean | undefined;
@@ -810,9 +810,9 @@ export declare const persistedStateSchema: z.ZodObject<{
810
810
  note: z.ZodOptional<z.ZodString>;
811
811
  }, z.ZodTypeAny, "passthrough">>, {
812
812
  value: unknown;
813
+ type: "select" | "text" | "checkbox" | "radio" | "range";
813
814
  id: string;
814
815
  label: string;
815
- type: "select" | "text" | "checkbox" | "radio" | "range";
816
816
  options?: string[] | undefined;
817
817
  note?: string | undefined;
818
818
  required?: boolean | undefined;
@@ -826,9 +826,9 @@ export declare const persistedStateSchema: z.ZodObject<{
826
826
  note: z.ZodOptional<z.ZodString>;
827
827
  }, z.ZodTypeAny, "passthrough">>], null>>>, "many">, [string, {
828
828
  value: unknown;
829
+ type: "select" | "text" | "checkbox" | "radio" | "range";
829
830
  id: string;
830
831
  label: string;
831
- type: "select" | "text" | "checkbox" | "radio" | "range";
832
832
  options?: string[] | undefined;
833
833
  note?: string | undefined;
834
834
  required?: boolean | undefined;
@@ -1077,9 +1077,9 @@ export declare function parsePersistedState(value: unknown): z.objectOutputType<
1077
1077
  note: z.ZodOptional<z.ZodString>;
1078
1078
  }, z.ZodTypeAny, "passthrough">>, {
1079
1079
  value: unknown;
1080
+ type: "select" | "text" | "checkbox" | "radio" | "range";
1080
1081
  id: string;
1081
1082
  label: string;
1082
- type: "select" | "text" | "checkbox" | "radio" | "range";
1083
1083
  options?: string[] | undefined;
1084
1084
  note?: string | undefined;
1085
1085
  required?: boolean | undefined;
@@ -1093,9 +1093,9 @@ export declare function parsePersistedState(value: unknown): z.objectOutputType<
1093
1093
  note: z.ZodOptional<z.ZodString>;
1094
1094
  }, z.ZodTypeAny, "passthrough">>], null>>>, "many">, [string, {
1095
1095
  value: unknown;
1096
+ type: "select" | "text" | "checkbox" | "radio" | "range";
1096
1097
  id: string;
1097
1098
  label: string;
1098
- type: "select" | "text" | "checkbox" | "radio" | "range";
1099
1099
  options?: string[] | undefined;
1100
1100
  note?: string | undefined;
1101
1101
  required?: boolean | undefined;
@@ -10,7 +10,7 @@ export interface CanvasPaths {
10
10
  dataDir: string;
11
11
  /** Session + revision store. */
12
12
  sessionsDir: string;
13
- /** Ephemeral root — may be lost on reboot. */
13
+ /** Ephemeral root, private to the user — may be lost on reboot. */
14
14
  tempDir: string;
15
15
  /** Daemon PID file. */
16
16
  pidFile: string;
@@ -28,7 +28,7 @@ export interface CanvasPathsConfig {
28
28
  * and pass the result; the kernel holds no migration policy.
29
29
  */
30
30
  dataDir?: string;
31
- /** Ephemeral root. Defaults to `<tmpdir>/<appName>`. */
31
+ /** Ephemeral root. Defaults to the per-user runtime directory, `userRuntimeDir(appName)`. */
32
32
  tempDir?: string;
33
33
  /** Create the directories. Pass `false` when only the strings are needed. */
34
34
  ensure?: boolean;
@@ -2699,13 +2699,13 @@ export declare const submittedResponseSchema: z.ZodObject<{
2699
2699
  id: z.ZodString;
2700
2700
  value: z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodNumber]>;
2701
2701
  }, "strip", z.ZodTypeAny, {
2702
- id: string;
2703
2702
  value: string | number | string[];
2704
- }, {
2705
2703
  id: string;
2704
+ }, {
2706
2705
  value: string | number | string[];
2706
+ id: string;
2707
2707
  }>;
2708
2708
  export declare const submittedResponsesSchema: z.ZodEffects<z.ZodArray<z.ZodUnknown, "many">, {
2709
- id: string;
2710
2709
  value: string | number | string[];
2710
+ id: string;
2711
2711
  }[], unknown[]>;