175 lines
6.3 KiB
Go
175 lines
6.3 KiB
Go
// Package auggie implements the Auggie (Augment Code) agent adapter: launching
|
|
// new headless Auggie sessions and resuming sessions when a native Auggie
|
|
// session id is known.
|
|
//
|
|
// Auggie is Augment Code's terminal coding agent (binary "auggie", installed via
|
|
// `npm install -g @augmentcode/auggie`). It exposes a headless one-shot mode via
|
|
// `--print` (alias `-p`) which runs a single instruction and exits -- the mode AO
|
|
// uses to drive it unattended.
|
|
//
|
|
// Launch shape:
|
|
//
|
|
// auggie --print [--rules <f>] [-- <prompt>]
|
|
//
|
|
// The prompt is the print-mode positional, passed after `--` so a prompt
|
|
// beginning with "-" is not mistaken for a flag. A system prompt, when supplied
|
|
// as an AO-owned file, is injected via Auggie's `--rules` flag, which appends
|
|
// guidance to the workspace rules.
|
|
//
|
|
// Permissions: Auggie has no single "approve everything" flag. It governs
|
|
// unattended tool/file approval through granular `--permission <tool>:<allow|deny>`
|
|
// rules (and a read-only `--ask` mode), not a 4-mode bypass like Claude Code.
|
|
// Because there is no verifiable blanket auto-approve flag, every AO permission
|
|
// mode emits no flag and defers to the user's Auggie configuration, rather than
|
|
// guessing a flag that does not exist.
|
|
//
|
|
// Resume: Auggie supports `--resume <sessionId>` (alias `-r`), usable with
|
|
// `--print` for headless resume. AO only has a native session id to resume from
|
|
// when one was captured into session metadata; Auggie exposes no hook/lifecycle
|
|
// system, so that id is not captured automatically yet. GetRestoreCommand
|
|
// therefore returns ok=false until a native session id is present, at which point
|
|
// callers fall back to a fresh launch.
|
|
//
|
|
// Hooks/activity: Auggie has no hook or lifecycle event system (it reads
|
|
// .claude/commands/ for slash commands, but that is not Claude Code hook
|
|
// compatibility). Hook installation and SessionInfo are intentionally no-ops
|
|
// (Tier C) until an Auggie-specific activity integration exists.
|
|
package auggie
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"sync"
|
|
|
|
"github.com/aoagents/agent-orchestrator/backend/internal/adapters"
|
|
"github.com/aoagents/agent-orchestrator/backend/internal/adapters/agent/agentbase"
|
|
"github.com/aoagents/agent-orchestrator/backend/internal/adapters/agent/binaryutil"
|
|
"github.com/aoagents/agent-orchestrator/backend/internal/ports"
|
|
)
|
|
|
|
const adapterID = "auggie"
|
|
|
|
// Plugin is the Auggie agent adapter. It is safe for concurrent use; the binary
|
|
// path is resolved once and cached under binaryMu.
|
|
type Plugin struct {
|
|
agentbase.Base
|
|
binaryMu sync.Mutex
|
|
resolvedBinary string
|
|
}
|
|
|
|
// New returns a ready-to-register Auggie adapter.
|
|
func New() *Plugin {
|
|
return &Plugin{}
|
|
}
|
|
|
|
var _ adapters.Adapter = (*Plugin)(nil)
|
|
var _ ports.Agent = (*Plugin)(nil)
|
|
|
|
// Manifest returns the adapter's static self-description.
|
|
func (p *Plugin) Manifest() adapters.Manifest {
|
|
return adapters.Manifest{
|
|
ID: adapterID,
|
|
Name: "Auggie",
|
|
Description: "Run Auggie (Augment Code) worker sessions.",
|
|
Version: "0.0.1",
|
|
Capabilities: []adapters.Capability{
|
|
adapters.CapabilityAgent,
|
|
},
|
|
}
|
|
}
|
|
|
|
// GetLaunchCommand builds the argv to start a new headless Auggie session:
|
|
//
|
|
// auggie --print [--rules <f>] [-- <prompt>]
|
|
//
|
|
// The prompt is passed after `--` so a prompt beginning with "-" is not mistaken
|
|
// for a flag. Auggie's `--instruction` flags are the task input, not a rule or
|
|
// system-prompt surface; AO standing instructions use `--rules` when the
|
|
// manager provides a prompt file.
|
|
func (p *Plugin) GetLaunchCommand(ctx context.Context, cfg ports.LaunchConfig) (cmd []string, err error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
binary, err := p.auggieBinary(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
cmd = []string{binary, "--print"}
|
|
if cfg.SystemPromptFile != "" {
|
|
cmd = append(cmd, "--rules", cfg.SystemPromptFile)
|
|
}
|
|
if cfg.Prompt != "" {
|
|
cmd = append(cmd, "--", cfg.Prompt)
|
|
}
|
|
return cmd, nil
|
|
}
|
|
|
|
// GetRestoreCommand rebuilds the argv that continues an existing Auggie session
|
|
// when a native session id is available in metadata:
|
|
//
|
|
// auggie --print --resume <sessionId>
|
|
//
|
|
// Auggie has no hook surface to capture that id automatically yet, so in practice
|
|
// the id is empty and ok is false, letting callers fall back to a fresh launch.
|
|
func (p *Plugin) GetRestoreCommand(ctx context.Context, cfg ports.RestoreConfig) (cmd []string, ok bool, err error) {
|
|
if err := ctx.Err(); err != nil {
|
|
return nil, false, err
|
|
}
|
|
agentSessionID := strings.TrimSpace(cfg.Session.Metadata[ports.MetadataKeyAgentSessionID])
|
|
if agentSessionID == "" {
|
|
return nil, false, nil
|
|
}
|
|
|
|
binary, err := p.auggieBinary(ctx)
|
|
if err != nil {
|
|
return nil, false, err
|
|
}
|
|
cmd = []string{binary, "--print"}
|
|
if cfg.SystemPromptFile != "" {
|
|
cmd = append(cmd, "--rules", cfg.SystemPromptFile)
|
|
}
|
|
cmd = append(cmd, "--resume", agentSessionID)
|
|
return cmd, true, nil
|
|
}
|
|
|
|
// Auggie has no single blanket auto-approve/bypass flag; unattended tool/file
|
|
// approval is governed by granular `--permission <tool>:<allow|deny>` rules, so
|
|
// AO emits no approval flag and defers every mode to the user's Auggie config.
|
|
// There is therefore no appendApprovalFlags helper for this adapter.
|
|
|
|
var auggieBinarySpec = binaryutil.BinarySpec{
|
|
Label: "auggie",
|
|
Names: []string{"auggie"},
|
|
WinNames: []string{"auggie.cmd", "auggie.exe", "auggie"},
|
|
UnixPaths: []string{"/usr/local/bin/auggie", "/opt/homebrew/bin/auggie"},
|
|
UnixHomePaths: [][]string{{".local", "bin", "auggie"}, {".npm", "bin", "auggie"}, {".npm-global", "bin", "auggie"}},
|
|
WinPaths: []binaryutil.WinPath{
|
|
{Base: binaryutil.WinAppData, Parts: []string{"npm", "auggie.cmd"}},
|
|
{Base: binaryutil.WinAppData, Parts: []string{"npm", "auggie.exe"}},
|
|
},
|
|
}
|
|
|
|
// ResolveAuggieBinary finds the `auggie` binary, searching PATH then common
|
|
// install locations. It returns "auggie" as a last resort so callers get the
|
|
// shell's normal command-not-found behavior if Auggie is absent.
|
|
func ResolveAuggieBinary(ctx context.Context) (string, error) {
|
|
return binaryutil.ResolveBinary(ctx, auggieBinarySpec)
|
|
}
|
|
|
|
func (p *Plugin) auggieBinary(ctx context.Context) (string, error) {
|
|
p.binaryMu.Lock()
|
|
defer p.binaryMu.Unlock()
|
|
|
|
if p.resolvedBinary != "" {
|
|
return p.resolvedBinary, nil
|
|
}
|
|
|
|
binary, err := ResolveAuggieBinary(ctx)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
p.resolvedBinary = binary
|
|
return binary, nil
|
|
}
|