contextgit 0.0.1 → 0.0.2

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 (83) hide show
  1. package/.claude/settings.local.json +41 -0
  2. package/.contextgit/config.json +10 -0
  3. package/.contextgit/system-prompt.md +4 -0
  4. package/.github/workflows/contextgit-ci.yml +40 -0
  5. package/CLAUDE.md +123 -0
  6. package/CLAUDE.md.next +65 -0
  7. package/docs/ContextGit_ARCHITECTURE_v3.md +1141 -0
  8. package/docs/ContextGit_DELTA.md +84 -0
  9. package/docs/ContextGit_PHASE1_PLAN.md +177 -0
  10. package/docs/ContextGit_PHASE2_PLAN.md +535 -0
  11. package/docs/ContextGit_PRD_v4.md +488 -0
  12. package/docs/decisions.md +370 -0
  13. package/package.json +23 -8
  14. package/packages/api/package.json +25 -0
  15. package/packages/api/src/bootstrap.ts +64 -0
  16. package/packages/api/src/config.ts +45 -0
  17. package/packages/api/src/index.ts +17 -0
  18. package/packages/api/src/middleware/auth.test.ts +83 -0
  19. package/packages/api/src/middleware/auth.ts +41 -0
  20. package/packages/api/src/remote-store.test.ts +301 -0
  21. package/packages/api/src/router.ts +121 -0
  22. package/packages/api/src/server-config.ts +34 -0
  23. package/packages/api/src/server.ts +38 -0
  24. package/packages/api/src/store-router.ts +241 -0
  25. package/packages/api/tsconfig.json +8 -0
  26. package/packages/cli/bin/run.js +4 -0
  27. package/packages/cli/package.json +29 -0
  28. package/packages/cli/src/bootstrap.ts +68 -0
  29. package/packages/cli/src/commands/branch.ts +58 -0
  30. package/packages/cli/src/commands/claim.ts +58 -0
  31. package/packages/cli/src/commands/commit.ts +79 -0
  32. package/packages/cli/src/commands/context.ts +46 -0
  33. package/packages/cli/src/commands/doctor.ts +99 -0
  34. package/packages/cli/src/commands/init.ts +141 -0
  35. package/packages/cli/src/commands/keygen.ts +65 -0
  36. package/packages/cli/src/commands/log.ts +103 -0
  37. package/packages/cli/src/commands/merge.ts +36 -0
  38. package/packages/cli/src/commands/pull.ts +145 -0
  39. package/packages/cli/src/commands/push.ts +158 -0
  40. package/packages/cli/src/commands/remote-show.ts +87 -0
  41. package/packages/cli/src/commands/search.ts +54 -0
  42. package/packages/cli/src/commands/serve.ts +61 -0
  43. package/packages/cli/src/commands/set-remote.ts +30 -0
  44. package/packages/cli/src/commands/status.ts +62 -0
  45. package/packages/cli/src/commands/unclaim.ts +28 -0
  46. package/packages/cli/src/config.ts +64 -0
  47. package/packages/cli/src/git-hooks.ts +61 -0
  48. package/packages/cli/tsconfig.json +9 -0
  49. package/packages/core/package.json +28 -0
  50. package/packages/core/src/embeddings.test.ts +58 -0
  51. package/packages/core/src/embeddings.ts +75 -0
  52. package/packages/core/src/engine.ts +274 -0
  53. package/packages/core/src/index.ts +6 -0
  54. package/packages/core/src/snapshot.ts +82 -0
  55. package/packages/core/src/summarizer.test.ts +120 -0
  56. package/packages/core/src/summarizer.ts +113 -0
  57. package/packages/core/src/threads.ts +29 -0
  58. package/packages/core/src/types.ts +240 -0
  59. package/packages/core/tsconfig.json +9 -0
  60. package/packages/mcp/package.json +31 -0
  61. package/packages/mcp/src/auto-snapshot.ts +83 -0
  62. package/packages/mcp/src/config.ts +53 -0
  63. package/packages/mcp/src/git-sync.ts +94 -0
  64. package/packages/mcp/src/index.ts +19 -0
  65. package/packages/mcp/src/server.ts +377 -0
  66. package/packages/mcp/tsconfig.json +9 -0
  67. package/packages/store/package.json +30 -0
  68. package/packages/store/src/branch-merge.test.ts +127 -0
  69. package/packages/store/src/engine-integration.test.ts +93 -0
  70. package/packages/store/src/index.ts +3 -0
  71. package/packages/store/src/interface.ts +62 -0
  72. package/packages/store/src/local/claims.test.ts +190 -0
  73. package/packages/store/src/local/index.ts +380 -0
  74. package/packages/store/src/local/local-store.test.ts +164 -0
  75. package/packages/store/src/local/migrations.ts +99 -0
  76. package/packages/store/src/local/queries.ts +760 -0
  77. package/packages/store/src/local/schema.ts +157 -0
  78. package/packages/store/src/remote/index.ts +300 -0
  79. package/packages/store/tsconfig.json +9 -0
  80. package/pnpm-workspace.yaml +2 -0
  81. package/scripts/build.sh +28 -0
  82. package/tsconfig.base.json +14 -0
  83. package/vitest.config.ts +15 -0
@@ -0,0 +1,41 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(git add:*)",
5
+ "Bash(git commit:*)",
6
+ "Skill(claude-api)",
7
+ "Skill(claude-api:*)",
8
+ "Bash(pnpm typecheck:*)",
9
+ "Bash(pnpm test:*)",
10
+ "Bash(pnpm build:*)",
11
+ "Bash(git push:*)",
12
+ "Read(//private/tmp/**)",
13
+ "Bash(node /Users/mendetrajovski/contextgit/packages/cli/bin/run.js --help)",
14
+ "Bash(node /Users/mendetrajovski/contextgit/packages/cli/bin/run.js commit -m \"First commit\" -c \"Set up the project structure\")",
15
+ "Bash(node /Users/mendetrajovski/contextgit/packages/cli/bin/run.js context)",
16
+ "Bash(pnpm install:*)",
17
+ "Bash(node packages/cli/bin/run.js init)",
18
+ "Bash(node packages/cli/bin/run.js context)",
19
+ "Bash(chmod +x /Users/mendetrajovski/contextgit/scripts/build.sh)",
20
+ "Bash(node packages/cli/bin/run.js context -f agents-md)",
21
+ "Bash(node packages/cli/bin/run.js commit -m \"Gate 2 ralph-loop: iteration 1\" -c \"Running ralph-loop validation gate. Wired RemoteStore into CLI+MCP bootstrap. Added scripts/build.sh. All 32 tests pass.\")",
22
+ "Bash(sed -e 's/@contextgit\\\\//@contextgit\\\\//g' -e 's/ContextGit/ContextGit/g' -e 's/contextgit/contextgit/g' CLAUDE.md)",
23
+ "Bash(mv CLAUDE.md.tmp CLAUDE.md)",
24
+ "Bash(node packages/cli/bin/run.js --help)",
25
+ "Bash(node packages/cli/bin/run.js commit -m \"Session: Days 14-15 oclif CLI Skeleton \\(2026-03-10\\) #6\" -c \"Built: packages/cli scaffolded \\(package.json, tsconfig.json, bin/run.js\\). config.ts: loadConfig/findConfigPath \\(duplicated from mcp to preserve dep graph\\). bootstrap.ts: shared setup for commit/context commands. commands/init.ts: generates nanoid projectId, creates project+branch, writes .contextgit/config.json, guards against double-init. commands/commit.ts: -m msg -c content -t threads --close ids. commands/context.ts: -f format prints store.getFormattedSnapshot\\(\\). core/types.ts: id? added to ProjectInput. LocalStore.createProject uses input.id ?? nanoid\\(\\). E2E validated in fresh tmp dir. Decided: config.ts duplicated in CLI \\(mcp→cli dep not allowed\\), ProjectInput.id? for init to match DB path key to entity ID, bootstrap\\(\\) shared helper, context command reads directly from store, commit --content defaults to --message. Unresolved: semanticSearch [], context scopes, server.tool\\(\\) deprecated, CLI not installable globally \\(chmod +x\\). Next: Days 16-17 Express REST API \\(POST /commits, GET /snapshot, GET /search\\).\")",
26
+ "Bash(node packages/cli/bin/run.js commit -m \"Session: Days 18-19 System-Prompt Fragment + AutoSnapshotManager \\(2026-03-10\\) #8\" -c \"Built: CLI init.ts self-heal: when config.json exists but DB empty, reads config, detects git branch, recreates project+branch instead of bailing. CLI init.ts: system-prompt fragment written to .contextgit/system-prompt.md and printed to stdout. AutoSnapshotManager: counts tool calls, fires engine.commit\\({commitType:''auto''}\\) every N=10 non-commit calls, resets on context_commit, swallows failures. mcp/server.ts: AutoSnapshotManager wired, autoSnapshot.onToolCall\\(toolName\\) in each tool handler. Dogfooded: contextgit init on this repo \\(self-heal triggered\\), contextgit commit and context confirmed. Decided: getBranchByGitName as DB health check for self-heal, AutoSnapshotManager counts context_get and context_search toward interval, loadConfig\\(\\) called twice in createServer\\(\\) \\(acceptable\\), commitType:''auto'' for observability. Unresolved: MCP not yet live-validated, server.tool\\(\\) deprecated, loadConfig\\(\\) called twice. Next: Days 20-21 configure Claude Code MCP, EmbeddingService with @xenova/transformers all-MiniLM-L6-v2.\")",
27
+ "Bash(node packages/cli/bin/run.js commit -m \"Session: Days 22-23 RemoteStore + FTS5 Fix \\(2026-03-11\\) #10\" -c \"Built: packages/api/src/store-router.ts: Express router exposing all 20 ContextStore methods as HTTP at /v1/store/... Float32Array serialized as number[]. packages/store/src/remote/index.ts: RemoteStore implementing ContextStore via fetch against store router, date-parsing helpers, Float32Array serialization. barrel exports updated. 7 integration tests \\(project/branch CRUD, commit retrieval, formatted snapshot identical to LocalStore, open thread round-trip, FTS search, mergeBranch\\). schema.ts: CREATE_FTS_TRIGGER AFTER INSERT ON commits, SCHEMA_V3_DDL. migrations.ts: v3 fts_trigger + FTS rebuild. queries.ts: fullTextSearch JOIN fixed from commits_fts.commit_id to c.rowid = commits_fts.rowid \\(content table rowid join\\). MCP confirmed live: context_get/context_commit/context_search visible in Claude Code — Gate 1 MCP validation PASS. All 32 tests pass. Decided: createStoreRouter separate from createApp \\(project-agnostic\\), integration test in api package, afterAll Promise-based cleanup, FTS5 content table bug fixed \\(rowid join\\), migration v3 trigger covers all INSERT paths. Unresolved: RemoteStore not wired in CLI/MCP bootstrap, server.tool\\(\\) deprecated, loadConfig\\(\\) twice, Gate 2/3 not yet validated. Next: Day 24 wire RemoteStore into CLI/MCP, Gate 2 ralph-loop CLI, Gate 3 REST curl, npx packaging.\")",
28
+ "Bash(node packages/cli/bin/run.js commit -m \"Session: Day 24 RemoteStore wiring + npx packaging + Phase 1 gates \\(2026-03-11\\) #11\" -c \"Built: packages/cli/src/bootstrap.ts: checks config.store !== ''local'', creates RemoteStore\\(config.store\\) when URL configured. mcp/server.ts: same RemoteStore/LocalStore switch. scripts/build.sh: builds all 5 packages in dep order via pnpm --filter. Root package.json: bin contextgit -> packages/cli/bin/run.js for npx. Gate 2 PASS \\(ralph-loop CLI\\): 3 iterations contextgit context -f agents-md -> contextgit commit, all 4 sections present \\(Project State, Current Branch, Recent Activity, Open Threads\\). Gate 3 PASS \\(REST API\\): GET /snapshot returns Project State, POST /commits returns {id,message,createdAt} 201. All 32 tests pass. Decided: config.store && !== ''local'' guard \\(handles missing field and explicit local\\), root package.json bin entry for npx, scripts/build.sh uses pnpm --filter for explicit ordering, Gate 3 uses flat routes not versioned URLs. Unresolved: server.tool\\(\\) deprecated, loadConfig\\(\\) twice, npx not tested in clean temp dir, Gate 1 formal cold-start not re-run. Next: Days 25-26 npx clean-install validation, Gate 1 formal cold-start.\")",
29
+ "Bash(node packages/cli/bin/run.js commit -m \"Session: Phase 1 Complete \\(2026-03-11\\)\" -c \"Full Phase 1 complete. Gate 1 MCP PASS, Gate 2 ralph-loop CLI PASS, Gate 3 REST API PASS, npx clean-install PASS. Renamed contexthub -> contextgit, npm name claimed. Slipped to Phase 2: git hooks integration, semantic search e2e validation. Next: Plan Phase 2 — RemoteStore, multi-agent, team support.\")",
30
+ "Bash(node packages/cli/bin/run.js commit -m \"Session: 2026-03-11 Phase 2 Kickoff\" -c \"Planning session only — nothing built. Phase 2 plan written and reviewed. Three updates added: busy_timeout mitigation, atomic pull transaction, doctor check, localhost hosting note. CLAUDE.md updated to point at Phase 2 plan. Remote hosting deferred to Phase 3 \\(Railway/fly.io\\) — localhost sufficient for Phase 2 validation. Plan is locked and ready to build. Next: Start Week 5. Build packages/mcp/src/git-sync.ts \\(captureGitMetadata + installGitHooks\\). Wire gitCommitSha and gitBranch into engine.commit\\(\\) via MCP and CLI. Fix double loadConfig\\(\\) bug in mcp/src/server.ts. Add context_branch and context_merge MCP tools.\")",
31
+ "mcp__contextgit__context_get",
32
+ "mcp__contextgit__context_commit",
33
+ "Bash(pnpm --filter @contextgit/core build)",
34
+ "Bash(git reset:*)",
35
+ "Bash(node packages/cli/dist/commands/remote-show.js --help)",
36
+ "Bash(node packages/cli/bin/run.js serve --help)",
37
+ "Bash(node packages/cli/bin/run.js doctor --help)",
38
+ "Bash(node packages/cli/bin/run.js commit --help)"
39
+ ]
40
+ }
41
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "project": "contextgit",
3
+ "projectId": "contextgit-001",
4
+ "store": "local",
5
+ "agentRole": "solo",
6
+ "workflowType": "interactive",
7
+ "autoSnapshot": true,
8
+ "snapshotInterval": 10,
9
+ "embeddingModel": "local"
10
+ }
@@ -0,0 +1,4 @@
1
+ You have access to ContextGit memory tools. At the start of every session, call
2
+ context_get with scope=global to load project state. After completing significant
3
+ work, call context_commit with a message describing what was done and any open
4
+ threads. Use context_branch before exploring risky changes.
@@ -0,0 +1,40 @@
1
+ # contextgit-ci.yml — template for capturing CI context into ContextGit.
2
+ #
3
+ # Copy this into your project's .github/workflows/ directory and set the
4
+ # required secrets (see below). Commits are written with agentRole=ci so
5
+ # they can be filtered from agent snapshots using:
6
+ # context_get agent_role=ci (MCP)
7
+ # contextgit log --all (CLI)
8
+
9
+ name: ContextGit CI
10
+
11
+ on: [push, pull_request]
12
+
13
+ jobs:
14
+ capture-context:
15
+ runs-on: ubuntu-latest
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - uses: actions/setup-node@v4
20
+ with:
21
+ node-version: '20'
22
+
23
+ - name: Install contextgit
24
+ run: npm install -g contextgit
25
+
26
+ - name: Capture CI context
27
+ run: |
28
+ contextgit commit \
29
+ -m "CI run ${{ github.run_number }}: ${{ github.event.head_commit.message }}" \
30
+ --ci-run-id "${{ github.run_id }}" \
31
+ --pipeline "${{ github.workflow }}"
32
+ env:
33
+ ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
34
+ CONTEXTGIT_REMOTE: ${{ secrets.CONTEXTGIT_REMOTE_URL }}
35
+ CONTEXTGIT_API_KEY: ${{ secrets.CONTEXTGIT_API_KEY }}
36
+
37
+ # Required secrets:
38
+ # ANTHROPIC_API_KEY — for the rolling summarizer (Claude Haiku)
39
+ # CONTEXTGIT_REMOTE_URL — URL of your ContextGit API server (from: contextgit serve)
40
+ # CONTEXTGIT_API_KEY — API key (from: contextgit keygen --save)
package/CLAUDE.md ADDED
@@ -0,0 +1,123 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project
6
+ ContextGit is a persistent memory layer for AI agent workflows — solving the
7
+ "amnesia problem" where agents lose context between sessions.
8
+
9
+ ## Repository
10
+ GitHub: https://github.com/MendeTr/contextgit
11
+ Branch: main
12
+ Clone: git clone https://github.com/MendeTr/contextgit
13
+
14
+
15
+
16
+ ## Session Start (do this every time)
17
+ Call context_get with scope=global immediately.
18
+ Do not read decisions.md. Do not ask questions first.
19
+ Read the snapshot. Then start working.
20
+ Do not ask what to work on. Start the highest priority item from the snapshot.
21
+ If unclear, follow the Phase 2 plan: docs/ContextGit_PHASE2_PLAN.md
22
+
23
+
24
+ ## After EVERY completed task
25
+ git add .
26
+ git commit -m "feat/fix: <what was done>"
27
+ git push
28
+ context_commit "what was built | key decisions | next task"
29
+
30
+ Do not wait to be asked. Every completed task = immediate commit.
31
+ This applies to bug fixes, feature additions, and refactors alike.
32
+
33
+ ## Session End (do this every time)
34
+ Call context_commit with:
35
+ - what was built
36
+ - key decisions and why
37
+ - open threads
38
+ - the first concrete task for the next session
39
+ Then: git add . && git commit -m "..." && git push
40
+ ```
41
+
42
+ Then commit everything:
43
+ ```bash
44
+ git add .
45
+ git commit -m ": "
46
+ git push
47
+ ```
48
+
49
+ ## Commit Convention
50
+ - `feat:` new functionality
51
+ - `feat(package):` scoped to a package e.g. `feat(core):`
52
+ - `fix:` bug fix
53
+ - `chore:` config, tooling, deps
54
+ - `docs:` documentation only
55
+ - `test:` tests only
56
+
57
+ ## Commands
58
+ ```bash
59
+ pnpm install # install dependencies
60
+ pnpm build # build all packages
61
+ pnpm test # run all tests
62
+ pnpm test:watch # watch mode
63
+ pnpm typecheck # type check all packages
64
+
65
+ # Single package
66
+ cd packages/store && pnpm test
67
+ ```
68
+
69
+ Node.js >=20 and pnpm >=9 required.
70
+
71
+ ## Architecture
72
+
73
+ Strict dependency graph — no circular deps:
74
+ ```
75
+ core → @anthropic-ai/sdk, @xenova/transformers, nanoid
76
+ store → core (types only), better-sqlite3, sqlite-vec
77
+ mcp → core, store, @modelcontextprotocol/sdk, simple-git
78
+ cli → core, store, @oclif/core
79
+ api → core, store, express
80
+ ```
81
+
82
+ ### Packages
83
+ - **`@contextgit/core`** — types, engine, summarizer, snapshot formatter, embeddings
84
+ - **`@contextgit/store`** — ContextStore interface + LocalStore (SQLite)
85
+ - **`packages/mcp`** — MCP server (Week 3)
86
+ - **`packages/cli`** — oclif CLI (Week 3)
87
+ - **`packages/api`** — Express REST API (Week 4)
88
+
89
+ ### Storage layer (`packages/store/src/local/`)
90
+ | File | Role |
91
+ |------|------|
92
+ | `schema.ts` | DDL — tables, sqlite-vec, FTS5, indexes |
93
+ | `migrations.ts` | Versioned migration runner |
94
+ | `queries.ts` | All prepared statements + row→domain converters |
95
+ | `index.ts` | LocalStore implementing ContextStore |
96
+
97
+ ### Key Rules (never break these)
98
+ - TEXT primary keys via `nanoid()` — never auto-increment integers
99
+ - `better-sqlite3` sync API wrapped in `Promise.resolve()` at interface boundary
100
+ - Open threads **never** passed to summarizer — immune to compression guarantee
101
+ - Never fail a COMMIT due to summarizer — graceful fallback always
102
+ - DB path: `~/.contextgit/projects/<projectId>.db` — tests use `:memory:`
103
+ - sqlite-vec loaded via `createRequire` shim — load failure degrades gracefully
104
+
105
+ ### Domain Model
106
+ `Project → Branch → Commit` core hierarchy.
107
+ `Thread` tracks open questions scoped to a project.
108
+ `Agent` records active agents per project.
109
+ All types in `packages/core/src/types.ts`.
110
+
111
+ ## TypeScript
112
+ All packages extend `tsconfig.base.json`. Target: ES2022, module: NodeNext,
113
+ strict mode, declaration maps, source maps. Output: `./dist` per package.
114
+
115
+ ## Tests
116
+ Vitest, in-memory SQLite. Each test file closes DB in `afterEach`.
117
+ Root vitest config collects `packages/*/src/**/*.test.ts`.
118
+
119
+ ## Key Docs
120
+ - `docs/decisions.md` — session history (read this first)
121
+ - `docs/ContextGit_PHASE1_PLAN.md` — current build plan
122
+ - `docs/ContextGit_ARCHITECTURE_v3.md` — full architecture
123
+ - `docs/ContextGit_PRD_v4.md` — product requirements
package/CLAUDE.md.next ADDED
@@ -0,0 +1,65 @@
1
+ # CLAUDE.md — ContextGit Agent Instructions
2
+
3
+ ## Session Start (do this every time)
4
+ Call context_get with scope=global immediately.
5
+ Do not read decisions.md. Do not ask questions first.
6
+ Read the snapshot. Then start working.
7
+ Do not ask what to work on. Start the highest priority item from the snapshot.
8
+ If unclear, follow the phase plan: docs/ContextGit_PHASE2_PLAN.md
9
+ If phase plan is complete, check docs/ContextGit_DELTA.md for open deltas.
10
+
11
+ ## After EVERY completed task
12
+ git add .
13
+ git commit -m "feat/fix: <what was done>"
14
+ git push
15
+ context_commit "what was built | key decisions | next task"
16
+
17
+ Do not wait to be asked. Every completed task = immediate commit.
18
+ This applies to bug fixes, feature additions, and refactors alike.
19
+
20
+ ## When scope changes mid-session
21
+ 1. Write a context_commit with replan: prefix immediately:
22
+ `context_commit "replan: <what changed and why. what is new scope. what is no longer in scope>"`
23
+ 2. Then build the new scope
24
+ 3. Write a normal context_commit when done
25
+
26
+ Do not build first and replan after. Replan commit must come first.
27
+ Other agents are reading the snapshot in real time.
28
+
29
+ ## When starting a task
30
+ Before building anything, call:
31
+ contextgit claim "<task name>"
32
+
33
+ This prevents other agents from picking up the same task simultaneously.
34
+ Claims auto-release on your next commit. You do not need to manually unclaim.
35
+ If you abandon a task without committing, call: contextgit unclaim "<task name>"
36
+
37
+ ## Claim lifecycle
38
+ proposed → active → released
39
+
40
+ In plan mode: claim is written as proposed.
41
+ On user approval: claim flips to active.
42
+ On commit: claim is auto-released.
43
+ On crash or abandon: claim expires after 2 hours (TTL).
44
+
45
+ ## Session End (do this every time)
46
+ Call context_commit with:
47
+ - what was built
48
+ - key decisions and why
49
+ - open threads
50
+ - the first concrete task for the next session
51
+
52
+ Then: git add . && git commit -m "..." && git push
53
+
54
+ ## Commit message conventions
55
+ feat: new functionality
56
+ fix: bug fix
57
+ chore: config, tooling, deps
58
+ docs: documentation only
59
+ test: tests only
60
+ replan: scope change (use contextgit replan, not just a commit message)
61
+
62
+ ## Key files
63
+ docs/ContextGit_PHASE2_PLAN.md — current phase plan and status
64
+ docs/ContextGit_DELTA.md — scope changes discovered during development
65
+ docs/IDEAS.md — future vision, do not build yet