@creator-notes/cnotes 0.80.0 → 0.82.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 (79) 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.js +43 -43
  10. package/dist/commands/canvas.js.map +1 -1
  11. package/dist/commands/deps.js +3 -3
  12. package/dist/commands/deps.js.map +1 -1
  13. package/dist/commands/draft.d.ts.map +1 -1
  14. package/dist/commands/draft.js +301 -141
  15. package/dist/commands/draft.js.map +1 -1
  16. package/dist/commands/feedback.js +3 -3
  17. package/dist/commands/feedback.js.map +1 -1
  18. package/dist/commands/files.js +3 -3
  19. package/dist/commands/files.js.map +1 -1
  20. package/dist/commands/focus.js +3 -3
  21. package/dist/commands/focus.js.map +1 -1
  22. package/dist/commands/init.js +1 -1
  23. package/dist/commands/init.js.map +1 -1
  24. package/dist/commands/notes.js +12 -12
  25. package/dist/commands/notes.js.map +1 -1
  26. package/dist/commands/operations.js +4 -4
  27. package/dist/commands/operations.js.map +1 -1
  28. package/dist/commands/quality.js +1 -1
  29. package/dist/commands/quality.js.map +1 -1
  30. package/dist/commands/relationships.d.ts +5 -0
  31. package/dist/commands/relationships.d.ts.map +1 -1
  32. package/dist/commands/relationships.js +13 -8
  33. package/dist/commands/relationships.js.map +1 -1
  34. package/dist/commands/review.d.ts.map +1 -1
  35. package/dist/commands/review.js +10 -7
  36. package/dist/commands/review.js.map +1 -1
  37. package/dist/commands/schema.js +1 -1
  38. package/dist/commands/schema.js.map +1 -1
  39. package/dist/commands/search.js +2 -2
  40. package/dist/commands/search.js.map +1 -1
  41. package/dist/commands/shared.js +1 -1
  42. package/dist/commands/shared.js.map +1 -1
  43. package/dist/commands/theme.js +5 -5
  44. package/dist/commands/theme.js.map +1 -1
  45. package/dist/commands/timeline.js +1 -1
  46. package/dist/commands/timeline.js.map +1 -1
  47. package/dist/commands/types.js +4 -4
  48. package/dist/commands/types.js.map +1 -1
  49. package/dist/commands/upgrade.js +1 -1
  50. package/dist/commands/upgrade.js.map +1 -1
  51. package/dist/commands/versions.js +2 -2
  52. package/dist/commands/versions.js.map +1 -1
  53. package/dist/commands/workspace.d.ts.map +1 -1
  54. package/dist/commands/workspace.js +90 -9
  55. package/dist/commands/workspace.js.map +1 -1
  56. package/dist/lib/api-client.d.ts +19 -1
  57. package/dist/lib/api-client.d.ts.map +1 -1
  58. package/dist/lib/api-client.js +32 -2
  59. package/dist/lib/api-client.js.map +1 -1
  60. package/dist/lib/config.d.ts +14 -0
  61. package/dist/lib/config.d.ts.map +1 -1
  62. package/dist/lib/config.js +20 -5
  63. package/dist/lib/config.js.map +1 -1
  64. package/dist/lib/draft-view.d.ts +306 -0
  65. package/dist/lib/draft-view.d.ts.map +1 -0
  66. package/dist/lib/draft-view.js +358 -0
  67. package/dist/lib/draft-view.js.map +1 -0
  68. package/dist/lib/errors.d.ts +6 -0
  69. package/dist/lib/errors.d.ts.map +1 -1
  70. package/dist/lib/errors.js +64 -1
  71. package/dist/lib/errors.js.map +1 -1
  72. package/dist/lib/urls.d.ts +15 -0
  73. package/dist/lib/urls.d.ts.map +1 -1
  74. package/dist/lib/urls.js +20 -0
  75. package/dist/lib/urls.js.map +1 -1
  76. package/dist/mcp-server.js +5 -1
  77. package/dist/mcp-server.js.map +1 -1
  78. package/package.json +1 -1
  79. package/skills/cnotes/SKILL.md +86 -60
@@ -2,18 +2,44 @@ import { readFileSync } from "node:fs";
2
2
  import { ApiClient } from "../lib/api-client.js";
3
3
  import { resolveBaseConfig, resolveConfig } from "../lib/config.js";
4
4
  import { loadConfig, setWorkspaceId } from "../lib/auth-store.js";
5
- import { ApiError, NotFoundError, ValidationError, handleError } from "../lib/errors.js";
6
- import { outputJson, outputTable, timeAgo, truncate } from "../lib/output.js";
5
+ import { CliError, EXIT_CODES, NotFoundError, ValidationError, handleError } from "../lib/errors.js";
6
+ import { outputJson, outputTable, truncate, timeAgo } from "../lib/output.js";
7
7
  import { resolveDraftRef } from "../lib/draft-ref.js";
8
+ import { canvasUrl, workspaceUrl } from "../lib/urls.js";
9
+ import { detectAgentClient } from "../lib/agent-client.js";
10
+ import { PRIVATE_UNTIL_APPROVED, approvalRefusal, askedLines, branchOpenedSentence, branchSummary, decisionSentence, draftLink, mergeRefusalHint, notADraft, refusalMessage, shadowNotice, spokenDetail, statusLines, } from "../lib/draft-view.js";
8
11
  /**
9
- * Make `workspaceId` the active workspace, or say how to when the token came
10
- * from a flag or env var and there is no config entry to write to.
12
+ * Make `workspaceId` the active workspace, and say plainly when that is not
13
+ * where writes go: CNOTES_WORKSPACE and the `-w` flag both beat the saved
14
+ * workspace, so a saved switch into a draft is shadowed while either points
15
+ * elsewhere. With no config entry to write to (the token came from a flag or
16
+ * env var), say how to work in it instead.
11
17
  */
12
- function activate(serverUrl, workspaceId) {
18
+ function activate(serverUrl, workspaceId, overrides, label, place = "the draft") {
13
19
  const switched = setWorkspaceId(loadConfig(), serverUrl, workspaceId);
14
- return switched
15
- ? { switched }
16
- : { switched, hint: `Set CNOTES_WORKSPACE=${workspaceId} (or pass -w ${workspaceId}) to work in it.` };
20
+ if (!switched) {
21
+ return {
22
+ switched,
23
+ active: false,
24
+ shadowedBy: null,
25
+ notice: `Set CNOTES_WORKSPACE=${workspaceId} (or pass -w ${workspaceId}) to work in it.`,
26
+ };
27
+ }
28
+ const notice = shadowNotice(workspaceId, overrides, label, place) ?? undefined;
29
+ const envShadow = overrides.env && overrides.env !== workspaceId ? overrides.env : undefined;
30
+ const flagShadow = overrides.flag && overrides.flag !== workspaceId ? overrides.flag : undefined;
31
+ const shadowedBy = envShadow
32
+ ? { source: "env", workspaceId: envShadow }
33
+ : flagShadow
34
+ ? { source: "flag", workspaceId: flagShadow }
35
+ : null;
36
+ // A -w flag only covers the commands that pass it, so the draft is still the
37
+ // workspace for every command run without it. The env var covers them all.
38
+ return { switched, active: !envShadow, shadowedBy, notice };
39
+ }
40
+ /** Name the parent where it is the id a shadow notice mentions. */
41
+ function parentLabel(parentId, parentName) {
42
+ return (id) => (id === parentId ? `${parentName ?? "the shared workspace"} (${id})` : id);
17
43
  }
18
44
  /** The draft a command acts on: the named one, else the active workspace. */
19
45
  async function resolveTarget(api, ref, activeId) {
@@ -29,87 +55,110 @@ async function resolveTarget(api, ref, activeId) {
29
55
  throw new NotFoundError(resolved.error, "Run `cnotes draft list`");
30
56
  return resolved.draft.id;
31
57
  }
32
- /** A 404 on the active workspace means it is not one of the caller's drafts. */
33
- function notADraft(error, named) {
34
- if (!named && error instanceof ApiError && error.status === 404) {
35
- return new NotFoundError("The active workspace is not one of your open drafts", "Name one (`cnotes draft merge <draft>`) or run `cnotes draft list`");
36
- }
37
- return error;
38
- }
39
- function printFindings(checks) {
40
- if (checks.findings.length === 0) {
41
- console.log(` Checks: all clear (${checks.notesChecked} notes, ${checks.editsChecked} proposed edits)`);
42
- return;
43
- }
44
- console.log(` Checks: ${checks.blocking} blocking, ${checks.warnings} warning${checks.warnings === 1 ? "" : "s"} (${checks.notesChecked} notes, ${checks.editsChecked} proposed edits)`);
45
- for (const f of checks.findings) {
46
- console.log(` ${f.blocking ? "✗" : "·"} ${f.code} · ${f.message}`);
47
- console.log(` fix: ${f.fix}`);
48
- }
49
- }
50
- function printRound(round) {
51
- if (!round)
52
- return;
53
- const outcome = round.outcome ? round.outcome.replace("_", " ") : round.status;
54
- console.log(` Review: ${outcome}${round.submittedAt ? `, ${timeAgo(round.submittedAt)}` : `, asked ${timeAgo(round.createdAt)}`} (${round.requestId})`);
55
- if (round.rationale)
56
- console.log(` ${round.rationale}`);
57
- }
58
58
  export function registerDraftCommands(program) {
59
59
  const draft = program
60
60
  .command("draft")
61
- .description("Private drafts of a shared workspace: build many notes and canvases out of sight, propose edits to shared notes, then merge through checks or dismiss as one unit")
61
+ .description("Private drafts of a shared workspace: build many notes and canvases out of sight and propose edits to shared notes; a person approves the draft in the browser, or you dismiss it")
62
62
  .addHelpText("after", `
63
63
  A draft is a private workspace opened from the active one. Only you (and agents
64
64
  using your login) can see it. Notes made in it take ids from the shared
65
- workspace's sequence, and a mention of a shared note links to it, so a merge
66
- moves everything over with the same ids and working links. A draft can also
67
- PROPOSE a new text for a shared note; the shared note changes only at merge.
65
+ workspace's sequence, and a mention of a shared note links to it, so the work
66
+ lands with the same ids and working links. A draft changes a shared note only
67
+ by PROPOSING a new text (draft propose); a live edit of a shared note from
68
+ inside a draft is refused.
68
69
 
69
- Merge runs checks first (broken links, citations of shared notes that moved,
70
- proposals whose base moved, empty bodies) and refuses while one blocks. If
71
- you asked yourself for a review (cnotes review request <canvas> --reviewer me),
72
- merge also needs that round approved. A merge is one row on the shared
73
- timeline and can be undone while nobody has built on it.
70
+ To rework a board other people read, branch it: draft open --from-canvas
71
+ CANVAS-n. The draft then holds your working copy, CANVAS-m, and the canvas
72
+ commands work on it as usual. The live board does not change until a person
73
+ accepts your copy as its next version.
74
+
75
+ Nothing in a draft reaches the shared workspace until a person approves it in
76
+ the browser. No key or agent can merge or approve a draft. Run draft status
77
+ until no check blocks, then name who decides with draft ask and stop. If they
78
+ send it back, draft status shows what they asked for.
74
79
 
75
80
  Examples:
76
81
  $ cnotes draft open "Pricing rethink" --intent "Rework tiers for teams"
82
+ $ cnotes draft open --from-canvas CANVAS-390 --intent "Restamp screens 4 to 7"
77
83
  $ cnotes notes create --notes '[...]' # lands in the draft
78
84
  $ cnotes notes get DECISION-12 # a shared note reads through from the draft
79
85
  $ cnotes draft propose DECISION-12 --markdown-file new.md --description "Annual is the default"
80
- $ cnotes draft status # what it holds, the checks, the review
81
- $ cnotes draft merge # move it all into the shared workspace
82
- $ cnotes draft undo-merge # put it back, while nothing built on it
86
+ $ cnotes draft status # who it waits on, the checks, what V2 changes
87
+ $ cnotes draft ask --reviewer sam@example.com # who decides; then stop
83
88
  $ cnotes draft dismiss # or drop it
84
89
  `);
85
90
  draft
86
91
  .command("open")
87
- .description("Open a draft of the active workspace and switch to it")
88
- .argument("<name>", "What the draft is called")
92
+ .description("Open a private draft of the active workspace and switch to it; --from-canvas branches a shared board into it")
93
+ .argument("[name]", "What the draft is called (optional with --from-canvas: \"<board name> V2\")")
94
+ .option("--from-canvas <canvas>", "Branch this board of the active workspace (CANVAS-n): the draft holds your working copy, and a person accepts it as the board's next version")
89
95
  .option("--intent <text>", "What the draft is for, in a sentence")
90
96
  .option("--no-switch", "Stay in the current workspace")
97
+ .addHelpText("after", `
98
+ With --from-canvas, the draft's first canvas is a copy of the board: its
99
+ cards, sections, links and the shared notes on it. Work on the copy (CANVAS-m)
100
+ with the usual canvas commands; a canvas write aimed at the live board from
101
+ inside the draft is refused and names your copy. The live board does not
102
+ change until a person accepts the copy as its next version.
103
+
104
+ --json adds branch { canvasId, displayId, sourceCanvasId, sourceDisplayId,
105
+ sourceName, baseLabel, copied } for a branch.
106
+ `)
91
107
  .action(async (name, opts) => {
92
108
  const cfg = resolveConfig(program.opts());
93
- const api = new ApiClient(cfg.serverUrl, cfg.token);
109
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
94
110
  try {
95
- const created = await api.post("/api/workspace-drafts", { workspaceId: cfg.workspaceId, name, intent: opts.intent });
96
- const switchResult = opts.switch ? activate(cfg.serverUrl, created.draftId) : { switched: false };
111
+ if (!name?.trim() && !opts.fromCanvas?.trim()) {
112
+ throw new ValidationError("Name the draft, or branch a board", 'Run `cnotes draft open "<name>"`, or `cnotes draft open --from-canvas CANVAS-n`');
113
+ }
114
+ const created = await api.post("/api/workspace-drafts", {
115
+ workspaceId: cfg.workspaceId,
116
+ name: name?.trim() || undefined,
117
+ intent: opts.intent,
118
+ fromCanvas: opts.fromCanvas?.trim() || undefined,
119
+ });
120
+ // A server too old to branch boards ignores fromCanvas and opens an
121
+ // ordinary empty draft. Close it again and say so, rather than switch
122
+ // the agent into a draft that does not hold the board.
123
+ if (opts.fromCanvas?.trim() && !created.branch) {
124
+ await api.post(`/api/workspace-drafts/${created.draftId}`, { action: "dismiss" }).catch(() => undefined);
125
+ throw new CliError("This server cannot branch boards yet, so nothing was branched.", EXIT_CODES.GENERIC, "Try again after the server update, or open an ordinary draft without --from-canvas.");
126
+ }
127
+ const switchResult = opts.switch
128
+ ? activate(cfg.serverUrl, created.draftId, cfg.workspaceOverrides, parentLabel(created.parentWorkspaceId))
129
+ : null;
130
+ const url = canvasUrl(cfg.serverUrl, created.draftId, created.homeCanvasId);
97
131
  if (cfg.quiet) {
98
132
  console.log(created.draftId);
99
133
  return;
100
134
  }
101
135
  if (cfg.json) {
102
- outputJson({ ...created, active: switchResult.switched });
136
+ outputJson({
137
+ ...created,
138
+ url,
139
+ active: switchResult?.active ?? false,
140
+ savedAsActive: switchResult?.switched ?? false,
141
+ shadowedBy: switchResult?.shadowedBy ?? null,
142
+ ...(switchResult?.notice ? { notice: switchResult.notice } : {}),
143
+ });
103
144
  return;
104
145
  }
105
- console.log(`Opened draft "${created.name}" (${created.draftId})`);
106
- if (switchResult.switched) {
107
- console.log("It is now the active workspace; new notes and canvases land in it.");
146
+ if (created.branch) {
147
+ console.log(branchOpenedSentence(created.branch));
108
148
  }
109
- else if ("hint" in switchResult && switchResult.hint) {
110
- console.log(switchResult.hint);
149
+ else {
150
+ console.log(`Opened draft "${created.name}" (${created.draftId}).`);
151
+ console.log(PRIVATE_UNTIL_APPROVED);
152
+ }
153
+ if (switchResult?.notice) {
154
+ console.log(switchResult.notice);
155
+ }
156
+ else if (switchResult?.active) {
157
+ console.log("It is now the active workspace; new notes and canvases land in it.");
111
158
  }
112
- console.log(`Link: ${cfg.serverUrl}/${created.draftId}?canvasId=${created.homeCanvasId}`);
159
+ if (created.branch)
160
+ console.log(`Draft: "${created.name}" (${created.draftId})`);
161
+ console.log(`Link: ${url}`);
113
162
  }
114
163
  catch (error) {
115
164
  handleError(error, cfg.json);
@@ -121,7 +170,7 @@ Examples:
121
170
  .option("--all", "Include merged and dismissed drafts")
122
171
  .action(async (opts) => {
123
172
  const cfg = resolveBaseConfig(program.opts());
124
- const api = new ApiClient(cfg.serverUrl, cfg.token);
173
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
125
174
  try {
126
175
  const data = await api.get("/api/workspace-drafts", {
127
176
  includeClosed: opts.all ? "true" : undefined,
@@ -159,25 +208,40 @@ Examples:
159
208
  .argument("<draft>", "Draft id or name (unique substring ok)")
160
209
  .action(async (ref) => {
161
210
  const cfg = resolveBaseConfig(program.opts());
162
- const api = new ApiClient(cfg.serverUrl, cfg.token);
211
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
163
212
  try {
164
213
  const id = await resolveTarget(api, ref, cfg.workspaceId);
165
214
  const detail = await api.get(`/api/workspace-drafts/${id}`);
166
- const switchResult = activate(cfg.serverUrl, id);
215
+ const d = detail.draft;
216
+ const switchResult = activate(cfg.serverUrl, id, cfg.workspaceOverrides, parentLabel(d.parentWorkspaceId, d.parentName));
217
+ const open = d.status === "open";
218
+ const url = open ? draftLink(cfg.serverUrl, detail) : null;
167
219
  if (cfg.quiet) {
168
220
  console.log(id);
169
221
  return;
170
222
  }
171
223
  if (cfg.json) {
172
- outputJson({ ...detail, active: switchResult.switched });
224
+ outputJson({
225
+ ...spokenDetail(detail),
226
+ url,
227
+ active: switchResult.active,
228
+ savedAsActive: switchResult.switched,
229
+ shadowedBy: switchResult.shadowedBy,
230
+ ...(switchResult.notice ? { notice: switchResult.notice } : {}),
231
+ });
173
232
  return;
174
233
  }
175
- console.log(`Checked out "${detail.draft.name}": ${detail.noteCount} notes, ${detail.canvasCount} canvases, ${detail.pendingEditCount} proposed edits, draft of ${detail.draft.parentName}.`);
176
- if (!switchResult.switched && switchResult.hint)
177
- console.log(switchResult.hint);
178
- if (detail.draft.intent)
179
- console.log(`Intent: ${detail.draft.intent}`);
180
- printRound(detail.round);
234
+ const n = (count, one, many) => `${count} ${count === 1 ? one : many}`;
235
+ console.log(`Checked out "${d.name}": ${n(detail.noteCount, "note", "notes")}, ${n(detail.canvasCount, "canvas", "canvases")}, ${n(detail.pendingEditCount, "proposed edit", "proposed edits")}, draft of ${d.parentName}.`);
236
+ console.log(open ? PRIVATE_UNTIL_APPROVED : `This draft was ${d.status}, so it takes no more writes.`);
237
+ if (switchResult.notice)
238
+ console.log(switchResult.notice);
239
+ if (d.intent)
240
+ console.log(`Intent: ${d.intent}`);
241
+ if (open) {
242
+ console.log(decisionSentence(detail.decision, Boolean(detail.branch)));
243
+ console.log(`Link: ${url}`);
244
+ }
181
245
  }
182
246
  catch (error) {
183
247
  handleError(error, cfg.json);
@@ -185,61 +249,80 @@ Examples:
185
249
  });
186
250
  draft
187
251
  .command("status")
188
- .description("What the active draft (or a named one) holds, the checks a merge would run, and the review round")
252
+ .description("Who the draft waits on, what it holds, its checks and proposed edits, and the link a person opens to approve it")
189
253
  .argument("[draft]", "Draft id or name; defaults to the active workspace")
190
254
  .option("--no-checks", "Skip the checks (faster for a quick look)")
255
+ .addHelpText("after", `
256
+ The first line under the name says where the draft stands: nobody asked yet,
257
+ sent back with what to change, or waiting on a named reviewer. When the next
258
+ move is yours, it ends with the draft ask to run: fix every blocking check,
259
+ then ask and stop. A key cannot merge or approve a draft.
260
+
261
+ For a branch of a shared board, the line after it says what V2 changes on
262
+ the live board ("V2 of CANVAS-390: 2 added, 5 moved, 2 removed, 3 links,
263
+ 1 reworded"), then each conflict, then how many cards changed on the live
264
+ board since you branched.
265
+
266
+ --json adds: decision { state, line, reviewerName, rationale, at }, checks,
267
+ blockedBy (the first blocking check, or null), edits, url (open drafts),
268
+ proposal { line, board, copy, counts, reworded, conflicts[],
269
+ liveChangedSinceBranch, sourceGone } for a branch, and merge { mergedAt,
270
+ acceptedByName, renamed[], undoneAt } once it landed.
271
+ `)
191
272
  .action(async (ref, opts) => {
192
273
  const cfg = resolveBaseConfig(program.opts());
193
- const api = new ApiClient(cfg.serverUrl, cfg.token);
274
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
194
275
  try {
195
276
  const id = await resolveTarget(api, ref, cfg.workspaceId);
196
277
  const detail = await api.get(`/api/workspace-drafts/${id}`).catch((e) => {
197
278
  throw notADraft(e, Boolean(ref));
198
279
  });
199
280
  const open = detail.draft.status === "open";
200
- const [checks, edits] = open && opts.checks
201
- ? await Promise.all([
202
- api.get(`/api/workspace-drafts/${id}/checks`),
203
- api.get(`/api/workspace-drafts/${id}/edits`),
204
- ])
205
- : [null, null];
281
+ // A branch's comparison is the status itself, so it is read even with
282
+ // --no-checks. A failure to read it is reported, not fatal.
283
+ const branchRead = open && detail.branch
284
+ ? api.get(`/api/workspace-drafts/${id}/branch`).then((view) => ({ view, error: null }), (e) => ({ view: null, error: e instanceof Error ? e.message : String(e) }))
285
+ : Promise.resolve({ view: null, error: null });
286
+ const [[checks, edits], branch] = await Promise.all([
287
+ open && opts.checks
288
+ ? Promise.all([
289
+ api.get(`/api/workspace-drafts/${id}/checks`),
290
+ api.get(`/api/workspace-drafts/${id}/edits`),
291
+ ])
292
+ : Promise.resolve([null, null]),
293
+ branchRead,
294
+ ]);
206
295
  if (cfg.quiet) {
207
296
  console.log(id);
208
297
  return;
209
298
  }
210
299
  if (cfg.json) {
211
- outputJson({ ...detail, checks: checks?.checks ?? null, blockedBy: checks?.blockedBy ?? null, edits: edits?.edits ?? [] });
300
+ outputJson({
301
+ ...spokenDetail(detail),
302
+ checks: checks?.checks ?? null,
303
+ blockedBy: checks?.blockedBy ?? null,
304
+ edits: edits?.edits ?? [],
305
+ url: open ? draftLink(cfg.serverUrl, detail) : null,
306
+ ...(detail.branch && open
307
+ ? {
308
+ proposal: branch.view ? branchSummary(branch.view, detail.pendingEditCount) : null,
309
+ ...(branch.error ? { proposalError: branch.error } : {}),
310
+ }
311
+ : {}),
312
+ });
212
313
  return;
213
314
  }
214
- const d = detail.draft;
215
- console.log(`${d.name} (${d.id})`);
216
- console.log(` Draft of: ${d.parentName} (${d.parentWorkspaceId})`);
217
- console.log(` Status: ${d.status}, opened ${timeAgo(d.createdAt)}`);
218
- console.log(` Holds: ${detail.noteCount} notes, ${detail.canvasCount} canvases, ${detail.pendingEditCount} proposed edits`);
219
- if (d.intent)
220
- console.log(` Intent: ${d.intent}`);
221
- if (edits && edits.edits.length > 0) {
222
- console.log(" Proposed edits of shared notes:");
223
- for (const e of edits.edits) {
224
- const base = e.conflict
225
- ? `based on v${e.baseVersionNumber}, now v${e.currentVersionNumber} (conflict)`
226
- : `based on v${e.baseVersionNumber}`;
227
- console.log(` ${e.noteDisplayId} · "${e.currentTitle}" → "${e.title}" · ${base}`);
228
- }
229
- }
230
- if (checks) {
231
- printFindings(checks.checks);
232
- printRound(checks.round);
233
- console.log(checks.blockedBy ? ` Merge: blocked. ${checks.blockedBy}` : " Merge: ready (cnotes draft merge)");
234
- }
235
- else {
236
- printRound(detail.round);
237
- }
238
- if (detail.merge) {
239
- console.log(detail.merge.undoneAt
240
- ? ` Merged ${timeAgo(detail.merge.mergedAt)}, undone ${timeAgo(detail.merge.undoneAt)}`
241
- : ` Merged ${timeAgo(detail.merge.mergedAt)} (${detail.merge.appliedEdits} edits applied). Undo with: cnotes draft undo-merge ${d.id}`);
242
- }
315
+ const lines = statusLines({
316
+ serverUrl: cfg.serverUrl,
317
+ detail,
318
+ checks,
319
+ edits: edits?.edits ?? null,
320
+ activeWorkspaceId: cfg.workspaceId,
321
+ branch: branch.view,
322
+ branchError: branch.error,
323
+ });
324
+ for (const line of lines)
325
+ console.log(line);
243
326
  }
244
327
  catch (error) {
245
328
  handleError(error, cfg.json);
@@ -247,7 +330,7 @@ Examples:
247
330
  });
248
331
  draft
249
332
  .command("propose")
250
- .description("Propose a new text for a SHARED note from inside the draft; the note changes only when the draft merges")
333
+ .description("Propose a new text for a SHARED note from inside the draft; the note changes only when a person approves the draft")
251
334
  .argument("<note>", "The shared note's display id (e.g. DECISION-12)")
252
335
  .option("--markdown-file <path>", "The complete new body, as markdown starting with a # heading")
253
336
  .option("--markdown <text>", "Inline markdown (short only)")
@@ -258,11 +341,13 @@ Examples:
258
341
  Read the shared note first (cnotes notes get <id> works from inside the
259
342
  draft), write the whole new body, then propose. Proposing the same note again
260
343
  replaces the proposal; if the shared note moved since, proposing again from
261
- its current text clears the base conflict the checks report.
344
+ its current text clears the base conflict the checks report. This is the only
345
+ way a draft changes a shared note: a live edit of one from inside a draft
346
+ (versions create, update, archive, retype) is refused.
262
347
  `)
263
348
  .action(async (note, opts) => {
264
349
  const cfg = resolveBaseConfig(program.opts());
265
- const api = new ApiClient(cfg.serverUrl, cfg.token);
350
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
266
351
  try {
267
352
  let markdown = opts.markdown;
268
353
  if (opts.markdownFile)
@@ -287,7 +372,7 @@ its current text clears the base conflict the checks report.
287
372
  return;
288
373
  }
289
374
  console.log(`${result.replaced ? "Updated the proposal for" : "Proposed a new text for"} ${result.noteDisplayId}: "${result.title}" (based on v${result.baseVersionNumber}).`);
290
- console.log("The shared note is unchanged until the draft merges. Check with: cnotes draft status");
375
+ console.log("The shared note is unchanged until a person approves the draft. Check with: cnotes draft status");
291
376
  }
292
377
  catch (error) {
293
378
  handleError(error, cfg.json);
@@ -301,7 +386,7 @@ its current text clears the base conflict the checks report.
301
386
  .option("--draft <draft>", "Draft id or name; defaults to the active workspace")
302
387
  .action(async (opts) => {
303
388
  const cfg = resolveBaseConfig(program.opts());
304
- const api = new ApiClient(cfg.serverUrl, cfg.token);
389
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
305
390
  try {
306
391
  const id = await resolveTarget(api, opts.draft, cfg.workspaceId);
307
392
  if (opts.note) {
@@ -360,7 +445,7 @@ its current text clears the base conflict the checks report.
360
445
  .option("--draft <draft>", "Draft id or name; defaults to the active workspace")
361
446
  .action(async (note, opts) => {
362
447
  const cfg = resolveBaseConfig(program.opts());
363
- const api = new ApiClient(cfg.serverUrl, cfg.token);
448
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
364
449
  try {
365
450
  const id = await resolveTarget(api, opts.draft, cfg.workspaceId);
366
451
  const result = await api
@@ -383,52 +468,118 @@ its current text clears the base conflict the checks report.
383
468
  }
384
469
  });
385
470
  draft
386
- .command("merge")
387
- .description("Run the checks, then move the draft's notes, canvases and proposed edits into the shared workspace as one timeline row")
388
- .argument("[draft]", "Draft id or name; defaults to the active workspace")
389
- .action(async (ref) => {
471
+ .command("ask")
472
+ .description("Name the person who decides the draft, then stop: they accept it or send it back in the browser")
473
+ .requiredOption("--reviewer <who>", "me, an email, or a user id of someone who edits the shared workspace")
474
+ .option("--note <text>", "One line for them: what to look at")
475
+ .option("--draft <draft>", "Draft id or name; defaults to the active workspace")
476
+ .addHelpText("after", `
477
+ The last step of a draft. Run draft status until no check blocks, then ask.
478
+ The person sees the ask in Shared with you and decides in the browser; a
479
+ branch of a shared board opens on the live board with your version drawn
480
+ over it. Only a person can accept it. After asking, stop: do not merge,
481
+ approve, or press anything for them. Their answer shows in draft status.
482
+
483
+ Naming someone else works for a branch (draft open --from-canvas); any draft
484
+ can be asked of yourself (--reviewer me). Asking again replaces the
485
+ unanswered ask.
486
+
487
+ --json: { asked, requestId, reviewerUserId, reviewerName, isSelf,
488
+ anchorCanvasId, link, draftId, line }.
489
+
490
+ Examples:
491
+ $ cnotes draft ask --reviewer sam@example.com --note "Screens 4 to 7 are restamped"
492
+ $ cnotes draft ask --reviewer me
493
+ `)
494
+ .action(async (opts) => {
390
495
  const cfg = resolveBaseConfig(program.opts());
391
- const api = new ApiClient(cfg.serverUrl, cfg.token);
496
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
392
497
  try {
393
- const id = await resolveTarget(api, ref, cfg.workspaceId);
498
+ const id = await resolveTarget(api, opts.draft, cfg.workspaceId);
394
499
  const result = await api
395
- .post(`/api/workspace-drafts/${id}`, { action: "merge" })
500
+ .post(`/api/workspace-drafts/${id}`, {
501
+ action: "ask",
502
+ reviewer: opts.reviewer,
503
+ note: opts.note,
504
+ })
396
505
  .catch((e) => {
397
- throw notADraft(e, Boolean(ref));
506
+ throw notADraft(e, Boolean(opts.draft));
507
+ });
508
+ let link = result.link ?? null;
509
+ if (!link) {
510
+ const detail = await api.get(`/api/workspace-drafts/${id}`).catch(() => null);
511
+ link = detail ? draftLink(cfg.serverUrl, detail) : null;
512
+ }
513
+ const lines = askedLines({
514
+ reviewerName: result.reviewerName,
515
+ link,
516
+ agent: detectAgentClient() !== "CLI",
398
517
  });
399
- const switched = id === cfg.workspaceId ? activate(cfg.serverUrl, result.parentWorkspaceId).switched : false;
400
518
  if (cfg.quiet) {
401
- console.log(result.parentWorkspaceId);
519
+ console.log(result.requestId);
402
520
  return;
403
521
  }
404
522
  if (cfg.json) {
405
- outputJson({ ...result, activeWorkspaceId: switched ? result.parentWorkspaceId : cfg.workspaceId });
523
+ outputJson({ ...result, link, draftId: id, line: lines.join(" ") });
406
524
  return;
407
525
  }
408
- console.log(`Merged: ${result.notesMoved} notes and ${result.canvasesMoved} canvases moved into the shared workspace, ${result.editsApplied} proposed edit${result.editsApplied === 1 ? "" : "s"} applied.`);
409
- if (result.renamed.length > 0) {
410
- console.log("These ids were taken in the shared workspace and changed (mentions updated):");
411
- for (const r of result.renamed)
412
- console.log(` ${r.from} -> ${r.to}`);
413
- }
414
- if (switched)
415
- console.log("Switched back to the shared workspace.");
416
- console.log(`One timeline row records it. Undo while nothing has built on it: cnotes draft undo-merge ${id}`);
417
- if (result.firstCanvasId) {
418
- console.log(`Link: ${cfg.serverUrl}/${result.parentWorkspaceId}?canvasId=${result.firstCanvasId}`);
419
- }
526
+ for (const line of lines)
527
+ console.log(line);
420
528
  }
421
529
  catch (error) {
422
530
  handleError(error, cfg.json);
423
531
  }
424
532
  });
533
+ draft
534
+ .command("merge")
535
+ .description("Agents cannot merge a draft: prints who it waits on and the link a person opens to approve it in the browser")
536
+ .argument("[draft]", "Draft id or name; defaults to the active workspace")
537
+ .addHelpText("after", `
538
+ A draft lands in the shared workspace only when a person approves it in the
539
+ browser. No key or agent can merge it, so this command always refuses. It
540
+ says who the draft waits on and prints the link to give that person, then
541
+ exits 7 (permission). --json puts the link in details.url.
542
+
543
+ When the checks are clear (cnotes draft status), name who decides with
544
+ cnotes draft ask --reviewer <email|me>, and stop.
545
+ `)
546
+ .action(async (ref) => {
547
+ const cfg = resolveBaseConfig(program.opts());
548
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
549
+ try {
550
+ const id = await resolveTarget(api, ref, cfg.workspaceId);
551
+ // The server refuses every key with 403 human_approval_required. Asking
552
+ // it anyway gets the current sentence: who the draft waits on.
553
+ const answer = await api.post(`/api/workspace-drafts/${id}`, { action: "merge" }).catch((e) => {
554
+ throw approvalRefusal(e) ? e : notADraft(e, Boolean(ref));
555
+ });
556
+ outputJson(answer);
557
+ }
558
+ catch (error) {
559
+ const refusal = approvalRefusal(error);
560
+ if (!refusal)
561
+ handleError(error, cfg.json);
562
+ const draftId = refusal.draftId ?? (await resolveTarget(api, ref, cfg.workspaceId).catch(() => undefined));
563
+ const detail = draftId
564
+ ? await api.get(`/api/workspace-drafts/${draftId}`).catch(() => null)
565
+ : null;
566
+ const url = detail ? draftLink(cfg.serverUrl, detail) : draftId ? workspaceUrl(cfg.serverUrl, draftId) : null;
567
+ handleError(new CliError(refusalMessage({ ...refusal, canvasId: refusal.canvasId ?? detail?.branch?.sourceCanvasId }, detail?.decision), EXIT_CODES.PERMISSION, mergeRefusalHint(refusal, detail?.decision, url), {
568
+ reason: "human_approval_required",
569
+ draftId: draftId ?? null,
570
+ state: refusal.state ?? null,
571
+ waitingOn: refusal.waitingOn ?? null,
572
+ url,
573
+ }), cfg.json);
574
+ }
575
+ });
425
576
  draft
426
577
  .command("undo-merge")
427
- .description("Put a merged draft back: notes and canvases return to it, applied edits are restored as new versions, the draft reopens")
578
+ .description("Ask to put a merged draft back. Undoing reverses a person's decision, so only the person who approved it can, from the merge row in History in the browser; a key is refused with that link")
428
579
  .argument("[draft]", "Draft id or name; defaults to the active workspace")
429
580
  .action(async (ref) => {
430
581
  const cfg = resolveBaseConfig(program.opts());
431
- const api = new ApiClient(cfg.serverUrl, cfg.token);
582
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
432
583
  try {
433
584
  const id = await resolveTarget(api, ref, cfg.workspaceId);
434
585
  const result = await api
@@ -457,7 +608,7 @@ its current text clears the base conflict the checks report.
457
608
  .argument("[draft]", "Draft id or name; defaults to the active workspace")
458
609
  .action(async (ref) => {
459
610
  const cfg = resolveBaseConfig(program.opts());
460
- const api = new ApiClient(cfg.serverUrl, cfg.token);
611
+ const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
461
612
  try {
462
613
  const id = await resolveTarget(api, ref, cfg.workspaceId);
463
614
  const result = await api
@@ -465,17 +616,26 @@ its current text clears the base conflict the checks report.
465
616
  .catch((e) => {
466
617
  throw notADraft(e, Boolean(ref));
467
618
  });
468
- const switched = id === cfg.workspaceId ? activate(cfg.serverUrl, result.parentWorkspaceId).switched : false;
619
+ const switchResult = id === cfg.workspaceId
620
+ ? activate(cfg.serverUrl, result.parentWorkspaceId, cfg.workspaceOverrides, undefined, "the shared workspace")
621
+ : null;
469
622
  if (cfg.quiet) {
470
623
  console.log(id);
471
624
  return;
472
625
  }
473
626
  if (cfg.json) {
474
- outputJson({ ...result, draftId: id });
627
+ outputJson({
628
+ ...result,
629
+ draftId: id,
630
+ switchedBack: switchResult?.active ?? false,
631
+ ...(switchResult?.notice ? { notice: switchResult.notice } : {}),
632
+ });
475
633
  return;
476
634
  }
477
635
  console.log("Dismissed. Nothing from the draft reached the shared workspace.");
478
- if (switched)
636
+ if (switchResult?.notice)
637
+ console.log(switchResult.notice);
638
+ else if (switchResult?.active)
479
639
  console.log("Switched back to the shared workspace.");
480
640
  }
481
641
  catch (error) {