@ryuenn3123/agentic-senior-core 4.3.15 → 5.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.
- package/.agents/plugins/marketplace.json +21 -0
- package/.agents/rules/agentic-senior-core.md +126 -0
- package/.claude-plugin/marketplace.json +17 -0
- package/.claude-plugin/plugin.json +17 -0
- package/.clinerules/agentic-senior-core.md +94 -0
- package/.codex-plugin/plugin.json +24 -0
- package/.cursor/rules/agentic-senior-core.mdc +99 -0
- package/.devin-plugin/plugin.json +13 -0
- package/.github/copilot-instructions.md +94 -0
- package/.github/plugin/marketplace.json +20 -0
- package/.github/plugin/plugin.json +16 -0
- package/.kiro/steering/agentic-senior-core.md +94 -0
- package/.openclaw/skills/asc/SKILL.md +23 -0
- package/.openclaw/skills/asc-audit/SKILL.md +28 -0
- package/.openclaw/skills/asc-review/SKILL.md +54 -0
- package/.opencode/plugins/agentic-senior-core.mjs +31 -0
- package/.windsurf/rules/agentic-senior-core.md +94 -0
- package/AGENTS.md +126 -179
- package/CONTRIBUTING.md +93 -63
- package/README.md +160 -111
- package/__init__.py +61 -0
- package/bin/agentic-senior-core.js +41 -43
- package/commands/asc-audit.md +1 -0
- package/commands/asc-audit.toml +2 -0
- package/commands/asc-help.md +9 -0
- package/commands/asc-help.toml +2 -0
- package/commands/asc-refactor.md +1 -0
- package/commands/asc-refactor.toml +2 -0
- package/commands/asc-review.md +1 -0
- package/commands/asc-review.toml +2 -0
- package/gemini-extension.json +10 -0
- package/hooks/copilot-hooks.json +21 -0
- package/hooks/hooks.json +31 -0
- package/hooks/session-start.js +36 -0
- package/hooks/subagent-start.js +38 -0
- package/lib/cli/commands/adapter.mjs +109 -0
- package/lib/cli/commands/clean.mjs +63 -0
- package/lib/cli/commands/status.mjs +94 -0
- package/package.json +43 -67
- package/plugin.yaml +16 -0
- package/scripts/uninstall.js +38 -0
- package/skills/asc/SKILL.md +16 -0
- package/skills/asc-audit/SKILL.md +28 -0
- package/skills/asc-refactor/SKILL.md +35 -0
- package/skills/asc-review/SKILL.md +54 -0
- package/.agent-context/policies/llm-judge-threshold.json +0 -29
- package/.agent-context/prompts/bootstrap-design.md +0 -63
- package/.agent-context/prompts/compact-natural-mode.md +0 -100
- package/.agent-context/prompts/init-project.md +0 -60
- package/.agent-context/prompts/refactor.md +0 -38
- package/.agent-context/prompts/review-code.md +0 -31
- package/.agent-context/review-checklists/architecture-review.md +0 -57
- package/.agent-context/review-checklists/pr-checklist.md +0 -136
- package/.agent-context/rules/api-docs.md +0 -24
- package/.agent-context/rules/api-versioning.md +0 -16
- package/.agent-context/rules/architecture.md +0 -33
- package/.agent-context/rules/background-jobs.md +0 -17
- package/.agent-context/rules/config-and-flags.md +0 -16
- package/.agent-context/rules/database-design.md +0 -18
- package/.agent-context/rules/docker-runtime.md +0 -17
- package/.agent-context/rules/error-handling.md +0 -16
- package/.agent-context/rules/event-driven.md +0 -16
- package/.agent-context/rules/frontend-architecture.md +0 -54
- package/.agent-context/rules/microservices.md +0 -16
- package/.agent-context/rules/migrations.md +0 -16
- package/.agent-context/rules/observability.md +0 -16
- package/.agent-context/rules/performance.md +0 -16
- package/.agent-context/rules/realtime.md +0 -16
- package/.agent-context/rules/resilience.md +0 -18
- package/.agent-context/rules/security.md +0 -18
- package/.agent-context/rules/testing.md +0 -16
- package/.agent-context/state/README.md +0 -25
- package/.agent-context/state/architecture-map.md +0 -40
- package/.agent-context/state/benchmark-comparison-schema.json +0 -181
- package/.agent-context/state/benchmark-reproducibility.json +0 -87
- package/.agent-context/state/benchmark-thresholds.json +0 -10
- package/.agent-context/state/benchmark-writer-judge-config.json +0 -58
- package/.agent-context/state/dependency-map.md +0 -41
- package/.agent-context/state/memory-adapter-contract.json +0 -52
- package/.agent-context/state/memory-schema-v1.json +0 -88
- package/GEMINI.md +0 -1
- package/benchmarks/README.md +0 -60
- package/benchmarks/compact-natural-mode/fixtures.mjs +0 -359
- package/benchmarks/compact-natural-mode/scorer.mjs +0 -331
- package/benchmarks/runtime-token-saver/fixtures.mjs +0 -836
- package/lib/cli/adaptive-context/catalog.mjs +0 -390
- package/lib/cli/adaptive-context/file-signals.mjs +0 -100
- package/lib/cli/adaptive-context/implications.mjs +0 -44
- package/lib/cli/adaptive-context.mjs +0 -365
- package/lib/cli/audits/typography-palette-anti-repeat/color-utils.mjs +0 -156
- package/lib/cli/audits/typography-palette-anti-repeat/file-scanner.mjs +0 -103
- package/lib/cli/audits/typography-palette-anti-repeat/typography-utils.mjs +0 -70
- package/lib/cli/audits/typography-palette-anti-repeat-audit.mjs +0 -239
- package/lib/cli/backup.mjs +0 -210
- package/lib/cli/commands/audit-design-anti-repeat.mjs +0 -39
- package/lib/cli/commands/context.mjs +0 -140
- package/lib/cli/commands/init/project-context.mjs +0 -60
- package/lib/cli/commands/init/runtime-environment.mjs +0 -59
- package/lib/cli/commands/init/setup-decisions.mjs +0 -83
- package/lib/cli/commands/init.mjs +0 -654
- package/lib/cli/commands/launch.mjs +0 -76
- package/lib/cli/commands/optimize.mjs +0 -284
- package/lib/cli/commands/rollback.mjs +0 -64
- package/lib/cli/commands/upgrade/token-optimization-state.mjs +0 -51
- package/lib/cli/commands/upgrade.mjs +0 -451
- package/lib/cli/compiler.mjs +0 -570
- package/lib/cli/constants.mjs +0 -136
- package/lib/cli/detector/constants.mjs +0 -135
- package/lib/cli/detector/design-evidence/collector.mjs +0 -256
- package/lib/cli/detector/design-evidence/constants.mjs +0 -39
- package/lib/cli/detector/design-evidence/file-traversal.mjs +0 -83
- package/lib/cli/detector/design-evidence/structured-attribute-evidence.mjs +0 -117
- package/lib/cli/detector/design-evidence/summary.mjs +0 -109
- package/lib/cli/detector/design-evidence/utility-helpers.mjs +0 -122
- package/lib/cli/detector/design-evidence.mjs +0 -25
- package/lib/cli/detector/stack-detection.mjs +0 -243
- package/lib/cli/detector/ui-signals.mjs +0 -150
- package/lib/cli/detector/workspace-scan.mjs +0 -177
- package/lib/cli/detector.mjs +0 -23
- package/lib/cli/init-detection-flow.mjs +0 -48
- package/lib/cli/init-options.mjs +0 -237
- package/lib/cli/init-selection.mjs +0 -29
- package/lib/cli/memory-continuity.mjs +0 -537
- package/lib/cli/preflight.mjs +0 -76
- package/lib/cli/project-scaffolder/constants.mjs +0 -69
- package/lib/cli/project-scaffolder/discovery.mjs +0 -272
- package/lib/cli/project-scaffolder/prompt-builders.mjs +0 -171
- package/lib/cli/project-scaffolder/storage.mjs +0 -144
- package/lib/cli/project-scaffolder/ui-scope-detection.mjs +0 -36
- package/lib/cli/project-scaffolder.mjs +0 -29
- package/lib/cli/rollback.mjs +0 -66
- package/lib/cli/token-optimization.mjs +0 -486
- package/lib/cli/utils/filesystem.mjs +0 -81
- package/lib/cli/utils/managed-surface.mjs +0 -280
- package/lib/cli/utils/prompting.mjs +0 -44
- package/lib/cli/utils.mjs +0 -479
- package/mcp.json +0 -134
- package/scripts/adaptive-context/fixtures.mjs +0 -183
- package/scripts/adaptive-context-benchmark.mjs +0 -9
- package/scripts/ascx-runtime-token-saver-benchmark.mjs +0 -9
- package/scripts/audit-cache-layer-contract.mjs +0 -263
- package/scripts/audit-caching-scope-hygiene.mjs +0 -268
- package/scripts/audit-file-size.mjs +0 -219
- package/scripts/audit-reflection-citations.mjs +0 -163
- package/scripts/audit-release-bundle.mjs +0 -170
- package/scripts/audit-rule-id-uniqueness.mjs +0 -313
- package/scripts/audit-typography-palette-anti-repeat.mjs +0 -120
- package/scripts/benchmark-evidence-bundle.mjs +0 -645
- package/scripts/benchmark-gate.mjs +0 -121
- package/scripts/benchmark-intelligence.mjs +0 -33
- package/scripts/benchmark-writer-judge-matrix.mjs +0 -379
- package/scripts/build-release-benchmark-bundle.mjs +0 -202
- package/scripts/bump-version.mjs +0 -103
- package/scripts/clean-local-artifacts.mjs +0 -78
- package/scripts/compact-natural-mode-benchmark.mjs +0 -9
- package/scripts/context-triggered-audit.mjs +0 -391
- package/scripts/detection-benchmark.mjs +0 -127
- package/scripts/docs-quality-drift-report.mjs +0 -358
- package/scripts/documentation-boundary-audit.mjs +0 -305
- package/scripts/explain-on-demand-audit.mjs +0 -427
- package/scripts/forbidden-content-check.mjs +0 -123
- package/scripts/frontend-usability-audit.mjs +0 -243
- package/scripts/generate-sbom.mjs +0 -61
- package/scripts/governance-weekly-report.mjs +0 -466
- package/scripts/llm-judge/checklist-loader.mjs +0 -45
- package/scripts/llm-judge/constants.mjs +0 -66
- package/scripts/llm-judge/diff-collection.mjs +0 -74
- package/scripts/llm-judge/prompting.mjs +0 -78
- package/scripts/llm-judge/providers.mjs +0 -111
- package/scripts/llm-judge/verdict.mjs +0 -134
- package/scripts/llm-judge.mjs +0 -200
- package/scripts/memory-continuity-benchmark.mjs +0 -322
- package/scripts/quality-trend-report.mjs +0 -289
- package/scripts/release-gate/audit-checks.mjs +0 -441
- package/scripts/release-gate/constants.mjs +0 -53
- package/scripts/release-gate/runtime.mjs +0 -63
- package/scripts/release-gate/static-checks.mjs +0 -182
- package/scripts/release-gate.mjs +0 -42
- package/scripts/rules-guardian-audit.mjs +0 -580
- package/scripts/single-source-lazy-loading-audit.mjs +0 -449
- package/scripts/sync-thin-adapters.mjs +0 -72
- package/scripts/token-optimization-benchmark.mjs +0 -252
- package/scripts/ui-design-judge/constants.mjs +0 -13
- package/scripts/ui-design-judge/design-execution-summary.mjs +0 -81
- package/scripts/ui-design-judge/git-input.mjs +0 -134
- package/scripts/ui-design-judge/prompting.mjs +0 -52
- package/scripts/ui-design-judge/providers.mjs +0 -102
- package/scripts/ui-design-judge/reporting.mjs +0 -183
- package/scripts/ui-design-judge/rubric-calibration.mjs +0 -214
- package/scripts/ui-design-judge/rubric-goldset.json +0 -188
- package/scripts/ui-design-judge.mjs +0 -319
- package/scripts/ui-rubric-calibration.mjs +0 -35
- package/scripts/validate/config.mjs +0 -519
- package/scripts/validate/coverage-checks.mjs +0 -446
- package/scripts/validate/file-structure.mjs +0 -162
- package/scripts/validate/markdown-content.mjs +0 -109
- package/scripts/validate/project-metadata.mjs +0 -166
- package/scripts/validate.mjs +0 -338
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DOCS_BY_LABEL,
|
|
3
|
-
PROMPT_CATALOG,
|
|
4
|
-
RULE_FAMILY_CATALOG,
|
|
5
|
-
STATE_BY_LABEL,
|
|
6
|
-
} from './adaptive-context/catalog.mjs';
|
|
7
|
-
import { CONTEXT_FILE_CATALOG } from './adaptive-context/file-signals.mjs';
|
|
8
|
-
import { IMPLICATION_CATALOG } from './adaptive-context/implications.mjs';
|
|
9
|
-
|
|
10
|
-
const CONTEXT_BUDGET_POLICY = Object.freeze({
|
|
11
|
-
maxRecommendedRuleCount: 5,
|
|
12
|
-
maxFallbackRuleCount: 7,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export function getRuleFamilyCatalog() {
|
|
16
|
-
return RULE_FAMILY_CATALOG.map((ruleFamily) => ({ ...ruleFamily }));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function normalizeRequestText(requestText) {
|
|
20
|
-
return String(requestText || '')
|
|
21
|
-
.trim()
|
|
22
|
-
.toLowerCase()
|
|
23
|
-
.replace(/\s+/g, ' ');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function findMatchedTriggers(normalizedRequestText, triggers) {
|
|
27
|
-
return triggers.filter((triggerText) => triggerMatchesRequest(normalizedRequestText, triggerText));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function escapeRegExp(rawText) {
|
|
31
|
-
return rawText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function triggerMatchesRequest(normalizedRequestText, triggerText) {
|
|
35
|
-
if (!normalizedRequestText || !triggerText) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (/^[a-z0-9 ]+$/.test(triggerText)) {
|
|
40
|
-
const triggerPattern = new RegExp(`(^|[^a-z0-9])${escapeRegExp(triggerText)}([^a-z0-9]|$)`);
|
|
41
|
-
return triggerPattern.test(normalizedRequestText);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return normalizedRequestText.includes(triggerText);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function compareCatalogEntries(leftEntry, rightEntry) {
|
|
48
|
-
return leftEntry.priority - rightEntry.priority || leftEntry.label.localeCompare(rightEntry.label);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function normalizeContextFilePath(contextFilePath) {
|
|
52
|
-
return String(contextFilePath || '')
|
|
53
|
-
.trim()
|
|
54
|
-
.replace(/\\/g, '/')
|
|
55
|
-
.replace(/\/+/g, '/')
|
|
56
|
-
.toLowerCase();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function normalizeContextFiles(contextFiles) {
|
|
60
|
-
if (!Array.isArray(contextFiles)) {
|
|
61
|
-
return [];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return contextFiles
|
|
65
|
-
.map(normalizeContextFilePath)
|
|
66
|
-
.filter(Boolean);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function uniqueSortedValues(values) {
|
|
70
|
-
return Array.from(new Set(values)).sort((leftValue, rightValue) => leftValue.localeCompare(rightValue));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function collectDocsForLabels(labels) {
|
|
74
|
-
const selectedDocs = ['docs/doc-index.md'];
|
|
75
|
-
|
|
76
|
-
for (const label of labels) {
|
|
77
|
-
selectedDocs.push(...(DOCS_BY_LABEL[label] || []));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return uniqueSortedValues(selectedDocs);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function collectStateForLabels(labels) {
|
|
84
|
-
const selectedState = ['.agent-context/state/onboarding-report.json'];
|
|
85
|
-
|
|
86
|
-
for (const label of labels) {
|
|
87
|
-
selectedState.push(...(STATE_BY_LABEL[label] || []));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return uniqueSortedValues(selectedState);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function collectPromptsForRequest(normalizedRequestText, labels) {
|
|
94
|
-
const selectedPrompts = [];
|
|
95
|
-
|
|
96
|
-
for (const promptEntry of PROMPT_CATALOG) {
|
|
97
|
-
const labelMatched = Array.isArray(promptEntry.labels)
|
|
98
|
-
&& promptEntry.labels.some((label) => labels.includes(label));
|
|
99
|
-
const triggerMatched = findMatchedTriggers(normalizedRequestText, promptEntry.triggers).length > 0;
|
|
100
|
-
|
|
101
|
-
if (labelMatched || triggerMatched) {
|
|
102
|
-
selectedPrompts.push(promptEntry.promptPath);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return uniqueSortedValues(selectedPrompts);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function createRuleEntryMap() {
|
|
110
|
-
const ruleEntryMap = new Map();
|
|
111
|
-
|
|
112
|
-
for (const ruleFamily of RULE_FAMILY_CATALOG) {
|
|
113
|
-
ruleEntryMap.set(ruleFamily.label, {
|
|
114
|
-
...ruleFamily,
|
|
115
|
-
matchedTriggers: [],
|
|
116
|
-
matchedFiles: [],
|
|
117
|
-
matchedImplications: [],
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return ruleEntryMap;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function getMatchedRuleEntries(ruleEntryMap) {
|
|
125
|
-
return Array.from(ruleEntryMap.values())
|
|
126
|
-
.filter((ruleFamily) => {
|
|
127
|
-
return ruleFamily.matchedTriggers.length > 0
|
|
128
|
-
|| ruleFamily.matchedFiles.length > 0
|
|
129
|
-
|| ruleFamily.matchedImplications.length > 0;
|
|
130
|
-
})
|
|
131
|
-
.sort(compareCatalogEntries);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function pushUniqueSignal(values, nextValue) {
|
|
135
|
-
if (nextValue && !values.includes(nextValue)) {
|
|
136
|
-
values.push(nextValue);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function applyDirectTextSignals(ruleEntryMap, normalizedRequestText) {
|
|
141
|
-
for (const ruleFamily of RULE_FAMILY_CATALOG) {
|
|
142
|
-
const matchedTriggers = findMatchedTriggers(normalizedRequestText, ruleFamily.triggers);
|
|
143
|
-
const targetRuleEntry = ruleEntryMap.get(ruleFamily.label);
|
|
144
|
-
|
|
145
|
-
for (const matchedTrigger of matchedTriggers) {
|
|
146
|
-
pushUniqueSignal(targetRuleEntry.matchedTriggers, matchedTrigger);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function applyContextFileSignals(ruleEntryMap, normalizedContextFiles) {
|
|
152
|
-
for (const contextFilePath of normalizedContextFiles) {
|
|
153
|
-
for (const fileSignal of CONTEXT_FILE_CATALOG) {
|
|
154
|
-
if (!fileSignal.patterns.some((filePattern) => filePattern.test(contextFilePath))) {
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const targetRuleEntry = ruleEntryMap.get(fileSignal.label);
|
|
159
|
-
pushUniqueSignal(targetRuleEntry.matchedFiles, contextFilePath);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function applyImplicationSignals(ruleEntryMap, normalizedRequestText) {
|
|
165
|
-
const matchedLabelSet = new Set(getMatchedRuleEntries(ruleEntryMap).map((ruleFamily) => ruleFamily.label));
|
|
166
|
-
|
|
167
|
-
for (const implicationRule of IMPLICATION_CATALOG) {
|
|
168
|
-
const hasRequiredLabel = implicationRule.requiresAnyLabel.some((label) => matchedLabelSet.has(label));
|
|
169
|
-
if (!hasRequiredLabel) {
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const matchedTriggers = findMatchedTriggers(normalizedRequestText, implicationRule.triggers);
|
|
174
|
-
if (matchedTriggers.length === 0) {
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const targetRuleEntry = ruleEntryMap.get(implicationRule.label);
|
|
179
|
-
const implicationDetail = `${implicationRule.reason}: ${matchedTriggers.join(', ')}`;
|
|
180
|
-
pushUniqueSignal(targetRuleEntry.matchedImplications, implicationDetail);
|
|
181
|
-
matchedLabelSet.add(implicationRule.label);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function countEvidenceSignals(evidenceEntry) {
|
|
186
|
-
return evidenceEntry.matchedTriggers.length
|
|
187
|
-
+ evidenceEntry.matchedFiles.length
|
|
188
|
-
+ evidenceEntry.matchedImplications.length;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function resolveUncertainty(labels, evidenceEntries, normalizedRequestText) {
|
|
192
|
-
if (!normalizedRequestText) {
|
|
193
|
-
return 'high';
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
if (labels.length === 0) {
|
|
197
|
-
return 'high';
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const hasSparseEvidence = evidenceEntries.some((evidenceEntry) => countEvidenceSignals(evidenceEntry) === 1);
|
|
201
|
-
const hasManyLabels = labels.length >= 6;
|
|
202
|
-
|
|
203
|
-
if (hasManyLabels || hasSparseEvidence) {
|
|
204
|
-
return 'medium';
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return 'low';
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function buildContextBudget(labels, evidenceEntries) {
|
|
211
|
-
const selectedRuleCount = labels.length;
|
|
212
|
-
const evidenceSignalCount = evidenceEntries.reduce(
|
|
213
|
-
(totalCount, evidenceEntry) => totalCount + countEvidenceSignals(evidenceEntry),
|
|
214
|
-
0
|
|
215
|
-
);
|
|
216
|
-
const overRecommendedRuleCount = Math.max(
|
|
217
|
-
0,
|
|
218
|
-
selectedRuleCount - CONTEXT_BUDGET_POLICY.maxRecommendedRuleCount
|
|
219
|
-
);
|
|
220
|
-
const overFallbackRuleCount = Math.max(
|
|
221
|
-
0,
|
|
222
|
-
selectedRuleCount - CONTEXT_BUDGET_POLICY.maxFallbackRuleCount
|
|
223
|
-
);
|
|
224
|
-
let status = 'within-budget';
|
|
225
|
-
|
|
226
|
-
if (overFallbackRuleCount > 0) {
|
|
227
|
-
status = 'fallback-required';
|
|
228
|
-
} else if (overRecommendedRuleCount > 0) {
|
|
229
|
-
status = 'wide-context';
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return {
|
|
233
|
-
status,
|
|
234
|
-
selectedRuleCount,
|
|
235
|
-
evidenceSignalCount,
|
|
236
|
-
maxRecommendedRuleCount: CONTEXT_BUDGET_POLICY.maxRecommendedRuleCount,
|
|
237
|
-
maxFallbackRuleCount: CONTEXT_BUDGET_POLICY.maxFallbackRuleCount,
|
|
238
|
-
overRecommendedRuleCount,
|
|
239
|
-
overFallbackRuleCount,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
export function buildSelectedContextManifest(options = {}) {
|
|
244
|
-
const {
|
|
245
|
-
contextFiles = [],
|
|
246
|
-
requestId = 'adhoc-request',
|
|
247
|
-
requestText = '',
|
|
248
|
-
} = options;
|
|
249
|
-
|
|
250
|
-
const normalizedRequestText = normalizeRequestText(requestText);
|
|
251
|
-
const normalizedContextFiles = normalizeContextFiles(contextFiles);
|
|
252
|
-
const ruleEntryMap = createRuleEntryMap();
|
|
253
|
-
|
|
254
|
-
applyDirectTextSignals(ruleEntryMap, normalizedRequestText);
|
|
255
|
-
applyContextFileSignals(ruleEntryMap, normalizedContextFiles);
|
|
256
|
-
applyImplicationSignals(ruleEntryMap, normalizedRequestText);
|
|
257
|
-
|
|
258
|
-
const matchedRuleEntries = getMatchedRuleEntries(ruleEntryMap);
|
|
259
|
-
|
|
260
|
-
const labels = matchedRuleEntries.map((ruleFamily) => ruleFamily.label);
|
|
261
|
-
const selectedRules = matchedRuleEntries.map((ruleFamily) => ruleFamily.rulePath);
|
|
262
|
-
const selectedRuleSet = new Set(selectedRules);
|
|
263
|
-
const skippedRules = RULE_FAMILY_CATALOG
|
|
264
|
-
.map((ruleFamily) => ruleFamily.rulePath)
|
|
265
|
-
.filter((rulePath) => !selectedRuleSet.has(rulePath))
|
|
266
|
-
.sort((leftPath, rightPath) => leftPath.localeCompare(rightPath));
|
|
267
|
-
const evidenceEntries = matchedRuleEntries.map((ruleFamily) => ({
|
|
268
|
-
label: ruleFamily.label,
|
|
269
|
-
matchedTriggers: ruleFamily.matchedTriggers,
|
|
270
|
-
matchedFiles: ruleFamily.matchedFiles,
|
|
271
|
-
matchedImplications: ruleFamily.matchedImplications,
|
|
272
|
-
}));
|
|
273
|
-
const uncertainty = resolveUncertainty(labels, evidenceEntries, normalizedRequestText);
|
|
274
|
-
const budget = buildContextBudget(labels, evidenceEntries);
|
|
275
|
-
|
|
276
|
-
return {
|
|
277
|
-
schemaVersion: 'adaptive-context-manifest-v1',
|
|
278
|
-
requestId,
|
|
279
|
-
contextFiles: normalizedContextFiles,
|
|
280
|
-
labels,
|
|
281
|
-
selectedRules,
|
|
282
|
-
selectedPrompts: collectPromptsForRequest(normalizedRequestText, labels),
|
|
283
|
-
selectedDocs: collectDocsForLabels(labels),
|
|
284
|
-
selectedState: collectStateForLabels(labels),
|
|
285
|
-
skippedRules,
|
|
286
|
-
uncertainty,
|
|
287
|
-
budget,
|
|
288
|
-
fallbackRequired: uncertainty === 'high' || budget.status === 'fallback-required',
|
|
289
|
-
evidence: evidenceEntries,
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function compareRequiredLabels(requiredLabels, actualLabels) {
|
|
294
|
-
const actualLabelSet = new Set(actualLabels);
|
|
295
|
-
|
|
296
|
-
return requiredLabels.filter((requiredLabel) => !actualLabelSet.has(requiredLabel));
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function compareExtraLabels(expectedLabels, actualLabels) {
|
|
300
|
-
const expectedLabelSet = new Set(expectedLabels);
|
|
301
|
-
|
|
302
|
-
return actualLabels.filter((actualLabel) => !expectedLabelSet.has(actualLabel));
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
export function evaluateAdaptiveContextFixtures(fixtures) {
|
|
306
|
-
const fixtureResults = fixtures.map((fixtureEntry) => {
|
|
307
|
-
const manifest = buildSelectedContextManifest({
|
|
308
|
-
requestId: fixtureEntry.id,
|
|
309
|
-
requestText: fixtureEntry.requestText,
|
|
310
|
-
});
|
|
311
|
-
const missedRequiredLabels = compareRequiredLabels(fixtureEntry.requiredLabels, manifest.labels);
|
|
312
|
-
const extraLabels = compareExtraLabels(fixtureEntry.allowedLabels || fixtureEntry.requiredLabels, manifest.labels);
|
|
313
|
-
|
|
314
|
-
return {
|
|
315
|
-
id: fixtureEntry.id,
|
|
316
|
-
passed: missedRequiredLabels.length === 0,
|
|
317
|
-
missedRequiredLabels,
|
|
318
|
-
extraLabels,
|
|
319
|
-
manifest,
|
|
320
|
-
};
|
|
321
|
-
});
|
|
322
|
-
const failedFixtures = fixtureResults.filter((fixtureResult) => !fixtureResult.passed);
|
|
323
|
-
const missedRequiredLabelCount = fixtureResults.reduce(
|
|
324
|
-
(totalCount, fixtureResult) => totalCount + fixtureResult.missedRequiredLabels.length,
|
|
325
|
-
0
|
|
326
|
-
);
|
|
327
|
-
const extraLabelCount = fixtureResults.reduce(
|
|
328
|
-
(totalCount, fixtureResult) => totalCount + fixtureResult.extraLabels.length,
|
|
329
|
-
0
|
|
330
|
-
);
|
|
331
|
-
const selectedRuleCounts = fixtureResults.map((fixtureResult) => fixtureResult.manifest.budget.selectedRuleCount);
|
|
332
|
-
const maxSelectedRuleCount = Math.max(...selectedRuleCounts, 0);
|
|
333
|
-
const totalSelectedRuleCount = selectedRuleCounts.reduce(
|
|
334
|
-
(totalCount, selectedRuleCount) => totalCount + selectedRuleCount,
|
|
335
|
-
0
|
|
336
|
-
);
|
|
337
|
-
const overRecommendedFixtureCount = fixtureResults.filter((fixtureResult) => {
|
|
338
|
-
return fixtureResult.manifest.budget.status !== 'within-budget';
|
|
339
|
-
}).length;
|
|
340
|
-
const fallbackFixtureCount = fixtureResults.filter((fixtureResult) => {
|
|
341
|
-
return fixtureResult.manifest.fallbackRequired;
|
|
342
|
-
}).length;
|
|
343
|
-
|
|
344
|
-
return {
|
|
345
|
-
reportName: 'adaptive-context-benchmark',
|
|
346
|
-
generatedAt: new Date().toISOString(),
|
|
347
|
-
fixtureCount: fixtureResults.length,
|
|
348
|
-
passed: failedFixtures.length === 0,
|
|
349
|
-
passedCount: fixtureResults.length - failedFixtures.length,
|
|
350
|
-
failedCount: failedFixtures.length,
|
|
351
|
-
missedRequiredLabelCount,
|
|
352
|
-
extraLabelCount,
|
|
353
|
-
budgetSummary: {
|
|
354
|
-
maxSelectedRuleCount,
|
|
355
|
-
averageSelectedRuleCount: fixtureResults.length === 0
|
|
356
|
-
? 0
|
|
357
|
-
: Number((totalSelectedRuleCount / fixtureResults.length).toFixed(2)),
|
|
358
|
-
overRecommendedFixtureCount,
|
|
359
|
-
fallbackFixtureCount,
|
|
360
|
-
maxRecommendedRuleCount: CONTEXT_BUDGET_POLICY.maxRecommendedRuleCount,
|
|
361
|
-
maxFallbackRuleCount: CONTEXT_BUDGET_POLICY.maxFallbackRuleCount,
|
|
362
|
-
},
|
|
363
|
-
results: fixtureResults,
|
|
364
|
-
};
|
|
365
|
-
}
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Color parsing and distance utilities for the typography/palette
|
|
5
|
-
* anti-repeat audit. OKLCH math is contained here so the main audit module
|
|
6
|
-
* stays focused on file scanning and ledger cross-check.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export const HEX_COLOR_PATTERN = /#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\b/g;
|
|
10
|
-
export const OKLCH_PATTERN = /oklch\(\s*([^)]+)\s*\)/gi;
|
|
11
|
-
|
|
12
|
-
export function expandShortHexColor(rawHexColor) {
|
|
13
|
-
if (rawHexColor.length !== 4) {
|
|
14
|
-
return rawHexColor;
|
|
15
|
-
}
|
|
16
|
-
const expandedChars = [];
|
|
17
|
-
for (let charIndex = 1; charIndex < rawHexColor.length; charIndex += 1) {
|
|
18
|
-
expandedChars.push(rawHexColor[charIndex], rawHexColor[charIndex]);
|
|
19
|
-
}
|
|
20
|
-
return `#${expandedChars.join('')}`.toLowerCase();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function normalizeHexColor(rawHexColor) {
|
|
24
|
-
if (typeof rawHexColor !== 'string' || rawHexColor.length === 0) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
const trimmedHex = rawHexColor.trim().toLowerCase();
|
|
28
|
-
if (!trimmedHex.startsWith('#')) {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
if (trimmedHex.length === 4) {
|
|
32
|
-
return expandShortHexColor(trimmedHex);
|
|
33
|
-
}
|
|
34
|
-
if (trimmedHex.length === 7 || trimmedHex.length === 9) {
|
|
35
|
-
return trimmedHex.slice(0, 7);
|
|
36
|
-
}
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function parseOklchNumber(rawNumber, percentScale) {
|
|
41
|
-
const numberString = String(rawNumber || '').trim();
|
|
42
|
-
if (numberString.endsWith('%')) {
|
|
43
|
-
const percentValue = parseFloat(numberString.slice(0, -1));
|
|
44
|
-
if (!Number.isFinite(percentValue)) {
|
|
45
|
-
return Number.NaN;
|
|
46
|
-
}
|
|
47
|
-
return (percentValue / 100) * percentScale;
|
|
48
|
-
}
|
|
49
|
-
return parseFloat(numberString);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function parseOklchTriple(oklchExpression) {
|
|
53
|
-
const componentTokens = String(oklchExpression || '')
|
|
54
|
-
.replace(/\//g, ' ')
|
|
55
|
-
.split(/[\s,]+/)
|
|
56
|
-
.filter((componentToken) => componentToken.length > 0);
|
|
57
|
-
if (componentTokens.length < 3) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
const lightness = parseOklchNumber(componentTokens[0], 1);
|
|
61
|
-
const chroma = parseFloat(componentTokens[1]);
|
|
62
|
-
const hueDegrees = parseOklchNumber(componentTokens[2], 360);
|
|
63
|
-
if (!Number.isFinite(lightness) || !Number.isFinite(chroma) || !Number.isFinite(hueDegrees)) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
return { lightness, chroma, hueDegrees };
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* L*C*H-style perceptual distance proxy. OKLCH is perceptually uniform,
|
|
71
|
-
* so a Cartesian-like delta over (L, C, C * Δhue_radians) tracks visible
|
|
72
|
-
* difference well enough for an anti-repeat heuristic.
|
|
73
|
-
*/
|
|
74
|
-
export function oklchPerceptualDistance(leftColor, rightColor) {
|
|
75
|
-
const lightnessDelta = leftColor.lightness - rightColor.lightness;
|
|
76
|
-
const chromaDelta = leftColor.chroma - rightColor.chroma;
|
|
77
|
-
const hueDelta = ((leftColor.hueDegrees - rightColor.hueDegrees + 540) % 360) - 180;
|
|
78
|
-
const hueArcRadians = (hueDelta * Math.PI) / 180;
|
|
79
|
-
const hueChromaDelta = leftColor.chroma * hueArcRadians;
|
|
80
|
-
return Math.sqrt(
|
|
81
|
-
lightnessDelta * lightnessDelta
|
|
82
|
-
+ chromaDelta * chromaDelta
|
|
83
|
-
+ hueChromaDelta * hueChromaDelta,
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function extractColorOccurrencesFromText(sourceText) {
|
|
88
|
-
/** @type {{ kind: 'hex' | 'oklch', raw: string, normalized: string | null, oklch: { lightness: number, chroma: number, hueDegrees: number } | null, index: number }[]} */
|
|
89
|
-
const colorOccurrences = [];
|
|
90
|
-
|
|
91
|
-
HEX_COLOR_PATTERN.lastIndex = 0;
|
|
92
|
-
let hexMatch;
|
|
93
|
-
// eslint-disable-next-line no-cond-assign
|
|
94
|
-
while ((hexMatch = HEX_COLOR_PATTERN.exec(sourceText)) !== null) {
|
|
95
|
-
colorOccurrences.push({
|
|
96
|
-
kind: 'hex',
|
|
97
|
-
raw: hexMatch[0],
|
|
98
|
-
normalized: normalizeHexColor(hexMatch[0]),
|
|
99
|
-
oklch: null,
|
|
100
|
-
index: hexMatch.index,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
OKLCH_PATTERN.lastIndex = 0;
|
|
105
|
-
let oklchMatch;
|
|
106
|
-
// eslint-disable-next-line no-cond-assign
|
|
107
|
-
while ((oklchMatch = OKLCH_PATTERN.exec(sourceText)) !== null) {
|
|
108
|
-
colorOccurrences.push({
|
|
109
|
-
kind: 'oklch',
|
|
110
|
-
raw: oklchMatch[0],
|
|
111
|
-
normalized: oklchMatch[0].toLowerCase(),
|
|
112
|
-
oklch: parseOklchTriple(oklchMatch[1]),
|
|
113
|
-
index: oklchMatch.index,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return colorOccurrences;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function extractLedgerColors(antiRepeatLedger) {
|
|
121
|
-
const previousPalettes = Array.isArray(antiRepeatLedger?.previousPalettes)
|
|
122
|
-
? antiRepeatLedger.previousPalettes
|
|
123
|
-
: [];
|
|
124
|
-
|
|
125
|
-
/** @type {{ kind: 'hex' | 'oklch', normalized: string | null, oklch: { lightness: number, chroma: number, hueDegrees: number } | null, sourceEntry: any }[]} */
|
|
126
|
-
const ledgerColors = [];
|
|
127
|
-
for (const ledgerEntry of previousPalettes) {
|
|
128
|
-
const summaryString = String(ledgerEntry?.summary || '');
|
|
129
|
-
if (!summaryString) {
|
|
130
|
-
continue;
|
|
131
|
-
}
|
|
132
|
-
HEX_COLOR_PATTERN.lastIndex = 0;
|
|
133
|
-
let hexMatch;
|
|
134
|
-
// eslint-disable-next-line no-cond-assign
|
|
135
|
-
while ((hexMatch = HEX_COLOR_PATTERN.exec(summaryString)) !== null) {
|
|
136
|
-
ledgerColors.push({
|
|
137
|
-
kind: 'hex',
|
|
138
|
-
normalized: normalizeHexColor(hexMatch[0]),
|
|
139
|
-
oklch: null,
|
|
140
|
-
sourceEntry: ledgerEntry,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
OKLCH_PATTERN.lastIndex = 0;
|
|
144
|
-
let oklchMatch;
|
|
145
|
-
// eslint-disable-next-line no-cond-assign
|
|
146
|
-
while ((oklchMatch = OKLCH_PATTERN.exec(summaryString)) !== null) {
|
|
147
|
-
ledgerColors.push({
|
|
148
|
-
kind: 'oklch',
|
|
149
|
-
normalized: oklchMatch[0].toLowerCase(),
|
|
150
|
-
oklch: parseOklchTriple(oklchMatch[1]),
|
|
151
|
-
sourceEntry: ledgerEntry,
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return ledgerColors;
|
|
156
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Filesystem scanning for the typography/palette anti-repeat audit. Walks
|
|
5
|
-
* the repository tree, skips noisy directories (node_modules, build outputs,
|
|
6
|
-
* etc.), and yields scannable CSS-like and token-config file paths.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { readdirSync, statSync, existsSync } from 'node:fs';
|
|
10
|
-
import { extname, join, relative, sep } from 'node:path';
|
|
11
|
-
|
|
12
|
-
export const DEFAULT_CSS_FILE_EXTENSIONS = new Set(['.css', '.scss', '.sass', '.less']);
|
|
13
|
-
export const TOKEN_CONFIG_FILE_NAMES = new Set([
|
|
14
|
-
'tailwind.config.js',
|
|
15
|
-
'tailwind.config.cjs',
|
|
16
|
-
'tailwind.config.mjs',
|
|
17
|
-
'tailwind.config.ts',
|
|
18
|
-
'theme.config.js',
|
|
19
|
-
'theme.config.ts',
|
|
20
|
-
'design-tokens.js',
|
|
21
|
-
'design-tokens.ts',
|
|
22
|
-
]);
|
|
23
|
-
export const SCAN_SKIP_DIRECTORY_NAMES = new Set([
|
|
24
|
-
'node_modules',
|
|
25
|
-
'.git',
|
|
26
|
-
'.agentic-backup',
|
|
27
|
-
'.benchmarks',
|
|
28
|
-
'dist',
|
|
29
|
-
'build',
|
|
30
|
-
'.next',
|
|
31
|
-
'out',
|
|
32
|
-
'coverage',
|
|
33
|
-
'.cache',
|
|
34
|
-
]);
|
|
35
|
-
|
|
36
|
-
function isInsideSkippedDirectory(absolutePath, repositoryRootPath) {
|
|
37
|
-
const relativePath = relative(repositoryRootPath, absolutePath);
|
|
38
|
-
if (!relativePath || relativePath.startsWith('..')) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
const pathSegments = relativePath.split(sep);
|
|
42
|
-
return pathSegments.some((segmentName) => SCAN_SKIP_DIRECTORY_NAMES.has(segmentName));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function* walkDirectoryEntries(currentDirectoryPath, repositoryRootPath) {
|
|
46
|
-
const directoryEntries = readdirSync(currentDirectoryPath, { withFileTypes: true });
|
|
47
|
-
for (const directoryEntry of directoryEntries) {
|
|
48
|
-
const childPath = join(currentDirectoryPath, directoryEntry.name);
|
|
49
|
-
if (directoryEntry.isDirectory()) {
|
|
50
|
-
if (SCAN_SKIP_DIRECTORY_NAMES.has(directoryEntry.name)) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
if (isInsideSkippedDirectory(childPath, repositoryRootPath)) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
yield* walkDirectoryEntries(childPath, repositoryRootPath);
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (directoryEntry.isFile()) {
|
|
60
|
-
yield childPath;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function isScannableFile(absoluteFilePath) {
|
|
66
|
-
const fileExtension = extname(absoluteFilePath).toLowerCase();
|
|
67
|
-
if (DEFAULT_CSS_FILE_EXTENSIONS.has(fileExtension)) {
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
const baseName = absoluteFilePath.split(/[\\/]/).pop();
|
|
71
|
-
return TOKEN_CONFIG_FILE_NAMES.has(baseName);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export function collectScannableFilePaths(repositoryRootPath, scanRoots) {
|
|
75
|
-
const collectedFilePaths = [];
|
|
76
|
-
for (const scanRoot of scanRoots) {
|
|
77
|
-
const absoluteScanRoot = join(repositoryRootPath, scanRoot);
|
|
78
|
-
if (!existsSync(absoluteScanRoot)) {
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
const scanRootStat = statSync(absoluteScanRoot);
|
|
82
|
-
if (!scanRootStat.isDirectory()) {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
for (const candidateFilePath of walkDirectoryEntries(absoluteScanRoot, repositoryRootPath)) {
|
|
86
|
-
if (!isScannableFile(candidateFilePath)) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
collectedFilePaths.push(candidateFilePath);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return collectedFilePaths.sort();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export function lineNumberFromIndex(sourceText, charIndex) {
|
|
96
|
-
let lineNumber = 1;
|
|
97
|
-
for (let scanIndex = 0; scanIndex < charIndex && scanIndex < sourceText.length; scanIndex += 1) {
|
|
98
|
-
if (sourceText[scanIndex] === '\n') {
|
|
99
|
-
lineNumber += 1;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return lineNumber;
|
|
103
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Font-family parsing for the typography/palette anti-repeat audit. CSS
|
|
5
|
-
* `font-family:` declarations and `@font-face` blocks are the inputs;
|
|
6
|
-
* normalized lowercase family tokens are the outputs.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export const FONT_FAMILY_DECLARATION_PATTERN = /font-family\s*:\s*([^;}]+)[;}]/gi;
|
|
10
|
-
export const FONT_FACE_FAMILY_PATTERN = /@font-face\s*\{[^}]*font-family\s*:\s*([^;]+);/gi;
|
|
11
|
-
|
|
12
|
-
export function normalizeFontFamilyToken(rawFamilyToken) {
|
|
13
|
-
return String(rawFamilyToken || '')
|
|
14
|
-
.replace(/^["']|["']$/g, '')
|
|
15
|
-
.trim()
|
|
16
|
-
.toLowerCase();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function splitFontFamilyDeclaration(declarationValue) {
|
|
20
|
-
return String(declarationValue || '')
|
|
21
|
-
.split(',')
|
|
22
|
-
.map((familyEntry) => normalizeFontFamilyToken(familyEntry))
|
|
23
|
-
.filter((familyEntry) => familyEntry.length > 0 && !familyEntry.startsWith('var('));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function extractFontFamiliesFromText(sourceText) {
|
|
27
|
-
/** @type {{ family: string, index: number }[]} */
|
|
28
|
-
const familyOccurrences = [];
|
|
29
|
-
|
|
30
|
-
for (const matchPattern of [FONT_FAMILY_DECLARATION_PATTERN, FONT_FACE_FAMILY_PATTERN]) {
|
|
31
|
-
matchPattern.lastIndex = 0;
|
|
32
|
-
let regexMatch;
|
|
33
|
-
// eslint-disable-next-line no-cond-assign
|
|
34
|
-
while ((regexMatch = matchPattern.exec(sourceText)) !== null) {
|
|
35
|
-
const declarationValue = regexMatch[1];
|
|
36
|
-
const declarationStartIndex = regexMatch.index;
|
|
37
|
-
for (const familyEntry of splitFontFamilyDeclaration(declarationValue)) {
|
|
38
|
-
familyOccurrences.push({ family: familyEntry, index: declarationStartIndex });
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return familyOccurrences;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function extractLedgerTypographyFamilies(antiRepeatLedger) {
|
|
47
|
-
const previousTypographyChoices = Array.isArray(antiRepeatLedger?.previousTypographyChoices)
|
|
48
|
-
? antiRepeatLedger.previousTypographyChoices
|
|
49
|
-
: [];
|
|
50
|
-
|
|
51
|
-
const ledgerFamilies = new Map();
|
|
52
|
-
for (const ledgerEntry of previousTypographyChoices) {
|
|
53
|
-
const summaryString = String(ledgerEntry?.summary || '');
|
|
54
|
-
if (!summaryString) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
// Summaries are emitted as "role: value; role: value". Each value is a
|
|
58
|
-
// font family that the previous design shipped.
|
|
59
|
-
for (const summaryPart of summaryString.split(';')) {
|
|
60
|
-
const colonSplitIndex = summaryPart.indexOf(':');
|
|
61
|
-
const familyValue = colonSplitIndex >= 0 ? summaryPart.slice(colonSplitIndex + 1) : summaryPart;
|
|
62
|
-
const normalizedFamilyValue = normalizeFontFamilyToken(familyValue);
|
|
63
|
-
if (normalizedFamilyValue.length === 0) {
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
ledgerFamilies.set(normalizedFamilyValue, ledgerEntry);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return ledgerFamilies;
|
|
70
|
-
}
|