polymath-agent 0.1.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/LICENSE +21 -0
- package/README.md +147 -0
- package/dist/cli.js +1764 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 psychiatristlee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Polymath ๐ช
|
|
2
|
+
|
|
3
|
+
A **cost-optimized, multi-model AI agent** for your **terminal, VS Code, and Chrome**.
|
|
4
|
+
Like Claude Code, it breaks a request into typed steps โ but it routes **each step to
|
|
5
|
+
the cheapest model that's actually good at it** (via [OpenRouter](https://openrouter.ai),
|
|
6
|
+
300+ models), records **real token usage and cost by date + model**, and **recommends
|
|
7
|
+
the best-value model combo before you run**.
|
|
8
|
+
|
|
9
|
+
| Surface | What it does | Install |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| **CLI / TUI** (`poly`) | Full coding agent in your terminal | `npm i -g polymath-agent` |
|
|
12
|
+
| **VS Code** | Runs the agent in the integrated terminal | [`vscode-extension/`](vscode-extension/) โ VSIX |
|
|
13
|
+
| **Chrome** | Automates work in the browser (read / click / type / extract) | [`chrome-extension/`](chrome-extension/) โ load unpacked |
|
|
14
|
+
|
|
15
|
+
All three share the same skill-aware routing brain and cost ledger.
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
โ Polymath ยท policy: value โโโโโโโโโโโโโโโโ 4 calls ยท 12.1k tok ยท $0.0031 โ
|
|
19
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
20
|
+
๐ Plan (5 steps) ยท planner: google/gemini-2.0-flash-001
|
|
21
|
+
โถ Step 1 [plan] โ google/gemini-2.0-flash-001 ~$0.0004
|
|
22
|
+
โถ Step 2 [search] โ mistralai/ministral-3b ~$0.0001
|
|
23
|
+
โถ Step 4 [edit] โ qwen/qwen3-coder ~$0.0021
|
|
24
|
+
โ Added dark-mode toggle to settings panel
|
|
25
|
+
โ Done ยท 4 calls ยท 12.1k tokens ยท $0.0031
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Why
|
|
29
|
+
|
|
30
|
+
Running every task on a frontier model is wasteful. Searching, summarizing, and reading
|
|
31
|
+
don't need a $15/Mtok model โ a $0.05/Mtok one is fine, and a cheap **coder-tuned** model
|
|
32
|
+
beats a pricey generalist at edits. Polymath assigns the cheapest model that genuinely
|
|
33
|
+
*covers* each task and proves the savings with a per-call cost ledger.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
> Requires **Node.js โฅ 22.5** (the CLI uses the built-in `node:sqlite`).
|
|
38
|
+
|
|
39
|
+
### 1 ยท CLI (`poly`)
|
|
40
|
+
|
|
41
|
+
**From npm:**
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install -g polymath-agent
|
|
45
|
+
poly login # guided OpenRouter key setup
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**From source** (no npm publish needed):
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
git clone https://github.com/psychiatristlee/mathology.git
|
|
52
|
+
cd mathology
|
|
53
|
+
npm install # auto-builds dist/cli.js
|
|
54
|
+
npm link # puts `poly` on your PATH
|
|
55
|
+
poly login
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2 ยท VS Code extension
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
cd vscode-extension
|
|
62
|
+
npm install && npm run build && npm run package # -> polymath-vscode-0.1.0.vsix
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Install the `.vsix` via **Extensions โ โฆ โ Install from VSIXโฆ**, then use the Command
|
|
66
|
+
Palette โ **"Polymath:"**. (It drives the `poly` CLI, and offers to install it if missing.)
|
|
67
|
+
|
|
68
|
+
### 3 ยท Chrome extension
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
cd chrome-extension
|
|
72
|
+
npm install && npm run build
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Then `chrome://extensions` โ enable **Developer mode** โ **Load unpacked** โ pick the
|
|
76
|
+
`chrome-extension/` folder. Open the side panel, paste your OpenRouter key in **Settings**,
|
|
77
|
+
and give it a goal for the active tab. See [chrome-extension/README.md](chrome-extension/README.md).
|
|
78
|
+
|
|
79
|
+
## First run (CLI)
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
poly recommend "add a dark-mode toggle to the settings page" # model/cost options first
|
|
83
|
+
poly run -w -x "add a dark-mode toggle" # -w allow file writes, -x allow shell commands
|
|
84
|
+
poly usage # cost by date + model
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Commands
|
|
88
|
+
|
|
89
|
+
| Command | What it does |
|
|
90
|
+
|---|---|
|
|
91
|
+
| `poly login` | Connect/replace your OpenRouter API key (Claude-Code-style onboarding). |
|
|
92
|
+
| `poly run [goal]` | Launch the interactive agent. Shows the recommended routing, then executes. |
|
|
93
|
+
| `poly recommend <goal>` | Pre-run recommendation: cheapest / best-value / best-quality model combos + savings. |
|
|
94
|
+
| `poly models` | Browse the catalog with pricing, tier, tool support. Filters: `--tier`, `--tools`, `--search`. |
|
|
95
|
+
| `poly usage` | Recorded usage & cost grouped by **date + model**. `--today`, `--since`, `--sync`. |
|
|
96
|
+
| `poly sync` | Push the local usage ledger to Firestore. |
|
|
97
|
+
| `poly config show\|set\|firestore` | View/change settings. |
|
|
98
|
+
|
|
99
|
+
### Routing objectives
|
|
100
|
+
|
|
101
|
+
Routing is **skill-aware**: each task type maps to a skill (coding / reasoning /
|
|
102
|
+
retrieval / speed), and every model family has a strength profile for those skills
|
|
103
|
+
(Claude โ coding & agentic, DeepSeek-R1 / o-series โ reasoning, Gemini Flash โ cheap
|
|
104
|
+
retrieval, โฆ). See [`src/models/strengths.ts`](src/models/strengths.ts).
|
|
105
|
+
|
|
106
|
+
- `cheapest` โ cheapest model that still **covers** the task's skill.
|
|
107
|
+
- `value` โ best **strength-per-dollar for that task** (default). Coding work lands
|
|
108
|
+
on the cheapest genuinely-good coder; a cheap coder-tuned model beats a pricey
|
|
109
|
+
generalist for `edit`.
|
|
110
|
+
- `quality` โ strongest model at the task's skill (e.g. Claude for coding edits).
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
poly run --objective quality "design a rate limiter"
|
|
114
|
+
poly run --max-cost 0.02 "small bug fix" # never pick a model that'd cost > $0.02/call
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## How it works
|
|
118
|
+
|
|
119
|
+
1. **Plan** โ a cheap model decomposes the request into typed steps
|
|
120
|
+
(`plan`, `search`, `read`, `edit`, `command`, `review`, `reason`, โฆ).
|
|
121
|
+
2. **Route** โ each task maps to a skill; a model is *eligible* if it meets the tier
|
|
122
|
+
floor **or** is strong enough at that skill (so cheap coder models qualify for
|
|
123
|
+
edits). The router then picks by objective. See [`src/router/`](src/router/),
|
|
124
|
+
[`src/models/tiers.ts`](src/models/tiers.ts), [`src/models/strengths.ts`](src/models/strengths.ts).
|
|
125
|
+
3. **Execute** โ a bounded tool-use loop runs the step (read/write files, run
|
|
126
|
+
commands). Every model call's real usage + cost is logged.
|
|
127
|
+
4. **Ledger** โ usage is stored in local SQLite (`~/.config/polymath/usage.sqlite`)
|
|
128
|
+
and optionally synced to Firestore.
|
|
129
|
+
|
|
130
|
+
## Data & secrets
|
|
131
|
+
|
|
132
|
+
- API key: `~/.config/polymath/config.json` (chmod 600). Override per-shell with
|
|
133
|
+
`OPENROUTER_API_KEY`.
|
|
134
|
+
- Usage DB: `~/.config/polymath/usage.sqlite` (built-in `node:sqlite`, no native deps).
|
|
135
|
+
- Optional Firestore sync uses the project's existing `mathology-b8e3d` Firebase
|
|
136
|
+
project; enable with `poly config firestore on` and provide credentials via
|
|
137
|
+
`FIREBASE_SERVICE_ACCOUNT_KEY` or ADC.
|
|
138
|
+
|
|
139
|
+
## Develop
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
npm run dev -- recommend "..." # run from source via tsx
|
|
143
|
+
npm run typecheck # tsc --noEmit
|
|
144
|
+
npm run build # esbuild -> dist/cli.js
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Requires Node โฅ 22.5 (for `node:sqlite`).
|