Built Word Documents (.docx):
Spensara Overview (.docx)
Capability Assessment (.docx)
Brink POS Ingestion Analysis (.docx)
The Borg Ingestion Architecture (.docx)
Categories
Implementation Specs (157)
Detailed engineering and feature implementation specifications.
- specs/AnomalyDetection/TASK1.1.md
- specs/AnomalyDetection/TASK1.2.md
- specs/AnomalyDetection/TASK1.3.md
- specs/AnomalyDetection/TASK1.4.md
- specs/AnomalyDetection/TASK2.1.md
- specs/AnomalyDetection/TASK2.2.md
- specs/AnomalyDetection/TASK3.1.md
- specs/AnomalyDetection/TASK3.2.md
- specs/AnomalyDetection/TASK3.3.md
- specs/AnomalyDetection/TASK4.1.md
- specs/AnomalyDetection/TASK4.2.md
- specs/AnomalyDetection/TASK4.3.md
- specs/AnomalyDetection/TASK4.4.md
- specs/AnomalyDetection/TASK5.1.md
- specs/AnomalyDetection/TASK5.2.md
- specs/AnomalyDetection/TASK5.3.md
- specs/AnomalyDetection/TASK6.1.md
- specs/AnomalyDetection/TASK6.2.md
- specs/AnomalyDetection/TASK6.3.md
- specs/AnomalyDetection/TASKS.md
- specs/ApiServicePostgresTestStability/TASK.md
- specs/BackendDatabaseConsolidation/TASK.md
- specs/BackendDatabaseConsolidation/TASK1.1.md
- specs/BackendDatabaseConsolidation/TASK1.2.md
- specs/BackendDatabaseConsolidation/TASK1.3.md
- specs/BackendDatabaseConsolidation/TASK2.1.md
- specs/BackendDatabaseConsolidation/TASK2.2.md
- specs/BackendDatabaseConsolidation/TASK2.3.md
- specs/BackendDatabaseConsolidation/TASK3.1.md
- specs/BackendDatabaseConsolidation/TASK3.2.md
- specs/BackendDatabaseConsolidation/TASK4.1.md
- specs/BackendDatabaseConsolidation/TASK4.2.md
- specs/BackendDatabaseConsolidation/TASK4.3.md
- specs/BackendDatabaseConsolidation/TASK5.1.md
- specs/BackendDatabaseConsolidation/TASK5.2.md
- specs/BrinkLaborGetShiftsStaging/TASK.md
- specs/BrinkPosOrdersFirstEtlJob/TASK.md
- specs/BrinkPosOrdersFirstEtlJob/TASK0.md
- specs/BrinkPosOrdersFirstEtlJob/TASK1.md
- specs/BrinkPosOrdersFirstEtlJob/TASK2.1.md
- specs/BrinkPosOrdersFirstEtlJob/TASK2.2.md
- specs/BrinkPosOrdersFirstEtlJob/TASK2.3.md
- specs/BrinkPosOrdersFirstEtlJob/TASK2.4.md
- specs/BrinkPosOrdersFirstEtlJob/TASK2.md
- specs/BrinkPosOrdersFirstEtlJob/TASK3.1.md
- specs/BrinkPosOrdersFirstEtlJob/TASK3.2.md
- specs/BrinkPosOrdersFirstEtlJob/TASK3.3.md
- specs/BrinkPosOrdersFirstEtlJob/TASK3.4.md
- specs/BrinkPosOrdersFirstEtlJob/TASK3.md
- specs/BrinkPosOrdersFirstEtlJob/TASK4.1.md
- specs/BrinkPosOrdersFirstEtlJob/TASK4.2.md
- specs/BrinkPosOrdersFirstEtlJob/TASK4.3.md
- specs/BrinkPosOrdersFirstEtlJob/TASK4.4.md
- specs/BrinkPosOrdersFirstEtlJob/TASK4.md
- specs/BrinkPosOrdersFirstEtlJob/TASK5.1.md
- specs/BrinkPosOrdersFirstEtlJob/TASK5.2.md
- specs/BrinkPosOrdersFirstEtlJob/TASK5.3.md
- specs/BrinkPosOrdersFirstEtlJob/TASK5.4.md
- specs/BrinkPosOrdersFirstEtlJob/TASK5.md
- specs/BrinkPosOrdersFirstEtlJob/TASK6.1.md
- specs/BrinkPosOrdersFirstEtlJob/TASK6.2.md
- specs/BrinkPosOrdersFirstEtlJob/TASK6.3.md
- specs/BrinkPosOrdersFirstEtlJob/TASK6.4.md
- specs/BrinkPosOrdersFirstEtlJob/TASK6.md
- specs/BrinkPosOrdersFirstEtlJob/TASK7.md
- specs/BrinkPosOrdersFirstEtlJob/TASK8.md
- specs/BrinkPosOrdersFirstEtlJob/TASK9.md
- specs/BrinkSettings2ToStaging/TASK.MD
- specs/CuratedToS3Stage/TASK.md
- specs/CuratedToS3Stage/TASK0.md
- specs/CuratedToS3Stage/TASK1.md
- specs/CuratedToS3Stage/TASK2.md
- specs/CuratedToS3Stage/TASK3.md
- specs/CuratedToS3Stage/TASK4.md
- specs/CustomerCredentialCustomHeaders/TASK.md
- specs/CustomerCredentialCustomHeaders/TASK1.1.md
- specs/CustomerCredentialCustomHeaders/TASK1.2.md
- specs/CustomerCredentialCustomHeaders/TASK2.1.md
- specs/CustomerCredentialCustomHeaders/TASK2.2.md
- specs/CustomerCredentialCustomHeaders/TASK3.1.md
- specs/CustomerCredentialTriggeredProvisioning/TASK.md
- specs/CustomerCredentialTriggeredProvisioning/TASK1.1.md
- specs/CustomerCredentialTriggeredProvisioning/TASK1.2.md
- specs/CustomerCredentialTriggeredProvisioning/TASK2.1.md
- specs/CustomerCredentialTriggeredProvisioning/TASK2.2.md
- specs/CustomerCredentialTriggeredProvisioning/TASK3.1.md
- specs/CustomerCredentialTriggeredProvisioning/TASK3.2.md
- specs/CustomerCredentialTriggeredProvisioning/TASK4.1.md
- specs/EtlSourceAdapterFramework/TASK.md
- specs/EtlSourceAdapterFramework/TASK0.md
- specs/EtlSourceAdapterFramework/TASK1.md
- specs/EtlSourceAdapterFramework/TASK2.md
- specs/EtlSourceAdapterFramework/TASK3.md
- specs/EtlSourceAdapterFramework/TASK4.md
- specs/EtlSourceAdapterFramework/TASK5.md
- specs/EtlSourceAdapterFramework/TASK6.md
- specs/KdsCdcDebeziumIntegration/TASK.md
- specs/KdsCdcDebeziumIntegration/TASK1.md
- specs/KdsCdcDebeziumIntegration/TASK2.md
- specs/KdsCdcDebeziumIntegration/TASK3.md
- specs/KdsCdcDebeziumIntegration/TASK4.md
- specs/KdsCdcDebeziumIntegration/TASK5.md
- specs/KdsCdcDurableRelationRouting/TASK.md
- specs/KdsCdcDurableRelationRouting/TASK1.md
- specs/KdsCdcDurableRelationRouting/TASK2.md
- specs/KdsCdcDurableRelationRouting/TASK3.md
- specs/KdsCdcDurableRelationRouting/TASK4.md
- specs/KdsCdcDurableRelationRouting/TASK5.md
- specs/KdsCdcIngestion/TASK.md
- specs/KdsCdcIngestion/TASK1.md
- specs/KdsCdcIngestion/TASK2.md
- specs/KdsCdcIngestion/TASK3.md
- specs/KdsCdcIngestion/TASK4.md
- specs/KdsCdcIngestion/TASK5.md
- specs/KdsCdcIngestion/TASK6.md
- specs/KdsCdcIngestion/TASK7.md
- specs/KdsCdcIngestion/TASK8.md
- specs/KdsCdcIngestion/TASK9.md
- specs/KdsCdcReplayExecution/TASK.md
- specs/KdsCdcReplayExecution/TASK1.md
- specs/KdsCdcReplayExecution/TASK2.md
- specs/KdsCdcReplayExecution/TASK3.md
- specs/KdsCdcReplayExecution/TASK4.md
- specs/KdsMonitorServingContractMigration/TASK.md
- specs/KdsMonitorServingContractMigration/TASK1.1.md
- specs/KdsMonitorServingContractMigration/TASK1.2.md
- specs/KdsMonitorServingContractMigration/TASK2.1.md
- specs/KdsMonitorServingContractMigration/TASK2.2.md
- specs/KdsMonitorServingContractMigration/TASK3.1.md
- specs/KdsMonitorServingContractMigration/TASK3.2.md
- specs/RedshiftFoundation/TASK.md
- specs/RedshiftFoundation/TASK1.1.md
- specs/RedshiftFoundation/TASK1.2.md
- specs/RedshiftFoundation/TASK1.3.md
- specs/RedshiftFoundation/TASK1.4.md
- specs/RedshiftFoundation/TASK2.1.md
- specs/RedshiftFoundation/TASK2.2.md
- specs/RedshiftFoundation/TASK3.1.md
- specs/RedshiftFoundation/TASK3.2.md
- specs/RedshiftFoundation/TASK3.3.md
- specs/RedshiftSyntheticDataFeed/TASK.md
- specs/RedshiftSyntheticDataFeed/TASK1.1.md
- specs/RedshiftSyntheticDataFeed/TASK1.2.md
- specs/RedshiftSyntheticDataFeed/TASK1.3.md
- specs/RedshiftSyntheticDataFeed/TASK2.1.md
- specs/RedshiftSyntheticDataFeed/TASK2.2.md
- specs/RedshiftSyntheticDataFeed/TASK3.1.md
- specs/RedshiftSyntheticDataFeed/TASK3.2.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK1.1.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK1.2.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK2.1.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK2.2.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK2.3.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK3.1.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK3.2.md
- specs/SingleStoreRedshiftRuntimeReadPath/TASK4.1.md
TASK 3.3: Create MonitorSpec Seed Data Examples
Summary
Seed example MonitorSpec records using EF Core 9's UseSeeding / UseAsyncSeeding API. All seeding code lives in the Kds.Ai.Data project alongside the DbContext - no separate seeder service or repository is needed. The ExamplePrompts class provides example system prompts as constants for development and testing.
Dependencies
- TASK 1.1 (MonitorSpec entity)
Design Principles
- EF9
UseSeeding/UseAsyncSeeding: The recommended Microsoft approach (introduced in EF Core 9). Seeding callbacks are registered onDbContextOptionsBuilderand run automatically afterEnsureCreated,Migrate, ordotnet ef database update- even if no migrations were applied. The seeding code is protected by the migration locking mechanism to prevent concurrency issues. - Both sync and async: Microsoft requires implementing both
UseSeeding(sync) andUseAsyncSeeding(async). EF Core tooling relies on the synchronous version; runtime code uses the async version. To avoid duplicating logic, the syncSeedmethod delegates toSeedAsyncvia.GetAwaiter().GetResult(). - Idempotent: The callbacks check whether a monitor with the given name already exists before inserting.
- All in
Kds.Ai.Data: Since seeds are for initial testing/development, they live in the Data project next to the DbContext. No cross-project wiring needed. - Example prompts in code: We include a few example system prompts as constants for development and testing. In production, prompts are authored by humans and stored in the database.
Reference: EF9 UseSeeding pattern
From the official Microsoft documentation:
csharp
// UseSeeding and UseAsyncSeeding are set up in the options configuration step:
options
.UseSqlServer(connectionString)
.UseSeeding((context, _) =>
{
var testBlog = context.Set<Blog>().FirstOrDefault(b => b.Url == "http://test.com");
if (testBlog == null)
{
context.Set<Blog>().Add(new Blog { Url = "http://test.com" });
context.SaveChanges();
}
})
.UseAsyncSeeding(async (context, _, cancellationToken) =>
{
var testBlog = await context.Set<Blog>().FirstOrDefaultAsync(
b => b.Url == "http://test.com", cancellationToken);
if (testBlog == null)
{
context.Set<Blog>().Add(new Blog { Url = "http://test.com" });
await context.SaveChangesAsync(cancellationToken);
}
});Key points from the docs:
- The
boolargument of the seed delegate indicates whether any store management operation was performed. - The methods are called as part of
EnsureCreated,Migrate, anddotnet ef database update, even if there are no model changes. - The code is protected by the migration locking mechanism to prevent concurrency issues.
Files to Create
1. backend/Kds.Ai.Data/Seeding/ExamplePrompts.cs
csharp
namespace Kds.Ai.Data.Seeding;
/// <summary>
/// Example system prompts for development and testing.
/// In production, prompts are authored by humans via the UI/CLI.
/// </summary>
public static class ExamplePrompts
{
/// <summary>
/// Example prompt for prep-time anomaly detection on KDSDev orders data.
/// This is NOT compiled into the agent - it is stored as plain text in MonitorSpec.SystemPrompt.
/// </summary>
public const string PrepTimeAnomaly = """
You are a restaurant operations anomaly detector. Your job is to analyze order preparation times and detect anomalies.
## Database
You have access to a MySQL database via the `mysql_query` tool. The key table is `orders` in the KDSDev database:
- `preparation_time` (int, seconds, nullable) - how long the order took to prepare
- `create_time` (int, unix timestamp) - when the order was created
- `store_guid` (varchar) - which store/restaurant
- `items_count` (int) - number of items in the order
- `order_type` (varchar) - type of order (dine-in, takeout, delivery)
- `destination` (varchar) - kitchen station
- `done` (tinyint) - whether the order is complete
- `is_deleted` (tinyint) - soft delete flag
## Analysis Approach
1. Query the last 24 hours of completed orders (done=1, is_deleted=0, preparation_time IS NOT NULL)
2. Aggregate by hour to get hourly average prep times
3. Compare against the historical baseline (same hour of day over the past 28 days)
4. Flag hours where the average prep time deviates significantly (>2 standard deviations)
5. Optionally break down by order_type or destination to find more specific patterns
## Output
When done analyzing, call the `emit_conclusion` tool with your findings.
- Set `anomalyDetected` to true if you found significant deviations
- Set severity: "Low" for minor (2-3σ), "Medium" for moderate (3-4σ), "High" for severe (>4σ)
- Include a clear summary and detailed markdown analysis
- List each anomalous finding with the affected time period and evidence
""";
}2. backend/Kds.Ai.Data/Seeding/MonitorSpecSeeding.cs
Static helper class with the seeding logic. The async method contains the real implementation; the sync version (required by EF Core tooling) delegates to it via GetAwaiter().GetResult():
csharp
using Kds.Ai.Data.Entities;
using Kds.Ai.Data.Enums;
using Microsoft.EntityFrameworkCore;
namespace Kds.Ai.Data.Seeding;
/// <summary>
/// Seeding logic for MonitorSpec records.
/// Called from UseSeeding/UseAsyncSeeding callbacks on DbContextOptionsBuilder.
/// </summary>
public static class MonitorSpecSeeding
{
private static readonly (string Name, string SystemPrompt)[] SeedMonitors =
[
("Prep Time Monitor - Downtown", ExamplePrompts.PrepTimeAnomaly)
];
/// <summary>
/// Synchronous seeding callback for UseSeeding.
/// Required by EF Core tooling (dotnet ef database update).
/// Delegates to the async implementation.
/// </summary>
public static void Seed(KdsAiDbContext context)
{
SeedAsync(context, CancellationToken.None).GetAwaiter().GetResult();
}
/// <summary>
/// Asynchronous seeding callback for UseAsyncSeeding.
/// Contains the actual seeding logic.
/// </summary>
public static async Task SeedAsync(KdsAiDbContext context, CancellationToken cancellationToken)
{
foreach (var (name, systemPrompt) in SeedMonitors)
{
var exists = await context.MonitorSpecs
.AnyAsync(m => m.Name == name, cancellationToken);
if (!exists)
{
context.MonitorSpecs.Add(new MonitorSpec
{
Name = name,
SystemPrompt = systemPrompt,
State = MonitorState.Draft
});
}
}
await context.SaveChangesAsync(cancellationToken);
}
}Files to Modify
3. backend/Kds.Ai.Data/DependencyInjectionExtensions.cs
Wire up UseSeeding / UseAsyncSeeding directly in the AddDataModule method:
csharp
using Kds.Ai.Data.Seeding;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Kds.Ai.Data;
public static class DependencyInjectionExtensions
{
public static IHostApplicationBuilder AddDataModule(this IHostApplicationBuilder builder, string connectionName = "kdsaidb")
{
builder.Services.AddDbContext<KdsAiDbContext>(options =>
{
// we are using default connection string for schema migrations only
var connectionString = builder.Configuration.GetConnectionString(connectionName) ?? "Server=localhost;Database=dummy;";
options.UseMySQL(connectionString);
options
.UseSeeding((context, _) =>
{
if (context is KdsAiDbContext db)
{
MonitorSpecSeeding.Seed(db);
}
})
.UseAsyncSeeding(async (context, _, cancellationToken) =>
{
if (context is KdsAiDbContext db)
{
await MonitorSpecSeeding.SeedAsync(db, cancellationToken);
}
});
});
return builder;
}
}How It Works
- When the application starts,
Migrate()/MigrateAsync()is called (orEnsureCreated). - EF Core runs the
UseSeeding(sync) orUseAsyncSeeding(async) callback automatically. - The callback checks if each named monitor already exists via
Any()/AnyAsync(). - Missing monitors are added with
Draftstate and saved. - The migration locking mechanism prevents concurrent seeding across multiple instances.
Acceptance Criteria
- [ ]
ExamplePromptsclass created inKds.Ai.Data/Seeding/ - [ ] At least one example prompt constant
- [ ]
MonitorSpecSeedingstatic class withSeedAsync(real logic) andSeed(delegates via.GetAwaiter().GetResult()) - [ ] Duplicates prevented by checking name existence before inserting
- [ ]
UseSeeding/UseAsyncSeedingwired inAddDataModule - [ ] No separate seeder service class, no repository dependency for seeding
- [ ] No domain-specific code (no
PrepTimeMonitorSpecFactory, noPrepTimeMonitorConfig) - [ ] No references to
StoreGuidorMonitorType - [ ] Monitors created in
Draftstate by default - [ ] Solution builds without errors
Notes
- The old
PrepTimeMonitorSpecFactoryis completely replaced by this generic approach ExamplePromptsis for dev convenience only - prompts are plain text, not typed models- No
PrepTimeMonitorConfig- configuration is optional free-form JSON, not a typed class - The seeder uses name-based deduplication since MonitorSpec no longer has StoreGuid+MonitorType as a composite key
- EF Core tooling (
dotnet ef) relies on the synchronousUseSeeding- the syncSeeddelegates toSeedAsyncvia.GetAwaiter().GetResult()to avoid duplicating logic - The seeding code is concurrency-safe via EF Core's migration locking mechanism