feat: REST API for remote data management, recall, and import#337
Merged
Conversation
Add /api/v1/ endpoints enabling lore data, recall, and import commands
to work against a remote gateway when LORE_REMOTE_URL is set.
API endpoints:
- GET /api/v1/projects, stats, knowledge/:id, sessions/:id, distillations/:id
- GET /api/v1/projects/:id/{knowledge,sessions,distillations}
- DELETE /api/v1/{knowledge,sessions,distillations,projects}/:id
- POST /api/v1/projects/:id/{clear,reindex,dedup}, /api/v1/projects/merge
- GET /api/v1/recall with query expansion (gateway has LLM client)
- POST /api/v1/import/{extract,record}, GET /api/v1/import/history
Infrastructure:
- resolveProjectByRemoteOrPath() in core — read-only project lookup
preferring git_remote over path (no project creation side-effects)
- Zstd request body decompression (Content-Encoding: zstd)
- CLI remote helper with projectQueryParams() for git_remote-first lookup
- All CLI commands (data, recall, import) check LORE_REMOTE_URL and
delegate to the API; local codepath unchanged
- 28 new API tests, 1519 total tests passing
Critical: - C2: Fix null body crash in handleClearProject (JSON null → TypeError) - C3: Move reindex to global POST /api/v1/reindex (backfill is DB-wide, not project-scoped — the old project-scoped route was misleading) - C4: Guard handleMergeProjects against hosted mode (backfillGitRemotes runs git on local FS, unsafe on hosted gateway) - C5: Add DELETE to CORS access-control-allow-methods Medium: - M1: Remove dead variables in cmdListRemote knowledge case - M3: Handle non-JSON error responses in remote.ts (e.g. nginx 502) - M5: Validate scope parameter in recall endpoint - M6: Call setLastImportAt + exportLoreFile in importRemote - M7: Check literal routes before parameterized routes in api.ts Low: - L3: Remove dead endpoint variable in cmdDedupRemote - L4: Fix test to actually test git_remote/path query param resolution 5 new tests added (33 total API tests, 1524 total suite).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/api/v1/REST API endpoints enablinglore data,lore recall, andlore importto work against a remote gateway whenLORE_REMOTE_URLis setresolveProjectByRemoteOrPath()in core for read-only project lookup preferringgit_remoteoverpathContent-Encoding: zstd) for efficient import payloadsAPI Endpoints
Data reads:
GET /api/v1/projects— list all projectsGET /api/v1/stats— global statsGET /api/v1/projects/:id/{knowledge,sessions,distillations}— project-scoped listsGET /api/v1/{knowledge,sessions,distillations}/:id— show single entryData mutations:
DELETE /api/v1/{knowledge,sessions,distillations,projects}/:idPOST /api/v1/projects/:id/{clear,dedup}POST /api/v1/projects/merge(guarded against hosted mode)POST /api/v1/reindex— global embedding backfill (DB-wide, not project-scoped)Recall:
GET /api/v1/recall?q=...&git_remote=...— with query expansion (gateway has LLM client)Import:
POST /api/v1/import/extract— accept chunks, run curator LLM, store resultsPOST /api/v1/import/record— mark session as importedGET /api/v1/import/history— list import recordsCLI Remote Wiring
All CLI commands (
data,recall,import) checkLORE_REMOTE_URLearly and delegate to the REST API. Local codepaths are unchanged. Commands that require local filesystem access (recover,clear --all) error with a clear message in remote mode.Self-Review Fixes (a591e38)
Addressed 11 findings from thorough self-review:
Critical:
handleClearProject(JSONnull→ TypeError)POST /api/v1/reindex(backfill is DB-wide, not project-scoped)handleMergeProjectsagainst hosted mode (backfillGitRemotesruns git on local FS)DELETEto CORSaccess-control-allow-methodsMedium:
cmdListRemoteknowledge caseremote.ts(e.g. nginx 502)setLastImportAt+exportLoreFileinimportRemoteLow:
cmdDedupRemotegit_remote/pathquery param resolutionDeferred (acceptable):
Files Changed
packages/core/src/db.tsresolveProjectByRemoteOrPath()+projectPath()packages/core/src/index.tspackages/gateway/src/api.tspackages/gateway/src/server.ts/api/route (lazy-imported), add DELETE to CORSpackages/gateway/src/cli/remote.tspackages/gateway/src/cli/data.tspackages/gateway/src/cli/recall-cmd.tspackages/gateway/src/cli/import.tspackages/gateway/test/api.test.tsTest Results