Init improvements#1176
Conversation
c0b52eb to
3723a9c
Compare
There was a problem hiding this comment.
Pull request overview
This PR enhances Kitfile generation for kit init and kit import by introducing a --depth option to control how deeply the directory tree is traversed for file-by-file classification, and by making directory layers explicit via trailing slashes.
Changes:
- Add a
--depthflag tokit initandkit import, threading the value through to Kitfile generation. - Refactor Kitfile generation to support depth-based recursion and adjust how unknown files/directories are handled.
- Append trailing slashes to directory layer paths and update fixtures/tests accordingly.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| testing/testdata/kitfile-generation/test_prompt-handling.yaml | Updates expected Kitfile output to include trailing slashes for directory layers. |
| testing/testdata/kitfile-generation/test_directory-handling.yaml | Updates expected Kitfile output to include trailing slashes for directory layers. |
| pkg/lib/kitfile/generate/skill.go | Ensures skill directory prompt paths are emitted with a trailing slash. |
| pkg/lib/kitfile/generate/skill_test.go | Updates tests for new GenerateKitfile signature and trailing-slash directory paths. |
| pkg/lib/kitfile/generate/generate.go | Implements depth support, refactors file/dir processing, and adds withTrailingSlash. |
| pkg/lib/kitfile/generate/generate_test.go | Adds coverage for depth-based generation behavior (including subdir README/LICENSE and model parts). |
| pkg/cmd/kitinit/cmd.go | Adds --depth flag and passes it into Kitfile generation. |
| pkg/cmd/kitimport/util.go | Extends kitfile generation helper to accept depth. |
| pkg/cmd/kitimport/hfimport.go | Passes depth through when generating Kitfiles during HF import. |
| pkg/cmd/kitimport/gitimport.go | Passes depth through when generating Kitfiles during Git import. |
| pkg/cmd/kitimport/cmd.go | Adds --depth flag to the import command options. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if len(unknownFiles) > 5 { | ||
| output.Logf(output.LogLevelTrace, "Unrecognized files found in %s; adding catch-all code layer", dir.Path) | ||
| kitfile.Code = append(kitfile.Code, artifact.Code{Path: "."}) | ||
| } else if len(unknownFiles) > 0 { | ||
| output.Logf(output.LogLevelTrace, "Unrecognized files found in %s; adding as code layers") | ||
| for _, f := range unknownFiles { | ||
| kitfile.Code = append(kitfile.Code, artifact.Code{Path: f.Path}) | ||
| } |
There was a problem hiding this comment.
This is acceptable; replacing all detected code files with a catch-all layer is no longer desirable, in my opinon; we should avoid adding an opaque Path: "." layer if we can, as it's hard to reason about what it actually contains.
| // We can, in the future, recurse deeper into the directory tree here. For now, treat secondary dirs as unknowns | ||
| directoryContents[int(fileTypeUnknown)] = append(directoryContents[int(fileTypeUnknown)], subdir.Path) | ||
| // We can, in the future, recurse deeper into the directory tree here. For now, treat additional dirs as unknowns | ||
| directoryContents[int(fileTypeUnknown)] = append(directoryContents[int(fileTypeUnknown)], filepath.Join(withTrailingSlash(dir.Path), subdir.Path)) |
There was a problem hiding this comment.
Ah yeah this was me getting confused because the test I had written was invalid :D
Forgot to remove this bit
| func withTrailingSlash(p string) string { | ||
| if p == "." || strings.HasSuffix(p, "/") { | ||
| return p | ||
| } | ||
| return p + "/" |
There was a problem hiding this comment.
Paths should all be normalized during DirectoryListing generation (
) so this should never see a windows-style backslash.| case fileTypeCode: | ||
| kitfile.Code = append(kitfile.Code, artifact.Code{Path: file.Path}) |
There was a problem hiding this comment.
We don't currently check all the various source code file extensions but this approach is more correct and would have to be made if we started doing that. Not a bug to exhaust an enum in a switch.
Add flag `--depth` to commands that generate Kitfiles. The provided depth controls how far down a directory structure kit will navigate before starting to group directories into layers -- for example, with depth=1, files in immediate subdirectories of the context will be processed individually and added to the Kitfile as appropriate. Signed-off-by: Angel Misevski <amisevsk@gmail.com>
Signed-off-by: Angel Misevski <amisevsk@gmail.com>
3723a9c to
69ab6ca
Compare
Description
Add a
--depthflag for Kitfile generation (kit initandkit import) that can be used to control how far down a directory tree we traverse before starting to add less fine-grained directory entries. For--depth=0(the default), behaviour is the same as in the current main branch: all files in the context directory are classified and added to the Kitfile, and any subdirectories are added on a best-effort basis (if we can tell they're all one type, we use that type; otherwise we add a code layer for the directory).Increasing the depth parameter means files in individual subdirectories are also classified in the same way, so
--depth=1includes files in immediate subdirectories,--depth=2goes one directory further, etc. Depth can be set to-1to process all files individually.This flag can lead to much larger Kitfiles if a lot of individual files are added. However, this behaviour may be desirable in some cases, such as when a directory contains a large number of moderate or large files -- adding them as separate entries means they each appear in their own layer, and prevents the entire directory layer from being invalidated if a single file in the directory is updated.
Additionally, this PR makes one small change to how Kitfiles are generated: when directories are added to the Kitfile, we add a trailing slash to make it clearer that the layer represents a directory versus a regular file.
Linked issues
N/A
AI-Assisted Code