trellis 1.0.8 → 2.0.6

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 +564 -83
  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
@@ -0,0 +1,272 @@
1
+ // @bun
2
+ import {
3
+ createVcsOp,
4
+ decisionEntityId
5
+ } from "./index-fd4e26s4.js";
6
+
7
+ // src/decisions/hooks.ts
8
+ class HookRegistry {
9
+ preHooks = [];
10
+ postHooks = [];
11
+ registerPreHook(hook) {
12
+ this.preHooks.push(hook);
13
+ }
14
+ registerPostHook(hook) {
15
+ this.postHooks.push(hook);
16
+ }
17
+ removePreHook(name) {
18
+ this.preHooks = this.preHooks.filter((h) => h.name !== name);
19
+ }
20
+ removePostHook(name) {
21
+ this.postHooks = this.postHooks.filter((h) => h.name !== name);
22
+ }
23
+ getPreHooks(toolName) {
24
+ return this.preHooks.filter((h) => matchesPattern(h.toolPattern, toolName));
25
+ }
26
+ getPostHooks(toolName) {
27
+ return this.postHooks.filter((h) => matchesPattern(h.toolPattern, toolName));
28
+ }
29
+ async runPreHooks(toolName, input) {
30
+ const hooks = this.getPreHooks(toolName);
31
+ const merged = {};
32
+ for (const hook of hooks) {
33
+ try {
34
+ const ctx = await hook.handler(toolName, input);
35
+ Object.assign(merged, ctx);
36
+ if (ctx.custom) {
37
+ merged.custom = { ...merged.custom, ...ctx.custom };
38
+ }
39
+ } catch {}
40
+ }
41
+ return merged;
42
+ }
43
+ async runPostHooks(toolName, input, output, preContext) {
44
+ const hooks = this.getPostHooks(toolName);
45
+ const merged = {};
46
+ for (const hook of hooks) {
47
+ try {
48
+ const enrichment = await hook.handler(toolName, input, output, preContext);
49
+ if (enrichment.rationale)
50
+ merged.rationale = enrichment.rationale;
51
+ if (enrichment.alternatives)
52
+ merged.alternatives = enrichment.alternatives;
53
+ if (enrichment.confidence !== undefined)
54
+ merged.confidence = enrichment.confidence;
55
+ if (enrichment.relatedEntities) {
56
+ merged.relatedEntities = [
57
+ ...merged.relatedEntities ?? [],
58
+ ...enrichment.relatedEntities
59
+ ];
60
+ }
61
+ if (enrichment.custom) {
62
+ merged.custom = { ...merged.custom, ...enrichment.custom };
63
+ }
64
+ } catch {}
65
+ }
66
+ return merged;
67
+ }
68
+ clear() {
69
+ this.preHooks = [];
70
+ this.postHooks = [];
71
+ }
72
+ }
73
+ function matchesPattern(pattern, toolName) {
74
+ if (pattern instanceof RegExp) {
75
+ return pattern.test(toolName);
76
+ }
77
+ if (pattern === "*")
78
+ return true;
79
+ if (!pattern.includes("*"))
80
+ return pattern === toolName;
81
+ const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
82
+ return new RegExp(`^${escaped}$`).test(toolName);
83
+ }
84
+ // src/decisions/auto-capture.ts
85
+ function wrapToolHandler(toolName, handler, opts) {
86
+ return async (params) => {
87
+ if (opts.exclude?.has(toolName)) {
88
+ return handler(params);
89
+ }
90
+ const preContext = await opts.hooks.runPreHooks(toolName, params);
91
+ const result = await handler(params);
92
+ const enrichment = await opts.hooks.runPostHooks(toolName, params, result, preContext);
93
+ const decision = {
94
+ toolName,
95
+ input: sanitizeInput(params),
96
+ outputSummary: summarize(result),
97
+ context: preContext.prompt ?? preContext.conversationId,
98
+ rationale: enrichment.rationale,
99
+ alternatives: enrichment.alternatives,
100
+ confidence: enrichment.confidence,
101
+ relatedEntities: enrichment.relatedEntities,
102
+ custom: {
103
+ ...preContext.custom,
104
+ ...enrichment.custom,
105
+ agentModel: preContext.agentModel
106
+ }
107
+ };
108
+ opts.recorder(decision).catch(() => {});
109
+ return result;
110
+ };
111
+ }
112
+ function sanitizeInput(params) {
113
+ const sanitized = {};
114
+ for (const [key, value] of Object.entries(params)) {
115
+ if (typeof value === "string" && value.length > 2000) {
116
+ sanitized[key] = value.slice(0, 2000) + "\u2026";
117
+ } else {
118
+ sanitized[key] = value;
119
+ }
120
+ }
121
+ return sanitized;
122
+ }
123
+ function summarize(result) {
124
+ if (result === null || result === undefined)
125
+ return "";
126
+ if (typeof result === "object" && result !== null && "content" in result) {
127
+ const content = result.content;
128
+ if (Array.isArray(content)) {
129
+ const texts = content.filter((c) => c.type === "text").map((c) => c.text).join(`
130
+ `);
131
+ return texts.length > 500 ? texts.slice(0, 500) + "\u2026" : texts;
132
+ }
133
+ }
134
+ const str = typeof result === "string" ? result : JSON.stringify(result, null, 0);
135
+ return str.length > 500 ? str.slice(0, 500) + "\u2026" : str;
136
+ }
137
+
138
+ // src/decisions/index.ts
139
+ import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
140
+ import { join, dirname } from "path";
141
+ function getDecisionCounterPath(rootPath) {
142
+ return join(rootPath, ".trellis", "decision-counter.json");
143
+ }
144
+ function nextDecisionId(rootPath) {
145
+ const counterPath = getDecisionCounterPath(rootPath);
146
+ let counter = 0;
147
+ if (existsSync(counterPath)) {
148
+ try {
149
+ counter = JSON.parse(readFileSync(counterPath, "utf-8")).counter ?? 0;
150
+ } catch {}
151
+ }
152
+ counter++;
153
+ const dir = dirname(counterPath);
154
+ if (!existsSync(dir))
155
+ mkdirSync(dir, { recursive: true });
156
+ writeFileSync(counterPath, JSON.stringify({ counter }, null, 2));
157
+ return `DEC-${counter}`;
158
+ }
159
+ async function recordDecision(ctx, rootPath, input) {
160
+ const id = nextDecisionId(rootPath);
161
+ const op = await createVcsOp("vcs:decisionRecord", {
162
+ agentId: ctx.agentId,
163
+ previousHash: ctx.getLastOp()?.hash,
164
+ vcs: {
165
+ decisionId: id,
166
+ decisionToolName: input.toolName,
167
+ decisionToolInput: input.input ? JSON.stringify(input.input) : undefined,
168
+ decisionToolOutput: input.outputSummary,
169
+ decisionContext: input.context,
170
+ decisionRationale: input.rationale,
171
+ decisionAlternatives: input.alternatives ? JSON.stringify(input.alternatives) : undefined
172
+ }
173
+ });
174
+ ctx.applyOp(op);
175
+ if (input.relatedEntities) {
176
+ const eid = decisionEntityId(id);
177
+ const links = input.relatedEntities.map((target) => ({
178
+ e1: eid,
179
+ a: "relatedTo",
180
+ e2: target
181
+ }));
182
+ if (links.length > 0) {
183
+ ctx.store.addLinks(links);
184
+ }
185
+ }
186
+ return op;
187
+ }
188
+ function buildDecision(ctx, entityId) {
189
+ const facts = ctx.store.getFactsByEntity(entityId);
190
+ const get = (a) => {
191
+ const matches = facts.filter((f) => f.a === a);
192
+ return matches.length > 0 ? matches[matches.length - 1].v : undefined;
193
+ };
194
+ const links = ctx.store.getLinksByAttribute("relatedTo");
195
+ const related = links.filter((l) => l.e1 === entityId).map((l) => l.e2);
196
+ const bareId = entityId.replace(/^decision:/, "");
197
+ const alternativesRaw = get("alternatives");
198
+ let alternatives;
199
+ if (alternativesRaw) {
200
+ try {
201
+ alternatives = JSON.parse(alternativesRaw);
202
+ } catch {
203
+ alternatives = [alternativesRaw];
204
+ }
205
+ }
206
+ const confidenceRaw = get("confidence");
207
+ const confidence = confidenceRaw !== undefined ? parseFloat(confidenceRaw) : undefined;
208
+ return {
209
+ id: bareId,
210
+ toolName: get("toolName") ?? "",
211
+ outputSummary: get("outputSummary"),
212
+ context: get("context"),
213
+ rationale: get("rationale"),
214
+ alternatives,
215
+ confidence,
216
+ createdAt: get("createdAt"),
217
+ createdBy: get("createdBy"),
218
+ relatedEntities: related
219
+ };
220
+ }
221
+ function queryDecisions(ctx, filter) {
222
+ const decisionFacts = ctx.store.getFactsByAttribute("type").filter((f) => f.v === "Decision");
223
+ let decisions = decisionFacts.map((f) => buildDecision(ctx, f.e));
224
+ if (filter?.toolPattern) {
225
+ const pattern = filter.toolPattern;
226
+ const regex = pattern.includes("*") ? new RegExp(`^${pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`) : null;
227
+ decisions = decisions.filter((d) => regex ? regex.test(d.toolName) : d.toolName === pattern);
228
+ }
229
+ if (filter?.agentId) {
230
+ decisions = decisions.filter((d) => d.createdBy === filter.agentId);
231
+ }
232
+ if (filter?.since) {
233
+ const since = new Date(filter.since).getTime();
234
+ decisions = decisions.filter((d) => d.createdAt && new Date(d.createdAt).getTime() >= since);
235
+ }
236
+ if (filter?.until) {
237
+ const until = new Date(filter.until).getTime();
238
+ decisions = decisions.filter((d) => d.createdAt && new Date(d.createdAt).getTime() <= until);
239
+ }
240
+ if (filter?.entityId) {
241
+ decisions = decisions.filter((d) => d.relatedEntities.includes(filter.entityId));
242
+ }
243
+ decisions.sort((a, b) => {
244
+ if (!a.createdAt || !b.createdAt)
245
+ return 0;
246
+ return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
247
+ });
248
+ if (filter?.limit && filter.limit > 0) {
249
+ decisions = decisions.slice(0, filter.limit);
250
+ }
251
+ return decisions;
252
+ }
253
+ function getDecisionChain(ctx, entityId) {
254
+ const allLinks = ctx.store.getLinksByAttribute("relatedTo");
255
+ const decisionEids = new Set(allLinks.filter((l) => l.e2 === entityId).map((l) => l.e1).filter((e) => e.startsWith("decision:")));
256
+ const decisions = Array.from(decisionEids).map((eid) => buildDecision(ctx, eid));
257
+ decisions.sort((a, b) => {
258
+ if (!a.createdAt || !b.createdAt)
259
+ return 0;
260
+ return new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
261
+ });
262
+ return decisions;
263
+ }
264
+ function getDecision(ctx, id) {
265
+ const eid = decisionEntityId(id);
266
+ const typeFact = ctx.store.getFactsByEntity(eid).find((f) => f.a === "type" && f.v === "Decision");
267
+ if (!typeFact)
268
+ return null;
269
+ return buildDecision(ctx, eid);
270
+ }
271
+
272
+ export { HookRegistry, wrapToolHandler, recordDecision, queryDecisions, getDecisionChain, getDecision };
@@ -0,0 +1,67 @@
1
+ // @bun
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ function __accessProp(key) {
9
+ return this[key];
10
+ }
11
+ var __toESMCache_node;
12
+ var __toESMCache_esm;
13
+ var __toESM = (mod, isNodeMode, target) => {
14
+ var canCache = mod != null && typeof mod === "object";
15
+ if (canCache) {
16
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
17
+ var cached = cache.get(mod);
18
+ if (cached)
19
+ return cached;
20
+ }
21
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
22
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
23
+ for (let key of __getOwnPropNames(mod))
24
+ if (!__hasOwnProp.call(to, key))
25
+ __defProp(to, key, {
26
+ get: __accessProp.bind(mod, key),
27
+ enumerable: true
28
+ });
29
+ if (canCache)
30
+ cache.set(mod, to);
31
+ return to;
32
+ };
33
+ var __toCommonJS = (from) => {
34
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
35
+ if (entry)
36
+ return entry;
37
+ entry = __defProp({}, "__esModule", { value: true });
38
+ if (from && typeof from === "object" || typeof from === "function") {
39
+ for (var key of __getOwnPropNames(from))
40
+ if (!__hasOwnProp.call(entry, key))
41
+ __defProp(entry, key, {
42
+ get: __accessProp.bind(from, key),
43
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
44
+ });
45
+ }
46
+ __moduleCache.set(from, entry);
47
+ return entry;
48
+ };
49
+ var __moduleCache;
50
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
51
+ var __returnValue = (v) => v;
52
+ function __exportSetter(name, newValue) {
53
+ this[name] = __returnValue.bind(null, newValue);
54
+ }
55
+ var __export = (target, all) => {
56
+ for (var name in all)
57
+ __defProp(target, name, {
58
+ get: all[name],
59
+ enumerable: true,
60
+ configurable: true,
61
+ set: __exportSetter.bind(all, name)
62
+ });
63
+ };
64
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
65
+ var __require = import.meta.require;
66
+
67
+ export { __toESM, __toCommonJS, __commonJS, __export, __esm, __require };