vibeostheog 0.13.22

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 ADDED
@@ -0,0 +1,286 @@
1
+ # vibeOS for OpenCode
2
+
3
+ Cost-aware delegation and policy plugin for OpenCode Desktop.
4
+
5
+ vibeOS helps keep expensive model usage under control by enforcing delegation behavior, tracking savings, and exposing runtime controls through the `trinity` tool.
6
+
7
+ ## Version
8
+
9
+ Current package version: `0.11.0`
10
+
11
+ ## What It Does
12
+
13
+ - Tracks estimated savings from delegation warnings and enforcement events.
14
+ - Tracks cache savings as a separate persisted category when scratchpad cache hits are observed.
15
+ - Adds a live footer to assistant outputs with model split, cumulative savings, and trend arrow.
16
+ - Provides `trinity` runtime controls for slot switching, enforcement toggles, audits, and diagnostics.
17
+ - Adds per-session model locking: prevents the plugin from auto-switching models when the user changes the model in the OpenCode GUI (`trinity lock on|off`).
18
+ - Adds optional flow checks and TDD skeleton enforcement.
19
+ - Adds project guard: ensures AGENTS.md and README.md exist and stay protected in every project.
20
+ - Adds report and research-audit tooling.
21
+ - Learns recurring struggle and routine patterns per project, with `trinity patterns` inspection and `trinity patterns clear`.
22
+ - Stress mitigation pipeline: detects user stress signals, shows live stress gauge in footer, injects protective system prompts, and upgrades Task tier when user is stressed.
23
+ - vibeOS MCP server with HTTP API for extended tool capabilities (trinity, reports, session metrics, diagnostics).
24
+ - TUI dashboard sidebar plugin for real-time plugin status and controls.
25
+ - **Web dashboard** — SolidJS SPA served via standalone server (`npm run dashboard`) or embedded in the MCP server. Real-time SSE push updates at `http://127.0.0.1:3333`.
26
+ - Worker-to-Brain (WBP) protocol synthesizes delegated task output directly in assistant chat.
27
+ - **Remote API protection**: Core algorithms run on a self-hosted API server (`api.vibetheog.com`) with token-based authentication. Non-paying seats can be deactivated, immediately revoking all API tokens and falling back to local degraded mode.
28
+
29
+ ## Remote API Protection
30
+
31
+ vibeOS protects its core algorithms by serving them from a self-hosted API server rather than bundling them entirely in the plugin:
32
+
33
+ | Algorithm | Endpoint | Description |
34
+ |---|---|---|---|
35
+ | Delegation enforcement | `POST /api/v1/delegate/check` | Model cost calculation, block/warn routing |
36
+ | Model tier routing | `POST /api/v1/route/model` | Tier classification, stress-aware routing |
37
+ | Stress scoring | `POST /api/v1/stress/score` | NLP stress signal detection |
38
+ | Blackbox engine | `POST /api/v1/blackbox/analyze` | Dialogue trajectory, loop detection, pivot/switch, outcome tracking |
39
+ | Blackbox calibration | `POST /api/v1/blackbox/calibrate` | Auto-tune thresholds from session outcomes |
40
+ | Blackbox calibration state | `GET /api/v1/blackbox/calibration` | Read calibrated weights per project |
41
+ | Blackbox outcome | `POST /api/v1/blackbox/outcome` | Record session satisfaction outcome |
42
+ | Blackbox project sessions | `GET /api/v1/blackbox/project-sessions` | List cross-session history per project |
43
+ | TDD skeleton gen | `POST /api/v1/tdd/skeleton` | Multi-language test generation |
44
+ | Pattern learner | `POST /api/v1/patterns/observe` | Friction/routine detection |
45
+ | Model pricing | `POST /api/v1/pricing/fetch` | Dynamic OpenRouter pricing cache |
46
+ | Context compression | `POST /api/v1/compress/context` | Bullet-point extraction |
47
+
48
+ ### Environment Variables
49
+
50
+ ```
51
+ VIBEOS_API_URL=https://api.vibetheog.com # API server URL (default: https://api.vibetheog.com)
52
+ VIBEOS_API_TOKEN=vos_... # Your API token (required for remote mode)
53
+ VIBEOS_API_ENABLED=true # Set to "false" to use local-only mode
54
+ CLAUDE_CREDIT_PERCENT=150 # Override credit percentage (default: 100)
55
+ CLAUDE_CONTEXT7_AVAILABLE=true # Set to enable context7 cost optimization
56
+ CLAUDE_SCRATCHPAD_MAX_AGE_SEC=86400 # Scratchpad cache lifetime in seconds
57
+ VIBEOS_MCP_PORT=3001 # MCP server port (default: 3001)
58
+ ```
59
+
60
+ When `VIBEOS_API_TOKEN` is not set or `VIBEOS_API_ENABLED=false`, the plugin runs in local-only mode with all algorithms bundled. When a valid token is provided, core algorithms are offloaded to the remote API.
61
+
62
+ ### Seat & Token Management
63
+
64
+ The API server manages licenses via seats:
65
+
66
+ - **Create a seat + token** (WordPress integration):
67
+ `POST /admin/seats` with `{ "name": "...", "email": "...", "with_token": "label" }`
68
+
69
+ - **Suspend a seat** (non-paying customer):
70
+ `PATCH /admin/seats/:id` with `{ "status": "suspended" }`
71
+ This immediately revokes all API tokens for that seat. The plugin falls back to local degraded mode.
72
+
73
+ - **Reactivate a seat**:
74
+ `PATCH /admin/seats/:id` with `{ "status": "active" }`
75
+
76
+ ## Runtime Model Slots
77
+
78
+ Slots are configured in `~/.claude/model-tiers.json`:
79
+
80
+ - `brain`
81
+ - `medium`
82
+ - `cheap`
83
+
84
+ On startup, the plugin detects the active model/slot from `model-tiers.json`. No automatic slot switching occurs; use `trinity set <slot>` or `trinity rebuild` to change slots.
85
+
86
+ ## Savings Categories (Persisted)
87
+
88
+ State file: `~/.claude/delegation-state.json`
89
+
90
+ - Delegation savings:
91
+ - `sessions[...].warns[].est_savings_usd`
92
+ - aggregated into footer totals
93
+ - Cache savings:
94
+ - `sessions[...].cache_savings_usd`
95
+ - `lifetime.cache_savings_usd`
96
+ - optional `sessions[...].cache_hits[]` audit entries
97
+ - Context7 missed-savings tracker:
98
+ - `lifetime.missed_context7_usd`
99
+
100
+ ## Footer Format
101
+
102
+ Typical output footer:
103
+
104
+ `— [model route] | VibeTheOG: <total> saved <arrow> —`
105
+
106
+ Example (with savings):
107
+
108
+ `— [🧠 deepseek-v4-flash → ⚙ deepseek-chat] | VibeTheOG: 0.01 saved → —`
109
+
110
+ Example (no savings yet, tier label only):
111
+
112
+ `— [⚙ Mid] —`
113
+
114
+ ## `trinity` Tool Commands
115
+
116
+ Main commands:
117
+
118
+ - `trinity status`
119
+ - `trinity set brain|medium|cheap`
120
+ - `trinity brain|medium|cheap`
121
+ - `trinity enable` / `trinity disable`
122
+ - `trinity thinking full|brief|off`
123
+ - `trinity enforce` / `trinity enforce on|off`
124
+ - `trinity lock on|off` / `trinity lock`
125
+ - `trinity flow on|off` / `trinity flow enforce on|off` / `trinity flow`
126
+ - `trinity tdd on|off` / `trinity tdd strict on|off` / `trinity tdd quality on|off` / `trinity tdd`
127
+ - `trinity project`
128
+ - `trinity patterns`
129
+ - `trinity patterns clear`
130
+ - `trinity patterns suggest`
131
+ - `trinity repair-state`
132
+ - `trinity guard`
133
+ - `trinity diagnose`
134
+ - `trinity rebuild`
135
+ - `trinity help`
136
+
137
+ ## Optional Enforcement Modules
138
+
139
+ - Delegation enforcement:
140
+ - Blocks direct `write`/`edit`/`notebookedit` on high-tier brain when enabled.
141
+ - Adds user-visible enforcement notes.
142
+ - Flow enforcer:
143
+ - Rule checks for write/edit patterns.
144
+ - Optional TODO/FIXME extraction queue when flow enforcement is enabled.
145
+ - TDD enforcer:
146
+ - Auto-creates skeleton tests for changed source files when enabled.
147
+ - Strict mode is ON by default: TODO tests fail loudly until implemented.
148
+ - Project Guard:
149
+ - On session init, checks if AGENTS.md and README.md exist in the project root.
150
+ - Auto-creates AGENTS.md with protective rules (LLM must ask before modifying code).
151
+ - Auto-creates README.md with tech stack auto-detection and feature stubs.
152
+ - Flow rules warn/flag on write/edit to these protected files.
153
+ - System prompt injects directive to maintain both files.
154
+ - `trinity guard` command regenerates both files on demand.
155
+
156
+ ## Reports and Audit Tools
157
+
158
+ - `research-audit`
159
+ - `report-save`
160
+ - `report-list`
161
+ - `report-read`
162
+
163
+ These use `~/.claude/reports` and project memory in `~/.claude/project-states.json`.
164
+
165
+ ## Pattern Learning
166
+
167
+ - Detects repeated friction signals and recurring successful routines from session behavior.
168
+ - Stores per-project pattern memory in `~/.claude/project-states.json`.
169
+ - Promotes patterns after repeated confirmation across sessions and surfaces them via `trinity patterns`.
170
+
171
+ ## Blackbox Decision Engine
172
+
173
+ The blackbox tracks dialogue trajectory per-session and per-project, providing real-time decision state insights:
174
+
175
+ **Enabled by default.**
176
+
177
+ - **Resolution tracking**: Classifies each session into one of 7 sub-regimes (INIT, DIVERGENT, EXPLORING, REFINING, CONVERGING, CLOSED, LOOPING) based on entropy trends, action consistency, feature contradiction, and embedding drift.
178
+ - **Real feature extraction**: Derives 11 features from each user message — message length, word count, question ratio, code blocks, urgency signals, sentiment, complexity, repetition, and instruction density.
179
+ - **Loop prevention**: Detects when the conversation is going in circles and injects escalating system prompt interventions (gentle → suggestive → assertive → escalated) to break the loop.
180
+ - **PIVOT/SWITCH detection**: Recognizes when the user changes context outside the current project scope and injects scope-confirmation directives.
181
+ - **Outcome tracking**: Detects satisfaction signals from assistant responses (positive: "thanks/that works/perfect"; negative: "broken/still failing/wrong") and records them for calibration.
182
+ - **Cross-session continuity**: State persists per project fingerprint in `~/.claude/blackbox-state.json` and remotely in SQLite, allowing resolution state to carry across terminal restarts.
183
+ - **Online calibration**: The API server aggregates session outcomes and auto-tunes loop detection, momentum, and closure thresholds per project via `POST /api/v1/blackbox/calibrate`.
184
+
185
+ Commands:
186
+ - `trinity blackbox on` — Enable the decision engine
187
+ - `trinity blackbox off` — Disable the decision engine
188
+ - `trinity blackbox status` — View current resolution, sub-regime, momentum, loop state, and project history
189
+ - `trinity blackbox reset` — Clear the resolution tracker for the current session
190
+
191
+
192
+ The blackbox injects a decision directive into system prompts showing current resolution state, intent volatility, and continuity. When looping or pivoting is detected, stronger intervention directives are injected to guide the model.
193
+
194
+ ### Session Workflow Phases
195
+
196
+ The meta-controller maps detected sub-regimes to optimization modes, which are the authority over all plugin settings. Each turn, `syncControlSettings()` writes the mode's control vector to `model-tiers.json`, auto-toggling enforcement, flow, TDD, and thinking level:
197
+
198
+ | Regime | Mode | Enforce | Flow | TDD | Tier | Think |
199
+ |---|---|---|---|---|---|---|
200
+ | INIT | budget | relaxed | audit | lazy | cheap | off |
201
+ | EXPLORING / DIVERGENT | budget | relaxed | audit | lazy | cheap | off |
202
+ | REFINING | budget | relaxed | audit | lazy | cheap | off |
203
+ | CONVERGING / CLOSED | quality | strict | strict | quality | brain | full |
204
+ | LOOPING | speed | relaxed | audit | lazy | medium | off |
205
+
206
+ **Stress override**: When user stress exceeds 1.5, any regime escalates to `quality` mode — enforcement tightens, brain tier activates. Settings are re-synced every turn; mode is the sole authority. Manual `trinity enforce on/off` still works until the next turn re-evaluates.
207
+
208
+ When the blackbox is disabled, a lightweight `classifyTurnSimple()` fallback inspects user message patterns:
209
+ - Q&A patterns (`"how"`, `"what"`, `"explain"`) → EXPLORING (relaxed)
210
+ - Implementation patterns (`"write"`, `"fix"`, `"implement"`) → REFINING (normal)
211
+
212
+ ## Install
213
+
214
+ ### npm (Recommended)
215
+
216
+ Published to npm as `vibeOS`:
217
+
218
+ ```bash
219
+ npm install vibeOS
220
+ ```
221
+
222
+ Then register in `~/.config/opencode/opencode.json`:
223
+ ```json
224
+ "plugins": [
225
+ { "id": "vibeOS", "path": "node_modules/vibeOS/src/index.js" }
226
+ ]
227
+ ```
228
+
229
+ ### Local Plugin File
230
+
231
+ For OpenCode Desktop local plugin usage, copy these files to `~/.config/opencode/plugins/`:
232
+
233
+ ```
234
+ cp src/index.js ~/.config/opencode/plugins/vibeOS.js
235
+ cp src/vibeOS-lib/flow-enforcer.js ~/.config/opencode/plugins/vibeOS-lib/flow-enforcer.js
236
+ cp src/vibeOS-lib/session-metrics.js ~/.config/opencode/plugins/vibeOS-lib/session-metrics.js
237
+ cp src/vibeOS-lib/flow-rules.json ~/.config/opencode/plugins/vibeOS-lib/flow-rules.json
238
+ cp src/utils/cost-formatter.js ~/.config/opencode/plugins/vibeOS-lib/cost-formatter.js
239
+ cp src/utils/math.js ~/.config/opencode/plugins/vibeOS-lib/math.js
240
+ cp src/utils/timer.js ~/.config/opencode/plugins/vibeOS-lib/timer.js
241
+ ```
242
+
243
+ Then register the plugin in `~/.config/opencode/opencode.json`:
244
+
245
+ ```json
246
+ "plugins": [
247
+ { "id": "vibeOS", "path": "~/.config/opencode/plugins/vibeOS.js" }
248
+ ]
249
+ ```
250
+
251
+ Restart OpenCode Desktop. The plugin auto-creates `~/.claude/model-tiers.json` on first run.
252
+
253
+ ## Web Dashboard
254
+
255
+ Open `http://127.0.0.1:3333` in your browser after starting the server.
256
+
257
+ ```bash
258
+ npm run build:dashboard # Build the SPA (one-time)
259
+ npm run dashboard # Start standalone server on :3333
260
+ npm run dev:dashboard # Vite dev server on :5173 with hot-reload
261
+ ```
262
+
263
+ Features: model split, savings, sessions, stress gauge, trinity controls, reports, blackbox state. SSE push updates every 1.5s.
264
+
265
+ ## Build
266
+
267
+ - `npm run build`
268
+ - `npm run build:dashboard` (build the web dashboard SPA)
269
+
270
+ `npm run build` compiles TypeScript source-of-truth modules and syncs generated JS artifacts used by runtime.
271
+
272
+ ## CI/CD
273
+
274
+ GitHub Actions workflows are in `.github/workflows/`:
275
+
276
+ - **CI** (`.github/workflows/ci.yml`): Runs on every push/PR to `main`/`master`. Executes typecheck, syntax check, test suite, TypeScript audit, and build validation.
277
+
278
+ - **Release** (`.github/workflows/release.yml`): Manual trigger via GitHub Actions UI (`workflow_dispatch`). Prompts for version bump type (patch/minor/major), then runs tests, builds, and executes `scripts/release.mjs --yes --ci` which bumps version, updates changelog, commits/tags/pushes, creates a GitHub Release, and publishes to npm.
279
+
280
+ Before using the release workflow, add an `NPM_TOKEN` secret to the repository with an npm automation token that has publish permissions for the `vibeOS` package.
281
+
282
+ ## Known Limitations
283
+
284
+ - OpenCode runtime behavior can vary by version for per-task model override handling.
285
+ - Some legacy tests in this repo are older than current enforcement defaults and may fail due to changed policy semantics rather than runtime breakage.
286
+ - Savings are estimates, not billing data.
@@ -0,0 +1,69 @@
1
+ {
2
+ "$schema_version": 1,
3
+ "_comment": "Single source of truth for VibeTheOG model classification. Both the bash hook and JS plugin load this file. Tier IDs (high/mid/budget) are stable — display labels are user-facing.",
4
+ "trinity": {
5
+ "_comment": "Per-slot models for both runtimes. `oc` writes to the OpenCode config. `cc` writes to the CC config. Adjust to match your available models.",
6
+ "brain": {
7
+ "oc": "provider/high-tier-model",
8
+ "cc": "brain"
9
+ },
10
+ "medium": {
11
+ "oc": "provider/mid-tier-model",
12
+ "cc": "medium"
13
+ },
14
+ "cheap": {
15
+ "oc": "provider/budget-tier-model",
16
+ "cc": "budget"
17
+ }
18
+ },
19
+ "selection": {
20
+ "_comment": "Used by `trinity auto`: pick `brain` slot when credit ≥ threshold, else `fallback` slot. Dropping to mid slot at low credit is more reliable than burning what's left on flaky brain calls. `enabled` toggles all VibeTheOG logic. `active_slot` records the last slot set by `trinity`.",
21
+ "credit_threshold_percent": 30,
22
+ "brain": "brain",
23
+ "fallback": "medium",
24
+ "enabled": true,
25
+ "active_slot": "brain",
26
+ "delegation_enforce": true,
27
+ "tdd_strict": true
28
+ },
29
+ "tiers": {
30
+ "high": {
31
+ "label": "brain",
32
+ "icon": "🧠",
33
+ "regex": "opus|gemini-.*-pro|deepseek.*v4.*pro|deepseek.*r1|gpt-5|mistral.*large|qwen.*max|grok-3|command.*r.*plus|(^|[^a-z])o[134]($|[^a-z])",
34
+ "behavior": "warn on Edit/Write/Bash with savings estimate; ledger; context7 nudge; scratchpad observe"
35
+ },
36
+ "mid": {
37
+ "label": "medium",
38
+ "icon": "⚙",
39
+ "regex": "claude.*sonnet|sonnet|deepseek.*v4.*flash|deepseek.*v[23]|deepseek.*coder|gemini-.*-flash|gpt-4o(?!-mini)|gpt-4(?!o)|llama|mixtral|mistral(?!.*large)|qwen.*plus|grok-2|command.*r(?!.*plus)|o[134]-mini",
40
+ "behavior": "silent; ledger only"
41
+ },
42
+ "budget": {
43
+ "label": "cheap",
44
+ "icon": "⚡",
45
+ "regex": ".*",
46
+ "behavior": "fully silent; pass-through"
47
+ }
48
+ },
49
+ "pricing": {
50
+ "high": {
51
+ "input": 15.00,
52
+ "output": 75.00,
53
+ "cache_read": 1.50,
54
+ "cache_write": 18.75
55
+ },
56
+ "mid": {
57
+ "input": 3.00,
58
+ "output": 15.00,
59
+ "cache_read": 0.30,
60
+ "cache_write": 3.75
61
+ },
62
+ "budget": {
63
+ "input": 0.80,
64
+ "output": 4.00,
65
+ "cache_read": 0.08,
66
+ "cache_write": 1.00
67
+ }
68
+ }
69
+ }
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "vibeostheog",
3
+ "version": "0.13.22",
4
+ "description": "Cost-aware delegation enforcer for OpenCode. Tracks model usage, routes Task subagents to cheaper tiers, surfaces cumulative savings in chat. Includes research audit, reporting framework, project memory, progressive scratchpad decadence, and trinity CLI for brain/medium/cheap slot switching.",
5
+ "scripts": {
6
+ "release": "node scripts/release.mjs",
7
+ "release:patch": "node scripts/release.mjs patch --yes",
8
+ "release:minor": "node scripts/release.mjs minor --yes",
9
+ "release:major": "node scripts/release.mjs major --yes",
10
+ "build": "tsc -p tsconfig.json --noEmit && npx esbuild src/index.ts --bundle --outfile=src/index.js --platform=node --format=esm --target=node22 --external:node:* && node scripts/deploy.mjs",
11
+ "deploy": "node scripts/deploy.mjs",
12
+ "typecheck": "tsc -p tsconfig.json --noEmit",
13
+ "checkpoint:validate": "node scripts/checkpoint-validate.mjs",
14
+ "test:scripts": "node --test scripts/tests/checkpoint-validate.test.mjs",
15
+ "ts:audit": "node scripts/ts-audit.mjs",
16
+ "test": "VIBEOS_MCP_PORT=0 node --test tests/*.test.mjs src/tests/*.test.js src/utils/tests/*.test.mjs src/vibeOS-lib/tests/*.test.mjs",
17
+ "codex:guard": "bash plugins/vibetheog-codex/scripts/run-guard.sh",
18
+ "codex:guard:full": "VIBETHEOG_GUARD_FULL=1 bash plugins/vibetheog-codex/scripts/run-guard.sh",
19
+ "codex:hook:precommit": "bash plugins/vibetheog-codex/hooks/pre-commit.sh",
20
+ "codex:hook:summary": "bash plugins/vibetheog-codex/hooks/post-command-summary.sh",
21
+ "precommit": "node scripts/pre-commit.mjs",
22
+ "audit-state": "node scripts/audit-state.mjs",
23
+ "migrate-ledger": "node scripts/migrate-ledger.mjs",
24
+ "build:dashboard": "cd src/dashboard && npm install && npm run build",
25
+ "dev:dashboard": "cd src/dashboard && npm run dev",
26
+ "dashboard": "node scripts/dashboard-server.mjs",
27
+ "test:e2e": "node --test tests/dashboard-buttons.e2e.test.mjs",
28
+ "test:dashboard": "node --test tests/test_dashboard.test.mjs"
29
+ },
30
+ "type": "module",
31
+ "exports": {
32
+ ".": "./src/index.js"
33
+ },
34
+ "keywords": [
35
+ "opencode",
36
+ "opencode-plugin",
37
+ "cost",
38
+ "delegation",
39
+ "model-routing",
40
+ "trinity"
41
+ ],
42
+ "author": "vibeOS",
43
+ "license": "MIT",
44
+ "engines": {
45
+ "node": ">=18"
46
+ },
47
+ "peerDependencies": {
48
+ "@opencode-ai/plugin": ">=1.0.0"
49
+ },
50
+ "files": [
51
+ "src/index.js",
52
+ "model-tiers.sample.json",
53
+ "README.md",
54
+ "CHANGELOG.md",
55
+ "LICENSE"
56
+ ],
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "https://github.com/DrunkkToys/vibeOS.git"
60
+ },
61
+ "homepage": "https://github.com/DrunkkToys/vibeOS#readme",
62
+ "bugs": {
63
+ "url": "https://github.com/DrunkkToys/vibeOS/issues"
64
+ },
65
+ "devDependencies": {
66
+ "@playwright/test": "^1.60.0",
67
+ "@types/express": "^5.0.6",
68
+ "@types/node": "^22.15.30",
69
+ "esbuild": "^0.28.0",
70
+ "express": "^5.2.1",
71
+ "typescript": "^5.9.3"
72
+ },
73
+ "dependencies": {
74
+ "solid-js": "^1.9.13"
75
+ }
76
+ }