3.3 KiB
3.3 KiB
description, argument-hint, model, allowed-tools
| description | argument-hint | model | allowed-tools |
|---|---|---|---|
| Insert a new session change after a specific revision | <ref> [message] | claude-haiku-4-5 | Bash(jjagent:*), Bash(jj:*) |
jjagent:insert-after
Insert a new session change after a specific revision using jj's --insert-after flag
instructions
You must follow these steps:
-
Parse arguments:
$1(required): The jj reference to insert after$2 $3 $4...(optional): Custom commit message for the session (all remaining arguments)- If
$1is empty, inform the user that a reference is required
-
Get the current session ID:
- Extract it from the system reminder at the start of this conversation
- The format is: "The current session ID is "
-
Check if a session change already exists:
- Run:
jjagent change-id <session-id> - If this succeeds and returns a change ID, the session already has a change
- If it fails, the session doesn't have a change yet
- Run:
-
Validate that ref is an ancestor of @ (working copy):
- Run:
jj log -r "$1..@" --no-graph -T "change_id.short()" - If this command fails or returns empty output,
$1is not an ancestor of@ - If not an ancestor, inform the user: "Error: '$1' is not an ancestor of the working copy. Please choose a revision that comes before @ in the commit history."
- Stop execution if validation fails
- Run:
-
Handle existing session change:
- If a change already exists for this session, STOP and ask the user for confirmation: "This session already has a change at . Would you like to rebase it to insert after '$1'?"
- IMPORTANT: You MUST wait for explicit user confirmation before proceeding
- Do NOT rebase without the user's explicit approval
- If the user confirms YES, then run:
jj rebase -r <change-id> --insert-after "$1" - If the user says NO or declines, stop and explain that no changes were made
- After rebasing (if confirmed), show the result with:
jj log -r <change-id> --no-graph
-
Create new session change (if no existing change):
- Build the commit message using the session-message command:
- If custom message arguments were provided (if
$2is not empty):- Combine all arguments from
$2onwards into the message - Run:
jjagent session-message <session-id> "$2 $3 $4..."(all remaining args)
- Combine all arguments from
- If no custom message (if
$2is empty):- Run:
jjagent session-message <session-id>
- Run:
- If custom message arguments were provided (if
- Create the change:
jj new --insert-after "$1" --no-edit -m "$(jjagent session-message <session-id> [message if provided])" - Show the result with:
jj log -r @ --no-graph
- Build the commit message using the session-message command:
-
Inform the user:
- Confirm that the session change has been created/rebased
- Explain that future edits will be tracked in this change
Example usage
# Insert session after the parent of working copy
/jjagent:insert-after @-
# Insert with custom message
/jjagent:insert-after @-- "Implement user authentication"
# Insert after a specific change ID
/jjagent:insert-after qwerty123
Important notes
- The
$1(ref) must be an ancestor of@(working copy) - If a session change already exists, offer to rebase it
- Always validate the reference before creating/rebasing changes
- Use proper quoting when passing
$1to shell commands - When passing custom messages to
jjagent session-message, combine all arguments from$2onwards