one-more-token 0.0.0-stage → 0.5.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.
@@ -0,0 +1,149 @@
1
+ -- Initial normalized schema (spec §4).
2
+ -- Ids are deterministic strings produced by adapters, so re-ingesting the same data upserts
3
+ -- instead of duplicating rows (spec §3, idempotency). No foreign keys: DuckDB cannot upsert
4
+ -- parent rows that are referenced, and integrity is enforced by Zod at ingest time.
5
+
6
+ CREATE TABLE sources (
7
+ id VARCHAR PRIMARY KEY,
8
+ agent VARCHAR NOT NULL,
9
+ path VARCHAR NOT NULL,
10
+ adapter_version VARCHAR NOT NULL,
11
+ last_ingested_at TIMESTAMPTZ
12
+ );
13
+
14
+ CREATE TABLE sessions (
15
+ id VARCHAR PRIMARY KEY,
16
+ source_id VARCHAR NOT NULL,
17
+ agent VARCHAR NOT NULL,
18
+ cwd VARCHAR,
19
+ repo VARCHAR,
20
+ branch VARCHAR,
21
+ started_at TIMESTAMPTZ NOT NULL,
22
+ ended_at TIMESTAMPTZ,
23
+ title VARCHAR,
24
+ format_version VARCHAR NOT NULL
25
+ );
26
+
27
+ CREATE TABLE turns (
28
+ id VARCHAR PRIMARY KEY,
29
+ session_id VARCHAR NOT NULL,
30
+ idx INTEGER NOT NULL,
31
+ role VARCHAR NOT NULL,
32
+ ts TIMESTAMPTZ NOT NULL,
33
+ model VARCHAR,
34
+ provider VARCHAR,
35
+ effort VARCHAR,
36
+ subscription_id VARCHAR
37
+ );
38
+
39
+ CREATE TABLE usage (
40
+ turn_id VARCHAR PRIMARY KEY,
41
+ input_tokens BIGINT NOT NULL DEFAULT 0 CHECK (input_tokens >= 0),
42
+ output_tokens BIGINT NOT NULL DEFAULT 0 CHECK (output_tokens >= 0),
43
+ cache_read_tokens BIGINT NOT NULL DEFAULT 0 CHECK (cache_read_tokens >= 0),
44
+ cache_write_tokens BIGINT NOT NULL DEFAULT 0 CHECK (cache_write_tokens >= 0),
45
+ reported_cost_usd DOUBLE,
46
+ computed_cost_usd DOUBLE
47
+ );
48
+
49
+ CREATE TABLE tool_calls (
50
+ id VARCHAR PRIMARY KEY,
51
+ turn_id VARCHAR NOT NULL,
52
+ tool VARCHAR NOT NULL,
53
+ duration_ms BIGINT,
54
+ status VARCHAR NOT NULL CHECK (status IN ('ok', 'error'))
55
+ );
56
+
57
+ CREATE TABLE subagent_runs (
58
+ id VARCHAR PRIMARY KEY,
59
+ parent_session_id VARCHAR NOT NULL,
60
+ role VARCHAR NOT NULL,
61
+ model VARCHAR,
62
+ provider VARCHAR,
63
+ effort VARCHAR,
64
+ started_at TIMESTAMPTZ,
65
+ duration_ms BIGINT,
66
+ input_tokens BIGINT NOT NULL DEFAULT 0,
67
+ output_tokens BIGINT NOT NULL DEFAULT 0,
68
+ cache_read_tokens BIGINT NOT NULL DEFAULT 0,
69
+ cache_write_tokens BIGINT NOT NULL DEFAULT 0,
70
+ reported_cost_usd DOUBLE,
71
+ computed_cost_usd DOUBLE
72
+ );
73
+
74
+ CREATE TABLE profiles (
75
+ hash VARCHAR PRIMARY KEY,
76
+ name VARCHAR NOT NULL,
77
+ definition JSON NOT NULL,
78
+ first_seen_at TIMESTAMPTZ NOT NULL
79
+ );
80
+
81
+ CREATE TABLE turn_profile (
82
+ turn_id VARCHAR PRIMARY KEY,
83
+ profile_hash VARCHAR NOT NULL,
84
+ attribution VARCHAR NOT NULL CHECK (attribution IN ('exact', 'estimated'))
85
+ );
86
+
87
+ CREATE TABLE pricing (
88
+ model VARCHAR NOT NULL,
89
+ provider VARCHAR NOT NULL,
90
+ valid_from DATE NOT NULL,
91
+ valid_to DATE,
92
+ input_per_mtok DOUBLE NOT NULL,
93
+ output_per_mtok DOUBLE NOT NULL,
94
+ cache_read_per_mtok DOUBLE NOT NULL,
95
+ cache_write_per_mtok DOUBLE NOT NULL,
96
+ PRIMARY KEY (model, provider, valid_from)
97
+ );
98
+
99
+ CREATE TABLE subscriptions (
100
+ id VARCHAR PRIMARY KEY,
101
+ plan_id VARCHAR NOT NULL,
102
+ provider VARCHAR NOT NULL,
103
+ label VARCHAR NOT NULL,
104
+ started_at DATE,
105
+ ended_at DATE
106
+ );
107
+
108
+ CREATE TABLE quota_windows (
109
+ id VARCHAR PRIMARY KEY,
110
+ subscription_id VARCHAR NOT NULL,
111
+ kind VARCHAR NOT NULL CHECK (kind IN ('five_hours', 'weekly', 'monthly')),
112
+ starts_at TIMESTAMPTZ NOT NULL,
113
+ ends_at TIMESTAMPTZ NOT NULL,
114
+ used_tokens BIGINT NOT NULL DEFAULT 0,
115
+ used_usd DOUBLE NOT NULL DEFAULT 0,
116
+ limit_usd DOUBLE,
117
+ estimated_pct DOUBLE
118
+ );
119
+
120
+ CREATE TABLE calibrations (
121
+ id VARCHAR PRIMARY KEY,
122
+ subscription_id VARCHAR NOT NULL,
123
+ window_kind VARCHAR NOT NULL CHECK (window_kind IN ('five_hours', 'weekly', 'monthly')),
124
+ observed_at TIMESTAMPTZ NOT NULL,
125
+ observed_pct DOUBLE NOT NULL CHECK (observed_pct >= 0),
126
+ note VARCHAR
127
+ );
128
+
129
+ CREATE TABLE commits (
130
+ repo VARCHAR NOT NULL,
131
+ sha VARCHAR NOT NULL,
132
+ authored_at TIMESTAMPTZ NOT NULL,
133
+ author VARCHAR,
134
+ message VARCHAR,
135
+ additions INTEGER,
136
+ deletions INTEGER,
137
+ PRIMARY KEY (repo, sha)
138
+ );
139
+
140
+ CREATE TABLE ingest_issues (
141
+ id VARCHAR PRIMARY KEY,
142
+ source_id VARCHAR,
143
+ path VARCHAR,
144
+ location VARCHAR,
145
+ severity VARCHAR NOT NULL CHECK (severity IN ('warning', 'error', 'critical')),
146
+ code VARCHAR NOT NULL,
147
+ message VARCHAR NOT NULL,
148
+ created_at TIMESTAMPTZ NOT NULL DEFAULT current_timestamp
149
+ );
@@ -0,0 +1,7 @@
1
+ -- Whole-file snapshots: a matching hash AND adapter version can skip parsing (spec §3).
2
+ CREATE TABLE ingest_checkpoints (
3
+ source_id VARCHAR PRIMARY KEY,
4
+ content_hash VARCHAR NOT NULL,
5
+ adapter_version VARCHAR NOT NULL,
6
+ ingested_at TIMESTAMPTZ NOT NULL
7
+ );
@@ -0,0 +1,3 @@
1
+ -- Reprice unchanged sources when the reference catalog or pricing policy changes (spec §4).
2
+ -- NULL legacy checkpoints reparse once; the hash commits atomically with the source snapshot.
3
+ ALTER TABLE ingest_checkpoints ADD COLUMN pricing_hash VARCHAR DEFAULT NULL;
@@ -0,0 +1,6 @@
1
+ -- Child sessions (subagents, subtasks) point at their parent; compaction turns mark context resets (spec §7.1).
2
+ -- Existing rows keep no parent and no compaction until their source is re-ingested.
3
+ -- DuckDB cannot add a constrained column, nor SET NOT NULL over existing rows inside the migration
4
+ -- transaction: the default backfills false and the Zod batch contract requires a boolean on write.
5
+ ALTER TABLE sessions ADD COLUMN parent_session_id VARCHAR DEFAULT NULL;
6
+ ALTER TABLE turns ADD COLUMN is_compaction BOOLEAN DEFAULT false;
@@ -0,0 +1,28 @@
1
+ -- Quota attribution is by subscription, not by agent (spec §4, §5): the user's local config says which
2
+ -- provider (and optionally which agent) each subscription covers. Rules are rewritten on every config
3
+ -- sync; `position` is the global match order (subscriptions in file order, then their rules).
4
+ CREATE TABLE subscription_rules (
5
+ position INTEGER PRIMARY KEY,
6
+ subscription_id VARCHAR NOT NULL,
7
+ provider VARCHAR NOT NULL,
8
+ agent VARCHAR
9
+ );
10
+
11
+ -- Derived at query time so editing the config never needs a re-ingest. Dates are inclusive and compared
12
+ -- with the turn's local calendar date; a turn without a matching rule is pay-as-you-go API usage (NULL).
13
+ CREATE VIEW turn_subscriptions AS
14
+ SELECT
15
+ t.id AS turn_id,
16
+ (
17
+ SELECT r.subscription_id
18
+ FROM subscription_rules r
19
+ JOIN subscriptions s ON s.id = r.subscription_id
20
+ WHERE r.provider = t.provider
21
+ AND (r.agent IS NULL OR r.agent = se.agent)
22
+ AND (s.started_at IS NULL OR CAST(t.ts AS DATE) >= s.started_at)
23
+ AND (s.ended_at IS NULL OR CAST(t.ts AS DATE) <= s.ended_at)
24
+ ORDER BY r.position
25
+ LIMIT 1
26
+ ) AS subscription_id
27
+ FROM turns t
28
+ LEFT JOIN sessions se ON se.id = t.session_id;
@@ -0,0 +1,8 @@
1
+ -- Exact profile attribution (spec §6.2): the gentle-shell session profile bound when each turn was
2
+ -- recorded, as parsed from `gentle-pi.session-profile/v1` entries. Owned by the turn's source and
3
+ -- rewritten with it, so `turn_profile` can be recomputed in full without reparsing unchanged files.
4
+ -- Turns with no binding (never bound, cleared, invalid entry) have no row.
5
+ CREATE TABLE turn_profile_bindings (
6
+ turn_id VARCHAR PRIMARY KEY,
7
+ profile_hash VARCHAR NOT NULL
8
+ );
@@ -0,0 +1,13 @@
1
+ -- Quota readings reported by the provider inside agent data (spec §5.3, Phase 4 D2): Codex
2
+ -- `rate_limits` give the % used of the 5 h and weekly windows. They are derived from agent sources,
3
+ -- so they live here, owned by their source and rewritten with it on every re-ingest, never in the
4
+ -- user's calibrations file. Additive only: no existing table changes.
5
+ CREATE TABLE provider_quota_readings (
6
+ id VARCHAR PRIMARY KEY,
7
+ source_id VARCHAR NOT NULL,
8
+ origin VARCHAR NOT NULL CHECK (origin IN ('codex')),
9
+ window_kind VARCHAR NOT NULL CHECK (window_kind IN ('five_hours', 'weekly')),
10
+ observed_at TIMESTAMPTZ NOT NULL,
11
+ observed_pct DOUBLE NOT NULL CHECK (observed_pct >= 0 AND observed_pct <= 100),
12
+ resets_at TIMESTAMPTZ NOT NULL
13
+ );
@@ -0,0 +1,25 @@
1
+ -- Git links (spec §4, §7.1, Phase 4 L13/L14). Additive only: `commits` (migration 001) keeps the
2
+ -- user's commits; these tables link them to sessions, pull requests and turns.
3
+
4
+ -- The repository (toplevel path) of each session, resolved from its cwd or inherited from its
5
+ -- parent. Kept when the directory later disappears, like the commits of that repository.
6
+ CREATE TABLE session_repos (
7
+ session_id VARCHAR PRIMARY KEY,
8
+ repo VARCHAR NOT NULL
9
+ );
10
+
11
+ -- Pull request of a stored commit, inferred from a local `Merge pull request #N` merge commit.
12
+ CREATE TABLE commit_pull_requests (
13
+ repo VARCHAR NOT NULL,
14
+ sha VARCHAR NOT NULL,
15
+ pr_number INTEGER NOT NULL CHECK (pr_number > 0),
16
+ PRIMARY KEY (repo, sha)
17
+ );
18
+
19
+ -- Derived: the commit each turn is attributed to, rewritten in full after every ingest. Orphan
20
+ -- turns (no commit) have no row.
21
+ CREATE TABLE turn_commits (
22
+ turn_id VARCHAR PRIMARY KEY,
23
+ repo VARCHAR NOT NULL,
24
+ sha VARCHAR NOT NULL
25
+ );
@@ -0,0 +1,9 @@
1
+ CREATE TABLE alert_notifications (
2
+ alert_id VARCHAR NOT NULL,
3
+ subscription_id VARCHAR NOT NULL,
4
+ kind VARCHAR NOT NULL CHECK (kind IN ('five_hours', 'weekly', 'monthly')),
5
+ window_start TIMESTAMPTZ NOT NULL,
6
+ threshold_pct DOUBLE NOT NULL,
7
+ sent_at TIMESTAMPTZ NOT NULL,
8
+ PRIMARY KEY (alert_id, window_start)
9
+ );
@@ -0,0 +1,9 @@
1
+ -- Corrected task class per session (spec §7.3, phase 5 L3). Additive only: it is user data, never
2
+ -- written by ingest, so a correction survives a re-ingest of the same session.
3
+ -- The derived class is computed at query time; `unknown` is never stored, it is the absence of a
4
+ -- correction and of positive evidence.
5
+ CREATE TABLE session_task_classes (
6
+ session_id VARCHAR PRIMARY KEY,
7
+ task_class VARCHAR NOT NULL CHECK (task_class IN ('feature', 'inline')),
8
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT current_timestamp
9
+ );
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "one-more-token",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.5.0",
4
+ "description": "One More Token: local dashboard for AI coding agent usage (omt start | serve | ingest | watch)",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "omt": "./dist/main.js"
9
+ },
10
+ "files": [
11
+ "dist/",
12
+ "web-dist/",
13
+ "data/",
14
+ "migrations/",
15
+ "README.md"
16
+ ],
17
+ "dependencies": {
18
+ "@duckdb/node-api": "1.5.6-r.1"
19
+ },
20
+ "engines": {
21
+ "node": ">=22"
22
+ },
23
+ "keywords": [
24
+ "ai",
25
+ "agents",
26
+ "claude-code",
27
+ "dashboard",
28
+ "usage",
29
+ "tokens",
30
+ "duckdb"
31
+ ]
32
+ }