@codyswann/lisa 5.2.0 → 5.2.2
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/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +31 -60
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/package.json +4 -5
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/skills/lisa-learnings-audit/SKILL.md +53 -10
- package/plugins/lisa/skills/lisa-learnings-audit/SKILL.md +53 -10
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-agy/skills/lisa-learnings-audit/SKILL.md +53 -10
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/skills/lisa-learnings-audit/SKILL.md +53 -10
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/skills/lisa-learnings-audit/SKILL.md +53 -10
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/skills/lisa-learnings-audit/SKILL.md +53 -10
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/src/base/skills/lisa-learnings-audit/SKILL.md +53 -10
- package/scripts/check-phrase-manifest-parity.mjs +6 -3
- package/scripts/classify-phrase-tests.mjs +109 -20
- package/scripts/fix-namespace-test-assertions.mjs +3 -20
- package/scripts/lib/phrase-tests/doc-taint.mjs +708 -0
- package/scripts/lib/phrase-tests/inventory.mjs +381 -0
- package/scripts/lib/phrase-tests/manifest.mjs +14 -2
- package/scripts/lib/phrase-tests/marker-classes.mjs +323 -0
- package/scripts/lib/phrase-tests/redact.mjs +88 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which Markdown phrase assertions are load-bearing (CodySwannGT/lisa#4867).
|
|
3
|
+
*
|
|
4
|
+
* A phrase pinned in a skill, rule, agent or command document is one of:
|
|
5
|
+
*
|
|
6
|
+
* - MACHINE-TOKEN — a marker whose exact spelling shipped code reads. The
|
|
7
|
+
* document carries it so an agent following the document writes it, and a
|
|
8
|
+
* script or hook then parses it. Rewording it breaks the parser, so a test
|
|
9
|
+
* must protect it. Every entry names the parser and its `needle`s, the
|
|
10
|
+
* literals that parser contains; `phrase-tests-marker-classes.test.ts`
|
|
11
|
+
* fails if a parser file stops containing a needle, so a row cannot
|
|
12
|
+
* outlive the code that justified it.
|
|
13
|
+
*
|
|
14
|
+
* Matching a row makes a phrase a token CANDIDATE, nothing more. A
|
|
15
|
+
* MACHINE-TOKEN pin belongs only in a document that must WRITE the token —
|
|
16
|
+
* one an agent follows to emit the marker the parser then reads. A
|
|
17
|
+
* document that merely names the token (a rule explaining it, an index
|
|
18
|
+
* listing it) does not need the pin: nothing breaks if it stops spelling
|
|
19
|
+
* it there.
|
|
20
|
+
* - STRUCTURAL — document shape that code reads: the frontmatter delimiter
|
|
21
|
+
* and a frontmatter key whose value is an identifier, not prose.
|
|
22
|
+
* - WORDING — everything else. Guidance prose needs review, not a test, and a
|
|
23
|
+
* marker that only agents or tests read is wording too: no parser breaks.
|
|
24
|
+
*
|
|
25
|
+
* Matching is deliberately narrow. A phrase is a token only when the WHOLE
|
|
26
|
+
* phrase is the token (with its argument where the token takes one): a
|
|
27
|
+
* sentence that merely mentions `[lisa-pr-link]` pins the sentence, so it is
|
|
28
|
+
* WORDING. A regular-expression phrase is first reduced to the literal it
|
|
29
|
+
* matches; a pattern with real regex syntax is matched against its source by
|
|
30
|
+
* `sourcePattern` when the row has one, and is WORDING otherwise. Every doubt
|
|
31
|
+
* resolves to WORDING.
|
|
32
|
+
*
|
|
33
|
+
* Markers considered and left out because no shipped code parses them (the
|
|
34
|
+
* only hits are comments, documents or tests): `[lisa-ledger-saturated]`,
|
|
35
|
+
* `[lisa-gardener]`, `[lisa-rejection-candidate]`, `[lisa-learning-drop]`,
|
|
36
|
+
* `[lisa-learning-pr]`, `[lisa-learning-upstream-handoff]`,
|
|
37
|
+
* `[lisa-repair-intake]`, `EVIDENCE-REF` (parse-plan.py deliberately does not
|
|
38
|
+
* match it), and `[lisa-project-ideation]` (the idempotency harness takes the
|
|
39
|
+
* marker as an argument rather than spelling it).
|
|
40
|
+
* @module scripts/lib/phrase-tests/marker-classes
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/** @typedef {"MACHINE-TOKEN" | "STRUCTURAL" | "WORDING"} PhraseClass */
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @typedef {object} TokenClass
|
|
47
|
+
* @property {string} id - Stable rule name, reported with each verdict.
|
|
48
|
+
* @property {"MACHINE-TOKEN" | "STRUCTURAL"} cls - The class it confers.
|
|
49
|
+
* @property {RegExp} pattern - Matches the WHOLE literal phrase.
|
|
50
|
+
* @property {RegExp} [sourcePattern] - Matches a regex phrase's source when
|
|
51
|
+
* the regex cannot be reduced to a literal.
|
|
52
|
+
* @property {readonly string[]} parser - Repository paths of the code that
|
|
53
|
+
* reads the token.
|
|
54
|
+
* @property {string | readonly string[]} needle - The literal(s) every
|
|
55
|
+
* parser file contains. A needle must be specific enough that losing it
|
|
56
|
+
* means the parser changed: a bare `---` or `description` proves nothing.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
const MACHINE_TOKEN = "MACHINE-TOKEN";
|
|
60
|
+
const STRUCTURAL = "STRUCTURAL";
|
|
61
|
+
|
|
62
|
+
/** Frontmatter keys the Codex command-to-skill transformer reads. */
|
|
63
|
+
const COMMAND_KEYS = "description|argument-hint|allowed-tools";
|
|
64
|
+
|
|
65
|
+
/** Frontmatter keys the Codex agent transformer reads. */
|
|
66
|
+
const AGENT_KEYS = "name|description|skills|model|tools";
|
|
67
|
+
|
|
68
|
+
const COMMAND_TRANSFORMER = "src/codex/command-skill-transformer.ts";
|
|
69
|
+
const AGENT_TRANSFORMER = "src/codex/agent-transformer.ts";
|
|
70
|
+
|
|
71
|
+
/** The frontmatter split both transformers apply, as it is spelled there. */
|
|
72
|
+
const FRONTMATTER_SPLIT = String.raw`/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/`;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* A STRUCTURAL row for frontmatter keys: the key, optionally followed by an
|
|
76
|
+
* identifier value (never prose), as a literal or as a regex source.
|
|
77
|
+
* @param {string} id - Row id.
|
|
78
|
+
* @param {string} keys - Alternation of key names.
|
|
79
|
+
* @param {string} parser - The transformer that reads them.
|
|
80
|
+
* @param {readonly string[]} needle - How that transformer reads them.
|
|
81
|
+
* @returns {TokenClass} The row.
|
|
82
|
+
*/
|
|
83
|
+
function frontmatterKeyRow(id, keys, parser, needle) {
|
|
84
|
+
return {
|
|
85
|
+
id,
|
|
86
|
+
cls: STRUCTURAL,
|
|
87
|
+
pattern: new RegExp(`^(?:${keys}):(?: [\\w@./:-]*)?$`, "u"),
|
|
88
|
+
sourcePattern: new RegExp(
|
|
89
|
+
String.raw`^\^(?:${keys}):(?:\\s[*+]| )?(?:\\S\+|\.\+|\.\*)?\$?$`,
|
|
90
|
+
"u"
|
|
91
|
+
),
|
|
92
|
+
parser: [parser],
|
|
93
|
+
needle,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
const WORK_ITEM_CLI = "all/copy-overwrite/scripts/lisa-work-item.mjs";
|
|
97
|
+
const DESIGN_SOURCE_GATE = "plugins/src/base/scripts/design-source-gate.mjs";
|
|
98
|
+
|
|
99
|
+
/** @type {readonly TokenClass[]} */
|
|
100
|
+
export const TOKEN_CLASSES = Object.freeze([
|
|
101
|
+
{
|
|
102
|
+
id: "lisa-pr-link",
|
|
103
|
+
cls: MACHINE_TOKEN,
|
|
104
|
+
pattern: /^\[lisa-pr-link\]$/u,
|
|
105
|
+
parser: [WORK_ITEM_CLI],
|
|
106
|
+
needle: "[lisa-pr-link]",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: "lisa-human-gate",
|
|
110
|
+
cls: MACHINE_TOKEN,
|
|
111
|
+
pattern: /^(?:<!-- )?\[lisa-human-gate\](?: reason=\S+)?(?: -->)?$/u,
|
|
112
|
+
parser: [
|
|
113
|
+
"all/copy-overwrite/scripts/lisa-hooks/block-direct-issue-create.sh",
|
|
114
|
+
],
|
|
115
|
+
needle: 'HUMAN_GATE_MARKER = "[lisa-human-gate]"',
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
id: "lisa-ci-failed",
|
|
119
|
+
cls: MACHINE_TOKEN,
|
|
120
|
+
pattern: /^(?:<!-- )?\[lisa-ci-failed\](?: run=\S+)?(?: -->)?$/u,
|
|
121
|
+
parser: ["scripts/lisa-ci-rework-route.mjs"],
|
|
122
|
+
needle: "[lisa-ci-failed]",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: "lisa-ci-cleared",
|
|
126
|
+
cls: MACHINE_TOKEN,
|
|
127
|
+
pattern: /^(?:<!-- )?\[lisa-ci-cleared\](?: run=\S+)?(?: -->)?$/u,
|
|
128
|
+
parser: ["scripts/lisa-ci-failure-redispatch.mjs"],
|
|
129
|
+
needle: "lisa-ci-cleared",
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
id: "lisa-tracker-claim",
|
|
133
|
+
cls: MACHINE_TOKEN,
|
|
134
|
+
pattern: /^\[lisa-tracker-claim\]$/u,
|
|
135
|
+
parser: ["scripts/lisa-ci-failure-redispatch.mjs"],
|
|
136
|
+
needle: "lisa-tracker-claim",
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: "lisa-auto-merge-off",
|
|
140
|
+
cls: MACHINE_TOKEN,
|
|
141
|
+
pattern: /^(?:<!-- )?\[lisa-auto-merge-off\](?: -->)?$/u,
|
|
142
|
+
parser: ["plugins/src/base/scripts/pr-arming-sweep.mjs"],
|
|
143
|
+
needle: '"[lisa-auto-merge-off]"',
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
id: "lisa-qa-queue",
|
|
147
|
+
cls: MACHINE_TOKEN,
|
|
148
|
+
pattern: /^\[lisa-qa-queue\](?: QA (?:pass|fail))?$/u,
|
|
149
|
+
parser: ["plugins/src/base/scripts/qa-signal-lifecycle.mjs"],
|
|
150
|
+
needle: "lisa-qa-queue",
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
id: "lisa-upstream-attribution",
|
|
154
|
+
cls: MACHINE_TOKEN,
|
|
155
|
+
pattern:
|
|
156
|
+
/^(?:<!-- )?\[lisa-upstream-attribution(?:-occurrence)?\](?: key=\S*)?(?: -->)?$/u,
|
|
157
|
+
parser: ["src/core/upstream-attribution-body.ts"],
|
|
158
|
+
needle: "[lisa-upstream-attribution",
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
id: "lisa-completion-authorization",
|
|
162
|
+
cls: MACHINE_TOKEN,
|
|
163
|
+
pattern: /^\[lisa-completion-authorization\]$/u,
|
|
164
|
+
parser: ["all/copy-overwrite/scripts/lib/completion-authorization.mjs"],
|
|
165
|
+
needle: "[lisa-completion-authorization]",
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
id: "lisa-npm-checkpoint",
|
|
169
|
+
cls: MACHINE_TOKEN,
|
|
170
|
+
pattern: /^\[lisa-npm-checkpoint\]$/u,
|
|
171
|
+
parser: ["all/copy-overwrite/scripts/lib/npm-update-checkpoint.mjs"],
|
|
172
|
+
needle: "[lisa-npm-checkpoint]",
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
id: "lisa-npm-filing",
|
|
176
|
+
cls: MACHINE_TOKEN,
|
|
177
|
+
pattern: /^(?:<!-- )?\[lisa-npm-(?:filing|proposal)\]$/u,
|
|
178
|
+
parser: ["all/copy-overwrite/scripts/lib/npm-update-leaf-contract.mjs"],
|
|
179
|
+
needle: ["<!-- [lisa-npm-filing] ", "<!-- [lisa-npm-proposal] "],
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
id: "work-item-trailer",
|
|
183
|
+
cls: MACHINE_TOKEN,
|
|
184
|
+
pattern: /^Work-Item:(?: \S+)?$/u,
|
|
185
|
+
parser: [WORK_ITEM_CLI],
|
|
186
|
+
needle: "Work-Item:",
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
id: "lisa-usage-heading",
|
|
190
|
+
cls: MACHINE_TOKEN,
|
|
191
|
+
pattern: /^## Lisa Usage$/u,
|
|
192
|
+
parser: ["all/copy-overwrite/scripts/lib/usage-ledger.mjs"],
|
|
193
|
+
needle: '"## Lisa Usage"',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
id: "lisa-usage-token",
|
|
197
|
+
cls: MACHINE_TOKEN,
|
|
198
|
+
pattern:
|
|
199
|
+
/^<!-- lisa:usage-(?:entry|entry-measured-subset|rollup)\b[^\n]*$/u,
|
|
200
|
+
parser: ["src/utils/usage-accounting.ts"],
|
|
201
|
+
needle: "<!-- lisa:usage-entry",
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
id: "lisa-learnings-contract",
|
|
205
|
+
cls: MACHINE_TOKEN,
|
|
206
|
+
pattern: /^<!-- lisa-learnings-contract:v\d+(?: -->)?$/u,
|
|
207
|
+
parser: ["src/core/learnings-document.ts"],
|
|
208
|
+
needle: "<!-- lisa-learnings-contract:v",
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: "lisa-review-substitute",
|
|
212
|
+
cls: MACHINE_TOKEN,
|
|
213
|
+
pattern: /^<!-- lisa:review-substitute\b[^\n]*$/u,
|
|
214
|
+
parser: [
|
|
215
|
+
"all/copy-overwrite/scripts/check-third-party-review-evidence.mjs",
|
|
216
|
+
],
|
|
217
|
+
needle: '"lisa:review-substitute"',
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
id: "design-source-none",
|
|
221
|
+
cls: MACHINE_TOKEN,
|
|
222
|
+
pattern:
|
|
223
|
+
/^(?:<!-- )?DESIGN-SOURCE: none — not in Figma(?: — [^\n]+?)?(?: -->)?$/u,
|
|
224
|
+
parser: [DESIGN_SOURCE_GATE],
|
|
225
|
+
needle: 'DESIGN_SOURCE_NONE_MARKER = "DESIGN-SOURCE: none — not in Figma"',
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
id: "design-source-figma",
|
|
229
|
+
cls: MACHINE_TOKEN,
|
|
230
|
+
pattern:
|
|
231
|
+
/^(?:<!-- )?DESIGN-SOURCE:(?: (?:<figma-url>|https:\/\/(?:[\w-]+\.)*figma\.com\/\S+))?(?: -->)?$/u,
|
|
232
|
+
parser: [DESIGN_SOURCE_GATE],
|
|
233
|
+
needle: "const ANNOTATION = /DESIGN-SOURCE:",
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
id: "local-evidence-claim",
|
|
237
|
+
cls: MACHINE_TOKEN,
|
|
238
|
+
pattern: /^\[(?:EVIDENCE|SCREENSHOT): [^\]\n]+\]$/u,
|
|
239
|
+
parser: ["plugins/src/base/skills/lisa-jira-journey/scripts/parse-plan.py"],
|
|
240
|
+
needle: "(SCREENSHOT|EVIDENCE)",
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
id: "frontmatter-delimiter",
|
|
244
|
+
cls: STRUCTURAL,
|
|
245
|
+
pattern: /^---\n?$/u,
|
|
246
|
+
sourcePattern: /^\^---(?:\\n|\$|\\r\?\\n)?$/u,
|
|
247
|
+
parser: [COMMAND_TRANSFORMER, AGENT_TRANSFORMER],
|
|
248
|
+
needle: FRONTMATTER_SPLIT,
|
|
249
|
+
},
|
|
250
|
+
frontmatterKeyRow("frontmatter-key", COMMAND_KEYS, COMMAND_TRANSFORMER, [
|
|
251
|
+
"obj.description",
|
|
252
|
+
'obj["argument-hint"]',
|
|
253
|
+
'obj["allowed-tools"]',
|
|
254
|
+
]),
|
|
255
|
+
frontmatterKeyRow("frontmatter-agent-key", AGENT_KEYS, AGENT_TRANSFORMER, [
|
|
256
|
+
"frontmatter.name",
|
|
257
|
+
"frontmatter.description",
|
|
258
|
+
"frontmatter.skills",
|
|
259
|
+
"frontmatter.model",
|
|
260
|
+
"frontmatter.tools",
|
|
261
|
+
]),
|
|
262
|
+
]);
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* The needles of a row as a list.
|
|
266
|
+
* @param {TokenClass} row - A row.
|
|
267
|
+
* @returns {readonly string[]} Its needles.
|
|
268
|
+
*/
|
|
269
|
+
export function needlesOf(row) {
|
|
270
|
+
return typeof row.needle === "string" ? [row.needle] : row.needle;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Regex metacharacters that make a source more than a literal. */
|
|
274
|
+
const METACHARACTERS = new Set("[](){}*+?|^$.");
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Reduce a regular-expression source to the literal string it matches, when
|
|
278
|
+
* it matches exactly one: escapes of punctuation are unescaped, and a leading
|
|
279
|
+
* `^` / trailing `$` anchor is dropped. Any other syntax returns undefined.
|
|
280
|
+
* @param {string} source - A RegExp source.
|
|
281
|
+
* @returns {string | undefined} The literal, or undefined.
|
|
282
|
+
*/
|
|
283
|
+
export function literalOf(source) {
|
|
284
|
+
const body = source.replace(/^\^/u, "").replace(/(?<!\\)\$$/u, "");
|
|
285
|
+
let literal = "";
|
|
286
|
+
for (let index = 0; index < body.length; index += 1) {
|
|
287
|
+
const char = body[index];
|
|
288
|
+
if (char === "\\") {
|
|
289
|
+
const next = body[index + 1];
|
|
290
|
+
if (next === undefined || /[A-Za-z0-9]/u.test(next)) return undefined;
|
|
291
|
+
literal += next;
|
|
292
|
+
index += 1;
|
|
293
|
+
} else if (METACHARACTERS.has(char)) {
|
|
294
|
+
return undefined;
|
|
295
|
+
} else {
|
|
296
|
+
literal += char;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return literal;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Classify one pinned phrase.
|
|
304
|
+
* @param {string} phrase - A literal phrase, or a RegExp source when
|
|
305
|
+
* `isPattern` is set.
|
|
306
|
+
* @param {{ isPattern?: boolean }} [options] - Whether `phrase` is a source.
|
|
307
|
+
* @returns {{ cls: PhraseClass, rule: string, parser: readonly string[] }}
|
|
308
|
+
* The class, the rule that decided it, and the parser that reads it.
|
|
309
|
+
*/
|
|
310
|
+
export function classifyPhrase(phrase, { isPattern = false } = {}) {
|
|
311
|
+
const literal = isPattern ? literalOf(phrase) : phrase;
|
|
312
|
+
const row = TOKEN_CLASSES.find(candidate =>
|
|
313
|
+
literal === undefined
|
|
314
|
+
? candidate.sourcePattern?.test(phrase) === true
|
|
315
|
+
: candidate.pattern.test(literal.trim())
|
|
316
|
+
);
|
|
317
|
+
if (row) return { cls: row.cls, rule: row.id, parser: row.parser };
|
|
318
|
+
return {
|
|
319
|
+
cls: "WORDING",
|
|
320
|
+
rule: literal === undefined ? "regex-prose" : "prose",
|
|
321
|
+
parser: [],
|
|
322
|
+
};
|
|
323
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Redact credential-shaped literals from classifier output
|
|
3
|
+
* (CodySwannGT/lisa#4867).
|
|
4
|
+
*
|
|
5
|
+
* The classifier copies assertion arguments verbatim into its reports, and
|
|
6
|
+
* some test fixtures are fake secrets. A fake secret committed as evidence
|
|
7
|
+
* still trips secret scanners, and a real one would leak, so every string in
|
|
8
|
+
* a report passes through here before it is printed.
|
|
9
|
+
*
|
|
10
|
+
* The placeholders follow the `[REDACTED:<KIND>]` vocabulary of
|
|
11
|
+
* `plugins/src/wiki/scripts/wiki-safety.mjs`. That module's patterns are
|
|
12
|
+
* anchored on a key name (`api_key = …`), so they miss a bare token such as a
|
|
13
|
+
* Stripe key standing alone in a string; these patterns match token shapes.
|
|
14
|
+
* @module scripts/lib/phrase-tests/redact
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** @typedef {{ kind: string, re: RegExp, replace?: string }} SecretShape */
|
|
18
|
+
|
|
19
|
+
/** @type {readonly SecretShape[]} */
|
|
20
|
+
export const SECRET_SHAPES = Object.freeze([
|
|
21
|
+
{
|
|
22
|
+
kind: "PRIVATE_KEY",
|
|
23
|
+
re: /-----BEGIN (?:[A-Z]+ )*PRIVATE KEY-----(?:[\s\S]*?-----END (?:[A-Z]+ )*PRIVATE KEY-----)?/gu,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
kind: "URL_CREDENTIALS",
|
|
27
|
+
re: /\b([a-z][a-z0-9+.-]*:\/\/)[^\s/:@]+:[^\s/@]+@/giu,
|
|
28
|
+
replace: "$1[REDACTED:URL_CREDENTIALS]@",
|
|
29
|
+
},
|
|
30
|
+
{ kind: "API_KEY", re: /\b(?:sk|pk|rk)_(?:live|test)_[A-Za-z0-9]{8,}/gu },
|
|
31
|
+
{
|
|
32
|
+
kind: "GITHUB_TOKEN",
|
|
33
|
+
re: /\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_\w{20,})/gu,
|
|
34
|
+
},
|
|
35
|
+
{ kind: "AWS_ACCESS_KEY", re: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/gu },
|
|
36
|
+
{ kind: "SLACK_TOKEN", re: /\bxox[abposr]-[A-Za-z0-9-]{10,}/gu },
|
|
37
|
+
{
|
|
38
|
+
kind: "JWT",
|
|
39
|
+
re: /\beyJ[A-Za-z0-9_-]{8,}(?:\.[A-Za-z0-9_-]+){0,2}/gu,
|
|
40
|
+
},
|
|
41
|
+
{ kind: "OAUTH_TOKEN", re: /\bya29\.[\w.-]{10,}/gu },
|
|
42
|
+
{ kind: "GOOGLE_API_KEY", re: /\bAIza[\w-]{20,}/gu },
|
|
43
|
+
{ kind: "GITLAB_TOKEN", re: /\bglpat-[\w-]{16,}/gu },
|
|
44
|
+
{ kind: "NPM_TOKEN", re: /\bnpm_[A-Za-z0-9]{10,}/gu },
|
|
45
|
+
{ kind: "SHOPIFY_TOKEN", re: /\bshpat_[A-Za-z0-9]{16,}/gu },
|
|
46
|
+
{ kind: "SENDGRID_KEY", re: /\bSG\.[\w-]{10,}(?:\.[\w-]+)?/gu },
|
|
47
|
+
{ kind: "HUGGINGFACE_TOKEN", re: /\bhf_[A-Za-z0-9]{20,}/gu },
|
|
48
|
+
{ kind: "API_KEY", re: /\bsk-(?:ant|proj)-[\w-]{10,}/gu },
|
|
49
|
+
{ kind: "DIGITALOCEAN_TOKEN", re: /\bdop_v1_[A-Za-z0-9]{16,}/gu },
|
|
50
|
+
{ kind: "PYPI_TOKEN", re: /\bpypi-[\w-]{16,}/gu },
|
|
51
|
+
]);
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Replace every credential-shaped run in a string.
|
|
55
|
+
* @param {string} text - Any string.
|
|
56
|
+
* @returns {string} The string with each secret replaced by its placeholder.
|
|
57
|
+
*/
|
|
58
|
+
export function redactText(text) {
|
|
59
|
+
return SECRET_SHAPES.reduce(
|
|
60
|
+
(current, shape) =>
|
|
61
|
+
current.replace(shape.re, shape.replace ?? `[REDACTED:${shape.kind}]`),
|
|
62
|
+
text
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Redact every string inside a JSON-shaped value, keys included.
|
|
68
|
+
* @template T
|
|
69
|
+
* @param {T} value - A report, or any part of one.
|
|
70
|
+
* @returns {T} A copy with every string redacted.
|
|
71
|
+
*/
|
|
72
|
+
export function redactDeep(value) {
|
|
73
|
+
if (typeof value === "string") return /** @type {T} */ (redactText(value));
|
|
74
|
+
if (Array.isArray(value)) {
|
|
75
|
+
return /** @type {T} */ (value.map(item => redactDeep(item)));
|
|
76
|
+
}
|
|
77
|
+
if (value !== null && typeof value === "object") {
|
|
78
|
+
return /** @type {T} */ (
|
|
79
|
+
Object.fromEntries(
|
|
80
|
+
Object.entries(value).map(([key, item]) => [
|
|
81
|
+
redactText(key),
|
|
82
|
+
redactDeep(item),
|
|
83
|
+
])
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
return value;
|
|
88
|
+
}
|