@creator-notes/cnotes 0.79.0 → 0.81.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 (92) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +1 -0
  3. package/dist/commands/auth-keys.js +2 -2
  4. package/dist/commands/auth-keys.js.map +1 -1
  5. package/dist/commands/brief.js +1 -1
  6. package/dist/commands/brief.js.map +1 -1
  7. package/dist/commands/canvas-milestone.js +3 -3
  8. package/dist/commands/canvas-milestone.js.map +1 -1
  9. package/dist/commands/canvas.d.ts.map +1 -1
  10. package/dist/commands/canvas.js +125 -78
  11. package/dist/commands/canvas.js.map +1 -1
  12. package/dist/commands/deps.js +3 -3
  13. package/dist/commands/deps.js.map +1 -1
  14. package/dist/commands/draft.d.ts.map +1 -1
  15. package/dist/commands/draft.js +301 -141
  16. package/dist/commands/draft.js.map +1 -1
  17. package/dist/commands/feedback.js +3 -3
  18. package/dist/commands/feedback.js.map +1 -1
  19. package/dist/commands/files.js +3 -3
  20. package/dist/commands/files.js.map +1 -1
  21. package/dist/commands/focus.js +3 -3
  22. package/dist/commands/focus.js.map +1 -1
  23. package/dist/commands/init.js +1 -1
  24. package/dist/commands/init.js.map +1 -1
  25. package/dist/commands/notes.d.ts.map +1 -1
  26. package/dist/commands/notes.js +15 -14
  27. package/dist/commands/notes.js.map +1 -1
  28. package/dist/commands/operations.d.ts +9 -0
  29. package/dist/commands/operations.d.ts.map +1 -1
  30. package/dist/commands/operations.js +152 -49
  31. package/dist/commands/operations.js.map +1 -1
  32. package/dist/commands/quality.js +1 -1
  33. package/dist/commands/quality.js.map +1 -1
  34. package/dist/commands/relationships.js +3 -3
  35. package/dist/commands/relationships.js.map +1 -1
  36. package/dist/commands/review.d.ts.map +1 -1
  37. package/dist/commands/review.js +10 -7
  38. package/dist/commands/review.js.map +1 -1
  39. package/dist/commands/schema.js +1 -1
  40. package/dist/commands/schema.js.map +1 -1
  41. package/dist/commands/search.js +2 -2
  42. package/dist/commands/search.js.map +1 -1
  43. package/dist/commands/shared.js +1 -1
  44. package/dist/commands/shared.js.map +1 -1
  45. package/dist/commands/theme.js +5 -5
  46. package/dist/commands/theme.js.map +1 -1
  47. package/dist/commands/timeline.js +1 -1
  48. package/dist/commands/timeline.js.map +1 -1
  49. package/dist/commands/types.js +4 -4
  50. package/dist/commands/types.js.map +1 -1
  51. package/dist/commands/upgrade.js +1 -1
  52. package/dist/commands/upgrade.js.map +1 -1
  53. package/dist/commands/versions.js +2 -2
  54. package/dist/commands/versions.js.map +1 -1
  55. package/dist/commands/workspace.d.ts.map +1 -1
  56. package/dist/commands/workspace.js +90 -9
  57. package/dist/commands/workspace.js.map +1 -1
  58. package/dist/lib/active-run.d.ts +62 -0
  59. package/dist/lib/active-run.d.ts.map +1 -0
  60. package/dist/lib/active-run.js +75 -0
  61. package/dist/lib/active-run.js.map +1 -0
  62. package/dist/lib/api-client.d.ts +19 -1
  63. package/dist/lib/api-client.d.ts.map +1 -1
  64. package/dist/lib/api-client.js +32 -2
  65. package/dist/lib/api-client.js.map +1 -1
  66. package/dist/lib/auth-store.d.ts +66 -0
  67. package/dist/lib/auth-store.d.ts.map +1 -1
  68. package/dist/lib/auth-store.js +204 -28
  69. package/dist/lib/auth-store.js.map +1 -1
  70. package/dist/lib/build-schema.d.ts +1 -1
  71. package/dist/lib/build-schema.js +1 -1
  72. package/dist/lib/build-schema.js.map +1 -1
  73. package/dist/lib/config.d.ts +14 -0
  74. package/dist/lib/config.d.ts.map +1 -1
  75. package/dist/lib/config.js +20 -5
  76. package/dist/lib/config.js.map +1 -1
  77. package/dist/lib/draft-view.d.ts +306 -0
  78. package/dist/lib/draft-view.d.ts.map +1 -0
  79. package/dist/lib/draft-view.js +358 -0
  80. package/dist/lib/draft-view.js.map +1 -0
  81. package/dist/lib/errors.d.ts +6 -0
  82. package/dist/lib/errors.d.ts.map +1 -1
  83. package/dist/lib/errors.js +64 -1
  84. package/dist/lib/errors.js.map +1 -1
  85. package/dist/lib/urls.d.ts +15 -0
  86. package/dist/lib/urls.d.ts.map +1 -1
  87. package/dist/lib/urls.js +20 -0
  88. package/dist/lib/urls.js.map +1 -1
  89. package/dist/mcp-server.js +6 -2
  90. package/dist/mcp-server.js.map +1 -1
  91. package/package.json +1 -1
  92. package/skills/cnotes/SKILL.md +104 -64
@@ -2,11 +2,12 @@ import { writeFileSync } from "node:fs";
2
2
  import path from "node:path";
3
3
  import { Option } from "commander";
4
4
  import { ApiClient, resolveActiveAgentRun } from "../lib/api-client.js";
5
+ import { resolveActiveSlot, fetchRunStatus, isStillOpen } from "../lib/active-run.js";
5
6
  import { resolveBaseConfig, resolveConfig } from "../lib/config.js";
6
7
  import { ApiError, CliError, EXIT_CODES, handleError, ValidationError } from "../lib/errors.js";
7
8
  import { parseJsonOption, readFileSafe } from "../lib/fs-utils.js";
8
- import { loadConfig, setActiveAgentRunId, clearActiveAgentRunId, getActiveAgentRunId, } from "../lib/auth-store.js";
9
- import { outputJson, outputTable, outputQuiet, truncate, timeAgo, formatAgo } from "../lib/output.js";
9
+ import { loadConfig, setActiveAgentRunId, registerAgentRun, unregisterAgentRun, isOwnedAgentRun, } from "../lib/auth-store.js";
10
+ import { outputJson, outputTable, outputQuiet, truncate, timeAgo } from "../lib/output.js";
10
11
  import { readHeadlineWarnings, reportHeadlineWarnings } from "../lib/headline-warnings.js";
11
12
  import { readCanvasMarkdown, renderCanvasMarkdown, parseSharedCanvasLink, sameServerOrigin, readCanvasSection, renderCanvasSectionMarkdown, } from "../lib/canvas-read.js";
12
13
  import { resolveAgentSession } from "../lib/claude-session.js";
@@ -154,7 +155,7 @@ Examples:
154
155
  `)
155
156
  .action(async (opts) => {
156
157
  const cfg = resolveConfig(program.opts());
157
- const api = new ApiClient(cfg.serverUrl, cfg.token);
158
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
158
159
  try {
159
160
  const limit = Math.max(1, parseInt(opts.limit ?? "20", 10) || 20);
160
161
  const params = { workspaceId: cfg.workspaceId };
@@ -236,7 +237,7 @@ Examples:
236
237
  `)
237
238
  .action(async (query, opts) => {
238
239
  const cfg = resolveConfig(program.opts());
239
- const api = new ApiClient(cfg.serverUrl, cfg.token);
240
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
240
241
  try {
241
242
  const limit = Math.max(1, parseInt(opts.limit ?? "10", 10) || 10);
242
243
  const data = await api.get("/api/canvas/search", {
@@ -297,7 +298,7 @@ Examples:
297
298
  `)
298
299
  .action(async (canvasId) => {
299
300
  const cfg = resolveConfig(program.opts());
300
- const api = new ApiClient(cfg.serverUrl, cfg.token);
301
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
301
302
  try {
302
303
  const data = await api.get(canvasActionPath(canvasId, cfg.workspaceId));
303
304
  if (cfg.json) {
@@ -371,7 +372,7 @@ Examples:
371
372
  `)
372
373
  .action(async (canvasId, opts) => {
373
374
  const cfg = resolveConfig(program.opts());
374
- const api = new ApiClient(cfg.serverUrl, cfg.token);
375
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
375
376
  try {
376
377
  const size = parseSize(opts.size);
377
378
  if (!size)
@@ -439,7 +440,7 @@ Examples:
439
440
  .argument("<canvasId>", "Canvas ID")
440
441
  .action(async (canvasId) => {
441
442
  const cfg = resolveConfig(program.opts());
442
- const api = new ApiClient(cfg.serverUrl, cfg.token);
443
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
443
444
  try {
444
445
  const data = await api.get(`/api/canvas/${encodeURIComponent(canvasId)}/digest?workspaceId=${encodeURIComponent(cfg.workspaceId)}`);
445
446
  if (cfg.json) {
@@ -500,7 +501,7 @@ Examples:
500
501
  .option("--limit <n>", "Max entries (default 50, max 200)", "50")
501
502
  .action(async (canvasId, opts) => {
502
503
  const cfg = resolveConfig(program.opts());
503
- const api = new ApiClient(cfg.serverUrl, cfg.token);
504
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
504
505
  try {
505
506
  const params = { workspaceId: cfg.workspaceId };
506
507
  if (opts.limit !== undefined)
@@ -562,7 +563,7 @@ workspaces. Notes inside lists or linked canvases keep their own access.
562
563
  const shared = Boolean(link) || Boolean(opts.shared);
563
564
  // A shared read must not need (or be overridden by) a selected workspace.
564
565
  const cfg = shared ? resolveBaseConfig(program.opts()) : resolveConfig(program.opts());
565
- const api = new ApiClient(cfg.serverUrl, cfg.token);
566
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
566
567
  try {
567
568
  if (link && !sameServerOrigin(link.origin, cfg.serverUrl)) {
568
569
  throw new ValidationError(`This share link is for ${link.origin}, but the CLI is signed in to ${new URL(cfg.serverUrl).origin}.`, `Retry with --server ${link.origin} (run \`cnotes auth login --server ${link.origin}\` first if you have no login there).`);
@@ -597,7 +598,7 @@ Examples:
597
598
  `)
598
599
  .action(async (section) => {
599
600
  const cfg = resolveConfig(program.opts());
600
- const api = new ApiClient(cfg.serverUrl, cfg.token);
601
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
601
602
  try {
602
603
  const result = await readCanvasSection(api, cfg.workspaceId, section);
603
604
  if (cfg.json) {
@@ -618,7 +619,7 @@ Examples:
618
619
  .option("--audience <text>", "Target audience — who this canvas is meant to serve or inform")
619
620
  .action(async (name, opts) => {
620
621
  const cfg = resolveConfig(program.opts());
621
- const api = new ApiClient(cfg.serverUrl, cfg.token);
622
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
622
623
  try {
623
624
  const body = {
624
625
  workspaceId: cfg.workspaceId,
@@ -679,7 +680,7 @@ Examples:
679
680
  .option("--audience <text>", "Target audience — who this canvas is meant to serve or inform")
680
681
  .action(async (canvasId, opts) => {
681
682
  const cfg = resolveConfig(program.opts());
682
- const api = new ApiClient(cfg.serverUrl, cfg.token);
683
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
683
684
  try {
684
685
  if (opts.title === undefined && opts.goal === undefined && opts.audience === undefined) {
685
686
  handleError(new ValidationError("At least one of --title, --goal, or --audience is required"), cfg.json);
@@ -717,7 +718,7 @@ Examples:
717
718
  .argument("<canvasId>", "Canvas ID")
718
719
  .action(async (canvasId) => {
719
720
  const cfg = resolveConfig(program.opts());
720
- const api = new ApiClient(cfg.serverUrl, cfg.token);
721
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
721
722
  try {
722
723
  const data = await api.delete(canvasActionPath(canvasId, cfg.workspaceId));
723
724
  if (cfg.json) {
@@ -737,7 +738,7 @@ Examples:
737
738
  .argument("<canvasId>", "Canvas ID")
738
739
  .action(async (canvasId) => {
739
740
  const cfg = resolveConfig(program.opts());
740
- const api = new ApiClient(cfg.serverUrl, cfg.token);
741
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
741
742
  try {
742
743
  const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
743
744
  action: "setAsHome",
@@ -759,7 +760,7 @@ Examples:
759
760
  .argument("<canvasId>", "Canvas ID")
760
761
  .action(async (canvasId) => {
761
762
  const cfg = resolveConfig(program.opts());
762
- const api = new ApiClient(cfg.serverUrl, cfg.token);
763
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
763
764
  try {
764
765
  const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
765
766
  action: "archive",
@@ -781,7 +782,7 @@ Examples:
781
782
  .argument("<canvasId>", "Canvas ID")
782
783
  .action(async (canvasId) => {
783
784
  const cfg = resolveConfig(program.opts());
784
- const api = new ApiClient(cfg.serverUrl, cfg.token);
785
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
785
786
  try {
786
787
  const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
787
788
  action: "unarchive",
@@ -815,7 +816,7 @@ Examples:
815
816
  `)
816
817
  .action(async (canvasId, opts) => {
817
818
  const cfg = resolveConfig(program.opts());
818
- const api = new ApiClient(cfg.serverUrl, cfg.token);
819
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
819
820
  try {
820
821
  const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
821
822
  action: "addNode",
@@ -858,7 +859,7 @@ Examples:
858
859
  // invocation must fail loudly rather than be silently reinterpreted.
859
860
  const addTextElementAction = async (canvasId, opts) => {
860
861
  const cfg = resolveConfig(program.opts());
861
- const api = new ApiClient(cfg.serverUrl, cfg.token);
862
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
862
863
  let content;
863
864
  if (opts.contentFile) {
864
865
  content = readFileSafe(opts.contentFile);
@@ -968,7 +969,7 @@ and only warns.
968
969
  .option("--color <hex>", "Frame tint — omit unless it encodes a role. Role hexes: #3B82F6 evidence · #22C55E commitment · #EC4899 insight · #F59E0B warning · #EF4444 danger · #8B5CF6 people; anything else snaps to the nearest of these at render")
969
970
  .action(async (canvasId, opts, cmd) => {
970
971
  const cfg = resolveConfig(program.opts());
971
- const api = new ApiClient(cfg.serverUrl, cfg.token);
972
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
972
973
  try {
973
974
  const noteIds = opts.notes
974
975
  ? opts.notes.split(",").map((id) => id.trim()).filter(Boolean)
@@ -1057,7 +1058,7 @@ Examples:
1057
1058
  `)
1058
1059
  .action(async (sectionId, opts) => {
1059
1060
  const cfg = resolveConfig(program.opts());
1060
- const api = new ApiClient(cfg.serverUrl, cfg.token);
1061
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
1061
1062
  try {
1062
1063
  // Convex ids are long lowercase alphanumerics; anything else (SECTION-7,
1063
1064
  // section-7) is treated as a workspace-scoped display id.
@@ -1131,7 +1132,7 @@ Examples:
1131
1132
  .option("--y <n>", "Y position", "100")
1132
1133
  .action(async (canvasId, opts) => {
1133
1134
  const cfg = resolveConfig(program.opts());
1134
- const api = new ApiClient(cfg.serverUrl, cfg.token);
1135
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
1135
1136
  try {
1136
1137
  if (opts.view !== "list" && opts.view !== "grid") {
1137
1138
  throw new ValidationError(`Invalid view mode "${opts.view}". Must be "list" or "grid".`);
@@ -1167,7 +1168,7 @@ Examples:
1167
1168
  .option("--y <n>", "Y position", "100")
1168
1169
  .action(async (canvasId, opts) => {
1169
1170
  const cfg = resolveConfig(program.opts());
1170
- const api = new ApiClient(cfg.serverUrl, cfg.token);
1171
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
1171
1172
  try {
1172
1173
  const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
1173
1174
  action: "addCanvasLink",
@@ -1201,7 +1202,7 @@ Examples:
1201
1202
  `)
1202
1203
  .action(async (canvasId, opts) => {
1203
1204
  const cfg = resolveConfig(program.opts());
1204
- const api = new ApiClient(cfg.serverUrl, cfg.token);
1205
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
1205
1206
  try {
1206
1207
  const items = parseJsonOption(opts.notes, "--notes", '[{"noteId":"TASK-1","x":100,"y":200}]');
1207
1208
  if (!Array.isArray(items) || items.length === 0) {
@@ -1296,7 +1297,7 @@ Placement (relative to nodes already on the canvas):
1296
1297
  `)
1297
1298
  .action(async (canvasId, opts) => {
1298
1299
  const cfg = resolveConfig(program.opts());
1299
- const api = new ApiClient(cfg.serverUrl, cfg.token);
1300
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
1300
1301
  try {
1301
1302
  let raw;
1302
1303
  if (opts.spec) {
@@ -1440,7 +1441,7 @@ Examples:
1440
1441
  `)
1441
1442
  .action(async (canvasId, opts) => {
1442
1443
  const cfg = resolveConfig(program.opts());
1443
- const api = new ApiClient(cfg.serverUrl, cfg.token);
1444
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
1444
1445
  try {
1445
1446
  const validNodeTypes = new Set([
1446
1447
  "note",
@@ -1627,7 +1628,7 @@ Examples:
1627
1628
  .requiredOption("--moves <json>", "JSON array of {nodeId, nodeType, x, y} objects (nodeType: note|text|list|canvas|richtext|section; `text` is legacy — old heading nodes, no longer creatable)")
1628
1629
  .action(async (canvasId, opts) => {
1629
1630
  const cfg = resolveConfig(program.opts());
1630
- const api = new ApiClient(cfg.serverUrl, cfg.token);
1631
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
1631
1632
  try {
1632
1633
  const items = parseJsonOption(opts.moves, "--moves", '[{"nodeId":"abc","nodeType":"note","x":100,"y":200}]');
1633
1634
  if (!Array.isArray(items) || items.length === 0) {
@@ -1677,7 +1678,7 @@ Examples:
1677
1678
  .option("--edges <json>", "JSON array of edge ID strings to remove on their own")
1678
1679
  .action(async (canvasId, opts) => {
1679
1680
  const cfg = resolveConfig(program.opts());
1680
- const api = new ApiClient(cfg.serverUrl, cfg.token);
1681
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
1681
1682
  try {
1682
1683
  const nodeIds = (opts.nodes
1683
1684
  ? parseJsonOption(opts.nodes, "--nodes", '["SECTION-7","DECISION-3"]')
@@ -1757,7 +1758,7 @@ Examples:
1757
1758
  .option("--line-style <style>", "Line style: solid (default) | dashed", "solid")
1758
1759
  .action(async (canvasId, opts) => {
1759
1760
  const cfg = resolveConfig(program.opts());
1760
- const api = new ApiClient(cfg.serverUrl, cfg.token);
1761
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
1761
1762
  try {
1762
1763
  const { arrowStart, arrowEnd } = parseArrowMode(opts.arrow);
1763
1764
  const lineStyle = parseLineStyle(opts.lineStyle);
@@ -1811,7 +1812,7 @@ Examples:
1811
1812
  .option("--reverse", "Swap source and target nodes")
1812
1813
  .action(async (canvasId, opts) => {
1813
1814
  const cfg = resolveConfig(program.opts());
1814
- const api = new ApiClient(cfg.serverUrl, cfg.token);
1815
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
1815
1816
  try {
1816
1817
  const body = {
1817
1818
  action: "updateEdge",
@@ -1874,7 +1875,7 @@ Examples:
1874
1875
  `)
1875
1876
  .action(async (canvasId, opts) => {
1876
1877
  const cfg = resolveConfig(program.opts());
1877
- const api = new ApiClient(cfg.serverUrl, cfg.token);
1878
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
1878
1879
  try {
1879
1880
  // Reject non-numeric input here. Number("wide") is NaN, which
1880
1881
  // JSON.stringify writes as null, so the server would answer "expected
@@ -1955,7 +1956,7 @@ Examples:
1955
1956
  `)
1956
1957
  .action(async (canvasId, opts) => {
1957
1958
  const cfg = resolveConfig(program.opts());
1958
- const api = new ApiClient(cfg.serverUrl, cfg.token);
1959
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
1959
1960
  try {
1960
1961
  if (opts.content !== undefined && opts.contentFile !== undefined) {
1961
1962
  throw new ValidationError("Pass --content or --content-file, not both.");
@@ -2016,7 +2017,7 @@ Examples:
2016
2017
  .addOption(new Option("--type <type>", "Node type (defaults to note; `text` is legacy — old heading nodes, no longer creatable)").choices(["note", "text", "list", "canvas", "richtext", "section"]))
2017
2018
  .action(async (canvasId, opts) => {
2018
2019
  const cfg = resolveConfig(program.opts());
2019
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2020
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2020
2021
  try {
2021
2022
  const positionX = Number(opts.x);
2022
2023
  const positionY = Number(opts.y);
@@ -2052,7 +2053,7 @@ Examples:
2052
2053
  .requiredOption("--node <nodeId>", "Canvas node ID")
2053
2054
  .action(async (canvasId, opts) => {
2054
2055
  const cfg = resolveConfig(program.opts());
2055
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2056
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2056
2057
  try {
2057
2058
  await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
2058
2059
  action: "removeNode",
@@ -2076,7 +2077,7 @@ Examples:
2076
2077
  .requiredOption("--edge <edgeId>", "Canvas edge ID")
2077
2078
  .action(async (canvasId, opts) => {
2078
2079
  const cfg = resolveConfig(program.opts());
2079
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2080
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2080
2081
  try {
2081
2082
  await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
2082
2083
  action: "removeEdge",
@@ -2099,7 +2100,7 @@ Examples:
2099
2100
  .description("List available canvas templates")
2100
2101
  .action(async () => {
2101
2102
  const cfg = resolveConfig(program.opts());
2102
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2103
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2103
2104
  try {
2104
2105
  const data = await api.get("/api/canvas/template");
2105
2106
  const templates = data.templates || [];
@@ -2138,7 +2139,7 @@ Examples:
2138
2139
  `)
2139
2140
  .action(async (templateId, opts) => {
2140
2141
  const cfg = resolveConfig(program.opts());
2141
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2142
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2142
2143
  try {
2143
2144
  // Validate template exists by fetching template list
2144
2145
  const templateData = await api.get("/api/canvas/template");
@@ -2258,11 +2259,13 @@ Examples:
2258
2259
  .requiredOption("--prompt <text>", "Run headline. Verb-first, at most 110 characters. The platform may rewrite it. The body is kept.")
2259
2260
  .option("--rationale <text>", "Optional rationale (e.g. agent's plan)")
2260
2261
  .option("--force", "If an active run already exists on this server, end it server-side and start a fresh one")
2262
+ .option("--detached", "Open an independent run that does NOT become the active run on this server. Writes attach to it only through the printed CNOTES_AGENT_RUN_ID / CNOTES_AGENT_BEFORE_SNAPSHOT_ID exports. Use when another agent may hold the active run on this machine.")
2261
2263
  .addHelpText("after", `
2262
2264
  Examples:
2263
2265
  $ cnotes canvas agent-run begin --canvas <id> --prompt "Reorganize into sections"
2264
2266
  $ cnotes canvas place <id> --spec ./layout.json # attaches automatically
2265
2267
  $ cnotes canvas agent-run end --canvas <id>
2268
+ $ eval "$(cnotes canvas agent-run begin --canvas <id> --prompt "..." --detached)" # your own run, env-scoped
2266
2269
 
2267
2270
  After 'begin', every subsequent cnotes write on this server attaches to the
2268
2271
  run automatically — no env var to export, and it survives across separate
@@ -2270,11 +2273,12 @@ shells. End with 'cnotes canvas agent-run end --canvas <id>'.
2270
2273
 
2271
2274
  If a run is already open (from 'agent-run begin' or 'operations begin'),
2272
2275
  begin refuses rather than silently clobbering it. Pass --force to end the
2273
- prior run server-side and start fresh.
2276
+ prior run server-side and start fresh, or --detached to open your own run
2277
+ alongside it (eval the printed exports so your writes carry it).
2274
2278
  `)
2275
2279
  .action(async (opts) => {
2276
2280
  const cfg = resolveConfig(program.opts());
2277
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2281
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2278
2282
  // This command is designed to be usable via `eval "$(...)"`, which makes
2279
2283
  // stdout a non-TTY. resolveConfig's default would then flip cfg.json on
2280
2284
  // and we'd emit JSON instead of shell exports — breaking the eval form.
@@ -2286,24 +2290,17 @@ prior run server-side and start fresh.
2286
2290
  // pointer, and a request carries exactly one X-Agent-Run-Id — so a
2287
2291
  // second begin would either clobber the first or silently attach writes
2288
2292
  // to the wrong run. Mirrors `cnotes operations begin`.
2289
- const existing = getActiveAgentRunId(loadConfig(), cfg.serverUrl);
2290
- if (existing) {
2291
- if (opts.force) {
2292
- try {
2293
- await api.post("/api/operations", {
2294
- action: "end",
2295
- agentRunId: existing.agentRunId,
2296
- });
2297
- }
2298
- catch {
2299
- // Best-effort: ending an already-completed/abandoned run is
2300
- // idempotent server-side. Either way clear the local pointer so
2301
- // the caller isn't wedged.
2302
- }
2303
- clearActiveAgentRunId(loadConfig(), cfg.serverUrl);
2304
- }
2305
- else {
2306
- throw new CliError(`An active agent-run already exists on this server (agentRunId ${existing.agentRunId}, started ${formatAgo(existing.startedAt)}).`, EXIT_CODES.CONFLICT, "End it first (`cnotes canvas agent-run end --canvas <id>` or `cnotes operations end`), or pass --force to end it server-side and start fresh.");
2293
+ // A detached run never competes for the pointer, so it needs no
2294
+ // conflict check — and must not --force the active run away either.
2295
+ // Otherwise a stale holder (crashed bot) is forgotten and a running
2296
+ // one needs --force. Mirrors `cnotes operations begin`.
2297
+ if (!opts.detached) {
2298
+ const slot = await resolveActiveSlot(api, cfg.serverUrl, {
2299
+ force: opts.force,
2300
+ endCommand: "cnotes canvas agent-run end --canvas <id>` or `cnotes operations end",
2301
+ });
2302
+ if (slot.forgot) {
2303
+ console.error(`# forgot stale run ${slot.forgot.agentRunId} (${slot.forgot.status} server-side); starting fresh`);
2307
2304
  }
2308
2305
  }
2309
2306
  const body = {
@@ -2328,13 +2325,26 @@ prior run server-side and start fresh.
2328
2325
  // getRevertContext bails — "Revert this run" is dead for the whole
2329
2326
  // batch. Persisting the run id without it produces a run that looks
2330
2327
  // perfectly healthy and cannot be undone.
2331
- const persisted = setActiveAgentRunId(loadConfig(), cfg.serverUrl, data.agentRunId, Date.now(), data.beforeCheckpointId);
2328
+ //
2329
+ // --detached records the run only in the open-run registry (so `end`
2330
+ // knows it is ours) and leaves the active pointer alone: the run is
2331
+ // carried by the printed env exports instead, so another agent's
2332
+ // active run on this machine is neither clobbered nor ended.
2333
+ const tracked = opts.detached
2334
+ ? registerAgentRun(loadConfig(), cfg.serverUrl, data.agentRunId, {
2335
+ startedAt: Date.now(),
2336
+ beforeSnapshotId: data.beforeCheckpointId,
2337
+ canvasId: opts.canvas,
2338
+ detached: true,
2339
+ })
2340
+ : setActiveAgentRunId(loadConfig(), cfg.serverUrl, data.agentRunId, Date.now(), data.beforeCheckpointId);
2341
+ const persisted = tracked && !opts.detached;
2332
2342
  // No stored config entry for this server (token came from --token /
2333
2343
  // CNOTES_TOKEN against a server never logged into), so there is nowhere
2334
2344
  // to record the run. Say so rather than printing "every write now
2335
2345
  // attaches" — silently attaching nothing is the bug this flow exists to
2336
2346
  // kill. stderr, so it can't corrupt --json or the eval form.
2337
- if (!persisted) {
2347
+ if (!tracked && !opts.detached) {
2338
2348
  console.error(`# WARNING: could not persist the active run for ${cfg.serverUrl} — no stored login for that server.`);
2339
2349
  console.error(`# Subsequent cnotes writes will NOT attach to it. Either run \`cnotes auth login\`,`);
2340
2350
  console.error(`# or use the env form: eval "$(cnotes canvas agent-run begin --canvas ${opts.canvas} --prompt "...")"`);
@@ -2345,20 +2355,28 @@ prior run server-side and start fresh.
2345
2355
  return;
2346
2356
  }
2347
2357
  if (wantsJson) {
2348
- outputJson(data);
2358
+ outputJson({
2359
+ ...data,
2360
+ activeRunPersisted: persisted,
2361
+ detached: Boolean(opts.detached),
2362
+ });
2349
2363
  return;
2350
2364
  }
2351
2365
  // Still print the eval-friendly exports so the older
2352
2366
  // eval "$(npx cnotes canvas agent-run begin ...)"
2353
2367
  // form keeps working. The env var takes precedence over the persisted
2354
- // pointer, so both paths agree on the same run.
2368
+ // pointer, so both paths agree on the same run. For a detached run the
2369
+ // exports are the ONLY way writes attach, so they are not optional.
2355
2370
  console.log(`export CNOTES_AGENT_RUN_ID=${data.agentRunId}`);
2356
2371
  console.log(`export CNOTES_AGENT_BEFORE_SNAPSHOT_ID=${data.beforeCheckpointId}`);
2357
2372
  console.error(`# agent run started: v${data.beforeSnapshotNumber} (${data.agentRunId})`);
2358
2373
  if (persisted) {
2359
2374
  console.error(`# every cnotes write on this server now attaches to this run`);
2360
2375
  }
2361
- console.error(`# end with: npx cnotes canvas agent-run end --canvas ${opts.canvas}`);
2376
+ else if (opts.detached) {
2377
+ console.error(`# detached run: writes attach only with the two exports above set (eval this output)`);
2378
+ }
2379
+ console.error(`# end with: npx cnotes canvas agent-run end --canvas ${opts.canvas}${opts.detached ? ` --run-id ${data.agentRunId}` : ""}`);
2362
2380
  }
2363
2381
  catch (error) {
2364
2382
  handleError(error, wantsJson);
@@ -2378,7 +2396,7 @@ Examples:
2378
2396
  `)
2379
2397
  .action(async (command, opts) => {
2380
2398
  const cfg = resolveConfig(program.opts());
2381
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2399
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2382
2400
  if (command.length === 0) {
2383
2401
  throw new ValidationError('No command to run. Usage:\n cnotes canvas agent-run wrap --canvas <id> --prompt "..." -- <command>');
2384
2402
  }
@@ -2392,6 +2410,16 @@ Examples:
2392
2410
  });
2393
2411
  console.error(`# agent run started: v${begin.beforeSnapshotNumber} (${begin.agentRunId})`);
2394
2412
  reportHeadlineWarnings(readHeadlineWarnings(begin));
2413
+ // Record the run as one this CLI opened — in the registry only, never as
2414
+ // the active pointer (see below). If the close at the end fails and the
2415
+ // user follows the printed `agent-run end --run-id` advice, `end` then
2416
+ // recognises the run as ours instead of refusing it.
2417
+ registerAgentRun(loadConfig(), cfg.serverUrl, begin.agentRunId, {
2418
+ startedAt: Date.now(),
2419
+ beforeSnapshotId: begin.beforeCheckpointId,
2420
+ canvasId: opts.canvas,
2421
+ detached: true,
2422
+ });
2395
2423
  // Step 2: spawn the wrapped command with the run env var set.
2396
2424
  // stdio is inherited so the subprocess prints to the user's terminal
2397
2425
  // exactly as if they'd run it themselves. Only runId + before-snapshot
@@ -2436,6 +2464,9 @@ Examples:
2436
2464
  action: "agentRunEnd",
2437
2465
  agentRunId: begin.agentRunId,
2438
2466
  });
2467
+ // Closed cleanly: forget it. Only this run — an outer `operations`
2468
+ // run this wrap was nested in stays active and open.
2469
+ unregisterAgentRun(loadConfig(), cfg.serverUrl, begin.agentRunId);
2439
2470
  const status = exitCode === 0 ? "completed" : `exited ${exitCode}`;
2440
2471
  console.error(`# agent run ${status}: v${end.afterSnapshotNumber} (${begin.agentRunId})`);
2441
2472
  if (cfg.json) {
@@ -2459,10 +2490,18 @@ Examples:
2459
2490
  .command("end")
2460
2491
  .description("Close an agent-run session — captures an after-snapshot and clears the active run")
2461
2492
  .requiredOption("--canvas <id>", "Canvas ID to close")
2462
- .option("--run-id <id>", "Agent run ID (defaults to the active run on this server, then CNOTES_AGENT_RUN_ID)")
2493
+ .option("--run-id <id>", "Agent run ID (defaults to CNOTES_AGENT_RUN_ID, then the active run on this server)")
2494
+ .option("--force", "End the run even though this CLI did not open it (another machine or login)")
2495
+ .addHelpText("after", `
2496
+ End only closes runs this CLI opened. Ending one run never touches another:
2497
+ the active pointer is cleared only when it was pointing at the run that
2498
+ ended, so a detached run can end while the active run stays open and vice
2499
+ versa. A run id this CLI has no record of is refused (exit code 5); pass
2500
+ --force to end it anyway.
2501
+ `)
2463
2502
  .action(async (opts) => {
2464
2503
  const cfg = resolveConfig(program.opts());
2465
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2504
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2466
2505
  // Same reasoning as `begin`: eval form makes stdout non-TTY, so don't
2467
2506
  // let the auto-detect flip us into JSON mode.
2468
2507
  const wantsJson = program.opts().json === true || process.env.CNOTES_JSON === "1";
@@ -2476,18 +2515,26 @@ Examples:
2476
2515
  if (!runId) {
2477
2516
  throw new ValidationError("No active run on this server, and no --run-id passed", "Open one with `cnotes canvas agent-run begin --canvas <id> --prompt \"...\"`, or pass --run-id <id> to close a specific run.");
2478
2517
  }
2518
+ // Never close a run this CLI did not open (see `operations end`): the
2519
+ // registry holds every run begin/wrap opened here; `null` means there
2520
+ // is no stored login to check against, so let it through.
2521
+ // A run that is already over is harmless to end (idempotent), so
2522
+ // only a live unknown run is refused.
2523
+ const owned = isOwnedAgentRun(loadConfig(), cfg.serverUrl, runId);
2524
+ if (owned === false && !opts.force && isStillOpen(await fetchRunStatus(api, runId))) {
2525
+ throw new CliError(`This CLI has no record of opening run ${runId} on ${cfg.serverUrl}; it was not started here.`, EXIT_CODES.CONFLICT, "Ending it could close another agent's run. If you are sure, pass --force.");
2526
+ }
2479
2527
  const data = await api.post(canvasActionPath(opts.canvas, cfg.workspaceId), {
2480
2528
  action: "agentRunEnd",
2481
2529
  agentRunId: runId,
2530
+ ...(opts.force ? { force: true } : {}),
2482
2531
  });
2483
- // Clear the local pointer so the next write detaches. Only clear when
2484
- // it matches the run we just closed, so a concurrent begin from another
2485
- // shell isn't stomped. Done after a successful response so a transient
2486
- // server error can't desync local state from the server.
2487
- const active = getActiveAgentRunId(loadConfig(), cfg.serverUrl);
2488
- if (active?.agentRunId === data.agentRunId) {
2489
- clearActiveAgentRunId(loadConfig(), cfg.serverUrl);
2490
- }
2532
+ // Forget this run, and only this run: it leaves the open-run registry,
2533
+ // and the active pointer is cleared only when it was pointing at the
2534
+ // run we just closed — a concurrent run from another shell (active or
2535
+ // detached) is left as it was. Done after a successful response so a
2536
+ // transient server error can't desync local state from the server.
2537
+ unregisterAgentRun(loadConfig(), cfg.serverUrl, data.agentRunId);
2491
2538
  if (cfg.quiet) {
2492
2539
  outputQuiet(String(data.afterSnapshotNumber));
2493
2540
  return;
@@ -2537,7 +2584,7 @@ Examples:
2537
2584
  `)
2538
2585
  .action(async (canvasId, opts) => {
2539
2586
  const cfg = resolveConfig(program.opts());
2540
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2587
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2541
2588
  try {
2542
2589
  // Both the status vocabulary and the open-only rule for workspace-wide
2543
2590
  // reads live in canvas-paths.ts, where they are unit-tested.
@@ -2613,7 +2660,7 @@ Examples:
2613
2660
  `)
2614
2661
  .action(async (canvasId, opts) => {
2615
2662
  const cfg = resolveConfig(program.opts());
2616
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2663
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2617
2664
  try {
2618
2665
  if (opts.author && !["human", "agent"].includes(opts.author)) {
2619
2666
  throw new ValidationError("--author must be human or agent");
@@ -2645,7 +2692,7 @@ Examples:
2645
2692
  .requiredOption("--id <annotationId>", "Comment ID (from comments list)")
2646
2693
  .action(async (canvasId, opts) => {
2647
2694
  const cfg = resolveConfig(program.opts());
2648
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2695
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2649
2696
  try {
2650
2697
  const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
2651
2698
  action: "resolveComment",
@@ -2678,7 +2725,7 @@ Examples:
2678
2725
  .requiredOption("--id <annotationId>", "Comment ID (from comments list --status resolved)")
2679
2726
  .action(async (canvasId, opts) => {
2680
2727
  const cfg = resolveConfig(program.opts());
2681
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2728
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2682
2729
  try {
2683
2730
  const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
2684
2731
  action: "reopenComment",
@@ -2709,7 +2756,7 @@ Examples:
2709
2756
  .argument("<canvasId>", "Canvas ID")
2710
2757
  .action(async (canvasId) => {
2711
2758
  const cfg = resolveConfig(program.opts());
2712
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2759
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2713
2760
  try {
2714
2761
  const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
2715
2762
  action: "submitReview",
@@ -2749,7 +2796,7 @@ Examples:
2749
2796
  .requiredOption("--id <annotationId>", "Comment ID (from comments list)")
2750
2797
  .action(async (canvasId, opts) => {
2751
2798
  const cfg = resolveConfig(program.opts());
2752
- const api = new ApiClient(cfg.serverUrl, cfg.token);
2799
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
2753
2800
  try {
2754
2801
  const data = await api.post(canvasActionPath(canvasId, cfg.workspaceId), {
2755
2802
  action: "removeComment",