@creator-notes/cnotes 0.106.0 → 0.107.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creator-notes-cli",
3
- "version": "0.106.0",
3
+ "version": "0.107.0",
4
4
  "description": "CreatorNotes CLI: create notes, build canvases, search knowledge from the terminal",
5
5
  "author": {
6
6
  "name": "CreatorNotes",
@@ -7,6 +7,7 @@ import { outputJson, outputTable, truncate, timeAgo } from "../lib/output.js";
7
7
  import { proposalHandle, resolveDraftRef, resolveProposalHandle } from "../lib/draft-ref.js";
8
8
  import { canvasUrl, workspaceUrl } from "../lib/urls.js";
9
9
  import { detectAgentClient } from "../lib/agent-client.js";
10
+ import { inPlaceStatusLines, inPlaceTarget, openedInPlaceLines, workingInPlaceLine, } from "../lib/proposal-in-place.js";
10
11
  import { PRIVATE_UNTIL_APPROVED, approvalRefusal, askBlockedWarning, askedLines, branchOpenedSentence, branchSummary, decisionSentence, draftLink, draftListNotes, draftListStatus, mergeUndoLink, unsureAcceptLine, mergeRefusalHint, notADraft, rebranchedLines, refusalMessage, proposalNotice, spokenDetail, statusLines, MESSAGE_HINT, } from "../lib/draft-view.js";
11
12
  /** "1,2,5" as run indexes; undefined when nothing was passed. */
12
13
  function parseRuns(raw) {
@@ -182,7 +183,39 @@ out, so the work keeps its direction.
182
183
  intent: opts.intent,
183
184
  answers: splitIds(opts.answers),
184
185
  fromCanvas: opts.fromCanvas?.trim() || undefined,
186
+ // A proposal of notes opens in place where the workspace has it on.
187
+ ...(opts.fromCanvas?.trim() ? {} : { inPlace: true }),
185
188
  });
189
+ if (created.kind === "in_place") {
190
+ const handle = created.displayId ?? created.draftId;
191
+ const switched = opts.switch
192
+ ? enterProposal(cfg.serverUrl, created.parentWorkspaceId, { draftId: created.draftId, handle: created.displayId, name: created.name, kind: "in_place" }, cfg.workspaceOverrides, parentLabel(created.parentWorkspaceId))
193
+ : null;
194
+ const link = `${workspaceUrl(cfg.serverUrl, created.parentWorkspaceId)}?${new URLSearchParams({ proposal: created.draftId }).toString()}`;
195
+ if (cfg.quiet) {
196
+ console.log(created.draftId);
197
+ return;
198
+ }
199
+ if (cfg.json) {
200
+ outputJson({
201
+ ...created,
202
+ url: link,
203
+ active: switched?.active ?? false,
204
+ savedAsActive: switched?.switched ?? false,
205
+ shadowedBy: switched?.shadowedBy ?? null,
206
+ ...(switched?.notice ? { notice: switched.notice } : {}),
207
+ });
208
+ return;
209
+ }
210
+ for (const line of openedInPlaceLines(handle, created.name))
211
+ console.log(line);
212
+ if (switched?.notice)
213
+ console.log(switched.notice);
214
+ else if (switched?.active)
215
+ console.log(workingInPlaceLine(handle));
216
+ console.log(`Link: ${link}`);
217
+ return;
218
+ }
186
219
  // A server too old to branch boards ignores fromCanvas and opens an
187
220
  // ordinary empty draft. Close it again and say so, rather than put
188
221
  // the agent into a draft that does not hold the board.
@@ -243,15 +276,38 @@ out, so the work keeps its direction.
243
276
  const data = await api.get("/api/workspace-drafts", {
244
277
  includeClosed: opts.all ? "true" : undefined,
245
278
  });
279
+ // Proposals in place live in the shared workspace you work in.
280
+ const sharedId = liveWorkspaceId(cfg);
281
+ const inPlace = sharedId
282
+ ? await api
283
+ .get("/api/proposals", { workspaceId: sharedId, includeClosed: opts.all ? "true" : undefined })
284
+ .then((r) => r.proposals, () => [])
285
+ : [];
246
286
  if (cfg.quiet) {
247
287
  for (const d of data.drafts)
248
288
  console.log(d.id);
289
+ for (const p of inPlace)
290
+ console.log(p.id);
249
291
  return;
250
292
  }
251
293
  if (cfg.json) {
252
- outputJson(data);
294
+ outputJson({ ...data, inPlace });
253
295
  return;
254
296
  }
297
+ if (inPlace.length > 0) {
298
+ outputTable(["ID", "NAME", "IN", "STATUS", "OPENED", ""], inPlace.map((p) => [
299
+ p.displayId,
300
+ truncate(p.name, 32),
301
+ "in place",
302
+ p.role === "reviewer" ? "asked of you" : p.status,
303
+ timeAgo(p.createdAt),
304
+ cfg.proposal?.draftId === p.id ? "(active)" : "",
305
+ ]));
306
+ if (data.drafts.length > 0)
307
+ console.log("");
308
+ }
309
+ if (data.drafts.length === 0 && inPlace.length > 0)
310
+ return;
255
311
  if (data.drafts.length === 0) {
256
312
  console.log("No open drafts. Start one with `cnotes draft open <name>`.");
257
313
  return;
@@ -283,6 +339,36 @@ out, so the work keeps its direction.
283
339
  const cfg = resolveBaseConfig(program.opts());
284
340
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
285
341
  try {
342
+ const inPlaceId = await inPlaceTarget(api, ref, cfg);
343
+ if (inPlaceId) {
344
+ const s = await api.get(`/api/proposals/${inPlaceId}`);
345
+ const p = s.proposal;
346
+ const takesWrites = p.status === "open" && p.isOwner;
347
+ const switched = takesWrites
348
+ ? enterProposal(cfg.serverUrl, p.workspaceId, { draftId: p.id, handle: p.displayId, name: p.name, kind: "in_place" }, cfg.workspaceOverrides, parentLabel(p.workspaceId))
349
+ : { switched: false, active: false, shadowedBy: null };
350
+ if (cfg.quiet) {
351
+ console.log(p.id);
352
+ return;
353
+ }
354
+ if (cfg.json) {
355
+ outputJson({ ...s, active: switched.active, savedAsActive: switched.switched, shadowedBy: switched.shadowedBy });
356
+ return;
357
+ }
358
+ console.log(`Checked out ${p.displayId} "${p.name}": ${s.notes.length} new notes, ${s.canvases.length} canvases, ${s.edits.length} proposed rewordings.`);
359
+ if (switched.notice)
360
+ console.log(switched.notice);
361
+ else if (switched.active)
362
+ console.log(workingInPlaceLine(p.displayId));
363
+ else if (p.status !== "open")
364
+ console.log(`${p.displayId} is ${p.status}, so it takes no more writes.`);
365
+ if (p.intent)
366
+ console.log(`Intent: ${p.intent}`);
367
+ console.log(s.decision.line);
368
+ if (p.status === "open")
369
+ console.log(`Link: ${s.url}`);
370
+ return;
371
+ }
286
372
  const id = await resolveTarget(api, ref, cfg);
287
373
  const detail = await api.get(`/api/workspace-drafts/${id}`);
288
374
  const d = detail.draft;
@@ -372,6 +458,25 @@ names each workspace with the -w that selects it.
372
458
  const cfg = resolveBaseConfig(program.opts());
373
459
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
374
460
  try {
461
+ const inPlaceId = await inPlaceTarget(api, ref, cfg);
462
+ if (inPlaceId) {
463
+ const s = await api.get(`/api/proposals/${inPlaceId}`);
464
+ // Accepted or dismissed: stop sending commands into it.
465
+ if (s.proposal.status !== "open" && cfg.proposal?.draftId === inPlaceId && cfg.proposal.source === "saved") {
466
+ clearProposalById(loadConfig(), cfg.serverUrl, inPlaceId);
467
+ }
468
+ if (cfg.quiet) {
469
+ console.log(inPlaceId);
470
+ return;
471
+ }
472
+ if (cfg.json) {
473
+ outputJson(s);
474
+ return;
475
+ }
476
+ for (const line of inPlaceStatusLines(s))
477
+ console.log(line);
478
+ return;
479
+ }
375
480
  const id = await resolveTarget(api, ref, cfg);
376
481
  const detail = await api.get(`/api/workspace-drafts/${id}`).catch((e) => {
377
482
  throw notADraft(e, Boolean(ref));
@@ -464,6 +569,24 @@ editsApplied, mergeId, operationId, runsMerged?, runsLeft? }.
464
569
  const cfg = resolveBaseConfig(program.opts());
465
570
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
466
571
  try {
572
+ const inPlaceId = await inPlaceTarget(api, ref, cfg);
573
+ if (inPlaceId) {
574
+ if (opts.runs)
575
+ throw new ValidationError("A proposal in place lands whole", "Accept it, or send it back");
576
+ const landed = await api.post(`/api/proposals/${inPlaceId}`, { action: "accept", note: opts.note });
577
+ if (cfg.quiet) {
578
+ console.log(inPlaceId);
579
+ return;
580
+ }
581
+ if (cfg.json) {
582
+ outputJson(landed);
583
+ return;
584
+ }
585
+ const n = (count, one) => `${count} ${one}${count === 1 ? "" : "s"}`;
586
+ console.log(`Accepted ${landed.merged} under your key: ${n(landed.notes, "note")} and ${n(landed.canvases, "canvas")} are live, ${n(landed.edits, "rewording")} applied.`);
587
+ console.log("Undo is yours, in the browser, while nobody has built on it.");
588
+ return;
589
+ }
467
590
  const id = await resolveTarget(api, ref, cfg);
468
591
  const detail = await api.get(`/api/workspace-drafts/${id}`).catch((e) => {
469
592
  throw notADraft(e, Boolean(ref));
@@ -570,6 +693,17 @@ Sending it back as a verdict stays with the person, in the browser.
570
693
  const cfg = resolveBaseConfig(program.opts());
571
694
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
572
695
  try {
696
+ const inPlaceId = await inPlaceTarget(api, ref, cfg);
697
+ if (inPlaceId) {
698
+ const result = await api.post(`/api/proposals/${inPlaceId}`, { action: "send-back", note: opts.note });
699
+ if (cfg.quiet)
700
+ console.log(inPlaceId);
701
+ else if (cfg.json)
702
+ outputJson(result);
703
+ else
704
+ console.log("Sent back. The proposer reads your line in cnotes draft status and asks again when it is fixed.");
705
+ return;
706
+ }
573
707
  const id = await resolveTarget(api, ref, cfg);
574
708
  const result = await api
575
709
  .post(`/api/workspace-drafts/${id}`, { action: "send-back", note: opts.note })
@@ -621,6 +755,28 @@ way a draft changes a shared note: a live edit of one from inside a draft
621
755
  if (!markdown || !markdown.trim()) {
622
756
  throw new ValidationError("A proposal needs the new body", "Pass --markdown-file <path>, --markdown <text> or --markdown-stdin");
623
757
  }
758
+ const inPlaceId = await inPlaceTarget(api, opts.draft, cfg);
759
+ if (inPlaceId) {
760
+ // A save of a live note while you work in the proposal is the rewording.
761
+ if (cfg.proposal?.draftId !== inPlaceId) {
762
+ throw new ValidationError("Work in the proposal to propose a rewording into it", `Run \`cnotes draft checkout ${opts.draft}\` first`);
763
+ }
764
+ const result = await api.post(`/api/notes/${encodeURIComponent(note)}/versions`, { content: markdown, description: opts.description });
765
+ if (!result.proposed) {
766
+ throw new CliError(`${note} belongs to the proposal, so the save wrote its next version instead of proposing one.`, EXIT_CODES.GENERIC, "Propose rewordings of live notes only; a note the proposal made changes with cnotes versions create");
767
+ }
768
+ if (cfg.quiet) {
769
+ console.log(result.noteDisplayId);
770
+ return;
771
+ }
772
+ if (cfg.json) {
773
+ outputJson({ ...result, draftId: inPlaceId });
774
+ return;
775
+ }
776
+ console.log(`${result.replaced ? "Updated the proposal for" : "Proposed a new text for"} ${result.noteDisplayId}: "${result.title}" (based on v${result.baseVersionNumber}).`);
777
+ console.log("The live note is unchanged until a person accepts the proposal. Check with: cnotes draft status");
778
+ return;
779
+ }
624
780
  const id = await resolveTarget(api, opts.draft, cfg);
625
781
  const result = await api
626
782
  .post(`/api/workspace-drafts/${id}/edits`, { action: "propose", note, markdown, description: opts.description })
@@ -661,6 +817,26 @@ displayId, title, type, versionNumber, markdown } }.
661
817
  const cfg = resolveBaseConfig(program.opts());
662
818
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
663
819
  try {
820
+ const inPlaceId = await inPlaceTarget(api, ref, cfg);
821
+ if (inPlaceId) {
822
+ // The proposer and the person asked read its notes like any other:
823
+ // cnotes notes get <id> shows a pending note to them.
824
+ const st = await api.get(`/api/proposals/${inPlaceId}`);
825
+ if (opts.note) {
826
+ throw new ValidationError(`Read it with cnotes notes get ${opts.note}`, "A proposal in place's notes read like any other note, for you");
827
+ }
828
+ if (cfg.json) {
829
+ outputJson({ notes: st.notes, canvases: st.canvases });
830
+ return;
831
+ }
832
+ for (const n of st.notes)
833
+ console.log(`${n.displayId} ${n.type} ${n.title ?? "Untitled"}`);
834
+ for (const c of st.canvases)
835
+ console.log(`${c.displayId ?? c.id} canvas ${c.name}`);
836
+ if (st.notes.length + st.canvases.length === 0)
837
+ console.log(`${st.proposal.displayId} adds no notes or canvases.`);
838
+ return;
839
+ }
664
840
  const id = await resolveTarget(api, ref, cfg);
665
841
  if (opts.note) {
666
842
  const one = await api.get(`/api/workspace-drafts/${id}/notes`, { note: opts.note });
@@ -712,6 +888,20 @@ displayId, title, type, versionNumber, markdown } }.
712
888
  const cfg = resolveBaseConfig(program.opts());
713
889
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
714
890
  try {
891
+ const inPlaceId = await inPlaceTarget(api, opts.draft, cfg);
892
+ if (inPlaceId) {
893
+ const st = await api.get(`/api/proposals/${inPlaceId}`);
894
+ if (cfg.json) {
895
+ outputJson({ edits: st.edits });
896
+ return;
897
+ }
898
+ if (st.edits.length === 0)
899
+ console.log(`${st.proposal.displayId} proposes no rewordings.`);
900
+ for (const e of st.edits) {
901
+ console.log(`${e.noteDisplayId} ${e.title ?? ""} (based on v${e.baseVersionNumber})${e.changeDescription ? `: ${e.changeDescription.split("\n")[0]}` : ""}`);
902
+ }
903
+ return;
904
+ }
715
905
  const id = await resolveTarget(api, opts.draft, cfg);
716
906
  if (opts.note) {
717
907
  const one = await api
@@ -771,6 +961,17 @@ displayId, title, type, versionNumber, markdown } }.
771
961
  const cfg = resolveBaseConfig(program.opts());
772
962
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
773
963
  try {
964
+ const inPlaceId = await inPlaceTarget(api, opts.draft, cfg);
965
+ if (inPlaceId) {
966
+ const result = await api.post(`/api/proposals/${inPlaceId}`, { action: "discard", noteDisplayId: note });
967
+ if (cfg.quiet)
968
+ console.log(result.discarded);
969
+ else if (cfg.json)
970
+ outputJson({ ...result, draftId: inPlaceId });
971
+ else
972
+ console.log(`Discarded the proposal for ${result.discarded}.`);
973
+ return;
974
+ }
774
975
  const id = await resolveTarget(api, opts.draft, cfg);
775
976
  const result = await api
776
977
  .post(`/api/workspace-drafts/${id}/edits`, { action: "discard", note })
@@ -848,6 +1049,29 @@ Examples:
848
1049
  const cfg = resolveBaseConfig(program.opts());
849
1050
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
850
1051
  try {
1052
+ const inPlaceId = await inPlaceTarget(api, opts.draft, cfg);
1053
+ if (inPlaceId) {
1054
+ if (!opts.headline) {
1055
+ throw new ValidationError("Say what it did: --headline", MESSAGE_HINT);
1056
+ }
1057
+ const asked = await api.post(`/api/proposals/${inPlaceId}`, { action: "ask", reviewer: opts.reviewer, headline: opts.headline, changes: opts.changes, leftOut: opts.leftOut });
1058
+ const blocking = asked.checks.findings.filter((f) => f.blocking);
1059
+ for (const f of blocking)
1060
+ console.error(`Blocking: ${f.message} ${f.fix}`);
1061
+ if (cfg.quiet) {
1062
+ console.log(inPlaceId);
1063
+ return;
1064
+ }
1065
+ if (cfg.json) {
1066
+ outputJson({ ...asked, draftId: inPlaceId, link: asked.url });
1067
+ return;
1068
+ }
1069
+ console.log(blocking.length > 0
1070
+ ? `Asked, but ${blocking.length} check${blocking.length === 1 ? "" : "s"} block${blocking.length === 1 ? "s" : ""} it: nothing can be accepted until you fix ${blocking.length === 1 ? "it" : "them"} and ask again.`
1071
+ : "Asked. The person decides it; your part is done, so stop here.");
1072
+ console.log(`Link: ${asked.url}`);
1073
+ return;
1074
+ }
851
1075
  const id = await resolveTarget(api, opts.draft, cfg);
852
1076
  const result = await api
853
1077
  .post(`/api/workspace-drafts/${id}`, {
@@ -951,6 +1175,25 @@ cnotes draft ask --reviewer <email|me>, and stop.
951
1175
  const cfg = resolveBaseConfig(program.opts());
952
1176
  const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
953
1177
  try {
1178
+ const inPlaceId = await inPlaceTarget(api, ref, cfg);
1179
+ if (inPlaceId) {
1180
+ const result = await api.post(`/api/proposals/${inPlaceId}`, { action: "dismiss" });
1181
+ const wasActive = cfg.proposal?.draftId === inPlaceId;
1182
+ clearProposalById(loadConfig(), cfg.serverUrl, inPlaceId);
1183
+ const stillPinned = wasActive && cfg.proposal?.source === "env";
1184
+ if (cfg.quiet)
1185
+ console.log(inPlaceId);
1186
+ else if (cfg.json)
1187
+ outputJson({ ...result, draftId: inPlaceId, switchedBack: wasActive && !stillPinned });
1188
+ else {
1189
+ console.log(`Dismissed ${result.dismissed}. Nothing from it reached the shared workspace.`);
1190
+ if (stillPinned)
1191
+ console.log(LEAVE_PINNED);
1192
+ else if (wasActive)
1193
+ console.log("You work live in the shared workspace again.");
1194
+ }
1195
+ return;
1196
+ }
954
1197
  const id = await resolveTarget(api, ref, cfg);
955
1198
  const result = await api
956
1199
  .post(`/api/workspace-drafts/${id}`, { action: "dismiss" })
@@ -1,5 +1,6 @@
1
1
  import { ApiError, asCliError, CliError, EXIT_CODES, isPermanentNetworkError, isRefusedBeforeSend } from "./errors.js";
2
2
  import { loadConfig, getActiveAgentRunId, getServerConfig } from "./auth-store.js";
3
+ import { inPlaceProposalId, resolveProposal } from "./config.js";
3
4
  import { detectAgentClient } from "./agent-client.js";
4
5
  const MAX_RETRIES = 3;
5
6
  const RETRY_BASE_MS = 1000;
@@ -54,6 +55,12 @@ export function resolveActiveAgentRun(serverUrl) {
54
55
  * Advisory: it can only make a write stricter, never wider.
55
56
  */
56
57
  export const WORKSPACE_HEADER = "X-Cnotes-Workspace";
58
+ /**
59
+ * The header that sends a write into a proposal in place: the server stamps
60
+ * new notes and canvases with it and turns a save of a live note into a
61
+ * proposed rewording (convex/lib/proposalVisibility.ts).
62
+ */
63
+ export const PROPOSAL_HEADER = "X-Cnotes-Proposal";
57
64
  export class ApiClient {
58
65
  serverUrl;
59
66
  token;
@@ -71,6 +78,10 @@ export class ApiClient {
71
78
  this.workspaceId = workspaceId;
72
79
  }
73
80
  /** The working workspace sent as {@link WORKSPACE_HEADER}, if one is known. */
81
+ /** The proposal in place commands aimed at `workspace` go into (CNOTES_PROPOSAL, else the saved one). */
82
+ inPlaceProposal(workspace) {
83
+ return inPlaceProposalId(resolveProposal(workspace, getServerConfig(loadConfig(), this.serverUrl)));
84
+ }
74
85
  workingWorkspace() {
75
86
  const id = this.workspaceId?.trim() ||
76
87
  process.env.CNOTES_WORKSPACE?.trim() ||
@@ -111,6 +122,9 @@ export class ApiClient {
111
122
  const workspace = this.workingWorkspace();
112
123
  if (workspace)
113
124
  base[WORKSPACE_HEADER] = workspace;
125
+ const proposal = this.inPlaceProposal(workspace);
126
+ if (proposal)
127
+ base[PROPOSAL_HEADER] = proposal;
114
128
  const run = resolveActiveAgentRun(this.serverUrl);
115
129
  if (run) {
116
130
  base["X-Agent-Run-Id"] = run.agentRunId;
@@ -244,6 +258,9 @@ export class ApiClient {
244
258
  const workspace = this.workingWorkspace();
245
259
  if (workspace)
246
260
  headers[WORKSPACE_HEADER] = workspace;
261
+ const proposal = this.inPlaceProposal(workspace);
262
+ if (proposal)
263
+ headers[PROPOSAL_HEADER] = proposal;
247
264
  // Build fresh FormData per attempt so retries don't send a consumed body
248
265
  const res = await this.fetchWithRetry(url.toString(), {
249
266
  method: "POST",
@@ -1,5 +1,9 @@
1
1
  import { loadConfig, getServerConfig } from "./auth-store.js";
2
2
  import { AuthError, ValidationError } from "./errors.js";
3
+ /** The proposal-in-place id to send as X-Cnotes-Proposal, when commands go into one. */
4
+ export function inPlaceProposalId(proposal) {
5
+ return proposal?.kind === "in_place" ? proposal.draftId : undefined;
6
+ }
3
7
  /** CNOTES_PROPOSAL values that mean "work live in this terminal". */
4
8
  export const LIVE_VALUES = new Set(["none", "live", "off"]);
5
9
  /**
@@ -24,6 +28,7 @@ export function resolveProposal(workspaceId, server, env = process.env.CNOTES_PR
24
28
  name: savedUnder?.[1].name,
25
29
  sharedWorkspaceId: savedUnder?.[0] ?? workspaceId,
26
30
  source: "env",
31
+ ...(savedUnder?.[1].kind ? { kind: savedUnder[1].kind } : {}),
27
32
  };
28
33
  }
29
34
  const saved = server?.proposals?.[workspaceId];
@@ -98,7 +103,8 @@ export function resolveConfig(opts) {
98
103
  return {
99
104
  serverUrl,
100
105
  token,
101
- workspaceId: proposal?.draftId ?? workspaceId,
106
+ // A proposal in place keeps the shared workspace; a draft is its own.
107
+ workspaceId: proposal && !inPlaceProposalId(proposal) ? proposal.draftId : workspaceId,
102
108
  proposal,
103
109
  workspaceSource,
104
110
  workspaceOverrides,
@@ -121,7 +127,7 @@ export function resolveBaseConfig(opts) {
121
127
  serverUrl,
122
128
  token,
123
129
  ...picked,
124
- ...(proposal ? { workspaceId: proposal.draftId, proposal } : {}),
130
+ ...(proposal ? { workspaceId: inPlaceProposalId(proposal) ? picked.workspaceId : proposal.draftId, proposal } : {}),
125
131
  ...resolveOutput(opts),
126
132
  };
127
133
  }
@@ -0,0 +1,102 @@
1
+ import { ApiError } from "./errors.js";
2
+ import { liveWorkspaceId } from "./config.js";
3
+ import { proposalHandle } from "./draft-ref.js";
4
+ const PROPOSAL_ID = /^[a-z0-9]{32}$/;
5
+ /** Whether a 404 means "not a proposal in place" rather than a real failure. */
6
+ function isNotFound(error) {
7
+ return error instanceof ApiError && (error.status === 404 || error.status === 400);
8
+ }
9
+ /**
10
+ * The proposal in place a `draft` command acts on, or null when the target
11
+ * is a draft workspace (or nothing). No ref: the one you work in. A handle:
12
+ * looked up in the shared workspace you work in. An id: asked for directly.
13
+ */
14
+ export async function inPlaceTarget(api, ref, cfg) {
15
+ if (!ref)
16
+ return cfg.proposal?.kind === "in_place" ? cfg.proposal.draftId : null;
17
+ const trimmed = ref.trim();
18
+ if (PROPOSAL_ID.test(trimmed)) {
19
+ if (cfg.proposal?.kind === "in_place" && cfg.proposal.draftId === trimmed)
20
+ return trimmed;
21
+ const found = await api.get(`/api/proposals/${trimmed}`).catch((e) => {
22
+ if (isNotFound(e))
23
+ return null;
24
+ throw e;
25
+ });
26
+ return found ? trimmed : null;
27
+ }
28
+ const handle = proposalHandle(trimmed);
29
+ const workspaceId = liveWorkspaceId(cfg);
30
+ if (!handle || !workspaceId)
31
+ return null;
32
+ const found = await api
33
+ .get("/api/proposals", { workspaceId, handle })
34
+ .catch((e) => {
35
+ if (isNotFound(e))
36
+ return null;
37
+ throw e;
38
+ });
39
+ return found?.id ?? null;
40
+ }
41
+ /** The sentence after opening one. */
42
+ export function openedInPlaceLines(displayId, name, workspaceName) {
43
+ return [
44
+ `Opened ${displayId} "${name}" in place.`,
45
+ `Its notes and canvases are rows of ${workspaceName ?? "the shared workspace"} that only you, and the person you ask, can see until they accept it.`,
46
+ ];
47
+ }
48
+ /** The sentence after a proposal in place becomes the one you work in. */
49
+ export function workingInPlaceLine(displayId) {
50
+ return `You now work in ${displayId}: new notes and canvases land in it, and saving a live note proposes a rewording. \`cnotes draft leave\` works live again.`;
51
+ }
52
+ /** What `draft status` prints for a proposal in place. */
53
+ export function inPlaceStatusLines(s) {
54
+ const p = s.proposal;
55
+ const out = [`${p.displayId} "${p.name}" · ${p.status}`];
56
+ if (p.isReviewer && !p.isOwner && p.status === "open") {
57
+ out.push("Asked of you. Read it, then cnotes draft accept or cnotes draft send-back --note \"<what should change>\".");
58
+ }
59
+ else {
60
+ out.push(s.decision.line);
61
+ }
62
+ if (p.intent)
63
+ out.push(`Why: ${p.intent}`);
64
+ if (p.message) {
65
+ out.push(`Headline: ${p.message.headline}`);
66
+ if (p.message.changes)
67
+ out.push(`Changes: ${p.message.changes}`);
68
+ if (p.message.leftOut)
69
+ out.push(`Left out: ${p.message.leftOut}`);
70
+ }
71
+ const blocking = s.checks.findings.filter((f) => f.blocking);
72
+ const warnings = s.checks.findings.filter((f) => !f.blocking);
73
+ if (blocking.length > 0) {
74
+ out.push("", `Blocking (${blocking.length}):`);
75
+ for (const f of blocking)
76
+ out.push(` ${f.message} ${f.fix}`);
77
+ }
78
+ if (s.notes.length > 0) {
79
+ out.push("", `New notes (${s.notes.length}):`);
80
+ for (const n of s.notes)
81
+ out.push(` ${n.displayId} ${n.title ?? "Untitled"}`);
82
+ }
83
+ if (s.canvases.length > 0) {
84
+ out.push("", `New canvases (${s.canvases.length}):`);
85
+ for (const c of s.canvases)
86
+ out.push(` ${c.displayId ?? c.id} ${c.name}`);
87
+ }
88
+ if (s.edits.length > 0) {
89
+ out.push("", `Proposed rewordings (${s.edits.length}):`);
90
+ for (const e of s.edits) {
91
+ out.push(` ${e.noteDisplayId} ${e.title ?? ""} (based on v${e.baseVersionNumber})${e.changeDescription ? `: ${e.changeDescription.split("\n")[0]}` : ""}`);
92
+ }
93
+ }
94
+ if (warnings.length > 0) {
95
+ out.push("", `Warnings (${warnings.length}):`);
96
+ for (const f of warnings)
97
+ out.push(` ${f.message} ${f.fix}`);
98
+ }
99
+ if (p.status === "open")
100
+ out.push("", `Link: ${s.url}`);
101
+ return out;
102
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator-notes/cnotes",
3
- "version": "0.106.0",
3
+ "version": "0.107.0",
4
4
  "description": "CLI for CreatorNotes — create notes, build canvases, search knowledge from the terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -28,6 +28,21 @@ it into the draft, whether the workspace came from the saved config,
28
28
  workspace and the draft ("Working in: PROPOSAL-9 · ..."). `cnotes draft leave`
29
29
  works live again; the draft stays open.
30
30
 
31
+ ### In place
32
+
33
+ Where a workspace has it on, `draft open` without `--from-canvas` opens a
34
+ proposal **in place** instead: no draft workspace is created. `draft open`
35
+ says "Opened PROPOSAL-16 ... in place". While you work in it, commands stay
36
+ aimed at the shared workspace and the CLI sends the proposal with each one:
37
+ new notes and canvases are rows of the shared workspace that only you and the
38
+ person you ask can see, and saving a live note (`versions create` or `draft
39
+ propose`) proposes a rewording. A change to live work is refused with
40
+ `live_write_from_proposal` (a card or edge on a live board, a live board's
41
+ name, archiving or retyping a live note): build on the proposal's own
42
+ canvases, and say the rest in `--left-out`. `draft status`, `ask`, `accept`,
43
+ `send-back`, `dismiss`, `discard` and `leave` work the same way. Branching a
44
+ board (`--from-canvas`) still opens a draft workspace.
45
+
31
46
  ## When to open one
32
47
 
33
48
  Open a draft before you: