feat(workspace): record workspace sync state and publish changes to clients

Merged
SA
2mo ago
+1507-19

Issue for this PR

No separate issue (feature PR). Companion change in the IDE extension consumes the new route and event.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Workspace skills re-sync on each turn (5-minute interval) and memory loads per session, but nothing recorded when those checks ran or what they changed. The TUI sidebar could show "skills synced Xm ago" from a marker file. An IDE extension running serve could show nothing, and had no way to learn that a workspace had changed in SaaS short of re-running /workspace refresh.

This adds a small per-project sync state and exposes it:

  • altimate/workspace/sync-state.ts. One record per synced entity kind (skills, memory):
    • Fields: last checked, last changed, count, ok/error, and what the last change added, removed or updated, by label.
    • Storage: persisted under the state dir, because the TUI sidebar (main thread) and the per-turn syncs (server worker) share no module state. This is the same reason lastSuccessfulSyncAt reads a marker from disk.
    • Diffing: generic over {id: {label, version}}, so a future kind gets the same metadata by recording its items.
  • Writers. syncSkills (from the list it read, minus skills it could not install) and memory's commitLoad (hydrate and refresh) record from their existing paths. There are no new timers.
    • The first check for a workspace is a baseline, not a change, so the whole workspace isn't announced as "added".
    • A failed check keeps the last known items.
  • altimate.workspace.sync.changed bus event. Published only when a check found a difference, or when a kind's error state changed (a new problem, a different problem, or recovery). Unchanged checks publish nothing.
  • GET /altimate/workspace/status. Returns the recorded state for the request's workspace, resolved through resolveBindingOutcome, so it is pin-aware. It is behind the same refusal gate as the other workspace routes.
  • TUI sidebar. Gains "memory loaded Xm ago" from the same state.

Recording never fails a sync: the import is guarded, writes are chained per file, and a publish without an instance is logged and dropped.

How did you verify your code works?

  • bun run typecheck: clean.
  • New: test/altimate/workspace/sync-state.test.ts (10). It covers the diff, the baseline, publishing only on change, errors published once with last items kept and recovery published, kinds recorded independently, a rebind starting over, and a publish failure not failing the record.
  • Extended:
    • skill-sync.test.ts: added, updated, failed list, and an uninstallable skill. 126 pass.
    • memory-sync.test.ts: a per-project diff by title, and unbound records nothing. 134 pass.
    • altimate-workspace-routes.test.ts: bound, unbound, kill switch, browser origin. 25 pass.
  • Broader suites (test/altimate/workspace, test/server, test/cli, test/session): 3494 pass. The 8 failures also fail on a clean main with the same names (httpapi-mcp and httpapi-experimental timeouts, two prompt.test.ts cases).
  • End to end. I built a linux-arm64 binary, ran it as the extension's serve in code-server against a local backend, and attached skills to the workspace through the API:
    • The status route recorded a baseline, then added: ["creating-dbt-models"].
    • The event reached the extension over /event.

Screenshots / recordings

Not a UI change in this repo apart from the sidebar line. The extension PR has screenshots of the consumer.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

๐Ÿค– Generated with Claude Code


Summary by cubic

Tracks when workspace skills and memory were last checked and what changed, so the TUI sidebar and the IDE extension can show sync status without re-running refresh.

  • Adds per-project sync state (last checked, last changed, item count, errors, and what the last change added, removed, or updated), persisted in owner-only files โ€” one per entity kind, so skill and memory writers in separate threads or processes never overwrite each other.
  • Records are scoped to the account and the read time captured before the check: a late result from a previous binding, a record written under another account, or one that started reading before the stored record was made is dropped, and the first check for a rebound workspace or a new account is a fresh baseline.
  • Skill syncs and memory loads record from their existing paths; memory items are versioned by content as well as the mirror timestamp, so a web edit that keeps the timestamp still counts as changed.
  • The sidebar's "memory loaded" reads the last successful load; state is cleared when memory is turned off, the project is unlinked, or the skill snapshot is taken out of service.
  • Publishes altimate.workspace.sync.changed only when a check finds a difference or the error state changes, including recovery; recording and publishing never fail a sync.
  • Adds GET /altimate/workspace/status, returning the recorded state for the bound workspace โ€” including a stale flag when the binding is last-known โ€” and shows "memory loaded Xm ago" in the TUI sidebar.

Testing

  • Adds unit tests for diffing, baselines, event publishing, error handling, account and read-time fencing, rebind/relink races, file modes, and independent kinds, plus route and integration coverage for skill sync, memory sync, and the status endpoint.

Summary by CodeRabbit

  • New Features
    • Workspace status now tracks skill and memory sync results, including added, removed, and updated items, check times, and sync errors.
    • The workspace sidebar can show how recently memory was loaded.
    • A workspace status endpoint provides the current binding status and recorded sync details for bound workspaces.
    • Sync details distinguish items by their display labels and detect memory content changes even when timestamps remain unchanged.
  • Bug Fixes
    • Sync now reports when routing cannot be resolved or a workspace binding is not approved, rather than proceeding with a fallback.
    • Unlinking a workspace preserves sync information recorded by a subsequent relink.