feat: workspace discovery for monorepo support#451
Merged
Conversation
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.
Problem
Lore uses
process.cwd()as the project path with no directory traversal. This fails for monorepo setups:Downward (primary pain point): User runs
lore runfrom monorepo root (no.git). Sub-projects are bare directories under the root, each with their own.gitand.lore.md. Lore never discovers these sub-project.lore.mdfiles.Upward: User runs from a sub-project. Lore doesn't discover the monorepo root above, missing shared config.
Solution
Config-driven sub-project discovery
New
workspacesfield in.lore.json:Supports literal relative paths and single-level globs. Mirrors
package.jsonworkspaces /pnpm-workspace.yamlconventions.Upward discovery via
discoverWorkspaceRoot()Walks up from cwd checking for project markers at each level:
.lore.jsonwithworkspacesfield (strongest signal — user explicitly declared workspace root).git,.hg,.svn,.jj, etc. (definitive)pnpm-workspace.yaml,nx.json,turbo.json, etc. (definitive)package.json,pyproject.toml,Cargo.toml, etc. (closest-wins, walk continues)Stop boundary at
homedir()— never claims$HOMEas workspace root even if~/.gitexists (common dotfile managers).Integration flow
At startup (
initIfNeeded):.lore.jsonfrom resolved pathworkspacesis configured, resolve glob patterns to sub-project dirs.lore.mdfrom each sub-project into the root project's knowledge base (viaimportLoreFileAs).lore.mdfiles for live changes (independent debounce timers per watcher)Sub-project
.lore.mdfiles are read-only imports — entries are attributed to the root project so they're visible viaforSession(). Lore does not write back to sub-project files.Safety
resolveWorkspacesrejects../escapes — resolved paths must be underrootDir.git,.vscode, etc. (matches npm/pnpm behavior)$HOMEimportLoreFileAsskips re-import when source file unchanged (mtime cache)Files changed
packages/core/src/workspace.tsdiscoverWorkspaceRoot()+resolveWorkspaces()packages/core/src/config.tsworkspacesfield to schemapackages/core/src/agents-file.tsimportLoreFileAs()packages/core/src/index.tspackages/core/test/workspace.test.tspackages/gateway/src/cli/run.tsdiscoverWorkspaceRoot(process.cwd())packages/gateway/src/config.tspackages/gateway/src/pipeline.tspackages/opencode/src/index.tsTest plan