Preserve manager skill bootstrap work
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
"git.a-wan.net/alan/pipelines/internal/harness"
|
||||
)
|
||||
|
||||
//go:embed skill/SKILL.md skill/references/*.md
|
||||
//go:embed skill/SKILL.md skill/references/*.md manager/SKILL.md
|
||||
var content embed.FS
|
||||
|
||||
// Command launches the normal CLI directly. Skill loading and questions belong
|
||||
|
||||
@@ -163,3 +163,60 @@ func TestSkillUpgradeAddsSelfContainedNotificationReference(t *testing.T) {
|
||||
t.Fatal("user notes lost")
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagerSkillInstallsWithoutReplacingUnmanagedSkill(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
dir, err := InstallManagerSkill()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err = InstallManagerSkill(); err != nil {
|
||||
t.Fatal("repeat manager install", err)
|
||||
}
|
||||
data, err := os.ReadFile(filepath.Join(dir, "SKILL.md"))
|
||||
if err != nil || !strings.Contains(string(data), "name: pipelines-manager") {
|
||||
t.Fatalf("manager skill = %q, %v", data, err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(dir, "SKILL.md"), []byte("operator customization"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := InstallManagerSkill(); err == nil {
|
||||
t.Fatal("overwrote modified manager skill")
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagerSkillInstallRefusesUnmanagedExistingSkill(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
dir, err := ManagerSkillDirectory()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
path := filepath.Join(dir, "SKILL.md")
|
||||
if err := os.WriteFile(path, []byte("operator skill"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := InstallManagerSkill(); err == nil {
|
||||
t.Fatal("replaced unmanaged manager skill")
|
||||
}
|
||||
}
|
||||
|
||||
func TestManagerSkillInstallRestoresMissingManagedFile(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
dir, err := InstallManagerSkill()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
path := filepath.Join(dir, "SKILL.md")
|
||||
if err := os.Remove(path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := InstallManagerSkill(); err != nil {
|
||||
t.Fatal("restore manager skill", err)
|
||||
}
|
||||
if data, err := os.ReadFile(path); err != nil || !strings.Contains(string(data), "name: pipelines-manager") {
|
||||
t.Fatalf("restored manager skill = %q, %v", data, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,3 +143,82 @@ func writeSkillFile(path string, data []byte) error {
|
||||
}
|
||||
return os.Rename(f.Name(), path)
|
||||
}
|
||||
|
||||
// ManagerSkillDirectory is the source-controlled Pipelines manager skill location.
|
||||
func ManagerSkillDirectory() (string, error) {
|
||||
dir := os.Getenv("XDG_CONFIG_HOME")
|
||||
if dir == "" {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
dir = filepath.Join(home, ".config")
|
||||
}
|
||||
return filepath.Abs(filepath.Join(dir, "opencode", "skills", "pipelines-manager"))
|
||||
}
|
||||
|
||||
// InstallManagerSkill installs only the dedicated manager skill. It refuses an
|
||||
// unmanaged or modified same-name skill and uses the same ownership marker and
|
||||
// atomic write protection as InstallSkill.
|
||||
func InstallManagerSkill() (string, error) {
|
||||
dir, err := ManagerSkillDirectory()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
marker := filepath.Join(dir, ".pipelines-managed.json")
|
||||
if info, statErr := os.Lstat(marker); statErr == nil && !info.Mode().IsRegular() {
|
||||
return "", fmt.Errorf("refusing non-regular manager skill ownership marker %s", marker)
|
||||
} else if statErr != nil && !os.IsNotExist(statErr) {
|
||||
return "", statErr
|
||||
}
|
||||
previous := map[string]string{}
|
||||
if data, readErr := os.ReadFile(marker); readErr == nil {
|
||||
if err := json.Unmarshal(data, &previous); err != nil {
|
||||
return "", fmt.Errorf("invalid manager skill ownership marker: %w", err)
|
||||
}
|
||||
} else if !os.IsNotExist(readErr) {
|
||||
return "", readErr
|
||||
}
|
||||
data, err := content.ReadFile("manager/SKILL.md")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
const file = "SKILL.md"
|
||||
next := digest(data)
|
||||
path := filepath.Join(dir, file)
|
||||
if info, statErr := os.Lstat(path); statErr == nil {
|
||||
if !info.Mode().IsRegular() {
|
||||
return "", fmt.Errorf("refusing to replace non-regular manager skill file %s", path)
|
||||
}
|
||||
existing, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if previous[file] == "" || (digest(existing) != previous[file] && digest(existing) != next) {
|
||||
return "", fmt.Errorf("manager skill file %s is user-managed or modified; preserve/rename it before installing the Pipelines manager skill", path)
|
||||
}
|
||||
} else if !os.IsNotExist(statErr) {
|
||||
return "", statErr
|
||||
}
|
||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||
return "", err
|
||||
}
|
||||
// A managed file may have been deleted after the marker was written. The
|
||||
// marker proves ownership, but not that the target still exists; recreate a
|
||||
// missing file before leaving the marker unchanged.
|
||||
if previous[file] != next || !regularFile(path) {
|
||||
if err := writeSkillFile(path, data); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
markerData, _ := json.MarshalIndent(map[string]string{file: next}, "", " ")
|
||||
if err := writeSkillFile(marker, markerData); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
func regularFile(path string) bool {
|
||||
info, err := os.Stat(path)
|
||||
return err == nil && info.Mode().IsRegular()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
---
|
||||
name: pipelines-manager
|
||||
description: Manage project work through Pipelines: clarify operator intent, route actionable work to the appropriate pipeline, monitor runs, and unblock evidence-based failures without acting as an additional developer or reviewer.
|
||||
---
|
||||
|
||||
# Pipelines manager
|
||||
|
||||
Clarify scope, consent and constraints with the operator. Inspect only enough project map, queue and history to write actionable tasks; prompts state the goal, acceptance checks and constraints, not an invented implementation. Work from a branch/worktree and select the pipeline by area.
|
||||
|
||||
Pipelines own implementation, testing, review, conflict resolution and landing. The manager assigns, monitors with `pipelines wait <ids>`, reconciles completion and unblocks exact evidenced failures; it does not hand-edit projects, rewrite deliverables, or add a second acceptance/review gate. For Pipelines itself, use observed failures to improve the product through its pipelines, never workaround scripts.
|
||||
|
||||
Keep durable queue records as intent; the server is run-state authority. Start independent work in bounded parallelism only where edits, provider capacity, machine pressure and capture resources permit. Hardware waits pause in the runner. Do not create polling loops, lane/queue drivers, sleeping model stages, or claim undeployed queue/timer support.
|
||||
|
||||
Preserve partial work and sessions on failure. Diagnose the failed operation from evidence; a timeout is not proof of a lost message. Do not blindly replay a whole implementer stage or raise limits to hide defects. Before cleanup require ancestry proof; never delete branches or discard unknown changes. Report failures and decisions briefly, not routine green completion. Do not install, deploy or restart while work is in flight; obtain explicit operator approval for system changes.
|
||||
|
||||
Use the configured strong manager model for operator chats. Developer pipeline model choices remain distinct and configurable; do not hardcode catalog IDs, pricing or temporary endpoints here. Keep project-specific commands and policy in project maps.
|
||||
Reference in New Issue
Block a user