Skip to content

fix(core): build /init prompt with the session directory - #61048

Open
hcalt500 wants to merge 1 commit into
anomalyco:devfrom
hcalt500:fix/init-review-session-directory
Open

hcalt500 wants to merge 1 commit into
anomalyco:devfrom
hcalt500:fix/init-review-session-directory

Conversation

@hcalt500

@hcalt500 hcalt500 commented Nov 1, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #52833

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

/init builds its prompt from initialize.txt and replaces ${path} with location.project.directory, the git worktree root. A session opened in a subdirectory of a repository therefore writes AGENTS.md at the repository root instead of the directory the session belongs to.

This PR substitutes location.directory instead, so /init targets the session's directory. When the session is opened at the repository root both values are the same, so that case is unchanged. Instruction loading still searches upward from the session directory to the repository root, so an AGENTS.md written in a subdirectory is still loaded by sessions started below it.

/review is not touched: review.txt has no ${path} placeholder, so the substitution had no effect. An earlier revision changed that line as well; it has been dropped to keep the diff minimal.

The code change is one line in packages/core/src/plugin/command.ts, plus the test expectations. The public plugin API is unchanged.

Product decision: #52833 has a reply describing the current repository-root behaviour as intentional. This PR deliberately changes nested-session /init; a maintainer should confirm that is wanted before merge. If the repository-root behaviour is preferred, the PR can be closed.

How did you verify your code works?

  • bun test --timeout 30000 test/plugin/command.test.ts from packages/core: 1 pass, 0 fail.
  • The test opens the session in /repo/packages/app inside the /repo project and asserts that the /init prompt resolves ${path} to /repo/packages/app.
  • Manual check with the simulated model: on the base the /init prompt points at the repository root; with this change it points at the session directory.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Added by the opencode bot (AI-generated).

Related: #51191, #55776, #58148

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Nov 1, 2026

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The /init fix works. I opened sessions in a directory nested inside a git repository using the simulated model. On the base, the /init prompt points AGENTS.md at the repository root; with this change, it points at the session's directory. bun test test/plugin/command.test.ts passes. The public API is unchanged, but this changes how the built-in /init command behaves in nested sessions.

  • Product decision needed: on #52833, a reply calls the current repository-root behaviour by design and turns the request into a feature request. A maintainer should confirm they want /init to follow the session directory before this lands. Instruction loading already searches upward from the session directory to the repository root, so an AGENTS.md written in a subdirectory will still be loaded.
  • The /review change does nothing: review.txt has no ${path} placeholder, so /review behaves exactly as before. The description's claim that /review now targets the package directory isn't accurate. Either drop that line so the change stays minimal, or correct the description.

Related: #51191, #55776, #58148

Before

After

Comment thread packages/core/src/plugin/command.ts Outdated
...input.prompt,
sessionID: input.sessionID,
text: append(PROMPT_REVIEW.replace("${path}", location.project.directory), input.prompt.text),
text: append(PROMPT_REVIEW.replace("${path}", location.directory), input.prompt.text),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

PROMPT_REVIEW (command/review.txt) contains no ${path} placeholder, so this replacement has no effect and /review behaves exactly as before. This line can be dropped to keep the change minimal.

The command plugin substituted ${path} with location.project.directory,
the git worktree root. In a monorepo that made /init write AGENTS.md at
the repository root instead of the directory the session was opened in.

Use location.directory so ${path} points at the session location
directory, and pin the test to a session opened in a subdirectory of the
project instead of the project root.

/review is unchanged: review.txt has no ${path} placeholder.

Fixes anomalyco#52833
@hcalt500 hcalt500 changed the title fix(core): build /init and /review prompts with the session directory fix(core): build /init prompt with the session directory Nov 1, 2026
@hcalt500
hcalt500 force-pushed the fix/init-review-session-directory branch from 7970216 to b542bdc Compare November 1, 2026 12:55
@hcalt500

hcalt500 commented Nov 1, 2026

Copy link
Copy Markdown
Author

Thanks for the review. Updated the branch:

  • Dropped the /review change. review.txt has no ${path} placeholder, so that line was a no-op; /review behavior is unchanged.
  • The PR is now limited to /init (one line in command.ts plus the test expectations).
  • Rewrote the PR description to remove the inaccurate /review claim and to call out the product decision explicitly.

On the product decision: this intentionally changes nested-session /init from the repository root to the session directory. If maintainers prefer the current repository-root behavior, feel free to close this. Otherwise the rationale is that /init should generate context for the package the session is working in. Instruction loading still walks upward, so a nested AGENTS.md is still picked up by sessions below it.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

1 similar comment
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

My earlier point is addressed: the change that did nothing to /review has been dropped, so the diff is now only /init. The /init change is the same one I checked before, and test/plugin/command.test.ts still passes. The public API is unchanged. One thing is still open: a maintainer needs to confirm that /init should follow the session directory, since #52833 has a reply describing the repository-root behaviour as intentional.

This branch has not been deployed

No deployments
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.

/init and /review use the git worktree root instead of the session location directory

1 participant