@creator-notes/cnotes 0.127.1 → 0.129.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.
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { ApiClient } from "../lib/api-client.js";
|
|
2
|
+
import { resolveConfig } from "../lib/config.js";
|
|
3
|
+
import { handleError } from "../lib/errors.js";
|
|
4
|
+
import { outputJson, truncate } from "../lib/output.js";
|
|
5
|
+
/** Orphans printed before "…and N more"; --json always carries every one. */
|
|
6
|
+
const ORPHANS_SHOWN = 30;
|
|
7
|
+
const name = (n) => `${n.displayId} ${truncate(n.title || "(untitled)", 60)}`;
|
|
8
|
+
/** The report as a reader scans it: what misleads first, then what nobody reaches. */
|
|
9
|
+
export function workspaceCheckLines(report, opts = {}) {
|
|
10
|
+
const lines = [];
|
|
11
|
+
const decisions = report.stalePremises;
|
|
12
|
+
if (decisions.length > 0) {
|
|
13
|
+
lines.push(`Decisions resting on an archived or replaced note: ${decisions.length}`);
|
|
14
|
+
for (const d of decisions) {
|
|
15
|
+
lines.push(` ${name(d)}`);
|
|
16
|
+
for (const p of d.restsOn) {
|
|
17
|
+
const why = p.state === "archived"
|
|
18
|
+
? "archived"
|
|
19
|
+
: `replaced by ${(p.replacedBy ?? []).map((r) => r.displayId).join(", ")}`;
|
|
20
|
+
lines.push(` ${p.relationship ?? "links to"} ${name(p)}: ${why}`);
|
|
21
|
+
}
|
|
22
|
+
if (d.capped)
|
|
23
|
+
lines.push(" (more links than one check reads; older ones unchecked)");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
lines.push("No Decision rests on an archived or replaced note.");
|
|
28
|
+
}
|
|
29
|
+
if (!report.premisesChecked) {
|
|
30
|
+
lines.push(" Replacement could not be read on some pages; only archived premises are listed there.");
|
|
31
|
+
}
|
|
32
|
+
lines.push("");
|
|
33
|
+
const orphans = report.orphans;
|
|
34
|
+
if (orphans.length > 0) {
|
|
35
|
+
lines.push(`Notes no link or canvas reaches: ${orphans.length}`);
|
|
36
|
+
const shown = opts.allOrphans ? orphans : orphans.slice(0, ORPHANS_SHOWN);
|
|
37
|
+
for (const o of shown)
|
|
38
|
+
lines.push(` ${name(o)} (${o.type})`);
|
|
39
|
+
if (shown.length < orphans.length) {
|
|
40
|
+
lines.push(` …and ${orphans.length - shown.length} more (--all-orphans, or --json for every one)`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
lines.push("Every note has a live link or sits on a canvas.");
|
|
45
|
+
}
|
|
46
|
+
lines.push("");
|
|
47
|
+
lines.push(`Checked ${report.scanned.toLocaleString("en-US")} notes.`);
|
|
48
|
+
return lines;
|
|
49
|
+
}
|
|
50
|
+
export function registerWorkspaceCheck(ws, program) {
|
|
51
|
+
ws.command("check")
|
|
52
|
+
.description("Find Decisions resting on archived or replaced notes, and notes no link or canvas reaches")
|
|
53
|
+
.option("--all-orphans", "List every orphan note, not the first 30")
|
|
54
|
+
.option("--page-size <n>", "Notes read per request (1-100)", "40")
|
|
55
|
+
.addHelpText("after", `
|
|
56
|
+
Reads the whole workspace, a page at a time, and reports what may mislead the
|
|
57
|
+
next reader:
|
|
58
|
+
- a Decision that links to a note since archived, or replaced (a newer note
|
|
59
|
+
links to it with supersedes / replaces / superseded-by). The Decision may
|
|
60
|
+
rest on something no longer true: read it, then revise or re-confirm it.
|
|
61
|
+
A "supersedes" link from the Decision itself is a replacement, not a premise.
|
|
62
|
+
- a live note with no live link in or out and on no canvas: only search
|
|
63
|
+
reaches it. Link it from the note it belongs with, place it, or archive it.
|
|
64
|
+
|
|
65
|
+
Before relying on one Decision, \`cnotes notes get <id> --expand\` shows the
|
|
66
|
+
notes it rests on and which were replaced.
|
|
67
|
+
|
|
68
|
+
--json returns { stalePremises, orphans, scanned, premisesChecked }.
|
|
69
|
+
|
|
70
|
+
Examples:
|
|
71
|
+
$ cnotes workspace check
|
|
72
|
+
$ cnotes workspace check --json
|
|
73
|
+
`)
|
|
74
|
+
.action(async (opts) => {
|
|
75
|
+
const cfg = resolveConfig(program.opts());
|
|
76
|
+
const api = new ApiClient(cfg.serverUrl, cfg.token, cfg.workspaceId);
|
|
77
|
+
const limit = String(Math.min(100, Math.max(1, parseInt(opts.pageSize ?? "40", 10) || 40)));
|
|
78
|
+
try {
|
|
79
|
+
const report = { stalePremises: [], orphans: [], scanned: 0, premisesChecked: true };
|
|
80
|
+
let cursor = null;
|
|
81
|
+
// A progress count only on a terminal: a log would keep every \r line.
|
|
82
|
+
const showProgress = !cfg.json && process.stderr.isTTY === true;
|
|
83
|
+
do {
|
|
84
|
+
const page = await api.get("/api/notes/check", {
|
|
85
|
+
workspaceId: cfg.workspaceId,
|
|
86
|
+
limit,
|
|
87
|
+
...(cursor ? { cursor } : {}),
|
|
88
|
+
});
|
|
89
|
+
report.stalePremises.push(...page.stalePremises);
|
|
90
|
+
report.orphans.push(...page.orphans);
|
|
91
|
+
report.scanned += page.scanned;
|
|
92
|
+
report.premisesChecked &&= page.premisesChecked;
|
|
93
|
+
cursor = page.cursor;
|
|
94
|
+
if (showProgress && cursor)
|
|
95
|
+
process.stderr.write(`\rChecked ${report.scanned} notes…`);
|
|
96
|
+
} while (cursor);
|
|
97
|
+
if (showProgress)
|
|
98
|
+
process.stderr.write("\r\x1b[K");
|
|
99
|
+
if (cfg.json) {
|
|
100
|
+
outputJson(report, cfg.fields);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
for (const line of workspaceCheckLines(report, { allOrphans: opts.allOrphans }))
|
|
104
|
+
console.log(line);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
handleError(error, cfg.json);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
@@ -6,6 +6,7 @@ import { outputJson, outputTable, timeAgo } from "../lib/output.js";
|
|
|
6
6
|
import { blockedWorkspaceNotes, workspaceListState } from "../lib/billing-block.js";
|
|
7
7
|
import { isNotFound } from "../lib/proposal-in-place.js";
|
|
8
8
|
import { draftLink, draftOfLine, spokenDetail } from "../lib/draft-view.js";
|
|
9
|
+
import { registerWorkspaceCheck } from "./workspace-check.js";
|
|
9
10
|
const CHECKOUT_POLL_INTERVAL_MS = 5000;
|
|
10
11
|
/**
|
|
11
12
|
* One poll of the verify-creation endpoint. The two "keep waiting" states are
|
|
@@ -163,6 +164,7 @@ export function registerWorkspaceCommands(program) {
|
|
|
163
164
|
.command("workspace")
|
|
164
165
|
.alias("ws")
|
|
165
166
|
.description("Manage workspaces");
|
|
167
|
+
registerWorkspaceCheck(ws, program);
|
|
166
168
|
ws
|
|
167
169
|
.command("list")
|
|
168
170
|
.description("List your workspaces")
|
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
* The server sends only dimensions that say something, so nothing here
|
|
7
7
|
* invents a reading when a field is missing.
|
|
8
8
|
*/
|
|
9
|
+
function readChecked(raw) {
|
|
10
|
+
if (!raw || typeof raw !== "object")
|
|
11
|
+
return undefined;
|
|
12
|
+
const c = raw;
|
|
13
|
+
const by = Array.isArray(c.by) ? c.by.filter((n) => typeof n === "string") : [];
|
|
14
|
+
if (by.length === 0 || typeof c.version !== "number" || typeof c.at !== "string")
|
|
15
|
+
return undefined;
|
|
16
|
+
return { by, at: c.at, version: c.version, current: c.current === true };
|
|
17
|
+
}
|
|
9
18
|
/** The fields off a raw note row, or undefined when there is nothing to read. */
|
|
10
19
|
export function readNoteDimensions(note) {
|
|
11
20
|
const dimensions = Array.isArray(note.dimensions)
|
|
@@ -26,9 +35,10 @@ export function readNoteDimensions(note) {
|
|
|
26
35
|
}))
|
|
27
36
|
: [];
|
|
28
37
|
const waitsOn = Array.isArray(note.waitsOn) ? note.waitsOn.filter((n) => typeof n === "string") : [];
|
|
29
|
-
|
|
38
|
+
const checked = readChecked(note.checked);
|
|
39
|
+
if (dimensions.length === 0 && waitsOn.length === 0 && !checked)
|
|
30
40
|
return undefined;
|
|
31
|
-
return { dimensions, waitsOn, waitsOnYou: note.waitsOnYou === true };
|
|
41
|
+
return { dimensions, waitsOn, waitsOnYou: note.waitsOnYou === true, ...(checked ? { checked } : {}) };
|
|
32
42
|
}
|
|
33
43
|
const refs = (notes) => notes.map((r) => (r.title ? `${r.displayId} (${r.title})` : r.displayId)).join(", ");
|
|
34
44
|
/**
|
|
@@ -54,14 +64,30 @@ export function formatWaitsOn(reading) {
|
|
|
54
64
|
* "Answered by: none yet (open)"
|
|
55
65
|
* "Waits on: you"
|
|
56
66
|
* "Superseded by: DECISION-117 (Wedge pivots)"
|
|
67
|
+
* "Checked by: Deniss · Nov 16 (v3)"
|
|
68
|
+
* "Checked: v3 by Ana, changed since"
|
|
57
69
|
*/
|
|
58
70
|
export function formatNoteDimensionLines(reading) {
|
|
59
71
|
const lines = reading.dimensions.map((d) => `${d.label}: ${formatDimension(d)}`);
|
|
60
72
|
const waits = formatWaitsOn(reading);
|
|
61
73
|
if (waits)
|
|
62
74
|
lines.push(`Waits on: ${waits}`);
|
|
75
|
+
const checked = formatChecked(reading.checked);
|
|
76
|
+
if (checked)
|
|
77
|
+
lines.push(checked);
|
|
63
78
|
return lines;
|
|
64
79
|
}
|
|
80
|
+
const DAY = new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", timeZone: "UTC" });
|
|
81
|
+
/** The mark as one header line, or null when nobody checked the note. */
|
|
82
|
+
export function formatChecked(checked) {
|
|
83
|
+
if (!checked)
|
|
84
|
+
return null;
|
|
85
|
+
const who = checked.by.join(", ");
|
|
86
|
+
if (!checked.current)
|
|
87
|
+
return `Checked: v${checked.version} by ${who}, changed since`;
|
|
88
|
+
const day = Number.isNaN(Date.parse(checked.at)) ? "" : ` · ${DAY.format(new Date(checked.at))}`;
|
|
89
|
+
return `Checked by: ${who}${day} (v${checked.version})`;
|
|
90
|
+
}
|
|
65
91
|
/**
|
|
66
92
|
* `--dimension key=state` as [key, state], split on the FIRST "=" only: a
|
|
67
93
|
* percentage state is itself ">=50" or "<=25". Either part is "" when missing.
|
package/package.json
CHANGED
package/skills/cnotes/SKILL.md
CHANGED
|
@@ -17,7 +17,7 @@ Every note and canvas you write is context: what the next reader, a teammate or
|
|
|
17
17
|
|
|
18
18
|
Each call costs the user a model round trip, so batch, and send independent calls together. Reads need no run.
|
|
19
19
|
|
|
20
|
-
1. **Read, in parallel.** `cnotes workspace current` names the workspace and its relationship types (`-w <id>` targets another for one command). `cnotes brief "<task>"` returns the notes, canvases and recent changes most relevant to the task, with what earlier runs made of each (`lesson:` under a note; `Start here` lists the notes runs keep finding useful): read a correction before relying on the note it sits on. `cnotes search "<topic>"` finds notes, canvases and images in one call; a first line `Not in the workspace: …` names words no note holds, so say that rather than answer from the nearest note. `cnotes notes get <id> --expand` loads a note with the notes it rests on. Before changing a canvas, `cnotes canvas read <canvasId>` (or `read-section SECTION-n` when the request names a frame). `cnotes types show <Type>` for each type you will write: author to its rubric. A Decision or Guide you find may already settle what you were about to propose.
|
|
20
|
+
1. **Read, in parallel.** `cnotes workspace current` names the workspace and its relationship types (`-w <id>` targets another for one command). `cnotes brief "<task>"` returns the notes, canvases and recent changes most relevant to the task, with what earlier runs made of each (`lesson:` under a note; `Start here` lists the notes runs keep finding useful): read a correction before relying on the note it sits on. `cnotes search "<topic>"` finds notes, canvases and images in one call; a first line `Not in the workspace: …` names words no note holds, so say that rather than answer from the nearest note. `cnotes notes get <id> --expand` loads a note with the notes it rests on; a `Checked by:` line means a person confirmed that version with a passkey, so lean on it over an unchecked note. Before changing a canvas, `cnotes canvas read <canvasId>` (or `read-section SECTION-n` when the request names a frame). `cnotes types show <Type>` for each type you will write: author to its rubric. A Decision or Guide you find may already settle what you were about to propose.
|
|
21
21
|
2. **Name the kind of request.** [references/situations.md](references/situations.md) sorts it into one of 13 rows by what the person will do with the result, and each row says what to write, how to lay it out and how to check it. The first row is no board: most requests want the work done or a plain answer, and at most one note.
|
|
22
22
|
3. **Write once, with `--intent`.** `--intent "<headline>"` opens an agent run for that one command and closes it after, so the change lands on the timeline as one revertable run; a removal gets a before snapshot. When a run is already open, the write joins it. To add cards, create and place them together:
|
|
23
23
|
```json
|