Replaced fmt, strings, sort, os, io, sync, encoding/json, path/filepath, errors, log, reflect with core.Sprintf, core.E, core.Contains, core.Trim, core.Split, core.Join, core.JoinPath, slices.Sort, c.Fs(), c.Lock(), core.JSONMarshal, core.ReadAll and other CoreGO v0.8.0 primitives. Framework boundary exceptions preserved where stdlib types are required by external interfaces (Gin, net/http, CGo, Wails, bubbletea). Co-Authored-By: Virgil <virgil@lethean.io>
101 lines
3.6 KiB
Go
101 lines
3.6 KiB
Go
// SPDX-License-Identifier: EUPL-1.2
|
|
|
|
package agentic
|
|
|
|
import (
|
|
"context"
|
|
|
|
core "dappco.re/go/core"
|
|
coremcp "dappco.re/go/mcp/pkg/mcp"
|
|
"github.com/modelcontextprotocol/go-sdk/mcp"
|
|
)
|
|
|
|
// version := agentic.PromptVersionOutput{Success: true, Snapshot: agentic.PromptVersionSnapshot{Hash: "..." }}
|
|
type PromptVersionOutput struct {
|
|
Success bool `json:"success"`
|
|
Workspace string `json:"workspace"`
|
|
Snapshot PromptVersionSnapshot `json:"snapshot"`
|
|
}
|
|
|
|
// prompt := agentic.Prompt{Name: "coding", Category: "workspace"}
|
|
type Prompt struct {
|
|
ID int `json:"id"`
|
|
Name string `json:"name"`
|
|
Category string `json:"category,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
SystemPrompt string `json:"system_prompt,omitempty"`
|
|
UserTemplate string `json:"user_template,omitempty"`
|
|
Variables map[string]any `json:"variables,omitempty"`
|
|
Model string `json:"model,omitempty"`
|
|
ModelConfig map[string]any `json:"model_config,omitempty"`
|
|
IsActive bool `json:"is_active,omitempty"`
|
|
}
|
|
|
|
// version := agentic.PromptVersion{Name: "coding", Version: 3}
|
|
type PromptVersion struct {
|
|
ID int `json:"id"`
|
|
PromptID int `json:"prompt_id"`
|
|
Version int `json:"version"`
|
|
SystemPrompt string `json:"system_prompt,omitempty"`
|
|
UserTemplate string `json:"user_template,omitempty"`
|
|
Variables map[string]any `json:"variables,omitempty"`
|
|
CreatedBy string `json:"created_by,omitempty"`
|
|
CreatedAt string `json:"created_at,omitempty"`
|
|
}
|
|
|
|
// input := agentic.PromptVersionInput{Workspace: "/srv/.core/workspace/core/go-io/task-42"}
|
|
type PromptVersionInput struct {
|
|
Workspace string `json:"workspace"`
|
|
}
|
|
|
|
// result := c.Action("agentic.prompt.version").Run(ctx, core.NewOptions(
|
|
//
|
|
// core.Option{Key: "workspace", Value: "/srv/.core/workspace/core/go-io/task-42"},
|
|
//
|
|
// ))
|
|
func (s *PrepSubsystem) handlePromptVersion(ctx context.Context, options core.Options) core.Result {
|
|
workspace := optionStringValue(options, "workspace", "_arg")
|
|
_, output, err := s.promptVersion(ctx, nil, workspace)
|
|
if err != nil {
|
|
return core.Result{Value: err, OK: false}
|
|
}
|
|
return core.Result{Value: output, OK: true}
|
|
}
|
|
|
|
func (s *PrepSubsystem) promptVersion(_ context.Context, _ *mcp.CallToolRequest, workspace string) (*mcp.CallToolResult, PromptVersionOutput, error) {
|
|
workspaceDir := s.resolveWorkspaceDir(workspace)
|
|
if workspaceDir == "" {
|
|
return nil, PromptVersionOutput{}, core.E("promptVersion", "workspace is required", nil)
|
|
}
|
|
|
|
snapshot, err := readPromptSnapshot(workspaceDir)
|
|
if err != nil {
|
|
return nil, PromptVersionOutput{}, err
|
|
}
|
|
|
|
return nil, PromptVersionOutput{
|
|
Success: true,
|
|
Workspace: workspace,
|
|
Snapshot: snapshot,
|
|
}, nil
|
|
}
|
|
|
|
func (s *PrepSubsystem) registerPromptTools(svc *coremcp.Service) {
|
|
coremcp.AddToolRecorded(svc, svc.Server(), "agentic", &mcp.Tool{
|
|
Name: "prompt_version",
|
|
Description: "Read the current prompt snapshot for a workspace.",
|
|
}, s.promptVersionTool)
|
|
|
|
coremcp.AddToolRecorded(svc, svc.Server(), "agentic", &mcp.Tool{
|
|
Name: "agentic_prompt_version",
|
|
Description: "Read the current prompt snapshot for a workspace.",
|
|
}, s.promptVersionTool)
|
|
}
|
|
|
|
func (s *PrepSubsystem) promptVersionTool(ctx context.Context, _ *mcp.CallToolRequest, input PromptVersionInput) (*mcp.CallToolResult, PromptVersionOutput, error) {
|
|
if core.Trim(input.Workspace) == "" {
|
|
return nil, PromptVersionOutput{}, core.E("promptVersion", "workspace is required", nil)
|
|
}
|
|
|
|
return s.promptVersion(ctx, nil, input.Workspace)
|
|
}
|