@side-quest/kit 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +54 -352
  3. package/dist/cli.d.ts +14 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +156 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/index.d.ts +8 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +8 -2509
  10. package/dist/index.js.map +1 -0
  11. package/dist/lib/ast/index.d.ts +11 -0
  12. package/dist/lib/ast/index.d.ts.map +1 -0
  13. package/dist/lib/ast/index.js +15 -0
  14. package/dist/lib/ast/index.js.map +1 -0
  15. package/dist/lib/ast/languages.d.ts +55 -0
  16. package/dist/lib/ast/languages.d.ts.map +1 -0
  17. package/dist/lib/ast/languages.js +146 -0
  18. package/dist/lib/ast/languages.js.map +1 -0
  19. package/dist/lib/ast/pattern.d.ts +84 -0
  20. package/dist/lib/ast/pattern.d.ts.map +1 -0
  21. package/dist/lib/ast/pattern.js +268 -0
  22. package/dist/lib/ast/pattern.js.map +1 -0
  23. package/dist/lib/ast/searcher.d.ts +89 -0
  24. package/dist/lib/ast/searcher.d.ts.map +1 -0
  25. package/dist/lib/ast/searcher.js +316 -0
  26. package/dist/lib/ast/searcher.js.map +1 -0
  27. package/dist/lib/ast/types.d.ts +93 -0
  28. package/dist/lib/ast/types.d.ts.map +1 -0
  29. package/dist/lib/ast/types.js +23 -0
  30. package/dist/lib/ast/types.js.map +1 -0
  31. package/dist/lib/commands/callers.d.ts +20 -0
  32. package/dist/lib/commands/callers.d.ts.map +1 -0
  33. package/dist/lib/commands/callers.js +162 -0
  34. package/dist/lib/commands/callers.js.map +1 -0
  35. package/dist/lib/commands/find.d.ts +15 -0
  36. package/dist/lib/commands/find.d.ts.map +1 -0
  37. package/dist/lib/commands/find.js +113 -0
  38. package/dist/lib/commands/find.js.map +1 -0
  39. package/dist/lib/commands/overview.d.ts +6 -0
  40. package/dist/lib/commands/overview.d.ts.map +1 -0
  41. package/dist/lib/commands/overview.js +52 -0
  42. package/dist/lib/commands/overview.js.map +1 -0
  43. package/dist/lib/commands/prime.d.ts +16 -0
  44. package/dist/lib/commands/prime.d.ts.map +1 -0
  45. package/dist/lib/commands/prime.js +168 -0
  46. package/dist/lib/commands/prime.js.map +1 -0
  47. package/dist/lib/commands/search.d.ts +20 -0
  48. package/dist/lib/commands/search.d.ts.map +1 -0
  49. package/dist/lib/commands/search.js +111 -0
  50. package/dist/lib/commands/search.js.map +1 -0
  51. package/dist/lib/errors.d.ts +80 -0
  52. package/dist/lib/errors.d.ts.map +1 -0
  53. package/dist/lib/errors.js +189 -0
  54. package/dist/lib/errors.js.map +1 -0
  55. package/dist/lib/formatters/output.d.ts +5 -0
  56. package/dist/lib/formatters/output.d.ts.map +1 -0
  57. package/dist/lib/formatters/output.js +5 -0
  58. package/dist/lib/formatters/output.js.map +1 -0
  59. package/dist/lib/formatters.d.ts +29 -0
  60. package/dist/lib/formatters.d.ts.map +1 -0
  61. package/dist/lib/formatters.js +141 -0
  62. package/dist/lib/formatters.js.map +1 -0
  63. package/dist/lib/index-tools.d.ts +108 -0
  64. package/dist/lib/index-tools.d.ts.map +1 -0
  65. package/dist/lib/index-tools.js +311 -0
  66. package/dist/lib/index-tools.js.map +1 -0
  67. package/dist/lib/index.d.ts +21 -0
  68. package/dist/lib/index.d.ts.map +1 -0
  69. package/dist/lib/index.js +42 -0
  70. package/dist/lib/index.js.map +1 -0
  71. package/dist/lib/kit-wrapper.d.ts +70 -0
  72. package/dist/lib/kit-wrapper.d.ts.map +1 -0
  73. package/dist/lib/kit-wrapper.js +462 -0
  74. package/dist/lib/kit-wrapper.js.map +1 -0
  75. package/dist/lib/logger.d.ts +28 -0
  76. package/dist/lib/logger.d.ts.map +1 -0
  77. package/dist/lib/logger.js +39 -0
  78. package/dist/lib/logger.js.map +1 -0
  79. package/dist/lib/types.d.ts +179 -0
  80. package/dist/lib/types.d.ts.map +1 -0
  81. package/dist/lib/types.js +48 -0
  82. package/dist/lib/types.js.map +1 -0
  83. package/dist/lib/utils/args.d.ts +40 -0
  84. package/dist/lib/utils/args.d.ts.map +1 -0
  85. package/dist/lib/utils/args.js +58 -0
  86. package/dist/lib/utils/args.js.map +1 -0
  87. package/dist/lib/utils/git.d.ts +23 -0
  88. package/dist/lib/utils/git.d.ts.map +1 -0
  89. package/dist/lib/utils/git.js +50 -0
  90. package/dist/lib/utils/git.js.map +1 -0
  91. package/dist/lib/utils/index-parser.d.ts +155 -0
  92. package/dist/lib/utils/index-parser.d.ts.map +1 -0
  93. package/dist/lib/utils/index-parser.js +252 -0
  94. package/dist/lib/utils/index-parser.js.map +1 -0
  95. package/dist/lib/validators.d.ts +138 -0
  96. package/dist/lib/validators.d.ts.map +1 -0
  97. package/dist/lib/validators.js +302 -0
  98. package/dist/lib/validators.js.map +1 -0
  99. package/dist/mcp/index.d.ts +19 -0
  100. package/dist/mcp/index.d.ts.map +1 -0
  101. package/dist/mcp/index.js +769 -0
  102. package/dist/mcp/index.js.map +1 -0
  103. package/package.json +5 -2
  104. package/src/cli.ts +170 -0
  105. package/src/lib/ast/index.ts +32 -0
  106. package/src/lib/ast/languages.ts +172 -0
  107. package/src/lib/ast/pattern.ts +299 -0
  108. package/src/lib/ast/searcher.ts +381 -0
  109. package/src/lib/ast/types.ts +99 -0
  110. package/src/lib/commands/callers.ts +226 -0
  111. package/src/lib/commands/find.ts +159 -0
  112. package/src/lib/commands/overview.ts +73 -0
  113. package/src/lib/commands/prime.ts +271 -0
  114. package/src/lib/commands/search.ts +146 -0
  115. package/src/lib/errors.ts +221 -0
  116. package/src/lib/formatters/output.ts +9 -0
  117. package/src/lib/formatters.ts +189 -0
  118. package/src/lib/index-tools.ts +471 -0
  119. package/src/lib/index.ts +122 -0
  120. package/src/lib/kit-wrapper.ts +675 -0
  121. package/src/lib/logger.ts +57 -0
  122. package/src/lib/types.ts +228 -0
  123. package/src/lib/utils/args.ts +72 -0
  124. package/src/lib/utils/git.ts +65 -0
  125. package/src/lib/utils/index-parser.ts +350 -0
  126. package/src/lib/validators.ts +437 -0
  127. package/src/mcp/index.ts +144 -79
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Kit Plugin Type Definitions
3
+ *
4
+ * Shared types for the Kit MCP server and CLI wrapper.
5
+ */
6
+ /**
7
+ * Response format options for tool output.
8
+ */
9
+ export declare enum ResponseFormat {
10
+ MARKDOWN = "markdown",
11
+ JSON = "json"
12
+ }
13
+ /**
14
+ * A single grep match result.
15
+ */
16
+ export interface GrepMatch {
17
+ /** Relative file path from repository root */
18
+ file: string;
19
+ /** Line number (1-indexed) */
20
+ line?: number;
21
+ /** Matched line content */
22
+ content: string;
23
+ }
24
+ /**
25
+ * Result of a grep search operation.
26
+ */
27
+ export interface GrepResult {
28
+ /** Number of matches found */
29
+ count: number;
30
+ /** Array of match objects */
31
+ matches: GrepMatch[];
32
+ /** Search pattern used */
33
+ pattern: string;
34
+ /** Repository path searched */
35
+ path: string;
36
+ }
37
+ /**
38
+ * Options for grep search.
39
+ */
40
+ export interface GrepOptions {
41
+ /** Search pattern (text or regex) */
42
+ pattern: string;
43
+ /** Repository path to search */
44
+ path?: string;
45
+ /** Case-sensitive search (default: true) */
46
+ caseSensitive?: boolean;
47
+ /** File pattern to include (e.g., "*.py") */
48
+ include?: string;
49
+ /** File pattern to exclude */
50
+ exclude?: string;
51
+ /** Maximum results to return (default: 100) */
52
+ maxResults?: number;
53
+ /** Subdirectory to search within */
54
+ directory?: string;
55
+ }
56
+ /**
57
+ * A single semantic search match.
58
+ */
59
+ export interface SemanticMatch {
60
+ /** Relative file path */
61
+ file: string;
62
+ /** Code chunk that matched */
63
+ chunk: string;
64
+ /** Relevance score (higher = more relevant) */
65
+ score: number;
66
+ /** Start line of the chunk */
67
+ startLine?: number;
68
+ /** End line of the chunk */
69
+ endLine?: number;
70
+ }
71
+ /**
72
+ * Result of a semantic search operation.
73
+ */
74
+ export interface SemanticResult {
75
+ /** Number of matches found */
76
+ count: number;
77
+ /** Array of semantic matches */
78
+ matches: SemanticMatch[];
79
+ /** Natural language query used */
80
+ query: string;
81
+ /** Repository path searched */
82
+ path: string;
83
+ /** Whether results came from fallback grep */
84
+ fallback?: boolean;
85
+ /** Install hint if semantic search unavailable */
86
+ installHint?: string;
87
+ }
88
+ /**
89
+ * Options for semantic search.
90
+ */
91
+ export interface SemanticOptions {
92
+ /** Natural language query */
93
+ query: string;
94
+ /** Repository path to search */
95
+ path?: string;
96
+ /** Number of results to return (default: 5) */
97
+ topK?: number;
98
+ /** Chunking strategy: 'symbols' or 'lines' */
99
+ chunkBy?: 'symbols' | 'lines';
100
+ /** Force rebuild of vector index */
101
+ buildIndex?: boolean;
102
+ }
103
+ /**
104
+ * A symbol usage/definition found by Kit.
105
+ */
106
+ export interface SymbolUsage {
107
+ /** File containing the symbol */
108
+ file: string;
109
+ /** Symbol type (function, class, variable, etc.) */
110
+ type: string;
111
+ /** Symbol name */
112
+ name: string;
113
+ /** Line number (may be null in current Kit version) */
114
+ line: number | null;
115
+ /** Context around the usage */
116
+ context: string | null;
117
+ }
118
+ /**
119
+ * Result of a symbol usages search.
120
+ */
121
+ export interface UsagesResult {
122
+ /** Number of usages found */
123
+ count: number;
124
+ /** Array of symbol usages */
125
+ usages: SymbolUsage[];
126
+ /** Symbol name searched for */
127
+ symbolName: string;
128
+ /** Repository path searched */
129
+ path: string;
130
+ }
131
+ /**
132
+ * Options for symbol usages search.
133
+ */
134
+ export interface UsagesOptions {
135
+ /** Repository path */
136
+ path?: string;
137
+ /** Symbol name to find usages for */
138
+ symbolName: string;
139
+ /** Filter by symbol type (function, class, etc.) */
140
+ symbolType?: string;
141
+ }
142
+ /**
143
+ * Error result type.
144
+ */
145
+ export interface ErrorResult {
146
+ /** Error message */
147
+ error: string;
148
+ /** Optional recovery hint */
149
+ hint?: string;
150
+ }
151
+ /**
152
+ * Generic result type that can be success or error.
153
+ */
154
+ export type KitResult<T> = T | ErrorResult;
155
+ /**
156
+ * Type guard for error results.
157
+ */
158
+ export declare function isError<T extends object>(result: KitResult<T>): result is ErrorResult;
159
+ /** Environment variable name for configuring default path */
160
+ export declare const KIT_DEFAULT_PATH_ENV = "KIT_DEFAULT_PATH";
161
+ /**
162
+ * Get the default path for Kit operations using cascading defaults:
163
+ * 1. KIT_DEFAULT_PATH environment variable (if set)
164
+ * 2. Current working directory (process.cwd())
165
+ *
166
+ * @returns Resolved default path for Kit operations
167
+ */
168
+ export declare function getDefaultKitPath(): string;
169
+ /** Default timeout for grep operations (ms) */
170
+ export declare const GREP_TIMEOUT = 30000;
171
+ /** Default timeout for semantic operations (ms) */
172
+ export declare const SEMANTIC_TIMEOUT = 60000;
173
+ /** Default timeout for symbol usages operations (ms) */
174
+ export declare const USAGES_TIMEOUT = 45000;
175
+ /** Default max results for grep */
176
+ export declare const DEFAULT_MAX_RESULTS = 100;
177
+ /** Default top-k for semantic search */
178
+ export declare const DEFAULT_TOP_K = 5;
179
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,oBAAY,cAAc;IACzB,QAAQ,aAAa;IACrB,IAAI,SAAS;CACb;AAMD;;GAEG;AACH,MAAM,WAAW,SAAS;IACzB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAA;IACZ,8BAA8B;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAA;CACf;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAA;IACb,6BAA6B;IAC7B,OAAO,EAAE,SAAS,EAAE,CAAA;IACpB,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,+BAA+B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;GAMG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED,+CAA+C;AAC/C,eAAO,MAAM,YAAY,QAAQ,CAAA;AAEjC,mDAAmD;AACnD,eAAO,MAAM,gBAAgB,QAAQ,CAAA;AAErC,wDAAwD;AACxD,eAAO,MAAM,cAAc,QAAQ,CAAA;AAEnC,mCAAmC;AACnC,eAAO,MAAM,mBAAmB,MAAM,CAAA;AAEtC,wCAAwC;AACxC,eAAO,MAAM,aAAa,IAAI,CAAA"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Kit Plugin Type Definitions
3
+ *
4
+ * Shared types for the Kit MCP server and CLI wrapper.
5
+ */
6
+ // ============================================================================
7
+ // Response Format
8
+ // ============================================================================
9
+ /**
10
+ * Response format options for tool output.
11
+ */
12
+ export var ResponseFormat;
13
+ (function (ResponseFormat) {
14
+ ResponseFormat["MARKDOWN"] = "markdown";
15
+ ResponseFormat["JSON"] = "json";
16
+ })(ResponseFormat || (ResponseFormat = {}));
17
+ /**
18
+ * Type guard for error results.
19
+ */
20
+ export function isError(result) {
21
+ return typeof result === 'object' && result !== null && 'error' in result;
22
+ }
23
+ // ============================================================================
24
+ // Default Configuration
25
+ // ============================================================================
26
+ /** Environment variable name for configuring default path */
27
+ export const KIT_DEFAULT_PATH_ENV = 'KIT_DEFAULT_PATH';
28
+ /**
29
+ * Get the default path for Kit operations using cascading defaults:
30
+ * 1. KIT_DEFAULT_PATH environment variable (if set)
31
+ * 2. Current working directory (process.cwd())
32
+ *
33
+ * @returns Resolved default path for Kit operations
34
+ */
35
+ export function getDefaultKitPath() {
36
+ return process.env[KIT_DEFAULT_PATH_ENV] || process.cwd();
37
+ }
38
+ /** Default timeout for grep operations (ms) */
39
+ export const GREP_TIMEOUT = 30000;
40
+ /** Default timeout for semantic operations (ms) */
41
+ export const SEMANTIC_TIMEOUT = 60000;
42
+ /** Default timeout for symbol usages operations (ms) */
43
+ export const USAGES_TIMEOUT = 45000;
44
+ /** Default max results for grep */
45
+ export const DEFAULT_MAX_RESULTS = 100;
46
+ /** Default top-k for semantic search */
47
+ export const DEFAULT_TOP_K = 5;
48
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E;;GAEG;AACH,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACzB,uCAAqB,CAAA;IACrB,+BAAa,CAAA;AACd,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AA2KD;;GAEG;AACH,MAAM,UAAU,OAAO,CACtB,MAAoB;IAEpB,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,IAAI,MAAM,CAAA;AAC1E,CAAC;AAED,+EAA+E;AAC/E,wBAAwB;AACxB,+EAA+E;AAE/E,6DAA6D;AAC7D,MAAM,CAAC,MAAM,oBAAoB,GAAG,kBAAkB,CAAA;AAEtD;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB;IAChC,OAAO,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAA;AAC1D,CAAC;AAED,+CAA+C;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAG,KAAK,CAAA;AAEjC,mDAAmD;AACnD,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAA;AAErC,wDAAwD;AACxD,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAA;AAEnC,mCAAmC;AACnC,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAA;AAEtC,wCAAwC;AACxC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAA"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Command-line argument parsing utilities
3
+ *
4
+ * Adapted from cinema-bandit plugin's argument parsing pattern.
5
+ * Parses arguments in the format: <command> [positional] [--flag value]
6
+ */
7
+ /**
8
+ * Parsed command-line arguments
9
+ */
10
+ export interface ParsedArgs {
11
+ /** The subcommand (e.g., "prime", "find", "callers") */
12
+ command: string;
13
+ /** Positional arguments after the command */
14
+ positional: string[];
15
+ /** Named flags (e.g., --format json, --force) */
16
+ flags: Record<string, string>;
17
+ }
18
+ /**
19
+ * Parses command-line arguments into a structured object.
20
+ *
21
+ * @param args - Raw arguments from process.argv.slice(2)
22
+ * @returns Parsed arguments with command, positional args, and flags
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * parseArgs(["prime"]);
27
+ * // { command: "prime", positional: [], flags: {} }
28
+ *
29
+ * parseArgs(["find", "MyFunction"]);
30
+ * // { command: "find", positional: ["MyFunction"], flags: {} }
31
+ *
32
+ * parseArgs(["find", "MyFunction", "--format", "json"]);
33
+ * // { command: "find", positional: ["MyFunction"], flags: { "format": "json" } }
34
+ *
35
+ * parseArgs(["prime", "--force"]);
36
+ * // { command: "prime", positional: [], flags: { "force": "true" } }
37
+ * ```
38
+ */
39
+ export declare function parseArgs(args: string[]): ParsedArgs;
40
+ //# sourceMappingURL=args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/args.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B,wDAAwD;IACxD,OAAO,EAAE,MAAM,CAAA;IACf,6CAA6C;IAC7C,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CA+BpD"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Command-line argument parsing utilities
3
+ *
4
+ * Adapted from cinema-bandit plugin's argument parsing pattern.
5
+ * Parses arguments in the format: <command> [positional] [--flag value]
6
+ */
7
+ /**
8
+ * Parses command-line arguments into a structured object.
9
+ *
10
+ * @param args - Raw arguments from process.argv.slice(2)
11
+ * @returns Parsed arguments with command, positional args, and flags
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * parseArgs(["prime"]);
16
+ * // { command: "prime", positional: [], flags: {} }
17
+ *
18
+ * parseArgs(["find", "MyFunction"]);
19
+ * // { command: "find", positional: ["MyFunction"], flags: {} }
20
+ *
21
+ * parseArgs(["find", "MyFunction", "--format", "json"]);
22
+ * // { command: "find", positional: ["MyFunction"], flags: { "format": "json" } }
23
+ *
24
+ * parseArgs(["prime", "--force"]);
25
+ * // { command: "prime", positional: [], flags: { "force": "true" } }
26
+ * ```
27
+ */
28
+ export function parseArgs(args) {
29
+ const command = args[0] ?? '';
30
+ const positional = [];
31
+ const flags = {};
32
+ let i = 1;
33
+ while (i < args.length) {
34
+ const arg = args[i];
35
+ if (arg.startsWith('--')) {
36
+ // Handle --flag or --flag value
37
+ const key = arg.slice(2);
38
+ const nextArg = args[i + 1];
39
+ // Check if there's a value after the flag
40
+ if (nextArg && !nextArg.startsWith('--')) {
41
+ flags[key] = nextArg;
42
+ i += 2;
43
+ }
44
+ else {
45
+ // Boolean flag (no value)
46
+ flags[key] = 'true';
47
+ i++;
48
+ }
49
+ }
50
+ else {
51
+ // Positional argument
52
+ positional.push(arg);
53
+ i++;
54
+ }
55
+ }
56
+ return { command, positional, flags };
57
+ }
58
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.js","sourceRoot":"","sources":["../../../src/lib/utils/args.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,SAAS,CAAC,IAAc;IACvC,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IAC7B,MAAM,UAAU,GAAa,EAAE,CAAA;IAC/B,MAAM,KAAK,GAA2B,EAAE,CAAA;IAExC,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAW,CAAA;QAE7B,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,gCAAgC;YAChC,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;YACxB,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;YAE3B,0CAA0C;YAC1C,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1C,KAAK,CAAC,GAAG,CAAC,GAAG,OAAO,CAAA;gBACpB,CAAC,IAAI,CAAC,CAAA;YACP,CAAC;iBAAM,CAAC;gBACP,0BAA0B;gBAC1B,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAA;gBACnB,CAAC,EAAE,CAAA;YACJ,CAAC;QACF,CAAC;aAAM,CAAC;YACP,sBAAsB;YACtB,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACpB,CAAC,EAAE,CAAA;QACJ,CAAC;IACF,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAA;AACtC,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Find the git repository root directory (async).
3
+ * @returns The git root path, or null if not in a git repo
4
+ */
5
+ export declare function findGitRoot(): Promise<string | null>;
6
+ /**
7
+ * Find the git repository root directory (synchronous).
8
+ * @returns The git root path, or undefined if not in a git repo
9
+ */
10
+ export declare function findGitRootSync(): string | undefined;
11
+ /**
12
+ * Resolve the target directory for operations.
13
+ * Uses custom path if provided, falls back to git root, then cwd.
14
+ * @param customPath - Optional custom path to use
15
+ * @returns Resolved target directory path
16
+ */
17
+ export declare function getTargetDir(customPath?: string): Promise<string>;
18
+ /**
19
+ * Constants for index file management
20
+ */
21
+ export declare const INDEX_FILE = "PROJECT_INDEX.json";
22
+ export declare const MAX_AGE_HOURS = 24;
23
+ //# sourceMappingURL=git.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/git.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAgB1D;AAED;;;GAGG;AACH,wBAAgB,eAAe,IAAI,MAAM,GAAG,SAAS,CAMpD;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAWvE;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,uBAAuB,CAAA;AAC9C,eAAO,MAAM,aAAa,KAAK,CAAA"}
@@ -0,0 +1,50 @@
1
+ import { resolve } from 'node:path';
2
+ import { ensureCommandAvailable, spawnSyncCollect, spawnWithTimeout, } from '@side-quest/core/spawn';
3
+ /**
4
+ * Find the git repository root directory (async).
5
+ * @returns The git root path, or null if not in a git repo
6
+ */
7
+ export async function findGitRoot() {
8
+ const gitCmd = ensureCommandAvailable('git');
9
+ const result = await spawnWithTimeout([gitCmd, 'rev-parse', '--show-toplevel'], 10_000);
10
+ if (result.timedOut || result.exitCode !== 0) {
11
+ return null;
12
+ }
13
+ if (result.stdout) {
14
+ return result.stdout.trim();
15
+ }
16
+ return null;
17
+ }
18
+ /**
19
+ * Find the git repository root directory (synchronous).
20
+ * @returns The git root path, or undefined if not in a git repo
21
+ */
22
+ export function findGitRootSync() {
23
+ const result = spawnSyncCollect(['git', 'rev-parse', '--show-toplevel']);
24
+ if (result.exitCode === 0 && result.stdout.trim()) {
25
+ return result.stdout.trim();
26
+ }
27
+ return undefined;
28
+ }
29
+ /**
30
+ * Resolve the target directory for operations.
31
+ * Uses custom path if provided, falls back to git root, then cwd.
32
+ * @param customPath - Optional custom path to use
33
+ * @returns Resolved target directory path
34
+ */
35
+ export async function getTargetDir(customPath) {
36
+ if (customPath) {
37
+ return resolve(customPath);
38
+ }
39
+ const gitRoot = await findGitRoot();
40
+ if (gitRoot) {
41
+ return gitRoot;
42
+ }
43
+ return process.cwd();
44
+ }
45
+ /**
46
+ * Constants for index file management
47
+ */
48
+ export const INDEX_FILE = 'PROJECT_INDEX.json';
49
+ export const MAX_AGE_HOURS = 24;
50
+ //# sourceMappingURL=git.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.js","sourceRoot":"","sources":["../../../src/lib/utils/git.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EACN,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,GAChB,MAAM,wBAAwB,CAAA;AAE/B;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAChC,MAAM,MAAM,GAAG,sBAAsB,CAAC,KAAK,CAAC,CAAA;IAC5C,MAAM,MAAM,GAAG,MAAM,gBAAgB,CACpC,CAAC,MAAM,EAAE,WAAW,EAAE,iBAAiB,CAAC,EACxC,MAAM,CACN,CAAA;IAED,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;IAC5B,CAAC;IAED,OAAO,IAAI,CAAA;AACZ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC9B,MAAM,MAAM,GAAG,gBAAgB,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAA;IACxE,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACnD,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAA;IAC5B,CAAC;IACD,OAAO,SAAS,CAAA;AACjB,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,UAAmB;IACrD,IAAI,UAAU,EAAE,CAAC;QAChB,OAAO,OAAO,CAAC,UAAU,CAAC,CAAA;IAC3B,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,WAAW,EAAE,CAAA;IACnC,IAAI,OAAO,EAAE,CAAC;QACb,OAAO,OAAO,CAAA;IACf,CAAC;IAED,OAAO,OAAO,CAAC,GAAG,EAAE,CAAA;AACrB,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,oBAAoB,CAAA;AAC9C,MAAM,CAAC,MAAM,aAAa,GAAG,EAAE,CAAA"}
@@ -0,0 +1,155 @@
1
+ /**
2
+ * PROJECT_INDEX.json parser and query utilities
3
+ *
4
+ * Provides TypeScript-based queries to replace jq dependencies.
5
+ * Supports git-style directory search to find index from any subdirectory.
6
+ */
7
+ /**
8
+ * Symbol definition from Kit CLI index
9
+ */
10
+ export interface Symbol {
11
+ name: string;
12
+ type: 'function' | 'class' | 'interface' | 'type' | 'constant' | 'variable';
13
+ start_line: number;
14
+ end_line: number;
15
+ code: string;
16
+ file: string;
17
+ }
18
+ /**
19
+ * File tree entry
20
+ */
21
+ export interface FileTreeEntry {
22
+ path: string;
23
+ is_dir: boolean;
24
+ name: string;
25
+ size: number;
26
+ }
27
+ /**
28
+ * PROJECT_INDEX.json structure (from Kit CLI)
29
+ */
30
+ export interface ProjectIndex {
31
+ file_tree: FileTreeEntry[];
32
+ files: FileTreeEntry[];
33
+ symbols: Record<string, Symbol[]>;
34
+ }
35
+ /**
36
+ * Search up directory tree for PROJECT_INDEX.json (git-style)
37
+ *
38
+ * Note: Delegates to @sidequest/core/fs findUpSync for the file search.
39
+ *
40
+ * @param startDir - Directory to start searching from (default: process.cwd())
41
+ * @returns Absolute path to PROJECT_INDEX.json
42
+ * @throws Error if index not found
43
+ */
44
+ export declare function findProjectIndex(startDir?: string): Promise<string>;
45
+ /**
46
+ * Resolve explicit path to PROJECT_INDEX.json
47
+ *
48
+ * Handles three cases:
49
+ * 1. Path to PROJECT_INDEX.json file directly
50
+ * 2. Path to directory containing PROJECT_INDEX.json
51
+ * 3. Relative path that needs resolution
52
+ *
53
+ * @param explicitPath - Explicit path provided by user
54
+ * @returns Absolute path to PROJECT_INDEX.json
55
+ * @throws Error if index not found at specified path
56
+ */
57
+ export declare function resolveExplicitIndexPath(explicitPath: string): string;
58
+ /**
59
+ * Load and parse PROJECT_INDEX.json
60
+ *
61
+ * @param explicitPath - Optional explicit path to index file or directory
62
+ * @returns Parsed project index
63
+ * @throws Error if index not found or invalid JSON
64
+ */
65
+ export declare function loadProjectIndex(explicitPath?: string): Promise<ProjectIndex>;
66
+ /**
67
+ * Find symbols by name across all files
68
+ *
69
+ * @param index - Project index
70
+ * @param symbolName - Symbol name to search for (exact match)
71
+ * @returns Array of matching symbols with their file paths
72
+ */
73
+ export declare function findSymbol(index: ProjectIndex, symbolName: string): Array<{
74
+ file: string;
75
+ symbol: Symbol;
76
+ }>;
77
+ /**
78
+ * Find symbols by fuzzy name matching (case-insensitive substring)
79
+ *
80
+ * @param index - Project index
81
+ * @param query - Search query (substring, case-insensitive)
82
+ * @returns Array of matching symbols with their file paths
83
+ */
84
+ export declare function findSymbolFuzzy(index: ProjectIndex, query: string): Array<{
85
+ file: string;
86
+ symbol: Symbol;
87
+ score: number;
88
+ }>;
89
+ /**
90
+ * Get all symbols in a file
91
+ *
92
+ * @param index - Project index
93
+ * @param filePath - File path (can be relative or absolute)
94
+ * @returns Array of symbols in the file
95
+ */
96
+ export declare function getFileSymbols(index: ProjectIndex, filePath: string): Symbol[];
97
+ /**
98
+ * Get all files with their symbol counts
99
+ *
100
+ * @param index - Project index
101
+ * @returns Array of files with symbol counts
102
+ */
103
+ export declare function getFileStats(index: ProjectIndex): Array<{
104
+ file: string;
105
+ symbolCount: number;
106
+ }>;
107
+ /**
108
+ * Get symbol distribution by type
109
+ *
110
+ * @param index - Project index
111
+ * @returns Record of symbol types to counts
112
+ */
113
+ export declare function getSymbolTypeDistribution(index: ProjectIndex): Record<string, number>;
114
+ /**
115
+ * Get all exported symbols (heuristic: uppercase or common export patterns)
116
+ *
117
+ * Note: Kit index doesn't have explicit "exported" flag, so we use naming conventions
118
+ *
119
+ * @param index - Project index
120
+ * @returns Array of likely exported symbols
121
+ */
122
+ export declare function getExportedSymbols(index: ProjectIndex): Array<{
123
+ file: string;
124
+ symbol: Symbol;
125
+ }>;
126
+ /**
127
+ * Group symbols by directory
128
+ *
129
+ * @param index - Project index
130
+ * @returns Record of directory paths to symbol counts
131
+ */
132
+ export declare function groupSymbolsByDirectory(index: ProjectIndex): Record<string, number>;
133
+ /**
134
+ * Get directory with most symbols (complexity hotspot)
135
+ *
136
+ * @param index - Project index
137
+ * @param topN - Number of top directories to return
138
+ * @returns Array of directories sorted by symbol count
139
+ */
140
+ export declare function getComplexityHotspots(index: ProjectIndex, topN?: number): Array<{
141
+ directory: string;
142
+ symbolCount: number;
143
+ }>;
144
+ /**
145
+ * Get all symbols of a specific type
146
+ *
147
+ * @param index - Project index
148
+ * @param type - Symbol type to filter by
149
+ * @returns Array of matching symbols with file paths
150
+ */
151
+ export declare function getSymbolsByType(index: ProjectIndex, type: Symbol['type']): Array<{
152
+ file: string;
153
+ symbol: Symbol;
154
+ }>;
155
+ //# sourceMappingURL=index-parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-parser.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/index-parser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;GAEG;AACH,MAAM,WAAW,MAAM;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,UAAU,GAAG,OAAO,GAAG,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