slingit 0.1.1 → 0.2.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
@@ -26,6 +26,9 @@ npx slingit shot analysis.md --public
26
26
  # Delete after 7 days
27
27
  npx slingit shot analysis.md --expire 7
28
28
 
29
+ # Load a note back — prints its Markdown to stdout (decrypts locally, key from #)
30
+ npx slingit pull https://slingit.dev/aX7k2mQp9f#Hk3...
31
+
29
32
  # Skill for Claude Code ("send these findings to X's email")
30
33
  npx slingit install-skill
31
34
 
@@ -58,6 +61,20 @@ Env takes precedence over the file; the file takes precedence over the built-in
58
61
  | `--from <text>` | Optional sender/signature shown on the note page and email | hidden |
59
62
  | `--copy` | Copy the link to the clipboard | off |
60
63
 
64
+ ## Loading a note (`pull`)
65
+
66
+ ```bash
67
+ npx slingit pull <url>
68
+ ```
69
+
70
+ Fetches a published note and prints its Markdown to stdout — handy for pulling an
71
+ analysis another agent slung straight into a session. The note id is read from the URL
72
+ path and, for encrypted notes, the AES key from the `#` fragment: the ciphertext is
73
+ fetched by id alone and decrypted locally, so the key is never sent to the server (same
74
+ zero-knowledge model as the browser reader). Pass the **full link including the part
75
+ after `#`**; `--public` links have no fragment and pull just as well. Expired or missing
76
+ notes produce a clear error and a non-zero exit code.
77
+
61
78
  ## Skill installation
62
79
 
63
80
  ```bash
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "slingit",
3
- "version": "0.1.1",
4
- "description": "Fire-and-forget: share formatted Markdown notes via link. Encrypted by default (key in #URL), optional email delivery.",
3
+ "version": "0.2.0",
4
+ "description": "Share formatted Markdown notes via link. Encrypted by default (key in #URL), optional email delivery.",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "slingit": "bin/slingit.js"
8
8
  },
9
+ "scripts": {
10
+ "test": "node test/unit.mjs"
11
+ },
9
12
  "files": [
10
13
  "bin",
11
14
  "src",
@@ -26,4 +29,4 @@
26
29
  ],
27
30
  "author": "BTA Systems",
28
31
  "license": "MIT"
29
- }
32
+ }
package/skill/SKILL.md CHANGED
@@ -1,14 +1,30 @@
1
1
  ---
2
2
  name: slingit
3
- description: Share formatted Markdown notes/analyses via a link (SlingIt). Use when the user asks to send session findings to an email, share an analysis as a link, "slingit this to X", "send these conclusions to Y's email", or "give me a link to this analysis".
3
+ description: Share formatted Markdown notes/analyses via a link (SlingIt), or load one back into the session. Use when the user asks to send session findings to an email, share an analysis as a link, "slingit this to X", "send these conclusions to Y's email", "give me a link to this analysis", or to read/load/pull an existing SlingIt link ("load this slingit note", "pull https://slingit.dev/...").
4
4
  ---
5
5
 
6
6
  # SlingIt — publish notes from the session
7
7
 
8
- You publish formatted Markdown notes with `npx slingit shot`. Each note gets a short
9
- link `https://slingit.dev/{id}`; by default it is **end-to-end encrypted** the AES-256
8
+ You publish formatted Markdown notes with `npx slingit shot`, and load published
9
+ notes back with `npx slingit pull <url>`. Each note gets a short link
10
+ `https://slingit.dev/{id}`; by default it is **end-to-end encrypted** — the AES-256
10
11
  key lives only in the `#` fragment of the URL, so the server cannot read the content.
11
12
 
13
+ ## Loading a note into the session (`pull`)
14
+
15
+ When the user gives you a SlingIt link and asks to "load", "read", "pull", or "open"
16
+ the note (e.g. another agent slung an analysis to review), fetch it with:
17
+
18
+ ```bash
19
+ npx slingit pull <url>
20
+ ```
21
+
22
+ It prints the note's Markdown to stdout so you can read it into your context. Pass the
23
+ **full link including the part after `#`** — for encrypted notes the key lives in the
24
+ fragment and decryption happens locally in the CLI (the key is never sent to the
25
+ server). Public links (`--public`) have no key and pull just as well. If the note has
26
+ expired or the link is wrong, `pull` prints a clear error and exits non-zero.
27
+
12
28
  ## Choose the input method first
13
29
 
14
30
  Use the method that matches the user's request:
package/src/cli.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import { readFile } from 'node:fs/promises';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import { shot } from './shot.js';
4
+ import { pull } from './pull.js';
4
5
  import { installSkill } from './install-skill.js';
5
6
 
6
7
  const HELP = `slingit — share Markdown notes via link (encrypted by default)
7
8
 
8
9
  Usage:
9
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
10
12
  slingit install-skill [flags] install the agent skill
11
13
  slingit help this help
12
14
 
@@ -33,6 +35,10 @@ Configuration (optional — the CLI works out of the box, no config needed):
33
35
 
34
36
  By default: the note is encrypted with AES-256-GCM locally, the key only ends up
35
37
  in the #URL fragment (the server never sees it). --public is a deliberate opt-out.
38
+
39
+ pull decrypts locally too: it reads the note id from the URL path and the key from
40
+ the #fragment, fetches the ciphertext by id alone, and prints the Markdown. The key
41
+ is never sent to the server. Pass the full link, including the part after #.
36
42
  `;
37
43
 
38
44
  export async function main(argv) {
@@ -41,6 +47,8 @@ export async function main(argv) {
41
47
  switch (command) {
42
48
  case 'shot':
43
49
  return shot(rest);
50
+ case 'pull':
51
+ return pull(rest);
44
52
  case 'install-skill':
45
53
  return installSkill(rest);
46
54
  case '--version':
package/src/crypto.js CHANGED
@@ -20,3 +20,21 @@ export async function encryptNote(plaintext) {
20
20
  keyB64url: Buffer.from(keyBytes).toString('base64url'),
21
21
  };
22
22
  }
23
+
24
+ /**
25
+ * Decrypts a note fetched from the server. Mirrors the browser reader:
26
+ * the AES-256-GCM key comes from the URL #fragment (base64url) and never
27
+ * touches the server; the IV lives in the note's public metadata (base64).
28
+ *
29
+ * @param {ArrayBuffer|Uint8Array} ciphertext raw bytes from GET /{id}.blob
30
+ * @param {string} keyB64url 32-byte key, base64url, from the #fragment
31
+ * @param {string} ivB64 12-byte IV, base64, from meta.encryption.iv
32
+ * @returns {Promise<string>} the decrypted Markdown
33
+ */
34
+ export async function decryptNote(ciphertext, keyB64url, ivB64) {
35
+ const keyBytes = Buffer.from(keyB64url, 'base64url');
36
+ const iv = Buffer.from(ivB64, 'base64');
37
+ const key = await crypto.subtle.importKey('raw', keyBytes, 'AES-GCM', false, ['decrypt']);
38
+ const plaintext = await crypto.subtle.decrypt({ name: 'AES-GCM', iv }, key, ciphertext);
39
+ return new TextDecoder().decode(plaintext);
40
+ }
package/src/pull.js ADDED
@@ -0,0 +1,109 @@
1
+ import { decryptNote } from './crypto.js';
2
+
3
+ // Same id shape the Worker route accepts (10–14 url-safe chars).
4
+ const ID_RE = /^[A-Za-z0-9_-]{10,14}$/;
5
+
6
+ /**
7
+ * `slingit pull <url>` — fetch a published note and print its Markdown to stdout.
8
+ *
9
+ * The note id comes from the URL path and the AES key from the #fragment. The
10
+ * blob is fetched by id alone (public read, no token) exactly like the browser
11
+ * reader, so the key never reaches the server — the iron rule stays intact.
12
+ */
13
+ export async function pull(args) {
14
+ const { url } = parseArgs(args);
15
+ const { id, origin, key } = parseUrl(url);
16
+
17
+ const meta = await fetchMeta(origin, id);
18
+ const blob = await fetchBlob(origin, id);
19
+
20
+ let markdown;
21
+ if (meta.mode === 'public') {
22
+ // Public notes store plaintext Markdown — nothing to decrypt.
23
+ markdown = Buffer.from(blob).toString('utf8');
24
+ } else {
25
+ if (!key) {
26
+ throw new Error(
27
+ 'this note is encrypted but the link has no key after "#" — you need the full link (including the #fragment) to read it'
28
+ );
29
+ }
30
+ if (!meta.encryption?.iv) {
31
+ throw new Error('note metadata is missing encryption parameters — cannot decrypt');
32
+ }
33
+ try {
34
+ markdown = await decryptNote(blob, key, meta.encryption.iv);
35
+ } catch {
36
+ throw new Error(
37
+ 'could not decrypt the note — the key in the link is wrong or the content is corrupted'
38
+ );
39
+ }
40
+ }
41
+
42
+ process.stdout.write(markdown.endsWith('\n') ? markdown : `${markdown}\n`);
43
+ }
44
+
45
+ function parseArgs(args) {
46
+ let url = null;
47
+ for (const a of args) {
48
+ if (a.startsWith('-')) throw new Error(`unknown flag "${a}". See: slingit help`);
49
+ if (url) throw new Error('only one URL can be given');
50
+ url = a;
51
+ }
52
+ if (!url) throw new Error('usage: slingit pull <url>');
53
+ return { url };
54
+ }
55
+
56
+ function parseUrl(input) {
57
+ let url;
58
+ try {
59
+ url = new URL(input);
60
+ } catch {
61
+ throw new Error(`not a valid URL: ${input}`);
62
+ }
63
+ if (url.protocol !== 'https:' && url.protocol !== 'http:') {
64
+ throw new Error(`unsupported URL scheme "${url.protocol}" — expected http(s)`);
65
+ }
66
+ const segment = url.pathname.split('/').filter(Boolean).pop() || '';
67
+ const id = segment.replace(/\.(blob|json|raw)$/, '');
68
+ if (!ID_RE.test(id)) {
69
+ throw new Error(`could not find a note id in the URL: ${input}`);
70
+ }
71
+ // The key is the whole #fragment, matching the reader's location.hash.slice(1).
72
+ const key = url.hash ? url.hash.slice(1) : '';
73
+ return { id, origin: url.origin, key };
74
+ }
75
+
76
+ async function fetchMeta(origin, id) {
77
+ const res = await httpGet(`${origin}/${id}.json`);
78
+ assertNotExpired(res);
79
+ if (!res.ok) throw new Error(`server returned HTTP ${res.status} for the note metadata`);
80
+ try {
81
+ return await res.json();
82
+ } catch {
83
+ throw new Error('unexpected response from the server (invalid note metadata)');
84
+ }
85
+ }
86
+
87
+ async function fetchBlob(origin, id) {
88
+ const res = await httpGet(`${origin}/${id}.blob`);
89
+ assertNotExpired(res);
90
+ if (!res.ok) throw new Error(`server returned HTTP ${res.status} for the note content`);
91
+ return res.arrayBuffer();
92
+ }
93
+
94
+ function assertNotExpired(res) {
95
+ if (res.status === 410) {
96
+ throw new Error('this note has expired and is no longer available');
97
+ }
98
+ if (res.status === 404) {
99
+ throw new Error('note not found — the link may be wrong or the note has expired');
100
+ }
101
+ }
102
+
103
+ async function httpGet(target) {
104
+ try {
105
+ return await fetch(target);
106
+ } catch (err) {
107
+ throw new Error(`could not connect to ${new URL(target).origin} (${err.cause?.code || err.message})`);
108
+ }
109
+ }