Resolve internal paths via import.meta.url instead of cwd#762
Open
domdomegg wants to merge 1 commit intomindcraft-bots:developfrom
Open
Resolve internal paths via import.meta.url instead of cwd#762domdomegg wants to merge 1 commit intomindcraft-bots:developfrom
domdomegg wants to merge 1 commit intomindcraft-bots:developfrom
Conversation
agent_process.js spawns 'node src/process/init_agent.js', prompter.js reads './profiles/defaults/*.json', and coder.js reads './bots/*Template.js' — all relative to process.cwd(), so running 'node /path/to/mindcraft/main.js' from anywhere other than the repo root fails with ENOENT. Resolve relative to the source file instead. Also spawn process.execPath rather than 'node' so the child uses the same Node binary as the parent. No behavior change when run from the repo root.
Contributor
There was a problem hiding this comment.
Pull request overview
Updates internal file/path resolution to be based on module locations (import.meta.url / __dirname) rather than process.cwd(), allowing the project to run correctly when launched from outside the repo root.
Changes:
- Resolve
init_agent.jsviaimport.meta.urland spawn child processes usingprocess.execPath. - Load default profiles from
profiles/defaultsusing an absolute path derived from__dirname. - Load bot templates (
execTemplate.js,lintTemplate.js) using an absolute path derived fromimport.meta.url.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/process/agent_process.js | Makes agent child process startup independent of cwd by resolving init_agent.js from the module URL and using process.execPath. |
| src/models/prompter.js | Reads default profile JSON files via a __dirname-derived path instead of relative cwd paths. |
| src/agent/coder.js | Reads bot template files via a __dirname-derived path instead of relative cwd paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const agentProcess = spawn('node', args, { | ||
| const agentProcess = spawn(process.execPath, args, { | ||
| stdio: 'inherit', | ||
| stderr: 'inherit', |
There was a problem hiding this comment.
child_process.spawn does not support a stderr option; stderr handling is controlled via stdio. Keeping stderr: 'inherit' is misleading and has no effect. Consider removing it, or switching stdio to an explicit array if you need different behavior for stdin/stdout/stderr.
Suggested change
| stderr: 'inherit', |
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.
A few files read package-internal assets relative to
process.cwd(), so running from anywhere other than the repo root fails:src/process/agent_process.js:spawn('node', ['src/process/init_agent.js', ...])→ resolveinit_agent.jsviaimport.meta.url, and useprocess.execPathinstead of'node'so the child uses the same Node binary.src/models/prompter.js:readFileSync('./profiles/defaults/...')→path.join(__dirname, '../../profiles/defaults', ...)(it already had__dirnamedefined).src/agent/coder.js:readFile('./bots/execTemplate.js')→path.join(__dirname, '../../bots/execTemplate.js').No behavior change when run from the repo root.