amalgm 0.0.0 → 0.0.32

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 (116) hide show
  1. package/README.md +41 -1
  2. package/bin/amalgm.js +8 -2
  3. package/lib/auth-store.js +223 -0
  4. package/lib/cli.js +1132 -0
  5. package/lib/paths.js +30 -0
  6. package/lib/supervisor.js +476 -0
  7. package/lib/tunnel-chat.js +328 -0
  8. package/lib/tunnel-events.js +499 -0
  9. package/package.json +30 -3
  10. package/runtime/README.md +4 -0
  11. package/runtime/lib/chatInput.js +315 -0
  12. package/runtime/lib/harnesses.js +988 -0
  13. package/runtime/lib/local/amalgmStore.js +136 -0
  14. package/runtime/lib/local/credentialResolver.js +425 -0
  15. package/runtime/lib/mcpApps/registry.js +619 -0
  16. package/runtime/package.json +5 -0
  17. package/runtime/scripts/amalgm-mcp/agents/rest.js +144 -0
  18. package/runtime/scripts/amalgm-mcp/agents/store.js +684 -0
  19. package/runtime/scripts/amalgm-mcp/agents/talk.js +1162 -0
  20. package/runtime/scripts/amalgm-mcp/agents/tools.js +221 -0
  21. package/runtime/scripts/amalgm-mcp/artifacts/advertise.js +132 -0
  22. package/runtime/scripts/amalgm-mcp/artifacts/rest.js +103 -0
  23. package/runtime/scripts/amalgm-mcp/artifacts/store.js +157 -0
  24. package/runtime/scripts/amalgm-mcp/artifacts/supervisor.js +402 -0
  25. package/runtime/scripts/amalgm-mcp/artifacts/tools.js +176 -0
  26. package/runtime/scripts/amalgm-mcp/browser/page.js +637 -0
  27. package/runtime/scripts/amalgm-mcp/browser/tools.js +688 -0
  28. package/runtime/scripts/amalgm-mcp/config.js +140 -0
  29. package/runtime/scripts/amalgm-mcp/credentials/rest.js +45 -0
  30. package/runtime/scripts/amalgm-mcp/deps.js +40 -0
  31. package/runtime/scripts/amalgm-mcp/email/inbound.js +215 -0
  32. package/runtime/scripts/amalgm-mcp/events/executor.js +179 -0
  33. package/runtime/scripts/amalgm-mcp/events/ingress.js +113 -0
  34. package/runtime/scripts/amalgm-mcp/events/matcher.js +125 -0
  35. package/runtime/scripts/amalgm-mcp/events/rest.js +200 -0
  36. package/runtime/scripts/amalgm-mcp/events/ring-buffer.js +19 -0
  37. package/runtime/scripts/amalgm-mcp/events/store.js +113 -0
  38. package/runtime/scripts/amalgm-mcp/events/tools.js +306 -0
  39. package/runtime/scripts/amalgm-mcp/events/webhook-url.js +28 -0
  40. package/runtime/scripts/amalgm-mcp/fs/rest.js +293 -0
  41. package/runtime/scripts/amalgm-mcp/index.js +100 -0
  42. package/runtime/scripts/amalgm-mcp/lib/chat-runner.js +167 -0
  43. package/runtime/scripts/amalgm-mcp/lib/email-md.js +288 -0
  44. package/runtime/scripts/amalgm-mcp/lib/mcp-resolver.js +63 -0
  45. package/runtime/scripts/amalgm-mcp/lib/prefs.js +441 -0
  46. package/runtime/scripts/amalgm-mcp/lib/storage.js +92 -0
  47. package/runtime/scripts/amalgm-mcp/lib/supabase.js +118 -0
  48. package/runtime/scripts/amalgm-mcp/lib/tool-result.js +177 -0
  49. package/runtime/scripts/amalgm-mcp/local/rest.js +87 -0
  50. package/runtime/scripts/amalgm-mcp/mcp-connections/rest.js +234 -0
  51. package/runtime/scripts/amalgm-mcp/notify/index.js +107 -0
  52. package/runtime/scripts/amalgm-mcp/server/core-tools.js +20 -0
  53. package/runtime/scripts/amalgm-mcp/server/http.js +377 -0
  54. package/runtime/scripts/amalgm-mcp/server/mcp.js +127 -0
  55. package/runtime/scripts/amalgm-mcp/slack/inbound.js +200 -0
  56. package/runtime/scripts/amalgm-mcp/state/db.js +194 -0
  57. package/runtime/scripts/amalgm-mcp/state/events.js +113 -0
  58. package/runtime/scripts/amalgm-mcp/state/rest.js +64 -0
  59. package/runtime/scripts/amalgm-mcp/state/snapshot.js +76 -0
  60. package/runtime/scripts/amalgm-mcp/tasks/executor.js +225 -0
  61. package/runtime/scripts/amalgm-mcp/tasks/rest.js +110 -0
  62. package/runtime/scripts/amalgm-mcp/tasks/schedule-normalization.js +85 -0
  63. package/runtime/scripts/amalgm-mcp/tasks/scheduler.js +105 -0
  64. package/runtime/scripts/amalgm-mcp/tasks/store.js +154 -0
  65. package/runtime/scripts/amalgm-mcp/tasks/tools.js +391 -0
  66. package/runtime/scripts/amalgm-mcp/toolbox/rest.js +75 -0
  67. package/runtime/scripts/amalgm-mcp/toolbox/runner.js +257 -0
  68. package/runtime/scripts/amalgm-mcp/toolbox/store.js +933 -0
  69. package/runtime/scripts/amalgm-mcp/toolbox/tools.js +269 -0
  70. package/runtime/scripts/amalgm-mcp/user-api-keys/rest.js +105 -0
  71. package/runtime/scripts/amalgm-mcp/workspace/rest.js +497 -0
  72. package/runtime/scripts/chat-core/adapters/claude.js +165 -0
  73. package/runtime/scripts/chat-core/adapters/codex.js +313 -0
  74. package/runtime/scripts/chat-core/adapters/opencode.js +412 -0
  75. package/runtime/scripts/chat-core/auth.js +177 -0
  76. package/runtime/scripts/chat-core/contract.js +328 -0
  77. package/runtime/scripts/chat-core/credentials/store.js +212 -0
  78. package/runtime/scripts/chat-core/egress.js +87 -0
  79. package/runtime/scripts/chat-core/engine.js +253 -0
  80. package/runtime/scripts/chat-core/event-schema.js +231 -0
  81. package/runtime/scripts/chat-core/events.js +190 -0
  82. package/runtime/scripts/chat-core/index.js +11 -0
  83. package/runtime/scripts/chat-core/input.js +50 -0
  84. package/runtime/scripts/chat-core/normalizers/claude.js +450 -0
  85. package/runtime/scripts/chat-core/normalizers/codex.js +380 -0
  86. package/runtime/scripts/chat-core/normalizers/normalizer_spec.md +259 -0
  87. package/runtime/scripts/chat-core/normalizers/opencode.js +552 -0
  88. package/runtime/scripts/chat-core/normalizers/tool_contract.md +123 -0
  89. package/runtime/scripts/chat-core/normalizers/usage_contract.md +304 -0
  90. package/runtime/scripts/chat-core/parts.js +253 -0
  91. package/runtime/scripts/chat-core/recorder.js +65 -0
  92. package/runtime/scripts/chat-core/runtime.js +86 -0
  93. package/runtime/scripts/chat-core/server.js +163 -0
  94. package/runtime/scripts/chat-core/sse.js +196 -0
  95. package/runtime/scripts/chat-core/stores.js +100 -0
  96. package/runtime/scripts/chat-core/tool-display.js +149 -0
  97. package/runtime/scripts/chat-core/tool-shape.js +143 -0
  98. package/runtime/scripts/chat-core/tooling/mcp-bundle.js +161 -0
  99. package/runtime/scripts/chat-core/tooling/mcp-relay.js +97 -0
  100. package/runtime/scripts/chat-core/tooling/native-binaries.js +608 -0
  101. package/runtime/scripts/chat-core/tooling/system-prompt.js +20 -0
  102. package/runtime/scripts/chat-core/usage.js +343 -0
  103. package/runtime/scripts/chat-server/config.js +110 -0
  104. package/runtime/scripts/chat-server/db.js +529 -0
  105. package/runtime/scripts/chat-server/index.js +33 -0
  106. package/runtime/scripts/chat-server/model-catalog.js +327 -0
  107. package/runtime/scripts/chat-server.js +75 -0
  108. package/runtime/scripts/credential-adapter.js +131 -0
  109. package/runtime/scripts/fs-watcher.js +888 -0
  110. package/runtime/scripts/local-gateway.js +854 -0
  111. package/runtime/scripts/platform-context.txt +246 -0
  112. package/runtime/scripts/port-monitor.js +175 -0
  113. package/runtime/scripts/proxy-token-store.js +162 -0
  114. package/runtime/scripts/runtime-auth.js +163 -0
  115. package/runtime/scripts/test-claude-code-models.js +87 -0
  116. package/runtime/tsconfig.json +15 -0
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Auth mode preferences.
5
+ *
6
+ * This file intentionally does not write CLI configs or runtime env. Chat-core
7
+ * owns runtime auth envelopes in scripts/chat-core/auth.js. The MCP sidecars
8
+ * still import this module to read/write the user's preferred auth mode for a
9
+ * harness, so keep the API small and boring.
10
+ */
11
+
12
+ const fs = require('fs');
13
+ const os = require('os');
14
+ const path = require('path');
15
+
16
+ const VALID_HARNESS_IDS = ['claude_code', 'codex', 'opencode', 'pi'];
17
+ const VALID_AUTH_MODES = ['amalgm', 'provider_auth', 'byok'];
18
+ const SUPPORTED_AUTH_BY_HARNESS = {
19
+ claude_code: ['amalgm', 'byok', 'provider_auth'],
20
+ codex: ['amalgm', 'byok', 'provider_auth'],
21
+ opencode: ['amalgm', 'byok'],
22
+ pi: ['amalgm', 'byok', 'provider_auth'],
23
+ };
24
+
25
+ const AMALGM_DIR = process.env.AMALGM_DIR || path.join(os.homedir(), '.amalgm');
26
+ const AUTH_MODES_FILE = path.join(AMALGM_DIR, 'auth-modes.json');
27
+ const AUTH_MODE_LEGACY_FILE = path.join(AMALGM_DIR, 'auth-mode');
28
+
29
+ function defaultAuthModes() {
30
+ return {
31
+ claude_code: 'amalgm',
32
+ codex: 'amalgm',
33
+ opencode: 'amalgm',
34
+ pi: 'amalgm',
35
+ };
36
+ }
37
+
38
+ function coerceAuthMode(harnessId, authMethod) {
39
+ const supported = SUPPORTED_AUTH_BY_HARNESS[harnessId] || ['amalgm'];
40
+ return supported.includes(authMethod) ? authMethod : supported[0];
41
+ }
42
+
43
+ function readPersistedAuthModes() {
44
+ const defaults = defaultAuthModes();
45
+ try {
46
+ const parsed = JSON.parse(fs.readFileSync(AUTH_MODES_FILE, 'utf8'));
47
+ const out = { ...defaults };
48
+ for (const harnessId of VALID_HARNESS_IDS) {
49
+ out[harnessId] = coerceAuthMode(harnessId, parsed?.[harnessId]);
50
+ }
51
+ return out;
52
+ } catch {}
53
+
54
+ try {
55
+ const legacy = fs.readFileSync(AUTH_MODE_LEGACY_FILE, 'utf8').trim();
56
+ const out = { ...defaults };
57
+ for (const harnessId of VALID_HARNESS_IDS) {
58
+ if (SUPPORTED_AUTH_BY_HARNESS[harnessId]?.includes(legacy)) out[harnessId] = legacy;
59
+ }
60
+ return out;
61
+ } catch {}
62
+
63
+ return defaults;
64
+ }
65
+
66
+ function writePersistedAuthModes(modes) {
67
+ fs.mkdirSync(AMALGM_DIR, { recursive: true });
68
+ fs.writeFileSync(AUTH_MODES_FILE, JSON.stringify(modes, null, 2));
69
+ }
70
+
71
+ function getPersistedAuthMode(harnessId) {
72
+ if (!VALID_HARNESS_IDS.includes(harnessId)) return 'amalgm';
73
+ return coerceAuthMode(harnessId, readPersistedAuthModes()[harnessId]);
74
+ }
75
+
76
+ function setPersistedAuthMode(harnessId, authMethod) {
77
+ if (!VALID_HARNESS_IDS.includes(harnessId)) return false;
78
+ const modes = readPersistedAuthModes();
79
+ modes[harnessId] = coerceAuthMode(harnessId, authMethod);
80
+ writePersistedAuthModes(modes);
81
+ return true;
82
+ }
83
+
84
+ function validateAuthForHarness(harnessId, authMethod) {
85
+ if (!VALID_HARNESS_IDS.includes(harnessId)) {
86
+ return { valid: false, reason: `Unknown harness: ${harnessId}` };
87
+ }
88
+ if (!VALID_AUTH_MODES.includes(authMethod)) {
89
+ return { valid: false, reason: `Unknown auth method: ${authMethod}` };
90
+ }
91
+ if (!SUPPORTED_AUTH_BY_HARNESS[harnessId]?.includes(authMethod)) {
92
+ return { valid: false, reason: `${harnessId} does not support ${authMethod}` };
93
+ }
94
+ return { valid: true };
95
+ }
96
+
97
+ function applyAuthMode(harnessId, authMethod) {
98
+ return setPersistedAuthMode(harnessId, authMethod);
99
+ }
100
+
101
+ function applyAllOnStartup() {
102
+ return true;
103
+ }
104
+
105
+ function resolveAuthEnvelope(harnessId, authMethod) {
106
+ return {
107
+ harnessId,
108
+ authMethod: coerceAuthMode(harnessId, authMethod || getPersistedAuthMode(harnessId)),
109
+ scope: 'chat_core_session',
110
+ };
111
+ }
112
+
113
+ function pickAcpAuthMethod() {
114
+ return { method: null, skip: true, reason: 'ACP runtime removed from live chat path' };
115
+ }
116
+
117
+ module.exports = {
118
+ applyAuthMode,
119
+ applyAllOnStartup,
120
+ coerceAuthMode,
121
+ getPersistedAuthMode,
122
+ pickAcpAuthMethod,
123
+ readPersistedAuthModes,
124
+ resolveAuthEnvelope,
125
+ setPersistedAuthMode,
126
+ validateAuthForHarness,
127
+ writePersistedAuthModes,
128
+ VALID_AUTH_MODES,
129
+ VALID_HARNESS_IDS,
130
+ SUPPORTED_AUTH_BY_HARNESS,
131
+ };