gitnexus 1.6.6-rc.90 → 1.6.6-rc.91

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.
@@ -28,10 +28,38 @@
28
28
  * aliased `using static X = Y.Z;`, attributed namespace declarations,
29
29
  * and preprocessor-guarded declarations correctly because the
30
30
  * tree-sitter grammar parses them as real nodes (not textual
31
- * coincidences).
31
+ * coincidences). When the orchestrator's `treeCache` has no Tree for a
32
+ * file — the worker path, where native Trees can't cross MessageChannels
33
+ * — `extractFileStructure` falls back to a line scanner rather than
34
+ * re-parsing every file from scratch (that re-parse dominated worker-mode
35
+ * scope-resolution time). See `extractCsharpStructureViaScanner`.
32
36
  */
33
37
  import type { ParsedFile } from '../../../../_shared/index.js';
34
38
  import type { ScopeResolutionIndexes } from '../../model/scope-resolution-indexes.js';
39
+ export interface CsharpFileStructure {
40
+ /** Declared namespace names in file source order. Empty array means
41
+ * the file has no `namespace X;` / `namespace X { }` declaration
42
+ * and sits in the default (global) namespace. */
43
+ readonly namespaces: readonly string[];
44
+ /** Dotted paths from `using static X.Y.Z;` (including
45
+ * `global using static` and aliased `using static A = X.Y.Z;`). */
46
+ readonly usingStaticPaths: readonly string[];
47
+ }
48
+ /** Line-scanner used when no cached tree is available (worker-parsed files
49
+ * can't transfer native tree-sitter Trees across MessageChannels, so
50
+ * `treeCache` is empty for them). Re-parsing every C# file here with
51
+ * tree-sitter was the dominant scope-resolution cost on large worker-mode
52
+ * runs — for a multi-thousand-file solution this loop alone re-parsed the
53
+ * whole repo a second time. The scanner extracts the same `namespaces` /
54
+ * `usingStaticPaths` the AST walk produces for line-anchored declarations,
55
+ * while tracking block-comment and string state across lines (via
56
+ * `advanceCsScanState`) so a `namespace` / `using static` keyword at the
57
+ * start of a line inside a block comment, verbatim string, or raw string
58
+ * literal is NOT mistaken for a declaration. The remaining trade-off vs the
59
+ * AST is a declaration whose keyword is not at the start of a code line
60
+ * (split across lines, or sharing a line with a comment/string closer).
61
+ * Mirrors PHP's `extractNamespaceViaScanner` (issue #1741). */
62
+ export declare function extractCsharpStructureViaScanner(content: string): CsharpFileStructure;
35
63
  /** Content + (optional) pre-parsed tree-sitter trees keyed by filePath.
36
64
  * The orchestrator builds `fileContents` from the pipeline's file list;
37
65
  * `treeCache` is the same `scopeTreeCache` already populated by the
@@ -28,21 +28,188 @@
28
28
  * aliased `using static X = Y.Z;`, attributed namespace declarations,
29
29
  * and preprocessor-guarded declarations correctly because the
30
30
  * tree-sitter grammar parses them as real nodes (not textual
31
- * coincidences).
31
+ * coincidences). When the orchestrator's `treeCache` has no Tree for a
32
+ * file — the worker path, where native Trees can't cross MessageChannels
33
+ * — `extractFileStructure` falls back to a line scanner rather than
34
+ * re-parsing every file from scratch (that re-parse dominated worker-mode
35
+ * scope-resolution time). See `extractCsharpStructureViaScanner`.
32
36
  */
33
- import { getCsharpParser } from './query.js';
34
- import { getTreeSitterBufferSize } from '../../constants.js';
35
- import { parseSourceSafe } from '../../../tree-sitter/safe-parse.js';
36
- /** Build a structural view of a C# file by walking the tree-sitter
37
- * AST. Prefers `cachedTree` (handed in via `treeCache`) so we don't
38
- * re-parse files the orchestrator already parsed for `extractParsedFile`;
39
- * falls back to a fresh parse on cache miss. Parser singleton is
40
- * shared across calls. */
37
+ // Line-anchored matchers for the worker-path fallback (see
38
+ // `extractCsharpStructureViaScanner`). Anchored at line start (after
39
+ // indentation); the scanner additionally tracks block-comment / string
40
+ // state across lines so a keyword at the start of a line inside one of
41
+ // those regions is skipped.
42
+ const CS_NAMESPACE_RE = /^[ \t]*namespace[ \t]+([A-Za-z_@][A-Za-z0-9_.]*)/;
43
+ // `global using static`, plain `using static`, and the aliased
44
+ // `using static Alias = NS.Type;` form (the AST keeps the RHS path, so
45
+ // the optional `Alias =` is skipped and only the dotted path captured).
46
+ const CS_USING_STATIC_RE = /^[ \t]*(?:global[ \t]+)?using[ \t]+static[ \t]+(?:[A-Za-z_@][A-Za-z0-9_]*[ \t]*=[ \t]*)?([A-Za-z_@][A-Za-z0-9_.]*)/;
47
+ /** Advance the scanner's lexical state across one line, consuming block
48
+ * comments (slash-star), line comments (`//`), single-line regular /
49
+ * interpolated strings, verbatim strings (`@"…"`), and raw string literals
50
+ * (`"""…"""`, fence length tracked in `rawFence`). Returns the state and
51
+ * raw-fence length in effect at the START of the next line. Single-line
52
+ * strings and `//` comments resolve back to `code` before end of line; only
53
+ * block comments and multi-line strings carry state forward. */
54
+ function advanceCsScanState(line, state, rawFence) {
55
+ const n = line.length;
56
+ let i = 0;
57
+ while (i < n) {
58
+ if (state === 'block') {
59
+ const end = line.indexOf('*/', i);
60
+ if (end === -1)
61
+ return ['block', rawFence];
62
+ i = end + 2;
63
+ state = 'code';
64
+ }
65
+ else if (state === 'verbatim') {
66
+ // Ends at a `"` that is not doubled (`""` is an escaped quote).
67
+ while (i < n) {
68
+ if (line[i] === '"') {
69
+ if (line[i + 1] === '"') {
70
+ i += 2;
71
+ continue;
72
+ }
73
+ break;
74
+ }
75
+ i++;
76
+ }
77
+ if (i >= n)
78
+ return ['verbatim', rawFence];
79
+ i += 1;
80
+ state = 'code';
81
+ }
82
+ else if (state === 'raw') {
83
+ // Ends at a run of `"` at least `rawFence` long.
84
+ let closed = false;
85
+ while (i < n) {
86
+ if (line[i] === '"') {
87
+ let k = i;
88
+ while (k < n && line[k] === '"')
89
+ k++;
90
+ if (k - i >= rawFence) {
91
+ i = k;
92
+ state = 'code';
93
+ rawFence = 0;
94
+ closed = true;
95
+ break;
96
+ }
97
+ i = k;
98
+ }
99
+ else {
100
+ i++;
101
+ }
102
+ }
103
+ if (!closed)
104
+ return ['raw', rawFence];
105
+ }
106
+ else {
107
+ const c = line[i];
108
+ const next = line[i + 1];
109
+ if (c === '/' && next === '/')
110
+ return ['code', rawFence]; // line comment to EOL
111
+ if (c === '/' && next === '*') {
112
+ state = 'block';
113
+ i += 2;
114
+ }
115
+ else if (c === '@' && next === '"') {
116
+ state = 'verbatim';
117
+ i += 2;
118
+ }
119
+ else if ((c === '$' && next === '@') || (c === '@' && next === '$')) {
120
+ if (line[i + 2] === '"') {
121
+ state = 'verbatim'; // interpolated verbatim ($@"…" / @$"…")
122
+ i += 3;
123
+ }
124
+ else {
125
+ i++;
126
+ }
127
+ }
128
+ else if (c === '"') {
129
+ let k = i;
130
+ while (k < n && line[k] === '"')
131
+ k++;
132
+ const run = k - i;
133
+ if (run >= 3) {
134
+ state = 'raw';
135
+ rawFence = run;
136
+ i = k;
137
+ }
138
+ else if (run === 2) {
139
+ i = k; // "" — empty string
140
+ }
141
+ else {
142
+ // single-line regular / interpolated string; consume to closer
143
+ let j = i + 1;
144
+ while (j < n) {
145
+ if (line[j] === '\\') {
146
+ j += 2;
147
+ continue;
148
+ }
149
+ if (line[j] === '"')
150
+ break;
151
+ j++;
152
+ }
153
+ i = j >= n ? n : j + 1;
154
+ }
155
+ }
156
+ else {
157
+ i++;
158
+ }
159
+ }
160
+ }
161
+ return [state, rawFence];
162
+ }
163
+ /** Line-scanner used when no cached tree is available (worker-parsed files
164
+ * can't transfer native tree-sitter Trees across MessageChannels, so
165
+ * `treeCache` is empty for them). Re-parsing every C# file here with
166
+ * tree-sitter was the dominant scope-resolution cost on large worker-mode
167
+ * runs — for a multi-thousand-file solution this loop alone re-parsed the
168
+ * whole repo a second time. The scanner extracts the same `namespaces` /
169
+ * `usingStaticPaths` the AST walk produces for line-anchored declarations,
170
+ * while tracking block-comment and string state across lines (via
171
+ * `advanceCsScanState`) so a `namespace` / `using static` keyword at the
172
+ * start of a line inside a block comment, verbatim string, or raw string
173
+ * literal is NOT mistaken for a declaration. The remaining trade-off vs the
174
+ * AST is a declaration whose keyword is not at the start of a code line
175
+ * (split across lines, or sharing a line with a comment/string closer).
176
+ * Mirrors PHP's `extractNamespaceViaScanner` (issue #1741). */
177
+ export function extractCsharpStructureViaScanner(content) {
178
+ const namespaces = [];
179
+ const usingStaticPaths = [];
180
+ let state = 'code';
181
+ let rawFence = 0;
182
+ for (const line of content.split('\n')) {
183
+ // Only match when the line START is real code — keywords reached while
184
+ // inside a block comment / multi-line string are skipped.
185
+ if (state === 'code') {
186
+ const ns = CS_NAMESPACE_RE.exec(line);
187
+ if (ns !== null) {
188
+ namespaces.push(ns[1]);
189
+ }
190
+ else {
191
+ const us = CS_USING_STATIC_RE.exec(line);
192
+ if (us !== null)
193
+ usingStaticPaths.push(us[1]);
194
+ }
195
+ }
196
+ [state, rawFence] = advanceCsScanState(line, state, rawFence);
197
+ }
198
+ return { namespaces, usingStaticPaths };
199
+ }
200
+ /** Build a structural view of a C# file. Prefers `cachedTree` (handed in
201
+ * via `treeCache`) and walks the tree-sitter AST — the authoritative
202
+ * path that sees `global using static`, aliased `using static X = Y.Z;`,
203
+ * attributed namespace declarations, and preprocessor-guarded nodes
204
+ * correctly. On cache miss (worker-parsed files, whose native Trees
205
+ * can't cross MessageChannels) it falls back to the line scanner instead
206
+ * of a fresh tree-sitter parse — the parse here dominated worker-mode
207
+ * scope-resolution time. Parser singleton is shared across calls. */
41
208
  function extractFileStructure(content, cachedTree) {
42
- const tree = cachedTree ??
43
- parseSourceSafe(getCsharpParser(), content, undefined, {
44
- bufferSize: getTreeSitterBufferSize(content),
45
- });
209
+ if (!cachedTree) {
210
+ return extractCsharpStructureViaScanner(content);
211
+ }
212
+ const tree = cachedTree;
46
213
  const namespaces = [];
47
214
  const usingStaticPaths = [];
48
215
  const visit = (node) => {
@@ -238,6 +405,9 @@ export function populateCsharpNamespaceSiblings(parsedFiles, indexes, inputs) {
238
405
  // scope, so `Record(...)` (without `Logger.` qualifier) resolves
239
406
  // to `Logger.Record`. AST walk above captured these (including
240
407
  // `global using static` and aliased forms).
408
+ // Pre-index files by path once: the member-injection lookup below would
409
+ // otherwise be an O(files) scan per `using static` import.
410
+ const fileByPath = new Map(parsedFiles.map((p) => [p.filePath, p]));
241
411
  for (const parsed of parsedFiles) {
242
412
  const struct = structureByFile.get(parsed.filePath);
243
413
  if (struct === undefined)
@@ -245,6 +415,9 @@ export function populateCsharpNamespaceSiblings(parsedFiles, indexes, inputs) {
245
415
  const moduleScope = parsed.scopes.find((s) => s.kind === 'Module');
246
416
  if (moduleScope === undefined)
247
417
  continue;
418
+ // Per-file de-dup sets keyed by simple name, seeded lazily from the
419
+ // augmentation bucket — replaces the per-member O(A) `.some` scan below.
420
+ const seenByName = new Map();
248
421
  for (const fullPath of struct.usingStaticPaths) {
249
422
  const lastDot = fullPath.lastIndexOf('.');
250
423
  if (lastDot === -1)
@@ -265,7 +438,7 @@ export function populateCsharpNamespaceSiblings(parsedFiles, indexes, inputs) {
265
438
  // Inject the class's member methods into the importer's module
266
439
  // scope. `memberByOwner` wasn't built yet here, so we walk the
267
440
  // file's localDefs to find members with `ownerId === targetDef.nodeId`.
268
- const targetFile = parsedFiles.find((p) => p.filePath === targetDef.filePath);
441
+ const targetFile = fileByPath.get(targetDef.filePath);
269
442
  if (targetFile === undefined)
270
443
  continue;
271
444
  for (const memberDef of targetFile.localDefs) {
@@ -282,8 +455,16 @@ export function populateCsharpNamespaceSiblings(parsedFiles, indexes, inputs) {
282
455
  // `lookupBindingsAt`, which fans out across `bindings` +
283
456
  // `bindingAugmentations`.
284
457
  const bucketArr = getAugmentationBucket(augmentations, moduleScope.id, simpleName);
285
- if (bucketArr.some((b) => b.def.nodeId === memberDef.nodeId))
458
+ let seen = seenByName.get(simpleName);
459
+ if (seen === undefined) {
460
+ seen = new Set();
461
+ for (const b of bucketArr)
462
+ seen.add(b.def.nodeId);
463
+ seenByName.set(simpleName, seen);
464
+ }
465
+ if (seen.has(memberDef.nodeId))
286
466
  continue;
467
+ seen.add(memberDef.nodeId);
287
468
  bucketArr.push({ def: memberDef, origin: 'import' });
288
469
  }
289
470
  }
@@ -299,6 +480,9 @@ export function populateCsharpNamespaceSiblings(parsedFiles, indexes, inputs) {
299
480
  const moduleScope = parsed.scopes.find((s) => s.kind === 'Module');
300
481
  if (moduleScope === undefined)
301
482
  continue;
483
+ // Per-file de-dup sets keyed by simple name, seeded lazily from the
484
+ // augmentation bucket — replaces the per-def O(A) `.some` scan below.
485
+ const seenByName = new Map();
302
486
  for (const imp of parsed.parsedImports) {
303
487
  if (imp.kind !== 'namespace')
304
488
  continue;
@@ -316,16 +500,35 @@ export function populateCsharpNamespaceSiblings(parsedFiles, indexes, inputs) {
316
500
  if (simpleName === '')
317
501
  continue;
318
502
  const bucketArr = getAugmentationBucket(augmentations, moduleScope.id, simpleName);
319
- if (bucketArr.some((b) => b.def.nodeId === def.nodeId))
503
+ let seen = seenByName.get(simpleName);
504
+ if (seen === undefined) {
505
+ seen = new Set();
506
+ for (const b of bucketArr)
507
+ seen.add(b.def.nodeId);
508
+ seenByName.set(simpleName, seen);
509
+ }
510
+ if (seen.has(def.nodeId))
320
511
  continue;
512
+ seen.add(def.nodeId);
321
513
  bucketArr.push({ def, origin: 'namespace' });
322
514
  }
323
515
  }
324
516
  }
325
- for (const [, bucket] of buckets) {
326
- // De-dup by (nodeId, filePath) across multiple declarations (e.g.
327
- // partial classes declaring the same name in two files — we take
328
- // both and leave de-dup to downstream consumers of bindings).
517
+ // Workspace-level binding channel for global-namespace types (see the
518
+ // global fast-path below). `lookupBindingsAt` consults this as a third
519
+ // source after finalized + per-scope augmented bindings. Its inner arrays
520
+ // are mutable by contract (append-only, like `bindingAugmentations` see
521
+ // the ScopeResolutionIndexes doc + validateBindingsImmutability), so the
522
+ // ReadonlyMap→Map cast is localized to this one line and all writes go
523
+ // through `getWorkspaceBucket`.
524
+ const workspace = indexes.workspaceFqnBindings;
525
+ for (const [nsName, bucket] of buckets) {
526
+ // Group sibling defs by simple name. Append in place — the previous
527
+ // `[...prev, def]` copy made this O(D²) per bucket, which on the
528
+ // global (`''`) namespace bucket of a large Unity solution (tens of
529
+ // thousands of type defs) was a primary slowness/OOM source. We keep
530
+ // every declaration (e.g. partial classes across files) and leave
531
+ // de-dup to downstream consumers.
329
532
  const defsByName = new Map();
330
533
  for (const def of bucket.classDefs) {
331
534
  // Simple name = last segment of qualifiedName (e.g. `App.User` → `User`).
@@ -333,27 +536,81 @@ export function populateCsharpNamespaceSiblings(parsedFiles, indexes, inputs) {
333
536
  const key = q.includes('.') ? q.slice(q.lastIndexOf('.') + 1) : q;
334
537
  if (key === '')
335
538
  continue;
336
- const arr = [...(defsByName.get(key) ?? [])];
539
+ let arr = defsByName.get(key);
540
+ if (arr === undefined) {
541
+ arr = [];
542
+ defsByName.set(key, arr);
543
+ }
337
544
  arr.push(def);
338
- defsByName.set(key, arr);
545
+ }
546
+ // Global-namespace fast path (Unity OOM guard). Types declared in the
547
+ // default (global) namespace are visible from EVERY file in C# — the
548
+ // global namespace is always implicitly in scope — so one workspace-
549
+ // level entry per simple name is both semantically correct and O(D)
550
+ // instead of the O(S·D) per-scope augmentation that materialized
551
+ // billions of BindingRefs on large Unity solutions (tens of thousands
552
+ // of global types × tens of thousands of scopes). `walkScopeChain`
553
+ // checks local `scope.bindings` first, so local declarations still
554
+ // shadow these workspace entries; a file resolving its own global type
555
+ // hits the local binding before this map. Dedup by `def.nodeId` keeps
556
+ // partial-class / duplicate declarations from double-emitting.
557
+ if (nsName === '') {
558
+ for (const [name, defs] of defsByName) {
559
+ const bucket = getWorkspaceBucket(workspace, name);
560
+ const seen = new Set();
561
+ for (const b of bucket)
562
+ seen.add(b.def.nodeId);
563
+ for (const def of defs) {
564
+ if (seen.has(def.nodeId))
565
+ continue; // dedup by nodeId (keeps partials, drops re-emits)
566
+ seen.add(def.nodeId);
567
+ bucket.push({ def, origin: 'namespace' });
568
+ }
569
+ }
570
+ continue;
571
+ }
572
+ // Pre-index the first scope per file once (O(S)) instead of an
573
+ // O(S) `.find` re-run for every (scope, name) pair, which made the
574
+ // injection loop O(S²·D) and was the dominant cost on large buckets.
575
+ // Multiple scopes share a filePath (Module + Namespace); the local
576
+ // shadow check only needs that file's lexical `Scope.bindings`, which
577
+ // is identical regardless of which of those scopes we read.
578
+ const firstScopeByFile = new Map();
579
+ for (const s of bucket.scopes) {
580
+ if (!firstScopeByFile.has(s.filePath))
581
+ firstScopeByFile.set(s.filePath, s.scope);
339
582
  }
340
583
  for (const { scopeId, filePath } of bucket.scopes) {
584
+ const localScope = firstScopeByFile.get(filePath);
341
585
  for (const [name, defs] of defsByName) {
342
586
  // Skip names already present locally — `origin: 'local'` in
343
587
  // scope.bindings would naturally shadow the cross-file
344
588
  // namespace entry, but we also keep this index lean.
345
- const local = bucket.scopes.find((s) => s.filePath === filePath)?.scope.bindings.get(name);
589
+ const local = localScope?.bindings.get(name);
346
590
  if (local !== undefined && local.some((b) => b.origin === 'local'))
347
591
  continue;
348
- let bucketArr = null;
592
+ // Bind the augmentation bucket and its seeded de-dup set together
593
+ // under one nullable lifecycle, so neither needs a non-null
594
+ // assertion (they are always set or unset as a pair). Stays lazy:
595
+ // nothing is allocated for a name with no cross-file defs.
596
+ let inject = null;
349
597
  for (const def of defs) {
350
598
  if (def.filePath === filePath)
351
599
  continue; // don't self-reference
352
- if (bucketArr === null)
353
- bucketArr = getAugmentationBucket(augmentations, scopeId, name);
354
- if (bucketArr.some((b) => b.def.nodeId === def.nodeId))
600
+ if (inject === null) {
601
+ const bucket = getAugmentationBucket(augmentations, scopeId, name);
602
+ // Seed the de-dup set from any entries an earlier pass
603
+ // (using-static / cross-namespace imports) already added,
604
+ // replacing the per-def O(A) `.some` scan.
605
+ const seen = new Set();
606
+ for (const b of bucket)
607
+ seen.add(b.def.nodeId);
608
+ inject = { bucket, seen };
609
+ }
610
+ if (inject.seen.has(def.nodeId))
355
611
  continue;
356
- bucketArr.push({ def, origin: 'namespace' });
612
+ inject.seen.add(def.nodeId);
613
+ inject.bucket.push({ def, origin: 'namespace' });
357
614
  }
358
615
  }
359
616
  }
@@ -378,6 +635,21 @@ function getAugmentationBucket(augmentations, scopeId, name) {
378
635
  }
379
636
  return bucketArr;
380
637
  }
638
+ /** Get-or-create a mutable inner bucket inside the `workspaceFqnBindings`
639
+ * channel (the scope-independent third channel; see
640
+ * `ScopeResolutionIndexes.workspaceFqnBindings`). Like
641
+ * `getAugmentationBucket`, the inner arrays are mutable by contract —
642
+ * callers `push` directly. Keeping the get-or-create here means the one
643
+ * ReadonlyMap→Map cast at the call site is the only place the mutable
644
+ * view is taken. */
645
+ function getWorkspaceBucket(workspace, name) {
646
+ let bucketArr = workspace.get(name);
647
+ if (bucketArr === undefined) {
648
+ bucketArr = [];
649
+ workspace.set(name, bucketArr);
650
+ }
651
+ return bucketArr;
652
+ }
381
653
  function isTypeDef(def) {
382
654
  return (def.type === 'Class' ||
383
655
  def.type === 'Interface' ||
@@ -63,11 +63,15 @@ export interface ScopeResolutionIndexes {
63
63
  * are returned first and win duplicate `def.nodeId` metadata, with
64
64
  * unique augmentations appended after. See I8. */
65
65
  readonly bindingAugmentations: ReadonlyMap<ScopeId, ReadonlyMap<string, readonly BindingRef[]>>;
66
- /** Workspace-level FQN binding lookup. Populated by PHP namespace-
67
- * siblings Step 3b as a shared map instead of per-scope duplication.
68
- * Consulted by `lookupBindingsAt` as a third source after finalized
69
- * and per-scope augmented bindings. Keys are backslash-separated FQNs
70
- * (e.g. `App\Models\User`). */
66
+ /** Workspace-level binding lookup, shared instead of per-scope
67
+ * duplication. Consulted by `lookupBindingsAt` as a third source after
68
+ * finalized and per-scope augmented bindings. Language-specific
69
+ * namespace-sibling hooks populate it with disjoint key formats that
70
+ * never collide — e.g. backslash-separated FQNs (`App\Models\User`) for
71
+ * backslash-namespace languages, and bare simple names (`User`) for
72
+ * global-/default-namespace types that are visible from every file. The
73
+ * shared map gives those workspace-wide names one entry each instead of
74
+ * O(scopes × defs) per-scope augmentation. */
71
75
  readonly workspaceFqnBindings: ReadonlyMap<string, readonly BindingRef[]>;
72
76
  /** Pre-resolution usage facts; consumed by the resolution phase. */
73
77
  readonly referenceSites: readonly ReferenceSite[];
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Dev-mode runtime validator for the two-channel binding lifecycle
3
- * (Contract Invariant I8 in `contract/scope-resolver.ts`).
2
+ * Dev-mode runtime validator for the post-finalize binding-channel
3
+ * lifecycle (Contract Invariant I8 in `contract/scope-resolver.ts`).
4
4
  *
5
5
  * The two channels:
6
6
  * - `indexes.bindings` — finalize-output channel. After
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Dev-mode runtime validator for the two-channel binding lifecycle
3
- * (Contract Invariant I8 in `contract/scope-resolver.ts`).
2
+ * Dev-mode runtime validator for the post-finalize binding-channel
3
+ * lifecycle (Contract Invariant I8 in `contract/scope-resolver.ts`).
4
4
  *
5
5
  * The two channels:
6
6
  * - `indexes.bindings` — finalize-output channel. After
@@ -61,5 +61,18 @@ export function validateBindingsImmutability(indexes, onWarn) {
61
61
  }
62
62
  }
63
63
  }
64
+ // Third channel: `workspaceFqnBindings` (scope-independent, shared map
65
+ // populated by language namespace-sibling hooks — PHP FQN keys, C#
66
+ // global-namespace simple names). Like bindingAugmentations its inner
67
+ // arrays are mutable by contract (hooks `push()` directly), so freezing
68
+ // one is the same defect as freezing an augmentation bucket.
69
+ for (const [name, bucket] of indexes.workspaceFqnBindings) {
70
+ if (Object.isFrozen(bucket)) {
71
+ onWarn(`binding-immutability: indexes.workspaceFqnBindings[${name}] is FROZEN — ` +
72
+ `the workspace channel is mutable by contract; freezing it defeats the ` +
73
+ `append-only purpose. See ScopeResolver Invariant I8.`);
74
+ violations++;
75
+ }
76
+ }
64
77
  return violations;
65
78
  }
@@ -55,6 +55,14 @@ export declare function lookupBindingsAt(scopeId: ScopeId, name: string, scopes:
55
55
  * Fast paths (zero allocation) when at most one channel is populated:
56
56
  * returns the underlying `Map.keys()` iterator directly. Only when both
57
57
  * channels carry names do we materialize a `Set` for deduplication.
58
+ *
59
+ * Scope: enumerates only the per-scope `bindings` and `bindingAugmentations`
60
+ * channels. It deliberately EXCLUDES the scope-independent
61
+ * `workspaceFqnBindings` channel (PHP FQN keys, C# global-namespace simple
62
+ * names). `lookupBindingsAt` consults that third channel when resolving a
63
+ * specific name, but name *enumeration* here does not — those names apply at
64
+ * every scope and would flood per-scope callers. Callers that need
65
+ * workspace-level names must read `workspaceFqnBindings` directly.
58
66
  */
59
67
  export declare function namesAtScope(scopeId: ScopeId, scopes: ScopeResolutionIndexes): Iterable<string>;
60
68
  /**
@@ -92,6 +92,14 @@ const EMPTY_NAMES = Object.freeze([]);
92
92
  * Fast paths (zero allocation) when at most one channel is populated:
93
93
  * returns the underlying `Map.keys()` iterator directly. Only when both
94
94
  * channels carry names do we materialize a `Set` for deduplication.
95
+ *
96
+ * Scope: enumerates only the per-scope `bindings` and `bindingAugmentations`
97
+ * channels. It deliberately EXCLUDES the scope-independent
98
+ * `workspaceFqnBindings` channel (PHP FQN keys, C# global-namespace simple
99
+ * names). `lookupBindingsAt` consults that third channel when resolving a
100
+ * specific name, but name *enumeration* here does not — those names apply at
101
+ * every scope and would flood per-scope callers. Callers that need
102
+ * workspace-level names must read `workspaceFqnBindings` directly.
95
103
  */
96
104
  export function namesAtScope(scopeId, scopes) {
97
105
  const finalized = scopes.bindings.get(scopeId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gitnexus",
3
- "version": "1.6.6-rc.90",
3
+ "version": "1.6.6-rc.91",
4
4
  "description": "Graph-powered code intelligence for AI agents. Index any codebase, query via MCP or CLI.",
5
5
  "author": "Abhigyan Patwari",
6
6
  "license": "PolyForm-Noncommercial-1.0.0",