Search for AGENT.md in project subdirectory
opencode can be started from a project's subdirectory. In this case it looks for AGENT*.md in current directory only, not in the project's root.
Suggestion: implement project root identification (e.g. based on special file existence like .git, pyproject.toml, etc.) & additionally load agents files starting from the project root.
This issue might be a duplicate of existing issues. Please check:
- #1877: Support a root folder for aggregating sessions across subdirectories in Opencode - discusses project root identification and handling subdirectories within a project structure
Feel free to ignore if none of these address your specific case.
I think there are 2 different tasks and 1 common subtask:
- use project's sessions
- use project's AGENT.md
- locate project root (common)
hmm i thought we already loaded agents.md from project root everytime
Maybe I misread your wording but as you can see in this basic project we definitely read AGENTS.md from project root even when you are in subdirectory.
Hmm looks like it works for projects with .git. However, how do you discover project root? It is this code - https://github.com/sst/opencode/blob/1f57b9a70f09bea9c9fd5662becdda18c967f9a1/packages/opencode/src/app/app.ts#L69 ? I don't think it is generic enough - there are projects without git and with other VCSs or even without VCS at all. It's better to enable user to define root marker files with some sane defaults (e.g. .git, .hg and similar).
makes sense
Hmm looks like it works for projects with .git. However, how do you discover project root? It is this code -
opencode/packages/opencode/src/app/app.ts
Line 69 in 1f57b9a const root = git ?? input.cwd ? I don't think it is generic enough - there are projects without git and with other VCSs or even without VCS at all. It's better to enable user to define root marker files with some sane defaults (e.g. .git, .hg and similar).
I started using git worktree and realized that opencode always is looking into the main worktree, but not in my current worktree. This implementation detail made me understand why. running git config --list --show-origin made me realize that opencode thinks it should look in the directory from which the worktree was generated. Not sure what a solution to this would be.
--- After some digging:
I looked: since the referenced code is old, most likely this part is relevant, which is already in develop: https://github.com/sst/opencode/blob/900fe5ca041c5b9e2de9449c441dd9cb10beed0a/packages/opencode/src/project/project.ts#L68C17-L68C70
worktree = path.dirname(
await $`git rev-parse --path-format=absolute --git-common-dir`
.quiet()
.nothrow()
.cwd(worktree)
.text()
.then((x) => x.trim()),
)
And this looks like it already solves my issue. While i think git rev-parse --path-format=absolute --git-dir would give the worktree's directory and the above command gives the common directory.
I'll have to test with the current develop.
I'll have to test with the current develop.
Does this mean you have to test on latest? sorry i didn't quite follow u
Sorry, for the confusion, I have opened an new issue #2445 And I have tested with latest and found a quick fix. https://github.com/maiterth/opencode/compare/dev...feature-test-worktree-rootdir But this is actually unrelated to OPs issue. -> #2445
sweet, just saw it thanks @maiterth
[automated] Closing due to 90+ days of inactivity. Feel free to reopen if you still need this!