Skip to content

Local API and recent files shared across machines - #3

Merged
itrycodinganditsbad merged 9 commits into
mainfrom
m4-local-api
Oct 18, 2026
Merged

itrycodinganditsbad merged 9 commits into
mainfrom
m4-local-api

Conversation

@itrycodinganditsbad

Copy link
Copy Markdown
Owner

What you get

  • One sign-in per machine. The agent now serves a small API on 127.0.0.1 (random port, token in an owner-only local-api.json). Apps and the launcher sign in, sign out and read status through it, even while run is signed out. They never talk to the server themselves.
  • Recent files that follow you. Each app has one recents list per account, shared through the server's new live service (/api/v1/live). It works offline and catches up when the server is back. craft-cloud-agent recents <app> shows a list on the command line.
  • craft-cloud-app, the small crate apps and the launcher link: no async, no TLS, no Loro. connect and status give up after about 2 s, and a recents watch reconnects on its own.

Server

  • Each live document has an update log, numbered without gaps under a row lock. Catch-up is by number, and an update is stored before it is acked.
  • Limits: 16 MiB per document, at most 64 documents holding updates per account, and 1,024 in all. Over a limit, the answer is quota_exceeded, and the machines keep their recents locally.
  • craft-cloud-server live reset-doc <user> <app> empties one log. Every machine then sends up what the log lacks. File sync isn't affected.

New crates and licences

Loro (the CRDT behind recents) and its dependencies. Four crates are allowed by name: xxhash-rust (BSL-1.0), and im, bitmaps and sized-chunks (MPL-2.0, used unmodified). Every other licence rule is unchanged.

Runs for the first time in CI

  • Postgres: migration 0003, the row lock that numbers appends, the quota and the account caps, live_spaces with ON CONFLICT.
  • Windows: a data folder outside %LOCALAPPDATA% is refused, so the token isn't left readable by others.

Testing

  • cargo xtask ci passes locally (fmt, licences, clippy, all tests).
  • Simulations: sync engine with 16,000 seeds, with and without crashes; network with 5,000 seeds; recents with 10,000 seeds, plus 1,000 after the last fixes.
  • The recents tests cover a server restore, reset-doc, a crash mid-push, an unreadable document file and a Loro panic. An acked add is never lost.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RC1oqfy9kZznj94RjMojyz

itrycodinganditsbad and others added 9 commits October 18, 2026 14:27
…p; Loro's licences by name

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RC1oqfy9kZznj94RjMojyz
…-out, quota, reset-doc

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RC1oqfy9kZznj94RjMojyz
…e live service

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RC1oqfy9kZznj94RjMojyz
…hat list, keeps the link

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RC1oqfy9kZznj94RjMojyz
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RC1oqfy9kZznj94RjMojyz
…te at the cap

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RC1oqfy9kZznj94RjMojyz
…folder too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RC1oqfy9kZznj94RjMojyz
@itrycodinganditsbad
itrycodinganditsbad merged commit e22c1c8 into main Oct 18, 2026
3 checks passed
@itrycodinganditsbad
itrycodinganditsbad deleted the m4-local-api branch October 21, 2026 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant