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

  1. Verify the cwd is a valid project directory when creating project-scoped agents, or switch scope to 'user'
  2. Ensure HOME / user config directories are set and writable
  3. Manually create the agents directory expected for the scope
  4. 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

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


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/6eb3cabf721133ad. Report an issue: GitHub.