@vellumai/assistant 0.10.8-dev.202607151902.7dbe06e → 0.10.8-dev.202607151931.db21e87
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__/mtime-cache.test.ts +61 -0
- package/src/cli/commands/plugins.ts +27 -1
- package/src/monitoring/__tests__/plugin-source-watch.test.ts +3 -1
- package/src/monitoring/plugin-source-watch.ts +3 -62
- package/src/plugins/collect-source-versions.ts +77 -0
- package/src/plugins/mtime-cache.ts +47 -0
- package/src/runtime/routes/plugins-routes.ts +15 -0
package/package.json
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
getCachedUserTools,
|
|
40
40
|
getUserHooksFor,
|
|
41
41
|
populateCacheAtBoot,
|
|
42
|
+
reconcilePluginSourcesNow,
|
|
42
43
|
resetPluginCacheForTests,
|
|
43
44
|
} from "../plugins/mtime-cache.js";
|
|
44
45
|
import { getSourceVersionsPath } from "../plugins/source-versions.js";
|
|
@@ -721,6 +722,66 @@ describe("plugin runtime activation", () => {
|
|
|
721
722
|
).toBe(true);
|
|
722
723
|
});
|
|
723
724
|
|
|
725
|
+
test("reconcilePluginSourcesNow brings a freshly installed plugin up immediately, without the sentinel", async () => {
|
|
726
|
+
await populateCacheAtBoot(); // empty plugins dir
|
|
727
|
+
expect(getAllToolDefinitions().some((t) => t.name === "eager-tool")).toBe(
|
|
728
|
+
false,
|
|
729
|
+
);
|
|
730
|
+
|
|
731
|
+
const dir = freshPluginDir("eager-plugin");
|
|
732
|
+
writePackageJson(dir, { ...SIMPLE_PKG, name: "eager-plugin" });
|
|
733
|
+
writeTool(dir, "eager-tool", TOOL_SRC("eager-tool"));
|
|
734
|
+
const initMarker = join(ROOT, "eager-init.log");
|
|
735
|
+
writeMarkerHook(dir, "init", initMarker, "init");
|
|
736
|
+
|
|
737
|
+
// Deliberately do NOT publish through the watcher and do NOT dispatch a
|
|
738
|
+
// hook — this is the imperative install path: the plugin's files land on
|
|
739
|
+
// disk and the daemon is told to bring it up right now.
|
|
740
|
+
await reconcilePluginSourcesNow();
|
|
741
|
+
await loadPluginTools();
|
|
742
|
+
|
|
743
|
+
expect(getAllToolDefinitions().some((t) => t.name === "eager-tool")).toBe(
|
|
744
|
+
true,
|
|
745
|
+
);
|
|
746
|
+
// init ran exactly once, as part of the reconcile — not at a later turn.
|
|
747
|
+
expect(readFileSync(initMarker, "utf8").trim().split("\n")).toHaveLength(1);
|
|
748
|
+
|
|
749
|
+
// Calling it again (e.g. the monitor's later sentinel publish, or a
|
|
750
|
+
// redundant poke) is a no-op — the plugin is already up.
|
|
751
|
+
await reconcilePluginSourcesNow();
|
|
752
|
+
expect(readFileSync(initMarker, "utf8").trim().split("\n")).toHaveLength(1);
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
test("reconcilePluginSourcesNow deactivates a removed plugin without re-running shutdown", async () => {
|
|
756
|
+
await populateCacheAtBoot(); // empty plugins dir
|
|
757
|
+
|
|
758
|
+
const dir = freshPluginDir("teardown-plugin");
|
|
759
|
+
writePackageJson(dir, { ...SIMPLE_PKG, name: "teardown-plugin" });
|
|
760
|
+
writeTool(dir, "teardown-tool", TOOL_SRC("teardown-tool"));
|
|
761
|
+
const shutdownMarker = join(ROOT, "teardown-shutdown.log");
|
|
762
|
+
writeMarkerHook(dir, "shutdown", shutdownMarker, "bye");
|
|
763
|
+
|
|
764
|
+
await reconcilePluginSourcesNow();
|
|
765
|
+
await loadPluginTools();
|
|
766
|
+
expect(
|
|
767
|
+
getAllToolDefinitions().some((t) => t.name === "teardown-tool"),
|
|
768
|
+
).toBe(true);
|
|
769
|
+
|
|
770
|
+
// This is the daemon uninstall route's teardown path: the managed uninstall
|
|
771
|
+
// runs `shutdown` itself (while the files are present) and removes the
|
|
772
|
+
// directory, then reconciles. The reconcile here only mirrors the removal —
|
|
773
|
+
// it drops the plugin's tools/hooks but must NOT run `shutdown` a second
|
|
774
|
+
// time (the removal reason carries no shutdown).
|
|
775
|
+
rmSync(dir, { recursive: true, force: true });
|
|
776
|
+
await reconcilePluginSourcesNow();
|
|
777
|
+
await loadPluginTools();
|
|
778
|
+
|
|
779
|
+
expect(
|
|
780
|
+
getAllToolDefinitions().some((t) => t.name === "teardown-tool"),
|
|
781
|
+
).toBe(false);
|
|
782
|
+
expect(existsSync(shutdownMarker)).toBe(false);
|
|
783
|
+
});
|
|
784
|
+
|
|
724
785
|
test("activation is idempotent — republishing without changes does not re-run init", async () => {
|
|
725
786
|
const dir = freshPluginDir("idem-plugin");
|
|
726
787
|
writePackageJson(dir, { ...SIMPLE_PKG, name: "idem-plugin" });
|
|
@@ -10,6 +10,7 @@ import { createRequire } from "node:module";
|
|
|
10
10
|
|
|
11
11
|
import type { Command } from "commander";
|
|
12
12
|
|
|
13
|
+
import { cliIpcCall } from "../../ipc/cli-client.js";
|
|
13
14
|
import { yellow } from "../lib/cli-colors.js";
|
|
14
15
|
import { applyCommandHelp, subcommand } from "../lib/cli-command-help.js";
|
|
15
16
|
import { confirmPrompt } from "../lib/confirm-prompt.js";
|
|
@@ -569,7 +570,32 @@ export function registerPluginsCommand(program: Command): void {
|
|
|
569
570
|
return;
|
|
570
571
|
}
|
|
571
572
|
}
|
|
572
|
-
|
|
573
|
+
// Prefer the daemon: it runs the plugin's `shutdown` hook and drops
|
|
574
|
+
// the plugin's tools/hooks in the main process — symmetric to how
|
|
575
|
+
// install runs `init` there. Fall back to a local uninstall only
|
|
576
|
+
// when the daemon is unreachable (a transport error carries no
|
|
577
|
+
// `statusCode`); an operator can still uninstall while it's stopped,
|
|
578
|
+
// and `shutdown` then runs in this process, the only one available.
|
|
579
|
+
const daemon = await cliIpcCall<{ name: string; target: string }>(
|
|
580
|
+
"plugins_uninstall",
|
|
581
|
+
{ pathParams: { name } },
|
|
582
|
+
);
|
|
583
|
+
let result: { name: string; target: string };
|
|
584
|
+
if (daemon.ok && daemon.result) {
|
|
585
|
+
result = daemon.result;
|
|
586
|
+
} else if (daemon.statusCode === undefined) {
|
|
587
|
+
log.debug(
|
|
588
|
+
{ name, error: daemon.error },
|
|
589
|
+
"uninstall could not reach the daemon; running shutdown + removal locally",
|
|
590
|
+
);
|
|
591
|
+
result = await libs.uninstall.uninstallPlugin({ name });
|
|
592
|
+
} else {
|
|
593
|
+
// The daemon reached a decision (not installed, bad name, …);
|
|
594
|
+
// surface it rather than silently retrying locally.
|
|
595
|
+
console.error(daemon.error ?? "Plugin uninstall failed.");
|
|
596
|
+
process.exitCode = 1;
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
573
599
|
log.info(
|
|
574
600
|
{ name: result.name, target: result.target },
|
|
575
601
|
"external plugin uninstalled",
|
|
@@ -46,8 +46,10 @@ afterAll(() => {
|
|
|
46
46
|
rmSync(ROOT, { recursive: true, force: true });
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
const {
|
|
49
|
+
const { createSourceWatchState, runSourceWatchPass } =
|
|
50
50
|
await import("../plugin-source-watch.js");
|
|
51
|
+
const { collectSourceVersions } =
|
|
52
|
+
await import("../../plugins/collect-source-versions.js");
|
|
51
53
|
const { getSourceVersionsPath, readSourceVersions } =
|
|
52
54
|
await import("../../plugins/source-versions.js");
|
|
53
55
|
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
import {
|
|
26
26
|
existsSync,
|
|
27
27
|
mkdirSync,
|
|
28
|
+
readdirSync,
|
|
28
29
|
renameSync,
|
|
29
30
|
statSync,
|
|
30
31
|
writeFileSync,
|
|
31
32
|
} from "node:fs";
|
|
32
|
-
import { readdirSync } from "node:fs";
|
|
33
33
|
import { join } from "node:path";
|
|
34
34
|
|
|
35
|
-
import {
|
|
35
|
+
import { collectSourceVersions } from "../plugins/collect-source-versions.js";
|
|
36
36
|
import type {
|
|
37
37
|
PluginSourceVersion,
|
|
38
38
|
SourceVersionsDocument,
|
|
@@ -43,69 +43,10 @@ import {
|
|
|
43
43
|
SOURCE_VERSIONS_FORMAT,
|
|
44
44
|
} from "../plugins/source-versions.js";
|
|
45
45
|
import { getLogger } from "../util/logger.js";
|
|
46
|
-
import {
|
|
47
|
-
getMonitoringDataDir,
|
|
48
|
-
getWorkspaceHooksDir,
|
|
49
|
-
getWorkspacePluginsDir,
|
|
50
|
-
} from "../util/platform.js";
|
|
46
|
+
import { getMonitoringDataDir } from "../util/platform.js";
|
|
51
47
|
|
|
52
48
|
const log = getLogger("plugin-source-watch");
|
|
53
49
|
|
|
54
|
-
/**
|
|
55
|
-
* Collect the current source version of every watched directory: each
|
|
56
|
-
* plugin directory under `<workspace>/plugins/` (same discovery rule as the
|
|
57
|
-
* daemon's plugin scan — a directory with a `package.json`), plus the
|
|
58
|
-
* standalone workspace hooks directory when it exists. Disabled plugins are
|
|
59
|
-
* fingerprinted too: consumers need fresh state the moment a plugin is
|
|
60
|
-
* re-enabled, and the `disabled` field is how they observe the toggle
|
|
61
|
-
* itself (dotfiles are excluded from the fingerprint).
|
|
62
|
-
*/
|
|
63
|
-
export function collectSourceVersions(): Record<string, PluginSourceVersion> {
|
|
64
|
-
const out: Record<string, PluginSourceVersion> = {};
|
|
65
|
-
|
|
66
|
-
const pluginsDir = getWorkspacePluginsDir();
|
|
67
|
-
let entries: string[] = [];
|
|
68
|
-
try {
|
|
69
|
-
entries = readdirSync(pluginsDir);
|
|
70
|
-
} catch {
|
|
71
|
-
// No plugins directory yet — nothing to watch there.
|
|
72
|
-
}
|
|
73
|
-
for (const entry of entries) {
|
|
74
|
-
if (entry.startsWith(".")) {
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
const dir = join(pluginsDir, entry);
|
|
78
|
-
try {
|
|
79
|
-
if (!statSync(dir).isDirectory()) {
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
} catch {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
if (!existsSync(join(dir, "package.json"))) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const snapshot = snapshotPluginSource(dir);
|
|
89
|
-
out[dir] = {
|
|
90
|
-
fingerprint: snapshot.fingerprint,
|
|
91
|
-
evictionPaths: snapshot.evictionPaths,
|
|
92
|
-
disabled: existsSync(join(dir, ".disabled")),
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const workspaceHooksDir = getWorkspaceHooksDir();
|
|
97
|
-
if (existsSync(workspaceHooksDir)) {
|
|
98
|
-
const snapshot = snapshotPluginSource(workspaceHooksDir);
|
|
99
|
-
out[workspaceHooksDir] = {
|
|
100
|
-
fingerprint: snapshot.fingerprint,
|
|
101
|
-
evictionPaths: snapshot.evictionPaths,
|
|
102
|
-
disabled: false,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return out;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
50
|
/**
|
|
110
51
|
* Whether two version maps describe the same source state. Compares key
|
|
111
52
|
* sets, fingerprints, and disabled flags; eviction paths are derived from
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Walk the workspace's plugin directories and snapshot each one's current
|
|
3
|
+
* source version.
|
|
4
|
+
*
|
|
5
|
+
* This is the single collector shared by the two producers of a source-versions
|
|
6
|
+
* map: the resource monitor's watcher (which fingerprints on a timer and writes
|
|
7
|
+
* the sentinel — see `../monitoring/plugin-source-watch.ts`) and the daemon's
|
|
8
|
+
* imperative reconcile (which applies the walk directly, without waiting on the
|
|
9
|
+
* watcher — see `reconcilePluginSourcesNow` in `./mtime-cache.ts`). Keeping the
|
|
10
|
+
* walk in one place guarantees both paths produce byte-identical maps, so an
|
|
11
|
+
* imperative reconcile never disagrees with the watcher's next publish and
|
|
12
|
+
* causes a spurious reload.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
getWorkspaceHooksDir,
|
|
20
|
+
getWorkspacePluginsDir,
|
|
21
|
+
} from "../util/platform.js";
|
|
22
|
+
import { snapshotPluginSource } from "./source-fingerprint.js";
|
|
23
|
+
import type { PluginSourceVersion } from "./source-versions.js";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Collect the current source version of every watched directory: each plugin
|
|
27
|
+
* directory under `<workspace>/plugins/` (a directory with a `package.json`),
|
|
28
|
+
* plus the standalone workspace hooks directory when it exists. Disabled
|
|
29
|
+
* plugins are fingerprinted too: consumers need fresh state the moment a plugin
|
|
30
|
+
* is re-enabled, and the `disabled` field is how they observe the toggle itself
|
|
31
|
+
* (dotfiles are excluded from the fingerprint).
|
|
32
|
+
*/
|
|
33
|
+
export function collectSourceVersions(): Record<string, PluginSourceVersion> {
|
|
34
|
+
const out: Record<string, PluginSourceVersion> = {};
|
|
35
|
+
|
|
36
|
+
const pluginsDir = getWorkspacePluginsDir();
|
|
37
|
+
let entries: string[] = [];
|
|
38
|
+
try {
|
|
39
|
+
entries = readdirSync(pluginsDir);
|
|
40
|
+
} catch {
|
|
41
|
+
// No plugins directory yet — nothing to watch there.
|
|
42
|
+
}
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
if (entry.startsWith(".")) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const dir = join(pluginsDir, entry);
|
|
48
|
+
try {
|
|
49
|
+
if (!statSync(dir).isDirectory()) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
} catch {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (!existsSync(join(dir, "package.json"))) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const snapshot = snapshotPluginSource(dir);
|
|
59
|
+
out[dir] = {
|
|
60
|
+
fingerprint: snapshot.fingerprint,
|
|
61
|
+
evictionPaths: snapshot.evictionPaths,
|
|
62
|
+
disabled: existsSync(join(dir, ".disabled")),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const workspaceHooksDir = getWorkspaceHooksDir();
|
|
67
|
+
if (existsSync(workspaceHooksDir)) {
|
|
68
|
+
const snapshot = snapshotPluginSource(workspaceHooksDir);
|
|
69
|
+
out[workspaceHooksDir] = {
|
|
70
|
+
fingerprint: snapshot.fingerprint,
|
|
71
|
+
evictionPaths: snapshot.evictionPaths,
|
|
72
|
+
disabled: false,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
@@ -58,6 +58,7 @@ import {
|
|
|
58
58
|
getWorkspaceHooksDir,
|
|
59
59
|
getWorkspacePluginsDir,
|
|
60
60
|
} from "../util/platform.js";
|
|
61
|
+
import { collectSourceVersions } from "./collect-source-versions.js";
|
|
61
62
|
import {
|
|
62
63
|
deriveToolName,
|
|
63
64
|
listSurfaceDir,
|
|
@@ -308,6 +309,52 @@ async function maybeReconcileFromSentinel(): Promise<void> {
|
|
|
308
309
|
}
|
|
309
310
|
}
|
|
310
311
|
|
|
312
|
+
/**
|
|
313
|
+
* Imperatively reconcile the plugin caches against the current on-disk state
|
|
314
|
+
* *now* — without waiting for the resource monitor to republish the
|
|
315
|
+
* source-versions sentinel or for the next hook dispatch to notice it.
|
|
316
|
+
*
|
|
317
|
+
* An install / uninstall / enable / disable materializes files on disk; the
|
|
318
|
+
* steady-state path picks that up eventually — the monitor republishes the
|
|
319
|
+
* sentinel and the dispatch-path gate applies the diff on the next turn. That
|
|
320
|
+
* is eventually-correct but not immediate: nothing runs a newly installed
|
|
321
|
+
* plugin's `init` until some later turn dispatches a hook. Callers that just
|
|
322
|
+
* changed the plugin set on disk (the install / uninstall routes, and the
|
|
323
|
+
* CLI's best-effort post-install poke) call this to bring the change up
|
|
324
|
+
* deterministically, so a freshly installed plugin's `init` fires as part of
|
|
325
|
+
* the install rather than at the next daemon boot.
|
|
326
|
+
*
|
|
327
|
+
* Reuses the same collector the monitor writes into the sentinel, so the map
|
|
328
|
+
* applied here is identical to the monitor's next publish — which then diffs to
|
|
329
|
+
* a no-op. Idempotent and safe to call redundantly: `applySourceVersions` only
|
|
330
|
+
* redeploys directories whose fingerprint moved, and activation is guarded so a
|
|
331
|
+
* plugin already up is never re-initialized. Never throws — a failure is
|
|
332
|
+
* contained inside `applySourceVersions` and logged there.
|
|
333
|
+
*
|
|
334
|
+
* Coordinates with the sentinel gate through the shared `reconcileInFlight`
|
|
335
|
+
* latch: it waits out any dispatch-driven reconcile already running, then
|
|
336
|
+
* claims the latch for its own apply, so the two paths never overlap.
|
|
337
|
+
*/
|
|
338
|
+
export async function reconcilePluginSourcesNow(): Promise<void> {
|
|
339
|
+
while (reconcileInFlight !== null) {
|
|
340
|
+
await reconcileInFlight;
|
|
341
|
+
}
|
|
342
|
+
// `applySourceVersions` contains its own failures, but the `collectSourceVersions()`
|
|
343
|
+
// walk that feeds it runs outside that guard — wrap the whole thing so an
|
|
344
|
+
// imperative reconcile never rejects into its callers (the install route must
|
|
345
|
+
// still return success for an install whose files already landed on disk).
|
|
346
|
+
reconcileInFlight = (async () => {
|
|
347
|
+
try {
|
|
348
|
+
await applySourceVersions(collectSourceVersions());
|
|
349
|
+
} catch (err) {
|
|
350
|
+
log.error({ err }, "imperative plugin reconcile failed");
|
|
351
|
+
}
|
|
352
|
+
})().finally(() => {
|
|
353
|
+
reconcileInFlight = null;
|
|
354
|
+
});
|
|
355
|
+
await reconcileInFlight;
|
|
356
|
+
}
|
|
357
|
+
|
|
311
358
|
/**
|
|
312
359
|
* Validate that a directory path from the sentinel is an allowed plugin
|
|
313
360
|
* source: either under the workspace plugins directory or the standalone
|
|
@@ -91,6 +91,7 @@ import {
|
|
|
91
91
|
import { getPlatformBaseUrl } from "../../config/env.js";
|
|
92
92
|
import { isPluginDisabled } from "../../plugins/disabled-state.js";
|
|
93
93
|
import { ensurePluginApiShim } from "../../plugins/ensure-plugin-api-shim.js";
|
|
94
|
+
import { reconcilePluginSourcesNow } from "../../plugins/mtime-cache.js";
|
|
94
95
|
import { getLocalCategorySlugs } from "../../skills/categories-cache.js";
|
|
95
96
|
import { getLogger } from "../../util/logger.js";
|
|
96
97
|
import { getWorkspacePluginsDir } from "../../util/platform.js";
|
|
@@ -1092,7 +1093,15 @@ async function handleUninstallPlugin({
|
|
|
1092
1093
|
await ensurePluginApiShim().catch(() => {});
|
|
1093
1094
|
|
|
1094
1095
|
try {
|
|
1096
|
+
// `uninstallPlugin` runs the plugin's `shutdown` hook (while its files are
|
|
1097
|
+
// still present) and then removes the directory — both in this daemon
|
|
1098
|
+
// process. Following it with a reconcile drops the plugin's now-absent
|
|
1099
|
+
// tools and hooks from the in-memory caches immediately (the `shutdown`
|
|
1100
|
+
// already ran, so the reconcile's deactivation does not run it again),
|
|
1101
|
+
// rather than leaving that to the background source watcher. Symmetric to
|
|
1102
|
+
// the install route, which reconciles to bring a new plugin up.
|
|
1095
1103
|
const result = await uninstallPlugin({ name: rawName });
|
|
1104
|
+
await reconcilePluginSourcesNow();
|
|
1096
1105
|
publishPluginsChanged(getOriginClientId(headers));
|
|
1097
1106
|
return { name: result.name, target: result.target };
|
|
1098
1107
|
} catch (err) {
|
|
@@ -1228,6 +1237,12 @@ async function handleInstallPlugin({ body = {}, headers }: RouteHandlerArgs) {
|
|
|
1228
1237
|
{ fetch: globalThis.fetch.bind(globalThis) },
|
|
1229
1238
|
);
|
|
1230
1239
|
}
|
|
1240
|
+
// Bring the freshly materialized plugin up in-process right now — register
|
|
1241
|
+
// its tools and run its `init` hook — instead of waiting for the resource
|
|
1242
|
+
// monitor to republish the sentinel and a later turn to apply it. This is
|
|
1243
|
+
// what makes `init` fire as part of the install rather than at the next
|
|
1244
|
+
// daemon boot. Never throws; a failure is contained and logged.
|
|
1245
|
+
await reconcilePluginSourcesNow();
|
|
1231
1246
|
publishPluginsChanged(getOriginClientId(headers));
|
|
1232
1247
|
return {
|
|
1233
1248
|
ok: true as const,
|