Files
雷电芽衣 bc6983a62e chore(oss): audit the server package and resync the SDK mirrors
Split the 657-line operation service into eor, submit, and verify
modules, add the AGENT_REVOKED and KEY_RETIRED codes the Backend already
emits, and condense every multi-line comment. Mirror Node, Python, and
Go at 2.1.0 with the deep-health 503, non-idempotent retry, rotation
grace, and path-encoding fixes. Document which routes and response
fields the self-hosted server does not provide.

Claude-Session: https://claude.ai/code/session_01Agoc9bRVE9KL7mmWtey9Vq
2026-09-03 20:48:20 -04:00

145 lines
3.3 KiB
Go

package plugins
import (
"fmt"
"path/filepath"
)
// AugmentPlugin manages Auggie native global user hooks.
type AugmentPlugin struct {
rename renameFunc
}
// ManagesGuardRuntime reports that the guard is committed with the audit runtime.
func (p *AugmentPlugin) ManagesGuardRuntime() bool {
return true
}
// PreflightInstall validates settings and runtime identity before any write.
func (p *AugmentPlugin) PreflightInstall(config InstallConfig) error {
document, err := readAugmentDocument()
if err != nil {
return err
}
_, _, err = preflightAugmentInstallation(config, document)
return err
}
func (p *AugmentPlugin) Install(config InstallConfig) error {
document, err := readAugmentDocument()
if err != nil {
return err
}
paths, nodePath, err := preflightAugmentInstallation(config, document)
if err != nil {
return err
}
hooks, _ := removeManagedAugmentHooks(document.hooks, "", paths.runtimeRoot)
hooks["PreToolUse"] = append(
hooks["PreToolUse"],
buildAugmentGroup(buildAugmentHandler(paths.guardWrapperPath)),
)
hooks["PostToolUse"] = append(
hooks["PostToolUse"],
buildAugmentGroup(buildAugmentHandler(paths.auditWrapperPath)),
)
rendered, err := renderAugmentDocument(document, hooks)
if err != nil {
return fmt.Errorf("render Auggie user settings: %w", err)
}
changes, err := prepareAugmentInstallationChanges(
config,
paths,
nodePath,
rendered,
)
if err != nil {
return err
}
if err := writeManagedChanges(
changes,
"Install Augment Code CLI hooks",
p.rename,
paths.runtimeRoot,
paths.agentDirectory,
filepath.Dir(document.configPath),
"Auggie configuration directory",
); err != nil {
return err
}
fmt.Println("Auggie: user-level PreToolUse and PostToolUse hooks installed.")
return nil
}
func (p *AugmentPlugin) Uninstall(agentID string) error {
document, err := readAugmentDocument()
if err != nil {
return err
}
if !document.exists {
return nil
}
runtimeRoot, err := AgentRuntimeRoot()
if err != nil {
return err
}
hooks, changed := removeManagedAugmentHooks(
document.hooks,
agentID,
runtimeRoot,
)
if !changed {
return nil
}
rendered, err := renderAugmentDocument(document, hooks)
if err != nil {
return fmt.Errorf("render Auggie user settings: %w", err)
}
change, err := prepareRenderedAugmentChange(rendered)
if err != nil {
return err
}
return writeManagedChanges(
[]*fileChange{change},
"Uninstall Augment Code CLI hooks",
p.rename,
"",
"",
filepath.Dir(document.configPath),
"Auggie configuration directory",
)
}
func (p *AugmentPlugin) Status() (PluginStatus, error) {
configPath, pathErr := augmentConfigPath()
entry := SupportedAgents[augmentAgentKey]
status := PluginStatus{
AgentName: augmentAgentKey, DisplayName: entry.Name, ConfigPath: configPath,
}
if pathErr != nil {
return status, pathErr
}
document, err := readAugmentDocument()
if err != nil {
return status, err
}
runtimeRoot, err := AgentRuntimeRoot()
if err != nil {
return status, err
}
contracts := augmentRuntimeContracts(document.hooks, runtimeRoot)
status.HookConfigured = len(contracts) > 0
if !status.HookConfigured {
return status, nil
}
status.HookScriptExists, err = augmentRuntimeFilesExist(
contracts,
runtimeRoot,
)
if err != nil {
return status, err
}
status.Installed = status.HookScriptExists
return status, nil
}