@creator-notes/cnotes 0.120.2 → 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/output.js +11 -0
- package/package.json +1 -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/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/package.json
CHANGED
|
@@ -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`.
|