Skip to content

refactor(skill): refactor SkillBox with Skill util class#724

Open
fang-tech wants to merge 1 commit intoagentscope-ai:mainfrom
fang-tech:refactor/skill/refacor-file-ops-in-skill
Open

refactor(skill): refactor SkillBox with Skill util class#724
fang-tech wants to merge 1 commit intoagentscope-ai:mainfrom
fang-tech:refactor/skill/refacor-file-ops-in-skill

Conversation

@fang-tech
Copy link
Contributor

AgentScope-Java Version

[The version of AgentScope-Java you are working on, e.g. 1.0.8, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]

Description

[Please describe the background, purpose, changes made, and how to test this PR]

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@gemini-code-assist
Copy link

Summary of Changes

Hello @fang-tech, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the SkillBox class by extracting file system related operations into a new utility class SkillFileSystemHelper. It also updates the way skill repository sources are formatted and adds corresponding tests to ensure the changes are working as expected.

Highlights

  • SkillBox Refactoring: Introduces a SkillFileSystemHelper class to handle temporary directory cleanup, simplifying the SkillBox class.
  • Source String Formatting: Updates the getSource method in FileSystemSkillRepository and ClasspathSkillRepository to provide a more consistent and informative source string.
  • Testing: Adds new tests for getSource method in ClasspathSkillRepositoryTest and FileSystemSkillRepositoryTest to ensure correct source string formatting.
Changelog
  • agentscope-core/src/main/java/io/agentscope/core/skill/SkillBox.java
    • Introduces SkillFileSystemHelper for managing temporary directory cleanup.
    • Simplifies ensureWorkDirExists and ensureUploadDirExists methods.
  • agentscope-core/src/main/java/io/agentscope/core/skill/repository/FileSystemSkillRepository.java
    • Updates the default source string format to 'filesystem:parent_child'.
  • agentscope-core/src/test/java/io/agentscope/core/skill/repository/ClasspathSkillRepositoryTest.java
    • Adds tests for getSource method to verify the default and custom source formats.
  • agentscope-core/src/test/java/io/agentscope/core/skill/repository/FileSystemSkillRepositoryTest.java
    • Adds tests for getSource method, including tests for default source, custom source, null source, and source suffix generation.
Activity
  • Code formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors SkillBox to delegate file system operations to a new SkillFileSystemHelper utility class, which improves code organization and reusability. The changes also standardize the source string format in FileSystemSkillRepository for better consistency. While the refactoring is a good step, it has introduced a critical compilation error in SkillBox by referencing a variable that was removed. I've added a comment with a suggested fix for this issue. The test updates are comprehensive and correctly validate the new behavior.

Copy link
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 skill repository “source” formatting and consolidates temp-directory cleanup logic into SkillFileSystemHelper, updating unit tests accordingly.

Changes:

  • Update FileSystemSkillRepository#getSource() to use filesystem: and an underscore-based suffix format.
  • Refactor SkillBox temp work directory cleanup to use SkillFileSystemHelper.registerTempDirectoryCleanup(...) and simplify directory initialization logic.
  • Add/adjust unit tests for getSource() behavior in filesystem and classpath repositories.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
agentscope-core/src/main/java/io/agentscope/core/skill/repository/FileSystemSkillRepository.java Changes default source format from filesystem_... to filesystem:... and updates suffix delimiter.
agentscope-core/src/main/java/io/agentscope/core/skill/SkillBox.java Replaces inline shutdown-hook cleanup with SkillFileSystemHelper and refactors work/upload dir creation.
agentscope-core/src/test/java/io/agentscope/core/skill/repository/FileSystemSkillRepositoryTest.java Updates and expands getSource()/suffix unit tests to match new filesystem source format.
agentscope-core/src/test/java/io/agentscope/core/skill/repository/ClasspathSkillRepositoryTest.java Adds getSource() unit tests for default/custom source and trailing-slash handling.
Comments suppressed due to low confidence (1)

agentscope-core/src/main/java/io/agentscope/core/skill/SkillBox.java:690

  • In the non-temp branch, Files.exists(workDir), createDirectories(workDir), and the log statement still reference workDir, but there is no local variable defined anymore. This is a compile error; switch these references to this.workDir (or define a local variable before the if).
            // Create directory if it doesn't exist
            if (!Files.exists(workDir)) {
                try {
                    Files.createDirectories(workDir);
                    logger.info("Created working directory: {}", workDir);

Comment on lines +677 to 681
this.workDir = Files.createTempDirectory("agentscope-code-execution-");

SkillFileSystemHelper.registerTempDirectoryCleanup(workDir);

logger.info("Created temporary working directory: {}", workDir);
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

workDir is referenced but no longer declared in this method (e.g., in registerTempDirectoryCleanup(workDir) and the log statement). This will not compile; use this.workDir (or introduce a local Path workDir = this.workDir) consistently after creating the temp directory.

Copilot uses AI. Check for mistakes.
assertEquals("filesystem_" + expectedSuffix, source);
@DisplayName("Should return default source with format: filesystem:parent_child")
void testGetSource_DefaultSource() {
assertTrue(repository.getSource().matches("filesystem:[^_]+_skills"));
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The regex filesystem:[^_]+_skills assumes the parent directory name contains no underscores, but buildDefaultSourceSuffix() does not enforce that. This can make the test flaky depending on the temp directory name. Consider asserting against the exact expected suffix derived from skillsBaseDir.getParent().getFileName() and skillsBaseDir.getFileName() (or relax the regex to avoid assumptions about underscores).

Suggested change
assertTrue(repository.getSource().matches("filesystem:[^_]+_skills"));
String parentName = skillsBaseDir.getParent().getFileName().toString();
String childName = skillsBaseDir.getFileName().toString();
String expectedSource = "filesystem:" + parentName + "_" + childName;
assertEquals(expectedSource, repository.getSource());

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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