Skip to content

Split skill unpack into a dedicated function#1165

Open
gorkem wants to merge 2 commits intokitops-ml:mainfrom
gorkem:unpackskill-refactor
Open

Split skill unpack into a dedicated function#1165
gorkem wants to merge 2 commits intokitops-ml:mainfrom
gorkem:unpackskill-refactor

Conversation

@gorkem
Copy link
Copy Markdown
Member

@gorkem gorkem commented Apr 19, 2026

What

Extracts --as-skill handling out of unpackRecursive into a dedicated unpackSkill function in pkg/lib/filesystem/unpack/core.go.

Why

opts.SkillOptions guards were threaded through every layer case in unpackRecursive, making the control flow hard to follow. Skill unpack only cares about prompt layers — it doesn't write a Kitfile, traverse parent refs, or handle remote datasets. Separating the two paths removes dead branches from each function.

Pulls --as-skill handling out of unpackRecursive, which was
threaded with opts.SkillOptions guards across every layer
case. unpackSkill now only walks prompt layers, skipping
Kitfile write, parent-ref traversal, and remote-dataset
handling that don't apply in skill mode.

Signed-off-by: Gorkem Ercan <gorkem.ercan@gmail.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors --as-skill handling by extracting prompt-layer skill installation logic out of unpackRecursive into a dedicated unpackSkill function, simplifying control flow in the main unpack path.

Changes:

  • Route UnpackModelKit to unpackSkill when opts.SkillOptions is set.
  • Remove skill-mode conditionals, counters, and summary logic from unpackRecursive.
  • Add unpackSkill implementation that scans prompt layers and installs skills from SKILL.md.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +69 to +71
if opts.SkillOptions != nil {
return unpackSkill(ctx, opts)
}
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnpackModelKit guards opts != nil above, but then unconditionally dereferences opts.SkillOptions. If opts is nil (which this function currently appears to allow), this will panic. Add an early opts == nil check (return a clear error) or change the condition to if opts != nil && opts.SkillOptions != nil before calling unpackSkill/unpackRecursive.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a check

if layerDesc.Annotations[constants.LayerSubtypeAnnotation] != constants.LayerSubtypePrompt {
continue
}

Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unpackSkill indexes config.Prompts[promptIdx] without checking bounds. If the Kitfile prompt list is missing entries or is inconsistent with the manifest prompt layers, this will panic. Consider validating promptIdx < len(config.Prompts) (and returning a descriptive error) before indexing, similar to how other mismatches are handled.

Suggested change
if promptIdx >= len(config.Prompts) {
return fmt.Errorf("manifest contains more prompt layers than kitfile entries: prompt index %d out of range (prompts=%d)", promptIdx, len(config.Prompts))
}

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The manifest's prompt layers and config.Prompts are produced 1:1 by the pack step from the same source, so promptIdx can't exceed len(config.Prompts) unless the modelkit is corrupt.

Callers always pass non-nil *UnpackOptions, but the existing
L
`opts != nil && opts.UnpackDir != ""` guard implied nil was
possible while the rest of the function would dereference it
unchecked. Return an explicit error at the API boundary instead.

Signed-off-by: Gorkem Ercan <gorkem.ercan@gmail.com>
@gorkem gorkem requested a review from amisevsk April 19, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants