@creator-notes/cnotes 0.135.1 → 0.136.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,6 +1,6 @@
1
1
  {
2
2
  "name": "creator-notes-cli",
3
- "version": "0.135.1",
3
+ "version": "0.136.0",
4
4
  "description": "CreatorNotes CLI: create notes, build canvases, search knowledge from the terminal",
5
5
  "author": {
6
6
  "name": "CreatorNotes",
@@ -21,8 +21,11 @@ export function registerBriefCommand(program) {
21
21
  Read-only and free of credits. \`operations begin --prompt\` includes the same
22
22
  brief, so you only need this when you are not opening a run. It opens with
23
23
  the workspace's conventions, one title each (conventions.rules in --json): the
24
- title is the rule, and \`cnotes notes get <id>\` has the why. The brief ends on
25
- one line, beforeWriting in --json: name the kind of request before you write.
24
+ title is the rule, and \`cnotes notes get <id>\` has the why. A canvas whose
25
+ goal has been judged carries a "done:" line (canvases[].done in --json): met,
26
+ partly met or not met, and each part of its Done when that is not true yet. The
27
+ brief ends on one line, beforeWriting in --json: name the kind of request
28
+ before you write.
26
29
 
27
30
  Examples:
28
31
  $ cnotes brief "set the Amplitude API key in production"
@@ -0,0 +1,88 @@
1
+ /**
2
+ * A board's done verdict as one sentence, for the places an agent already
3
+ * reads before it acts: the head of `cnotes canvas read` and each canvas a
4
+ * brief names (`cnotes brief`, `cnotes operations begin`).
5
+ *
6
+ * The verdict was stored and judged for weeks while only `cnotes canvas done`
7
+ * printed it, a command nothing told an agent to run. So an agent adding to a
8
+ * board read its goal and never learned which part of the Done when was still
9
+ * missing. The sentence leads with the level and then names what is not yet
10
+ * true, because that is what the next piece of work should aim at.
11
+ *
12
+ * Lives in the CLI package because the CLI cannot import from lib/; the web
13
+ * app's routes take it through lib/canvas/done-line.ts.
14
+ */
15
+ const LEVEL_LABEL = {
16
+ 0: "not met",
17
+ 1: "partly met",
18
+ 2: "met",
19
+ };
20
+ const flat = (s) => s.replace(/\s+/g, " ").trim();
21
+ const unstopped = (s) => flat(s).replace(/[.;]+$/, "");
22
+ /**
23
+ * The reading inside a stored score (a `canvasDone.latest` row, or `score` in
24
+ * GET /api/canvas/<id>/done), or null when there is nothing to say: the board
25
+ * was never judged, or the goal was reworded since, so the verdict is about a
26
+ * sentence the canvas no longer has.
27
+ */
28
+ export function doneReadingFrom(score) {
29
+ if (!score || typeof score !== "object")
30
+ return null;
31
+ const s = score;
32
+ if (s.fresh === false)
33
+ return null;
34
+ if (s.level !== 0 && s.level !== 1 && s.level !== 2)
35
+ return null;
36
+ if (typeof s.scoredAt !== "number")
37
+ return null;
38
+ const parts = [];
39
+ for (const p of Array.isArray(s.parts) ? s.parts : []) {
40
+ if (!p || typeof p.part !== "string" || typeof p.holds !== "boolean")
41
+ continue;
42
+ parts.push({ part: p.part, holds: p.holds, why: typeof p.why === "string" && p.why.trim() ? p.why : null });
43
+ }
44
+ return {
45
+ level: s.level,
46
+ scoredAt: s.scoredAt,
47
+ evidence: typeof s.evidence === "string" && s.evidence.trim() ? s.evidence : null,
48
+ parts: parts.length > 0 ? parts : null,
49
+ };
50
+ }
51
+ /**
52
+ * "partly met, 2 of 3 parts hold. Not yet: Deniss's answer is on the Question
53
+ * card (QUESTION-12 has no answer). Judged 2d ago."
54
+ *
55
+ * `judged` is the verdict's age in the caller's own words, so it agrees with
56
+ * the other ages that caller prints. `why: false` drops each part's reason,
57
+ * for a brief, where the canvas read that follows carries it.
58
+ */
59
+ export function doneVerdictLine(done, opts = {}) {
60
+ const label = LEVEL_LABEL[done.level];
61
+ const sentences = [];
62
+ const parts = done.parts ?? [];
63
+ if (parts.length > 0) {
64
+ const held = parts.filter((p) => p.holds).length;
65
+ if (parts.length === 1)
66
+ sentences.push(label);
67
+ else if (held === parts.length)
68
+ sentences.push(`${label}, all ${parts.length} parts hold`);
69
+ else
70
+ sentences.push(`${label}, ${held} of ${parts.length} parts hold`);
71
+ const missing = parts
72
+ .filter((p) => !p.holds)
73
+ .map((p) => {
74
+ const why = opts.why !== false && p.why ? ` (${unstopped(p.why)})` : "";
75
+ return `${unstopped(p.part)}${why}`;
76
+ });
77
+ if (missing.length > 0)
78
+ sentences.push(`Not yet: ${missing.join("; ")}`);
79
+ }
80
+ else {
81
+ sentences.push(label);
82
+ if (done.evidence)
83
+ sentences.push(unstopped(done.evidence));
84
+ }
85
+ if (opts.judged)
86
+ sentences.push(`Judged ${opts.judged}`);
87
+ return `${sentences.join(". ")}.`;
88
+ }
@@ -1,4 +1,5 @@
1
1
  import { describeLesson, fetchLessons } from "./lessons.js";
2
+ import { doneReadingFrom, doneVerdictLine } from "./done-line.js";
2
3
  export const BRIEF_LIMIT = 8;
3
4
  export const BRIEF_CANVAS_LIMIT = 3;
4
5
  export const BRIEF_CHANGE_LIMIT = 5;
@@ -91,16 +92,35 @@ export async function loadSessionBrief(api, workspaceId, prompt) {
91
92
  if (search === null && timeline === null)
92
93
  return null;
93
94
  const found = briefFromSearch(query, search);
94
- // After the search, since the lessons are looked up on the notes it found.
95
- const lessons = await fetchLessons(api, workspaceId, found.notes.map((n) => n.displayId))
96
- .then(lessonsFromResponse)
97
- .catch(() => null);
95
+ // After the search, since the lessons are looked up on the notes it found
96
+ // and the verdicts on the canvases it found. Reading a verdict is free and
97
+ // never runs the judge.
98
+ const [lessons, canvases] = await Promise.all([
99
+ fetchLessons(api, workspaceId, found.notes.map((n) => n.displayId))
100
+ .then(lessonsFromResponse)
101
+ .catch(() => null),
102
+ Promise.all(found.canvases.map((c) => withDoneReading(api, workspaceId, c))),
103
+ ]);
98
104
  return {
99
105
  ...found,
106
+ canvases,
100
107
  changes: changesFromTimeline(timeline),
101
108
  ...(lessons ? { lessons } : {}),
102
109
  };
103
110
  }
111
+ /** The canvas with its done verdict, or as it was when it has none or the lookup fails. */
112
+ async function withDoneReading(api, workspaceId, canvas) {
113
+ const done = await api
114
+ .get(`/api/canvas/${encodeURIComponent(canvas.ref)}/done`, { workspaceId })
115
+ .then((r) => doneReadingFrom(r?.score))
116
+ .catch(() => null);
117
+ return done ? { ...canvas, done } : canvas;
118
+ }
119
+ /** "today" or "3d ago": the age every dated line of a brief uses. */
120
+ function daysAgo(at, now) {
121
+ const days = Math.max(0, Math.round((now - at) / 86_400_000));
122
+ return days === 0 ? "today" : `${days}d ago`;
123
+ }
104
124
  /** Pull the lessons overlay out of a `/api/lessons` response. */
105
125
  export function lessonsFromResponse(data) {
106
126
  const d = data;
@@ -160,13 +180,15 @@ export function renderBrief(brief, now = Date.now()) {
160
180
  lines.push(` ${c.ref} ${c.title}`);
161
181
  if (c.about)
162
182
  lines.push(` ${clip(c.about, 140)}`);
183
+ // Never clipped: the part that is not yet true is the reason to print it.
184
+ if (c.done)
185
+ lines.push(` done: ${doneVerdictLine(c.done, { judged: daysAgo(c.done.scoredAt, now), why: false })}`);
163
186
  }
164
187
  }
165
188
  if (brief.changes.length > 0) {
166
189
  lines.push("Recent changes on this:");
167
190
  for (const c of brief.changes) {
168
- const days = c.createdAt ? Math.max(0, Math.round((now - c.createdAt) / 86_400_000)) : null;
169
- const when = days === null ? "" : days === 0 ? "today" : `${days}d ago`;
191
+ const when = c.createdAt ? daysAgo(c.createdAt, now) : "";
170
192
  lines.push(` ${c.displayId} v${c.versionNumber} ${clip(c.headline, 90)}${when ? ` (${when})` : ""}`);
171
193
  }
172
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator-notes/cnotes",
3
- "version": "0.135.1",
3
+ "version": "0.136.0",
4
4
  "description": "CLI for CreatorNotes — create notes, build canvases, search knowledge from the terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -97,7 +97,11 @@ cnotes canvas create "<name>" --goal "<text>" --audience "<text>" --spec spec.js
97
97
  # Tufte"), the situation and its date (banner line 1) and the audience (--audience). "Track X" / "Explore X" are briefs
98
98
  # to yourself, not results; give them an exit ("Decide which X ship next. Done when ...").
99
99
  # `canvas read` prints the goal under the title, so re-read it before adding to a board and keep
100
- # the board inside it; fix a stale goal with `canvas update --goal`. The banner restates the goal
100
+ # the board inside it; fix a stale goal with `canvas update --goal`. Under the goal a judged board
101
+ # prints one `*Done: …*` line: met, partly met or not met, then "Not yet:" with each part of the
102
+ # Done when that is not true yet. Aim the work at those parts. When a part waits on a person's
103
+ # answer, ask them that question instead of adding more to the board. `cnotes brief` prints the
104
+ # same verdict under each canvas it names. No line means the board has not been judged. The banner restates the goal
101
105
  # in reader's words (canvas-elements.md, hard rule 7).
102
106
  cnotes canvas update <canvasId> [--title "<text>"] [--goal "<text>"] [--audience "<text>"]
103
107
  # Is the board done? The judge's last reading of whether the goal's "Done when" is true of