Skip to content

Commit 40db296

Browse files
authored
Merge pull request #938 from jupyter-naas/fix-pretty-markdown
fix: improve markdown transformation handling in GitAgent
2 parents 6b6154a + 6f368f0 commit 40db296

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

  • libs
    • naas-abi-core/naas_abi_core/services/agent
    • naas-abi-marketplace/naas_abi_marketplace/applications/git/agents

libs/naas-abi-core/naas_abi_core/services/agent/Agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,9 @@ def _pretty_display_markdown(
865865
self,
866866
response: BaseMessage,
867867
) -> BaseMessage:
868+
if len(response.content) > 0:
869+
return response
870+
868871
prompt = [
869872
SystemMessage(
870873
content=(
@@ -896,7 +899,7 @@ def _pretty_display_markdown(
896899
- If the input is already well-formatted, make minimal changes."""
897900
)
898901
),
899-
AIMessage(content=(f"Initial content:\n{response.content}")),
902+
HumanMessage(content=(f"Initial content:\n{response.content}")),
900903
]
901904

902905
try:

libs/naas-abi-marketplace/naas_abi_marketplace/applications/git/agents/GitAgent.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class GitAgent(Agent):
2121
- inspect the repository state (branch, status, staged diff, recent commits, whether the branch exists on origin)
2222
- generate a pull request description by invoking the PullRequestDescriptionAgent
2323
- commit staged changes
24-
- restore accidental working-tree changes (e.g. lockfile churn)
24+
- restore accidental working-tree changes and commit lockfile updates in a dedicated chore commit
2525
- push the branch (ONLY when explicitly requested)
2626
- find/create/update/view a GitHub pull request via `gh`
2727
@@ -31,25 +31,24 @@ class GitAgent(Agent):
3131
- Do NOT require staged or unstaged changes. Commits already on the branch are enough. `pull_request_description` compares the branch to the base (e.g. `origin/main...HEAD`) and does not need a staged diff.
3232
- First check if a PR already exists for the current branch using `gh_pr_find_for_branch`.
3333
- If it exists: call `pull_request_description`, then update with `gh_pr_edit`, then show the PR via `gh_pr_view`.
34-
- If it does not exist: call `git_remote_branch_exists`. If false, explain that the branch must be on origin before opening a PR; do NOT push unless the user explicitly asked to push (offer that they can ask you to push).
35-
- If the branch is on origin (or after a user-requested push): call `pull_request_description`, then create with `gh_pr_create`, then `gh_pr_view`.
34+
- If it does not exist: call `git_remote_branch_exists`. If false, automatically push the branch to origin using `git_push` (which sets the upstream), then proceed.
35+
- Once the branch is on origin: call `pull_request_description`, then create with `gh_pr_create`, then `gh_pr_view`.
3636
- If the user asks to **open/update a PR** after or alongside committing: follow the commit workflow when they asked to commit; then apply the PR-only rules above for create/update/view.
37-
- If the user asks to open/update a PR but does NOT explicitly ask to push: you MUST NOT push.
38-
- If a new PR cannot be created because the branch is not on origin, explain that pushing is required and stop (unless they explicitly asked to push).
37+
- Whenever a PR needs to be created/updated and the branch is not yet on origin, always push it automatically using `git_push` before attempting to create the PR.
3938
4039
Standard workflow — pick the path that matches the user request:
4140
4241
**Path PR-only** (user asked to open/update a PR and did NOT ask to commit new changes):
4342
1) Optionally call `git_status` or `git_log` for context.
4443
2) Call `pull_request_description` and use its output as the PR body (it reflects all commits on the branch vs base).
4544
3) If the branch name starts with digits (e.g. "123-fix-..."), ensure the PR body starts with: "This pull request resolves #123"
46-
4) `gh_pr_find_for_branch` → if a PR exists: `gh_pr_edit` with a sensible title/body; if not: ensure branch is on origin (`git_remote_branch_exists`), then `gh_pr_create` if possible → `gh_pr_view`.
45+
4) `gh_pr_find_for_branch` → if a PR exists: `gh_pr_edit` with a sensible title/body; if not: check `git_remote_branch_exists` — if false, call `git_push` to push the branch to origin first — then `gh_pr_create` → `gh_pr_view`.
4746
4847
**Path commit** (user asked to commit):
4948
1) Call `git_status` and `git_diff_staged`. If nothing is staged, stop and explain that staging is required to commit.
5049
2) Draft a Conventional Commit message (type/scope/subject) based on the staged diff.
5150
3) Call `git_commit` with that message.
52-
4) Call `git_status` again; if only lockfiles changed by hooks/tooling (e.g. `uv.lock`) and are unrelated, call `git_restore` on them to keep the PR focused.
51+
4) Call `git_status` again; if lockfiles (e.g. `uv.lock`, `pnpm-lock.yaml`, `package-lock.json`) were modified by hooks/tooling and are unstaged, stage and commit them in a dedicated commit with message `chore: update lockfile`.
5352
5) If the user explicitly asked to push, call `git_push`.
5453
6) If the user also asked to open/update a PR, continue with **Path PR-only** steps 2–4.
5554

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)