codesession-cli 1.0.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +201 -119
- package/dist/agents.d.ts +155 -0
- package/dist/agents.d.ts.map +1 -0
- package/dist/agents.js +308 -0
- package/dist/agents.js.map +1 -0
- package/dist/db.d.ts +1 -0
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +44 -5
- package/dist/db.js.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +290 -54
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +30 -5
- package/skills/codesession/SKILL.md +92 -0
- package/src/db.ts +0 -239
- package/src/formatters.ts +0 -152
- package/src/git.ts +0 -44
- package/src/index.ts +0 -206
- package/src/types.ts +0 -49
- package/src/watcher.ts +0 -52
- package/test.ts +0 -4
- package/tsconfig.json +0 -20
package/README.md
CHANGED
|
@@ -1,186 +1,272 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>codesession-cli</h1>
|
|
3
|
+
<p><strong>Track what your AI agents actually cost</strong></p>
|
|
4
|
+
|
|
5
|
+
<p>
|
|
6
|
+
<a href="https://www.npmjs.com/package/codesession-cli"><img src="https://img.shields.io/npm/v/codesession-cli?color=brightgreen" alt="npm version"></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/codesession-cli"><img src="https://img.shields.io/npm/dm/codesession-cli" alt="npm downloads"></a>
|
|
8
|
+
<a href="https://github.com/brian-mwirigi/codesession-cli/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/codesession-cli" alt="license"></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p><em>Track agent runs • Monitor files • Log commits • Enforce budgets</em></p>
|
|
12
|
+
</div>
|
|
2
13
|
|
|
3
|
-
|
|
14
|
+
---
|
|
4
15
|
|
|
5
|
-
##
|
|
16
|
+
## The Problem
|
|
6
17
|
|
|
7
|
-
|
|
8
|
-
- **File Monitoring** - Automatically track file changes
|
|
9
|
-
- **Git Integration** - Log commits during sessions
|
|
10
|
-
- **AI Cost Tracking** - Record AI API usage per session
|
|
11
|
-
- **Statistics** - View productivity metrics
|
|
12
|
-
- **Local Storage** - All data stored locally in SQLite
|
|
18
|
+
Your AI agent just ran for 45 minutes. It made 23 API calls, edited 15 files, and created 4 commits.
|
|
13
19
|
|
|
14
|
-
|
|
20
|
+
**You have no idea what it cost.**
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
# Install
|
|
18
|
-
npm install -g codesession
|
|
22
|
+
OpenClaw, Claude Code, custom agents — they all burn tokens with zero visibility. You find out when the bill arrives.
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
cs start "Build user auth"
|
|
24
|
+
## The Solution
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
One command to start tracking. Everything logged automatically.
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
```bash
|
|
29
|
+
# Start tracking an agent run
|
|
30
|
+
cs start "Fix authentication bug"
|
|
31
|
+
|
|
32
|
+
# Agent does its thing... (files, commits, AI calls tracked automatically)
|
|
27
33
|
|
|
28
|
-
#
|
|
29
|
-
cs
|
|
34
|
+
# End and see the damage
|
|
35
|
+
cs end
|
|
36
|
+
# Session: 47m • 15 files • 4 commits • $8.47 AI cost
|
|
30
37
|
```
|
|
31
38
|
|
|
39
|
+
## Works With
|
|
40
|
+
|
|
41
|
+
- **[OpenClaw](https://openclaw.ai)** — Ships as an OpenClaw skill ([install from ClawHub](#openclaw-skill))
|
|
42
|
+
- **Claude Code** — Track autonomous coding sessions
|
|
43
|
+
- **Custom agents** — Programmatic API with budget enforcement
|
|
44
|
+
- **Manual sessions** — Track your own coding time and costs
|
|
45
|
+
|
|
32
46
|
## Installation
|
|
33
47
|
|
|
34
48
|
```bash
|
|
35
|
-
npm install -g codesession
|
|
49
|
+
npm install -g codesession-cli
|
|
36
50
|
```
|
|
37
51
|
|
|
38
|
-
##
|
|
52
|
+
## Quick Start
|
|
39
53
|
|
|
40
|
-
###
|
|
54
|
+
### CLI Usage
|
|
41
55
|
|
|
42
56
|
```bash
|
|
43
|
-
# Start
|
|
44
|
-
cs start "
|
|
57
|
+
# Start a session
|
|
58
|
+
cs start "Build user auth"
|
|
59
|
+
|
|
60
|
+
# Log AI usage — cost auto-calculated from built-in pricing
|
|
61
|
+
cs log-ai -p anthropic -m claude-sonnet-4 --prompt-tokens 8000 --completion-tokens 2000
|
|
62
|
+
|
|
63
|
+
# Or provide cost manually
|
|
64
|
+
cs log-ai -p anthropic -m claude-opus-4-6 -t 15000 -c 0.30
|
|
65
|
+
|
|
66
|
+
# Check current costs mid-session
|
|
67
|
+
cs status
|
|
68
|
+
|
|
69
|
+
# End session
|
|
70
|
+
cs end -n "Auth complete, all tests passing"
|
|
71
|
+
|
|
72
|
+
# View session history
|
|
73
|
+
cs list
|
|
74
|
+
cs show --files --commits
|
|
75
|
+
cs stats
|
|
45
76
|
|
|
46
|
-
#
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
# - Time spent
|
|
77
|
+
# Export sessions
|
|
78
|
+
cs export --format csv
|
|
79
|
+
cs export --format json --limit 10
|
|
50
80
|
```
|
|
51
81
|
|
|
52
|
-
###
|
|
82
|
+
### JSON Output (for agents)
|
|
83
|
+
|
|
84
|
+
Every command supports `--json` for machine-readable output:
|
|
53
85
|
|
|
54
86
|
```bash
|
|
55
|
-
|
|
56
|
-
|
|
87
|
+
cs status --json
|
|
88
|
+
# {"id":42,"name":"Fix auth","status":"active","aiCost":3.47,"aiTokens":89000,...}
|
|
57
89
|
|
|
58
|
-
|
|
90
|
+
cs log-ai -p openai -m gpt-4o --prompt-tokens 3000 --completion-tokens 2000 --json
|
|
91
|
+
# {"logged":{"provider":"openai","model":"gpt-4o","tokens":5000,"promptTokens":3000,"completionTokens":2000,"cost":0.0275},"session":{"id":42,"aiCost":3.52,"aiTokens":94000}}
|
|
59
92
|
```
|
|
60
93
|
|
|
61
|
-
|
|
94
|
+
---
|
|
62
95
|
|
|
63
|
-
|
|
64
|
-
# Show last session
|
|
65
|
-
cs show
|
|
96
|
+
## OpenClaw Skill
|
|
66
97
|
|
|
67
|
-
|
|
68
|
-
cs show 5
|
|
98
|
+
codesession-cli ships as an [OpenClaw](https://openclaw.ai) skill. The agent automatically tracks its own session costs.
|
|
69
99
|
|
|
70
|
-
|
|
71
|
-
cs show --files --commits
|
|
100
|
+
### Install the skill
|
|
72
101
|
|
|
73
|
-
|
|
74
|
-
|
|
102
|
+
Copy the skill to your OpenClaw workspace:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
# Option 1: Copy from npm package
|
|
106
|
+
cp -r $(npm root -g)/codesession-cli/skills/codesession ~/.openclaw/skills/
|
|
75
107
|
|
|
76
|
-
#
|
|
77
|
-
|
|
108
|
+
# Option 2: Clone and copy
|
|
109
|
+
git clone https://github.com/brian-mwirigi/codesession-cli.git
|
|
110
|
+
cp -r codesession-cli/skills/codesession ~/.openclaw/skills/
|
|
78
111
|
```
|
|
79
112
|
|
|
80
|
-
###
|
|
113
|
+
### What it does
|
|
114
|
+
|
|
115
|
+
Once installed, the OpenClaw agent will:
|
|
116
|
+
|
|
117
|
+
1. Run `cs start "task name"` at the beginning of each task
|
|
118
|
+
2. Log API usage with `cs log-ai` after each AI call
|
|
119
|
+
3. Check costs with `cs status --json` during long tasks
|
|
120
|
+
4. Run `cs end` when the task completes
|
|
121
|
+
|
|
122
|
+
### Example: Agent run tracked by codesession
|
|
81
123
|
|
|
82
|
-
```bash
|
|
83
|
-
# Overall stats
|
|
84
|
-
cs stats
|
|
85
124
|
```
|
|
125
|
+
You: Fix the payment processing bug and add retry logic
|
|
86
126
|
|
|
87
|
-
|
|
127
|
+
Agent: Starting session tracking...
|
|
128
|
+
$ cs start "Fix payment processing + retry"
|
|
129
|
+
✓ Session started
|
|
88
130
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
cs log-ai -p anthropic -m claude-
|
|
131
|
+
[Agent works: reads files, edits code, runs tests...]
|
|
132
|
+
$ cs log-ai -p anthropic -m claude-opus-4-6 --prompt-tokens 8000 --completion-tokens 4000
|
|
133
|
+
$ cs log-ai -p anthropic -m claude-opus-4-6 --prompt-tokens 12000 --completion-tokens 6000
|
|
134
|
+
$ cs log-ai -p anthropic -m claude-opus-4-6 --prompt-tokens 5000 --completion-tokens 3000
|
|
135
|
+
|
|
136
|
+
$ cs end -n "Fixed payment bug, added exponential backoff retry"
|
|
137
|
+
✓ Session ended
|
|
138
|
+
|
|
139
|
+
Session: 12m • 6 files • 2 commits • $0.76 AI cost
|
|
92
140
|
```
|
|
93
141
|
|
|
94
|
-
|
|
142
|
+
After 50 agent runs:
|
|
95
143
|
|
|
96
144
|
```bash
|
|
97
|
-
|
|
98
|
-
|
|
145
|
+
$ cs stats
|
|
146
|
+
┌──────────────┬────────────────┐
|
|
147
|
+
│ Total Sessions│ 50 │
|
|
148
|
+
│ Total Time │ 8h 34m │
|
|
149
|
+
│ Files Changed│ 312 │
|
|
150
|
+
│ Commits │ 87 │
|
|
151
|
+
│ Total AI Cost│ $47.23 │
|
|
152
|
+
└──────────────┴────────────────┘
|
|
99
153
|
```
|
|
100
154
|
|
|
101
|
-
|
|
155
|
+
---
|
|
102
156
|
|
|
103
|
-
|
|
104
|
-
$ cs show
|
|
157
|
+
## Programmatic API (for agent frameworks)
|
|
105
158
|
|
|
106
|
-
|
|
159
|
+
Build codesession tracking directly into your agent:
|
|
107
160
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
├──────────────┼────────────────────────────┤
|
|
111
|
-
│ Status │ Completed │
|
|
112
|
-
│ Started │ Feb 01, 2026 14:30 │
|
|
113
|
-
│ Ended │ Feb 01, 2026 16:45 │
|
|
114
|
-
│ Duration │ 2h 15m │
|
|
115
|
-
│ Files Changed│ 12 │
|
|
116
|
-
│ Commits │ 5 │
|
|
117
|
-
│ AI Tokens │ 45,000 │
|
|
118
|
-
│ AI Cost │ $2.34 │
|
|
119
|
-
│ Notes │ Completed basic auth flow │
|
|
120
|
-
└──────────────┴────────────────────────────┘
|
|
121
|
-
```
|
|
161
|
+
```typescript
|
|
162
|
+
import { AgentSession, BudgetExceededError } from 'codesession-cli/agents';
|
|
122
163
|
|
|
123
|
-
|
|
164
|
+
const session = new AgentSession('Refactor auth module', {
|
|
165
|
+
budget: 5.00, // Hard cap: stop at $5
|
|
166
|
+
directory: './src', // Watch this directory
|
|
167
|
+
git: true, // Track commits
|
|
168
|
+
});
|
|
124
169
|
|
|
125
|
-
|
|
126
|
-
Track exact time and costs per feature for client billing.
|
|
170
|
+
session.start();
|
|
127
171
|
|
|
128
|
-
|
|
129
|
-
|
|
172
|
+
// After each AI call — with granular tokens (cost auto-calculated)
|
|
173
|
+
session.logAI('anthropic', 'claude-opus-4-6', 15000, 0.30, {
|
|
174
|
+
promptTokens: 10000,
|
|
175
|
+
completionTokens: 5000,
|
|
176
|
+
});
|
|
130
177
|
|
|
131
|
-
|
|
132
|
-
|
|
178
|
+
// Pre-flight check
|
|
179
|
+
if (!session.canAfford(2.00)) {
|
|
180
|
+
console.log('Switching to cheaper model...');
|
|
181
|
+
}
|
|
133
182
|
|
|
134
|
-
|
|
135
|
-
|
|
183
|
+
// Budget enforcement is automatic
|
|
184
|
+
try {
|
|
185
|
+
session.logAI('openai', 'gpt-4o', 50000, 4.80);
|
|
186
|
+
} catch (e) {
|
|
187
|
+
if (e instanceof BudgetExceededError) {
|
|
188
|
+
console.log(`Stopped at $${e.spent} (limit: $${e.budget})`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
136
191
|
|
|
137
|
-
|
|
138
|
-
|
|
192
|
+
const summary = session.end();
|
|
193
|
+
// { duration: 847, filesChanged: 12, aiCost: 4.80, commits: 3, ... }
|
|
194
|
+
```
|
|
139
195
|
|
|
140
|
-
|
|
196
|
+
### `runAgentSession` helper
|
|
141
197
|
|
|
142
|
-
|
|
198
|
+
Wraps start/end/error handling automatically:
|
|
143
199
|
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
|
|
200
|
+
```typescript
|
|
201
|
+
import { runAgentSession } from 'codesession-cli/agents';
|
|
202
|
+
|
|
203
|
+
const summary = await runAgentSession(
|
|
204
|
+
'Fix all linting errors',
|
|
205
|
+
{ budget: 3.00, directory: './src' },
|
|
206
|
+
async (session) => {
|
|
207
|
+
// Your agent logic
|
|
208
|
+
const response = await anthropic.messages.create({ ... });
|
|
209
|
+
session.logAI('anthropic', 'claude-sonnet-4-5', tokens, cost);
|
|
210
|
+
}
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
console.log(`Done: ${summary.filesChanged} files, $${summary.aiCost}`);
|
|
147
214
|
```
|
|
148
215
|
|
|
149
|
-
|
|
216
|
+
---
|
|
150
217
|
|
|
151
|
-
|
|
218
|
+
## All Commands
|
|
152
219
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
cs
|
|
157
|
-
|
|
220
|
+
| Command | Description |
|
|
221
|
+
|---------|-------------|
|
|
222
|
+
| `cs start <name>` | Start tracking a session |
|
|
223
|
+
| `cs end [-n notes]` | End session, show summary |
|
|
224
|
+
| `cs status` | Show active session |
|
|
225
|
+
| `cs show [id] [--files] [--commits]` | Show session details |
|
|
226
|
+
| `cs list [-l limit]` | List recent sessions |
|
|
227
|
+
| `cs stats` | Overall statistics |
|
|
228
|
+
| `cs log-ai -p <provider> -m <model> [options]` | Log AI usage (cost auto-derived or manual) |
|
|
229
|
+
| `cs export [--format json\|csv] [--limit n]` | Export sessions as JSON or CSV |
|
|
158
230
|
|
|
159
|
-
|
|
231
|
+
All commands support `--json` for machine-readable output.
|
|
160
232
|
|
|
161
|
-
|
|
233
|
+
### log-ai options
|
|
162
234
|
|
|
163
|
-
|
|
235
|
+
| Flag | Description |
|
|
236
|
+
|------|-------------|
|
|
237
|
+
| `-p, --provider` | AI provider (required) |
|
|
238
|
+
| `-m, --model` | Model name (required) |
|
|
239
|
+
| `-t, --tokens` | Total tokens |
|
|
240
|
+
| `--prompt-tokens` | Prompt/input tokens |
|
|
241
|
+
| `--completion-tokens` | Completion/output tokens |
|
|
242
|
+
| `-c, --cost` | Cost in USD (auto-calculated if omitted for known models) |
|
|
164
243
|
|
|
165
|
-
##
|
|
244
|
+
## Data Storage
|
|
166
245
|
|
|
167
|
-
|
|
168
|
-
# Clone
|
|
169
|
-
git clone https://github.com/brian-mwirigi/codesession.git
|
|
170
|
-
cd codesession
|
|
246
|
+
All data stored locally in `~/.devsession/sessions.db` (SQLite with WAL mode for concurrent access).
|
|
171
247
|
|
|
172
|
-
|
|
173
|
-
npm install
|
|
248
|
+
No telemetry. No cloud. 100% local.
|
|
174
249
|
|
|
175
|
-
|
|
176
|
-
npm run dev -- start "Test session"
|
|
250
|
+
## Example Output
|
|
177
251
|
|
|
178
|
-
|
|
179
|
-
|
|
252
|
+
```bash
|
|
253
|
+
$ cs show
|
|
180
254
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
255
|
+
Session: Build user auth
|
|
256
|
+
|
|
257
|
+
┌──────────────┬────────────────────────────┐
|
|
258
|
+
│ Metric │ Value │
|
|
259
|
+
├──────────────┼────────────────────────────┤
|
|
260
|
+
│ Status │ Completed │
|
|
261
|
+
│ Started │ Feb 09, 2026 14:30 │
|
|
262
|
+
│ Ended │ Feb 09, 2026 16:45 │
|
|
263
|
+
│ Duration │ 2h 15m │
|
|
264
|
+
│ Files Changed│ 12 │
|
|
265
|
+
│ Commits │ 5 │
|
|
266
|
+
│ AI Tokens │ 45,000 │
|
|
267
|
+
│ AI Cost │ $2.34 │
|
|
268
|
+
│ Notes │ Completed basic auth flow │
|
|
269
|
+
└──────────────┴────────────────────────────┘
|
|
184
270
|
```
|
|
185
271
|
|
|
186
272
|
## License
|
|
@@ -191,10 +277,6 @@ MIT
|
|
|
191
277
|
|
|
192
278
|
Built by [Brian Mwirigi](https://github.com/brian-mwirigi)
|
|
193
279
|
|
|
194
|
-
## Testing
|
|
195
|
-
|
|
196
|
-
This is a test modification to trigger file watcher.
|
|
197
|
-
|
|
198
280
|
---
|
|
199
281
|
|
|
200
|
-
**
|
|
282
|
+
**Know what your agents cost. Ship with confidence.**
|
package/dist/agents.d.ts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Sessions - Programmatic API for AI agents
|
|
3
|
+
*
|
|
4
|
+
* Track agent runs with automatic file watching, git tracking,
|
|
5
|
+
* AI cost logging, and budget enforcement.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { AgentSession } from 'codesession-cli/agents';
|
|
10
|
+
*
|
|
11
|
+
* const session = new AgentSession('Refactor auth module', {
|
|
12
|
+
* budget: 5.00,
|
|
13
|
+
* directory: './src',
|
|
14
|
+
* git: true,
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* session.start();
|
|
18
|
+
* // ... agent does work ...
|
|
19
|
+
* const summary = session.end();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export interface AgentSessionConfig {
|
|
23
|
+
/** Hard budget cap in dollars. Session auto-ends if exceeded. */
|
|
24
|
+
budget?: number;
|
|
25
|
+
/** Directory to watch for file changes. Defaults to cwd. */
|
|
26
|
+
directory?: string;
|
|
27
|
+
/** Enable git commit tracking. Defaults to true. */
|
|
28
|
+
git?: boolean;
|
|
29
|
+
/** Interval (ms) to check for new git commits. Defaults to 5000. */
|
|
30
|
+
gitPollInterval?: number;
|
|
31
|
+
/** Callback when budget is exceeded. Called before session ends. */
|
|
32
|
+
onBudgetExceeded?: (spent: number, budget: number) => void;
|
|
33
|
+
/** Callback when AI usage is logged. */
|
|
34
|
+
onAIUsage?: (cost: number, totalCost: number, model: string) => void;
|
|
35
|
+
/** Callback on each file change. */
|
|
36
|
+
onFileChange?: (filePath: string, changeType: string) => void;
|
|
37
|
+
/** Optional metadata to attach to the session. */
|
|
38
|
+
metadata?: Record<string, any>;
|
|
39
|
+
}
|
|
40
|
+
export interface AgentSessionSummary {
|
|
41
|
+
sessionId: number;
|
|
42
|
+
name: string;
|
|
43
|
+
duration: number;
|
|
44
|
+
filesChanged: number;
|
|
45
|
+
commits: number;
|
|
46
|
+
aiCost: number;
|
|
47
|
+
aiTokens: number;
|
|
48
|
+
budgetRemaining: number | null;
|
|
49
|
+
files: {
|
|
50
|
+
path: string;
|
|
51
|
+
type: string;
|
|
52
|
+
timestamp: string;
|
|
53
|
+
}[];
|
|
54
|
+
commitList: {
|
|
55
|
+
hash: string;
|
|
56
|
+
message: string;
|
|
57
|
+
timestamp: string;
|
|
58
|
+
}[];
|
|
59
|
+
aiUsageBreakdown: {
|
|
60
|
+
provider: string;
|
|
61
|
+
model: string;
|
|
62
|
+
tokens: number;
|
|
63
|
+
cost: number;
|
|
64
|
+
timestamp: string;
|
|
65
|
+
}[];
|
|
66
|
+
metadata?: Record<string, any>;
|
|
67
|
+
}
|
|
68
|
+
export declare class AgentSession {
|
|
69
|
+
private sessionId;
|
|
70
|
+
private name;
|
|
71
|
+
private config;
|
|
72
|
+
private gitInterval;
|
|
73
|
+
private totalCost;
|
|
74
|
+
private totalTokens;
|
|
75
|
+
private started;
|
|
76
|
+
private ended;
|
|
77
|
+
constructor(name: string, config?: AgentSessionConfig);
|
|
78
|
+
/**
|
|
79
|
+
* Start the agent session. Begins file watching and git tracking.
|
|
80
|
+
* @returns The session ID
|
|
81
|
+
*/
|
|
82
|
+
start(): number;
|
|
83
|
+
/**
|
|
84
|
+
* Log AI usage for this session. Automatically checks budget.
|
|
85
|
+
* Cost is optional — auto-calculated from built-in pricing if omitted (requires known model).
|
|
86
|
+
* @returns The remaining budget (null if no budget set)
|
|
87
|
+
* @throws BudgetExceededError if budget is exceeded
|
|
88
|
+
*/
|
|
89
|
+
logAI(provider: string, model: string, tokens: number, cost: number, options?: {
|
|
90
|
+
promptTokens?: number;
|
|
91
|
+
completionTokens?: number;
|
|
92
|
+
}): number | null;
|
|
93
|
+
/**
|
|
94
|
+
* Check how much budget remains.
|
|
95
|
+
* @returns Remaining budget in dollars, or null if no budget set
|
|
96
|
+
*/
|
|
97
|
+
get budgetRemaining(): number | null;
|
|
98
|
+
/** Current total cost spent in this session */
|
|
99
|
+
get spent(): number;
|
|
100
|
+
/** Current total tokens used in this session */
|
|
101
|
+
get tokens(): number;
|
|
102
|
+
/** Whether this session is currently active */
|
|
103
|
+
get isActive(): boolean;
|
|
104
|
+
/** The database session ID (null if not started) */
|
|
105
|
+
get id(): number | null;
|
|
106
|
+
/**
|
|
107
|
+
* End the agent session and return a full summary.
|
|
108
|
+
*/
|
|
109
|
+
end(notes?: string): AgentSessionSummary;
|
|
110
|
+
/**
|
|
111
|
+
* Check if an AI call would exceed the budget.
|
|
112
|
+
* Useful for pre-flight checks before making expensive API calls.
|
|
113
|
+
* @returns true if the call would stay within budget
|
|
114
|
+
*/
|
|
115
|
+
canAfford(estimatedCost: number): boolean;
|
|
116
|
+
private assertStarted;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Thrown when an agent session exceeds its budget.
|
|
120
|
+
* Catch this to handle budget enforcement gracefully.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* try {
|
|
125
|
+
* session.logAI('openai', 'gpt-4o', 5000, 0.10);
|
|
126
|
+
* } catch (e) {
|
|
127
|
+
* if (e instanceof BudgetExceededError) {
|
|
128
|
+
* console.log(`Over budget: spent $${e.spent}, limit $${e.budget}`);
|
|
129
|
+
* }
|
|
130
|
+
* }
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare class BudgetExceededError extends Error {
|
|
134
|
+
spent: number;
|
|
135
|
+
budget: number;
|
|
136
|
+
constructor(spent: number, budget: number);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Quick helper to run an agent function within a tracked session.
|
|
140
|
+
* Handles start/end/error automatically.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* const summary = await runAgentSession('Fix all linting errors', {
|
|
145
|
+
* budget: 3.00,
|
|
146
|
+
* directory: './src',
|
|
147
|
+
* }, async (session) => {
|
|
148
|
+
* // Your agent logic here
|
|
149
|
+
* const response = await openai.chat.completions.create({ ... });
|
|
150
|
+
* session.logAI('openai', 'gpt-4o', response.usage.total_tokens, 0.05);
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export declare function runAgentSession(name: string, config: AgentSessionConfig, agentFn: (session: AgentSession) => Promise<void>): Promise<AgentSessionSummary>;
|
|
155
|
+
//# sourceMappingURL=agents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../src/agents.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAcH,MAAM,WAAW,kBAAkB;IACjC,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oDAAoD;IACpD,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,oEAAoE;IACpE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3D,wCAAwC;IACxC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACrE,oCAAoC;IACpC,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9D,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,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