@codyswann/lisa 5.1.7 → 5.2.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.
Files changed (101) hide show
  1. package/all/copy-overwrite/scripts/lib/github-attestation-provider.mjs +15 -0
  2. package/all/copy-overwrite/scripts/lib/npm-update-allocate.mjs +32 -39
  3. package/all/copy-overwrite/scripts/lib/npm-update-authorization.mjs +12 -2
  4. package/all/copy-overwrite/scripts/lib/npm-update-checkpoint.mjs +10 -30
  5. package/all/copy-overwrite/scripts/lib/npm-update-execution-adapter.mjs +4 -1
  6. package/all/copy-overwrite/scripts/lib/npm-update-helper-graph.mjs +1 -1
  7. package/all/copy-overwrite/scripts/lib/npm-update-helper-inventory.mjs +4 -0
  8. package/all/copy-overwrite/scripts/lib/npm-update-hosted-hook.mjs +2 -1
  9. package/all/copy-overwrite/scripts/lib/npm-update-invariants.mjs +15 -1
  10. package/all/copy-overwrite/scripts/lib/npm-update-leaf-contract.mjs +41 -9
  11. package/all/copy-overwrite/scripts/lib/npm-update-leaf.mjs +23 -35
  12. package/all/copy-overwrite/scripts/lib/npm-update-policy.mjs +41 -6
  13. package/all/copy-overwrite/scripts/lib/npm-update-recovery.mjs +16 -3
  14. package/all/copy-overwrite/scripts/lib/npm-update-tracker-jira.mjs +300 -0
  15. package/all/copy-overwrite/scripts/lib/npm-update-tracker-linear.mjs +304 -0
  16. package/all/copy-overwrite/scripts/lib/npm-update-tracker-wire.mjs +298 -0
  17. package/all/copy-overwrite/scripts/lib/npm-update-tracker.mjs +179 -0
  18. package/all/copy-overwrite/scripts/lisa-npm-updater.mjs +16 -2
  19. package/all/copy-overwrite/scripts/lisa-work-item.mjs +1 -1
  20. package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +62 -14
  21. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  22. package/dist/core/lisa-owned-hash-ledger.js +96 -0
  23. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  24. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  25. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  26. package/dist/core/upstream-evidence-manifest.js +84 -77
  27. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  28. package/package.json +4 -5
  29. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  30. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  31. package/plugins/lisa-agy/plugin.json +1 -1
  32. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  33. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  34. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  35. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  36. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  37. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  38. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  39. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  40. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  41. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  42. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  43. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  44. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  45. package/plugins/lisa-expo-agy/plugin.json +1 -1
  46. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  48. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  49. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  50. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  51. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  52. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  53. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  54. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  55. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  56. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  57. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  58. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  59. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  60. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  62. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  63. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  64. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  65. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  66. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  67. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  69. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  70. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  71. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  72. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  73. package/plugins/lisa-rails-agy/plugin.json +1 -1
  74. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  75. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  76. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  77. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  78. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  79. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  80. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  81. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  82. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  83. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  84. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  85. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  86. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  87. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  88. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  89. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  90. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  91. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  92. package/scripts/check-phrase-manifest-parity.mjs +6 -3
  93. package/scripts/classify-phrase-tests.mjs +109 -20
  94. package/scripts/fix-namespace-test-assertions.mjs +3 -20
  95. package/scripts/lib/phrase-tests/doc-taint.mjs +708 -0
  96. package/scripts/lib/phrase-tests/inventory.mjs +381 -0
  97. package/scripts/lib/phrase-tests/manifest.mjs +14 -2
  98. package/scripts/lib/phrase-tests/marker-classes.mjs +323 -0
  99. package/scripts/lib/phrase-tests/redact.mjs +88 -0
  100. package/scripts/two-channel-couplings.json +1 -1
  101. package/typescript/copy-overwrite/.prettierignore +4 -0
@@ -0,0 +1,381 @@
1
+ /**
2
+ * Classify every Markdown phrase assertion (CodySwannGT/lisa#4867): each
3
+ * required-phrases manifest entry, and each `toContain` / `toMatch` site in a
4
+ * unit test that reads a Markdown document. The class of each phrase comes
5
+ * from `marker-classes.mjs`; this module only finds the phrases.
6
+ * @module scripts/lib/phrase-tests/inventory
7
+ */
8
+ import ts from "typescript";
9
+
10
+ import {
11
+ booleanLiteral,
12
+ expectChains,
13
+ isPhraseChain,
14
+ parseSource,
15
+ walk,
16
+ } from "./ast.mjs";
17
+ import {
18
+ MANIFEST_COMMENT,
19
+ manifestEntries,
20
+ SOURCE_GUARDS_COMMENT,
21
+ } from "./manifest.mjs";
22
+ import {
23
+ analyseDocTaint,
24
+ mentionsDocumentPath,
25
+ subjectSource,
26
+ } from "./doc-taint.mjs";
27
+ import { classifyPhrase } from "./marker-classes.mjs";
28
+
29
+ /**
30
+ * @typedef {{ cls: string, rule: string, parser: readonly string[] }} PhraseVerdict
31
+ * @typedef {object} AssertionVerdict
32
+ * @property {string} file - The test file.
33
+ * @property {number} line - 1-based line of the assertion.
34
+ * @property {string} matcher - `toContain`, `not.toMatch`, `includes` ...
35
+ * @property {string} subject - Source text of the `expect(...)` argument.
36
+ * @property {"markdown" | "other" | "unknown"} source - Where that text comes from.
37
+ * @property {"string" | "pattern" | "expression"} kind - What the phrase is.
38
+ * @property {string | { source: string, flags: string }} value - The phrase,
39
+ * or the argument's source text when it is not a literal.
40
+ * @property {string} cls - Its class.
41
+ * @property {string} rule - The rule that decided the class.
42
+ * @property {readonly string[]} parser - The parser behind a MACHINE-TOKEN.
43
+ */
44
+
45
+ /** Phrases pinned in a file that is not a Markdown document. */
46
+ const NOT_MARKDOWN = "NOT-MARKDOWN";
47
+
48
+ /** Classes a report counts, in display order. */
49
+ export const REPORT_CLASSES = Object.freeze([
50
+ "MACHINE-TOKEN",
51
+ "STRUCTURAL",
52
+ "WORDING",
53
+ "UNRESOLVED",
54
+ NOT_MARKDOWN,
55
+ ]);
56
+
57
+ /** A Markdown document: the only kind of file whose wording this culls. */
58
+ const MARKDOWN_FILE = /\.mdc?$/u;
59
+
60
+ /**
61
+ * Count verdicts by class, every class present even when zero.
62
+ * @param {readonly { cls: string }[]} verdicts - Classified phrases.
63
+ * @returns {Record<string, number>} Counts keyed by class.
64
+ */
65
+ export function countByClass(verdicts) {
66
+ /** @type {Record<string, number>} */
67
+ const counts = Object.fromEntries(REPORT_CLASSES.map(cls => [cls, 0]));
68
+ for (const { cls } of verdicts) counts[cls] = (counts[cls] ?? 0) + 1;
69
+ return counts;
70
+ }
71
+
72
+ /**
73
+ * Count assertion sites by where their subject text comes from.
74
+ * @param {readonly { source: string }[]} sites - Classified sites.
75
+ * @returns {Record<string, number>} Counts for markdown, other and unknown.
76
+ */
77
+ export function countBySource(sites) {
78
+ /** @type {Record<string, number>} */
79
+ const counts = { markdown: 0, other: 0, unknown: 0 };
80
+ for (const { source } of sites) counts[source] = (counts[source] ?? 0) + 1;
81
+ return counts;
82
+ }
83
+
84
+ /**
85
+ * Classify one manifest check. A check on a file that is not a Markdown
86
+ * document — a workflow, a hook, a script — is NOT-MARKDOWN: it pins source
87
+ * text, not guidance prose, and is outside what CodySwannGT/lisa#4867 culls.
88
+ * @param {import("./manifest.mjs").PhraseCheck} check - The check.
89
+ * @returns {{ cls: string, rule: string, parser: readonly string[] }} Its class.
90
+ */
91
+ export function classifyCheck(check) {
92
+ if (!MARKDOWN_FILE.test(check.file)) {
93
+ return { cls: NOT_MARKDOWN, rule: "not-a-markdown-document", parser: [] };
94
+ }
95
+ return check.kind === "string"
96
+ ? classifyPhrase(/** @type {string} */ (check.value))
97
+ : classifyPhrase(
98
+ /** @type {import("./manifest.mjs").Pattern} */ (check.value).source,
99
+ { isPattern: true }
100
+ );
101
+ }
102
+
103
+ /**
104
+ * Classify every entry of the required-phrases manifest.
105
+ * @param {import("./manifest.mjs").Manifest} manifest - The manifest.
106
+ * @returns {{ files: number, entries: number, counts: Record<string, number>, verdicts: (import("./manifest.mjs").PhraseCheck & PhraseVerdict)[] }} The report.
107
+ */
108
+ export function classifyManifest(manifest) {
109
+ const verdicts = manifestEntries(manifest).map(check => ({
110
+ ...check,
111
+ ...classifyCheck(check),
112
+ }));
113
+ return {
114
+ files: Object.keys(manifest.files).length,
115
+ entries: verdicts.length,
116
+ counts: countByClass(verdicts),
117
+ verdicts,
118
+ };
119
+ }
120
+
121
+ /** Classes that may stay in the required-phrases manifest. */
122
+ export const LOAD_BEARING = Object.freeze(["MACHINE-TOKEN", "STRUCTURAL"]);
123
+
124
+ /**
125
+ * The entries of a manifest whose class passes `keep`, dropping every file
126
+ * left with none.
127
+ * @param {import("./manifest.mjs").Manifest} manifest - The manifest.
128
+ * @param {(cls: string) => boolean} keep - Which classes to keep.
129
+ * @param {readonly string[]} comment - The `$comment` of the result.
130
+ * @returns {import("./manifest.mjs").Manifest} The selected manifest.
131
+ */
132
+ export function selectEntries(manifest, keep, comment) {
133
+ const kept =
134
+ (
135
+ /** @type {string} */ file,
136
+ /** @type {"required" | "forbidden"} */ polarity,
137
+ /** @type {"string" | "pattern"} */ kind
138
+ ) =>
139
+ (/** @type {any} */ value) =>
140
+ keep(classifyCheck({ file, polarity, kind, value }).cls);
141
+ const files = Object.entries(manifest.files).flatMap(([file, entry]) => {
142
+ const selected = {
143
+ required: entry.required.filter(kept(file, "required", "string")),
144
+ forbidden: entry.forbidden.filter(kept(file, "forbidden", "string")),
145
+ requiredPatterns: entry.requiredPatterns.filter(
146
+ kept(file, "required", "pattern")
147
+ ),
148
+ forbiddenPatterns: entry.forbiddenPatterns.filter(
149
+ kept(file, "forbidden", "pattern")
150
+ ),
151
+ source: entry.source,
152
+ };
153
+ const empty =
154
+ selected.required.length +
155
+ selected.forbidden.length +
156
+ selected.requiredPatterns.length +
157
+ selected.forbiddenPatterns.length ===
158
+ 0;
159
+ return empty ? [] : [[file, selected]];
160
+ });
161
+ return { $comment: comment, files: Object.fromEntries(files) };
162
+ }
163
+
164
+ /**
165
+ * Split a manifest: its MACHINE-TOKEN and STRUCTURAL entries stay as the
166
+ * required-phrases manifest, its NOT-MARKDOWN entries move to the
167
+ * source-text guards, and its WORDING entries are dropped.
168
+ *
169
+ * The guards already on disk are merged, never replaced: after the first
170
+ * run the manifest holds no NOT-MARKDOWN entries, so a second run would
171
+ * otherwise write an empty guards file. Running it again is a no-op.
172
+ * @param {import("./manifest.mjs").Manifest} manifest - The manifest.
173
+ * @param {import("./manifest.mjs").Manifest} [existingGuards] - The
174
+ * source-text guards file as it stands, if there is one.
175
+ * @returns {{ manifest: import("./manifest.mjs").Manifest, sourceGuards: import("./manifest.mjs").Manifest }} The two files.
176
+ */
177
+ export function pruneManifest(manifest, existingGuards) {
178
+ const found = selectEntries(
179
+ manifest,
180
+ cls => cls === NOT_MARKDOWN,
181
+ SOURCE_GUARDS_COMMENT
182
+ );
183
+ return {
184
+ manifest: selectEntries(
185
+ manifest,
186
+ cls => LOAD_BEARING.includes(cls),
187
+ MANIFEST_COMMENT
188
+ ),
189
+ sourceGuards: existingGuards
190
+ ? mergeManifests(existingGuards, found, SOURCE_GUARDS_COMMENT)
191
+ : found,
192
+ };
193
+ }
194
+
195
+ /** The arrays of a manifest file entry. */
196
+ const ENTRY_KEYS = /** @type {const} */ ([
197
+ "required",
198
+ "forbidden",
199
+ "requiredPatterns",
200
+ "forbiddenPatterns",
201
+ "source",
202
+ ]);
203
+
204
+ /**
205
+ * Append the values of `more` that `base` lacks, keeping `base` in order.
206
+ * @param {readonly unknown[]} base - Existing values.
207
+ * @param {readonly unknown[]} more - Values to add.
208
+ * @returns {unknown[]} The union.
209
+ */
210
+ function union(base, more) {
211
+ const seen = new Set(base.map(value => JSON.stringify(value)));
212
+ return [...base, ...more.filter(value => !seen.has(JSON.stringify(value)))];
213
+ }
214
+
215
+ /**
216
+ * Merge two manifests. Every value in `base` stays where it is and new
217
+ * values are appended, so merging nothing new returns `base` unchanged.
218
+ * @param {import("./manifest.mjs").Manifest} base - The manifest kept.
219
+ * @param {import("./manifest.mjs").Manifest} more - Entries to add.
220
+ * @param {readonly string[]} comment - The `$comment` of the result.
221
+ * @returns {import("./manifest.mjs").Manifest} The merged manifest.
222
+ */
223
+ export function mergeManifests(base, more, comment) {
224
+ const files = { ...base.files };
225
+ for (const [file, entry] of Object.entries(more.files)) {
226
+ const current = files[file];
227
+ files[file] = current
228
+ ? /** @type {import("./manifest.mjs").FileEntry} */ (
229
+ Object.fromEntries(
230
+ ENTRY_KEYS.map(key => [key, union(current[key], entry[key])])
231
+ )
232
+ )
233
+ : entry;
234
+ }
235
+ const sorted = Object.keys(files)
236
+ .sort()
237
+ .map(file => [file, files[file]]);
238
+ return { $comment: comment, files: Object.fromEntries(sorted) };
239
+ }
240
+
241
+ /** Calls that read a file's text. */
242
+ const READ_CALLS = /\b(?:readFileSync|readFile)\b/u;
243
+
244
+ /**
245
+ * Whether a test file reads a Markdown document: it spells a `.md` / `.mdc`
246
+ * extension and a document root in its literals and calls a file read.
247
+ * @param {ts.SourceFile} sourceFile - The parsed test file.
248
+ * @returns {boolean} True when the file reads Markdown.
249
+ */
250
+ export function readsMarkdown(sourceFile) {
251
+ return READ_CALLS.test(sourceFile.text) && mentionsDocumentPath(sourceFile);
252
+ }
253
+
254
+ /**
255
+ * `const NAME = <string or regex literal>` bindings in a file, so an
256
+ * assertion that names a constant still resolves to its phrase.
257
+ * @param {ts.SourceFile} sourceFile - The parsed test file.
258
+ * @returns {Map<string, ts.Expression>} Initialisers keyed by name.
259
+ */
260
+ function constantLiterals(sourceFile) {
261
+ /** @type {Map<string, ts.Expression>} */
262
+ const constants = new Map();
263
+ /** @type {Set<string>} */
264
+ const shadowed = new Set();
265
+ walk(sourceFile, node => {
266
+ if (
267
+ ts.isVariableDeclaration(node) &&
268
+ ts.isIdentifier(node.name) &&
269
+ node.initializer &&
270
+ ts.isVarConst(node)
271
+ ) {
272
+ const name = node.name.text;
273
+ if (constants.has(name) || shadowed.has(name)) {
274
+ constants.delete(name);
275
+ shadowed.add(name);
276
+ } else {
277
+ constants.set(name, node.initializer);
278
+ }
279
+ }
280
+ });
281
+ return constants;
282
+ }
283
+
284
+ /**
285
+ * The phrase an assertion argument spells, if it is a literal.
286
+ * @param {ts.Expression | undefined} node - The argument.
287
+ * @param {Map<string, ts.Expression>} constants - File constants.
288
+ * @returns {{ kind: "string", value: string } | { kind: "pattern", value: { source: string, flags: string } } | undefined} The phrase.
289
+ */
290
+ export function literalPhrase(node, constants) {
291
+ if (node === undefined) return undefined;
292
+ if (ts.isStringLiteralLike(node)) return { kind: "string", value: node.text };
293
+ if (node.kind === ts.SyntaxKind.RegularExpressionLiteral) {
294
+ const text = node.getText();
295
+ const end = text.lastIndexOf("/");
296
+ return {
297
+ kind: "pattern",
298
+ value: { source: text.slice(1, end), flags: text.slice(end + 1) },
299
+ };
300
+ }
301
+ if (ts.isIdentifier(node) && constants.has(node.text)) {
302
+ const initializer = constants.get(node.text);
303
+ return initializer === node
304
+ ? undefined
305
+ : literalPhrase(initializer, new Map());
306
+ }
307
+ return undefined;
308
+ }
309
+
310
+ /**
311
+ * The argument and polarity of one phrase chain: `toContain(x)` /
312
+ * `toMatch(x)`, or `<text>.includes(x)` checked with `toBe(true|false)`.
313
+ * @param {ReturnType<typeof import("./ast.mjs").readExpectChain>} chain - A phrase chain.
314
+ * @returns {{ argument: ts.Expression | undefined, negated: boolean, matcher: string }} The parts.
315
+ */
316
+ export function phraseParts(chain) {
317
+ if (chain.matcher !== "toBe") {
318
+ return {
319
+ argument: chain.args[0],
320
+ negated: chain.negated,
321
+ matcher: chain.matcher ?? "",
322
+ };
323
+ }
324
+ const includes = /** @type {ts.CallExpression} */ (chain.subject);
325
+ const expected = booleanLiteral(chain.args[0]);
326
+ return {
327
+ // Not a boolean literal: the polarity is unknown, so leave the
328
+ // argument unset and let the site report UNRESOLVED.
329
+ argument: expected === undefined ? undefined : includes.arguments[0],
330
+ negated: expected === chain.negated,
331
+ matcher: "includes",
332
+ };
333
+ }
334
+
335
+ /**
336
+ * Classify every phrase assertion in a test file that reads Markdown.
337
+ * @param {string} fileName - Repository-relative test path.
338
+ * @param {string} text - Its contents.
339
+ * @returns {AssertionVerdict[]} One verdict per phrase assertion site; empty when the
340
+ * file reads no Markdown. `source` says whether the asserted text is a
341
+ * Markdown document ("markdown"), something else such as script output
342
+ * ("other"), or could not be traced ("unknown"); only "markdown" sites are
343
+ * Markdown wording assertions.
344
+ */
345
+ export function classifyAssertions(fileName, text) {
346
+ const sourceFile = parseSource(fileName, text);
347
+ if (!readsMarkdown(sourceFile)) return [];
348
+ const constants = constantLiterals(sourceFile);
349
+ const taint = analyseDocTaint(sourceFile);
350
+ return expectChains(sourceFile)
351
+ .filter(isPhraseChain)
352
+ .map(chain => {
353
+ const { argument, negated, matcher } = phraseParts(chain);
354
+ const phrase = literalPhrase(argument, constants);
355
+ const line =
356
+ sourceFile.getLineAndCharacterOfPosition(chain.site.getStart()).line +
357
+ 1;
358
+ const base = {
359
+ file: fileName,
360
+ line,
361
+ matcher: negated ? `not.${matcher}` : matcher,
362
+ subject: chain.subject?.getText(sourceFile) ?? "",
363
+ source: subjectSource(chain.subject, taint),
364
+ };
365
+ if (phrase === undefined) {
366
+ return {
367
+ ...base,
368
+ kind: "expression",
369
+ value: argument?.getText(sourceFile) ?? "",
370
+ cls: "UNRESOLVED",
371
+ rule: "argument-not-literal",
372
+ parser: [],
373
+ };
374
+ }
375
+ const verdict =
376
+ phrase.kind === "string"
377
+ ? classifyPhrase(phrase.value)
378
+ : classifyPhrase(phrase.value.source, { isPattern: true });
379
+ return { ...base, ...phrase, ...verdict };
380
+ });
381
+ }
@@ -11,11 +11,23 @@
11
11
  /** Repository-relative path of the manifest. */
12
12
  export const MANIFEST_PATH = "tests/phrase-manifest/required-phrases.json";
13
13
 
14
+ /** Repository-relative path of the non-Markdown source-text guards. */
15
+ export const SOURCE_GUARDS_PATH =
16
+ "tests/phrase-manifest/source-text-guards.json";
17
+
18
+ /** Explains the source-text guards file to whoever opens it. */
19
+ export const SOURCE_GUARDS_COMMENT = Object.freeze([
20
+ "Phrases that must (required) or must not (forbidden) appear in files that are NOT Markdown documents — workflows, hooks, scripts — checked by tests/unit/docs/required-phrases.test.ts.",
21
+ "These guard source text, not guidance prose, so they are outside CodySwannGT/lisa#4867's Markdown cull; they were split out of required-phrases.json so that file holds only MACHINE-TOKEN and STRUCTURAL entries. A Markdown file listed here fails the test.",
22
+ "Same schema as required-phrases.json; hand-maintained, so keep keys and arrays sorted. Patterns are RegExp { source, flags } with String#match semantics.",
23
+ ]);
24
+
14
25
  /** Explains the file to whoever opens it. */
15
26
  export const MANIFEST_COMMENT = Object.freeze([
16
27
  "Phrases that must (required) or must not (forbidden) appear in each file, checked by tests/unit/docs/required-phrases.test.ts.",
17
- "Generated ONCE by scripts/generate-phrase-manifest.mjs from the phrase-only test files it replaced (CodySwannGT/lisa#4609); those files are deleted, so it cannot be regenerated.",
18
- "It is now the hand-maintained source of truth: add, change or remove phrases here directly, keeping keys and arrays sorted.",
28
+ "Only load-bearing phrases belong here (CodySwannGT/lisa#4867): a MACHINE-TOKEN that shipped code parses, or a STRUCTURAL frontmatter line. Guidance wording needs review, not a test, so any other class fails the test. Guards on non-Markdown files live in tests/phrase-manifest/source-text-guards.json.",
29
+ "The classes and the parser behind each token are in scripts/lib/phrase-tests/marker-classes.mjs; `node scripts/classify-phrase-tests.mjs --classify-manifest` classifies every entry.",
30
+ "First generated by scripts/generate-phrase-manifest.mjs from deleted phrase-only tests (CodySwannGT/lisa#4609), then pruned to its load-bearing entries; it is hand-maintained, so keep keys and arrays sorted.",
19
31
  "Patterns are RegExp { source, flags } and use String#match semantics. `source` lists the deleted tests each file's phrases came from, as `<test file> › <describe > it title>`.",
20
32
  ]);
21
33