@workover/cli 0.6.0 → 0.7.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.
package/README.md CHANGED
@@ -20,6 +20,7 @@ workover projects # the projects you can reach, with their ids
20
20
  workover doc list --project 11
21
21
  workover doc read 1234
22
22
  workover rules list --project 11 # the style guide agents should write by
23
+ workover comments list 1234 # the feedback people left on a document
23
24
  workover draft --org 3 --project 11 "Document the billing flow"
24
25
  workover whoami # show the current sign-in
25
26
  workover logout # sign out and revoke this device's token
@@ -87,6 +88,32 @@ is how images get deleted by something that thought it was filling in a blank. I
87
88
  without that scope it is refused and `doc propose` is the way through. Every direct edit is recorded
88
89
  in the workspace's audit log, since unlike a proposal it leaves no review trail of its own.
89
90
 
91
+ ## Comments
92
+
93
+ The other half of coworking: the feedback a person left on the work, readable and answerable from
94
+ the terminal that produced it.
95
+
96
+ ```sh
97
+ workover comments list 1234 # open threads on the document
98
+ workover comments list 1234 --all # ...including resolved ones
99
+ workover comments add 1234 --to 45 "Fixed — it now says annual."
100
+ workover comments resolve 45
101
+ ```
102
+
103
+ `list` shows open threads only, with each reply printed under the comment it answers. Resolved
104
+ threads are hidden rather than dropped — `--all` brings them back, and the count at the bottom says
105
+ how many are being left out, so a document never looks quieter than it is.
106
+
107
+ **Reply before you resolve.** A thread that closes with no answer tells the person who raised it
108
+ nothing except that their objection is gone, and reopening is the only way back. `resolve` and
109
+ `reopen` are the same act in both directions, and both are recorded in the document's activity log
110
+ with your name against them.
111
+
112
+ Reading, commenting and resolving all work with a normal `workover login` — no extra scope. Deleting
113
+ a comment does not: it is deliberately not reachable from a token at all. An edit or a resolve leaves
114
+ the thread there to be read and reopened, while a deletion leaves nothing behind to notice, so that
115
+ one stays something a person does in the browser.
116
+
90
117
  ## The style guide
91
118
 
92
119
  Your workspace's **Style Guide** (Workover → Settings → Style Guide) is the set of rules your team
package/bin/workover.mjs CHANGED
@@ -1,6 +1,13 @@
1
1
  #!/usr/bin/env node
2
- // Workover CLI — Phase 1: `login` / `logout` / `whoami` via the device-authorization flow (RFC 8628).
3
- // Auth only for now; document/coworking commands (and the MCP server) build on the stored token.
2
+ // The Workover CLI. `login` / `logout` / `whoami` authenticate through the device-authorization
3
+ // flow (RFC 8628); everything else works on documents with the stored token: `projects`, `doc`
4
+ // (list/read/create/propose/write/search/tabs), `rules`, `comments`, `draft`, `draft-set`, `eval`.
5
+ //
6
+ // This header used to say "auth only for now", left over from the first version and never updated
7
+ // as the commands landed. On 2026-09-09 an agent read it, concluded the CLI could not edit
8
+ // documents, and reported the whole editing path as missing — while `doc write` had been shipping
9
+ // for weeks. A stale comment claiming LESS than the code does is read as a limitation and believed,
10
+ // because nobody grep-checks a file header. Keep this list current or delete it.
4
11
  import {
5
12
  readFileSync,
6
13
  writeFileSync,
@@ -23,6 +30,7 @@ import {
23
30
  documentText,
24
31
  contentCommitted,
25
32
  renderRulesBlock,
33
+ threadComments,
26
34
  } from '../lib.mjs';
27
35
 
28
36
  /*
@@ -73,10 +81,17 @@ const post = async (path, body) => {
73
81
  return res.json().catch(() => ({}));
74
82
  };
75
83
 
76
- /** An authenticated call against the signed-in API. GET unless a body is given. */
77
- const authedCall = async (cfg, path, body) => {
84
+ /**
85
+ * An authenticated call against the signed-in API. GET unless a body is given, POST when one is,
86
+ * and whatever `method` names when the route wants something else.
87
+ *
88
+ * The verb used to be inferred from the presence of a body, which covers every route these commands
89
+ * had until now and cannot express a PATCH — resolving a comment sends a body to a route that is
90
+ * not a POST, and inferring would have silently called the wrong endpoint.
91
+ */
92
+ const authedCall = async (cfg, path, body, { method } = {}) => {
78
93
  const res = await fetch(`${cfg.api}${path}`, {
79
- method: body ? 'POST' : 'GET',
94
+ method: method || (body ? 'POST' : 'GET'),
80
95
  headers: {
81
96
  authorization: `Bearer ${cfg.token}`,
82
97
  ...(body ? { 'content-type': 'application/json' } : {}),
@@ -1026,6 +1041,175 @@ async function docCommand() {
1026
1041
 
1027
1042
  }
1028
1043
 
1044
+ const COMMENTS_USAGE = [
1045
+ '',
1046
+ ' Usage: workover comments <command>',
1047
+ '',
1048
+ ' list <docId> [--all] [--json] the feedback on a document,',
1049
+ ' open threads only unless --all',
1050
+ ' add <docId> "<text>" leave a comment',
1051
+ ' [--to <commentId>] ...as a reply in that thread',
1052
+ ' [--quote "<text>"] ...against the passage it is about',
1053
+ ' resolve <commentId> [--json] mark a thread dealt with',
1054
+ ' reopen <commentId> [--json] put it back',
1055
+ '',
1056
+ ' Resolve the thread you actually answered, and say what you did first —',
1057
+ ' `comments add <docId> --to <commentId> "..."` then `comments resolve`. A',
1058
+ ' thread that closes with no reply tells the person who raised it nothing,',
1059
+ ' and reopening is the only way back.',
1060
+ '',
1061
+ ].join('\n');
1062
+
1063
+ /**
1064
+ * One comment: who and when on the first line, then the passage it is about, then the note itself.
1065
+ *
1066
+ * `label` carries the id and the shape (a thread opens with `#45`, an answer to it with `↳ #47`),
1067
+ * so a reply is visibly an answer rather than a second opinion that happens to be indented. Dates
1068
+ * are the ISO prefix rather than anything locale-aware — the CLI's output gets pasted into issues
1069
+ * and diffed, and a date that renders differently per machine is a false change.
1070
+ */
1071
+ const printComment = (c, { label, pad }) => {
1072
+ const who = c.authorName || `user ${c.authorId}`;
1073
+ const when = String(c.createdAt || '').slice(0, 10);
1074
+ const mark = c.resolved ? ' (resolved)' : '';
1075
+ console.log(`${label}${who}${when ? ` · ${when}` : ''}${mark}`);
1076
+ // The quoted passage first: it is what the comment is ABOUT, and the note rarely repeats it.
1077
+ if (c.quote) console.log(`${pad}on “${stripHtml(c.quote)}”`);
1078
+ for (const line of String(c.body || '').split('\n')) {
1079
+ console.log(`${pad}${line}`);
1080
+ }
1081
+ };
1082
+
1083
+ /**
1084
+ * Read, answer and close the comments on a document.
1085
+ *
1086
+ * The half of coworking that was missing. An agent could read a document and propose edits to it,
1087
+ * and could not see the objection somebody left on the work it had just done — so every review
1088
+ * round trip went back through the browser, and a person had to retype the feedback into the
1089
+ * terminal for the agent that caused it.
1090
+ */
1091
+ async function commentsCommand() {
1092
+ const sub = process.argv[3];
1093
+ // Usage before sign-in, matching `doc`: someone who typed the command wrong is asking what the
1094
+ // commands are, and answering "not signed in" sends them to fix the wrong thing.
1095
+ if (!['list', 'add', 'resolve', 'reopen'].includes(sub)) {
1096
+ console.log(COMMENTS_USAGE);
1097
+ process.exit(sub ? 1 : 0);
1098
+ }
1099
+ const { flags, positionals } = parseArgs(process.argv.slice(4), {
1100
+ booleans: ['json', 'all'],
1101
+ });
1102
+ const cfg = requireSignIn();
1103
+ const asJson = flags.json === true;
1104
+
1105
+ if (sub === 'resolve' || sub === 'reopen') {
1106
+ const resolved = sub === 'resolve';
1107
+ const commentId = rowId(positionals[0]);
1108
+ if (commentId === null) {
1109
+ console.log(`\n Usage: workover comments ${sub} <commentId>`);
1110
+ console.log(' The comment id — `workover comments list <docId>` prints it.\n');
1111
+ process.exit(1);
1112
+ }
1113
+ const res = await authedCall(
1114
+ cfg,
1115
+ `/project/comments/${commentId}`,
1116
+ { resolved },
1117
+ { method: 'PATCH' },
1118
+ );
1119
+ if (asJson) return console.log(JSON.stringify(res, null, 2));
1120
+ console.log(
1121
+ `\n \x1b[32m✓\x1b[0m ${resolved ? 'Resolved' : 'Reopened'} comment #${commentId}.`,
1122
+ );
1123
+ // Named because it is recoverable and the person who raised the thread cannot see who closed
1124
+ // it from the terminal. Both facts are the reason this is allowed to happen unattended at all.
1125
+ console.log(
1126
+ ` It is in the document's activity log as ${resolved ? 'resolved' : 'reopened'}, and`,
1127
+ );
1128
+ console.log(
1129
+ ` \`workover comments ${resolved ? 'reopen' : 'resolve'} ${commentId}\` undoes it.\n`,
1130
+ );
1131
+ return;
1132
+ }
1133
+
1134
+ if (sub === 'add') {
1135
+ const usage = 'workover comments add <docId> "<text>" [--to <commentId>]';
1136
+ const docId = docIdArg(positionals, usage);
1137
+ // The text is everything after the document id, so an unquoted sentence still arrives whole.
1138
+ let body = positionals.slice(1).join(' ').trim();
1139
+ // `--file` only when asked for. `doc` reads piped stdin without being told, which is right for
1140
+ // a document body; a comment is a sentence somebody types, and silently waiting on stdin would
1141
+ // read as a command that had hung.
1142
+ if (!body && typeof flags.file === 'string') body = (await readBody(flags)).trim();
1143
+ if (!body) {
1144
+ console.log(`\n Usage: ${usage}`);
1145
+ console.log(' Or --file <path> for a longer note.\n');
1146
+ process.exit(1);
1147
+ }
1148
+ const parentId = flags.to == null ? null : rowId(flags.to);
1149
+ if (flags.to != null && parentId === null) {
1150
+ console.log('\n ✗ --to must be a comment id. List them: workover comments list <docId>\n');
1151
+ process.exit(1);
1152
+ }
1153
+ const created = await authedCall(cfg, `/project/doc/${docId}/comments`, {
1154
+ body,
1155
+ ...(parentId === null ? {} : { parentId }),
1156
+ ...(typeof flags.quote === 'string' ? { quote: flags.quote } : {}),
1157
+ });
1158
+ if (asJson) return console.log(JSON.stringify(created, null, 2));
1159
+ console.log(
1160
+ `\n \x1b[32m✓\x1b[0m ${parentId === null ? 'Commented on' : `Replied in thread #${parentId} on`} document #${docId}${created?.id ? ` (#${created.id})` : ''}.`,
1161
+ );
1162
+ console.log(' Everyone on the document can see it, and the thread stays open until');
1163
+ console.log(' somebody resolves it.\n');
1164
+ return;
1165
+ }
1166
+
1167
+ // list
1168
+ const docId = docIdArg(positionals, 'workover comments list <docId>');
1169
+ const rows = (await authedCall(cfg, `/project/doc/${docId}/comments`)) || [];
1170
+ const all = threadComments(rows, { includeResolved: true });
1171
+ const threads = flags.all === true ? all : all.filter((t) => !t.resolved);
1172
+ const hidden = all.length - threads.length;
1173
+
1174
+ if (asJson) return console.log(JSON.stringify(threads, null, 2));
1175
+
1176
+ if (!threads.length) {
1177
+ console.log(
1178
+ hidden
1179
+ ? `\n No open comments on document #${docId} — ${hidden} resolved (--all shows them).\n`
1180
+ : `\n No comments on document #${docId}.\n`,
1181
+ );
1182
+ return;
1183
+ }
1184
+
1185
+ console.log('');
1186
+ for (const t of threads) {
1187
+ printComment(t, { label: ` #${String(t.id).padEnd(6)} `, pad: ' ' });
1188
+ for (const r of t.replies) {
1189
+ console.log('');
1190
+ printComment(r, { label: ` ↳ #${r.id} `, pad: ' ' });
1191
+ }
1192
+ console.log('');
1193
+ }
1194
+ /*
1195
+ * The tally has to describe what was actually printed, in both modes.
1196
+ *
1197
+ * Counting only the open ones reads as an undercount under `--all`, where the resolved threads
1198
+ * are right there on the screen; mentioning what is hidden is the whole point without it. So the
1199
+ * sentence changes rather than the number being reused.
1200
+ */
1201
+ const open = threads.filter((t) => !t.resolved).length;
1202
+ const shownResolved = threads.length - open;
1203
+ const plural = (n) => (n === 1 ? '' : 's');
1204
+ const tally = hidden
1205
+ ? `${open} open thread${plural(open)}, ${hidden} resolved (--all shows them)`
1206
+ : shownResolved
1207
+ ? `${threads.length} thread${plural(threads.length)}, ${shownResolved} resolved`
1208
+ : `${open} open thread${plural(open)}`;
1209
+ console.log(` ${tally}.`);
1210
+ console.log(` Reply with \`workover comments add ${docId} --to <commentId> "..."\`.\n`);
1211
+ }
1212
+
1029
1213
  /** The project ids every `doc` command asks for. */
1030
1214
  async function projects() {
1031
1215
  const cfg = requireSignIn();
@@ -1050,6 +1234,7 @@ else if (cmd === 'draft-set') await draftSet();
1050
1234
  else if (cmd === 'eval') await evaluateDocs();
1051
1235
  else if (cmd === 'doc') await docCommand();
1052
1236
  else if (cmd === 'rules') await rulesCommand();
1237
+ else if (cmd === 'comments') await commentsCommand();
1053
1238
  else if (cmd === 'projects') await projects();
1054
1239
  else {
1055
1240
  console.log('\n Workover CLI\n');
@@ -1064,6 +1249,8 @@ else {
1064
1249
  console.log(' plus tabs and tab-new for documents with several bodies');
1065
1250
  console.log(' workover doc create --project 11 --title "Billing" --file b.md');
1066
1251
  console.log(' workover doc read 123 · workover doc propose 123 --file new.md');
1252
+ console.log(' comments Read, answer and resolve feedback on a document');
1253
+ console.log(' workover comments list 123 · workover comments resolve 45');
1067
1254
  console.log(' rules The style guide agents should write by: list, export, add');
1068
1255
  console.log(' workover rules export --project 11 >> AGENTS.md');
1069
1256
  console.log(' projects List the projects you can reach, with their ids');
package/lib.mjs CHANGED
@@ -208,3 +208,66 @@ export const renderRulesBlock = (rules) => {
208
208
  '<<<END_WORKSPACE_CONTENT_RULES>>>',
209
209
  ].join('\n');
210
210
  };
211
+
212
+ /**
213
+ * Group a document's flat comment rows into threads, oldest conversation first.
214
+ *
215
+ * The API returns one row per comment with `parentId` pointing at whatever it answers, which is the
216
+ * right shape to store and the wrong shape to read: a reply printed between two unrelated top-level
217
+ * comments is not visibly a reply to either.
218
+ *
219
+ * `resolved` is read off the ROOT of a thread, never off each row. It is a per-row column, but a
220
+ * thread is the unit a person actually resolves — so filtering row by row would hide a resolved
221
+ * reply inside an open thread, leaving an answer with no question, and would print open replies
222
+ * under a resolved root, reopening a conversation nobody reopened.
223
+ *
224
+ * Two shapes are flattened rather than trusted, because both make comments DISAPPEAR from a
225
+ * terminal while they still exist in the app, which is the one failure a reviewer cannot catch:
226
+ *
227
+ * - A reply whose parent is not in the list is promoted to a thread of its own. The parent may have
228
+ * been deleted — its author or the document's owner can — and swallowing every answer to it would
229
+ * drop the objection silently.
230
+ * - A reply to a reply is attached to the thread's root. The schema threads one level deep, so
231
+ * nothing should be nested twice; filing it under a comment that is itself a reply would put it
232
+ * in a bucket nothing ever reads. The walk is bounded, so a row whose parent chain loops ends up
233
+ * as its own root instead of hanging.
234
+ */
235
+ export const threadComments = (comments, { includeResolved = false } = {}) => {
236
+ const rows = (comments || []).filter((c) => c && c.id != null);
237
+ const byId = new Map(rows.map((c) => [c.id, c]));
238
+
239
+ const rootOf = (comment) => {
240
+ let node = comment;
241
+ const seen = new Set();
242
+ while (node.parentId != null && !seen.has(node.id)) {
243
+ seen.add(node.id);
244
+ const parent = byId.get(node.parentId);
245
+ if (!parent || parent.id === node.id) break;
246
+ node = parent;
247
+ }
248
+ return node;
249
+ };
250
+
251
+ // Oldest first, so a thread reads top to bottom the way it was written. `id` breaks ties: two
252
+ // comments can share a timestamp, and an unstable order would shuffle them between runs.
253
+ const order = (a, b) =>
254
+ String(a.createdAt || '').localeCompare(String(b.createdAt || '')) ||
255
+ Number(a.id) - Number(b.id);
256
+
257
+ const roots = [];
258
+ const repliesByRoot = new Map();
259
+ for (const c of rows) {
260
+ const root = rootOf(c);
261
+ if (root === c) {
262
+ roots.push(c);
263
+ continue;
264
+ }
265
+ if (!repliesByRoot.has(root.id)) repliesByRoot.set(root.id, []);
266
+ repliesByRoot.get(root.id).push(c);
267
+ }
268
+
269
+ return roots
270
+ .filter((r) => includeResolved || !r.resolved)
271
+ .sort(order)
272
+ .map((r) => ({ ...r, replies: (repliesByRoot.get(r.id) || []).sort(order) }));
273
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workover/cli",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Workover command line — sign in and cowork on your documents from the terminal.",
5
5
  "license": "UNLICENSED",
6
6
  "author": "ScaleMath",