From b07b41cd435991cd254957af79055080c85b346e Mon Sep 17 00:00:00 2001 From: tanaka takashi Date: Sun, 9 Aug 2026 21:08:20 +0900 Subject: feat: AI Agent Sandbox MCP Server v1を実装 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Specifications、Design、ImplementationPlanの優先順位を整理し、単一Task実行モデル、typed option優先、設定可能なresource上限、local Ollamaを必須とするRelease Gateを文書化。 .NET 10/C# 14の5 production project、3 test project、E2E Clientを構築。typed YAML、en/ja locale、fixed/user prompt、stdioおよびloopback限定Streamable HTTP、agent_run/agent_status、Session、Ollama text/tool/Vision、TaskGraphとtoken accountingを実装。 Windows sandboxとしてfixed AppContainer、canonical/reparse検査、能力別ACL、path+SHA-256 executable approval、child-process restriction、Job Object、task journal、atomic file transaction、crash recoveryを実装。WFPのIPv4/IPv6 default denyとexact allow、dynamic session、temporary loopback exemption、管理者/BFE診断を追加。 Security/Recovery test、MCP/Ollama integration test、stdio/HTTP Operational E2E、Release Bundle生成・checksum・manifest・fresh extraction検査を追加。Requirement TraceabilityとPhase 0〜11の進捗、初回セットアップ可能なREADMEを整備。 Debug/Release/publish/objをrepository rootのbuild/へ集約し、旧project-local bin/objへの依存を除去。artifacts/とbuild/をGit管理外に設定し、clean checkoutでもsolution buildからE2E Clientまで生成可能にした。 --- src/Agent.Core/Localization/LocaleCatalog.cs | 97 ++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/Agent.Core/Localization/LocaleCatalog.cs (limited to 'src/Agent.Core/Localization/LocaleCatalog.cs') diff --git a/src/Agent.Core/Localization/LocaleCatalog.cs b/src/Agent.Core/Localization/LocaleCatalog.cs new file mode 100644 index 0000000..3c49283 --- /dev/null +++ b/src/Agent.Core/Localization/LocaleCatalog.cs @@ -0,0 +1,97 @@ +using System.Text.Json; +using System.Text.RegularExpressions; + +namespace Agent.Core.Localization; + +public sealed partial class LocaleCatalog +{ + private readonly IReadOnlyDictionary> _locales; + private readonly IReadOnlyDictionary _fallback; + + private LocaleCatalog(string selectedLocale, IReadOnlyDictionary> locales, IReadOnlyDictionary fallback) + { + SelectedLocale = selectedLocale; + _locales = locales; + _fallback = fallback; + } + + public string SelectedLocale { get; } + public IReadOnlyCollection Keys => _fallback.Keys.ToArray(); + + public static LocaleCatalog Load(string directory, string selectedLocale, string fallbackLocale = "en") + { + if (!Directory.Exists(directory)) throw new LocaleException($"Locale directory does not exist: {directory}"); + + var locales = new Dictionary>(StringComparer.OrdinalIgnoreCase); + foreach (string file in Directory.EnumerateFiles(directory, "*.json", SearchOption.TopDirectoryOnly)) + { + string locale = Path.GetFileNameWithoutExtension(file); + locales.Add(locale, ReadFlatObject(file)); + } + + if (!locales.TryGetValue(fallbackLocale, out IReadOnlyDictionary? fallback)) + throw new LocaleException($"Fallback locale '{fallbackLocale}' is missing."); + + HashSet baselineKeys = fallback.Keys.ToHashSet(StringComparer.Ordinal); + Dictionary> baselinePlaceholders = fallback.ToDictionary(static p => p.Key, static p => Placeholders(p.Value), StringComparer.Ordinal); + foreach ((string locale, IReadOnlyDictionary values) in locales) + { + string? unknown = values.Keys.FirstOrDefault(key => !baselineKeys.Contains(key)); + if (unknown is not null) throw new LocaleException($"Locale '{locale}' contains unknown key '{unknown}'."); + foreach ((string key, string message) in values) + { + if (!baselinePlaceholders[key].SetEquals(Placeholders(message))) + throw new LocaleException($"Locale '{locale}' has mismatched placeholders for key '{key}'."); + } + } + + if (!locales.ContainsKey(selectedLocale)) throw new LocaleException($"Selected locale '{selectedLocale}' is missing."); + return new LocaleCatalog(selectedLocale, locales, fallback); + } + + public string Get(string key) + { + if (_locales[SelectedLocale].TryGetValue(key, out string? selected)) return selected; + return _fallback.TryGetValue(key, out string? fallback) ? fallback : key; + } + + public string Format(string key, IReadOnlyDictionary values) + { + string template = Get(key); + return PlaceholderRegex().Replace(template, match => + { + string name = match.Groups[1].Value; + if (!values.TryGetValue(name, out object? value)) throw new LocaleException($"Missing placeholder value '{name}' for key '{key}'."); + return Convert.ToString(value, System.Globalization.CultureInfo.InvariantCulture) ?? string.Empty; + }); + } + + private static Dictionary ReadFlatObject(string file) + { + try + { + using JsonDocument document = JsonDocument.Parse(File.ReadAllText(file)); + if (document.RootElement.ValueKind != JsonValueKind.Object) throw new LocaleException($"Locale file must contain a JSON object: {file}"); + var result = new Dictionary(StringComparer.Ordinal); + foreach (JsonProperty property in document.RootElement.EnumerateObject()) + { + if (property.Value.ValueKind != JsonValueKind.String) throw new LocaleException($"Locale value '{property.Name}' must be a string."); + if (!result.TryAdd(property.Name, property.Value.GetString()!)) throw new LocaleException($"Duplicate locale key '{property.Name}'."); + } + return result; + } + catch (LocaleException) + { + throw; + } + catch (Exception ex) when (ex is JsonException or IOException or UnauthorizedAccessException) + { + throw new LocaleException($"Could not load locale file '{file}': {ex.Message}", ex); + } + } + + private static HashSet Placeholders(string text) => PlaceholderRegex().Matches(text).Select(static m => m.Groups[1].Value).ToHashSet(StringComparer.Ordinal); + + [GeneratedRegex("\\{([A-Za-z][A-Za-z0-9_]*)\\}", RegexOptions.CultureInvariant)] + private static partial Regex PlaceholderRegex(); +} -- cgit v1.2.3