@semiont/core 0.5.22 → 0.5.24

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.
@@ -1,296 +1,9 @@
1
+ import { createTomlConfigLoader } from '../chunk-XQTWEBJ5.js';
1
2
  import * as fs from 'fs';
2
3
  import * as os from 'os';
3
4
  import * as path from 'path';
4
- import { parse } from 'smol-toml';
5
5
  import { execFileSync } from 'child_process';
6
6
 
7
- // src/config/node-config-loader.ts
8
- function deepMerge(base, override) {
9
- const result = { ...base };
10
- for (const key of Object.keys(override)) {
11
- const b = base[key];
12
- const o = override[key];
13
- if (o !== void 0 && o !== null && typeof o === "object" && !Array.isArray(o) && b !== void 0 && b !== null && typeof b === "object" && !Array.isArray(b)) {
14
- result[key] = deepMerge(b, o);
15
- } else if (o !== void 0) {
16
- result[key] = o;
17
- }
18
- }
19
- return result;
20
- }
21
- function resolveEnvVars(obj, env) {
22
- if (typeof obj === "string") {
23
- return obj.replace(/\$\{([^}]+)\}/g, (match, expr) => {
24
- const sepIdx = expr.indexOf(":-");
25
- const varName = sepIdx >= 0 ? expr.slice(0, sepIdx) : expr;
26
- const defaultValue = sepIdx >= 0 ? expr.slice(sepIdx + 2) : void 0;
27
- const value = env[varName];
28
- if (value !== void 0) return value;
29
- if (defaultValue !== void 0) return defaultValue;
30
- throw new Error(`Environment variable ${varName} is not set (referenced in config as ${match})`);
31
- });
32
- }
33
- if (Array.isArray(obj)) {
34
- return obj.map((item) => resolveEnvVars(item, env));
35
- }
36
- if (obj !== null && typeof obj === "object") {
37
- const resolved = {};
38
- for (const key in obj) {
39
- resolved[key] = resolveEnvVars(obj[key], env);
40
- }
41
- return resolved;
42
- }
43
- return obj;
44
- }
45
- function requirePlatform(value, serviceName) {
46
- if (!value) {
47
- throw new Error(`platform is required for service '${serviceName}' \u2014 add 'platform = "posix"|"container"|"external"' to its config section`);
48
- }
49
- return value;
50
- }
51
- function loadTomlConfig(projectRoot, environment, globalConfigPath, reader, env) {
52
- const projectConfigContent = projectRoot ? reader.readIfExists(`${projectRoot}/.semiont/config`) : null;
53
- const projectConfig = projectConfigContent ? parse(projectConfigContent) : void 0;
54
- const projectName = projectConfig?.project?.name ?? "semiont-project";
55
- const projectVersion = projectConfig?.project?.version;
56
- const projectSite = projectConfig?.site;
57
- const globalContent = reader.readIfExists(globalConfigPath);
58
- const raw = globalContent ? parse(globalContent) : {};
59
- const resolvedEnvironment = environment ?? env.SEMIONT_ENV ?? raw.defaults?.environment;
60
- if (!resolvedEnvironment) {
61
- throw new Error(
62
- "No environment selected: pass one explicitly, set SEMIONT_ENV, or declare `[defaults] environment` in ~/.semiontconfig."
63
- );
64
- }
65
- const projectHasSection = projectConfig?.environments != null && resolvedEnvironment in projectConfig.environments;
66
- const globalHasSection = raw.environments != null && resolvedEnvironment in raw.environments;
67
- if (!projectHasSection && !globalHasSection) {
68
- throw new Error(
69
- `Environment "${resolvedEnvironment}" is selected but no [environments.${resolvedEnvironment}] section exists in the project (.semiont/config) or global (~/.semiontconfig) config. Declare the section, or select an environment that exists.`
70
- );
71
- }
72
- const projectEnvSection = projectConfig?.environments?.[resolvedEnvironment] ?? {};
73
- const userEnvSection = raw.environments?.[resolvedEnvironment] ?? {};
74
- const envSection = deepMerge(
75
- projectEnvSection,
76
- userEnvSection
77
- );
78
- const resolved = resolveEnvVars(envSection, env);
79
- const flatInference = resolved.inference;
80
- const makeMeaningSection = resolved["make-meaning"];
81
- const workersSection = resolved.workers ?? {};
82
- const actorsSection = resolved.actors ?? {};
83
- const defaultWorkerInference = workersSection["default"]?.inference;
84
- const defaultMakeMeaningInference = makeMeaningSection?.default?.inference;
85
- function mergeWithFlatInference(specific) {
86
- if (!flatInference) return specific;
87
- const providerDefaults = {};
88
- if (specific.type === "anthropic") {
89
- const a = flatInference.anthropic;
90
- if (a) {
91
- providerDefaults.apiKey = a.apiKey;
92
- providerDefaults.endpoint = a.endpoint;
93
- } else {
94
- if (!flatInference.type) {
95
- throw new Error(
96
- `[environments.${resolvedEnvironment}.inference] is missing 'type'. Add type = "anthropic" or use [inference.anthropic] sub-section.`
97
- );
98
- }
99
- providerDefaults.apiKey = flatInference.apiKey;
100
- providerDefaults.endpoint = flatInference.endpoint;
101
- }
102
- } else if (specific.type === "ollama") {
103
- const o = flatInference.ollama;
104
- if (o) {
105
- providerDefaults.baseURL = o.baseURL;
106
- } else {
107
- if (!flatInference.type) {
108
- throw new Error(
109
- `[environments.${resolvedEnvironment}.inference] is missing 'type'. Add type = "ollama" or use [inference.ollama] sub-section.`
110
- );
111
- }
112
- providerDefaults.baseURL = flatInference.baseURL;
113
- }
114
- }
115
- return {
116
- maxTokens: flatInference.maxTokens,
117
- ...providerDefaults,
118
- ...specific
119
- };
120
- }
121
- function resolveActorInference(fromMakeMeaning, fromActors) {
122
- const base = fromMakeMeaning ?? fromActors ?? defaultMakeMeaningInference;
123
- if (!base) return void 0;
124
- return mergeWithFlatInference(base);
125
- }
126
- const actors = {};
127
- const gathererInference = resolveActorInference(
128
- makeMeaningSection?.actors?.gatherer?.inference,
129
- actorsSection["gatherer"]?.inference
130
- );
131
- if (gathererInference) actors.gatherer = gathererInference;
132
- const matcherInference = resolveActorInference(
133
- makeMeaningSection?.actors?.matcher?.inference,
134
- actorsSection["matcher"]?.inference
135
- );
136
- if (matcherInference) actors.matcher = matcherInference;
137
- const workers = {};
138
- const workerTypes = ["reference-annotation", "highlight-annotation", "assessment-annotation", "comment-annotation", "tag-annotation", "generation"];
139
- if (defaultWorkerInference) {
140
- workers.default = mergeWithFlatInference(defaultWorkerInference);
141
- }
142
- for (const wt of workerTypes) {
143
- const specific = workersSection[wt]?.inference;
144
- if (specific) {
145
- workers[wt] = mergeWithFlatInference(specific);
146
- }
147
- }
148
- const backend = resolved.backend;
149
- const site = resolved.site ?? projectSite;
150
- const inferenceSection = resolved.inference;
151
- let inferenceProviders;
152
- if (inferenceSection) {
153
- inferenceProviders = {};
154
- if (inferenceSection.anthropic) {
155
- const a = inferenceSection.anthropic;
156
- inferenceProviders.anthropic = {
157
- platform: requirePlatform(a.platform, "inference.anthropic"),
158
- endpoint: a.endpoint ?? "https://api.anthropic.com",
159
- apiKey: a.apiKey ?? ""
160
- };
161
- } else if (inferenceSection.type === "anthropic") {
162
- inferenceProviders.anthropic = {
163
- platform: requirePlatform(inferenceSection.platform, "inference"),
164
- endpoint: inferenceSection.endpoint ?? "https://api.anthropic.com",
165
- apiKey: inferenceSection.apiKey ?? ""
166
- };
167
- }
168
- if (inferenceSection.ollama) {
169
- const o = inferenceSection.ollama;
170
- inferenceProviders.ollama = {
171
- platform: { type: requirePlatform(o.platform, "inference.ollama") },
172
- baseURL: o.baseURL,
173
- port: o.baseURL ? void 0 : o.port ?? 11434
174
- };
175
- } else if (inferenceSection.type === "ollama") {
176
- inferenceProviders.ollama = {
177
- platform: { type: requirePlatform(inferenceSection.platform, "inference") },
178
- baseURL: inferenceSection.baseURL,
179
- port: inferenceSection.baseURL ? void 0 : 11434
180
- };
181
- }
182
- }
183
- const topLevelWorkers = {};
184
- for (const [name, w] of Object.entries(workersSection)) {
185
- if (w.inference) {
186
- topLevelWorkers[name] = { inference: { type: w.inference.type, model: w.inference.model } };
187
- }
188
- }
189
- const topLevelActors = {};
190
- for (const [name, a] of Object.entries(actorsSection)) {
191
- if (a.inference) {
192
- topLevelActors[name] = { inference: { type: a.inference.type, model: a.inference.model } };
193
- }
194
- }
195
- if (makeMeaningSection?.actors?.gatherer?.inference) {
196
- topLevelActors["gatherer"] = { inference: { type: makeMeaningSection.actors.gatherer.inference.type, model: makeMeaningSection.actors.gatherer.inference.model } };
197
- }
198
- if (makeMeaningSection?.actors?.matcher?.inference) {
199
- topLevelActors["matcher"] = { inference: { type: makeMeaningSection.actors.matcher.inference.type, model: makeMeaningSection.actors.matcher.inference.model } };
200
- }
201
- const frontend = resolved.frontend;
202
- const services = {};
203
- if (backend) {
204
- services.backend = {
205
- platform: { type: requirePlatform(backend.platform, "backend") },
206
- port: backend.port ?? 4e3,
207
- publicURL: backend.publicURL ?? `http://localhost:${backend.port ?? 4e3}`
208
- };
209
- }
210
- if (frontend) {
211
- services.frontend = {
212
- platform: { type: requirePlatform(frontend.platform, "frontend") },
213
- port: frontend.port ?? 3e3,
214
- siteName: site?.siteName ?? "Semiont",
215
- publicURL: frontend.publicURL
216
- };
217
- }
218
- if (resolved.graph) {
219
- services.graph = {
220
- ...resolved.graph,
221
- platform: { type: requirePlatform(resolved.graph.platform, "graph") },
222
- type: resolved.graph.type ?? "neo4j"
223
- };
224
- } else if (makeMeaningSection?.graph) {
225
- services.graph = makeMeaningSection.graph;
226
- }
227
- if (resolved.database) {
228
- services.database = {
229
- platform: { type: requirePlatform(resolved.database.platform, "database") },
230
- type: "postgres",
231
- image: resolved.database.image,
232
- host: resolved.database.host ?? "localhost",
233
- port: resolved.database.port ?? 5432,
234
- name: resolved.database.name,
235
- user: resolved.database.user,
236
- password: resolved.database.password
237
- };
238
- }
239
- if (resolved.vectors) {
240
- services.vectors = {
241
- platform: { type: "external" },
242
- type: resolved.vectors.type ?? "qdrant",
243
- host: resolved.vectors.host,
244
- port: resolved.vectors.port ?? 6333
245
- };
246
- }
247
- const embeddingSource = resolved.embedding ?? resolved.vectors?.embedding;
248
- if (embeddingSource) {
249
- services.embedding = {
250
- platform: { type: "external" },
251
- type: embeddingSource.type,
252
- model: embeddingSource.model,
253
- apiKey: embeddingSource.apiKey,
254
- baseURL: embeddingSource.baseURL,
255
- endpoint: embeddingSource.endpoint,
256
- chunking: resolved.embedding?.chunking ?? resolved.vectors?.chunking ? {
257
- chunkSize: (resolved.embedding?.chunking ?? resolved.vectors?.chunking)?.chunkSize ?? 512,
258
- overlap: (resolved.embedding?.chunking ?? resolved.vectors?.chunking)?.overlap ?? 64
259
- } : void 0
260
- };
261
- }
262
- const config = {
263
- services,
264
- ...inferenceProviders ? { inference: inferenceProviders } : {},
265
- ...Object.keys(topLevelWorkers).length > 0 ? { workers: topLevelWorkers } : {},
266
- ...Object.keys(topLevelActors).length > 0 ? { actors: topLevelActors } : {},
267
- site: site ? {
268
- domain: site.domain ?? "localhost",
269
- siteName: site.siteName,
270
- adminEmail: site.adminEmail,
271
- oauthAllowedDomains: site.oauthAllowedDomains
272
- } : void 0,
273
- logLevel: resolved.logLevel,
274
- _metadata: {
275
- environment: resolvedEnvironment,
276
- projectRoot,
277
- projectName,
278
- projectVersion,
279
- ...Object.keys(actors).length > 0 ? { actors } : {},
280
- ...Object.keys(workers).length > 0 ? { workers } : {},
281
- // Always set — the loader is the ONE home of this default (D5).
282
- // Consuming code (make-meaning's gather path) receives a required
283
- // value and defaults nothing.
284
- gather: { settleTimeoutMs: makeMeaningSection?.gather?.settleTimeoutMs ?? 15e3 }
285
- }
286
- };
287
- return config;
288
- }
289
- function createTomlConfigLoader(reader, globalConfigPath, env) {
290
- return (projectRoot, environment) => {
291
- return loadTomlConfig(projectRoot, environment, globalConfigPath, reader, env);
292
- };
293
- }
294
7
  var SemiontProject = class _SemiontProject {
295
8
  root;
296
9
  name;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/config/toml-loader.ts","../../src/project.ts","../../src/config/node-config-loader.ts"],"names":["parseToml","fs2","path2","os2"],"mappings":";;;;;;;AA0BA,SAAS,SAAA,CAA6C,MAAS,QAAA,EAAyB;AACtF,EAAA,MAAM,MAAA,GAAS,EAAE,GAAG,IAAA,EAAK;AACzB,EAAA,KAAA,MAAW,GAAA,IAAO,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAA,EAAG;AACvC,IAAA,MAAM,CAAA,GAAI,KAAK,GAAG,CAAA;AAClB,IAAA,MAAM,CAAA,GAAI,SAAS,GAAG,CAAA;AACtB,IAAA,IAAI,CAAA,KAAM,UAAa,CAAA,KAAM,IAAA,IAAQ,OAAO,CAAA,KAAM,QAAA,IAAY,CAAC,KAAA,CAAM,OAAA,CAAQ,CAAC,KAC1E,CAAA,KAAM,MAAA,IAAa,CAAA,KAAM,IAAA,IAAQ,OAAO,CAAA,KAAM,YAAY,CAAC,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AAA,IAAO,EAAA,CAAA,UAAA,CAAW,UAAU,CAAA,EAAG;AAC7B,MAAA,MAAM,OAAA,GAAa,EAAA,CAAA,YAAA,CAAa,UAAA,EAAY,OAAO,CAAA;AACnD,MAAA,KAAA,MAAW,IAAA,IAAQ,OAAA,CAAQ,KAAA,CAAM,IAAI,CAAA,EAAG;AACtC,QAAA,MAAM,OAAA,GAAU,KAAK,IAAA,EAAK;AAC1B,QAAA,IAAI,QAAQ,UAAA,CAAW,MAAM,KAAK,OAAA,CAAQ,QAAA,CAAS,GAAG,CAAA,EAAG;AACvD,UAAA,MAAM,GAAG,GAAG,IAAI,CAAA,GAAI,OAAA,CAAQ,MAAM,GAAG,CAAA;AACrC,UAAA,OAAO,IAAA,CAAK,KAAK,GAAG,CAAA,CAAE,MAAK,CAAE,OAAA,CAAQ,YAAY,IAAI,CAAA;AAAA,QACvD;AAAA,MACF;AAAA,IACF;AACA,IAAA,OAAY,cAAS,WAAW,CAAA;AAAA,EAClC;AACF;;;AC3LA,IAAM,kBAAA,GAAqB;AAAA,EACzB,YAAA,EAAc,CAAC,QAAA,KACVC,EAAA,CAAA,UAAA,CAAW,QAAQ,CAAA,GAAOA,EAAA,CAAA,YAAA,CAAa,QAAA,EAAU,OAAO,CAAA,GAAI;AACnE,CAAA;AAcO,SAAS,qBAAA,CACd,aACA,WAAA,EACmB;AACnB,EAAA,MAAM,gBAAA,GAAwBC,IAAA,CAAA,IAAA,CAAQC,EAAA,CAAA,OAAA,EAAQ,EAAG,gBAAgB,CAAA;AACjE,EAAA,OAAO,sBAAA;AAAA,IACL,kBAAA;AAAA,IACA,gBAAA;AAAA,IACA,OAAA,CAAQ;AAAA,GACV,CAAE,aAAa,WAAW,CAAA;AAC5B","file":"node-config-loader.js","sourcesContent":["/**\n * TOML Config Loader\n *\n * Reads ~/.semiontconfig (TOML) and .semiont/config (TOML) and produces\n * an EnvironmentConfig for the requested environment.\n *\n * File format: see TOML-XDG-CONFIG.md\n *\n * Loading sequence:\n * 1. Read .semiont/config → projectName, site, environments.<env>.* (project base)\n * 2. Read ~/.semiontconfig → defaults, environments.<env>.* (user overrides)\n * 3. Deep-merge: project base ← user overrides (user wins on conflicts)\n * Any environment name is valid (local, staging, production, custom, ...)\n * 4. Resolve ${VAR} references from process.env\n * 5. Apply inheritance: workers.<name> → workers.default → error\n * 6. Map to EnvironmentConfig shape\n */\n\nimport { parse as parseToml } from 'smol-toml';\nimport type { EnvironmentConfig, OllamaProviderConfig, AnthropicProviderConfig } from './config.types';\nimport type { PlatformType } from './config.types';\n\n/**\n * Deep merge two plain objects. Arrays and primitives in `override` replace those in `base`.\n * Nested objects are merged recursively. `override` takes precedence on conflicts.\n */\nfunction deepMerge<T extends Record<string, unknown>>(base: T, override: Partial<T>): T {\n const result = { ...base } as Record<string, unknown>;\n for (const key of Object.keys(override)) {\n const b = base[key];\n const o = override[key];\n if (o !== undefined && o !== null && typeof o === 'object' && !Array.isArray(o) &&\n b !== undefined && b !== null && typeof b === 'object' && !Array.isArray(b)) {\n result[key] = deepMerge(b as Record<string, unknown>, o as Record<string, unknown>);\n } else if (o !== undefined) {\n result[key] = o;\n }\n }\n return result as T;\n}\n\nfunction resolveEnvVars(obj: unknown, env: Record<string, string | undefined>): unknown {\n if (typeof obj === 'string') {\n return obj.replace(/\\$\\{([^}]+)\\}/g, (match, expr: string) => {\n const sepIdx = expr.indexOf(':-');\n const varName = sepIdx >= 0 ? expr.slice(0, sepIdx) : expr;\n const defaultValue = sepIdx >= 0 ? expr.slice(sepIdx + 2) : undefined;\n const value = env[varName];\n if (value !== undefined) return value;\n if (defaultValue !== undefined) return defaultValue;\n throw new Error(`Environment variable ${varName} is not set (referenced in config as ${match})`);\n });\n }\n if (Array.isArray(obj)) {\n return obj.map(item => resolveEnvVars(item, env));\n }\n if (obj !== null && typeof obj === 'object') {\n const resolved: Record<string, unknown> = {};\n for (const key in obj as Record<string, unknown>) {\n resolved[key] = resolveEnvVars((obj as Record<string, unknown>)[key], env);\n }\n return resolved;\n }\n return obj;\n}\n\n// ── Inference config types (mirrored from packages/make-meaning/src/config.ts) ─\n// Kept here to avoid a circular dependency: core cannot import make-meaning.\n\nexport interface InferenceConfig {\n type: 'anthropic' | 'ollama';\n model: string;\n maxTokens?: number;\n apiKey?: string;\n endpoint?: string;\n baseURL?: string;\n}\n\nexport interface ActorInferenceConfig {\n gatherer?: InferenceConfig;\n matcher?: InferenceConfig;\n}\n\nexport interface WorkerInferenceConfig {\n default?: InferenceConfig;\n 'reference-annotation'?: InferenceConfig;\n 'highlight-annotation'?: InferenceConfig;\n 'assessment-annotation'?: InferenceConfig;\n 'comment-annotation'?: InferenceConfig;\n 'tag-annotation'?: InferenceConfig;\n 'generation'?: InferenceConfig;\n}\n\n// ── Types for ~/.semiontconfig ────────────────────────────────────────────────\n\ninterface SemiontConfigFile {\n user?: {\n name?: string;\n email?: string;\n };\n defaults?: {\n environment?: string;\n platform?: string;\n };\n environments?: Record<string, EnvironmentSection>;\n}\n\ninterface GraphSection {\n platform?: string;\n type?: string;\n name?: string;\n uri?: string;\n username?: string;\n password?: string;\n database?: string;\n [key: string]: unknown;\n}\n\ninterface InferenceFlatSection {\n // Flat (single-provider) format: type = \"anthropic\"|\"ollama\" at this level\n type?: 'anthropic' | 'ollama';\n platform?: string;\n model?: string;\n maxTokens?: number;\n apiKey?: string;\n endpoint?: string;\n baseURL?: string;\n // Keyed (multi-provider) format: [inference.anthropic] / [inference.ollama]\n anthropic?: { platform?: string; apiKey?: string; endpoint?: string };\n ollama?: { platform?: string; baseURL?: string; port?: number };\n}\n\ninterface EnvironmentSection {\n backend?: {\n platform?: string;\n port?: number;\n publicURL?: string;\n frontendURL?: string;\n };\n frontend?: {\n platform?: string;\n port?: number;\n publicURL?: string;\n };\n site?: {\n domain?: string;\n siteName?: string;\n adminEmail?: string;\n oauthAllowedDomains?: string[];\n enableLocalAuth?: boolean;\n };\n database?: {\n platform?: string;\n image?: string;\n host?: string;\n port?: number;\n name?: string;\n user?: string;\n password?: string;\n };\n graph?: GraphSection;\n vectors?: {\n type?: 'qdrant' | 'memory';\n host?: string;\n port?: number;\n // Legacy: embedding nested under vectors (migrated to top-level)\n embedding?: {\n type?: 'voyage' | 'ollama';\n model?: string;\n apiKey?: string;\n baseURL?: string;\n endpoint?: string;\n };\n chunking?: {\n chunkSize?: number;\n overlap?: number;\n };\n };\n embedding?: {\n type?: 'voyage' | 'ollama';\n model?: string;\n apiKey?: string;\n baseURL?: string;\n endpoint?: string;\n chunking?: {\n chunkSize?: number;\n overlap?: number;\n };\n };\n inference?: InferenceFlatSection;\n 'make-meaning'?: {\n graph?: Record<string, unknown>;\n actors?: {\n gatherer?: { inference?: InferenceConfig };\n matcher?: { inference?: InferenceConfig };\n };\n default?: { inference?: InferenceConfig };\n /**\n * Resource-gather knobs. `settleTimeoutMs` bounds the semanticContext\n * read-your-writes barrier (SMELTER-INDEX-SYNC D3/D5) — how long a gather\n * waits for the vector projection to settle before degrading to an absent\n * semanticContext. Must nest INSIDE downstream watchdogs (job-worker\n * liveness, client stall watchdogs) — see SMELTER-INDEX-SYNC A4.\n */\n gather?: { settleTimeoutMs?: number };\n };\n workers?: Record<string, { inference?: InferenceConfig }>;\n actors?: Record<string, { inference?: InferenceConfig }>;\n logLevel?: 'error' | 'warn' | 'info' | 'http' | 'debug';\n}\n\n// ── File reader abstraction (same pattern as createConfigLoader) ──────────────\n\nexport type TomlFileReader = {\n readIfExists: (path: string) => string | null;\n};\n\nfunction requirePlatform(value: string | undefined, serviceName: string): PlatformType {\n if (!value) {\n throw new Error(`platform is required for service '${serviceName}' — add 'platform = \"posix\"|\"container\"|\"external\"' to its config section`);\n }\n return value as PlatformType;\n}\n\n// ── Main loader function ──────────────────────────────────────────────────────\n\n/**\n * Parse ~/.semiontconfig and .semiont/config and return EnvironmentConfig.\n *\n * @param projectRoot - Path to the project root (contains .semiont/config)\n * @param environment - Environment name (e.g. 'local', 'production'); when\n * undefined, resolved from SEMIONT_ENV, then `[defaults] environment`\n * @param globalConfigPath - Path to ~/.semiontconfig (caller resolves ~ expansion)\n * @param reader - File reader abstraction\n * @param env - Environment variables for ${VAR} resolution\n */\nexport function loadTomlConfig(\n projectRoot: string | null,\n environment: string | undefined,\n globalConfigPath: string,\n reader: TomlFileReader,\n env: Record<string, string | undefined>\n): EnvironmentConfig {\n // 1. Read + parse project config from .semiont/config (skipped when no project root)\n const projectConfigContent = projectRoot ? reader.readIfExists(`${projectRoot}/.semiont/config`) : null;\n const projectConfig = projectConfigContent\n ? (parseToml(projectConfigContent) as {\n project?: { name?: string; version?: string };\n site?: EnvironmentSection['site'];\n environments?: Record<string, EnvironmentSection>;\n })\n : undefined;\n const projectName = projectConfig?.project?.name ?? 'semiont-project';\n const projectVersion = projectConfig?.project?.version;\n const projectSite = projectConfig?.site;\n\n // 2. Read global config (optional — missing config yields empty environments)\n const globalContent = reader.readIfExists(globalConfigPath);\n const raw = globalContent ? (parseToml(globalContent) as SemiontConfigFile) : ({} as SemiontConfigFile);\n\n // 3. Resolve WHICH environment to load. `[defaults] environment` is the key the\n // launcher selects from (config.go: cfg.Defaults.Environment); the backend\n // resolves from the SAME key so one config selects the environment for both\n // halves. Precedence: explicit arg > SEMIONT_ENV (override, incl. tests) >\n // [defaults] environment. There is NO silent 'local'/'development' fallback —\n // an unselected environment is a config error, not a default.\n const resolvedEnvironment = environment ?? env.SEMIONT_ENV ?? raw.defaults?.environment;\n if (!resolvedEnvironment) {\n throw new Error(\n 'No environment selected: pass one explicitly, set SEMIONT_ENV, or declare ' +\n '`[defaults] environment` in ~/.semiontconfig.',\n );\n }\n\n // 4. A named environment with no [environments.X] section ANYWHERE is a config\n // error, not a silent empty {}. The silent {} is what let a KB declaring\n // `environment = \"staging\"` (with no [environments.staging]) load nothing and\n // let every downstream default fire — including site.domain -> 'localhost',\n // the fabricated colliding did:web:localhost identity. Fail loud instead.\n const projectHasSection =\n projectConfig?.environments != null && resolvedEnvironment in projectConfig.environments;\n const globalHasSection = raw.environments != null && resolvedEnvironment in raw.environments;\n if (!projectHasSection && !globalHasSection) {\n throw new Error(\n `Environment \"${resolvedEnvironment}\" is selected but no [environments.${resolvedEnvironment}] ` +\n 'section exists in the project (.semiont/config) or global (~/.semiontconfig) config. ' +\n 'Declare the section, or select an environment that exists.',\n );\n }\n\n // 5. Deep-merge: project base + user overrides (user wins on conflicts)\n const projectEnvSection: EnvironmentSection = projectConfig?.environments?.[resolvedEnvironment] ?? {};\n const userEnvSection: EnvironmentSection = raw.environments?.[resolvedEnvironment] ?? {};\n const envSection: EnvironmentSection = deepMerge(\n projectEnvSection as Record<string, unknown>,\n userEnvSection as Record<string, unknown>\n ) as EnvironmentSection;\n\n // 4. Resolve ${VAR} references\n const resolved = resolveEnvVars(envSection, env) as EnvironmentSection;\n\n // 5. Build make-meaning actor/worker inference config with inheritance\n // The flat [inference] section provides defaults (apiKey, maxTokens, endpoint/baseURL).\n // Actor/worker sections only need to specify type and model; missing fields fall back\n // to the flat inference section.\n const flatInference = resolved.inference;\n const makeMeaningSection = resolved['make-meaning'];\n const workersSection = resolved.workers ?? {};\n const actorsSection = resolved.actors ?? {};\n const defaultWorkerInference = workersSection['default']?.inference;\n const defaultMakeMeaningInference = makeMeaningSection?.default?.inference;\n\n function mergeWithFlatInference(specific: InferenceConfig): InferenceConfig {\n if (!flatInference) return specific;\n // For keyed sub-sections, inherit credentials from the matching provider sub-section.\n // For flat (legacy) format, flatInference.type is required to know which fields apply.\n const providerDefaults: Partial<InferenceConfig> = {};\n if (specific.type === 'anthropic') {\n const a = flatInference.anthropic;\n if (a) {\n providerDefaults.apiKey = a.apiKey;\n providerDefaults.endpoint = a.endpoint;\n } else {\n if (!flatInference.type) {\n throw new Error(\n `[environments.${resolvedEnvironment}.inference] is missing 'type'. ` +\n `Add type = \"anthropic\" or use [inference.anthropic] sub-section.`\n );\n }\n providerDefaults.apiKey = flatInference.apiKey;\n providerDefaults.endpoint = flatInference.endpoint;\n }\n } else if (specific.type === 'ollama') {\n const o = flatInference.ollama;\n if (o) {\n providerDefaults.baseURL = o.baseURL;\n } else {\n if (!flatInference.type) {\n throw new Error(\n `[environments.${resolvedEnvironment}.inference] is missing 'type'. ` +\n `Add type = \"ollama\" or use [inference.ollama] sub-section.`\n );\n }\n providerDefaults.baseURL = flatInference.baseURL;\n }\n }\n return {\n maxTokens: flatInference.maxTokens,\n ...providerDefaults,\n ...specific,\n };\n }\n\n function resolveActorInference(fromMakeMeaning?: InferenceConfig, fromActors?: InferenceConfig): InferenceConfig | undefined {\n const base = fromMakeMeaning ?? fromActors ?? defaultMakeMeaningInference;\n if (!base) return undefined;\n return mergeWithFlatInference(base);\n }\n\n const actors: ActorInferenceConfig = {};\n const gathererInference = resolveActorInference(\n makeMeaningSection?.actors?.gatherer?.inference,\n actorsSection['gatherer']?.inference\n );\n if (gathererInference) actors.gatherer = gathererInference;\n\n const matcherInference = resolveActorInference(\n makeMeaningSection?.actors?.matcher?.inference,\n actorsSection['matcher']?.inference\n );\n if (matcherInference) actors.matcher = matcherInference;\n\n const workers: WorkerInferenceConfig = {};\n const workerTypes = ['reference-annotation', 'highlight-annotation', 'assessment-annotation', 'comment-annotation', 'tag-annotation', 'generation'] as const;\n if (defaultWorkerInference) {\n workers.default = mergeWithFlatInference(defaultWorkerInference);\n }\n for (const wt of workerTypes) {\n const specific = workersSection[wt]?.inference;\n if (specific) {\n (workers as Record<string, InferenceConfig>)[wt] = mergeWithFlatInference(specific);\n }\n }\n\n // 6. Map to EnvironmentConfig\n const backend = resolved.backend;\n const site = resolved.site ?? projectSite;\n const inferenceSection = resolved.inference;\n\n // Build inference providers config.\n // Supports two formats:\n // Flat: [environments.local.inference] type = \"anthropic\"|\"ollama\" (single provider)\n // Keyed: [environments.local.inference.anthropic] / [environments.local.inference.ollama] (multi-provider)\n let inferenceProviders: EnvironmentConfig['inference'] | undefined;\n if (inferenceSection) {\n inferenceProviders = {};\n // Keyed sub-sections take priority\n if (inferenceSection.anthropic) {\n const a = inferenceSection.anthropic;\n inferenceProviders.anthropic = {\n platform: requirePlatform(a.platform, 'inference.anthropic'),\n endpoint: a.endpoint ?? 'https://api.anthropic.com',\n apiKey: a.apiKey ?? '',\n } as AnthropicProviderConfig;\n } else if (inferenceSection.type === 'anthropic') {\n inferenceProviders.anthropic = {\n platform: requirePlatform(inferenceSection.platform, 'inference'),\n endpoint: inferenceSection.endpoint ?? 'https://api.anthropic.com',\n apiKey: inferenceSection.apiKey ?? '',\n } as AnthropicProviderConfig;\n }\n if (inferenceSection.ollama) {\n const o = inferenceSection.ollama;\n inferenceProviders.ollama = {\n platform: { type: requirePlatform(o.platform, 'inference.ollama') },\n baseURL: o.baseURL,\n port: o.baseURL ? undefined : (o.port ?? 11434),\n } as OllamaProviderConfig;\n } else if (inferenceSection.type === 'ollama') {\n inferenceProviders.ollama = {\n platform: { type: requirePlatform(inferenceSection.platform, 'inference') },\n baseURL: inferenceSection.baseURL,\n port: inferenceSection.baseURL ? undefined : 11434,\n } as OllamaProviderConfig;\n }\n }\n\n // Build top-level workers/actors maps for EnvironmentConfig\n const topLevelWorkers: EnvironmentConfig['workers'] = {};\n for (const [name, w] of Object.entries(workersSection)) {\n if (w.inference) {\n topLevelWorkers[name] = { inference: { type: w.inference.type, model: w.inference.model } };\n }\n }\n const topLevelActors: EnvironmentConfig['actors'] = {};\n for (const [name, a] of Object.entries(actorsSection)) {\n if (a.inference) {\n topLevelActors[name] = { inference: { type: a.inference.type, model: a.inference.model } };\n }\n }\n // Also include make-meaning actors\n if (makeMeaningSection?.actors?.gatherer?.inference) {\n topLevelActors['gatherer'] = { inference: { type: makeMeaningSection.actors.gatherer.inference.type, model: makeMeaningSection.actors.gatherer.inference.model } };\n }\n if (makeMeaningSection?.actors?.matcher?.inference) {\n topLevelActors['matcher'] = { inference: { type: makeMeaningSection.actors.matcher.inference.type, model: makeMeaningSection.actors.matcher.inference.model } };\n }\n\n const frontend = resolved.frontend;\n\n const services: EnvironmentConfig['services'] = {};\n\n if (backend) {\n services.backend = {\n platform: { type: requirePlatform(backend.platform, 'backend') },\n port: backend.port ?? 4000,\n publicURL: backend.publicURL ?? `http://localhost:${backend.port ?? 4000}`,\n };\n }\n\n if (frontend) {\n services.frontend = {\n platform: { type: requirePlatform(frontend.platform, 'frontend') },\n port: frontend.port ?? 3000,\n siteName: site?.siteName ?? 'Semiont',\n publicURL: frontend.publicURL,\n };\n }\n\n if (resolved.graph) {\n services.graph = {\n ...resolved.graph,\n platform: { type: requirePlatform(resolved.graph.platform as string | undefined, 'graph') },\n type: (resolved.graph.type ?? 'neo4j') as import('./config.types').GraphDatabaseType,\n } as EnvironmentConfig['services']['graph'];\n } else if (makeMeaningSection?.graph) {\n services.graph = makeMeaningSection.graph as EnvironmentConfig['services']['graph'];\n }\n\n if (resolved.database) {\n services.database = {\n platform: { type: requirePlatform(resolved.database.platform, 'database') },\n type: 'postgres',\n image: resolved.database.image,\n host: resolved.database.host ?? 'localhost',\n port: resolved.database.port ?? 5432,\n name: resolved.database.name,\n user: resolved.database.user,\n password: resolved.database.password,\n } as EnvironmentConfig['services']['database'];\n }\n\n if (resolved.vectors) {\n services.vectors = {\n platform: { type: 'external' as PlatformType },\n type: (resolved.vectors.type ?? 'qdrant') as 'qdrant' | 'memory',\n host: resolved.vectors.host,\n port: resolved.vectors.port ?? 6333,\n } as EnvironmentConfig['services']['vectors'];\n }\n\n // Embedding: top-level takes precedence, fall back to legacy vectors.embedding\n const embeddingSource = resolved.embedding ?? resolved.vectors?.embedding;\n if (embeddingSource) {\n services.embedding = {\n platform: { type: 'external' as PlatformType },\n type: embeddingSource.type!,\n model: embeddingSource.model!,\n apiKey: embeddingSource.apiKey,\n baseURL: embeddingSource.baseURL,\n endpoint: embeddingSource.endpoint,\n chunking: (resolved.embedding?.chunking ?? resolved.vectors?.chunking) ? {\n chunkSize: (resolved.embedding?.chunking ?? resolved.vectors?.chunking)?.chunkSize ?? 512,\n overlap: (resolved.embedding?.chunking ?? resolved.vectors?.chunking)?.overlap ?? 64,\n } : undefined,\n } as EnvironmentConfig['services']['embedding'];\n }\n\n const config: EnvironmentConfig = {\n services,\n ...(inferenceProviders ? { inference: inferenceProviders } : {}),\n ...(Object.keys(topLevelWorkers).length > 0 ? { workers: topLevelWorkers } : {}),\n ...(Object.keys(topLevelActors).length > 0 ? { actors: topLevelActors } : {}),\n site: site ? {\n domain: site.domain ?? 'localhost',\n siteName: site.siteName,\n adminEmail: site.adminEmail,\n oauthAllowedDomains: site.oauthAllowedDomains as [string, ...string[]] | undefined,\n } : undefined,\n logLevel: resolved.logLevel,\n _metadata: {\n environment: resolvedEnvironment,\n projectRoot,\n projectName,\n projectVersion,\n ...(Object.keys(actors).length > 0 ? { actors } : {}),\n ...(Object.keys(workers).length > 0 ? { workers } : {}),\n // Always set — the loader is the ONE home of this default (D5).\n // Consuming code (make-meaning's gather path) receives a required\n // value and defaults nothing.\n gather: { settleTimeoutMs: makeMeaningSection?.gather?.settleTimeoutMs ?? 15_000 },\n },\n };\n\n return config;\n}\n\n/**\n * Create a TOML config loader backed by a file reader.\n * Drop-in replacement for createConfigLoader that reads TOML instead of JSON.\n * The caller must resolve globalConfigPath (e.g. expand '~' using process.env.HOME).\n */\nexport function createTomlConfigLoader(\n reader: TomlFileReader,\n globalConfigPath: string,\n env: Record<string, string | undefined>\n) {\n return (projectRoot: string | null, environment?: string): EnvironmentConfig => {\n return loadTomlConfig(projectRoot, environment, globalConfigPath, reader, env);\n };\n}\n","import * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { execFileSync } from 'child_process';\n\n/**\n * Represents a Semiont project rooted at a given directory.\n *\n * Computes all paths — durable and ephemeral — once at construction time.\n * XDG environment variables are read here and nowhere else.\n *\n * Durable paths (inside the project root, committed or repo-local):\n * eventsDir — .semiont/events/ (system of record, committed)\n *\n * Ephemeral paths (outside the project root, never committed):\n * configDir — $XDG_CONFIG_HOME/semiont/{name}/ (generated config for managed processes)\n * dataHome — $XDG_DATA_HOME/semiont/{name}/ (persistent user data, e.g. database files)\n * stateDir — $XDG_STATE_HOME/semiont/{name}/\n * projectionsDir — stateDir/projections/\n * jobsDir — stateDir/jobs/\n * backendLogsDir — stateDir/backend/\n * backendAppLogFile — backendLogsDir/app.log\n * backendErrorLogFile — backendLogsDir/error.log\n * runtimeDir — $XDG_RUNTIME_DIR/semiont/{name}/ (or $TMPDIR fallback)\n * backendPidFile — runtimeDir/backend.pid\n *\n * Note: frontend paths are NOT project-scoped. The frontend service is bundled\n * with the CLI and uses fixed XDG paths keyed by \"frontend\", not project name.\n * See apps/cli/src/platforms/posix/handlers/frontend-paths.ts.\n */\nexport class SemiontProject {\n readonly root: string;\n readonly name: string;\n\n /** True if [git] sync = true in .semiont/config. When true, semiont stages\n * working-tree and event-log changes in the git index automatically. */\n readonly gitSync: boolean;\n\n // Durable\n readonly eventsDir: string;\n\n // Ephemeral — config (generated config files for managed processes)\n readonly configDir: string;\n\n // Ephemeral — data (persistent user data managed by semiont)\n readonly dataHome: string;\n\n // Ephemeral — state\n readonly stateDir: string;\n readonly projectionsDir: string;\n readonly jobsDir: string;\n readonly backendLogsDir: string;\n readonly backendAppLogFile: string;\n readonly backendErrorLogFile: string;\n\n // Ephemeral — runtime\n readonly runtimeDir: string;\n readonly backendPidFile: string;\n\n constructor(projectRoot: string, name?: string) {\n this.root = projectRoot;\n if (name !== undefined) {\n const configPath = path.join(projectRoot, '.semiont', 'config');\n if (!fs.existsSync(configPath)) {\n fs.mkdirSync(path.join(projectRoot, '.semiont'), { recursive: true });\n fs.writeFileSync(configPath, `[project]\\nname = \"${name}\"\\n`);\n }\n }\n this.name = SemiontProject.readName(projectRoot);\n this.gitSync = SemiontProject.readGitSync(projectRoot);\n\n this.eventsDir = path.join(projectRoot, '.semiont', 'events');\n\n const xdgConfig = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config');\n this.configDir = path.join(xdgConfig, 'semiont', this.name);\n\n const xdgData = process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share');\n this.dataHome = path.join(xdgData, 'semiont', this.name);\n\n const xdgState = process.env.XDG_STATE_HOME || path.join(os.homedir(), '.local', 'state');\n this.stateDir = path.join(xdgState, 'semiont', this.name);\n this.projectionsDir = path.join(this.stateDir, 'projections');\n this.jobsDir = path.join(this.stateDir, 'jobs');\n this.backendLogsDir = path.join(this.stateDir, 'backend');\n this.backendAppLogFile = path.join(this.backendLogsDir, 'app.log');\n this.backendErrorLogFile = path.join(this.backendLogsDir, 'error.log');\n\n const xdgRuntime = process.env.XDG_RUNTIME_DIR;\n const runtimeBase = xdgRuntime ?? process.env.TMPDIR ?? '/tmp';\n this.runtimeDir = path.join(runtimeBase, 'semiont', this.name);\n this.backendPidFile = path.join(this.runtimeDir, 'backend.pid');\n }\n\n /**\n * Read the current git branch for the project root.\n * Returns null if the project is not a git repo or git is not available.\n */\n gitBranch(): string | null {\n try {\n return execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {\n cwd: this.root,\n encoding: 'utf-8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }).trim() || null;\n } catch {\n return null;\n }\n }\n\n /**\n * Delete all ephemeral state for this project (stateDir + runtimeDir).\n * Does not touch eventsDir or dataDir.\n */\n async destroy(): Promise<void> {\n await Promise.all([\n fs.promises.rm(this.configDir, { recursive: true, force: true }),\n fs.promises.rm(this.stateDir, { recursive: true, force: true }),\n fs.promises.rm(this.runtimeDir, { recursive: true, force: true }),\n ]);\n }\n\n /**\n * The KB's permanent identity literal — `[site] domain` from the committed\n * `.semiont/config`, which `kbDid()` renders as `did:web:<domain>`.\n * `undefined` when the section or key is absent.\n *\n * Reads the committed file DIRECTLY, and deliberately not\n * `EnvironmentConfig.site.domain`, which is the same value only by\n * accident: the TOML loader defaults a domain-less `[site]` to the string\n * `'localhost'` (so every domain-less KB on a machine would claim one\n * fabricated `did:web:localhost`) and lets the environment section\n * override the KB's own declaration. Either would report an identity the\n * launcher never minted — an address wearing a name, which is the whole\n * category error .plans/KB-IDENTITY-VS-ADDRESS.md exists to end. Identity\n * is declared or absent; it is never defaulted.\n */\n siteDomain(): string | undefined {\n const configPath = path.join(this.root, '.semiont', 'config');\n if (!fs.existsSync(configPath)) return undefined;\n const content = fs.readFileSync(configPath, 'utf-8');\n let inSiteSection = false;\n for (const line of content.split('\\n')) {\n const trimmed = line.trim();\n if (trimmed.startsWith('#')) continue;\n if (trimmed === '[site]') { inSiteSection = true; continue; }\n if (trimmed.startsWith('[')) { inSiteSection = false; continue; }\n if (!inSiteSection) continue;\n const eq = trimmed.indexOf('=');\n if (eq < 0) continue;\n if (trimmed.slice(0, eq).trim() !== 'domain') continue;\n const value = trimmed.slice(eq + 1).trim().replace(/^\"(.*)\"$/, '$1');\n return value === '' ? undefined : value;\n }\n return undefined;\n }\n\n /**\n * Read [git] sync from .semiont/config.\n * Defaults to false if the section or key is absent.\n */\n private static readGitSync(projectRoot: string): boolean {\n const configPath = path.join(projectRoot, '.semiont', 'config');\n if (!fs.existsSync(configPath)) return false;\n const content = fs.readFileSync(configPath, 'utf-8');\n let inGitSection = false;\n for (const line of content.split('\\n')) {\n const trimmed = line.trim();\n if (trimmed === '[git]') { inGitSection = true; continue; }\n if (trimmed.startsWith('[')) { inGitSection = false; continue; }\n if (inGitSection && trimmed.startsWith('sync') && trimmed.includes('=')) {\n const value = trimmed.split('=')[1]?.trim();\n return value === 'true';\n }\n }\n return false;\n }\n\n /**\n * Read the project name from .semiont/config [project] name = \"...\"\n * Falls back to the directory basename if the config is absent or has no name.\n */\n private static readName(projectRoot: string): string {\n const configPath = path.join(projectRoot, '.semiont', 'config');\n if (fs.existsSync(configPath)) {\n const content = fs.readFileSync(configPath, 'utf-8');\n for (const line of content.split('\\n')) {\n const trimmed = line.trim();\n if (trimmed.startsWith('name') && trimmed.includes('=')) {\n const [, ...rest] = trimmed.split('=');\n return rest.join('=').trim().replace(/^\"(.*)\"$/, '$1');\n }\n }\n }\n return path.basename(projectRoot);\n }\n}\n","import * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { createTomlConfigLoader } from './toml-loader.js';\nimport type { EnvironmentConfig } from './config.types.js';\n\nexport { SemiontProject } from '../project.js';\n\nconst nodeTomlFileReader = {\n readIfExists: (filePath: string): string | null =>\n fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : null,\n};\n\n/**\n * Load semiont environment config for a Node.js process.\n *\n * Reads ~/.semiontconfig (global) merged with .semiont/config (project-local),\n * then selects the given environment overlay.\n *\n * This is the canonical config loader for any Node.js process. The environment\n * is resolved by the loader itself — explicit `environment` arg > SEMIONT_ENV >\n * `[defaults] environment` — so entry points call this WITHOUT reading\n * SEMIONT_ENV (or inventing a default); one config selects the environment for\n * the backend the same way the launcher selects it.\n */\nexport function loadEnvironmentConfig(\n projectRoot: string,\n environment?: string\n): EnvironmentConfig {\n const globalConfigPath = path.join(os.homedir(), '.semiontconfig');\n return createTomlConfigLoader(\n nodeTomlFileReader,\n globalConfigPath,\n process.env\n )(projectRoot, environment);\n}\n"]}
1
+ {"version":3,"sources":["../../src/project.ts","../../src/config/node-config-loader.ts"],"names":["fs2","path2","os2"],"mappings":";;;;;;AA8BO,IAAM,cAAA,GAAN,MAAM,eAAA,CAAe;AAAA,EACjB,IAAA;AAAA,EACA,IAAA;AAAA;AAAA;AAAA,EAIA,OAAA;AAAA;AAAA,EAGA,SAAA;AAAA;AAAA,EAGA,SAAA;AAAA;AAAA,EAGA,QAAA;AAAA;AAAA,EAGA,QAAA;AAAA,EACA,cAAA;AAAA,EACA,OAAA;AAAA,EACA,cAAA;AAAA,EACA,iBAAA;AAAA,EACA,mBAAA;AAAA;AAAA,EAGA,UAAA;AAAA,EACA,cAAA;AAAA,EAET,WAAA,CAAY,aAAqB,IAAA,EAAe;AAC9C,IAAA,IAAA,CAAK,IAAA,GAAO,WAAA;AACZ,IAAA,IAAI,SAAS,MAAA,EAAW;AACtB,MAAA,MAAM,UAAA,GAAkB,IAAA,CAAA,IAAA,CAAK,WAAA,EAAa,UAAA,EAAY,QAAQ,CAAA;AAC9D,MAAA,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qBAAA,CACd,aACA,WAAA,EACmB;AACnB,EAAA,MAAM,gBAAA,GAAwBC,IAAA,CAAA,IAAA,CAAQC,EAAA,CAAA,OAAA,EAAQ,EAAG,gBAAgB,CAAA;AACjE,EAAA,OAAO,sBAAA;AAAA,IACL,kBAAA;AAAA,IACA,gBAAA;AAAA,IACA,OAAA,CAAQ;AAAA,GACV,CAAE,aAAa,WAAW,CAAA;AAC5B","file":"node-config-loader.js","sourcesContent":["import * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { execFileSync } from 'child_process';\n\n/**\n * Represents a Semiont project rooted at a given directory.\n *\n * Computes all paths — durable and ephemeral — once at construction time.\n * XDG environment variables are read here and nowhere else.\n *\n * Durable paths (inside the project root, committed or repo-local):\n * eventsDir — .semiont/events/ (system of record, committed)\n *\n * Ephemeral paths (outside the project root, never committed):\n * configDir — $XDG_CONFIG_HOME/semiont/{name}/ (generated config for managed processes)\n * dataHome — $XDG_DATA_HOME/semiont/{name}/ (persistent user data, e.g. database files)\n * stateDir — $XDG_STATE_HOME/semiont/{name}/\n * projectionsDir — stateDir/projections/\n * jobsDir — stateDir/jobs/\n * backendLogsDir — stateDir/backend/\n * backendAppLogFile — backendLogsDir/app.log\n * backendErrorLogFile — backendLogsDir/error.log\n * runtimeDir — $XDG_RUNTIME_DIR/semiont/{name}/ (or $TMPDIR fallback)\n * backendPidFile — runtimeDir/backend.pid\n *\n * Note: the frontend has no entry here, deliberately. It serves static assets\n * from its own container image and keeps no per-project state on the host, so\n * there is nothing to derive from a project root.\n */\nexport class SemiontProject {\n readonly root: string;\n readonly name: string;\n\n /** True if [git] sync = true in .semiont/config. When true, semiont stages\n * working-tree and event-log changes in the git index automatically. */\n readonly gitSync: boolean;\n\n // Durable\n readonly eventsDir: string;\n\n // Ephemeral — config (generated config files for managed processes)\n readonly configDir: string;\n\n // Ephemeral — data (persistent user data managed by semiont)\n readonly dataHome: string;\n\n // Ephemeral — state\n readonly stateDir: string;\n readonly projectionsDir: string;\n readonly jobsDir: string;\n readonly backendLogsDir: string;\n readonly backendAppLogFile: string;\n readonly backendErrorLogFile: string;\n\n // Ephemeral — runtime\n readonly runtimeDir: string;\n readonly backendPidFile: string;\n\n constructor(projectRoot: string, name?: string) {\n this.root = projectRoot;\n if (name !== undefined) {\n const configPath = path.join(projectRoot, '.semiont', 'config');\n if (!fs.existsSync(configPath)) {\n fs.mkdirSync(path.join(projectRoot, '.semiont'), { recursive: true });\n fs.writeFileSync(configPath, `[project]\\nname = \"${name}\"\\n`);\n }\n }\n this.name = SemiontProject.readName(projectRoot);\n this.gitSync = SemiontProject.readGitSync(projectRoot);\n\n this.eventsDir = path.join(projectRoot, '.semiont', 'events');\n\n const xdgConfig = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config');\n this.configDir = path.join(xdgConfig, 'semiont', this.name);\n\n const xdgData = process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share');\n this.dataHome = path.join(xdgData, 'semiont', this.name);\n\n const xdgState = process.env.XDG_STATE_HOME || path.join(os.homedir(), '.local', 'state');\n this.stateDir = path.join(xdgState, 'semiont', this.name);\n this.projectionsDir = path.join(this.stateDir, 'projections');\n this.jobsDir = path.join(this.stateDir, 'jobs');\n this.backendLogsDir = path.join(this.stateDir, 'backend');\n this.backendAppLogFile = path.join(this.backendLogsDir, 'app.log');\n this.backendErrorLogFile = path.join(this.backendLogsDir, 'error.log');\n\n const xdgRuntime = process.env.XDG_RUNTIME_DIR;\n const runtimeBase = xdgRuntime ?? process.env.TMPDIR ?? '/tmp';\n this.runtimeDir = path.join(runtimeBase, 'semiont', this.name);\n this.backendPidFile = path.join(this.runtimeDir, 'backend.pid');\n }\n\n /**\n * Read the current git branch for the project root.\n * Returns null if the project is not a git repo or git is not available.\n */\n gitBranch(): string | null {\n try {\n return execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], {\n cwd: this.root,\n encoding: 'utf-8',\n stdio: ['ignore', 'pipe', 'ignore'],\n }).trim() || null;\n } catch {\n return null;\n }\n }\n\n /**\n * Delete all ephemeral state for this project (stateDir + runtimeDir).\n * Does not touch eventsDir or dataDir.\n */\n async destroy(): Promise<void> {\n await Promise.all([\n fs.promises.rm(this.configDir, { recursive: true, force: true }),\n fs.promises.rm(this.stateDir, { recursive: true, force: true }),\n fs.promises.rm(this.runtimeDir, { recursive: true, force: true }),\n ]);\n }\n\n /**\n * The KB's permanent identity literal — `[site] domain` from the committed\n * `.semiont/config`, which `kbDid()` renders as `did:web:<domain>`.\n * `undefined` when the section or key is absent.\n *\n * Reads the committed file DIRECTLY, and deliberately not\n * `EnvironmentConfig.site.domain`, which is the same value only by\n * accident: the TOML loader defaults a domain-less `[site]` to the string\n * `'localhost'` (so every domain-less KB on a machine would claim one\n * fabricated `did:web:localhost`) and lets the environment section\n * override the KB's own declaration. Either would report an identity the\n * launcher never minted — an address wearing a name, which is the whole\n * category error .plans/KB-IDENTITY-VS-ADDRESS.md exists to end. Identity\n * is declared or absent; it is never defaulted.\n */\n siteDomain(): string | undefined {\n const configPath = path.join(this.root, '.semiont', 'config');\n if (!fs.existsSync(configPath)) return undefined;\n const content = fs.readFileSync(configPath, 'utf-8');\n let inSiteSection = false;\n for (const line of content.split('\\n')) {\n const trimmed = line.trim();\n if (trimmed.startsWith('#')) continue;\n if (trimmed === '[site]') { inSiteSection = true; continue; }\n if (trimmed.startsWith('[')) { inSiteSection = false; continue; }\n if (!inSiteSection) continue;\n const eq = trimmed.indexOf('=');\n if (eq < 0) continue;\n if (trimmed.slice(0, eq).trim() !== 'domain') continue;\n const value = trimmed.slice(eq + 1).trim().replace(/^\"(.*)\"$/, '$1');\n return value === '' ? undefined : value;\n }\n return undefined;\n }\n\n /**\n * Read [git] sync from .semiont/config.\n * Defaults to false if the section or key is absent.\n */\n private static readGitSync(projectRoot: string): boolean {\n const configPath = path.join(projectRoot, '.semiont', 'config');\n if (!fs.existsSync(configPath)) return false;\n const content = fs.readFileSync(configPath, 'utf-8');\n let inGitSection = false;\n for (const line of content.split('\\n')) {\n const trimmed = line.trim();\n if (trimmed === '[git]') { inGitSection = true; continue; }\n if (trimmed.startsWith('[')) { inGitSection = false; continue; }\n if (inGitSection && trimmed.startsWith('sync') && trimmed.includes('=')) {\n const value = trimmed.split('=')[1]?.trim();\n return value === 'true';\n }\n }\n return false;\n }\n\n /**\n * Read the project name from .semiont/config [project] name = \"...\"\n * Falls back to the directory basename if the config is absent or has no name.\n */\n private static readName(projectRoot: string): string {\n const configPath = path.join(projectRoot, '.semiont', 'config');\n if (fs.existsSync(configPath)) {\n const content = fs.readFileSync(configPath, 'utf-8');\n for (const line of content.split('\\n')) {\n const trimmed = line.trim();\n if (trimmed.startsWith('name') && trimmed.includes('=')) {\n const [, ...rest] = trimmed.split('=');\n return rest.join('=').trim().replace(/^\"(.*)\"$/, '$1');\n }\n }\n }\n return path.basename(projectRoot);\n }\n}\n","import * as fs from 'fs';\nimport * as os from 'os';\nimport * as path from 'path';\nimport { createTomlConfigLoader } from './toml-loader.js';\nimport type { EnvironmentConfig } from './config.types.js';\n\nexport { SemiontProject } from '../project.js';\n\nconst nodeTomlFileReader = {\n readIfExists: (filePath: string): string | null =>\n fs.existsSync(filePath) ? fs.readFileSync(filePath, 'utf-8') : null,\n};\n\n/**\n * Load semiont environment config for a Node.js process.\n *\n * Reads ~/.semiontconfig (global) merged with .semiont/config (project-local),\n * then selects the given environment overlay.\n *\n * This is the canonical config loader for any Node.js process. The environment\n * is resolved by the loader itself — an explicit `environment` argument, else\n * `[defaults] environment` from the committed config — so entry points call this\n * without selecting one; one config selects the environment for the backend the\n * same way the launcher selects it. There is no environment-variable override.\n */\nexport function loadEnvironmentConfig(\n projectRoot: string,\n environment?: string\n): EnvironmentConfig {\n const globalConfigPath = path.join(os.homedir(), '.semiontconfig');\n return createTomlConfigLoader(\n nodeTomlFileReader,\n globalConfigPath,\n process.env\n )(projectRoot, environment);\n}\n"]}