can1357/oh-my-pi · error
Cannot resolve ${this.#createScope} agents directory.
Error message
Cannot resolve ${this.#createScope} agents directory. What it means
When saving a generated agent, the hub resolves the target agents directory via getAgentsDirectories (filtered to the chosen create scope: user or project). If the resolved list yields no path for that scope, it cannot determine where to write the <identifier>.md file and throws this templated error naming the scope.
Source
Thrown at packages/coding-agent/src/modes/components/agents-hub.ts:816
}
return parseGeneratedAgentSpec(raw);
} finally {
unsubscribe();
await session.dispose();
}
}
async #saveGeneratedAgent(): Promise<void> {
const spec = this.#createSpec;
if (!spec) return;
const dirs = getConfigDirs("agents", {
user: this.#createScope === "user",
project: this.#createScope === "project",
cwd: this.#cwd,
});
const targetDir = dirs[0]?.path;
if (!targetDir) {
throw new Error(`Cannot resolve ${this.#createScope} agents directory.`);
}
const filePath = path.join(targetDir, `${spec.identifier}.md`);
try {
await fs.stat(filePath);
throw new Error(`Agent file already exists: ${shortenPath(filePath)}`);
} catch (error) {
if (!isEnoent(error)) throw error;
}
const frontmatter = YAML.stringify({ name: spec.identifier, description: spec.whenToUse }, null, 2).trimEnd();
const content = `---\n${frontmatter}\n---\n\n${spec.systemPrompt.trim()}\n`;
await Bun.write(filePath, content);
await refreshAgentDiscovery(this.#cwd, this.#extensionRoots());
this.#clearCreateFlow();
this.#notice = `Created agent ${spec.identifier} at ${shortenPath(filePath)}`;
await this.#reload();
}
// ═══════════════════════════════════════════════════════════════════════View on GitHub (pinned to 9690622007)
Solutions
- Verify the cwd is a valid project directory when creating project-scoped agents, or switch scope to 'user'
- Ensure HOME / user config directories are set and writable
- Manually create the agents directory expected for the scope
- Reopen the hub so createScope and the directory resolution are recomputed
Example fix
// before createScope: "project" in a non-project cwd -> dirs[0] undefined // after createScope: "user" -> resolves ~/.config/omp/agents/agent-name.md
Defensive patterns
Strategy: fallback
Validate before calling
const dirs = await getAgentsDirectories({ user: scope === "user", project: scope === "project", cwd });
if (!dirs[0]?.path) throw new Error(`Agents dir for scope '${scope}' unresolved`); Try / catch
try {
await hub.saveGeneratedAgent(spec);
} catch (err) {
if (err instanceof Error && err.message.includes("Cannot resolve")) {
// switch scope to user or fix cwd/HOME, then retry
} else throw err;
} Prevention
- Run the CLI inside a real project directory for project-scoped agents
- Ensure HOME and config directories are set and writable
- Prefer user scope when cwd may not be a project root
- Create agents directories ahead of time in setup scripts
When it happens
Trigger: Writing a newly created agent when getAgentsDirectories({user, project, cwd}) returns an empty or first-entry-less result for this.#createScope — e.g. scope set to 'project' but the directory resolution can't produce a project agents dir for the cwd.
Common situations: cwd is not a recognized project root so project-level agents dir can't be resolved; user config dir (e.g. ~/.config/omp/agents) unresolvable due to HOME unset or permission issues; createScope value inconsistent with the dirs request.
Related errors
- cannot move {0} to a subdirectory of itself, {1}
- Agent file already exists: ${shortenPath(filePath)}
- Could not find agent compaction prompts
- Unpacked ASAR file '${label}' is a directory
- unknown filetype: {ft_debug}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/6eb3cabf721133ad.
Report an issue: GitHub.