2026-01-30 09:19:20 +00:00
|
|
|
package agentic
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"os"
|
|
|
|
|
"os/exec"
|
2026-01-30 10:18:54 +00:00
|
|
|
"strings"
|
2026-01-30 09:19:20 +00:00
|
|
|
|
|
|
|
|
"github.com/host-uk/core/pkg/framework"
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-30 10:18:54 +00:00
|
|
|
// Tasks for AI service
|
2026-01-30 09:19:20 +00:00
|
|
|
|
2026-01-30 10:18:54 +00:00
|
|
|
// TaskCommit requests Claude to create a commit.
|
|
|
|
|
type TaskCommit struct {
|
2026-01-30 09:19:20 +00:00
|
|
|
Path string
|
|
|
|
|
Name string
|
|
|
|
|
CanEdit bool // allow Write/Edit tools
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 10:18:54 +00:00
|
|
|
// TaskPrompt sends a custom prompt to Claude.
|
|
|
|
|
type TaskPrompt struct {
|
2026-01-30 09:19:20 +00:00
|
|
|
Prompt string
|
|
|
|
|
WorkDir string
|
|
|
|
|
AllowedTools []string
|
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
|
|
|
|
|
|
|
|
taskID string
|
2026-01-30 09:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
func (t *TaskPrompt) SetTaskID(id string) { t.taskID = id }
|
|
|
|
|
func (t *TaskPrompt) GetTaskID() string { return t.taskID }
|
|
|
|
|
|
2026-01-30 09:19:20 +00:00
|
|
|
// ServiceOptions for configuring the AI service.
|
|
|
|
|
type ServiceOptions struct {
|
|
|
|
|
DefaultTools []string
|
2026-01-30 10:18:54 +00:00
|
|
|
AllowEdit bool // global permission for Write/Edit tools
|
2026-01-30 09:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DefaultServiceOptions returns sensible defaults.
|
|
|
|
|
func DefaultServiceOptions() ServiceOptions {
|
|
|
|
|
return ServiceOptions{
|
|
|
|
|
DefaultTools: []string{"Bash", "Read", "Glob", "Grep"},
|
2026-01-30 10:18:54 +00:00
|
|
|
AllowEdit: false,
|
2026-01-30 09:19:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Service provides AI/Claude operations as a Core service.
|
|
|
|
|
type Service struct {
|
|
|
|
|
*framework.ServiceRuntime[ServiceOptions]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewService creates an AI service factory.
|
|
|
|
|
func NewService(opts ServiceOptions) func(*framework.Core) (any, error) {
|
|
|
|
|
return func(c *framework.Core) (any, error) {
|
|
|
|
|
return &Service{
|
|
|
|
|
ServiceRuntime: framework.NewServiceRuntime(c, opts),
|
|
|
|
|
}, nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 10:18:54 +00:00
|
|
|
// OnStartup registers task handlers.
|
2026-01-30 09:19:20 +00:00
|
|
|
func (s *Service) OnStartup(ctx context.Context) error {
|
2026-01-30 10:18:54 +00:00
|
|
|
s.Core().RegisterTask(s.handleTask)
|
2026-01-30 09:19:20 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 10:18:54 +00:00
|
|
|
func (s *Service) handleTask(c *framework.Core, t framework.Task) (any, bool, error) {
|
|
|
|
|
switch m := t.(type) {
|
|
|
|
|
case TaskCommit:
|
|
|
|
|
err := s.doCommit(m)
|
|
|
|
|
return nil, true, err
|
|
|
|
|
|
|
|
|
|
case TaskPrompt:
|
|
|
|
|
err := s.doPrompt(m)
|
|
|
|
|
return nil, true, err
|
2026-01-30 09:19:20 +00:00
|
|
|
}
|
2026-01-30 10:18:54 +00:00
|
|
|
return nil, false, nil
|
2026-01-30 09:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-30 10:18:54 +00:00
|
|
|
func (s *Service) doCommit(task TaskCommit) error {
|
2026-01-30 09:19:20 +00:00
|
|
|
prompt := Prompt("commit")
|
|
|
|
|
|
2026-01-30 10:18:54 +00:00
|
|
|
tools := []string{"Bash", "Read", "Glob", "Grep"}
|
|
|
|
|
if task.CanEdit {
|
|
|
|
|
tools = []string{"Bash", "Read", "Write", "Edit", "Glob", "Grep"}
|
2026-01-30 09:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-30 10:18:54 +00:00
|
|
|
cmd := exec.CommandContext(context.Background(), "claude", "-p", prompt, "--allowedTools", strings.Join(tools, ","))
|
|
|
|
|
cmd.Dir = task.Path
|
2026-01-30 09:19:20 +00:00
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
cmd.Stdin = os.Stdin
|
|
|
|
|
|
|
|
|
|
return cmd.Run()
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 10:18:54 +00:00
|
|
|
func (s *Service) doPrompt(task TaskPrompt) error {
|
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
|
|
|
if task.taskID != "" {
|
|
|
|
|
s.Core().Progress(task.taskID, 0.1, "Starting Claude...", &task)
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 10:18:54 +00:00
|
|
|
opts := s.Opts()
|
|
|
|
|
tools := opts.DefaultTools
|
|
|
|
|
if len(tools) == 0 {
|
|
|
|
|
tools = []string{"Bash", "Read", "Glob", "Grep"}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(task.AllowedTools) > 0 {
|
|
|
|
|
tools = task.AllowedTools
|
2026-01-30 09:19:20 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-30 10:18:54 +00:00
|
|
|
cmd := exec.CommandContext(context.Background(), "claude", "-p", task.Prompt, "--allowedTools", strings.Join(tools, ","))
|
|
|
|
|
if task.WorkDir != "" {
|
|
|
|
|
cmd.Dir = task.WorkDir
|
2026-01-30 09:19:20 +00:00
|
|
|
}
|
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
|
cmd.Stderr = os.Stderr
|
|
|
|
|
cmd.Stdin = os.Stdin
|
|
|
|
|
|
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
|
|
|
if task.taskID != "" {
|
|
|
|
|
s.Core().Progress(task.taskID, 0.5, "Running Claude prompt...", &task)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := cmd.Run()
|
|
|
|
|
|
|
|
|
|
if task.taskID != "" {
|
|
|
|
|
if err != nil {
|
|
|
|
|
s.Core().Progress(task.taskID, 1.0, "Failed: "+err.Error(), &task)
|
|
|
|
|
} else {
|
|
|
|
|
s.Core().Progress(task.taskID, 1.0, "Completed", &task)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err
|
2026-01-30 09:19:20 +00:00
|
|
|
}
|