agent-canvas 0.1.19 → 0.1.21

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.
@@ -6,9 +6,10 @@ import { handleWatch } from "./lib/commands/watch.ts";
6
6
  import { handleDaemon } from "./lib/commands/daemon.ts";
7
7
  import { handleInstall } from "./lib/commands/install.ts";
8
8
  import { handleInstructions } from "./lib/commands/instructions.ts";
9
+ import { VERSION } from "./lib/config.ts";
9
10
 
10
11
  function printUsage() {
11
- console.error(`agent-canvas — Interactive visual canvas for Claude Code
12
+ console.log(`agent-canvas v${VERSION} — Interactive visual canvas for Claude Code
12
13
 
13
14
  Commands:
14
15
  agent-canvas install [local|global] Install skill for Claude Code
@@ -28,6 +29,11 @@ Environment:
28
29
  async function main() {
29
30
  const args = process.argv.slice(2);
30
31
 
32
+ if (args[0] === "--version" || args[0] === "-v") {
33
+ console.log(VERSION);
34
+ return;
35
+ }
36
+
31
37
  if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
32
38
  printUsage();
33
39
  process.exit(args.length === 0 ? 1 : 0);
@@ -114,7 +114,14 @@ export async function compilePlan(jsx: string, projectRoot?: string): Promise<Co
114
114
  jsx = resolveMarkdownFiles(jsx, projectRoot);
115
115
  }
116
116
 
117
- const hasDefaultExport = /export\s+default\b/.test(jsx);
117
+ // Strip template literals and strings so `export default` inside CodeBlock
118
+ // content (e.g. {`export default defineConfig(...)`}) doesn't false-positive.
119
+ const strippedJsx = jsx
120
+ .replace(/\{`[^`]*`\}/gs, "") // {`...`} template expressions
121
+ .replace(/`[^`]*`/gs, "") // standalone template literals
122
+ .replace(/"[^"]*"/g, "") // double-quoted strings
123
+ .replace(/'[^']*'/g, ""); // single-quoted strings
124
+ const hasDefaultExport = /export\s+default\b/.test(strippedJsx);
118
125
 
119
126
  const source = hasDefaultExport
120
127
  ? `${COMPONENT_IMPORTS}\n${jsx}`
@@ -57,32 +57,40 @@ export function createApiHandlers(ctx: ApiContext): Route[] {
57
57
 
58
58
  const projectRoot = body.projectRoot || process.cwd();
59
59
  const isNew = !sessionManager.get(sessionId);
60
- const session = sessionManager.upsert(sessionId, canvasFiles, projectRoot, body.label, body.response);
61
60
 
62
- // Compile all canvas files in parallel
61
+ // Compile all canvas files first — only create a revision if at least one succeeds
62
+ const compiled = new Map<string, string>();
63
63
  const errors: Record<string, string> = {};
64
- let anyOk = false;
65
64
  await Promise.all(
66
65
  [...canvasFiles.entries()].map(async ([filename, jsx]) => {
67
- const result = await compilePlan(jsx, session.projectRoot);
66
+ const result = await compilePlan(jsx, projectRoot);
68
67
  if (result.ok) {
69
- sessionManager.saveCompiled(sessionId, filename, result.js, session.currentRevision);
70
- anyOk = true;
68
+ compiled.set(filename, result.js);
71
69
  } else {
72
70
  errors[filename] = result.error;
73
71
  }
74
72
  }),
75
73
  );
76
74
 
77
- if (anyOk) {
78
- broadcastPlanUpdate(sessionId);
75
+ if (compiled.size === 0) {
76
+ return jsonResponse({
77
+ ok: false,
78
+ error: "All canvas files failed to compile",
79
+ errors,
80
+ }, 400);
81
+ }
82
+
83
+ const session = sessionManager.upsert(sessionId, canvasFiles, projectRoot, body.label, body.response);
84
+ for (const [filename, js] of compiled) {
85
+ sessionManager.saveCompiled(sessionId, filename, js, session.currentRevision);
79
86
  }
80
87
 
88
+ broadcastPlanUpdate(sessionId);
81
89
  watchSession(sessionId, sessionManager, broadcastPlanUpdate);
82
90
 
83
91
  const browserUrl = `http://localhost:${port}/s/${sessionId}`;
84
92
  return jsonResponse({
85
- ok: anyOk,
93
+ ok: true,
86
94
  browserUrl,
87
95
  isNew,
88
96
  revision: session.currentRevision,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-canvas",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "description": "Interactive visual canvas for Claude Code — rich annotatable documents in the browser",
5
5
  "bin": {
6
6
  "agent-canvas": "bin/agent-canvas.js"