slingit 0.2.0 → 0.2.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.
package/README.md CHANGED
@@ -29,6 +29,9 @@ npx slingit shot analysis.md --expire 7
29
29
  # Load a note back — prints its Markdown to stdout (decrypts locally, key from #)
30
30
  npx slingit pull https://slingit.dev/aX7k2mQp9f#Hk3...
31
31
 
32
+ # Also pull back any reader comments left on the note (feedback loop)
33
+ npx slingit pull https://slingit.dev/aX7k2mQp9f#Hk3... --comments
34
+
32
35
  # Skill for Claude Code ("send these findings to X's email")
33
36
  npx slingit install-skill
34
37
 
@@ -64,7 +67,7 @@ Env takes precedence over the file; the file takes precedence over the built-in
64
67
  ## Loading a note (`pull`)
65
68
 
66
69
  ```bash
67
- npx slingit pull <url>
70
+ npx slingit pull <url> [--comments|--comments-only]
68
71
  ```
69
72
 
70
73
  Fetches a published note and prints its Markdown to stdout — handy for pulling an
@@ -75,6 +78,21 @@ zero-knowledge model as the browser reader). Pass the **full link including the
75
78
  after `#`**; `--public` links have no fragment and pull just as well. Expired or missing
76
79
  notes produce a clear error and a non-zero exit code.
77
80
 
81
+ With `--comments`, any reader comments left on the note are fetched too and appended as
82
+ a `## Comments` section after the body — closing the feedback loop when someone reviews a
83
+ note you shared. Comments on encrypted notes are decrypted locally with the same key. If
84
+ the comments cannot be fetched, the note body still prints and a one-line notice goes to
85
+ stderr.
86
+
87
+ With `--comments-only`, only the comments are fetched and printed — the note body is
88
+ skipped entirely. Unlike `--comments`, a failure to fetch here is a hard error (there's
89
+ nothing else to fall back to).
90
+
91
+ | Flag | Description | Default |
92
+ |---|---|---|
93
+ | `--comments` | Also fetch reader comments and append them after the note body | off |
94
+ | `--comments-only` | Fetch and print just the comments, skipping the note body | off |
95
+
78
96
  ## Skill installation
79
97
 
80
98
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slingit",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Share formatted Markdown notes via link. Encrypted by default (key in #URL), optional email delivery.",
5
5
  "type": "module",
6
6
  "bin": {
package/skill/SKILL.md CHANGED
@@ -25,6 +25,30 @@ fragment and decryption happens locally in the CLI (the key is never sent to the
25
25
  server). Public links (`--public`) have no key and pull just as well. If the note has
26
26
  expired or the link is wrong, `pull` prints a clear error and exits non-zero.
27
27
 
28
+ ### Reader feedback (`--comments`)
29
+
30
+ Add `--comments` to also fetch any reader comments left on the note and append them as
31
+ a `## Comments` section after the body:
32
+
33
+ ```bash
34
+ npx slingit pull <url> --comments
35
+ ```
36
+
37
+ Use this to **check for reviewer feedback on a note you shared earlier**: sling an
38
+ analysis to a human, and once they have read it and left comments in the browser reader,
39
+ pull it back with `--comments` to bring their feedback into the session. Comments on
40
+ encrypted notes are decrypted locally with the same key from the `#` fragment. If a note
41
+ has no comments yet, the section reads `## Comments (0)`; if the comments cannot be
42
+ fetched, the note body still prints and a one-line notice goes to stderr.
43
+
44
+ If you only care about the feedback and not the (already-known) note body — e.g. checking
45
+ in on a note you slung earlier in the same session — use `--comments-only` instead to skip
46
+ re-fetching and re-printing the whole document:
47
+
48
+ ```bash
49
+ npx slingit pull <url> --comments-only
50
+ ```
51
+
28
52
  ## Choose the input method first
29
53
 
30
54
  Use the method that matches the user's request:
package/src/cli.js CHANGED
@@ -8,7 +8,8 @@ const HELP = `slingit — share Markdown notes via link (encrypted by default)
8
8
 
9
9
  Usage:
10
10
  slingit shot [file.md] [flags] publish a note (file or stdin)
11
- slingit pull <url> fetch a note by link, print its Markdown to stdout
11
+ slingit pull <url> [--comments|--comments-only]
12
+ fetch a note by link, print its Markdown to stdout
12
13
  slingit install-skill [flags] install the agent skill
13
14
  slingit help this help
14
15
 
@@ -39,6 +40,8 @@ in the #URL fragment (the server never sees it). --public is a deliberate opt-ou
39
40
  pull decrypts locally too: it reads the note id from the URL path and the key from
40
41
  the #fragment, fetches the ciphertext by id alone, and prints the Markdown. The key
41
42
  is never sent to the server. Pass the full link, including the part after #.
43
+ Add --comments to also fetch reader feedback and append it as a Comments section.
44
+ Use --comments-only to fetch just the comments, without the note body.
42
45
  `;
43
46
 
44
47
  export async function main(argv) {
package/src/pull.js CHANGED
@@ -11,10 +11,23 @@ const ID_RE = /^[A-Za-z0-9_-]{10,14}$/;
11
11
  * reader, so the key never reaches the server — the iron rule stays intact.
12
12
  */
13
13
  export async function pull(args) {
14
- const { url } = parseArgs(args);
14
+ const { url, comments: wantComments, commentsOnly } = parseArgs(args);
15
15
  const { id, origin, key } = parseUrl(url);
16
16
 
17
17
  const meta = await fetchMeta(origin, id);
18
+
19
+ if (commentsOnly) {
20
+ if (meta.mode !== 'public' && !key) {
21
+ throw new Error(
22
+ 'this note is encrypted but the link has no key after "#" — you need the full link (including the #fragment) to read its comments'
23
+ );
24
+ }
25
+ const raw = await fetchComments(origin, id);
26
+ const normalized = await decryptComments(raw, meta, key);
27
+ process.stdout.write(formatCommentsSection(normalized, { standalone: true }));
28
+ return;
29
+ }
30
+
18
31
  const blob = await fetchBlob(origin, id);
19
32
 
20
33
  let markdown;
@@ -39,18 +52,41 @@ export async function pull(args) {
39
52
  }
40
53
  }
41
54
 
42
- process.stdout.write(markdown.endsWith('\n') ? markdown : `${markdown}\n`);
55
+ let output = markdown.endsWith('\n') ? markdown : `${markdown}\n`;
56
+
57
+ if (wantComments) {
58
+ // The note itself already loaded — a comments hiccup must not fail the pull.
59
+ try {
60
+ const raw = await fetchComments(origin, id);
61
+ const normalized = await decryptComments(raw, meta, key);
62
+ output += formatCommentsSection(normalized);
63
+ } catch (err) {
64
+ process.stderr.write(`slingit: could not load comments (${err.message}); skipping\n`);
65
+ }
66
+ }
67
+
68
+ process.stdout.write(output);
43
69
  }
44
70
 
45
71
  function parseArgs(args) {
46
72
  let url = null;
73
+ let comments = false;
74
+ let commentsOnly = false;
47
75
  for (const a of args) {
76
+ if (a === '--comments') {
77
+ comments = true;
78
+ continue;
79
+ }
80
+ if (a === '--comments-only') {
81
+ commentsOnly = true;
82
+ continue;
83
+ }
48
84
  if (a.startsWith('-')) throw new Error(`unknown flag "${a}". See: slingit help`);
49
85
  if (url) throw new Error('only one URL can be given');
50
86
  url = a;
51
87
  }
52
- if (!url) throw new Error('usage: slingit pull <url>');
53
- return { url };
88
+ if (!url) throw new Error('usage: slingit pull <url> [--comments|--comments-only]');
89
+ return { url, comments, commentsOnly };
54
90
  }
55
91
 
56
92
  function parseUrl(input) {
@@ -91,6 +127,84 @@ async function fetchBlob(origin, id) {
91
127
  return res.arrayBuffer();
92
128
  }
93
129
 
130
+ /** Fetch the reader comments for a note. Returns the raw `comments` array. */
131
+ async function fetchComments(origin, id) {
132
+ const res = await httpGet(`${origin}/${id}/comments`);
133
+ if (!res.ok) throw new Error(`server returned HTTP ${res.status}`);
134
+ let data;
135
+ try {
136
+ data = await res.json();
137
+ } catch {
138
+ throw new Error('invalid comments response');
139
+ }
140
+ return Array.isArray(data?.comments) ? data.comments : [];
141
+ }
142
+
143
+ /**
144
+ * Normalize raw comments into `{ author, createdAt, scope, text, quote }`.
145
+ * For encrypted notes each comment carries its own ciphertext + fresh IV and is
146
+ * decrypted with the note's key (same in-memory key, never logged or stored — the
147
+ * iron rule holds exactly like the note-body path). A comment that fails to
148
+ * decrypt or parse is skipped rather than aborting the whole pull.
149
+ */
150
+ async function decryptComments(raw, meta, key) {
151
+ if (meta.mode === 'public') {
152
+ // Public comments are already plaintext.
153
+ return raw.map((c) => ({
154
+ author: c.author,
155
+ createdAt: c.createdAt,
156
+ scope: c.scope,
157
+ text: c.text,
158
+ quote: c.quote ?? null,
159
+ }));
160
+ }
161
+ const out = [];
162
+ for (const c of raw) {
163
+ try {
164
+ const ciphertext = Buffer.from(c.ciphertext, 'base64');
165
+ const { text, quote } = JSON.parse(await decryptNote(ciphertext, key, c.iv));
166
+ out.push({
167
+ author: c.author,
168
+ createdAt: c.createdAt,
169
+ scope: c.scope,
170
+ text,
171
+ quote: quote ?? null,
172
+ });
173
+ } catch {
174
+ // Corrupted or tampered comment — skip it.
175
+ }
176
+ }
177
+ return out;
178
+ }
179
+
180
+ /**
181
+ * Render a normalized comments array as a Markdown section. By default it's
182
+ * appended after the note body (so it opens with a `---` separator); pass
183
+ * `standalone: true` for `--comments-only` output, which has no document above
184
+ * it to separate from. Pure and self-contained so it can be unit-tested without
185
+ * a server.
186
+ */
187
+ export function formatCommentsSection(comments, { standalone = false } = {}) {
188
+ let out = standalone
189
+ ? `## Comments (${comments.length})\n\n`
190
+ : `\n---\n\n## Comments (${comments.length})\n\n`;
191
+ if (comments.length === 0) {
192
+ return `${out}_No comments yet._\n`;
193
+ }
194
+ out += comments.map(formatComment).join('\n\n');
195
+ return out.endsWith('\n') ? out : `${out}\n`;
196
+ }
197
+
198
+ function formatComment(c) {
199
+ const date = typeof c.createdAt === 'string' ? c.createdAt.slice(0, 10) : '';
200
+ const lines = [`**${c.author}** — ${date}`];
201
+ if (c.scope === 'selection' && c.quote != null && c.quote !== '') {
202
+ lines.push(`> ${c.quote}`);
203
+ }
204
+ lines.push('', c.text ?? '');
205
+ return lines.join('\n');
206
+ }
207
+
94
208
  function assertNotExpired(res) {
95
209
  if (res.status === 410) {
96
210
  throw new Error('this note has expired and is no longer available');