* feat(forge): let providers declare their hosts, names, sign-in, and review decisions Prepare the forge contract for a second provider: - ForgeProvider lists the hosts it serves and names itself (label, changeRequestNoun); registering a provider that lists a host another registered provider lists throws, so each URL has at most one provider. ctx.forge.describe(forge) returns the family's ForgeDescription. - ForgeReadiness carries the sign-in command, which the panel's sign-in banner shows instead of building `gh auth login` for the github family. - ForgeReviewData lists the review decisions the host lets the reader record; the review dialog offers only those instead of hardcoding the GitHub rule that a pull request's author may only comment. - ForgeReviewThread.original may name a later commit the host carried the thread to while its lines stayed unchanged. - The changes view names the code host and its word for a change request from the entry's ForgeDescription instead of hardcoding GitHub and PR. The GitHub provider declares its configured hosts, GitHub, pull requests, `gh auth login --hostname <host>`, and reads viewerDidAuthor for the review decisions. Upgrade guide: forge-provider-hosts. * feat(forge-gitlab): read GitLab merge requests through the GitLab CLI Add the experimental forge-gitlab provider. It serves the configured GitLab hosts through glab: status batches over GraphQL, head-pinned patches from merge request diff versions, commit listings, merge bases, pipeline jobs, closing issues, and review threads mapped from REST discussions, including outdated threads' hunks. The forge bundle composes the provider, disabled by default. * feat(forge-gitlab): write GitLab reviews, retry pipelines, request reviews, and rebase The GitLab provider now writes through glab as well as reading: comments start discussions at positions derived from the head's diff version, pending replies and comments are draft notes that a review publishes with its summary and review state, and approving checks the head through GitLab's sha parameter. Review reads carry the signed-in user's rights from GraphQL, their draft notes as the pending review, and the decisions GitLab lets them record. Snapshots name the head pipeline as every job's rerun, offer rebase as the branch update, and follow GitLab's permissions for reruns and review requests. updateBranch's contract now states how a provider whose host takes no expected head checks it. * feat(forge): let forge providers register the commands that bind change requests forge-session no longer recognizes gh commands by itself. A provider now registers a declarative ForgeCommandRule through ctx.forgeSession.registerCommands: its executable, creation and reference subcommands, change request page path, JSON URL members, declared options, and a pure select that maps one parsed reference command to a URL or a read-only lookup. forge-github registers gh and forge-gitlab registers glab, which adds glab mr create, view, update, and checkout, including numbers with -R: a full project URL binds directly, and other repository forms resolve through glab mr view in the call's shell. forge-session keeps the shared parts: the literal shell tokenizer, option parsing, output reading, lookups, and the projection. The forgeChangeRequests state version derives from the recognized rules, so a changed rule set refolds every Session, including commands that ran before the provider loaded. Ending a registration keeps its rule recognized until restart, so unloading providers at shutdown does not rewrite every checkpoint. * refactor(forge-gitlab): publish the GitLab provider as @deepseek-ai/dsh-forge-gitlab New experimental packages omit the experimental prefix so that promotion keeps their npm name. Register the directory in EXPERIMENTAL_PACKAGE_NAME_EXCEPTIONS instead of growing the legacy prefixed list, and rename every dependency, configuration row, path mapping, and document that names the package. * fix(forge-gitlab): keep review writes, comment positions, and reads within GitLab's facts and the limits - After GitLab refuses a publication, read the drafts again: delete them only when all remain, since GitLab can publish them before it refuses the summary, and report the outcome as unknown otherwise. A rollback that leaves drafts reports how many may remain. - Place comments on files GitLab collapsed through the diff compared from their texts, and let a file's new path name it over another file's old path after chained renames. - Keep the final newline of raw file reads. - Apply maxOutputBytes to the complete review result, and report a read whose rights stop early or skip a discussion's later notes as truncated. - Serve a version over maxCachedVersionBytes without keeping it. - Resolve uploaded avatars GitLab names by their path on the host. - Schedule bounded reads through p-limit. * fix(forge-session): run lookups only for live command rules and keep the projection registered - Reference lookups use the rules of live registrations, so a disposed provider's rule still folds but starts no gh or glab process. - A failed re-registration registers the projection again with the earlier rules, so clients keep its view; an error is logged only when that fails too. - Document the startup re-registration, test that the checkpointed state version survives a real Loader start, shutdown, and restart, and record that starting without a provider removes the bindings only its commands made. - Describe the changes view's pending review and single comment without naming GitHub, which keeps its own rule in forge-github, and render registerCommands as code in the generated service reference. * fix(forge-bundle): name GitLab merge requests in the bundle description The bundle now follows GitLab merge requests as well as GitHub pull requests, so the description's first sentence in every locale names both kinds of change request. * feat(forge): bind the change requests that gh api and glab api requests name Models often read a merge request through `glab api` or a pull request through `gh api` instead of `glab mr view` or `gh pr view`, which left the change request unbound. A command rule now declares raw API request subcommands beside its reference subcommands, each group with its own options, since `-f` is a value of `gh api` and a flag of `gh pr checkout`. An API request binds, as referenced, only the change request its REST path names, such as `projects/group%2Fapp/merge_requests/7/changes` or `repos/octo/demo/pulls/7/files`; its output is not read, since one request can list many change requests. A path whose host the command names binds directly, and one without a host, or with the current repository's placeholders, resolves through the CLI's view command in the call's shell. The gh and glab rules move to version 2. * docs(forge): add forge-gitlab and the forge-session peers to the module graph Regenerate docs/module-graph for the renamed GitLab provider and the optional forge-session peer of both providers. * test(web): refresh the forge bundle description in the recommended plugin catalog The creation recommendation recording carries every recommended plugin's description; refresh it for the forge bundle description that now names GitLab merge requests and the glab sign-in. * chore(forge-gitlab): carry the 0.2.2-rc.3 release version and move upgrade guides to v0.2.2-rc.3
18 KiB
description, kind
| description | kind |
|---|---|
| Serve the experimental forge registry for GitLab hosts through the GitLab CLI on the host. | package-reference |
@deepseek-ai/dsh-forge-gitlab
English | 中文
Summary
Read and write GitLab.com and self-managed GitLab merge requests for ctx.forge with the GitLab CLI that is already signed in on the host. Each poll reads state, changed lines, head pipeline jobs, reviewers and approvals, mergeability, unresolved discussions, and closing issues for every due merge request; the changes view reads the diff pinned to the head, the commits, and the review threads with their positions at the head and where they were last seen. It writes comments as discussions and draft notes, resolves discussions, submits and approves reviews, marks drafts ready, merges, retries pipelines, requests reviews, and rebases.
Table of Contents
- Use this package
- Understand the implementation
- Further Exploration
- Model Experience
- Known Limitations and Deferred Work
- Dev Note
Use this package
Mount the provider after the forge registry and list every self-managed host explicitly. The Forge bundle mounts it with gitlab.com.
- name: '@deepseek-ai/dsh-experimental-forge'
- name: '@deepseek-ai/dsh-forge-gitlab'
config:
hosts: [gitlab.com, gitlab.example.com]
The provider runs glab as a host process, even when Sessions execute commands in another execution world. Sign in once per host with glab auth login --hostname <host>. The child receives the host environment without DSH_* variables, without variables whose names contain KEY, PASSWORD, SECRET, or TOKEN, and without the variables that make glab choose another host, repository, or remote, such as GITLAB_HOST, GITLAB_REPO, and GLAB_REMOTE_ALIAS; it runs in the temporary directory, because inside a checkout glab resolves project paths against that checkout's remotes. Prompts, update checks, telemetry, pagers, and colors are disabled, and every request names its host with --hostname. Numeric limits must be positive safe integers; only timeoutMs is bounded by the runtime timer limit. glabCommand, hosts, timeoutMs, maxOutputBytes, maxReviewThreads, maxCommits, statusBatchSize, maxConcurrentRequests, and maxCachedVersionBytes are listed in the configuration catalog.
The provider lists its configured hosts in lowercase as hosts, names itself GitLab, and calls change requests merge requests. It serves a remote URL in https, http, ssh, or git form, or in scp form such as [email protected]:group/sub/app.git, when its host is configured; nested groups form the repository's owner, such as group/sub. HTTP(S) remotes retain custom ports in the host identity; SSH and Git transport ports are excluded. It serves merge request URLs of the form https://<host>/<namespace>/<project>/-/merge_requests/<number> with any trailing path, query, or fragment, and builds that form without the suffix as the canonical URL; fileUrl returns https://<host>/<namespace>/<project>/-/blob/<commit>/<path>. A readiness probe reads the REST user resource: success is ready, a refusal of the credentials is unauthenticated with glab auth login --hostname <host> as its sign-in command, and any other failure, including a glab that cannot start, is unavailable. A head lookup returns up to 20 open merge requests whose source branch is the branch and whose source project is the target project, newest first; a lookup of the project's default branch returns none.
While forge-session runs, the plugin registers the glab command rule with it. glab mr create and glab mr new bind the merge requests they print. glab mr view, glab mr update, and glab mr checkout bind the merge request that a URL selects, or a number with --repo, --repo=, or -R before or after it; a full http or https project URL supplies the URL directly, and any other repository form, such as group/app or a Git URL, resolves through glab mr view <number> --repo <repository> --output json --jq .web_url in the call's shell, which applies that shell's glab configuration and GITLAB_HOST. glab api binds the merge request its REST path names, such as projects/group%2Fapp/merge_requests/7/changes, with a leading / or api/v4/ or as a full API URL: directly when --hostname or the URL names the host, else through glab mr view <number> --repo <path>, or without --repo for the :fullpath and :id placeholders; a numeric project id names nothing.
A fetch groups references by host, splits each group into batches of statusBatchSize merge requests (default 2), and runs at most maxConcurrentRequests (default 4) GraphQL queries at once. GitLab refuses a query whose complexity passes 250, which a merge request with 20 reviewers, 20 approvers, and 50 jobs nearly reaches alone, so a refused batch is halved and read again. Mergeability comes from detailedMergeStatus, mergeStatus, and conflicts. The query selects the merge status before diffStatsSummary, after which GitLab 19.5 reports CONFLICT for a merge request it found mergeable. UNCHECKED, CHECKING, PREPARING, and APPROVALS_SYNCING are unknown, and so is a merge status GitLab has not checked since a change (UNCHECKED or CANNOT_BE_MERGED_RECHECK), whatever its last outcome says; GitLab checks it again only when a REST read of the merge request asks it to, so the poll sends one and a later poll reads the outcome. Otherwise CONFLICT is conflicting even while conflicts is false. A merge request is ready to merge when it is open, not a draft, MERGEABLE, not conflicting, and the signed-in user may merge it. The project's fast-forward setting makes the merge method rebase instead of merge, and the merge request's squash settings add, force, or omit squash. The review decision is changes-requested when a reviewer's state is REQUESTED_CHANGES, approved when GitLab reports the merge request approved, and review-required for NOT_APPROVED. Reviewers come first, then approvers who are not reviewers, never the author; a reviewer whose review is awaited is requested, and reviewer states map to approved, changes-requested, commented, and dismissed. Checks are the head pipeline's jobs without the ones a retry replaced: a failed job allowed to fail is neutral, a manual job is pending unless it is allowed to fail, which makes it skipped, and the pipeline's status decides the rollup. Every job names its pipeline's global id as its rerun, since GitLab retries a pipeline's failed and cancelled jobs together, and canRerunChecks follows the signed-in user's right to update the head pipeline. A poll reads the first 50 jobs; fetchChecks reads the rest 100 per page, refusing a page whose head moved. branchUpdates offers rebase, GitLab's only branch update, while the branches have diverged without conflicts, no rebase runs, and the user may push to the head branch; canRequestReviews follows the user's right to update the merge request. The unresolved count is GitLab's resolvable discussions less the resolved ones. Closing issues come from REST closes_issues, up to 25, and are read again only when the merge request's update time changes; a failed read keeps the last list marked truncated.
diff reads the newest MR diff version, which GitLab records for every push, and returns stale unless its head is the requested commit; it then joins the version's per-file diffs into one patch with Git's headers, ordered by path as GitLab's raw patch is, and compares a file GitLab collapsed or found too large from its text at both commits. A version whose real_size ends in +, which GitLab sets past its file limit, is too-large. For every open merge request measured, the patch matched GitLab's raw patch except for Git's index lines. commits lists the merge request's commits oldest first, at most maxCommits (default 250), reading the pages that hold the oldest ones when GitLab's X-Total counts more. compare reads repository/compare between two commits and reports a comparison GitLab stopped for time as too-large, and mergeBase reads repository/merge_base. fileText reads repository/files/<path>/raw at a full commit.
readReview reads REST discussions 100 per page until maxReviewThreads threads, beside GraphQL pages of the signed-in user's rights on the merge request and on each discussion and note, the user's draft notes, and their approval, then the diff versions; the newest version must be at the requested head, else the read is stale. A thread is a discussion whose first note is a diff note on a text or file position; discussions on the overview, on images, and without notes are left out, and system notes are dropped from threads. GitLab keeps one position per thread, at the last diff version whose lines the thread's lines were unchanged in: a position at the head gives current, and every line thread keeps its position as original. GitLab does not move a multi-line thread's line_range when it carries the thread to a new version, so a range's first line is its last line less the range's length. An outdated thread's diffHunk is cut from its position's diff: the version's file when GitLab keeps it, or a comparison of the file's text at the position's merge base and head, since GitLab drops the files of earlier versions once a merge request merges. Those patches never change and are kept until they pass maxCachedVersionBytes (default 16 MiB); a version larger than that serves its read without being kept. The read is truncated when it stops before the last discussion page, leaves the rights of a discussion or of a note past a discussion's first 100 unread, or drops the threads whose hunks and drafts bring the result past maxOutputBytes. A thread may be replied to when the user may comment, and resolved when GitLab lets the user resolve its discussion; a note may be edited and deleted when GitLab grants the user adminNote on it. The user's draft notes are their pending review, whose id is draft-notes: a draft reply joins its thread as a pending comment, and a draft on a file position is a thread of its own, which cannot be replied to or resolved before it is published. GitLab reports no creation time for drafts, so they carry the read's time. reviewEvents offers comment to a user who may comment, approve when GitLab lets them approve or they already approved, since GitLab Community Edition lets authors approve their own merge requests, and request-changes only to reviewers, since GitLab records that decision only for them.
markReady calls the GraphQL mergeRequestSetDraft mutation, and merge puts merge with sha set to the confirmed head and squash for the squash method, so GitLab refuses with HTTP 409, reported as stale, once the head moved; the merge request's own setting decides whether GitLab deletes the head branch.
Review writes read the newest diff version first and refuse with stale unless its head is the confirmed commit. A comment's position names that version's merge base, target tip, and head: an added line names its new line, a deleted line its old line, and any other line both, inside or outside the hunks, and a range adds a line_range with GitLab's line codes; a line the version's diff does not hold is refused before anything is written, and a comment on an unchanged line reads back on the new side. A file GitLab collapsed or found too large is placed on the diff compared from its texts, and a file's new path names it over another file's old path. submitReview starts a discussion for one comment. A review writes each comment as a draft note, approves at the head when its decision is approve, and publishes the drafts with the summary and the review state of comment (reviewed) or request-changes (requested_changes); a refused draft or approval deletes the drafts it wrote. After a refused publication the drafts are read again, since GitLab can publish them before refusing the summary: they are deleted only when all remain, else the result is unknown. A deletion that fails makes the result unknown with the number of drafts that may remain. A review is refused while the user holds drafts, which publishing would include. Pending replies and comments are draft notes, which submit-pending publishes in the same way and discard-pending deletes one by one, reporting how many it deleted before a refusal. An approval is skipped when the user already approved, since GitLab answers a second one with HTTP 401. Replies, resolutions, edits, and deletions go through the merge request's own paths, so GitLab refuses ids of another merge request.
rerunChecks retries the head pipeline once it has failed jobs and none pending. requestReviews adds new reviewers with mergeRequestSetReviewers and asks current ones again with mergeRequestReviewerRereview; a merge request that takes one reviewer, as on GitLab's free tier, refuses a second, and GitLab has no team reviewers. reviewerCandidates lists at most 20 of GitLab's matches among the users who can see the project, never the author, none suggested. updateBranch only rebases: GitLab names no head in a rebase request, so the provider reads the head first and refuses a moved one with stale, and GitLab rebases in the background once it accepted the request. Writes are never retried: a 4xx answer is a refusal, failed, except HTTP 401, unauthenticated, and HTTP 409 to a merge or an approval, stale; a 5xx answer, an answer without a status, and a write past timeoutMs are unknown.
Understand the implementation
Implementation internals — click to expand
Each status query reads several merge requests under aliases with their project paths and numbers as variables, so a missing project or merge request fails only its own alias.
| Source | Responsibility |
|---|---|
src/index.ts |
Configuration validation, and provider and command rule registration |
src/commands.ts |
The glab command rule that forge-session binds merge requests by |
src/provider.ts |
URL mapping, batching, closing issue and diff caches, and actions |
src/api.ts |
REST, GraphQL, and write requests through glab api, and failure mapping |
src/status.ts |
Status query construction and snapshot mapping |
src/diff.ts |
Version-pinned patches, comparisons, merge bases, and file texts |
src/commits.ts |
Commit listing oldest first |
src/review.ts |
Discussion, draft note, and permission reads, and mapping onto head and original positions |
src/writes.ts |
Review writes and submissions through discussions, draft notes, and approvals |
src/position.ts |
Diff note positions and line codes from a version's file diff |
src/overview.ts |
Pipeline retries, review requests, reviewer candidates, and rebases |
src/pool.ts |
Bounded concurrency |
src/glab.ts |
Host glab execution with environment scrubbing and limits |
src/urls.ts |
Remote, merge request, and issue URL parsing, and project path validation |
Further Exploration
- Forge registry — provider registration and shared polling.
- Forge subsystem — provider contract and change request types.
- GitHub provider — the provider this one mirrors for GitHub hosts.
Model Experience
None, as the provider reads and writes merge requests for host-side watchers and the panel without contributing model context.
KV Cache effect
None. Provider output reaches only host-side watchers.
Known Limitations and Deferred Work
- GitLab CLI on the host —
glabmust be installed and signed in for each configured host; tokens in environment variables are not forwarded. Hosts missing fromhostsare never read; a status fetch returnsunavailablefor their references, and a head lookup rejects before startingglab. A host whose SSH remotes use another host name, or a GitLab installed under a path prefix, is not recognized. - No viewed marks — the provider keeps no viewed marks, so the changes view keeps them in the browser, as GitLab's own pages do.
- Rebase without a head check — a push between the head read and the rebase request is rebased too, and a rebase GitLab fails in the background is not reported.
- Overview discussions — discussions that are not on a file count toward
unresolvedThreadsbut are not returned as threads. - Bots and draft times — comment authors are never marked as bots, and draft notes carry the read's time.
- CE fields only — the status query reads fields Community Edition has; required approvals, code owners, suggested reviewers, and merged-results pipelines of paid tiers are not read.
- Rate limits — every poll costs one GraphQL query per batch plus one REST request per merge request whose update time changed; a review read costs one REST and one GraphQL request per 100 discussions, one request each for the versions, the draft notes, and the approval, and up to two per outdated file not yet cached; a write reads the newest version first, and a comment reads its version's files once.
Dev Note
Working context for maintainers — click to expand
None.