@principal-ai/subsystems-react 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/index.d.ts +4 -0
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -0
  4. package/dist/index.js.map +1 -1
  5. package/dist/subsystem/ComponentDeclaration.d.ts +7 -1
  6. package/dist/subsystem/ComponentDeclaration.d.ts.map +1 -1
  7. package/dist/subsystem/ComponentDeclaration.js +169 -5
  8. package/dist/subsystem/ComponentDeclaration.js.map +1 -1
  9. package/dist/subsystem/ConstructsCatalog.d.ts +9 -1
  10. package/dist/subsystem/ConstructsCatalog.d.ts.map +1 -1
  11. package/dist/subsystem/ConstructsCatalog.js +9 -2
  12. package/dist/subsystem/ConstructsCatalog.js.map +1 -1
  13. package/dist/subsystem/IssueList.d.ts +4 -2
  14. package/dist/subsystem/IssueList.d.ts.map +1 -1
  15. package/dist/subsystem/IssueList.js +6 -6
  16. package/dist/subsystem/IssueList.js.map +1 -1
  17. package/dist/subsystem/SubsystemComponentGraph.d.ts +13 -0
  18. package/dist/subsystem/SubsystemComponentGraph.d.ts.map +1 -1
  19. package/dist/subsystem/SubsystemComponentGraph.js +10 -3
  20. package/dist/subsystem/SubsystemComponentGraph.js.map +1 -1
  21. package/dist/subsystem/SymbolInspectionCard.d.ts +31 -0
  22. package/dist/subsystem/SymbolInspectionCard.d.ts.map +1 -0
  23. package/dist/subsystem/SymbolInspectionCard.js +247 -0
  24. package/dist/subsystem/SymbolInspectionCard.js.map +1 -0
  25. package/dist/subsystem/symbolRefs.d.ts +95 -0
  26. package/dist/subsystem/symbolRefs.d.ts.map +1 -0
  27. package/dist/subsystem/symbolRefs.js +167 -0
  28. package/dist/subsystem/symbolRefs.js.map +1 -0
  29. package/package.json +1 -1
  30. package/src/index.ts +14 -0
  31. package/src/stories/Subsystem/ComponentDeclarationSymbols.stories.tsx +269 -0
  32. package/src/subsystem/ComponentDeclaration.tsx +239 -9
  33. package/src/subsystem/ConstructsCatalog.tsx +20 -0
  34. package/src/subsystem/IssueList.tsx +10 -8
  35. package/src/subsystem/SubsystemComponentGraph.tsx +26 -1
  36. package/src/subsystem/SymbolInspectionCard.tsx +433 -0
  37. package/src/subsystem/symbolRefs.test.ts +127 -0
  38. package/src/subsystem/symbolRefs.ts +256 -0
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Referenced symbols inside a component's declaration.
3
+ *
4
+ * A declaration mentions other symbols — parameter/return types, property
5
+ * types, `extends`/`implements`, and related callables (`callers`/`callees`,
6
+ * `references`/`usedBy`). This module flattens the structured declaration into
7
+ * a deduped, lookup-friendly list so the panel can offer a graphify inspection
8
+ * per name, and defines the payload graphify returns for one.
9
+ *
10
+ * Slice 1 is display-only: the inspection payload is produced by the host (or,
11
+ * in stories, by a fixture). Nothing here reads the graph.
12
+ */
13
+ import type { GraphifyComponentDetail } from '../graphify';
14
+ /** One symbol a declaration references, normalized for lookup. */
15
+ export interface DeclarationSymbolRef {
16
+ /** Referenced name as written (e.g. `SessionRecord`), no call/`()` decoration. */
17
+ name: string;
18
+ /** Graphify node id when the backing reference carried one. */
19
+ nodeId?: string;
20
+ /** Reference context (`parameter_type`, `return_type`, `field`, `caller`, …). */
21
+ context?: string;
22
+ /** `L<line>` of the reference site, when known. */
23
+ sourceLocation?: string;
24
+ }
25
+ /**
26
+ * How a symbol resolved against the cached graphify graph. Name-first, so it
27
+ * mirrors the type-ref resolver (`graphify/resolve.ts`) rather than component
28
+ * anchoring — there is no claimed file to fall back to.
29
+ */
30
+ export type SymbolInspectionResolution =
31
+ /** Exactly one definition node for the name. */
32
+ 'resolved'
33
+ /** Referenced, but no definition in this corpus (external / ambient type). */
34
+ | 'unresolved'
35
+ /** Multiple same-label definitions. */
36
+ | 'ambiguous'
37
+ /** The name isn't in the graph at all. */
38
+ | 'missing';
39
+ export interface SymbolInspectionNode {
40
+ nodeId: string;
41
+ label: string;
42
+ /** Repo-root-relative source path. */
43
+ sourceFile?: string;
44
+ /** `L<line>` of the definition. */
45
+ sourceLocation?: string;
46
+ fileType?: string;
47
+ community?: string;
48
+ }
49
+ export interface SymbolInspectionCandidate {
50
+ nodeId: string;
51
+ label: string;
52
+ sourceFile?: string;
53
+ }
54
+ /**
55
+ * The actual source declaration, read from the checkout at the node's anchor.
56
+ * Used when graphify resolved a location but couldn't reconstruct the shape.
57
+ */
58
+ export interface SymbolInspectionSource {
59
+ file: string;
60
+ startLine?: number;
61
+ /** Declaration text as read from source. */
62
+ text: string;
63
+ }
64
+ /**
65
+ * What graphify has on one symbol. The useful payload is `declaration` — the
66
+ * symbol's declaration shape, rebuilt from graph edges — with `source` as the
67
+ * fallback when graphify knows where the symbol is but not what it is.
68
+ * `resolution` and `candidates` explain a miss; the rest of the graph's
69
+ * inference bookkeeping is deliberately not part of this payload.
70
+ */
71
+ export interface SymbolInspection {
72
+ symbol: string;
73
+ purl?: string;
74
+ resolution: SymbolInspectionResolution;
75
+ node?: SymbolInspectionNode;
76
+ /** The symbol's declaration, when graphify could reconstruct it. */
77
+ declaration?: GraphifyComponentDetail;
78
+ /** The declaration as read from source, when only the location is known. */
79
+ source?: SymbolInspectionSource;
80
+ candidates?: SymbolInspectionCandidate[];
81
+ /** Human-readable reason when there's neither a declaration nor source. */
82
+ reason?: string;
83
+ }
84
+ /**
85
+ * True when there's no declaration to show — either graphify couldn't resolve
86
+ * the symbol or couldn't reconstruct its shape. The case where offering
87
+ * "add to model + agent" is worthwhile.
88
+ */
89
+ export declare function isLimitedInspection(info: SymbolInspection | null | undefined): boolean;
90
+ /**
91
+ * Flatten a declaration into the set of symbols it references, deduped by name.
92
+ * Entries backed by a `nodeId` win over bare-name entries.
93
+ */
94
+ export declare function extractDeclarationSymbolRefs(declaration: GraphifyComponentDetail | undefined): DeclarationSymbolRef[];
95
+ //# sourceMappingURL=symbolRefs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbolRefs.d.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C,EAAE,oBAAoB,CAAC;IAC5B,oEAAoE;IACpE,WAAW,CAAC,EAAE,uBAAuB,CAAC;IACtC,4EAA4E;IAC5E,MAAM,CAAC,EAAE,sBAAsB,CAAC;IAChC,UAAU,CAAC,EAAE,yBAAyB,EAAE,CAAC;IACzC,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,GACxC,OAAO,CAET;AAwDD;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,uBAAuB,GAAG,SAAS,GAC/C,oBAAoB,EAAE,CAyFxB"}
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Referenced symbols inside a component's declaration.
3
+ *
4
+ * A declaration mentions other symbols — parameter/return types, property
5
+ * types, `extends`/`implements`, and related callables (`callers`/`callees`,
6
+ * `references`/`usedBy`). This module flattens the structured declaration into
7
+ * a deduped, lookup-friendly list so the panel can offer a graphify inspection
8
+ * per name, and defines the payload graphify returns for one.
9
+ *
10
+ * Slice 1 is display-only: the inspection payload is produced by the host (or,
11
+ * in stories, by a fixture). Nothing here reads the graph.
12
+ */
13
+ /**
14
+ * True when there's no declaration to show — either graphify couldn't resolve
15
+ * the symbol or couldn't reconstruct its shape. The case where offering
16
+ * "add to model + agent" is worthwhile.
17
+ */
18
+ export function isLimitedInspection(info) {
19
+ return !info?.declaration;
20
+ }
21
+ // ---------------------------------------------------------------------------
22
+ // Extraction
23
+ // ---------------------------------------------------------------------------
24
+ /** Names that carry no lookup value — primitives and non-identifiers. */
25
+ const PRIMITIVES = new Set([
26
+ 'string',
27
+ 'number',
28
+ 'boolean',
29
+ 'bigint',
30
+ 'symbol',
31
+ 'void',
32
+ 'null',
33
+ 'undefined',
34
+ 'never',
35
+ 'any',
36
+ 'unknown',
37
+ 'object',
38
+ 'true',
39
+ 'false',
40
+ 'self',
41
+ 'None',
42
+ 'True',
43
+ 'False',
44
+ 'bool',
45
+ 'int',
46
+ 'float',
47
+ 'str',
48
+ 'bytes',
49
+ 'list',
50
+ 'dict',
51
+ 'tuple',
52
+ 'set',
53
+ ]);
54
+ /** A bare (optionally dotted) identifier we can look up by name. */
55
+ function isSimpleSymbolName(type) {
56
+ if (!type)
57
+ return false;
58
+ const t = type.trim();
59
+ if (!/^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*)*$/.test(t))
60
+ return false;
61
+ return !PRIMITIVES.has(t);
62
+ }
63
+ /**
64
+ * Normalize a callable/related label (`normalize()`, `.get`, `capture-session`)
65
+ * to a name. Labels are freer than type expressions — kebab-case is common.
66
+ */
67
+ function normalizeRelatedName(raw) {
68
+ if (!raw)
69
+ return null;
70
+ const t = raw.trim().replace(/^\./, '').replace(/\(\)$/, '');
71
+ if (!/^[A-Za-z_$][\w$.-]*$/.test(t))
72
+ return null;
73
+ return PRIMITIVES.has(t) ? null : t;
74
+ }
75
+ /**
76
+ * Flatten a declaration into the set of symbols it references, deduped by name.
77
+ * Entries backed by a `nodeId` win over bare-name entries.
78
+ */
79
+ export function extractDeclarationSymbolRefs(declaration) {
80
+ if (!declaration)
81
+ return [];
82
+ const byName = new Map();
83
+ const add = (name, opts = {}) => {
84
+ if (!name)
85
+ return;
86
+ const existing = byName.get(name);
87
+ const nodeId = opts.ref?.nodeId;
88
+ const next = {
89
+ name,
90
+ nodeId: nodeId ?? existing?.nodeId,
91
+ context: opts.ref?.context ?? opts.context ?? existing?.context,
92
+ sourceLocation: opts.ref?.source_location ?? opts.sourceLocation ?? existing?.sourceLocation,
93
+ };
94
+ // Prefer the richer entry when we already have one with a nodeId.
95
+ if (existing?.nodeId && !nodeId)
96
+ return;
97
+ byName.set(name, next);
98
+ };
99
+ const addType = (type, ref, context) => {
100
+ if (!isSimpleSymbolName(type))
101
+ return;
102
+ add(type.trim(), { ref, context });
103
+ };
104
+ const addCall = (call, context) => {
105
+ if (!call)
106
+ return;
107
+ add(normalizeRelatedName(call.name), {
108
+ context,
109
+ sourceLocation: call.source_location,
110
+ });
111
+ };
112
+ switch (declaration.kind) {
113
+ case 'function':
114
+ for (const p of declaration.parameters ?? [])
115
+ addType(p.type, p.ref, 'parameter_type');
116
+ addType(declaration.returnType, declaration.returnTypeRef, 'return_type');
117
+ for (const c of declaration.callers ?? [])
118
+ addCall(c, 'caller');
119
+ for (const c of declaration.callees ?? [])
120
+ addCall(c, 'callee');
121
+ break;
122
+ case 'method':
123
+ for (const p of declaration.parameters ?? [])
124
+ addType(p.type, p.ref, 'parameter_type');
125
+ addType(declaration.returnType, undefined, 'return_type');
126
+ break;
127
+ case 'class':
128
+ for (const m of declaration.methods ?? []) {
129
+ for (const p of m.parameters ?? [])
130
+ addType(p.type, p.ref, 'parameter_type');
131
+ addType(m.returnType, m.returnTypeRef, 'return_type');
132
+ }
133
+ for (const p of declaration.properties ?? []) {
134
+ addType(p.type, p.typeRef, 'field');
135
+ }
136
+ for (const name of declaration.extends ?? [])
137
+ addType(name, undefined, 'extends');
138
+ for (const name of declaration.implements ?? [])
139
+ addType(name, undefined, 'implements');
140
+ for (const r of declaration.references ?? []) {
141
+ add(normalizeRelatedName(r.name), { ref: r, context: r.context ?? 'references' });
142
+ }
143
+ break;
144
+ case 'type':
145
+ for (const p of declaration.properties ?? []) {
146
+ addType(p.type, p.typeRef, 'field');
147
+ }
148
+ for (const r of declaration.usedBy ?? []) {
149
+ add(normalizeRelatedName(r.name), { ref: r, context: r.context ?? 'usedBy' });
150
+ }
151
+ for (const name of declaration.implementors ?? [])
152
+ addType(name, undefined, 'implementor');
153
+ addType(declaration.aliasOf, undefined, 'alias');
154
+ for (const alt of declaration.unionOf ?? [])
155
+ addType(alt, undefined, 'union');
156
+ break;
157
+ case 'store':
158
+ for (const p of declaration.properties ?? []) {
159
+ addType(p.type, p.typeRef, 'field');
160
+ }
161
+ break;
162
+ default:
163
+ break;
164
+ }
165
+ return [...byName.values()];
166
+ }
167
+ //# sourceMappingURL=symbolRefs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"symbolRefs.js","sourceRoot":"","sources":["../../src/subsystem/symbolRefs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAoFH;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAyC;IAEzC,OAAO,CAAC,IAAI,EAAE,WAAW,CAAC;AAC5B,CAAC;AAED,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E,yEAAyE;AACzE,MAAM,UAAU,GAAwB,IAAI,GAAG,CAAC;IAC9C,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,MAAM;IACN,WAAW;IACX,OAAO;IACP,KAAK;IACL,SAAS;IACT,QAAQ;IACR,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,KAAK;IACL,OAAO;IACP,KAAK;IACL,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,KAAK;CACN,CAAC,CAAC;AAEH,oEAAoE;AACpE,SAAS,kBAAkB,CAAC,IAA+B;IACzD,IAAI,CAAC,IAAI;QAAE,OAAO,KAAK,CAAC;IACxB,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IACtB,IAAI,CAAC,yCAAyC,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACrE,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC;AAED;;;GAGG;AACH,SAAS,oBAAoB,CAAC,GAAuB;IACnD,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IACtB,MAAM,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC7D,IAAI,CAAC,sBAAsB,CAA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AAE,SAAS,EAAE,aAAa,CAAC,CAAC;YAC3F,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YACjD,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,OAAO,IAAI,EAAE;gBAAE,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;YAC9E,MAAM;QACR,KAAK,OAAO;YACV,KAAK,MAAM,CAAC,IAAI,WAAW,CAAC,UAAU,IAAI,EAAE,EAAE;gBAC5C,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;aACrC;YACD,MAAM;QACR;YACE,MAAM;KACT;IAED,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AAC9B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@principal-ai/subsystems-react",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "description": "React UI for Subsystem Models — graph, Pierre code views, and session-event feeds",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -101,6 +101,20 @@ export type {
101
101
  ComponentDeclarationProps,
102
102
  } from './subsystem/ComponentDeclaration';
103
103
  export { ComponentDeclaration } from './subsystem/ComponentDeclaration';
104
+ export { SymbolInspectionCard } from './subsystem/SymbolInspectionCard';
105
+ export type { SymbolInspectionCardProps } from './subsystem/SymbolInspectionCard';
106
+ export {
107
+ extractDeclarationSymbolRefs,
108
+ isLimitedInspection,
109
+ } from './subsystem/symbolRefs';
110
+ export type {
111
+ DeclarationSymbolRef,
112
+ SymbolInspection,
113
+ SymbolInspectionResolution,
114
+ SymbolInspectionNode,
115
+ SymbolInspectionSource,
116
+ SymbolInspectionCandidate,
117
+ } from './subsystem/symbolRefs';
104
118
  export {
105
119
  SubsystemDiagnosticToggle,
106
120
  diagnosticStatusColor,
@@ -0,0 +1,269 @@
1
+ import React, { useState } from 'react';
2
+ import '@xyflow/react/dist/style.css';
3
+ import type { Meta, StoryObj } from '@storybook/react';
4
+ import { ThemeProvider, defaultEditorTheme } from '@principal-ade/industry-theme';
5
+ import { ComponentDeclaration } from '../../subsystem/ComponentDeclaration';
6
+ import type { SubsystemComponent } from '../../subsystem/model';
7
+ import type { GraphifyComponentDetail } from '../../graphify';
8
+ import type { SymbolInspection } from '../../subsystem/symbolRefs';
9
+
10
+ const meta = {
11
+ title: 'Subsystem/ComponentDeclarationSymbols',
12
+ component: ComponentDeclaration,
13
+ parameters: { layout: 'padded' },
14
+ tags: ['autodocs'],
15
+ decorators: [
16
+ (Story) => (
17
+ <ThemeProvider theme={defaultEditorTheme}>
18
+ <div style={{ maxWidth: '80ch', margin: '0 auto' }}>
19
+ <Story />
20
+ </div>
21
+ </ThemeProvider>
22
+ ),
23
+ ],
24
+ } satisfies Meta<typeof ComponentDeclaration>;
25
+ export default meta;
26
+
27
+ // ---------------------------------------------------------------------------
28
+ // Fixture graphify lookups — one per information level. Names absent from the
29
+ // map resolve as `missing`, mirroring "nothing in the cached graph".
30
+ // ---------------------------------------------------------------------------
31
+
32
+ const INSPECTIONS: Record<string, SymbolInspection> = {
33
+ RawEvent: {
34
+ symbol: 'RawEvent',
35
+ purl: 'pkg:github/principal-ai/agent-monitoring',
36
+ resolution: 'resolved',
37
+ node: {
38
+ nodeId: 'eventprocessing_types_rawevent',
39
+ label: 'RawEvent',
40
+ sourceFile: 'src/event-processing/types.ts',
41
+ sourceLocation: 'L8',
42
+ },
43
+ declaration: {
44
+ kind: 'type',
45
+ properties: [
46
+ { name: 'id', type: 'string' },
47
+ { name: 'at', type: 'number' },
48
+ { name: 'payload', type: 'unknown' },
49
+ ],
50
+ usedBy: [],
51
+ implementors: [],
52
+ },
53
+ },
54
+ BaseProcessor: {
55
+ symbol: 'BaseProcessor',
56
+ purl: 'pkg:github/principal-ai/agent-monitoring',
57
+ resolution: 'resolved',
58
+ node: {
59
+ nodeId: 'eventprocessing_baseprocessor_baseprocessor',
60
+ label: 'BaseProcessor',
61
+ sourceFile: 'src/event-processing/BaseProcessor.ts',
62
+ sourceLocation: 'L3',
63
+ },
64
+ declaration: {
65
+ kind: 'class',
66
+ methods: [{ nodeId: 'm-run', name: 'run', parameters: [], returnType: 'void' }],
67
+ properties: [],
68
+ extends: [],
69
+ implements: [],
70
+ instantiations: [],
71
+ references: [],
72
+ },
73
+ },
74
+ // Limited: graphify resolved the location but couldn't reconstruct the
75
+ // shape — the card falls back to the source declaration, still offering
76
+ // "Add to references" because the model has no structured declaration.
77
+ ProcessingOptions: {
78
+ symbol: 'ProcessingOptions',
79
+ purl: 'pkg:github/principal-ai/agent-monitoring',
80
+ resolution: 'resolved',
81
+ node: {
82
+ nodeId: 'eventprocessing_types_processingoptions',
83
+ label: 'ProcessingOptions',
84
+ sourceFile: 'src/event-processing/types.ts',
85
+ sourceLocation: 'L21',
86
+ },
87
+ source: {
88
+ file: 'src/event-processing/types.ts',
89
+ startLine: 21,
90
+ text: 'interface ProcessingOptions {\n retries: number;\n timeoutMs: number;\n}',
91
+ },
92
+ },
93
+ // Limited: multiple same-label definitions.
94
+ ProcessedEvent: {
95
+ symbol: 'ProcessedEvent',
96
+ resolution: 'ambiguous',
97
+ candidates: [
98
+ { nodeId: 'a1', label: 'ProcessedEvent', sourceFile: 'src/event-processing/types.ts' },
99
+ { nodeId: 'a2', label: 'ProcessedEvent', sourceFile: 'src/legacy/types.ts' },
100
+ ],
101
+ },
102
+ // Limited: referenced but not defined in this corpus (external/ambient type).
103
+ Disposable: {
104
+ symbol: 'Disposable',
105
+ resolution: 'unresolved',
106
+ reason: 'referenced but not defined in this corpus',
107
+ },
108
+ // Limited: nothing in the corpus.
109
+ EventEmitterLike: {
110
+ symbol: 'EventEmitterLike',
111
+ resolution: 'missing',
112
+ reason: 'no matching definition in the cached graph',
113
+ },
114
+ SessionRecord: {
115
+ symbol: 'SessionRecord',
116
+ resolution: 'resolved',
117
+ node: {
118
+ nodeId: 'session_transcript_sessionrecord',
119
+ label: 'SessionRecord',
120
+ sourceFile: 'src/session/transcript.ts',
121
+ sourceLocation: 'L12',
122
+ },
123
+ declaration: {
124
+ kind: 'type',
125
+ properties: [
126
+ { name: 'id', type: 'string' },
127
+ { name: 'admittedSeq', type: 'number' },
128
+ { name: 'events', type: 'SessionEvent[]' },
129
+ ],
130
+ usedBy: [],
131
+ implementors: [],
132
+ },
133
+ },
134
+ 'capture-session': {
135
+ symbol: 'capture-session',
136
+ resolution: 'resolved',
137
+ node: {
138
+ nodeId: 'session_capture_capture_session',
139
+ label: 'capture-session()',
140
+ sourceFile: 'src/session/capture.ts',
141
+ sourceLocation: 'L40',
142
+ },
143
+ declaration: {
144
+ kind: 'function',
145
+ parameters: [{ name: 'session', type: 'SessionRecord' }],
146
+ returnType: 'Promise<void>',
147
+ callers: [],
148
+ callees: [],
149
+ },
150
+ },
151
+ };
152
+
153
+ const inspect = (symbol: string): Promise<SymbolInspection> =>
154
+ new Promise((resolve) =>
155
+ setTimeout(
156
+ () =>
157
+ resolve(
158
+ INSPECTIONS[symbol] ?? {
159
+ symbol,
160
+ resolution: 'missing',
161
+ reason: 'no matching definition in the cached graph',
162
+ },
163
+ ),
164
+ 220,
165
+ ),
166
+ );
167
+
168
+ function Harness({ component }: { component: SubsystemComponent }) {
169
+ const [log, setLog] = useState<string[]>([]);
170
+ return (
171
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
172
+ <div style={{ fontFamily: 'monospace', fontSize: 11, color: '#888' }}>
173
+ Click a dotted-underlined symbol to inspect what graphify has on it.
174
+ </div>
175
+ <ComponentDeclaration
176
+ component={component}
177
+ onInspectSymbol={inspect}
178
+ onAddToModel={(ref, info) =>
179
+ setLog((l) => [`add ${ref.name} (${info?.resolution ?? 'no info'})`, ...l])
180
+ }
181
+ onOpenFile={(file, opts) =>
182
+ setLog((l) => [
183
+ `open ${file}${opts?.startLine ? `:${opts.startLine}` : ''}`,
184
+ ...l,
185
+ ])
186
+ }
187
+ />
188
+ <div
189
+ data-symbol-action-log
190
+ style={{ fontFamily: 'monospace', fontSize: 11, color: '#6a9955', minHeight: 16 }}
191
+ >
192
+ {log.length ? `actions: ${log.join(' · ')}` : 'actions: —'}
193
+ </div>
194
+ </div>
195
+ );
196
+ }
197
+
198
+ // ---------------------------------------------------------------------------
199
+ // A class whose declaration references a range of symbols — resolved
200
+ // (type/class), thin (unknown construct → "Add to references"), ambiguous,
201
+ // unresolved, and missing.
202
+ // ---------------------------------------------------------------------------
203
+
204
+ const classComponent: SubsystemComponent = {
205
+ alias: 'class-event-processor',
206
+ name: 'EventProcessor',
207
+ construct: 'class',
208
+ file: 'src/event-processing/EventProcessor.ts',
209
+ purl: 'pkg:github/principal-ai/agent-monitoring',
210
+ symbol: 'EventProcessor',
211
+ purpose: 'Consumes raw events and emits processed ones.',
212
+ declaration: {
213
+ kind: 'class',
214
+ methods: [
215
+ {
216
+ nodeId: 'm-process',
217
+ name: 'process',
218
+ parameters: [
219
+ { name: 'event', type: 'RawEvent' },
220
+ { name: 'options', type: 'ProcessingOptions' },
221
+ ],
222
+ returnType: 'ProcessedEvent',
223
+ },
224
+ {
225
+ nodeId: 'm-batch',
226
+ name: 'batch',
227
+ parameters: [{ name: 'events', type: 'RawEvent[]' }],
228
+ returnType: 'Promise<ProcessedEvent[]>',
229
+ },
230
+ { nodeId: 'm-dispose', name: 'dispose' },
231
+ ],
232
+ properties: [
233
+ { name: 'queue', type: 'RawEvent[]' },
234
+ { name: 'options', type: 'Required<ProcessingOptions>' },
235
+ ],
236
+ extends: ['BaseProcessor'],
237
+ implements: ['Disposable', 'EventEmitterLike'],
238
+ instantiations: [],
239
+ references: [{ nodeId: 'n-emitter', name: 'EventEmitterLike', context: 'type' }],
240
+ } satisfies GraphifyComponentDetail,
241
+ };
242
+
243
+ export const InspectableSymbols: StoryObj<Record<string, never>> = {
244
+ render: () => <Harness component={classComponent} />,
245
+ };
246
+
247
+ // ---------------------------------------------------------------------------
248
+ // A function — callers/callees are clickable too, alongside param/return types.
249
+ // ---------------------------------------------------------------------------
250
+
251
+ const functionComponent: SubsystemComponent = {
252
+ alias: 'fn-normalize',
253
+ name: 'normalize',
254
+ construct: 'function',
255
+ file: 'src/session/SessionReader.ts',
256
+ purl: 'pkg:github/principal-ai/agent-monitoring',
257
+ symbol: 'SessionReader.normalize',
258
+ declaration: {
259
+ kind: 'function',
260
+ parameters: [{ name: 'session', type: 'SessionRecord' }],
261
+ returnType: 'SessionEvent[]',
262
+ callers: [{ nodeId: 'c1', name: 'capture-session', source_location: 'L120' }],
263
+ callees: [{ nodeId: 'c2', name: 'toUniversalEvents', source_location: 'L64' }],
264
+ } satisfies GraphifyComponentDetail,
265
+ };
266
+
267
+ export const CallableRelated: StoryObj<Record<string, never>> = {
268
+ render: () => <Harness component={functionComponent} />,
269
+ };