@adhdev/daemon-core 0.9.82-rc.377 → 0.9.82-rc.379
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/cli-adapters/provider-cli-adapter.d.ts +5 -0
- package/dist/cli-adapters/pty-write-chunking.d.ts +34 -0
- package/dist/commands/router.d.ts +3 -470
- package/dist/index.js +298 -218
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +299 -219
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-coordinator-config.d.ts +21 -0
- package/dist/mesh/mesh-node-identity.d.ts +289 -0
- package/dist/mesh/mesh-refine-gates.d.ts +428 -0
- package/dist/providers/spec/fsm-driver.d.ts +6 -4
- package/package.json +2 -2
- package/src/cli-adapters/provider-cli-adapter.ts +62 -1
- package/src/cli-adapters/pty-write-chunking.ts +106 -0
- package/src/commands/med-family/mesh-crud.ts +28 -1
- package/src/commands/router.ts +104 -3650
- package/src/mesh/mesh-coordinator-config.ts +97 -0
- package/src/mesh/mesh-node-identity.ts +1887 -0
- package/src/mesh/mesh-queue-assignment.ts +34 -0
- package/src/mesh/mesh-refine-gates.ts +1652 -0
- package/src/providers/spec/fsm-driver.ts +13 -26
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hermes / MCP coordinator config helpers
|
|
3
|
+
*
|
|
4
|
+
* Extracted from commands/router.ts (behavior-preserving move). Contains the
|
|
5
|
+
* MCP-server config parse/serialize helpers and the Hermes coordinator base
|
|
6
|
+
* config loading / temp-override stripping / credential-copy helpers.
|
|
7
|
+
*
|
|
8
|
+
* router.ts re-exports every public symbol from here so existing import paths
|
|
9
|
+
* keep working.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { LOG } from '../logging/logger.js';
|
|
13
|
+
import * as yaml from 'js-yaml';
|
|
14
|
+
import { homedir } from 'os';
|
|
15
|
+
import { join as pathJoin, resolve as pathResolve } from 'path';
|
|
16
|
+
import * as fs from 'fs';
|
|
17
|
+
import type { MeshCoordinatorConfigFormat } from './mesh-refine-gates.js';
|
|
18
|
+
|
|
19
|
+
function loadYamlModule(): { load: (input: string) => any; dump: (input: any, options?: Record<string, any>) => string } {
|
|
20
|
+
return yaml as { load: (input: string) => any; dump: (input: any, options?: Record<string, any>) => string };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getMcpServersKey(format: MeshCoordinatorConfigFormat): 'mcpServers' | 'mcp_servers' {
|
|
24
|
+
return format === 'hermes_config_yaml' ? 'mcp_servers' : 'mcpServers';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function parseMeshCoordinatorMcpConfig(text: string, format: MeshCoordinatorConfigFormat): Record<string, any> {
|
|
28
|
+
if (!text.trim()) return {};
|
|
29
|
+
if (format === 'claude_mcp_json') return JSON.parse(text);
|
|
30
|
+
const parsed = loadYamlModule().load(text);
|
|
31
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function serializeMeshCoordinatorMcpConfig(config: Record<string, any>, format: MeshCoordinatorConfigFormat): string {
|
|
35
|
+
if (format === 'claude_mcp_json') return JSON.stringify(config, null, 2);
|
|
36
|
+
return loadYamlModule().dump(config, { noRefs: true, lineWidth: 120 });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function resolveHermesUserHome(): string {
|
|
40
|
+
const explicitHome = process.env.HERMES_HOME?.trim();
|
|
41
|
+
return explicitHome || pathJoin(homedir(), '.hermes');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function loadHermesCoordinatorBaseConfig(targetConfigPath: string): { config: Record<string, any>; sourceHome: string; sourceConfigPath: string } {
|
|
45
|
+
const sourceHome = resolveHermesUserHome();
|
|
46
|
+
const sourceConfigPath = pathJoin(sourceHome, 'config.yaml');
|
|
47
|
+
if (!fs.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
48
|
+
if (pathResolve(sourceConfigPath) === pathResolve(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
49
|
+
|
|
50
|
+
const parsed = parseMeshCoordinatorMcpConfig(fs.readFileSync(sourceConfigPath, 'utf-8'), 'hermes_config_yaml');
|
|
51
|
+
const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
|
|
52
|
+
return { config: baseConfig, sourceHome, sourceConfigPath };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function stripHermesCoordinatorTempModelProviderOverrides(config: Record<string, any>): Record<string, any> {
|
|
56
|
+
const {
|
|
57
|
+
model: _model,
|
|
58
|
+
provider: _provider,
|
|
59
|
+
default_model: _defaultModel,
|
|
60
|
+
defaultProvider: _defaultProvider,
|
|
61
|
+
default_provider: _defaultProviderSnake,
|
|
62
|
+
modelProvider: _modelProvider,
|
|
63
|
+
model_provider: _modelProviderSnake,
|
|
64
|
+
...sanitized
|
|
65
|
+
} = config;
|
|
66
|
+
const delegation = sanitized.delegation;
|
|
67
|
+
if (delegation && typeof delegation === 'object' && !Array.isArray(delegation)) {
|
|
68
|
+
const {
|
|
69
|
+
model: _delegationModel,
|
|
70
|
+
provider: _delegationProvider,
|
|
71
|
+
modelProvider: _delegationModelProvider,
|
|
72
|
+
model_provider: _delegationModelProviderSnake,
|
|
73
|
+
...delegationRest
|
|
74
|
+
} = delegation;
|
|
75
|
+
if (Object.keys(delegationRest).length > 0) {
|
|
76
|
+
sanitized.delegation = delegationRest;
|
|
77
|
+
} else {
|
|
78
|
+
delete sanitized.delegation;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return sanitized;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function copyHermesCoordinatorCredentialFiles(sourceHome: string, targetHome: string) {
|
|
85
|
+
if (pathResolve(sourceHome) === pathResolve(targetHome)) return;
|
|
86
|
+
for (const fileName of ['.env', 'auth.json']) {
|
|
87
|
+
const sourcePath = pathJoin(sourceHome, fileName);
|
|
88
|
+
const targetPath = pathJoin(targetHome, fileName);
|
|
89
|
+
if (!fs.existsSync(sourcePath)) continue;
|
|
90
|
+
try {
|
|
91
|
+
fs.copyFileSync(sourcePath, targetPath);
|
|
92
|
+
} catch (error: any) {
|
|
93
|
+
LOG.warn('MeshCoordinator', `Could not copy Hermes ${fileName} into isolated coordinator home: ${error?.message || error}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|