@omercnet/paseo-context-mode 1.2.3-next.233.1 → 1.2.3

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/index.server.ts CHANGED
@@ -3,11 +3,7 @@ import { createContextModeActionHandlers } from "./server/actions";
3
3
  import { createContextModeAnalyticsHandler } from "./server/analytics";
4
4
  import { resolveContextModeBinary } from "./server/binary";
5
5
  import { createContextModeHandlers } from "./server/handlers";
6
- import {
7
- injectContextModeEnvironment,
8
- injectContextModeOnCreate,
9
- readProviderOverrides,
10
- } from "./server/integration";
6
+ import { injectContextModeEnvironment, injectContextModeOnCreate } from "./server/integration";
11
7
  import { createContextModeKnowledgeHandlers } from "./server/knowledge";
12
8
  import {
13
9
  contextModeSettings,
@@ -42,19 +38,17 @@ export default function contribute(server: PluginServerContext) {
42
38
  server.handle(getContextModeDoctorReport, actionHandlers.doctor);
43
39
  server.handle(getContextModeInstallAction, actionHandlers.install);
44
40
  server.handle(getContextModeUpgradeAction, actionHandlers.upgrade);
45
- server.before("agent.create", async ({ request }, { paseo }) => {
41
+ server.before("agent.create", async ({ request }) => {
46
42
  const current = await settings.read();
47
43
  if (current.status !== "ready") return request;
48
44
  const binary = await resolveContextModeBinary(current.values);
49
45
  if (binary.state !== "found") return request;
50
- const providers = await readProviderOverrides(paseo);
51
- return injectContextModeOnCreate(request, current.values, binary.launch, { providers });
46
+ return injectContextModeOnCreate(request, current.values, binary.launch);
52
47
  });
53
- server.before("agent.session_open", async ({ request }, { paseo }) => {
48
+ server.before("agent.session_open", async ({ request }) => {
54
49
  const current = await settings.read();
55
50
  if (current.status !== "ready") return request;
56
- const providers = await readProviderOverrides(paseo);
57
- return injectContextModeEnvironment(request, current.values, { providers });
51
+ return injectContextModeEnvironment(request, current.values);
58
52
  });
59
53
  return () => {};
60
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omercnet/paseo-context-mode",
3
- "version": "1.2.3-next.233.1",
3
+ "version": "1.2.3",
4
4
  "type": "module",
5
5
  "description": "Provider-aware Context Mode health, savings, and MCP activation for Paseo.",
6
6
  "license": "MIT",
@@ -8,12 +8,7 @@ import type {
8
8
  IntegrationAudit,
9
9
  } from "../shared";
10
10
  import { type BinaryResolution, type LaunchDescriptor, resolveContextModeBinary } from "./binary";
11
- import {
12
- createIntegrationAudit,
13
- type IntegrationDependencies,
14
- type ProviderConfigSource,
15
- readProviderOverrides,
16
- } from "./integration";
11
+ import { createIntegrationAudit } from "./integration";
17
12
  import {
18
13
  callContextModeTool,
19
14
  inspectContextMode,
@@ -33,7 +28,6 @@ export interface ContextModeHandlerDependencies {
33
28
  createAudit?: (
34
29
  settings: ContextModeSettings,
35
30
  runtime: { path: string; version: string | null },
36
- dependencies?: IntegrationDependencies,
37
31
  ) => Promise<IntegrationAudit>;
38
32
  }
39
33
 
@@ -41,10 +35,7 @@ export interface ContextModeHandlers {
41
35
  status(input: ContextModeRefreshInput): Promise<BinaryStatus>;
42
36
  doctor(input: ContextModeRefreshInput): Promise<CommandReport>;
43
37
  stats(input: ContextModeRefreshInput): Promise<CommandReport>;
44
- audit(
45
- input: ContextModeRefreshInput,
46
- context?: { paseo?: ProviderConfigSource },
47
- ): Promise<IntegrationAudit>;
38
+ audit(input: ContextModeRefreshInput): Promise<IntegrationAudit>;
48
39
  }
49
40
 
50
41
  interface CacheEntry<T> {
@@ -179,10 +170,7 @@ export function createContextModeHandlers(
179
170
  });
180
171
  }
181
172
 
182
- async function audit(
183
- _input: ContextModeRefreshInput,
184
- context?: { paseo?: ProviderConfigSource },
185
- ): Promise<IntegrationAudit> {
173
+ async function audit(_input: ContextModeRefreshInput): Promise<IntegrationAudit> {
186
174
  const resolved = await settingsAndBinary();
187
175
  if (resolved.state === "unavailable") {
188
176
  return {
@@ -197,11 +185,10 @@ export function createContextModeHandlers(
197
185
  version: null,
198
186
  tools: [],
199
187
  }));
200
- return buildAudit(
201
- resolved.settings,
202
- { path: resolved.binary.path, version: inspection.version },
203
- { providers: await readProviderOverrides(context?.paseo) },
204
- );
188
+ return buildAudit(resolved.settings, {
189
+ path: resolved.binary.path,
190
+ version: inspection.version,
191
+ });
205
192
  }
206
193
 
207
194
  return {
@@ -54,52 +54,6 @@ export interface IntegrationDependencies {
54
54
  fileContains?: (path: string, text: string) => Promise<boolean>;
55
55
  now?: () => Date;
56
56
  env?: NodeJS.ProcessEnv;
57
- providers?: ProviderOverrides;
58
- }
59
-
60
- export type ProviderOverrides = Readonly<
61
- Record<string, { extends?: string; env?: Readonly<Record<string, string>> }>
62
- >;
63
-
64
- /** Structural slice of the hook/RPC `paseo` API; avoids a client-package import. */
65
- export interface ProviderConfigSource {
66
- config: { get(): Promise<{ config: { providers?: unknown } }> };
67
- }
68
-
69
- /**
70
- * Reads `agents.providers` from the daemon. Paseo applies a provider's own `env` and `extends`
71
- * after the `agent.create` hook runs, so the hooks must look them up to find the right storage.
72
- * Failures degrade to "no overrides" (canonical provider behavior).
73
- */
74
- export async function readProviderOverrides(
75
- paseo: ProviderConfigSource | undefined,
76
- ): Promise<ProviderOverrides> {
77
- try {
78
- const { config } = (await paseo?.config.get()) ?? {};
79
- const entries: Array<[string, { extends?: string; env?: Record<string, string> }]> = [];
80
- for (const [id, value] of Object.entries(config?.providers ?? {})) {
81
- if (typeof value !== "object" || value === null) continue;
82
- const { extends: parent, env } = value as { extends?: unknown; env?: unknown };
83
- entries.push([
84
- id,
85
- {
86
- ...(typeof parent === "string" ? { extends: parent } : {}),
87
- ...(typeof env === "object" && env !== null && !Array.isArray(env)
88
- ? {
89
- env: Object.fromEntries(
90
- Object.entries(env).filter(
91
- (entry): entry is [string, string] => typeof entry[1] === "string",
92
- ),
93
- ),
94
- }
95
- : {}),
96
- },
97
- ]);
98
- }
99
- return Object.fromEntries(entries);
100
- } catch {
101
- return {};
102
- }
103
57
  }
104
58
 
105
59
  export interface ContextModeStorageOptions {
@@ -287,23 +241,7 @@ const PROVIDER_POLICIES: Readonly<Record<Exclude<AuditedProvider, "omp-plugin">,
287
241
 
288
242
  function providerPolicy(provider: string): ProviderPolicy | null {
289
243
  if (provider === "omp-plugin" || provider.startsWith("omp-plugin-")) return OMP_POLICY;
290
- return Object.hasOwn(PROVIDER_POLICIES, provider)
291
- ? PROVIDER_POLICIES[provider as keyof typeof PROVIDER_POLICIES]
292
- : null;
293
- }
294
-
295
- /**
296
- * Mirrors Paseo's single-level `extends`: a derived provider uses its parent's policy, and its
297
- * effective env is the parent's override env overlaid with its own.
298
- */
299
- function resolveProvider(
300
- id: string,
301
- providers: ProviderOverrides = {},
302
- ): { base: string; policy: ProviderPolicy | null; env: Record<string, string> } {
303
- const own = Object.hasOwn(providers, id) ? providers[id] : undefined;
304
- const base = own?.extends ?? id;
305
- const parent = base !== id && Object.hasOwn(providers, base) ? providers[base] : undefined;
306
- return { base, policy: providerPolicy(base), env: { ...parent?.env, ...own?.env } };
244
+ return PROVIDER_POLICIES[provider as keyof typeof PROVIDER_POLICIES] ?? null;
307
245
  }
308
246
 
309
247
  async function defaultPathExists(path: string): Promise<boolean> {
@@ -384,40 +322,24 @@ export async function createIntegrationAudit(
384
322
  const pathExists = dependencies.pathExists ?? defaultPathExists;
385
323
  const fileContains = dependencies.fileContains ?? defaultFileContains;
386
324
  const hostEnvironment = dependencies.env ?? process.env;
387
- const nativeByPolicy = new Map<string, Promise<boolean>>();
388
- const detectNative = (
389
- policy: ProviderPolicy,
390
- env: Readonly<Record<string, string | undefined>>,
391
- key: string,
392
- ) => {
393
- const cacheKey = `${policy.platform}\0${key}`;
394
- const existing = nativeByPolicy.get(cacheKey);
325
+ const context = providerContext(home, undefined, hostEnvironment);
326
+ const nativeByPolicy = new Map<ProviderPolicy, Promise<boolean>>();
327
+ const detectNative = (policy: ProviderPolicy) => {
328
+ const existing = nativeByPolicy.get(policy);
395
329
  if (existing) return existing;
396
- const detected = nativeIntegrationDetected(
397
- policy,
398
- providerContext(home, undefined, env),
399
- pathExists,
400
- fileContains,
401
- );
402
- nativeByPolicy.set(cacheKey, detected);
330
+ const detected = nativeIntegrationDetected(policy, context, pathExists, fileContains);
331
+ nativeByPolicy.set(policy, detected);
403
332
  return detected;
404
333
  };
405
- const configured = dependencies.providers ?? {};
406
- const derived = Object.keys(configured).filter(
407
- (id) => !(AUDITED_PROVIDERS as readonly string[]).includes(id),
408
- );
409
334
  const providers: ProviderIntegration[] = [];
410
- for (const provider of [...AUDITED_PROVIDERS, ...derived]) {
411
- const { base, policy, env: providerEnv } = resolveProvider(provider, configured);
335
+ for (const provider of AUDITED_PROVIDERS) {
336
+ const policy = providerPolicy(provider);
412
337
  if (!policy) continue;
413
- const env = { ...hostEnvironment, ...providerEnv };
414
- const storageRoot = contextModeStorageRootFor(base, { home, env });
338
+ const storageRoot = contextModeStorageRootFor(provider, { home, env: hostEnvironment });
415
339
  if (!storageRoot) continue;
416
340
  const reusesExistingStorage = await pathExists(storageRoot);
417
341
  const native =
418
- settings.autoInject &&
419
- settings.preferNativeIntegrations &&
420
- (await detectNative(policy, env, JSON.stringify(providerEnv)));
342
+ settings.autoInject && settings.preferNativeIntegrations && (await detectNative(policy));
421
343
  const activation = !settings.autoInject ? "disabled" : native ? "native" : "mcp";
422
344
  providers.push({
423
345
  provider,
@@ -455,35 +377,34 @@ export async function injectContextModeOnCreate<T extends CreateRequest>(
455
377
  ) {
456
378
  return request;
457
379
  }
458
- const {
459
- base,
460
- policy,
461
- env: providerEnv,
462
- } = resolveProvider(request.config.provider, dependencies.providers);
380
+ const policy = providerPolicy(request.config.provider);
463
381
  if (!policy) return request;
464
382
  const home = dependencies.home ?? homedir();
465
383
  const hostEnvironment = dependencies.env ?? process.env;
466
384
  const pathExists = dependencies.pathExists ?? defaultPathExists;
467
385
  const fileContains = dependencies.fileContains ?? defaultFileContains;
468
- const env = { ...hostEnvironment, ...providerEnv, ...request.env };
386
+ const context = providerContext(home, request.config.cwd, {
387
+ ...hostEnvironment,
388
+ ...request.env,
389
+ });
469
390
  if (
470
391
  settings.preferNativeIntegrations &&
471
- (await nativeIntegrationDetected(
472
- policy,
473
- providerContext(home, request.config.cwd, env),
474
- pathExists,
475
- fileContains,
476
- ))
392
+ (await nativeIntegrationDetected(policy, context, pathExists, fileContains))
477
393
  ) {
478
394
  return request;
479
395
  }
480
- const storageRoot = contextModeStorageRootFor(base, { home, cwd: request.config.cwd, env });
396
+ const storageRoot = contextModeStorageRootFor(request.config.provider, {
397
+ home,
398
+ cwd: request.config.cwd,
399
+ env: { ...hostEnvironment, ...request.env },
400
+ });
481
401
  if (!storageRoot) return request;
402
+ const env = serverEnvironment(policy, storageRoot, request.env);
482
403
  const server: McpServer = {
483
404
  type: "stdio",
484
405
  command: launch.program,
485
406
  args: launch.args,
486
- env: serverEnvironment(policy, storageRoot, request.env),
407
+ env,
487
408
  };
488
409
  return {
489
410
  ...request,
@@ -500,18 +421,14 @@ export async function injectContextModeEnvironment<T extends SessionOpenRequest>
500
421
  dependencies: IntegrationDependencies = {},
501
422
  ): Promise<T> {
502
423
  if (!settings.autoInject) return request;
503
- const {
504
- base,
505
- policy,
506
- env: providerEnv,
507
- } = resolveProvider(request.provider, dependencies.providers);
424
+ const policy = providerPolicy(request.provider);
508
425
  if (!policy) return request;
509
426
  const home = dependencies.home ?? homedir();
510
427
  const hostEnvironment = dependencies.env ?? process.env;
511
- const storageRoot = contextModeStorageRootFor(base, {
428
+ const storageRoot = contextModeStorageRootFor(request.provider, {
512
429
  home,
513
430
  cwd: request.cwd,
514
- env: { ...hostEnvironment, ...providerEnv, ...request.env },
431
+ env: { ...hostEnvironment, ...request.env },
515
432
  });
516
433
  if (!storageRoot) return request;
517
434
  return {