ain-state-compiler 0.1.0__tar.gz
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.
- ain_state_compiler-0.1.0/LICENSE +21 -0
- ain_state_compiler-0.1.0/MANIFEST.in +6 -0
- ain_state_compiler-0.1.0/PKG-INFO +313 -0
- ain_state_compiler-0.1.0/README.md +281 -0
- ain_state_compiler-0.1.0/ain_state_compiler/__init__.py +24 -0
- ain_state_compiler-0.1.0/ain_state_compiler/__main__.py +5 -0
- ain_state_compiler-0.1.0/ain_state_compiler/cli.py +465 -0
- ain_state_compiler-0.1.0/ain_state_compiler/compiler/__init__.py +1 -0
- ain_state_compiler-0.1.0/ain_state_compiler/compiler/conflict_detector.py +184 -0
- ain_state_compiler-0.1.0/ain_state_compiler/compiler/state_compiler.py +227 -0
- ain_state_compiler-0.1.0/ain_state_compiler/compiler/token_optimizer.py +98 -0
- ain_state_compiler-0.1.0/ain_state_compiler/query.py +136 -0
- ain_state_compiler-0.1.0/ain_state_compiler/sync.py +181 -0
- ain_state_compiler-0.1.0/ain_state_compiler.egg-info/PKG-INFO +313 -0
- ain_state_compiler-0.1.0/ain_state_compiler.egg-info/SOURCES.txt +26 -0
- ain_state_compiler-0.1.0/ain_state_compiler.egg-info/dependency_links.txt +1 -0
- ain_state_compiler-0.1.0/ain_state_compiler.egg-info/entry_points.txt +2 -0
- ain_state_compiler-0.1.0/ain_state_compiler.egg-info/requires.txt +6 -0
- ain_state_compiler-0.1.0/ain_state_compiler.egg-info/top_level.txt +1 -0
- ain_state_compiler-0.1.0/dashboard/app.js +317 -0
- ain_state_compiler-0.1.0/dashboard/index.html +144 -0
- ain_state_compiler-0.1.0/dashboard/style.css +768 -0
- ain_state_compiler-0.1.0/mock_data/emails.json +16 -0
- ain_state_compiler-0.1.0/mock_data/jira_issues.json +18 -0
- ain_state_compiler-0.1.0/mock_data/slack_history.json +38 -0
- ain_state_compiler-0.1.0/pyproject.toml +57 -0
- ain_state_compiler-0.1.0/requirements.txt +5 -0
- ain_state_compiler-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sambit Mishra
|
|
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.
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ain-state-compiler
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: The G-Brain Company Brain Primitive: continuously compiles Slack, Jira, and Gmail into an executable, conflict-resolved operational state for AI agents.
|
|
5
|
+
Author-email: Sambit Mishra <contact@ain-compiler.ai>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/sambitmishra98/ain-state-compiler
|
|
8
|
+
Project-URL: Documentation, https://github.com/sambitmishra98/ain-state-compiler#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/sambitmishra98/ain-state-compiler
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/sambitmishra98/ain-state-compiler/issues
|
|
11
|
+
Keywords: company-brain,enterprise-ai,knowledge-management,state-compiler,offline-ai,ollama,supabase,institutional-memory,ain,g-brain,yc
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Information Technology
|
|
15
|
+
Classifier: Topic :: Office/Business
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Operating System :: OS Independent
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Provides-Extra: server
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: build; extra == "dev"
|
|
30
|
+
Requires-Dist: twine; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
|
|
33
|
+
# ain-state-compiler
|
|
34
|
+
|
|
35
|
+
> **The G-Brain Primitive** — A local-first, self-improving Company Brain that continuously compiles Slack, Jira, and Gmail into an executable, conflict-resolved operational state for AI agents.
|
|
36
|
+
|
|
37
|
+
[](https://pypi.org/project/ain-state-compiler/)
|
|
38
|
+
[](https://www.python.org/)
|
|
39
|
+
[](https://pypi.org/project/ain-state-compiler/)
|
|
40
|
+
[](https://opensource.org/licenses/MIT)
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## What Is This?
|
|
45
|
+
|
|
46
|
+
Most enterprise knowledge systems offer static storage and RAG over documents.
|
|
47
|
+
|
|
48
|
+
`ain-state-compiler` solves a harder problem:
|
|
49
|
+
|
|
50
|
+
> **Continuously compiling an organization's operational reality into an executable, internally consistent state representation.**
|
|
51
|
+
|
|
52
|
+
The output is not a document retrieval system — it is a **Company Brain**:
|
|
53
|
+
|
|
54
|
+
| Dimension | Static KB (Notion/Wikis) | AIN State Compiler |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| Focus | Storing documents | Maintaining live state |
|
|
57
|
+
| Refunds | Refund policy PDF | Actual refund behaviors observed across support logs |
|
|
58
|
+
| Engineering | Static runbooks | SRE behavior during actual incident response |
|
|
59
|
+
| Workflows | SOP text | Extracted from real event execution traces |
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Architecture
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
[ Slack / Jira / Gmail ]
|
|
67
|
+
|
|
|
68
|
+
v
|
|
69
|
+
[ Shared Hivemind DB ] <-- Supabase (cloud) or SQLite (local)
|
|
70
|
+
|
|
|
71
|
+
v (Every 5 minutes, offline cron)
|
|
72
|
+
[ sync + state_compiler ] -- Zero-LLM, 100% offline
|
|
73
|
+
|
|
|
74
|
+
+---------+-----------+
|
|
75
|
+
| | |
|
|
76
|
+
[IMMs] [OEGs] [Conflict Report]
|
|
77
|
+
\ | /
|
|
78
|
+
[compiled_state/]
|
|
79
|
+
|
|
|
80
|
+
(On-demand query only)
|
|
81
|
+
v
|
|
82
|
+
[ Ollama LLM ] <-- local gemma3:1b
|
|
83
|
+
|
|
|
84
|
+
[ Agent Action ]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
**Key Principles:**
|
|
88
|
+
- **Zero-LLM at source**: All ingestion, structuring, and conflict detection is 100% offline deterministic code.
|
|
89
|
+
- **LLMs on-demand only**: Only invoked when you explicitly query the brain. Context is pre-compiled and token-optimized (14-30% reduction via JSON→YAML).
|
|
90
|
+
- **Self-improving**: Notices recurring resolution structures and updates its executable skill library.
|
|
91
|
+
- **Shared hivemind**: Multiple team members write to one central DB; all local nodes compile their own state and read from the same source of truth.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Installation
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
pip install ain-state-compiler
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### First-Time Setup
|
|
102
|
+
|
|
103
|
+
After installing, run the interactive setup wizard:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
ain-brain setup
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
This will prompt you for:
|
|
110
|
+
- **Slack Bot Token** (`xoxb-...`)
|
|
111
|
+
- **Jira URL + API Token**
|
|
112
|
+
- **Gmail App Password**
|
|
113
|
+
- **Supabase URL + Service Role Key** (central cloud hivemind)
|
|
114
|
+
- Optional external DB credentials
|
|
115
|
+
|
|
116
|
+
All credentials are saved to `.env` in your project directory.
|
|
117
|
+
|
|
118
|
+
### Install Ollama (Local LLM)
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
ain-brain install-ollama
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
This downloads and installs [Ollama](https://ollama.com) and pulls `gemma3:1b`.
|
|
125
|
+
LLMs are only called when you query the brain — never during ingestion.
|
|
126
|
+
|
|
127
|
+
### Register 5-Minute Background Sync
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
ain-brain cron
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
- **Windows**: Registers a Windows Task Scheduler task (`AINBrainSync`).
|
|
134
|
+
- **Linux/macOS**: Adds a `crontab` entry.
|
|
135
|
+
|
|
136
|
+
The background task runs `sync + compile` every 5 minutes completely offline.
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Usage
|
|
141
|
+
|
|
142
|
+
### Seed the local database (mock data for testing)
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
ain-brain init-db
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Run a one-shot sync + compile
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
ain-brain sync
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Query the Company Brain
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
ain-brain query "What is the current deployment status of Analytics v2?"
|
|
158
|
+
ain-brain query "What is the billing situation with Acme Corp?"
|
|
159
|
+
ain-brain query "Are there any active conflicts in the system?"
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
If Ollama is running, it uses `gemma3:1b` for inference. Otherwise it falls back to the deterministic offline resolver.
|
|
163
|
+
|
|
164
|
+
### Start the Dashboard Server
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
ain-brain server
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Open [http://localhost:8000](http://localhost:8000) to access the B2B glassmorphic dashboard with:
|
|
171
|
+
- Live ingest stream terminal
|
|
172
|
+
- Active contradictions panel
|
|
173
|
+
- YAML OEG viewer
|
|
174
|
+
- Interactive query terminal
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Python API
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from ain_state_compiler import StateCompiler, ConflictDetector, TokenOptimizer
|
|
182
|
+
|
|
183
|
+
# Compile operational state
|
|
184
|
+
compiler = StateCompiler("/path/to/project")
|
|
185
|
+
summary = compiler.compile()
|
|
186
|
+
print(summary)
|
|
187
|
+
# {'processed_slack_events': 6, 'processed_jira_issues': 2, ..., 'detected_conflicts': 2}
|
|
188
|
+
|
|
189
|
+
# Token optimization
|
|
190
|
+
import json
|
|
191
|
+
data = {"key": "value", "nested": {"a": 1, "b": "hello world"}}
|
|
192
|
+
savings = TokenOptimizer.calculate_savings(data)
|
|
193
|
+
print(f"YAML saves {savings['saving_percentage']}% tokens vs JSON")
|
|
194
|
+
|
|
195
|
+
# Query the brain
|
|
196
|
+
from ain_state_compiler.query import query_brain
|
|
197
|
+
answer, node, used_llm = query_brain("What is the analytics v2 flag status?")
|
|
198
|
+
print(answer)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Sync with Supabase
|
|
202
|
+
|
|
203
|
+
Set environment variables (or configure via `ain-brain setup`):
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
SUPABASE_URL=https://your-project.supabase.co
|
|
207
|
+
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Then run:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
ain-brain sync
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
The sync will pull from Supabase and write compiled state back to the `compile_log` table.
|
|
217
|
+
|
|
218
|
+
---
|
|
219
|
+
|
|
220
|
+
## Supabase Schema
|
|
221
|
+
|
|
222
|
+
Run these SQL commands in Supabase SQL Editor to create the required tables:
|
|
223
|
+
|
|
224
|
+
```sql
|
|
225
|
+
CREATE TABLE slack_history (
|
|
226
|
+
id SERIAL PRIMARY KEY,
|
|
227
|
+
channel TEXT NOT NULL,
|
|
228
|
+
timestamp TEXT NOT NULL,
|
|
229
|
+
"user" TEXT NOT NULL,
|
|
230
|
+
text TEXT NOT NULL
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
CREATE TABLE jira_issues (
|
|
234
|
+
id TEXT PRIMARY KEY,
|
|
235
|
+
title TEXT NOT NULL,
|
|
236
|
+
status TEXT NOT NULL,
|
|
237
|
+
assignee TEXT NOT NULL,
|
|
238
|
+
updated_at TEXT NOT NULL,
|
|
239
|
+
description TEXT NOT NULL
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
CREATE TABLE emails (
|
|
243
|
+
id TEXT PRIMARY KEY,
|
|
244
|
+
subject TEXT NOT NULL,
|
|
245
|
+
sender TEXT NOT NULL,
|
|
246
|
+
timestamp TEXT NOT NULL,
|
|
247
|
+
body TEXT NOT NULL
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
CREATE TABLE compile_log (
|
|
251
|
+
id SERIAL PRIMARY KEY,
|
|
252
|
+
compiled_at TEXT NOT NULL,
|
|
253
|
+
slack_events INTEGER,
|
|
254
|
+
jira_issues INTEGER,
|
|
255
|
+
emails INTEGER,
|
|
256
|
+
conflicts INTEGER
|
|
257
|
+
);
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## What Gets Compiled
|
|
263
|
+
|
|
264
|
+
Each sync cycle produces:
|
|
265
|
+
|
|
266
|
+
| File | Description |
|
|
267
|
+
|---|---|
|
|
268
|
+
| `compiled_state/product_deployment_imm.md` | Product Deployment Institutional Memory Module |
|
|
269
|
+
| `compiled_state/acme_corp_billing_imm.md` | Billing configuration IMM |
|
|
270
|
+
| `compiled_state/active_conflicts_report.md` | All detected cross-departmental contradictions |
|
|
271
|
+
| `compiled_state/operational_state.json` | Full operational state (JSON) |
|
|
272
|
+
| `compiled_state/operational_state.yaml` | Token-optimized YAML (14-30% smaller) |
|
|
273
|
+
| `compiled_state/token_optimization_metrics.json` | Compression metrics |
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## The Contradiction Engine
|
|
278
|
+
|
|
279
|
+
The primary competitive moat. Instead of exposing raw conflicting data to AI agents (which causes hallucination), the Contradiction Engine resolves state before agents ever see it.
|
|
280
|
+
|
|
281
|
+
Example detection:
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
[CON-001] CRITICAL: Feature Flag Rollback vs GA Announcement
|
|
285
|
+
- Jira ENG-1043: Status=Done (GA implied)
|
|
286
|
+
- Email: Marketing sent "Analytics v2 is now live!" to all customers
|
|
287
|
+
- Slack: SRE set analytics_v2=FALSE due to DB connection pool exhaustion
|
|
288
|
+
|
|
289
|
+
Resolution: Halt GA messaging. Update Jira to BLOCKED. Issue customer notice.
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Token Optimization
|
|
295
|
+
|
|
296
|
+
Before submitting context to a local LLM, the JSON→YAML optimizer strips brackets, quotes, and separators:
|
|
297
|
+
|
|
298
|
+
```
|
|
299
|
+
JSON: {"key": "value", "nested": {"a": 1}} (38 chars)
|
|
300
|
+
YAML: key: value\nnested:\n a: 1 (27 chars = 29% smaller)
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
On realistic payloads, this saves **14-30% of tokens**, reducing inference latency and API costs.
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## License
|
|
308
|
+
|
|
309
|
+
MIT License — see [LICENSE](LICENSE)
|
|
310
|
+
|
|
311
|
+
---
|
|
312
|
+
|
|
313
|
+
*Built on the AIN (Autonomous Intelligence Network) architecture. Part of the G-Brain Company Brain research program.*
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# ain-state-compiler
|
|
2
|
+
|
|
3
|
+
> **The G-Brain Primitive** — A local-first, self-improving Company Brain that continuously compiles Slack, Jira, and Gmail into an executable, conflict-resolved operational state for AI agents.
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/ain-state-compiler/)
|
|
6
|
+
[](https://www.python.org/)
|
|
7
|
+
[](https://pypi.org/project/ain-state-compiler/)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## What Is This?
|
|
13
|
+
|
|
14
|
+
Most enterprise knowledge systems offer static storage and RAG over documents.
|
|
15
|
+
|
|
16
|
+
`ain-state-compiler` solves a harder problem:
|
|
17
|
+
|
|
18
|
+
> **Continuously compiling an organization's operational reality into an executable, internally consistent state representation.**
|
|
19
|
+
|
|
20
|
+
The output is not a document retrieval system — it is a **Company Brain**:
|
|
21
|
+
|
|
22
|
+
| Dimension | Static KB (Notion/Wikis) | AIN State Compiler |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| Focus | Storing documents | Maintaining live state |
|
|
25
|
+
| Refunds | Refund policy PDF | Actual refund behaviors observed across support logs |
|
|
26
|
+
| Engineering | Static runbooks | SRE behavior during actual incident response |
|
|
27
|
+
| Workflows | SOP text | Extracted from real event execution traces |
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Architecture
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
[ Slack / Jira / Gmail ]
|
|
35
|
+
|
|
|
36
|
+
v
|
|
37
|
+
[ Shared Hivemind DB ] <-- Supabase (cloud) or SQLite (local)
|
|
38
|
+
|
|
|
39
|
+
v (Every 5 minutes, offline cron)
|
|
40
|
+
[ sync + state_compiler ] -- Zero-LLM, 100% offline
|
|
41
|
+
|
|
|
42
|
+
+---------+-----------+
|
|
43
|
+
| | |
|
|
44
|
+
[IMMs] [OEGs] [Conflict Report]
|
|
45
|
+
\ | /
|
|
46
|
+
[compiled_state/]
|
|
47
|
+
|
|
|
48
|
+
(On-demand query only)
|
|
49
|
+
v
|
|
50
|
+
[ Ollama LLM ] <-- local gemma3:1b
|
|
51
|
+
|
|
|
52
|
+
[ Agent Action ]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Key Principles:**
|
|
56
|
+
- **Zero-LLM at source**: All ingestion, structuring, and conflict detection is 100% offline deterministic code.
|
|
57
|
+
- **LLMs on-demand only**: Only invoked when you explicitly query the brain. Context is pre-compiled and token-optimized (14-30% reduction via JSON→YAML).
|
|
58
|
+
- **Self-improving**: Notices recurring resolution structures and updates its executable skill library.
|
|
59
|
+
- **Shared hivemind**: Multiple team members write to one central DB; all local nodes compile their own state and read from the same source of truth.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Installation
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install ain-state-compiler
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### First-Time Setup
|
|
70
|
+
|
|
71
|
+
After installing, run the interactive setup wizard:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
ain-brain setup
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
This will prompt you for:
|
|
78
|
+
- **Slack Bot Token** (`xoxb-...`)
|
|
79
|
+
- **Jira URL + API Token**
|
|
80
|
+
- **Gmail App Password**
|
|
81
|
+
- **Supabase URL + Service Role Key** (central cloud hivemind)
|
|
82
|
+
- Optional external DB credentials
|
|
83
|
+
|
|
84
|
+
All credentials are saved to `.env` in your project directory.
|
|
85
|
+
|
|
86
|
+
### Install Ollama (Local LLM)
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
ain-brain install-ollama
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
This downloads and installs [Ollama](https://ollama.com) and pulls `gemma3:1b`.
|
|
93
|
+
LLMs are only called when you query the brain — never during ingestion.
|
|
94
|
+
|
|
95
|
+
### Register 5-Minute Background Sync
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
ain-brain cron
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
- **Windows**: Registers a Windows Task Scheduler task (`AINBrainSync`).
|
|
102
|
+
- **Linux/macOS**: Adds a `crontab` entry.
|
|
103
|
+
|
|
104
|
+
The background task runs `sync + compile` every 5 minutes completely offline.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Usage
|
|
109
|
+
|
|
110
|
+
### Seed the local database (mock data for testing)
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
ain-brain init-db
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Run a one-shot sync + compile
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
ain-brain sync
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### Query the Company Brain
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
ain-brain query "What is the current deployment status of Analytics v2?"
|
|
126
|
+
ain-brain query "What is the billing situation with Acme Corp?"
|
|
127
|
+
ain-brain query "Are there any active conflicts in the system?"
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
If Ollama is running, it uses `gemma3:1b` for inference. Otherwise it falls back to the deterministic offline resolver.
|
|
131
|
+
|
|
132
|
+
### Start the Dashboard Server
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
ain-brain server
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Open [http://localhost:8000](http://localhost:8000) to access the B2B glassmorphic dashboard with:
|
|
139
|
+
- Live ingest stream terminal
|
|
140
|
+
- Active contradictions panel
|
|
141
|
+
- YAML OEG viewer
|
|
142
|
+
- Interactive query terminal
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Python API
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from ain_state_compiler import StateCompiler, ConflictDetector, TokenOptimizer
|
|
150
|
+
|
|
151
|
+
# Compile operational state
|
|
152
|
+
compiler = StateCompiler("/path/to/project")
|
|
153
|
+
summary = compiler.compile()
|
|
154
|
+
print(summary)
|
|
155
|
+
# {'processed_slack_events': 6, 'processed_jira_issues': 2, ..., 'detected_conflicts': 2}
|
|
156
|
+
|
|
157
|
+
# Token optimization
|
|
158
|
+
import json
|
|
159
|
+
data = {"key": "value", "nested": {"a": 1, "b": "hello world"}}
|
|
160
|
+
savings = TokenOptimizer.calculate_savings(data)
|
|
161
|
+
print(f"YAML saves {savings['saving_percentage']}% tokens vs JSON")
|
|
162
|
+
|
|
163
|
+
# Query the brain
|
|
164
|
+
from ain_state_compiler.query import query_brain
|
|
165
|
+
answer, node, used_llm = query_brain("What is the analytics v2 flag status?")
|
|
166
|
+
print(answer)
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Sync with Supabase
|
|
170
|
+
|
|
171
|
+
Set environment variables (or configure via `ain-brain setup`):
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
SUPABASE_URL=https://your-project.supabase.co
|
|
175
|
+
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Then run:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
ain-brain sync
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The sync will pull from Supabase and write compiled state back to the `compile_log` table.
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Supabase Schema
|
|
189
|
+
|
|
190
|
+
Run these SQL commands in Supabase SQL Editor to create the required tables:
|
|
191
|
+
|
|
192
|
+
```sql
|
|
193
|
+
CREATE TABLE slack_history (
|
|
194
|
+
id SERIAL PRIMARY KEY,
|
|
195
|
+
channel TEXT NOT NULL,
|
|
196
|
+
timestamp TEXT NOT NULL,
|
|
197
|
+
"user" TEXT NOT NULL,
|
|
198
|
+
text TEXT NOT NULL
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
CREATE TABLE jira_issues (
|
|
202
|
+
id TEXT PRIMARY KEY,
|
|
203
|
+
title TEXT NOT NULL,
|
|
204
|
+
status TEXT NOT NULL,
|
|
205
|
+
assignee TEXT NOT NULL,
|
|
206
|
+
updated_at TEXT NOT NULL,
|
|
207
|
+
description TEXT NOT NULL
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
CREATE TABLE emails (
|
|
211
|
+
id TEXT PRIMARY KEY,
|
|
212
|
+
subject TEXT NOT NULL,
|
|
213
|
+
sender TEXT NOT NULL,
|
|
214
|
+
timestamp TEXT NOT NULL,
|
|
215
|
+
body TEXT NOT NULL
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
CREATE TABLE compile_log (
|
|
219
|
+
id SERIAL PRIMARY KEY,
|
|
220
|
+
compiled_at TEXT NOT NULL,
|
|
221
|
+
slack_events INTEGER,
|
|
222
|
+
jira_issues INTEGER,
|
|
223
|
+
emails INTEGER,
|
|
224
|
+
conflicts INTEGER
|
|
225
|
+
);
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## What Gets Compiled
|
|
231
|
+
|
|
232
|
+
Each sync cycle produces:
|
|
233
|
+
|
|
234
|
+
| File | Description |
|
|
235
|
+
|---|---|
|
|
236
|
+
| `compiled_state/product_deployment_imm.md` | Product Deployment Institutional Memory Module |
|
|
237
|
+
| `compiled_state/acme_corp_billing_imm.md` | Billing configuration IMM |
|
|
238
|
+
| `compiled_state/active_conflicts_report.md` | All detected cross-departmental contradictions |
|
|
239
|
+
| `compiled_state/operational_state.json` | Full operational state (JSON) |
|
|
240
|
+
| `compiled_state/operational_state.yaml` | Token-optimized YAML (14-30% smaller) |
|
|
241
|
+
| `compiled_state/token_optimization_metrics.json` | Compression metrics |
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## The Contradiction Engine
|
|
246
|
+
|
|
247
|
+
The primary competitive moat. Instead of exposing raw conflicting data to AI agents (which causes hallucination), the Contradiction Engine resolves state before agents ever see it.
|
|
248
|
+
|
|
249
|
+
Example detection:
|
|
250
|
+
|
|
251
|
+
```
|
|
252
|
+
[CON-001] CRITICAL: Feature Flag Rollback vs GA Announcement
|
|
253
|
+
- Jira ENG-1043: Status=Done (GA implied)
|
|
254
|
+
- Email: Marketing sent "Analytics v2 is now live!" to all customers
|
|
255
|
+
- Slack: SRE set analytics_v2=FALSE due to DB connection pool exhaustion
|
|
256
|
+
|
|
257
|
+
Resolution: Halt GA messaging. Update Jira to BLOCKED. Issue customer notice.
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Token Optimization
|
|
263
|
+
|
|
264
|
+
Before submitting context to a local LLM, the JSON→YAML optimizer strips brackets, quotes, and separators:
|
|
265
|
+
|
|
266
|
+
```
|
|
267
|
+
JSON: {"key": "value", "nested": {"a": 1}} (38 chars)
|
|
268
|
+
YAML: key: value\nnested:\n a: 1 (27 chars = 29% smaller)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
On realistic payloads, this saves **14-30% of tokens**, reducing inference latency and API costs.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## License
|
|
276
|
+
|
|
277
|
+
MIT License — see [LICENSE](LICENSE)
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
*Built on the AIN (Autonomous Intelligence Network) architecture. Part of the G-Brain Company Brain research program.*
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
ain-state-compiler: The G-Brain Enterprise Company Brain Primitive.
|
|
3
|
+
|
|
4
|
+
A local-first, offline-ingestion engine that continuously compiles raw
|
|
5
|
+
corporate communications (Slack, Jira, Gmail) into an executable,
|
|
6
|
+
internally consistent operational state representation — ready for AI agents.
|
|
7
|
+
|
|
8
|
+
Zero-LLM at source. LLMs called only on-demand query.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
__version__ = "0.1.0"
|
|
12
|
+
__author__ = "Sambit Mishra"
|
|
13
|
+
__email__ = "contact@ain-compiler.ai"
|
|
14
|
+
|
|
15
|
+
from ain_state_compiler.compiler.state_compiler import StateCompiler
|
|
16
|
+
from ain_state_compiler.compiler.conflict_detector import ConflictDetector
|
|
17
|
+
from ain_state_compiler.compiler.token_optimizer import TokenOptimizer
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"StateCompiler",
|
|
21
|
+
"ConflictDetector",
|
|
22
|
+
"TokenOptimizer",
|
|
23
|
+
"__version__",
|
|
24
|
+
]
|