@conarium-ai/core 0.2.30 → 0.2.32
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/CHANGELOG.md +72 -0
- package/LIMITATIONS.md +5 -5
- package/LIMITATIONS.tr.md +5 -5
- package/README.md +17 -4
- package/bin/conarium-anchor-service.mjs +22 -3
- package/bin/conarium-doctor.mjs +28 -18
- package/bin/conarium-token-sync.mjs +54 -0
- package/deploy/anchor-service/README.md +3 -0
- package/deploy/anchor-service/conarium-token-sync.service +14 -0
- package/deploy/anchor-service/conarium-token-sync.timer +11 -0
- package/dist/anchor-service.d.ts +10 -0
- package/dist/anchor-service.d.ts.map +1 -1
- package/dist/anchor-service.js +33 -6
- package/dist/anchor-service.js.map +1 -1
- package/dist/governance.d.ts.map +1 -1
- package/dist/governance.js +69 -14
- package/dist/governance.js.map +1 -1
- package/dist/masking-cost.d.ts +1 -1
- package/dist/masking-cost.js +4 -4
- package/dist/masking-cost.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +4 -4
- package/dist/server.js.map +1 -1
- package/docs/BENCHMARK.md +49 -35
- package/docs/PRICING.md +41 -0
- package/docs/RECEIPT-SPEC.md +1 -0
- package/docs/benchmarks/latest.json +1662 -1662
- package/docs/benchmarks/masking-cost-threshold.json +2 -2
- package/docs/benchmarks/masking-cpu-summary.json +25 -0
- package/docs/benchmarks/masking-identity-after.json +66 -0
- package/docs/benchmarks/masking-identity-before.json +66 -0
- package/docs/benchmarks/masking-profile-100.json +22 -0
- package/docs/benchmarks/masking-profile-500.json +22 -0
- package/docs/benchmarks/masking-profile-5000.json +22 -0
- package/docs/benchmarks/overhead-20260818T1842Z-win32-before.json +539 -0
- package/docs/benchmarks/overhead-20260818T1852Z-win32.json +539 -0
- package/docs/benchmarks/overhead-20260818T2120Z-win32-09b2100.json +2310 -0
- package/docs/benchmarks/overhead-20260818T2145Z-win32-46acd75.json +2310 -0
- package/docs/claims/reviews/0.2.31.md +76 -0
- package/docs/claims/reviews/0.2.32.md +69 -0
- package/package.json +3 -1
- package/scripts/profile-masking-carryover.mjs +140 -0
- package/scripts/profile-masking-once.mjs +79 -0
- package/scripts/snapshot-masking-identity.mjs +62 -0
- package/scripts/summarize-cpuprofile.mjs +24 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Claims review — 0.2.31
|
|
2
|
+
|
|
3
|
+
- base: v0.2.30
|
|
4
|
+
- head: 6435b56
|
|
5
|
+
- surface: sha256:a07a8a6e91f86dc4c34a343a4d76cb9213ccb509b9b4db578e6abf5890e97291
|
|
6
|
+
- verdict: pass
|
|
7
|
+
- reviewer: Claude, reading on the maintainer's instruction — an assistant read, not an independent human one
|
|
8
|
+
|
|
9
|
+
Four claim surfaces changed across the three merges in this release: `README.md`,
|
|
10
|
+
`LIMITATIONS.md`, `LIMITATIONS.tr.md` and `docs/BENCHMARK.md`. A fifth,
|
|
11
|
+
`docs/PRICING.md`, arrived unlisted and was added to the surface list during this
|
|
12
|
+
review; the finding below came out of reading it.
|
|
13
|
+
|
|
14
|
+
The performance numbers were checked against their own artefacts rather than
|
|
15
|
+
against the previous text. `docs/BENCHMARK.md` names the environment it measured
|
|
16
|
+
in (win32 10.0.26200, Node v24.5.0, Postgres 16.15) where the previous revision
|
|
17
|
+
named a different one (WSL2, Node v18.19.1, Postgres 16.14), and it carries both
|
|
18
|
+
raw JSON files — before at `09b2100`, after at `46acd75` — from the same machine,
|
|
19
|
+
so the improvement it reports is attributed to the code change rather than to the
|
|
20
|
+
platform change that happened alongside it. The archived Linux run is kept and
|
|
21
|
+
labelled "do not quote next to these cells". `LIMITATIONS.md` and its Turkish
|
|
22
|
+
counterpart carry the new figures with the new environment named in the same
|
|
23
|
+
sentence. Raising the warning threshold from 100 to 500 is a behaviour change and
|
|
24
|
+
`test/threshold_source.mjs` now reads it from
|
|
25
|
+
`docs/benchmarks/masking-cost-threshold.json` instead of a second hand-written
|
|
26
|
+
copy, so the document and the doctor cannot drift apart. Nothing there says more
|
|
27
|
+
than the runs establish.
|
|
28
|
+
|
|
29
|
+
## Findings
|
|
30
|
+
|
|
31
|
+
### 1. README.md:331 and docs/PRICING.md:10,14,35 — the package sold something that cannot be bought
|
|
32
|
+
|
|
33
|
+
- Claim: "VAT added where applicable. Buy at [conarium.dev/buy](https://conarium.dev/buy)."
|
|
34
|
+
(`README.md`), the Button column entry "Get started → `/buy?plan=pro&period=monthly|yearly`"
|
|
35
|
+
under the heading "Pricing (same words as the site)", the section title "Pro (sold)",
|
|
36
|
+
and "The waitlist form (`#cta`) ... is not Pro checkout ... Pro never uses it."
|
|
37
|
+
(`docs/PRICING.md`)
|
|
38
|
+
- Mechanism: the `/buy` route on conarium.dev, the Pro card buttons, and the
|
|
39
|
+
`CONARIUM_CHECKOUT_LIVE` gate that fronts `/api/checkout/init`
|
|
40
|
+
- Why it falls short: measured on the live site while writing this record — `/buy`,
|
|
41
|
+
`/buy?plan=pro&period=monthly` and `/buy?plan=pro&period=yearly` each answer `302`
|
|
42
|
+
to `https://conarium.dev/#cta`; both Pro buttons carry `href="#cta"`; and
|
|
43
|
+
`/api/checkout/live` returns `{"live":false}`. Every purchase path leads to the
|
|
44
|
+
waitlist form, which is the one destination `PRICING.md` states Pro never uses.
|
|
45
|
+
A reader who installs the package and follows the instruction reaches a mailing
|
|
46
|
+
list signup. "Same words as the site" is also not met: the site's button target
|
|
47
|
+
is `#cta`, the file's is `/buy?plan=pro`.
|
|
48
|
+
- Disposition: reworded in `6435b56`. The price stands as published terms; the
|
|
49
|
+
purchase instruction is replaced by what `/buy` does today, and each edit names
|
|
50
|
+
the condition that reverses it, so opening the payment path is an edit to a
|
|
51
|
+
stated clause rather than a search through prose.
|
|
52
|
+
|
|
53
|
+
### 2. test/denetci.mjs — a promise surface with no assigned reader
|
|
54
|
+
|
|
55
|
+
- Claim: not a sentence — the absence of one. `docs/PRICING.md` states a price, a
|
|
56
|
+
refund window, a fair-use limit and what each tier delivers, and it ships in the
|
|
57
|
+
tarball under the `docs` entry of `package.json` `files`.
|
|
58
|
+
- Mechanism: the `SURFACES` list in `test/denetci.mjs`, which decides what a
|
|
59
|
+
release reviewer is shown
|
|
60
|
+
- Why it falls short: the file was not on that list, so its claims would have
|
|
61
|
+
reached npm unread. The gate itself reported this — `denetci.mjs input` printed
|
|
62
|
+
"unlisted: docs/PRICING.md — changed here, not read as a claim surface" — which
|
|
63
|
+
is the drift guard on the hand-written list working as intended, and the first
|
|
64
|
+
reading of the file produced finding 1.
|
|
65
|
+
- Disposition: accepted; listed in `6435b56` with the reason recorded at the entry.
|
|
66
|
+
|
|
67
|
+
Both findings are the same failure the earlier records describe: a guard locks
|
|
68
|
+
phrasings already caught and cannot see a new one. `claim_discipline.mjs` passes
|
|
69
|
+
on this tree (11 surfaces, 13 previously-published overclaims, no drift) and was
|
|
70
|
+
passing on the text that told the reader to buy.
|
|
71
|
+
|
|
72
|
+
A note repeated from 0.2.29 and 0.2.30, because it applies here too: the gate this
|
|
73
|
+
file satisfies calls itself "the one check a human has to answer". A human did not
|
|
74
|
+
read these diffs; an assistant did, at the maintainer's instruction. The gate
|
|
75
|
+
verifies that a record exists and that the claim surfaces have not moved since it
|
|
76
|
+
was written. It does not verify who wrote it.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Claims review — 0.2.32
|
|
2
|
+
|
|
3
|
+
- base: v0.2.31
|
|
4
|
+
- head: 4614ed4
|
|
5
|
+
- surface: sha256:a07a8a6e91f86dc4c34a343a4d76cb9213ccb509b9b4db578e6abf5890e97291
|
|
6
|
+
- verdict: pass
|
|
7
|
+
- reviewer: Claude, reading on the maintainer's instruction — an assistant read, not an independent human one
|
|
8
|
+
|
|
9
|
+
The surface hash is unchanged from 0.2.31: none of the seventeen listed documents
|
|
10
|
+
was touched. Everything claimed in this release is claimed somewhere the list does
|
|
11
|
+
not look, which is the finding below.
|
|
12
|
+
|
|
13
|
+
`CHANGELOG.md` gained four entries and is deliberately not a claim surface — it
|
|
14
|
+
records what happened rather than promising what the product does. It was three
|
|
15
|
+
versions behind the package, which is its own kind of dishonesty in a file that
|
|
16
|
+
ships in the tarball, and that is repaired here.
|
|
17
|
+
|
|
18
|
+
## Findings
|
|
19
|
+
|
|
20
|
+
### 1. src/server.ts — the tool descriptions are a claim surface with no reader
|
|
21
|
+
|
|
22
|
+
- Claim: not one sentence but a location. The four MCP tool descriptions ship in
|
|
23
|
+
the tarball, are handed to the model on every session, and this release
|
|
24
|
+
rewrote all of them to make behavioural promises: what is read-only, what the
|
|
25
|
+
output looks like, what the policy has already done to it.
|
|
26
|
+
- Mechanism: the `SURFACES` list in `test/denetci.mjs`, which decides what a
|
|
27
|
+
release reviewer is shown.
|
|
28
|
+
- Why it falls short: `src/server.ts` is not on that list and cannot usefully be
|
|
29
|
+
added — it is a code file, and listing it would put every unrelated diff in
|
|
30
|
+
front of the reviewer until the reviewer stops reading. So the most-read text
|
|
31
|
+
in the package, the text an agent actually acts on, went past the gate
|
|
32
|
+
unexamined. This review caught the two findings below only because the same
|
|
33
|
+
person happened to write them.
|
|
34
|
+
- Disposition: accepted, not fixed here. The repair is to derive the descriptions
|
|
35
|
+
from one file that can be listed, which is a change to how the server is
|
|
36
|
+
assembled and does not belong in a release about wording.
|
|
37
|
+
|
|
38
|
+
### 2. src/server.ts — "Every call is recorded in a signed receipt"
|
|
39
|
+
|
|
40
|
+
- Claim: `"Every call is recorded in a signed receipt."` — written into all four
|
|
41
|
+
tool descriptions in this release's first draft.
|
|
42
|
+
- Mechanism: `AuditLog` in `src/audit.ts`, whose receipt chain is guarded by
|
|
43
|
+
`receiptSink`.
|
|
44
|
+
- Why it falls short: receipts are opt-in. `src/audit.ts:291` states it plainly —
|
|
45
|
+
*"Makbuz zinciri durumu — opt-in (receiptSink verilirse aktif)"* — and
|
|
46
|
+
`src/audit.ts:415` returns early when no sink is set. With no `receiptSink` in
|
|
47
|
+
the config there is no receipt at all, so "every call" describes a
|
|
48
|
+
configuration rather than the product. What *is* unconditional is the ledger
|
|
49
|
+
entry; and where a sink is configured the signature is guaranteed, because the
|
|
50
|
+
server refuses to start with a sink and no Ed25519 key.
|
|
51
|
+
- Disposition: reworded before commit. The descriptions now say the call is
|
|
52
|
+
written to the audit ledger, and to a signed receipt as well when a receipt
|
|
53
|
+
sink is configured.
|
|
54
|
+
|
|
55
|
+
### 3. src/server.ts — "Scopes outside the policy are skipped rather than searched"
|
|
56
|
+
|
|
57
|
+
- Claim: `"Scopes outside the policy are skipped rather than searched."` — first
|
|
58
|
+
draft of the `search` description.
|
|
59
|
+
- Mechanism: the `search` branch in `src/server.ts`.
|
|
60
|
+
- Why it falls short: I could not find the skip. The branch records a denial and
|
|
61
|
+
raises, which reads as a refused call rather than a narrowed one, and "skipped"
|
|
62
|
+
asserts a specific behaviour a caller would plan around — silently getting
|
|
63
|
+
fewer scopes is a different contract from being refused.
|
|
64
|
+
- Disposition: reworded before commit to what the code does establish: the policy
|
|
65
|
+
decides which scopes are searchable at all.
|
|
66
|
+
|
|
67
|
+
Two of the three findings are sentences written in this release and corrected
|
|
68
|
+
before it left. That is the gate working in the only way it can here, and also
|
|
69
|
+
the reason finding 1 matters: nothing structural would have caught them.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@conarium-ai/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.32",
|
|
4
4
|
"mcpName": "io.github.dogrucanemek-alt/conarium",
|
|
5
5
|
"//files-artefakt": "examples/ altindaki uretilmis dosyalar (ozel anahtar, makbuz/denetim JSONL) ELENIR. .gitignore npm'i baglamaz: izin listesinde 'examples' oldugu icin demoyu kosturmus bir makinede 'npm publish' _keys/audit-ed25519.pem'i (OZEL ANAHTAR) ve makbuzlari yayinliyordu. test/pack_artefakt.mjs bunu kilitler. Elemeler examples/ ile SINIRLI: test-vectors/ altindaki receipts.jsonl ve .pub.pem YAYINLANMAK ZORUNDA, yoksa ucuncu taraf konformans vektorlerini kosturamaz.",
|
|
6
6
|
"//files": "Pakete NE gireceginin izin listesi. Liste olmadan npm her seyi gonderiyordu: 296 dosya / 1.5 MB — CI workflowlari, gitleaks ayari, 137 KB pazarlama gorseli, sitenin api/chat.js dosyasi. Bir bankanin guvenlik ekibi tarball'i acip bunlari gorur. scripts/ BILEREK var: conarium-reconcile calisirken scripts/pg-snapshot.sql'e atif yapiyor, olmazsa kullanici destek maili yazar.",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"scripts",
|
|
11
11
|
"docs",
|
|
12
12
|
"!docs/reviews",
|
|
13
|
+
"!docs/benchmarks/*.cpuprofile",
|
|
13
14
|
"public",
|
|
14
15
|
"assets",
|
|
15
16
|
"examples",
|
|
@@ -78,6 +79,7 @@
|
|
|
78
79
|
"conarium-stamp": "bin/conarium-stamp.mjs",
|
|
79
80
|
"conarium-anchor-service": "bin/conarium-anchor-service.mjs",
|
|
80
81
|
"conarium-anchor-upgrade": "bin/conarium-anchor-upgrade.mjs",
|
|
82
|
+
"conarium-token-sync": "bin/conarium-token-sync.mjs",
|
|
81
83
|
"conarium-console": "bin/conarium-console.mjs",
|
|
82
84
|
"conarium-suggest-policy": "bin/conarium-suggest-policy.mjs"
|
|
83
85
|
},
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* One-shot profiler for the 5 000-row masked redact path.
|
|
4
|
+
* Does not publish numbers into docs/BENCHMARK.md.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync, writeFileSync } from 'node:fs'
|
|
7
|
+
import { dirname, join } from 'node:path'
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
9
|
+
import { performance } from 'node:perf_hooks'
|
|
10
|
+
|
|
11
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
12
|
+
const govJs = join(root, 'dist', 'governance.js')
|
|
13
|
+
if (!existsSync(govJs)) {
|
|
14
|
+
console.error('dist/governance.js missing — run npm run build first')
|
|
15
|
+
process.exit(2)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { Governance } = await import(pathToFileURL(govJs).href)
|
|
19
|
+
const n = Number(process.argv[2] || 5_000)
|
|
20
|
+
const SECRET_EMAIL = 'bench-secret-user@example.com'
|
|
21
|
+
const QUERY = 'SELECT id, name, email, note FROM public.bench_customers ORDER BY id'
|
|
22
|
+
|
|
23
|
+
function syntheticRows(count) {
|
|
24
|
+
const rows = new Array(count)
|
|
25
|
+
for (let i = 1; i <= count; i++) {
|
|
26
|
+
rows[i - 1] = {
|
|
27
|
+
id: i,
|
|
28
|
+
name: `user-${i}`,
|
|
29
|
+
email: i === 1 ? SECRET_EMAIL : `user-${i}@example.com`,
|
|
30
|
+
note: `note ${i}`,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return rows
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function escapeRegExp(value) {
|
|
37
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function knownValueMatchers(values) {
|
|
41
|
+
const unique = new Set()
|
|
42
|
+
for (const value of values) {
|
|
43
|
+
const trimmed = value.trim()
|
|
44
|
+
if (trimmed.length >= 3) unique.add(trimmed)
|
|
45
|
+
}
|
|
46
|
+
return [...unique]
|
|
47
|
+
.sort((a, b) => b.length - a.length)
|
|
48
|
+
.map((v) => new RegExp(`(?<![\\p{L}\\p{N}])${escapeRegExp(v)}(?![\\p{L}\\p{N}])`, 'giu'))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function redactKnownValues(text, matchers) {
|
|
52
|
+
let out = text
|
|
53
|
+
let count = 0
|
|
54
|
+
for (const matcher of matchers) {
|
|
55
|
+
out = out.replace(matcher, () => {
|
|
56
|
+
count++
|
|
57
|
+
return '[MASKED_PII]'
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
return { text: out, count }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const rows = syntheticRows(n)
|
|
64
|
+
const declared = rows.map((r) => r.email)
|
|
65
|
+
|
|
66
|
+
const tCompile0 = performance.now()
|
|
67
|
+
const matchers = knownValueMatchers(declared)
|
|
68
|
+
const compileMs = performance.now() - tCompile0
|
|
69
|
+
|
|
70
|
+
const nameSample = rows[0].name
|
|
71
|
+
const noteSample = rows[0].note
|
|
72
|
+
const tOneField0 = performance.now()
|
|
73
|
+
redactKnownValues(nameSample, matchers)
|
|
74
|
+
redactKnownValues(noteSample, matchers)
|
|
75
|
+
const oneRowCarryMs = performance.now() - tOneField0
|
|
76
|
+
|
|
77
|
+
const tAllCarry0 = performance.now()
|
|
78
|
+
let carryHits = 0
|
|
79
|
+
for (const row of rows) {
|
|
80
|
+
carryHits += redactKnownValues(row.name, matchers).count
|
|
81
|
+
carryHits += redactKnownValues(row.note, matchers).count
|
|
82
|
+
}
|
|
83
|
+
const allCarryMs = performance.now() - tAllCarry0
|
|
84
|
+
|
|
85
|
+
const govPartial = new Governance({
|
|
86
|
+
allowTables: ['public.bench_customers'],
|
|
87
|
+
maskColumns: ['*.email'],
|
|
88
|
+
maxRows: Math.max(n, 100),
|
|
89
|
+
})
|
|
90
|
+
const govAllow = new Governance({
|
|
91
|
+
allowTables: ['public.bench_customers'],
|
|
92
|
+
maxRows: Math.max(n, 100),
|
|
93
|
+
})
|
|
94
|
+
const guarded = govPartial.guardQuery(QUERY)
|
|
95
|
+
const payload = {
|
|
96
|
+
rows,
|
|
97
|
+
rowCount: n,
|
|
98
|
+
fields: ['id', 'name', 'email', 'note'],
|
|
99
|
+
sql: guarded.sql,
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// warmup
|
|
103
|
+
govPartial.redact(payload, guarded.aliases, guarded.metadata)
|
|
104
|
+
govAllow.redact(payload, guarded.aliases, guarded.metadata)
|
|
105
|
+
|
|
106
|
+
const tPartial0 = performance.now()
|
|
107
|
+
const partial = govPartial.redact(payload, guarded.aliases, guarded.metadata)
|
|
108
|
+
const partialMs = performance.now() - tPartial0
|
|
109
|
+
|
|
110
|
+
const tAllow0 = performance.now()
|
|
111
|
+
const allow = govAllow.redact(payload, guarded.aliases, guarded.metadata)
|
|
112
|
+
const allowMs = performance.now() - tAllow0
|
|
113
|
+
|
|
114
|
+
const report = {
|
|
115
|
+
n,
|
|
116
|
+
node: process.version,
|
|
117
|
+
compileMatchersMs: compileMs,
|
|
118
|
+
matcherCount: matchers.length,
|
|
119
|
+
oneRowTwoFieldsCarryMs: oneRowCarryMs,
|
|
120
|
+
allRowsCarryOnlyMs: allCarryMs,
|
|
121
|
+
carryHits,
|
|
122
|
+
fullRedactPartialMs: partialMs,
|
|
123
|
+
fullRedactAllowMs: allowMs,
|
|
124
|
+
impliedCarryPerRowMs: allCarryMs / n,
|
|
125
|
+
impliedIfLinearFrom100: (allCarryMs / n) * 100,
|
|
126
|
+
quadraticSignature: {
|
|
127
|
+
matchers: matchers.length,
|
|
128
|
+
fieldsPerRow: 2,
|
|
129
|
+
replaceCalls: matchers.length * n * 2,
|
|
130
|
+
},
|
|
131
|
+
maskedCountPartial: partial.governance.maskedCount,
|
|
132
|
+
maskedCountAllow: allow.governance.maskedCount,
|
|
133
|
+
byClassPartial: partial.governance.byClass ?? {},
|
|
134
|
+
byClassAllow: allow.governance.byClass ?? {},
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const outPath = join(root, 'docs', 'benchmarks', `masking-profile-${n}.json`)
|
|
138
|
+
writeFileSync(outPath, JSON.stringify(report, null, 2) + '\n')
|
|
139
|
+
console.log(JSON.stringify(report, null, 2))
|
|
140
|
+
console.log(`wrote ${outPath}`)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Isolated one-shot: kind=allow|partial|carry [n] */
|
|
3
|
+
import { existsSync } from 'node:fs'
|
|
4
|
+
import { dirname, join } from 'node:path'
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
6
|
+
import { performance } from 'node:perf_hooks'
|
|
7
|
+
|
|
8
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
9
|
+
const govJs = join(root, 'dist', 'governance.js')
|
|
10
|
+
if (!existsSync(govJs)) {
|
|
11
|
+
console.error('dist/governance.js missing')
|
|
12
|
+
process.exit(2)
|
|
13
|
+
}
|
|
14
|
+
const { Governance } = await import(pathToFileURL(govJs).href)
|
|
15
|
+
|
|
16
|
+
const kind = process.argv[2] || 'partial'
|
|
17
|
+
const n = Number(process.argv[3] || 5_000)
|
|
18
|
+
const SECRET_EMAIL = 'bench-secret-user@example.com'
|
|
19
|
+
const QUERY = 'SELECT id, name, email, note FROM public.bench_customers ORDER BY id'
|
|
20
|
+
|
|
21
|
+
const rows = new Array(n)
|
|
22
|
+
for (let i = 1; i <= n; i++) {
|
|
23
|
+
rows[i - 1] = {
|
|
24
|
+
id: i,
|
|
25
|
+
name: `user-${i}`,
|
|
26
|
+
email: i === 1 ? SECRET_EMAIL : `user-${i}@example.com`,
|
|
27
|
+
note: `note ${i}`,
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (kind === 'carry') {
|
|
32
|
+
const declared = rows.map((r) => r.email)
|
|
33
|
+
const unique = new Set()
|
|
34
|
+
for (const value of declared) {
|
|
35
|
+
const trimmed = value.trim()
|
|
36
|
+
if (trimmed.length >= 3) unique.add(trimmed)
|
|
37
|
+
}
|
|
38
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
39
|
+
const t0 = performance.now()
|
|
40
|
+
const matchers = [...unique]
|
|
41
|
+
.sort((a, b) => b.length - a.length)
|
|
42
|
+
.map((v) => new RegExp(`(?<![\\p{L}\\p{N}])${escapeRegExp(v)}(?![\\p{L}\\p{N}])`, 'giu'))
|
|
43
|
+
const compileMs = performance.now() - t0
|
|
44
|
+
const t1 = performance.now()
|
|
45
|
+
let hits = 0
|
|
46
|
+
for (const row of rows) {
|
|
47
|
+
for (const text of [row.name, row.note]) {
|
|
48
|
+
let out = text
|
|
49
|
+
for (const matcher of matchers) {
|
|
50
|
+
out = out.replace(matcher, () => {
|
|
51
|
+
hits++
|
|
52
|
+
return '[MASKED_PII]'
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const applyMs = performance.now() - t1
|
|
58
|
+
console.log(JSON.stringify({ kind, n, compileMs, applyMs, hits, matchers: matchers.length }))
|
|
59
|
+
process.exit(0)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const policy =
|
|
63
|
+
kind === 'allow'
|
|
64
|
+
? { allowTables: ['public.bench_customers'], maxRows: Math.max(n, 100) }
|
|
65
|
+
: { allowTables: ['public.bench_customers'], maskColumns: ['*.email'], maxRows: Math.max(n, 100) }
|
|
66
|
+
const gov = new Governance(policy)
|
|
67
|
+
const guarded = gov.guardQuery(QUERY)
|
|
68
|
+
const payload = { rows, rowCount: n, fields: ['id', 'name', 'email', 'note'], sql: guarded.sql }
|
|
69
|
+
const t0 = performance.now()
|
|
70
|
+
const out = gov.redact(payload, guarded.aliases, guarded.metadata)
|
|
71
|
+
const ms = performance.now() - t0
|
|
72
|
+
console.log(JSON.stringify({
|
|
73
|
+
kind,
|
|
74
|
+
n,
|
|
75
|
+
ms,
|
|
76
|
+
maskedCount: out.governance.maskedCount,
|
|
77
|
+
byClass: out.governance.byClass ?? {},
|
|
78
|
+
maskedFields: out.governance.maskedFields,
|
|
79
|
+
}))
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** Hash of redact output for the bench-shaped unique-email payload. */
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
4
|
+
import { existsSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { dirname, join } from 'node:path'
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
7
|
+
|
|
8
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
|
|
9
|
+
const govJs = join(root, 'dist', 'governance.js')
|
|
10
|
+
if (!existsSync(govJs)) process.exit(2)
|
|
11
|
+
const { Governance } = await import(pathToFileURL(govJs).href)
|
|
12
|
+
|
|
13
|
+
const SECRET_EMAIL = 'bench-secret-user@example.com'
|
|
14
|
+
const QUERY = 'SELECT id, name, email, note FROM public.bench_customers ORDER BY id'
|
|
15
|
+
const label = process.argv[2] || 'before'
|
|
16
|
+
const sizes = (process.argv[3] || '100,500,5000').split(',').map(Number)
|
|
17
|
+
|
|
18
|
+
function rows(n) {
|
|
19
|
+
return Array.from({ length: n }, (_, i) => {
|
|
20
|
+
const id = i + 1
|
|
21
|
+
return {
|
|
22
|
+
id,
|
|
23
|
+
name: `user-${id}`,
|
|
24
|
+
email: id === 1 ? SECRET_EMAIL : `user-${id}@example.com`,
|
|
25
|
+
note: `note ${id}`,
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const out = { label, node: process.version, sizes: {} }
|
|
31
|
+
for (const n of sizes) {
|
|
32
|
+
const gov = new Governance({
|
|
33
|
+
allowTables: ['public.bench_customers'],
|
|
34
|
+
maskColumns: ['*.email'],
|
|
35
|
+
maxRows: Math.max(n, 100),
|
|
36
|
+
})
|
|
37
|
+
const guarded = gov.guardQuery(QUERY)
|
|
38
|
+
const result = gov.redact(
|
|
39
|
+
{ rows: rows(n), rowCount: n, fields: ['id', 'name', 'email', 'note'], sql: guarded.sql },
|
|
40
|
+
guarded.aliases,
|
|
41
|
+
guarded.metadata,
|
|
42
|
+
)
|
|
43
|
+
const body = JSON.stringify({
|
|
44
|
+
rows: result.rows,
|
|
45
|
+
maskedCount: result.governance.maskedCount,
|
|
46
|
+
byClass: result.governance.byClass ?? {},
|
|
47
|
+
maskedFields: result.governance.maskedFields,
|
|
48
|
+
})
|
|
49
|
+
out.sizes[String(n)] = {
|
|
50
|
+
sha256: createHash('sha256').update(body).digest('hex'),
|
|
51
|
+
maskedCount: result.governance.maskedCount,
|
|
52
|
+
byClass: result.governance.byClass ?? {},
|
|
53
|
+
maskedFields: result.governance.maskedFields,
|
|
54
|
+
sampleRow: result.rows[0],
|
|
55
|
+
lastRow: result.rows[n - 1],
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const path = join(root, 'docs', 'benchmarks', `masking-identity-${label}.json`)
|
|
60
|
+
writeFileSync(path, JSON.stringify(out, null, 2) + '\n')
|
|
61
|
+
console.log(JSON.stringify(out, null, 2))
|
|
62
|
+
console.log(`wrote ${path}`)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
|
|
4
|
+
const raw = JSON.parse(readFileSync(process.argv[2], 'utf8'))
|
|
5
|
+
const nodes = raw.nodes || []
|
|
6
|
+
const self = new Map()
|
|
7
|
+
let total = 0
|
|
8
|
+
for (const node of nodes) {
|
|
9
|
+
const hit = node.hitCount || 0
|
|
10
|
+
if (!hit) continue
|
|
11
|
+
total += hit
|
|
12
|
+
const f = node.callFrame || {}
|
|
13
|
+
const name = f.functionName || '(anonymous)'
|
|
14
|
+
const url = (f.url || '').replace(/^file:\/\//, '')
|
|
15
|
+
const line = typeof f.lineNumber === 'number' ? f.lineNumber + 1 : '?'
|
|
16
|
+
const key = `${name} ${url}:${line}`
|
|
17
|
+
self.set(key, (self.get(key) || 0) + hit)
|
|
18
|
+
}
|
|
19
|
+
const ranked = [...self.entries()].sort((a, b) => b[1] - a[1]).slice(0, 25)
|
|
20
|
+
for (const [key, hit] of ranked) {
|
|
21
|
+
const pct = total ? ((100 * hit) / total).toFixed(1) : '0'
|
|
22
|
+
console.log(`${String(hit).padStart(8)} ${pct.padStart(5)}% ${key}`)
|
|
23
|
+
}
|
|
24
|
+
console.log(`total hits ${total}`)
|