@orta/attodo 0.0.0-stage → 0.1.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.
Files changed (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +87 -2
  3. package/dist/app/controller.js +240 -0
  4. package/dist/app/controller.js.map +1 -0
  5. package/dist/atproto/spaces.js +54 -0
  6. package/dist/atproto/spaces.js.map +1 -0
  7. package/dist/atproto/transport.js +208 -0
  8. package/dist/atproto/transport.js.map +1 -0
  9. package/dist/auth/oauth.js +115 -0
  10. package/dist/auth/oauth.js.map +1 -0
  11. package/dist/cli.js +201 -0
  12. package/dist/cli.js.map +1 -0
  13. package/dist/config.js +20 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/lexicons/at/todos/area.defs.js +28 -0
  16. package/dist/lexicons/at/todos/area.defs.js.map +1 -0
  17. package/dist/lexicons/at/todos/area.js +6 -0
  18. package/dist/lexicons/at/todos/area.js.map +1 -0
  19. package/dist/lexicons/at/todos/checklistItem.defs.js +28 -0
  20. package/dist/lexicons/at/todos/checklistItem.defs.js.map +1 -0
  21. package/dist/lexicons/at/todos/checklistItem.js +6 -0
  22. package/dist/lexicons/at/todos/checklistItem.js.map +1 -0
  23. package/dist/lexicons/at/todos/defs.defs.js +33 -0
  24. package/dist/lexicons/at/todos/defs.defs.js.map +1 -0
  25. package/dist/lexicons/at/todos/defs.js +5 -0
  26. package/dist/lexicons/at/todos/defs.js.map +1 -0
  27. package/dist/lexicons/at/todos/heading.defs.js +28 -0
  28. package/dist/lexicons/at/todos/heading.defs.js.map +1 -0
  29. package/dist/lexicons/at/todos/heading.js +6 -0
  30. package/dist/lexicons/at/todos/heading.js.map +1 -0
  31. package/dist/lexicons/at/todos/item.defs.js +30 -0
  32. package/dist/lexicons/at/todos/item.defs.js.map +1 -0
  33. package/dist/lexicons/at/todos/item.js +6 -0
  34. package/dist/lexicons/at/todos/item.js.map +1 -0
  35. package/dist/lexicons/at/todos/join.defs.js +23 -0
  36. package/dist/lexicons/at/todos/join.defs.js.map +1 -0
  37. package/dist/lexicons/at/todos/join.js +6 -0
  38. package/dist/lexicons/at/todos/join.js.map +1 -0
  39. package/dist/lexicons/at/todos/personalSpace.defs.js +19 -0
  40. package/dist/lexicons/at/todos/personalSpace.defs.js.map +1 -0
  41. package/dist/lexicons/at/todos/personalSpace.js +6 -0
  42. package/dist/lexicons/at/todos/personalSpace.js.map +1 -0
  43. package/dist/lexicons/at/todos/plan.defs.js +30 -0
  44. package/dist/lexicons/at/todos/plan.defs.js.map +1 -0
  45. package/dist/lexicons/at/todos/plan.js +6 -0
  46. package/dist/lexicons/at/todos/plan.js.map +1 -0
  47. package/dist/lexicons/at/todos/project.defs.js +28 -0
  48. package/dist/lexicons/at/todos/project.defs.js.map +1 -0
  49. package/dist/lexicons/at/todos/project.js +6 -0
  50. package/dist/lexicons/at/todos/project.js.map +1 -0
  51. package/dist/lexicons/at/todos/sharedSpace.defs.js +20 -0
  52. package/dist/lexicons/at/todos/sharedSpace.defs.js.map +1 -0
  53. package/dist/lexicons/at/todos/sharedSpace.js +6 -0
  54. package/dist/lexicons/at/todos/sharedSpace.js.map +1 -0
  55. package/dist/lexicons/at/todos/spaceInfo.defs.js +23 -0
  56. package/dist/lexicons/at/todos/spaceInfo.defs.js.map +1 -0
  57. package/dist/lexicons/at/todos/spaceInfo.js +6 -0
  58. package/dist/lexicons/at/todos/spaceInfo.js.map +1 -0
  59. package/dist/lexicons/at/todos/tag.defs.js +28 -0
  60. package/dist/lexicons/at/todos/tag.defs.js.map +1 -0
  61. package/dist/lexicons/at/todos/tag.js +6 -0
  62. package/dist/lexicons/at/todos/tag.js.map +1 -0
  63. package/dist/lexicons/at/todos.js +16 -0
  64. package/dist/lexicons/at/todos.js.map +1 -0
  65. package/dist/lexicons/at.js +5 -0
  66. package/dist/lexicons/at.js.map +1 -0
  67. package/dist/lexicons/index.js +5 -0
  68. package/dist/lexicons/index.js.map +1 -0
  69. package/dist/store.js +75 -0
  70. package/dist/store.js.map +1 -0
  71. package/dist/tui/App.js +231 -0
  72. package/dist/tui/App.js.map +1 -0
  73. package/package.json +54 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Orta Therox
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,88 @@
1
- # Temporary Holding Version
1
+ # attodo in the terminal
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A to-do app for your terminal that syncs through atproto: sign in with an Atmosphere account (your Bluesky handle works), and your to-dos live in your own repo, in a [permissioned space](https://atproto.com/guides/spaces). Shared lists come from the Atmosphere Groups you're in.
4
+
5
+ It runs attodo's sync engine: the Rust implementation in [`../rust`](../rust), compiled to WebAssembly and published as [`attodo-sync`](../rust/attodo-wasm/npm). Every attodo app uses the same engine.
6
+
7
+ ## Use it
8
+
9
+ Needs Node 22 or later (tested on 26).
10
+
11
+ ```sh
12
+ npm install -g @orta/attodo
13
+ attodo --demo # try it without an account
14
+ ```
15
+
16
+ From a checkout, at the repository root (building the engine needs Rust and [wasm-pack](https://crates.io/crates/wasm-pack)):
17
+
18
+ ```sh
19
+ npm install
20
+ npm run build # the engine, then the CLI
21
+ node node/dist/cli.js # or `npm start -w @orta/attodo -- --demo`
22
+ ```
23
+
24
+ | Command | What it does |
25
+ | --- | --- |
26
+ | `attodo` | Opens the app. Signs you in first if needed. |
27
+ | `attodo login <handle>` | Signs in through your PDS's OAuth page in the browser. The CLI is a loopback client, so nothing has to be registered. |
28
+ | `attodo logout` | Signs out. |
29
+ | `attodo sync` | Syncs once and reports problems. |
30
+ | `attodo list [today]` | Syncs, then prints a list: `inbox`, `today`, `evening`, `upcoming`, `anytime`, `someday`, `logbook` or `trash`. |
31
+ | `attodo add <title> [--when today]` | Adds a to-do. `--when` is `inbox` (the default), `today`, `evening`, `tomorrow`, `anytime` or `someday`. |
32
+ | `attodo --demo` | The full app on an in-memory network with a second, simulated member. No account needed. |
33
+
34
+ In the app:
35
+
36
+ | Key | |
37
+ | --- | --- |
38
+ | `←` `→`, `h` `l`, `Tab` | switch list (Inbox, Today, Upcoming, Anytime, Someday, Logbook, Trash, then your shared lists) |
39
+ | `↑` `↓`, `j` `k` | move |
40
+ | `n` | new to-do in the current list |
41
+ | `Enter`, `Space`, `x` | complete, or reopen |
42
+ | `e` | edit the title |
43
+ | `t` `v` `m` `a` `s` `i` | schedule: today, this evening, tomorrow, anytime, someday, inbox |
44
+ | `d` | move to the Trash; in the Trash, delete for good (asks first) |
45
+ | `u` | put back from the Trash |
46
+ | `r` | sync now |
47
+ | `?` | help |
48
+ | `q` | quit |
49
+
50
+ The app syncs when it opens, every 30 seconds, and a moment after each edit. It works offline: edits are kept and sent once the hosts can be reached. Scheduling a to-do in a shared list writes to your private plan for it (SPEC §4.9), so it only changes your own Today.
51
+
52
+ Files live in `$ATTODO_HOME`, else `$XDG_CONFIG_HOME/attodo`, else `~/.config/attodo`. They are readable only by you:
53
+
54
+ - `account.json`: the signed-in account;
55
+ - `oauth-sessions.json`, `oauth-state.json`: OAuth tokens and keys;
56
+ - `devices/<did>.json`: this device's replica of your spaces, with changes not yet sent.
57
+
58
+ ## How it's built
59
+
60
+ | Path | What it is |
61
+ | --- | --- |
62
+ | `attodo-sync` (npm) | The sync engine, from `rust/attodo-sync` through `rust/attodo-wasm`. It merges, syncs, verifies, builds the lists and saves the device. It has no I/O and reaches the hosts through a `Transport`. It also provides the in-memory network that `--demo` and the tests use. |
63
+ | `src/atproto/` | The real `Transport`, over `@atproto/lex-space`. It also finds your spaces and creates the personal one. |
64
+ | `src/auth/oauth.ts` | OAuth login as a loopback client (`@atproto/oauth-client-node`). |
65
+ | `src/app/controller.ts` | The app around the engine: the sync loop, saving, and status for the UI. |
66
+ | `src/tui/App.tsx` | The terminal UI (Ink). |
67
+
68
+ Syncs run one at a time. Edits apply immediately, even while a sync is waiting on the network. The engine holds the device only between its awaits and keeps what was edited meanwhile. `rust/attodo-sync/tests/interleaving.rs` tests that, and `test/controller.test.ts` does too, through the WebAssembly boundary.
69
+
70
+ ## Testing
71
+
72
+ ```sh
73
+ npm test # from the repository root, or here
74
+ ```
75
+
76
+ | Test | What it covers |
77
+ | --- | --- |
78
+ | `test/controller.test.ts` | The app over the engine's simulated network: two accounts, personal and shared lists, saving and loading, an unreachable host, edits made while a write is on its way, refused edits |
79
+ | `test/tui.test.tsx` | The TUI, driven by keystrokes through a fake terminal |
80
+
81
+ The engine's own tests, proofs and model checking are in [`../rust`](../rust) ([VERIFICATION.md](../rust/VERIFICATION.md)).
82
+
83
+ ## Not yet
84
+
85
+ - Areas, projects, headings, checklists and tags show up through the lists, but the app can't create or edit them yet.
86
+ - Repeating to-dos (SPEC §7) are not implemented, in the engine either.
87
+ - Creating shared lists and joining groups happen in Atmosphere Groups apps. The CLI shows the shared lists you can already read.
88
+ - Permissioned spaces are new. A PDS that doesn't support them yet shows an error at sign-in or on the first sync, and `--demo` is the way to try the app.
@@ -0,0 +1,240 @@
1
+ /**
2
+ * The app around the sync engine: one device for the signed-in account, its
3
+ * spaces, a sync loop, saving to disk, and the to-do operations the TUI
4
+ * offers. The engine is `attodo-sync`, the Rust engine compiled to
5
+ * WebAssembly; everything about to-dos (what "complete" or "today" means,
6
+ * what each list holds) is decided there, so every app on it agrees.
7
+ *
8
+ * Concurrency: syncs run one at a time. Edits apply at once, even while a
9
+ * sync is waiting on the network: the engine holds the device only between
10
+ * its awaits and keeps what was edited meanwhile
11
+ * (`rust/attodo-sync/tests/interleaving.rs`).
12
+ */
13
+ import { randomBytes, randomInt } from 'node:crypto';
14
+ import { EventEmitter } from 'node:events';
15
+ import { Device, } from 'attodo-sync';
16
+ const pad = (n, width = 2) => String(n).padStart(width, '0');
17
+ /** The local date of `d`, `YYYY-MM-DD`. */
18
+ export function localToday(d = new Date()) {
19
+ return `${pad(d.getFullYear(), 4)}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
20
+ }
21
+ /** `date` (`YYYY-MM-DD`) moved by `n` days. */
22
+ export function addDays(date, n) {
23
+ const [y, m, d] = date.split('-').map(Number);
24
+ const t = new Date(0);
25
+ t.setUTCFullYear(y, m - 1, d + n);
26
+ return `${pad(t.getUTCFullYear(), 4)}-${pad(t.getUTCMonth() + 1)}-${pad(t.getUTCDate())}`;
27
+ }
28
+ /** Whether the engine refused an edit; `code` says why (`ReadOnly`, `TooLarge`…). */
29
+ export function isEditFailure(e) {
30
+ return e instanceof Error && e.name === 'EditFailure';
31
+ }
32
+ function isSyncFailure(e) {
33
+ return e instanceof Error && e.name === 'SyncFailure';
34
+ }
35
+ export class Controller extends EventEmitter {
36
+ opts;
37
+ device;
38
+ status = { syncing: false, errors: new Map(), pending: 0, rejected: [] };
39
+ syncing = Promise.resolve();
40
+ pollTimer;
41
+ flushTimer;
42
+ saveTimer;
43
+ saving = Promise.resolve();
44
+ closed = false;
45
+ constructor(opts, device) {
46
+ super();
47
+ this.opts = opts;
48
+ this.device = device;
49
+ this.status.pending = device.pending();
50
+ }
51
+ static async open(opts) {
52
+ const saved = await opts.storage?.load();
53
+ const device = saved && saved.me === opts.me ? Device.fromJson(saved) : new Device(opts.me, randomInt(1024), randomBytes(8).readBigUInt64BE());
54
+ return new Controller(opts, device);
55
+ }
56
+ get me() {
57
+ return this.device.me;
58
+ }
59
+ nowMicros() {
60
+ return this.opts.now?.() ?? Date.now() * 1000;
61
+ }
62
+ today() {
63
+ return this.opts.today?.() ?? localToday();
64
+ }
65
+ /** Starts syncing: now, then every `pollMs`. */
66
+ start() {
67
+ const first = this.sync();
68
+ const every = this.opts.pollMs ?? 30_000;
69
+ if (every > 0)
70
+ this.pollTimer = setInterval(() => void this.sync(), every);
71
+ return first;
72
+ }
73
+ async close() {
74
+ this.closed = true;
75
+ clearInterval(this.pollTimer);
76
+ clearTimeout(this.flushTimer);
77
+ await this.syncing;
78
+ clearTimeout(this.saveTimer);
79
+ await this.save();
80
+ }
81
+ // ---------------------------------------------------------------- spaces
82
+ personalSpace() {
83
+ return this.device.personalSpace();
84
+ }
85
+ spaces() {
86
+ return this.device.spaces().map((s) => {
87
+ const error = this.status.errors.get(s.space);
88
+ return error ? { ...s, error } : s;
89
+ });
90
+ }
91
+ /** "Personal", a shared list's title (§3.4), or else its key. */
92
+ spaceTitle(space) {
93
+ return this.device.spaceTitle(space);
94
+ }
95
+ async discover() {
96
+ const found = await this.opts.discover();
97
+ this.device.addSpace(found.personal, 'personal');
98
+ for (const s of found.shared)
99
+ this.device.addSpace(s, 'shared');
100
+ }
101
+ // ---------------------------------------------------------------- sync
102
+ /** One round: find spaces, then sync each. Rounds never overlap. */
103
+ sync() {
104
+ const round = this.syncing.then(() => this.round());
105
+ this.syncing = round.catch(() => { });
106
+ return round;
107
+ }
108
+ async round() {
109
+ if (this.closed)
110
+ return;
111
+ this.status.syncing = true;
112
+ this.emit('status');
113
+ try {
114
+ try {
115
+ await this.discover();
116
+ this.status.errors.delete('discover');
117
+ }
118
+ catch (e) {
119
+ // Offline: sync the spaces already known.
120
+ this.status.errors.set('discover', e instanceof Error ? e.message : String(e));
121
+ }
122
+ for (const { space } of this.device.spaces()) {
123
+ try {
124
+ this.report(space, await this.device.syncSpace(this.opts.transport, space, this.nowMicros()));
125
+ }
126
+ catch (e) {
127
+ if (!isSyncFailure(e))
128
+ throw e;
129
+ this.status.errors.set(space, e.message);
130
+ }
131
+ this.emit('change');
132
+ }
133
+ this.status.lastSyncMs = Date.now();
134
+ }
135
+ finally {
136
+ this.status.syncing = false;
137
+ this.status.pending = this.device.pending();
138
+ this.emit('status');
139
+ this.scheduleSave();
140
+ }
141
+ }
142
+ report(space, { pull, flush }) {
143
+ const problems = [];
144
+ for (const f of pull.failed)
145
+ problems.push(`${f.repo}: ${f.error.message}`);
146
+ if (flush.stopped)
147
+ problems.push(flush.stopped.message);
148
+ if (flush.oversized.length)
149
+ problems.push(`${flush.oversized.length} record(s) too large to save`);
150
+ for (const r of flush.rejected)
151
+ this.status.rejected.push(`${r.title ?? r.path.rkey}: ${r.error}`);
152
+ if (problems.length)
153
+ this.status.errors.set(space, problems.join('; '));
154
+ else
155
+ this.status.errors.delete(space);
156
+ }
157
+ // ---------------------------------------------------------------- saving
158
+ scheduleSave() {
159
+ if (!this.opts.storage)
160
+ return;
161
+ clearTimeout(this.saveTimer);
162
+ this.saveTimer = setTimeout(() => void this.save(), 250);
163
+ }
164
+ /** Writes the device to storage; saves never overlap, and each writes the latest state. */
165
+ save() {
166
+ const storage = this.opts.storage;
167
+ if (!storage)
168
+ return Promise.resolve();
169
+ const next = this.saving.then(() => storage.save(this.device.toJson()));
170
+ this.saving = next.catch(() => { });
171
+ return next;
172
+ }
173
+ /** After an edit: show it, save it, and flush it soon. */
174
+ edited() {
175
+ this.status.pending = this.device.pending();
176
+ this.emit('change');
177
+ this.emit('status');
178
+ this.scheduleSave();
179
+ if (this.closed)
180
+ return;
181
+ clearTimeout(this.flushTimer);
182
+ this.flushTimer = setTimeout(() => void this.sync(), this.opts.flushDelayMs ?? 1500);
183
+ }
184
+ // ---------------------------------------------------------------- reading
185
+ lists() {
186
+ return this.device.lists(this.today());
187
+ }
188
+ /** Every active to-do and project of one space, for its own list. */
189
+ spaceList(space) {
190
+ return this.device.spaceList(space);
191
+ }
192
+ /** The rows of a list, read in one pass over the replica. */
193
+ rows(listed) {
194
+ return this.device.rows(listed, this.today());
195
+ }
196
+ // ---------------------------------------------------------------- editing
197
+ edit(f) {
198
+ const out = f(this.nowMicros());
199
+ this.edited();
200
+ return out;
201
+ }
202
+ /**
203
+ * Adds a to-do: to the personal space, or a shared list. `inbox` only
204
+ * means something in the personal space; a shared to-do starts `anytime`.
205
+ */
206
+ add(title, when, space) {
207
+ const target = space ?? this.personalSpace();
208
+ if (target === undefined) {
209
+ // Before the first sync has found the personal space.
210
+ throw Object.assign(new Error('Your personal space has not been found yet.'), { name: 'EditFailure', code: 'UnknownSpace' });
211
+ }
212
+ return this.edit((now) => this.device.addTodo(target, title, when, this.today(), now));
213
+ }
214
+ setTitle(ref, title) {
215
+ this.edit((now) => this.device.setTitle(ref, title, now));
216
+ }
217
+ setNotes(ref, notes) {
218
+ this.edit((now) => this.device.setNotes(ref, notes, now));
219
+ }
220
+ /** Completes an open to-do, or reopens a closed one. */
221
+ toggleDone(ref) {
222
+ this.edit((now) => this.device.toggleDone(ref, now));
223
+ }
224
+ /**
225
+ * When to do something (§6.1): an object's own schedule in the personal
226
+ * space; in a shared one, the user's plan, so it changes nothing for the
227
+ * others.
228
+ */
229
+ schedule(ref, when) {
230
+ this.edit((now) => this.device.schedule(ref, when, this.today(), now));
231
+ }
232
+ trash(ref, trashed = true) {
233
+ this.edit((now) => this.device.trash(ref, trashed, now));
234
+ }
235
+ /** Deletes for good (§5.6): every app stops showing it. */
236
+ deleteForever(ref) {
237
+ this.edit((now) => this.device.deleteForever(ref, now));
238
+ }
239
+ }
240
+ //# sourceMappingURL=controller.js.map
@@ -0,0 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,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;IACtD,CAAC;IAED;;;;OAIG;IACH,QAAQ,CAAC,GAAc,EAAE,IAAU;QACjC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,CAAC,CAAA;IACxE,CAAC;IAED,KAAK,CAAC,GAAc,EAAE,OAAO,GAAG,IAAI;QAClC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,CAAA;IAC1D,CAAC;IAED,2DAA2D;IAC3D,aAAa,CAAC,GAAc;QAC1B,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;IACzD,CAAC;CACF"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Finding the user's spaces (SPEC §3.3): the personal space, created if
3
+ * missing, and the shared lists they've joined.
4
+ */
5
+ import { SpaceClient, lexicons as spaceLexicons, personalspace } from '@atproto/lex-space';
6
+ import { xrpc, XrpcResponseError } from '@atproto/lex-client';
7
+ import * as lexicons from '../lexicons/index.js';
8
+ /** The space types (SPEC §3). */
9
+ export const PERSONAL_SPACE = 'at.todos.personalSpace';
10
+ export const SHARED_SPACE = 'at.todos.sharedSpace';
11
+ const listSpaces = spaceLexicons.com.atproto.space.listSpaces;
12
+ export function personalSpaceRef(did) {
13
+ return `at:space/${did}/${PERSONAL_SPACE}/self`;
14
+ }
15
+ /** Every space of `spaceType` the account owns or has written to. */
16
+ export async function listSpacesOfType(agent, spaceType) {
17
+ const out = [];
18
+ let cursor;
19
+ for (;;) {
20
+ const { body } = await xrpc(agent, listSpaces, {
21
+ params: { spaceType: spaceType, limit: 100, ...(cursor ? { cursor } : {}) },
22
+ });
23
+ for (const s of body.spaces)
24
+ out.push(s.space);
25
+ if (!body.cursor || body.cursor === cursor || body.spaces.length === 0)
26
+ return out;
27
+ cursor = body.cursor;
28
+ }
29
+ }
30
+ /**
31
+ * The personal space, created if the account has none. `SpaceAlreadyExists`
32
+ * counts as success: another device may have won the race (§3.1).
33
+ */
34
+ export async function ensurePersonalSpace(agent) {
35
+ const ref = personalSpaceRef(agent.did);
36
+ const found = await listSpacesOfType(agent, PERSONAL_SPACE);
37
+ if (found.includes(ref))
38
+ return ref;
39
+ try {
40
+ await SpaceClient.createSpace(agent, lexicons.at.todos.personalSpace, {
41
+ policy: personalspace.policy.$build({}),
42
+ });
43
+ }
44
+ catch (e) {
45
+ if (!(e instanceof XrpcResponseError && e.error === 'SpaceAlreadyExists'))
46
+ throw e;
47
+ }
48
+ return ref;
49
+ }
50
+ /** The shared lists the user has joined (§3.3). Groups' members spaces are not watched yet. */
51
+ export async function joinedSharedSpaces(agent) {
52
+ return listSpacesOfType(agent, SHARED_SPACE);
53
+ }
54
+ //# sourceMappingURL=spaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spaces.js","sourceRoot":"","sources":["../../src/atproto/spaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,WAAW,EAAE,QAAQ,IAAI,aAAa,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAC1F,OAAO,EAAE,IAAI,EAAE,iBAAiB,EAAqB,MAAM,qBAAqB,CAAA;AAChF,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAEhD,iCAAiC;AACjC,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAA;AACtD,MAAM,CAAC,MAAM,YAAY,GAAG,sBAAsB,CAAA;AAElD,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAA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,CAAC,EAAE,CAAC,KAAK,CAAC,aAAa,EAAE;YACpE,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;SACxC,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,IAAI,CAAC,CAAC,CAAC,YAAY,iBAAiB,IAAI,CAAC,CAAC,KAAK,KAAK,oBAAoB,CAAC;YAAE,MAAM,CAAC,CAAA;IACpF,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED,+FAA+F;AAC/F,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,KAAmB;IAC1D,OAAO,gBAAgB,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;AAC9C,CAAC"}
@@ -0,0 +1,208 @@
1
+ /**
2
+ * The engine's `Transport` over `@atproto/lex-space`. Reads of other accounts'
3
+ * repos go to their PDSes with a space credential and are checked against
4
+ * their hosts' MACs by `SpaceReader`; the engine then verifies op logs and
5
+ * snapshots against those commits itself. Writes go to the user's PDS
6
+ * through their OAuth session.
7
+ *
8
+ * The engine takes plain JSON: record values in their JSON form
9
+ * (`lexToJson`), TIDs and CIDs as strings, and the commit's data as
10
+ * `{ $bytes }`. It checks everything it's sent; a value it can't read fails
11
+ * the call as an invalid response.
12
+ */
13
+ import { SpaceClient, SpaceRepoVerificationError } from '@atproto/lex-space';
14
+ import { XrpcFetchError, XrpcInvalidResponseError, XrpcResponseError } from '@atproto/lex-client';
15
+ import { isValidTid } from '@atproto/syntax';
16
+ import { parseCidSafe } from '@atproto/lex-data';
17
+ import { jsonToLex, lexToJson } from '@atproto/lex-json';
18
+ import * as lexicons from '../lexicons/index.js';
19
+ import { PERSONAL_SPACE, SHARED_SPACE } from './spaces.js';
20
+ const WRITERS_PAGE = 100;
21
+ const OPS_PAGE = 100;
22
+ function rateLimitOf(headers, now = Date.now()) {
23
+ if (!headers)
24
+ return undefined;
25
+ const limit = Number(headers.get('ratelimit-limit'));
26
+ const remaining = Number(headers.get('ratelimit-remaining'));
27
+ const reset = Number(headers.get('ratelimit-reset'));
28
+ if (!headers.has('ratelimit-remaining') || !Number.isFinite(limit) || !Number.isFinite(remaining))
29
+ return undefined;
30
+ // `RateLimit-Reset` is epoch seconds on the reference PDS.
31
+ return { limit, remaining, resetMs: Number.isFinite(reset) && reset > 0 ? reset * 1000 : now };
32
+ }
33
+ function retryAfterMs(headers, now = Date.now()) {
34
+ const after = headers.get('retry-after');
35
+ if (after) {
36
+ const ms = /^\s*\d+\s*$/.test(after) ? Number(after) * 1000 : new Date(after).getTime() - now;
37
+ if (Number.isFinite(ms) && ms > 0)
38
+ return ms;
39
+ }
40
+ const reset = Number(headers.get('ratelimit-reset'));
41
+ if (Number.isFinite(reset) && reset * 1000 > now)
42
+ return reset * 1000 - now;
43
+ return 60_000;
44
+ }
45
+ /** Classifies whatever a lex-space call threw. */
46
+ export function toTransportError(e) {
47
+ if (e instanceof XrpcResponseError) {
48
+ if (e.status === 429)
49
+ return { kind: 'rateLimited', retryAfterMs: retryAfterMs(e.headers) };
50
+ if (e.status >= 500)
51
+ return { kind: 'server', status: e.status, message: e.message };
52
+ return { kind: 'xrpc', status: e.status, error: e.error, message: e.message };
53
+ }
54
+ if (e instanceof XrpcFetchError)
55
+ return { kind: 'network', message: e.message };
56
+ // A response that doesn't parse, or doesn't match its MAC: try again later.
57
+ if (e instanceof XrpcInvalidResponseError)
58
+ return { kind: 'server', status: 502, message: e.message };
59
+ if (e instanceof SpaceRepoVerificationError)
60
+ return { kind: 'server', status: 502, message: e.message };
61
+ if (e instanceof Error && (e.name === 'AbortError' || e.name === 'TimeoutError'))
62
+ return { kind: 'network', message: e.message };
63
+ // Credential problems surface as XRPC errors from the PDS; anything else is unexpected.
64
+ return { kind: 'network', message: e instanceof Error ? e.message : String(e) };
65
+ }
66
+ async function call(f) {
67
+ try {
68
+ return { ok: true, value: await f() };
69
+ }
70
+ catch (e) {
71
+ return { ok: false, error: toTransportError(e) };
72
+ }
73
+ }
74
+ /**
75
+ * CIDs as the engine compares them: the canonical string of the parsed CID
76
+ * (CIDv1 in base32), so a host writing another multibase still matches. A
77
+ * string that doesn't parse is kept, and fails verification.
78
+ */
79
+ export function canonicalCid(s) {
80
+ return parseCidSafe(s)?.toString() ?? s;
81
+ }
82
+ const json = (v) => lexToJson(v);
83
+ function commitOf(c) {
84
+ return { ver: c.ver, repo: c.repo, space: c.space, rev: c.rev, data: json(c.data) };
85
+ }
86
+ function spaceTypeOf(space) {
87
+ const type = space.split('/')[2];
88
+ if (type === PERSONAL_SPACE)
89
+ return lexicons.at.todos.personalSpace;
90
+ if (type === SHARED_SPACE)
91
+ return lexicons.at.todos.sharedSpace;
92
+ throw new TypeError(`not an attodo space: ${space}`);
93
+ }
94
+ export class LexSpaceTransport {
95
+ agent;
96
+ fetch;
97
+ clients = new Map();
98
+ constructor(agent, fetch) {
99
+ this.agent = agent;
100
+ this.fetch = fetch;
101
+ }
102
+ /** One client per space, so its space credential is reused. */
103
+ client(space) {
104
+ let c = this.clients.get(space);
105
+ if (!c) {
106
+ const opts = { agent: this.agent };
107
+ if (this.fetch)
108
+ opts.fetch = this.fetch;
109
+ const ns = spaceTypeOf(space);
110
+ const ref = space;
111
+ // Two calls, so each is typed by its own space type.
112
+ c = (ns === lexicons.at.todos.personalSpace
113
+ ? SpaceClient.openSpace(lexicons.at.todos.personalSpace, ref, opts)
114
+ : SpaceClient.openSpace(lexicons.at.todos.sharedSpace, ref, opts));
115
+ this.clients.set(space, c);
116
+ }
117
+ return c;
118
+ }
119
+ listWriters(space, since, cursor) {
120
+ return call(async () => {
121
+ // The cursor is a space revision: resume after the later of the two
122
+ // (TIDs sort as strings).
123
+ const c = cursor && isValidTid(cursor) ? cursor : undefined;
124
+ const after = since !== undefined && c !== undefined ? (since > c ? since : c) : (since ?? c);
125
+ const { body } = await this.client(space).listWriters({
126
+ limit: WRITERS_PAGE,
127
+ ...(after !== undefined ? { cursor: after } : {}),
128
+ });
129
+ const entries = [];
130
+ for (const r of body.repos) {
131
+ if (r.$type === 'com.atproto.space.defs#repoWrite') {
132
+ entries.push({ repo: r.repo, spaceRev: r.spaceRev, repoRev: r.repoRev ?? '' });
133
+ }
134
+ else if (r.$type === 'com.atproto.space.defs#repoRemoved') {
135
+ entries.push({ repo: r.repo, spaceRev: r.spaceRev });
136
+ }
137
+ // Entries of a kind this version doesn't know are skipped.
138
+ }
139
+ return body.cursor ? { entries, cursor: body.cursor } : { entries };
140
+ });
141
+ }
142
+ listRepoOps(space, repo, since, cursor) {
143
+ return call(async () => {
144
+ const { body } = await this.client(space).listRepoOps({
145
+ repo: repo,
146
+ since,
147
+ limit: OPS_PAGE,
148
+ ...(cursor ? { cursor } : {}),
149
+ });
150
+ const ops = body.ops.map((o) => {
151
+ const op = { rev: o.rev, path: { collection: o.collection, rkey: o.rkey } };
152
+ if (o.cid)
153
+ op.cid = canonicalCid(o.cid);
154
+ if (o.prev)
155
+ op.prev = canonicalCid(o.prev);
156
+ if (o.value !== undefined)
157
+ op.value = json(o.value);
158
+ return op;
159
+ });
160
+ const page = { ops, commit: commitOf(body.commit) };
161
+ if (body.cursor)
162
+ page.cursor = body.cursor;
163
+ return page;
164
+ });
165
+ }
166
+ getRecord(space, repo, path) {
167
+ return call(async () => {
168
+ try {
169
+ const { body } = await this.client(space).getRecord(path.collection, path.rkey, { repo: repo });
170
+ return { cid: canonicalCid(body.cid), value: json(body.value) };
171
+ }
172
+ catch (e) {
173
+ if (e instanceof XrpcResponseError && e.error === 'RecordNotFound')
174
+ return undefined;
175
+ throw e;
176
+ }
177
+ });
178
+ }
179
+ getSnapshot(space, repo) {
180
+ return call(async () => {
181
+ const snap = await this.client(space).getRepoSnapshot({ repo: repo });
182
+ return {
183
+ commit: commitOf(snap.commit),
184
+ records: snap.records.map((r) => ({
185
+ path: { collection: r.collection, rkey: r.rkey },
186
+ cid: canonicalCid(r.cid.toString()),
187
+ value: json(r.record),
188
+ })),
189
+ };
190
+ });
191
+ }
192
+ applyWrites(space, writes) {
193
+ return call(async () => {
194
+ // Written as built: the high-water copy keeps other apps' data, which
195
+ // the typed helper's client-side validation might reject.
196
+ const ops = writes.map((w) => {
197
+ const base = { collection: w.path.collection, rkey: w.path.rkey };
198
+ if (w.action === 'delete')
199
+ return { $type: 'com.atproto.space.applyWrites#delete', ...base };
200
+ return { $type: `com.atproto.space.applyWrites#${w.action}`, ...base, value: jsonToLex(w.value) };
201
+ });
202
+ const res = await this.client(space).applyWrites(() => ops);
203
+ const rateLimit = rateLimitOf(res.headers);
204
+ return rateLimit ? { rateLimit } : {};
205
+ });
206
+ }
207
+ }
208
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/atproto/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,iBAAiB,EAAqB,MAAM,qBAAqB,CAAA;AAEpH,OAAO,EAAE,UAAU,EAAuB,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,YAAY,EAAiB,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAiBxD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1D,MAAM,YAAY,GAAG,GAAG,CAAA;AACxB,MAAM,QAAQ,GAAG,GAAG,CAAA;AAEpB,SAAS,WAAW,CAAC,OAA4B,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;IACjE,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAA;IAC9B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAA;IACpD,MAA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