@senpi-ai/runtime 1.1.1 → 1.1.3

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 (117) hide show
  1. package/dist/actions/close-position/close-position.action.d.ts.map +1 -1
  2. package/dist/actions/close-position/close-position.action.js +4 -1
  3. package/dist/actions/close-position/close-position.action.js.map +1 -1
  4. package/dist/actions/llm-decision/anthropic-llm-decision.d.ts +9 -0
  5. package/dist/actions/llm-decision/anthropic-llm-decision.d.ts.map +1 -1
  6. package/dist/actions/llm-decision/anthropic-llm-decision.js +90 -3
  7. package/dist/actions/llm-decision/anthropic-llm-decision.js.map +1 -1
  8. package/dist/actions/llm-decision/factory.d.ts +6 -0
  9. package/dist/actions/llm-decision/factory.d.ts.map +1 -1
  10. package/dist/actions/llm-decision/factory.js +2 -0
  11. package/dist/actions/llm-decision/factory.js.map +1 -1
  12. package/dist/actions/llm-decision/openclaw-llm-decision.d.ts +30 -0
  13. package/dist/actions/llm-decision/openclaw-llm-decision.d.ts.map +1 -1
  14. package/dist/actions/llm-decision/openclaw-llm-decision.js +114 -15
  15. package/dist/actions/llm-decision/openclaw-llm-decision.js.map +1 -1
  16. package/dist/actions/open-position/open-position.action.d.ts.map +1 -1
  17. package/dist/actions/open-position/open-position.action.js +35 -8
  18. package/dist/actions/open-position/open-position.action.js.map +1 -1
  19. package/dist/cli/guide-commands.d.ts.map +1 -1
  20. package/dist/cli/guide-commands.js +8 -4
  21. package/dist/cli/guide-commands.js.map +1 -1
  22. package/dist/cli/senpi-cli-config.js +2 -3
  23. package/dist/cli/senpi-cli-config.js.map +1 -1
  24. package/dist/dsl/engine-client/config-mapping.d.ts +5 -0
  25. package/dist/dsl/engine-client/config-mapping.d.ts.map +1 -1
  26. package/dist/dsl/engine-client/config-mapping.js +14 -2
  27. package/dist/dsl/engine-client/config-mapping.js.map +1 -1
  28. package/dist/dsl/monitor/process-one-position.d.ts.map +1 -1
  29. package/dist/dsl/monitor/process-one-position.js +24 -1
  30. package/dist/dsl/monitor/process-one-position.js.map +1 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +18 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/runtime/decision-errors.d.ts +166 -0
  35. package/dist/runtime/decision-errors.d.ts.map +1 -0
  36. package/dist/runtime/decision-errors.js +328 -0
  37. package/dist/runtime/decision-errors.js.map +1 -0
  38. package/dist/runtime/notifications.d.ts +15 -1
  39. package/dist/runtime/notifications.d.ts.map +1 -1
  40. package/dist/runtime/notifications.js +16 -57
  41. package/dist/runtime/notifications.js.map +1 -1
  42. package/dist/runtime/risk-guard.d.ts +10 -0
  43. package/dist/runtime/risk-guard.d.ts.map +1 -1
  44. package/dist/runtime/risk-guard.js +6 -12
  45. package/dist/runtime/risk-guard.js.map +1 -1
  46. package/dist/runtime/run.d.ts +6 -0
  47. package/dist/runtime/run.d.ts.map +1 -1
  48. package/dist/runtime/run.js +1 -0
  49. package/dist/runtime/run.js.map +1 -1
  50. package/dist/runtime/runtime-schema.d.ts +1091 -73
  51. package/dist/runtime/runtime-schema.d.ts.map +1 -1
  52. package/dist/runtime/runtime-schema.js +34 -0
  53. package/dist/runtime/runtime-schema.js.map +1 -1
  54. package/dist/runtime/runtime.d.ts +8 -0
  55. package/dist/runtime/runtime.d.ts.map +1 -1
  56. package/dist/runtime/runtime.js +70 -37
  57. package/dist/runtime/runtime.js.map +1 -1
  58. package/dist/runtime/strategy-lifecycle.d.ts +45 -0
  59. package/dist/runtime/strategy-lifecycle.d.ts.map +1 -0
  60. package/dist/runtime/strategy-lifecycle.js +117 -0
  61. package/dist/runtime/strategy-lifecycle.js.map +1 -0
  62. package/dist/senpi/client.d.ts +1 -0
  63. package/dist/senpi/client.d.ts.map +1 -1
  64. package/dist/senpi/client.js +51 -0
  65. package/dist/senpi/client.js.map +1 -1
  66. package/dist/senpi/types.d.ts +2 -1
  67. package/dist/senpi/types.d.ts.map +1 -1
  68. package/dist/tracking/context.d.ts +31 -0
  69. package/dist/tracking/context.d.ts.map +1 -0
  70. package/dist/tracking/context.js +20 -0
  71. package/dist/tracking/context.js.map +1 -0
  72. package/dist/tracking/spans/constants.d.ts +19 -0
  73. package/dist/tracking/spans/constants.d.ts.map +1 -0
  74. package/dist/tracking/spans/constants.js +31 -0
  75. package/dist/tracking/spans/constants.js.map +1 -0
  76. package/dist/tracking/spans/index.d.ts +13 -0
  77. package/dist/tracking/spans/index.d.ts.map +1 -0
  78. package/dist/tracking/spans/index.js +16 -0
  79. package/dist/tracking/spans/index.js.map +1 -0
  80. package/dist/tracking/spans/plugin-span-tracker.d.ts +3 -0
  81. package/dist/tracking/spans/plugin-span-tracker.d.ts.map +1 -0
  82. package/dist/tracking/spans/plugin-span-tracker.js +42 -0
  83. package/dist/tracking/spans/plugin-span-tracker.js.map +1 -0
  84. package/dist/tracking/spans/redact-pii.d.ts +115 -0
  85. package/dist/tracking/spans/redact-pii.d.ts.map +1 -0
  86. package/dist/tracking/spans/redact-pii.js +464 -0
  87. package/dist/tracking/spans/redact-pii.js.map +1 -0
  88. package/dist/tracking/spans/sanitize-payload.d.ts +19 -0
  89. package/dist/tracking/spans/sanitize-payload.d.ts.map +1 -0
  90. package/dist/tracking/spans/sanitize-payload.js +68 -0
  91. package/dist/tracking/spans/sanitize-payload.js.map +1 -0
  92. package/dist/tracking/spans/span-hooks.d.ts +28 -0
  93. package/dist/tracking/spans/span-hooks.d.ts.map +1 -0
  94. package/dist/tracking/spans/span-hooks.js +409 -0
  95. package/dist/tracking/spans/span-hooks.js.map +1 -0
  96. package/dist/tracking/spans/span-tracker.d.ts +133 -0
  97. package/dist/tracking/spans/span-tracker.d.ts.map +1 -0
  98. package/dist/tracking/spans/span-tracker.js +721 -0
  99. package/dist/tracking/spans/span-tracker.js.map +1 -0
  100. package/dist/tracking/spans/span-transport.d.ts +65 -0
  101. package/dist/tracking/spans/span-transport.d.ts.map +1 -0
  102. package/dist/tracking/spans/span-transport.js +240 -0
  103. package/dist/tracking/spans/span-transport.js.map +1 -0
  104. package/dist/tracking/spans/types.d.ts +101 -0
  105. package/dist/tracking/spans/types.d.ts.map +1 -0
  106. package/dist/tracking/spans/types.js +6 -0
  107. package/dist/tracking/spans/types.js.map +1 -0
  108. package/dist/types/hooks.d.ts +1 -0
  109. package/dist/types/hooks.d.ts.map +1 -1
  110. package/dist/types/hooks.js +1 -0
  111. package/dist/types/hooks.js.map +1 -1
  112. package/dist/utils/retry.d.ts +7 -0
  113. package/dist/utils/retry.d.ts.map +1 -1
  114. package/dist/utils/retry.js +5 -1
  115. package/dist/utils/retry.js.map +1 -1
  116. package/openclaw.plugin.json +1 -1
  117. package/package.json +3 -1
@@ -0,0 +1,115 @@
1
+ /**
2
+ * PII + secret redaction for span payloads.
3
+ *
4
+ * Walks the `data` field of each span and replaces matches in string values
5
+ * before the batch hits the wire. Runs at flush time (async) — the underlying
6
+ * redactor is async, and the producer is fire-and-forget, so we pay the
7
+ * latency on the network-bound path rather than on the caller's enqueue call.
8
+ *
9
+ * Scope (see createOpenRedactionAdapter): emails, phones (US, international,
10
+ * India, China, South Korea, Japan, UK mobile, Brazil), ~28 vendor API keys
11
+ * / tokens (AWS, GitHub, Stripe, OpenAI, etc.), EVM private keys, Anthropic
12
+ * `sk-ant-*` keys, generic `sk-*` keys, and BIP39 mnemonic phrases.
13
+ *
14
+ * Integration point: BatchingSpanTransport.flush() applies this to every
15
+ * span in the batch before JSON.stringify. Only `span.data` is walked;
16
+ * top-level columns (`address`, `correlationId`, etc.) are non-PII identifiers
17
+ * and stay as-is.
18
+ *
19
+ * Always on — the plugin initializes a default redactor at startup.
20
+ */
21
+ import type { TrackingSpan } from "./types.js";
22
+ /** Minimal interface so tests can inject a synchronous stub. */
23
+ export interface PiiRedactor {
24
+ redact(text: string): Promise<string>;
25
+ }
26
+ /**
27
+ * Walks a JSON-shaped value. Strings are run through the redactor; arrays
28
+ * and plain objects are recursed; everything else (number, boolean, null,
29
+ * non-plain objects) is returned unchanged. Preserves reference identity
30
+ * when nothing changes — useful for short-circuit downstream comparisons.
31
+ */
32
+ export declare function redactStringsDeep(value: unknown, redactor: PiiRedactor): Promise<unknown>;
33
+ /**
34
+ * Redact PII inside `span.data` only. Top-level structural fields (address,
35
+ * correlationId, runId, etc.) are non-PII identifiers and skipped.
36
+ *
37
+ * Returns the same span if nothing changed (avoids object allocation when no
38
+ * PII was found).
39
+ */
40
+ export declare function redactSpanData(span: TrackingSpan, redactor: PiiRedactor): Promise<TrackingSpan>;
41
+ export declare function setDefaultPiiRedactor(r: PiiRedactor | null): void;
42
+ export declare function getDefaultPiiRedactor(): PiiRedactor | null;
43
+ /**
44
+ * Find BIP39-mnemonic spans in `text` using a true sliding window — not
45
+ * a greedy regex with a post-hoc validator.
46
+ *
47
+ * Why this and not a regex+validator:
48
+ * - OpenRedaction calls the validator on whatever the regex captured. JS
49
+ * regex matching is left-to-right with no backtracking across `lastIndex`
50
+ * advances; once a (greedy) match is rejected, the engine moves past it
51
+ * entirely. So a 17-word lowercase run like "my secret is <12 BIP39>
52
+ * so keep safe" gets captured whole, fails validation on word count,
53
+ * and the engine doesn't retry the 12-word window starting 3 tokens in.
54
+ *
55
+ * Algorithm:
56
+ * 1. Tokenize lowercase-only words and their offsets (skips capitalized
57
+ * words and punctuation — real mnemonics from wallet exports are
58
+ * always all-lowercase space-separated).
59
+ * 2. Walk left to right. At each token position, try valid mnemonic
60
+ * counts largest-first (24, 21, 18, 15, 12) so a 24-word phrase
61
+ * inside a longer prose run isn't missed by a premature 12-match.
62
+ * 3. A window is valid only when every word is BIP39 AND the gap between
63
+ * consecutive tokens in the source is whitespace-only (rejects forms
64
+ * with commas or other punctuation between words, which real wallet
65
+ * exports don't use).
66
+ * 4. On match, record the source span and advance past it; otherwise step
67
+ * forward one token.
68
+ */
69
+ export declare function findMnemonicSpans(text: string, bip39: Set<string>): Array<{
70
+ start: number;
71
+ end: number;
72
+ }>;
73
+ /**
74
+ * Pre-redact BIP39 mnemonics in `text` before handing the result to
75
+ * OpenRedaction. Returns the original string when no mnemonics are present
76
+ * (cheap path — only the tokenizer runs and finds nothing).
77
+ */
78
+ export declare function redactMnemonicsPreRedaction(text: string): Promise<string>;
79
+ /**
80
+ * Build an OpenRedaction-backed PiiRedactor.
81
+ *
82
+ * Detects:
83
+ * - Contact PII: emails.
84
+ * - Phones (all custom — upstream phone patterns are unreliable, see
85
+ * ALLOWLISTED_PATTERN_TYPES docstring): US, international (`+` prefix),
86
+ * India, China, South Korea, Japan, UK mobile, Brazil. Each requires
87
+ * either an explicit country code OR a country-specific mobile prefix
88
+ * plus separators, so bare numeric IDs (timestamps, span IDs, UUIDs)
89
+ * survive untouched.
90
+ * - Credentials (upstream): cloud / vendor API keys + tokens (AWS, Azure,
91
+ * GCP, GitHub, Slack, Stripe, OpenAI, Twilio, …), bearer + JWT tokens,
92
+ * OAuth secrets, generic API keys, SSH/PEM private keys, URLs with
93
+ * embedded auth.
94
+ * - Crypto secrets (custom patterns): EVM private keys (0x + 64 hex),
95
+ * Anthropic `sk-ant-*` keys, generic `sk-*` keys (OpenAI/OpenRouter).
96
+ * - BIP39 mnemonic phrases (out-of-band sliding-window pre-pass — see
97
+ * `redactMnemonicsPreRedaction`): 12/15/18/21/24 BIP39 words, found and
98
+ * redacted before the OpenRedaction pass so embedded phrases like
99
+ * "my key is <12 words> keep safe" are caught.
100
+ *
101
+ * Tuning:
102
+ * - `enableFalsePositiveFilter: false` — explicit; the library defaults
103
+ * this to truthy in practice and suppresses valid international-phone
104
+ * matches in some contexts.
105
+ * - `enableContextAnalysis: false` — saves CPU; context rules add
106
+ * latency and aren't load-bearing for the patterns we keep.
107
+ * - `enableCache: true` — chat history repeats; cache skips re-scan.
108
+ * - `confidenceThreshold: 0.5` — kept conservative; custom patterns score
109
+ * 1.0 so this only affects built-ins.
110
+ *
111
+ * Lazy-imports `openredaction` and `bip39` — both deps stay cold for builds
112
+ * / tests that don't enable redaction.
113
+ */
114
+ export declare function createOpenRedactionAdapter(): Promise<PiiRedactor>;
115
+ //# sourceMappingURL=redact-pii.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redact-pii.d.ts","sourceRoot":"","sources":["../../../src/tracking/spans/redact-pii.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK/C,gEAAgE;AAChE,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACvC;AAQD;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,WAAW,GACpB,OAAO,CAAC,OAAO,CAAC,CAgClB;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,WAAW,GACpB,OAAO,CAAC,YAAY,CAAC,CAKvB;AASD,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,GAAG,IAAI,CAEjE;AAED,wBAAgB,qBAAqB,IAAI,WAAW,GAAG,IAAI,CAE1D;AAqOD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,GACjB,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CA0CvC;AAsBD;;;;GAIG;AACH,wBAAsB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAI/E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,WAAW,CAAC,CAkCvE"}
@@ -0,0 +1,464 @@
1
+ /**
2
+ * PII + secret redaction for span payloads.
3
+ *
4
+ * Walks the `data` field of each span and replaces matches in string values
5
+ * before the batch hits the wire. Runs at flush time (async) — the underlying
6
+ * redactor is async, and the producer is fire-and-forget, so we pay the
7
+ * latency on the network-bound path rather than on the caller's enqueue call.
8
+ *
9
+ * Scope (see createOpenRedactionAdapter): emails, phones (US, international,
10
+ * India, China, South Korea, Japan, UK mobile, Brazil), ~28 vendor API keys
11
+ * / tokens (AWS, GitHub, Stripe, OpenAI, etc.), EVM private keys, Anthropic
12
+ * `sk-ant-*` keys, generic `sk-*` keys, and BIP39 mnemonic phrases.
13
+ *
14
+ * Integration point: BatchingSpanTransport.flush() applies this to every
15
+ * span in the batch before JSON.stringify. Only `span.data` is walked;
16
+ * top-level columns (`address`, `correlationId`, etc.) are non-PII identifiers
17
+ * and stay as-is.
18
+ *
19
+ * Always on — the plugin initializes a default redactor at startup.
20
+ */
21
+ import { createLogger } from "../../utils/logger.js";
22
+ const logger = createLogger("[senpi-core][redact-pii]");
23
+ function isPlainObject(value) {
24
+ if (value === null || typeof value !== "object")
25
+ return false;
26
+ const proto = Object.getPrototypeOf(value);
27
+ return proto === Object.prototype || proto === null;
28
+ }
29
+ /**
30
+ * Walks a JSON-shaped value. Strings are run through the redactor; arrays
31
+ * and plain objects are recursed; everything else (number, boolean, null,
32
+ * non-plain objects) is returned unchanged. Preserves reference identity
33
+ * when nothing changes — useful for short-circuit downstream comparisons.
34
+ */
35
+ export async function redactStringsDeep(value, redactor) {
36
+ if (typeof value === "string") {
37
+ if (value.length === 0)
38
+ return value;
39
+ try {
40
+ return await redactor.redact(value);
41
+ }
42
+ catch (err) {
43
+ logger.warn("redactor.redact threw; passing through original", {
44
+ err: err instanceof Error ? err.message : String(err),
45
+ preview: value.slice(0, 64),
46
+ });
47
+ return value;
48
+ }
49
+ }
50
+ if (Array.isArray(value)) {
51
+ const next = await Promise.all(value.map((item) => redactStringsDeep(item, redactor)));
52
+ return next.some((v, i) => v !== value[i]) ? next : value;
53
+ }
54
+ if (isPlainObject(value)) {
55
+ const entries = await Promise.all(Object.entries(value).map(async ([k, v]) => [k, await redactStringsDeep(v, redactor)]));
56
+ let changed = false;
57
+ const out = {};
58
+ for (const [k, v] of entries) {
59
+ out[k] = v;
60
+ if (v !== value[k])
61
+ changed = true;
62
+ }
63
+ return changed ? out : value;
64
+ }
65
+ return value;
66
+ }
67
+ /**
68
+ * Redact PII inside `span.data` only. Top-level structural fields (address,
69
+ * correlationId, runId, etc.) are non-PII identifiers and skipped.
70
+ *
71
+ * Returns the same span if nothing changed (avoids object allocation when no
72
+ * PII was found).
73
+ */
74
+ export async function redactSpanData(span, redactor) {
75
+ if (!span.data || typeof span.data !== "object")
76
+ return span;
77
+ const next = await redactStringsDeep(span.data, redactor);
78
+ if (next === span.data)
79
+ return span;
80
+ return { ...span, data: next };
81
+ }
82
+ // ─── Default redactor lifecycle ────────────────────────────────────────────
83
+ //
84
+ // The runtime registers a default redactor at startup when the feature flag is
85
+ // on; transports look it up via getDefaultPiiRedactor(). Tests can override.
86
+ let defaultRedactor = null;
87
+ export function setDefaultPiiRedactor(r) {
88
+ defaultRedactor = r;
89
+ }
90
+ export function getDefaultPiiRedactor() {
91
+ return defaultRedactor;
92
+ }
93
+ /**
94
+ * Built-in OpenRedaction pattern types we allowlist for span redaction.
95
+ *
96
+ * Scoped via the `patterns` whitelist (not categories) because category
97
+ * activation sweeps in patterns that false-positive on our domain content:
98
+ *
99
+ * - `categories: ['personal']` activates NAME patterns that redact
100
+ * strategy/asset names ("Setup Bison strategy" → "[NAME_xxx] strategy",
101
+ * "long position on ETH" → "long position on [NAME_xxx]").
102
+ * - `categories: ['financial']` activates ETH_ADDR which redacts wallet
103
+ * addresses inside `data.input.strategyWalletAddress`, breaking joins.
104
+ *
105
+ * Phone patterns from upstream are NOT used — we ship our own custom
106
+ * patterns instead. Specifically:
107
+ * - `PHONE_UK` — over-permissive: regex matches any 11-12 digit run with
108
+ * no separators, so the trailing 12-digit segment of a UUID (e.g.,
109
+ * `...446655440000`) is misclassified as a UK phone.
110
+ * - `PHONE_US` (upstream) — matches bare 10-digit numbers, which collides
111
+ * with 10-digit Unix timestamps (`1716855600`).
112
+ * - `PHONE_INTERNATIONAL` (upstream) — fine in isolation, but with
113
+ * `enableContextAnalysis: false` the library still suppresses matches
114
+ * in some contexts via undocumented filters; replacing it with our own
115
+ * custom version gives us deterministic behavior.
116
+ * - `TURKEY_ID` — personal national ID, not a credential.
117
+ */
118
+ const ALLOWLISTED_PATTERN_TYPES = [
119
+ // Contact PII (phones come from custom patterns below)
120
+ "EMAIL",
121
+ // Cloud / vendor API keys + tokens
122
+ "AWS_ACCESS_KEY",
123
+ "AWS_SECRET_KEY",
124
+ "AZURE_STORAGE_KEY",
125
+ "BEARER_TOKEN",
126
+ "CARD_AUTH_CODE",
127
+ "DOCKER_AUTH",
128
+ "FIREBASE_API_KEY",
129
+ "GENERIC_API_KEY",
130
+ "GENERIC_SECRET",
131
+ "GITHUB_TOKEN",
132
+ "GOOGLE_API_KEY",
133
+ "HEROKU_API_KEY",
134
+ "JWT_TOKEN",
135
+ "KUBERNETES_SECRET",
136
+ "MAILGUN_API_KEY",
137
+ "NPM_TOKEN",
138
+ "OAUTH_CLIENT_SECRET",
139
+ "OAUTH_TOKEN",
140
+ "OPENAI_API_KEY",
141
+ "PRIVATE_KEY",
142
+ "PYPI_TOKEN",
143
+ "SENDGRID_API_KEY",
144
+ "SLACK_TOKEN",
145
+ "SSH_PRIVATE_KEY",
146
+ "STRIPE_API_KEY",
147
+ "TWILIO_API_KEY",
148
+ "URL_WITH_AUTH",
149
+ ];
150
+ /**
151
+ * Phone patterns are entirely custom because upstream is unreliable: PHONE_UK
152
+ * matches bare 11–12 digit runs (UUID trailing segments), upstream PHONE_US
153
+ * matches bare 10-digit runs (Unix-seconds timestamps), and the library
154
+ * doesn't ship India / China / Korea / Japan / Brazil patterns at all.
155
+ *
156
+ * Design rule: every pattern requires either an explicit country code OR a
157
+ * country-specific mobile prefix AND/OR separators between groups. Pure
158
+ * numeric IDs (timestamps, span IDs, counters, UUID segments) don't satisfy
159
+ * any of those constraints, so they survive untouched.
160
+ */
161
+ const PHONE_PATTERNS = [
162
+ {
163
+ type: "PHONE_INTL",
164
+ regex: /\+\d[\d\s.\-()]{8,20}\d/g,
165
+ priority: 90,
166
+ placeholder: "[PHONE_INTL_{n}]",
167
+ severity: "high",
168
+ description: "International phone with explicit + country-code prefix.",
169
+ },
170
+ {
171
+ type: "PHONE_US",
172
+ // `(?<!\d)` / `(?!\d)` instead of `\b` so `(415) 555-1234` matches at
173
+ // "space-paren" (where \b fails) and bare 10-digit timestamps don't.
174
+ regex: /(?<!\d)(?:\+1[\s.-])?(?:\(\d{3}\)[\s.-]?|\d{3}[\s.-])\d{3}[\s.-]\d{4}(?!\d)/g,
175
+ priority: 88,
176
+ placeholder: "[PHONE_US_{n}]",
177
+ severity: "high",
178
+ description: "US phone with at least one separator (rejects bare 10-digit timestamps).",
179
+ },
180
+ {
181
+ type: "PHONE_IN",
182
+ regex: /\b(?:\+?91[\s.-]?)?[6-9]\d{4}[\s.-]?\d{5}\b/g,
183
+ priority: 85,
184
+ placeholder: "[PHONE_IN_{n}]",
185
+ severity: "high",
186
+ description: "Indian mobile (10 digits starting 6-9; optional +91/91 prefix).",
187
+ },
188
+ {
189
+ type: "PHONE_CN",
190
+ regex: /\b(?:\+?86[\s.-]?)?1[3-9]\d[\s.-]?\d{4}[\s.-]?\d{4}\b/g,
191
+ priority: 85,
192
+ placeholder: "[PHONE_CN_{n}]",
193
+ severity: "high",
194
+ description: "Chinese mobile (11 digits starting 1[3-9]; optional +86/86 prefix).",
195
+ },
196
+ {
197
+ type: "PHONE_KR",
198
+ regex: /\b(?:\+?82[\s.-]?)?0?1[01679][\s.-]\d{3,4}[\s.-]\d{4}\b/g,
199
+ priority: 85,
200
+ placeholder: "[PHONE_KR_{n}]",
201
+ severity: "high",
202
+ description: "Korean mobile (010/011/016-019 + separators; optional +82 prefix).",
203
+ },
204
+ {
205
+ type: "PHONE_JP",
206
+ regex: /\b(?:\+?81[\s.-]?)?0?[789]0[\s.-]\d{4}[\s.-]\d{4}\b/g,
207
+ priority: 85,
208
+ placeholder: "[PHONE_JP_{n}]",
209
+ severity: "high",
210
+ description: "Japanese mobile (070/080/090 + separators; optional +81 prefix).",
211
+ },
212
+ {
213
+ type: "PHONE_UK_MOBILE",
214
+ regex: /\b(?:\+?44[\s.-]?|0)7\d{3}[\s.-]?\d{3}[\s.-]?\d{3}\b/g,
215
+ priority: 85,
216
+ placeholder: "[PHONE_UK_{n}]",
217
+ severity: "high",
218
+ description: "UK mobile (07xxx; optional +44 prefix).",
219
+ },
220
+ {
221
+ type: "PHONE_BR",
222
+ regex: /\b\+?55[\s.-]?\(?\d{2}\)?[\s.-]?9\d{4}[\s.-]?\d{4}\b/g,
223
+ priority: 85,
224
+ placeholder: "[PHONE_BR_{n}]",
225
+ severity: "high",
226
+ description: "Brazilian mobile (+55 required + DDD + 9-digit number).",
227
+ },
228
+ ];
229
+ /**
230
+ * Lazy-load the BIP39 English wordlist into a Set for O(1) lookup during
231
+ * mnemonic validation. Cached after first call; the `bip39` package is only
232
+ * pulled in when PII redaction is enabled, keeping cold-start cost off the
233
+ * non-redacting build.
234
+ */
235
+ let bip39WordSet = null;
236
+ async function getBip39WordSet() {
237
+ if (bip39WordSet)
238
+ return bip39WordSet;
239
+ const mod = (await import("bip39"));
240
+ const wordlists = mod.wordlists ?? mod.default?.wordlists;
241
+ if (!wordlists?.english) {
242
+ throw new Error("bip39: english wordlist not available");
243
+ }
244
+ bip39WordSet = new Set(wordlists.english);
245
+ return bip39WordSet;
246
+ }
247
+ /**
248
+ * Build the custom-pattern set we layer on top of OpenRedaction's built-ins.
249
+ * These cover credentials common in our agent traffic that the upstream
250
+ * library either misses entirely or whose built-in pattern doesn't fire
251
+ * without context:
252
+ *
253
+ * - CRYPTO_PRIVKEY_HEX: `0x` + 64 hex = EVM private key. Also matches
254
+ * SHA-256 hashes; over-redaction is acceptable since hashes inside
255
+ * `data` are rare and not load-bearing.
256
+ * - ANTHROPIC_API_KEY: `sk-ant-(api|admin)NN-...`; upstream has no
257
+ * specific Anthropic pattern.
258
+ * - SK_API_KEY: catch-all for OpenAI / OpenRouter / similar `sk-` prefixed
259
+ * keys; upstream OPENAI_API_KEY didn't fire on real `sk-proj-*` and
260
+ * `sk-svcacct-*` formats in smoke tests.
261
+ *
262
+ * NOTE: Mnemonic detection is NOT in this list. The earlier regex-with-
263
+ * validator approach was greedy and silently missed mnemonics surrounded by
264
+ * other lowercase words (e.g. "my secret is <12 BIP39 words> so keep safe"
265
+ * → regex captures the full 17-word run, validator rejects on count/words,
266
+ * library moves on without retrying a shorter window). Mnemonics are now
267
+ * handled by `redactMnemonicsPreRedaction` ahead of the OpenRedaction pass.
268
+ */
269
+ async function buildCustomPatterns() {
270
+ return [
271
+ ...PHONE_PATTERNS,
272
+ {
273
+ type: "CRYPTO_PRIVKEY_HEX",
274
+ regex: /\b0x[0-9a-fA-F]{64}\b/g,
275
+ priority: 110,
276
+ placeholder: "[CRYPTO_PRIVKEY_{n}]",
277
+ severity: "critical",
278
+ description: "EVM private key (0x + 32-byte hex). Matches SHA-256 hashes too — accepted as collateral.",
279
+ },
280
+ {
281
+ type: "ANTHROPIC_API_KEY",
282
+ regex: /\bsk-ant-(?:api|admin)\d+-[A-Za-z0-9_\-]{40,}\b/g,
283
+ priority: 110,
284
+ placeholder: "[ANTHROPIC_KEY_{n}]",
285
+ severity: "critical",
286
+ },
287
+ {
288
+ type: "SK_API_KEY",
289
+ regex: /\bsk-(?:proj|live|test|or|svcacct)?[-_]?[A-Za-z0-9_\-]{32,}\b/g,
290
+ priority: 100,
291
+ placeholder: "[SK_KEY_{n}]",
292
+ severity: "critical",
293
+ description: "Catch-all for sk-* API keys (OpenAI, OpenRouter, etc.).",
294
+ },
295
+ ];
296
+ }
297
+ /**
298
+ * Find BIP39-mnemonic spans in `text` using a true sliding window — not
299
+ * a greedy regex with a post-hoc validator.
300
+ *
301
+ * Why this and not a regex+validator:
302
+ * - OpenRedaction calls the validator on whatever the regex captured. JS
303
+ * regex matching is left-to-right with no backtracking across `lastIndex`
304
+ * advances; once a (greedy) match is rejected, the engine moves past it
305
+ * entirely. So a 17-word lowercase run like "my secret is <12 BIP39>
306
+ * so keep safe" gets captured whole, fails validation on word count,
307
+ * and the engine doesn't retry the 12-word window starting 3 tokens in.
308
+ *
309
+ * Algorithm:
310
+ * 1. Tokenize lowercase-only words and their offsets (skips capitalized
311
+ * words and punctuation — real mnemonics from wallet exports are
312
+ * always all-lowercase space-separated).
313
+ * 2. Walk left to right. At each token position, try valid mnemonic
314
+ * counts largest-first (24, 21, 18, 15, 12) so a 24-word phrase
315
+ * inside a longer prose run isn't missed by a premature 12-match.
316
+ * 3. A window is valid only when every word is BIP39 AND the gap between
317
+ * consecutive tokens in the source is whitespace-only (rejects forms
318
+ * with commas or other punctuation between words, which real wallet
319
+ * exports don't use).
320
+ * 4. On match, record the source span and advance past it; otherwise step
321
+ * forward one token.
322
+ */
323
+ export function findMnemonicSpans(text, bip39) {
324
+ const tokens = [];
325
+ const wordRe = /[a-z]+/g;
326
+ let m;
327
+ while ((m = wordRe.exec(text)) !== null) {
328
+ tokens.push({ word: m[0], start: m.index, end: m.index + m[0].length });
329
+ }
330
+ const validCounts = [24, 21, 18, 15, 12];
331
+ const spans = [];
332
+ let i = 0;
333
+ while (i < tokens.length) {
334
+ let matched = false;
335
+ for (const count of validCounts) {
336
+ if (i + count > tokens.length)
337
+ continue;
338
+ let valid = true;
339
+ for (let j = 0; j < count; j++) {
340
+ if (!bip39.has(tokens[i + j].word)) {
341
+ valid = false;
342
+ break;
343
+ }
344
+ if (j > 0) {
345
+ const gap = text.slice(tokens[i + j - 1].end, tokens[i + j].start);
346
+ if (!/^\s+$/.test(gap)) {
347
+ valid = false;
348
+ break;
349
+ }
350
+ }
351
+ }
352
+ if (valid) {
353
+ spans.push({
354
+ start: tokens[i].start,
355
+ end: tokens[i + count - 1].end,
356
+ });
357
+ i += count;
358
+ matched = true;
359
+ break;
360
+ }
361
+ }
362
+ if (!matched)
363
+ i++;
364
+ }
365
+ return spans;
366
+ }
367
+ let mnemonicCounter = 0;
368
+ function redactMnemonicSpans(text, spans) {
369
+ if (spans.length === 0)
370
+ return text;
371
+ let out = "";
372
+ let cursor = 0;
373
+ for (const span of spans) {
374
+ out += text.slice(cursor, span.start);
375
+ // Bracketed uppercase placeholder ensures the result won't re-tokenize
376
+ // back into lowercase BIP39-shaped words on a second pass.
377
+ const suffix = String(mnemonicCounter++ % 10000).padStart(4, "0");
378
+ out += `[MNEMONIC_${suffix}]`;
379
+ cursor = span.end;
380
+ }
381
+ out += text.slice(cursor);
382
+ return out;
383
+ }
384
+ /**
385
+ * Pre-redact BIP39 mnemonics in `text` before handing the result to
386
+ * OpenRedaction. Returns the original string when no mnemonics are present
387
+ * (cheap path — only the tokenizer runs and finds nothing).
388
+ */
389
+ export async function redactMnemonicsPreRedaction(text) {
390
+ const bip39 = await getBip39WordSet();
391
+ const spans = findMnemonicSpans(text, bip39);
392
+ return redactMnemonicSpans(text, spans);
393
+ }
394
+ /**
395
+ * Build an OpenRedaction-backed PiiRedactor.
396
+ *
397
+ * Detects:
398
+ * - Contact PII: emails.
399
+ * - Phones (all custom — upstream phone patterns are unreliable, see
400
+ * ALLOWLISTED_PATTERN_TYPES docstring): US, international (`+` prefix),
401
+ * India, China, South Korea, Japan, UK mobile, Brazil. Each requires
402
+ * either an explicit country code OR a country-specific mobile prefix
403
+ * plus separators, so bare numeric IDs (timestamps, span IDs, UUIDs)
404
+ * survive untouched.
405
+ * - Credentials (upstream): cloud / vendor API keys + tokens (AWS, Azure,
406
+ * GCP, GitHub, Slack, Stripe, OpenAI, Twilio, …), bearer + JWT tokens,
407
+ * OAuth secrets, generic API keys, SSH/PEM private keys, URLs with
408
+ * embedded auth.
409
+ * - Crypto secrets (custom patterns): EVM private keys (0x + 64 hex),
410
+ * Anthropic `sk-ant-*` keys, generic `sk-*` keys (OpenAI/OpenRouter).
411
+ * - BIP39 mnemonic phrases (out-of-band sliding-window pre-pass — see
412
+ * `redactMnemonicsPreRedaction`): 12/15/18/21/24 BIP39 words, found and
413
+ * redacted before the OpenRedaction pass so embedded phrases like
414
+ * "my key is <12 words> keep safe" are caught.
415
+ *
416
+ * Tuning:
417
+ * - `enableFalsePositiveFilter: false` — explicit; the library defaults
418
+ * this to truthy in practice and suppresses valid international-phone
419
+ * matches in some contexts.
420
+ * - `enableContextAnalysis: false` — saves CPU; context rules add
421
+ * latency and aren't load-bearing for the patterns we keep.
422
+ * - `enableCache: true` — chat history repeats; cache skips re-scan.
423
+ * - `confidenceThreshold: 0.5` — kept conservative; custom patterns score
424
+ * 1.0 so this only affects built-ins.
425
+ *
426
+ * Lazy-imports `openredaction` and `bip39` — both deps stay cold for builds
427
+ * / tests that don't enable redaction.
428
+ */
429
+ export async function createOpenRedactionAdapter() {
430
+ const { OpenRedaction } = await import("openredaction");
431
+ const customPatterns = await buildCustomPatterns();
432
+ // Our local custom-pattern descriptor type is structurally compatible with
433
+ // the upstream PIIPattern. Cast at the options-object boundary so callers
434
+ // don't need a build-time dependency on the openredaction type.
435
+ const options = {
436
+ patterns: [...ALLOWLISTED_PATTERN_TYPES],
437
+ customPatterns,
438
+ enableContextAnalysis: false,
439
+ enableMultiPass: false,
440
+ enableCache: true,
441
+ cacheSize: 200,
442
+ // Despite the docs saying default is `false`, leaving this unset
443
+ // causes the library to suppress otherwise-valid phone matches in some
444
+ // contexts (e.g., `+44 20 7946 0958` after "ring me on"). Force off so
445
+ // our strict custom regex is the only thing deciding what gets redacted.
446
+ enableFalsePositiveFilter: false,
447
+ confidenceThreshold: 0.5,
448
+ };
449
+ const instance = new OpenRedaction(options);
450
+ // Warm the BIP39 word set so the first user-facing call doesn't pay the
451
+ // dynamic-import latency.
452
+ await getBip39WordSet();
453
+ return {
454
+ async redact(text) {
455
+ // Mnemonic pre-pass runs FIRST — its sliding-window detector can find
456
+ // mnemonics that OpenRedaction's regex-with-validator misses when the
457
+ // phrase is embedded in surrounding lowercase prose.
458
+ const preRedacted = await redactMnemonicsPreRedaction(text);
459
+ const result = await instance.detect(preRedacted);
460
+ return result.redacted;
461
+ },
462
+ };
463
+ }
464
+ //# sourceMappingURL=redact-pii.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redact-pii.js","sourceRoot":"","sources":["../../../src/tracking/spans/redact-pii.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,MAAM,GAAG,YAAY,CAAC,0BAA0B,CAAC,CAAC;AAOxD,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IAC3C,OAAO,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,KAAc,EACd,QAAqB;IAErB,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACrC,IAAI,CAAC;YACH,OAAO,MAAM,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,iDAAiD,EAAE;gBAC7D,GAAG,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;gBACrD,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;aAC5B,CAAC,CAAC;YACH,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J,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Strip OpenClaw framework metadata from LLM payload strings before they're
3
+ * stamped onto spans.
4
+ *
5
+ * OpenClaw injects several metadata blocks into user-role messages:
6
+ * - `[[reply_to ...]]` markers
7
+ * - `Conversation info (untrusted metadata): { ... }` blocks
8
+ * - `Sender (untrusted metadata): { ... }` blocks
9
+ * - `Untrusted context (... ): <<<EXTERNAL_UNTRUSTED_CONTENT ... >>>` blocks
10
+ * (the heavy one — can be MBs when web-search / RAG context is attached)
11
+ * - `media:<url>.jpg` image references
12
+ *
13
+ * Without stripping, every llm_input on a Telegram chat session balloons past
14
+ * 1MB and our per-field truncation kicks in, losing the actual user prompt in
15
+ * the noise. Mirrors `opik-openclaw/src/service/payload-sanitizer.ts`.
16
+ */
17
+ export declare function sanitizePayloadString(value: string): string;
18
+ export declare function sanitizePayloadValue(value: unknown): unknown;
19
+ //# sourceMappingURL=sanitize-payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sanitize-payload.d.ts","sourceRoot":"","sources":["../../../src/tracking/spans/sanitize-payload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAWH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAY3D;AAQD,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAwB5D"}