@trazum/core 1.8.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/LICENSE +21 -0
- package/README.md +163 -0
- package/dist/advisories.d.ts +23 -0
- package/dist/advisories.d.ts.map +1 -0
- package/dist/advisories.js +376 -0
- package/dist/advisories.js.map +1 -0
- package/dist/aws-sigv4.d.ts +88 -0
- package/dist/aws-sigv4.d.ts.map +1 -0
- package/dist/aws-sigv4.js +117 -0
- package/dist/aws-sigv4.js.map +1 -0
- package/dist/baseline.d.ts +171 -0
- package/dist/baseline.d.ts.map +1 -0
- package/dist/baseline.js +273 -0
- package/dist/baseline.js.map +1 -0
- package/dist/cache.d.ts +26 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +28 -0
- package/dist/cache.js.map +1 -0
- package/dist/changes.d.ts +29 -0
- package/dist/changes.d.ts.map +1 -0
- package/dist/changes.js +142 -0
- package/dist/changes.js.map +1 -0
- package/dist/compare.d.ts +65 -0
- package/dist/compare.d.ts.map +1 -0
- package/dist/compare.js +58 -0
- package/dist/compare.js.map +1 -0
- package/dist/config-schema.d.ts +118 -0
- package/dist/config-schema.d.ts.map +1 -0
- package/dist/config-schema.js +315 -0
- package/dist/config-schema.js.map +1 -0
- package/dist/config.d.ts +47 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +112 -0
- package/dist/config.js.map +1 -0
- package/dist/detect.d.ts +70 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/detect.js +228 -0
- package/dist/detect.js.map +1 -0
- package/dist/evaluate.d.ts +98 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +110 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/extract.d.ts +81 -0
- package/dist/extract.d.ts.map +1 -0
- package/dist/extract.js +280 -0
- package/dist/extract.js.map +1 -0
- package/dist/gcp-auth.d.ts +58 -0
- package/dist/gcp-auth.d.ts.map +1 -0
- package/dist/gcp-auth.js +113 -0
- package/dist/gcp-auth.js.map +1 -0
- package/dist/glob.d.ts +49 -0
- package/dist/glob.d.ts.map +1 -0
- package/dist/glob.js +154 -0
- package/dist/glob.js.map +1 -0
- package/dist/host.d.ts +30 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +69 -0
- package/dist/host.js.map +1 -0
- package/dist/i18n/en.d.ts +4 -0
- package/dist/i18n/en.d.ts.map +1 -0
- package/dist/i18n/en.js +168 -0
- package/dist/i18n/en.js.map +1 -0
- package/dist/i18n/es.d.ts +4 -0
- package/dist/i18n/es.d.ts.map +1 -0
- package/dist/i18n/es.js +168 -0
- package/dist/i18n/es.js.map +1 -0
- package/dist/i18n/index.d.ts +36 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +50 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/types.d.ts +180 -0
- package/dist/i18n/types.d.ts.map +1 -0
- package/dist/i18n/types.js +11 -0
- package/dist/i18n/types.js.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/llm.d.ts +226 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +485 -0
- package/dist/llm.js.map +1 -0
- package/dist/nearest.d.ts +20 -0
- package/dist/nearest.d.ts.map +1 -0
- package/dist/nearest.js +54 -0
- package/dist/nearest.js.map +1 -0
- package/dist/net.d.ts +90 -0
- package/dist/net.d.ts.map +1 -0
- package/dist/net.js +203 -0
- package/dist/net.js.map +1 -0
- package/dist/node.d.ts +32 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +33 -0
- package/dist/node.js.map +1 -0
- package/dist/openrouter.d.ts +25 -0
- package/dist/openrouter.d.ts.map +1 -0
- package/dist/openrouter.js +72 -0
- package/dist/openrouter.js.map +1 -0
- package/dist/optimize.d.ts +38 -0
- package/dist/optimize.d.ts.map +1 -0
- package/dist/optimize.js +183 -0
- package/dist/optimize.js.map +1 -0
- package/dist/otlp.d.ts +91 -0
- package/dist/otlp.d.ts.map +1 -0
- package/dist/otlp.js +102 -0
- package/dist/otlp.js.map +1 -0
- package/dist/phrases.d.ts +169 -0
- package/dist/phrases.d.ts.map +1 -0
- package/dist/phrases.js +939 -0
- package/dist/phrases.js.map +1 -0
- package/dist/pricing-overlay.d.ts +55 -0
- package/dist/pricing-overlay.d.ts.map +1 -0
- package/dist/pricing-overlay.js +241 -0
- package/dist/pricing-overlay.js.map +1 -0
- package/dist/pricing.d.ts +115 -0
- package/dist/pricing.d.ts.map +1 -0
- package/dist/pricing.js +400 -0
- package/dist/pricing.js.map +1 -0
- package/dist/profile.d.ts +71 -0
- package/dist/profile.d.ts.map +1 -0
- package/dist/profile.js +55 -0
- package/dist/profile.js.map +1 -0
- package/dist/promptfoo.d.ts +58 -0
- package/dist/promptfoo.d.ts.map +1 -0
- package/dist/promptfoo.js +149 -0
- package/dist/promptfoo.js.map +1 -0
- package/dist/prune.d.ts +91 -0
- package/dist/prune.d.ts.map +1 -0
- package/dist/prune.js +110 -0
- package/dist/prune.js.map +1 -0
- package/dist/reorder.d.ts +82 -0
- package/dist/reorder.d.ts.map +1 -0
- package/dist/reorder.js +215 -0
- package/dist/reorder.js.map +1 -0
- package/dist/review.d.ts +54 -0
- package/dist/review.d.ts.map +1 -0
- package/dist/review.js +131 -0
- package/dist/review.js.map +1 -0
- package/dist/rules.d.ts +5 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/rules.js +279 -0
- package/dist/rules.js.map +1 -0
- package/dist/savings.d.ts +36 -0
- package/dist/savings.d.ts.map +1 -0
- package/dist/savings.js +83 -0
- package/dist/savings.js.map +1 -0
- package/dist/segment.d.ts +8 -0
- package/dist/segment.d.ts.map +1 -0
- package/dist/segment.js +74 -0
- package/dist/segment.js.map +1 -0
- package/dist/shared-prefix.d.ts +63 -0
- package/dist/shared-prefix.d.ts.map +1 -0
- package/dist/shared-prefix.js +151 -0
- package/dist/shared-prefix.js.map +1 -0
- package/dist/similarity.d.ts +13 -0
- package/dist/similarity.d.ts.map +1 -0
- package/dist/similarity.js +30 -0
- package/dist/similarity.js.map +1 -0
- package/dist/structure.d.ts +144 -0
- package/dist/structure.d.ts.map +1 -0
- package/dist/structure.js +455 -0
- package/dist/structure.js.map +1 -0
- package/dist/suggest.d.ts +100 -0
- package/dist/suggest.d.ts.map +1 -0
- package/dist/suggest.js +151 -0
- package/dist/suggest.js.map +1 -0
- package/dist/tokenizer.d.ts +57 -0
- package/dist/tokenizer.d.ts.map +1 -0
- package/dist/tokenizer.js +157 -0
- package/dist/tokenizer.js.map +1 -0
- package/dist/types.d.ts +296 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/walk.d.ts +40 -0
- package/dist/walk.d.ts.map +1 -0
- package/dist/walk.js +95 -0
- package/dist/walk.js.map +1 -0
- package/package.json +56 -0
- package/src/advisories.ts +431 -0
- package/src/aws-sigv4.ts +174 -0
- package/src/baseline.ts +390 -0
- package/src/cache.ts +54 -0
- package/src/changes.ts +158 -0
- package/src/compare.ts +131 -0
- package/src/config-schema.ts +451 -0
- package/src/config.ts +161 -0
- package/src/detect.ts +312 -0
- package/src/evaluate.ts +188 -0
- package/src/extract.ts +336 -0
- package/src/gcp-auth.ts +166 -0
- package/src/glob.ts +160 -0
- package/src/host.ts +90 -0
- package/src/i18n/en.ts +236 -0
- package/src/i18n/es.ts +236 -0
- package/src/i18n/index.ts +68 -0
- package/src/i18n/types.ts +230 -0
- package/src/index.ts +228 -0
- package/src/llm.ts +708 -0
- package/src/nearest.ts +61 -0
- package/src/net.ts +233 -0
- package/src/node.ts +63 -0
- package/src/openrouter.ts +125 -0
- package/src/optimize.ts +228 -0
- package/src/otlp.ts +179 -0
- package/src/phrases.ts +1047 -0
- package/src/pricing-overlay.ts +319 -0
- package/src/pricing.ts +468 -0
- package/src/profile.ts +124 -0
- package/src/promptfoo.ts +213 -0
- package/src/prune.ts +211 -0
- package/src/reorder.ts +307 -0
- package/src/review.ts +180 -0
- package/src/rules.ts +324 -0
- package/src/savings.ts +121 -0
- package/src/segment.ts +106 -0
- package/src/shared-prefix.ts +198 -0
- package/src/similarity.ts +28 -0
- package/src/structure.ts +652 -0
- package/src/suggest.ts +254 -0
- package/src/tokenizer.ts +190 -0
- package/src/types.ts +323 -0
- package/src/walk.ts +117 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseline.js","sourceRoot":"","sources":["../src/baseline.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAElC,MAAM,CAAC,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AAExD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAyBlD,MAAM,OAAO,aAAc,SAAQ,KAAK;IAG3B,MAAM;IAFjB,YACE,OAAe,EACN,MAAc;QAEvB,KAAK,CAAC,GAAG,MAAM,KAAK,OAAO,EAAE,CAAC,CAAC;sBAFtB,MAAM;QAGf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,GAAG,2BAA2B,CAAC;AAEhD,MAAM,aAAa,GAAG,CAAC,KAAc,EAAoC,EAAE,CACzE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEvE,SAAS,iBAAiB,CAAC,KAAc,EAAE,KAAa,EAAE,MAAc;IACtE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QACvE,MAAM,IA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,YAAY,EAAE,CAAC;QAC3F,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC3F,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAC/B,QAA0B,EAC1B,QAAsB,EACtB,eAAuB;IAEvB,MAAM,eAAe,GACnB,QAAQ,CAAC,QAAQ,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK;QAC1C,QAAQ,CAAC,QAAQ,CAAC,aAAa,KAAK,QAAQ,CAAC,aAAa;QAC1D,QAAQ,CAAC,QAAQ,CAAC,eAAe,KAAK,QAAQ,CAAC,eAAe;QAC9D,QAAQ,CAAC,QAAQ,CAAC,YAAY,KAAK,QAAQ,CAAC,YAAY;QACxD,QAAQ,CAAC,QAAQ,CAAC,aAAa,KAAK,QAAQ,CAAC,aAAa,CAAC;IAC7D,MAAM,cAAc,GAAG,QAAQ,CAAC,eAAe,KAAK,eAAe,CAAC;IAEpE,OAAO,EAAE,UAAU,EAAE,CAAC,eAAe,IAAI,CAAC,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC;AAC9F,CAAC"}
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { TokenCounter } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Cacheable-prefix analysis.
|
|
4
|
+
*
|
|
5
|
+
* Prompt caching is a byte-for-byte prefix match, so as soon as a template
|
|
6
|
+
* placeholder ({{user}}, ${query}...) is filled with a different value,
|
|
7
|
+
* everything after it stops being cached. The real cacheable prefix of a
|
|
8
|
+
* template is therefore NOT the whole prompt, but whatever precedes the first
|
|
9
|
+
* variable placeholder.
|
|
10
|
+
*/
|
|
11
|
+
export interface CachePrefixAnalysis {
|
|
12
|
+
/** Total tokens in the prompt. */
|
|
13
|
+
totalTokens: number;
|
|
14
|
+
/** Tokens before the first variable placeholder. With no placeholders, the total. */
|
|
15
|
+
stablePrefixTokens: number;
|
|
16
|
+
/** Text of the first variable placeholder, or `null` when there is none. */
|
|
17
|
+
firstPlaceholder: string | null;
|
|
18
|
+
/**
|
|
19
|
+
* Tokens of NON-placeholder content sitting after the first placeholder:
|
|
20
|
+
* stable instructions that are not cached today and that would be cached if
|
|
21
|
+
* moved ahead of the first placeholder.
|
|
22
|
+
*/
|
|
23
|
+
staticTokensAfter: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function analyzeCachePrefix(prompt: string, count: TokenCounter): CachePrefixAnalysis;
|
|
26
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;;;GAQG;AACH,MAAM,WAAW,mBAAmB;IAClC,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAC;IACpB,qFAAqF;IACrF,kBAAkB,EAAE,MAAM,CAAC;IAC3B,4EAA4E;IAC5E,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC;;;;OAIG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,mBAAmB,CA0B3F"}
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { segment } from './segment.js';
|
|
2
|
+
export function analyzeCachePrefix(prompt, count) {
|
|
3
|
+
const segments = segment(prompt);
|
|
4
|
+
const totalTokens = count(prompt);
|
|
5
|
+
let firstPlaceholder = null;
|
|
6
|
+
let prefix = '';
|
|
7
|
+
let staticAfter = '';
|
|
8
|
+
for (const seg of segments) {
|
|
9
|
+
if (firstPlaceholder === null) {
|
|
10
|
+
if (seg.kind === 'protected' && seg.protection === 'placeholder') {
|
|
11
|
+
firstPlaceholder = seg.text;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
prefix += seg.text;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else if (!(seg.kind === 'protected' && seg.protection === 'placeholder')) {
|
|
18
|
+
staticAfter += seg.text;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
totalTokens,
|
|
23
|
+
stablePrefixTokens: firstPlaceholder === null ? totalTokens : count(prefix),
|
|
24
|
+
firstPlaceholder,
|
|
25
|
+
staticTokensAfter: firstPlaceholder === null ? 0 : count(staticAfter),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AA2BvC,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,KAAmB;IACpE,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IAElC,IAAI,gBAAgB,GAAkB,IAAI,CAAC;IAC3C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,WAAW,GAAG,EAAE,CAAC;IAErB,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,IAAI,gBAAgB,KAAK,IAAI,EAAE,CAAC;YAC9B,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW,IAAI,GAAG,CAAC,UAAU,KAAK,aAAa,EAAE,CAAC;gBACjE,gBAAgB,GAAG,GAAG,CAAC,IAAI,CAAC;YAC9B,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC;YACrB,CAAC;QACH,CAAC;aAAM,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,WAAW,IAAI,GAAG,CAAC,UAAU,KAAK,aAAa,CAAC,EAAE,CAAC;YAC3E,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,OAAO;QACL,WAAW;QACX,kBAAkB,EAAE,gBAAgB,KAAK,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC;QAC3E,gBAAgB;QAChB,iBAAiB,EAAE,gBAAgB,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC;KACtE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-rule change extraction.
|
|
3
|
+
*
|
|
4
|
+
* The report says a rule fired four times and saved nineteen tokens. That is
|
|
5
|
+
* enough to trust the `safe` level and nowhere near enough to review the
|
|
6
|
+
* `aggressive` one, where the honest advice has always been "read the diff" —
|
|
7
|
+
* and the diff was one undifferentiated block for every rule at once.
|
|
8
|
+
*
|
|
9
|
+
* This turns each rule into its own short list of "this became that", so an
|
|
10
|
+
* aggressive run can be judged rule by rule and a single bad rule disabled
|
|
11
|
+
* with `--disable`, instead of the whole level.
|
|
12
|
+
*/
|
|
13
|
+
export interface RuleChange {
|
|
14
|
+
/** The text the rule removed or replaced. */
|
|
15
|
+
before: string;
|
|
16
|
+
/** What it became. Empty when the text was simply deleted. */
|
|
17
|
+
after: string;
|
|
18
|
+
}
|
|
19
|
+
/** Changes reported per rule. The hit count carries the true total. */
|
|
20
|
+
export declare const DEFAULT_CHANGE_LIMIT = 5;
|
|
21
|
+
/**
|
|
22
|
+
* Extracts what a rule changed, as a short list of before/after pairs.
|
|
23
|
+
*
|
|
24
|
+
* Returns an empty list rather than a partial one when the change is too large
|
|
25
|
+
* to summarise usefully — an empty list reads as "nothing to show here", which
|
|
26
|
+
* is honest, where a truncated one would read as "this is all that happened".
|
|
27
|
+
*/
|
|
28
|
+
export declare function extractChanges(before: string, after: string, limit?: number): RuleChange[];
|
|
29
|
+
//# sourceMappingURL=changes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changes.d.ts","sourceRoot":"","sources":["../src/changes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,KAAK,EAAE,MAAM,CAAC;CACf;AAeD,uEAAuE;AACvE,eAAO,MAAM,oBAAoB,IAAI,CAAC;AA2CtC;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,KAAK,GAAE,MAA6B,GACnC,UAAU,EAAE,CAqEd"}
|
package/dist/changes.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-rule change extraction.
|
|
3
|
+
*
|
|
4
|
+
* The report says a rule fired four times and saved nineteen tokens. That is
|
|
5
|
+
* enough to trust the `safe` level and nowhere near enough to review the
|
|
6
|
+
* `aggressive` one, where the honest advice has always been "read the diff" —
|
|
7
|
+
* and the diff was one undifferentiated block for every rule at once.
|
|
8
|
+
*
|
|
9
|
+
* This turns each rule into its own short list of "this became that", so an
|
|
10
|
+
* aggressive run can be judged rule by rule and a single bad rule disabled
|
|
11
|
+
* with `--disable`, instead of the whole level.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Longest run of text either side will be diffed word by word.
|
|
15
|
+
*
|
|
16
|
+
* Everything here runs on attacker-controlled input, so the cost has to be
|
|
17
|
+
* bounded by construction rather than by hoping prompts are small. The common
|
|
18
|
+
* prefix and suffix are trimmed first, which is linear and usually leaves very
|
|
19
|
+
* little, but a rule that edits in a hundred scattered places leaves a middle
|
|
20
|
+
* as long as the prompt. Past this size the extraction is skipped: a list of
|
|
21
|
+
* changes that long is not something anyone reads anyway, and the hit count
|
|
22
|
+
* already says how much happened.
|
|
23
|
+
*/
|
|
24
|
+
const MAX_DIFF_CHARS = 4000;
|
|
25
|
+
/** Changes reported per rule. The hit count carries the true total. */
|
|
26
|
+
export const DEFAULT_CHANGE_LIMIT = 5;
|
|
27
|
+
function splitWords(text) {
|
|
28
|
+
return text.match(/\s+|[^\s]+/g) ?? [];
|
|
29
|
+
}
|
|
30
|
+
/** Length of the common prefix, in characters. */
|
|
31
|
+
function commonPrefix(a, b) {
|
|
32
|
+
const max = Math.min(a.length, b.length);
|
|
33
|
+
let i = 0;
|
|
34
|
+
while (i < max && a[i] === b[i])
|
|
35
|
+
i++;
|
|
36
|
+
return i;
|
|
37
|
+
}
|
|
38
|
+
/** Length of the common suffix, in characters, not overlapping `start`. */
|
|
39
|
+
function commonSuffix(a, b, start) {
|
|
40
|
+
const max = Math.min(a.length, b.length) - start;
|
|
41
|
+
let i = 0;
|
|
42
|
+
while (i < max && a[a.length - 1 - i] === b[b.length - 1 - i])
|
|
43
|
+
i++;
|
|
44
|
+
return i;
|
|
45
|
+
}
|
|
46
|
+
/** Walks a prefix length back to the start of the word it lands inside. */
|
|
47
|
+
function toWordStart(text, length) {
|
|
48
|
+
let i = length;
|
|
49
|
+
while (i > 0 && !/\s/.test(text[i - 1]))
|
|
50
|
+
i--;
|
|
51
|
+
return i;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Shrinks a suffix until it begins at a word boundary.
|
|
55
|
+
*
|
|
56
|
+
* Shrinking rather than growing is the whole point: the common suffix is only
|
|
57
|
+
* common up to the length `commonSuffix` found, so extending it past that
|
|
58
|
+
* would claim two different strings match. Pulling it back instead keeps the
|
|
59
|
+
* guarantee and hands the partial word to the diff, where it belongs.
|
|
60
|
+
*/
|
|
61
|
+
function toWordEnd(before, length) {
|
|
62
|
+
let i = length;
|
|
63
|
+
while (i > 0 && !/\s/.test(before[before.length - i]))
|
|
64
|
+
i--;
|
|
65
|
+
return i;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Extracts what a rule changed, as a short list of before/after pairs.
|
|
69
|
+
*
|
|
70
|
+
* Returns an empty list rather than a partial one when the change is too large
|
|
71
|
+
* to summarise usefully — an empty list reads as "nothing to show here", which
|
|
72
|
+
* is honest, where a truncated one would read as "this is all that happened".
|
|
73
|
+
*/
|
|
74
|
+
export function extractChanges(before, after, limit = DEFAULT_CHANGE_LIMIT) {
|
|
75
|
+
if (before === after)
|
|
76
|
+
return [];
|
|
77
|
+
// Rules make local edits, so trimming the shared ends first usually leaves a
|
|
78
|
+
// middle small enough to diff properly — and does it in linear time.
|
|
79
|
+
//
|
|
80
|
+
// The trim is by character but the diff is by word, so both boundaries are
|
|
81
|
+
// pushed back out to whitespace. Without that the middle starts mid-word and
|
|
82
|
+
// the change reads as gibberish: removing "quite" from "be quite accurate"
|
|
83
|
+
// reported itself as `be quit → b`, which is accurate, useless, and worse
|
|
84
|
+
// than showing nothing.
|
|
85
|
+
const start = toWordStart(before, commonPrefix(before, after));
|
|
86
|
+
const end = toWordEnd(before, commonSuffix(before, after, start));
|
|
87
|
+
const beforeMiddle = before.slice(start, before.length - end);
|
|
88
|
+
const afterMiddle = after.slice(start, after.length - end);
|
|
89
|
+
if (beforeMiddle.length > MAX_DIFF_CHARS || afterMiddle.length > MAX_DIFF_CHARS) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
const a = splitWords(beforeMiddle);
|
|
93
|
+
const b = splitWords(afterMiddle);
|
|
94
|
+
// Longest common subsequence over words, to align the two sides.
|
|
95
|
+
const rows = a.length + 1;
|
|
96
|
+
const cols = b.length + 1;
|
|
97
|
+
const table = new Int32Array(rows * cols);
|
|
98
|
+
for (let i = a.length - 1; i >= 0; i--) {
|
|
99
|
+
for (let j = b.length - 1; j >= 0; j--) {
|
|
100
|
+
table[i * cols + j] =
|
|
101
|
+
a[i] === b[j]
|
|
102
|
+
? table[(i + 1) * cols + (j + 1)] + 1
|
|
103
|
+
: Math.max(table[(i + 1) * cols + j], table[i * cols + (j + 1)]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const changes = [];
|
|
107
|
+
let removed = '';
|
|
108
|
+
let added = '';
|
|
109
|
+
const flush = () => {
|
|
110
|
+
if (!removed && !added)
|
|
111
|
+
return;
|
|
112
|
+
// Whitespace-only churn is not a change anyone needs to review; the
|
|
113
|
+
// whitespace rule's hit count already reports it.
|
|
114
|
+
if (removed.trim() || added.trim()) {
|
|
115
|
+
changes.push({ before: removed.trim(), after: added.trim() });
|
|
116
|
+
}
|
|
117
|
+
removed = '';
|
|
118
|
+
added = '';
|
|
119
|
+
};
|
|
120
|
+
let i = 0;
|
|
121
|
+
let j = 0;
|
|
122
|
+
while (i < a.length && j < b.length) {
|
|
123
|
+
if (a[i] === b[j]) {
|
|
124
|
+
flush();
|
|
125
|
+
i++;
|
|
126
|
+
j++;
|
|
127
|
+
}
|
|
128
|
+
else if (table[(i + 1) * cols + j] >= table[i * cols + (j + 1)]) {
|
|
129
|
+
removed += a[i++];
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
added += b[j++];
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
while (i < a.length)
|
|
136
|
+
removed += a[i++];
|
|
137
|
+
while (j < b.length)
|
|
138
|
+
added += b[j++];
|
|
139
|
+
flush();
|
|
140
|
+
return changes.slice(0, limit);
|
|
141
|
+
}
|
|
142
|
+
//# sourceMappingURL=changes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"changes.js","sourceRoot":"","sources":["../src/changes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AASH;;;;;;;;;;GAUG;AACH,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B,uEAAuE;AACvE,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAA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AAC;QACD,OAAO,GAAG,EAAE,CAAC;QACb,KAAK,GAAG,EAAE,CAAC;IACb,CAAC,CAAC;IAEF,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC;QACpC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAClB,KAAK,EAAE,CAAC;YACR,CAAC,EAAE,CAAC;YACJ,CAAC,EAAE,CAAC;QACN,CAAC;aAAM,IAAI,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAE,IAAI,KAAK,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAE,EAAE,CAAC;YACpE,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACpB,CAAC;aAAM,CAAC;YACN,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACvC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM;QAAE,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACrC,KAAK,EAAE,CAAC;IAER,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { AdvisoryId, RuleId } from './types.js';
|
|
2
|
+
import type { OptimizeOptions, UsageProfile } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Comparing two versions of a prompt.
|
|
5
|
+
*
|
|
6
|
+
* `optimize()` answers "how much fat is in this prompt". This answers a
|
|
7
|
+
* different question, and the one a pull request actually raises: "somebody
|
|
8
|
+
* edited this — did it get worse?"
|
|
9
|
+
*
|
|
10
|
+
* Sign convention, stated once and held everywhere: **every number here is a
|
|
11
|
+
* delta, `after - before`, and positive means the change made things worse.**
|
|
12
|
+
* That is deliberately the opposite of the rest of the codebase, where every
|
|
13
|
+
* figure is a saving. Mixing the two conventions in one report is the single
|
|
14
|
+
* easiest way to make a cost tool lie, so nothing in this module is called a
|
|
15
|
+
* saving and nothing reuses that name.
|
|
16
|
+
*/
|
|
17
|
+
export interface RuleDelta {
|
|
18
|
+
/** Rules that fire on the new version but did not on the old one. */
|
|
19
|
+
newlyFiring: RuleId[];
|
|
20
|
+
/** Rules that fired on the old version and no longer do. */
|
|
21
|
+
noLongerFiring: RuleId[];
|
|
22
|
+
}
|
|
23
|
+
export interface AdvisoryDelta {
|
|
24
|
+
/** Advisories the new version raises that the old one did not. */
|
|
25
|
+
appeared: AdvisoryId[];
|
|
26
|
+
/** Advisories the old version raised that the new one has resolved. */
|
|
27
|
+
resolved: AdvisoryId[];
|
|
28
|
+
}
|
|
29
|
+
export interface PromptComparison {
|
|
30
|
+
tokensBefore: number;
|
|
31
|
+
tokensAfter: number;
|
|
32
|
+
/** `after - before`. Positive means the prompt grew. */
|
|
33
|
+
tokenDelta: number;
|
|
34
|
+
/** The delta as a percentage of the old size. 0 when the old size was 0. */
|
|
35
|
+
deltaPct: number;
|
|
36
|
+
/** Monthly cost change in USD. Positive means it now costs more. */
|
|
37
|
+
monthlyDeltaUsd: number;
|
|
38
|
+
/** Per-call cost change in USD. Positive means it now costs more. */
|
|
39
|
+
perCallDeltaUsd: number;
|
|
40
|
+
rules: RuleDelta;
|
|
41
|
+
advisories: AdvisoryDelta;
|
|
42
|
+
usage: UsageProfile;
|
|
43
|
+
}
|
|
44
|
+
export interface CompareOptions extends OptimizeOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Compare what the rules would leave, rather than what was written.
|
|
47
|
+
*
|
|
48
|
+
* Off by default, and that default matters: a pull request changed the file
|
|
49
|
+
* on disk, so the file on disk is what the reviewer is being asked about.
|
|
50
|
+
* Optimising both sides first would hide a prompt that doubled in length but
|
|
51
|
+
* happened to double in courtesy, which is exactly the change worth seeing.
|
|
52
|
+
*/
|
|
53
|
+
optimizeBoth?: boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Compares two prompt versions.
|
|
57
|
+
*
|
|
58
|
+
* Both sides go through `optimize()` regardless, because that is what produces
|
|
59
|
+
* the rule and advisory findings — but by default the *token and cost figures*
|
|
60
|
+
* come from the text as written. `optimizeBoth` switches the figures to the
|
|
61
|
+
* optimised text, for a team that runs Trazum in their pipeline and cares
|
|
62
|
+
* about what actually reaches the model.
|
|
63
|
+
*/
|
|
64
|
+
export declare function comparePrompts(before: string, after: string, options?: CompareOptions): PromptComparison;
|
|
65
|
+
//# sourceMappingURL=compare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../src/compare.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEhE;;;;;;;;;;;;;GAaG;AAEH,MAAM,WAAW,SAAS;IACxB,qEAAqE;IACrE,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,4DAA4D;IAC5D,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,QAAQ,EAAE,UAAU,EAAE,CAAC;IACvB,uEAAuE;IACvE,QAAQ,EAAE,UAAU,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,eAAe,EAAE,MAAM,CAAC;IACxB,qEAAqE;IACrE,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,SAAS,CAAC;IACjB,UAAU,EAAE,aAAa,CAAC;IAC1B,KAAK,EAAE,YAAY,CAAC;CACrB;AAED,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAgBD;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,cAAmB,GAC3B,gBAAgB,CAyClB"}
|
package/dist/compare.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { optimize } from './optimize.js';
|
|
2
|
+
import { computeSavings } from './savings.js';
|
|
3
|
+
const difference = (a, b) => {
|
|
4
|
+
const inB = new Set(b);
|
|
5
|
+
return a.filter((item) => !inB.has(item));
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Collapses negative zero.
|
|
9
|
+
*
|
|
10
|
+
* Negating a saving of zero produces `-0`, which is arithmetically fine and
|
|
11
|
+
* renders as `-$0` in a cost report — a change that did not happen, shown with
|
|
12
|
+
* a direction.
|
|
13
|
+
*/
|
|
14
|
+
const noNegativeZero = (value) => (value === 0 ? 0 : value);
|
|
15
|
+
/**
|
|
16
|
+
* Compares two prompt versions.
|
|
17
|
+
*
|
|
18
|
+
* Both sides go through `optimize()` regardless, because that is what produces
|
|
19
|
+
* the rule and advisory findings — but by default the *token and cost figures*
|
|
20
|
+
* come from the text as written. `optimizeBoth` switches the figures to the
|
|
21
|
+
* optimised text, for a team that runs Trazum in their pipeline and cares
|
|
22
|
+
* about what actually reaches the model.
|
|
23
|
+
*/
|
|
24
|
+
export function comparePrompts(before, after, options = {}) {
|
|
25
|
+
const { optimizeBoth = false, ...optimizeOptions } = options;
|
|
26
|
+
const beforeResult = optimize(before, optimizeOptions);
|
|
27
|
+
const afterResult = optimize(after, optimizeOptions);
|
|
28
|
+
const tokensBefore = optimizeBoth ? beforeResult.tokensAfter : beforeResult.tokensBefore;
|
|
29
|
+
const tokensAfter = optimizeBoth ? afterResult.tokensAfter : afterResult.tokensBefore;
|
|
30
|
+
const tokenDelta = tokensAfter - tokensBefore;
|
|
31
|
+
const usage = afterResult.usage;
|
|
32
|
+
// computeSavings is before-minus-after, so its "saving" is our delta with
|
|
33
|
+
// the sign flipped. Negating once, here, is what keeps the convention above
|
|
34
|
+
// true everywhere else.
|
|
35
|
+
const savings = computeSavings(tokensBefore, tokensAfter, usage);
|
|
36
|
+
const beforeRules = beforeResult.rules.map((r) => r.id);
|
|
37
|
+
const afterRules = afterResult.rules.map((r) => r.id);
|
|
38
|
+
const beforeAdvisories = beforeResult.advisories.map((a) => a.id);
|
|
39
|
+
const afterAdvisories = afterResult.advisories.map((a) => a.id);
|
|
40
|
+
return {
|
|
41
|
+
tokensBefore,
|
|
42
|
+
tokensAfter,
|
|
43
|
+
tokenDelta,
|
|
44
|
+
deltaPct: tokensBefore > 0 ? (tokenDelta / tokensBefore) * 100 : 0,
|
|
45
|
+
monthlyDeltaUsd: noNegativeZero(-savings.monthlySavingsUsd),
|
|
46
|
+
perCallDeltaUsd: noNegativeZero(savings.perCall.after.totalUsd - savings.perCall.before.totalUsd),
|
|
47
|
+
rules: {
|
|
48
|
+
newlyFiring: difference(afterRules, beforeRules),
|
|
49
|
+
noLongerFiring: difference(beforeRules, afterRules),
|
|
50
|
+
},
|
|
51
|
+
advisories: {
|
|
52
|
+
appeared: difference(afterAdvisories, beforeAdvisories),
|
|
53
|
+
resolved: difference(beforeAdvisories, afterAdvisories),
|
|
54
|
+
},
|
|
55
|
+
usage,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { PricingCatalogue } from './pricing.js';
|
|
2
|
+
import type { Locale } from './i18n/index.js';
|
|
3
|
+
import type { RuleId, RuleLevel, UsageProfile } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* The shape and validation of `trazum.config.json`. No filesystem access — the
|
|
6
|
+
* loader that reads the file lives in `config.ts`, which is only reachable via
|
|
7
|
+
* `@trazum/core/node`. Keeping the schema pure is what lets the browser bundle
|
|
8
|
+
* import the types and key lists without dragging `node:fs` into its graph.
|
|
9
|
+
*
|
|
10
|
+
* The problem this solves is small and real: every command in a repository's CI
|
|
11
|
+
* repeats the same four flags, and the one place they get out of step is the
|
|
12
|
+
* place the numbers stop meaning anything.
|
|
13
|
+
*
|
|
14
|
+
* **Every validation failure here throws.** That is the whole design. A config
|
|
15
|
+
* file is trusted to carry a budget, and the failure mode of a lenient parser
|
|
16
|
+
* is a typo'd key silently ignored, defaults quietly restored, and a green
|
|
17
|
+
* build for a prompt nobody measured. An unreadable config is a loud error; a
|
|
18
|
+
* config that half-applies is a lie.
|
|
19
|
+
*/
|
|
20
|
+
export declare const CONFIG_FILENAME = "trazum.config.json";
|
|
21
|
+
/**
|
|
22
|
+
* Largest config file this will read.
|
|
23
|
+
*
|
|
24
|
+
* A config is a couple of dozen lines. This exists so a hostile or accidental
|
|
25
|
+
* multi-megabyte file is refused before `JSON.parse` is handed the whole thing.
|
|
26
|
+
*/
|
|
27
|
+
export declare const MAX_CONFIG_BYTES: number;
|
|
28
|
+
/** How far up the tree the search for a config file will walk. */
|
|
29
|
+
export declare const MAX_CONFIG_SEARCH_DEPTH = 32;
|
|
30
|
+
export interface BaselineConfig {
|
|
31
|
+
/** Path to the baseline file, relative to the config. */
|
|
32
|
+
path: string;
|
|
33
|
+
/**
|
|
34
|
+
* Thresholds. At least one is required — see `parseBaselineConfig` for why a
|
|
35
|
+
* baseline with no threshold is a configuration error rather than a default.
|
|
36
|
+
*/
|
|
37
|
+
maxGrowthTokens?: number;
|
|
38
|
+
maxGrowthPct?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface TrazumConfig {
|
|
41
|
+
level?: RuleLevel;
|
|
42
|
+
locale?: Locale;
|
|
43
|
+
disable?: RuleId[];
|
|
44
|
+
usage?: Partial<UsageProfile>;
|
|
45
|
+
/**
|
|
46
|
+
* Token budgets by glob pattern. The most specific matching pattern wins —
|
|
47
|
+
* see `mostSpecificMatch`, which states what "specific" means rather than
|
|
48
|
+
* leaving it to be inferred.
|
|
49
|
+
*/
|
|
50
|
+
budgets?: Record<string, number>;
|
|
51
|
+
/** Default for `trazum diff --max-growth`, in tokens. */
|
|
52
|
+
maxGrowth?: number;
|
|
53
|
+
/**
|
|
54
|
+
* The cost baseline, and how much drift from it is tolerated.
|
|
55
|
+
*
|
|
56
|
+
* This is the difference between a ceiling and a gate. `budgets` asks whether
|
|
57
|
+
* a file fits; this asks whether the repository got worse than it was at the
|
|
58
|
+
* commit somebody recorded. Present in the config means `trazum check` in
|
|
59
|
+
* directory mode reads the baseline and gates on it without a flag — a gate
|
|
60
|
+
* you have to remember to pass an argument to is a gate that runs in the
|
|
61
|
+
* author's terminal and not in CI.
|
|
62
|
+
*/
|
|
63
|
+
baseline?: BaselineConfig;
|
|
64
|
+
/** File extensions directory mode treats as prompts. */
|
|
65
|
+
extensions?: string[];
|
|
66
|
+
/**
|
|
67
|
+
* Path to a pricing overlay, relative to the config file.
|
|
68
|
+
*
|
|
69
|
+
* Lets a project correct a published price without upgrading the library. The
|
|
70
|
+
* bundled catalogue stays the default; this only layers on top.
|
|
71
|
+
*/
|
|
72
|
+
pricing?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Every key the config accepts. Exported so the CLI's help can be tested
|
|
76
|
+
* against it rather than against a second hand-maintained list — a setting the
|
|
77
|
+
* help never mentions is one only the changelog knows about.
|
|
78
|
+
*/
|
|
79
|
+
export declare const CONFIG_KEYS: readonly ['level', 'locale', 'disable', 'usage', 'budgets', 'maxGrowth', 'baseline', 'extensions', 'pricing'];
|
|
80
|
+
export declare const CONFIG_BASELINE_KEYS: readonly ['path', 'maxGrowthTokens', 'maxGrowthPct'];
|
|
81
|
+
export declare const CONFIG_USAGE_KEYS: readonly ['model', 'callsPerMonth', 'avgOutputTokens', 'cacheHitRate', 'batchEligible'];
|
|
82
|
+
/** Extensions directory mode reads when the config does not say otherwise. */
|
|
83
|
+
export declare const DEFAULT_EXTENSIONS: string[];
|
|
84
|
+
export declare class ConfigError extends Error {
|
|
85
|
+
readonly source: string;
|
|
86
|
+
constructor(message: string, source: string);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Checks a config's `usage.model` against a resolved catalogue.
|
|
90
|
+
*
|
|
91
|
+
* Separate from `parseConfig` because it needs the catalogue, and the catalogue
|
|
92
|
+
* may be defined by the very document being parsed — `pricing` is a config key.
|
|
93
|
+
* `loadConfig` calls this once the overlay is in hand, so a typo'd model is still
|
|
94
|
+
* a loud error, just one raised at the point where "unknown model" can be
|
|
95
|
+
* answered truthfully.
|
|
96
|
+
*/
|
|
97
|
+
export declare function validateConfigModel(config: TrazumConfig, catalogue: PricingCatalogue, source: string): void;
|
|
98
|
+
/**
|
|
99
|
+
* Validates a config document.
|
|
100
|
+
*
|
|
101
|
+
* `source` names the file in every error, because a config error found while
|
|
102
|
+
* running `trazum check` in a monorepo is useless without knowing which of
|
|
103
|
+
* several config files it came from.
|
|
104
|
+
*/
|
|
105
|
+
export declare function parseConfig(raw: string, source?: string): TrazumConfig;
|
|
106
|
+
export interface ResolvedBudget {
|
|
107
|
+
/** The pattern the budget came from, so a surprising number can be traced. */
|
|
108
|
+
pattern: string;
|
|
109
|
+
maxTokens: number;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The budget that applies to a path, or null when no pattern matches.
|
|
113
|
+
*
|
|
114
|
+
* Returning the pattern alongside the number is the point: a file failing
|
|
115
|
+
* against a budget the reader cannot locate in their config is a bug report.
|
|
116
|
+
*/
|
|
117
|
+
export declare function budgetFor(path: string, budgets: Record<string, number> | undefined): ResolvedBudget | null;
|
|
118
|
+
//# sourceMappingURL=config-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config-schema.d.ts","sourceRoot":"","sources":["../src/config-schema.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAIrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAElE;;;;;;;;;;;;;;;GAeG;AAEH,eAAO,MAAM,eAAe,uBAAuB,CAAC;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAY,CAAC;AAE1C,kEAAkE;AAClE,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;;;OASG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;;;OAKG;IACH,OAAO,CAAC,EAA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