trimference 0.3.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/BENCHMARK.md +39 -0
- package/CHANGELOG.md +41 -0
- package/CONTRIBUTING.md +43 -0
- package/DEMO.md +106 -0
- package/LICENSE +21 -0
- package/README.md +268 -0
- package/SECURITY.md +17 -0
- package/action.yml +182 -0
- package/dist/baseline.d.ts +13 -0
- package/dist/baseline.d.ts.map +1 -0
- package/dist/baseline.js +23 -0
- package/dist/baseline.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +245 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +31 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +127 -0
- package/dist/config.js.map +1 -0
- package/dist/ecoLLM.d.ts +33 -0
- package/dist/ecoLLM.d.ts.map +1 -0
- package/dist/ecoLLM.js +98 -0
- package/dist/ecoLLM.js.map +1 -0
- package/dist/impact.d.ts +22 -0
- package/dist/impact.d.ts.map +1 -0
- package/dist/impact.js +80 -0
- package/dist/impact.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/models.d.ts +21 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +58 -0
- package/dist/models.js.map +1 -0
- package/dist/prComment.d.ts +36 -0
- package/dist/prComment.d.ts.map +1 -0
- package/dist/prComment.js +45 -0
- package/dist/prComment.js.map +1 -0
- package/dist/reporters/impactTracker.d.ts +21 -0
- package/dist/reporters/impactTracker.d.ts.map +1 -0
- package/dist/reporters/impactTracker.js +54 -0
- package/dist/reporters/impactTracker.js.map +1 -0
- package/dist/reporters/jsonReporter.d.ts +4 -0
- package/dist/reporters/jsonReporter.d.ts.map +1 -0
- package/dist/reporters/jsonReporter.js +34 -0
- package/dist/reporters/jsonReporter.js.map +1 -0
- package/dist/reporters/markdownReporter.d.ts +4 -0
- package/dist/reporters/markdownReporter.d.ts.map +1 -0
- package/dist/reporters/markdownReporter.js +97 -0
- package/dist/reporters/markdownReporter.js.map +1 -0
- package/dist/reporters/sarifReporter.d.ts +4 -0
- package/dist/reporters/sarifReporter.d.ts.map +1 -0
- package/dist/reporters/sarifReporter.js +63 -0
- package/dist/reporters/sarifReporter.js.map +1 -0
- package/dist/reporters/terminalReporter.d.ts +10 -0
- package/dist/reporters/terminalReporter.d.ts.map +1 -0
- package/dist/reporters/terminalReporter.js +80 -0
- package/dist/reporters/terminalReporter.js.map +1 -0
- package/dist/rules/agentLoopWithoutBudget.d.ts +3 -0
- package/dist/rules/agentLoopWithoutBudget.d.ts.map +1 -0
- package/dist/rules/agentLoopWithoutBudget.js +105 -0
- package/dist/rules/agentLoopWithoutBudget.js.map +1 -0
- package/dist/rules/expensiveModelSimpleTask.d.ts +3 -0
- package/dist/rules/expensiveModelSimpleTask.d.ts.map +1 -0
- package/dist/rules/expensiveModelSimpleTask.js +119 -0
- package/dist/rules/expensiveModelSimpleTask.js.map +1 -0
- package/dist/rules/frequentCron.d.ts +3 -0
- package/dist/rules/frequentCron.d.ts.map +1 -0
- package/dist/rules/frequentCron.js +64 -0
- package/dist/rules/frequentCron.js.map +1 -0
- package/dist/rules/helpers.d.ts +65 -0
- package/dist/rules/helpers.d.ts.map +1 -0
- package/dist/rules/helpers.js +383 -0
- package/dist/rules/helpers.js.map +1 -0
- package/dist/rules/hugeContext.d.ts +3 -0
- package/dist/rules/hugeContext.d.ts.map +1 -0
- package/dist/rules/hugeContext.js +74 -0
- package/dist/rules/hugeContext.js.map +1 -0
- package/dist/rules/imageGenerationLoop.d.ts +3 -0
- package/dist/rules/imageGenerationLoop.d.ts.map +1 -0
- package/dist/rules/imageGenerationLoop.js +72 -0
- package/dist/rules/imageGenerationLoop.js.map +1 -0
- package/dist/rules/index.d.ts +14 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +24 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/missingRateLimit.d.ts +3 -0
- package/dist/rules/missingRateLimit.d.ts.map +1 -0
- package/dist/rules/missingRateLimit.js +78 -0
- package/dist/rules/missingRateLimit.js.map +1 -0
- package/dist/rules/noLlmCache.d.ts +3 -0
- package/dist/rules/noLlmCache.d.ts.map +1 -0
- package/dist/rules/noLlmCache.js +71 -0
- package/dist/rules/noLlmCache.js.map +1 -0
- package/dist/rules/noTokenLimit.d.ts +3 -0
- package/dist/rules/noTokenLimit.d.ts.map +1 -0
- package/dist/rules/noTokenLimit.js +59 -0
- package/dist/rules/noTokenLimit.js.map +1 -0
- package/dist/rules/repeatedEmbeddings.d.ts +3 -0
- package/dist/rules/repeatedEmbeddings.d.ts.map +1 -0
- package/dist/rules/repeatedEmbeddings.js +81 -0
- package/dist/rules/repeatedEmbeddings.js.map +1 -0
- package/dist/rules/sequentialLlmCalls.d.ts +3 -0
- package/dist/rules/sequentialLlmCalls.d.ts.map +1 -0
- package/dist/rules/sequentialLlmCalls.js +69 -0
- package/dist/rules/sequentialLlmCalls.js.map +1 -0
- package/dist/scanner.d.ts +23 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +217 -0
- package/dist/scanner.js.map +1 -0
- package/dist/types.d.ts +93 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/package.json +75 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAoB7B,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,MAAM;IACN,MAAM;IACN,KAAK;CACN,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG;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,CAAC;IACZ,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;AAC3E,CAAC"}
|
package/dist/ecoLLM.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Provider } from "./models.js";
|
|
2
|
+
export type EcoLLMTaskType = "classification" | "extraction" | "generation" | "reasoning" | "embedding";
|
|
3
|
+
export type EcoLLMInputSize = "small" | "medium" | "large";
|
|
4
|
+
export type EcoLLMInput = {
|
|
5
|
+
taskType: EcoLLMTaskType;
|
|
6
|
+
inputSize: EcoLLMInputSize;
|
|
7
|
+
latencySensitive?: boolean;
|
|
8
|
+
trimMode?: boolean;
|
|
9
|
+
/** @deprecated Use trimMode. */
|
|
10
|
+
ecoMode?: boolean;
|
|
11
|
+
provider?: Provider;
|
|
12
|
+
};
|
|
13
|
+
export type EcoLLMRecommendation = {
|
|
14
|
+
recommendedModelTier: "small" | "medium" | "large";
|
|
15
|
+
shouldCache: boolean;
|
|
16
|
+
maxTokenRecommendation: number;
|
|
17
|
+
notes: string[];
|
|
18
|
+
/** Example model names for the recommended tier, when a provider is given. */
|
|
19
|
+
suggestedModels?: string[];
|
|
20
|
+
};
|
|
21
|
+
export type TrimInferenceTaskType = EcoLLMTaskType;
|
|
22
|
+
export type TrimInferenceInputSize = EcoLLMInputSize;
|
|
23
|
+
export type TrimInferenceInput = EcoLLMInput;
|
|
24
|
+
export type TrimInferenceRecommendation = EcoLLMRecommendation;
|
|
25
|
+
/**
|
|
26
|
+
* A local, offline advisor. It makes NO network calls and holds no provider
|
|
27
|
+
* secrets — it just maps a task shape to a directional recommendation.
|
|
28
|
+
* @deprecated Use trimInference.
|
|
29
|
+
*/
|
|
30
|
+
export declare function ecoLLM(input: EcoLLMInput): EcoLLMRecommendation;
|
|
31
|
+
/** Preferred Trimference name for the local model-tier advisor. */
|
|
32
|
+
export declare function trimInference(input: TrimInferenceInput): TrimInferenceRecommendation;
|
|
33
|
+
//# sourceMappingURL=ecoLLM.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecoLLM.d.ts","sourceRoot":"","sources":["../src/ecoLLM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,MAAM,cAAc,GACtB,gBAAgB,GAChB,YAAY,GACZ,YAAY,GACZ,WAAW,GACX,WAAW,CAAC;AAEhB,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE3D,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,cAAc,CAAC;IACzB,SAAS,EAAE,eAAe,CAAC;IAC3B,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gCAAgC;IAChC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,oBAAoB,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;IACnD,WAAW,EAAE,OAAO,CAAC;IACrB,sBAAsB,EAAE,MAAM,CAAC;IAC/B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,8EAA8E;IAC9E,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,cAAc,CAAC;AACnD,MAAM,MAAM,sBAAsB,GAAG,eAAe,CAAC;AACrD,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC;AAC7C,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,CAAC;AAW/D;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,oBAAoB,CAgH/D;AAED,mEAAmE;AACnE,wBAAgB,aAAa,CAC3B,KAAK,EAAE,kBAAkB,GACxB,2BAA2B,CAE7B"}
|
package/dist/ecoLLM.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { MODEL_MAP } from "./models.js";
|
|
2
|
+
const TIER_ORDER = ["small", "medium", "large"];
|
|
3
|
+
function downshift(tier) {
|
|
4
|
+
const i = TIER_ORDER.indexOf(tier);
|
|
5
|
+
return TIER_ORDER[Math.max(0, i - 1)];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A local, offline advisor. It makes NO network calls and holds no provider
|
|
9
|
+
* secrets — it just maps a task shape to a directional recommendation.
|
|
10
|
+
* @deprecated Use trimInference.
|
|
11
|
+
*/
|
|
12
|
+
export function ecoLLM(input) {
|
|
13
|
+
const { taskType, inputSize, latencySensitive = false, ecoMode = false, trimMode = ecoMode, provider = "unknown", } = input;
|
|
14
|
+
const notes = [];
|
|
15
|
+
let tier;
|
|
16
|
+
let shouldCache = false;
|
|
17
|
+
let maxTokenRecommendation;
|
|
18
|
+
switch (taskType) {
|
|
19
|
+
case "classification":
|
|
20
|
+
case "extraction": {
|
|
21
|
+
// Structured tasks rarely need a top-tier model.
|
|
22
|
+
tier = inputSize === "large" ? "medium" : "small";
|
|
23
|
+
shouldCache = true;
|
|
24
|
+
maxTokenRecommendation = 256;
|
|
25
|
+
notes.push(`${taskType} is usually well served by a small or medium model tier.`);
|
|
26
|
+
notes.push("Cache results for repeated or deterministic inputs to avoid re-running inference.");
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
case "reasoning": {
|
|
30
|
+
// Reasoning scales with input; large input warrants the large tier.
|
|
31
|
+
tier = inputSize === "large" ? "large" : "medium";
|
|
32
|
+
shouldCache = false;
|
|
33
|
+
maxTokenRecommendation = inputSize === "large" ? 2048 : 1024;
|
|
34
|
+
notes.push("Reasoning tasks benefit from more capable tiers, especially with large inputs.");
|
|
35
|
+
notes.push("Break multi-step reasoning into cacheable sub-steps where possible.");
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
case "generation": {
|
|
39
|
+
tier = "medium";
|
|
40
|
+
shouldCache = true;
|
|
41
|
+
maxTokenRecommendation = 1024;
|
|
42
|
+
notes.push("Set an output token cap that matches the expected response length.");
|
|
43
|
+
notes.push("Cache deterministic or templated generations.");
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case "embedding": {
|
|
47
|
+
tier = "small";
|
|
48
|
+
shouldCache = true;
|
|
49
|
+
maxTokenRecommendation = 0; // embeddings do not produce output tokens
|
|
50
|
+
notes.push("Embeddings should be persisted; check for an existing vector before re-embedding unchanged text.");
|
|
51
|
+
notes.push("Batch embedding requests to reduce per-call overhead.");
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
default: {
|
|
55
|
+
// Exhaustiveness guard.
|
|
56
|
+
const _never = taskType;
|
|
57
|
+
throw new Error(`Unknown task type: ${String(_never)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (latencySensitive) {
|
|
61
|
+
const before = tier;
|
|
62
|
+
tier = downshift(tier);
|
|
63
|
+
if (tier !== before) {
|
|
64
|
+
notes.push("Latency-sensitive: preferring a smaller/faster tier to reduce response time.");
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
notes.push("Latency-sensitive: consider streaming and a tight token cap.");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (trimMode) {
|
|
71
|
+
const before = tier;
|
|
72
|
+
tier = downshift(tier);
|
|
73
|
+
shouldCache = true;
|
|
74
|
+
if (tier !== before) {
|
|
75
|
+
notes.push("Trim mode: chose a smaller model tier to reduce compute and cost.");
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
notes.push("Trim mode: already at the smallest sensible tier; caching is enabled.");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
let suggestedModels;
|
|
82
|
+
if (provider !== "unknown") {
|
|
83
|
+
suggestedModels = MODEL_MAP[provider][tier];
|
|
84
|
+
notes.push(`${provider} models at the ${tier} tier include: ${suggestedModels.join(", ")} (examples, verify quality).`);
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
recommendedModelTier: tier,
|
|
88
|
+
shouldCache,
|
|
89
|
+
maxTokenRecommendation,
|
|
90
|
+
notes,
|
|
91
|
+
...(suggestedModels ? { suggestedModels } : {}),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** Preferred Trimference name for the local model-tier advisor. */
|
|
95
|
+
export function trimInference(input) {
|
|
96
|
+
return ecoLLM(input);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=ecoLLM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ecoLLM.js","sourceRoot":"","sources":["../src/ecoLLM.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,aAAa,CAAC;AAqCvD,MAAM,UAAU,GAAW,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AAExD,SAAS,SAAS,CAAC,IAAU;IAC3B,MAAM,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAE,CAAC;AACzC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,KAAkB;IACvC,MAAM,EACJ,QAAQ,EACR,SAAS,EACT,gBAAgB,GAAG,KAAK,EACxB,OAAO,GAAG,KAAK,EACf,QAAQ,GAAG,OAAO,EAClB,QAAQ,GAAG,SAAS,GACrB,GAAG,KAAK,CAAC;IACV,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,IAAI,IAAU,CAAC;IACf,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,sBA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QACtB,KAAK;QACL,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAChD,CAAC;AACJ,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,aAAa,CAC3B,KAAyB;IAEzB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC"}
|
package/dist/impact.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Finding, ImpactEstimate, Level, Severity } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* A human-review-style "Suggested first pass": 2–4 plain-English actions
|
|
4
|
+
* derived from the highest-impact findings, deduplicated and impact-ordered.
|
|
5
|
+
* Expects findings already sorted by severity then impact score.
|
|
6
|
+
*/
|
|
7
|
+
export declare function suggestedFirstPass(findings: Finding[], limit?: number): string[];
|
|
8
|
+
export declare const SEVERITY_WEIGHT: Record<Severity, number>;
|
|
9
|
+
/** Clamp a raw score into the documented 1..100 range. */
|
|
10
|
+
export declare function clampScore(score: number): number;
|
|
11
|
+
/** Build an ImpactEstimate, clamping the score defensively. */
|
|
12
|
+
export declare function makeImpact(estimate: ImpactEstimate): ImpactEstimate;
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Carbon and water levels are not measurements and are omitted
|
|
15
|
+
* from current reports. Use operationalImpactLine instead.
|
|
16
|
+
*/
|
|
17
|
+
export declare function impactLine(impact: ImpactEstimate): string;
|
|
18
|
+
/** Human-facing operational signal; deliberately excludes carbon/water claims. */
|
|
19
|
+
export declare function operationalImpactLine(impact: ImpactEstimate): string;
|
|
20
|
+
export declare function levelWeight(level: Level): number;
|
|
21
|
+
export declare const IMPACT_DISCLAIMER: string;
|
|
22
|
+
//# sourceMappingURL=impact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impact.d.ts","sourceRoot":"","sources":["../src/impact.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAwB3E;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,SAAI,GAAG,MAAM,EAAE,CAW3E;AAQD,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAIpD,CAAC;AAEF,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,QAAQ,EAAE,cAAc,GAAG,cAAc,CAEnE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAOzD;AAED,kFAAkF;AAClF,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAMpE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAEhD;AAED,eAAO,MAAM,iBAAiB,QAE0C,CAAC"}
|
package/dist/impact.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trimference produces DIRECTIONAL impact estimates, not measured emissions.
|
|
3
|
+
* These helpers keep impact wording and math in one place.
|
|
4
|
+
*/
|
|
5
|
+
/** Plain-English "first pass" action per rule, for the review-summary section. */
|
|
6
|
+
const RULE_ACTION = {
|
|
7
|
+
"no-llm-cache": "Add caching around repeated model calls.",
|
|
8
|
+
"repeated-embeddings": "Persist embeddings instead of regenerating unchanged text.",
|
|
9
|
+
"huge-context": "Limit prompt context with summarization or retrieval.",
|
|
10
|
+
"image-generation-loop": "Cap and cache repeated image generation.",
|
|
11
|
+
"no-token-limit": "Add output token limits to model calls.",
|
|
12
|
+
"frequent-cron": "Reduce frequent background polling with backoff or event-driven triggers.",
|
|
13
|
+
"expensive-model-simple-task": "Use smaller model tiers for simple classification or extraction tasks.",
|
|
14
|
+
"sequential-llm-calls": "Combine, cache, or parallelize multi-call LLM flows.",
|
|
15
|
+
"agent-loop-without-budget": "Add step, time, and token/cost budgets to agent loops.",
|
|
16
|
+
"missing-rate-limit": "Add rate limits or quotas to public AI routes.",
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A human-review-style "Suggested first pass": 2–4 plain-English actions
|
|
20
|
+
* derived from the highest-impact findings, deduplicated and impact-ordered.
|
|
21
|
+
* Expects findings already sorted by severity then impact score.
|
|
22
|
+
*/
|
|
23
|
+
export function suggestedFirstPass(findings, limit = 4) {
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
const actions = [];
|
|
26
|
+
for (const f of findings) {
|
|
27
|
+
const action = RULE_ACTION[f.ruleId];
|
|
28
|
+
if (!action || seen.has(action))
|
|
29
|
+
continue;
|
|
30
|
+
seen.add(action);
|
|
31
|
+
actions.push(action);
|
|
32
|
+
if (actions.length >= limit)
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
return actions;
|
|
36
|
+
}
|
|
37
|
+
const LEVEL_WEIGHT = {
|
|
38
|
+
low: 1,
|
|
39
|
+
medium: 2,
|
|
40
|
+
high: 3,
|
|
41
|
+
};
|
|
42
|
+
export const SEVERITY_WEIGHT = {
|
|
43
|
+
low: 1,
|
|
44
|
+
medium: 2,
|
|
45
|
+
high: 3,
|
|
46
|
+
};
|
|
47
|
+
/** Clamp a raw score into the documented 1..100 range. */
|
|
48
|
+
export function clampScore(score) {
|
|
49
|
+
return Math.max(1, Math.min(100, Math.round(score)));
|
|
50
|
+
}
|
|
51
|
+
/** Build an ImpactEstimate, clamping the score defensively. */
|
|
52
|
+
export function makeImpact(estimate) {
|
|
53
|
+
return { ...estimate, score: clampScore(estimate.score) };
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated Carbon and water levels are not measurements and are omitted
|
|
57
|
+
* from current reports. Use operationalImpactLine instead.
|
|
58
|
+
*/
|
|
59
|
+
export function impactLine(impact) {
|
|
60
|
+
return [
|
|
61
|
+
`compute ${impact.computeWaste}`,
|
|
62
|
+
`carbon ${impact.carbonImpact}`,
|
|
63
|
+
`water ${impact.waterImpact}`,
|
|
64
|
+
`cost ${impact.costImpact}`,
|
|
65
|
+
].join(" · ");
|
|
66
|
+
}
|
|
67
|
+
/** Human-facing operational signal; deliberately excludes carbon/water claims. */
|
|
68
|
+
export function operationalImpactLine(impact) {
|
|
69
|
+
return [
|
|
70
|
+
`compute risk ${impact.computeWaste}`,
|
|
71
|
+
`cost risk ${impact.costImpact}`,
|
|
72
|
+
`confidence ${impact.confidence}`,
|
|
73
|
+
].join(" · ");
|
|
74
|
+
}
|
|
75
|
+
export function levelWeight(level) {
|
|
76
|
+
return LEVEL_WEIGHT[level];
|
|
77
|
+
}
|
|
78
|
+
export const IMPACT_DISCLAIMER = "Trimference uses static heuristics. Findings are review prompts, not measured " +
|
|
79
|
+
"usage, cost, emissions, water consumption, or infrastructure energy.";
|
|
80
|
+
//# sourceMappingURL=impact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impact.js","sourceRoot":"","sources":["../src/impact.ts"],"names":[],"mappings":"AAEA;;;GAGG;AAEH,kFAAkF;AAClF,MAAM,WAAW,GAA2B;IAC1C,cAAc,EAAE,0CAA0C;IAC1D,qBAAqB,EAAE,4DAA4D;IACnF,cAAc,EAAE,uDAAuD;IACvE,uBAAuB,EAAE,0CAA0C;IACnE,gBAAgB,EAAE,yCAAyC;IAC3D,eAAe,EACb,2EAA2E;IAC7E,6BAA6B,EAC3B,wEAAwE;IAC1E,sBAAsB,EAAE,sDAAsD;IAC9E,2BAA2B,EACzB,wDAAwD;IAC1D,oBAAoB,EAAE,gDAAgD;CACvE,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAmB,EAAE,KAAK,GAAG,CAAC;IAC/D,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,OAAO,GAAa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AAK,CAAC,CAAC;AAChB,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,qBAAqB,CAAC,MAAsB;IAC1D,OAAO;QACL,gBAAgB,MAAM,CAAC,YAAY,EAAE;QACrC,aAAa,MAAM,CAAC,UAAU,EAAE;QAChC,cAAc,MAAM,CAAC,UAAU,EAAE;KAClC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAY;IACtC,OAAO,YAAY,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,CAAC,MAAM,iBAAiB,GAC5B,gFAAgF;IAChF,sEAAsE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type { Finding, ImpactEstimate, Rule, ScanOptions, ScanResult, ScanSummary, Severity, Level, SourceFile, WasteCategory, } from "./types.js";
|
|
2
|
+
export { WASTE_CATEGORY_LABEL } from "./types.js";
|
|
3
|
+
export { scan, runRules, discoverFiles, sortFindings, findingFingerprint, } from "./scanner.js";
|
|
4
|
+
export { BASELINE_VERSION, readBaseline, writeBaseline, type TrimferenceBaseline, type EcoLintBaseline, } from "./baseline.js";
|
|
5
|
+
export { rules } from "./rules/index.js";
|
|
6
|
+
export { trimInference, ecoLLM, type TrimInferenceInput, type TrimInferenceRecommendation, type TrimInferenceTaskType, type TrimInferenceInputSize, type EcoLLMInput, type EcoLLMRecommendation, type EcoLLMTaskType, type EcoLLMInputSize, } from "./ecoLLM.js";
|
|
7
|
+
export { renderTerminalReport } from "./reporters/terminalReporter.js";
|
|
8
|
+
export { renderJsonReport } from "./reporters/jsonReporter.js";
|
|
9
|
+
export { renderSarifReport } from "./reporters/sarifReporter.js";
|
|
10
|
+
export { renderMarkdownReport } from "./reporters/markdownReporter.js";
|
|
11
|
+
export { TRIMFERENCE_COMMENT_MARKER, ECOLINT_COMMENT_MARKER, MAX_COMMENT_LENGTH, buildCommentBody, type CommentBodyOptions, } from "./prComment.js";
|
|
12
|
+
export { IMPACT_DISCLAIMER, impactLine, operationalImpactLine, makeImpact, } from "./impact.js";
|
|
13
|
+
export { DEFAULT_CONFIG, SCANNABLE_EXTENSIONS, CONFIG_FILENAME, LEGACY_CONFIG_FILENAME, loadConfig, type TrimferenceFileConfig, type EcoLintFileConfig, } from "./config.js";
|
|
14
|
+
export { MODEL_MAP, detectProvider, classifyModelTier, suggestSmallerModels, type Provider, type ModelTier, } from "./models.js";
|
|
15
|
+
export type { RuleContext } from "./types.js";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,OAAO,EACP,cAAc,EACd,IAAI,EACJ,WAAW,EACX,UAAU,EACV,WAAW,EACX,QAAQ,EACR,KAAK,EACL,UAAU,EACV,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EACL,aAAa,EACb,MAAM,EACN,KAAK,kBAAkB,EACvB,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC3B,KAAK,WAAW,EAChB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,kBAAkB,GACxB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,iBAAiB,EACjB,UAAU,EACV,qBAAqB,EACrB,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,sBAAsB,EACtB,UAAU,EACV,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,GACvB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,KAAK,QAAQ,EACb,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { WASTE_CATEGORY_LABEL } from "./types.js";
|
|
2
|
+
export { scan, runRules, discoverFiles, sortFindings, findingFingerprint, } from "./scanner.js";
|
|
3
|
+
export { BASELINE_VERSION, readBaseline, writeBaseline, } from "./baseline.js";
|
|
4
|
+
export { rules } from "./rules/index.js";
|
|
5
|
+
export { trimInference, ecoLLM, } from "./ecoLLM.js";
|
|
6
|
+
export { renderTerminalReport } from "./reporters/terminalReporter.js";
|
|
7
|
+
export { renderJsonReport } from "./reporters/jsonReporter.js";
|
|
8
|
+
export { renderSarifReport } from "./reporters/sarifReporter.js";
|
|
9
|
+
export { renderMarkdownReport } from "./reporters/markdownReporter.js";
|
|
10
|
+
export { TRIMFERENCE_COMMENT_MARKER, ECOLINT_COMMENT_MARKER, MAX_COMMENT_LENGTH, buildCommentBody, } from "./prComment.js";
|
|
11
|
+
export { IMPACT_DISCLAIMER, impactLine, operationalImpactLine, makeImpact, } from "./impact.js";
|
|
12
|
+
export { DEFAULT_CONFIG, SCANNABLE_EXTENSIONS, CONFIG_FILENAME, LEGACY_CONFIG_FILENAME, loadConfig, } from "./config.js";
|
|
13
|
+
export { MODEL_MAP, detectProvider, classifyModelTier, suggestSmallerModels, } from "./models.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,aAAa,EACb,YAAY,EACZ,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,aAAa,GAGd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EACL,aAAa,EACb,MAAM,GASP,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAEvE,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,EACtB,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,iBAAiB,EACjB,UAAU,EACV,qBAAqB,EACrB,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,sBAAsB,EACtB,UAAU,GAGX,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,oBAAoB,GAGrB,MAAM,aAAa,CAAC"}
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A lightweight, CONFIGURABLE heuristic map of provider model tiers.
|
|
3
|
+
*
|
|
4
|
+
* These lists are intentionally illustrative, not authoritative — providers
|
|
5
|
+
* release and rename models constantly. Trimference uses this only to make
|
|
6
|
+
* suggestions more concrete ("consider gpt-4o-mini"), never to make hard claims.
|
|
7
|
+
*/
|
|
8
|
+
export type Provider = "openai" | "anthropic" | "google" | "mistral" | "unknown";
|
|
9
|
+
export type ModelTier = "small" | "medium" | "large";
|
|
10
|
+
export type ProviderModels = Record<ModelTier, string[]>;
|
|
11
|
+
export declare const MODEL_MAP: Record<Exclude<Provider, "unknown">, ProviderModels>;
|
|
12
|
+
/** Guess the provider from a model slug. Returns "unknown" if unclear. */
|
|
13
|
+
export declare function detectProvider(model: string): Provider;
|
|
14
|
+
/** Classify a model slug into a tier using the map, or null if not found. */
|
|
15
|
+
export declare function classifyModelTier(model: string): ModelTier | null;
|
|
16
|
+
/**
|
|
17
|
+
* Suggest smaller-tier example models for a provider. Falls back to a generic
|
|
18
|
+
* suggestion when the provider is unknown.
|
|
19
|
+
*/
|
|
20
|
+
export declare function suggestSmallerModels(provider: Provider): string[];
|
|
21
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAEjF,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAErD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;AAEzD,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,EAAE,cAAc,CAqB1E,CAAC;AAEF,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAStD;AAED,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAUjE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,EAAE,CAGjE"}
|
package/dist/models.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const MODEL_MAP = {
|
|
2
|
+
openai: {
|
|
3
|
+
small: ["gpt-4o-mini", "gpt-4.1-mini"],
|
|
4
|
+
medium: ["gpt-4.1", "gpt-4o"],
|
|
5
|
+
large: ["o3", "o4-mini-high"],
|
|
6
|
+
},
|
|
7
|
+
anthropic: {
|
|
8
|
+
small: ["claude-3-5-haiku", "claude-3-haiku"],
|
|
9
|
+
medium: ["claude-3-5-sonnet", "claude-sonnet"],
|
|
10
|
+
large: ["claude-opus"],
|
|
11
|
+
},
|
|
12
|
+
google: {
|
|
13
|
+
small: ["gemini-flash", "gemini-1.5-flash", "gemini-2.0-flash"],
|
|
14
|
+
medium: ["gemini-pro"],
|
|
15
|
+
large: ["gemini-ultra"],
|
|
16
|
+
},
|
|
17
|
+
mistral: {
|
|
18
|
+
small: ["ministral", "mistral-small"],
|
|
19
|
+
medium: ["mistral-medium"],
|
|
20
|
+
large: ["mistral-large"],
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
/** Guess the provider from a model slug. Returns "unknown" if unclear. */
|
|
24
|
+
export function detectProvider(model) {
|
|
25
|
+
const m = model.toLowerCase();
|
|
26
|
+
if (/(^|[^a-z])(gpt-|o1|o3|o4|text-embedding-|dall-e|davinci)/.test(m)) {
|
|
27
|
+
return "openai";
|
|
28
|
+
}
|
|
29
|
+
if (m.includes("claude"))
|
|
30
|
+
return "anthropic";
|
|
31
|
+
if (m.includes("gemini") || m.includes("palm"))
|
|
32
|
+
return "google";
|
|
33
|
+
if (m.includes("mistral") || m.includes("ministral"))
|
|
34
|
+
return "mistral";
|
|
35
|
+
return "unknown";
|
|
36
|
+
}
|
|
37
|
+
/** Classify a model slug into a tier using the map, or null if not found. */
|
|
38
|
+
export function classifyModelTier(model) {
|
|
39
|
+
const m = model.toLowerCase();
|
|
40
|
+
for (const provider of Object.values(MODEL_MAP)) {
|
|
41
|
+
for (const tier of ["small", "medium", "large"]) {
|
|
42
|
+
if (provider[tier].some((name) => m.includes(name.toLowerCase()))) {
|
|
43
|
+
return tier;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Suggest smaller-tier example models for a provider. Falls back to a generic
|
|
51
|
+
* suggestion when the provider is unknown.
|
|
52
|
+
*/
|
|
53
|
+
export function suggestSmallerModels(provider) {
|
|
54
|
+
if (provider === "unknown")
|
|
55
|
+
return [];
|
|
56
|
+
return MODEL_MAP[provider].small;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,MAAM,SAAS,GAAyD;IAC7E,MAAM,EAAE;QACN,KAAK,EAAE,CAAC,aAAa,EAAE,cAAc,CAAC;QACtC,MAAM,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC;QAC7B,KAAK,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC;KAC9B;IACD,SAAS,EAAE;QACT,KAAK,EAAE,CAAC,kBAAkB,EAAE,gBAAgB,CAAC;QAC7C,MAAM,EAAE,CAAC,mBAAmB,EAAE,eAAe,CAAC;QAC9C,KAAK,EAAE,CAAC,aAAa,CAAC;KACvB;IACD,MAAM,EAAE;QACN,KAAK,EAAE,CAAC,cAAc,EAAE,kBAA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CAAC,EAAE,CAAC;gBAClE,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAkB;IACrD,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACtC,OAAO,SAAS,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for posting the Trimference report as a pull-request comment.
|
|
3
|
+
*
|
|
4
|
+
* The GitHub Action embeds an inline copy of this logic inside an
|
|
5
|
+
* `actions/github-script` step (it cannot import from the published package at
|
|
6
|
+
* action runtime). This module keeps the same rules in one testable place and
|
|
7
|
+
* documents the contract the action relies on.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Stable marker placed at the top of the comment body so the action can find
|
|
11
|
+
* and update its own comment instead of posting duplicates. Do not change this
|
|
12
|
+
* without a migration — existing comments are matched by this exact string.
|
|
13
|
+
*/
|
|
14
|
+
export declare const TRIMFERENCE_COMMENT_MARKER = "<!-- trimference-report -->";
|
|
15
|
+
/** @deprecated Used only to migrate comments created before the rename. */
|
|
16
|
+
export declare const ECOLINT_COMMENT_MARKER = "<!-- ecolint-ai-report -->";
|
|
17
|
+
/**
|
|
18
|
+
* GitHub rejects issue/PR comments longer than 65536 characters. Leave headroom
|
|
19
|
+
* for the marker and the truncation note.
|
|
20
|
+
*/
|
|
21
|
+
export declare const MAX_COMMENT_LENGTH = 60000;
|
|
22
|
+
export type CommentBodyOptions = {
|
|
23
|
+
/** Max length of the rendered report before truncation. Defaults to {@link MAX_COMMENT_LENGTH}. */
|
|
24
|
+
maxLength?: number;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Build the PR comment body from a Markdown report.
|
|
28
|
+
*
|
|
29
|
+
* - Prepends {@link TRIMFERENCE_COMMENT_MARKER} so the comment can be found/updated.
|
|
30
|
+
* - Truncates on a line boundary if the report is too long for a PR comment,
|
|
31
|
+
* appending a note that points readers to the full report in the job summary.
|
|
32
|
+
* The Markdown report is front-loaded (summary, impact score, category
|
|
33
|
+
* breakdown, top fixes), so truncation keeps the most useful content.
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildCommentBody(report: string, options?: CommentBodyOptions): string;
|
|
36
|
+
//# sourceMappingURL=prComment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prComment.d.ts","sourceRoot":"","sources":["../src/prComment.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,gCAAgC,CAAC;AACxE,2EAA2E;AAC3E,eAAO,MAAM,sBAAsB,+BAA+B,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AAExC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,mGAAmG;IACnG,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,kBAAuB,GAC/B,MAAM,CAkBR"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for posting the Trimference report as a pull-request comment.
|
|
3
|
+
*
|
|
4
|
+
* The GitHub Action embeds an inline copy of this logic inside an
|
|
5
|
+
* `actions/github-script` step (it cannot import from the published package at
|
|
6
|
+
* action runtime). This module keeps the same rules in one testable place and
|
|
7
|
+
* documents the contract the action relies on.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Stable marker placed at the top of the comment body so the action can find
|
|
11
|
+
* and update its own comment instead of posting duplicates. Do not change this
|
|
12
|
+
* without a migration — existing comments are matched by this exact string.
|
|
13
|
+
*/
|
|
14
|
+
export const TRIMFERENCE_COMMENT_MARKER = "<!-- trimference-report -->";
|
|
15
|
+
/** @deprecated Used only to migrate comments created before the rename. */
|
|
16
|
+
export const ECOLINT_COMMENT_MARKER = "<!-- ecolint-ai-report -->";
|
|
17
|
+
/**
|
|
18
|
+
* GitHub rejects issue/PR comments longer than 65536 characters. Leave headroom
|
|
19
|
+
* for the marker and the truncation note.
|
|
20
|
+
*/
|
|
21
|
+
export const MAX_COMMENT_LENGTH = 60000;
|
|
22
|
+
/**
|
|
23
|
+
* Build the PR comment body from a Markdown report.
|
|
24
|
+
*
|
|
25
|
+
* - Prepends {@link TRIMFERENCE_COMMENT_MARKER} so the comment can be found/updated.
|
|
26
|
+
* - Truncates on a line boundary if the report is too long for a PR comment,
|
|
27
|
+
* appending a note that points readers to the full report in the job summary.
|
|
28
|
+
* The Markdown report is front-loaded (summary, impact score, category
|
|
29
|
+
* breakdown, top fixes), so truncation keeps the most useful content.
|
|
30
|
+
*/
|
|
31
|
+
export function buildCommentBody(report, options = {}) {
|
|
32
|
+
const maxLength = options.maxLength ?? MAX_COMMENT_LENGTH;
|
|
33
|
+
const trimmed = report.trimEnd();
|
|
34
|
+
if (trimmed.length <= maxLength) {
|
|
35
|
+
return `${TRIMFERENCE_COMMENT_MARKER}\n${trimmed}\n`;
|
|
36
|
+
}
|
|
37
|
+
// Cut at the last newline before the limit so we never split a Markdown line.
|
|
38
|
+
const slice = trimmed.slice(0, maxLength);
|
|
39
|
+
const lastNewline = slice.lastIndexOf("\n");
|
|
40
|
+
const body = (lastNewline > 0 ? slice.slice(0, lastNewline) : slice).trimEnd();
|
|
41
|
+
const note = "> ⚠️ This report was truncated to fit a PR comment. " +
|
|
42
|
+
"See the full Trimference report in the workflow **job summary**.";
|
|
43
|
+
return `${TRIMFERENCE_COMMENT_MARKER}\n${body}\n\n---\n\n${note}\n`;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=prComment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prComment.js","sourceRoot":"","sources":["../src/prComment.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,6BAA6B,CAAC;AACxE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,sBAAsB,GAAG,4BAA4B,CAAC;AAEnE;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAOxC;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAc,EACd,UAA8B,EAAE;IAEhC,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC;IAC1D,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;IAEjC,IAAI,OAAO,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;QAChC,OAAO,GAAG,0BAA0B,KAAK,OAAO,IAAI,CAAC;IACvD,CAAC;IAED,8EAA8E;IAC9E,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IAC1C,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,IAAI,GAAG,CAAC,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;IAE/E,MAAM,IAAI,GACR,sDAAsD;QACtD,kEAAkE,CAAC;IAErE,OAAO,GAAG,0BAA0B,KAAK,IAAI,cAAc,IAAI,IAAI,CAAC;AACtE,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Finding, ScanResult, WasteCategory } from "../types.js";
|
|
2
|
+
/** Category counts sorted high-to-low, as [label, count] pairs. */
|
|
3
|
+
export declare function categoryBreakdown(result: ScanResult): Array<{
|
|
4
|
+
category: WasteCategory;
|
|
5
|
+
label: string;
|
|
6
|
+
count: number;
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* A short, human-readable "fix opportunity" line for a finding, e.g.
|
|
10
|
+
* "Add caching around app/api/generate/route.ts".
|
|
11
|
+
*/
|
|
12
|
+
export declare function fixOpportunityLabel(f: Finding): string;
|
|
13
|
+
/**
|
|
14
|
+
* Top distinct fix opportunities across all findings, highest score first.
|
|
15
|
+
* Deduplicated by label so the same file+category isn't listed repeatedly.
|
|
16
|
+
*/
|
|
17
|
+
export declare function topFixOpportunities(result: ScanResult, limit?: number): Array<{
|
|
18
|
+
label: string;
|
|
19
|
+
score: number;
|
|
20
|
+
}>;
|
|
21
|
+
//# sourceMappingURL=impactTracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impactTracker.d.ts","sourceRoot":"","sources":["../../src/reporters/impactTracker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGtE,mEAAmE;AACnE,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,UAAU,GACjB,KAAK,CAAC;IAAE,QAAQ,EAAE,aAAa,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAWlE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAkBtD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,UAAU,EAClB,KAAK,SAAI,GACR,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAWzC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { WASTE_CATEGORY_LABEL } from "../types.js";
|
|
2
|
+
/** Category counts sorted high-to-low, as [label, count] pairs. */
|
|
3
|
+
export function categoryBreakdown(result) {
|
|
4
|
+
const entries = Object.entries(result.summary.findingsByCategory);
|
|
5
|
+
return entries
|
|
6
|
+
.sort((a, b) => b[1] - a[1])
|
|
7
|
+
.map(([category, count]) => ({
|
|
8
|
+
category,
|
|
9
|
+
label: WASTE_CATEGORY_LABEL[category],
|
|
10
|
+
count,
|
|
11
|
+
}));
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A short, human-readable "fix opportunity" line for a finding, e.g.
|
|
15
|
+
* "Add caching around app/api/generate/route.ts".
|
|
16
|
+
*/
|
|
17
|
+
export function fixOpportunityLabel(f) {
|
|
18
|
+
const loc = f.filePath;
|
|
19
|
+
switch (f.wasteCategory) {
|
|
20
|
+
case "repeated-inference":
|
|
21
|
+
return `Add caching / reduce repeated calls in ${loc}`;
|
|
22
|
+
case "token-bloat":
|
|
23
|
+
return `Limit prompt context in ${loc}`;
|
|
24
|
+
case "model-overkill":
|
|
25
|
+
return `Right-size the model in ${loc}`;
|
|
26
|
+
case "redundant-embedding":
|
|
27
|
+
return `Persist embeddings in ${loc}`;
|
|
28
|
+
case "unbounded-generation":
|
|
29
|
+
return `Set an output token limit in ${loc}`;
|
|
30
|
+
case "background-compute-drift":
|
|
31
|
+
return `Reduce schedule frequency in ${loc}`;
|
|
32
|
+
case "multimodal-cost-explosion":
|
|
33
|
+
return `Cap repeated image generation in ${loc}`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Top distinct fix opportunities across all findings, highest score first.
|
|
38
|
+
* Deduplicated by label so the same file+category isn't listed repeatedly.
|
|
39
|
+
*/
|
|
40
|
+
export function topFixOpportunities(result, limit = 3) {
|
|
41
|
+
const seen = new Set();
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const f of result.findings) {
|
|
44
|
+
const label = fixOpportunityLabel(f);
|
|
45
|
+
if (seen.has(label))
|
|
46
|
+
continue;
|
|
47
|
+
seen.add(label);
|
|
48
|
+
out.push({ label, score: f.impact.score });
|
|
49
|
+
if (out.length >= limit)
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=impactTracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"impactTracker.js","sourceRoot":"","sources":["../../src/reporters/impactTracker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,mEAAmE;AACnE,MAAM,UAAU,iBAAiB,CAC/B,MAAkB;IAElB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAE/D,CAAC;IACF,OAAO,OAAO;SACX,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3B,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;QAC3B,QAAQ;QACR,KAAK,EAAE,oBAAoB,CAAC,QAAQ,CAAC;QACrC,KAAK;KACN,CAAC,CAAC,CAAC;AACR,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,CAAU;IAC5C,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC;IACvB,QAAQ,CAAC,CAAC,aAAa,EAAE,CAAC;QACxB,KAAK,oBAAoB;YACvB,OAAO,0CAA0C,GAAG,EAAE,CAAC;QACzD,KAAK,aAAa;YAChB,OAAO,2BAA2B,GAAG,EAAE,CAAC;QAC1C,KAAK,gBAAgB;YACnB,OAAO,2BAA2B,GAAG,EAAE,CAAC;QAC1C,KAAK,qBAAqB;YACxB,OAAO,yBAAyB,GAAG,EAAE,CAAC;QACxC,KAAK,sBAAsB;YACzB,OAAO,gCAAgC,GAAG,EAAE,CAAC;QAC/C,KAAK,0BAA0B;YAC7B,OAAO,gCAAgC,GAAG,EAAE,CAAC;QAC/C,KAAK,2BAA2B;YAC9B,OAAO,oCAAoC,GAAG,EAAE,CAAC;IACrD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAkB,EAClB,KAAK,GAAG,CAAC;IAET,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,GAAG,GAA4C,EAAE,CAAC;IACxD,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QAChC,MAAM,KAAK,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAAC;QACrC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,SAAS;QAC9B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAChB,GAAG,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;QAC3C,IAAI,GAAG,CAAC,MAAM,IAAI,KAAK;YAAE,MAAM;IACjC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonReporter.d.ts","sourceRoot":"","sources":["../../src/reporters/jsonReporter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,+DAA+D;AAC/D,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CA8B3D"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { IMPACT_DISCLAIMER } from "../impact.js";
|
|
2
|
+
/** Render a scan result as a stable, colorless JSON string. */
|
|
3
|
+
export function renderJsonReport(result) {
|
|
4
|
+
const { summary, findings } = result;
|
|
5
|
+
const payload = {
|
|
6
|
+
schemaVersion: 2,
|
|
7
|
+
summary: {
|
|
8
|
+
filesScanned: summary.filesScanned,
|
|
9
|
+
durationMs: summary.durationMs,
|
|
10
|
+
totalFindings: summary.totalFindings,
|
|
11
|
+
high: summary.high,
|
|
12
|
+
medium: summary.medium,
|
|
13
|
+
low: summary.low,
|
|
14
|
+
priorityPoints: summary.priorityPoints,
|
|
15
|
+
baselineSuppressed: summary.baselineSuppressed,
|
|
16
|
+
ruleErrors: summary.ruleErrors,
|
|
17
|
+
findingsByCategory: summary.findingsByCategory,
|
|
18
|
+
topCategory: summary.topCategory,
|
|
19
|
+
suggestedFirstPass: summary.suggestedFirstPass,
|
|
20
|
+
},
|
|
21
|
+
disclaimer: IMPACT_DISCLAIMER,
|
|
22
|
+
findings: findings.map(({ impact, ...finding }) => ({
|
|
23
|
+
...finding,
|
|
24
|
+
operationalImpact: {
|
|
25
|
+
computeRisk: impact.computeWaste,
|
|
26
|
+
costRisk: impact.costImpact,
|
|
27
|
+
confidence: impact.confidence,
|
|
28
|
+
explanation: impact.explanation,
|
|
29
|
+
},
|
|
30
|
+
})),
|
|
31
|
+
};
|
|
32
|
+
return JSON.stringify(payload, null, 2);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=jsonReporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonReporter.js","sourceRoot":"","sources":["../../src/reporters/jsonReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD,+DAA+D;AAC/D,MAAM,UAAU,gBAAgB,CAAC,MAAkB;IACjD,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IACrC,MAAM,OAAO,GAAG;QACd,aAAa,EAAE,CAAC;QAChB,OAAO,EAAE;YACP,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,aAAa,EAAE,OAAO,CAAC,aAAa;YACpC,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,GAAG,EAAE,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