Commit Graph

333 Commits

Author SHA1 Message Date
242cacea7c feat(16-02): add userId scoping to thread, setup, and auth services
- All functions accept userId, no more prodDb defaults
- Thread operations verify ownership via and(eq(id), eq(userId))
- Candidate operations verify parent thread ownership before proceeding
- resolveThread includes userId in new item insert and verifies category ownership
- Setup operations use and() for composite id+userId conditions
- syncSetupItems validates both setup and item ownership via inArray
- updateItemClassification and removeSetupItem verify setup ownership
- Auth service: reordered createApiKey params to (db, userId, name)
- verifyApiKey unchanged (already returns { userId } from Plan 01)
2026-04-05 10:43:38 +02:00
8d85d2839e feat(16-02): add userId scoping to item, category, totals, and CSV services
- All functions accept userId as second parameter, no more prodDb defaults
- All queries filter by eq(table.userId, userId) for data isolation
- Get-by-id, update, delete use and() for composite id+userId conditions
- deleteCategory uses dynamic getOrCreateUncategorized(db, userId) not hardcoded ID
- CSV import scopes category lookup/creation and item creation to userId
- CSV export filters items by userId
- Category service converted from sync SQLite to async Postgres patterns
2026-04-05 10:41:59 +02:00
ad309510af Merge branch 'worktree-agent-a9a8b0dc' into Develop
# Conflicts:
#	.planning/REQUIREMENTS.md
#	.planning/ROADMAP.md
#	.planning/STATE.md
#	drizzle-pg/meta/0000_snapshot.json
#	drizzle-pg/meta/_journal.json
#	src/db/schema.ts
#	src/db/seed.ts
#	src/server/middleware/auth.ts
#	src/server/services/auth.service.ts
#	src/server/services/category.service.ts
#	src/server/services/oauth.service.ts
#	tests/helpers/db.ts
2026-04-05 10:38:29 +02:00
a0e5442816 docs(16-01): complete multi-user data model foundation plan
- Add 16-01-SUMMARY.md with schema, middleware, and test changes
- Update STATE.md with phase 16 progress and decisions
- Update ROADMAP.md with plan progress (1/4 complete)
- Mark MULTI-01, MULTI-04, MULTI-06 complete in REQUIREMENTS.md
2026-04-05 10:37:57 +02:00
050478c543 feat(16-01): update test helper to seed user and return { db, userId }
- createTestDb uses PGlite with drizzle-pg migrations
- Seeds test user with logtoSub and per-user Uncategorized category
- Returns { db, userId } instead of just db
- Add createSecondTestUser helper for cross-user isolation tests
2026-04-05 10:34:38 +02:00
b6d562f082 feat(16-01): update auth middleware and services to resolve userId
- verifyApiKey returns { userId } | null instead of boolean
- verifyAccessToken returns { userId } | null instead of boolean
- Add getOrCreateUser upsert function in auth.service
- Add getOrCreateUncategorized helper in category.service
- requireAuth sets userId on Hono context for all 3 auth methods
- Remove GET bypass: all API routes require auth for userId resolution
- Keep bypass for /api/auth and /api/health paths
2026-04-05 10:34:19 +02:00
91e93a31a5 feat(16-01): migrate schema to pgTable and add users table with userId columns
- Rewrite schema.ts from sqlite-core to pg-core (pgTable, serial, timestamp, doublePrecision)
- Add users table with id, logtoSub (unique), createdAt
- Add userId FK column to items, categories, threads, setups, apiKeys, oauthTokens
- Add composite unique constraint on categories(userId, name)
- Change settings PK to composite (userId, key)
- Remove global Uncategorized seed from seed.ts (now per-user lazy)
- Generate Drizzle pg migration
2026-04-05 10:32:51 +02:00
64821f856c docs(16): create multi-user data model phase plan 2026-04-05 10:27:30 +02:00
dbd265d18d docs(phase-16): add validation strategy 2026-04-05 10:18:50 +02:00
b87551694f docs(16): research multi-user data model phase 2026-04-05 10:17:56 +02:00
632e4d3a1a docs(state): record phase 16 context session 2026-04-05 10:11:48 +02:00
73a11c8bdb docs(16): capture phase context 2026-04-05 10:11:23 +02:00
6209e40221 docs(phase-15): complete phase execution 2026-04-04 21:52:30 +02:00
6be9a2b168 fix(15): update oauth routes/tests for async + OIDC session auth
- Add await to all oauth service calls in routes (registerClient, getClient, etc.)
- Rewrite oauth tests to use mocked OIDC session instead of createUser/password
- Test consent-based authorize flow instead of credential-based flow

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 21:43:06 +02:00
59e7f4be8a fix(15): convert auth service/tests to async PGlite pattern
The executor agents wrote sync SQLite-style calls (.get(), .all(), .run())
instead of the async Postgres pattern established in Phase 14. Fixed:
- auth.service.ts: use await + destructuring for all DB operations
- auth routes: await listApiKeys
- All auth test files: async createTestDb(), await service calls

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 21:40:12 +02:00
72eefd1a06 Merge branch 'worktree-agent-a7f7c229' into Develop
# Conflicts:
#	.planning/REQUIREMENTS.md
#	.planning/ROADMAP.md
#	.planning/STATE.md
#	tests/routes/auth.test.ts
#	tests/services/auth.service.test.ts
2026-04-04 20:56:29 +02:00
46ed547340 docs(15-03): complete client auth UI and test updates plan
- SUMMARY.md with OIDC login redirect, auth hook cleanup, E2E seed, test updates
- STATE.md updated with decisions and session info
- ROADMAP.md updated with phase 15 progress
- Requirements AUTH-01, AUTH-02, AUTH-05 marked complete
2026-04-04 20:56:09 +02:00
689a56b2b7 feat(15-03): update E2E seed and auth tests for OIDC architecture
- E2E seed creates API key instead of user for authentication
- Auth service tests cover only API key CRUD (removed user/session tests)
- Auth middleware tests validate three-way auth: API key, Bearer token, OIDC session
- Auth route tests mock getAuth for OIDC session, test /me and /keys endpoints
- Remove all references to createUser, verifyPassword, createSession in auth tests
2026-04-04 20:54:18 +02:00
79b27b6bcc feat(15-03): rewrite login page and auth hooks for OIDC
- Login page redirects to Logto instead of showing credential form
- AuthState uses string id (Logto sub claim) instead of number
- Remove useLogin, useSetup, useChangePassword hooks
- useLogout redirects to /logout (server-side OIDC logout)
- Remove ChangePasswordSection from settings page
- Update UserMenu to use new useLogout API
- Settings page shows API keys section when authenticated
2026-04-04 20:52:58 +02:00
3158274c6a Merge branch 'worktree-agent-a9901af2' into Develop
# Conflicts:
#	.planning/REQUIREMENTS.md
#	.planning/ROADMAP.md
#	.planning/STATE.md
#	bun.lock
#	package.json
#	src/server/middleware/auth.ts
#	src/server/routes/auth.ts
#	src/server/routes/oauth.ts
#	src/server/services/auth.service.ts
2026-04-04 20:48:38 +02:00
82eb9e7286 docs(15-02): complete OIDC auth integration plan
- Add 15-02-SUMMARY.md with execution results
- Update STATE.md with position, decisions, session info
- Update ROADMAP.md with plan progress
- Mark AUTH-01, AUTH-02, AUTH-03 requirements complete
2026-04-04 20:48:04 +02:00
c0e6db5aa6 feat(15-02): update MCP OAuth and MCP middleware for OIDC
- Replace verifyPassword with getAuth in OAuth authorize routes
- Replace login form with consent-only form (no credential fields)
- Remove getUserCount bypass from MCP auth middleware
- GET/POST /authorize redirect to /login if no OIDC session
2026-04-04 20:46:23 +02:00
1b6a65b4d5 feat(15-02): rewrite auth routes for OIDC login/callback/logout
- Add top-level /login, /callback, /logout OIDC routes in index.ts
- Strip auth.ts to /me (OIDC claims) and API key CRUD only
- Remove credential-based login, setup, password change routes
- Remove all cookie/session handling from auth routes
2026-04-04 20:44:46 +02:00
259dc2bc8c feat(15-02): install OIDC deps, rewrite auth middleware and service
- Install @hono/oidc-auth and jose for OIDC integration
- Rewrite requireAuth middleware with three-way auth: API key, MCP Bearer, OIDC session
- Strip auth.service.ts to API key functions only (remove user/session management)
- Remove all references to getUserCount, getSession, refreshSession from middleware
2026-04-04 20:43:52 +02:00
e3659a23f1 Merge branch 'worktree-agent-ae56a15a' into Develop
# Conflicts:
#	.planning/ROADMAP.md
#	.planning/STATE.md
#	docker-compose.dev.yml
#	docker-compose.yml
#	src/db/schema.ts
2026-04-04 20:41:11 +02:00
73c3d69dba docs(15-01): complete Logto Docker infrastructure plan
- Create 15-01-SUMMARY.md with execution results
- Update STATE.md with phase 15 position and decisions
- Update ROADMAP.md with plan progress
- Mark AUTH-04 requirement complete
2026-04-04 20:40:30 +02:00
0fe231ff1c feat(15-01): remove users and sessions tables from schema
- Delete users and sessions table definitions from src/db/schema.ts
- Generate Drizzle migration to drop both tables
- Retain apiKeys, oauthClients, oauthCodes, oauthTokens tables
2026-04-04 20:38:38 +02:00
625862f5ae feat(15-01): add Logto service to Docker Compose and create init script
- Add Logto OIDC provider to docker-compose.yml and docker-compose.dev.yml
- Create docker/init-logto-db.sql to initialize separate Logto database on Postgres
- Add OIDC env vars (issuer, client ID/secret, auth secret) to app service
- Document all required env vars in .env.example
2026-04-04 20:37:57 +02:00
f2c1d04cfc docs(15): create phase plan for external authentication 2026-04-04 20:30:27 +02:00
7ba931352a docs(phase-15): add validation strategy 2026-04-04 20:22:42 +02:00
5b0190dbbc docs(15): research external authentication phase domain 2026-04-04 20:21:47 +02:00
4be3d26ae0 docs(state): record phase 15 context session 2026-04-04 20:15:47 +02:00
46e2d1896b docs(15): capture phase context 2026-04-04 20:15:40 +02:00
77bd3c55d0 docs(14-06): complete test suite async conversion plan
- SUMMARY.md: 18 test files converted, 161 tests passing on PGlite
- STATE.md: updated position, decisions, session
- ROADMAP.md: phase 14 complete (6/6 plans)
- REQUIREMENTS.md: DB-02, DB-03 marked complete

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 15:42:17 +02:00
f30d375544 feat(14-06): convert route tests + MCP tests to async PGlite
- All 8 route test files: async createTestApp(), async beforeEach
- MCP tools test: await createTestDb(), await getCollectionSummary()
- Fixed MCP tool files: added await to all service calls in items, categories, threads, setups tools
- Fixed MCP collection resource: made getCollectionSummary async
- Fixed MCP index.ts: await getCollectionSummary call
- Increased test timeout to 30s in bunfig.toml for PGlite WASM overhead
- Zero SQLite references remain in tests/

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 15:40:14 +02:00
458b33f1c7 feat(14-06): convert all 9 service test files to async PGlite
- All beforeEach now use async/await createTestDb()
- All service calls in tests now awaited
- All direct DB calls (.run()/.all()) replaced with await
- All test callbacks made async
- Fixed PostgreSQL GROUP BY strictness in totals.service.ts (categories.name and categories.icon added to groupBy)
- db type changed to 'any' to accommodate PGlite type differences

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 13:11:52 +02:00
cb2a192cb5 docs(14-04): complete route handlers async conversion plan
- Add 14-04-SUMMARY.md documenting async conversion of all 9 route files and auth middleware
- Update STATE.md with progress (83%) and decisions
- Update ROADMAP.md with plan progress
2026-04-04 12:44:55 +02:00
22aaed76f2 feat(14-04): convert auth, OAuth, settings routes and auth middleware to async/await
- Add await before all service calls in auth, OAuth routes
- Convert settings.ts direct DB calls: remove .get()/.run(), use await + destructuring
- Auth middleware: await getUserCount, getSession, refreshSession
- Fix formatting in threads.ts for biome compliance
- All files pass lint
2026-04-04 12:43:29 +02:00
5edcc660e4 feat(14-04): convert data route handlers to async/await
- Add await before all service calls in items, categories, threads, setups, totals routes
- Make all handler callbacks async
- Covers getAllItems, createItem, updateItem, deleteItem, duplicateItem,
  getAllCategories, createCategory, updateCategory, deleteCategory,
  getAllThreads, getThreadWithCandidates, createThread, updateThread, deleteThread,
  resolveThread, createCandidate, updateCandidate, deleteCandidate, reorderCandidates,
  getAllSetups, getSetupWithItems, createSetup, updateSetup, deleteSetup,
  syncSetupItems, updateItemClassification, removeSetupItem,
  getCategoryTotals, getGlobalTotals, exportItemsCsv, importItemsCsv
2026-04-04 12:40:55 +02:00
fddbf8166d docs(14-03): complete service layer async conversion plan
- SUMMARY.md documents 30 async function conversions across 9 service files
- STATE.md updated with position, decisions, session info
- ROADMAP.md progress updated (4/6 summaries for phase 14)
- Requirements DB-01, DB-02 marked complete
2026-04-04 12:36:38 +02:00
75bf3e0dcd feat(14-03): convert auth/oauth/csv services to async, await seedDefaults
- auth.service.ts: 10 functions async, removed .all()/.get()/.run()
- oauth.service.ts: 7 functions async, boolean conversion (used: true/false)
- csv.service.ts: export/import functions async, removed .all()/.get()/.run()
- server index.ts: seedDefaults() now awaited for async DB
- PGlite smoke test confirms async services work end-to-end
2026-04-04 12:35:18 +02:00
4d705af3f1 feat(14-03): convert core data services to async PostgreSQL operations
- item.service.ts: 6 functions async, removed .all()/.get()/.run()
- category.service.ts: 4 functions async, transaction uses async callback
- thread.service.ts: 10 functions async, transactions in resolveThread/reorderCandidates use async callbacks
- setup.service.ts: 8 functions async, syncSetupItems transaction uses async callback
- totals.service.ts: 2 functions async, removed .all()/.get()
2026-04-04 12:32:58 +02:00
295be8c09d Merge branch 'worktree-agent-a5f21c17' into Develop
# Conflicts:
#	.planning/REQUIREMENTS.md
#	.planning/ROADMAP.md
#	.planning/STATE.md
2026-04-04 12:30:57 +02:00
85104f3687 docs(14-05): complete SQLite-to-Postgres migration script plan
- SUMMARY.md with execution results
- STATE.md updated with plan 05 completion
- ROADMAP.md updated with phase 14 progress
- DB-04 requirement marked complete
2026-04-04 12:30:31 +02:00
b4c38134e1 feat(14-05): create SQLite-to-Postgres data migration script
- One-time migration script with type conversions (unix timestamps to Date, int to bool)
- Migrates all 13 tables in FK dependency order
- Resets serial sequences after data migration
- Adds db:migrate-from-sqlite npm script
2026-04-04 12:28:19 +02:00
f7b830a6ff docs(14-02): complete Docker & Compose for PostgreSQL plan
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 12:25:16 +02:00
186e74bcea feat(14-02): update Dockerfile for PostgreSQL (remove native build deps)
- Remove apt-get install of python3/make/g++ (no longer needed without better-sqlite3)
- Change COPY drizzle to COPY drizzle-pg for PostgreSQL migrations
- Remove mkdir -p data (no SQLite data directory needed)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 12:24:00 +02:00
50b451bf65 feat(14-02): add Docker Compose files for PostgreSQL dev and production
- Create docker-compose.dev.yml with Postgres 16 for local development
- Rewrite docker-compose.yml with Postgres service, healthcheck, and app dependency chain
- Production uses externalized POSTGRES_PASSWORD and DATABASE_URL env vars

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 12:23:35 +02:00
ec8d1c362c Merge branch 'worktree-agent-a730aaff' into Develop
# Conflicts:
#	.planning/ROADMAP.md
#	.planning/STATE.md
2026-04-04 12:22:21 +02:00
d2d64279d3 docs(14-01): complete database foundation plan
- Created 14-01-SUMMARY.md with execution results
- Updated STATE.md with plan progress and decisions
- Updated ROADMAP.md progress table (1/6 plans)
- Marked DB-01 and DB-03 requirements complete
2026-04-04 12:21:50 +02:00