From 1d2e2f24dce23a8844264b16e097e8198bdabb1e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Jan 2026 03:57:28 +0000 Subject: [PATCH 1/2] feat: add config load command to load configuration from file Add `triagent config load ` command that allows loading configuration from a JSON file and merging it with the existing configuration. This makes it easier to share and restore configurations across environments. --- src/cli/config.ts | 14 ++++++++++++++ src/index.ts | 48 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/cli/config.ts b/src/cli/config.ts index 4b50c38..9021446 100644 --- a/src/cli/config.ts +++ b/src/cli/config.ts @@ -175,3 +175,17 @@ export function maskApiKey(key: string): string { if (key.length <= 8) return "****"; return key.slice(0, 4) + "****" + key.slice(-4); } + +export async function loadConfigFromFile(filePath: string): Promise { + const content = await readFile(filePath, "utf-8"); + const importedConfig = JSON.parse(content) as StoredConfig; + return importedConfig; +} + +export async function mergeConfigFromFile(filePath: string): Promise { + const importedConfig = await loadConfigFromFile(filePath); + const existingConfig = await loadStoredConfig(); + const mergedConfig = { ...existingConfig, ...importedConfig }; + await saveStoredConfig(mergedConfig); + return mergedConfig; +} diff --git a/src/index.ts b/src/index.ts index d5f1ef0..876c1dd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -11,15 +11,17 @@ import { saveStoredConfig, getConfigPath, maskApiKey, + mergeConfigFromFile, type StoredConfig, } from "./cli/config.js"; import type { AIProvider } from "./config.js"; interface CliArgs { command: "run" | "config" | "cluster"; - configAction?: "set" | "get" | "list" | "path"; + configAction?: "set" | "get" | "list" | "path" | "load"; configKey?: string; configValue?: string; + configFilePath?: string; clusterAction?: "add" | "remove" | "list" | "use" | "status"; clusterName?: string; clusterContext?: string; @@ -46,9 +48,13 @@ function parseArgs(): CliArgs { // Check for config subcommand if (args[0] === "config") { result.command = "config"; - result.configAction = args[1] as "set" | "get" | "list" | "path"; - result.configKey = args[2]; - result.configValue = args[3]; + result.configAction = args[1] as "set" | "get" | "list" | "path" | "load"; + if (result.configAction === "load") { + result.configFilePath = args[2]; + } else { + result.configKey = args[2]; + result.configValue = args[3]; + } return result; } @@ -116,6 +122,7 @@ CONFIG COMMANDS: triagent config get Get a configuration value triagent config list List all configuration values triagent config path Show config file path + triagent config load Load configuration from a JSON file CONFIG KEYS: aiProvider - AI provider (openai, anthropic, google) @@ -453,8 +460,39 @@ async function handleConfigCommand(args: CliArgs): Promise { console.log(path); break; } + case "load": { + if (!args.configFilePath) { + console.error("Usage: triagent config load "); + process.exit(1); + } + try { + const mergedConfig = await mergeConfigFromFile(args.configFilePath); + console.log(`✅ Configuration loaded from ${args.configFilePath}`); + console.log("\nMerged configuration:"); + for (const [key, value] of Object.entries(mergedConfig)) { + if (value === undefined) continue; + if (key === "apiKey") { + console.log(` ${key}: ${maskApiKey(String(value))}`); + } else if (typeof value === "object") { + console.log(` ${key}: ${JSON.stringify(value)}`); + } else { + console.log(` ${key}: ${value}`); + } + } + } catch (error) { + if ((error as NodeJS.ErrnoException).code === "ENOENT") { + console.error(`❌ File not found: ${args.configFilePath}`); + } else if (error instanceof SyntaxError) { + console.error(`❌ Invalid JSON in file: ${args.configFilePath}`); + } else { + console.error(`❌ Failed to load config: ${error}`); + } + process.exit(1); + } + break; + } default: - console.error("Usage: triagent config [key] [value]"); + console.error("Usage: triagent config [key] [value]"); process.exit(1); } } From 00fc883fed2f1e15cc4bd946dd28b103b661404e Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 19 Jan 2026 03:58:05 +0000 Subject: [PATCH 2/2] chore: update bun.lock --- bun.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/bun.lock b/bun.lock index 0cd2a5e..3a5bdb5 100644 --- a/bun.lock +++ b/bun.lock @@ -1,5 +1,6 @@ { "lockfileVersion": 1, + "configVersion": 0, "workspaces": { "": { "name": "firefighter",