SandboxVerificationService.cscsharp

Documentation

Lilith self-improvement (Version 7+)

Lilith can extend herself only by creating tools in three categories:

| Category | Location | Examples | |----------|----------|----------| | Core | Agent-Core | Memory, time (rare; system-level) | | Addon | Agent-Addons | Weather, C# projects, apps | | Self | Lilith | Workspace files, self-improvement |

Layout

  • ShippedSource/ — copy of src/Version7 next to the built app (MSBuild CopyShippedSource)
  • {workspace}/output/self-improvement/live — current editable source
  • {workspace}/output/self-improvement/sandbox — clone for edits and builds
  • {workspace}/output/self-improvement/backups/{timestamp} — backups before promote

Tools

1. self_improve_get_source_layout 2. self_improve_generate_tool 3. self_improve_backup_live 4. self_improve_create_sandbox 5. self_improve_build_sandbox 6. self_improve_verify_sandbox_tool 7. self_improve_promote_sandbox — copies sandbox → live, builds, restarts

Set GENESIS_REPO_ROOT to the repo root when developing from source instead of ShippedSource.

using System;using System.IO;using System.Linq;using System.Text;namespace Lilith.Agent.SelfImprovement;internal static class SandboxVerificationService{    public static string VerifyTool(SelfImprovementPaths paths, ToolSpecStore spec)    {        if (string.IsNullOrWhiteSpace(spec.ToolName))            throw new ArgumentException("tool_name is required.");        string toolName = spec.ToolName;        string? expected = spec.ResolveExpectedResult();        var sb = new StringBuilder();        sb.AppendLine(SandboxBuildService.BuildSandboxConsole(paths));        sb.AppendLine();        bool foundInSource = Directory.EnumerateFiles(paths.Sandbox, "*.cs", SearchOption.AllDirectories)            .Any(f => File.ReadAllText(f).Contains($"\"{toolName}\"", StringComparison.OrdinalIgnoreCase)                        || File.ReadAllText(f).Contains($"Name = \"{toolName}\"", StringComparison.OrdinalIgnoreCase));        sb.AppendLine(foundInSource            ? $"Source check: tool '{toolName}' appears in sandbox source."            : $"Source check: tool '{toolName}' was NOT found in sandbox .cs files.");        string testOutput = SandboxBuildService.RunDesignTests(paths, "FullyQualifiedName~ToolCalling");        sb.AppendLine();        sb.AppendLine(testOutput);        bool buildOk = sb.ToString().Contains("Build succeeded", StringComparison.OrdinalIgnoreCase)                       || sb.ToString().Contains("0 Error(s)", StringComparison.OrdinalIgnoreCase);        bool testsOk = testOutput.Contains("Passed!", StringComparison.OrdinalIgnoreCase)                       || testOutput.StartsWith("Skipped", StringComparison.OrdinalIgnoreCase);        string invokeResult = buildOk            ? SandboxToolInvoker.Invoke(paths, toolName)            : "Skipped: sandbox build failed.";        sb.AppendLine();        if (expected is not null)        {            bool toolOk = !invokeResult.StartsWith("Error", StringComparison.OrdinalIgnoreCase)                            && invokeResult.Trim().Equals(expected, StringComparison.OrdinalIgnoreCase);            sb.AppendLine($"Tool invoke: {toolName}() => '{invokeResult}' (expected '{expected}')");            sb.AppendLine(toolOk ? "TOOL TEST PASSED" : "TOOL TEST FAILED");        }        else        {            bool toolOk = !invokeResult.StartsWith("Error", StringComparison.OrdinalIgnoreCase);            sb.AppendLine($"Tool invoke: {toolName}() => '{invokeResult}'");            sb.AppendLine(toolOk ? "TOOL TEST PASSED" : "TOOL TEST FAILED");        }        bool toolTestOk = sb.ToString().Contains("TOOL TEST PASSED", StringComparison.Ordinal);        sb.AppendLine();        sb.AppendLine(buildOk && foundInSource && testsOk && toolTestOk            ? $"VERIFICATION PASSED for '{toolName}'. You may call self_improve_promote_sandbox."            : $"VERIFICATION FAILED for '{toolName}'. Fix sandbox, rebuild, and verify again before promote.");        return sb.ToString().TrimEnd();    }}