Commit Graph

26 Commits

Author SHA1 Message Date
saravanakumardb1
fe2ab6010e fix(backend): remove stale TODO-008 comment, add telemetry to suggestions route 2026-04-19 00:53:05 -07:00
saravanakumardb1
8ca9e27532 test(ai-context): TODO-009 unit tests for LLM context message generators
Adds 18 new tests covering:

Backend (13 tests in ai-context.test.ts):
- keyword fallback — meeting, doctor, flight, case-insensitive
- generic fallback — no match, minute/hour formatting
- LLM path — flag-gated (off = no fetch), extraction-service success,
  Ollama cascade when extraction returns null, error → keyword fallback,
  short Ollama response rejected, non-200 fallthrough
- prompt construction — includes category, urgency, timeOfDay,
  recentTimerLabels

Web (5 new tests in context-messages.test.ts):
- LLM success path
- keyword fallback when backend returns 500
- keyword fallback when backend throws
- generic fallback when backend fails and no keyword matches
- payload shape — POST /api/context-message with all params

Test counts: backend 240 (was ~227), web 399 (was ~394), all green.
2026-04-17 12:40:10 -07:00
saravanakumardb1
229ce4f00f feat(backend): wire Ollama LLM for context messages (TODO-005)
Dual-path LLM enrichment for AI context prep messages:
1. extraction-service (if EXTRACTION_SERVICE_URL set)
2. Ollama direct (if OLLAMA_URL set) — non-streaming /api/generate
3. Keyword rules fallback
4. Generic fallback

New env vars: OLLAMA_URL, OLLAMA_MODEL (default: gemma3:4b)
Both LLM paths use 5s timeout and null-return-on-error pattern.
Feature-gated behind ai_context_messages.enabled flag.
2026-04-13 17:00:24 -07:00
saravanakumardb1
9b398bbd68 fix(backend): convert ecosystem-phase2 test to Vitest, fix .ts extension + hardcoded productId
- ecosystem-phase2.test.ts used node:test — Vitest discovered it but ran 0 tests
- Converted to Vitest describe/it/expect — now 2 tests actually execute
- Added coverage for missing plan-created-event graceful fallback
- Fixed .ts import extension to .js (ESM convention, tsc build compat)
- Replaced 6 hardcoded 'chronomind' literals with PRODUCT_ID import
2026-04-13 15:51:58 -07:00
saravanakumardb1
82428d7bf9 fix(backend): fix sync throw isolation in event bus + add 6 tests
Promise.allSettled only catches rejected promises, not synchronous throws.
Wrap handler calls in Promise.resolve().then() to isolate sync errors.
Add 6 unit tests covering delivery, unsubscribe, error isolation,
singleton, reset, and removeAll.
2026-04-13 11:42:14 -07:00
saravanakumardb1
fbac905e9c feat(backend): add domain event bus + webhook dispatch
Add typed event bus (6 events: timer.created/fired/completed,
routine.started/completed, household.created) with Promise.allSettled
isolation. Wire webhook subscriber bridge using @bytelyst/webhook-dispatch
for HMAC-signed delivery with retry.

All 219 tests pass.
2026-04-13 11:28:38 -07:00
fdd3743f28 feat(phase2): import chronomind routines from plans 2026-04-03 19:30:11 -07:00
saravanakumardb1
9897d2cd09 docs(todos): standardize all TODOs with running numbers and delegatable instructions
Replace ad-hoc AGENTIC-N comments with standardized TODO-NNN format across
the entire codebase. Each TODO has:
  - Running number (TODO-001 through TODO-011)
  - Priority level (high/medium/low)
  - Phase reference (0, A.1, A.4, B, cleanup)
  - Clear step-by-step instructions an AI agent can follow

TODO index:
  TODO-001: Kill switch maintenance banner (providers.tsx)
  TODO-002: Feedback button in settings page
  TODO-003: Accessibility focus trap for modals
  TODO-004: Clone routine template instead of mutating in-place
  TODO-005: Wire real LLM enrichment for context messages
  TODO-006: Centralize backend URL configuration
  TODO-007: MCP tool integration tests (common-plat)
  TODO-008: Wire trackEvent() calls into routes + components
  TODO-009: Unit tests for AI context generation
  TODO-010: Import PRODUCT_ID from product-config (5 route files)
  TODO-011: Wire error boundary to telemetry

Added consolidated TODO Index table at top of AGENTIC_AI_ROADMAP.md
for agent scanning. 219 backend tests pass, no code changes.
2026-04-01 01:05:25 -07:00
saravanakumardb1
c80c1e4462 feat(ai-context): Phase A.4 — context-aware AI messages with LLM fallback
Add AI-enriched context message generation:

- backend/src/lib/ai-context.ts: LLM-powered context generator with keyword fallback
  - Calls extraction-service timer-context task when EXTRACTION_SERVICE_URL is set
  - Falls back to keyword rules, then generic message
  - Gated behind isFeatureEnabled('ai_context_messages.enabled')
- backend/src/lib/config.ts: Add EXTRACTION_SERVICE_URL env var
- backend/src/server.ts: POST /api/context-message route
- web/src/lib/context-messages.ts: fetchEnrichedMessage() with graceful degradation
- Updated AGENTIC_AI_ROADMAP.md checkboxes for Phase A.1 + A.2

All 219 backend tests + 394 web tests pass. No breaking changes.
2026-03-31 23:46:00 -07:00
saravanakumardb1
29a48025eb feat(agent-actions): Phase A.2 — agent action audit trail module + tests
Add agent-actions module for AI/MCP operation audit trail:

- types.ts: 3 enums (ACTOR_TYPES, ACTION_STATES, ACTION_TYPES), AgentActionDoc,
  CreateAgentActionSchema, AgentActionQuerySchema, BatchApproveSchema
- repository.ts: CRUD + batchApproveByActor using @bytelyst/datastore
- routes.ts: 5 endpoints (list, create, approve, reject, batch-approve)
  All gated behind isFeatureEnabled('agent_inbox.enabled')
- Registered cm_agent_actions container in cosmos-init.ts
- Registered agentActionRoutes in server.ts

Tests (37 new, 219 total):
- 22 agent-actions schema tests (constants, create, query, batch-approve)
- 15 timer schema tests (RescheduleTimerSchema, AvailabilityQuerySchema)

All 219 backend tests pass. No breaking changes.
2026-03-31 23:38:03 -07:00
saravanakumardb1
f3e14e28dd feat(ecosystem): Phase 0 — kill-switch, feedback, accessibility, feature flags, telemetry events
Phase 0 of the Agentic AI Roadmap: ecosystem gap fixes.

- Add @bytelyst/kill-switch-client integration (web/src/lib/kill-switch.ts)
- Wire kill switch check into providers.tsx on app init
- Add @bytelyst/feedback-client integration (web/src/lib/feedback.ts)
- Add @bytelyst/accessibility to web dependencies
- Add 7 agentic feature flags to backend (all default false)
- Define 16 telemetry event constants (backend + web)
- Add AGENTIC_AI_ROADMAP.md with full Phase 0-E plan + audit findings

All 182 backend tests pass. All 394 web tests pass.
No breaking changes to existing functionality.
2026-03-31 23:26:37 -07:00
saravanakumardb1
8c90d863a8 feat(backend): admin-panel encryption toggle via initEncryption()
- FIELD_ENCRYPT_ENABLED env var (default: true, fallback only)
- initEncryption(productId) polls encryption_enabled from platform-service
- Admin panel toggle takes precedence, 3s timeout graceful fallback
2026-03-21 15:24:58 -07:00
saravanakumardb1
253a9db0ea feat(backend): encrypt sensitive fields across all modules
- timers: description
- routines: description, steps[].notes
- shared-timers: description
- webhooks: secret, description
- Add @bytelyst/field-encrypt dep + chronomind-mek config
- field-encrypt singleton (getEncryptor lazy pattern)
- Encrypt on create/update/batchUpsert, decrypt on read/list/since
- Backward-compatible via isEncryptedField guard
- 182/182 tests passing, typecheck clean
2026-03-21 12:11:39 -07:00
saravanakumardb1
bc735dfdb9 feat(backend): add @bytelyst/backend-flags + backend-telemetry, fix config defaults
- Add @bytelyst/backend-flags and @bytelyst/backend-telemetry packages
- Create feature-flags.ts and telemetry.ts wrappers using shared packages
- Add TELEMETRY_ENABLED and FEATURE_FLAGS_ENABLED config fields
- Default DB_PROVIDER to memory (fixes test failures without env vars)
- Add JWT_SECRET dev default and PLATFORM_SERVICE_URL
- 176/176 tests pass
2026-03-20 17:31:01 -07:00
saravanakumardb1
6acc97bf8a fix(backend): use config.DB_PROVIDER instead of process.env.DB_PROVIDER in datastore.ts
- Reads validated DB_PROVIDER from Zod config instead of raw env
- Removes stale isTest fallback logic (now handled by config defaults)
2026-03-20 08:29:36 -07:00
saravanakumardb1
ea508b1fdc fix(backend): make COSMOS_ENDPOINT/KEY validation conditional on DB_PROVIDER
- Only require Cosmos credentials when DB_PROVIDER=cosmos
- Standardize to .refine() pattern matching all other repos
2026-03-20 08:26:07 -07:00
saravanakumardb1
0bda7dd9dc refactor(backend): migrate config.ts to @bytelyst/backend-config base schema
- Extends baseBackendConfigSchema with product-specific overrides
- DB_PROVIDER now declared in all repos (was missing in 3)
2026-03-20 07:56:29 -07:00
saravanakumardb1
a7b0ae9cdc refactor(backend): migrate auth.ts + request-context.ts to @bytelyst/fastify-auth
- auth.ts: 80→18 lines, delegates to createAuthMiddleware()
- request-context.ts: delegates to createRequestContext()
- Re-exports JwtPayload, AuthPayload from shared package
2026-03-20 07:45:58 -07:00
saravanakumardb1
30872465d3 refactor(backend): load product identity from shared/product.json 2026-03-20 07:23:31 -07:00
saravanakumardb1
b4a6c62e15 refactor(backend): remove errors.ts re-export, import @bytelyst/errors directly 2026-03-20 07:19:29 -07:00
saravanakumardb1
82e7a9c367 fix(auth): JWKS URL-tracking singleton + expanded test coverage 2026-03-12 11:22:03 -07:00
saravanakumardb1
3d2ce9325f feat(auth): RS256 JWKS verification — ChronoMind backend 2026-03-12 11:15:03 -07:00
saravanakumardb1
35756f95c0 chore(backend): remove orphaned cosmos.ts — all repos now use datastore.ts 2026-03-02 01:49:24 -08:00
saravanakumardb1
8731cf38fd fix(backend): add NODE_ENV=test auto-selection and sync setProvider with global singleton 2026-03-02 01:49:11 -08:00
saravanakumardb1
03d4b7def9 refactor(backend): migrate ChronoMind repositories to @bytelyst/datastore 2026-03-02 01:45:16 -08:00
saravanakumardb1
f10b83c122 feat(backend): scaffold product-specific Fastify backend (port 4011)
Add backend/ directory with Fastify 5 + TypeScript ESM service:
- Modules: timers, routines, households, shared-timers, webhooks (migrated from platform-service)
- Cosmos containers: timers, routines, households, shared_timers, webhook_subscriptions, webhook_events
- JWT verification via jose (matches platform-service issuer)
- Shared @bytelyst/* packages via file: refs
- 171 Vitest tests passing

Update AGENTS.md: update backend integration section with product backend details
2026-03-01 20:39:08 -08:00