@creator-notes/cnotes 0.120.1 → 0.120.2

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,6 +1,6 @@
1
1
  {
2
2
  "name": "creator-notes-cli",
3
- "version": "0.120.1",
3
+ "version": "0.120.2",
4
4
  "description": "CreatorNotes CLI: create notes, build canvases, search knowledge from the terminal",
5
5
  "author": {
6
6
  "name": "CreatorNotes",
@@ -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
- ...(savedUnder?.[1].kind ? { kind: savedUnder[1].kind } : {}),
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/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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator-notes/cnotes",
3
- "version": "0.120.1",
3
+ "version": "0.120.2",
4
4
  "description": "CLI for CreatorNotes — create notes, build canvases, search knowledge from the terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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. A command aimed at
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