@creator-notes/cnotes 0.111.0 → 0.112.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,11 +1,93 @@
|
|
|
1
1
|
import { ApiClient } from "../lib/api-client.js";
|
|
2
|
+
import { BRAND } from "../lib/brand.js";
|
|
2
3
|
import { resolveBaseConfig } from "../lib/config.js";
|
|
3
4
|
import { handleError, ValidationError } from "../lib/errors.js";
|
|
4
|
-
import { outputJson } from "../lib/output.js";
|
|
5
|
+
import { outputJson, outputQuiet } from "../lib/output.js";
|
|
6
|
+
const MINUTE_MS = 60_000;
|
|
7
|
+
const LIFETIME_UNIT_MS = { m: MINUTE_MS, h: 60 * MINUTE_MS, d: 24 * 60 * MINUTE_MS };
|
|
8
|
+
/** `--expires 30m | 2h | 1d` in milliseconds, within the server's 1 minute to 24 hours. */
|
|
9
|
+
export function parseKeyLifetime(value) {
|
|
10
|
+
const match = /^(\d+)\s*([mhd])$/i.exec(value.trim());
|
|
11
|
+
if (!match) {
|
|
12
|
+
throw new ValidationError(`--expires takes a lifetime like 30m, 2h or 1d, not "${value}".`);
|
|
13
|
+
}
|
|
14
|
+
const ms = Number(match[1]) * LIFETIME_UNIT_MS[match[2].toLowerCase()];
|
|
15
|
+
if (ms < MINUTE_MS || ms > LIFETIME_UNIT_MS.d) {
|
|
16
|
+
throw new ValidationError("A child key lives between 1 minute and 24 hours (--expires 1m to 24h).");
|
|
17
|
+
}
|
|
18
|
+
return ms;
|
|
19
|
+
}
|
|
20
|
+
/** The environment that hands a child key to the agent it was minted for. */
|
|
21
|
+
export function childKeyEnv(child, serverUrl) {
|
|
22
|
+
const server = serverUrl && serverUrl !== BRAND.url ? `CNOTES_SERVER=${serverUrl} ` : "";
|
|
23
|
+
return `${server}CNOTES_TOKEN=${child.key} CNOTES_WORKSPACE=${child.workspaceId}`;
|
|
24
|
+
}
|
|
25
|
+
function describeKey(k, now) {
|
|
26
|
+
const tags = [];
|
|
27
|
+
if (k.source === "child")
|
|
28
|
+
tags.push(`child of ${k.parentKeyId ?? "a revoked key"}`);
|
|
29
|
+
if (k.source === "oauth")
|
|
30
|
+
tags.push("connector");
|
|
31
|
+
if (k.workspaceId)
|
|
32
|
+
tags.push(`pinned to ${k.workspaceId}`);
|
|
33
|
+
if (k.expiresAt && k.expiresAt < now)
|
|
34
|
+
tags.push("expired");
|
|
35
|
+
return tags.length ? ` (${tags.join(", ")})` : "";
|
|
36
|
+
}
|
|
5
37
|
export function registerAuthKeysCommands(auth, program) {
|
|
6
38
|
const keys = auth
|
|
7
39
|
.command("keys")
|
|
8
|
-
.description("
|
|
40
|
+
.description("Create child keys for agents you start, and list and revoke CLI API keys");
|
|
41
|
+
keys
|
|
42
|
+
.command("create")
|
|
43
|
+
.description("Mint a key for one agent you are about to start: named, pinned to one workspace, expiring within 24 hours")
|
|
44
|
+
.requiredOption("--name <name>", 'Who the key is for, as History should show it (e.g. "Seat 3 · Notion PM")')
|
|
45
|
+
.option("--expires <lifetime>", "How long it lives: 30m, 2h (the default) or up to 24h")
|
|
46
|
+
.addHelpText("after", `
|
|
47
|
+
The key is pinned to the workspace -w names (else your current one), acts with
|
|
48
|
+
your role there, and is shown once. Every run the agent opens is labelled with
|
|
49
|
+
its name in History. Revoking your own key revokes every child it minted.
|
|
50
|
+
Only a key from \`cnotes auth login\` can mint; a child or a connector token cannot.
|
|
51
|
+
|
|
52
|
+
Examples:
|
|
53
|
+
$ cnotes auth keys create --name "Seat 3 · Notion PM" --expires 90m
|
|
54
|
+
$ CHILD=$(cnotes auth keys create --name "Verifier · undo" -q) # just the key
|
|
55
|
+
$ CNOTES_TOKEN=$CHILD CNOTES_WORKSPACE=<workspaceId> cnotes notes list`)
|
|
56
|
+
.action(async (opts) => {
|
|
57
|
+
const json = program.opts().json ?? false;
|
|
58
|
+
try {
|
|
59
|
+
const cfg = resolveBaseConfig(program.opts());
|
|
60
|
+
if (!cfg.token)
|
|
61
|
+
throw new ValidationError("Not authenticated. Run `cnotes auth login` first.");
|
|
62
|
+
if (!cfg.workspaceId) {
|
|
63
|
+
throw new ValidationError("No workspace to pin the key to.", "Pass -w <workspaceId> or run `cnotes workspace use`.");
|
|
64
|
+
}
|
|
65
|
+
const ttlMs = opts.expires !== undefined ? parseKeyLifetime(opts.expires) : undefined;
|
|
66
|
+
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
67
|
+
const child = await api.post("/api/auth/cli-keys", {
|
|
68
|
+
name: opts.name,
|
|
69
|
+
workspaceId: cfg.workspaceId,
|
|
70
|
+
...(ttlMs !== undefined ? { ttlMs } : {}),
|
|
71
|
+
});
|
|
72
|
+
if (program.opts().quiet) {
|
|
73
|
+
outputQuiet(child.key);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (json) {
|
|
77
|
+
outputJson({ ...child, env: childKeyEnv(child, cfg.serverUrl) });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
console.log(`Child key "${child.name}", pinned to ${child.workspaceId}, expires ${new Date(child.expiresAt).toISOString()}.`);
|
|
81
|
+
console.log("Shown once. Hand it to that agent only:");
|
|
82
|
+
console.log("");
|
|
83
|
+
console.log(` ${childKeyEnv(child, cfg.serverUrl)} cnotes ...`);
|
|
84
|
+
console.log("");
|
|
85
|
+
console.log(`Revoke just this one with: cnotes auth keys revoke ${child.keyId}`);
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
handleError(error, json);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
9
91
|
keys
|
|
10
92
|
.command("list")
|
|
11
93
|
.description("List CLI API keys (metadata only — not the secret values)")
|
|
@@ -27,6 +109,7 @@ export function registerAuthKeysCommands(auth, program) {
|
|
|
27
109
|
return;
|
|
28
110
|
}
|
|
29
111
|
console.log("CLI API keys:");
|
|
112
|
+
const now = Date.now();
|
|
30
113
|
for (const k of rows) {
|
|
31
114
|
const last = k.lastUsedAt
|
|
32
115
|
? new Date(k.lastUsedAt).toISOString()
|
|
@@ -34,7 +117,7 @@ export function registerAuthKeysCommands(auth, program) {
|
|
|
34
117
|
const exp = k.expiresAt
|
|
35
118
|
? new Date(k.expiresAt).toISOString()
|
|
36
119
|
: "never";
|
|
37
|
-
console.log(` ${k.id} ${k.name}`);
|
|
120
|
+
console.log(` ${k.id} ${k.name}${describeKey(k, now)}`);
|
|
38
121
|
console.log(` created: ${new Date(k.createdAt).toISOString()} last used: ${last} expires: ${exp}`);
|
|
39
122
|
}
|
|
40
123
|
}
|
|
@@ -58,7 +141,8 @@ export function registerAuthKeysCommands(auth, program) {
|
|
|
58
141
|
outputJson(result);
|
|
59
142
|
}
|
|
60
143
|
else {
|
|
61
|
-
|
|
144
|
+
const children = result.childrenRevoked ?? 0;
|
|
145
|
+
console.log(`Revoked CLI API key ${keyId}${children ? `, and the ${children} child key${children === 1 ? "" : "s"} it minted` : ""}`);
|
|
62
146
|
}
|
|
63
147
|
}
|
|
64
148
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@creator-notes/cnotes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.112.0",
|
|
4
4
|
"description": "CLI for CreatorNotes — create notes, build canvases, search knowledge from the terminal",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@inquirer/prompts": "^8.3.2",
|
|
61
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
61
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
62
62
|
"commander": "^12.1.0",
|
|
63
63
|
"open": "^10.1.0",
|
|
64
64
|
"update-notifier": "^5.1.0",
|
|
@@ -93,6 +93,15 @@ cnotes operations end --agent-run-id $RUN
|
|
|
93
93
|
|
|
94
94
|
The draft you work in is shared the same way: `draft open` and `draft checkout` save it for every terminal on the login. A second agent that should work live sets `CNOTES_PROPOSAL=none`; one that works in its own draft sets `CNOTES_PROPOSAL=<draft id>` ([drafts.md](drafts.md)).
|
|
95
95
|
|
|
96
|
+
**Agents you start.** When you start other agents (subagents, a swarm, a scheduled bot), give each one its own key instead of yours: `cnotes auth keys create --name "<who it is>"` mints a key pinned to the active workspace (or `-w`) that lives 2 hours unless `--expires` says otherwise (up to 24h). Every run that agent opens shows its name in History, so the person can tell five agents of one brand apart. `-q` prints only the key; the agent uses it through the environment and opens its own detached run:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
KEY=$(cnotes auth keys create --name "Seat 3 · Notion PM" --expires 90m -q)
|
|
100
|
+
CNOTES_TOKEN=$KEY CNOTES_WORKSPACE=<workspaceId> cnotes operations begin --prompt "Reviewed the pricing story" --detached -q
|
|
101
|
+
```
|
|
102
|
+
|
|
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
|
+
|
|
96
105
|
## Writing a good `--prompt`
|
|
97
106
|
|
|
98
107
|
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`.
|