@creator-notes/cnotes 0.121.3 → 0.121.4

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creator-notes-cli",
3
- "version": "0.121.3",
3
+ "version": "0.121.4",
4
4
  "description": "CreatorNotes CLI: create notes, build canvases, search knowledge from the terminal",
5
5
  "author": {
6
6
  "name": "CreatorNotes",
@@ -5,16 +5,9 @@ import { resolveConfig } from "../lib/config.js";
5
5
  import { handleError, ValidationError, ApiError, CliError, EXIT_CODES, } from "../lib/errors.js";
6
6
  import { outputJson, outputQuiet } from "../lib/output.js";
7
7
  import { extractStorageId } from "../lib/storage-id.js";
8
- import { unsupportedImageTypeMessage } from "../lib/image-types.js";
8
+ import { UPLOAD_MIME_BY_EXT, unsupportedImageTypeMessage } from "../lib/image-types.js";
9
9
  const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
10
- const MIME_MAP = {
11
- ".jpg": "image/jpeg",
12
- ".jpeg": "image/jpeg",
13
- ".png": "image/png",
14
- ".gif": "image/gif",
15
- ".webp": "image/webp",
16
- };
17
- // Reverse of MIME_MAP plus a few extra read-only types, for naming downloads.
10
+ // Reverse of UPLOAD_MIME_BY_EXT plus a few extra read-only types, for naming downloads.
18
11
  const EXT_BY_MIME = {
19
12
  "image/jpeg": "jpg",
20
13
  "image/png": "png",
@@ -24,7 +17,7 @@ const EXT_BY_MIME = {
24
17
  };
25
18
  function getMimeType(filePath) {
26
19
  const ext = path.extname(filePath).toLowerCase();
27
- return MIME_MAP[ext];
20
+ return UPLOAD_MIME_BY_EXT[ext];
28
21
  }
29
22
  function formatBytes(bytes) {
30
23
  if (bytes < 1024)
@@ -16,6 +16,8 @@ import { formatDoneParts } from "../lib/done-parts.js";
16
16
  * every run re-reads the graph, so the tree cannot drift from the notes.
17
17
  */
18
18
  const MAX_GOALS = 100;
19
+ /** Goals read side by side while walking the tree. */
20
+ const LOAD_AT_ONCE = 8;
19
21
  const isGoalType = (type) => typeof type === "string" && type.trim().toLowerCase() === "goal";
20
22
  async function loadGoal(api, workspaceId, displayId) {
21
23
  const [notes, rels, placed] = await Promise.all([
@@ -115,17 +117,23 @@ Examples:
115
117
  if (!isGoalType(root.type)) {
116
118
  throw new ValidationError(`${displayId} is a ${root.type || "untyped"} note. A goal tree starts at a Goal note; create one with \`cnotes notes create --type Goal\`.`);
117
119
  }
120
+ // Breadth first, a few goals at a time: each goal is three or four
121
+ // reads, so one at a time made a 20-goal tree 60+ round trips in a row.
118
122
  const nodes = new Map([[root.displayId, root]]);
119
- const queue = [...root.children];
123
+ let queue = [...root.children];
120
124
  while (queue.length > 0 && nodes.size < MAX_GOALS) {
121
- const id = queue.shift();
122
- if (nodes.has(id))
123
- continue;
124
- const node = await loadGoal(api, cfg.workspaceId, id);
125
- if (!node)
126
- continue;
127
- nodes.set(id, node);
128
- queue.push(...node.children.filter((c) => !nodes.has(c)));
125
+ const batch = [...new Set(queue.filter((id) => !nodes.has(id)))].slice(0, Math.min(LOAD_AT_ONCE, MAX_GOALS - nodes.size));
126
+ if (batch.length === 0)
127
+ break;
128
+ queue = queue.filter((id) => !nodes.has(id) && !batch.includes(id));
129
+ const loaded = await Promise.all(batch.map((id) => loadGoal(api, cfg.workspaceId, id)));
130
+ batch.forEach((id, i) => {
131
+ const node = loaded[i];
132
+ if (!node || nodes.has(id))
133
+ return;
134
+ nodes.set(id, node);
135
+ queue.push(...node.children.filter((c) => !nodes.has(c)));
136
+ });
129
137
  }
130
138
  const view = deriveGoalTree(root.displayId, nodes);
131
139
  if (nodes.size >= MAX_GOALS)
@@ -343,29 +343,6 @@ export function listOpenAgentRuns(config, serverUrl) {
343
343
  }))
344
344
  .sort((a, b) => a.startedAt - b.startedAt);
345
345
  }
346
- /**
347
- * Clear the active agent-run for a server. Called by `cnotes operations end` /
348
- * `cnotes canvas agent-run end` after a successful close, so the next cnotes
349
- * write reverts to "unattached" unless the user opens a new run.
350
- */
351
- export function clearActiveAgentRunId(config, serverUrl) {
352
- mutateServerConfig(config, serverUrl, (sc) => {
353
- if (!(sc.activeAgentRunId || sc.activeAgentRunStartedAt || sc.activeAgentBeforeSnapshotId)) {
354
- return false;
355
- }
356
- // The active run has ended, so it leaves the open-run registry with the
357
- // pointer. Detached runs in the registry are untouched: they are other
358
- // agents' business.
359
- if (sc.activeAgentRunId && sc.agentRuns && sc.activeAgentRunId in sc.agentRuns) {
360
- delete sc.agentRuns[sc.activeAgentRunId];
361
- if (Object.keys(sc.agentRuns).length === 0)
362
- delete sc.agentRuns;
363
- }
364
- delete sc.activeAgentRunId;
365
- delete sc.activeAgentRunStartedAt;
366
- delete sc.activeAgentBeforeSnapshotId;
367
- });
368
- }
369
346
  /**
370
347
  * Read the active agent-run for a server (if any). `beforeSnapshotId` is
371
348
  * present only for canvas runs (see the field docs on ServerConfig).
@@ -1,3 +1,11 @@
1
+ /** The image types the server stores, by extension: what `files upload` and `cnotes_files_upload` send. */
2
+ export const UPLOAD_MIME_BY_EXT = {
3
+ ".jpg": "image/jpeg",
4
+ ".jpeg": "image/jpeg",
5
+ ".png": "image/png",
6
+ ".gif": "image/gif",
7
+ ".webp": "image/webp",
8
+ };
1
9
  /**
2
10
  * The refusal `files upload` and the stdio MCP server's `cnotes_files_upload`
3
11
  * give for a file the server will not store. SVG gets its own reason because
@@ -11,5 +19,5 @@ export function unsupportedImageTypeMessage(ext) {
11
19
  return ("SVG isn't accepted, because an SVG file can carry scripts. Convert it to PNG first " +
12
20
  "(for example `rsvg-convert -o diagram.png diagram.svg`) and upload the PNG.");
13
21
  }
14
- return `Unsupported file type: ${ext}. Allowed: .jpg, .jpeg, .png, .gif, .webp`;
22
+ return `Unsupported file type: ${ext}. Allowed: ${Object.keys(UPLOAD_MIME_BY_EXT).join(", ")}`;
15
23
  }
@@ -168,29 +168,6 @@ export function gradeFromStored(note) {
168
168
  gradedBy: stored.gradedBy,
169
169
  };
170
170
  }
171
- /** @deprecated Server Check quality responses. Kept so a stored body still maps. */
172
- export function gradeFromResponse(body) {
173
- if (body.outcome === "graded" && typeof body.level === "number") {
174
- return {
175
- outcome: "graded",
176
- level: body.level,
177
- label: LADDER_LABELS[body.level] ?? `Level ${body.level}`,
178
- isTopRung: body.level >= LADDER_TOP,
179
- feedback: String(body.feedback ?? ""),
180
- nextStep: String(body.nextStep ?? ""),
181
- suggestions: Array.isArray(body.suggestions) ? body.suggestions.map(String) : [],
182
- criteria: readCriteria(body.criteria),
183
- gradedBy: typeof body.gradedBy === "string" ? body.gradedBy : null,
184
- };
185
- }
186
- if (body.outcome === "needs_agent") {
187
- return { outcome: "needs_agent", reason: String(body.reason ?? AGENT_GRADE_INSTRUCTION) };
188
- }
189
- return {
190
- outcome: "skipped",
191
- reason: String(body.reason ?? body.skipReason ?? "not graded"),
192
- };
193
- }
194
171
  /** The payload handed to the calling agent: rubric, note, and how to record. */
195
172
  export function gradeRequestFor(note, rubric) {
196
173
  const criteriaExample = JSON.stringify([{ criterion: "<name>", reason: "<why>" }]);
@@ -39,7 +39,7 @@ import { runQuery } from "./commands/query.js";
39
39
  import { inToolRun } from "./lib/mcp-run.js";
40
40
  import { isLocalDbEnabled } from "./lib/auth-store.js";
41
41
  import { explainTruncation, listNotes, SERVER_LIST_CAP } from "./lib/notes-list.js";
42
- import { unsupportedImageTypeMessage } from "./lib/image-types.js";
42
+ import { UPLOAD_MIME_BY_EXT, unsupportedImageTypeMessage } from "./lib/image-types.js";
43
43
  // ---------------------------------------------------------------------------
44
44
  // Environment
45
45
  // ---------------------------------------------------------------------------
@@ -1449,13 +1449,6 @@ api.post(`/api/workspaces/${workspaceId}/trial`, { source: "mcp-stdio" })));
1449
1449
  // ---------------------------------------------------------------------------
1450
1450
  // Files
1451
1451
  // ---------------------------------------------------------------------------
1452
- const FILE_MIME_MAP = {
1453
- ".jpg": "image/jpeg",
1454
- ".jpeg": "image/jpeg",
1455
- ".png": "image/png",
1456
- ".gif": "image/gif",
1457
- ".webp": "image/webp",
1458
- };
1459
1452
  server.tool("cnotes_files_upload", "Upload an image file to the workspace. Returns the public URL. Supports .jpg, .jpeg, .png, .gif, .webp (max 5MB). Convert an SVG to PNG first.", {
1460
1453
  filePath: z.string().describe("Absolute path to the image file on disk"),
1461
1454
  }, async ({ filePath }) => withErrorHandling(async () => {
@@ -1473,7 +1466,7 @@ server.tool("cnotes_files_upload", "Upload an image file to the workspace. Retur
1473
1466
  if (stat.size > 5 * 1024 * 1024)
1474
1467
  throw new Error(`File too large (${stat.size} bytes). Maximum is 5MB.`);
1475
1468
  const ext = path.extname(absPath).toLowerCase();
1476
- const mimeType = FILE_MIME_MAP[ext];
1469
+ const mimeType = UPLOAD_MIME_BY_EXT[ext];
1477
1470
  if (!mimeType)
1478
1471
  throw new Error(unsupportedImageTypeMessage(ext));
1479
1472
  const buffer = readFileSync(absPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator-notes/cnotes",
3
- "version": "0.121.3",
3
+ "version": "0.121.4",
4
4
  "description": "CLI for CreatorNotes — create notes, build canvases, search knowledge from the terminal",
5
5
  "type": "module",
6
6
  "bin": {