@hexclave/shared-backend 1.0.33 → 1.0.34
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/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +96 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +96 -5
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;;iBAkDgB,YAAA,CAAa,KAAA;AAAA,iBAIb,qBAAA,CAAsB,SAAA;AAAA,iBAkBtB,sBAAA,CAAuB,cAAA;AAAA,iBAMjB,gBAAA,CAAiB,cAAA,WAAyB,OAAA,CAAQ,MAAA;AAAA,iBAIlD,cAAA,CAAe,cAAA,WAAyB,OAAA;EAAU,MAAA,EAAQ,MAAA;EAAQ,cAAA;AAAA;AAAA,iBAkElE,kBAAA,CAAmB,cAAA,UAAwB,YAAA,EAAc,MAAA,GAAS,OAAA;AAAA,iBA+ElE,mBAAA,CAAoB,cAAA,UAAwB,MAAA,EAAQ,MAAA,GAAS,OAAA"}
|
package/dist/esm/index.js
CHANGED
|
@@ -12,6 +12,23 @@ import { ClaudeAgentFailureError, ClaudeAgentTimeoutError, getToolWriteTargetPat
|
|
|
12
12
|
const jiti = createJiti(import.meta.url, { moduleCache: false });
|
|
13
13
|
const LOG_PREFIX = "[Stack config updater]";
|
|
14
14
|
const DEFAULT_AGENT_TIMEOUT_MS = 12e4;
|
|
15
|
+
const CONFIG_UPDATE_LOG_PATH_LIMIT = 40;
|
|
16
|
+
function formatConfigUpdaterErrorForLog(error) {
|
|
17
|
+
if (error instanceof Error) return {
|
|
18
|
+
errorName: error.name,
|
|
19
|
+
errorMessage: error.message,
|
|
20
|
+
errorStack: error.stack
|
|
21
|
+
};
|
|
22
|
+
return { errorMessage: String(error) };
|
|
23
|
+
}
|
|
24
|
+
function configUpdatePathDetailsForLog(changes) {
|
|
25
|
+
const paths = changes.map(({ path: configPath }) => configPath).sort();
|
|
26
|
+
return {
|
|
27
|
+
configUpdatePathCount: paths.length,
|
|
28
|
+
configUpdatePaths: paths.slice(0, CONFIG_UPDATE_LOG_PATH_LIMIT),
|
|
29
|
+
configUpdatePathsTruncated: paths.length > CONFIG_UPDATE_LOG_PATH_LIMIT
|
|
30
|
+
};
|
|
31
|
+
}
|
|
15
32
|
function isConfigModule(value) {
|
|
16
33
|
return value !== null && typeof value === "object";
|
|
17
34
|
}
|
|
@@ -81,16 +98,35 @@ function renderConfigObjectToFile(configFilePath, config) {
|
|
|
81
98
|
writeFileAtomic(configFilePath, renderConfigObjectToString(configFilePath, config));
|
|
82
99
|
}
|
|
83
100
|
async function updateConfigObject(configFilePath, configUpdate) {
|
|
101
|
+
const startedAtMs = performance.now();
|
|
84
102
|
ensureConfigFileExists(configFilePath);
|
|
85
|
-
|
|
103
|
+
const changes = flattenConfigUpdate(configUpdate);
|
|
104
|
+
if (changes.length === 0) {
|
|
105
|
+
console.log(`${LOG_PREFIX} Skipping config update because it contains no changes`, { configFilePath });
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const updateLogDetails = {
|
|
109
|
+
configFilePath,
|
|
110
|
+
...configUpdatePathDetailsForLog(changes)
|
|
111
|
+
};
|
|
112
|
+
console.log(`${LOG_PREFIX} Starting config file update`, updateLogDetails);
|
|
86
113
|
const content = readFileSync(configFilePath, "utf-8");
|
|
87
114
|
const staticConfig = tryParseStaticConfigFileContent(content, configFilePath);
|
|
88
115
|
if (staticConfig != null && isValidConfig(staticConfig)) {
|
|
116
|
+
console.log(`${LOG_PREFIX} Applying config update with static config rewrite`, updateLogDetails);
|
|
89
117
|
const merged = override(staticConfig, configUpdate);
|
|
90
118
|
if (!isValidConfig(merged)) throw new Error(`${LOG_PREFIX} Merged config is invalid after applying update to ${configFilePath}`);
|
|
91
119
|
renderConfigObjectToFile(configFilePath, merged);
|
|
120
|
+
console.log(`${LOG_PREFIX} Finished config update with static config rewrite`, {
|
|
121
|
+
...updateLogDetails,
|
|
122
|
+
elapsedMs: Math.round(performance.now() - startedAtMs)
|
|
123
|
+
});
|
|
92
124
|
return;
|
|
93
125
|
}
|
|
126
|
+
console.log(`${LOG_PREFIX} Applying config update with agent-assisted rewrite`, {
|
|
127
|
+
...updateLogDetails,
|
|
128
|
+
configDirectory: path.dirname(configFilePath)
|
|
129
|
+
});
|
|
94
130
|
const baselineConfig = await tryReadConfigForValidation(configFilePath);
|
|
95
131
|
const { snapshots, seen } = snapshotConfigFiles(configFilePath, content);
|
|
96
132
|
try {
|
|
@@ -101,16 +137,31 @@ async function updateConfigObject(configFilePath, configUpdate) {
|
|
|
101
137
|
});
|
|
102
138
|
await validateAgentUpdate(configFilePath, baselineConfig, configUpdate, snapshots);
|
|
103
139
|
} catch (error) {
|
|
140
|
+
console.warn(`${LOG_PREFIX} Config update failed; restoring files from snapshots`, {
|
|
141
|
+
...updateLogDetails,
|
|
142
|
+
snapshotCount: snapshots.length,
|
|
143
|
+
elapsedMs: Math.round(performance.now() - startedAtMs),
|
|
144
|
+
...formatConfigUpdaterErrorForLog(error)
|
|
145
|
+
});
|
|
104
146
|
try {
|
|
105
147
|
restoreConfigFiles(snapshots);
|
|
148
|
+
console.warn(`${LOG_PREFIX} Restored files after failed config update`, {
|
|
149
|
+
...updateLogDetails,
|
|
150
|
+
snapshotCount: snapshots.length
|
|
151
|
+
});
|
|
106
152
|
} catch (restoreError) {
|
|
107
153
|
console.error(`${LOG_PREFIX} Failed to fully roll back config files after a failed update of ${configFilePath}; some files may be left in a partially-restored state`, {
|
|
108
154
|
configFilePath,
|
|
109
|
-
|
|
155
|
+
...formatConfigUpdaterErrorForLog(restoreError)
|
|
110
156
|
});
|
|
111
157
|
}
|
|
112
158
|
throw error;
|
|
113
159
|
}
|
|
160
|
+
console.log(`${LOG_PREFIX} Finished config update with agent-assisted rewrite`, {
|
|
161
|
+
...updateLogDetails,
|
|
162
|
+
elapsedMs: Math.round(performance.now() - startedAtMs),
|
|
163
|
+
snapshotCount: snapshots.length
|
|
164
|
+
});
|
|
114
165
|
}
|
|
115
166
|
async function replaceConfigObject(configFilePath, config) {
|
|
116
167
|
renderConfigObjectToFile(configFilePath, config);
|
|
@@ -118,6 +169,11 @@ async function replaceConfigObject(configFilePath, config) {
|
|
|
118
169
|
async function runConfigUpdateAgent(options) {
|
|
119
170
|
const timeoutMs = parseAgentTimeoutMs();
|
|
120
171
|
const deniedOutOfBoundsWrites = /* @__PURE__ */ new Set();
|
|
172
|
+
const startedAtMs = performance.now();
|
|
173
|
+
console.log(`${LOG_PREFIX} Starting config update agent`, {
|
|
174
|
+
cwd: options.cwd,
|
|
175
|
+
timeoutMs
|
|
176
|
+
});
|
|
121
177
|
try {
|
|
122
178
|
await runHeadlessClaudeAgent({
|
|
123
179
|
prompt: options.prompt,
|
|
@@ -150,11 +206,46 @@ async function runConfigUpdateAgent(options) {
|
|
|
150
206
|
}
|
|
151
207
|
});
|
|
152
208
|
} catch (error) {
|
|
153
|
-
if (error instanceof ClaudeAgentTimeoutError)
|
|
154
|
-
|
|
209
|
+
if (error instanceof ClaudeAgentTimeoutError) {
|
|
210
|
+
console.warn(`${LOG_PREFIX} Config update agent timed out`, {
|
|
211
|
+
cwd: options.cwd,
|
|
212
|
+
timeoutMs,
|
|
213
|
+
elapsedMs: Math.round(performance.now() - startedAtMs),
|
|
214
|
+
...formatConfigUpdaterErrorForLog(error)
|
|
215
|
+
});
|
|
216
|
+
throw new Error(`Config update agent timed out after ${timeoutMs}ms. It was unable to apply the config changes to the file.`);
|
|
217
|
+
}
|
|
218
|
+
if (error instanceof ClaudeAgentFailureError) {
|
|
219
|
+
console.warn(`${LOG_PREFIX} Config update agent failed`, {
|
|
220
|
+
cwd: options.cwd,
|
|
221
|
+
timeoutMs,
|
|
222
|
+
elapsedMs: Math.round(performance.now() - startedAtMs),
|
|
223
|
+
...formatConfigUpdaterErrorForLog(error)
|
|
224
|
+
});
|
|
225
|
+
throw new Error(`${error.message} It was unable to apply the config changes to the file.`);
|
|
226
|
+
}
|
|
227
|
+
console.warn(`${LOG_PREFIX} Config update agent failed unexpectedly`, {
|
|
228
|
+
cwd: options.cwd,
|
|
229
|
+
timeoutMs,
|
|
230
|
+
elapsedMs: Math.round(performance.now() - startedAtMs),
|
|
231
|
+
...formatConfigUpdaterErrorForLog(error)
|
|
232
|
+
});
|
|
155
233
|
throw error;
|
|
156
234
|
}
|
|
157
|
-
|
|
235
|
+
console.log(`${LOG_PREFIX} Finished config update agent`, {
|
|
236
|
+
cwd: options.cwd,
|
|
237
|
+
timeoutMs,
|
|
238
|
+
elapsedMs: Math.round(performance.now() - startedAtMs),
|
|
239
|
+
deniedOutOfBoundsWriteCount: deniedOutOfBoundsWrites.size
|
|
240
|
+
});
|
|
241
|
+
if (deniedOutOfBoundsWrites.size > 0) {
|
|
242
|
+
console.warn(`${LOG_PREFIX} Config update agent attempted out-of-bounds writes`, {
|
|
243
|
+
cwd: options.cwd,
|
|
244
|
+
deniedOutOfBoundsWriteCount: deniedOutOfBoundsWrites.size,
|
|
245
|
+
deniedOutOfBoundsWrites: [...deniedOutOfBoundsWrites]
|
|
246
|
+
});
|
|
247
|
+
throw new Error(`Config update agent tried to modify ${deniedOutOfBoundsWrites.size} file(s) outside the config directory, which is not allowed: ${[...deniedOutOfBoundsWrites].join(", ")}. The config was not updated.`);
|
|
248
|
+
}
|
|
158
249
|
}
|
|
159
250
|
function parseAgentTimeoutMs() {
|
|
160
251
|
const raw = process.env.STACK_CONFIG_UPDATE_AGENT_TIMEOUT_MS;
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { showOnboardingHexclaveConfigValue } from \"@hexclave/shared/dist/config-authoring\";\nimport { detectImportPackageFromDir, parseHexclaveConfigFileContent, renderConfigFileContent } from \"@hexclave/shared/dist/config-rendering\";\nimport type { Config, ConfigValue, NormalizedConfig } from \"@hexclave/shared/dist/config/format\";\nimport { isValidConfig, normalize, override } from \"@hexclave/shared/dist/config/format\";\nimport { captureError } from \"@hexclave/shared/dist/utils/errors\";\nimport { createHash } from \"crypto\";\nimport { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from \"fs\";\nimport { createJiti } from \"jiti\";\nimport path from \"path\";\nimport { ClaudeAgentFailureError, ClaudeAgentTimeoutError, getToolWriteTargetPath, isPathInsideDir, runHeadlessClaudeAgent } from \"./config-agent\";\n\nconst jiti = createJiti(import.meta.url, { moduleCache: false });\n\nconst LOG_PREFIX = \"[Stack config updater]\";\nconst DEFAULT_AGENT_TIMEOUT_MS = 120_000;\n\ntype ConfigModule = {\n config?: unknown,\n};\n\ntype ConfigFileSnapshot = { path: string, content: string | null };\ntype ConfigChange = { path: string, value: ConfigValue };\n\nfunction isConfigModule(value: unknown): value is ConfigModule {\n return value !== null && typeof value === \"object\";\n}\n\nexport function sha256String(value: string): string {\n return createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nexport function resolveConfigFilePath(inputPath: string): string {\n const resolved = path.resolve(inputPath);\n const looksLikeConfigFile = /\\.(ts|js|mjs|cjs)$/i.test(resolved);\n if (looksLikeConfigFile) {\n return resolved;\n }\n // Prefer hexclave.config.ts, fall back to stack.config.ts, default to the new name.\n const hexclaveCandidate = path.join(resolved, \"hexclave.config.ts\");\n const legacyCandidate = path.join(resolved, \"stack.config.ts\");\n if (existsSync(hexclaveCandidate)) {\n return hexclaveCandidate;\n }\n if (existsSync(legacyCandidate)) {\n return legacyCandidate;\n }\n return hexclaveCandidate;\n}\n\nexport function ensureConfigFileExists(configFilePath: string): void {\n if (existsSync(configFilePath)) return;\n mkdirSync(path.dirname(configFilePath), { recursive: true });\n renderConfigObjectToFile(configFilePath, {});\n}\n\nexport async function readConfigObject(configFilePath: string): Promise<Config> {\n return (await readConfigFile(configFilePath)).config;\n}\n\nexport async function readConfigFile(configFilePath: string): Promise<{ config: Config, showOnboarding: boolean }> {\n ensureConfigFileExists(configFilePath);\n const content = readFileSync(configFilePath, \"utf-8\");\n if (content.trim() === \"\") {\n return {\n config: {},\n showOnboarding: false,\n };\n }\n\n let configModule: unknown;\n try {\n configModule = await jiti.import<unknown>(configFilePath);\n } catch (error) {\n // Capture the raw jiti/framework error for diagnostics, but don't attach it as `cause` on the thrown error:\n // dashboard error formatting renders causes recursively, which would leak framework internals into the\n // user-facing message we're deliberately replacing.\n captureError(\"shared-backend/readConfigFile\", error);\n throw new Error(\n `Failed to load config file ${configFilePath}.`,\n );\n }\n if (!isConfigModule(configModule)) {\n throw new Error(`Invalid config in ${configFilePath}. The file must export a plain \\`config\\` object or \"show-onboarding\".`);\n }\n\n const config = configModule.config;\n if (config === showOnboardingHexclaveConfigValue) {\n return {\n config: {},\n showOnboarding: true,\n };\n }\n if (!isValidConfig(config)) {\n throw new Error(`Invalid config in ${configFilePath}.`);\n }\n return {\n config,\n showOnboarding: false,\n };\n}\n\nfunction renderConfigObjectToString(configFilePath: string, config: Config): string {\n const importPackage = detectImportPackageFromDir(path.dirname(configFilePath));\n return renderConfigFileContent(config, importPackage);\n}\n\nfunction writeFileAtomic(configFilePath: string, content: string): void {\n const dir = path.dirname(configFilePath);\n mkdirSync(dir, { recursive: true });\n const tempPath = path.join(dir, `.stack.config.${Math.random().toString(36).slice(2)}.tmp`);\n writeFileSync(tempPath, content, \"utf-8\");\n try {\n renameSync(tempPath, configFilePath);\n } catch (error) {\n try {\n rmSync(tempPath);\n } catch { /* best-effort cleanup */ }\n throw error;\n }\n}\n\nfunction renderConfigObjectToFile(configFilePath: string, config: Config): void {\n writeFileAtomic(configFilePath, renderConfigObjectToString(configFilePath, config));\n}\n\nexport async function updateConfigObject(configFilePath: string, configUpdate: Config): Promise<void> {\n ensureConfigFileExists(configFilePath);\n\n if (flattenConfigUpdate(configUpdate).length === 0) return;\n\n const content = readFileSync(configFilePath, \"utf-8\");\n\n // Fast path: if the config is a plain static literal (no imports, no helpers),\n // apply the update deterministically without invoking the AI agent.\n const staticConfig = tryParseStaticConfigFileContent(content, configFilePath);\n if (staticConfig != null && isValidConfig(staticConfig)) {\n const merged = override(staticConfig, configUpdate);\n if (!isValidConfig(merged)) {\n throw new Error(`${LOG_PREFIX} Merged config is invalid after applying update to ${configFilePath}`);\n }\n renderConfigObjectToFile(configFilePath, merged);\n return;\n }\n\n // Agent path: config has custom structure (imports, helpers, external files)\n // that must be preserved — delegate to the AI agent.\n const baselineConfig = await tryReadConfigForValidation(configFilePath);\n const { snapshots, seen } = snapshotConfigFiles(configFilePath, content);\n try {\n await runConfigUpdateAgent({\n prompt: buildConfigUpdatePrompt(path.basename(configFilePath), configUpdate, baselineConfig),\n cwd: path.dirname(configFilePath),\n onFileWillChange: (filePath) => captureSnapshotIfAbsent(snapshots, filePath, seen),\n });\n await validateAgentUpdate(configFilePath, baselineConfig, configUpdate, snapshots);\n } catch (error) {\n try {\n restoreConfigFiles(snapshots);\n } catch (restoreError) {\n console.error(`${LOG_PREFIX} Failed to fully roll back config files after a failed update of ${configFilePath}; some files may be left in a partially-restored state`, {\n configFilePath,\n restoreError: restoreError instanceof Error ? restoreError.message : String(restoreError),\n });\n }\n throw error;\n }\n}\n\nexport async function replaceConfigObject(configFilePath: string, config: Config): Promise<void> {\n renderConfigObjectToFile(configFilePath, config);\n}\n\nasync function runConfigUpdateAgent(options: {\n prompt: string,\n cwd: string,\n onFileWillChange?: (filePath: string) => void,\n}): Promise<void> {\n const timeoutMs = parseAgentTimeoutMs();\n const deniedOutOfBoundsWrites = new Set<string>();\n try {\n await runHeadlessClaudeAgent({\n prompt: options.prompt,\n cwd: options.cwd,\n allowedTools: [\"Read\", \"Write\", \"Edit\", \"Glob\", \"Grep\"],\n strictIsolation: true,\n timeoutMs,\n stderr: (data) => { console.warn(`${LOG_PREFIX} [agent] ${data}`); },\n onPreToolUse: (input) => {\n const target = getToolWriteTargetPath(input.tool_name, input.tool_input, options.cwd);\n if (target == null) return { continue: true };\n if (!isPathInsideDir(options.cwd, target)) {\n deniedOutOfBoundsWrites.add(target);\n return {\n hookSpecificOutput: {\n hookEventName: \"PreToolUse\",\n permissionDecision: \"deny\",\n permissionDecisionReason: `Refusing to modify ${target}: config updates may only change files inside the config directory.`,\n },\n };\n }\n options.onFileWillChange?.(target);\n return { continue: true };\n },\n });\n } catch (error) {\n if (error instanceof ClaudeAgentTimeoutError) {\n throw new Error(`Config update agent timed out after ${timeoutMs}ms. It was unable to apply the config changes to the file.`);\n }\n if (error instanceof ClaudeAgentFailureError) {\n throw new Error(`${error.message} It was unable to apply the config changes to the file.`);\n }\n throw error;\n }\n if (deniedOutOfBoundsWrites.size > 0) {\n throw new Error(`Config update agent tried to modify ${deniedOutOfBoundsWrites.size} file(s) outside the config directory, which is not allowed: ${[...deniedOutOfBoundsWrites].join(\", \")}. The config was not updated.`);\n }\n}\n\nfunction parseAgentTimeoutMs(): number {\n const raw = process.env.STACK_CONFIG_UPDATE_AGENT_TIMEOUT_MS;\n if (raw == null || raw.trim() === \"\") return DEFAULT_AGENT_TIMEOUT_MS;\n const parsed = Number(raw);\n if (!Number.isFinite(parsed) || parsed <= 0) {\n throw new Error(`Invalid STACK_CONFIG_UPDATE_AGENT_TIMEOUT_MS: ${JSON.stringify(raw)}. Expected a positive number of milliseconds.`);\n }\n return parsed;\n}\n\nfunction captureSnapshotIfAbsent(snapshots: ConfigFileSnapshot[], filePath: string, seen: Set<string>): void {\n const resolved = path.resolve(filePath);\n if (seen.has(resolved)) return;\n seen.add(resolved);\n snapshots.push({ path: resolved, content: existsSync(resolved) ? readFileSync(resolved, \"utf-8\") : null });\n}\n\nfunction snapshotConfigFiles(configFilePath: string, configContent: string): { snapshots: ConfigFileSnapshot[]; seen: Set<string> } {\n const dir = path.dirname(configFilePath);\n const resolvedConfig = path.resolve(configFilePath);\n const snapshots: ConfigFileSnapshot[] = [{ path: resolvedConfig, content: configContent }];\n const seen = new Set<string>([resolvedConfig]);\n for (const specifier of getRelativeImportSpecifiers(configContent)) {\n const resolved = path.resolve(dir, specifier);\n if (!isPathInsideDir(dir, resolved)) continue;\n captureSnapshotIfAbsent(snapshots, resolved, seen);\n }\n return { snapshots, seen };\n}\n\nfunction restoreConfigFiles(snapshots: ConfigFileSnapshot[]): void {\n const failures: string[] = [];\n for (const { path: filePath, content } of snapshots) {\n try {\n if (content === null) {\n if (existsSync(filePath)) rmSync(filePath);\n } else {\n writeFileSync(filePath, content, \"utf-8\");\n }\n } catch (error) {\n failures.push(`${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n if (failures.length > 0) {\n throw new Error(`Failed to restore ${failures.length} file(s) during rollback: ${failures.join(\"; \")}`);\n }\n}\n\nasync function tryReadConfigForValidation(configFilePath: string): Promise<Config | null> {\n try {\n return (await readConfigFile(configFilePath)).config;\n } catch (error) {\n console.warn(`${LOG_PREFIX} Could not evaluate config for validation baseline; will fall back to a structural check`, {\n configFilePath,\n error: error instanceof Error ? error.message : String(error),\n });\n return null;\n }\n}\n\nasync function validateAgentUpdate(configFilePath: string, baselineConfig: Config | null, configUpdate: Config, snapshots: ConfigFileSnapshot[]): Promise<void> {\n if (baselineConfig != null) {\n const target = canonicalizeConfig(override(baselineConfig, configUpdate));\n const result = canonicalizeConfig((await readConfigFile(configFilePath)).config);\n if (!configsEqual(result, target)) {\n throw new Error(`Config update validation failed for ${configFilePath}: the updated file does not evaluate to the expected configuration.`);\n }\n return;\n }\n\n // Structural-only fallback: when jiti can't evaluate the config (e.g. missing\n // runtime dependencies in import-with attributes), we can only verify that\n // (a) something changed on disk and (b) the file still exports `config`.\n // This cannot catch silently mis-applied values — an accepted tradeoff vs.\n // blocking updates entirely for configs we can't evaluate.\n // When nothing changed on disk the update is either already applied or the\n // agent couldn't figure out what to do. Treat it as a no-op rather than a\n // hard failure: the structural check below still verifies the file is valid.\n if (flattenConfigUpdate(configUpdate).length > 0 && !snapshotsChangedOnDisk(snapshots)) {\n console.warn(`${LOG_PREFIX} Agent did not modify any file for ${configFilePath}; assuming values are already up to date.`);\n }\n\n const content = readFileSync(configFilePath, \"utf-8\");\n if (!configFileExportsConfig(content, configFilePath)) {\n throw new Error(`Config update validation failed for ${configFilePath}: the updated file no longer exports a valid \\`config\\`.`);\n }\n}\n\nfunction tryParseStaticConfigFileContent(content: string, configFilePath: string): Config | null {\n try {\n const parsed = parseHexclaveConfigFileContent(content, configFilePath);\n return isValidConfig(parsed) ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction configFileExportsConfig(content: string, configFilePath: string): boolean {\n try {\n parseHexclaveConfigFileContent(content, configFilePath);\n return true;\n } catch {\n // Dynamic configs can be valid even when the static parser cannot evaluate\n // them. For the structural fallback we only need to know that a runtime\n // config binding still exists after the agent edited the file.\n return /\\bexport\\s+const\\s+config\\b/.test(content);\n }\n}\n\nfunction getRelativeImportSpecifiers(content: string): string[] {\n const specifiers: string[] = [];\n const importPattern = /\\bimport\\b(?:[^'\"]*?\\bfrom\\s*)?[\"'](\\.{1,2}\\/[^\"']+)[\"']/g;\n let match: RegExpExecArray | null;\n while ((match = importPattern.exec(content)) !== null) {\n specifiers.push(match[1]);\n }\n return specifiers;\n}\n\nfunction snapshotsChangedOnDisk(snapshots: ConfigFileSnapshot[]): boolean {\n return snapshots.some(({ path: filePath, content }) => {\n const current = existsSync(filePath) ? readFileSync(filePath, \"utf-8\") : null;\n return current !== content;\n });\n}\n\nfunction flattenConfigUpdate(update: Config): ConfigChange[] {\n const changes: ConfigChange[] = [];\n const walk = (prefix: string, obj: Config): void => {\n for (const [key, value] of Object.entries(obj)) {\n const fullPath = prefix === \"\" ? key : `${prefix}.${key}`;\n if (value === undefined) continue;\n if (value !== null && typeof value === \"object\" && !Array.isArray(value) && Object.keys(value).length > 0) {\n walk(fullPath, value);\n } else {\n changes.push({ path: fullPath, value });\n }\n }\n };\n walk(\"\", update);\n return changes;\n}\n\nfunction buildConfigUpdatePrompt(configFileName: string, configUpdate: Config, baselineConfig: Config | null): string {\n const changes = flattenConfigUpdate(configUpdate);\n const changeLines = changes.map(({ path: configPath, value }) => {\n return `- ${JSON.stringify(configPath)}: set to ${JSON.stringify(value)}`;\n }).join(\"\\n\");\n const expectedConfig = baselineConfig == null ? null : canonicalizeConfig(override(baselineConfig, configUpdate));\n const expectedConfigSection = expectedConfig == null ? \"\" : `\nAfter the edit, evaluating the exported \\`config\\` must produce this exact JSON value:\n\n${JSON.stringify(expectedConfig, null, 2)}\n`;\n\n return `You are editing a Hexclave / Stack Auth configuration file in place. Apply a set of configuration changes WITHOUT changing how the file is written.\n\nConfig file: ${JSON.stringify(configFileName)} (in the current working directory).\n\nThe file exports a \\`config\\` object (it may be wrapped in a helper such as \\`defineStackConfig(...)\\`). Some config values may be sourced from other files via imports, for example:\n\n import welcomeEmail from \"./welcome-email.tsx\" with { type: \"text\" };\n export const config = { emails: { templates: { welcome: welcomeEmail } } };\n\nApply EXACTLY these changes. Paths use dot notation, so \\`a.b.c\\` refers to \\`config.a.b.c\\`:\n\n${changeLines}\n${expectedConfigSection}\n\nRules:\n- Change ONLY the config paths listed above. Leave every other part of the file byte-for-byte unchanged: imports, comments, formatting, helper wrappers, and any config fields not listed.\n- If a listed path's value is currently provided by an imported external file (like the \\`import ... with { type: \"text\" }\\` example above), DO NOT inline the new value into the config file. Instead, overwrite that external file with the new value and keep the import statement intact.\n- If a listed path's value is a plain inline literal, edit it inline.\n- Keep the file valid: it must still export a \\`config\\` that, once evaluated, reflects the new values exactly.\n- Do not run any shell commands and do not create files other than what is required to apply these changes.`;\n}\n\nfunction canonicalizeConfig(config: Config): NormalizedConfig {\n const droppedKeys: string[] = [];\n const normalized = normalize(config, {\n onDotIntoNonObject: \"ignore\",\n onDotIntoNull: \"empty-object\",\n droppedKeys,\n });\n if (droppedKeys.length > 0) {\n throw new Error(`Config update has conflicting keys that would be dropped during normalization: ${droppedKeys.map((key) => JSON.stringify(key)).join(\", \")}`);\n }\n return normalized;\n}\n\nfunction configsEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (a === null || b === null) return a === b;\n if (Array.isArray(a) || Array.isArray(b)) {\n if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;\n return a.every((value, index) => configsEqual(value, b[index]));\n }\n if (typeof a === \"object\" && typeof b === \"object\") {\n const aEntries = Object.entries(a);\n const bMap = new Map(Object.entries(b));\n if (aEntries.length !== bMap.size) return false;\n return aEntries.every(([key, value]) => bMap.has(key) && configsEqual(value, bMap.get(key)));\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;AAWA,MAAM,OAAO,WAAW,OAAO,KAAK,KAAK,EAAE,aAAa,OAAO,CAAC;AAEhE,MAAM,aAAa;AACnB,MAAM,2BAA2B;AASjC,SAAS,eAAe,OAAuC;AAC7D,QAAO,UAAU,QAAQ,OAAO,UAAU;;AAG5C,SAAgB,aAAa,OAAuB;AAClD,QAAO,WAAW,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM;;AAGzD,SAAgB,sBAAsB,WAA2B;CAC/D,MAAM,WAAW,KAAK,QAAQ,UAAU;AAExC,KAD4B,sBAAsB,KAAK,SAAS,CAE9D,QAAO;CAGT,MAAM,oBAAoB,KAAK,KAAK,UAAU,qBAAqB;CACnE,MAAM,kBAAkB,KAAK,KAAK,UAAU,kBAAkB;AAC9D,KAAI,WAAW,kBAAkB,CAC/B,QAAO;AAET,KAAI,WAAW,gBAAgB,CAC7B,QAAO;AAET,QAAO;;AAGT,SAAgB,uBAAuB,gBAA8B;AACnE,KAAI,WAAW,eAAe,CAAE;AAChC,WAAU,KAAK,QAAQ,eAAe,EAAE,EAAE,WAAW,MAAM,CAAC;AAC5D,0BAAyB,gBAAgB,EAAE,CAAC;;AAG9C,eAAsB,iBAAiB,gBAAyC;AAC9E,SAAQ,MAAM,eAAe,eAAe,EAAE;;AAG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,QAAO;AAC1C,SAAO,SAAS,OAAO,CAAC,KAAK,WAAW,KAAK,IAAI,IAAI,IAAI,aAAa,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC;;AAE9F,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import { showOnboardingHexclaveConfigValue } from \"@hexclave/shared/dist/config-authoring\";\nimport { detectImportPackageFromDir, parseHexclaveConfigFileContent, renderConfigFileContent } from \"@hexclave/shared/dist/config-rendering\";\nimport type { Config, ConfigValue, NormalizedConfig } from \"@hexclave/shared/dist/config/format\";\nimport { isValidConfig, normalize, override } from \"@hexclave/shared/dist/config/format\";\nimport { captureError } from \"@hexclave/shared/dist/utils/errors\";\nimport { createHash } from \"crypto\";\nimport { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from \"fs\";\nimport { createJiti } from \"jiti\";\nimport path from \"path\";\nimport { ClaudeAgentFailureError, ClaudeAgentTimeoutError, getToolWriteTargetPath, isPathInsideDir, runHeadlessClaudeAgent } from \"./config-agent\";\n\nconst jiti = createJiti(import.meta.url, { moduleCache: false });\n\nconst LOG_PREFIX = \"[Stack config updater]\";\nconst DEFAULT_AGENT_TIMEOUT_MS = 120_000;\nconst CONFIG_UPDATE_LOG_PATH_LIMIT = 40;\n\ntype ConfigModule = {\n config?: unknown,\n};\n\ntype ConfigFileSnapshot = { path: string, content: string | null };\ntype ConfigChange = { path: string, value: ConfigValue };\n\nfunction formatConfigUpdaterErrorForLog(error: unknown): Record<string, unknown> {\n if (error instanceof Error) {\n return {\n errorName: error.name,\n errorMessage: error.message,\n errorStack: error.stack,\n };\n }\n return {\n errorMessage: String(error),\n };\n}\n\nfunction configUpdatePathDetailsForLog(changes: ConfigChange[]): Record<string, unknown> {\n const paths = changes.map(({ path: configPath }) => configPath).sort();\n return {\n configUpdatePathCount: paths.length,\n configUpdatePaths: paths.slice(0, CONFIG_UPDATE_LOG_PATH_LIMIT),\n configUpdatePathsTruncated: paths.length > CONFIG_UPDATE_LOG_PATH_LIMIT,\n };\n}\n\nfunction isConfigModule(value: unknown): value is ConfigModule {\n return value !== null && typeof value === \"object\";\n}\n\nexport function sha256String(value: string): string {\n return createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nexport function resolveConfigFilePath(inputPath: string): string {\n const resolved = path.resolve(inputPath);\n const looksLikeConfigFile = /\\.(ts|js|mjs|cjs)$/i.test(resolved);\n if (looksLikeConfigFile) {\n return resolved;\n }\n // Prefer hexclave.config.ts, fall back to stack.config.ts, default to the new name.\n const hexclaveCandidate = path.join(resolved, \"hexclave.config.ts\");\n const legacyCandidate = path.join(resolved, \"stack.config.ts\");\n if (existsSync(hexclaveCandidate)) {\n return hexclaveCandidate;\n }\n if (existsSync(legacyCandidate)) {\n return legacyCandidate;\n }\n return hexclaveCandidate;\n}\n\nexport function ensureConfigFileExists(configFilePath: string): void {\n if (existsSync(configFilePath)) return;\n mkdirSync(path.dirname(configFilePath), { recursive: true });\n renderConfigObjectToFile(configFilePath, {});\n}\n\nexport async function readConfigObject(configFilePath: string): Promise<Config> {\n return (await readConfigFile(configFilePath)).config;\n}\n\nexport async function readConfigFile(configFilePath: string): Promise<{ config: Config, showOnboarding: boolean }> {\n ensureConfigFileExists(configFilePath);\n const content = readFileSync(configFilePath, \"utf-8\");\n if (content.trim() === \"\") {\n return {\n config: {},\n showOnboarding: false,\n };\n }\n\n let configModule: unknown;\n try {\n configModule = await jiti.import<unknown>(configFilePath);\n } catch (error) {\n // Capture the raw jiti/framework error for diagnostics, but don't attach it as `cause` on the thrown error:\n // dashboard error formatting renders causes recursively, which would leak framework internals into the\n // user-facing message we're deliberately replacing.\n captureError(\"shared-backend/readConfigFile\", error);\n throw new Error(\n `Failed to load config file ${configFilePath}.`,\n );\n }\n if (!isConfigModule(configModule)) {\n throw new Error(`Invalid config in ${configFilePath}. The file must export a plain \\`config\\` object or \"show-onboarding\".`);\n }\n\n const config = configModule.config;\n if (config === showOnboardingHexclaveConfigValue) {\n return {\n config: {},\n showOnboarding: true,\n };\n }\n if (!isValidConfig(config)) {\n throw new Error(`Invalid config in ${configFilePath}.`);\n }\n return {\n config,\n showOnboarding: false,\n };\n}\n\nfunction renderConfigObjectToString(configFilePath: string, config: Config): string {\n const importPackage = detectImportPackageFromDir(path.dirname(configFilePath));\n return renderConfigFileContent(config, importPackage);\n}\n\nfunction writeFileAtomic(configFilePath: string, content: string): void {\n const dir = path.dirname(configFilePath);\n mkdirSync(dir, { recursive: true });\n const tempPath = path.join(dir, `.stack.config.${Math.random().toString(36).slice(2)}.tmp`);\n writeFileSync(tempPath, content, \"utf-8\");\n try {\n renameSync(tempPath, configFilePath);\n } catch (error) {\n try {\n rmSync(tempPath);\n } catch { /* best-effort cleanup */ }\n throw error;\n }\n}\n\nfunction renderConfigObjectToFile(configFilePath: string, config: Config): void {\n writeFileAtomic(configFilePath, renderConfigObjectToString(configFilePath, config));\n}\n\nexport async function updateConfigObject(configFilePath: string, configUpdate: Config): Promise<void> {\n const startedAtMs = performance.now();\n ensureConfigFileExists(configFilePath);\n\n const changes = flattenConfigUpdate(configUpdate);\n if (changes.length === 0) {\n console.log(`${LOG_PREFIX} Skipping config update because it contains no changes`, {\n configFilePath,\n });\n return;\n }\n const updateLogDetails = {\n configFilePath,\n ...configUpdatePathDetailsForLog(changes),\n };\n console.log(`${LOG_PREFIX} Starting config file update`, updateLogDetails);\n\n const content = readFileSync(configFilePath, \"utf-8\");\n\n // Fast path: if the config is a plain static literal (no imports, no helpers),\n // apply the update deterministically without invoking the AI agent.\n const staticConfig = tryParseStaticConfigFileContent(content, configFilePath);\n if (staticConfig != null && isValidConfig(staticConfig)) {\n console.log(`${LOG_PREFIX} Applying config update with static config rewrite`, updateLogDetails);\n const merged = override(staticConfig, configUpdate);\n if (!isValidConfig(merged)) {\n throw new Error(`${LOG_PREFIX} Merged config is invalid after applying update to ${configFilePath}`);\n }\n renderConfigObjectToFile(configFilePath, merged);\n console.log(`${LOG_PREFIX} Finished config update with static config rewrite`, {\n ...updateLogDetails,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n });\n return;\n }\n\n // Agent path: config has custom structure (imports, helpers, external files)\n // that must be preserved — delegate to the AI agent.\n console.log(`${LOG_PREFIX} Applying config update with agent-assisted rewrite`, {\n ...updateLogDetails,\n configDirectory: path.dirname(configFilePath),\n });\n const baselineConfig = await tryReadConfigForValidation(configFilePath);\n const { snapshots, seen } = snapshotConfigFiles(configFilePath, content);\n try {\n await runConfigUpdateAgent({\n prompt: buildConfigUpdatePrompt(path.basename(configFilePath), configUpdate, baselineConfig),\n cwd: path.dirname(configFilePath),\n onFileWillChange: (filePath) => captureSnapshotIfAbsent(snapshots, filePath, seen),\n });\n await validateAgentUpdate(configFilePath, baselineConfig, configUpdate, snapshots);\n } catch (error) {\n console.warn(`${LOG_PREFIX} Config update failed; restoring files from snapshots`, {\n ...updateLogDetails,\n snapshotCount: snapshots.length,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n ...formatConfigUpdaterErrorForLog(error),\n });\n try {\n restoreConfigFiles(snapshots);\n console.warn(`${LOG_PREFIX} Restored files after failed config update`, {\n ...updateLogDetails,\n snapshotCount: snapshots.length,\n });\n } catch (restoreError) {\n console.error(`${LOG_PREFIX} Failed to fully roll back config files after a failed update of ${configFilePath}; some files may be left in a partially-restored state`, {\n configFilePath,\n ...formatConfigUpdaterErrorForLog(restoreError),\n });\n }\n throw error;\n }\n console.log(`${LOG_PREFIX} Finished config update with agent-assisted rewrite`, {\n ...updateLogDetails,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n snapshotCount: snapshots.length,\n });\n}\n\nexport async function replaceConfigObject(configFilePath: string, config: Config): Promise<void> {\n renderConfigObjectToFile(configFilePath, config);\n}\n\nasync function runConfigUpdateAgent(options: {\n prompt: string,\n cwd: string,\n onFileWillChange?: (filePath: string) => void,\n}): Promise<void> {\n const timeoutMs = parseAgentTimeoutMs();\n const deniedOutOfBoundsWrites = new Set<string>();\n const startedAtMs = performance.now();\n console.log(`${LOG_PREFIX} Starting config update agent`, {\n cwd: options.cwd,\n timeoutMs,\n });\n try {\n await runHeadlessClaudeAgent({\n prompt: options.prompt,\n cwd: options.cwd,\n allowedTools: [\"Read\", \"Write\", \"Edit\", \"Glob\", \"Grep\"],\n strictIsolation: true,\n timeoutMs,\n stderr: (data) => { console.warn(`${LOG_PREFIX} [agent] ${data}`); },\n onPreToolUse: (input) => {\n const target = getToolWriteTargetPath(input.tool_name, input.tool_input, options.cwd);\n if (target == null) return { continue: true };\n if (!isPathInsideDir(options.cwd, target)) {\n deniedOutOfBoundsWrites.add(target);\n return {\n hookSpecificOutput: {\n hookEventName: \"PreToolUse\",\n permissionDecision: \"deny\",\n permissionDecisionReason: `Refusing to modify ${target}: config updates may only change files inside the config directory.`,\n },\n };\n }\n options.onFileWillChange?.(target);\n return { continue: true };\n },\n });\n } catch (error) {\n if (error instanceof ClaudeAgentTimeoutError) {\n console.warn(`${LOG_PREFIX} Config update agent timed out`, {\n cwd: options.cwd,\n timeoutMs,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n ...formatConfigUpdaterErrorForLog(error),\n });\n throw new Error(`Config update agent timed out after ${timeoutMs}ms. It was unable to apply the config changes to the file.`);\n }\n if (error instanceof ClaudeAgentFailureError) {\n console.warn(`${LOG_PREFIX} Config update agent failed`, {\n cwd: options.cwd,\n timeoutMs,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n ...formatConfigUpdaterErrorForLog(error),\n });\n throw new Error(`${error.message} It was unable to apply the config changes to the file.`);\n }\n console.warn(`${LOG_PREFIX} Config update agent failed unexpectedly`, {\n cwd: options.cwd,\n timeoutMs,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n ...formatConfigUpdaterErrorForLog(error),\n });\n throw error;\n }\n console.log(`${LOG_PREFIX} Finished config update agent`, {\n cwd: options.cwd,\n timeoutMs,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n deniedOutOfBoundsWriteCount: deniedOutOfBoundsWrites.size,\n });\n if (deniedOutOfBoundsWrites.size > 0) {\n console.warn(`${LOG_PREFIX} Config update agent attempted out-of-bounds writes`, {\n cwd: options.cwd,\n deniedOutOfBoundsWriteCount: deniedOutOfBoundsWrites.size,\n deniedOutOfBoundsWrites: [...deniedOutOfBoundsWrites],\n });\n throw new Error(`Config update agent tried to modify ${deniedOutOfBoundsWrites.size} file(s) outside the config directory, which is not allowed: ${[...deniedOutOfBoundsWrites].join(\", \")}. The config was not updated.`);\n }\n}\n\nfunction parseAgentTimeoutMs(): number {\n const raw = process.env.STACK_CONFIG_UPDATE_AGENT_TIMEOUT_MS;\n if (raw == null || raw.trim() === \"\") return DEFAULT_AGENT_TIMEOUT_MS;\n const parsed = Number(raw);\n if (!Number.isFinite(parsed) || parsed <= 0) {\n throw new Error(`Invalid STACK_CONFIG_UPDATE_AGENT_TIMEOUT_MS: ${JSON.stringify(raw)}. Expected a positive number of milliseconds.`);\n }\n return parsed;\n}\n\nfunction captureSnapshotIfAbsent(snapshots: ConfigFileSnapshot[], filePath: string, seen: Set<string>): void {\n const resolved = path.resolve(filePath);\n if (seen.has(resolved)) return;\n seen.add(resolved);\n snapshots.push({ path: resolved, content: existsSync(resolved) ? readFileSync(resolved, \"utf-8\") : null });\n}\n\nfunction snapshotConfigFiles(configFilePath: string, configContent: string): { snapshots: ConfigFileSnapshot[]; seen: Set<string> } {\n const dir = path.dirname(configFilePath);\n const resolvedConfig = path.resolve(configFilePath);\n const snapshots: ConfigFileSnapshot[] = [{ path: resolvedConfig, content: configContent }];\n const seen = new Set<string>([resolvedConfig]);\n for (const specifier of getRelativeImportSpecifiers(configContent)) {\n const resolved = path.resolve(dir, specifier);\n if (!isPathInsideDir(dir, resolved)) continue;\n captureSnapshotIfAbsent(snapshots, resolved, seen);\n }\n return { snapshots, seen };\n}\n\nfunction restoreConfigFiles(snapshots: ConfigFileSnapshot[]): void {\n const failures: string[] = [];\n for (const { path: filePath, content } of snapshots) {\n try {\n if (content === null) {\n if (existsSync(filePath)) rmSync(filePath);\n } else {\n writeFileSync(filePath, content, \"utf-8\");\n }\n } catch (error) {\n failures.push(`${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n if (failures.length > 0) {\n throw new Error(`Failed to restore ${failures.length} file(s) during rollback: ${failures.join(\"; \")}`);\n }\n}\n\nasync function tryReadConfigForValidation(configFilePath: string): Promise<Config | null> {\n try {\n return (await readConfigFile(configFilePath)).config;\n } catch (error) {\n console.warn(`${LOG_PREFIX} Could not evaluate config for validation baseline; will fall back to a structural check`, {\n configFilePath,\n error: error instanceof Error ? error.message : String(error),\n });\n return null;\n }\n}\n\nasync function validateAgentUpdate(configFilePath: string, baselineConfig: Config | null, configUpdate: Config, snapshots: ConfigFileSnapshot[]): Promise<void> {\n if (baselineConfig != null) {\n const target = canonicalizeConfig(override(baselineConfig, configUpdate));\n const result = canonicalizeConfig((await readConfigFile(configFilePath)).config);\n if (!configsEqual(result, target)) {\n throw new Error(`Config update validation failed for ${configFilePath}: the updated file does not evaluate to the expected configuration.`);\n }\n return;\n }\n\n // Structural-only fallback: when jiti can't evaluate the config (e.g. missing\n // runtime dependencies in import-with attributes), we can only verify that\n // (a) something changed on disk and (b) the file still exports `config`.\n // This cannot catch silently mis-applied values — an accepted tradeoff vs.\n // blocking updates entirely for configs we can't evaluate.\n // When nothing changed on disk the update is either already applied or the\n // agent couldn't figure out what to do. Treat it as a no-op rather than a\n // hard failure: the structural check below still verifies the file is valid.\n if (flattenConfigUpdate(configUpdate).length > 0 && !snapshotsChangedOnDisk(snapshots)) {\n console.warn(`${LOG_PREFIX} Agent did not modify any file for ${configFilePath}; assuming values are already up to date.`);\n }\n\n const content = readFileSync(configFilePath, \"utf-8\");\n if (!configFileExportsConfig(content, configFilePath)) {\n throw new Error(`Config update validation failed for ${configFilePath}: the updated file no longer exports a valid \\`config\\`.`);\n }\n}\n\nfunction tryParseStaticConfigFileContent(content: string, configFilePath: string): Config | null {\n try {\n const parsed = parseHexclaveConfigFileContent(content, configFilePath);\n return isValidConfig(parsed) ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction configFileExportsConfig(content: string, configFilePath: string): boolean {\n try {\n parseHexclaveConfigFileContent(content, configFilePath);\n return true;\n } catch {\n // Dynamic configs can be valid even when the static parser cannot evaluate\n // them. For the structural fallback we only need to know that a runtime\n // config binding still exists after the agent edited the file.\n return /\\bexport\\s+const\\s+config\\b/.test(content);\n }\n}\n\nfunction getRelativeImportSpecifiers(content: string): string[] {\n const specifiers: string[] = [];\n const importPattern = /\\bimport\\b(?:[^'\"]*?\\bfrom\\s*)?[\"'](\\.{1,2}\\/[^\"']+)[\"']/g;\n let match: RegExpExecArray | null;\n while ((match = importPattern.exec(content)) !== null) {\n specifiers.push(match[1]);\n }\n return specifiers;\n}\n\nfunction snapshotsChangedOnDisk(snapshots: ConfigFileSnapshot[]): boolean {\n return snapshots.some(({ path: filePath, content }) => {\n const current = existsSync(filePath) ? readFileSync(filePath, \"utf-8\") : null;\n return current !== content;\n });\n}\n\nfunction flattenConfigUpdate(update: Config): ConfigChange[] {\n const changes: ConfigChange[] = [];\n const walk = (prefix: string, obj: Config): void => {\n for (const [key, value] of Object.entries(obj)) {\n const fullPath = prefix === \"\" ? key : `${prefix}.${key}`;\n if (value === undefined) continue;\n if (value !== null && typeof value === \"object\" && !Array.isArray(value) && Object.keys(value).length > 0) {\n walk(fullPath, value);\n } else {\n changes.push({ path: fullPath, value });\n }\n }\n };\n walk(\"\", update);\n return changes;\n}\n\nfunction buildConfigUpdatePrompt(configFileName: string, configUpdate: Config, baselineConfig: Config | null): string {\n const changes = flattenConfigUpdate(configUpdate);\n const changeLines = changes.map(({ path: configPath, value }) => {\n return `- ${JSON.stringify(configPath)}: set to ${JSON.stringify(value)}`;\n }).join(\"\\n\");\n const expectedConfig = baselineConfig == null ? null : canonicalizeConfig(override(baselineConfig, configUpdate));\n const expectedConfigSection = expectedConfig == null ? \"\" : `\nAfter the edit, evaluating the exported \\`config\\` must produce this exact JSON value:\n\n${JSON.stringify(expectedConfig, null, 2)}\n`;\n\n return `You are editing a Hexclave / Stack Auth configuration file in place. Apply a set of configuration changes WITHOUT changing how the file is written.\n\nConfig file: ${JSON.stringify(configFileName)} (in the current working directory).\n\nThe file exports a \\`config\\` object (it may be wrapped in a helper such as \\`defineStackConfig(...)\\`). Some config values may be sourced from other files via imports, for example:\n\n import welcomeEmail from \"./welcome-email.tsx\" with { type: \"text\" };\n export const config = { emails: { templates: { welcome: welcomeEmail } } };\n\nApply EXACTLY these changes. Paths use dot notation, so \\`a.b.c\\` refers to \\`config.a.b.c\\`:\n\n${changeLines}\n${expectedConfigSection}\n\nRules:\n- Change ONLY the config paths listed above. Leave every other part of the file byte-for-byte unchanged: imports, comments, formatting, helper wrappers, and any config fields not listed.\n- If a listed path's value is currently provided by an imported external file (like the \\`import ... with { type: \"text\" }\\` example above), DO NOT inline the new value into the config file. Instead, overwrite that external file with the new value and keep the import statement intact.\n- If a listed path's value is a plain inline literal, edit it inline.\n- Keep the file valid: it must still export a \\`config\\` that, once evaluated, reflects the new values exactly.\n- Do not run any shell commands and do not create files other than what is required to apply these changes.`;\n}\n\nfunction canonicalizeConfig(config: Config): NormalizedConfig {\n const droppedKeys: string[] = [];\n const normalized = normalize(config, {\n onDotIntoNonObject: \"ignore\",\n onDotIntoNull: \"empty-object\",\n droppedKeys,\n });\n if (droppedKeys.length > 0) {\n throw new Error(`Config update has conflicting keys that would be dropped during normalization: ${droppedKeys.map((key) => JSON.stringify(key)).join(\", \")}`);\n }\n return normalized;\n}\n\nfunction configsEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (a === null || b === null) return a === b;\n if (Array.isArray(a) || Array.isArray(b)) {\n if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;\n return a.every((value, index) => configsEqual(value, b[index]));\n }\n if (typeof a === \"object\" && typeof b === \"object\") {\n const aEntries = Object.entries(a);\n const bMap = new Map(Object.entries(b));\n if (aEntries.length !== bMap.size) return false;\n return a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QAAO;AACpB,KAAI,MAAM,QAAQ,MAAM,KAAM,QAAO,MAAM;AAC3C,KAAI,MAAM,QAAQ,EAAE,IAAI,MAAM,QAAQ,EAAE,EAAE;AACxC,MAAI,CAAC,MAAM,QAAQ,EAAE,IAAI,CAAC,MAAM,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAC5E,SAAO,EAAE,OAAO,OAAO,UAAU,aAAa,OAAO,EAAE,OAAO,CAAC;;AAEjE,KAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;EAClD,MAAM,WAAW,OAAO,QAAQ,EAAE;EAClC,MAAM,OAAO,IAAI,IAAI,OAAO,QAAQ,EAAE,CAAC;AACvC,MAAI,SAAS,WAAW,KAAK,KAAM,QAAO;AAC1C,SAAO,SAAS,OAAO,CAAC,KAAK,WAAW,KAAK,IAAI,IAAI,IAAI,aAAa,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC;;AAE9F,QAAO"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;iBAkDgB,YAAA,CAAa,KAAA;AAAA,iBAIb,qBAAA,CAAsB,SAAA;AAAA,iBAkBtB,sBAAA,CAAuB,cAAA;AAAA,iBAMjB,gBAAA,CAAiB,cAAA,WAAyB,OAAA,CAAQ,MAAA;AAAA,iBAIlD,cAAA,CAAe,cAAA,WAAyB,OAAA;EAAU,MAAA,EAAQ,MAAA;EAAQ,cAAA;AAAA;AAAA,iBAkElE,kBAAA,CAAmB,cAAA,UAAwB,YAAA,EAAc,MAAA,GAAS,OAAA;AAAA,iBA+ElE,mBAAA,CAAoB,cAAA,UAAwB,MAAA,EAAQ,MAAA,GAAS,OAAA"}
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,23 @@ let __config_agent_js = require("./config-agent.js");
|
|
|
15
15
|
const jiti$1 = (0, jiti.createJiti)(require("url").pathToFileURL(__filename).href, { moduleCache: false });
|
|
16
16
|
const LOG_PREFIX = "[Stack config updater]";
|
|
17
17
|
const DEFAULT_AGENT_TIMEOUT_MS = 12e4;
|
|
18
|
+
const CONFIG_UPDATE_LOG_PATH_LIMIT = 40;
|
|
19
|
+
function formatConfigUpdaterErrorForLog(error) {
|
|
20
|
+
if (error instanceof Error) return {
|
|
21
|
+
errorName: error.name,
|
|
22
|
+
errorMessage: error.message,
|
|
23
|
+
errorStack: error.stack
|
|
24
|
+
};
|
|
25
|
+
return { errorMessage: String(error) };
|
|
26
|
+
}
|
|
27
|
+
function configUpdatePathDetailsForLog(changes) {
|
|
28
|
+
const paths = changes.map(({ path: configPath }) => configPath).sort();
|
|
29
|
+
return {
|
|
30
|
+
configUpdatePathCount: paths.length,
|
|
31
|
+
configUpdatePaths: paths.slice(0, CONFIG_UPDATE_LOG_PATH_LIMIT),
|
|
32
|
+
configUpdatePathsTruncated: paths.length > CONFIG_UPDATE_LOG_PATH_LIMIT
|
|
33
|
+
};
|
|
34
|
+
}
|
|
18
35
|
function isConfigModule(value) {
|
|
19
36
|
return value !== null && typeof value === "object";
|
|
20
37
|
}
|
|
@@ -84,16 +101,35 @@ function renderConfigObjectToFile(configFilePath, config) {
|
|
|
84
101
|
writeFileAtomic(configFilePath, renderConfigObjectToString(configFilePath, config));
|
|
85
102
|
}
|
|
86
103
|
async function updateConfigObject(configFilePath, configUpdate) {
|
|
104
|
+
const startedAtMs = performance.now();
|
|
87
105
|
ensureConfigFileExists(configFilePath);
|
|
88
|
-
|
|
106
|
+
const changes = flattenConfigUpdate(configUpdate);
|
|
107
|
+
if (changes.length === 0) {
|
|
108
|
+
console.log(`${LOG_PREFIX} Skipping config update because it contains no changes`, { configFilePath });
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const updateLogDetails = {
|
|
112
|
+
configFilePath,
|
|
113
|
+
...configUpdatePathDetailsForLog(changes)
|
|
114
|
+
};
|
|
115
|
+
console.log(`${LOG_PREFIX} Starting config file update`, updateLogDetails);
|
|
89
116
|
const content = (0, fs.readFileSync)(configFilePath, "utf-8");
|
|
90
117
|
const staticConfig = tryParseStaticConfigFileContent(content, configFilePath);
|
|
91
118
|
if (staticConfig != null && (0, _hexclave_shared_dist_config_format.isValidConfig)(staticConfig)) {
|
|
119
|
+
console.log(`${LOG_PREFIX} Applying config update with static config rewrite`, updateLogDetails);
|
|
92
120
|
const merged = (0, _hexclave_shared_dist_config_format.override)(staticConfig, configUpdate);
|
|
93
121
|
if (!(0, _hexclave_shared_dist_config_format.isValidConfig)(merged)) throw new Error(`${LOG_PREFIX} Merged config is invalid after applying update to ${configFilePath}`);
|
|
94
122
|
renderConfigObjectToFile(configFilePath, merged);
|
|
123
|
+
console.log(`${LOG_PREFIX} Finished config update with static config rewrite`, {
|
|
124
|
+
...updateLogDetails,
|
|
125
|
+
elapsedMs: Math.round(performance.now() - startedAtMs)
|
|
126
|
+
});
|
|
95
127
|
return;
|
|
96
128
|
}
|
|
129
|
+
console.log(`${LOG_PREFIX} Applying config update with agent-assisted rewrite`, {
|
|
130
|
+
...updateLogDetails,
|
|
131
|
+
configDirectory: path.default.dirname(configFilePath)
|
|
132
|
+
});
|
|
97
133
|
const baselineConfig = await tryReadConfigForValidation(configFilePath);
|
|
98
134
|
const { snapshots, seen } = snapshotConfigFiles(configFilePath, content);
|
|
99
135
|
try {
|
|
@@ -104,16 +140,31 @@ async function updateConfigObject(configFilePath, configUpdate) {
|
|
|
104
140
|
});
|
|
105
141
|
await validateAgentUpdate(configFilePath, baselineConfig, configUpdate, snapshots);
|
|
106
142
|
} catch (error) {
|
|
143
|
+
console.warn(`${LOG_PREFIX} Config update failed; restoring files from snapshots`, {
|
|
144
|
+
...updateLogDetails,
|
|
145
|
+
snapshotCount: snapshots.length,
|
|
146
|
+
elapsedMs: Math.round(performance.now() - startedAtMs),
|
|
147
|
+
...formatConfigUpdaterErrorForLog(error)
|
|
148
|
+
});
|
|
107
149
|
try {
|
|
108
150
|
restoreConfigFiles(snapshots);
|
|
151
|
+
console.warn(`${LOG_PREFIX} Restored files after failed config update`, {
|
|
152
|
+
...updateLogDetails,
|
|
153
|
+
snapshotCount: snapshots.length
|
|
154
|
+
});
|
|
109
155
|
} catch (restoreError) {
|
|
110
156
|
console.error(`${LOG_PREFIX} Failed to fully roll back config files after a failed update of ${configFilePath}; some files may be left in a partially-restored state`, {
|
|
111
157
|
configFilePath,
|
|
112
|
-
|
|
158
|
+
...formatConfigUpdaterErrorForLog(restoreError)
|
|
113
159
|
});
|
|
114
160
|
}
|
|
115
161
|
throw error;
|
|
116
162
|
}
|
|
163
|
+
console.log(`${LOG_PREFIX} Finished config update with agent-assisted rewrite`, {
|
|
164
|
+
...updateLogDetails,
|
|
165
|
+
elapsedMs: Math.round(performance.now() - startedAtMs),
|
|
166
|
+
snapshotCount: snapshots.length
|
|
167
|
+
});
|
|
117
168
|
}
|
|
118
169
|
async function replaceConfigObject(configFilePath, config) {
|
|
119
170
|
renderConfigObjectToFile(configFilePath, config);
|
|
@@ -121,6 +172,11 @@ async function replaceConfigObject(configFilePath, config) {
|
|
|
121
172
|
async function runConfigUpdateAgent(options) {
|
|
122
173
|
const timeoutMs = parseAgentTimeoutMs();
|
|
123
174
|
const deniedOutOfBoundsWrites = /* @__PURE__ */ new Set();
|
|
175
|
+
const startedAtMs = performance.now();
|
|
176
|
+
console.log(`${LOG_PREFIX} Starting config update agent`, {
|
|
177
|
+
cwd: options.cwd,
|
|
178
|
+
timeoutMs
|
|
179
|
+
});
|
|
124
180
|
try {
|
|
125
181
|
await (0, __config_agent_js.runHeadlessClaudeAgent)({
|
|
126
182
|
prompt: options.prompt,
|
|
@@ -153,11 +209,46 @@ async function runConfigUpdateAgent(options) {
|
|
|
153
209
|
}
|
|
154
210
|
});
|
|
155
211
|
} catch (error) {
|
|
156
|
-
if (error instanceof __config_agent_js.ClaudeAgentTimeoutError)
|
|
157
|
-
|
|
212
|
+
if (error instanceof __config_agent_js.ClaudeAgentTimeoutError) {
|
|
213
|
+
console.warn(`${LOG_PREFIX} Config update agent timed out`, {
|
|
214
|
+
cwd: options.cwd,
|
|
215
|
+
timeoutMs,
|
|
216
|
+
elapsedMs: Math.round(performance.now() - startedAtMs),
|
|
217
|
+
...formatConfigUpdaterErrorForLog(error)
|
|
218
|
+
});
|
|
219
|
+
throw new Error(`Config update agent timed out after ${timeoutMs}ms. It was unable to apply the config changes to the file.`);
|
|
220
|
+
}
|
|
221
|
+
if (error instanceof __config_agent_js.ClaudeAgentFailureError) {
|
|
222
|
+
console.warn(`${LOG_PREFIX} Config update agent failed`, {
|
|
223
|
+
cwd: options.cwd,
|
|
224
|
+
timeoutMs,
|
|
225
|
+
elapsedMs: Math.round(performance.now() - startedAtMs),
|
|
226
|
+
...formatConfigUpdaterErrorForLog(error)
|
|
227
|
+
});
|
|
228
|
+
throw new Error(`${error.message} It was unable to apply the config changes to the file.`);
|
|
229
|
+
}
|
|
230
|
+
console.warn(`${LOG_PREFIX} Config update agent failed unexpectedly`, {
|
|
231
|
+
cwd: options.cwd,
|
|
232
|
+
timeoutMs,
|
|
233
|
+
elapsedMs: Math.round(performance.now() - startedAtMs),
|
|
234
|
+
...formatConfigUpdaterErrorForLog(error)
|
|
235
|
+
});
|
|
158
236
|
throw error;
|
|
159
237
|
}
|
|
160
|
-
|
|
238
|
+
console.log(`${LOG_PREFIX} Finished config update agent`, {
|
|
239
|
+
cwd: options.cwd,
|
|
240
|
+
timeoutMs,
|
|
241
|
+
elapsedMs: Math.round(performance.now() - startedAtMs),
|
|
242
|
+
deniedOutOfBoundsWriteCount: deniedOutOfBoundsWrites.size
|
|
243
|
+
});
|
|
244
|
+
if (deniedOutOfBoundsWrites.size > 0) {
|
|
245
|
+
console.warn(`${LOG_PREFIX} Config update agent attempted out-of-bounds writes`, {
|
|
246
|
+
cwd: options.cwd,
|
|
247
|
+
deniedOutOfBoundsWriteCount: deniedOutOfBoundsWrites.size,
|
|
248
|
+
deniedOutOfBoundsWrites: [...deniedOutOfBoundsWrites]
|
|
249
|
+
});
|
|
250
|
+
throw new Error(`Config update agent tried to modify ${deniedOutOfBoundsWrites.size} file(s) outside the config directory, which is not allowed: ${[...deniedOutOfBoundsWrites].join(", ")}. The config was not updated.`);
|
|
251
|
+
}
|
|
161
252
|
}
|
|
162
253
|
function parseAgentTimeoutMs() {
|
|
163
254
|
const raw = process.env.STACK_CONFIG_UPDATE_AGENT_TIMEOUT_MS;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["jiti","showOnboardingHexclaveConfigValue","ClaudeAgentTimeoutError","ClaudeAgentFailureError"],"sources":["../src/index.ts"],"sourcesContent":["import { showOnboardingHexclaveConfigValue } from \"@hexclave/shared/dist/config-authoring\";\nimport { detectImportPackageFromDir, parseHexclaveConfigFileContent, renderConfigFileContent } from \"@hexclave/shared/dist/config-rendering\";\nimport type { Config, ConfigValue, NormalizedConfig } from \"@hexclave/shared/dist/config/format\";\nimport { isValidConfig, normalize, override } from \"@hexclave/shared/dist/config/format\";\nimport { captureError } from \"@hexclave/shared/dist/utils/errors\";\nimport { createHash } from \"crypto\";\nimport { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from \"fs\";\nimport { createJiti } from \"jiti\";\nimport path from \"path\";\nimport { ClaudeAgentFailureError, ClaudeAgentTimeoutError, getToolWriteTargetPath, isPathInsideDir, runHeadlessClaudeAgent } from \"./config-agent\";\n\nconst jiti = createJiti(import.meta.url, { moduleCache: false });\n\nconst LOG_PREFIX = \"[Stack config updater]\";\nconst DEFAULT_AGENT_TIMEOUT_MS = 120_000;\n\ntype ConfigModule = {\n config?: unknown,\n};\n\ntype ConfigFileSnapshot = { path: string, content: string | null };\ntype ConfigChange = { path: string, value: ConfigValue };\n\nfunction isConfigModule(value: unknown): value is ConfigModule {\n return value !== null && typeof value === \"object\";\n}\n\nexport function sha256String(value: string): string {\n return createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nexport function resolveConfigFilePath(inputPath: string): string {\n const resolved = path.resolve(inputPath);\n const looksLikeConfigFile = /\\.(ts|js|mjs|cjs)$/i.test(resolved);\n if (looksLikeConfigFile) {\n return resolved;\n }\n // Prefer hexclave.config.ts, fall back to stack.config.ts, default to the new name.\n const hexclaveCandidate = path.join(resolved, \"hexclave.config.ts\");\n const legacyCandidate = path.join(resolved, \"stack.config.ts\");\n if (existsSync(hexclaveCandidate)) {\n return hexclaveCandidate;\n }\n if (existsSync(legacyCandidate)) {\n return legacyCandidate;\n }\n return hexclaveCandidate;\n}\n\nexport function ensureConfigFileExists(configFilePath: string): void {\n if (existsSync(configFilePath)) return;\n mkdirSync(path.dirname(configFilePath), { recursive: true });\n renderConfigObjectToFile(configFilePath, {});\n}\n\nexport async function readConfigObject(configFilePath: string): Promise<Config> {\n return (await readConfigFile(configFilePath)).config;\n}\n\nexport async function readConfigFile(configFilePath: string): Promise<{ config: Config, showOnboarding: boolean }> {\n ensureConfigFileExists(configFilePath);\n const content = readFileSync(configFilePath, \"utf-8\");\n if (content.trim() === \"\") {\n return {\n config: {},\n showOnboarding: false,\n };\n }\n\n let configModule: unknown;\n try {\n configModule = await jiti.import<unknown>(configFilePath);\n } catch (error) {\n // Capture the raw jiti/framework error for diagnostics, but don't attach it as `cause` on the thrown error:\n // dashboard error formatting renders causes recursively, which would leak framework internals into the\n // user-facing message we're deliberately replacing.\n captureError(\"shared-backend/readConfigFile\", error);\n throw new Error(\n `Failed to load config file ${configFilePath}.`,\n );\n }\n if (!isConfigModule(configModule)) {\n throw new Error(`Invalid config in ${configFilePath}. The file must export a plain \\`config\\` object or \"show-onboarding\".`);\n }\n\n const config = configModule.config;\n if (config === showOnboardingHexclaveConfigValue) {\n return {\n config: {},\n showOnboarding: true,\n };\n }\n if (!isValidConfig(config)) {\n throw new Error(`Invalid config in ${configFilePath}.`);\n }\n return {\n config,\n showOnboarding: false,\n };\n}\n\nfunction renderConfigObjectToString(configFilePath: string, config: Config): string {\n const importPackage = detectImportPackageFromDir(path.dirname(configFilePath));\n return renderConfigFileContent(config, importPackage);\n}\n\nfunction writeFileAtomic(configFilePath: string, content: string): void {\n const dir = path.dirname(configFilePath);\n mkdirSync(dir, { recursive: true });\n const tempPath = path.join(dir, `.stack.config.${Math.random().toString(36).slice(2)}.tmp`);\n writeFileSync(tempPath, content, \"utf-8\");\n try {\n renameSync(tempPath, configFilePath);\n } catch (error) {\n try {\n rmSync(tempPath);\n } catch { /* best-effort cleanup */ }\n throw error;\n }\n}\n\nfunction renderConfigObjectToFile(configFilePath: string, config: Config): void {\n writeFileAtomic(configFilePath, renderConfigObjectToString(configFilePath, config));\n}\n\nexport async function updateConfigObject(configFilePath: string, configUpdate: Config): Promise<void> {\n ensureConfigFileExists(configFilePath);\n\n if (flattenConfigUpdate(configUpdate).length === 0) return;\n\n const content = readFileSync(configFilePath, \"utf-8\");\n\n // Fast path: if the config is a plain static literal (no imports, no helpers),\n // apply the update deterministically without invoking the AI agent.\n const staticConfig = tryParseStaticConfigFileContent(content, configFilePath);\n if (staticConfig != null && isValidConfig(staticConfig)) {\n const merged = override(staticConfig, configUpdate);\n if (!isValidConfig(merged)) {\n throw new Error(`${LOG_PREFIX} Merged config is invalid after applying update to ${configFilePath}`);\n }\n renderConfigObjectToFile(configFilePath, merged);\n return;\n }\n\n // Agent path: config has custom structure (imports, helpers, external files)\n // that must be preserved — delegate to the AI agent.\n const baselineConfig = await tryReadConfigForValidation(configFilePath);\n const { snapshots, seen } = snapshotConfigFiles(configFilePath, content);\n try {\n await runConfigUpdateAgent({\n prompt: buildConfigUpdatePrompt(path.basename(configFilePath), configUpdate, baselineConfig),\n cwd: path.dirname(configFilePath),\n onFileWillChange: (filePath) => captureSnapshotIfAbsent(snapshots, filePath, seen),\n });\n await validateAgentUpdate(configFilePath, baselineConfig, configUpdate, snapshots);\n } catch (error) {\n try {\n restoreConfigFiles(snapshots);\n } catch (restoreError) {\n console.error(`${LOG_PREFIX} Failed to fully roll back config files after a failed update of ${configFilePath}; some files may be left in a partially-restored state`, {\n configFilePath,\n restoreError: restoreError instanceof Error ? restoreError.message : String(restoreError),\n });\n }\n throw error;\n }\n}\n\nexport async function replaceConfigObject(configFilePath: string, config: Config): Promise<void> {\n renderConfigObjectToFile(configFilePath, config);\n}\n\nasync function runConfigUpdateAgent(options: {\n prompt: string,\n cwd: string,\n onFileWillChange?: (filePath: string) => void,\n}): Promise<void> {\n const timeoutMs = parseAgentTimeoutMs();\n const deniedOutOfBoundsWrites = new Set<string>();\n try {\n await runHeadlessClaudeAgent({\n prompt: options.prompt,\n cwd: options.cwd,\n allowedTools: [\"Read\", \"Write\", \"Edit\", \"Glob\", \"Grep\"],\n strictIsolation: true,\n timeoutMs,\n stderr: (data) => { console.warn(`${LOG_PREFIX} [agent] ${data}`); },\n onPreToolUse: (input) => {\n const target = getToolWriteTargetPath(input.tool_name, input.tool_input, options.cwd);\n if (target == null) return { continue: true };\n if (!isPathInsideDir(options.cwd, target)) {\n deniedOutOfBoundsWrites.add(target);\n return {\n hookSpecificOutput: {\n hookEventName: \"PreToolUse\",\n permissionDecision: \"deny\",\n permissionDecisionReason: `Refusing to modify ${target}: config updates may only change files inside the config directory.`,\n },\n };\n }\n options.onFileWillChange?.(target);\n return { continue: true };\n },\n });\n } catch (error) {\n if (error instanceof ClaudeAgentTimeoutError) {\n throw new Error(`Config update agent timed out after ${timeoutMs}ms. It was unable to apply the config changes to the file.`);\n }\n if (error instanceof ClaudeAgentFailureError) {\n throw new Error(`${error.message} It was unable to apply the config changes to the file.`);\n }\n throw error;\n }\n if (deniedOutOfBoundsWrites.size > 0) {\n throw new Error(`Config update agent tried to modify ${deniedOutOfBoundsWrites.size} file(s) outside the config directory, which is not allowed: ${[...deniedOutOfBoundsWrites].join(\", \")}. The config was not updated.`);\n }\n}\n\nfunction parseAgentTimeoutMs(): number {\n const raw = process.env.STACK_CONFIG_UPDATE_AGENT_TIMEOUT_MS;\n if (raw == null || raw.trim() === \"\") return DEFAULT_AGENT_TIMEOUT_MS;\n const parsed = Number(raw);\n if (!Number.isFinite(parsed) || parsed <= 0) {\n throw new Error(`Invalid STACK_CONFIG_UPDATE_AGENT_TIMEOUT_MS: ${JSON.stringify(raw)}. Expected a positive number of milliseconds.`);\n }\n return parsed;\n}\n\nfunction captureSnapshotIfAbsent(snapshots: ConfigFileSnapshot[], filePath: string, seen: Set<string>): void {\n const resolved = path.resolve(filePath);\n if (seen.has(resolved)) return;\n seen.add(resolved);\n snapshots.push({ path: resolved, content: existsSync(resolved) ? readFileSync(resolved, \"utf-8\") : null });\n}\n\nfunction snapshotConfigFiles(configFilePath: string, configContent: string): { snapshots: ConfigFileSnapshot[]; seen: Set<string> } {\n const dir = path.dirname(configFilePath);\n const resolvedConfig = path.resolve(configFilePath);\n const snapshots: ConfigFileSnapshot[] = [{ path: resolvedConfig, content: configContent }];\n const seen = new Set<string>([resolvedConfig]);\n for (const specifier of getRelativeImportSpecifiers(configContent)) {\n const resolved = path.resolve(dir, specifier);\n if (!isPathInsideDir(dir, resolved)) continue;\n captureSnapshotIfAbsent(snapshots, resolved, seen);\n }\n return { snapshots, seen };\n}\n\nfunction restoreConfigFiles(snapshots: ConfigFileSnapshot[]): void {\n const failures: string[] = [];\n for (const { path: filePath, content } of snapshots) {\n try {\n if (content === null) {\n if (existsSync(filePath)) rmSync(filePath);\n } else {\n writeFileSync(filePath, content, \"utf-8\");\n }\n } catch (error) {\n failures.push(`${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n if (failures.length > 0) {\n throw new Error(`Failed to restore ${failures.length} file(s) during rollback: ${failures.join(\"; \")}`);\n }\n}\n\nasync function tryReadConfigForValidation(configFilePath: string): Promise<Config | null> {\n try {\n return (await readConfigFile(configFilePath)).config;\n } catch (error) {\n console.warn(`${LOG_PREFIX} Could not evaluate config for validation baseline; will fall back to a structural check`, {\n configFilePath,\n error: error instanceof Error ? error.message : String(error),\n });\n return null;\n }\n}\n\nasync function validateAgentUpdate(configFilePath: string, baselineConfig: Config | null, configUpdate: Config, snapshots: ConfigFileSnapshot[]): Promise<void> {\n if (baselineConfig != null) {\n const target = canonicalizeConfig(override(baselineConfig, configUpdate));\n const result = canonicalizeConfig((await readConfigFile(configFilePath)).config);\n if (!configsEqual(result, target)) {\n throw new Error(`Config update validation failed for ${configFilePath}: the updated file does not evaluate to the expected configuration.`);\n }\n return;\n }\n\n // Structural-only fallback: when jiti can't evaluate the config (e.g. missing\n // runtime dependencies in import-with attributes), we can only verify that\n // (a) something changed on disk and (b) the file still exports `config`.\n // This cannot catch silently mis-applied values — an accepted tradeoff vs.\n // blocking updates entirely for configs we can't evaluate.\n // When nothing changed on disk the update is either already applied or the\n // agent couldn't figure out what to do. Treat it as a no-op rather than a\n // hard failure: the structural check below still verifies the file is valid.\n if (flattenConfigUpdate(configUpdate).length > 0 && !snapshotsChangedOnDisk(snapshots)) {\n console.warn(`${LOG_PREFIX} Agent did not modify any file for ${configFilePath}; assuming values are already up to date.`);\n }\n\n const content = readFileSync(configFilePath, \"utf-8\");\n if (!configFileExportsConfig(content, configFilePath)) {\n throw new Error(`Config update validation failed for ${configFilePath}: the updated file no longer exports a valid \\`config\\`.`);\n }\n}\n\nfunction tryParseStaticConfigFileContent(content: string, configFilePath: string): Config | null {\n try {\n const parsed = parseHexclaveConfigFileContent(content, configFilePath);\n return isValidConfig(parsed) ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction configFileExportsConfig(content: string, configFilePath: string): boolean {\n try {\n parseHexclaveConfigFileContent(content, configFilePath);\n return true;\n } catch {\n // Dynamic configs can be valid even when the static parser cannot evaluate\n // them. For the structural fallback we only need to know that a runtime\n // config binding still exists after the agent edited the file.\n return /\\bexport\\s+const\\s+config\\b/.test(content);\n }\n}\n\nfunction getRelativeImportSpecifiers(content: string): string[] {\n const specifiers: string[] = [];\n const importPattern = /\\bimport\\b(?:[^'\"]*?\\bfrom\\s*)?[\"'](\\.{1,2}\\/[^\"']+)[\"']/g;\n let match: RegExpExecArray | null;\n while ((match = importPattern.exec(content)) !== null) {\n specifiers.push(match[1]);\n }\n return specifiers;\n}\n\nfunction snapshotsChangedOnDisk(snapshots: ConfigFileSnapshot[]): boolean {\n return snapshots.some(({ path: filePath, content }) => {\n const current = existsSync(filePath) ? readFileSync(filePath, \"utf-8\") : null;\n return current !== content;\n });\n}\n\nfunction flattenConfigUpdate(update: Config): ConfigChange[] {\n const changes: ConfigChange[] = [];\n const walk = (prefix: string, obj: Config): void => {\n for (const [key, value] of Object.entries(obj)) {\n const fullPath = prefix === \"\" ? key : `${prefix}.${key}`;\n if (value === undefined) continue;\n if (value !== null && typeof value === \"object\" && !Array.isArray(value) && Object.keys(value).length > 0) {\n walk(fullPath, value);\n } else {\n changes.push({ path: fullPath, value });\n }\n }\n };\n walk(\"\", update);\n return changes;\n}\n\nfunction buildConfigUpdatePrompt(configFileName: string, configUpdate: Config, baselineConfig: Config | null): string {\n const changes = flattenConfigUpdate(configUpdate);\n const changeLines = changes.map(({ path: configPath, value }) => {\n return `- ${JSON.stringify(configPath)}: set to ${JSON.stringify(value)}`;\n }).join(\"\\n\");\n const expectedConfig = baselineConfig == null ? null : canonicalizeConfig(override(baselineConfig, configUpdate));\n const expectedConfigSection = expectedConfig == null ? \"\" : `\nAfter the edit, evaluating the exported \\`config\\` must produce this exact JSON value:\n\n${JSON.stringify(expectedConfig, null, 2)}\n`;\n\n return `You are editing a Hexclave / Stack Auth configuration file in place. Apply a set of configuration changes WITHOUT changing how the file is written.\n\nConfig file: ${JSON.stringify(configFileName)} (in the current working directory).\n\nThe file exports a \\`config\\` object (it may be wrapped in a helper such as \\`defineStackConfig(...)\\`). Some config values may be sourced from other files via imports, for example:\n\n import welcomeEmail from \"./welcome-email.tsx\" with { type: \"text\" };\n export const config = { emails: { templates: { welcome: welcomeEmail } } };\n\nApply EXACTLY these changes. Paths use dot notation, so \\`a.b.c\\` refers to \\`config.a.b.c\\`:\n\n${changeLines}\n${expectedConfigSection}\n\nRules:\n- Change ONLY the config paths listed above. Leave every other part of the file byte-for-byte unchanged: imports, comments, formatting, helper wrappers, and any config fields not listed.\n- If a listed path's value is currently provided by an imported external file (like the \\`import ... with { type: \"text\" }\\` example above), DO NOT inline the new value into the config file. Instead, overwrite that external file with the new value and keep the import statement intact.\n- If a listed path's value is a plain inline literal, edit it inline.\n- Keep the file valid: it must still export a \\`config\\` that, once evaluated, reflects the new values exactly.\n- Do not run any shell commands and do not create files other than what is required to apply these changes.`;\n}\n\nfunction canonicalizeConfig(config: Config): NormalizedConfig {\n const droppedKeys: string[] = [];\n const normalized = normalize(config, {\n onDotIntoNonObject: \"ignore\",\n onDotIntoNull: \"empty-object\",\n droppedKeys,\n });\n if (droppedKeys.length > 0) {\n throw new Error(`Config update has conflicting keys that would be dropped during normalization: ${droppedKeys.map((key) => JSON.stringify(key)).join(\", \")}`);\n }\n return normalized;\n}\n\nfunction configsEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (a === null || b === null) return a === b;\n if (Array.isArray(a) || Array.isArray(b)) {\n if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;\n return a.every((value, index) => configsEqual(value, b[index]));\n }\n if (typeof a === \"object\" && typeof b === \"object\") {\n const aEntries = Object.entries(a);\n const bMap = new Map(Object.entries(b));\n if (aEntries.length !== bMap.size) return false;\n return aEntries.every(([key, value]) => bMap.has(key) && configsEqual(value, bMap.get(key)));\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;AAWA,MAAMA,6EAAmC,EAAE,aAAa,OAAO,CAAC;AAEhE,MAAM,aAAa;AACnB,MAAM,2BAA2B;AASjC,SAAS,eAAe,OAAuC;AAC7D,QAAO,UAAU,QAAQ,OAAO,UAAU;;AAG5C,SAAgB,aAAa,OAAuB;AAClD,+BAAkB,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM;;AAGzD,SAAgB,sBAAsB,WAA2B;CAC/D,MAAM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AAI,MAAM,QAAQ,EAAE,EAAE;AACxC,MAAI,CAAC,MAAM,QAAQ,EAAE,IAAI,CAAC,MAAM,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAC5E,SAAO,EAAE,OAAO,OAAO,UAAU,aAAa,OAAO,EAAE,OAAO,CAAC;;AAEjE,KAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;EAClD,MAAM,WAAW,OAAO,QAAQ,EAAE;EAClC,MAAM,OAAO,IAAI,IAAI,OAAO,QAAQ,EAAE,CAAC;AACvC,MAAI,SAAS,WAAW,KAAK,KAAM,QAAO;AAC1C,SAAO,SAAS,OAAO,CAAC,KAAK,WAAW,KAAK,IAAI,IAAI,IAAI,aAAa,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC;;AAE9F,QAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["jiti","showOnboardingHexclaveConfigValue","ClaudeAgentTimeoutError","ClaudeAgentFailureError"],"sources":["../src/index.ts"],"sourcesContent":["import { showOnboardingHexclaveConfigValue } from \"@hexclave/shared/dist/config-authoring\";\nimport { detectImportPackageFromDir, parseHexclaveConfigFileContent, renderConfigFileContent } from \"@hexclave/shared/dist/config-rendering\";\nimport type { Config, ConfigValue, NormalizedConfig } from \"@hexclave/shared/dist/config/format\";\nimport { isValidConfig, normalize, override } from \"@hexclave/shared/dist/config/format\";\nimport { captureError } from \"@hexclave/shared/dist/utils/errors\";\nimport { createHash } from \"crypto\";\nimport { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from \"fs\";\nimport { createJiti } from \"jiti\";\nimport path from \"path\";\nimport { ClaudeAgentFailureError, ClaudeAgentTimeoutError, getToolWriteTargetPath, isPathInsideDir, runHeadlessClaudeAgent } from \"./config-agent\";\n\nconst jiti = createJiti(import.meta.url, { moduleCache: false });\n\nconst LOG_PREFIX = \"[Stack config updater]\";\nconst DEFAULT_AGENT_TIMEOUT_MS = 120_000;\nconst CONFIG_UPDATE_LOG_PATH_LIMIT = 40;\n\ntype ConfigModule = {\n config?: unknown,\n};\n\ntype ConfigFileSnapshot = { path: string, content: string | null };\ntype ConfigChange = { path: string, value: ConfigValue };\n\nfunction formatConfigUpdaterErrorForLog(error: unknown): Record<string, unknown> {\n if (error instanceof Error) {\n return {\n errorName: error.name,\n errorMessage: error.message,\n errorStack: error.stack,\n };\n }\n return {\n errorMessage: String(error),\n };\n}\n\nfunction configUpdatePathDetailsForLog(changes: ConfigChange[]): Record<string, unknown> {\n const paths = changes.map(({ path: configPath }) => configPath).sort();\n return {\n configUpdatePathCount: paths.length,\n configUpdatePaths: paths.slice(0, CONFIG_UPDATE_LOG_PATH_LIMIT),\n configUpdatePathsTruncated: paths.length > CONFIG_UPDATE_LOG_PATH_LIMIT,\n };\n}\n\nfunction isConfigModule(value: unknown): value is ConfigModule {\n return value !== null && typeof value === \"object\";\n}\n\nexport function sha256String(value: string): string {\n return createHash(\"sha256\").update(value).digest(\"hex\");\n}\n\nexport function resolveConfigFilePath(inputPath: string): string {\n const resolved = path.resolve(inputPath);\n const looksLikeConfigFile = /\\.(ts|js|mjs|cjs)$/i.test(resolved);\n if (looksLikeConfigFile) {\n return resolved;\n }\n // Prefer hexclave.config.ts, fall back to stack.config.ts, default to the new name.\n const hexclaveCandidate = path.join(resolved, \"hexclave.config.ts\");\n const legacyCandidate = path.join(resolved, \"stack.config.ts\");\n if (existsSync(hexclaveCandidate)) {\n return hexclaveCandidate;\n }\n if (existsSync(legacyCandidate)) {\n return legacyCandidate;\n }\n return hexclaveCandidate;\n}\n\nexport function ensureConfigFileExists(configFilePath: string): void {\n if (existsSync(configFilePath)) return;\n mkdirSync(path.dirname(configFilePath), { recursive: true });\n renderConfigObjectToFile(configFilePath, {});\n}\n\nexport async function readConfigObject(configFilePath: string): Promise<Config> {\n return (await readConfigFile(configFilePath)).config;\n}\n\nexport async function readConfigFile(configFilePath: string): Promise<{ config: Config, showOnboarding: boolean }> {\n ensureConfigFileExists(configFilePath);\n const content = readFileSync(configFilePath, \"utf-8\");\n if (content.trim() === \"\") {\n return {\n config: {},\n showOnboarding: false,\n };\n }\n\n let configModule: unknown;\n try {\n configModule = await jiti.import<unknown>(configFilePath);\n } catch (error) {\n // Capture the raw jiti/framework error for diagnostics, but don't attach it as `cause` on the thrown error:\n // dashboard error formatting renders causes recursively, which would leak framework internals into the\n // user-facing message we're deliberately replacing.\n captureError(\"shared-backend/readConfigFile\", error);\n throw new Error(\n `Failed to load config file ${configFilePath}.`,\n );\n }\n if (!isConfigModule(configModule)) {\n throw new Error(`Invalid config in ${configFilePath}. The file must export a plain \\`config\\` object or \"show-onboarding\".`);\n }\n\n const config = configModule.config;\n if (config === showOnboardingHexclaveConfigValue) {\n return {\n config: {},\n showOnboarding: true,\n };\n }\n if (!isValidConfig(config)) {\n throw new Error(`Invalid config in ${configFilePath}.`);\n }\n return {\n config,\n showOnboarding: false,\n };\n}\n\nfunction renderConfigObjectToString(configFilePath: string, config: Config): string {\n const importPackage = detectImportPackageFromDir(path.dirname(configFilePath));\n return renderConfigFileContent(config, importPackage);\n}\n\nfunction writeFileAtomic(configFilePath: string, content: string): void {\n const dir = path.dirname(configFilePath);\n mkdirSync(dir, { recursive: true });\n const tempPath = path.join(dir, `.stack.config.${Math.random().toString(36).slice(2)}.tmp`);\n writeFileSync(tempPath, content, \"utf-8\");\n try {\n renameSync(tempPath, configFilePath);\n } catch (error) {\n try {\n rmSync(tempPath);\n } catch { /* best-effort cleanup */ }\n throw error;\n }\n}\n\nfunction renderConfigObjectToFile(configFilePath: string, config: Config): void {\n writeFileAtomic(configFilePath, renderConfigObjectToString(configFilePath, config));\n}\n\nexport async function updateConfigObject(configFilePath: string, configUpdate: Config): Promise<void> {\n const startedAtMs = performance.now();\n ensureConfigFileExists(configFilePath);\n\n const changes = flattenConfigUpdate(configUpdate);\n if (changes.length === 0) {\n console.log(`${LOG_PREFIX} Skipping config update because it contains no changes`, {\n configFilePath,\n });\n return;\n }\n const updateLogDetails = {\n configFilePath,\n ...configUpdatePathDetailsForLog(changes),\n };\n console.log(`${LOG_PREFIX} Starting config file update`, updateLogDetails);\n\n const content = readFileSync(configFilePath, \"utf-8\");\n\n // Fast path: if the config is a plain static literal (no imports, no helpers),\n // apply the update deterministically without invoking the AI agent.\n const staticConfig = tryParseStaticConfigFileContent(content, configFilePath);\n if (staticConfig != null && isValidConfig(staticConfig)) {\n console.log(`${LOG_PREFIX} Applying config update with static config rewrite`, updateLogDetails);\n const merged = override(staticConfig, configUpdate);\n if (!isValidConfig(merged)) {\n throw new Error(`${LOG_PREFIX} Merged config is invalid after applying update to ${configFilePath}`);\n }\n renderConfigObjectToFile(configFilePath, merged);\n console.log(`${LOG_PREFIX} Finished config update with static config rewrite`, {\n ...updateLogDetails,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n });\n return;\n }\n\n // Agent path: config has custom structure (imports, helpers, external files)\n // that must be preserved — delegate to the AI agent.\n console.log(`${LOG_PREFIX} Applying config update with agent-assisted rewrite`, {\n ...updateLogDetails,\n configDirectory: path.dirname(configFilePath),\n });\n const baselineConfig = await tryReadConfigForValidation(configFilePath);\n const { snapshots, seen } = snapshotConfigFiles(configFilePath, content);\n try {\n await runConfigUpdateAgent({\n prompt: buildConfigUpdatePrompt(path.basename(configFilePath), configUpdate, baselineConfig),\n cwd: path.dirname(configFilePath),\n onFileWillChange: (filePath) => captureSnapshotIfAbsent(snapshots, filePath, seen),\n });\n await validateAgentUpdate(configFilePath, baselineConfig, configUpdate, snapshots);\n } catch (error) {\n console.warn(`${LOG_PREFIX} Config update failed; restoring files from snapshots`, {\n ...updateLogDetails,\n snapshotCount: snapshots.length,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n ...formatConfigUpdaterErrorForLog(error),\n });\n try {\n restoreConfigFiles(snapshots);\n console.warn(`${LOG_PREFIX} Restored files after failed config update`, {\n ...updateLogDetails,\n snapshotCount: snapshots.length,\n });\n } catch (restoreError) {\n console.error(`${LOG_PREFIX} Failed to fully roll back config files after a failed update of ${configFilePath}; some files may be left in a partially-restored state`, {\n configFilePath,\n ...formatConfigUpdaterErrorForLog(restoreError),\n });\n }\n throw error;\n }\n console.log(`${LOG_PREFIX} Finished config update with agent-assisted rewrite`, {\n ...updateLogDetails,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n snapshotCount: snapshots.length,\n });\n}\n\nexport async function replaceConfigObject(configFilePath: string, config: Config): Promise<void> {\n renderConfigObjectToFile(configFilePath, config);\n}\n\nasync function runConfigUpdateAgent(options: {\n prompt: string,\n cwd: string,\n onFileWillChange?: (filePath: string) => void,\n}): Promise<void> {\n const timeoutMs = parseAgentTimeoutMs();\n const deniedOutOfBoundsWrites = new Set<string>();\n const startedAtMs = performance.now();\n console.log(`${LOG_PREFIX} Starting config update agent`, {\n cwd: options.cwd,\n timeoutMs,\n });\n try {\n await runHeadlessClaudeAgent({\n prompt: options.prompt,\n cwd: options.cwd,\n allowedTools: [\"Read\", \"Write\", \"Edit\", \"Glob\", \"Grep\"],\n strictIsolation: true,\n timeoutMs,\n stderr: (data) => { console.warn(`${LOG_PREFIX} [agent] ${data}`); },\n onPreToolUse: (input) => {\n const target = getToolWriteTargetPath(input.tool_name, input.tool_input, options.cwd);\n if (target == null) return { continue: true };\n if (!isPathInsideDir(options.cwd, target)) {\n deniedOutOfBoundsWrites.add(target);\n return {\n hookSpecificOutput: {\n hookEventName: \"PreToolUse\",\n permissionDecision: \"deny\",\n permissionDecisionReason: `Refusing to modify ${target}: config updates may only change files inside the config directory.`,\n },\n };\n }\n options.onFileWillChange?.(target);\n return { continue: true };\n },\n });\n } catch (error) {\n if (error instanceof ClaudeAgentTimeoutError) {\n console.warn(`${LOG_PREFIX} Config update agent timed out`, {\n cwd: options.cwd,\n timeoutMs,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n ...formatConfigUpdaterErrorForLog(error),\n });\n throw new Error(`Config update agent timed out after ${timeoutMs}ms. It was unable to apply the config changes to the file.`);\n }\n if (error instanceof ClaudeAgentFailureError) {\n console.warn(`${LOG_PREFIX} Config update agent failed`, {\n cwd: options.cwd,\n timeoutMs,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n ...formatConfigUpdaterErrorForLog(error),\n });\n throw new Error(`${error.message} It was unable to apply the config changes to the file.`);\n }\n console.warn(`${LOG_PREFIX} Config update agent failed unexpectedly`, {\n cwd: options.cwd,\n timeoutMs,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n ...formatConfigUpdaterErrorForLog(error),\n });\n throw error;\n }\n console.log(`${LOG_PREFIX} Finished config update agent`, {\n cwd: options.cwd,\n timeoutMs,\n elapsedMs: Math.round(performance.now() - startedAtMs),\n deniedOutOfBoundsWriteCount: deniedOutOfBoundsWrites.size,\n });\n if (deniedOutOfBoundsWrites.size > 0) {\n console.warn(`${LOG_PREFIX} Config update agent attempted out-of-bounds writes`, {\n cwd: options.cwd,\n deniedOutOfBoundsWriteCount: deniedOutOfBoundsWrites.size,\n deniedOutOfBoundsWrites: [...deniedOutOfBoundsWrites],\n });\n throw new Error(`Config update agent tried to modify ${deniedOutOfBoundsWrites.size} file(s) outside the config directory, which is not allowed: ${[...deniedOutOfBoundsWrites].join(\", \")}. The config was not updated.`);\n }\n}\n\nfunction parseAgentTimeoutMs(): number {\n const raw = process.env.STACK_CONFIG_UPDATE_AGENT_TIMEOUT_MS;\n if (raw == null || raw.trim() === \"\") return DEFAULT_AGENT_TIMEOUT_MS;\n const parsed = Number(raw);\n if (!Number.isFinite(parsed) || parsed <= 0) {\n throw new Error(`Invalid STACK_CONFIG_UPDATE_AGENT_TIMEOUT_MS: ${JSON.stringify(raw)}. Expected a positive number of milliseconds.`);\n }\n return parsed;\n}\n\nfunction captureSnapshotIfAbsent(snapshots: ConfigFileSnapshot[], filePath: string, seen: Set<string>): void {\n const resolved = path.resolve(filePath);\n if (seen.has(resolved)) return;\n seen.add(resolved);\n snapshots.push({ path: resolved, content: existsSync(resolved) ? readFileSync(resolved, \"utf-8\") : null });\n}\n\nfunction snapshotConfigFiles(configFilePath: string, configContent: string): { snapshots: ConfigFileSnapshot[]; seen: Set<string> } {\n const dir = path.dirname(configFilePath);\n const resolvedConfig = path.resolve(configFilePath);\n const snapshots: ConfigFileSnapshot[] = [{ path: resolvedConfig, content: configContent }];\n const seen = new Set<string>([resolvedConfig]);\n for (const specifier of getRelativeImportSpecifiers(configContent)) {\n const resolved = path.resolve(dir, specifier);\n if (!isPathInsideDir(dir, resolved)) continue;\n captureSnapshotIfAbsent(snapshots, resolved, seen);\n }\n return { snapshots, seen };\n}\n\nfunction restoreConfigFiles(snapshots: ConfigFileSnapshot[]): void {\n const failures: string[] = [];\n for (const { path: filePath, content } of snapshots) {\n try {\n if (content === null) {\n if (existsSync(filePath)) rmSync(filePath);\n } else {\n writeFileSync(filePath, content, \"utf-8\");\n }\n } catch (error) {\n failures.push(`${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n }\n }\n if (failures.length > 0) {\n throw new Error(`Failed to restore ${failures.length} file(s) during rollback: ${failures.join(\"; \")}`);\n }\n}\n\nasync function tryReadConfigForValidation(configFilePath: string): Promise<Config | null> {\n try {\n return (await readConfigFile(configFilePath)).config;\n } catch (error) {\n console.warn(`${LOG_PREFIX} Could not evaluate config for validation baseline; will fall back to a structural check`, {\n configFilePath,\n error: error instanceof Error ? error.message : String(error),\n });\n return null;\n }\n}\n\nasync function validateAgentUpdate(configFilePath: string, baselineConfig: Config | null, configUpdate: Config, snapshots: ConfigFileSnapshot[]): Promise<void> {\n if (baselineConfig != null) {\n const target = canonicalizeConfig(override(baselineConfig, configUpdate));\n const result = canonicalizeConfig((await readConfigFile(configFilePath)).config);\n if (!configsEqual(result, target)) {\n throw new Error(`Config update validation failed for ${configFilePath}: the updated file does not evaluate to the expected configuration.`);\n }\n return;\n }\n\n // Structural-only fallback: when jiti can't evaluate the config (e.g. missing\n // runtime dependencies in import-with attributes), we can only verify that\n // (a) something changed on disk and (b) the file still exports `config`.\n // This cannot catch silently mis-applied values — an accepted tradeoff vs.\n // blocking updates entirely for configs we can't evaluate.\n // When nothing changed on disk the update is either already applied or the\n // agent couldn't figure out what to do. Treat it as a no-op rather than a\n // hard failure: the structural check below still verifies the file is valid.\n if (flattenConfigUpdate(configUpdate).length > 0 && !snapshotsChangedOnDisk(snapshots)) {\n console.warn(`${LOG_PREFIX} Agent did not modify any file for ${configFilePath}; assuming values are already up to date.`);\n }\n\n const content = readFileSync(configFilePath, \"utf-8\");\n if (!configFileExportsConfig(content, configFilePath)) {\n throw new Error(`Config update validation failed for ${configFilePath}: the updated file no longer exports a valid \\`config\\`.`);\n }\n}\n\nfunction tryParseStaticConfigFileContent(content: string, configFilePath: string): Config | null {\n try {\n const parsed = parseHexclaveConfigFileContent(content, configFilePath);\n return isValidConfig(parsed) ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction configFileExportsConfig(content: string, configFilePath: string): boolean {\n try {\n parseHexclaveConfigFileContent(content, configFilePath);\n return true;\n } catch {\n // Dynamic configs can be valid even when the static parser cannot evaluate\n // them. For the structural fallback we only need to know that a runtime\n // config binding still exists after the agent edited the file.\n return /\\bexport\\s+const\\s+config\\b/.test(content);\n }\n}\n\nfunction getRelativeImportSpecifiers(content: string): string[] {\n const specifiers: string[] = [];\n const importPattern = /\\bimport\\b(?:[^'\"]*?\\bfrom\\s*)?[\"'](\\.{1,2}\\/[^\"']+)[\"']/g;\n let match: RegExpExecArray | null;\n while ((match = importPattern.exec(content)) !== null) {\n specifiers.push(match[1]);\n }\n return specifiers;\n}\n\nfunction snapshotsChangedOnDisk(snapshots: ConfigFileSnapshot[]): boolean {\n return snapshots.some(({ path: filePath, content }) => {\n const current = existsSync(filePath) ? readFileSync(filePath, \"utf-8\") : null;\n return current !== content;\n });\n}\n\nfunction flattenConfigUpdate(update: Config): ConfigChange[] {\n const changes: ConfigChange[] = [];\n const walk = (prefix: string, obj: Config): void => {\n for (const [key, value] of Object.entries(obj)) {\n const fullPath = prefix === \"\" ? key : `${prefix}.${key}`;\n if (value === undefined) continue;\n if (value !== null && typeof value === \"object\" && !Array.isArray(value) && Object.keys(value).length > 0) {\n walk(fullPath, value);\n } else {\n changes.push({ path: fullPath, value });\n }\n }\n };\n walk(\"\", update);\n return changes;\n}\n\nfunction buildConfigUpdatePrompt(configFileName: string, configUpdate: Config, baselineConfig: Config | null): string {\n const changes = flattenConfigUpdate(configUpdate);\n const changeLines = changes.map(({ path: configPath, value }) => {\n return `- ${JSON.stringify(configPath)}: set to ${JSON.stringify(value)}`;\n }).join(\"\\n\");\n const expectedConfig = baselineConfig == null ? null : canonicalizeConfig(override(baselineConfig, configUpdate));\n const expectedConfigSection = expectedConfig == null ? \"\" : `\nAfter the edit, evaluating the exported \\`config\\` must produce this exact JSON value:\n\n${JSON.stringify(expectedConfig, null, 2)}\n`;\n\n return `You are editing a Hexclave / Stack Auth configuration file in place. Apply a set of configuration changes WITHOUT changing how the file is written.\n\nConfig file: ${JSON.stringify(configFileName)} (in the current working directory).\n\nThe file exports a \\`config\\` object (it may be wrapped in a helper such as \\`defineStackConfig(...)\\`). Some config values may be sourced from other files via imports, for example:\n\n import welcomeEmail from \"./welcome-email.tsx\" with { type: \"text\" };\n export const config = { emails: { templates: { welcome: welcomeEmail } } };\n\nApply EXACTLY these changes. Paths use dot notation, so \\`a.b.c\\` refers to \\`config.a.b.c\\`:\n\n${changeLines}\n${expectedConfigSection}\n\nRules:\n- Change ONLY the config paths listed above. Leave every other part of the file byte-for-byte unchanged: imports, comments, formatting, helper wrappers, and any config fields not listed.\n- If a listed path's value is currently provided by an imported external file (like the \\`import ... with { type: \"text\" }\\` example above), DO NOT inline the new value into the config file. Instead, overwrite that external file with the new value and keep the import statement intact.\n- If a listed path's value is a plain inline literal, edit it inline.\n- Keep the file valid: it must still export a \\`config\\` that, once evaluated, reflects the new values exactly.\n- Do not run any shell commands and do not create files other than what is required to apply these changes.`;\n}\n\nfunction canonicalizeConfig(config: Config): NormalizedConfig {\n const droppedKeys: string[] = [];\n const normalized = normalize(config, {\n onDotIntoNonObject: \"ignore\",\n onDotIntoNull: \"empty-object\",\n droppedKeys,\n });\n if (droppedKeys.length > 0) {\n throw new Error(`Config update has conflicting keys that would be dropped during normalization: ${droppedKeys.map((key) => JSON.stringify(key)).join(\", \")}`);\n }\n return normalized;\n}\n\nfunction configsEqual(a: unknown, b: unknown): boolean {\n if (a === b) return true;\n if (a === null || b === null) return a === b;\n if (Array.isArray(a) || Array.isArray(b)) {\n if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;\n return a.every((value, index) => configsEqual(value, b[index]));\n }\n if (typeof a === \"object\" && typeof b === \"object\") {\n const aEntries = Object.entries(a);\n const bMap = new Map(Object.entries(b));\n if (aEntries.length !== bMap.size) return false;\n return aEntries.every(([key, value]) => bMap.has(key) && configsEqual(value, bMap.get(key)));\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;AAWA,MAAMA,6EAAmC,EAAE,aAAa,OAAO,CAAC;AAEhE,MAAM,aAAa;AACnB,MAAM,2BAA2B;AACjC,MAAM,+BAA+B;AASrC,SAAS,+BAA+B,OAAyC;AAC/E,KAAI,iBAAiB,MACnB,QAAO;EACL,WAAW,MAAM;EACjB,cAAc,MAAM;EACpB,YAAY,MAAM;EACnB;AAEH,QAAO,EACL,cAAc,OAAO,MAAM,EAC5B;;AAGH,SAAS,8BAA8B,SAAkD;CACvF,MAAM,QAAQ,QAAQ,KAAK,EAAE,MAAM,iBAAiB,WAAW,CAAC,MAAM;AACtE,QAAO;EACL,uBAAuB,MAAM;EAC7B,mBAAmB,MAAM,MAAM,GAAG,6BAA6B;EAC/D,4BAA4B,MAAM,SAAS;EAC5C;;AAGH,SAAS,eAAe,OAAuC;AAC7D,QAAO,UAAU,QAAQ,OAAO,UAAU;;AAG5C,SAAgB,aAAa,OAAuB;AAClD,+BAAkB,SAAS,CAAC,OAAO,MAAM,CAAC,OAAO,MAAM;;AAGzD,SAAgB,sBAAsB,WAA2B;CAC/D,MAAM,WAAW,aAAK,QAAQ,UAAU;AAExC,KA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AS,mBAAmB,QAAkC;CAC5D,MAAM,cAAwB,EAAE;CAChC,MAAM,gEAAuB,QAAQ;EACnC,oBAAoB;EACpB,eAAe;EACf;EACD,CAAC;AACF,KAAI,YAAY,SAAS,EACvB,OAAM,IAAI,MAAM,kFAAkF,YAAY,KAAK,QAAQ,KAAK,UAAU,IAAI,CAAC,CAAC,KAAK,KAAK,GAAG;AAE/J,QAAO;;AAGT,SAAS,aAAa,GAAY,GAAqB;AACrD,KAAI,MAAM,EAAG,QAAO;AACpB,KAAI,MAAM,QAAQ,MAAM,KAAM,QAAO,MAAM;AAC3C,KAAI,MAAM,QAAQ,EAAE,IAAI,MAAM,QAAQ,EAAE,EAAE;AACxC,MAAI,CAAC,MAAM,QAAQ,EAAE,IAAI,CAAC,MAAM,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAC5E,SAAO,EAAE,OAAO,OAAO,UAAU,aAAa,OAAO,EAAE,OAAO,CAAC;;AAEjE,KAAI,OAAO,MAAM,YAAY,OAAO,MAAM,UAAU;EAClD,MAAM,WAAW,OAAO,QAAQ,EAAE;EAClC,MAAM,OAAO,IAAI,IAAI,OAAO,QAAQ,EAAE,CAAC;AACvC,MAAI,SAAS,WAAW,KAAK,KAAM,QAAO;AAC1C,SAAO,SAAS,OAAO,CAAC,KAAK,WAAW,KAAK,IAAI,IAAI,IAAI,aAAa,OAAO,KAAK,IAAI,IAAI,CAAC,CAAC;;AAE9F,QAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hexclave/shared-backend",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.34",
|
|
4
4
|
"repository": "https://github.com/hexclave/hexclave",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@anthropic-ai/claude-agent-sdk": "^0.2.73",
|
|
31
31
|
"jiti": "^2.4.2",
|
|
32
|
-
"@hexclave/shared": "1.0.
|
|
32
|
+
"@hexclave/shared": "1.0.34"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "20.17.6",
|