{"record":{"id":"6eb3cabf721133ad","repo":"can1357/oh-my-pi","slug":"cannot-resolve-this-createscope-agents-directo","errorCode":null,"errorMessage":"Cannot resolve ${this.#createScope} agents directory.","messagePattern":"Cannot resolve (.+?) agents directory\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/modes/components/agents-hub.ts","lineNumber":816,"sourceCode":"\t\t\t}\n\t\t\treturn parseGeneratedAgentSpec(raw);\n\t\t} finally {\n\t\t\tunsubscribe();\n\t\t\tawait session.dispose();\n\t\t}\n\t}\n\n\tasync #saveGeneratedAgent(): Promise<void> {\n\t\tconst spec = this.#createSpec;\n\t\tif (!spec) return;\n\t\tconst dirs = getConfigDirs(\"agents\", {\n\t\t\tuser: this.#createScope === \"user\",\n\t\t\tproject: this.#createScope === \"project\",\n\t\t\tcwd: this.#cwd,\n\t\t});\n\t\tconst targetDir = dirs[0]?.path;\n\t\tif (!targetDir) {\n\t\t\tthrow new Error(`Cannot resolve ${this.#createScope} agents directory.`);\n\t\t}\n\t\tconst filePath = path.join(targetDir, `${spec.identifier}.md`);\n\t\ttry {\n\t\t\tawait fs.stat(filePath);\n\t\t\tthrow new Error(`Agent file already exists: ${shortenPath(filePath)}`);\n\t\t} catch (error) {\n\t\t\tif (!isEnoent(error)) throw error;\n\t\t}\n\t\tconst frontmatter = YAML.stringify({ name: spec.identifier, description: spec.whenToUse }, null, 2).trimEnd();\n\t\tconst content = `---\\n${frontmatter}\\n---\\n\\n${spec.systemPrompt.trim()}\\n`;\n\t\tawait Bun.write(filePath, content);\n\t\tawait refreshAgentDiscovery(this.#cwd, this.#extensionRoots());\n\t\tthis.#clearCreateFlow();\n\t\tthis.#notice = `Created agent ${spec.identifier} at ${shortenPath(filePath)}`;\n\t\tawait this.#reload();\n\t}\n\n\t// ═══════════════════════════════════════════════════════════════════════","sourceCodeStart":798,"sourceCodeEnd":834,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/modes/components/agents-hub.ts#L798-L834","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ncreateScope: \"project\" in a non-project cwd -> dirs[0] undefined\n// after\ncreateScope: \"user\" -> resolves ~/.config/omp/agents/agent-name.md","handlingStrategy":"fallback","validationCode":"const dirs = await getAgentsDirectories({ user: scope === \"user\", project: scope === \"project\", cwd });\nif (!dirs[0]?.path) throw new Error(`Agents dir for scope '${scope}' unresolved`);","typeGuard":null,"tryCatchPattern":"try {\n  await hub.saveGeneratedAgent(spec);\n} catch (err) {\n  if (err instanceof Error && err.message.includes(\"Cannot resolve\")) {\n    // switch scope to user or fix cwd/HOME, then retry\n  } else throw err;\n}","preventionTips":["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"],"tags":["filesystem","path-resolution","agents"],"backgroundTag":"directory-resolution-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}