@creator-notes/cnotes 0.117.1 → 0.119.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/dist/commands/draft.js +57 -0
- package/dist/lib/api-client.js +18 -3
- package/dist/lib/errors.js +31 -5
- package/dist/lib/intent-run.js +22 -1
- package/dist/lib/mcp-run.js +59 -0
- package/dist/lib/proposal-in-place.js +10 -0
- package/dist/lib/waiting-proposals.js +3 -0
- package/dist/mcp-server.js +128 -77
- package/dist/program.js +5 -1
- package/package.json +1 -1
- package/skills/cnotes/SKILL.md +2 -2
- package/skills/cnotes/references/drafts.md +23 -0
- package/skills/cnotes/references/operations.md +3 -3
package/dist/commands/draft.js
CHANGED
|
@@ -726,6 +726,63 @@ Sending it back as a verdict stays with the person, in the browser.
|
|
|
726
726
|
handleError(error, cfg.json);
|
|
727
727
|
}
|
|
728
728
|
});
|
|
729
|
+
draft
|
|
730
|
+
.command("prepare")
|
|
731
|
+
.description("Prepare the answer to a proposal asked of your person, for them to give: accept or send it back, with why")
|
|
732
|
+
.argument("[draft]", "Proposal handle (PROPOSAL-n, as operations begin lists it) or id")
|
|
733
|
+
.option("--accept", "Recommend accepting it")
|
|
734
|
+
.option("--send-back", "Recommend sending it back")
|
|
735
|
+
.requiredOption("--note <text>", "Why, in one line the person reads before deciding")
|
|
736
|
+
.addHelpText("after", `
|
|
737
|
+
For another agent of the person a proposal in place was asked of, under its
|
|
738
|
+
own key. The person reads your recommendation on the review in the browser or
|
|
739
|
+
on the phone and gives the answer with one tap; nothing lands until they do.
|
|
740
|
+
Then stop: preparing is your whole part.
|
|
741
|
+
|
|
742
|
+
The key that built the proposal (opened it, wrote into it, or asked for it)
|
|
743
|
+
cannot prepare its answer (403, exit 7). Two agents on one login key count as
|
|
744
|
+
one agent, so give each its own key: cnotes auth keys create --name "<agent>".
|
|
745
|
+
A proposal with no record of which key built it is left to the person.
|
|
746
|
+
|
|
747
|
+
An accept is refused while a check blocks it; prepare a send-back instead,
|
|
748
|
+
saying what should change. Any later write into the proposal clears what you
|
|
749
|
+
prepared, so prepare after the last change you reviewed.
|
|
750
|
+
|
|
751
|
+
--json: { prepared, verdict }.
|
|
752
|
+
|
|
753
|
+
Examples:
|
|
754
|
+
$ cnotes draft prepare PROPOSAL-7 --accept --note "Matches DECISION-1 and the checks pass"
|
|
755
|
+
$ cnotes draft prepare PROPOSAL-7 --send-back --note "It drops the monthly option DECISION-1 keeps"
|
|
756
|
+
`)
|
|
757
|
+
.action(async (ref, opts) => {
|
|
758
|
+
const cfg = resolveBaseConfig(program.opts());
|
|
759
|
+
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
760
|
+
try {
|
|
761
|
+
if (Boolean(opts.accept) === Boolean(opts.sendBack)) {
|
|
762
|
+
throw new ValidationError("Choose one: --accept or --send-back");
|
|
763
|
+
}
|
|
764
|
+
const inPlaceId = await inPlaceTarget(api, ref, cfg);
|
|
765
|
+
if (!inPlaceId) {
|
|
766
|
+
throw new ValidationError("Only a proposal in place can be prepared. Name it by its handle: cnotes draft prepare PROPOSAL-n.");
|
|
767
|
+
}
|
|
768
|
+
const verdict = opts.accept ? "accept" : "send_back";
|
|
769
|
+
const result = await api.post(`/api/proposals/${inPlaceId}`, {
|
|
770
|
+
action: "prepare",
|
|
771
|
+
verdict,
|
|
772
|
+
note: opts.note,
|
|
773
|
+
});
|
|
774
|
+
if (cfg.quiet)
|
|
775
|
+
console.log(inPlaceId);
|
|
776
|
+
else if (cfg.json)
|
|
777
|
+
outputJson(result);
|
|
778
|
+
else {
|
|
779
|
+
console.log(`Prepared: ${verdict === "accept" ? "accept" : "send it back"}. The person reads it on the review and gives the answer; your part is done, so stop here.`);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
catch (error) {
|
|
783
|
+
handleError(error, cfg.json);
|
|
784
|
+
}
|
|
785
|
+
});
|
|
729
786
|
draft
|
|
730
787
|
.command("propose")
|
|
731
788
|
.description("Propose a new text for a SHARED note from inside the draft; the note changes only when a person approves the draft")
|
package/dist/lib/api-client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
1
2
|
import { ApiError, asCliError, CliError, EXIT_CODES, isPermanentNetworkError, isRefusedBeforeSend } from "./errors.js";
|
|
2
3
|
import { loadConfig, getActiveAgentRunId, getServerConfig } from "./auth-store.js";
|
|
3
4
|
import { inPlaceProposalId, resolveProposal } from "./config.js";
|
|
@@ -22,13 +23,24 @@ function isWriteRequest(method, url) {
|
|
|
22
23
|
return false;
|
|
23
24
|
return !(method === "POST" && READ_POSTS.has(new URL(url).pathname));
|
|
24
25
|
}
|
|
26
|
+
const scopedRun = new AsyncLocalStorage();
|
|
27
|
+
/**
|
|
28
|
+
* Run `fn` with every request it makes riding `run`. The stdio MCP server
|
|
29
|
+
* opens a run per write tool call this way (lib/mcp-run.ts): its tool calls
|
|
30
|
+
* run side by side in one process, so the run cannot live in `process.env`.
|
|
31
|
+
*/
|
|
32
|
+
export function withScopedAgentRun(run, fn) {
|
|
33
|
+
return scopedRun.run(run, fn);
|
|
34
|
+
}
|
|
25
35
|
/**
|
|
26
36
|
* Resolve the agent-run to attach to writes against `serverUrl`, in precedence
|
|
27
37
|
* order:
|
|
28
38
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
39
|
+
* 0. A run scoped to the current call by {@link withScopedAgentRun} (the
|
|
40
|
+
* stdio MCP server's per-tool-call run).
|
|
41
|
+
* 1. `CNOTES_AGENT_RUN_ID` env var (explicit override, wins everything
|
|
42
|
+
* below). `canvas agent-run wrap` sets this for its subprocess, so a
|
|
43
|
+
* wrapped run correctly beats any outer persisted run.
|
|
32
44
|
* 2. The active run persisted on this server's config, written by
|
|
33
45
|
* `cnotes operations begin` / `cnotes canvas agent-run begin` and cleared
|
|
34
46
|
* by their matching `end`.
|
|
@@ -44,6 +56,9 @@ function isWriteRequest(method, url) {
|
|
|
44
56
|
* attached to is exactly the desync that let agent edits record as human ones.
|
|
45
57
|
*/
|
|
46
58
|
export function resolveActiveAgentRun(serverUrl) {
|
|
59
|
+
const scoped = scopedRun.getStore();
|
|
60
|
+
if (scoped)
|
|
61
|
+
return scoped;
|
|
47
62
|
const envRunId = process.env.CNOTES_AGENT_RUN_ID;
|
|
48
63
|
if (envRunId) {
|
|
49
64
|
return {
|
package/dist/lib/errors.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* "ENOTFOUND"). A write that failed after it was sent carries
|
|
23
23
|
* `mayHaveCommitted: true` (see {@link failedBeforeSend}).
|
|
24
24
|
*/
|
|
25
|
+
import { INTENT_COMMANDS } from "./intent-run.js";
|
|
25
26
|
export const EXIT_CODES = {
|
|
26
27
|
OK: 0,
|
|
27
28
|
GENERIC: 1,
|
|
@@ -135,11 +136,13 @@ export class ApiError extends CliError {
|
|
|
135
136
|
? "Update billing on the workspace billing page, then retry."
|
|
136
137
|
: serverCode === "subscription_required"
|
|
137
138
|
? "This workspace is on the free plan. Run `cnotes upgrade` to start a free 7-day Pro trial (no card), then retry."
|
|
138
|
-
:
|
|
139
|
-
?
|
|
140
|
-
:
|
|
141
|
-
?
|
|
142
|
-
:
|
|
139
|
+
: serverCode === "operation_required"
|
|
140
|
+
? operationRequiredHint()
|
|
141
|
+
: reason !== undefined && Object.hasOwn(REASON_HINTS, reason)
|
|
142
|
+
? REASON_HINTS[reason]
|
|
143
|
+
: mayHaveCommitted
|
|
144
|
+
? WRITE_FAILED_AFTER_SEND_HINT
|
|
145
|
+
: hintForStatus(status, baseMsg, resource);
|
|
143
146
|
super(msg, exitCode, hint);
|
|
144
147
|
this.status = status;
|
|
145
148
|
this.body = body;
|
|
@@ -153,6 +156,29 @@ export class ApiError extends CliError {
|
|
|
153
156
|
this.upgradeUrl = body.upgradeUrl;
|
|
154
157
|
}
|
|
155
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* The `<group> <command>` this process is running (program.ts sets it before
|
|
161
|
+
* the action), so a refusal can name the flag that fixes that command.
|
|
162
|
+
*/
|
|
163
|
+
let runningCommand;
|
|
164
|
+
export function setRunningCommand(path) {
|
|
165
|
+
runningCommand = path;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The server refuses a write from a key outside an agent run (422
|
|
169
|
+
* `operation_required`, FEEDBACK-6KQR). A command that takes `--intent` is one
|
|
170
|
+
* flag away from its own run; anything else needs a run opened around it.
|
|
171
|
+
*/
|
|
172
|
+
export function operationRequiredHint(command = runningCommand) {
|
|
173
|
+
const bracket = "For several writes that belong together, open one run with `cnotes operations begin --prompt \"<headline>\"` " +
|
|
174
|
+
"and close it with `cnotes operations end`.";
|
|
175
|
+
if (command && Object.hasOwn(INTENT_COMMANDS, command)) {
|
|
176
|
+
return (`Add --intent "<what you are changing>" to \`cnotes ${command}\` and run it again: ` +
|
|
177
|
+
`it opens a run for this one change and closes it after. ${bracket}`);
|
|
178
|
+
}
|
|
179
|
+
return ("Open a run with `cnotes operations begin --prompt \"<headline>\"`, run this again, then close it with " +
|
|
180
|
+
'`cnotes operations end`. A single write command that lists --intent in its --help can take --intent "<headline>" instead.');
|
|
181
|
+
}
|
|
156
182
|
/**
|
|
157
183
|
* The prefix of the server's refusal when a key tries to complete a draft's
|
|
158
184
|
* review round as approved. That refusal carries no machine reason yet, so
|
package/dist/lib/intent-run.js
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* "<group> <command>" → bracket. Group names, not aliases. Every command that
|
|
3
|
+
* writes through a route the server guards with `requireAgentRun` belongs here
|
|
4
|
+
* (FEEDBACK-6KQR): outside a run the server refuses it with 422
|
|
5
|
+
* `operation_required`, and `--intent` is the one-call way into a run.
|
|
6
|
+
*/
|
|
2
7
|
export const INTENT_COMMANDS = {
|
|
3
8
|
"notes create": "workspace",
|
|
9
|
+
"notes update": "workspace",
|
|
10
|
+
"notes delete": "workspace",
|
|
11
|
+
"notes bulk-archive": "workspace",
|
|
12
|
+
"notes retype": "workspace",
|
|
13
|
+
"notes bulk-retype": "workspace",
|
|
14
|
+
"notes move": "workspace",
|
|
4
15
|
"versions create": "workspace",
|
|
16
|
+
// In a proposal in place, a proposed rewording is saved as a version.
|
|
17
|
+
"draft propose": "workspace",
|
|
18
|
+
"relationships rm": "workspace",
|
|
19
|
+
"deps review": "workspace",
|
|
5
20
|
"canvas create": "workspace",
|
|
21
|
+
"canvas from-template": "workspace",
|
|
6
22
|
"canvas update": "workspace",
|
|
23
|
+
// Deleting the whole canvas leaves no canvas to snapshot after, so not a canvas run.
|
|
24
|
+
"canvas delete": "workspace",
|
|
25
|
+
"canvas archive": "workspace",
|
|
26
|
+
"canvas unarchive": "workspace",
|
|
7
27
|
"canvas place": "workspace",
|
|
8
28
|
"canvas arrange": "workspace",
|
|
9
29
|
"canvas add-node": "workspace",
|
|
10
30
|
"canvas add-text": "workspace",
|
|
31
|
+
"canvas add-richtext": "workspace",
|
|
11
32
|
"canvas add-section": "workspace",
|
|
12
33
|
"canvas add-list": "workspace",
|
|
13
34
|
"canvas add-link": "workspace",
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One agent run per write tool call in the stdio MCP server (FEEDBACK-6KQR).
|
|
3
|
+
*
|
|
4
|
+
* The server refuses a write from a `cn_` key that arrives outside a run
|
|
5
|
+
* (422 `operation_required`), so a write tool that just called REST would fail
|
|
6
|
+
* unless the person had left an `operations begin` run open. Each write tool
|
|
7
|
+
* therefore takes the model's `intent` and, when no run is open, opens one with
|
|
8
|
+
* it as the headline, makes its writes under it, and closes it, the way the
|
|
9
|
+
* remote connector does (lib/mcp/operations.ts in the app). A run that is
|
|
10
|
+
* already open (CNOTES_AGENT_RUN_ID, or `cnotes operations begin` on this
|
|
11
|
+
* machine) is joined instead, as `--intent` joins one on the command line.
|
|
12
|
+
*
|
|
13
|
+
* Bracket: a tool that REMOVES canvas content opens a canvas run, whose before
|
|
14
|
+
* snapshot is what can restore what it removed. Everything else opens a
|
|
15
|
+
* workspace run; the canvas route takes its before-checkpoint at the run's
|
|
16
|
+
* first content write to each canvas.
|
|
17
|
+
*/
|
|
18
|
+
import { resolveActiveAgentRun, withScopedAgentRun } from "./api-client.js";
|
|
19
|
+
export const MCP_RUN_RATIONALE = "Requested through the cnotes MCP server";
|
|
20
|
+
/**
|
|
21
|
+
* Run `fn` inside an agent run: the open one if there is one, else a run
|
|
22
|
+
* opened for this call with `intent` as its headline. Pass `canvasId` for a
|
|
23
|
+
* tool that removes canvas content.
|
|
24
|
+
*
|
|
25
|
+
* Closing is best-effort: a run that fails to close is reaped as abandoned,
|
|
26
|
+
* which still keeps its writes attributed, and never masks the tool's result.
|
|
27
|
+
*/
|
|
28
|
+
export async function inToolRun(ctx, intent, fn, opts = {}) {
|
|
29
|
+
if (resolveActiveAgentRun(ctx.serverUrl))
|
|
30
|
+
return fn();
|
|
31
|
+
const prompt = intent.trim();
|
|
32
|
+
if (opts.canvasId) {
|
|
33
|
+
// workspaceId lets the route resolve a CANVAS-12 handle on the key path.
|
|
34
|
+
const path = `/api/canvas/${encodeURIComponent(opts.canvasId)}?workspaceId=${encodeURIComponent(ctx.workspaceId)}`;
|
|
35
|
+
const begin = await ctx.api.post(path, {
|
|
36
|
+
action: "agentRunBegin",
|
|
37
|
+
prompt,
|
|
38
|
+
rationale: MCP_RUN_RATIONALE,
|
|
39
|
+
});
|
|
40
|
+
try {
|
|
41
|
+
return await withScopedAgentRun({ agentRunId: begin.agentRunId, beforeSnapshotId: begin.beforeCheckpointId }, fn);
|
|
42
|
+
}
|
|
43
|
+
finally {
|
|
44
|
+
await ctx.api.post(path, { action: "agentRunEnd", agentRunId: begin.agentRunId }).catch(() => undefined);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const begin = await ctx.api.post("/api/operations", {
|
|
48
|
+
action: "begin",
|
|
49
|
+
workspaceId: ctx.workspaceId,
|
|
50
|
+
prompt,
|
|
51
|
+
rationale: MCP_RUN_RATIONALE,
|
|
52
|
+
});
|
|
53
|
+
try {
|
|
54
|
+
return await withScopedAgentRun({ agentRunId: begin.agentRunId }, fn);
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
await ctx.api.post("/api/operations", { action: "end", agentRunId: begin.agentRunId }).catch(() => undefined);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { ApiError } from "./errors.js";
|
|
2
2
|
import { liveWorkspaceId } from "./config.js";
|
|
3
3
|
import { proposalHandle } from "./draft-ref.js";
|
|
4
|
+
/** One line for a prepared answer: who recommends what, and why. */
|
|
5
|
+
export function preparedLine(p) {
|
|
6
|
+
return `Prepared by ${p.byKeyName}: ${p.verdict === "accept" ? "accept it" : "send it back"}. ${p.note}`;
|
|
7
|
+
}
|
|
4
8
|
const PROPOSAL_ID = /^[a-z0-9]{32}$/;
|
|
5
9
|
/** Whether a 404 means "not a proposal in place" rather than a real failure. */
|
|
6
10
|
export function isNotFound(error) {
|
|
@@ -59,6 +63,12 @@ export function inPlaceStatusLines(s) {
|
|
|
59
63
|
else {
|
|
60
64
|
out.push(s.decision.line);
|
|
61
65
|
}
|
|
66
|
+
if (s.prepared) {
|
|
67
|
+
out.push(`${preparedLine(s.prepared)} The person gives the answer.`);
|
|
68
|
+
}
|
|
69
|
+
else if (p.isReviewer && p.isOwner && p.status === "open" && p.message) {
|
|
70
|
+
out.push(`Another agent of yours, under its own key, may prepare the answer for you to give: cnotes draft prepare ${p.displayId} --accept|--send-back --note "<why>".`);
|
|
71
|
+
}
|
|
62
72
|
if (p.intent)
|
|
63
73
|
out.push(`Why: ${p.intent}`);
|
|
64
74
|
if (p.message) {
|
|
@@ -20,6 +20,9 @@ export function renderProposalsForCaller(result) {
|
|
|
20
20
|
const parts = [`${p.displayId} "${p.name}"`, `built by ${p.builtBy}`];
|
|
21
21
|
if (p.sentBack)
|
|
22
22
|
parts.push("sent back");
|
|
23
|
+
if (p.prepared) {
|
|
24
|
+
parts.push(`${p.prepared.byKeyName} prepared: ${p.prepared.verdict === "accept" ? "accept" : "send back"}`);
|
|
25
|
+
}
|
|
23
26
|
if (p.overlaps.length > 0)
|
|
24
27
|
parts.push(overlapText(p.overlaps));
|
|
25
28
|
lines.push(` ${parts.join(" · ")}`);
|
package/dist/mcp-server.js
CHANGED
|
@@ -36,6 +36,7 @@ import { lintNarratedVerbMentions, lintPlainTextDisplayIds, lintPlainTextDisplay
|
|
|
36
36
|
import { DECISION_CARD_RULE } from "./lib/decision-citation.js";
|
|
37
37
|
import { parseReviewRef } from "./lib/review-helpers.js";
|
|
38
38
|
import { runQuery } from "./commands/query.js";
|
|
39
|
+
import { inToolRun } from "./lib/mcp-run.js";
|
|
39
40
|
import { isLocalDbEnabled } from "./lib/auth-store.js";
|
|
40
41
|
import { explainTruncation, listNotes, SERVER_LIST_CAP } from "./lib/notes-list.js";
|
|
41
42
|
import { unsupportedImageTypeMessage } from "./lib/image-types.js";
|
|
@@ -110,6 +111,21 @@ async function withErrorHandling(fn) {
|
|
|
110
111
|
return err(msg);
|
|
111
112
|
}
|
|
112
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Every write tool takes the model's intent: the server refuses a write from a
|
|
116
|
+
* key outside an agent run (FEEDBACK-6KQR), so the tool opens a run for its
|
|
117
|
+
* one call with this sentence as the timeline headline, or joins the run that
|
|
118
|
+
* is already open (lib/mcp-run.ts).
|
|
119
|
+
*/
|
|
120
|
+
const intentArg = z
|
|
121
|
+
.string()
|
|
122
|
+
.trim()
|
|
123
|
+
.min(1)
|
|
124
|
+
.max(200)
|
|
125
|
+
.describe("One short past-tense sentence (under 200 characters) saying what this change does: the timeline headline. Name things by title, not raw ids. Example: 'Added the pricing risks to the Q1 roadmap'. Opens an agent run for this one call, or joins the run already open.");
|
|
126
|
+
const runContext = { api, serverUrl: CNOTES_SERVER, workspaceId };
|
|
127
|
+
/** Run a write tool's REST calls inside an agent run; pass canvasId when it removes canvas content. */
|
|
128
|
+
const inRun = (intent, fn, canvasId) => inToolRun(runContext, intent, fn, canvasId ? { canvasId } : {});
|
|
113
129
|
// ---------------------------------------------------------------------------
|
|
114
130
|
// Server
|
|
115
131
|
// ---------------------------------------------------------------------------
|
|
@@ -281,32 +297,33 @@ server.tool("cnotes_notes_get", "Get one or more notes by display ID (e.g. MEETI
|
|
|
281
297
|
}));
|
|
282
298
|
server.tool("cnotes_notes_delete", "Delete (archive) a note.", {
|
|
283
299
|
id: z.string().describe("Note display ID or Convex ID"),
|
|
284
|
-
|
|
300
|
+
intent: intentArg,
|
|
301
|
+
}, async ({ id, intent }) => withErrorHandling(() => inRun(intent, async () => {
|
|
285
302
|
const noteId = await resolveNoteId(api, workspaceId, id);
|
|
286
303
|
return api.delete(`/api/notes/${noteId}`);
|
|
287
|
-
}));
|
|
304
|
+
})));
|
|
288
305
|
server.tool("cnotes_notes_bulk_archive", "Archive or unarchive multiple notes in one operation. More efficient than calling cnotes_notes_delete multiple times.", {
|
|
289
306
|
ids: z.array(z.string()).describe("Array of note display IDs or Convex IDs"),
|
|
290
307
|
unarchive: z.boolean().optional().default(false).describe("Set true to unarchive instead of archive"),
|
|
291
|
-
|
|
308
|
+
intent: intentArg,
|
|
309
|
+
}, async ({ ids, unarchive, intent }) => withErrorHandling(() => inRun(intent, async () => {
|
|
292
310
|
const noteIds = await Promise.all(ids.map((id) => resolveNoteId(api, workspaceId, id)));
|
|
293
311
|
return api.post("/api/notes/bulk", {
|
|
294
312
|
action: "bulkArchive",
|
|
295
313
|
noteIds,
|
|
296
314
|
isArchived: !unarchive,
|
|
297
315
|
});
|
|
298
|
-
}));
|
|
316
|
+
})));
|
|
299
317
|
server.tool("cnotes_notes_bulk_retype", "Retype multiple notes to a new type in one operation. Each note is atomically retyped (new note created, old archived, cross-linked).", {
|
|
300
318
|
ids: z.array(z.string()).describe("Array of note display IDs or Convex IDs to retype"),
|
|
301
319
|
targetType: z.string().describe("Target type name (must be an existing supertag, e.g. 'Insight')"),
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}));
|
|
320
|
+
intent: intentArg,
|
|
321
|
+
}, async ({ ids, targetType, intent }) => withErrorHandling(() => inRun(intent, () => api.post("/api/notes/bulk", {
|
|
322
|
+
action: "bulkRetype",
|
|
323
|
+
workspaceId,
|
|
324
|
+
noteIds: ids,
|
|
325
|
+
targetType,
|
|
326
|
+
}))));
|
|
310
327
|
server.tool("cnotes_notes_update", "Update note metadata (type, tags, pin/archive status). Does NOT change content — use cnotes_versions_create for that. Title is read-only (derived from # h1 heading in content).", {
|
|
311
328
|
id: z.string().describe("Note display ID or Convex ID"),
|
|
312
329
|
type: z.string().optional().describe("New note type (must be an existing supertag, e.g. 'Insight')"),
|
|
@@ -315,7 +332,8 @@ server.tool("cnotes_notes_update", "Update note metadata (type, tags, pin/archiv
|
|
|
315
332
|
unpin: z.boolean().optional().describe("Unpin the note"),
|
|
316
333
|
archive: z.boolean().optional().describe("Archive the note"),
|
|
317
334
|
unarchive: z.boolean().optional().describe("Unarchive the note"),
|
|
318
|
-
|
|
335
|
+
intent: intentArg,
|
|
336
|
+
}, async ({ id, type, tags, pin, unpin, archive, unarchive, intent }) => withErrorHandling(async () => {
|
|
319
337
|
const body = {};
|
|
320
338
|
if (type !== undefined)
|
|
321
339
|
body.type = type;
|
|
@@ -333,8 +351,10 @@ server.tool("cnotes_notes_update", "Update note metadata (type, tags, pin/archiv
|
|
|
333
351
|
if (Object.keys(body).length === 0) {
|
|
334
352
|
throw new Error("At least one of type, tags, pin, unpin, archive, or unarchive is required");
|
|
335
353
|
}
|
|
336
|
-
|
|
337
|
-
|
|
354
|
+
return inRun(intent, async () => {
|
|
355
|
+
const noteId = await resolveNoteId(api, workspaceId, id);
|
|
356
|
+
return api.patch(`/api/notes/${noteId}`, body);
|
|
357
|
+
});
|
|
338
358
|
}));
|
|
339
359
|
const NoteCreateItem = z.object({
|
|
340
360
|
key: z.string().describe("Unique key for this item, used in @key placeholder cross-references"),
|
|
@@ -352,7 +372,8 @@ server.tool("cnotes_notes_create", "Create one or more interlinked notes in a si
|
|
|
352
372
|
notes: z
|
|
353
373
|
.union([NoteCreateItem, z.array(NoteCreateItem).min(1)])
|
|
354
374
|
.describe("Either a single item object or a non-empty array of items."),
|
|
355
|
-
|
|
375
|
+
intent: intentArg,
|
|
376
|
+
}, async ({ notes, intent }) => withErrorHandling(async () => {
|
|
356
377
|
const items = Array.isArray(notes) ? notes : [notes];
|
|
357
378
|
// The three pre-flight reads are independent of each other and of the
|
|
358
379
|
// create, so they run as one round trip instead of three in a row.
|
|
@@ -372,11 +393,11 @@ server.tool("cnotes_notes_create", "Create one or more interlinked notes in a si
|
|
|
372
393
|
const mentionWarnings = relTypes
|
|
373
394
|
? items.flatMap((n) => lintNarratedVerbMentions(String(n.markdown ?? ""), relTypes).map((w) => ({ item: n.key, ...w })))
|
|
374
395
|
: [];
|
|
375
|
-
const result = await api.post("/api/notes/bulk", {
|
|
396
|
+
const result = await inRun(intent, () => api.post("/api/notes/bulk", {
|
|
376
397
|
action: "bulkCreate",
|
|
377
398
|
workspaceId,
|
|
378
399
|
notes: items,
|
|
379
|
-
});
|
|
400
|
+
}));
|
|
380
401
|
// Attach rubrics ON EACH result so filtering to results[] still carries
|
|
381
402
|
// the standard. Top-level rubrics kept for backward compatibility.
|
|
382
403
|
const typeByKey = new Map(items.map((n) => [n.key, n.type]));
|
|
@@ -394,11 +415,12 @@ server.tool("cnotes_notes_create", "Create one or more interlinked notes in a si
|
|
|
394
415
|
server.tool("cnotes_notes_retype", "Change a single note's type. Atomic operation: creates a new note with the target type, archives the old one, and cross-links both.", {
|
|
395
416
|
noteId: z.string().describe("Display ID of the note to retype (e.g. NOTE-1)"),
|
|
396
417
|
targetType: z.string().describe("Target type name (must be an existing supertag)"),
|
|
397
|
-
|
|
418
|
+
intent: intentArg,
|
|
419
|
+
}, async ({ noteId, targetType, intent }) => withErrorHandling(() => inRun(intent, () => api.post("/api/notes/retype", {
|
|
398
420
|
workspaceId,
|
|
399
421
|
noteId,
|
|
400
422
|
targetType,
|
|
401
|
-
})));
|
|
423
|
+
}))));
|
|
402
424
|
// ---------------------------------------------------------------------------
|
|
403
425
|
// Search tools
|
|
404
426
|
// ---------------------------------------------------------------------------
|
|
@@ -506,26 +528,28 @@ const layoutNotesArg = z
|
|
|
506
528
|
}))
|
|
507
529
|
.min(1)
|
|
508
530
|
.describe("Notes to create and place in this call (cnotes_notes_create item shape); a note leaf places one with noteId '@<key>'");
|
|
509
|
-
server.tool("cnotes_canvas_create", "Create a new canvas. Goal and target audience are required — every canvas must declare the result it exists to produce and who it serves. Write the goal FIRST, for a reader: a result sentence, then a \"Done when\" sentence (the server rejects a goal without one).\n\nLAY IT OUT IN THE SAME CALL: pass `doc` (and `notes`), exactly as cnotes_canvas_place takes them, and the server places the layout onto the new canvas before it answers, under `layout` in the result. One call replaces create then place.
|
|
531
|
+
server.tool("cnotes_canvas_create", "Create a new canvas. Goal and target audience are required — every canvas must declare the result it exists to produce and who it serves. Write the goal FIRST, for a reader: a result sentence, then a \"Done when\" sentence (the server rejects a goal without one).\n\nLAY IT OUT IN THE SAME CALL: pass `doc` (and `notes`), exactly as cnotes_canvas_place takes them, and the server places the layout onto the new canvas before it answers, under `layout` in the result. One call replaces create then place. A layout the server refuses creates nothing: fix the doc and call this again.", {
|
|
510
532
|
name: z.string().describe("Canvas name"),
|
|
511
533
|
goal: z.string().describe(`${CANVAS_GOAL_DESCRIPTION} Required.`),
|
|
512
534
|
targetAudience: z.string().describe("Target audience — who this canvas is meant to serve or inform, and what they do with it. Required."),
|
|
513
535
|
doc: layoutDocArg.optional(),
|
|
514
536
|
notes: layoutNotesArg.optional(),
|
|
515
|
-
|
|
537
|
+
intent: intentArg,
|
|
538
|
+
}, async ({ name, goal, targetAudience, doc, notes, intent }) => withErrorHandling(() => inRun(intent, () => api.post("/api/canvas", {
|
|
516
539
|
workspaceId,
|
|
517
540
|
title: name,
|
|
518
541
|
goal,
|
|
519
542
|
targetAudience,
|
|
520
543
|
...(doc ? { doc } : {}),
|
|
521
544
|
...(notes ? { notes } : {}),
|
|
522
|
-
})));
|
|
545
|
+
}))));
|
|
523
546
|
server.tool("cnotes_canvas_update", "Update canvas metadata: title, goal, and/or target audience. Use this to set or fix the goal a board is scoped to (cnotes_canvas_read shows the current one under the title). The goal follows the same two-sentence shape as on create and is rejected without a \"Done when\" sentence.", {
|
|
524
547
|
canvasId: z.string().describe("Canvas ID"),
|
|
525
548
|
title: z.string().optional().describe("New canvas title"),
|
|
526
549
|
goal: z.string().optional().describe(CANVAS_GOAL_DESCRIPTION),
|
|
527
550
|
targetAudience: z.string().optional().describe("Target audience — who this canvas is meant to serve or inform, and what they do with it"),
|
|
528
|
-
|
|
551
|
+
intent: intentArg,
|
|
552
|
+
}, async ({ canvasId, title, goal, targetAudience, intent }) => {
|
|
529
553
|
if (!title && !goal && !targetAudience) {
|
|
530
554
|
return err("at least one of title, goal, or targetAudience is required");
|
|
531
555
|
}
|
|
@@ -536,17 +560,19 @@ server.tool("cnotes_canvas_update", "Update canvas metadata: title, goal, and/or
|
|
|
536
560
|
body.goal = goal;
|
|
537
561
|
if (targetAudience !== undefined)
|
|
538
562
|
body.targetAudience = targetAudience;
|
|
539
|
-
return withErrorHandling(() => api.patch(`/api/canvas/${encodeURIComponent(canvasId)}`, body, { workspaceId }));
|
|
563
|
+
return withErrorHandling(() => inRun(intent, () => api.patch(`/api/canvas/${encodeURIComponent(canvasId)}`, body, { workspaceId })));
|
|
540
564
|
});
|
|
541
565
|
server.tool("cnotes_canvas_delete", "Delete a canvas.", {
|
|
542
566
|
canvasId: z.string().describe("Canvas ID"),
|
|
543
|
-
|
|
567
|
+
intent: intentArg,
|
|
568
|
+
}, async ({ canvasId, intent }) => withErrorHandling(() => inRun(intent, () => api.delete(`/api/canvas/${canvasId}`))));
|
|
544
569
|
server.tool("cnotes_canvas_archive", "Archive or unarchive a canvas. Archiving is a soft delete (sets archivedAt timestamp). Use unarchive=true to restore.", {
|
|
545
570
|
canvasId: z.string().describe("Canvas ID"),
|
|
546
571
|
unarchive: z.boolean().optional().default(false).describe("Set true to unarchive/restore instead of archive"),
|
|
547
|
-
|
|
572
|
+
intent: intentArg,
|
|
573
|
+
}, async ({ canvasId, unarchive, intent }) => withErrorHandling(() => inRun(intent, () => api.post(`/api/canvas/${canvasId}`, {
|
|
548
574
|
action: unarchive ? "unarchive" : "archive",
|
|
549
|
-
})));
|
|
575
|
+
}))));
|
|
550
576
|
server.tool("cnotes_canvas_set_home", "Set a canvas as the workspace home/default canvas. Clears any previous home canvas.", {
|
|
551
577
|
canvasId: z.string().describe("Canvas ID to set as home"),
|
|
552
578
|
}, async ({ canvasId }) => withErrorHandling(() => api.post(`/api/canvas/${canvasId}`, { action: "setAsHome" })));
|
|
@@ -580,10 +606,11 @@ server.tool("cnotes_canvas_add_node", "[Deprecated: use cnotes_canvas_place] Add
|
|
|
580
606
|
section: SECTION_ARG,
|
|
581
607
|
x: RAW_X,
|
|
582
608
|
y: RAW_Y,
|
|
583
|
-
|
|
609
|
+
intent: intentArg,
|
|
610
|
+
}, async ({ canvasId, noteId, section, x, y, intent }) => withErrorHandling(() => inRun(intent, () => addOne(canvasId, { type: "note", noteId }, { x, y }, section, () => api.post(`/api/canvas/${canvasId}`, {
|
|
584
611
|
action: "bulkAddNodes",
|
|
585
612
|
items: [{ type: "note", noteId, positionX: x, positionY: y }],
|
|
586
|
-
}))));
|
|
613
|
+
})))));
|
|
587
614
|
// The canvas has ONE free-form text element, called "Text", and it is a `richtext`
|
|
588
615
|
// node on the wire. The old `text` node kind (the "Heading") is LEGACY: existing ones
|
|
589
616
|
// still render / move / delete, but nothing creates them any more — a Text element with
|
|
@@ -597,11 +624,12 @@ const textElementSchema = {
|
|
|
597
624
|
section: SECTION_ARG,
|
|
598
625
|
x: RAW_X,
|
|
599
626
|
y: RAW_Y,
|
|
627
|
+
intent: intentArg,
|
|
600
628
|
};
|
|
601
|
-
const addTextElement = ({ canvasId, content, size, color, section, x, y }) => withErrorHandling(() => addOne(canvasId, { type: "richtext", content, ...(size ? { size } : {}), ...(color ? { colorHex: color } : {}) }, { x, y }, section, () => api.post(`/api/canvas/${canvasId}`, {
|
|
629
|
+
const addTextElement = ({ canvasId, content, size, color, section, x, y, intent }) => withErrorHandling(() => inRun(intent, () => addOne(canvasId, { type: "richtext", content, ...(size ? { size } : {}), ...(color ? { colorHex: color } : {}) }, { x, y }, section, () => api.post(`/api/canvas/${canvasId}`, {
|
|
602
630
|
action: "bulkAddNodes",
|
|
603
631
|
items: [{ type: "richtext", content, size, colorHex: color, positionX: x, positionY: y }],
|
|
604
|
-
})));
|
|
632
|
+
}))));
|
|
605
633
|
server.tool("cnotes_canvas_add_text", "[Deprecated: use cnotes_canvas_place] Add a Text element to a canvas — free-form rich text placed directly on the canvas (markdown: headings, emphasis, images), with an optional background tint (none by default). A heading is just content '# Title'. Height follows content: when the element reaches down into what sits below it (notes, lists, section frames and their title chips), the server moves that band down to clear it and the result carries ripple {delta, movedNodeCount}. If the result carries layoutWarning, the element still overlaps the named nodes it could not move (a column beside it, siblings in its own frame); the write succeeded, but reflow those (bulk-move/arrange) before finishing.", textElementSchema, addTextElement);
|
|
606
634
|
server.tool("cnotes_canvas_add_richtext", "[Deprecated: use cnotes_canvas_add_text or cnotes_canvas_place] Alias of cnotes_canvas_add_text — adds the same Text element (richtext) with the same arguments.", textElementSchema, addTextElement);
|
|
607
635
|
server.tool("cnotes_canvas_add_list", "[Deprecated: use cnotes_canvas_place] Add a list/grid node grouping notes on a canvas. The description is the only label; its first paragraph derives the searchable title.", {
|
|
@@ -612,12 +640,13 @@ server.tool("cnotes_canvas_add_list", "[Deprecated: use cnotes_canvas_place] Add
|
|
|
612
640
|
section: SECTION_ARG,
|
|
613
641
|
x: RAW_X,
|
|
614
642
|
y: RAW_Y,
|
|
615
|
-
|
|
643
|
+
intent: intentArg,
|
|
644
|
+
}, async ({ canvasId, description, noteIds, viewMode, section, x, y, intent }) => withErrorHandling(() => {
|
|
616
645
|
const ids = noteIds ? noteIds.split(",").map((id) => id.trim()) : undefined;
|
|
617
|
-
return addOne(canvasId, { type: "list", description, viewMode, ...(ids ? { noteIds: ids } : {}) }, { x, y }, section, () => api.post(`/api/canvas/${canvasId}`, {
|
|
646
|
+
return inRun(intent, () => addOne(canvasId, { type: "list", description, viewMode, ...(ids ? { noteIds: ids } : {}) }, { x, y }, section, () => api.post(`/api/canvas/${canvasId}`, {
|
|
618
647
|
action: "bulkAddNodes",
|
|
619
648
|
items: [{ type: "list", description, viewMode, noteIds: ids, positionX: x, positionY: y }],
|
|
620
|
-
}));
|
|
649
|
+
})));
|
|
621
650
|
}));
|
|
622
651
|
server.tool("cnotes_canvas_add_link", "[Deprecated: use cnotes_canvas_place] Add a link to another canvas.", {
|
|
623
652
|
canvasId: z.string().describe("Canvas ID"),
|
|
@@ -625,10 +654,11 @@ server.tool("cnotes_canvas_add_link", "[Deprecated: use cnotes_canvas_place] Add
|
|
|
625
654
|
section: SECTION_ARG,
|
|
626
655
|
x: RAW_X,
|
|
627
656
|
y: RAW_Y,
|
|
628
|
-
|
|
657
|
+
intent: intentArg,
|
|
658
|
+
}, async ({ canvasId, targetCanvasId, section, x, y, intent }) => withErrorHandling(() => inRun(intent, () => addOne(canvasId, { type: "canvas", linkedCanvasId: targetCanvasId }, { x, y }, section, () => api.post(`/api/canvas/${canvasId}`, {
|
|
629
659
|
action: "bulkAddNodes",
|
|
630
660
|
items: [{ type: "canvas", linkedCanvasId: targetCanvasId, positionX: x, positionY: y }],
|
|
631
|
-
}))));
|
|
661
|
+
})))));
|
|
632
662
|
// --- Primary bulk tool ---
|
|
633
663
|
server.tool("cnotes_canvas_bulk_add", "LOW-LEVEL: add items at raw x/y that YOU choose, with no packing. Prefer cnotes_canvas_place (the solver lays items out with no overlaps; `intoSection` puts them into a section, which arranges itself). Use bulk_add only to reproduce an exact template. Supported item types: note, richtext (the Text element), list, canvas (link to another canvas), section (named region frame), and edge. Prefer one batch over repeated single-item calls. Items are processed in order so edges can reference nodes created earlier in the same batch via sourceItemIndex/targetItemIndex.\n\nELEMENT CHOICE — notes are the knowledge tier (typed, versioned, searchable, the only content agents read back in full); everything else is presentation furniture. Default any claim/fact/decision/finding worth keeping to a typed NOTE. Use richtext (the Text element) for card-sized framing — orientation banners, a markdown heading used as a label ('# Q1 Goals', untinted), emphasis quoting a note, image tiles — never as the sole home of a claim; section for a named REGION of the canvas; list for grouping member notes (description = one-line frame; N distinct things = N notes); canvas for portals; edge for note-to-note relationships (notes only — richtext endpoints fail; mirror the relationship as a mention in the note bodies).\n\nA richtext card's BOX IS DERIVED, not chosen: width is the size preset (small 560, medium 1120, large 1680) and height follows the content — so x/y spacing must clear the card the server measures, not the one you pictured. A results[] entry carrying layoutWarning means that element overlaps the named nodes, whether they were already on the canvas or added earlier in this same batch (columns pitched for `small` while the items are `medium` is the classic one). The write succeeded; reflow what it runs over (bulk-move/arrange), or use cnotes_canvas_place and let the solver pack it, before finishing. Replacing a banner with longer copy is handled: when the batch is that ONE richtext item, the server moves whatever the taller card reaches down into (including section frames and their title chips) down to clear it, and the result carries ripple {delta, movedNodeCount}.", {
|
|
634
664
|
canvasId: z.string().describe("Canvas ID"),
|
|
@@ -686,7 +716,8 @@ server.tool("cnotes_canvas_bulk_add", "LOW-LEVEL: add items at raw x/y that YOU
|
|
|
686
716
|
label: z.string().optional().describe("Edge label"),
|
|
687
717
|
}),
|
|
688
718
|
])).optional().describe("Array of items to add (supports all node types and edges). Item indices for edges are relative to this array, not the merged result."),
|
|
689
|
-
|
|
719
|
+
intent: intentArg,
|
|
720
|
+
}, async ({ canvasId, notes, items, intent }) => withErrorHandling(() => {
|
|
690
721
|
// Normalize: convert legacy notes to items format, merge with items
|
|
691
722
|
const noteItems = (notes ?? []).map((n) => ({
|
|
692
723
|
type: "note",
|
|
@@ -710,12 +741,12 @@ server.tool("cnotes_canvas_bulk_add", "LOW-LEVEL: add items at raw x/y that YOU
|
|
|
710
741
|
return { ...rest, positionX: x, positionY: y };
|
|
711
742
|
}),
|
|
712
743
|
];
|
|
713
|
-
return api.post(`/api/canvas/${canvasId}`, {
|
|
744
|
+
return inRun(intent, () => api.post(`/api/canvas/${canvasId}`, {
|
|
714
745
|
action: "bulkAddNodes",
|
|
715
746
|
items: allItems,
|
|
716
|
-
});
|
|
747
|
+
}));
|
|
717
748
|
}));
|
|
718
|
-
server.tool("cnotes_canvas_place", "Place items on a canvas using a DECLARATIVE LAYOUT (no x/y math). The server measures every item, packs them with no overlaps, and inserts them in a single batch. PREFER THIS over cnotes_canvas_bulk_add whenever you can express the layout as stacks/grids/anchors — which is almost always. The agent should describe STRUCTURE (rows, columns, what's near what), not pixel coordinates.\n\nELEMENT CHOICE: default content to typed NOTES (the only versioned, searchable tier agents can read back); richtext = the Text element, card-sized framing only (a heading is just content '# Title', untinted), section = a named region frame, list = member notes behind a one-line frame, edges connect notes only.\n\nThe call is best-effort, NOT atomic: per-item failures are reported in the response (HTTP 207) but the items that succeeded stay on the canvas. Always inspect `items[].error` and `edges[].error` in the response.\n\nThe `doc` argument is a layout document:\n { root: <LayoutNode>, edges?: [{from, to, label?}], origin?: {x, y} }\n\n<LayoutNode> is one of:\n • { kind: 'stack', axis: 'vertical'|'horizontal', gap?: 'tight'|'medium'|'spacious'|<px>, align?: 'start'|'center'|'end', items: [<LayoutNode>...] }\n • { kind: 'grid', columns: <n>, gap?: ..., items: [<LayoutNode>...] }\n • { kind: 'anchor', to: '<displayId or canvas node id>', direction: 'right'|'left'|'above'|'below', gap?: ..., child: <LayoutNode> }\n • { kind: 'item', type: 'note'|'richtext'|'list'|'canvas'|'section', key?: '<name>', ...item-specific fields }\n\nLeaf item shapes (no x/y!):\n note: { kind:'item', type:'note', noteId:'NOTE-3', key?:'a' }\n richtext: { kind:'item', type:'richtext', content:'# Markdown OK', size?:'small'|'medium'|'large', colorHex?:'<role hex>' } // the Text element: card-sized framing only; a heading is just content '# Title' with no colorHex; colorHex is a ROLE tint (#3B82F6 evidence · #22C55E commitment · #EC4899 insight · #F59E0B warning · #EF4444 danger · #8B5CF6 people — anything else snaps to the nearest), default untinted; plain markdown, NO [NOTE-X](relationship:...) mention syntax (corrupts the card); knowledge worth keeping = a note\n list: { kind:'item', type:'list', description:'One-line frame — first paragraph becomes the title', noteIds?:['NOTE-1','NOTE-2'], viewMode?:'list'|'grid' } // description is REQUIRED and is a frame, never the content: N distinct things = N notes in noteIds\n canvas: { kind:'item', type:'canvas', linkedCanvasId:'<id>' }\n\nEdges reference endpoints by, in priority order: `@<key>` (any item with a `key` placed in the same call), the original noteId/displayId of a note placed in this call (e.g. 'NOTE-7'), or the displayId / convex id of a node already on the canvas.\n\nNEW NOTES IN THE SAME CALL: pass `notes` (the cnotes_notes_create item shape) and place each with a note leaf whose noteId is '@<key>'. Bodies cross-link with [@<key>: Title](relationship:<verb>); edges and anchors say '@<key>'. One call replaces notes_create then place, inside the same
|
|
749
|
+
server.tool("cnotes_canvas_place", "Place items on a canvas using a DECLARATIVE LAYOUT (no x/y math). The server measures every item, packs them with no overlaps, and inserts them in a single batch. PREFER THIS over cnotes_canvas_bulk_add whenever you can express the layout as stacks/grids/anchors — which is almost always. The agent should describe STRUCTURE (rows, columns, what's near what), not pixel coordinates.\n\nELEMENT CHOICE: default content to typed NOTES (the only versioned, searchable tier agents can read back); richtext = the Text element, card-sized framing only (a heading is just content '# Title', untinted), section = a named region frame, list = member notes behind a one-line frame, edges connect notes only.\n\nThe call is best-effort, NOT atomic: per-item failures are reported in the response (HTTP 207) but the items that succeeded stay on the canvas. Always inspect `items[].error` and `edges[].error` in the response.\n\nThe `doc` argument is a layout document:\n { root: <LayoutNode>, edges?: [{from, to, label?}], origin?: {x, y} }\n\n<LayoutNode> is one of:\n • { kind: 'stack', axis: 'vertical'|'horizontal', gap?: 'tight'|'medium'|'spacious'|<px>, align?: 'start'|'center'|'end', items: [<LayoutNode>...] }\n • { kind: 'grid', columns: <n>, gap?: ..., items: [<LayoutNode>...] }\n • { kind: 'anchor', to: '<displayId or canvas node id>', direction: 'right'|'left'|'above'|'below', gap?: ..., child: <LayoutNode> }\n • { kind: 'item', type: 'note'|'richtext'|'list'|'canvas'|'section', key?: '<name>', ...item-specific fields }\n\nLeaf item shapes (no x/y!):\n note: { kind:'item', type:'note', noteId:'NOTE-3', key?:'a' }\n richtext: { kind:'item', type:'richtext', content:'# Markdown OK', size?:'small'|'medium'|'large', colorHex?:'<role hex>' } // the Text element: card-sized framing only; a heading is just content '# Title' with no colorHex; colorHex is a ROLE tint (#3B82F6 evidence · #22C55E commitment · #EC4899 insight · #F59E0B warning · #EF4444 danger · #8B5CF6 people — anything else snaps to the nearest), default untinted; plain markdown, NO [NOTE-X](relationship:...) mention syntax (corrupts the card); knowledge worth keeping = a note\n list: { kind:'item', type:'list', description:'One-line frame — first paragraph becomes the title', noteIds?:['NOTE-1','NOTE-2'], viewMode?:'list'|'grid' } // description is REQUIRED and is a frame, never the content: N distinct things = N notes in noteIds\n canvas: { kind:'item', type:'canvas', linkedCanvasId:'<id>' }\n\nEdges reference endpoints by, in priority order: `@<key>` (any item with a `key` placed in the same call), the original noteId/displayId of a note placed in this call (e.g. 'NOTE-7'), or the displayId / convex id of a node already on the canvas.\n\nNEW NOTES IN THE SAME CALL: pass `notes` (the cnotes_notes_create item shape) and place each with a note leaf whose noteId is '@<key>'. Bodies cross-link with [@<key>: Title](relationship:<verb>); edges and anchors say '@<key>'. One call replaces notes_create then place, inside the same run. The notes are created only if the layout solves, and come back under `notes`.\n\nExample (a SWOT-like quadrant):\n {\n root: {\n kind:'stack', axis:'vertical', gap:'spacious',\n items:[\n { kind:'stack', axis:'horizontal', gap:'spacious', items:[\n { kind:'grid', columns:2, items:[\n { kind:'item', type:'note', noteId:'STR-1' },\n { kind:'item', type:'note', noteId:'STR-2' },\n ]},\n { kind:'grid', columns:2, items:[\n { kind:'item', type:'note', noteId:'WEAK-1' },\n ]},\n ]},\n { kind:'stack', axis:'horizontal', gap:'spacious', items:[ /* opportunities + threats */ ]},\n ],\n },\n }", {
|
|
719
750
|
canvasId: z.string().describe("Canvas ID"),
|
|
720
751
|
doc: layoutDocArg,
|
|
721
752
|
intoSection: z
|
|
@@ -723,12 +754,13 @@ server.tool("cnotes_canvas_place", "Place items on a canvas using a DECLARATIVE
|
|
|
723
754
|
.optional()
|
|
724
755
|
.describe("SECTION-<n> to put the items INTO: appended to its layout (end of its shortest column, or the next grid cell); the section re-arranges and resizes. A section container in the doc creates an ARRANGED section that keeps its cards laid out until a card is moved by hand; add to it later with intoSection, never by aiming origin inside the frame. The doc may not contain sections when intoSection is set."),
|
|
725
756
|
notes: layoutNotesArg.optional(),
|
|
726
|
-
|
|
757
|
+
intent: intentArg,
|
|
758
|
+
}, async ({ canvasId, doc, intoSection, notes, intent }) => withErrorHandling(() => inRun(intent, () => api.post(`/api/canvas/${encodeURIComponent(canvasId)}?workspaceId=${encodeURIComponent(workspaceId)}`, {
|
|
727
759
|
action: "placeLayout",
|
|
728
760
|
doc,
|
|
729
761
|
...(intoSection ? { intoSection } : {}),
|
|
730
762
|
...(notes ? { notes } : {}),
|
|
731
|
-
})));
|
|
763
|
+
}))));
|
|
732
764
|
server.tool("cnotes_canvas_arrange", "Reflow EXISTING canvas nodes with the layout solver (no x/y math). Unlike cnotes_canvas_place (create-only), this MOVES nodes already on the canvas — mixed kinds welcome (note, canvas-link, richtext, list, legacy text). Prefer this over cnotes_canvas_bulk_move whenever you are reorganizing existing content into a grid/stack/section.\n\nLeaves in `doc` must be `{ kind:'item', type:'existing', nodeId:'<id or NOTE-n>', nodeType:'note'|'text'|'richtext'|'list'|'canvas' }`. Wrap them in a section container and pass `targetSectionId` (SECTION-<n>) to pack into that frame and auto-resize it in place — the SECTION-<n> id stays stable (never delete+re-add).\n\nConvenience shape for a section reflow:\n {\n targetSectionId: 'SECTION-90',\n autoResize: true,\n doc: {\n root: {\n kind: 'section', name: '<current name>', key: 'frame',\n child: {\n kind: 'grid', columns: 4, gap: 'medium',\n items: [\n { kind:'item', type:'existing', nodeId:'…', nodeType:'canvas' },\n { kind:'item', type:'existing', nodeId:'NOTE-3', nodeType:'note' }\n ]\n }\n }\n }\n }\n\nWhen targetSectionId is set and origin/placement are omitted, the server pins the layout to the frame's current origin (placement exact).", {
|
|
733
765
|
canvasId: z.string().describe("Canvas ID"),
|
|
734
766
|
doc: z
|
|
@@ -757,13 +789,18 @@ server.tool("cnotes_canvas_arrange", "Reflow EXISTING canvas nodes with the layo
|
|
|
757
789
|
.boolean()
|
|
758
790
|
.optional()
|
|
759
791
|
.describe("Solve and preview without moving anything."),
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
})
|
|
792
|
+
intent: intentArg,
|
|
793
|
+
}, async ({ canvasId, doc, targetSectionId, autoResize, dryRun, intent }) => {
|
|
794
|
+
const arrange = () => api.post(`/api/canvas/${encodeURIComponent(canvasId)}?workspaceId=${encodeURIComponent(workspaceId)}`, {
|
|
795
|
+
action: "arrangeLayout",
|
|
796
|
+
doc,
|
|
797
|
+
...(targetSectionId ? { targetSectionId } : {}),
|
|
798
|
+
...(autoResize !== undefined ? { autoResize } : {}),
|
|
799
|
+
...(dryRun ? { dryRun: true } : {}),
|
|
800
|
+
});
|
|
801
|
+
// A dry run moves nothing, so it opens no run.
|
|
802
|
+
return withErrorHandling(() => (dryRun ? arrange() : inRun(intent, arrange)));
|
|
803
|
+
});
|
|
767
804
|
server.tool("cnotes_canvas_bulk_move", "Move multiple nodes to new positions in one operation. More efficient than calling cnotes_canvas_move_node multiple times. Prefer cnotes_canvas_arrange when reorganizing into a grid/stack/section — that path measures cards and auto-resizes frames.", {
|
|
768
805
|
canvasId: z.string().describe("Canvas ID"),
|
|
769
806
|
moves: z.array(z.object({
|
|
@@ -772,7 +809,8 @@ server.tool("cnotes_canvas_bulk_move", "Move multiple nodes to new positions in
|
|
|
772
809
|
x: z.number().describe("New X position"),
|
|
773
810
|
y: z.number().describe("New Y position"),
|
|
774
811
|
})).describe("Array of node moves"),
|
|
775
|
-
|
|
812
|
+
intent: intentArg,
|
|
813
|
+
}, async ({ canvasId, moves, intent }) => withErrorHandling(() => inRun(intent, () => api.post(`/api/canvas/${canvasId}`, {
|
|
776
814
|
action: "bulkMoveNodes",
|
|
777
815
|
moves: moves.map((m) => ({
|
|
778
816
|
nodeId: m.nodeId,
|
|
@@ -780,7 +818,7 @@ server.tool("cnotes_canvas_bulk_move", "Move multiple nodes to new positions in
|
|
|
780
818
|
positionX: m.x,
|
|
781
819
|
positionY: m.y,
|
|
782
820
|
})),
|
|
783
|
-
})));
|
|
821
|
+
}))));
|
|
784
822
|
server.tool("cnotes_canvas_bulk_remove", "Remove nodes and/or edges from a canvas in one operation — the way to REVISE a canvas rather than only add to it. Works on every element type (note cards, section frames, text, richtext, lists, canvas links).\n\nRemoval is placement-only: the notes behind removed cards keep their content, versions and display IDs and stay on every other canvas. It is not archiving (and archiving a note does NOT take it off a canvas).\n\nnodeIds accepts a raw node id, a SECTION-<n>, or a note display ID (e.g. DECISION-3) resolving to that note's card on this canvas. Edges attached to a removed node come off automatically; list edgeIds only to drop an edge while keeping both nodes. Best-effort: check results[]/edgeResults[] for per-item status.", {
|
|
785
823
|
canvasId: z.string().describe("Canvas ID or display ID (e.g. CANVAS-12)"),
|
|
786
824
|
nodeIds: z
|
|
@@ -791,7 +829,11 @@ server.tool("cnotes_canvas_bulk_remove", "Remove nodes and/or edges from a canva
|
|
|
791
829
|
.array(z.string())
|
|
792
830
|
.optional()
|
|
793
831
|
.describe("Edges to remove on their own (edges on removed nodes cascade automatically)"),
|
|
794
|
-
|
|
832
|
+
intent: intentArg,
|
|
833
|
+
}, async ({ canvasId, nodeIds, edgeIds, intent }) => withErrorHandling(() =>
|
|
834
|
+
// A removal runs in a canvas run: its before snapshot is what can bring
|
|
835
|
+
// back what this removes.
|
|
836
|
+
inRun(intent, () =>
|
|
795
837
|
// ?workspaceId= is not decoration: a "CANVAS-12" handle is only
|
|
796
838
|
// resolvable against a workspace on the Bearer path, so without it this
|
|
797
839
|
// 400s for exactly the callers the description tells to use display ids.
|
|
@@ -799,7 +841,7 @@ api.post(`/api/canvas/${encodeURIComponent(canvasId)}?workspaceId=${encodeURICom
|
|
|
799
841
|
action: "bulkRemoveNodes",
|
|
800
842
|
nodeIds: nodeIds ?? [],
|
|
801
843
|
edgeIds: edgeIds ?? [],
|
|
802
|
-
})));
|
|
844
|
+
}), canvasId)));
|
|
803
845
|
server.tool("cnotes_canvas_add_edge", "Connect two nodes on a canvas with an edge (any node type, including section frames). Defaults to an arrow at the target end and a solid line.", {
|
|
804
846
|
canvasId: z.string().describe("Canvas ID"),
|
|
805
847
|
sourceNodeId: z.string().describe("Source node ID"),
|
|
@@ -813,16 +855,17 @@ server.tool("cnotes_canvas_add_edge", "Connect two nodes on a canvas with an edg
|
|
|
813
855
|
.enum(["solid", "dashed"])
|
|
814
856
|
.optional()
|
|
815
857
|
.describe("Line style (default: solid)"),
|
|
816
|
-
|
|
858
|
+
intent: intentArg,
|
|
859
|
+
}, async ({ canvasId, sourceNodeId, targetNodeId, label, arrow, lineStyle, intent }) => withErrorHandling(() => {
|
|
817
860
|
const markers = arrowToMarkers(arrow);
|
|
818
|
-
return api.post(`/api/canvas/${canvasId}`, {
|
|
861
|
+
return inRun(intent, () => api.post(`/api/canvas/${canvasId}`, {
|
|
819
862
|
action: "addEdge",
|
|
820
863
|
sourceNodeId,
|
|
821
864
|
targetNodeId,
|
|
822
865
|
label,
|
|
823
866
|
...markers,
|
|
824
867
|
lineStyle,
|
|
825
|
-
});
|
|
868
|
+
}));
|
|
826
869
|
}));
|
|
827
870
|
server.tool("cnotes_canvas_update_edge", "Update an edge: change its label, toggle arrowheads, switch line style, or reverse direction. Only the fields you pass are changed.", {
|
|
828
871
|
canvasId: z.string().describe("Canvas ID"),
|
|
@@ -838,7 +881,8 @@ server.tool("cnotes_canvas_update_edge", "Update an edge: change its label, togg
|
|
|
838
881
|
.describe("Arrow direction"),
|
|
839
882
|
lineStyle: z.enum(["solid", "dashed"]).optional().describe("Line style"),
|
|
840
883
|
reverse: z.boolean().optional().describe("Swap source and target nodes"),
|
|
841
|
-
|
|
884
|
+
intent: intentArg,
|
|
885
|
+
}, async ({ canvasId, edgeId, label, arrow, lineStyle, reverse, intent }) => withErrorHandling(() => {
|
|
842
886
|
const body = {
|
|
843
887
|
action: "updateEdge",
|
|
844
888
|
edgeId,
|
|
@@ -851,7 +895,7 @@ server.tool("cnotes_canvas_update_edge", "Update an edge: change its label, togg
|
|
|
851
895
|
body.lineStyle = lineStyle;
|
|
852
896
|
if (reverse !== undefined)
|
|
853
897
|
body.reverse = reverse;
|
|
854
|
-
return api.post(`/api/canvas/${canvasId}`, body);
|
|
898
|
+
return inRun(intent, () => api.post(`/api/canvas/${canvasId}`, body));
|
|
855
899
|
}));
|
|
856
900
|
server.tool("cnotes_canvas_update_section", "Resize, rename, move, recolor or ARRANGE an existing section frame IN PLACE, keeping its SECTION-<n> id. Never delete + re-add a section, which mints a NEW id and breaks every [[SECTION-<n>]] mention pointing at the old one. Only the fields you pass are changed. `arrange: true` (on its own) tidies everything inside the frame, keeping the rows and columns the cards are roughly in, sizes the frame to fit, and leaves the section ARRANGED: it re-lays itself out as cards are added, edited or removed, until a card is moved by hand. Use it whenever a section's contents overlap or spill past the frame. `arrange: false` stops arranging; nothing moves. A hand resize or move of the frame also stops it.", {
|
|
857
901
|
canvasId: z.string().describe("Canvas ID"),
|
|
@@ -871,16 +915,17 @@ server.tool("cnotes_canvas_update_section", "Resize, rename, move, recolor or AR
|
|
|
871
915
|
.boolean()
|
|
872
916
|
.optional()
|
|
873
917
|
.describe("true: lay out the cards inside the frame, size it to fit, keep it arranged. false: stop arranging (nothing moves). Send on its own."),
|
|
874
|
-
|
|
918
|
+
intent: intentArg,
|
|
919
|
+
}, async ({ canvasId, sectionId, name, x, y, width, height, colorHex, arrange, intent }) => withErrorHandling(() => {
|
|
875
920
|
if (arrange !== undefined) {
|
|
876
921
|
if ([name, x, y, width, height, colorHex].some((v) => v !== undefined)) {
|
|
877
922
|
throw new Error("Arrange is its own call: send arrange alone, then any other change in a second call.");
|
|
878
923
|
}
|
|
879
|
-
return api.post(canvasPath(canvasId), {
|
|
924
|
+
return inRun(intent, () => api.post(canvasPath(canvasId), {
|
|
880
925
|
action: "arrangeSection",
|
|
881
926
|
sectionId,
|
|
882
927
|
...(arrange ? {} : { stop: true }),
|
|
883
|
-
});
|
|
928
|
+
}));
|
|
884
929
|
}
|
|
885
930
|
const body = {
|
|
886
931
|
action: "updateSectionNode",
|
|
@@ -899,7 +944,7 @@ server.tool("cnotes_canvas_update_section", "Resize, rename, move, recolor or AR
|
|
|
899
944
|
if (colorHex !== undefined)
|
|
900
945
|
body.colorHex = colorHex;
|
|
901
946
|
// workspaceId lets the server resolve a CANVAS-<n> handle, not just a raw id.
|
|
902
|
-
return api.post(`/api/canvas/${encodeURIComponent(canvasId)}?workspaceId=${encodeURIComponent(workspaceId)}`, body);
|
|
947
|
+
return inRun(intent, () => api.post(`/api/canvas/${encodeURIComponent(canvasId)}?workspaceId=${encodeURIComponent(workspaceId)}`, body));
|
|
903
948
|
}));
|
|
904
949
|
server.tool("cnotes_canvas_move_node", "LOW-LEVEL: move one node to raw x/y, with no collision check. To tidy or reorganize a canvas use cnotes_canvas_arrange; to see every item's box and any overlaps first use cnotes_canvas_status (it also suggests a free spot). The response carries layoutWarning when the node lands on another item.", {
|
|
905
950
|
canvasId: z.string().describe("Canvas ID"),
|
|
@@ -907,7 +952,8 @@ server.tool("cnotes_canvas_move_node", "LOW-LEVEL: move one node to raw x/y, wit
|
|
|
907
952
|
nodeType: z.enum(["note", "text", "list", "canvas", "richtext", "section"]).optional().default("note").describe("Node type. 'text' is a LEGACY kind (old heading nodes) — still movable/deletable, but no longer creatable."),
|
|
908
953
|
x: z.number().describe("New X position"),
|
|
909
954
|
y: z.number().describe("New Y position"),
|
|
910
|
-
|
|
955
|
+
intent: intentArg,
|
|
956
|
+
}, async ({ canvasId, nodeId, nodeType, x, y, intent }) => withErrorHandling(() => inRun(intent, () =>
|
|
911
957
|
// workspaceId lets the server resolve CANVAS-<n> and read the layout
|
|
912
958
|
// for its overlap check.
|
|
913
959
|
api.post(`/api/canvas/${encodeURIComponent(canvasId)}?workspaceId=${encodeURIComponent(workspaceId)}`, {
|
|
@@ -916,21 +962,23 @@ api.post(`/api/canvas/${encodeURIComponent(canvasId)}?workspaceId=${encodeURICom
|
|
|
916
962
|
nodeType,
|
|
917
963
|
positionX: x,
|
|
918
964
|
positionY: y,
|
|
919
|
-
})));
|
|
965
|
+
}))));
|
|
920
966
|
server.tool("cnotes_canvas_remove_node", "Remove a node from a canvas.", {
|
|
921
967
|
canvasId: z.string().describe("Canvas ID"),
|
|
922
968
|
nodeId: z.string().describe("Canvas node ID"),
|
|
923
|
-
|
|
969
|
+
intent: intentArg,
|
|
970
|
+
}, async ({ canvasId, nodeId, intent }) => withErrorHandling(() => inRun(intent, () => api.post(`/api/canvas/${canvasId}`, {
|
|
924
971
|
action: "removeNode",
|
|
925
972
|
nodeId,
|
|
926
|
-
})));
|
|
973
|
+
}), canvasId)));
|
|
927
974
|
server.tool("cnotes_canvas_remove_edge", "Remove an edge from a canvas.", {
|
|
928
975
|
canvasId: z.string().describe("Canvas ID"),
|
|
929
976
|
edgeId: z.string().describe("Canvas edge ID"),
|
|
930
|
-
|
|
977
|
+
intent: intentArg,
|
|
978
|
+
}, async ({ canvasId, edgeId, intent }) => withErrorHandling(() => inRun(intent, () => api.post(`/api/canvas/${canvasId}`, {
|
|
931
979
|
action: "removeEdge",
|
|
932
980
|
edgeId,
|
|
933
|
-
})));
|
|
981
|
+
}), canvasId)));
|
|
934
982
|
server.tool("cnotes_canvas_digest", "Get the AI-generated digest of a canvas: narrative summary, key themes, and a per-note summary list. Run this FIRST when starting on any canvas — full orientation in one call, so you don't read each note individually. The notes list is always populated even when digest status is 'none' or 'stale' (a null per-note summary just means it hasn't generated yet).", {
|
|
935
983
|
canvasId: z.string().describe("Canvas ID"),
|
|
936
984
|
}, async ({ canvasId }) => withErrorHandling(() => api.get(`/api/canvas/${encodeURIComponent(canvasId)}/digest`, { workspaceId })));
|
|
@@ -950,11 +998,12 @@ server.tool("cnotes_canvas_templates", "List available canvas templates.", {}, a
|
|
|
950
998
|
server.tool("cnotes_canvas_from_template", "Create a canvas from a predefined template.", {
|
|
951
999
|
templateId: z.string().describe("Template ID"),
|
|
952
1000
|
title: z.string().optional().describe("Custom canvas title"),
|
|
953
|
-
|
|
1001
|
+
intent: intentArg,
|
|
1002
|
+
}, async ({ templateId, title, intent }) => withErrorHandling(() => inRun(intent, () => api.post("/api/canvas/template", {
|
|
954
1003
|
workspaceId,
|
|
955
1004
|
templateId,
|
|
956
1005
|
title,
|
|
957
|
-
})));
|
|
1006
|
+
}))));
|
|
958
1007
|
// ---------------------------------------------------------------------------
|
|
959
1008
|
// Timeline
|
|
960
1009
|
// ---------------------------------------------------------------------------
|
|
@@ -1325,19 +1374,20 @@ server.tool("cnotes_deps_review", "Record an assessment of a dependency as a SUG
|
|
|
1325
1374
|
.describe("update_needed: dependent no longer matches. no_change: checked, still holds. updated: checked after the dependent was updated. uncertain: cannot tell from the evidence."),
|
|
1326
1375
|
explanation: z.string().min(1).max(2000).describe("What you found: which passage, and why"),
|
|
1327
1376
|
proposedUpdate: z.string().max(2000).optional().describe("Proposed wording or action for someone to apply"),
|
|
1328
|
-
|
|
1377
|
+
intent: intentArg,
|
|
1378
|
+
}, async ({ relationshipId, outcome, explanation, proposedUpdate, intent }) => withErrorHandling(async () => {
|
|
1329
1379
|
const evidence = (await api.get("/api/dependencies", {
|
|
1330
1380
|
workspaceId,
|
|
1331
1381
|
relationshipId,
|
|
1332
1382
|
}));
|
|
1333
|
-
return api.post("/api/dependencies", {
|
|
1383
|
+
return inRun(intent, () => api.post("/api/dependencies", {
|
|
1334
1384
|
workspaceId,
|
|
1335
1385
|
relationshipId,
|
|
1336
1386
|
checkpoint: evidence.checkpoint,
|
|
1337
1387
|
outcome,
|
|
1338
1388
|
explanation,
|
|
1339
1389
|
proposedUpdate,
|
|
1340
|
-
});
|
|
1390
|
+
}));
|
|
1341
1391
|
}));
|
|
1342
1392
|
// ---------------------------------------------------------------------------
|
|
1343
1393
|
// Versions
|
|
@@ -1359,7 +1409,8 @@ server.tool("cnotes_versions_create", "Create a new version of a note. Content i
|
|
|
1359
1409
|
noteId: z.string().describe("Note display ID or Convex ID"),
|
|
1360
1410
|
markdown: z.string().describe("New content as markdown"),
|
|
1361
1411
|
description: z.string().describe("Change description (required)"),
|
|
1362
|
-
|
|
1412
|
+
intent: intentArg,
|
|
1413
|
+
}, async ({ noteId, markdown, description, intent }) => withErrorHandling(async () => {
|
|
1363
1414
|
// Narrated-verb lint (warn-only): same contract as cnotes_notes_create.
|
|
1364
1415
|
let mentionWarnings = [];
|
|
1365
1416
|
if (hasGenericMention(markdown)) {
|
|
@@ -1373,10 +1424,10 @@ server.tool("cnotes_versions_create", "Create a new version of a note. Content i
|
|
|
1373
1424
|
// self-references stay quiet.
|
|
1374
1425
|
const plainTextIdWarnings = await lintPlainTextDisplayIds(markdown, api, workspaceId, [noteId]);
|
|
1375
1426
|
const resolvedId = await resolveNoteId(api, workspaceId, noteId);
|
|
1376
|
-
const data = await api.post(`/api/notes/${resolvedId}/versions`, {
|
|
1427
|
+
const data = await inRun(intent, () => api.post(`/api/notes/${resolvedId}/versions`, {
|
|
1377
1428
|
content: markdown,
|
|
1378
1429
|
description,
|
|
1379
|
-
});
|
|
1430
|
+
}));
|
|
1380
1431
|
return {
|
|
1381
1432
|
...data,
|
|
1382
1433
|
...(mentionWarnings.length > 0 ? { mentionWarnings } : {}),
|
package/dist/program.js
CHANGED
|
@@ -36,6 +36,7 @@ import { registerClaudeHookCommand } from "./commands/claude-hook.js";
|
|
|
36
36
|
import { loadConfig, getServerConfig } from "./lib/auth-store.js";
|
|
37
37
|
import { parseFields } from "./lib/config.js";
|
|
38
38
|
import { setOutputMode } from "./lib/output.js";
|
|
39
|
+
import { setRunningCommand } from "./lib/errors.js";
|
|
39
40
|
import { applyIntentOptions } from "./lib/intent-run.js";
|
|
40
41
|
import { runUnderIntent } from "./lib/intent-runner.js";
|
|
41
42
|
/**
|
|
@@ -80,9 +81,12 @@ export function buildProgram(version) {
|
|
|
80
81
|
.option("-w, --workspace <id>", "Override active workspace ID")
|
|
81
82
|
.option("--server <url>", "Override server URL");
|
|
82
83
|
// -q and --fields are root flags, so apply them once here for every command.
|
|
83
|
-
|
|
84
|
+
// The command's path lets a refusal name the flag that fixes it (errors.ts).
|
|
85
|
+
program.hook("preAction", (_root, actionCommand) => {
|
|
84
86
|
const opts = program.opts();
|
|
85
87
|
setOutputMode({ quiet: Boolean(opts.quiet), fields: parseFields(opts.fields) });
|
|
88
|
+
const group = actionCommand.parent && actionCommand.parent !== program ? actionCommand.parent.name() : undefined;
|
|
89
|
+
setRunningCommand(group ? `${group} ${actionCommand.name()}` : actionCommand.name());
|
|
86
90
|
});
|
|
87
91
|
program.addHelpText("after", `
|
|
88
92
|
Examples:
|
package/package.json
CHANGED
package/skills/cnotes/SKILL.md
CHANGED
|
@@ -17,7 +17,7 @@ Every note and canvas you write is context: what the next reader, a teammate or
|
|
|
17
17
|
|
|
18
18
|
1. **Confirm the workspace.** `cnotes workspace current` names it and lists its relationship types. `-w <id>` targets another one for a single command.
|
|
19
19
|
2. **Read before you write.** Past sessions and teammates left context for this task. `cnotes brief "<task>"` returns the notes, canvases and recent changes most relevant to the task. Search notes and canvases separately (they are different corpora): `cnotes search semantic "<topic>"` and `cnotes canvas search "<topic>"`. `cnotes notes get <id> --expand` loads a note with the notes it rests on. Before changing a canvas, `cnotes canvas read <canvasId>`. A Decision or Guide you find may already settle what you were about to propose.
|
|
20
|
-
3. **Open a run.** `cnotes operations begin --prompt "<the change as a past-tense headline, e.g. Added a risks list to the Q1 roadmap>" --json`, as its own command; check its exit code before writing (a pipe hides it).
|
|
20
|
+
3. **Open a run.** `cnotes operations begin --prompt "<the change as a past-tense headline, e.g. Added a risks list to the Q1 roadmap>" --json`, as its own command; check its exit code before writing (a pipe hides it). Every write refuses to run without one. The response carries `typeRubrics`, the same brief, and the proposals waiting on you with any that reword the same note as another (read those first, [references/drafts.md](references/drafts.md) step 8); `-q` prints only the run id, with the proposals on stderr. One canvas per run: end it and begin another before writing to a second canvas.
|
|
21
21
|
4. **Write to the type's rubric.** Pick the type, run `cnotes types show <Type>`, and author to its rubric. Audience-facing prose (note bodies, banners, pre-reads) goes through [references/humanizer.md](references/humanizer.md) first; transcripts, quotes and other raw capture are stored verbatim.
|
|
22
22
|
5. **Create notes in one batch.** `cnotes notes create --notes '[{"key":"A","type":"Insight","markdownFile":"./a.md"}, ...]'`. Each body starts with a `# h1` (the title). Cross-link inside the batch with `[@A: Title](relationship:<verb>)`. Detail: [references/notes.md](references/notes.md).
|
|
23
23
|
6. **Grade what you wrote.** `cnotes quality <displayIds...> --fail-below 4`, then revise weak notes with `cnotes versions create <id> --description "<what changed>" --markdown-file <path>`.
|
|
@@ -26,7 +26,7 @@ Every note and canvas you write is context: what the next reader, a teammate or
|
|
|
26
26
|
9. **Close the run.** `cnotes operations end`.
|
|
27
27
|
10. **Link the result.** End your reply with the canvas link (see [Surfacing the canvas link](#surfacing-the-canvas-link)).
|
|
28
28
|
|
|
29
|
-
Reads
|
|
29
|
+
Reads need no run. A task that is ONE write (a `notes update` too) needs no `begin`/`end`: pass `--intent "<headline>"` on that command (see the fast path).
|
|
30
30
|
|
|
31
31
|
## Fast path: a routine canvas change
|
|
32
32
|
|
|
@@ -243,6 +243,29 @@ As the builder, a status line reading "Merged runs 2 and 4 of 4. Runs 1 and 3
|
|
|
243
243
|
are still proposed." means the rest is yours again: fix it and ask, or
|
|
244
244
|
dismiss it.
|
|
245
245
|
|
|
246
|
+
### Preparing the answer for your own person
|
|
247
|
+
|
|
248
|
+
When another agent of the same person built a proposal in place and asked
|
|
249
|
+
that person, you cannot accept it: no key of theirs lands their own agents'
|
|
250
|
+
work. You can prepare the answer they give. `operations begin` lists it under
|
|
251
|
+
waiting on you, with "built by you via Codex (Slack)". Read it with `cnotes
|
|
252
|
+
draft status PROPOSAL-n` and its rewordings, check it against what it rewords,
|
|
253
|
+
then:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
cnotes draft prepare PROPOSAL-n --accept --note "<why it should land>"
|
|
257
|
+
cnotes draft prepare PROPOSAL-n --send-back --note "<what should change>"
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
The person reads "<your key's name> recommends landing it" with your line on
|
|
261
|
+
the review, in the browser or on the phone, and gives the answer with one
|
|
262
|
+
tap. Then stop. You need your own key (`cnotes auth keys create --name
|
|
263
|
+
"<agent>"`): the key that opened, wrote into or asked for the proposal is
|
|
264
|
+
refused, and two agents on one login key count as one. An accept is refused
|
|
265
|
+
while a check blocks; prepare a send-back that says what to fix. A later write
|
|
266
|
+
into the proposal clears what you prepared, and `operations begin` says
|
|
267
|
+
"<agent> prepared: accept" so a second reviewer does not start again.
|
|
268
|
+
|
|
246
269
|
## What to rely on
|
|
247
270
|
- **One line says who it waits on.** `draft status`, `draft checkout` and
|
|
248
271
|
`workspace current` print it: nobody asked yet, the changes a person asked
|
|
@@ -14,7 +14,7 @@ Read this for the detail behind `operations begin`/`end`: when to wrap, two agen
|
|
|
14
14
|
|
|
15
15
|
When an AI agent is doing a **batch of work** — creating notes, modifying 2+ entities, or building a canvas with content — wrap it in a workspace-level **operation**. The batch then shows up in the timeline as a single legible row with intent + evidence + count, and the user can later revert the whole run as one unit. Unwrapped, each write is an isolated timeline row with no shared intent or batch revert — and on canvas and other multi-write paths nothing forces the wrap, so you must open the run yourself.
|
|
16
16
|
|
|
17
|
-
**This is enforced for
|
|
17
|
+
**This is enforced for every write.** A note create, version, metadata change, archive, retype, move, link removal, dependency review or canvas change from a key is rejected with `operation_required` (HTTP 422, exit 3) unless a run is active or the command carries `--intent`. Comments, review requests, uploads, types and focus plans are not. Begin one first; the active run then auto-attaches to every subsequent write.
|
|
18
18
|
|
|
19
19
|
## When to wrap
|
|
20
20
|
|
|
@@ -22,11 +22,11 @@ When an AI agent is doing a **batch of work** — creating notes, modifying 2+ e
|
|
|
22
22
|
|---|---|
|
|
23
23
|
| Reading: `digest`, `get`, `list`, `activity`, `timeline`, `search`, `rel list` | **No** — read-only |
|
|
24
24
|
| **Any `cnotes notes create`** (even a single note) | **Yes — enforced.** Creates run through the batch endpoint, which now rejects writes with no active run |
|
|
25
|
-
| A single `notes update` / tag / pin / archive change | **
|
|
25
|
+
| A single `notes update` / tag / pin / archive change | **Yes — enforced.** Pass `--intent "<headline>"` on it, or wrap it with your other writes |
|
|
26
26
|
| Two or more writes that belong to one intent (multi-note batch, canvas build-out, multi-step refactor) | **Yes** |
|
|
27
27
|
| Canvas mutations done as part of an agent task | **Yes** — even one canvas command, if it's part of a larger batch |
|
|
28
28
|
|
|
29
|
-
**One write is its own run with `--intent`.** When the whole task is a single write command (`notes create`, `versions create`, `canvas create`, `place`, `arrange`, an `add-*`, `update-*`, `move-*` or `remove-*` canvas command), pass `--intent "<headline>"` on it instead of bracketing it: the CLI opens a run with that headline, runs the command under it, and closes the run even when the command fails. Removals (`bulk-remove`, `remove-node`, `remove-edge`) get a canvas run with a before snapshot, the same as `canvas agent-run wrap`, so they can be undone. When a run is already open, the write joins it and `--intent` is not used as a headline. `cnotes <command> --help` lists the flag on every command that takes it.
|
|
29
|
+
**One write is its own run with `--intent`.** When the whole task is a single write command (`notes create`, `update`, `delete`, `retype` or `move`, `versions create`, `rel rm`, `deps review`, `canvas create`, `update`, `delete`, `archive`, `place`, `arrange`, an `add-*`, `update-*`, `move-*` or `remove-*` canvas command), pass `--intent "<headline>"` on it instead of bracketing it: the CLI opens a run with that headline, runs the command under it, and closes the run even when the command fails. Removals (`bulk-remove`, `remove-node`, `remove-edge`) get a canvas run with a before snapshot, the same as `canvas agent-run wrap`, so they can be undone. When a run is already open, the write joins it and `--intent` is not used as a headline. `cnotes <command> --help` lists the flag on every command that takes it.
|
|
30
30
|
|
|
31
31
|
## The pattern
|
|
32
32
|
|