-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add HTTP transport mode and server config file support #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+371
−28
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
08539c6
feat: add server config file support for pre-registering projects
PatrickSys a844e53
style: apply prettier formatting
PatrickSys 912e6f6
fix(config): reject empty roots and invalid ports
PatrickSys c637bf5
fix(deps): patch picomatch audit path
PatrickSys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import os from 'node:os'; | ||
| import { promises as fs } from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| export interface ProjectConfig { | ||
| root: string; | ||
| excludePatterns?: string[]; | ||
| } | ||
|
|
||
| export interface ServerConfig { | ||
| projects?: ProjectConfig[]; | ||
| server?: { port?: number; host?: string }; | ||
| } | ||
|
|
||
| function expandTilde(filePath: string): string { | ||
| if (filePath === '~' || filePath.startsWith('~/') || filePath.startsWith('~\\')) { | ||
| return path.join(os.homedir(), filePath.slice(1)); | ||
| } | ||
| return filePath; | ||
| } | ||
|
|
||
| export async function loadServerConfig(): Promise<ServerConfig | null> { | ||
| const configPath = | ||
| process.env.CODEBASE_CONTEXT_CONFIG_PATH ?? | ||
| path.join(os.homedir(), '.codebase-context', 'config.json'); | ||
|
|
||
| let raw: string; | ||
| try { | ||
| raw = await fs.readFile(configPath, 'utf8'); | ||
| } catch (err) { | ||
| if ((err as NodeJS.ErrnoException).code === 'ENOENT') { | ||
| return null; | ||
| } | ||
| console.error(`[config] Failed to load config: ${(err as Error).message}`); | ||
| return null; | ||
| } | ||
|
|
||
| let parsed: unknown; | ||
| try { | ||
| parsed = JSON.parse(raw); | ||
| } catch (err) { | ||
| console.error(`[config] Failed to load config: ${(err as Error).message}`); | ||
| return null; | ||
| } | ||
|
|
||
| if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) { | ||
| return null; | ||
| } | ||
|
|
||
| const config = parsed as Record<string, unknown>; | ||
| const result: ServerConfig = {}; | ||
|
|
||
| // Resolve projects | ||
| if (Array.isArray(config.projects)) { | ||
| result.projects = (config.projects as unknown[]) | ||
| .filter((p): p is Record<string, unknown> => typeof p === 'object' && p !== null) | ||
| .map((p) => { | ||
| const rawRoot = typeof p.root === 'string' ? p.root.trim() : ''; | ||
| if (!rawRoot) { | ||
| console.error('[config] Skipping project entry with missing or empty root'); | ||
| return null; | ||
| } | ||
| const resolvedRoot = path.resolve(expandTilde(rawRoot)); | ||
PatrickSys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const proj: ProjectConfig = { root: resolvedRoot }; | ||
| if (Array.isArray(p.excludePatterns)) { | ||
| proj.excludePatterns = p.excludePatterns.filter( | ||
| (pattern): pattern is string => typeof pattern === 'string' | ||
| ); | ||
| } | ||
| return proj; | ||
| }) | ||
| .filter((project): project is ProjectConfig => project !== null); | ||
| } | ||
|
|
||
| // Resolve server options | ||
| if (typeof config.server === 'object' && config.server !== null) { | ||
| const srv = config.server as Record<string, unknown>; | ||
| result.server = {}; | ||
|
|
||
| if (typeof srv.host === 'string') { | ||
| result.server.host = srv.host; | ||
| } | ||
|
|
||
| if (srv.port !== undefined) { | ||
| const portValue = srv.port; | ||
| const portNum = typeof portValue === 'number' ? portValue : Number(portValue); | ||
| if (Number.isInteger(portNum) && portNum > 0 && portNum <= 65535) { | ||
| result.server.port = portNum; | ||
| } else { | ||
| console.error(`[config] Ignoring invalid server.port: ${portValue}`); | ||
| } | ||
| } | ||
PatrickSys marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return result; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.