@contentrain/mcp 1.2.1 → 1.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 +93 -25
- package/dist/annotations-Clhbw2lh.mjs +126 -0
- package/dist/annotations-Clhbw2lh.mjs.map +1 -0
- package/dist/{apply-manager-BkPMfpsN.mjs → apply-manager-D5ym5Jba.mjs} +7 -7
- package/dist/{apply-manager-BkPMfpsN.mjs.map → apply-manager-D5ym5Jba.mjs.map} +1 -1
- package/dist/{astro-parser-BJ-54JGe.mjs → astro-parser-B-nLl0zE.mjs} +3 -3
- package/dist/{astro-parser-BJ-54JGe.mjs.map → astro-parser-B-nLl0zE.mjs.map} +1 -1
- package/dist/{branch-lifecycle-wGJg25LT.mjs → branch-lifecycle-CFVpTpNT.mjs} +33 -3
- package/dist/{branch-lifecycle-wGJg25LT.mjs.map → branch-lifecycle-CFVpTpNT.mjs.map} +1 -1
- package/dist/{compiler-rIC4ETHv.mjs → compiler-k4yttlzM.mjs} +2 -2
- package/dist/{compiler-rIC4ETHv.mjs.map → compiler-k4yttlzM.mjs.map} +1 -1
- package/dist/{compiler-sfc.cjs-BbD04rn_.mjs → compiler-sfc.cjs-D0d_OicF.mjs} +2 -2
- package/dist/{compiler-sfc.cjs-BbD04rn_.mjs.map → compiler-sfc.cjs-D0d_OicF.mjs.map} +1 -1
- package/dist/config-BIl5Ybj0.mjs +40 -0
- package/dist/config-BIl5Ybj0.mjs.map +1 -0
- package/dist/content-manager-DqDLSNQ-.d.mts +63 -0
- package/dist/content-manager-DqDLSNQ-.d.mts.map +1 -0
- package/dist/context-J0OU9Nfp.mjs +102 -0
- package/dist/context-J0OU9Nfp.mjs.map +1 -0
- package/dist/contracts-DfL0BfrD.mjs +2 -0
- package/dist/core/apply-manager.mjs +10 -10
- package/dist/core/config.d.mts +13 -0
- package/dist/core/config.d.mts.map +1 -1
- package/dist/core/config.mjs +2 -3
- package/dist/core/content-manager.d.mts +2 -45
- package/dist/core/content-manager.mjs +3 -4
- package/dist/core/context.d.mts +32 -2
- package/dist/core/context.d.mts.map +1 -1
- package/dist/core/context.mjs +7 -7
- package/dist/core/contracts/index.d.mts +2 -0
- package/dist/core/contracts/index.mjs +2 -0
- package/dist/core/doctor.d.mts +76 -0
- package/dist/core/doctor.d.mts.map +1 -0
- package/dist/core/doctor.mjs +8 -0
- package/dist/core/graph-builder.mjs +3 -4
- package/dist/core/meta-manager.mjs +2 -3
- package/dist/core/model-manager.d.mts +34 -1
- package/dist/core/model-manager.d.mts.map +1 -1
- package/dist/core/model-manager.mjs +3 -4
- package/dist/core/ops/index.d.mts +137 -0
- package/dist/core/ops/index.d.mts.map +1 -0
- package/dist/core/ops/index.mjs +4 -0
- package/dist/core/overlay-reader.d.mts +42 -0
- package/dist/core/overlay-reader.d.mts.map +1 -0
- package/dist/core/overlay-reader.mjs +2 -0
- package/dist/core/scan-config.mjs +2 -3
- package/dist/core/scanner.mjs +4 -5
- package/dist/core/validator/index.d.mts +129 -0
- package/dist/core/validator/index.d.mts.map +1 -0
- package/dist/core/validator/index.mjs +6 -0
- package/dist/{detect-DinOQAmK.mjs → detect-DL9mFmaS.mjs} +2 -2
- package/dist/{detect-DinOQAmK.mjs.map → detect-DL9mFmaS.mjs.map} +1 -1
- package/dist/doctor-CgBoT6h1.mjs +338 -0
- package/dist/doctor-CgBoT6h1.mjs.map +1 -0
- package/dist/{fs-BnIQ4dKj.mjs → fs-DLbVB-Ek.mjs} +2 -2
- package/dist/fs-DLbVB-Ek.mjs.map +1 -0
- package/dist/git/branch-lifecycle.d.mts +30 -1
- package/dist/git/branch-lifecycle.d.mts.map +1 -1
- package/dist/git/branch-lifecycle.mjs +4 -5
- package/dist/git/transaction.d.mts +2 -2
- package/dist/git/transaction.d.mts.map +1 -1
- package/dist/git/transaction.mjs +8 -8
- package/dist/{graph-builder-tM7zj-SX.mjs → graph-builder-DXv2JEp-.mjs} +3 -3
- package/dist/{graph-builder-tM7zj-SX.mjs.map → graph-builder-DXv2JEp-.mjs.map} +1 -1
- package/dist/{id-DV_T9Ic8.mjs → id-CIO9s0x_.mjs} +1 -1
- package/dist/{id-DV_T9Ic8.mjs.map → id-CIO9s0x_.mjs.map} +1 -1
- package/dist/index-D0wQJSgs.d.mts +2 -0
- package/dist/index.mjs +22 -17
- package/dist/index.mjs.map +1 -1
- package/dist/local-DvP4Y4T-.mjs +182 -0
- package/dist/local-DvP4Y4T-.mjs.map +1 -0
- package/dist/{meta-manager--0IwAPCl.mjs → meta-manager-C900rEyG.mjs} +2 -2
- package/dist/{meta-manager--0IwAPCl.mjs.map → meta-manager-C900rEyG.mjs.map} +1 -1
- package/dist/{model-manager-DW_fOGRM.mjs → model-manager-BhLsUgaB.mjs} +241 -49
- package/dist/model-manager-BhLsUgaB.mjs.map +1 -0
- package/dist/{node-Cbq5eR5i.mjs → node-DN9hZeil.mjs} +1 -1
- package/dist/{node-Cbq5eR5i.mjs.map → node-DN9hZeil.mjs.map} +1 -1
- package/dist/ops-DjEWi5Wa.mjs +486 -0
- package/dist/ops-DjEWi5Wa.mjs.map +1 -0
- package/dist/overlay-reader-DOdyDRIv.mjs +74 -0
- package/dist/overlay-reader-DOdyDRIv.mjs.map +1 -0
- package/dist/paths-C3xNyc7z.mjs +52 -0
- package/dist/paths-C3xNyc7z.mjs.map +1 -0
- package/dist/paths-CYl5vCBD.mjs +54 -0
- package/dist/paths-CYl5vCBD.mjs.map +1 -0
- package/dist/providers/github/index.d.mts +201 -0
- package/dist/providers/github/index.d.mts.map +1 -0
- package/dist/providers/github/index.mjs +494 -0
- package/dist/providers/github/index.mjs.map +1 -0
- package/dist/providers/gitlab/index.d.mts +158 -0
- package/dist/providers/gitlab/index.d.mts.map +1 -0
- package/dist/providers/gitlab/index.mjs +361 -0
- package/dist/providers/gitlab/index.mjs.map +1 -0
- package/dist/providers/local/index.d.mts +106 -0
- package/dist/providers/local/index.d.mts.map +1 -0
- package/dist/providers/local/index.mjs +12 -0
- package/dist/{scan-config-QgnJ1-52.mjs → scan-config-jC6XmiqF.mjs} +2 -2
- package/dist/{scan-config-QgnJ1-52.mjs.map → scan-config-jC6XmiqF.mjs.map} +1 -1
- package/dist/{scanner-DUoXnmtI.mjs → scanner-DKMwc03k.mjs} +7 -7
- package/dist/{scanner-DUoXnmtI.mjs.map → scanner-DKMwc03k.mjs.map} +1 -1
- package/dist/serialization-B1CEzR4H.mjs +2 -0
- package/dist/server/http/index.d.mts +107 -0
- package/dist/server/http/index.d.mts.map +1 -0
- package/dist/server/http/index.mjs +248 -0
- package/dist/server/http/index.mjs.map +1 -0
- package/dist/{server-Dtq8vqbK.mjs → server-BkhhtEE2.mjs} +486 -355
- package/dist/server-BkhhtEE2.mjs.map +1 -0
- package/dist/server-WqGx6ait.d.mts +50 -0
- package/dist/server-WqGx6ait.d.mts.map +1 -0
- package/dist/server.d.mts +2 -7
- package/dist/server.mjs +22 -17
- package/dist/{source-map-generator-DpO-ejrt.mjs → source-map-generator-BWDva49I.mjs} +1 -1
- package/dist/{source-map-generator-DpO-ejrt.mjs.map → source-map-generator-BWDva49I.mjs.map} +1 -1
- package/dist/{svelte-parser-1bBcMx3T.mjs → svelte-parser-Dr9mmZuk.mjs} +3 -3
- package/dist/{svelte-parser-1bBcMx3T.mjs.map → svelte-parser-Dr9mmZuk.mjs.map} +1 -1
- package/dist/templates/index.mjs +1 -1
- package/dist/{templates-bRPzYq4M.mjs → templates-VrLVqfe5.mjs} +1 -1
- package/dist/{templates-bRPzYq4M.mjs.map → templates-VrLVqfe5.mjs.map} +1 -1
- package/dist/testing/conformance.d.mts +59 -0
- package/dist/testing/conformance.d.mts.map +1 -0
- package/dist/testing/conformance.mjs +59 -0
- package/dist/testing/conformance.mjs.map +1 -0
- package/dist/tools/annotations.d.mts +24 -0
- package/dist/tools/annotations.d.mts.map +1 -0
- package/dist/tools/annotations.mjs +2 -0
- package/dist/{transaction-C_Pvux78.mjs → transaction-DgkNgWSI.mjs} +61 -32
- package/dist/transaction-DgkNgWSI.mjs.map +1 -0
- package/dist/tsx-parser-BOMZE_yQ.mjs +2 -0
- package/dist/{tsx-parser-BWiMGAIR.mjs → tsx-parser-CQc6nr-o.mjs} +1 -1
- package/dist/{tsx-parser-BWiMGAIR.mjs.map → tsx-parser-CQc6nr-o.mjs.map} +1 -1
- package/dist/util/detect.mjs +2 -3
- package/dist/util/fs.mjs +1 -2
- package/dist/util/id.mjs +1 -1
- package/dist/validator-B0nNRFeU.mjs +906 -0
- package/dist/validator-B0nNRFeU.mjs.map +1 -0
- package/dist/{vue-parser-DTPTN3Yb.mjs → vue-parser-COgjArqv.mjs} +3 -3
- package/dist/{vue-parser-DTPTN3Yb.mjs.map → vue-parser-COgjArqv.mjs.map} +1 -1
- package/package.json +82 -23
- package/testing/conformance/01-new-collection-entry/expected/.contentrain/config.json +15 -0
- package/testing/conformance/01-new-collection-entry/expected/.contentrain/content/blog/blog/en.json +6 -0
- package/testing/conformance/01-new-collection-entry/expected/.contentrain/context.json +22 -0
- package/testing/conformance/01-new-collection-entry/expected/.contentrain/meta/blog/en.json +7 -0
- package/testing/conformance/01-new-collection-entry/expected/.contentrain/models/blog.json +16 -0
- package/testing/conformance/01-new-collection-entry/scenario.json +19 -0
- package/testing/conformance/01-new-collection-entry/setup/.contentrain/config.json +15 -0
- package/testing/conformance/01-new-collection-entry/setup/.contentrain/models/blog.json +16 -0
- package/testing/conformance/02-new-singleton/expected/.contentrain/config.json +15 -0
- package/testing/conformance/02-new-singleton/expected/.contentrain/content/marketing/hero/en.json +4 -0
- package/testing/conformance/02-new-singleton/expected/.contentrain/context.json +22 -0
- package/testing/conformance/02-new-singleton/expected/.contentrain/meta/hero/en.json +5 -0
- package/testing/conformance/02-new-singleton/expected/.contentrain/models/hero.json +16 -0
- package/testing/conformance/02-new-singleton/scenario.json +18 -0
- package/testing/conformance/02-new-singleton/setup/.contentrain/config.json +15 -0
- package/testing/conformance/02-new-singleton/setup/.contentrain/models/hero.json +16 -0
- package/testing/conformance/03-new-dictionary/expected/.contentrain/config.json +15 -0
- package/testing/conformance/03-new-dictionary/expected/.contentrain/content/marketing/ui-strings/en.json +5 -0
- package/testing/conformance/03-new-dictionary/expected/.contentrain/context.json +22 -0
- package/testing/conformance/03-new-dictionary/expected/.contentrain/meta/ui-strings/en.json +5 -0
- package/testing/conformance/03-new-dictionary/expected/.contentrain/models/ui-strings.json +7 -0
- package/testing/conformance/03-new-dictionary/scenario.json +19 -0
- package/testing/conformance/03-new-dictionary/setup/.contentrain/config.json +15 -0
- package/testing/conformance/03-new-dictionary/setup/.contentrain/models/ui-strings.json +7 -0
- package/testing/conformance/README.md +77 -0
- package/testing/conformance/scenarios.json +36 -0
- package/dist/config-B5kc2oeV.mjs +0 -27
- package/dist/config-B5kc2oeV.mjs.map +0 -1
- package/dist/context-DIDt_TxX.mjs +0 -46
- package/dist/context-DIDt_TxX.mjs.map +0 -1
- package/dist/core/content-manager.d.mts.map +0 -1
- package/dist/core/validator.d.mts +0 -23
- package/dist/core/validator.d.mts.map +0 -1
- package/dist/core/validator.mjs +0 -7
- package/dist/fs-BnIQ4dKj.mjs.map +0 -1
- package/dist/model-manager-DW_fOGRM.mjs.map +0 -1
- package/dist/serializer-CnHTtmc1.mjs +0 -2
- package/dist/server-Dtq8vqbK.mjs.map +0 -1
- package/dist/server.d.mts.map +0 -1
- package/dist/transaction-C_Pvux78.mjs.map +0 -1
- package/dist/tsx-parser-BFLv292Y.mjs +0 -2
- package/dist/util/serializer.d.mts +0 -2
- package/dist/util/serializer.mjs +0 -2
- package/dist/validator-SQYUV2JP.mjs +0 -581
- package/dist/validator-SQYUV2JP.mjs.map +0 -1
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
import { n as isNotFoundError, t as resolveRepoPath } from "../../paths-C3xNyc7z.mjs";
|
|
2
|
+
import { CONTENTRAIN_BRANCH } from "@contentrain/types";
|
|
3
|
+
import { createPrivateKey, createSign } from "node:crypto";
|
|
4
|
+
//#region src/providers/github/app-auth.ts
|
|
5
|
+
/**
|
|
6
|
+
* Sign a GitHub App JWT.
|
|
7
|
+
*
|
|
8
|
+
* GitHub's spec: RS256 (RSASSA-PKCS1-v1_5), 10-minute max lifetime,
|
|
9
|
+
* `iat` 60 seconds in the past to cover small clock skew, `iss`
|
|
10
|
+
* set to the numeric app ID.
|
|
11
|
+
*/
|
|
12
|
+
function base64UrlEncode(obj) {
|
|
13
|
+
return Buffer.from(JSON.stringify(obj), "utf8").toString("base64url");
|
|
14
|
+
}
|
|
15
|
+
function signAppJwt(config) {
|
|
16
|
+
const now = Math.floor(Date.now() / 1e3);
|
|
17
|
+
const header = {
|
|
18
|
+
alg: "RS256",
|
|
19
|
+
typ: "JWT"
|
|
20
|
+
};
|
|
21
|
+
const payload = {
|
|
22
|
+
iat: now - 60,
|
|
23
|
+
exp: now + 540,
|
|
24
|
+
iss: String(config.appId)
|
|
25
|
+
};
|
|
26
|
+
const toSign = `${base64UrlEncode(header)}.${base64UrlEncode(payload)}`;
|
|
27
|
+
const keyObject = createPrivateKey({
|
|
28
|
+
key: config.privateKey,
|
|
29
|
+
format: "pem"
|
|
30
|
+
});
|
|
31
|
+
const signer = createSign("RSA-SHA256");
|
|
32
|
+
signer.update(toSign);
|
|
33
|
+
signer.end();
|
|
34
|
+
return `${toSign}.${signer.sign(keyObject).toString("base64url")}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Exchange an App JWT for an installation-scoped access token by calling
|
|
38
|
+
* GitHub's `POST /app/installations/{id}/access_tokens` endpoint.
|
|
39
|
+
*
|
|
40
|
+
* Uses `fetch` (Node ≥22 has it native) so the helper stays dependency-
|
|
41
|
+
* free. Throws on non-2xx responses with the GitHub-returned message.
|
|
42
|
+
*/
|
|
43
|
+
async function exchangeInstallationToken(config, opts = {}) {
|
|
44
|
+
const jwt = signAppJwt(config);
|
|
45
|
+
const baseUrl = opts.baseUrl ?? "https://api.github.com";
|
|
46
|
+
const response = await (opts.fetchImpl ?? globalThis.fetch)(`${baseUrl}/app/installations/${config.installationId}/access_tokens`, {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: {
|
|
49
|
+
Authorization: `Bearer ${jwt}`,
|
|
50
|
+
Accept: "application/vnd.github+json",
|
|
51
|
+
"X-GitHub-Api-Version": "2022-11-28"
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
const body = await response.text().catch(() => "");
|
|
56
|
+
throw new Error(`GitHub installation-token exchange failed: ${response.status} ${response.statusText}${body ? ` — ${body}` : ""}`);
|
|
57
|
+
}
|
|
58
|
+
const data = await response.json();
|
|
59
|
+
return {
|
|
60
|
+
token: data.token,
|
|
61
|
+
expiresAt: data.expires_at
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
//#region src/providers/github/capabilities.ts
|
|
66
|
+
/**
|
|
67
|
+
* Capability set for GitHubProvider.
|
|
68
|
+
*
|
|
69
|
+
* GitHub over the Git Data API has no working tree, so local worktree
|
|
70
|
+
* features, source-file access and AST scans are unavailable. Push /
|
|
71
|
+
* PR operations are free because every commit goes straight to the
|
|
72
|
+
* remote. Branch protection detection uses the Repos API.
|
|
73
|
+
*
|
|
74
|
+
* Tools that require `astScan`, `sourceRead` or `sourceWrite` must
|
|
75
|
+
* gracefully reject (with `capability_required`) when running against
|
|
76
|
+
* a GitHubProvider — this is the mechanism behind phase 6's normalize
|
|
77
|
+
* capability-gate.
|
|
78
|
+
*/
|
|
79
|
+
const GITHUB_CAPABILITIES = {
|
|
80
|
+
localWorktree: false,
|
|
81
|
+
sourceRead: false,
|
|
82
|
+
sourceWrite: false,
|
|
83
|
+
pushRemote: true,
|
|
84
|
+
branchProtection: true,
|
|
85
|
+
pullRequestFallback: true,
|
|
86
|
+
astScan: false
|
|
87
|
+
};
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/providers/github/apply-plan.ts
|
|
90
|
+
/**
|
|
91
|
+
* Apply a plan to a GitHub repository as a single atomic commit via the
|
|
92
|
+
* Git Data API. High-level flow:
|
|
93
|
+
*
|
|
94
|
+
* 1. Resolve the base commit SHA — either the current HEAD of the target
|
|
95
|
+
* branch, or the HEAD of `input.base` (or the repo's default branch)
|
|
96
|
+
* when the target branch does not yet exist.
|
|
97
|
+
* 2. Read the base tree SHA from that commit.
|
|
98
|
+
* 3. Walk `input.changes` in parallel — create a blob per non-null
|
|
99
|
+
* content, emit a tree entry with `sha: null` for each deletion.
|
|
100
|
+
* 4. Create a new tree layered on top of the base tree with the collected
|
|
101
|
+
* entries.
|
|
102
|
+
* 5. Create the commit (tree, parents, author).
|
|
103
|
+
* 6. Update an existing branch ref or create a new one pointing at the
|
|
104
|
+
* commit.
|
|
105
|
+
*
|
|
106
|
+
* No working tree, no transaction — the commit is durable as soon as the
|
|
107
|
+
* final ref update returns.
|
|
108
|
+
*/
|
|
109
|
+
async function applyPlanToGitHub(client, repo, input) {
|
|
110
|
+
const { baseSha, branchExists } = await resolveBaseSha(client, repo, input.branch, input.base);
|
|
111
|
+
const baseTreeSha = (await client.rest.git.getCommit({
|
|
112
|
+
owner: repo.owner,
|
|
113
|
+
repo: repo.name,
|
|
114
|
+
commit_sha: baseSha
|
|
115
|
+
})).data.tree.sha;
|
|
116
|
+
const treeEntries = await Promise.all(input.changes.map((change) => buildTreeEntry(client, repo, change)));
|
|
117
|
+
const tree = await client.rest.git.createTree({
|
|
118
|
+
owner: repo.owner,
|
|
119
|
+
repo: repo.name,
|
|
120
|
+
base_tree: baseTreeSha,
|
|
121
|
+
tree: treeEntries
|
|
122
|
+
});
|
|
123
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
124
|
+
const commit = await client.rest.git.createCommit({
|
|
125
|
+
owner: repo.owner,
|
|
126
|
+
repo: repo.name,
|
|
127
|
+
message: input.message,
|
|
128
|
+
tree: tree.data.sha,
|
|
129
|
+
parents: [baseSha],
|
|
130
|
+
author: {
|
|
131
|
+
name: input.author.name,
|
|
132
|
+
email: input.author.email,
|
|
133
|
+
date: timestamp
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
if (branchExists) await client.rest.git.updateRef({
|
|
137
|
+
owner: repo.owner,
|
|
138
|
+
repo: repo.name,
|
|
139
|
+
ref: `heads/${input.branch}`,
|
|
140
|
+
sha: commit.data.sha
|
|
141
|
+
});
|
|
142
|
+
else await client.rest.git.createRef({
|
|
143
|
+
owner: repo.owner,
|
|
144
|
+
repo: repo.name,
|
|
145
|
+
ref: `refs/heads/${input.branch}`,
|
|
146
|
+
sha: commit.data.sha
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
sha: commit.data.sha,
|
|
150
|
+
message: commit.data.message,
|
|
151
|
+
author: {
|
|
152
|
+
name: commit.data.author?.name ?? input.author.name,
|
|
153
|
+
email: commit.data.author?.email ?? input.author.email
|
|
154
|
+
},
|
|
155
|
+
timestamp: commit.data.author?.date ?? timestamp
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
async function buildTreeEntry(client, repo, change) {
|
|
159
|
+
const path = resolveRepoPath(repo.contentRoot, change.path);
|
|
160
|
+
if (change.content === null) return {
|
|
161
|
+
path,
|
|
162
|
+
mode: "100644",
|
|
163
|
+
type: "blob",
|
|
164
|
+
sha: null
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
path,
|
|
168
|
+
mode: "100644",
|
|
169
|
+
type: "blob",
|
|
170
|
+
sha: (await client.rest.git.createBlob({
|
|
171
|
+
owner: repo.owner,
|
|
172
|
+
repo: repo.name,
|
|
173
|
+
content: change.content,
|
|
174
|
+
encoding: "utf-8"
|
|
175
|
+
})).data.sha
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
async function resolveBaseSha(client, repo, branch, base) {
|
|
179
|
+
try {
|
|
180
|
+
return {
|
|
181
|
+
baseSha: (await client.rest.git.getRef({
|
|
182
|
+
owner: repo.owner,
|
|
183
|
+
repo: repo.name,
|
|
184
|
+
ref: `heads/${branch}`
|
|
185
|
+
})).data.object.sha,
|
|
186
|
+
branchExists: true
|
|
187
|
+
};
|
|
188
|
+
} catch (error) {
|
|
189
|
+
if (!isNotFoundError(error)) throw error;
|
|
190
|
+
}
|
|
191
|
+
const baseRefName = base ?? CONTENTRAIN_BRANCH;
|
|
192
|
+
return {
|
|
193
|
+
baseSha: (await client.rest.git.getRef({
|
|
194
|
+
owner: repo.owner,
|
|
195
|
+
repo: repo.name,
|
|
196
|
+
ref: `heads/${baseRefName}`
|
|
197
|
+
})).data.object.sha,
|
|
198
|
+
branchExists: false
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/providers/github/branch-ops.ts
|
|
203
|
+
/**
|
|
204
|
+
* Branch/merge/diff helpers backed by the Repos and Git Data APIs.
|
|
205
|
+
*
|
|
206
|
+
* Pure functions so they can be composed into `GitHubProvider` or used
|
|
207
|
+
* standalone. All throw on non-404 errors; 404s collapse to empty-ish
|
|
208
|
+
* results where that matches the `RepoProvider` contract (e.g. a
|
|
209
|
+
* missing branch prefix yields `[]` rather than raising).
|
|
210
|
+
*/
|
|
211
|
+
async function getDefaultBranch(client, repo) {
|
|
212
|
+
return (await client.rest.repos.get({
|
|
213
|
+
owner: repo.owner,
|
|
214
|
+
repo: repo.name
|
|
215
|
+
})).data.default_branch;
|
|
216
|
+
}
|
|
217
|
+
async function listBranches(client, repo, prefix) {
|
|
218
|
+
const branches = [];
|
|
219
|
+
const iterator = client.paginate.iterator(client.rest.repos.listBranches, {
|
|
220
|
+
owner: repo.owner,
|
|
221
|
+
repo: repo.name,
|
|
222
|
+
per_page: 100
|
|
223
|
+
});
|
|
224
|
+
for await (const page of iterator) for (const b of page.data) {
|
|
225
|
+
if (prefix && !b.name.startsWith(prefix)) continue;
|
|
226
|
+
branches.push({
|
|
227
|
+
name: b.name,
|
|
228
|
+
sha: b.commit.sha,
|
|
229
|
+
protected: b.protected
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return branches;
|
|
233
|
+
}
|
|
234
|
+
async function createBranch(client, repo, name, fromRef) {
|
|
235
|
+
const base = await client.rest.git.getRef({
|
|
236
|
+
owner: repo.owner,
|
|
237
|
+
repo: repo.name,
|
|
238
|
+
ref: `heads/${fromRef}`
|
|
239
|
+
});
|
|
240
|
+
await client.rest.git.createRef({
|
|
241
|
+
owner: repo.owner,
|
|
242
|
+
repo: repo.name,
|
|
243
|
+
ref: `refs/heads/${name}`,
|
|
244
|
+
sha: base.data.object.sha
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
async function deleteBranch(client, repo, name) {
|
|
248
|
+
await client.rest.git.deleteRef({
|
|
249
|
+
owner: repo.owner,
|
|
250
|
+
repo: repo.name,
|
|
251
|
+
ref: `heads/${name}`
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
async function getBranchDiff(client, repo, branch, base) {
|
|
255
|
+
return ((await client.rest.repos.compareCommits({
|
|
256
|
+
owner: repo.owner,
|
|
257
|
+
repo: repo.name,
|
|
258
|
+
base,
|
|
259
|
+
head: branch
|
|
260
|
+
})).data.files ?? []).map((f) => ({
|
|
261
|
+
path: f.filename,
|
|
262
|
+
status: normaliseStatus(f.status),
|
|
263
|
+
before: null,
|
|
264
|
+
after: null
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
267
|
+
async function mergeBranch(client, repo, branch, into) {
|
|
268
|
+
try {
|
|
269
|
+
return {
|
|
270
|
+
merged: true,
|
|
271
|
+
sha: (await client.rest.repos.merge({
|
|
272
|
+
owner: repo.owner,
|
|
273
|
+
repo: repo.name,
|
|
274
|
+
base: into,
|
|
275
|
+
head: branch
|
|
276
|
+
})).data.sha,
|
|
277
|
+
pullRequestUrl: null
|
|
278
|
+
};
|
|
279
|
+
} catch (error) {
|
|
280
|
+
if (isNotModified(error)) return {
|
|
281
|
+
merged: true,
|
|
282
|
+
sha: null,
|
|
283
|
+
pullRequestUrl: null
|
|
284
|
+
};
|
|
285
|
+
throw error;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
async function isMerged(client, repo, branch, into) {
|
|
289
|
+
return (await client.rest.repos.compareCommits({
|
|
290
|
+
owner: repo.owner,
|
|
291
|
+
repo: repo.name,
|
|
292
|
+
base: into,
|
|
293
|
+
head: branch
|
|
294
|
+
})).data.ahead_by === 0;
|
|
295
|
+
}
|
|
296
|
+
function normaliseStatus(status) {
|
|
297
|
+
if (status === "added") return "added";
|
|
298
|
+
if (status === "removed") return "removed";
|
|
299
|
+
return "modified";
|
|
300
|
+
}
|
|
301
|
+
function isNotModified(error) {
|
|
302
|
+
return typeof error === "object" && error !== null && error.status === 204;
|
|
303
|
+
}
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/providers/github/reader.ts
|
|
306
|
+
/**
|
|
307
|
+
* GitHubReader — `RepoReader` backed by the GitHub Repos + Git Data APIs.
|
|
308
|
+
*
|
|
309
|
+
* Reads pass through `repos.getContent`; directories return a list of
|
|
310
|
+
* names, files return decoded UTF-8 text. Files larger than ~1 MB are
|
|
311
|
+
* fetched by blob SHA through `git.getBlob` because `getContent` omits
|
|
312
|
+
* the body in that case.
|
|
313
|
+
*
|
|
314
|
+
* `ref` is forwarded verbatim and may be a branch name, tag name or
|
|
315
|
+
* commit SHA. When omitted, GitHub resolves to the repository's default
|
|
316
|
+
* branch — which is usually wrong for Contentrain flows, so callers
|
|
317
|
+
* should always pass the explicit `contentrain` tracking branch.
|
|
318
|
+
*/
|
|
319
|
+
var GitHubReader = class {
|
|
320
|
+
constructor(client, repo) {
|
|
321
|
+
this.client = client;
|
|
322
|
+
this.repo = repo;
|
|
323
|
+
}
|
|
324
|
+
async readFile(path, ref) {
|
|
325
|
+
const repoPath = resolveRepoPath(this.repo.contentRoot, path);
|
|
326
|
+
const data = (await this.client.rest.repos.getContent({
|
|
327
|
+
owner: this.repo.owner,
|
|
328
|
+
repo: this.repo.name,
|
|
329
|
+
path: repoPath,
|
|
330
|
+
ref
|
|
331
|
+
})).data;
|
|
332
|
+
if (Array.isArray(data)) throw new Error(`GitHubReader: path "${path}" is a directory, not a file`);
|
|
333
|
+
if (data.type !== "file") throw new Error(`GitHubReader: path "${path}" is a ${data.type}, not a file`);
|
|
334
|
+
if (data.content === "" && data.size > 0) {
|
|
335
|
+
const blob = await this.client.rest.git.getBlob({
|
|
336
|
+
owner: this.repo.owner,
|
|
337
|
+
repo: this.repo.name,
|
|
338
|
+
file_sha: data.sha
|
|
339
|
+
});
|
|
340
|
+
if (blob.data.encoding !== "base64") throw new Error(`GitHubReader: unexpected blob encoding "${blob.data.encoding}" for ${path}`);
|
|
341
|
+
return Buffer.from(blob.data.content, "base64").toString("utf-8");
|
|
342
|
+
}
|
|
343
|
+
if (data.encoding !== "base64") throw new Error(`GitHubReader: unexpected encoding "${data.encoding}" for ${path}`);
|
|
344
|
+
return Buffer.from(data.content, "base64").toString("utf-8");
|
|
345
|
+
}
|
|
346
|
+
async listDirectory(path, ref) {
|
|
347
|
+
const repoPath = resolveRepoPath(this.repo.contentRoot, path);
|
|
348
|
+
try {
|
|
349
|
+
const data = (await this.client.rest.repos.getContent({
|
|
350
|
+
owner: this.repo.owner,
|
|
351
|
+
repo: this.repo.name,
|
|
352
|
+
path: repoPath,
|
|
353
|
+
ref
|
|
354
|
+
})).data;
|
|
355
|
+
if (!Array.isArray(data)) return [];
|
|
356
|
+
return data.map((entry) => entry.name);
|
|
357
|
+
} catch (error) {
|
|
358
|
+
if (isNotFoundError(error)) return [];
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
async fileExists(path, ref) {
|
|
363
|
+
const repoPath = resolveRepoPath(this.repo.contentRoot, path);
|
|
364
|
+
try {
|
|
365
|
+
await this.client.rest.repos.getContent({
|
|
366
|
+
owner: this.repo.owner,
|
|
367
|
+
repo: this.repo.name,
|
|
368
|
+
path: repoPath,
|
|
369
|
+
ref
|
|
370
|
+
});
|
|
371
|
+
return true;
|
|
372
|
+
} catch (error) {
|
|
373
|
+
if (isNotFoundError(error)) return false;
|
|
374
|
+
throw error;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region src/providers/github/provider.ts
|
|
380
|
+
/**
|
|
381
|
+
* GitHubProvider — `RepoProvider` backed by the Octokit-driven GitHub
|
|
382
|
+
* REST + Git Data APIs.
|
|
383
|
+
*
|
|
384
|
+
* The provider is transport-agnostic; it only talks to an `Octokit`
|
|
385
|
+
* instance passed into the constructor. The `createGitHubProvider`
|
|
386
|
+
* helper in `factory.ts` wraps the dynamic import so consumers never
|
|
387
|
+
* have to touch Octokit directly.
|
|
388
|
+
*/
|
|
389
|
+
var GitHubProvider = class {
|
|
390
|
+
capabilities = GITHUB_CAPABILITIES;
|
|
391
|
+
reader;
|
|
392
|
+
constructor(client, repo) {
|
|
393
|
+
this.client = client;
|
|
394
|
+
this.repo = repo;
|
|
395
|
+
this.reader = new GitHubReader(client, repo);
|
|
396
|
+
}
|
|
397
|
+
readFile(path, ref) {
|
|
398
|
+
return this.reader.readFile(path, ref);
|
|
399
|
+
}
|
|
400
|
+
listDirectory(path, ref) {
|
|
401
|
+
return this.reader.listDirectory(path, ref);
|
|
402
|
+
}
|
|
403
|
+
fileExists(path, ref) {
|
|
404
|
+
return this.reader.fileExists(path, ref);
|
|
405
|
+
}
|
|
406
|
+
applyPlan(input) {
|
|
407
|
+
return applyPlanToGitHub(this.client, this.repo, input);
|
|
408
|
+
}
|
|
409
|
+
listBranches(prefix) {
|
|
410
|
+
return listBranches(this.client, this.repo, prefix);
|
|
411
|
+
}
|
|
412
|
+
createBranch(name, fromRef) {
|
|
413
|
+
const resolved = fromRef ?? "main";
|
|
414
|
+
return createBranch(this.client, this.repo, name, resolved);
|
|
415
|
+
}
|
|
416
|
+
deleteBranch(name) {
|
|
417
|
+
return deleteBranch(this.client, this.repo, name);
|
|
418
|
+
}
|
|
419
|
+
getBranchDiff(branch, base) {
|
|
420
|
+
const resolved = base ?? "main";
|
|
421
|
+
return getBranchDiff(this.client, this.repo, branch, resolved);
|
|
422
|
+
}
|
|
423
|
+
mergeBranch(branch, into) {
|
|
424
|
+
return mergeBranch(this.client, this.repo, branch, into);
|
|
425
|
+
}
|
|
426
|
+
isMerged(branch, into) {
|
|
427
|
+
const resolved = into ?? "main";
|
|
428
|
+
return isMerged(this.client, this.repo, branch, resolved);
|
|
429
|
+
}
|
|
430
|
+
getDefaultBranch() {
|
|
431
|
+
return getDefaultBranch(this.client, this.repo);
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
//#endregion
|
|
435
|
+
//#region src/providers/github/factory.ts
|
|
436
|
+
/**
|
|
437
|
+
* Create an Octokit-backed `GitHubClient` from an auth configuration.
|
|
438
|
+
*
|
|
439
|
+
* The `@octokit/rest` module is imported dynamically so it stays a pure
|
|
440
|
+
* optional peer dependency — self-hosted MCP on stdio can run without
|
|
441
|
+
* it. If the module is not installed, the import throws with a helpful
|
|
442
|
+
* hint pointing the operator at the peer dependency.
|
|
443
|
+
*
|
|
444
|
+
* Two auth modes:
|
|
445
|
+
*
|
|
446
|
+
* - `pat` — personal access token or fine-grained PAT. Simplest for
|
|
447
|
+
* self-hosted MCP or CI runners.
|
|
448
|
+
* - `app` — GitHub App installation auth. The factory mints a short-
|
|
449
|
+
* lived JWT, exchanges it for an installation token via
|
|
450
|
+
* `exchangeInstallationToken`, and instantiates Octokit with the
|
|
451
|
+
* resulting bearer. The returned token expires in ~1 hour; callers
|
|
452
|
+
* that need auto-refresh should instead inject their own Octokit
|
|
453
|
+
* built with `@octokit/auth-app`'s auth strategy and construct
|
|
454
|
+
* `GitHubProvider` directly. See the embedding guide for trade-offs.
|
|
455
|
+
*/
|
|
456
|
+
async function createGitHubClient(auth) {
|
|
457
|
+
let OctokitCtor;
|
|
458
|
+
try {
|
|
459
|
+
({Octokit: OctokitCtor} = await import("@octokit/rest"));
|
|
460
|
+
} catch (error) {
|
|
461
|
+
throw new Error("@octokit/rest is required for the GitHubProvider but could not be loaded. Install it as a peer dependency: pnpm add @octokit/rest.", { cause: error });
|
|
462
|
+
}
|
|
463
|
+
if (auth.type === "pat") return new OctokitCtor({ auth: auth.token });
|
|
464
|
+
if (auth.type === "app") {
|
|
465
|
+
const { token } = await exchangeInstallationToken({
|
|
466
|
+
appId: auth.appId,
|
|
467
|
+
privateKey: auth.privateKey,
|
|
468
|
+
installationId: auth.installationId
|
|
469
|
+
});
|
|
470
|
+
return new OctokitCtor({ auth: token });
|
|
471
|
+
}
|
|
472
|
+
const unknown = auth;
|
|
473
|
+
throw new Error(`GitHub auth type "${unknown.type}" is not supported. Use "pat" or "app".`);
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Factory for the full provider — instantiates an Octokit client and
|
|
477
|
+
* wraps it in a `GitHubProvider`. Consumers who already hold an Octokit
|
|
478
|
+
* instance (HTTP server injecting shared clients, tests, etc.) should
|
|
479
|
+
* instantiate `GitHubProvider` directly instead.
|
|
480
|
+
*/
|
|
481
|
+
async function createGitHubProvider(opts) {
|
|
482
|
+
return new GitHubProvider(await createGitHubClient(opts.auth), opts.repo);
|
|
483
|
+
}
|
|
484
|
+
//#endregion
|
|
485
|
+
//#region src/providers/github/types.ts
|
|
486
|
+
/** Default author used when a call does not provide one. */
|
|
487
|
+
const DEFAULT_GITHUB_AUTHOR = {
|
|
488
|
+
name: "Contentrain",
|
|
489
|
+
email: "mcp@contentrain.io"
|
|
490
|
+
};
|
|
491
|
+
//#endregion
|
|
492
|
+
export { DEFAULT_GITHUB_AUTHOR, GITHUB_CAPABILITIES, GitHubProvider, GitHubReader, createGitHubClient, createGitHubProvider, exchangeInstallationToken, signAppJwt };
|
|
493
|
+
|
|
494
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["listBranchesOp","createBranchOp","deleteBranchOp","getBranchDiffOp","mergeBranchOp","isMergedOp","getDefaultBranchOp"],"sources":["../../../src/providers/github/app-auth.ts","../../../src/providers/github/capabilities.ts","../../../src/providers/github/apply-plan.ts","../../../src/providers/github/branch-ops.ts","../../../src/providers/github/reader.ts","../../../src/providers/github/provider.ts","../../../src/providers/github/factory.ts","../../../src/providers/github/types.ts"],"sourcesContent":["import { createPrivateKey, createSign } from 'node:crypto'\n\n/**\n * GitHub App authentication helpers.\n *\n * Two entry points:\n *\n * - {@link signAppJwt} — mint a short-lived (10 min) GitHub App JWT from\n * `appId` + `privateKey`. Used to authenticate app-level endpoints\n * (listing installations, creating installation tokens).\n *\n * - {@link exchangeInstallationToken} — exchange an app JWT for a\n * per-installation access token that can be passed straight to\n * `Octokit({ auth: token })`. Installation tokens last ~1 hour and\n * must be refreshed.\n *\n * Both helpers are pure — they never import `@octokit/rest` or\n * `@octokit/auth-app`. Callers that want auto-refresh behaviour should\n * either wire `@octokit/auth-app` as the `authStrategy` when constructing\n * their own Octokit (see the embedding guide), or call\n * `exchangeInstallationToken` on their own schedule.\n */\n\nexport interface AppAuthConfig {\n /** GitHub App ID (numeric, from the app's settings page). */\n appId: number\n /** PEM-encoded private key — the contents of the `.pem` the app issued. */\n privateKey: string\n /** Installation the token should be scoped to. */\n installationId: number\n}\n\nexport interface InstallationTokenResult {\n /** Opaque bearer token — pass to `new Octokit({ auth: token })`. */\n token: string\n /** ISO 8601 expiry. Installation tokens expire after ~1 hour. */\n expiresAt: string\n}\n\n/**\n * Sign a GitHub App JWT.\n *\n * GitHub's spec: RS256 (RSASSA-PKCS1-v1_5), 10-minute max lifetime,\n * `iat` 60 seconds in the past to cover small clock skew, `iss`\n * set to the numeric app ID.\n */\nfunction base64UrlEncode(obj: unknown): string {\n return Buffer.from(JSON.stringify(obj), 'utf8').toString('base64url')\n}\n\nexport function signAppJwt(config: Pick<AppAuthConfig, 'appId' | 'privateKey'>): string {\n const now = Math.floor(Date.now() / 1000)\n const header = { alg: 'RS256', typ: 'JWT' }\n const payload = {\n iat: now - 60,\n exp: now + 9 * 60,\n iss: String(config.appId),\n }\n\n const toSign = `${base64UrlEncode(header)}.${base64UrlEncode(payload)}`\n const keyObject = createPrivateKey({ key: config.privateKey, format: 'pem' })\n const signer = createSign('RSA-SHA256')\n signer.update(toSign)\n signer.end()\n const signature = signer.sign(keyObject).toString('base64url')\n\n return `${toSign}.${signature}`\n}\n\n/**\n * Exchange an App JWT for an installation-scoped access token by calling\n * GitHub's `POST /app/installations/{id}/access_tokens` endpoint.\n *\n * Uses `fetch` (Node ≥22 has it native) so the helper stays dependency-\n * free. Throws on non-2xx responses with the GitHub-returned message.\n */\nexport async function exchangeInstallationToken(\n config: AppAuthConfig,\n opts: { baseUrl?: string, fetchImpl?: typeof globalThis.fetch } = {},\n): Promise<InstallationTokenResult> {\n const jwt = signAppJwt(config)\n const baseUrl = opts.baseUrl ?? 'https://api.github.com'\n const fetchImpl = opts.fetchImpl ?? globalThis.fetch\n\n const url = `${baseUrl}/app/installations/${config.installationId}/access_tokens`\n const response = await fetchImpl(url, {\n method: 'POST',\n headers: {\n Authorization: `Bearer ${jwt}`,\n Accept: 'application/vnd.github+json',\n 'X-GitHub-Api-Version': '2022-11-28',\n },\n })\n\n if (!response.ok) {\n const body = await response.text().catch(() => '')\n throw new Error(\n `GitHub installation-token exchange failed: ${response.status} ${response.statusText}${body ? ` — ${body}` : ''}`,\n )\n }\n\n const data = await response.json() as { token: string, expires_at: string }\n return { token: data.token, expiresAt: data.expires_at }\n}\n","import type { ProviderCapabilities } from '../../core/contracts/index.js'\n\n/**\n * Capability set for GitHubProvider.\n *\n * GitHub over the Git Data API has no working tree, so local worktree\n * features, source-file access and AST scans are unavailable. Push /\n * PR operations are free because every commit goes straight to the\n * remote. Branch protection detection uses the Repos API.\n *\n * Tools that require `astScan`, `sourceRead` or `sourceWrite` must\n * gracefully reject (with `capability_required`) when running against\n * a GitHubProvider — this is the mechanism behind phase 6's normalize\n * capability-gate.\n */\nexport const GITHUB_CAPABILITIES: ProviderCapabilities = {\n localWorktree: false,\n sourceRead: false,\n sourceWrite: false,\n pushRemote: true,\n branchProtection: true,\n pullRequestFallback: true,\n astScan: false,\n}\n","import { CONTENTRAIN_BRANCH } from '@contentrain/types'\nimport type { ApplyPlanInput, Commit, FileChange } from '../../core/contracts/index.js'\nimport { isNotFoundError, resolveRepoPath } from '../shared/index.js'\nimport type { GitHubClient } from './client.js'\nimport type { RepoRef } from './types.js'\n\ninterface TreeEntry {\n path: string\n mode: '100644' | '100755' | '040000' | '160000' | '120000'\n type: 'blob' | 'tree' | 'commit'\n sha: string | null\n}\n\n/**\n * Apply a plan to a GitHub repository as a single atomic commit via the\n * Git Data API. High-level flow:\n *\n * 1. Resolve the base commit SHA — either the current HEAD of the target\n * branch, or the HEAD of `input.base` (or the repo's default branch)\n * when the target branch does not yet exist.\n * 2. Read the base tree SHA from that commit.\n * 3. Walk `input.changes` in parallel — create a blob per non-null\n * content, emit a tree entry with `sha: null` for each deletion.\n * 4. Create a new tree layered on top of the base tree with the collected\n * entries.\n * 5. Create the commit (tree, parents, author).\n * 6. Update an existing branch ref or create a new one pointing at the\n * commit.\n *\n * No working tree, no transaction — the commit is durable as soon as the\n * final ref update returns.\n */\nexport async function applyPlanToGitHub(\n client: GitHubClient,\n repo: RepoRef,\n input: ApplyPlanInput,\n): Promise<Commit> {\n const { baseSha, branchExists } = await resolveBaseSha(client, repo, input.branch, input.base)\n\n const baseCommit = await client.rest.git.getCommit({\n owner: repo.owner,\n repo: repo.name,\n commit_sha: baseSha,\n })\n const baseTreeSha = baseCommit.data.tree.sha\n\n const treeEntries = await Promise.all(\n input.changes.map(change => buildTreeEntry(client, repo, change)),\n )\n\n const tree = await client.rest.git.createTree({\n owner: repo.owner,\n repo: repo.name,\n base_tree: baseTreeSha,\n tree: treeEntries,\n })\n\n const timestamp = new Date().toISOString()\n const commit = await client.rest.git.createCommit({\n owner: repo.owner,\n repo: repo.name,\n message: input.message,\n tree: tree.data.sha,\n parents: [baseSha],\n author: {\n name: input.author.name,\n email: input.author.email,\n date: timestamp,\n },\n })\n\n if (branchExists) {\n await client.rest.git.updateRef({\n owner: repo.owner,\n repo: repo.name,\n ref: `heads/${input.branch}`,\n sha: commit.data.sha,\n })\n } else {\n await client.rest.git.createRef({\n owner: repo.owner,\n repo: repo.name,\n ref: `refs/heads/${input.branch}`,\n sha: commit.data.sha,\n })\n }\n\n return {\n sha: commit.data.sha,\n message: commit.data.message,\n author: {\n name: commit.data.author?.name ?? input.author.name,\n email: commit.data.author?.email ?? input.author.email,\n },\n timestamp: commit.data.author?.date ?? timestamp,\n }\n}\n\nasync function buildTreeEntry(\n client: GitHubClient,\n repo: RepoRef,\n change: FileChange,\n): Promise<TreeEntry> {\n const path = resolveRepoPath(repo.contentRoot, change.path)\n if (change.content === null) {\n return { path, mode: '100644', type: 'blob', sha: null }\n }\n const blob = await client.rest.git.createBlob({\n owner: repo.owner,\n repo: repo.name,\n content: change.content,\n encoding: 'utf-8',\n })\n return { path, mode: '100644', type: 'blob', sha: blob.data.sha }\n}\n\nasync function resolveBaseSha(\n client: GitHubClient,\n repo: RepoRef,\n branch: string,\n base: string | undefined,\n): Promise<{ baseSha: string, branchExists: boolean }> {\n try {\n const ref = await client.rest.git.getRef({\n owner: repo.owner,\n repo: repo.name,\n ref: `heads/${branch}`,\n })\n return { baseSha: ref.data.object.sha, branchExists: true }\n } catch (error) {\n if (!isNotFoundError(error)) throw error\n }\n\n // Invariant: feature branches always fork from the Contentrain\n // content-tracking branch. Callers that genuinely want to bypass this\n // must pass `base` explicitly. The repository's default branch\n // (main / master / trunk) is NOT the fallback — that would create a\n // split-brain where remote writes derive from a different ref than\n // local writes, which the LocalProvider transaction path forbids.\n const baseRefName = base ?? CONTENTRAIN_BRANCH\n\n const baseRef = await client.rest.git.getRef({\n owner: repo.owner,\n repo: repo.name,\n ref: `heads/${baseRefName}`,\n })\n return { baseSha: baseRef.data.object.sha, branchExists: false }\n}\n","import type { Branch, FileDiff, MergeResult } from '../../core/contracts/index.js'\nimport type { GitHubClient } from './client.js'\nimport type { RepoRef } from './types.js'\n\n/**\n * Branch/merge/diff helpers backed by the Repos and Git Data APIs.\n *\n * Pure functions so they can be composed into `GitHubProvider` or used\n * standalone. All throw on non-404 errors; 404s collapse to empty-ish\n * results where that matches the `RepoProvider` contract (e.g. a\n * missing branch prefix yields `[]` rather than raising).\n */\n\nexport async function getDefaultBranch(client: GitHubClient, repo: RepoRef): Promise<string> {\n const response = await client.rest.repos.get({ owner: repo.owner, repo: repo.name })\n return response.data.default_branch\n}\n\nexport async function listBranches(\n client: GitHubClient,\n repo: RepoRef,\n prefix?: string,\n): Promise<Branch[]> {\n const branches: Branch[] = []\n const iterator = client.paginate.iterator(client.rest.repos.listBranches, {\n owner: repo.owner,\n repo: repo.name,\n per_page: 100,\n })\n for await (const page of iterator) {\n for (const b of page.data) {\n if (prefix && !b.name.startsWith(prefix)) continue\n branches.push({ name: b.name, sha: b.commit.sha, protected: b.protected })\n }\n }\n return branches\n}\n\nexport async function createBranch(\n client: GitHubClient,\n repo: RepoRef,\n name: string,\n fromRef: string,\n): Promise<void> {\n const base = await client.rest.git.getRef({\n owner: repo.owner,\n repo: repo.name,\n ref: `heads/${fromRef}`,\n })\n await client.rest.git.createRef({\n owner: repo.owner,\n repo: repo.name,\n ref: `refs/heads/${name}`,\n sha: base.data.object.sha,\n })\n}\n\nexport async function deleteBranch(\n client: GitHubClient,\n repo: RepoRef,\n name: string,\n): Promise<void> {\n await client.rest.git.deleteRef({\n owner: repo.owner,\n repo: repo.name,\n ref: `heads/${name}`,\n })\n}\n\nexport async function getBranchDiff(\n client: GitHubClient,\n repo: RepoRef,\n branch: string,\n base: string,\n): Promise<FileDiff[]> {\n const response = await client.rest.repos.compareCommits({\n owner: repo.owner,\n repo: repo.name,\n base,\n head: branch,\n })\n const files = response.data.files ?? []\n return files.map(f => ({\n path: f.filename,\n status: normaliseStatus(f.status),\n before: null,\n after: null,\n }))\n}\n\nexport async function mergeBranch(\n client: GitHubClient,\n repo: RepoRef,\n branch: string,\n into: string,\n): Promise<MergeResult> {\n try {\n const response = await client.rest.repos.merge({\n owner: repo.owner,\n repo: repo.name,\n base: into,\n head: branch,\n })\n return { merged: true, sha: response.data.sha, pullRequestUrl: null }\n } catch (error) {\n if (isNotModified(error)) {\n return { merged: true, sha: null, pullRequestUrl: null }\n }\n throw error\n }\n}\n\nexport async function isMerged(\n client: GitHubClient,\n repo: RepoRef,\n branch: string,\n into: string,\n): Promise<boolean> {\n const response = await client.rest.repos.compareCommits({\n owner: repo.owner,\n repo: repo.name,\n base: into,\n head: branch,\n })\n return response.data.ahead_by === 0\n}\n\nfunction normaliseStatus(status: string): FileDiff['status'] {\n if (status === 'added') return 'added'\n if (status === 'removed') return 'removed'\n return 'modified'\n}\n\nfunction isNotModified(error: unknown): boolean {\n return typeof error === 'object' && error !== null && (error as { status?: number }).status === 204\n}\n","import type { RepoReader } from '../../core/contracts/index.js'\nimport { isNotFoundError, resolveRepoPath } from '../shared/index.js'\nimport type { GitHubClient } from './client.js'\nimport type { RepoRef } from './types.js'\n\n/**\n * GitHubReader — `RepoReader` backed by the GitHub Repos + Git Data APIs.\n *\n * Reads pass through `repos.getContent`; directories return a list of\n * names, files return decoded UTF-8 text. Files larger than ~1 MB are\n * fetched by blob SHA through `git.getBlob` because `getContent` omits\n * the body in that case.\n *\n * `ref` is forwarded verbatim and may be a branch name, tag name or\n * commit SHA. When omitted, GitHub resolves to the repository's default\n * branch — which is usually wrong for Contentrain flows, so callers\n * should always pass the explicit `contentrain` tracking branch.\n */\nexport class GitHubReader implements RepoReader {\n constructor(\n private readonly client: GitHubClient,\n private readonly repo: RepoRef,\n ) {}\n\n async readFile(path: string, ref?: string): Promise<string> {\n const repoPath = resolveRepoPath(this.repo.contentRoot, path)\n const response = await this.client.rest.repos.getContent({\n owner: this.repo.owner,\n repo: this.repo.name,\n path: repoPath,\n ref,\n })\n const data = response.data\n if (Array.isArray(data)) {\n throw new Error(`GitHubReader: path \"${path}\" is a directory, not a file`)\n }\n if (data.type !== 'file') {\n throw new Error(`GitHubReader: path \"${path}\" is a ${data.type}, not a file`)\n }\n\n // GitHub omits content for files > 1 MB — fall back to blob fetch.\n if (data.content === '' && data.size > 0) {\n const blob = await this.client.rest.git.getBlob({\n owner: this.repo.owner,\n repo: this.repo.name,\n file_sha: data.sha,\n })\n if (blob.data.encoding !== 'base64') {\n throw new Error(`GitHubReader: unexpected blob encoding \"${blob.data.encoding}\" for ${path}`)\n }\n return Buffer.from(blob.data.content, 'base64').toString('utf-8')\n }\n\n if (data.encoding !== 'base64') {\n throw new Error(`GitHubReader: unexpected encoding \"${data.encoding}\" for ${path}`)\n }\n return Buffer.from(data.content, 'base64').toString('utf-8')\n }\n\n async listDirectory(path: string, ref?: string): Promise<string[]> {\n const repoPath = resolveRepoPath(this.repo.contentRoot, path)\n try {\n const response = await this.client.rest.repos.getContent({\n owner: this.repo.owner,\n repo: this.repo.name,\n path: repoPath,\n ref,\n })\n const data = response.data\n if (!Array.isArray(data)) return []\n return data.map(entry => entry.name)\n } catch (error) {\n if (isNotFoundError(error)) return []\n throw error\n }\n }\n\n async fileExists(path: string, ref?: string): Promise<boolean> {\n const repoPath = resolveRepoPath(this.repo.contentRoot, path)\n try {\n await this.client.rest.repos.getContent({\n owner: this.repo.owner,\n repo: this.repo.name,\n path: repoPath,\n ref,\n })\n return true\n } catch (error) {\n if (isNotFoundError(error)) return false\n throw error\n }\n }\n}\n","import type {\n ApplyPlanInput,\n Branch,\n Commit,\n FileDiff,\n MergeResult,\n ProviderCapabilities,\n RepoProvider,\n} from '../../core/contracts/index.js'\nimport { applyPlanToGitHub } from './apply-plan.js'\nimport {\n createBranch as createBranchOp,\n deleteBranch as deleteBranchOp,\n getBranchDiff as getBranchDiffOp,\n getDefaultBranch as getDefaultBranchOp,\n isMerged as isMergedOp,\n listBranches as listBranchesOp,\n mergeBranch as mergeBranchOp,\n} from './branch-ops.js'\nimport { GITHUB_CAPABILITIES } from './capabilities.js'\nimport type { GitHubClient } from './client.js'\nimport { GitHubReader } from './reader.js'\nimport type { RepoRef } from './types.js'\n\n/**\n * GitHubProvider — `RepoProvider` backed by the Octokit-driven GitHub\n * REST + Git Data APIs.\n *\n * The provider is transport-agnostic; it only talks to an `Octokit`\n * instance passed into the constructor. The `createGitHubProvider`\n * helper in `factory.ts` wraps the dynamic import so consumers never\n * have to touch Octokit directly.\n */\nexport class GitHubProvider implements RepoProvider {\n readonly capabilities: ProviderCapabilities = GITHUB_CAPABILITIES\n private readonly reader: GitHubReader\n\n constructor(\n private readonly client: GitHubClient,\n public readonly repo: RepoRef,\n ) {\n this.reader = new GitHubReader(client, repo)\n }\n\n readFile(path: string, ref?: string): Promise<string> {\n return this.reader.readFile(path, ref)\n }\n listDirectory(path: string, ref?: string): Promise<string[]> {\n return this.reader.listDirectory(path, ref)\n }\n fileExists(path: string, ref?: string): Promise<boolean> {\n return this.reader.fileExists(path, ref)\n }\n\n applyPlan(input: ApplyPlanInput): Promise<Commit> {\n return applyPlanToGitHub(this.client, this.repo, input)\n }\n\n listBranches(prefix?: string): Promise<Branch[]> {\n return listBranchesOp(this.client, this.repo, prefix)\n }\n createBranch(name: string, fromRef?: string): Promise<void> {\n const resolved = fromRef ?? 'main'\n return createBranchOp(this.client, this.repo, name, resolved)\n }\n deleteBranch(name: string): Promise<void> {\n return deleteBranchOp(this.client, this.repo, name)\n }\n getBranchDiff(branch: string, base?: string): Promise<FileDiff[]> {\n const resolved = base ?? 'main'\n return getBranchDiffOp(this.client, this.repo, branch, resolved)\n }\n mergeBranch(branch: string, into: string): Promise<MergeResult> {\n return mergeBranchOp(this.client, this.repo, branch, into)\n }\n isMerged(branch: string, into?: string): Promise<boolean> {\n const resolved = into ?? 'main'\n return isMergedOp(this.client, this.repo, branch, resolved)\n }\n getDefaultBranch(): Promise<string> {\n return getDefaultBranchOp(this.client, this.repo)\n }\n}\n","import type { GitHubClient } from './client.js'\nimport { exchangeInstallationToken } from './app-auth.js'\nimport { GitHubProvider } from './provider.js'\nimport type { GitHubAuth, RepoRef } from './types.js'\n\n/**\n * Create an Octokit-backed `GitHubClient` from an auth configuration.\n *\n * The `@octokit/rest` module is imported dynamically so it stays a pure\n * optional peer dependency — self-hosted MCP on stdio can run without\n * it. If the module is not installed, the import throws with a helpful\n * hint pointing the operator at the peer dependency.\n *\n * Two auth modes:\n *\n * - `pat` — personal access token or fine-grained PAT. Simplest for\n * self-hosted MCP or CI runners.\n * - `app` — GitHub App installation auth. The factory mints a short-\n * lived JWT, exchanges it for an installation token via\n * `exchangeInstallationToken`, and instantiates Octokit with the\n * resulting bearer. The returned token expires in ~1 hour; callers\n * that need auto-refresh should instead inject their own Octokit\n * built with `@octokit/auth-app`'s auth strategy and construct\n * `GitHubProvider` directly. See the embedding guide for trade-offs.\n */\nexport async function createGitHubClient(auth: GitHubAuth): Promise<GitHubClient> {\n let OctokitCtor: typeof import('@octokit/rest').Octokit\n try {\n ({ Octokit: OctokitCtor } = await import('@octokit/rest'))\n } catch (error) {\n throw new Error(\n '@octokit/rest is required for the GitHubProvider but could not be loaded. '\n + 'Install it as a peer dependency: pnpm add @octokit/rest.',\n { cause: error },\n )\n }\n\n if (auth.type === 'pat') {\n return new OctokitCtor({ auth: auth.token })\n }\n\n if (auth.type === 'app') {\n const { token } = await exchangeInstallationToken({\n appId: auth.appId,\n privateKey: auth.privateKey,\n installationId: auth.installationId,\n })\n return new OctokitCtor({ auth: token })\n }\n\n const unknown = auth as { type: string }\n throw new Error(`GitHub auth type \"${unknown.type}\" is not supported. Use \"pat\" or \"app\".`)\n}\n\n/**\n * Factory for the full provider — instantiates an Octokit client and\n * wraps it in a `GitHubProvider`. Consumers who already hold an Octokit\n * instance (HTTP server injecting shared clients, tests, etc.) should\n * instantiate `GitHubProvider` directly instead.\n */\nexport async function createGitHubProvider(opts: { auth: GitHubAuth, repo: RepoRef }): Promise<GitHubProvider> {\n const client = await createGitHubClient(opts.auth)\n return new GitHubProvider(client, opts.repo)\n}\n","import type { CommitAuthor } from '../../core/contracts/index.js'\n\n/**\n * A reference to a GitHub repository.\n *\n * `contentRoot` is the repo-relative directory prefix where Contentrain\n * content lives. For a flat content repo it stays `''`; for a monorepo\n * where Contentrain is embedded (e.g. `apps/web/.contentrain/`) it holds\n * that prefix. All reader/writer paths are joined against it.\n */\nexport interface RepoRef {\n owner: string\n name: string\n contentRoot?: string\n}\n\n/**\n * Authentication options for the GitHub provider.\n *\n * - `pat` — a personal access token or fine-grained PAT. Simplest for\n * self-hosted MCP or CI runners. Phase 5.1 ships with this mode only.\n * - `app` — GitHub App installation auth (JWT + installation token\n * exchange). Planned for Phase 5.2; see `.internal/refactor/\n * 02-studio-handoff.md` S6 for how Studio's hosted MCP plugs in.\n */\nexport type GitHubAuth =\n | { type: 'pat', token: string }\n | {\n type: 'app'\n appId: number\n privateKey: string\n installationId: number\n }\n\n/** Default author used when a call does not provide one. */\nexport const DEFAULT_GITHUB_AUTHOR: CommitAuthor = {\n name: 'Contentrain',\n email: 'mcp@contentrain.io',\n}\n"],"mappings":";;;;;;;;;;;AA8CA,SAAS,gBAAgB,KAAsB;AAC7C,QAAO,OAAO,KAAK,KAAK,UAAU,IAAI,EAAE,OAAO,CAAC,SAAS,YAAY;;AAGvE,SAAgB,WAAW,QAA6D;CACtF,MAAM,MAAM,KAAK,MAAM,KAAK,KAAK,GAAG,IAAK;CACzC,MAAM,SAAS;EAAE,KAAK;EAAS,KAAK;EAAO;CAC3C,MAAM,UAAU;EACd,KAAK,MAAM;EACX,KAAK,MAAM;EACX,KAAK,OAAO,OAAO,MAAM;EAC1B;CAED,MAAM,SAAS,GAAG,gBAAgB,OAAO,CAAC,GAAG,gBAAgB,QAAQ;CACrE,MAAM,YAAY,iBAAiB;EAAE,KAAK,OAAO;EAAY,QAAQ;EAAO,CAAC;CAC7E,MAAM,SAAS,WAAW,aAAa;AACvC,QAAO,OAAO,OAAO;AACrB,QAAO,KAAK;AAGZ,QAAO,GAAG,OAAO,GAFC,OAAO,KAAK,UAAU,CAAC,SAAS,YAAY;;;;;;;;;AAYhE,eAAsB,0BACpB,QACA,OAAkE,EAAE,EA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