gitnexus 1.6.3-rc.36 → 1.6.3-rc.38
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.
package/dist/cli/ai-context.js
CHANGED
|
@@ -13,6 +13,32 @@ const __filename = fileURLToPath(import.meta.url);
|
|
|
13
13
|
const __dirname = path.dirname(__filename);
|
|
14
14
|
const GITNEXUS_START_MARKER = '<!-- gitnexus:start -->';
|
|
15
15
|
const GITNEXUS_END_MARKER = '<!-- gitnexus:end -->';
|
|
16
|
+
/**
|
|
17
|
+
* Find the index of a section marker that occupies its own line.
|
|
18
|
+
* Unlike `indexOf`, this rejects inline prose references like
|
|
19
|
+
* `` See the `<!-- gitnexus:start -->` block `` that appear
|
|
20
|
+
* mid-sentence (#1041). A marker counts as section-position only when:
|
|
21
|
+
* - preceded by newline or start-of-file, AND
|
|
22
|
+
* - followed by newline, `\r` (CRLF files), or end-of-file.
|
|
23
|
+
* The generator always emits each marker alone on its line, so this
|
|
24
|
+
* matches every legitimate section and none of the inline mentions.
|
|
25
|
+
*
|
|
26
|
+
* `startFrom` lets the end-marker lookup start after the already-found
|
|
27
|
+
* start marker, avoiding a scan from 0 and guaranteeing we never pick
|
|
28
|
+
* up an end marker that appears earlier in the file than the start.
|
|
29
|
+
*/
|
|
30
|
+
function findSectionMarkerIndex(content, marker, startFrom = 0) {
|
|
31
|
+
let idx = content.indexOf(marker, startFrom);
|
|
32
|
+
while (idx !== -1) {
|
|
33
|
+
const atLineStart = idx === 0 || content[idx - 1] === '\n';
|
|
34
|
+
const endPos = idx + marker.length;
|
|
35
|
+
const atLineEnd = endPos === content.length || content[endPos] === '\n' || content[endPos] === '\r';
|
|
36
|
+
if (atLineStart && atLineEnd)
|
|
37
|
+
return idx;
|
|
38
|
+
idx = content.indexOf(marker, idx + 1);
|
|
39
|
+
}
|
|
40
|
+
return -1;
|
|
41
|
+
}
|
|
16
42
|
/**
|
|
17
43
|
* Generate the full GitNexus context content.
|
|
18
44
|
*
|
|
@@ -123,9 +149,14 @@ async function upsertGitNexusSection(filePath, content) {
|
|
|
123
149
|
return 'created';
|
|
124
150
|
}
|
|
125
151
|
const existingContent = await fs.readFile(filePath, 'utf-8');
|
|
126
|
-
// Check if GitNexus section already exists
|
|
127
|
-
|
|
128
|
-
|
|
152
|
+
// Check if GitNexus section already exists. Matching is restricted
|
|
153
|
+
// to markers that occupy their own line so that inline prose
|
|
154
|
+
// references (e.g. `` See the `<!-- gitnexus:start -->` block `` in
|
|
155
|
+
// the shipped CLAUDE.md) are NOT treated as section delimiters
|
|
156
|
+
// (#1041). The end-marker scan starts after the start-marker so it
|
|
157
|
+
// can never pick up an earlier end in the file.
|
|
158
|
+
const startIdx = findSectionMarkerIndex(existingContent, GITNEXUS_START_MARKER);
|
|
159
|
+
const endIdx = findSectionMarkerIndex(existingContent, GITNEXUS_END_MARKER, startIdx === -1 ? 0 : startIdx);
|
|
129
160
|
if (startIdx !== -1 && endIdx !== -1 && endIdx > startIdx) {
|
|
130
161
|
// Replace existing section
|
|
131
162
|
const before = existingContent.substring(0, startIdx);
|
|
@@ -287,31 +287,47 @@ const findEnclosingFunctionId = (node, filePath, provider) => {
|
|
|
287
287
|
}
|
|
288
288
|
// Qualify with enclosing class to match definition-phase node IDs
|
|
289
289
|
const classInfo = cachedFindEnclosingClassInfo(current, filePath, provider.resolveEnclosingOwner);
|
|
290
|
-
const
|
|
290
|
+
const encLang = getLanguageFromFilename(filePath);
|
|
291
|
+
const standaloneMethodInfo = (finalLabel === 'Method' || finalLabel === 'Constructor') &&
|
|
292
|
+
encLang === SupportedLanguages.Go &&
|
|
293
|
+
provider.methodExtractor?.extractFromNode
|
|
294
|
+
? provider.methodExtractor.extractFromNode(current, {
|
|
295
|
+
filePath,
|
|
296
|
+
language: encLang,
|
|
297
|
+
})
|
|
298
|
+
: null;
|
|
299
|
+
const ownerName = classInfo?.className ?? standaloneMethodInfo?.receiverType ?? undefined;
|
|
300
|
+
const qualifiedName = ownerName ? `${ownerName}.${funcName}` : funcName;
|
|
291
301
|
// Include #<arity> suffix to match definition-phase Method/Constructor IDs.
|
|
292
302
|
// Use the same MethodExtractor (getMethodInfo) as the definition phase.
|
|
293
303
|
// When same-arity collisions exist, also append ~type1,type2.
|
|
294
304
|
let arity;
|
|
295
305
|
let encTypeTag = '';
|
|
296
306
|
if (finalLabel === 'Method' || finalLabel === 'Constructor') {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
307
|
+
if (standaloneMethodInfo) {
|
|
308
|
+
arity = standaloneMethodInfo.parameters.some((p) => p.isVariadic)
|
|
309
|
+
? undefined
|
|
310
|
+
: standaloneMethodInfo.parameters.length;
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
const classNode = findEnclosingClassNode(current) ?? findClassNodeByQualifiedName(current);
|
|
314
|
+
if (classNode && encLang) {
|
|
315
|
+
const methodMap = getMethodInfo(classNode, provider, {
|
|
316
|
+
filePath,
|
|
317
|
+
language: encLang,
|
|
318
|
+
});
|
|
319
|
+
const defLine = current.startPosition.row + 1;
|
|
320
|
+
const info = methodMap?.get(`${funcName}:${defLine}`);
|
|
321
|
+
if (info) {
|
|
322
|
+
arity = info.parameters.some((p) => p.isVariadic)
|
|
323
|
+
? undefined
|
|
324
|
+
: info.parameters.length;
|
|
325
|
+
if (methodMap && arity !== undefined) {
|
|
326
|
+
const g = buildCollisionGroups(methodMap);
|
|
327
|
+
encTypeTag =
|
|
328
|
+
typeTagForId(methodMap, funcName, arity, info, encLang, g) +
|
|
329
|
+
constTagForId(methodMap, funcName, arity, info, g);
|
|
330
|
+
}
|
|
315
331
|
}
|
|
316
332
|
}
|
|
317
333
|
}
|
package/package.json
CHANGED