@lumy-pack/line-lore 0.0.1

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 (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +188 -0
  3. package/dist/ast/index.d.ts +1 -0
  4. package/dist/ast/parser.d.ts +6 -0
  5. package/dist/cache/file-cache.d.ts +19 -0
  6. package/dist/cache/index.d.ts +1 -0
  7. package/dist/cli.d.ts +1 -0
  8. package/dist/cli.mjs +2288 -0
  9. package/dist/commands/cache.d.ts +2 -0
  10. package/dist/commands/graph.d.ts +2 -0
  11. package/dist/commands/health.d.ts +2 -0
  12. package/dist/commands/index.d.ts +4 -0
  13. package/dist/commands/trace.d.ts +2 -0
  14. package/dist/components/TraceProgress.d.ts +7 -0
  15. package/dist/components/TraceResult.d.ts +8 -0
  16. package/dist/components/index.d.ts +2 -0
  17. package/dist/core/ancestry/ancestry.d.ts +10 -0
  18. package/dist/core/ancestry/index.d.ts +2 -0
  19. package/dist/core/ast-diff/ast-diff.d.ts +4 -0
  20. package/dist/core/ast-diff/comparison/index.d.ts +2 -0
  21. package/dist/core/ast-diff/comparison/structure-comparator.d.ts +4 -0
  22. package/dist/core/ast-diff/extraction/index.d.ts +2 -0
  23. package/dist/core/ast-diff/extraction/signature-hasher.d.ts +4 -0
  24. package/dist/core/ast-diff/extraction/symbol-extractor.d.ts +3 -0
  25. package/dist/core/ast-diff/index.d.ts +4 -0
  26. package/dist/core/blame/blame.d.ts +3 -0
  27. package/dist/core/blame/detection/cosmetic-detector.d.ts +7 -0
  28. package/dist/core/blame/detection/index.d.ts +2 -0
  29. package/dist/core/blame/index.d.ts +4 -0
  30. package/dist/core/blame/parsing/blame-parser.d.ts +2 -0
  31. package/dist/core/blame/parsing/index.d.ts +1 -0
  32. package/dist/core/core.d.ts +14 -0
  33. package/dist/core/index.d.ts +11 -0
  34. package/dist/core/issue-graph/index.d.ts +2 -0
  35. package/dist/core/issue-graph/issue-graph.d.ts +5 -0
  36. package/dist/core/patch-id/index.d.ts +2 -0
  37. package/dist/core/patch-id/patch-id.d.ts +11 -0
  38. package/dist/core/pr-lookup/index.d.ts +1 -0
  39. package/dist/core/pr-lookup/pr-lookup.d.ts +3 -0
  40. package/dist/errors.d.ts +32 -0
  41. package/dist/git/executor.d.ts +2 -0
  42. package/dist/git/health.d.ts +4 -0
  43. package/dist/git/index.d.ts +3 -0
  44. package/dist/git/remote.d.ts +6 -0
  45. package/dist/index.cjs +1904 -0
  46. package/dist/index.d.ts +6 -0
  47. package/dist/index.mjs +1872 -0
  48. package/dist/output/formats.d.ts +5 -0
  49. package/dist/output/index.d.ts +2 -0
  50. package/dist/output/normalizer.d.ts +11 -0
  51. package/dist/platform/github/github-adapter.d.ts +17 -0
  52. package/dist/platform/github/github-enterprise-adapter.d.ts +8 -0
  53. package/dist/platform/github/index.d.ts +2 -0
  54. package/dist/platform/gitlab/gitlab-adapter.d.ts +17 -0
  55. package/dist/platform/gitlab/gitlab-self-hosted-adapter.d.ts +8 -0
  56. package/dist/platform/gitlab/index.d.ts +2 -0
  57. package/dist/platform/index.d.ts +6 -0
  58. package/dist/platform/platform.d.ts +9 -0
  59. package/dist/platform/scheduler/index.d.ts +2 -0
  60. package/dist/platform/scheduler/request-scheduler.d.ts +17 -0
  61. package/dist/types/ast.d.ts +28 -0
  62. package/dist/types/blame.d.ts +34 -0
  63. package/dist/types/cache.d.ts +5 -0
  64. package/dist/types/git.d.ts +23 -0
  65. package/dist/types/graph.d.ts +15 -0
  66. package/dist/types/index.d.ts +11 -0
  67. package/dist/types/output.d.ts +24 -0
  68. package/dist/types/pipeline.d.ts +28 -0
  69. package/dist/types/platform.d.ts +44 -0
  70. package/dist/types/stage.d.ts +14 -0
  71. package/dist/types/trace.d.ts +38 -0
  72. package/dist/types/util.d.ts +4 -0
  73. package/dist/utils/command-registry.d.ts +29 -0
  74. package/dist/utils/index.d.ts +1 -0
  75. package/dist/utils/line-range.d.ts +2 -0
  76. package/dist/version.d.ts +1 -0
  77. package/package.json +71 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present Vincent K. Kelvin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,188 @@
1
+ # @lumy-pack/line-lore
2
+
3
+ Trace code lines to their originating Pull Requests via deterministic git blame analysis and platform APIs.
4
+
5
+ ## Features
6
+
7
+ - **Line-to-PR tracing**: Reverse-trace any code line to its source PR in seconds
8
+ - **4-stage pipeline**: Blame → Cosmetic detection → Ancestry traversal → PR lookup
9
+ - **Multi-platform support**: GitHub, GitHub Enterprise, GitLab, and GitLab self-hosted
10
+ - **Operating levels**: Graceful degradation from offline (Level 0) to full API access (Level 2)
11
+ - **Dual deployment**: Use as CLI tool or import as a programmatic library
12
+ - **Smart caching**: Built-in caching for git operations and API responses
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install @lumy-pack/line-lore
18
+ # or
19
+ yarn add @lumy-pack/line-lore
20
+ ```
21
+
22
+ ## Quick Start
23
+
24
+ ### CLI Usage
25
+
26
+ ```bash
27
+ # Trace a single line to its PR
28
+ npx @lumy-pack/line-lore trace src/auth.ts -L 42
29
+
30
+ # Trace a line range
31
+ npx @lumy-pack/line-lore trace src/config.ts -L 10,50
32
+
33
+ # Deep trace with squash PR exploration
34
+ npx @lumy-pack/line-lore trace src/auth.ts -L 42 --deep
35
+
36
+ # Traverse PR-to-issues graph
37
+ npx @lumy-pack/line-lore graph --pr 42 --depth 2
38
+
39
+ # Check system health
40
+ npx @lumy-pack/line-lore health
41
+
42
+ # Clear caches
43
+ npx @lumy-pack/line-lore cache clear
44
+
45
+ # Output as JSON
46
+ npx @lumy-pack/line-lore trace src/auth.ts -L 42 --output json
47
+
48
+ # Output for LLM consumption
49
+ npx @lumy-pack/line-lore trace src/auth.ts -L 42 --output llm
50
+
51
+ # Suppress formatting, return data only
52
+ npx @lumy-pack/line-lore trace src/auth.ts -L 42 --quiet
53
+ ```
54
+
55
+ ### Programmatic API
56
+
57
+ ```typescript
58
+ import { trace, health, clearCache } from '@lumy-pack/line-lore';
59
+
60
+ // Trace a line to its PR
61
+ const result = await trace({
62
+ file: 'src/auth.ts',
63
+ line: 42,
64
+ });
65
+
66
+ console.log(result.nodes); // TraceNode[]
67
+ console.log(result.operatingLevel); // 0 | 1 | 2
68
+ console.log(result.warnings); // degradation messages
69
+ ```
70
+
71
+ ## How It Works
72
+
73
+ @lumy-pack/line-lore executes a 4-stage deterministic pipeline:
74
+
75
+ 1. **Line → Commit (Blame)**: Git blame with `-C -C -M` flags to detect renames and copies
76
+ 2. **Cosmetic Detection**: AST structural comparison to skip formatting-only changes
77
+ 3. **Commit → Merge Commit**: Ancestry-path traversal + patch-id matching to resolve merge commits
78
+ 4. **Merge Commit → PR**: Commit message parsing + platform API lookup
79
+
80
+ No ML or heuristics — results are always reproducible.
81
+
82
+ ## Operating Levels
83
+
84
+ - **Level 0**: Git only (offline, fastest)
85
+ - **Level 1**: Platform CLI detected but not authenticated
86
+ - **Level 2**: Full API access (GitHub/GitLab authenticated)
87
+
88
+ Higher levels unlock deep tracing, issue graph traversal, and more accurate PR matching.
89
+
90
+ ## Platform Support
91
+
92
+ - GitHub.com
93
+ - GitHub Enterprise Server
94
+ - GitLab.com
95
+ - GitLab Self-Hosted
96
+
97
+ ## API Reference
98
+
99
+ ### `trace(options: TraceOptions): Promise<TraceFullResult>`
100
+
101
+ Trace a code line to its originating PR.
102
+
103
+ **Options:**
104
+ - `file` (string): Path to the file
105
+ - `line` (number): Starting line number (1-indexed)
106
+ - `endLine?` (number): Ending line for range queries
107
+ - `remote?` (string): Git remote name (default: 'origin')
108
+ - `deep?` (boolean): Enable deep trace for squash merges
109
+ - `graphDepth?` (number): Issue graph traversal depth
110
+ - `output?` ('human' | 'json' | 'llm'): Output format
111
+ - `quiet?` (boolean): Suppress formatting
112
+ - `noAst?` (boolean): Disable AST analysis
113
+ - `noCache?` (boolean): Disable caching
114
+
115
+ **Returns:**
116
+ ```typescript
117
+ {
118
+ nodes: TraceNode[]; // Ancestry nodes (commits, PRs, etc)
119
+ operatingLevel: 0 | 1 | 2; // Capability level
120
+ featureFlags: FeatureFlags; // Enabled features
121
+ warnings: string[]; // Degradation notices
122
+ }
123
+ ```
124
+
125
+ ### `health(options?: { cwd?: string }): Promise<HealthReport>`
126
+
127
+ Check system health: git version, platform CLI status, authentication.
128
+
129
+ ### `clearCache(): Promise<void>`
130
+
131
+ Clear PR lookup and patch-id caches.
132
+
133
+ ### `traverseIssueGraph(adapter, startType, startNumber, options?): Promise<GraphResult>`
134
+
135
+ Traverse PR-to-issues graph (requires Level 2 access).
136
+
137
+ ## CLI Reference
138
+
139
+ | Command | Purpose |
140
+ |---------|---------|
141
+ | `npx @lumy-pack/line-lore trace <file>` | Trace a line to its PR |
142
+ | `-L, --line <num>` | Starting line (required) |
143
+ | `--end-line <num>` | Ending line for range |
144
+ | `--deep` | Deep trace (squash merges) |
145
+ | `--output <format>` | Output as json, llm, or human |
146
+ | `--quiet` | Suppress formatting |
147
+ | `npx @lumy-pack/line-lore health` | Check system health |
148
+ | `npx @lumy-pack/line-lore graph --pr <num>` | Traverse PR graph |
149
+ | `--depth <num>` | Graph traversal depth |
150
+ | `npx @lumy-pack/line-lore cache clear` | Clear caches |
151
+
152
+ ## Error Handling
153
+
154
+ Errors are typed via `LineLoreError` with specific error codes:
155
+
156
+ ```typescript
157
+ import { trace, LineLoreError } from '@lumy-pack/line-lore';
158
+
159
+ try {
160
+ await trace({ file: 'src/auth.ts', line: 42 });
161
+ } catch (error) {
162
+ if (error instanceof LineLoreError) {
163
+ console.error(error.code); // e.g., 'FILE_NOT_FOUND'
164
+ console.error(error.message);
165
+ console.error(error.context); // additional metadata
166
+ }
167
+ }
168
+ ```
169
+
170
+ Common codes:
171
+ - `NOT_GIT_REPO` — not in a git repository
172
+ - `FILE_NOT_FOUND` — file does not exist
173
+ - `INVALID_LINE` — line number out of range
174
+ - `GIT_BLAME_FAILED` — git blame execution failed
175
+ - `PR_NOT_FOUND` — PR not found for commit
176
+ - `CLI_NOT_AUTHENTICATED` — platform CLI not authenticated
177
+ - `API_RATE_LIMITED` — platform API rate limit exceeded
178
+
179
+ ## Requirements
180
+
181
+ - Node.js >= 20
182
+ - Git >= 2.27
183
+ - Optional: `gh` CLI >= 2.0 (for GitHub API)
184
+ - Optional: `glab` CLI >= 1.30 (for GitLab API)
185
+
186
+ ## License
187
+
188
+ MIT
@@ -0,0 +1 @@
1
+ export { detectLanguage, extractSymbolsFromText, findSymbols, isAstAvailable, parseFile, } from './parser.js';
@@ -0,0 +1,6 @@
1
+ import type { SymbolInfo } from '../types/index.js';
2
+ export declare function isAstAvailable(): boolean;
3
+ export declare function detectLanguage(filePath: string): string | null;
4
+ export declare function parseFile(source: string, lang: string): Promise<unknown | null>;
5
+ export declare function findSymbols(source: string, lang: string): Promise<SymbolInfo[]>;
6
+ export declare function extractSymbolsFromText(source: string, lang: string): SymbolInfo[];
@@ -0,0 +1,19 @@
1
+ export declare class FileCache<T> {
2
+ private readonly filePath;
3
+ private readonly maxEntries;
4
+ private writeQueue;
5
+ constructor(fileName: string, options?: {
6
+ maxEntries?: number;
7
+ cacheDir?: string;
8
+ });
9
+ get(key: string): Promise<T | null>;
10
+ has(key: string): Promise<boolean>;
11
+ set(key: string, value: T): Promise<void>;
12
+ delete(key: string): Promise<boolean>;
13
+ clear(): Promise<void>;
14
+ size(): Promise<number>;
15
+ private doSet;
16
+ private readStore;
17
+ private writeStore;
18
+ destroy(): Promise<void>;
19
+ }
@@ -0,0 +1 @@
1
+ export { FileCache } from './file-cache.js';
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};