@promptdriven/runtime-client 0.0.0-stage → 1.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/LICENSE +7 -0
- package/README.md +42 -2
- package/package.json +28 -4
- package/src/index.mjs +1 -0
- package/src/runtime/agent-ask.mjs +187 -0
- package/src/runtime/agent-chat.mjs +152 -0
- package/src/runtime/agent-coverage.mjs +97 -0
- package/src/runtime/agent-guide.mjs +152 -0
- package/src/runtime/agent-judge.mjs +71 -0
- package/src/runtime/agent-packet.mjs +62 -0
- package/src/runtime/agent-project.mjs +93 -0
- package/src/runtime/contract-refs.mjs +519 -0
- package/src/runtime/contracts.mjs +138 -0
- package/src/runtime/index.mjs +974 -0
- package/src/runtime/lint-call-preflight.mjs +19 -0
- package/src/runtime/lint-compatibility-display.mjs +62 -0
- package/src/runtime/live-local-bridge.mjs +178 -0
- package/src/runtime/live-local.mjs +181 -0
- package/src/runtime/product-composition.mjs +384 -0
- package/src/runtime/run-program.mjs +797 -0
- package/src/runtime/runtime-binding-plan.mjs +145 -0
- package/src/runtime/runtime-bindings.mjs +81 -0
- package/src/runtime/runtime-check-plan.mjs +411 -0
- package/src/runtime/runtime-client.mjs +8114 -0
- package/src/runtime/runtime-lint-receipt.mjs +25 -0
- package/src/runtime/runtime-markdown.mjs +215 -0
- package/src/runtime/runtime-outcome.mjs +468 -0
- package/src/runtime/runtime-output.mjs +752 -0
- package/src/runtime/runtime-preflight.mjs +3832 -0
- package/src/runtime/runtime-slots.mjs +462 -0
- package/src/runtime/runtime-workspace-migration.mjs +70 -0
- package/src/runtime/runtime-workspace.mjs +52 -0
- package/src/runtime/scenario-json.mjs +257 -0
- package/src/runtime/secret-redaction.mjs +54 -0
- package/src/runtime/try-doors.mjs +597 -0
- package/src/runtime/try-http.mjs +285 -0
- package/src/runtime/try-mcp.mjs +223 -0
- package/src/runtime/try-session.mjs +95 -0
- package/src/runtime/try-update-policy.mjs +43 -0
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
// Generated from prompts/cli/scenario-json.prompt.md (sha256: 5b6173d4ec1a476063de34a456a6e29ccabeb5d3c2e3fd3500e0593d81fbab1e).
|
|
2
|
+
// Exact whole numbers in Runtime scenario files: read, write and compare without rounding.
|
|
3
|
+
|
|
4
|
+
const EXACT_INTEGER = /^-?(?:0|[1-9][0-9]*)$/;
|
|
5
|
+
const plain = value => value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
6
|
+
&& (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);
|
|
7
|
+
const pointerToken = key => String(key).replaceAll('~', '~0').replaceAll('/', '~1');
|
|
8
|
+
const fromToken = token => token.replaceAll('~1', '/').replaceAll('~0', '~');
|
|
9
|
+
const inexact = (Kind, message) => Object.assign(new Kind(message), { code: 'scenario-number-inexact' });
|
|
10
|
+
|
|
11
|
+
export function parseScenarioJson(text) {
|
|
12
|
+
return JSON.parse(text, (_key, value, context) =>
|
|
13
|
+
typeof value === 'number' && !Number.isSafeInteger(value) && typeof context?.source === 'string' && EXACT_INTEGER.test(context.source)
|
|
14
|
+
? BigInt(context.source) : value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function stringifyScenarioJson(value, space) {
|
|
18
|
+
return JSON.stringify(value, (_key, item) => typeof item === 'bigint' ? JSON.rawJSON(item.toString()) : item, space);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function exactNumber(value) {
|
|
22
|
+
if (typeof value === 'number') return value;
|
|
23
|
+
if (typeof value !== 'bigint') throw inexact(TypeError, `Expected a Number or an exact integer, got ${typeof value}.`);
|
|
24
|
+
const nearest = Number(value);
|
|
25
|
+
if (Number.isFinite(nearest) && BigInt(nearest) === value) return nearest;
|
|
26
|
+
throw inexact(RangeError, `${value} has no exact JavaScript Number; the nearest Number is ${Number.isFinite(nearest) ? BigInt(nearest) : nearest}.`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function exactValue(value) {
|
|
30
|
+
if (typeof value === 'number') return Number.isInteger(value) && !Number.isSafeInteger(value) ? BigInt(value) : value;
|
|
31
|
+
if (typeof value === 'bigint') return value >= BigInt(Number.MIN_SAFE_INTEGER) && value <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(value) : value;
|
|
32
|
+
if (Array.isArray(value)) return value.map(exactValue);
|
|
33
|
+
if (plain(value)) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, exactValue(item)]));
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// A number token with a fraction or exponent whose digits change when it is read as a Number.
|
|
38
|
+
class Read { constructor(source, value) { this.source = source; this.value = value; } }
|
|
39
|
+
const normalNumber = text => {
|
|
40
|
+
const match = /^(-?)([0-9]+)(?:\.([0-9]+))?(?:[eE]([+-]?[0-9]+))?$/.exec(text);
|
|
41
|
+
if (!match) return text;
|
|
42
|
+
const digits = (match[2] + (match[3] ?? '')).replace(/^0+/, '');
|
|
43
|
+
if (!digits) return '0';
|
|
44
|
+
const zeros = /0*$/.exec(digits)[0].length;
|
|
45
|
+
return `${match[1]}${digits.slice(0, digits.length - zeros)}e${BigInt(match[4] ?? 0) - BigInt((match[3] ?? '').length) + BigInt(zeros)}`;
|
|
46
|
+
};
|
|
47
|
+
export function roundedNumberTokens(text) {
|
|
48
|
+
const doc = JSON.parse(text, (_key, value, context) => typeof value === 'number' && typeof context?.source === 'string'
|
|
49
|
+
&& !EXACT_INTEGER.test(context.source) && normalNumber(context.source) !== normalNumber(String(value)) ? new Read(context.source, value) : value);
|
|
50
|
+
const found = [];
|
|
51
|
+
const visit = (item, path) => {
|
|
52
|
+
if (item instanceof Read) found.push({ path, source: item.source, value: item.value });
|
|
53
|
+
else if (Array.isArray(item)) item.forEach((member, index) => visit(member, [...path, index]));
|
|
54
|
+
else if (plain(item)) for (const [key, member] of Object.entries(item)) visit(member, [...path, key]);
|
|
55
|
+
};
|
|
56
|
+
visit(doc, []);
|
|
57
|
+
return found;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function exactIntegerLeaves(value) {
|
|
61
|
+
const leaves = [];
|
|
62
|
+
const visit = (item, pointer) => {
|
|
63
|
+
if (typeof item === 'bigint') leaves.push({ pointer, value: item.toString() });
|
|
64
|
+
else if (Array.isArray(item)) item.forEach((member, index) => visit(member, `${pointer}/${index}`));
|
|
65
|
+
else if (plain(item)) for (const [key, member] of Object.entries(item)) visit(member, `${pointer}/${pointerToken(key)}`);
|
|
66
|
+
};
|
|
67
|
+
visit(value, '');
|
|
68
|
+
return leaves;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function jsonSafe(value) {
|
|
72
|
+
if (typeof value === 'bigint') return Number(value);
|
|
73
|
+
if (Array.isArray(value)) return value.map(jsonSafe);
|
|
74
|
+
if (plain(value)) return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, jsonSafe(item)]));
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function withExactIntegers(value, leaves) {
|
|
79
|
+
let copy = structuredClone(value);
|
|
80
|
+
for (const leaf of Array.isArray(leaves) ? leaves : []) {
|
|
81
|
+
if (typeof leaf?.pointer !== 'string' || typeof leaf?.value !== 'string' || !EXACT_INTEGER.test(leaf.value)) continue;
|
|
82
|
+
const exact = BigInt(leaf.value);
|
|
83
|
+
if (leaf.pointer === '') { if (copy === Number(exact)) copy = exact; continue; }
|
|
84
|
+
if (!leaf.pointer.startsWith('/')) continue;
|
|
85
|
+
const tokens = leaf.pointer.slice(1).split('/').map(fromToken), last = tokens.pop();
|
|
86
|
+
let holder = copy;
|
|
87
|
+
for (const token of tokens) holder = (Array.isArray(holder) || plain(holder)) && Object.hasOwn(holder, token) ? holder[token] : undefined;
|
|
88
|
+
if ((Array.isArray(holder) || plain(holder)) && Object.hasOwn(holder, last) && holder[last] === Number(exact)) holder[last] = exact;
|
|
89
|
+
}
|
|
90
|
+
return copy;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const derivationError = message => Object.assign(new SyntaxError(message), { code: 'scenario-derivation-invalid' });
|
|
94
|
+
const absInteger = value => value < 0n ? -value : value;
|
|
95
|
+
const DERIVATION_COMPONENT_LIMIT = 10n ** 10001n;
|
|
96
|
+
function gcdInteger(left, right) {
|
|
97
|
+
left = absInteger(left); right = absInteger(right);
|
|
98
|
+
while (right) [left, right] = [right, left % right];
|
|
99
|
+
return left;
|
|
100
|
+
}
|
|
101
|
+
function rational(numerator, denominator = 1n) {
|
|
102
|
+
if (!denominator) throw derivationError('Division by zero.');
|
|
103
|
+
if (denominator < 0n) { numerator = -numerator; denominator = -denominator; }
|
|
104
|
+
const divisor = gcdInteger(numerator, denominator);
|
|
105
|
+
const n = numerator / divisor, d = denominator / divisor;
|
|
106
|
+
if (absInteger(n) >= DERIVATION_COMPONENT_LIMIT || d >= DERIVATION_COMPONENT_LIMIT)
|
|
107
|
+
throw derivationError('Exact component exceeds 10,001 decimal digits.');
|
|
108
|
+
return { n, d };
|
|
109
|
+
}
|
|
110
|
+
function decimalRational(token) {
|
|
111
|
+
const match = /^([+-]?)(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/.exec(token);
|
|
112
|
+
const exponent = BigInt(match[4] ?? '0');
|
|
113
|
+
if (absInteger(exponent) > 10000n) throw derivationError('Decimal exponent exceeds 10,000.');
|
|
114
|
+
const digits = (match[2] + (match[3] ?? '')) || '0';
|
|
115
|
+
const n = BigInt(digits) * (match[1] === '-' ? -1n : 1n);
|
|
116
|
+
const scale = BigInt((match[3] ?? '').length) - exponent;
|
|
117
|
+
return scale < 0n ? rational(n * 10n ** -scale) : rational(n, 10n ** scale);
|
|
118
|
+
}
|
|
119
|
+
const addRational = (a, b) => rational(a.n * b.d + b.n * a.d, a.d * b.d);
|
|
120
|
+
const subtractRational = (a, b) => rational(a.n * b.d - b.n * a.d, a.d * b.d);
|
|
121
|
+
const multiplyRational = (a, b) => rational(a.n * b.n, a.d * b.d);
|
|
122
|
+
const divideRational = (a, b) => rational(a.n * b.d, a.d * b.n);
|
|
123
|
+
function roundRational(value, mode) {
|
|
124
|
+
const q = value.n / value.d, r = value.n % value.d;
|
|
125
|
+
if (mode === 'trunc' || !r) return rational(q);
|
|
126
|
+
if (mode === 'floor') return rational(q - (r < 0n ? 1n : 0n));
|
|
127
|
+
if (mode === 'ceil') return rational(q + (r > 0n ? 1n : 0n));
|
|
128
|
+
const comparison = absInteger(r) * 2n - value.d;
|
|
129
|
+
const advance = comparison > 0n || comparison === 0n && (mode === 'round_half_up' || q % 2n !== 0n);
|
|
130
|
+
return rational(q + (advance ? (value.n < 0n ? -1n : 1n) : 0n));
|
|
131
|
+
}
|
|
132
|
+
function factorMultiplicity(value, factor) {
|
|
133
|
+
const powers = [];
|
|
134
|
+
for (let power = factor, count = 1; power <= value; power *= power, count *= 2)
|
|
135
|
+
powers.push({ power, count });
|
|
136
|
+
let count = 0;
|
|
137
|
+
for (let index = powers.length - 1; index >= 0; index--) {
|
|
138
|
+
const candidate = powers[index];
|
|
139
|
+
if (value % candidate.power === 0n) { value /= candidate.power; count += candidate.count; }
|
|
140
|
+
}
|
|
141
|
+
return { rest: value, count };
|
|
142
|
+
}
|
|
143
|
+
function canonicalDerivation(text) {
|
|
144
|
+
if (text.length > 20004) throw derivationError('Canonical result exceeds 20,004 characters.');
|
|
145
|
+
return text;
|
|
146
|
+
}
|
|
147
|
+
function formatRational(value) {
|
|
148
|
+
if (value.d === 1n) return String(value.n);
|
|
149
|
+
const two = factorMultiplicity(value.d, 2n), five = factorMultiplicity(two.rest, 5n);
|
|
150
|
+
if (five.rest !== 1n) return canonicalDerivation(`${value.n}/${value.d}`);
|
|
151
|
+
const twos = two.count, fives = five.count;
|
|
152
|
+
const scale = Math.max(twos, fives);
|
|
153
|
+
if (scale > 10000) throw derivationError('Terminating result exceeds 10,000 fractional decimal places.');
|
|
154
|
+
const digits = String(absInteger(value.n) * 2n ** BigInt(scale - twos) * 5n ** BigInt(scale - fives)).padStart(scale + 1, '0');
|
|
155
|
+
const decimal = `${digits.slice(0, -scale)}.${digits.slice(-scale)}`.replace(/0+$/, '');
|
|
156
|
+
return canonicalDerivation(`${value.n < 0n ? '-' : ''}${decimal}`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// This parser only recognizes the exact-math grammar. Authored text never runs as JavaScript.
|
|
160
|
+
function derivationRational(expression) {
|
|
161
|
+
if (typeof expression !== 'string') throw derivationError('derivation must be a string.');
|
|
162
|
+
if (expression.length > 10000) throw derivationError('Expression exceeds 10,000 characters.');
|
|
163
|
+
let offset = 0, token = '', depth = 0;
|
|
164
|
+
const next = () => {
|
|
165
|
+
const whitespace = /^\s*/.exec(expression.slice(offset))[0]; offset += whitespace.length;
|
|
166
|
+
if (offset === expression.length) { token = ''; return; }
|
|
167
|
+
const match = /^(?:(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?|[A-Za-z_][A-Za-z_0-9]*|[+*/(),-])/.exec(expression.slice(offset));
|
|
168
|
+
if (!match) throw derivationError(`Unexpected character at position ${offset + 1}.`);
|
|
169
|
+
token = match[0]; offset += token.length;
|
|
170
|
+
};
|
|
171
|
+
const nested = action => {
|
|
172
|
+
if (++depth > 128) throw derivationError('Expression nesting exceeds 128 levels.');
|
|
173
|
+
try { return action(); } finally { depth--; }
|
|
174
|
+
};
|
|
175
|
+
const requireToken = wanted => {
|
|
176
|
+
if (token !== wanted) throw derivationError(`Expected ${wanted} at position ${offset + 1}.`);
|
|
177
|
+
next();
|
|
178
|
+
};
|
|
179
|
+
const primary = () => {
|
|
180
|
+
if (token === '+' || token === '-') {
|
|
181
|
+
const sign = token; next();
|
|
182
|
+
const value = nested(primary);
|
|
183
|
+
return sign === '-' ? rational(-value.n, value.d) : value;
|
|
184
|
+
}
|
|
185
|
+
if (token === '(') {
|
|
186
|
+
next(); const value = nested(sum); requireToken(')'); return value;
|
|
187
|
+
}
|
|
188
|
+
if (/^[\d.]/.test(token)) { const value = decimalRational(token); next(); return value; }
|
|
189
|
+
const name = token;
|
|
190
|
+
if (!['min', 'max', 'floor', 'ceil', 'trunc', 'round_half_up', 'round_half_even'].includes(name))
|
|
191
|
+
throw derivationError(`Expected a number or an allowed function at position ${offset + 1}.`);
|
|
192
|
+
next(); requireToken('(');
|
|
193
|
+
const args = nested(() => {
|
|
194
|
+
const values = [];
|
|
195
|
+
if (token !== ')') {
|
|
196
|
+
values.push(sum());
|
|
197
|
+
while (token === ',') { next(); values.push(sum()); }
|
|
198
|
+
}
|
|
199
|
+
return values;
|
|
200
|
+
});
|
|
201
|
+
requireToken(')');
|
|
202
|
+
if (name === 'min' || name === 'max') {
|
|
203
|
+
if (!args.length) throw derivationError(`${name} needs at least one argument.`);
|
|
204
|
+
return args.reduce((selected, value) => {
|
|
205
|
+
const difference = value.n * selected.d - selected.n * value.d;
|
|
206
|
+
return (name === 'min' ? difference < 0n : difference > 0n) ? value : selected;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
if (args.length !== 1) throw derivationError(`${name} needs one argument.`);
|
|
210
|
+
return roundRational(args[0], name);
|
|
211
|
+
};
|
|
212
|
+
const product = () => {
|
|
213
|
+
let left = primary();
|
|
214
|
+
while (['*', '/', 'div', 'mod'].includes(token)) {
|
|
215
|
+
const op = token; next(); const right = primary();
|
|
216
|
+
if (op === '*') left = multiplyRational(left, right);
|
|
217
|
+
else if (op === '/') left = divideRational(left, right);
|
|
218
|
+
else {
|
|
219
|
+
const quotient = divideRational(left, right), whole = rational(quotient.n / quotient.d);
|
|
220
|
+
left = op === 'div' ? whole : subtractRational(left, multiplyRational(whole, right));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return left;
|
|
224
|
+
};
|
|
225
|
+
const sum = () => {
|
|
226
|
+
let left = product();
|
|
227
|
+
while (token === '+' || token === '-') {
|
|
228
|
+
const op = token; next(); const right = product();
|
|
229
|
+
left = op === '+' ? addRational(left, right) : subtractRational(left, right);
|
|
230
|
+
}
|
|
231
|
+
return left;
|
|
232
|
+
};
|
|
233
|
+
next(); const value = sum();
|
|
234
|
+
if (token !== '') throw derivationError(`Unexpected token ${token}.`);
|
|
235
|
+
return value;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function evaluateDerivation(expression) {
|
|
239
|
+
return formatRational(derivationRational(expression));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function checkDerivation(check) {
|
|
243
|
+
if (!check || !Object.hasOwn(check, 'derivation')) return null;
|
|
244
|
+
try {
|
|
245
|
+
if (typeof check.value !== 'bigint' && (typeof check.value !== 'number' || !Number.isFinite(check.value)))
|
|
246
|
+
throw derivationError('A derivation needs a finite numeric scalar value.');
|
|
247
|
+
const computed = derivationRational(check.derivation);
|
|
248
|
+
const expected = typeof check.value === 'bigint' || Number.isInteger(check.value)
|
|
249
|
+
? rational(BigInt(check.value)) : decimalRational(String(check.value));
|
|
250
|
+
return computed.n === expected.n && computed.d === expected.d ? null : {
|
|
251
|
+
code: 'scenario-derivation-mismatch',
|
|
252
|
+
message: `Derivation evaluates to ${formatRational(computed)}; expected value is ${formatRational(expected)}.`,
|
|
253
|
+
};
|
|
254
|
+
} catch (error) {
|
|
255
|
+
return { code: 'scenario-derivation-invalid', message: error.message };
|
|
256
|
+
}
|
|
257
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Generated from prompts/cli/secret-redaction.prompt.md (sha256: ce9cfca0e024e8b39785b35a44e9e287012cbdcc399cec52fc77afe866bdacfe).
|
|
2
|
+
// Owned by prompts/cli/secret-redaction.prompt.md.
|
|
3
|
+
const SECRET = /token|password|secret|api[_-]?key|authorization|cookie|credential/i;
|
|
4
|
+
const remembered = new Set();
|
|
5
|
+
const secretName = /token|secret|password|passwd|credential|authorization|cookie|api[_-]?key|_key$/i;
|
|
6
|
+
export function rememberSecrets(...values) {
|
|
7
|
+
for (const value of values) if (typeof value === 'string' && value) remembered.add(value);
|
|
8
|
+
}
|
|
9
|
+
export function knownSecretValues(env = process.env, secrets = []) {
|
|
10
|
+
return [...new Set([...remembered, ...secrets,
|
|
11
|
+
...[process.env, env].flatMap(source => Object.entries(source ?? {})
|
|
12
|
+
.filter(([name,value]) => secretName.test(name) && typeof value === 'string' && value)
|
|
13
|
+
.map(([,value]) => value))])].filter(value => typeof value === 'string' && value);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Keep undecided raw text only for the longest possible match. The second
|
|
17
|
+
// callback argument lets evidence consumers count original bytes and lines.
|
|
18
|
+
export function redactingValues(emit, secrets) {
|
|
19
|
+
const values = [...new Set(secrets)].filter(value => typeof value === 'string' && value);
|
|
20
|
+
const overlap = Math.max(0, ...values.map(value => value.length - 1));
|
|
21
|
+
let pending = '';
|
|
22
|
+
const drain = final => {
|
|
23
|
+
const limit = final ? pending.length : Math.max(0, pending.length - overlap);
|
|
24
|
+
let offset = 0;
|
|
25
|
+
while (offset < limit) {
|
|
26
|
+
let start = -1, matched = '';
|
|
27
|
+
for (const value of values) {
|
|
28
|
+
const index = pending.indexOf(value, offset);
|
|
29
|
+
if (index >= 0 && (start < 0 || index < start || index === start && value.length > matched.length)) {
|
|
30
|
+
start = index; matched = value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (start < 0 || start >= limit) break;
|
|
34
|
+
if (start > offset) emit(pending.slice(offset,start), pending.slice(offset,start));
|
|
35
|
+
emit('[redacted]', matched);
|
|
36
|
+
offset = start + matched.length;
|
|
37
|
+
}
|
|
38
|
+
if (offset < limit) { emit(pending.slice(offset,limit), pending.slice(offset,limit)); offset = limit; }
|
|
39
|
+
pending = pending.slice(offset);
|
|
40
|
+
};
|
|
41
|
+
return {write(text) { pending += text; drain(false); }, end() { drain(true); }};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function redactSecrets(value, secrets = []) {
|
|
45
|
+
let redacted = '';
|
|
46
|
+
const stream = redactingValues(text => { redacted += text; }, knownSecretValues(process.env,secrets));
|
|
47
|
+
stream.write(String(value ?? '')); stream.end();
|
|
48
|
+
value = redacted;
|
|
49
|
+
value=value.replace(/https?:\/\/[^\s"'<>]+/g,text=>{try{const url=new URL(text);let changed=false;if(url.username||url.password){url.username='';url.password='';changed=true;}for(const key of [...url.searchParams.keys()])if(SECRET.test(key)||/^(?:key|auth|signature)$/i.test(key)){url.searchParams.set(key,'[redacted]');changed=true;}return changed?url.href:text;}catch{return text.replace(/(https?:\/\/)[^\s/@]+(?::[^\s/@]*)?@/gi,'$1[redacted]@');}});
|
|
50
|
+
value = value.replace(/-----BEGIN [^-]*PRIVATE KEY-----[\s\S]*?(?:-----END [^-]*PRIVATE KEY-----|$)/g,'[redacted]');
|
|
51
|
+
value = value.replace(/\b(authorization|cookie|set-cookie)["']?\s*[:=]\s*[^\r\n]+/gi, '$1=[redacted]');
|
|
52
|
+
value = value.replace(/\bAKIA[A-Z0-9]{16}\b/g,'[redacted]').replace(/\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,'[redacted]');
|
|
53
|
+
return value.replace(/\b(?:gh[pousr]_[A-Za-z0-9_]+|github_pat_[A-Za-z0-9_]+|sk-[A-Za-z0-9_-]{12,}|AIza[A-Za-z0-9_-]+|ya29\.[A-Za-z0-9_.-]+)\b/g,'[redacted]').replace(/\b(?:Bearer|Basic)\s+\S+/gi,'[redacted]').replace(/\b(key|token|password|secret|api[_-]?key|authorization|cookie|credential)["']?\s*[:=]\s*(?:"(?:\\.|[^"\\])*(?:"|$)|'(?:\\.|[^'\\])*(?:'|$)|[^\s,;]+)/gi,'$1=[redacted]').replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f]/g,'');
|
|
54
|
+
}
|