collections.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * Collections configuration management
  3. *
  4. * This module manages the YAML-based collection configuration at ~/.config/qmd/index.yml.
  5. * Collections define which directories to index and their associated contexts.
  6. */
  7. import type { ChunkStrategy } from "./store.js";
  8. /**
  9. * Context definitions for a collection
  10. * Key is path prefix (e.g., "/", "/2024", "/Board of Directors")
  11. * Value is the context description
  12. */
  13. export type ContextMap = Record<string, string>;
  14. /**
  15. * A single collection configuration
  16. */
  17. export interface Collection {
  18. path: string;
  19. pattern: string;
  20. ignore?: string[];
  21. context?: ContextMap;
  22. update?: string;
  23. includeByDefault?: boolean;
  24. /**
  25. * Chunking strategy for this collection (Phase 2 — i-bud0h8vu). When
  26. * unset, qmd falls back to the global CLI `--chunk-strategy` flag.
  27. *
  28. * - "auto" — char-based chunks with AST break points as hints.
  29. * - "regex" — char-based chunks without AST hints (legacy).
  30. * - "function" — one chunk per AST function/class/method range for
  31. * supported code files. Opt-in per collection; files
  32. * with zero detected ranges fall back to "auto".
  33. *
  34. * Changing this value requires a per-collection force-reindex
  35. * (`qmd update --force <collection>`). The `content_hash`-keyed rows
  36. * replace in-place, so other collections are unaffected.
  37. */
  38. chunkStrategy?: ChunkStrategy;
  39. }
  40. /**
  41. * Model configuration for embedding, reranking, and generation
  42. */
  43. export interface ModelsConfig {
  44. embed?: string;
  45. rerank?: string;
  46. generate?: string;
  47. }
  48. /**
  49. * The complete configuration file structure
  50. */
  51. export interface CollectionConfig {
  52. global_context?: string;
  53. editor_uri?: string;
  54. editor_uri_template?: string;
  55. collections: Record<string, Collection>;
  56. models?: ModelsConfig;
  57. }
  58. /**
  59. * Collection with its name (for return values)
  60. */
  61. export interface NamedCollection extends Collection {
  62. name: string;
  63. }
  64. /**
  65. * Set the config source for SDK mode.
  66. * - File path: load/save from a specific YAML file
  67. * - Inline config: use an in-memory CollectionConfig (saveConfig updates in place, no file I/O)
  68. * - undefined: reset to default file-based config
  69. */
  70. export declare function setConfigSource(source?: {
  71. configPath?: string;
  72. config?: CollectionConfig;
  73. }): void;
  74. /**
  75. * Set the current index name for config file lookup
  76. * Config file will be ~/.config/qmd/{indexName}.yml
  77. */
  78. export declare function setConfigIndexName(name: string): void;
  79. /**
  80. * Load configuration from the configured source.
  81. * - Inline config: returns the in-memory object directly
  82. * - File-based: reads from YAML file (default ~/.config/qmd/index.yml)
  83. * Returns empty config if file doesn't exist
  84. */
  85. export declare function loadConfig(): CollectionConfig;
  86. /**
  87. * Save configuration to the configured source.
  88. * - Inline config: updates the in-memory object (no file I/O)
  89. * - File-based: writes to YAML file (default ~/.config/qmd/index.yml)
  90. */
  91. export declare function saveConfig(config: CollectionConfig): void;
  92. /**
  93. * Get a specific collection by name
  94. * Returns null if not found
  95. */
  96. export declare function getCollection(name: string): NamedCollection | null;
  97. /**
  98. * List all collections
  99. */
  100. export declare function listCollections(): NamedCollection[];
  101. /**
  102. * Get collections that are included by default in queries
  103. */
  104. export declare function getDefaultCollections(): NamedCollection[];
  105. /**
  106. * Get collection names that are included by default
  107. */
  108. export declare function getDefaultCollectionNames(): string[];
  109. /**
  110. * Update a collection's settings
  111. */
  112. export declare function updateCollectionSettings(name: string, settings: {
  113. update?: string | null;
  114. includeByDefault?: boolean;
  115. }): boolean;
  116. /**
  117. * Add or update a collection
  118. */
  119. export declare function addCollection(name: string, path: string, pattern?: string): void;
  120. /**
  121. * Remove a collection
  122. */
  123. export declare function removeCollection(name: string): boolean;
  124. /**
  125. * Rename a collection
  126. */
  127. export declare function renameCollection(oldName: string, newName: string): boolean;
  128. /**
  129. * Get global context
  130. */
  131. export declare function getGlobalContext(): string | undefined;
  132. /**
  133. * Set global context
  134. */
  135. export declare function setGlobalContext(context: string | undefined): void;
  136. /**
  137. * Get all contexts for a collection
  138. */
  139. export declare function getContexts(collectionName: string): ContextMap | undefined;
  140. /**
  141. * Add or update a context for a specific path in a collection
  142. */
  143. export declare function addContext(collectionName: string, pathPrefix: string, contextText: string): boolean;
  144. /**
  145. * Remove a context from a collection
  146. */
  147. export declare function removeContext(collectionName: string, pathPrefix: string): boolean;
  148. /**
  149. * List all contexts across all collections
  150. */
  151. export declare function listAllContexts(): Array<{
  152. collection: string;
  153. path: string;
  154. context: string;
  155. }>;
  156. /**
  157. * Find best matching context for a given collection and path
  158. * Returns the most specific matching context (longest path prefix match)
  159. */
  160. export declare function findContextForPath(collectionName: string, filePath: string): string | undefined;
  161. /**
  162. * Get the config file path (useful for error messages)
  163. */
  164. export declare function getConfigPath(): string;
  165. /**
  166. * Check if config file exists
  167. */
  168. export declare function configExists(): boolean;
  169. /**
  170. * Validate a collection name
  171. * Collection names must be valid and not contain special characters
  172. */
  173. export declare function isValidCollectionName(name: string): boolean;