coauthored 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/PRIVACY.md +107 -0
- package/README.md +113 -3
- package/THIRD_PARTY_LICENSES.md +105 -0
- package/dist/cli/analytics/anchors.js +39 -0
- package/dist/cli/analytics/archetypes.js +193 -0
- package/dist/cli/analytics/content/analyzer.js +945 -0
- package/dist/cli/analytics/content/classify.js +115 -0
- package/dist/cli/analytics/content/demo-corpus.js +301 -0
- package/dist/cli/analytics/content/sketch.js +54 -0
- package/dist/cli/analytics/dataset.js +321 -0
- package/dist/cli/analytics/demo-fixtures.js +531 -0
- package/dist/cli/analytics/fdr.js +183 -0
- package/dist/cli/analytics/helicorder.js +66 -0
- package/dist/cli/analytics/insights.js +589 -0
- package/dist/cli/analytics/models.js +75 -0
- package/dist/cli/analytics/pricing.js +121 -0
- package/dist/cli/analytics/probable-cause.js +115 -0
- package/dist/cli/analytics/report-builder.js +162 -0
- package/dist/cli/analytics/statistics.js +91 -0
- package/dist/cli/analytics/time.js +252 -0
- package/dist/cli/cli/args.js +105 -0
- package/dist/cli/cli/browser.js +71 -0
- package/dist/cli/cli/index.js +20 -0
- package/dist/cli/cli/main.js +520 -0
- package/dist/cli/cli/phrase-review.js +78 -0
- package/dist/cli/cli/server.js +481 -0
- package/dist/cli/cli/terminal.js +363 -0
- package/dist/cli/ingest/adapters/aider.js +116 -0
- package/dist/cli/ingest/adapters/claude-code.js +139 -0
- package/dist/cli/ingest/adapters/cline-roo.js +89 -0
- package/dist/cli/ingest/adapters/codex-cli.js +240 -0
- package/dist/cli/ingest/adapters/content.js +99 -0
- package/dist/cli/ingest/adapters/cursor-ide.js +149 -0
- package/dist/cli/ingest/adapters/gemini-cli.js +208 -0
- package/dist/cli/ingest/adapters/index.js +18 -0
- package/dist/cli/ingest/adapters/opencode.js +203 -0
- package/dist/cli/ingest/adapters/pi-agent.js +85 -0
- package/dist/cli/ingest/adapters/shared.js +484 -0
- package/dist/cli/ingest/content-sink.js +31 -0
- package/dist/cli/ingest/discovery.js +50 -0
- package/dist/cli/ingest/message-digests.js +61 -0
- package/dist/cli/ingest/pipeline.js +155 -0
- package/dist/cli/ingest/safe-fs.js +284 -0
- package/dist/cli/ingest/sqlite-stage.js +139 -0
- package/dist/cli/ingest/time-window.js +34 -0
- package/dist/cli/ingest/tool-map.js +24 -0
- package/dist/cli/ingest/types.js +1 -0
- package/dist/cli/ingest/worker.js +97 -0
- package/dist/cli/report/content/emoji-names.js +3956 -0
- package/dist/cli/report/content/insights.js +41 -0
- package/dist/cli/report/content/lexicons.js +112 -0
- package/dist/cli/report/content/policy.js +77 -0
- package/dist/cli/report/content/redact.js +164 -0
- package/dist/cli/report/content/stopwords.js +8848 -0
- package/dist/cli/report/content/suppression.js +2617 -0
- package/dist/cli/report/content/validate.js +152 -0
- package/dist/cli/report/copy-lint.js +105 -0
- package/dist/cli/report/share.js +132 -0
- package/dist/cli/report/types.js +1 -0
- package/dist/cli/report/validators.js +334 -0
- package/dist/web/assets/Archivo-VF-BohoA-Sn.woff2 +0 -0
- package/dist/web/assets/DelaGothicOne-subset-CpoJGhTq.woff2 +0 -0
- package/dist/web/assets/Film-BkhZFxG9.css +1 -0
- package/dist/web/assets/MartianMono-VF-CmJ1nXx9.woff2 +0 -0
- package/dist/web/assets/app-Dw1a5h5V.js +38 -0
- package/dist/web/assets/bricolage-grotesque-latin-700-normal-gtcctNPv.woff2 +0 -0
- package/dist/web/assets/bricolage-grotesque-latin-800-normal-J50vIsBe.woff2 +0 -0
- package/dist/web/assets/chorus-D7bfON5Z.ogg +0 -0
- package/dist/web/assets/chorus-bass-CBTKpMv_.ogg +0 -0
- package/dist/web/assets/chorus-drums-BOzgLSoq.ogg +0 -0
- package/dist/web/assets/chorus-harmony-DnJYs_tp.ogg +0 -0
- package/dist/web/assets/chorus-lead-CFpg5DC1.ogg +0 -0
- package/dist/web/assets/chunk-BNfsY4o8.js +1 -0
- package/dist/web/assets/chunk-BSm8IhPY.js +1 -0
- package/dist/web/assets/chunk-Bi6EQAkf.js +1 -0
- package/dist/web/assets/chunk-D6HyoJCB.js +46 -0
- package/dist/web/assets/chunk-DrEayQLY.js +1 -0
- package/dist/web/assets/chunk-V3YGpFIw.js +1 -0
- package/dist/web/assets/chunk-XGhNFWse.js +1 -0
- package/dist/web/assets/dialogue-card-A5zmbNhu.ogg +0 -0
- package/dist/web/assets/groove-bass-BFNelLKi.ogg +0 -0
- package/dist/web/assets/groove-drums-BY1SBntR.ogg +0 -0
- package/dist/web/assets/groove-harmony-C0CrBzu3.ogg +0 -0
- package/dist/web/assets/groove-lead-CEYPzm5U.ogg +0 -0
- package/dist/web/assets/groove-ln-zQmTb.ogg +0 -0
- package/dist/web/assets/guess-high-CL6mF18x.ogg +0 -0
- package/dist/web/assets/guess-low-C3UnKayZ.ogg +0 -0
- package/dist/web/assets/higher-BevsMIWl.ogg +0 -0
- package/dist/web/assets/identity-0EPS3msD.ogg +0 -0
- package/dist/web/assets/index-DpT0dtHc.css +1 -0
- package/dist/web/assets/intro-DeRh6kUx.ogg +0 -0
- package/dist/web/assets/intro-bass-D63IPU0H.ogg +0 -0
- package/dist/web/assets/intro-drums-Dt9QO534.ogg +0 -0
- package/dist/web/assets/intro-harmony-DBsMG9jJ.ogg +0 -0
- package/dist/web/assets/intro-lead-DWcWS1ia.ogg +0 -0
- package/dist/web/assets/jar-coin-rtCvspuq.ogg +0 -0
- package/dist/web/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- package/dist/web/assets/jetbrains-mono-latin-600-normal-C8RAYTDA.woff2 +0 -0
- package/dist/web/assets/ledger-tick-C1rQgQGX.ogg +0 -0
- package/dist/web/assets/night-B_bMOZcf.ogg +0 -0
- package/dist/web/assets/night-bass-B-7Ay9ME.ogg +0 -0
- package/dist/web/assets/night-drums-zEtqWXX3.ogg +0 -0
- package/dist/web/assets/night-harmony-C5Ix2yce.ogg +0 -0
- package/dist/web/assets/night-lead-B7KMlRyj.ogg +0 -0
- package/dist/web/assets/ourturn-DX78hTEz.ogg +0 -0
- package/dist/web/assets/plus-jakarta-sans-latin-400-normal-Dhut76fR.woff2 +0 -0
- package/dist/web/assets/plus-jakarta-sans-latin-500-normal-Bf-nb4oT.woff2 +0 -0
- package/dist/web/assets/plus-jakarta-sans-latin-600-normal-DLTa1BUW.woff2 +0 -0
- package/dist/web/assets/plus-jakarta-sans-latin-700-normal-CfpNZvy6.woff2 +0 -0
- package/dist/web/assets/reveal-BmWAGHih.ogg +0 -0
- package/dist/web/assets/review-split-Dac4zagw.ogg +0 -0
- package/dist/web/assets/shutter-uhz2Y9S9.ogg +0 -0
- package/dist/web/assets/soclose-CiUFR5St.ogg +0 -0
- package/dist/web/assets/stinger-TnnzHAMN.ogg +0 -0
- package/dist/web/assets/stomp-mzIk4cGm.ogg +0 -0
- package/dist/web/assets/syne-latin-700-normal-AF3Rs61n.woff2 +0 -0
- package/dist/web/assets/syne-latin-800-normal-EehdNYzx.woff2 +0 -0
- package/dist/web/assets/tension-BHvWG5ru.ogg +0 -0
- package/dist/web/assets/tension-bass-4G-2qA9W.ogg +0 -0
- package/dist/web/assets/tension-drums-D7sdehJr.ogg +0 -0
- package/dist/web/assets/tension-harmony-FyPldmLb.ogg +0 -0
- package/dist/web/assets/tension-lead-C5uoFMR8.ogg +0 -0
- package/dist/web/assets/why-clock-Dzs1A_ym.ogg +0 -0
- package/dist/web/favicon.svg +1 -0
- package/dist/web/index.html +16 -0
- package/dist/web/licenses/OFL-Archivo.txt +93 -0
- package/dist/web/licenses/OFL-DelaGothic.txt +93 -0
- package/dist/web/licenses/OFL-MartianMono.txt +93 -0
- package/package.json +63 -6
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function eligibleContentInsights(c) {
|
|
2
|
+
const { style, combos, emoji, safety } = c;
|
|
3
|
+
const cat = (id) => c.lexicon.find(row => row.id === id);
|
|
4
|
+
const total = (id) => cat(id)?.total ?? 0;
|
|
5
|
+
const agreement = cat('agent-agree');
|
|
6
|
+
const confidence = cat('agent-confident');
|
|
7
|
+
const grade = (term) => confidence?.headline?.[term] ?? confidence?.topTerms.find(row => row.term === term)?.count ?? 0;
|
|
8
|
+
const scriptCounts = Object.values(style.scripts);
|
|
9
|
+
const scriptTotal = scriptCounts.reduce((a, b) => a + b, 0);
|
|
10
|
+
const gates = [
|
|
11
|
+
(agreement?.total ?? 0) >= 10 && agreement.sessions >= 3,
|
|
12
|
+
(combos.apologies.agent >= 5 && combos.apologies.user >= 5) || (combos.apologies.agent >= 20 && combos.apologies.user === 0),
|
|
13
|
+
total('please') + total('thanks') >= 20,
|
|
14
|
+
style.oneWord >= 25 && (style.oneWordTop?.count ?? 0) >= 10,
|
|
15
|
+
total('swear-mild') + total('swear-strong') >= 10 && combos.swearSessions >= 3,
|
|
16
|
+
total('why') >= 25,
|
|
17
|
+
total('agent-confident') >= 10 && total('not-working') + total('again-still') >= 10,
|
|
18
|
+
cat('instruction')?.topTerms.some(row => row.count >= 20 && row.sessions >= 5),
|
|
19
|
+
grade('perfect') + grade('excellent') >= 20,
|
|
20
|
+
combos.agentOpener !== null,
|
|
21
|
+
style.agentExclaimReplies >= 50,
|
|
22
|
+
total('undo') >= 10,
|
|
23
|
+
style.capsPrompts >= 5,
|
|
24
|
+
style.promptsWithLetters >= 200,
|
|
25
|
+
style.prompts >= 200,
|
|
26
|
+
style.prompts >= 50,
|
|
27
|
+
emoji.total >= 20 && (emoji.user.length > 0 || emoji.agent.length > 0),
|
|
28
|
+
combos.pleasePer100ByMonth.some(n => n !== null),
|
|
29
|
+
combos.thanksLastPromptLong !== null && combos.thanksLastPromptShort !== null,
|
|
30
|
+
combos.goOnStreak >= 5,
|
|
31
|
+
style.prompts >= 50,
|
|
32
|
+
style.stackLines >= 100,
|
|
33
|
+
Object.values(combos.thanksByLanguage).filter(n => n >= 5).length >= 2,
|
|
34
|
+
scriptTotal > 0 && scriptCounts.filter(n => n / scriptTotal >= .02).length >= 2,
|
|
35
|
+
c.private?.phrases.length,
|
|
36
|
+
c.private?.words.length,
|
|
37
|
+
style.prompts >= 50 && c.private?.openers.length,
|
|
38
|
+
safety.secret + safety.pii + safety.identifier > 0,
|
|
39
|
+
];
|
|
40
|
+
return gates.flatMap((eligible, index) => eligible ? [index + 1] : []);
|
|
41
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// Curated lexicons for the content analysis pass.
|
|
2
|
+
// Every list in this file was written by hand for Coauthored. No third-party word list is copied here.
|
|
3
|
+
//
|
|
4
|
+
// Matching happens on normalized tokens: NFKC, lowercase, curly apostrophes folded to ASCII.
|
|
5
|
+
// Multi-word entries are space-separated token sequences and are matched by the phrase matcher.
|
|
6
|
+
export const CATEGORIES = [
|
|
7
|
+
{
|
|
8
|
+
id: 'please', role: 'user', shareEligible: true,
|
|
9
|
+
phrases: ['please', 'pls', 'plz', 'pleeease', 'kindly', 'bitte', 'por favor', 'per favore', 's\'il te plaît',
|
|
10
|
+
's\'il vous plaît', 'пожалуйста', 'пж', '请', 'お願い', 'お願いします', '부탁해', '부탁합니다', 'lütfen', 'proszę'],
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: 'thanks', role: 'user', shareEligible: true,
|
|
14
|
+
phrases: ['thanks', 'thank you', 'thx', 'ty', 'tysm', 'thank u', 'cheers', 'appreciate it', 'much appreciated',
|
|
15
|
+
'merci', 'danke', 'gracias', 'grazie', 'obrigado', 'obrigada', 'спасибо', 'спс', '谢谢', '多谢',
|
|
16
|
+
'ありがとう', 'ありがとうございます', '감사합니다', '고마워', 'teşekkürler', 'dzięki', 'dank je'],
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: 'sorry-user', role: 'user', shareEligible: true,
|
|
20
|
+
phrases: ['sorry', 'my bad', 'my mistake', 'oops', 'apologies', 'désolé', 'perdón', 'entschuldigung', 'извини', 'прости'],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'swear-mild', role: 'user', shareEligible: true, censor: true,
|
|
24
|
+
phrases: ['damn', 'dammit', 'damnit', 'crap', 'hell', 'bloody', 'heck', 'frick', 'freaking', 'friggin',
|
|
25
|
+
'merde', 'mist', 'mierda', 'блин', 'чёрт', 'черт', 'cazzo'],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: 'swear-strong', role: 'user', shareEligible: true, censor: true,
|
|
29
|
+
phrases: ['fuck', 'fucking', 'fucked', 'fucks', 'wtf', 'ffs', 'shit', 'shitty', 'bullshit', 'asshole',
|
|
30
|
+
'goddamn', 'scheiße', 'scheisse', 'joder', 'putain', 'блять', 'бля', 'сука', 'хрен', 'kurwa'],
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: 'why', role: 'user', shareEligible: true,
|
|
34
|
+
phrases: ['why', 'warum', 'pourquoi', 'por qué', 'perché', 'почему', 'зачем', '为什么', 'なぜ', 'どうして', '왜'],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
id: 'again-still', role: 'user', shareEligible: true,
|
|
38
|
+
phrases: ['still', 'again', 'once again', 'same error', 'same issue', 'same problem', 'опять', 'снова', 'encore', 'immer noch'],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: 'not-working', role: 'user', shareEligible: true,
|
|
42
|
+
phrases: ['not working', 'doesn\'t work', 'does not work', 'didn\'t work', 'did not work', 'still broken',
|
|
43
|
+
'it\'s broken', 'is broken', 'still failing', 'still fails', 'не работает', 'funktioniert nicht', 'ne marche pas',
|
|
44
|
+
'no funciona', '还是不行', '動かない'],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
id: 'exasperation', role: 'user', shareEligible: true,
|
|
48
|
+
phrases: ['ugh', 'argh', 'come on', 'seriously', 'what the', 'no no', 'no no no', 'nope', 'facepalm', 'omg', 'jesus'],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
id: 'praise', role: 'user', shareEligible: true,
|
|
52
|
+
phrases: ['perfect', 'great job', 'nice', 'nice work', 'awesome', 'amazing', 'love it', 'well done', 'good job',
|
|
53
|
+
'brilliant', 'excellent', 'beautiful', 'nailed it', 'lgtm', 'super', 'génial', 'отлично', '完美', '完璧'],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: 'instruction', role: 'user', shareEligible: true,
|
|
57
|
+
phrases: ['make sure', 'don\'t', 'do not', 'never', 'always', 'instead', 'actually', 'just', 'only', 'step by step',
|
|
58
|
+
'think hard', 'ultrathink', 'be concise', 'can you', 'no mistakes', 'double check', 'run the tests', 'write tests',
|
|
59
|
+
'add tests', 'commit', 'push', 'refactor', 'simplify', 'clean up', 'read the', 'look at', 'check the'],
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
id: 'go-on', role: 'user', shareEligible: true,
|
|
63
|
+
phrases: ['continue', 'keep going', 'go ahead', 'go on', 'proceed', 'yes', 'yep', 'yeah', 'ok', 'okay', 'k',
|
|
64
|
+
'sure', 'do it', 'ship it', 'go', 'next', 'да', 'давай', 'oui', 'ja', 'sí', '好', '好的', 'はい'],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
id: 'undo', role: 'user', shareEligible: true,
|
|
68
|
+
phrases: ['revert', 'undo', 'roll back', 'rollback', 'put it back', 'go back', 'start over', 'try again',
|
|
69
|
+
'that\'s wrong', 'that is wrong', 'wrong', 'not what i asked', 'not what i meant', 'stop'],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
id: 'agent-agree', role: 'agent', shareEligible: true,
|
|
73
|
+
phrases: ['you\'re absolutely right', 'you are absolutely right', 'you\'re right', 'you are right',
|
|
74
|
+
'great question', 'good catch', 'great catch', 'great idea', 'good point', 'great point', 'absolutely', "you're wrong"],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
id: 'agent-sorry', role: 'agent', shareEligible: true,
|
|
78
|
+
phrases: ['i apologize', 'my apologies', 'apologies for', 'sorry for the confusion', 'sorry about that',
|
|
79
|
+
'i made an error', 'i made a mistake', 'my mistake'],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: 'agent-confident', role: 'agent', shareEligible: true,
|
|
83
|
+
phrases: ['perfect', 'excellent', 'production ready', 'comprehensive', 'robust',
|
|
84
|
+
'all tests pass', 'all tests are passing', 'fully functional', 'successfully', 'seamlessly'],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: 'agent-narration', role: 'agent', shareEligible: false,
|
|
88
|
+
phrases: ['let me', 'now let me', 'i\'ll', 'i will', 'i see the issue', 'i see the problem', 'the issue is',
|
|
89
|
+
'the problem is', 'now i understand', 'i understand', 'let\'s'],
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
id: 'agent-praise', role: 'agent', shareEligible: true,
|
|
93
|
+
phrases: ['great', 'great work', 'nice work', 'well done', 'happy to help', 'glad'],
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
// Upper-case words that are not shouting.
|
|
97
|
+
export const ACRONYMS = new Set(`API APIS URL URLS JSON YAML TOML HTML CSS JS TS SQL CLI UI UX ID IDS HTTP HTTPS
|
|
98
|
+
TCP UDP DNS CPU GPU RAM SSD OK PR PRS CI CD AWS GCP SDK JWT CSV PDF PNG SVG XML REST TODO FIXME README LLM MCP
|
|
99
|
+
ENV NPM PNPM IO OS AI DB ORM CORS CSP DOM SSR SSG GQL VM SSH TLS SSL UTF NFC NFKC ASAP FYI IMO IIRC TL DR TLDR MVP
|
|
100
|
+
`.trim().split(/\s+/));
|
|
101
|
+
// Display labels are authored derivations of the canonical matching terms.
|
|
102
|
+
const DISPLAY_OVERRIDES = {
|
|
103
|
+
'check the': 'Check the…', 'read the': 'Read the…', 'look at': 'Look at…',
|
|
104
|
+
'can you': 'Can you…', lgtm: 'LGTM',
|
|
105
|
+
};
|
|
106
|
+
export const displayLexiconTerm = (term) => (Object.hasOwn(DISPLAY_OVERRIDES, term) ? DISPLAY_OVERRIDES[term] : undefined) ?? term.charAt(0).toUpperCase() + term.slice(1).replaceAll("'", '’');
|
|
107
|
+
export const LEXICON_DISPLAY = Object.fromEntries(CATEGORIES.flatMap(category => category.phrases.map(term => [term, displayLexiconTerm(term)])));
|
|
108
|
+
export const HEADLINE_TERMS = {
|
|
109
|
+
'agent-agree': ["you're absolutely right", 'you are absolutely right', "you're wrong"],
|
|
110
|
+
'agent-confident': ['perfect', 'excellent', 'production ready', 'all tests pass'],
|
|
111
|
+
praise: ['perfect', 'excellent'],
|
|
112
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { EMOJI_NAMES } from './emoji-names.js';
|
|
2
|
+
import { ACRONYMS, CATEGORIES } from './lexicons.js';
|
|
3
|
+
import { redact } from './redact.js';
|
|
4
|
+
import { STOPWORDS } from './stopwords.js';
|
|
5
|
+
import { SUPPRESSION } from './suppression.js';
|
|
6
|
+
export const MAX_MESSAGE_BYTES = 256 * 1024;
|
|
7
|
+
export const MAX_OPEN_WORD_CHARS = 20;
|
|
8
|
+
// I1: harness texts injected into the user role. The adapters drop them by flag (isMeta, isCompactSummary,
|
|
9
|
+
// isVisibleInTranscriptOnly …); these backstops drop them by their fixed opening when a flag is missing. Checked where
|
|
10
|
+
// the adapters hand text to the content sink, and again in the analyzer.
|
|
11
|
+
export const INJECTED_USER_TEXT = new RegExp('^\\s*(?:' + [
|
|
12
|
+
'This session is being continued from a previous conversation that ran out of context',
|
|
13
|
+
'Caveat: The messages below were generated by the user while running local commands',
|
|
14
|
+
'Base directory for this skill:',
|
|
15
|
+
'Another language model started to solve this problem',
|
|
16
|
+
'This is the Gemini CLI\\. We are setting up the context',
|
|
17
|
+
].join('|') + ')', 'i');
|
|
18
|
+
export const CONTENT_GATES = { minCount: 8, minSessions: 3, minDays: 2, maxChars: 32, maxCapitalizedShare: 0.5 };
|
|
19
|
+
export const CONTENT_FIELDS = ['human prompt text', 'agent reply text (prose blocks only)'];
|
|
20
|
+
// R2: read only to feed the phrase veto as keyed HMACs. Never counted, never stored. ("tool arguments" in
|
|
21
|
+
// CONTENT_EXCLUDED means they are never counted; the stored demo fixtures fix that list's wording.)
|
|
22
|
+
export const CONTENT_VETO_ONLY = ['path words in tool arguments', 'session and project folder names'];
|
|
23
|
+
export const CONTENT_EXCLUDED = ['tool arguments', 'tool output', 'file contents supplied by tools',
|
|
24
|
+
'thinking/reasoning blocks', 'system and metadata messages', 'compact summaries', 'replays',
|
|
25
|
+
'subagent-authored prompts'];
|
|
26
|
+
const ENGLISH_LENGTHS = {
|
|
27
|
+
please: 5, thanks: 9, 'sorry-user': 5, 'swear-mild': 10, 'swear-strong': 11,
|
|
28
|
+
why: 1, 'again-still': 6, 'not-working': 10, exasperation: 11, praise: 14, 'go-on': 17,
|
|
29
|
+
};
|
|
30
|
+
export const SWEARS = new Set(['swear-mild', 'swear-strong']);
|
|
31
|
+
export const censor = (term) => [...term].map((ch, i) => i === 0 || !/\p{L}/u.test(ch) ? ch : '*').join('');
|
|
32
|
+
export const fold = (s) => s.normalize('NFKC').replace(/[‘’ʼ']/g, "'").toLowerCase();
|
|
33
|
+
export const SCRIPTS = {
|
|
34
|
+
Latin: /\p{Script=Latin}/u, Cyrillic: /\p{Script=Cyrillic}/u, Han: /\p{Script=Han}/u,
|
|
35
|
+
Kana: /[\p{Script=Hiragana}\p{Script=Katakana}]/u, Hangul: /\p{Script=Hangul}/u,
|
|
36
|
+
Greek: /\p{Script=Greek}/u, Arabic: /\p{Script=Arabic}/u, Hebrew: /\p{Script=Hebrew}/u,
|
|
37
|
+
Devanagari: /\p{Script=Devanagari}/u, Thai: /\p{Script=Thai}/u,
|
|
38
|
+
};
|
|
39
|
+
export const THANKS_LANGUAGES = {
|
|
40
|
+
merci: 'fr', danke: 'de', gracias: 'es', grazie: 'it', obrigado: 'pt', obrigada: 'pt',
|
|
41
|
+
спасибо: 'ru', спс: 'ru', 谢谢: 'zh', 多谢: 'zh', ありがとう: 'ja', ありがとうございます: 'ja',
|
|
42
|
+
감사합니다: 'ko', 고마워: 'ko', teşekkürler: 'tr', dzięki: 'pl', 'dank je': 'nl',
|
|
43
|
+
};
|
|
44
|
+
export const categoriesFor = (preview = false) => preview ? CATEGORIES : CATEGORIES.map(category => ({
|
|
45
|
+
...category, phrases: category.phrases.slice(0, ENGLISH_LENGTHS[category.id] ?? category.phrases.length),
|
|
46
|
+
}));
|
|
47
|
+
const makeLexicon = (preview) => new Map(categoriesFor(preview).map(category => [category.id, {
|
|
48
|
+
...category, shown: new Set(category.phrases.map(term => category.censor ? censor(term) : term)),
|
|
49
|
+
}]));
|
|
50
|
+
export const LEXICONS = { 'lex-2026.1-en': makeLexicon(false), 'lex-2026.1-preview': makeLexicon(true) };
|
|
51
|
+
const stops = Object.fromEntries(Object.entries(STOPWORDS).map(([k, words]) => [k, new Set(words.map(fold))]));
|
|
52
|
+
const suppression = new Set([...SUPPRESSION, ...CATEGORIES.filter(c => SWEARS.has(c.id)).flatMap(c => c.phrases)]
|
|
53
|
+
.map(s => fold(s).replace(/[^\p{L}\p{M}' ]/gu, ' ').replace(/\s+/g, ' ').trim()));
|
|
54
|
+
export function isStopword(word, preview) {
|
|
55
|
+
const script = SCRIPTS.Kana.test(word) ? 'Kana' : SCRIPTS.Han.test(word) ? 'Han' :
|
|
56
|
+
SCRIPTS.Cyrillic.test(word) ? 'Cyrillic' : SCRIPTS.Hangul.test(word) ? 'Hangul' : preview ? 'Latin' : 'English';
|
|
57
|
+
return stops[script].has(word);
|
|
58
|
+
}
|
|
59
|
+
const SAFE_TOKEN = /^\p{L}[\p{L}\p{M}]*(?:'\p{L}[\p{L}\p{M}]*)*$/u;
|
|
60
|
+
export function validOpenTerm(term, preview) {
|
|
61
|
+
if (term.length > CONTENT_GATES.maxChars || term !== fold(term) || redact(term).hits)
|
|
62
|
+
return false;
|
|
63
|
+
const tokens = term.split(' ');
|
|
64
|
+
if (!tokens.every(token => token.length <= MAX_OPEN_WORD_CHARS && SAFE_TOKEN.test(token)) || isStopword(tokens.at(-1), preview))
|
|
65
|
+
return false;
|
|
66
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
67
|
+
for (let end = i + 1; end <= tokens.length; end++) {
|
|
68
|
+
if (suppression.has(tokens.slice(i, end).join(' ')))
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
export const validEmoji = (emoji) => emoji.length <= 32 && Object.hasOwn(EMOJI_NAMES, emoji) && /^(?:\p{RGI_Emoji})$/v.test(emoji);
|
|
75
|
+
export const isCapsWord = (word) => word.length >= 3 && word !== word.toLowerCase() &&
|
|
76
|
+
word === word.toUpperCase() && !ACRONYMS.has(word);
|
|
77
|
+
export const LEXICON_HASHES = { 'lex-2026.1-en': 'f27d6dccfb3c6b523f4a0cf745024fe6a2b1835e3ac8752501eded85015a3b20', 'lex-2026.1-preview': '6656ddea8eec067e331a20b0bcf2077a1aef0756db27c5b2a3969254c8ee97e1' };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// Secret, PII and identifier scrubber for prose lines.
|
|
2
|
+
// Rules are written for this prototype. Their categories follow gitleaks (MIT) and secretlint (MIT) rule families,
|
|
3
|
+
// but no rule file is copied. Over-redaction is the safe failure: a redacted word is only a lost joke.
|
|
4
|
+
//
|
|
5
|
+
// Every match is replaced by MARK, a private-use character the tokenizer treats as a hard boundary,
|
|
6
|
+
// so no n-gram can straddle a redaction and no fragment of a match is ever counted.
|
|
7
|
+
export const MARK = '';
|
|
8
|
+
// NFKC, then delete every format character (\p{Cf}: ZWSP, ZWJ, ZWNJ, WJ, SHY, BOM, bidi controls, tags) and every
|
|
9
|
+
// default-ignorable code point (variation selectors, U+034F, the Hangul fillers, U+17B4/5, the Mongolian selectors),
|
|
10
|
+
// so none of them can split or glue a secret past a rule. Runs before any redaction or classification. The one
|
|
11
|
+
// exception is a complete RGI emoji sequence (❤️, 👨💻, 🏴): it is a fixed Unicode list, a pictograph is a token
|
|
12
|
+
// boundary anyway, and deleting its ZWJ or VS16 would miscount it. Anywhere else, including next to an emoji, they go.
|
|
13
|
+
// U+2800 BRAILLE PATTERN BLANK is not default-ignorable but renders as nothing, so it goes too.
|
|
14
|
+
const FORMAT = /[\p{Cf}\p{Default_Ignorable_Code_Point}\u2800]/u;
|
|
15
|
+
const FORMAT_OUTSIDE_EMOJI = /(\p{RGI_Emoji})|[\p{Cf}\p{Default_Ignorable_Code_Point}\u2800]/gv;
|
|
16
|
+
export const normalizeContentText = (text) => {
|
|
17
|
+
const nfkc = text.normalize('NFKC');
|
|
18
|
+
return FORMAT.test(nfkc) ? nfkc.replace(FORMAT_OUTSIDE_EMOJI, (_m, emoji) => emoji ?? '') : nfkc;
|
|
19
|
+
};
|
|
20
|
+
export function shannon(value) {
|
|
21
|
+
const freq = new Map();
|
|
22
|
+
for (const ch of value)
|
|
23
|
+
freq.set(ch, (freq.get(ch) ?? 0) + 1);
|
|
24
|
+
let bits = 0;
|
|
25
|
+
for (const n of freq.values()) {
|
|
26
|
+
const p = n / value.length;
|
|
27
|
+
bits -= p * Math.log2(p);
|
|
28
|
+
}
|
|
29
|
+
return bits;
|
|
30
|
+
}
|
|
31
|
+
function luhn(raw) {
|
|
32
|
+
const digits = raw.replace(/\D/g, '');
|
|
33
|
+
if (digits.length < 13 || digits.length > 19)
|
|
34
|
+
return false;
|
|
35
|
+
let sum = 0;
|
|
36
|
+
for (let i = 0; i < digits.length; i++) {
|
|
37
|
+
let d = digits.charCodeAt(digits.length - 1 - i) - 48;
|
|
38
|
+
if (i % 2 === 1) {
|
|
39
|
+
d *= 2;
|
|
40
|
+
if (d > 9)
|
|
41
|
+
d -= 9;
|
|
42
|
+
}
|
|
43
|
+
sum += d;
|
|
44
|
+
}
|
|
45
|
+
return sum % 10 === 0;
|
|
46
|
+
}
|
|
47
|
+
const ipv4 = (m) => m.split('.').every(part => Number(part) <= 255);
|
|
48
|
+
const mixed = (m) => /[A-Za-z]/.test(m) && /\d/.test(m);
|
|
49
|
+
const TLD = 'com|net|org|io|dev|app|ai|co|local|internal|corp|lan|cloud|sh|me|xyz|gov|edu|uk|de|fr|ru|cn|jp|in|br|eu|us|ca|au|nl|se|ch|biz|info|tech|site|online';
|
|
50
|
+
const FILE_EXT = 'ts|tsx|js|jsx|mjs|cjs|py|rb|go|rs|java|kt|swift|c|h|cc|cpp|hpp|cs|php|vue|svelte|md|mdx|json|jsonl|ya?ml|toml|ini|env|lock|sql|sh|ps1|bat|css|scss|html|xml|csv|txt|log|png|jpe?g|svg|pdf|zip|tar|gz|db|sqlite|vscdb|dockerfile';
|
|
51
|
+
// Secret keywords for the `assignment` rule, with `pw`, `pin`, `passcode` and `passphrase` (R4). Recovery codes and
|
|
52
|
+
// seed phrases have their own rule, which takes the rest of the sentence.
|
|
53
|
+
const SECRET_KEYWORDS = 'api[ _-]?key|apikey|secret|token|passw(?:or)?d|passphrase|pwd|pw|pin|passcode|auth|credential|' +
|
|
54
|
+
'private[ _-]?key|access[ _-]?key';
|
|
55
|
+
// "password" in each language the lexicons cover: fr, de, es, it, pt, ru, zh, ja, ko, tr, pl, nl.
|
|
56
|
+
const FOREIGN_PASSWORD = 'mot de passe|passwort|kennwort|contraseña|clave|parola d\'ordine|senha|palavra-passe|пароль|' +
|
|
57
|
+
'密码|密碼|口令|パスワード|暗証番号|비밀번호|암호|패스워드|şifre|parola|hasło|wachtwoord';
|
|
58
|
+
// Every common quote pair, typographic and CJK included. Each body stops at its own closing quote or a newline. A
|
|
59
|
+
// straight or curly single quote may hold an apostrophe ('otter's lantern'), so those close only before a boundary.
|
|
60
|
+
const QUOTE_END = `(?=[\\s.,;:!?)\\]]|$)`;
|
|
61
|
+
const QUOTED = [
|
|
62
|
+
`"[^"\\r\\n]{1,200}"`, `'[^\\r\\n]{1,200}?'${QUOTE_END}`, `‘[^\\r\\n]{1,200}?’${QUOTE_END}`,
|
|
63
|
+
...['“”', '«»', '»«', '„“', '„”', '‚‘', '‹›', '「」', '『』'].map(([open, close]) => `${open}[^${close}\\r\\n]{1,200}${close}`),
|
|
64
|
+
].join('|');
|
|
65
|
+
// Order matters: specific secrets first, then structured PII, then identifiers, then generic entropy.
|
|
66
|
+
const RULES = [
|
|
67
|
+
{ id: 'rooted-path', cls: 'identifier', re: /(?:file:\/\/|\b[A-Za-z]:[\\/]|\\\\|~[\\/]|\.{1,2}[\\/]|%[A-Za-z_][A-Za-z0-9_]{0,40}%[\\/]|\b(?:OneDrive|SharePoint)\s+-\s+|(?<![\w:/])\/)(?:(?!\.(?=\s|$))[^"'<>\r\n!?。!?])+/gi },
|
|
68
|
+
{ id: 'private-key', cls: 'secret', re: /-----BEGIN [A-Z0-9 ]*PRIVATE KEY(?: BLOCK)?-----[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY(?: BLOCK)?-----|$)/g },
|
|
69
|
+
{ id: 'anthropic-key', cls: 'secret', re: /\bsk-ant-[A-Za-z0-9_-]{20,}/g },
|
|
70
|
+
{ id: 'openai-key', cls: 'secret', re: /\bsk-(?:proj-|svcacct-|admin-)?[A-Za-z0-9_-]{20,}/g },
|
|
71
|
+
{ id: 'aws-access-key', cls: 'secret', re: /\b(?:AKIA|ASIA|ABIA|ACCA|AGPA|AIDA|AROA)[A-Z0-9]{16}\b/g },
|
|
72
|
+
{ id: 'github-token', cls: 'secret', re: /\b(?:gh[pousr]_[A-Za-z0-9]{30,}|github_pat_[A-Za-z0-9_]{40,})\b/g },
|
|
73
|
+
{ id: 'gitlab-token', cls: 'secret', re: /\bglpat-[A-Za-z0-9_-]{20,}/g },
|
|
74
|
+
{ id: 'slack-token', cls: 'secret', re: /\bxox[abposr]-[A-Za-z0-9-]{10,}|https:\/\/hooks\.slack\.com\/services\/[A-Za-z0-9/]+/g },
|
|
75
|
+
{ id: 'stripe-key', cls: 'secret', re: /\b(?:sk|rk|pk)_(?:live|test)_[A-Za-z0-9]{16,}/g },
|
|
76
|
+
{ id: 'google-api-key', cls: 'secret', re: /\bAIza[0-9A-Za-z_-]{35}\b/g },
|
|
77
|
+
{ id: 'npm-token', cls: 'secret', re: /\bnpm_[A-Za-z0-9]{36}\b/g },
|
|
78
|
+
{ id: 'jwt', cls: 'secret', re: /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g },
|
|
79
|
+
{ id: 'url-credentials', cls: 'secret', re: /\b[a-z][a-z0-9+.-]{1,20}:\/\/[^\s:@/]+:[^\s@/]+@[^\s/]+\S*/gi },
|
|
80
|
+
{ id: 'bearer', cls: 'secret', re: /\b(?:Bearer|Basic|Token)\s+[A-Za-z0-9._~+/-]{16,}=*/g },
|
|
81
|
+
{ id: 'sensitive-value', cls: 'secret', re: /\b(?:sig|token|key|secret|password|auth)\s*=\s*(?:"[^"\r\n]*"|'[^'\r\n]*'|[^\s&#"',;]+)/gi },
|
|
82
|
+
{ id: 'assignment', cls: 'secret',
|
|
83
|
+
// A quoted value is taken whole, in any quote pair, so `password is “correct horse battery staple”` loses all
|
|
84
|
+
// four words. "the password for prod is …" allows up to three words between the keyword and the verb.
|
|
85
|
+
re: new RegExp(`\\b(?:[A-Za-z0-9]+[_-])*(?:${SECRET_KEYWORDS})s?\\b["'‘’“”]?(?:\\s+(?:for|to|of|on|at)(?:\\s+[^\\s:=]{1,40}){1,3}?)?\\s*(?:[:=]|=>|\\b(?:is|was|are|were)\\b)\\s*(?:${QUOTED}|["']?[^\\s"',;]{6,}["']?)`, 'gi') },
|
|
86
|
+
// A recovery or seed phrase is several ordinary words by design: take the rest of the sentence.
|
|
87
|
+
{ id: 'seed-phrase', cls: 'secret',
|
|
88
|
+
re: /\b(?:recovery|seed|mnemonic|backup)[ _-]?(?:phrase|words?|codes?)\b[^\S\r\n]*(?:[:=]|=>|\b(?:is|was|are|were)\b)?[^\S\r\n]*[^.!?\r\n]{1,300}/gi },
|
|
89
|
+
// The word for "password" in each language the lexicons cover, with that language's "is" or a colon.
|
|
90
|
+
{ id: 'password-word', cls: 'secret',
|
|
91
|
+
re: new RegExp(`(?<![\\p{L}\\p{M}])(?:${FOREIGN_PASSWORD})[^\\S\\r\\n]*(?:[::=—]|=>|(?:ist|est|es|é|è|is|jest|to|это)(?![\\p{L}\\p{M}])|[是为は는은이])[^\\S\\r\\n]*(?:${QUOTED}|[^\\s"',;]{4,})`, 'giu') },
|
|
92
|
+
// Unicode-aware, so a non-ASCII local part or domain (jane@acmé.com, иван@почта.рф) is removed whole. The
|
|
93
|
+
// lookbehind starts a match only at the beginning of a run, which keeps it linear.
|
|
94
|
+
{ id: 'email', cls: 'pii', re: /(?<![\p{L}\p{M}\p{N}._%+-])[\p{L}\p{M}\p{N}._%+-]+@[\p{L}\p{M}\p{N}-]+(?:\.[\p{L}\p{M}\p{N}-]+)+/gu },
|
|
95
|
+
{ id: 'url', cls: 'pii', re: /\b(?:https?|ftp|wss?|file|ssh|git):\/\/[^\s<>"'`)\]]+|\bwww\.[^\s<>"'`)\]]+/gi },
|
|
96
|
+
{ id: 'card-number', cls: 'pii', re: /\b(?:\d[ -]?){12,18}\d\b/g, check: luhn },
|
|
97
|
+
{ id: 'iban', cls: 'pii', re: /\b[A-Z]{2}\d{2}(?: ?[A-Z0-9]{4}){3,7}(?: ?[A-Z0-9]{1,4})?\b/g },
|
|
98
|
+
{ id: 'ssn-like', cls: 'pii', re: /\b\d{3}-\d{2}-\d{4}\b/g },
|
|
99
|
+
{ id: 'phone', cls: 'pii', re: /(?<![\w+])\+\d{1,3}(?:[ .-]\(?\d{1,4}\)?){2,5}(?!\d)|\(\d{3}\) ?\d{3}-\d{4}\b|\b\d{3}[.-]\d{3}[.-]\d{4}\b/g },
|
|
100
|
+
{ id: 'uuid', cls: 'identifier', re: /\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/gi },
|
|
101
|
+
{ id: 'mac', cls: 'identifier', re: /\b(?:[0-9a-f]{2}[:-]){5}[0-9a-f]{2}\b/gi },
|
|
102
|
+
{ id: 'ipv4', cls: 'pii', re: /\b(?:\d{1,3}\.){3}\d{1,3}(?::\d{1,5})?\b/g, check: m => ipv4(m.replace(/:\d+$/, '')) },
|
|
103
|
+
{ id: 'ipv6', cls: 'pii', re: /\b(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}\b|\b(?:[0-9a-f]{1,4}:){2,6}:(?:[0-9a-f]{1,4}(?::[0-9a-f]{1,4}){0,5})?\b/gi },
|
|
104
|
+
{ id: 'posix-path', cls: 'identifier', re: /(?:~|\.{1,2})?\/(?:[\w.@+-]+\/)+[\w.@+-]*|\b[\w.-]+\/[\w.-]+\/[\w./-]*/g },
|
|
105
|
+
{ id: 'file-name', cls: 'identifier', re: new RegExp(`\\b[\\w-]+(?:\\/[\\w.-]+)*\\.(?:${FILE_EXT})\\b`, 'gi') },
|
|
106
|
+
{ id: 'hostname', cls: 'identifier', re: new RegExp(`\\b(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+(?:${TLD})\\b`, 'gi') },
|
|
107
|
+
{ id: 'handle', cls: 'identifier', re: /(?<![\w.])@[A-Za-z0-9_][A-Za-z0-9_.-]{1,38}/g },
|
|
108
|
+
{ id: 'hex-id', cls: 'identifier', re: /\b[0-9a-f]{12,}\b/gi, check: m => /\d/.test(m) && /[a-f]/i.test(m) },
|
|
109
|
+
{ id: 'long-number', cls: 'identifier', re: /\b\d{6,}\b/g },
|
|
110
|
+
{ id: 'high-entropy', cls: 'secret', re: /[A-Za-z0-9+/_=-]{20,}/g,
|
|
111
|
+
check: m => mixed(m) && shannon(m) >= (m.length >= 32 ? 3.7 : 3.4) },
|
|
112
|
+
{ id: 'letters-secret', cls: 'secret', re: /\b[A-Za-z]{16,}\b/g,
|
|
113
|
+
check: m => /[a-z][A-Z]/.test(m) || shannon(m) >= 3.4 },
|
|
114
|
+
];
|
|
115
|
+
export const RULE_IDS = RULES.map(rule => rule.id);
|
|
116
|
+
export const RULE_CLASS = { 'pgp-block': 'secret', certificate: 'identifier', ...Object.fromEntries(RULES.map(rule => [rule.id, rule.cls])) };
|
|
117
|
+
const quick = /[@:/\\.\d_=-]|[A-Z]{4}|eyJ|BEGIN|[A-Za-z]{16}/;
|
|
118
|
+
// The assignment rule's `is` form needs no punctuation, so its keywords trigger the rules on their own.
|
|
119
|
+
const quickKeyword = new RegExp(`\\b(?:key|mnemonic|backup|seed|recovery|${SECRET_KEYWORDS})s?\\b|${FOREIGN_PASSWORD}`, 'i');
|
|
120
|
+
const lastSeparator = /^(.*[\\/][^\s\\/]*)/s;
|
|
121
|
+
export function redact(input, listener) {
|
|
122
|
+
let text = normalizeContentText(input);
|
|
123
|
+
if (!quick.test(text) && !quickKeyword.test(text))
|
|
124
|
+
return { text, hits: null };
|
|
125
|
+
let hits = null;
|
|
126
|
+
for (const rule of RULES) {
|
|
127
|
+
rule.re.lastIndex = 0;
|
|
128
|
+
if (!rule.re.test(text))
|
|
129
|
+
continue;
|
|
130
|
+
rule.re.lastIndex = 0;
|
|
131
|
+
text = text.replace(rule.re, match => {
|
|
132
|
+
if (rule.check && !rule.check(match))
|
|
133
|
+
return match;
|
|
134
|
+
hits ??= {};
|
|
135
|
+
hits[rule.id] = (hits[rule.id] ?? 0) + 1;
|
|
136
|
+
if (listener)
|
|
137
|
+
listener(rule.id, rule.id === 'rooted-path' ? lastSeparator.exec(match)?.[1] ?? match : match);
|
|
138
|
+
return MARK;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return { text, hits };
|
|
142
|
+
}
|
|
143
|
+
// Multi-line secrets must be removed before the text is split into lines, or the header, body and footer
|
|
144
|
+
// would each be judged alone. Runs once per message on the raw text.
|
|
145
|
+
const BLOCKS = [
|
|
146
|
+
{ id: 'private-key', cls: 'secret', re: /-----BEGIN [A-Z0-9 ]*PRIVATE KEY(?: BLOCK)?-----[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY(?: BLOCK)?-----|$)/g },
|
|
147
|
+
{ id: 'pgp-block', cls: 'secret', re: /-----BEGIN PGP [A-Z ]+-----[\s\S]*?(?:-----END PGP [A-Z ]+-----|$)/g },
|
|
148
|
+
{ id: 'certificate', cls: 'identifier', re: /-----BEGIN CERTIFICATE-----[\s\S]*?(?:-----END CERTIFICATE-----|$)/g },
|
|
149
|
+
];
|
|
150
|
+
export function redactBlocks(input) {
|
|
151
|
+
input = normalizeContentText(input);
|
|
152
|
+
if (!input.includes('-----BEGIN '))
|
|
153
|
+
return { text: input, hits: null };
|
|
154
|
+
let text = input;
|
|
155
|
+
let hits = null;
|
|
156
|
+
for (const rule of BLOCKS) {
|
|
157
|
+
text = text.replace(rule.re, () => {
|
|
158
|
+
hits ??= {};
|
|
159
|
+
hits[rule.id] = (hits[rule.id] ?? 0) + 1;
|
|
160
|
+
return MARK;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return { text, hits };
|
|
164
|
+
}
|