Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-8421: fix(agent): load Multica-installed skills in the Pi runtime via --skill (#9741)

JimmyChiac185771772cf
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.go
index eec74cc5d5..c4bd5e793f 100644
--- a/server/internal/daemon/daemon.go
+++ b/server/internal/daemon/daemon.go
@@ -8917,6 +8917,7 @@ func (d *Daemon) runTask(ctx context.Context, task Task, provider string, slot i
EnableTaskSupplement: taskSupplementNegotiated,
CursorHookCommand: cursorHookCommand,
Cwd: env.WorkDir,
+ PiSkillPaths: env.PiSkillPaths,
Model: model,
ThreadName: deriveTaskThreadName(task),
Timeout: d.cfg.AgentTimeout,
diff --git a/server/internal/daemon/execenv/context.go b/server/internal/daemon/execenv/context.go
index 2b5a47bd49..3c76ce0324 100644
--- a/server/internal/daemon/execenv/context.go
+++ b/server/internal/daemon/execenv/context.go
@@ -137,7 +137,7 @@ func writeWorkspacesRootMarkerAtomic(path string, data []byte) error {
// Copilot: skills → {workDir}/.github/skills/{name}/SKILL.md (native project-level discovery)
// OpenCode: skills → {workDir}/.opencode/skills/{name}/SKILL.md (native discovery)
// OpenClaw: skills → {workDir}/skills/{name}/SKILL.md (native discovery — paired with a per-task synthesized openclaw-config.json that pins agents.defaults.workspace to workDir; see openclaw_config.go)
-// Pi: skills → {workDir}/.pi/skills/{name}/SKILL.md (native discovery)
+// Pi: skills → {workDir}/.pi/skills/{name}/SKILL.md (explicit --skill loading)
// Cursor: skills → {workDir}/.cursor/skills/{name}/SKILL.md (native discovery)
// Kimi: skills → {workDir}/.kimi/skills/{name}/SKILL.md (native discovery)
// Reasonix: skills → {workDir}/.reasonix/skills/{name}/SKILL.md (native discovery)
@@ -377,7 +377,7 @@ func skillsDirPath(workDir, provider string) string {
// no openclaw scan path ever inspected.
return filepath.Join(workDir, "skills")
case "pi":
- // Pi natively discovers skills from .pi/skills/ in the workdir.
+ // The Pi backend explicitly loads skills from .pi/skills/ via --skill.
return filepath.Join(workDir, ".pi", "skills")
case "cursor":
// Cursor natively discovers skills from .cursor/skills/ in the workdir.
diff --git a/server/internal/daemon/execenv/execenv.go b/server/internal/daemon/execenv/execenv.go
index 5510ede236..36a84218cc 100644
--- a/server/internal/daemon/execenv/execenv.go
+++ b/server/internal/daemon/execenv/execenv.go
@@ -275,6 +275,9 @@ type Environment struct {
// ({RootDir}/workdir/); when the task is bound to a local_directory
// project_resource, it is the user's path instead. See LocalDirectory.
WorkDir string
+ // PiSkillPaths lists the daemon-written SKILL.md files from this dispatch's
+ // sidecar manifest, including any collision-free directory names.
+ PiSkillPaths []string
// LocalDirectory is true when WorkDir points at a user-supplied path
// outside RootDir (the local_directory flow). Callers that key behavior
// on "may I remove WorkDir as scratch?" must check this — for example
@@ -607,6 +610,9 @@ func Prepare(params PrepareParams, logger *slog.Logger) (*Environment, error) {
if err := writeContextFiles(workDir, params.Provider, params.Task, manifest); err != nil {
return nil, fmt.Errorf("execenv: write context files: %w", err)
}
+ if params.Provider == "pi" {
+ env.PiSkillPaths = manifest.skillFiles(skillsDirPath(workDir, params.Provider))
+ }
if err := prepareOmpMcpConfig(workDir, params.Provider, params.McpConfig, manifest); err != nil {
return nil, fmt.Errorf("execenv: prepare omp mcp config: %w", err)
}
@@ -905,6 +911,8 @@ func Reuse(params ReuseParams, logger *slog.Logger) *Environment {
manifest := &sidecarManifest{}
if err := writeContextFiles(params.WorkDir, params.Provider, params.Task, manifest); err != nil {
logger.Warn("execenv: refresh context files failed", "error", err)
+ } else if params.Provider == "pi" {
+ env.PiSkillPaths = manifest.skillFiles(skillsDirPath(params.WorkDir, params.Provider))
}
if err := prepareOmpMcpConfig(params.WorkDir, params.Provider, params.McpConfig, manifest); err != nil {
logger.Warn("execenv: refresh omp mcp config failed; forcing fresh prepare", "error", err)
diff --git a/server/internal/daemon/execenv/pi_skills_test.go b/server/internal/daemon/execenv/pi_skills_test.go
new file mode 100644
index 0000000000..21df37028f
--- /dev/null
+++ b/server/internal/daemon/execenv/pi_skills_test.go
@@ -0,0 +1,120 @@
+package execenv
+
+import (
+ "os"
+ "path/filepath"
+ "slices"
+ "testing"
+)
+
+func TestPreparePiSkillPaths(t *testing.T) {
+ t.Parallel()
+ for _, tc := range []struct {
+ name, provider, existing, managed string
+ bound bool
+ }{
+ {"bound", "pi", "", "review", true},
+ {"unassigned", "pi", "untrusted", "", false},
+ {"unrelated", "pi", "untrusted", "review", true},
+ {"collision", "pi", "review", "review-multica", true},
+ {"omp", "omp", "untrusted", "", true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ userDir := t.TempDir()
+ var existingPath string
+ if tc.existing != "" {
+ existingPath = filepath.Join(userDir, ".pi", "skills", tc.existing, "SKILL.md")
+ if err := os.MkdirAll(filepath.Dir(existingPath), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(existingPath, []byte("user skill"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ }
+ task := TaskContextForEnv{IssueID: "pi-skills"}
+ if tc.bound {
+ task.AgentSkills = []SkillContextForEnv{{
+ Name: "review", Content: "Managed skill.",
+ Files: []SkillFileContextForEnv{{Path: "references/SKILL.md", Content: "Supporting file."}},
+ }}
+ }
+ env, err := Prepare(PrepareParams{
+ WorkspacesRoot: t.TempDir(), WorkspaceID: "ws-pi-skills",
+ TaskID: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
+ Provider: tc.provider, LocalWorkDir: userDir, Task: task,
+ }, testLogger())
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer env.Cleanup(true)
+ var want []string
+ if tc.managed != "" {
+ want = []string{filepath.Join(userDir, ".pi", "skills", tc.managed, "SKILL.md")}
+ if _, err := os.Stat(want[0]); err != nil {
+ t.Fatalf("managed skill missing: %v", err)
+ }
+ }
+ if !slices.Equal(env.PiSkillPaths, want) {
+ t.Fatalf("PiSkillPaths = %v, want only %v", env.PiSkillPaths, want)
+ }
+ if existingPath != "" {
+ if data, err := os.ReadFile(existingPath); err != nil || string(data) != "user skill" {
+ t.Fatalf("user skill changed: %q, %v", data, err)
+ }
+ }
+ })
+ }
+}
+
+func TestReusePiSkillPathsRefresh(t *testing.T) {
+ t.Parallel()
+ task := TaskContextForEnv{IssueID: "pi-skills-reuse", AgentSkills: []SkillContextForEnv{{Name: "first", Content: "First."}}}
+ env, err := Prepare(PrepareParams{
+ WorkspacesRoot: t.TempDir(), WorkspaceID: "ws-pi-reuse",
+ TaskID: "a1b2c3d4-e5f6-7890-abcd-ef1234567890", Provider: "pi", Task: task,
+ }, testLogger())
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer env.Cleanup(true)
+ skillsDir := filepath.Join(env.WorkDir, ".pi", "skills")
+ if want := []string{filepath.Join(skillsDir, "first", "SKILL.md")}; !slices.Equal(env.PiSkillPaths, want) {
+ t.Fatalf("initial PiSkillPaths = %v, want %v", env.PiSkillPaths, want)
+ }
+ userPath := filepath.Join(skillsDir, "untrusted", "SKILL.md")
+ if err := os.MkdirAll(filepath.Dir(userPath), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(userPath, []byte("user skill"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ for _, tc := range []struct {
+ name string
+ invalid bool
+ }{{name: "second"}, {name: "broken", invalid: true}, {}} {
+ task.AgentSkills = nil
+ var want []string
+ if tc.name != "" {
+ task.AgentSkills = []SkillContextForEnv{{Name: tc.name, Content: "Updated."}}
+ if tc.invalid {
+ // A failed bundle write must not explicitly load a partial skill.
+ task.AgentSkills[0].Files = []SkillFileContextForEnv{
+ {Path: "duplicate.txt", Content: "first"},
+ {Path: "duplicate.txt", Content: "second"},
+ }
+ } else {
+ want = []string{filepath.Join(skillsDir, tc.name, "SKILL.md")}
+ }
+ }
+ reused := Reuse(ReuseParams{WorkDir: env.WorkDir, Provider: "pi", Task: task}, testLogger())
+ if reused == nil {
+ t.Fatal("Reuse returned nil")
+ }
+ if !slices.Equal(reused.PiSkillPaths, want) {
+ t.Fatalf("refreshed PiSkillPaths = %v, want %v", reused.PiSkillPaths, want)
+ }
+ if data, err := os.ReadFile(userPath); err != nil || string(data) != "user skill" {
+ t.Fatalf("user skill changed on reuse: %q, %v", data, err)
+ }
+ }
+}
diff --git a/server/internal/daemon/execenv/runtime_config.go b/server/internal/daemon/execenv/runtime_config.go
index f3f4f1998a..3e26ad650c 100644
--- a/server/internal/daemon/execenv/runtime_config.go
+++ b/server/internal/daemon/execenv/runtime_config.go
@@ -170,7 +170,7 @@ func formatProjectResource(r ProjectResourceForEnv) string {
// For DevEco Code: writes {workDir}/AGENTS.md (skills discovered natively from .deveco/skills/)
// For OpenClaw: writes {workDir}/AGENTS.md (skills discovered natively from {workDir}/skills/ via per-task openclaw-config.json that pins agents.defaults.workspace)
// For Hermes: writes {workDir}/AGENTS.md (skills discovered natively from a per-task HERMES_HOME/skills seeded by the daemon; see hermes_home.go)
-// For Pi: writes {workDir}/AGENTS.md (skills discovered natively from .pi/skills/)
+// For Pi: writes {workDir}/AGENTS.md (skills explicitly loaded from .pi/skills/ via --skill)
// For Oh-My-Pi (omp): writes {workDir}/AGENTS.md (omp is a pi fork; skills discovered from .omp/skills/)
// For Cursor: writes {workDir}/AGENTS.md (skills discovered natively from .cursor/skills/)
// For Kimi: writes {workDir}/AGENTS.md (Kimi Code CLI reads AGENTS.md natively; skills auto-discovered from project skills dirs)
diff --git a/server/internal/daemon/execenv/sidecar_manifest.go b/server/internal/daemon/execenv/sidecar_manifest.go
index 23b229d135..e1e8c0e855 100644
--- a/server/internal/daemon/execenv/sidecar_manifest.go
+++ b/server/internal/daemon/execenv/sidecar_manifest.go
@@ -67,6 +67,19 @@ type sidecarManifest struct {
Dirs []string `json:"dirs,omitempty"`
}
+// skillFiles returns the primary SKILL.md files we wrote directly under the
+// given skills parent. Supporting files named SKILL.md are not skill entries.
+func (m *sidecarManifest) skillFiles(skillsParent string) []string {
+ parent := filepath.Clean(skillsParent)
+ var paths []string
+ for _, path := range m.Files {
+ if filepath.Base(path) == "SKILL.md" && filepath.Dir(filepath.Dir(path)) == parent {
+ paths = append(paths, path)
+ }
+ }
+ return paths
+}
+
// recordMkdirAll behaves like os.MkdirAll(path, perm) but additionally
// records every parent directory it had to create (skipping any that
// already existed) into m so CleanupSidecars can rmdir them later. The
diff --git a/server/pkg/agent/agent.go b/server/pkg/agent/agent.go
index 0e37c1f766..1897a9dce8 100644
--- a/server/pkg/agent/agent.go
+++ b/server/pkg/agent/agent.go
@@ -29,6 +29,9 @@ type ExecOptions struct {
EnableTaskSupplement bool
Cwd string
Model string
+ // PiSkillPaths contains only the SKILL.md files written for this task by
+ // the daemon. Pi loads them explicitly without trusting other project files.
+ PiSkillPaths []string
// SystemPrompt carries the Multica runtime brief for the few providers
// that cannot pick it up from disk. The daemon leaves it empty for every
// other provider (see daemon.providerNeedsInlineSystemPrompt), because the
diff --git a/server/pkg/agent/omp_session.go b/server/pkg/agent/omp_session.go
index dacc9bbd38..7057bab9e7 100644
--- a/server/pkg/agent/omp_session.go
+++ b/server/pkg/agent/omp_session.go
@@ -24,7 +24,7 @@ var ompSessionArgs = map[string]blockedArgMode{
func buildOmpArgs(sessionPath, sessionDir string, opts ExecOptions, logger *slog.Logger) []string {
opts.CustomArgs = filterCustomArgs(opts.CustomArgs, ompSessionArgs, logger)
- args := buildPiArgs(sessionPath, opts, logger)
+ args := buildPiArgsFor("omp", sessionPath, opts, logger)
if sessionDir != "" {
args = append(args, "--session-dir", sessionDir)
}
diff --git a/server/pkg/agent/pi.go b/server/pkg/agent/pi.go
index d9f8138948..9a9f5a86fd 100644
--- a/server/pkg/agent/pi.go
+++ b/server/pkg/agent/pi.go
@@ -1176,20 +1176,25 @@ var piCustomArgModes = map[string]blockedArgMode{
"--offline": blockedStandalone,
}
-// buildPiArgs assembles the argv for a one-shot Pi invocation.
+// buildPiArgs assembles the argv for a Pi task invocation.
//
// Flags:
//
// -p non-interactive mode (prompt arrives on stdin)
// --mode json emit one JSON event per line on stdout
+// --mode rpc use RPC instead when task supplements are enabled
// --session <path> session log file (created upfront, reused on resume)
// --model <selector> model selector, passed through verbatim
// --thinking <level> per-agent reasoning level override
//
-// The prompt is deliberately absent from argv. Pi reads a non-TTY stdin in
-// print/JSON mode; using that supported path prevents Windows PowerShell's npm
-// shim from re-tokenising prompt content into options.
+// The prompt is deliberately absent from argv. It arrives on stdin as text
+// in print/JSON mode or a prompt command in RPC mode, preventing Windows
+// PowerShell's npm shim from re-tokenising prompt content into options.
func buildPiArgs(sessionPath string, opts ExecOptions, logger *slog.Logger) []string {
+ return buildPiArgsFor("pi", sessionPath, opts, logger)
+}
+
+func buildPiArgsFor(label, sessionPath string, opts ExecOptions, logger *slog.Logger) []string {
args := []string{"-p", "--mode", "json"}
if opts.EnableTaskSupplement {
args = []string{"--mode", "rpc"}
@@ -1213,6 +1218,14 @@ func buildPiArgs(sessionPath string, opts ExecOptions, logger *slog.Logger) []st
if opts.ThinkingLevel != "" {
args = append(args, "--thinking", opts.ThinkingLevel)
}
+ // Explicitly load only this dispatch's managed skill files. Scanning the
+ // project directory would also opt user-owned skills into untrusted runs.
+ // OMP retains its native .omp/skills discovery.
+ if label == "pi" {
+ for _, path := range opts.PiSkillPaths {
+ args = append(args, "--skill", path)
+ }
+ }
// Note: we intentionally do NOT pass --tools here. Omitting it lets
// Pi use its full tool registry, including user-installed extension
// tools. Passing --tools acts as a restrictive allowlist that
diff --git a/server/pkg/agent/pi_test.go b/server/pkg/agent/pi_test.go
index f0df99720a..326e5a7070 100644
--- a/server/pkg/agent/pi_test.go
+++ b/server/pkg/agent/pi_test.go
@@ -66,6 +66,60 @@ func TestBuildPiArgsPreservesProjectTrustFlags(t *testing.T) {
}
}
+func TestBuildPiArgsLoadsMulticaSkills(t *testing.T) {
+ for _, mode := range []string{"json", "rpc"} {
+ t.Run(mode, func(t *testing.T) {
+ opts := ExecOptions{
+ Cwd: t.TempDir(),
+ EnableTaskSupplement: mode == "rpc",
+ PiSkillPaths: []string{
+ filepath.Join(t.TempDir(), "managed skills", "local-ci", "SKILL.md"),
+ filepath.Join(t.TempDir(), "review-multica", "SKILL.md"),
+ },
+ CustomArgs: []string{"--no-approve"},
+ }
+ args := buildPiArgs("/tmp/s.jsonl", opts, slog.Default())
+ if countArg(args, "--skill") != len(opts.PiSkillPaths) {
+ t.Fatalf("want one --skill per managed file: %v", args)
+ }
+ joined := strings.Join(args, "\x00")
+ for _, path := range opts.PiSkillPaths {
+ if !strings.Contains(joined, "--skill\x00"+path+"\x00") {
+ t.Errorf("managed skill %q missing from %v", path, args)
+ }
+ }
+ wantPrint := 0
+ if mode == "json" {
+ wantPrint = 1
+ }
+ if !strings.Contains(joined, "--mode\x00"+mode+"\x00") || countArg(args, "-p") != wantPrint {
+ t.Errorf("wrong invocation mode: %v", args)
+ }
+ if countArg(args, "--approve") != 0 || countArg(args, "--no-approve") != 1 {
+ t.Errorf("project trust flags changed: %v", args)
+ }
+ if got := buildOmpArgs("", "", opts, slog.Default()); countArg(got, "--skill") != 0 {
+ t.Fatalf("omp must not get managed Pi skills: %v", got)
+ }
+ })
+ }
+}
+
+func TestBuildPiArgsDoesNotDiscoverProjectSkills(t *testing.T) {
+ cwd := t.TempDir()
+ path := filepath.Join(cwd, ".pi", "skills", "untrusted", "SKILL.md")
+ if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(path, []byte("repository-owned skill"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ args := buildPiArgs("", ExecOptions{Cwd: cwd}, slog.Default())
+ if countArg(args, "--skill") != 0 {
+ t.Fatalf("project skill was explicitly loaded without a managed path: %v", args)
+ }
+}
+
func TestBuildPiArgsAppendsMcpExtension(t *testing.T) {
extensionPath := "/tmp/multica-pi-mcp-test/mcp-extension.mjs"
args := buildPiArgs("/tmp/s.jsonl", ExecOptions{