Skip to content

refactor: Phase 3 architecture optimization#13

Merged
kevintseng merged 26 commits intomainfrom
develop
Apr 17, 2026
Merged

refactor: Phase 3 architecture optimization#13
kevintseng merged 26 commits intomainfrom
develop

Conversation

@kevintseng
Copy link
Copy Markdown
Contributor

Summary

  • Module extraction: Split operations.ts (501→236 lines) into consolidator.ts + serializer.ts with re-exports for backward compat
  • N+1 query fix: Batch entity hydration (getEntitiesByIds) reduces search queries from 400+ to ~8 for limit=100
  • Type safety: Replaced 19/20 as any casts with typed interfaces (EntityRow, CountRow, AnthropicResponse, etc.)
  • Input validation: Shared Zod schemas with maxLength/maxArraySize limits, 1MB body limit
  • Security: API key masking in capabilities, deep-merge LLM config
  • Tests: 396 tests across 24 files (up from 348/20)

Test plan

  • 396 tests passing (vitest, forks pool)
  • tsc --noEmit clean
  • npm run build clean
  • Comprehensive code review (Claude) — all dims pass
  • as any count: 20 → 1
  • Zero transport changes (re-export backward compat)

Add localized README files for zh-TW, zh-CN, ja, ko, pt, fr, de, vi,
es, and th. Update main README.md with language selector at the top of
each file linking all versions together.
Adds a locale system (en, zh-TW, zh-CN, ja, ko, pt, fr, de, vi, es, th)
to the Preact dashboard. Browser language is auto-detected on first load;
selection persists to localStorage. A language selector is added to the
Settings tab. All UI strings across Header, TabNav, SearchTab, BrowseTab,
AnalyticsTab, and SettingsTab are replaced with t() calls.
Rewrote all translated READMEs to match the new English README structure:
- Added "The Problem" emotional opening section
- Added "Get Started in 60 Seconds" 3-step flow
- Added "Who Is This For?" table
- Added "Works With Everything" 3-column layout
- Replaced old comparison table with focused Mem0/Zep comparison
- Added "What Happens Automatically" hooks table
- Added "Smart Features" section with emoji bullets
- Added "Unlock Smart Mode" tiered table
- Updated "All 6 Memory Tools" table format
- Updated Contributing section to match English
- Updated license footer to match English
- CI: add dashboard build step (cd dashboard && npm ci && npx vite build)
- Smoke test: verify 27 required files (was 10) — core, transports, hooks, skills, dashboard
- Installation test: verify plugin version match, skills exist, bin entries, dashboard build
- Installation test: use execFileSync instead of execSync (security)
- Publish workflow: add dashboard build before npm publish
- 294 tests (was 289)
Introduces analyzeFailure() which deduplicates session errors (max 5),
calls the configured LLM provider, and returns a StructuredLesson with
error/rootCause/fix/prevention/errorPattern/fixPattern/severity.
Exports parseLesson() for direct unit testing; always returns null on
any failure path rather than throwing.
Creates createLesson/createExplicitLesson/findProjectLessons with
lesson-{project}-{errorPattern} naming for upsert dedup. Uses pre-call
recall check for reliable isNew detection (RememberResult.observations
is always the input count, not total stored). 12 tests, all passing.
Query lesson_learned entities tagged to the current project and append
prevention hints to the session context, so Claude sees known pitfalls
at session start before making the same mistakes.
Adds learn() to core operations (wraps createExplicitLesson from lesson-engine),
LearnInput/LearnResult types, and learn tool across all 3 transports (MCP, HTTP, CLI).
Includes 17 new tests covering core, MCP handler, and HTTP transport layers.
When LLM is configured (Level 1), the Stop hook now analyzes session
errors via failure-analyzer and creates structured lesson_learned
entities via lesson-engine. Falls back gracefully to rule-based
extraction when no LLM is available.

Adds 8 tests for session-summary hook covering: entity creation,
bugfix tagging, skip guards, dedup, heavy sessions, and Level 0
fallback.
…ive warnings

- Add failure-analyzer.ts and lesson-engine.ts to ARCHITECTURE.md
- Add learn tool (7th MCP tool) to API_REFERENCE.md
- Bump version to 3.1.0 in package.json and plugin.json
- Add failure-analyzer.js and lesson-engine.js to smoke test required files
schema-export.ts was missing the learn tool definition,
causing memesh export-schema to omit it from the output.
…LM config

- GET /v1/config: detectCapabilities() returned raw API key in
  capabilities.llm.apiKey — now masked before response
- POST /v1/config: updateConfig() shallow-merged top-level only,
  causing partial LLM updates to drop saved apiKey — now deep-merges
  the llm object to preserve existing fields

Found by Codex (gpt-5.4) code review.
…rden HTTP server

- Extract 8 Zod validation schemas from handlers.ts + server.ts into
  shared src/transports/schemas.ts (single source of truth)
- Add maxLength/maxArraySize to all inputs: name(255), type(100),
  observations(10000 per, 100 max), tags(255 per, 50 max), etc.
- Set explicit Express body limit (1MB)
- Fix unhandled promise in dashboard fallback (.catch added)
- Add LIMIT 50 to typeDistribution query in /v1/stats
…kg, and http

Add EntityRow, CountRow, PragmaColumnRow, FtsRow and other typed
interfaces to core/types.ts and use them in db.ts, knowledge-graph.ts,
and transports/http/server.ts — eliminating 10 of 20 as-any casts on
SQLite query results with zero behavior change.
Move consolidate() and compressObservations() into dedicated
consolidator.ts module. Re-export consolidate from operations.ts
to maintain backward compatibility with all transports.
Move exportMemories() and importMemories() into dedicated
serializer.ts module. Re-export from operations.ts to maintain
backward compatibility with all transports.
Add AnthropicResponse, OpenAIResponse, OllamaResponse interfaces to
types.ts and use them in consolidator.ts, failure-analyzer.ts, and
query-expander.ts instead of as any casts on response.json().
@kevintseng kevintseng merged commit a5064e2 into main Apr 17, 2026
11 of 13 checks passed
Comment thread src/core/consolidator.ts Dismissed
Comment thread src/core/consolidator.ts Dismissed
Comment thread src/core/consolidator.ts Dismissed
Comment thread src/core/consolidator.ts Dismissed
Comment thread src/core/consolidator.ts Dismissed
Comment on lines +11 to +14
import {
RememberSchema, RecallSchema, ForgetSchema, ConsolidateSchema,
ExportSchema, ExportResultSchema, ImportSchema, LearnSchema,
} from '../schemas.js';
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.

2 participants