@sema-agent/core 7.62.0 → 7.63.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.
Files changed (193) hide show
  1. package/CHANGELOG.md +528 -0
  2. package/dist/agents/subagent-transcript-placement.d.ts +23 -0
  3. package/dist/agents/subagent-transcript-placement.js +14 -0
  4. package/dist/agents/subagent.js +82 -51
  5. package/dist/brain/route-adjudicator.js +9 -4
  6. package/dist/core/approval-object.js +1 -1
  7. package/dist/core/arg-summary.js +1 -1
  8. package/dist/core/ask-question.d.ts +2 -2
  9. package/dist/core/canonical-json.d.ts +23 -13
  10. package/dist/core/canonical-json.js +4 -4
  11. package/dist/core/checkpoint-queries.d.ts +47 -4
  12. package/dist/core/checkpoint-queries.js +36 -16
  13. package/dist/core/checkpoint-requirements.d.ts +3 -3
  14. package/dist/core/checkpoint-requirements.js +2 -1
  15. package/dist/core/checkpoint-row-verdict.d.ts +15 -4
  16. package/dist/core/checkpoint-row-verdict.js +22 -2
  17. package/dist/core/checkpoint-store.d.ts +23 -10
  18. package/dist/core/checkpoint-store.js +45 -4
  19. package/dist/core/compliance.d.ts +6 -2
  20. package/dist/core/compliance.js +3 -3
  21. package/dist/core/engine-attestation.d.ts +1 -1
  22. package/dist/core/engine-notice.d.ts +19 -4
  23. package/dist/core/git-worktree-env.d.ts +62 -3
  24. package/dist/core/git-worktree-env.js +91 -30
  25. package/dist/core/governance-codes.d.ts +7 -3
  26. package/dist/core/governance-codes.js +13 -3
  27. package/dist/core/memory-engine/consolidation-driver.d.ts +32 -17
  28. package/dist/core/memory-engine/consolidation-driver.js +99 -98
  29. package/dist/core/memory-engine/consolidation.d.ts +73 -10
  30. package/dist/core/memory-engine/consolidation.js +167 -11
  31. package/dist/core/memory-engine/data-plane.d.ts +8 -4
  32. package/dist/core/memory-engine/data-plane.js +11 -6
  33. package/dist/core/memory-engine/delegation-settlement.d.ts +37 -35
  34. package/dist/core/memory-engine/delegation-settlement.js +53 -59
  35. package/dist/core/memory-engine/dual-root.d.ts +12 -6
  36. package/dist/core/memory-engine/dual-root.js +9 -5
  37. package/dist/core/memory-engine/engine.d.ts +98 -35
  38. package/dist/core/memory-engine/engine.js +477 -380
  39. package/dist/core/memory-engine/entry-scan.d.ts +8 -0
  40. package/dist/core/memory-engine/entry-scan.js +3 -0
  41. package/dist/core/memory-engine/file-backend.d.ts +29 -3
  42. package/dist/core/memory-engine/file-backend.js +66 -35
  43. package/dist/core/memory-engine/index.d.ts +7 -7
  44. package/dist/core/memory-engine/index.js +6 -6
  45. package/dist/core/memory-engine/landing-admission.d.ts +5 -3
  46. package/dist/core/memory-engine/landing-admission.js +3 -3
  47. package/dist/core/memory-engine/layout.d.ts +121 -45
  48. package/dist/core/memory-engine/layout.js +252 -102
  49. package/dist/core/memory-engine/memory-backend-contract.d.ts +19 -1
  50. package/dist/core/memory-engine/memory-backend-contract.js +320 -0
  51. package/dist/core/memory-engine/memory-deployment.d.ts +31 -8
  52. package/dist/core/memory-engine/memory-deployment.js +26 -12
  53. package/dist/core/memory-engine/scope-contract.d.ts +52 -11
  54. package/dist/core/memory-engine/scope-contract.js +68 -19
  55. package/dist/core/memory-engine/session-write-home.d.ts +3 -1
  56. package/dist/core/memory-engine/session-write-home.js +1 -1
  57. package/dist/core/memory-engine/sync-client.d.ts +3 -1
  58. package/dist/core/memory-engine/sync-client.js +7 -0
  59. package/dist/core/memory-engine/sync-report.d.ts +3 -2
  60. package/dist/core/memory-engine/sync-report.js +6 -2
  61. package/dist/core/memory-engine/tools.d.ts +2 -2
  62. package/dist/core/memory-engine/tools.js +10 -10
  63. package/dist/core/memory-engine/types.d.ts +118 -19
  64. package/dist/core/memory-engine/types.js +1 -0
  65. package/dist/core/memory.js +15 -6
  66. package/dist/core/mods/stations.d.ts +20 -1
  67. package/dist/core/mods/stations.js +21 -2
  68. package/dist/core/park-selfcheck.js +2 -2
  69. package/dist/core/pause-registry.d.ts +2 -0
  70. package/dist/core/pause-registry.js +3 -0
  71. package/dist/core/permission-rule-consent.d.ts +10 -3
  72. package/dist/core/permission-rule-consent.js +37 -24
  73. package/dist/core/permission-rule-store.d.ts +35 -1
  74. package/dist/core/permission-rule-store.js +27 -8
  75. package/dist/core/read-only-shell.js +3 -2
  76. package/dist/core/redaction-marks.d.ts +8 -0
  77. package/dist/core/redaction-marks.js +6 -0
  78. package/dist/core/remote-env.d.ts +12 -1
  79. package/dist/core/remote-env.js +3 -0
  80. package/dist/core/runner/child-tree.d.ts +29 -3
  81. package/dist/core/runner/child-tree.js +39 -16
  82. package/dist/core/runner/contracts.d.ts +18 -9
  83. package/dist/core/runner/gate-exit.js +2 -2
  84. package/dist/core/runner/inherited-ask-grants.js +1 -1
  85. package/dist/core/runner/memory-consolidation-driver.d.ts +6 -3
  86. package/dist/core/runner/memory-consolidation-driver.js +4 -4
  87. package/dist/core/runner/memory-consolidation-write-judge.d.ts +2 -1
  88. package/dist/core/runner/memory-consolidation-write-judge.js +3 -2
  89. package/dist/core/runner/person-path-rows.d.ts +8 -3
  90. package/dist/core/runner/person-path-rows.js +5 -1
  91. package/dist/core/runner/placement-fence.d.ts +12 -0
  92. package/dist/core/runner/placement-fence.js +20 -6
  93. package/dist/core/runner/prepare-ask-lane.js +2 -2
  94. package/dist/core/runner/prepare-caps-and-workflow.d.ts +4 -1
  95. package/dist/core/runner/prepare-caps-and-workflow.js +5 -2
  96. package/dist/core/runner/prepare-execution-env.js +17 -6
  97. package/dist/core/runner/prepare-hands-readface.d.ts +2 -1
  98. package/dist/core/runner/prepare-hands-readface.js +4 -3
  99. package/dist/core/runner/prepare-inherited-gate.d.ts +10 -8
  100. package/dist/core/runner/prepare-inherited-gate.js +8 -4
  101. package/dist/core/runner/prepare-memory-engine-session.d.ts +2 -4
  102. package/dist/core/runner/prepare-memory-engine-session.js +4 -4
  103. package/dist/core/runner/prepare-memory.d.ts +3 -2
  104. package/dist/core/runner/prepare-memory.js +28 -20
  105. package/dist/core/runner/prepare-park-ask.js +4 -3
  106. package/dist/core/runner/prepare-task.js +15 -12
  107. package/dist/core/runner/prepare-workspace-restore.js +3 -6
  108. package/dist/core/runner/run-leg.js +1 -1
  109. package/dist/core/runner/run-settle-and-teardown.js +3 -2
  110. package/dist/core/runner/terminal-account.js +1 -1
  111. package/dist/core/runner-deps.d.ts +6 -2
  112. package/dist/core/secret-env.d.ts +1 -1
  113. package/dist/core/secret-env.js +4 -4
  114. package/dist/core/session-checkout.d.ts +108 -0
  115. package/dist/core/session-checkout.js +485 -0
  116. package/dist/core/session-store.d.ts +12 -4
  117. package/dist/core/session-store.js +23 -3
  118. package/dist/core/session.d.ts +16 -2
  119. package/dist/core/session.js +3 -0
  120. package/dist/core/store-contracts/checkpoint-store-contract.d.ts +0 -12
  121. package/dist/core/store-contracts/checkpoint-store-contract.js +6 -7
  122. package/dist/core/store-contracts/session-store-contract.js +39 -0
  123. package/dist/core/task-event.d.ts +21 -0
  124. package/dist/core/task-notification.d.ts +9 -1
  125. package/dist/core/task-notification.js +6 -0
  126. package/dist/core/task-registry-agent.d.ts +14 -2
  127. package/dist/core/task-registry-agent.js +45 -19
  128. package/dist/core/task-registry-shared.d.ts +26 -11
  129. package/dist/core/task-registry.d.ts +15 -9
  130. package/dist/core/task-registry.js +9 -10
  131. package/dist/core/task-spec-members.js +1 -1
  132. package/dist/core/task-spec.d.ts +20 -0
  133. package/dist/core/tool-policy.d.ts +14 -12
  134. package/dist/core/tool-policy.js +11 -10
  135. package/dist/core/tool-spec.d.ts +38 -19
  136. package/dist/core/types.d.ts +1 -1
  137. package/dist/core/untrusted-egress.d.ts +15 -4
  138. package/dist/core/untrusted-egress.js +23 -22
  139. package/dist/core/workspace-snapshot.d.ts +3 -1
  140. package/dist/core/workspace-snapshot.js +1 -0
  141. package/dist/engine/harness/types.d.ts +66 -1
  142. package/dist/engine/harness/types.js +108 -0
  143. package/dist/engine/session/import-validate.js +6 -1
  144. package/dist/engine/session/session.d.ts +24 -1
  145. package/dist/engine/session/session.js +45 -1
  146. package/dist/index.d.ts +7 -4
  147. package/dist/index.js +7 -4
  148. package/dist/internal/harness-types.d.ts +1 -1
  149. package/dist/orchestration/run-workflow-tool.d.ts +4 -1
  150. package/dist/orchestration/run-workflow-tool.js +1 -0
  151. package/dist/orchestration/workflow.d.ts +3 -0
  152. package/dist/orchestration/workflow.js +3 -1
  153. package/dist/stores/file/session-store.js +2 -1
  154. package/dist/tools/fs/bash-program-position.js +3 -3
  155. package/dist/tools/fs/program-read-model.d.ts +34 -10
  156. package/dist/tools/fs/program-read-model.js +37 -7
  157. package/dist/tools/fs/program-read-model.rows.js +13 -2
  158. package/dist/tools/fs/read-deny.d.ts +13 -1
  159. package/dist/tools/fs/read-deny.js +10 -2
  160. package/dist/tools/fs/removal-targets.js +3 -3
  161. package/dist/tools/fs/safety.d.ts +2 -0
  162. package/dist/tools/fs/safety.js +1 -1
  163. package/dist/tools/fs/shell-read-argv.d.ts +8 -1
  164. package/dist/tools/fs/shell-read-argv.js +34 -29
  165. package/dist/tools/fs/shell-read-bindings.d.ts +2 -0
  166. package/dist/tools/fs/shell-read-bindings.js +5 -1
  167. package/dist/tools/fs/shell-read-brace.d.ts +18 -0
  168. package/dist/tools/fs/shell-read-brace.js +79 -0
  169. package/dist/tools/fs/shell-read-check.js +10 -8
  170. package/dist/tools/fs/shell-read-establish.js +23 -16
  171. package/dist/tools/fs/shell-read-judge.d.ts +11 -0
  172. package/dist/tools/fs/shell-read-judge.js +3 -3
  173. package/dist/tools/fs/shell-read-plan.d.ts +10 -0
  174. package/dist/tools/fs/shell-read-plan.js +189 -93
  175. package/dist/tools/fs/shell-read-start.d.ts +19 -9
  176. package/dist/tools/fs/shell-read-start.js +20 -12
  177. package/dist/tools/fs/shell-read-word.d.ts +10 -0
  178. package/dist/tools/fs/shell-read-word.js +9 -5
  179. package/dist/tools/fs/shell-read-workdir.d.ts +26 -7
  180. package/dist/tools/fs/shell-read-workdir.js +73 -12
  181. package/dist/tools/fs/shell-read-write-targets.js +13 -8
  182. package/dist/tools/worktree.d.ts +3 -2
  183. package/dist/tools/worktree.js +7 -35
  184. package/package.json +3 -2
  185. package/test/export-surface.snapshot.json +73 -11
  186. package/wire-changes/core-stores-sql@7.63.0.json +30 -0
  187. package/wire-changes/core@7.63.0.json +3523 -0
  188. package/wire-changes/mods-kernel@7.63.0.json +30 -0
  189. package/wire-changes/primitives@7.63.0.json +445 -0
  190. package/dist/core/credential-vocabulary.d.ts +0 -176
  191. package/dist/core/credential-vocabulary.js +0 -190
  192. package/dist/core/redaction-passes.d.ts +0 -82
  193. package/dist/core/redaction-passes.js +0 -377
@@ -1,190 +0,0 @@
1
- export const URI_SCHEME_SOURCE = String.raw `(?<![A-Za-z0-9+.\-_])[0-9+.\-_]*[A-Za-z][A-Za-z0-9+.\-_]*`;
2
- export const URL_USERINFO_SOURCE = String.raw `(?:[^/\s"@]*@)+`;
3
- export const CREDENTIAL_MIN_CHARS = 8;
4
- const VENDOR_BODY = `[A-Za-z0-9_-]{${CREDENTIAL_MIN_CHARS},}`;
5
- const VALUE_END = String.raw `\s"';|&`;
6
- const VALUE_CHAR = `[^${VALUE_END}]`;
7
- const ESCAPE_DEPTH = 63;
8
- const QUOTED_VALUE_MAX = 1024;
9
- const PLAIN_QUOTES = [`"`, `'`, `&quot;`, `&apos;`, `&#34;`, `&#39;`, `%22`, `%27`];
10
- const ESCAPED_QUOTES = [`"`, `'`, `x22`, `x27`, `u0022`, `u0027`, `042`, `047`];
11
- const BACKSLASHES = String.raw `\\{1,${ESCAPE_DEPTH}}`;
12
- const QUOTE = `(?:${PLAIN_QUOTES.join("|")}|${BACKSLASHES}(?:${ESCAPED_QUOTES.join("|")}))`;
13
- const WORD_START = `(?:(?<![A-Za-z0-9])|(?<=${QUOTE}))`;
14
- const AFTER_CLOSING_QUOTE = String.raw `(?:[\s,}\]:]|["']|$)`;
15
- const VALUE_RUN_END = `(?:(?<!\\\\)|(?!\\\\{0,${ESCAPE_DEPTH}}["']))`;
16
- const GLUED_RUN = `${VALUE_CHAR}*${VALUE_RUN_END}`;
17
- const pairedValue = (open, close) => `${open}(?!${AFTER_CLOSING_QUOTE})[^\\n]{0,${QUOTED_VALUE_MAX}}?${close}`;
18
- const QUOTED_VALUE = [
19
- ...PLAIN_QUOTES.map((q) => pairedValue(q, q)),
20
- ...ESCAPED_QUOTES.map((q, i) => pairedValue(`(${BACKSLASHES})${q}`, `(?<!\\\\)(?:\\${i + 2})${q}`)),
21
- `${QUOTE}(?!${AFTER_CLOSING_QUOTE})${GLUED_RUN}`,
22
- ].join("|");
23
- const BEARER_TAIL = `(?:(?!${QUOTE})\\S${GLUED_RUN}|(?<==)(?:${QUOTED_VALUE}))`;
24
- const HEADER_PARAM = String.raw `=[ \t]*(\\{0,${ESCAPE_DEPTH}})(["'])(?:(?!(?<!\\)\2\3)[^\r\n])*(?:(?<!\\)\2\3(?=[\s,;]|\\{0,${ESCAPE_DEPTH}}["']|$)|(?=[\r\n]|$))`;
25
- const HEADER_VALUE = String.raw `(?:[A-Za-z][A-Za-z0-9!#$%&*+.^_|~-]*[ \t]+)?(?:${HEADER_PARAM}|[^\s"',]|[ \t]*,[ \t]*(?=[^\s"',])|[ \t]+(?==)|(?<==)[ \t]+(?=[^\s"',]))+${VALUE_RUN_END}`;
26
- const headed = (body, flags = "g") => new RegExp(`${WORD_START}${body}`, flags);
27
- const HUMP_BEFORE = "[a-z0-9]";
28
- const KEYWORD_VALUE_WORDS = ["token", "secret", "key", "password", "passwd", "credential"];
29
- const anyCase = (word) => [...word].map((c) => `[${c.toUpperCase()}${c.toLowerCase()}]`).join("");
30
- const VALUE_ROW_FIELDS = [["Account", "Key"]];
31
- const leftToItsRow = (keyword) => VALUE_ROW_FIELDS.filter(([, k]) => k.toLowerCase() === keyword).map(([front]) => `(?<!(?<![A-Za-z0-9])${front})`).join("");
32
- const KEYWORD_HEAD = `(?:${WORD_START}(?:${KEYWORD_VALUE_WORDS.map(anyCase).join("|")})|(?<=${HUMP_BEFORE})(?:${KEYWORD_VALUE_WORDS.map((w) => leftToItsRow(w) + w[0].toUpperCase() + anyCase(w.slice(1))).join("|")})|(?<=[A-Z])(?:${KEYWORD_VALUE_WORDS.map((w) => w[0].toUpperCase() + w[1] + anyCase(w.slice(2))).join("|")}))`;
33
- const KEY_QUOTE = `(?:\\\\{0,${ESCAPE_DEPTH}}["'])?`;
34
- export const CREDENTIAL_VOCABULARY = {
35
- values: [
36
- { id: "github-token", kind: "prefixed-token", source: "arg-summary", confidence: "high", pass: "vendor-prefixed", match: headed(`gh[opsur][-_]${VENDOR_BODY}`), strict: /\b(?:ghp|gho|ghu|ghs|ghr)_[A-Za-z0-9]{36,}\b/ },
37
- { id: "github-fine-grained-pat", kind: "prefixed-token", source: "arg-summary", confidence: "high", pass: "vendor-prefixed", match: headed(`github_pat[-_]${VENDOR_BODY}`), strict: /\bgithub_pat_[A-Za-z0-9_]{60,}\b/ },
38
- { id: "openai-api-key", kind: "prefixed-token", source: "arg-summary", confidence: "high", pass: "vendor-prefixed", match: headed(`sk-${VENDOR_BODY}`), strict: /\bsk-(?:ant-(?:api03-)?|proj-)?[A-Za-z0-9_]{20,}\b/ },
39
- { id: "stripe-secret-key", kind: "prefixed-token", source: "arg-summary", confidence: "high", pass: "vendor-prefixed", match: headed(`(?:sk_|rk[-_])${VENDOR_BODY}`), strict: /\b[sr]k_(?:live|test)_[A-Za-z0-9]{24,}\b/ },
40
- { id: "stripe-publishable-key", kind: "prefixed-token", source: "arg-summary", confidence: "high", pass: "vendor-prefixed", match: headed(`pk[-_]${VENDOR_BODY}`) },
41
- { id: "gitlab-pat", kind: "prefixed-token", source: "arg-summary", confidence: "high", pass: "vendor-prefixed", match: headed("glpat-[A-Za-z0-9_-]{20,}") },
42
- { id: "npm-access-token", kind: "prefixed-token", source: "arg-summary", confidence: "high", pass: "vendor-prefixed", match: headed("npm_[A-Za-z0-9]{36,}") },
43
- { id: "google-oauth-access-token", kind: "prefixed-token", source: "arg-summary", confidence: "high", pass: "vendor-prefixed", match: headed(String.raw `ya29\.[A-Za-z0-9_.-]{20,}`) },
44
- { id: "google-api-key", kind: "prefixed-token", source: "arg-summary", confidence: "high", match: headed("AIza[A-Za-z0-9_-]{20,}"), strict: /\bAIza[0-9A-Za-z_-]{35}\b/ },
45
- { id: "slack-token", kind: "prefixed-token", source: "arg-summary", confidence: "high", match: headed("xox[baprs]-[A-Za-z0-9-]{10,}"), strict: /\bxox[baprs]-(?:[A-Za-z0-9]+-){1,3}[A-Za-z0-9]{16,}\b/ },
46
- { id: "aws-access-key-id", kind: "prefixed-token", source: "arg-summary", confidence: "high", match: headed("(?:A3T[A-Z0-9]|AKIA|ASIA|ABIA|ACCA)[0-9A-Z]{12,}"), strict: /\bAKIA[0-9A-Z]{16}\b/ },
47
- { id: "huggingface-token", kind: "prefixed-token", source: "arg-summary", confidence: "high", match: headed("hf_[A-Za-z0-9]{20,}"), strict: /\bhf_(?=[A-Za-z0-9]*[0-9])[A-Za-z0-9]{20,}\b/ },
48
- { id: "jwt", kind: "jwt", source: "arg-summary", confidence: "high", match: headed("eyJ[A-Za-z0-9._-]{20,}"), strict: /\beyJ[A-Za-z0-9_-]+\.eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]{16,}\b/ },
49
- { id: "private-key", kind: "private-key-block", source: "arg-summary", confidence: "high", match: /-----BEGIN[ A-Z0-9]*PRIVATE KEY(?: BLOCK)?-----[\s\S]*?(?:-----END[ A-Z0-9]*PRIVATE KEY(?: BLOCK)?-----|$)/g, strict: /-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?-----/ },
50
- { id: "bearer-token", kind: "bearer-token", source: "arg-summary", confidence: "high", match: headed(String.raw `()[Bb][Ee][Aa][Rr][Ee][Rr]\s+[A-Za-z0-9._~+/-]{${CREDENTIAL_MIN_CHARS},}=*(?:${BEARER_TAIL})?`), strict: /\bAuthorization:\s*Bearer\s+(?=[A-Za-z0-9._~+/-]*[0-9])[A-Za-z0-9._~+/-]{20,}=*/ },
51
- { id: "authorization-header", kind: "authorization-header", source: "arg-summary", confidence: "high", match: headed(String.raw `(authorization(?:\\{0,${ESCAPE_DEPTH}}["'])?[ \t]*[=:][ \t]*(?:\\{0,${ESCAPE_DEPTH}}["'])?)${HEADER_VALUE}`, "gi") },
52
- { id: "azure-storage-account-key", kind: "prefixed-token", source: "arg-summary", confidence: "high", match: /(AccountKey=)[A-Za-z0-9+/]{40,}={0,2}/g, strict: /AccountKey=[A-Za-z0-9+/]{40,}={0,2}/ },
53
- { id: "keyword-value", kind: "keyword-value", source: "arg-summary", confidence: "medium", match: new RegExp(String.raw `(${KEYWORD_HEAD}${KEY_QUOTE}\s*[=:]\s*${KEY_QUOTE})${VALUE_CHAR}{4,}${VALUE_RUN_END}`, "g") },
54
- { id: "url-userinfo", kind: "url-credentials", source: "untrusted-egress", confidence: "medium", match: new RegExp(String.raw `(${URI_SCHEME_SOURCE}:\/\/)(${URL_USERINFO_SOURCE})`, "gi") },
55
- { id: "signed-url-param", kind: "signed-url-param", source: "untrusted-egress", confidence: "high", match: /([?&#](?:sig|signature|sas|code)=)[^&\s"'#]+/gi },
56
- ],
57
- words: [
58
- ...["TOKEN", "SECRET", "PASSWORD", "PASSWD", "PASSPHRASE", "KEY"].map((word) => ({ word, position: "leading" })),
59
- { word: "AUTH", position: "leading", recordKeys: ["AUTHORIZATION", "AUTHENTICATION", "OAUTH", "AUTHN", "AUTHZ"] },
60
- ...["COOKIE", "PAT", "DSN", "WEBHOOK", "CREDENTIAL", "CREDENTIALS", "CREDS", "APIKEY", "ACCESSKEY", "SECRETKEY", "ACCOUNTKEY", "PRIVATEKEY", "AUTHKEY", "SSHKEY", "SIGNINGKEY", "MASTERKEY", "DEPLOYKEY", "ENCRYPTIONKEY", "PGPASSWORD", "SSHPASS"].map((word) => ({ word, position: "leading" })),
61
- ...["KEY", "SECRET", "PASSWORD", "CREDENTIAL"].map((word) => ({ word, position: "plural" })),
62
- { word: "TOKEN", position: "counted-plural" },
63
- ...["PWD", "PASS", "JWT"].map((word) => ({ word, position: "separated" })),
64
- ...["TOKEN", "SECRET", "PASSWORD", "PASSWD", "PASSPHRASE"].map((word) => ({ word, position: "embedded" })),
65
- ],
66
- countWords: ["MAX", "OUTPUT", "INPUT", "THINKING", "NUM", "TOTAL"],
67
- connectionStringName: /CONN(ECT(ION)?)?_?STR(ING)?S?(?=$|[_0-9])/i,
68
- exactEnvNames: [
69
- "ANTHROPIC_API_KEY", "CLAUDE_CODE_OAUTH_TOKEN", "CLAUDE_CODE_ARTIFACTS_API_TOKEN", "CLAUDE_CODE_MEMORY_API_TOKEN",
70
- "CLAUDE_CODE_SLACK_TAG_TOKEN", "ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_FOUNDRY_API_KEY", "ANTHROPIC_FOUNDRY_AUTH_TOKEN",
71
- "ANTHROPIC_AWS_API_KEY", "ANTHROPIC_CUSTOM_HEADERS", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN",
72
- "AWS_BEARER_TOKEN_BEDROCK", "GOOGLE_APPLICATION_CREDENTIALS", "GOOGLE_GHA_CREDS_PATH", "AZURE_CLIENT_SECRET",
73
- "IDENTITY_HEADER", "MSI_SECRET", "AZURE_CLIENT_CERTIFICATE_PATH", "AZURE_CLIENT_CERTIFICATE_PASSWORD",
74
- "AZURE_PASSWORD", "AZURE_FEDERATED_TOKEN_FILE", "AWS_WEB_IDENTITY_TOKEN_FILE",
75
- "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI", "AWS_CONTAINER_CREDENTIALS_FULL_URI",
76
- "AWS_CONTAINER_AUTHORIZATION_TOKEN", "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE", "CLOUDSDK_AUTH_ACCESS_TOKEN",
77
- "GOOGLE_OAUTH_ACCESS_TOKEN", "CLAUDE_CODE_OAUTH_REFRESH_TOKEN", "HF_TOKEN", "HUGGING_FACE_HUB_TOKEN",
78
- "HUGGINGFACEHUB_API_TOKEN", "NODE_AUTH_TOKEN", "NUGET_AUTH_TOKEN", "CARGO_REGISTRY_TOKEN", "TWINE_PASSWORD",
79
- "TWINE_USERNAME", "PYPI_TOKEN", "PYPI_API_TOKEN", "UV_PUBLISH_TOKEN", "UV_PUBLISH_PASSWORD", "UV_PUBLISH_USERNAME",
80
- "FLIT_PASSWORD", "FLIT_USERNAME", "HATCH_INDEX_AUTH", "HATCH_INDEX_USER", "GEM_HOST_API_KEY", "MATURIN_PYPI_TOKEN",
81
- "MATURIN_PASSWORD", "MATURIN_USERNAME", "CONAN_LOGIN_USERNAME", "CONAN_PASSWORD", "ANACONDA_API_TOKEN",
82
- "BINSTAR_API_TOKEN", "VAULT_TOKEN", "VAULT_AUTH_TOKEN", "VAULT_ROLE_ID", "VAULT_SECRET_ID", "CONSUL_HTTP_TOKEN",
83
- "CONSUL_HTTP_AUTH", "NOMAD_TOKEN", "NOMAD_HTTP_AUTH", "CI_REGISTRY_USER", "CI_DEPLOY_USER", "JF_USER",
84
- "FASTLANE_SESSION", "MATCH_GIT_BASIC_AUTHORIZATION", "SONAR_TOKEN", "SONARQUBE_SCANNER_PARAMS",
85
- "SONAR_SCANNER_JSON_PARAMS", "SLACK_WEBHOOK_URL", "SLACK_WEBHOOK", "DISCORD_WEBHOOK", "DISCORD_WEBHOOK_URL",
86
- "TEAMS_WEBHOOK_URL", "MS_TEAMS_WEBHOOK_URI", "ANTHROPIC_IDENTITY_TOKEN", "ANTHROPIC_IDENTITY_TOKEN_FILE",
87
- "CLOUDSDK_AUTH_ACCESS_TOKEN_FILE", "CLOUDSDK_AUTH_AUTHORIZATION_TOKEN_FILE", "AZURE_AUTH_LOCATION",
88
- "ACTIONS_ID_TOKEN_REQUEST_TOKEN", "ACTIONS_ID_TOKEN_REQUEST_URL", "ACTIONS_RUNTIME_TOKEN", "ACTIONS_RUNTIME_URL",
89
- "ALL_INPUTS", "VSS_NUGET_EXTERNAL_FEED_ENDPOINTS", "ARTIFACTS_CREDENTIALPROVIDER_EXTERNAL_FEED_ENDPOINTS",
90
- "VSS_NUGET_ACCESSTOKEN", "ARTIFACTS_CREDENTIALPROVIDER_ACCESSTOKEN", "COMPOSER_AUTH", "OVERRIDE_GITHUB_TOKEN",
91
- "DEFAULT_WORKFLOW_TOKEN", "SSH_SIGNING_KEY",
92
- ],
93
- nonSecretExactNames: [
94
- "PARTITION_KEY", "SORT_KEY", "RANGE_KEY", "IDEMPOTENCY_KEY", "CACHE_KEY",
95
- "DB_FOREIGN_KEYS", "JSON_SORT_KEYS",
96
- "MAX_NEW_TOKENS", "MAX_COMPLETION_TOKENS", "AIDER_MAP_TOKENS", "AIDER_MAX_CHAT_HISTORY_TOKENS",
97
- "MAX_BATCH_PREFILL_TOKENS", "MAX_WAITING_TOKENS", "MAX_TOP_N_TOKENS", "RATE_LIMIT_TOKENS",
98
- "PROMPT_TOKENS", "CONTEXT_TOKENS",
99
- ],
100
- nonSecretNameShape: /^GIT_CONFIG_KEY_[0-9][A-Za-z0-9_]*$/,
101
- nonCredentialPrefix: /^AUTH0_/i,
102
- tokenPrefix: /^(?:gh[opusr]_|github_pat_|glpat-|xox[abpr]-|sk-|pk-|AKIA|eyJ|ya29\.|npm_)/,
103
- policy: { urlUserinfo: "keep-username" },
104
- };
105
- export const refuseLabel = (id) => id.replaceAll("-", "_");
106
- export function refuseWriteView(vocabulary) {
107
- return vocabulary.values.flatMap((row) => (row.strict === undefined ? [] : [{ label: refuseLabel(row.id), re: row.strict }]));
108
- }
109
- export function egressPassGroups(vocabulary) {
110
- const groups = [];
111
- for (const row of vocabulary.values) {
112
- const last = groups[groups.length - 1];
113
- if (row.pass !== undefined && last !== undefined && last[0].pass === row.pass)
114
- last.push(row);
115
- else
116
- groups.push([row]);
117
- }
118
- return groups;
119
- }
120
- function credentialWordPattern(countWords, rows) {
121
- const at = (position) => rows.filter((r) => r.position === position).map((r) => r.word);
122
- const countedPlural = `(?<!(?:^|_)(?:${countWords.join("|")})_)(?:${at("counted-plural").join("|")})S`;
123
- const [separated, embedded] = [at("separated"), at("embedded")];
124
- const positions = [
125
- `(^|_)(${at("leading").join("|")}|(${at("plural").join("|")})S|${countedPlural})`,
126
- ...(separated.length > 0 ? [`_(${separated.join("|")})`] : []),
127
- ...(embedded.length > 0 ? [`(${embedded.join("|")})`] : []),
128
- ];
129
- const segmentWord = `(?:${[...at("leading"), ...at("plural").map((w) => `${w}S`), ...separated, countedPlural].join("|")})`;
130
- return { credentialWord: new RegExp(`(${positions.join("|")})(?=$|[_0-9])`, "i"), segmentWord };
131
- }
132
- export function envNameView(vocabulary) {
133
- const { credentialWord, segmentWord } = credentialWordPattern(vocabulary.countWords, vocabulary.words);
134
- return {
135
- exactNames: new Set(vocabulary.exactEnvNames.flatMap((name) => [name, `INPUT_${name}`])),
136
- nonSecretExactNames: new Set(vocabulary.nonSecretExactNames),
137
- nonSecretNameShape: vocabulary.nonSecretNameShape,
138
- nonCredentialPrefix: vocabulary.nonCredentialPrefix,
139
- credentialWord,
140
- connectionStringName: vocabulary.connectionStringName,
141
- segmentWord,
142
- tokenPrefix: vocabulary.tokenPrefix,
143
- };
144
- }
145
- export function splitCamelCase(name) {
146
- return ["OAuth", "NextAuth"]
147
- .reduce((text, word) => text.replaceAll(word, word[0] + word.slice(1).toLowerCase()), name)
148
- .replace(new RegExp(`(${HUMP_BEFORE})([A-Z])`, "g"), "$1_$2")
149
- .replace(/([A-Z])([A-Z][a-z])/g, "$1_$2");
150
- }
151
- export function recordKeyView(vocabulary) {
152
- const rows = vocabulary.words.flatMap((w) => [w.word, ...(w.recordKeys ?? [])].map((word) => ({ word, position: w.position === "separated" ? "leading" : w.position })));
153
- return {
154
- credentialWord: credentialWordPattern(vocabulary.countWords, rows).credentialWord,
155
- nonSecretExactNames: new Set(vocabulary.nonSecretExactNames),
156
- nonSecretNameShape: vocabulary.nonSecretNameShape,
157
- nonCredentialPrefix: vocabulary.nonCredentialPrefix,
158
- };
159
- }
160
- const RECORD_KEYS = recordKeyView(CREDENTIAL_VOCABULARY);
161
- function holdsCredentialWord(text, view) {
162
- const words = text.replace(view.nonCredentialPrefix, "").replace(/-/g, "_");
163
- return view.credentialWord.test(words) || view.credentialWord.test(splitCamelCase(words));
164
- }
165
- function isNonSecretRecordName(key, source, view) {
166
- const spelled = key.replace(/-/g, "_");
167
- const folded = spelled.toUpperCase();
168
- if (view.nonSecretExactNames.has(folded))
169
- return true;
170
- if (source !== "header")
171
- return false;
172
- if (folded.length !== spelled.length)
173
- return false;
174
- for (const name of view.nonSecretExactNames) {
175
- if (folded.endsWith(`_${name}`) && !holdsCredentialWord(spelled.slice(0, spelled.length - name.length - 1), view))
176
- return true;
177
- }
178
- return false;
179
- }
180
- function readsAsCredential(key, source, view) {
181
- if (view.nonSecretNameShape.test(key))
182
- return false;
183
- return holdsCredentialWord(key, view) && !isNonSecretRecordName(key, source, view);
184
- }
185
- export function isSensitiveRecordKey(key, view = RECORD_KEYS) {
186
- return readsAsCredential(key, "member", view);
187
- }
188
- export function isSensitiveHeaderName(name, view = RECORD_KEYS) {
189
- return readsAsCredential(name, "header", view);
190
- }
@@ -1,82 +0,0 @@
1
- /**
2
- * The redaction pass engine every egress tier runs on, and the core bracket RENDERER of the vocabulary's answer.
3
- * Which text is a credential is the vocabulary's answer (credential-vocabulary.ts); which passes a text meets is
4
- * its tier's (untrusted-egress.ts).
5
- */
6
- import type { RedactionConfidence, RedactionSource, ValueFamilyRow } from "./credential-vocabulary.js";
7
- export type { RedactionConfidence, RedactionSource } from "./credential-vocabulary.js";
8
- /** One redaction hit: what was detected, where (ORIGINAL-input coordinates), how confidently, the marker
9
- * literal written in its place, which rule table minted it, and — present when a vocabulary row minted it — the
10
- * value family (the row's stable id; a host-leak hit such as a URL or a path names none). */
11
- export interface RedactionFinding {
12
- kind: string;
13
- span: readonly [number, number];
14
- confidence: RedactionConfidence;
15
- marker: string;
16
- source: RedactionSource;
17
- family?: string;
18
- }
19
- /** The minimum a finding must declare to be summarizable. Both text findings ({@link RedactionFinding})
20
- * and the env arm's entry findings satisfy it, so {@link summarizeRedactions} is ONE helper rather than
21
- * one per material kind. */
22
- export interface SummarizableFinding {
23
- kind: string;
24
- confidence: RedactionConfidence;
25
- }
26
- /** ANG-3 (envelope declaration) — render findings as ONE human-readable line, e.g.
27
- * `"3 redactions: prefixed-token (high) x1, url (medium) x1, fs-path (low) x1"`, so an upper layer can
28
- * declare to its consumer how much was removed and how confidently.
29
- *
30
- * PURE, and deliberately only that: it reads the array, returns a string, and injects nothing anywhere.
31
- * Attaching this line to an output is the caller's decision — a redaction pipeline that silently
32
- * appended prose to the very text it was asked to bound would break both the size contract
33
- * (`boundedString`) and the byte-invariance the whole channel is built on.
34
- *
35
- * Grouping is by kind AND confidence together: collapsing on kind alone would report whichever
36
- * confidence happened to arrive first for the rest of that group, which is exactly the silent
37
- * mis-statement ANG-4 exists to prevent. */
38
- export declare function summarizeRedactions(findings: readonly SummarizableFinding[]): string;
39
- /** The optional collector every redaction entry point accepts. `preexistingMarkers` (ANG-11) counts
40
- * marker-shaped literals ALREADY present in the input before any pass ran — a nonzero value means the
41
- * text arrived pre-redacted or carries caller-declared markers, either way "marker present" is not proof this
42
- * pipeline ran. Caller-owned: pass `{ findings: [] }` and read it back after the call. */
43
- export interface RedactionReport {
44
- findings: RedactionFinding[];
45
- preexistingMarkers?: number;
46
- }
47
- /** A declared redaction pass — the unit {@link runRedactionPasses} executes and reports on. */
48
- export interface RedactionPass {
49
- kind: string;
50
- confidence: RedactionConfidence;
51
- marker: string;
52
- /** The rule table that owns this pass's rule — copied verbatim onto every finding it mints (ANG-11), whoever
53
- * runs the pass. */
54
- source: RedactionSource;
55
- re: RegExp;
56
- /** A literal replacement (only `$1` substitution is used by these passes) or a replacer fn. */
57
- replace: string | ((match: string, ...groups: string[]) => string);
58
- /** The value family a hit belongs to: one id, or — for a pass joining several rows — the id of the row that
59
- * matches at the hit's offset in the pass input. Absent = the pass is no vocabulary row. */
60
- family?: string | ((input: string, at: number) => string);
61
- }
62
- /**
63
- * Run the declared passes in order, collecting findings (original-input spans) when a report is given.
64
- *
65
- * FORMAT CHARACTERS (#532): the passes scan a VIEW of the input with every `\p{Cf}` removed, so a
66
- * credential split by a zero-width character is one token to the scanner, not two fragments of which
67
- * only the first (or neither) matches. The OUTPUT keeps every format character that sits OUTSIDE a
68
- * replaced span — a joiner in an emoji sequence, a non-joiner in Persian text, a soft hyphen in a word
69
- * — and drops only those INSIDE the span the marker replaces (they were part of the secret). A
70
- * format-free input takes the exact historical path (byte-identical output). The view's replacements and
71
- * every boundary scan's are taken as disjoint spans of their input (a later pass that matched across an
72
- * earlier pass's inserted text is rendered from the removals instead), so the spans always map back
73
- * exactly and no scan is skipped.
74
- */
75
- export declare function runRedactionPasses(input: string, passes: readonly RedactionPass[], report?: RedactionReport): string;
76
- /**
77
- * The egress view rendered as passes, in the vocabulary's order: one pass per group (a group of several rows is ONE
78
- * leftmost alternation, its hits attributed to the row that matches at the hit's offset). A row whose wide form
79
- * captures a label keeps it ahead of the marker; `replacers` renders a kind whose marker placement is a policy (the
80
- * URL userinfo).
81
- */
82
- export declare function egressPasses(groups: ReadonlyArray<readonly ValueFamilyRow[]>, replacers?: Readonly<Record<string, (match: string, ...groups: string[]) => string>>): RedactionPass[];
@@ -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
- }