@comforge/mcp 0.2.0 → 0.4.0
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/README.md +71 -183
- package/dist/contracts.d.ts +12 -0
- package/dist/contracts.js +26 -0
- package/dist/host.d.ts +31 -1
- package/dist/hostServices.d.ts +133 -0
- package/dist/hostServices.js +240 -0
- package/dist/http.d.ts +8 -1
- package/dist/http.js +4 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +4 -3
- package/dist/server.d.ts +22 -0
- package/dist/server.js +64 -11
- package/dist/tools.d.ts +11 -1
- package/dist/tools.js +109 -31
- package/llms.txt +12 -6
- package/package.json +13 -3
package/README.md
CHANGED
|
@@ -1,188 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/vikramrao1994/comforge">
|
|
3
|
+
<picture>
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/vikramrao1994/comforge/raw/main/docs/assets/brand/comforge-logo-dark.svg">
|
|
5
|
+
<img alt="Comforge" src="https://github.com/vikramrao1994/comforge/raw/main/docs/assets/brand/comforge-logo-light.svg" height="40">
|
|
6
|
+
</picture>
|
|
7
|
+
</a>
|
|
8
|
+
</p>
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
over the [Model Context Protocol](https://modelcontextprotocol.io). It calls the CLI's published
|
|
5
|
-
lifecycle services and `@comforge/github`'s reads in process. It never shells out to `comforge`,
|
|
6
|
-
parses its output, or keeps a second copy of its governance, state or authorization.
|
|
10
|
+
# @comforge/mcp
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
unreleased candidates of `@comforge/core`, `@comforge/github` and `@comforge/cli`, and on this
|
|
10
|
-
package's own unreleased changes; `package.json` still says 0.1.0 until the version PR.
|
|
12
|
+
Agent integration for the governed lifecycle: the `comforge-mcp` server exposes it over the [Model Context Protocol](https://modelcontextprotocol.io) on stdio or Streamable HTTP. It calls the lifecycle services of `@comforge/cli` in process, so governance, state and authorization are never duplicated, and it never merges, deploys, approves, requests a review, closes an issue or runs an arbitrary command.
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
[](https://www.npmjs.com/package/@comforge/mcp)
|
|
15
|
+
[](https://github.com/vikramrao1994/comforge/actions/workflows/ci.yml)
|
|
16
|
+
[](https://github.com/vikramrao1994/comforge/blob/main/LICENSE)
|
|
17
|
+
[](https://github.com/vikramrao1994/comforge/blob/main/docs/reference/compatibility.md)
|
|
13
18
|
|
|
14
|
-
##
|
|
19
|
+
## Install
|
|
15
20
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
| `comforge_capabilities` | all | profiles, repository ids, tools, execution availability, what the server never does |
|
|
19
|
-
| `comforge_context` | all | routes a task through the repository's context manifest |
|
|
20
|
-
| `comforge_status` | all | initiatives, summary first and paginated, or one initiative with counts |
|
|
21
|
-
| `comforge_evidence` | all | one section of an initiative's record (validations, publications, completions, revisions, operations), newest first |
|
|
22
|
-
| `comforge_issue` | all | an issue and whether its specification still verifies, or (without `number`) a page of issues; text is untrusted |
|
|
23
|
-
| `comforge_pr` | all | a pull request, optionally its checks, changed files and native GitHub reviews |
|
|
24
|
-
| `comforge_prs` (candidate) | all | a page of the repository's pull requests (`state` open, closed or all) |
|
|
25
|
-
| `comforge_comments` (candidate) | all | a page of an issue's or pull request's comments; text is untrusted |
|
|
26
|
-
| `comforge_reviews` (candidate) | all | a pull request's advisory reviews, with integrity and provenance |
|
|
27
|
-
| `comforge_artifact` (candidate) | all | one file at an exact commit, only under the repository's trusted `artifacts.readable` paths |
|
|
28
|
-
| `comforge_start` | executor | verifies the specification, creates the isolated checkout |
|
|
29
|
-
| `comforge_revise` | executor | reuses or re-creates a pull request's checkout and syncs it |
|
|
30
|
-
| `comforge_verify` | executor | trusted validation of an exact commit in a clean snapshot |
|
|
31
|
-
| `comforge_deliver` | publisher | push, one pull request, one completion record, read back; `execute:false` plans |
|
|
32
|
-
| `comforge_recover` | publisher | settles uncertain writes from GitHub; `execute:false` reports |
|
|
33
|
-
| `comforge_cleanup` | publisher | plans a cleanup; executing needs operator mode or a cleanup-scoped command grant (candidate; below) |
|
|
34
|
-
| `comforge_publish_review` (candidate) | reviewer | publishes one advisory review comment bound to the reviewed head; `execute:false` plans |
|
|
35
|
-
| `comforge_publish_specification` (candidate) | publisher | publishes a specification issue (idempotent, read back); `execute:false` plans |
|
|
36
|
-
|
|
37
|
-
The candidate contracts total 18 tools. Advisory reviews are marked comments, never native
|
|
38
|
-
reviews or approvals.
|
|
39
|
-
The four profiles are `read-only`, `reviewer` (adds patches and full review bodies to reads),
|
|
40
|
-
`executor` and `publisher`. A principal can hold several. A principal discovers only the tools its
|
|
41
|
-
profiles permit, and every call checks the profile again.
|
|
42
|
-
|
|
43
|
-
## Contracts
|
|
44
|
-
|
|
45
|
-
Every input object is strict and versioned. An unknown field is refused before a handler runs,
|
|
46
|
-
and so is a forged internal option such as `authorized`, a path, a URL or a credential. A
|
|
47
|
-
repository is named by its allowlisted id.
|
|
48
|
-
|
|
49
|
-
```text
|
|
50
|
-
success {schema:"comforge-mcp/v1", tool, ok:true, exit, summary, data, page?}
|
|
51
|
-
refusal {schema:"comforge-mcp-error/v1", code, message, exit, retryable, hint?, detail?}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
`exit` is the CLI's exit class: 0 ok, 1 refused, 2 usage or configuration, 3 failed, 4 incomplete.
|
|
55
|
-
Results are bounded: about 48,000 characters each, and untrusted text is excerpted unless a
|
|
56
|
-
reviewer asks for detail. Longer lists are paginated with `cursor` and `pageSize`. Credentials
|
|
57
|
-
and secret-like text are redacted. Over HTTP, host paths are replaced by `<host>`.
|
|
58
|
-
|
|
59
|
-
## Security model
|
|
60
|
-
|
|
61
|
-
- **Credentials are server-owned.** The host provides them per repository and principal, or they
|
|
62
|
-
come from the repository's trusted `security.credentials` source. They are never returned.
|
|
63
|
-
- **Authorization stays in `@comforge/cli`.** Writes need the repository's trusted
|
|
64
|
-
`security.authorization`: owner grants or operator mode. A caller passes an owner-signed grant
|
|
65
|
-
envelope in `grant`, and the CLI verifies it against the trusted keys, ticket, specification,
|
|
66
|
-
head and branch. The server cannot authorize anything itself.
|
|
67
|
-
- **Cleanup needs its own authority (candidate).** `comforge_cleanup` with `execute:true` runs
|
|
68
|
-
under operator mode, or under an owner grant that scopes the command to cleanup of the merged
|
|
69
|
-
pull request (`authorizeCommand` in [`@comforge/core`](https://www.npmjs.com/package/@comforge/core)). A grant signed
|
|
70
|
-
to publish is never valid for cleanup. With the published `@comforge/core` 0.1.x grant format,
|
|
71
|
-
which cannot name a command, `execute:true` is refused with `command-scope-unsupported`; run
|
|
72
|
-
cleanup through the `comforge` CLI.
|
|
73
|
-
- **Repository isolation.** Each principal has an allowlist. An unknown or foreign id gets the same
|
|
74
|
-
refusal, and the trusted configuration must name the bound GitHub repository.
|
|
75
|
-
- **Local stdio.** The trust boundary is the local user. The operator picks the repositories and
|
|
76
|
-
profiles at launch, and there is no authentication. Repository commands run in the server's
|
|
77
|
-
process environment, as `comforge` would.
|
|
78
|
-
- **Streamable HTTP.** The host mounts `createHttpHandler(options)` and authenticates each request,
|
|
79
|
-
returning a principal or `null`. Before any MCP message is parsed, the handler checks:
|
|
80
|
-
1. the `Host` allowlist;
|
|
81
|
-
2. the `Origin` allowlist;
|
|
82
|
-
3. the method;
|
|
83
|
-
4. the body size;
|
|
84
|
-
5. authentication, with a `WWW-Authenticate` challenge on 401;
|
|
85
|
-
6. the per-principal rate and concurrency limits.
|
|
86
|
-
|
|
87
|
-
Sessions are created by `initialize`, bound to their principal and expire when idle. Any other
|
|
88
|
-
principal presenting the session id is refused.
|
|
89
|
-
- **Remote execution is off by default.** Over HTTP, the tools that run repository commands
|
|
90
|
-
(start, revise, verify, deliver, recover, cleanup) are neither listed nor callable unless the
|
|
91
|
-
host passes an `IsolationProvider`. That is the host's attestation that its runtime runs every
|
|
92
|
-
command inside an isolation boundary it operates. A flag cannot stand in for it. This package
|
|
93
|
-
implements no sandbox and claims none.
|
|
94
|
-
- **Remote publication is not remote execution (candidate).** The reads, `comforge_publish_review`
|
|
95
|
-
and `comforge_publish_specification` run no repository command, so over HTTP they are available
|
|
96
|
-
without an `IsolationProvider`. They still need the principal's profile and the repository's
|
|
97
|
-
trusted authorization. Only the executing tools need the provider.
|
|
98
|
-
- **Host policy (candidate).** `HostServices.hostPolicy(binding)` hands the CLI's `HostPolicy`
|
|
99
|
-
(checkout parent, worker preparation and removal, validation) to the lifecycle for one
|
|
100
|
-
repository. It is host code; no tool input reaches it.
|
|
101
|
-
- **Cancellation.** It is checked between the CLI's stages, never in the middle of a write. An
|
|
102
|
-
interrupted delivery is recorded and settled by `comforge_recover`.
|
|
103
|
-
|
|
104
|
-
## Deploying the HTTP handler
|
|
105
|
-
|
|
106
|
-
- **Terminate TLS in front of it.** The handler checks the `Host` header against `allowedHosts`
|
|
107
|
-
and the `Origin` header against `allowedOrigins`. It never reads `X-Forwarded-*`. A reverse
|
|
108
|
-
proxy must forward the original `Host`, and the host's `authenticate` must not trust
|
|
109
|
-
client-supplied identity headers that the proxy does not set.
|
|
110
|
-
- **Each request is authenticated,** including session reuse, the SSE `GET` and `DELETE`.
|
|
111
|
-
- A session belongs to the principal that initialized it.
|
|
112
|
-
- A different principal is refused.
|
|
113
|
-
- If the same principal comes back with other profiles or repositories, the session ends,
|
|
114
|
-
and the client starts a new one. A revoked principal gets 401 at once.
|
|
115
|
-
- An authenticator that throws is treated as no principal.
|
|
116
|
-
- **Limits are per process.** Rate, concurrency and session limits and the session table live in
|
|
117
|
-
one process, so a multi-instance deployment needs sticky sessions and limits enforced in front.
|
|
118
|
-
- **Repository commands are synchronous.** They block the process for their duration (see
|
|
119
|
-
Limits). Remote execution belongs on host-operated workers that the `IsolationProvider`
|
|
120
|
-
stands for.
|
|
121
|
-
- `compactDiscovery: true` (or `--compact-discovery`) leaves the output schemas out of
|
|
122
|
-
`tools/list`. Measured: 39-45% fewer discovery tokens (17 tools: 11,019 to 6,759). The results
|
|
123
|
-
keep the same versioned envelope.
|
|
124
|
-
- `textContent: "summary"` (candidate; `--summary-text`; default `"full"`) makes each result's text
|
|
125
|
-
content one summary line and leaves `structuredContent` unchanged. Measured: a model that is
|
|
126
|
-
given `structuredContent` reads the same tokens; the wire shrinks to about the structured size.
|
|
127
|
-
A client that reads only text sees just the summary line, so it is opt-in.
|
|
128
|
-
|
|
129
|
-
Measurements are per-call tokenizer counts on one repository. Equivalent initiative state still costs more through MCP
|
|
130
|
-
than through the CLI (4,224 vs 3,701 tokens for every initiative's status); for the new reads MCP
|
|
131
|
-
is the smallest equivalent form (pull requests 1,191 vs CLI 1,617 vs raw GitHub 2,587). Discovery
|
|
132
|
-
is the largest fixed cost of an MCP session. These are per-call counts; no end-to-end saving is
|
|
133
|
-
claimed.
|
|
134
|
-
|
|
135
|
-
## Repositories without a checkout (candidate)
|
|
136
|
-
|
|
137
|
-
A host that has no checkout (a web app that answers MCP over HTTP) can still serve the GitHub
|
|
138
|
-
evidence reads: `comforge_capabilities`, `comforge_issue`, `comforge_pr`, `comforge_prs`,
|
|
139
|
-
`comforge_comments`, `comforge_reviews` and `comforge_artifact` (`REMOTE_READ_TOOLS`).
|
|
140
|
-
|
|
141
|
-
```ts
|
|
142
|
-
createHttpHandler({
|
|
143
|
-
repositories: [],
|
|
144
|
-
remoteRepositories: [{ id: "widgets", owner: "acme", name: "widgets", configSha256: "<optional pin>" }],
|
|
145
|
-
remote: {
|
|
146
|
-
trustedConfig: async (b) => ({ revision, text, observedAt }), // host code: the base head and its comforge.config.json
|
|
147
|
-
credentials: (b, principal) => serverOwnedToken,
|
|
148
|
-
configMaxAgeMs: 600_000,
|
|
149
|
-
},
|
|
150
|
-
host: { runtime: () => { throw new Error("no runtime"); } },
|
|
151
|
-
// authenticate, allowedHosts, ... as above
|
|
152
|
-
});
|
|
21
|
+
```sh
|
|
22
|
+
npm install --save-exact @comforge/mcp # or: bun add --exact @comforge/mcp
|
|
153
23
|
```
|
|
154
24
|
|
|
155
|
-
|
|
156
|
-
snapshot whose revision is not a full SHA (`config-invalid`), that is older than
|
|
157
|
-
`configMaxAgeMs` or from the future (`config-stale`, retryable), that differs from the pin or
|
|
158
|
-
from GitHub's bytes at that revision read with the server's credential (`config-mismatch`), or
|
|
159
|
-
that names another repository (`repository-mismatch`). A source that throws is `config-missing`.
|
|
160
|
-
- Whether the revision is the base branch head is the host's statement; the server verifies the
|
|
161
|
-
bytes at that revision, not branch membership.
|
|
162
|
-
- Every other tool is refused for such a repository with `checkout-required`, with or without an
|
|
163
|
-
`IsolationProvider`: loading a configuration never enables execution or writes. A server with
|
|
164
|
-
only checkout-free repositories does not list those tools at all.
|
|
165
|
-
|
|
166
|
-
## Signed command scope (candidate)
|
|
25
|
+
It brings `@comforge/cli`, `@comforge/core`, `@comforge/github` and `@comforge/ledger`; do not install them separately for this. You need a repository whose base branch carries `comforge.config.json` ([configuration](https://github.com/vikramrao1994/comforge/blob/main/docs/reference/configuration.md)).
|
|
167
26
|
|
|
168
|
-
|
|
169
|
-
- a grant **without** the field keeps its meaning for publish, complete, deliver and recover;
|
|
170
|
-
- such a grant is **never** valid for cleanup;
|
|
171
|
-
- a grant **with** the field is valid only for the commands it lists.
|
|
27
|
+
## Quick example
|
|
172
28
|
|
|
173
|
-
|
|
174
|
-
released and pinned. The grant format is documented in the
|
|
175
|
-
[`@comforge/core` README](https://www.npmjs.com/package/@comforge/core).
|
|
176
|
-
|
|
177
|
-
## Run locally
|
|
29
|
+
Serve a repository to a local agent over stdio. The default profile is `read-only`; add profiles to expose more tools.
|
|
178
30
|
|
|
179
31
|
```sh
|
|
180
32
|
npx comforge-mcp --repository . --profile executor --profile publisher
|
|
181
33
|
```
|
|
182
34
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
## Embed
|
|
35
|
+
Or mount the Streamable HTTP handler in your own server:
|
|
186
36
|
|
|
187
37
|
```ts
|
|
188
38
|
import { createHttpHandler } from "@comforge/mcp";
|
|
@@ -197,17 +47,55 @@ const handler = createHttpHandler({
|
|
|
197
47
|
// Bun.serve({ fetch: (req) => handler.handle(req) }), or any web-standard Request/Response host.
|
|
198
48
|
```
|
|
199
49
|
|
|
200
|
-
|
|
201
|
-
|
|
50
|
+
## What it provides
|
|
51
|
+
|
|
52
|
+
Tools are grouped into four profiles. A principal can hold several, discovers only the tools its profiles permit, and every call checks the profile again. Write tools plan with `execute: false` and act with `execute: true`.
|
|
53
|
+
|
|
54
|
+
| Profile | Tools |
|
|
55
|
+
|---|---|
|
|
56
|
+
| `read-only` | `comforge_capabilities`, `comforge_context`, `comforge_status`, `comforge_evidence`, `comforge_issue`, `comforge_pr`, `comforge_prs`, `comforge_comments`, `comforge_reviews`, `comforge_artifact` |
|
|
57
|
+
| `reviewer` | Adds patches and full review bodies to reads, and `comforge_publish_review` |
|
|
58
|
+
| `executor` | `comforge_start`, `comforge_revise`, `comforge_verify` |
|
|
59
|
+
| `publisher` | `comforge_deliver`, `comforge_recover`, `comforge_cleanup`, `comforge_publish_specification`, `comforge_publish_comment` |
|
|
60
|
+
|
|
61
|
+
Results are versioned and bounded (about 48,000 characters), paginated with `cursor` and `pageSize`, and redacted. Untrusted issue, comment and pull request text is excerpted. `--compact-discovery` leaves output schemas out of `tools/list`, and `--summary-text` reduces each result's text content to one line.
|
|
62
|
+
|
|
63
|
+
| Export | Subpath | Use |
|
|
64
|
+
|---|---|---|
|
|
65
|
+
| `createComforgeMcpServer` | `@comforge/mcp` | An `McpServer` over your repository bindings, for any transport |
|
|
66
|
+
| `serveStdio` | `@comforge/mcp` | The stdio transport the executable uses |
|
|
67
|
+
| `createHttpHandler` | `@comforge/mcp` | Streamable HTTP with authentication, `Host` and `Origin` allowlists, limits and per-principal sessions |
|
|
68
|
+
| `registerComforgeTools` | `@comforge/mcp` | The native tools on an application's existing `McpServer`, next to its own tools (unreleased) |
|
|
69
|
+
| `createEngineeringHost`, `sqliteOperationStore`, `fetchTransport` | `@comforge/mcp/host` | The same engineering services for an application's own server |
|
|
70
|
+
|
|
71
|
+
Composition: `registerComforgeTools(server, options)` registers exactly the tools `createComforgeMcpServer` would, with the same schemas and handlers, onto a server you already have. A name the server already holds is refused before anything is registered; comforge never renames a tool. Checkout-free repositories (`remoteRepositories`) serve evidence reads, and with `remote.governance` also `comforge_publish_specification`, `comforge_publish_review` and `comforge_publish_comment`, under the host's per-command write credential, durable operation store and authorization (operator-mode repositories only; owner-grant repositories need a checkout).
|
|
72
|
+
|
|
73
|
+
Credentials stay server-owned and are never returned. Writes are authorized by the repository's trusted configuration in `@comforge/cli` (an owner-signed grant or operator mode), never by the server or a tool input. Over HTTP, tools that run repository commands are neither listed nor callable unless the host supplies an `IsolationProvider`.
|
|
74
|
+
|
|
75
|
+
## Compatibility
|
|
76
|
+
|
|
77
|
+
- Node.js 22.18 or later, or Bun 1.4 or later; Git on `PATH`.
|
|
78
|
+
- macOS and Linux (the same platforms as `@comforge/cli`).
|
|
79
|
+
- Any MCP client that supports stdio or Streamable HTTP; integration notes exist for several agents (see Documentation).
|
|
80
|
+
|
|
81
|
+
Details: [compatibility](https://github.com/vikramrao1994/comforge/blob/main/docs/reference/compatibility.md).
|
|
82
|
+
|
|
83
|
+
## Limitations
|
|
84
|
+
|
|
85
|
+
- **No sandbox.** Repository commands run synchronously and block the server process; over HTTP, remote execution belongs on host-operated workers behind an `IsolationProvider`.
|
|
86
|
+
- **Per-process limits.** Rate, concurrency and session limits live in one process; a multi-instance deployment needs sticky sessions and limits enforced in front.
|
|
87
|
+
- **Advisory reviews are marked comments**, not native reviews or approvals, and need the repository's trusted `review` configuration section.
|
|
88
|
+
- Initiative state is a file ledger with compare-and-swap: a concurrent writer on the same checkout is refused, and an interrupted delivery is settled by `comforge_recover`.
|
|
89
|
+
|
|
90
|
+
See [security model, HTTP deployment and limits](https://github.com/vikramrao1994/comforge/blob/main/docs/reference/mcp.md#security-model).
|
|
202
91
|
|
|
203
|
-
##
|
|
92
|
+
## Documentation
|
|
204
93
|
|
|
205
|
-
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
-
|
|
213
|
-
per limit domain.
|
|
94
|
+
- [Repository README](https://github.com/vikramrao1994/comforge#readme)
|
|
95
|
+
- [MCP reference](https://github.com/vikramrao1994/comforge/blob/main/docs/reference/mcp.md), [tool selection](https://github.com/vikramrao1994/comforge/blob/main/docs/reference/tool-selection.md), [errors](https://github.com/vikramrao1994/comforge/blob/main/docs/reference/errors.md)
|
|
96
|
+
- [Recipe: MCP for coding agents](https://github.com/vikramrao1994/comforge/blob/main/docs/recipes/02-mcp-for-coding-agents.md) and [embedded host services](https://github.com/vikramrao1994/comforge/blob/main/docs/recipes/07-embedded-host-services.md)
|
|
97
|
+
- [Agent integrations](https://github.com/vikramrao1994/comforge/tree/main/docs/integrations)
|
|
98
|
+
- [Architecture](https://github.com/vikramrao1994/comforge/blob/main/docs/concepts/architecture.md)
|
|
99
|
+
- [Runnable example](https://github.com/vikramrao1994/comforge/tree/main/examples/mcp-consumer)
|
|
100
|
+
- [Changelog](https://github.com/vikramrao1994/comforge/blob/main/packages/mcp/CHANGELOG.md)
|
|
101
|
+
- [License (Apache-2.0)](https://github.com/vikramrao1994/comforge/blob/main/LICENSE)
|
package/dist/contracts.d.ts
CHANGED
|
@@ -186,6 +186,18 @@ export declare const INPUTS: {
|
|
|
186
186
|
signature: z.ZodString;
|
|
187
187
|
}, z.core.$strict>>;
|
|
188
188
|
}, z.core.$strict>;
|
|
189
|
+
readonly comforge_publish_comment: z.ZodObject<{
|
|
190
|
+
repository: z.ZodString;
|
|
191
|
+
issue: z.ZodNumber;
|
|
192
|
+
body: z.ZodString;
|
|
193
|
+
idempotencyKey: z.ZodString;
|
|
194
|
+
relatedReview: z.ZodOptional<z.ZodObject<{
|
|
195
|
+
prNumber: z.ZodNumber;
|
|
196
|
+
commentId: z.ZodNumber;
|
|
197
|
+
reviewedHeadSha: z.ZodString;
|
|
198
|
+
}, z.core.$strict>>;
|
|
199
|
+
execute: z.ZodBoolean;
|
|
200
|
+
}, z.core.$strict>;
|
|
189
201
|
};
|
|
190
202
|
export type ToolName = keyof typeof INPUTS;
|
|
191
203
|
export declare const TOOL_NAMES: ToolName[];
|
package/dist/contracts.js
CHANGED
|
@@ -218,6 +218,23 @@ export const INPUTS = {
|
|
|
218
218
|
grant: GrantEnvelope.optional(),
|
|
219
219
|
})
|
|
220
220
|
.strict(),
|
|
221
|
+
comforge_publish_comment: z
|
|
222
|
+
.object({
|
|
223
|
+
repository: RepositoryId,
|
|
224
|
+
issue: Positive.describe("A published specification issue"),
|
|
225
|
+
body: z.string().min(1).max(20_000).describe("Markdown, exactly as the owner confirmed it"),
|
|
226
|
+
idempotencyKey: z
|
|
227
|
+
.string()
|
|
228
|
+
.regex(/^[A-Za-z0-9][A-Za-z0-9._:-]{15,127}$/)
|
|
229
|
+
.describe("Reuse the same key to retry; a new key only for a new comment"),
|
|
230
|
+
relatedReview: z
|
|
231
|
+
.object({ prNumber: Positive, commentId: Positive, reviewedHeadSha: Sha })
|
|
232
|
+
.strict()
|
|
233
|
+
.optional()
|
|
234
|
+
.describe("An advisory review the comment refers to; its findings are not copied"),
|
|
235
|
+
execute: z.boolean().describe("false plans without any write"),
|
|
236
|
+
})
|
|
237
|
+
.strict(),
|
|
221
238
|
};
|
|
222
239
|
export const TOOL_NAMES = Object.keys(INPUTS);
|
|
223
240
|
const READ = PROFILES;
|
|
@@ -388,6 +405,15 @@ export const TOOLS = {
|
|
|
388
405
|
writes: true,
|
|
389
406
|
destructive: false,
|
|
390
407
|
},
|
|
408
|
+
comforge_publish_comment: {
|
|
409
|
+
name: "comforge_publish_comment",
|
|
410
|
+
title: "Publish a discussion comment",
|
|
411
|
+
description: "Comment on an open, published specification issue, idempotently per key; evidence only, never an approval or authorization. execute:false plans.",
|
|
412
|
+
profiles: PUBLISHER,
|
|
413
|
+
executes: false,
|
|
414
|
+
writes: true,
|
|
415
|
+
destructive: false,
|
|
416
|
+
},
|
|
391
417
|
};
|
|
392
418
|
/** Reviewer reads patches and review bodies in detail; read-only gets summaries. */
|
|
393
419
|
export const DETAIL_PROFILES = ["reviewer", "executor", "publisher"];
|
package/dist/host.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type ComforgeConfig, type CredentialProvider, type HostPolicy, type Runtime, type StateStore } from "@comforge/cli";
|
|
1
|
+
import { type ComforgeConfig, type CredentialProvider, type HostPolicy, type RemoteAuthorizationDecision, type RemoteAuthorizationRequest, type Runtime, type StateStore } from "@comforge/cli";
|
|
2
|
+
import type { OperationLedger } from "@comforge/github";
|
|
2
3
|
import type { Principal } from "./contracts.ts";
|
|
3
4
|
export interface RepositoryBinding {
|
|
4
5
|
/** Allowlisted id callers use. */
|
|
@@ -88,10 +89,39 @@ export interface TrustedConfigSnapshot {
|
|
|
88
89
|
* URL or credential from a caller: the host supplies them, and the server checks the snapshot
|
|
89
90
|
* against GitHub (the same bytes at that revision), its pin, its age and its repository.
|
|
90
91
|
*/
|
|
92
|
+
/** A governance write a checkout-free host is asked to approve (0.4.0). */
|
|
93
|
+
export type RemoteGovernanceCommand = "publish-specification" | "publish-review" | "publish-comment";
|
|
94
|
+
/**
|
|
95
|
+
* Checkout-free governed publication for one repository (0.4.0): the host's write credential,
|
|
96
|
+
* durable write ledger and authorization policy. Present only where the host opts in; without it
|
|
97
|
+
* the repository serves evidence reads only, as in 0.2.0.
|
|
98
|
+
*/
|
|
99
|
+
export interface RemoteGovernanceHost {
|
|
100
|
+
/**
|
|
101
|
+
* The write credential for one command, or undefined to refuse it. Kept apart from the read
|
|
102
|
+
* credential, and per command, so a host can hold a review credential that cannot open issues.
|
|
103
|
+
*/
|
|
104
|
+
credentials(command: RemoteGovernanceCommand): string | undefined;
|
|
105
|
+
/** Durable, shared across processes and restarts (for example `sqliteOperationStore`). */
|
|
106
|
+
operations: OperationLedger;
|
|
107
|
+
/**
|
|
108
|
+
* The host's decision for one exact write, after every protocol check passed and before
|
|
109
|
+
* anything is sent: scopes, feature switches, rate limits. Never bypasses the repository's
|
|
110
|
+
* own authorization: owner-grant repositories are refused without a checkout.
|
|
111
|
+
*/
|
|
112
|
+
authorize(request: RemoteAuthorizationRequest): RemoteAuthorizationDecision | Promise<RemoteAuthorizationDecision>;
|
|
113
|
+
/** The writer's correlation-marker namespace; default the configuration's `security.markerNamespace`. */
|
|
114
|
+
markerNamespace?: string;
|
|
115
|
+
}
|
|
91
116
|
export interface RemoteHost {
|
|
92
117
|
trustedConfig(binding: RemoteRepositoryBinding): TrustedConfigSnapshot | Promise<TrustedConfigSnapshot>;
|
|
93
118
|
/** Server-owned GitHub token for the binding; never returned to a caller. */
|
|
94
119
|
credentials(binding: RemoteRepositoryBinding, principal: Principal): string | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* 0.4.0: governed publication for this binding and principal, or undefined (reads only). Asked
|
|
122
|
+
* per call, so the answer may depend on the principal's grants.
|
|
123
|
+
*/
|
|
124
|
+
governance?(binding: RemoteRepositoryBinding, principal: Principal): RemoteGovernanceHost | undefined;
|
|
95
125
|
/** Oldest snapshot accepted; default 10 minutes. */
|
|
96
126
|
configMaxAgeMs?: number;
|
|
97
127
|
fetchImpl?: typeof fetch;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { type AdvisoryReview, type AuthorizationDecision, type EvidenceLimits, type FetchTransportOptions, type FileBytesEvidence, GitHubAdapterError, type GitHubEvidence, type GitHubTransport, type IssueCommentEvidence, listAdvisoryReviews, type OperationDescriptor, type OperationLedger, type OperationRecord, type UntrustedText, type WriteCapability, type WriteOperation, type WriteOutcome, type WrittenResource } from "@comforge/github";
|
|
2
|
+
import { type PreparedDatabase, type RetentionReport } from "@comforge/ledger/sqlite";
|
|
3
|
+
import type { TrustedConfigSnapshot } from "./host.ts";
|
|
4
|
+
export declare const HOST_SERVICES_SCHEMA: "comforge-host-services/v1";
|
|
5
|
+
/** One GitHub read: `get(path, query)`. The host's own client, or `fetchTransport`. */
|
|
6
|
+
export type HostTransport = GitHubTransport;
|
|
7
|
+
/** Exact-commit, complete-or-refuse reads of one repository. */
|
|
8
|
+
export type HostEvidence = GitHubEvidence;
|
|
9
|
+
/** The host's SQLite handle: `prepare(sql)` returning a statement with `run`, `get` and `all`. */
|
|
10
|
+
export type HostDatabase = PreparedDatabase;
|
|
11
|
+
/** Durable operation records with insert-if-absent and version-checked replace. */
|
|
12
|
+
export type OperationStore = OperationLedger;
|
|
13
|
+
/**
|
|
14
|
+
* Every refusal of these services: `code` is stable, `detail` carries no credential or body.
|
|
15
|
+
* One class for reads, writes and stores, so a host maps it once.
|
|
16
|
+
*/
|
|
17
|
+
export declare const HostServiceError: typeof GitHubAdapterError;
|
|
18
|
+
export type HostServiceError = GitHubAdapterError;
|
|
19
|
+
export type { AdvisoryReview, AuthorizationDecision, FileBytesEvidence, IssueCommentEvidence, OperationDescriptor, OperationRecord, TrustedConfigSnapshot, UntrustedText, WriteCapability, WriteOperation, WriteOutcome, WrittenResource, };
|
|
20
|
+
/** A transport over `fetch` with a server-owned token; GitHub's API origin unless overridden. */
|
|
21
|
+
export declare function fetchTransport(options: FetchTransportOptions): HostTransport;
|
|
22
|
+
export interface HostWriteOptions {
|
|
23
|
+
/** Server-owned. Never stored, logged or returned. */
|
|
24
|
+
token: string | (() => string | Promise<string>);
|
|
25
|
+
/** The only writes performed, whatever the token permits. */
|
|
26
|
+
capabilities: readonly WriteCapability[];
|
|
27
|
+
/** The host's decision for one exact descriptor. Policy stays with the host. */
|
|
28
|
+
authorize: (descriptor: OperationDescriptor) => AuthorizationDecision | Promise<AuthorizationDecision>;
|
|
29
|
+
operations: OperationStore;
|
|
30
|
+
/** Milliseconds since the epoch. */
|
|
31
|
+
clock: () => number;
|
|
32
|
+
markers?: {
|
|
33
|
+
namespace?: string;
|
|
34
|
+
} | false;
|
|
35
|
+
/** The login the token writes as; reconciliation trusts only its markers. */
|
|
36
|
+
expectedAuthor?: string;
|
|
37
|
+
fetchImpl?: typeof fetch;
|
|
38
|
+
apiOrigin?: string;
|
|
39
|
+
timeoutMs?: number;
|
|
40
|
+
maxBodyBytes?: number;
|
|
41
|
+
userAgent?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface EngineeringHostOptions {
|
|
44
|
+
repository: {
|
|
45
|
+
owner: string;
|
|
46
|
+
name: string;
|
|
47
|
+
};
|
|
48
|
+
transport: HostTransport;
|
|
49
|
+
/** Paging and text bounds of the evidence reads; the package defaults otherwise. */
|
|
50
|
+
evidenceLimits?: Partial<EvidenceLimits>;
|
|
51
|
+
writes?: HostWriteOptions;
|
|
52
|
+
}
|
|
53
|
+
export interface HostWrites {
|
|
54
|
+
/** The exact descriptor `operation` would send; sends nothing. */
|
|
55
|
+
prepare(operation: WriteOperation): Promise<OperationDescriptor>;
|
|
56
|
+
/** Sends once per operation id; a repeat is answered from the operation store. */
|
|
57
|
+
execute(operation: WriteOperation): Promise<WriteOutcome>;
|
|
58
|
+
/** Settles an uncertain write against GitHub without sending it again. */
|
|
59
|
+
reconcile(operationId: string): Promise<WriteOutcome>;
|
|
60
|
+
abandon(operationId: string, reason: string): Promise<void>;
|
|
61
|
+
}
|
|
62
|
+
export interface EngineeringHost {
|
|
63
|
+
readonly schema: typeof HOST_SERVICES_SCHEMA;
|
|
64
|
+
/** `owner/name`. */
|
|
65
|
+
readonly repository: string;
|
|
66
|
+
readonly profile: "read-only" | "governed-writes";
|
|
67
|
+
readonly evidence: HostEvidence;
|
|
68
|
+
/**
|
|
69
|
+
* Advisory reviews on a pull request, decoded under the host's review protocol. Author trust
|
|
70
|
+
* comes from the forge's authenticated comment author and `trustedAuthors`, never from text.
|
|
71
|
+
*/
|
|
72
|
+
advisoryReviews(protocol: Parameters<typeof listAdvisoryReviews>[1], pullRequest: {
|
|
73
|
+
number: number;
|
|
74
|
+
headSha: string;
|
|
75
|
+
}, options: {
|
|
76
|
+
trustedAuthors: readonly string[];
|
|
77
|
+
}): Promise<AdvisoryReview[]>;
|
|
78
|
+
/** `comforge.config.json` at the head of `branch`, as bytes at one immutable revision. */
|
|
79
|
+
trustedConfig(options: {
|
|
80
|
+
branch: string;
|
|
81
|
+
now?: () => number;
|
|
82
|
+
maxBytes?: number;
|
|
83
|
+
}): Promise<TrustedConfigSnapshot>;
|
|
84
|
+
/** Whether GitHub holds exactly `snapshot.text` at `snapshot.revision`. */
|
|
85
|
+
confirmTrustedConfig(snapshot: Pick<TrustedConfigSnapshot, "revision" | "text">): Promise<"match" | "mismatch" | "absent">;
|
|
86
|
+
readonly writes: HostWrites;
|
|
87
|
+
}
|
|
88
|
+
export declare function createEngineeringHost(options: EngineeringHostOptions): EngineeringHost;
|
|
89
|
+
/** An operation that can never be sent again: succeeded, abandoned, or failed without retry. */
|
|
90
|
+
export declare function isFinished(record: OperationRecord): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* The stored form of a record: a finished one keeps a digest of its body instead of the body.
|
|
93
|
+
* Identity, version, fingerprint, descriptor digest, outcome and failure are untouched.
|
|
94
|
+
*/
|
|
95
|
+
export declare function minimizeFinished(record: OperationRecord): OperationRecord;
|
|
96
|
+
export type RetentionClass = "retryable" | "unresolved" | "finished-compact" | "finished-compactable";
|
|
97
|
+
export declare function retentionClass(record: OperationRecord): RetentionClass;
|
|
98
|
+
export interface SqliteOperationStoreOptions {
|
|
99
|
+
/** The host's database. `prepare` is called on first use, never at construction. */
|
|
100
|
+
database: HostDatabase;
|
|
101
|
+
/** The repository (`owner/name`) whose records this store holds; others are refused. */
|
|
102
|
+
repository: string;
|
|
103
|
+
/** Default `comforge_ledger`. An existing table keeps its name, columns and rows. */
|
|
104
|
+
table?: string;
|
|
105
|
+
/** The column holding the repository. Default `namespace`. */
|
|
106
|
+
repositoryColumn?: string;
|
|
107
|
+
/** Write `kind` and `state` beside each record (`kind` can never change). Default false. */
|
|
108
|
+
kindAndStateColumns?: boolean;
|
|
109
|
+
clock?: () => Date;
|
|
110
|
+
}
|
|
111
|
+
export interface SqliteOperationStore extends OperationStore {
|
|
112
|
+
/** Read-only: how many of this repository's records are in each retention class. */
|
|
113
|
+
inspect(): Promise<{
|
|
114
|
+
operations: number;
|
|
115
|
+
classes: Record<string, number>;
|
|
116
|
+
unreadable: number;
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* Identity-preserving: finished records last written before `before` are rewritten in their
|
|
120
|
+
* minimized form, at most `limit` per call. Unresolved and retryable records are never touched.
|
|
121
|
+
*/
|
|
122
|
+
compact(options: {
|
|
123
|
+
before: Date;
|
|
124
|
+
limit: number;
|
|
125
|
+
}): Promise<RetentionReport>;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The operation store over the host's SQLite database. Atomic across processes and restarts
|
|
129
|
+
* (insert-if-absent, version-checked replace). A record never holds a credential, a finished
|
|
130
|
+
* one is stored minimized, and one that is malformed, of another repository or inconsistent
|
|
131
|
+
* with its state is refused, so the writer reports a store failure and sends nothing.
|
|
132
|
+
*/
|
|
133
|
+
export declare function sqliteOperationStore(options: SqliteOperationStoreOptions): SqliteOperationStore;
|