dsh-thinking-levels 4.5.0 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -77,6 +77,14 @@ export interface ThinkingLevelsConfig {
77
77
  * namespace strip, exactly like a built-in token.
78
78
  */
79
79
  simpleTools: string[] | Volatile<string[]>;
80
+ /**
81
+ * Extra RAW REGEX patterns with the same cheap-and-deterministic role
82
+ * (issue #12): each entry compiles as written (`i` flag, no auto-anchoring —
83
+ * anchor with `^` yourself), and the matcher tests BOTH the full tool name
84
+ * and the namespace-stripped bare name, so `ops_.*` covers the whole family.
85
+ * Invalid patterns are skipped with a one-time warning.
86
+ */
87
+ simpleToolsRegex: string[] | Volatile<string[]>;
80
88
  /**
81
89
  * Master takeover switch: mirrored into the openai-completions transport's
82
90
  * own section (`llm-openai-completions.enabled`) when it flips. The
@@ -114,6 +122,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
114
122
  allowDowngrade: z<boolean, boolean, "volatile-defined">;
115
123
  allowUpgrade: z<boolean, boolean, "volatile-defined">;
116
124
  simpleTools: z<NoInfer<string[]>, NoInfer<string[]>, "volatile-defined">;
125
+ simpleToolsRegex: z<NoInfer<string[]>, NoInfer<string[]>, "volatile-defined">;
117
126
  takeover: z<boolean, boolean, "volatile-defined">;
118
127
  takeoverUi: z<boolean, boolean, "volatile-defined">;
119
128
  defaultPricing: z<"off" | "custom" | "estimate" | "cn" | "global", "off" | "custom" | "estimate" | "cn" | "global", "volatile-defined">;
@@ -134,6 +143,7 @@ export declare const Config: z<Schemastery.ObjectS<NoInfer<{
134
143
  allowDowngrade: z<boolean, boolean, "volatile-defined">;
135
144
  allowUpgrade: z<boolean, boolean, "volatile-defined">;
136
145
  simpleTools: z<NoInfer<string[]>, NoInfer<string[]>, "volatile-defined">;
146
+ simpleToolsRegex: z<NoInfer<string[]>, NoInfer<string[]>, "volatile-defined">;
137
147
  takeover: z<boolean, boolean, "volatile-defined">;
138
148
  takeoverUi: z<boolean, boolean, "volatile-defined">;
139
149
  defaultPricing: z<"off" | "custom" | "estimate" | "cn" | "global", "off" | "custom" | "estimate" | "cn" | "global", "volatile-defined">;
@@ -162,6 +172,7 @@ export declare const LegacyConfig: z<Schemastery.ObjectS<NoInfer<{
162
172
  allowDowngrade: z<boolean, boolean, "defined">;
163
173
  allowUpgrade: z<boolean, boolean, "defined">;
164
174
  simpleTools: z<string[], string[], "defined">;
175
+ simpleToolsRegex: z<string[], string[], "defined">;
165
176
  takeover: z<boolean, boolean, "defined">;
166
177
  takeoverUi: z<boolean, boolean, "defined">;
167
178
  defaultPricing: z<"off" | "custom" | "estimate" | "cn" | "global", "off" | "custom" | "estimate" | "cn" | "global", "defined">;
@@ -182,6 +193,7 @@ export declare const LegacyConfig: z<Schemastery.ObjectS<NoInfer<{
182
193
  allowDowngrade: z<boolean, boolean, "defined">;
183
194
  allowUpgrade: z<boolean, boolean, "defined">;
184
195
  simpleTools: z<string[], string[], "defined">;
196
+ simpleToolsRegex: z<string[], string[], "defined">;
185
197
  takeover: z<boolean, boolean, "defined">;
186
198
  takeoverUi: z<boolean, boolean, "defined">;
187
199
  defaultPricing: z<"off" | "custom" | "estimate" | "cn" | "global", "off" | "custom" | "estimate" | "cn" | "global", "defined">;
package/lib/index.js CHANGED
@@ -33,6 +33,7 @@ export const Config = z.object({
33
33
  allowDowngrade: z.boolean().default(true).volatile(),
34
34
  allowUpgrade: z.boolean().default(false).volatile(),
35
35
  simpleTools: z.array(z.string()).default([]).volatile(),
36
+ simpleToolsRegex: z.array(z.string()).default([]).volatile(),
36
37
  takeover: z.boolean().default(false).volatile(),
37
38
  takeoverUi: z.boolean().default(false).volatile(),
38
39
  defaultPricing: defaultPricingSchema.volatile(),
@@ -51,6 +52,7 @@ export const LegacyConfig = z.object({
51
52
  allowDowngrade: z.boolean().default(true),
52
53
  allowUpgrade: z.boolean().default(false),
53
54
  simpleTools: z.array(z.string()).default([]),
55
+ simpleToolsRegex: z.array(z.string()).default([]),
54
56
  takeover: z.boolean().default(false),
55
57
  takeoverUi: z.boolean().default(false),
56
58
  defaultPricing: defaultPricingSchema,
@@ -63,6 +65,7 @@ export const DEFAULT_CONFIG = {
63
65
  allowDowngrade: true,
64
66
  allowUpgrade: false,
65
67
  simpleTools: [],
68
+ simpleToolsRegex: [],
66
69
  takeover: false,
67
70
  takeoverUi: false,
68
71
  defaultPricing: 'estimate',
@@ -93,6 +96,7 @@ function resolveLiveConfig(config) {
93
96
  allowDowngrade: readVolatile(config.allowDowngrade, true),
94
97
  allowUpgrade: readVolatile(config.allowUpgrade, false),
95
98
  simpleTools: readVolatile(config.simpleTools, []),
99
+ simpleToolsRegex: readVolatile(config.simpleToolsRegex, []),
96
100
  takeover: readVolatile(config.takeover, false),
97
101
  takeoverUi: readVolatile(config.takeoverUi, false),
98
102
  defaultPricing: readVolatile(config.defaultPricing, 'estimate'),
@@ -453,6 +457,7 @@ export function installLegacySection(ctx, config, hooks) {
453
457
  allowDowngrade: readVolatile(config.allowDowngrade, true),
454
458
  allowUpgrade: readVolatile(config.allowUpgrade, false),
455
459
  simpleTools: readVolatile(config.simpleTools, []),
460
+ simpleToolsRegex: readVolatile(config.simpleToolsRegex, []),
456
461
  takeover: readVolatile(config.takeover, false),
457
462
  takeoverUi: readVolatile(config.takeoverUi, false),
458
463
  models: config.models,
@@ -659,6 +664,7 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
659
664
  allowDowngrade: cfg.allowDowngrade,
660
665
  allowUpgrade: cfg.allowUpgrade,
661
666
  extraSimpleTools: cfg.simpleTools,
667
+ extraSimpleRegex: cfg.simpleToolsRegex,
662
668
  supportsReasoning: capabilityFor.supportsReasoning,
663
669
  efforts: capabilityFor.efforts,
664
670
  toggleOnly: capabilityFor.toggleOnly,
@@ -812,6 +818,7 @@ export function apply(ctx, config = DEFAULT_CONFIG) {
812
818
  allowDowngrade: cfg.allowDowngrade,
813
819
  allowUpgrade: cfg.allowUpgrade,
814
820
  extraSimpleTools: cfg.simpleTools,
821
+ extraSimpleRegex: cfg.simpleToolsRegex,
815
822
  efforts: capabilityFor.efforts,
816
823
  toggleOnly: capabilityFor.toggleOnly,
817
824
  });
@@ -66,6 +66,8 @@ export interface StrictStepInput {
66
66
  allowUpgrade: boolean;
67
67
  /** Extra tool names merged into the built-in cheap-and-deterministic set (issue #8 `Config.simpleTools`). */
68
68
  extraSimpleTools?: readonly string[];
69
+ /** Extra raw regex patterns for the same set (issue #12 `Config.simpleToolsRegex`). */
70
+ extraSimpleRegex?: readonly string[];
69
71
  /** Whether the target model advertises reasoning-effort support at all. */
70
72
  supportsReasoning: boolean;
71
73
  /** The model's advertised effort ids (including plugin masks like `auto`). */
@@ -81,6 +81,7 @@ export function planStrictStep(input) {
81
81
  allowDowngrade: input.allowDowngrade,
82
82
  allowUpgrade: input.allowUpgrade,
83
83
  extraSimpleTools: input.extraSimpleTools,
84
+ extraSimpleRegex: input.extraSimpleRegex,
84
85
  efforts: input.efforts,
85
86
  toggleOnly: input.toggleOnly,
86
87
  });
@@ -69,7 +69,40 @@ export interface EffortDecisionInput {
69
69
  * leaves the built-in classification untouched (issue #8 `Config.simpleTools`).
70
70
  */
71
71
  extraSimpleTools?: readonly string[];
72
+ /**
73
+ * Extra RAW REGEX patterns treated as cheap-and-deterministic, merged with
74
+ * the literal list and the built-in set (issue #12 `Config.simpleToolsRegex`).
75
+ * Each entry compiles as written (`i` flag, no auto-anchoring — the hint
76
+ * suggests `^`); invalid entries are skipped with a one-time warning. The
77
+ * matcher tests the full name and the bare name, so a family pattern like
78
+ * `ops_.*` hits the whole namespace.
79
+ */
80
+ extraSimpleRegex?: readonly string[];
81
+ }
82
+ /**
83
+ * The merged cheap-and-deterministic classifier over both extra lists
84
+ * (issue #12): literal entries (`Config.simpleTools`, anchored exactly as
85
+ * before) plus raw regex entries (`Config.simpleToolsRegex`, compiled as
86
+ * written — invalid ones skipped with a one-time warning, never thrown).
87
+ *
88
+ * `test` matches the FULL tool name AND the namespace-stripped bare name: a
89
+ * family pattern like `ops_.*` can only ever hit the full name (the bare name
90
+ * carries no `ops_` prefix), while a literal entry like `ops_bash` used to be
91
+ * dead on arrival against the bare name alone — the dual face repairs it as a
92
+ * side effect. The BUILT-IN table keeps its bare-name-only semantics (the
93
+ * issue #8 contract); only the extra lists gained the second face.
94
+ */
95
+ export interface SimpleToolMatcher {
96
+ test(name: string): boolean;
72
97
  }
98
+ /**
99
+ * Compile the two extra lists into one classifier, or `null` when both are
100
+ * empty (the built-in classification then stands alone). A compile is pure
101
+ * apart from the one-time `console.warn` for invalid regex entries — the
102
+ * cache keys on content, so the warning fires once per configuration, not
103
+ * once per request.
104
+ */
105
+ export declare function compileSimpleToolsMatcher(literal: readonly string[] | undefined, regex: readonly string[] | undefined): SimpleToolMatcher | null;
73
106
  /**
74
107
  * Map the user's selected level to the level injected into the next
75
108
  * `agent/request`. Manual levels (off / low / high / max) pass through
@@ -123,6 +156,11 @@ export interface EffortInjectionInput {
123
156
  * the `auto` scheduler (issue #8 `Config.simpleTools`).
124
157
  */
125
158
  extraSimpleTools?: readonly string[];
159
+ /**
160
+ * Extra raw regex patterns for the same set (issue #12
161
+ * `Config.simpleToolsRegex`), compiled as written, invalid ones skipped.
162
+ */
163
+ extraSimpleRegex?: readonly string[];
126
164
  /** The model's advertised effort ids (including plugin masks like `auto`). */
127
165
  efforts: readonly string[];
128
166
  /**
@@ -75,27 +75,68 @@ function escapeRe(source) {
75
75
  return source.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
76
76
  }
77
77
  /**
78
- * Compiled `extraSimpleTools` matchers, memoised by content. The config array
79
- * may be a fresh reference on every read (volatile `.get()`), so key on the
80
- * joined names rather than identity to avoid recompiling per request.
78
+ * Compiled matchers, memoised by content. The config arrays may be fresh
79
+ * references on every read (volatile `.get()`), so key on the joined contents
80
+ * rather than identity to avoid recompiling per request.
81
81
  */
82
- const EXTRA_SIMPLE_RE_CACHE = new Map();
83
- function compileExtraSimpleTools(tokens) {
84
- if (tokens === undefined || tokens.length === 0)
82
+ const SIMPLE_MATCHER_CACHE = new Map();
83
+ /**
84
+ * Compile the two extra lists into one classifier, or `null` when both are
85
+ * empty (the built-in classification then stands alone). A compile is pure
86
+ * apart from the one-time `console.warn` for invalid regex entries — the
87
+ * cache keys on content, so the warning fires once per configuration, not
88
+ * once per request.
89
+ */
90
+ export function compileSimpleToolsMatcher(literal, regex) {
91
+ const literalKey = (literal ?? []).join('\u0000');
92
+ const regexKey = (regex ?? []).join('\u0000');
93
+ if (literalKey === '' && regexKey === '')
85
94
  return null;
86
- const key = tokens.join('\u0000');
87
- const hit = EXTRA_SIMPLE_RE_CACHE.get(key);
95
+ const key = `${literalKey}\u0001${regexKey}`;
96
+ const hit = SIMPLE_MATCHER_CACHE.get(key);
88
97
  if (hit !== undefined)
89
98
  return hit;
90
- const cleaned = tokens.map(token => token.trim()).filter(token => token !== '');
91
- const re = cleaned.length === 0 ? null : new RegExp(`^(?:${cleaned.map(escapeRe).join('|')})(?:_|$)`, 'i');
92
- EXTRA_SIMPLE_RE_CACHE.set(key, re);
93
- return re;
99
+ const matcher = buildSimpleToolsMatcher(literal ?? [], regex ?? []);
100
+ SIMPLE_MATCHER_CACHE.set(key, matcher);
101
+ return matcher;
102
+ }
103
+ function buildSimpleToolsMatcher(literal, regex) {
104
+ const cleaned = literal.map(token => token.trim()).filter(token => token !== '');
105
+ const literalRe = cleaned.length === 0
106
+ ? null
107
+ : new RegExp(`^(?:${cleaned.map(escapeRe).join('|')})(?:_|$)`, 'i');
108
+ const rawRes = [];
109
+ const failed = [];
110
+ for (const pattern of regex) {
111
+ const trimmed = pattern.trim();
112
+ if (trimmed === '')
113
+ continue;
114
+ try {
115
+ rawRes.push(new RegExp(trimmed, 'i'));
116
+ }
117
+ catch {
118
+ failed.push(trimmed);
119
+ }
120
+ }
121
+ if (failed.length > 0) {
122
+ console.warn(`[dsh-thinking-levels] Config.simpleToolsRegex: skipped invalid pattern(s) (they must compile as JavaScript RegExp): ${failed.map(p => `/${p}/`).join(', ')}`);
123
+ }
124
+ if (literalRe === null && rawRes.length === 0)
125
+ return null;
126
+ return {
127
+ test(name) {
128
+ const bare = name.replace(TOOL_NAMESPACE_RE, '');
129
+ return (literalRe !== null && (literalRe.test(name) || literalRe.test(bare)))
130
+ || rawRes.some(re => re.test(name) || re.test(bare));
131
+ },
132
+ };
94
133
  }
95
- /** Whether a tool name (namespace prefix removed) looks cheap-and-deterministic. */
134
+ /** Whether a tool name looks cheap-and-deterministic: the built-in table reads
135
+ * the namespace-stripped bare name (issue #8 semantics, untouched); the extra
136
+ * matcher carries its own dual face (full name ∥ bare name, issue #12). */
96
137
  function isSimpleToolName(name, extra) {
97
138
  const bare = name.replace(TOOL_NAMESPACE_RE, '');
98
- return SIMPLE_TOOL_RE.test(bare) || (extra !== undefined && extra !== null && extra.test(bare));
139
+ return SIMPLE_TOOL_RE.test(bare) || (extra !== undefined && extra !== null && extra.test(name));
99
140
  }
100
141
  /** Count how many of the recent calls look cheap-and-deterministic. */
101
142
  function simpleRatio(calls, extra) {
@@ -155,10 +196,10 @@ function scheduleEffort(calls, allowDowngrade, allowUpgrade, extra) {
155
196
  * @returns The level to inject; `auto` is resolved before returning.
156
197
  */
157
198
  export function decideEffort(input) {
158
- const { recentCalls, selected, allowDowngrade, allowUpgrade, extraSimpleTools } = input;
199
+ const { recentCalls, selected, allowDowngrade, allowUpgrade, extraSimpleTools, extraSimpleRegex } = input;
159
200
  if (selected !== 'auto')
160
201
  return selected;
161
- return scheduleEffort(recentCalls, allowDowngrade, allowUpgrade, compileExtraSimpleTools(extraSimpleTools));
202
+ return scheduleEffort(recentCalls, allowDowngrade, allowUpgrade, compileSimpleToolsMatcher(extraSimpleTools, extraSimpleRegex));
162
203
  }
163
204
  /**
164
205
  * Whether a model's resolved metadata advertises reasoning-effort support.
@@ -252,6 +293,7 @@ export function resolveEffortInjection(input) {
252
293
  allowDowngrade: input.allowDowngrade,
253
294
  allowUpgrade: input.allowUpgrade,
254
295
  extraSimpleTools: input.extraSimpleTools,
296
+ extraSimpleRegex: input.extraSimpleRegex,
255
297
  });
256
298
  const clamped = clampToEfforts(level, efforts);
257
299
  return clamped === undefined ? { inject: false } : { inject: true, level: clamped };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-thinking-levels",
3
- "version": "4.5.0",
3
+ "version": "4.6.0",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org",
6
6
  "access": "public",