@creator-notes/cnotes 0.120.1 → 0.121.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/auth.js +54 -5
- package/dist/commands/canvas.js +2 -2
- package/dist/commands/timeline.js +3 -2
- package/dist/commands/versions.js +3 -2
- package/dist/lib/config.js +10 -1
- package/dist/lib/env-proposal.js +36 -0
- package/dist/lib/output.js +11 -0
- package/dist/program.js +6 -1
- package/package.json +1 -1
- package/skills/cnotes/references/drafts.md +4 -1
- package/skills/cnotes/references/operations.md +2 -0
package/dist/commands/auth.js
CHANGED
|
@@ -3,8 +3,9 @@ import { randomBytes } from "node:crypto";
|
|
|
3
3
|
import { loadConfig, saveConfig, setServerConfig, removeServerConfig, getServerConfig, } from "../lib/auth-store.js";
|
|
4
4
|
import { validateServerUrl, unofficialServerWarning, allowedCallbackOrigins, } from "../lib/server-url.js";
|
|
5
5
|
import { readStdin } from "../lib/stdin.js";
|
|
6
|
-
import { EXIT_CODES, handleError } from "../lib/errors.js";
|
|
6
|
+
import { ApiError, EXIT_CODES, handleError } from "../lib/errors.js";
|
|
7
7
|
import { outputJson } from "../lib/output.js";
|
|
8
|
+
import { ApiClient } from "../lib/api-client.js";
|
|
8
9
|
import { registerAuthKeysCommands } from "./auth-keys.js";
|
|
9
10
|
export function registerAuthCommands(program) {
|
|
10
11
|
const auth = program
|
|
@@ -109,6 +110,11 @@ Exit codes:
|
|
|
109
110
|
2 signed out
|
|
110
111
|
|
|
111
112
|
\`cnotes whoami\` and \`cnotes auth status\` are the same command.
|
|
113
|
+
|
|
114
|
+
When signed in, it asks the server which key this is. On a child key
|
|
115
|
+
(\`cnotes auth keys create\`) it prints the agent the key was minted for, the
|
|
116
|
+
name History shows on that agent's changes, and the account it acts for.
|
|
117
|
+
If the server cannot be asked, it prints the saved login and says why.
|
|
112
118
|
`;
|
|
113
119
|
/**
|
|
114
120
|
* Print who is signed in. Exit 2 when there is no token, so a script can
|
|
@@ -116,17 +122,46 @@ Exit codes:
|
|
|
116
122
|
* `cnotes auth status` and `cnotes whoami` both call this.
|
|
117
123
|
*/
|
|
118
124
|
function registerAuthStatus(command, program) {
|
|
119
|
-
command.addHelpText("after", AUTH_STATUS_HELP).action(() => {
|
|
125
|
+
command.addHelpText("after", AUTH_STATUS_HELP).action(async () => {
|
|
120
126
|
const json = program.opts().json ?? false;
|
|
121
127
|
try {
|
|
122
|
-
showAuthStatus(json);
|
|
128
|
+
await showAuthStatus(json);
|
|
123
129
|
}
|
|
124
130
|
catch (error) {
|
|
125
131
|
handleError(error, json);
|
|
126
132
|
}
|
|
127
133
|
});
|
|
128
134
|
}
|
|
129
|
-
|
|
135
|
+
/** Ask the server which key this is; a short wait, so `whoami` stays quick offline. */
|
|
136
|
+
async function fetchKeyIdentity(serverUrl, token, workspaceId) {
|
|
137
|
+
let timer;
|
|
138
|
+
const timeout = new Promise((_, reject) => {
|
|
139
|
+
timer = setTimeout(() => reject(new Error("no answer within 2 s")), 2_000);
|
|
140
|
+
timer.unref();
|
|
141
|
+
});
|
|
142
|
+
try {
|
|
143
|
+
const api = new ApiClient(serverUrl, token, workspaceId ?? undefined);
|
|
144
|
+
const identity = await Promise.race([api.get("/api/auth/whoami"), timeout]);
|
|
145
|
+
return { identity };
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
if (error instanceof ApiError)
|
|
149
|
+
return { error: `HTTP ${error.status}: ${error.message}` };
|
|
150
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
clearTimeout(timer);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function describeKey(key) {
|
|
157
|
+
const pin = key.workspaceId ? `, pinned to workspace ${key.workspaceId}` : "";
|
|
158
|
+
if (key.kind === "child")
|
|
159
|
+
return `child key${pin}`;
|
|
160
|
+
if (key.kind === "oauth")
|
|
161
|
+
return `connector token "${key.name ?? ""}"${pin}`;
|
|
162
|
+
return `CLI key "${key.name ?? ""}"${pin}`;
|
|
163
|
+
}
|
|
164
|
+
async function showAuthStatus(json) {
|
|
130
165
|
const config = loadConfig();
|
|
131
166
|
const serverUrl = process.env.CNOTES_SERVER || config.currentServer;
|
|
132
167
|
const sc = getServerConfig(config, serverUrl);
|
|
@@ -149,18 +184,32 @@ function showAuthStatus(json) {
|
|
|
149
184
|
return;
|
|
150
185
|
}
|
|
151
186
|
const workspaceId = process.env.CNOTES_WORKSPACE?.trim() || sc?.workspaceId || null;
|
|
152
|
-
const
|
|
187
|
+
const checked = await fetchKeyIdentity(serverUrl, token, workspaceId);
|
|
188
|
+
const identity = "identity" in checked ? checked.identity : null;
|
|
189
|
+
// The server's answer wins: under CNOTES_TOKEN, or a child key, the saved
|
|
190
|
+
// login's email belongs to some other key.
|
|
191
|
+
const email = identity?.email || sc?.email || (envToken ? "(from CNOTES_TOKEN)" : "unknown");
|
|
153
192
|
if (json) {
|
|
154
193
|
outputJson({
|
|
155
194
|
authenticated: true,
|
|
156
195
|
server: serverUrl,
|
|
157
196
|
email,
|
|
158
197
|
workspaceId,
|
|
198
|
+
agentName: identity?.agentName ?? null,
|
|
199
|
+
key: identity?.key ?? null,
|
|
200
|
+
...("error" in checked ? { keyCheckError: checked.error } : {}),
|
|
159
201
|
});
|
|
160
202
|
return;
|
|
161
203
|
}
|
|
162
204
|
console.log(`Server: ${serverUrl}`);
|
|
163
205
|
console.log(`Email: ${email}`);
|
|
206
|
+
if (identity?.agentName) {
|
|
207
|
+
console.log(`Agent: ${identity.agentName} (History shows this name on its changes)`);
|
|
208
|
+
}
|
|
209
|
+
if (identity?.key)
|
|
210
|
+
console.log(`Key: ${describeKey(identity.key)}`);
|
|
211
|
+
else if ("error" in checked)
|
|
212
|
+
console.log(`Key: not checked (${checked.error})`);
|
|
164
213
|
console.log(`Workspace: ${workspaceId || "(not selected)"}`);
|
|
165
214
|
}
|
|
166
215
|
/** Read a small JSON body from an HTTP POST (login callback). */
|
package/dist/commands/canvas.js
CHANGED
|
@@ -7,7 +7,7 @@ import { resolveBaseConfig, resolveConfig } from "../lib/config.js";
|
|
|
7
7
|
import { ApiError, CliError, EXIT_CODES, handleError, ValidationError } from "../lib/errors.js";
|
|
8
8
|
import { parseJsonOption, readFileSafe } from "../lib/fs-utils.js";
|
|
9
9
|
import { loadConfig, setActiveAgentRunId, registerAgentRun, unregisterAgentRun, isOwnedAgentRun, } from "../lib/auth-store.js";
|
|
10
|
-
import { outputJson, outputTable, outputQuiet, truncate, timeAgo } from "../lib/output.js";
|
|
10
|
+
import { authorLabel, outputJson, outputTable, outputQuiet, truncate, timeAgo } from "../lib/output.js";
|
|
11
11
|
import { readHeadlineWarnings, reportHeadlineWarnings } from "../lib/headline-warnings.js";
|
|
12
12
|
import { formatDoneParts } from "../lib/done-parts.js";
|
|
13
13
|
import { parseSharedCanvasLink, sameServerOrigin } from "../lib/share-link.js";
|
|
@@ -901,7 +901,7 @@ Examples:
|
|
|
901
901
|
"";
|
|
902
902
|
return [
|
|
903
903
|
timeAgo(op.startedAt),
|
|
904
|
-
truncate(op.actorName
|
|
904
|
+
truncate(authorLabel({ name: op.actorName, agentName: op.agentName }), 32),
|
|
905
905
|
truncate(op.operationType, 22),
|
|
906
906
|
op.status,
|
|
907
907
|
String(op.eventCount ?? 0),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ApiClient } from "../lib/api-client.js";
|
|
2
2
|
import { resolveConfig } from "../lib/config.js";
|
|
3
3
|
import { handleError, ValidationError } from "../lib/errors.js";
|
|
4
|
-
import { outputJson, outputTable, timeAgo, truncate } from "../lib/output.js";
|
|
4
|
+
import { authorLabel, outputJson, outputTable, timeAgo, truncate } from "../lib/output.js";
|
|
5
5
|
const DURATION_UNITS = {
|
|
6
6
|
m: 60_000,
|
|
7
7
|
h: 3_600_000,
|
|
@@ -108,9 +108,10 @@ Examples:
|
|
|
108
108
|
item.note.displayId,
|
|
109
109
|
`v${item.versionNumber}`,
|
|
110
110
|
truncate(item.changeDescription || "(no description)", 50),
|
|
111
|
+
truncate(authorLabel(item.author), 32),
|
|
111
112
|
timeAgo(item.createdAtRaw),
|
|
112
113
|
]);
|
|
113
|
-
outputTable(["NOTE", "V#", "CHANGE", "WHEN"], rows);
|
|
114
|
+
outputTable(["NOTE", "V#", "CHANGE", "BY", "WHEN"], rows);
|
|
114
115
|
const typeSummary = Object.entries(data.summary.byType)
|
|
115
116
|
.map(([type, count]) => `${type}: ${count}`)
|
|
116
117
|
.join(", ");
|
|
@@ -3,7 +3,7 @@ import { ApiClient } from "../lib/api-client.js";
|
|
|
3
3
|
import { resolveConfig } from "../lib/config.js";
|
|
4
4
|
import { handleError, ValidationError, EXIT_CODES } from "../lib/errors.js";
|
|
5
5
|
import { readFileSafe } from "../lib/fs-utils.js";
|
|
6
|
-
import { outputJson, outputTable, timeAgo } from "../lib/output.js";
|
|
6
|
+
import { authorLabel, outputJson, outputTable, timeAgo } from "../lib/output.js";
|
|
7
7
|
import { readHeadlineWarnings, reportHeadlineWarnings } from "../lib/headline-warnings.js";
|
|
8
8
|
import { pendingProposalLines } from "../lib/draft-view.js";
|
|
9
9
|
import { resolveNoteId } from "../lib/resolve-note.js";
|
|
@@ -44,9 +44,10 @@ Examples:
|
|
|
44
44
|
String(v.versionNumber || ""),
|
|
45
45
|
v.isLatest ? "*" : "",
|
|
46
46
|
String(v.description || v.changeDescription || ""),
|
|
47
|
+
authorLabel(v.author),
|
|
47
48
|
v.createdAt ? timeAgo(v.createdAt) : "",
|
|
48
49
|
]);
|
|
49
|
-
outputTable(["VERSION", "LATEST", "DESCRIPTION", "CREATED"], rows);
|
|
50
|
+
outputTable(["VERSION", "LATEST", "DESCRIPTION", "BY", "CREATED"], rows);
|
|
50
51
|
}
|
|
51
52
|
catch (error) {
|
|
52
53
|
handleError(error, cfg.json);
|
package/dist/lib/config.js
CHANGED
|
@@ -4,6 +4,14 @@ import { AuthError, ValidationError } from "./errors.js";
|
|
|
4
4
|
export function inPlaceProposalId(proposal) {
|
|
5
5
|
return proposal?.kind === "in_place" ? proposal.draftId : undefined;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Ids CNOTES_PROPOSAL named that the server confirmed are proposals in place,
|
|
9
|
+
* though this machine never saved them (lib/env-proposal.ts). Per process.
|
|
10
|
+
*/
|
|
11
|
+
const confirmedInPlace = new Set();
|
|
12
|
+
export function rememberInPlace(id) {
|
|
13
|
+
confirmedInPlace.add(id);
|
|
14
|
+
}
|
|
7
15
|
/** CNOTES_PROPOSAL values that mean "work live in this terminal". */
|
|
8
16
|
export const LIVE_VALUES = new Set(["none", "live", "off"]);
|
|
9
17
|
/**
|
|
@@ -22,13 +30,14 @@ export function resolveProposal(workspaceId, server, env = process.env.CNOTES_PR
|
|
|
22
30
|
// Aimed straight at the draft already: nothing to swap.
|
|
23
31
|
if (pinned === workspaceId)
|
|
24
32
|
return undefined;
|
|
33
|
+
const kind = savedUnder?.[1].kind ?? (confirmedInPlace.has(pinned) ? "in_place" : undefined);
|
|
25
34
|
return {
|
|
26
35
|
draftId: pinned,
|
|
27
36
|
handle: savedUnder?.[1].handle,
|
|
28
37
|
name: savedUnder?.[1].name,
|
|
29
38
|
sharedWorkspaceId: savedUnder?.[0] ?? workspaceId,
|
|
30
39
|
source: "env",
|
|
31
|
-
...(
|
|
40
|
+
...(kind ? { kind } : {}),
|
|
32
41
|
};
|
|
33
42
|
}
|
|
34
43
|
const saved = server?.proposals?.[workspaceId];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CNOTES_PROPOSAL may name a proposal this machine never saved: a second agent
|
|
3
|
+
* handed only the id works in it from its own terminal. A saved proposal
|
|
4
|
+
* carries its kind; an unsaved id does not, and a proposal in place read as a
|
|
5
|
+
* draft workspace sent its id where a workspace id belongs, which the server
|
|
6
|
+
* answered with HTTP 500. Before the command runs, ask the server once whether
|
|
7
|
+
* the id is a proposal in place. Anything else keeps the old reading: a draft
|
|
8
|
+
* workspace.
|
|
9
|
+
*/
|
|
10
|
+
import { ApiClient } from "./api-client.js";
|
|
11
|
+
import { getServerConfig, loadConfig } from "./auth-store.js";
|
|
12
|
+
import { LIVE_VALUES, rememberInPlace } from "./config.js";
|
|
13
|
+
const PROPOSAL_ID = /^[a-z0-9]{32}$/;
|
|
14
|
+
export async function probeEnvProposal(globalOpts) {
|
|
15
|
+
const pinned = process.env.CNOTES_PROPOSAL?.trim();
|
|
16
|
+
if (!pinned || LIVE_VALUES.has(pinned.toLowerCase()) || !PROPOSAL_ID.test(pinned))
|
|
17
|
+
return;
|
|
18
|
+
const config = loadConfig();
|
|
19
|
+
const serverUrl = globalOpts.server || process.env.CNOTES_SERVER || config.currentServer;
|
|
20
|
+
if (!serverUrl)
|
|
21
|
+
return;
|
|
22
|
+
const server = getServerConfig(config, serverUrl);
|
|
23
|
+
// A saved proposal already says what it is.
|
|
24
|
+
if (Object.values(server?.proposals ?? {}).some((p) => p.draftId === pinned))
|
|
25
|
+
return;
|
|
26
|
+
const token = process.env.CNOTES_TOKEN || server?.token;
|
|
27
|
+
if (!token)
|
|
28
|
+
return;
|
|
29
|
+
try {
|
|
30
|
+
await new ApiClient(serverUrl, token).get(`/api/proposals/${pinned}`);
|
|
31
|
+
rememberInPlace(pinned);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
// Not a proposal in place, or the server could not say: a draft workspace, as before.
|
|
35
|
+
}
|
|
36
|
+
}
|
package/dist/lib/output.js
CHANGED
|
@@ -148,6 +148,17 @@ export function outputJson(data, fields) {
|
|
|
148
148
|
export function outputQuiet(value) {
|
|
149
149
|
console.log(value);
|
|
150
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* A change's author the way History words it: "Deniss via Anti-entropy Bot"
|
|
153
|
+
* when a bot's child key made it, else the person (PM-139).
|
|
154
|
+
*/
|
|
155
|
+
export function authorLabel(author) {
|
|
156
|
+
const person = author?.name?.trim() || "";
|
|
157
|
+
const agent = author?.agentName?.trim() || "";
|
|
158
|
+
if (agent)
|
|
159
|
+
return `${person || "Someone"} via ${agent}`;
|
|
160
|
+
return person || "—";
|
|
161
|
+
}
|
|
151
162
|
/**
|
|
152
163
|
* Print a simple table with aligned columns.
|
|
153
164
|
*/
|
package/dist/program.js
CHANGED
|
@@ -39,6 +39,7 @@ import { setOutputMode } from "./lib/output.js";
|
|
|
39
39
|
import { setRunningCommand } from "./lib/errors.js";
|
|
40
40
|
import { applyIntentOptions } from "./lib/intent-run.js";
|
|
41
41
|
import { runUnderIntent } from "./lib/intent-runner.js";
|
|
42
|
+
import { probeEnvProposal } from "./lib/env-proposal.js";
|
|
42
43
|
/**
|
|
43
44
|
* Appended to Commander's own error text. Agents read stderr, and both errors
|
|
44
45
|
* below used to cost them a wrong conclusion rather than a retry.
|
|
@@ -88,6 +89,9 @@ export function buildProgram(version) {
|
|
|
88
89
|
const group = actionCommand.parent && actionCommand.parent !== program ? actionCommand.parent.name() : undefined;
|
|
89
90
|
setRunningCommand(group ? `${group} ${actionCommand.name()}` : actionCommand.name());
|
|
90
91
|
});
|
|
92
|
+
// CNOTES_PROPOSAL naming a proposal this machine never saved: learn whether
|
|
93
|
+
// it is one in place before any request goes out (lib/env-proposal.ts).
|
|
94
|
+
program.hook("preAction", () => probeEnvProposal(program.opts()));
|
|
91
95
|
program.addHelpText("after", `
|
|
92
96
|
Examples:
|
|
93
97
|
$ cnotes notes list --type Insight --json
|
|
@@ -108,7 +112,8 @@ Exit codes:
|
|
|
108
112
|
|
|
109
113
|
Env vars:
|
|
110
114
|
CNOTES_SERVER, CNOTES_TOKEN, CNOTES_WORKSPACE, CNOTES_JSON=1
|
|
111
|
-
CNOTES_PROPOSAL=<draft id> works in that draft from this terminal
|
|
115
|
+
CNOTES_PROPOSAL=<draft id> works in that draft from this terminal, saved
|
|
116
|
+
on this machine or not;
|
|
112
117
|
CNOTES_PROPOSAL=none works live while a draft is checked out (-w naming
|
|
113
118
|
the same workspace still goes into the draft)
|
|
114
119
|
`);
|
package/package.json
CHANGED
|
@@ -280,7 +280,10 @@ into the proposal clears what you prepared, and `operations begin` says
|
|
|
280
280
|
- **The draft you work in is saved for this login on this machine.** Every
|
|
281
281
|
terminal using it works in the draft too. When two agents share a login,
|
|
282
282
|
pin each terminal: `CNOTES_PROPOSAL=<draft id>` works in that draft and
|
|
283
|
-
`CNOTES_PROPOSAL=none` works live, whatever is saved.
|
|
283
|
+
`CNOTES_PROPOSAL=none` works live, whatever is saved. The id may be a
|
|
284
|
+
proposal this machine never saved (a second agent handed only the id); the
|
|
285
|
+
CLI asks the server whether it is a proposal in place before the command
|
|
286
|
+
runs. A command aimed at
|
|
284
287
|
another workspace (`-w`, `CNOTES_WORKSPACE`) works there, live; `-w`
|
|
285
288
|
naming the draft's own shared workspace still goes into the draft. Type
|
|
286
289
|
setup is live work: `types update` refuses inside a draft, because a merge
|
|
@@ -102,6 +102,8 @@ CNOTES_TOKEN=$KEY CNOTES_WORKSPACE=<workspaceId> cnotes operations begin --promp
|
|
|
102
102
|
|
|
103
103
|
A child key cannot mint keys, list or revoke them, or reach another workspace. `cnotes auth keys revoke <yourKeyId>` revokes every child it minted, and `cnotes auth keys list` marks which keys are children.
|
|
104
104
|
|
|
105
|
+
To trace a change back to the agent that made it, read the BY column (in JSON, `author.agentName`) of `cnotes timeline`, `cnotes versions list <note>` and `cnotes canvas activity <canvas>`: a change made under a child key reads "Deniss via Seat 3 · Notion PM". Under a child key, `cnotes whoami` prints the agent's name and the account it acts for.
|
|
106
|
+
|
|
105
107
|
## Writing a good `--prompt`
|
|
106
108
|
|
|
107
109
|
The prompt is the timeline row's headline, and the server lints it like every headline: start with a past-tense verb and name the specific object, in the user's terms for that object. An imperative ("Re-cite the notes ...") is accepted but warns `not_verb_first`.
|