@tangle-network/agent-profile-materialize 0.25.2 → 0.25.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/dist/harness.js CHANGED
@@ -348,14 +348,15 @@ export function materializerReplacement(relPath, content, plannedContent) {
348
348
  * there.
349
349
  *
350
350
  * An `opencode.json` this package wrote holds the opencode schema id, only the
351
- * keys this package writes, and only instruction paths this package invented.
352
- * A user config that holds nothing else is indistinguishable from that output
353
- * and is replaced too; a config with any other key, or with an instruction path
354
- * of the user's own, is refused.
351
+ * keys this package writes, and only instruction paths this package invented;
352
+ * a user config holding nothing else is replaced too, any other key or own
353
+ * instruction path is refused.
355
354
  */
356
355
  function isMaterializerOutput(relPath, content, plannedContent) {
357
356
  if (MATERIALIZER_RESERVED_PATHS.has(relPath))
358
357
  return true;
358
+ if (relPath === ".pi/mcp.json" || relPath === ".kimi/mcp.json")
359
+ return isMaterializerMcpConfig(relPath, content);
359
360
  if (MATERIALIZER_SUBAGENT_PATH.test(relPath)) {
360
361
  const existing = content();
361
362
  if (existing === undefined)
@@ -435,3 +436,4 @@ export function skillDirForHarness(harness) {
435
436
  return HARNESS_SKILL_DIRS[harness];
436
437
  }
437
438
  import { createHash } from "node:crypto";
439
+ import { isMaterializerMcpConfig } from "./mcp-config-ownership.js";
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ export * from "./harness-prompt.js";
7
7
  export { type ConcurrentProfileRevision, ensurePublicConcurrentProfileRoots, type ManagedWorkspaceFileDigest, type ManagedWorkspaceManifest, preparePublicConcurrentProfileRevision, } from "./managed-workspace.js";
8
8
  export type { OpenCodeMcpConfig } from "./mcp.js";
9
9
  export { openCodeMcpConfig } from "./mcp.js";
10
+ export { isMaterializerMcpConfig } from "./mcp-config-ownership.js";
10
11
  export { modelIdsMatch, qualifyModelId, unqualifyModelId, } from "./model-id.js";
11
12
  export { buildPiModelsConfig, buildPiModelsConfigFile, PI_MODELS_CONFIG_PATH, type PiModelsConfigFile, type PiModelsConfigInput, type PiRuntimePaths, resolvePiRuntimePaths, } from "./pi-models-config.js";
12
13
  export { applyWorkspacePlan, applyWorkspacePlanWithSecretProvider, } from "./plan-application.js";
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ export { HARNESS_SKILL_DIRS, harnessAutoLoadsAgentContextFile, harnessAutoLoadsC
4
4
  export * from "./harness-prompt.js";
5
5
  export { ensurePublicConcurrentProfileRoots, preparePublicConcurrentProfileRevision, } from "./managed-workspace.js";
6
6
  export { openCodeMcpConfig } from "./mcp.js";
7
+ export { isMaterializerMcpConfig } from "./mcp-config-ownership.js";
7
8
  export { modelIdsMatch, qualifyModelId, unqualifyModelId, } from "./model-id.js";
8
9
  export { buildPiModelsConfig, buildPiModelsConfigFile, PI_MODELS_CONFIG_PATH, resolvePiRuntimePaths, } from "./pi-models-config.js";
9
10
  export { applyWorkspacePlan, applyWorkspacePlanWithSecretProvider, } from "./plan-application.js";
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Harness MCP config files this package generates wholesale from
3
+ * `profile.mcp`: exactly one `mcpServers` object whose entries carry only
4
+ * the fields the generators write. Recognizable by that shape alone (no
5
+ * schema id to key on), so an existing file holding ONLY those registrations
6
+ * is this package's earlier output and a new plan replaces it — a per-turn
7
+ * profile changes these bytes routinely (physim's MCP env carries turn
8
+ * state). Anything else at the path (a user's own keys, extra fields) still
9
+ * refuses: the name alone proves nothing, same rule as `opencode.json`.
10
+ */
11
+ /** Paths owned by this rule. `.gemini/settings.json` is deliberately absent:
12
+ * it is a broader user settings file the package only contributes one key
13
+ * to, so its bytes cannot prove authorship. */
14
+ export declare const MATERIALIZER_MCP_CONFIG_PATHS: Set<string>;
15
+ /** The parsed form this rule accepts: `JSON.parse` output narrowed at the
16
+ * I/O boundary by {@link parseMcpServersConfig}. */
17
+ export interface McpServersConfig {
18
+ mcpServers: Record<string, Record<string, unknown>>;
19
+ }
20
+ /** Parse workspace bytes into the one shape this rule owns, or `null` when
21
+ * the bytes are anything else (not an object, other top-level keys, or
22
+ * server entries that are not objects). The I/O boundary for
23
+ * {@link isGeneratedMcpConfigShape}. */
24
+ export declare function parseMcpServersConfig(bytes: string): McpServersConfig | null;
25
+ /** Whether a parsed MCP config carries ONLY the registrations this package
26
+ * generates: no extra top-level keys, and every server entry holds only
27
+ * generated fields. A user's own key anywhere makes this `false`. */
28
+ export declare function isGeneratedMcpConfigShape(config: McpServersConfig): boolean;
29
+ /** Whether the existing file at `relPath` is this package's own earlier MCP
30
+ * config output (shape rule above). `undefined` content = no regular file. */
31
+ export declare function isMaterializerMcpConfig(relPath: string, content: () => string | undefined): boolean;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Harness MCP config files this package generates wholesale from
3
+ * `profile.mcp`: exactly one `mcpServers` object whose entries carry only
4
+ * the fields the generators write. Recognizable by that shape alone (no
5
+ * schema id to key on), so an existing file holding ONLY those registrations
6
+ * is this package's earlier output and a new plan replaces it — a per-turn
7
+ * profile changes these bytes routinely (physim's MCP env carries turn
8
+ * state). Anything else at the path (a user's own keys, extra fields) still
9
+ * refuses: the name alone proves nothing, same rule as `opencode.json`.
10
+ */
11
+ /** Paths owned by this rule. `.gemini/settings.json` is deliberately absent:
12
+ * it is a broader user settings file the package only contributes one key
13
+ * to, so its bytes cannot prove authorship. */
14
+ export const MATERIALIZER_MCP_CONFIG_PATHS = new Set([
15
+ ".pi/mcp.json",
16
+ ".kimi/mcp.json",
17
+ ]);
18
+ const GENERATED_MCP_SERVER_KEYS = new Set([
19
+ "command",
20
+ "args",
21
+ "env",
22
+ "cwd",
23
+ "url",
24
+ "httpUrl",
25
+ "headers",
26
+ "transport",
27
+ "enabled",
28
+ "directTools",
29
+ ]);
30
+ /** Parse workspace bytes into the one shape this rule owns, or `null` when
31
+ * the bytes are anything else (not an object, other top-level keys, or
32
+ * server entries that are not objects). The I/O boundary for
33
+ * {@link isGeneratedMcpConfigShape}. */
34
+ export function parseMcpServersConfig(bytes) {
35
+ let parsed;
36
+ try {
37
+ parsed = JSON.parse(bytes);
38
+ }
39
+ catch {
40
+ return null;
41
+ }
42
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
43
+ return null;
44
+ }
45
+ const { mcpServers } = parsed;
46
+ if (mcpServers === null ||
47
+ typeof mcpServers !== "object" ||
48
+ Array.isArray(mcpServers)) {
49
+ return null;
50
+ }
51
+ for (const server of Object.values(mcpServers)) {
52
+ if (server === null ||
53
+ typeof server !== "object" ||
54
+ Array.isArray(server)) {
55
+ return null;
56
+ }
57
+ }
58
+ return { mcpServers: mcpServers };
59
+ }
60
+ /** Whether a parsed MCP config carries ONLY the registrations this package
61
+ * generates: no extra top-level keys, and every server entry holds only
62
+ * generated fields. A user's own key anywhere makes this `false`. */
63
+ export function isGeneratedMcpConfigShape(config) {
64
+ const keys = Object.keys(config);
65
+ if (keys.length !== 1 || keys[0] !== "mcpServers")
66
+ return false;
67
+ return Object.values(config.mcpServers).every((server) => Object.keys(server).every((key) => GENERATED_MCP_SERVER_KEYS.has(key)));
68
+ }
69
+ /** Whether the existing file at `relPath` is this package's own earlier MCP
70
+ * config output (shape rule above). `undefined` content = no regular file. */
71
+ export function isMaterializerMcpConfig(relPath, content) {
72
+ if (!MATERIALIZER_MCP_CONFIG_PATHS.has(relPath))
73
+ return false;
74
+ const bytes = content();
75
+ if (bytes === undefined)
76
+ return false;
77
+ const config = parseMcpServersConfig(bytes);
78
+ return config !== null && isGeneratedMcpConfigShape(config);
79
+ }
@@ -1,4 +1,4 @@
1
- export declare const compareStrings: (a: string, b: string) => 1 | -1 | 0;
1
+ export declare const compareStrings: (a: string, b: string) => 1 | 0 | -1;
2
2
  export declare const DEFAULT_FILE_MODE = 420;
3
3
  export declare const PRIVATE_FILE_MODE = 384;
4
4
  export declare const EXECUTABLE_FILE_MODE = 493;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-profile-materialize",
3
- "version": "0.25.2",
3
+ "version": "0.25.3",
4
4
  "description": "Materialize an AgentProfile into the native per-harness workspace files (the one shared materializer for cli-bridge, agent-dev-container, and VB).",
5
5
  "type": "module",
6
6
  "repository": {