@creator-notes/cnotes 0.127.1 → 0.128.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.127.1",
3
+ "version": "0.128.0",
4
4
  "description": "CreatorNotes CLI: create notes, build canvases, search knowledge from the terminal",
5
5
  "author": {
6
6
  "name": "CreatorNotes",
@@ -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")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator-notes/cnotes",
3
- "version": "0.127.1",
3
+ "version": "0.128.0",
4
4
  "description": "CLI for CreatorNotes — create notes, build canvases, search knowledge from the terminal",
5
5
  "type": "module",
6
6
  "bin": {