monkeypatchlist 0.0.0-stage → 0.1.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 (221) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +61 -0
  3. package/README.md +183 -2
  4. package/catalog/catalog.json +552211 -0
  5. package/catalog/catalog.schema.json +787 -0
  6. package/catalog/changelog.json +3 -0
  7. package/dist/bin/monkeypatchlist.d.ts +2 -0
  8. package/dist/bin/monkeypatchlist.js +3 -0
  9. package/dist/catalog.d.ts +561 -0
  10. package/dist/catalog.js +58 -0
  11. package/dist/cli.d.ts +84 -0
  12. package/dist/cli.js +470 -0
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.js +1 -0
  15. package/dist/lockfile-input.d.ts +9 -0
  16. package/dist/lockfile-input.js +91 -0
  17. package/dist/packages/analysis/binding.d.ts +2 -0
  18. package/dist/packages/analysis/binding.js +5 -0
  19. package/dist/packages/analysis/index.d.ts +10 -0
  20. package/dist/packages/analysis/index.js +13 -0
  21. package/dist/packages/analysis/job.d.ts +33 -0
  22. package/dist/packages/analysis/job.js +85 -0
  23. package/dist/packages/analysis/lib/absence-tags.d.ts +34 -0
  24. package/dist/packages/analysis/lib/absence-tags.js +340 -0
  25. package/dist/packages/analysis/lib/ast.d.ts +28 -0
  26. package/dist/packages/analysis/lib/ast.js +64 -0
  27. package/dist/packages/analysis/lib/binding.d.ts +36 -0
  28. package/dist/packages/analysis/lib/binding.js +66 -0
  29. package/dist/packages/analysis/lib/budget.d.ts +80 -0
  30. package/dist/packages/analysis/lib/budget.js +31 -0
  31. package/dist/packages/analysis/lib/catch-arms.d.ts +19 -0
  32. package/dist/packages/analysis/lib/catch-arms.js +351 -0
  33. package/dist/packages/analysis/lib/chunk-loads.d.ts +160 -0
  34. package/dist/packages/analysis/lib/chunk-loads.js +882 -0
  35. package/dist/packages/analysis/lib/chunk-registry.d.ts +45 -0
  36. package/dist/packages/analysis/lib/chunk-registry.js +334 -0
  37. package/dist/packages/analysis/lib/code-routes.d.ts +52 -0
  38. package/dist/packages/analysis/lib/code-routes.js +921 -0
  39. package/dist/packages/analysis/lib/collisions.d.ts +22 -0
  40. package/dist/packages/analysis/lib/collisions.js +103 -0
  41. package/dist/packages/analysis/lib/definitions.d.ts +76 -0
  42. package/dist/packages/analysis/lib/definitions.js +782 -0
  43. package/dist/packages/analysis/lib/early-exits.d.ts +39 -0
  44. package/dist/packages/analysis/lib/early-exits.js +161 -0
  45. package/dist/packages/analysis/lib/effect.d.ts +138 -0
  46. package/dist/packages/analysis/lib/effect.js +800 -0
  47. package/dist/packages/analysis/lib/global-object.d.ts +581 -0
  48. package/dist/packages/analysis/lib/global-object.js +8240 -0
  49. package/dist/packages/analysis/lib/keys.d.ts +33 -0
  50. package/dist/packages/analysis/lib/keys.js +82 -0
  51. package/dist/packages/analysis/lib/line-starts.d.ts +41 -0
  52. package/dist/packages/analysis/lib/line-starts.js +79 -0
  53. package/dist/packages/analysis/lib/link-group.d.ts +51 -0
  54. package/dist/packages/analysis/lib/link-group.js +487 -0
  55. package/dist/packages/analysis/lib/module-links.d.ts +117 -0
  56. package/dist/packages/analysis/lib/module-links.js +1060 -0
  57. package/dist/packages/analysis/lib/nested-code.d.ts +38 -0
  58. package/dist/packages/analysis/lib/nested-code.js +200 -0
  59. package/dist/packages/analysis/lib/numeric.d.ts +16 -0
  60. package/dist/packages/analysis/lib/numeric.js +216 -0
  61. package/dist/packages/analysis/lib/once-flags.d.ts +12 -0
  62. package/dist/packages/analysis/lib/once-flags.js +190 -0
  63. package/dist/packages/analysis/lib/parameter-arguments.d.ts +12 -0
  64. package/dist/packages/analysis/lib/parameter-arguments.js +34 -0
  65. package/dist/packages/analysis/lib/parse.d.ts +10 -0
  66. package/dist/packages/analysis/lib/parse.js +39 -0
  67. package/dist/packages/analysis/lib/partial.d.ts +60 -0
  68. package/dist/packages/analysis/lib/partial.js +518 -0
  69. package/dist/packages/analysis/lib/print.d.ts +3 -0
  70. package/dist/packages/analysis/lib/print.js +150 -0
  71. package/dist/packages/analysis/lib/reachability.d.ts +137 -0
  72. package/dist/packages/analysis/lib/reachability.js +1295 -0
  73. package/dist/packages/analysis/lib/resolver.d.ts +13 -0
  74. package/dist/packages/analysis/lib/resolver.js +2886 -0
  75. package/dist/packages/analysis/lib/restores.d.ts +42 -0
  76. package/dist/packages/analysis/lib/restores.js +482 -0
  77. package/dist/packages/analysis/lib/rewritten-deletes.d.ts +6 -0
  78. package/dist/packages/analysis/lib/rewritten-deletes.js +142 -0
  79. package/dist/packages/analysis/lib/scope.d.ts +110 -0
  80. package/dist/packages/analysis/lib/scope.js +443 -0
  81. package/dist/packages/analysis/lib/script-loads.d.ts +56 -0
  82. package/dist/packages/analysis/lib/script-loads.js +359 -0
  83. package/dist/packages/analysis/lib/summaries.d.ts +177 -0
  84. package/dist/packages/analysis/lib/summaries.js +498 -0
  85. package/dist/packages/analysis/lib/types.d.ts +632 -0
  86. package/dist/packages/analysis/lib/types.js +128 -0
  87. package/dist/packages/analysis/lib/wrap.d.ts +34 -0
  88. package/dist/packages/analysis/lib/wrap.js +407 -0
  89. package/dist/packages/analysis/lib/writes.d.ts +358 -0
  90. package/dist/packages/analysis/lib/writes.js +1612 -0
  91. package/dist/packages/analysis/visit-order.d.ts +3 -0
  92. package/dist/packages/analysis/visit-order.js +23 -0
  93. package/dist/packages/attribution/index.d.ts +233 -0
  94. package/dist/packages/attribution/index.js +444 -0
  95. package/dist/packages/attribution/lib/containing-package.d.ts +76 -0
  96. package/dist/packages/attribution/lib/containing-package.js +304 -0
  97. package/dist/packages/attribution/lib/first-party.d.ts +37 -0
  98. package/dist/packages/attribution/lib/first-party.js +153 -0
  99. package/dist/packages/attribution/lib/lockfile-graph.d.ts +99 -0
  100. package/dist/packages/attribution/lib/lockfile-graph.js +158 -0
  101. package/dist/packages/attribution/lib/lockfile.d.ts +33 -0
  102. package/dist/packages/attribution/lib/lockfile.js +330 -0
  103. package/dist/packages/attribution/lib/path-rules.d.ts +29 -0
  104. package/dist/packages/attribution/lib/path-rules.js +84 -0
  105. package/dist/packages/attribution/lib/pnpm.d.ts +4 -0
  106. package/dist/packages/attribution/lib/pnpm.js +133 -0
  107. package/dist/packages/attribution/lib/remote-url.d.ts +7 -0
  108. package/dist/packages/attribution/lib/remote-url.js +24 -0
  109. package/dist/packages/attribution/lib/source-map.d.ts +51 -0
  110. package/dist/packages/attribution/lib/source-map.js +125 -0
  111. package/dist/packages/attribution/lib/yaml.d.ts +9 -0
  112. package/dist/packages/attribution/lib/yaml.js +277 -0
  113. package/dist/packages/attribution/lib/yarn.d.ts +7 -0
  114. package/dist/packages/attribution/lib/yarn.js +227 -0
  115. package/dist/packages/baseline/index.d.ts +45 -0
  116. package/dist/packages/baseline/index.js +41 -0
  117. package/dist/packages/baseline/lib/error.d.ts +15 -0
  118. package/dist/packages/baseline/lib/error.js +25 -0
  119. package/dist/packages/baseline/lib/format.d.ts +49 -0
  120. package/dist/packages/baseline/lib/format.js +22 -0
  121. package/dist/packages/baseline/lib/migrations.d.ts +19 -0
  122. package/dist/packages/baseline/lib/migrations.js +7 -0
  123. package/dist/packages/baseline/lib/previous.d.ts +23 -0
  124. package/dist/packages/baseline/lib/previous.js +64 -0
  125. package/dist/packages/baseline/lib/read.d.ts +39 -0
  126. package/dist/packages/baseline/lib/read.js +219 -0
  127. package/dist/packages/baseline/lib/report.d.ts +25 -0
  128. package/dist/packages/baseline/lib/report.js +104 -0
  129. package/dist/packages/baseline/lib/skew.d.ts +51 -0
  130. package/dist/packages/baseline/lib/skew.js +75 -0
  131. package/dist/packages/compare/index.d.ts +120 -0
  132. package/dist/packages/compare/index.js +274 -0
  133. package/dist/packages/compare/lib/catalog-notes.d.ts +73 -0
  134. package/dist/packages/compare/lib/catalog-notes.js +224 -0
  135. package/dist/packages/completeness/index.d.ts +246 -0
  136. package/dist/packages/completeness/index.js +249 -0
  137. package/dist/packages/confidence/index.d.ts +54 -0
  138. package/dist/packages/confidence/index.js +71 -0
  139. package/dist/packages/config/index.d.ts +107 -0
  140. package/dist/packages/config/index.js +95 -0
  141. package/dist/packages/config/lib/command-line.d.ts +23 -0
  142. package/dist/packages/config/lib/command-line.js +239 -0
  143. package/dist/packages/config/lib/config-file.d.ts +11 -0
  144. package/dist/packages/config/lib/config-file.js +119 -0
  145. package/dist/packages/config/lib/scan-config-id.d.ts +28 -0
  146. package/dist/packages/config/lib/scan-config-id.js +54 -0
  147. package/dist/packages/config/lib/schema.d.ts +2 -0
  148. package/dist/packages/config/lib/schema.js +31 -0
  149. package/dist/packages/config/lib/types.d.ts +64 -0
  150. package/dist/packages/config/lib/types.js +6 -0
  151. package/dist/packages/config/lib/urls.d.ts +6 -0
  152. package/dist/packages/config/lib/urls.js +9 -0
  153. package/dist/packages/discovery/index.d.ts +277 -0
  154. package/dist/packages/discovery/index.js +1950 -0
  155. package/dist/packages/discovery/lib/import-map.d.ts +68 -0
  156. package/dist/packages/discovery/lib/import-map.js +180 -0
  157. package/dist/packages/discovery/lib/requests.d.ts +58 -0
  158. package/dist/packages/discovery/lib/requests.js +591 -0
  159. package/dist/packages/discovery/lib/scopes.d.ts +6 -0
  160. package/dist/packages/discovery/lib/scopes.js +286 -0
  161. package/dist/packages/discovery/lib/source-maps.d.ts +56 -0
  162. package/dist/packages/discovery/lib/source-maps.js +209 -0
  163. package/dist/packages/discovery/lib/swept-code.d.ts +27 -0
  164. package/dist/packages/discovery/lib/swept-code.js +107 -0
  165. package/dist/packages/discovery/lib/syntax.d.ts +17 -0
  166. package/dist/packages/discovery/lib/syntax.js +39 -0
  167. package/dist/packages/findings/index.d.ts +106 -0
  168. package/dist/packages/findings/index.js +254 -0
  169. package/dist/packages/findings/lib/scope.d.ts +38 -0
  170. package/dist/packages/findings/lib/scope.js +110 -0
  171. package/dist/packages/parallel/index.d.ts +2 -0
  172. package/dist/packages/parallel/index.js +5 -0
  173. package/dist/packages/parallel/lib/protocol.d.ts +15 -0
  174. package/dist/packages/parallel/lib/protocol.js +2 -0
  175. package/dist/packages/parallel/lib/runner.d.ts +36 -0
  176. package/dist/packages/parallel/lib/runner.js +96 -0
  177. package/dist/packages/parallel/lib/schedule.d.ts +16 -0
  178. package/dist/packages/parallel/lib/schedule.js +52 -0
  179. package/dist/packages/parallel/lib/worker.d.ts +1 -0
  180. package/dist/packages/parallel/lib/worker.js +18 -0
  181. package/dist/packages/policy/index.d.ts +36 -0
  182. package/dist/packages/policy/index.js +22 -0
  183. package/dist/packages/report/explain.d.ts +26 -0
  184. package/dist/packages/report/explain.js +99 -0
  185. package/dist/packages/report/index.d.ts +210 -0
  186. package/dist/packages/report/index.js +388 -0
  187. package/dist/packages/report/terminal.d.ts +11 -0
  188. package/dist/packages/report/terminal.js +331 -0
  189. package/dist/packages/source-store/fixture.d.ts +22 -0
  190. package/dist/packages/source-store/fixture.js +58 -0
  191. package/dist/packages/source-store/index.d.ts +278 -0
  192. package/dist/packages/source-store/index.js +322 -0
  193. package/dist/packages/source-store/lib/addresses.d.ts +6 -0
  194. package/dist/packages/source-store/lib/addresses.js +91 -0
  195. package/dist/packages/source-store/lib/connection.d.ts +15 -0
  196. package/dist/packages/source-store/lib/connection.js +135 -0
  197. package/dist/packages/source-store/lib/content-types.d.ts +16 -0
  198. package/dist/packages/source-store/lib/content-types.js +75 -0
  199. package/dist/packages/source-store/lib/data-urls.d.ts +10 -0
  200. package/dist/packages/source-store/lib/data-urls.js +85 -0
  201. package/dist/packages/source-store/lib/deadline.d.ts +18 -0
  202. package/dist/packages/source-store/lib/deadline.js +44 -0
  203. package/dist/packages/source-store/lib/exchange.d.ts +29 -0
  204. package/dist/packages/source-store/lib/exchange.js +112 -0
  205. package/dist/packages/source-store/lib/integrity.d.ts +19 -0
  206. package/dist/packages/source-store/lib/integrity.js +86 -0
  207. package/dist/packages/source-store/lib/outcomes.d.ts +12 -0
  208. package/dist/packages/source-store/lib/outcomes.js +22 -0
  209. package/dist/packages/source-store/lib/proxy.d.ts +11 -0
  210. package/dist/packages/source-store/lib/proxy.js +53 -0
  211. package/dist/packages/source-store/lib/session.d.ts +12 -0
  212. package/dist/packages/source-store/lib/session.js +139 -0
  213. package/dist/packages/source-store/lib/urls.d.ts +6 -0
  214. package/dist/packages/source-store/lib/urls.js +15 -0
  215. package/dist/packages/source-store/resolve.d.ts +59 -0
  216. package/dist/packages/source-store/resolve.js +45 -0
  217. package/dist/scan.d.ts +65 -0
  218. package/dist/scan.js +592 -0
  219. package/package.json +95 -4
  220. package/schema/config.schema.json +133 -0
  221. package/schema/report.schema.json +1905 -0
@@ -0,0 +1,3 @@
1
+ import type { Resolver } from './lib/types.ts';
2
+ /** The JS resolver, visiting its call lists in an order `seed` shuffles (Fisher–Yates over a mulberry32 stream). */
3
+ export declare function shuffledResolver(seed: number): Resolver;
@@ -0,0 +1,23 @@
1
+ // Visit order (§18 Context policy): results are independent of the order the resolver visits its work in. A shuffled
2
+ // resolver visits the calls of each function, and of each program, in a seeded pseudo-random order, so a permutation
3
+ // test can show that a scan's report stays byte-identical. It is for tests only; the CLI ships `jsResolver`.
4
+ import { createJsResolver } from "./lib/resolver.js";
5
+ /** The JS resolver, visiting its call lists in an order `seed` shuffles (Fisher–Yates over a mulberry32 stream). */
6
+ export function shuffledResolver(seed) {
7
+ let state = seed >>> 0;
8
+ const next = () => {
9
+ state = (state + 0x6d2b79f5) >>> 0;
10
+ let t = state;
11
+ t = Math.imul(t ^ (t >>> 15), t | 1);
12
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
13
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
14
+ };
15
+ return createJsResolver(undefined, (items) => {
16
+ const out = [...items];
17
+ for (let index = out.length - 1; index > 0; index--) {
18
+ const other = Math.floor(next() * (index + 1));
19
+ [out[index], out[other]] = [out[other], out[index]];
20
+ }
21
+ return out;
22
+ });
23
+ }
@@ -0,0 +1,233 @@
1
+ import type { RemoteUrlNormalization } from '../../catalog.ts';
2
+ import type { GeneratedLocation, IneffectiveWrite, RawOccurrence, TraceStep } from '../analysis/index.ts';
3
+ import { type Confidence } from '../confidence/index.ts';
4
+ import { introducerReasons, type IntroducerReason } from './lib/lockfile.ts';
5
+ import { type PathRules } from './lib/path-rules.ts';
6
+ import { type LineReading } from './lib/source-map.ts';
7
+ export type { PathRules } from './lib/path-rules.ts';
8
+ export { introducerReasons, type IntroducerReason };
9
+ export { lockfileManifests } from './lib/lockfile.ts';
10
+ /**
11
+ * The lockfile a scan was given (§10 Introducing dependencies): its path as given, its text (null when it can't be
12
+ * read), and the `lockfile.importer` setting, or null.
13
+ */
14
+ export interface LockfileInput {
15
+ path: string;
16
+ text: string | null;
17
+ importer: string | null;
18
+ /**
19
+ * The `package.json` texts beside the lockfile (§2 Inputs), by folder relative to its directory (`''` for its
20
+ * own), null for one that couldn't be read: its own, and the workspaces' it names. Absent for npm and Bun, which
21
+ * record what they give.
22
+ */
23
+ manifests?: Readonly<Record<string, string | null>>;
24
+ }
25
+ /**
26
+ * Why introducers are unknown, for the attribution block (§10 Unknown is not empty, §13): null with a usable lockfile.
27
+ * `evidence` says what made it so: the format version of a lockfile that isn't usable, the store path the
28
+ * lockfile disagrees with, or why no importer was picked.
29
+ */
30
+ export interface Introducers {
31
+ reason: IntroducerReason | null;
32
+ evidence: string | null;
33
+ /**
34
+ * How certain the introducers are, with a usable lockfile: `high` from `package-lock.json`, `bun.lock` and
35
+ * `pnpm-lock.yaml`, and `medium` from `yarn.lock`, whose derived facts are capped there (§10 Formats).
36
+ */
37
+ confidence?: 'high' | 'medium';
38
+ }
39
+ /**
40
+ * The catalog data attribution reads (§4 Catalog versions): the framework path rules and escape-only shapes (§10), and
41
+ * the remote URL normalization rules (§11).
42
+ */
43
+ export interface AttributionRules extends PathRules {
44
+ remoteUrlNormalization: RemoteUrlNormalization;
45
+ }
46
+ /** Where an artifact is served from (§8 Origin and provenance). */
47
+ export type Origin = 'local-build' | 'same-origin' | 'cross-origin' | 'inline';
48
+ /** How the code behind a finding got into its artifact (§10 Provenance). */
49
+ export declare const provenances: readonly ["first-party", "bundled-dependency", "remote", "inline", "unknown"];
50
+ export type Provenance = (typeof provenances)[number];
51
+ /** The artifact fields attribution reads, and that occurrences carry: URL, hash and origin (§8). */
52
+ export interface ArtifactIdentity {
53
+ url: string;
54
+ hash: string;
55
+ origin: Origin;
56
+ }
57
+ /**
58
+ * An artifact as attribution reads it: its identity, its text, and the source map that verified against it (§2), with
59
+ * the method that paired it, the line reading that verified it and the build-relative path whose directory its
60
+ * relative sources resolve against (null when it has none in the build), or null when none did.
61
+ */
62
+ export interface MappedArtifact extends ArtifactIdentity {
63
+ /**
64
+ * The name occurrences give the artifact, when it isn't its URL: one key URL reached through two fetched URLs is an
65
+ * artifact of each (§11).
66
+ */
67
+ id?: string;
68
+ text: string;
69
+ map: {
70
+ raw: unknown;
71
+ reading: LineReading;
72
+ method: string;
73
+ base: string | null;
74
+ } | null;
75
+ }
76
+ /**
77
+ * The attribution of an occurrence: its attribution key (§11), the provenance that follows from it, and for a `pkg:`
78
+ * key the containing package's name (§10). A finding's also carries `vendoredBy` when its code is vendored (§10
79
+ * Provenance, §15): evidence only, never in the fingerprint, the baseline or `changed`.
80
+ */
81
+ export interface Attribution {
82
+ key: string;
83
+ provenance: Provenance;
84
+ package?: string;
85
+ vendoredBy?: string;
86
+ workspace?: string;
87
+ }
88
+ /** A position in an original source (§10): the raw `sources` entry, a 1-based line and a 0-based column. */
89
+ export interface OriginalLocation {
90
+ source: string;
91
+ line: number;
92
+ column: number;
93
+ }
94
+ /**
95
+ * An occurrence's attribution evidence (§8, §10), each field present only when it applies:
96
+ * - `source`: the raw `sources` entry of the synthetic or bundler-runtime source the lookup reached (null for a null
97
+ * entry), which counts as unmapped
98
+ * - `rejected`: the lookup candidate a failed token check discarded
99
+ * - `slug`: the lossy slug that names a scoped package under Yarn's pnpm linker
100
+ * - `pathRule`: the id of the framework path rule that named the package of an escaped source
101
+ * - `package`: the package a remote artifact's map names at the occurrence, which is evidence only: remote code keys
102
+ * `url:` (§9, §10 Provenance)
103
+ * - `vendoredBy`: the vendoring package, `name@version`, when the containing package's path lies inside another
104
+ * package's store entry (a store-name mismatch), or inside an installed package when the lockfile says it isn't
105
+ * installed itself (§10 Provenance), which is evidence only
106
+ * - `version`: the containing package's version, from its strongest source (§10 Version), which is evidence only
107
+ * - `workspace`: the lockfile workspace (`name@version`) that holds first-party code, which only a lockfile gives
108
+ * (§10 Provenance; ADR 0006), evidence only
109
+ */
110
+ export interface AttributionEvidence {
111
+ source?: string | null;
112
+ rejected?: OriginalLocation;
113
+ slug?: string;
114
+ pathRule?: string;
115
+ package?: string;
116
+ vendoredBy?: string;
117
+ version?: PackageVersion;
118
+ workspace?: string;
119
+ }
120
+ /**
121
+ * Where a package's version came from (§10 Version), strongest first: a store path, a lockfile keyed by install path,
122
+ * then the weak content signals: the package's `package.json` in `sourcesContent`, an in-package `VERSION`
123
+ * constant, a banner.
124
+ */
125
+ export declare const versionSources: readonly ["store-path", "lockfile", "package-json", "version-constant", "banner"];
126
+ export type VersionSource = (typeof versionSources)[number];
127
+ /** The strong version sources, the only ones that feed `packages` and the `previousVersion` note (§10, §11). */
128
+ export declare const strongVersionSources: ReadonlySet<VersionSource>;
129
+ /** A package's version and where it came from (§10 Version). */
130
+ export interface PackageVersion {
131
+ version: string;
132
+ versionSource: VersionSource;
133
+ }
134
+ /**
135
+ * A `token-check` trace step (§14): the token check's result at the lookup point (§10), the token, and the lookup
136
+ * candidate it checked: the mapped original position, kept when the check passes or doesn't apply, and discarded when
137
+ * it fails.
138
+ */
139
+ export interface TokenCheckStep {
140
+ kind: 'token-check';
141
+ result: 'passed' | 'failed' | 'n/a';
142
+ token: string | null;
143
+ lookup: GeneratedLocation;
144
+ candidate: OriginalLocation;
145
+ text: string;
146
+ }
147
+ /**
148
+ * A `path-rule` trace step (§14): the framework path rule that named the package of an escaped source (§10), the
149
+ * package it named, and the raw source it matched.
150
+ */
151
+ export interface PathRuleStep {
152
+ kind: 'path-rule';
153
+ rule: string;
154
+ package: string;
155
+ source: string;
156
+ text: string;
157
+ }
158
+ /** A trace step of an attributed occurrence: the resolver's, or one attribution adds (§14, §19 Attribution). */
159
+ export type AttributedTraceStep = TraceStep | TokenCheckStep | PathRuleStep;
160
+ export interface AttributedOccurrence extends Omit<RawOccurrence, 'artifact' | 'confidence' | 'lookup' | 'trace'> {
161
+ artifact: ArtifactIdentity;
162
+ attribution: Attribution;
163
+ /** The original location a source map resolves, when attribution kept one (§8). */
164
+ original: OriginalLocation | null;
165
+ evidence: AttributionEvidence;
166
+ /**
167
+ * The introducing dependencies (§10), `name@version`, sorted: present only for bundled-dependency code that a usable
168
+ * lockfile places, and absent when they are unknown.
169
+ */
170
+ introducedBy?: string[];
171
+ /** The resolver's target and mutation confidence, and attribution's own (§9). */
172
+ confidence: Confidence;
173
+ /** The resolver's trace, then attribution's `token-check` and `path-rule` steps, if any. */
174
+ trace: AttributedTraceStep[];
175
+ }
176
+ /**
177
+ * Attributes each occurrence (§10):
178
+ *
179
+ * - Inline code is the entry document's (`inline`), and has high attribution confidence.
180
+ * - Remote code keys `url:` with its URL normalized by the catalog's rules (§11 Remote URL normalization), provenance
181
+ * `remote`, and is `high` on that key (§9). A verified map still gives its occurrences original locations, looked up
182
+ * as for local code, and a package the map names is evidence only (`evidence.package`).
183
+ * - Local code without a source map is `unknown`, with `no-map`.
184
+ * - Local code with a verified map is looked up there at the occurrence's lookup point, with the line reading that
185
+ * verified the map. A position that is unmapped, or maps to a synthetic or bundler-runtime source, is `unknown` with
186
+ * `no-map`. Otherwise the token check runs, and a position that fails it is discarded: `unknown`, with
187
+ * `token-check-failed` and the rejected candidate. A kept position's source path names the containing package, which
188
+ * keys `pkg:<name>` with provenance `bundled-dependency`. A source with an unrecognized scheme is `unknown` with
189
+ * `foreign-scheme`, and a scoped package under Yarn's pnpm linker `unknown` with `yarn-slug`. A source under no
190
+ * `node_modules` segment inside its namespace's inferred root is first-party, keyed `app:<root-relative path>`
191
+ * (`first-party-inferred` when the root lies above the bundler base), unless its map's ignore list demotes it to
192
+ * `unknown` (`ignore-list-demoted`). One outside the root is escaped: `unknown` with `escaped-source`. Before the
193
+ * root decides, the catalog's framework path rules are tried, then its escape-only shapes: a source a rule
194
+ * matches keys the package the rule names (`bundled-dependency`, `framework-path-rule`, with a `path-rule` step),
195
+ * and one an escape-only shape matches is escaped, wherever the root is.
196
+ */
197
+ export declare function attribute(occurrences: readonly RawOccurrence[], artifacts: readonly MappedArtifact[], rules: AttributionRules): AttributedOccurrence[];
198
+ /**
199
+ * An occurrence of an ineffective write (§3 Record), attributed as a finding's occurrence is: its location, attribution
200
+ * and evidence, and the resolver's trace, then attribution's `token-check` step, if any.
201
+ */
202
+ export interface AttributedIneffectiveWrite extends Omit<IneffectiveWrite, 'artifact' | 'lookup' | 'trace'> {
203
+ artifact: ArtifactIdentity;
204
+ attribution: Attribution;
205
+ original: OriginalLocation | null;
206
+ evidence: AttributionEvidence;
207
+ trace: AttributedTraceStep[];
208
+ }
209
+ /** Attributes each occurrence of an ineffective write (§3 Record), as `attribute` attributes a finding's. */
210
+ export declare function attributeIneffective(writes: readonly IneffectiveWrite[], artifacts: readonly MappedArtifact[], rules: AttributionRules): AttributedIneffectiveWrite[];
211
+ /** A scan's attribution: one inferred root per namespace, and the lockfile as the scan reads it. */
212
+ export interface ScanAttribution {
213
+ /** Attributes each occurrence of a finding, as `attribute` does, with the lockfile's evidence and introducers. */
214
+ attribute(occurrences: readonly RawOccurrence[]): AttributedOccurrence[];
215
+ /** Attributes each occurrence of an ineffective write, as `attributeIneffective` does, with the lockfile's evidence. */
216
+ attributeIneffective(writes: readonly IneffectiveWrite[]): AttributedIneffectiveWrite[];
217
+ /** Why introducers are unknown, for the attribution block (§13). */
218
+ introducers: Introducers;
219
+ }
220
+ /**
221
+ * The attribution of a scan over `artifacts` (§10), with the lockfile it was given, or null. The lockfile only adds
222
+ * evidence, never a key (ADR 0006):
223
+ *
224
+ * - A lockfile that can't be read or parsed, or a format version R1 doesn't read (`package-lock.json` v1), gives
225
+ * `no-lockfile`, with the format version as evidence, as no lockfile does.
226
+ * - A lockfile with no installed copy of a package at the version a store path in the scan's maps gives it is stale
227
+ * for the whole scan: `lockfile-stale`, and it derives nothing.
228
+ * - Otherwise a package's install path gives it its lockfile version (§10 Version), and a package path the lockfile
229
+ * says isn't installed is vendored, in the installed package around it (§10 Provenance). First-party code gets its
230
+ * workspace as evidence.
231
+ * - The importer is picked as `importerOf` says; with none, `importer-unresolved`, and no introducers.
232
+ */
233
+ export declare function attribution(artifacts: readonly MappedArtifact[], rules: AttributionRules, lockfileInput: LockfileInput | null): ScanAttribution;