shiplock 0.4.0 → 0.4.1
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/cli.mjs +32 -9
- package/index.mjs +1 -1
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -186,6 +186,22 @@ export async function repositoryStatus({ base, token, repository, fetch: fetchIm
|
|
|
186
186
|
throw new Error(body.error || `ShipLock could not read the repository (${res.status}).`);
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
/** Select the repository git names (app/api/cli/repository). The server checks
|
|
190
|
+
* the account's GitHub installation can read it; if not, it returns the App
|
|
191
|
+
* install link, which must be on ShipLock's own address before it is opened. */
|
|
192
|
+
export async function selectRepository({ base, token, repository, fetch: fetchImpl = fetch }) {
|
|
193
|
+
const res = await fetchImpl(`${trim(base)}/api/cli/repository`, {
|
|
194
|
+
method: "POST",
|
|
195
|
+
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
196
|
+
body: JSON.stringify({ repository }),
|
|
197
|
+
});
|
|
198
|
+
const body = await res.json().catch(() => ({}));
|
|
199
|
+
if (res.status !== 200) throw new Error(body.error || `ShipLock could not select the repository (${res.status}).`);
|
|
200
|
+
if (body.state === "selected" && typeof body.repository === "string") return { state: "selected", repository: body.repository };
|
|
201
|
+
if (body.state === "install" && typeof body.url === "string" && body.url.startsWith(`${trim(base)}/`)) return { state: "install", url: body.url };
|
|
202
|
+
throw new Error("ShipLock sent an unexpected answer. Update with npx shiplock@latest init.");
|
|
203
|
+
}
|
|
204
|
+
|
|
189
205
|
export function openBrowser(url) {
|
|
190
206
|
if (process.env.SHIPLOCK_NO_BROWSER) return;
|
|
191
207
|
const [cmd, args] = process.platform === "darwin" ? ["open", [url]]
|
|
@@ -207,7 +223,7 @@ async function signIn(base) {
|
|
|
207
223
|
async function init(base) {
|
|
208
224
|
const root = git(["rev-parse", "--show-toplevel"]);
|
|
209
225
|
if (!root) throw new Error("Run shiplock init inside a git repository.");
|
|
210
|
-
|
|
226
|
+
let repository = githubRepository(git(["remote", "get-url", "origin"]) ?? "");
|
|
211
227
|
if (!repository) throw new Error("This repository has no GitHub remote named origin. ShipLock reads repositories through GitHub.");
|
|
212
228
|
console.log(`${banner()}\n\n ${dim("Repository")} ${bold(repository)}\n`);
|
|
213
229
|
|
|
@@ -219,15 +235,22 @@ async function init(base) {
|
|
|
219
235
|
} else console.log(ok("Signed in"));
|
|
220
236
|
|
|
221
237
|
if (status.state === "not_selected") {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
238
|
+
// The repository comes from git, never from a picker in the browser.
|
|
239
|
+
let chosen = await selectRepository({ base, token, repository });
|
|
240
|
+
if (chosen.state === "install") {
|
|
241
|
+
console.log(`\n${bronze("◆")} Install the ShipLock GitHub App on ${bold(repository)}. Opening GitHub...`);
|
|
242
|
+
console.log(dim(`Browser didn't open? ${chosen.url}`));
|
|
243
|
+
openBrowser(chosen.url);
|
|
244
|
+
const deadline = Date.now() + 15 * 60 * 1000;
|
|
245
|
+
while (chosen.state === "install" && Date.now() < deadline) {
|
|
246
|
+
await sleep(5000);
|
|
247
|
+
chosen = await selectRepository({ base, token, repository });
|
|
248
|
+
}
|
|
249
|
+
if (chosen.state !== "selected") throw new Error(`The GitHub App cannot read ${repository} yet. Install it on this repository, then run shiplock init again.`);
|
|
229
250
|
}
|
|
230
|
-
|
|
251
|
+
repository = chosen.repository;
|
|
252
|
+
status = await repositoryStatus({ base, token, repository });
|
|
253
|
+
if (status.state !== "selected") throw new Error(`ShipLock could not read ${repository} yet. Run shiplock init again in a minute.`);
|
|
231
254
|
}
|
|
232
255
|
console.log(ok(`${repository} connected`));
|
|
233
256
|
|
package/index.mjs
CHANGED
|
@@ -101,7 +101,7 @@ const RESOURCES = [
|
|
|
101
101
|
{ uri: "shiplock://posture", name: "ShipLock posture", description: "Current security posture summary (counts, last scan).", mimeType: "application/json" },
|
|
102
102
|
];
|
|
103
103
|
|
|
104
|
-
const server = new Server({ name: "shiplock", version: "0.
|
|
104
|
+
const server = new Server({ name: "shiplock", version: "0.4.1" }, { capabilities: { tools: {}, resources: {} } });
|
|
105
105
|
|
|
106
106
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
|
|
107
107
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shiplock",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "ShipLock in your terminal: sign in, add ShipLock to your repository's .mcp.json, and give your coding agent its security findings over MCP. ShipLock writes no code.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://shiplock.dev",
|