Skip to content

Ticket artifacts are being saved to project .ai/ instead of ~/.ai #163

Description

@williamthorsen

Problem

The MCP init_run tool (packages/mcp/src/tools/init-run.ts:67) hardcodes the artifact base directory as join(projectRoot, '.ai', ...), which places run artifacts at <projectDir>/.ai/ instead of the documented default ~/.ai/.

The artifact conventions (artifact-conventions.md) specify a preference cascade for resolving the base directory:

  1. artifacts.base_dir from <projectRoot>/.agents/preferences.yaml
  2. artifacts.base_dir from ~/.agents/preferences.yaml
  3. Default: ~/.ai

All non-MCP skills (save-artifact, save-plan, review-change) and the orchestrate skill's fallback path correctly follow this cascade. The MCP init_run tool is the only code path that ignores it.

Proposed solution

Implement the preference cascade directly in the MCP server so that init_run resolves the artifact base directory from preferences files automatically. Add an optional baseDir parameter as an explicit override for testing and advanced callers.

Key changes:

  • Add js-yaml dependency to the MCP package
  • Create resolve-base-dir.ts utility implementing the preference cascade
  • Update init_run to call the resolver instead of hardcoding the path
  • Add baseDir to the MCP tool schema
  • Update tests, orchestrate skill docs, and artifact conventions

Acceptance criteria

  • init_run defaults to ~/.ai when no preferences are set and no baseDir is passed
  • init_run reads artifacts.base_dir from project-level .agents/preferences.yaml
  • init_run falls back to global ~/.agents/preferences.yaml when project-level is absent
  • Relative base_dir values are resolved from projectRoot
  • Explicit baseDir parameter overrides the preference cascade
  • All existing MCP tests pass (updated with explicit baseDir for self-containment)
  • New resolve-base-dir tests cover the full cascade
  • pnpm run check passes at root

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions