@evomap/evolver 1.89.20 → 2.0.0-beta.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/README.md +27 -564
- package/bin/evolver-llm-proxy.js +3 -0
- package/bin/evolver-mcp.js +2 -0
- package/bin/evolver-proxy.js +3 -0
- package/bin/evolver.js +4 -0
- package/index.js +1 -3586
- package/package.json +32 -62
- package/CONTRIBUTING.md +0 -19
- package/LICENSE +0 -641
- package/README.ja-JP.md +0 -521
- package/README.ko-KR.md +0 -520
- package/README.zh-CN.md +0 -531
- package/SKILL.md +0 -365
- package/assets/cover.png +0 -0
- package/assets/gep/genes.seed.json +0 -496
- package/conformance/savings-core/constants.json +0 -30
- package/conformance/savings-core/golden-vectors.json +0 -333
- package/scripts/a2a_export.js +0 -63
- package/scripts/a2a_ingest.js +0 -79
- package/scripts/a2a_promote.js +0 -118
- package/scripts/analyze_by_skill.js +0 -121
- package/scripts/build_binaries.js +0 -479
- package/scripts/check-changelog.js +0 -166
- package/scripts/extract_log.js +0 -85
- package/scripts/generate_history.js +0 -75
- package/scripts/gep_append_event.js +0 -96
- package/scripts/gep_personality_report.js +0 -234
- package/scripts/human_report.js +0 -147
- package/scripts/recall-verify-report.js +0 -234
- package/scripts/recover_loop.js +0 -61
- package/scripts/refresh_stars_badge.js +0 -168
- package/scripts/seed-merchants.js +0 -91
- package/scripts/skill2recipes.js +0 -118
- package/scripts/suggest_version.js +0 -89
- package/scripts/validate-modules.js +0 -38
- package/scripts/validate-suite.js +0 -78
- package/skills/_meta/SKILL.md +0 -41
- package/skills/index.json +0 -14
- package/src/adapters/claudeCode.js +0 -194
- package/src/adapters/codex.js +0 -216
- package/src/adapters/cursor.js +0 -91
- package/src/adapters/hookAdapter.js +0 -469
- package/src/adapters/kiro.js +0 -195
- package/src/adapters/opencode.js +0 -326
- package/src/adapters/scripts/_lockPaths.js +0 -74
- package/src/adapters/scripts/_memoryFiltering.js +0 -35
- package/src/adapters/scripts/_runtimePaths.js +0 -440
- package/src/adapters/scripts/evolver-session-end.js +0 -321
- package/src/adapters/scripts/evolver-session-start.js +0 -587
- package/src/adapters/scripts/evolver-signal-detect.js +0 -98
- package/src/adapters/scripts/evolver-task-recall.js +0 -173
- package/src/atp/atpExecute.js +0 -283
- package/src/atp/atpTaskPickup.js +0 -233
- package/src/atp/autoBuyer.js +0 -382
- package/src/atp/autoDeliver.js +0 -215
- package/src/atp/cli.js +0 -354
- package/src/atp/cliAutobuyPrompt.js +0 -154
- package/src/atp/consumerAgent.js +0 -157
- package/src/atp/defaultHandler.js +0 -69
- package/src/atp/heartbeatSignalsHandler.js +0 -254
- package/src/atp/hubClient.js +0 -317
- package/src/atp/index.js +0 -38
- package/src/atp/merchantAgent.js +0 -118
- package/src/atp/protocol.js +0 -41
- package/src/atp/questionComposer.js +0 -133
- package/src/atp/serviceHelper.js +0 -92
- package/src/canary.js +0 -13
- package/src/config.js +0 -351
- package/src/evolve/guards.js +0 -1
- package/src/evolve/pipeline/collect.js +0 -1
- package/src/evolve/pipeline/dispatch.js +0 -1
- package/src/evolve/pipeline/enrich.js +0 -1
- package/src/evolve/pipeline/hub.js +0 -1
- package/src/evolve/pipeline/select.js +0 -1
- package/src/evolve/pipeline/signals.js +0 -1
- package/src/evolve/utils.js +0 -1
- package/src/evolve.js +0 -1
- package/src/experiment/agentRunner.js +0 -229
- package/src/experiment/cli.js +0 -159
- package/src/experiment/comparison.js +0 -233
- package/src/experiment/metrics.js +0 -75
- package/src/forceUpdate.js +0 -991
- package/src/gep/a2a.js +0 -173
- package/src/gep/a2aProtocol.js +0 -1
- package/src/gep/analyzer.js +0 -35
- package/src/gep/antiAbuseTelemetry.js +0 -1
- package/src/gep/assetCallLog.js +0 -197
- package/src/gep/assetStore.js +0 -723
- package/src/gep/assets.js +0 -36
- package/src/gep/autoDistillConv.js +0 -1
- package/src/gep/autoDistillLlm.js +0 -1
- package/src/gep/bridge.js +0 -138
- package/src/gep/candidateEval.js +0 -1
- package/src/gep/candidates.js +0 -1
- package/src/gep/claimNudge.js +0 -121
- package/src/gep/cliContracts.js +0 -1190
- package/src/gep/contentHash.js +0 -1
- package/src/gep/conversationDistiller.js +0 -1
- package/src/gep/conversationSniffer.js +0 -1
- package/src/gep/crypto.js +0 -1
- package/src/gep/curriculum.js +0 -1
- package/src/gep/deviceId.js +0 -1
- package/src/gep/directoryClient.js +0 -115
- package/src/gep/envFingerprint.js +0 -1
- package/src/gep/epigenetics.js +0 -1
- package/src/gep/execBridge.js +0 -1
- package/src/gep/executionTrace.js +0 -291
- package/src/gep/explore.js +0 -1
- package/src/gep/featureFlags.js +0 -121
- package/src/gep/gitOps.js +0 -265
- package/src/gep/hash.js +0 -1
- package/src/gep/hostErrorClassifier.js +0 -34
- package/src/gep/hubFetch.js +0 -1
- package/src/gep/hubReview.js +0 -1
- package/src/gep/hubSearch.js +0 -1
- package/src/gep/hubVerify.js +0 -1
- package/src/gep/idleScheduler.js +0 -400
- package/src/gep/issueReporter.js +0 -416
- package/src/gep/learningSignals.js +0 -1
- package/src/gep/llmReview.js +0 -92
- package/src/gep/localStateAwareness.js +0 -243
- package/src/gep/mailboxTransport.js +0 -119
- package/src/gep/memoryGraph.js +0 -1
- package/src/gep/memoryGraphAdapter.js +0 -1
- package/src/gep/mutation.js +0 -1
- package/src/gep/narrativeMemory.js +0 -1
- package/src/gep/oauthLogin.js +0 -181
- package/src/gep/openPRRegistry.js +0 -1
- package/src/gep/paths.js +0 -522
- package/src/gep/personality.js +0 -1
- package/src/gep/policyCheck.js +0 -1
- package/src/gep/portable.js +0 -103
- package/src/gep/privacyClient.js +0 -235
- package/src/gep/prompt.js +0 -1
- package/src/gep/questionGenerator.js +0 -518
- package/src/gep/recallInject.js +0 -1
- package/src/gep/recallVerifier.js +0 -1
- package/src/gep/reflection.js +0 -1
- package/src/gep/sanitize.js +0 -264
- package/src/gep/savingsCore.js +0 -1
- package/src/gep/schemas/capsule.js +0 -170
- package/src/gep/schemas/gene.js +0 -154
- package/src/gep/schemas/index.js +0 -8
- package/src/gep/schemas/protocol.js +0 -51
- package/src/gep/schemas/task.js +0 -74
- package/src/gep/selector.js +0 -1
- package/src/gep/selfPR.js +0 -469
- package/src/gep/signals.js +0 -776
- package/src/gep/skill2gep.js +0 -1056
- package/src/gep/skill2gepAudit.js +0 -303
- package/src/gep/skill2recipes.js +0 -511
- package/src/gep/skillDistiller.js +0 -1
- package/src/gep/skillPublisher.js +0 -358
- package/src/gep/solidify.js +0 -1
- package/src/gep/strategy.js +0 -1
- package/src/gep/taskReceiver.js +0 -575
- package/src/gep/tokenSavings.js +0 -1
- package/src/gep/trajectoryExport.js +0 -1
- package/src/gep/validationReport.js +0 -55
- package/src/gep/validator/index.js +0 -411
- package/src/gep/validator/reporter.js +0 -210
- package/src/gep/validator/sandboxExecutor.js +0 -480
- package/src/gep/validator/stakeBootstrap.js +0 -357
- package/src/gep/workspaceKeychain.js +0 -1
- package/src/ops/cleanup.js +0 -80
- package/src/ops/commentary.js +0 -60
- package/src/ops/health_check.js +0 -104
- package/src/ops/index.js +0 -11
- package/src/ops/innovation.js +0 -67
- package/src/ops/lifecycle.js +0 -798
- package/src/ops/self_repair.js +0 -76
- package/src/ops/skills_monitor.js +0 -147
- package/src/ops/trigger.js +0 -33
- package/src/proxy/clientSettings.js +0 -405
- package/src/proxy/envelope.js +0 -59
- package/src/proxy/extensions/dmHandler.js +0 -45
- package/src/proxy/extensions/sessionHandler.js +0 -141
- package/src/proxy/extensions/skillUpdater.js +0 -64
- package/src/proxy/extensions/traceControl.js +0 -1
- package/src/proxy/index.js +0 -1395
- package/src/proxy/inject.js +0 -1
- package/src/proxy/lifecycle/manager.js +0 -1568
- package/src/proxy/mailbox/state.js +0 -207
- package/src/proxy/mailbox/store.js +0 -590
- package/src/proxy/router/cache_passthrough.js +0 -26
- package/src/proxy/router/features.js +0 -84
- package/src/proxy/router/gemini_route.js +0 -154
- package/src/proxy/router/messages_route.js +0 -535
- package/src/proxy/router/model_router.js +0 -113
- package/src/proxy/router/models_route.js +0 -52
- package/src/proxy/router/ollama_route.js +0 -103
- package/src/proxy/router/responses_route.js +0 -170
- package/src/proxy/router/vertex_route.js +0 -110
- package/src/proxy/server/http.js +0 -363
- package/src/proxy/server/routes.js +0 -558
- package/src/proxy/server/settings.js +0 -115
- package/src/proxy/sync/engine.js +0 -179
- package/src/proxy/sync/inbound.js +0 -211
- package/src/proxy/sync/outbound.js +0 -320
- package/src/proxy/task/monitor.js +0 -131
- package/src/proxy/trace/extractor.js +0 -1
- package/src/proxy/trace/usage.js +0 -1
- package/src/webui/client/clientJs/assets.js +0 -111
- package/src/webui/client/clientJs/bootstrap.js +0 -92
- package/src/webui/client/clientJs/common.js +0 -77
- package/src/webui/client/clientJs/i18n.js +0 -366
- package/src/webui/client/clientJs/index.js +0 -35
- package/src/webui/client/clientJs/interactions.js +0 -351
- package/src/webui/client/clientJs/overview.js +0 -152
- package/src/webui/client/clientJs/personality.js +0 -285
- package/src/webui/client/clientJs/pipelines.js +0 -330
- package/src/webui/client/indexHtml.js +0 -221
- package/src/webui/client/static.js +0 -23
- package/src/webui/client/stylesCss.js +0 -639
- package/src/webui/client/vendor/README.md +0 -15
- package/src/webui/client/vendor/echarts.min.js +0 -45
- package/src/webui/index.js +0 -14
- package/src/webui/observer/assets.js +0 -146
- package/src/webui/observer/index.js +0 -37
- package/src/webui/observer/interactions.js +0 -127
- package/src/webui/observer/jsonl.js +0 -75
- package/src/webui/observer/paths.js +0 -46
- package/src/webui/observer/personality.js +0 -43
- package/src/webui/observer/pipelineEvents.js +0 -58
- package/src/webui/observer/redact.js +0 -63
- package/src/webui/observer/runs.js +0 -356
- package/src/webui/observer/safety.js +0 -57
- package/src/webui/observer/skills.js +0 -70
- package/src/webui/observer/status.js +0 -71
- package/src/webui/server/http.js +0 -138
- package/src/webui/server/routes.js +0 -41
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// skill2gepAudit.js -- Mechanical leakage audit for skill2gep.
|
|
4
|
-
//
|
|
5
|
-
// This is a JS port of Gene-Bench's Stage-3 leakage audit
|
|
6
|
-
// (eval/evolve_genes_v3.py: build_private_vocab / find_mechanical_leakage /
|
|
7
|
-
// redact_private_literals). It is a PURELY mechanical set-difference: it never
|
|
8
|
-
// reasons about meaning, only about literals.
|
|
9
|
-
//
|
|
10
|
-
// private tokens = (hard literals that appear in the run's HIDDEN text:
|
|
11
|
-
// the final solution, verifier feedback, raw stdout/stderr)
|
|
12
|
-
// - (hard literals that already appear in the PUBLIC SKILL.md)
|
|
13
|
-
//
|
|
14
|
-
// Any Gene string containing a private token is either redacted (default) or
|
|
15
|
-
// reported so the caller can refuse to publish. "Hard" literals are the ones
|
|
16
|
-
// most likely to encode an answer or a private contract constant:
|
|
17
|
-
// - multi-digit numbers (single digits are ubiquitous scaffolding),
|
|
18
|
-
// - quoted strings that look structured (identifiers, paths, enums),
|
|
19
|
-
// - CLI flags (--foo),
|
|
20
|
-
// - bare structured tokens (snake_case, dotted, slashed, SCREAMING_CASE).
|
|
21
|
-
//
|
|
22
|
-
// Public code contracts (file names, column names, CLI flags that appear in
|
|
23
|
-
// the Skill itself) are deliberately allowed through: forbidding them would
|
|
24
|
-
// make code Genes too vague to be useful, exactly as the reference notes.
|
|
25
|
-
|
|
26
|
-
const NUM_RE = /-?\d+(?:\.\d+)?/g;
|
|
27
|
-
const QUOTED_RE = /['"]([^'"]{2,64})['"]/g;
|
|
28
|
-
const CODE_SPAN_RE = /(?<!`)`([^`\n]{2,80})`(?!`)/g;
|
|
29
|
-
const FLAG_RE = /--[a-z][a-z0-9_-]*[a-z0-9]/g;
|
|
30
|
-
const WORD_RE = /[A-Za-z][A-Za-z0-9_]{2,}/g;
|
|
31
|
-
const BARE_STRUCTURED_RE =
|
|
32
|
-
/(?<![A-Za-z0-9_./\\-])[A-Za-z0-9][A-Za-z0-9_./\\-]{1,80}(?![A-Za-z0-9_./\\-])/g;
|
|
33
|
-
|
|
34
|
-
// Generic English / Python / benchmark-scaffold stopwords. NOT domain-specific.
|
|
35
|
-
// Mirrors the reference _STOPWORDS set so the audit behaves the same.
|
|
36
|
-
const STOPWORDS = new Set([
|
|
37
|
-
'the', 'and', 'for', 'with', 'that', 'this', 'from', 'into', 'your', 'you',
|
|
38
|
-
'are', 'not', 'use', 'using', 'must', 'should', 'will', 'can', 'may', 'any',
|
|
39
|
-
'all', 'each', 'one', 'two', 'given', 'input', 'output', 'value', 'values',
|
|
40
|
-
'result', 'results', 'return', 'returns', 'function', 'functions', 'code',
|
|
41
|
-
'task', 'tasks', 'test', 'tests', 'assert', 'import', 'def', 'class', 'self',
|
|
42
|
-
'true', 'false', 'none', 'print', 'data', 'list', 'dict', 'string', 'str',
|
|
43
|
-
'int', 'float', 'bool', 'file', 'files', 'path', 'line', 'lines', 'answer',
|
|
44
|
-
'analysis', 'solution', 'program', 'python', 'run', 'running', 'expected',
|
|
45
|
-
'actual', 'case', 'cases', 'example', 'examples', 'following', 'above',
|
|
46
|
-
'below', 'number', 'numbers', 'set', 'get', 'name', 'names', 'format',
|
|
47
|
-
'required', 'exactly', 'scenario', 'problem', 'compute', 'calculate',
|
|
48
|
-
]);
|
|
49
|
-
|
|
50
|
-
function isTrivialNumber(tok) {
|
|
51
|
-
// Single-digit integers are loop bounds / "step 1" scaffolding and almost
|
|
52
|
-
// always appear in the public text too; treating them as private only
|
|
53
|
-
// creates false positives.
|
|
54
|
-
if (tok.indexOf('.') !== -1) return false;
|
|
55
|
-
const n = Number(tok);
|
|
56
|
-
return Number.isInteger(n) && Math.abs(n) < 10;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function isStructuredLiteral(tok) {
|
|
60
|
-
const s = String(tok || '').trim();
|
|
61
|
-
if (!s) return false;
|
|
62
|
-
if (new RegExp('^' + escapeRe(s) + '$').test(s) && NUM_RE_full(s)) {
|
|
63
|
-
return !isTrivialNumber(s);
|
|
64
|
-
}
|
|
65
|
-
if (s.startsWith('--')) return true;
|
|
66
|
-
if (/[0-9]/.test(s)) return true;
|
|
67
|
-
if (s.indexOf('_') !== -1 || s.indexOf('.') !== -1 || s.indexOf('/') !== -1 || s.indexOf('\\') !== -1) return true;
|
|
68
|
-
if (/^[A-Z][A-Z0-9_-]{2,}$/.test(s)) return true;
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Helper: does the whole string parse as a single number? (re.fullmatch on _NUM_RE)
|
|
73
|
-
function NUM_RE_full(s) {
|
|
74
|
-
return /^-?\d+(?:\.\d+)?$/.test(s);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function escapeRe(s) {
|
|
78
|
-
return String(s).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function words(text) {
|
|
82
|
-
const out = new Set();
|
|
83
|
-
const matches = String(text || '').match(WORD_RE) || [];
|
|
84
|
-
for (const w of matches) {
|
|
85
|
-
const lw = w.toLowerCase();
|
|
86
|
-
if (!STOPWORDS.has(lw)) out.add(lw);
|
|
87
|
-
}
|
|
88
|
-
return out;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function alnumCount(s) {
|
|
92
|
-
const m = String(s).match(/[a-z0-9]/gi);
|
|
93
|
-
return m ? m.length : 0;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Return { words: Set, hard: Set } where hard are leakage-relevant literals.
|
|
97
|
-
function contentTokens(text) {
|
|
98
|
-
const t = String(text || '');
|
|
99
|
-
const w = words(t);
|
|
100
|
-
const hard = new Set();
|
|
101
|
-
|
|
102
|
-
let m;
|
|
103
|
-
NUM_RE.lastIndex = 0;
|
|
104
|
-
while ((m = NUM_RE.exec(t)) !== null) {
|
|
105
|
-
if (!isTrivialNumber(m[0])) hard.add(m[0]);
|
|
106
|
-
}
|
|
107
|
-
QUOTED_RE.lastIndex = 0;
|
|
108
|
-
while ((m = QUOTED_RE.exec(t)) !== null) {
|
|
109
|
-
const q = m[1].trim().toLowerCase();
|
|
110
|
-
if (alnumCount(q) >= 3 && !STOPWORDS.has(q) && isStructuredLiteral(q)) hard.add(q);
|
|
111
|
-
}
|
|
112
|
-
CODE_SPAN_RE.lastIndex = 0;
|
|
113
|
-
while ((m = CODE_SPAN_RE.exec(t)) !== null) {
|
|
114
|
-
const q = m[1].trim().toLowerCase();
|
|
115
|
-
if (alnumCount(q) >= 3 && !STOPWORDS.has(q) && isStructuredLiteral(q)) hard.add(q);
|
|
116
|
-
}
|
|
117
|
-
const flags = t.toLowerCase().match(FLAG_RE) || [];
|
|
118
|
-
for (const f of flags) hard.add(f);
|
|
119
|
-
|
|
120
|
-
return { words: w, hard: hard };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Hard literals visible in the public SKILL.md. Public contracts are often
|
|
124
|
-
// written as bare structured strings (headings, prose), not just code spans,
|
|
125
|
-
// so we treat those as public too -- otherwise the audit would falsely reject
|
|
126
|
-
// useful code Genes that mention a file/column the solver is allowed to see.
|
|
127
|
-
function publicHardTokens(text) {
|
|
128
|
-
const { hard } = contentTokens(text);
|
|
129
|
-
const t = String(text || '');
|
|
130
|
-
let m;
|
|
131
|
-
BARE_STRUCTURED_RE.lastIndex = 0;
|
|
132
|
-
while ((m = BARE_STRUCTURED_RE.exec(t)) !== null) {
|
|
133
|
-
const tok = m[0].replace(/^[`'".,:;()[\]{}<>]+|[`'".,:;()[\]{}<>]+$/g, '').toLowerCase();
|
|
134
|
-
if (alnumCount(tok) >= 2 && !STOPWORDS.has(tok) && isStructuredLiteral(tok)) hard.add(tok);
|
|
135
|
-
}
|
|
136
|
-
return hard;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Concatenate the run's hidden text: the final solution plus any verifier
|
|
140
|
-
// feedback / stdout / stderr captured in the execution trace. These are the
|
|
141
|
-
// surfaces from which an agent might copy an answer constant into the Gene.
|
|
142
|
-
function hiddenBlob(execution) {
|
|
143
|
-
const ex = execution || {};
|
|
144
|
-
const parts = [];
|
|
145
|
-
if (ex.final_solution) parts.push(String(ex.final_solution));
|
|
146
|
-
if (ex.content_summary) parts.push(String(ex.content_summary));
|
|
147
|
-
const trace = Array.isArray(ex.trace) ? ex.trace : [];
|
|
148
|
-
for (const t of trace) {
|
|
149
|
-
if (t && t.stdout_tail) parts.push(String(t.stdout_tail));
|
|
150
|
-
if (t && t.stderr_tail) parts.push(String(t.stderr_tail));
|
|
151
|
-
}
|
|
152
|
-
const rollouts = Array.isArray(ex.rollouts) ? ex.rollouts : [];
|
|
153
|
-
for (const r of rollouts) {
|
|
154
|
-
if (r && r.feedback_tail) parts.push(String(r.feedback_tail));
|
|
155
|
-
}
|
|
156
|
-
// mutation_log error categories are copied verbatim into _source.overcame_errors
|
|
157
|
-
// and paraphrased into preconditions, so any private constant embedded in an
|
|
158
|
-
// error label (e.g. "threshold_202_exceeded") must be treated as a hidden
|
|
159
|
-
// source. Plain snake_case names are not "hard" literals and never enter the
|
|
160
|
-
// vocab, so this only catches genuinely private embedded constants.
|
|
161
|
-
const mutationLog = Array.isArray(ex.mutation_log) ? ex.mutation_log : [];
|
|
162
|
-
for (const e of mutationLog) parts.push(String(e || ''));
|
|
163
|
-
return parts.join('\n');
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// private = hidden hard tokens - public hard tokens.
|
|
167
|
-
function buildPrivateVocab(skillMd, execution) {
|
|
168
|
-
const publicHard = publicHardTokens(skillMd);
|
|
169
|
-
const { hard: hiddenHard } = contentTokens(hiddenBlob(execution));
|
|
170
|
-
const out = new Set();
|
|
171
|
-
for (const tok of hiddenHard) {
|
|
172
|
-
if (!publicHard.has(tok)) out.add(tok);
|
|
173
|
-
}
|
|
174
|
-
return out;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Walk every leaf string in a Gene payload, yielding [location, value].
|
|
178
|
-
function iterPayloadStrings(payload) {
|
|
179
|
-
const out = [];
|
|
180
|
-
const fields = ['summary', 'category'];
|
|
181
|
-
for (const f of fields) {
|
|
182
|
-
if (typeof payload[f] === 'string') out.push([f, payload[f]]);
|
|
183
|
-
}
|
|
184
|
-
for (const f of ['signals_match', 'strategy', 'preconditions', 'avoid', 'validation']) {
|
|
185
|
-
const arr = payload[f];
|
|
186
|
-
if (Array.isArray(arr)) {
|
|
187
|
-
arr.forEach((v, i) => { if (typeof v === 'string') out.push([f + '[' + i + ']', v]); });
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
// _source.overcame_errors is published metadata copied straight from
|
|
191
|
-
// mutation_log; scan it too so an embedded private constant cannot ride
|
|
192
|
-
// through there after the visible fields are redacted.
|
|
193
|
-
const src = payload._source;
|
|
194
|
-
if (src && Array.isArray(src.overcame_errors)) {
|
|
195
|
-
src.overcame_errors.forEach((v, i) => {
|
|
196
|
-
if (typeof v === 'string') out.push(['_source.overcame_errors[' + i + ']', v]);
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
return out;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
function tokenHits(value, tok) {
|
|
203
|
-
const low = String(value).toLowerCase();
|
|
204
|
-
if (alnumCount(tok) < 2) return false;
|
|
205
|
-
if (/[a-z]/i.test(tok)) {
|
|
206
|
-
return new RegExp('(?<![A-Za-z0-9_])' + escapeRe(tok) + '(?![A-Za-z0-9_])', 'i').test(low);
|
|
207
|
-
}
|
|
208
|
-
return new RegExp('(?<![A-Za-z0-9_.])' + escapeRe(tok) + '(?![A-Za-z0-9_.])').test(String(value));
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Return [{ token, location }] for every private literal found in the Gene.
|
|
212
|
-
function findLeakage(payload, privateVocab) {
|
|
213
|
-
if (!privateVocab || privateVocab.size === 0) return [];
|
|
214
|
-
const leaks = [];
|
|
215
|
-
const seen = new Set();
|
|
216
|
-
for (const [loc, value] of iterPayloadStrings(payload)) {
|
|
217
|
-
for (const tok of privateVocab) {
|
|
218
|
-
if (tokenHits(value, tok)) {
|
|
219
|
-
const key = tok + '|' + loc;
|
|
220
|
-
if (!seen.has(key)) { seen.add(key); leaks.push({ token: tok, location: loc }); }
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return leaks;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function literalReplacement(tok) {
|
|
228
|
-
if (NUM_RE_full(tok)) return 'the task-specific numeric value';
|
|
229
|
-
if (tok.indexOf('/') !== -1 || tok.indexOf('\\') !== -1 || tok.indexOf('.') !== -1) return 'the task-specified file or path';
|
|
230
|
-
if (tok.indexOf('_') !== -1) return 'the task-specific field';
|
|
231
|
-
return 'the task-specific term';
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function replaceLiteral(text, tok) {
|
|
235
|
-
const replacement = literalReplacement(tok);
|
|
236
|
-
if (/[a-z]/i.test(tok)) {
|
|
237
|
-
return String(text).replace(new RegExp('(?<![A-Za-z0-9_])' + escapeRe(tok) + '(?![A-Za-z0-9_])', 'ig'), replacement);
|
|
238
|
-
}
|
|
239
|
-
return String(text).replace(new RegExp('(?<![A-Za-z0-9_.])' + escapeRe(tok) + '(?![A-Za-z0-9_.])', 'g'), replacement);
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// Return a copy of the Gene with every private literal generalized. Longer
|
|
243
|
-
// tokens are replaced first so a shorter token can't partially clobber a
|
|
244
|
-
// longer one. Used only after a leak is detected; safer than discarding an
|
|
245
|
-
// otherwise-reusable payload.
|
|
246
|
-
function redactPrivateLiterals(payload, privateVocab) {
|
|
247
|
-
const out = JSON.parse(JSON.stringify(payload));
|
|
248
|
-
const toks = Array.from(privateVocab || []).sort((a, b) => b.length - a.length);
|
|
249
|
-
// String fields. `category` is an enum so it never actually leaks, but we
|
|
250
|
-
// process it anyway to stay symmetric with findLeakage (which scans it).
|
|
251
|
-
for (const f of ['summary', 'category']) {
|
|
252
|
-
if (typeof out[f] === 'string') {
|
|
253
|
-
for (const tok of toks) out[f] = replaceLiteral(out[f], tok);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
for (const f of ['signals_match', 'strategy', 'preconditions', 'avoid']) {
|
|
257
|
-
if (Array.isArray(out[f])) {
|
|
258
|
-
out[f] = out[f].map((item) => {
|
|
259
|
-
if (typeof item !== 'string') return item;
|
|
260
|
-
let v = item;
|
|
261
|
-
for (const tok of toks) v = replaceLiteral(v, tok);
|
|
262
|
-
return v;
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
// Validation commands must stay runnable, so we cannot rewrite a private
|
|
267
|
-
// literal into prose. Instead drop any command that contains one -- an empty
|
|
268
|
-
// validation list is the correct, safe outcome (matches the Gene-Bench
|
|
269
|
-
// contract that a Gene may legitimately have no validation).
|
|
270
|
-
if (Array.isArray(out.validation)) {
|
|
271
|
-
out.validation = out.validation.filter((cmd) => {
|
|
272
|
-
if (typeof cmd !== 'string') return false;
|
|
273
|
-
return !toks.some((tok) => tokenHits(cmd, tok));
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
// _source.overcame_errors mirrors mutation_log; generalize private literals
|
|
277
|
-
// embedded in an error label so the published metadata cannot leak them.
|
|
278
|
-
if (out._source && Array.isArray(out._source.overcame_errors)) {
|
|
279
|
-
out._source.overcame_errors = out._source.overcame_errors.map((item) => {
|
|
280
|
-
if (typeof item !== 'string') return item;
|
|
281
|
-
let v = item;
|
|
282
|
-
for (const tok of toks) v = replaceLiteral(v, tok);
|
|
283
|
-
return v;
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
// Keep summary within the schema's 300-char ceiling after substitution.
|
|
287
|
-
if (typeof out.summary === 'string' && out.summary.length > 300) {
|
|
288
|
-
out.summary = out.summary.slice(0, 297).replace(/\s+$/, '') + '...';
|
|
289
|
-
}
|
|
290
|
-
return out;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
module.exports = {
|
|
294
|
-
contentTokens,
|
|
295
|
-
publicHardTokens,
|
|
296
|
-
buildPrivateVocab,
|
|
297
|
-
iterPayloadStrings,
|
|
298
|
-
findLeakage,
|
|
299
|
-
redactPrivateLiterals,
|
|
300
|
-
// exported for unit tests
|
|
301
|
-
isStructuredLiteral,
|
|
302
|
-
isTrivialNumber,
|
|
303
|
-
};
|