Skip to content

feat: project-level API server + CLAUDE.md parser module (v0.4.0) - #15

Merged
dahai80 merged 1 commit into
mainfrom
feat/project-api-v0.4.0
Jul 29, 2026
Merged

dahai80 merged 1 commit into
mainfrom
feat/project-api-v0.4.0

Conversation

@dahai80

@dahai80 dahai80 commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

Implements Issue #6 (P0) and Issue #7 (P1).

Issue #6: Project-Level API (JSON-RPC/HTTP)

HTTP server for Fusion Studio integration using Bun.serve():

Endpoint Method Description
/api/project/context?cwd=<path> GET Returns CLAUDE.md + project instructions
/api/sessions?cwd=<path> GET List session history
/api/sessions/:id?cwd=<path> GET Get session detail
/api/memory?cwd=<path> GET Scan project memory files
/api/memory?cwd=<path> POST Write memory file

Start with: ./fusion-code --serve [--port=4827] [--auth=<token>]

  • CORS enabled for cross-origin access
  • Optional Bearer token auth
  • Replaces src/server/server.ts stub with real implementation

Issue #7: CLAUDE.md Parser Module

Standalone re-export barrel at src/lib/claudemd-parser/:

  • Import via @fusion-mlx/fusion-code/claudemd-parser
  • Exports: parseFrontmatter, MEMORY_TYPES, scanMemoryFiles, getMemoryFilesPortable, getProjectContextPortable

Key Design Decisions

  • claudemdPortable.ts — DI version of claudemd.ts that accepts cwd parameter instead of reading bootstrap/state. No hooks, no analytics, no feature flags. This is what the API server uses.
  • projectApiServer.ts — Uses Bun.serve() (zero deps, matches existing upstreamproxy/relay.ts pattern). Route matching supports parameterized paths (:id).
  • No JSON-RPC — HTTP REST is simpler, more debuggable, and sufficient for the described use cases. Can add JSON-RPC wrapper later if needed.

Files Changed

File Change
src/server/projectApiServer.ts NEW — HTTP API server
src/server/server.ts MODIFIED — stub → real startServer()
src/entrypoints/cli.tsx MODIFIED — added --serve/--api dispatch
src/utils/claudemdPortable.ts NEW — portable CLAUDE.md parsing
src/lib/claudemd-parser/index.ts NEW — re-export barrel
package.json MODIFIED — added exports, version → 0.4.0
tests/server/projectApiServer.test.ts NEW — 10 tests
tests/lib/claudemd-parser.test.ts NEW — 7 tests

Test Results

312 pass, 2 flaky (pre-existing fusion-mlx-adapter test isolation — not related to this change)

Fixes #6, Fixes #7

🤖 Generated with Claude Code

- Add projectApiServer.ts: HTTP server with 5 endpoints for Fusion Studio
  - GET /api/project/context?cwd=<path>
  - GET /api/sessions?cwd=<path>
  - GET /api/sessions/:id?cwd=<path>
  - GET /api/memory?cwd=<path>
  - POST /api/memory?cwd=<path>
- Add claudemdPortable.ts: DI version of claudemd.ts without CLI deps
- Add claudemd-parser module (src/lib/claudemd-parser/) for external use
- Replace server.ts stub with real startServer()
- Add --serve/--api CLI dispatch with --port= and --auth= options
- Add package.json exports for @fusion-mlx/fusion-code/claudemd-parser
- Add 17 new tests (10 API + 7 module)
- Fixes #6 (P0), Fixes #7 (P1)

Co-Authored-By: Claude <[email protected]>
@dahai80
dahai80 merged commit d18f4c1 into main Jul 29, 2026
1 check passed
@dahai80
dahai80 deleted the feat/project-api-v0.4.0 branch July 29, 2026 09:31
dahai80 added a commit that referenced this pull request Aug 28, 2026
) (#185)

Extract the composedOnScroll scroll-routing logic from REPL.tsx into a
pure helper src/utils/composedOnScroll.ts (applyComposedOnScroll). No
React hooks, no JSX, no await — only side effects are mutating
lastUserScrollTsRef.current and dispatching to 4 callbacks/setters,
byte-identical to the inlined useCallback body.

REPL keeps a thin useCallback wrapper whose deps array
[onRepin, onScrollAway, maybeLoadOlder, setAppState] is unchanged
verbatim (feature() is a bun:bundle build-time DCE macro, not a runtime
dep). Downstream reads the same const name.

Tests (src/__tests__/utils/composedOnScroll.test.ts, 5 cases) cover the
non-feature paths: timestamp write, sticky->onRepin, non-sticky->
onScrollAway(handle). KAIROS/BUDDY arms are DCE-off under bun test (no
flag) and asserted not-invoked; production build:dev:full covers them.

Gates: typecheck 0 / 865 tests / biome clean / build:dev pass.
REPL 6468 -> 6455 (-13). Cumulative across 15 slices: -641.

Co-authored-by: Claude Fable 5 <[email protected]>
dahai80 added a commit that referenced this pull request Aug 28, 2026
#187)

Extract setInputValue useCallback body (27 LOC, 3 deps) to pure-helper
src/utils/inputValueState.ts applySetInputValue(). Same aggregate-input
pattern as slices #15/#16: typed InputValueStateSetters (7 fields),
REPL keeps useCallback thin wrapper, deps array
[setIsPromptInputActive, repinScroll, trySuggestBgPRIntercept] unchanged
verbatim. RECENT_SCROLL_REPIN_WINDOW_MS (REPL-local const 3000) passed as
recentScrollRepinWindowMs field to keep helper pure-agnostic.

Behavior: (1) trySuggestBgPRIntercept(prev,value) hit -> early return;
(2) empty->non-empty + scroll-stale (>= window) -> repinScroll;
(3) sync inputValueRef.current + setInputValueRaw + setIsPromptInputActive(trim>0).

Tests: 8 cases (repin+write+activate, intercept early-return, non-empty
guard, scroll within-window/boundary, empty deactivate, whitespace guard,
ref-sync-before-setters). 881/881 pass, typecheck 0, biome clean, build:dev ok.

REPL 6434 -> 6420 (-14). Cumulative 7096 -> 6420 (-676) across 16 slices.
Zero REPL import churn. Byte-identical behavior (deps + ref reads unchanged).

Co-authored-by: Claude Fable 5 <[email protected]>
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.

请求: CLAUDE.md 解析库抽离为独立模块 请求: 暴露项目级 API (JSON-RPC/HTTP)

1 participant