JZzzzStudio/CosmicPhantom
About
本地优先、确认后生效、可审计的 AI Agent 长期记忆引擎。原始事件可回放,记忆可纠错,答案能回到原话。| Local-first, confirmation-gated, auditable memory for AI agents.
AI & Machine LearningMeasured star growth
- in 24h
- +12
- in 7 days
- Collecting history
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.en.md
Original
Memory your agent should keep — and can actually correct.
Local-first · Confirmation-gated · Replayable · Auditable
中文 · English
In 30 seconds
- Evidence first. Every turn lands in
events.db: append-only, replayable, exportable. - Nothing is remembered without confirmation. Extracted content waits in
candidates/. - Answers can return to the source. Results carry
source_refback to the card, log, or raw event.
| Without CP | With CP |
|---|---|
| Re-explain past decisions every session | Handoff state and confirmed memory come back |
| A passing remark becomes a permanent fact | Candidates stay isolated until confirmed |
| Corrections fight the old answer | Corrections bind to the current version and retire the old one |
| No idea why the agent said that | Every result expands to its source |
What it solves
Long-running agents lose context, drift in summaries, and keep stale conclusions alive. CP does not just store more; it separates memory into three layers with explicit boundaries:
- Evidence — raw events, append-only, replayable.
- Candidates — extracted content that has no effect until confirmed.
- Active memory — confirmed, versioned, traceable, correctable.
How it works
Agent
↓ MCP / CLI / hooks
events.db (raw events)
↓ replayable projection
daily/ (dated work log)
↓ extraction
candidates/ (pending; never in default retrieval)
↓ explicit user confirmation
domains/ (project / preference / knowledge)
↓ retrieval + evidence gate
bounded injection (identity card / recovery capsule / memory)
| Domain | Default scope | Purpose |
|---|---|---|
project |
workspace |
Current goals, decisions, blockers, next actions |
preference |
global |
Cross-project preferences and standing rules |
knowledge |
explicit | References and domain material |
Quick start
Requires Node.js 22.5+ and Git. No GPU needed; local vectors are optional and BM25 is the default.
git clone https://github.com/JZzzzStudio/cosmic-phantom.git
cd CosmicPhantom
npm run demo:memory
The demo uses synthetic data and cleans up its temporary instance. See FIRST-MEMORY.md for the step-by-step loop.
Connect your agent
CP is a standard MCP server. The installer writes the launch command into your host config and verifies that 17 tools actually start:
npx cosmic-phantom install --root <instance> --agent <agent-id>
npx cosmic-phantom verify --root <instance>
- Host support comes from
add-mcp: 25 clients including Claude Code, Codex, Cursor, VS Code, Windsurf, and Cline - The installer backs up the config, merges only
cosmic-phantom, reads it back, and rolls back on failure - Fully quit and restart the host afterward; existing sessions do not hot-load MCP
- Installer source:
npm/. If the npm package is not published yet, runnode cli.cjsthere
Manual MCP command:
<node> --experimental-sqlite <instance>/resources/mcp-server/index.js --root <instance>
Three guarantees
1. Confirmation gate
Before confirmation, a candidate is absent from default retrieval, injection, and the identity card:
store_memory → candidate (pending)
preview_candidate_confirmation → previewHash
confirm_candidates(previewHash, userConfirmed=true) → active
Retrieval returns zero hits before confirmation and the new card after. A stale preview rejects the whole batch; there is no partial write.
2. Provenance
Results carry their source:
{
"id": "ent-...-v1",
"source_ref": "legacy:20260811-0018",
"source_kind": "legacy_migration",
"source": { "legacy_source": "distilled/2026-08-11.md" }
}
Standard event anchors use events.db:cp-evt-v2:<hash>. Migrated cards fall back to their legacy id/path instead of returning null.
3. Failures are visible
verify checks card fields, source coverage, index drift, privacy egress, queue backlog, and fail-open counters. “Not initialized” is not reported as “broken”, and degraded mode is not reported as success.
node --experimental-sqlite memory-cli.js verify --root <instance>
Where the data lives
Everything stays inside the instance directory, $HOME/.cosmic-phantom by default:
| Path | Role | Rebuildable |
|---|---|---|
events.db |
Raw event source | No; long-lived |
daily/ |
Dated projection | Yes; replay |
candidates/ |
Pending review | No; audit trail |
domains/ |
Active memory (three domains) | No; controlled evolution |
memories/ |
Legacy active memory, read-only | No new writes after migration |
current-state.json |
Handoff state | No; revision-guarded |
embedding-db/ |
Optional vectors | Yes; may be absent |
Derived layers never overwrite raw events or unconfirmed memory.
Privacy and private instances
- The public repo contains code, docs, synthetic samples, and redacted numbers — no personal sessions, instance databases, or credentials
- The hot path calls no cloud model; if local vectors are missing, retrieval falls back to BM25 and reports the degradation
- Sensitive content stays local by default and can be explicitly withdrawn; exports do not resurrect redacted content
- Private instances can require a local grant bound to machine, agent, and expiry; unauthenticated access is read-only
- The grant blocks unauthenticated agents, not the local OS user
Private instances
Public instances do not require a GitHub identity. To bind an instance to a private repository, enable .cp/private.json in the instance root:
node --experimental-sqlite memory-cli.js auth login --repo <owner/repo> --owner <github-id> --agent <agent-id> --root <instance>
Write commands, MCP write tools, and data sync then verify a local grant bound to machine, agent, and expiry. Re-verify after changing agents or machines, when the grant expires, and before any sync. Unauthenticated access is read-only; private mode is off by default. The grant blocks unauthenticated agents, not the local OS user.
Current limitations
- Single-user local system, not multi-tenant;
scopeis content scope, not account permission - BM25 is the default. Hybrid retrieval is not enabled: measured recall gained nothing and p95 rose 154%; re-entry gates live in the evaluation report
agentscope is not implemented; onlyglobal/workspace- Scale tested at 275 entities / 81 active cards; thousands of cards are unverified
- Host integration needs MCP config plus a restart; database/UI-only hosts require manual setup
- The three-domain migration guarantees data movement, provenance, and rollback — not a line-by-line review of every card
Documentation
| Goal | Document |
|---|---|
| First memory loop | docs/FIRST-MEMORY.md |
| Data model and invariants | docs/ARCHITECTURE.md |
| Product design | docs/PRODUCT-DESIGN.md |
| Agent integration | docs/AGENT-CONFIG.md |
| CLI reference | docs/CLI.md |
| Terminology | docs/TERMINOLOGY.md |
| Directory map | DIRECTORY-MAP.md |
| Security | SECURITY.md |
| Contributing | CONTRIBUTING.md |
License
MIT for the engine code. Personal instance data, private repositories, and unpublished instance content are not distributed.
Explore related projects
Loading…