amalgm 0.1.75 → 0.1.76
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/package.json +1 -1
- package/runtime/scripts/amalgm-mcp/agent-config/importers/claude.js +52 -0
- package/runtime/scripts/amalgm-mcp/agent-config/importers/codex.js +36 -0
- package/runtime/scripts/amalgm-mcp/agent-config/importers/common.js +115 -0
- package/runtime/scripts/amalgm-mcp/agent-config/importers/index.js +14 -0
- package/runtime/scripts/amalgm-mcp/agent-config/importers/opencode.js +59 -0
- package/runtime/scripts/amalgm-mcp/agent-config/renderers/hooks.js +55 -0
- package/runtime/scripts/amalgm-mcp/agent-config/renderers/instructions.js +54 -0
- package/runtime/scripts/amalgm-mcp/agent-config/rest.js +168 -0
- package/runtime/scripts/amalgm-mcp/agent-config/schema.js +248 -0
- package/runtime/scripts/amalgm-mcp/agent-config/store.js +123 -0
- package/runtime/scripts/amalgm-mcp/agents/hooks.js +2 -0
- package/runtime/scripts/amalgm-mcp/agents/rest.js +45 -2
- package/runtime/scripts/amalgm-mcp/agents/talk.js +20 -4
- package/runtime/scripts/amalgm-mcp/automations/tool-actions.js +52 -9
- package/runtime/scripts/amalgm-mcp/automations/tools.js +3 -3
- package/runtime/scripts/amalgm-mcp/events/internal-workflows.js +3 -3
- package/runtime/scripts/amalgm-mcp/lib/chat-payloads.js +101 -0
- package/runtime/scripts/amalgm-mcp/server/core-tools.js +10 -10
- package/runtime/scripts/amalgm-mcp/server/local-service-router.js +2 -0
- package/runtime/scripts/amalgm-mcp/server/routes/agents.js +13 -0
- package/runtime/scripts/amalgm-mcp/server/routes/chat-payloads.js +37 -0
- package/runtime/scripts/amalgm-mcp/state/db.js +11 -0
- package/runtime/scripts/amalgm-mcp/state/snapshot.js +13 -3
- package/runtime/scripts/amalgm-mcp/tests/agent-config.test.js +80 -0
- package/runtime/scripts/amalgm-mcp/tests/automations-store-runner.test.js +17 -5
- package/runtime/scripts/amalgm-mcp/tests/chat-payloads.test.js +71 -0
- package/runtime/scripts/amalgm-mcp/tests/core-tools.test.js +9 -9
- package/runtime/scripts/amalgm-mcp/tests/mcp-surface.test.js +29 -0
- package/runtime/scripts/amalgm-mcp/tests/system-catalog.test.js +21 -16
- package/runtime/scripts/amalgm-mcp/tests/toolbox-service.test.js +9 -7
- package/runtime/scripts/amalgm-mcp/toolbox/selection.js +21 -1
- package/runtime/scripts/amalgm-mcp/toolbox/system-catalog.js +16 -1
- package/runtime/scripts/amalgm-mcp/workflows/compiler.js +1 -1
- package/runtime/scripts/amalgm-mcp/workflows/runner.js +8 -2
- package/runtime/scripts/chat-core/adapters/claude.js +2 -2
- package/runtime/scripts/chat-core/adapters/codex.js +82 -12
- package/runtime/scripts/chat-core/auth.js +13 -4
- package/runtime/scripts/chat-core/contract.js +18 -0
- package/runtime/scripts/chat-core/tests/auth.test.js +27 -2
- package/runtime/scripts/chat-core/tests/native-config.test.js +65 -12
- package/runtime/scripts/chat-core/tooling/native-config.js +73 -0
- package/runtime/scripts/chat-core/tooling/runtime-home.js +2 -2
- package/runtime/scripts/chat-core/tooling/system-prompt.js +3 -1
- package/runtime/scripts/local-gateway.js +1 -0
|
@@ -238,6 +238,65 @@ function syncOpenCodeNativeConfig(runtimeHome) {
|
|
|
238
238
|
};
|
|
239
239
|
}
|
|
240
240
|
|
|
241
|
+
function copyJsonSubsetIfPresent(source, target, keys) {
|
|
242
|
+
const data = readJsonFile(source);
|
|
243
|
+
if (!data || typeof data !== 'object' || Array.isArray(data)) return false;
|
|
244
|
+
const out = {};
|
|
245
|
+
for (const key of keys) {
|
|
246
|
+
if (data[key] !== undefined) out[key] = data[key];
|
|
247
|
+
}
|
|
248
|
+
if (Object.keys(out).length === 0) return false;
|
|
249
|
+
if (!ensureDirectory(path.dirname(target)) || !canWriteFileTarget(target)) return false;
|
|
250
|
+
fs.writeFileSync(target, JSON.stringify(out, null, 2), { mode: 0o600 });
|
|
251
|
+
try { fs.chmodSync(target, 0o600); } catch {}
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function syncCodexProviderAuth(runtimeHome) {
|
|
256
|
+
if (!runtimeHome) return null;
|
|
257
|
+
const sourceDir = path.join(nativeHome(), '.codex');
|
|
258
|
+
fs.mkdirSync(runtimeHome, { recursive: true });
|
|
259
|
+
ensureHomeAlias(runtimeHome, '.codex');
|
|
260
|
+
const copied = copyFileIfPresent(path.join(sourceDir, 'auth.json'), path.join(runtimeHome, 'auth.json'));
|
|
261
|
+
if (copied) copyFileIfPresent(path.join(sourceDir, 'auth.json'), path.join(runtimeHome, '.codex', 'auth.json'));
|
|
262
|
+
return copied ? { sourceDir, runtimeHome, copied: true, authOnly: true } : null;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function syncClaudeProviderAuth(runtimeHome) {
|
|
266
|
+
if (!runtimeHome) return null;
|
|
267
|
+
const home = nativeHome();
|
|
268
|
+
const sourceDir = path.join(home, '.claude');
|
|
269
|
+
fs.mkdirSync(runtimeHome, { recursive: true });
|
|
270
|
+
ensureHomeAlias(runtimeHome, '.claude');
|
|
271
|
+
const copiedCredentials = copyFileIfPresent(
|
|
272
|
+
path.join(sourceDir, '.credentials.json'),
|
|
273
|
+
path.join(runtimeHome, '.credentials.json'),
|
|
274
|
+
);
|
|
275
|
+
const copiedOauth = copyJsonSubsetIfPresent(
|
|
276
|
+
path.join(home, '.claude.json'),
|
|
277
|
+
path.join(runtimeHome, '.claude.json'),
|
|
278
|
+
['claudeAiOauth', 'oauthAccount'],
|
|
279
|
+
) || copyJsonSubsetIfPresent(
|
|
280
|
+
path.join(sourceDir, '.claude.json'),
|
|
281
|
+
path.join(runtimeHome, '.claude.json'),
|
|
282
|
+
['claudeAiOauth', 'oauthAccount'],
|
|
283
|
+
);
|
|
284
|
+
const keychain = ensureNativeKeychainAlias(runtimeHome);
|
|
285
|
+
return copiedCredentials || copiedOauth || keychain
|
|
286
|
+
? { sourceDir, runtimeHome, copied: copiedCredentials || copiedOauth, keychain, authOnly: true }
|
|
287
|
+
: null;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function syncOpenCodeProviderAuth(runtimeHome) {
|
|
291
|
+
if (!runtimeHome) return null;
|
|
292
|
+
const home = nativeHome();
|
|
293
|
+
const source = path.join(home, '.local', 'share', 'opencode', 'auth.json');
|
|
294
|
+
const target = path.join(runtimeHome, '.local', 'share', 'opencode', 'auth.json');
|
|
295
|
+
fs.mkdirSync(runtimeHome, { recursive: true });
|
|
296
|
+
const copied = copyFileIfPresent(source, target);
|
|
297
|
+
return copied ? { sourceDir: path.dirname(source), runtimeHome, copied: true, authOnly: true } : null;
|
|
298
|
+
}
|
|
299
|
+
|
|
241
300
|
function readJsonFile(file) {
|
|
242
301
|
try {
|
|
243
302
|
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
@@ -289,6 +348,16 @@ function syncNativeHarnessConfig(contract) {
|
|
|
289
348
|
return null;
|
|
290
349
|
}
|
|
291
350
|
|
|
351
|
+
function syncNativeProviderAuth(contract) {
|
|
352
|
+
const runtimeHome = contract?.auth?.runtimeHome;
|
|
353
|
+
if (!runtimeHome) return null;
|
|
354
|
+
if (contract.authMethod !== 'provider_auth') return null;
|
|
355
|
+
if (contract.harness === 'codex') return syncCodexProviderAuth(runtimeHome);
|
|
356
|
+
if (contract.harness === 'claude_code') return syncClaudeProviderAuth(runtimeHome);
|
|
357
|
+
if (contract.harness === 'opencode') return syncOpenCodeProviderAuth(runtimeHome);
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
|
|
292
361
|
module.exports = {
|
|
293
362
|
__private: {
|
|
294
363
|
claudeNativeHookSettings,
|
|
@@ -301,8 +370,12 @@ module.exports = {
|
|
|
301
370
|
shouldCopyConfigPath,
|
|
302
371
|
},
|
|
303
372
|
claudeNativeHookSettings,
|
|
373
|
+
syncClaudeProviderAuth,
|
|
304
374
|
syncClaudeNativeConfig,
|
|
375
|
+
syncCodexProviderAuth,
|
|
305
376
|
syncCodexNativeConfig,
|
|
306
377
|
syncNativeHarnessConfig,
|
|
378
|
+
syncNativeProviderAuth,
|
|
379
|
+
syncOpenCodeProviderAuth,
|
|
307
380
|
syncOpenCodeNativeConfig,
|
|
308
381
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const { runtimeEnv } = require('../auth');
|
|
5
|
-
const {
|
|
5
|
+
const { syncNativeProviderAuth } = require('./native-config');
|
|
6
6
|
|
|
7
7
|
function managedRuntimeHome(contract) {
|
|
8
8
|
const runtimeHome = contract?.auth?.runtimeHome;
|
|
@@ -16,7 +16,7 @@ function prepareHarnessRuntime(contract, baseEnv = process.env) {
|
|
|
16
16
|
const runtimeHome = managedRuntimeHome(contract);
|
|
17
17
|
fs.mkdirSync(runtimeHome, { recursive: true });
|
|
18
18
|
const syncInfo = contract?.authMethod === 'provider_auth'
|
|
19
|
-
?
|
|
19
|
+
? syncNativeProviderAuth(contract)
|
|
20
20
|
: null;
|
|
21
21
|
return {
|
|
22
22
|
runtimeHome,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
const { PLATFORM_CONTEXT } = require('../../chat-server/config');
|
|
4
4
|
const { activeMemoryContextBlock, instructionsContextBlock } = require('./active-memory');
|
|
5
5
|
const { passiveMemoryContextBlock } = require('./passive-memory');
|
|
6
|
+
const { renderAgentInstructions } = require('../../amalgm-mcp/agent-config/renderers/instructions');
|
|
6
7
|
|
|
7
8
|
function trimBlock(value) {
|
|
8
9
|
return String(value || '').trim();
|
|
@@ -11,7 +12,8 @@ function trimBlock(value) {
|
|
|
11
12
|
function composeSystemPrompt(contract) {
|
|
12
13
|
const parts = [];
|
|
13
14
|
const platform = trimBlock(PLATFORM_CONTEXT);
|
|
14
|
-
const custom = trimBlock(contract?.systemPrompt)
|
|
15
|
+
const custom = trimBlock(contract?.systemPrompt)
|
|
16
|
+
|| trimBlock(renderAgentInstructions(contract?.agentConfig, { includeAgentToAgentPrompt: false }));
|
|
15
17
|
const instructions = contract?.providerSessionId ? '' : trimBlock(instructionsContextBlock(contract));
|
|
16
18
|
const active = contract?.providerSessionId ? '' : trimBlock(activeMemoryContextBlock(contract));
|
|
17
19
|
const passive = contract?.providerSessionId ? '' : trimBlock(passiveMemoryContextBlock());
|