@vibecontrols/plugin-sdk 2026.1123.1 → 2026.1124.1

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/README.md CHANGED
@@ -42,6 +42,13 @@ const { onServerStart, onServerStop } = createLifecycleHooks({
42
42
  onInit: async (hostServices) => {
43
43
  /* ... */
44
44
  },
45
+ // Receives the agent's stop context, not hostServices. `reason` is
46
+ // "reload" on a hot reload / update and "shutdown" on a daemon stop; it is
47
+ // undefined when the agent gives no reason (e.g. plugin removal).
48
+ onShutdown: async (context) => {
49
+ if (context?.reason === "reload") return; // keep long-lived state
50
+ /* full teardown */
51
+ },
45
52
  });
46
53
  ```
47
54
 
@@ -74,6 +81,8 @@ const app = new RoutesBuilder("demo", hostServices)
74
81
  app.get("/ping", () => ({ ok: true }));
75
82
  ```
76
83
 
84
+ `withAuth` accepts the same credentials as the agent: an `x-agent-api-key` header (`AGENT_API_KEY_HEADER`) or `Authorization: Bearer <key>`. The key is compared in constant time, and an empty expected key rejects every request. Query-string keys are never read.
85
+
77
86
  ### `telemetry` — auto-tagged emitter
78
87
 
79
88
  ```ts
@@ -4,7 +4,7 @@
4
4
  * `AuditLogger` binds `source` to the plugin name and forwards events to
5
5
  * `hostServices.audit?.emit`. No-op when the host doesn't expose audit.
6
6
  */
7
- import { r as HostServices } from "../index-D946chPf.js";
7
+ import { r as HostServices } from "../index-DumrPKY-.js";
8
8
  export declare class AuditLogger {
9
9
  private readonly source;
10
10
  private readonly hostServices?;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Type-safe wrapper over `hostServices.broadcast` — no-op when absent.
5
5
  */
6
- import { r as HostServices } from "../index-D946chPf.js";
6
+ import { r as HostServices } from "../index-DumrPKY-.js";
7
7
  export declare class BroadcastEmitter {
8
8
  private readonly hostServices?;
9
9
  constructor(hostServices?: HostServices | undefined);
@@ -10,7 +10,7 @@
10
10
  * with sane fallbacks; invalid values warn through the logger and return
11
11
  * the default.
12
12
  */
13
- import { m as SdkLogger, r as HostServices } from "../index-D946chPf.js";
13
+ import { _ as SdkLogger, r as HostServices } from "../index-DumrPKY-.js";
14
14
  export declare class ConfigManager {
15
15
  private readonly pluginName;
16
16
  private readonly hostServices?;
@@ -20,7 +20,7 @@
20
20
  * - Consumer plugins MUST redact credentials before returning. The aggregator
21
21
  * does not sanitise contributions.
22
22
  */
23
- import { r as HostServices } from "../index-D946chPf.js";
23
+ import { r as HostServices } from "../index-DumrPKY-.js";
24
24
  /** Single context contribution returned by a plugin. */
25
25
  export interface ContextContribution {
26
26
  /** Stable identifier of the contributing plugin. */
@@ -11,5 +11,5 @@
11
11
  * vibecontrols-agent/src/core/profile-context.ts:62-151,
12
12
  * vibecontrols-agent/src/core/plugin-capabilities.ts.
13
13
  */
14
- import { _ as SupportedOS, a as MetaProviderRef, c as PluginNukeContext, d as PrerequisiteKind, f as ProfileContext, g as StorageProvider, h as ServiceRegistry, i as IframeBridge, l as PluginTag, m as SdkLogger, n as HostPlugins, o as NukeResult, p as ProviderType, r as HostServices, s as PluginCapabilities, t as FULL_TRUST_CAPS, u as Prerequisite, v as VibePlugin, y as VibePluginFactory } from "../index-D946chPf.js";
15
- export { FULL_TRUST_CAPS, HostPlugins, HostServices, IframeBridge, MetaProviderRef, NukeResult, PluginCapabilities, PluginNukeContext, PluginTag, Prerequisite, PrerequisiteKind, ProfileContext, ProviderType, SdkLogger, ServiceRegistry, StorageProvider, SupportedOS, VibePlugin, VibePluginFactory };
14
+ import { S as VibePluginFactory, _ as SdkLogger, a as MetaProviderRef, b as SupportedOS, c as PluginCapabilities, d as PluginStopReason, f as PluginTag, g as ProviderType, h as ProfileContext, i as IframeBridge, l as PluginNukeContext, m as PrerequisiteKind, n as HostPlugins, o as NukeResult, p as Prerequisite, r as HostServices, s as PROVIDER_TYPES, t as FULL_TRUST_CAPS, u as PluginStopContext, v as ServiceRegistry, x as VibePlugin, y as StorageProvider } from "../index-DumrPKY-.js";
15
+ export { FULL_TRUST_CAPS, HostPlugins, HostServices, IframeBridge, MetaProviderRef, NukeResult, PROVIDER_TYPES, PluginCapabilities, PluginNukeContext, PluginStopContext, PluginStopReason, PluginTag, Prerequisite, PrerequisiteKind, ProfileContext, ProviderType, SdkLogger, ServiceRegistry, StorageProvider, SupportedOS, VibePlugin, VibePluginFactory };
@@ -10,6 +10,30 @@ const FULL_TRUST_CAPS = {
10
10
  singletonOnly: false,
11
11
  requiresIsolation: false
12
12
  };
13
- export { FULL_TRUST_CAPS };
13
+ /**
14
+ * Provider-registry type a META plugin's providers register under, mirroring
15
+ * the agent `ServiceRegistry`'s provider types. Declared on `MetaProviderRef`
16
+ * so a META can ELECT a platform default (not merely install it) without
17
+ * having to scan every registry type to discover which one a provider owns.
18
+ *
19
+ * Kept in lockstep with the agent `ServiceRegistry` provider types
20
+ * (vibecontrols-agent/src/core/service-registry.ts). The agent's test suite
21
+ * imports this runtime list and asserts its own `PROVIDER_TYPES` matches it
22
+ * value-for-value, so the two cannot drift silently.
23
+ *
24
+ * `desk` is the BotManor Stewards desk family (plan 09 §5.5): a META
25
+ * `@vibecontrols/vibe-plugin-desk` routing to browser / x11 / macOS / Windows
26
+ * desk providers.
27
+ */
28
+ const PROVIDER_TYPES = [
29
+ "tunnel",
30
+ "session",
31
+ "ai",
32
+ "plan",
33
+ "gitops",
34
+ "security",
35
+ "desk"
36
+ ];
37
+ export { FULL_TRUST_CAPS, PROVIDER_TYPES };
14
38
 
15
39
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { g as StorageProvider, m as SdkLogger } from "./index-D946chPf.js";
1
+ import { _ as SdkLogger, y as StorageProvider } from "./index-DumrPKY-.js";
2
2
  declare class TypedStore<T> {
3
3
  private readonly storage;
4
4
  private readonly namespace;
@@ -22,9 +22,16 @@ type SupportedOS = "linux" | "darwin" | "win32";
22
22
  * having to scan every registry type to discover which one a provider owns.
23
23
  *
24
24
  * Kept in lockstep with the agent `ServiceRegistry` provider types
25
- * (vibecontrols-agent/src/core/service-registry.ts).
25
+ * (vibecontrols-agent/src/core/service-registry.ts). The agent's test suite
26
+ * imports this runtime list and asserts its own `PROVIDER_TYPES` matches it
27
+ * value-for-value, so the two cannot drift silently.
28
+ *
29
+ * `desk` is the BotManor Stewards desk family (plan 09 §5.5): a META
30
+ * `@vibecontrols/vibe-plugin-desk` routing to browser / x11 / macOS / Windows
31
+ * desk providers.
26
32
  */
27
- type ProviderType = "tunnel" | "session" | "ai" | "plan" | "gitops" | "security";
33
+ declare const PROVIDER_TYPES: readonly ["tunnel", "session", "ai", "plan", "gitops", "security", "desk"];
34
+ type ProviderType = (typeof PROVIDER_TYPES)[number];
28
35
  interface Prerequisite {
29
36
  name: string;
30
37
  kind: PrerequisiteKind;
@@ -85,6 +92,26 @@ interface NukeResult {
85
92
  /** Non-fatal notes (e.g. "left binary installed — shared/user-owned"). */
86
93
  notes?: string[];
87
94
  }
95
+ /**
96
+ * Why the agent is stopping a plugin. `reload` is a hot reload or an
97
+ * in-place update — the plugin is started again immediately, so it should
98
+ * preserve long-lived state (terminal sessions, tunnels). `shutdown` is a
99
+ * full daemon stop — tear everything down.
100
+ */
101
+ type PluginStopReason = "reload" | "shutdown";
102
+ /**
103
+ * The single argument the agent passes to `onServerStop`. Mirrors the agent's
104
+ * real call sites (vibecontrols-agent/src/core/plugin-system.ts
105
+ * `dispatchServerStop`, and the plugin-mgr update/reload routes).
106
+ *
107
+ * The argument is OPTIONAL: the agent omits it when it removes a plugin and on
108
+ * some stop paths, so a plugin must treat `undefined` as "reason unknown" and
109
+ * tear down safely. It is NOT `HostServices` — earlier SDK releases declared
110
+ * that, but the agent has never passed host services here.
111
+ */
112
+ interface PluginStopContext {
113
+ reason: PluginStopReason;
114
+ }
88
115
  interface StorageProvider {
89
116
  get<T = unknown>(namespace: string, key: string): Promise<T | null>;
90
117
  set<T = unknown>(namespace: string, key: string, value: T): Promise<void>;
@@ -390,7 +417,11 @@ interface VibePlugin {
390
417
  * work (queue processors, watchers) or register context providers.
391
418
  */
392
419
  onServerReady?: (app: unknown, hostServices: HostServices) => void | Promise<void>;
393
- onServerStop?: (hostServices: HostServices) => void | Promise<void>;
420
+ /**
421
+ * Stop hook. Receives a `PluginStopContext` (or `undefined`), never
422
+ * `HostServices` — capture any host services you need in `onServerStart`.
423
+ */
424
+ onServerStop?: (context?: PluginStopContext) => void | Promise<void>;
394
425
  /**
395
426
  * Nuke lifecycle. The agent invokes this on `vibe nuke` BEFORE the plugin
396
427
  * package is uninstalled, while the daemon is still running, so the plugin
@@ -407,4 +438,4 @@ interface VibePlugin {
407
438
  onCliSetup?: (program: unknown, hostServices: HostServices) => void;
408
439
  }
409
440
  type VibePluginFactory = (ctx: ProfileContext) => VibePlugin;
410
- export { SupportedOS as _, MetaProviderRef as a, PluginNukeContext as c, PrerequisiteKind as d, ProfileContext as f, StorageProvider as g, ServiceRegistry as h, IframeBridge as i, PluginTag as l, SdkLogger as m, HostPlugins as n, NukeResult as o, ProviderType as p, HostServices as r, PluginCapabilities as s, FULL_TRUST_CAPS as t, Prerequisite as u, VibePlugin as v, VibePluginFactory as y };
441
+ export { VibePluginFactory as S, SdkLogger as _, MetaProviderRef as a, SupportedOS as b, PluginCapabilities as c, PluginStopReason as d, PluginTag as f, ProviderType as g, ProfileContext as h, IframeBridge as i, PluginNukeContext as l, PrerequisiteKind as m, HostPlugins as n, NukeResult as o, Prerequisite as p, HostServices as r, PROVIDER_TYPES as s, FULL_TRUST_CAPS as t, PluginStopContext as u, ServiceRegistry as v, VibePlugin as x, StorageProvider as y };
package/dist/index.d.ts CHANGED
@@ -25,13 +25,13 @@
25
25
  * Subpath imports (`@vibecontrols/plugin-sdk/cli`, etc.) remain available
26
26
  * for tighter tree-shaking on big plugins.
27
27
  */
28
- import { _ as SupportedOS, a as MetaProviderRef, c as PluginNukeContext, d as PrerequisiteKind, f as ProfileContext, g as StorageProvider, h as ServiceRegistry, l as PluginTag, m as SdkLogger, n as HostPlugins, o as NukeResult, p as ProviderType, r as HostServices, s as PluginCapabilities, t as FULL_TRUST_CAPS, u as Prerequisite, v as VibePlugin, y as VibePluginFactory } from "./index-D946chPf.js";
28
+ import { S as VibePluginFactory, _ as SdkLogger, a as MetaProviderRef, b as SupportedOS, c as PluginCapabilities, d as PluginStopReason, f as PluginTag, g as ProviderType, h as ProfileContext, l as PluginNukeContext, m as PrerequisiteKind, n as HostPlugins, o as NukeResult, p as Prerequisite, r as HostServices, s as PROVIDER_TYPES, t as FULL_TRUST_CAPS, u as PluginStopContext, v as ServiceRegistry, x as VibePlugin, y as StorageProvider } from "./index-DumrPKY-.js";
29
29
  import { LifecycleHooks, LifecycleSpec, createLifecycleHooks } from "./lifecycle/index.js";
30
30
  import { a as OutputFlags, c as pickOutputMode, i as MultimodeOptions, l as runMultimode, n as StatusCommandSpec, o as OutputMode, r as redact, s as maybePrintJson, t as CliCommandBuilder } from "./index-Q_hnxaN_.js";
31
- import { ApiKeyResolver, RoutesBuilder } from "./routes/index.js";
31
+ import { AGENT_API_KEY_HEADER, ApiKeyResolver, RoutesBuilder, apiKeyFromRequest } from "./routes/index.js";
32
32
  import { TelemetryEmitter } from "./telemetry/index.js";
33
33
  import { BoundLogger } from "./log/index.js";
34
- import { n as TypedStore, t as NamespaceStore } from "./index-BM4zNXSR.js";
34
+ import { n as TypedStore, t as NamespaceStore } from "./index-1rZQqkq7.js";
35
35
  import { ConfigManager } from "./config/index.js";
36
36
  import { findAvailablePort, gracefulKill, isProcessAlive, sleep } from "./subprocess/index.js";
37
37
  import { HttpClient, HttpClientOptions, RequestOptions } from "./http/index.js";
@@ -41,4 +41,4 @@ import { AuditLogger } from "./audit/index.js";
41
41
  import { BroadcastEmitter } from "./broadcast/index.js";
42
42
  import { a as platformLabel, i as manualInstallHint, n as PlatformLabel, r as SupportedPlatform, t as OsAdapter } from "./os-DoFa9kjr.js";
43
43
  import { n as paths, t as PathHelpers } from "./paths-h28H4Xeb.js";
44
- export { type ApiKeyResolver, AuditLogger, BoundLogger, BroadcastEmitter, CONTEXT_PROVIDER_TYPE, CliCommandBuilder, type CliContribution, ConfigManager, type ContextContribution, type ContextProvider, type ContextRequest, FULL_TRUST_CAPS, type HostPlugins, type HostServices, HttpClient, type HttpClientOptions, type LifecycleHooks, type LifecycleSpec, type MetaProviderRef, type MultimodeOptions, NamespaceStore, type NukeResult, type OsAdapter, type OutputFlags, type OutputMode, type PathHelpers, type PlatformLabel, type PluginCapabilities, type PluginNukeContext, type PluginTag, type Prerequisite, type PrerequisiteKind, type ProfileContext, ProviderRegistry, type ProviderType, type RequestOptions, RoutesBuilder, type SdkLogger, type ServiceRegistry, type StatusCommandSpec, type StorageProvider, type SupportedOS, type SupportedPlatform, TelemetryEmitter, TypedStore, type VibePlugin, type VibePluginFactory, createLifecycleHooks, currentSupportedOS, findAvailablePort, getContextProvider, gracefulKill, isProcessAlive, listContextProviders, manualInstallHint, maybePrintJson, paths, pickOutputMode, platformLabel, provisionMetaProviders, redact, registerContextProvider, runMultimode, sleep };
44
+ export { AGENT_API_KEY_HEADER, type ApiKeyResolver, AuditLogger, BoundLogger, BroadcastEmitter, CONTEXT_PROVIDER_TYPE, CliCommandBuilder, type CliContribution, ConfigManager, type ContextContribution, type ContextProvider, type ContextRequest, FULL_TRUST_CAPS, type HostPlugins, type HostServices, HttpClient, type HttpClientOptions, type LifecycleHooks, type LifecycleSpec, type MetaProviderRef, type MultimodeOptions, NamespaceStore, type NukeResult, type OsAdapter, type OutputFlags, type OutputMode, PROVIDER_TYPES, type PathHelpers, type PlatformLabel, type PluginCapabilities, type PluginNukeContext, type PluginStopContext, type PluginStopReason, type PluginTag, type Prerequisite, type PrerequisiteKind, type ProfileContext, ProviderRegistry, type ProviderType, type RequestOptions, RoutesBuilder, type SdkLogger, type ServiceRegistry, type StatusCommandSpec, type StorageProvider, type SupportedOS, type SupportedPlatform, TelemetryEmitter, TypedStore, type VibePlugin, type VibePluginFactory, apiKeyFromRequest, createLifecycleHooks, currentSupportedOS, findAvailablePort, getContextProvider, gracefulKill, isProcessAlive, listContextProviders, manualInstallHint, maybePrintJson, paths, pickOutputMode, platformLabel, provisionMetaProviders, redact, registerContextProvider, runMultimode, sleep };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { FULL_TRUST_CAPS } from "./contract/index.js";
1
+ import { FULL_TRUST_CAPS, PROVIDER_TYPES } from "./contract/index.js";
2
2
  import { createLifecycleHooks } from "./lifecycle/index.js";
3
3
  import { a as runMultimode, i as pickOutputMode, n as redact, r as maybePrintJson, t as CliCommandBuilder } from "./cli-CGyu31Cn.js";
4
- import { RoutesBuilder } from "./routes/index.js";
4
+ import { AGENT_API_KEY_HEADER, RoutesBuilder, apiKeyFromRequest } from "./routes/index.js";
5
5
  import { TelemetryEmitter } from "./telemetry/index.js";
6
6
  import { BoundLogger } from "./log/index.js";
7
7
  import { n as TypedStore, t as NamespaceStore } from "./storage-DkNBaJHC.js";
@@ -14,4 +14,4 @@ import { AuditLogger } from "./audit/index.js";
14
14
  import { BroadcastEmitter } from "./broadcast/index.js";
15
15
  import { manualInstallHint, platformLabel } from "./host/os.js";
16
16
  import { paths } from "./host/paths.js";
17
- export { AuditLogger, BoundLogger, BroadcastEmitter, CONTEXT_PROVIDER_TYPE, CliCommandBuilder, ConfigManager, FULL_TRUST_CAPS, HttpClient, NamespaceStore, ProviderRegistry, RoutesBuilder, TelemetryEmitter, TypedStore, createLifecycleHooks, currentSupportedOS, findAvailablePort, getContextProvider, gracefulKill, isProcessAlive, listContextProviders, manualInstallHint, maybePrintJson, paths, pickOutputMode, platformLabel, provisionMetaProviders, redact, registerContextProvider, runMultimode, sleep };
17
+ export { AGENT_API_KEY_HEADER, AuditLogger, BoundLogger, BroadcastEmitter, CONTEXT_PROVIDER_TYPE, CliCommandBuilder, ConfigManager, FULL_TRUST_CAPS, HttpClient, NamespaceStore, PROVIDER_TYPES, ProviderRegistry, RoutesBuilder, TelemetryEmitter, TypedStore, apiKeyFromRequest, createLifecycleHooks, currentSupportedOS, findAvailablePort, getContextProvider, gracefulKill, isProcessAlive, listContextProviders, manualInstallHint, maybePrintJson, paths, pickOutputMode, platformLabel, provisionMetaProviders, redact, registerContextProvider, runMultimode, sleep };
@@ -1,7 +1,7 @@
1
+ import { createHash } from "node:crypto";
1
2
  import { homedir, tmpdir } from "node:os";
2
3
  import * as path$1 from "node:path";
3
4
  import { spawn } from "node:child_process";
4
- import { createHash } from "node:crypto";
5
5
  import { createWriteStream, existsSync, promises } from "node:fs";
6
6
  import { Readable } from "node:stream";
7
7
  import { pipeline } from "node:stream/promises";
@@ -7,14 +7,20 @@
7
7
  *
8
8
  * Cross-platform: pure JS, no fs / spawn.
9
9
  */
10
- import { c as PluginNukeContext, o as NukeResult, r as HostServices } from "../index-D946chPf.js";
10
+ import { l as PluginNukeContext, o as NukeResult, r as HostServices, u as PluginStopContext } from "../index-DumrPKY-.js";
11
11
  export interface LifecycleSpec {
12
12
  /** Plugin name — used for telemetry tagging + skip log messages. */
13
13
  name: string;
14
14
  /** Optional init handler — called with hostServices on onServerStart. */
15
15
  onInit?: (hostServices: HostServices) => void | Promise<void>;
16
- /** Optional shutdown handler — called with hostServices on onServerStop. */
17
- onShutdown?: (hostServices: HostServices) => void | Promise<void>;
16
+ /**
17
+ * Optional shutdown handler — called on onServerStop with the agent's stop
18
+ * context (`{ reason: "reload" | "shutdown" }`, or `undefined` when the agent
19
+ * gives no reason). It does NOT receive HostServices; capture what you need
20
+ * in `onInit`. Use `context?.reason === "reload"` to keep long-lived state
21
+ * across a hot reload.
22
+ */
23
+ onShutdown?: (context?: PluginStopContext) => void | Promise<void>;
18
24
  /**
19
25
  * Optional nuke handler — called with hostServices + ctx on `vibe nuke`,
20
26
  * BEFORE the plugin is uninstalled and while the daemon is still up. Use it
@@ -29,7 +35,7 @@ export interface LifecycleSpec {
29
35
  }
30
36
  export interface LifecycleHooks {
31
37
  onServerStart: (app: unknown, hostServices: HostServices) => Promise<void>;
32
- onServerStop: (hostServices: HostServices) => Promise<void>;
38
+ onServerStop: (context?: PluginStopContext) => Promise<void>;
33
39
  onNuke: (hostServices: HostServices, ctx: PluginNukeContext) => Promise<void | NukeResult>;
34
40
  }
35
41
  export declare function createLifecycleHooks(spec: LifecycleSpec): LifecycleHooks;
@@ -10,8 +10,8 @@ function createLifecycleHooks(spec) {
10
10
  if (onInit) await onInit(hostServices);
11
11
  if (telemetryEventName) hostServices.telemetry?.emit(telemetryEventName, { plugin: name });
12
12
  },
13
- onServerStop: async (hostServices) => {
14
- if (onShutdown) await onShutdown(hostServices);
13
+ onServerStop: async (context) => {
14
+ if (onShutdown) await onShutdown(context);
15
15
  },
16
16
  onNuke: async (hostServices, ctx) => {
17
17
  if (onNuke) return onNuke(hostServices, ctx);
@@ -5,7 +5,7 @@
5
5
  * `log.info("started")` instead of `logger.info("my-plugin", "started")`
6
6
  * at every call-site. No-op when the underlying logger is absent.
7
7
  */
8
- import { m as SdkLogger } from "../index-D946chPf.js";
8
+ import { _ as SdkLogger } from "../index-DumrPKY-.js";
9
9
  type Meta = Record<string, unknown>;
10
10
  export declare class BoundLogger {
11
11
  private readonly logger;
@@ -5,7 +5,7 @@
5
5
  * `register` and consumer plugins call `get` / `list`. Every method is a
6
6
  * graceful no-op when the host has no registry.
7
7
  */
8
- import { _ as SupportedOS, a as MetaProviderRef, h as ServiceRegistry, r as HostServices } from "../index-D946chPf.js";
8
+ import { a as MetaProviderRef, b as SupportedOS, r as HostServices, v as ServiceRegistry } from "../index-DumrPKY-.js";
9
9
  import { ContextProvider } from "../context/index.js";
10
10
  export interface CliContribution {
11
11
  statusSections?: unknown[];
@@ -9,9 +9,23 @@
9
9
  * If a plugin doesn't ship HTTP routes it never imports this module so
10
10
  * elysia stays an optional peer.
11
11
  */
12
- import { r as HostServices } from "../index-D946chPf.js";
12
+ import { r as HostServices } from "../index-DumrPKY-.js";
13
13
  import { Elysia } from "elysia";
14
14
  export type ApiKeyResolver = () => string | Promise<string>;
15
+ /**
16
+ * Header the agent authenticates REST and WebSocket clients with
17
+ * (vibecontrols-agent/src/middleware/auth.ts `getApiKeyFromHeaders`).
18
+ * `withAuth` accepts exactly what the agent accepts — this header, or
19
+ * `Authorization: Bearer <key>` — so a plugin route never rejects a request
20
+ * the agent itself would let through, or vice versa.
21
+ */
22
+ export declare const AGENT_API_KEY_HEADER = "x-agent-api-key";
23
+ /**
24
+ * Extract the API key from a request the same way the agent does: the
25
+ * `x-agent-api-key` header first, then an `Authorization: Bearer` token.
26
+ * Returns null when neither is present. Query-string keys are never read.
27
+ */
28
+ export declare function apiKeyFromRequest(request: Request): string | null;
15
29
  export declare class RoutesBuilder {
16
30
  private readonly pluginName;
17
31
  private readonly hostServices?;
@@ -1,3 +1,4 @@
1
+ import { timingSafeEqual } from "node:crypto";
1
2
  import { Elysia } from "elysia";
2
3
  // src/routes/index.ts
3
4
  /**
@@ -11,6 +12,35 @@ import { Elysia } from "elysia";
11
12
  * If a plugin doesn't ship HTTP routes it never imports this module so
12
13
  * elysia stays an optional peer.
13
14
  */
15
+ /**
16
+ * Header the agent authenticates REST and WebSocket clients with
17
+ * (vibecontrols-agent/src/middleware/auth.ts `getApiKeyFromHeaders`).
18
+ * `withAuth` accepts exactly what the agent accepts — this header, or
19
+ * `Authorization: Bearer <key>` — so a plugin route never rejects a request
20
+ * the agent itself would let through, or vice versa.
21
+ */
22
+ const AGENT_API_KEY_HEADER = "x-agent-api-key";
23
+ /**
24
+ * Extract the API key from a request the same way the agent does: the
25
+ * `x-agent-api-key` header first, then an `Authorization: Bearer` token.
26
+ * Returns null when neither is present. Query-string keys are never read.
27
+ */
28
+ function apiKeyFromRequest(request) {
29
+ const headerKey = request.headers.get(AGENT_API_KEY_HEADER);
30
+ if (headerKey) return headerKey;
31
+ const auth = request.headers.get("authorization");
32
+ if (auth?.startsWith("Bearer ")) {
33
+ const token = auth.slice(7);
34
+ return token.length > 0 ? token : null;
35
+ }
36
+ return null;
37
+ }
38
+ function constantTimeEqual(a, b) {
39
+ const left = Buffer.from(a, "utf8");
40
+ const right = Buffer.from(b, "utf8");
41
+ if (left.length !== right.length) return false;
42
+ return timingSafeEqual(left, right);
43
+ }
14
44
  var RoutesBuilder = class {
15
45
  pluginName;
16
46
  hostServices;
@@ -49,9 +79,9 @@ var RoutesBuilder = class {
49
79
  if (this.apiKeyResolver) {
50
80
  const resolver = this.apiKeyResolver;
51
81
  app.onBeforeHandle(async ({ request, set }) => {
52
- const supplied = request.headers.get("x-api-key");
82
+ const supplied = apiKeyFromRequest(request);
53
83
  const expected = await resolver();
54
- if (!supplied || supplied !== expected) {
84
+ if (!supplied || !expected || !constantTimeEqual(supplied, expected)) {
55
85
  set.status = 401;
56
86
  return { error: "unauthorized" };
57
87
  }
@@ -80,6 +110,6 @@ var RoutesBuilder = class {
80
110
  return app;
81
111
  }
82
112
  };
83
- export { RoutesBuilder };
113
+ export { AGENT_API_KEY_HEADER, RoutesBuilder, apiKeyFromRequest };
84
114
 
85
115
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
- import { n as TypedStore, t as NamespaceStore } from "../index-BM4zNXSR.js";
1
+ import { n as TypedStore, t as NamespaceStore } from "../index-1rZQqkq7.js";
2
2
  export { NamespaceStore, TypedStore };
@@ -13,7 +13,7 @@
13
13
  *
14
14
  * Cross-platform: pure Node + optional Bun runtime feature detection.
15
15
  */
16
- import { m as SdkLogger } from "../index-D946chPf.js";
16
+ import { _ as SdkLogger } from "../index-DumrPKY-.js";
17
17
  export declare function sleep(ms: number): Promise<void>;
18
18
  /**
19
19
  * Returns true if a process with `pid` is reachable from this process.
@@ -6,7 +6,7 @@
6
6
  * No-op when the host doesn't expose the telemetry surface (e.g. plugin
7
7
  * loaded without the `telemetry: true` capability).
8
8
  */
9
- import { r as HostServices } from "../index-D946chPf.js";
9
+ import { r as HostServices } from "../index-DumrPKY-.js";
10
10
  export declare class TelemetryEmitter {
11
11
  private readonly pluginName;
12
12
  private readonly pluginVersion;
@@ -1,4 +1,4 @@
1
- import { f as ProfileContext, r as HostServices, y as VibePluginFactory } from "../index-D946chPf.js";
1
+ import { S as VibePluginFactory, h as ProfileContext, r as HostServices } from "../index-DumrPKY-.js";
2
2
  type DeepPartial<T> = T extends object ? { [K in keyof T]?: DeepPartial<T[K]>; } : T;
3
3
  /**
4
4
  * Build a fully-stubbed `HostServices`. Every function is a Bun `mock()`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibecontrols/plugin-sdk",
3
- "version": "2026.1123.1",
3
+ "version": "2026.1124.1",
4
4
  "type": "module",
5
5
  "description": "VibeControls Plugin SDK — shared contract, lifecycle, CLI, telemetry, storage helpers for all vibe-plugin-* packages.",
6
6
  "engines": {