Skip to content

fix(dag): resolve global dag-prompts from the configured config directory #380

Description

@LeXwDeX

Problem

Global DAG prompt lookup hardcodes ~/.config/opencode/dag-prompts, ignoring both OPENCODE_CONFIG_DIR and XDG_CONFIG_HOME. Other global DAG and memory assets consistently resolve through Flag.OPENCODE_CONFIG_DIR ?? Global.Path.config.

User Impact

Users with redirected config directories can successfully install/sync global prompt assets into the configured opencode directory, but prompt_template: { id } cannot resolve them and reports the misleading validation error prompt id ... does not resolve. This breaks every non-default XDG/config-dir setup.

Evidence

  • packages/opencode/src/dag/templates/resolve.ts:95: hardcoded path.join(os.homedir(), ".config", "opencode", "dag-prompts", ...).
  • packages/opencode/src/dag/workflows.ts:152, packages/opencode/src/dag/config.ts:116, and packages/opencode/src/memory/config.ts:167: sibling global assets use Flag.OPENCODE_CONFIG_DIR ?? Global.Path.config.
  • packages/core/src/plugin/command/dag-template-update.txt:16-24: the command contract explicitly requires OPENCODE_CONFIG_DIR and XDG support.
  • packages/opencode/src/dag/validation.ts:999-1000: unresolved prompt diagnostic.
  • packages/opencode/src/dag/templates/resolve.ts:42-44,97-102: safe-ID validation and project-first precedence that must remain unchanged.

Fix Requirements

  1. Resolve the global path with path.join(Flag.OPENCODE_CONFIG_DIR ?? Global.Path.config, "dag-prompts", ${id}.md).
  2. Preserve isSafeTemplateId, project-scoped precedence, interpolation, and diagnostics.
  3. Update the nearby comment describing the global directory.
  4. Add a focused OPENCODE_CONFIG_DIR redirection test in packages/opencode/test/dag/dag-templates.test.ts.

Non-goals

  • Do not add migration or symlink behavior.
  • Do not change project-scoped lookup, sanitization, interpolation, or diagnostic wording.

Acceptance Criteria

  • With OPENCODE_CONFIG_DIR=/tmp/x and /tmp/x/dag-prompts/foo.md present, prompt id foo resolves that file.
  • Default behavior remains unchanged when no override is set, including XDG resolution through Global.Path.config.
  • os.homedir is no longer used by dag/templates/resolve.ts.

Likely Code Locations

  • packages/opencode/src/dag/templates/resolve.ts
  • packages/opencode/test/dag/dag-templates.test.ts

Verification

cd packages/opencode && bun test test/dag/dag-templates.test.ts && bun typecheck
git grep -n "os.homedir" -- packages/opencode/src/dag/templates/resolve.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified and ready for an agent

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions