@tonycasey/lisa 2.25.4 → 2.26.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 (72) hide show
  1. package/dist/lib/application/handlers/SessionStartHandler.d.ts +15 -0
  2. package/dist/lib/application/handlers/SessionStartHandler.d.ts.map +1 -1
  3. package/dist/lib/application/handlers/SessionStartHandler.js +116 -5
  4. package/dist/lib/application/handlers/SessionStartHandler.js.map +1 -1
  5. package/dist/lib/application/services/GitTriageService.d.ts +45 -0
  6. package/dist/lib/application/services/GitTriageService.d.ts.map +1 -0
  7. package/dist/lib/application/services/GitTriageService.js +360 -0
  8. package/dist/lib/application/services/GitTriageService.js.map +1 -0
  9. package/dist/lib/application/services/SessionContextFormatter.d.ts +11 -1
  10. package/dist/lib/application/services/SessionContextFormatter.d.ts.map +1 -1
  11. package/dist/lib/application/services/SessionContextFormatter.js +59 -3
  12. package/dist/lib/application/services/SessionContextFormatter.js.map +1 -1
  13. package/dist/lib/application/services/index.d.ts +1 -0
  14. package/dist/lib/application/services/index.d.ts.map +1 -1
  15. package/dist/lib/application/services/index.js +3 -1
  16. package/dist/lib/application/services/index.js.map +1 -1
  17. package/dist/lib/domain/interfaces/ICommitEnricher.d.ts +81 -0
  18. package/dist/lib/domain/interfaces/ICommitEnricher.d.ts.map +1 -0
  19. package/dist/lib/domain/interfaces/ICommitEnricher.js +33 -0
  20. package/dist/lib/domain/interfaces/ICommitEnricher.js.map +1 -0
  21. package/dist/lib/domain/interfaces/IGitClient.d.ts +86 -0
  22. package/dist/lib/domain/interfaces/IGitClient.d.ts.map +1 -1
  23. package/dist/lib/domain/interfaces/IGitTriageService.d.ts +180 -0
  24. package/dist/lib/domain/interfaces/IGitTriageService.d.ts.map +1 -0
  25. package/dist/lib/domain/interfaces/IGitTriageService.js +12 -0
  26. package/dist/lib/domain/interfaces/IGitTriageService.js.map +1 -0
  27. package/dist/lib/domain/interfaces/ILisaServices.d.ts +6 -0
  28. package/dist/lib/domain/interfaces/ILisaServices.d.ts.map +1 -1
  29. package/dist/lib/domain/interfaces/index.d.ts +3 -1
  30. package/dist/lib/domain/interfaces/index.d.ts.map +1 -1
  31. package/dist/lib/domain/interfaces/index.js +4 -1
  32. package/dist/lib/domain/interfaces/index.js.map +1 -1
  33. package/dist/lib/infrastructure/adapters/claude/session-start.d.ts +1 -0
  34. package/dist/lib/infrastructure/adapters/claude/session-start.d.ts.map +1 -1
  35. package/dist/lib/infrastructure/adapters/claude/session-start.js +18 -4
  36. package/dist/lib/infrastructure/adapters/claude/session-start.js.map +1 -1
  37. package/dist/lib/infrastructure/di/ServiceFactory.d.ts +2 -0
  38. package/dist/lib/infrastructure/di/ServiceFactory.d.ts.map +1 -1
  39. package/dist/lib/infrastructure/di/bootstrap.d.ts.map +1 -1
  40. package/dist/lib/infrastructure/di/bootstrap.js +11 -1
  41. package/dist/lib/infrastructure/di/bootstrap.js.map +1 -1
  42. package/dist/lib/infrastructure/di/tokens.d.ts +2 -0
  43. package/dist/lib/infrastructure/di/tokens.d.ts.map +1 -1
  44. package/dist/lib/infrastructure/di/tokens.js +1 -0
  45. package/dist/lib/infrastructure/di/tokens.js.map +1 -1
  46. package/dist/lib/infrastructure/git/GitClient.d.ts +11 -1
  47. package/dist/lib/infrastructure/git/GitClient.d.ts.map +1 -1
  48. package/dist/lib/infrastructure/git/GitClient.js +137 -0
  49. package/dist/lib/infrastructure/git/GitClient.js.map +1 -1
  50. package/dist/lib/infrastructure/logging/Logger.d.ts +13 -1
  51. package/dist/lib/infrastructure/logging/Logger.d.ts.map +1 -1
  52. package/dist/lib/infrastructure/logging/Logger.js +25 -7
  53. package/dist/lib/infrastructure/logging/Logger.js.map +1 -1
  54. package/dist/lib/infrastructure/logging/factory.d.ts +5 -1
  55. package/dist/lib/infrastructure/logging/factory.d.ts.map +1 -1
  56. package/dist/lib/infrastructure/logging/factory.js +3 -0
  57. package/dist/lib/infrastructure/logging/factory.js.map +1 -1
  58. package/dist/lib/infrastructure/logging/index.d.ts +1 -1
  59. package/dist/lib/infrastructure/logging/index.d.ts.map +1 -1
  60. package/dist/lib/infrastructure/logging/index.js.map +1 -1
  61. package/dist/lib/infrastructure/services/CommitEnricher.d.ts +26 -0
  62. package/dist/lib/infrastructure/services/CommitEnricher.d.ts.map +1 -0
  63. package/dist/lib/infrastructure/services/CommitEnricher.js +214 -0
  64. package/dist/lib/infrastructure/services/CommitEnricher.js.map +1 -0
  65. package/dist/lib/infrastructure/services/prompts/commit-extraction.d.ts +26 -0
  66. package/dist/lib/infrastructure/services/prompts/commit-extraction.d.ts.map +1 -0
  67. package/dist/lib/infrastructure/services/prompts/commit-extraction.js +151 -0
  68. package/dist/lib/infrastructure/services/prompts/commit-extraction.js.map +1 -0
  69. package/dist/opencode/lisa.js +907 -18
  70. package/dist/package.json +1 -1
  71. package/dist/project/.lisa/rules/shared/git-rules.md +12 -3
  72. package/package.json +1 -1
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ /**
3
+ * Commit Enricher Implementation.
4
+ *
5
+ * LLM-powered extraction of structured facts from git commits.
6
+ * Takes high-interest commits from GitTriageService and extracts
7
+ * meaningful facts (features, decisions, refactors, etc.) for memory.
8
+ *
9
+ * Error Handling:
10
+ * - Graceful fallback: if the LLM call fails for any reason, returns
11
+ * an empty result — never blocks session start or git triage.
12
+ * - Error messages are sanitized (first line only) to avoid logging
13
+ * raw API response bodies which may contain sensitive data.
14
+ *
15
+ * Part of LISA-8: Phase 2 Git-Powered Memory Enrichment.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.createCommitEnricher = createCommitEnricher;
19
+ const ICommitEnricher_1 = require("../../domain/interfaces/ICommitEnricher");
20
+ const IMemoryQuality_1 = require("../../domain/interfaces/types/IMemoryQuality");
21
+ const commit_extraction_1 = require("./prompts/commit-extraction");
22
+ /** Default maximum commits to process in one batch. */
23
+ const DEFAULT_MAX_COMMITS = 5;
24
+ /** Default maximum tokens for the LLM call. */
25
+ const DEFAULT_MAX_TOKENS = 4096;
26
+ /** Empty usage stats for fallback results. */
27
+ const EMPTY_USAGE = { inputTokens: 0, outputTokens: 0, totalTokens: 0 };
28
+ /**
29
+ * Create a commit enricher.
30
+ *
31
+ * @param llmGuard - LLM guard for policy-enforced completions
32
+ * @param logger - Optional logger
33
+ */
34
+ function createCommitEnricher(llmGuard, logger) {
35
+ return {
36
+ async enrich(commits, options = {}) {
37
+ try {
38
+ // Filter out commits that should be skipped (use shortSha for consistency)
39
+ const skipShas = new Set(options.skipShas ?? []);
40
+ const filteredCommits = commits.filter(c => !skipShas.has(c.commit.shortSha));
41
+ if (filteredCommits.length === 0) {
42
+ return {
43
+ facts: [],
44
+ commitsProcessed: 0,
45
+ commitsSkipped: commits.length,
46
+ usage: EMPTY_USAGE,
47
+ };
48
+ }
49
+ // Limit to maxCommits (guard against <= 0)
50
+ const maxCommits = Math.max(0, options.maxCommits ?? DEFAULT_MAX_COMMITS);
51
+ const toProcess = filteredCommits.slice(0, maxCommits);
52
+ // Fast-return for empty toProcess to avoid wasting LLM tokens
53
+ if (toProcess.length === 0) {
54
+ return {
55
+ facts: [],
56
+ commitsProcessed: 0,
57
+ commitsSkipped: commits.length,
58
+ usage: EMPTY_USAGE,
59
+ };
60
+ }
61
+ const skipped = commits.length - toProcess.length;
62
+ // Build allowed SHAs set for validation (both full and short)
63
+ const allowedShas = new Set(toProcess.flatMap(c => [c.commit.sha, c.commit.shortSha].filter(Boolean)));
64
+ const prompt = (0, commit_extraction_1.buildCommitExtractionPrompt)(toProcess, options);
65
+ const response = await llmGuard.complete(prompt.user, 'extraction', {
66
+ systemPrompt: prompt.system,
67
+ temperature: 0.3,
68
+ maxTokens: options.maxTokens ?? DEFAULT_MAX_TOKENS,
69
+ });
70
+ const parsed = parseCommitExtractionResponse(response.text, options, allowedShas);
71
+ return {
72
+ facts: parsed.facts,
73
+ commitsProcessed: toProcess.length,
74
+ commitsSkipped: skipped,
75
+ usage: response.usage,
76
+ };
77
+ }
78
+ catch (error) {
79
+ // Sanitize error message to avoid logging raw API response bodies
80
+ const errorMsg = error instanceof Error
81
+ ? error.message.split('\n')[0] // Take only first line
82
+ : 'Unknown error';
83
+ logger?.warn('Commit enrichment failed, returning empty result', {
84
+ error: errorMsg,
85
+ });
86
+ return {
87
+ facts: [],
88
+ commitsProcessed: 0,
89
+ commitsSkipped: commits.length,
90
+ usage: EMPTY_USAGE,
91
+ };
92
+ }
93
+ },
94
+ };
95
+ }
96
+ /**
97
+ * Parse and validate the LLM extraction response.
98
+ *
99
+ * Expects JSON with `{ facts: [...] }`.
100
+ * Invalid facts are silently dropped.
101
+ *
102
+ * @param allowedShas - Optional set of valid SHAs to reject hallucinated commits
103
+ */
104
+ function parseCommitExtractionResponse(responseText, options = {}, allowedShas) {
105
+ // Try to extract JSON from the response
106
+ const jsonText = extractJson(responseText);
107
+ if (!jsonText) {
108
+ return { facts: [] };
109
+ }
110
+ let parsed;
111
+ try {
112
+ parsed = JSON.parse(jsonText);
113
+ }
114
+ catch {
115
+ return { facts: [] };
116
+ }
117
+ if (typeof parsed !== 'object' || parsed === null) {
118
+ return { facts: [] };
119
+ }
120
+ const obj = parsed;
121
+ const rawFacts = Array.isArray(obj.facts) ? obj.facts : [];
122
+ const allowedTypes = options.extractTypes;
123
+ const facts = [];
124
+ for (const raw of rawFacts) {
125
+ const fact = validateCommitFact(raw, allowedTypes, allowedShas);
126
+ if (fact) {
127
+ facts.push(fact);
128
+ }
129
+ }
130
+ return { facts };
131
+ }
132
+ /**
133
+ * Extract JSON from LLM response text.
134
+ * Handles responses that may have text before/after the JSON block.
135
+ * Uses progressive try-parse from each '{' to handle braces inside strings.
136
+ */
137
+ function extractJson(text) {
138
+ const trimmed = text.trim();
139
+ // Try each '{' as a potential JSON start
140
+ let start = trimmed.indexOf('{');
141
+ while (start !== -1) {
142
+ // Try parsing progressively longer substrings from this start
143
+ for (let end = trimmed.lastIndexOf('}'); end > start; end = trimmed.lastIndexOf('}', end - 1)) {
144
+ const candidate = trimmed.slice(start, end + 1);
145
+ try {
146
+ JSON.parse(candidate);
147
+ return candidate;
148
+ }
149
+ catch {
150
+ // Try a shorter substring
151
+ }
152
+ }
153
+ start = trimmed.indexOf('{', start + 1);
154
+ }
155
+ return null;
156
+ }
157
+ /**
158
+ * Validate a single extracted commit fact from the LLM response.
159
+ * Returns null for invalid facts.
160
+ *
161
+ * @param allowedShas - Optional set of valid SHAs to reject hallucinated commits
162
+ */
163
+ function validateCommitFact(raw, allowedTypes, allowedShas) {
164
+ if (typeof raw !== 'object' || raw === null)
165
+ return null;
166
+ const obj = raw;
167
+ // Text is required and must be non-empty
168
+ if (typeof obj.text !== 'string' || obj.text.trim().length === 0)
169
+ return null;
170
+ // Type must be valid
171
+ if (typeof obj.type !== 'string' || !(0, ICommitEnricher_1.isValidCommitFactType)(obj.type))
172
+ return null;
173
+ // If type filter specified, enforce it
174
+ if (allowedTypes && allowedTypes.length > 0 && !allowedTypes.includes(obj.type)) {
175
+ return null;
176
+ }
177
+ // commitSha is required
178
+ if (typeof obj.commitSha !== 'string' || obj.commitSha.trim().length === 0)
179
+ return null;
180
+ const commitSha = obj.commitSha.trim();
181
+ // Reject facts with unknown SHAs (LLM may hallucinate)
182
+ if (allowedShas && !allowedShas.has(commitSha))
183
+ return null;
184
+ // Confidence must be valid (default to 'medium' if missing)
185
+ let confidence = 'medium';
186
+ if (typeof obj.confidence === 'string') {
187
+ if ((0, IMemoryQuality_1.isValidConfidence)(obj.confidence)) {
188
+ confidence = obj.confidence;
189
+ }
190
+ // If invalid confidence string, keep default 'medium'
191
+ }
192
+ // Tags must be string array (default to empty)
193
+ const tags = [];
194
+ if (Array.isArray(obj.tags)) {
195
+ for (const tag of obj.tags) {
196
+ if (typeof tag === 'string' && tag.trim().length > 0) {
197
+ tags.push(tag.trim());
198
+ }
199
+ }
200
+ }
201
+ // Rationale is optional
202
+ const rationale = typeof obj.rationale === 'string' && obj.rationale.trim().length > 0
203
+ ? obj.rationale.trim()
204
+ : undefined;
205
+ return {
206
+ text: obj.text.trim(),
207
+ type: obj.type,
208
+ confidence,
209
+ tags,
210
+ commitSha,
211
+ rationale,
212
+ };
213
+ }
214
+ //# sourceMappingURL=CommitEnricher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommitEnricher.js","sourceRoot":"","sources":["../../../../src/lib/infrastructure/services/CommitEnricher.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAiCH,oDA6EC;AAjGD,6EAAgF;AAChF,iFAAiF;AAEjF,mEAA0E;AAE1E,uDAAuD;AACvD,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAE9B,+CAA+C;AAC/C,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEhC,8CAA8C;AAC9C,MAAM,WAAW,GAAc,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;AAEnF;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,QAAmB,EACnB,MAAgB;IAEhB,OAAO;QACL,KAAK,CAAC,MAAM,CACV,OAAiC,EACjC,UAAoC,EAAE;YAEtC,IAAI,CAAC;gBACH,2EAA2E;gBAC3E,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC;gBACjD,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;gBAE9E,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBACjC,OAAO;wBACL,KAAK,EAAE,EAAE;wBACT,gBAAgB,EAAE,CAAC;wBACnB,cAAc,EAAE,OAAO,CAAC,MAAM;wBAC9B,KAAK,EAAE,WAAW;qBACnB,CAAC;gBACJ,CAAC;gBAED,2CAA2C;gBAC3C,MAAM,UAAU,GAA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CAAC;QAC9B,CAAC;QACD,sDAAsD;IACxD,CAAC;IAED,+CAA+C;IAC/C,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,KAAK,MAAM,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;YAC3B,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;YACxB,CAAC;QACH,CAAC;IACH,CAAC;IAED,wBAAwB;IACxB,MAAM,SAAS,GAAG,OAAO,GAAG,CAAC,SAAS,KAAK,QAAQ,IAAI,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QACpF,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE;QACtB,CAAC,CAAC,SAAS,CAAC;IAEd,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE;QACrB,IAAI,EAAE,GAAG,CAAC,IAAsB;QAChC,UAAU;QACV,IAAI;QACJ,SAAS;QACT,SAAS;KACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Commit Extraction Prompt Builder.
3
+ *
4
+ * Constructs system and user prompts for LLM-based fact extraction
5
+ * from git commits. Requests structured JSON output with typed facts,
6
+ * confidence levels, and tags.
7
+ *
8
+ * Part of LISA-8: Phase 2 Git-Powered Memory Enrichment.
9
+ */
10
+ import type { IScoredCommit } from '../../../domain/interfaces/IGitTriageService';
11
+ import type { ICommitEnrichmentOptions } from '../../../domain/interfaces/ICommitEnricher';
12
+ /**
13
+ * Built prompt pair for the commit extraction LLM call.
14
+ */
15
+ export interface ICommitExtractionPrompt {
16
+ readonly system: string;
17
+ readonly user: string;
18
+ }
19
+ /**
20
+ * Build an extraction prompt from a batch of high-interest commits.
21
+ *
22
+ * @param commits - High-interest commits from triage
23
+ * @param options - Enrichment options
24
+ */
25
+ export declare function buildCommitExtractionPrompt(commits: readonly IScoredCommit[], options?: ICommitEnrichmentOptions): ICommitExtractionPrompt;
26
+ //# sourceMappingURL=commit-extraction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-extraction.d.ts","sourceRoot":"","sources":["../../../../../src/lib/infrastructure/services/prompts/commit-extraction.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAClF,OAAO,KAAK,EAAE,wBAAwB,EAAkB,MAAM,4CAA4C,CAAC;AAE3G;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAOD;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,SAAS,aAAa,EAAE,EACjC,OAAO,GAAE,wBAA6B,GACrC,uBAAuB,CAiEzB"}
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ /**
3
+ * Commit Extraction Prompt Builder.
4
+ *
5
+ * Constructs system and user prompts for LLM-based fact extraction
6
+ * from git commits. Requests structured JSON output with typed facts,
7
+ * confidence levels, and tags.
8
+ *
9
+ * Part of LISA-8: Phase 2 Git-Powered Memory Enrichment.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.buildCommitExtractionPrompt = buildCommitExtractionPrompt;
13
+ /**
14
+ * Default maximum facts to extract per batch.
15
+ */
16
+ const DEFAULT_MAX_FACTS = 10;
17
+ /**
18
+ * Build an extraction prompt from a batch of high-interest commits.
19
+ *
20
+ * @param commits - High-interest commits from triage
21
+ * @param options - Enrichment options
22
+ */
23
+ function buildCommitExtractionPrompt(commits, options = {}) {
24
+ const extractTypes = options.extractTypes;
25
+ const maxFacts = Math.min(commits.length * 2, DEFAULT_MAX_FACTS);
26
+ const validTypes = extractTypes && extractTypes.length > 0
27
+ ? extractTypes
28
+ : [
29
+ 'feature',
30
+ 'decision',
31
+ 'refactor',
32
+ 'migration',
33
+ 'bugfix',
34
+ 'breaking-change',
35
+ 'convention',
36
+ 'dependency',
37
+ ];
38
+ const system = [
39
+ 'You are analyzing git commits to extract structured facts for project memory.',
40
+ 'Your task is to identify important information worth remembering long-term.',
41
+ '',
42
+ 'Fact types to extract:',
43
+ '- feature: New functionality or capability added to the project',
44
+ '- decision: Architecture or technology choice evident from the commit',
45
+ '- refactor: Code restructuring without behavior change',
46
+ '- migration: Data migration, API migration, or technology migration',
47
+ '- bugfix: Bug fix with root cause (what was broken and why)',
48
+ '- breaking-change: Changes that break backward compatibility',
49
+ '- convention: New patterns or coding conventions introduced',
50
+ '- dependency: Significant dependency additions, updates, or removals',
51
+ '',
52
+ 'Confidence levels:',
53
+ '- high: Clear from commit message, subject, or explicit description',
54
+ '- medium: Reasonably inferred from commit context and signals',
55
+ '- low: Tentative inference, may need verification',
56
+ '',
57
+ 'Guidelines:',
58
+ '- Each fact should be self-contained and understandable without the commit context.',
59
+ '- Include relevant file paths, technologies, or components in tags.',
60
+ '- For bugfixes, try to identify the root cause if evident from the message.',
61
+ '- Focus on facts that would be valuable for future developers.',
62
+ '- Do not extract trivial changes (formatting, typos, version bumps).',
63
+ `- Extract at most ${maxFacts} facts total across all commits.`,
64
+ extractTypes && extractTypes.length > 0
65
+ ? `- Only extract facts of these types: ${extractTypes.join(', ')}`
66
+ : '- Extract facts of any type listed above.',
67
+ '',
68
+ 'Respond with ONLY a valid JSON object in this exact format:',
69
+ '{',
70
+ ' "facts": [',
71
+ ' {',
72
+ ' "text": "Clear description of the fact",',
73
+ ` "type": "one of: ${validTypes.join(', ')}",`,
74
+ ' "confidence": "high | medium | low",',
75
+ ' "tags": ["relevant", "tags"],',
76
+ ' "commitSha": "short SHA of the source commit",',
77
+ ' "rationale": "Why this fact is worth remembering"',
78
+ ' }',
79
+ ' ]',
80
+ '}',
81
+ ].join('\n');
82
+ const user = formatCommitsForPrompt(commits);
83
+ return { system, user };
84
+ }
85
+ /**
86
+ * Format commits into a structured prompt section.
87
+ */
88
+ function formatCommitsForPrompt(commits) {
89
+ const parts = [];
90
+ parts.push('## Commits to Analyze');
91
+ parts.push('');
92
+ for (let i = 0; i < commits.length; i++) {
93
+ const { commit, stats, signals } = commits[i];
94
+ parts.push(`### Commit ${i + 1}: ${commit.shortSha}`);
95
+ parts.push(`**Subject:** ${commit.subject}`);
96
+ if (commit.body && commit.body.trim().length > 0) {
97
+ const truncatedBody = commit.body.length > 500
98
+ ? commit.body.slice(0, 500) + '...'
99
+ : commit.body;
100
+ parts.push(`**Body:** ${truncatedBody}`);
101
+ }
102
+ parts.push(`**Timestamp:** ${commit.timestamp.toISOString()}`);
103
+ parts.push(`**Author:** ${commit.author}`);
104
+ if (stats) {
105
+ parts.push(`**Files changed:** ${stats.filesChanged}`);
106
+ parts.push(`**Lines:** +${stats.insertions} -${stats.deletions}`);
107
+ if (stats.directoriesCreated.length > 0) {
108
+ parts.push(`**New directories:** ${stats.directoriesCreated.join(', ')}`);
109
+ }
110
+ }
111
+ // Format interest signals
112
+ const signalList = formatSignals(signals);
113
+ if (signalList.length > 0) {
114
+ parts.push(`**Signals:** ${signalList.join(', ')}`);
115
+ }
116
+ parts.push('');
117
+ }
118
+ return parts.join('\n');
119
+ }
120
+ /**
121
+ * Format interest signals into readable strings.
122
+ */
123
+ function formatSignals(signals) {
124
+ const result = [];
125
+ if (signals.largeDiffFiles) {
126
+ result.push('large-diff-files');
127
+ }
128
+ if (signals.largeDiffLines) {
129
+ result.push('large-diff-lines');
130
+ }
131
+ if (signals.mergeCommitWithPR && signals.prNumber) {
132
+ result.push(`merge-PR-#${signals.prNumber}`);
133
+ }
134
+ if (signals.hasConventionalPrefix && signals.conventionalType) {
135
+ result.push(`conventional:${signals.conventionalType}`);
136
+ }
137
+ if (signals.hasDecisionKeywords) {
138
+ result.push('decision-keywords');
139
+ }
140
+ if (signals.createsNewDirectory) {
141
+ result.push('new-directory');
142
+ }
143
+ if (signals.isTagAdjacent) {
144
+ result.push('tag-adjacent');
145
+ }
146
+ if (signals.hasLongMessageBody) {
147
+ result.push('detailed-message');
148
+ }
149
+ return result;
150
+ }
151
+ //# sourceMappingURL=commit-extraction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commit-extraction.js","sourceRoot":"","sources":["../../../../../src/lib/infrastructure/services/prompts/commit-extraction.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AAwBH,kEAoEC;AA/ED;;GAEG;AACH,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;;;;GAKG;AACH,SAAgB,2BAA2B,CACzC,OAAiC,EACjC,UAAoC,EAAE;IAEtC,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,iBAAiB,CAAC,CAAC;IAEjE,MAAM,UAAU,GAAsB,YAAY,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC;QAC3E,CAAC,CAAC,YAAY;QACd,CAAC,CAAE;YACC,SAAS;YACT,UAAU;YACV,UAAU;YACV,WAAW;YACX,QAAQ;YACR,iBAAiB;YACjB,YAAY;YACZ,YAAY;SACwB,CAAC;IAE3C,MAAM,MAAM,GAAG;QACb,+EAA+E;QAC/E,6EAA6E;QAC7E,EAAE;QACF,wBAAwB;QACxB,iEAAiE;QACjE,uEAAuE;QACvE,wDAAwD;QACxD,qEAAqE;QACrE,6DAA6D;QAC7D,8DAA8D;QAC9D,6DAA6D;QAC7D,sEAAsE;QACtE,EAAE;QACF,oBAAoB;QACpB,qEAAqE;QACrE,+DAA+D;QAC/D,mDAAmD;QACnD,EAAE;QACF,aAAa;QACb,qFAAqF;QACrF,qE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