@vellumai/assistant 0.11.3-dev.202608140033.273a3d8 → 0.11.3-dev.202608140136.76df6b7
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/package.json +1 -1
- package/src/__tests__/app-compiler.test.ts +38 -3
- package/src/__tests__/mtime-cache.test.ts +1 -1
- package/src/__tests__/plugin-secret-pattern-contribution.test.ts +1 -1
- package/src/__tests__/user-plugin-loader.test.ts +1 -1
- package/src/bundler/package-resolver.ts +2 -30
- package/src/hooks/hook-loader.ts +3 -3
- package/src/hooks/registry.ts +50 -6
- package/src/plugins/mtime-cache.ts +11 -49
- package/src/tools/registry.ts +2 -1
package/package.json
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
packageName,
|
|
21
21
|
resolvePackage,
|
|
22
22
|
} from "../bundler/package-resolver.js";
|
|
23
|
+
import { ensureBun } from "../util/bun-runtime.js";
|
|
23
24
|
|
|
24
25
|
// ---------------------------------------------------------------------------
|
|
25
26
|
// Shared temp directory
|
|
@@ -56,6 +57,29 @@ async function scaffold(
|
|
|
56
57
|
return appDir;
|
|
57
58
|
}
|
|
58
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Download `pkg` into bun's global module cache via a throwaway install.
|
|
62
|
+
*
|
|
63
|
+
* `resolvePackage` bounds its own install at INSTALL_TIMEOUT_MS (10s), which a
|
|
64
|
+
* cold global cache can exceed for a large package on a slow network. Priming
|
|
65
|
+
* first is unbounded, so the install the test measures resolves from cache and
|
|
66
|
+
* stays well inside that bound.
|
|
67
|
+
*/
|
|
68
|
+
async function primeBunCache(pkg: string): Promise<void> {
|
|
69
|
+
const primeDir = join(tempDir, `prime-${pkg.replaceAll(/[^a-z0-9]/gi, "-")}`);
|
|
70
|
+
await mkdir(primeDir, { recursive: true });
|
|
71
|
+
await writeFile(
|
|
72
|
+
join(primeDir, "package.json"),
|
|
73
|
+
JSON.stringify({ name: "prime-cache", private: true }),
|
|
74
|
+
);
|
|
75
|
+
const proc = Bun.spawn([await ensureBun(), "install", "--no-save", pkg], {
|
|
76
|
+
cwd: primeDir,
|
|
77
|
+
stdout: "ignore",
|
|
78
|
+
stderr: "ignore",
|
|
79
|
+
});
|
|
80
|
+
await proc.exited;
|
|
81
|
+
}
|
|
82
|
+
|
|
59
83
|
const MINIMAL_HTML = `<!DOCTYPE html>
|
|
60
84
|
<html>
|
|
61
85
|
<head><title>Test</title></head>
|
|
@@ -466,10 +490,21 @@ describe("package-resolver", () => {
|
|
|
466
490
|
expect(ALLOWED_PACKAGES).toContain("clsx");
|
|
467
491
|
});
|
|
468
492
|
|
|
469
|
-
// `lucide` (the vanilla package)
|
|
470
|
-
//
|
|
471
|
-
// exports icon data arrays, not Preact components. Apps use inline SVG.
|
|
493
|
+
// `lucide` (the vanilla package) exports icon data arrays, not Preact
|
|
494
|
+
// components, and unpacks to ~29 MB for no benefit. Apps use inline SVG.
|
|
472
495
|
test("ALLOWED_PACKAGES excludes lucide", () => {
|
|
473
496
|
expect(ALLOWED_PACKAGES).not.toContain("lucide");
|
|
474
497
|
});
|
|
498
|
+
|
|
499
|
+
// `chart.js` is a large allowlisted package: it must install into the shared
|
|
500
|
+
// cache and resolve so apps importing it can compile.
|
|
501
|
+
test("resolvePackage installs a large allowlisted package", async () => {
|
|
502
|
+
await primeBunCache("chart.js");
|
|
503
|
+
|
|
504
|
+
const result = await resolvePackage("chart.js");
|
|
505
|
+
expect(result).not.toBeNull();
|
|
506
|
+
expect(existsSync(join(getCacheDir(), "node_modules", "chart.js"))).toBe(
|
|
507
|
+
true,
|
|
508
|
+
);
|
|
509
|
+
}, 60_000);
|
|
475
510
|
});
|
|
@@ -30,10 +30,10 @@ import {
|
|
|
30
30
|
} from "bun:test";
|
|
31
31
|
|
|
32
32
|
import { _inspectHookCacheForTests } from "../hooks/hook-loader.js";
|
|
33
|
+
import { getUserHooksFor } from "../hooks/registry.js";
|
|
33
34
|
import {
|
|
34
35
|
_inspectToolCacheForTests,
|
|
35
36
|
getCachedUserTools,
|
|
36
|
-
getUserHooksFor,
|
|
37
37
|
populateCacheAtBoot,
|
|
38
38
|
reconcilePluginSourcesNow,
|
|
39
39
|
resetPluginCacheForTests,
|
|
@@ -34,8 +34,8 @@ import {
|
|
|
34
34
|
} from "bun:test";
|
|
35
35
|
|
|
36
36
|
import { bootstrapPlugins } from "../daemon/external-plugins-bootstrap.js";
|
|
37
|
+
import { getUserHooksFor } from "../hooks/registry.js";
|
|
37
38
|
import {
|
|
38
|
-
getUserHooksFor,
|
|
39
39
|
populateCacheAtBoot,
|
|
40
40
|
reconcilePluginSourcesNow,
|
|
41
41
|
resetPluginCacheForTests,
|
|
@@ -23,9 +23,9 @@ import { tmpdir } from "node:os";
|
|
|
23
23
|
import { join } from "node:path";
|
|
24
24
|
import { beforeEach, describe, expect, test } from "bun:test";
|
|
25
25
|
|
|
26
|
+
import { getUserHooksFor } from "../hooks/registry.js";
|
|
26
27
|
import {
|
|
27
28
|
getCachedUserTools,
|
|
28
|
-
getUserHooksFor,
|
|
29
29
|
resetPluginCacheForTests,
|
|
30
30
|
} from "../plugins/mtime-cache.js";
|
|
31
31
|
import { loadUserPlugins } from "../plugins/user-loader.js";
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { existsSync } from "node:fs";
|
|
9
|
-
import { mkdir
|
|
9
|
+
import { mkdir } from "node:fs/promises";
|
|
10
10
|
import { join } from "node:path";
|
|
11
11
|
|
|
12
12
|
import { ensureBun } from "../util/bun-runtime.js";
|
|
@@ -24,8 +24,8 @@ export const ALLOWED_PACKAGES: readonly string[] = [
|
|
|
24
24
|
"clsx",
|
|
25
25
|
] as const;
|
|
26
26
|
|
|
27
|
+
/** Bounds a runaway install; the allowlist above bounds what may be installed. */
|
|
27
28
|
const INSTALL_TIMEOUT_MS = 10_000;
|
|
28
|
-
const MAX_PACKAGE_SIZE_BYTES = 5 * 1024 * 1024; // 5 MB
|
|
29
29
|
|
|
30
30
|
/** In-flight install promises keyed by package name, to deduplicate concurrent requests. */
|
|
31
31
|
const inflight = new Map<string, Promise<string | null>>();
|
|
@@ -148,37 +148,9 @@ async function installPackage(
|
|
|
148
148
|
return null;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
-
// Enforce max size
|
|
152
|
-
if (existsSync(pkgDir)) {
|
|
153
|
-
const size = await dirSize(pkgDir);
|
|
154
|
-
if (size > MAX_PACKAGE_SIZE_BYTES) {
|
|
155
|
-
log.warn({ pkg, size }, "Package exceeds size limit, removing");
|
|
156
|
-
const { rm } = await import("node:fs/promises");
|
|
157
|
-
await rm(pkgDir, { recursive: true, force: true });
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
151
|
return existsSync(pkgDir) ? nodeModulesDir : null;
|
|
163
152
|
} catch (err) {
|
|
164
153
|
log.warn({ pkg, err }, "Package resolution failed");
|
|
165
154
|
return null;
|
|
166
155
|
}
|
|
167
156
|
}
|
|
168
|
-
|
|
169
|
-
/** Recursively sum file sizes under a directory. */
|
|
170
|
-
async function dirSize(dir: string): Promise<number> {
|
|
171
|
-
const { readdir } = await import("node:fs/promises");
|
|
172
|
-
const entries = await readdir(dir, { withFileTypes: true });
|
|
173
|
-
let total = 0;
|
|
174
|
-
for (const entry of entries) {
|
|
175
|
-
const full = join(dir, entry.name);
|
|
176
|
-
if (entry.isDirectory()) {
|
|
177
|
-
total += await dirSize(full);
|
|
178
|
-
} else {
|
|
179
|
-
const s = await stat(full);
|
|
180
|
-
total += s.size;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return total;
|
|
184
|
-
}
|
package/src/hooks/hook-loader.ts
CHANGED
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
* registry, so the next read re-resolves fresh.
|
|
40
40
|
*
|
|
41
41
|
* Plugin *discovery* (which plugin directories exist, in what order) lives in
|
|
42
|
-
* `../plugins/mtime-cache.ts`;
|
|
43
|
-
*
|
|
44
|
-
* this module lets it sit below the plugin cache with no import cycle.
|
|
42
|
+
* `../plugins/mtime-cache.ts`; hook lookup in `./registry.ts` passes the
|
|
43
|
+
* discovered names into {@link collectUserHookEntries}. Keeping discovery out
|
|
44
|
+
* of this module lets it sit below the plugin cache with no import cycle.
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
47
|
import {
|
package/src/hooks/registry.ts
CHANGED
|
@@ -6,20 +6,22 @@
|
|
|
6
6
|
* hook-chain ordering.
|
|
7
7
|
*
|
|
8
8
|
* User-land hooks (from the filesystem) are owned by
|
|
9
|
-
* {@link ./hook-loader.ts} and surfaced through
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* {@link ./hook-loader.ts} and surfaced through {@link getUserHooksFor}.
|
|
10
|
+
* This module owns the in-process hooks that default plugins register at
|
|
11
|
+
* boot, plus the user-land lookup that walks discovered plugin names from
|
|
12
|
+
* the plugin cache.
|
|
12
13
|
*
|
|
13
14
|
* {@link getHooksFor} combines both sources: in-process hooks from this
|
|
14
15
|
* registry (filtered by `isPluginDisabled` at read time) and user-land hooks
|
|
15
16
|
* from the plugin cache. The read-time filtering is what makes `assistant
|
|
16
|
-
* plugins disable default-*` take effect immediately in a running assistant
|
|
17
|
-
*
|
|
17
|
+
* plugins disable default-*` take effect immediately in a running assistant:
|
|
18
|
+
* the hooks stay registered but are filtered out on the next turn.
|
|
18
19
|
*/
|
|
19
20
|
|
|
20
21
|
import { isPluginDisabled } from "../plugins/disabled-state.js";
|
|
21
|
-
import {
|
|
22
|
+
import { getDiscoveredUserPluginNames } from "../plugins/mtime-cache.js";
|
|
22
23
|
import type { HookEntry, HookFunction } from "../plugins/types.js";
|
|
24
|
+
import { collectUserHookEntries } from "./hook-loader.js";
|
|
23
25
|
|
|
24
26
|
// ─── Internal state ──────────────────────────────────────────────────────────
|
|
25
27
|
|
|
@@ -75,6 +77,48 @@ export function unregisterPluginHooks(pluginName: string): void {
|
|
|
75
77
|
|
|
76
78
|
// ─── Queries ─────────────────────────────────────────────────────────────────
|
|
77
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Get all hooks for a given event name from user plugins and standalone
|
|
82
|
+
* workspace hooks, from the hook loader's in-memory cache. Plugin hooks run
|
|
83
|
+
* in install-date order, the workspace hook runs last.
|
|
84
|
+
*
|
|
85
|
+
* This is a pure cache read: it never scans disk, activates a plugin, or
|
|
86
|
+
* runs `init`. Activation happens only at boot (`populateCacheAtBoot`)
|
|
87
|
+
* and through the imperative install/uninstall poke
|
|
88
|
+
* (`reconcilePluginSourcesNow`), both main-daemon paths, so a
|
|
89
|
+
* sidecar process that dispatches hooks (a worker running conversation
|
|
90
|
+
* turns) can never bring a plugin up in its own process.
|
|
91
|
+
*
|
|
92
|
+
* `effectiveEnabledPlugins` carries the per-chat plugin scope: when non-null,
|
|
93
|
+
* user plugins outside the set are skipped (standalone workspace hooks always
|
|
94
|
+
* run). `null`/omitted means no per-chat restriction.
|
|
95
|
+
*/
|
|
96
|
+
export async function getUserHookEntriesFor<TCtx = unknown>(
|
|
97
|
+
hookName: string,
|
|
98
|
+
effectiveEnabledPlugins?: Set<string> | null,
|
|
99
|
+
): Promise<HookEntry<TCtx>[]> {
|
|
100
|
+
return collectUserHookEntries<TCtx>(
|
|
101
|
+
hookName,
|
|
102
|
+
getDiscoveredUserPluginNames(),
|
|
103
|
+
effectiveEnabledPlugins,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* {@link getUserHookEntriesFor} without owner attribution. Returns just the
|
|
109
|
+
* hook functions in the same order.
|
|
110
|
+
*/
|
|
111
|
+
export async function getUserHooksFor<TCtx = unknown>(
|
|
112
|
+
hookName: string,
|
|
113
|
+
effectiveEnabledPlugins?: Set<string> | null,
|
|
114
|
+
): Promise<HookFunction<TCtx>[]> {
|
|
115
|
+
const entries = await getUserHookEntriesFor<TCtx>(
|
|
116
|
+
hookName,
|
|
117
|
+
effectiveEnabledPlugins,
|
|
118
|
+
);
|
|
119
|
+
return entries.map((e) => e.fn);
|
|
120
|
+
}
|
|
121
|
+
|
|
78
122
|
/**
|
|
79
123
|
* Collect every registered hook for the given name, in registration order.
|
|
80
124
|
* Plugins that don't declare a hook for `name` are skipped. Used by the
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
* - Plugins are never "registered" as a unit — we register their tools into
|
|
27
27
|
* the global tool registry.
|
|
28
28
|
*
|
|
29
|
-
* Tools are populated at boot by `loadUserPlugins()`;
|
|
30
|
-
*
|
|
31
|
-
* each hook through the hook loader on demand.
|
|
29
|
+
* Tools are populated at boot by `loadUserPlugins()`; hook dispatch reads
|
|
30
|
+
* discovered plugin names from this cache via {@link getDiscoveredUserPluginNames}
|
|
31
|
+
* and resolves each hook through the hook loader on demand.
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
34
|
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
|
|
@@ -38,7 +38,6 @@ import type { Logger } from "pino";
|
|
|
38
38
|
|
|
39
39
|
import {
|
|
40
40
|
clearPluginHooks,
|
|
41
|
-
collectUserHookEntries,
|
|
42
41
|
evictHooksForOwner,
|
|
43
42
|
hasWorkspaceHooks,
|
|
44
43
|
type HookOwnerKind,
|
|
@@ -47,7 +46,7 @@ import {
|
|
|
47
46
|
runShutdownHook,
|
|
48
47
|
WORKSPACE_HOOKS_OWNER,
|
|
49
48
|
} from "../hooks/hook-loader.js";
|
|
50
|
-
import type {
|
|
49
|
+
import type { ShutdownReason } from "../plugin-api/types.js";
|
|
51
50
|
import {
|
|
52
51
|
registerPluginSecretPatterns,
|
|
53
52
|
resetPluginSecretPatternsForTests,
|
|
@@ -76,11 +75,7 @@ import {
|
|
|
76
75
|
importWithTimeout,
|
|
77
76
|
setSurfaceImportTimeout,
|
|
78
77
|
} from "./surface-import.js";
|
|
79
|
-
import type {
|
|
80
|
-
|
|
81
|
-
// Re-export for type compat — consumers that import HookFunction from
|
|
82
|
-
// the mtime cache module still resolve.
|
|
83
|
-
export type { HookFunction } from "./types.js";
|
|
78
|
+
import type { PluginCredentialKeyPattern } from "./types.js";
|
|
84
79
|
|
|
85
80
|
const log = getLogger("plugin-mtime-cache");
|
|
86
81
|
|
|
@@ -206,48 +201,15 @@ let lastVersions: Record<string, PluginSourceVersion> = {};
|
|
|
206
201
|
/** In-flight reconcile — concurrent imperative pokes await it rather than racing. */
|
|
207
202
|
let reconcileInFlight: Promise<void> | null = null;
|
|
208
203
|
|
|
209
|
-
// ───
|
|
204
|
+
// ─── Discovery reads ─────────────────────────────────────────────────────────
|
|
210
205
|
|
|
211
206
|
/**
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
* This is a pure cache read: it never scans disk, activates a plugin, or
|
|
217
|
-
* runs `init`. Activation happens only at boot ({@link populateCacheAtBoot})
|
|
218
|
-
* and through the imperative install/uninstall poke
|
|
219
|
-
* ({@link reconcilePluginSourcesNow}) — both main-daemon paths — so a
|
|
220
|
-
* sidecar process that dispatches hooks (a worker running conversation
|
|
221
|
-
* turns) can never bring a plugin up in its own process.
|
|
222
|
-
*
|
|
223
|
-
* `effectiveEnabledPlugins` carries the per-chat plugin scope: when non-null,
|
|
224
|
-
* user plugins outside the set are skipped (standalone workspace hooks always
|
|
225
|
-
* run). `null`/omitted means no per-chat restriction.
|
|
207
|
+
* Plugin names currently in the discovery cache, in install-date order.
|
|
208
|
+
* Hook lookup in `hooks/registry.ts` walks this set; the cache itself does
|
|
209
|
+
* not resolve hooks.
|
|
226
210
|
*/
|
|
227
|
-
export
|
|
228
|
-
|
|
229
|
-
effectiveEnabledPlugins?: Set<string> | null,
|
|
230
|
-
): Promise<HookEntry<TCtx>[]> {
|
|
231
|
-
return collectUserHookEntries<TCtx>(
|
|
232
|
-
hookName,
|
|
233
|
-
discoveredPluginDirs.values(),
|
|
234
|
-
effectiveEnabledPlugins,
|
|
235
|
-
);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* {@link getUserHookEntriesFor} without owner attribution — returns just the
|
|
240
|
-
* hook functions in the same order.
|
|
241
|
-
*/
|
|
242
|
-
export async function getUserHooksFor<TCtx = unknown>(
|
|
243
|
-
hookName: string,
|
|
244
|
-
effectiveEnabledPlugins?: Set<string> | null,
|
|
245
|
-
): Promise<HookFunction<TCtx>[]> {
|
|
246
|
-
const entries = await getUserHookEntriesFor<TCtx>(
|
|
247
|
-
hookName,
|
|
248
|
-
effectiveEnabledPlugins,
|
|
249
|
-
);
|
|
250
|
-
return entries.map((e) => e.fn);
|
|
211
|
+
export function getDiscoveredUserPluginNames(): Iterable<string> {
|
|
212
|
+
return discoveredPluginDirs.values();
|
|
251
213
|
}
|
|
252
214
|
|
|
253
215
|
// ─── Source-versions reconcile ───────────────────────────────────────────────
|
package/src/tools/registry.ts
CHANGED
|
@@ -431,7 +431,8 @@ export function unregisterPluginTools(pluginName: string): void {
|
|
|
431
431
|
* {@link import("../plugins/mtime-cache.js").getActiveUserPluginTools} and diffs
|
|
432
432
|
* the result into the registry: plugins that vanished are unregistered, new
|
|
433
433
|
* plugins register, and a plugin whose per-tool source mtimes moved is
|
|
434
|
-
* re-registered. Mirrors how hooks resolve through `getUserHookEntriesFor
|
|
434
|
+
* re-registered. Mirrors how hooks resolve through `getUserHookEntriesFor`
|
|
435
|
+
* in `hooks/registry.ts`.
|
|
435
436
|
*
|
|
436
437
|
* This is a pure read of the plugin cache — it does NOT reconcile the cache
|
|
437
438
|
* against the source-versions sentinel, so it never activates a plugin or runs
|