| 1 | -- Effort and recommendations (docs.g1t.sh/guides/spend/). |
| 2 | -- |
| 3 | -- An agent's effort setting lives in its routing JSON (`effort`: auto, |
| 4 | -- low, medium, high or max), so it is versioned with the rest of the |
| 5 | -- definition and needs no column. What is recorded here is the level each |
| 6 | -- piece of work actually ran at, so what a level costs and how often its |
| 7 | -- work is accepted can be measured from real history. |
| 8 | |
| 9 | -- The level a session ran at: low, medium, high or max. When Auto raises |
| 10 | -- it partway (someone steered it), the highest. Null before this. |
| 11 | ALTER TABLE agent_sessions ADD COLUMN effort TEXT; |
| 12 | -- The tier its last step ran on, for the record. |
| 13 | ALTER TABLE agent_sessions ADD COLUMN tier TEXT; |
| 14 | -- The level a chat reply ran at. |
| 15 | ALTER TABLE agent_replies ADD COLUMN effort TEXT; |
| 16 | |
| 17 | CREATE INDEX IF NOT EXISTS agent_sessions_finished ON agent_sessions (workspace_id, agent_id, finished_at); |
| 18 | |
| 19 | -- Ways to spend less, from the weekly check (src/recommend.ts). One row per |
| 20 | -- agent and suggestion; a check refreshes an open or thin one in place, and |
| 21 | -- never reopens one that was applied or dismissed until the agent's |
| 22 | -- setting changes. status: open, thin (too little history to say), |
| 23 | -- applied, dismissed, stale (the setting changed under it). |
| 24 | CREATE TABLE agent_recommendations ( |
| 25 | id TEXT PRIMARY KEY, |
| 26 | workspace_id TEXT NOT NULL, |
| 27 | agent_id TEXT NOT NULL, |
| 28 | kind TEXT NOT NULL, |
| 29 | status TEXT NOT NULL, |
| 30 | from_effort TEXT NOT NULL, |
| 31 | to_effort TEXT NOT NULL, |
| 32 | title TEXT NOT NULL, |
| 33 | reason TEXT NOT NULL, |
| 34 | -- JSON: the window and both sides' counts, acceptance and costs. |
| 35 | evidence TEXT NOT NULL, |
| 36 | saving_month_micros INTEGER, |
| 37 | checked_at TEXT NOT NULL, |
| 38 | resolved_by TEXT, |
| 39 | resolved_at TEXT, |
| 40 | created_at TEXT NOT NULL |
| 41 | ); |
| 42 | CREATE UNIQUE INDEX agent_recommendations_one ON agent_recommendations (agent_id, kind, from_effort, to_effort); |
| 43 | CREATE INDEX agent_recommendations_workspace ON agent_recommendations (workspace_id, status); |
| 44 | |
| 45 | -- When the check last ran for each workspace, so the page can say so and |
| 46 | -- the daily run checks each workspace once a week. |
| 47 | CREATE TABLE agent_recommendation_checks ( |
| 48 | workspace_id TEXT PRIMARY KEY, |
| 49 | checked_at TEXT NOT NULL |
| 50 | ); |