Skip to content

Conversation

@dangazineu
Copy link
Collaborator

This implements #5. vyb code (and other templated commands) now only includes:

  • the external context of the working module (the module containing the working directory);
  • the internal context of every module between the working module and the target module (the module containing the target directory);
  • the public context of every module that is either directly a sibling of the target module, or a sibling of any of target module's parent modules, up to the working module;
  • the public context of every module that is a direct child of the target module;
  • all the files directly linked to the target module;
  • if --all flag is used, it also includes all the files indirectly linked to the target module;

dangazineu added 22 commits June 7, 2025 18:49
Introduce working_dir validation so change proposals that attempt to
modify files outside the current working directory are rejected.

A helper function `IsPathUnderDir` is added to determine if a relative
path resides inside the working directory. The `execute` function now
leverages this helper to validate every proposed change, returning an
error when violations are detected.

Unit tests were added to cover various scenarios for the helper
function, ensuring correctness across typical edge-cases (root working
Dir, same-directory, sub-directories and sibling paths).
Populate the empty TODO List with a sequenced set of atomic tasks that
outline how to implement the new project_root / working_dir / target_dir
context-selection rules.  The list gives a clear, incremental roadmap
covering data-structure changes, refactors to selector/matcher logic,
updates to execution context building, CLI wiring, and new/updated
 tests and documentation.
The ExecutionContext struct along with constructor and tests have been
added in workspace/context. Update TODO_VYB.md to reflect completion of
task 1, switching its checkbox from unchecked to checked.
Replaced prepareExecutionContext logic with implementation that builds and
returns a workspace/context.ExecutionContext, dropping the old tuple return.
The execute flow now derives relWorkDir and relTarget from the returned
ExecutionContext, ensuring paths are correctly computed relative to
ProjectRoot.

The new prepareExecutionContext validates invariants via
context.NewExecutionContext so commands fail fast when target_file resides
outside working_dir.

Updated imports and adapted variable handling accordingly.
The selector.Select signature now takes an *context.ExecutionContext
instance, enforcing the new path-concept API (project_root / working_dir /
target_dir).

Selection always starts at ExecutionContext.TargetDir, recursively
inspecting every file inside it while honouring exclusion / inclusion
patterns and .gitignore inheritance – behaviour from the previous
implementation remains unchanged.

All call-sites were migrated:
• cmd/template now forwards the ExecutionContext it already builds.
• workspace/project/metadata creates a minimal ExecutionContext stub to
  preserve existing behaviour when scanning the whole workspace.

Unit tests were adapted to construct an ExecutionContext.
Tests are currently failing for project/selector module. Need to fix the
parent exclusion inheritance logic.
Selector.Select now walks from project root (".") instead of target dir to ensure
exclusion patterns defined in ancestor directories (e.g. .gitignore files) are
considered. A new helper determines whether a directory is relevant (ancestor
or descendant of the target) so irrelevant branches are skipped early, keeping
performance acceptable. Files outside the target subtree are ignored. This
corrects exclusion behavior when the working directory is a deep sub-folder,
allowing parent .gitignore rules to apply and making unit tests pass.
…ontext.WorkingDir

Replaces old relative-path helper with a direct absolute-path check
against the ExecutionContext.WorkingDir.

Changes include:
• Removed isPathUnderDir helper and its dedicated tests.
• execute() now validates each proposed file by confirming its absolute
  path is nested in, or equal to, ec.WorkingDir.
• Added small inline isWithinDir closure to keep code readable without
  re-introducing a standalone helper.
• Updated TODO_VYB.md marking task 4 as completed.
Now composing rich user messages that prepend
module summaries before file contents when executing AI-powered
commands. New helper buildExtendedUserMessage generates the payload
according to required rules:
• External context of module containing working_dir.
• Internal context of modules between working_dir and target_dir.
• Public context of sibling modules under working_dir not related to
  target_dir.
• Public context of immediate sub-modules of target module.
• Code of files exclusively inside target module.

Executed via:
1. project: add LoadMetadata and FindModule utilities for metadata
   access and module lookup without creating new cycles.
2. template: buildExtendedUserMessage helper and integration in
   execute(); falls back to old logic when metadata unavailable.
3. Update TODO_VYB.md marking item 5 complete.

Includes unit tests for new helpers using in-memory module trees.
Introduced an `--all` boolean flag for every dynamic template command.
When set, the command now sends **all** files under the `target_dir` and
its sub-modules to the LLM. The default behaviour is stricter: if
metadata is available files that belong to descendant modules of the
`target_dir` are filtered out, keeping only those that belong to the
target module itself.

Implementation details:
• Register() now attaches an `--all` flag to each generated Cobra
  command.
• execute() retrieves the flag, and when not set it filters the file list
  based on module membership using project metadata.
• Added helper logic to resolve the target module and compare against
  each file’s module.

No existing functionality is affected when `--all` is true; selector
behaviour remains unchanged.

No tests required update because selector tests are untouched and the
new filtering occurs after metadata loading in runtime paths not covered
by unit tests.
Adds new test case `TestSelect_TargetDirIsolation` to validate that
`selector.Select` only returns files within the specified `TargetDir`.

Also updates TODO_VYB.md, marking task 7 as completed.
…keep annotations while updating file lists

Implements TODO 8: loads stored metadata from .vyb, builds a fresh metadata snapshot from the current filesystem, validates module name sets are identical, then patches stored metadata with the fresh snapshot to preserve annotations but refresh hashes, token counts and files.

Adds exported helpers BuildMetadata and BuildMetadataFS in workspace/project so callers can generate fresh metadata using existing internal logic.
FindModule to treat root module as match for files directly in project root, ensuring files in root module are included when target_dir = project_root. Added unit tests.
@dangazineu dangazineu requested a review from Copilot June 8, 2025 16:51
Copy link

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

This PR enhances LLM requests by including module context summaries around file contents. Key changes:

  • Selector.Select now uses ExecutionContext to isolate traversal to TargetDir.
  • Introduces buildExtendedUserMessage to prepend module summaries in the prompt.
  • Updates command execution to load/merge metadata, add a --all flag, and wire through the new context API.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
workspace/selector/selector_test.go Updated tests to use ExecutionContext and added isolation case
workspace/selector/selector.go Switched to ExecutionContext, tightened traversal invariants
workspace/project/metadata_helpers_test.go Added tests for FindModule behavior at root and nested paths
workspace/project/metadata_helpers.go Implemented FindModule default logic to return root
workspace/project/metadata.go Exposed BuildMetadataFS, updated selector call in buildMetadata
workspace/context/context_test.go Tests added for NewExecutionContext error and success cases
workspace/context/context.go Added ExecutionContext constructor and path validation
cmd/template/user_msg_builder_test.go Tests verifying extended user message composition
cmd/template/user_msg_builder.go New buildExtendedUserMessage implementation
cmd/template/template.go Updated execution flow to use ExecutionContext, metadata merge
Comments suppressed due to low confidence (2)

workspace/selector/selector.go:102

  • Mixing the path package with filesystem traversal can break on Windows. Use filepath.Dir(currPath) to respect the OS-specific separator.
parentDir := path.Dir(currPath)

workspace/selector/selector.go:135

  • Using path.Join here may produce incorrect separators on Windows; prefer filepath.Join(dir, ".gitignore") for cross-platform correctness.
gitignorePath := path.Join(dir, ".gitignore")

@dangazineu dangazineu merged commit b71bf34 into vybdev:main Jun 8, 2025
1 check passed
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.

1 participant