ghagga-core 2.5.0 → 2.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/README.md +1 -1
- package/dist/agents/consensus.d.ts +16 -0
- package/dist/agents/consensus.d.ts.map +1 -1
- package/dist/agents/consensus.js +57 -33
- package/dist/agents/consensus.js.map +1 -1
- package/dist/agents/diagnostic.d.ts +55 -0
- package/dist/agents/diagnostic.d.ts.map +1 -0
- package/dist/agents/diagnostic.js +143 -0
- package/dist/agents/diagnostic.js.map +1 -0
- package/dist/agents/prompts.d.ts +6 -4
- package/dist/agents/prompts.d.ts.map +1 -1
- package/dist/agents/prompts.js +110 -24
- package/dist/agents/prompts.js.map +1 -1
- package/dist/agents/simple.d.ts +7 -0
- package/dist/agents/simple.d.ts.map +1 -1
- package/dist/agents/simple.js +32 -18
- package/dist/agents/simple.js.map +1 -1
- package/dist/agents/workflow.d.ts +28 -1
- package/dist/agents/workflow.d.ts.map +1 -1
- package/dist/agents/workflow.js +112 -45
- package/dist/agents/workflow.js.map +1 -1
- package/dist/enhance/enhance.d.ts.map +1 -1
- package/dist/enhance/enhance.js +16 -4
- package/dist/enhance/enhance.js.map +1 -1
- package/dist/format.d.ts +47 -1
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +175 -3
- package/dist/format.js.map +1 -1
- package/dist/graph/blast-radius.d.ts +57 -0
- package/dist/graph/blast-radius.d.ts.map +1 -0
- package/dist/graph/blast-radius.js +145 -0
- package/dist/graph/blast-radius.js.map +1 -0
- package/dist/graph/builder.d.ts +50 -0
- package/dist/graph/builder.d.ts.map +1 -0
- package/dist/graph/builder.js +210 -0
- package/dist/graph/builder.js.map +1 -0
- package/dist/graph/extractors/go.d.ts +9 -0
- package/dist/graph/extractors/go.d.ts.map +1 -0
- package/dist/graph/extractors/go.js +78 -0
- package/dist/graph/extractors/go.js.map +1 -0
- package/dist/graph/extractors/index.d.ts +22 -0
- package/dist/graph/extractors/index.d.ts.map +1 -0
- package/dist/graph/extractors/index.js +37 -0
- package/dist/graph/extractors/index.js.map +1 -0
- package/dist/graph/extractors/java.d.ts +9 -0
- package/dist/graph/extractors/java.d.ts.map +1 -0
- package/dist/graph/extractors/java.js +80 -0
- package/dist/graph/extractors/java.js.map +1 -0
- package/dist/graph/extractors/javascript.d.ts +9 -0
- package/dist/graph/extractors/javascript.d.ts.map +1 -0
- package/dist/graph/extractors/javascript.js +204 -0
- package/dist/graph/extractors/javascript.js.map +1 -0
- package/dist/graph/extractors/python.d.ts +9 -0
- package/dist/graph/extractors/python.d.ts.map +1 -0
- package/dist/graph/extractors/python.js +103 -0
- package/dist/graph/extractors/python.js.map +1 -0
- package/dist/graph/extractors/rust.d.ts +9 -0
- package/dist/graph/extractors/rust.d.ts.map +1 -0
- package/dist/graph/extractors/rust.js +115 -0
- package/dist/graph/extractors/rust.js.map +1 -0
- package/dist/graph/extractors/types.d.ts +31 -0
- package/dist/graph/extractors/types.d.ts.map +1 -0
- package/dist/graph/extractors/types.js +9 -0
- package/dist/graph/extractors/types.js.map +1 -0
- package/dist/graph/extractors/typescript.d.ts +9 -0
- package/dist/graph/extractors/typescript.d.ts.map +1 -0
- package/dist/graph/extractors/typescript.js +151 -0
- package/dist/graph/extractors/typescript.js.map +1 -0
- package/dist/graph/index.d.ts +15 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +14 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/loader.d.ts +43 -0
- package/dist/graph/loader.d.ts.map +1 -0
- package/dist/graph/loader.js +104 -0
- package/dist/graph/loader.js.map +1 -0
- package/dist/graph/schema.d.ts +113 -0
- package/dist/graph/schema.d.ts.map +1 -0
- package/dist/graph/schema.js +144 -0
- package/dist/graph/schema.js.map +1 -0
- package/dist/health/trends.js +1 -1
- package/dist/health/trends.js.map +1 -1
- package/dist/index.d.ts +20 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- package/dist/index.js.map +1 -1
- package/dist/memory/sqlite.js +4 -4
- package/dist/memory/sqlite.js.map +1 -1
- package/dist/pipeline.d.ts.map +1 -1
- package/dist/pipeline.js +291 -42
- package/dist/pipeline.js.map +1 -1
- package/dist/providers/cli-bridge.d.ts +136 -0
- package/dist/providers/cli-bridge.d.ts.map +1 -0
- package/dist/providers/cli-bridge.js +457 -0
- package/dist/providers/cli-bridge.js.map +1 -0
- package/dist/providers/fallback.d.ts +8 -0
- package/dist/providers/fallback.d.ts.map +1 -1
- package/dist/providers/fallback.js +24 -8
- package/dist/providers/fallback.js.map +1 -1
- package/dist/providers/gateway.d.ts +40 -0
- package/dist/providers/gateway.d.ts.map +1 -0
- package/dist/providers/gateway.js +52 -0
- package/dist/providers/gateway.js.map +1 -0
- package/dist/providers/generate-fn.d.ts +62 -0
- package/dist/providers/generate-fn.d.ts.map +1 -0
- package/dist/providers/generate-fn.js +84 -0
- package/dist/providers/generate-fn.js.map +1 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +53 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/tools/plugins/index.d.ts +2 -0
- package/dist/tools/plugins/index.d.ts.map +1 -1
- package/dist/tools/plugins/index.js +7 -0
- package/dist/tools/plugins/index.js.map +1 -1
- package/dist/tools/plugins/zizmor.d.ts +22 -0
- package/dist/tools/plugins/zizmor.d.ts.map +1 -0
- package/dist/tools/plugins/zizmor.js +112 -0
- package/dist/tools/plugins/zizmor.js.map +1 -0
- package/dist/tools/resolve.js +1 -1
- package/dist/tools/resolve.js.map +1 -1
- package/dist/tools/types.d.ts +1 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/types.d.ts +54 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +21 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/concurrency.d.ts +29 -0
- package/dist/utils/concurrency.d.ts.map +1 -0
- package/dist/utils/concurrency.js +40 -0
- package/dist/utils/concurrency.js.map +1 -0
- package/dist/utils/context-levels.d.ts +113 -0
- package/dist/utils/context-levels.d.ts.map +1 -0
- package/dist/utils/context-levels.js +255 -0
- package/dist/utils/context-levels.js.map +1 -0
- package/dist/utils/diff.d.ts +25 -0
- package/dist/utils/diff.d.ts.map +1 -1
- package/dist/utils/diff.js +28 -0
- package/dist/utils/diff.js.map +1 -1
- package/dist/utils/llm-timeout.d.ts +38 -0
- package/dist/utils/llm-timeout.d.ts.map +1 -0
- package/dist/utils/llm-timeout.js +76 -0
- package/dist/utils/llm-timeout.js.map +1 -0
- package/dist/utils/path-protection.d.ts +59 -0
- package/dist/utils/path-protection.d.ts.map +1 -0
- package/dist/utils/path-protection.js +136 -0
- package/dist/utils/path-protection.js.map +1 -0
- package/dist/utils/token-budget.d.ts +34 -1
- package/dist/utils/token-budget.d.ts.map +1 -1
- package/dist/utils/token-budget.js +108 -3
- package/dist/utils/token-budget.js.map +1 -1
- package/package.json +21 -19
- package/LICENSE +0 -21
|
@@ -5,13 +5,17 @@
|
|
|
5
5
|
* server error (5xx) or times out, it moves to the next provider.
|
|
6
6
|
* Client errors (4xx) are NOT retried — they indicate misconfiguration.
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { generateTextWithTimeout } from '../utils/llm-timeout.js';
|
|
9
9
|
import { createModel } from './index.js';
|
|
10
10
|
// ─── Helpers ────────────────────────────────────────────────────
|
|
11
11
|
/**
|
|
12
|
-
* Check if an error is
|
|
12
|
+
* Check if an error is retryable (should try the next provider in the chain).
|
|
13
|
+
*
|
|
14
|
+
* Retryable: 5xx, timeouts, rate limits (429), and payload-too-large (413).
|
|
15
|
+
* The 413 case is important for free-tier providers with low TPM limits —
|
|
16
|
+
* the next provider in the chain may have a higher limit.
|
|
13
17
|
*/
|
|
14
|
-
function isRetryableError(error) {
|
|
18
|
+
export function isRetryableError(error) {
|
|
15
19
|
if (error instanceof Error) {
|
|
16
20
|
const message = error.message.toLowerCase();
|
|
17
21
|
// Network/timeout errors
|
|
@@ -24,10 +28,16 @@ function isRetryableError(error) {
|
|
|
24
28
|
const statusMatch = /status[:\s]*(\d{3})/i.exec(message);
|
|
25
29
|
if (statusMatch) {
|
|
26
30
|
const status = parseInt(statusMatch[1] ?? '0', 10);
|
|
27
|
-
|
|
31
|
+
// 5xx server errors + 413 payload too large (TPM exceeded) + 429 rate limit
|
|
32
|
+
return status >= 500 || status === 413 || status === 429;
|
|
28
33
|
}
|
|
29
|
-
// Rate limit
|
|
30
|
-
if (message.includes('rate limit') ||
|
|
34
|
+
// Rate limit / TPM exceeded — also retryable with a different provider
|
|
35
|
+
if (message.includes('rate limit') ||
|
|
36
|
+
message.includes('rate_limit') ||
|
|
37
|
+
message.includes('429') ||
|
|
38
|
+
message.includes('413') ||
|
|
39
|
+
message.includes('request too large') ||
|
|
40
|
+
message.includes('tokens per minute')) {
|
|
31
41
|
return true;
|
|
32
42
|
}
|
|
33
43
|
}
|
|
@@ -54,12 +64,18 @@ export async function generateWithFallback(options) {
|
|
|
54
64
|
for (const { provider, model, apiKey } of providers) {
|
|
55
65
|
try {
|
|
56
66
|
const languageModel = createModel(provider, model, apiKey);
|
|
57
|
-
const result = await
|
|
67
|
+
const result = await generateTextWithTimeout({
|
|
58
68
|
model: languageModel,
|
|
59
69
|
system,
|
|
60
70
|
prompt,
|
|
61
71
|
temperature,
|
|
62
|
-
});
|
|
72
|
+
}, { provider, model });
|
|
73
|
+
// Timeout: treat as a retryable error and try next provider
|
|
74
|
+
if (result === null) {
|
|
75
|
+
lastError = new Error(`LLM call timed out for ${provider}/${model}`);
|
|
76
|
+
console.warn(`[ghagga] Provider ${provider}/${model} timed out, trying next...`);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
63
79
|
// Calculate tokens used from the response
|
|
64
80
|
const tokensUsed = (result.usage?.inputTokens ?? 0) + (result.usage?.outputTokens ?? 0);
|
|
65
81
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fallback.js","sourceRoot":"","sources":["../../src/providers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R,KAAK;gBACL,UAAU;aACX,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,SAAS,GAAG,KAAK,CAAC;YAElB,IAAI,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC5B,oCAAoC;gBACpC,OAAO,CAAC,IAAI,CACV,qBAAqB,QAAQ,IAAI,KAAK,8CAA8C,EACpF,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CAAC;gBACF,SAAS;YACX,CAAC;YAED,4DAA4D;YAC5D,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,6CAA6C;IAC7C,MAAM,SAAS,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Gateway provider — delegates LLM calls to a centralized gateway service.
|
|
3
|
+
*
|
|
4
|
+
* The gateway URL and token are configured per-installation via the dashboard
|
|
5
|
+
* (stored in the provider chain entry). No environment variables needed.
|
|
6
|
+
*
|
|
7
|
+
* API contract:
|
|
8
|
+
* POST /v1/generate
|
|
9
|
+
* Request: { prompt, system, provider?, model?, project? }
|
|
10
|
+
* Response: { text, provider, model, tokensUsed }
|
|
11
|
+
*
|
|
12
|
+
* This provider bypasses the AI SDK entirely — the gateway handles model
|
|
13
|
+
* selection, provider routing, and token management internally.
|
|
14
|
+
*/
|
|
15
|
+
export interface GatewayOptions {
|
|
16
|
+
/** Gateway base URL (e.g., "https://llm-gateway.javierzader.com") */
|
|
17
|
+
gatewayUrl: string;
|
|
18
|
+
/** Bearer token for gateway authentication */
|
|
19
|
+
gatewayToken: string;
|
|
20
|
+
/** Model to request (optional — gateway can auto-select) */
|
|
21
|
+
model?: string;
|
|
22
|
+
/** Project identifier for gateway tracking/routing */
|
|
23
|
+
project?: string;
|
|
24
|
+
}
|
|
25
|
+
export interface GatewayResponse {
|
|
26
|
+
text: string;
|
|
27
|
+
provider: string;
|
|
28
|
+
model: string;
|
|
29
|
+
tokensUsed?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Generate text via the LLM Gateway.
|
|
33
|
+
*
|
|
34
|
+
* @param prompt - User prompt (typically includes the diff)
|
|
35
|
+
* @param systemPrompt - System prompt (review instructions, context, etc.)
|
|
36
|
+
* @param options - Gateway connection options (URL, token, model, project)
|
|
37
|
+
* @returns Gateway response with generated text and metadata
|
|
38
|
+
*/
|
|
39
|
+
export declare function generateViaGateway(prompt: string, systemPrompt?: string, options?: GatewayOptions): Promise<GatewayResponse>;
|
|
40
|
+
//# sourceMappingURL=gateway.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../src/providers/gateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,MAAM,WAAW,cAAc;IAC7B,qEAAqE;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB,8CAA8C;IAC9C,YAAY,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAID;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,eAAe,CAAC,CAiC1B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM Gateway provider — delegates LLM calls to a centralized gateway service.
|
|
3
|
+
*
|
|
4
|
+
* The gateway URL and token are configured per-installation via the dashboard
|
|
5
|
+
* (stored in the provider chain entry). No environment variables needed.
|
|
6
|
+
*
|
|
7
|
+
* API contract:
|
|
8
|
+
* POST /v1/generate
|
|
9
|
+
* Request: { prompt, system, provider?, model?, project? }
|
|
10
|
+
* Response: { text, provider, model, tokensUsed }
|
|
11
|
+
*
|
|
12
|
+
* This provider bypasses the AI SDK entirely — the gateway handles model
|
|
13
|
+
* selection, provider routing, and token management internally.
|
|
14
|
+
*/
|
|
15
|
+
// ─── Public API ─────────────────────────────────────────────────
|
|
16
|
+
/**
|
|
17
|
+
* Generate text via the LLM Gateway.
|
|
18
|
+
*
|
|
19
|
+
* @param prompt - User prompt (typically includes the diff)
|
|
20
|
+
* @param systemPrompt - System prompt (review instructions, context, etc.)
|
|
21
|
+
* @param options - Gateway connection options (URL, token, model, project)
|
|
22
|
+
* @returns Gateway response with generated text and metadata
|
|
23
|
+
*/
|
|
24
|
+
export async function generateViaGateway(prompt, systemPrompt, options) {
|
|
25
|
+
const { gatewayUrl, gatewayToken, model, project } = options ?? {};
|
|
26
|
+
if (!gatewayUrl) {
|
|
27
|
+
throw new Error('Gateway URL not configured — set it in the dashboard provider chain settings');
|
|
28
|
+
}
|
|
29
|
+
if (!gatewayToken) {
|
|
30
|
+
throw new Error('Gateway token not configured — set the API key in the dashboard provider chain settings');
|
|
31
|
+
}
|
|
32
|
+
const response = await fetch(`${gatewayUrl}/v1/generate`, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: {
|
|
35
|
+
'Content-Type': 'application/json',
|
|
36
|
+
Authorization: `Bearer ${gatewayToken}`,
|
|
37
|
+
},
|
|
38
|
+
body: JSON.stringify({
|
|
39
|
+
prompt,
|
|
40
|
+
system: systemPrompt,
|
|
41
|
+
model,
|
|
42
|
+
project,
|
|
43
|
+
}),
|
|
44
|
+
signal: AbortSignal.timeout(180_000), // 3 min timeout (matches CLI bridge)
|
|
45
|
+
});
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
const error = await response.text().catch(() => 'unknown error');
|
|
48
|
+
throw new Error(`Gateway error (${response.status}): ${error}`);
|
|
49
|
+
}
|
|
50
|
+
return response.json();
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=gateway.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../src/providers/gateway.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAsBH,mEAAmE;AAEnE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAc,EACd,YAAqB,EACrB,OAAwB;IAExB,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAEnE,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,8EAA8E,CAAC,CAAC;IAClG,CAAC;IACD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,UAAU,cAAc,EAAE;QACxD,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,YAAY,EAAE;SACxC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,MAAM;YACN,MAAM,EAAE,YAAY;YACpB,KAAK;YACL,OAAO;SACR,CAAC;QACF,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,qCAAqC;KAC5E,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,eAAe,CAAC,CAAC;QACjE,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,CAAC,MAAM,MAAM,KAAK,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,QAAQ,CAAC,IAAI,EAA8B,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GenerateTextFn abstraction — backend-agnostic LLM text generation.
|
|
3
|
+
*
|
|
4
|
+
* Decouples agent orchestration from the LLM backend. Agents call
|
|
5
|
+
* `generateFn(system, prompt)` instead of directly importing AI SDK,
|
|
6
|
+
* CLI bridge, or gateway functions.
|
|
7
|
+
*
|
|
8
|
+
* Three factory functions create GenerateTextFn instances for each backend:
|
|
9
|
+
* - createAISDKGenerateFn — wraps AI SDK's createModel + generateTextWithTimeout
|
|
10
|
+
* - createCLIBridgeGenerateFn — wraps generateViaCLI (child_process)
|
|
11
|
+
* - createGatewayGenerateFn — wraps generateViaGateway (HTTP)
|
|
12
|
+
*/
|
|
13
|
+
import type { LLMProvider } from '../types.js';
|
|
14
|
+
/** Result from any LLM text generation backend */
|
|
15
|
+
export interface GenerateResult {
|
|
16
|
+
text: string;
|
|
17
|
+
tokensUsed: number;
|
|
18
|
+
provider: string;
|
|
19
|
+
model: string;
|
|
20
|
+
}
|
|
21
|
+
/** Generic text generation function — abstracts AI SDK, CLI bridge, and gateway */
|
|
22
|
+
export type GenerateTextFn = (system: string, prompt: string) => Promise<GenerateResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Create a GenerateTextFn backed by the Vercel AI SDK.
|
|
25
|
+
*
|
|
26
|
+
* Wraps `createModel` + `generateTextWithTimeout`. Converts the
|
|
27
|
+
* `null` timeout sentinel into a thrown Error so agents get a
|
|
28
|
+
* clean exception (caught by `allSettled`).
|
|
29
|
+
*
|
|
30
|
+
* @param provider - LLM provider name (e.g., 'anthropic', 'openai')
|
|
31
|
+
* @param model - Model identifier (e.g., 'claude-sonnet-4-20250514')
|
|
32
|
+
* @param apiKey - Decrypted API key
|
|
33
|
+
*/
|
|
34
|
+
export declare function createAISDKGenerateFn(provider: LLMProvider, model: string, apiKey: string): GenerateTextFn;
|
|
35
|
+
/**
|
|
36
|
+
* Create a GenerateTextFn backed by the CLI bridge (child_process).
|
|
37
|
+
*
|
|
38
|
+
* Wraps `generateViaCLI`. Returns `tokensUsed: 0` because CLI
|
|
39
|
+
* tools don't report token usage.
|
|
40
|
+
*
|
|
41
|
+
* @param options - CLI bridge options (preferredCLI, cliModel, credentials)
|
|
42
|
+
*/
|
|
43
|
+
export declare function createCLIBridgeGenerateFn(options: {
|
|
44
|
+
preferredCLI?: string;
|
|
45
|
+
cliModel?: string;
|
|
46
|
+
credentials?: Record<string, string>;
|
|
47
|
+
}): GenerateTextFn;
|
|
48
|
+
/**
|
|
49
|
+
* Create a GenerateTextFn backed by the LLM Gateway (HTTP).
|
|
50
|
+
*
|
|
51
|
+
* Wraps `generateViaGateway`. Maps gateway response fields into
|
|
52
|
+
* the GenerateResult shape.
|
|
53
|
+
*
|
|
54
|
+
* @param options - Gateway connection options (URL, token, model, project)
|
|
55
|
+
*/
|
|
56
|
+
export declare function createGatewayGenerateFn(options: {
|
|
57
|
+
gatewayUrl: string;
|
|
58
|
+
gatewayToken: string;
|
|
59
|
+
model?: string;
|
|
60
|
+
project?: string;
|
|
61
|
+
}): GenerateTextFn;
|
|
62
|
+
//# sourceMappingURL=generate-fn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-fn.d.ts","sourceRoot":"","sources":["../../src/providers/generate-fn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAQ/C,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,mFAAmF;AACnF,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;AAIzF;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,WAAW,EACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,cAAc,CAiBhB;AAID;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE;IACjD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC,GAAG,cAAc,CAUjB;AAID;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE;IAC/C,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,cAAc,CAUjB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GenerateTextFn abstraction — backend-agnostic LLM text generation.
|
|
3
|
+
*
|
|
4
|
+
* Decouples agent orchestration from the LLM backend. Agents call
|
|
5
|
+
* `generateFn(system, prompt)` instead of directly importing AI SDK,
|
|
6
|
+
* CLI bridge, or gateway functions.
|
|
7
|
+
*
|
|
8
|
+
* Three factory functions create GenerateTextFn instances for each backend:
|
|
9
|
+
* - createAISDKGenerateFn — wraps AI SDK's createModel + generateTextWithTimeout
|
|
10
|
+
* - createCLIBridgeGenerateFn — wraps generateViaCLI (child_process)
|
|
11
|
+
* - createGatewayGenerateFn — wraps generateViaGateway (HTTP)
|
|
12
|
+
*/
|
|
13
|
+
import { generateTextWithTimeout } from '../utils/llm-timeout.js';
|
|
14
|
+
import { generateViaCLI } from './cli-bridge.js';
|
|
15
|
+
import { generateViaGateway } from './gateway.js';
|
|
16
|
+
import { createModel } from './index.js';
|
|
17
|
+
// ─── Factory: AI SDK ────────────────────────────────────────────
|
|
18
|
+
/**
|
|
19
|
+
* Create a GenerateTextFn backed by the Vercel AI SDK.
|
|
20
|
+
*
|
|
21
|
+
* Wraps `createModel` + `generateTextWithTimeout`. Converts the
|
|
22
|
+
* `null` timeout sentinel into a thrown Error so agents get a
|
|
23
|
+
* clean exception (caught by `allSettled`).
|
|
24
|
+
*
|
|
25
|
+
* @param provider - LLM provider name (e.g., 'anthropic', 'openai')
|
|
26
|
+
* @param model - Model identifier (e.g., 'claude-sonnet-4-20250514')
|
|
27
|
+
* @param apiKey - Decrypted API key
|
|
28
|
+
*/
|
|
29
|
+
export function createAISDKGenerateFn(provider, model, apiKey) {
|
|
30
|
+
return async (system, prompt) => {
|
|
31
|
+
const languageModel = createModel(provider, model, apiKey);
|
|
32
|
+
const result = await generateTextWithTimeout({ model: languageModel, system, prompt, temperature: 0.3 }, { provider, model });
|
|
33
|
+
if (result === null) {
|
|
34
|
+
throw new Error(`LLM call timed out (${provider}/${model})`);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
text: result.text,
|
|
38
|
+
tokensUsed: (result.usage?.inputTokens ?? 0) + (result.usage?.outputTokens ?? 0),
|
|
39
|
+
provider,
|
|
40
|
+
model,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// ─── Factory: CLI Bridge ────────────────────────────────────────
|
|
45
|
+
/**
|
|
46
|
+
* Create a GenerateTextFn backed by the CLI bridge (child_process).
|
|
47
|
+
*
|
|
48
|
+
* Wraps `generateViaCLI`. Returns `tokensUsed: 0` because CLI
|
|
49
|
+
* tools don't report token usage.
|
|
50
|
+
*
|
|
51
|
+
* @param options - CLI bridge options (preferredCLI, cliModel, credentials)
|
|
52
|
+
*/
|
|
53
|
+
export function createCLIBridgeGenerateFn(options) {
|
|
54
|
+
return async (system, prompt) => {
|
|
55
|
+
const result = generateViaCLI(prompt, system, options);
|
|
56
|
+
return {
|
|
57
|
+
text: result.text,
|
|
58
|
+
tokensUsed: 0, // CLI doesn't report tokens
|
|
59
|
+
provider: 'cli-bridge',
|
|
60
|
+
model: result.cli,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// ─── Factory: Gateway ───────────────────────────────────────────
|
|
65
|
+
/**
|
|
66
|
+
* Create a GenerateTextFn backed by the LLM Gateway (HTTP).
|
|
67
|
+
*
|
|
68
|
+
* Wraps `generateViaGateway`. Maps gateway response fields into
|
|
69
|
+
* the GenerateResult shape.
|
|
70
|
+
*
|
|
71
|
+
* @param options - Gateway connection options (URL, token, model, project)
|
|
72
|
+
*/
|
|
73
|
+
export function createGatewayGenerateFn(options) {
|
|
74
|
+
return async (system, prompt) => {
|
|
75
|
+
const result = await generateViaGateway(prompt, system, options);
|
|
76
|
+
return {
|
|
77
|
+
text: result.text,
|
|
78
|
+
tokensUsed: result.tokensUsed ?? 0,
|
|
79
|
+
provider: result.provider,
|
|
80
|
+
model: result.model,
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=generate-fn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-fn.js","sourceRoot":"","sources":["../../src/providers/generate-fn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAezC,mEAAmE;AAEnE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CACnC,QAAqB,EACrB,KAAa,EACb,MAAc;IAEd,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;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AAC;QACjE,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,CAAC;YAClC,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -15,6 +15,11 @@
|
|
|
15
15
|
* Qwen (Alibaba Cloud DashScope) uses the OpenAI-compatible endpoint at
|
|
16
16
|
* https://dashscope-intl.aliyuncs.com/compatible-mode/v1. Requires a
|
|
17
17
|
* DashScope API key (DASHSCOPE_API_KEY).
|
|
18
|
+
*
|
|
19
|
+
* Groq uses https://api.groq.com/openai/v1 (free tier: 1K–14.4K RPD).
|
|
20
|
+
* Cerebras uses https://api.cerebras.ai/v1 (free tier: 14.4K RPD, ~3000 tok/s).
|
|
21
|
+
* DeepSeek uses https://api.deepseek.com/v1 (near-free, no rate limit).
|
|
22
|
+
* OpenRouter uses https://openrouter.ai/api/v1 (gateway to 200+ models).
|
|
18
23
|
*/
|
|
19
24
|
import type { LanguageModel } from 'ai';
|
|
20
25
|
import type { LLMProvider } from '../types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAyB/C;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,iJAiFnE;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAG/F"}
|
package/dist/providers/index.js
CHANGED
|
@@ -15,16 +15,30 @@
|
|
|
15
15
|
* Qwen (Alibaba Cloud DashScope) uses the OpenAI-compatible endpoint at
|
|
16
16
|
* https://dashscope-intl.aliyuncs.com/compatible-mode/v1. Requires a
|
|
17
17
|
* DashScope API key (DASHSCOPE_API_KEY).
|
|
18
|
+
*
|
|
19
|
+
* Groq uses https://api.groq.com/openai/v1 (free tier: 1K–14.4K RPD).
|
|
20
|
+
* Cerebras uses https://api.cerebras.ai/v1 (free tier: 14.4K RPD, ~3000 tok/s).
|
|
21
|
+
* DeepSeek uses https://api.deepseek.com/v1 (near-free, no rate limit).
|
|
22
|
+
* OpenRouter uses https://openrouter.ai/api/v1 (gateway to 200+ models).
|
|
18
23
|
*/
|
|
19
24
|
import { createAnthropic } from '@ai-sdk/anthropic';
|
|
20
25
|
import { createGoogleGenerativeAI } from '@ai-sdk/google';
|
|
21
26
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
27
|
+
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
22
28
|
/** GitHub Models inference endpoint (OpenAI-compatible) */
|
|
23
29
|
const GITHUB_MODELS_BASE_URL = 'https://models.inference.ai.azure.com';
|
|
24
30
|
/** Ollama local inference endpoint (OpenAI-compatible) */
|
|
25
31
|
const OLLAMA_BASE_URL = 'http://localhost:11434/v1';
|
|
26
32
|
/** Qwen / DashScope international endpoint (OpenAI-compatible) */
|
|
27
33
|
const QWEN_BASE_URL = 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1';
|
|
34
|
+
/** Groq Cloud inference endpoint (OpenAI-compatible) */
|
|
35
|
+
const GROQ_BASE_URL = 'https://api.groq.com/openai/v1';
|
|
36
|
+
/** Cerebras inference endpoint (OpenAI-compatible) */
|
|
37
|
+
const CEREBRAS_BASE_URL = 'https://api.cerebras.ai/v1';
|
|
38
|
+
/** DeepSeek inference endpoint (OpenAI-compatible) */
|
|
39
|
+
const DEEPSEEK_BASE_URL = 'https://api.deepseek.com/v1';
|
|
40
|
+
/** OpenRouter gateway endpoint (OpenAI-compatible) */
|
|
41
|
+
const OPENROUTER_BASE_URL = 'https://openrouter.ai/api/v1';
|
|
28
42
|
// ─── Provider Factory ───────────────────────────────────────────
|
|
29
43
|
/**
|
|
30
44
|
* Create a provider instance configured with the given API key.
|
|
@@ -62,6 +76,45 @@ export function createProvider(provider, apiKey) {
|
|
|
62
76
|
baseURL: QWEN_BASE_URL,
|
|
63
77
|
name: 'qwen',
|
|
64
78
|
});
|
|
79
|
+
case 'groq':
|
|
80
|
+
return createOpenAI({
|
|
81
|
+
apiKey,
|
|
82
|
+
baseURL: GROQ_BASE_URL,
|
|
83
|
+
name: 'groq',
|
|
84
|
+
});
|
|
85
|
+
case 'cerebras': {
|
|
86
|
+
const provider = createOpenAICompatible({
|
|
87
|
+
name: 'cerebras',
|
|
88
|
+
baseURL: CEREBRAS_BASE_URL,
|
|
89
|
+
apiKey,
|
|
90
|
+
});
|
|
91
|
+
return ((modelId) => provider.chatModel(modelId));
|
|
92
|
+
}
|
|
93
|
+
case 'deepseek': {
|
|
94
|
+
const provider = createOpenAICompatible({
|
|
95
|
+
name: 'deepseek',
|
|
96
|
+
baseURL: DEEPSEEK_BASE_URL,
|
|
97
|
+
apiKey,
|
|
98
|
+
});
|
|
99
|
+
return ((modelId) => provider.chatModel(modelId));
|
|
100
|
+
}
|
|
101
|
+
case 'openrouter': {
|
|
102
|
+
const provider = createOpenAICompatible({
|
|
103
|
+
name: 'openrouter',
|
|
104
|
+
baseURL: OPENROUTER_BASE_URL,
|
|
105
|
+
apiKey,
|
|
106
|
+
});
|
|
107
|
+
return ((modelId) => provider.chatModel(modelId));
|
|
108
|
+
}
|
|
109
|
+
case 'cli-bridge':
|
|
110
|
+
// CLI Bridge does not use the AI SDK — it calls CLIs via child_process.
|
|
111
|
+
// Return a dummy provider that throws if accidentally called via createModel().
|
|
112
|
+
// The pipeline intercepts cli-bridge before reaching createModel().
|
|
113
|
+
throw new Error('cli-bridge provider cannot be used with createModel(). Use generateViaCLI() from providers/cli-bridge.js instead.');
|
|
114
|
+
case 'gateway':
|
|
115
|
+
// Gateway does not use the AI SDK — it delegates to an external LLM Gateway service.
|
|
116
|
+
// The pipeline intercepts gateway before reaching createModel().
|
|
117
|
+
throw new Error('gateway provider cannot be used with createModel(). Use generateViaGateway() from providers/gateway.js instead.');
|
|
65
118
|
default: {
|
|
66
119
|
// Exhaustive check — TypeScript will error if a provider is missing
|
|
67
120
|
const _exhaustive = provider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAInE,2DAA2D;AAC3D,MAAM,sBAAsB,GAAG,uCAAuC,CAAC;AAEvE,0DAA0D;AAC1D,MAAM,eAAe,GAAG,2BAA2B,CAAC;AAEpD,kEAAkE;AAClE,MAAM,aAAa,GAAG,wDAAwD,CAAC;AAE/E,wDAAwD;AACxD,MAAM,aAAa,GAAG,gCAAgC,CAAC;AAEvD,sDAAsD;AACtD,MAAM,iBAAiB,GAAG,4BAA4B,CAAC;AAEvD,sDAAsD;AACtD,MAAM,iBAAiB,GAAG,6BAA6B,CAAC;AAExD,sDAAsD;AACtD,MAAM,mBAAmB,GAAG,8BAA8B,CAAC;AAE3D,mEAAmE;AAEnE;;;;;;;;;GASG;AACH,MA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;YACH,OAAO,CAAC,CAAC,OAAe,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,CAEvD,CAAC;QACJ,CAAC;QACD,KAAK,YAAY,CAAC,CAAC,CAAC;YAClB,MAAM,QAAQ,GAAG,sBAAsB,CAAC;gBACtC,IAAI,EAAE,YAAY;gBAClB,OAAO,EAAE,mBAAmB;gBAC5B,MAAM;aACP,CAAC,CAAC;YACH,OAAO,CAAC,CAAC,OAAe,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,CAEvD,CAAC;QACJ,CAAC;QACD,KAAK,YAAY;YACf,wEAAwE;YACxE,gFAAgF;YAChF,oEAAoE;YACpE,MAAM,IAAI,KAAK,CACb,mHAAmH,CACpH,CAAC;QACJ,KAAK,SAAS;YACZ,qFAAqF;YACrF,iEAAiE;YACjE,MAAM,IAAI,KAAK,CACb,iHAAiH,CAClH,CAAC;QACJ,OAAO,CAAC,CAAC,CAAC;YACR,oEAAoE;YACpE,MAAM,WAAW,GAAU,QAAQ,CAAC;YACpC,MAAM,IAAI,KAAK,CAAC,qBAAqB,WAAW,EAAE,CAAC,CAAC;QACtD,CAAC;IACH,CAAC;AACH,CAAC;AAED,mEAAmE;AAEnE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CAAC,QAAqB,EAAE,KAAa,EAAE,MAAc;IAC9E,MAAM,gBAAgB,GAAG,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAC1D,OAAO,gBAAgB,CAAC,KAAK,CAAkB,CAAC;AAClD,CAAC"}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* Phase 3: gitleaks, shellcheck, markdownlint, lizard (always-on)
|
|
9
9
|
* Phase 4: ruff, bandit, golangci-lint (auto-detect)
|
|
10
10
|
* Phase 5: biome, pmd, psalm, clippy, hadolint (auto-detect)
|
|
11
|
+
* Phase 6: zizmor (auto-detect — CI/CD security)
|
|
11
12
|
*/
|
|
12
13
|
/**
|
|
13
14
|
* Register all default tool plugins with the registry.
|
|
@@ -34,4 +35,5 @@ export { ruffPlugin } from './ruff.js';
|
|
|
34
35
|
export { semgrepPlugin } from './semgrep.js';
|
|
35
36
|
export { shellcheckPlugin } from './shellcheck.js';
|
|
36
37
|
export { trivyPlugin } from './trivy.js';
|
|
38
|
+
export { zizmorPlugin } from './zizmor.js';
|
|
37
39
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/plugins/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/plugins/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAoDH;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAQ7C;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAED,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* Phase 3: gitleaks, shellcheck, markdownlint, lizard (always-on)
|
|
9
9
|
* Phase 4: ruff, bandit, golangci-lint (auto-detect)
|
|
10
10
|
* Phase 5: biome, pmd, psalm, clippy, hadolint (auto-detect)
|
|
11
|
+
* Phase 6: zizmor (auto-detect — CI/CD security)
|
|
11
12
|
*/
|
|
12
13
|
import { toolRegistry } from '../registry.js';
|
|
13
14
|
// Phase 4: auto-detect (Python + Go)
|
|
@@ -29,6 +30,8 @@ import { ruffPlugin } from './ruff.js';
|
|
|
29
30
|
import { semgrepPlugin } from './semgrep.js';
|
|
30
31
|
import { shellcheckPlugin } from './shellcheck.js';
|
|
31
32
|
import { trivyPlugin } from './trivy.js';
|
|
33
|
+
// Phase 6: auto-detect (CI/CD security)
|
|
34
|
+
import { zizmorPlugin } from './zizmor.js';
|
|
32
35
|
/** All built-in plugins. Grows as more phases are implemented. */
|
|
33
36
|
const DEFAULT_PLUGINS = [
|
|
34
37
|
// Phase 2: always-on (adapted)
|
|
@@ -50,6 +53,8 @@ const DEFAULT_PLUGINS = [
|
|
|
50
53
|
psalmPlugin,
|
|
51
54
|
clippyPlugin,
|
|
52
55
|
hadolintPlugin,
|
|
56
|
+
// Phase 6: auto-detect (CI/CD security)
|
|
57
|
+
zizmorPlugin,
|
|
53
58
|
];
|
|
54
59
|
let initialized = false;
|
|
55
60
|
/**
|
|
@@ -90,4 +95,6 @@ export { ruffPlugin } from './ruff.js';
|
|
|
90
95
|
export { semgrepPlugin } from './semgrep.js';
|
|
91
96
|
export { shellcheckPlugin } from './shellcheck.js';
|
|
92
97
|
export { trivyPlugin } from './trivy.js';
|
|
98
|
+
// Phase 6
|
|
99
|
+
export { zizmorPlugin } from './zizmor.js';
|
|
93
100
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/plugins/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/plugins/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,qCAAqC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,mCAAmC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,+BAA+B;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,2BAA2B;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,wCAAwC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,kEAAkE;AAClE,MAAM,eAAe,G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AAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,UAAU;AACV,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zizmor plugin — GitHub Actions security analysis (auto-detect).
|
|
3
|
+
*
|
|
4
|
+
* Scans .github/workflows/*.{yml,yaml} files for security vulnerabilities
|
|
5
|
+
* including template injection, unpinned actions, and excessive permissions.
|
|
6
|
+
*
|
|
7
|
+
* Uses ExecutionContext for DI instead of direct child_process.
|
|
8
|
+
*/
|
|
9
|
+
import type { FindingSeverity, ReviewFinding } from '../../types.js';
|
|
10
|
+
import type { RawToolOutput, ToolDefinition } from '../types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Map zizmor SARIF severity level to GHAGGA FindingSeverity.
|
|
13
|
+
* Exported for direct unit testing.
|
|
14
|
+
*/
|
|
15
|
+
export declare function mapZizmorSeverity(level: string, ruleId?: string): FindingSeverity;
|
|
16
|
+
/**
|
|
17
|
+
* Parse zizmor SARIF v2.1.0 output into ReviewFinding[].
|
|
18
|
+
* Exported for direct testing with fixture data.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseZizmorOutput(raw: RawToolOutput, repoDir: string): ReviewFinding[];
|
|
21
|
+
export declare const zizmorPlugin: ToolDefinition;
|
|
22
|
+
//# sourceMappingURL=zizmor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zizmor.d.ts","sourceRoot":"","sources":["../../../src/tools/plugins/zizmor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,KAAK,EAAoB,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAiDnF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe,CAKjF;AAID;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,EAAE,CA4BtF;AAID,eAAO,MAAM,YAAY,EAAE,cAuD1B,CAAC"}
|