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.
Files changed (45) hide show
  1. package/package.json +1 -1
  2. package/runtime/scripts/amalgm-mcp/agent-config/importers/claude.js +52 -0
  3. package/runtime/scripts/amalgm-mcp/agent-config/importers/codex.js +36 -0
  4. package/runtime/scripts/amalgm-mcp/agent-config/importers/common.js +115 -0
  5. package/runtime/scripts/amalgm-mcp/agent-config/importers/index.js +14 -0
  6. package/runtime/scripts/amalgm-mcp/agent-config/importers/opencode.js +59 -0
  7. package/runtime/scripts/amalgm-mcp/agent-config/renderers/hooks.js +55 -0
  8. package/runtime/scripts/amalgm-mcp/agent-config/renderers/instructions.js +54 -0
  9. package/runtime/scripts/amalgm-mcp/agent-config/rest.js +168 -0
  10. package/runtime/scripts/amalgm-mcp/agent-config/schema.js +248 -0
  11. package/runtime/scripts/amalgm-mcp/agent-config/store.js +123 -0
  12. package/runtime/scripts/amalgm-mcp/agents/hooks.js +2 -0
  13. package/runtime/scripts/amalgm-mcp/agents/rest.js +45 -2
  14. package/runtime/scripts/amalgm-mcp/agents/talk.js +20 -4
  15. package/runtime/scripts/amalgm-mcp/automations/tool-actions.js +52 -9
  16. package/runtime/scripts/amalgm-mcp/automations/tools.js +3 -3
  17. package/runtime/scripts/amalgm-mcp/events/internal-workflows.js +3 -3
  18. package/runtime/scripts/amalgm-mcp/lib/chat-payloads.js +101 -0
  19. package/runtime/scripts/amalgm-mcp/server/core-tools.js +10 -10
  20. package/runtime/scripts/amalgm-mcp/server/local-service-router.js +2 -0
  21. package/runtime/scripts/amalgm-mcp/server/routes/agents.js +13 -0
  22. package/runtime/scripts/amalgm-mcp/server/routes/chat-payloads.js +37 -0
  23. package/runtime/scripts/amalgm-mcp/state/db.js +11 -0
  24. package/runtime/scripts/amalgm-mcp/state/snapshot.js +13 -3
  25. package/runtime/scripts/amalgm-mcp/tests/agent-config.test.js +80 -0
  26. package/runtime/scripts/amalgm-mcp/tests/automations-store-runner.test.js +17 -5
  27. package/runtime/scripts/amalgm-mcp/tests/chat-payloads.test.js +71 -0
  28. package/runtime/scripts/amalgm-mcp/tests/core-tools.test.js +9 -9
  29. package/runtime/scripts/amalgm-mcp/tests/mcp-surface.test.js +29 -0
  30. package/runtime/scripts/amalgm-mcp/tests/system-catalog.test.js +21 -16
  31. package/runtime/scripts/amalgm-mcp/tests/toolbox-service.test.js +9 -7
  32. package/runtime/scripts/amalgm-mcp/toolbox/selection.js +21 -1
  33. package/runtime/scripts/amalgm-mcp/toolbox/system-catalog.js +16 -1
  34. package/runtime/scripts/amalgm-mcp/workflows/compiler.js +1 -1
  35. package/runtime/scripts/amalgm-mcp/workflows/runner.js +8 -2
  36. package/runtime/scripts/chat-core/adapters/claude.js +2 -2
  37. package/runtime/scripts/chat-core/adapters/codex.js +82 -12
  38. package/runtime/scripts/chat-core/auth.js +13 -4
  39. package/runtime/scripts/chat-core/contract.js +18 -0
  40. package/runtime/scripts/chat-core/tests/auth.test.js +27 -2
  41. package/runtime/scripts/chat-core/tests/native-config.test.js +65 -12
  42. package/runtime/scripts/chat-core/tooling/native-config.js +73 -0
  43. package/runtime/scripts/chat-core/tooling/runtime-home.js +2 -2
  44. package/runtime/scripts/chat-core/tooling/system-prompt.js +3 -1
  45. 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 { syncNativeHarnessConfig } = require('./native-config');
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
- ? syncNativeHarnessConfig(contract)
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());
@@ -144,6 +144,7 @@ const MCP_PREFIXES = [
144
144
  '/state',
145
145
  '/local',
146
146
  '/credentials',
147
+ '/chat-payloads',
147
148
  '/email',
148
149
  '/slack',
149
150
  '/user-api-keys',