replicas-engine 0.1.744 → 0.1.745

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.
@@ -0,0 +1,371 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ createToolSelectorCandidateIndex,
4
+ extractToolUiStreamMode,
5
+ formatPromptCommandName,
6
+ formatToolName,
7
+ getAgentPath,
8
+ getToolNameCandidates,
9
+ interpolateEnvRecord,
10
+ interpolateEnvVars,
11
+ isServerDisabled,
12
+ isToolAllowed,
13
+ resolveBearerToken,
14
+ resolveConfigPath,
15
+ resolveServerUrl,
16
+ resolveToolPrefix
17
+ } from "./chunk-NZRMKTVA.js";
18
+
19
+ // ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/resource-tools.ts
20
+ function resourceNameToToolName(name) {
21
+ let result = name.replace(/[^a-zA-Z0-9]/g, "_").replace(/_+/g, "_").replace(/^_+/, "").replace(/_+$/, "").toLowerCase();
22
+ if (!result || /^\d/.test(result)) {
23
+ result = "resource" + (result ? "_" + result : "");
24
+ }
25
+ return result;
26
+ }
27
+
28
+ // ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/ui-tool-visibility.ts
29
+ function extractUiToolVisibility(meta) {
30
+ if (!meta || typeof meta !== "object") return void 0;
31
+ const ui = meta.ui;
32
+ if (!ui || typeof ui !== "object" || Array.isArray(ui)) return void 0;
33
+ const visibility = ui.visibility;
34
+ if (visibility === void 0) return void 0;
35
+ if (!Array.isArray(visibility)) return [];
36
+ const values = [];
37
+ for (const entry of visibility) {
38
+ if (entry !== "model" && entry !== "app") return [];
39
+ if (!values.includes(entry)) values.push(entry);
40
+ }
41
+ return values;
42
+ }
43
+ function isUiToolVisibleToModel(visibility) {
44
+ return visibility === void 0 || visibility.includes("model");
45
+ }
46
+ function isUiToolCallableByApp(visibility) {
47
+ return visibility === void 0 || visibility.includes("app");
48
+ }
49
+
50
+ // ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/metadata-cache.ts
51
+ import { existsSync, readFileSync, writeFileSync, renameSync, mkdirSync } from "fs";
52
+ import { dirname } from "path";
53
+ import { createHash } from "crypto";
54
+
55
+ // ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/ui-app-bridge-helpers.ts
56
+ var RESOURCE_MIME_TYPE = "text/html;profile=mcp-app";
57
+ var RESOURCE_URI_META_KEY = "ui/resourceUri";
58
+ function getToolUiResourceUri(tool) {
59
+ const meta = tool._meta;
60
+ let resourceUri = getNestedResourceUri(meta);
61
+ if (resourceUri === void 0) {
62
+ resourceUri = meta?.[RESOURCE_URI_META_KEY];
63
+ }
64
+ if (typeof resourceUri === "string" && resourceUri.startsWith("ui://")) {
65
+ return resourceUri;
66
+ }
67
+ if (resourceUri !== void 0) {
68
+ throw new Error(`Invalid UI resource URI: ${JSON.stringify(resourceUri)}`);
69
+ }
70
+ return void 0;
71
+ }
72
+ function buildAllowAttribute(permissions) {
73
+ if (!permissions) return "";
74
+ const allowed = [];
75
+ if (permissions.camera) allowed.push("camera");
76
+ if (permissions.microphone) allowed.push("microphone");
77
+ if (permissions.geolocation) allowed.push("geolocation");
78
+ if (permissions.clipboardWrite) allowed.push("clipboard-write");
79
+ return allowed.join("; ");
80
+ }
81
+ function getNestedResourceUri(meta) {
82
+ const ui = meta?.ui;
83
+ if (!ui || typeof ui !== "object") return void 0;
84
+ return ui.resourceUri;
85
+ }
86
+
87
+ // ../node_modules/.bun/pi-mcp-adapter@2.32.1+04b0d7b0bc944965/node_modules/pi-mcp-adapter/metadata-cache.ts
88
+ var CACHE_VERSION = 1;
89
+ var CACHE_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1e3;
90
+ function getMetadataCachePath() {
91
+ return getAgentPath("mcp-cache.json");
92
+ }
93
+ function loadMetadataCache() {
94
+ const cachePath = getMetadataCachePath();
95
+ if (!existsSync(cachePath)) return null;
96
+ try {
97
+ const raw = JSON.parse(readFileSync(cachePath, "utf-8"));
98
+ if (!raw || typeof raw !== "object") return null;
99
+ if (raw.version !== CACHE_VERSION) return null;
100
+ if (!raw.servers || typeof raw.servers !== "object") return null;
101
+ return raw;
102
+ } catch {
103
+ return null;
104
+ }
105
+ }
106
+ function saveMetadataCache(cache) {
107
+ const cachePath = getMetadataCachePath();
108
+ const dir = dirname(cachePath);
109
+ mkdirSync(dir, { recursive: true });
110
+ let merged = { version: CACHE_VERSION, servers: {} };
111
+ try {
112
+ if (existsSync(cachePath)) {
113
+ const existing = JSON.parse(readFileSync(cachePath, "utf-8"));
114
+ if (existing && existing.version === CACHE_VERSION && existing.servers) {
115
+ merged.servers = { ...existing.servers };
116
+ }
117
+ }
118
+ } catch {
119
+ }
120
+ merged.version = CACHE_VERSION;
121
+ merged.servers = { ...merged.servers, ...cache.servers };
122
+ const tmpPath = `${cachePath}.${process.pid}.tmp`;
123
+ writeFileSync(tmpPath, JSON.stringify(merged), "utf-8");
124
+ renameSync(tmpPath, cachePath);
125
+ }
126
+ function computeServerHash(definition, environment = process.env) {
127
+ const identity = {
128
+ command: definition.command,
129
+ args: definition.args,
130
+ socket: resolveConfigPath(definition.socket, environment),
131
+ env: interpolateEnvRecord(definition.env, environment),
132
+ cwd: resolveConfigPath(definition.cwd, environment),
133
+ url: resolveServerUrl(definition, environment),
134
+ headers: interpolateEnvRecord(definition.headers, environment),
135
+ requestHeadersCommand: definition.requestHeadersCommand ? {
136
+ command: interpolateEnvVars(definition.requestHeadersCommand.command, environment),
137
+ args: definition.requestHeadersCommand.args?.map((argument) => interpolateEnvVars(argument, environment)),
138
+ env: interpolateEnvRecord(definition.requestHeadersCommand.env, environment),
139
+ timeoutMs: definition.requestHeadersCommand.timeoutMs
140
+ } : void 0,
141
+ auth: definition.auth,
142
+ protocolVersion: definition.protocolVersion,
143
+ bearerToken: resolveBearerToken(definition, environment),
144
+ bearerTokenEnv: definition.bearerTokenEnv,
145
+ exposeResources: definition.exposeResources,
146
+ includeTools: definition.includeTools,
147
+ excludeTools: definition.excludeTools
148
+ };
149
+ const normalized = stableStringify(identity);
150
+ return createHash("sha256").update(normalized).digest("hex");
151
+ }
152
+ function isServerCacheValid(entry, definition, maxAgeMs = CACHE_MAX_AGE_MS, environment = process.env) {
153
+ let configHash;
154
+ try {
155
+ configHash = computeServerHash(definition, environment);
156
+ } catch {
157
+ return false;
158
+ }
159
+ if (!entry || entry.configHash !== configHash) return false;
160
+ if (!entry.cachedAt || typeof entry.cachedAt !== "number") return false;
161
+ const declaredTtlMs = entry.ttlMs;
162
+ if (typeof declaredTtlMs === "number" && Number.isSafeInteger(declaredTtlMs) && declaredTtlMs >= 0) {
163
+ if (declaredTtlMs === 0) return false;
164
+ const ageMs = Date.now() - entry.cachedAt;
165
+ const effectiveMaxAge = maxAgeMs > 0 ? Math.min(maxAgeMs, declaredTtlMs) : declaredTtlMs;
166
+ return ageMs < effectiveMaxAge;
167
+ }
168
+ if (maxAgeMs > 0 && Date.now() - entry.cachedAt > maxAgeMs) return false;
169
+ return true;
170
+ }
171
+ function parseDirectToolSelectors(selectors) {
172
+ const servers = /* @__PURE__ */ new Set();
173
+ const tools = /* @__PURE__ */ new Map();
174
+ for (let selector of selectors) {
175
+ selector = selector.replace(/\/+$/, "");
176
+ if (selector.includes("/")) {
177
+ const [server, tool] = selector.split("/", 2);
178
+ if (server && tool) {
179
+ const serverTools = tools.get(server) ?? /* @__PURE__ */ new Set();
180
+ serverTools.add(tool);
181
+ tools.set(server, serverTools);
182
+ } else if (server) {
183
+ servers.add(server);
184
+ }
185
+ } else if (selector) {
186
+ servers.add(selector);
187
+ }
188
+ }
189
+ return { servers, tools };
190
+ }
191
+ function getMissingConfiguredDirectToolServers(config, cache, envOverride) {
192
+ const missing = [];
193
+ const globalDirect = config.settings?.directTools;
194
+ const envSelection = envOverride ? parseDirectToolSelectors(envOverride) : null;
195
+ for (const [serverName, definition] of Object.entries(config.mcpServers)) {
196
+ if (isServerDisabled(definition)) continue;
197
+ const hasDirectTools = envSelection ? envSelection.servers.has(serverName) || envSelection.tools.has(serverName) : definition.directTools !== void 0 ? !!definition.directTools : !!globalDirect;
198
+ if (!hasDirectTools) continue;
199
+ const serverCache = cache?.servers?.[serverName];
200
+ if (!serverCache || !isServerCacheValid(serverCache, definition)) {
201
+ missing.push(serverName);
202
+ }
203
+ }
204
+ return missing;
205
+ }
206
+ function reconstructToolMetadata(serverName, entry, prefix, definition, configuredServers, cache, sharedSelectorCandidateIndex) {
207
+ const metadata = [];
208
+ const seenNames = /* @__PURE__ */ new Set();
209
+ const effectivePrefix = resolveToolPrefix(definition, prefix);
210
+ const hasToolFilters = Array.isArray(definition.includeTools) && definition.includeTools.length > 0 || Array.isArray(definition.excludeTools) && definition.excludeTools.length > 0;
211
+ const selectorCandidateIndex = hasToolFilters ? sharedSelectorCandidateIndex ?? (configuredServers && cache ? createCachedToolSelectorCandidateIndex(configuredServers, cache, prefix) : void 0) : void 0;
212
+ for (const tool of entry.tools ?? []) {
213
+ if (!tool?.name) continue;
214
+ if (!isUiToolVisibleToModel(tool.uiVisibility)) {
215
+ continue;
216
+ }
217
+ if (!isToolAllowed(tool.name, serverName, effectivePrefix, definition.includeTools, definition.excludeTools, selectorCandidateIndex)) {
218
+ continue;
219
+ }
220
+ const name = formatToolName(tool.name, serverName, effectivePrefix);
221
+ if (seenNames.has(name)) {
222
+ continue;
223
+ }
224
+ seenNames.add(name);
225
+ metadata.push({
226
+ name,
227
+ originalName: tool.name,
228
+ description: tool.description ?? "",
229
+ ...tool.inputSchema !== void 0 ? { inputSchema: tool.inputSchema } : {},
230
+ ...tool.uiResourceUri !== void 0 ? { uiResourceUri: tool.uiResourceUri } : {},
231
+ ...tool.uiVisibility !== void 0 ? { uiVisibility: tool.uiVisibility } : {},
232
+ ...tool.uiStreamMode !== void 0 ? { uiStreamMode: tool.uiStreamMode } : {}
233
+ });
234
+ }
235
+ if (definition.exposeResources !== false) {
236
+ for (const resource of entry.resources ?? []) {
237
+ if (!resource?.name || !resource?.uri) continue;
238
+ const baseName = `read_${resourceNameToToolName(resource.name)}`;
239
+ if (!isToolAllowed(baseName, serverName, effectivePrefix, definition.includeTools, definition.excludeTools, selectorCandidateIndex)) {
240
+ continue;
241
+ }
242
+ const name = formatToolName(baseName, serverName, effectivePrefix);
243
+ if (seenNames.has(name)) {
244
+ continue;
245
+ }
246
+ seenNames.add(name);
247
+ metadata.push({
248
+ name,
249
+ originalName: baseName,
250
+ description: resource.description ?? `Read resource: ${resource.uri}`,
251
+ resourceUri: resource.uri
252
+ });
253
+ }
254
+ }
255
+ return metadata;
256
+ }
257
+ function createCachedToolSelectorCandidateIndex(configuredServers, cache, prefix) {
258
+ const candidates = /* @__PURE__ */ new Set();
259
+ for (const [serverName, definition] of Object.entries(configuredServers)) {
260
+ const entry = cache.servers[serverName];
261
+ if (!entry || !isServerCacheValid(entry, definition) || isServerDisabled(definition)) continue;
262
+ const effectivePrefix = resolveToolPrefix(definition, prefix);
263
+ for (const tool of entry.tools ?? []) {
264
+ if (!isUiToolVisibleToModel(tool.uiVisibility)) continue;
265
+ for (const candidate of getToolNameCandidates(tool.name, serverName, effectivePrefix, false)) candidates.add(candidate);
266
+ }
267
+ if (definition.exposeResources !== false) {
268
+ for (const resource of entry.resources ?? []) {
269
+ const baseName = `read_${resourceNameToToolName(resource.name)}`;
270
+ for (const candidate of getToolNameCandidates(baseName, serverName, effectivePrefix, false)) candidates.add(candidate);
271
+ }
272
+ }
273
+ }
274
+ return createToolSelectorCandidateIndex(candidates);
275
+ }
276
+ function serializeTools(tools) {
277
+ return tools.filter((t) => t?.name).map((t) => {
278
+ const uiResourceUri = tryGetToolUiResourceUri(t);
279
+ const uiVisibility = extractUiToolVisibility(t._meta);
280
+ const uiStreamMode = extractToolUiStreamMode(t._meta);
281
+ return {
282
+ name: t.name,
283
+ ...t.description !== void 0 ? { description: t.description } : {},
284
+ ...t.inputSchema !== void 0 ? { inputSchema: t.inputSchema } : {},
285
+ ...uiResourceUri !== void 0 ? { uiResourceUri } : {},
286
+ ...uiVisibility !== void 0 ? { uiVisibility } : {},
287
+ ...uiStreamMode !== void 0 ? { uiStreamMode } : {}
288
+ };
289
+ });
290
+ }
291
+ function serializeResources(resources) {
292
+ return resources.filter((r) => r?.name && r?.uri).map((r) => ({
293
+ uri: r.uri,
294
+ name: r.name,
295
+ ...r.description !== void 0 ? { description: r.description } : {}
296
+ }));
297
+ }
298
+ function serializePrompts(prompts) {
299
+ return (prompts ?? []).filter((prompt) => prompt?.name).map((prompt) => ({
300
+ name: prompt.name,
301
+ ...prompt.title !== void 0 ? { title: prompt.title } : {},
302
+ ...prompt.description !== void 0 ? { description: prompt.description } : {},
303
+ ...Array.isArray(prompt.arguments) ? {
304
+ arguments: prompt.arguments.filter((argument) => argument?.name).map((argument) => ({
305
+ name: argument.name,
306
+ ...argument.description !== void 0 ? { description: argument.description } : {},
307
+ ...argument.required !== void 0 ? { required: argument.required } : {}
308
+ }))
309
+ } : {}
310
+ }));
311
+ }
312
+ function reconstructPromptMetadata(serverName, prompts, prefix, definition) {
313
+ const effectivePrefix = resolveToolPrefix(definition, prefix);
314
+ return (prompts ?? []).filter((prompt) => prompt?.name).map((prompt) => {
315
+ const args = Array.isArray(prompt.arguments) ? prompt.arguments.filter((argument) => argument?.name).map((argument) => ({
316
+ name: argument.name,
317
+ ...argument.description !== void 0 ? { description: argument.description } : {},
318
+ ...argument.required !== void 0 ? { required: argument.required } : {}
319
+ })) : [];
320
+ return {
321
+ serverName,
322
+ originalName: prompt.name,
323
+ commandName: formatPromptCommandName(prompt.name, serverName, effectivePrefix),
324
+ ...prompt.title !== void 0 ? { title: prompt.title } : {},
325
+ description: prompt.description ?? "",
326
+ arguments: args
327
+ };
328
+ });
329
+ }
330
+ function stableStringify(value) {
331
+ if (value === null || value === void 0 || typeof value !== "object") {
332
+ const serialized = JSON.stringify(value);
333
+ return serialized === void 0 ? "undefined" : serialized;
334
+ }
335
+ if (Array.isArray(value)) {
336
+ return `[${value.map((v) => stableStringify(v)).join(",")}]`;
337
+ }
338
+ const obj = value;
339
+ const keys = Object.keys(obj).sort();
340
+ return `{${keys.map((k) => `${JSON.stringify(k)}:${stableStringify(obj[k])}`).join(",")}}`;
341
+ }
342
+ function tryGetToolUiResourceUri(tool) {
343
+ try {
344
+ return getToolUiResourceUri({ _meta: tool._meta });
345
+ } catch {
346
+ return void 0;
347
+ }
348
+ }
349
+
350
+ export {
351
+ RESOURCE_MIME_TYPE,
352
+ getToolUiResourceUri,
353
+ buildAllowAttribute,
354
+ resourceNameToToolName,
355
+ extractUiToolVisibility,
356
+ isUiToolVisibleToModel,
357
+ isUiToolCallableByApp,
358
+ getMetadataCachePath,
359
+ loadMetadataCache,
360
+ saveMetadataCache,
361
+ computeServerHash,
362
+ isServerCacheValid,
363
+ parseDirectToolSelectors,
364
+ getMissingConfiguredDirectToolServers,
365
+ reconstructToolMetadata,
366
+ createCachedToolSelectorCandidateIndex,
367
+ serializeTools,
368
+ serializeResources,
369
+ serializePrompts,
370
+ reconstructPromptMetadata
371
+ };
@@ -239,7 +239,7 @@ var DEFAULT_CODEX_ARGS = [
239
239
  var MIN_CODEX_CLI_VERSION = "0.153.3";
240
240
  var CODEX_UPGRADE_TIMEOUT_MS = 12e4;
241
241
  var codexCliVersionEnsured = null;
242
- var ENGINE_PACKAGE_VERSION = "0.1.744";
242
+ var ENGINE_PACKAGE_VERSION = "0.1.745";
243
243
  var INITIALIZE_METHOD = "initialize";
244
244
  var INITIALIZED_NOTIFICATION = "initialized";
245
245
  var ACCOUNT_LOGIN_START_METHOD = "account/login/start";
@@ -7,6 +7,7 @@ import {
7
7
  isRecord
8
8
  } from "./chunk-2RB7SIP3.js";
9
9
  import "./chunk-HMIVYASC.js";
10
+ import "./chunk-5KSXSK7Y.js";
10
11
 
11
12
  // src/command-protection-hook.ts
12
13
  var provider = process.argv[2];
@@ -8,6 +8,7 @@ import {
8
8
  import "./chunk-ITEQAMIZ.js";
9
9
  import "./chunk-2RB7SIP3.js";
10
10
  import "./chunk-HMIVYASC.js";
11
+ import "./chunk-5KSXSK7Y.js";
11
12
 
12
13
  // src/deepseek-command-protection-plugin.ts
13
14
  function replicasCommandProtection(context) {
@@ -6,12 +6,13 @@ import {
6
6
  import {
7
7
  AppServerProcess,
8
8
  buildCodexAgentEnv
9
- } from "./chunk-XQM2BWLW.js";
9
+ } from "./chunk-ZDBGX4MA.js";
10
10
  import {
11
11
  AGENT,
12
12
  getMemoryOutputSafetyViolation,
13
13
  headlessAgentRequestSchema
14
14
  } from "./chunk-HMIVYASC.js";
15
+ import "./chunk-5KSXSK7Y.js";
15
16
 
16
17
  // src/headless-agent.ts
17
18
  import { createHash } from "crypto";