2026-03-16 11:10:33 +00:00
|
|
|
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
|
|
|
|
|
|
package agentic
|
|
|
|
|
|
|
|
|
|
import (
|
feat(v0.8.0): full AX migration — ServiceRuntime, Actions, quality gates, transport
go-process:
- Register factory, Result lifecycle, 5 named Action handlers
- Start/Run/StartWithOptions/RunWithOptions all return core.Result
- core.ID() replaces fmt.Sprintf, core.As replaces errors.As
core/agent:
- PrepSubsystem + monitor.Subsystem + setup.Service embed ServiceRuntime[T]
- 22 named Actions + agent.completion Task pipeline in OnStartup
- ChannelNotifier removed — all IPC via c.ACTION(messages.X{})
- proc.go: all methods via s.Core().Process(), returns core.Result
- status.go: WriteAtomic + JSONMarshalString
- paths.go: Fs.NewUnrestricted() replaces unsafe.Pointer
- transport.go: ONE net/http file — HTTPGet/HTTPPost/HTTPDo/MCP transport
- All disallowed imports eliminated from source files (13 quality gates)
- String concat eliminated — core.Concat() throughout
- 1:1 _test.go + _example_test.go for every source file
- Reference docs synced from core/go v0.8.0
- RFC-025 updated with net/http, net/url, io/fs quality gates
- lib.go: io/fs eliminated via Data.ListNames, Array[T].Deduplicate
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-26 01:27:46 +00:00
|
|
|
"context"
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
|
|
|
|
|
core "dappco.re/go/core"
|
2026-03-16 11:10:33 +00:00
|
|
|
)
|
|
|
|
|
|
2026-03-30 21:22:54 +00:00
|
|
|
func (s *PrepSubsystem) ingestFindings(workspaceDir string) {
|
|
|
|
|
statusResult := ReadStatusResult(workspaceDir)
|
2026-03-30 20:45:23 +00:00
|
|
|
workspaceStatus, ok := workspaceStatusValue(statusResult)
|
|
|
|
|
if !ok || workspaceStatus.Status != "completed" {
|
2026-03-16 11:10:33 +00:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 21:22:54 +00:00
|
|
|
logFiles := workspaceLogFiles(workspaceDir)
|
2026-03-16 11:10:33 +00:00
|
|
|
if len(logFiles) == 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 20:45:23 +00:00
|
|
|
logResult := fs.Read(logFiles[0])
|
|
|
|
|
if !logResult.OK || len(logResult.Value.(string)) < 100 {
|
2026-03-16 11:10:33 +00:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 20:45:23 +00:00
|
|
|
logBody := logResult.Value.(string)
|
2026-03-16 11:10:33 +00:00
|
|
|
|
2026-03-30 20:45:23 +00:00
|
|
|
if core.Contains(logBody, "QUOTA_EXHAUSTED") || core.Contains(logBody, "QuotaError") {
|
2026-03-16 11:10:33 +00:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 20:45:23 +00:00
|
|
|
findings := countFileRefs(logBody)
|
2026-03-16 11:10:33 +00:00
|
|
|
if findings < 2 {
|
2026-03-30 20:45:23 +00:00
|
|
|
return
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
issueType := "task"
|
|
|
|
|
priority := "normal"
|
2026-03-30 20:45:23 +00:00
|
|
|
if core.Contains(logBody, "security") || core.Contains(logBody, "Security") {
|
2026-03-16 11:10:33 +00:00
|
|
|
issueType = "bug"
|
|
|
|
|
priority = "high"
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 20:45:23 +00:00
|
|
|
title := core.Sprintf("Scan findings for %s (%d items)", workspaceStatus.Repo, findings)
|
2026-03-16 11:10:33 +00:00
|
|
|
|
2026-03-30 20:45:23 +00:00
|
|
|
issueDescription := logBody
|
|
|
|
|
if len(issueDescription) > 10000 {
|
|
|
|
|
issueDescription = core.Concat(issueDescription[:10000], "\n\n... (truncated, see full log in workspace)")
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
2026-03-30 20:45:23 +00:00
|
|
|
s.createIssueViaAPI(title, issueDescription, issueType, priority)
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func countFileRefs(body string) int {
|
|
|
|
|
count := 0
|
|
|
|
|
for i := 0; i < len(body)-5; i++ {
|
|
|
|
|
if body[i] == '`' {
|
|
|
|
|
j := i + 1
|
|
|
|
|
for j < len(body) && body[j] != '`' && j-i < 100 {
|
|
|
|
|
j++
|
|
|
|
|
}
|
|
|
|
|
if j < len(body) && body[j] == '`' {
|
|
|
|
|
ref := body[i+1 : j]
|
refactor: migrate core/agent to Core primitives — reference implementation
Phase 1: go-io/go-log → core.Fs{}, core.E(), core.Error/Info/Warn
Phase 2: strings/fmt → core.Contains, core.Sprintf, core.Split etc
Phase 3: embed.FS → core.Mount/core.Embed, core.Extract
Phase 4: cmd/main.go → core.Command(), c.Cli().Run(), no cli package
All packages migrated:
- pkg/lib (Codex): core.Mount, core.Extract, Result returns, AX comments
- pkg/setup (Codex): core.Fs, core.E, fixed missing lib helpers
- pkg/brain (Codex): Core primitives, AX comments
- pkg/monitor (Codex): Core string/logging primitives
- pkg/agentic (Codex): 20 files, Core primitives throughout
- cmd/main.go: pure Core CLI, no fmt/log/filepath/strings/cli
Remaining stdlib: path/filepath (Core doesn't wrap OS paths),
fmt.Sscanf/strings.Map (no Core equivalent).
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 06:13:41 +00:00
|
|
|
if core.Contains(ref, ".go:") || core.Contains(ref, ".php:") {
|
2026-03-16 11:10:33 +00:00
|
|
|
count++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 20:45:23 +00:00
|
|
|
func (s *PrepSubsystem) createIssueViaAPI(title, description, issueType, priority string) {
|
2026-03-16 11:10:33 +00:00
|
|
|
if s.brainKey == "" {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-30 20:45:23 +00:00
|
|
|
apiKeyResult := fs.Read(core.JoinPath(HomeDir(), ".claude", "agent-api.key"))
|
|
|
|
|
if !apiKeyResult.OK {
|
2026-03-16 11:10:33 +00:00
|
|
|
return
|
|
|
|
|
}
|
2026-03-30 20:45:23 +00:00
|
|
|
apiKey := core.Trim(apiKeyResult.Value.(string))
|
2026-03-16 11:10:33 +00:00
|
|
|
|
2026-03-30 20:45:23 +00:00
|
|
|
issuePayload := core.JSONMarshalString(map[string]string{
|
2026-03-16 11:10:33 +00:00
|
|
|
"title": title,
|
|
|
|
|
"description": description,
|
|
|
|
|
"type": issueType,
|
|
|
|
|
"priority": priority,
|
|
|
|
|
"reporter": "cladius",
|
|
|
|
|
})
|
|
|
|
|
|
2026-03-30 20:45:23 +00:00
|
|
|
HTTPPost(context.Background(), core.Concat(s.brainURL, "/v1/issues"), issuePayload, apiKey, "Bearer")
|
2026-03-16 11:10:33 +00:00
|
|
|
}
|