notusci 0.1.2 → 0.1.3

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/cli.mjs +19 -6
  3. package/src/core.mjs +17 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notusci",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "CI for coding agents: verify uncommitted changes with your GitHub Actions workflow and get typed JSON",
5
5
  "license": "MIT",
6
6
  "homepage": "https://ci.notusworks.com",
package/src/cli.mjs CHANGED
@@ -305,8 +305,8 @@ async function waitUntilReady(s, path, repo, deadline = Infinity) {
305
305
  }
306
306
  }
307
307
 
308
- /** @param {Session} s @param {string} root @param {string} repo @param {string} workflow @param {number} timeoutSeconds */
309
- async function verify(s, root, repo, workflow, timeoutSeconds) {
308
+ /** @param {Session} s @param {string} root @param {string} repo @param {string} workflow @param {number} timeoutSeconds @param {string} [rerunOf] */
309
+ async function verify(s, root, repo, workflow, timeoutSeconds, rerunOf) {
310
310
  const baseSha = sourceBaseSha(root); const startedAt = performance.now(); const deadline = Date.now() + timeoutSeconds * 1000;
311
311
  const base = await api(s, "/api/verify/base", { query: { repo, baseSha, workflow }, deadline });
312
312
  if (base?.schemaVersion !== 2 || typeof base.present !== "boolean") throw new Error("invalid base probe response");
@@ -321,7 +321,7 @@ async function verify(s, root, repo, workflow, timeoutSeconds) {
321
321
  body = { ...body, objects: full.objects };
322
322
  }
323
323
  let submitted = await api(s, "/api/verify/v2", { method: "POST", body: encodeSource(body), timeoutSeconds: 300,
324
- deadline, query: { repo, workflow, idempotencyKey } });
324
+ deadline, query: { repo, workflow, idempotencyKey, rerunOf } });
325
325
  if (submitted?.schemaVersion !== 2 || typeof submitted.verifyId !== "string" || submitted.sourceIdentity !== expectedIdentity
326
326
  || typeof submitted.baseRequired !== "boolean")
327
327
  throw new Error("invalid Source v2 admission response");
@@ -351,6 +351,14 @@ async function main(s, input) {
351
351
  case "login": return login(s, input);
352
352
  case "billing": return billing(s, input);
353
353
  case "logout": return logout(s);
354
+ case "whoami": {
355
+ const { user, scopes, repos, installUrl } = await api(s, "/api/whoami");
356
+ return print({ user, scopes, repos, installUrl });
357
+ }
358
+ case "repos": {
359
+ const { user, repos, installUrl } = await api(s, "/api/whoami");
360
+ return print({ user, repos, installUrl });
361
+ }
354
362
  case "token list": return print({ tokens: await api(s, "/api/tokens") });
355
363
  case "token revoke":
356
364
  await api(s, `/api/tokens/${encodeURIComponent(input.id)}`, { method: "DELETE" });
@@ -373,6 +381,10 @@ async function main(s, input) {
373
381
  const { shipId } = await api(s, "/api/ships", { method: "POST", body: { repo, pushRunId: input.runId } });
374
382
  return report(await waitUntilReady(s, `/api/ships/${shipId}/wait`, repo));
375
383
  }
384
+ case "approve": {
385
+ const repo = repoOrOrigin(input.repo);
386
+ return print(await api(s, `/api/pull-requests/${input.runId}/approve`, { method: "POST", query: { repo } }));
387
+ }
376
388
  case "wait": {
377
389
  const repo = repoOrOrigin(input.repo);
378
390
  if (input.timeoutSeconds === undefined) return print(await api(s, runPath(input.runId, "wait"), { query: { repo }, timeoutSeconds: 35 }));
@@ -384,9 +396,9 @@ async function main(s, input) {
384
396
  return print(await api(s, `/api/${kind}/${input.runId}/logs/search`, { query: { repo: repoOrOrigin(input.repo), query: input.query, limit: input.limit } }));
385
397
  }
386
398
  case "rerun-failed": {
387
- const repo = repoOrOrigin(input.repo); let body;
388
- try { body = JSON.parse(readFileSync(input.file, "utf8")); } catch { throw new CliError({ code: "usage", error: `${input.file} must be readable JSON`, next: "Fix --file and retry." }); }
389
- return print(await api(s, `/api/agent/verifies/${input.failedVerifyId}/rerun`, { method: "POST", body: { ...body, repo } }));
399
+ const { root, repo } = gitRepo();
400
+ const failed = await api(s, `/api/verifies/${input.failedVerifyId}/wait`, { query: { repo, timeoutSeconds: 1 } });
401
+ return report(await verify(s, root, repo, failed.workflow, input.timeoutSeconds, input.failedVerifyId));
390
402
  }
391
403
  }
392
404
  }
@@ -394,6 +406,7 @@ async function main(s, input) {
394
406
  try {
395
407
  const input = parseCommand(process.argv.slice(2));
396
408
  if (input.command === "help") print(HELP);
409
+ else if (input.command === "version") print({ version: JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version });
397
410
  else await main(session(), input);
398
411
  }
399
412
  catch (error) {
package/src/core.mjs CHANGED
@@ -32,25 +32,27 @@ function usage(error) {
32
32
  const OPTIONS = {
33
33
  init: { scope: { type: "string" }, "no-mcp": { type: "boolean" }, billing: { type: "boolean" } },
34
34
  login: { scope: { type: "string" } },
35
- doctor: {}, logout: {}, token: {},
35
+ doctor: {}, logout: {}, token: {}, whoami: {}, repos: {}, version: {}, "--version": {},
36
36
  target: { repo: { type: "string" }, file: { type: "string" }, "auto-promote": { type: "string" } },
37
37
  verify: { workflow: { type: "string" }, timeout: { type: "string" } },
38
38
  wait: { repo: { type: "string" }, timeout: { type: "string" } },
39
39
  failures: { repo: { type: "string" } },
40
40
  "search-logs": { repo: { type: "string" }, query: { type: "string" }, limit: { type: "string" } },
41
- "rerun-failed": { repo: { type: "string" }, file: { type: "string" } },
41
+ "rerun-failed": { timeout: { type: "string" } },
42
42
  ship: { repo: { type: "string" } },
43
+ approve: { repo: { type: "string" } },
43
44
  billing: { repo: { type: "string" }, timeout: { type: "string" } },
44
45
  };
45
46
 
46
47
  export const HELP = {
47
48
  commands: [
48
- "init [--scope SCOPES] [--no-mcp] [--billing]", "doctor", "login [--scope SCOPES]", "logout", "token list", "token revoke ID",
49
- "target set --repo OWNER/REPO --file TARGET.json [--auto-promote on|off]", "verify [--workflow PATH] [--timeout SECONDS]",
49
+ "init [--scope SCOPES] [--no-mcp] [--billing]", "billing [--repo OWNER/REPO] [--timeout SECONDS]", "doctor",
50
+ "login [--scope SCOPES]", "logout", "whoami", "repos", "token list", "token revoke ID",
51
+ "target set [--repo OWNER/REPO] --file TARGET.json [--auto-promote on|off]", "verify [--workflow PATH] [--timeout SECONDS]",
50
52
  "wait ID [--repo OWNER/REPO] [--timeout SECONDS]", "failures ID [--repo OWNER/REPO]", "ship ID [--repo OWNER/REPO]",
51
- "billing [--repo OWNER/REPO] [--timeout SECONDS]",
52
- "search-logs ID --query LITERAL [--repo OWNER/REPO] [--limit COUNT]",
53
- "rerun-failed ID --file REQUEST.json [--repo OWNER/REPO]",
53
+ "approve ID [--repo OWNER/REPO]",
54
+ "search-logs ID --query LITERAL [--limit COUNT] [--repo OWNER/REPO]",
55
+ "rerun-failed ID [--timeout SECONDS]", "--version",
54
56
  ],
55
57
  scopes: SCOPES,
56
58
  docs: "https://ci.notusworks.com/docs/agents.md",
@@ -86,7 +88,8 @@ export function parseCommand(args) {
86
88
  if (unknown.length) throw usage(`unknown scope ${unknown.join(",")}; scopes are ${SCOPES.join(",")}`);
87
89
  return command === "init" ? { command, scopes, mcp: !values["no-mcp"], billing: values.billing === true } : { command, scopes };
88
90
  }
89
- if (command === "doctor" || command === "logout") { expect(); return { command }; }
91
+ if (["doctor", "logout", "whoami", "repos"].includes(command)) { expect(); return { command }; }
92
+ if (command === "version" || command === "--version") { expect(); return { command: "version" }; }
90
93
  if (command === "token") {
91
94
  if (positionals[0] === "revoke") { expect("revoke", "*"); return { command: "token revoke", id: positionals[1] }; }
92
95
  expect("list");
@@ -114,8 +117,8 @@ export function parseCommand(args) {
114
117
  }
115
118
  if (command === "rerun-failed") {
116
119
  expect("*"); const id = positionals[0].toLowerCase();
117
- if (!isPushRunId(id) || !values.file) throw usage("rerun-failed requires a verify UUID and --file");
118
- return { command, failedVerifyId: id, repo: values.repo, file: values.file };
120
+ if (!isPushRunId(id)) throw usage("rerun-failed requires a verify UUID");
121
+ return { command, failedVerifyId: id, timeoutSeconds: timeoutSeconds ?? 540 };
119
122
  }
120
123
  expect("*");
121
124
  const raw = positionals[0];
@@ -123,6 +126,10 @@ export function parseCommand(args) {
123
126
  if (typeof runId === "number" ? !Number.isSafeInteger(runId) : !isPushRunId(runId)) {
124
127
  throw usage("ID must be a positive safe integer or UUID");
125
128
  }
129
+ if (command === "approve") {
130
+ if (typeof runId !== "string") throw usage("approve requires a NotusCI pull request run UUID");
131
+ return { command, runId, repo: values.repo };
132
+ }
126
133
  if (command === "ship") {
127
134
  if (typeof runId !== "string") throw usage("ship requires a NotusCI push UUID");
128
135
  return { command, runId, repo: values.repo };