@withgateway/sdk 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +3121 -1283
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +3185 -1347
- package/dist/cli.mjs.map +1 -1
- package/dist/files/index.js +9 -0
- package/dist/files/index.js.map +1 -1
- package/dist/files/index.mjs +9 -0
- package/dist/files/index.mjs.map +1 -1
- package/dist/hooks/index.d.mts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +280 -8
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +272 -8
- package/dist/hooks/index.mjs.map +1 -1
- package/dist/{index-1xnxt0Cc.d.ts → index-BO2SNSgy.d.ts} +12 -1
- package/dist/{index-B0R3IgsV.d.mts → index-BaKu5ZSU.d.mts} +124 -2
- package/dist/{index-B0R3IgsV.d.ts → index-BaKu5ZSU.d.ts} +124 -2
- package/dist/{index-C1wDEwH4.d.mts → index-Cz8Q6Keo.d.mts} +12 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +726 -167
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +718 -167
- package/dist/index.mjs.map +1 -1
- package/dist/traces/index.js +9 -0
- package/dist/traces/index.js.map +1 -1
- package/dist/traces/index.mjs +9 -0
- package/dist/traces/index.mjs.map +1 -1
- package/dist/tracing/index.d.mts +1 -1
- package/dist/tracing/index.d.ts +1 -1
- package/dist/tracing/index.js +97 -61
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/index.mjs +97 -61
- package/dist/tracing/index.mjs.map +1 -1
- package/dist/worlds/index.d.mts +154 -4
- package/dist/worlds/index.d.ts +154 -4
- package/dist/worlds/index.js +348 -97
- package/dist/worlds/index.js.map +1 -1
- package/dist/worlds/index.mjs +348 -97
- package/dist/worlds/index.mjs.map +1 -1
- package/package.json +1 -1
- package/runtime/gatewaysdk/environment/_bundle.py +1 -1
- package/runtime/gatewaysdk/environment/_materialize.py +53 -9
- package/runtime/gatewaysdk/environment/_toml.py +13 -0
- package/runtime/gatewaysdk/environment/schema/api.py +3 -7
- package/runtime/gatewaysdk/environment/schema/batch.py +15 -11
- package/runtime/gatewaysdk/environment/schema/bundle_runtime.py +24 -0
- package/runtime/gatewaysdk/environment/schema/compiler.py +60 -28
- package/runtime/gatewaysdk/environment/schema/conform.py +1 -1
- package/runtime/gatewaysdk/environment/schema/connector.py +1 -1
- package/runtime/gatewaysdk/environment/schema/connectors/google-drive/readers/merge.ingest.toml +25 -0
- package/runtime/gatewaysdk/environment/schema/connectors/google-drive/readers/merge.toml +17 -0
- package/runtime/gatewaysdk/environment/schema/extract.py +1 -5
- package/runtime/gatewaysdk/environment/schema/host_surfaces.py +1 -5
- package/runtime/gatewaysdk/environment/schema/mapping.py +1 -1
- package/runtime/gatewaysdk/environment/schema/platform.py +16 -4
- package/runtime/gatewaysdk/environment/schema/redaction.py +1 -1
- package/runtime/gatewaysdk/environment/schema/scaffold.py +9 -2
- package/runtime/gatewaysdk/environment/schema/skills/benchmarks-getting-started/SKILL.md +67 -9
- package/runtime/gatewaysdk/environment/schema/skills/hooks-getting-started/SKILL.md +61 -2
- package/runtime/gatewaysdk/environment/schema/skills/world-data-ingestion/SKILL.md +4 -1
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/SKILL.md +11 -11
- package/runtime/gatewaysdk/environment/schema/skills/worlds-getting-started/references/cli-mcp-map.md +17 -1
- package/runtime/gatewaysdk/environment/schema/snapshot.py +1 -5
- package/runtime/gatewaysdk/environment/schema/tools_world.py +1 -5
- package/runtime/gatewaysdk/environment/schema/ui.py +1 -5
- package/runtime/gatewaysdk/environment/schema/world_tests.py +1 -1
- package/runtime/gatewaysdk/environment/world.py +120 -4
- package/skills/benchmarks-getting-started/SKILL.md +67 -9
- package/skills/connector-schema-authoring/connector-worlds.md +8 -1
- package/skills/connector-schema-authoring/world-schema.md +1 -1
- package/skills/hooks-getting-started/SKILL.md +61 -2
- package/skills/world-data-ingestion/SKILL.md +4 -1
- package/skills/worlds-getting-started/SKILL.md +11 -11
- package/skills/worlds-getting-started/references/cli-mcp-map.md +17 -1
package/dist/hooks/index.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as Alias, a as AliasHandler, b as AliasMap, B as Bound, C as CONTEXT_KEY,
|
|
1
|
+
export { A as Alias, a as AliasHandler, b as AliasMap, c as AuditFinding, d as AuditRecord, e as AuditReport, B as Bound, C as CONTEXT_KEY, f as CallableTool, g as CommandHandler, h as ConnectorTool, D as Decision, j as DenyHandler, E as EVENTS, k as EVENT_ALIASES, F as FieldKinds, l as FieldSource, m as FinderSource, n as Finding, o as FunctionHandler, H as HANDLER_TYPES, p as Handler, q as HandlerFn, r as HandlerSpec, s as HandlerType, t as HookConfig, u as HookConfigError, v as HookDenied, w as HookError, x as HookEvent, y as HookEventName, z as HookRequest, G as HookResponse, I as HookResult, J as HookRule, K as HookRun, L as HookRunOptions, M as HookedSession, N as HttpHandler, O as HttpTool, P as INBOUND_KINDS, Q as INPUT_TYPES, R as Identifier, S as IdentifierCensus, T as IdentifierSource, U as Identity, V as InboundKind, W as JsonSchema, X as KINDS, Y as LegendEntry, Z as LegendRow, _ as LegendSource, $ as LiveConfig, a0 as LiveTool, a1 as LiveToolError, a2 as LiveTools, a3 as Matcher, a4 as PARSE_MODES, a5 as Pair, a6 as ParseMode, a7 as RecordHandler, a8 as RecordSink, a9 as Recorder, aa as RedactHandler, ab as RedactionAudit, ac as Replay, ad as RequestFn, ae as RunVerdict, af as SeedEntity, ag as SeedRow, ah as SessionLike, ai as TOOL_KINDS, aj as ToolFn, ak as ToolFunctions, al as ToolKind, am as ToolSpec, an as WrappedTools, ao as applyLimit, ap as applyResult, aq as buildTool, ar as canonical, as as definition, at as describeHandler, au as describeMatcher, av as describeTool, aw as emailPairs, ax as emptyConfig, ay as emptyLive, az as eventToJson, aA as explodeIp, aB as findKind, aC as folded, aD as genericPairs, aE as importCallable, aF as inputSchema, aG as interpolateHeaders, aH as interpolatePath, aI as isGlobalIpv4, aJ as jsPattern, aK as jsonPath, aL as loadHookConfig, aM as mapFields, aN as matches, aO as mirrorHandle, aP as namePairs, aQ as newRunKey, aR as normalizeEvent, aS as pageTitle, aT as parseHookConfig, aU as parseJson, aV as parseMatcher, aW as parseRegex, aX as parseStdout, aY as parseText, aZ as phonePairs, a_ as pyQuote, a$ as readConnection, b0 as readable, b1 as refusalReason, b2 as render, b3 as resultFromJson, b4 as splitTopLevel, b5 as stripTags, b6 as unescapeHtml, b7 as vendorOf, b8 as withContext, b9 as withDefaults } from '../index-BaKu5ZSU.mjs';
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { A as Alias, a as AliasHandler, b as AliasMap, B as Bound, C as CONTEXT_KEY,
|
|
1
|
+
export { A as Alias, a as AliasHandler, b as AliasMap, c as AuditFinding, d as AuditRecord, e as AuditReport, B as Bound, C as CONTEXT_KEY, f as CallableTool, g as CommandHandler, h as ConnectorTool, D as Decision, j as DenyHandler, E as EVENTS, k as EVENT_ALIASES, F as FieldKinds, l as FieldSource, m as FinderSource, n as Finding, o as FunctionHandler, H as HANDLER_TYPES, p as Handler, q as HandlerFn, r as HandlerSpec, s as HandlerType, t as HookConfig, u as HookConfigError, v as HookDenied, w as HookError, x as HookEvent, y as HookEventName, z as HookRequest, G as HookResponse, I as HookResult, J as HookRule, K as HookRun, L as HookRunOptions, M as HookedSession, N as HttpHandler, O as HttpTool, P as INBOUND_KINDS, Q as INPUT_TYPES, R as Identifier, S as IdentifierCensus, T as IdentifierSource, U as Identity, V as InboundKind, W as JsonSchema, X as KINDS, Y as LegendEntry, Z as LegendRow, _ as LegendSource, $ as LiveConfig, a0 as LiveTool, a1 as LiveToolError, a2 as LiveTools, a3 as Matcher, a4 as PARSE_MODES, a5 as Pair, a6 as ParseMode, a7 as RecordHandler, a8 as RecordSink, a9 as Recorder, aa as RedactHandler, ab as RedactionAudit, ac as Replay, ad as RequestFn, ae as RunVerdict, af as SeedEntity, ag as SeedRow, ah as SessionLike, ai as TOOL_KINDS, aj as ToolFn, ak as ToolFunctions, al as ToolKind, am as ToolSpec, an as WrappedTools, ao as applyLimit, ap as applyResult, aq as buildTool, ar as canonical, as as definition, at as describeHandler, au as describeMatcher, av as describeTool, aw as emailPairs, ax as emptyConfig, ay as emptyLive, az as eventToJson, aA as explodeIp, aB as findKind, aC as folded, aD as genericPairs, aE as importCallable, aF as inputSchema, aG as interpolateHeaders, aH as interpolatePath, aI as isGlobalIpv4, aJ as jsPattern, aK as jsonPath, aL as loadHookConfig, aM as mapFields, aN as matches, aO as mirrorHandle, aP as namePairs, aQ as newRunKey, aR as normalizeEvent, aS as pageTitle, aT as parseHookConfig, aU as parseJson, aV as parseMatcher, aW as parseRegex, aX as parseStdout, aY as parseText, aZ as phonePairs, a_ as pyQuote, a$ as readConnection, b0 as readable, b1 as refusalReason, b2 as render, b3 as resultFromJson, b4 as splitTopLevel, b5 as stripTags, b6 as unescapeHtml, b7 as vendorOf, b8 as withContext, b9 as withDefaults } from '../index-BaKu5ZSU.js';
|
package/dist/hooks/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var hooks_exports = {};
|
|
|
32
32
|
__export(hooks_exports, {
|
|
33
33
|
AliasHandler: () => AliasHandler,
|
|
34
34
|
AliasMap: () => AliasMap,
|
|
35
|
+
AuditReport: () => AuditReport,
|
|
35
36
|
CONTEXT_KEY: () => CONTEXT_KEY,
|
|
36
37
|
CallableTool: () => CallableTool,
|
|
37
38
|
CommandHandler: () => CommandHandler,
|
|
@@ -39,6 +40,8 @@ __export(hooks_exports, {
|
|
|
39
40
|
DenyHandler: () => DenyHandler,
|
|
40
41
|
EVENTS: () => EVENTS,
|
|
41
42
|
EVENT_ALIASES: () => EVENT_ALIASES,
|
|
43
|
+
FieldSource: () => FieldSource,
|
|
44
|
+
FinderSource: () => FinderSource,
|
|
42
45
|
FunctionHandler: () => FunctionHandler,
|
|
43
46
|
HANDLER_TYPES: () => HANDLER_TYPES,
|
|
44
47
|
HookConfigError: () => HookConfigError,
|
|
@@ -50,13 +53,18 @@ __export(hooks_exports, {
|
|
|
50
53
|
HttpTool: () => HttpTool,
|
|
51
54
|
INBOUND_KINDS: () => INBOUND_KINDS,
|
|
52
55
|
INPUT_TYPES: () => INPUT_TYPES,
|
|
56
|
+
Identifier: () => Identifier,
|
|
57
|
+
IdentifierCensus: () => IdentifierCensus,
|
|
58
|
+
IdentifierSource: () => IdentifierSource,
|
|
53
59
|
KINDS: () => KINDS,
|
|
60
|
+
LegendSource: () => LegendSource,
|
|
54
61
|
LiveToolError: () => LiveToolError,
|
|
55
62
|
LiveTools: () => LiveTools,
|
|
56
63
|
PARSE_MODES: () => PARSE_MODES,
|
|
57
64
|
RecordHandler: () => RecordHandler,
|
|
58
65
|
Recorder: () => Recorder,
|
|
59
66
|
RedactHandler: () => RedactHandler,
|
|
67
|
+
RedactionAudit: () => RedactionAudit,
|
|
60
68
|
Replay: () => Replay,
|
|
61
69
|
TOOL_KINDS: () => TOOL_KINDS,
|
|
62
70
|
applyLimit: () => applyLimit,
|
|
@@ -112,6 +120,49 @@ __export(hooks_exports, {
|
|
|
112
120
|
});
|
|
113
121
|
module.exports = __toCommonJS(hooks_exports);
|
|
114
122
|
|
|
123
|
+
// src/hooks/caseSwap.ts
|
|
124
|
+
var CASE_SWAP_MIN_CHARS = 4;
|
|
125
|
+
var standingAlone = /* @__PURE__ */ new Map();
|
|
126
|
+
function standingAlonePattern(needle) {
|
|
127
|
+
let pattern = standingAlone.get(needle);
|
|
128
|
+
if (pattern === void 0) {
|
|
129
|
+
const escaped = needle.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
130
|
+
pattern = new RegExp(`(?<![A-Za-z0-9])${escaped}(?![A-Za-z0-9])`, "gi");
|
|
131
|
+
standingAlone.set(needle, pattern);
|
|
132
|
+
}
|
|
133
|
+
return pattern;
|
|
134
|
+
}
|
|
135
|
+
var WORD = /[A-Za-z0-9]+/g;
|
|
136
|
+
function shapedWord(word, seen) {
|
|
137
|
+
const hasLetter = seen.toLowerCase() !== seen.toUpperCase();
|
|
138
|
+
if (hasLetter && seen === seen.toUpperCase()) return word.toUpperCase();
|
|
139
|
+
if (hasLetter && seen === seen.toLowerCase()) return word.toLowerCase();
|
|
140
|
+
const first = seen.slice(0, 1);
|
|
141
|
+
if (first !== first.toLowerCase())
|
|
142
|
+
return word.slice(0, 1).toUpperCase() + word.slice(1);
|
|
143
|
+
return word;
|
|
144
|
+
}
|
|
145
|
+
function shaped(replacement, seen) {
|
|
146
|
+
const seenWords = seen.match(WORD) ?? [];
|
|
147
|
+
if (seenWords.length !== (replacement.match(WORD) ?? []).length)
|
|
148
|
+
return shapedWord(replacement, seen);
|
|
149
|
+
let index2 = 0;
|
|
150
|
+
return replacement.replace(
|
|
151
|
+
WORD,
|
|
152
|
+
(word) => shapedWord(word, seenWords[index2++])
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
function swapValue(text, needle, replacement) {
|
|
156
|
+
if (!needle) return text;
|
|
157
|
+
const out = text.split(needle).join(replacement);
|
|
158
|
+
if (needle.length < CASE_SWAP_MIN_CHARS) return out;
|
|
159
|
+
if (!out.toLowerCase().includes(needle.toLowerCase())) return out;
|
|
160
|
+
return out.replace(
|
|
161
|
+
standingAlonePattern(needle),
|
|
162
|
+
(seen) => shaped(replacement, seen)
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
115
166
|
// src/hooks/alias.ts
|
|
116
167
|
var import_node_crypto = require("crypto");
|
|
117
168
|
var GIVEN = [
|
|
@@ -946,10 +997,9 @@ var AliasMap = class _AliasMap {
|
|
|
946
997
|
const [inbound] = this.pairs();
|
|
947
998
|
let out = text;
|
|
948
999
|
for (const [needle, replacement, alias] of inbound) {
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
}
|
|
1000
|
+
const swapped = swapValue(out, needle, replacement);
|
|
1001
|
+
if (swapped !== out) alias.hitsIn += 1;
|
|
1002
|
+
out = swapped;
|
|
953
1003
|
}
|
|
954
1004
|
out = out.replace(SHA256_ANY_GLOBAL, (match) => this.mintDigest(match));
|
|
955
1005
|
if (this.mintInbound.length) out = this.mintFoundIn(out, where);
|
|
@@ -965,10 +1015,9 @@ var AliasMap = class _AliasMap {
|
|
|
965
1015
|
const [, outbound] = this.pairs();
|
|
966
1016
|
let out = text;
|
|
967
1017
|
for (const [needle, replacement, alias] of outbound) {
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
}
|
|
1018
|
+
const swapped = swapValue(out, needle, replacement);
|
|
1019
|
+
if (swapped !== out) alias.hitsOut += 1;
|
|
1020
|
+
out = swapped;
|
|
972
1021
|
}
|
|
973
1022
|
const problems = [];
|
|
974
1023
|
for (const [needle] of outbound) {
|
|
@@ -3604,6 +3653,221 @@ var LiveTools = class _LiveTools {
|
|
|
3604
3653
|
}
|
|
3605
3654
|
};
|
|
3606
3655
|
|
|
3656
|
+
// src/hooks/audit.ts
|
|
3657
|
+
var MIN_VALUE_CHARS = 4;
|
|
3658
|
+
var REVIEW_MIN_CHARS = 20;
|
|
3659
|
+
var ANY_TOOL = "*";
|
|
3660
|
+
var isObject4 = (node) => typeof node === "object" && node !== null && !Array.isArray(node);
|
|
3661
|
+
function* stringsOf(node) {
|
|
3662
|
+
if (typeof node === "string") {
|
|
3663
|
+
yield node;
|
|
3664
|
+
return;
|
|
3665
|
+
}
|
|
3666
|
+
const children = Array.isArray(node) ? node : isObject4(node) ? Object.values(node) : [];
|
|
3667
|
+
for (const child of children) yield* stringsOf(child);
|
|
3668
|
+
}
|
|
3669
|
+
function* fieldsOf(node) {
|
|
3670
|
+
if (Array.isArray(node)) {
|
|
3671
|
+
for (const child of node) yield* fieldsOf(child);
|
|
3672
|
+
return;
|
|
3673
|
+
}
|
|
3674
|
+
if (!isObject4(node)) return;
|
|
3675
|
+
for (const [key2, value] of Object.entries(node)) {
|
|
3676
|
+
yield [key2, value];
|
|
3677
|
+
yield* fieldsOf(value);
|
|
3678
|
+
}
|
|
3679
|
+
}
|
|
3680
|
+
var Identifier = class {
|
|
3681
|
+
constructor(kind, value, source) {
|
|
3682
|
+
this.kind = kind;
|
|
3683
|
+
this.value = value;
|
|
3684
|
+
this.source = source;
|
|
3685
|
+
}
|
|
3686
|
+
get key() {
|
|
3687
|
+
return folded(this.value);
|
|
3688
|
+
}
|
|
3689
|
+
get prefix() {
|
|
3690
|
+
return this.value.slice(0, 3);
|
|
3691
|
+
}
|
|
3692
|
+
};
|
|
3693
|
+
var IdentifierSource = class {
|
|
3694
|
+
ignored() {
|
|
3695
|
+
return [];
|
|
3696
|
+
}
|
|
3697
|
+
};
|
|
3698
|
+
var LegendSource = class extends IdentifierSource {
|
|
3699
|
+
name = "legend";
|
|
3700
|
+
entries;
|
|
3701
|
+
constructor(legend) {
|
|
3702
|
+
super();
|
|
3703
|
+
this.entries = legend.filter((entry) => entry.real);
|
|
3704
|
+
}
|
|
3705
|
+
collect() {
|
|
3706
|
+
return this.entries.filter((entry) => (entry.role ?? "private") !== "public").map((entry) => new Identifier(entry.kind ?? "reference", String(entry.real), this.name));
|
|
3707
|
+
}
|
|
3708
|
+
ignored() {
|
|
3709
|
+
const open = this.entries.filter((e) => e.role === "public").map((e) => String(e.real));
|
|
3710
|
+
const personas = this.entries.filter((e) => e.alias).map((e) => String(e.alias));
|
|
3711
|
+
return [...open, ...personas];
|
|
3712
|
+
}
|
|
3713
|
+
};
|
|
3714
|
+
var FieldSource = class extends IdentifierSource {
|
|
3715
|
+
constructor(fieldKinds) {
|
|
3716
|
+
super();
|
|
3717
|
+
this.fieldKinds = fieldKinds;
|
|
3718
|
+
}
|
|
3719
|
+
name = "fields";
|
|
3720
|
+
kindsFor(tool) {
|
|
3721
|
+
return { ...this.fieldKinds[ANY_TOOL] ?? {}, ...this.fieldKinds[tool] ?? {} };
|
|
3722
|
+
}
|
|
3723
|
+
*collect(raw) {
|
|
3724
|
+
for (const record of raw) {
|
|
3725
|
+
const kinds = this.kindsFor(String(record.tool ?? ""));
|
|
3726
|
+
for (const [key2, value] of fieldsOf(record.result)) {
|
|
3727
|
+
const kind = kinds[key2];
|
|
3728
|
+
if (kind === void 0) continue;
|
|
3729
|
+
for (const text of stringsOf(value)) yield new Identifier(kind, text, this.name);
|
|
3730
|
+
}
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3733
|
+
};
|
|
3734
|
+
var FinderSource = class extends IdentifierSource {
|
|
3735
|
+
name;
|
|
3736
|
+
kinds;
|
|
3737
|
+
constructor(kinds = INBOUND_KINDS) {
|
|
3738
|
+
super();
|
|
3739
|
+
const bad = kinds.filter((kind) => !INBOUND_KINDS.includes(kind));
|
|
3740
|
+
if (bad.length > 0)
|
|
3741
|
+
throw new Error(
|
|
3742
|
+
`${bad.join(", ")} cannot be found by a pattern; only ${INBOUND_KINDS.join(", ")} can`
|
|
3743
|
+
);
|
|
3744
|
+
this.kinds = [...kinds];
|
|
3745
|
+
this.name = `finders:${this.kinds.join(",")}`;
|
|
3746
|
+
}
|
|
3747
|
+
*collect(raw) {
|
|
3748
|
+
for (const record of raw)
|
|
3749
|
+
for (const text of stringsOf(record.result))
|
|
3750
|
+
for (const kind of this.kinds)
|
|
3751
|
+
for (const value of findKind(kind, text)) yield new Identifier(kind, value, "finders");
|
|
3752
|
+
}
|
|
3753
|
+
};
|
|
3754
|
+
var IdentifierCensus = class {
|
|
3755
|
+
constructor(sources) {
|
|
3756
|
+
this.sources = sources;
|
|
3757
|
+
}
|
|
3758
|
+
get detectors() {
|
|
3759
|
+
return this.sources.map((source) => source.name);
|
|
3760
|
+
}
|
|
3761
|
+
build(raw) {
|
|
3762
|
+
const ignored = new Set(this.sources.flatMap((s) => [...s.ignored()].map(folded)));
|
|
3763
|
+
const seen = /* @__PURE__ */ new Map();
|
|
3764
|
+
for (const source of this.sources)
|
|
3765
|
+
for (const identifier of source.collect(raw)) {
|
|
3766
|
+
if (identifier.value.length < MIN_VALUE_CHARS || ignored.has(identifier.key)) continue;
|
|
3767
|
+
if (!seen.has(identifier.key)) seen.set(identifier.key, identifier);
|
|
3768
|
+
}
|
|
3769
|
+
return [...seen.values()];
|
|
3770
|
+
}
|
|
3771
|
+
};
|
|
3772
|
+
function shuffled(items, seed) {
|
|
3773
|
+
const out = [...items];
|
|
3774
|
+
let state = seed >>> 0;
|
|
3775
|
+
const next = () => {
|
|
3776
|
+
state = state + 1831565813 >>> 0;
|
|
3777
|
+
let t = Math.imul(state ^ state >>> 15, 1 | state);
|
|
3778
|
+
t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
|
|
3779
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
3780
|
+
};
|
|
3781
|
+
for (let i = out.length - 1; i > 0; i -= 1) {
|
|
3782
|
+
const j = Math.floor(next() * (i + 1));
|
|
3783
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
3784
|
+
}
|
|
3785
|
+
return out;
|
|
3786
|
+
}
|
|
3787
|
+
var AuditReport = class {
|
|
3788
|
+
constructor(findings, census, detectors, recordsScanned, leakedIdentifiers, cleanTexts) {
|
|
3789
|
+
this.findings = findings;
|
|
3790
|
+
this.census = census;
|
|
3791
|
+
this.detectors = detectors;
|
|
3792
|
+
this.recordsScanned = recordsScanned;
|
|
3793
|
+
this.leakedIdentifiers = leakedIdentifiers;
|
|
3794
|
+
this.cleanTexts = cleanTexts;
|
|
3795
|
+
}
|
|
3796
|
+
get ok() {
|
|
3797
|
+
return this.findings.length === 0;
|
|
3798
|
+
}
|
|
3799
|
+
get censusTotal() {
|
|
3800
|
+
return this.census.length;
|
|
3801
|
+
}
|
|
3802
|
+
/** The share of census identifiers that did NOT reach the model; 1 for an empty census. */
|
|
3803
|
+
get coverage() {
|
|
3804
|
+
if (this.census.length === 0) return 1;
|
|
3805
|
+
return Math.round((1 - this.leakedIdentifiers / this.census.length) * 1e4) / 1e4;
|
|
3806
|
+
}
|
|
3807
|
+
count(pick3) {
|
|
3808
|
+
const counts = {};
|
|
3809
|
+
for (const identifier of this.census) counts[pick3(identifier)] = (counts[pick3(identifier)] ?? 0) + 1;
|
|
3810
|
+
return counts;
|
|
3811
|
+
}
|
|
3812
|
+
/** `size` strings the model saw that nothing flagged, for a person to read. */
|
|
3813
|
+
reviewSample(size, seed = 0) {
|
|
3814
|
+
const pool = [...this.cleanTexts].sort(
|
|
3815
|
+
(a, b) => a.record - b.record || a.text.localeCompare(b.text)
|
|
3816
|
+
);
|
|
3817
|
+
return shuffled(pool, seed).slice(0, size);
|
|
3818
|
+
}
|
|
3819
|
+
toDict() {
|
|
3820
|
+
return {
|
|
3821
|
+
ok: this.ok,
|
|
3822
|
+
records_scanned: this.recordsScanned,
|
|
3823
|
+
detectors: this.detectors,
|
|
3824
|
+
census: {
|
|
3825
|
+
total: this.censusTotal,
|
|
3826
|
+
by_source: this.count((i) => i.source),
|
|
3827
|
+
by_kind: this.count((i) => i.kind)
|
|
3828
|
+
},
|
|
3829
|
+
leaked_identifiers: this.leakedIdentifiers,
|
|
3830
|
+
coverage: this.coverage,
|
|
3831
|
+
findings: this.findings
|
|
3832
|
+
};
|
|
3833
|
+
}
|
|
3834
|
+
};
|
|
3835
|
+
var RedactionAudit = class _RedactionAudit {
|
|
3836
|
+
constructor(census) {
|
|
3837
|
+
this.census = census;
|
|
3838
|
+
}
|
|
3839
|
+
/** The standard audit: the run's legend, declared field kinds, pattern finders. */
|
|
3840
|
+
static forRun(options) {
|
|
3841
|
+
return new _RedactionAudit(
|
|
3842
|
+
new IdentifierCensus([
|
|
3843
|
+
new LegendSource(options.legend ?? []),
|
|
3844
|
+
new FieldSource(options.fieldKinds ?? {}),
|
|
3845
|
+
new FinderSource(options.finderKinds ?? INBOUND_KINDS)
|
|
3846
|
+
])
|
|
3847
|
+
);
|
|
3848
|
+
}
|
|
3849
|
+
run(raw, shown) {
|
|
3850
|
+
const census = this.census.build(raw);
|
|
3851
|
+
const findings = [];
|
|
3852
|
+
const clean = [];
|
|
3853
|
+
const leaked = /* @__PURE__ */ new Set();
|
|
3854
|
+
shown.forEach((record, index2) => {
|
|
3855
|
+
const tool = String(record.tool ?? "");
|
|
3856
|
+
const texts = [...stringsOf(record.result)];
|
|
3857
|
+
const haystack = folded(texts.join("\n"));
|
|
3858
|
+
const hits = census.filter((identifier) => haystack.includes(identifier.key));
|
|
3859
|
+
hits.forEach((identifier) => leaked.add(identifier.key));
|
|
3860
|
+
findings.push(
|
|
3861
|
+
...hits.map((i) => ({ record: index2, tool, kind: i.kind, source: i.source, prefix: i.prefix }))
|
|
3862
|
+
);
|
|
3863
|
+
clean.push(
|
|
3864
|
+
...texts.filter((t) => t.length >= REVIEW_MIN_CHARS && !hits.some((i) => folded(t).includes(i.key))).map((text) => ({ record: index2, tool, text }))
|
|
3865
|
+
);
|
|
3866
|
+
});
|
|
3867
|
+
return new AuditReport(findings, census, this.census.detectors, shown.length, leaked.size, clean);
|
|
3868
|
+
}
|
|
3869
|
+
};
|
|
3870
|
+
|
|
3607
3871
|
// src/hooks/run.ts
|
|
3608
3872
|
var import_node_crypto2 = require("crypto");
|
|
3609
3873
|
var fs4 = __toESM(require("fs"));
|
|
@@ -4274,6 +4538,7 @@ var HookedSession = class {
|
|
|
4274
4538
|
0 && (module.exports = {
|
|
4275
4539
|
AliasHandler,
|
|
4276
4540
|
AliasMap,
|
|
4541
|
+
AuditReport,
|
|
4277
4542
|
CONTEXT_KEY,
|
|
4278
4543
|
CallableTool,
|
|
4279
4544
|
CommandHandler,
|
|
@@ -4281,6 +4546,8 @@ var HookedSession = class {
|
|
|
4281
4546
|
DenyHandler,
|
|
4282
4547
|
EVENTS,
|
|
4283
4548
|
EVENT_ALIASES,
|
|
4549
|
+
FieldSource,
|
|
4550
|
+
FinderSource,
|
|
4284
4551
|
FunctionHandler,
|
|
4285
4552
|
HANDLER_TYPES,
|
|
4286
4553
|
HookConfigError,
|
|
@@ -4292,13 +4559,18 @@ var HookedSession = class {
|
|
|
4292
4559
|
HttpTool,
|
|
4293
4560
|
INBOUND_KINDS,
|
|
4294
4561
|
INPUT_TYPES,
|
|
4562
|
+
Identifier,
|
|
4563
|
+
IdentifierCensus,
|
|
4564
|
+
IdentifierSource,
|
|
4295
4565
|
KINDS,
|
|
4566
|
+
LegendSource,
|
|
4296
4567
|
LiveToolError,
|
|
4297
4568
|
LiveTools,
|
|
4298
4569
|
PARSE_MODES,
|
|
4299
4570
|
RecordHandler,
|
|
4300
4571
|
Recorder,
|
|
4301
4572
|
RedactHandler,
|
|
4573
|
+
RedactionAudit,
|
|
4302
4574
|
Replay,
|
|
4303
4575
|
TOOL_KINDS,
|
|
4304
4576
|
applyLimit,
|