@senad-d/branchme 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,8 +3,8 @@
3
3
  ## 0.1.0 - Unreleased
4
4
 
5
5
  - Implemented the `branchme` informational slash command with help aliases.
6
- - Added strict BranchMe tools: `branch_status`, `change_branch`, `create_branch`, `push_branch`, and `pull_request`.
7
- - Added argv-style git helpers for repository status, branch validation/creation/switching, clean-worktree preflight, upstream detection, and current-branch push/publish.
6
+ - Added strict BranchMe tools: `branch_status`, `change_branch`, `pull_branch`, `create_branch`, `push_branch`, and `pull_request`.
7
+ - Added argv-style git helpers for repository status, branch validation/creation/switching, clean-worktree preflight, upstream detection, fast-forward-only current-branch pull, and current-branch push/publish.
8
8
  - Added GitHub repository resolution, environment-token and local `.env` token fallback handling, REST pull request creation, response validation, and token redaction.
9
9
  - Added bounded automatic Git context before each agent run with branch/upstream state, working-tree counts and unstaged paths, authenticated related-open-PR lookup, and recent commits.
10
10
  - Expanded `branch_status` into a shared, explicit, read-only context refresh for state that may change during a run.
package/README.md CHANGED
@@ -11,12 +11,12 @@
11
11
 
12
12
  <p align="center">
13
13
  Current-repository branch and pull request tools for <a href="https://pi.dev">pi</a>.
14
- <br />Inspect branch state, switch/create branches, push, and open GitHub PRs from pi prompts.
14
+ <br />Inspect branch state, switch/create/update branches, push, and open GitHub PRs from pi prompts.
15
15
  </p>
16
16
 
17
17
  ---
18
18
 
19
- BranchMe is a Pi extension for safe branch workflow automation. Before each agent run, it appends a bounded, read-only snapshot of the current Git repository to the system prompt. It also adds an informational `/branchme` command and five agent-callable tools that explicitly refresh state, switch to an existing local branch, create a branch from the current `HEAD`, push the current branch, and create a GitHub pull request.
19
+ BranchMe is a Pi extension for safe branch workflow automation. Before each agent run, it appends a bounded, read-only snapshot of the current Git repository to the system prompt. It also adds an informational `/branchme` command and six agent-callable tools that explicitly refresh state, switch to an existing local branch, fast-forward the clean current branch from its upstream, create a branch from the current `HEAD`, push the current branch, and create a GitHub pull request.
20
20
 
21
21
  <table align="center">
22
22
  <tr>
@@ -30,8 +30,8 @@ BranchMe is a Pi extension for safe branch workflow automation. Before each agen
30
30
  </table>
31
31
 
32
32
  - **Context-aware:** every agent run starts with bounded branch, working-tree, related-PR, and recent-commit metadata; repository metadata is untrusted data, not instructions.
33
- - **Current-repository only:** Git and GitHub operations are scoped to the checkout where pi is running.
34
- - **Commit-safe:** context collection is read-only, and BranchMe never stages files, creates commits, generates commit messages, rebases, merges, resets, or edits files directly.
33
+ - **Current-repository only:** Git and GitHub operations are scoped to the checkout where pi is running; `pull_branch` updates only the clean current branch from its configured upstream.
34
+ - **Commit-safe:** context collection is read-only, and BranchMe never stages files, creates commits, generates commit messages, rebases, creates merge commits, resets, or edits files directly.
35
35
  - **Strict tools:** tool schemas reject extra properties such as `force`, `stash`, `discard`, `owner`, `repo`, `path`, or `baseRef`.
36
36
  - **PR-ready:** create GitHub pull requests from existing local branches after verifying the `headBranch` matches GitHub and the base is visible, with explicit PR fields and `GITHUB_TOKEN` or `GH_TOKEN` from the process environment or a local `.env` fallback.
37
37
 
@@ -81,12 +81,14 @@ A typical BranchMe flow is:
81
81
 
82
82
  1. Use the automatic snapshot to understand state at the start of the agent run.
83
83
  2. Use `branch_status` when you explicitly need fresh state, especially after a Git mutation in the same run.
84
- 3. Switch with `change_branch` or create from current `HEAD` with `create_branch`.
85
- 4. Make edits and commit outside BranchMe.
86
- 5. Push the current branch with `push_branch`.
87
- 6. After `push_branch` completes and GitHub can see the branches, create a pull request with `pull_request`.
84
+ 3. Switch to the local base branch with `change_branch`.
85
+ 4. Update it from its configured upstream with `pull_branch`, which requires a clean worktree and uses fast-forward-only semantics.
86
+ 5. Create from the updated `HEAD` with `create_branch`.
87
+ 6. Make edits and commit outside BranchMe.
88
+ 7. Push the current branch with `push_branch`.
89
+ 8. After `push_branch` completes and GitHub can see the branches, create a pull request with `pull_request`.
88
90
 
89
- BranchMe is tool-based. The slash command is informational only and never changes branches, pushes, commits, stages, edits files, or opens pull requests.
91
+ BranchMe is tool-based. The slash command is informational only and never changes or updates branches, pushes, commits, stages, edits files, or opens pull requests.
90
92
 
91
93
  ---
92
94
 
@@ -156,7 +158,7 @@ $EDITOR .env
156
158
  pi
157
159
  ```
158
160
 
159
- `push_branch` uses your normal Git remote credentials. BranchMe does not inject `GITHUB_TOKEN` into `git push`.
161
+ `pull_branch` and `push_branch` use your normal Git remote credentials. BranchMe does not inject `GITHUB_TOKEN` into `git pull` or `git push`.
160
162
  When the current branch already has an upstream, BranchMe pushes an explicit `HEAD:<upstream-branch-ref>` refspec to the configured upstream remote instead of relying on a bare `git push`.
161
163
  Run `pull_request` only after `push_branch` has completed; `pull_request` preflights the GitHub `headBranch` and `baseBranch` before creating the PR and fails with retry guidance if a branch is not visible yet or the GitHub `headBranch` commit does not match the local branch.
162
164
 
@@ -197,11 +199,12 @@ Commands are informational only. BranchMe actions are performed by agent-callabl
197
199
  | --- | --- | --- |
198
200
  | `branch_status` | `{}` | Explicitly refreshes the same bounded context used at agent start: repo root in structured details, branch/detached state, upstream and ahead/behind counts, working-tree counts and unstaged/untracked paths, related open PR, and recent commits. It is read-only. |
199
201
  | `change_branch` | `{ "branchName": string }` | Validates `branchName`, requires `refs/heads/<branchName>` to exist locally, rejects dirty worktrees, and runs `git switch <branchName>`. |
202
+ | `pull_branch` | `{}` | Requires a clean current branch with a configured upstream and runs `git pull --ff-only --no-rebase --no-autostash <upstream-remote> <upstream-branch-ref>`; divergence fails without rebasing or creating a merge commit. |
200
203
  | `create_branch` | `{ "branchName": string }` | Validates `branchName`, rejects existing local branches, and runs `git switch -c <branchName>` from current `HEAD`. |
201
204
  | `push_branch` | `{}` | Pushes the current branch to its configured upstream remote with an explicit `HEAD:<upstream-branch-ref>` refspec, or publishes it with `git push --set-upstream origin <currentBranch>` when no upstream exists. |
202
205
  | `pull_request` | `{ "headBranch": string, "baseBranch": string, "title": string, "body": string, "draft": boolean }` | Preflights GitHub branch visibility and verifies the GitHub `headBranch` commit matches the local branch, then creates a pull request in the resolved current repository via `POST /repos/{owner}/{repo}/pulls`; branch refs must exist locally and cannot use `owner:branch`. |
203
206
 
204
- All schemas reject additional properties. `change_branch` never accepts `baseRef`, `force`, `stash`, `discard`, `create`, `owner`, `repo`, or path inputs. `pull_request` never accepts `owner`, `repo`, or owner-prefixed branch refs; BranchMe resolves the repository from local `origin` and/or matching `GITHUB_REPOSITORY`.
207
+ All schemas reject additional properties. `change_branch` never accepts `baseRef`, `force`, `stash`, `discard`, `create`, `owner`, `repo`, or path inputs. `pull_branch` has a strict empty schema and never accepts a branch, remote, force, or rebase option. `pull_request` never accepts `owner`, `repo`, or owner-prefixed branch refs; BranchMe resolves the repository from local `origin` and/or matching `GITHUB_REPOSITORY`.
205
208
 
206
209
  ---
207
210
 
@@ -219,7 +222,7 @@ Before each agent run, BranchMe appends an **Automatic Git Context** snapshot to
219
222
 
220
223
  Collection defaults are a 5-second timeout per local Git command, a 4-second related-PR lookup timeout, at most 512 characters per metadata value, and at most 4,000 characters for the rendered snapshot. GitHub response bodies are limited to 64 KiB. The formatter can further shorten values or omit entries to stay within the total limit.
221
224
 
222
- The snapshot is fresh at agent start but is not live. A branch switch, commit, file change, push, or other mutation later in the same run can make it stale. `branch_status` performs an explicit current-state refresh through the same shared collector and remains read-only; it does not mutate files, Git state, or GitHub state.
225
+ The snapshot is fresh at agent start but is not live. A branch switch, pull, commit, file change, push, or other mutation later in the same run can make it stale. `branch_status` performs an explicit current-state refresh through the same shared collector and remains read-only; it does not mutate files, Git state, or GitHub state.
223
226
 
224
227
  Related-PR metadata does not come from Git alone. When repository, branch, and credentials resolve, automatic collection and explicit `branch_status` may make an authenticated `GET /repos/{owner}/{repo}/pulls?state=open&head={owner}:{branch}&per_page=1` request. Without a token there is no unauthenticated fallback or GitHub request; the PR field is reported as unavailable while local Git context remains usable.
225
228
 
@@ -229,7 +232,8 @@ Use BranchMe from pi prompts or automation that drives pi with explicit tool cal
229
232
 
230
233
  ```text
231
234
  Use branch_status.
232
- Create branch feature/docs-refresh from the current HEAD with create_branch.
235
+ Switch to the base branch with change_branch, then use pull_branch after the switch completes.
236
+ Create branch feature/docs-refresh from the updated current HEAD with create_branch.
233
237
  Push the current branch with push_branch.
234
238
  After push_branch completes, create a draft pull request from feature/docs-refresh to main titled "Refresh docs" with this body: "...".
235
239
  ```
@@ -239,6 +243,7 @@ BranchMe operates only on the repository where pi is running:
239
243
  - Automatic collection and `branch_status` run bounded, read-only Git commands from the verified git root.
240
244
  - Git commands use `pi.exec("git", args, { cwd, signal, timeout })` with argv arrays; repository mutations run from the verified git root.
241
245
  - `change_branch` switches only to existing local branches and has no `force`, `stash`, `discard`, remote, or path input.
246
+ - `pull_branch` requires a clean worktree and configured upstream, updates only the current branch with `git pull --ff-only --no-rebase --no-autostash`, and has no branch, remote, force, or rebase input.
242
247
  - `create_branch` creates from the current `HEAD` only and has no `baseRef` input.
243
248
  - `push_branch` pushes only the current branch, uses no bare upstream `git push`, and has no `branchName` input.
244
249
  - `pull_request` creates PRs only for the resolved current GitHub repository, requires `headBranch` and `baseBranch` to exist locally, requires the GitHub `headBranch` commit to match the local branch, queues behind in-flight same-repository git mutation windows when possible, and rejects `owner:branch` head refs.
@@ -287,10 +292,12 @@ Ensure the token and Git credentials have permission for the branch and pull req
287
292
  | Problem | Try |
288
293
  | --- | --- |
289
294
  | Not a git repository | Start pi from inside a git checkout. |
290
- | Detached `HEAD` | Use `change_branch` to switch to an existing local branch, or checkout a branch before `create_branch` or `push_branch`. |
295
+ | Detached `HEAD` | Use `change_branch` to switch to an existing local branch, or checkout a branch before `pull_branch`, `create_branch`, or `push_branch`. |
291
296
  | Branch already exists | Choose a new local branch name for `create_branch`, or use `change_branch` to switch to it. |
292
297
  | Branch does not exist locally | Create a local branch first; `change_branch` does not checkout remote branches. |
293
- | Dirty worktree before branch switch | Commit, stash, or discard changes outside BranchMe before using `change_branch`. |
298
+ | Dirty worktree before branch switch or pull | Commit, stash, or discard changes outside BranchMe before using `change_branch` or `pull_branch`. |
299
+ | Pull has no upstream | Configure the current branch upstream outside BranchMe, then retry `pull_branch`. |
300
+ | Pull is not a fast-forward | Reconcile the divergent branch outside BranchMe; `pull_branch` never rebases, force-updates, or creates a merge commit. |
294
301
  | Push fails | Confirm the current branch is correct and your normal Git remote credentials can push. |
295
302
  | Related PR is unavailable | Set `GITHUB_TOKEN` or `GH_TOKEN` before starting pi if related-PR context is wanted. Without a token, BranchMe keeps local context and intentionally makes no unauthenticated GitHub request. |
296
303
  | PR auth fails | Set `GITHUB_TOKEN` or `GH_TOKEN` before starting pi, or copy `.env.example` to `.env` and fill in one token. |
@@ -312,7 +319,7 @@ npm run check:pack
312
319
  printf '/branchme help\n/quit\n' | pi --no-extensions -e .
313
320
  ```
314
321
 
315
- Validation covers TypeScript typechecking, formatting checks, automatic context collection and prompt injection, mocked GitHub lookup, unit tests, package checks, checkout Pi runtime smoke, and package-content verification. The checkout smoke loads BranchMe through Pi, then uses a temporary verifier command to confirm all five BranchMe tools are visible through `pi.getAllTools()` with strict schemas and prompt metadata. Smoke-test notes are recorded in [`docs/SMOKE_TEST.md`](docs/SMOKE_TEST.md), and TUI/help captures are stored in [`docs/TUI_CAPTURE.md`](docs/TUI_CAPTURE.md).
322
+ Validation covers TypeScript typechecking, formatting checks, automatic context collection and prompt injection, mocked GitHub lookup, unit tests, package checks, checkout Pi runtime smoke, and package-content verification. The checkout smoke loads BranchMe through Pi, then uses a temporary verifier command to confirm all six BranchMe tools are visible through `pi.getAllTools()` with strict schemas and prompt metadata. Smoke-test notes are recorded in [`docs/SMOKE_TEST.md`](docs/SMOKE_TEST.md), and TUI/help captures are stored in [`docs/TUI_CAPTURE.md`](docs/TUI_CAPTURE.md).
316
323
 
317
324
  Refresh TUI captures intentionally with:
318
325
 
package/SECURITY.md CHANGED
@@ -17,14 +17,17 @@ Implemented git mutations are limited to:
17
17
 
18
18
  - `change_branch`: `git switch <branchName>` after branch-name validation, local `refs/heads/<branchName>` verification, and clean-worktree preflight.
19
19
  - `create_branch`: `git switch -c <branchName>` from current `HEAD` after branch-name validation and existing-branch checks.
20
+ - `pull_branch`: `git pull --ff-only --no-rebase --no-autostash <upstreamRemote> <upstreamBranchRef>` for the clean current branch after validating its configured upstream target.
20
21
  - `push_branch`: `git push <upstreamRemote> HEAD:<upstreamBranchRef>` for the current branch when an upstream exists, or `git push --set-upstream origin <currentBranch>` when no upstream exists.
21
22
 
22
23
  Before each agent run, BranchMe also runs bounded, read-only Git commands to collect branch/upstream/ahead-behind state, working-tree counts, up to 20 unstaged or untracked path entries, and up to 5 recent commits. The same collector runs when `branch_status` explicitly refreshes context. Collection does not run `switch`, `push`, `add`, `commit`, or any other mutation, and it never reads diffs or file contents.
23
24
 
24
- Branch switching can update working-tree files as normal Git checkout behavior. Mutating branch operations for the same repository are serialized to avoid same-turn branch races. `pull_request` also uses the same repository queue around PR preflight and creation so it can wait behind an already-started same-repository push. BranchMe rejects dirty worktrees before `change_branch` and does not force checkout, stash, stage files, create commits, reset, rebase, merge, or edit files directly.
25
+ Branch switching and fast-forward pulls can update working-tree files as normal Git behavior. Mutating branch operations for the same repository are serialized to avoid same-turn branch races. `pull_request` also uses the same repository queue around PR preflight and creation so it can wait behind an already-started same-repository mutation. BranchMe rejects dirty worktrees before `change_branch` and `pull_branch`. It does not force checkout, stash, stage files, create commits, reset, rebase, create merge commits, or edit files directly.
25
26
 
26
27
  ## Network behavior
27
28
 
29
+ `pull_branch` and `push_branch` contact the configured Git remote through the user's normal Git transport and credentials. They do not use or inject `GITHUB_TOKEN` or `GH_TOKEN`.
30
+
28
31
  BranchMe's GitHub helpers use these REST API requests:
29
32
 
30
33
  ```text
@@ -45,12 +48,15 @@ BranchMe operates on the current repository only.
45
48
  - The GitHub repository is inferred from local `origin` and/or `GITHUB_REPOSITORY`.
46
49
  - Tool inputs never accept filesystem paths, `owner`, `repo`, or owner-prefixed `owner:branch` PR refs.
47
50
  - `change_branch` accepts only `branchName` and never creates branches, checks out remote branches, forces, stashes, or discards changes.
51
+ - `pull_branch` accepts no parameters, updates only the clean current branch from its configured upstream, and uses fast-forward-only semantics.
48
52
  - If local `origin` and `GITHUB_REPOSITORY` both resolve but disagree, PR creation and related-PR lookup fail closed.
49
53
  - PR branch inputs are validated as existing local branch-name refs; missing local branches and cross-repository `head` values are rejected before token lookup or any GitHub request.
50
54
  - PR branch inputs must also be visible on GitHub before the PR is created, and `headBranch` must match the local branch commit; unpublished or stale `headBranch` values fail with guidance to run `push_branch`, wait for it to complete, and retry `pull_request`.
51
55
 
52
56
  ## Credentials
53
57
 
58
+ Git pull and push authentication is handled by the user's configured Git credential and transport setup. BranchMe never passes GitHub API tokens to Git commands.
59
+
54
60
  `pull_request` and related-PR lookup check `process.env.GITHUB_TOKEN`, then `process.env.GH_TOKEN`. If neither process token is set, BranchMe reads a local `.env` file from the verified git root and checks:
55
61
 
56
62
  - `GITHUB_TOKEN` (preferred)
@@ -18,7 +18,7 @@ pi --no-extensions -e .
18
18
  ## Automated smoke behavior
19
19
 
20
20
  - `npm run smoke:pi` first runs isolated checkout Pi processes from a temporary non-Git working directory: one with `pi --no-extensions -e <package> -e <temporary verifier>` and `/branchmeverify verify`, then one with `pi --no-extensions -e <package>` and `/branchme help`.
21
- - The temporary command verifier calls `pi.getAllTools()` after BranchMe loads and confirms `branch_status`, `change_branch`, `create_branch`, `push_branch`, and `pull_request` are active runtime tools with strict schemas, prompt guidelines, descriptions, and extension source metadata.
21
+ - The temporary command verifier calls `pi.getAllTools()` after BranchMe loads and confirms `branch_status`, `change_branch`, `pull_branch`, `create_branch`, `push_branch`, and `pull_request` are active runtime tools with strict schemas, prompt guidelines, descriptions, and extension source metadata.
22
22
  - A second temporary verifier registers a deterministic local smoke model, blocks `fetch`, and runs normal prompts through real Pi lifecycle handling. It verifies automatic no-tool Git context in a temporary repository, one real `branch_status` tool refresh after a verifier-created local change, safe credential-free related-PR status with no request, and non-Git startup fallback.
23
23
  - The checkout command smoke accepts either `/branchme help` text or the read-only BranchMe status fallback as equivalent non-mutating command output.
24
24
  - `npm run smoke:pi:packed` creates an npm tarball under a temporary directory, installs that tarball into a separate temporary package with `npm install --omit=dev`, and runs pi against the installed package instead of the source checkout.
@@ -32,7 +32,7 @@ pi --no-extensions -e .
32
32
  ## Result
33
33
 
34
34
  - `npm run validate` passed.
35
- - `npm run smoke:pi` loaded BranchMe through Pi, verified all five BranchMe tools through the real `pi.getAllTools()` runtime surface, and confirmed non-mutating BranchMe command output.
35
+ - `npm run smoke:pi` loaded BranchMe through Pi, verified all six BranchMe tools through the real `pi.getAllTools()` runtime surface, and confirmed non-mutating BranchMe command output.
36
36
  - The isolated Git-context prompt smoke observed the `before_agent_start` snapshot, answered branch and dirty-tree state without a tool call, refreshed a verifier-created local change through one real `branch_status` call, returned safe unavailable context without credentials or outside Git, and attempted no network request.
37
37
  - `npm run smoke:pi:packed` packed BranchMe outside the repository, installed the artifact in a temporary production workspace, loaded the installed package through Pi, and confirmed non-mutating BranchMe command output.
38
38
  - `npm run check:pack` confirmed the package contents are limited to public docs, images, source, license, package metadata, `.env.example`, and `tsconfig.json`.
package/docs/STRUCTURE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # BranchMe Structure Guide
2
2
 
3
- BranchMe is a TypeScript Pi extension package for current-repository git branch, push, and GitHub pull request workflows.
3
+ BranchMe is a TypeScript Pi extension package for current-repository git branch update, push, and GitHub pull request workflows.
4
4
 
5
5
  ## Source layout
6
6
 
@@ -13,7 +13,7 @@ src/
13
13
  ├── commands/
14
14
  │ └── branchme-command.ts # /branchme status/help command; informational only
15
15
  ├── tools/
16
- │ └── branchme-tools.ts # branch_status/change_branch/create_branch/push_branch/pull_request registration
16
+ │ └── branchme-tools.ts # branch_status/change_branch/pull_branch/create_branch/push_branch/pull_request registration
17
17
  ├── git.ts # argv-style git helpers and per-repo workflow queue
18
18
  ├── github.ts # GitHub repo resolution, env/.env tokens, branch preflight, REST calls, redaction
19
19
  └── ui/
@@ -22,11 +22,11 @@ src/
22
22
 
23
23
  ## Module boundaries
24
24
 
25
- 1. `src/extension.ts` stays small and registers the command, five tools, and one `before_agent_start` context hook.
25
+ 1. `src/extension.ts` stays small and registers the command, six tools, and one `before_agent_start` context hook.
26
26
  2. `src/git-context.ts` owns the shared read-only collector, escaped/bounded formatter, automatic system-prompt append, and the current-state output used by `branch_status`.
27
27
  3. `src/commands/branchme-command.ts` parses `/branchme`, `/branchme help`, `--help`, and `-h`; it never performs git or GitHub mutations and avoids raw stdout in JSON mode.
28
28
  4. `src/tools/branchme-tools.ts` owns TypeBox schemas, prompt metadata, tool content, and safe structured details. `branch_status` delegates to the shared context collector for an explicit refresh.
29
- 5. `src/git.ts` owns current-repository git behavior: root detection, branch/upstream/ahead-behind inspection, working-tree parsing, recent-commit collection, branch validation, branch creation, existing-local-branch switching, clean-worktree preflight, current-branch push/publish, and the per-repository workflow queue.
29
+ 5. `src/git.ts` owns current-repository git behavior: root detection, branch/upstream/ahead-behind inspection, working-tree parsing, recent-commit collection, branch validation, branch creation, existing-local-branch switching, clean-worktree preflight, fast-forward-only current-branch pull, current-branch push/publish, and the per-repository workflow queue.
30
30
  6. `src/github.ts` owns GitHub `owner/repo` parsing, repository boundary checks, `GITHUB_TOKEN`/`GH_TOKEN` process-env and hardened git-root `.env` fallback resolution, authenticated related-open-PR lookup, PR branch-name syntax validation, GitHub branch visibility/commit preflight, PR REST calls, bounded response validation, and redacted errors.
31
31
  7. `src/redaction.ts` owns shared credential redaction for Git, GitHub, and prompt-bound metadata.
32
32
  8. `src/types.ts` keeps serializable details shared by helpers, context, and tools.
@@ -36,7 +36,7 @@ src/
36
36
 
37
37
  - No long-lived processes, watchers, timers, sockets, or background jobs start in the extension factory.
38
38
  - A single `before_agent_start` handler synchronously collects a fresh snapshot for each agent run and appends it to the existing system prompt; failures degrade to bounded unavailable context rather than blocking startup.
39
- - Slash commands are informational; tools perform branch, push, and PR actions. There is no context command or sixth tool.
39
+ - Slash commands are informational; tools perform branch update, push, and PR actions. There is no context command or seventh tool.
40
40
  - Every tool uses a strict TypeBox object schema with `additionalProperties: false`.
41
41
  - Every tool defines a description, `promptSnippet`, and tool-specific `promptGuidelines` that explicitly name the tool.
42
42
  - Git commands use `pi.exec("git", args, { cwd, signal, timeout })` with argv arrays; repository mutations run from the verified git root and same-repository mutation/PR windows are serialized per repository.
@@ -51,11 +51,12 @@ src/
51
51
  - Related-PR lookup may issue an authenticated `GET /pulls` before every agent run and on explicit refresh. It has a 4-second timeout and 64 KiB response limit, and makes no unauthenticated fallback request.
52
52
  - The start-of-run snapshot may be stale after a mutation in that same run; `branch_status` is the explicit read-only refresh.
53
53
  - `change_branch` mutates local HEAD and working-tree files only through `git switch <branchName>` for existing local branches after a clean-worktree preflight.
54
+ - `pull_branch` requires a clean worktree and configured upstream, then updates only the current branch with an explicit `git pull --ff-only --no-rebase --no-autostash <remote> <remote-ref>` command; divergence fails without a rebase or merge commit.
54
55
  - `create_branch` mutates local branch/HEAD only with `git switch -c`.
55
56
  - `push_branch` mutates remote refs only for the current branch and uses an explicit upstream remote/refspec instead of bare `git push` when an upstream exists.
56
57
  - `pull_request` requires `headBranch` and `baseBranch` to exist locally, requires `headBranch` to match the GitHub-visible branch commit, queues behind already-started same-repository git mutation windows, makes GitHub REST API calls for the resolved current repository only, and rejects missing, owner-prefixed, or unsafe branch refs before token lookup or the request.
57
58
  - `pull_request` reads `GITHUB_TOKEN` or `GH_TOKEN` from process environment first; only when neither process token is set does it read those token keys from a small regular `.env` file in the verified git root as a fallback.
58
- - BranchMe does not force checkout, stash, stage, commit, directly edit files, read non-token `.env` keys, follow unsafe `.env` file types, depend on GitHub CLI, or collect telemetry.
59
+ - BranchMe does not force checkout, stash, stage, commit, rebase, create merge commits, directly edit files, read non-token `.env` keys, follow unsafe `.env` file types, depend on GitHub CLI, or collect telemetry.
59
60
 
60
61
  ## Documentation
61
62
 
@@ -23,16 +23,19 @@ Commands only show info; BranchMe tools perform actions.
23
23
  ## Workflow
24
24
 
25
25
  1. `branch_status` — inspect repo and branch state.
26
- 2. `change_branch` / `create_branch` — switch to an existing clean branch or create one from `HEAD`.
27
- 3. Commit outside BranchMe.
28
- 4. `push_branch` — push the current branch.
29
- 5. `pull_request` — open a PR after `push_branch` completes and GitHub sees the branches.
26
+ 2. `change_branch` — switch to the clean local base branch.
27
+ 3. `pull_branch` — fast-forward the current branch from its configured upstream.
28
+ 4. `create_branch` — create a new branch from the updated `HEAD`.
29
+ 5. Commit outside BranchMe.
30
+ 6. `push_branch` — push the current branch.
31
+ 7. `pull_request` — open a PR after `push_branch` completes and GitHub sees the branches.
30
32
 
31
33
  ## Requirements
32
34
 
33
35
  - Run inside a Git repo with `git` available.
34
36
  - For PRs: GitHub `origin` and `GITHUB_TOKEN` or `GH_TOKEN` (environment or `.env`).
35
- - BranchMe never stages or commits.
37
+ - `pull_branch` requires a clean working tree and configured upstream.
38
+ - BranchMe never stages, commits, rebases, or creates merge commits.
36
39
  ```
37
40
 
38
41
  ## Panel: Tiny mode: clean branch with token
@@ -98,12 +101,12 @@ Width: 80
98
101
  │ Status │ WORKFLOW │
99
102
  │▶ Workflow │ branch_status -> inspect │
100
103
  │ │ change_branch -> existing local │
104
+ │ │ pull_branch -> fast-forward │
101
105
  │ │ create_branch -> from HEAD │
102
106
  │ │ push_branch -> current branch │
103
107
  │ │ pull_request -> after push │
104
- │ │ │
105
108
  ├─────────────────────┴────────────────────────────────────────────────────────┤
106
- │ 2/2 • workflow • inspect → change/create → push → PR │
109
+ │ 2/2 • workflow • inspect → change → pull → create → push → PR │
107
110
  ╰──────────────────────────────────────────────────────────────────────────────╯
108
111
  ```
109
112
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@senad-d/branchme",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "description": "Minimal Pi extension for current-repository git branch, push, and pull request workflows.",
6
6
  "license": "MIT",
@@ -32,16 +32,19 @@ export function getBranchMeHelpText(): string {
32
32
  "## Workflow",
33
33
  "",
34
34
  "1. `branch_status` — inspect repo and branch state.",
35
- "2. `change_branch` / `create_branch` — switch to an existing clean branch or create one from `HEAD`.",
36
- "3. Commit outside BranchMe.",
37
- "4. `push_branch` — push the current branch.",
38
- "5. `pull_request` — open a PR after `push_branch` completes and GitHub sees the branches.",
35
+ "2. `change_branch` — switch to the clean local base branch.",
36
+ "3. `pull_branch` — fast-forward the current branch from its configured upstream.",
37
+ "4. `create_branch` — create a new branch from the updated `HEAD`.",
38
+ "5. Commit outside BranchMe.",
39
+ "6. `push_branch` — push the current branch.",
40
+ "7. `pull_request` — open a PR after `push_branch` completes and GitHub sees the branches.",
39
41
  "",
40
42
  "## Requirements",
41
43
  "",
42
44
  "- Run inside a Git repo with `git` available.",
43
45
  "- For PRs: GitHub `origin` and `GITHUB_TOKEN` or `GH_TOKEN` (environment or `.env`).",
44
- "- BranchMe never stages or commits.",
46
+ "- `pull_branch` requires a clean working tree and configured upstream.",
47
+ "- BranchMe never stages, commits, rebases, or creates merge commits.",
45
48
  ].join("\n");
46
49
  }
47
50
 
package/src/constants.ts CHANGED
@@ -4,6 +4,7 @@ export const BRANCHME_COMMAND_NAME = "branchme";
4
4
  export const BRANCH_STATUS_TOOL_NAME = "branch_status";
5
5
  export const CREATE_BRANCH_TOOL_NAME = "create_branch";
6
6
  export const CHANGE_BRANCH_TOOL_NAME = "change_branch";
7
+ export const PULL_BRANCH_TOOL_NAME = "pull_branch";
7
8
  export const PUSH_BRANCH_TOOL_NAME = "push_branch";
8
9
  export const PULL_REQUEST_TOOL_NAME = "pull_request";
9
10
 
@@ -11,12 +12,14 @@ export const BRANCHME_TOOL_NAMES = [
11
12
  BRANCH_STATUS_TOOL_NAME,
12
13
  CREATE_BRANCH_TOOL_NAME,
13
14
  CHANGE_BRANCH_TOOL_NAME,
15
+ PULL_BRANCH_TOOL_NAME,
14
16
  PUSH_BRANCH_TOOL_NAME,
15
17
  PULL_REQUEST_TOOL_NAME,
16
18
  ] as const;
17
19
 
18
20
  export const GIT_STATUS_TIMEOUT_MS = 5_000;
19
21
  export const GIT_MUTATION_TIMEOUT_MS = 30_000;
22
+ export const GIT_PULL_TIMEOUT_MS = 120_000;
20
23
  export const GIT_PUSH_TIMEOUT_MS = 120_000;
21
24
  export const GITHUB_RELATED_PR_TIMEOUT_MS = 4_000;
22
25
 
package/src/git.ts CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  GIT_CONTEXT_RECENT_COMMIT_LIMIT,
5
5
  GIT_CONTEXT_VALUE_LIMIT_CHARS,
6
6
  GIT_MUTATION_TIMEOUT_MS,
7
+ GIT_PULL_TIMEOUT_MS,
7
8
  GIT_PUSH_TIMEOUT_MS,
8
9
  GIT_STATUS_TIMEOUT_MS,
9
10
  MAX_SUMMARY_OUTPUT_CHARS,
@@ -18,6 +19,7 @@ import type {
18
19
  GitExecResult,
19
20
  GitFileChange,
20
21
  GitFileChangeSummary,
22
+ PullBranchDetails,
21
23
  PushBranchDetails,
22
24
  RecentCommit,
23
25
  WorkingTreeDetails,
@@ -182,6 +184,12 @@ export async function getUpstreamBranch(
182
184
  return upstream || null;
183
185
  }
184
186
 
187
+ interface ConfiguredUpstreamTarget {
188
+ upstream: string;
189
+ remote: string;
190
+ remoteRef: string;
191
+ }
192
+
185
193
  interface PushTarget {
186
194
  upstream: string | null;
187
195
  mode: "push" | "publish";
@@ -191,21 +199,23 @@ interface PushTarget {
191
199
  args: string[];
192
200
  }
193
201
 
194
- function validateRemoteName(remote: string): void {
195
- if (!remote) throw new Error("Unable to push current branch: upstream remote is missing.");
196
- if (remote === ".") throw new Error("Unable to push current branch: upstream is a local branch, not a remote.");
197
- if (remote.startsWith("-")) throw new Error("Unable to push current branch: upstream remote cannot start with '-'.");
202
+ type UpstreamOperation = "pull" | "push";
203
+
204
+ function validateRemoteName(remote: string, operation: UpstreamOperation): void {
205
+ if (!remote) throw new Error(`Unable to ${operation} current branch: upstream remote is missing.`);
206
+ if (remote === ".") throw new Error(`Unable to ${operation} current branch: upstream is a local branch, not a remote.`);
207
+ if (remote.startsWith("-")) throw new Error(`Unable to ${operation} current branch: upstream remote cannot start with '-'.`);
198
208
  if (remote.includes(":") || remote.includes("@")) {
199
- throw new Error("Unable to push current branch: upstream remote name cannot be a URL or user-prefixed target.");
209
+ throw new Error(`Unable to ${operation} current branch: upstream remote name cannot be a URL or user-prefixed target.`);
200
210
  }
201
211
  if (/[\u0000-\u001f\u007f]/u.test(remote) || /\s/u.test(remote)) {
202
- throw new Error("Unable to push current branch: upstream remote contains whitespace or control characters.");
212
+ throw new Error(`Unable to ${operation} current branch: upstream remote contains whitespace or control characters.`);
203
213
  }
204
214
  }
205
215
 
206
- function normalizeRemoteHeadRef(mergeRef: string): string {
216
+ function normalizeRemoteHeadRef(mergeRef: string, operation: UpstreamOperation): string {
207
217
  if (!mergeRef.startsWith("refs/heads/")) {
208
- throw new Error("Unable to push current branch: upstream merge ref is not a branch ref.");
218
+ throw new Error(`Unable to ${operation} current branch: upstream merge ref is not a branch ref.`);
209
219
  }
210
220
 
211
221
  const branchName = mergeRef.slice("refs/heads/".length);
@@ -231,15 +241,39 @@ async function getBranchConfigValue(
231
241
  return value || null;
232
242
  }
233
243
 
234
- async function resolvePushTarget(
244
+ async function resolveConfiguredUpstreamTarget(
235
245
  pi: Pick<ExtensionAPI, "exec">,
236
246
  ctx: GitCommandContext,
237
247
  currentBranch: string,
248
+ operation: UpstreamOperation,
238
249
  signal?: AbortSignal,
239
- ): Promise<PushTarget> {
250
+ ): Promise<ConfiguredUpstreamTarget | null> {
240
251
  validateBranchNameInput(currentBranch);
241
252
  const upstream = await getUpstreamBranch(pi, ctx, signal);
242
- if (!upstream) {
253
+ if (!upstream) return null;
254
+
255
+ const remote = await getBranchConfigValue(pi, ctx, currentBranch, "remote", signal);
256
+ const mergeRef = await getBranchConfigValue(pi, ctx, currentBranch, "merge", signal);
257
+ if (!remote || !mergeRef) {
258
+ throw new Error(`Unable to ${operation} current branch: upstream exists but branch remote/merge configuration is incomplete.`);
259
+ }
260
+
261
+ validateRemoteName(remote, operation);
262
+ return {
263
+ upstream,
264
+ remote,
265
+ remoteRef: normalizeRemoteHeadRef(mergeRef, operation),
266
+ };
267
+ }
268
+
269
+ async function resolvePushTarget(
270
+ pi: Pick<ExtensionAPI, "exec">,
271
+ ctx: GitCommandContext,
272
+ currentBranch: string,
273
+ signal?: AbortSignal,
274
+ ): Promise<PushTarget> {
275
+ const upstreamTarget = await resolveConfiguredUpstreamTarget(pi, ctx, currentBranch, "push", signal);
276
+ if (!upstreamTarget) {
243
277
  const remoteRef = `refs/heads/${currentBranch}`;
244
278
  return {
245
279
  upstream: null,
@@ -251,22 +285,12 @@ async function resolvePushTarget(
251
285
  };
252
286
  }
253
287
 
254
- const remote = await getBranchConfigValue(pi, ctx, currentBranch, "remote", signal);
255
- const mergeRef = await getBranchConfigValue(pi, ctx, currentBranch, "merge", signal);
256
- if (!remote || !mergeRef) {
257
- throw new Error("Unable to push current branch: upstream exists but branch remote/merge configuration is incomplete.");
258
- }
259
-
260
- validateRemoteName(remote);
261
- const remoteRef = normalizeRemoteHeadRef(mergeRef);
262
- const refspec = `HEAD:${remoteRef}`;
288
+ const refspec = `HEAD:${upstreamTarget.remoteRef}`;
263
289
  return {
264
- upstream,
290
+ ...upstreamTarget,
265
291
  mode: "push",
266
- remote,
267
- remoteRef,
268
292
  refspec,
269
- args: ["push", remote, refspec],
293
+ args: ["push", upstreamTarget.remote, refspec],
270
294
  };
271
295
  }
272
296
 
@@ -676,6 +700,41 @@ export async function changeExistingLocalBranch(
676
700
  });
677
701
  }
678
702
 
703
+ export async function pullCurrentBranch(
704
+ pi: Pick<ExtensionAPI, "exec">,
705
+ ctx: GitCommandContext,
706
+ signal?: AbortSignal,
707
+ ): Promise<PullBranchDetails> {
708
+ const repoRoot = await getGitRoot(pi, ctx, signal);
709
+ const rootCtx = { cwd: repoRoot };
710
+
711
+ return withRepositoryMutationQueue(repoRoot, async () => {
712
+ const currentBranch = await requireCurrentBranch(pi, rootCtx, signal);
713
+ if (await hasWorkingTreeChanges(pi, rootCtx, signal)) {
714
+ throw new Error("Working tree has uncommitted changes; clean it before pulling the current branch.");
715
+ }
716
+
717
+ const target = await resolveConfiguredUpstreamTarget(pi, rootCtx, currentBranch, "pull", signal);
718
+ if (!target) {
719
+ throw new Error(`Unable to pull current branch '${safeDetail(currentBranch)}': no upstream is configured.`);
720
+ }
721
+
722
+ const result = await runGit(pi, rootCtx, ["pull", "--ff-only", "--no-rebase", "--no-autostash", target.remote, target.remoteRef], {
723
+ signal,
724
+ timeout: GIT_PULL_TIMEOUT_MS,
725
+ });
726
+
727
+ return {
728
+ repoRoot,
729
+ currentBranch: safeDetail(currentBranch),
730
+ upstream: safeDetail(target.upstream),
731
+ remote: safeDetail(target.remote),
732
+ remoteRef: safeDetail(target.remoteRef),
733
+ output: safeOutput(result.stdout || result.stderr),
734
+ };
735
+ });
736
+ }
737
+
679
738
  export async function pushCurrentBranch(
680
739
  pi: Pick<ExtensionAPI, "exec">,
681
740
  ctx: GitCommandContext,
@@ -4,6 +4,7 @@ import {
4
4
  BRANCH_STATUS_TOOL_NAME,
5
5
  CHANGE_BRANCH_TOOL_NAME,
6
6
  CREATE_BRANCH_TOOL_NAME,
7
+ PULL_BRANCH_TOOL_NAME,
7
8
  PULL_REQUEST_TOOL_NAME,
8
9
  PUSH_BRANCH_TOOL_NAME,
9
10
  } from "../constants.ts";
@@ -13,6 +14,7 @@ import {
13
14
  getGitRoot,
14
15
  getLocalBranchCommit,
15
16
  localBranchExists,
17
+ pullCurrentBranch,
16
18
  pushCurrentBranch,
17
19
  validateBranchName,
18
20
  withRepositoryMutationQueue,
@@ -197,6 +199,26 @@ export function registerBranchMeTools(pi: Pick<ExtensionAPI, "registerTool" | "e
197
199
  },
198
200
  });
199
201
 
202
+ pi.registerTool({
203
+ name: PULL_BRANCH_TOOL_NAME,
204
+ label: "Pull Branch",
205
+ description: "pull_branch updates the current branch from its configured upstream with git pull --ff-only --no-rebase --no-autostash. pull_branch requires a clean working tree and never rebases, creates merge commits, force-updates, stashes, stages, or commits.",
206
+ promptSnippet: "pull_branch: fast-forward the clean current branch from its configured upstream without rebasing",
207
+ promptGuidelines: [
208
+ "Use pull_branch only when the user explicitly wants to update the current branch from its configured upstream.",
209
+ "Use pull_branch only on a clean working tree with an upstream; pull_branch has no branchName, remote, force, or rebase parameters.",
210
+ "Do not call pull_branch in the same tool batch as change_branch or create_branch; call pull_branch after change_branch completes, then call create_branch after pull_branch completes.",
211
+ ],
212
+ parameters: EmptyParametersSchema,
213
+ async execute(_toolCallId, _params, signal, _onUpdate, ctx) {
214
+ const details = await pullCurrentBranch(pi, ctx, signal);
215
+ return {
216
+ content: [{ type: "text", text: `Pulled current branch ${details.currentBranch} with fast-forward-only semantics.` }],
217
+ details,
218
+ };
219
+ },
220
+ });
221
+
200
222
  pi.registerTool({
201
223
  name: PUSH_BRANCH_TOOL_NAME,
202
224
  label: "Push Branch",
package/src/types.ts CHANGED
@@ -87,6 +87,15 @@ export interface ChangeBranchDetails {
87
87
  hasChangesBeforeSwitch: false;
88
88
  }
89
89
 
90
+ export interface PullBranchDetails {
91
+ repoRoot: string;
92
+ currentBranch: string;
93
+ upstream: string;
94
+ remote: string;
95
+ remoteRef: string;
96
+ output: string;
97
+ }
98
+
90
99
  export interface PushBranchDetails {
91
100
  repoRoot: string;
92
101
  currentBranch: string;
@@ -177,7 +177,7 @@ function sectionFooter(section: BranchMePanelSection, data: BranchMePanelData):
177
177
  case "status":
178
178
  return "status • current repository only • tools perform actions";
179
179
  case "workflow":
180
- return "workflow • inspect → change/create → push → PR";
180
+ return "workflow • inspect → change → pull → create → push → PR";
181
181
  }
182
182
  }
183
183
 
@@ -197,6 +197,7 @@ function sectionRows(section: BranchMePanelSection, data: BranchMePanelData): Pa
197
197
  heading("WORKFLOW"),
198
198
  workflowDetailRow("branch_status", "inspect"),
199
199
  workflowDetailRow("change_branch", "existing local"),
200
+ workflowDetailRow("pull_branch", "fast-forward"),
200
201
  workflowDetailRow("create_branch", "from HEAD"),
201
202
  workflowDetailRow("push_branch", "current branch"),
202
203
  workflowDetailRow("pull_request", "after push"),