@dv.nghiem/flowdeck 0.4.6 → 0.4.8
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 +14 -1
- package/dist/agents/orchestrator.d.ts +2 -5
- package/dist/agents/orchestrator.d.ts.map +1 -1
- package/dist/config/schema.d.ts +1 -15
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/dashboard/server.mjs +14 -1
- package/dist/hooks/orchestrator-guard-hook.d.ts +5 -15
- package/dist/hooks/orchestrator-guard-hook.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +617 -1938
- package/dist/{tools/dispatch-routing.d.ts → lib/task-routing.d.ts} +1 -3
- package/dist/lib/task-routing.d.ts.map +1 -0
- package/dist/services/agent-contract-registry.d.ts.map +1 -1
- package/dist/services/agent-performance.d.ts +1 -1
- package/dist/services/agent-performance.d.ts.map +1 -1
- package/dist/services/cost-estimator.d.ts +0 -88
- package/dist/services/cost-estimator.d.ts.map +1 -1
- package/dist/services/event-logger.d.ts +1 -1
- package/dist/services/event-logger.d.ts.map +1 -1
- package/dist/services/quick-router.d.ts +24 -0
- package/dist/services/quick-router.d.ts.map +1 -1
- package/dist/services/supervisor-binding.d.ts +6 -0
- package/dist/services/supervisor-binding.d.ts.map +1 -1
- package/dist/services/workflow-router.d.ts +57 -0
- package/dist/services/workflow-router.d.ts.map +1 -0
- package/dist/services/workflow-scorecard.d.ts.map +1 -1
- package/dist/tools/planning-state-lib.d.ts +23 -0
- package/dist/tools/planning-state-lib.d.ts.map +1 -1
- package/docs/concepts/workflows.md +48 -0
- package/docs/index.md +15 -2
- package/docs/reference/workflow-router.md +337 -0
- package/package.json +1 -1
- package/src/commands/fd-discuss.md +8 -1
- package/src/commands/fd-execute.md +25 -3
- package/src/commands/fd-new-feature.md +97 -4
- package/src/commands/fd-plan.md +14 -4
- package/src/commands/fd-quick.md +43 -16
- package/src/rules/common/agent-orchestration.md +52 -18
- package/src/skills/agent-harness-construction/SKILL.md +5 -5
- package/dist/services/delegation-budget.d.ts +0 -54
- package/dist/services/delegation-budget.d.ts.map +0 -1
- package/dist/services/prompt-cache.d.ts +0 -61
- package/dist/services/prompt-cache.d.ts.map +0 -1
- package/dist/services/token-metrics.d.ts +0 -97
- package/dist/services/token-metrics.d.ts.map +0 -1
- package/dist/tools/delegate.d.ts +0 -4
- package/dist/tools/delegate.d.ts.map +0 -1
- package/dist/tools/dispatch-routing.d.ts.map +0 -1
- package/dist/tools/run-pipeline.d.ts +0 -4
- package/dist/tools/run-pipeline.d.ts.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: FlowDeck agent registry and orchestration rules — which agent to
|
|
2
|
+
description: FlowDeck agent registry and orchestration rules — which agent to route to and when
|
|
3
3
|
always_on: true
|
|
4
4
|
stages: []
|
|
5
5
|
languages: []
|
|
@@ -56,13 +56,13 @@ Independent agents can run simultaneously. Examples:
|
|
|
56
56
|
**Feature implementation:**
|
|
57
57
|
```
|
|
58
58
|
Wave 1 (parallel):
|
|
59
|
-
@researcher
|
|
60
|
-
@backend-coder
|
|
61
|
-
@tester
|
|
59
|
+
@researcher — research the library API
|
|
60
|
+
@backend-coder — implement the model and types
|
|
61
|
+
@tester — write test cases
|
|
62
62
|
|
|
63
63
|
Wave 2 (after Wave 1):
|
|
64
|
-
@backend-coder
|
|
65
|
-
@reviewer
|
|
64
|
+
@backend-coder — implement service using Wave 1 research
|
|
65
|
+
@reviewer — review Wave 1 implementation
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
**Pre-deploy check:**
|
|
@@ -73,19 +73,53 @@ Parallel:
|
|
|
73
73
|
@tester — run full test suite
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
##
|
|
76
|
+
## Adaptive Workflow Routing
|
|
77
77
|
|
|
78
|
-
FlowDeck
|
|
78
|
+
FlowDeck uses adaptive workflow routing. The orchestrator selects the most appropriate workflow class at runtime based on task context, complexity, risk, and codebase familiarity.
|
|
79
79
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
### Workflow Classes
|
|
81
|
+
|
|
82
|
+
| Class | Stages | When Selected |
|
|
83
|
+
|-------|--------|---------------|
|
|
84
|
+
| `quick` | execute → verify | Simple, low-risk tasks (< 5 files, no ambiguity) |
|
|
85
|
+
| `standard` | plan → execute → verify | Normal implementation tasks |
|
|
86
|
+
| `explore` | discuss → plan → execute → verify | Ambiguous or unfamiliar tasks |
|
|
87
|
+
| `ui-heavy` | discuss → design → plan → execute → verify | UI/UX-heavy tasks |
|
|
88
|
+
| `bugfix` | discuss → fix-bug → verify | Bug fixes |
|
|
89
|
+
| `docs-only` | write-docs → verify | Documentation-only changes |
|
|
90
|
+
| `verify-heavy` | plan → execute → verify | High blast radius or sensitive paths |
|
|
91
|
+
|
|
92
|
+
### Routing Criteria
|
|
93
|
+
|
|
94
|
+
The orchestrator scores tasks across these dimensions:
|
|
95
|
+
- **Simplicity**: Is the task a simple rename, typo fix, or config update?
|
|
96
|
+
- **Confidence**: How well does the task description match known patterns?
|
|
97
|
+
- **Risk**: Is the blast radius small (< 3 files) and are no sensitive paths touched?
|
|
98
|
+
- **Codebase familiarity**: Is the codebase mapping fresh (< 24h)?
|
|
99
|
+
- **Complexity**: Is the task cheap (classify, validate, summarize) vs expensive (architect, refactor entire system)?
|
|
100
|
+
|
|
101
|
+
The workflow class with the highest score is selected. The orchestrator prefers the lightest workflow that is sufficient.
|
|
102
|
+
|
|
103
|
+
### Phase Behavior
|
|
104
|
+
|
|
105
|
+
- **quick / docs-only**: Skip discuss and plan phases. Run execute directly.
|
|
106
|
+
- **standard / verify-heavy**: Skip discuss. Start with plan.
|
|
107
|
+
- **explore / bugfix / ui-heavy**: Include discuss phase for requirements gathering.
|
|
108
|
+
- **ui-heavy**: Always include design phase before execute.
|
|
109
|
+
|
|
110
|
+
### Escalation
|
|
111
|
+
|
|
112
|
+
If the orchestrator discovers during execution that the initial workflow class is insufficient, it escalates to a richer workflow:
|
|
113
|
+
- quick → standard: when blast radius exceeds 3 files
|
|
114
|
+
- standard → verify-heavy: when sensitive paths are touched
|
|
115
|
+
- standard → ui-heavy: when design requirements emerge
|
|
116
|
+
- explore → standard: when confidence improves after discussion
|
|
117
|
+
|
|
118
|
+
Escalation is logged with reasons and triggers replanning.
|
|
83
119
|
|
|
84
|
-
|
|
85
|
-
|-------|-------|---------|
|
|
86
|
-
| discuss | `@discusser` | `/fd-discuss` |
|
|
87
|
-
| plan | `@planner` → `@plan-checker` | `/fd-plan` |
|
|
88
|
-
| execute | `@orchestrator` → `@backend-coder`, `@tester`, etc. | `/fd-new-feature` |
|
|
89
|
-
| review | `@reviewer` + `@security-auditor` | `/fd-verify` |
|
|
120
|
+
### Phase Gating (Relaxed)
|
|
90
121
|
|
|
91
|
-
|
|
122
|
+
Phase gating is advisory, not absolute:
|
|
123
|
+
- For `quick` and `docs-only` workflows: phases may be skipped without override.
|
|
124
|
+
- For other workflows: follow the phase order for the selected workflow class.
|
|
125
|
+
- The orchestrator may override phase gating when the workflow class permits it.
|
|
@@ -78,7 +78,7 @@ async function withRetry<T>(
|
|
|
78
78
|
interface AgentMessage {
|
|
79
79
|
from: string;
|
|
80
80
|
to: string;
|
|
81
|
-
type: 'request' | 'response' | '
|
|
81
|
+
type: 'request' | 'response' | 'assign' | 'result';
|
|
82
82
|
payload: unknown;
|
|
83
83
|
traceId: string;
|
|
84
84
|
}
|
|
@@ -87,20 +87,20 @@ class SupervisorAgent {
|
|
|
87
87
|
private agents: Map<string, Agent>;
|
|
88
88
|
private messageQueue: AgentMessage[] = [];
|
|
89
89
|
|
|
90
|
-
async
|
|
90
|
+
async assignTask(task: Task, targetAgent: string): Promise<Result> {
|
|
91
91
|
const message: AgentMessage = {
|
|
92
92
|
from: this.id,
|
|
93
93
|
to: targetAgent,
|
|
94
|
-
type: '
|
|
94
|
+
type: 'assign',
|
|
95
95
|
payload: task,
|
|
96
96
|
traceId: generateTraceId(),
|
|
97
97
|
};
|
|
98
98
|
return this.sendAndWait(message);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
async
|
|
101
|
+
async assignParallel(tasks: Task[], agents: string[]): Promise<Result[]> {
|
|
102
102
|
return Promise.all(
|
|
103
|
-
tasks.map((task, i) => this.
|
|
103
|
+
tasks.map((task, i) => this.assignTask(task, agents[i % agents.length]))
|
|
104
104
|
);
|
|
105
105
|
}
|
|
106
106
|
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Delegation Budget Manager
|
|
3
|
-
* Tracks and enforces per-run limits on tool calls, delegations, retries, and depth.
|
|
4
|
-
* Stored in .codebase/BUDGETS.json.
|
|
5
|
-
* When a limit is reached the run should stop, escalate, or enter fallback mode.
|
|
6
|
-
*/
|
|
7
|
-
export type BudgetStatus = "active" | "warning" | "exhausted" | "completed";
|
|
8
|
-
export interface BudgetLimits {
|
|
9
|
-
maxToolCalls: number;
|
|
10
|
-
maxDelegatedAgents: number;
|
|
11
|
-
maxRetries: number;
|
|
12
|
-
maxDepth: number;
|
|
13
|
-
maxSameStepRetries: number;
|
|
14
|
-
}
|
|
15
|
-
export interface BudgetConsumed {
|
|
16
|
-
toolCalls: number;
|
|
17
|
-
delegatedAgents: number;
|
|
18
|
-
retries: number;
|
|
19
|
-
maxDepthReached: number;
|
|
20
|
-
/** step_id → retry count */
|
|
21
|
-
sameStepRetries: Record<string, number>;
|
|
22
|
-
}
|
|
23
|
-
export interface DelegationBudget {
|
|
24
|
-
run_id: string;
|
|
25
|
-
session_id: string;
|
|
26
|
-
created_at: string;
|
|
27
|
-
updated_at: string;
|
|
28
|
-
limits: BudgetLimits;
|
|
29
|
-
consumed: BudgetConsumed;
|
|
30
|
-
status: BudgetStatus;
|
|
31
|
-
exhaustion_reason?: string;
|
|
32
|
-
}
|
|
33
|
-
export interface BudgetCheckResult {
|
|
34
|
-
allowed: boolean;
|
|
35
|
-
warning: boolean;
|
|
36
|
-
reason?: string;
|
|
37
|
-
}
|
|
38
|
-
export declare function createBudget(dir: string, run_id: string, session_id?: string): DelegationBudget;
|
|
39
|
-
export declare function getBudget(dir: string, run_id: string): DelegationBudget | null;
|
|
40
|
-
export declare function isBudgetExhausted(dir: string, run_id: string): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Increment tool call counter. Returns whether the call is allowed.
|
|
43
|
-
*/
|
|
44
|
-
export declare function recordToolCall(dir: string, run_id: string): BudgetCheckResult;
|
|
45
|
-
/**
|
|
46
|
-
* Increment delegation counter and track max depth.
|
|
47
|
-
*/
|
|
48
|
-
export declare function recordDelegation(dir: string, run_id: string, depth: number): BudgetCheckResult;
|
|
49
|
-
/**
|
|
50
|
-
* Increment retry counter for a specific step. Enforces both per-step and total limits.
|
|
51
|
-
*/
|
|
52
|
-
export declare function recordRetry(dir: string, run_id: string, step_id: string): BudgetCheckResult;
|
|
53
|
-
export declare function completeBudget(dir: string, run_id: string): void;
|
|
54
|
-
//# sourceMappingURL=delegation-budget.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegation-budget.d.ts","sourceRoot":"","sources":["../../src/services/delegation-budget.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,WAAW,CAAA;AAE3E,MAAM,WAAW,YAAY;IAC3B,YAAY,EAAE,MAAM,CAAA;IACpB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,kBAAkB,EAAE,MAAM,CAAA;CAC3B;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,eAAe,EAAE,MAAM,CAAA;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,MAAM,CAAA;IACvB,4BAA4B;IAC5B,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM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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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"prompt-cache.d.ts","sourceRoot":"","sources":["../../src/services/prompt-cache.ts"],"names":[],"mappings":"AAmBA,4EAA4E;AAC5E,eAAO,MAAM,gBAAgB,aAQ3B,CAAA;AAMF,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,UAAU;IACzB,aAAa,EAAE,MAAM,CAAA;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;CACzB;AA+BD,wBAAgB,OAAO,CACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,MAAM,CAGR;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,MAAM,CASR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,aAAa,UAAQ,GACpB,MAAM,GAAG,IAAI,CAaf;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,aAAa,UAAQ,EACrB,MAAM,SAAiB,GACtB,IAAI,CAsBN;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAsC9C;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CA6BrD;AAED,0FAA0F;AAC1F,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAQjD"}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
export type WorkflowStage = "discuss" | "plan" | "execute" | "verify" | "design" | "fix-bug" | "write-docs" | "council" | "delegate" | "pipeline" | "exploration" | "unknown";
|
|
2
|
-
export type MetricEventType = "model_call" | "cache_hit" | "duplicate_suppressed" | "rule_bypass" | "retry";
|
|
3
|
-
export interface MetricEvent {
|
|
4
|
-
ts: string;
|
|
5
|
-
workflow_id: string;
|
|
6
|
-
stage: WorkflowStage;
|
|
7
|
-
event: MetricEventType;
|
|
8
|
-
agent?: string;
|
|
9
|
-
/**
|
|
10
|
-
* Model identifier used for this call (e.g. "claude-sonnet-4.6").
|
|
11
|
-
* Enables cost estimation via cost-estimator.ts.
|
|
12
|
-
*/
|
|
13
|
-
model?: string;
|
|
14
|
-
/** Estimated input tokens (chars / 4) */
|
|
15
|
-
est_input_tokens: number;
|
|
16
|
-
/** Estimated output tokens (chars / 4) */
|
|
17
|
-
est_output_tokens: number;
|
|
18
|
-
/** Raw input character count */
|
|
19
|
-
input_chars: number;
|
|
20
|
-
/** Raw output character count */
|
|
21
|
-
output_chars: number;
|
|
22
|
-
duration_ms?: number;
|
|
23
|
-
/** Estimated USD cost for this event (populated when model is known). */
|
|
24
|
-
est_cost_usd?: number;
|
|
25
|
-
}
|
|
26
|
-
export interface StageSummary {
|
|
27
|
-
stage: WorkflowStage;
|
|
28
|
-
model_calls: number;
|
|
29
|
-
cache_hits: number;
|
|
30
|
-
duplicates_suppressed: number;
|
|
31
|
-
rule_bypasses: number;
|
|
32
|
-
retries: number;
|
|
33
|
-
total_est_input_tokens: number;
|
|
34
|
-
total_est_output_tokens: number;
|
|
35
|
-
avg_input_chars: number;
|
|
36
|
-
avg_output_chars: number;
|
|
37
|
-
/** Estimated USD cost for this stage (requires model field on events). */
|
|
38
|
-
est_cost_usd: number;
|
|
39
|
-
}
|
|
40
|
-
export interface MetricsReport {
|
|
41
|
-
workflow_id: string;
|
|
42
|
-
by_stage: StageSummary[];
|
|
43
|
-
totals: {
|
|
44
|
-
model_calls: number;
|
|
45
|
-
cache_hits: number;
|
|
46
|
-
duplicates_suppressed: number;
|
|
47
|
-
rule_bypasses: number;
|
|
48
|
-
retries: number;
|
|
49
|
-
est_input_tokens: number;
|
|
50
|
-
est_output_tokens: number;
|
|
51
|
-
/** Estimated total USD cost across all model calls. 0 if no model info available. */
|
|
52
|
-
est_cost_usd: number;
|
|
53
|
-
/** Estimated USD wasted on retries. */
|
|
54
|
-
retry_cost_usd: number;
|
|
55
|
-
cache_hit_rate: number;
|
|
56
|
-
duplicate_suppression_rate: number;
|
|
57
|
-
rule_bypass_rate: number;
|
|
58
|
-
retry_rate: number;
|
|
59
|
-
};
|
|
60
|
-
efficiency: {
|
|
61
|
-
most_expensive_stage: string;
|
|
62
|
-
cache_effectiveness: "good" | "moderate" | "low";
|
|
63
|
-
avg_context_chars_by_stage: Record<string, number>;
|
|
64
|
-
};
|
|
65
|
-
/** Workflow-level timing if startWorkflowTimer was called. */
|
|
66
|
-
elapsed_ms?: number;
|
|
67
|
-
}
|
|
68
|
-
/** Rough token estimate: ~4 chars per token. */
|
|
69
|
-
export declare function estimateTokens(text: string): number;
|
|
70
|
-
export declare function recordModelCall(dir: string, workflow_id: string, stage: WorkflowStage, inputText: string, outputText: string, agent?: string, duration_ms?: number, model?: string, est_cost_usd?: number): void;
|
|
71
|
-
export declare function recordCacheHit(dir: string, workflow_id: string, stage: WorkflowStage, inputText: string, agent?: string, model?: string): void;
|
|
72
|
-
export declare function recordDuplicateSuppressed(dir: string, workflow_id: string, stage: WorkflowStage, agent?: string): void;
|
|
73
|
-
/**
|
|
74
|
-
* Record a retry model call.
|
|
75
|
-
* This is a model call that happened because the previous attempt failed transiently.
|
|
76
|
-
* Contributes to retry_cost_usd in the cost report.
|
|
77
|
-
*/
|
|
78
|
-
export declare function recordRetryCall(dir: string, workflow_id: string, stage: WorkflowStage, inputText: string, outputText: string, agent?: string, duration_ms?: number, model?: string, est_cost_usd?: number): void;
|
|
79
|
-
/**
|
|
80
|
-
* Record a rule-based bypass — a check answered deterministically without a model call.
|
|
81
|
-
* `check_type` identifies which rule-based check was used.
|
|
82
|
-
*/
|
|
83
|
-
export declare function recordRuleBypass(dir: string, workflow_id: string, stage: WorkflowStage, check_type: string, agent?: string): void;
|
|
84
|
-
/**
|
|
85
|
-
* Mark the start of a workflow run for latency tracking.
|
|
86
|
-
* Call this before the first model call for a workflow.
|
|
87
|
-
*/
|
|
88
|
-
export declare function startWorkflowTimer(workflow_id: string): void;
|
|
89
|
-
/**
|
|
90
|
-
* Get elapsed milliseconds since startWorkflowTimer was called.
|
|
91
|
-
* Returns undefined if the timer was not started.
|
|
92
|
-
*/
|
|
93
|
-
export declare function getWorkflowElapsed(workflow_id: string): number | undefined;
|
|
94
|
-
export declare function getMetricsReport(dir: string, workflow_id: string): MetricsReport;
|
|
95
|
-
/** List all workflow IDs that have metric events. */
|
|
96
|
-
export declare function listTrackedWorkflows(dir: string): string[];
|
|
97
|
-
//# sourceMappingURL=token-metrics.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"token-metrics.d.ts","sourceRoot":"","sources":["../../src/services/token-metrics.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,aAAa,GACrB,SAAS,GACT,MAAM,GACN,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,YAAY,GACZ,SAAS,GACT,UAAU,GACV,UAAU,GACV,aAAa,GACb,SAAS,CAAA;AAEb,MAAM,MAAM,eAAe,GACvB,YAAY,GACZ,WAAW,GACX,sBAAsB,GACtB,aAAa,GACb,OAAO,CAAA;AAEX,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAA;IACV,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,EAAE,aAAa,CAAA;IACpB,KAAK,EAAE,eAAe,CAAA;IACtB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,yCAAyC;IACzC,gBAAgB,EAAE,MAAM,CAAA;IACxB,0CAA0C;IAC1C,iBAAiB,EAAE,MAAM,CAAA;IACzB,gCAAgC;IAChC,WAAW,EAAE,MAAM,CAAA;IACnB,iCAAiC;IACjC,YAAY,EAAE,MAAM,CAAA;IACpB,WAA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,EAAE,MAAM,GAAG,IAAI,CAE5D;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG1E;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,aAAa,CAsHhF;AAED,qDAAqD;AACrD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAe1D"}
|
package/dist/tools/delegate.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"delegate.d.ts","sourceRoot":"","sources":["../../src/tools/delegate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAkBtD,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAqPzE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch-routing.d.ts","sourceRoot":"","sources":["../../src/tools/dispatch-routing.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAChB,UAAU,GACV,QAAQ,GACR,gBAAgB,GAChB,WAAW,GACX,QAAQ,GACR,SAAS,GACT,eAAe,GACf,UAAU,GACV,UAAU,GACV,eAAe,CAAA;AAEnB,wBAAgB,WAAW,CAAC,SAAS,EAAE,GAAG,GAAG,OAAO,CAOnD;AAED,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAUvD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,CAevF;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,QAAQ,CAa3D;AAmCD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAOpD;AAED,MAAM,MAAM,UAAU,GAClB,cAAc,GACd,WAAW,GACX,aAAa,GACb,gBAAgB,GAChB,YAAY,GACZ,UAAU,GACV,eAAe,GACf,YAAY,GACZ,YAAY,CAAA;AAEhB,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAYnE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"run-pipeline.d.ts","sourceRoot":"","sources":["../../src/tools/run-pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAC/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AA8BtD,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc,CAuI5E"}
|