wire.ts 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. /**
  2. * The wire shapes of the graph API — types only, no runtime.
  3. *
  4. * These mirror the server's payloads (`src/ui-server/api/`, CG-42) rather than
  5. * re-deriving them: the API is versioned with the binary that serves it, so a
  6. * field the server stopped sending should break the type-check here, not
  7. * surface as `undefined` in a rail three screens later.
  8. *
  9. * They are also the vocabulary of {@link GraphAdapter} (`adapter.ts`): a host
  10. * embedding these components answers in exactly these shapes, whether it is
  11. * reading them over HTTP from `codegraph ui` or building them in-process from
  12. * its own engine. Keeping them in a file with no imports and no side effects is
  13. * what lets a host depend on the vocabulary without pulling in the transport.
  14. */
  15. import type { WireHighlight } from './highlight';
  16. /* ---------------------------------------------------------------- shapes -- */
  17. export type NodeKind = string;
  18. export type EdgeKind = string;
  19. export interface WireNodeRef {
  20. id: string;
  21. kind: NodeKind;
  22. name: string;
  23. qualifiedName: string;
  24. /** Project-relative, forward slashes on every platform. */
  25. file: string;
  26. line: number;
  27. endLine: number;
  28. language: string;
  29. signature?: string;
  30. exported?: boolean;
  31. /** Lives in a file that looks like test or fixture code. */
  32. test: boolean;
  33. /**
  34. * Lives in a tool-generated file, so the row draws in ink-4. Optional: only
  35. * the endpoints that show it pay for the lookup, so `undefined` means "not
  36. * asked", never "no".
  37. */
  38. generated?: boolean;
  39. }
  40. export interface WireNodeDetail extends WireNodeRef {
  41. startColumn: number;
  42. endColumn: number;
  43. docstring?: string;
  44. visibility?: string;
  45. async?: boolean;
  46. static?: boolean;
  47. abstract?: boolean;
  48. decorators?: string[];
  49. typeParameters?: string[];
  50. returnType?: string;
  51. lines: number;
  52. }
  53. export interface WireMember extends WireNodeRef {
  54. parentId: string;
  55. /** 1 = a direct member; 2 = a member of a member (a method inside a file's class). */
  56. depth: number;
  57. fanIn: number;
  58. fanOut: number;
  59. /** This member redeclares one an ancestor type declares. */
  60. overrides?: WireOverride;
  61. }
  62. /** How a subtype is tied to the type above it. */
  63. export type WireHierarchyRelation = 'extends' | 'implements';
  64. /** A member that redeclares an ancestor's — a name match inside a linked chain. */
  65. export interface WireOverride {
  66. baseId: string;
  67. baseTypeId: string;
  68. baseTypeName: string;
  69. relation: WireHierarchyRelation;
  70. }
  71. /** One type in the hierarchy tree, and the single edge that puts it there. */
  72. export interface WireHierarchyNode extends WireNodeRef {
  73. /** Steps from the focus, in whichever direction the row sits. 1 = direct. */
  74. depth: number;
  75. /** The row this one hangs off — the focus's id at depth 1. */
  76. parentId: string;
  77. relation: WireHierarchyRelation;
  78. /** Synthesized rather than parsed (Go's implicit interface satisfaction). */
  79. synthesized: boolean;
  80. via?: string;
  81. registeredAt?: string;
  82. /** Direct subtypes of this row that are NOT in the payload. */
  83. hiddenSubtypes: number;
  84. }
  85. /** Ancestors up, subtypes down, and the fan an interface call dispatches into. */
  86. export interface WireHierarchy {
  87. ancestors: WireList<WireHierarchyNode>;
  88. descendants: WireList<WireHierarchyNode>;
  89. /** True number of DIRECT subtypes, whatever `descendants` was capped to. */
  90. direct: number;
  91. /** Of `direct`, the ones tied by `implements`. */
  92. implementers: number;
  93. /** Subtypes exist below what the walk returned. */
  94. bounded: boolean;
  95. /** A call through this type dispatches at runtime rather than to one target. */
  96. polymorphic: boolean;
  97. }
  98. export interface WireEdge {
  99. kind: EdgeKind;
  100. line?: number;
  101. col?: number;
  102. confidence?: number;
  103. resolvedBy?: string;
  104. provenance?: string;
  105. synthesizedBy?: string;
  106. via?: string;
  107. registeredAt?: string;
  108. valueRef?: boolean;
  109. /** Branch conditions the call site runs under — `!isUploading && isCollected`. */
  110. when?: string;
  111. }
  112. /** Every edge between the focal symbol and ONE other symbol, as a single row. */
  113. export interface WireRelation {
  114. node: WireNodeRef;
  115. edgeKinds: EdgeKind[];
  116. edges: WireEdge[];
  117. edgeCount: number;
  118. /** Distinct call-site lines, ascending — what the gutter ports anchor to. */
  119. lines: number[];
  120. confidence: number | null;
  121. uncertain: boolean;
  122. synthesized: boolean;
  123. fanIn?: number;
  124. hub?: boolean;
  125. }
  126. export interface WireList<T> {
  127. total: number;
  128. shown: number;
  129. truncated: boolean;
  130. items: T[];
  131. }
  132. export interface WireTestSummary {
  133. reached: boolean;
  134. hops: number | null;
  135. fileCount: number;
  136. files: string[];
  137. /** False weakens the claim to "no test calls this directly" — see the server. */
  138. exhaustive: boolean;
  139. hopsSearched: number;
  140. }
  141. export interface WireOutsideIndex {
  142. total: number;
  143. byKind: Record<string, number>;
  144. samples: Array<{ name: string; kind: string; line?: number; col?: number }>;
  145. }
  146. export interface WireBlastSummary {
  147. direct: number;
  148. withinHops: number;
  149. hops: number;
  150. files: number;
  151. testFiles: number;
  152. routes: number;
  153. topFiles: Array<{ file: string; symbols: number; test: boolean }>;
  154. }
  155. export interface WireSymbolPayload {
  156. node: WireNodeDetail;
  157. /** Outermost first: file, then module/class, then the symbol's own parent. */
  158. ancestors: WireNodeRef[];
  159. members: WireList<WireMember>;
  160. /** The type-hierarchy block. `null` for anything that is not a type, and for a type with none. */
  161. hierarchy: WireHierarchy | null;
  162. incoming: WireList<WireRelation>;
  163. outgoing: WireList<WireRelation>;
  164. typesUsed: WireRelation[];
  165. counts: {
  166. callers: number;
  167. callees: number;
  168. typesUsed: number;
  169. fanIn: number;
  170. fanOut: number;
  171. members: number;
  172. hub: boolean;
  173. };
  174. tests: WireTestSummary;
  175. outsideIndex: WireOutsideIndex;
  176. blast: WireBlastSummary | null;
  177. /** The file changed on disk since the index — line ranges may be shifted. */
  178. drift: boolean;
  179. }
  180. export interface WireSource {
  181. file: string;
  182. language: string;
  183. drift: boolean;
  184. /**
  185. * Which numbering `lines` belong to. `'indexed'` — the file matches the
  186. * index. `'current'` — it drifted and we asked for the bytes anyway
  187. * (`ondrift: 'current'`), so nothing the graph holds about this file lines up
  188. * with them. `'none'` — it drifted and no slice came back.
  189. */
  190. showing: 'indexed' | 'current' | 'none';
  191. contentHash: string;
  192. indexedAt: number;
  193. generated: boolean;
  194. totalLines: number | null;
  195. from?: number;
  196. to?: number;
  197. /** Absent when the file drifted and `ondrift` was left at its default. */
  198. lines?: string[];
  199. truncated?: boolean;
  200. reason?: string;
  201. /**
  202. * The same lines, classified by the server's tree-sitter parse — one entry
  203. * per line, each a list of `[classId, text]` pairs indexed into `classes`.
  204. * Absent whenever `lines` is, and `engine: 'plain'` whenever no grammar
  205. * covers the file. See `lib/highlight.ts`.
  206. */
  207. highlight?: WireHighlight;
  208. }
  209. /* ------------------------------------------------------------- file view -- */
  210. /** A row in the file outline — a symbol, its nesting and its edge counts. */
  211. export interface WireOutlineEntry extends WireNodeRef {
  212. /** Containing symbol within this file, or null for a top-level one. */
  213. parentId: string | null;
  214. /** Nesting depth from the top level of the file, starting at 0. */
  215. depth: number;
  216. fanIn: number;
  217. fanOut: number;
  218. }
  219. /** One file at the far end of an import rail, with the symbols the edges name. */
  220. export interface WireImportRow {
  221. file: string;
  222. test: boolean;
  223. symbols: Array<{ id: string; name: string; kind: string; line: number }>;
  224. symbolCount: number;
  225. }
  226. export interface WireFilePayload {
  227. file: {
  228. path: string;
  229. language: string;
  230. size: number;
  231. modifiedAt: number;
  232. indexedAt: number;
  233. contentHash: string;
  234. nodeCount: number;
  235. generated: boolean;
  236. test: boolean;
  237. errors: string[];
  238. /** The file node's own id, so the viewer can open the file AS a symbol. */
  239. id: string | null;
  240. };
  241. /** Calls made outside every definition — module-level code. */
  242. topLevel: { calls: number };
  243. /** The file changed on disk since it was indexed; the outline's lines shifted. */
  244. drift: boolean;
  245. outline: WireList<WireOutlineEntry>;
  246. /** `imports` edges only — a subset of `dependencies`, with symbol names. */
  247. imports: WireList<WireImportRow>;
  248. importedBy: WireList<WireImportRow>;
  249. /** Import statements that resolved to nothing indexed: packages, builtins. */
  250. unresolvedImports: Array<{ name: string; line: number }>;
  251. /** Every file this one reaches by any cross-file edge — `getFileDependencies`. */
  252. dependencies: string[];
  253. /** Every file that reaches into this one — `getFileDependents`. */
  254. dependents: string[];
  255. }
  256. /* ------------------------------------------------ whole-file source view -- */
  257. /** A reference the resolver never landed: a gutter port with no destination. */
  258. export interface WireFileOutsideRef {
  259. line: number;
  260. col: number;
  261. name: string;
  262. kind: string;
  263. }
  264. /** Every edge from ONE symbol in a file to ONE symbol anywhere. */
  265. export interface WireFileCall {
  266. /** The symbol making the calls — the file node itself for top-level code. */
  267. ownerId: string;
  268. ownerLine: number;
  269. relation: WireRelation;
  270. }
  271. export interface WireFileCodePayload {
  272. file: {
  273. path: string;
  274. language: string;
  275. size: number;
  276. indexedAt: number;
  277. contentHash: string;
  278. generated: boolean;
  279. test: boolean;
  280. errors: string[];
  281. id: string | null;
  282. /** Lines on disk now — the height of the scrolling document. */
  283. totalLines: number | null;
  284. };
  285. drift: boolean;
  286. reason?: string;
  287. outline: WireList<WireOutlineEntry>;
  288. calls: WireList<WireFileCall>;
  289. outside: WireList<WireFileOutsideRef>;
  290. /** Calls landing on a definition in this same file — the arc diagram's total. */
  291. intraFileCalls: number;
  292. timing: { elapsedMs: number };
  293. }
  294. export interface WireBlastScale {
  295. maxDirect: number;
  296. maxWithinHops: number;
  297. hops: number;
  298. sampled: number;
  299. estimated: boolean;
  300. }
  301. /* ------------------------------------------------------- search palette -- */
  302. /** How a result's text matched the query — the server's primary sort key. */
  303. export type MatchKind = 'exact' | 'prefix' | 'substring' | 'qualified' | 'file' | 'related';
  304. export interface WireSearchResult extends WireNodeRef {
  305. matchKind: MatchKind;
  306. }
  307. export interface WireSearchGroup {
  308. kind: NodeKind;
  309. count: number;
  310. items: WireSearchResult[];
  311. }
  312. export interface WireSearch {
  313. query: string;
  314. /** The free-text part, with any `kind:` / `lang:` / `path:` filters removed. */
  315. text: string;
  316. filters: { kinds: string[]; languages: string[]; paths: string[]; names: string[] };
  317. results: WireList<WireSearchResult>;
  318. /** Kind buckets in ranked order — flattening them reproduces the ranking. */
  319. groups: WireSearchGroup[];
  320. }
  321. export interface WireNodeRefs {
  322. items: WireNodeRef[];
  323. /** Ids that name nothing in this index — a stale link, not an error. */
  324. missing: string[];
  325. }
  326. /* --------------------------------------------------------------- routes -- */
  327. /** One row of the URL -> handler map (`/api/routes`). */
  328. export interface WireRoute {
  329. /** The route node's name, verbatim: "POST /v1/users/{id}". */
  330. url: string;
  331. /** The verb, when the name leads with one. Null for a file-routed page. */
  332. method: string | null;
  333. /** The URL without the verb — the same string as `url` when there is none. */
  334. path: string;
  335. handler: string;
  336. handlerKind: string;
  337. /** Where the request is SERVED. */
  338. file: string;
  339. line: number;
  340. handlerId: string | null;
  341. /** Where the URL is REGISTERED — the router file, which is how routes group. */
  342. routeFile: string;
  343. routeLine: number;
  344. routeId: string;
  345. }
  346. export interface WireRoutes {
  347. routed: boolean;
  348. /** Every URL the index holds, whether or not its handler resolved. */
  349. routeCount: number;
  350. /** Rows in `entries` — the ones whose handler the manifest could name. */
  351. shown: number;
  352. truncated: boolean;
  353. topHandlerFile: string | null;
  354. topHandlerFileCount: number;
  355. entries: WireRoute[];
  356. }
  357. /* ---------------------------------------------------------- entry points -- */
  358. export interface WireEntryRoute {
  359. /** The route node's name, verbatim: "POST /v1/users/{id}". */
  360. url: string;
  361. /** The verb, when the name leads with one. Null for a file-routed page. */
  362. method: string | null;
  363. /** The URL without the verb — the same string as `url` when there is none. */
  364. path: string;
  365. handler: string;
  366. handlerKind: string;
  367. /** Where the request is SERVED. */
  368. file: string;
  369. line: number;
  370. handlerId: string | null;
  371. /** Where the URL is REGISTERED — the router file, which is how routes group. */
  372. routeFile: string;
  373. routeLine: number;
  374. routeId: string;
  375. }
  376. export interface WireEntryFile extends WireNodeRef {
  377. /** Calls and instantiations made at the top level of the file. */
  378. calls: number;
  379. /** Distinct other files this one's symbols reach. */
  380. reaches: number;
  381. /** Other files reaching into this one. Zero means nothing imports it. */
  382. dependents: number;
  383. }
  384. export interface WireEntryHub extends WireNodeRef {
  385. dependents: number;
  386. }
  387. export interface WireEntryTest extends WireNodeRef {
  388. /** Distinct other files this test reaches — what it exercises. */
  389. reaches: number;
  390. /** References behind that reach. */
  391. refs: number;
  392. }
  393. export interface WireEntryPoints {
  394. /** Frameworks the resolver detected — named in the Routes header. */
  395. frameworks: string[];
  396. routes: {
  397. routed: boolean;
  398. /** Every `route` node in the graph, resolved handler or not. */
  399. routeCount: number;
  400. items: WireList<WireEntryRoute>;
  401. };
  402. /** `total` is a floor on `files` and `hubs`; on `tests` it is exact. */
  403. files: WireList<WireEntryFile>;
  404. tests: WireList<WireEntryTest>;
  405. hubs: WireList<WireEntryHub>;
  406. index: { lastIndexedAt: number | null; files: number };
  407. timing: { elapsedMs: number; cached: boolean };
  408. }
  409. export interface WireStats {
  410. project: { root: string; name: string };
  411. index: {
  412. state: string | null;
  413. lastIndexedAt: number | null;
  414. stale: boolean;
  415. version: string | null;
  416. extractionVersion: number | null;
  417. backend: string;
  418. journalMode: string;
  419. pendingReferences: number;
  420. generatedFiles: number;
  421. watching: boolean;
  422. watcherDegraded: boolean;
  423. };
  424. graph: {
  425. nodes: number;
  426. edges: number;
  427. files: number;
  428. nodesByKind: Record<string, number>;
  429. edgesByKind: Record<string, number>;
  430. filesByLanguage: Record<string, number>;
  431. dbSizeBytes: number;
  432. walSizeBytes: number;
  433. };
  434. frameworks: string[];
  435. thresholds: { hub: number; uncertainBelow: number };
  436. blastScale: WireBlastScale;
  437. }
  438. /* ------------------------------------------------------------- flow strip -- */
  439. export interface WireFlowEdge extends WireEdge {
  440. /** The link's label: "calls", "via callback · registered at file:line". */
  441. label: string;
  442. /** This hop reads callee → caller — the reader stepped UP into it. */
  443. upward: boolean;
  444. /** Confidence below 0.6: the link is dashed `2 3`. */
  445. uncertain: boolean;
  446. /** A synthesized dynamic-dispatch bridge: dashed `5 3`. */
  447. synthesized: boolean;
  448. }
  449. export interface WireFlowSource {
  450. file: string;
  451. language: string;
  452. from: number;
  453. to: number;
  454. /** Absent when `drift` — a mis-sliced window is worse than an empty card. */
  455. lines?: string[];
  456. highlight?: WireHighlight;
  457. drift: boolean;
  458. reason?: string;
  459. }
  460. /** The call site a card is opened at — the identifier drawn as an accent link. */
  461. export interface WireFlowCallRef {
  462. line: number;
  463. col: number | null;
  464. name: string;
  465. targetId: string;
  466. /** The link points back at the previous card, not on to the next one. */
  467. backwards: boolean;
  468. }
  469. export interface WireFlowHop {
  470. node: WireNodeRef;
  471. /** The edge from the PREVIOUS hop into this one; null on the first. */
  472. edge: WireFlowEdge | null;
  473. callRef: WireFlowCallRef | null;
  474. source: WireFlowSource | null;
  475. }
  476. /** One plausible runtime target of a keyed dispatch — a clickable cap row. */
  477. export interface WireBoundaryCandidate {
  478. node: WireNodeRef;
  479. display: string;
  480. named: boolean;
  481. }
  482. /** A dynamic-dispatch site: the form, the key when it is visible, the targets. */
  483. export interface WireBoundarySite {
  484. form: string;
  485. label: string;
  486. snippet: string;
  487. line: number;
  488. key: string | null;
  489. keyIsType: boolean;
  490. moreSites: number;
  491. candidates: WireBoundaryCandidate[];
  492. candidateNote: string | null;
  493. }
  494. export interface WireFlowContinuation {
  495. node: WireNodeRef;
  496. line: number | null;
  497. confidence: number | null;
  498. }
  499. /** Where the graph stops — the strip's end cap (design spec §3.5). */
  500. export interface WireFlowBoundary {
  501. node: WireNodeRef;
  502. sites: WireBoundarySite[];
  503. uncertain: WireList<WireFlowContinuation>;
  504. further: WireList<WireFlowContinuation>;
  505. missed: WireNodeRef[];
  506. }
  507. export interface WireFlow {
  508. id: string;
  509. /** "execute → rowToFileRecord", for the header's flow picker. */
  510. label: string;
  511. hops: WireFlowHop[];
  512. /** Null on a flow that reaches everything it was asked about. */
  513. boundary: WireFlowBoundary | null;
  514. /** One card at the dispatch site, not a path: the answer ran out here. */
  515. partial: boolean;
  516. }
  517. export interface WireFlowAmbiguity {
  518. token: string;
  519. chosen: WireNodeRef | null;
  520. others: WireNodeRef[];
  521. }
  522. export interface WireFlowPayload {
  523. query: {
  524. kind: 'directed' | 'symbols' | 'trail';
  525. from: string | null;
  526. to: string | null;
  527. symbols: string[];
  528. };
  529. flows: WireFlow[];
  530. ambiguous: WireFlowAmbiguity[];
  531. /** Tokens that named nothing in this index. */
  532. unresolved: string[];
  533. /** Why there is no flow, when there is none. */
  534. reason: string | null;
  535. index: { lastIndexedAt: number | null; edges: number; files: number };
  536. timing: { elapsedMs: number };
  537. }
  538. /* -------------------------------------------------------------- the map -- */
  539. export interface WireMapModule {
  540. /** Directory path, the `(root files)` bucket, or a façade file's own path. */
  541. id: string;
  542. label: string;
  543. files: number;
  544. symbols: number;
  545. languages: Array<{ language: string; files: number }>;
  546. /** More than half its files are tests. */
  547. test: boolean;
  548. /** How many of its files are tool-generated. All of them → drawn in ink-4. */
  549. generated: number;
  550. /** Which of `fileList.items` are generated, so a row in the panel can dim too. */
  551. generatedFiles: string[];
  552. /** A single file kept out of the root bucket because it is the façade. */
  553. facade: boolean;
  554. /** Its files, capped — the side panel's list when the module is selected. */
  555. fileList: { total: number; shown: number; truncated: boolean; items: string[] };
  556. }
  557. export interface WireMapLink {
  558. source: string;
  559. target: string;
  560. /** Every confident cross-module edge behind this link. */
  561. count: number;
  562. /**
  563. * The subset resolved through an import, a qualified name, an inheritance
  564. * clause or a typed receiver — what the layering trusts.
  565. */
  566. declared: number;
  567. byKind: Array<{ kind: EdgeKind; count: number }>;
  568. topPairs: Array<{ from: string; to: string; count: number; declared: number }>;
  569. }
  570. export interface WireMapCycle {
  571. size: number;
  572. files: string[];
  573. modules: string[];
  574. }
  575. export interface WireMapPayload {
  576. root: string;
  577. depth: number;
  578. roots: Array<{ root: string; label: string; files: number }>;
  579. modules: WireMapModule[];
  580. links: WireMapLink[];
  581. cycles: { total: number; shown: number; truncated: boolean; items: WireMapCycle[] };
  582. excluded: { uncertainEdges: number; confidenceBelow: number };
  583. index: { lastIndexedAt: number | null; edges: number; files: number };
  584. timing: { elapsedMs: number; cached: boolean };
  585. }
  586. /* ---------------------------------------------------------------- screens -- */
  587. export interface WireScreen {
  588. id: string;
  589. path: string;
  590. file: string;
  591. line: number;
  592. component: WireNodeRef | null;
  593. incoming: number;
  594. outgoing: number;
  595. }
  596. export interface WireScreenOrigin {
  597. id: string;
  598. node: WireNodeRef;
  599. outgoing: number;
  600. /** Shared chrome: how many screens render it. */
  601. sharedBy?: number;
  602. }
  603. export interface WireScreenSite {
  604. file: string;
  605. line: number;
  606. href: string;
  607. method: string;
  608. /** The conditions THIS site runs under (the whole chain's plus its own); '' when unconditional. */
  609. when: string;
  610. }
  611. export interface WireScreenLink {
  612. id: string;
  613. from: string;
  614. to: string;
  615. fromOrigin: boolean;
  616. via: WireNodeRef[];
  617. when: string;
  618. sites: WireScreenSite[];
  619. synthesized: boolean;
  620. }
  621. export interface WireScreensPayload {
  622. routed: boolean;
  623. entry: string | null;
  624. screens: WireScreen[];
  625. origins: WireScreenOrigin[];
  626. links: WireScreenLink[];
  627. dropped: number;
  628. index: { lastIndexedAt: number | null; edges: number; files: number };
  629. timing: { elapsedMs: number };
  630. }
  631. /* ------------------------------------------------------------------ steps -- */
  632. export type WireStepKind = 'anchor' | 'screen' | 'trigger' | 'bridge' | 'event' | 'store' | 'effect';
  633. export type WireStepLinkKind = 'calls' | 'navigates' | 'handler' | 'bridge' | 'event' | 'store' | 'effect';
  634. export interface WireStepSite {
  635. file: string;
  636. line: number;
  637. /** `push /capture`, `calls`, `client.post` — what the site does, in a word or two. */
  638. text: string;
  639. /** What the site passes, abbreviated (`'userEmail', values.email`); '' for none; absent when unreadable. */
  640. args?: string;
  641. /** The conditions THIS site runs under (the whole chain's); '' when unconditional. */
  642. when: string;
  643. /** What fires THIS site, when it differs from the link's first. */
  644. trigger?: WireStepTrigger;
  645. /** For a response site: the status code it sends, when literal. */
  646. status?: number;
  647. /**
  648. * The decision the site's INNERMOST condition belongs to, when one was
  649. * read. Two sites that agree on `branch` and disagree on `arm` are the two
  650. * ways of ONE fork — which a joined condition string can never say, however
  651. * exactly one reads as the other's negation.
  652. */
  653. decision?: WireStepDecision;
  654. }
  655. /** One arm of one decision, as the site that runs under it records it. */
  656. export interface WireStepDecision {
  657. /** Where the branching construct starts (`line:column`) — the fork's identity. */
  658. branch: string;
  659. /** The decision as a reader says it, always positive: `await hasSeenWelcome(…)`. */
  660. on: string;
  661. /** THIS arm's own condition — an `if` and its `else` differ here and nowhere else. */
  662. arm: string;
  663. form: 'if' | 'switch' | 'ternary' | 'try';
  664. /** The arm taken when the condition does NOT hold — the `else` side. */
  665. not?: true;
  666. }
  667. /** What fires a step or a link: the event it is written under, and the function that writes it there. */
  668. export interface WireStepTrigger {
  669. /**
  670. * `prop` / `option` / `callback`: a binding at the call site (JSX attribute,
  671. * `on*` key, runs-later argument). `request`: the route a handler serves —
  672. * `name` the verb, `of` the path. `decorator`: a decorator on the handler —
  673. * `name` its name, `of` its literal argument (`@Process('email')`). `load`:
  674. * a page's own load-time work — `of` the page path.
  675. */
  676. kind: 'prop' | 'option' | 'callback' | 'request' | 'decorator' | 'load';
  677. /** `onPress`, `onSubmit`, `useEffect`, `addListener`, `POST`, `Process`. */
  678. name: string;
  679. /** `Button` for a prop, `useFormik` for an option, the first string argument for a callback; null when unknown. */
  680. of: string | null;
  681. /** The function the binding is written in. */
  682. in: string;
  683. /** What runs before it fires: the middleware / guard chain, in order (`authenticate`, `validate(…)`). */
  684. after?: string[];
  685. }
  686. export interface WireStep {
  687. /** The node's id, or `effect:<function id>:<api>` for a call leaving the index. */
  688. id: string;
  689. kind: WireStepKind;
  690. /** The step the picture starts from. A screen anchor keeps `kind: 'screen'`. */
  691. anchor: boolean;
  692. /** Null only for an effect, which is a call site rather than a symbol. */
  693. node: WireNodeRef | null;
  694. label: string;
  695. sub: string;
  696. /** Steps from the anchor: the row. */
  697. depth: number;
  698. /**
  699. * Why the walk did not go on from this step: a cap (`depth`, `fan-out`,
  700. * `folded`, `steps`), or `screen` — another screen, or an endpoint reached
  701. * across a tier, drawn as a boundary.
  702. */
  703. cut: 'depth' | 'fan-out' | 'folded' | 'steps' | 'screen' | 'component' | null;
  704. /** The event name a native event step arrived on — the first, when several land here. */
  705. event?: string;
  706. /** Every event that lands on this step. */
  707. events?: string[];
  708. /** For a handler: what fires it. */
  709. trigger?: WireStepTrigger;
  710. /** The step's place in its row, in the code's order (a hop written inside another site's arguments before that site). */
  711. order?: number;
  712. /**
  713. * A screen anchor's picture only: the region of the screen this step belongs
  714. * to — the top-level component (or hook) the walk first reached it through,
  715. * the screen's own component for the screen body. The viewer lays a screen's
  716. * picture out by these; absent, the rows are distance.
  717. */
  718. region?: { id: string; label: string };
  719. /**
  720. * For a screen or an endpoint — also a `bridge` step that is an endpoint
  721. * reached across a tier: its path and the symbol that serves it.
  722. * `endpoint` when the route leads with an HTTP verb; `inline` when the
  723. * handler is anonymous at the registration site (component is null).
  724. */
  725. screen?: { path: string; component: WireNodeRef | null; endpoint: boolean; inline: boolean };
  726. /**
  727. * The calls one function makes into one category, and the function. A
  728. * database call names its model / table and read vs write when the call
  729. * says; a response box lists the status codes its sites send.
  730. */
  731. effect?: {
  732. api: string;
  733. apis: string[];
  734. category: string;
  735. by: WireNodeRef;
  736. line: number;
  737. model?: string;
  738. access?: 'read' | 'write';
  739. statuses?: number[];
  740. };
  741. }
  742. export interface WireStepLink {
  743. id: string;
  744. from: string;
  745. to: string;
  746. kind: WireStepLinkKind;
  747. /** The symbols folded between the two steps, in order. */
  748. via: WireNodeRef[];
  749. /** Conditions along the whole chain, joined; '' when unconditional. */
  750. when: string;
  751. /** How the last hop was established when it was not a plain call. */
  752. label: string;
  753. /** The call the first hop is written inside the arguments of — `res.json` for a token signed while building the reply. */
  754. within?: string;
  755. synthesized: boolean;
  756. uncertain: boolean;
  757. sites: WireStepSite[];
  758. /** What fires the first site, when something binds it to an event. */
  759. trigger?: WireStepTrigger;
  760. }
  761. /* ------------------------------------------- the same walk, in the code's order -- */
  762. /** How an arm of a fork leaves, when it does — the rail stops there. */
  763. export type WireArmEnd = 'reply' | 'return' | 'throw' | 'exit';
  764. export interface WireArm {
  765. /** This arm's own condition, in the words the rest of the view uses. */
  766. when: string;
  767. /** The arm taken when the fork's condition does NOT hold — the `else` side. */
  768. not?: true;
  769. /** How it leaves: it answers the request, returns, or throws. Null = it runs on. */
  770. ends: WireArmEnd | null;
  771. body: WireBlock;
  772. }
  773. export type WireBlock = WireItem[];
  774. export type WireItem =
  775. /**
  776. * A step of the picture, where the code writes it. `body` is what it does,
  777. * when the walk entered it; `again` says it happens here too and was read
  778. * above — a function is read ONCE in a rail, however many times it is called.
  779. */
  780. | { kind: 'step'; step: string; link?: string; within?: string; body?: WireBlock; again?: true }
  781. /** A decision: `if` / `else`, a `switch`, a ternary, a `try`, or an early exit. */
  782. | { kind: 'fork'; on: string; form: 'if' | 'switch' | 'ternary' | 'try'; arms: WireArm[] }
  783. /**
  784. * A run of items that is not plain sequence: a helper drawn where it is
  785. * called (`inline`), a body that runs for each item (`loop`), work that runs
  786. * after this function returns (`later`), or calls started together
  787. * (`together`).
  788. */
  789. | {
  790. kind: 'block';
  791. block: 'inline' | 'loop' | 'later' | 'together';
  792. by?: string;
  793. /** For a loop: whether it runs once per item or while a condition holds. */
  794. loop?: 'each' | 'while';
  795. via?: WireNodeRef;
  796. within?: string;
  797. body: WireBlock;
  798. again?: true;
  799. }
  800. /** Where the reading stopped: a helper that calls itself, or a cap the walk hit. */
  801. | { kind: 'cut'; why: 'folded' | 'depth' };
  802. export interface WireProgram {
  803. root: WireBlock;
  804. /** Items the reading could not place — a recursion or a cap it hit. */
  805. truncated: number;
  806. }
  807. export interface WireStepsPayload {
  808. anchor: WireNodeRef;
  809. /** Other symbols that share the anchor's name, when it was given by name. */
  810. ambiguous: WireNodeRef[];
  811. /** An `app` of screens, an `api` of endpoints, or a `web` app with both — the viewer's words follow it. */
  812. project: 'app' | 'api' | 'web';
  813. steps: WireStep[];
  814. links: WireStepLink[];
  815. /**
  816. * The same walk read in the code's ORDER — the anchor's body as a rail that
  817. * forks where the code forks. Null when the anchor has no body to read.
  818. */
  819. program: WireProgram | null;
  820. /** Which reading to open with; the URL's `view` overrides it. */
  821. defaultView: 'order' | 'tree';
  822. depth: number;
  823. limit: number;
  824. /** Screens reached from the anchor were entered rather than drawn as boundaries. */
  825. through: boolean;
  826. truncated: { steps: number; hubs: number; chrome: number };
  827. index: { lastIndexedAt: number | null; edges: number; files: number };
  828. timing: { elapsedMs: number };
  829. }
  830. /* -------------------------------------------------------------- dead code -- */
  831. /** One symbol nothing in the index reaches. */
  832. export interface WireDeadCodeRow extends WireNodeRef {
  833. /** Source lines it spans — the rank, and what deleting it would remove. */
  834. lines: number;
  835. /** Unreferenced members inside it: a dead class takes its methods with it. */
  836. members: WireList<WireNodeRef>;
  837. }
  838. /** The rows of one file, in source order. */
  839. export interface WireDeadCodeGroup {
  840. file: string;
  841. /** Tool-generated — drawn dimmed wherever it appears. */
  842. generated: boolean;
  843. test: boolean;
  844. lines: number;
  845. rows: WireDeadCodeRow[];
  846. }
  847. /** One reason candidates were dropped, already worded for the screen. */
  848. export interface WireDeadCodeExclusion {
  849. reason: string;
  850. count: number;
  851. label: string;
  852. }
  853. export interface WireDeadCode {
  854. rows: WireList<WireDeadCodeRow>;
  855. /** The SHOWN rows, grouped by file — group order follows the best row. */
  856. groups: WireDeadCodeGroup[];
  857. /** Symbols with no incoming reference at all, before any exclusion ran. */
  858. candidates: number;
  859. excluded: WireDeadCodeExclusion[];
  860. excludedTotal: number;
  861. kinds: string[];
  862. includeExported: boolean;
  863. includeTests: boolean;
  864. includeGenerated: boolean;
  865. bounded: boolean;
  866. /** Every row was checked against the text of the files that can reach it. */
  867. corroborated: boolean;
  868. timing: { elapsedMs: number };
  869. }
  870. /* ---------------------------------------------------------- saved trails -- */
  871. /**
  872. * How a saved hop fared against the index as it is NOW.
  873. *
  874. * A trail is stored by qualified name rather than by node id (a node id
  875. * contains its start line, so any edit above a symbol renames it), and every
  876. * hop is re-resolved on the way out. This is what that re-resolution found.
  877. */
  878. export type WireTrailHopStatus = 'ok' | 'moved' | 'ambiguous' | 'missing';
  879. export interface WireTrailHop {
  880. dir: 'start' | 'down' | 'up';
  881. /** The name as it was when the trail was saved. */
  882. name: string;
  883. qualifiedName: string;
  884. kind: string;
  885. savedFile: string;
  886. savedLine: number;
  887. status: WireTrailHopStatus;
  888. /** The symbol's id NOW. Null when nothing answers to it any more. */
  889. id: string | null;
  890. file: string | null;
  891. line: number | null;
  892. /** Finished screen wording for a status that is not `ok`; null when it is. */
  893. note: string | null;
  894. }
  895. export interface WireTrail {
  896. id: string;
  897. name: string;
  898. note: string;
  899. author: string;
  900. createdAt: string;
  901. updatedAt: string;
  902. hops: WireTrailHop[];
  903. /** Hops that still resolve to a symbol in this index. */
  904. resolved: number;
  905. /** Every hop resolved, and none of them moved. */
  906. intact: boolean;
  907. /**
  908. * The longest run of CONSECUTIVE resolved hops, as the `t` param. Null when
  909. * nothing in the trail resolves. Never stitched across a hole — the trail is
  910. * a path, and a fabricated adjacency is worse than a short one.
  911. */
  912. encoded: string | null;
  913. /** 1-based index of the first hop `encoded` carries. */
  914. openFrom: number;
  915. /** How many hops `encoded` carries. */
  916. openCount: number;
  917. /** The symbol the trail opens at — the last hop of that run. */
  918. openId: string | null;
  919. }
  920. export interface WireTrails {
  921. trails: WireTrail[];
  922. /** Writes are off. Save and Delete are hidden, and the screen says why. */
  923. readOnly: boolean;
  924. readOnlyReason: string | null;
  925. /** Project-relative directory the files live in. */
  926. directory: string;
  927. /** Files in that directory that were not readable trails. */
  928. skipped: number;
  929. bounded: boolean;
  930. /** The id just written, on the answer to a save. */
  931. saved?: string;
  932. /** That save replaced a trail of the same name. */
  933. replaced?: boolean;
  934. /** The id just removed, on the answer to a delete. */
  935. deleted?: string;
  936. }