pi-roundtable 0.7.5 → 0.7.7

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 CHANGED
@@ -5,6 +5,21 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.7.7] - 2026-10-03
9
+
10
+ ### Changed
11
+
12
+ - `scrubDiagnostic` takes linear time on a long run of `eyJ-` too: the JWT pattern now starts at the beginning of a run (a JWT glued directly after `-` is no longer masked by that pattern, only as the value of a secret-named field).
13
+ - `scrubDiagnostic` reads a quoted value up to its closing quote, so a secret holding `}`, `]`, blanks, `&`, `,` or `;` is masked whole; `}` and `]` end only an unquoted value. A value an earlier rule already masked is not masked again (no `[redacted]]`).
14
+
15
+ ## [0.7.6] - 2026-10-03
16
+
17
+ ### Changed
18
+
19
+ - `scrubDiagnostic` takes time linear in the text at any bound (`diagnosticChars: Infinity` included): every pattern starts at the beginning of a run through a lookbehind, and a value is read only for a secret-named field.
20
+ - `scrubDiagnostic` no longer masks what is not a secret: plural `tokens` counters (`max_tokens`, `input_tokens`), a numeric value of a token name, setting names such as `password_policy` or `token_limit`, and the word after `Basic`, `Bearer` or `token` unless it has a credential shape. A value ends at `}` and `]`.
21
+ - Drawing: `permissive` also accepts an empty relationship-map node id (the argument schema allows it), draws a sigil whose intention has no letters or is blank, and ignores a sacred-geometry color canvas cannot parse.
22
+
8
23
  ## [0.7.5] - 2026-10-03
9
24
 
10
25
  ### Added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-roundtable",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "description": "A plugin-driven Pi agent server for Discord",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,40 +1,118 @@
1
+ /*
2
+ * A pattern whose first characters can recur inside the run it then scans (a leading `\b` before a
3
+ * repeatable class, or a literal such as `eyJ` that may appear again after a `-`) restarts at every
4
+ * repeat and takes quadratic time. Those patterns start at the beginning of a run of their own
5
+ * character class through a lookbehind; the others begin with a literal that cannot recur inside
6
+ * what they scan. Scrubbing then takes time linear in the text at any length.
7
+ */
8
+
1
9
  /** Tool text that may name a credential: userinfo in URLs, bearer values, and well-known token shapes. */
2
- const CREDENTIALS: [RegExp, string][] = [
3
- [/\b([a-z][a-z0-9+.-]*:\/\/)[^\s/@]+@/gi, "$1[redacted]@"],
10
+ const CREDENTIALS: [RegExp, string | ((...match: string[]) => string)][] = [
11
+ [/(?<![a-z0-9+.-])([a-z][a-z0-9+.-]*:\/\/)[^\s/@]+@/gi, "$1[redacted]@"],
4
12
  [
5
13
  /\b(authorization|proxy-authorization)\s*[:=]\s*[^\r\n]+/gi,
6
14
  "$1: [redacted]",
7
15
  ],
8
- [/\b(bearer|basic|token)\s+[A-Za-z0-9._~+/=-]{8,}/gi, "$1 [redacted]"],
9
16
  [
10
- /\b(gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|glpat-[A-Za-z0-9_-]{16,}|sk-[A-Za-z0-9_-]{16,}|xox[abprs]-[A-Za-z0-9-]{10,}|AKIA[0-9A-Z]{16}|AIza[0-9A-Za-z_-]{30,})\b/g,
11
- "[redacted]",
17
+ /\b(bearer|basic|token)(\s+)([A-Za-z0-9._~+/=-]{8,})/gi,
18
+ (match, scheme = "", _space = "", value = "") =>
19
+ looksLikeCredential(value) ? `${scheme} [redacted]` : match,
12
20
  ],
13
- // Assignments, query parameters and JSON fields whose name says it is a secret, in any case.
14
21
  [
15
- /\b([a-z0-9_-]*(?:token|secret|password|passwd|api[_-]?key|credential)[a-z0-9_-]*)(["']?\s*[:=]\s*["']?)[^\s"',&;]+/gi,
16
- "$1$2[redacted]",
22
+ /\b(gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|glpat-[A-Za-z0-9_-]{16,}|sk-[A-Za-z0-9_-]{16,}|xox[abprs]-[A-Za-z0-9-]{10,}|AKIA[0-9A-Z]{16}|AIza[0-9A-Za-z_-]{30,})\b/g,
23
+ "[redacted]",
17
24
  ],
18
25
  [
19
26
  /\b(cookie|set-cookie|x-api-key|x-auth-token|x-access-token)\s*:\s*[^\r\n]+/gi,
20
27
  "$1: [redacted]",
21
28
  ],
22
- [/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]*/g, "[redacted]"],
29
+ [
30
+ /(?<![A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]*/g,
31
+ "[redacted]",
32
+ ],
23
33
  [
24
34
  /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,
25
35
  "[redacted]",
26
36
  ],
27
37
  ];
28
38
 
39
+ /** A bare word such as "authentication" is not a credential; a value with digits, symbols or inner capitals, or a very long one, may be. */
40
+ function looksLikeCredential(value: string): boolean {
41
+ return (
42
+ /[0-9+/=_~]/.test(value) || /[a-z][A-Z]/.test(value) || value.length >= 32
43
+ );
44
+ }
45
+
46
+ /** Names that say the value is a secret. A plural `tokens` counts tokens, and is not one. */
47
+ const SECRET_NAME =
48
+ /token(?!s(?![a-z]))|secret|password|passwd|api[_-]?key|credential/i;
49
+ /** What a name may continue with after the keyword and still hold a setting, not a secret. */
50
+ const SETTING_SUFFIX =
51
+ /^[_-]?(?:policy|policies|rules?|length|count|limit|max|min|type|format|expir\w*|ttl|lifetime|required|enabled|strategy|file|path|url|name|field|prompt|hint|window|budget|usage)(?![a-z])/i;
52
+
53
+ /** Whether the name says its value is a secret; a count is not a token, so a token name needs a non-numeric value. */
54
+ function secretKind(name: string): "secret" | "token" | undefined {
55
+ const keyword = SECRET_NAME.exec(name);
56
+ if (!keyword) return undefined;
57
+ const rest = name.slice(keyword.index + keyword[0].length);
58
+ if (SETTING_SUFFIX.test(rest)) return undefined;
59
+ return /^token/i.test(keyword[0]) ? "token" : "secret";
60
+ }
61
+
62
+ /** The name and separator of an assignment, query parameter or JSON field; the value is read separately. */
63
+ const ASSIGNMENT = /(?<![a-z0-9_-])([a-z0-9_-]+)(["']?\s*[:=]\s*["']?)/gi;
64
+ /** An unquoted value ends at a blank, a quote, a separator or a closing bracket. */
65
+ const UNQUOTED = /[^\s"',&;}\]]+/y;
66
+ /** A quoted value runs to its closing quote, whatever it holds. */
67
+ const DOUBLE_QUOTED = /[^"]+/y;
68
+ const SINGLE_QUOTED = /[^']+/y;
69
+
70
+ /** The value that follows a separator ending in `end`, or undefined when there is none. */
71
+ function valueAt(
72
+ text: string,
73
+ end: number,
74
+ separator: string,
75
+ ): string | undefined {
76
+ const quote = separator.endsWith('"')
77
+ ? DOUBLE_QUOTED
78
+ : separator.endsWith("'")
79
+ ? SINGLE_QUOTED
80
+ : UNQUOTED;
81
+ quote.lastIndex = end;
82
+ return quote.exec(text)?.[0];
83
+ }
84
+
85
+ /** Masks the value of every assignment whose name says it is a secret, in any case. */
86
+ function maskAssignments(text: string): string {
87
+ let out = "";
88
+ let cursor = 0;
89
+ for (const match of text.matchAll(ASSIGNMENT)) {
90
+ const start = match.index ?? 0;
91
+ const end = start + match[0].length;
92
+ if (start < cursor) continue;
93
+ // The value is read only for a secret name, so ordinary text costs nothing more to pass.
94
+ const kind = secretKind(match[1] ?? "");
95
+ if (!kind) continue;
96
+ const value = valueAt(text, end, match[2] ?? "");
97
+ // An earlier rule already masked this value.
98
+ if (value === undefined || value.startsWith("[redacted")) continue;
99
+ if (kind === "token" && /^[0-9]+$/.test(value)) continue;
100
+ out += `${text.slice(cursor, end)}[redacted]`;
101
+ cursor = end + value.length;
102
+ }
103
+ return out + text.slice(cursor);
104
+ }
105
+
29
106
  /**
30
107
  * Text from a failed subprocess or worker, safe to show a model or the owner: credentials are
31
108
  * masked, control characters are removed, and the length is bounded. Empty input returns "".
32
109
  */
33
110
  export function scrubDiagnostic(text: string, max = 600): string {
34
- // The patterns run on a bounded prefix, so hostile input cannot make them slow.
111
+ // Only what could survive the final cut is scrubbed, so the work follows the bound asked for.
35
112
  let clean = text.slice(0, Math.max(max * 4, 4096));
36
113
  for (const [pattern, replacement] of CREDENTIALS)
37
- clean = clean.replace(pattern, replacement);
114
+ clean = clean.replace(pattern, replacement as string);
115
+ clean = maskAssignments(clean);
38
116
  clean = Array.from(clean, (char) => {
39
117
  const code = char.charCodeAt(0);
40
118
  // Keep tab and newline; every other control character becomes a space.