Repository navigation
Conversation
Replace the per-character canonical mapping with compact segments and a lazy array view. Printable ASCII runs are lowercased in bulk, common non-ASCII characters are cached, and the existing offset/fold contract is preserved for callers and tests. Also route config domain normalization through the shared URL policy, fail closed on malformed wildcard placement, remove compiler-proven dead code, and add deterministic property/invariant tests plus a reproducible benchmark.
Use median/p95 results from the committed benchmark harness on the stated hardware, and scope tsconfig to the new benchmark file instead of every script.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes evidence canonicalization and the operations built on it
substantially faster, adds a deterministic invariant/property suite for the
pure policy layers, routes config domain normalization through the shared URL
policy, and removes compiler-proven dead code.
It is applied on top of current
origin/main(c9681b2). It does notinclude PR #26; it was independently merged with PR #26 in a separate worktree
and re-tested (see Reconciliation).
What changed
src/shared/evidence.ts: replace the per-character canonical mapping withcompact segments and a lazy array view. Printable ASCII runs are lowercased
in bulk; non-ASCII characters keep the exact NFKC/NFD/fold behavior and a
bounded cache avoids re-normalizing repeated characters.
src/shared/search.ts: use the compact mapping accessors for case-insensitiveliteral search offsets.
src/shared/url-policy.ts/src/config.ts: one shared domain normalizer.Normalization is idempotent, strips mixed leading/trailing dot and whitespace
forms, and fails closed on malformed wildcard placement instead of turning
".*.a"into the broader bare host"a".the compiler and an import scan proved unused. No workflow, recovery, policy
evaluation or browser-control behavior is changed.
test/unit/invariants.test.ts: 36 deterministic invariant/property tests.docs/invariants.md: invariant catalog, fix-history coverage,counterexamples, benchmark methodology and limitations.
scripts/bench-evidence.ts+npm run bench:evidence: reproduciblewarmup/median/p95 benchmark.
Correctness and parity
generated mixed Unicode corpus: 20,157/20,157 exact matches, including
text, starts, ends and folds.
smart punctuation, full-width characters, circled numbers, emoji, invisible
characters, leading/trailing whitespace, tabs/newlines and collapsed runs.
tests pass.
Performance
Method: Windows 11, Node v22.15.1 (win32/x64), AMD Ryzen 7 4800H (16 logical
CPUs), 23.4 GiB RAM.
npm run bench:evidence: 3 warmup runs, 15 measurediterations (5 MB uses 5), median and p95. The same harness was run in a detached
origin/mainworktree for the baseline.ASCII page = repeated 70-character ASCII sentence. Mixed page = repeated
sentence with accented Latin, curly quotes, an em dash and an apostrophe.
1 MB p95: canonicalization 688 → 6.0 ms; literal 669 → 6.6 ms; normalized
594 → 4.8 ms; fuzzy 622 → 94 ms. 5 MB p95: 3,513 → 13.2 ms; 3,046 → 16.7 ms;
2,791 → 14.8 ms; 2,721 → 107 ms.
Limitations: the 100x+ result is for predominantly ASCII pages. Mixed-script
pages are ~3.4x because per-character segments dominate. Fuzzy matching is
still dominated by bounded Levenshtein distance; it was not forced to 100x
because that would alter matching semantics.
Invariants and counterexamples
Exhaustive over finite domains: every policy mode × capability, every
permanent deny/restriction, every invalid-policy capability, every mutating
tool mapping, every site-scoped URL requirement, every short URL/domain string
over a stated alphabet, and every boolean-type config rejection case.
Seeded property tests: canonical mapping bounds/order/folds, canonicalization
idempotence, literal-search span validity, ambiguity/context behavior,
audit redaction and outcome derivation, snapshot caps, target normalization,
and config fail-closed parsing.
Counterexamples found and fixed:
normalizeDomainEntrywas not idempotent (".*.a"→"*.a"→"a").config.tshad a second domain parser that left trailing dots.".*.a"into the bare host"a"; it now fails closed instead.run's end offset instead of its first character's offset; both were caught
by the parity corpus and fixed.
Reconciliation with main and PR #26
origin/main(c9681b2); onlyCHANGELOG.mdconflicted.origin/phase7/workflow-execution-engine-20261203(PR feat(workflows): bounded workflow execution engine with safe resume #26) into aseparate worktree, resolving only
CHANGELOG.mdand thestartPageServerhelper conflict. No workflow execution, recovery, cancellation or checkpoint
code was modified.
npm run typecheck,npm run build, andnpm testpass:758 tests, 743 pass, 15 skip, 0 fail.
CHANGELOG.mdandtest/integration/helpers.ts.Dead code
Removed 98 lines: 9 unused exports and 10 unused locals/parameters/imports.
tsc --noUnusedLocals --noUnusedParametersis clean for the changed source.The two files with no relative importer (
src/bridge/entry.ts,src/onboard/skill-offer-cli.ts) are build entry points and were retained.Risks
ZEN_MCP_E2E=1and platform coverage is still tracked by issue Verify and fix macOS and Linux support #15.Not doing
main.