package main import ( "context" "encoding/json" "flag" "fmt" "os" "time" "git.cin.su/m/Assistant/adapters/postgres" "git.cin.su/m/Assistant/contracts/work" "git.cin.su/m/Assistant/modules/work/application" "git.cin.su/m/Assistant/modules/work/ports" ) type memoryStore struct{ writes int } func (s *memoryStore) SaveDispatchIntent(context.Context, work.AgentDispatchIntent) error { s.writes++ return nil } func (s *memoryStore) SaveAgentLease(context.Context, work.AgentLease) error { s.writes++; return nil } func (s *memoryStore) AcceptAgentCallback(context.Context, work.AgentCallback) error { s.writes++ return nil } func main() { enabled := flag.Bool("enable-canary", false, "explicitly enable the manual canary") implementation := flag.String("implementation", "fake-worker", "allowlisted deterministic implementation") postgresMode := flag.Bool("postgres", false, "use the Work PostgreSQL repository instead of in-memory storage") flag.Parse() now := time.UnixMilli(1_700_000_000_000) intent := work.AgentDispatchIntent{DispatchID: "manual-dispatch-1", IdempotencyKey: "manual-idempotency-1", DelegationID: "manual-delegation-1", RunID: "manual-run-1", ImplementationID: *implementation, ImplementationRevision: 1, SourceRevision: "manual-source-1", WorktreeID: "manual-worktree-1", VerificationPlanRef: "manual-verification-1", CreatedAtUnixMillis: now.UnixMilli()} var store ports.ExecutionStore = &memoryStore{} var closeStore func() if *postgresMode { repository, err := postgres.OpenWork(context.Background(), postgres.ContinuityConfig{Host: os.Getenv("POSTGRES_HOST"), Port: os.Getenv("POSTGRES_PORT"), Database: os.Getenv("POSTGRES_DATABASE"), User: os.Getenv("WORK_POSTGRES_USER"), Password: os.Getenv("WORK_POSTGRES_PASSWORD")}) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } store = repository closeStore = repository.Close } if closeStore != nil { defer closeStore() } result, err := application.ExecuteCanaryDryRun(context.Background(), store, application.CanaryConfig{Enabled: *enabled, ImplementationID: "fake-worker", MaxDispatches: 1}, 0, intent, "manual-worker", 1, now, 15*time.Minute) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } output := struct { DispatchID string `json:"dispatch_id"` RunID string `json:"run_id"` CallbackCount int `json:"callback_count"` StoreWrites int `json:"store_writes"` }{result.Intent.DispatchID, string(result.Intent.RunID), result.CallbackCount(), 0} if memory, ok := store.(*memoryStore); ok { output.StoreWrites = memory.writes } if err := json.NewEncoder(os.Stdout).Encode(output); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } }