@dv.nghiem/flowdeck 0.4.2 → 0.4.4
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/hooks/telemetry-hook.d.ts +3 -2
- package/dist/hooks/telemetry-hook.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1588 -336
- package/dist/services/activity-reporter.d.ts +96 -0
- package/dist/services/activity-reporter.d.ts.map +1 -0
- package/dist/services/activity-reporter.test.d.ts +2 -0
- package/dist/services/activity-reporter.test.d.ts.map +1 -0
- 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 +15 -1
- 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 +2 -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 +2 -1
- 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,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Activity Reporter
|
|
3
|
+
*
|
|
4
|
+
* Surfaces tool lifecycle events and workflow-stage progress to the user
|
|
5
|
+
* in real-time via two channels:
|
|
6
|
+
* 1. appLog (client.app.log) — persistent server log visible in the log panel
|
|
7
|
+
* 2. toast (client.tui.showToast) — ephemeral in-TUI notifications for key events
|
|
8
|
+
*
|
|
9
|
+
* Design goals:
|
|
10
|
+
* - Every significant tool call emits a concise user-visible log line
|
|
11
|
+
* - Key events (failures, stage transitions, waiting states) also show TUI toasts
|
|
12
|
+
* - Heartbeat toast fires if a tracked tool runs > HEARTBEAT_INTERVAL_MS
|
|
13
|
+
* - Normal mode: short summaries (no raw dumps)
|
|
14
|
+
* - Debug mode (FLOWDECK_DEBUG=true): full inputs/outputs + trace metadata
|
|
15
|
+
* - Retries, fallbacks, cache hits, and skips are all individually logged
|
|
16
|
+
*/
|
|
17
|
+
/** Interval before the first "still running" heartbeat toast (ms) */
|
|
18
|
+
export declare const HEARTBEAT_INTERVAL_MS = 15000;
|
|
19
|
+
export type ToastVariant = "info" | "success" | "warning" | "error";
|
|
20
|
+
/** Injectable toast function — wraps client.tui.showToast in production. */
|
|
21
|
+
export type ToastFn = (msg: string, variant: ToastVariant, duration?: number) => void;
|
|
22
|
+
export declare function isDebugMode(): boolean;
|
|
23
|
+
/** Trim text to maxLen, appending ellipsis when truncated */
|
|
24
|
+
export declare function summarize(text: string, maxLen?: number): string;
|
|
25
|
+
/** Format milliseconds as human-readable "42ms" or "3.2s" */
|
|
26
|
+
export declare function fmtDuration(ms: number): string;
|
|
27
|
+
export interface ActivityMeta {
|
|
28
|
+
session_id?: string;
|
|
29
|
+
run_id?: string;
|
|
30
|
+
command?: string;
|
|
31
|
+
stage?: string;
|
|
32
|
+
agent?: string;
|
|
33
|
+
retry_count?: number;
|
|
34
|
+
workflow_id?: string;
|
|
35
|
+
tool?: string;
|
|
36
|
+
}
|
|
37
|
+
export declare class ActivityReporter {
|
|
38
|
+
private readonly log;
|
|
39
|
+
private readonly toastFn?;
|
|
40
|
+
/** correlationKey → start epoch ms */
|
|
41
|
+
private readonly startTimes;
|
|
42
|
+
/** correlationKey → heartbeat interval handle */
|
|
43
|
+
private readonly heartbeats;
|
|
44
|
+
constructor(log: (msg: string) => void, toast?: ToastFn);
|
|
45
|
+
private emit;
|
|
46
|
+
/** Send an ephemeral toast to the TUI. Duration is in milliseconds. */
|
|
47
|
+
private toastNow;
|
|
48
|
+
/**
|
|
49
|
+
* Record start time against a correlation key and start a heartbeat interval.
|
|
50
|
+
* If the tracked operation hasn't finished within HEARTBEAT_INTERVAL_MS, a
|
|
51
|
+
* "still running" log line and toast are emitted to prevent the TUI from
|
|
52
|
+
* looking frozen during long-running tools.
|
|
53
|
+
*/
|
|
54
|
+
trackStart(key: string): void;
|
|
55
|
+
/**
|
|
56
|
+
* Consume the start time for key, cancel its heartbeat, and return elapsed ms.
|
|
57
|
+
* Returns undefined if key was never tracked.
|
|
58
|
+
*/
|
|
59
|
+
elapsedMs(key: string): number | undefined;
|
|
60
|
+
/** Emitted when a tool call begins. */
|
|
61
|
+
reportToolStarted(tool: string, inputSummary: string, meta?: ActivityMeta): void;
|
|
62
|
+
/** Emitted when a tool call completes successfully. */
|
|
63
|
+
reportToolCompleted(tool: string, durationMs: number | undefined, resultSummary: string, meta?: ActivityMeta): void;
|
|
64
|
+
/** Emitted when a tool call fails (after all retries are exhausted). */
|
|
65
|
+
reportToolFailed(tool: string, durationMs: number | undefined, error: string, meta?: ActivityMeta): void;
|
|
66
|
+
/** Emitted each time a tool call is retried. */
|
|
67
|
+
reportToolRetried(tool: string, attempt: number, reason: string, meta?: ActivityMeta): void;
|
|
68
|
+
/** Emitted when the system falls back from one tool/strategy to another. */
|
|
69
|
+
reportToolFallback(fromTool: string, toTool: string, reason: string, meta?: ActivityMeta): void;
|
|
70
|
+
/** Emitted when a tool call is satisfied from the prompt cache. */
|
|
71
|
+
reportCacheHit(tool: string, agent: string, meta?: ActivityMeta): void;
|
|
72
|
+
/** Emitted when a tool or step is intentionally skipped. */
|
|
73
|
+
reportSkipped(tool: string, reason: string, meta?: ActivityMeta): void;
|
|
74
|
+
/**
|
|
75
|
+
* Report high-level workflow stage transitions so users can see
|
|
76
|
+
* which phase of a long-running workflow is currently active.
|
|
77
|
+
* Key status values (started/complete/failed/waiting) also emit TUI toasts.
|
|
78
|
+
*/
|
|
79
|
+
reportStageProgress(stage: string, status: "started" | "running" | "complete" | "failed" | "waiting", detail?: string, meta?: ActivityMeta): void;
|
|
80
|
+
/**
|
|
81
|
+
* Emitted when the permission.ask hook fires — the system is blocked
|
|
82
|
+
* on user approval. Shows a prominent warning toast.
|
|
83
|
+
*/
|
|
84
|
+
reportWaitingForApproval(tool: string, _meta?: ActivityMeta): void;
|
|
85
|
+
/**
|
|
86
|
+
* Emitted when a user command begins execution.
|
|
87
|
+
* Shows a brief info toast so the user knows the system heard them.
|
|
88
|
+
*/
|
|
89
|
+
reportCommandStarted(command: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* Emitted when a user command completes (session.idle fires after it).
|
|
92
|
+
* Shows a success toast with a note about file modifications.
|
|
93
|
+
*/
|
|
94
|
+
reportCommandCompleted(command: string, hasEdits: boolean): void;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=activity-reporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity-reporter.d.ts","sourceRoot":"","sources":["../../src/services/activity-reporter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH,qEAAqE;AACrE,eAAO,MAAM,qBAAqB,QAAS,CAAA;AAK3C,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAA;AACnE,4EAA4E;AAC5E,MAAM,MAAM,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;AAErF,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAED,6DAA6D;AAC7D,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,SAAqB,GAAG,MAAM,CAI3E;AAED,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAG9C;AAOD,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAA;I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AC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,IAAI;IAQ/F,4EAA4E;IAC5E,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,IAAI;IAQnG,mEAAmE;IACnE,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,IAAI;IAM1E,4DAA4D;IAC5D,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,IAAI;IAS1E;;;;OAIG;IACH,mBAAmB,CACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,EACjE,MAAM,CAAC,EAAE,MAAM,EACf,IAAI,GAAE,YAAiB,GACtB,IAAI;IAkCP;;;OAGG;IACH,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,GAAE,YAAiB,GAAG,IAAI;IAMtE;;;OAGG;IACH,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAO3C;;;OAGG;IACH,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,IAAI;CAOjE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity-reporter.test.d.ts","sourceRoot":"","sources":["../../src/services/activity-reporter.test.ts"],"names":[],"mappings":""}
|
|
@@ -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,0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/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,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|
@@ -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":""}
|