@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.
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +1 -0
- package/dist/commands/auth-keys.js +2 -2
- package/dist/commands/auth-keys.js.map +1 -1
- package/dist/commands/brief.js +1 -1
- package/dist/commands/brief.js.map +1 -1
- package/dist/commands/canvas-milestone.js +3 -3
- package/dist/commands/canvas-milestone.js.map +1 -1
- package/dist/commands/canvas.js +43 -43
- package/dist/commands/canvas.js.map +1 -1
- package/dist/commands/deps.js +3 -3
- package/dist/commands/deps.js.map +1 -1
- package/dist/commands/draft.d.ts.map +1 -1
- package/dist/commands/draft.js +301 -141
- package/dist/commands/draft.js.map +1 -1
- package/dist/commands/feedback.js +3 -3
- package/dist/commands/feedback.js.map +1 -1
- package/dist/commands/files.js +3 -3
- package/dist/commands/files.js.map +1 -1
- package/dist/commands/focus.js +3 -3
- package/dist/commands/focus.js.map +1 -1
- package/dist/commands/init.js +1 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/notes.js +12 -12
- package/dist/commands/notes.js.map +1 -1
- package/dist/commands/operations.js +4 -4
- package/dist/commands/operations.js.map +1 -1
- package/dist/commands/quality.js +1 -1
- package/dist/commands/quality.js.map +1 -1
- package/dist/commands/relationships.d.ts +5 -0
- package/dist/commands/relationships.d.ts.map +1 -1
- package/dist/commands/relationships.js +13 -8
- package/dist/commands/relationships.js.map +1 -1
- package/dist/commands/review.d.ts.map +1 -1
- package/dist/commands/review.js +10 -7
- package/dist/commands/review.js.map +1 -1
- package/dist/commands/schema.js +1 -1
- package/dist/commands/schema.js.map +1 -1
- package/dist/commands/search.js +2 -2
- package/dist/commands/search.js.map +1 -1
- package/dist/commands/shared.js +1 -1
- package/dist/commands/shared.js.map +1 -1
- package/dist/commands/theme.js +5 -5
- package/dist/commands/theme.js.map +1 -1
- package/dist/commands/timeline.js +1 -1
- package/dist/commands/timeline.js.map +1 -1
- package/dist/commands/types.js +4 -4
- package/dist/commands/types.js.map +1 -1
- package/dist/commands/upgrade.js +1 -1
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/versions.js +2 -2
- package/dist/commands/versions.js.map +1 -1
- package/dist/commands/workspace.d.ts.map +1 -1
- package/dist/commands/workspace.js +90 -9
- package/dist/commands/workspace.js.map +1 -1
- package/dist/lib/api-client.d.ts +19 -1
- package/dist/lib/api-client.d.ts.map +1 -1
- package/dist/lib/api-client.js +32 -2
- package/dist/lib/api-client.js.map +1 -1
- package/dist/lib/config.d.ts +14 -0
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +20 -5
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/draft-view.d.ts +306 -0
- package/dist/lib/draft-view.d.ts.map +1 -0
- package/dist/lib/draft-view.js +358 -0
- package/dist/lib/draft-view.js.map +1 -0
- package/dist/lib/errors.d.ts +6 -0
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +64 -1
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/urls.d.ts +15 -0
- package/dist/lib/urls.d.ts.map +1 -1
- package/dist/lib/urls.js +20 -0
- package/dist/lib/urls.js.map +1 -1
- package/dist/mcp-server.js +5 -1
- package/dist/mcp-server.js.map +1 -1
- package/package.json +1 -1
- package/skills/cnotes/SKILL.md +86 -60
package/dist/commands/draft.js
CHANGED
|
@@ -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 {
|
|
6
|
-
import { outputJson, outputTable,
|
|
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,
|
|
10
|
-
*
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
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
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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 #
|
|
81
|
-
$ cnotes draft
|
|
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("
|
|
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
|
-
|
|
96
|
-
|
|
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({
|
|
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
|
-
|
|
106
|
-
|
|
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
|
|
110
|
-
console.log(
|
|
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
|
-
|
|
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
|
|
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({
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (
|
|
179
|
-
console.log(
|
|
180
|
-
|
|
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("
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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({
|
|
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
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
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
|
|
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
|
|
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("
|
|
387
|
-
.description("
|
|
388
|
-
.
|
|
389
|
-
.
|
|
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,
|
|
498
|
+
const id = await resolveTarget(api, opts.draft, cfg.workspaceId);
|
|
394
499
|
const result = await api
|
|
395
|
-
.post(`/api/workspace-drafts/${id}`, {
|
|
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(
|
|
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.
|
|
519
|
+
console.log(result.requestId);
|
|
402
520
|
return;
|
|
403
521
|
}
|
|
404
522
|
if (cfg.json) {
|
|
405
|
-
outputJson({ ...result,
|
|
523
|
+
outputJson({ ...result, link, draftId: id, line: lines.join(" ") });
|
|
406
524
|
return;
|
|
407
525
|
}
|
|
408
|
-
|
|
409
|
-
|
|
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("
|
|
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
|
|
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({
|
|
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 (
|
|
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) {
|