@dv.nghiem/flowdeck 0.4.2 → 0.4.3
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 +3 -0
- package/dist/agents/index.d.ts +13 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/config/schema.d.ts +19 -0
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/hooks/compaction-hook.d.ts +6 -1
- package/dist/hooks/compaction-hook.d.ts.map +1 -1
- package/dist/hooks/shell-env-hook.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1236 -318
- package/dist/services/artifact-store.d.ts +39 -0
- package/dist/services/artifact-store.d.ts.map +1 -0
- package/dist/services/artifact-store.test.d.ts +2 -0
- package/dist/services/artifact-store.test.d.ts.map +1 -0
- package/dist/services/context-assembler.d.ts +29 -0
- package/dist/services/context-assembler.d.ts.map +1 -0
- package/dist/services/context-assembler.test.d.ts +2 -0
- package/dist/services/context-assembler.test.d.ts.map +1 -0
- package/dist/services/cost-budget.d.ts +53 -0
- package/dist/services/cost-budget.d.ts.map +1 -0
- package/dist/services/cost-budget.test.d.ts +2 -0
- package/dist/services/cost-budget.test.d.ts.map +1 -0
- package/dist/services/cost-estimator.d.ts +103 -0
- package/dist/services/cost-estimator.d.ts.map +1 -0
- package/dist/services/cost-estimator.test.d.ts +2 -0
- package/dist/services/cost-estimator.test.d.ts.map +1 -0
- package/dist/services/draft-verifier.d.ts +48 -0
- package/dist/services/draft-verifier.d.ts.map +1 -0
- package/dist/services/draft-verifier.test.d.ts +2 -0
- package/dist/services/draft-verifier.test.d.ts.map +1 -0
- package/dist/services/index.d.ts +13 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/lazy-rule-loader.d.ts +104 -0
- package/dist/services/lazy-rule-loader.d.ts.map +1 -0
- package/dist/services/lazy-rule-loader.test.d.ts +23 -0
- package/dist/services/lazy-rule-loader.test.d.ts.map +1 -0
- package/dist/services/model-router-ext.test.d.ts +2 -0
- package/dist/services/model-router-ext.test.d.ts.map +1 -0
- package/dist/services/model-router.d.ts +52 -0
- package/dist/services/model-router.d.ts.map +1 -0
- package/dist/services/model-router.test.d.ts +2 -0
- package/dist/services/model-router.test.d.ts.map +1 -0
- package/dist/services/prompt-cache-ext.test.d.ts +2 -0
- package/dist/services/prompt-cache-ext.test.d.ts.map +1 -0
- package/dist/services/prompt-cache.d.ts +61 -0
- package/dist/services/prompt-cache.d.ts.map +1 -0
- package/dist/services/prompt-cache.test.d.ts +2 -0
- package/dist/services/prompt-cache.test.d.ts.map +1 -0
- package/dist/services/rtk-manager.d.ts +80 -0
- package/dist/services/rtk-manager.d.ts.map +1 -0
- package/dist/services/rtk-manager.test.d.ts +2 -0
- package/dist/services/rtk-manager.test.d.ts.map +1 -0
- package/dist/services/rtk-policy.d.ts +26 -0
- package/dist/services/rtk-policy.d.ts.map +1 -0
- package/dist/services/rtk-policy.test.d.ts +2 -0
- package/dist/services/rtk-policy.test.d.ts.map +1 -0
- package/dist/services/rule-engine.d.ts +29 -0
- package/dist/services/rule-engine.d.ts.map +1 -0
- package/dist/services/rule-engine.test.d.ts +2 -0
- package/dist/services/rule-engine.test.d.ts.map +1 -0
- package/dist/services/task-batcher.d.ts +48 -0
- package/dist/services/task-batcher.d.ts.map +1 -0
- package/dist/services/task-batcher.test.d.ts +2 -0
- package/dist/services/task-batcher.test.d.ts.map +1 -0
- package/dist/services/telemetry.d.ts +6 -0
- package/dist/services/telemetry.d.ts.map +1 -1
- package/dist/services/token-budget.d.ts +44 -0
- package/dist/services/token-budget.d.ts.map +1 -0
- package/dist/services/token-budget.test.d.ts +2 -0
- package/dist/services/token-budget.test.d.ts.map +1 -0
- package/dist/services/token-metrics-ext.test.d.ts +2 -0
- package/dist/services/token-metrics-ext.test.d.ts.map +1 -0
- package/dist/services/token-metrics.d.ts +97 -0
- package/dist/services/token-metrics.d.ts.map +1 -0
- package/dist/services/token-metrics.test.d.ts +2 -0
- package/dist/services/token-metrics.test.d.ts.map +1 -0
- package/dist/tools/council.d.ts.map +1 -1
- package/dist/tools/delegate.d.ts.map +1 -1
- package/dist/tools/load-rules.d.ts +25 -0
- package/dist/tools/load-rules.d.ts.map +1 -0
- package/dist/tools/rtk-setup.d.ts +22 -0
- package/dist/tools/rtk-setup.d.ts.map +1 -0
- package/dist/tools/run-pipeline.d.ts.map +1 -1
- package/docs/commands/fd-map-codebase.md +2 -1
- package/docs/configuration/index.md +26 -0
- package/docs/getting-started/installation.md +20 -0
- package/docs/reference/hooks.md +16 -1
- package/docs/reference/rtk.md +162 -0
- package/package.json +1 -1
- package/src/rules/common/agent-orchestration.md +7 -0
- package/src/rules/common/behavioral.md +7 -0
- package/src/rules/common/coding-style.md +7 -0
- package/src/rules/common/git-workflow.md +7 -0
- package/src/rules/common/security.md +7 -0
- package/src/rules/common/testing.md +7 -0
- package/src/rules/golang/patterns.md +7 -0
- package/src/rules/java/patterns.md +7 -0
- package/src/rules/python/patterns.md +7 -0
- package/src/rules/rust/patterns.md +7 -0
- package/src/rules/typescript/patterns.md +7 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const ARTIFACT_SUMMARY_MAX_CHARS = 500;
|
|
2
|
+
export interface Artifact {
|
|
3
|
+
id: string;
|
|
4
|
+
agent: string;
|
|
5
|
+
stage: string;
|
|
6
|
+
summary: string;
|
|
7
|
+
content: string;
|
|
8
|
+
content_chars: number;
|
|
9
|
+
state_version: number;
|
|
10
|
+
index_version: number;
|
|
11
|
+
created_at: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ArtifactRef {
|
|
14
|
+
id: string;
|
|
15
|
+
summary: string;
|
|
16
|
+
}
|
|
17
|
+
/** Content-hash of the output text (24-char hex prefix). */
|
|
18
|
+
export declare function contentHash(content: string): string;
|
|
19
|
+
/** Auto-generate a short summary from content (first ARTIFACT_SUMMARY_MAX_CHARS chars, stripped). */
|
|
20
|
+
export declare function summarizeContent(content: string): string;
|
|
21
|
+
/**
|
|
22
|
+
* Store an artifact and return a ref (id + summary) for carry-forward.
|
|
23
|
+
* On storage failure, returns a ref with the summary only (id may be recomputed later).
|
|
24
|
+
*/
|
|
25
|
+
export declare function storeArtifact(dir: string, agent: string, stage: string, content: string, stateVersion: number, indexVersion: number): ArtifactRef;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieve an artifact by ID, enforcing version consistency.
|
|
28
|
+
* Returns null when: not found, stateVersion/indexVersion mismatch, or corrupt file.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getArtifact(dir: string, id: string, stateVersion: number, indexVersion: number): Artifact | null;
|
|
31
|
+
/**
|
|
32
|
+
* Resolve `artifact:<id>` tokens in a text string, replacing each with the
|
|
33
|
+
* artifact's full content. Tokens whose artifact is not found or stale are
|
|
34
|
+
* replaced with a `[artifact:<id> not found]` placeholder.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveArtifactRefs(dir: string, text: string, stateVersion: number, indexVersion: number): string;
|
|
37
|
+
/** Format an ArtifactRef for carry-forward in pipeline prompts. */
|
|
38
|
+
export declare function formatArtifactRef(ref: ArtifactRef): string;
|
|
39
|
+
//# sourceMappingURL=artifact-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-store.d.ts","sourceRoot":"","sources":["../../src/services/artifact-store.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,0BAA0B,MAAM,CAAA;AAE7C,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;CAChB;AAUD,4DAA4D;AAC5D,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,qGAAqG;AACrG,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAIxD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,WAAW,CAsBb;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,EACV,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,QAAQ,GAAG,IAAI,CAUjB;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,MAAM,CAKR;AAED,mEAAmE;AACnE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,CAE1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact-store.test.d.ts","sourceRoot":"","sources":["../../src/services/artifact-store.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface StageContext {
|
|
2
|
+
stage: string;
|
|
3
|
+
/** Concise human-readable summary for injection into model prompts */
|
|
4
|
+
compact_summary: string;
|
|
5
|
+
/** Current state version — for cache invalidation */
|
|
6
|
+
state_version: number;
|
|
7
|
+
/** Current codebase index version — for cache invalidation */
|
|
8
|
+
index_version: number;
|
|
9
|
+
/** Structured fields relevant to this stage */
|
|
10
|
+
fields: Record<string, unknown>;
|
|
11
|
+
/** Was this loaded from cache (same summaryVersions as last call)? */
|
|
12
|
+
from_cache: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Assembles a minimal, stage-specific context for prompt injection.
|
|
16
|
+
*
|
|
17
|
+
* Uses in-memory cache keyed by (stage, dir) + (stateVersion, indexVersion).
|
|
18
|
+
* Safe for concurrent readers — no file writes.
|
|
19
|
+
*
|
|
20
|
+
* @param dir - project root directory
|
|
21
|
+
* @param stage - current workflow stage
|
|
22
|
+
* @returns StageContext with compact_summary and fields
|
|
23
|
+
*/
|
|
24
|
+
export declare function assembleStageContext(dir: string, stage: string): StageContext;
|
|
25
|
+
/** Explicitly invalidate the context cache for a directory (call after state writes). */
|
|
26
|
+
export declare function invalidateContextCache(dir: string): void;
|
|
27
|
+
/** Return current cache entry count (for tests/telemetry). */
|
|
28
|
+
export declare function getContextCacheSize(): number;
|
|
29
|
+
//# sourceMappingURL=context-assembler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-assembler.d.ts","sourceRoot":"","sources":["../../src/services/context-assembler.ts"],"names":[],"mappings":"AAeA,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,sEAAsE;IACtE,eAAe,EAAE,MAAM,CAAA;IACvB,qDAAqD;IACrD,aAAa,EAAE,MAAM,CAAA;IACrB,8DAA8D;IAC9D,aAAa,EAAE,MAAM,CAAA;IACrB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,sEAAsE;IACtE,UAAU,EAAE,OAAO,CAAA;CACpB;AAuGD;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,YAAY,CAmC7E;AAED,yFAAyF;AACzF,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAIxD;AAED,8DAA8D;AAC9D,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-assembler.test.d.ts","sourceRoot":"","sources":["../../src/services/context-assembler.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost Budget Service
|
|
3
|
+
*
|
|
4
|
+
* Enforces per-workflow cost and token ceilings.
|
|
5
|
+
* Complements delegation-budget.ts (which counts calls/retries/depth) by tracking
|
|
6
|
+
* estimated USD spend and token consumption across a workflow run.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const result = checkCostBudget(dir, workflowId, { inputTokensDelta: 5000, costUSDDelta: 0.015 }, cfg)
|
|
10
|
+
* if (result.status === "exhausted") throw new Error(result.message)
|
|
11
|
+
*/
|
|
12
|
+
import { loadFlowDeckConfig } from "../config";
|
|
13
|
+
export interface CostBudgetState {
|
|
14
|
+
workflow_id: string;
|
|
15
|
+
run_id: string;
|
|
16
|
+
started_at: string;
|
|
17
|
+
total_input_tokens: number;
|
|
18
|
+
total_output_tokens: number;
|
|
19
|
+
total_est_cost_usd: number;
|
|
20
|
+
call_count: number;
|
|
21
|
+
}
|
|
22
|
+
export type CostBudgetStatus = "ok" | "warned" | "exhausted";
|
|
23
|
+
export interface CostBudgetCheckResult {
|
|
24
|
+
status: CostBudgetStatus;
|
|
25
|
+
message: string;
|
|
26
|
+
state: CostBudgetState;
|
|
27
|
+
}
|
|
28
|
+
export interface CostDelta {
|
|
29
|
+
inputTokensDelta?: number;
|
|
30
|
+
outputTokensDelta?: number;
|
|
31
|
+
costUSDDelta?: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Apply a delta to the running budget state and check against configured limits.
|
|
35
|
+
* If no governance.costBudget is configured, always returns "ok".
|
|
36
|
+
*
|
|
37
|
+
* @param dir - project directory (for loading config and persisting state)
|
|
38
|
+
* @param workflowId - e.g. the GSD run id or workflow name
|
|
39
|
+
* @param runId - a unique id for this invocation (e.g. sessionID)
|
|
40
|
+
* @param delta - tokens/cost consumed by the current call
|
|
41
|
+
* @param cfg - optional pre-loaded budget config (avoids re-reading flowdeck.json)
|
|
42
|
+
*/
|
|
43
|
+
export declare function checkCostBudget(dir: string, workflowId: string, runId: string, delta: CostDelta, cfg?: ReturnType<typeof loadFlowDeckConfig>): CostBudgetCheckResult;
|
|
44
|
+
/**
|
|
45
|
+
* Read the current accumulated state for a workflow run without applying a delta.
|
|
46
|
+
* Returns null if no state exists yet.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getCostBudgetState(dir: string, workflowId: string, runId: string): CostBudgetState | null;
|
|
49
|
+
/**
|
|
50
|
+
* Reset the budget state for a workflow run (e.g. at start of a new run).
|
|
51
|
+
*/
|
|
52
|
+
export declare function resetCostBudget(dir: string, workflowId: string, runId: string): void;
|
|
53
|
+
//# sourceMappingURL=cost-budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-budget.d.ts","sourceRoot":"","sources":["../../src/services/cost-budget.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAI9C,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,mBAAmB,EAAE,MAAM,CAAA;IAC3B,kBAAkB,EAAE,MAAM,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,QAAQ,GAAG,WAAW,CAAA;AAE5D,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,gBAAgB,CAAA;IACxB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,eAAe,CAAA;CACvB;AAED,MAAM,WAAW,SAAS;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AA8CD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAC7B,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,SAAS,EAChB,GAAG,CAAC,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,GAC1C,qBAAqB,CAwDvB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,GACZ,eAAe,GAAG,IAAI,CAGxB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAIpF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-budget.test.d.ts","sourceRoot":"","sources":["../../src/services/cost-budget.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cost Estimator Service
|
|
3
|
+
*
|
|
4
|
+
* Provides USD cost estimates for model calls based on a pricing table.
|
|
5
|
+
* Covers common OpenCode-compatible models (Anthropic, OpenAI, Google).
|
|
6
|
+
*
|
|
7
|
+
* Prices are per 1,000 tokens (input / output) in USD.
|
|
8
|
+
* Rates reflect publicly available list pricing; update when vendors change them.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* import { estimateCostUSD, getCostReport } from "./cost-estimator"
|
|
12
|
+
* const cost = estimateCostUSD("claude-sonnet-4.6", 5000, 1200)
|
|
13
|
+
*/
|
|
14
|
+
import type { MetricEvent } from "./token-metrics";
|
|
15
|
+
/** Cost per million tokens in USD. */
|
|
16
|
+
interface ModelPricing {
|
|
17
|
+
/** USD per 1M input tokens. */
|
|
18
|
+
input: number;
|
|
19
|
+
/** USD per 1M output tokens. */
|
|
20
|
+
output: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resolve pricing for a model identifier string.
|
|
24
|
+
* Matching is case-insensitive prefix match; more specific prefixes take priority.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getModelPricing(model: string): ModelPricing;
|
|
27
|
+
/**
|
|
28
|
+
* Estimate USD cost for a single model call.
|
|
29
|
+
*
|
|
30
|
+
* @param model - Model identifier (e.g. "claude-sonnet-4.6", "gpt-4o")
|
|
31
|
+
* @param inputTokens - Number of input tokens (use estimateTokens() if char count only)
|
|
32
|
+
* @param outputTokens - Number of output tokens
|
|
33
|
+
* @returns Estimated cost in USD (unrounded — round at display time)
|
|
34
|
+
*/
|
|
35
|
+
export declare function estimateCostUSD(model: string, inputTokens: number, outputTokens: number): number;
|
|
36
|
+
/**
|
|
37
|
+
* Estimate cost from raw character counts using the 4 chars/token heuristic.
|
|
38
|
+
* Convenience wrapper for callers that don't have token counts.
|
|
39
|
+
*/
|
|
40
|
+
export declare function estimateCostFromChars(model: string, inputChars: number, outputChars: number): number;
|
|
41
|
+
export interface AgentCostEntry {
|
|
42
|
+
agent: string;
|
|
43
|
+
model_calls: number;
|
|
44
|
+
cache_hits: number;
|
|
45
|
+
retries: number;
|
|
46
|
+
est_input_tokens: number;
|
|
47
|
+
est_output_tokens: number;
|
|
48
|
+
est_cost_usd: number;
|
|
49
|
+
}
|
|
50
|
+
export interface StageCostEntry {
|
|
51
|
+
stage: string;
|
|
52
|
+
model_calls: number;
|
|
53
|
+
cache_hits: number;
|
|
54
|
+
retries: number;
|
|
55
|
+
est_input_tokens: number;
|
|
56
|
+
est_output_tokens: number;
|
|
57
|
+
est_cost_usd: number;
|
|
58
|
+
/** Fraction of total workflow cost (0–1). */
|
|
59
|
+
cost_fraction: number;
|
|
60
|
+
}
|
|
61
|
+
export interface CostReport {
|
|
62
|
+
workflow_id: string;
|
|
63
|
+
/** Per-agent breakdown. */
|
|
64
|
+
by_agent: AgentCostEntry[];
|
|
65
|
+
/** Per-stage breakdown. */
|
|
66
|
+
by_stage: StageCostEntry[];
|
|
67
|
+
totals: {
|
|
68
|
+
model_calls: number;
|
|
69
|
+
cache_hits: number;
|
|
70
|
+
retries: number;
|
|
71
|
+
est_input_tokens: number;
|
|
72
|
+
est_output_tokens: number;
|
|
73
|
+
est_cost_usd: number;
|
|
74
|
+
/** Tokens/$ saved by cache hits (based on avg per-call token count). */
|
|
75
|
+
cache_savings_est_usd: number;
|
|
76
|
+
/** Tokens/$ wasted by retries. */
|
|
77
|
+
retry_cost_est_usd: number;
|
|
78
|
+
cache_hit_rate: number;
|
|
79
|
+
retry_rate: number;
|
|
80
|
+
};
|
|
81
|
+
/** Sorted from most to least expensive. */
|
|
82
|
+
most_expensive_agents: string[];
|
|
83
|
+
most_expensive_stages: string[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Build a cost report from MetricEvent[] for a given workflow.
|
|
87
|
+
*
|
|
88
|
+
* The caller is responsible for loading the events (from TOKEN_METRICS.jsonl).
|
|
89
|
+
* `defaultModel` is used when an event has no model field.
|
|
90
|
+
*/
|
|
91
|
+
export declare function buildCostReport(workflowId: string, events: MetricEvent[], defaultModel?: string): CostReport;
|
|
92
|
+
/**
|
|
93
|
+
* Load MetricEvents from TOKEN_METRICS.jsonl for a workflow and build a CostReport.
|
|
94
|
+
* Convenience wrapper around buildCostReport for production use.
|
|
95
|
+
*/
|
|
96
|
+
export declare function getCostReport(dir: string, workflowId: string, defaultModel?: string): CostReport;
|
|
97
|
+
/**
|
|
98
|
+
* Format a cost report as a human-readable summary string (for logging/display).
|
|
99
|
+
* Returns compact output — use for appLog or tool output.
|
|
100
|
+
*/
|
|
101
|
+
export declare function formatCostReport(report: CostReport): string;
|
|
102
|
+
export {};
|
|
103
|
+
//# sourceMappingURL=cost-estimator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-estimator.d.ts","sourceRoot":"","sources":["../../src/services/cost-estimator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAKlD,sCAAsC;AACtC,UAAU,YAAY;IACpB,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAA;CACf;AAsDD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,CAO3D;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB,MAAM,CAGR;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAClB,MAAM,CAER;AAID,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,EAAE,MAAM,CAAA;IACxB,iBAAiB,EAAE,MAAM,CAAA;IACzB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,EAAE,MAAM,CAAA;IACxB,iBAAiB,EAAE,MAAM,CAAA;IACzB,YAAY,EAAE,MAAM,CAAA;IACpB,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,2BAA2B;IAC3B,QAAQ,EAAE,cAAc,EAAE,CAAA;IAC1B,2BAA2B;IAC3B,QAAQ,EAAE,cAAc,EAAE,CAAA;IAC1B,MAAM,EAAE;QACN,WAAW,EAAE,MAAM,CAAA;QACnB,UAAU,EAAE,MAAM,CAAA;QAClB,OAAO,EAAE,MAAM,CAAA;QACf,gBAAgB,EAAE,MAAM,CAAA;QACxB,iBAAiB,EAAE,MAAM,CAAA;QACzB,YAAY,EAAE,MAAM,CAAA;QACpB,wEAAwE;QACxE,qBAAqB,EAAE,MAAM,CAAA;QAC7B,kCAAkC;QAClC,kBAAkB,EAAE,MAAM,CAAA;QAC1B,cAAc,EAAE,MAAM,CAAA;QACtB,UAAU,EAAE,MAAM,CAAA;KACnB,CAAA;IACD,2CAA2C;IAC3C,qBAAqB,EAAE,MAAM,EAAE,CAAA;IAC/B,qBAAqB,EAAE,MAAM,EAAE,CAAA;CAChC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,WAAW,EAAE,EACrB,YAAY,SAAK,GAChB,UAAU,CAyGZ;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,SAAK,GAAG,UAAU,CAe5F;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAgB3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cost-estimator.test.d.ts","sourceRoot":"","sources":["../../src/services/cost-estimator.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Draft Verifier
|
|
3
|
+
*
|
|
4
|
+
* Implements draft-then-verify for agent calls. A cheap draft is checked
|
|
5
|
+
* against deterministic verifiers before deciding whether to escalate to
|
|
6
|
+
* an expensive model call.
|
|
7
|
+
*
|
|
8
|
+
* PHASE 1: Only rule-based (deterministic) verifiers are supported.
|
|
9
|
+
* Model-based verification is explicitly excluded to avoid turning 1 call into 2.
|
|
10
|
+
*
|
|
11
|
+
* Usage pattern:
|
|
12
|
+
* 1. Run cheap/draft agent → get draft response
|
|
13
|
+
* 2. Call verifyDraft(draft, verifiers)
|
|
14
|
+
* 3. If decision.accepted → return draft, skip expensive agent
|
|
15
|
+
* 4. If !decision.accepted → call expensive agent
|
|
16
|
+
*/
|
|
17
|
+
export type BuiltinVerifierType = "min_length" | "is_json" | "contains_key" | "matches_regex" | "is_nonempty" | "no_error_markers";
|
|
18
|
+
export interface BuiltinVerifier {
|
|
19
|
+
type: BuiltinVerifierType;
|
|
20
|
+
/** min_length: minimum character count after trimming */
|
|
21
|
+
min_chars?: number;
|
|
22
|
+
/** contains_key: substring that must appear in the response */
|
|
23
|
+
required_key?: string;
|
|
24
|
+
/** matches_regex: regex pattern string */
|
|
25
|
+
pattern?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface VerificationResult {
|
|
28
|
+
passed: boolean;
|
|
29
|
+
verifier: BuiltinVerifierType;
|
|
30
|
+
reason: string;
|
|
31
|
+
}
|
|
32
|
+
export interface DraftVerifyDecision {
|
|
33
|
+
/** True if all verifiers passed and the draft is acceptable. */
|
|
34
|
+
accepted: boolean;
|
|
35
|
+
verifications: VerificationResult[];
|
|
36
|
+
failures: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Run all verifiers against a draft response.
|
|
40
|
+
* ALL verifiers must pass for the draft to be accepted.
|
|
41
|
+
*/
|
|
42
|
+
export declare function verifyDraft(draft: string, verifiers: BuiltinVerifier[]): DraftVerifyDecision;
|
|
43
|
+
/**
|
|
44
|
+
* Return a default set of verifiers for a given task output type.
|
|
45
|
+
* Use as a starting point — callers can extend or replace.
|
|
46
|
+
*/
|
|
47
|
+
export declare function defaultVerifiers(taskType: "json_response" | "prose_response" | "classification"): BuiltinVerifier[];
|
|
48
|
+
//# sourceMappingURL=draft-verifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft-verifier.d.ts","sourceRoot":"","sources":["../../src/services/draft-verifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,MAAM,mBAAmB,GAC3B,YAAY,GACZ,SAAS,GACT,cAAc,GACd,eAAe,GACf,aAAa,GACb,kBAAkB,CAAA;AAEtB,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,mBAAmB,CAAA;IACzB,yDAAyD;IACzD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,OAAO,CAAA;IACf,QAAQ,EAAE,mBAAmB,CAAA;IAC7B,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,QAAQ,EAAE,OAAO,CAAA;IACjB,aAAa,EAAE,kBAAkB,EAAE,CAAA;IACnC,QAAQ,EAAE,MAAM,CAAA;CACjB;AAiBD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,mBAAmB,CAI5F;AAkFD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,eAAe,GAAG,gBAAgB,GAAG,gBAAgB,GAC9D,eAAe,EAAE,CAsBnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft-verifier.test.d.ts","sourceRoot":"","sources":["../../src/services/draft-verifier.test.ts"],"names":[],"mappings":""}
|
package/dist/services/index.d.ts
CHANGED
|
@@ -9,4 +9,17 @@ export * from "./agent-trace-graph";
|
|
|
9
9
|
export * from "./delegation-budget";
|
|
10
10
|
export * from "./deadlock-detector";
|
|
11
11
|
export * from "./workflow-scorecard";
|
|
12
|
+
export * from "./token-metrics";
|
|
13
|
+
export * from "./model-router";
|
|
14
|
+
export * from "./context-assembler";
|
|
15
|
+
export * from "./prompt-cache";
|
|
16
|
+
export * from "./rule-engine";
|
|
17
|
+
export * from "./artifact-store";
|
|
18
|
+
export * from "./task-batcher";
|
|
19
|
+
export * from "./draft-verifier";
|
|
20
|
+
export * from "./token-budget";
|
|
21
|
+
export * from "./cost-estimator";
|
|
22
|
+
export * from "./cost-budget";
|
|
23
|
+
export * from "./rtk-manager";
|
|
24
|
+
export * from "./rtk-policy";
|
|
12
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,2BAA2B,CAAA;AACzC,cAAc,mBAAmB,CAAA;AACjC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,qBAAqB,CAAA;AACnC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy Rule Loader
|
|
3
|
+
*
|
|
4
|
+
* Replaces the eager `loadRulePaths()` (loads all rule files) with two-phase discovery:
|
|
5
|
+
*
|
|
6
|
+
* 1. Discovery (cheap): reads frontmatter-only metadata from all rule files without
|
|
7
|
+
* loading their full content. Results are cached per `rulesDir`.
|
|
8
|
+
*
|
|
9
|
+
* 2. Selection: filters rules by `always_on`, `languages`, and `stages` signals
|
|
10
|
+
* derived from the project context.
|
|
11
|
+
*
|
|
12
|
+
* This eliminates unrelated language patterns (e.g. Java rules for a TypeScript
|
|
13
|
+
* project) and provides the infrastructure for future stage-based lazy loading.
|
|
14
|
+
*
|
|
15
|
+
* Rules without frontmatter are treated as always-on (fail-safe).
|
|
16
|
+
*/
|
|
17
|
+
/** Metadata parsed from a rule file's YAML frontmatter. */
|
|
18
|
+
export interface RuleMetadata {
|
|
19
|
+
/** Absolute path to the rule file. */
|
|
20
|
+
path: string;
|
|
21
|
+
/** One-line description extracted from frontmatter. */
|
|
22
|
+
description: string;
|
|
23
|
+
/** If true, inject unconditionally regardless of stage/language. */
|
|
24
|
+
always_on: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Workflow stages this rule is relevant for (empty = all stages).
|
|
27
|
+
* Values: discuss | plan | execute | verify | fix-bug | write-docs
|
|
28
|
+
*/
|
|
29
|
+
stages: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Project languages this rule applies to (empty = all languages).
|
|
32
|
+
* Values: typescript | javascript | python | go | java | rust
|
|
33
|
+
*/
|
|
34
|
+
languages: string[];
|
|
35
|
+
}
|
|
36
|
+
/** Context signals used to select rules. */
|
|
37
|
+
export interface SelectionContext {
|
|
38
|
+
/** Detected project languages (e.g. ["typescript"]). */
|
|
39
|
+
languages?: string[];
|
|
40
|
+
/**
|
|
41
|
+
* Current workflow stage. When provided, stage-restricted rules are
|
|
42
|
+
* filtered to only those matching the stage.
|
|
43
|
+
* When absent (e.g. at plugin startup), stage-restricted rules are still
|
|
44
|
+
* included if they have no language restriction, or excluded if they require
|
|
45
|
+
* a specific language that isn't detected.
|
|
46
|
+
*/
|
|
47
|
+
stage?: string;
|
|
48
|
+
}
|
|
49
|
+
/** Result of a rule selection pass. */
|
|
50
|
+
export interface RuleSelection {
|
|
51
|
+
selected: RuleMetadata[];
|
|
52
|
+
skipped: RuleMetadata[];
|
|
53
|
+
/** Map from file path to human-readable selection reason. */
|
|
54
|
+
reasons: Record<string, string>;
|
|
55
|
+
total_discovered: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Parse a minimal YAML frontmatter block from markdown content.
|
|
59
|
+
* Supports string, boolean, and bracketed array values only.
|
|
60
|
+
* Returns an empty object if no `---` delimited frontmatter is found.
|
|
61
|
+
*/
|
|
62
|
+
export declare function parseFrontmatter(content: string): Record<string, unknown>;
|
|
63
|
+
/**
|
|
64
|
+
* Scan a directory for `*.md` rule files and return their metadata (frontmatter only).
|
|
65
|
+
* Results are cached per `rulesDir` until `invalidateRuleCache()` is called.
|
|
66
|
+
*/
|
|
67
|
+
export declare function discoverRules(rulesDir: string): RuleMetadata[];
|
|
68
|
+
/**
|
|
69
|
+
* Select which rule files should be loaded for the given context.
|
|
70
|
+
*
|
|
71
|
+
* Selection rules (evaluated in order):
|
|
72
|
+
*
|
|
73
|
+
* 1. `always_on: true` → always selected.
|
|
74
|
+
* 2. Language-restricted (`languages` non-empty):
|
|
75
|
+
* - Selected if any detected project language matches.
|
|
76
|
+
* - Skipped if no language match (eliminates foreign-language patterns).
|
|
77
|
+
* 3. Stage-restricted (`stages` non-empty, `stage` provided in context):
|
|
78
|
+
* - Selected if the current stage matches.
|
|
79
|
+
* - Skipped if stage doesn't match.
|
|
80
|
+
* 4. All other rules (no language, no stage restriction) → selected.
|
|
81
|
+
*/
|
|
82
|
+
export declare function selectRulePaths(rulesDir: string, context?: SelectionContext): RuleSelection;
|
|
83
|
+
/**
|
|
84
|
+
* Convenience wrapper: returns the file paths to inject into `cfg.instructions`
|
|
85
|
+
* at plugin startup. Uses detected project languages for language-based filtering.
|
|
86
|
+
* Stage filtering is intentionally skipped at startup (stage is not known yet).
|
|
87
|
+
*/
|
|
88
|
+
export declare function getStartupRulePaths(rulesDir: string, detectedLanguages: string[]): string[];
|
|
89
|
+
/**
|
|
90
|
+
* Detect the primary programming languages used in a project by inspecting
|
|
91
|
+
* known indicator files in the project root.
|
|
92
|
+
* Returns lowercase language names matching the `languages` field in rule frontmatter.
|
|
93
|
+
*/
|
|
94
|
+
export declare function detectProjectLanguages(projectRoot: string): string[];
|
|
95
|
+
/**
|
|
96
|
+
* Build a human-readable diagnostic string for logging.
|
|
97
|
+
* Reports how many rules were discovered, selected, and skipped with reasons.
|
|
98
|
+
*/
|
|
99
|
+
export declare function buildSelectionDiagnostics(selection: RuleSelection, context: SelectionContext): string;
|
|
100
|
+
/** Invalidate the discovery cache (call after rule files change, e.g. in tests). */
|
|
101
|
+
export declare function invalidateRuleCache(): void;
|
|
102
|
+
/** Return current cache entry count (for tests/telemetry). */
|
|
103
|
+
export declare function getRuleCacheSize(): number;
|
|
104
|
+
//# sourceMappingURL=lazy-rule-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-rule-loader.d.ts","sourceRoot":"","sources":["../../src/services/lazy-rule-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,2DAA2D;AAC3D,MAAM,WAAW,YAAY;IAC3B,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,uDAAuD;IACvD,WAAW,EAAE,MAAM,CAAA;IACnB,oEAAoE;IACpE,SAAS,EAAE,OAAO,CAAA;IAClB;;;OAGG;IACH,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB;;;OAGG;IACH,SAAS,EAAE,MAAM,EAAE,CAAA;CACpB;AAED,4CAA4C;AAC5C,MAAM,WAAW,gBAAgB;IAC/B,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,uCAAuC;AACvC,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,YAAY,EAAE,CAAA;IACxB,OAAO,EAAE,YAAY,EAAE,CAAA;IACvB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAOD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyBzE;AAkCD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY,EAAE,CA0B9D;AAID;;;;;;;;;;;;;GAaG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,gBAAqB,GAC7B,aAAa,CAiDf;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,MAAM,EAAE,GAC1B,MAAM,EAAE,CAGV;AAID;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,CAiDpE;AAID;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,aAAa,EACxB,OAAO,EAAE,gBAAgB,GACxB,MAAM,CAgBR;AAID,oFAAoF;AACpF,wBAAgB,mBAAmB,IAAI,IAAI,CAE1C;AAED,8DAA8D;AAC9D,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy Rule Loader Tests
|
|
3
|
+
*
|
|
4
|
+
* Covers:
|
|
5
|
+
* - parseFrontmatter: correctly parses always_on, stages, languages arrays, and description
|
|
6
|
+
* - discoverRules: finds all .md files, caches results, skips README.md
|
|
7
|
+
* - selectRulePaths: always_on rules always included
|
|
8
|
+
* - selectRulePaths: language-mismatched rules skipped
|
|
9
|
+
* - selectRulePaths: language-matched rules included
|
|
10
|
+
* - selectRulePaths: stage filtering when stage is provided
|
|
11
|
+
* - selectRulePaths: stage-restricted rules still included when stage is absent
|
|
12
|
+
* - selectRulePaths: rules without frontmatter treated as always_on (fail-safe)
|
|
13
|
+
* - getStartupRulePaths: returns paths only for selected rules
|
|
14
|
+
* - detectProjectLanguages: detects TypeScript via tsconfig.json
|
|
15
|
+
* - detectProjectLanguages: detects Python via requirements.txt
|
|
16
|
+
* - detectProjectLanguages: detects Go via go.mod
|
|
17
|
+
* - detectProjectLanguages: detects Rust via Cargo.toml
|
|
18
|
+
* - buildSelectionDiagnostics: includes discovered/selected/skipped counts
|
|
19
|
+
* - invalidateRuleCache: clears cached discovery results
|
|
20
|
+
* - repeated loading suppressed (same dir returns cached metadata)
|
|
21
|
+
*/
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=lazy-rule-loader.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-rule-loader.test.d.ts","sourceRoot":"","sources":["../../src/services/lazy-rule-loader.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-router-ext.test.d.ts","sourceRoot":"","sources":["../../src/services/model-router-ext.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model Router Service
|
|
3
|
+
*
|
|
4
|
+
* Classifies task complexity and maps agents to cost tiers.
|
|
5
|
+
* Routes cheap tasks away from expensive models and provides
|
|
6
|
+
* orchestrator-prompt slimming via stage-aware agent filtering.
|
|
7
|
+
*
|
|
8
|
+
* IMPORTANT: This service is telemetry/guidance only.
|
|
9
|
+
* It does NOT change which model OpenCode uses for each call.
|
|
10
|
+
* Actual model switching requires caller integration (flagged with TODO).
|
|
11
|
+
*/
|
|
12
|
+
export type TaskComplexity = "cheap" | "standard" | "expensive";
|
|
13
|
+
export type AgentTier = "cheap" | "standard" | "expensive";
|
|
14
|
+
export interface RoutingDecision {
|
|
15
|
+
complexity: TaskComplexity;
|
|
16
|
+
reason: string;
|
|
17
|
+
/** Agents that are appropriate for this complexity tier */
|
|
18
|
+
eligible_agents: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare function classifyTaskComplexity(task: string): RoutingDecision;
|
|
21
|
+
export declare function getTierForAgent(agentName: string): AgentTier;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the set of agents relevant to the given workflow stage.
|
|
24
|
+
* Returns undefined if the stage is unknown (caller should use full list).
|
|
25
|
+
*/
|
|
26
|
+
export declare function filterAgentsForStage(stage: string): string[] | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Returns agent names to DISABLE for the given stage.
|
|
29
|
+
* Useful for `buildOrchestratorPrompt(disabledAgents)` which takes a disallow-set.
|
|
30
|
+
*
|
|
31
|
+
* @param stage - workflow stage name
|
|
32
|
+
* @param allAgents - complete list of registered agent names
|
|
33
|
+
*/
|
|
34
|
+
export declare function getDisabledAgentsForStage(stage: string, allAgents: string[]): Set<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Tally of agents that would be shown vs hidden for each stage.
|
|
37
|
+
* Used for reporting/telemetry.
|
|
38
|
+
*/
|
|
39
|
+
export declare function computePromptSlimmingStats(allAgents: string[]): Record<string, {
|
|
40
|
+
shown: number;
|
|
41
|
+
hidden: number;
|
|
42
|
+
saving_pct: number;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Return a soft output-format hint to prepend to prompts for cheap tasks.
|
|
46
|
+
* For cheap/classification tasks, requests compact JSON output to reduce prose.
|
|
47
|
+
* Returns an empty string for standard/expensive tasks (no constraint injected).
|
|
48
|
+
*
|
|
49
|
+
* This is guidance only — not enforced at the API level.
|
|
50
|
+
*/
|
|
51
|
+
export declare function getOutputFormatHint(complexity: TaskComplexity): string;
|
|
52
|
+
//# sourceMappingURL=model-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-router.d.ts","sourceRoot":"","sources":["../../src/services/model-router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,UAAU,GAAG,WAAW,CAAA;AAE/D,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,WAAW,CAAA;AAE1D,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,cAAc,CAAA;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,2DAA2D;IAC3D,eAAe,EAAE,MAAM,EAAE,CAAA;CAC1B;AAsCD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAwBpE;AAoED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAE5D;AA2ED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAIxE;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CASzF;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,MAAM,EAAE,GAClB,MAAM,CAAC,MAAM,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,CAavE;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,cAAc,GAAG,MAAM,CAKtE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-router.test.d.ts","sourceRoot":"","sources":["../../src/services/model-router.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-cache-ext.test.d.ts","sourceRoot":"","sources":["../../src/services/prompt-cache-ext.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/** Agents that are safe to cache — pure read-only / idempotent analysis. */
|
|
2
|
+
export declare const CACHEABLE_AGENTS: Set<string>;
|
|
3
|
+
export interface CacheEntry {
|
|
4
|
+
key: string;
|
|
5
|
+
agent: string;
|
|
6
|
+
state_version: number;
|
|
7
|
+
index_version: number;
|
|
8
|
+
created_at: string;
|
|
9
|
+
ttl_ms: number;
|
|
10
|
+
response: string;
|
|
11
|
+
}
|
|
12
|
+
export interface CacheStats {
|
|
13
|
+
total_entries: number;
|
|
14
|
+
valid_entries: number;
|
|
15
|
+
expired_entries: number;
|
|
16
|
+
cache_size_bytes: number;
|
|
17
|
+
}
|
|
18
|
+
export declare function hashKey(agent: string, prompt: string, context: string, stateVersion: number, indexVersion: number): string;
|
|
19
|
+
/**
|
|
20
|
+
* Normalize a prompt for fuzzy cache lookup.
|
|
21
|
+
* Collapses multiple whitespace characters to single spaces and trims.
|
|
22
|
+
* Only whitespace is normalized — punctuation and case are preserved
|
|
23
|
+
* to avoid false cache hits across semantically different queries.
|
|
24
|
+
*/
|
|
25
|
+
export declare function normalizeForCache(text: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Like hashKey but using whitespace-normalized prompt and context.
|
|
28
|
+
* Used as a fallback after the exact key misses.
|
|
29
|
+
*/
|
|
30
|
+
export declare function hashKeyNormalized(agent: string, prompt: string, context: string, stateVersion: number, indexVersion: number): string;
|
|
31
|
+
/**
|
|
32
|
+
* Retrieve a cached response.
|
|
33
|
+
*
|
|
34
|
+
* Lookup order:
|
|
35
|
+
* 1. Exact key (prompt.trim() + context.trim())
|
|
36
|
+
* 2. Whitespace-normalized key (collapses multiple spaces/newlines)
|
|
37
|
+
*
|
|
38
|
+
* Returns null when:
|
|
39
|
+
* - Agent is not in CACHEABLE_AGENTS
|
|
40
|
+
* - No entry exists under either key
|
|
41
|
+
* - Entry is expired
|
|
42
|
+
* - stateVersion or indexVersion don't match (state changed since cached)
|
|
43
|
+
*/
|
|
44
|
+
export declare function getCached(dir: string, agent: string, prompt: string, context: string, stateVersion: number, indexVersion: number, safe_to_cache?: boolean): string | null;
|
|
45
|
+
/**
|
|
46
|
+
* Store a response in the cache.
|
|
47
|
+
*
|
|
48
|
+
* No-ops silently when:
|
|
49
|
+
* - safe_to_cache is false
|
|
50
|
+
* - Agent is not in CACHEABLE_AGENTS
|
|
51
|
+
*/
|
|
52
|
+
export declare function setCached(dir: string, agent: string, prompt: string, context: string, stateVersion: number, indexVersion: number, response: string, safe_to_cache?: boolean, ttl_ms?: number): void;
|
|
53
|
+
/**
|
|
54
|
+
* Remove expired entries and trim to MAX_CACHE_ENTRIES.
|
|
55
|
+
* Called automatically on setCached.
|
|
56
|
+
*/
|
|
57
|
+
export declare function pruneExpired(dir: string): void;
|
|
58
|
+
export declare function getCacheStats(dir: string): CacheStats;
|
|
59
|
+
/** Force-invalidate all cache entries for a given directory (call after state writes). */
|
|
60
|
+
export declare function invalidateCache(dir: string): void;
|
|
61
|
+
//# sourceMappingURL=prompt-cache.d.ts.map
|