Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cmd/project/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ import (
// else - never a JSON error/report object - on failure.
func printCompileIssues(cmd *cobra.Command, issues []projects.Issue) {
errStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("196"))
warnStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("214"))

for _, issue := range issues {
location := issue.File
if issue.Path != "" {
location += " " + issue.Path
}
fmt.Fprintln(cmd.ErrOrStderr(), errStyle.Render("✗ ")+location+": "+issue.Message)
prefix := errStyle.Render("✗ ")
if issue.IsWarning() {
prefix = warnStyle.Render("⚠ ")
}
fmt.Fprintln(cmd.ErrOrStderr(), prefix+location+": "+issue.Message)
}
}

Expand All @@ -37,10 +42,14 @@ func newCompileCmd() *cobra.Command {
Long: `Validates and compiles the project directory. With --json, prints the canonical single-line config JSON to stdout; otherwise prints the pretty-printed config and its hash.`,
RunE: func(cmd *cobra.Command, args []string) error {
result, issues := projects.CompileWithSkillBundles(dir, skillBundlesDir)
errs, _ := projects.PartitionIssues(issues)

if len(issues) > 0 {
printCompileIssues(cmd, issues)
return fmt.Errorf("%d validation issue(s)", len(issues))
}

if len(errs) > 0 {
return fmt.Errorf("%d validation issue(s)", len(errs))
}

if asJSON {
Expand Down
32 changes: 24 additions & 8 deletions cmd/project/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,30 @@ import (
"github.com/spf13/cobra"
)

// printIssues renders validation issues either as human-readable lines or JSON.
// printIssues renders validation issues either as human-readable lines or
// JSON. "valid" (JSON) and the pass/fail line (human) are computed from
// errors only - warnings are printed but never make a run invalid.
func printIssues(cmd *cobra.Command, issues []projects.Issue, asJSON bool) {
if asJSON {
out, _ := json.MarshalIndent(map[string]any{"valid": len(issues) == 0, "issues": issues}, "", " ")
errs, _ := projects.PartitionIssues(issues)
out, _ := json.MarshalIndent(map[string]any{"valid": len(errs) == 0, "issues": issues}, "", " ")
fmt.Fprintln(cmd.OutOrStdout(), string(out))
return
}

errStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("196"))
warnStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("214"))

for _, issue := range issues {
location := issue.File
if issue.Path != "" {
location += " " + issue.Path
}
cmd.Println(errStyle.Render("✗ ") + location + ": " + issue.Message)
prefix := errStyle.Render("✗ ")
if issue.IsWarning() {
prefix = warnStyle.Render("⚠ ")
}
cmd.Println(prefix + location + ": " + issue.Message)
}
}

Expand All @@ -38,16 +46,24 @@ func newValidateCmd() *cobra.Command {
Long: `Validates project.json and every agent definition against the published schemas. Exits 0 when valid, 1 when not (CI-friendly).`,
RunE: func(cmd *cobra.Command, args []string) error {
issues := projects.Validate(dir)
errs, warnings := projects.PartitionIssues(issues)

if len(issues) > 0 {
printIssues(cmd, issues, asJSON)
return fmt.Errorf("%d validation issue(s)", len(issues))
} else if asJSON {
printIssues(cmd, nil, true)
}

if asJSON {
printIssues(cmd, nil, true)
} else {
cmd.Println("✓ Project is valid")
if len(errs) > 0 {
return fmt.Errorf("%d validation issue(s)", len(errs))
}

if !asJSON {
if len(warnings) > 0 {
cmd.Printf("✓ Project is valid (%d warning(s))\n", len(warnings))
} else {
cmd.Println("✓ Project is valid")
}
}
return nil
},
Expand Down
30 changes: 23 additions & 7 deletions projects/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,20 @@ func compile(dir, skillBundlesDir string) (*CompileResult, []Issue) {

for _, s := range loaded.Skills {
compiled, skillIssues := readSkillBundle(dir, s, skillBundlesDir)
if len(skillIssues) > 0 {
issues = append(issues, skillIssues...)
issues = append(issues, skillIssues...)

// compiled is nil either because of a genuine content error (caught
// below by the errors check) or because the skill's git tree hash
// could not be resolved - a warning-only skip (readSkillBundle), not
// a compile failure.
if compiled == nil {
continue
}

skills = append(skills, *compiled)
}

if len(issues) > 0 {
if errs, _ := PartitionIssues(issues); len(errs) > 0 {
return nil, issues
}

Expand All @@ -97,7 +102,7 @@ func compile(dir, skillBundlesDir string) (*CompileResult, []Issue) {

configJSON, err := json.Marshal(config)
if err != nil {
return nil, []Issue{{File: "project.json", Message: "internal error serializing compiled config: " + err.Error()}}
return nil, append(issues, Issue{File: "project.json", Message: "internal error serializing compiled config: " + err.Error()})
}

sum := sha256.Sum256(configJSON)
Expand All @@ -106,11 +111,22 @@ func compile(dir, skillBundlesDir string) (*CompileResult, []Issue) {
Config: config,
ConfigJSON: configJSON,
Hash: hex.EncodeToString(sum[:]),
}, nil
}, issues // issues may be non-nil here too: warning-only issues (e.g. an uncommitted skill dir) do not block compile.
}

// Validate runs the full compile pipeline and reports issues only.
// Validate loads and validates a project directory: schema checks, agent and
// skill discovery, and skill file-content checks (dotfiles, size caps, path
// length, symlinks, frontmatter). It never touches git: tree-hash resolution
// only happens on the compile path (readSkillBundle), so an uncommitted or
// never-committed skill directory - the artifact that ships is the git tree
// at a commit, resolved by the platform's compile job, not the working tree -
// validates cleanly as long as its content is valid.
func Validate(dir string) []Issue {
_, issues := Compile(dir)
absDir, err := filepath.Abs(dir)
if err != nil {
return []Issue{{File: "project.json", Message: "cannot resolve project directory: " + err.Error()}}
}

_, issues := Load(absDir)
return issues
}
Loading
Loading