notusci 0.1.2 → 0.1.4

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 +29 -6
  3. package/src/core.mjs +34 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notusci",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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,20 @@ 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 "repo set": {
385
+ const repo = repoOrOrigin(input.repo);
386
+ return print(await api(s, `/api/repos/${repo}/settings`, { method: "PUT", body: { pushWorkflow: input.pushWorkflow } }));
387
+ }
388
+ case "migrations list": return print(await api(s, `/api/repos/${repoOrOrigin(input.repo)}/migrations`));
389
+ case "migrations approve": {
390
+ const { manifestDigest, pushRunId, reason, forceDestructive } = input;
391
+ return print(await api(s, `/api/repos/${repoOrOrigin(input.repo)}/migrations/approvals`, { method: "POST",
392
+ body: { manifestDigest, pushRunId, reason, ...(forceDestructive ? { forceDestructive } : {}) } }));
393
+ }
394
+ case "approve": {
395
+ const repo = repoOrOrigin(input.repo);
396
+ return print(await api(s, `/api/pull-requests/${input.runId}/approve`, { method: "POST", query: { repo } }));
397
+ }
376
398
  case "wait": {
377
399
  const repo = repoOrOrigin(input.repo);
378
400
  if (input.timeoutSeconds === undefined) return print(await api(s, runPath(input.runId, "wait"), { query: { repo }, timeoutSeconds: 35 }));
@@ -384,9 +406,9 @@ async function main(s, input) {
384
406
  return print(await api(s, `/api/${kind}/${input.runId}/logs/search`, { query: { repo: repoOrOrigin(input.repo), query: input.query, limit: input.limit } }));
385
407
  }
386
408
  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 } }));
409
+ const { root, repo } = gitRepo();
410
+ const failed = await api(s, `/api/verifies/${input.failedVerifyId}/wait`, { query: { repo, timeoutSeconds: 1 } });
411
+ return report(await verify(s, root, repo, failed.workflow, input.timeoutSeconds, input.failedVerifyId));
390
412
  }
391
413
  }
392
414
  }
@@ -394,6 +416,7 @@ async function main(s, input) {
394
416
  try {
395
417
  const input = parseCommand(process.argv.slice(2));
396
418
  if (input.command === "help") print(HELP);
419
+ else if (input.command === "version") print({ version: JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version });
397
420
  else await main(session(), input);
398
421
  }
399
422
  catch (error) {
package/src/core.mjs CHANGED
@@ -32,25 +32,30 @@ 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" } },
44
+ repo: { repo: { type: "string" }, "push-workflow": { type: "string" }, off: { type: "boolean" } },
45
+ migrations: { repo: { type: "string" }, push: { type: "string" }, reason: { type: "string" }, "force-destructive": { type: "boolean" } },
43
46
  billing: { repo: { type: "string" }, timeout: { type: "string" } },
44
47
  };
45
48
 
46
49
  export const HELP = {
47
50
  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]",
51
+ "init [--scope SCOPES] [--no-mcp] [--billing]", "billing [--repo OWNER/REPO] [--timeout SECONDS]", "doctor",
52
+ "login [--scope SCOPES]", "logout", "whoami", "repos", "token list", "token revoke ID",
53
+ "target set [--repo OWNER/REPO] --file TARGET.json [--auto-promote on|off]", "verify [--workflow PATH] [--timeout SECONDS]",
50
54
  "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]",
55
+ "approve ID [--repo OWNER/REPO]", "repo set [--repo OWNER/REPO] --push-workflow PATH|--off",
56
+ "migrations list [--repo OWNER/REPO]", "migrations approve MANIFEST_DIGEST --push ID --reason TEXT [--repo OWNER/REPO] [--force-destructive]",
57
+ "search-logs ID --query LITERAL [--limit COUNT] [--repo OWNER/REPO]",
58
+ "rerun-failed ID [--timeout SECONDS]", "--version",
54
59
  ],
55
60
  scopes: SCOPES,
56
61
  docs: "https://ci.notusworks.com/docs/agents.md",
@@ -86,7 +91,8 @@ export function parseCommand(args) {
86
91
  if (unknown.length) throw usage(`unknown scope ${unknown.join(",")}; scopes are ${SCOPES.join(",")}`);
87
92
  return command === "init" ? { command, scopes, mcp: !values["no-mcp"], billing: values.billing === true } : { command, scopes };
88
93
  }
89
- if (command === "doctor" || command === "logout") { expect(); return { command }; }
94
+ if (["doctor", "logout", "whoami", "repos"].includes(command)) { expect(); return { command }; }
95
+ if (command === "version" || command === "--version") { expect(); return { command: "version" }; }
90
96
  if (command === "token") {
91
97
  if (positionals[0] === "revoke") { expect("revoke", "*"); return { command: "token revoke", id: positionals[1] }; }
92
98
  expect("list");
@@ -99,6 +105,20 @@ export function parseCommand(args) {
99
105
  if (auto !== undefined && auto !== "on" && auto !== "off") throw usage("--auto-promote must be on or off");
100
106
  return { command: "target set", repo: values.repo, file: values.file, autoPromote: auto === undefined ? undefined : auto === "on" };
101
107
  }
108
+ if (command === "repo") {
109
+ expect("set");
110
+ if ((values["push-workflow"] === undefined) === (values.off !== true)) throw usage("repo set needs exactly one of --push-workflow PATH or --off");
111
+ return { command: "repo set", repo: values.repo, pushWorkflow: values.off ? null : values["push-workflow"] };
112
+ }
113
+ if (command === "migrations") {
114
+ if (positionals[0] === "list") { expect("list"); return { command: "migrations list", repo: values.repo }; }
115
+ expect("approve", "*");
116
+ if (!/^[0-9a-f]{64}$/.test(positionals[1]) || !isPushRunId(values.push?.toLowerCase() ?? "") || !values.reason?.trim()) {
117
+ throw usage("migrations approve needs a 64-hex manifest digest, --push PUSH_UUID and --reason TEXT");
118
+ }
119
+ return { command: "migrations approve", repo: values.repo, manifestDigest: positionals[1], pushRunId: values.push.toLowerCase(),
120
+ reason: values.reason, forceDestructive: values["force-destructive"] === true };
121
+ }
102
122
  if (command === "verify") {
103
123
  expect();
104
124
  if (values.workflow === "") throw usage("--workflow must not be empty");
@@ -114,8 +134,8 @@ export function parseCommand(args) {
114
134
  }
115
135
  if (command === "rerun-failed") {
116
136
  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 };
137
+ if (!isPushRunId(id)) throw usage("rerun-failed requires a verify UUID");
138
+ return { command, failedVerifyId: id, timeoutSeconds: timeoutSeconds ?? 540 };
119
139
  }
120
140
  expect("*");
121
141
  const raw = positionals[0];
@@ -123,6 +143,10 @@ export function parseCommand(args) {
123
143
  if (typeof runId === "number" ? !Number.isSafeInteger(runId) : !isPushRunId(runId)) {
124
144
  throw usage("ID must be a positive safe integer or UUID");
125
145
  }
146
+ if (command === "approve") {
147
+ if (typeof runId !== "string") throw usage("approve requires a NotusCI pull request run UUID");
148
+ return { command, runId, repo: values.repo };
149
+ }
126
150
  if (command === "ship") {
127
151
  if (typeof runId !== "string") throw usage("ship requires a NotusCI push UUID");
128
152
  return { command, runId, repo: values.repo };