@principal-ai/subsystems-react 0.56.32 → 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.
- package/dist/graphify/anchor.d.ts +1 -44
- package/dist/graphify/anchor.d.ts.map +1 -1
- package/dist/graphify/anchor.js +1 -172
- package/dist/graphify/anchor.js.map +1 -1
- package/dist/graphify/consolidated.d.ts +1 -258
- package/dist/graphify/consolidated.d.ts.map +1 -1
- package/dist/graphify/consolidated.js +1 -10
- package/dist/graphify/consolidated.js.map +1 -1
- package/dist/graphify/construct.d.ts +1 -40
- package/dist/graphify/construct.d.ts.map +1 -1
- package/dist/graphify/construct.js +1 -99
- package/dist/graphify/construct.js.map +1 -1
- package/dist/graphify/ids.d.ts +1 -18
- package/dist/graphify/ids.d.ts.map +1 -1
- package/dist/graphify/ids.js +1 -45
- package/dist/graphify/ids.js.map +1 -1
- package/dist/graphify/resolve.d.ts +1 -47
- package/dist/graphify/resolve.d.ts.map +1 -1
- package/dist/graphify/resolve.js +1 -82
- package/dist/graphify/resolve.js.map +1 -1
- package/dist/graphify/signature.d.ts +1 -86
- package/dist/graphify/signature.d.ts.map +1 -1
- package/dist/graphify/signature.js +1 -275
- package/dist/graphify/signature.js.map +1 -1
- package/dist/graphify/types.d.ts +1 -140
- package/dist/graphify/types.d.ts.map +1 -1
- package/dist/graphify/types.js +1 -7
- package/dist/graphify/types.js.map +1 -1
- package/dist/subsystem/IssueList.d.ts.map +1 -1
- package/dist/subsystem/IssueList.js +4 -1
- package/dist/subsystem/IssueList.js.map +1 -1
- package/dist/subsystem/containerCard.d.ts +6 -0
- package/dist/subsystem/containerCard.d.ts.map +1 -1
- package/dist/subsystem/containerCard.js +16 -1
- package/dist/subsystem/containerCard.js.map +1 -1
- package/package.json +3 -3
- package/src/graphify/anchor.ts +1 -206
- package/src/graphify/consolidated.ts +1 -298
- package/src/graphify/construct.ts +1 -153
- package/src/graphify/ids.ts +1 -48
- package/src/graphify/resolve.ts +1 -115
- package/src/graphify/signature.ts +1 -354
- package/src/graphify/types.ts +1 -164
- package/src/subsystem/IssueList.category.test.ts +11 -0
- package/src/subsystem/IssueList.tsx +4 -1
- package/src/subsystem/containerCard.test.ts +30 -0
- package/src/subsystem/containerCard.tsx +34 -1
|
@@ -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';
|
package/src/graphify/ids.ts
CHANGED
|
@@ -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';
|
package/src/graphify/resolve.ts
CHANGED
|
@@ -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';
|
|
@@ -1,354 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Signature / params verification against graphify `references` edges.
|
|
3
|
-
*
|
|
4
|
-
* Graphify does not store arity or parameter names — only `parameter_type` /
|
|
5
|
-
* `return_type` edges to type nodes (unions become multiple edges). Comparison
|
|
6
|
-
* is therefore **named type bags**, not positional arity.
|
|
7
|
-
*
|
|
8
|
-
* Many TS/JS functions have no such edges yet. When graphify has no signature
|
|
9
|
-
* signal, the check is skipped (not a hard fail) so Verify can still gate on
|
|
10
|
-
* kind. When graphify *does* emit types, claimed detail must match.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type { GraphifyEdge, GraphifyNode } from './types';
|
|
14
|
-
|
|
15
|
-
/** Inferred signature from graphify edges (no param names). */
|
|
16
|
-
export interface GraphifyInferredSignature {
|
|
17
|
-
parameters: Array<{ type: string; nodeId: string }>;
|
|
18
|
-
returnType?: string;
|
|
19
|
-
returnTypeNodeId?: string;
|
|
20
|
-
/**
|
|
21
|
-
* Types reachable only via `generic_arg` edges (Promise<X>, Array<X>,
|
|
22
|
-
* Omit<X,…>, Map<…>). Kept out of `parameters`/`returnType` — not read
|
|
23
|
-
* by the bag comparison — so skipped cases can be told apart.
|
|
24
|
-
*/
|
|
25
|
-
genericArgs?: Array<{ type: string; nodeId: string }>;
|
|
26
|
-
/**
|
|
27
|
-
* Count of `inline_parameter` self-edges (anonymous object-literal params).
|
|
28
|
-
* Graphify emits one per anon param only with its `--inline-params` flag.
|
|
29
|
-
*/
|
|
30
|
-
inlineParameters?: number;
|
|
31
|
-
/** True when at least one parameter_type or return_type edge exists. */
|
|
32
|
-
hasSignal: boolean;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface ClaimedSignature {
|
|
36
|
-
parameters?: Array<{ name?: string; type: string }>;
|
|
37
|
-
returnType?: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Granular skip classification. `signature_skipped` means "graphify has no
|
|
42
|
-
* parameter_type/return_type edges to compare", but *why* matters for future
|
|
43
|
-
* work:
|
|
44
|
-
* - `no_claimed_types`: authored detail has no named types (primitives/inline).
|
|
45
|
-
* - `generic_arg_only`: claimed types resolve, but only as `generic_arg`
|
|
46
|
-
* (Promise/Omit/Map/Array wrappers) — this extractor does not read them.
|
|
47
|
-
* - `partially_generic_arg`: some, not all, claimed types resolve as generic_arg.
|
|
48
|
-
* - `unresolved_claimed_types`: claimed names have no edges at all
|
|
49
|
-
* (global/npm types, or a dropped same-file label collision).
|
|
50
|
-
*/
|
|
51
|
-
export type SignatureSkipCode =
|
|
52
|
-
| 'no_claimed_types'
|
|
53
|
-
| 'generic_arg_only'
|
|
54
|
-
| 'partially_generic_arg'
|
|
55
|
-
| 'unresolved_claimed_types';
|
|
56
|
-
|
|
57
|
-
export interface SignatureCompareResult {
|
|
58
|
-
match: boolean;
|
|
59
|
-
/** Skipped because graphify had no parameter/return type edges. */
|
|
60
|
-
skipped: boolean;
|
|
61
|
-
reason?: string;
|
|
62
|
-
/** Granular skip classification when `skipped` is true. */
|
|
63
|
-
skipCode?: SignatureSkipCode;
|
|
64
|
-
claimed: { parameterTypes: string[]; returnTypes: string[] };
|
|
65
|
-
inferred: { parameterTypes: string[]; returnTypes: string[] };
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const PRIMITIVES = new Set([
|
|
69
|
-
'string',
|
|
70
|
-
'number',
|
|
71
|
-
'boolean',
|
|
72
|
-
'void',
|
|
73
|
-
'null',
|
|
74
|
-
'undefined',
|
|
75
|
-
'any',
|
|
76
|
-
'unknown',
|
|
77
|
-
'never',
|
|
78
|
-
'object',
|
|
79
|
-
'symbol',
|
|
80
|
-
'bigint',
|
|
81
|
-
'true',
|
|
82
|
-
'false',
|
|
83
|
-
'this',
|
|
84
|
-
]);
|
|
85
|
-
|
|
86
|
-
/** Common generic wrappers — keep inner type names, drop the wrapper. */
|
|
87
|
-
const TYPE_WRAPPERS = new Set([
|
|
88
|
-
'Promise',
|
|
89
|
-
'Array',
|
|
90
|
-
'ReadonlyArray',
|
|
91
|
-
'Map',
|
|
92
|
-
'Set',
|
|
93
|
-
'WeakMap',
|
|
94
|
-
'WeakSet',
|
|
95
|
-
'Record',
|
|
96
|
-
'Partial',
|
|
97
|
-
'Required',
|
|
98
|
-
'Readonly',
|
|
99
|
-
'Awaited',
|
|
100
|
-
'NonNullable',
|
|
101
|
-
'ReturnType',
|
|
102
|
-
'Parameters',
|
|
103
|
-
'InstanceType',
|
|
104
|
-
'Pick',
|
|
105
|
-
'Omit',
|
|
106
|
-
'Exclude',
|
|
107
|
-
'Extract',
|
|
108
|
-
]);
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Pull comparable named type identifiers out of an authored / graphify type
|
|
112
|
-
* string. Skips primitives, inline object types, and known wrappers.
|
|
113
|
-
*/
|
|
114
|
-
export function extractNamedTypes(typeStr: string): string[] {
|
|
115
|
-
if (!typeStr || !typeStr.trim()) return [];
|
|
116
|
-
let s = typeStr;
|
|
117
|
-
// Drop string/template literals so their contents aren't tokens.
|
|
118
|
-
s = s.replace(/`(?:\\.|[^`\\])*`/g, ' ');
|
|
119
|
-
s = s.replace(/'(?:\\.|[^'\\])*'/g, ' ');
|
|
120
|
-
s = s.replace(/"(?:\\.|[^"\\])*"/g, ' ');
|
|
121
|
-
// Drop inline object / mapped types (non-greedy, repeated for nesting).
|
|
122
|
-
for (let i = 0; i < 8; i++) {
|
|
123
|
-
const next = s.replace(/\{[^{}]*\}/g, ' ');
|
|
124
|
-
if (next === s) break;
|
|
125
|
-
s = next;
|
|
126
|
-
}
|
|
127
|
-
const found = new Set<string>();
|
|
128
|
-
const re = /[A-Za-z_][A-Za-z0-9_.]*/g;
|
|
129
|
-
let m: RegExpExecArray | null;
|
|
130
|
-
while ((m = re.exec(s)) !== null) {
|
|
131
|
-
const raw = m[0]!;
|
|
132
|
-
const base = raw.includes('.') ? (raw.split('.').pop() ?? raw) : raw;
|
|
133
|
-
if (PRIMITIVES.has(base)) continue;
|
|
134
|
-
if (TYPE_WRAPPERS.has(base)) continue;
|
|
135
|
-
// Skip lone lowercase keywords that aren't types we care about.
|
|
136
|
-
if (base === 'typeof' || base === 'keyof' || base === 'infer' || base === 'extends') {
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
found.add(base);
|
|
140
|
-
}
|
|
141
|
-
return [...found].sort();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function labelOf(
|
|
145
|
-
nodeId: string,
|
|
146
|
-
nodesById: ReadonlyMap<string, GraphifyNode>,
|
|
147
|
-
): string {
|
|
148
|
-
const n = nodesById.get(nodeId);
|
|
149
|
-
const label = n && typeof n.label === 'string' ? n.label.trim() : '';
|
|
150
|
-
return label || nodeId;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/** Collect parameter_type / return_type edges for a callable node. */
|
|
154
|
-
export function extractGraphifySignature(
|
|
155
|
-
nodeId: string,
|
|
156
|
-
edges: readonly GraphifyEdge[],
|
|
157
|
-
nodesById: ReadonlyMap<string, GraphifyNode>,
|
|
158
|
-
): GraphifyInferredSignature {
|
|
159
|
-
const id = String(nodeId);
|
|
160
|
-
const parameters: GraphifyInferredSignature['parameters'] = [];
|
|
161
|
-
const genericArgs: GraphifyInferredSignature['genericArgs'] = [];
|
|
162
|
-
let returnType: string | undefined;
|
|
163
|
-
let returnTypeNodeId: string | undefined;
|
|
164
|
-
let inlineParameters = 0;
|
|
165
|
-
|
|
166
|
-
for (const e of edges) {
|
|
167
|
-
if (String(e.source) !== id || e.relation !== 'references') continue;
|
|
168
|
-
const ctx = e.context;
|
|
169
|
-
const target = String(e.target);
|
|
170
|
-
if (ctx === 'parameter_type') {
|
|
171
|
-
parameters.push({ type: labelOf(target, nodesById), nodeId: target });
|
|
172
|
-
} else if (ctx === 'return_type' && returnType === undefined) {
|
|
173
|
-
returnType = labelOf(target, nodesById);
|
|
174
|
-
returnTypeNodeId = target;
|
|
175
|
-
} else if (ctx === 'generic_arg') {
|
|
176
|
-
genericArgs.push({ type: labelOf(target, nodesById), nodeId: target });
|
|
177
|
-
} else if (ctx === 'inline_parameter') {
|
|
178
|
-
inlineParameters += 1;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return {
|
|
183
|
-
parameters,
|
|
184
|
-
genericArgs,
|
|
185
|
-
returnType,
|
|
186
|
-
returnTypeNodeId,
|
|
187
|
-
inlineParameters,
|
|
188
|
-
hasSignal: parameters.length > 0 || returnType !== undefined,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function bagsEqual(a: string[], b: string[]): boolean {
|
|
193
|
-
if (a.length !== b.length) return false;
|
|
194
|
-
for (let i = 0; i < a.length; i++) {
|
|
195
|
-
if (a[i] !== b[i]) return false;
|
|
196
|
-
}
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function claimedBags(claimed: ClaimedSignature | undefined): {
|
|
201
|
-
parameterTypes: string[];
|
|
202
|
-
returnTypes: string[];
|
|
203
|
-
} {
|
|
204
|
-
const parameterTypes = new Set<string>();
|
|
205
|
-
for (const p of claimed?.parameters ?? []) {
|
|
206
|
-
for (const t of extractNamedTypes(p.type)) parameterTypes.add(t);
|
|
207
|
-
}
|
|
208
|
-
const returnTypes = new Set<string>();
|
|
209
|
-
if (claimed?.returnType) {
|
|
210
|
-
for (const t of extractNamedTypes(claimed.returnType)) returnTypes.add(t);
|
|
211
|
-
}
|
|
212
|
-
return {
|
|
213
|
-
parameterTypes: [...parameterTypes].sort(),
|
|
214
|
-
returnTypes: [...returnTypes].sort(),
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function inferredBags(inferred: GraphifyInferredSignature): {
|
|
219
|
-
parameterTypes: string[];
|
|
220
|
-
returnTypes: string[];
|
|
221
|
-
} {
|
|
222
|
-
const parameterTypes = new Set<string>();
|
|
223
|
-
for (const p of inferred.parameters) {
|
|
224
|
-
for (const t of extractNamedTypes(p.type)) parameterTypes.add(t);
|
|
225
|
-
}
|
|
226
|
-
const returnTypes = new Set<string>();
|
|
227
|
-
if (inferred.returnType) {
|
|
228
|
-
for (const t of extractNamedTypes(inferred.returnType)) returnTypes.add(t);
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
parameterTypes: [...parameterTypes].sort(),
|
|
232
|
-
returnTypes: [...returnTypes].sort(),
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Compare authored function/method detail signature to graphify edges.
|
|
238
|
-
*
|
|
239
|
-
* - No graphify signal → skipped (match=true).
|
|
240
|
-
* - Otherwise named-type bags for params and return must match exactly.
|
|
241
|
-
*/
|
|
242
|
-
export function compareSignatures(
|
|
243
|
-
claimed: ClaimedSignature | undefined,
|
|
244
|
-
inferred: GraphifyInferredSignature,
|
|
245
|
-
): SignatureCompareResult {
|
|
246
|
-
const claimedBagsResult = claimedBags(claimed);
|
|
247
|
-
const inferredBagsResult = inferredBags(inferred);
|
|
248
|
-
|
|
249
|
-
// Anonymous object-literal params ("inline") carry no named types, so they
|
|
250
|
-
// only ever surface via graphify's `inline_parameter` markers. A claim of an
|
|
251
|
-
// inline param against a graph with no marker proves nothing (the store
|
|
252
|
-
// graph may predate the flag), so absence alone keeps the skip path. When
|
|
253
|
-
// the graph DOES emit a marker, anon-count parity is compared like any
|
|
254
|
-
// parameter signal.
|
|
255
|
-
const claimedAnonCount = (claimed?.parameters ?? []).filter((p) =>
|
|
256
|
-
(p.type ?? '').trim().startsWith('{'),
|
|
257
|
-
).length;
|
|
258
|
-
const inferredAnonCount = inferred.inlineParameters ?? 0;
|
|
259
|
-
const hasAnonSignal = inferredAnonCount > 0;
|
|
260
|
-
|
|
261
|
-
if (!inferred.hasSignal && !hasAnonSignal) {
|
|
262
|
-
const claimedTypes = new Set<string>([
|
|
263
|
-
...claimedBagsResult.parameterTypes,
|
|
264
|
-
...claimedBagsResult.returnTypes,
|
|
265
|
-
]);
|
|
266
|
-
const genericArgTypes = new Set(
|
|
267
|
-
(inferred.genericArgs ?? []).map((a) => a.type),
|
|
268
|
-
);
|
|
269
|
-
const sorted = [...claimedTypes].sort();
|
|
270
|
-
let skipCode: SignatureSkipCode;
|
|
271
|
-
let reason: string;
|
|
272
|
-
if (sorted.length === 0) {
|
|
273
|
-
skipCode = 'no_claimed_types';
|
|
274
|
-
reason = 'no claimable named types in authored signature (primitives/inline only)';
|
|
275
|
-
} else {
|
|
276
|
-
const found = sorted.filter((t) => genericArgTypes.has(t));
|
|
277
|
-
if (found.length === sorted.length) {
|
|
278
|
-
skipCode = 'generic_arg_only';
|
|
279
|
-
reason = `claimed types ([${sorted.join(', ')}]) present only as generic_arg (wrapper-indirected: Promise/Omit/Map/Array) — extractor does not read generic_arg`;
|
|
280
|
-
} else if (found.length > 0) {
|
|
281
|
-
skipCode = 'partially_generic_arg';
|
|
282
|
-
reason = `claimed types resolve only via generic_arg for ${found.join(', ')}; rest unresolved (${sorted.filter((t) => !genericArgTypes.has(t)).join(', ')})`;
|
|
283
|
-
} else {
|
|
284
|
-
skipCode = 'unresolved_claimed_types';
|
|
285
|
-
reason = `claimed types ([${sorted.join(', ')}]) have no parameter_type/return_type/generic_arg edges (global/npm types or dropped same-file label collision)`;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
return {
|
|
289
|
-
match: true,
|
|
290
|
-
skipped: true,
|
|
291
|
-
reason,
|
|
292
|
-
skipCode,
|
|
293
|
-
claimed: claimedBagsResult,
|
|
294
|
-
inferred: inferredBagsResult,
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const paramsOk = bagsEqual(
|
|
299
|
-
claimedBagsResult.parameterTypes,
|
|
300
|
-
inferredBagsResult.parameterTypes,
|
|
301
|
-
);
|
|
302
|
-
const anonParamsOk = claimedAnonCount === inferredAnonCount;
|
|
303
|
-
const returnOk = bagsEqual(
|
|
304
|
-
claimedBagsResult.returnTypes,
|
|
305
|
-
inferredBagsResult.returnTypes,
|
|
306
|
-
);
|
|
307
|
-
const match = paramsOk && anonParamsOk && returnOk;
|
|
308
|
-
if (paramsOk && anonParamsOk && !returnOk) {
|
|
309
|
-
// Params verified, but the claimed return types can't be backed. When
|
|
310
|
-
// every claimed return type is either wrapper-indirected (generic_arg:
|
|
311
|
-
// Promise<X>, Omit<X,…>) or entirely unresolved (global/npm/DOM types),
|
|
312
|
-
// that's a coverage gap, not a lie — mark the check skipped instead of
|
|
313
|
-
// hard-failing, mirroring the pre-signal skip classification. A mixed
|
|
314
|
-
// bag (some generic, some unresolved) stays a hard mismatch.
|
|
315
|
-
const claimReturn = claimedBagsResult.returnTypes;
|
|
316
|
-
if (claimReturn.length > 0) {
|
|
317
|
-
const genericArgTypes = new Set(
|
|
318
|
-
(inferred.genericArgs ?? []).map((a) => a.type),
|
|
319
|
-
);
|
|
320
|
-
const gen = claimReturn.filter((t) => genericArgTypes.has(t));
|
|
321
|
-
const unresolved = claimReturn.filter((t) => !genericArgTypes.has(t));
|
|
322
|
-
let skipCode: SignatureSkipCode | undefined;
|
|
323
|
-
let reason: string | undefined;
|
|
324
|
-
if (gen.length === claimReturn.length) {
|
|
325
|
-
skipCode = 'generic_arg_only';
|
|
326
|
-
reason = `claimed return types ([${claimReturn.join(', ')}]) present only as generic_arg (wrapper-indirected: Promise/Omit/Map/Array) — extractor does not read generic_arg; params verified`;
|
|
327
|
-
} else if (unresolved.length === claimReturn.length) {
|
|
328
|
-
skipCode = 'unresolved_claimed_types';
|
|
329
|
-
reason = `claimed return types ([${claimReturn.join(', ')}]) have no parameter_type/return_type/generic_arg edges (global/npm types or dropped same-file label collision); params verified`;
|
|
330
|
-
}
|
|
331
|
-
if (skipCode) {
|
|
332
|
-
return {
|
|
333
|
-
match: true,
|
|
334
|
-
skipped: true,
|
|
335
|
-
reason,
|
|
336
|
-
skipCode,
|
|
337
|
-
claimed: claimedBagsResult,
|
|
338
|
-
inferred: inferredBagsResult,
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return {
|
|
344
|
-
match,
|
|
345
|
-
skipped: false,
|
|
346
|
-
reason: match
|
|
347
|
-
? undefined
|
|
348
|
-
: !paramsOk || !anonParamsOk
|
|
349
|
-
? 'parameter_types_mismatch'
|
|
350
|
-
: 'return_type_mismatch',
|
|
351
|
-
claimed: claimedBagsResult,
|
|
352
|
-
inferred: inferredBagsResult,
|
|
353
|
-
};
|
|
354
|
-
}
|
|
1
|
+
export * from '@principal-ai/subsystems-core/graphify/signature';
|