@sema-agent/core 7.62.0 → 7.64.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/CHANGELOG.md +936 -0
- package/dist/agents/cc-peer-directory.js +1 -0
- package/dist/agents/cc-peer-wire.d.ts +4 -0
- package/dist/agents/cc-peer-wire.js +1 -0
- package/dist/agents/cc-uds-peer-channel.js +5 -0
- package/dist/agents/cross-session-judge.d.ts +3 -1
- package/dist/agents/cross-session-judge.js +4 -1
- package/dist/agents/peer-directory.d.ts +8 -0
- package/dist/agents/peer-directory.js +4 -0
- package/dist/agents/peer-held-queue.d.ts +9 -3
- package/dist/agents/peer-held-queue.js +12 -9
- package/dist/agents/peer-idle.d.ts +20 -1
- package/dist/agents/peer-idle.js +23 -12
- package/dist/agents/peer-notice-route.d.ts +16 -5
- package/dist/agents/peer-notice-route.js +11 -9
- package/dist/agents/peer-notices.d.ts +25 -8
- package/dist/agents/peer-notices.js +6 -1
- package/dist/agents/peer-session-drain.d.ts +32 -6
- package/dist/agents/peer-session-drain.js +100 -26
- package/dist/agents/send-message-tool.d.ts +7 -0
- package/dist/agents/send-message-tool.js +18 -6
- package/dist/agents/subagent-transcript-placement.d.ts +23 -0
- package/dist/agents/subagent-transcript-placement.js +14 -0
- package/dist/agents/subagent.js +102 -54
- package/dist/brain/route-adjudicator.js +9 -4
- package/dist/core/allow-entry.d.ts +4 -0
- package/dist/core/approval-object.js +1 -1
- package/dist/core/arg-summary.js +1 -1
- package/dist/core/ask-origin.d.ts +1 -1
- package/dist/core/ask-origin.js +2 -2
- package/dist/core/ask-question.d.ts +2 -2
- package/dist/core/ask-unresolvable-notice.d.ts +13 -4
- package/dist/core/ask-unresolvable-notice.js +10 -3
- package/dist/core/auto-compaction.d.ts +7 -5
- package/dist/core/background-agent-store.d.ts +7 -0
- package/dist/core/background-agent-store.js +3 -0
- package/dist/core/canonical-json.d.ts +23 -13
- package/dist/core/canonical-json.js +4 -4
- package/dist/core/checkpoint-queries.d.ts +50 -4
- package/dist/core/checkpoint-queries.js +42 -17
- package/dist/core/checkpoint-requirements.d.ts +3 -3
- package/dist/core/checkpoint-requirements.js +2 -1
- package/dist/core/checkpoint-row-verdict.d.ts +15 -4
- package/dist/core/checkpoint-row-verdict.js +22 -2
- package/dist/core/checkpoint-store.d.ts +28 -11
- package/dist/core/checkpoint-store.js +45 -4
- package/dist/core/compliance.d.ts +6 -2
- package/dist/core/compliance.js +3 -3
- package/dist/core/context-settings.d.ts +40 -9
- package/dist/core/context-settings.js +32 -10
- package/dist/core/engine-attestation.d.ts +27 -7
- package/dist/core/engine-attestation.js +5 -1
- package/dist/core/engine-notice.d.ts +43 -5
- package/dist/core/extension-requester.d.ts +9 -0
- package/dist/core/extension-requester.js +7 -0
- package/dist/core/file-history-store.d.ts +28 -0
- package/dist/core/file-history-store.js +48 -5
- package/dist/core/fs-write-gate-policy.js +1 -1
- package/dist/core/gate-fold.js +2 -0
- package/dist/core/gate-lanes.js +2 -0
- package/dist/core/gate-outcome.d.ts +39 -2
- package/dist/core/gate-outcome.js +20 -1
- package/dist/core/git-worktree-env.d.ts +62 -3
- package/dist/core/git-worktree-env.js +91 -30
- package/dist/core/governance-codes.d.ts +9 -3
- package/dist/core/governance-codes.js +17 -3
- package/dist/core/leg-identity.d.ts +19 -1
- package/dist/core/leg-identity.js +12 -0
- package/dist/core/mailbox-store.d.ts +39 -4
- package/dist/core/mailbox-store.js +14 -2
- package/dist/core/memory-engine/consolidation-driver.d.ts +32 -17
- package/dist/core/memory-engine/consolidation-driver.js +99 -98
- package/dist/core/memory-engine/consolidation.d.ts +74 -10
- package/dist/core/memory-engine/consolidation.js +183 -11
- package/dist/core/memory-engine/control-objects.d.ts +25 -0
- package/dist/core/memory-engine/control-objects.js +151 -0
- package/dist/core/memory-engine/control-plane-adoption.d.ts +48 -0
- package/dist/core/memory-engine/control-plane-adoption.js +159 -0
- package/dist/core/memory-engine/data-plane.d.ts +8 -4
- package/dist/core/memory-engine/data-plane.js +11 -6
- package/dist/core/memory-engine/delegation-settlement.d.ts +58 -40
- package/dist/core/memory-engine/delegation-settlement.js +270 -85
- package/dist/core/memory-engine/dual-root.d.ts +12 -6
- package/dist/core/memory-engine/dual-root.js +11 -7
- package/dist/core/memory-engine/engine.d.ts +136 -58
- package/dist/core/memory-engine/engine.js +491 -394
- package/dist/core/memory-engine/entry-scan.d.ts +8 -0
- package/dist/core/memory-engine/entry-scan.js +3 -0
- package/dist/core/memory-engine/file-backend.d.ts +62 -60
- package/dist/core/memory-engine/file-backend.js +122 -198
- package/dist/core/memory-engine/index.d.ts +8 -7
- package/dist/core/memory-engine/index.js +7 -6
- package/dist/core/memory-engine/landing-admission.d.ts +5 -3
- package/dist/core/memory-engine/landing-admission.js +3 -3
- package/dist/core/memory-engine/layout.d.ts +127 -46
- package/dist/core/memory-engine/layout.js +264 -109
- package/dist/core/memory-engine/memory-backend-contract.d.ts +26 -1
- package/dist/core/memory-engine/memory-backend-contract.js +476 -0
- package/dist/core/memory-engine/memory-deployment.d.ts +42 -11
- package/dist/core/memory-engine/memory-deployment.js +54 -15
- package/dist/core/memory-engine/origin-clearance.d.ts +12 -3
- package/dist/core/memory-engine/origin-clearance.js +68 -9
- package/dist/core/memory-engine/scope-contract.d.ts +52 -11
- package/dist/core/memory-engine/scope-contract.js +68 -19
- package/dist/core/memory-engine/session-write-home.d.ts +37 -2
- package/dist/core/memory-engine/session-write-home.js +38 -11
- package/dist/core/memory-engine/sync-client.d.ts +3 -1
- package/dist/core/memory-engine/sync-client.js +7 -0
- package/dist/core/memory-engine/sync-report.d.ts +3 -2
- package/dist/core/memory-engine/sync-report.js +6 -2
- package/dist/core/memory-engine/tools.d.ts +2 -2
- package/dist/core/memory-engine/tools.js +10 -10
- package/dist/core/memory-engine/types.d.ts +155 -19
- package/dist/core/memory-engine/types.js +2 -0
- package/dist/core/memory.js +15 -6
- package/dist/core/mode-policy.js +3 -3
- package/dist/core/mods/agent-stations.d.ts +18 -0
- package/dist/core/mods/agent-stations.js +8 -6
- package/dist/core/mods/extension-call.d.ts +4 -0
- package/dist/core/mods/extension-call.js +8 -0
- package/dist/core/mods/stations.d.ts +20 -1
- package/dist/core/mods/stations.js +21 -2
- package/dist/core/mods/tool-call.js +3 -4
- package/dist/core/parent-spec-seat.d.ts +2 -2
- package/dist/core/park-selfcheck.js +2 -2
- package/dist/core/pause-registry.d.ts +2 -0
- package/dist/core/pause-registry.js +3 -0
- package/dist/core/peer-channel.d.ts +5 -0
- package/dist/core/permission-rule-consent.d.ts +26 -8
- package/dist/core/permission-rule-consent.js +76 -36
- package/dist/core/permission-rule-store.d.ts +72 -13
- package/dist/core/permission-rule-store.js +29 -8
- package/dist/core/read-only-shell.js +3 -2
- package/dist/core/redaction-marks.d.ts +8 -0
- package/dist/core/redaction-marks.js +6 -0
- package/dist/core/refusal-echo.d.ts +20 -0
- package/dist/core/refusal-echo.js +33 -0
- package/dist/core/remote-env.d.ts +12 -1
- package/dist/core/remote-env.js +3 -0
- package/dist/core/retention.d.ts +180 -10
- package/dist/core/retention.js +45 -0
- package/dist/core/retired-keys.d.ts +5 -0
- package/dist/core/retired-keys.js +3 -0
- package/dist/core/rule-offer-read.d.ts +0 -4
- package/dist/core/rule-offer-read.js +2 -18
- package/dist/core/runner/child-tree.d.ts +29 -3
- package/dist/core/runner/child-tree.js +39 -16
- package/dist/core/runner/classifier-ladder.d.ts +7 -1
- package/dist/core/runner/classifier-ladder.js +4 -2
- package/dist/core/runner/compact-session.js +10 -7
- package/dist/core/runner/compaction-call-options.d.ts +7 -7
- package/dist/core/runner/compaction-call-options.js +3 -2
- package/dist/core/runner/contracts.d.ts +39 -11
- package/dist/core/runner/delegation-owner.d.ts +10 -3
- package/dist/core/runner/delegation-owner.js +4 -1
- package/dist/core/runner/gate-exit.d.ts +6 -0
- package/dist/core/runner/gate-exit.js +13 -4
- package/dist/core/runner/inherited-ask-grants.js +1 -1
- package/dist/core/runner/memory-consolidation-driver.d.ts +10 -5
- package/dist/core/runner/memory-consolidation-driver.js +12 -9
- package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
- package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
- package/dist/core/runner/person-path-rows.d.ts +8 -3
- package/dist/core/runner/person-path-rows.js +5 -1
- package/dist/core/runner/placement-fence.d.ts +12 -0
- package/dist/core/runner/placement-fence.js +20 -6
- package/dist/core/runner/prepare-ask-lane.js +5 -5
- package/dist/core/runner/prepare-caps-and-workflow.d.ts +7 -2
- package/dist/core/runner/prepare-caps-and-workflow.js +7 -4
- package/dist/core/runner/prepare-config-doors.js +4 -0
- package/dist/core/runner/prepare-delegation-surface.d.ts +3 -0
- package/dist/core/runner/prepare-delegation-surface.js +2 -2
- package/dist/core/runner/prepare-execution-env.js +17 -6
- package/dist/core/runner/prepare-gate-stations.d.ts +5 -0
- package/dist/core/runner/prepare-gate-stations.js +5 -5
- package/dist/core/runner/prepare-hands-readface.d.ts +2 -1
- package/dist/core/runner/prepare-hands-readface.js +5 -4
- package/dist/core/runner/prepare-inherited-gate.d.ts +13 -9
- package/dist/core/runner/prepare-inherited-gate.js +12 -6
- package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
- package/dist/core/runner/prepare-memory-engine-session.js +4 -4
- package/dist/core/runner/prepare-memory.d.ts +7 -2
- package/dist/core/runner/prepare-memory.js +41 -39
- package/dist/core/runner/prepare-park-ask.js +4 -3
- package/dist/core/runner/prepare-policy-chain.js +7 -7
- package/dist/core/runner/prepare-prompt-inputs.js +1 -1
- package/dist/core/runner/prepare-task.js +26 -18
- package/dist/core/runner/prepare-wiring-manifest.d.ts +3 -1
- package/dist/core/runner/prepare-wiring-manifest.js +3 -2
- package/dist/core/runner/prepare-workspace-restore.js +3 -6
- package/dist/core/runner/resume-admission.d.ts +2 -2
- package/dist/core/runner/resume-admission.js +2 -23
- package/dist/core/runner/role-resolution-table.d.ts +98 -0
- package/dist/core/runner/role-resolution-table.js +62 -0
- package/dist/core/runner/run-compaction-machinery.js +2 -2
- package/dist/core/runner/run-identity-wiring.js +12 -9
- package/dist/core/runner/run-leg.js +9 -5
- package/dist/core/runner/run-notification-lane.js +22 -22
- package/dist/core/runner/run-recovery-lanes.js +3 -3
- package/dist/core/runner/run-settle-and-teardown.js +3 -2
- package/dist/core/runner/run-terminal-adoption.js +1 -1
- package/dist/core/runner/run-turn-boundary.js +14 -15
- package/dist/core/runner/runtask.js +1 -1
- package/dist/core/runner/terminal-account.js +1 -1
- package/dist/core/runner/tool-occurrence.d.ts +4 -2
- package/dist/core/runner/tool-occurrence.js +2 -2
- package/dist/core/runner-deps.d.ts +7 -3
- package/dist/core/secret-env.d.ts +1 -1
- package/dist/core/secret-env.js +4 -4
- package/dist/core/session-checkout.d.ts +168 -0
- package/dist/core/session-checkout.js +579 -0
- package/dist/core/session-store.d.ts +12 -4
- package/dist/core/session-store.js +23 -3
- package/dist/core/session.d.ts +16 -2
- package/dist/core/session.js +3 -0
- package/dist/core/shell-read-silence.js +8 -0
- package/dist/core/store-contracts/checkpoint-store-contract.d.ts +0 -12
- package/dist/core/store-contracts/checkpoint-store-contract.js +6 -7
- package/dist/core/store-contracts/peer-directory-contract.js +8 -1
- package/dist/core/store-contracts/session-store-contract.js +39 -0
- package/dist/core/task-event.d.ts +30 -5
- package/dist/core/task-notification.d.ts +119 -32
- package/dist/core/task-notification.js +186 -100
- package/dist/core/task-registry-agent.d.ts +25 -2
- package/dist/core/task-registry-agent.js +56 -22
- package/dist/core/task-registry-shared.d.ts +33 -11
- package/dist/core/task-registry.d.ts +33 -9
- package/dist/core/task-registry.js +36 -18
- package/dist/core/task-spec-members.js +1 -1
- package/dist/core/task-spec.d.ts +27 -2
- package/dist/core/tool-errors.d.ts +14 -6
- package/dist/core/tool-errors.js +1 -1
- package/dist/core/tool-policy.d.ts +32 -13
- package/dist/core/tool-policy.js +27 -17
- package/dist/core/tool-result-store.d.ts +20 -0
- package/dist/core/tool-spec.d.ts +42 -19
- package/dist/core/trace.d.ts +3 -2
- package/dist/core/types.d.ts +1 -1
- package/dist/core/untrusted-egress.d.ts +15 -4
- package/dist/core/untrusted-egress.js +23 -22
- package/dist/core/workflow-journal-store.d.ts +11 -0
- package/dist/core/workflow-journal-store.js +7 -0
- package/dist/core/workflow-run-store.d.ts +9 -0
- package/dist/core/workflow-run-store.js +6 -0
- package/dist/core/workspace-snapshot.d.ts +3 -1
- package/dist/core/workspace-snapshot.js +1 -0
- package/dist/engine/compaction/compaction.d.ts +2 -1
- package/dist/engine/harness/types.d.ts +67 -1
- package/dist/engine/harness/types.js +108 -0
- package/dist/engine/session/import-validate.js +6 -1
- package/dist/engine/session/session.d.ts +30 -1
- package/dist/engine/session/session.js +48 -1
- package/dist/index.d.ts +12 -7
- package/dist/index.js +12 -7
- package/dist/internal/harness-types.d.ts +1 -1
- package/dist/orchestration/run-workflow-tool.d.ts +8 -1
- package/dist/orchestration/run-workflow-tool.js +8 -0
- package/dist/orchestration/workflow-types.d.ts +2 -1
- package/dist/orchestration/workflow.d.ts +6 -0
- package/dist/orchestration/workflow.js +5 -2
- package/dist/stores/file/checkpoint-store.d.ts +6 -0
- package/dist/stores/file/checkpoint-store.js +4 -1
- package/dist/stores/file/file-history-store.d.ts +13 -0
- package/dist/stores/file/file-history-store.js +75 -13
- package/dist/stores/file/index.d.ts +11 -1
- package/dist/stores/file/index.js +7 -11
- package/dist/stores/file/permission-rule-store.d.ts +23 -0
- package/dist/stores/file/permission-rule-store.js +75 -7
- package/dist/stores/file/session-store.js +2 -1
- package/dist/stores/file/tool-result-store.d.ts +14 -0
- package/dist/stores/file/tool-result-store.js +39 -2
- package/dist/stores/file/workflow-journal-store.d.ts +4 -0
- package/dist/stores/file/workflow-journal-store.js +17 -0
- package/dist/stores/file/workflow-run-store.d.ts +3 -0
- package/dist/stores/file/workflow-run-store.js +15 -0
- package/dist/tools/fs/bash-program-position.js +3 -3
- package/dist/tools/fs/program-read-model.d.ts +34 -10
- package/dist/tools/fs/program-read-model.js +37 -7
- package/dist/tools/fs/program-read-model.rows.js +13 -2
- package/dist/tools/fs/read-deny.d.ts +28 -3
- package/dist/tools/fs/read-deny.js +18 -2
- package/dist/tools/fs/removal-targets.js +3 -3
- package/dist/tools/fs/safety.d.ts +2 -0
- package/dist/tools/fs/safety.js +1 -1
- package/dist/tools/fs/shell-read-argv.d.ts +8 -1
- package/dist/tools/fs/shell-read-argv.js +34 -29
- package/dist/tools/fs/shell-read-bindings.d.ts +2 -0
- package/dist/tools/fs/shell-read-bindings.js +5 -1
- package/dist/tools/fs/shell-read-brace.d.ts +18 -0
- package/dist/tools/fs/shell-read-brace.js +79 -0
- package/dist/tools/fs/shell-read-check.d.ts +8 -2
- package/dist/tools/fs/shell-read-check.js +16 -14
- package/dist/tools/fs/shell-read-establish.js +23 -16
- package/dist/tools/fs/shell-read-judge.d.ts +11 -0
- package/dist/tools/fs/shell-read-judge.js +3 -3
- package/dist/tools/fs/shell-read-plan.d.ts +10 -0
- package/dist/tools/fs/shell-read-plan.js +189 -93
- package/dist/tools/fs/shell-read-start.d.ts +19 -9
- package/dist/tools/fs/shell-read-start.js +20 -12
- package/dist/tools/fs/shell-read-word.d.ts +10 -0
- package/dist/tools/fs/shell-read-word.js +9 -5
- package/dist/tools/fs/shell-read-workdir.d.ts +26 -7
- package/dist/tools/fs/shell-read-workdir.js +73 -12
- package/dist/tools/fs/shell-read-write-targets.js +13 -8
- package/dist/tools/worktree.d.ts +3 -2
- package/dist/tools/worktree.js +7 -35
- package/package.json +3 -2
- package/test/export-surface.snapshot.json +135 -11
- package/wire-changes/core-stores-sql@7.63.0.json +30 -0
- package/wire-changes/core-stores-sql@7.64.0.json +30 -0
- package/wire-changes/core@7.63.0.json +3523 -0
- package/wire-changes/core@7.64.0.json +2653 -0
- package/wire-changes/mods-kernel@7.63.0.json +30 -0
- package/wire-changes/mods-kernel@7.64.0.json +30 -0
- package/wire-changes/primitives@7.63.0.json +445 -0
- package/wire-changes/primitives@7.64.0.json +30 -0
- package/dist/core/credential-vocabulary.d.ts +0 -176
- package/dist/core/credential-vocabulary.js +0 -190
- package/dist/core/redaction-passes.d.ts +0 -82
- package/dist/core/redaction-passes.js +0 -377
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
import { REDACTION_MARK, REDACTION_MARKS, redactionMarkerSpans } from "./redaction-marks.js";
|
|
2
|
-
export function summarizeRedactions(findings) {
|
|
3
|
-
if (findings.length === 0)
|
|
4
|
-
return "no redactions";
|
|
5
|
-
const counts = new Map();
|
|
6
|
-
for (const f of findings) {
|
|
7
|
-
const label = `${f.kind} (${f.confidence})`;
|
|
8
|
-
counts.set(label, (counts.get(label) ?? 0) + 1);
|
|
9
|
-
}
|
|
10
|
-
const parts = [...counts].map(([label, n]) => `${label} x${n}`);
|
|
11
|
-
return `${findings.length} redaction${findings.length === 1 ? "" : "s"}: ${parts.join(", ")}`;
|
|
12
|
-
}
|
|
13
|
-
function passZeroMapper(batches) {
|
|
14
|
-
const cursors = batches.map(() => ({ i: 0, delta: 0 }));
|
|
15
|
-
return (pos) => {
|
|
16
|
-
let p = pos;
|
|
17
|
-
for (let b = batches.length - 1; b >= 0; b--) {
|
|
18
|
-
const edits = batches[b];
|
|
19
|
-
const c = cursors[b];
|
|
20
|
-
let mapped;
|
|
21
|
-
while (mapped === undefined && c.i < edits.length) {
|
|
22
|
-
const e = edits[c.i];
|
|
23
|
-
const outStart = e.at + c.delta;
|
|
24
|
-
if (p < outStart)
|
|
25
|
-
mapped = p - c.delta;
|
|
26
|
-
else if (p < outStart + e.insertedLen)
|
|
27
|
-
mapped = e.at;
|
|
28
|
-
else {
|
|
29
|
-
c.delta += e.insertedLen - e.removedLen;
|
|
30
|
-
c.i++;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
p = mapped ?? p - c.delta;
|
|
34
|
-
}
|
|
35
|
-
return p;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
const FORMAT_CHAR_RE = /\p{Cf}/u;
|
|
39
|
-
const MAX_FORMAT_SLOT_SCANS = 64;
|
|
40
|
-
function finding(pass, span, family) {
|
|
41
|
-
const f = { kind: pass.kind, confidence: pass.confidence, span, marker: pass.marker, source: pass.source };
|
|
42
|
-
if (family !== undefined)
|
|
43
|
-
f.family = family;
|
|
44
|
-
return f;
|
|
45
|
-
}
|
|
46
|
-
function insertedFor(pass, match, groups) {
|
|
47
|
-
return typeof pass.replace === "string"
|
|
48
|
-
? pass.replace.replace(/\$(\d)/g, (_m, d) => groups[Number(d) - 1] ?? "")
|
|
49
|
-
: pass.replace(match, ...groups);
|
|
50
|
-
}
|
|
51
|
-
function removedRegion(pass, match, groups, inserted) {
|
|
52
|
-
if (typeof pass.replace === "string") {
|
|
53
|
-
const parts = pass.replace.split(/(\$\d)/).filter((p) => p !== "");
|
|
54
|
-
const isRef = (p) => /^\$\d$/.test(p);
|
|
55
|
-
const refText = (p) => groups[Number(p[1]) - 1] ?? "";
|
|
56
|
-
let head = "";
|
|
57
|
-
for (const p of parts) {
|
|
58
|
-
if (!isRef(p))
|
|
59
|
-
break;
|
|
60
|
-
head += refText(p);
|
|
61
|
-
}
|
|
62
|
-
let tail = "";
|
|
63
|
-
for (let i = parts.length - 1; i >= 0 && isRef(parts[i]); i--)
|
|
64
|
-
tail = refText(parts[i]) + tail;
|
|
65
|
-
if (parts.every(isRef))
|
|
66
|
-
return [0, match.length];
|
|
67
|
-
if (!match.startsWith(head))
|
|
68
|
-
head = "";
|
|
69
|
-
if (!match.endsWith(tail) || head.length + tail.length > match.length)
|
|
70
|
-
tail = "";
|
|
71
|
-
return [head.length, match.length - tail.length];
|
|
72
|
-
}
|
|
73
|
-
const markerAt = pass.marker === "" ? -1 : inserted.lastIndexOf(pass.marker);
|
|
74
|
-
const headStop = markerAt < 0 ? inserted.length : markerAt;
|
|
75
|
-
const tailStop = markerAt < 0 ? inserted.length : inserted.length - markerAt - pass.marker.length;
|
|
76
|
-
let head = 0;
|
|
77
|
-
while (head < match.length && head < headStop && match[head] === inserted[head])
|
|
78
|
-
head++;
|
|
79
|
-
let tail = 0;
|
|
80
|
-
while (tail < match.length - head && tail < inserted.length - head && tail < tailStop && match[match.length - 1 - tail] === inserted[inserted.length - 1 - tail])
|
|
81
|
-
tail++;
|
|
82
|
-
return [head, match.length - tail];
|
|
83
|
-
}
|
|
84
|
-
const SOLO_SCAN_WORK_PER_CHAR = 8;
|
|
85
|
-
const SOLO_SCAN_WORK_FLOOR = 1 << 17;
|
|
86
|
-
function soloHits(input, passes) {
|
|
87
|
-
const hits = [];
|
|
88
|
-
passes.forEach((pass, i) => {
|
|
89
|
-
const re = new RegExp(pass.re.source, pass.re.flags.includes("g") ? pass.re.flags : `${pass.re.flags}g`);
|
|
90
|
-
const rescans = pass.family !== undefined;
|
|
91
|
-
let work = Math.max(SOLO_SCAN_WORK_PER_CHAR * input.length, SOLO_SCAN_WORK_FLOOR);
|
|
92
|
-
for (let m = re.exec(input); m !== null; m = re.exec(input)) {
|
|
93
|
-
const at = m.index;
|
|
94
|
-
const familyAt = () => (typeof pass.family === "function" ? pass.family(input, at) : pass.family);
|
|
95
|
-
if (rescans) {
|
|
96
|
-
work -= m[0].length;
|
|
97
|
-
if (work < 0) {
|
|
98
|
-
hits.push({ start: at, end: input.length, marker: pass.marker === "" ? REDACTION_MARK : pass.marker, pass: i, family: familyAt(), matchStart: at, matchEnd: input.length });
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
re.lastIndex = at + 1;
|
|
102
|
-
}
|
|
103
|
-
else
|
|
104
|
-
re.lastIndex = at + Math.max(m[0].length, 1);
|
|
105
|
-
const inserted = insertedFor(pass, m[0], m.slice(1));
|
|
106
|
-
if (inserted === m[0])
|
|
107
|
-
continue;
|
|
108
|
-
const [a, b] = removedRegion(pass, m[0], m.slice(1), inserted);
|
|
109
|
-
if (b <= a)
|
|
110
|
-
continue;
|
|
111
|
-
const family = familyAt();
|
|
112
|
-
hits.push({ start: at + a, end: at + b, marker: inserted.slice(a, inserted.length - (m[0].length - b)), pass: i, family, matchStart: at, matchEnd: at + m[0].length });
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
return hits;
|
|
116
|
-
}
|
|
117
|
-
function unremovedHits(hits, removals) {
|
|
118
|
-
const gone = [];
|
|
119
|
-
for (const r of [...removals].filter((x) => x.end > x.start).sort((x, y) => x.start - y.start || y.end - x.end)) {
|
|
120
|
-
const last = gone[gone.length - 1];
|
|
121
|
-
if (last !== undefined && r.start <= last[1])
|
|
122
|
-
last[1] = Math.max(last[1], r.end);
|
|
123
|
-
else
|
|
124
|
-
gone.push([r.start, r.end]);
|
|
125
|
-
}
|
|
126
|
-
return hits.filter((h) => {
|
|
127
|
-
let lo = 0;
|
|
128
|
-
let hi = gone.length - 1;
|
|
129
|
-
let at = -1;
|
|
130
|
-
while (lo <= hi) {
|
|
131
|
-
const mid = (lo + hi) >> 1;
|
|
132
|
-
if (gone[mid][0] <= h.start) {
|
|
133
|
-
at = mid;
|
|
134
|
-
lo = mid + 1;
|
|
135
|
-
}
|
|
136
|
-
else
|
|
137
|
-
hi = mid - 1;
|
|
138
|
-
}
|
|
139
|
-
return at === -1 || gone[at][1] < h.end;
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
function sequentialRemovals(batches) {
|
|
143
|
-
const removals = [];
|
|
144
|
-
for (let j = 0; j < batches.length; j++) {
|
|
145
|
-
const toPassZero = passZeroMapper(batches.slice(0, j));
|
|
146
|
-
for (const e of batches[j]) {
|
|
147
|
-
const start = toPassZero(e.at + e.head);
|
|
148
|
-
const end = toPassZero(e.at + e.removedLen - e.tail);
|
|
149
|
-
removals.push({ start, end: Math.max(start, end), marker: e.inserted.slice(e.head, e.insertedLen - e.tail), pass: e.pass, family: e.family });
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
return removals;
|
|
153
|
-
}
|
|
154
|
-
function renderRemovals(input, removals) {
|
|
155
|
-
const sorted = removals.filter((r) => r.end > r.start || r.marker !== "").sort((x, y) => x.start - y.start || y.end - x.end);
|
|
156
|
-
const edits = [];
|
|
157
|
-
let out = "";
|
|
158
|
-
let cursor = 0;
|
|
159
|
-
for (let i = 0; i < sorted.length;) {
|
|
160
|
-
const start = sorted[i].start;
|
|
161
|
-
let end = sorted[i].end;
|
|
162
|
-
let widest;
|
|
163
|
-
for (; i < sorted.length && (sorted[i].start < end || sorted[i].start === start || (sorted[i].marker === "" && sorted[i].start === end)); i++) {
|
|
164
|
-
const r = sorted[i];
|
|
165
|
-
if (r.end > end)
|
|
166
|
-
end = r.end;
|
|
167
|
-
if (r.marker !== "" && (widest === undefined || r.end - r.start > widest.end - widest.start))
|
|
168
|
-
widest = r;
|
|
169
|
-
}
|
|
170
|
-
const marker = widest?.marker ?? REDACTION_MARK;
|
|
171
|
-
out += input.slice(cursor, start) + marker;
|
|
172
|
-
cursor = end;
|
|
173
|
-
edits.push({ at: start, removedLen: end - start, insertedLen: marker.length, inserted: marker, family: widest?.family, head: 0, tail: 0, pass: widest?.pass ?? sorted[i - 1].pass });
|
|
174
|
-
}
|
|
175
|
-
return { out: out + input.slice(cursor), edits };
|
|
176
|
-
}
|
|
177
|
-
function runPasses(input, passes, findings, toOriginal) {
|
|
178
|
-
const batches = [];
|
|
179
|
-
let cur = input;
|
|
180
|
-
passes.forEach((pass, passIndex) => {
|
|
181
|
-
const edits = [];
|
|
182
|
-
const passInput = cur;
|
|
183
|
-
const toPassZero = passZeroMapper(batches.slice());
|
|
184
|
-
cur = cur.replace(pass.re, (...args) => {
|
|
185
|
-
const match = args[0];
|
|
186
|
-
const offset = args[args.length - 2];
|
|
187
|
-
const groups = args.slice(1, -2);
|
|
188
|
-
const inserted = insertedFor(pass, match, groups);
|
|
189
|
-
if (inserted === match)
|
|
190
|
-
return inserted;
|
|
191
|
-
const family = typeof pass.family === "function" ? pass.family(passInput, offset) : pass.family;
|
|
192
|
-
if (findings !== undefined)
|
|
193
|
-
findings.push({ pass: passIndex, f: finding(pass, [toOriginal(toPassZero(offset)), toOriginal(toPassZero(offset + match.length))], family) });
|
|
194
|
-
const [a, b] = removedRegion(pass, match, groups, inserted);
|
|
195
|
-
edits.push({ at: offset, removedLen: match.length, insertedLen: inserted.length, inserted, family, head: a, tail: match.length - b, pass: passIndex });
|
|
196
|
-
return inserted;
|
|
197
|
-
});
|
|
198
|
-
batches.push(edits);
|
|
199
|
-
});
|
|
200
|
-
return { out: cur, batches };
|
|
201
|
-
}
|
|
202
|
-
function applyPasses(input, passes, report, toOriginal, disjoint = false) {
|
|
203
|
-
const found = report === undefined ? undefined : [];
|
|
204
|
-
const plain = runPasses(input, passes, found, toOriginal);
|
|
205
|
-
const solo = soloHits(input, passes);
|
|
206
|
-
const sequential = solo.length === 0 ? [] : sequentialRemovals(plain.batches);
|
|
207
|
-
const outer = unremovedHits(solo, sequential);
|
|
208
|
-
const mappable = !disjoint || replacedSpans(plain.batches) !== undefined;
|
|
209
|
-
const whole = outer.length === 0 && mappable ? undefined : renderRemovals(input, [...sequential, ...outer]);
|
|
210
|
-
if (whole === undefined || (whole.out === plain.out && mappable)) {
|
|
211
|
-
if (report !== undefined)
|
|
212
|
-
report.findings.push(...found.map((x) => x.f));
|
|
213
|
-
return plain;
|
|
214
|
-
}
|
|
215
|
-
if (report !== undefined) {
|
|
216
|
-
const seen = new Set(found.map((x) => `${x.pass}:${x.f.span[0]}:${x.f.span[1]}`));
|
|
217
|
-
for (const h of outer) {
|
|
218
|
-
const span = [toOriginal(h.matchStart), toOriginal(h.matchEnd)];
|
|
219
|
-
const key = `${h.pass}:${span[0]}:${span[1]}`;
|
|
220
|
-
if (seen.has(key))
|
|
221
|
-
continue;
|
|
222
|
-
seen.add(key);
|
|
223
|
-
found.push({ pass: h.pass, f: finding(passes[h.pass], span, h.family) });
|
|
224
|
-
}
|
|
225
|
-
found.sort((x, y) => x.pass - y.pass || x.f.span[0] - y.f.span[0]);
|
|
226
|
-
report.findings.push(...found.map((x) => x.f));
|
|
227
|
-
}
|
|
228
|
-
return { out: whole.out, batches: [whole.edits] };
|
|
229
|
-
}
|
|
230
|
-
function replacedSpans(batches) {
|
|
231
|
-
const spans = [];
|
|
232
|
-
for (let j = 0; j < batches.length; j++) {
|
|
233
|
-
const toPassZero = passZeroMapper(batches.slice(0, j));
|
|
234
|
-
for (const e of batches[j]) {
|
|
235
|
-
const s0 = toPassZero(e.at);
|
|
236
|
-
const e0 = toPassZero(e.at + e.removedLen);
|
|
237
|
-
if (e0 - s0 !== e.removedLen)
|
|
238
|
-
return undefined;
|
|
239
|
-
spans.push({ start: s0, end: e0, inserted: e.inserted, pass: e.pass, family: e.family });
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
spans.sort((a, b) => a.start - b.start);
|
|
243
|
-
for (let i = 1; i < spans.length; i++)
|
|
244
|
-
if (spans[i].start < spans[i - 1].end)
|
|
245
|
-
return undefined;
|
|
246
|
-
return spans;
|
|
247
|
-
}
|
|
248
|
-
export function runRedactionPasses(input, passes, report) {
|
|
249
|
-
if (report !== undefined && report.preexistingMarkers === undefined) {
|
|
250
|
-
report.preexistingMarkers = redactionMarkerSpans(input).length;
|
|
251
|
-
}
|
|
252
|
-
if (!FORMAT_CHAR_RE.test(input))
|
|
253
|
-
return applyPasses(input, passes, report, (pos) => pos).out;
|
|
254
|
-
const viewChars = [];
|
|
255
|
-
const viewToOriginal = [];
|
|
256
|
-
const formatAtSlot = [];
|
|
257
|
-
const charStartOffsets = [];
|
|
258
|
-
{
|
|
259
|
-
let orig = 0;
|
|
260
|
-
let viewOff = 0;
|
|
261
|
-
let slotBuf = "";
|
|
262
|
-
for (const ch of input) {
|
|
263
|
-
if (FORMAT_CHAR_RE.test(ch)) {
|
|
264
|
-
slotBuf += ch;
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
formatAtSlot.push(slotBuf);
|
|
268
|
-
slotBuf = "";
|
|
269
|
-
viewToOriginal.push(orig);
|
|
270
|
-
charStartOffsets.push(viewOff);
|
|
271
|
-
viewChars.push(ch);
|
|
272
|
-
viewOff += ch.length;
|
|
273
|
-
}
|
|
274
|
-
orig += ch.length;
|
|
275
|
-
}
|
|
276
|
-
formatAtSlot.push(slotBuf);
|
|
277
|
-
viewToOriginal.push(input.length);
|
|
278
|
-
charStartOffsets.push(viewOff);
|
|
279
|
-
}
|
|
280
|
-
const view = viewChars.join("");
|
|
281
|
-
const offsetToCharIndex = new Map();
|
|
282
|
-
charStartOffsets.forEach((off, idx) => offsetToCharIndex.set(off, idx));
|
|
283
|
-
const toOriginal = (pos) => {
|
|
284
|
-
const idx = offsetToCharIndex.get(pos);
|
|
285
|
-
return idx === undefined ? input.length : viewToOriginal[idx];
|
|
286
|
-
};
|
|
287
|
-
const { batches } = applyPasses(view, passes, report, toOriginal, true);
|
|
288
|
-
const viewSpans = replacedSpans(batches);
|
|
289
|
-
if (viewSpans === undefined)
|
|
290
|
-
return REDACTION_MARK;
|
|
291
|
-
const spans = viewSpans.map((sp) => {
|
|
292
|
-
const startIdx = offsetToCharIndex.get(sp.start) ?? viewChars.length;
|
|
293
|
-
const endIdx = offsetToCharIndex.get(sp.end) ?? viewChars.length;
|
|
294
|
-
const lastIdx = endIdx - 1;
|
|
295
|
-
const endOrig = lastIdx >= startIdx && lastIdx < viewChars.length ? viewToOriginal[lastIdx] + viewChars[lastIdx].length : viewToOriginal[startIdx];
|
|
296
|
-
return { start: viewToOriginal[startIdx], end: endOrig, inserted: sp.inserted };
|
|
297
|
-
});
|
|
298
|
-
const viewOffsetToOriginal = (viewStart, viewEnd) => {
|
|
299
|
-
const startIdx = offsetToCharIndex.get(viewStart) ?? viewChars.length;
|
|
300
|
-
const endIdx = offsetToCharIndex.get(viewEnd) ?? viewChars.length;
|
|
301
|
-
const lastIdx = endIdx - 1;
|
|
302
|
-
const endOrig = lastIdx >= startIdx && lastIdx < viewChars.length ? viewToOriginal[lastIdx] + viewChars[lastIdx].length : viewToOriginal[startIdx];
|
|
303
|
-
return { start: viewToOriginal[startIdx], end: endOrig };
|
|
304
|
-
};
|
|
305
|
-
const cutOffsets = [];
|
|
306
|
-
for (let k = 1; k < viewChars.length; k++)
|
|
307
|
-
if (formatAtSlot[k] !== "")
|
|
308
|
-
cutOffsets.push(charStartOffsets[k]);
|
|
309
|
-
if (cutOffsets.length > MAX_FORMAT_SLOT_SCANS)
|
|
310
|
-
return REDACTION_MARK;
|
|
311
|
-
const extra = [];
|
|
312
|
-
const rawSpans = replacedSpans(applyPasses(input, passes, undefined, (pos) => pos, true).batches);
|
|
313
|
-
if (rawSpans !== undefined)
|
|
314
|
-
extra.push(...rawSpans);
|
|
315
|
-
for (const cut of cutOffsets) {
|
|
316
|
-
const cutSpans = replacedSpans(applyPasses(view.slice(cut), passes, undefined, (pos) => pos, true).batches);
|
|
317
|
-
if (cutSpans === undefined)
|
|
318
|
-
continue;
|
|
319
|
-
for (const c of cutSpans) {
|
|
320
|
-
const o = viewOffsetToOriginal(c.start + cut, c.end + cut);
|
|
321
|
-
extra.push({ ...c, start: o.start, end: o.end });
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
extra.sort((a, b) => a.start - b.start);
|
|
325
|
-
const firstEndingAfter = (pos) => {
|
|
326
|
-
let lo = 0;
|
|
327
|
-
let hi = spans.length;
|
|
328
|
-
while (lo < hi) {
|
|
329
|
-
const mid = (lo + hi) >> 1;
|
|
330
|
-
if (spans[mid].end > pos)
|
|
331
|
-
hi = mid;
|
|
332
|
-
else
|
|
333
|
-
lo = mid + 1;
|
|
334
|
-
}
|
|
335
|
-
return lo;
|
|
336
|
-
};
|
|
337
|
-
for (const r of extra) {
|
|
338
|
-
const at = firstEndingAfter(r.start);
|
|
339
|
-
const hit = spans[at];
|
|
340
|
-
if (hit !== undefined && hit.start < r.end) {
|
|
341
|
-
if (r.start < hit.start)
|
|
342
|
-
hit.start = r.start;
|
|
343
|
-
if (r.end > hit.end)
|
|
344
|
-
hit.end = r.end;
|
|
345
|
-
let next = at + 1;
|
|
346
|
-
while (next < spans.length && spans[next].start < hit.end)
|
|
347
|
-
hit.end = Math.max(hit.end, spans[next++].end);
|
|
348
|
-
if (next > at + 1)
|
|
349
|
-
spans.splice(at + 1, next - at - 1);
|
|
350
|
-
continue;
|
|
351
|
-
}
|
|
352
|
-
spans.splice(at, 0, { start: r.start, end: r.end, inserted: r.inserted });
|
|
353
|
-
if (report !== undefined)
|
|
354
|
-
report.findings.push(finding(passes[r.pass], [r.start, r.end], r.family));
|
|
355
|
-
}
|
|
356
|
-
let result = "";
|
|
357
|
-
let cursor = 0;
|
|
358
|
-
for (const sp of spans) {
|
|
359
|
-
result += input.slice(cursor, sp.start) + sp.inserted;
|
|
360
|
-
cursor = sp.end;
|
|
361
|
-
}
|
|
362
|
-
result += input.slice(cursor);
|
|
363
|
-
return result;
|
|
364
|
-
}
|
|
365
|
-
const BRACKET_MARKER = { "url-credentials": REDACTION_MARKS.credentials };
|
|
366
|
-
const bracketMarker = (kind) => BRACKET_MARKER[kind] ?? REDACTION_MARK;
|
|
367
|
-
const capturesLabel = (re) => new RegExp(`${re.source}|`).exec("").length > 1;
|
|
368
|
-
export function egressPasses(groups, replacers = {}) {
|
|
369
|
-
return groups.map((rows) => {
|
|
370
|
-
const head = rows[0];
|
|
371
|
-
const marker = bracketMarker(head.kind);
|
|
372
|
-
const re = rows.length === 1 ? head.match : new RegExp(rows.map((r) => `(?:${r.match.source})`).join("|"), head.match.flags);
|
|
373
|
-
const sticky = rows.map((r) => ({ id: r.id, re: new RegExp(r.match.source, r.match.flags.replace("g", "") + "y") }));
|
|
374
|
-
const family = rows.length === 1 ? head.id : (input, at) => sticky.find((s) => ((s.re.lastIndex = at), s.re.test(input)))?.id ?? head.id;
|
|
375
|
-
return { kind: head.kind, confidence: head.confidence, marker, source: head.source, re, replace: replacers[head.kind] ?? (capturesLabel(head.match) ? `$1${marker}` : marker), family };
|
|
376
|
-
});
|
|
377
|
-
}
|