Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs
Submodule docs updated from 7f3750 to 09132c
10 changes: 6 additions & 4 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,24 @@ dotnet_diagnostic.RCS1168.severity = warning # Parameter name 'foo' differs from
dotnet_diagnostic.RCS1175.severity = warning # Unused 'this' parameter 'operation'.
dotnet_diagnostic.RCS1192.severity = warning # Unnecessary usage of verbatim string literal.
dotnet_diagnostic.RCS1194.severity = warning # Implement exception constructors.
dotnet_diagnostic.RCS1211.severity = warning # Remove unnecessary else clause.
dotnet_diagnostic.RCS1211.severity = none # Remove unnecessary else clause.
dotnet_diagnostic.RCS1214.severity = warning # Unnecessary interpolated string.
dotnet_diagnostic.RCS1225.severity = warning # Make class sealed.
dotnet_diagnostic.RCS1232.severity = warning # Order elements in documentation comment.

# Diagnostics elevated as warnings
dotnet_diagnostic.CA1000.severity = warning # Do not declare static members on generic types
dotnet_diagnostic.CA1031.severity = warning # Do not catch general exception types
dotnet_diagnostic.CA1031.severity = none # Do not catch general exception types
dotnet_diagnostic.CA1050.severity = warning # Declare types in namespaces
dotnet_diagnostic.CA1063.severity = warning # Implement IDisposable correctly
dotnet_diagnostic.CA1064.severity = warning # Exceptions should be public
dotnet_diagnostic.CA1303.severity = warning # Do not pass literals as localized parameters
dotnet_diagnostic.CA1307.severity = none # StringComparison parameter - using default culture comparison is intentional for query parsing
dotnet_diagnostic.CA1308.severity = none # Case-insensitive string comparisons are explicitly required by design
dotnet_diagnostic.CA1416.severity = warning # Validate platform compatibility
dotnet_diagnostic.CA1508.severity = warning # Avoid dead conditional code
dotnet_diagnostic.CA1852.severity = warning # Sealed classes
dotnet_diagnostic.CA1859.severity = warning # Use concrete types when possible for improved performance
dotnet_diagnostic.CA1859.severity = none # Use concrete types when possible for improved performance
dotnet_diagnostic.CA1860.severity = warning # Prefer comparing 'Count' to 0 rather than using 'Any()', both for clarity and for performance
dotnet_diagnostic.CA2000.severity = warning # Call System.IDisposable.Dispose on object before all references to it are out of scope
dotnet_diagnostic.CA2007.severity = error # Do not directly await a Task
Expand Down Expand Up @@ -132,7 +134,7 @@ dotnet_diagnostic.IDE0161.severity = warning # Use file-scoped namespace

dotnet_diagnostic.RCS1032.severity = warning # Remove redundant parentheses.
dotnet_diagnostic.RCS1118.severity = warning # Mark local variable as const.
dotnet_diagnostic.RCS1141.severity = warning # Add 'param' element to documentation comment.
dotnet_diagnostic.RCS1141.severity = none # Add 'param' element to documentation comment.
dotnet_diagnostic.RCS1197.severity = warning # Optimize StringBuilder.AppendLine call.
dotnet_diagnostic.RCS1205.severity = warning # Order named arguments according to the order of parameters.
dotnet_diagnostic.RCS1229.severity = warning # Use async/await when necessary.
Expand Down
10 changes: 0 additions & 10 deletions src/Core/.editorconfig

This file was deleted.

4 changes: 4 additions & 0 deletions src/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
<InternalsVisibleTo Include="KernelMemory.Core.Tests" />
</ItemGroup>

<ItemGroup>
<EditorConfigFiles Remove=".editorconfig" />
</ItemGroup>

</Project>
19 changes: 0 additions & 19 deletions src/Core/GlobalSuppressions.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/Core/Search/Query/Parsers/MongoJsonQueryParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Globalization;
using System.Text.Json;
using KernelMemory.Core.Search.Query.Ast;

Expand Down Expand Up @@ -320,7 +322,7 @@ private LiteralNode ParseArrayValue(JsonElement element)
}
else if (item.ValueKind == JsonValueKind.Number)
{
items.Add(item.GetDouble().ToString());
items.Add(item.GetDouble().ToString(CultureInfo.CurrentCulture));
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
<PackageVersion Include="Microsoft.ML.Tokenizers.Data.O200kBase" Version="1.0.2" />
<PackageVersion Include="Microsoft.ML.Tokenizers.Data.P50kBase" Version="1.0.2" />
<!-- CLI and UI -->
<PackageVersion Include="Spectre.Console" Version="0.49.1" />
<PackageVersion Include="Spectre.Console.Cli" Version="0.49.1" />
<PackageVersion Include="Spectre.Console" Version="0.54.0" />
<PackageVersion Include="Spectre.Console.Cli" Version="0.53.1" />
<!-- Serialization -->
<PackageVersion Include="YamlDotNet" Version="16.2.0" />
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
<!-- Testing -->
<PackageVersion Include="Moq" Version="4.20.72" />
</ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions src/Main/CLI/CliApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ public sealed class CliApplicationBuilder
public CommandApp Build(string[]? args = null)
{
// 1. Determine config path from args early (before command execution)
var configPath = this.DetermineConfigPath(args ?? Array.Empty<string>());
string configPath = this.DetermineConfigPath(args ?? []);

// 2. Load config ONCE (happens before any command runs)
var config = ConfigParser.LoadFromFile(configPath);
AppConfig config = ConfigParser.LoadFromFile(configPath);

// 3. Create DI container and register AppConfig as singleton
var services = new ServiceCollection();
ServiceCollection services = new();
services.AddSingleton(config);

// Also register the config path so commands can access it
services.AddSingleton(new ConfigPathService(configPath));

// 4. Create type registrar for Spectre.Console.Cli DI integration
var registrar = new TypeRegistrar(services);
TypeRegistrar registrar = new(services);

// 5. Build CommandApp with DI support
var app = new CommandApp(registrar);
CommandApp app = new(registrar);
this.Configure(app);
return app;
}
Expand Down Expand Up @@ -162,4 +162,4 @@ public void Configure(CommandApp app)
config.ValidateExamples();
});
}
}
}
3 changes: 2 additions & 1 deletion src/Main/CLI/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Diagnostics.CodeAnalysis;
using KernelMemory.Core.Config;
using KernelMemory.Core.Config.ContentIndex;
Expand Down Expand Up @@ -128,7 +129,7 @@ protected ContentService CreateContentService(NodeConfig node, bool readonlyMode
builder.AddConsole();
builder.SetMinimumLevel(LogLevel.Warning);
});
var searchIndexes = Services.SearchIndexFactory.CreateIndexes(node.SearchIndexes, loggerFactory);
var searchIndexes = SearchIndexFactory.CreateIndexes(node.SearchIndexes, loggerFactory);

// Create storage service with search indexes
var storage = new ContentStorageService(context, cuidGenerator, logger, searchIndexes);
Expand Down
21 changes: 15 additions & 6 deletions src/Main/CLI/Commands/ConfigCommand.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// Copyright (c) Microsoft. All rights reserved.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;
using KernelMemory.Core.Config;
using KernelMemory.Main.CLI.Infrastructure;
using KernelMemory.Main.CLI.Models;
using KernelMemory.Main.CLI.OutputFormatters;
using Spectre.Console;
using Spectre.Console.Cli;

Expand Down Expand Up @@ -36,7 +40,7 @@ public class ConfigCommand : BaseCommand<ConfigCommandSettings>
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};

private readonly ConfigPathService _configPathService;
Expand All @@ -47,23 +51,23 @@ public class ConfigCommand : BaseCommand<ConfigCommandSettings>
/// <param name="config">Application configuration (injected by DI).</param>
/// <param name="configPathService">Service providing the config file path (injected by DI).</param>
public ConfigCommand(
KernelMemory.Core.Config.AppConfig config,
AppConfig config,
ConfigPathService configPathService) : base(config)
{
this._configPathService = configPathService ?? throw new ArgumentNullException(nameof(configPathService));
}

[SuppressMessage("Design", "CA1031:Do not catch general exception types",
Justification = "Top-level command handler must catch all exceptions to return appropriate exit codes and error messages")]
public override async Task<int> ExecuteAsync(
public async Task<int> ExecuteAsync(
CommandContext context,
ConfigCommandSettings settings)
{
try
{
// ConfigCommand doesn't need node selection - it queries the entire configuration
// So we skip Initialize() and just use the injected config directly
var formatter = CLI.OutputFormatters.OutputFormatterFactory.Create(settings);
var formatter = OutputFormatterFactory.Create(settings);
var configPath = this._configPathService.Path;
var configFileExists = File.Exists(configPath);

Expand Down Expand Up @@ -128,11 +132,16 @@ public override async Task<int> ExecuteAsync(
}
catch (Exception ex)
{
var formatter = CLI.OutputFormatters.OutputFormatterFactory.Create(settings);
var formatter = OutputFormatterFactory.Create(settings);
return this.HandleError(ex, formatter);
}
}

public override Task<int> ExecuteAsync(CommandContext context, ConfigCommandSettings settings, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}

/// <summary>
/// Handles the --create flag to write the configuration to disk.
/// </summary>
Expand All @@ -142,7 +151,7 @@ public override async Task<int> ExecuteAsync(
/// <returns>Exit code.</returns>
[SuppressMessage("Design", "CA1031:Do not catch general exception types",
Justification = "Config creation must catch all exceptions to return appropriate exit codes")]
private int HandleCreateConfig(string configPath, bool configFileExists, CLI.OutputFormatters.IOutputFormatter formatter)
private int HandleCreateConfig(string configPath, bool configFileExists, IOutputFormatter formatter)
{
try
{
Expand Down
13 changes: 7 additions & 6 deletions src/Main/CLI/Commands/DeleteCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft. All rights reserved.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using KernelMemory.Core.Config;
using KernelMemory.Main.CLI.OutputFormatters;
using Spectre.Console;
using Spectre.Console.Cli;

Expand Down Expand Up @@ -41,15 +43,14 @@ public class DeleteCommand : BaseCommand<DeleteCommandSettings>
/// Initializes a new instance of the <see cref="DeleteCommand"/> class.
/// </summary>
/// <param name="config">Application configuration (injected by DI).</param>
public DeleteCommand(KernelMemory.Core.Config.AppConfig config) : base(config)
public DeleteCommand(AppConfig config) : base(config)
{
}

[SuppressMessage("Design", "CA1031:Do not catch general exception types",
Justification = "Top-level command handler must catch all exceptions to return appropriate exit codes and error messages")]
public override async Task<int> ExecuteAsync(
CommandContext context,
DeleteCommandSettings settings)
DeleteCommandSettings settings,
CancellationToken cancellationToken)
{
try
{
Expand Down Expand Up @@ -79,7 +80,7 @@ public override async Task<int> ExecuteAsync(
}
catch (Exception ex)
{
var formatter = CLI.OutputFormatters.OutputFormatterFactory.Create(settings);
var formatter = OutputFormatterFactory.Create(settings);
return this.HandleError(ex, formatter);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Main/CLI/Commands/ExamplesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public sealed class Settings : CommandSettings
}

/// <inheritdoc />
public override int Execute(CommandContext context, Settings settings)
public override int Execute(CommandContext context, Settings settings, CancellationToken cancellationToken)
{
if (!string.IsNullOrEmpty(settings.Command))
{
Expand Down
18 changes: 10 additions & 8 deletions src/Main/CLI/Commands/GetCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Copyright (c) Microsoft. All rights reserved.

using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using KernelMemory.Core.Config;
using KernelMemory.Core.Storage.Models;
using KernelMemory.Main.CLI.Exceptions;
using KernelMemory.Main.CLI.OutputFormatters;
using Spectre.Console;
using Spectre.Console.Cli;

Expand Down Expand Up @@ -46,15 +49,14 @@ public class GetCommand : BaseCommand<GetCommandSettings>
/// Initializes a new instance of the <see cref="GetCommand"/> class.
/// </summary>
/// <param name="config">Application configuration (injected by DI).</param>
public GetCommand(KernelMemory.Core.Config.AppConfig config) : base(config)
public GetCommand(AppConfig config) : base(config)
{
}

[SuppressMessage("Design", "CA1031:Do not catch general exception types",
Justification = "Top-level command handler must catch all exceptions to return appropriate exit codes and error messages")]
public override async Task<int> ExecuteAsync(
CommandContext context,
GetCommandSettings settings)
GetCommandSettings settings,
CancellationToken cancellationToken)
{
try
{
Expand All @@ -70,7 +72,7 @@ public override async Task<int> ExecuteAsync(
}

// Wrap result with node information
var response = Core.Storage.Models.ContentDtoWithNode.FromContentDto(result, node.Id);
var response = ContentDtoWithNode.FromContentDto(result, node.Id);

formatter.Format(response);

Expand All @@ -84,7 +86,7 @@ public override async Task<int> ExecuteAsync(
}
catch (Exception ex)
{
var formatter = CLI.OutputFormatters.OutputFormatterFactory.Create(settings);
var formatter = OutputFormatterFactory.Create(settings);
return this.HandleError(ex, formatter);
}
}
Expand All @@ -95,7 +97,7 @@ public override async Task<int> ExecuteAsync(
/// <param name="settings">Command settings for output format.</param>
private void ShowFirstRunMessage(GetCommandSettings settings)
{
var formatter = CLI.OutputFormatters.OutputFormatterFactory.Create(settings);
var formatter = OutputFormatterFactory.Create(settings);

// For JSON/YAML, return null (valid, parseable output)
if (!settings.Format.Equals("human", StringComparison.OrdinalIgnoreCase))
Expand Down
Loading
Loading