trellis 3.1.35 → 3.2.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.
- package/CHANGELOG.md +23 -5
- package/README.md +63 -156
- package/bin/trellis.mjs +2 -75
- package/dist/{better-sqlite-backend-ahx5p0br.js → better-sqlite-backend-2P4F6AOJ.js} +91 -29
- package/dist/boot-middleware-MHLHFCUC.js +9 -0
- package/dist/browser/index.d.ts +18 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +95 -0
- package/dist/{index-53f3b8p8.js → chunk-2W3MHTMG.js} +552 -213
- package/dist/chunk-44FFQKQX.js +142 -0
- package/dist/chunk-4HYPLFJD.js +150 -0
- package/dist/chunk-4XIVMVHC.js +361 -0
- package/dist/{index-yp88he8n.js → chunk-6CTA6MCE.js} +88 -64
- package/dist/chunk-6GEZ6DN5.js +394 -0
- package/dist/chunk-7ZFRVCUE.js +211 -0
- package/dist/chunk-CAG4FULI.js +121 -0
- package/dist/chunk-FF36CQHZ.js +61 -0
- package/dist/{index-h32txmxe.js → chunk-FKQO5A3H.js} +6 -13
- package/dist/{index-nq520y6k.js → chunk-FWRS4CSC.js} +46 -32
- package/dist/chunk-GFZCJ4EH.js +108 -0
- package/dist/chunk-GLM4HGN4.js +55 -0
- package/dist/{index-4cdr7x2x.js → chunk-GU374KWZ.js} +182 -111
- package/dist/chunk-H6JB3PZ3.js +45 -0
- package/dist/chunk-IZX2PLIB.js +1240 -0
- package/dist/chunk-J2TXUFCZ.js +289 -0
- package/dist/chunk-J3WYZO3Q.js +211 -0
- package/dist/{index-xzym9w0m.js → chunk-JA7AIHRK.js} +12 -7
- package/dist/chunk-JHHEXEDM.js +162 -0
- package/dist/chunk-JUEMDWLU.js +233 -0
- package/dist/chunk-KFQGP6VL.js +33 -0
- package/dist/chunk-KIJITUZB.js +419 -0
- package/dist/{index-4wxa8xz4.js → chunk-KQ4A2D2P.js} +162 -23
- package/dist/chunk-KSU2GW22.js +958 -0
- package/dist/{index-rv1p47gp.js → chunk-L5N5PR2S.js} +3015 -2480
- package/dist/{index-h9e2efx4.js → chunk-LNUIGRDZ.js} +71 -55
- package/dist/{index-skhn0agf.js → chunk-MLC5BUYO.js} +19 -20
- package/dist/chunk-MPXUVGT3.js +104 -0
- package/dist/chunk-N6MYZT4O.js +68 -0
- package/dist/chunk-O2AV5WMN.js +48 -0
- package/dist/chunk-PZ4XYZ4J.js +143 -0
- package/dist/chunk-QB5ISE47.js +419 -0
- package/dist/chunk-RSWUFTO2.js +857 -0
- package/dist/chunk-S3XLFZ27.js +1095 -0
- package/dist/{index-w5wccer3.js → chunk-S6GBJ2ZB.js} +28 -12
- package/dist/{index-7pjz3tsy.js → chunk-SGMDTWJJ.js} +57 -15
- package/dist/chunk-SPSPV5BC.js +390 -0
- package/dist/chunk-TCKXSOBP.js +123 -0
- package/dist/chunk-UBGUDMUV.js +59 -0
- package/dist/{index-wt8rz4gn.js → chunk-UQISRW6T.js} +97 -26
- package/dist/chunk-USEINYUL.js +12 -0
- package/dist/{index-bmyt7k8n.js → chunk-UZRUP7QW.js} +12 -4
- package/dist/{index-xhcp6xrn.js → chunk-VBYUTRXX.js} +695 -514
- package/dist/{index-vkpkfwhq.js → chunk-VDAKEOML.js} +234 -194
- package/dist/chunk-WXSWA3MV.js +0 -0
- package/dist/{index-n9f2qyh5.js → chunk-X5FLTRUB.js} +55 -33
- package/dist/{index-h7zxhhhh.js → chunk-XMQ7G77X.js} +46 -38
- package/dist/{index-w7ng765c.js → chunk-YCM7ZYEZ.js} +102 -49
- package/dist/cli/deploy-cli.d.ts +18 -0
- package/dist/cli/deploy-cli.d.ts.map +1 -0
- package/dist/cli/errors.d.ts +6 -0
- package/dist/cli/errors.d.ts.map +1 -0
- package/dist/cli/examples.d.ts +23 -0
- package/dist/cli/examples.d.ts.map +1 -0
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +2426 -6225
- package/dist/client/index.browser.d.ts +29 -0
- package/dist/client/index.browser.d.ts.map +1 -0
- package/dist/client/index.browser.js +64 -0
- package/dist/client/index.d.ts +6 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +41 -21
- package/dist/client/live.d.ts +67 -0
- package/dist/client/live.d.ts.map +1 -0
- package/dist/client/reactive.d.ts +31 -0
- package/dist/client/reactive.d.ts.map +1 -0
- package/dist/client/sdk.browser.d.ts +104 -0
- package/dist/client/sdk.browser.d.ts.map +1 -0
- package/dist/client/sdk.browser.js +9 -0
- package/dist/client/sdk.d.ts +26 -2
- package/dist/client/sdk.d.ts.map +1 -1
- package/dist/client/sdk.js +9 -0
- package/dist/client/vcs-client.d.ts +129 -0
- package/dist/client/vcs-client.d.ts.map +1 -0
- package/dist/cms/index.js +171 -163
- package/dist/{config-8hczw0rs.js → config-PFTP67TR.js} +8 -9
- package/dist/core/computation/index.d.ts +5 -0
- package/dist/core/computation/index.d.ts.map +1 -0
- package/dist/core/computation/rollup.d.ts +18 -0
- package/dist/core/computation/rollup.d.ts.map +1 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +171 -104
- package/dist/core/kernel/boot-middleware.d.ts +10 -0
- package/dist/core/kernel/boot-middleware.d.ts.map +1 -0
- package/dist/core/kernel/logic-middleware.d.ts +7 -1
- package/dist/core/kernel/logic-middleware.d.ts.map +1 -1
- package/dist/core/kernel/trellis-kernel.d.ts.map +1 -1
- package/dist/core/ontology/types.d.ts +5 -0
- package/dist/core/ontology/types.d.ts.map +1 -1
- package/dist/core/persist/better-sqlite-backend.d.ts +9 -2
- package/dist/core/persist/better-sqlite-backend.d.ts.map +1 -1
- package/dist/core/persist/factory.d.ts +6 -7
- package/dist/core/persist/factory.d.ts.map +1 -1
- package/dist/core/persist/factory.js +2 -3
- package/dist/core/persist/sqljs-backend.js +2 -3
- package/dist/db/index.d.ts +4 -1
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +67 -54
- package/dist/db/inspector.js +11 -19
- package/dist/db/trellis.css +1 -1
- package/dist/decisions/index.js +9 -10
- package/dist/deploy-LQ7GUGJ5.js +9 -0
- package/dist/deploy-YNVG5E4E.js +9 -0
- package/dist/deploy-cli-24BCHAXY.js +67 -0
- package/dist/deploy-cli-C35HTITO.js +67 -0
- package/dist/embeddings/auto-embed.d.ts +2 -2
- package/dist/embeddings/auto-embed.d.ts.map +1 -1
- package/dist/embeddings/index.js +20 -22
- package/dist/embeddings/search.d.ts +2 -1
- package/dist/embeddings/search.d.ts.map +1 -1
- package/dist/embeddings/store.d.ts +25 -4
- package/dist/embeddings/store.d.ts.map +1 -1
- package/dist/engine.d.ts +59 -19
- package/dist/engine.d.ts.map +1 -1
- package/dist/import-UZEKXU3B.js +10 -0
- package/dist/index.js +102 -93
- package/dist/launch-explorer-HZ4ZJA4X.js +95 -0
- package/dist/links/index.js +24 -26
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/plugins/agent-memory/index.js +316 -0
- package/dist/plugins/idea-garden/index.js +165 -0
- package/dist/plugins/plan-approval/index.js +579 -0
- package/dist/plugins/proactive-watcher/index.js +194 -0
- package/dist/{index-2r4jxwnb.js → query-XYLTJYSA.js} +14 -15
- package/dist/react/index.js +39 -70
- package/dist/react/realtime.js +11 -0
- package/dist/react/schema-hooks.js +87 -0
- package/dist/realtime/broadcast-channel-transport.d.ts +43 -0
- package/dist/realtime/broadcast-channel-transport.d.ts.map +1 -0
- package/dist/realtime/durable-object-relay-transport.d.ts +96 -0
- package/dist/realtime/durable-object-relay-transport.d.ts.map +1 -0
- package/dist/realtime/index.d.ts +44 -0
- package/dist/realtime/index.d.ts.map +1 -0
- package/dist/realtime/index.js +40 -0
- package/dist/realtime/memory-hub.d.ts +32 -0
- package/dist/realtime/memory-hub.d.ts.map +1 -0
- package/dist/realtime/persistent-channel.d.ts +105 -0
- package/dist/realtime/persistent-channel.d.ts.map +1 -0
- package/dist/realtime/presence.d.ts +73 -0
- package/dist/realtime/presence.d.ts.map +1 -0
- package/dist/realtime/relay-persistence.d.ts +37 -0
- package/dist/realtime/relay-persistence.d.ts.map +1 -0
- package/dist/realtime/relay-persistence.js +107 -0
- package/dist/realtime/relay-server.d.ts +103 -0
- package/dist/realtime/relay-server.d.ts.map +1 -0
- package/dist/realtime/room.d.ts +98 -0
- package/dist/realtime/room.d.ts.map +1 -0
- package/dist/realtime/text.d.ts +73 -0
- package/dist/realtime/text.d.ts.map +1 -0
- package/dist/realtime/types.d.ts +89 -0
- package/dist/realtime/types.d.ts.map +1 -0
- package/dist/realtime/websocket-relay-transport.d.ts +28 -0
- package/dist/realtime/websocket-relay-transport.d.ts.map +1 -0
- package/dist/realtime.bundle.js +1100 -0
- package/dist/{remote-manager-xvbg4230.js → remote-manager-ODE3T2KR.js} +25 -15
- package/dist/scaffold/seed.d.ts.map +1 -1
- package/dist/scaffold/write.d.ts +1 -1
- package/dist/scaffold/write.d.ts.map +1 -1
- package/dist/schema/define.d.ts +137 -0
- package/dist/schema/define.d.ts.map +1 -0
- package/dist/schema/entity-projection.d.ts +34 -0
- package/dist/schema/entity-projection.d.ts.map +1 -0
- package/dist/schema/eql.d.ts +46 -0
- package/dist/schema/eql.d.ts.map +1 -0
- package/dist/schema/index.d.ts +21 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +46 -0
- package/dist/schema/kernel-resolve.d.ts +21 -0
- package/dist/schema/kernel-resolve.d.ts.map +1 -0
- package/dist/schema/mutations.d.ts +20 -0
- package/dist/schema/mutations.d.ts.map +1 -0
- package/dist/schema/resolve.d.ts +21 -0
- package/dist/schema/resolve.d.ts.map +1 -0
- package/dist/server/deploy-meta.d.ts +25 -0
- package/dist/server/deploy-meta.d.ts.map +1 -0
- package/dist/server/deploy.d.ts +7 -2
- package/dist/server/deploy.d.ts.map +1 -1
- package/dist/server/index.d.ts +7 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +100 -58
- package/dist/server/node-adapter.js +5 -104
- package/dist/server/realtime.d.ts +14 -3
- package/dist/server/realtime.d.ts.map +1 -1
- package/dist/server/server.d.ts +8 -16
- package/dist/server/server.d.ts.map +1 -1
- package/dist/server/sprites.d.ts +18 -1
- package/dist/server/sprites.d.ts.map +1 -1
- package/dist/server/tenancy.d.ts +4 -0
- package/dist/server/tenancy.d.ts.map +1 -1
- package/dist/server/usage-meter.d.ts +53 -0
- package/dist/server/usage-meter.d.ts.map +1 -0
- package/dist/server-MB3OPSPI.js +18 -0
- package/dist/server-ZVWGLLRF.js +18 -0
- package/dist/sprites-KQGTGM6W.js +27 -0
- package/dist/{sprites-vc4qbrp1.js → sprites-RU3E4XQN.js} +6 -7
- package/dist/svelte/index.d.ts +17 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +51 -0
- package/dist/svelte/schema-hooks.d.ts +45 -0
- package/dist/svelte/schema-hooks.d.ts.map +1 -0
- package/dist/svelte/schema-hooks.js +71 -0
- package/dist/svelte/stores.d.ts +78 -0
- package/dist/svelte/stores.d.ts.map +1 -0
- package/dist/sync/http-transport.d.ts +3 -3
- package/dist/sync/http-transport.d.ts.map +1 -1
- package/dist/sync/index.d.ts +15 -1
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +617 -0
- package/dist/sync/memory-room.d.ts +37 -0
- package/dist/sync/memory-room.d.ts.map +1 -0
- package/dist/sync/memory-transport.d.ts +3 -3
- package/dist/sync/memory-transport.d.ts.map +1 -1
- package/dist/sync/partykit-room.d.ts +40 -0
- package/dist/sync/partykit-room.d.ts.map +1 -0
- package/dist/sync/partykit-transport.d.ts +84 -0
- package/dist/sync/partykit-transport.d.ts.map +1 -0
- package/dist/sync/room-core.d.ts +53 -0
- package/dist/sync/room-core.d.ts.map +1 -0
- package/dist/sync/sync-engine.d.ts +40 -2
- package/dist/sync/sync-engine.d.ts.map +1 -1
- package/dist/sync/sync-room-server.d.ts +39 -0
- package/dist/sync/sync-room-server.d.ts.map +1 -0
- package/dist/sync/types.d.ts +70 -3
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/sync/vcs-sync-peer.d.ts +63 -0
- package/dist/sync/vcs-sync-peer.d.ts.map +1 -0
- package/dist/sync/ws-transport.d.ts +2 -2
- package/dist/sync/ws-transport.d.ts.map +1 -1
- package/dist/tenancy-NBLLGCNJ.js +14 -0
- package/dist/tenancy-POMWQP6M.js +16 -0
- package/dist/ui/client.html +355 -67
- package/dist/ui/launch-explorer.d.ts +22 -0
- package/dist/ui/launch-explorer.d.ts.map +1 -0
- package/dist/ui/server.d.ts +1 -1
- package/dist/ui/server.d.ts.map +1 -1
- package/dist/vcs/blob-store.d.ts.map +1 -1
- package/dist/vcs/idb-op-log.d.ts +67 -0
- package/dist/vcs/idb-op-log.d.ts.map +1 -0
- package/dist/vcs/index.d.ts +1 -0
- package/dist/vcs/index.d.ts.map +1 -1
- package/dist/vcs/index.js +81 -72
- package/dist/vcs/issue.d.ts +22 -5
- package/dist/vcs/issue.d.ts.map +1 -1
- package/dist/vcs/lane-materialize.d.ts +5 -0
- package/dist/vcs/lane-materialize.d.ts.map +1 -1
- package/dist/vcs/op-log.d.ts +28 -2
- package/dist/vcs/op-log.d.ts.map +1 -1
- package/dist/vcs/ops.d.ts +10 -0
- package/dist/vcs/ops.d.ts.map +1 -1
- package/dist/vcs/types.d.ts +2 -0
- package/dist/vcs/types.d.ts.map +1 -1
- package/dist/{vm-config-6xhsj6b3.js → vm-config-JI4OXKDQ.js} +9 -10
- package/dist/vue/hooks.d.ts +64 -0
- package/dist/vue/hooks.d.ts.map +1 -0
- package/dist/vue/index.d.ts +19 -0
- package/dist/vue/index.d.ts.map +1 -0
- package/dist/vue/index.js +59 -0
- package/dist/vue/schema-hooks.d.ts +41 -0
- package/dist/vue/schema-hooks.d.ts.map +1 -0
- package/dist/vue/schema-hooks.js +64 -0
- package/package.json +130 -17
- package/dist/deploy-999q207z.js +0 -10
- package/dist/engine-y0724kjq.js +0 -8
- package/dist/import-s2b8e0ft.js +0 -11
- package/dist/index-a76rekgs.js +0 -67
- package/dist/index-c9h37r6h.js +0 -1
- package/dist/index-hr9qvv77.js +0 -860
- package/dist/index-k5b0xskw.js +0 -1
- package/dist/index-nzb3am4f.js +0 -80
- package/dist/index-wncptktd.js +0 -292
- package/dist/index-y6a4kj0p.js +0 -43
- package/dist/index-yhwjgfvj.js +0 -342
- package/dist/sdk-bepky0xs.js +0 -16
- package/dist/server-szdjx0nt.js +0 -13
- package/dist/sqlite-backend-0vsmc6qj.js +0 -8
- package/dist/tenancy-pjm32b4v.js +0 -14
|
@@ -1,92 +1,131 @@
|
|
|
1
|
-
// @bun
|
|
2
1
|
import {
|
|
3
|
-
createVcsOp,
|
|
4
2
|
decisionEntityId,
|
|
5
|
-
init_ops,
|
|
6
3
|
init_types
|
|
7
|
-
} from "./
|
|
4
|
+
} from "./chunk-N6MYZT4O.js";
|
|
5
|
+
import {
|
|
6
|
+
createVcsOp,
|
|
7
|
+
init_ops
|
|
8
|
+
} from "./chunk-GLM4HGN4.js";
|
|
8
9
|
import {
|
|
9
10
|
__esm
|
|
10
|
-
} from "./
|
|
11
|
+
} from "./chunk-KFQGP6VL.js";
|
|
11
12
|
|
|
12
13
|
// src/decisions/hooks.ts
|
|
13
|
-
class HookRegistry {
|
|
14
|
-
preHooks = [];
|
|
15
|
-
postHooks = [];
|
|
16
|
-
registerPreHook(hook) {
|
|
17
|
-
this.preHooks.push(hook);
|
|
18
|
-
}
|
|
19
|
-
registerPostHook(hook) {
|
|
20
|
-
this.postHooks.push(hook);
|
|
21
|
-
}
|
|
22
|
-
removePreHook(name) {
|
|
23
|
-
this.preHooks = this.preHooks.filter((h) => h.name !== name);
|
|
24
|
-
}
|
|
25
|
-
removePostHook(name) {
|
|
26
|
-
this.postHooks = this.postHooks.filter((h) => h.name !== name);
|
|
27
|
-
}
|
|
28
|
-
getPreHooks(toolName) {
|
|
29
|
-
return this.preHooks.filter((h) => matchesPattern(h.toolPattern, toolName));
|
|
30
|
-
}
|
|
31
|
-
getPostHooks(toolName) {
|
|
32
|
-
return this.postHooks.filter((h) => matchesPattern(h.toolPattern, toolName));
|
|
33
|
-
}
|
|
34
|
-
async runPreHooks(toolName, input) {
|
|
35
|
-
const hooks = this.getPreHooks(toolName);
|
|
36
|
-
const merged = {};
|
|
37
|
-
for (const hook of hooks) {
|
|
38
|
-
try {
|
|
39
|
-
const ctx = await hook.handler(toolName, input);
|
|
40
|
-
Object.assign(merged, ctx);
|
|
41
|
-
if (ctx.custom) {
|
|
42
|
-
merged.custom = { ...merged.custom, ...ctx.custom };
|
|
43
|
-
}
|
|
44
|
-
} catch {}
|
|
45
|
-
}
|
|
46
|
-
return merged;
|
|
47
|
-
}
|
|
48
|
-
async runPostHooks(toolName, input, output, preContext) {
|
|
49
|
-
const hooks = this.getPostHooks(toolName);
|
|
50
|
-
const merged = {};
|
|
51
|
-
for (const hook of hooks) {
|
|
52
|
-
try {
|
|
53
|
-
const enrichment = await hook.handler(toolName, input, output, preContext);
|
|
54
|
-
if (enrichment.rationale)
|
|
55
|
-
merged.rationale = enrichment.rationale;
|
|
56
|
-
if (enrichment.alternatives)
|
|
57
|
-
merged.alternatives = enrichment.alternatives;
|
|
58
|
-
if (enrichment.confidence !== undefined)
|
|
59
|
-
merged.confidence = enrichment.confidence;
|
|
60
|
-
if (enrichment.relatedEntities) {
|
|
61
|
-
merged.relatedEntities = [
|
|
62
|
-
...merged.relatedEntities ?? [],
|
|
63
|
-
...enrichment.relatedEntities
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
if (enrichment.custom) {
|
|
67
|
-
merged.custom = { ...merged.custom, ...enrichment.custom };
|
|
68
|
-
}
|
|
69
|
-
} catch {}
|
|
70
|
-
}
|
|
71
|
-
return merged;
|
|
72
|
-
}
|
|
73
|
-
clear() {
|
|
74
|
-
this.preHooks = [];
|
|
75
|
-
this.postHooks = [];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
14
|
function matchesPattern(pattern, toolName) {
|
|
79
15
|
if (pattern instanceof RegExp) {
|
|
80
16
|
return pattern.test(toolName);
|
|
81
17
|
}
|
|
82
|
-
if (pattern === "*")
|
|
83
|
-
|
|
84
|
-
if (!pattern.includes("*"))
|
|
85
|
-
return pattern === toolName;
|
|
18
|
+
if (pattern === "*") return true;
|
|
19
|
+
if (!pattern.includes("*")) return pattern === toolName;
|
|
86
20
|
const escaped = pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*");
|
|
87
21
|
return new RegExp(`^${escaped}$`).test(toolName);
|
|
88
22
|
}
|
|
89
|
-
var
|
|
23
|
+
var HookRegistry;
|
|
24
|
+
var init_hooks = __esm({
|
|
25
|
+
"src/decisions/hooks.ts"() {
|
|
26
|
+
"use strict";
|
|
27
|
+
HookRegistry = class {
|
|
28
|
+
preHooks = [];
|
|
29
|
+
postHooks = [];
|
|
30
|
+
/**
|
|
31
|
+
* Register a pre-hook that runs before a tool handler.
|
|
32
|
+
*/
|
|
33
|
+
registerPreHook(hook) {
|
|
34
|
+
this.preHooks.push(hook);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Register a post-hook that runs after a tool handler.
|
|
38
|
+
*/
|
|
39
|
+
registerPostHook(hook) {
|
|
40
|
+
this.postHooks.push(hook);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Remove a pre-hook by name.
|
|
44
|
+
*/
|
|
45
|
+
removePreHook(name) {
|
|
46
|
+
this.preHooks = this.preHooks.filter((h) => h.name !== name);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Remove a post-hook by name.
|
|
50
|
+
*/
|
|
51
|
+
removePostHook(name) {
|
|
52
|
+
this.postHooks = this.postHooks.filter((h) => h.name !== name);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get all pre-hooks matching a tool name.
|
|
56
|
+
*/
|
|
57
|
+
getPreHooks(toolName) {
|
|
58
|
+
return this.preHooks.filter((h) => matchesPattern(h.toolPattern, toolName));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get all post-hooks matching a tool name.
|
|
62
|
+
*/
|
|
63
|
+
getPostHooks(toolName) {
|
|
64
|
+
return this.postHooks.filter(
|
|
65
|
+
(h) => matchesPattern(h.toolPattern, toolName)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Run all matching pre-hooks and merge their contexts.
|
|
70
|
+
*/
|
|
71
|
+
async runPreHooks(toolName, input) {
|
|
72
|
+
const hooks = this.getPreHooks(toolName);
|
|
73
|
+
const merged = {};
|
|
74
|
+
for (const hook of hooks) {
|
|
75
|
+
try {
|
|
76
|
+
const ctx = await hook.handler(toolName, input);
|
|
77
|
+
Object.assign(merged, ctx);
|
|
78
|
+
if (ctx.custom) {
|
|
79
|
+
merged.custom = { ...merged.custom, ...ctx.custom };
|
|
80
|
+
}
|
|
81
|
+
} catch {
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return merged;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Run all matching post-hooks and merge their enrichments.
|
|
88
|
+
*/
|
|
89
|
+
async runPostHooks(toolName, input, output, preContext) {
|
|
90
|
+
const hooks = this.getPostHooks(toolName);
|
|
91
|
+
const merged = {};
|
|
92
|
+
for (const hook of hooks) {
|
|
93
|
+
try {
|
|
94
|
+
const enrichment = await hook.handler(
|
|
95
|
+
toolName,
|
|
96
|
+
input,
|
|
97
|
+
output,
|
|
98
|
+
preContext
|
|
99
|
+
);
|
|
100
|
+
if (enrichment.rationale) merged.rationale = enrichment.rationale;
|
|
101
|
+
if (enrichment.alternatives)
|
|
102
|
+
merged.alternatives = enrichment.alternatives;
|
|
103
|
+
if (enrichment.confidence !== void 0)
|
|
104
|
+
merged.confidence = enrichment.confidence;
|
|
105
|
+
if (enrichment.relatedEntities) {
|
|
106
|
+
merged.relatedEntities = [
|
|
107
|
+
...merged.relatedEntities ?? [],
|
|
108
|
+
...enrichment.relatedEntities
|
|
109
|
+
];
|
|
110
|
+
}
|
|
111
|
+
if (enrichment.custom) {
|
|
112
|
+
merged.custom = { ...merged.custom, ...enrichment.custom };
|
|
113
|
+
}
|
|
114
|
+
} catch {
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return merged;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Clear all hooks.
|
|
121
|
+
*/
|
|
122
|
+
clear() {
|
|
123
|
+
this.preHooks = [];
|
|
124
|
+
this.postHooks = [];
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
});
|
|
90
129
|
|
|
91
130
|
// src/decisions/auto-capture.ts
|
|
92
131
|
function wrapToolHandler(toolName, handler, opts) {
|
|
@@ -94,9 +133,17 @@ function wrapToolHandler(toolName, handler, opts) {
|
|
|
94
133
|
if (opts.exclude?.has(toolName)) {
|
|
95
134
|
return handler(params);
|
|
96
135
|
}
|
|
97
|
-
const preContext = await opts.hooks.runPreHooks(
|
|
136
|
+
const preContext = await opts.hooks.runPreHooks(
|
|
137
|
+
toolName,
|
|
138
|
+
params
|
|
139
|
+
);
|
|
98
140
|
const result = await handler(params);
|
|
99
|
-
const enrichment = await opts.hooks.runPostHooks(
|
|
141
|
+
const enrichment = await opts.hooks.runPostHooks(
|
|
142
|
+
toolName,
|
|
143
|
+
params,
|
|
144
|
+
result,
|
|
145
|
+
preContext
|
|
146
|
+
);
|
|
100
147
|
const decision = {
|
|
101
148
|
toolName,
|
|
102
149
|
input: sanitizeInput(params),
|
|
@@ -112,15 +159,16 @@ function wrapToolHandler(toolName, handler, opts) {
|
|
|
112
159
|
agentModel: preContext.agentModel
|
|
113
160
|
}
|
|
114
161
|
};
|
|
115
|
-
opts.recorder(decision).catch(() => {
|
|
162
|
+
opts.recorder(decision).catch(() => {
|
|
163
|
+
});
|
|
116
164
|
return result;
|
|
117
165
|
};
|
|
118
166
|
}
|
|
119
167
|
function sanitizeInput(params) {
|
|
120
168
|
const sanitized = {};
|
|
121
169
|
for (const [key, value] of Object.entries(params)) {
|
|
122
|
-
if (typeof value === "string" && value.length >
|
|
123
|
-
sanitized[key] = value.slice(0,
|
|
170
|
+
if (typeof value === "string" && value.length > 2e3) {
|
|
171
|
+
sanitized[key] = value.slice(0, 2e3) + "\u2026";
|
|
124
172
|
} else {
|
|
125
173
|
sanitized[key] = value;
|
|
126
174
|
}
|
|
@@ -128,20 +176,22 @@ function sanitizeInput(params) {
|
|
|
128
176
|
return sanitized;
|
|
129
177
|
}
|
|
130
178
|
function summarize(result) {
|
|
131
|
-
if (result === null || result ===
|
|
132
|
-
return "";
|
|
179
|
+
if (result === null || result === void 0) return "";
|
|
133
180
|
if (typeof result === "object" && result !== null && "content" in result) {
|
|
134
181
|
const content = result.content;
|
|
135
182
|
if (Array.isArray(content)) {
|
|
136
|
-
const texts = content.filter((c) => c.type === "text").map((c) => c.text).join(
|
|
137
|
-
`);
|
|
183
|
+
const texts = content.filter((c) => c.type === "text").map((c) => c.text).join("\n");
|
|
138
184
|
return texts.length > 500 ? texts.slice(0, 500) + "\u2026" : texts;
|
|
139
185
|
}
|
|
140
186
|
}
|
|
141
187
|
const str = typeof result === "string" ? result : JSON.stringify(result, null, 0);
|
|
142
188
|
return str.length > 500 ? str.slice(0, 500) + "\u2026" : str;
|
|
143
189
|
}
|
|
144
|
-
var init_auto_capture = (
|
|
190
|
+
var init_auto_capture = __esm({
|
|
191
|
+
"src/decisions/auto-capture.ts"() {
|
|
192
|
+
"use strict";
|
|
193
|
+
}
|
|
194
|
+
});
|
|
145
195
|
|
|
146
196
|
// src/decisions/index.ts
|
|
147
197
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs";
|
|
@@ -155,12 +205,12 @@ function nextDecisionId(rootPath) {
|
|
|
155
205
|
if (existsSync(counterPath)) {
|
|
156
206
|
try {
|
|
157
207
|
counter = JSON.parse(readFileSync(counterPath, "utf-8")).counter ?? 0;
|
|
158
|
-
} catch {
|
|
208
|
+
} catch {
|
|
209
|
+
}
|
|
159
210
|
}
|
|
160
211
|
counter++;
|
|
161
212
|
const dir = dirname(counterPath);
|
|
162
|
-
if (!existsSync(dir))
|
|
163
|
-
mkdirSync(dir, { recursive: true });
|
|
213
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
164
214
|
writeFileSync(counterPath, JSON.stringify({ counter }, null, 2));
|
|
165
215
|
return `DEC-${counter}`;
|
|
166
216
|
}
|
|
@@ -172,11 +222,11 @@ async function recordDecision(ctx, rootPath, input) {
|
|
|
172
222
|
vcs: {
|
|
173
223
|
decisionId: id,
|
|
174
224
|
decisionToolName: input.toolName,
|
|
175
|
-
decisionToolInput: input.input ? JSON.stringify(input.input) :
|
|
225
|
+
decisionToolInput: input.input ? JSON.stringify(input.input) : void 0,
|
|
176
226
|
decisionToolOutput: input.outputSummary,
|
|
177
227
|
decisionContext: input.context,
|
|
178
228
|
decisionRationale: input.rationale,
|
|
179
|
-
decisionAlternatives: input.alternatives ? JSON.stringify(input.alternatives) :
|
|
229
|
+
decisionAlternatives: input.alternatives ? JSON.stringify(input.alternatives) : void 0
|
|
180
230
|
}
|
|
181
231
|
});
|
|
182
232
|
await ctx.applyOp(op);
|
|
@@ -197,7 +247,7 @@ function buildDecision(ctx, entityId) {
|
|
|
197
247
|
const facts = ctx.store.getFactsByEntity(entityId);
|
|
198
248
|
const get = (a) => {
|
|
199
249
|
const matches = facts.filter((f) => f.a === a);
|
|
200
|
-
return matches.length > 0 ? matches[matches.length - 1].v :
|
|
250
|
+
return matches.length > 0 ? matches[matches.length - 1].v : void 0;
|
|
201
251
|
};
|
|
202
252
|
const links = ctx.store.getLinksByAttribute("relatedTo");
|
|
203
253
|
const related = links.filter((l) => l.e1 === entityId).map((l) => l.e2);
|
|
@@ -212,7 +262,7 @@ function buildDecision(ctx, entityId) {
|
|
|
212
262
|
}
|
|
213
263
|
}
|
|
214
264
|
const confidenceRaw = get("confidence");
|
|
215
|
-
const confidence = confidenceRaw !==
|
|
265
|
+
const confidence = confidenceRaw !== void 0 ? parseFloat(confidenceRaw) : void 0;
|
|
216
266
|
return {
|
|
217
267
|
id: bareId,
|
|
218
268
|
toolName: get("toolName") ?? "",
|
|
@@ -231,26 +281,35 @@ function queryDecisions(ctx, filter) {
|
|
|
231
281
|
let decisions = decisionFacts.map((f) => buildDecision(ctx, f.e));
|
|
232
282
|
if (filter?.toolPattern) {
|
|
233
283
|
const pattern = filter.toolPattern;
|
|
234
|
-
const regex = pattern.includes("*") ? new RegExp(
|
|
235
|
-
|
|
284
|
+
const regex = pattern.includes("*") ? new RegExp(
|
|
285
|
+
`^${pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*/g, ".*")}$`
|
|
286
|
+
) : null;
|
|
287
|
+
decisions = decisions.filter(
|
|
288
|
+
(d) => regex ? regex.test(d.toolName) : d.toolName === pattern
|
|
289
|
+
);
|
|
236
290
|
}
|
|
237
291
|
if (filter?.agentId) {
|
|
238
292
|
decisions = decisions.filter((d) => d.createdBy === filter.agentId);
|
|
239
293
|
}
|
|
240
294
|
if (filter?.since) {
|
|
241
295
|
const since = new Date(filter.since).getTime();
|
|
242
|
-
decisions = decisions.filter(
|
|
296
|
+
decisions = decisions.filter(
|
|
297
|
+
(d) => d.createdAt && new Date(d.createdAt).getTime() >= since
|
|
298
|
+
);
|
|
243
299
|
}
|
|
244
300
|
if (filter?.until) {
|
|
245
301
|
const until = new Date(filter.until).getTime();
|
|
246
|
-
decisions = decisions.filter(
|
|
302
|
+
decisions = decisions.filter(
|
|
303
|
+
(d) => d.createdAt && new Date(d.createdAt).getTime() <= until
|
|
304
|
+
);
|
|
247
305
|
}
|
|
248
306
|
if (filter?.entityId) {
|
|
249
|
-
decisions = decisions.filter(
|
|
307
|
+
decisions = decisions.filter(
|
|
308
|
+
(d) => d.relatedEntities.includes(filter.entityId)
|
|
309
|
+
);
|
|
250
310
|
}
|
|
251
311
|
decisions.sort((a, b) => {
|
|
252
|
-
if (!a.createdAt || !b.createdAt)
|
|
253
|
-
return 0;
|
|
312
|
+
if (!a.createdAt || !b.createdAt) return 0;
|
|
254
313
|
return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
|
|
255
314
|
});
|
|
256
315
|
if (filter?.limit && filter.limit > 0) {
|
|
@@ -260,11 +319,14 @@ function queryDecisions(ctx, filter) {
|
|
|
260
319
|
}
|
|
261
320
|
function getDecisionChain(ctx, entityId) {
|
|
262
321
|
const allLinks = ctx.store.getLinksByAttribute("relatedTo");
|
|
263
|
-
const decisionEids = new Set(
|
|
264
|
-
|
|
322
|
+
const decisionEids = new Set(
|
|
323
|
+
allLinks.filter((l) => l.e2 === entityId).map((l) => l.e1).filter((e) => e.startsWith("decision:"))
|
|
324
|
+
);
|
|
325
|
+
const decisions = Array.from(decisionEids).map(
|
|
326
|
+
(eid) => buildDecision(ctx, eid)
|
|
327
|
+
);
|
|
265
328
|
decisions.sort((a, b) => {
|
|
266
|
-
if (!a.createdAt || !b.createdAt)
|
|
267
|
-
return 0;
|
|
329
|
+
if (!a.createdAt || !b.createdAt) return 0;
|
|
268
330
|
return new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime();
|
|
269
331
|
});
|
|
270
332
|
return decisions;
|
|
@@ -272,15 +334,24 @@ function getDecisionChain(ctx, entityId) {
|
|
|
272
334
|
function getDecision(ctx, id) {
|
|
273
335
|
const eid = decisionEntityId(id);
|
|
274
336
|
const typeFact = ctx.store.getFactsByEntity(eid).find((f) => f.a === "type" && f.v === "Decision");
|
|
275
|
-
if (!typeFact)
|
|
276
|
-
return null;
|
|
337
|
+
if (!typeFact) return null;
|
|
277
338
|
return buildDecision(ctx, eid);
|
|
278
339
|
}
|
|
279
|
-
var init_decisions = __esm(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
340
|
+
var init_decisions = __esm({
|
|
341
|
+
"src/decisions/index.ts"() {
|
|
342
|
+
init_hooks();
|
|
343
|
+
init_auto_capture();
|
|
344
|
+
init_ops();
|
|
345
|
+
init_types();
|
|
346
|
+
}
|
|
284
347
|
});
|
|
285
348
|
|
|
286
|
-
export {
|
|
349
|
+
export {
|
|
350
|
+
HookRegistry,
|
|
351
|
+
wrapToolHandler,
|
|
352
|
+
recordDecision,
|
|
353
|
+
queryDecisions,
|
|
354
|
+
getDecisionChain,
|
|
355
|
+
getDecision,
|
|
356
|
+
init_decisions
|
|
357
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TrellisDb
|
|
3
|
+
} from "./chunk-J2TXUFCZ.js";
|
|
4
|
+
|
|
5
|
+
// src/react/provider.tsx
|
|
6
|
+
import React, {
|
|
7
|
+
createContext,
|
|
8
|
+
useContext,
|
|
9
|
+
useMemo,
|
|
10
|
+
useEffect
|
|
11
|
+
} from "react";
|
|
12
|
+
var TrellisContext = createContext(null);
|
|
13
|
+
function TrellisProvider({
|
|
14
|
+
url,
|
|
15
|
+
apiKey,
|
|
16
|
+
tenantId,
|
|
17
|
+
children
|
|
18
|
+
}) {
|
|
19
|
+
const client = useMemo(() => {
|
|
20
|
+
const opts = { url };
|
|
21
|
+
if (apiKey) opts.apiKey = apiKey;
|
|
22
|
+
if (tenantId) opts.tenantId = tenantId;
|
|
23
|
+
return new TrellisDb(opts);
|
|
24
|
+
}, [url, apiKey, tenantId]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
return () => {
|
|
27
|
+
client.disconnect();
|
|
28
|
+
};
|
|
29
|
+
}, [client]);
|
|
30
|
+
return /* @__PURE__ */ React.createElement(TrellisContext.Provider, { value: client }, children);
|
|
31
|
+
}
|
|
32
|
+
function useTrellis() {
|
|
33
|
+
const client = useContext(TrellisContext);
|
|
34
|
+
if (!client) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
'useTrellis() must be used within a <TrellisProvider>. Wrap your app with <TrellisProvider url="...">.'
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return client;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
TrellisProvider,
|
|
44
|
+
useTrellis
|
|
45
|
+
};
|