types.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * Agent target abstraction for the installer.
  3. *
  4. * Each MCP-capable agent (Claude Code, Cursor, Codex CLI, opencode, ...)
  5. * implements this interface so the installer orchestrator can write the
  6. * right MCP-server config + instructions file + permissions for that
  7. * agent without baking client-specific paths into core code. Adding a
  8. * new agent = one new file in `targets/` + one entry in `registry.ts`.
  9. *
  10. * Closes the Claude-locked installer issue (upstream #137). The
  11. * runtime MCP server is already agent-agnostic; this brings the
  12. * installer to the same surface.
  13. */
  14. export type Location = 'global' | 'local';
  15. /**
  16. * Stable string id used in the `--target` CLI flag and the registry
  17. * lookup. New targets add a value here when they're added to the
  18. * registry. Keep these short and lowercase.
  19. */
  20. export type TargetId = 'claude' | 'cursor' | 'codex' | 'opencode' | 'hermes' | 'gemini' | 'antigravity' | 'kiro';
  21. /**
  22. * Result of `target.detect(location)`.
  23. *
  24. * `installed` is a best-effort heuristic that the agent's CLI / app /
  25. * config dir is present on this system — used to default the
  26. * multiselect prompt to "what's actually here." False positives are
  27. * acceptable (we still write); false negatives just mean the user
  28. * has to opt in manually.
  29. *
  30. * `alreadyConfigured` reports whether codegraph has already been
  31. * wired into this target at this location — drives the
  32. * "Updated"-vs-"Added" log line and lets `--check` exit 0/1.
  33. */
  34. export interface DetectionResult {
  35. installed: boolean;
  36. alreadyConfigured: boolean;
  37. /** Path inspected; surfaced in diagnostic / dry-run output. */
  38. configPath?: string;
  39. }
  40. /**
  41. * What `target.install(location)` actually changed on disk. The
  42. * orchestrator renders one log line per file using `action`.
  43. *
  44. * `unchanged` means we touched the file but its contents were already
  45. * what we'd write — used for byte-identical idempotent re-runs.
  46. */
  47. export interface WriteResult {
  48. files: Array<{
  49. path: string;
  50. action: 'created' | 'updated' | 'unchanged' | 'removed' | 'not-found' | 'kept';
  51. }>;
  52. /**
  53. * Optional one-line notes the orchestrator surfaces verbatim — e.g.
  54. * "Restart Cursor to apply." Keep these short; multi-line goes in
  55. * the README.
  56. */
  57. notes?: string[];
  58. }
  59. export interface InstallOptions {
  60. /**
  61. * Whether to write the agent's permissions / auto-allow surface
  62. * (Claude `settings.json`, others where applicable). When the
  63. * target has no permissions concept this option is a no-op.
  64. */
  65. autoAllow: boolean;
  66. }
  67. export interface AgentTarget {
  68. /** Stable id; matches the `TargetId` union. */
  69. readonly id: TargetId;
  70. /** Human-readable name shown in clack prompts and log lines. */
  71. readonly displayName: string;
  72. /** Optional URL for "where do I learn more about this agent." */
  73. readonly docsUrl?: string;
  74. /**
  75. * Whether this target supports the given install location.
  76. *
  77. * Some agents (Codex CLI as of 2026-05) have no project-local
  78. * config concept — only a single `~/.codex/` dir. Returning false
  79. * for an unsupported (target, location) pair lets the orchestrator
  80. * skip cleanly with a clear message.
  81. */
  82. supportsLocation(loc: Location): boolean;
  83. detect(loc: Location): DetectionResult;
  84. install(loc: Location, opts: InstallOptions): WriteResult;
  85. /**
  86. * Inverse of install. Removes only what install would have written;
  87. * preserves sibling MCP servers, sibling permissions, and unrelated
  88. * markdown sections. Must be safe to call when nothing was ever
  89. * installed (returns `not-found` actions).
  90. */
  91. uninstall(loc: Location): WriteResult;
  92. /**
  93. * Print the MCP-server snippet a user would paste manually for this
  94. * target. Used by `codegraph install --print-config <id>` and by
  95. * the README. Must NOT touch the filesystem.
  96. */
  97. printConfig(loc: Location): string;
  98. /** Filesystem paths this target would write to at this location. */
  99. describePaths(loc: Location): string[];
  100. /**
  101. * Optional. Write any project-local surfaces this target needs in
  102. * order to work fully when its MCP config is configured globally.
  103. * Called by `codegraph init` to bootstrap new projects without
  104. * forcing the user to re-run `codegraph install` per project.
  105. *
  106. * Most targets need nothing here — their global config is complete.
  107. * Cursor is the notable exception: its rules system
  108. * (`.cursor/rules/*.mdc`) is project-scoped only, and is what makes
  109. * Cursor's agent prefer codegraph over its built-in grep.
  110. *
  111. * Must be idempotent. Targets that have nothing project-local omit
  112. * the method entirely.
  113. */
  114. wireProjectSurfaces?(): WriteResult;
  115. }