trellis 1.0.7 → 2.0.5

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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +533 -82
  3. package/bin/trellis.mjs +2 -0
  4. package/dist/cli/index.js +4718 -0
  5. package/dist/core/index.js +12 -0
  6. package/dist/decisions/index.js +19 -0
  7. package/dist/embeddings/index.js +43 -0
  8. package/dist/index-1j1anhmr.js +4038 -0
  9. package/dist/index-3s0eak0p.js +1556 -0
  10. package/dist/index-8pce39mh.js +272 -0
  11. package/dist/index-a76rekgs.js +67 -0
  12. package/dist/index-cy9k1g6v.js +684 -0
  13. package/dist/index-fd4e26s4.js +69 -0
  14. package/dist/{store/eav-store.js → index-gkvhzm9f.js} +4 -6
  15. package/dist/index-gnw8d7d6.js +51 -0
  16. package/dist/index-vkpkfwhq.js +817 -0
  17. package/dist/index.js +118 -2876
  18. package/dist/links/index.js +55 -0
  19. package/dist/transformers-m9je15kg.js +32491 -0
  20. package/dist/vcs/index.js +110 -0
  21. package/logo.png +0 -0
  22. package/logo.svg +9 -0
  23. package/package.json +79 -76
  24. package/src/cli/index.ts +2340 -0
  25. package/src/core/index.ts +35 -0
  26. package/src/core/kernel/middleware.ts +44 -0
  27. package/src/core/persist/backend.ts +64 -0
  28. package/src/core/store/eav-store.ts +467 -0
  29. package/src/decisions/auto-capture.ts +136 -0
  30. package/src/decisions/hooks.ts +163 -0
  31. package/src/decisions/index.ts +261 -0
  32. package/src/decisions/types.ts +103 -0
  33. package/src/embeddings/chunker.ts +327 -0
  34. package/src/embeddings/index.ts +41 -0
  35. package/src/embeddings/model.ts +95 -0
  36. package/src/embeddings/search.ts +305 -0
  37. package/src/embeddings/store.ts +313 -0
  38. package/src/embeddings/types.ts +85 -0
  39. package/src/engine.ts +1083 -0
  40. package/src/garden/cluster.ts +330 -0
  41. package/src/garden/garden.ts +306 -0
  42. package/src/garden/index.ts +29 -0
  43. package/src/git/git-exporter.ts +286 -0
  44. package/src/git/git-importer.ts +329 -0
  45. package/src/git/git-reader.ts +189 -0
  46. package/src/git/index.ts +22 -0
  47. package/src/identity/governance.ts +211 -0
  48. package/src/identity/identity.ts +224 -0
  49. package/src/identity/index.ts +30 -0
  50. package/src/identity/signing-middleware.ts +97 -0
  51. package/src/index.ts +20 -0
  52. package/src/links/index.ts +49 -0
  53. package/src/links/lifecycle.ts +400 -0
  54. package/src/links/parser.ts +484 -0
  55. package/src/links/ref-index.ts +186 -0
  56. package/src/links/resolver.ts +314 -0
  57. package/src/links/types.ts +108 -0
  58. package/src/mcp/index.ts +22 -0
  59. package/src/mcp/server.ts +1278 -0
  60. package/src/semantic/csharp-parser.ts +493 -0
  61. package/src/semantic/go-parser.ts +585 -0
  62. package/src/semantic/index.ts +34 -0
  63. package/src/semantic/java-parser.ts +456 -0
  64. package/src/semantic/python-parser.ts +659 -0
  65. package/src/semantic/ruby-parser.ts +446 -0
  66. package/src/semantic/rust-parser.ts +784 -0
  67. package/src/semantic/semantic-merge.ts +210 -0
  68. package/src/semantic/ts-parser.ts +681 -0
  69. package/src/semantic/types.ts +175 -0
  70. package/src/sync/index.ts +32 -0
  71. package/src/sync/memory-transport.ts +66 -0
  72. package/src/sync/reconciler.ts +237 -0
  73. package/src/sync/sync-engine.ts +258 -0
  74. package/src/sync/types.ts +104 -0
  75. package/src/vcs/blob-store.ts +124 -0
  76. package/src/vcs/branch.ts +150 -0
  77. package/src/vcs/checkpoint.ts +64 -0
  78. package/src/vcs/decompose.ts +469 -0
  79. package/src/vcs/diff.ts +409 -0
  80. package/src/vcs/engine-context.ts +26 -0
  81. package/src/vcs/index.ts +23 -0
  82. package/src/vcs/issue.ts +800 -0
  83. package/src/vcs/merge.ts +425 -0
  84. package/src/vcs/milestone.ts +124 -0
  85. package/src/vcs/ops.ts +59 -0
  86. package/src/vcs/types.ts +213 -0
  87. package/src/vcs/vcs-middleware.ts +81 -0
  88. package/src/watcher/fs-watcher.ts +217 -0
  89. package/src/watcher/index.ts +9 -0
  90. package/src/watcher/ingestion.ts +116 -0
  91. package/dist/ai/index.js +0 -688
  92. package/dist/cli/server.js +0 -3321
  93. package/dist/cli/tql.js +0 -5282
  94. package/dist/client/tql-client.js +0 -108
  95. package/dist/graph/index.js +0 -2248
  96. package/dist/kernel/logic-middleware.js +0 -179
  97. package/dist/kernel/middleware.js +0 -0
  98. package/dist/kernel/operations.js +0 -32
  99. package/dist/kernel/schema-middleware.js +0 -34
  100. package/dist/kernel/security-middleware.js +0 -53
  101. package/dist/kernel/trellis-kernel.js +0 -2239
  102. package/dist/kernel/workspace.js +0 -91
  103. package/dist/persist/backend.js +0 -0
  104. package/dist/persist/sqlite-backend.js +0 -123
  105. package/dist/query/index.js +0 -1643
  106. package/dist/server/index.js +0 -3309
  107. package/dist/workflows/index.js +0 -3160
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Trent Brew <tbrew@turtle.tech>
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.
package/README.md CHANGED
@@ -1,8 +1,33 @@
1
- # Trellis Kernel
1
+ <p align="center">
2
+ <img src="logo.png" alt="TrellisVCS" width="128" />
3
+ </p>
2
4
 
3
- Trellis is a **semantic operating system for knowledge work** that treats your workspace as a declarative configuration. This repository contains the core Trellis kernel: a high-performance, durable, and extensible semantic engine.
5
+ # TrellisVCS
4
6
 
5
- The kernel provides a unified interface for data ingestion, querying (EQL-S, Datalog, Natural Language), and automated reasoning, all backed by an append-only operation log for full reproducibility and sync.
7
+ > **Graph-native, code-first version control.**
8
+ > Every file save is an op. Every op is a node. History is a causal graph, not a linear diff.
9
+
10
+ TrellisVCS is a from-scratch VCS built on five pillars:
11
+
12
+ 1. **Causal Stream** — an immutable, content-addressed log of ops where every change is causally chained to its predecessor.
13
+ 2. **Semantic Patching** — changes are recorded as structured AST patches (`symbolRename`, `symbolModify`, …) rather than line diffs, enabling conflict-free merges.
14
+ 3. **Narrative Milestones** — you never "commit". Instead you carve checkpoints and milestones out of a continuous stream of work.
15
+ 4. **Governance Subgraph** — op signing, identity management, and policy rules enforced before ops enter the stream.
16
+ 5. **Idea Garden** — abandoned work clusters are automatically detected and surfaced for later revival.
17
+
18
+ ---
19
+
20
+ ## Table of Contents
21
+
22
+ - [Quick Start](#quick-start)
23
+ - [Architecture](#architecture)
24
+ - [CLI Reference](#cli-reference)
25
+ - [Module Guide](#module-guide)
26
+ - [How It Works](#how-it-works)
27
+ - [Design Doc](#design-doc)
28
+ - [Development](#development)
29
+
30
+ ---
6
31
 
7
32
  ## Quick Start
8
33
 
@@ -10,107 +35,533 @@ The kernel provides a unified interface for data ingestion, querying (EQL-S, Dat
10
35
  # Install dependencies
11
36
  bun install
12
37
 
13
- # Run the CLI on bundled sample data
14
- bun run tql -d data/posts.json -q "FIND post AS ?p RETURN ?p.id, ?p.title"
38
+ # Initialize a new TrellisVCS repo in the current directory
39
+ bun run src/cli/index.ts init
15
40
 
16
- # Run tests
17
- bun run test
18
- ```
41
+ # Watch for file changes (continuous op stream)
42
+ bun run src/cli/index.ts watch
43
+
44
+ # Check status
45
+ bun run src/cli/index.ts status
19
46
 
20
- ## Key Capabilities
47
+ # Import an existing Git repo
48
+ bun run src/cli/index.ts import --from /path/to/git-repo
49
+ ```
21
50
 
22
- - **Semantic Storage** – Durable EAV (Entity-Attribute-Value) store backed by SQLite with in-memory indexing for query performance.
23
- - **Event Sourcing** – Content-addressed operation log with causality tracking (hashing, agent metadata, linked chains).
24
- - **Multi-Modal Querying** –
25
- - **EQL-S**: A strict SQL-like DSL for entities and relationships.
26
- - **Datalog**: Direct access to the semi-naive evaluator for recursive and complex logic.
27
- - **Natural Language**: AI-powered translation of human intent into structured queries.
28
- - **Declarative Workspaces** – Boot entire environments from `.trellis` files containing ontologies (schemas), projections (views), and graph data.
29
- - **Middleware System** – Async-aware hooks for security (capability-based), schema enforcement, and logic (formulas, rollups).
30
- - **Time-Travel** – Query the state of your graph at any specific operation hash or historical timestamp.
51
+ ---
31
52
 
32
- ## Project Structure
53
+ ## Architecture
33
54
 
34
55
  ```
56
+ TrellisVCS/
35
57
  ├── src/
36
- │ ├── store/ # Core EAV engine, indexing, and catalog
37
- │ ├── persist/ # SQLite backend and operation log
38
- │ ├── query/ # EQL-S parser/compiler and Datalog engine
39
- │ ├── kernel/ # Kernel API, Middleware, and AI Interop
40
- │ ├── ai/ # NL providers and orchestrator
41
- │ ├── graph/ # Agent graph runtime (optional)
42
- └── workflows/ # Workflow engine (optional)
43
- ├── docs/ # Architectural guides and plan
44
- └── test/ # Comprehensive Vitest suites
58
+ │ ├── vcs/ # Core op types, constructors, decomposition
59
+ ├── types.ts # VcsOp, VcsOpKind (16 kinds), VcsPayload
60
+ ├── ops.ts # createVcsOp() SHA-256 content-addressed ops
61
+ ├── decompose.ts # VcsOp EAV graph facts
62
+ ├── branch.ts # Branch create/switch/list/delete
63
+ ├── milestone.ts # Milestone creation with op-range tracking
64
+ │ ├── checkpoint.ts # Auto/manual checkpoints
65
+ │ │ ├── diff.ts # File-level diff (file state at op)
66
+ │ │ ├── merge.ts # Three-way merge engine
67
+ │ │ ├── blob-store.ts # Content-addressed blob storage (SHA-256)
68
+ │ │ └── vcs-middleware.ts # Middleware plug for trellis-core kernel
69
+ │ │
70
+ │ ├── git/ # Git interop bridge
71
+ │ │ ├── git-reader.ts # Read commits, file changes, history
72
+ │ │ ├── git-importer.ts # Git → TrellisVCS (milestones + file ops)
73
+ │ │ └── git-exporter.ts # TrellisVCS milestones → Git commits
74
+ │ │
75
+ │ ├── identity/ # Cryptographic identity + governance
76
+ │ │ ├── identity.ts # Ed25519 keypair + DID generation
77
+ │ │ ├── signing-middleware.ts # Op signing middleware
78
+ │ │ └── governance.ts # Policy rules + enforcement
79
+ │ │
80
+ │ ├── garden/ # Idea Garden — abandoned work detection
81
+ │ │ ├── cluster.ts # IdeaCluster types + 3 detection heuristics
82
+ │ │ └── garden.ts # IdeaGarden query class (search, revive, stats)
83
+ │ │
84
+ │ ├── semantic/ # AST-level semantic patching
85
+ │ │ ├── types.ts # ParserAdapter, ASTEntity, SemanticPatch (11 kinds)
86
+ │ │ ├── ts-parser.ts # TypeScript/JS structural parser adapter
87
+ │ │ └── semantic-merge.ts # Patch commutativity + merge engine
88
+ │ │
89
+ │ ├── sync/ # Peer sync + CRDT reconciler
90
+ │ │ ├── types.ts # PeerId, SyncMessage, BranchPolicy
91
+ │ │ ├── reconciler.ts # Fork detection + op stream merging
92
+ │ │ ├── sync-engine.ts # Push/pull protocol, linear/CRDT modes
93
+ │ │ └── memory-transport.ts # In-memory transport for testing
94
+ │ │
95
+ │ ├── watcher/ # Filesystem monitoring
96
+ │ │ ├── fs-watcher.ts # Bun fs.watch wrapper with debounce + SHA-256
97
+ │ │ └── ingestion.ts # FileChangeEvent → VcsOp pipeline
98
+ │ │
99
+ │ ├── cli/
100
+ │ │ └── index.ts # 15+ CLI commands (Commander.js)
101
+ │ │
102
+ │ ├── engine.ts # Composition root — ties everything together
103
+ │ └── index.ts # Public API surface
104
+
105
+ ├── test/
106
+ │ ├── vcs/ # Op creation, decomposition
107
+ │ ├── git/ # Git reader, importer, exporter
108
+ │ ├── p2/ # Branches, milestones, checkpoints
109
+ │ ├── p3/ # Diff, merge
110
+ │ ├── p4/ # Identity, signing, governance
111
+ │ ├── p5/ # Idea Garden clusters
112
+ │ ├── p6/ # Semantic parser + merge
113
+ │ ├── p7/ # CRDT reconciler + sync engine
114
+ │ └── engine.test.ts # Integration tests
115
+
116
+ ├── trellis-core/ # Kernel dependency (source-linked)
117
+ ├── DESIGN.md # Full architecture specification
118
+ └── PILLARS.md # Design philosophy
45
119
  ```
46
120
 
47
- ## Usage
121
+ ### The Op Stream
48
122
 
49
- ### Programmatic Example
123
+ Every action in TrellisVCS is an immutable `VcsOp`:
50
124
 
51
125
  ```typescript
52
- import { TrellisKernel } from 'trellis/kernel';
53
- import { SqliteKernelBackend } from 'trellis/kernel/sqlite';
54
-
55
- // Initialize with persistence
56
- const backend = new SqliteKernelBackend({ filename: 'workspace.sqlite' });
57
- const kernel = new TrellisKernel({ backend });
58
-
59
- // Boot with data
60
- await kernel.boot(
61
- [
62
- { id: 1, title: 'Build Trellis', status: 'active' },
63
- { id: 2, title: 'Release Kernel', status: 'planning' },
64
- ],
65
- { entityType: 'Task' },
66
- );
67
-
68
- // Query with EQL-S
69
- const res = await kernel.query(
70
- 'FIND Task AS ?t WHERE ?t.status = "active" RETURN ?t.title',
71
- );
72
-
73
- console.log(res.rows); // [{ "?t.title": "Build Trellis" }]
74
- ```
75
-
76
- ### Declarative Workspace (.trellis)
77
-
78
- ```json
79
- {
80
- "workspace": {
81
- "name": "My Projects",
82
- "ontologies": {
83
- "trellis:schema/project": {
84
- /* schema def */
85
- }
86
- },
87
- "graph": {
88
- "nodes": [{ "@id": "p1", "@type": "Project", "name": "Web App" }]
89
- },
90
- "projections": {
91
- "active-view": { "name": "Active", "query": "FIND Project AS ?p ..." }
92
- }
93
- }
126
+ interface VcsOp {
127
+ hash: string; // trellis:op:<sha256> content-addressed
128
+ kind: VcsOpKind; // e.g. 'vcs:fileModify'
129
+ timestamp: string; // ISO 8601
130
+ agentId: string; // Author identity (DID)
131
+ previousHash?: string; // Causal chain link
132
+ vcs: VcsPayload; // Op-specific data (filePath, contentHash, …)
133
+ signature?: string; // Ed25519 signature (P4+)
94
134
  }
95
135
  ```
96
136
 
137
+ Ops are written to `.trellis/ops.json` and replayed into an in-memory EAV graph on startup. They are **never rewritten or deleted**.
138
+
139
+ ### Op Tiers
140
+
141
+ | Tier | Kinds | Description |
142
+ | :---- | :---------------------------------------------------------- | :-------------------------------- |
143
+ | **0** | `fileAdd`, `fileModify`, `fileDelete`, `fileRename` | File-level mutations from watcher |
144
+ | **1** | `dirAdd`, `dirDelete`, `branchCreate`, `milestoneCreate`, … | Structural VCS control ops |
145
+ | **2** | `symbolRename`, `symbolMove`, `symbolExtract` | AST-level semantic patches |
146
+
147
+ ---
148
+
149
+ ## CLI Reference
150
+
151
+ ### Repository Setup
152
+
153
+ ```bash
154
+ trellis init [--path <dir>] # Initialize a new repo
155
+ trellis import --from <git-repo> # Import Git history as milestones
156
+ trellis export --to <dir> # Export milestones to Git commits
157
+ ```
158
+
159
+ ### Working
160
+
161
+ ```bash
162
+ trellis status # Current branch, op count, pending changes
163
+ trellis log [--limit N] [--branch b] # Op stream history
164
+ trellis files [--deleted] # All tracked files
165
+ trellis watch # Start continuous file watching
166
+ ```
167
+
168
+ ### Branches
169
+
170
+ ```bash
171
+ trellis branch # List branches
172
+ trellis branch <name> # Create a branch
173
+ trellis branch -d <name> # Delete a branch
174
+ ```
175
+
176
+ ### Milestones & Checkpoints
177
+
178
+ ```bash
179
+ trellis milestone create -m "message" # Create milestone
180
+ trellis milestone create -m "msg" --from <hash> --to <hash> # Over a specific range
181
+ trellis milestone list # List milestones
182
+ trellis checkpoint create # Manual checkpoint
183
+ trellis checkpoint list # List checkpoints
184
+ ```
185
+
186
+ ### Diff & Merge
187
+
188
+ ```bash
189
+ trellis diff [--from <hash>] [--to <hash>] # File-level diff
190
+ trellis merge --branch <name> [--dry-run] # Three-way merge
191
+ trellis parse <file> # Semantic parse (declarations, imports)
192
+ trellis sdiff <fileA> <fileB> # Semantic diff between two versions
193
+ ```
194
+
195
+ ### Identity & Governance
196
+
197
+ ```bash
198
+ trellis identity [show|create|list] # Manage identities
199
+ trellis governance [list|add|remove] # Manage policy rules
200
+ ```
201
+
202
+ ### Idea Garden
203
+
204
+ ```bash
205
+ trellis garden # List abandoned clusters
206
+ trellis garden list [--status <s>] [--file <f>] # Filter clusters
207
+ trellis garden show <cluster-id> # Inspect a cluster
208
+ trellis garden search --keyword <term> # Search by keyword
209
+ trellis garden revive <cluster-id> # Revive cluster as branch
210
+ trellis garden stats # Garden statistics
211
+ ```
212
+
213
+ ### Sync
214
+
215
+ ```bash
216
+ trellis sync status # Local sync state
217
+ trellis sync reconcile --remote <path> # Reconcile with another local repo
218
+ ```
219
+
220
+ ---
221
+
222
+ ## Module Guide
223
+
224
+ ### `TrellisVcsEngine`
225
+
226
+ The main entry point. Ties together the kernel, file watcher, op log, branches, milestones, identity, garden, semantic parser, and sync.
227
+
228
+ ```typescript
229
+ import { TrellisVcsEngine } from 'trellisvcs';
230
+
231
+ const engine = new TrellisVcsEngine({ rootPath: '/my/project' });
232
+
233
+ // New repo
234
+ await engine.initRepo();
235
+
236
+ // Existing repo
237
+ engine.open();
238
+
239
+ // Core queries
240
+ engine.getOps(); // All ops
241
+ engine.status(); // Branch, op count, files
242
+ engine.log(); // Formatted op history
243
+ engine.getFiles(); // Currently tracked files
244
+
245
+ // Branches
246
+ await engine.createBranch('feature/x');
247
+ engine.switchBranch('feature/x');
248
+ engine.listBranches();
249
+ await engine.deleteBranch('feature/x');
250
+
251
+ // Milestones
252
+ await engine.createMilestone('Implement auth', { fromOpHash, toOpHash });
253
+ engine.listMilestones();
254
+
255
+ // Semantic parsing
256
+ engine.parseFile(content, 'src/auth.ts');
257
+ engine.semanticDiff(oldContent, newContent, 'src/auth.ts');
258
+
259
+ // Idea Garden
260
+ const garden = engine.garden();
261
+ garden.listClusters();
262
+ garden.search({ keyword: 'auth' });
263
+ garden.revive(clusterId);
264
+ ```
265
+
266
+ ### `src/garden/` — Idea Garden
267
+
268
+ Detects abandoned work using three heuristics, then exposes a query API.
269
+
97
270
  ```typescript
98
- await kernel.boot(trellisConfig);
99
- const view = await kernel.executeProjection('active-view');
271
+ import { detectClusters, IdeaGarden } from './src/garden/index.js';
272
+
273
+ const clusters = detectClusters(ops, milestonedHashes);
274
+ const garden = new IdeaGarden(ops, milestones);
275
+
276
+ garden.search({ file: 'auth.ts', status: 'abandoned', limit: 10 });
277
+ garden.stats(); // { total, abandoned, draft, revived, totalOps, totalFiles }
278
+ garden.revive('cluster:abc');
100
279
  ```
101
280
 
102
- ## Documentation
281
+ **Detection heuristics:**
282
+
283
+ | Heuristic | Trigger | Signal |
284
+ | :---------------------- | :------------------ | :---------------------------------------------------------------- |
285
+ | `contextSwitchDetector` | File-set pivot | Group of ops in unrelated dirs followed by a context switch away |
286
+ | `revertDetector` | Complementary ops | Ops undone by a subsequent inverse op (add→delete, modify→revert) |
287
+ | `staleBranchDetector` | Time + no milestone | Ops on non-`main` branches untouched >7 days without a milestone |
288
+
289
+ ### `src/semantic/` — Semantic Patching
290
+
291
+ Parses TypeScript/JavaScript into structural entities and computes semantic diffs.
292
+
293
+ ```typescript
294
+ import { typescriptParser, semanticMerge } from './src/semantic/index.js';
295
+
296
+ // Parse
297
+ const result = typescriptParser.parse(source, 'file.ts');
298
+ result.declarations; // ASTEntity[] — functions, classes, interfaces, enums, …
299
+ result.imports; // ImportRelation[]
300
+ result.exports; // ExportRelation[]
301
+
302
+ // Diff
303
+ const patches = typescriptParser.diff(oldResult, newResult);
304
+ // SemanticPatch[] — symbolAdd | symbolRemove | symbolModify |
305
+ // symbolRename | importAdd | importRemove | …
306
+
307
+ // Merge (patch commutativity per DESIGN.md §4.4)
308
+ const merged = semanticMerge(ourPatches, theirPatches, 'file.ts');
309
+ merged.clean; // true if no conflicts
310
+ merged.patches; // Merged patch list
311
+ merged.conflicts; // SemanticMergeConflict[] — entity-level, with suggestion
312
+ ```
313
+
314
+ ### `src/sync/` — Peer Sync
315
+
316
+ Implements the have→want→ops→ack protocol with linear and CRDT branch modes.
317
+
318
+ ```typescript
319
+ import { SyncEngine, MemoryTransport, reconcile } from './src/sync/index.js';
320
+
321
+ // Standalone CRDT reconciler
322
+ const result = reconcile(localOps, remoteOps);
323
+ result.merged; // Interleaved by timestamp
324
+ result.forkPoint; // Last common op hash
325
+ result.conflicts; // File-level conflicts
326
+
327
+ // Full sync engine
328
+ const transport = new MemoryTransport('peer-a', 'Alice');
329
+ const engine = new SyncEngine({
330
+ localPeerId: 'peer-a',
331
+ transport,
332
+ getLocalOps: () => ops,
333
+ onOpsReceived: (newOps) => {
334
+ /* integrate */
335
+ },
336
+ branchPolicy: { linear: false }, // CRDT mode
337
+ });
338
+
339
+ await engine.pushTo('peer-b');
340
+ await engine.pullFrom('peer-b');
341
+ engine.reconcileWith(remoteOps);
342
+ ```
343
+
344
+ ---
345
+
346
+ ## How It Works
103
347
 
104
- - [Kernel Alignment Plan](docs/KERNEL-ALIGNMENT-PLAN.md) – The roadmap followed for the current architecture.
105
- - [EAV Engine Guide](docs/EAV-README.md) – Deep dive into the storage layer.
106
- - [Workflows & Agent Graphs](docs/WORKFLOWS.md) – High-level automation.
348
+ ### Init Flow
349
+
350
+ ```
351
+ trellis init
352
+ → mkdirSync .trellis/
353
+ → write config.json (agentId, defaultBranch, ignorePatterns)
354
+ → create vcs:branchCreate op for "main"
355
+ → scan filesystem → create vcs:fileAdd op per file
356
+ → flush ops to .trellis/ops.json
357
+ ```
358
+
359
+ ### Watch Flow
360
+
361
+ ```
362
+ trellis watch
363
+ → FileWatcher.scan() populates known-files map
364
+ → FileWatcher.start() sets up Bun fs.watch
365
+ → on change → debounce → SHA-256 hash → emit FileChangeEvent
366
+ → Ingestion.process(event) → createVcsOp(kind, payload)
367
+ → engine.applyOp(op) → EAV store + op log
368
+ → auto-checkpoint if threshold crossed
369
+ ```
370
+
371
+ ### Milestone Flow
372
+
373
+ ```
374
+ trellis milestone create -m "Add auth"
375
+ → auto-detect fromOpHash (last milestone's toOpHash + 1)
376
+ → collect affected files from ops in range
377
+ → createVcsOp('vcs:milestoneCreate', { message, fromOpHash, toOpHash, affectedFiles })
378
+ → optional: trellis export → Git commit
379
+ ```
380
+
381
+ ### Semantic Diff Flow
382
+
383
+ ```
384
+ trellis sdiff old.ts new.ts
385
+ → typescriptParser.parse(old) → ParseResult { declarations, imports, exports }
386
+ → typescriptParser.parse(new) → ParseResult
387
+ → typescriptParser.diff(old, new) → SemanticPatch[]
388
+ - symbolAdd / symbolRemove / symbolModify
389
+ - symbolRename (detected via signature similarity)
390
+ - importAdd / importRemove / importModify
391
+ ```
392
+
393
+ ### Sync / Reconcile Flow
394
+
395
+ ```
396
+ Engine A sends 'have' { heads: { main: 'h42' }, opCount: 42 }
397
+ → Engine B compares to its own heads
398
+ → B sends 'want' { afterHash: 'h38' }
399
+ → A sends 'ops' [ op39, op40, op41, op42 ]
400
+ → B integrates new ops (linear: filter dupes; CRDT: reconcile())
401
+ → B sends 'ack' { integrated: ['h39', …] }
402
+ ```
403
+
404
+ ---
405
+
406
+ ## Design Doc
407
+
408
+ See [`DESIGN.md`](./DESIGN.md) for the full architecture specification, including:
409
+
410
+ - §3 — Causal stream and branch concurrency model
411
+ - §4 — Semantic patching: parser adapter interface, patch types, commutativity table
412
+ - §5 — Milestone narrative model
413
+ - §6 — Identity, signing, and governance
414
+ - §7 — Idea Garden cluster detection heuristics
415
+ - §10 — Open questions and architectural trade-offs
416
+
417
+ ---
107
418
 
108
419
  ## Development
109
420
 
421
+ ### Prerequisites
422
+
423
+ - [Bun](https://bun.sh) ≥ 1.0
424
+ - No other native dependencies
425
+
426
+ ### Install
427
+
428
+ ```bash
429
+ bun install
430
+ ```
431
+
432
+ ### Test
433
+
110
434
  ```bash
111
- bun run typecheck # Type checking
112
- bun run test # Run Vitest suites
113
- bun run clean # Clean build artifacts
435
+ bun test
436
+ # Run a specific phase:
437
+ bun test test/p6
438
+ bun test test/p7
439
+ ```
440
+
441
+ **266 tests across 21 files, all passing.**
442
+
443
+ ### Typecheck
444
+
445
+ ```bash
446
+ bun run typecheck
447
+ ```
448
+
449
+ ### Build
450
+
451
+ ```bash
452
+ # Build for npm (bun build → dist/)
453
+ bun run build
454
+
455
+ # Run CLI directly during development
456
+ bun run src/cli/index.ts <command>
114
457
  ```
115
458
 
116
- Built with [Bun](https://bun.sh) for fast TypeScript execution.
459
+ ---
460
+
461
+ ## npm Package
462
+
463
+ ### Install
464
+
465
+ ```bash
466
+ bun add trellis
467
+ ```
468
+
469
+ > **Requires [Bun](https://bun.sh) ≥ 1.0** — TrellisVCS uses `bun:sqlite` for the vector store and Bun's native TS support.
470
+
471
+ ### Subpath Exports
472
+
473
+ ```typescript
474
+ // Main entry — engine + core VCS types
475
+ import { TrellisVcsEngine } from 'trellis';
476
+
477
+ // Core — EAV store, kernel types
478
+ import { EAVStore } from 'trellis/core';
479
+ import type { Fact, Link } from 'trellis/core';
480
+
481
+ // VCS — ops, branches, milestones, issues, diff, merge
482
+ import type { VcsOp, VcsOpKind } from 'trellis/vcs';
483
+
484
+ // AI — semantic embeddings + vector search
485
+ import { EmbeddingManager, VectorStore } from 'trellis/ai';
486
+
487
+ // Links — wiki-link parser, resolver, ref index
488
+ import { parseFileRefs, resolveRef, RefIndex } from 'trellis/links';
489
+
490
+ // Decisions — decision trace recording + queries
491
+ import { recordDecision, queryDecisions } from 'trellis/decisions';
492
+ ```
493
+
494
+ ---
495
+
496
+ ## New Modules
497
+
498
+ ### `src/links/` — Wiki-Link References
499
+
500
+ Parse `[[wiki-links]]` from markdown, doc-comments, and source files. Resolve references to issues, files, symbols, milestones, and decisions. Build a bidirectional reference index.
501
+
502
+ ```typescript
503
+ import { parseFileRefs, resolveRef, RefIndex } from 'trellis/links';
504
+
505
+ // Parse wiki-links from a file
506
+ const refs = parseFileRefs('src/engine.ts', source);
507
+ // → [{ raw: '[[TRL-5]]', namespace: 'issue', target: 'TRL-5', ... }]
508
+
509
+ // Resolve a reference
510
+ const resolved = resolveRef(ref, context);
511
+ // → { state: 'resolved', title: 'Add Python parser', uri: '...' }
512
+
513
+ // Build bidirectional index
514
+ const index = new RefIndex();
515
+ index.indexFile('README.md', refs, context);
516
+ index.getIncoming('issue:TRL-5'); // All files that reference TRL-5
517
+ ```
518
+
519
+ ### `src/embeddings/` — Semantic Search
520
+
521
+ Embed issues, milestones, files, code entities, and decisions into a vector store for semantic search.
522
+
523
+ ```typescript
524
+ import { EmbeddingManager } from 'trellis/ai';
525
+
526
+ const manager = new EmbeddingManager(engine, { dbPath: 'embeddings.db' });
527
+ await manager.reindex(); // Index all content
528
+ const results = await manager.search('auth flow'); // Semantic search
529
+ // → [{ id: 'issue:TRL-5', content: '...', score: 0.87 }]
530
+ ```
531
+
532
+ ### `src/decisions/` — Decision Traces
533
+
534
+ Automatically capture tool invocations as auditable decision records. Enrich with rationale via pre/post hooks.
535
+
536
+ ```typescript
537
+ import { recordDecision, queryDecisions } from 'trellis/decisions';
538
+
539
+ // Record a decision
540
+ const dec = await recordDecision(ctx, {
541
+ toolName: 'trellis_issue_create',
542
+ input: { title: 'Add parser' },
543
+ output: { id: 'TRL-5' },
544
+ });
545
+
546
+ // Query decisions
547
+ const decs = queryDecisions(ctx, { tool: 'trellis_issue_*' });
548
+ ```
549
+
550
+ ---
551
+
552
+ ## Roadmap
553
+
554
+ | Phase | Deliverable | Status | Commit |
555
+ | :---- | :---------------------------------------------- | :----- | :-------- |
556
+ | P0 | Causal stream + CLI | ✅ | `51475d3` |
557
+ | P0.5 | VS Code extension / visual timeline | ✅ | `947d5a1` |
558
+ | P1 | Git import bridge | ✅ | `f4cc4a6` |
559
+ | P2 | Branches, milestones, checkpoints | ✅ | `3f91e9a` |
560
+ | P2.5 | Blob store, engine modularization, git exporter | ✅ | `5c43a31` |
561
+ | P3 | File-level diff + text-based merge | ✅ | `c953654` |
562
+ | P4 | Identity + op signing + governance | ✅ | `3acddda` |
563
+ | P5 | Idea Garden — cluster detection + query | ✅ | `105a207` |
564
+ | P6 | Semantic patching — parser adapter + diff/merge | ✅ | `22192ae` |
565
+ | P7 | Peer sync + CRDT reconciler | ✅ | `d02f3f7` |
566
+ | P8 | Wiki-links, embeddings, decision traces | ✅ | `b9cd5b7` |
567
+ | P9 | npm package + VSCode extension publish | 🚧 | |
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ import '../dist/cli/index.js';