@phantomind/core 0.1.0 → 0.1.1

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 (2) hide show
  1. package/README.md +534 -0
  2. package/package.json +1 -1
package/README.md ADDED
@@ -0,0 +1,534 @@
1
+ # 🔮 PhantomMindAI
2
+
3
+ **Universal AI Development Enhancement Layer**
4
+
5
+ > *"You already pay for Copilot, Cursor, or Claude. PhantomMindAI makes what you already have 10x more effective."*
6
+
7
+ [![npm version](https://img.shields.io/npm/v/@phantomind/core.svg)](https://www.npmjs.com/package/@phantomind/core)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+ [![Node.js >=18](https://img.shields.io/badge/node-%3E%3D18-brightgreen)](https://nodejs.org)
10
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.8-blue)](https://www.typescriptlang.org)
11
+ [![MCP Compatible](https://img.shields.io/badge/MCP-compatible-purple)](https://modelcontextprotocol.io)
12
+
13
+ ---
14
+
15
+ ## What is PhantomMindAI?
16
+
17
+ PhantomMindAI solves the **context amnesia problem**: AI assistants forget everything about your project every session, every context switch, and every time a new team member onboards.
18
+
19
+ PhantomMindAI provides:
20
+
21
+ - **Persistent context layer** — one source of truth (`SKILLS.md`, `RULES.md`, `schema.json`) synced to every AI assistant automatically
22
+ - **Universal LLM abstraction** — one API for Anthropic, OpenAI, Gemini, Groq, Mistral, Ollama, DeepSeek, and OpenRouter, with automatic fallback and budget routing
23
+ - **Agentic task execution** — multi-role agent orchestration with human-in-the-loop checkpoints
24
+ - **AI output quality enforcement** — secret scanning, hallucination detection, dual-model verification, consistency checking
25
+ - **MCP Server** — expose project intelligence as a Model Context Protocol server for Cursor, Continue, Claude Code, and more
26
+ - **Full observability** — cost tracking, audit trails, and analytics dashboard
27
+
28
+ ---
29
+
30
+ ## Table of Contents
31
+
32
+ - [Installation](#installation)
33
+ - [Quick Start](#quick-start)
34
+ - [CLI Reference](#cli-reference)
35
+ - [Configuration](#configuration)
36
+ - [Supported AI Assistants](#supported-ai-assistants)
37
+ - [Supported LLM Providers](#supported-llm-providers)
38
+ - [Programmatic API](#programmatic-api)
39
+ - [MCP Server](#mcp-server)
40
+ - [Agent System](#agent-system)
41
+ - [Quality Layer](#quality-layer)
42
+ - [Observability](#observability)
43
+ - [Architecture](#architecture)
44
+
45
+ ---
46
+
47
+ ## Installation
48
+
49
+ ```bash
50
+ # Install globally (recommended — enables `phantomind` CLI)
51
+ npm install -g @phantomind/core
52
+
53
+ # Or install as a project dependency
54
+ npm install @phantomind/core
55
+
56
+ # Verify installation
57
+ phantomind --version
58
+ ```
59
+
60
+ **Requirements:** Node.js ≥ 18
61
+
62
+ ---
63
+
64
+ ## Quick Start
65
+
66
+ ### 1. Initialize in your project
67
+
68
+ ```bash
69
+ cd your-project
70
+ phantomind init
71
+ ```
72
+
73
+ This creates:
74
+
75
+ ```
76
+ .phantomind/
77
+ SKILLS.md ← Auto-learned project patterns
78
+ RULES.md ← AI behavior rules
79
+ schema.json ← Output contracts
80
+ config.yaml ← PhantomMindAI configuration
81
+ ```
82
+
83
+ ### 2. Sync to your AI tools
84
+
85
+ ```bash
86
+ phantomind sync
87
+ ```
88
+
89
+ Generated adapter files (auto-updated, never edit directly):
90
+
91
+ ```
92
+ .github/copilot-instructions.md ← GitHub Copilot
93
+ .cursorrules ← Cursor
94
+ .clinerules ← Cline
95
+ .continue/config.json ← Continue
96
+ .windsurfrules ← Windsurf
97
+ .zed/settings.json ← Zed
98
+ .aider.conf.yml ← Aider
99
+ .claude/CLAUDE.md ← Claude Code CLI
100
+ AGENTS.md ← OpenAI Codex CLI
101
+ ```
102
+
103
+ ### 3. Use the programmatic API (optional)
104
+
105
+ ```typescript
106
+ import { phantom } from '@phantomind/core';
107
+
108
+ await phantom.init();
109
+
110
+ // Complete with auto-routing across providers
111
+ const response = await phantom.complete('Refactor this function to use async/await');
112
+
113
+ // Run an agentic task
114
+ const result = await phantom.agent('Add input validation to the user registration endpoint');
115
+
116
+ // Semantic search across codebase
117
+ const matches = await phantom.search('authentication middleware');
118
+ ```
119
+
120
+ ---
121
+
122
+ ## CLI Reference
123
+
124
+ ```
125
+ phantomind [command] [options]
126
+ ```
127
+
128
+ | Command | Description |
129
+ |---------|-------------|
130
+ | `phantomind init` | Initialize PhantomMindAI in the current project |
131
+ | `phantomind sync` | Sync context to all configured AI assistant adapters |
132
+ | `phantomind serve` | Start the MCP server (stdio or HTTP transport) |
133
+ | `phantomind eval` | Test and benchmark LLM provider connections |
134
+ | `phantomind validate [files...]` | Scan code for secrets, hallucinations, and consistency issues |
135
+ | `phantomind audit` | View cost reports and audit trail |
136
+ | `phantomind stats` | Display project context statistics |
137
+ | `phantomind agent <task>` | Execute an agentic task from the CLI |
138
+ | `phantomind schema [name]` | List or display schema definitions |
139
+
140
+ ### `phantomind init`
141
+
142
+ ```bash
143
+ phantomind init [options]
144
+
145
+ Options:
146
+ --provider <name> Primary LLM provider (anthropic|openai|gemini|groq|mistral|ollama|deepseek|openrouter)
147
+ --adapters <list> Comma-separated adapter list (e.g. copilot,cursor,cline)
148
+ --yes Skip interactive prompts
149
+ ```
150
+
151
+ ### `phantomind sync`
152
+
153
+ ```bash
154
+ phantomind sync [options]
155
+
156
+ Options:
157
+ --adapters <list> Only sync specific adapters
158
+ --dry-run Preview changes without writing files
159
+ --verbose Show per-file diff
160
+ ```
161
+
162
+ ### `phantomind validate`
163
+
164
+ ```bash
165
+ phantomind validate [files...] [options]
166
+
167
+ Options:
168
+ --no-secrets Skip secret scanning
169
+ --no-hallucinations Skip hallucination detection
170
+ --no-consistency Skip consistency checking
171
+ --fix Auto-fix detected secrets (redaction)
172
+ ```
173
+
174
+ ### `phantomind audit`
175
+
176
+ ```bash
177
+ phantomind audit [options]
178
+
179
+ Options:
180
+ --period <p> today|week|month|all (default: today)
181
+ --type <t> dashboard|costs|actions (default: dashboard)
182
+ --format <f> terminal|markdown|json
183
+ ```
184
+
185
+ ### `phantomind agent`
186
+
187
+ ```bash
188
+ phantomind agent <task> [options]
189
+
190
+ Options:
191
+ --role <role> architect|implementer|securityReviewer|testWriter|documenter
192
+ --orchestrate Use multi-role orchestration
193
+ --roles <list> Roles for orchestration (e.g. architect,implementer,testWriter)
194
+ --max-steps <n> Maximum agent steps (default: 30)
195
+ ```
196
+
197
+ ---
198
+
199
+ ## Configuration
200
+
201
+ PhantomMindAI is configured via `.phantomind/config.yaml`:
202
+
203
+ ```yaml
204
+ # .phantomind/config.yaml
205
+
206
+ providers:
207
+ primary:
208
+ name: anthropic
209
+ model: claude-opus-4-5
210
+ apiKey: ${ANTHROPIC_API_KEY}
211
+ fallback:
212
+ name: openai
213
+ model: gpt-4o
214
+ apiKey: ${OPENAI_API_KEY}
215
+ budget:
216
+ name: groq
217
+ model: llama-3.3-70b-versatile
218
+ apiKey: ${GROQ_API_KEY}
219
+
220
+ adapters:
221
+ - copilot
222
+ - cursor
223
+ - cline
224
+ - continue
225
+ - claude-code
226
+ - codex
227
+
228
+ mcp:
229
+ enabled: true
230
+ port: 3333
231
+
232
+ budget:
233
+ maxCostPerDay: 5.00
234
+ warningAt: 0.80
235
+ fallbackOnBudget: budget
236
+
237
+ agent:
238
+ maxSteps: 30
239
+ memory:
240
+ enabled: true
241
+ maxEntries: 200
242
+
243
+ quality:
244
+ secretScanning: true
245
+ hallucinationDetection: true
246
+ dualVerification: false
247
+ ```
248
+
249
+ ### Environment Variables
250
+
251
+ | Variable | Provider |
252
+ |----------|----------|
253
+ | `ANTHROPIC_API_KEY` | Anthropic (Claude) |
254
+ | `OPENAI_API_KEY` | OpenAI (GPT) |
255
+ | `GEMINI_API_KEY` | Google Gemini |
256
+ | `GROQ_API_KEY` | Groq |
257
+ | `MISTRAL_API_KEY` | Mistral |
258
+ | `DEEPSEEK_API_KEY` | DeepSeek |
259
+ | `OPENROUTER_API_KEY` | OpenRouter |
260
+
261
+ PhantomMindAI automatically loads `.env` / `.env.local` from the project root.
262
+
263
+ ---
264
+
265
+ ## Supported AI Assistants
266
+
267
+ | Adapter | File Generated | Status |
268
+ |---------|---------------|--------|
269
+ | GitHub Copilot | `.github/copilot-instructions.md` | ✅ |
270
+ | Cursor | `.cursorrules` | ✅ |
271
+ | Cline | `.clinerules` | ✅ |
272
+ | Continue | `.continue/config.json` | ✅ |
273
+ | Windsurf | `.windsurfrules` | ✅ |
274
+ | Zed | `.zed/settings.json` | ✅ |
275
+ | Aider | `.aider.conf.yml` | ✅ |
276
+ | Claude Code | `.claude/CLAUDE.md` | ✅ |
277
+ | OpenAI Codex | `AGENTS.md` | ✅ |
278
+
279
+ ---
280
+
281
+ ## Supported LLM Providers
282
+
283
+ | Provider | Models | Notes |
284
+ |----------|--------|-------|
285
+ | **Anthropic** | claude-opus-4-5, claude-sonnet-4-5, claude-haiku-3-5 | Recommended primary |
286
+ | **OpenAI** | gpt-4o, gpt-4o-mini, o3, o4-mini | Excellent fallback |
287
+ | **Google Gemini** | gemini-2.0-flash, gemini-2.5-pro | Best for large context |
288
+ | **Groq** | llama-3.3-70b, mixtral-8x7b | Best budget option |
289
+ | **Mistral** | mistral-large-latest, codestral | Strong for code |
290
+ | **Ollama** | any local model | No API key, fully local |
291
+ | **DeepSeek** | deepseek-chat, deepseek-reasoner | Cost-efficient |
292
+ | **OpenRouter** | 200+ models | Meta-provider |
293
+
294
+ ### Provider Routing
295
+
296
+ ```yaml
297
+ providers:
298
+ primary: # Highest quality — used by default
299
+ name: anthropic
300
+ model: claude-opus-4-5
301
+ fallback: # Used if primary fails
302
+ name: openai
303
+ model: gpt-4o
304
+ budget: # Used when daily cost threshold exceeded
305
+ name: groq
306
+ model: llama-3.3-70b-versatile
307
+ local: # Used for offline/sensitive tasks
308
+ name: ollama
309
+ model: llama3.2
310
+ ```
311
+
312
+ ---
313
+
314
+ ## Programmatic API
315
+
316
+ ```typescript
317
+ import { phantom } from '@phantomind/core';
318
+
319
+ // Initialize (loads config, connects providers)
320
+ await phantom.init();
321
+
322
+ // Get project context (intelligent multi-layer context)
323
+ const ctx = await phantom.ctx({ maxTokens: 4000 });
324
+
325
+ // Complete with context injection and auto-routing
326
+ const response = await phantom.complete('Explain the auth module', {
327
+ maxTokens: 1000,
328
+ temperature: 0.3,
329
+ });
330
+
331
+ // Complete with intelligent retry on failure
332
+ const result = await phantom.completeWithRetry('Implement JWT refresh logic');
333
+
334
+ // Run an agentic task (single role)
335
+ const agentResult = await phantom.agent('Refactor the payment service', {
336
+ role: 'implementer',
337
+ maxSteps: 25,
338
+ });
339
+
340
+ // Multi-agent orchestration
341
+ const orchestrated = await phantom.orchestrate(
342
+ 'Build a rate limiting middleware',
343
+ ['architect', 'implementer', 'securityReviewer', 'testWriter'],
344
+ );
345
+
346
+ // Semantic search across codebase
347
+ const matches = await phantom.search('database connection pooling', 5);
348
+ // returns: Array<{ path, score, snippet }>
349
+
350
+ // Sync adapters
351
+ await phantom.sync(['copilot', 'cursor'], /* dryRun */ false);
352
+
353
+ // Validate code
354
+ const { secrets, hallucinations } = await phantom.validate(code, 'auth.ts');
355
+
356
+ // Cost report
357
+ const costs = phantom.costs('today'); // 'today' | 'week' | 'month' | 'all'
358
+
359
+ // Analytics dashboard
360
+ const dashboard = phantom.dashboard();
361
+ console.log(dashboard.formatTerminal());
362
+
363
+ // Learn project patterns
364
+ const skills = await phantom.learn();
365
+
366
+ // Save state
367
+ await phantom.save();
368
+ ```
369
+
370
+ ---
371
+
372
+ ## MCP Server
373
+
374
+ PhantomMindAI exposes a [Model Context Protocol](https://modelcontextprotocol.io) server providing 9 tools to any MCP-compatible AI assistant:
375
+
376
+ ```bash
377
+ phantomind serve
378
+ ```
379
+
380
+ ### MCP Tools
381
+
382
+ | Tool | Description |
383
+ |------|-------------|
384
+ | `get_project_context` | Full project context (skills, rules, schema) |
385
+ | `search_codebase` | Semantic search across indexed files |
386
+ | `validate_code` | Secret + hallucination scan |
387
+ | `get_schema` | Retrieve a named JSON/Zod schema |
388
+ | `list_schemas` | List all registered schemas |
389
+ | `complete` | LLM completion via provider router |
390
+ | `run_agent` | Execute an agentic task |
391
+ | `get_cost_report` | Current cost breakdown |
392
+ | `get_audit_log` | Recent audit entries |
393
+
394
+ ### MCP Configuration (Claude Desktop / Continue)
395
+
396
+ ```json
397
+ {
398
+ "mcpServers": {
399
+ "phantomind": {
400
+ "command": "npx",
401
+ "args": ["phantomind", "serve"],
402
+ "cwd": "/path/to/your/project"
403
+ }
404
+ }
405
+ }
406
+ ```
407
+
408
+ ---
409
+
410
+ ## Agent System
411
+
412
+ ### Roles
413
+
414
+ | Role | Specialization |
415
+ |------|---------------|
416
+ | `architect` | System design, architecture decisions, dependency planning |
417
+ | `implementer` | Feature implementation, code generation, refactoring |
418
+ | `securityReviewer` | Vulnerability scanning, threat modeling, secure coding |
419
+ | `testWriter` | Unit tests, integration tests, edge cases, mocks |
420
+ | `documenter` | API docs, README, inline comments, changelogs |
421
+
422
+ ### Single-Agent Execution
423
+
424
+ ```bash
425
+ phantomind agent "Add rate limiting to the API" --role implementer --max-steps 20
426
+ ```
427
+
428
+ ### Multi-Agent Orchestration
429
+
430
+ ```bash
431
+ phantomind agent "Build OAuth2 integration" --orchestrate \
432
+ --roles architect,implementer,securityReviewer,testWriter
433
+ ```
434
+
435
+ ---
436
+
437
+ ## Quality Layer
438
+
439
+ ### Secret Scanning
440
+
441
+ Detects and redacts API keys, tokens, passwords, and credentials:
442
+
443
+ ```bash
444
+ phantomind validate src/ --secrets
445
+ ```
446
+
447
+ Detects: AWS keys, GitHub tokens, Stripe keys, OpenAI keys, JWT secrets, PEM certificates, database connection strings, and 20+ other patterns.
448
+
449
+ ### Hallucination Detection
450
+
451
+ Checks AI-generated code for:
452
+ - `import` statements referencing non-existent packages
453
+ - References to files that don't exist in the project
454
+ - Usage of type names not defined in the codebase
455
+
456
+ ### Consistency Checking
457
+
458
+ Identifies inconsistencies across the codebase:
459
+ - Naming convention violations (camelCase vs snake_case drift)
460
+ - Mixed async patterns
461
+ - Architectural boundary violations
462
+
463
+ ### Dual-Model Verification
464
+
465
+ For critical outputs, a second model independently verifies correctness before acceptance.
466
+
467
+ ---
468
+
469
+ ## Observability
470
+
471
+ ### Cost Tracking
472
+
473
+ ```bash
474
+ phantomind audit --type costs --period week
475
+ ```
476
+
477
+ Tracks cost per provider, per model, per day with budget alerts.
478
+
479
+ ### Audit Trail
480
+
481
+ All agent actions are logged to `.phantomind/audit/audit.jsonl`:
482
+
483
+ ```bash
484
+ phantomind audit --type actions
485
+ ```
486
+
487
+ ### Analytics Dashboard
488
+
489
+ ```bash
490
+ phantomind audit --type dashboard
491
+ ```
492
+
493
+ Displays: request count, total cost, success rate, response time, quality events, agent task completion.
494
+
495
+ ---
496
+
497
+ ## Architecture
498
+
499
+ ```
500
+ packages/core/src/
501
+ ├── types.ts ← All shared TypeScript interfaces
502
+ ├── index.ts ← PhantomMind class + phantom singleton
503
+ ├── config/ ← Config loading (cosmiconfig, .env, deep-merge)
504
+ ├── providers/ ← LLM provider abstractions + router
505
+ ├── context/ ← Project context management + semantic search
506
+ ├── adapters/ ← AI assistant adapter sync (9 adapters)
507
+ ├── mcp/ ← MCP Server (9 tools)
508
+ ├── agent/ ← Agentic execution engine + orchestrator
509
+ ├── quality/ ← Output quality enforcement
510
+ ├── schemas/ ← Schema registry (Zod + JSON Schema)
511
+ ├── templates/ ← SKILLS.md + RULES.md templates
512
+ ├── observability/ ← Audit, cost, dashboard
513
+ └── cli/ ← CLI commands (Commander.js)
514
+ ```
515
+
516
+ ---
517
+
518
+ ## Roadmap
519
+
520
+ | Version | Features |
521
+ |---------|---------|
522
+ | **v0.1** | Context sync, adapter generation, CLI init/sync |
523
+ | **v0.2** | Provider router, budget management, MCP server |
524
+ | **v0.3** | Agent executor, orchestrator, task queue |
525
+ | **v0.4** | Quality layer (secrets, hallucinations, consistency) |
526
+ | **v0.5** | Observability (audit, costs, dashboard) |
527
+ | **v1.0** | Schema registry, templates, stable API |
528
+ | **v1.x** | VS Code extension, Git hooks, CI/CD integration |
529
+
530
+ ---
531
+
532
+ ## License
533
+
534
+ MIT © [Synaptode](https://github.com/synaptode)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantomind/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "PhantomMindAI — Universal AI Context Layer for Development",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",