173 Commits

Author SHA1 Message Date
root
cf429da534 feat(api): pages routes + revisions + backlinks
Add lib/api/routes/pages.js: list by space, create/get/patch/delete,
get-by-slug, list revisions, and backlinks via entity_links.listTo
enriched with the source entity's title (whitelisted entity_type set
to keep the dynamic-table SELECT bounded).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 20:48:58 +10:00
root
50649bea5f feat(api): tasks routes
Add lib/api/routes/tasks.js: list by space (status filter), list by
project (position then created_at), create scoped to space with
optional project_id, get/patch/delete by id. status=done flips
completed_at via the repo's existing trigger logic.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 20:46:39 +10:00
root
beb6da21c8 feat(api): projects routes
Add lib/api/routes/projects.js: list by space (with status filter),
create scoped to space, get/patch/delete by id. FK violation from
unknown space_id maps to 400 invalid_space.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 16:39:31 +10:00
root
ebb1e836ca feat(api): spaces routes
Add lib/api/routes/spaces.js: list, create, get-by-id, get-by-slug,
patch, delete. Mounted under /api/spaces. Server smoke restored.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 16:38:23 +10:00
root
75afedaef0 feat(api): error + validate + pagination plumbing
Add lib/api/{errors,validate,pagination,index}.js: typed ApiError
subclasses, errorMiddleware, zod-backed validate(), parsePagination
with caps, and a mountApi() that owns /api routing + 404 + error tail.
server.js delegates /api to mountApi and drops the inline /api/spaces
smoke (returns in Task 2).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-31 16:37:06 +10:00
root
d862eaa3b0 feat(server): Express bootstrap, /health, ownerOnly on /api, smoke /api/spaces 2026-05-31 15:30:50 +10:00
root
7e55f07689 feat(auth): owner-only middleware for single-user bearer auth 2026-05-31 11:06:21 +10:00
root
cd71d64523 feat(auth): capability check — user/cron/worker allow; agents tiered allow/suggest/deny 2026-05-31 11:06:00 +10:00
root
10902bc6ac feat: real audit_log with redaction + pending_changes; replace stub 2026-05-31 11:04:53 +10:00
root
47ea0768fd feat(repos): tags, polymorphic entity_links, attachments 2026-05-31 11:02:58 +10:00
root
1b51c3c18d feat(schema): 005 — tags, entity_tags, entity_links, attachments 2026-05-31 11:02:14 +10:00
root
1d799105ac feat(repos): agents (+ tokens + caps), conversations, messages 2026-05-31 10:36:40 +10:00
root
5e094f347e feat(schema): 004 — agents, agent_tokens, conversations, messages 2026-05-31 10:35:56 +10:00
root
6086cf9a7a fix(schema): tighten tenant boundaries on resources/deps/creds/source_docs
Apply same composite-FK pattern as 001/002 for migration 003:
- resources: add UNIQUE (id, space_id) as FK target.
- resource_dependencies: denormalize space_id, composite FKs on both endpoints
  (enforces both ends of a dep live in the same space at the DB layer).
- resource_credentials: denormalize space_id, composite FK to resources.
- source_docs.resource_id: NOT NULL (tenancy anchor); resource_id was already
  absent from the update FIELDS list so docs cannot move resources.

Repos derive space_id from the resource on addDependency/addCredential so callers
can't fake cross-tenant assignment. 3 regression tests added.
2026-05-31 10:33:17 +10:00
root
9dd944226d fix(schema): tighten tenant boundaries on pages/refs
Three security-review findings on migration 002:
- pages.space_id and refs.space_id changed to NOT NULL + ON DELETE CASCADE
  (was nullable + SET NULL, which allowed orphan rows surviving space deletion).
- pages.parent_id wrapped in composite FK (parent_id, space_id) -> pages(id, space_id)
  to prevent cross-space parent linkage (same pattern as tasks.project_id in 001).
- idx_refs_external promoted to UNIQUE on (space_id, source_kind, external_id);
  upsertByExternal now requires space_id and dedups per-space, not globally.

Added 3 regression tests covering composite FK rejection, CASCADE-on-space-delete,
and per-space dedup independence.
2026-05-31 02:21:47 +10:00
root
c8649d753f feat(repos): resources (+ deps + creds) and source_docs 2026-05-31 02:19:23 +10:00
root
99d64221a0 feat(schema): 003 — resources, deps, credentials, source_docs 2026-05-31 02:18:39 +10:00
root
c891c495bb feat(repos): pages with auto-revisions, refs with upsertByExternal 2026-05-31 02:17:01 +10:00
root
652f7c3894 feat(schema): 002 — pages, page_revisions, refs with FTS + vector indexes 2026-05-31 02:16:06 +10:00
root
3ca1509935 fix(schema): enforce cross-space FK on tasks.project_id via composite key
Security review flagged that tasks.project_id could reference a project in
a different space. Added composite FK (project_id, space_id) -> projects(id, space_id)
with ON DELETE SET NULL (project_id) so a deleted project leaves the task in
its space with project_id NULL rather than orphaning into a NULL space.

Added two regression tests: cross-space FK rejection + cascade behavior.
2026-05-31 02:14:20 +10:00
root
951016385a feat(repos): spaces, projects, tasks with audit stub
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 02:11:31 +10:00
root
05ee9b3f41 feat(schema): 001 — spaces, projects, tasks with check constraints
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 02:07:15 +10:00
root
789ab8fca8 feat: db pool + migration runner with idempotency
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-31 02:05:53 +10:00