This commit is contained in:
OpenClaw-User 2026-03-14 17:10:41 +08:00
commit 80de87c7c1
4 changed files with 16 additions and 11 deletions

View file

@ -1,15 +1,9 @@
package onboard package onboard
import ( import (
"embed"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
//go:generate cp -r ../../../../workspace .
//go:embed workspace
var embeddedFiles embed.FS
func NewOnboardCommand() *cobra.Command { func NewOnboardCommand() *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "onboard", Use: "onboard",

View file

@ -6,6 +6,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
picoclaw "github.com/sipeed/picoclaw"
"github.com/sipeed/picoclaw/cmd/picoclaw/internal" "github.com/sipeed/picoclaw/cmd/picoclaw/internal"
"github.com/sipeed/picoclaw/pkg/config" "github.com/sipeed/picoclaw/pkg/config"
) )
@ -47,20 +48,20 @@ func onboard() {
} }
func createWorkspaceTemplates(workspace string) { func createWorkspaceTemplates(workspace string) {
err := copyEmbeddedToTarget(workspace) err := copyEmbeddedToTarget(picoclaw.EmbeddedWorkspace, workspace)
if err != nil { if err != nil {
fmt.Printf("Error copying workspace templates: %v\n", err) fmt.Printf("Error copying workspace templates: %v\n", err)
} }
} }
func copyEmbeddedToTarget(targetDir string) error { func copyEmbeddedToTarget(source fs.FS, targetDir string) error {
// Ensure target directory exists // Ensure target directory exists
if err := os.MkdirAll(targetDir, 0o755); err != nil { if err := os.MkdirAll(targetDir, 0o755); err != nil {
return fmt.Errorf("Failed to create target directory: %w", err) return fmt.Errorf("Failed to create target directory: %w", err)
} }
// Walk through all files in embed.FS // Walk through all files in embed.FS
err := fs.WalkDir(embeddedFiles, "workspace", func(path string, d fs.DirEntry, err error) error { err := fs.WalkDir(source, "workspace", func(path string, d fs.DirEntry, err error) error {
if err != nil { if err != nil {
return err return err
} }
@ -71,7 +72,7 @@ func copyEmbeddedToTarget(targetDir string) error {
} }
// Read embedded file // Read embedded file
data, err := embeddedFiles.ReadFile(path) data, err := fs.ReadFile(source, path)
if err != nil { if err != nil {
return fmt.Errorf("Failed to read embedded file %s: %w", path, err) return fmt.Errorf("Failed to read embedded file %s: %w", path, err)
} }

View file

@ -4,12 +4,14 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
picoclaw "github.com/sipeed/picoclaw"
) )
func TestCopyEmbeddedToTargetUsesAgentsMarkdown(t *testing.T) { func TestCopyEmbeddedToTargetUsesAgentsMarkdown(t *testing.T) {
targetDir := t.TempDir() targetDir := t.TempDir()
if err := copyEmbeddedToTarget(targetDir); err != nil { if err := copyEmbeddedToTarget(picoclaw.EmbeddedWorkspace, targetDir); err != nil {
t.Fatalf("copyEmbeddedToTarget() error = %v", err) t.Fatalf("copyEmbeddedToTarget() error = %v", err)
} }

8
embedded_workspace.go Normal file
View file

@ -0,0 +1,8 @@
package picoclaw
import "embed"
// EmbeddedWorkspace bundles the default workspace templates used by `picoclaw onboard`.
//
//go:embed workspace
var EmbeddedWorkspace embed.FS