Skip to content

Resolve internal paths via import.meta.url instead of cwd#762

Open
domdomegg wants to merge 1 commit intomindcraft-bots:developfrom
domdomegg:cwd-independent-paths
Open

Resolve internal paths via import.meta.url instead of cwd#762
domdomegg wants to merge 1 commit intomindcraft-bots:developfrom
domdomegg:cwd-independent-paths

Conversation

@domdomegg
Copy link
Copy Markdown

@domdomegg domdomegg commented Apr 15, 2026

A few files read package-internal assets relative to process.cwd(), so running from anywhere other than the repo root fails:

$ cd /tmp && node ~/mindcraft/main.js
Error: ENOENT: no such file or directory, open './profiles/defaults/_default.json'
  • src/process/agent_process.js: spawn('node', ['src/process/init_agent.js', ...]) → resolve init_agent.js via import.meta.url, and use process.execPath instead 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 __dirname defined).
  • src/agent/coder.js: readFile('./bots/execTemplate.js')path.join(__dirname, '../../bots/execTemplate.js').

No behavior change when run from the repo root.

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.
@domdomegg domdomegg marked this pull request as ready for review April 15, 2026 15:32
@Sweaterdog Sweaterdog requested a review from Copilot April 15, 2026 21:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.js via import.meta.url and spawn child processes using process.execPath.
  • Load default profiles from profiles/defaults using an absolute path derived from __dirname.
  • Load bot templates (execTemplate.js, lintTemplate.js) using an absolute path derived from import.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',
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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',

Copilot uses AI. Check for mistakes.
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.

2 participants