feat: add symbol-aware depgraph authority overlay - #2157
Conversation
Size Report
npm unpacked components
Startup median (7 runs, lower is better):
Top changed chunks: no changes in the largest emitted chunks. Top changed packed filesNo changed packed files. |
|
Reviewed exact head P1 — the overlay duplicates live-state authority declarations. |
Deep code-quality reviewVerified locally on That said, I don't think this should merge as-is. The overlay hand-rolls a classifier for information the declarations already carry, and it puts two ownership facts in the consumer instead of in the module #2126 created to hold them. 1. The label already exists in the data. The overlay re-derives it as six branches.
The overlay ignores The code-judo move is to let the declarations be the classifier: type AuthorityRule = {
label: DeclaredAuthorityLabel;
side: 'source' | 'target';
roots: readonly string[];
/** When present, the import must name one of these. */
symbols?: readonly string[];
};
const AUTHORITY_RULES: readonly AuthorityRule[] = [
...ARCHITECTURE_OWNERSHIP.vocabulary.map((d) => ({ label: d.kind, side: 'target', roots: d.roots })),
...ARCHITECTURE_OWNERSHIP.capabilities.map((d) => ({ label: d.kind, side: 'target', roots: [d.root], symbols: d.exports })),
...ARCHITECTURE_OWNERSHIP.liveState.map((d) => ({ label: d.kind, side: 'target', roots: [d.root], symbols: d.exports })),
...ARCHITECTURE_OWNERSHIP.executablePolicies.map((d) => ({ label: d.kind, side: 'source', roots: d.roots })),
];
function declaredAuthorities(edge: ResolvedImportEdge): DeclaredAuthorityLabel[] {
return AUTHORITY_RULES.filter(
(rule) =>
rule.roots.some((root) =>
matchesDeclaredRoot(rule.side === 'source' ? edge.file : edge.target, root),
) && (!rule.symbols || edge.symbols.some((symbol) => rule.symbols!.includes(symbol))),
).map((rule) => rule.label);
}That deletes Two things fall out for free:
Keep 2.
|
|
Addressed in
Validation is updated in the PR body: |
|
Re-reviewed exact head |
|
Addressed the deep review in final head
Validation: |
|
Re-reviewed exact head |
|
Summary
Closes #2128
Adds a tooling-only, report-only, symbol-aware authority overlay to the static dependency graph.
It reuses the existing layering import parser and the central architecture-ownership declarations;
it preserves every existing JSON field and four-position edge tuple, and adds parallel
edgeAuthoritiesplus stableauthorityCountsfields.The overlay reports
vocabulary,capability,live-state-shape,live-state-authority,executable-policy, andordinary. Import kind remains independent. Collapsed edges accumulateall declared labels from their raw imports, so multi-label edges are retained. The README documents
that this is declared-authority evidence, not proof of behavioral ownership, safe removability, or
a score/threshold.
The authority classifier is a single declaration-derived rule table. Exact
SessionStateandSessionStoreroots and declared exports live inARCHITECTURE_OWNERSHIP, with drift coverage;the old depgraph constants are gone. The shared parser extracts named source symbols once and
handles comments inside bindings. The strict
readNamedExportsreader is used for capability andlive-state declaration checks;
readDirectNamedExportsremains for the R11 source scan, where itsintentional
export *-tolerant semantics are still required. No second import parser was added.Validation
f152827447; merged prerequisite tooling: centralize machine-readable architecture ownership declarations #2126 / PR refactor(layering): centralize architecture ownership #2150 commit4244691e1ed0f71c148c412b8e645963f30a02b8is an ancestor of final head3e6fdb51ec.origin/main:caa3dc23f9f3f6a829e91e8c5f00a1e4a3084f53. A three-waygit merge-treeis clean; current main's replay/rank edits touch some layering files but introduce no genuine
conflict or authority-overlay overlap requiring a rebase.
pnpm install --frozen-lockfile && pnpm build: passed on the fresh worktree.pnpm depgraph:test: 24/24 passed, including all authority classifications, type-onlySessionState, SessionStore authority/import kind, lookalike files, multi-label collapse, and
legacy payload shape.
pnpm check:layering: 168/168 tests passed; layering guard OK.MissingSessionStateExportto the shared declarationmade
pnpm check:layeringfail at the live-state drift test (167 pass, 1 fail, exit 1).Restoring the declaration returned the focused depgraph suite to 24/24.
pnpm check:affected --run: exit 0; all runnable checks passed. The full 56-check set wasselected; GitHub-authoritative native/device/coverage lanes were skipped locally.
classification, collapse alignment, ordinary projection, and shared comment-safe parsing are
addressed; no remaining valid in-scope findings.
Exact report and jq evidence at final head:
Observed output: generated commit
3e6fdb51ec, 1,530 files, 7,923 edges; authority countsvocabulary=155,capability=54,live-state-shape=114,live-state-authority=82,executable-policy=80,ordinary=7441; the non-ordinary query returned 482 rows and themulti-label query returned 3 collapsed edges.
Size
scripts/orscripts/depgraph/README.md.src/orpackages/files changed.parser +46; focused regression tests +247; documentation +36. These sum to +444; deletions
remove the obsolete duplicate authority extraction and parser/object-literal duplication.
Residual risks
side-effect, and dynamic imports do not provide named-symbol evidence and are not inferred into
a capability/state label.
quality, behavioral equivalence, or removability.