-
Notifications
You must be signed in to change notification settings - Fork 223
context: load project skills from git root #2164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3b6b8b8
context: load project skills from git root
enyst 2bc2e1b
tests: avoid forked marker under xdist
enyst 59c1018
tests: cover repo-root AGENTS.md when running from subdir
enyst 251a74b
context: simplify load_project_skills merging
enyst 85a02ea
tests: use TestLLM in repo root project skills test
enyst ede2670
Merge remote-tracking branch 'origin/main' into fix/load-project-skil…
enyst 6c0ada3
tests: use sdk TestLLM helper
enyst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| from openhands.sdk.agent import Agent | ||
| from openhands.sdk.context.agent_context import AgentContext | ||
| from openhands.sdk.context.skills import load_project_skills | ||
| from openhands.sdk.conversation.impl.local_conversation import LocalConversation | ||
| from openhands.sdk.event import SystemPromptEvent | ||
| from openhands.sdk.llm import Message, TextContent | ||
| from openhands.sdk.testing import TestLLM | ||
|
|
||
|
|
||
| def test_system_prompt_includes_repo_root_agents_md_when_workdir_is_subdir( | ||
| tmp_path: Path, | ||
| ): | ||
| """Repo-root AGENTS.md should still be injected when starting from a subdir. | ||
|
|
||
| This is the integration-style equivalent of the CLI manual test: | ||
| - work_dir is a subdirectory | ||
| - git repo root contains AGENTS.md | ||
| - AgentContext is built from load_project_skills(work_dir) | ||
| - LocalConversation initialization emits a SystemPromptEvent | ||
|
|
||
| We assert the sentinel from the repo root AGENTS.md appears in the | ||
| SystemPromptEvent.dynamic_context. | ||
| """ | ||
|
|
||
| (tmp_path / ".git").mkdir() | ||
| (tmp_path / "AGENTS.md").write_text("# Project Guidelines\n\nSENTINEL_ROOT_123\n") | ||
|
|
||
| subdir = tmp_path / "subdir" | ||
| subdir.mkdir() | ||
|
|
||
| skills = load_project_skills(subdir) | ||
| ctx = AgentContext( | ||
| skills=skills, | ||
| # Keep deterministic across environments. | ||
| current_datetime="2026-01-01T00:00:00Z", | ||
| ) | ||
|
|
||
| agent = Agent( | ||
| llm=TestLLM.from_messages( | ||
| [ | ||
| Message( | ||
| role="assistant", | ||
| content=[TextContent(text="ok")], | ||
| ) | ||
| ], | ||
| model="test-model", | ||
| ), | ||
| tools=[], | ||
| include_default_tools=[], | ||
| agent_context=ctx, | ||
| ) | ||
|
|
||
| conversation = LocalConversation( | ||
| agent=agent, | ||
| workspace=subdir, | ||
| persistence_dir=tmp_path / "conversation", | ||
| delete_on_close=True, | ||
| ) | ||
| conversation.send_message("hi") | ||
|
|
||
| system_prompt_event = next( | ||
| e for e in conversation.state.events if isinstance(e, SystemPromptEvent) | ||
| ) | ||
| assert system_prompt_event.dynamic_context is not None | ||
| assert "SENTINEL_ROOT_123" in system_prompt_event.dynamic_context.text | ||
|
|
||
| conversation.close() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.