@principal-ai/subsystems-react 0.56.31 → 0.56.33

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 (59) hide show
  1. package/dist/graphify/anchor.d.ts +1 -44
  2. package/dist/graphify/anchor.d.ts.map +1 -1
  3. package/dist/graphify/anchor.js +1 -172
  4. package/dist/graphify/anchor.js.map +1 -1
  5. package/dist/graphify/consolidated.d.ts +1 -258
  6. package/dist/graphify/consolidated.d.ts.map +1 -1
  7. package/dist/graphify/consolidated.js +1 -10
  8. package/dist/graphify/consolidated.js.map +1 -1
  9. package/dist/graphify/construct.d.ts +1 -40
  10. package/dist/graphify/construct.d.ts.map +1 -1
  11. package/dist/graphify/construct.js +1 -99
  12. package/dist/graphify/construct.js.map +1 -1
  13. package/dist/graphify/ids.d.ts +1 -18
  14. package/dist/graphify/ids.d.ts.map +1 -1
  15. package/dist/graphify/ids.js +1 -45
  16. package/dist/graphify/ids.js.map +1 -1
  17. package/dist/graphify/resolve.d.ts +1 -47
  18. package/dist/graphify/resolve.d.ts.map +1 -1
  19. package/dist/graphify/resolve.js +1 -82
  20. package/dist/graphify/resolve.js.map +1 -1
  21. package/dist/graphify/signature.d.ts +1 -86
  22. package/dist/graphify/signature.d.ts.map +1 -1
  23. package/dist/graphify/signature.js +1 -275
  24. package/dist/graphify/signature.js.map +1 -1
  25. package/dist/graphify/types.d.ts +1 -140
  26. package/dist/graphify/types.d.ts.map +1 -1
  27. package/dist/graphify/types.js +1 -7
  28. package/dist/graphify/types.js.map +1 -1
  29. package/dist/subsystem/IssueList.d.ts.map +1 -1
  30. package/dist/subsystem/IssueList.js +5 -2
  31. package/dist/subsystem/IssueList.js.map +1 -1
  32. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  33. package/dist/subsystem/SubsystemComponentGraph.js +33 -19
  34. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  35. package/dist/subsystem/containerCard.d.ts +6 -0
  36. package/dist/subsystem/containerCard.d.ts.map +1 -1
  37. package/dist/subsystem/containerCard.js +16 -1
  38. package/dist/subsystem/containerCard.js.map +1 -1
  39. package/dist/utils/elkLayout.d.ts +22 -0
  40. package/dist/utils/elkLayout.d.ts.map +1 -1
  41. package/dist/utils/elkLayout.js +55 -0
  42. package/dist/utils/elkLayout.js.map +1 -1
  43. package/package.json +3 -3
  44. package/src/graphify/anchor.ts +1 -206
  45. package/src/graphify/consolidated.ts +1 -298
  46. package/src/graphify/construct.ts +1 -153
  47. package/src/graphify/ids.ts +1 -48
  48. package/src/graphify/resolve.ts +1 -115
  49. package/src/graphify/signature.ts +1 -354
  50. package/src/graphify/types.ts +1 -164
  51. package/src/stories/Canvases/Subsystem/FocusReset.stories.tsx +55 -0
  52. package/src/stories/Canvases/Subsystem/fixtures/focus-reset-case.json +479 -0
  53. package/src/subsystem/IssueList.category.test.ts +11 -0
  54. package/src/subsystem/IssueList.tsx +5 -2
  55. package/src/subsystem/SubsystemComponentGraph.tsx +47 -19
  56. package/src/subsystem/containerCard.test.ts +30 -0
  57. package/src/subsystem/containerCard.tsx +34 -1
  58. package/src/utils/elkLayout.test.ts +33 -0
  59. package/src/utils/elkLayout.ts +75 -0
@@ -1,298 +1 @@
1
- /**
2
- * Graphify consolidated / drill-down types.
3
- *
4
- * graphify stores the graph in flat, normalized form — class vs function vs
5
- * type is NOT a node attribute (every code node is `file_type: "code"`); it is
6
- * derived from graph structure. These types rebuild that structure from the raw
7
- * edges so a UI can show a drill-down modal for a subsystem component or jump
8
- * to its definition file.
9
- */
10
-
11
- import type {
12
- GraphifyConfidence,
13
- GraphifyFileType,
14
- GraphifyRelation,
15
- } from './types';
16
-
17
- /** How a subsystem component resolved to a graphify node. */
18
- export type GraphifyAnchorResolution = 'exact' | 'file-only' | 'ambiguous' | 'missing';
19
-
20
- /**
21
- * The bridge between a facet component and the graphify graph.
22
- *
23
- * `nodeId` is reconstructed from the component's `file` + `symbol` via the id
24
- * slug scheme; `resolution` says how confident that reconstruction is.
25
- * `source_file` + `source_location` are the "open the definition" primitive.
26
- */
27
- export interface SubsystemGraphifyAnchor {
28
- /** Resolved graphify node id. */
29
- nodeId: string;
30
- /** PURL of the repo the node lives in (pkg:github/owner/repo). */
31
- purl: string;
32
- /** How the anchor resolved — the honesty signal for verification. */
33
- resolution: GraphifyAnchorResolution;
34
- /** Human-readable node label from the graph. */
35
- label: string;
36
- /** Repo-relative path of the node's source file. */
37
- source_file: string;
38
- /** `L<line>` — the line of the definition for a file-open jump. */
39
- source_location?: string;
40
- /** Node classification from the graph. */
41
- file_type: GraphifyFileType;
42
- /** Leiden community id. */
43
- community?: number | null;
44
- /** Human-readable community label. */
45
- community_name?: string;
46
- }
47
-
48
- // ---------------------------------------------------------------------------
49
- // Leaf info types — each backed by a specific graphify edge pattern
50
- // ---------------------------------------------------------------------------
51
-
52
- /** A method on a class-like node (`method` edge from the class). */
53
- export interface GraphifyMethodInfo {
54
- /** The method's own node id. */
55
- nodeId: string;
56
- /** Display name from the label (`.get()` → `get`). */
57
- name: string;
58
- /** Typed parameters from `references` edges with context `parameter_type`. */
59
- parameters?: GraphifyParamInfo[];
60
- /** Return type from a `references` edge with context `return_type`. */
61
- returnType?: string;
62
- /** Backing edge target for `returnType`, when the graph had one. */
63
- returnTypeRef?: GraphifyReferenceInfo;
64
- }
65
-
66
- /** A property/field on a class- or type-like node. */
67
- export interface GraphifyPropertyInfo {
68
- /** Field name — present when graphify emits a `defines` node (C++). */
69
- name: string;
70
- /** Field type from a `references` edge with context `field`. */
71
- type?: string;
72
- /** Backing edge target for `type`, when the graph had one. */
73
- typeRef?: GraphifyReferenceInfo;
74
- /** The field's own node id when it exists (e.g. C++ `defines` nodes). */
75
- nodeId?: string;
76
- }
77
-
78
- /**
79
- * A single typed parameter of a function (`references` context `parameter_type`).
80
- *
81
- * `ref.nodeId` is the resolvable half: it targets the type's definition node
82
- * when graphify resolved the reference, or a sourceless stub node when the
83
- * name was ambiguous / external (see `resolveGraphifyTypeRef`).
84
- */
85
- export interface GraphifyParamInfo {
86
- /** Parameter name — not captured by graphify; left undefined. */
87
- name?: string;
88
- /** Parameter type. */
89
- type: string;
90
- /** Backing `references[parameter_type|generic_arg]` edge target. */
91
- ref?: GraphifyReferenceInfo;
92
- }
93
-
94
- /** One call relationship, in either direction. */
95
- export interface GraphifyCallInfo {
96
- /** The other endpoint's node id (caller for `callers`, callee for `callees`). */
97
- nodeId: string;
98
- /** The other endpoint's display label. */
99
- name: string;
100
- /** `L<line>` of the call site. */
101
- source_location?: string;
102
- }
103
-
104
- /** A type-name reference to a node (`references` edge with a context). */
105
- export interface GraphifyReferenceInfo {
106
- /** The referenced node id. */
107
- nodeId: string;
108
- /** The referenced node's display label. */
109
- name: string;
110
- /** Reference context (e.g. `type`, `field`, `generic_arg`, `attribute`). */
111
- context?: string;
112
- /** `L<line>` of the reference site. */
113
- source_location?: string;
114
- }
115
-
116
- // ---------------------------------------------------------------------------
117
- // Discriminated union — the drill-down payload
118
- // ---------------------------------------------------------------------------
119
-
120
- /** A class-like node: owns outgoing `method` edges. */
121
- export interface GraphifyClassDetail {
122
- kind: 'class';
123
- /** Methods connected via `method` edges. */
124
- methods: GraphifyMethodInfo[];
125
- /** Fields from `defines`/`references` context `field`. */
126
- properties: GraphifyPropertyInfo[];
127
- /** `inherits` edge targets. */
128
- extends: string[];
129
- /** `implements` edge targets. */
130
- implements: string[];
131
- /** Incoming `calls` — graphify models constructor calls as calls into the class. */
132
- instantiations: GraphifyCallInfo[];
133
- /** Everywhere the type name is referenced (`references` edges). */
134
- references: GraphifyReferenceInfo[];
135
- }
136
-
137
- /** A function-like node: label ends `name()` with no `method` edges. */
138
- export interface GraphifyFunctionDetail {
139
- kind: 'function';
140
- /** Parameter types from `references` context `parameter_type`. */
141
- parameters: GraphifyParamInfo[];
142
- /** Return type from `references` context `return_type`. */
143
- returnType?: string;
144
- /** Backing edge target for `returnType`, when the graph had one. */
145
- returnTypeRef?: GraphifyReferenceInfo;
146
- /** Incoming `calls` edges. */
147
- callers: GraphifyCallInfo[];
148
- /** Outgoing `calls` edges. */
149
- callees: GraphifyCallInfo[];
150
- }
151
-
152
- /** One generic type parameter, e.g. `T` or `K extends keyof StudioMessages`. */
153
- export interface GraphifyTypeParamInfo {
154
- name: string;
155
- /** Constraint written after `extends` (or language equivalent). */
156
- constraint?: string;
157
- }
158
-
159
- /** A callable/function type: `(params) => returnType`. */
160
- export interface GraphifyCallableTypeInfo {
161
- parameters?: GraphifyParamInfo[];
162
- returnType?: string;
163
- }
164
-
165
- /** One enum member, with its optional literal value. */
166
- export interface GraphifyEnumMemberInfo {
167
- name: string;
168
- value?: string;
169
- }
170
-
171
- /** A type-like node (interface/struct): revealed by incoming `implements` edges. */
172
- export interface GraphifyTypeDetail {
173
- kind: 'type';
174
- /** Struct/interface fields. */
175
- properties: GraphifyPropertyInfo[];
176
- /** Nodes referencing this type name. */
177
- usedBy: GraphifyReferenceInfo[];
178
- /** Nodes that `inherits`/`implements` this type. */
179
- implementors: string[];
180
- /** Generic type parameters, e.g. `<K extends keyof StudioMessages>`. */
181
- generics?: GraphifyTypeParamInfo[];
182
- /** Callable type — `(params) => returnType` (TS/Go/Rust fn, Java lambda). */
183
- signature?: GraphifyCallableTypeInfo;
184
- /** Enum members (name, optional literal value). */
185
- enumMembers?: GraphifyEnumMemberInfo[];
186
- /** Alias whose RHS is a plain reference, e.g. `StudioMessages[K]`. */
187
- aliasOf?: string;
188
- /** Simple union of alternatives, e.g. `'started' | 'stopped'`. */
189
- unionOf?: string[];
190
- /**
191
- * Verbatim RHS — the escape hatch for shapes the structured fields can't
192
- * express (mapped/conditional/template-literal/infer types, `typeof`/utility
193
- * compositions, C pointers, Rust trait objects). Wins over every shape above.
194
- */
195
- rhs?: string;
196
- }
197
-
198
- /** A facet-only component with no graphify node (external consumer stub). */
199
- export interface GraphifyExternalDetail {
200
- kind: 'external';
201
- /** Facet-only label; there is no backing graph data. */
202
- label?: string;
203
- /**
204
- * Authored key/value facts about the dependency (endpoints, install command,
205
- * db path). Mirrors the model document's `external.attributes`; graphify never
206
- * populates it, it is authored alongside the facet.
207
- */
208
- attributes?: GraphifyCustomEntityAttribute[];
209
- }
210
-
211
- /** A single authored attribute on a custom entity — free-form key/value. */
212
- export interface GraphifyCustomEntityAttribute {
213
- key: string;
214
- value: string;
215
- }
216
-
217
- /**
218
- * A custom-entity (actor — Person/agent/queue) declaration. Authored, never
219
- * extracted: there is no graphify node for a Person. `attributes` are
220
- * free-form key/value pairs surfaced in the declaration panel; the base
221
- * component fields carry the node identity (`entityKind`, `color`, `purpose`).
222
- */
223
- export interface GraphifyCustomEntityDetail {
224
- kind: 'custom_entity';
225
- attributes: GraphifyCustomEntityAttribute[];
226
- }
227
-
228
- /**
229
- * A retained-state node (`kind: 'store'`): state and its contract, no
230
- * behavior. `kind` is the node's verifiable anchor — a store anchors to a
231
- * *state location* (module consts, a file or db), not to a declaration.
232
- * When a class manages the store's access, that is a SEPARATE node
233
- * (`kind: 'class'`, methods = the access mechanism) joined by
234
- * `writes`/`reads` — never merged into one hybrid node. This payload
235
- * renders as state declarations (`declare const …`), never as a class
236
- * stub.
237
- */
238
- export interface GraphifyStoreDetail {
239
- kind: 'store';
240
- /** The retained state members (module-level consts or class fields). */
241
- properties: GraphifyPropertyInfo[];
242
- /**
243
- * Where the retained state physically lives / who mediates access. Authored
244
- * — graphify cannot infer it: `memory` = process-lifetime RAM, `disk` =
245
- * this process reads/writes the filesystem, `external` = mediated by another
246
- * system (db/service; carries no `process`).
247
- */
248
- storage?: 'memory' | 'disk' | 'external';
249
- /**
250
- * The type of the retained state itself — a store declares its type the way
251
- * every other declaration does (`Map<string, FeedState>`, `Set<Listener>`,
252
- * a table's row type). Orthogonal to `storage`.
253
- */
254
- valueType?: string;
255
- /** Backing edge target for `valueType`, when the graph has one. */
256
- valueTypeRef?: GraphifyReferenceInfo;
257
- }
258
-
259
- /** A standalone method selected from its owning class. */
260
- export interface GraphifyMethodDetail {
261
- kind: 'method';
262
- /** The class that owns this method. */
263
- hostClass: string;
264
- /** Parameter types from `references` context `parameter_type`. */
265
- parameters?: GraphifyParamInfo[];
266
- /** Return type from `references` context `return_type`. */
267
- returnType?: string;
268
- }
269
-
270
- /**
271
- * The structured declaration payload for a subsystem component (click panel).
272
- *
273
- * The discriminant is derived from graph structure, not read off the node:
274
- * method edges → class; `()` label + no method edges → function; incoming
275
- * `implements` → type. File/module Graphify nodes are not subsystem
276
- * declaration kinds — anchor to a concrete export instead. `external`
277
- * covers consumer stubs. `method` covers standalone method components
278
- * selected from a class.
279
- */
280
- export type GraphifyComponentDetail =
281
- | GraphifyClassDetail
282
- | GraphifyFunctionDetail
283
- | GraphifyMethodDetail
284
- | GraphifyTypeDetail
285
- | GraphifyExternalDetail
286
- | GraphifyCustomEntityDetail
287
- | GraphifyStoreDetail;
288
-
289
- /** A raw graphify edge backing a facet claim (verification + provenance). */
290
- export interface GraphifyEdgeRef {
291
- source: string;
292
- target: string;
293
- relation: GraphifyRelation;
294
- confidence: GraphifyConfidence;
295
- confidence_score?: number;
296
- source_file: string;
297
- source_location?: string;
298
- }
1
+ export * from '@principal-ai/subsystems-core/graphify/consolidated';
@@ -1,153 +1 @@
1
- /**
2
- * Infer a subsystem-style construct from a graphify node + edges.
3
- *
4
- * Graphify does not store construct on nodes (everything is `file_type: "code"`).
5
- * Class vs function vs type is derived from structure — same rules as
6
- * `GraphifyComponentDetail` in consolidated.ts.
7
- */
8
-
9
- import type { GraphifyEdge, GraphifyNode } from './types';
10
-
11
- /** Construct inferred from graph structure (never read off the node). */
12
- export type InferredGraphifyConstruct =
13
- | 'class'
14
- | 'function'
15
- | 'method'
16
- | 'type'
17
- | 'module'
18
- | 'unknown';
19
-
20
- export interface InferConstructFromGraphifyResult {
21
- construct: InferredGraphifyConstruct;
22
- evidence: string[];
23
- }
24
-
25
- const FILE_LABEL_RE =
26
- /\.(py|js|jsx|ts|tsx|mjs|cjs|java|go|rs|rb|php|cs|cpp|cc|c|h|hpp|pas|pp|dpr|swift|kt|scala|dart|lua|pl|pm|ex|exs|zig|vue|svelte)$/i;
27
-
28
- function isMethodStyleLabel(label: string): boolean {
29
- return label.trim().startsWith('.');
30
- }
31
-
32
- function isCallStyleLabel(label: string): boolean {
33
- return label.trim().endsWith('()');
34
- }
35
-
36
- function isFilenameLabel(label: string, sourceFile: string): boolean {
37
- const trimmed = label.trim();
38
- if (FILE_LABEL_RE.test(trimmed)) return true;
39
- if (!sourceFile) return false;
40
- const base = sourceFile.replace(/\\/g, '/').split('/').pop() ?? '';
41
- return !!base && trimmed === base;
42
- }
43
-
44
- /**
45
- * Infer construct for a definition node from its label and incident edges.
46
- *
47
- * Priority: class → method → function → type → module → unknown.
48
- */
49
- export function inferConstructFromGraphify(
50
- node: GraphifyNode,
51
- edges: readonly GraphifyEdge[],
52
- ): InferConstructFromGraphifyResult {
53
- const id = String(node.id);
54
- const label = String(node.label ?? '').trim();
55
- const sourceFile =
56
- typeof node.source_file === 'string' ? node.source_file : '';
57
- const evidence: string[] = [];
58
-
59
- const outgoingMethod = edges.filter(
60
- (e) => String(e.source) === id && e.relation === 'method',
61
- );
62
- if (outgoingMethod.length > 0) {
63
- evidence.push(`${outgoingMethod.length} outgoing method edge(s)`);
64
- return { construct: 'class', evidence };
65
- }
66
-
67
- const incomingMethod = edges.filter(
68
- (e) => String(e.target) === id && e.relation === 'method',
69
- );
70
- if (incomingMethod.length > 0 && isMethodStyleLabel(label)) {
71
- evidence.push(
72
- `incoming method edge from ${String(incomingMethod[0]!.source)}`,
73
- `label ${label}`,
74
- );
75
- return { construct: 'method', evidence };
76
- }
77
-
78
- if (isCallStyleLabel(label)) {
79
- evidence.push(`call-style label ${label}`);
80
- return { construct: 'function', evidence };
81
- }
82
-
83
- const incomingImplements = edges.filter(
84
- (e) => String(e.target) === id && e.relation === 'implements',
85
- );
86
- if (incomingImplements.length > 0) {
87
- evidence.push(
88
- `${incomingImplements.length} incoming implements edge(s)`,
89
- );
90
- return { construct: 'type', evidence };
91
- }
92
-
93
- if (node.type === 'module' || isFilenameLabel(label, sourceFile)) {
94
- evidence.push(
95
- node.type === 'module'
96
- ? 'node.type=module'
97
- : `filename label ${label}`,
98
- );
99
- return { construct: 'module', evidence };
100
- }
101
-
102
- if (label) evidence.push(`unclassified label ${label}`);
103
- else evidence.push('no classifying signals');
104
- return { construct: 'unknown', evidence };
105
- }
106
-
107
- /** Type-family constructs all infer as the coarse 'type' — graph structure
108
- * (implements/references edges) cannot sub-classify interface vs alias vs
109
- * enum vs variable; only the source declaration can. */
110
- const TYPE_FAMILY: ReadonlySet<string> = new Set(['interface', 'type_alias', 'enum']);
111
-
112
- /** Strict claimed-vs-inferred check, with type-family compatibility. */
113
- export function constructsMatch(
114
- claimed: string | undefined,
115
- inferred: InferredGraphifyConstruct,
116
- ): boolean {
117
- if (!claimed || claimed === 'external') return true;
118
- if (TYPE_FAMILY.has(claimed)) return inferred === 'type';
119
- return claimed === inferred;
120
- }
121
-
122
- export interface ConstructCheckOutcome {
123
- /** true = confirmed, false = known mismatch, null = unconfirmed (needs agent). */
124
- match: boolean | null;
125
- /** Confirming construct from an accepted augmentation, when that is what confirmed it. */
126
- augmentedBy?: string;
127
- }
128
-
129
- /**
130
- * Resolve a claimed construct against Graphify's inferred construct, allowing an
131
- * accepted, agent-confirmed augmentation to stand in for Graphify when it is
132
- * silent (`unknown`) or when it disagrees.
133
- *
134
- * Graphify's inferred construct is a *structural hint*, never ground truth: its
135
- * vocabulary (`class | function | method | type | module | unknown`) has no
136
- * `store` or `custom_entity`, and a call-style accessor label biases it to
137
- * `function`. When source-reading confirms the model's claim, that confirmation
138
- * (recorded as an accepted augmentation) wins over the hint.
139
- */
140
- export function resolveConstructMatch(
141
- claimed: string | undefined,
142
- inferred: InferredGraphifyConstruct,
143
- augmentedConstruct?: string | null,
144
- ): ConstructCheckOutcome {
145
- const aug = augmentedConstruct?.trim();
146
- if (!claimed || claimed === 'external') return { match: true };
147
- const augConfirms = !!aug && aug === claimed;
148
- if (inferred === 'unknown') {
149
- return augConfirms ? { match: true, augmentedBy: aug } : { match: null };
150
- }
151
- if (constructsMatch(claimed, inferred)) return { match: true };
152
- return augConfirms ? { match: true, augmentedBy: aug } : { match: false };
153
- }
1
+ export * from '@principal-ai/subsystems-core/graphify/construct';
@@ -1,48 +1 @@
1
- /**
2
- * Mirror of graphify/ids.py — NFKC + casefold-ish + non-word → `_`.
3
- *
4
- * Definition node ids are `makeId(fileStem, ...symbolParts)`. Stub ids are
5
- * intentionally different (name-only / `ref_…`); this module is for the
6
- * definition path used by component anchoring.
7
- */
8
-
9
- /** Normalize one id string to graphify's canonical form. */
10
- export function normalizeGraphifyId(s: string): string {
11
- let out = s.normalize("NFKC");
12
- // JS has no Unicode casefold; lowercasing + second NFKC is close enough
13
- // for the Latin/ASCII identifiers we resolve in practice.
14
- out = out.toLowerCase().normalize("NFKC");
15
- out = out.replace(/[^\w]+/gu, "_");
16
- out = out.replace(/_+/g, "_");
17
- return out.replace(/^_|_$/g, "");
18
- }
19
-
20
- /** Build a canonical node id from path/symbol parts (graphify `make_id`). */
21
- export function makeGraphifyId(...parts: string[]): string {
22
- const joined = parts
23
- .filter((p) => typeof p === "string" && p.length > 0)
24
- .map((p) => p.replace(/^[_.]+|[_.]+$/g, ""))
25
- .filter(Boolean)
26
- .join("_");
27
- return normalizeGraphifyId(joined);
28
- }
29
-
30
- /**
31
- * File stem used as the node-id prefix (graphify `_file_stem`):
32
- * full path with extension dropped, posix separators.
33
- */
34
- export function graphifyFileStem(file: string): string {
35
- const posix = file.replace(/\\/g, "/").replace(/^\.\//, "");
36
- const lastSlash = posix.lastIndexOf("/");
37
- const base = lastSlash >= 0 ? posix.slice(lastSlash + 1) : posix;
38
- const dir = lastSlash >= 0 ? posix.slice(0, lastSlash + 1) : "";
39
- if (!base || base === ".") return "";
40
- const dot = base.lastIndexOf(".");
41
- const stemBase = dot > 0 ? base.slice(0, dot) : base;
42
- return `${dir}${stemBase}`;
43
- }
44
-
45
- /** Normalize a repo-relative path for source_file comparison. */
46
- export function normalizeSourcePath(file: string): string {
47
- return file.replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+/g, "/");
48
- }
1
+ export * from '@principal-ai/subsystems-core/graphify/ids';
@@ -1,115 +1 @@
1
- /**
2
- * Resolve graphify type-name references to their defining nodes.
3
- *
4
- * A `references` edge (`parameter_type`, `return_type`, `field`,
5
- * `generic_arg`) targets either the type's real definition node or a
6
- * *sourceless stub* graphify left behind when the name could not be uniquely
7
- * resolved at extraction time (mirrors `_rewire_unique_stub_nodes` there:
8
- * ambiguous same-label definitions and never-defined names stay stubs).
9
- *
10
- * This module applies the same conservative matching from the consumer side so
11
- * UI click targets can distinguish "jump to definition" from "N candidates"
12
- * from "not in this corpus".
13
- */
14
-
15
- import type { GraphifyNode } from './types';
16
- import type { GraphifyReferenceInfo } from './consolidated';
17
-
18
- /** Outcome of resolving one type reference. */
19
- export type GraphifyTypeRefStatus =
20
- /** Target node is a real definition — jump to its `source_file`. */
21
- | 'resolved'
22
- /** Target was a stub and multiple same-label definitions exist. */
23
- | 'ambiguous'
24
- /** Target was a stub and nothing in the corpus defines the name. */
25
- | 'unresolved'
26
- /** No nodeId on the ref, or the id is not in the graph. */
27
- | 'missing';
28
-
29
- export interface GraphifyTypeRefResolution {
30
- status: GraphifyTypeRefStatus;
31
- /** The definition node when resolved; the stub itself otherwise. */
32
- node: GraphifyNode | null;
33
- /** Same-label definitions when the target was an unresolved stub. */
34
- candidates: GraphifyNode[];
35
- }
36
-
37
- /**
38
- * Mirror graphify's `normalise_callable_label`: trim, strip surrounding
39
- * parens/leading dots, lowercase. `SessionReader()` and `sessionreader`
40
- * collapse to the same key.
41
- */
42
- export function normalizeGraphifyLabel(label: string): string {
43
- return label
44
- .trim()
45
- .replace(/^[()]+|[()]+$/g, '')
46
- .replace(/^\.+/, '')
47
- .toLowerCase();
48
- }
49
-
50
- const FILE_SUFFIX_RE =
51
- /\.(py|js|jsx|ts|tsx|mjs|cjs|java|go|rs|rb|php|cs|cpp|cc|c|h|hpp|pas|pp|dpr|swift|kt|scala|dart|lua|pl|pm|ex|exs|zig|vue|svelte)$/i;
52
-
53
- function isDefinition(node: GraphifyNode): boolean {
54
- if (node.file_type !== 'code') return false;
55
- const file = typeof node.source_file === 'string' ? node.source_file : '';
56
- if (!file) return false;
57
- const label = typeof node.label === 'string' ? node.label.trim() : '';
58
- return !!label && !FILE_SUFFIX_RE.test(label);
59
- }
60
-
61
- /** Prebuilt lookup state — build once per graph, resolve many refs. */
62
- export interface GraphifyTypeResolver {
63
- resolve(nodeId: string | undefined, fallbackLabel?: string): GraphifyTypeRefResolution;
64
- }
65
-
66
- export function createGraphifyTypeResolver(nodes: readonly GraphifyNode[]): GraphifyTypeResolver {
67
- const byId = new Map<string, GraphifyNode>();
68
- const defsByExactLabel = new Map<string, GraphifyNode[]>();
69
- const defsByFoldedLabel = new Map<string, GraphifyNode[]>();
70
-
71
- for (const node of nodes) {
72
- byId.set(String(node.id), node);
73
- if (!isDefinition(node)) continue;
74
- const label = String(node.label).trim();
75
- (defsByExactLabel.get(label) ?? defsByExactLabel.set(label, []).get(label)!).push(node);
76
- const folded = normalizeGraphifyLabel(label);
77
- if (!folded) continue;
78
- (defsByFoldedLabel.get(folded) ?? defsByFoldedLabel.set(folded, []).get(folded)!).push(node);
79
- }
80
-
81
- function resolve(nodeId: string | undefined, fallbackLabel?: string): GraphifyTypeRefResolution {
82
- if (!nodeId) return { status: 'missing', node: null, candidates: [] };
83
- const target = byId.get(nodeId);
84
- if (!target) return { status: 'missing', node: null, candidates: [] };
85
- // Real definition (graphify rewired the reference onto it, or it lived in
86
- // the referencing file all along).
87
- if (isDefinition(target)) return { status: 'resolved', node: target, candidates: [] };
88
-
89
- // Sourceless stub — try the rewire tiers: exact label, then folded.
90
- const label = typeof target.label === 'string' && target.label.trim() ? target.label.trim() : (fallbackLabel ?? '');
91
- let candidates = defsByExactLabel.get(label) ?? [];
92
- if (candidates.length !== 1) {
93
- const folded = normalizeGraphifyLabel(label);
94
- candidates = folded ? (defsByFoldedLabel.get(folded) ?? []) : [];
95
- }
96
- if (candidates.length === 1) {
97
- // Unique match — same fold `_rewire_unique_stub_nodes` performs at
98
- // extraction time; graphs built before that pass land here instead.
99
- return { status: 'resolved', node: candidates[0]!, candidates };
100
- }
101
- if (candidates.length > 1) return { status: 'ambiguous', node: target, candidates };
102
- return { status: 'unresolved', node: target, candidates: [] };
103
- }
104
-
105
- return { resolve };
106
- }
107
-
108
- /** One-shot convenience over {@link createGraphifyTypeResolver}. */
109
- export function resolveGraphifyTypeRef(
110
- nodes: readonly GraphifyNode[],
111
- ref: Pick<GraphifyReferenceInfo, 'nodeId'> | { nodeId?: string } | undefined,
112
- fallbackLabel?: string,
113
- ): GraphifyTypeRefResolution {
114
- return createGraphifyTypeResolver(nodes).resolve(ref?.nodeId, fallbackLabel);
115
- }
1
+ export * from '@principal-ai/subsystems-core/graphify/resolve';