@cosyte/script-utils 0.0.2 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosyte/script-utils",
3
- "version": "0.0.2",
3
+ "version": "0.1.1",
4
4
  "description": "Zero-dependency helpers for the repo-local gate scripts in @cosyte/* repos.",
5
5
  "keywords": [
6
6
  "cli",
@@ -29,6 +29,14 @@
29
29
  "./phi-scan": {
30
30
  "types": "./phi-scan.d.ts",
31
31
  "default": "./phi-scan.js"
32
+ },
33
+ "./internal-refs": {
34
+ "types": "./internal-refs.d.ts",
35
+ "default": "./internal-refs.js"
36
+ },
37
+ "./attw": {
38
+ "types": "./attw.d.ts",
39
+ "default": "./attw.js"
32
40
  }
33
41
  },
34
42
  "files": [
@@ -36,6 +44,11 @@
36
44
  "index.d.ts",
37
45
  "phi-scan.js",
38
46
  "phi-scan.d.ts",
47
+ "internal-refs.js",
48
+ "internal-refs.d.ts",
49
+ "attw.js",
50
+ "attw.d.ts",
51
+ "check-no-emdash.sh",
39
52
  "README.md",
40
53
  "CHANGELOG.md"
41
54
  ],
@@ -44,5 +57,12 @@
44
57
  },
45
58
  "publishConfig": {
46
59
  "access": "public"
60
+ },
61
+ "devDependencies": {
62
+ "vitest": "4.1.4"
63
+ },
64
+ "scripts": {
65
+ "build": "node ../../scripts/pack-emdash-gate.mjs",
66
+ "test": "vitest run"
47
67
  }
48
68
  }
package/phi-scan.d.ts CHANGED
@@ -7,15 +7,28 @@
7
7
  * The caller owns the five per-repo axes below and the per-standard field detectors.
8
8
  */
9
9
 
10
- /** A reported PHI finding. `path` is the LOCUS the engine chose, never a path the caller invents. */
10
+ /**
11
+ * A reported PHI finding: a POSITION and a RULE, never the token that matched. `path` is the LOCUS
12
+ * the engine chose, never a path the caller invents.
13
+ *
14
+ * 🛑 THE MATCHED VALUE IS NOT PART OF A FINDING. The report goes to stderr, stderr is a CI log, and
15
+ * a diagnostic about a PHI leak that quotes the leak is a second copy of it somewhere worse
16
+ * (`phi-safety` P4). A detector may pass `value`; the engine drops it at the boundary rather than
17
+ * storing it, so no reporting path downstream can print what no record carries.
18
+ */
11
19
  export interface Hit {
12
20
  /** The reported locus: the target's repo-relative path, plus an origin label when it has one. */
13
21
  path: string;
14
22
  /** A locator inside the target: `(ssn)`, `(email)`, or a field id from a per-standard detector. */
15
23
  segment: string;
16
- /** The offending value, as found. */
17
- value: string;
18
- /** Why it was raised, in a few words. */
24
+ /**
25
+ * The offending value, as a detector found it. ACCEPTED AND DISCARDED: the engine neither stores
26
+ * nor prints it, and a hit the engine reports never carries one. It stays in the surface so a
27
+ * detector that has the token in hand can keep saying so at its own call site without the engine
28
+ * becoming the place that publishes it.
29
+ */
30
+ value?: string;
31
+ /** Why it was raised, in a few words. This is what the report prints beside the locator. */
19
32
  reason: string;
20
33
  }
21
34
 
@@ -45,6 +58,10 @@ export interface Target {
45
58
  /**
46
59
  * Where these bytes came from, when it is not simply the file at `path`. Set only by the index
47
60
  * union, and it decorates the REPORTED LOCUS ONLY.
61
+ *
62
+ * TWO VALUES, BECAUSE THE REMEDY DIFFERS. `git index` is a path whose working-tree copy this run
63
+ * did not read at all; `git index; the working tree differs` is one whose disk copy WAS read and
64
+ * carries other bytes, so the file a developer opens is clean and re-staging is part of the fix.
48
65
  */
49
66
  origin?: string;
50
67
  }
@@ -85,7 +102,14 @@ export type DetectFn = (ctx: DetectContext) => void;
85
102
 
86
103
  /** The three codes this repo's own exit contract assigns. All three must differ. */
87
104
  export interface PhiScanExitCodes {
88
- /** The scan ran, read every target it enumerated, and found nothing. */
105
+ /**
106
+ * The scan ran, read every target it enumerated, and found nothing. The ONE subtraction is the
107
+ * enumeration TOCTOU window: an UNTRACKED file the walk listed, in `all` mode, that was gone by
108
+ * read time and is still gone at the end of the run, is reported SKIPPED. Git carries no bytes
109
+ * at such a path, so nothing this repository holds went unread. WHEN THAT HAPPENS THE CLEAN LINE
110
+ * ITSELF SAYS SO on stdout, counting the skipped files, so the subtraction is visible to a reader
111
+ * who never sees stderr; with nothing skipped the line is byte-identical to what it always was.
112
+ */
89
113
  clean: number;
90
114
  /** This corpus contains something that looks like PHI. */
91
115
  hits: number;
@@ -122,13 +146,31 @@ export interface PhiScanConfig {
122
146
  * contract reserves for HITS FOUND.
123
147
  *
124
148
  * WHAT DERIVING GIVES UP: a declaration can notice that a root is not the KIND it was meant to be
125
- * and derivation cannot, so a root that changes kind is silently treated as what it now is. A root
126
- * that is NEITHER a file nor a directory is still refused, and a root naming a symbolic link is
127
- * refused rather than followed. A MISSING root is skipped, which is unchanged from the copied
128
- * scanners. It is not the last state in which a root contributes nothing without saying so, and
129
- * two others are known: a file root the read filter drops (a `.md` file root reads nothing under
130
- * the default `isWalkReadable`, so porting one means overriding that filter too), and an
131
- * UNREADABLE root, which is reported the same way a missing one is.
149
+ * and derivation cannot, so a root that changes kind is silently treated as what it now is. That
150
+ * is a recorded narrowing rather than an oversight, with its compensating control named:
151
+ * `documentation/decisions/0003-the-phi-scan-engine-gap-settlements.md`, N2. Every TRACKED file
152
+ * that lived under such a root is still read, because the index half of `all` mode is not narrowed
153
+ * by this parameter at all.
154
+ *
155
+ * ALL THREE KINDS HAVE ONE SETTLED OUTCOME. A REGULAR FILE is scanned as one target. A SYMBOLIC
156
+ * LINK is refused rather than followed, and so is anything that is neither a file nor a directory.
157
+ * A DIRECTORY THAT CANNOT BE ENUMERATED is refused at the caller's `refuse` code, naming the path
158
+ * and the errno; it used to escape `readdirSync` uncaught and take node's own exit 1, the code
159
+ * this contract reserves for HITS FOUND. A MISSING root is skipped by the WALK, which is unchanged
160
+ * from the copied scanners, and is then caught by the rule below.
161
+ *
162
+ * 🛑 EVERY ROOT MUST YIELD AT LEAST ONE FILE THE WALK READ, OR `all` MODE REFUSES AND NAMES THE
163
+ * STARVED ROOTS. That is what closes the class the paragraph above used to end with: a root that
164
+ * contributes nothing WITHOUT SAYING SO. All three of the known members are in it - a missing
165
+ * root, an UNREADABLE root (reported the same way a missing one is), and a root whose every file
166
+ * the read filter drops, which is what a `.md` file root does under the default
167
+ * `isWalkReadable`. A root is a scope decision, and a scope decision that silently selected
168
+ * nothing is the sweep reporting on a corpus it never had.
169
+ *
170
+ * THE INDEX HALF NEVER CREDITS A ROOT. A root that is missing or empty on disk is starved even
171
+ * when git tracks files under it: those files are still read from the bytes git carries, and any
172
+ * hit in them is reported before the refusal, but what git carries cannot vouch for a directory
173
+ * on disk.
132
174
  */
133
175
  scanRoots: readonly string[];
134
176
 
@@ -143,6 +185,16 @@ export interface PhiScanConfig {
143
185
  * scan root, so the non-regular refusal never saw it, and the route read the link's TARGET PATH
144
186
  * as if it were content and reported clean at exit 0. A staged path this admits and no scan root
145
187
  * covers is now REFUSED, naming the path.
188
+ *
189
+ * 🛑 THIS PREDICATE ALSO DECIDES WHAT THE `--staged` ROUTE REFUSES, which is a change. Its
190
+ * non-regular and unmerged refusals used to key on the ROOT half of scope, so a caller whose
191
+ * staged scope is narrower than its roots had commits blocked that its own gate had always let
192
+ * through. What a commit is blocked on is this key's job. THE COST: a staged non-regular entry
193
+ * this predicate declines is no longer refused HERE. `all` mode still refuses it twice over (the
194
+ * walk classifies it under a scan root, and the index route refuses the tracked record wherever it
195
+ * sits), so a repository's own sweep still does. Recorded as N1 in
196
+ * `documentation/decisions/0003-the-phi-scan-engine-gap-settlements.md`; widen this predicate if
197
+ * you want the wider refusal.
146
198
  */
147
199
  isStagedReadable: (relPath: string) => boolean;
148
200