@tpsdev-ai/flair 0.2.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.
Files changed (64) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +246 -0
  3. package/SECURITY.md +116 -0
  4. package/config.yaml +16 -0
  5. package/dist/resources/A2AAdapter.js +474 -0
  6. package/dist/resources/Agent.js +9 -0
  7. package/dist/resources/AgentCard.js +45 -0
  8. package/dist/resources/AgentSeed.js +111 -0
  9. package/dist/resources/IngestEvents.js +149 -0
  10. package/dist/resources/Integration.js +13 -0
  11. package/dist/resources/IssueTokens.js +19 -0
  12. package/dist/resources/Memory.js +122 -0
  13. package/dist/resources/MemoryBootstrap.js +263 -0
  14. package/dist/resources/MemoryConsolidate.js +105 -0
  15. package/dist/resources/MemoryFeed.js +41 -0
  16. package/dist/resources/MemoryReflect.js +105 -0
  17. package/dist/resources/OrgEvent.js +43 -0
  18. package/dist/resources/OrgEventCatchup.js +65 -0
  19. package/dist/resources/OrgEventMaintenance.js +29 -0
  20. package/dist/resources/SemanticSearch.js +147 -0
  21. package/dist/resources/SkillScan.js +101 -0
  22. package/dist/resources/Soul.js +9 -0
  23. package/dist/resources/SoulFeed.js +12 -0
  24. package/dist/resources/WorkspaceLatest.js +45 -0
  25. package/dist/resources/WorkspaceState.js +76 -0
  26. package/dist/resources/auth-middleware.js +470 -0
  27. package/dist/resources/embeddings-provider.js +127 -0
  28. package/dist/resources/embeddings.js +42 -0
  29. package/dist/resources/health.js +6 -0
  30. package/dist/resources/memory-feed-lib.js +15 -0
  31. package/dist/resources/table-helpers.js +35 -0
  32. package/package.json +62 -0
  33. package/resources/A2AAdapter.ts +510 -0
  34. package/resources/Agent.ts +10 -0
  35. package/resources/AgentCard.ts +65 -0
  36. package/resources/AgentSeed.ts +119 -0
  37. package/resources/IngestEvents.ts +189 -0
  38. package/resources/Integration.ts +14 -0
  39. package/resources/IssueTokens.ts +29 -0
  40. package/resources/Memory.ts +138 -0
  41. package/resources/MemoryBootstrap.ts +283 -0
  42. package/resources/MemoryConsolidate.ts +121 -0
  43. package/resources/MemoryFeed.ts +48 -0
  44. package/resources/MemoryReflect.ts +122 -0
  45. package/resources/OrgEvent.ts +63 -0
  46. package/resources/OrgEventCatchup.ts +89 -0
  47. package/resources/OrgEventMaintenance.ts +37 -0
  48. package/resources/SemanticSearch.ts +157 -0
  49. package/resources/SkillScan.ts +146 -0
  50. package/resources/Soul.ts +10 -0
  51. package/resources/SoulFeed.ts +15 -0
  52. package/resources/WorkspaceLatest.ts +66 -0
  53. package/resources/WorkspaceState.ts +102 -0
  54. package/resources/auth-middleware.ts +502 -0
  55. package/resources/embeddings-provider.ts +144 -0
  56. package/resources/embeddings.ts +28 -0
  57. package/resources/health.ts +7 -0
  58. package/resources/memory-feed-lib.ts +22 -0
  59. package/resources/table-helpers.ts +46 -0
  60. package/schemas/agent.graphql +22 -0
  61. package/schemas/event.graphql +12 -0
  62. package/schemas/memory.graphql +50 -0
  63. package/schemas/schema.graphql +41 -0
  64. package/schemas/workspace.graphql +14 -0
package/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ Copyright 2026 TPS Dev AI
8
+
9
+ Licensed under the Apache License, Version 2.0 (the "License");
10
+ you may not use this file except in compliance with the License.
11
+ You may obtain a copy of the License at
12
+
13
+ http://www.apache.org/licenses/LICENSE-2.0
14
+
15
+ Unless required by applicable law or agreed to in writing, software
16
+ distributed under the License is distributed on an "AS IS" BASIS,
17
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ See the License for the specific language governing permissions and
19
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,246 @@
1
+ # 🎖️ Flair
2
+
3
+ [![CI](https://github.com/tpsdev-ai/flair/actions/workflows/test.yml/badge.svg)](https://github.com/tpsdev-ai/flair/actions/workflows/test.yml)
4
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
+
6
+ **Identity, memory, and soul for AI agents.**
7
+
8
+ Agents forget everything between sessions. Flair gives them a persistent sense of self — who they are, what they know, how they think — backed by cryptographic identity and semantic search.
9
+
10
+ Built on [Harper](https://github.com/HarperFast/harper). Single process. No sidecars. Zero external API calls for embeddings.
11
+
12
+ ## Why
13
+
14
+ Every agent framework gives you chat history. None of them give you *identity*.
15
+
16
+ An agent that can't remember what it learned yesterday, can't prove who it is to another agent, and loses its personality on restart isn't really an agent. It's a stateless function with a system prompt.
17
+
18
+ Flair fixes that:
19
+
20
+ - **Identity** — Ed25519 key pairs. Agents sign every request. No passwords, no API keys, no shared secrets.
21
+ - **Memory** — Persistent knowledge with semantic search. Write a lesson learned today, find it six months from now by meaning, not keywords.
22
+ - **Soul** — Personality, values, procedures. The stuff that makes an agent *that agent*, not just another LLM wrapper.
23
+
24
+ ## How It Works
25
+
26
+ Flair is a native [Harper v5](https://github.com/HarperFast/harper) application. Harper handles HTTP, persistence (RocksDB), and application logic in a single process.
27
+
28
+ ```
29
+ Agent ──[Ed25519-signed request]──▶ Flair (Harper)
30
+ ├── Auth middleware (verify signature)
31
+ ├── Identity (Agent + Integration tables)
32
+ ├── Memory (write → auto-embed → store)
33
+ ├── Soul (permanent personality/values)
34
+ └── Search (semantic + keyword, ranked)
35
+ ```
36
+
37
+ **No external dependencies at runtime.** Embeddings are generated in-process using [nomic-embed-text](https://huggingface.co/nomic-ai/nomic-embed-text-v1.5-GGUF) via a Harper plugin. Model runs on CPU or GPU (Metal, CUDA). No API calls, no sidecar processes, no network hops.
38
+
39
+ ## Features
40
+
41
+ ### Cryptographic Identity
42
+ Every agent has an Ed25519 key pair. Requests are signed with `agentId:timestamp:nonce:METHOD:/path` and verified against the agent's registered public key. 30-second replay window with nonce deduplication.
43
+
44
+ ### Semantic Memory
45
+ Memories are automatically embedded on write using [nomic-embed-text](https://huggingface.co/nomic-ai/nomic-embed-text-v1.5-GGUF) (768 dimensions). Search by meaning:
46
+
47
+ ```bash
48
+ # Write a memory
49
+ flair memory write "Harper v5 sandbox blocks node:module but process.dlopen works"
50
+
51
+ # Find it later by concept, not exact words
52
+ flair memory search "native addon loading in sandboxed runtimes"
53
+ # → [0.67] Harper v5 sandbox blocks node:module but process.dlopen works
54
+ ```
55
+
56
+ ### Tiered Durability
57
+ Not all memories are equal:
58
+
59
+ | Durability | Delete | TTL | Use Case |
60
+ |------------|--------|-----|----------|
61
+ | `permanent` | ❌ Rejected | None | Identity, values, core knowledge |
62
+ | `persistent` | ✅ Allowed | None | Daily logs, project context |
63
+ | `standard` | ✅ Allowed | None | Working memory (default) |
64
+ | `ephemeral` | ✅ Allowed | 24h | Scratch space, temp context |
65
+
66
+ ### Real-Time Feeds
67
+ Subscribe to memory or soul changes via WebSocket/SSE. Useful for dashboards, cross-agent sync, or audit trails.
68
+
69
+ ### Multi-Agent
70
+ One Flair instance serves any number of agents. Each agent has its own keys, memories, and soul. Agents can't read each other's data without explicit access grants.
71
+
72
+ ## Quick Start
73
+
74
+ ### Prerequisites
75
+ - [Node.js 20+](https://nodejs.org/) (24+ recommended)
76
+
77
+ ### Install & Run
78
+
79
+ ```bash
80
+ # Install
81
+ npm install -g @tpsdev-ai/flair
82
+
83
+ # Bootstrap a Flair instance (installs Harper, creates database, starts service)
84
+ flair init
85
+
86
+ # Register your first agent
87
+ flair agent add mybot --name "My Bot" --role assistant
88
+
89
+ # Check everything is working
90
+ flair status
91
+ ```
92
+
93
+ That's it. Your agent now has identity and memory.
94
+
95
+ ### Use with OpenClaw
96
+
97
+ ```bash
98
+ npm install @tpsdev-ai/openclaw-flair
99
+ ```
100
+
101
+ Add to your `openclaw.json`:
102
+ ```json
103
+ {
104
+ "memory": {
105
+ "provider": "@tpsdev-ai/openclaw-flair"
106
+ }
107
+ }
108
+ ```
109
+
110
+ Your agent will automatically remember things between sessions and recall them by meaning.
111
+
112
+ ### Use the CLI directly
113
+
114
+ ```bash
115
+ # Write a memory
116
+ flair memory add --agent mybot --content "Harper v5 sandbox blocks bare imports"
117
+
118
+ # Search by meaning, not keywords
119
+ flair memory search --agent mybot --q "native module loading issues"
120
+
121
+ # Set personality
122
+ flair soul set --agent mybot --key role --value "Security reviewer, meticulous and skeptical"
123
+
124
+ # Back up everything
125
+ flair backup --admin-pass "$FLAIR_ADMIN_PASS"
126
+
127
+ # Restore from backup
128
+ flair restore ./flair-backup-2026-03-15.json --admin-pass "$FLAIR_ADMIN_PASS"
129
+ ```
130
+
131
+ ### Cold Start Bootstrap
132
+
133
+ Agents can pull their full context on startup via the `BootstrapMemories` endpoint:
134
+
135
+ ```bash
136
+ curl -H "Authorization: TPS-Ed25519 ..." \
137
+ -X POST http://localhost:9926/BootstrapMemories \
138
+ -d '{"agentId": "mybot", "maxTokens": 4000}'
139
+ ```
140
+
141
+ Returns soul + recent memories + relevant context as a formatted block. Bounded context regardless of total memory size.
142
+
143
+ ## Architecture
144
+
145
+ ```
146
+ flair/
147
+ ├── src/cli.ts # CLI: init, agent, status, backup, grant
148
+ ├── config.yaml # Harper app configuration
149
+ ├── schemas/
150
+ │ ├── agent.graphql # Agent + Integration + MemoryGrant tables
151
+ │ └── memory.graphql # Memory + Soul tables
152
+ ├── resources/
153
+ │ ├── auth-middleware.ts # Ed25519 verification + agent scoping
154
+ │ ├── embeddings-provider.ts # In-process nomic embeddings
155
+ │ ├── Memory.ts # Durability enforcement + auto-embed
156
+ │ ├── Soul.ts # Permanent-by-default personality
157
+ │ ├── MemorySearch.ts # Hybrid semantic + keyword search
158
+ │ ├── MemoryBootstrap.ts # Cold start context assembly
159
+ │ └── MemoryFeed.ts # Real-time memory changes
160
+ ├── plugins/
161
+ │ └── openclaw-memory/ # @tpsdev-ai/openclaw-flair plugin
162
+ └── SECURITY.md # Threat model + auth documentation
163
+ ```
164
+
165
+ ### Key Design Decisions
166
+
167
+ - **Harper-native** — No Express, no middleware frameworks. Harper IS the runtime.
168
+ - **In-process embeddings** — Native [nomic-embed-text](https://huggingface.co/nomic-ai/nomic-embed-text-v1.5-GGUF) (768 dimensions) via [llama.cpp](https://github.com/ggerganov/llama.cpp). Runs on CPU or GPU (Metal, CUDA). No API calls, no OpenAI key needed.
169
+ - **Schema-driven** — GraphQL schemas with `@table @export` auto-generate REST CRUD. Custom resources extend behavior (durability guards, auto-embedding, search).
170
+ - **Zero admin tokens on disk** — Admin credentials come from the `HDB_ADMIN_PASSWORD` environment variable only. Never stored on the filesystem.
171
+
172
+ ## Deployment
173
+
174
+ ### Local (default)
175
+
176
+ ```bash
177
+ flair init
178
+ ```
179
+
180
+ Your data stays on your machine. Best for personal agents, dev teams, and privacy-first setups. Flair runs as a single Harper process — no Docker, no cloud, no external services.
181
+
182
+ ### Remote Server
183
+
184
+ Run Flair on a VPS or cloud instance. Agents connect over HTTPS:
185
+
186
+ ```bash
187
+ # On the server
188
+ flair init --port 9926
189
+ # Agents connect with:
190
+ FLAIR_URL=https://your-server:9926 flair agent add mybot
191
+ ```
192
+
193
+ Good for teams with multiple machines or always-on agents.
194
+
195
+ ### Harper Fabric (coming soon)
196
+
197
+ Managed multi-region deployment via [Harper Fabric](https://www.harperdb.io/). Data replication, automatic failover, web dashboard. Enterprise scale without ops overhead.
198
+
199
+ ## Security
200
+
201
+ See [SECURITY.md](SECURITY.md) for the full security model, threat analysis, and recommendations.
202
+
203
+ **Key points:**
204
+ - Ed25519 cryptographic identity — agents sign every request
205
+ - Collection-level data isolation — agents can't read each other's memories
206
+ - Admin credentials never stored on disk — environment variables only
207
+ - Key rotation via `flair agent rotate-key`
208
+ - Cross-agent access requires explicit grants
209
+
210
+ ## Development
211
+
212
+ ```bash
213
+ bun install # Install dependencies
214
+ bun run build # Compile TypeScript → dist/
215
+ bun test # Run unit + integration tests
216
+ ```
217
+
218
+ Integration tests spin up a real Harper instance on a random port, run the test suite, and tear down. No mocks for the database layer.
219
+
220
+ ## Status
221
+
222
+ > **Note:** Flair uses [Harper v5](https://github.com/HarperFast/harper), currently in beta. We run it in production daily and track upstream closely. Pin your Harper version.
223
+
224
+ Flair is in active development and daily use. We dogfood it — the agents that build Flair use Flair for their own memory and identity. 7 agents, 150+ memories, running continuously since March 2026.
225
+
226
+ **What works:**
227
+ - ✅ Ed25519 agent identity and auth
228
+ - ✅ CLI: init, agent add/remove/rotate-key, status, backup/restore, grant/revoke
229
+ - ✅ Memory CRUD with durability enforcement
230
+ - ✅ In-process semantic embeddings (768-dim nomic-embed-text, Metal GPU)
231
+ - ✅ Hybrid search (semantic + keyword)
232
+ - ✅ Soul (permanent personality/values)
233
+ - ✅ Real-time feeds (WebSocket/SSE)
234
+ - ✅ Agent-scoped data isolation
235
+ - ✅ Cold start bootstrap
236
+ - ✅ OpenClaw memory plugin
237
+
238
+ **What's next:**
239
+ - [ ] Encryption at rest (opt-in AES-256-GCM per memory)
240
+ - [ ] Pluggable embedding backends (OpenAI, Cohere, local)
241
+ - [ ] Harper Fabric deployment (managed multi-office)
242
+ - [ ] Scheduled automatic backups
243
+
244
+ ## License
245
+
246
+ [Apache 2.0](LICENSE)
package/SECURITY.md ADDED
@@ -0,0 +1,116 @@
1
+ # Flair Security Model
2
+
3
+ ## Overview
4
+
5
+ Flair uses cryptographic identity (Ed25519) for agent authentication and
6
+ collection-level scoping to enforce data isolation between agents.
7
+
8
+ ## Authentication
9
+
10
+ ### Agent Authentication (Ed25519)
11
+
12
+ Every request includes an `Authorization` header:
13
+
14
+ ```
15
+ TPS-Ed25519 <agentId>:<timestamp>:<nonce>:<signature>
16
+ ```
17
+
18
+ The signature covers `agentId:timestamp:nonce:METHOD:/path` using the
19
+ agent's Ed25519 private key. The server verifies against the agent's
20
+ registered public key.
21
+
22
+ - **Replay window:** 30 seconds
23
+ - **Nonce deduplication:** Prevents replay within the window
24
+ - **No shared secrets:** Each agent has its own key pair
25
+
26
+ ### Admin Authentication
27
+
28
+ Admin operations (agent management, backup, restore) use Harper's
29
+ built-in HTTP Basic auth:
30
+
31
+ ```
32
+ Authorization: Basic <base64(admin:password)>
33
+ ```
34
+
35
+ The admin password is set via `HDB_ADMIN_PASSWORD` environment variable
36
+ at Harper startup. **It is never stored on the filesystem by Flair.**
37
+
38
+ ## Data Scoping
39
+
40
+ ### Memory Isolation
41
+
42
+ Each agent can only read and write its own memories. This is enforced at
43
+ the database layer (Harper resource `search()` override), not application
44
+ logic:
45
+
46
+ - `GET /Memory/` — returns only the authenticated agent's memories
47
+ - `POST /Memory` — writes with the authenticated agent's ID
48
+ - `POST /MemorySearch` — searches only the authenticated agent's memories
49
+
50
+ ### Cross-Agent Access
51
+
52
+ Explicit grants allow one agent to read another's memories:
53
+
54
+ ```
55
+ MemoryGrant { fromAgentId, toAgentId, scope: "read" }
56
+ ```
57
+
58
+ Grants are created by admin or by the granting agent.
59
+
60
+ ### Admin Bypass
61
+
62
+ Admin-authenticated requests bypass agent scoping. Admin can read all
63
+ memories, all souls, and all agent records. SQL and GraphQL endpoints
64
+ are restricted to admin-only.
65
+
66
+ ## Key Management
67
+
68
+ ### Key Storage
69
+
70
+ Private keys are stored at `~/.flair/keys/<agentId>.key` with `0600`
71
+ permissions (owner read/write only). Legacy path `~/.tps/secrets/flair/`
72
+ is supported with deprecation warnings.
73
+
74
+ ### Key Generation
75
+
76
+ Keys are generated during `flair agent add` using Ed25519 (via tweetnacl).
77
+ The 32-byte seed is stored; the full 64-byte secret key is derived at
78
+ runtime.
79
+
80
+ ### Key Rotation
81
+
82
+ `flair agent rotate-key <id>` generates a new key pair, updates the
83
+ public key in Flair, and backs up the old key as `<agentId>.key.bak`.
84
+
85
+ ## Threat Model
86
+
87
+ ### Threats Mitigated
88
+
89
+ - **Agent impersonation:** Ed25519 signatures prevent one agent from
90
+ acting as another without possessing the private key.
91
+ - **Cross-agent data leakage:** Collection-level scoping ensures agents
92
+ can only query their own data.
93
+ - **Replay attacks:** 30-second window + nonce deduplication.
94
+ - **Privilege escalation via SQL:** SQL and GraphQL endpoints blocked
95
+ for non-admin agents.
96
+ - **Admin token theft from filesystem:** Admin credentials are only in
97
+ process environment, never on disk.
98
+
99
+ ### Threats NOT Mitigated (Runtime Responsibility)
100
+
101
+ - **Same-OS-user key theft:** If multiple agents run as the same OS user,
102
+ file permissions alone don't prevent key access. Use process-level
103
+ sandboxing (nono, Docker, separate users) to isolate agents.
104
+ - **Memory dumps:** Private keys exist in process memory. A compromised
105
+ process could extract them.
106
+ - **Network sniffing:** Flair uses HTTP by default. Use HTTPS in
107
+ production or restrict to localhost.
108
+
109
+ ## Recommendations
110
+
111
+ 1. **Use HTTPS** for any non-localhost deployment
112
+ 2. **Sandbox agents** with nono, Docker, or separate OS users
113
+ 3. **Rotate keys** periodically with `flair agent rotate-key`
114
+ 4. **Back up** with `flair backup` — backup files contain memory content
115
+ and should be treated as sensitive
116
+ 5. **Monitor** with `flair status` — warns about key permission issues
package/config.yaml ADDED
@@ -0,0 +1,16 @@
1
+ name: flair
2
+ rest: true
3
+
4
+ http:
5
+ port: 8787
6
+
7
+ graphqlSchema:
8
+ files: schemas/*.graphql
9
+
10
+ jsResource:
11
+ files: dist/resources/*.js
12
+
13
+ authentication:
14
+ # Default secure. Set to false for local development only.
15
+ authorizeLocal: true
16
+ enableSessions: true