notsleep 1.0.0 → 1.2.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/.env.example +130 -117
- package/README.md +107 -0
- package/dashboard/index.html +22 -4
- package/dist/agent.d.ts +33 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +227 -47
- package/dist/agent.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +23 -13
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +12 -0
- package/dist/context.js.map +1 -1
- package/dist/cost.d.ts +5 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +17 -2
- package/dist/cost.js.map +1 -1
- package/dist/dashboard.d.ts +2 -0
- package/dist/dashboard.d.ts.map +1 -1
- package/dist/dashboard.js.map +1 -1
- package/dist/fileconfig.d.ts +12 -0
- package/dist/fileconfig.d.ts.map +1 -1
- package/dist/fileconfig.js.map +1 -1
- package/dist/index.js +78 -21
- package/dist/index.js.map +1 -1
- package/dist/memory.d.ts +58 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +222 -0
- package/dist/memory.js.map +1 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +42 -6
- package/dist/provider.js.map +1 -1
- package/dist/repomap.d.ts +39 -0
- package/dist/repomap.d.ts.map +1 -0
- package/dist/repomap.js +286 -0
- package/dist/repomap.js.map +1 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +20 -0
- package/dist/schema.js.map +1 -1
- package/dist/test-dashboard.d.ts.map +1 -1
- package/dist/test-dashboard.js +9 -1
- package/dist/test-dashboard.js.map +1 -1
- package/dist/tools.d.ts +19 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +207 -85
- package/dist/tools.js.map +1 -1
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/.env.example
CHANGED
|
@@ -1,117 +1,130 @@
|
|
|
1
|
-
# ╔══════════════════════════════════════════════════════════╗
|
|
2
|
-
# ║ NotSleep Configuration ║
|
|
3
|
-
# ╚══════════════════════════════════════════════════════════╝
|
|
4
|
-
#
|
|
5
|
-
# Copy file ini jadi .env lalu isi sesuai kebutuhan:
|
|
6
|
-
# copy .env.example .env
|
|
7
|
-
#
|
|
8
|
-
|
|
9
|
-
# ─── Provider ────────────────────────────────────────────
|
|
10
|
-
# Pilih: "openai" atau "anthropic"
|
|
11
|
-
NOTSLEEP_PROVIDER=openai
|
|
12
|
-
|
|
13
|
-
# ─── OpenAI ──────────────────────────────────────────────
|
|
14
|
-
OPENAI_API_KEY=sk-...
|
|
15
|
-
OPENAI_MODEL=gpt-4o
|
|
16
|
-
# Custom base URL (untuk Azure, local proxy, LM Studio, Ollama, dll)
|
|
17
|
-
# OPENAI_BASE_URL=https://api.openai.com/v1
|
|
18
|
-
|
|
19
|
-
# ─── Anthropic ───────────────────────────────────────────
|
|
20
|
-
ANTHROPIC_API_KEY=sk-ant-...
|
|
21
|
-
ANTHROPIC_MODEL=claude-sonnet-4-20250514
|
|
22
|
-
# ANTHROPIC_BASE_URL=https://api.anthropic.com
|
|
23
|
-
|
|
24
|
-
# ─── Registry model (gaya OpenCode / models.dev) ─────────
|
|
25
|
-
# Alih-alih pilih provider + model terpisah, cukup satu string "provider/model".
|
|
26
|
-
# NotSleep sudah punya baseURL bawaan untuk provider populer di bawah — kamu
|
|
27
|
-
# tinggal isi API key-nya. Aktifkan dengan NOTSLEEP_MODEL atau field "model"
|
|
28
|
-
# di notsleep.json, atau flag --model provider/model.
|
|
29
|
-
# NOTSLEEP_MODEL=groq/llama-3.3-70b-versatile
|
|
30
|
-
#
|
|
31
|
-
# Model murah untuk kerja internal agent (summarize context, generate task).
|
|
32
|
-
# Bisa "provider/model" atau id polos (pakai kredensial provider utama).
|
|
33
|
-
# NOTSLEEP_SMALL_MODEL=groq/llama-3.1-8b-instant
|
|
34
|
-
#
|
|
35
|
-
# Provider bawaan (isi key yang relevan saja):
|
|
36
|
-
# openai/... OPENAI_API_KEY
|
|
37
|
-
# anthropic/... ANTHROPIC_API_KEY (SDK native)
|
|
38
|
-
# openrouter/... OPENROUTER_API_KEY (mis. openrouter/anthropic/claude-3.5-sonnet)
|
|
39
|
-
# groq/... GROQ_API_KEY
|
|
40
|
-
# deepseek/... DEEPSEEK_API_KEY
|
|
41
|
-
# together/... TOGETHER_API_KEY
|
|
42
|
-
# xai/... XAI_API_KEY
|
|
43
|
-
# fireworks/... FIREWORKS_API_KEY
|
|
44
|
-
# mistral/... MISTRAL_API_KEY
|
|
45
|
-
# perplexity/... PERPLEXITY_API_KEY
|
|
46
|
-
# gemini/... GEMINI_API_KEY
|
|
47
|
-
# ollama/... (lokal, tanpa key)
|
|
48
|
-
# limitrouter/... OPENAI_API_KEY
|
|
49
|
-
# GROQ_API_KEY=gsk-...
|
|
50
|
-
# OPENROUTER_API_KEY=sk-or-...
|
|
51
|
-
|
|
52
|
-
# ─── Agent Behavior ─────────────────────────────────────
|
|
53
|
-
# Max loop iterations sebelum agent berhenti paksa
|
|
54
|
-
NOTSLEEP_MAX_ITERATIONS=1000
|
|
55
|
-
|
|
56
|
-
# Continuous mode: setelah 1 task selesai, otomatis lanjut task berikutnya
|
|
57
|
-
# true = agent tidak berhenti sampai queue kosong / kamu stop manual
|
|
58
|
-
# false = agent berhenti setelah 1 task selesai
|
|
59
|
-
NOTSLEEP_CONTINUOUS=false
|
|
60
|
-
|
|
61
|
-
# ─── Context Window Management ──────────────────────────
|
|
62
|
-
# Batas token context window. KOSONGKAN / 0 = auto-detect dari model.
|
|
63
|
-
# Auto-detect sync live dari models.dev (di-cache 24 jam), fallback ke
|
|
64
|
-
# endpoint /models provider, lalu ke tabel statis. Isi manual hanya kalau
|
|
65
|
-
# mau override.
|
|
66
|
-
# NOTSLEEP_CONTEXT_WINDOW_LIMIT=120000
|
|
67
|
-
#
|
|
68
|
-
# Matikan sync jaringan model metadata (offline / air-gapped): pakai cache
|
|
69
|
-
# atau tabel statis saja.
|
|
70
|
-
# NOTSLEEP_NO_MODEL_SYNC=1
|
|
71
|
-
|
|
72
|
-
# Kapan mulai summarize (0.75 = kalau context sudah 75% penuh)
|
|
73
|
-
NOTSLEEP_SUMMARIZE_THRESHOLD=0.75
|
|
74
|
-
|
|
75
|
-
# ─── Error Handling ─────────────────────────────────────
|
|
76
|
-
# Max retry kalau API error (rate limit, server error, network)
|
|
77
|
-
NOTSLEEP_MAX_RETRIES=10
|
|
78
|
-
|
|
79
|
-
# Base delay untuk exponential backoff (ms)
|
|
80
|
-
NOTSLEEP_RETRY_BASE_DELAY_MS=1000
|
|
81
|
-
|
|
82
|
-
# Timeout untuk tool execution (ms) - default 2 menit
|
|
83
|
-
NOTSLEEP_TOOL_TIMEOUT_MS=120000
|
|
84
|
-
|
|
85
|
-
# ───
|
|
86
|
-
#
|
|
87
|
-
#
|
|
88
|
-
#
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
#
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
#
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
#
|
|
99
|
-
#
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
#
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
#
|
|
106
|
-
#
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
#
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
#
|
|
113
|
-
#
|
|
114
|
-
#
|
|
115
|
-
#
|
|
116
|
-
#
|
|
117
|
-
#
|
|
1
|
+
# ╔══════════════════════════════════════════════════════════╗
|
|
2
|
+
# ║ NotSleep Configuration ║
|
|
3
|
+
# ╚══════════════════════════════════════════════════════════╝
|
|
4
|
+
#
|
|
5
|
+
# Copy file ini jadi .env lalu isi sesuai kebutuhan:
|
|
6
|
+
# copy .env.example .env
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
# ─── Provider ────────────────────────────────────────────
|
|
10
|
+
# Pilih: "openai" atau "anthropic"
|
|
11
|
+
NOTSLEEP_PROVIDER=openai
|
|
12
|
+
|
|
13
|
+
# ─── OpenAI ──────────────────────────────────────────────
|
|
14
|
+
OPENAI_API_KEY=sk-...
|
|
15
|
+
OPENAI_MODEL=gpt-4o
|
|
16
|
+
# Custom base URL (untuk Azure, local proxy, LM Studio, Ollama, dll)
|
|
17
|
+
# OPENAI_BASE_URL=https://api.openai.com/v1
|
|
18
|
+
|
|
19
|
+
# ─── Anthropic ───────────────────────────────────────────
|
|
20
|
+
ANTHROPIC_API_KEY=sk-ant-...
|
|
21
|
+
ANTHROPIC_MODEL=claude-sonnet-4-20250514
|
|
22
|
+
# ANTHROPIC_BASE_URL=https://api.anthropic.com
|
|
23
|
+
|
|
24
|
+
# ─── Registry model (gaya OpenCode / models.dev) ─────────
|
|
25
|
+
# Alih-alih pilih provider + model terpisah, cukup satu string "provider/model".
|
|
26
|
+
# NotSleep sudah punya baseURL bawaan untuk provider populer di bawah — kamu
|
|
27
|
+
# tinggal isi API key-nya. Aktifkan dengan NOTSLEEP_MODEL atau field "model"
|
|
28
|
+
# di notsleep.json, atau flag --model provider/model.
|
|
29
|
+
# NOTSLEEP_MODEL=groq/llama-3.3-70b-versatile
|
|
30
|
+
#
|
|
31
|
+
# Model murah untuk kerja internal agent (summarize context, generate task).
|
|
32
|
+
# Bisa "provider/model" atau id polos (pakai kredensial provider utama).
|
|
33
|
+
# NOTSLEEP_SMALL_MODEL=groq/llama-3.1-8b-instant
|
|
34
|
+
#
|
|
35
|
+
# Provider bawaan (isi key yang relevan saja):
|
|
36
|
+
# openai/... OPENAI_API_KEY
|
|
37
|
+
# anthropic/... ANTHROPIC_API_KEY (SDK native)
|
|
38
|
+
# openrouter/... OPENROUTER_API_KEY (mis. openrouter/anthropic/claude-3.5-sonnet)
|
|
39
|
+
# groq/... GROQ_API_KEY
|
|
40
|
+
# deepseek/... DEEPSEEK_API_KEY
|
|
41
|
+
# together/... TOGETHER_API_KEY
|
|
42
|
+
# xai/... XAI_API_KEY
|
|
43
|
+
# fireworks/... FIREWORKS_API_KEY
|
|
44
|
+
# mistral/... MISTRAL_API_KEY
|
|
45
|
+
# perplexity/... PERPLEXITY_API_KEY
|
|
46
|
+
# gemini/... GEMINI_API_KEY
|
|
47
|
+
# ollama/... (lokal, tanpa key)
|
|
48
|
+
# limitrouter/... OPENAI_API_KEY
|
|
49
|
+
# GROQ_API_KEY=gsk-...
|
|
50
|
+
# OPENROUTER_API_KEY=sk-or-...
|
|
51
|
+
|
|
52
|
+
# ─── Agent Behavior ─────────────────────────────────────
|
|
53
|
+
# Max loop iterations sebelum agent berhenti paksa
|
|
54
|
+
NOTSLEEP_MAX_ITERATIONS=1000
|
|
55
|
+
|
|
56
|
+
# Continuous mode: setelah 1 task selesai, otomatis lanjut task berikutnya
|
|
57
|
+
# true = agent tidak berhenti sampai queue kosong / kamu stop manual
|
|
58
|
+
# false = agent berhenti setelah 1 task selesai
|
|
59
|
+
NOTSLEEP_CONTINUOUS=false
|
|
60
|
+
|
|
61
|
+
# ─── Context Window Management ──────────────────────────
|
|
62
|
+
# Batas token context window. KOSONGKAN / 0 = auto-detect dari model.
|
|
63
|
+
# Auto-detect sync live dari models.dev (di-cache 24 jam), fallback ke
|
|
64
|
+
# endpoint /models provider, lalu ke tabel statis. Isi manual hanya kalau
|
|
65
|
+
# mau override.
|
|
66
|
+
# NOTSLEEP_CONTEXT_WINDOW_LIMIT=120000
|
|
67
|
+
#
|
|
68
|
+
# Matikan sync jaringan model metadata (offline / air-gapped): pakai cache
|
|
69
|
+
# atau tabel statis saja.
|
|
70
|
+
# NOTSLEEP_NO_MODEL_SYNC=1
|
|
71
|
+
|
|
72
|
+
# Kapan mulai summarize (0.75 = kalau context sudah 75% penuh)
|
|
73
|
+
NOTSLEEP_SUMMARIZE_THRESHOLD=0.75
|
|
74
|
+
|
|
75
|
+
# ─── Error Handling ─────────────────────────────────────
|
|
76
|
+
# Max retry kalau API error (rate limit, server error, network)
|
|
77
|
+
NOTSLEEP_MAX_RETRIES=10
|
|
78
|
+
|
|
79
|
+
# Base delay untuk exponential backoff (ms)
|
|
80
|
+
NOTSLEEP_RETRY_BASE_DELAY_MS=1000
|
|
81
|
+
|
|
82
|
+
# Timeout untuk tool execution (ms) - default 2 menit
|
|
83
|
+
NOTSLEEP_TOOL_TIMEOUT_MS=120000
|
|
84
|
+
|
|
85
|
+
# ─── Self-Learning Memory ───────────────────────────────
|
|
86
|
+
# Memori pelajaran persisten lintas-run (LOCAL by default, tidak di-push).
|
|
87
|
+
# NOTSLEEP_MEMORY=false # matikan memori
|
|
88
|
+
# NOTSLEEP_MEMORY_FILE=.notsleep/memory.md # lokasi file (di .notsleep/ = lokal)
|
|
89
|
+
# NOTSLEEP_MEMORY_MAX=200 # batas jumlah pelajaran
|
|
90
|
+
# NOTSLEEP_AUTO_REFLECT=false # matikan auto-refleksi tiap task selesai
|
|
91
|
+
|
|
92
|
+
# ─── Web Dashboard ──────────────────────────────────────
|
|
93
|
+
# Aktifkan dashboard otomatis tanpa flag --ui
|
|
94
|
+
# NOTSLEEP_DASHBOARD=true
|
|
95
|
+
# Port untuk web dashboard (aktifkan dengan --ui)
|
|
96
|
+
NOTSLEEP_DASHBOARD_PORT=3120
|
|
97
|
+
|
|
98
|
+
# ─── Storage ────────────────────────────────────────────
|
|
99
|
+
# Folder untuk simpan checkpoint (crash recovery)
|
|
100
|
+
NOTSLEEP_CHECKPOINT_DIR=.notsleep/checkpoints
|
|
101
|
+
|
|
102
|
+
# Folder untuk simpan log files
|
|
103
|
+
NOTSLEEP_LOG_DIR=.notsleep/logs
|
|
104
|
+
|
|
105
|
+
# File yang kalau dibuat, agent akan berhenti
|
|
106
|
+
# Cara stop: echo. > .notsleep/STOP
|
|
107
|
+
NOTSLEEP_STOP_FILE=.notsleep/STOP
|
|
108
|
+
|
|
109
|
+
# ─── Config File (alternatif .env) ──────────────────────
|
|
110
|
+
# Selain .env, kamu bisa pakai file JSON: notsleep.json (project)
|
|
111
|
+
# atau ~/.notsleep/config.json (global). Bikin dengan wizard:
|
|
112
|
+
# notsleep init # bikin notsleep.json di project ini
|
|
113
|
+
# notsleep init --global # bikin config global
|
|
114
|
+
# notsleep config # lihat config final + sumbernya
|
|
115
|
+
#
|
|
116
|
+
# Prioritas (yang atas menang):
|
|
117
|
+
# 1. CLI flags (--model, --provider, dst)
|
|
118
|
+
# 2. notsleep.json (project)
|
|
119
|
+
# 3. ~/.notsleep/config.json (global)
|
|
120
|
+
# 4. .env / environment
|
|
121
|
+
# 5. default bawaan
|
|
122
|
+
#
|
|
123
|
+
# Di notsleep.json, API key bisa pakai referensi env biar aman:
|
|
124
|
+
# "apiKey": "{env:OPENAI_API_KEY}"
|
|
125
|
+
|
|
126
|
+
# ─── Repository Map ─────────────────────────────────────
|
|
127
|
+
# Peta codebase terkompresi (simbol per file, diperingkat) yang disuntik ke
|
|
128
|
+
# prompt supaya agent tak baca file buta-butaan.
|
|
129
|
+
# NOTSLEEP_REPO_MAP=false # matikan
|
|
130
|
+
# NOTSLEEP_REPO_MAP_TOKENS=2000 # budget token peta
|
package/README.md
CHANGED
|
@@ -189,6 +189,81 @@ bare model id, which reuses the primary provider's key + base URL (e.g. primary
|
|
|
189
189
|
`gpt-4o`, `small_model: "gpt-4o-mini"`). CLI: `--small-model`. Unset → internal
|
|
190
190
|
calls use the primary model.
|
|
191
191
|
|
|
192
|
+
### Repository map — the codebase at a glance
|
|
193
|
+
|
|
194
|
+
The biggest waste in an autonomous loop is the agent opening files just to find
|
|
195
|
+
where things live. NotSleep builds a **compressed, ranked map of the codebase**
|
|
196
|
+
and injects it into the system prompt, so the agent navigates straight to the
|
|
197
|
+
right file instead of reading everything.
|
|
198
|
+
|
|
199
|
+
```
|
|
200
|
+
REPOSITORY MAP (the codebase at a glance — top-level symbols per file, most-referenced first).
|
|
201
|
+
Use this to jump STRAIGHT to the right file instead of reading files to find things.
|
|
202
|
+
|
|
203
|
+
src/types.ts
|
|
204
|
+
type Provider · interface AgentConfig · interface Message · interface QueuedTask · ...
|
|
205
|
+
src/logger.ts
|
|
206
|
+
class Logger · enum LogLevel · interface LogEntry
|
|
207
|
+
src/tools.ts
|
|
208
|
+
fn createBuiltinTools · fn parseRetryAfter · fn backoffDelay · ...
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
- **Language-aware** symbol extraction (TS/JS, Python, Go, Rust, Java/Kotlin,
|
|
212
|
+
Ruby, PHP, C-family, C#) — no heavy parser dependency.
|
|
213
|
+
- **Ranked like Aider's repo map**: a symbol's importance is how many *other*
|
|
214
|
+
files reference it, so core types outrank file-local helpers.
|
|
215
|
+
- **Token-budgeted** — the lowest-signal files are dropped, never the core ones.
|
|
216
|
+
|
|
217
|
+
On NotSleep's own repo this is a **~970-token map of 35 files, built in 25 ms** —
|
|
218
|
+
replacing the tens of thousands of tokens an agent would burn reading files
|
|
219
|
+
blindly.
|
|
220
|
+
|
|
221
|
+
```json
|
|
222
|
+
{ "repoMap": { "enabled": true, "maxTokens": 2000 } }
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Disable with `"enabled": false` or `NOTSLEEP_REPO_MAP=false`.
|
|
226
|
+
|
|
227
|
+
### Self-learning memory
|
|
228
|
+
|
|
229
|
+
The agent keeps a persistent memory of lessons across runs, so it gets better
|
|
230
|
+
over time instead of relearning the same things every run. It's a **built-in**
|
|
231
|
+
feature — you don't need to wire it into your prompt:
|
|
232
|
+
|
|
233
|
+
- **Auto-loaded** into the system prompt at the start of every run and every new
|
|
234
|
+
task, so the agent recalls what it learned before.
|
|
235
|
+
- **`remember` tool** — the agent saves a durable lesson (a gotcha, a codebase
|
|
236
|
+
fact, a decision + why) whenever it discovers one.
|
|
237
|
+
- **Auto-reflection** — after each completed task, the cheap `small_model`
|
|
238
|
+
distills 0–3 lessons and stores them automatically.
|
|
239
|
+
|
|
240
|
+
Memory is **local by default** (`.notsleep/memory.md`, git-ignored) — each user
|
|
241
|
+
builds their own memory; it is never pushed or published. Manage it with:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
notsleep memory # list stored lessons
|
|
245
|
+
notsleep memory --remove 3 # drop lesson #3
|
|
246
|
+
notsleep memory --clear # wipe
|
|
247
|
+
notsleep memory --export mem.md # copy elsewhere
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Config (all optional):
|
|
251
|
+
|
|
252
|
+
```json
|
|
253
|
+
{
|
|
254
|
+
"memory": {
|
|
255
|
+
"enabled": true,
|
|
256
|
+
"path": ".notsleep/memory.md",
|
|
257
|
+
"maxEntries": 200,
|
|
258
|
+
"autoReflect": true
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
To share memory across machines/clones, set `path` to a committed file like
|
|
264
|
+
`LEARNINGS.md` (note: it becomes public in a public repo). Disable entirely with
|
|
265
|
+
`"enabled": false` or `NOTSLEEP_MEMORY=false`.
|
|
266
|
+
|
|
192
267
|
### Config ergonomics — JSONC, file refs, instructions, schema
|
|
193
268
|
|
|
194
269
|
- **Comments + trailing commas (JSONC):** `notsleep.json` may contain `//` and
|
|
@@ -257,6 +332,38 @@ All settings can also be configured via `.env` file or CLI flags:
|
|
|
257
332
|
| `NOTSLEEP_RETRY_BASE_DELAY_MS` | `1000` | Base delay for exponential backoff |
|
|
258
333
|
| `NOTSLEEP_TOOL_TIMEOUT_MS` | `120000` | Timeout for tool execution |
|
|
259
334
|
|
|
335
|
+
## Cost
|
|
336
|
+
|
|
337
|
+
**NotSleep itself is free** (MIT). It has no fees and phones no one — but it
|
|
338
|
+
**calls an LLM API**, and you pay **your own provider** with **your own API
|
|
339
|
+
key**. There's no shared/hosted cost: what you spend is entirely your choice.
|
|
340
|
+
|
|
341
|
+
How much depends on the model and how long you run:
|
|
342
|
+
|
|
343
|
+
| Setup | Cost |
|
|
344
|
+
|-------|------|
|
|
345
|
+
| **Ollama** (a local model on your machine) | **$0** — fully offline, no API calls |
|
|
346
|
+
| **Free tiers** (Groq, Gemini) | **$0** up to the provider's quota |
|
|
347
|
+
| **Cheap models** (`claude-haiku`, `deepseek`, `gemini-*-flash`, `*-mini`) | cents per cycle |
|
|
348
|
+
| **Frontier models** (Opus, GPT-5) | more — cache to keep it low |
|
|
349
|
+
|
|
350
|
+
Keeping it cheap:
|
|
351
|
+
|
|
352
|
+
- **Pick a cheap or local model** — it's one string: `--model ollama/llama3`,
|
|
353
|
+
`--model groq/llama-3.3-70b`, `--model deepseek/deepseek-chat`.
|
|
354
|
+
- **Use `small_model`** so the agent's internal calls (summaries, task
|
|
355
|
+
generation) run on something cheap.
|
|
356
|
+
- **Cap spend** with `--max-cost 5` (the agent stops when the estimate crosses
|
|
357
|
+
your budget).
|
|
358
|
+
- **Prompt caching.** The agent is read-heavy — it re-sends the growing context
|
|
359
|
+
every turn — so caching matters a lot. OpenAI, DeepSeek, and most proxies
|
|
360
|
+
cache automatically; NotSleep sets Anthropic `cache_control` for you so
|
|
361
|
+
Anthropic-direct runs are cached too. Cached input is billed ~10× cheaper,
|
|
362
|
+
which can turn a "$30" run into cents.
|
|
363
|
+
|
|
364
|
+
The dashboard's **Est. Cost** is a best-effort, cache-aware estimate — a rough
|
|
365
|
+
guide, not a bill. Your provider's dashboard is the source of truth.
|
|
366
|
+
|
|
260
367
|
## Programmatic API
|
|
261
368
|
|
|
262
369
|
```typescript
|
package/dashboard/index.html
CHANGED
|
@@ -272,6 +272,11 @@
|
|
|
272
272
|
/* ─── Log Panel ──────────────────────────── */
|
|
273
273
|
.log-panel {
|
|
274
274
|
grid-row: 2;
|
|
275
|
+
/* min-height:0 lets this grid item shrink to its 1fr track and scroll
|
|
276
|
+
internally, instead of expanding past the viewport (which pushed the
|
|
277
|
+
stats row off-screen). min-width:0 does the same for long log lines. */
|
|
278
|
+
min-height: 0;
|
|
279
|
+
min-width: 0;
|
|
275
280
|
}
|
|
276
281
|
|
|
277
282
|
.log-body {
|
|
@@ -331,6 +336,8 @@
|
|
|
331
336
|
display: flex;
|
|
332
337
|
flex-direction: column;
|
|
333
338
|
gap: 16px;
|
|
339
|
+
min-height: 0;
|
|
340
|
+
min-width: 0;
|
|
334
341
|
}
|
|
335
342
|
|
|
336
343
|
/* ─── Task Queue ─────────────────────────── */
|
|
@@ -491,15 +498,22 @@
|
|
|
491
498
|
font-size: 12px;
|
|
492
499
|
color: var(--accent);
|
|
493
500
|
display: flex;
|
|
494
|
-
align-items:
|
|
501
|
+
align-items: flex-start;
|
|
495
502
|
gap: 8px;
|
|
503
|
+
flex-shrink: 0;
|
|
504
|
+
/* A long task/mission can be thousands of chars — cap it so it scrolls
|
|
505
|
+
instead of blowing up the panel height. */
|
|
506
|
+
max-height: 64px;
|
|
507
|
+
overflow-y: auto;
|
|
496
508
|
}
|
|
509
|
+
#currentTaskText { word-break: break-word; }
|
|
497
510
|
|
|
498
511
|
.current-task-label {
|
|
499
512
|
font-weight: 700;
|
|
500
513
|
text-transform: uppercase;
|
|
501
514
|
font-size: 10px;
|
|
502
515
|
letter-spacing: 0.5px;
|
|
516
|
+
flex-shrink: 0;
|
|
503
517
|
}
|
|
504
518
|
</style>
|
|
505
519
|
</head>
|
|
@@ -541,7 +555,7 @@
|
|
|
541
555
|
</div>
|
|
542
556
|
<div class="stat-card">
|
|
543
557
|
<div id="statTokens" class="stat-value">0</div>
|
|
544
|
-
<div class="stat-label">
|
|
558
|
+
<div class="stat-label">Total tokens</div>
|
|
545
559
|
</div>
|
|
546
560
|
<div class="stat-card">
|
|
547
561
|
<div id="statCost" class="stat-value">$0</div>
|
|
@@ -723,9 +737,13 @@ function updateState(s) {
|
|
|
723
737
|
const ctxFill = document.getElementById('ctxFill');
|
|
724
738
|
ctxFill.style.width = Math.min(ctxPct, 100) + '%';
|
|
725
739
|
ctxFill.className = 'progress-bar-fill ' + (ctxPct >= 85 ? 'ctx-high' : ctxPct >= 60 ? 'ctx-warn' : 'ctx-ok');
|
|
726
|
-
|
|
740
|
+
// Prefer the exact prompt_tokens reported by the API (matches your provider's
|
|
741
|
+
// "input tokens"); fall back to the usage ratio before the first response.
|
|
742
|
+
const ctxTokens = s.contextTokens != null
|
|
743
|
+
? s.contextTokens
|
|
744
|
+
: Math.round((s.contextUsage || 0) * (s.contextLimit || 0));
|
|
727
745
|
document.getElementById('ctxLabel').textContent =
|
|
728
|
-
`${ctxPct}% · ${formatNumber(ctxTokens)} / ${formatNumber(s.contextLimit || 0)}`;
|
|
746
|
+
`${ctxPct}% · ${formatNumber(ctxTokens)} / ${formatNumber(s.contextLimit || 0)} tokens`;
|
|
729
747
|
|
|
730
748
|
// Cost-per-hour, derived from est. cost and elapsed time (relevant for long runs).
|
|
731
749
|
const elapsedHr = s.stats.startTime ? (Date.now() - s.stats.startTime) / 3600000 : 0;
|
package/dist/agent.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ export declare class Agent {
|
|
|
38
38
|
private currentTaskStartIteration;
|
|
39
39
|
/** Optional dashboard for web UI */
|
|
40
40
|
private dashboard;
|
|
41
|
+
/** Self-learning memory (null when disabled). */
|
|
42
|
+
private memory;
|
|
41
43
|
/**
|
|
42
44
|
* Exact prompt-token count reported by the provider on the last chat call.
|
|
43
45
|
* This is the real API measurement of the context size at that moment —
|
|
@@ -62,6 +64,22 @@ export declare class Agent {
|
|
|
62
64
|
*/
|
|
63
65
|
private consecutiveErrors;
|
|
64
66
|
private static readonly MAX_CONSECUTIVE_ERRORS;
|
|
67
|
+
/**
|
|
68
|
+
* Consecutive turns spent ONLY reading/exploring (no edit, shell, or other
|
|
69
|
+
* state-changing action). Weaker models can loop reading files without ever
|
|
70
|
+
* acting; when this streak crosses the threshold we nudge them to make a
|
|
71
|
+
* concrete change. Reset to 0 whenever a productive tool is used.
|
|
72
|
+
*/
|
|
73
|
+
private exploreStreak;
|
|
74
|
+
private static readonly EXPLORE_NUDGE_AT;
|
|
75
|
+
/**
|
|
76
|
+
* Whether the current task has already received its "wrap up, you're near the
|
|
77
|
+
* per-task budget" warning. Reset when a new task starts. Lets the model
|
|
78
|
+
* finish gracefully (call task_complete) instead of being cut off abruptly.
|
|
79
|
+
*/
|
|
80
|
+
private wrapUpWarned;
|
|
81
|
+
/** Tools that only observe — using ONLY these counts as "exploring". */
|
|
82
|
+
private static readonly READ_ONLY_TOOLS;
|
|
65
83
|
constructor(config: AgentConfig, logger: Logger);
|
|
66
84
|
/**
|
|
67
85
|
* Register a custom tool.
|
|
@@ -158,5 +176,20 @@ export declare class Agent {
|
|
|
158
176
|
*/
|
|
159
177
|
private buildFinalSummary;
|
|
160
178
|
private sleep;
|
|
179
|
+
/**
|
|
180
|
+
* Build the system-prompt content, appending the agent's persistent memory so
|
|
181
|
+
* it "remembers" past lessons at the start of every run and every new task —
|
|
182
|
+
* without the mission having to spell it out.
|
|
183
|
+
*/
|
|
184
|
+
private buildSystemContent;
|
|
185
|
+
/** The `remember` tool: lets the agent save a durable lesson to memory. */
|
|
186
|
+
private buildRememberTool;
|
|
187
|
+
/**
|
|
188
|
+
* Auto-reflection: after a task completes, ask the cheap small model to
|
|
189
|
+
* distill 0-3 durable lessons from what just happened and save them. This is
|
|
190
|
+
* how the agent "learns on its own" without needing to call `remember`
|
|
191
|
+
* explicitly. Best-effort — never blocks or fails the run.
|
|
192
|
+
*/
|
|
193
|
+
private reflectAndRemember;
|
|
161
194
|
}
|
|
162
195
|
//# sourceMappingURL=agent.d.ts.map
|
package/dist/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,WAAW,EAA2B,OAAO,EAAc,QAAQ,EAAE,cAAc,EAAyB,MAAM,SAAS,CAAC;AAErI,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAGlC,OAAO,EAAE,eAAe,EAAoB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAkBA,OA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