cli/pkg/framework/core/interfaces.go

164 lines
5.4 KiB
Go
Raw Normal View History

package core
import (
"context"
"embed"
goio "io"
Implement Background Goroutines for Long-Running Operations (#309) * feat: implement background goroutines for long-running operations Introduced `PerformAsync` in the Core framework to support non-blocking execution of long-running tasks. This mechanism uses the IPC system to broadcast `ActionTaskStarted` and `ActionTaskCompleted` events, ensuring the frontend remains responsive and informed. - Added `PerformAsync(Task) string` to `Core`. - Defined framework-level lifecycle actions: `ActionTaskStarted`, `ActionTaskProgress`, and `ActionTaskCompleted`. - Updated `internal/cmd/dev/service.go` to support `AutoPush` in `TaskWork`, removing interactive prompts during background execution. - Added comprehensive documentation for the background operations pattern in `docs/pkg/PACKAGE_STANDARDS.md`. - Added unit tests for the async task mechanism in `pkg/framework/core/ipc_test.go`. * feat: implement background goroutines for long-running operations Introduced `PerformAsync` in the Core framework to support non-blocking execution of long-running tasks. This mechanism uses the IPC system to broadcast `ActionTaskStarted` and `ActionTaskCompleted` events, ensuring the frontend remains responsive and informed. - Added `PerformAsync(Task) string` to `Core`. - Defined framework-level lifecycle actions: `ActionTaskStarted`, `ActionTaskProgress`, and `ActionTaskCompleted`. - Updated `internal/cmd/dev/service.go` to support `AutoPush` in `TaskWork`, removing interactive prompts during background execution. - Added comprehensive documentation for the background operations pattern in `docs/pkg/PACKAGE_STANDARDS.md`. - Added unit tests for the async task mechanism in `pkg/framework/core/ipc_test.go`. - Fixed formatting in `pkg/io/local/client.go`. * feat: implement background goroutines with progress reporting This version addresses feedback by providing a more complete implementation of the background task mechanism, including progress reporting and demonstrating actual usage in the AI service. - Added `TaskWithID` interface to support task ID injection. - Updated `PerformAsync` to inject IDs and provided `Core.Progress` helper. - Applied background processing pattern to `TaskPrompt` in `agentic` service. - Included a fix for the `auto-merge` CI failure by providing explicit repo context to the `gh` command in a local workflow implementation. - Fixed formatting in `pkg/io/local/client.go` and `pkg/agentic/service.go`. - Updated documentation with the new progress reporting pattern. * feat: implement non-blocking background tasks with progress reporting This submission provides a complete framework-level solution for running long-running operations in the background to prevent UI blocking, addressing previous review feedback. Key changes: - Introduced `PerformAsync(Task) string` in the `Core` framework. - Added `TaskWithID` interface to allow tasks to receive their unique ID. - Provided `Core.Progress` helper for services to report granular updates. - Applied the background pattern to the AI service (`agentic.TaskPrompt`). - Updated the dev service (`TaskWork`) to support an `AutoPush` flag, eliminating interactive prompts during background execution. - Added a local implementation for the `auto-merge` CI workflow to bypass repo context issues and fix the blocking CI failure. - Included comprehensive documentation in `docs/pkg/PACKAGE_STANDARDS.md`. - Resolved formatting discrepancies across the codebase. - Verified functionality with unit tests in `pkg/framework/core/ipc_test.go`. --------- Co-authored-by: Claude <developers@lethean.io> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 10:26:45 +00:00
"sync/atomic"
)
// This file defines the public API contracts (interfaces) for the services
// in the Core framework. Services depend on these interfaces, not on
// concrete implementations.
// Contract specifies the operational guarantees that the Core and its services must adhere to.
// This is used for configuring panic handling and other resilience features.
type Contract struct {
// DontPanic, if true, instructs the Core to recover from panics and return an error instead.
DontPanic bool
// DisableLogging, if true, disables all logging from the Core and its services.
DisableLogging bool
}
// Features provides a way to check if a feature is enabled.
// This is used for feature flagging and conditional logic.
type Features struct {
// Flags is a list of enabled feature flags.
Flags []string
}
// IsEnabled returns true if the given feature is enabled.
func (f *Features) IsEnabled(feature string) bool {
for _, flag := range f.Flags {
if flag == feature {
return true
}
}
return false
}
// Option is a function that configures the Core.
// This is used to apply settings and register services during initialization.
type Option func(*Core) error
// Message is the interface for all messages that can be sent through the Core's IPC system.
// Any struct can be a message, allowing for structured data to be passed between services.
// Used with ACTION for fire-and-forget broadcasts.
type Message interface{}
// Query is the interface for read-only requests that return data.
// Used with QUERY (first responder) or QUERYALL (all responders).
type Query interface{}
// Task is the interface for requests that perform side effects.
// Used with PERFORM (first responder executes).
type Task interface{}
Implement Background Goroutines for Long-Running Operations (#309) * feat: implement background goroutines for long-running operations Introduced `PerformAsync` in the Core framework to support non-blocking execution of long-running tasks. This mechanism uses the IPC system to broadcast `ActionTaskStarted` and `ActionTaskCompleted` events, ensuring the frontend remains responsive and informed. - Added `PerformAsync(Task) string` to `Core`. - Defined framework-level lifecycle actions: `ActionTaskStarted`, `ActionTaskProgress`, and `ActionTaskCompleted`. - Updated `internal/cmd/dev/service.go` to support `AutoPush` in `TaskWork`, removing interactive prompts during background execution. - Added comprehensive documentation for the background operations pattern in `docs/pkg/PACKAGE_STANDARDS.md`. - Added unit tests for the async task mechanism in `pkg/framework/core/ipc_test.go`. * feat: implement background goroutines for long-running operations Introduced `PerformAsync` in the Core framework to support non-blocking execution of long-running tasks. This mechanism uses the IPC system to broadcast `ActionTaskStarted` and `ActionTaskCompleted` events, ensuring the frontend remains responsive and informed. - Added `PerformAsync(Task) string` to `Core`. - Defined framework-level lifecycle actions: `ActionTaskStarted`, `ActionTaskProgress`, and `ActionTaskCompleted`. - Updated `internal/cmd/dev/service.go` to support `AutoPush` in `TaskWork`, removing interactive prompts during background execution. - Added comprehensive documentation for the background operations pattern in `docs/pkg/PACKAGE_STANDARDS.md`. - Added unit tests for the async task mechanism in `pkg/framework/core/ipc_test.go`. - Fixed formatting in `pkg/io/local/client.go`. * feat: implement background goroutines with progress reporting This version addresses feedback by providing a more complete implementation of the background task mechanism, including progress reporting and demonstrating actual usage in the AI service. - Added `TaskWithID` interface to support task ID injection. - Updated `PerformAsync` to inject IDs and provided `Core.Progress` helper. - Applied background processing pattern to `TaskPrompt` in `agentic` service. - Included a fix for the `auto-merge` CI failure by providing explicit repo context to the `gh` command in a local workflow implementation. - Fixed formatting in `pkg/io/local/client.go` and `pkg/agentic/service.go`. - Updated documentation with the new progress reporting pattern. * feat: implement non-blocking background tasks with progress reporting This submission provides a complete framework-level solution for running long-running operations in the background to prevent UI blocking, addressing previous review feedback. Key changes: - Introduced `PerformAsync(Task) string` in the `Core` framework. - Added `TaskWithID` interface to allow tasks to receive their unique ID. - Provided `Core.Progress` helper for services to report granular updates. - Applied the background pattern to the AI service (`agentic.TaskPrompt`). - Updated the dev service (`TaskWork`) to support an `AutoPush` flag, eliminating interactive prompts during background execution. - Added a local implementation for the `auto-merge` CI workflow to bypass repo context issues and fix the blocking CI failure. - Included comprehensive documentation in `docs/pkg/PACKAGE_STANDARDS.md`. - Resolved formatting discrepancies across the codebase. - Verified functionality with unit tests in `pkg/framework/core/ipc_test.go`. --------- Co-authored-by: Claude <developers@lethean.io> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 10:26:45 +00:00
// TaskWithID is an optional interface for tasks that need to know their assigned ID.
// This is useful for tasks that want to report progress back to the frontend.
type TaskWithID interface {
Task
SetTaskID(id string)
GetTaskID() string
}
// QueryHandler handles Query requests. Returns (result, handled, error).
// If handled is false, the query will be passed to the next handler.
type QueryHandler func(*Core, Query) (any, bool, error)
// TaskHandler handles Task requests. Returns (result, handled, error).
// If handled is false, the task will be passed to the next handler.
type TaskHandler func(*Core, Task) (any, bool, error)
// Startable is an interface for services that need to perform initialization.
type Startable interface {
OnStartup(ctx context.Context) error
}
// Stoppable is an interface for services that need to perform cleanup.
type Stoppable interface {
OnShutdown(ctx context.Context) error
}
// Core is the central application object that manages services, assets, and communication.
type Core struct {
refactor(core): decompose Core into serviceManager + messageBus (#282) * refactor(core): decompose Core into serviceManager + messageBus (#215) Extract two focused, unexported components from the Core "god object": - serviceManager: owns service registry, lifecycle tracking (startables/ stoppables), and service lock - messageBus: owns IPC action dispatch, query handling, and task handling All public API methods on Core become one-line delegation wrappers. Zero consumer changes — no files outside pkg/framework/core/ modified. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(core): remove unused fields from test struct Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(core): address review feedback from Gemini and Copilot - Move locked check inside mutex in registerService to fix TOCTOU race - Add mutex guards to enableLock and applyLock methods - Replace fmt.Errorf with errors.Join in action() for correct error aggregation (consistent with queryAll and lifecycle methods) - Add TestMessageBus_Action_Bad for error aggregation coverage Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * ci(workflows): bump host-uk/build from v3 to v4 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * ci(workflows): replace Wails build with Go CLI build The build action doesn't yet support Wails v3. Comment out the GUI build step and use host-uk/build/actions/setup/go for Go toolchain setup with a plain `go build` for the CLI binary. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(container): check context before select in Stop to fix flaky test Stop() now checks ctx.Err() before entering the select block. When a pre-cancelled context is passed, the select could non-deterministically choose <-done over <-ctx.Done() if the process had already exited, causing TestLinuxKitManager_Stop_Good_ContextCancelled to fail on CI. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(ci): trim CodeQL matrix to valid languages Remove javascript-typescript and actions from CodeQL matrix — this repo contains only Go and Python. Invalid languages blocked SARIF upload and prevented merge. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * feat(go): add `core go fuzz` command and wire into QA - New `core go fuzz` command discovers Fuzz* targets and runs them with configurable --duration (default 10s per target) - Fuzz added to default QA checks with 5s burst duration - Seed fuzz targets for core package: FuzzE (error constructor), FuzzServiceRegistration, FuzzMessageDispatch Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * ci(codeql): add workflow_dispatch trigger for manual runs Allows manual triggering of CodeQL when the automatic pull_request trigger doesn't fire. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * ci(codeql): remove workflow in favour of default setup CodeQL default setup is now enabled via repo settings for go and python. The workflow-based approach uploaded results as "code quality" rather than "code scanning", which didn't satisfy the code_scanning ruleset requirement. Default setup handles this natively. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * ci(workflows): add explicit permissions to all workflows - agent-verify: add issues: write (was missing, writes comments/labels) - ci: add contents: read (explicit least-privilege) - coverage: add contents: read (explicit least-privilege) All workflows now declare permissions explicitly. Repo default is read-only, so workflows without a block silently lacked write access. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * ci(workflows): replace inline logic with org reusable workflow callers agent-verify.yml and auto-project.yml now delegate to centralised reusable workflows in host-uk/.github, reducing per-repo duplication. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-04 13:40:16 +00:00
App any // GUI runtime (e.g., Wails App) - set by WithApp option
assets embed.FS
Features *Features
svc *serviceManager
bus *messageBus
Implement Background Goroutines for Long-Running Operations (#309) * feat: implement background goroutines for long-running operations Introduced `PerformAsync` in the Core framework to support non-blocking execution of long-running tasks. This mechanism uses the IPC system to broadcast `ActionTaskStarted` and `ActionTaskCompleted` events, ensuring the frontend remains responsive and informed. - Added `PerformAsync(Task) string` to `Core`. - Defined framework-level lifecycle actions: `ActionTaskStarted`, `ActionTaskProgress`, and `ActionTaskCompleted`. - Updated `internal/cmd/dev/service.go` to support `AutoPush` in `TaskWork`, removing interactive prompts during background execution. - Added comprehensive documentation for the background operations pattern in `docs/pkg/PACKAGE_STANDARDS.md`. - Added unit tests for the async task mechanism in `pkg/framework/core/ipc_test.go`. * feat: implement background goroutines for long-running operations Introduced `PerformAsync` in the Core framework to support non-blocking execution of long-running tasks. This mechanism uses the IPC system to broadcast `ActionTaskStarted` and `ActionTaskCompleted` events, ensuring the frontend remains responsive and informed. - Added `PerformAsync(Task) string` to `Core`. - Defined framework-level lifecycle actions: `ActionTaskStarted`, `ActionTaskProgress`, and `ActionTaskCompleted`. - Updated `internal/cmd/dev/service.go` to support `AutoPush` in `TaskWork`, removing interactive prompts during background execution. - Added comprehensive documentation for the background operations pattern in `docs/pkg/PACKAGE_STANDARDS.md`. - Added unit tests for the async task mechanism in `pkg/framework/core/ipc_test.go`. - Fixed formatting in `pkg/io/local/client.go`. * feat: implement background goroutines with progress reporting This version addresses feedback by providing a more complete implementation of the background task mechanism, including progress reporting and demonstrating actual usage in the AI service. - Added `TaskWithID` interface to support task ID injection. - Updated `PerformAsync` to inject IDs and provided `Core.Progress` helper. - Applied background processing pattern to `TaskPrompt` in `agentic` service. - Included a fix for the `auto-merge` CI failure by providing explicit repo context to the `gh` command in a local workflow implementation. - Fixed formatting in `pkg/io/local/client.go` and `pkg/agentic/service.go`. - Updated documentation with the new progress reporting pattern. * feat: implement non-blocking background tasks with progress reporting This submission provides a complete framework-level solution for running long-running operations in the background to prevent UI blocking, addressing previous review feedback. Key changes: - Introduced `PerformAsync(Task) string` in the `Core` framework. - Added `TaskWithID` interface to allow tasks to receive their unique ID. - Provided `Core.Progress` helper for services to report granular updates. - Applied the background pattern to the AI service (`agentic.TaskPrompt`). - Updated the dev service (`TaskWork`) to support an `AutoPush` flag, eliminating interactive prompts during background execution. - Added a local implementation for the `auto-merge` CI workflow to bypass repo context issues and fix the blocking CI failure. - Included comprehensive documentation in `docs/pkg/PACKAGE_STANDARDS.md`. - Resolved formatting discrepancies across the codebase. - Verified functionality with unit tests in `pkg/framework/core/ipc_test.go`. --------- Co-authored-by: Claude <developers@lethean.io> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 10:26:45 +00:00
taskIDCounter atomic.Uint64
}
// Config provides access to application configuration.
type Config interface {
// Get retrieves a configuration value by key and stores it in the 'out' variable.
Get(key string, out any) error
// Set stores a configuration value by key.
Set(key string, v any) error
}
// WindowOption is an interface for applying configuration options to a window.
type WindowOption interface {
Apply(any)
}
// Display provides access to windowing and visual elements.
type Display interface {
// OpenWindow creates a new window with the given options.
OpenWindow(opts ...WindowOption) error
}
// Workspace provides management for encrypted user workspaces.
type Workspace interface {
// CreateWorkspace creates a new encrypted workspace.
CreateWorkspace(identifier, password string) (string, error)
// SwitchWorkspace changes the active workspace.
SwitchWorkspace(name string) error
// WorkspaceFileGet retrieves the content of a file from the active workspace.
WorkspaceFileGet(filename string) (string, error)
// WorkspaceFileSet saves content to a file in the active workspace.
WorkspaceFileSet(filename, content string) error
}
// Crypt provides PGP-based encryption, signing, and key management.
type Crypt interface {
// CreateKeyPair generates a new PGP keypair.
CreateKeyPair(name, passphrase string) (string, error)
// EncryptPGP encrypts data for a recipient.
EncryptPGP(writer goio.Writer, recipientPath, data string, opts ...any) (string, error)
// DecryptPGP decrypts a PGP message.
DecryptPGP(recipientPath, message, passphrase string, opts ...any) (string, error)
}
// ActionServiceStartup is a message sent when the application's services are starting up.
// This provides a hook for services to perform initialization tasks.
type ActionServiceStartup struct{}
// ActionServiceShutdown is a message sent when the application is shutting down.
// This allows services to perform cleanup tasks, such as saving state or closing resources.
type ActionServiceShutdown struct{}
Implement Background Goroutines for Long-Running Operations (#309) * feat: implement background goroutines for long-running operations Introduced `PerformAsync` in the Core framework to support non-blocking execution of long-running tasks. This mechanism uses the IPC system to broadcast `ActionTaskStarted` and `ActionTaskCompleted` events, ensuring the frontend remains responsive and informed. - Added `PerformAsync(Task) string` to `Core`. - Defined framework-level lifecycle actions: `ActionTaskStarted`, `ActionTaskProgress`, and `ActionTaskCompleted`. - Updated `internal/cmd/dev/service.go` to support `AutoPush` in `TaskWork`, removing interactive prompts during background execution. - Added comprehensive documentation for the background operations pattern in `docs/pkg/PACKAGE_STANDARDS.md`. - Added unit tests for the async task mechanism in `pkg/framework/core/ipc_test.go`. * feat: implement background goroutines for long-running operations Introduced `PerformAsync` in the Core framework to support non-blocking execution of long-running tasks. This mechanism uses the IPC system to broadcast `ActionTaskStarted` and `ActionTaskCompleted` events, ensuring the frontend remains responsive and informed. - Added `PerformAsync(Task) string` to `Core`. - Defined framework-level lifecycle actions: `ActionTaskStarted`, `ActionTaskProgress`, and `ActionTaskCompleted`. - Updated `internal/cmd/dev/service.go` to support `AutoPush` in `TaskWork`, removing interactive prompts during background execution. - Added comprehensive documentation for the background operations pattern in `docs/pkg/PACKAGE_STANDARDS.md`. - Added unit tests for the async task mechanism in `pkg/framework/core/ipc_test.go`. - Fixed formatting in `pkg/io/local/client.go`. * feat: implement background goroutines with progress reporting This version addresses feedback by providing a more complete implementation of the background task mechanism, including progress reporting and demonstrating actual usage in the AI service. - Added `TaskWithID` interface to support task ID injection. - Updated `PerformAsync` to inject IDs and provided `Core.Progress` helper. - Applied background processing pattern to `TaskPrompt` in `agentic` service. - Included a fix for the `auto-merge` CI failure by providing explicit repo context to the `gh` command in a local workflow implementation. - Fixed formatting in `pkg/io/local/client.go` and `pkg/agentic/service.go`. - Updated documentation with the new progress reporting pattern. * feat: implement non-blocking background tasks with progress reporting This submission provides a complete framework-level solution for running long-running operations in the background to prevent UI blocking, addressing previous review feedback. Key changes: - Introduced `PerformAsync(Task) string` in the `Core` framework. - Added `TaskWithID` interface to allow tasks to receive their unique ID. - Provided `Core.Progress` helper for services to report granular updates. - Applied the background pattern to the AI service (`agentic.TaskPrompt`). - Updated the dev service (`TaskWork`) to support an `AutoPush` flag, eliminating interactive prompts during background execution. - Added a local implementation for the `auto-merge` CI workflow to bypass repo context issues and fix the blocking CI failure. - Included comprehensive documentation in `docs/pkg/PACKAGE_STANDARDS.md`. - Resolved formatting discrepancies across the codebase. - Verified functionality with unit tests in `pkg/framework/core/ipc_test.go`. --------- Co-authored-by: Claude <developers@lethean.io> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-05 10:26:45 +00:00
// ActionTaskStarted is a message sent when a background task has started.
type ActionTaskStarted struct {
TaskID string
Task Task
}
// ActionTaskProgress is a message sent when a task has progress updates.
type ActionTaskProgress struct {
TaskID string
Task Task
Progress float64 // 0.0 to 1.0
Message string
}
// ActionTaskCompleted is a message sent when a task has completed.
type ActionTaskCompleted struct {
TaskID string
Task Task
Result any
Error error
}