@jini-ai/agent-runtime 0.7.3-next.2 → 0.7.4
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/CHANGELOG.md +7 -0
- package/README.md +38 -0
- package/dist/agent-protocol/acp/models.d.ts +0 -10
- package/dist/agent-protocol/acp/models.js +0 -10
- package/dist/agent-protocol/acp/rpc.d.ts +5 -1
- package/dist/agent-protocol/acp/rpc.js +2 -1
- package/dist/agent-protocol/acp/session-permission.js +4 -3
- package/dist/agent-protocol/acp/session-results.d.ts +4 -4
- package/dist/agent-protocol/acp/session-results.js +30 -21
- package/dist/agent-protocol/acp/session-run.js +0 -8
- package/dist/agent-protocol/acp/session-types.d.ts +0 -1
- package/dist/agent-protocol/acp/session-usage.d.ts +12 -0
- package/dist/agent-protocol/acp/session-usage.js +29 -0
- package/dist/agent-protocol/acp/session.d.ts +1 -1
- package/dist/agent-protocol/acp/session.js +10 -4
- package/dist/agent-protocol/acp/text-suppression.js +75 -71
- package/dist/agent-protocol/pi-rpc/events.d.ts +21 -4
- package/dist/agent-protocol/pi-rpc/events.js +9 -9
- package/dist/agent-protocol/pi-rpc/internal.d.ts +6 -2
- package/dist/agent-protocol/pi-rpc/internal.js +6 -4
- package/dist/agent-protocol/pi-rpc/session.js +4 -3
- package/dist/anthropic-live-models.js +0 -0
- package/dist/claude-code-models.d.ts +3 -1
- package/dist/claude-code-models.js +4 -4
- package/dist/claude-stream-frames.js +1 -1
- package/dist/cli-probe-cache.d.ts +33 -0
- package/dist/cli-probe-cache.js +59 -0
- package/dist/custom-instructions.d.ts +107 -0
- package/dist/custom-instructions.js +80 -0
- package/dist/defs/{aider.d.ts → aider/index.d.ts} +2 -1
- package/dist/defs/{aider.js → aider/index.js} +6 -3
- package/dist/defs/amr/executable-env.d.ts +2 -0
- package/dist/defs/amr/executable-env.js +2 -0
- package/dist/defs/amr/executable-resolution.d.ts +5 -1
- package/dist/defs/amr/executable-resolution.js +1 -1
- package/dist/defs/antigravity/index.d.ts +1 -0
- package/dist/defs/antigravity/index.js +3 -0
- package/dist/defs/antigravity/permissions.d.ts +26 -0
- package/dist/defs/antigravity/permissions.js +66 -0
- package/dist/defs/{auggie.d.ts → auggie/index.d.ts} +1 -1
- package/dist/defs/{auggie.js → auggie/index.js} +3 -3
- package/dist/defs/claude/config-dir.d.ts +62 -0
- package/dist/defs/claude/config-dir.js +133 -0
- package/dist/defs/claude/filesystem.d.ts +33 -0
- package/dist/defs/claude/filesystem.js +30 -0
- package/dist/defs/{claude.d.ts → claude/index.d.ts} +1 -1
- package/dist/defs/{claude.js → claude/index.js} +9 -9
- package/dist/defs/claude/mcp-config.d.ts +22 -0
- package/dist/defs/claude/mcp-config.js +29 -0
- package/dist/defs/claude/mcp-delivery.d.ts +57 -0
- package/dist/defs/claude/mcp-delivery.js +75 -0
- package/dist/defs/claude/mcp-json.d.ts +34 -0
- package/dist/defs/claude/mcp-json.js +38 -0
- package/dist/defs/claude/subagent-start.d.ts +12 -0
- package/dist/defs/claude/subagent-start.js +35 -0
- package/dist/defs/{cline.d.ts → cline/index.d.ts} +1 -1
- package/dist/defs/{cline.js → cline/index.js} +3 -3
- package/dist/defs/codex/contracts.d.ts +47 -0
- package/dist/defs/codex/contracts.js +6 -0
- package/dist/defs/codex/event-stream.d.ts +5 -1
- package/dist/defs/codex/event-stream.js +29 -24
- package/dist/defs/codex/home-config.d.ts +55 -0
- package/dist/defs/codex/home-config.js +224 -0
- package/dist/defs/codex/home-staging.d.ts +57 -0
- package/dist/defs/codex/home-staging.js +184 -0
- package/dist/defs/{codex.d.ts → codex/index.d.ts} +2 -2
- package/dist/defs/{codex.js → codex/index.js} +3 -3
- package/dist/defs/codex/isolation.d.ts +29 -0
- package/dist/defs/codex/isolation.js +69 -0
- package/dist/defs/codex/launch.d.ts +4 -1
- package/dist/defs/codex/launch.js +1 -1
- package/dist/defs/codex/mcp-delivery.d.ts +8 -0
- package/dist/defs/codex/mcp-delivery.js +5 -0
- package/dist/defs/{crush.d.ts → crush/index.d.ts} +1 -1
- package/dist/defs/{crush.js → crush/index.js} +3 -3
- package/dist/defs/cursor-agent/event-stream.d.ts +5 -1
- package/dist/defs/cursor-agent/event-stream.js +14 -7
- package/dist/defs/{cursor-agent.d.ts → cursor-agent/index.d.ts} +1 -1
- package/dist/defs/{cursor-agent.js → cursor-agent/index.js} +4 -4
- package/dist/defs/{deepseek.d.ts → deepseek/index.d.ts} +2 -1
- package/dist/defs/{deepseek.js → deepseek/index.js} +6 -3
- package/dist/defs/{devin.d.ts → devin/index.d.ts} +1 -1
- package/dist/defs/{devin.js → devin/index.js} +3 -3
- package/dist/defs/{droid.d.ts → droid/index.d.ts} +1 -1
- package/dist/defs/{droid.js → droid/index.js} +3 -3
- package/dist/defs/gemini/event-stream.d.ts +5 -1
- package/dist/defs/gemini/event-stream.js +15 -12
- package/dist/defs/gemini/tool-calls.d.ts +7 -0
- package/dist/defs/gemini/tool-calls.js +9 -0
- package/dist/defs/{goose.d.ts → goose/index.d.ts} +1 -1
- package/dist/defs/{goose.js → goose/index.js} +3 -3
- package/dist/defs/{grok-build.d.ts → grok-build/index.d.ts} +1 -1
- package/dist/defs/{grok-build.js → grok-build/index.js} +3 -3
- package/dist/defs/index.d.ts +28 -28
- package/dist/defs/index.js +28 -28
- package/dist/defs/{kilo.d.ts → kilo/index.d.ts} +1 -1
- package/dist/defs/{kilo.js → kilo/index.js} +3 -3
- package/dist/defs/kimi/event-stream.d.ts +4 -1
- package/dist/defs/kimi/event-stream.js +6 -5
- package/dist/defs/{kimi.d.ts → kimi/index.d.ts} +1 -1
- package/dist/defs/{kimi.js → kimi/index.js} +3 -3
- package/dist/defs/{kiro.d.ts → kiro/index.d.ts} +1 -1
- package/dist/defs/{kiro.js → kiro/index.js} +3 -3
- package/dist/defs/mimo/constants.d.ts +2 -0
- package/dist/defs/mimo/constants.js +2 -0
- package/dist/defs/{mimo.d.ts → mimo/index.d.ts} +1 -1
- package/dist/defs/{mimo.js → mimo/index.js} +3 -3
- package/dist/defs/opencode/constants.d.ts +2 -0
- package/dist/defs/opencode/constants.js +2 -0
- package/dist/defs/opencode/event-stream.d.ts +5 -1
- package/dist/defs/opencode/event-stream.js +13 -11
- package/dist/defs/{opencode.d.ts → opencode/index.d.ts} +2 -2
- package/dist/defs/{opencode.js → opencode/index.js} +5 -5
- package/dist/defs/opencode/mcp-config.d.ts +108 -0
- package/dist/defs/opencode/mcp-config.js +119 -0
- package/dist/defs/opencode/model-discovery.d.ts +3 -1
- package/dist/defs/opencode/model-discovery.js +1 -1
- package/dist/defs/opencode/tool-calls.d.ts +7 -0
- package/dist/defs/opencode/tool-calls.js +12 -0
- package/dist/defs/{opencode-acp.d.ts → opencode-acp/index.d.ts} +2 -2
- package/dist/defs/{opencode-acp.js → opencode-acp/index.js} +4 -4
- package/dist/defs/{pi.d.ts → pi/index.d.ts} +1 -1
- package/dist/defs/{pi.js → pi/index.js} +3 -3
- package/dist/defs/pi/model-discovery.d.ts +4 -1
- package/dist/defs/pi/model-discovery.js +1 -1
- package/dist/defs/{qoder.d.ts → qoder/index.d.ts} +1 -1
- package/dist/defs/{qoder.js → qoder/index.js} +3 -3
- package/dist/defs/{qwen.d.ts → qwen/index.d.ts} +1 -1
- package/dist/defs/{qwen.js → qwen/index.js} +3 -3
- package/dist/defs/{reasonix.d.ts → reasonix/index.d.ts} +1 -1
- package/dist/defs/{reasonix.js → reasonix/index.js} +3 -3
- package/dist/defs/{trae-cli.d.ts → trae-cli/index.d.ts} +1 -1
- package/dist/defs/{trae-cli.js → trae-cli/index.js} +3 -3
- package/dist/defs/{vibe.d.ts → vibe/index.d.ts} +1 -1
- package/dist/defs/{vibe.js → vibe/index.js} +3 -3
- package/dist/executables.js +1 -1
- package/dist/inventory/index.d.ts +61 -0
- package/dist/inventory/index.js +45 -0
- package/dist/json-event-stream-shared.d.ts +10 -2
- package/dist/json-event-stream-shared.js +21 -13
- package/dist/json-event-stream.js +6 -5
- package/dist/launch.js +1 -1
- package/dist/model-catalog-live-discovery.d.ts +103 -0
- package/dist/model-catalog-live-discovery.js +111 -0
- package/dist/model-discovery-adapters.d.ts +6 -1
- package/dist/model-discovery-adapters.js +4 -3
- package/dist/model-discovery-config.js +1 -1
- package/dist/native-permissions.d.ts +19 -0
- package/dist/native-permissions.js +22 -0
- package/dist/providers/anthropic-messages.js +3 -2
- package/dist/providers/connection-guard.js +99 -84
- package/dist/providers/connection-test.js +0 -5
- package/dist/providers/google-messages.js +1 -1
- package/dist/providers/oauth-provider.d.ts +1 -23
- package/dist/providers/oauth-provider.js +1 -35
- package/dist/providers/openai-chat-request.js +1 -1
- package/dist/providers/tool-loop-verdict.d.ts +1 -0
- package/dist/providers/tool-loop-verdict.js +4 -1
- package/dist/providers/tool-turn-types.d.ts +12 -9
- package/dist/providers/tool-turn.d.ts +63 -1
- package/dist/providers/tool-turn.js +67 -1
- package/dist/qoder-stream.js +66 -66
- package/dist/role-marker-guard.js +49 -30
- package/dist/runtime-def-binding.js +1 -1
- package/dist/runtime-port-bindings.d.ts +82 -0
- package/dist/runtime-port-bindings.js +4 -1
- package/dist/runtime-strategies.d.ts +100 -0
- package/dist/runtime-strategies.js +129 -0
- package/package.json +44 -10
- package/dist/defs/amp.d.ts +0 -2
- package/dist/defs/amp.js +0 -2
- package/dist/defs/amr.d.ts +0 -2
- package/dist/defs/amr.js +0 -2
- package/dist/defs/codebuddy.d.ts +0 -2
- package/dist/defs/codebuddy.js +0 -2
- package/dist/defs/hermes.d.ts +0 -2
- package/dist/defs/hermes.js +0 -2
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { homedir } from 'node:os';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { promises as fs } from 'node:fs';
|
|
4
|
+
import { getRecord } from '../../json-event-stream-shared.js';
|
|
5
|
+
/** Read the current settings text; a missing file is undefined, every other failure rejects. */
|
|
6
|
+
async function readSettingsText(settingsPath) {
|
|
7
|
+
try {
|
|
8
|
+
return await fs.readFile(settingsPath, 'utf8');
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error.code !== 'ENOENT')
|
|
12
|
+
throw error;
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Parse and validate the settings shape; anything unexpected rejects rather than widening permissions. */
|
|
17
|
+
function parseSettings(raw) {
|
|
18
|
+
const settings = getRecord({ value: raw === undefined ? {} : JSON.parse(raw) });
|
|
19
|
+
if (!settings)
|
|
20
|
+
throw new Error('Antigravity settings must be an object');
|
|
21
|
+
const permissions = getRecord({ value: settings.permissions === undefined ? {} : settings.permissions });
|
|
22
|
+
if (!permissions || (permissions.allow !== undefined && !Array.isArray(permissions.allow))) {
|
|
23
|
+
throw new Error('Antigravity permissions.allow must be an array');
|
|
24
|
+
}
|
|
25
|
+
return { settings, permissions, allow: permissions.allow ?? [] };
|
|
26
|
+
}
|
|
27
|
+
/** The allow list holding exactly one copy of rule (first occurrence kept, order otherwise
|
|
28
|
+
* unchanged), or null when it already holds exactly one and nothing needs writing. */
|
|
29
|
+
function grantedAllowList(allow, rule) {
|
|
30
|
+
const first = allow.indexOf(rule);
|
|
31
|
+
if (first < 0)
|
|
32
|
+
return [...allow, rule];
|
|
33
|
+
const deduped = allow.filter((entry, index) => entry !== rule || index === first);
|
|
34
|
+
return deduped.length === allow.length ? null : deduped;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Persist one server's MCP grant for agy, which has no run-scoped settings override.
|
|
38
|
+
* Holds the host's lock and writes through the host's atomic writer, which also keeps the first
|
|
39
|
+
* existing file as a backup (lock, then backup, then write; the lock is released on every path).
|
|
40
|
+
* Invalid settings and I/O failures reject before spawn rather than widening permissions.
|
|
41
|
+
* @complexity O(settings bytes), including the allow-list scan; bounded by the settings file.
|
|
42
|
+
*/
|
|
43
|
+
export async function ensureAntigravityMcpPermission({ settingsPath, serverName, fileLock, writer }, _options = {}) {
|
|
44
|
+
if (!/^[\w.-]+$/.test(serverName))
|
|
45
|
+
throw new Error('Invalid MCP server name');
|
|
46
|
+
const rule = `mcp(${serverName}/*)`;
|
|
47
|
+
await fileLock.withFileLock({ lockPath: `${settingsPath}.jini-lock`, run: async () => {
|
|
48
|
+
const raw = await readSettingsText(settingsPath);
|
|
49
|
+
const { settings, permissions, allow } = parseSettings(raw);
|
|
50
|
+
const nextAllow = grantedAllowList(allow, rule);
|
|
51
|
+
if (nextAllow === null)
|
|
52
|
+
return;
|
|
53
|
+
if (raw !== undefined)
|
|
54
|
+
await writer.backupOriginalOnce({ filePath: settingsPath });
|
|
55
|
+
await writer.writeText({ filePath: settingsPath, content: `${JSON.stringify({
|
|
56
|
+
...settings, permissions: { ...permissions, allow: nextAllow },
|
|
57
|
+
}, null, 2)}\n` }, { refuseSymlink: true });
|
|
58
|
+
} }, { createParent: true, timeoutMs: 5000 });
|
|
59
|
+
}
|
|
60
|
+
/** Prepare this CLI's persistent MCP permission before an env-passthrough launch. */
|
|
61
|
+
export async function prepareAntigravityBridge({ delivery, serverName, fileLock, writer }, { ensurePermission }) {
|
|
62
|
+
if (delivery?.kind !== 'env-passthrough')
|
|
63
|
+
return;
|
|
64
|
+
await ensurePermission({ settingsPath: join(homedir(), '.gemini', 'antigravity-cli', 'settings.json'), serverName, fileLock, writer });
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=permissions.js.map
|
|
@@ -30,4 +30,4 @@ export declare const auggieAgentDef: {
|
|
|
30
30
|
deps?: import("@jini-ai/core/contracts/agents").ModelDiscoveryDeps;
|
|
31
31
|
}): Promise<import("@jini-ai/core/contracts/agents").DefaultModelResolution>;
|
|
32
32
|
};
|
|
33
|
-
//# sourceMappingURL=
|
|
33
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createAgentModelDiscovery } from '
|
|
1
|
+
import { createAgentModelDiscovery } from '../../model-discovery-native.js';
|
|
2
2
|
/**
|
|
3
3
|
* @module defs/auggie
|
|
4
4
|
*
|
|
@@ -7,7 +7,7 @@ import { createAgentModelDiscovery } from '../model-discovery-native.js';
|
|
|
7
7
|
* (<https://github.com/agentclientprotocol/registry>, `auggie/agent.json`). Sign-in is
|
|
8
8
|
* `auggie login` in a terminal.
|
|
9
9
|
*/
|
|
10
|
-
import { acpModelFetcher, DEFAULT_MODEL_OPTION } from '
|
|
10
|
+
import { acpModelFetcher, DEFAULT_MODEL_OPTION } from '../shared.js';
|
|
11
11
|
export const auggieAgentDef = {
|
|
12
12
|
// UNVERIFIED live integration locally; source/category and limits are documented in model-discovery-adapters.ts.
|
|
13
13
|
...createAgentModelDiscovery('auggie', { fallbackModels: () => auggieAgentDef.fallbackModels }),
|
|
@@ -24,4 +24,4 @@ export const auggieAgentDef = {
|
|
|
24
24
|
// `acp-json-rpc` def — see `types.ts#RuntimeAgentDef.imageDelivery`'s doc.
|
|
25
25
|
imageDelivery: 'native',
|
|
26
26
|
};
|
|
27
|
-
//# sourceMappingURL=
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
export declare const CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR";
|
|
2
|
+
/** A staged, run-scoped `claude` CLI config directory and the release of everything it holds. */
|
|
3
|
+
export type PreparedClaudeConfigDir = {
|
|
4
|
+
/** Absolute path to hand to the spawned child as its `CLAUDE_CONFIG_DIR` env var. */
|
|
5
|
+
readonly path: string;
|
|
6
|
+
/** Recursively removes the staged directory — it may hold a copied login credential (see {@link prepareClaudeConfigDirForRun}'s doc). Safe to call more than once. */
|
|
7
|
+
readonly cleanup: () => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
/** The staging mechanism's filesystem seams, all required once resolved. */
|
|
10
|
+
export interface ClaudeConfigDirSeams {
|
|
11
|
+
readonly mkdtemp: ({ prefix }: {
|
|
12
|
+
readonly prefix: string;
|
|
13
|
+
}) => Promise<string>;
|
|
14
|
+
readonly readFile: ({ path }: {
|
|
15
|
+
readonly path: string;
|
|
16
|
+
}) => Promise<string>;
|
|
17
|
+
readonly writeFile: ({ path, content }: {
|
|
18
|
+
readonly path: string;
|
|
19
|
+
readonly content: string;
|
|
20
|
+
}) => Promise<void>;
|
|
21
|
+
readonly removeDir: ({ path }: {
|
|
22
|
+
readonly path: string;
|
|
23
|
+
}) => Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Where `claude`'s own config resolution reads the operator's REAL config from, to seed a run's
|
|
27
|
+
* scratch copy — never where it writes. Mirrors `resolveSourceCodexHomeDir`'s exact reasoning
|
|
28
|
+
* and resolution order: `CLAUDE_CONFIG_DIR` is not in `BASELINE_AGENT_ENV_KEYS`, so a spawned child
|
|
29
|
+
* never inherits it anyway — the whole point is finding wherever the *operator's actual* Claude Code
|
|
30
|
+
* install lives, a host-machine fact resolved against the daemon HOST process's own environment.
|
|
31
|
+
* @param hostEnv - The daemon process's own environment.
|
|
32
|
+
* @returns `hostEnv.CLAUDE_CONFIG_DIR` when set to a non-blank value (matching Claude Code's own
|
|
33
|
+
* resolution order, confirmed against installed Claude Code 2.1.263), else the CLI's documented
|
|
34
|
+
* default, `~/.claude`.
|
|
35
|
+
* @complexity O(1).
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveSourceClaudeConfigDir({ hostEnv }: {
|
|
38
|
+
readonly hostEnv: NodeJS.ProcessEnv;
|
|
39
|
+
}): string;
|
|
40
|
+
/**
|
|
41
|
+
* Finding 1 of SEC-assistant-env-isolation-2026-09-07's one effect — stages this run's scratch
|
|
42
|
+
* `CLAUDE_CONFIG_DIR` directory, returning the prepared handle the launcher's `cleanupStagedFiles` should later
|
|
43
|
+
* release (see {@link prepareClaudeConfigDirForRun}'s own doc for why this is unconditional for `claude` runs, unlike
|
|
44
|
+
* the Codex home's gate on a host-configured MCP bridge strategy).
|
|
45
|
+
*
|
|
46
|
+
* Bound only to the real `claude` CLI's own definition id (`runtime-strategies.ts`) rather than to
|
|
47
|
+
* `externalMcpInjection === 'claude-mcp-json'` (which `codebuddy` also declares): isolating the operator's personal
|
|
48
|
+
* `~/.claude` is specific to the real `claude` CLI's own config resolution, not to every def that happens to share its
|
|
49
|
+
* `.mcp.json` delivery shape. Matches the existing `USER`-for-claude-login special case already singled
|
|
50
|
+
* out by id in `BASELINE_AGENT_ENV_KEYS`'s own doc in `launch.ts`.
|
|
51
|
+
* @param required.hostEnv - The daemon's own environment, threaded through to {@link resolveSourceClaudeConfigDir} rather than read from a module-level `process.env`, matching the Codex home staging's identical testability reasoning.
|
|
52
|
+
* @param optional.seams - Injectable mkdtemp/readFile/writeFile/removeDir, real filesystem by default.
|
|
53
|
+
* @throws Whatever staging rejects with; the caller turns that into a pre-spawn `AGENT_SPAWN_FAILED` failure.
|
|
54
|
+
* @complexity O(1) plus {@link prepareClaudeConfigDirForRun}'s own cost.
|
|
55
|
+
*/
|
|
56
|
+
export declare function stageClaudeConfigDir({ runId, hostEnv }: {
|
|
57
|
+
readonly runId: string;
|
|
58
|
+
readonly hostEnv: NodeJS.ProcessEnv;
|
|
59
|
+
}, { seams }?: {
|
|
60
|
+
readonly seams?: Partial<ClaudeConfigDirSeams> | undefined;
|
|
61
|
+
}): Promise<PreparedClaudeConfigDir>;
|
|
62
|
+
//# sourceMappingURL=config-dir.d.ts.map
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { promises as fsPromises } from 'node:fs';
|
|
2
|
+
import { homedir, tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { defaultReadMcpJsonFile, defaultWriteMcpJsonFile } from './mcp-json.js';
|
|
5
|
+
export const CLAUDE_CONFIG_DIR_ENV = 'CLAUDE_CONFIG_DIR';
|
|
6
|
+
function defaultMkdtempClaudeConfigDir({ prefix }) {
|
|
7
|
+
return fsPromises.mkdtemp(join(tmpdir(), prefix));
|
|
8
|
+
}
|
|
9
|
+
function defaultRemoveClaudeConfigDir({ path }) {
|
|
10
|
+
return fsPromises.rm(path, { recursive: true, force: true });
|
|
11
|
+
}
|
|
12
|
+
function resolveClaudeConfigDirSeams(options) {
|
|
13
|
+
return {
|
|
14
|
+
mkdtemp: options?.mkdtemp ?? defaultMkdtempClaudeConfigDir,
|
|
15
|
+
readFile: options?.readFile ?? defaultReadMcpJsonFile,
|
|
16
|
+
writeFile: options?.writeFile ?? defaultWriteMcpJsonFile,
|
|
17
|
+
removeDir: options?.removeDir ?? defaultRemoveClaudeConfigDir,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Where `claude`'s own config resolution reads the operator's REAL config from, to seed a run's
|
|
22
|
+
* scratch copy — never where it writes. Mirrors `resolveSourceCodexHomeDir`'s exact reasoning
|
|
23
|
+
* and resolution order: `CLAUDE_CONFIG_DIR` is not in `BASELINE_AGENT_ENV_KEYS`, so a spawned child
|
|
24
|
+
* never inherits it anyway — the whole point is finding wherever the *operator's actual* Claude Code
|
|
25
|
+
* install lives, a host-machine fact resolved against the daemon HOST process's own environment.
|
|
26
|
+
* @param hostEnv - The daemon process's own environment.
|
|
27
|
+
* @returns `hostEnv.CLAUDE_CONFIG_DIR` when set to a non-blank value (matching Claude Code's own
|
|
28
|
+
* resolution order, confirmed against installed Claude Code 2.1.263), else the CLI's documented
|
|
29
|
+
* default, `~/.claude`.
|
|
30
|
+
* @complexity O(1).
|
|
31
|
+
*/
|
|
32
|
+
export function resolveSourceClaudeConfigDir({ hostEnv }) {
|
|
33
|
+
const override = hostEnv.CLAUDE_CONFIG_DIR;
|
|
34
|
+
return override !== undefined && override.trim().length > 0 ? override : join(homedir(), '.claude');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Stages a fresh, randomly-named `CLAUDE_CONFIG_DIR` directory (same non-determinism requirement as
|
|
38
|
+
* `McpJsonInjectionOptions.mkdtemp`'s own doc — `os.tmpdir()` is a shared location on a
|
|
39
|
+
* multi-user host, so a guessable name is a real pre-plant/symlink target).
|
|
40
|
+
*
|
|
41
|
+
* **Deliberately empty by default** — unlike `prepareCodexHomeForRun`, which copies the real
|
|
42
|
+
* `config.toml` wholesale (Codex has no personal-data problem in that file), this directory gets
|
|
43
|
+
* NOTHING written into it beyond a best-effort copy of `.credentials.json` (see below). That is the
|
|
44
|
+
* fix: the operator's real `skills`/`plugins`/`agents`/`memory-path index`/`settings.json` must NOT
|
|
45
|
+
* carry over implicitly. `claude` runs correctly against a config directory holding nothing at all —
|
|
46
|
+
* it falls back to its own built-in defaults, not an error.
|
|
47
|
+
*
|
|
48
|
+
* **Login preservation, verified rather than assumed** (per this task's own instruction — "prove
|
|
49
|
+
* login still resolves; do not assume"): confirmed live (2026-09-07, installed Claude Code 2.1.263,
|
|
50
|
+
* macOS) that `claude auth status` reports `loggedIn: false` against ANY `CLAUDE_CONFIG_DIR` other
|
|
51
|
+
* than the operator's real one — including the real `HOME` with only `CLAUDE_CONFIG_DIR` swapped —
|
|
52
|
+
* and confirmed against Claude Code's own docs (code.claude.com/docs/en/authentication) why: "If
|
|
53
|
+
* you've set the CLAUDE_CONFIG_DIR environment variable, Claude Code keeps the .credentials.json
|
|
54
|
+
* file under that directory instead, including the file the macOS fallback writes, and keys the
|
|
55
|
+
* macOS Keychain entry to that directory too, so a session with a different CLAUDE_CONFIG_DIR reads
|
|
56
|
+
* a different entry." So a scratch directory is never logged in by default on ANY platform, not just
|
|
57
|
+
* the ones with no Keychain at all. This function only closes the *portable* case: when the source
|
|
58
|
+
* directory holds a file-based `.credentials.json` (Linux, Windows, or a Keychain-locked macOS
|
|
59
|
+
* fallback — none of which this function can distinguish, and does not need to), it is copied
|
|
60
|
+
* best-effort into the scratch directory, exactly `prepareCodexHomeForRun`'s `auth.json` copy. When
|
|
61
|
+
* it does not (a normal macOS Keychain-only install, confirmed the common case on this codebase's
|
|
62
|
+
* own dev machine), this function does NOT attempt to read the macOS Keychain itself — that would
|
|
63
|
+
* mean this daemon process extracting a live OAuth secret out of an OS-managed credential store into
|
|
64
|
+
* a plaintext file, a materially different and larger security surface than forwarding an
|
|
65
|
+
* already-resolved credential the host handed it (which `credentialEnv`/`ANTHROPIC_API_KEY` already
|
|
66
|
+
* does, safely, today — see `AgentExecutorRunInput.credentialEnv`'s own doc). In that case this
|
|
67
|
+
* mirrors `prepareCodexHomeForRun`'s own accepted outcome for a missing credential file verbatim:
|
|
68
|
+
* "the spawned CLI runs unauthenticated" is documented, existing, precedented behavior in this file,
|
|
69
|
+
* not a new failure mode invented here. A host that needs the isolated child to stay logged in on
|
|
70
|
+
* such an install must supply a credential explicitly via `AgentExecutorRunInput.credentialEnv`
|
|
71
|
+
* (`ANTHROPIC_API_KEY` or `CLAUDE_CODE_OAUTH_TOKEN` — both outrank Keychain-based subscription login
|
|
72
|
+
* in Claude Code's own auth precedence, so the isolated child authenticates without ever needing the
|
|
73
|
+
* operator's personal Keychain entry at all) — see this fix's own handoff report for the operational
|
|
74
|
+
* consequence on a host with no such credential configured yet.
|
|
75
|
+
*
|
|
76
|
+
* **Never touches the real config directory.** `sourceConfigDir` is read-only throughout.
|
|
77
|
+
* @param runId - Embedded in the temp-dir prefix for traceability, same sanitization discipline as `prepareCodexHomeForRun`'s `safeRunId`.
|
|
78
|
+
* @param sourceConfigDir - Where to read a possible real `.credentials.json` from — see {@link resolveSourceClaudeConfigDir}.
|
|
79
|
+
* @param seams - Injectable mkdtemp/readFile/writeFile/removeDir, real filesystem by default.
|
|
80
|
+
* @throws Whatever `mkdtemp` rejects with — the caller ({@link stageClaudeConfigDir}) turns that into a pre-spawn `AGENT_SPAWN_FAILED` failure, matching `prepareCodexHomeForRun`'s own contract.
|
|
81
|
+
* @complexity O(1) plus one directory creation and up to one best-effort file read/write round trip.
|
|
82
|
+
*/
|
|
83
|
+
async function prepareClaudeConfigDirForRun(runId, sourceConfigDir, seams) {
|
|
84
|
+
const safeRunId = runId.replace(/[^A-Za-z0-9_-]/g, '-').slice(0, 80) || 'run';
|
|
85
|
+
const dir = await seams.mkdtemp({ prefix: `jini-claude-config-${safeRunId}-` });
|
|
86
|
+
try {
|
|
87
|
+
const credentialsPath = join(sourceConfigDir, '.credentials.json');
|
|
88
|
+
let credentialsRaw;
|
|
89
|
+
try {
|
|
90
|
+
credentialsRaw = await seams.readFile({ path: credentialsPath });
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// No file-based credential to copy (the common macOS-Keychain-only case) — see this
|
|
94
|
+
// function's own doc for why that is an accepted, documented outcome, not a failure here.
|
|
95
|
+
credentialsRaw = undefined;
|
|
96
|
+
}
|
|
97
|
+
if (credentialsRaw !== undefined) {
|
|
98
|
+
await seams.writeFile({ path: join(dir, '.credentials.json'), content: credentialsRaw });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
await seams.removeDir({ path: dir }).catch(() => {
|
|
103
|
+
// Best-effort only — the original error below is what the caller must see either way.
|
|
104
|
+
});
|
|
105
|
+
throw err;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
path: dir,
|
|
109
|
+
cleanup: async () => {
|
|
110
|
+
await seams.removeDir({ path: dir });
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Finding 1 of SEC-assistant-env-isolation-2026-09-07's one effect — stages this run's scratch
|
|
116
|
+
* `CLAUDE_CONFIG_DIR` directory, returning the prepared handle the launcher's `cleanupStagedFiles` should later
|
|
117
|
+
* release (see {@link prepareClaudeConfigDirForRun}'s own doc for why this is unconditional for `claude` runs, unlike
|
|
118
|
+
* the Codex home's gate on a host-configured MCP bridge strategy).
|
|
119
|
+
*
|
|
120
|
+
* Bound only to the real `claude` CLI's own definition id (`runtime-strategies.ts`) rather than to
|
|
121
|
+
* `externalMcpInjection === 'claude-mcp-json'` (which `codebuddy` also declares): isolating the operator's personal
|
|
122
|
+
* `~/.claude` is specific to the real `claude` CLI's own config resolution, not to every def that happens to share its
|
|
123
|
+
* `.mcp.json` delivery shape. Matches the existing `USER`-for-claude-login special case already singled
|
|
124
|
+
* out by id in `BASELINE_AGENT_ENV_KEYS`'s own doc in `launch.ts`.
|
|
125
|
+
* @param required.hostEnv - The daemon's own environment, threaded through to {@link resolveSourceClaudeConfigDir} rather than read from a module-level `process.env`, matching the Codex home staging's identical testability reasoning.
|
|
126
|
+
* @param optional.seams - Injectable mkdtemp/readFile/writeFile/removeDir, real filesystem by default.
|
|
127
|
+
* @throws Whatever staging rejects with; the caller turns that into a pre-spawn `AGENT_SPAWN_FAILED` failure.
|
|
128
|
+
* @complexity O(1) plus {@link prepareClaudeConfigDirForRun}'s own cost.
|
|
129
|
+
*/
|
|
130
|
+
export function stageClaudeConfigDir({ runId, hostEnv }, { seams } = {}) {
|
|
131
|
+
return prepareClaudeConfigDirForRun(runId, resolveSourceClaudeConfigDir({ hostEnv }), resolveClaudeConfigDirSeams(seams));
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=config-dir.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RuntimeBuildOptions } from '@jini-ai/core/contracts/agents';
|
|
2
|
+
/** The launcher's mutable run input, as far as this policy touches it. */
|
|
3
|
+
export type ClaudeFilesystemRunInput = RuntimeBuildOptions & {
|
|
4
|
+
filesystemRuntimeReadPaths?: readonly string[];
|
|
5
|
+
filesystemRuntimeTempBase?: string;
|
|
6
|
+
};
|
|
7
|
+
/** The runtime port's filesystem policy members the supported branch reads. */
|
|
8
|
+
export interface ClaudeFilesystemPolicy {
|
|
9
|
+
runtimePaths(required: {
|
|
10
|
+
launchPath: string;
|
|
11
|
+
}): readonly string[];
|
|
12
|
+
settings(required: {
|
|
13
|
+
options: RuntimeBuildOptions;
|
|
14
|
+
}): string;
|
|
15
|
+
}
|
|
16
|
+
export declare const claudeFilesystemAdapter: {
|
|
17
|
+
prepare({ input, spawnEnv, runtimeTemps }: {
|
|
18
|
+
input: ClaudeFilesystemRunInput;
|
|
19
|
+
spawnEnv: NodeJS.ProcessEnv;
|
|
20
|
+
runtimeTemps: string[];
|
|
21
|
+
}): Promise<void> | void;
|
|
22
|
+
unsupported({ input }: {
|
|
23
|
+
input: ClaudeFilesystemRunInput;
|
|
24
|
+
}): void;
|
|
25
|
+
supported({ input, launchPath, spawnEnv }: {
|
|
26
|
+
input: ClaudeFilesystemRunInput;
|
|
27
|
+
launchPath: string;
|
|
28
|
+
spawnEnv: NodeJS.ProcessEnv;
|
|
29
|
+
}, { filesystem }: {
|
|
30
|
+
filesystem: ClaudeFilesystemPolicy;
|
|
31
|
+
}): void;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=filesystem.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
async function prepareClaudeRuntimeTemp({ input, spawnEnv, runtimeTemps }) {
|
|
3
|
+
// Read denies also block create/unlink, so Claude's cwd files cannot live under /tmp.
|
|
4
|
+
// /var/tmp exists on macOS/Linux; its realpath plus /claude-<uid> must fit 44 bytes
|
|
5
|
+
// or the policy refuses launch instead of letting Bash fall back to shared scratch.
|
|
6
|
+
// mkdtemp creates a private 0700 directory; register cleanup before resolving aliases.
|
|
7
|
+
const runtimeTemp = await fs.mkdtemp('/var/tmp/jini-');
|
|
8
|
+
runtimeTemps.push(runtimeTemp);
|
|
9
|
+
input.filesystemRuntimeTempBase = await fs.realpath(runtimeTemp);
|
|
10
|
+
spawnEnv.CLAUDE_CODE_TMPDIR = input.filesystemRuntimeTempBase;
|
|
11
|
+
}
|
|
12
|
+
export const claudeFilesystemAdapter = {
|
|
13
|
+
prepare({ input, spawnEnv, runtimeTemps }) {
|
|
14
|
+
if (process.platform === 'win32')
|
|
15
|
+
return;
|
|
16
|
+
return prepareClaudeRuntimeTemp({ input, spawnEnv, runtimeTemps });
|
|
17
|
+
},
|
|
18
|
+
unsupported({ input }) {
|
|
19
|
+
// Personal Claude hooks/permissions stay excluded even on an unconfined CLI fallback.
|
|
20
|
+
input.settingSources = [];
|
|
21
|
+
},
|
|
22
|
+
supported({ input, launchPath, spawnEnv }, { filesystem }) {
|
|
23
|
+
input.filesystemRuntimeReadPaths = filesystem.runtimePaths({ launchPath });
|
|
24
|
+
// Validates host settings here so a malformed value fails cleanly; buildArgs merges again (idempotent).
|
|
25
|
+
input.settings = filesystem.settings({ options: input });
|
|
26
|
+
// A login environment can otherwise force auto-memory back on despite the host setting.
|
|
27
|
+
spawnEnv.CLAUDE_CODE_DISABLE_AUTO_MEMORY = '1';
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=filesystem.js.map
|
|
@@ -73,4 +73,4 @@ export declare const claudeAgentDef: {
|
|
|
73
73
|
deps?: import("@jini-ai/core/contracts/agents").ModelDiscoveryDeps;
|
|
74
74
|
}): Promise<import("@jini-ai/core/contracts/agents").DefaultModelResolution>;
|
|
75
75
|
};
|
|
76
|
-
//# sourceMappingURL=
|
|
76
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { resolveNativeCapabilityDenies, resolveNativeToolDenies } from '
|
|
2
|
-
import { claudeFilesystemSettings, validateFilesystemLaunch, validateReadOnlyExtraDirs } from '
|
|
3
|
-
import { createAgentModelDiscovery } from '
|
|
1
|
+
import { resolveNativeCapabilityDenies, resolveNativeToolDenies } from '../../native-tool-policy.js';
|
|
2
|
+
import { claudeFilesystemSettings, validateFilesystemLaunch, validateReadOnlyExtraDirs } from '../../claude-filesystem-policy.js';
|
|
3
|
+
import { createAgentModelDiscovery } from '../../model-discovery-native.js';
|
|
4
4
|
/**
|
|
5
5
|
* Claude Code has no dedicated image-attachment flag. imageDelivery: 'prompt-path' makes the
|
|
6
6
|
* executor append local image paths to the prompt and add their directories to extraAllowedDirs;
|
|
@@ -9,11 +9,11 @@ import { createAgentModelDiscovery } from '../model-discovery-native.js';
|
|
|
9
9
|
* A filesystemRoot launch instead validates these directories and omits --add-dir entirely;
|
|
10
10
|
* hosts must stage attachments inside that root (owner boundary introduced 2026-10-23).
|
|
11
11
|
*/
|
|
12
|
-
import { addDirArgs, nonDefaultFlag, permissionModeArgs, resolveCapabilities, sessionArgs } from '
|
|
13
|
-
import { buildClaudeMcpConfigArgs, DEFAULT_MODEL_OPTION } from '
|
|
14
|
-
import { loadMmdRouteModels } from '
|
|
15
|
-
import { loadAnthropicLiveModels, mergeLiveModels } from '
|
|
16
|
-
import { loadClaudeCodeModels } from '
|
|
12
|
+
import { addDirArgs, nonDefaultFlag, permissionModeArgs, resolveCapabilities, sessionArgs } from '../claude-compatible-args.js';
|
|
13
|
+
import { buildClaudeMcpConfigArgs, DEFAULT_MODEL_OPTION } from '../shared.js';
|
|
14
|
+
import { loadMmdRouteModels } from '../../mmd-routes.js';
|
|
15
|
+
import { loadAnthropicLiveModels, mergeLiveModels } from '../../anthropic-live-models.js';
|
|
16
|
+
import { loadClaudeCodeModels } from '../../claude-code-models.js';
|
|
17
17
|
/**
|
|
18
18
|
* The levels `claude --effort` accepts, as the CLI itself reports them when
|
|
19
19
|
* given an unknown one. Anything outside this set is dropped rather than
|
|
@@ -314,4 +314,4 @@ export const claudeAgentDef = {
|
|
|
314
314
|
// behalf rather than this file forwarding `_imagePaths` itself.
|
|
315
315
|
imageDelivery: 'prompt-path',
|
|
316
316
|
};
|
|
317
|
-
//# sourceMappingURL=
|
|
317
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Stage Claude's HTTP capability outside the project; only this private path enters argv.
|
|
2
|
+
* @returns A private config path and removal of only its owned directory.
|
|
3
|
+
* @throws Filesystem staging errors after removing partial output.
|
|
4
|
+
* @complexity O(config bytes), one project read and one private config write.
|
|
5
|
+
*/
|
|
6
|
+
export declare function prepareClaudeHttpMcpConfig({ cwd, endpoint, serverName }: {
|
|
7
|
+
cwd: string;
|
|
8
|
+
endpoint: {
|
|
9
|
+
readonly url: string;
|
|
10
|
+
readonly token: string;
|
|
11
|
+
};
|
|
12
|
+
serverName: string;
|
|
13
|
+
}, { inheritUserMcp, readFile }?: {
|
|
14
|
+
inheritUserMcp?: boolean;
|
|
15
|
+
readFile?: (required: {
|
|
16
|
+
readonly path: string;
|
|
17
|
+
}) => Promise<string>;
|
|
18
|
+
}): Promise<{
|
|
19
|
+
path: string;
|
|
20
|
+
cleanup: () => Promise<void>;
|
|
21
|
+
}>;
|
|
22
|
+
//# sourceMappingURL=mcp-config.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { defaultReadMcpJsonFile, mergeMcpJsonContent } from './mcp-json.js';
|
|
5
|
+
/** Stage Claude's HTTP capability outside the project; only this private path enters argv.
|
|
6
|
+
* @returns A private config path and removal of only its owned directory.
|
|
7
|
+
* @throws Filesystem staging errors after removing partial output.
|
|
8
|
+
* @complexity O(config bytes), one project read and one private config write.
|
|
9
|
+
*/
|
|
10
|
+
export async function prepareClaudeHttpMcpConfig({ cwd, endpoint, serverName }, { inheritUserMcp = true, readFile = defaultReadMcpJsonFile } = {}) {
|
|
11
|
+
const dir = await fs.mkdtemp(join(tmpdir(), 'jini-claude-mcp-'));
|
|
12
|
+
const cleanup = () => fs.rm(dir, { recursive: true, force: true });
|
|
13
|
+
try {
|
|
14
|
+
let existingRaw;
|
|
15
|
+
if (inheritUserMcp)
|
|
16
|
+
existingRaw = await readFile({ path: join(cwd, '.mcp.json') }).catch(() => undefined);
|
|
17
|
+
const content = mergeMcpJsonContent({ existingRaw, serverName, serverEntry: {
|
|
18
|
+
type: 'http', url: endpoint.url, headers: { Authorization: `Bearer ${endpoint.token}` },
|
|
19
|
+
} });
|
|
20
|
+
const path = join(dir, 'mcp.json');
|
|
21
|
+
await fs.writeFile(path, content, { encoding: 'utf8', mode: 0o600, flag: 'wx' });
|
|
22
|
+
return { path, cleanup };
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
await cleanup();
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=mcp-config.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type McpServerEntryLike } from './mcp-json.js';
|
|
2
|
+
export declare function buildClaudeMcpDelivery<Entry extends McpServerEntryLike>({ cwd, runId, serverEntry }: {
|
|
3
|
+
cwd: string;
|
|
4
|
+
runId: string;
|
|
5
|
+
serverEntry: Entry;
|
|
6
|
+
}): {
|
|
7
|
+
kind: 'claude-mcp-json';
|
|
8
|
+
mcpJsonPath: string;
|
|
9
|
+
serverEntry: Entry;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The `'claude-mcp-json'` mechanism's one effect: writes (merging, never clobbering — see
|
|
13
|
+
* {@link mergeMcpJsonContent}) this run's own config — the project's own servers merged with this
|
|
14
|
+
* run's `jini` bridge entry — to the run-scoped path ({@link mcpJsonPathForRun}) the def was already
|
|
15
|
+
* handed via `RuntimeContext.mcpJsonPath`, so the def's own `--strict-mcp-config --mcp-config <path>`
|
|
16
|
+
* argv has a real file to point at by spawn time, instead of auto-discovering `cwd/.mcp.json` (which
|
|
17
|
+
* needs an interactive trust prompt a headless spawn can never answer — confirmed live 2026-07-30,
|
|
18
|
+
* see `@jini-ai/agent-runtime`'s `defs/claude/index.ts`).
|
|
19
|
+
*
|
|
20
|
+
* Reads `cwd/.mcp.json` and writes `delivery.mcpJsonPath`: the project's file is a merge source only,
|
|
21
|
+
* never a write target. See {@link mcpJsonPathForRun} for why one file per run is load-bearing rather
|
|
22
|
+
* than cosmetic, and why the read and write paths must differ.
|
|
23
|
+
*
|
|
24
|
+
* A no-op for every other delivery mechanism, which is expressed by the caller simply not having a
|
|
25
|
+
* `'claude-mcp-json'` delivery to hand it rather than by a strategy re-check in here.
|
|
26
|
+
* @param cwd - The run's working directory, so the project's own `.mcp.json` can be read as the
|
|
27
|
+
* merge base — not carried on `delivery` itself, since that only describes the write target.
|
|
28
|
+
* @param delivery - The already-built `'claude-mcp-json'` delivery (path + entry). Both fields come
|
|
29
|
+
* from `buildMcpBridgeDelivery`, so the credential was resolved exactly once, for this run.
|
|
30
|
+
* @param options - Supplies the injectable `readFile`/`writeFile` seams.
|
|
31
|
+
* @throws Whatever `writeFile` rejects with — the caller (`run()`) turns that into a pre-spawn
|
|
32
|
+
* `AGENT_SPAWN_FAILED` failure, matching the pre-spawn filesystem guards in `launch.ts`
|
|
33
|
+
* (`stagePromptFile`'s own try/catch).
|
|
34
|
+
* @complexity O(1) plus one `readFile`/`writeFile` round trip.
|
|
35
|
+
* @overallScore 100/100
|
|
36
|
+
*/
|
|
37
|
+
export declare function writeMcpJsonForRun({ cwd, delivery, options, serverName }: {
|
|
38
|
+
cwd: string;
|
|
39
|
+
delivery: {
|
|
40
|
+
readonly kind: string;
|
|
41
|
+
readonly mcpJsonPath?: string;
|
|
42
|
+
readonly serverEntry?: McpServerEntryLike;
|
|
43
|
+
};
|
|
44
|
+
options: {
|
|
45
|
+
readonly readFile?: (required: {
|
|
46
|
+
readonly path: string;
|
|
47
|
+
}) => Promise<string>;
|
|
48
|
+
readonly writeFile?: (required: {
|
|
49
|
+
readonly path: string;
|
|
50
|
+
readonly content: string;
|
|
51
|
+
}) => Promise<void>;
|
|
52
|
+
};
|
|
53
|
+
serverName: string;
|
|
54
|
+
}, { inheritUserConfig }?: {
|
|
55
|
+
inheritUserConfig?: boolean | undefined;
|
|
56
|
+
}): Promise<string>;
|
|
57
|
+
//# sourceMappingURL=mcp-delivery.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { defaultReadMcpJsonFile, defaultWriteMcpJsonFile, mergeMcpJsonContent } from './mcp-json.js';
|
|
3
|
+
export function buildClaudeMcpDelivery({ cwd, runId, serverEntry }) {
|
|
4
|
+
return { kind: 'claude-mcp-json', mcpJsonPath: mcpJsonPathForRun(cwd, runId), serverEntry };
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* This run's own MCP config path, inside `cwd` but deliberately **not** `cwd/.mcp.json`.
|
|
8
|
+
*
|
|
9
|
+
* A shared filename cannot carry two runs' identities at once, and that is exactly what the file
|
|
10
|
+
* carries: `mcpServers.jini.env` holds this run's `JINI_RUN_ID` and its bearer `JINI_DAEMON_TOKEN`.
|
|
11
|
+
* A spawned CLI reads its MCP config when it starts its client, not synchronously at spawn — so with
|
|
12
|
+
* one shared file, a second run in the same directory overwrote the entry the first run's child had
|
|
13
|
+
* not read yet, and that child's `jini-mcp` subprocess then called back carrying the *other* run's id
|
|
14
|
+
* and token: run A's tool calls executing inside run B's authority context. Concurrent runs in one
|
|
15
|
+
* working directory are supported by design (see `McpJsonInjectionOptions.credential`'s doc on why the
|
|
16
|
+
* credential is a per-run resolver at all), so the resolution is one file per run, not a lock that
|
|
17
|
+
* refuses the second run.
|
|
18
|
+
*
|
|
19
|
+
* Naming it after the run also means the project's own `.mcp.json` is never written at all — it stays
|
|
20
|
+
* purely a merge source, so there is no original content to restore afterwards either.
|
|
21
|
+
*
|
|
22
|
+
* The run id is host-supplied and lands in a filename, so everything outside `[A-Za-z0-9_-]` is
|
|
23
|
+
* replaced (dots included — a `..` segment must not survive) and the result is length-capped. Real run
|
|
24
|
+
* ids are UUIDs, which pass through untouched; the cap could in principle collide two ids sharing a
|
|
25
|
+
* 128-character prefix, which no id shape this daemon mints can produce.
|
|
26
|
+
* @complexity O(n) in the run id's length.
|
|
27
|
+
*/
|
|
28
|
+
function mcpJsonPathForRun(cwd, runId) {
|
|
29
|
+
const safeRunId = runId.replace(/[^A-Za-z0-9_-]/g, '_').slice(0, 128);
|
|
30
|
+
return join(cwd, `.mcp.jini-${safeRunId}.json`);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The `'claude-mcp-json'` mechanism's one effect: writes (merging, never clobbering — see
|
|
34
|
+
* {@link mergeMcpJsonContent}) this run's own config — the project's own servers merged with this
|
|
35
|
+
* run's `jini` bridge entry — to the run-scoped path ({@link mcpJsonPathForRun}) the def was already
|
|
36
|
+
* handed via `RuntimeContext.mcpJsonPath`, so the def's own `--strict-mcp-config --mcp-config <path>`
|
|
37
|
+
* argv has a real file to point at by spawn time, instead of auto-discovering `cwd/.mcp.json` (which
|
|
38
|
+
* needs an interactive trust prompt a headless spawn can never answer — confirmed live 2026-07-30,
|
|
39
|
+
* see `@jini-ai/agent-runtime`'s `defs/claude/index.ts`).
|
|
40
|
+
*
|
|
41
|
+
* Reads `cwd/.mcp.json` and writes `delivery.mcpJsonPath`: the project's file is a merge source only,
|
|
42
|
+
* never a write target. See {@link mcpJsonPathForRun} for why one file per run is load-bearing rather
|
|
43
|
+
* than cosmetic, and why the read and write paths must differ.
|
|
44
|
+
*
|
|
45
|
+
* A no-op for every other delivery mechanism, which is expressed by the caller simply not having a
|
|
46
|
+
* `'claude-mcp-json'` delivery to hand it rather than by a strategy re-check in here.
|
|
47
|
+
* @param cwd - The run's working directory, so the project's own `.mcp.json` can be read as the
|
|
48
|
+
* merge base — not carried on `delivery` itself, since that only describes the write target.
|
|
49
|
+
* @param delivery - The already-built `'claude-mcp-json'` delivery (path + entry). Both fields come
|
|
50
|
+
* from `buildMcpBridgeDelivery`, so the credential was resolved exactly once, for this run.
|
|
51
|
+
* @param options - Supplies the injectable `readFile`/`writeFile` seams.
|
|
52
|
+
* @throws Whatever `writeFile` rejects with — the caller (`run()`) turns that into a pre-spawn
|
|
53
|
+
* `AGENT_SPAWN_FAILED` failure, matching the pre-spawn filesystem guards in `launch.ts`
|
|
54
|
+
* (`stagePromptFile`'s own try/catch).
|
|
55
|
+
* @complexity O(1) plus one `readFile`/`writeFile` round trip.
|
|
56
|
+
* @overallScore 100/100
|
|
57
|
+
*/
|
|
58
|
+
export async function writeMcpJsonForRun({ cwd, delivery, options, serverName }, { inheritUserConfig = true } = {}) {
|
|
59
|
+
if (delivery.kind !== 'claude-mcp-json' || delivery.mcpJsonPath === undefined || delivery.serverEntry === undefined)
|
|
60
|
+
throw new TypeError('Unexpected MCP delivery');
|
|
61
|
+
const readFileFn = options.readFile ?? defaultReadMcpJsonFile;
|
|
62
|
+
const writeFileFn = options.writeFile ?? defaultWriteMcpJsonFile;
|
|
63
|
+
let existingRaw;
|
|
64
|
+
try {
|
|
65
|
+
existingRaw = inheritUserConfig ? await readFileFn({ path: join(cwd, '.mcp.json') }) : undefined;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
// No existing file (ENOENT — the common case) or unreadable for any other reason: both
|
|
69
|
+
// degrade to "start fresh", matching mergeMcpJsonContent's own doc.
|
|
70
|
+
existingRaw = undefined;
|
|
71
|
+
}
|
|
72
|
+
await writeFileFn({ path: delivery.mcpJsonPath, content: mergeMcpJsonContent({ existingRaw: existingRaw, serverEntry: delivery.serverEntry, serverName }) });
|
|
73
|
+
return delivery.mcpJsonPath;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=mcp-delivery.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** The `.mcp.json` `mcpServers` entry a bridge delivery carries; the daemon's richer entry type is assignable to this. */
|
|
2
|
+
export interface McpServerEntryLike {
|
|
3
|
+
readonly command: string;
|
|
4
|
+
readonly args: string[];
|
|
5
|
+
readonly env: Readonly<Record<string, string>>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Merges the bridge's entry (under `serverName`) into an existing `.mcp.json`'s `mcpServers` map, preserving
|
|
9
|
+
* every other key and every other registered server untouched. A missing (`existingRaw ===
|
|
10
|
+
* undefined`), empty, or unparseable-as-a-JSON-object existing file all degrade to "start from an
|
|
11
|
+
* empty document" rather than throwing — an unparseable project `.mcp.json` is a pre-existing
|
|
12
|
+
* problem this driver did not create and cannot safely repair, so it is deliberately overwritten
|
|
13
|
+
* with a fresh, valid file containing just this run's bridge entry rather than left broken or
|
|
14
|
+
* left blocking the run. Pure — no I/O — so every branch is directly assertable.
|
|
15
|
+
* @complexity O(1) plus `JSON.parse`/`JSON.stringify`'s own cost on a small config file.
|
|
16
|
+
* @overallScore 100/100
|
|
17
|
+
*/
|
|
18
|
+
export declare function mergeMcpJsonContent({ existingRaw, serverEntry, serverName }: {
|
|
19
|
+
readonly existingRaw: string | undefined;
|
|
20
|
+
readonly serverEntry: McpServerEntryLike | {
|
|
21
|
+
readonly type: 'http';
|
|
22
|
+
readonly url: string;
|
|
23
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
24
|
+
};
|
|
25
|
+
readonly serverName: string;
|
|
26
|
+
}): string;
|
|
27
|
+
export declare function defaultReadMcpJsonFile({ path }: {
|
|
28
|
+
readonly path: string;
|
|
29
|
+
}): Promise<string>;
|
|
30
|
+
export declare function defaultWriteMcpJsonFile({ path, content }: {
|
|
31
|
+
readonly path: string;
|
|
32
|
+
readonly content: string;
|
|
33
|
+
}): Promise<void>;
|
|
34
|
+
//# sourceMappingURL=mcp-json.d.ts.map
|