Files
deepseek-harness/packages/experimental/forge-session
LegGasai cb44a3c2ee feat(forge): read, review, and bind GitLab merge requests (#8317)
* 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
2026-11-13 07:56:57 +00:00
..

description, kind
description kind
Bind change requests to the Session that created, pushed, or tracked them, and watch their status. package-reference

@deepseek-ai/dsh-experimental-forge-session

English | 中文

Summary

List the change requests a Session is working on without a separate registry. A projection derives bindings from binding records and from the Session's shell results, including those inside PTC programs, for git push and the commands forge providers register, such as gh pr create. After each push, and when a caller such as the forge panel reports the branch a Session works on, the service looks up open change requests for that branch and records the unbound ones. Watching a Session polls its bound change requests through ctx.forge. The Session summary carries the bindings to clients.

Table of Contents


Use this package

Mount the service with the forge registry, a provider, and the Session projection registry.

- name: '@deepseek-ai/dsh-session-projection'
- name: '@deepseek-ai/dsh-experimental-forge'
- name: '@deepseek-ai/dsh-experimental-forge-github'
- name: '@deepseek-ai/dsh-experimental-forge-session'

A provider registers the commands of its CLI with ctx.forgeSession.registerCommands(rule), an effect on the calling fiber that returns its disposer; while forge-session runs, forge-github registers gh and forge-gitlab registers glab. A rule names its executable, its creation subcommands, its reference subcommands and its raw API request subcommands, each group with the options it accepts, a regular expression for the change request page path, the JSON members that hold a reference command's own URL, and a select function that maps one parsed reference or API request command to a URL or to a read-only lookup command. Registration throws for a malformed rule and for a rule whose id or executable a live registration has. A rule classifies the same input the same way every time, and its registrant raises version whenever the rule classifies any command or output differently.

ctx.forgeSession.changeRequests(session) returns the visible bindings in first-recorded order. Each entry carries the URL, its origin (created, referenced, discovered, or tracked), the provider reference or null when no provider serves the URL, and the latest polling result or null. watch(session, listener) is an effect on the calling fiber: while a Session has a watcher, every visible binding that a provider serves is polled, and listeners receive the complete list after each later binding change, provider registration change, or polling result. Provider changes resynchronize existing watches, including URLs that were previously unserved. track(session, url) binds a URL under the provider's canonical form, or restores a dismissed binding, and throws when no provider recognizes the URL. dismiss(session, url) hides a visible binding; other URLs leave the log unchanged. discoverBranch(session, remote, branch) runs the lookup that follows a push for a branch on the remote at remote and resolves once it has recorded its bindings or failed; a remote that no provider serves changes nothing.

A bash or pwsh call binds evidence only from its first result, and only when the tool execution itself succeeded; the command's exit status does not matter. A bash or pwsh call inside a PTC program binds the same evidence from its tool/ptc-dispatch event, which logs the call's arguments with its settled outcome. A command containing a rule's creation subcommand, such as gh pr create, binds every change request page URL of that rule in its text output. A command containing a reference subcommand, such as gh pr view, binds, as referenced, the change request that the rule's select finds in a literal simple command, plus the URL its output prints for its own change request: a url: field or a URL alone on a line before the -- line that starts a description, and the rule's JSON URL members. Links in a description or in other fields do not bind, and a command that also contains a creation subcommand binds its URLs as created. An API request subcommand, such as glab api, binds as referenced only the change request its request path names; its output is not read, since one request can list many change requests. A command containing git push, optionally with leading -C, -c, or long Git options, records each branch listed under a To <remote> line as created, updated, forced, or already up to date; rejected and deleted refs, new tags, and explicit refs outside refs/heads/ are skipped. For each pushed branch whose remote a provider serves, the service runs ctx.forge.findByHead within discoveryTimeoutMs and appends a discover record for every returned change request that is not bound. Dismissed bindings remain bound and are skipped; only track restores them. Every push repeats the lookup; failures are logged as warnings. Closing a Session cancels its unfinished branch lookups without adding bindings. Reopening it does not repeat those lookups; another push, discoverBranch, or track can bind the change request. URLs that differ only in scheme, letter case, query, fragment, or trailing slashes name the same binding.

A command's options parse by the declarations of the group whose subcommand it runs: a value option takes the next word, the text after =, or for a one-letter option the rest of the word, and an undeclared option makes the command name nothing. When select returns a lookup for a single command, optionally piped through head, tail, or cat, a completed foreground Bash call runs that read-only command, prefixed with env and the command's literal environment assignments, through the same shell service, cwd, managed environment, and standing sandbox policy; the CLI resolves its configured host. A lookup whose complete output is one page URL of the rule appends a reference binding record; other output and failures leave bindings unchanged and log a warning. A Bash call inside a PTC program runs its lookup after the enclosing root call settles, so the lookup follows that root call's cancellation. This live observer requires tools, shell, and shellEnv; projection-only compositions still recover recorded URLs. Queries share discoveryTimeoutMs, stop on caller cancellation, and are aborted and awaited on service disposal.

Binding actions are plugin:forge-session/binding records listed in the experimental persistence catalog; fork and resume carry them with the shell events, so a fork starts with its parent's bindings. discoveryTimeoutMs is listed in the configuration catalog.


Understand the implementation

Implementation internals — click to expand

The forgeChangeRequests projection keeps shell calls awaiting their first result, every binding with its dismissal state, and each pushed branch with the sequence number of the latest result that reported it. Pending calls are dropped at turn/end. Its client view, which the Session summary carries, is every binding with its URL, origin, and dismissal state in first-recorded order, and it keeps its reference while only pending calls or pushes change. The service reacts to a tool/result or tool/ptc-dispatch event by discovering exactly the pushes whose sequence number equals the event's, and refreshes watchers when the bindings array changes. Disposing the service aborts lookups and drops their results.

The projection's state version is 5 × 2^32 plus a 32-bit hash of the recognized rules' id@version pairs, so a checkpoint folded with other rules is discarded and the log folds again. A registration that changes the recognized rules releases the projection and registers it at the new version once the registrations of the same microtask have run, one re-registration at a time; each Session refolds its log with the new rules when next read, including commands that ran before the provider loaded, and watchers whose bindings changed are notified. Ending a registration leaves its rule recognized until the service restarts or another registration replaces its id or executable, so unloading providers, including at shutdown, leaves the checkpointed version unchanged; only live registrations run reference lookups. Each start registers the projection without rules, since providers register theirs once forge-session has started, and their registrations then re-register it once. A failed re-registration registers the projection again with the earlier rules and logs a warning; when that fails too, it logs an error, and clients see no bindings until the service restarts.

Source Responsibility
src/index.ts Discovery, track and dismiss records, and Session watches
src/projection.ts Fold of shell calls, results, program dispatches, and binding records
src/commands.ts Rule validation and compilation, command classification, and output parsing
src/references.ts Literal simple commands of a shell command line
src/reference-lookup.ts Live lookups of change requests named without a host
src/types.ts Binding record, projection state, and entry types

Further Exploration


Model Experience

None, as bindings, discovery records, and polled status never enter model requests; clients see the bindings through the Session summary.

KV Cache effect

None. Binding records are ignorable plugin records outside the model-visible conversation.

Known Limitations and Deferred Work

  • Limited shell recognition — Only CLIs with a registered rule bind. Numeric selectors require a literal repository. Expansion, substitutions, multiline scripts, undeclared options, and aliases are excluded. Unqualified repositories in compound commands or PowerShell require an output URL or track; the live resolver cannot recover their original environment. Replay restores confirmed reference records and selectors that name their host without running a lookup; old unqualified calls without a recorded URL need another invocation or track. Branch selectors and git push --porcelain remain unsupported.
  • Rule changes refold every Session — a provider that adds a rule or raises its version invalidates every checkpointed forgeChangeRequests row: each Session refolds its whole log when next read, and until then the Session list shows no cached bindings for it. A Session read during startup, before the providers register, folds without their commands, and a checkpoint written then folds again at the next start. Starting without a provider removes the bindings that only its commands made, such as those of gh pr create without forge-github; binding records stay. Re-registration emits no projection change, so an open Session's summary shows the refolded bindings once a later event changes its projection state; watchers and changeRequests see them at once.
  • Discovery timing — a change request opened elsewhere for a branch appears after the next push of that branch, after a caller such as the forge panel reports the branch again, or after a track.
  • No model tool — the model cannot read or change bindings yet.
  • Background output — run_in_background: true returns a job id without binding evidence. A foreground command moved to the background contributes only the output in its first result; later job output does not add bindings. Use track for change requests missing from that result.
  • Unqualified tag updates — a forced or up-to-date tag printed without refs/tags/ is treated as a branch. Discovery may bind an open change request for a branch with the same name; use dismiss to hide an incorrect binding.
  • Shortened program output — a shell call inside a PTC program binds from the logged copy of its output, which the spill policy can shorten. A URL only in the omitted part does not bind, and the live lookup, which reads the complete output, skips a call whose output prints its own URL; use track.
  • Per-Session bindings — subagent Sessions keep their own bindings; a parent Session does not aggregate them.
  • Silent lookup failures — lookup failures reach the host log only; neither the Session nor its watchers see them.

Dev Note

Working context for maintainers — click to expand

None.